@@ -, +, @@ --- C4/Accounts.pm | 91 +++++++++++++++++++++----------- installer/data/mysql/kohastructure.sql | 1 + installer/data/mysql/updatedatabase.pl | 7 +++ 3 files changed, 68 insertions(+), 31 deletions(-) --- a/C4/Accounts.pm +++ a/C4/Accounts.pm @@ -145,10 +145,11 @@ sub recordpayment { # create new line my $usth = $dbh->prepare( "INSERT INTO accountlines - (borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id) - VALUES (?,?,now(),?,'Payment,thanks','Pay',?,?)" + (borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id,branchcode) + VALUES (?,?,now(),?,'Payment,thanks','Pay',?,?,?)" ); - $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, 0 - $amountleft, $manager_id ); + + $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, 0 - $amountleft, $manager_id, $branch ); UpdateStats( $branch, 'payment', $data, '', '', '', $borrowernumber, $nextaccntno ); @@ -230,14 +231,22 @@ sub makepayment { my $payment = 0 - $amount; $payment_note //= ""; - my $ins = - $dbh->prepare( - "INSERT - INTO accountlines (borrowernumber, accountno, date, amount, itemnumber, description, accounttype, amountoutstanding, manager_id, note) - VALUES ( ?, ?, now(), ?, ?, 'Payment,thanks', 'Pay', 0, ?, ?)" - ); - $ins->execute($borrowernumber, $nextaccntno, $payment, $data->{'itemnumber'}, $manager_id, $payment_note); - $ins->finish; + my $ins = $dbh->prepare(q{ + INSERT 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, + C4::Context->userenv->{'branch'} + ); } if ( C4::Context->preference("FinesLog") ) { @@ -360,10 +369,10 @@ 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',?,?,?)"); + (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber,manager_id,branchcode) + VALUES (?,?,now(),?,?,'L',?,?,?,?)"); $sth2->execute($borrowernumber,$accountno,$amount, - $description,$amount,$itemnumber,$manager_id); + $description,$amount,$itemnumber,$manager_id,C4::Context->userenv->{'branch'}); $sth2->finish; if ( C4::Context->preference("FinesLog") ) { @@ -413,6 +422,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->{'branch'}; my $dbh = C4::Context->dbh; my $notifyid = 0; my $insert; @@ -463,16 +473,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") ) { @@ -848,10 +858,19 @@ sub recordpayment_selectaccts { } # create new line - $sql = 'INSERT INTO accountlines ' . - '(borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id,note) ' . - q|VALUES (?,?,now(),?,'Payment,thanks','Pay',?,?,?)|; - $dbh->do($sql,{},$borrowernumber, $nextaccntno, 0 - $amount, 0 - $amountleft, $manager_id, $note ); + $sql = q{ + INSERT INTO accountlines ( + borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, manager_id, note, branchcode + ) VALUES ( + ?, ?, NOW(), ?, 'Payment,thanks', 'Pay', ?, ?, ?, ? + ) + }; + $dbh->do( + $sql, {}, $borrowernumber, + $nextaccntno, 0 - $amount, 0 - $amountleft, + $manager_id, $note, $branch + ); + UpdateStats( $branch, 'payment', $amount, '', '', '', $borrowernumber, $nextaccntno ); if ( C4::Context->preference("FinesLog") ) { @@ -889,7 +908,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") ) { @@ -906,12 +925,22 @@ sub makepartialpayment { } # create new line - my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, ' - . 'description, accounttype, amountoutstanding, itemnumber, manager_id, note) ' - . ' VALUES (?, ?, now(), ?, ?, ?, 0, ?, ?, ?)'; - - $dbh->do( $insert, undef, $borrowernumber, $nextaccntno, $amount, - "Payment, thanks - $user", 'Pay', $data->{'itemnumber'}, $manager_id, $payment_note); + my $insert = q{ + INSERT INTO accountlines ( + borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, itemnumber, manager_id, note, branchcode + ) VALUES ( + ?, ?, NOW(), ?, ?, ?, 0, ?, ?, ?, ? + ) + }; + + $dbh->do( + $insert, undef, + $borrowernumber, $nextaccntno, + $amount, "Payment, thanks - $user", + 'Pay', $data->{'itemnumber'}, + $manager_id, $payment_note, + C4::Context->userenv->{'branch'} + ); UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber, $accountno ); --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -2636,6 +2636,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`), --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -7067,6 +7067,13 @@ if ( CheckVersion($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.13.00.XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do("ALTER TABLE accountlines ADD branchcode VARCHAR( 10 ) NULL DEFAULT NULL AFTER manager_id"); + print "Upgrade to $DBversion done (Added column branchcode to accountlines)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) --