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 2558-2567 sub _FixAccountForLostAndReturned { Link Here
2558
    }
2558
    }
2559
    $amountleft *= -1 if ($amountleft > 0);
2559
    $amountleft *= -1 if ($amountleft > 0);
2560
    my $desc = "Item Returned " . $item_id;
2560
    my $desc = "Item Returned " . $item_id;
2561
    my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
2561
    $usth = $dbh->prepare("INSERT INTO accountlines
2562
    $usth = $dbh->prepare("INSERT INTO accountlines
2562
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
2563
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,branchcode)
2563
        VALUES (?,?,now(),?,?,'CR',?)");
2564
        VALUES (?,?,now(),?,?,'CR',?,?)");
2564
    $usth->execute($data->{'borrowernumber'},$nextaccntno,0-$amount,$desc,$amountleft);
2565
    $usth->execute( $data->{'borrowernumber'}, $nextaccntno, 0-$amount, $desc, $amountleft, $branchcode );
2565
    if ($borrowernumber) {
2566
    if ($borrowernumber) {
2566
        # FIXME: same as query above.  use 1 sth for both
2567
        # FIXME: same as query above.  use 1 sth for both
2567
        $usth = $dbh->prepare("INSERT INTO accountoffsets
2568
        $usth = $dbh->prepare("INSERT INTO accountoffsets
Lines 3113-3124 sub AddRenewal { Link Here
3113
        $sth = $dbh->prepare(
3114
        $sth = $dbh->prepare(
3114
                "INSERT INTO accountlines
3115
                "INSERT INTO accountlines
3115
                    (date, borrowernumber, accountno, amount, manager_id,
3116
                    (date, borrowernumber, accountno, amount, manager_id,
3116
                    description,accounttype, amountoutstanding, itemnumber)
3117
                    description,accounttype, amountoutstanding, itemnumber, branch)
3117
                    VALUES (now(),?,?,?,?,?,?,?,?)"
3118
                    VALUES (now(),?,?,?,?,?,?,?,?,?)"
3118
        );
3119
        );
3119
        $sth->execute( $borrowernumber, $accountno, $charge, $manager_id,
3120
        $sth->execute( $borrowernumber, $accountno, $charge, $manager_id,
3120
            "Renewal of Rental Item $item->{'title'} $item->{'barcode'}",
3121
            "Renewal of Rental Item $item->{'title'} $item->{'barcode'}",
3121
            'Rent', $charge, $itemnumber );
3122
            'Rent', $charge, $itemnumber, C4::Context->userenv->{'branch'} );
3122
    }
3123
    }
3123
3124
3124
    # Send a renewal slip according to checkout alert preferencei
3125
    # Send a renewal slip according to checkout alert preferencei
Lines 3365-3375 sub AddIssuingCharge { Link Here
3365
        INSERT INTO accountlines
3366
        INSERT INTO accountlines
3366
            (borrowernumber, itemnumber, accountno,
3367
            (borrowernumber, itemnumber, accountno,
3367
            date, amount, description, accounttype,
3368
            date, amount, description, accounttype,
3368
            amountoutstanding, manager_id)
3369
            amountoutstanding, manager_id, branchcode)
3369
        VALUES (?, ?, ?,now(), ?, 'Rental', 'Rent',?,?)
3370
        VALUES (?, ?, ?,now(), ?, 'Rental', 'Rent',?,?,?)
3370
    ";
3371
    ";
3371
    my $sth = $dbh->prepare($query);
3372
    my $sth = $dbh->prepare($query);
3372
    $sth->execute( $borrowernumber, $itemnumber, $nextaccntno, $charge, $charge, $manager_id );
3373
    $sth->execute( $borrowernumber, $itemnumber, $nextaccntno, $charge, $charge, $manager_id, C4::Context->userenv->{'branch'} );
3373
}
3374
}
3374
3375
3375
=head2 GetTransfers
3376
=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 2680-2685 CREATE TABLE `accountlines` ( Link Here
2680
  `notify_level` int(2) NOT NULL default 0,
2680
  `notify_level` int(2) NOT NULL default 0,
2681
  `note` text NULL default NULL,
2681
  `note` text NULL default NULL,
2682
  `manager_id` int(11) NULL,
2682
  `manager_id` int(11) NULL,
2683
  `branchcode` VARCHAR( 10 ) NULL DEFAULT NULL, -- the branchcode of the library where a payment was made, a manual invoice created, etc.
2683
  PRIMARY KEY (`accountlines_id`),
2684
  PRIMARY KEY (`accountlines_id`),
2684
  KEY `acctsborridx` (`borrowernumber`),
2685
  KEY `acctsborridx` (`borrowernumber`),
2685
  KEY `timeidx` (`timestamp`),
2686
  KEY `timeidx` (`timestamp`),
2686
- 

Return to bug 7595