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

(-)a/C4/Accounts.pm (-26 / +33 lines)
Lines 126-134 sub recordpayment { Link Here
126
    my $usth = $dbh->prepare(
126
    my $usth = $dbh->prepare(
127
        "INSERT INTO accountlines
127
        "INSERT INTO accountlines
128
  (borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding)
128
  (borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding)
129
  VALUES (?,?,now(),?,'Payment,thanks','Pay',?)"
129
  VALUES (?,?,now(),?,'Payment,thanks','Pay',?,?)"
130
    );
130
    );
131
    $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, 0 - $amountleft );
131
    $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, 0 - $amountleft, $branch );
132
    $usth->finish;
132
    $usth->finish;
133
    UpdateStats( $branch, 'payment', $data, '', '', '', $borrowernumber, $nextaccntno );
133
    UpdateStats( $branch, 'payment', $data, '', '', '', $borrowernumber, $nextaccntno );
134
    $sth->finish;
134
    $sth->finish;
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 ( $borrowernumber, $accountno, $amount, $branchcode, $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 201-217 sub makepayment { Link Here
201
        my $ins = 
201
        my $ins = 
202
            $dbh->prepare( 
202
            $dbh->prepare( 
203
                "INSERT 
203
                "INSERT 
204
                    INTO accountlines (borrowernumber, accountno, date, amount, itemnumber, description, accounttype, amountoutstanding, manager_id)
204
                    INTO accountlines (borrowernumber, accountno, date, amount, itemnumber, description, accounttype, amountoutstanding, manager_id, branch)
205
                    VALUES ( ?, ?, now(), ?, ?, 'Payment,thanks', 'Pay', 0, ?)"
205
                    VALUES ( ?, ?, now(), ?, ?, 'Payment,thanks', 'Pay', 0, ?, ?)"
206
            );
206
            );
207
        $ins->execute($borrowernumber, $nextaccntno, $payment, $data->{'itemnumber'}, $manager_id);
207
        $ins->execute($borrowernumber, $nextaccntno, $payment, $data->{'itemnumber'}, $manager_id, $branchcode);
208
        $ins->finish;
208
        $ins->finish;
209
    }
209
    }
210
210
211
    # FIXME - The second argument to &UpdateStats is supposed to be the
211
    # FIXME - The second argument to &UpdateStats is supposed to be the
212
    # branch code.
212
    # branch code.
213
    # UpdateStats is now being passed $accountno too. MTJ
213
    # UpdateStats is now being passed $accountno too. MTJ
214
    UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber,
214
    UpdateStats( $branchcode, 'payment', $amount, '', '', '', $borrowernumber,
215
        $accountno );
215
        $accountno );
216
    #from perldoc: for SELECT only #$sth->finish;
216
    #from perldoc: for SELECT only #$sth->finish;
217
217
Lines 284-289 sub chargelostitem{ Link Here
284
# FIXME : if no replacement price, borrower just doesn't get charged?
284
# FIXME : if no replacement price, borrower just doesn't get charged?
285
    my $dbh = C4::Context->dbh();
285
    my $dbh = C4::Context->dbh();
286
    my ($borrowernumber, $itemnumber, $amount, $description) = @_;
286
    my ($borrowernumber, $itemnumber, $amount, $description) = @_;
287
    my $branchcode = C4::Context->userenv->{'branch'};
287
288
288
    # first make sure the borrower hasn't already been charged for this item
289
    # first make sure the borrower hasn't already been charged for this item
289
    my $sth1=$dbh->prepare("SELECT * from accountlines
290
    my $sth1=$dbh->prepare("SELECT * from accountlines
Lines 298-307 sub chargelostitem{ Link Here
298
        #  process (or person) to update it, since we don't handle any defaults for replacement prices.
299
        #  process (or person) to update it, since we don't handle any defaults for replacement prices.
299
        my $accountno = getnextacctno($borrowernumber);
300
        my $accountno = getnextacctno($borrowernumber);
300
        my $sth2=$dbh->prepare("INSERT INTO accountlines
301
        my $sth2=$dbh->prepare("INSERT INTO accountlines
301
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber)
302
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber,branchcode)
302
        VALUES (?,?,now(),?,?,'L',?,?)");
303
        VALUES (?,?,now(),?,?,'L',?,?,?)");
303
        $sth2->execute($borrowernumber,$accountno,$amount,
304
        $sth2->execute($borrowernumber,$accountno,$amount,
304
        $description,$amount,$itemnumber);
305
        $description,$amount,$itemnumber,$branchcode);
305
        $sth2->finish;
306
        $sth2->finish;
306
    # FIXME: Log this ?
307
    # FIXME: Log this ?
307
    }
308
    }
Lines 337-342 sub manualinvoice { Link Here
337
    my ( $borrowernumber, $itemnum, $desc, $type, $amount, $note ) = @_;
338
    my ( $borrowernumber, $itemnum, $desc, $type, $amount, $note ) = @_;
338
    my $manager_id = 0;
339
    my $manager_id = 0;
339
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
340
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
341
    my $branchcode = C4::Context->userenv->{'branch'};
340
    my $dbh      = C4::Context->dbh;
342
    my $dbh      = C4::Context->dbh;
341
    my $notifyid = 0;
343
    my $notifyid = 0;
342
    my $insert;
344
    my $insert;
Lines 387-402 sub manualinvoice { Link Here
387
        $desc .= ' ' . $itemnum;
389
        $desc .= ' ' . $itemnum;
388
        my $sth = $dbh->prepare(
390
        my $sth = $dbh->prepare(
389
            'INSERT INTO  accountlines
391
            'INSERT INTO  accountlines
390
                        (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, itemnumber,notify_id, note, manager_id)
392
                        (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, itemnumber,notify_id, note, manager_id, branchcode)
391
        VALUES (?, ?, now(), ?,?, ?,?,?,?,?,?)');
393
        VALUES (?, ?, now(), ?,?, ?,?,?,?,?,?,?)');
392
     $sth->execute($borrowernumber, $accountno, $amount, $desc, $type, $amountleft, $itemnum,$notifyid, $note, $manager_id) || return $sth->errstr;
394
     $sth->execute($borrowernumber, $accountno, $amount, $desc, $type, $amountleft, $itemnum,$notifyid, $note, $manager_id, $branchcode) || return $sth->errstr;
393
  } else {
395
  } else {
394
    my $sth=$dbh->prepare("INSERT INTO  accountlines
396
    my $sth=$dbh->prepare("INSERT INTO  accountlines
395
            (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding,notify_id, note, manager_id)
397
            (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding,notify_id, note, manager_id, branchcode)
396
            VALUES (?, ?, now(), ?, ?, ?, ?,?,?,?)"
398
            VALUES (?, ?, now(), ?, ?, ?, ?,?,?,?,?)"
397
        );
399
        );
398
        $sth->execute( $borrowernumber, $accountno, $amount, $desc, $type,
400
        $sth->execute( $borrowernumber, $accountno, $amount, $desc, $type,
399
            $amountleft, $notifyid, $note, $manager_id );
401
            $amountleft, $notifyid, $note, $manager_id, $branchcode );
400
    }
402
    }
401
    return 0;
403
    return 0;
402
}
404
}
Lines 713-722 sub recordpayment_selectaccts { Link Here
713
    }
715
    }
714
716
715
    # create new line
717
    # create new line
716
    $sql = 'INSERT INTO accountlines ' .
718
    $sql = "
717
    '(borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding) ' .
719
        INSERT INTO accountlines 
718
    q|VALUES (?,?,now(),?,'Payment,thanks','Pay',?)|;
720
        ( borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, branchcode) 
719
    $dbh->do($sql,{},$borrowernumber, $nextaccntno, 0 - $amount, 0 - $amountleft );
721
        VALUES (?,?,now(),?,'Payment,thanks','Pay',?,?)
722
    ";
723
    $dbh->do($sql,{},$borrowernumber, $nextaccntno, 0 - $amount, 0 - $amountleft, $branch );
720
    UpdateStats( $branch, 'payment', $amount, '', '', '', $borrowernumber, $nextaccntno );
724
    UpdateStats( $branch, 'payment', $amount, '', '', '', $borrowernumber, $nextaccntno );
721
    return;
725
    return;
722
}
726
}
Lines 739-755 sub makepartialpayment { Link Here
739
        'SELECT * FROM accountlines WHERE  borrowernumber=? AND accountno=?',undef,$borrowernumber,$accountno);
743
        'SELECT * FROM accountlines WHERE  borrowernumber=? AND accountno=?',undef,$borrowernumber,$accountno);
740
    my $new_outstanding = $data->{amountoutstanding} - $amount;
744
    my $new_outstanding = $data->{amountoutstanding} - $amount;
741
745
742
    my $update = 'UPDATE  accountlines SET amountoutstanding = ?  WHERE   borrowernumber = ? '
746
    my $update = "
743
    . ' AND   accountno = ?';
747
        UPDATE  accountlines SET amountoutstanding = ? WHERE borrowernumber = ?  AND accountno = ?
748
    ";
744
    $dbh->do( $update, undef, $new_outstanding, $borrowernumber, $accountno);
749
    $dbh->do( $update, undef, $new_outstanding, $borrowernumber, $accountno);
745
750
746
    # create new line
751
    # create new line
747
    my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, '
752
    my $insert = "
748
    .  'description, accounttype, amountoutstanding, itemnumber, manager_id) '
753
        INSERT INTO accountlines (borrowernumber, accountno, date, amount,
749
    . ' VALUES (?, ?, now(), ?, ?, ?, 0, ?, ?)';
754
        description, accounttype, amountoutstanding, itemnumber, manager_id, branchcode)
755
        VALUES (?, ?, now(), ?, ?, ?, 0, ?, ?, ?)
756
    ";
750
757
751
    $dbh->do(  $insert, undef, $borrowernumber, $nextaccntno, $amount,
758
    $dbh->do(  $insert, undef, $borrowernumber, $nextaccntno, $amount,
752
        "Payment, thanks - $user", 'Pay', $data->{'itemnumber'}, $manager_id);
759
        "Payment, thanks - $user", 'Pay', $data->{'itemnumber'}, $manager_id, $branch);
753
760
754
    UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber, $accountno );
761
    UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber, $accountno );
755
762
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 2360-2365 CREATE TABLE `accountlines` ( Link Here
2360
  `notify_level` int(2) NOT NULL default 0,
2360
  `notify_level` int(2) NOT NULL default 0,
2361
  `note` text NULL default NULL,
2361
  `note` text NULL default NULL,
2362
  `manager_id` int(11) NULL,
2362
  `manager_id` int(11) NULL,
2363
  `branchcode` VARCHAR( 10 ) NULL DEFAULT NULL, -- the branchcode of the library where a payment was made, a manual invoice created, etc.
2363
  KEY `acctsborridx` (`borrowernumber`),
2364
  KEY `acctsborridx` (`borrowernumber`),
2364
  KEY `timeidx` (`timestamp`),
2365
  KEY `timeidx` (`timestamp`),
2365
  KEY `itemnumber` (`itemnumber`),
2366
  KEY `itemnumber` (`itemnumber`),
(-)a/installer/data/mysql/updatedatabase.pl (-1 / +7 lines)
Lines 4712-4717 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { Link Here
4712
    SetVersion($DBversion);
4712
    SetVersion($DBversion);
4713
}
4713
}
4714
4714
4715
$DBversion = "3.07.00.XXX";
4716
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
4717
    $dbh->do("ALTER TABLE accountlines ADD branchcode VARCHAR( 10 ) NULL DEFAULT NULL");
4718
    print "Upgrade to $DBversion done (Added column branchcode to accountlines)\n";
4719
    SetVersion($DBversion);
4720
}
4721
4715
=head1 FUNCTIONS
4722
=head1 FUNCTIONS
4716
4723
4717
=head2 DropAllForeignKeys($table)
4724
=head2 DropAllForeignKeys($table)
4718
- 

Return to bug 7595