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