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

(-)a/C4/Accounts.pm (-26 / +31 lines)
Lines 124-134 sub recordpayment { Link Here
124
124
125
    # create new line
125
    # create new line
126
    my $usth = $dbh->prepare(
126
    my $usth = $dbh->prepare(
127
        "INSERT INTO accountlines
127
        "INSERT INTO accountlines ( borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, branchcode )
128
  (borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding)
128
         VALUES ( ?, ?, now(), ?, 'Payment,thanks','Pay', ?, ? )"
129
  VALUES (?,?,now(),?,'Payment,thanks','Pay',?)"
130
    );
129
    );
131
    $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, 0 - $amountleft );
130
    $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, 0 - $amountleft, $branch );
132
    $usth->finish;
131
    $usth->finish;
133
    UpdateStats( $branch, 'payment', $data, '', '', '', $borrowernumber, $nextaccntno );
132
    UpdateStats( $branch, 'payment', $data, '', '', '', $borrowernumber, $nextaccntno );
134
    $sth->finish;
133
    $sth->finish;
Lines 201-210 sub makepayment { Link Here
201
        my $ins = 
200
        my $ins = 
202
            $dbh->prepare( 
201
            $dbh->prepare( 
203
                "INSERT 
202
                "INSERT 
204
                    INTO accountlines (borrowernumber, accountno, date, amount, itemnumber, description, accounttype, amountoutstanding, manager_id)
203
                    INTO accountlines (borrowernumber, accountno, date, amount, itemnumber, description, accounttype, amountoutstanding, manager_id, branchcode)
205
                    VALUES ( ?, ?, now(), ?, ?, 'Payment,thanks', 'Pay', 0, ?)"
204
                    VALUES ( ?, ?, now(), ?, ?, 'Payment,thanks', 'Pay', 0, ?, ?)"
206
            );
205
            );
207
        $ins->execute($borrowernumber, $nextaccntno, $payment, $data->{'itemnumber'}, $manager_id);
206
        $ins->execute($borrowernumber, $nextaccntno, $payment, $data->{'itemnumber'}, $manager_id, C4::Context->userenv->{'branch'});
208
        $ins->finish;
207
        $ins->finish;
209
    }
208
    }
210
209
Lines 298-307 sub chargelostitem{ Link Here
298
        #  process (or person) to update it, since we don't handle any defaults for replacement prices.
297
        #  process (or person) to update it, since we don't handle any defaults for replacement prices.
299
        my $accountno = getnextacctno($borrowernumber);
298
        my $accountno = getnextacctno($borrowernumber);
300
        my $sth2=$dbh->prepare("INSERT INTO accountlines
299
        my $sth2=$dbh->prepare("INSERT INTO accountlines
301
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber)
300
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber,branchcode)
302
        VALUES (?,?,now(),?,?,'L',?,?)");
301
        VALUES (?,?,now(),?,?,'L',?,?,?)");
303
        $sth2->execute($borrowernumber,$accountno,$amount,
302
        $sth2->execute($borrowernumber,$accountno,$amount,
304
        $description,$amount,$itemnumber);
303
        $description,$amount,$itemnumber,C4::Context->userenv->{'branch'});
305
        $sth2->finish;
304
        $sth2->finish;
306
    # FIXME: Log this ?
305
    # FIXME: Log this ?
307
    }
306
    }
Lines 337-342 sub manualinvoice { Link Here
337
    my ( $borrowernumber, $itemnum, $desc, $type, $amount, $note ) = @_;
336
    my ( $borrowernumber, $itemnum, $desc, $type, $amount, $note ) = @_;
338
    my $manager_id = 0;
337
    my $manager_id = 0;
339
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
338
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
339
    my $branchcode = C4::Context->userenv->{'branch'};
340
    my $dbh      = C4::Context->dbh;
340
    my $dbh      = C4::Context->dbh;
341
    my $notifyid = 0;
341
    my $notifyid = 0;
342
    my $insert;
342
    my $insert;
Lines 387-402 sub manualinvoice { Link Here
387
        $desc .= ' ' . $itemnum;
387
        $desc .= ' ' . $itemnum;
388
        my $sth = $dbh->prepare(
388
        my $sth = $dbh->prepare(
389
            'INSERT INTO  accountlines
389
            'INSERT INTO  accountlines
390
                        (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, itemnumber,notify_id, note, manager_id)
390
                        (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, itemnumber,notify_id, note, manager_id, branchcode)
391
        VALUES (?, ?, now(), ?,?, ?,?,?,?,?,?)');
391
        VALUES (?, ?, now(), ?,?, ?,?,?,?,?,?,?)');
392
     $sth->execute($borrowernumber, $accountno, $amount, $desc, $type, $amountleft, $itemnum,$notifyid, $note, $manager_id) || return $sth->errstr;
392
     $sth->execute($borrowernumber, $accountno, $amount, $desc, $type, $amountleft, $itemnum,$notifyid, $note, $manager_id, $branchcode) || return $sth->errstr;
393
  } else {
393
  } else {
394
    my $sth=$dbh->prepare("INSERT INTO  accountlines
394
    my $sth=$dbh->prepare("INSERT INTO  accountlines
395
            (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding,notify_id, note, manager_id)
395
            (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding,notify_id, note, manager_id, branchcode)
396
            VALUES (?, ?, now(), ?, ?, ?, ?,?,?,?)"
396
            VALUES (?, ?, now(), ?, ?, ?, ?,?,?,?,?)"
397
        );
397
        );
398
        $sth->execute( $borrowernumber, $accountno, $amount, $desc, $type,
398
        $sth->execute( $borrowernumber, $accountno, $amount, $desc, $type,
399
            $amountleft, $notifyid, $note, $manager_id );
399
            $amountleft, $notifyid, $note, $manager_id, $branchcode );
400
    }
400
    }
401
    return 0;
401
    return 0;
402
}
402
}
Lines 713-722 sub recordpayment_selectaccts { Link Here
713
    }
713
    }
714
714
715
    # create new line
715
    # create new line
716
    $sql = 'INSERT INTO accountlines ' .
716
    $sql = "
717
    '(borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding) ' .
717
        INSERT INTO accountlines 
718
    q|VALUES (?,?,now(),?,'Payment,thanks','Pay',?)|;
718
        ( borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, branchcode) 
719
    $dbh->do($sql,{},$borrowernumber, $nextaccntno, 0 - $amount, 0 - $amountleft );
719
        VALUES (?,?,now(),?,'Payment,thanks','Pay',?,?)
720
    ";
721
    $dbh->do($sql,{},$borrowernumber, $nextaccntno, 0 - $amount, 0 - $amountleft, $branch );
720
    UpdateStats( $branch, 'payment', $amount, '', '', '', $borrowernumber, $nextaccntno );
722
    UpdateStats( $branch, 'payment', $amount, '', '', '', $borrowernumber, $nextaccntno );
721
    return;
723
    return;
722
}
724
}
Lines 739-755 sub makepartialpayment { Link Here
739
        'SELECT * FROM accountlines WHERE  borrowernumber=? AND accountno=?',undef,$borrowernumber,$accountno);
741
        'SELECT * FROM accountlines WHERE  borrowernumber=? AND accountno=?',undef,$borrowernumber,$accountno);
740
    my $new_outstanding = $data->{amountoutstanding} - $amount;
742
    my $new_outstanding = $data->{amountoutstanding} - $amount;
741
743
742
    my $update = 'UPDATE  accountlines SET amountoutstanding = ?  WHERE   borrowernumber = ? '
744
    my $update = "
743
    . ' AND   accountno = ?';
745
        UPDATE  accountlines SET amountoutstanding = ? WHERE borrowernumber = ?  AND accountno = ?
746
    ";
744
    $dbh->do( $update, undef, $new_outstanding, $borrowernumber, $accountno);
747
    $dbh->do( $update, undef, $new_outstanding, $borrowernumber, $accountno);
745
748
746
    # create new line
749
    # create new line
747
    my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, '
750
    my $insert = "
748
    .  'description, accounttype, amountoutstanding, itemnumber, manager_id) '
751
        INSERT INTO accountlines (borrowernumber, accountno, date, amount,
749
    . ' VALUES (?, ?, now(), ?, ?, ?, 0, ?, ?)';
752
        description, accounttype, amountoutstanding, itemnumber, manager_id, branchcode)
753
        VALUES (?, ?, now(), ?, ?, ?, 0, ?, ?, ?)
754
    ";
750
755
751
    $dbh->do(  $insert, undef, $borrowernumber, $nextaccntno, $amount,
756
    $dbh->do(  $insert, undef, $borrowernumber, $nextaccntno, $amount,
752
        "Payment, thanks - $user", 'Pay', $data->{'itemnumber'}, $manager_id);
757
        "Payment, thanks - $user", 'Pay', $data->{'itemnumber'}, $manager_id, C4::Context->userenv->{'branch'});
753
758
754
    UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber, $accountno );
759
    UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber, $accountno );
755
760
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 2383-2388 CREATE TABLE `accountlines` ( Link Here
2383
  `notify_level` int(2) NOT NULL default 0,
2383
  `notify_level` int(2) NOT NULL default 0,
2384
  `note` text NULL default NULL,
2384
  `note` text NULL default NULL,
2385
  `manager_id` int(11) NULL,
2385
  `manager_id` int(11) NULL,
2386
  `branchcode` VARCHAR( 10 ) NULL DEFAULT NULL, -- the branchcode of the library where a payment was made, a manual invoice created, etc.
2386
  KEY `acctsborridx` (`borrowernumber`),
2387
  KEY `acctsborridx` (`borrowernumber`),
2387
  KEY `timeidx` (`timestamp`),
2388
  KEY `timeidx` (`timestamp`),
2388
  KEY `itemnumber` (`itemnumber`),
2389
  KEY `itemnumber` (`itemnumber`),
(-)a/installer/data/mysql/updatedatabase.pl (-1 / +7 lines)
Lines 4892-4897 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { Link Here
4892
    SetVersion($DBversion);
4892
    SetVersion($DBversion);
4893
}
4893
}
4894
4894
4895
$DBversion = "3.07.00.XXX";
4896
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
4897
    $dbh->do("ALTER TABLE accountlines ADD branchcode VARCHAR( 10 ) NULL DEFAULT NULL AFTER manager_id");
4898
    print "Upgrade to $DBversion done (Added column branchcode to accountlines)\n";
4899
    SetVersion($DBversion);
4900
}
4901
4895
=head1 FUNCTIONS
4902
=head1 FUNCTIONS
4896
4903
4897
=head2 DropAllForeignKeys($table)
4904
=head2 DropAllForeignKeys($table)
4898
- 

Return to bug 7595