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

(-)a/C4/Accounts.pm (-18 / +201 lines)
Lines 24-29 use C4::Context; Link Here
24
use C4::Stats;
24
use C4::Stats;
25
use C4::Members;
25
use C4::Members;
26
use C4::Circulation qw(ReturnLostItem);
26
use C4::Circulation qw(ReturnLostItem);
27
use C4::Log qw(logaction);
28
29
use Data::Dumper qw(Dumper);
27
30
28
use vars qw($VERSION @ISA @EXPORT);
31
use vars qw($VERSION @ISA @EXPORT);
29
32
Lines 106-111 sub recordpayment { Link Here
106
    $sth->execute($borrowernumber);
109
    $sth->execute($borrowernumber);
107
110
108
    # offset transactions
111
    # offset transactions
112
    my @ids;
109
    while ( ( $accdata = $sth->fetchrow_hashref ) and ( $amountleft > 0 ) ) {
113
    while ( ( $accdata = $sth->fetchrow_hashref ) and ( $amountleft > 0 ) ) {
110
        if ( $accdata->{'amountoutstanding'} < $amountleft ) {
114
        if ( $accdata->{'amountoutstanding'} < $amountleft ) {
111
            $newamtos = 0;
115
            $newamtos = 0;
Lines 121-135 sub recordpayment { Link Here
121
     WHERE (accountlines_id = ?)"
125
     WHERE (accountlines_id = ?)"
122
        );
126
        );
123
        $usth->execute( $newamtos, $thisacct );
127
        $usth->execute( $newamtos, $thisacct );
124
        $usth->finish;
128
125
#        $usth = $dbh->prepare(
129
        if ( C4::Context->preference("FinesLog") ) {
126
#            "INSERT INTO accountoffsets
130
            $accdata->{'amountoutstanding_new'} = $newamtos;
127
#     (borrowernumber, accountno, offsetaccount,  offsetamount)
131
            logaction("FINES", 'MODIFY', $borrowernumber, Dumper({
128
#     VALUES (?,?,?,?)"
132
                action                => 'fee_payment',
129
#        );
133
                borrowernumber        => $accdata->{'borrowernumber'},
130
#        $usth->execute( $borrowernumber, $accdata->{'accountno'},
134
                old_amountoutstanding => $accdata->{'amountoutstanding'},
131
#            $nextaccntno, $newamtos );
135
                new_amountoutstanding => $newamtos,
132
        $usth->finish;
136
                amount_paid           => $accdata->{'amountoutstanding'} - $newamtos,
137
                accountlines_id       => $accdata->{'accountlines_id'},
138
                accountno             => $accdata->{'accountno'},
139
                manager_id            => $manager_id,
140
            }));
141
            push( @ids, $accdata->{'accountlines_id'} );
142
        }
133
    }
143
    }
134
144
135
    # create new line
145
    # create new line
Lines 139-147 sub recordpayment { Link Here
139
  VALUES (?,?,now(),?,'Payment,thanks','Pay',?,?)"
149
  VALUES (?,?,now(),?,'Payment,thanks','Pay',?,?)"
140
    );
150
    );
141
    $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, 0 - $amountleft, $manager_id );
151
    $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, 0 - $amountleft, $manager_id );
142
    $usth->finish;
152
143
    UpdateStats( $branch, 'payment', $data, '', '', '', $borrowernumber, $nextaccntno );
153
    UpdateStats( $branch, 'payment', $data, '', '', '', $borrowernumber, $nextaccntno );
144
    $sth->finish;
154
155
    if ( C4::Context->preference("FinesLog") ) {
156
        $accdata->{'amountoutstanding_new'} = $newamtos;
157
        logaction("FINES", 'CREATE',$borrowernumber,Dumper({
158
            action            => 'create_payment',
159
            borrowernumber    => $borrowernumber,
160
            accountno         => $nextaccntno,
161
            amount            => $data * -1,
162
            amountoutstanding => $amountleft * -1,
163
            accounttype       => 'Pay',
164
            accountlines_paid => \@ids,
165
            manager_id        => $manager_id,
166
        }));
167
    }
168
145
}
169
}
146
170
147
=head2 makepayment
171
=head2 makepayment
Lines 180-186 sub makepayment { Link Here
180
    my $data = $sth->fetchrow_hashref;
204
    my $data = $sth->fetchrow_hashref;
181
    $sth->finish;
205
    $sth->finish;
182
206
183
    if($data->{'accounttype'} eq "Pay"){
207
    my $payment;
208
    if ( $data->{'accounttype'} eq "Pay" ){
184
        my $udp = 		
209
        my $udp = 		
185
            $dbh->prepare(
210
            $dbh->prepare(
186
                "UPDATE accountlines
211
                "UPDATE accountlines
Lines 202-208 sub makepayment { Link Here
202
        $udp->finish;
227
        $udp->finish;
203
228
204
         # create new line
229
         # create new line
205
        my $payment = 0 - $amount;
230
        $payment = 0 - $amount;
206
        
231
        
207
        my $ins = 
232
        my $ins = 
208
            $dbh->prepare( 
233
            $dbh->prepare( 
Lines 214-225 sub makepayment { Link Here
214
        $ins->finish;
239
        $ins->finish;
215
    }
240
    }
216
241
242
    if ( C4::Context->preference("FinesLog") ) {
243
        logaction("FINES", 'MODIFY', $borrowernumber, Dumper({
244
            action                => 'fee_payment',
245
            borrowernumber        => $borrowernumber,
246
            old_amountoutstanding => $data->{'amountoutstanding'},
247
            new_amountoutstanding => 0,
248
            amount_paid           => $data->{'amountoutstanding'},
249
            accountlines_id       => $data->{'accountlines_id'},
250
            accountno             => $data->{'accountno'},
251
            manager_id            => $manager_id,
252
        }));
253
254
255
        logaction("FINES", 'CREATE',$borrowernumber,Dumper({
256
            action            => 'create_payment',
257
            borrowernumber    => $borrowernumber,
258
            accountno         => $nextaccntno,
259
            amount            => $payment,
260
            amountoutstanding => 0,,
261
            accounttype       => 'Pay',
262
            accountlines_paid => [$data->{'accountlines_id'}],
263
            manager_id        => $manager_id,
264
        }));
265
    }
266
267
217
    # FIXME - The second argument to &UpdateStats is supposed to be the
268
    # FIXME - The second argument to &UpdateStats is supposed to be the
218
    # branch code.
269
    # branch code.
219
    # UpdateStats is now being passed $accountno too. MTJ
270
    # UpdateStats is now being passed $accountno too. MTJ
220
    UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber,
271
    UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber,
221
        $accountno );
272
        $accountno );
222
    #from perldoc: for SELECT only #$sth->finish;
223
273
224
    #check to see what accounttype
274
    #check to see what accounttype
225
    if ( $data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L' ) {
275
    if ( $data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L' ) {
Lines 314-320 sub chargelostitem{ Link Here
314
        $sth2->execute($borrowernumber,$accountno,$amount,
364
        $sth2->execute($borrowernumber,$accountno,$amount,
315
        $description,$amount,$itemnumber,$manager_id);
365
        $description,$amount,$itemnumber,$manager_id);
316
        $sth2->finish;
366
        $sth2->finish;
317
    # FIXME: Log this ?
367
368
        if ( C4::Context->preference("FinesLog") ) {
369
            logaction("FINES", 'CREATE', $borrowernumber, Dumper({
370
                action            => 'create_fee',
371
                borrowernumber    => $borrowernumber,
372
                accountno         => $accountno,
373
                amount            => $amount,
374
                amountoutstanding => $amount,
375
                description       => $description,
376
                accounttype       => 'L',
377
                itemnumber        => $itemnumber,
378
                manager_id        => $manager_id,
379
            }));
380
        }
381
318
    }
382
    }
319
}
383
}
320
384
Lines 409-414 sub manualinvoice { Link Here
409
        $sth->execute( $borrowernumber, $accountno, $amount, $desc, $type,
473
        $sth->execute( $borrowernumber, $accountno, $amount, $desc, $type,
410
            $amountleft, $notifyid, $note, $manager_id );
474
            $amountleft, $notifyid, $note, $manager_id );
411
    }
475
    }
476
477
    if ( C4::Context->preference("FinesLog") ) {
478
        logaction("FINES", 'CREATE',$borrowernumber,Dumper({
479
            action            => 'create_fee',
480
            borrowernumber    => $borrowernumber,
481
            accountno         => $accountno,
482
            amount            => $amount,
483
            description       => $desc,
484
            accounttype       => $type,
485
            amountoutstanding => $amountleft,
486
            notify_id         => $notifyid,
487
            note              => $note,
488
            itemnumber        => $itemnum,
489
            manager_id        => $manager_id,
490
        }));
491
    }
492
412
    return 0;
493
    return 0;
413
}
494
}
414
495
Lines 653-659 sub ReversePayment { Link Here
653
    my ( $accountlines_id ) = @_;
734
    my ( $accountlines_id ) = @_;
654
    my $dbh = C4::Context->dbh;
735
    my $dbh = C4::Context->dbh;
655
736
656
    my $sth = $dbh->prepare('SELECT amountoutstanding FROM accountlines WHERE accountlines_id = ?');
737
    my $sth = $dbh->prepare('SELECT * FROM accountlines WHERE accountlines_id = ?');
657
    $sth->execute( $accountlines_id );
738
    $sth->execute( $accountlines_id );
658
    my $row = $sth->fetchrow_hashref();
739
    my $row = $sth->fetchrow_hashref();
659
    my $amount_outstanding = $row->{'amountoutstanding'};
740
    my $amount_outstanding = $row->{'amountoutstanding'};
Lines 665-670 sub ReversePayment { Link Here
665
        $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = 0, description = CONCAT( description, " Reversed -" ) WHERE accountlines_id = ?');
746
        $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = 0, description = CONCAT( description, " Reversed -" ) WHERE accountlines_id = ?');
666
        $sth->execute( $accountlines_id );
747
        $sth->execute( $accountlines_id );
667
    }
748
    }
749
750
    if ( C4::Context->preference("FinesLog") ) {
751
        my $manager_id = 0;
752
        $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
753
754
        if ( $amount_outstanding <= 0 ) {
755
            $row->{'amountoutstanding'} *= -1;
756
        } else {
757
            $row->{'amountoutstanding'} = '0';
758
        }
759
        $row->{'description'} .= ' Reversed -';
760
        logaction("FINES", 'MODIFY', $row->{'borrowernumber'}, Dumper({
761
            action                => 'reverse_fee_payment',
762
            borrowernumber        => $row->{'borrowernumber'},
763
            old_amountoutstanding => $row->{'amountoutstanding'},
764
            new_amountoutstanding => 0 - $amount_outstanding,,
765
            accountlines_id       => $row->{'accountlines_id'},
766
            accountno             => $row->{'accountno'},
767
            manager_id            => $manager_id,
768
        }));
769
770
    }
771
668
}
772
}
669
773
670
=head2 recordpayment_selectaccts
774
=head2 recordpayment_selectaccts
Lines 709-714 sub recordpayment_selectaccts { Link Here
709
    # offset transactions
813
    # offset transactions
710
    my $sth     = $dbh->prepare('UPDATE accountlines SET amountoutstanding= ? ' .
814
    my $sth     = $dbh->prepare('UPDATE accountlines SET amountoutstanding= ? ' .
711
        'WHERE accountlines_id=?');
815
        'WHERE accountlines_id=?');
816
817
    my @ids;
712
    for my $accdata ( @{$rows} ) {
818
    for my $accdata ( @{$rows} ) {
713
        if ($amountleft == 0) {
819
        if ($amountleft == 0) {
714
            last;
820
            last;
Lines 723-728 sub recordpayment_selectaccts { Link Here
723
        }
829
        }
724
        my $thisacct = $accdata->{accountlines_id};
830
        my $thisacct = $accdata->{accountlines_id};
725
        $sth->execute( $newamtos, $thisacct );
831
        $sth->execute( $newamtos, $thisacct );
832
833
        if ( C4::Context->preference("FinesLog") ) {
834
            logaction("FINES", 'MODIFY', $borrowernumber, Dumper({
835
                action                => 'fee_payment',
836
                borrowernumber        => $borrowernumber,
837
                old_amountoutstanding => $accdata->{'amountoutstanding'},
838
                new_amountoutstanding => $newamtos,
839
                amount_paid           => $accdata->{'amountoutstanding'} - $newamtos,
840
                accountlines_id       => $accdata->{'accountlines_id'},
841
                accountno             => $accdata->{'accountno'},
842
                manager_id            => $manager_id,
843
            }));
844
            push( @ids, $accdata->{'accountlines_id'} );
845
        }
846
726
    }
847
    }
727
848
728
    # create new line
849
    # create new line
Lines 731-736 sub recordpayment_selectaccts { Link Here
731
    q|VALUES (?,?,now(),?,'Payment,thanks','Pay',?,?)|;
852
    q|VALUES (?,?,now(),?,'Payment,thanks','Pay',?,?)|;
732
    $dbh->do($sql,{},$borrowernumber, $nextaccntno, 0 - $amount, 0 - $amountleft, $manager_id );
853
    $dbh->do($sql,{},$borrowernumber, $nextaccntno, 0 - $amount, 0 - $amountleft, $manager_id );
733
    UpdateStats( $branch, 'payment', $amount, '', '', '', $borrowernumber, $nextaccntno );
854
    UpdateStats( $branch, 'payment', $amount, '', '', '', $borrowernumber, $nextaccntno );
855
856
    if ( C4::Context->preference("FinesLog") ) {
857
        logaction("FINES", 'CREATE',$borrowernumber,Dumper({
858
            action            => 'create_payment',
859
            borrowernumber    => $borrowernumber,
860
            accountno         => $nextaccntno,
861
            amount            => 0 - $amount,
862
            amountoutstanding => 0 - $amountleft,
863
            accounttype       => 'Pay',
864
            accountlines_paid => \@ids,
865
            manager_id        => $manager_id,
866
        }));
867
    }
868
734
    return;
869
    return;
735
}
870
}
736
871
Lines 755-760 sub makepartialpayment { Link Here
755
    my $update = 'UPDATE  accountlines SET amountoutstanding = ?  WHERE   accountlines_id = ? ';
890
    my $update = 'UPDATE  accountlines SET amountoutstanding = ?  WHERE   accountlines_id = ? ';
756
    $dbh->do( $update, undef, $new_outstanding, $accountlines_id);
891
    $dbh->do( $update, undef, $new_outstanding, $accountlines_id);
757
892
893
    if ( C4::Context->preference("FinesLog") ) {
894
        logaction("FINES", 'MODIFY', $borrowernumber, Dumper({
895
            action                => 'fee_payment',
896
            borrowernumber        => $borrowernumber,
897
            old_amountoutstanding => $data->{'amountoutstanding'},
898
            new_amountoutstanding => $new_outstanding,
899
            amount_paid           => $data->{'amountoutstanding'} - $new_outstanding,
900
            accountlines_id       => $data->{'accountlines_id'},
901
            accountno             => $data->{'accountno'},
902
            manager_id            => $manager_id,
903
        }));
904
    }
905
758
    # create new line
906
    # create new line
759
    my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, '
907
    my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, '
760
    .  'description, accounttype, amountoutstanding, itemnumber, manager_id) '
908
    .  'description, accounttype, amountoutstanding, itemnumber, manager_id) '
Lines 765-770 sub makepartialpayment { Link Here
765
913
766
    UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber, $accountno );
914
    UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber, $accountno );
767
915
916
    if ( C4::Context->preference("FinesLog") ) {
917
        logaction("FINES", 'CREATE',$borrowernumber,Dumper({
918
            action            => 'create_payment',
919
            borrowernumber    => $user,
920
            accountno         => $nextaccntno,
921
            amount            => 0 - $amount,
922
            accounttype       => 'Pay',
923
            itemnumber        => $data->{'itemnumber'},
924
            accountlines_paid => [ $data->{'accountlines_id'} ],
925
            manager_id        => $manager_id,
926
        }));
927
    }
928
768
    return;
929
    return;
769
}
930
}
770
931
Lines 783-789 C<$branch> is the branchcode of the library where the writeoff occurred. Link Here
783
=cut
944
=cut
784
945
785
sub WriteOffFee {
946
sub WriteOffFee {
786
    my ( $borrowernumber, $accountline_id, $itemnum, $accounttype, $amount, $branch ) = @_;
947
    my ( $borrowernumber, $accountlines_id, $itemnum, $accounttype, $amount, $branch ) = @_;
787
    $branch ||= C4::Context->userenv->{branch};
948
    $branch ||= C4::Context->userenv->{branch};
788
    my $manager_id = 0;
949
    my $manager_id = 0;
789
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
950
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
Lines 799-805 sub WriteOffFee { Link Here
799
        WHERE accountlines_id = ? AND borrowernumber = ?
960
        WHERE accountlines_id = ? AND borrowernumber = ?
800
    ";
961
    ";
801
    $sth = $dbh->prepare( $query );
962
    $sth = $dbh->prepare( $query );
802
    $sth->execute( $accountline_id, $borrowernumber );
963
    $sth->execute( $accountlines_id, $borrowernumber );
964
965
    if ( C4::Context->preference("FinesLog") ) {
966
        logaction("FINES", 'MODIFY', $borrowernumber, Dumper({
967
            action                => 'fee_writeoff',
968
            borrowernumber        => $borrowernumber,
969
            accountlines_id       => $accountlines_id,
970
            manager_id            => $manager_id,
971
        }));
972
    }
803
973
804
    $query ="
974
    $query ="
805
        INSERT INTO accountlines
975
        INSERT INTO accountlines
Lines 810-815 sub WriteOffFee { Link Here
810
    my $acct = getnextacctno($borrowernumber);
980
    my $acct = getnextacctno($borrowernumber);
811
    $sth->execute( $borrowernumber, $acct, $itemnum, $amount, $manager_id );
981
    $sth->execute( $borrowernumber, $acct, $itemnum, $amount, $manager_id );
812
982
983
    if ( C4::Context->preference("FinesLog") ) {
984
        logaction("FINES", 'CREATE',$borrowernumber,Dumper({
985
            action            => 'create_writeoff',
986
            borrowernumber    => $borrowernumber,
987
            accountno         => $acct,
988
            amount            => 0 - $amount,
989
            accounttype       => 'W',
990
            itemnumber        => $itemnum,
991
            accountlines_paid => [ $accountlines_id ],
992
            manager_id        => $manager_id,
993
        }));
994
    }
995
813
    UpdateStats( $branch, 'writeoff', $amount, q{}, q{}, q{}, $borrowernumber );
996
    UpdateStats( $branch, 'writeoff', $amount, q{}, q{}, q{}, $borrowernumber );
814
997
815
}
998
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/logs.pref (-2 / +1 lines)
Lines 28-34 Logging: Link Here
28
          choices:
28
          choices:
29
              on: Log
29
              on: Log
30
              off: "Don't log"
30
              off: "Don't log"
31
        - when overdue fines are charged or automatically forgiven.
31
        - when fines are charged, paid, or forgiven.
32
    -
32
    -
33
        - pref: IssueLog
33
        - pref: IssueLog
34
          choices:
34
          choices:
35
- 

Return to bug 9293