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

(-)a/C4/Accounts.pm (-27 / +49 lines)
Lines 144-153 sub recordpayment { Link Here
144
    # create new line
144
    # create new line
145
    my $usth = $dbh->prepare(
145
    my $usth = $dbh->prepare(
146
        "INSERT INTO accountlines
146
        "INSERT INTO accountlines
147
  (borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id)
147
  (borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id,branchcode)
148
  VALUES (?,?,now(),?,'Payment,thanks','Pay',?,?)"
148
  VALUES (?,?,now(),?,'Payment,thanks','Pay',?,?,?)"
149
    );
149
    );
150
    $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, 0 - $amountleft, $manager_id );
150
151
    $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, 0 - $amountleft, $manager_id, $branch );
151
152
152
    UpdateStats( $branch, 'payment', $data, '', '', '', $borrowernumber, $nextaccntno );
153
    UpdateStats( $branch, 'payment', $data, '', '', '', $borrowernumber, $nextaccntno );
153
154
Lines 229-238 sub makepayment { Link Here
229
        my $ins = 
230
        my $ins = 
230
            $dbh->prepare( 
231
            $dbh->prepare( 
231
                "INSERT 
232
                "INSERT 
232
                    INTO accountlines (borrowernumber, accountno, date, amount, itemnumber, description, accounttype, amountoutstanding, manager_id, note)
233
                    INTO accountlines (borrowernumber, accountno, date, amount, itemnumber, description, accounttype, amountoutstanding, manager_id, note, branchcode)
233
                    VALUES ( ?, ?, now(), ?, ?, 'Payment,thanks', 'Pay', 0, ?, ?)"
234
                    VALUES ( ?, ?, now(), ?, ?, 'Payment,thanks', 'Pay', 0, ?, ?, ?)"
234
            );
235
            );
235
        $ins->execute($borrowernumber, $nextaccntno, $payment, $data->{'itemnumber'}, $manager_id, $payment_note);
236
        $ins->execute($borrowernumber, $nextaccntno, $payment, $data->{'itemnumber'}, $manager_id, $payment_note,  C4::Context->userenv->{'branch'});
236
    }
237
    }
237
238
238
    if ( C4::Context->preference("FinesLog") ) {
239
    if ( C4::Context->preference("FinesLog") ) {
Lines 354-363 sub chargelostitem{ Link Here
354
        #  process (or person) to update it, since we don't handle any defaults for replacement prices.
355
        #  process (or person) to update it, since we don't handle any defaults for replacement prices.
355
        my $accountno = getnextacctno($borrowernumber);
356
        my $accountno = getnextacctno($borrowernumber);
356
        my $sth2=$dbh->prepare("INSERT INTO accountlines
357
        my $sth2=$dbh->prepare("INSERT INTO accountlines
357
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber,manager_id)
358
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber,manager_id,branchcode)
358
        VALUES (?,?,now(),?,?,'L',?,?,?)");
359
        VALUES (?,?,now(),?,?,'L',?,?,?,?)");
359
        $sth2->execute($borrowernumber,$accountno,$amount,
360
        my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
360
        $description,$amount,$itemnumber,$manager_id);
361
        $sth2->execute( $borrowernumber, $accountno, $amount, $description,
362
            $amount, $itemnumber, $manager_id, $branchcode );
361
363
362
        if ( C4::Context->preference("FinesLog") ) {
364
        if ( C4::Context->preference("FinesLog") ) {
363
            logaction("FINES", 'CREATE', $borrowernumber, Dumper({
365
            logaction("FINES", 'CREATE', $borrowernumber, Dumper({
Lines 406-411 sub manualinvoice { Link Here
406
    my ( $borrowernumber, $itemnum, $desc, $type, $amount, $note ) = @_;
408
    my ( $borrowernumber, $itemnum, $desc, $type, $amount, $note ) = @_;
407
    my $manager_id = 0;
409
    my $manager_id = 0;
408
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
410
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
411
    my $branchcode = C4::Context->userenv->{'branch'};
409
    my $dbh      = C4::Context->dbh;
412
    my $dbh      = C4::Context->dbh;
410
    my $notifyid = 0;
413
    my $notifyid = 0;
411
    my $insert;
414
    my $insert;
Lines 442-457 sub manualinvoice { Link Here
442
        $desc .= ' ' . $itemnum;
445
        $desc .= ' ' . $itemnum;
443
        my $sth = $dbh->prepare(
446
        my $sth = $dbh->prepare(
444
            'INSERT INTO  accountlines
447
            'INSERT INTO  accountlines
445
                        (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, itemnumber,notify_id, note, manager_id)
448
                        (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, itemnumber,notify_id, note, manager_id, branchcode)
446
        VALUES (?, ?, now(), ?,?, ?,?,?,?,?,?)');
449
        VALUES (?, ?, now(), ?,?, ?,?,?,?,?,?,?)');
447
     $sth->execute($borrowernumber, $accountno, $amount, $desc, $type, $amountleft, $itemnum,$notifyid, $note, $manager_id) || return $sth->errstr;
450
     $sth->execute($borrowernumber, $accountno, $amount, $desc, $type, $amountleft, $itemnum,$notifyid, $note, $manager_id, $branchcode) || return $sth->errstr;
448
  } else {
451
  } else {
449
    my $sth=$dbh->prepare("INSERT INTO  accountlines
452
    my $sth=$dbh->prepare("INSERT INTO  accountlines
450
            (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding,notify_id, note, manager_id)
453
            (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding,notify_id, note, manager_id, branchcode)
451
            VALUES (?, ?, now(), ?, ?, ?, ?,?,?,?)"
454
            VALUES (?, ?, now(), ?, ?, ?, ?,?,?,?,?)"
452
        );
455
        );
453
        $sth->execute( $borrowernumber, $accountno, $amount, $desc, $type,
456
        $sth->execute( $borrowernumber, $accountno, $amount, $desc, $type,
454
            $amountleft, $notifyid, $note, $manager_id );
457
            $amountleft, $notifyid, $note, $manager_id, $branchcode );
455
    }
458
    }
456
459
457
    if ( C4::Context->preference("FinesLog") ) {
460
    if ( C4::Context->preference("FinesLog") ) {
Lines 655-664 sub recordpayment_selectaccts { Link Here
655
    }
658
    }
656
659
657
    # create new line
660
    # create new line
658
    $sql = 'INSERT INTO accountlines ' .
661
    $sql = q{
659
    '(borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id,note) ' .
662
        INSERT INTO accountlines (
660
    q|VALUES (?,?,now(),?,'Payment,thanks','Pay',?,?,?)|;
663
            borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, manager_id, note, branchcode
661
    $dbh->do($sql,{},$borrowernumber, $nextaccntno, 0 - $amount, 0 - $amountleft, $manager_id, $note );
664
        ) VALUES (
665
            ?, ?, NOW(), ?, 'Payment,thanks', 'Pay', ?, ?, ?, ?
666
        )
667
    };
668
    $dbh->do(
669
        $sql, {}, $borrowernumber,
670
        $nextaccntno, 0 - $amount, 0 - $amountleft,
671
        $manager_id,  $note,       $branch
672
    );
673
662
    UpdateStats( $branch, 'payment', $amount, '', '', '', $borrowernumber, $nextaccntno );
674
    UpdateStats( $branch, 'payment', $amount, '', '', '', $borrowernumber, $nextaccntno );
663
675
664
    if ( C4::Context->preference("FinesLog") ) {
676
    if ( C4::Context->preference("FinesLog") ) {
Lines 696-702 sub makepartialpayment { Link Here
696
        'SELECT * FROM accountlines WHERE  accountlines_id=?',undef,$accountlines_id);
708
        'SELECT * FROM accountlines WHERE  accountlines_id=?',undef,$accountlines_id);
697
    my $new_outstanding = $data->{amountoutstanding} - $amount;
709
    my $new_outstanding = $data->{amountoutstanding} - $amount;
698
710
699
    my $update = 'UPDATE  accountlines SET amountoutstanding = ?  WHERE   accountlines_id = ? ';
711
    my $update = 'UPDATE accountlines SET amountoutstanding = ? WHERE accountlines_id = ? ';
700
    $dbh->do( $update, undef, $new_outstanding, $accountlines_id);
712
    $dbh->do( $update, undef, $new_outstanding, $accountlines_id);
701
713
702
    if ( C4::Context->preference("FinesLog") ) {
714
    if ( C4::Context->preference("FinesLog") ) {
Lines 713-724 sub makepartialpayment { Link Here
713
    }
725
    }
714
726
715
    # create new line
727
    # create new line
716
    my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, '
728
    my $insert = q{
717
    .  'description, accounttype, amountoutstanding, itemnumber, manager_id, note) '
729
        INSERT INTO accountlines (
718
    . ' VALUES (?, ?, now(), ?, ?, ?, 0, ?, ?, ?)';
730
            borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, itemnumber, manager_id, note, branchcode
719
731
        ) VALUES (
720
    $dbh->do(  $insert, undef, $borrowernumber, $nextaccntno, $amount,
732
            ?, ?, NOW(), ?, ?, ?, 0, ?, ?, ?, ?
721
        "Payment, thanks - $user", 'Pay', $data->{'itemnumber'}, $manager_id, $payment_note);
733
        )
734
    };
735
736
    $dbh->do(
737
        $insert,         undef,
738
        $borrowernumber, $nextaccntno,
739
        $amount,         "Payment, thanks - $user",
740
        'Pay',           $data->{'itemnumber'},
741
        $manager_id,     $payment_note,
742
        C4::Context->userenv->{'branch'}
743
    );
722
744
723
    UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber, $accountno );
745
    UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber, $accountno );
724
746
(-)a/C4/Circulation.pm (-9 / +9 lines)
Lines 2214-2222 sub _FixAccountForLostAndReturned { Link Here
2214
    $amountleft *= -1 if ($amountleft > 0);
2214
    $amountleft *= -1 if ($amountleft > 0);
2215
    my $desc = "Item Returned " . $item_id;
2215
    my $desc = "Item Returned " . $item_id;
2216
    $usth = $dbh->prepare("INSERT INTO accountlines
2216
    $usth = $dbh->prepare("INSERT INTO accountlines
2217
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
2217
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,branchcode)
2218
        VALUES (?,?,now(),?,?,'CR',?)");
2218
        VALUES (?,?,now(),?,?,'CR',?,?)");
2219
    $usth->execute($data->{'borrowernumber'},$nextaccntno,0-$amount,$desc,$amountleft);
2219
    $usth->execute($data->{'borrowernumber'},$nextaccntno,0-$amount,$desc,$amountleft,C4::Context->userenv->{'branch'});
2220
    if ($borrowernumber) {
2220
    if ($borrowernumber) {
2221
        # FIXME: same as query above.  use 1 sth for both
2221
        # FIXME: same as query above.  use 1 sth for both
2222
        $usth = $dbh->prepare("INSERT INTO accountoffsets
2222
        $usth = $dbh->prepare("INSERT INTO accountoffsets
Lines 2591-2602 sub AddRenewal { Link Here
2591
        $sth = $dbh->prepare(
2591
        $sth = $dbh->prepare(
2592
                "INSERT INTO accountlines
2592
                "INSERT INTO accountlines
2593
                    (date, borrowernumber, accountno, amount, manager_id,
2593
                    (date, borrowernumber, accountno, amount, manager_id,
2594
                    description,accounttype, amountoutstanding, itemnumber)
2594
                    description,accounttype, amountoutstanding, itemnumber, branch)
2595
                    VALUES (now(),?,?,?,?,?,?,?,?)"
2595
                    VALUES (now(),?,?,?,?,?,?,?,?,?)"
2596
        );
2596
        );
2597
        $sth->execute( $borrowernumber, $accountno, $charge, $manager_id,
2597
        $sth->execute( $borrowernumber, $accountno, $charge, $manager_id,
2598
            "Renewal of Rental Item $item->{'title'} $item->{'barcode'}",
2598
            "Renewal of Rental Item $item->{'title'} $item->{'barcode'}",
2599
            'Rent', $charge, $itemnumber );
2599
            'Rent', $charge, $itemnumber, C4::Context->userenv->{'branch'} );
2600
    }
2600
    }
2601
2601
2602
    # Send a renewal slip according to checkout alert preferencei
2602
    # Send a renewal slip according to checkout alert preferencei
Lines 2781-2791 sub AddIssuingCharge { Link Here
2781
        INSERT INTO accountlines
2781
        INSERT INTO accountlines
2782
            (borrowernumber, itemnumber, accountno,
2782
            (borrowernumber, itemnumber, accountno,
2783
            date, amount, description, accounttype,
2783
            date, amount, description, accounttype,
2784
            amountoutstanding, manager_id)
2784
            amountoutstanding, manager_id, branchcode)
2785
        VALUES (?, ?, ?,now(), ?, 'Rental', 'Rent',?,?)
2785
        VALUES (?, ?, ?,now(), ?, 'Rental', 'Rent',?,?,?)
2786
    ";
2786
    ";
2787
    my $sth = $dbh->prepare($query);
2787
    my $sth = $dbh->prepare($query);
2788
    $sth->execute( $borrowernumber, $itemnumber, $nextaccntno, $charge, $charge, $manager_id );
2788
    $sth->execute( $borrowernumber, $itemnumber, $nextaccntno, $charge, $charge, $manager_id, C4::Context->userenv->{'branch'} );
2789
}
2789
}
2790
2790
2791
=head2 GetTransfers
2791
=head2 GetTransfers
(-)a/C4/Overdues.pm (-3 / +4 lines)
Lines 591-601 sub UpdateFine { Link Here
591
		my $nextaccntno = C4::Accounts::getnextacctno($borrowernumber);
591
		my $nextaccntno = C4::Accounts::getnextacctno($borrowernumber);
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
		my $query = "INSERT INTO accountlines
593
		my $query = "INSERT INTO accountlines
594
		    (borrowernumber,itemnumber,date,amount,description,accounttype,amountoutstanding,lastincrement,accountno)
594
                  (borrowernumber,itemnumber,date,amount,description,accounttype,amountoutstanding,lastincrement,accountno,branchcode)
595
			    VALUES (?,?,now(),?,?,'FU',?,?,?)";
595
                           VALUES (?,?,now(),?,?,'FU',?,?,?,?)";
596
		my $sth2 = $dbh->prepare($query);
596
		my $sth2 = $dbh->prepare($query);
597
		$debug and print STDERR "UpdateFine query: $query\nw/ args: $borrowernumber, $itemnum, $amount, $desc, $amount, $amount, $nextaccntno\n";
597
		$debug and print STDERR "UpdateFine query: $query\nw/ args: $borrowernumber, $itemnum, $amount, $desc, $amount, $amount, $nextaccntno\n";
598
        $sth2->execute($borrowernumber, $itemnum, $amount, $desc, $amount, $amount, $nextaccntno);
598
        my $branch = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
599
        $sth2->execute($borrowernumber, $itemnum, $amount, $desc, $amount, $amount, $nextaccntno, $branchcode);
599
    }
600
    }
600
    # logging action
601
    # logging action
601
    &logaction(
602
    &logaction(
(-)a/C4/Reserves.pm (-3 / +3 lines)
Lines 178-190 sub AddReserve { Link Here
178
        my $nextacctno = &getnextacctno( $borrowernumber );
178
        my $nextacctno = &getnextacctno( $borrowernumber );
179
        my $query      = qq/
179
        my $query      = qq/
180
        INSERT INTO accountlines
180
        INSERT INTO accountlines
181
            (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
181
            (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,branchcode)
182
        VALUES
182
        VALUES
183
            (?,?,now(),?,?,'Res',?)
183
            (?,?,now(),?,?,'Res',?,?)
184
    /;
184
    /;
185
        my $usth = $dbh->prepare($query);
185
        my $usth = $dbh->prepare($query);
186
        $usth->execute( $borrowernumber, $nextacctno, $fee,
186
        $usth->execute( $borrowernumber, $nextacctno, $fee,
187
            "Reserve Charge - $title", $fee );
187
            "Reserve Charge - $title", $fee, C4::Context->userenv->{'branch'} );
188
    }
188
    }
189
189
190
    #if ($const eq 'a'){
190
    #if ($const eq 'a'){
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 2699-2704 CREATE TABLE `accountlines` ( Link Here
2699
  `notify_level` int(2) NOT NULL default 0,
2699
  `notify_level` int(2) NOT NULL default 0,
2700
  `note` text NULL default NULL,
2700
  `note` text NULL default NULL,
2701
  `manager_id` int(11) NULL,
2701
  `manager_id` int(11) NULL,
2702
  `branchcode` VARCHAR( 10 ) NULL DEFAULT NULL, -- the branchcode of the library where a payment was made, a manual invoice created, etc.
2702
  PRIMARY KEY (`accountlines_id`),
2703
  PRIMARY KEY (`accountlines_id`),
2703
  KEY `acctsborridx` (`borrowernumber`),
2704
  KEY `acctsborridx` (`borrowernumber`),
2704
  KEY `timeidx` (`timestamp`),
2705
  KEY `timeidx` (`timestamp`),
(-)a/installer/data/mysql/updatedatabase.pl (-1 / +7 lines)
Lines 7778-7783 if(CheckVersion($DBversion)) { Link Here
7778
    SetVersion($DBversion);
7778
    SetVersion($DBversion);
7779
}
7779
}
7780
7780
7781
$DBversion = "3.15.00.XXX";
7782
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
7783
    $dbh->do("ALTER TABLE accountlines ADD branchcode VARCHAR( 10 ) NULL DEFAULT NULL AFTER manager_id");
7784
    print "Upgrade to $DBversion done (Added column branchcode to accountlines)\n";
7785
    SetVersion($DBversion);
7786
}
7787
7781
=head1 FUNCTIONS
7788
=head1 FUNCTIONS
7782
7789
7783
=head2 TableExists($table)
7790
=head2 TableExists($table)
7784
- 

Return to bug 7595