Business-AU-Ledger

 view release on metacpan or  search on metacpan

lib/Business/AU/Ledger/Database.pm  view on Meta::CPAN

package Business::AU::Ledger::Database;

use Business::AU::Ledger::Database::Payment;
use Business::AU::Ledger::Database::Receipt;

use Log::Dispatch;
use Log::Dispatch::DBI;

use Moose;

has last_insert_id => (is => 'rw', isa => 'Int');
has logger         => (is => 'rw', isa => 'Log::Dispatch');
has payment        => (is => 'rw', isa => 'Business::AU::Ledger::Database::Payment');
has receipt        => (is => 'rw', isa => 'Business::AU::Ledger::Database::Receipt');
has simple         => (is => 'rw', isa => 'DBIx::Simple');

use namespace::autoclean;

our $VERSION = '0.88';

# -----------------------------------------------

sub BUILD
{
	my($self) = @_;

	$self -> logger(Log::Dispatch -> new);
	$self -> logger -> add
	(
		Log::Dispatch::DBI -> new
		(
		 dbh       => $self -> simple -> dbh,
		 min_level => 'info',
		 name      => 'Ledger',
		)
	);
	$self -> payment(Business::AU::Ledger::Database::Payment -> new(db => $self, simple => $self -> simple) );
	$self -> receipt(Business::AU::Ledger::Database::Receipt -> new(db => $self, simple => $self -> simple) );

	return $self;

}	# End of BUILD.

# -----------------------------------------------

sub get_last_insert_id
{
	my($self, $table_name) = @_;

	$self -> last_insert_id($self -> simple -> dbh -> last_insert_id(undef, undef, $table_name, undef) );

}	# End of get_last_insert_id.

# -----------------------------------------------

sub get_month_name
{
	my($self, $number) = @_;
	my($month) = $self -> simple -> query('select name from months where id = ?', $number) -> hash;

	$self -> log(__PACKAGE__ . ". Leaving get_month_name: $number => $$month{'name'}");

	return $$month{'name'};

}	# End of get_month_name.

# -----------------------------------------------

sub get_month_number
{
	my($self, $name) = @_;
	my($month) = $self -> simple -> query('select id from months where name = ?', $name) -> hash;

	$self -> log(__PACKAGE__ . ". Leaving get_month_number. $name => $$month{'id'}");

	return $$month{'id'};



( run in 2.547 seconds using v1.01-cache-2.11-cpan-744e820c463 )