Bug 23805: Update 'W' to 'WRITEOFF' for consistency
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 14 Oct 2019 16:07:11 +0000 (17:07 +0100)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Thu, 24 Oct 2019 16:35:20 +0000 (17:35 +0100)
Signed-off-by: Kyle Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

C4/SIP/ILS/Transaction/FeePayment.pm
Koha/Account.pm
api/v1/swagger/definitions/patron_account_credit.json
installer/data/mysql/account_credit_types.sql
installer/data/mysql/atomicupdate/bug_23805_credit.perl
koha-tmpl/intranet-tmpl/prog/en/includes/accounts.inc
koha-tmpl/opac-tmpl/bootstrap/en/includes/account-table.inc
members/pay.pl
reports/cash_register_stats.pl
t/db_dependent/Accounts.t
t/db_dependent/Circulation.t

index 668d90e..7e19cc2 100644 (file)
@@ -50,7 +50,7 @@ sub pay {
     my $is_writeoff          = shift;
     my $disallow_overpayment = shift;
 
-    my $type = $is_writeoff ? 'writeoff' : 'PAYMENT';
+    my $type = $is_writeoff ? 'WRITEOFF' : 'PAYMENT';
 
     warn("RECORD:$borrowernumber::$amt");
 
index 67988f2..dd233ec 100644 (file)
@@ -79,7 +79,7 @@ sub pay {
     my $type          = $params->{type} || 'PAYMENT';
     my $payment_type  = $params->{payment_type} || undef;
     my $credit_type   = $params->{credit_type};
-    my $offset_type   = $params->{offset_type} || $type eq 'writeoff' ? 'Writeoff' : 'Payment';
+    my $offset_type   = $params->{offset_type} || $type eq 'WRITEOFF' ? 'Writeoff' : 'Payment';
     my $cash_register = $params->{cash_register};
 
     my $userenv = C4::Context->userenv;
@@ -216,11 +216,11 @@ sub pay {
     }
 
     $credit_type ||=
-      $type eq 'writeoff'
-      ? 'W'
+      $type eq 'WRITEOFF'
+      ? 'WRITEOFF'
       : 'PAYMENT';
 
-    $description ||= $type eq 'writeoff' ? 'Writeoff' : q{};
+    $description ||= $type eq 'WRITEOFF' ? 'Writeoff' : q{};
 
     my $payment = Koha::Account::Line->new(
         {
@@ -326,7 +326,7 @@ $credit_type can be any of:
   - 'PAYMENT'
   - 'FORGIVEN'
   - 'LOST_RETURN'
-  - 'writeoff'
+  - 'WRITEOFF'
 
 =cut
 
@@ -398,7 +398,7 @@ sub add_credit {
                     amount         => $amount,
                     borrowernumber => $self->{patron_id},
                 }
-            ) if grep { $type eq $_ } ('PAYMENT', 'writeoff') ;
+            ) if grep { $type eq $_ } ('PAYMENT', 'WRITEOFF') ;
 
             if ( C4::Context->preference("FinesLog") ) {
                 logaction(
@@ -720,7 +720,7 @@ our $offset_type = {
     'FORGIVEN'         => 'Writeoff',
     'LOST_RETURN'      => 'Lost Item',
     'PAYMENT'          => 'Payment',
-    'writeoff'         => 'Writeoff',
+    'WRITEOFF'         => 'Writeoff',
     'ACCOUNT'          => 'Account Fee',
     'ACCOUNT_RENEW'    => 'Account Fee',
     'RESERVE'          => 'Reserve Fee',
@@ -743,7 +743,7 @@ our $account_type_credit = {
     'FORGIVEN'         => 'FORGIVEN',
     'LOST_RETURN'      => 'LOST_RETURN',
     'PAYMENT'          => 'PAYMENT',
-    'writeoff'         => 'W'
+    'WRITEOFF'         => 'WRITEOFF'
 };
 
 =head1 AUTHORS
index 90683b4..a231471 100644 (file)
@@ -3,7 +3,7 @@
   "properties": {
     "credit_type": {
       "type": "string",
-      "description": "Type of credit ('CREDIT', 'FORGIVEN', 'LOST_RETURN', 'PAYMENT', 'writeoff' )"
+      "description": "Type of credit ('CREDIT', 'FORGIVEN', 'LOST_RETURN', 'PAYMENT', 'WRITEOFF' )"
     },
     "amount": {
       "type": "number",
index 579de31..d247427 100644 (file)
@@ -1,7 +1,6 @@
 INSERT INTO account_debit_types ( code, description, can_be_added_manually, is_system ) VALUES
 ('PAYMENT', 'Payment', 0, 1),
-('W', 'Writeoff', 0, 1),
-('WO', 'Writeoff', 0, 1),
+('WRITEOFF', 'Writeoff', 0, 1),
 ('FORGIVEN', 'Forgiven', 1, 1),
 ('CREDIT', 'Credit', 1, 1),
 ('LOST_RETURN', 'Lost item fee refund', 0, 1);
index abd55ad..27896d0 100644 (file)
@@ -37,8 +37,7 @@ if ( CheckVersion($DBversion) ) {
             )
             VALUES
               ('PAYMENT', 'Payment', 0, 1),
-              ('W', 'Writeoff', 0, 1),
-              ('WO', 'Writeoff', 0, 1),
+              ('WRITEOFF', 'Writeoff', 0, 1),
               ('FORGIVEN', 'Forgiven', 1, 1),
               ('CREDIT', 'Credit', 1, 1),
               ('LOST_RETURN', 'Lost item fee refund', 0, 1)
@@ -95,6 +94,13 @@ if ( CheckVersion($DBversion) ) {
         }
     );
 
+    # Update accountype 'W' to 'WRITEOFF'
+    $dbh->do(
+        qq{
+          UPDATE accountlines SET accounttype = 'WRITEOFF' WHERE accounttype = 'W' OR accounttype = 'WO'
+        }
+    );
+
     # Populating credit_type_code
     $dbh->do(
         qq{
index 19b5b3b..8d9e836 100644 (file)
@@ -3,9 +3,8 @@
     [%- IF account.credit_type_code -%]
         [%- SWITCH account.credit_type_code -%]
             [%- CASE 'PAYMENT'          -%]Payment
-            [%- CASE 'W'                -%]Writeoff
+            [%- CASE 'WRITEOFF'         -%]Writeoff
             [%- CASE 'FORGIVEN'         -%]Forgiven
-            [%- CASE 'WO'               -%]Writeoff
             [%- CASE 'CREDIT'           -%]Credit
             [%- CASE 'LOST_RETURN'      -%]Lost item fee refund
             [%- CASE                    -%][% account.credit_type.description | html %]
index cbf59ee..17f1ae3 100644 (file)
     [%- IF account.credit_type_code -%]
         [%- SWITCH account.credit_type_code -%]
             [%- CASE 'PAYMENT'          -%]Payment
-            [%- CASE 'W'                -%]Writeoff
+            [%- CASE 'WRITEOFF'         -%]Writeoff
             [%- CASE 'FORGIVEN'         -%]Forgiven
-            [%- CASE 'WO'               -%]Writeoff
             [%- CASE 'CREDIT'           -%]Credit
             [%- CASE 'LOST_RETURN'      -%]Lost item fee refund
             [%- CASE                    -%][% account.credit_type.description | html %]
index b12bd19..32c8c36 100755 (executable)
@@ -84,7 +84,7 @@ elsif ( $input->param('payselected') ) {
     payselected({ params => \@names });
 }
 elsif ( $input->param('writeoff_selected') ) {
-    payselected({ params => \@names, type => 'writeoff' });
+    payselected({ params => \@names, type => 'WRITEOFF' });
 }
 elsif ( $input->param('woall') ) {
     writeoff_all(@names);
@@ -116,7 +116,7 @@ elsif ( $input->param('confirm_writeoff') ) {
             {
                 amount     => $amount,
                 lines      => [ scalar Koha::Account::Lines->find($accountlines_id) ],
-                type       => 'writeoff',
+                type       => 'WRITEOFF',
                 note       => $payment_note,
                 interface  => C4::Context->interface,
                 library_id => $branch,
@@ -223,7 +223,7 @@ sub writeoff_all {
                 {
                     amount => $amount,
                     lines  => [ scalar Koha::Account::Lines->find($accountlines_id) ],
-                    type   => 'writeoff',
+                    type   => 'WRITEOFF',
                     note   => $payment_note,
                     interface  => C4::Context->interface,
                     library_id => $branch,
index da7b511..84ce194 100755 (executable)
@@ -74,7 +74,7 @@ if ($do_it) {
     } elsif ($transaction_type eq 'ACT') { #Active
         $whereTType = q{ AND credit_type_code IN ('PAYMENT','CREDIT') };
     } elsif ($transaction_type eq 'FORW') {
-        $whereTType = q{ AND credit_type_code IN ('FORGIVEN','W') };
+        $whereTType = q{ AND credit_type_code IN ('FORGIVEN','WRITEOFF') };
     } else {
         if ( any { $transaction_type eq $_->code } @debit_types ) {
             $whereTType = q{ AND debit_type_code = ? };
@@ -128,7 +128,7 @@ if ($do_it) {
             if($row->{credit_type_code} =~ /^CREDIT$/){
                 $grantotal -= abs($row->{amount});
                 $row->{amount} = '-' . $row->{amount};
-            }elsif($row->{credit_type_code} eq 'FORGIVEN' || $row->{credit_type_code} eq 'W'){
+            }elsif($row->{credit_type_code} eq 'FORGIVEN' || $row->{credit_type_code} eq 'WRITEOFF'){
             }else{
                 $grantotal += abs($row->{amount});
             }
index 99cb3f3..c7e21ab 100644 (file)
@@ -374,7 +374,7 @@ subtest "Koha::Account::pay writeoff tests" => sub {
         {
             lines  => [$line],
             amount => 42,
-            type   => 'writeoff',
+            type   => 'WRITEOFF',
         }
     );
 
@@ -384,7 +384,7 @@ subtest "Koha::Account::pay writeoff tests" => sub {
 
     my $writeoff = Koha::Account::Lines->find( $id );
 
-    is( $writeoff->credit_type_code, 'W', 'Type is correct for writeoff' );
+    is( $writeoff->credit_type_code, 'WRITEOFF', 'Type is correct for WRITEOFF' );
     is( $writeoff->description, 'Writeoff', 'Description is correct' );
     is( $writeoff->amount, '-42.000000', 'Amount is correct' );
 };
@@ -1180,7 +1180,7 @@ subtest "Payment notice tests" => sub {
     my $id = $account->pay( { amount => 1 } );
     is( Koha::Notice::Messages->search()->count(), 0, 'Notice for payment not sent if UseEmailReceipts is disabled' );
 
-    $id = $account->pay( { amount => 1, type => 'writeoff' } );
+    $id = $account->pay( { amount => 1, type => 'WRITEOFF' } );
     is( Koha::Notice::Messages->search()->count(), 0, 'Notice for writeoff not sent if UseEmailReceipts is disabled' );
 
     t::lib::Mocks::mock_preference('UseEmailReceipts', '1');
@@ -1196,7 +1196,7 @@ subtest "Payment notice tests" => sub {
     $letter->content('[%- USE Price -%]A writeoff of [% credit.amount * -1 | $Price %] has been applied to your account.');
     $letter->store();
 
-    $id = $account->pay( { amount => 13, type => 'writeoff' } );
+    $id = $account->pay( { amount => 13, type => 'WRITEOFF' } );
     $notice = Koha::Notice::Messages->search()->next();
     is( $notice->subject, 'Account writeoff', 'Notice subject is correct for payment' );
     is( $notice->letter_code, 'ACCOUNT_WRITEOFF', 'Notice letter code is correct for writeoff' );
index 0f78fa5..dddedd9 100755 (executable)
@@ -2148,7 +2148,7 @@ subtest '_FixAccountForLostAndReturned' => sub {
         # Write off the debt
         my $credit = $account->add_credit(
             {   amount => $account->balance,
-                type   => 'writeoff',
+                type   => 'WRITEOFF',
                 interface => 'test',
             }
         );
@@ -2345,7 +2345,7 @@ subtest '_FixAccountForLostAndReturned' => sub {
         my $write_off_amount = 25;
         my $write_off        = $account->add_credit(
             {   amount => $write_off_amount,
-                type   => 'writeoff',
+                type   => 'WRITEOFF',
                 interface => 'test',
             }
         );