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

(-)a/C4/Accounts.pm (-5 / +57 lines)
Lines 33-44 BEGIN { Link Here
33
	require Exporter;
33
	require Exporter;
34
	@ISA    = qw(Exporter);
34
	@ISA    = qw(Exporter);
35
	@EXPORT = qw(
35
	@EXPORT = qw(
36
		&recordpayment &makepayment &manualinvoice
36
		&recordpayment
37
		&getnextacctno &reconcileaccount &getcharges &ModNote &getcredits
37
		&makepayment
38
		&getrefunds &chargelostitem
38
		&manualinvoice
39
		&getnextacctno
40
		&reconcileaccount
41
		&getcharges 
42
		&ModNote 
43
		&getcredits
44
		&getrefunds 
45
		&chargelostitem
39
		&ReversePayment
46
		&ReversePayment
40
        makepartialpayment
47
                &makepartialpayment
41
        recordpayment_selectaccts
48
                &recordpayment_selectaccts
49
                &WriteOff
42
	);
50
	);
43
}
51
}
44
52
Lines 756-762 sub makepartialpayment { Link Here
756
    return;
764
    return;
757
}
765
}
758
766
767
=head2 WriteOff
759
768
769
  WriteOff( $borrowernumber, $accountnum, $itemnum, $accounttype, $amount, $branch );
770
771
Write off a fine for a patron.
772
C<$borrowernumber> is the patron's borrower number.
773
C<$accountnum> is the accountnumber of the fee to write off.
774
C<$itemnum> is the itemnumber of of item whose fine is being written off.
775
C<$accounttype> is the account type of the fine being written off.
776
C<$amount> is a floating-point number, giving the amount that is being written off. 
777
C<$branch> is the branchcode of the library where the writeoff occurred.
778
779
=cut
780
781
sub WriteOff {
782
    my ( $borrowernumber, $accountnum, $itemnum, $accounttype, $amount, $branch ) = @_;
783
    my $branch ||= C4::Context->userenv->{branch};
784
    my $manager_id = 0;
785
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
786
787
    # if no item is attached to fine, make sure to store it as a NULL
788
    $itemnum ||= undef;
789
    
790
    my ( $sth, $query );
791
    my $dbh = C4::Context->dbh();
792
    
793
    $query = "
794
        UPDATE accountlines SET amountoutstanding = 0 
795
        WHERE accountno = ? AND borrowernumber = ?
796
    ";
797
    $sth = $dbh->prepare( $query );
798
    $sth->execute( $accountnum, $borrowernumber );
799
800
    $query ="
801
        INSERT INTO accountlines 
802
        ( borrowernumber, accountno, itemnumber, date, amount, description, accounttype, manager_id )
803
        VALUES ( ?, ?, ?, NOW(), ?, 'Writeoff', 'W', ? )
804
    ";
805
    $sth = $dbh->prepare( $query );
806
    my $acct = getnextacctno($borrowernumber);
807
    $sth->execute( $borrowernumber, $acct, $itemnum, $amount, $manager_id );
808
809
    UpdateStats( $branch, 'writeoff', $amount, q{}, q{}, q{}, $borrowernumber );
810
811
}
760
812
761
END { }    # module clean-up code here (global destructor)
813
END { }    # module clean-up code here (global destructor)
762
814
(-)a/members/pay.pl (-43 / +2 lines)
Lines 53-61 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
53
    }
53
    }
54
);
54
);
55
55
56
my $writeoff_sth;
57
my $add_writeoff_sth;
58
59
my @names = $input->param;
56
my @names = $input->param;
60
57
61
my $borrowernumber = $input->param('borrowernumber');
58
my $borrowernumber = $input->param('borrowernumber');
Lines 90-96 if ($writeoff_all) { Link Here
90
    my $itemno       = $input->param('itemnumber');
87
    my $itemno       = $input->param('itemnumber');
91
    my $account_type = $input->param('accounttype');
88
    my $account_type = $input->param('accounttype');
92
    my $amount       = $input->param('amountoutstanding');
89
    my $amount       = $input->param('amountoutstanding');
93
    writeoff( $accountno, $itemno, $account_type, $amount );
90
    WriteOff( $borrowernumber, $accountno, $itemno, $account_type, $amount, $branch );
94
}
91
}
95
92
96
for (@names) {
93
for (@names) {
Lines 109-131 add_accounts_to_template(); Link Here
109
106
110
output_html_with_http_headers $input, $cookie, $template->output;
107
output_html_with_http_headers $input, $cookie, $template->output;
111
108
112
sub writeoff {
113
    my ( $accountnum, $itemnum, $accounttype, $amount ) = @_;
114
    my $manager_id = 0;
115
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
116
117
    # if no item is attached to fine, make sure to store it as a NULL
118
    $itemnum ||= undef;
119
    get_writeoff_sth();
120
    $writeoff_sth->execute( $accountnum, $borrowernumber );
121
122
    my $acct = getnextacctno($borrowernumber);
123
    $add_writeoff_sth->execute( $borrowernumber, $acct, $itemnum, $amount, $manager_id );
124
125
    UpdateStats( $branch, 'writeoff', $amount, q{}, q{}, q{}, $borrowernumber );
126
127
    return;
128
}
129
109
130
sub add_accounts_to_template {
110
sub add_accounts_to_template {
131
111
Lines 204-210 sub writeoff_all { Link Here
204
            my $itemno    = $input->param("itemnumber$value");
184
            my $itemno    = $input->param("itemnumber$value");
205
            my $amount    = $input->param("amount$value");
185
            my $amount    = $input->param("amount$value");
206
            my $accountno = $input->param("accountno$value");
186
            my $accountno = $input->param("accountno$value");
207
            writeoff( $accountno, $itemno, $accounttype, $amount );
187
            WriteOff( $borrowernumber, $accountno, $itemno, $accounttype, $amount, $branch );
208
        }
188
        }
209
    }
189
    }
210
190
Lines 270-292 sub payselected { Link Here
270
    print $input->redirect($redirect);
250
    print $input->redirect($redirect);
271
    return;
251
    return;
272
}
252
}
273
274
sub get_writeoff_sth {
275
276
    # lets prepare these statement handles only once
277
    if ($writeoff_sth) {
278
        return;
279
    } else {
280
        my $dbh = C4::Context->dbh;
281
282
        # Do we need to validate accounttype
283
        my $sql = 'Update accountlines set amountoutstanding=0 '
284
          . 'WHERE accountno=? and borrowernumber=?';
285
        $writeoff_sth = $dbh->prepare($sql);
286
        my $insert =
287
q{insert into accountlines (borrowernumber,accountno,itemnumber,date,amount,description,accounttype,manager_id)}
288
          . q{values (?,?,?,now(),?,'Writeoff','W',?)};
289
        $add_writeoff_sth = $dbh->prepare($insert);
290
    }
291
    return;
292
}
293
- 

Return to bug 7597