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

(-)a/C4/Accounts.pm (-58 / +56 lines)
Lines 64-70 patron. Link Here
64
64
65
Record payment by a patron. C<$borrowernumber> is the patron's
65
Record payment by a patron. C<$borrowernumber> is the patron's
66
borrower number. C<$payment> is a floating-point number, giving the
66
borrower number. C<$payment> is a floating-point number, giving the
67
amount that was paid. 
67
amount that was paid.
68
68
69
Amounts owed are paid off oldest first. That is, if the patron has a
69
Amounts owed are paid off oldest first. That is, if the patron has a
70
$1 fine from Feb. 1, another $1 fine from Mar. 1, and makes a payment
70
$1 fine from Feb. 1, another $1 fine from Mar. 1, and makes a payment
Lines 105-116 sub recordpayment { Link Here
105
            $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
105
            $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
106
            $amountleft = 0;
106
            $amountleft = 0;
107
        }
107
        }
108
        my $thisacct = $accdata->{accountno};
108
        my $thisacct = $accdata->{accountlinesid};
109
        my $usth     = $dbh->prepare(
109
        my $usth     = $dbh->prepare(
110
            "UPDATE accountlines SET amountoutstanding= ?
110
            "UPDATE accountlines SET amountoutstanding= ?
111
     WHERE (borrowernumber = ?) AND (accountno=?)"
111
     WHERE (accountlinesid = ?)"
112
        );
112
        );
113
        $usth->execute( $newamtos, $borrowernumber, $thisacct );
113
        $usth->execute( $newamtos, $thisacct );
114
        $usth->finish;
114
        $usth->finish;
115
#        $usth = $dbh->prepare(
115
#        $usth = $dbh->prepare(
116
#            "INSERT INTO accountoffsets
116
#            "INSERT INTO accountoffsets
Lines 136-142 sub recordpayment { Link Here
136
136
137
=head2 makepayment
137
=head2 makepayment
138
138
139
  &makepayment($borrowernumber, $acctnumber, $amount, $branchcode);
139
  &makepayment($accountlinesid, $borrowernumber, $acctnumber, $amount, $branchcode);
140
140
141
Records the fact that a patron has paid off the entire amount he or
141
Records the fact that a patron has paid off the entire amount he or
142
she owes.
142
she owes.
Lines 157-163 sub makepayment { Link Here
157
    #here we update both the accountoffsets and the account lines
157
    #here we update both the accountoffsets and the account lines
158
    #updated to check, if they are paying off a lost item, we return the item
158
    #updated to check, if they are paying off a lost item, we return the item
159
    # from their card, and put a note on the item record
159
    # from their card, and put a note on the item record
160
    my ( $borrowernumber, $accountno, $amount, $user, $branch ) = @_;
160
    my ( $accountlinesid, $borrowernumber, $accountno, $amount, $user, $branch ) = @_;
161
    my $dbh = C4::Context->dbh;
161
    my $dbh = C4::Context->dbh;
162
    my $manager_id = 0;
162
    my $manager_id = 0;
163
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; 
163
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; 
Lines 165-174 sub makepayment { Link Here
165
    # begin transaction
165
    # begin transaction
166
    my $nextaccntno = getnextacctno($borrowernumber);
166
    my $nextaccntno = getnextacctno($borrowernumber);
167
    my $newamtos    = 0;
167
    my $newamtos    = 0;
168
    my $sth =
168
    my $sth         = $dbh->prepare("SELECT * FROM accountlines WHERE accountlinesid=?");
169
      $dbh->prepare(
169
    $sth->execute( $accountlinesid );
170
        "SELECT * FROM accountlines WHERE  borrowernumber=? AND accountno=?");
171
    $sth->execute( $borrowernumber, $accountno );
172
    my $data = $sth->fetchrow_hashref;
170
    my $data = $sth->fetchrow_hashref;
173
    $sth->finish;
171
    $sth->finish;
174
172
Lines 177-198 sub makepayment { Link Here
177
            $dbh->prepare(
175
            $dbh->prepare(
178
                "UPDATE accountlines
176
                "UPDATE accountlines
179
                    SET amountoutstanding = 0, description = 'Payment,thanks'
177
                    SET amountoutstanding = 0, description = 'Payment,thanks'
180
                    WHERE borrowernumber = ?
178
                    WHERE accountlinesid = ?
181
                    AND accountno = ?
182
                "
179
                "
183
            );
180
            );
184
        $udp->execute($borrowernumber, $accountno );
181
        $udp->execute($accountlinesid);
185
        $udp->finish;
182
        $udp->finish;
186
    }else{
183
    }else{
187
        my $udp = 		
184
        my $udp = 		
188
            $dbh->prepare(
185
            $dbh->prepare(
189
                "UPDATE accountlines
186
                "UPDATE accountlines
190
                    SET amountoutstanding = 0
187
                    SET amountoutstanding = 0
191
                    WHERE borrowernumber = ?
188
                    WHERE accountlinesid = ?
192
                    AND accountno = ?
193
                "
189
                "
194
            );
190
            );
195
        $udp->execute($borrowernumber, $accountno );
191
        $udp->execute($accountlinesid);
196
        $udp->finish;
192
        $udp->finish;
197
193
198
         # create new line
194
         # create new line
Lines 219-224 sub makepayment { Link Here
219
    if ( $data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L' ) {
215
    if ( $data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L' ) {
220
        C4::Circulation::ReturnLostItem( $borrowernumber, $data->{'itemnumber'} );
216
        C4::Circulation::ReturnLostItem( $borrowernumber, $data->{'itemnumber'} );
221
    }
217
    }
218
    my $sthr = $dbh->prepare("SELECT max(accountlinesid) AS lastinsertid FROM accountlines");
219
    $sthr->execute();
220
    my $datalastinsertid = $sthr->fetchrow_hashref;
221
    $sthr->finish;
222
    return $datalastinsertid->{'lastinsertid'};
222
}
223
}
223
224
224
=head2 getnextacctno
225
=head2 getnextacctno
Lines 246-263 sub getnextacctno ($) { Link Here
246
247
247
=head2 fixaccounts (removed)
248
=head2 fixaccounts (removed)
248
249
249
  &fixaccounts($borrowernumber, $accountnumber, $amount);
250
  &fixaccounts($accountlinesid, $borrowernumber, $accountnumber, $amount);
250
251
251
#'
252
#'
252
# FIXME - I don't understand what this function does.
253
# FIXME - I don't understand what this function does.
253
sub fixaccounts {
254
sub fixaccounts {
254
    my ( $borrowernumber, $accountno, $amount ) = @_;
255
    my ( $accountlinesid, $borrowernumber, $accountno, $amount ) = @_;
255
    my $dbh = C4::Context->dbh;
256
    my $dbh = C4::Context->dbh;
256
    my $sth = $dbh->prepare(
257
    my $sth = $dbh->prepare(
257
        "SELECT * FROM accountlines WHERE borrowernumber=?
258
        "SELECT * FROM accountlines WHERE accountlinesid=?"
258
     AND accountno=?"
259
    );
259
    );
260
    $sth->execute( $borrowernumber, $accountno );
260
    $sth->execute( $accountlinesid );
261
    my $data = $sth->fetchrow_hashref;
261
    my $data = $sth->fetchrow_hashref;
262
262
263
    # FIXME - Error-checking
263
    # FIXME - Error-checking
Lines 269-276 sub fixaccounts { Link Here
269
        UPDATE  accountlines
269
        UPDATE  accountlines
270
        SET     amount = '$amount',
270
        SET     amount = '$amount',
271
                amountoutstanding = '$outstanding'
271
                amountoutstanding = '$outstanding'
272
        WHERE   borrowernumber = $borrowernumber
272
        WHERE   accountlinesid = $accountlinesid
273
          AND   accountno = $accountno
274
EOT
273
EOT
275
	# FIXME: exceedingly bad form.  Use prepare with placholders ("?") in query and execute args.
274
	# FIXME: exceedingly bad form.  Use prepare with placholders ("?") in query and execute args.
276
}
275
}
Lines 448-459 sub fixcredit { Link Here
448
            $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
447
            $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
449
            $amountleft = 0;
448
            $amountleft = 0;
450
        }
449
        }
451
        my $thisacct = $accdata->{accountno};
450
        my $thisacct = $accdata->{accountlinesid};
452
        my $usth     = $dbh->prepare(
451
        my $usth     = $dbh->prepare(
453
            "UPDATE accountlines SET amountoutstanding= ?
452
            "UPDATE accountlines SET amountoutstanding= ?
454
     WHERE (borrowernumber = ?) AND (accountno=?)"
453
     WHERE (accountlinesid = ?)"
455
        );
454
        );
456
        $usth->execute( $newamtos, $borrowernumber, $thisacct );
455
        $usth->execute( $newamtos, $thisacct );
457
        $usth->finish;
456
        $usth->finish;
458
        $usth = $dbh->prepare(
457
        $usth = $dbh->prepare(
459
            "INSERT INTO accountoffsets
458
            "INSERT INTO accountoffsets
Lines 487-498 sub fixcredit { Link Here
487
            $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
486
            $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
488
            $amountleft = 0;
487
            $amountleft = 0;
489
        }
488
        }
490
        my $thisacct = $accdata->{accountno};
489
        my $thisacct = $accdata->{accountlinesid};
491
        my $usth     = $dbh->prepare(
490
        my $usth     = $dbh->prepare(
492
            "UPDATE accountlines SET amountoutstanding= ?
491
            "UPDATE accountlines SET amountoutstanding= ?
493
     WHERE (borrowernumber = ?) AND (accountno=?)"
492
     WHERE (accountlinesid = ?)"
494
        );
493
        );
495
        $usth->execute( $newamtos, $borrowernumber, $thisacct );
494
        $usth->execute( $newamtos, $thisacct );
496
        $usth->finish;
495
        $usth->finish;
497
        $usth = $dbh->prepare(
496
        $usth = $dbh->prepare(
498
            "INSERT INTO accountoffsets
497
            "INSERT INTO accountoffsets
Lines 553-564 sub refund { Link Here
553
        }
552
        }
554
553
555
        #     print $amountleft;
554
        #     print $amountleft;
556
        my $thisacct = $accdata->{accountno};
555
        my $thisacct = $accdata->{accountlinesid};
557
        my $usth     = $dbh->prepare(
556
        my $usth     = $dbh->prepare(
558
            "UPDATE accountlines SET amountoutstanding= ?
557
            "UPDATE accountlines SET amountoutstanding= ?
559
     WHERE (borrowernumber = ?) AND (accountno=?)"
558
     WHERE (accountlinesid = ?)"
560
        );
559
        );
561
        $usth->execute( $newamtos, $borrowernumber, $thisacct );
560
        $usth->execute( $newamtos, $thisacct );
562
        $usth->finish;
561
        $usth->finish;
563
        $usth = $dbh->prepare(
562
        $usth = $dbh->prepare(
564
            "INSERT INTO accountoffsets
563
            "INSERT INTO accountoffsets
Lines 591-600 sub getcharges { Link Here
591
}
590
}
592
591
593
sub ModNote {
592
sub ModNote {
594
    my ( $borrowernumber, $accountno, $note ) = @_;
593
    my ( $accountlinesid, $note ) = @_;
595
    my $dbh = C4::Context->dbh;
594
    my $dbh = C4::Context->dbh;
596
    my $sth = $dbh->prepare('UPDATE accountlines SET note = ? WHERE borrowernumber = ? AND accountno = ?');
595
    my $sth = $dbh->prepare('UPDATE accountlines SET note = ? WHERE accountlinesid = ?');
597
    $sth->execute( $note, $borrowernumber, $accountno );
596
    $sth->execute( $note, $accountlinesid );
598
}
597
}
599
598
600
sub getcredits {
599
sub getcredits {
Lines 639-659 sub getrefunds { Link Here
639
}
638
}
640
639
641
sub ReversePayment {
640
sub ReversePayment {
642
  my ( $borrowernumber, $accountno ) = @_;
641
    my ( $accountlinesid ) = @_;
643
  my $dbh = C4::Context->dbh;
642
    my $dbh = C4::Context->dbh;
644
  
643
645
  my $sth = $dbh->prepare('SELECT amountoutstanding FROM accountlines WHERE borrowernumber = ? AND accountno = ?');
644
    my $sth = $dbh->prepare('SELECT amountoutstanding FROM accountlines WHERE accountlinesid = ?');
646
  $sth->execute( $borrowernumber, $accountno );
645
    $sth->execute( $accountlinesid );
647
  my $row = $sth->fetchrow_hashref();
646
    my $row = $sth->fetchrow_hashref();
648
  my $amount_outstanding = $row->{'amountoutstanding'};
647
    my $amount_outstanding = $row->{'amountoutstanding'};
649
  
648
650
  if ( $amount_outstanding <= 0 ) {
649
    if ( $amount_outstanding <= 0 ) {
651
    $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = amount * -1, description = CONCAT( description, " Reversed -" ) WHERE borrowernumber = ? AND accountno = ?');
650
        $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = amount * -1, description = CONCAT( description, " Reversed -" ) WHERE accountlinesid = ?');
652
    $sth->execute( $borrowernumber, $accountno );
651
        $sth->execute( $accountlinesid );
653
  } else {
652
    } else {
654
    $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = 0, description = CONCAT( description, " Reversed -" ) WHERE borrowernumber = ? AND accountno = ?');
653
        $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = 0, description = CONCAT( description, " Reversed -" ) WHERE accountlinesid = ?');
655
    $sth->execute( $borrowernumber, $accountno );
654
        $sth->execute( $accountlinesid );
656
  }
655
    }
657
}
656
}
658
657
659
=head2 recordpayment_selectaccts
658
=head2 recordpayment_selectaccts
Lines 695-701 sub recordpayment_selectaccts { Link Here
695
694
696
    # offset transactions
695
    # offset transactions
697
    my $sth     = $dbh->prepare('UPDATE accountlines SET amountoutstanding= ? ' .
696
    my $sth     = $dbh->prepare('UPDATE accountlines SET amountoutstanding= ? ' .
698
        'WHERE (borrowernumber = ?) AND (accountno=?)');
697
        'WHERE accountlinesid=?');
699
    for my $accdata ( @{$rows} ) {
698
    for my $accdata ( @{$rows} ) {
700
        if ($amountleft == 0) {
699
        if ($amountleft == 0) {
701
            last;
700
            last;
Lines 708-715 sub recordpayment_selectaccts { Link Here
708
            $newamtos   = $accdata->{amountoutstanding} - $amountleft;
707
            $newamtos   = $accdata->{amountoutstanding} - $amountleft;
709
            $amountleft = 0;
708
            $amountleft = 0;
710
        }
709
        }
711
        my $thisacct = $accdata->{accountno};
710
        my $thisacct = $accdata->{accountlinesid};
712
        $sth->execute( $newamtos, $borrowernumber, $thisacct );
711
        $sth->execute( $newamtos, $thisacct );
713
    }
712
    }
714
713
715
    # create new line
714
    # create new line
Lines 724-730 sub recordpayment_selectaccts { Link Here
724
# makepayment needs to be fixed to handle partials till then this separate subroutine
723
# makepayment needs to be fixed to handle partials till then this separate subroutine
725
# fills in
724
# fills in
726
sub makepartialpayment {
725
sub makepartialpayment {
727
    my ( $borrowernumber, $accountno, $amount, $user, $branch ) = @_;
726
    my ( $accountlinesid, $borrowernumber, $accountno, $amount, $user, $branch ) = @_;
728
    my $manager_id = 0;
727
    my $manager_id = 0;
729
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
728
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
730
    if (!$amount || $amount < 0) {
729
    if (!$amount || $amount < 0) {
Lines 736-747 sub makepartialpayment { Link Here
736
    my $newamtos    = 0;
735
    my $newamtos    = 0;
737
736
738
    my $data = $dbh->selectrow_hashref(
737
    my $data = $dbh->selectrow_hashref(
739
        'SELECT * FROM accountlines WHERE  borrowernumber=? AND accountno=?',undef,$borrowernumber,$accountno);
738
        'SELECT * FROM accountlines WHERE  accountlinesid=?',undef,$accountlinesid);
740
    my $new_outstanding = $data->{amountoutstanding} - $amount;
739
    my $new_outstanding = $data->{amountoutstanding} - $amount;
741
740
742
    my $update = 'UPDATE  accountlines SET amountoutstanding = ?  WHERE   borrowernumber = ? '
741
    my $update = 'UPDATE  accountlines SET amountoutstanding = ?  WHERE   accountlinesid = ? ';
743
    . ' AND   accountno = ?';
742
    $dbh->do( $update, undef, $new_outstanding, $accountlinesid);
744
    $dbh->do( $update, undef, $new_outstanding, $borrowernumber, $accountno);
745
743
746
    # create new line
744
    # create new line
747
    my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, '
745
    my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, '
(-)a/C4/Circulation.pm (-9 / +7 lines)
Lines 1841-1847 sub _FixOverduesOnReturn { Link Here
1841
    return 0 unless $data;    # no warning, there's just nothing to fix
1841
    return 0 unless $data;    # no warning, there's just nothing to fix
1842
1842
1843
    my $uquery;
1843
    my $uquery;
1844
    my @bind = ($borrowernumber, $item, $data->{'accountno'});
1844
    my @bind = ($data->{'accountlinesid'});
1845
    if ($exemptfine) {
1845
    if ($exemptfine) {
1846
        $uquery = "update accountlines set accounttype='FFOR', amountoutstanding=0";
1846
        $uquery = "update accountlines set accounttype='FFOR', amountoutstanding=0";
1847
        if (C4::Context->preference("FinesLog")) {
1847
        if (C4::Context->preference("FinesLog")) {
Lines 1861-1867 sub _FixOverduesOnReturn { Link Here
1861
    } else {
1861
    } else {
1862
        $uquery = "update accountlines set accounttype='F' ";
1862
        $uquery = "update accountlines set accounttype='F' ";
1863
    }
1863
    }
1864
    $uquery .= " where (borrowernumber = ?) and (itemnumber = ?) and (accountno = ?)";
1864
    $uquery .= " where (accountlinesid = ?)";
1865
    my $usth = $dbh->prepare($uquery);
1865
    my $usth = $dbh->prepare($uquery);
1866
    return $usth->execute(@bind);
1866
    return $usth->execute(@bind);
1867
}
1867
}
Lines 1904-1912 sub _FixAccountForLostAndReturned { Link Here
1904
        $amountleft = $data->{'amountoutstanding'} - $amount;   # Um, isn't this the same as ZERO?  We just tested those two things are ==
1904
        $amountleft = $data->{'amountoutstanding'} - $amount;   # Um, isn't this the same as ZERO?  We just tested those two things are ==
1905
    }
1905
    }
1906
    my $usth = $dbh->prepare("UPDATE accountlines SET accounttype = 'LR',amountoutstanding='0'
1906
    my $usth = $dbh->prepare("UPDATE accountlines SET accounttype = 'LR',amountoutstanding='0'
1907
        WHERE (borrowernumber = ?)
1907
        WHERE (accountlinesid = ?)");
1908
        AND (itemnumber = ?) AND (accountno = ?) ");
1908
    $usth->execute($data->{'accountlinesid'});      # We might be adjusting an account for some OTHER borrowernumber now.  Not the one we passed in.  
1909
    $usth->execute($data->{'borrowernumber'},$itemnumber,$acctno);      # We might be adjusting an account for some OTHER borrowernumber now.  Not the one we passed in.  
1910
    #check if any credit is left if so writeoff other accounts
1909
    #check if any credit is left if so writeoff other accounts
1911
    my $nextaccntno = getnextacctno($data->{'borrowernumber'});
1910
    my $nextaccntno = getnextacctno($data->{'borrowernumber'});
1912
    $amountleft *= -1 if ($amountleft < 0);
1911
    $amountleft *= -1 if ($amountleft < 0);
Lines 1925-1936 sub _FixAccountForLostAndReturned { Link Here
1925
                $newamtos = $accdata->{'amountoutstanding'} - $amountleft;
1924
                $newamtos = $accdata->{'amountoutstanding'} - $amountleft;
1926
                $amountleft = 0;
1925
                $amountleft = 0;
1927
            }
1926
            }
1928
            my $thisacct = $accdata->{'accountno'};
1927
            my $thisacct = $accdata->{'accountlinesid'};
1929
            # FIXME: move prepares outside while loop!
1928
            # FIXME: move prepares outside while loop!
1930
            my $usth = $dbh->prepare("UPDATE accountlines SET amountoutstanding= ?
1929
            my $usth = $dbh->prepare("UPDATE accountlines SET amountoutstanding= ?
1931
                    WHERE (borrowernumber = ?)
1930
                    WHERE (accountlinesid = ?)");
1932
                    AND (accountno=?)");
1931
            $usth->execute($newamtos,'$thisacct');    # FIXME: '$thisacct' is a string literal!
1933
            $usth->execute($newamtos,$data->{'borrowernumber'},'$thisacct');    # FIXME: '$thisacct' is a string literal!
1934
            $usth = $dbh->prepare("INSERT INTO accountoffsets
1932
            $usth = $dbh->prepare("INSERT INTO accountoffsets
1935
                (borrowernumber, accountno, offsetaccount,  offsetamount)
1933
                (borrowernumber, accountno, offsetaccount,  offsetamount)
1936
                VALUES
1934
                VALUES
(-)a/installer/data/mysql/kohastructure.sql (+2 lines)
Lines 2363-2368 CREATE TABLE `messages` ( -- circulation messages left via the patron's check ou Link Here
2363
2363
2364
DROP TABLE IF EXISTS `accountlines`;
2364
DROP TABLE IF EXISTS `accountlines`;
2365
CREATE TABLE `accountlines` (
2365
CREATE TABLE `accountlines` (
2366
  `accountlinesid` int(11) NOT NULL AUTO_INCREMENT,
2366
  `borrowernumber` int(11) NOT NULL default 0,
2367
  `borrowernumber` int(11) NOT NULL default 0,
2367
  `accountno` smallint(6) NOT NULL default 0,
2368
  `accountno` smallint(6) NOT NULL default 0,
2368
  `itemnumber` int(11) default NULL,
2369
  `itemnumber` int(11) default NULL,
Lines 2378-2383 CREATE TABLE `accountlines` ( Link Here
2378
  `notify_level` int(2) NOT NULL default 0,
2379
  `notify_level` int(2) NOT NULL default 0,
2379
  `note` text NULL default NULL,
2380
  `note` text NULL default NULL,
2380
  `manager_id` int(11) NULL,
2381
  `manager_id` int(11) NULL,
2382
  PRIMARY KEY (`accountlinesid`),
2381
  KEY `acctsborridx` (`borrowernumber`),
2383
  KEY `acctsborridx` (`borrowernumber`),
2382
  KEY `timeidx` (`timestamp`),
2384
  KEY `timeidx` (`timestamp`),
2383
  KEY `itemnumber` (`itemnumber`),
2385
  KEY `itemnumber` (`itemnumber`),
(-)a/installer/data/mysql/updatedatabase.pl (+7 lines)
Lines 4765-4770 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
4765
    SetVersion($DBversion);
4765
    SetVersion($DBversion);
4766
}
4766
}
4767
4767
4768
$DBversion = "XXX";
4769
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
4770
    $dbh->do("ALTER TABLE `accountlines` ADD `accountlinesid` INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;");
4771
    print "Upgrade to $DBversion done (adding accountlinesid field in accountlines table)\n";
4772
    SetVersion($DBversion);
4773
}
4774
4768
=head1 FUNCTIONS
4775
=head1 FUNCTIONS
4769
4776
4770
=head2 DropAllForeignKeys($table)
4777
=head2 DropAllForeignKeys($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 (-6 / +8 lines)
Lines 86-96 my $writeoff_all = $input->param('woall'); # writeoff all fines Link Here
86
if ($writeoff_all) {
86
if ($writeoff_all) {
87
    writeoff_all(@names);
87
    writeoff_all(@names);
88
} elsif ($writeoff_item) {
88
} elsif ($writeoff_item) {
89
    my $accountno    = $input->param('accountno');
89
    my $accountlinesid = $input->param('accountlinesid');
90
    my $itemno       = $input->param('itemnumber');
90
    my $itemno       = $input->param('itemnumber');
91
    my $account_type = $input->param('accounttype');
91
    my $account_type = $input->param('accounttype');
92
    my $amount       = $input->param('amount');
92
    my $amount       = $input->param('amount');
93
    writeoff( $accountno, $itemno, $account_type, $amount );
93
    writeoff( $accountlinesid, $itemno, $account_type, $amount );
94
}
94
}
95
95
96
for (@names) {
96
for (@names) {
Lines 110-123 add_accounts_to_template(); Link Here
110
output_html_with_http_headers $input, $cookie, $template->output;
110
output_html_with_http_headers $input, $cookie, $template->output;
111
111
112
sub writeoff {
112
sub writeoff {
113
    my ( $accountnum, $itemnum, $accounttype, $amount ) = @_;
113
    my ( $accountlinesid, $itemnum, $accounttype, $amount ) = @_;
114
    my $manager_id = 0;
114
    my $manager_id = 0;
115
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
115
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
116
116
117
    # if no item is attached to fine, make sure to store it as a NULL
117
    # if no item is attached to fine, make sure to store it as a NULL
118
    $itemnum ||= undef;
118
    $itemnum ||= undef;
119
    get_writeoff_sth();
119
    get_writeoff_sth();
120
    $writeoff_sth->execute( $accountnum, $borrowernumber );
120
    $writeoff_sth->execute( $accountlinesid );
121
121
122
    my $acct = getnextacctno($borrowernumber);
122
    my $acct = getnextacctno($borrowernumber);
123
    $add_writeoff_sth->execute( $borrowernumber, $acct, $itemnum, $amount, $manager_id );
123
    $add_writeoff_sth->execute( $borrowernumber, $acct, $itemnum, $amount, $manager_id );
Lines 187-192 sub redirect_to_paycollect { Link Here
187
    $redirect .= get_for_redirect( 'itemnumber',   "itemnumber$line_no",   0 );
187
    $redirect .= get_for_redirect( 'itemnumber',   "itemnumber$line_no",   0 );
188
    $redirect .= get_for_redirect( 'notify_id',    "notify_id$line_no",    0 );
188
    $redirect .= get_for_redirect( 'notify_id',    "notify_id$line_no",    0 );
189
    $redirect .= get_for_redirect( 'notify_level', "notify_level$line_no", 0 );
189
    $redirect .= get_for_redirect( 'notify_level', "notify_level$line_no", 0 );
190
    $redirect .= get_for_redirect( 'accountlinesid', "accountlinesid$line_no", 0 );
190
    $redirect .= '&remote_user=';
191
    $redirect .= '&remote_user=';
191
    $redirect .= $user;
192
    $redirect .= $user;
192
    return print $input->redirect($redirect);
193
    return print $input->redirect($redirect);
Lines 204-210 sub writeoff_all { Link Here
204
            my $itemno    = $input->param("itemnumber$value");
205
            my $itemno    = $input->param("itemnumber$value");
205
            my $amount    = $input->param("amount$value");
206
            my $amount    = $input->param("amount$value");
206
            my $accountno = $input->param("accountno$value");
207
            my $accountno = $input->param("accountno$value");
207
            writeoff( $accountno, $itemno, $accounttype, $amount );
208
            my $accountlinesid = $input->param("accountlinesid$value");
209
            writeoff( $accountlinesid, $itemno, $accounttype, $amount );
208
        }
210
        }
209
    }
211
    }
210
212
Lines 281-287 sub get_writeoff_sth { Link Here
281
283
282
        # Do we need to validate accounttype
284
        # Do we need to validate accounttype
283
        my $sql = 'Update accountlines set amountoutstanding=0 '
285
        my $sql = 'Update accountlines set amountoutstanding=0 '
284
          . 'WHERE accountno=? and borrowernumber=?';
286
          . 'WHERE accountlinesid=?';
285
        $writeoff_sth = $dbh->prepare($sql);
287
        $writeoff_sth = $dbh->prepare($sql);
286
        my $insert =
288
        my $insert =
287
q{insert into accountlines (borrowernumber,accountno,itemnumber,date,amount,description,accounttype,manager_id)}
289
q{insert into accountlines (borrowernumber,accountno,itemnumber,date,amount,description,accounttype,manager_id)}
(-)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