Bug 20980: Add 'Manual Credit' and fix existing offsets
authorTomas Cohen Arazi <tomascohen@theke.io>
Thu, 21 Jun 2018 17:43:34 +0000 (14:43 -0300)
committerNick Clemens <nick@bywatersolutions.com>
Fri, 6 Jul 2018 12:50:05 +0000 (12:50 +0000)
This patch adds a new offset type 'Manual Credit'. And adds an atomic
update for fixing existing offsets.

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>

installer/data/mysql/account_offset_types.sql
installer/data/mysql/atomicupdate/bug_20980.perl [new file with mode: 0644]
koha-tmpl/intranet-tmpl/prog/en/includes/account_offset_type.inc

index a9eaadc..7b96abf 100644 (file)
@@ -3,6 +3,7 @@ INSERT INTO account_offset_types ( type ) VALUES
 ('Payment'),
 ('Lost Item'),
 ('Processing Fee'),
+('Manual Credit'),
 ('Manual Debit'),
 ('Reverse Payment'),
 ('Forgiven'),
diff --git a/installer/data/mysql/atomicupdate/bug_20980.perl b/installer/data/mysql/atomicupdate/bug_20980.perl
new file mode 100644 (file)
index 0000000..691ecd5
--- /dev/null
@@ -0,0 +1,39 @@
+$DBversion = 'XXX';
+if( CheckVersion( $DBversion ) ) {
+
+    # Add 'Manual Credit' offset type
+    $dbh->do(q{
+        INSERT IGNORE INTO `account_offset_types` (`type`) VALUES ('Manual Credit');
+    });
+
+    # Fix wrong account offsets / Manual credits
+    $dbh->do(q{
+        UPDATE account_offsets
+        SET credit_id=debit_id,
+            debit_id=NULL,
+            type='Manual Credit'
+        WHERE amount < 0 AND
+              type='Manual Debit' AND
+              debit_id IN
+                (SELECT accountlines_id AS debit_id
+                 FROM accountlines
+                 WHERE accounttype='C');
+    });
+
+    # Fix wrong account offsets / Manually forgiven amounts
+    $dbh->do(q{
+        UPDATE account_offsets
+        SET credit_id=debit_id,
+            debit_id=NULL,
+            type='Writeoff'
+        WHERE amount < 0 AND
+              type='Manual Debit' AND
+              debit_id IN
+                (SELECT accountlines_id AS debit_id
+                 FROM accountlines
+                 WHERE accounttype='FOR');
+    });
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 20980 - Manual credit offsets are stored as debits)\n";
+}
index a36a883..6ec71d1 100644 (file)
@@ -1,5 +1,6 @@
 [% SWITCH account_offset.type %]
     [% CASE 'Payment' %]Payment
+    [% CASE 'Manual Credit' %]Manual credit
     [% CASE 'Manual Debit' %]Manual invoice
     [% CASE 'Lost Item Return' %]Lost item returned
     [% CASE 'Writeoff' %]Writeoff