From cc30dc39bf3c8f627865c1a4891fac534266dc03 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 22 Jun 2018 12:23:47 -0300 Subject: [PATCH] Bug 20980: Make mancredit.pl use Koha::Account::add_credit This patch makes creating a manual credit from the UI record the account offset as 'Manual Credit', and properly set account_offsets.credit_id instead of account_offsets.debit_id. To test: - Create a manual credit (of 'Credit' type) for a known patron (acevedo?) - Run: $ sudo koha-mysql kohadev > SELECT * FROM account_offsets; => FAIL: The account offset for the manual credit has type=Manual Debit, credit_id=NULL and debit_id=accountlines_id - Run the atomic update: $ updatedatabase - Run: $ sudo koha-mysql kohadev > SELECT * FROM account_offsets; => SUCCESS: The account offset has been corrected and now has type=Manual Credit, credit_id=accountlines_id and debit_id=NULL - Create a new manual credit (of 'Forgiven' type) for a known patron - Run: $ sudo koha-mysql kohadev > SELECT * FROM account_offsets; => SUCCESS: The account offset has been stored correctly as a credit! - Sign off :-D Signed-off-by: Josef Moravec Signed-off-by: Kyle M Hall Signed-off-by: Nick Clemens --- .../prog/en/modules/members/mancredit.tt | 4 +-- members/mancredit.pl | 32 +++++++++++++------ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/mancredit.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/mancredit.tt index 305910f0da..9aca8b52c7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/mancredit.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/mancredit.tt @@ -37,8 +37,8 @@
Manual credit
  1. diff --git a/members/mancredit.pl b/members/mancredit.pl index 0e8ac3e637..f1d388d577 100755 --- a/members/mancredit.pl +++ b/members/mancredit.pl @@ -32,8 +32,9 @@ use C4::Members; use C4::Accounts; use C4::Items; use C4::Members::Attributes qw(GetBorrowerAttributes); -use Koha::Patrons; +use Koha::Account; +use Koha::Patrons; use Koha::Patron::Categories; use Koha::Token; @@ -50,7 +51,10 @@ unless ( $patron ) { my $add=$input->param('add'); if ($add){ - if ( checkauth( $input, 0, $flagsrequired, 'intranet' ) ) { + + my ( $user_id ) = checkauth( $input, 0, $flagsrequired, 'intranet' ); + + if ( $user_id ) { die "Wrong CSRF token" unless Koha::Token->new->check_csrf( { @@ -61,16 +65,24 @@ if ($add){ # Note: If the logged in user is not allowed to see this patron an invoice can be forced # Here we are trusting librarians not to hack the system my $barcode = $input->param('barcode'); - my $itemnum; + my $item_id; if ($barcode) { - $itemnum = GetItemnumberFromBarcode($barcode); + $item_id = GetItemnumberFromBarcode($barcode); } - my $desc = $input->param('desc'); - my $note = $input->param('note'); - my $amount = $input->param('amount') || 0; - $amount = -$amount; - my $type = $input->param('type'); - manualinvoice( $borrowernumber, $itemnum, $desc, $type, $amount, $note ); + my $description = $input->param('desc'); + my $note = $input->param('note'); + my $amount = $input->param('amount') || 0; + my $type = $input->param('type'); + + Koha::Account->new({ patron_id => $borrowernumber })->add_credit({ + amount => $amount, + description => $description, + item_id => $item_id, + note => $note, + type => $type, + user_id => $user_id + }); + print $input->redirect("/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber"); } } else { -- 2.39.5