View | Details | Raw Unified | Return to bug 5905
Collapse All | Expand All

(-)a/C4/Accounts.pm (-187 / +252 lines)
Lines 17-24 package C4::Accounts; Link Here
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
19
20
21
use strict;
20
use strict;
21
22
#use warnings; FIXME - Bug 2505
22
#use warnings; FIXME - Bug 2505
23
use C4::Context;
23
use C4::Context;
24
use C4::Stats;
24
use C4::Stats;
Lines 29-44 use C4::Circulation qw(MarkIssueReturned); Link Here
29
use vars qw($VERSION @ISA @EXPORT);
29
use vars qw($VERSION @ISA @EXPORT);
30
30
31
BEGIN {
31
BEGIN {
32
	# set the version for version checking
32
    # set the version for version checking
33
	$VERSION = 3.03;
33
    $VERSION = 3.03;
34
	require Exporter;
34
    require Exporter;
35
	@ISA    = qw(Exporter);
35
    @ISA    = qw(Exporter);
36
	@EXPORT = qw(
36
    @EXPORT = qw(
37
		&recordpayment &makepayment &manualinvoice
37
      &recordpayment &makepayment &manualinvoice
38
		&getnextacctno &reconcileaccount &getcharges &getcredits
38
      &getnextacctno &reconcileaccount &getcharges 
39
		&getrefunds &chargelostitem
39
      &ModNote &ModMeansOfPayment &ModManagerId &getMeansOfPaymentList &getcredits
40
		&ReversePayment
40
      &getrefunds &chargelostitem
41
	); # removed &fixaccounts
41
      &ReversePayment
42
      );    # removed &fixaccounts
42
}
43
}
43
44
44
=head1 NAME
45
=head1 NAME
Lines 99-131 sub recordpayment { Link Here
99
        if ( $accdata->{'amountoutstanding'} < $amountleft ) {
100
        if ( $accdata->{'amountoutstanding'} < $amountleft ) {
100
            $newamtos = 0;
101
            $newamtos = 0;
101
            $amountleft -= $accdata->{'amountoutstanding'};
102
            $amountleft -= $accdata->{'amountoutstanding'};
102
        }
103
        } else {
103
        else {
104
            $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
104
            $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
105
            $amountleft = 0;
105
            $amountleft = 0;
106
        }
106
        }
107
        my $thisacct = $accdata->{accountno};
107
        my $thisacct = $accdata->{id};
108
        my $usth     = $dbh->prepare(
108
        my $usth     = $dbh->prepare(
109
            "UPDATE accountlines SET amountoutstanding= ?
109
            "UPDATE accountlines SET amountoutstanding= ?
110
     WHERE (borrowernumber = ?) AND (accountno=?)"
110
     WHERE (id = ?)"
111
        );
111
        );
112
        $usth->execute( $newamtos, $borrowernumber, $thisacct );
112
        $usth->execute( $newamtos, $borrowernumber, $thisacct );
113
        $usth->finish;
113
        $usth->finish;
114
#        $usth = $dbh->prepare(
114
115
#            "INSERT INTO accountoffsets
115
        #        $usth = $dbh->prepare(
116
#     (borrowernumber, accountno, offsetaccount,  offsetamount)
116
        #            "INSERT INTO accountoffsets
117
#     VALUES (?,?,?,?)"
117
        #     (borrowernumber, accountno, offsetaccount,  offsetamount)
118
#        );
118
        #     VALUES (?,?,?,?)"
119
#        $usth->execute( $borrowernumber, $accdata->{'accountno'},
119
        #        );
120
#            $nextaccntno, $newamtos );
120
        #        $usth->execute( $borrowernumber, $accdata->{'accountno'},
121
        #            $nextaccntno, $newamtos );
121
        $usth->finish;
122
        $usth->finish;
122
    }
123
    }
123
124
124
    # create new line
125
    # create new line
125
    my $usth = $dbh->prepare(
126
    my $usth = $dbh->prepare(
126
        "INSERT INTO accountlines
127
        "INSERT INTO accountlines
127
  (borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding)
128
  (borrowernumber, accountno,date,time,amount,description,accounttype,amountoutstanding)
128
  VALUES (?,?,now(),?,'Payment,thanks','Pay',?)"
129
  VALUES (?,?,now(),CURRENT_TIME,?,'Payment,thanks','Pay',?)"
129
    );
130
    );
130
    $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, 0 - $amountleft );
131
    $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, 0 - $amountleft );
131
    $usth->finish;
132
    $usth->finish;
Lines 135-141 sub recordpayment { Link Here
135
136
136
=head2 makepayment
137
=head2 makepayment
137
138
138
  &makepayment($borrowernumber, $acctnumber, $amount, $branchcode);
139
  &makepayment($accountlineid, $borrowernumber, $acctnumber, $amount, $branchcode, $note, $meansofpayment, $manager_id, $partpaymentamount);
139
140
140
Records the fact that a patron has paid off the entire amount he or
141
Records the fact that a patron has paid off the entire amount he or
141
she owes.
142
she owes.
Lines 144-150 C<$borrowernumber> is the patron's borrower number. C<$acctnumber> is Link Here
144
the account that was credited. C<$amount> is the amount paid (this is
145
the account that was credited. C<$amount> is the amount paid (this is
145
only used to record the payment. It is assumed to be equal to the
146
only used to record the payment. It is assumed to be equal to the
146
amount owed). C<$branchcode> is the code of the branch where payment
147
amount owed). C<$branchcode> is the code of the branch where payment
147
was made.
148
was made. if $partpaymentamount > 0 it's a part payment
148
149
149
=cut
150
=cut
150
151
Lines 156-211 sub makepayment { Link Here
156
    #here we update both the accountoffsets and the account lines
157
    #here we update both the accountoffsets and the account lines
157
    #updated to check, if they are paying off a lost item, we return the item
158
    #updated to check, if they are paying off a lost item, we return the item
158
    # from their card, and put a note on the item record
159
    # from their card, and put a note on the item record
159
    my ( $borrowernumber, $accountno, $amount, $user, $branch ) = @_;
160
    my ( $accountlineid, $borrowernumber, $accountno, $amount, $user, $branch, $note, $meansofpayment, $manager_id, $partpaymentamount ) = @_;
160
    my $dbh = C4::Context->dbh;
161
    my $dbh = C4::Context->dbh;
161
162
162
    # begin transaction
163
    # begin transaction
163
    my $nextaccntno = getnextacctno($borrowernumber);
164
    my $nextaccntno = getnextacctno($borrowernumber);
164
    my $newamtos    = 0;
165
    my $newamtos    = 0;
165
    my $sth =
166
    my $sth         = $dbh->prepare("SELECT * FROM accountlines WHERE id=?");
166
      $dbh->prepare(
167
    $sth->execute( $accountlineid );
167
        "SELECT * FROM accountlines WHERE  borrowernumber=? AND accountno=?");
168
    $sth->execute( $borrowernumber, $accountno );
169
    my $data = $sth->fetchrow_hashref;
168
    my $data = $sth->fetchrow_hashref;
170
    $sth->finish;
169
    $sth->finish;
171
170
    my $newamountoutstanding=0;
171
    my $payment = 0 - $amount;
172
    $payment = 0-$data->{'amountoutstanding'};
173
    my $finalamount = $amount;
174
    my $descriptionpayment="Payment for account n°".$accountno.",thanks - ".$user." : ".$data->{'description'};
175
	if($partpaymentamount!=0)
176
	{
177
		$newamountoutstanding=$data->{'amountoutstanding'}-$partpaymentamount;
178
		$payment = 0 - $partpaymentamount;
179
		$finalamount = $partpaymentamount;
180
		$descriptionpayment="Part Payment for account n°".$accountno.",thanks - ".$user." : ".$data->{'description'};
181
	}
172
    $dbh->do(
182
    $dbh->do(
173
        "UPDATE  accountlines
183
        "UPDATE  accountlines
174
        SET     amountoutstanding = 0
184
        SET     amountoutstanding = $newamountoutstanding
175
        WHERE   borrowernumber = $borrowernumber
185
        WHERE   id = $accountlineid
176
          AND   accountno = $accountno
177
        "
186
        "
178
    );
187
    );
179
188
180
    #  print $updquery;
189
    #  print $updquery;
181
#    $dbh->do( "
190
    #    $dbh->do( "
182
#        INSERT INTO     accountoffsets
191
    #        INSERT INTO     accountoffsets
183
#                        (borrowernumber, accountno, offsetaccount,
192
    #                        (borrowernumber, accountno, offsetaccount,
184
#                         offsetamount)
193
    #                         offsetamount)
185
#        VALUES          ($borrowernumber, $accountno, $nextaccntno, $newamtos)
194
    #        VALUES          ($borrowernumber, $accountno, $nextaccntno, $newamtos)
186
#        " );
195
    #        " );
187
196
188
    # create new line
197
    # create new line
189
    my $payment = 0 - $amount;
198
    
199
   
190
    $dbh->do( "
200
    $dbh->do( "
191
        INSERT INTO     accountlines
201
        INSERT INTO     accountlines
192
                        (borrowernumber, accountno, date, amount,
202
                        (borrowernumber, accountno, date, time, amount,
193
                         description, accounttype, amountoutstanding)
203
                         description, accounttype, amountoutstanding, note, meansofpayment, manager_id)
194
        VALUES          ($borrowernumber, $nextaccntno, now(), $payment,
204
        VALUES          ($borrowernumber, $nextaccntno, now(), CURRENT_TIME, $payment,
195
                        'Payment,thanks - $user', 'Pay', 0)
205
                        '$descriptionpayment', 'Pay', 0, '$note', '$meansofpayment', '$manager_id')
196
        " );
206
        " );
197
207
198
    # FIXME - The second argument to &UpdateStats is supposed to be the
208
    # FIXME - The second argument to &UpdateStats is supposed to be the
199
    # branch code.
209
    # branch code.
200
    # UpdateStats is now being passed $accountno too. MTJ
210
    # UpdateStats is now being passed $accountno too. MTJ
201
    UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber,
211
    UpdateStats( $user, 'payment', $finalamount, '', '', '', $borrowernumber, $accountno );
202
        $accountno );
203
    $sth->finish;
212
    $sth->finish;
204
213
205
    #check to see what accounttype
214
    #check to see what accounttype
206
    if ( $data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L' ) {
215
    if ( $data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L' ) {
207
        returnlost( $borrowernumber, $data->{'itemnumber'} );
216
        returnlost( $borrowernumber, $data->{'itemnumber'} );
208
    }
217
    }
218
     
219
    my $sth = $dbh->prepare("SELECT max(id) AS lastinsertid FROM accountlines");
220
    $sth->execute();
221
    my $datalastinsertid = $sth->fetchrow_hashref;
222
    $sth->finish;
223
    return $datalastinsertid->{'lastinsertid'};
209
}
224
}
210
225
211
=head2 getnextacctno
226
=head2 getnextacctno
Lines 228-250 sub getnextacctno ($) { Link Here
228
		 LIMIT 1"
243
		 LIMIT 1"
229
    );
244
    );
230
    $sth->execute($borrowernumber);
245
    $sth->execute($borrowernumber);
231
    return ($sth->fetchrow || 1);
246
    return ( $sth->fetchrow || 1 );
232
}
247
}
233
248
234
=head2 fixaccounts (removed)
249
=head2 fixaccounts (removed)
235
250
236
  &fixaccounts($borrowernumber, $accountnumber, $amount);
251
  &fixaccounts($accountlineid,$borrowernumber, $accountnumber, $amount);
237
252
238
#'
253
#'
239
# FIXME - I don't understand what this function does.
254
# FIXME - I don't understand what this function does.
240
sub fixaccounts {
255
sub fixaccounts {
241
    my ( $borrowernumber, $accountno, $amount ) = @_;
256
    my ( $accountlineid, $borrowernumber, $accountno, $amount ) = @_;
242
    my $dbh = C4::Context->dbh;
257
    my $dbh = C4::Context->dbh;
243
    my $sth = $dbh->prepare(
258
    my $sth = $dbh->prepare(
244
        "SELECT * FROM accountlines WHERE borrowernumber=?
259
        "SELECT * FROM accountlines WHERE id=?"
245
     AND accountno=?"
246
    );
260
    );
247
    $sth->execute( $borrowernumber, $accountno );
261
    $sth->execute( $accountlineid );
248
    my $data = $sth->fetchrow_hashref;
262
    my $data = $sth->fetchrow_hashref;
249
263
250
    # FIXME - Error-checking
264
    # FIXME - Error-checking
Lines 256-325 sub fixaccounts { Link Here
256
        UPDATE  accountlines
270
        UPDATE  accountlines
257
        SET     amount = '$amount',
271
        SET     amount = '$amount',
258
                amountoutstanding = '$outstanding'
272
                amountoutstanding = '$outstanding'
259
        WHERE   borrowernumber = $borrowernumber
273
        WHERE   id = $accountlineid
260
          AND   accountno = $accountno
261
EOT
274
EOT
262
	# FIXME: exceedingly bad form.  Use prepare with placholders ("?") in query and execute args.
275
	# FIXME: exceedingly bad form.  Use prepare with placholders ("?") in query and execute args.
263
}
276
}
264
277
265
=cut
278
=cut
266
279
267
sub returnlost{
280
sub returnlost {
268
    my ( $borrowernumber, $itemnum ) = @_;
281
    my ( $borrowernumber, $itemnum ) = @_;
269
    C4::Circulation::MarkIssueReturned( $borrowernumber, $itemnum );
282
    C4::Circulation::MarkIssueReturned( $borrowernumber, $itemnum );
270
    my $borrower = C4::Members::GetMember( 'borrowernumber'=>$borrowernumber );
283
    my $borrower = C4::Members::GetMember( 'borrowernumber' => $borrowernumber );
271
    my @datearr = localtime(time);
284
    my @datearr  = localtime(time);
272
    my $date = ( 1900 + $datearr[5] ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3];
285
    my $date     = ( 1900 + $datearr[5] ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3];
273
    my $bor = "$borrower->{'firstname'} $borrower->{'surname'} $borrower->{'cardnumber'}";
286
    my $bor      = "$borrower->{'firstname'} $borrower->{'surname'} $borrower->{'cardnumber'}";
274
    ModItem({ paidfor =>  "Paid for by $bor $date" }, undef, $itemnum);
287
    ModItem( { paidfor => "Paid for by $bor $date" }, undef, $itemnum );
275
}
288
}
276
289
290
sub chargelostitem {
277
291
278
sub chargelostitem{
292
    # lost ==1 Lost, lost==2 longoverdue, lost==3 lost and paid for
279
# lost ==1 Lost, lost==2 longoverdue, lost==3 lost and paid for
293
    # FIXME: itemlost should be set to 3 after payment is made, should be a warning to the interface that
280
# FIXME: itemlost should be set to 3 after payment is made, should be a warning to the interface that
294
    # a charge has been added
281
# a charge has been added
295
    # FIXME : if no replacement price, borrower just doesn't get charged?
282
# FIXME : if no replacement price, borrower just doesn't get charged?
296
283
   
297
    my $dbh          = C4::Context->dbh();
284
    my $dbh = C4::Context->dbh();
285
    my ($itemnumber) = @_;
298
    my ($itemnumber) = @_;
286
    my $sth=$dbh->prepare("SELECT issues.*,items.*,biblio.title 
299
    my $sth          = $dbh->prepare(
300
        "SELECT issues.*,items.*,biblio.title 
287
                           FROM issues 
301
                           FROM issues 
288
                           JOIN items USING (itemnumber) 
302
                           JOIN items USING (itemnumber) 
289
                           JOIN biblio USING (biblionumber)
303
                           JOIN biblio USING (biblionumber)
290
                           WHERE issues.itemnumber=?");
304
                           WHERE issues.itemnumber=?"
305
    );
291
    $sth->execute($itemnumber);
306
    $sth->execute($itemnumber);
292
    my $issues=$sth->fetchrow_hashref();
307
    my $issues = $sth->fetchrow_hashref();
293
308
294
    # if a borrower lost the item, add a replacement cost to the their record
309
    # if a borrower lost the item, add a replacement cost to the their record
295
    if ( $issues->{borrowernumber} ){
310
    if ( $issues->{borrowernumber} ) {
296
311
297
        # first make sure the borrower hasn't already been charged for this item
312
        # first make sure the borrower hasn't already been charged for this item
298
        my $sth1=$dbh->prepare("SELECT * from accountlines
313
        my $sth1 = $dbh->prepare(
299
        WHERE borrowernumber=? AND itemnumber=? and accounttype='L'");
314
            "SELECT * from accountlines
300
        $sth1->execute($issues->{'borrowernumber'},$itemnumber);
315
        WHERE borrowernumber=? AND itemnumber=? and accounttype='L'"
301
        my $existing_charge_hashref=$sth1->fetchrow_hashref();
316
        );
317
        $sth1->execute( $issues->{'borrowernumber'}, $itemnumber );
318
        my $existing_charge_hashref = $sth1->fetchrow_hashref();
302
319
303
        # OK, they haven't
320
        # OK, they haven't
304
        unless ($existing_charge_hashref) {
321
        unless ($existing_charge_hashref) {
322
305
            # This item is on issue ... add replacement cost to the borrower's record and mark it returned
323
            # This item is on issue ... add replacement cost to the borrower's record and mark it returned
306
            #  Note that we add this to the account even if there's no replacement price, allowing some other
324
            #  Note that we add this to the account even if there's no replacement price, allowing some other
307
            #  process (or person) to update it, since we don't handle any defaults for replacement prices.
325
            #  process (or person) to update it, since we don't handle any defaults for replacement prices.
308
            my $accountno = getnextacctno($issues->{'borrowernumber'});
326
            my $accountno = getnextacctno( $issues->{'borrowernumber'} );
309
            my $sth2=$dbh->prepare("INSERT INTO accountlines
327
            my $sth2      = $dbh->prepare(
310
            (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber)
328
                "INSERT INTO accountlines
311
            VALUES (?,?,now(),?,?,'L',?,?)");
329
            (borrowernumber,accountno,date,time,amount,description,accounttype,amountoutstanding,itemnumber)
312
            $sth2->execute($issues->{'borrowernumber'},$accountno,$issues->{'replacementprice'},
330
            VALUES (?,?,now(),CURRENT_TIME,?,?,'L',?,?)"
313
            "Lost Item $issues->{'title'} $issues->{'barcode'}",
331
            );
314
            $issues->{'replacementprice'},$itemnumber);
332
            $sth2->execute(
333
                $issues->{'borrowernumber'},
334
                $accountno,
335
                $issues->{'replacementprice'},
336
                "Lost Item $issues->{'title'} $issues->{'barcode'}",
337
                $issues->{'replacementprice'}, $itemnumber
338
            );
315
            $sth2->finish;
339
            $sth2->finish;
316
        # FIXME: Log this ?
340
341
            # FIXME: Log this ?
317
        }
342
        }
343
318
        #FIXME : Should probably have a way to distinguish this from an item that really was returned.
344
        #FIXME : Should probably have a way to distinguish this from an item that really was returned.
319
        warn " $issues->{'borrowernumber'}  /  $itemnumber ";
345
        warn " $issues->{'borrowernumber'}  /  $itemnumber ";
320
        C4::Circulation::MarkIssueReturned($issues->{borrowernumber},$itemnumber);
346
        C4::Circulation::MarkIssueReturned( $issues->{borrowernumber}, $itemnumber );
321
	#  Shouldn't MarkIssueReturned do this?
347
322
        C4::Items::ModItem({ onloan => undef }, undef, $itemnumber);
348
        #  Shouldn't MarkIssueReturned do this?
349
        C4::Items::ModItem( { onloan => undef }, undef, $itemnumber );
323
    }
350
    }
324
    $sth->finish;
351
    $sth->finish;
325
}
352
}
Lines 327-333 sub chargelostitem{ Link Here
327
=head2 manualinvoice
354
=head2 manualinvoice
328
355
329
  &manualinvoice($borrowernumber, $itemnumber, $description, $type,
356
  &manualinvoice($borrowernumber, $itemnumber, $description, $type,
330
                 $amount, $user);
357
                 $amount, $note, $meansofpayment);
331
358
332
C<$borrowernumber> is the patron's borrower number.
359
C<$borrowernumber> is the patron's borrower number.
333
C<$description> is a description of the transaction.
360
C<$description> is a description of the transaction.
Lines 340-346 should be the empty string. Link Here
340
367
341
#'
368
#'
342
# FIXME: In Koha 3.0 , the only account adjustment 'types' passed to this function
369
# FIXME: In Koha 3.0 , the only account adjustment 'types' passed to this function
343
# are :  
370
# are :
344
# 		'C' = CREDIT
371
# 		'C' = CREDIT
345
# 		'FOR' = FORGIVEN  (Formerly 'F', but 'F' is taken to mean 'FINE' elsewhere)
372
# 		'FOR' = FORGIVEN  (Formerly 'F', but 'F' is taken to mean 'FINE' elsewhere)
346
# 		'N' = New Card fee
373
# 		'N' = New Card fee
Lines 351-357 should be the empty string. Link Here
351
#
378
#
352
379
353
sub manualinvoice {
380
sub manualinvoice {
354
    my ( $borrowernumber, $itemnum, $desc, $type, $amount, $user ) = @_;
381
    my ( $borrowernumber, $itemnum, $desc, $type, $amount, $note, $meansofpayment ) = @_;
382
    my $manager_id = C4::Context->userenv->{'number'};
355
    my $dbh      = C4::Context->dbh;
383
    my $dbh      = C4::Context->dbh;
356
    my $notifyid = 0;
384
    my $notifyid = 0;
357
    my $insert;
385
    my $insert;
Lines 359-374 sub manualinvoice { Link Here
359
    my $accountno  = getnextacctno($borrowernumber);
387
    my $accountno  = getnextacctno($borrowernumber);
360
    my $amountleft = $amount;
388
    my $amountleft = $amount;
361
389
362
#    if (   $type eq 'CS'
390
    #    if (   $type eq 'CS'
363
#        || $type eq 'CB'
391
    #        || $type eq 'CB'
364
#        || $type eq 'CW'
392
    #        || $type eq 'CW'
365
#        || $type eq 'CF'
393
    #        || $type eq 'CF'
366
#        || $type eq 'CL' )
394
    #        || $type eq 'CL' )
367
#    {
395
    #    {
368
#        my $amount2 = $amount * -1;    # FIXME - $amount2 = -$amount
396
    #        my $amount2 = $amount * -1;    # FIXME - $amount2 = -$amount
369
#        $amountleft =
397
    #        $amountleft =
370
#          fixcredit( $borrowernumber, $amount2, $itemnum, $type, $user );
398
    #          fixcredit( $borrowernumber, $amount2, $itemnum, $type, $user );
371
#    }
399
    #    }
372
    if ( $type eq 'N' ) {
400
    if ( $type eq 'N' ) {
373
        $desc .= " New Card";
401
        $desc .= " New Card";
374
    }
402
    }
Lines 386-401 sub manualinvoice { Link Here
386
414
387
        $desc = " Lost Item";
415
        $desc = " Lost Item";
388
    }
416
    }
389
#    if ( $type eq 'REF' ) {
417
390
#        $desc .= " Cash Refund";
418
    #    if ( $type eq 'REF' ) {
391
#        $amountleft = refund( '', $borrowernumber, $amount );
419
    #        $desc .= " Cash Refund";
392
#    }
420
    #        $amountleft = refund( '', $borrowernumber, $amount );
421
    #    }
393
    if (   ( $type eq 'L' )
422
    if (   ( $type eq 'L' )
394
        or ( $type eq 'F' )
423
        or ( $type eq 'F' )
395
        or ( $type eq 'A' )
424
        or ( $type eq 'A' )
396
        or ( $type eq 'N' )
425
        or ( $type eq 'N' )
397
        or ( $type eq 'M' ) )
426
        or ( $type eq 'M' ) ) {
398
    {
399
        $notifyid = 1;
427
        $notifyid = 1;
400
    }
428
    }
401
429
Lines 403-418 sub manualinvoice { Link Here
403
        $desc .= " " . $itemnum;
431
        $desc .= " " . $itemnum;
404
        my $sth = $dbh->prepare(
432
        my $sth = $dbh->prepare(
405
            "INSERT INTO  accountlines
433
            "INSERT INTO  accountlines
406
                        (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, itemnumber,notify_id)
434
                        (borrowernumber, accountno, date, time, amount, description, accounttype, amountoutstanding, itemnumber,notify_id, note, manager_id, meansofpayment)
407
        VALUES (?, ?, now(), ?,?, ?,?,?,?)");
435
        VALUES (?, ?, now(),CURRENT_TIME, ?,?, ?,?,?,?,?,?,?)"
408
     $sth->execute($borrowernumber, $accountno, $amount, $desc, $type, $amountleft, $itemnum,$notifyid) || return $sth->errstr;
436
        );
409
  } else {
437
        $sth->execute( $borrowernumber, $accountno, $amount, $desc, $type, $amountleft, $itemnum, $notifyid, $note, $manager_id, $meansofpayment ) || return $sth->errstr;
410
    my $sth=$dbh->prepare("INSERT INTO  accountlines
438
    } else {
411
            (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding,notify_id)
439
        my $sth = $dbh->prepare(
412
            VALUES (?, ?, now(), ?, ?, ?, ?,?)"
440
            "INSERT INTO  accountlines
441
            (borrowernumber, accountno, date, time, amount, description, accounttype, amountoutstanding,notify_id, note, manager_id, meansofpayment)
442
            VALUES (?, ?, now(),CURRENT_TIME, ?, ?, ?, ?,?,?,?,?)"
413
        );
443
        );
414
        $sth->execute( $borrowernumber, $accountno, $amount, $desc, $type,
444
        $sth->execute( $borrowernumber, $accountno, $amount, $desc, $type, $amountleft, $notifyid, $note, $manager_id, $meansofpayment );
415
            $amountleft, $notifyid );
416
    }
445
    }
417
    return 0;
446
    return 0;
418
}
447
}
Lines 442-453 sub fixcredit { Link Here
442
    AND itemnumber=? AND amountoutstanding > 0)";
471
    AND itemnumber=? AND amountoutstanding > 0)";
443
        if ( $type eq 'CL' ) {
472
        if ( $type eq 'CL' ) {
444
            $query .= " AND (accounttype = 'L' OR accounttype = 'Rep')";
473
            $query .= " AND (accounttype = 'L' OR accounttype = 'Rep')";
445
        }
474
        } elsif ( $type eq 'CF' ) {
446
        elsif ( $type eq 'CF' ) {
447
            $query .= " AND (accounttype = 'F' OR accounttype = 'FU' OR
475
            $query .= " AND (accounttype = 'F' OR accounttype = 'FU' OR
448
      accounttype='Res' OR accounttype='Rent')";
476
      accounttype='Res' OR accounttype='Rent')";
449
        }
477
        } elsif ( $type eq 'CB' ) {
450
        elsif ( $type eq 'CB' ) {
451
            $query .= " and accounttype='A'";
478
            $query .= " and accounttype='A'";
452
        }
479
        }
453
480
Lines 459-483 sub fixcredit { Link Here
459
        if ( $accdata->{'amountoutstanding'} < $amountleft ) {
486
        if ( $accdata->{'amountoutstanding'} < $amountleft ) {
460
            $newamtos = 0;
487
            $newamtos = 0;
461
            $amountleft -= $accdata->{'amountoutstanding'};
488
            $amountleft -= $accdata->{'amountoutstanding'};
462
        }
489
        } else {
463
        else {
464
            $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
490
            $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
465
            $amountleft = 0;
491
            $amountleft = 0;
466
        }
492
        }
467
        my $thisacct = $accdata->{accountno};
493
        my $thisacct = $accdata->{id};
468
        my $usth     = $dbh->prepare(
494
        my $usth     = $dbh->prepare(
469
            "UPDATE accountlines SET amountoutstanding= ?
495
            "UPDATE accountlines SET amountoutstanding= ?
470
     WHERE (borrowernumber = ?) AND (accountno=?)"
496
     WHERE (id = ?)"
471
        );
497
        );
472
        $usth->execute( $newamtos, $borrowernumber, $thisacct );
498
        $usth->execute( $newamtos, $thisacct );
473
        $usth->finish;
499
        $usth->finish;
474
        $usth = $dbh->prepare(
500
        $usth = $dbh->prepare(
475
            "INSERT INTO accountoffsets
501
            "INSERT INTO accountoffsets
476
     (borrowernumber, accountno, offsetaccount,  offsetamount)
502
     (borrowernumber, accountno, offsetaccount,  offsetamount)
477
     VALUES (?,?,?,?)"
503
     VALUES (?,?,?,?)"
478
        );
504
        );
479
        $usth->execute( $borrowernumber, $accdata->{'accountno'},
505
        $usth->execute( $borrowernumber, $accdata->{'accountno'}, $nextaccntno, $newamtos );
480
            $nextaccntno, $newamtos );
481
        $usth->finish;
506
        $usth->finish;
482
    }
507
    }
483
508
Lines 498-522 sub fixcredit { Link Here
498
        if ( $accdata->{'amountoutstanding'} < $amountleft ) {
523
        if ( $accdata->{'amountoutstanding'} < $amountleft ) {
499
            $newamtos = 0;
524
            $newamtos = 0;
500
            $amountleft -= $accdata->{'amountoutstanding'};
525
            $amountleft -= $accdata->{'amountoutstanding'};
501
        }
526
        } else {
502
        else {
503
            $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
527
            $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
504
            $amountleft = 0;
528
            $amountleft = 0;
505
        }
529
        }
506
        my $thisacct = $accdata->{accountno};
530
        my $thisacct = $accdata->{id};
507
        my $usth     = $dbh->prepare(
531
        my $usth     = $dbh->prepare(
508
            "UPDATE accountlines SET amountoutstanding= ?
532
            "UPDATE accountlines SET amountoutstanding= ?
509
     WHERE (borrowernumber = ?) AND (accountno=?)"
533
     WHERE (id = ?)"
510
        );
534
        );
511
        $usth->execute( $newamtos, $borrowernumber, $thisacct );
535
        $usth->execute( $newamtos, $thisacct );
512
        $usth->finish;
536
        $usth->finish;
513
        $usth = $dbh->prepare(
537
        $usth = $dbh->prepare(
514
            "INSERT INTO accountoffsets
538
            "INSERT INTO accountoffsets
515
     (borrowernumber, accountno, offsetaccount,  offsetamount)
539
     (borrowernumber, accountno, offsetaccount,  offsetamount)
516
     VALUE (?,?,?,?)"
540
     VALUE (?,?,?,?)"
517
        );
541
        );
518
        $usth->execute( $borrowernumber, $accdata->{'accountno'},
542
        $usth->execute( $borrowernumber, $accdata->{'accountno'}, $nextaccntno, $newamtos );
519
            $nextaccntno, $newamtos );
520
        $usth->finish;
543
        $usth->finish;
521
    }
544
    }
522
    $sth->finish;
545
    $sth->finish;
Lines 562-588 sub refund { Link Here
562
        if ( $accdata->{'amountoutstanding'} > $amountleft ) {
585
        if ( $accdata->{'amountoutstanding'} > $amountleft ) {
563
            $newamtos = 0;
586
            $newamtos = 0;
564
            $amountleft -= $accdata->{'amountoutstanding'};
587
            $amountleft -= $accdata->{'amountoutstanding'};
565
        }
588
        } else {
566
        else {
567
            $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
589
            $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
568
            $amountleft = 0;
590
            $amountleft = 0;
569
        }
591
        }
570
592
571
        #     print $amountleft;
593
        #     print $amountleft;
572
        my $thisacct = $accdata->{accountno};
594
        my $thisacct = $accdata->{id};
573
        my $usth     = $dbh->prepare(
595
        my $usth     = $dbh->prepare(
574
            "UPDATE accountlines SET amountoutstanding= ?
596
            "UPDATE accountlines SET amountoutstanding= ?
575
     WHERE (borrowernumber = ?) AND (accountno=?)"
597
     WHERE (id = ?)"
576
        );
598
        );
577
        $usth->execute( $newamtos, $borrowernumber, $thisacct );
599
        $usth->execute( $newamtos, $thisacct );
578
        $usth->finish;
600
        $usth->finish;
579
        $usth = $dbh->prepare(
601
        $usth = $dbh->prepare(
580
            "INSERT INTO accountoffsets
602
            "INSERT INTO accountoffsets
581
     (borrowernumber, accountno, offsetaccount,  offsetamount)
603
     (borrowernumber, accountno, offsetaccount,  offsetamount)
582
     VALUES (?,?,?,?)"
604
     VALUES (?,?,?,?)"
583
        );
605
        );
584
        $usth->execute( $borrowernumber, $accdata->{'accountno'},
606
        $usth->execute( $borrowernumber, $accdata->{'accountno'}, $nextaccntno, $newamtos );
585
            $nextaccntno, $newamtos );
586
        $usth->finish;
607
        $usth->finish;
587
    }
608
    }
588
    $sth->finish;
609
    $sth->finish;
Lines 590-637 sub refund { Link Here
590
}
611
}
591
612
592
sub getcharges {
613
sub getcharges {
593
	my ( $borrowerno, $timestamp, $accountno ) = @_;
614
    my ( $borrowerno, $timestamp, $accountno ) = @_;
594
	my $dbh        = C4::Context->dbh;
615
    my $dbh        = C4::Context->dbh;
595
	my $timestamp2 = $timestamp - 1;
616
    my $timestamp2 = $timestamp - 1;
596
	my $query      = "";
617
    my $query      = "";
597
	my $sth = $dbh->prepare(
618
    my $sth        = $dbh->prepare( "SELECT * FROM accountlines WHERE borrowernumber=? AND accountno = ?" );
598
			"SELECT * FROM accountlines WHERE borrowernumber=? AND accountno = ?"
619
    $sth->execute( $borrowerno, $accountno );
599
          );
620
600
	$sth->execute( $borrowerno, $accountno );
601
	
602
    my @results;
621
    my @results;
603
    while ( my $data = $sth->fetchrow_hashref ) {
622
    while ( my $data = $sth->fetchrow_hashref ) {
604
		push @results,$data;
623
        push @results, $data;
605
	}
624
    }
606
    return (@results);
625
    return (@results);
607
}
626
}
608
627
628
sub ModNote {
629
    my ( $accountlineid, $note ) = @_;
630
    my $dbh = C4::Context->dbh;
631
    my $sth = $dbh->prepare('UPDATE accountlines SET note = ? WHERE id = ?');
632
    $sth->execute( $note, $accountlineid );
633
}
634
635
sub ModMeansOfPayment {
636
    my ( $accountlineid, $meansofpayment ) = @_;
637
    my $dbh = C4::Context->dbh;
638
    my $sth = $dbh->prepare('UPDATE accountlines SET meansofpayment = ? WHERE id = ?');
639
    $sth->execute( $meansofpayment, $accountlineid );
640
}
641
642
sub ModManagerId {
643
    my ( $accountlineid, $manager_id ) = @_;
644
    my $dbh = C4::Context->dbh;
645
    my $sth = $dbh->prepare('UPDATE accountlines SET manager_id = ? WHERE id = ?');
646
    $sth->execute( $manager_id, $accountlineid );
647
}
648
649
sub getMeansOfPaymentList {
650
	my ($selectedoption) = @_;
651
	my $dbh  = C4::Context->dbh;
652
	my $sth = $dbh->prepare( "SELECT * FROM `systempreferences` WHERE variable='MeansOfPayment'" );
653
	$sth->execute();
654
	my @options;
655
	my $booloption=0;
656
	while ( my $data = $sth->fetchrow_hashref ) {
657
	foreach my $option ( split( /\|/, $data->{'value'} ) ) {
658
            my $selected = '';
659
            if($option eq $selectedoption)
660
            {
661
            	$selected = ' selected="selected"';
662
            	$booloption=1;
663
            }
664
            push @options, { option => $option, selected => $selected };
665
        }
666
	}
667
	if($booloption==0 && $selectedoption ne "")
668
	{
669
		push @options, { option => $selectedoption, selected => ' selected="selected"' };
670
	}
671
    $sth->finish;
672
    return \@options;
673
}
609
674
610
sub getcredits {
675
sub getcredits {
611
	my ( $date, $date2 ) = @_;
676
    my ( $date, $date2 ) = @_;
612
	my $dbh = C4::Context->dbh;
677
    my $dbh = C4::Context->dbh;
613
	my $sth = $dbh->prepare(
678
    my $sth = $dbh->prepare(
614
			        "SELECT * FROM accountlines,borrowers
679
        "SELECT * FROM accountlines,borrowers
615
      WHERE amount < 0 AND accounttype <> 'Pay' AND accountlines.borrowernumber = borrowers.borrowernumber
680
      WHERE amount < 0 AND accounttype <> 'Pay' AND accountlines.borrowernumber = borrowers.borrowernumber
616
	  AND timestamp >=TIMESTAMP(?) AND timestamp < TIMESTAMP(?)"
681
	  AND timestamp >=TIMESTAMP(?) AND timestamp < TIMESTAMP(?)"
617
      );  
682
    );
618
683
619
    $sth->execute( $date, $date2 );                                                                                                              
684
    $sth->execute( $date, $date2 );
620
    my @results;          
685
    my @results;
621
    while ( my $data = $sth->fetchrow_hashref ) {
686
    while ( my $data = $sth->fetchrow_hashref ) {
622
		$data->{'date'} = $data->{'timestamp'};
687
        $data->{'date'} = $data->{'timestamp'};
623
		push @results,$data;
688
        push @results, $data;
624
	}
689
    }
625
    return (@results);
690
    return (@results);
626
} 
691
}
627
628
692
629
sub getrefunds {
693
sub getrefunds {
630
	my ( $date, $date2 ) = @_;
694
    my ( $date, $date2 ) = @_;
631
	my $dbh = C4::Context->dbh;
695
    my $dbh = C4::Context->dbh;
632
	
696
633
	my $sth = $dbh->prepare(
697
    my $sth = $dbh->prepare(
634
			        "SELECT *,timestamp AS datetime                                                                                      
698
        "SELECT *,timestamp AS datetime                                                                                      
635
                  FROM accountlines,borrowers
699
                  FROM accountlines,borrowers
636
                  WHERE (accounttype = 'REF'
700
                  WHERE (accounttype = 'REF'
637
					  AND accountlines.borrowernumber = borrowers.borrowernumber
701
					  AND accountlines.borrowernumber = borrowers.borrowernumber
Lines 642-669 sub getrefunds { Link Here
642
706
643
    my @results;
707
    my @results;
644
    while ( my $data = $sth->fetchrow_hashref ) {
708
    while ( my $data = $sth->fetchrow_hashref ) {
645
		push @results,$data;
709
        push @results, $data;
646
		
710
647
	}
711
    }
648
    return (@results);
712
    return (@results);
649
}
713
}
650
714
651
sub ReversePayment {
715
sub ReversePayment {
652
  my ( $borrowernumber, $accountno ) = @_;
716
    my ( $accountlineid ) = @_;
653
  my $dbh = C4::Context->dbh;
717
    my $dbh = C4::Context->dbh;
654
  
718
655
  my $sth = $dbh->prepare('SELECT amountoutstanding FROM accountlines WHERE borrowernumber = ? AND accountno = ?');
719
    my $sth = $dbh->prepare('SELECT amountoutstanding FROM accountlines WHERE id = ?');
656
  $sth->execute( $borrowernumber, $accountno );
720
    $sth->execute( $accountlineid );
657
  my $row = $sth->fetchrow_hashref();
721
    my $row                = $sth->fetchrow_hashref();
658
  my $amount_outstanding = $row->{'amountoutstanding'};
722
    my $amount_outstanding = $row->{'amountoutstanding'};
659
  
723
660
  if ( $amount_outstanding <= 0 ) {
724
    if ( $amount_outstanding <= 0 ) {
661
    $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = amount * -1, description = CONCAT( description, " Reversed -" ) WHERE borrowernumber = ? AND accountno = ?');
725
        $sth =
662
    $sth->execute( $borrowernumber, $accountno );
726
          $dbh->prepare('UPDATE accountlines SET amountoutstanding = amount * -1, description = CONCAT( description, " Reversed -" ) WHERE id = ?');
663
  } else {
727
        $sth->execute( $accountlineid );
664
    $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = 0, description = CONCAT( description, " Reversed -" ) WHERE borrowernumber = ? AND accountno = ?');
728
    } else {
665
    $sth->execute( $borrowernumber, $accountno );
729
        $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = 0, description = CONCAT( description, " Reversed -" ) WHERE id = ?');
666
  }
730
        $sth->execute( $accountlineid );
731
    }
667
}
732
}
668
733
669
END { }    # module clean-up code here (global destructor)
734
END { }    # module clean-up code here (global destructor)
(-)a/koha-tmpl/intranet-tmpl/prog/en/lib/jquery/plugins/jquery.numeric.js (+127 lines)
Line 0 Link Here
1
/*
2
 *
3
 * Copyright (c) 2006/2007 Sam Collett (http://www.texotela.co.uk)
4
 * Licensed under the MIT License:
5
 * http://www.opensource.org/licenses/mit-license.php
6
 * 
7
 * Version 1.0
8
 * Demo: http://www.texotela.co.uk/code/jquery/numeric/
9
 *
10
 * $LastChangedDate: 2007-05-29 11:31:36 +0100 (Tue, 29 May 2007) $
11
 * $Rev: 2005 $
12
 */
13
 
14
/*
15
 * Allows only valid characters to be entered into input boxes.
16
 * Note: does not validate that the final text is a valid number
17
 * (that could be done by another script, or server-side)
18
 *
19
 * @name     numeric
20
 * @param    decimal      Decimal separator (e.g. '.' or ',' - default is '.')
21
 * @param    callback     A function that runs if the number is not valid (fires onblur)
22
 * @author   Sam Collett (http://www.texotela.co.uk)
23
 * @example  $(".numeric").numeric();
24
 * @example  $(".numeric").numeric(",");
25
 * @example  $(".numeric").numeric(null, callback);
26
 *
27
 */
28
jQuery.fn.numeric = function(decimal, callback)
29
{
30
	decimal = decimal || ".";
31
	callback = typeof callback == "function" ? callback : function(){};
32
	this.keypress(
33
		function(e)
34
		{
35
			var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
36
			// allow enter/return key (only when in an input box)
37
			if(key == 13 && this.nodeName.toLowerCase() == "input")
38
			{
39
				return true;
40
			}
41
			else if(key == 13)
42
			{
43
				return false;
44
			}
45
			var allow = false;
46
			// allow Ctrl+A
47
			if((e.ctrlKey && key == 97 /* firefox */) || (e.ctrlKey && key == 65) /* opera */) return true;
48
			// allow Ctrl+X (cut)
49
			if((e.ctrlKey && key == 120 /* firefox */) || (e.ctrlKey && key == 88) /* opera */) return true;
50
			// allow Ctrl+C (copy)
51
			if((e.ctrlKey && key == 99 /* firefox */) || (e.ctrlKey && key == 67) /* opera */) return true;
52
			// allow Ctrl+Z (undo)
53
			if((e.ctrlKey && key == 122 /* firefox */) || (e.ctrlKey && key == 90) /* opera */) return true;
54
			// allow or deny Ctrl+V (paste), Shift+Ins
55
			if((e.ctrlKey && key == 118 /* firefox */) || (e.ctrlKey && key == 86) /* opera */
56
			|| (e.shiftKey && key == 45)) return true;
57
			// if a number was not pressed
58
			if(key < 48 || key > 57)
59
			{
60
				/* '-' only allowed at start */
61
				if(key == 45 && this.value.length == 0) return true;
62
				/* only one decimal separator allowed */
63
				if(key == decimal.charCodeAt(0) && this.value.indexOf(decimal) != -1)
64
				{
65
					allow = false;
66
				}
67
				// check for other keys that have special purposes
68
				if(
69
					key != 8 /* backspace */ &&
70
					key != 9 /* tab */ &&
71
					key != 13 /* enter */ &&
72
					key != 35 /* end */ &&
73
					key != 36 /* home */ &&
74
					key != 37 /* left */ &&
75
					key != 39 /* right */ &&
76
					key != 46 /* del */
77
				)
78
				{
79
					allow = false;
80
				}
81
				else
82
				{
83
					// for detecting special keys (listed above)
84
					// IE does not support 'charCode' and ignores them in keypress anyway
85
					if(typeof e.charCode != "undefined")
86
					{
87
						// special keys have 'keyCode' and 'which' the same (e.g. backspace)
88
						if(e.keyCode == e.which && e.which != 0)
89
						{
90
							allow = true;
91
						}
92
						// or keyCode != 0 and 'charCode'/'which' = 0
93
						else if(e.keyCode != 0 && e.charCode == 0 && e.which == 0)
94
						{
95
							allow = true;
96
						}
97
					}
98
				}
99
				// if key pressed is the decimal and it is not already in the field
100
				if(key == decimal.charCodeAt(0) && this.value.indexOf(decimal) == -1)
101
				{
102
					allow = true;
103
				}
104
			}
105
			else
106
			{
107
				allow = true;
108
			}
109
			return allow;
110
		}
111
	)
112
	.blur(
113
		function()
114
		{
115
			var val = jQuery(this).val();
116
			if(val != "")
117
			{
118
				var re = new RegExp("^\\d+$|\\d*" + decimal + "\\d+");
119
				if(!re.exec(val))
120
				{
121
					callback.apply(this);
122
				}
123
			}
124
		}
125
	);
126
	return this;
127
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tmpl (-15 / +46 lines)
Lines 1-6 Link Here
1
<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
1
<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
2
<title>Koha &rsaquo; Patrons &rsaquo; Account for <!-- TMPL_VAR NAME="firstname" --> <!-- TMPL_VAR NAME="surname" --></title>
2
<title>Koha &rsaquo; Patrons &rsaquo; Account for <!-- TMPL_VAR NAME="firstname" --> <!-- TMPL_VAR NAME="surname" --></title>
3
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
3
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
4
<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/jquery/plugins/jquery.tablesorter.min.js"></script>
5
<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/jquery/plugins/jquery.tablesorter.pager.js"></script>
6
<script type="text/javascript" id="js">$(document).ready(function() {
7
	$("#table_boracount").tablesorter({
8
		sortList: [[0,0]],
9
	}).tablesorterPager({container: $("#pagertable_boracount"),positionFixed: false,size: 20});
10
}); </script>
4
</head>
11
</head>
5
<body>
12
<body>
6
<!-- TMPL_INCLUDE NAME="header.inc" -->
13
<!-- TMPL_INCLUDE NAME="header.inc" -->
Lines 26-74 Link Here
26
</ul>
33
</ul>
27
<div class="tabs-container">
34
<div class="tabs-container">
28
<!-- The table with the account items -->
35
<!-- The table with the account items -->
29
<table>
36
<span id="pagertable_boracount" class="pager">
30
  <tr>
37
	<form class="formpager">&nbsp;<strong>page(s)</strong>&nbsp;:
38
		<img src="<!-- TMPL_VAR name="interface" -->/prog/img/first.png" class="first"/>
39
		<img src="<!-- TMPL_VAR name="interface" -->/prog/img/prev.png" class="prev"/>
40
		<input type="text" size="5" class="pagedisplay"/>
41
		<img src="<!-- TMPL_VAR name="interface" -->/prog/img/next.png" class="next"/>
42
		<img src="<!-- TMPL_VAR name="interface" -->/prog/img/last.png" class="last"/>
43
		, entries/page : 
44
		<select class="pagesize">
45
        	<option value="10">10</option>
46
			<option selected="selected" value="20">20</option>
47
			<option value="30">30</option>
48
			<option value="40">40</option>
49
			<option value="50">50</option>
50
			<option value="100">100</option>
51
		</select>
52
	</form>
53
</span>
54
<table id="table_boracount">
55
  <thead>
31
  	<th>Date</th>
56
  	<th>Date</th>
57
  	<th style="padding:0.2em 14px">n°</th>
58
  	<th>Means of payment</th>
32
    <th>Description of charges</th>
59
    <th>Description of charges</th>
33
    <th>Amount</th>
60
    <th>Amount</th>
34
    <th>Outstanding</th>
61
    <th>Outstanding</th>
62
    <th>Manager</th>
35
    <!-- TMPL_IF NAME="reverse_col" -->
63
    <!-- TMPL_IF NAME="reverse_col" -->
36
    <th>&nbsp;</th>
64
    <th>&nbsp;</th>
37
    <!-- /TMPL_IF -->
38
    <th>Print</th>
65
    <th>Print</th>
39
  </tr>
66
    <!-- /TMPL_IF -->
67
  </thead>
40
68
41
	<!-- FIXME: Shouldn't hardcode dollar signs, since Euro or Pound might be needed -->
69
	<!-- FIXME: Shouldn't hardcode dollar signs, since Euro or Pound might be needed -->
42
  <!-- TMPL_LOOP NAME="accounts" -->
70
  <!-- TMPL_LOOP NAME="accounts" -->
43
71
44
   <!-- TMPL_IF NAME="__odd__" --><tr><!-- TMPL_ELSE --><tr class="highlight"><!-- /TMPL_IF -->
72
   <!-- TMPL_IF NAME="__odd__" --><tr><!-- TMPL_ELSE --><tr><!-- /TMPL_IF -->
45
      <td><!-- TMPL_VAR NAME="date" --></td>
73
      <td><!-- TMPL_VAR NAME="date" --> <!-- TMPL_VAR NAME="time" --></td>
74
      <td><!-- TMPL_VAR NAME="accountno" --></td>
75
      <td><!-- TMPL_VAR NAME="meansofpayment" --></td>
46
      <td><!-- TMPL_VAR NAME="description" -->&nbsp;<!-- TMPL_IF NAME="itemnumber" --><a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->&amp;itemnumber=<!-- TMPL_VAR NAME="itemnumber" -->">View item</a>&nbsp;<!-- /TMPL_IF --><!-- TMPL_IF NAME="printtitle" --> <!-- TMPL_VAR NAME="title" escape="html" --><!-- /TMPL_IF --></td>
76
      <td><!-- TMPL_VAR NAME="description" -->&nbsp;<!-- TMPL_IF NAME="itemnumber" --><a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->&amp;itemnumber=<!-- TMPL_VAR NAME="itemnumber" -->">View item</a>&nbsp;<!-- /TMPL_IF --><!-- TMPL_IF NAME="printtitle" --> <!-- TMPL_VAR NAME="title" escape="html" --><!-- /TMPL_IF --></td>
47
      <!-- TMPL_IF NAME="amountcredit" --><td class="credit"><!-- TMPL_ELSE --><td class="debit"><!-- /TMPL_IF --><!-- TMPL_VAR NAME="amount" --></td>
77
      <!-- TMPL_IF NAME="amountcredit" --><td class="credit"><!-- TMPL_ELSE --><td class="debit"><!-- /TMPL_IF --><!-- TMPL_VAR NAME="amount" --></td>
48
      <!-- TMPL_IF NAME="amountoutstandingcredit" --><td class="credit"><!-- TMPL_ELSE --><td class="debit"><!-- /TMPL_IF --><!-- TMPL_VAR NAME="amountoutstanding" --></td>
78
      <!-- TMPL_IF NAME="amountoutstandingcredit" --><td class="credit"><!-- TMPL_ELSE --><td class="debit"><!-- /TMPL_IF --><!-- TMPL_VAR NAME="amountoutstanding" --></td>
79
    <td><!-- TMPL_VAR NAME="manager_details" --></td>
49
    <!-- TMPL_IF NAME="reverse_col" -->
80
    <!-- TMPL_IF NAME="reverse_col" -->
50
      <td>
81
      <td>
51
	<!-- TMPL_IF NAME="payment" -->
82
	<!-- TMPL_IF NAME="payment" -->
52
		<a href="boraccount.pl?action=reverse&amp;borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->&amp;accountno=<!-- TMPL_VAR NAME="accountno" -->">Reverse</a>
83
		<a href="boraccount.pl?action=reverse&borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->&accountno=<!-- TMPL_VAR NAME="accountno" -->&accountlineid=<!-- TMPL_VAR NAME="id" -->">Reverse</a>
53
	<!-- TMPL_ELSE -->
84
	<!-- TMPL_ELSE -->
54
		&nbsp;
85
		&nbsp;
55
	<!-- /TMPL_IF -->
86
	<!-- /TMPL_IF -->
56
      </td>
87
      </td>
57
	<!-- /TMPL_IF -->
88
	<!-- /TMPL_IF -->
58
<td>
89
    <td>
59
	<!-- TMPL_IF NAME="payment" -->
90
	    <!-- TMPL_IF NAME="payment" -->
60
		<a target="_blank" href="printfeercpt.pl?action=print&amp;borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->&amp;accountno=<!-- TMPL_VAR NAME="accountno" -->">Print</a>
91
		    <a target="_blank" href="printfeercpt.pl?action=print&amp;borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->&amp;accountno=<!-- TMPL_VAR NAME="accountno" -->">Print</a>
61
	<!-- TMPL_ELSE -->
92
	    <!-- TMPL_ELSE -->
62
		<a target="_blank" href="printinvoice.pl?action=print&amp;borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->&amp;accountno=<!-- TMPL_VAR NAME="accountno" -->">Print</a>
93
		    <a target="_blank" href="printinvoice.pl?action=print&amp;borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->&amp;accountno=<!-- TMPL_VAR NAME="accountno" -->">Print</a>
63
	<!-- /TMPL_IF -->
94
	    <!-- /TMPL_IF -->
64
      </td>
95
      </td>
65
    </tr>
96
    </tr>
66
97
67
  <!-- /TMPL_LOOP -->
98
  <!-- /TMPL_LOOP -->
68
<tfoot>
99
<tfoot>
69
  <tr>
100
  <tr>
70
    <td colspan="4">Total due</td>
101
    <td colspan="6">Total due</td>
71
    <!-- TMPL_IF NAME="totalcredit" --><td colspan="2" class="credit"><!-- TMPL_ELSE --><td colspan="2" class="debit"><!-- /TMPL_IF --><!-- TMPL_VAR NAME="total" --></td>
102
    <!-- TMPL_IF NAME="totalcredit" --><td colspan="3" class="credit"><!-- TMPL_ELSE --><td colspan="3" class="debit"><!-- /TMPL_IF --><!-- TMPL_VAR NAME="total" --></td>
72
  </tr>
103
  </tr>
73
  </tfoot>
104
  </tfoot>
74
</table>
105
</table>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tmpl (-5 / +62 lines)
Lines 1-6 Link Here
1
<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
1
<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
2
<title>Koha &rsaquo; Patrons &rsaquo; Pay Fines for  <!-- TMPL_VAR NAME="firstname" --> <!-- TMPL_VAR NAME="surname" --></title>
2
<title>Koha &rsaquo; Patrons &rsaquo; Pay Fines for  <!-- TMPL_VAR NAME="firstname" --> <!-- TMPL_VAR NAME="surname" --></title>
3
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
3
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
4
<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/jquery/plugins/jquery.numeric.js"></script>
5
<script type="text/javascript">
6
$(function(){$("input.numeric_only").numeric();});
7
</script>
8
<script type="text/javascript">
9
function payfinechange(value,accountlineid)
10
{
11
	if(value=="pp")
12
	{
13
		document.getElementById("partpaymentamount"+accountlineid).readOnly=false;
14
	}
15
	else
16
	{
17
		document.getElementById("partpaymentamount"+accountlineid).readOnly=true;
18
	}
19
}
20
21
function partpaymentchange(value,accountlineid,amountoutstanding)
22
{
23
	if(value>amountoutstanding)
24
	{
25
		document.getElementById("partpaymentamount"+accountlineid).value=amountoutstanding;
26
	}
27
	if(value<0)
28
	{
29
		value=0-value;
30
		document.getElementById("partpaymentamount"+accountlineid).value=value;
31
	}
32
}
33
</script>
34
4
</head>
35
</head>
5
<body>
36
<body>
6
<!-- TMPL_INCLUDE NAME="header.inc" -->
37
<!-- TMPL_INCLUDE NAME="header.inc" -->
Lines 31-37 Link Here
31
<table>
62
<table>
32
<tr>
63
<tr>
33
	<th>Fines &amp; Charges</th>
64
	<th>Fines &amp; Charges</th>
65
	<th>Means of payment</th>
34
	<th>Description</th>
66
	<th>Description</th>
67
	<th>Note</th>
68
	<th>Part payment</th>
35
	<th>Account Type</th>
69
	<th>Account Type</th>
36
	<th>Notify id</th>
70
	<th>Notify id</th>
37
	<th>Level</th>
71
	<th>Level</th>
Lines 42-53 Link Here
42
<!-- TMPL_LOOP name="allfile" -->
76
<!-- TMPL_LOOP name="allfile" -->
43
	<!-- TMPL_LOOP name="loop_pay" -->
77
	<!-- TMPL_LOOP name="loop_pay" -->
44
<tr>
78
<tr>
45
	<td>
79
	<td><input type="hidden" name="accountlineid<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="accountlineid" -->" />
80
	
46
	<!-- TMPL_IF NAME="net_balance" -->
81
	<!-- TMPL_IF NAME="net_balance" -->
47
	<select name="payfine<!-- TMPL_VAR name="i" -->">
82
	<select name="payfine<!-- TMPL_VAR name="i" -->" onChange="payfinechange(this.value,<!-- TMPL_VAR name="i" -->)">
48
	<option value="no">Unpaid</option>
83
	<option value="no">Unpaid</option>
49
	<option value="yes">Paid</option>
84
	<option value="yes">Paid</option>
50
	<option value="wo">Writeoff</option>
85
	<option value="wo">Writeoff</option>
86
	<option value="pp">Part payment</option>
51
	</select>
87
	</select>
52
	<!-- /TMPL_IF -->
88
	<!-- /TMPL_IF -->
53
	<input type="hidden" name="itemnumber<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="itemnumber" -->" />
89
	<input type="hidden" name="itemnumber<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="itemnumber" -->" />
Lines 60-66 Link Here
60
	<input type="hidden" name="notify_level<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="notify_level" -->" />
96
	<input type="hidden" name="notify_level<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="notify_level" -->" />
61
	<input type="hidden" name="totals<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="totals" -->" />
97
	<input type="hidden" name="totals<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="totals" -->" />
62
	</td>
98
	</td>
99
	<td>
100
	<!-- TMPL_IF NAME="net_balance" -->
101
	<select name="meansofpayment<!-- TMPL_VAR name="i" -->" id="meansofpayment<!-- TMPL_VAR name="i" -->">
102
<!-- TMPL_LOOP NAME="meansofpaymentoptions" -->
103
		<!-- TMPL_IF Name="selected" -->
104
        <option value="<!-- TMPL_VAR NAME="option" -->" selected="selected">
105
        <!-- TMPL_ELSE -->
106
        <option value="<!-- TMPL_VAR NAME="option" -->">
107
        <!-- /TMPL_IF -->
108
    <!-- TMPL_VAR NAME="option" --></option>
109
<!-- /TMPL_LOOP -->
110
</select><!-- TMPL_ELSE --><!-- TMPL_VAR NAME="meansofpayment" -->
111
	<!-- /TMPL_IF -->
112
	</td>
63
	<td><!-- TMPL_VAR name="description" --> <!-- TMPL_VAR name="title" escape="html" --></td>
113
	<td><!-- TMPL_VAR name="description" --> <!-- TMPL_VAR name="title" escape="html" --></td>
114
	<td>
115
	<!-- TMPL_IF NAME="net_balance" -->
116
	<input type="text" name="note<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="note" -->" /><!-- /TMPL_IF -->
117
	</td>
118
	<td>
119
	<!-- TMPL_IF NAME="net_balance" -->
120
	<input type="text" class="numeric_only" readOnly="true" id="partpaymentamount<!-- TMPL_VAR name="i" -->" name="partpaymentamount<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="partpaymentamount" -->" onKeyUp="partpaymentchange(this.value,<!-- TMPL_VAR name="i" -->,<!-- TMPL_VAR name="amountoutstanding" -->)" /><!-- /TMPL_IF -->
121
	</td>
64
	<td><!-- TMPL_VAR name="accounttype" --></td>
122
	<td><!-- TMPL_VAR name="accounttype" --></td>
65
	<td><!-- TMPL_VAR name="notify_id" --></td>
123
	<td><!-- TMPL_VAR name="notify_id" --></td>
66
	<td><!-- TMPL_VAR name="notify_level" --></td>
124
	<td><!-- TMPL_VAR name="notify_level" --></td>
Lines 70-83 Link Here
70
<!-- /TMPL_LOOP  -->
128
<!-- /TMPL_LOOP  -->
71
<!-- TMPL_IF  NAME="total"-->
129
<!-- TMPL_IF  NAME="total"-->
72
<tr>
130
<tr>
73
131
	<td colspan="9">Sub Total <!-- TMPL_VAR name="notify" --></td>
74
	<td colspan="6">Sub Total</td>
75
	<td><!-- TMPL_VAR name="total" --></td>
132
	<td><!-- TMPL_VAR name="total" --></td>
76
</tr>
133
</tr>
77
<!--/TMPL_IF-->
134
<!--/TMPL_IF-->
78
<!-- /TMPL_LOOP  -->
135
<!-- /TMPL_LOOP  -->
79
<tr>
136
<tr>
80
	<td colspan="6">Total Due</td>
137
	<td colspan="9">Total Due</td>
81
	<td><!-- TMPL_VAR name="total" --></td>
138
	<td><!-- TMPL_VAR name="total" --></td>
82
</tr>
139
</tr>
83
</table>
140
</table>
(-)a/members/boraccount.pl (-53 / +60 lines)
Lines 1-10 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
4
#writen 11/1/2000 by chris@katipo.oc.nz
3
#writen 11/1/2000 by chris@katipo.oc.nz
5
#script to display borrowers account details
4
#script to display borrowers account details
6
5
7
8
# Copyright 2000-2002 Katipo Communications
6
# Copyright 2000-2002 Katipo Communications
9
#
7
#
10
# This file is part of Koha.
8
# This file is part of Koha.
Lines 33-78 use C4::Members; Link Here
33
use C4::Branch;
31
use C4::Branch;
34
use C4::Accounts;
32
use C4::Accounts;
35
33
36
my $input=new CGI;
34
my $input = new CGI;
37
35
36
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
37
    {   template_name   => "members/boraccount.tmpl",
38
        query           => $input,
39
        type            => "intranet",
40
        authnotrequired => 0,
41
        flagsrequired   => { borrowers => 1, updatecharges => 1 },
42
        debug           => 1,
43
    }
44
);
38
45
39
my ($template, $loggedinuser, $cookie)
46
my $borrowernumber = $input->param('borrowernumber');
40
    = get_template_and_user({template_name => "members/boraccount.tmpl",
41
                            query => $input,
42
                            type => "intranet",
43
                            authnotrequired => 0,
44
                            flagsrequired => {borrowers => 1, updatecharges => 1},
45
                            debug => 1,
46
                            });
47
48
my $borrowernumber=$input->param('borrowernumber');
49
my $action = $input->param('action') || '';
47
my $action = $input->param('action') || '';
50
48
51
#get borrower details
49
#get borrower details
52
my $data=GetMember('borrowernumber' => $borrowernumber);
50
my $data = GetMember( 'borrowernumber' => $borrowernumber );
53
51
54
if ( $action eq 'reverse' ) {
52
if ( $action eq 'reverse' ) {
55
  ReversePayment( $borrowernumber, $input->param('accountno') );
53
    ReversePayment( $input->param('accountlineid') );
56
}
54
}
57
55
58
if ( $data->{'category_type'} eq 'C') {
56
if ( $data->{'category_type'} eq 'C' ) {
59
   my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
57
    my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
60
   my $cnt = scalar(@$catcodes);
58
    my $cnt = scalar(@$catcodes);
61
   $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
59
    $template->param( 'CATCODE_MULTI' => 1 ) if $cnt > 1;
62
   $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
60
    $template->param( 'catcode' => $catcodes->[0] ) if $cnt == 1;
63
}
61
}
64
62
65
#get account details
63
#get account details
66
my ($total,$accts,undef)=GetMemberAccountRecords($borrowernumber);
64
my ( $total, $accts, undef ) = GetMemberAccountRecords($borrowernumber);
67
my $totalcredit;
65
my $totalcredit;
68
if($total <= 0){
66
if ( $total <= 0 ) {
69
        $totalcredit = 1;
67
    $totalcredit = 1;
70
}
68
}
71
69
72
my $reverse_col = 0; # Flag whether we need to show the reverse column
70
my $reverse_col = 0;    # Flag whether we need to show the reverse column
73
foreach my $accountline ( @{$accts}) {
71
foreach my $accountline ( @{$accts} ) {
74
    $accountline->{amount} += 0.00;
72
    $accountline->{amount} += 0.00;
75
    if ($accountline->{amount} <= 0 ) {
73
    if ( $accountline->{amount} <= 0 ) {
76
        $accountline->{amountcredit} = 1;
74
        $accountline->{amountcredit} = 1;
77
    }
75
    }
78
    $accountline->{amountoutstanding} += 0.00;
76
    $accountline->{amountoutstanding} += 0.00;
Lines 80-124 foreach my $accountline ( @{$accts}) { Link Here
80
        $accountline->{amountoutstandingcredit} = 1;
78
        $accountline->{amountoutstandingcredit} = 1;
81
    }
79
    }
82
80
83
    $accountline->{date} = format_date($accountline->{date});
81
    $accountline->{date}              = format_date( $accountline->{date} );
84
    $accountline->{amount} = sprintf '%.2f', $accountline->{amount};
82
    $accountline->{amount}            = sprintf '%.2f', $accountline->{amount};
85
    $accountline->{amountoutstanding} = sprintf '%.2f', $accountline->{amountoutstanding};
83
    $accountline->{amountoutstanding} = sprintf '%.2f', $accountline->{amountoutstanding};
86
    if ($accountline->{accounttype} eq 'Pay') {
84
    if ( $accountline->{accounttype} eq 'Pay' ) {
87
        $accountline->{payment} = 1;
85
        $accountline->{payment} = 1;
88
        $reverse_col = 1;
86
        $reverse_col = 1;
89
    }
87
    }
90
    if ($accountline->{accounttype} ne 'F' && $accountline->{accounttype} ne 'FU'){
88
    if ( $accountline->{accounttype} ne 'F' && $accountline->{accounttype} ne 'FU' ) {
91
        $accountline->{printtitle} = 1;
89
        $accountline->{printtitle} = 1;
92
    }
90
    }
91
    
92
    if ( $accountline->{accounttype} ne 'F' && $accountline->{accounttype} ne 'FU' ) {
93
        $accountline->{printtitle} = 1;
94
    }
95
    if ( $accountline->{manager_id} ne '' ) {
96
       my $datamanager = GetMember( 'borrowernumber' => $accountline->{manager_id} );
97
    	$accountline->{manager_details}=$datamanager->{'firstname'}." ".$datamanager->{'surname'};
98
    }
93
}
99
}
94
100
95
$template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
101
$template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
96
102
97
my ($picture, $dberror) = GetPatronImage($data->{'cardnumber'});
103
my ( $picture, $dberror ) = GetPatronImage( $data->{'cardnumber'} );
98
$template->param( picture => 1 ) if $picture;
104
$template->param( picture => 1 ) if $picture;
99
105
100
$template->param(
106
$template->param(
101
    finesview           => 1,
107
    finesview      => 1,
102
    firstname           => $data->{'firstname'},
108
    firstname      => $data->{'firstname'},
103
    surname             => $data->{'surname'},
109
    surname        => $data->{'surname'},
104
    borrowernumber      => $borrowernumber,
110
    borrowernumber => $borrowernumber,
105
    cardnumber          => $data->{'cardnumber'},
111
    cardnumber     => $data->{'cardnumber'},
106
    categorycode        => $data->{'categorycode'},
112
    categorycode   => $data->{'categorycode'},
107
    category_type       => $data->{'category_type'},
113
    category_type  => $data->{'category_type'},
108
    categoryname		 => $data->{'description'},
114
    categoryname   => $data->{'description'},
109
    address             => $data->{'address'},
115
    address        => $data->{'address'},
110
    address2            => $data->{'address2'},
116
    address2       => $data->{'address2'},
111
    city                => $data->{'city'},
117
    city           => $data->{'city'},
112
    zipcode             => $data->{'zipcode'},
118
    zipcode        => $data->{'zipcode'},
113
    country             => $data->{'country'},
119
    country        => $data->{'country'},
114
    phone               => $data->{'phone'},
120
    phone          => $data->{'phone'},
115
    email               => $data->{'email'},
121
    email          => $data->{'email'},
116
    branchcode          => $data->{'branchcode'},
122
    branchcode     => $data->{'branchcode'},
117
	branchname			=> GetBranchName($data->{'branchcode'}),
123
    branchname     => GetBranchName( $data->{'branchcode'} ),
118
    total               => sprintf("%.2f",$total),
124
    total          => sprintf( "%.2f", $total ),
119
    totalcredit         => $totalcredit,
125
    totalcredit    => $totalcredit,
120
    is_child            => ($data->{'category_type'} eq 'C'),
126
    is_child       => ( $data->{'category_type'} eq 'C' ),
121
    reverse_col         => $reverse_col,
127
    reverse_col    => $reverse_col,
122
    accounts            => $accts );
128
    accounts       => $accts
129
);
123
130
124
output_html_with_http_headers $input, $cookie, $template->output;
131
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/members/pay.pl (-87 / +104 lines)
Lines 17-26 Link Here
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
19
20
21
=head1 pay.pl
20
=head1 pay.pl
22
21
23
 written 11/1/2000 by chris@katipo.oc.nz
24
 part of the koha library system, script to facilitate paying off fines
22
 part of the koha library system, script to facilitate paying off fines
25
23
26
=cut
24
=cut
Lines 33-49 use C4::Auth; Link Here
33
use C4::Output;
31
use C4::Output;
34
use CGI;
32
use CGI;
35
use C4::Members;
33
use C4::Members;
34
use C4::Context;
36
use C4::Accounts;
35
use C4::Accounts;
37
use C4::Stats;
36
use C4::Stats;
38
use C4::Koha;
37
use C4::Koha;
39
use C4::Overdues;
38
use C4::Overdues;
40
use C4::Branch; # GetBranches
39
use C4::Branch;    # GetBranches
41
40
42
my $input = new CGI;
41
my $input = new CGI;
43
42
my $lastinsertid = 0;
43
#warn Data::Dumper::Dumper $input;
44
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
44
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
45
    {
45
    {   template_name   => "members/pay.tmpl",
46
        template_name   => "members/pay.tmpl",
47
        query           => $input,
46
        query           => $input,
48
        type            => "intranet",
47
        type            => "intranet",
49
        authnotrequired => 0,
48
        authnotrequired => 0,
Lines 52-57 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
52
    }
51
    }
53
);
52
);
54
53
54
my $manager_id = C4::Context->userenv->{'number'};
55
my $borrowernumber = $input->param('borrowernumber');
55
my $borrowernumber = $input->param('borrowernumber');
56
if ( $borrowernumber eq '' ) {
56
if ( $borrowernumber eq '' ) {
57
    $borrowernumber = $input->param('borrowernumber0');
57
    $borrowernumber = $input->param('borrowernumber0');
Lines 63-96 my $user = $input->remote_user; Link Here
63
63
64
# get account details
64
# get account details
65
my $branches = GetBranches();
65
my $branches = GetBranches();
66
my $branch   = GetBranch( $input, $branches );
66
my $branch = GetBranch( $input, $branches );
67
67
68
my @names = $input->param;
68
my @names = $input->param;
69
my %inp;
69
my %inp;
70
my $check = 0;
70
my $check = 0;
71
for ( my $i = 0 ; $i < @names ; $i++ ) {
71
for ( my $i = 0 ; $i < @names ; $i++ ) {
72
    my $temp = $input->param( $names[$i] );
72
	if(defined($input->param( $names[ $i + 1 ] )) && $names[ $i + 1 ] =~ /^accountlineid/)
73
    if ( $temp eq 'wo' ) {
73
	{
74
        $inp{ $names[$i] } = $temp;
74
	    if(defined($input->param( "payfine".$input->param( $names[ $i + 1 ] ) )))
75
        $check = 1;
75
	    {
76
    }
76
	    	my $accountlineid      = $input->param( $names[ $i + 1 ] );#7
77
    if ( $temp eq 'yes' ) {
77
		    my $temp = $input->param( "payfine".$accountlineid );
78
78
		    if ( $temp eq 'wo' ) {
79
# FIXME : using array +4, +5, +6 is dirty. Should use arrays for each accountline
79
		        $inp{ $names[$i] } = $temp;
80
        my $amount         = $input->param( $names[ $i + 4 ] );
80
		        $check = 1;
81
        my $borrowernumber = $input->param( $names[ $i + 5 ] );
81
		    }
82
        my $accountno      = $input->param( $names[ $i + 6 ] );
82
		    if ( $temp eq 'yes' ) {
83
        makepayment( $borrowernumber, $accountno, $amount, $user, $branch );
83
				#my $accountlineid      = $input->param( $names[ $i + 1 ] );#7
84
        $check = 2;
84
		        # FIXME : using array +4, +5, +6 is dirty. Should use arrays for each accountline
85
    }
85
		        my $amount         = $input->param( "amount".$accountlineid );#4
86
		        my $borrowernumber = $input->param( "borrowernumber".$accountlineid );#5
87
		        my $accountno      = $input->param( "accountno".$accountlineid );#6
88
		        my $note     = $input->param( "note".$accountlineid );#12
89
		        my $meansofpayment     = $input->param( "meansofpayment".$accountlineid );#11
90
		        #$accountnoupdated = getnextacctno($borrowernumber);
91
		        $lastinsertid = makepayment( $accountlineid, $borrowernumber, $accountno, $amount, $user, $branch, $note, $meansofpayment, $manager_id, 0 );
92
		        $check = 2;
93
		    }
94
		    elsif($temp eq 'pp')
95
		    {
96
		    	#my $accountlineid      = $input->param( $names[ $i +1 ] );#7
97
		    	my $amount         = $input->param( "amount".$accountlineid );#4
98
		        my $borrowernumber = $input->param( "borrowernumber".$accountlineid );#5
99
		        my $accountno      = $input->param( "accountno".$accountlineid );#6
100
		        my $note     = $input->param( "note".$accountlineid );#12
101
		        my $meansofpayment     = $input->param( "meansofpayment".$accountlineid );#11
102
		        my $partpaymentamount         = $input->param( "partpaymentamount".$accountlineid );#13
103
		    	$lastinsertid = makepayment( $accountlineid, $borrowernumber, $accountno, $amount, $user, $branch, $note, $meansofpayment, $manager_id, $partpaymentamount);
104
		        $check = 2;
105
		    }
106
	    }
107
	}
86
}
108
}
109
87
my $total = $input->param('total') || '';
110
my $total = $input->param('total') || '';
88
if ( $check == 0 ) {
111
if ( $check == 0 ) {
89
    if ( $total ne '' ) {
112
    if ( $total ne '' ) {
90
        recordpayment( $borrowernumber, $total );
113
        recordpayment( $borrowernumber, $total );
91
    }
114
    }
92
115
93
    my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
116
    my ( $total, $accts, $numaccts ) = GetMemberAccountRecords($borrowernumber);
94
117
95
    my @allfile;
118
    my @allfile;
96
    my @notify = NumberNotifyId($borrowernumber);
119
    my @notify = NumberNotifyId($borrowernumber);
Lines 98-174 if ( $check == 0 ) { Link Here
98
    my $numberofnotify = scalar(@notify);
121
    my $numberofnotify = scalar(@notify);
99
    for ( my $j = 0 ; $j < scalar(@notify) ; $j++ ) {
122
    for ( my $j = 0 ; $j < scalar(@notify) ; $j++ ) {
100
        my @loop_pay;
123
        my @loop_pay;
101
        my ( $total , $accts, $numaccts) =
124
        my ( $total, $accts, $numaccts ) = GetBorNotifyAcctRecord( $borrowernumber, $notify[$j] );
102
          GetBorNotifyAcctRecord( $borrowernumber, $notify[$j] );
103
        for ( my $i = 0 ; $i < $numaccts ; $i++ ) {
125
        for ( my $i = 0 ; $i < $numaccts ; $i++ ) {
104
            my %line;
126
            my %line;
105
            if ( $accts->[$i]{'amountoutstanding'} != 0 ) {
127
            if ( $accts->[$i]{'amountoutstanding'} != 0 ) {
106
                $accts->[$i]{'amount'}            += 0.00;
128
                $accts->[$i]{'amount'}            += 0.00;
107
                $accts->[$i]{'amountoutstanding'} += 0.00;
129
                $accts->[$i]{'amountoutstanding'} += 0.00;
108
                $line{i}           = $j . "" . $i;
130
                $line{i}                 = $accts->[$i]{'id'};
109
                $line{itemnumber}  = $accts->[$i]{'itemnumber'};
131
                $line{accountlineid}     = $accts->[$i]{'id'};
110
                $line{accounttype} = $accts->[$i]{'accounttype'};
132
                $line{itemnumber}        = $accts->[$i]{'itemnumber'};
111
                $line{amount}      = sprintf( "%.2f", $accts->[$i]{'amount'} );
133
                $line{accounttype}       = $accts->[$i]{'accounttype'};
112
                $line{amountoutstanding} =
134
                $line{amount}            = sprintf( "%.2f", $accts->[$i]{'amount'} );
113
                  sprintf( "%.2f", $accts->[$i]{'amountoutstanding'} );
135
                $line{amountoutstanding} = sprintf( "%.2f", $accts->[$i]{'amountoutstanding'} );
114
                $line{borrowernumber} = $borrowernumber;
136
                $line{borrowernumber}    = $borrowernumber;
115
                $line{accountno}      = $accts->[$i]{'accountno'};
137
                $line{accountno}         = $accts->[$i]{'accountno'};
116
                $line{description}    = $accts->[$i]{'description'};
138
                $line{description}       = $accts->[$i]{'description'};
117
                $line{title}          = $accts->[$i]{'title'};
139
                $line{note}              = $accts->[$i]{'note'};
118
                $line{notify_id}      = $accts->[$i]{'notify_id'};
140
                $line{meansofpaymentoptions}=getMeansOfPaymentList($accts->[$i]{'meansofpayment'});
119
                $line{notify_level}   = $accts->[$i]{'notify_level'};
141
                $line{meansofpayment}     = $accts->[$i]{'meansofpayment'};
120
                $line{net_balance} = 1 if($accts->[$i]{'amountoutstanding'} > 0); # you can't pay a credit.
142
                $line{title}             = $accts->[$i]{'title'};
143
                $line{notify_id}         = $accts->[$i]{'notify_id'};
144
                $line{notify_level}      = $accts->[$i]{'notify_level'};
145
                $line{net_balance}       = 1 if ( $accts->[$i]{'amountoutstanding'} > 0 );         # you can't pay a credit.
121
                push( @loop_pay, \%line );
146
                push( @loop_pay, \%line );
122
            }
147
            }
123
        }
148
        }
124
149
125
        my $totalnotify = AmountNotify( $notify[$j], $borrowernumber );
150
        my $totalnotify = AmountNotify( $notify[$j], $borrowernumber );
126
        ( $totalnotify = '0' ) if ( $totalnotify =~ /^0.00/ );
151
        ( $totalnotify = '0' ) if ( $totalnotify =~ /^0.00/ );
127
        push @allfile,
152
        push @allfile, {
128
          {
129
            'loop_pay' => \@loop_pay,
153
            'loop_pay' => \@loop_pay,
130
            'notify'   => $notify[$j],
154
            'notify'   => $notify[$j],
131
            'total'    =>  sprintf( "%.2f",$totalnotify),
155
            'total'    => sprintf( "%.2f", $totalnotify ),
132
			
156
133
          };
157
        };
134
    }
158
    }
135
	
159
136
if ( $data->{'category_type'} eq 'C') {
160
    if ( $data->{'category_type'} eq 'C' ) {
137
   my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
161
        my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
138
   my $cnt = scalar(@$catcodes);
162
        my $cnt = scalar(@$catcodes);
139
   $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
163
        $template->param( 'CATCODE_MULTI' => 1 ) if $cnt > 1;
140
   $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
164
        $template->param( 'catcode' => $catcodes->[0] ) if $cnt == 1;
141
}
165
    }
142
	
166
143
$template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
167
    $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
144
my ($picture, $dberror) = GetPatronImage($data->{'cardnumber'});
168
    my ( $picture, $dberror ) = GetPatronImage( $data->{'cardnumber'} );
145
$template->param( picture => 1 ) if $picture;
169
    $template->param( picture => 1 ) if $picture;
146
	
170
147
    $template->param(
171
    $template->param(
148
        allfile        => \@allfile,
172
        allfile        => \@allfile,
149
        firstname      => $data->{'firstname'},
173
        firstname      => $data->{'firstname'},
150
        surname        => $data->{'surname'},
174
        surname        => $data->{'surname'},
151
        borrowernumber => $borrowernumber,
175
        borrowernumber => $borrowernumber,
152
	cardnumber => $data->{'cardnumber'},
176
        cardnumber     => $data->{'cardnumber'},
153
	categorycode => $data->{'categorycode'},
177
        categorycode   => $data->{'categorycode'},
154
	category_type => $data->{'category_type'},
178
        category_type  => $data->{'category_type'},
155
	categoryname  => $data->{'description'},
179
        categoryname   => $data->{'description'},
156
	address => $data->{'address'},
180
        address        => $data->{'address'},
157
	address2 => $data->{'address2'},
181
        address2       => $data->{'address2'},
158
	city => $data->{'city'},
182
        city           => $data->{'city'},
159
	zipcode => $data->{'zipcode'},
183
        zipcode        => $data->{'zipcode'},
160
	country => $data->{'country'},
184
        country        => $data->{'country'},
161
	phone => $data->{'phone'},
185
        phone          => $data->{'phone'},
162
	email => $data->{'email'},
186
        email          => $data->{'email'},
163
	branchcode => $data->{'branchcode'},
187
        branchcode     => $data->{'branchcode'},
164
	branchname => GetBranchName($data->{'branchcode'}),
188
        branchname     => GetBranchName( $data->{'branchcode'} ),
165
	is_child        => ($data->{'category_type'} eq 'C'),
189
        is_child       => ( $data->{'category_type'} eq 'C' ),
166
        total          => sprintf( "%.2f", $total )
190
        total          => sprintf( "%.2f", $total )
167
    );
191
    );
168
    output_html_with_http_headers $input, $cookie, $template->output;
192
    output_html_with_http_headers $input, $cookie, $template->output;
169
193
170
}
194
} else {
171
else {
172
195
173
    my %inp;
196
    my %inp;
174
    my @name = $input->param;
197
    my @name = $input->param;
Lines 188-210 else { Link Here
188
        my $itemno    = $input->param("itemnumber$value");
211
        my $itemno    = $input->param("itemnumber$value");
189
        my $amount    = $input->param("amount$value");
212
        my $amount    = $input->param("amount$value");
190
        my $accountno = $input->param("accountno$value");
213
        my $accountno = $input->param("accountno$value");
191
        writeoff( $borrowernumber, $accountno, $itemno, $accounttype, $amount );
214
        my $accountlineid = $input->param("accountlineid$value");
215
        writeoff( $borrowernumber, $accountno, $itemno, $accounttype, $amount, $accountlineid );
192
    }
216
    }
193
    $borrowernumber = $input->param('borrowernumber');
217
    $borrowernumber = $input->param('borrowernumber');
194
    print $input->redirect(
218
    print $input->redirect("/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
195
        "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
196
}
219
}
197
220
198
sub writeoff {
221
sub writeoff {
199
    my ( $borrowernumber, $accountnum, $itemnum, $accounttype, $amount ) = @_;
222
    my ( $borrowernumber, $accountnum, $itemnum, $accounttype, $amount, $accountlineid ) = @_;
200
    my $user = $input->remote_user;
223
    my $user = $input->remote_user;
201
    my $dbh  = C4::Context->dbh;
224
    my $dbh  = C4::Context->dbh;
202
    undef $itemnum unless $itemnum; # if no item is attached to fine, make sure to store it as a NULL
225
    undef $itemnum unless $itemnum;    # if no item is attached to fine, make sure to store it as a NULL
203
    my $sth =
226
    my $sth = $dbh->prepare( "Update accountlines set amountoutstanding=0 where id=?" );
204
      $dbh->prepare(
227
    $sth->execute( $accountlineid );
205
"Update accountlines set amountoutstanding=0 where accountno=? and borrowernumber=?"
206
      );
207
    $sth->execute( $accountnum, $borrowernumber );
208
    $sth->finish;
228
    $sth->finish;
209
    $sth = $dbh->prepare("select max(accountno) from accountlines");
229
    $sth = $dbh->prepare("select max(accountno) from accountlines");
210
    $sth->execute;
230
    $sth->execute;
Lines 212-223 sub writeoff { Link Here
212
    $sth->finish;
232
    $sth->finish;
213
    $account->{'max(accountno)'}++;
233
    $account->{'max(accountno)'}++;
214
    $sth = $dbh->prepare(
234
    $sth = $dbh->prepare(
215
"insert into accountlines (borrowernumber,accountno,itemnumber,date,amount,description,accounttype)
235
        "insert into accountlines (borrowernumber,accountno,itemnumber,date,time,amount,description,accounttype,manager_id)
216
						values (?,?,?,now(),?,'Writeoff','W')"
236
						values (?,?,?,now(),CURRENT_TIME,?,?,'W', ?)"
217
    );
237
    );
218
    $sth->execute( $borrowernumber, $account->{'max(accountno)'},
238
    $sth->execute( $borrowernumber, $account->{'max(accountno)'}, $itemnum, $amount,"Writeoff for account n°".$accountnum, $manager_id);
219
        $itemnum, $amount );
220
    $sth->finish;
239
    $sth->finish;
221
    UpdateStats( $branch, 'writeoff', $amount, '', '', '',
240
    UpdateStats( $branch, 'writeoff', $amount, '', '', '', $borrowernumber );
222
        $borrowernumber );
223
}
241
}
224
- 

Return to bug 5905