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

(-)a/C4/Accounts.pm (-27 / +48 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(),?,'','Pay',?,?)"
148
  VALUES (?,?,now(),?,'Payment,thanks','Pay',?,?,?)"
149
    );
149
    );
150
    $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, 0 - $amountleft, $manager_id );
150
    $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, 0 - $amountleft, $manager_id, $branch );
151
151
152
    UpdateStats( $branch, 'payment', $data, '', '', '', $borrowernumber, $nextaccntno );
152
    UpdateStats( $branch, 'payment', $data, '', '', '', $borrowernumber, $nextaccntno );
153
153
Lines 229-238 sub makepayment { Link Here
229
        my $ins = 
229
        my $ins = 
230
            $dbh->prepare( 
230
            $dbh->prepare( 
231
                "INSERT 
231
                "INSERT 
232
                    INTO accountlines (borrowernumber, accountno, date, amount, itemnumber, description, accounttype, amountoutstanding, manager_id, note)
232
                    INTO accountlines (borrowernumber, accountno, date, amount, itemnumber, description, accounttype, amountoutstanding, manager_id, note, branchcode)
233
                    VALUES ( ?, ?, now(), ?, ?, '', 'Pay', 0, ?, ?)"
233
                    VALUES ( ?, ?, now(), ?, ?, 'Payment,thanks', 'Pay', 0, ?, ?, ?)"
234
            );
234
            );
235
        $ins->execute($borrowernumber, $nextaccntno, $payment, $data->{'itemnumber'}, $manager_id, $payment_note);
235
        $ins->execute($borrowernumber, $nextaccntno, $payment, $data->{'itemnumber'}, $manager_id, $payment_note,  C4::Context->userenv->{'branch'});
236
    }
236
    }
237
237
238
    if ( C4::Context->preference("FinesLog") ) {
238
    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.
354
        #  process (or person) to update it, since we don't handle any defaults for replacement prices.
355
        my $accountno = getnextacctno($borrowernumber);
355
        my $accountno = getnextacctno($borrowernumber);
356
        my $sth2=$dbh->prepare("INSERT INTO accountlines
356
        my $sth2=$dbh->prepare("INSERT INTO accountlines
357
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber,manager_id)
357
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber,manager_id,branchcode)
358
        VALUES (?,?,now(),?,?,'L',?,?,?)");
358
        VALUES (?,?,now(),?,?,'L',?,?,?,?)");
359
        $sth2->execute($borrowernumber,$accountno,$amount,
359
        my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
360
        $description,$amount,$itemnumber,$manager_id);
360
        $sth2->execute( $borrowernumber, $accountno, $amount, $description,
361
            $amount, $itemnumber, $manager_id, $branchcode );
361
362
362
        if ( C4::Context->preference("FinesLog") ) {
363
        if ( C4::Context->preference("FinesLog") ) {
363
            logaction("FINES", 'CREATE', $borrowernumber, Dumper({
364
            logaction("FINES", 'CREATE', $borrowernumber, Dumper({
Lines 406-411 sub manualinvoice { Link Here
406
    my ( $borrowernumber, $itemnum, $desc, $type, $amount, $note ) = @_;
407
    my ( $borrowernumber, $itemnum, $desc, $type, $amount, $note ) = @_;
407
    my $manager_id = 0;
408
    my $manager_id = 0;
408
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
409
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
410
    my $branchcode = C4::Context->userenv->{'branch'};
409
    my $dbh      = C4::Context->dbh;
411
    my $dbh      = C4::Context->dbh;
410
    my $notifyid = 0;
412
    my $notifyid = 0;
411
    my $insert;
413
    my $insert;
Lines 425-440 sub manualinvoice { Link Here
425
        $desc .= ' ' . $itemnum;
427
        $desc .= ' ' . $itemnum;
426
        my $sth = $dbh->prepare(
428
        my $sth = $dbh->prepare(
427
            'INSERT INTO  accountlines
429
            'INSERT INTO  accountlines
428
                        (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, itemnumber,notify_id, note, manager_id)
430
                        (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, itemnumber,notify_id, note, manager_id, branchcode)
429
        VALUES (?, ?, now(), ?,?, ?,?,?,?,?,?)');
431
        VALUES (?, ?, now(), ?,?, ?,?,?,?,?,?,?)');
430
     $sth->execute($borrowernumber, $accountno, $amount, $desc, $type, $amountleft, $itemnum,$notifyid, $note, $manager_id) || return $sth->errstr;
432
     $sth->execute($borrowernumber, $accountno, $amount, $desc, $type, $amountleft, $itemnum,$notifyid, $note, $manager_id, $branchcode) || return $sth->errstr;
431
  } else {
433
  } else {
432
    my $sth=$dbh->prepare("INSERT INTO  accountlines
434
    my $sth=$dbh->prepare("INSERT INTO  accountlines
433
            (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding,notify_id, note, manager_id)
435
            (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding,notify_id, note, manager_id, branchcode)
434
            VALUES (?, ?, now(), ?, ?, ?, ?,?,?,?)"
436
            VALUES (?, ?, now(), ?, ?, ?, ?,?,?,?,?)"
435
        );
437
        );
436
        $sth->execute( $borrowernumber, $accountno, $amount, $desc, $type,
438
        $sth->execute( $borrowernumber, $accountno, $amount, $desc, $type,
437
            $amountleft, $notifyid, $note, $manager_id );
439
            $amountleft, $notifyid, $note, $manager_id, $branchcode );
438
    }
440
    }
439
441
440
    if ( C4::Context->preference("FinesLog") ) {
442
    if ( C4::Context->preference("FinesLog") ) {
Lines 638-647 sub recordpayment_selectaccts { Link Here
638
    }
640
    }
639
641
640
    # create new line
642
    # create new line
641
    $sql = 'INSERT INTO accountlines ' .
643
    $sql = q{
642
    '(borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id,note) ' .
644
        INSERT INTO accountlines (
643
    q|VALUES (?,?,now(),?,'','Pay',?,?,?)|;
645
            borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, manager_id, note, branchcode
644
    $dbh->do($sql,{},$borrowernumber, $nextaccntno, 0 - $amount, 0 - $amountleft, $manager_id, $note );
646
        ) VALUES (
647
            ?, ?, NOW(), ?, 'Payment,thanks', 'Pay', ?, ?, ?, ?
648
        )
649
    };
650
    $dbh->do(
651
        $sql, {}, $borrowernumber,
652
        $nextaccntno, 0 - $amount, 0 - $amountleft,
653
        $manager_id,  $note,       $branch
654
    );
655
645
    UpdateStats( $branch, 'payment', $amount, '', '', '', $borrowernumber, $nextaccntno );
656
    UpdateStats( $branch, 'payment', $amount, '', '', '', $borrowernumber, $nextaccntno );
646
657
647
    if ( C4::Context->preference("FinesLog") ) {
658
    if ( C4::Context->preference("FinesLog") ) {
Lines 679-685 sub makepartialpayment { Link Here
679
        'SELECT * FROM accountlines WHERE  accountlines_id=?',undef,$accountlines_id);
690
        'SELECT * FROM accountlines WHERE  accountlines_id=?',undef,$accountlines_id);
680
    my $new_outstanding = $data->{amountoutstanding} - $amount;
691
    my $new_outstanding = $data->{amountoutstanding} - $amount;
681
692
682
    my $update = 'UPDATE  accountlines SET amountoutstanding = ?  WHERE   accountlines_id = ? ';
693
    my $update = 'UPDATE accountlines SET amountoutstanding = ? WHERE accountlines_id = ? ';
683
    $dbh->do( $update, undef, $new_outstanding, $accountlines_id);
694
    $dbh->do( $update, undef, $new_outstanding, $accountlines_id);
684
695
685
    if ( C4::Context->preference("FinesLog") ) {
696
    if ( C4::Context->preference("FinesLog") ) {
Lines 696-707 sub makepartialpayment { Link Here
696
    }
707
    }
697
708
698
    # create new line
709
    # create new line
699
    my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, '
710
    my $insert = q{
700
    .  'description, accounttype, amountoutstanding, itemnumber, manager_id, note) '
711
        INSERT INTO accountlines (
701
    . ' VALUES (?, ?, now(), ?, ?, ?, 0, ?, ?, ?)';
712
            borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, itemnumber, manager_id, note, branchcode
702
713
        ) VALUES (
703
    $dbh->do(  $insert, undef, $borrowernumber, $nextaccntno, $amount,
714
            ?, ?, NOW(), ?, ?, ?, 0, ?, ?, ?, ?
704
        "Payment, thanks - $user", 'Pay', $data->{'itemnumber'}, $manager_id, $payment_note);
715
        )
716
    };
717
718
    $dbh->do(
719
        $insert,         undef,
720
        $borrowernumber, $nextaccntno,
721
        $amount,         "Payment, thanks - $user",
722
        'Pay',           $data->{'itemnumber'},
723
        $manager_id,     $payment_note,
724
        C4::Context->userenv->{'branch'}
725
    );
705
726
706
    UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber, $accountno );
727
    UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber, $accountno );
707
728
(-)a/C4/Circulation.pm (-9 / +9 lines)
Lines 2186-2194 sub _FixAccountForLostAndReturned { Link Here
2186
    $amountleft *= -1 if ($amountleft > 0);
2186
    $amountleft *= -1 if ($amountleft > 0);
2187
    my $desc = "Item Returned " . $item_id;
2187
    my $desc = "Item Returned " . $item_id;
2188
    $usth = $dbh->prepare("INSERT INTO accountlines
2188
    $usth = $dbh->prepare("INSERT INTO accountlines
2189
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
2189
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,branchcode)
2190
        VALUES (?,?,now(),?,?,'CR',?)");
2190
        VALUES (?,?,now(),?,?,'CR',?,?)");
2191
    $usth->execute($data->{'borrowernumber'},$nextaccntno,0-$amount,$desc,$amountleft);
2191
    $usth->execute($data->{'borrowernumber'},$nextaccntno,0-$amount,$desc,$amountleft,C4::Context->userenv->{'branch'});
2192
    if ($borrowernumber) {
2192
    if ($borrowernumber) {
2193
        # FIXME: same as query above.  use 1 sth for both
2193
        # FIXME: same as query above.  use 1 sth for both
2194
        $usth = $dbh->prepare("INSERT INTO accountoffsets
2194
        $usth = $dbh->prepare("INSERT INTO accountoffsets
Lines 2581-2592 sub AddRenewal { Link Here
2581
        $sth = $dbh->prepare(
2581
        $sth = $dbh->prepare(
2582
                "INSERT INTO accountlines
2582
                "INSERT INTO accountlines
2583
                    (date, borrowernumber, accountno, amount, manager_id,
2583
                    (date, borrowernumber, accountno, amount, manager_id,
2584
                    description,accounttype, amountoutstanding, itemnumber)
2584
                    description,accounttype, amountoutstanding, itemnumber, branch)
2585
                    VALUES (now(),?,?,?,?,?,?,?,?)"
2585
                    VALUES (now(),?,?,?,?,?,?,?,?,?)"
2586
        );
2586
        );
2587
        $sth->execute( $borrowernumber, $accountno, $charge, $manager_id,
2587
        $sth->execute( $borrowernumber, $accountno, $charge, $manager_id,
2588
            "Renewal of Rental Item $item->{'title'} $item->{'barcode'}",
2588
            "Renewal of Rental Item $item->{'title'} $item->{'barcode'}",
2589
            'Rent', $charge, $itemnumber );
2589
            'Rent', $charge, $itemnumber, C4::Context->userenv->{'branch'} );
2590
    }
2590
    }
2591
2591
2592
    # Send a renewal slip according to checkout alert preferencei
2592
    # Send a renewal slip according to checkout alert preferencei
Lines 2819-2829 sub AddIssuingCharge { Link Here
2819
        INSERT INTO accountlines
2819
        INSERT INTO accountlines
2820
            (borrowernumber, itemnumber, accountno,
2820
            (borrowernumber, itemnumber, accountno,
2821
            date, amount, description, accounttype,
2821
            date, amount, description, accounttype,
2822
            amountoutstanding, manager_id)
2822
            amountoutstanding, manager_id, branchcode)
2823
        VALUES (?, ?, ?,now(), ?, 'Rental', 'Rent',?,?)
2823
        VALUES (?, ?, ?,now(), ?, 'Rental', 'Rent',?,?,?)
2824
    ";
2824
    ";
2825
    my $sth = $dbh->prepare($query);
2825
    my $sth = $dbh->prepare($query);
2826
    $sth->execute( $borrowernumber, $itemnumber, $nextaccntno, $charge, $charge, $manager_id );
2826
    $sth->execute( $borrowernumber, $itemnumber, $nextaccntno, $charge, $charge, $manager_id, C4::Context->userenv->{'branch'} );
2827
}
2827
}
2828
2828
2829
=head2 GetTransfers
2829
=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 2698-2703 CREATE TABLE `accountlines` ( Link Here
2698
  `notify_level` int(2) NOT NULL default 0,
2698
  `notify_level` int(2) NOT NULL default 0,
2699
  `note` text NULL default NULL,
2699
  `note` text NULL default NULL,
2700
  `manager_id` int(11) NULL,
2700
  `manager_id` int(11) NULL,
2701
  `branchcode` VARCHAR( 10 ) NULL DEFAULT NULL, -- the branchcode of the library where a payment was made, a manual invoice created, etc.
2701
  PRIMARY KEY (`accountlines_id`),
2702
  PRIMARY KEY (`accountlines_id`),
2702
  KEY `acctsborridx` (`borrowernumber`),
2703
  KEY `acctsborridx` (`borrowernumber`),
2703
  KEY `timeidx` (`timestamp`),
2704
  KEY `timeidx` (`timestamp`),
(-)a/installer/data/mysql/updatedatabase.pl (-1 / +7 lines)
Lines 8191-8196 Your library.' Link Here
8191
    SetVersion($DBversion);
8191
    SetVersion($DBversion);
8192
}
8192
}
8193
8193
8194
$DBversion = "3.15.00.XXX";
8195
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
8196
    $dbh->do("ALTER TABLE accountlines ADD branchcode VARCHAR( 10 ) NULL DEFAULT NULL AFTER manager_id");
8197
    print "Upgrade to $DBversion done (Added column branchcode to accountlines)\n";
8198
    SetVersion($DBversion);
8199
}
8200
8194
=head1 FUNCTIONS
8201
=head1 FUNCTIONS
8195
8202
8196
=head2 TableExists($table)
8203
=head2 TableExists($table)
8197
- 

Return to bug 7595