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

(-)a/C4/Accounts.pm (-25 / +29 lines)
Lines 92-98 sub recordpayment { Link Here
92
    my $dbh        = C4::Context->dbh;
92
    my $dbh        = C4::Context->dbh;
93
    my $newamtos   = 0;
93
    my $newamtos   = 0;
94
    my $accdata    = "";
94
    my $accdata    = "";
95
    my $branch     = C4::Context->userenv->{'branch'};
95
    my $branch     = C4::Context->userenv ?
96
                         C4::Context->userenv->{'branch'} : undef;
96
    my $amountleft = $data;
97
    my $amountleft = $data;
97
    my $manager_id = 0;
98
    my $manager_id = 0;
98
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
99
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
Lines 148-160 sub recordpayment { Link Here
148
    # create new line
149
    # create new line
149
    my $usth = $dbh->prepare(
150
    my $usth = $dbh->prepare(
150
        "INSERT INTO accountlines
151
        "INSERT INTO accountlines
151
  (borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id, note)
152
  (borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id, note,branchcode)
152
  VALUES (?,?,now(),?,'',?,?,?,?)"
153
  VALUES (?,?,now(),?,'',?,?,?,?,?)"
153
    );
154
    );
154
155
155
    my $paytype = "Pay";
156
    my $paytype = "Pay";
156
    $paytype .= $sip_paytype if defined $sip_paytype;
157
    $paytype .= $sip_paytype if defined $sip_paytype;
157
    $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, $paytype, 0 - $amountleft, $manager_id, $payment_note );
158
    $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, $paytype, 0 - $amountleft, $manager_id, $payment_note, $branch );
158
    $usth->finish;
159
    $usth->finish;
159
160
160
    UpdateStats({
161
    UpdateStats({
Lines 243-252 sub makepayment { Link Here
243
        my $ins = 
244
        my $ins = 
244
            $dbh->prepare( 
245
            $dbh->prepare( 
245
                "INSERT 
246
                "INSERT 
246
                    INTO accountlines (borrowernumber, accountno, date, amount, itemnumber, description, accounttype, amountoutstanding, manager_id, note)
247
                    INTO accountlines (borrowernumber, accountno, date, amount, itemnumber, description, accounttype, amountoutstanding, manager_id, note, branchcode)
247
                    VALUES ( ?, ?, now(), ?, ?, '', 'Pay', 0, ?, ?)"
248
                    VALUES ( ?, ?, now(), ?, ?, 'Payment,thanks', 'Pay', 0, ?, ?, ?)"
248
            );
249
            );
249
        $ins->execute($borrowernumber, $nextaccntno, $payment, $data->{'itemnumber'}, $manager_id, $payment_note);
250
        my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
251
        $ins->execute($borrowernumber, $nextaccntno, $payment, $data->{'itemnumber'}, $manager_id, $payment_note, $branchcode);
250
    }
252
    }
251
253
252
    if ( C4::Context->preference("FinesLog") ) {
254
    if ( C4::Context->preference("FinesLog") ) {
Lines 369-378 sub chargelostitem{ Link Here
369
        #  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.
370
        my $accountno = getnextacctno($borrowernumber);
372
        my $accountno = getnextacctno($borrowernumber);
371
        my $sth2=$dbh->prepare("INSERT INTO accountlines
373
        my $sth2=$dbh->prepare("INSERT INTO accountlines
372
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber,manager_id)
374
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber,manager_id,branchcode)
373
        VALUES (?,?,now(),?,?,'L',?,?,?)");
375
        VALUES (?,?,now(),?,?,'L',?,?,?,?)");
374
        $sth2->execute($borrowernumber,$accountno,$amount,
376
        my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
375
        $description,$amount,$itemnumber,$manager_id);
377
        $sth2->execute( $borrowernumber, $accountno, $amount, $description,
378
            $amount, $itemnumber, $manager_id, $branchcode );
376
379
377
        if ( C4::Context->preference("FinesLog") ) {
380
        if ( C4::Context->preference("FinesLog") ) {
378
            logaction("FINES", 'CREATE', $borrowernumber, Dumper({
381
            logaction("FINES", 'CREATE', $borrowernumber, Dumper({
Lines 421-426 sub manualinvoice { Link Here
421
    my ( $borrowernumber, $itemnum, $desc, $type, $amount, $note ) = @_;
424
    my ( $borrowernumber, $itemnum, $desc, $type, $amount, $note ) = @_;
422
    my $manager_id = 0;
425
    my $manager_id = 0;
423
    $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 ? C4::Context->userenv->{'branch'} : undef;
424
    my $dbh      = C4::Context->dbh;
428
    my $dbh      = C4::Context->dbh;
425
    my $notifyid = 0;
429
    my $notifyid = 0;
426
    my $insert;
430
    my $insert;
Lines 440-455 sub manualinvoice { Link Here
440
        $desc .= ' ' . $itemnum;
444
        $desc .= ' ' . $itemnum;
441
        my $sth = $dbh->prepare(
445
        my $sth = $dbh->prepare(
442
            'INSERT INTO  accountlines
446
            'INSERT INTO  accountlines
443
                        (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)
444
        VALUES (?, ?, now(), ?,?, ?,?,?,?,?,?)');
448
        VALUES (?, ?, now(), ?,?, ?,?,?,?,?,?,?)');
445
     $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;
446
  } else {
450
  } else {
447
    my $sth=$dbh->prepare("INSERT INTO  accountlines
451
    my $sth=$dbh->prepare("INSERT INTO  accountlines
448
            (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)
449
            VALUES (?, ?, now(), ?, ?, ?, ?,?,?,?)"
453
            VALUES (?, ?, now(), ?, ?, ?, ?,?,?,?,?)"
450
        );
454
        );
451
        $sth->execute( $borrowernumber, $accountno, $amount, $desc, $type,
455
        $sth->execute( $borrowernumber, $accountno, $amount, $desc, $type,
452
            $amountleft, $notifyid, $note, $manager_id );
456
            $amountleft, $notifyid, $note, $manager_id, $branchcode );
453
    }
457
    }
454
458
455
    if ( C4::Context->preference("FinesLog") ) {
459
    if ( C4::Context->preference("FinesLog") ) {
Lines 599-605 sub recordpayment_selectaccts { Link Here
599
    my $dbh        = C4::Context->dbh;
603
    my $dbh        = C4::Context->dbh;
600
    my $newamtos   = 0;
604
    my $newamtos   = 0;
601
    my $accdata    = q{};
605
    my $accdata    = q{};
602
    my $branch     = C4::Context->userenv->{branch};
606
    my $branch     = C4::Context->userenv ? C4::Context->userenv->{branch} : undef;
603
    my $amountleft = $amount;
607
    my $amountleft = $amount;
604
    my $manager_id = 0;
608
    my $manager_id = 0;
605
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
609
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
Lines 654-662 sub recordpayment_selectaccts { Link Here
654
658
655
    # create new line
659
    # create new line
656
    $sql = 'INSERT INTO accountlines ' .
660
    $sql = 'INSERT INTO accountlines ' .
657
    '(borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id,note) ' .
661
    '(borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id,note,branchcode) ' .
658
    q|VALUES (?,?,now(),?,'','Pay',?,?,?)|;
662
    q|VALUES (?,?,now(),?,'','Pay',?,?,?,?)|;
659
    $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 );
660
    UpdateStats({
664
    UpdateStats({
661
                branch => $branch,
665
                branch => $branch,
662
                type => 'payment',
666
                type => 'payment',
Lines 700-706 sub makepartialpayment { Link Here
700
        'SELECT * FROM accountlines WHERE  accountlines_id=?',undef,$accountlines_id);
704
        'SELECT * FROM accountlines WHERE  accountlines_id=?',undef,$accountlines_id);
701
    my $new_outstanding = $data->{amountoutstanding} - $amount;
705
    my $new_outstanding = $data->{amountoutstanding} - $amount;
702
706
703
    my $update = 'UPDATE  accountlines SET amountoutstanding = ?  WHERE   accountlines_id = ? ';
707
    my $update = 'UPDATE accountlines SET amountoutstanding = ? WHERE accountlines_id = ? ';
704
    $dbh->do( $update, undef, $new_outstanding, $accountlines_id);
708
    $dbh->do( $update, undef, $new_outstanding, $accountlines_id);
705
709
706
    if ( C4::Context->preference("FinesLog") ) {
710
    if ( C4::Context->preference("FinesLog") ) {
Lines 718-728 sub makepartialpayment { Link Here
718
722
719
    # create new line
723
    # create new line
720
    my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, '
724
    my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, '
721
    .  'description, accounttype, amountoutstanding, itemnumber, manager_id, note) '
725
    .  'description, accounttype, amountoutstanding, itemnumber, manager_id, note, branchcode) '
722
    . ' VALUES (?, ?, now(), ?, ?, ?, 0, ?, ?, ?)';
726
    . ' VALUES (?, ?, now(), ?, ?, ?, 0, ?, ?, ?, ?)';
723
727
724
    $dbh->do(  $insert, undef, $borrowernumber, $nextaccntno, $amount,
728
    $dbh->do(  $insert, undef, $borrowernumber, $nextaccntno, $amount,
725
        '', 'Pay', $data->{'itemnumber'}, $manager_id, $payment_note);
729
        '', 'Pay', $data->{'itemnumber'}, $manager_id, $payment_note, C4::Context->userenv->{'branch'});
726
730
727
    UpdateStats({
731
    UpdateStats({
728
        branch => $branch,
732
        branch => $branch,
(-)a/C4/Circulation.pm (-9 / +10 lines)
Lines 2525-2534 sub _FixAccountForLostAndReturned { Link Here
2525
    }
2525
    }
2526
    $amountleft *= -1 if ($amountleft > 0);
2526
    $amountleft *= -1 if ($amountleft > 0);
2527
    my $desc = "Item Returned " . $item_id;
2527
    my $desc = "Item Returned " . $item_id;
2528
    my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
2528
    $usth = $dbh->prepare("INSERT INTO accountlines
2529
    $usth = $dbh->prepare("INSERT INTO accountlines
2529
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
2530
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,branchcode)
2530
        VALUES (?,?,now(),?,?,'CR',?)");
2531
        VALUES (?,?,now(),?,?,'CR',?,?)");
2531
    $usth->execute($data->{'borrowernumber'},$nextaccntno,0-$amount,$desc,$amountleft);
2532
    $usth->execute( $data->{'borrowernumber'}, $nextaccntno, 0-$amount, $desc, $amountleft, $branchcode );
2532
    if ($borrowernumber) {
2533
    if ($borrowernumber) {
2533
        # FIXME: same as query above.  use 1 sth for both
2534
        # FIXME: same as query above.  use 1 sth for both
2534
        $usth = $dbh->prepare("INSERT INTO accountoffsets
2535
        $usth = $dbh->prepare("INSERT INTO accountoffsets
Lines 3080-3091 sub AddRenewal { Link Here
3080
        $sth = $dbh->prepare(
3081
        $sth = $dbh->prepare(
3081
                "INSERT INTO accountlines
3082
                "INSERT INTO accountlines
3082
                    (date, borrowernumber, accountno, amount, manager_id,
3083
                    (date, borrowernumber, accountno, amount, manager_id,
3083
                    description,accounttype, amountoutstanding, itemnumber)
3084
                    description,accounttype, amountoutstanding, itemnumber, branch)
3084
                    VALUES (now(),?,?,?,?,?,?,?,?)"
3085
                    VALUES (now(),?,?,?,?,?,?,?,?,?)"
3085
        );
3086
        );
3086
        $sth->execute( $borrowernumber, $accountno, $charge, $manager_id,
3087
        $sth->execute( $borrowernumber, $accountno, $charge, $manager_id,
3087
            "Renewal of Rental Item $item->{'title'} $item->{'barcode'}",
3088
            "Renewal of Rental Item $item->{'title'} $item->{'barcode'}",
3088
            'Rent', $charge, $itemnumber );
3089
            'Rent', $charge, $itemnumber, C4::Context->userenv->{'branch'} );
3089
    }
3090
    }
3090
3091
3091
    # Send a renewal slip according to checkout alert preferencei
3092
    # Send a renewal slip according to checkout alert preferencei
Lines 3332-3342 sub AddIssuingCharge { Link Here
3332
        INSERT INTO accountlines
3333
        INSERT INTO accountlines
3333
            (borrowernumber, itemnumber, accountno,
3334
            (borrowernumber, itemnumber, accountno,
3334
            date, amount, description, accounttype,
3335
            date, amount, description, accounttype,
3335
            amountoutstanding, manager_id)
3336
            amountoutstanding, manager_id, branchcode)
3336
        VALUES (?, ?, ?,now(), ?, 'Rental', 'Rent',?,?)
3337
        VALUES (?, ?, ?,now(), ?, 'Rental', 'Rent',?,?,?)
3337
    ";
3338
    ";
3338
    my $sth = $dbh->prepare($query);
3339
    my $sth = $dbh->prepare($query);
3339
    $sth->execute( $borrowernumber, $itemnumber, $nextaccntno, $charge, $charge, $manager_id );
3340
    $sth->execute( $borrowernumber, $itemnumber, $nextaccntno, $charge, $charge, $manager_id, C4::Context->userenv->{'branch'} );
3340
}
3341
}
3341
3342
3342
=head2 GetTransfers
3343
=head2 GetTransfers
(-)a/C4/Overdues.pm (+2 lines)
Lines 603-608 sub UpdateFine { Link Here
603
603
604
            my $desc = ( $type ? "$type " : '' ) . "$title $due";    # FIXEDME, avoid whitespace prefix on empty $type
604
            my $desc = ( $type ? "$type " : '' ) . "$title $due";    # FIXEDME, avoid whitespace prefix on empty $type
605
605
606
            my $branchcode  = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
606
            my $accountline = Koha::Account::Line->new(
607
            my $accountline = Koha::Account::Line->new(
607
                {
608
                {
608
                    borrowernumber    => $borrowernumber,
609
                    borrowernumber    => $borrowernumber,
Lines 615-620 sub UpdateFine { Link Here
615
                    lastincrement     => $amount,
616
                    lastincrement     => $amount,
616
                    accountno         => $nextaccntno,
617
                    accountno         => $nextaccntno,
617
                    issue_id          => $issue_id,
618
                    issue_id          => $issue_id,
619
                    branchcode        => $branchcode,
618
                }
620
                }
619
            )->store();
621
            )->store();
620
        }
622
        }
(-)a/C4/Reserves.pm (+4 lines)
Lines 196-201 sub AddReserve { Link Here
196
    # Don't add itemtype limit if specific item is selected
196
    # Don't add itemtype limit if specific item is selected
197
    $itemtype = undef if $checkitem;
197
    $itemtype = undef if $checkitem;
198
198
199
    # Get the logged in library if there is one
200
    my $branchcode  = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
201
199
    # updates take place here
202
    # updates take place here
200
    my $hold = Koha::Hold->new(
203
    my $hold = Koha::Hold->new(
201
        {
204
        {
Lines 210-215 sub AddReserve { Link Here
210
            waitingdate    => $waitingdate,
213
            waitingdate    => $waitingdate,
211
            expirationdate => $expdate,
214
            expirationdate => $expdate,
212
            itemtype       => $itemtype,
215
            itemtype       => $itemtype,
216
            branchcode     => $branchcode,
213
        }
217
        }
214
    )->store();
218
    )->store();
215
    my $reserve_id = $hold->id();
219
    my $reserve_id = $hold->id();
(-)a/installer/data/mysql/atomicupdate/bug_7595.sql (+1 lines)
Line 0 Link Here
1
ALTER TABLE accountlines ADD branchcode VARCHAR( 10 ) NULL DEFAULT NULL AFTER manager_id;
(-)a/installer/data/mysql/kohastructure.sql (-1 / +1 lines)
Lines 2666-2671 CREATE TABLE `accountlines` ( Link Here
2666
  `notify_level` int(2) NOT NULL default 0,
2666
  `notify_level` int(2) NOT NULL default 0,
2667
  `note` text NULL default NULL,
2667
  `note` text NULL default NULL,
2668
  `manager_id` int(11) NULL,
2668
  `manager_id` int(11) NULL,
2669
  `branchcode` VARCHAR( 10 ) NULL DEFAULT NULL, -- the branchcode of the library where a payment was made, a manual invoice created, etc.
2669
  PRIMARY KEY (`accountlines_id`),
2670
  PRIMARY KEY (`accountlines_id`),
2670
  KEY `acctsborridx` (`borrowernumber`),
2671
  KEY `acctsborridx` (`borrowernumber`),
2671
  KEY `timeidx` (`timestamp`),
2672
  KEY `timeidx` (`timestamp`),
2672
- 

Return to bug 7595