|
Lines 86-181
was made.
Link Here
|
| 86 |
# FIXME - I'm not at all sure about the above, because I don't |
86 |
# FIXME - I'm not at all sure about the above, because I don't |
| 87 |
# understand what the acct* tables in the Koha database are for. |
87 |
# understand what the acct* tables in the Koha database are for. |
| 88 |
sub makepayment { |
88 |
sub makepayment { |
| 89 |
|
|
|
| 90 |
#here we update both the accountoffsets and the account lines |
| 91 |
#updated to check, if they are paying off a lost item, we return the item |
| 92 |
# from their card, and put a note on the item record |
| 93 |
my ( $accountlines_id, $borrowernumber, $accountno, $amount, $user, $branch, $payment_note ) = @_; |
89 |
my ( $accountlines_id, $borrowernumber, $accountno, $amount, $user, $branch, $payment_note ) = @_; |
| 94 |
my $dbh = C4::Context->dbh; |
|
|
| 95 |
my $manager_id = 0; |
| 96 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
| 97 |
|
| 98 |
# begin transaction |
| 99 |
my $nextaccntno = getnextacctno($borrowernumber); |
| 100 |
my $newamtos = 0; |
| 101 |
my $sth = $dbh->prepare("SELECT * FROM accountlines WHERE accountlines_id=?"); |
| 102 |
$sth->execute( $accountlines_id ); |
| 103 |
my $data = $sth->fetchrow_hashref; |
| 104 |
|
| 105 |
my $payment; |
| 106 |
if ( $data->{'accounttype'} eq "Pay" ){ |
| 107 |
my $udp = |
| 108 |
$dbh->prepare( |
| 109 |
"UPDATE accountlines |
| 110 |
SET amountoutstanding = 0 |
| 111 |
WHERE accountlines_id = ? |
| 112 |
" |
| 113 |
); |
| 114 |
$udp->execute($accountlines_id); |
| 115 |
}else{ |
| 116 |
my $udp = |
| 117 |
$dbh->prepare( |
| 118 |
"UPDATE accountlines |
| 119 |
SET amountoutstanding = 0 |
| 120 |
WHERE accountlines_id = ? |
| 121 |
" |
| 122 |
); |
| 123 |
$udp->execute($accountlines_id); |
| 124 |
|
| 125 |
# create new line |
| 126 |
my $payment = 0 - $amount; |
| 127 |
$payment_note //= ""; |
| 128 |
|
| 129 |
my $ins = |
| 130 |
$dbh->prepare( |
| 131 |
"INSERT |
| 132 |
INTO accountlines (borrowernumber, accountno, date, amount, itemnumber, description, accounttype, amountoutstanding, manager_id, note) |
| 133 |
VALUES ( ?, ?, now(), ?, ?, '', 'Pay', 0, ?, ?)" |
| 134 |
); |
| 135 |
$ins->execute($borrowernumber, $nextaccntno, $payment, $data->{'itemnumber'}, $manager_id, $payment_note); |
| 136 |
} |
| 137 |
|
| 138 |
if ( C4::Context->preference("FinesLog") ) { |
| 139 |
logaction("FINES", 'MODIFY', $borrowernumber, Dumper({ |
| 140 |
action => 'fee_payment', |
| 141 |
borrowernumber => $borrowernumber, |
| 142 |
old_amountoutstanding => $data->{'amountoutstanding'}, |
| 143 |
new_amountoutstanding => 0, |
| 144 |
amount_paid => $data->{'amountoutstanding'}, |
| 145 |
accountlines_id => $data->{'accountlines_id'}, |
| 146 |
accountno => $data->{'accountno'}, |
| 147 |
manager_id => $manager_id, |
| 148 |
})); |
| 149 |
|
| 150 |
|
| 151 |
logaction("FINES", 'CREATE',$borrowernumber,Dumper({ |
| 152 |
action => 'create_payment', |
| 153 |
borrowernumber => $borrowernumber, |
| 154 |
accountno => $nextaccntno, |
| 155 |
amount => $payment, |
| 156 |
amountoutstanding => 0,, |
| 157 |
accounttype => 'Pay', |
| 158 |
accountlines_paid => [$data->{'accountlines_id'}], |
| 159 |
manager_id => $manager_id, |
| 160 |
})); |
| 161 |
} |
| 162 |
|
| 163 |
UpdateStats({ |
| 164 |
branch => $branch, |
| 165 |
type => 'payment', |
| 166 |
amount => $amount, |
| 167 |
borrowernumber => $borrowernumber, |
| 168 |
accountno => $accountno |
| 169 |
}); |
| 170 |
|
90 |
|
| 171 |
#check to see what accounttype |
91 |
return Koha::Account->new( { patron_id => $borrowernumber } ) |
| 172 |
if ( $data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L' ) { |
92 |
->pay( { accountlines_id => $accountlines_id, amount => $amount, library_id => $branch, note => $payment_note } ); |
| 173 |
C4::Circulation::ReturnLostItem( $borrowernumber, $data->{'itemnumber'} ); |
|
|
| 174 |
} |
| 175 |
my $sthr = $dbh->prepare("SELECT max(accountlines_id) AS lastinsertid FROM accountlines"); |
| 176 |
$sthr->execute(); |
| 177 |
my $datalastinsertid = $sthr->fetchrow_hashref; |
| 178 |
return $datalastinsertid->{'lastinsertid'}; |
| 179 |
} |
93 |
} |
| 180 |
|
94 |
|
| 181 |
=head2 getnextacctno |
95 |
=head2 getnextacctno |