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