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

(-)a/C4/Accounts.pm (-58 / +56 lines)
Lines 72-78 patron. Link Here
72
72
73
Record payment by a patron. C<$borrowernumber> is the patron's
73
Record payment by a patron. C<$borrowernumber> is the patron's
74
borrower number. C<$payment> is a floating-point number, giving the
74
borrower number. C<$payment> is a floating-point number, giving the
75
amount that was paid. 
75
amount that was paid.
76
76
77
Amounts owed are paid off oldest first. That is, if the patron has a
77
Amounts owed are paid off oldest first. That is, if the patron has a
78
$1 fine from Feb. 1, another $1 fine from Mar. 1, and makes a payment
78
$1 fine from Feb. 1, another $1 fine from Mar. 1, and makes a payment
Lines 113-124 sub recordpayment { Link Here
113
            $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
113
            $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
114
            $amountleft = 0;
114
            $amountleft = 0;
115
        }
115
        }
116
        my $thisacct = $accdata->{accountno};
116
        my $thisacct = $accdata->{accountlinesid};
117
        my $usth     = $dbh->prepare(
117
        my $usth     = $dbh->prepare(
118
            "UPDATE accountlines SET amountoutstanding= ?
118
            "UPDATE accountlines SET amountoutstanding= ?
119
     WHERE (borrowernumber = ?) AND (accountno=?)"
119
     WHERE (accountlinesid = ?)"
120
        );
120
        );
121
        $usth->execute( $newamtos, $borrowernumber, $thisacct );
121
        $usth->execute( $newamtos, $thisacct );
122
        $usth->finish;
122
        $usth->finish;
123
#        $usth = $dbh->prepare(
123
#        $usth = $dbh->prepare(
124
#            "INSERT INTO accountoffsets
124
#            "INSERT INTO accountoffsets
Lines 144-150 sub recordpayment { Link Here
144
144
145
=head2 makepayment
145
=head2 makepayment
146
146
147
  &makepayment($borrowernumber, $acctnumber, $amount, $branchcode);
147
  &makepayment($accountlinesid, $borrowernumber, $acctnumber, $amount, $branchcode);
148
148
149
Records the fact that a patron has paid off the entire amount he or
149
Records the fact that a patron has paid off the entire amount he or
150
she owes.
150
she owes.
Lines 165-171 sub makepayment { Link Here
165
    #here we update both the accountoffsets and the account lines
165
    #here we update both the accountoffsets and the account lines
166
    #updated to check, if they are paying off a lost item, we return the item
166
    #updated to check, if they are paying off a lost item, we return the item
167
    # from their card, and put a note on the item record
167
    # from their card, and put a note on the item record
168
    my ( $borrowernumber, $accountno, $amount, $user, $branch ) = @_;
168
    my ( $accountlinesid, $borrowernumber, $accountno, $amount, $user, $branch ) = @_;
169
    my $dbh = C4::Context->dbh;
169
    my $dbh = C4::Context->dbh;
170
    my $manager_id = 0;
170
    my $manager_id = 0;
171
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; 
171
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; 
Lines 173-182 sub makepayment { Link Here
173
    # begin transaction
173
    # begin transaction
174
    my $nextaccntno = getnextacctno($borrowernumber);
174
    my $nextaccntno = getnextacctno($borrowernumber);
175
    my $newamtos    = 0;
175
    my $newamtos    = 0;
176
    my $sth =
176
    my $sth         = $dbh->prepare("SELECT * FROM accountlines WHERE accountlinesid=?");
177
      $dbh->prepare(
177
    $sth->execute( $accountlinesid );
178
        "SELECT * FROM accountlines WHERE  borrowernumber=? AND accountno=?");
179
    $sth->execute( $borrowernumber, $accountno );
180
    my $data = $sth->fetchrow_hashref;
178
    my $data = $sth->fetchrow_hashref;
181
    $sth->finish;
179
    $sth->finish;
182
180
Lines 185-206 sub makepayment { Link Here
185
            $dbh->prepare(
183
            $dbh->prepare(
186
                "UPDATE accountlines
184
                "UPDATE accountlines
187
                    SET amountoutstanding = 0, description = 'Payment,thanks'
185
                    SET amountoutstanding = 0, description = 'Payment,thanks'
188
                    WHERE borrowernumber = ?
186
                    WHERE accountlinesid = ?
189
                    AND accountno = ?
190
                "
187
                "
191
            );
188
            );
192
        $udp->execute($borrowernumber, $accountno );
189
        $udp->execute($accountlinesid);
193
        $udp->finish;
190
        $udp->finish;
194
    }else{
191
    }else{
195
        my $udp = 		
192
        my $udp = 		
196
            $dbh->prepare(
193
            $dbh->prepare(
197
                "UPDATE accountlines
194
                "UPDATE accountlines
198
                    SET amountoutstanding = 0
195
                    SET amountoutstanding = 0
199
                    WHERE borrowernumber = ?
196
                    WHERE accountlinesid = ?
200
                    AND accountno = ?
201
                "
197
                "
202
            );
198
            );
203
        $udp->execute($borrowernumber, $accountno );
199
        $udp->execute($accountlinesid);
204
        $udp->finish;
200
        $udp->finish;
205
201
206
         # create new line
202
         # create new line
Lines 227-232 sub makepayment { Link Here
227
    if ( $data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L' ) {
223
    if ( $data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L' ) {
228
        C4::Circulation::ReturnLostItem( $borrowernumber, $data->{'itemnumber'} );
224
        C4::Circulation::ReturnLostItem( $borrowernumber, $data->{'itemnumber'} );
229
    }
225
    }
226
    my $sthr = $dbh->prepare("SELECT max(accountlinesid) AS lastinsertid FROM accountlines");
227
    $sthr->execute();
228
    my $datalastinsertid = $sthr->fetchrow_hashref;
229
    $sthr->finish;
230
    return $datalastinsertid->{'lastinsertid'};
230
}
231
}
231
232
232
=head2 getnextacctno
233
=head2 getnextacctno
Lines 254-271 sub getnextacctno ($) { Link Here
254
255
255
=head2 fixaccounts (removed)
256
=head2 fixaccounts (removed)
256
257
257
  &fixaccounts($borrowernumber, $accountnumber, $amount);
258
  &fixaccounts($accountlinesid, $borrowernumber, $accountnumber, $amount);
258
259
259
#'
260
#'
260
# FIXME - I don't understand what this function does.
261
# FIXME - I don't understand what this function does.
261
sub fixaccounts {
262
sub fixaccounts {
262
    my ( $borrowernumber, $accountno, $amount ) = @_;
263
    my ( $accountlinesid, $borrowernumber, $accountno, $amount ) = @_;
263
    my $dbh = C4::Context->dbh;
264
    my $dbh = C4::Context->dbh;
264
    my $sth = $dbh->prepare(
265
    my $sth = $dbh->prepare(
265
        "SELECT * FROM accountlines WHERE borrowernumber=?
266
        "SELECT * FROM accountlines WHERE accountlinesid=?"
266
     AND accountno=?"
267
    );
267
    );
268
    $sth->execute( $borrowernumber, $accountno );
268
    $sth->execute( $accountlinesid );
269
    my $data = $sth->fetchrow_hashref;
269
    my $data = $sth->fetchrow_hashref;
270
270
271
    # FIXME - Error-checking
271
    # FIXME - Error-checking
Lines 277-284 sub fixaccounts { Link Here
277
        UPDATE  accountlines
277
        UPDATE  accountlines
278
        SET     amount = '$amount',
278
        SET     amount = '$amount',
279
                amountoutstanding = '$outstanding'
279
                amountoutstanding = '$outstanding'
280
        WHERE   borrowernumber = $borrowernumber
280
        WHERE   accountlinesid = $accountlinesid
281
          AND   accountno = $accountno
282
EOT
281
EOT
283
	# FIXME: exceedingly bad form.  Use prepare with placholders ("?") in query and execute args.
282
	# FIXME: exceedingly bad form.  Use prepare with placholders ("?") in query and execute args.
284
}
283
}
Lines 456-467 sub fixcredit { Link Here
456
            $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
455
            $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
457
            $amountleft = 0;
456
            $amountleft = 0;
458
        }
457
        }
459
        my $thisacct = $accdata->{accountno};
458
        my $thisacct = $accdata->{accountlinesid};
460
        my $usth     = $dbh->prepare(
459
        my $usth     = $dbh->prepare(
461
            "UPDATE accountlines SET amountoutstanding= ?
460
            "UPDATE accountlines SET amountoutstanding= ?
462
     WHERE (borrowernumber = ?) AND (accountno=?)"
461
     WHERE (accountlinesid = ?)"
463
        );
462
        );
464
        $usth->execute( $newamtos, $borrowernumber, $thisacct );
463
        $usth->execute( $newamtos, $thisacct );
465
        $usth->finish;
464
        $usth->finish;
466
        $usth = $dbh->prepare(
465
        $usth = $dbh->prepare(
467
            "INSERT INTO accountoffsets
466
            "INSERT INTO accountoffsets
Lines 495-506 sub fixcredit { Link Here
495
            $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
494
            $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
496
            $amountleft = 0;
495
            $amountleft = 0;
497
        }
496
        }
498
        my $thisacct = $accdata->{accountno};
497
        my $thisacct = $accdata->{accountlinesid};
499
        my $usth     = $dbh->prepare(
498
        my $usth     = $dbh->prepare(
500
            "UPDATE accountlines SET amountoutstanding= ?
499
            "UPDATE accountlines SET amountoutstanding= ?
501
     WHERE (borrowernumber = ?) AND (accountno=?)"
500
     WHERE (accountlinesid = ?)"
502
        );
501
        );
503
        $usth->execute( $newamtos, $borrowernumber, $thisacct );
502
        $usth->execute( $newamtos, $thisacct );
504
        $usth->finish;
503
        $usth->finish;
505
        $usth = $dbh->prepare(
504
        $usth = $dbh->prepare(
506
            "INSERT INTO accountoffsets
505
            "INSERT INTO accountoffsets
Lines 561-572 sub refund { Link Here
561
        }
560
        }
562
561
563
        #     print $amountleft;
562
        #     print $amountleft;
564
        my $thisacct = $accdata->{accountno};
563
        my $thisacct = $accdata->{accountlinesid};
565
        my $usth     = $dbh->prepare(
564
        my $usth     = $dbh->prepare(
566
            "UPDATE accountlines SET amountoutstanding= ?
565
            "UPDATE accountlines SET amountoutstanding= ?
567
     WHERE (borrowernumber = ?) AND (accountno=?)"
566
     WHERE (accountlinesid = ?)"
568
        );
567
        );
569
        $usth->execute( $newamtos, $borrowernumber, $thisacct );
568
        $usth->execute( $newamtos, $thisacct );
570
        $usth->finish;
569
        $usth->finish;
571
        $usth = $dbh->prepare(
570
        $usth = $dbh->prepare(
572
            "INSERT INTO accountoffsets
571
            "INSERT INTO accountoffsets
Lines 599-608 sub getcharges { Link Here
599
}
598
}
600
599
601
sub ModNote {
600
sub ModNote {
602
    my ( $borrowernumber, $accountno, $note ) = @_;
601
    my ( $accountlinesid, $note ) = @_;
603
    my $dbh = C4::Context->dbh;
602
    my $dbh = C4::Context->dbh;
604
    my $sth = $dbh->prepare('UPDATE accountlines SET note = ? WHERE borrowernumber = ? AND accountno = ?');
603
    my $sth = $dbh->prepare('UPDATE accountlines SET note = ? WHERE accountlinesid = ?');
605
    $sth->execute( $note, $borrowernumber, $accountno );
604
    $sth->execute( $note, $accountlinesid );
606
}
605
}
607
606
608
sub getcredits {
607
sub getcredits {
Lines 647-667 sub getrefunds { Link Here
647
}
646
}
648
647
649
sub ReversePayment {
648
sub ReversePayment {
650
  my ( $borrowernumber, $accountno ) = @_;
649
    my ( $accountlinesid ) = @_;
651
  my $dbh = C4::Context->dbh;
650
    my $dbh = C4::Context->dbh;
652
  
651
653
  my $sth = $dbh->prepare('SELECT amountoutstanding FROM accountlines WHERE borrowernumber = ? AND accountno = ?');
652
    my $sth = $dbh->prepare('SELECT amountoutstanding FROM accountlines WHERE accountlinesid = ?');
654
  $sth->execute( $borrowernumber, $accountno );
653
    $sth->execute( $accountlinesid );
655
  my $row = $sth->fetchrow_hashref();
654
    my $row = $sth->fetchrow_hashref();
656
  my $amount_outstanding = $row->{'amountoutstanding'};
655
    my $amount_outstanding = $row->{'amountoutstanding'};
657
  
656
658
  if ( $amount_outstanding <= 0 ) {
657
    if ( $amount_outstanding <= 0 ) {
659
    $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = amount * -1, description = CONCAT( description, " Reversed -" ) WHERE borrowernumber = ? AND accountno = ?');
658
        $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = amount * -1, description = CONCAT( description, " Reversed -" ) WHERE accountlinesid = ?');
660
    $sth->execute( $borrowernumber, $accountno );
659
        $sth->execute( $accountlinesid );
661
  } else {
660
    } else {
662
    $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = 0, description = CONCAT( description, " Reversed -" ) WHERE borrowernumber = ? AND accountno = ?');
661
        $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = 0, description = CONCAT( description, " Reversed -" ) WHERE accountlinesid = ?');
663
    $sth->execute( $borrowernumber, $accountno );
662
        $sth->execute( $accountlinesid );
664
  }
663
    }
665
}
664
}
666
665
667
=head2 recordpayment_selectaccts
666
=head2 recordpayment_selectaccts
Lines 703-709 sub recordpayment_selectaccts { Link Here
703
702
704
    # offset transactions
703
    # offset transactions
705
    my $sth     = $dbh->prepare('UPDATE accountlines SET amountoutstanding= ? ' .
704
    my $sth     = $dbh->prepare('UPDATE accountlines SET amountoutstanding= ? ' .
706
        'WHERE (borrowernumber = ?) AND (accountno=?)');
705
        'WHERE accountlinesid=?');
707
    for my $accdata ( @{$rows} ) {
706
    for my $accdata ( @{$rows} ) {
708
        if ($amountleft == 0) {
707
        if ($amountleft == 0) {
709
            last;
708
            last;
Lines 716-723 sub recordpayment_selectaccts { Link Here
716
            $newamtos   = $accdata->{amountoutstanding} - $amountleft;
715
            $newamtos   = $accdata->{amountoutstanding} - $amountleft;
717
            $amountleft = 0;
716
            $amountleft = 0;
718
        }
717
        }
719
        my $thisacct = $accdata->{accountno};
718
        my $thisacct = $accdata->{accountlinesid};
720
        $sth->execute( $newamtos, $borrowernumber, $thisacct );
719
        $sth->execute( $newamtos, $thisacct );
721
    }
720
    }
722
721
723
    # create new line
722
    # create new line
Lines 732-738 sub recordpayment_selectaccts { Link Here
732
# makepayment needs to be fixed to handle partials till then this separate subroutine
731
# makepayment needs to be fixed to handle partials till then this separate subroutine
733
# fills in
732
# fills in
734
sub makepartialpayment {
733
sub makepartialpayment {
735
    my ( $borrowernumber, $accountno, $amount, $user, $branch ) = @_;
734
    my ( $accountlinesid, $borrowernumber, $accountno, $amount, $user, $branch ) = @_;
736
    my $manager_id = 0;
735
    my $manager_id = 0;
737
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
736
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
738
    if (!$amount || $amount < 0) {
737
    if (!$amount || $amount < 0) {
Lines 744-755 sub makepartialpayment { Link Here
744
    my $newamtos    = 0;
743
    my $newamtos    = 0;
745
744
746
    my $data = $dbh->selectrow_hashref(
745
    my $data = $dbh->selectrow_hashref(
747
        'SELECT * FROM accountlines WHERE  borrowernumber=? AND accountno=?',undef,$borrowernumber,$accountno);
746
        'SELECT * FROM accountlines WHERE  accountlinesid=?',undef,$accountlinesid);
748
    my $new_outstanding = $data->{amountoutstanding} - $amount;
747
    my $new_outstanding = $data->{amountoutstanding} - $amount;
749
748
750
    my $update = 'UPDATE  accountlines SET amountoutstanding = ?  WHERE   borrowernumber = ? '
749
    my $update = 'UPDATE  accountlines SET amountoutstanding = ?  WHERE   accountlinesid = ? ';
751
    . ' AND   accountno = ?';
750
    $dbh->do( $update, undef, $new_outstanding, $accountlinesid);
752
    $dbh->do( $update, undef, $new_outstanding, $borrowernumber, $accountno);
753
751
754
    # create new line
752
    # create new line
755
    my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, '
753
    my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, '
(-)a/C4/Circulation.pm (-9 / +7 lines)
Lines 1894-1900 sub _FixOverduesOnReturn { Link Here
1894
    return 0 unless $data;    # no warning, there's just nothing to fix
1894
    return 0 unless $data;    # no warning, there's just nothing to fix
1895
1895
1896
    my $uquery;
1896
    my $uquery;
1897
    my @bind = ($borrowernumber, $item, $data->{'accountno'});
1897
    my @bind = ($data->{'accountlinesid'});
1898
    if ($exemptfine) {
1898
    if ($exemptfine) {
1899
        $uquery = "update accountlines set accounttype='FFOR', amountoutstanding=0";
1899
        $uquery = "update accountlines set accounttype='FFOR', amountoutstanding=0";
1900
        if (C4::Context->preference("FinesLog")) {
1900
        if (C4::Context->preference("FinesLog")) {
Lines 1914-1920 sub _FixOverduesOnReturn { Link Here
1914
    } else {
1914
    } else {
1915
        $uquery = "update accountlines set accounttype='F' ";
1915
        $uquery = "update accountlines set accounttype='F' ";
1916
    }
1916
    }
1917
    $uquery .= " where (borrowernumber = ?) and (itemnumber = ?) and (accountno = ?)";
1917
    $uquery .= " where (accountlinesid = ?)";
1918
    my $usth = $dbh->prepare($uquery);
1918
    my $usth = $dbh->prepare($uquery);
1919
    return $usth->execute(@bind);
1919
    return $usth->execute(@bind);
1920
}
1920
}
Lines 1957-1965 sub _FixAccountForLostAndReturned { Link Here
1957
        $amountleft = $data->{'amountoutstanding'} - $amount;   # Um, isn't this the same as ZERO?  We just tested those two things are ==
1957
        $amountleft = $data->{'amountoutstanding'} - $amount;   # Um, isn't this the same as ZERO?  We just tested those two things are ==
1958
    }
1958
    }
1959
    my $usth = $dbh->prepare("UPDATE accountlines SET accounttype = 'LR',amountoutstanding='0'
1959
    my $usth = $dbh->prepare("UPDATE accountlines SET accounttype = 'LR',amountoutstanding='0'
1960
        WHERE (borrowernumber = ?)
1960
        WHERE (accountlinesid = ?)");
1961
        AND (itemnumber = ?) AND (accountno = ?) ");
1961
    $usth->execute($data->{'accountlinesid'});      # We might be adjusting an account for some OTHER borrowernumber now.  Not the one we passed in.  
1962
    $usth->execute($data->{'borrowernumber'},$itemnumber,$acctno);      # We might be adjusting an account for some OTHER borrowernumber now.  Not the one we passed in.  
1963
    #check if any credit is left if so writeoff other accounts
1962
    #check if any credit is left if so writeoff other accounts
1964
    my $nextaccntno = getnextacctno($data->{'borrowernumber'});
1963
    my $nextaccntno = getnextacctno($data->{'borrowernumber'});
1965
    $amountleft *= -1 if ($amountleft < 0);
1964
    $amountleft *= -1 if ($amountleft < 0);
Lines 1978-1989 sub _FixAccountForLostAndReturned { Link Here
1978
                $newamtos = $accdata->{'amountoutstanding'} - $amountleft;
1977
                $newamtos = $accdata->{'amountoutstanding'} - $amountleft;
1979
                $amountleft = 0;
1978
                $amountleft = 0;
1980
            }
1979
            }
1981
            my $thisacct = $accdata->{'accountno'};
1980
            my $thisacct = $accdata->{'accountlinesid'};
1982
            # FIXME: move prepares outside while loop!
1981
            # FIXME: move prepares outside while loop!
1983
            my $usth = $dbh->prepare("UPDATE accountlines SET amountoutstanding= ?
1982
            my $usth = $dbh->prepare("UPDATE accountlines SET amountoutstanding= ?
1984
                    WHERE (borrowernumber = ?)
1983
                    WHERE (accountlinesid = ?)");
1985
                    AND (accountno=?)");
1984
            $usth->execute($newamtos,'$thisacct');    # FIXME: '$thisacct' is a string literal!
1986
            $usth->execute($newamtos,$data->{'borrowernumber'},'$thisacct');    # FIXME: '$thisacct' is a string literal!
1987
            $usth = $dbh->prepare("INSERT INTO accountoffsets
1985
            $usth = $dbh->prepare("INSERT INTO accountoffsets
1988
                (borrowernumber, accountno, offsetaccount,  offsetamount)
1986
                (borrowernumber, accountno, offsetaccount,  offsetamount)
1989
                VALUES
1987
                VALUES
(-)a/installer/data/mysql/kohastructure.sql (+2 lines)
Lines 2457-2462 CREATE TABLE `messages` ( -- circulation messages left via the patron's check ou Link Here
2457
2457
2458
DROP TABLE IF EXISTS `accountlines`;
2458
DROP TABLE IF EXISTS `accountlines`;
2459
CREATE TABLE `accountlines` (
2459
CREATE TABLE `accountlines` (
2460
  `accountlinesid` int(11) NOT NULL AUTO_INCREMENT,
2460
  `borrowernumber` int(11) NOT NULL default 0,
2461
  `borrowernumber` int(11) NOT NULL default 0,
2461
  `accountno` smallint(6) NOT NULL default 0,
2462
  `accountno` smallint(6) NOT NULL default 0,
2462
  `itemnumber` int(11) default NULL,
2463
  `itemnumber` int(11) default NULL,
Lines 2472-2477 CREATE TABLE `accountlines` ( Link Here
2472
  `notify_level` int(2) NOT NULL default 0,
2473
  `notify_level` int(2) NOT NULL default 0,
2473
  `note` text NULL default NULL,
2474
  `note` text NULL default NULL,
2474
  `manager_id` int(11) NULL,
2475
  `manager_id` int(11) NULL,
2476
  PRIMARY KEY (`accountlinesid`),
2475
  KEY `acctsborridx` (`borrowernumber`),
2477
  KEY `acctsborridx` (`borrowernumber`),
2476
  KEY `timeidx` (`timestamp`),
2478
  KEY `timeidx` (`timestamp`),
2477
  KEY `itemnumber` (`itemnumber`),
2479
  KEY `itemnumber` (`itemnumber`),
(-)a/installer/data/mysql/updatedatabase.pl (+7 lines)
Lines 5308-5313 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
5308
    SetVersion ($DBversion);
5308
    SetVersion ($DBversion);
5309
}
5309
}
5310
5310
5311
$DBversion = "XXX";
5312
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
5313
    $dbh->do("ALTER TABLE `accountlines` ADD `accountlinesid` INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;");
5314
    print "Upgrade to $DBversion done (adding accountlinesid field in accountlines table)\n";
5315
    SetVersion($DBversion);
5316
}
5317
5311
=head1 FUNCTIONS
5318
=head1 FUNCTIONS
5312
5319
5313
=head2 TableExists($table)
5320
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt (-3 / +3 lines)
Lines 51-57 Link Here
51
    [% IF ( reverse_col ) %]
51
    [% IF ( reverse_col ) %]
52
      <td>
52
      <td>
53
	[% IF ( account.payment ) %]
53
	[% IF ( account.payment ) %]
54
		<a href="boraccount.pl?action=reverse&amp;borrowernumber=[% account.borrowernumber %]&amp;accountno=[% account.accountno %]">Reverse</a>
54
		<a href="boraccount.pl?action=reverse&amp;accountlinesid=[% account.accountlinesid %]&amp;borrowernumber=[% account.borrowernumber %]">Reverse</a>
55
	[% ELSE %]
55
	[% ELSE %]
56
		&nbsp;
56
		&nbsp;
57
	[% END %]
57
	[% END %]
Lines 59-67 Link Here
59
	[% END %]
59
	[% END %]
60
<td>
60
<td>
61
	[% IF ( account.payment ) %]
61
	[% IF ( account.payment ) %]
62
		<a target="_blank" href="printfeercpt.pl?action=print&amp;borrowernumber=[% account.borrowernumber %]&amp;accountno=[% account.accountno %]">Print</a>
62
		<a target="_blank" href="printfeercpt.pl?action=print&amp;accountlinesid=[% account.accountlinesid %]&amp;borrowernumber=[% account.borrowernumber %]">Print</a>
63
	[% ELSE %]
63
	[% ELSE %]
64
		<a target="_blank" href="printinvoice.pl?action=print&amp;borrowernumber=[% account.borrowernumber %]&amp;accountno=[% account.accountno %]">Print</a>
64
		<a target="_blank" href="printinvoice.pl?action=print&amp;accountlinesid=[% account.accountlinesid %]&amp;borrowernumber=[% account.borrowernumber %]">Print</a>
65
	[% END %]
65
	[% END %]
66
      </td>
66
      </td>
67
    </tr>
67
    </tr>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tt (+1 lines)
Lines 73-78 Link Here
73
    <input type="hidden" name="description[% line.accountno %]" value="[% line.description %]" />
73
    <input type="hidden" name="description[% line.accountno %]" value="[% line.description %]" />
74
    <input type="hidden" name="accounttype[% line.accountno %]" value="[% line.accounttype %]" />
74
    <input type="hidden" name="accounttype[% line.accountno %]" value="[% line.accounttype %]" />
75
    <input type="hidden" name="amount[% line.accountno %]" value="[% line.amount %]" />
75
    <input type="hidden" name="amount[% line.accountno %]" value="[% line.amount %]" />
76
    <input type="hidden" name="accountlinesid[% line.accountno %]" value="[% line.accountlinesid %]" />
76
    <input type="hidden" name="amountoutstanding[% line.accountno %]" value="[% line.amountoutstanding %]" />
77
    <input type="hidden" name="amountoutstanding[% line.accountno %]" value="[% line.amountoutstanding %]" />
77
    <input type="hidden" name="borrowernumber[% line.accountno %]" value="[% line.borrowernumber %]" />
78
    <input type="hidden" name="borrowernumber[% line.accountno %]" value="[% line.borrowernumber %]" />
78
    <input type="hidden" name="accountno[% line.accountno %]" value="[% line.accountno %]" />
79
    <input type="hidden" name="accountno[% line.accountno %]" value="[% line.accountno %]" />
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt (+2 lines)
Lines 102-107 function moneyFormat(textObj) { Link Here
102
    <input type="hidden" name="amount" id="amount" value="[% amount %]" />
102
    <input type="hidden" name="amount" id="amount" value="[% amount %]" />
103
    <input type="hidden" name="amountoutstanding" id="amountoutstanding" value="[% amountoutstanding %]" />
103
    <input type="hidden" name="amountoutstanding" id="amountoutstanding" value="[% amountoutstanding %]" />
104
    <input type="hidden" name="accountno" id="accountno" value="[% accountno %]" />
104
    <input type="hidden" name="accountno" id="accountno" value="[% accountno %]" />
105
    <input type="hidden" name="accountlinesid" id="accountlinesid" value="[% accountlinesid %]" />
105
    <input type="hidden" name="title" id="title" value="[% title %]" />
106
    <input type="hidden" name="title" id="title" value="[% title %]" />
106
107
107
<fieldset class="rows">
108
<fieldset class="rows">
Lines 157-162 function moneyFormat(textObj) { Link Here
157
    <input type="hidden" name="amount" id="amount" value="[% amount %]" />
158
    <input type="hidden" name="amount" id="amount" value="[% amount %]" />
158
    <input type="hidden" name="amountoutstanding" id="amountoutstanding" value="[% amountoutstanding %]" />
159
    <input type="hidden" name="amountoutstanding" id="amountoutstanding" value="[% amountoutstanding %]" />
159
    <input type="hidden" name="accountno" id="accountno" value="[% accountno %]" />
160
    <input type="hidden" name="accountno" id="accountno" value="[% accountno %]" />
161
    <input type="hidden" name="accountlinesid" id="accountlinesid" value="[% accountlinesid %]" />
160
    <input type="hidden" name="title" id="title" value="[% title %]" />
162
    <input type="hidden" name="title" id="title" value="[% title %]" />
161
    <table>
163
    <table>
162
    <thead><tr>
164
    <thead><tr>
(-)a/members/boraccount.pl (-1 / +1 lines)
Lines 53-59 my $action = $input->param('action') || ''; Link Here
53
my $data=GetMember('borrowernumber' => $borrowernumber);
53
my $data=GetMember('borrowernumber' => $borrowernumber);
54
54
55
if ( $action eq 'reverse' ) {
55
if ( $action eq 'reverse' ) {
56
  ReversePayment( $borrowernumber, $input->param('accountno') );
56
  ReversePayment( $input->param('accountlinesid') );
57
}
57
}
58
58
59
if ( $data->{'category_type'} eq 'C') {
59
if ( $data->{'category_type'} eq 'C') {
(-)a/members/pay.pl (-3 / +42 lines)
Lines 83-93 my $writeoff_all = $input->param('woall'); # writeoff all fines Link Here
83
if ($writeoff_all) {
83
if ($writeoff_all) {
84
    writeoff_all(@names);
84
    writeoff_all(@names);
85
} elsif ($writeoff_item) {
85
} elsif ($writeoff_item) {
86
    my $accountno    = $input->param('accountno');
86
    my $accountlinesid = $input->param('accountlinesid');
87
    my $itemno       = $input->param('itemnumber');
87
    my $itemno       = $input->param('itemnumber');
88
    my $account_type = $input->param('accounttype');
88
    my $account_type = $input->param('accounttype');
89
    my $amount       = $input->param('amountoutstanding');
89
    my $amount       = $input->param('amountoutstanding');
90
    WriteOffFee( $borrowernumber, $accountno, $itemno, $account_type, $amount, $branch );
90
    WriteOffFee( $borrowernumber, $accountlinesid, $itemno, $account_type, $amount, $branch );
91
}
91
}
92
92
93
for (@names) {
93
for (@names) {
Lines 106-111 add_accounts_to_template(); Link Here
106
106
107
output_html_with_http_headers $input, $cookie, $template->output;
107
output_html_with_http_headers $input, $cookie, $template->output;
108
108
109
sub writeoff {
110
    my ( $accountlinesid, $itemnum, $accounttype, $amount ) = @_;
111
    my $manager_id = 0;
112
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
113
114
    # if no item is attached to fine, make sure to store it as a NULL
115
    $itemnum ||= undef;
116
    get_writeoff_sth();
117
    $writeoff_sth->execute( $accountlinesid );
118
119
    my $acct = getnextacctno($borrowernumber);
120
    $add_writeoff_sth->execute( $borrowernumber, $acct, $itemnum, $amount, $manager_id );
121
122
    UpdateStats( $branch, 'writeoff', $amount, q{}, q{}, q{}, $borrowernumber );
123
124
    return;
125
}
109
126
110
sub add_accounts_to_template {
127
sub add_accounts_to_template {
111
128
Lines 167-172 sub redirect_to_paycollect { Link Here
167
    $redirect .= get_for_redirect( 'itemnumber',   "itemnumber$line_no",   0 );
184
    $redirect .= get_for_redirect( 'itemnumber',   "itemnumber$line_no",   0 );
168
    $redirect .= get_for_redirect( 'notify_id',    "notify_id$line_no",    0 );
185
    $redirect .= get_for_redirect( 'notify_id',    "notify_id$line_no",    0 );
169
    $redirect .= get_for_redirect( 'notify_level', "notify_level$line_no", 0 );
186
    $redirect .= get_for_redirect( 'notify_level', "notify_level$line_no", 0 );
187
    $redirect .= get_for_redirect( 'accountlinesid', "accountlinesid$line_no", 0 );
170
    $redirect .= '&remote_user=';
188
    $redirect .= '&remote_user=';
171
    $redirect .= $user;
189
    $redirect .= $user;
172
    return print $input->redirect($redirect);
190
    return print $input->redirect($redirect);
Lines 184-190 sub writeoff_all { Link Here
184
            my $itemno    = $input->param("itemnumber$value");
202
            my $itemno    = $input->param("itemnumber$value");
185
            my $amount    = $input->param("amountoutstanding$value");
203
            my $amount    = $input->param("amountoutstanding$value");
186
            my $accountno = $input->param("accountno$value");
204
            my $accountno = $input->param("accountno$value");
187
            WriteOffFee( $borrowernumber, $accountno, $itemno, $accounttype, $amount, $branch );
205
            my $accountlinesid = $input->param("accountlinesid$value");
206
            WriteOffFee( $borrowernumber, $accountlinesid, $itemno, $accounttype, $amount, $branch );
188
        }
207
        }
189
    }
208
    }
190
209
Lines 250-252 sub payselected { Link Here
250
    print $input->redirect($redirect);
269
    print $input->redirect($redirect);
251
    return;
270
    return;
252
}
271
}
272
273
sub get_writeoff_sth {
274
275
    # lets prepare these statement handles only once
276
    if ($writeoff_sth) {
277
        return;
278
    } else {
279
        my $dbh = C4::Context->dbh;
280
281
        # Do we need to validate accounttype
282
        my $sql = 'Update accountlines set amountoutstanding=0 '
283
          . 'WHERE accountlinesid=?';
284
        $writeoff_sth = $dbh->prepare($sql);
285
        my $insert =
286
q{insert into accountlines (borrowernumber,accountno,itemnumber,date,amount,description,accounttype,manager_id)}
287
          . q{values (?,?,?,now(),?,'Writeoff','W',?)};
288
        $add_writeoff_sth = $dbh->prepare($insert);
289
    }
290
    return;
291
}
(-)a/members/paycollect.pl (-3 / +5 lines)
Lines 56-62 my $writeoff = $input->param('writeoff_individual'); Link Here
56
my $select_lines = $input->param('selected');
56
my $select_lines = $input->param('selected');
57
my $select       = $input->param('selected_accts');
57
my $select       = $input->param('selected_accts');
58
my $accountno;
58
my $accountno;
59
59
my $accountlinesid;
60
if ( $individual || $writeoff ) {
60
if ( $individual || $writeoff ) {
61
    if ($individual) {
61
    if ($individual) {
62
        $template->param( pay_individual => 1 );
62
        $template->param( pay_individual => 1 );
Lines 64-69 if ( $individual || $writeoff ) { Link Here
64
        $template->param( writeoff_individual => 1 );
64
        $template->param( writeoff_individual => 1 );
65
    }
65
    }
66
    my $accounttype       = $input->param('accounttype');
66
    my $accounttype       = $input->param('accounttype');
67
    $accountlinesid       = $input->param('accountlinesid');
67
    my $amount            = $input->param('amount');
68
    my $amount            = $input->param('amount');
68
    my $amountoutstanding = $input->param('amountoutstanding');
69
    my $amountoutstanding = $input->param('amountoutstanding');
69
    $accountno = $input->param('accountno');
70
    $accountno = $input->param('accountno');
Lines 75-80 if ( $individual || $writeoff ) { Link Here
75
    $total_due = $amountoutstanding;
76
    $total_due = $amountoutstanding;
76
    $template->param(
77
    $template->param(
77
        accounttype       => $accounttype,
78
        accounttype       => $accounttype,
79
        accountlinesid    => $accountlinesid,
78
        accountno         => $accountno,
80
        accountno         => $accountno,
79
        amount            => $amount,
81
        amount            => $amount,
80
        amountoutstanding => $amountoutstanding,
82
        amountoutstanding => $amountoutstanding,
Lines 101-110 if ( $total_paid and $total_paid ne '0.00' ) { Link Here
101
    } else {
103
    } else {
102
        if ($individual) {
104
        if ($individual) {
103
            if ( $total_paid == $total_due ) {
105
            if ( $total_paid == $total_due ) {
104
                makepayment( $borrowernumber, $accountno, $total_paid, $user,
106
                makepayment( $accountlinesid, $borrowernumber, $accountno, $total_paid, $user,
105
                    $branch );
107
                    $branch );
106
            } else {
108
            } else {
107
                makepartialpayment( $borrowernumber, $accountno, $total_paid,
109
                makepartialpayment( $accountlinesid, $borrowernumber, $accountno, $total_paid,
108
                    $user, $branch );
110
                    $user, $branch );
109
            }
111
            }
110
            print $input->redirect(
112
            print $input->redirect(
(-)a/members/printinvoice.pl (-1 / +1 lines)
Lines 48-53 my ($template, $loggedinuser, $cookie) Link Here
48
my $borrowernumber=$input->param('borrowernumber');
48
my $borrowernumber=$input->param('borrowernumber');
49
my $action = $input->param('action') || '';
49
my $action = $input->param('action') || '';
50
my $accountno = $input->param('accountno');
50
my $accountno = $input->param('accountno');
51
my $accountlinesid = $input->param('accountlinesid');
51
52
52
#get borrower details
53
#get borrower details
53
my $data=GetMember('borrowernumber' => $borrowernumber);
54
my $data=GetMember('borrowernumber' => $borrowernumber);
54
- 

Return to bug 7671