Bug 20980: Make mancredit.pl use Koha::Account::add_credit
authorTomas Cohen Arazi <tomascohen@theke.io>
Fri, 22 Jun 2018 15:23:47 +0000 (12:23 -0300)
committerNick Clemens <nick@bywatersolutions.com>
Fri, 6 Jul 2018 12:50:06 +0000 (12:50 +0000)
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 <josef.moravec@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

koha-tmpl/intranet-tmpl/prog/en/modules/members/mancredit.tt
members/mancredit.pl

index 305910f..9aca8b5 100644 (file)
@@ -37,8 +37,8 @@
 <fieldset class="rows">
 <legend>Manual credit</legend><ol>
        <li><label for="type">Credit type: </label><select name="type" id="type">
-<option value="C">Credit</option>
-<option value="FOR">Forgiven</option>
+<option value="credit">Credit</option>
+<option value="forgiven">Forgiven</option>
 </select></li>
        <li><label for="barcode">Barcode: </label><input type="text" name="barcode" id="barcode" /></li>
        <li><label for="desc">Description: </label><input type="text" name="desc" size="50" id="desc" /></li>
index 0e8ac3e..f1d388d 100755 (executable)
@@ -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 {