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

(-)a/C4/Accounts.pm (-24 / +27 lines)
Lines 93-99 sub recordpayment { Link Here
93
    my $dbh        = C4::Context->dbh;
93
    my $dbh        = C4::Context->dbh;
94
    my $newamtos   = 0;
94
    my $newamtos   = 0;
95
    my $accdata    = "";
95
    my $accdata    = "";
96
    my $branch     = C4::Context->userenv->{'branch'};
96
    my $branch     = C4::Context->userenv ?
97
                         C4::Context->userenv->{'branch'} : undef;
97
    my $amountleft = $data;
98
    my $amountleft = $data;
98
    my $manager_id = 0;
99
    my $manager_id = 0;
99
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
100
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
Lines 149-161 sub recordpayment { Link Here
149
    # create new line
150
    # create new line
150
    my $usth = $dbh->prepare(
151
    my $usth = $dbh->prepare(
151
        "INSERT INTO accountlines
152
        "INSERT INTO accountlines
152
  (borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id, note)
153
  (borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id, note,branchcode)
153
  VALUES (?,?,now(),?,'',?,?,?,?)"
154
  VALUES (?,?,now(),?,'',?,?,?,?,?)"
154
    );
155
    );
155
156
156
    my $paytype = "Pay";
157
    my $paytype = "Pay";
157
    $paytype .= $sip_paytype if defined $sip_paytype;
158
    $paytype .= $sip_paytype if defined $sip_paytype;
158
    $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, $paytype, 0 - $amountleft, $manager_id, $payment_note );
159
    $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, $paytype, 0 - $amountleft, $manager_id, $payment_note, $branch );
159
    $usth->finish;
160
    $usth->finish;
160
161
161
    UpdateStats({
162
    UpdateStats({
Lines 244-253 sub makepayment { Link Here
244
        my $ins = 
245
        my $ins = 
245
            $dbh->prepare( 
246
            $dbh->prepare( 
246
                "INSERT 
247
                "INSERT 
247
                    INTO accountlines (borrowernumber, accountno, date, amount, itemnumber, description, accounttype, amountoutstanding, manager_id, note)
248
                    INTO accountlines (borrowernumber, accountno, date, amount, itemnumber, description, accounttype, amountoutstanding, manager_id, note, branchcode)
248
                    VALUES ( ?, ?, now(), ?, ?, '', 'Pay', 0, ?, ?)"
249
                    VALUES ( ?, ?, now(), ?, ?, 'Payment,thanks', 'Pay', 0, ?, ?, ?)"
249
            );
250
            );
250
        $ins->execute($borrowernumber, $nextaccntno, $payment, $data->{'itemnumber'}, $manager_id, $payment_note);
251
        $ins->execute($borrowernumber, $nextaccntno, $payment, $data->{'itemnumber'}, $manager_id, $payment_note,  C4::Context->userenv->{'branch'});
251
    }
252
    }
252
253
253
    if ( C4::Context->preference("FinesLog") ) {
254
    if ( C4::Context->preference("FinesLog") ) {
Lines 370-379 sub chargelostitem{ Link Here
370
        #  process (or person) to update it, since we don't handle any defaults for replacement prices.
371
        #  process (or person) to update it, since we don't handle any defaults for replacement prices.
371
        my $accountno = getnextacctno($borrowernumber);
372
        my $accountno = getnextacctno($borrowernumber);
372
        my $sth2=$dbh->prepare("INSERT INTO accountlines
373
        my $sth2=$dbh->prepare("INSERT INTO accountlines
373
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber,manager_id)
374
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber,manager_id,branchcode)
374
        VALUES (?,?,now(),?,?,'L',?,?,?)");
375
        VALUES (?,?,now(),?,?,'L',?,?,?,?)");
375
        $sth2->execute($borrowernumber,$accountno,$amount,
376
        my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
376
        $description,$amount,$itemnumber,$manager_id);
377
        $sth2->execute( $borrowernumber, $accountno, $amount, $description,
378
            $amount, $itemnumber, $manager_id, $branchcode );
377
379
378
        if ( C4::Context->preference("FinesLog") ) {
380
        if ( C4::Context->preference("FinesLog") ) {
379
            logaction("FINES", 'CREATE', $borrowernumber, Dumper({
381
            logaction("FINES", 'CREATE', $borrowernumber, Dumper({
Lines 422-427 sub manualinvoice { Link Here
422
    my ( $borrowernumber, $itemnum, $desc, $type, $amount, $note ) = @_;
424
    my ( $borrowernumber, $itemnum, $desc, $type, $amount, $note ) = @_;
423
    my $manager_id = 0;
425
    my $manager_id = 0;
424
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
426
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
427
    my $branchcode = C4::Context->userenv->{'branch'};
425
    my $dbh      = C4::Context->dbh;
428
    my $dbh      = C4::Context->dbh;
426
    my $notifyid = 0;
429
    my $notifyid = 0;
427
    my $insert;
430
    my $insert;
Lines 441-456 sub manualinvoice { Link Here
441
        $desc .= ' ' . $itemnum;
444
        $desc .= ' ' . $itemnum;
442
        my $sth = $dbh->prepare(
445
        my $sth = $dbh->prepare(
443
            'INSERT INTO  accountlines
446
            'INSERT INTO  accountlines
444
                        (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, itemnumber,notify_id, note, manager_id)
447
                        (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, itemnumber,notify_id, note, manager_id, branchcode)
445
        VALUES (?, ?, now(), ?,?, ?,?,?,?,?,?)');
448
        VALUES (?, ?, now(), ?,?, ?,?,?,?,?,?,?)');
446
     $sth->execute($borrowernumber, $accountno, $amount, $desc, $type, $amountleft, $itemnum,$notifyid, $note, $manager_id) || return $sth->errstr;
449
     $sth->execute($borrowernumber, $accountno, $amount, $desc, $type, $amountleft, $itemnum,$notifyid, $note, $manager_id, $branchcode) || return $sth->errstr;
447
  } else {
450
  } else {
448
    my $sth=$dbh->prepare("INSERT INTO  accountlines
451
    my $sth=$dbh->prepare("INSERT INTO  accountlines
449
            (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding,notify_id, note, manager_id)
452
            (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding,notify_id, note, manager_id, branchcode)
450
            VALUES (?, ?, now(), ?, ?, ?, ?,?,?,?)"
453
            VALUES (?, ?, now(), ?, ?, ?, ?,?,?,?,?)"
451
        );
454
        );
452
        $sth->execute( $borrowernumber, $accountno, $amount, $desc, $type,
455
        $sth->execute( $borrowernumber, $accountno, $amount, $desc, $type,
453
            $amountleft, $notifyid, $note, $manager_id );
456
            $amountleft, $notifyid, $note, $manager_id, $branchcode );
454
    }
457
    }
455
458
456
    if ( C4::Context->preference("FinesLog") ) {
459
    if ( C4::Context->preference("FinesLog") ) {
Lines 655-663 sub recordpayment_selectaccts { Link Here
655
658
656
    # create new line
659
    # create new line
657
    $sql = 'INSERT INTO accountlines ' .
660
    $sql = 'INSERT INTO accountlines ' .
658
    '(borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id,note) ' .
661
    '(borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id,note,branchcode) ' .
659
    q|VALUES (?,?,now(),?,'','Pay',?,?,?)|;
662
    q|VALUES (?,?,now(),?,'','Pay',?,?,?,?)|;
660
    $dbh->do($sql,{},$borrowernumber, $nextaccntno, 0 - $amount, 0 - $amountleft, $manager_id, $note );
663
    $dbh->do($sql,{},$borrowernumber, $nextaccntno, 0 - $amount, 0 - $amountleft, $manager_id, $note, $branch );
661
    UpdateStats({
664
    UpdateStats({
662
                branch => $branch,
665
                branch => $branch,
663
                type => 'payment',
666
                type => 'payment',
Lines 701-707 sub makepartialpayment { Link Here
701
        'SELECT * FROM accountlines WHERE  accountlines_id=?',undef,$accountlines_id);
704
        'SELECT * FROM accountlines WHERE  accountlines_id=?',undef,$accountlines_id);
702
    my $new_outstanding = $data->{amountoutstanding} - $amount;
705
    my $new_outstanding = $data->{amountoutstanding} - $amount;
703
706
704
    my $update = 'UPDATE  accountlines SET amountoutstanding = ?  WHERE   accountlines_id = ? ';
707
    my $update = 'UPDATE accountlines SET amountoutstanding = ? WHERE accountlines_id = ? ';
705
    $dbh->do( $update, undef, $new_outstanding, $accountlines_id);
708
    $dbh->do( $update, undef, $new_outstanding, $accountlines_id);
706
709
707
    if ( C4::Context->preference("FinesLog") ) {
710
    if ( C4::Context->preference("FinesLog") ) {
Lines 719-729 sub makepartialpayment { Link Here
719
722
720
    # create new line
723
    # create new line
721
    my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, '
724
    my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, '
722
    .  'description, accounttype, amountoutstanding, itemnumber, manager_id, note) '
725
    .  'description, accounttype, amountoutstanding, itemnumber, manager_id, note, branchcode) '
723
    . ' VALUES (?, ?, now(), ?, ?, ?, 0, ?, ?, ?)';
726
    . ' VALUES (?, ?, now(), ?, ?, ?, 0, ?, ?, ?, ?)';
724
727
725
    $dbh->do(  $insert, undef, $borrowernumber, $nextaccntno, $amount,
728
    $dbh->do(  $insert, undef, $borrowernumber, $nextaccntno, $amount,
726
        '', 'Pay', $data->{'itemnumber'}, $manager_id, $payment_note);
729
        '', 'Pay', $data->{'itemnumber'}, $manager_id, $payment_note, C4::Context->userenv->{'branch'});
727
730
728
    UpdateStats({
731
    UpdateStats({
729
                branch => $user,
732
                branch => $user,
(-)a/C4/Circulation.pm (-9 / +9 lines)
Lines 2323-2331 sub _FixAccountForLostAndReturned { Link Here
2323
    $amountleft *= -1 if ($amountleft > 0);
2323
    $amountleft *= -1 if ($amountleft > 0);
2324
    my $desc = "Item Returned " . $item_id;
2324
    my $desc = "Item Returned " . $item_id;
2325
    $usth = $dbh->prepare("INSERT INTO accountlines
2325
    $usth = $dbh->prepare("INSERT INTO accountlines
2326
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
2326
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,branchcode)
2327
        VALUES (?,?,now(),?,?,'CR',?)");
2327
        VALUES (?,?,now(),?,?,'CR',?,?)");
2328
    $usth->execute($data->{'borrowernumber'},$nextaccntno,0-$amount,$desc,$amountleft);
2328
    $usth->execute($data->{'borrowernumber'},$nextaccntno,0-$amount,$desc,$amountleft,C4::Context->userenv->{'branch'});
2329
    if ($borrowernumber) {
2329
    if ($borrowernumber) {
2330
        # FIXME: same as query above.  use 1 sth for both
2330
        # FIXME: same as query above.  use 1 sth for both
2331
        $usth = $dbh->prepare("INSERT INTO accountoffsets
2331
        $usth = $dbh->prepare("INSERT INTO accountoffsets
Lines 2836-2847 sub AddRenewal { Link Here
2836
        $sth = $dbh->prepare(
2836
        $sth = $dbh->prepare(
2837
                "INSERT INTO accountlines
2837
                "INSERT INTO accountlines
2838
                    (date, borrowernumber, accountno, amount, manager_id,
2838
                    (date, borrowernumber, accountno, amount, manager_id,
2839
                    description,accounttype, amountoutstanding, itemnumber)
2839
                    description,accounttype, amountoutstanding, itemnumber, branch)
2840
                    VALUES (now(),?,?,?,?,?,?,?,?)"
2840
                    VALUES (now(),?,?,?,?,?,?,?,?,?)"
2841
        );
2841
        );
2842
        $sth->execute( $borrowernumber, $accountno, $charge, $manager_id,
2842
        $sth->execute( $borrowernumber, $accountno, $charge, $manager_id,
2843
            "Renewal of Rental Item $item->{'title'} $item->{'barcode'}",
2843
            "Renewal of Rental Item $item->{'title'} $item->{'barcode'}",
2844
            'Rent', $charge, $itemnumber );
2844
            'Rent', $charge, $itemnumber, C4::Context->userenv->{'branch'} );
2845
    }
2845
    }
2846
2846
2847
    # Send a renewal slip according to checkout alert preferencei
2847
    # Send a renewal slip according to checkout alert preferencei
Lines 3081-3091 sub AddIssuingCharge { Link Here
3081
        INSERT INTO accountlines
3081
        INSERT INTO accountlines
3082
            (borrowernumber, itemnumber, accountno,
3082
            (borrowernumber, itemnumber, accountno,
3083
            date, amount, description, accounttype,
3083
            date, amount, description, accounttype,
3084
            amountoutstanding, manager_id)
3084
            amountoutstanding, manager_id, branchcode)
3085
        VALUES (?, ?, ?,now(), ?, 'Rental', 'Rent',?,?)
3085
        VALUES (?, ?, ?,now(), ?, 'Rental', 'Rent',?,?,?)
3086
    ";
3086
    ";
3087
    my $sth = $dbh->prepare($query);
3087
    my $sth = $dbh->prepare($query);
3088
    $sth->execute( $borrowernumber, $itemnumber, $nextaccntno, $charge, $charge, $manager_id );
3088
    $sth->execute( $borrowernumber, $itemnumber, $nextaccntno, $charge, $charge, $manager_id, C4::Context->userenv->{'branch'} );
3089
}
3089
}
3090
3090
3091
=head2 GetTransfers
3091
=head2 GetTransfers
(-)a/C4/Overdues.pm (-4 / +5 lines)
Lines 592-602 sub UpdateFine { Link Here
592
            my $desc = ( $type ? "$type " : '' ) . "$title $due";    # FIXEDME, avoid whitespace prefix on empty $type
592
            my $desc = ( $type ? "$type " : '' ) . "$title $due";    # FIXEDME, avoid whitespace prefix on empty $type
593
593
594
            my $query = "INSERT INTO accountlines
594
            my $query = "INSERT INTO accountlines
595
                         (borrowernumber,itemnumber,date,amount,description,accounttype,amountoutstanding,lastincrement,accountno)
595
                         (borrowernumber,itemnumber,date,amount,description,accounttype,amountoutstanding,lastincrement,accountno,branchcode)
596
                         VALUES (?,?,now(),?,?,'FU',?,?,?)";
596
                         VALUES (?,?,now(),?,?,'FU',?,?,?,?)";
597
            my $sth2 = $dbh->prepare($query);
597
            my $sth2 = $dbh->prepare($query);
598
            $debug and print STDERR "UpdateFine query: $query\nw/ args: $borrowernumber, $itemnum, $amount, $desc, $amount, $amount, $nextaccntno\n";
598
            my $branch = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
599
            $sth2->execute( $borrowernumber, $itemnum, $amount, $desc, $amount, $amount, $nextaccntno );
599
            $debug and print STDERR "UpdateFine query: $query\nw/ args: $borrowernumber, $itemnum, $amount, $desc, $amount, $amount, $nextaccntno, $branch\n";
600
            $sth2->execute( $borrowernumber, $itemnum, $amount, $desc, $amount, $amount, $nextaccntno, $branch );
600
        }
601
        }
601
    }
602
    }
602
    # logging action
603
    # logging action
(-)a/C4/Reserves.pm (-3 / +3 lines)
Lines 185-197 sub AddReserve { Link Here
185
        my $nextacctno = &getnextacctno( $borrowernumber );
185
        my $nextacctno = &getnextacctno( $borrowernumber );
186
        my $query      = qq{
186
        my $query      = qq{
187
        INSERT INTO accountlines
187
        INSERT INTO accountlines
188
            (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
188
            (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,branchcode)
189
        VALUES
189
        VALUES
190
            (?,?,now(),?,?,'Res',?)
190
            (?,?,now(),?,?,'Res',?,?)
191
    };
191
    };
192
        my $usth = $dbh->prepare($query);
192
        my $usth = $dbh->prepare($query);
193
        $usth->execute( $borrowernumber, $nextacctno, $fee,
193
        $usth->execute( $borrowernumber, $nextacctno, $fee,
194
            "Reserve Charge - $title", $fee );
194
            "Reserve Charge - $title", $fee, C4::Context->userenv->{'branch'} );
195
    }
195
    }
196
196
197
    #if ($const eq 'a'){
197
    #if ($const eq 'a'){
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 2740-2745 CREATE TABLE `accountlines` ( Link Here
2740
  `notify_level` int(2) NOT NULL default 0,
2740
  `notify_level` int(2) NOT NULL default 0,
2741
  `note` text NULL default NULL,
2741
  `note` text NULL default NULL,
2742
  `manager_id` int(11) NULL,
2742
  `manager_id` int(11) NULL,
2743
  `branchcode` VARCHAR( 10 ) NULL DEFAULT NULL, -- the branchcode of the library where a payment was made, a manual invoice created, etc.
2743
  PRIMARY KEY (`accountlines_id`),
2744
  PRIMARY KEY (`accountlines_id`),
2744
  KEY `acctsborridx` (`borrowernumber`),
2745
  KEY `acctsborridx` (`borrowernumber`),
2745
  KEY `timeidx` (`timestamp`),
2746
  KEY `timeidx` (`timestamp`),
(-)a/installer/data/mysql/updatedatabase.pl (-1 / +8 lines)
Lines 10035-10040 if ( CheckVersion($DBversion) ) { Link Here
10035
    SetVersion ($DBversion);
10035
    SetVersion ($DBversion);
10036
}
10036
}
10037
10037
10038
$DBversion = "3.19.00.XXX";
10039
if ( CheckVersion($DBversion) ) {
10040
    $dbh->do("ALTER TABLE accountlines ADD branchcode VARCHAR( 10 ) NULL DEFAULT NULL AFTER manager_id");
10041
    print "Upgrade to $DBversion done (Added column branchcode to accountlines)\n";
10042
    SetVersion($DBversion);
10043
}
10044
10038
# DEVELOPER PROCESS, search for anything to execute in the db_update directory
10045
# DEVELOPER PROCESS, search for anything to execute in the db_update directory
10039
# SEE bug 13068
10046
# SEE bug 13068
10040
# if there is anything in the atomicupdate, read and execute it.
10047
# if there is anything in the atomicupdate, read and execute it.
Lines 10048-10053 while ( my $file = readdir $dirh ) { Link Here
10048
    my $rv = $installer->load_sql( $update_dir . $file ) ? 0 : 1;
10055
    my $rv = $installer->load_sql( $update_dir . $file ) ? 0 : 1;
10049
}
10056
}
10050
10057
10058
10051
=head1 FUNCTIONS
10059
=head1 FUNCTIONS
10052
10060
10053
=head2 TableExists($table)
10061
=head2 TableExists($table)
10054
- 

Return to bug 7595