From 3fffd93def5cb22cdae471435d952fe942a4d0d8 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 24 Feb 2012 14:26:05 -0500 Subject: [PATCH] Bug 7595 - Add branchcode to accountlines Adds a branchcode column to the accountlines table. For payments, this inserts the branchcode of the library where the payment was recorded. For manual invoices, it insert the branchcode of the library where the manual invoice was created. Signed-off-by: Nicole C. Engard I tested with creating manual invoices, and paying partial fines, entire fine lines, and writing off fines. All actions record the branch where the action took place properly. Signed-off-by: Marc Veron --- C4/Accounts.pm | 54 ++++++++++++++------------ C4/Circulation.pm | 19 ++++----- C4/Overdues.pm | 2 + C4/Reserves.pm | 4 ++ installer/data/mysql/atomicupdate/bug_7595.sql | 1 + installer/data/mysql/kohastructure.sql | 1 + 6 files changed, 47 insertions(+), 34 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_7595.sql diff --git a/C4/Accounts.pm b/C4/Accounts.pm index 485e453..b400df9 100644 --- a/C4/Accounts.pm +++ b/C4/Accounts.pm @@ -92,7 +92,8 @@ sub recordpayment { my $dbh = C4::Context->dbh; my $newamtos = 0; my $accdata = ""; - my $branch = C4::Context->userenv->{'branch'}; + my $branch = C4::Context->userenv ? + C4::Context->userenv->{'branch'} : undef; my $amountleft = $data; my $manager_id = 0; $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; @@ -148,13 +149,13 @@ sub recordpayment { # create new line my $usth = $dbh->prepare( "INSERT INTO accountlines - (borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id, note) - VALUES (?,?,now(),?,'',?,?,?,?)" + (borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id, note,branchcode) + VALUES (?,?,now(),?,'',?,?,?,?,?)" ); my $paytype = "Pay"; $paytype .= $sip_paytype if defined $sip_paytype; - $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, $paytype, 0 - $amountleft, $manager_id, $payment_note ); + $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, $paytype, 0 - $amountleft, $manager_id, $payment_note, $branch ); $usth->finish; UpdateStats({ @@ -243,10 +244,11 @@ sub makepayment { my $ins = $dbh->prepare( "INSERT - INTO accountlines (borrowernumber, accountno, date, amount, itemnumber, description, accounttype, amountoutstanding, manager_id, note) - VALUES ( ?, ?, now(), ?, ?, '', 'Pay', 0, ?, ?)" + INTO accountlines (borrowernumber, accountno, date, amount, itemnumber, description, accounttype, amountoutstanding, manager_id, note, branchcode) + VALUES ( ?, ?, now(), ?, ?, 'Payment,thanks', 'Pay', 0, ?, ?, ?)" ); - $ins->execute($borrowernumber, $nextaccntno, $payment, $data->{'itemnumber'}, $manager_id, $payment_note); + my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; + $ins->execute($borrowernumber, $nextaccntno, $payment, $data->{'itemnumber'}, $manager_id, $payment_note, $branchcode); } if ( C4::Context->preference("FinesLog") ) { @@ -369,10 +371,11 @@ sub chargelostitem{ # process (or person) to update it, since we don't handle any defaults for replacement prices. my $accountno = getnextacctno($borrowernumber); my $sth2=$dbh->prepare("INSERT INTO accountlines - (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber,manager_id) - VALUES (?,?,now(),?,?,'L',?,?,?)"); - $sth2->execute($borrowernumber,$accountno,$amount, - $description,$amount,$itemnumber,$manager_id); + (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber,manager_id,branchcode) + VALUES (?,?,now(),?,?,'L',?,?,?,?)"); + my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; + $sth2->execute( $borrowernumber, $accountno, $amount, $description, + $amount, $itemnumber, $manager_id, $branchcode ); if ( C4::Context->preference("FinesLog") ) { logaction("FINES", 'CREATE', $borrowernumber, Dumper({ @@ -421,6 +424,7 @@ sub manualinvoice { my ( $borrowernumber, $itemnum, $desc, $type, $amount, $note ) = @_; my $manager_id = 0; $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; + my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; my $dbh = C4::Context->dbh; my $notifyid = 0; my $insert; @@ -440,16 +444,16 @@ sub manualinvoice { $desc .= ' ' . $itemnum; my $sth = $dbh->prepare( 'INSERT INTO accountlines - (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, itemnumber,notify_id, note, manager_id) - VALUES (?, ?, now(), ?,?, ?,?,?,?,?,?)'); - $sth->execute($borrowernumber, $accountno, $amount, $desc, $type, $amountleft, $itemnum,$notifyid, $note, $manager_id) || return $sth->errstr; + (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, itemnumber,notify_id, note, manager_id, branchcode) + VALUES (?, ?, now(), ?,?, ?,?,?,?,?,?,?)'); + $sth->execute($borrowernumber, $accountno, $amount, $desc, $type, $amountleft, $itemnum,$notifyid, $note, $manager_id, $branchcode) || return $sth->errstr; } else { my $sth=$dbh->prepare("INSERT INTO accountlines - (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding,notify_id, note, manager_id) - VALUES (?, ?, now(), ?, ?, ?, ?,?,?,?)" + (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding,notify_id, note, manager_id, branchcode) + VALUES (?, ?, now(), ?, ?, ?, ?,?,?,?,?)" ); $sth->execute( $borrowernumber, $accountno, $amount, $desc, $type, - $amountleft, $notifyid, $note, $manager_id ); + $amountleft, $notifyid, $note, $manager_id, $branchcode ); } if ( C4::Context->preference("FinesLog") ) { @@ -599,7 +603,7 @@ sub recordpayment_selectaccts { my $dbh = C4::Context->dbh; my $newamtos = 0; my $accdata = q{}; - my $branch = C4::Context->userenv->{branch}; + my $branch = C4::Context->userenv ? C4::Context->userenv->{branch} : undef; my $amountleft = $amount; my $manager_id = 0; $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; @@ -654,9 +658,9 @@ sub recordpayment_selectaccts { # create new line $sql = 'INSERT INTO accountlines ' . - '(borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id,note) ' . - q|VALUES (?,?,now(),?,'','Pay',?,?,?)|; - $dbh->do($sql,{},$borrowernumber, $nextaccntno, 0 - $amount, 0 - $amountleft, $manager_id, $note ); + '(borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id,note,branchcode) ' . + q|VALUES (?,?,now(),?,'','Pay',?,?,?,?)|; + $dbh->do($sql,{},$borrowernumber, $nextaccntno, 0 - $amount, 0 - $amountleft, $manager_id, $note, $branch ); UpdateStats({ branch => $branch, type => 'payment', @@ -700,7 +704,7 @@ sub makepartialpayment { 'SELECT * FROM accountlines WHERE accountlines_id=?',undef,$accountlines_id); my $new_outstanding = $data->{amountoutstanding} - $amount; - my $update = 'UPDATE accountlines SET amountoutstanding = ? WHERE accountlines_id = ? '; + my $update = 'UPDATE accountlines SET amountoutstanding = ? WHERE accountlines_id = ? '; $dbh->do( $update, undef, $new_outstanding, $accountlines_id); if ( C4::Context->preference("FinesLog") ) { @@ -718,11 +722,11 @@ sub makepartialpayment { # create new line my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, ' - . 'description, accounttype, amountoutstanding, itemnumber, manager_id, note) ' - . ' VALUES (?, ?, now(), ?, ?, ?, 0, ?, ?, ?)'; + . 'description, accounttype, amountoutstanding, itemnumber, manager_id, note, branchcode) ' + . ' VALUES (?, ?, now(), ?, ?, ?, 0, ?, ?, ?, ?)'; $dbh->do( $insert, undef, $borrowernumber, $nextaccntno, $amount, - '', 'Pay', $data->{'itemnumber'}, $manager_id, $payment_note); + '', 'Pay', $data->{'itemnumber'}, $manager_id, $payment_note, C4::Context->userenv->{'branch'}); UpdateStats({ branch => $branch, diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 9b95bbf..0423646 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2558,10 +2558,11 @@ sub _FixAccountForLostAndReturned { } $amountleft *= -1 if ($amountleft > 0); my $desc = "Item Returned " . $item_id; + my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; $usth = $dbh->prepare("INSERT INTO accountlines - (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding) - VALUES (?,?,now(),?,?,'CR',?)"); - $usth->execute($data->{'borrowernumber'},$nextaccntno,0-$amount,$desc,$amountleft); + (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,branchcode) + VALUES (?,?,now(),?,?,'CR',?,?)"); + $usth->execute( $data->{'borrowernumber'}, $nextaccntno, 0-$amount, $desc, $amountleft, $branchcode ); if ($borrowernumber) { # FIXME: same as query above. use 1 sth for both $usth = $dbh->prepare("INSERT INTO accountoffsets @@ -3113,12 +3114,12 @@ sub AddRenewal { $sth = $dbh->prepare( "INSERT INTO accountlines (date, borrowernumber, accountno, amount, manager_id, - description,accounttype, amountoutstanding, itemnumber) - VALUES (now(),?,?,?,?,?,?,?,?)" + description,accounttype, amountoutstanding, itemnumber, branch) + VALUES (now(),?,?,?,?,?,?,?,?,?)" ); $sth->execute( $borrowernumber, $accountno, $charge, $manager_id, "Renewal of Rental Item $item->{'title'} $item->{'barcode'}", - 'Rent', $charge, $itemnumber ); + 'Rent', $charge, $itemnumber, C4::Context->userenv->{'branch'} ); } # Send a renewal slip according to checkout alert preferencei @@ -3365,11 +3366,11 @@ sub AddIssuingCharge { INSERT INTO accountlines (borrowernumber, itemnumber, accountno, date, amount, description, accounttype, - amountoutstanding, manager_id) - VALUES (?, ?, ?,now(), ?, 'Rental', 'Rent',?,?) + amountoutstanding, manager_id, branchcode) + VALUES (?, ?, ?,now(), ?, 'Rental', 'Rent',?,?,?) "; my $sth = $dbh->prepare($query); - $sth->execute( $borrowernumber, $itemnumber, $nextaccntno, $charge, $charge, $manager_id ); + $sth->execute( $borrowernumber, $itemnumber, $nextaccntno, $charge, $charge, $manager_id, C4::Context->userenv->{'branch'} ); } =head2 GetTransfers diff --git a/C4/Overdues.pm b/C4/Overdues.pm index 3f0c32d..4a31d8c 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -603,6 +603,7 @@ sub UpdateFine { my $desc = ( $type ? "$type " : '' ) . "$title $due"; # FIXEDME, avoid whitespace prefix on empty $type + my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; my $accountline = Koha::Account::Line->new( { borrowernumber => $borrowernumber, @@ -615,6 +616,7 @@ sub UpdateFine { lastincrement => $amount, accountno => $nextaccntno, issue_id => $issue_id, + branchcode => $branchcode, } )->store(); } diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 79fb11a..5d6e56e 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -196,6 +196,9 @@ sub AddReserve { # Don't add itemtype limit if specific item is selected $itemtype = undef if $checkitem; + # Get the logged in library if there is one + my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; + # updates take place here my $hold = Koha::Hold->new( { @@ -210,6 +213,7 @@ sub AddReserve { waitingdate => $waitingdate, expirationdate => $expdate, itemtype => $itemtype, + branchcode => $branchcode, } )->store(); my $reserve_id = $hold->id(); diff --git a/installer/data/mysql/atomicupdate/bug_7595.sql b/installer/data/mysql/atomicupdate/bug_7595.sql new file mode 100644 index 0000000..8fe161a --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_7595.sql @@ -0,0 +1 @@ +ALTER TABLE accountlines ADD branchcode VARCHAR( 10 ) NULL DEFAULT NULL AFTER manager_id; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 76aa462..f9f24b6 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2680,6 +2680,7 @@ CREATE TABLE `accountlines` ( `notify_level` int(2) NOT NULL default 0, `note` text NULL default NULL, `manager_id` int(11) NULL, + `branchcode` VARCHAR( 10 ) NULL DEFAULT NULL, -- the branchcode of the library where a payment was made, a manual invoice created, etc. PRIMARY KEY (`accountlines_id`), KEY `acctsborridx` (`borrowernumber`), KEY `timeidx` (`timestamp`), -- 2.1.4