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 115-126 sub recordpayment { Link Here
115
            $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
115
            $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
116
            $amountleft = 0;
116
            $amountleft = 0;
117
        }
117
        }
118
        my $thisacct = $accdata->{accountno};
118
        my $thisacct = $accdata->{accountlinesid};
119
        my $usth     = $dbh->prepare(
119
        my $usth     = $dbh->prepare(
120
            "UPDATE accountlines SET amountoutstanding= ?
120
            "UPDATE accountlines SET amountoutstanding= ?
121
     WHERE (borrowernumber = ?) AND (accountno=?)"
121
     WHERE (accountlinesid = ?)"
122
        );
122
        );
123
        $usth->execute( $newamtos, $borrowernumber, $thisacct );
123
        $usth->execute( $newamtos, $thisacct );
124
        $usth->finish;
124
        $usth->finish;
125
#        $usth = $dbh->prepare(
125
#        $usth = $dbh->prepare(
126
#            "INSERT INTO accountoffsets
126
#            "INSERT INTO accountoffsets
Lines 146-152 sub recordpayment { Link Here
146
146
147
=head2 makepayment
147
=head2 makepayment
148
148
149
  &makepayment($borrowernumber, $acctnumber, $amount, $branchcode);
149
  &makepayment($accountlinesid, $borrowernumber, $acctnumber, $amount, $branchcode);
150
150
151
Records the fact that a patron has paid off the entire amount he or
151
Records the fact that a patron has paid off the entire amount he or
152
she owes.
152
she owes.
Lines 167-173 sub makepayment { Link Here
167
    #here we update both the accountoffsets and the account lines
167
    #here we update both the accountoffsets and the account lines
168
    #updated to check, if they are paying off a lost item, we return the item
168
    #updated to check, if they are paying off a lost item, we return the item
169
    # from their card, and put a note on the item record
169
    # from their card, and put a note on the item record
170
    my ( $borrowernumber, $accountno, $amount, $user, $branch ) = @_;
170
    my ( $accountlinesid, $borrowernumber, $accountno, $amount, $user, $branch ) = @_;
171
    my $dbh = C4::Context->dbh;
171
    my $dbh = C4::Context->dbh;
172
    my $manager_id = 0;
172
    my $manager_id = 0;
173
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; 
173
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; 
Lines 175-184 sub makepayment { Link Here
175
    # begin transaction
175
    # begin transaction
176
    my $nextaccntno = getnextacctno($borrowernumber);
176
    my $nextaccntno = getnextacctno($borrowernumber);
177
    my $newamtos    = 0;
177
    my $newamtos    = 0;
178
    my $sth =
178
    my $sth         = $dbh->prepare("SELECT * FROM accountlines WHERE accountlinesid=?");
179
      $dbh->prepare(
179
    $sth->execute( $accountlinesid );
180
        "SELECT * FROM accountlines WHERE  borrowernumber=? AND accountno=?");
181
    $sth->execute( $borrowernumber, $accountno );
182
    my $data = $sth->fetchrow_hashref;
180
    my $data = $sth->fetchrow_hashref;
183
    $sth->finish;
181
    $sth->finish;
184
182
Lines 187-208 sub makepayment { Link Here
187
            $dbh->prepare(
185
            $dbh->prepare(
188
                "UPDATE accountlines
186
                "UPDATE accountlines
189
                    SET amountoutstanding = 0, description = 'Payment,thanks'
187
                    SET amountoutstanding = 0, description = 'Payment,thanks'
190
                    WHERE borrowernumber = ?
188
                    WHERE accountlinesid = ?
191
                    AND accountno = ?
192
                "
189
                "
193
            );
190
            );
194
        $udp->execute($borrowernumber, $accountno );
191
        $udp->execute($accountlinesid);
195
        $udp->finish;
192
        $udp->finish;
196
    }else{
193
    }else{
197
        my $udp = 		
194
        my $udp = 		
198
            $dbh->prepare(
195
            $dbh->prepare(
199
                "UPDATE accountlines
196
                "UPDATE accountlines
200
                    SET amountoutstanding = 0
197
                    SET amountoutstanding = 0
201
                    WHERE borrowernumber = ?
198
                    WHERE accountlinesid = ?
202
                    AND accountno = ?
203
                "
199
                "
204
            );
200
            );
205
        $udp->execute($borrowernumber, $accountno );
201
        $udp->execute($accountlinesid);
206
        $udp->finish;
202
        $udp->finish;
207
203
208
         # create new line
204
         # create new line
Lines 229-234 sub makepayment { Link Here
229
    if ( $data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L' ) {
225
    if ( $data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L' ) {
230
        C4::Circulation::ReturnLostItem( $borrowernumber, $data->{'itemnumber'} );
226
        C4::Circulation::ReturnLostItem( $borrowernumber, $data->{'itemnumber'} );
231
    }
227
    }
228
    my $sthr = $dbh->prepare("SELECT max(accountlinesid) AS lastinsertid FROM accountlines");
229
    $sthr->execute();
230
    my $datalastinsertid = $sthr->fetchrow_hashref;
231
    $sthr->finish;
232
    return $datalastinsertid->{'lastinsertid'};
232
}
233
}
233
234
234
=head2 getnextacctno
235
=head2 getnextacctno
Lines 256-273 sub getnextacctno ($) { Link Here
256
257
257
=head2 fixaccounts (removed)
258
=head2 fixaccounts (removed)
258
259
259
  &fixaccounts($borrowernumber, $accountnumber, $amount);
260
  &fixaccounts($accountlinesid, $borrowernumber, $accountnumber, $amount);
260
261
261
#'
262
#'
262
# FIXME - I don't understand what this function does.
263
# FIXME - I don't understand what this function does.
263
sub fixaccounts {
264
sub fixaccounts {
264
    my ( $borrowernumber, $accountno, $amount ) = @_;
265
    my ( $accountlinesid, $borrowernumber, $accountno, $amount ) = @_;
265
    my $dbh = C4::Context->dbh;
266
    my $dbh = C4::Context->dbh;
266
    my $sth = $dbh->prepare(
267
    my $sth = $dbh->prepare(
267
        "SELECT * FROM accountlines WHERE borrowernumber=?
268
        "SELECT * FROM accountlines WHERE accountlinesid=?"
268
     AND accountno=?"
269
    );
269
    );
270
    $sth->execute( $borrowernumber, $accountno );
270
    $sth->execute( $accountlinesid );
271
    my $data = $sth->fetchrow_hashref;
271
    my $data = $sth->fetchrow_hashref;
272
272
273
    # FIXME - Error-checking
273
    # FIXME - Error-checking
Lines 279-286 sub fixaccounts { Link Here
279
        UPDATE  accountlines
279
        UPDATE  accountlines
280
        SET     amount = '$amount',
280
        SET     amount = '$amount',
281
                amountoutstanding = '$outstanding'
281
                amountoutstanding = '$outstanding'
282
        WHERE   borrowernumber = $borrowernumber
282
        WHERE   accountlinesid = $accountlinesid
283
          AND   accountno = $accountno
284
EOT
283
EOT
285
	# FIXME: exceedingly bad form.  Use prepare with placholders ("?") in query and execute args.
284
	# FIXME: exceedingly bad form.  Use prepare with placholders ("?") in query and execute args.
286
}
285
}
Lines 460-471 sub fixcredit { Link Here
460
            $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
459
            $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
461
            $amountleft = 0;
460
            $amountleft = 0;
462
        }
461
        }
463
        my $thisacct = $accdata->{accountno};
462
        my $thisacct = $accdata->{accountlinesid};
464
        my $usth     = $dbh->prepare(
463
        my $usth     = $dbh->prepare(
465
            "UPDATE accountlines SET amountoutstanding= ?
464
            "UPDATE accountlines SET amountoutstanding= ?
466
     WHERE (borrowernumber = ?) AND (accountno=?)"
465
     WHERE (accountlinesid = ?)"
467
        );
466
        );
468
        $usth->execute( $newamtos, $borrowernumber, $thisacct );
467
        $usth->execute( $newamtos, $thisacct );
469
        $usth->finish;
468
        $usth->finish;
470
        $usth = $dbh->prepare(
469
        $usth = $dbh->prepare(
471
            "INSERT INTO accountoffsets
470
            "INSERT INTO accountoffsets
Lines 499-510 sub fixcredit { Link Here
499
            $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
498
            $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
500
            $amountleft = 0;
499
            $amountleft = 0;
501
        }
500
        }
502
        my $thisacct = $accdata->{accountno};
501
        my $thisacct = $accdata->{accountlinesid};
503
        my $usth     = $dbh->prepare(
502
        my $usth     = $dbh->prepare(
504
            "UPDATE accountlines SET amountoutstanding= ?
503
            "UPDATE accountlines SET amountoutstanding= ?
505
     WHERE (borrowernumber = ?) AND (accountno=?)"
504
     WHERE (accountlinesid = ?)"
506
        );
505
        );
507
        $usth->execute( $newamtos, $borrowernumber, $thisacct );
506
        $usth->execute( $newamtos, $thisacct );
508
        $usth->finish;
507
        $usth->finish;
509
        $usth = $dbh->prepare(
508
        $usth = $dbh->prepare(
510
            "INSERT INTO accountoffsets
509
            "INSERT INTO accountoffsets
Lines 565-576 sub refund { Link Here
565
        }
564
        }
566
565
567
        #     print $amountleft;
566
        #     print $amountleft;
568
        my $thisacct = $accdata->{accountno};
567
        my $thisacct = $accdata->{accountlinesid};
569
        my $usth     = $dbh->prepare(
568
        my $usth     = $dbh->prepare(
570
            "UPDATE accountlines SET amountoutstanding= ?
569
            "UPDATE accountlines SET amountoutstanding= ?
571
     WHERE (borrowernumber = ?) AND (accountno=?)"
570
     WHERE (accountlinesid = ?)"
572
        );
571
        );
573
        $usth->execute( $newamtos, $borrowernumber, $thisacct );
572
        $usth->execute( $newamtos, $thisacct );
574
        $usth->finish;
573
        $usth->finish;
575
        $usth = $dbh->prepare(
574
        $usth = $dbh->prepare(
576
            "INSERT INTO accountoffsets
575
            "INSERT INTO accountoffsets
Lines 603-612 sub getcharges { Link Here
603
}
602
}
604
603
605
sub ModNote {
604
sub ModNote {
606
    my ( $borrowernumber, $accountno, $note ) = @_;
605
    my ( $accountlinesid, $note ) = @_;
607
    my $dbh = C4::Context->dbh;
606
    my $dbh = C4::Context->dbh;
608
    my $sth = $dbh->prepare('UPDATE accountlines SET note = ? WHERE borrowernumber = ? AND accountno = ?');
607
    my $sth = $dbh->prepare('UPDATE accountlines SET note = ? WHERE accountlinesid = ?');
609
    $sth->execute( $note, $borrowernumber, $accountno );
608
    $sth->execute( $note, $accountlinesid );
610
}
609
}
611
610
612
sub getcredits {
611
sub getcredits {
Lines 651-671 sub getrefunds { Link Here
651
}
650
}
652
651
653
sub ReversePayment {
652
sub ReversePayment {
654
  my ( $borrowernumber, $accountno ) = @_;
653
    my ( $accountlinesid ) = @_;
655
  my $dbh = C4::Context->dbh;
654
    my $dbh = C4::Context->dbh;
656
  
655
657
  my $sth = $dbh->prepare('SELECT amountoutstanding FROM accountlines WHERE borrowernumber = ? AND accountno = ?');
656
    my $sth = $dbh->prepare('SELECT amountoutstanding FROM accountlines WHERE accountlinesid = ?');
658
  $sth->execute( $borrowernumber, $accountno );
657
    $sth->execute( $accountlinesid );
659
  my $row = $sth->fetchrow_hashref();
658
    my $row = $sth->fetchrow_hashref();
660
  my $amount_outstanding = $row->{'amountoutstanding'};
659
    my $amount_outstanding = $row->{'amountoutstanding'};
661
  
660
662
  if ( $amount_outstanding <= 0 ) {
661
    if ( $amount_outstanding <= 0 ) {
663
    $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = amount * -1, description = CONCAT( description, " Reversed -" ) WHERE borrowernumber = ? AND accountno = ?');
662
        $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = amount * -1, description = CONCAT( description, " Reversed -" ) WHERE accountlinesid = ?');
664
    $sth->execute( $borrowernumber, $accountno );
663
        $sth->execute( $accountlinesid );
665
  } else {
664
    } else {
666
    $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = 0, description = CONCAT( description, " Reversed -" ) WHERE borrowernumber = ? AND accountno = ?');
665
        $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = 0, description = CONCAT( description, " Reversed -" ) WHERE accountlinesid = ?');
667
    $sth->execute( $borrowernumber, $accountno );
666
        $sth->execute( $accountlinesid );
668
  }
667
    }
669
}
668
}
670
669
671
=head2 recordpayment_selectaccts
670
=head2 recordpayment_selectaccts
Lines 709-715 sub recordpayment_selectaccts { Link Here
709
708
710
    # offset transactions
709
    # offset transactions
711
    my $sth     = $dbh->prepare('UPDATE accountlines SET amountoutstanding= ? ' .
710
    my $sth     = $dbh->prepare('UPDATE accountlines SET amountoutstanding= ? ' .
712
        'WHERE (borrowernumber = ?) AND (accountno=?)');
711
        'WHERE accountlinesid=?');
713
    for my $accdata ( @{$rows} ) {
712
    for my $accdata ( @{$rows} ) {
714
        if ($amountleft == 0) {
713
        if ($amountleft == 0) {
715
            last;
714
            last;
Lines 722-729 sub recordpayment_selectaccts { Link Here
722
            $newamtos   = $accdata->{amountoutstanding} - $amountleft;
721
            $newamtos   = $accdata->{amountoutstanding} - $amountleft;
723
            $amountleft = 0;
722
            $amountleft = 0;
724
        }
723
        }
725
        my $thisacct = $accdata->{accountno};
724
        my $thisacct = $accdata->{accountlinesid};
726
        $sth->execute( $newamtos, $borrowernumber, $thisacct );
725
        $sth->execute( $newamtos, $thisacct );
727
    }
726
    }
728
727
729
    # create new line
728
    # create new line
Lines 738-744 sub recordpayment_selectaccts { Link Here
738
# makepayment needs to be fixed to handle partials till then this separate subroutine
737
# makepayment needs to be fixed to handle partials till then this separate subroutine
739
# fills in
738
# fills in
740
sub makepartialpayment {
739
sub makepartialpayment {
741
    my ( $borrowernumber, $accountno, $amount, $user, $branch ) = @_;
740
    my ( $accountlinesid, $borrowernumber, $accountno, $amount, $user, $branch ) = @_;
742
    my $manager_id = 0;
741
    my $manager_id = 0;
743
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
742
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
744
    if (!$amount || $amount < 0) {
743
    if (!$amount || $amount < 0) {
Lines 750-761 sub makepartialpayment { Link Here
750
    my $newamtos    = 0;
749
    my $newamtos    = 0;
751
750
752
    my $data = $dbh->selectrow_hashref(
751
    my $data = $dbh->selectrow_hashref(
753
        'SELECT * FROM accountlines WHERE  borrowernumber=? AND accountno=?',undef,$borrowernumber,$accountno);
752
        'SELECT * FROM accountlines WHERE  accountlinesid=?',undef,$accountlinesid);
754
    my $new_outstanding = $data->{amountoutstanding} - $amount;
753
    my $new_outstanding = $data->{amountoutstanding} - $amount;
755
754
756
    my $update = 'UPDATE  accountlines SET amountoutstanding = ?  WHERE   borrowernumber = ? '
755
    my $update = 'UPDATE  accountlines SET amountoutstanding = ?  WHERE   accountlinesid = ? ';
757
    . ' AND   accountno = ?';
756
    $dbh->do( $update, undef, $new_outstanding, $accountlinesid);
758
    $dbh->do( $update, undef, $new_outstanding, $borrowernumber, $accountno);
759
757
760
    # create new line
758
    # create new line
761
    my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, '
759
    my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, '
(-)a/C4/Circulation.pm (-9 / +7 lines)
Lines 1916-1922 sub _FixOverduesOnReturn { Link Here
1916
    return 0 unless $data;    # no warning, there's just nothing to fix
1916
    return 0 unless $data;    # no warning, there's just nothing to fix
1917
1917
1918
    my $uquery;
1918
    my $uquery;
1919
    my @bind = ($borrowernumber, $item, $data->{'accountno'});
1919
    my @bind = ($data->{'accountlinesid'});
1920
    if ($exemptfine) {
1920
    if ($exemptfine) {
1921
        $uquery = "update accountlines set accounttype='FFOR', amountoutstanding=0";
1921
        $uquery = "update accountlines set accounttype='FFOR', amountoutstanding=0";
1922
        if (C4::Context->preference("FinesLog")) {
1922
        if (C4::Context->preference("FinesLog")) {
Lines 1936-1942 sub _FixOverduesOnReturn { Link Here
1936
    } else {
1936
    } else {
1937
        $uquery = "update accountlines set accounttype='F' ";
1937
        $uquery = "update accountlines set accounttype='F' ";
1938
    }
1938
    }
1939
    $uquery .= " where (borrowernumber = ?) and (itemnumber = ?) and (accountno = ?)";
1939
    $uquery .= " where (accountlinesid = ?)";
1940
    my $usth = $dbh->prepare($uquery);
1940
    my $usth = $dbh->prepare($uquery);
1941
    return $usth->execute(@bind);
1941
    return $usth->execute(@bind);
1942
}
1942
}
Lines 1979-1987 sub _FixAccountForLostAndReturned { Link Here
1979
        $amountleft = $data->{'amountoutstanding'} - $amount;   # Um, isn't this the same as ZERO?  We just tested those two things are ==
1979
        $amountleft = $data->{'amountoutstanding'} - $amount;   # Um, isn't this the same as ZERO?  We just tested those two things are ==
1980
    }
1980
    }
1981
    my $usth = $dbh->prepare("UPDATE accountlines SET accounttype = 'LR',amountoutstanding='0'
1981
    my $usth = $dbh->prepare("UPDATE accountlines SET accounttype = 'LR',amountoutstanding='0'
1982
        WHERE (borrowernumber = ?)
1982
        WHERE (accountlinesid = ?)");
1983
        AND (itemnumber = ?) AND (accountno = ?) ");
1983
    $usth->execute($data->{'accountlinesid'});      # We might be adjusting an account for some OTHER borrowernumber now.  Not the one we passed in.
1984
    $usth->execute($data->{'borrowernumber'},$itemnumber,$acctno);      # We might be adjusting an account for some OTHER borrowernumber now.  Not the one we passed in.  
1985
    #check if any credit is left if so writeoff other accounts
1984
    #check if any credit is left if so writeoff other accounts
1986
    my $nextaccntno = getnextacctno($data->{'borrowernumber'});
1985
    my $nextaccntno = getnextacctno($data->{'borrowernumber'});
1987
    $amountleft *= -1 if ($amountleft < 0);
1986
    $amountleft *= -1 if ($amountleft < 0);
Lines 2000-2011 sub _FixAccountForLostAndReturned { Link Here
2000
                $newamtos = $accdata->{'amountoutstanding'} - $amountleft;
1999
                $newamtos = $accdata->{'amountoutstanding'} - $amountleft;
2001
                $amountleft = 0;
2000
                $amountleft = 0;
2002
            }
2001
            }
2003
            my $thisacct = $accdata->{'accountno'};
2002
            my $thisacct = $accdata->{'accountlinesid'};
2004
            # FIXME: move prepares outside while loop!
2003
            # FIXME: move prepares outside while loop!
2005
            my $usth = $dbh->prepare("UPDATE accountlines SET amountoutstanding= ?
2004
            my $usth = $dbh->prepare("UPDATE accountlines SET amountoutstanding= ?
2006
                    WHERE (borrowernumber = ?)
2005
                    WHERE (accountlinesid = ?)");
2007
                    AND (accountno=?)");
2006
            $usth->execute($newamtos,'$thisacct');    # FIXME: '$thisacct' is a string literal!
2008
            $usth->execute($newamtos,$data->{'borrowernumber'},'$thisacct');    # FIXME: '$thisacct' is a string literal!
2009
            $usth = $dbh->prepare("INSERT INTO accountoffsets
2007
            $usth = $dbh->prepare("INSERT INTO accountoffsets
2010
                (borrowernumber, accountno, offsetaccount,  offsetamount)
2008
                (borrowernumber, accountno, offsetaccount,  offsetamount)
2011
                VALUES
2009
                VALUES
(-)a/installer/data/mysql/kohastructure.sql (+2 lines)
Lines 2464-2469 CREATE TABLE `messages` ( -- circulation messages left via the patron's check ou Link Here
2464
2464
2465
DROP TABLE IF EXISTS `accountlines`;
2465
DROP TABLE IF EXISTS `accountlines`;
2466
CREATE TABLE `accountlines` (
2466
CREATE TABLE `accountlines` (
2467
  `accountlinesid` int(11) NOT NULL AUTO_INCREMENT,
2467
  `borrowernumber` int(11) NOT NULL default 0,
2468
  `borrowernumber` int(11) NOT NULL default 0,
2468
  `accountno` smallint(6) NOT NULL default 0,
2469
  `accountno` smallint(6) NOT NULL default 0,
2469
  `itemnumber` int(11) default NULL,
2470
  `itemnumber` int(11) default NULL,
Lines 2479-2484 CREATE TABLE `accountlines` ( Link Here
2479
  `notify_level` int(2) NOT NULL default 0,
2480
  `notify_level` int(2) NOT NULL default 0,
2480
  `note` text NULL default NULL,
2481
  `note` text NULL default NULL,
2481
  `manager_id` int(11) NULL,
2482
  `manager_id` int(11) NULL,
2483
  PRIMARY KEY (`accountlinesid`),
2482
  KEY `acctsborridx` (`borrowernumber`),
2484
  KEY `acctsborridx` (`borrowernumber`),
2483
  KEY `timeidx` (`timestamp`),
2485
  KEY `timeidx` (`timestamp`),
2484
  KEY `itemnumber` (`itemnumber`),
2486
  KEY `itemnumber` (`itemnumber`),
(-)a/installer/data/mysql/updatedatabase.pl (+7 lines)
Lines 5635-5640 if(C4::Context->preference("Version") < TransformToNum($DBversion) ) { Link Here
5635
    SetVersion($DBversion);
5635
    SetVersion($DBversion);
5636
}
5636
}
5637
5637
5638
$DBversion = "XXX";
5639
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
5640
    $dbh->do("ALTER TABLE `accountlines` ADD `accountlinesid` INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;");
5641
    print "Upgrade to $DBversion done (adding accountlinesid field in accountlines table)\n";
5642
    SetVersion($DBversion);
5643
}
5644
5638
=head1 FUNCTIONS
5645
=head1 FUNCTIONS
5639
5646
5640
=head2 TableExists($table)
5647
=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 / +44 lines)
Lines 42-47 use C4::Branch; Link Here
42
use C4::Members::Attributes qw(GetBorrowerAttributes);
42
use C4::Members::Attributes qw(GetBorrowerAttributes);
43
43
44
our $input = CGI->new;
44
our $input = CGI->new;
45
our $writeoff_sth;
46
our $add_writeoff_sth;
45
47
46
our ( $template, $loggedinuser, $cookie ) = get_template_and_user(
48
our ( $template, $loggedinuser, $cookie ) = get_template_and_user(
47
    {   template_name   => 'members/pay.tmpl',
49
    {   template_name   => 'members/pay.tmpl',
Lines 83-93 my $writeoff_all = $input->param('woall'); # writeoff all fines Link Here
83
if ($writeoff_all) {
85
if ($writeoff_all) {
84
    writeoff_all(@names);
86
    writeoff_all(@names);
85
} elsif ($writeoff_item) {
87
} elsif ($writeoff_item) {
86
    my $accountno    = $input->param('accountno');
88
    my $accountlinesid = $input->param('accountlinesid');
87
    my $itemno       = $input->param('itemnumber');
89
    my $itemno       = $input->param('itemnumber');
88
    my $account_type = $input->param('accounttype');
90
    my $account_type = $input->param('accounttype');
89
    my $amount       = $input->param('amountoutstanding');
91
    my $amount       = $input->param('amountoutstanding');
90
    WriteOffFee( $borrowernumber, $accountno, $itemno, $account_type, $amount, $branch );
92
    WriteOffFee( $borrowernumber, $accountlinesid, $itemno, $account_type, $amount, $branch );
91
}
93
}
92
94
93
for (@names) {
95
for (@names) {
Lines 106-111 add_accounts_to_template(); Link Here
106
108
107
output_html_with_http_headers $input, $cookie, $template->output;
109
output_html_with_http_headers $input, $cookie, $template->output;
108
110
111
sub writeoff {
112
    my ( $accountlinesid, $itemnum, $accounttype, $amount ) = @_;
113
    my $manager_id = 0;
114
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
115
116
    # if no item is attached to fine, make sure to store it as a NULL
117
    $itemnum ||= undef;
118
    get_writeoff_sth();
119
    $writeoff_sth->execute( $accountlinesid );
120
121
    my $acct = getnextacctno($borrowernumber);
122
    $add_writeoff_sth->execute( $borrowernumber, $acct, $itemnum, $amount, $manager_id );
123
124
    UpdateStats( $branch, 'writeoff', $amount, q{}, q{}, q{}, $borrowernumber );
125
126
    return;
127
}
109
128
110
sub add_accounts_to_template {
129
sub add_accounts_to_template {
111
130
Lines 167-172 sub redirect_to_paycollect { Link Here
167
    $redirect .= get_for_redirect( 'itemnumber',   "itemnumber$line_no",   0 );
186
    $redirect .= get_for_redirect( 'itemnumber',   "itemnumber$line_no",   0 );
168
    $redirect .= get_for_redirect( 'notify_id',    "notify_id$line_no",    0 );
187
    $redirect .= get_for_redirect( 'notify_id',    "notify_id$line_no",    0 );
169
    $redirect .= get_for_redirect( 'notify_level', "notify_level$line_no", 0 );
188
    $redirect .= get_for_redirect( 'notify_level', "notify_level$line_no", 0 );
189
    $redirect .= get_for_redirect( 'accountlinesid', "accountlinesid$line_no", 0 );
170
    $redirect .= '&remote_user=';
190
    $redirect .= '&remote_user=';
171
    $redirect .= $user;
191
    $redirect .= $user;
172
    return print $input->redirect($redirect);
192
    return print $input->redirect($redirect);
Lines 184-190 sub writeoff_all { Link Here
184
            my $itemno    = $input->param("itemnumber$value");
204
            my $itemno    = $input->param("itemnumber$value");
185
            my $amount    = $input->param("amountoutstanding$value");
205
            my $amount    = $input->param("amountoutstanding$value");
186
            my $accountno = $input->param("accountno$value");
206
            my $accountno = $input->param("accountno$value");
187
            WriteOffFee( $borrowernumber, $accountno, $itemno, $accounttype, $amount, $branch );
207
            my $accountlinesid = $input->param("accountlinesid$value");
208
            WriteOffFee( $borrowernumber, $accountlinesid, $itemno, $accounttype, $amount, $branch );
188
        }
209
        }
189
    }
210
    }
190
211
Lines 250-252 sub payselected { Link Here
250
    print $input->redirect($redirect);
271
    print $input->redirect($redirect);
251
    return;
272
    return;
252
}
273
}
274
275
sub get_writeoff_sth {
276
277
    # lets prepare these statement handles only once
278
    if ($writeoff_sth) {
279
        return;
280
    } else {
281
        my $dbh = C4::Context->dbh;
282
283
        # Do we need to validate accounttype
284
        my $sql = 'Update accountlines set amountoutstanding=0 '
285
          . 'WHERE accountlinesid=?';
286
        $writeoff_sth = $dbh->prepare($sql);
287
        my $insert =
288
q{insert into accountlines (borrowernumber,accountno,itemnumber,date,amount,description,accounttype,manager_id)}
289
          . q{values (?,?,?,now(),?,'Writeoff','W',?)};
290
        $add_writeoff_sth = $dbh->prepare($insert);
291
    }
292
    return;
293
}
(-)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