From b73e08da69943a94d8f24dcd8d21f478d5e1e461 Mon Sep 17 00:00:00 2001
From: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Date: Wed, 2 Oct 2019 15:27:00 +0100
Subject: [PATCH] Bug 23049: Use debit_type in staff client views
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr>
---
 Koha/Account/Line.pm                               | 14 ++++++
 .../intranet-tmpl/prog/en/includes/accounts.inc    | 54 +++++++++++++---------
 2 files changed, 45 insertions(+), 23 deletions(-)

diff --git a/Koha/Account/Line.pm b/Koha/Account/Line.pm
index 124aa29..1f70bb1 100644
--- a/Koha/Account/Line.pm
+++ b/Koha/Account/Line.pm
@@ -22,6 +22,7 @@ use Data::Dumper;
 
 use C4::Log qw(logaction);
 
+use Koha::Account::DebitType;
 use Koha::Account::Offsets;
 use Koha::Database;
 use Koha::Exceptions::Account;
@@ -82,6 +83,19 @@ sub checkout {
     return $self->{_checkout};
 }
 
+=head3 debit_type
+
+Return the debit_type linked to this account line
+
+=cut
+
+sub debit_type {
+    my ( $self ) = @_;
+    my $rs = $self->_result->debit_type;
+    return unless $rs;
+    return Koha::Account::DebitType->_new_from_dbic( $rs );
+}
+
 =head3 void
 
   $payment_accountline->void();
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/accounts.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/accounts.inc
index 61a31a2..75bd7f7 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/accounts.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/accounts.inc
@@ -1,28 +1,36 @@
 [%- BLOCK account_type_description -%]
-    [%- SWITCH account.accounttype -%]
-        [%- CASE 'Pay'              -%]<span>Payment
-        [%- CASE 'N'                -%]<span>New card
-        [%- CASE 'OVERDUE'          -%]<span>Fine
-        [%- CASE 'ACCOUNT'          -%]<span>Account creation fee
-        [%- CASE 'ACCOUNT_RENEW'    -%]<span>Account renewal fee
-        [%- CASE 'M'                -%]<span>Sundry
-        [%- CASE 'LOST'             -%]<span>Lost item
-        [%- CASE 'W'                -%]<span>Writeoff
-        [%- CASE 'HE'               -%]<span>Hold waiting too long
-        [%- CASE 'RENT'             -%]<span>Rental fee
-        [%- CASE 'RENT_DAILY'       -%]<span>Daily rental fee
-        [%- CASE 'RENT_RENEW'       -%]<span>Renewal of rental item
-        [%- CASE 'RENT_DAILY_RENEW' -%]<span>Rewewal of daily rental item
-        [%- CASE 'FOR'              -%]<span>Forgiven
-        [%- CASE 'PF'               -%]<span>Lost item processing fee
-        [%- CASE 'PAY'              -%]<span>Payment
-        [%- CASE 'WO'               -%]<span>Writeoff
-        [%- CASE 'C'                -%]<span>Credit
-        [%- CASE 'LOST_RETURN'      -%]<span>Lost item fee refund
-        [%- CASE 'Res'              -%]<span>Hold fee
-        [%- CASE                    -%]<span>[% account.accounttype | html %]
+    <span>
+    [%- IF account.accounttype -%]
+        [%- SWITCH account.accounttype -%]
+            [%- CASE 'Pay'              -%]Payment
+            [%- CASE 'W'                -%]Writeoff
+            [%- CASE 'FOR'              -%]Forgiven
+            [%- CASE 'PAY'              -%]Payment
+            [%- CASE 'WO'               -%]Writeoff
+            [%- CASE 'C'                -%]Credit
+            [%- CASE 'LOST_RETURN'      -%]Lost item fee refund
+            [%- CASE                    -%][% account.accounttype | html %]
+        [%- END -%]
+    [%- ELSIF account.debit_type -%]
+       [%- SWITCH account.debit_type -%]
+           [%- CASE 'N'                -%]New card
+           [%- CASE 'OVERDUE'          -%]Fine
+           [%- CASE 'ACCOUNT'          -%]Account creation fee
+           [%- CASE 'ACCOUNT_RENEW'    -%]Account renewal fee
+           [%- CASE 'M'                -%]Sundry
+           [%- CASE 'LOST'             -%]Lost item
+           [%- CASE 'HE'               -%]Hold waiting too long
+           [%- CASE 'RENT'             -%]Rental fee
+           [%- CASE 'RENT_DAILY'       -%]Daily rental fee
+           [%- CASE 'RENT_RENEW'       -%]Renewal of rental item
+           [%- CASE 'RENT_DAILY_RENEW' -%]Rewewal of daily rental item
+           [%- CASE 'PF'               -%]Lost item processing fee
+           [%- CASE 'Res'              -%]Hold fee
+           [%- CASE                    -%][% account.debit_type.description | html %]
+       [%- END -%]
     [%- END -%]
-    [%- PROCESS account_status_description account=account -%]</span>
+    [%- PROCESS account_status_description account=account -%]
+    </span>
 [%- END -%]
 
 [%- BLOCK offset_type_description -%]
-- 
2.7.4