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

(-)a/C4/Accounts.pm (-6 / +107 lines)
Lines 38-44 BEGIN { Link Here
38
		&getnextacctno &reconcileaccount &getcharges &ModNote &getcredits
38
		&getnextacctno &reconcileaccount &getcharges &ModNote &getcredits
39
		&getrefunds &chargelostitem
39
		&getrefunds &chargelostitem
40
		&ReversePayment
40
		&ReversePayment
41
	); # removed &fixaccounts
41
        makepartialpayment
42
        recordpayment_selectaccts
43
	);
42
}
44
}
43
45
44
=head1 NAME
46
=head1 NAME
Lines 369-375 sub manualinvoice { Link Here
369
    my $dbh      = C4::Context->dbh;
371
    my $dbh      = C4::Context->dbh;
370
    my $notifyid = 0;
372
    my $notifyid = 0;
371
    my $insert;
373
    my $insert;
372
    $itemnum =~ s/ //g;
373
    my $accountno  = getnextacctno($borrowernumber);
374
    my $accountno  = getnextacctno($borrowernumber);
374
    my $amountleft = $amount;
375
    my $amountleft = $amount;
375
376
Lines 413-424 sub manualinvoice { Link Here
413
        $notifyid = 1;
414
        $notifyid = 1;
414
    }
415
    }
415
416
416
    if ( $itemnum ne '' ) {
417
    if ( $itemnum ) {
417
        $desc .= " " . $itemnum;
418
        $desc .= ' ' . $itemnum;
418
        my $sth = $dbh->prepare(
419
        my $sth = $dbh->prepare(
419
            "INSERT INTO  accountlines
420
            'INSERT INTO  accountlines
420
                        (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, itemnumber,notify_id, note, manager_id)
421
                        (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, itemnumber,notify_id, note, manager_id)
421
        VALUES (?, ?, now(), ?,?, ?,?,?,?,?,?)");
422
        VALUES (?, ?, now(), ?,?, ?,?,?,?,?,?)');
422
     $sth->execute($borrowernumber, $accountno, $amount, $desc, $type, $amountleft, $itemnum,$notifyid, $note, $manager_id) || return $sth->errstr;
423
     $sth->execute($borrowernumber, $accountno, $amount, $desc, $type, $amountleft, $itemnum,$notifyid, $note, $manager_id) || return $sth->errstr;
423
  } else {
424
  } else {
424
    my $sth=$dbh->prepare("INSERT INTO  accountlines
425
    my $sth=$dbh->prepare("INSERT INTO  accountlines
Lines 686-691 sub ReversePayment { Link Here
686
  }
687
  }
687
}
688
}
688
689
690
=head2 recordpayment_selectaccts
691
692
  recordpayment_selectaccts($borrowernumber, $payment,$accts);
693
694
Record payment by a patron. C<$borrowernumber> is the patron's
695
borrower number. C<$payment> is a floating-point number, giving the
696
amount that was paid. C<$accts> is an array ref to a list of
697
accountnos which the payment can be recorded against
698
699
Amounts owed are paid off oldest first. That is, if the patron has a
700
$1 fine from Feb. 1, another $1 fine from Mar. 1, and makes a payment
701
of $1.50, then the oldest fine will be paid off in full, and $0.50
702
will be credited to the next one.
703
704
=cut
705
706
sub recordpayment_selectaccts {
707
    my ( $borrowernumber, $amount, $accts ) = @_;
708
709
    my $dbh        = C4::Context->dbh;
710
    my $newamtos   = 0;
711
    my $accdata    = q{};
712
    my $branch     = C4::Context->userenv->{branch};
713
    my $amountleft = $amount;
714
    my $sql = 'SELECT * FROM accountlines WHERE (borrowernumber = ?) ' .
715
    'AND (amountoutstanding<>0) ';
716
    if (@{$accts} ) {
717
        $sql .= ' AND accountno IN ( ' .  join ',', @{$accts};
718
        $sql .= ' ) ';
719
    }
720
    $sql .= ' ORDER BY date';
721
    # begin transaction
722
    my $nextaccntno = getnextacctno($borrowernumber);
723
724
    # get lines with outstanding amounts to offset
725
    my $rows = $dbh->selectall_arrayref($sql, { Slice => {} }, $borrowernumber);
726
727
    # offset transactions
728
    my $sth     = $dbh->prepare('UPDATE accountlines SET amountoutstanding= ? ' .
729
        'WHERE (borrowernumber = ?) AND (accountno=?)');
730
    for my $accdata ( @{$rows} ) {
731
        if ($amountleft == 0) {
732
            last;
733
        }
734
        if ( $accdata->{amountoutstanding} < $amountleft ) {
735
            $newamtos = 0;
736
            $amountleft -= $accdata->{amountoutstanding};
737
        }
738
        else {
739
            $newamtos   = $accdata->{amountoutstanding} - $amountleft;
740
            $amountleft = 0;
741
        }
742
        my $thisacct = $accdata->{accountno};
743
        $sth->execute( $newamtos, $borrowernumber, $thisacct );
744
    }
745
746
    # create new line
747
    $sql = 'INSERT INTO accountlines ' .
748
    '(borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding) ' .
749
    q|VALUES (?,?,now(),?,'Payment,thanks','Pay',?)|;
750
    $dbh->do($sql,{},$borrowernumber, $nextaccntno, 0 - $amount, 0 - $amountleft );
751
    UpdateStats( $branch, 'payment', $amount, '', '', '', $borrowernumber, $nextaccntno );
752
    return;
753
}
754
755
# makepayment needs to be fixed to handle partials till then this separate subroutine
756
# fills in
757
sub makepartialpayment {
758
    my ( $borrowernumber, $accountno, $amount, $user, $branch ) = @_;
759
    if (!$amount || $amount < 0) {
760
        return;
761
    }
762
    my $dbh = C4::Context->dbh;
763
764
    my $nextaccntno = getnextacctno($borrowernumber);
765
    my $newamtos    = 0;
766
767
    my $data = $dbh->selectrow_hashref(
768
        'SELECT * FROM accountlines WHERE  borrowernumber=? AND accountno=?',undef,$borrowernumber,$accountno);
769
    my $new_outstanding = $data->{amountoutstanding} - $amount;
770
771
    my $update = 'UPDATE  accountlines SET amountoutstanding = ?  WHERE   borrowernumber = ? '
772
    . ' AND   accountno = ?';
773
    $dbh->do( $update, undef, $new_outstanding, $borrowernumber, $accountno);
774
775
    # create new line
776
    my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, '
777
    .  'description, accounttype, amountoutstanding) '
778
    . ' VALUES (?, ?, now(), ?, ?, ?, 0)';
779
780
    $dbh->do(  $insert, undef, $borrowernumber, $nextaccntno, $amount,
781
        "Payment, thanks - $user", 'Pay');
782
783
    UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber, $accountno );
784
785
    return;
786
}
787
788
789
689
END { }    # module clean-up code here (global destructor)
790
END { }    # module clean-up code here (global destructor)
690
791
691
1;
792
1;
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.tt (+73 lines)
Line 0 Link Here
1
[%# duplicates circ-menu.inc but assumes all borrower attributes are in a borrower variable rather than
2
in the global namespace %]
3
[% IF borrower %]
4
<div class="patroninfo"><h5>[% borrower.firstname %] [% borrower.surname %] ([% borrower.cardnumber %])</h5>
5
<!--[if IE 6]>
6
<style type="tex/css">img { width: expression(this.width > 140 ? 140: true);
7
}</style>
8
<![endif]-->
9
<ul>
10
[% IF ( patronimages ) %]
11
[% IF borrower.has_picture %]
12
<li><img src="/cgi-bin/koha/members/patronimage.pl?crdnum=[% borrower.cardnumber %]" id="patronimage" alt="[% borrower.firstname %] [% borrower.surname %] ([% borrower.cardnumber %])" border="0" style="max-width : 140px; margin: .3em 0 .3em .3em; padding: .2em; border: 1px solid #CCCCCC; width:auto !important; width:130px;" /></li>
13
[% ELSE %]
14
<li><img src="/intranet-tmpl/prog/img/patron-blank.png" alt="[% borrower.firstname %] [% borrower.surname %] ([% borrower.cardnumber %])" border="0" style="margin: .3em 0 .3em .3em; padding: .2em; border: 1px solid #CCCCCC;" /></li>
15
[% END %]
16
[% END %]
17
    <li>[% IF borrower.address %]
18
            [% borrower.address %]
19
    [% ELSE %]
20
            <span class="empty">No address stored.</span>
21
    [% END %]</li>
22
    [% IF borrower.address2 %]
23
        <li>[% borrower.address2 %]</li>
24
    [% END %]<li>
25
    [% IF borrower.city %]
26
            [% borrower.city %][% IF borrower.state %], [% borrower.state %][% END %]
27
	    [% borrower.zipcode %][% IF ( borrower.country ) %], [% borrower.country %][% END %]
28
    [% ELSE %]
29
        <span class="empty">No city stored.</span>
30
    [% END %]</li>
31
    <li>[% IF borrower.phone %]
32
        [% borrower.phone %]
33
    [% ELSE %]
34
        [% IF borrower.mobile %]
35
            [% borrower.mobile %]
36
        [% ELSE %]
37
            [% IF borrower.phonepro %]
38
                [% borrower.phonepro %]
39
            [% ELSE %]
40
                <span class="empty">No phone stored.</span>
41
            [% END %]
42
        [% END %]
43
    [% END %]</li>
44
    [% IF borrower.email %]
45
        <li class="email"> <a href="mailto:[% borrower.email %]" title="[% borrower.email %]">[% borrower.email %]</a></li>
46
    [% ELSE %]
47
        [% IF borrower.emailpro %]
48
            <li class="email"> <a href="mailto:[% borrower.emailpro %]" title="[% borrower.emailpro %]">[% borrower.emailpro %]</a></li>
49
        [% ELSE %]
50
            <li> <span class="empty">No email stored.</span>    </li>
51
        [% END %]
52
    [% END %]
53
    <li>Category: [% borrower.description %] ([% borrower.categorycode %])</li>
54
    <li>Home Library: [% IF ( borrower.branchname ) %][% borrower.branchname %][% ELSE %][% borrower.branch %][% END %]</li>
55
</ul></div>
56
<div id="menu">
57
<ul>
58
	[% IF ( circview ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/circ/circulation.pl?borrowernumber=[% borrower.borrowernumber %]">Check Out</a></li>
59
	[% IF ( CAN_user_borrowers ) %]
60
	[% IF ( detailview ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrower.borrowernumber %]">Details</a></li>
61
	[% END %]
62
	 [% IF ( CAN_user_updatecharges ) %]
63
	[% IF ( finesview ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% borrower.borrowernumber %]">Fines</a></li>
64
	[% END %]
65
	[% IF ( intranetreadinghistory ) %][% IF ( readingrecordview ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/members/readingrec.pl?borrowernumber=[% borrower.borrowernumber %]">Circulation History</a></li>[% END %]
66
	[% IF ( CAN_user_parameters ) %][% IF ( logview ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/tools/viewlog.pl?do_it=1&amp;modules=MEMBERS&amp;modules=circulation&amp;object=[% borrower.borrowernumber %]&amp;src=circ">Modification Log</a></li>[% END %]
67
    [% IF ( EnhancedMessagingPreferences ) %]
68
    [% IF ( messagingview ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/members/messaging.pl?borrowernumber=[% borrower.borrowernumber %]">Messaging</a></li>
69
    [% END %]
70
    [% IF ( sentnotices ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/members/notices.pl?borrowernumber=[% borrower.borrowernumber %]">Notices</a></li>
71
</ul></div>
72
[% END %]
73
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/help/members/pay.tt (-9 / +42 lines)
Lines 1-18 Link Here
1
[% INCLUDE 'help-top.inc' %]
1
[% INCLUDE 'help-top.inc' %]
2
2
3
<h1>Pay/Reverse Fines</h1>
3
<h1>Pay and Writeoff Fines</h1>
4
4
5
<p>Each line item can be paid in full (or written off) using the 'Pay Fines' tab.</p>
5
<p>Each line item can be paid in full, partially paid, or written off.</p>
6
6
7
<h4>Pay a fine in full</h4>
7
<ul>
8
<ul>
8
	<li>Choose the payment type (Unpaid, Paid, Writeoff) from the pull down menu</li>
9
	<li>Click "Pay" next to the fine you want to pay in full</li>
9
	<li>Click 'Make Payment'</li>
10
	<li>The full amount of the fine will be populated for you in the "Collect From Patron" box</li>
10
	<li>A line item will be added to the account information showing the fee paid in full (or written off)</li>
11
	<li>Click "Confirm" </li>
11
	<li>If you accidentally mark and item as paid, you can reverse that line item by clicking 'Reverse' to the right of the line
12
	<li>The fine will be removed from outstanding fines, and displayed as fully paid.</li>
13
</ul>
14
15
<h4>Pay a partial fine</h4>
16
<ul>
17
	<li>Click "Pay" next to the fine you want to partially pay</li>
18
	<li>Enter the amount you are collecting from the patron in the "Collect From Patron" box</li>
19
	<li>Click "Confirm" </li>
20
	<li>The fine will be updated to show the original Amount, and the current Amount Outstanding</li>
21
</ul>
22
23
<h4>Writeoff a single fine</h4>
24
<ul>
25
	<li>Click "Writeoff" next to the fine you wish to writeoff.</li>
26
	<li>The fine will be removed from outstanding fines, and displayed as fully paid.</li>
27
</ul>
28
29
<h4>Pay an amount towards all fines</h4>
12
<ul>
30
<ul>
13
	<li>Once clicked a new line item will be added to the account, showing the payment as reversed</li>
31
	<li>Click the "Pay Amount" button</li>
32
	<li>Enter the amount you are collecting from the patron in "Collect from Patron." The sum of all fines is shown in "Total Amount Outstanding"</li>
33
	<li>Click "Confirm"</li>
34
	<li>The fine totals will be updated with the payment applied to oldest fines first.</li>
14
</ul>
35
</ul>
15
</li>
36
37
<h4>Writeoff All fines</h4>
38
<ul>
39
        <li>Click the "Writeoff All" button</li>
40
        <li>All fines will be removed from outstanding fines, and displayed as written off.</li>
41
</ul> 
42
43
<h4>Pay Selected fines</h4>
44
<ul>
45
	<li>Check the selection boxes next to the fines you wish to pay, click "Pay Selected"</li>
46
	<li>Enter an amount to pay towards the fines.</li>
47
	<li>Click "Confirm"</li>
48
	<li>The fine totals will be updated with the payment applied to the oldest selected fines first.</li>
16
</ul>
49
</ul>
17
50
18
[% INCLUDE 'help-bottom.inc' %]
51
[% INCLUDE 'help-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tt (-48 / +54 lines)
Lines 1-12 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Patrons &rsaquo; Pay Fines for  [% firstname %] [% surname %]</title>
2
<title>Koha &rsaquo; Patrons &rsaquo; Pay Fines for  [% borrower.firstname %] [% borrower.surname %]</title>
3
[% INCLUDE 'doc-head-close.inc' %]
3
[% INCLUDE 'doc-head-close.inc' %]
4
</head>
4
</head>
5
<body>
5
<body>
6
[% INCLUDE 'header.inc' %]
6
[% INCLUDE 'header.inc' %]
7
[% INCLUDE 'patron-search.inc' %]
7
[% INCLUDE 'patron-search.inc' %]
8
8
9
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/members/members-home.pl">Patrons</a>  &rsaquo; Pay Fines for [% firstname %] [% surname %]</div>
9
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/members/members-home.pl">Patrons</a>  &rsaquo; Pay Fines for [% borrower.firstname %] [% borrower.surname %]</div>
10
10
11
<div id="doc3" class="yui-t2">
11
<div id="doc3" class="yui-t2">
12
   
12
   
Lines 18-102 Link Here
18
<!-- The manual invoice and credit buttons -->
18
<!-- The manual invoice and credit buttons -->
19
<div class="toptabs">
19
<div class="toptabs">
20
<ul class="ui-tabs-nav">
20
<ul class="ui-tabs-nav">
21
	<li><a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% borrowernumber %]">Account</a></li>
21
	<li><a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% borrower.borrowernumber %]">Account</a></li>
22
	<li class="ui-tabs-selected"><a href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% borrowernumber %]" >Pay fines</a></li>
22
	<li class="ui-tabs-selected"><a href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% borrower.borrowernumber %]" >Pay fines</a></li>
23
	<li><a href="/cgi-bin/koha/members/maninvoice.pl?borrowernumber=[% borrowernumber %]" >Create Manual Invoice</a></li>
23
	<li><a href="/cgi-bin/koha/members/maninvoice.pl?borrowernumber=[% borrower.borrowernumber %]" >Create Manual Invoice</a></li>
24
	<li><a href="/cgi-bin/koha/members/mancredit.pl?borrowernumber=[% borrowernumber %]" >Create Manual Credit</a></li>
24
	<li><a href="/cgi-bin/koha/members/mancredit.pl?borrowernumber=[% borrower.borrowernumber %]" >Create Manual Credit</a></li>
25
</ul>
25
</ul>
26
<div class="tabs-container">
26
<div class="tabs-container">
27
27
28
[% IF ( allfile ) %]<form action="/cgi-bin/koha/members/pay.pl" method="post">
28
[% IF ( accounts ) %]
29
	<input type="hidden" name="borrowernumber" id="borrowernumber" value="[% borrowernumber %]" />
29
    <form action="/cgi-bin/koha/members/pay.pl" method="post">
30
	<input type="hidden" name="borrowernumber" id="borrowernumber" value="[% borrower.borrowernumber %]" />
30
31
31
<table>
32
<table>
32
<tr>
33
<tr>
33
	<th>Fines &amp; Charges</th>
34
	<th>Fines &amp; Charges</th>
35
    <th>Sel</th>
34
	<th>Description</th>
36
	<th>Description</th>
35
    <th>Note</th>
36
	<th>Account Type</th>
37
	<th>Account Type</th>
37
	<th>Notify id</th>
38
	<th>Notify id</th>
38
	<th>Level</th>
39
	<th>Level</th>
39
	<th>Amount</th>
40
	<th>Amount</th>
40
	<th>Amount Outstanding</th>
41
	<th>Amount Outstanding</th>
41
</tr>
42
</tr>
42
	
43
43
[% FOREACH allfil IN allfile %]
44
[% FOREACH account_grp IN accounts %]
44
	[% FOREACH loop_pa IN allfil.loop_pay %]
45
    [% FOREACH line IN account_grp.accountlines %]
45
<tr>
46
<tr>
46
	<td>
47
	[% IF ( loop_pa.net_balance ) %]
48
	<select name="payfine[% loop_pa.i %]">
49
	<option value="no">Unpaid</option>
50
	<option value="yes">Paid</option>
51
	<option value="wo">Writeoff</option>
52
	</select>
53
	[% END %]
54
	<input type="hidden" name="itemnumber[% loop_pa.i %]" value="[% loop_pa.itemnumber %]" />
55
	<input type="hidden" name="accounttype[% loop_pa.i %]" value="[% loop_pa.accounttype %]" />
56
	<input type="hidden" name="amount[% loop_pa.i %]" value="[% loop_pa.amount %]" />
57
	<input type="hidden" name="out[% loop_pa.i %]" value="[% loop_pa.amountoutstanding %]" />
58
	<input type="hidden" name="borrowernumber[% loop_pa.i %]" value="[% loop_pa.borrowernumber %]" />
59
	<input type="hidden" name="accountno[% loop_pa.i %]" value="[% loop_pa.accountno %]" />
60
	<input type="hidden" name="notify_id[% loop_pa.i %]" value="[% loop_pa.notify_id %]" />
61
	<input type="hidden" name="notify_level[% loop_pa.i %]" value="[% loop_pa.notify_level %]" />
62
	<input type="hidden" name="totals[% loop_pa.i %]" value="[% loop_pa.totals %]" />
63
	</td>
64
	<td>[% loop_pa.description %] [% loop_pa.title |html %]</td>
65
    <td>
47
    <td>
66
        [% IF ( loop_pa.net_balance ) %]
48
    [% IF ( line.amountoutstanding > 0 ) %]
67
            <input type="text" name="note[% loop_pa.i %]" value="[% loop_pa.note %]" />
49
        <input type="submit" name="pay_indiv_[% line.accountno %]" value="Pay" />
68
        [% ELSE %]
50
        <input type="submit" name="wo_indiv_[% line.accountno %]" value="Writeoff" />
69
            [% loop_pa.note %]
51
    [% END %]
70
        [% END %]
52
    <input type="hidden" name="itemnumber[% line.accountno %]" value="[% line.itemnumber %]" />
53
    <input type="hidden" name="description[% line.accountno %]" value="[% line.description %]" />
54
    <input type="hidden" name="accounttype[% line.accountno %]" value="[% line.accounttype %]" />
55
    <input type="hidden" name="amount[% line.accountno %]" value="[% line.amount %]" />
56
    <input type="hidden" name="amountoutstanding[% line.accountno %]" value="[% line.amountoutstanding %]" />
57
    <input type="hidden" name="borrowernumber[% line.accountno %]" value="[% line.borrowernumber %]" />
58
    <input type="hidden" name="accountno[% line.accountno %]" value="[% line.accountno %]" />
59
    <input type="hidden" name="notify_id[% line.accountno %]" value="[% line.notify_id %]" />
60
    <input type="hidden" name="notify_level[% line.accountno %]" value="[% line.notify_level %]" />
61
    <input type="hidden" name="totals[% line.accountno %]" value="[% line.totals %]" />
62
    </td>
63
    <td>
64
    [% IF ( line.amountoutstanding > 0 ) %]
65
        <input type="checkbox" checked="checked" name="incl_par_[% line.accountno %]" />
66
    [% END %]
71
    </td>
67
    </td>
72
	<td>[% loop_pa.accounttype %]</td>
68
    <td>[% line.description %] [% line.title |html_entity %]</td>
73
	<td>[% loop_pa.notify_id %]</td>
69
    <td>[% line.accounttype %]</td>
74
	<td>[% loop_pa.notify_level %]</td>
70
    <td>[% line.notify_id %]</td>
75
	<td class="debit">[% loop_pa.amount %]</td>
71
    <td>[% line.notify_level %]</td>
76
	<td class="debit">[% loop_pa.amountoutstanding %]</td>
72
    <td class="debit">[% line.amount | format('%.2f') %]</td>
73
    <td class="debit">[% line.amountoutstanding | format('%.2f') %]</td>
77
</tr>
74
</tr>
78
[% END %]
75
[% END %]
79
[% IF ( allfil.total ) %]
76
[% IF ( account_grp.total ) %]
80
<tr>
77
<tr>
81
78
82
	<td colspan="7">Sub Total</td>
79
    <td class="total" colspan="7">Sub Total:</td>
83
	<td>[% allfil.total %]</td>
80
    <td>[% account_grp.total | format('%.2f') %]</td>
84
</tr>
81
</tr>
85
[% END %]
82
[% END %]
86
[% END %]
83
[% END %]
87
<tr>
84
<tr>
88
	<td colspan="7">Total Due</td>
85
    <td class="total" colspan="7">Total Due:</td>
89
	<td>[% total %]</td>
86
    <td>[% total | format('%.2f') %]</td>
90
</tr>
87
</tr>
91
</table>
88
</table>
92
<fieldset class="action"><input type="submit" name="submit"  value="Make Payment" class="submit" /> <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% borrowernumber %]">Cancel</a></fieldset></form>[% ELSE %]<p>[% firstname %] [% surname %] has no outstanding fines.</p>[% END %]
89
<fieldset class="action">
90
<input type="submit" name="paycollect"  value="Pay Amount" class="submit" />
91
<input type="submit" name="woall"  value="Writeoff All" class="submit" />
92
<input type="submit" name="payselected"  value="Pay Selected" class="submit" />
93
<a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% borrower.borrowernumber %]">Cancel</a>
94
</fieldset>
95
</form>
96
[% ELSE %]
97
    <p>[% borrower.firstname %] [% borrower.surname %] has no outstanding fines.</p>
98
[% END %]
93
</div></div>
99
</div></div>
94
100
95
</div>
101
</div>
96
</div>
102
</div>
97
103
98
<div class="yui-b">
104
<div class="yui-b">
99
[% INCLUDE 'circ-menu.inc' %]
105
[% INCLUDE 'circ-menu.tt' %]
100
</div>
106
</div>
101
</div>
107
</div>
102
[% INCLUDE 'intranet-bottom.inc' %]
108
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt (+227 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Patrons &rsaquo; Collect Fine Payment for  [% borrower.firstname %] [% borrower.surname %]</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
<script type= "text/javascript">
5
//<![CDATA[
6
function moneyFormat(textObj) {
7
    var newValue = textObj.value;
8
    var decAmount = "";
9
    var dolAmount = "";
10
    var decFlag   = false;
11
    var aChar     = "";
12
13
    for(i=0; i < newValue.length; i++) {
14
        aChar = newValue.substring(i, i+1);
15
        if (aChar >= "0" && aChar <= "9") {
16
            if(decFlag) {
17
                decAmount = "" + decAmount + aChar;
18
            }
19
            else {
20
                dolAmount = "" + dolAmount + aChar;
21
            }
22
        }
23
        if (aChar == ".") {
24
            if (decFlag) {
25
                dolAmount = "";
26
                break;
27
            }
28
            decFlag = true;
29
        }
30
    }
31
32
    if (dolAmount == "") {
33
        dolAmount = "0";
34
    }
35
// Strip leading 0s
36
    if (dolAmount.length > 1) {
37
        while(dolAmount.length > 1 && dolAmount.substring(0,1) == "0") {
38
            dolAmount = dolAmount.substring(1,dolAmount.length);
39
        }
40
    }
41
    if (decAmount.length > 2) {
42
        decAmount = decAmount.substring(0,2);
43
    }
44
// Pad right side
45
    if (decAmount.length == 1) {
46
       decAmount = decAmount + "0";
47
    }
48
    if (decAmount.length == 0) {
49
       decAmount = decAmount + "00";
50
    }
51
52
    textObj.value = dolAmount + "." + decAmount;
53
}
54
//]]>
55
</script>
56
</head>
57
<body>
58
[% INCLUDE 'header.inc' %]
59
[% INCLUDE 'patron-search.inc' %]
60
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/members/members-home.pl">Patrons</a>  &rsaquo; Pay Fines for [% borrower.firstname %] [% borrower.surname %]</div>
61
62
<div id="doc3" class="yui-t2">
63
64
<div id="bd">
65
<div id="yui-main">
66
<div class="yui-b">
67
[% INCLUDE 'members-toolbar.inc' %]
68
69
70
<!-- The manual invoice and credit buttons -->
71
<div class="toptabs">
72
<ul class="ui-tabs-nav">
73
    <li>
74
    <a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% borrower.borrowernumber %]">Account</a>
75
    </li>
76
    <li class="ui-tabs-selected">
77
    <a href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% borrower.borrowernumber %]" >Pay fines</a>
78
    </li>
79
    <li>
80
    <a href="/cgi-bin/koha/members/maninvoice.pl?borrowernumber=[% borrower.borrowernumber %]" >Create Manual Invoice</a>
81
    </li>
82
    <li>
83
    <a href="/cgi-bin/koha/members/mancredit.pl?borrowernumber=[% borrower.borrowernumber %]" >Create Manual Credit</a>
84
    </li>
85
</ul>
86
<div class="tabs-container">
87
[% IF ( error ) %]
88
    <div id="error_message" class="dialog alert">
89
    [% error %]
90
    </div>
91
[% END %]
92
93
[% IF ( pay_individual ) %]
94
    <form name="payindivfine" onsubmit="return validatePayment(this);" method="post" action="/cgi-bin/koha/members/paycollect.pl">
95
    <input type="hidden" name="borrowernumber" id="borrowernumber" value="[% borrower.borrowernumber %]" />
96
    <input type="hidden" name="pay_individual" id="pay_individual" value="[% pay_individual %]" />
97
    <input type="hidden" name="description" id="description" value="[% description %]" />
98
    <input type="hidden" name="accounttype" id="accounttype" value="[% accounttype %]" />
99
    <input type="hidden" name="notify_id" id="notify_id" value="[% notify_id %]" />
100
    <input type="hidden" name="notify_level" id="notify_level" value="[% notify_level %]" />
101
    <input type="hidden" name="amount" id="amount" value="[% amount %]" />
102
    <input type="hidden" name="amountoutstanding" id="amountoutstanding" value="[% amountoutstanding %]" />
103
    <input type="hidden" name="accountno" id="accountno" value="[% accountno %]" />
104
    <input type="hidden" name="title" id="title" value="[% title %]" />
105
    <table>
106
    <tr>
107
        <th>Description</th>
108
        <th>Account Type</th>
109
        <th>Notify id</th>
110
        <th>Level</th>
111
        <th>Amount</th>
112
        <th>Amount Outstanding</th>
113
    </tr>
114
    <tr>
115
        <td>
116
            [% description %] [% title  %]
117
        </td>
118
        <td>[% accounttype %]</td>
119
        <td>[% notify_id %]</td>
120
        <td>[% notify_level %]</td>
121
        <td class="debit">[% amount | format('%.2f') %]</td>
122
        <td class="debit">[% amountoutstanding | format('%.2f') %]</td>
123
    </tr>
124
    <tr>
125
        <td>Total Amount Payable : </td>
126
        <td>[% amountoutstanding | format('%.2f') %]</td>
127
        <td colspan="4"></td>
128
    </tr>
129
    <tr><td colspan="6"> </td></tr>
130
    <tr>
131
        <td>Collect From Patron: </td>
132
        <td>
133
            <!-- default to paying all -->
134
        <input name="paid" id="paid" value="[% amountoutstanding | format('%.2f') %]" onchange="moneyFormat(document.payindivfine.paid)"/>
135
        </td>
136
    </tr>
137
    <tr><td colspan="6"></td></tr>
138
    <tr>
139
        <td colspan="6">
140
        <input type="submit" name="submitbutton" value="Confirm" />
141
        <a class="cancel" href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% borrower.borrowernumber %]">Cancel</a>
142
        </td>
143
    </tr>
144
145
    </table>
146
    </form>
147
[% ELSIF ( writeoff_individual ) %]
148
    <form name="woindivfine" action="/cgi-bin/koha/members/pay.pl" method="post" >
149
    <input type="hidden" name="borrowernumber" id="borrowernumber" value="[% borrower.borrowernumber %]" />
150
    <input type="hidden" name="pay_individual" id="pay_individual" value="[% pay_individual %]" />
151
    <input type="hidden" name="description" id="description" value="[% description %]" />
152
    <input type="hidden" name="accounttype" id="accounttype" value="[% accounttype %]" />
153
    <input type="hidden" name="notify_id" id="notify_id" value="[% notify_id %]" />
154
    <input type="hidden" name="notify_level" id="notify_level" value="[% notify_level %]" />
155
    <input type="hidden" name="amount" id="amount" value="[% amount %]" />
156
    <input type="hidden" name="amountoutstanding" id="amountoutstanding" value="[% amountoutstanding %]" />
157
    <input type="hidden" name="accountno" id="accountno" value="[% accountno %]" />
158
    <input type="hidden" name="title" id="title" value="[% title %]" />
159
    <table>
160
    <tr>
161
        <th>Description</th>
162
        <th>Account Type</th>
163
        <th>Notify id</th>
164
        <th>Level</th>
165
        <th>Amount</th>
166
        <th>Amount Outstanding</th>
167
    </tr>
168
    <tr>
169
        <td>[% description %] [% title %]</td>
170
        <td>[% accounttype %]</td>
171
        <td>[% notify_id %]</td>
172
        <td>[% notify_level %]</td>
173
        <td class="debit">[% amount | format('%.2f') %]</td>
174
        <td class="debit">[% amountoutstanding | format('%.2f') %]</td>
175
    </tr>
176
    <tr><td colspan="6"> </td></tr>
177
    <tr><td colspan="6"><strong>Writeoff This Charge?</strong></td></tr>
178
    <tr><td> </td></tr>
179
    <tr>
180
        <td colspan="6">
181
        <input type="submit" name="confirm_writeoff" id="confirm_writeoff" value="Confirm" />
182
        <a class="cancel" href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% borrower.borrowernumber %]">Cancel</a>
183
        </td>
184
    </tr>
185
186
    </table>
187
    </form>
188
[% ELSE %]
189
190
    <form name="payfine" onsubmit="return validatePayment(this);" method="post" action="/cgi-bin/koha/members/paycollect.pl">
191
    <input type="hidden" name="borrowernumber" id="borrowernumber" value="[% borrower.borrowernumber %]" />
192
    <input type="hidden" name="selected_accts" id="selected_accts" value="[% selected_accts %]" />
193
    <input type="hidden" name="total" id="total" value="[% total %]" />
194
195
    <table>
196
    <tr>
197
        <td>Total Amount Outstanding : </td>
198
        <td class="debit">[% total | format('%.2f') %]</td>
199
    </tr>
200
    <tr><td colspan="2"> </td></tr>
201
    <tr>
202
        <td>Collect From Patron: </td>
203
        <td>
204
        <!-- default to paying all -->
205
        <input name="paid" id="paid" value="[% total | format('%.2f') %]" onchange="moneyFormat(document.payfine.paid)"/>
206
        </td>
207
    </tr>
208
    <tr><td></td></tr>
209
    <tr>
210
        <td colspan="2">
211
        <input type="submit" name="submitbutton" value="Confirm" />
212
        <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% borrower.borrowernumber %]">Cancel</a>
213
        </td>
214
    </tr>
215
    </table>
216
    </form>
217
[% END %]
218
</div></div>
219
</div>
220
</div>
221
222
<div class="yui-b">
223
[% INCLUDE 'circ-menu.tt' %]
224
</div>
225
</div>
226
[% INCLUDE 'intranet-bottom.inc' %]
227
(-)a/members/pay.pl (-157 / +204 lines)
Lines 2-7 Link Here
2
2
3
# Copyright 2000-2002 Katipo Communications
3
# Copyright 2000-2002 Katipo Communications
4
# Copyright 2010 BibLibre
4
# Copyright 2010 BibLibre
5
# Copyright 2010,2011 PTFS-Europe Ltd
5
#
6
#
6
# This file is part of Koha.
7
# This file is part of Koha.
7
#
8
#
Lines 18-24 Link Here
18
# with Koha; if not, write to the Free Software Foundation, Inc.,
19
# with Koha; if not, write to the Free Software Foundation, Inc.,
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21
21
22
=head1 pay.pl
22
=head1 pay.pl
23
23
24
 written 11/1/2000 by chris@katipo.oc.nz
24
 written 11/1/2000 by chris@katipo.oc.nz
Lines 38-233 use C4::Accounts; Link Here
38
use C4::Stats;
38
use C4::Stats;
39
use C4::Koha;
39
use C4::Koha;
40
use C4::Overdues;
40
use C4::Overdues;
41
use C4::Branch; # GetBranches
41
use C4::Branch;
42
42
43
my $input = new CGI;
43
my $input = CGI->new;
44
44
45
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
45
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
46
    {
46
    {   template_name   => 'members/pay.tmpl',
47
        template_name   => "members/pay.tmpl",
48
        query           => $input,
47
        query           => $input,
49
        type            => "intranet",
48
        type            => 'intranet',
50
        authnotrequired => 0,
49
        authnotrequired => 0,
51
        flagsrequired   => { borrowers => 1, updatecharges => 1 },
50
        flagsrequired   => { borrowers => 1, updatecharges => 1 },
52
        debug           => 1,
51
        debug           => 1,
53
    }
52
    }
54
);
53
);
55
54
55
my $writeoff_sth;
56
my $add_writeoff_sth;
57
58
my @names = $input->param;
59
56
my $borrowernumber = $input->param('borrowernumber');
60
my $borrowernumber = $input->param('borrowernumber');
57
if ( $borrowernumber eq '' ) {
61
if ( !$borrowernumber ) {
58
    $borrowernumber = $input->param('borrowernumber0');
62
    $borrowernumber = $input->param('borrowernumber0');
59
}
63
}
60
64
61
# get borrower details
65
# get borrower details
62
my $data = GetMember( borrowernumber => $borrowernumber );
66
my $borrower = GetMember( borrowernumber => $borrowernumber );
63
my $user = $input->remote_user;
67
my $user = $input->remote_user;
68
$user ||= q{};
64
69
65
# get account details
66
my $branches = GetBranches();
70
my $branches = GetBranches();
67
my $branch   = GetBranch( $input, $branches );
71
my $branch = GetBranch( $input, $branches );
68
72
69
my @names = $input->param;
73
my $writeoff_item = $input->param('confirm_writeoff');
70
my %inp;
74
my $paycollect    = $input->param('paycollect');
71
my $check = 0;
75
if ($paycollect) {
72
for ( my $i = 0 ; $i < @names ; $i++ ) {
76
    print $input->redirect(
73
    my $temp = $input->param( $names[$i] );
77
        "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber");
74
    if ( $temp eq 'wo' ) {
78
}
75
        $inp{ $names[$i] } = $temp;
79
my $payselected = $input->param('payselected');
76
        $check = 1;
80
if ($payselected) {
77
    }
81
    payselected(@names);
78
    if ( $temp eq 'yes' ) {
79
80
# FIXME : using array +4, +5, +6 is dirty. Should use arrays for each accountline
81
        my $amount         = $input->param( $names[ $i + 4 ] );
82
        my $borrowernumber = $input->param( $names[ $i + 5 ] );
83
        my $accountno      = $input->param( $names[ $i + 6 ] );
84
        makepayment( $borrowernumber, $accountno, $amount, $user, $branch );
85
        $check = 2;
86
    }
87
    if ( $temp eq 'no'||$temp eq 'yes'||$temp eq 'wo') {
88
        my $borrowernumber = $input->param( $names[ $i + 5 ] );
89
        my $accountno      = $input->param( $names[ $i + 6 ] );
90
        my $note     = $input->param( $names[ $i + 10 ] );
91
        ModNote( $borrowernumber, $accountno, $note );
92
    }
93
}
82
}
94
83
95
my $total = $input->param('total') || '';
84
my $writeoff_all = $input->param('woall');    # writeoff all fines
96
if ( $check == 0 ) {
85
if ($writeoff_all) {
97
    if ( $total ne '' ) {
86
    writeoff_all(@names);
98
        recordpayment( $borrowernumber, $total );
87
} elsif ($writeoff_item) {
88
    my $accountno    = $input->param('accountno');
89
    my $itemno       = $input->param('itemnumber');
90
    my $account_type = $input->param('accounttype');
91
    my $amount       = $input->param('amount');
92
    writeoff( $accountno, $itemno, $account_type, $amount );
93
}
94
95
for (@names) {
96
    if (/^pay_indiv_(\d+)$/) {
97
        my $line_no = $1;
98
        redirect_to_paycollect( 'pay_individual', $line_no );
99
    } elsif (/^wo_indiv_(\d+)$/) {
100
        my $line_no = $1;
101
        redirect_to_paycollect( 'writeoff_individual', $line_no );
99
    }
102
    }
103
}
100
104
101
    my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
105
add_accounts_to_template();
102
103
    my @allfile;
104
    my @notify = NumberNotifyId($borrowernumber);
105
106
    my $numberofnotify = scalar(@notify);
107
    for ( my $j = 0 ; $j < scalar(@notify) ; $j++ ) {
108
        my @loop_pay;
109
        my ( $total , $accts, $numaccts) =
110
          GetBorNotifyAcctRecord( $borrowernumber, $notify[$j] );
111
        for ( my $i = 0 ; $i < $numaccts ; $i++ ) {
112
            my %line;
113
            if ( $accts->[$i]{'amountoutstanding'} != 0 ) {
114
                $accts->[$i]{'amount'}            += 0.00;
115
                $accts->[$i]{'amountoutstanding'} += 0.00;
116
                $line{i}           = $j . "" . $i;
117
                $line{itemnumber}  = $accts->[$i]{'itemnumber'};
118
                $line{accounttype} = $accts->[$i]{'accounttype'};
119
                $line{amount}      = sprintf( "%.2f", $accts->[$i]{'amount'} );
120
                $line{amountoutstanding} =
121
                  sprintf( "%.2f", $accts->[$i]{'amountoutstanding'} );
122
                $line{borrowernumber} = $borrowernumber;
123
                $line{accountno}      = $accts->[$i]{'accountno'};
124
                $line{description}    = $accts->[$i]{'description'};
125
                $line{note}           = $accts->[$i]{'note'};
126
                $line{title}          = $accts->[$i]{'title'};
127
                $line{notify_id}      = $accts->[$i]{'notify_id'};
128
                $line{notify_level}   = $accts->[$i]{'notify_level'};
129
                $line{net_balance} = 1 if($accts->[$i]{'amountoutstanding'} > 0); # you can't pay a credit.
130
                push( @loop_pay, \%line );
131
            }
132
        }
133
106
134
        my $totalnotify = AmountNotify( $notify[$j], $borrowernumber );
107
output_html_with_http_headers $input, $cookie, $template->output;
135
        ( $totalnotify = '0' ) if ( $totalnotify =~ /^0.00/ );
108
136
        push @allfile,
109
sub writeoff {
137
          {
110
    my ( $accountnum, $itemnum, $accounttype, $amount ) = @_;
138
            'loop_pay' => \@loop_pay,
111
139
            'notify'   => $notify[$j],
112
    # if no item is attached to fine, make sure to store it as a NULL
140
            'total'    =>  sprintf( "%.2f",$totalnotify),
113
    $itemnum ||= undef;
141
			
114
    get_writeoff_sth();
142
          };
115
    $writeoff_sth->execute( $accountnum, $borrowernumber );
143
    }
116
144
	
117
    my $acct = getnextacctno($borrowernumber);
145
if ( $data->{'category_type'} eq 'C') {
118
    $add_writeoff_sth->execute( $borrowernumber, $acct, $itemnum, $amount );
146
   my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
119
147
   my $cnt = scalar(@$catcodes);
120
    UpdateStats( $branch, 'writeoff', $amount, q{}, q{}, q{}, $borrowernumber );
148
   $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
121
149
   $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
122
    return;
150
}
123
}
151
	
124
152
$template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
125
sub add_accounts_to_template {
153
my ($picture, $dberror) = GetPatronImage($data->{'cardnumber'});
126
154
$template->param( picture => 1 ) if $picture;
127
    my ( $total, undef, undef ) = GetMemberAccountRecords($borrowernumber);
155
	
128
    my $accounts = [];
129
    my @notify   = NumberNotifyId($borrowernumber);
130
131
    my $notify_groups = [];
132
    for my $notify_id (@notify) {
133
        my ( $acct_total, $accountlines, undef ) =
134
          GetBorNotifyAcctRecord( $borrowernumber, $notify_id );
135
        if ( @{$accountlines} ) {
136
            my $totalnotify = AmountNotify( $notify_id, $borrowernumber );
137
            push @{$accounts},
138
              { accountlines => $accountlines,
139
                notify       => $notify_id,
140
                total        => $totalnotify,
141
              };
142
        }
143
    }
144
    borrower_add_additional_fields($borrower);
156
    $template->param(
145
    $template->param(
157
        allfile        => \@allfile,
146
        accounts => $accounts,
158
        firstname      => $data->{'firstname'},
147
        borrower => $borrower,
159
        surname        => $data->{'surname'},
148
        total    => $total,
160
        borrowernumber => $borrowernumber,
161
	cardnumber => $data->{'cardnumber'},
162
	categorycode => $data->{'categorycode'},
163
	category_type => $data->{'category_type'},
164
	categoryname  => $data->{'description'},
165
	address => $data->{'address'},
166
	address2 => $data->{'address2'},
167
	city => $data->{'city'},
168
    state => $data->{'state'},
169
	zipcode => $data->{'zipcode'},
170
	country => $data->{'country'},
171
	phone => $data->{'phone'},
172
	email => $data->{'email'},
173
	branchcode => $data->{'branchcode'},
174
	branchname => GetBranchName($data->{'branchcode'}),
175
	is_child        => ($data->{'category_type'} eq 'C'),
176
        total          => sprintf( "%.2f", $total )
177
    );
149
    );
178
    output_html_with_http_headers $input, $cookie, $template->output;
150
    return;
179
151
180
}
152
}
181
else {
153
182
154
sub get_for_redirect {
183
    my %inp;
155
    my ( $name, $name_in, $money ) = @_;
184
    my @name = $input->param;
156
    my $s     = q{&} . $name . q{=};
185
    for ( my $i = 0 ; $i < @name ; $i++ ) {
157
    my $value = $input->param($name_in);
186
        my $test = $input->param( $name[$i] );
158
    if ( !defined $value ) {
187
        if ( $test eq 'wo' ) {
159
        $value = ( $money == 1 ) ? 0 : q{};
188
            my $temp = $name[$i];
160
    }
189
            $temp =~ s/payfine//;
161
    if ($money) {
190
            $inp{ $name[$i] } = $temp;
162
        $s .= sprintf '%.2f', $value;
191
        }
163
    } else {
164
        $s .= $value;
192
    }
165
    }
193
    my $borrowernumber;
166
    return $s;
194
    while ( my ( $key, $value ) = each %inp ) {
167
}
195
168
196
        my $accounttype = $input->param("accounttype$value");
169
sub redirect_to_paycollect {
197
        $borrowernumber = $input->param("borrowernumber$value");
170
    my ( $action, $line_no ) = @_;
198
        my $itemno    = $input->param("itemnumber$value");
171
    my $redirect =
199
        my $amount    = $input->param("amount$value");
172
      "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber";
200
        my $accountno = $input->param("accountno$value");
173
    $redirect .= q{&};
201
        writeoff( $borrowernumber, $accountno, $itemno, $accounttype, $amount );
174
    $redirect .= "$action=1";
175
    $redirect .= get_for_redirect( 'accounttype', "accounttype$line_no", 0 );
176
    $redirect .= get_for_redirect( 'amount', "amount$line_no", 1 );
177
    $redirect .=
178
      get_for_redirect( 'amountoutstanding', "amountoutstanding$line_no", 1 );
179
    $redirect .= get_for_redirect( 'accountno',    "accountno$line_no",    0 );
180
    $redirect .= get_for_redirect( 'description',  "description$line_no",  0 );
181
    $redirect .= get_for_redirect( 'title',        "title$line_no",        0 );
182
    $redirect .= get_for_redirect( 'itemnumber',   "itemnumber$line_no",   0 );
183
    $redirect .= get_for_redirect( 'notify_id',    "notify_id$line_no",    0 );
184
    $redirect .= get_for_redirect( 'notify_level', "notify_level$line_no", 0 );
185
    $redirect .= '&remote_user=';
186
    $redirect .= $user;
187
    return print $input->redirect($redirect);
188
}
189
190
sub writeoff_all {
191
    my @params = @_;
192
    my @wo_lines = grep { /^accountno\d+$/ } @params;
193
    for (@wo_lines) {
194
        if (/(\d+)/) {
195
            my $value       = $1;
196
            my $accounttype = $input->param("accounttype$value");
197
198
            #    my $borrowernum    = $input->param("borrowernumber$value");
199
            my $itemno    = $input->param("itemnumber$value");
200
            my $amount    = $input->param("amount$value");
201
            my $accountno = $input->param("accountno$value");
202
            writeoff( $accountno, $itemno, $accounttype, $amount );
203
        }
202
    }
204
    }
205
203
    $borrowernumber = $input->param('borrowernumber');
206
    $borrowernumber = $input->param('borrowernumber');
204
    print $input->redirect(
207
    print $input->redirect(
205
        "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
208
        "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
209
    return;
206
}
210
}
207
211
208
sub writeoff {
212
sub borrower_add_additional_fields {
209
    my ( $borrowernumber, $accountnum, $itemnum, $accounttype, $amount ) = @_;
213
    my $b_ref = shift;
210
    my $user = $input->remote_user;
214
211
    my $dbh  = C4::Context->dbh;
215
# some borrower info is not returned in the standard call despite being assumed
212
    undef $itemnum unless $itemnum; # if no item is attached to fine, make sure to store it as a NULL
216
# in a number of templates. It should not be the business of this script but in lieu of
213
    my $sth =
217
# a revised api here it is ...
214
      $dbh->prepare(
218
    if ( $b_ref->{category_type} eq 'C' ) {
215
"Update accountlines set amountoutstanding=0 where accountno=? and borrowernumber=?"
219
        my ( $catcodes, $labels ) =
216
      );
220
          GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
217
    $sth->execute( $accountnum, $borrowernumber );
221
        if ( @{$catcodes} ) {
218
    $sth->finish;
222
            if ( @{$catcodes} > 1 ) {
219
    $sth = $dbh->prepare("select max(accountno) from accountlines");
223
                $b_ref->{CATCODE_MULTI} = 1;
220
    $sth->execute;
224
            } elsif ( @{$catcodes} == 1 ) {
221
    my $account = $sth->fetchrow_hashref;
225
                $b_ref->{catcode} = $catcodes->[0];
222
    $sth->finish;
226
            }
223
    $account->{'max(accountno)'}++;
227
        }
224
    $sth = $dbh->prepare(
228
    } elsif ( $b_ref->{category_type} eq 'A' ) {
225
"insert into accountlines (borrowernumber,accountno,itemnumber,date,amount,description,accounttype)
229
        $b_ref->{adultborrower} = 1;
226
						values (?,?,?,now(),?,'Writeoff','W')"
230
    }
227
    );
231
    my ( $picture, $dberror ) = GetPatronImage( $b_ref->{cardnumber} );
228
    $sth->execute( $borrowernumber, $account->{'max(accountno)'},
232
    if ($picture) {
229
        $itemnum, $amount );
233
        $b_ref->{has_picture} = 1;
230
    $sth->finish;
234
    }
231
    UpdateStats( $branch, 'writeoff', $amount, '', '', '',
235
232
        $borrowernumber );
236
    $b_ref->{branchname} = GetBranchName( $b_ref->{branchcode} );
237
    return;
238
}
239
240
sub payselected {
241
    my @params = @_;
242
    my $amt    = 0;
243
    my @lines_to_pay;
244
    foreach (@params) {
245
        if (/^incl_par_(\d+)$/) {
246
            my $index = $1;
247
            push @lines_to_pay, $input->param("accountno$index");
248
            $amt += $input->param("amountoutstanding$index");
249
        }
250
    }
251
    $amt = '&amt=' . $amt;
252
    my $sel = '&selected=' . join ',', @lines_to_pay;
253
    my $redirect =
254
        "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber"
255
      . $amt
256
      . $sel;
257
258
    print $input->redirect($redirect);
259
    return;
260
}
261
262
sub get_writeoff_sth {
263
264
    # lets prepare these statement handles only once
265
    if ($writeoff_sth) {
266
        return;
267
    } else {
268
        my $dbh = C4::Context->dbh;
269
270
        # Do we need to validate accounttype
271
        my $sql = 'Update accountlines set amountoutstanding=0 '
272
          . 'WHERE accountno=? and borrowernumber=?';
273
        $writeoff_sth = $dbh->prepare($sql);
274
        my $insert =
275
q{insert into accountlines (borrowernumber,accountno,itemnumber,date,amount,description,accounttype)}
276
          . q{values (?,?,?,now(),?,'Writeoff','W')};
277
        $add_writeoff_sth = $dbh->prepare($insert);
278
    }
279
    return;
233
}
280
}
(-)a/members/paycollect.pl (-1 / +171 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
# Copyright 2009,2010 PTFS Inc.
3
# Copyright 2011 PTFS-Europe Ltd
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use strict;
21
use warnings;
22
use C4::Context;
23
use C4::Auth;
24
use C4::Output;
25
use CGI;
26
use C4::Members;
27
use C4::Accounts;
28
use C4::Koha;
29
use C4::Branch;
30
31
my $input = CGI->new();
32
33
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
34
    {   template_name   => 'members/paycollect.tmpl',
35
        query           => $input,
36
        type            => 'intranet',
37
        authnotrequired => 0,
38
        flagsrequired   => { borrowers => 1, updatecharges => 1 },
39
        debug           => 1,
40
    }
41
);
42
43
# get borrower details
44
my $borrowernumber = $input->param('borrowernumber');
45
my $borrower       = GetMember( borrowernumber => $borrowernumber );
46
my $user           = $input->remote_user;
47
48
# get account details
49
my $branch = GetBranch( $input, GetBranches() );
50
51
my ( $total_due, $accts, $numaccts ) = GetMemberAccountRecords($borrowernumber);
52
my $total_paid = $input->param('paid');
53
54
my $individual   = $input->param('pay_individual');
55
my $writeoff     = $input->param('writeoff_individual');
56
my $select_lines = $input->param('selected');
57
my $select       = $input->param('selected_accts');
58
my $accountno;
59
60
if ( $individual || $writeoff ) {
61
    if ($individual) {
62
        $template->param( pay_individual => 1 );
63
    } elsif ($writeoff) {
64
        $template->param( writeoff_individual => 1 );
65
    }
66
    my $accounttype       = $input->param('accounttype');
67
    my $amount            = $input->param('amount');
68
    my $amountoutstanding = $input->param('amountoutstanding');
69
    $accountno = $input->param('accountno');
70
    my $description  = $input->param('description');
71
    my $title        = $input->param('title');
72
    my $notify_id    = $input->param('notify_id');
73
    my $notify_level = $input->param('notify_level');
74
    $total_due = $amountoutstanding;
75
    $template->param(
76
        accounttype       => $accounttype,
77
        accountno         => $accountno,
78
        amount            => $amount,
79
        amountoutstanding => $amountoutstanding,
80
        title             => $title,
81
        description       => $description,
82
        notify_id         => $notify_id,
83
        notify_level      => $notify_level,
84
    );
85
} elsif ($select_lines) {
86
    $total_due = $input->param('amt');
87
    $template->param(
88
        selected_accts => $select_lines,
89
        amt            => $total_due
90
    );
91
}
92
93
if ( $total_paid and $total_paid ne '0.00' ) {
94
    if ( $total_paid < 0 or $total_paid > $total_due ) {
95
        $template->param(
96
            error => sprintf( 'You must pay a value less than or equal to %f.2',
97
                $total_due )
98
        );
99
    } else {
100
        if ($individual) {
101
            if ( $total_paid == $total_due ) {
102
                makepayment( $borrowernumber, $accountno, $total_paid, $user,
103
                    $branch );
104
            } else {
105
                makepartialpayment( $borrowernumber, $accountno, $total_paid,
106
                    $user, $branch );
107
            }
108
            print $input->redirect(
109
                "/cgi-bin/koha/members/pay.pl?borrowernumber=$borrowernumber");
110
        } else {
111
            if ($select) {
112
                if ( $select =~ /^([\d,]*).*/ ) {
113
                    $select = $1;    # ensure passing no junk
114
                }
115
                my @acc = split /,/, $select;
116
                recordpayment_selectaccts( $borrowernumber, $total_paid,
117
                    \@acc );
118
            } else {
119
                recordpayment( $borrowernumber, $total_paid );
120
            }
121
122
# recordpayment does not return success or failure so lets redisplay the boraccount
123
124
            print $input->redirect(
125
"/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber"
126
            );
127
        }
128
    }
129
} else {
130
    $total_paid = '0.00';    #TODO not right with pay_individual
131
}
132
133
borrower_add_additional_fields($borrower);
134
135
$template->param(
136
137
 #borrowenumber  => $borrower->{borrowernumber}, # some templates require global
138
    borrowenumber => $borrowernumber,    # some templates require global
139
    borrower      => $borrower,
140
    total         => $total_due
141
);
142
143
output_html_with_http_headers $input, $cookie, $template->output;
144
145
sub borrower_add_additional_fields {
146
    my $b_ref = shift;
147
148
# some borrower info is not returned in the standard call despite being assumed
149
# in a number of templates. It should not be the business of this script but in lieu of
150
# a revised api here it is ...
151
    if ( $b_ref->{category_type} eq 'C' ) {
152
        my ( $catcodes, $labels ) =
153
          GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
154
        if ( @{$catcodes} ) {
155
            if ( @{$catcodes} > 1 ) {
156
                $b_ref->{CATCODE_MULTI} = 1;
157
            } elsif ( @{$catcodes} == 1 ) {
158
                $b_ref->{catcode} = $catcodes->[0];
159
            }
160
        }
161
    } elsif ( $b_ref->{category_type} eq 'A' ) {
162
        $b_ref->{adultborrower} = 1;
163
    }
164
    my ( $picture, $dberror ) = GetPatronImage( $b_ref->{cardnumber} );
165
    if ($picture) {
166
        $b_ref->{has_picture} = 1;
167
    }
168
169
    $b_ref->{branchname} = GetBranchName( $b_ref->{branchcode} );
170
    return;
171
}

Return to bug 3498