From ef76c957b2d1c5828524270ddc3f4d84fe8ebd25 Mon Sep 17 00:00:00 2001 From: Blou Date: Thu, 17 Jul 2014 15:06:31 -0400 Subject: [PATCH] bug 5620 - Capture Mode of payment, receipt number and notes in pay fines. Using sql file in atomiqueupdate using function GetKohaAuthorisedValues --- C4/Accounts.pm | 25 ++++++++--------- C4/Koha.pm | 31 +++++++++++----------- .../atomicupdate/bug5620_Add_Mode_Of_Payment.sql | 6 +++++ installer/data/mysql/kohastructure.sql | 1 + .../prog/en/modules/members/boraccount.tt | 2 ++ .../prog/en/modules/members/paycollect.tt | 18 +++++++++++++ members/paycollect.pl | 18 ++++++++++--- 7 files changed, 71 insertions(+), 30 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug5620_Add_Mode_Of_Payment.sql diff --git a/C4/Accounts.pm b/C4/Accounts.pm index e49becb..30cb84e 100644 --- a/C4/Accounts.pm +++ b/C4/Accounts.pm @@ -26,6 +26,7 @@ use C4::Members; use C4::Circulation qw(ReturnLostItem); use C4::Log qw(logaction); use Koha::Account; +use C4::Koha qw(GetKohaAuthorisedValueLib); use Data::Dumper qw(Dumper); @@ -90,7 +91,7 @@ sub makepayment { #here we update both the accountoffsets and the account lines #updated to check, if they are paying off a lost item, we return the item # from their card, and put a note on the item record - my ( $accountlines_id, $borrowernumber, $accountno, $amount, $user, $branch, $payment_note ) = @_; + my ( $accountlines_id, $borrowernumber, $accountno, $amount, $user, $branch, $payment_note, $paymentmode ) = @_; my $dbh = C4::Context->dbh; my $manager_id = 0; $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; @@ -129,10 +130,10 @@ sub makepayment { my $ins = $dbh->prepare( "INSERT - INTO accountlines (borrowernumber, accountno, date, amount, itemnumber, description, accounttype, amountoutstanding, manager_id, note) - VALUES ( ?, ?, now(), ?, ?, '', 'Pay', 0, ?, ?)" + INTO accountlines (borrowernumber, accountno, date, amount, itemnumber, description, accounttype, amountoutstanding, manager_id, note, paymentmode) + VALUES ( ?, ?, now(), ?, ?, '', 'Pay', 0, ?, ?, ?)" ); - $ins->execute($borrowernumber, $nextaccntno, $payment, $data->{'itemnumber'}, $manager_id, $payment_note); + $ins->execute($borrowernumber, $nextaccntno, $payment, $data->{'itemnumber'}, $manager_id, $payment_note, GetKohaAuthorisedValueLib('PAYMODE', $paymentmode)); } if ( C4::Context->preference("FinesLog") ) { @@ -480,7 +481,7 @@ will be credited to the next one. =cut sub recordpayment_selectaccts { - my ( $borrowernumber, $amount, $accts, $note ) = @_; + my ( $borrowernumber, $amount, $accts, $note, $paymentmode ) = @_; my $dbh = C4::Context->dbh; my $newamtos = 0; @@ -540,9 +541,9 @@ sub recordpayment_selectaccts { # create new line $sql = 'INSERT INTO accountlines ' . - '(borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id,note) ' . - q|VALUES (?,?,now(),?,'','Pay',?,?,?)|; - $dbh->do($sql,{},$borrowernumber, $nextaccntno, 0 - $amount, 0 - $amountleft, $manager_id, $note ); + '(borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id,note,paymentmode) ' . + q|VALUES (?,?,now(),?,'','Pay',?,?,?,?)|; + $dbh->do($sql,{},$borrowernumber, $nextaccntno, 0 - $amount, 0 - $amountleft, $manager_id, $note, GetKohaAuthorisedValueLib('PAYMODE', $paymentmode) ); UpdateStats({ branch => $branch, type => 'payment', @@ -570,7 +571,7 @@ sub recordpayment_selectaccts { # makepayment needs to be fixed to handle partials till then this separate subroutine # fills in sub makepartialpayment { - my ( $accountlines_id, $borrowernumber, $accountno, $amount, $user, $branch, $payment_note ) = @_; + my ( $accountlines_id, $borrowernumber, $accountno, $amount, $user, $branch, $payment_note, $paymentmode ) = @_; my $manager_id = 0; $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; if (!$amount || $amount < 0) { @@ -604,11 +605,11 @@ sub makepartialpayment { # create new line my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, ' - . 'description, accounttype, amountoutstanding, itemnumber, manager_id, note) ' - . ' VALUES (?, ?, now(), ?, ?, ?, 0, ?, ?, ?)'; + . 'description, accounttype, amountoutstanding, itemnumber, manager_id, note, paymentmode) ' + . ' VALUES (?, ?, now(), ?, ?, ?, 0, ?, ?, ?,?)'; $dbh->do( $insert, undef, $borrowernumber, $nextaccntno, $amount, - '', 'Pay', $data->{'itemnumber'}, $manager_id, $payment_note); + '', 'Pay', $data->{'itemnumber'}, $manager_id, $payment_note, GetKohaAuthorisedValueLib('PAYMODE', $paymentmode)); UpdateStats({ branch => $branch, diff --git a/C4/Koha.pm b/C4/Koha.pm index 0ff4851..bc4fd50 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -1042,21 +1042,22 @@ Returns undef if no authorised value category is defined for the kohafield. =cut sub GetKohaAuthorisedValues { - my ($kohafield,$fwcode,$opac) = @_; - $fwcode='' unless $fwcode; - my %values; - my $dbh = C4::Context->dbh; - my $avcode = GetAuthValCode($kohafield,$fwcode); - if ($avcode) { - my $sth = $dbh->prepare("select authorised_value, lib, lib_opac from authorised_values where category=? "); - $sth->execute($avcode); - while ( my ($val, $lib, $lib_opac) = $sth->fetchrow_array ) { - $values{$val} = ($opac && $lib_opac) ? $lib_opac : $lib; - } - return \%values; - } else { - return; - } + my ($kohafield,$fwcode,$opac, $category) = @_; + $fwcode='' unless $fwcode; + my %values; + my $dbh = C4::Context->dbh; + my $avcode = GetAuthValCode($kohafield,$fwcode); + $avcode = $category unless ($avcode); + if ($avcode) { + my $sth = $dbh->prepare("select authorised_value, lib, lib_opac from authorised_values where category=? "); + $sth->execute($avcode); + while ( my ($val, $lib, $lib_opac) = $sth->fetchrow_array ) { + $values{$val} = ($opac && $lib_opac) ? $lib_opac : $lib; + } + return \%values; + } else { + return; + } } =head2 GetKohaAuthorisedValuesFromField diff --git a/installer/data/mysql/atomicupdate/bug5620_Add_Mode_Of_Payment.sql b/installer/data/mysql/atomicupdate/bug5620_Add_Mode_Of_Payment.sql new file mode 100644 index 0000000..df8af99 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug5620_Add_Mode_Of_Payment.sql @@ -0,0 +1,6 @@ +ALTER table accountlines ADD COLUMN paymentmode TEXT NOT NULL; +INSERT INTO authorised_values (category, authorised_value, lib, lib_opac) VALUES +('PAYMODE','CASH','Cash', 'Cash'), +('PAYMODE','CC','Credit Card', 'Credit Card'), +('PAYMODE','DEBIG','Debit', 'Debit'); + diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index e38efc5..8364035 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2685,6 +2685,7 @@ CREATE TABLE `accountlines` ( `notify_level` int(2) NOT NULL default 0, `note` text NULL default NULL, `manager_id` int(11) NULL, + `paymentmode` text COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`accountlines_id`), KEY `acctsborridx` (`borrowernumber`), KEY `timeidx` (`timestamp`), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt index ca0a804..2246b5d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt @@ -64,6 +64,7 @@ $(document).ready(function() { Date Description of charges Note + Payment mode Amount Outstanding [% IF ( reverse_col ) %] @@ -105,6 +106,7 @@ $(document).ready(function() { [%- IF account.description %], [% account.description %][% END %]  [% IF ( account.itemnumber ) %][% account.title |html %][% END %] [% account.note | html_line_break %] + [% account.paymentmode %] [% IF ( account.amountcredit ) %][% ELSE %][% END %][% account.amount %] [% IF ( account.amountoutstandingcredit ) %][% ELSE %][% END %][% account.amountoutstanding %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt index 069ad69..fa0249c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt @@ -148,6 +148,15 @@ function moneyFormat(textObj) { +
  • + + +
  • + @@ -213,6 +222,15 @@ function moneyFormat(textObj) { +
  • + + +
  • +
  • diff --git a/members/paycollect.pl b/members/paycollect.pl index 1cb6ad9..880bcac 100755 --- a/members/paycollect.pl +++ b/members/paycollect.pl @@ -46,6 +46,16 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); +# get authorised values with category of PAYMODE +my @paymentmodes; +my $paymentmodesHash = GetKohaAuthorisedValues('', '', '', 'PAYMODE'); +foreach my $key (keys %$paymentmodesHash) { + push @paymentmodes, {'authorised_value' => $key, + 'lib' => $paymentmodesHash->{$key}}; +} +$template->param( paymentmodes => \@paymentmodes ); + + # get borrower details my $borrowernumber = $input->param('borrowernumber'); my $borrower = GetMember( borrowernumber => $borrowernumber ); @@ -55,6 +65,7 @@ my $branch = C4::Context->userenv->{'branch'}; my ( $total_due, $accts, $numaccts ) = GetMemberAccountRecords($borrowernumber); my $total_paid = $input->param('paid'); +my $paymentmode = $input->param('paymentmode'); my $individual = $input->param('pay_individual'); my $writeoff = $input->param('writeoff_individual'); @@ -113,10 +124,10 @@ if ( $total_paid and $total_paid ne '0.00' ) { if ($individual) { if ( $total_paid == $total_due ) { makepayment( $accountlines_id, $borrowernumber, $accountno, $total_paid, $user, - $branch, $payment_note ); + $branch, $payment_note, $paymentmode ); } else { makepartialpayment( $accountlines_id, $borrowernumber, $accountno, $total_paid, - $user, $branch, $payment_note ); + $user, $branch, $payment_note, $paymentmode ); } print $input->redirect( "/cgi-bin/koha/members/pay.pl?borrowernumber=$borrowernumber"); @@ -127,11 +138,12 @@ if ( $total_paid and $total_paid ne '0.00' ) { } my @acc = split /,/, $select; my $note = $input->param('selected_accts_notes'); - recordpayment_selectaccts( $borrowernumber, $total_paid, \@acc, $note ); + recordpayment_selectaccts( $borrowernumber, $total_paid, \@acc, $note, $paymentmode ); } else { my $note = $input->param('selected_accts_notes'); Koha::Account->new( { patron_id => $borrowernumber } ) ->pay( { amount => $total_paid, note => $note } ); + recordpayment( $borrowernumber, $total_paid, '', $note, $paymentmode ); } print $input->redirect( -- 1.9.1