From 684f42b2d3341a99aca87af241592c64b3e48aa5 Mon Sep 17 00:00:00 2001
From: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Date: Thu, 3 Oct 2019 12:22:47 +0100
Subject: [PATCH] Bug 23049: (follow-up) Impliment feedback

---
 .../mysql/atomicupdate/bug_23049_debit.perl   |  8 +--
 installer/data/mysql/kohastructure.sql        |  6 +--
 .../prog/en/modules/admin/debit_types.tt      | 50 +++++++++----------
 3 files changed, 31 insertions(+), 33 deletions(-)

diff --git a/installer/data/mysql/atomicupdate/bug_23049_debit.perl b/installer/data/mysql/atomicupdate/bug_23049_debit.perl
index 9219a95cb9..14949991e8 100644
--- a/installer/data/mysql/atomicupdate/bug_23049_debit.perl
+++ b/installer/data/mysql/atomicupdate/bug_23049_debit.perl
@@ -4,7 +4,7 @@ if ( CheckVersion($DBversion) ) {
     $dbh->do(
         qq{
             CREATE TABLE IF NOT EXISTS account_debit_types (
-              code varchar(16) NOT NULL,
+              code varchar(64) NOT NULL,
               description varchar(200) NULL,
               can_be_added_manually tinyint(4) NOT NULL DEFAULT '1',
               default_amount decimal(28, 6) NULL,
@@ -16,7 +16,7 @@ if ( CheckVersion($DBversion) ) {
     $dbh->do(
         qq{
             CREATE TABLE IF NOT EXISTS ac_debit_types_branches (
-                debit_type_code VARCHAR(16),
+                debit_type_code VARCHAR(64),
                 branchcode VARCHAR(10),
                 FOREIGN KEY (debit_type_code) REFERENCES account_debit_types(code) ON DELETE CASCADE,
                 FOREIGN KEY (branchcode) REFERENCES branches(branchcode) ON DELETE CASCADE
@@ -58,7 +58,7 @@ if ( CheckVersion($DBversion) ) {
               can_be_added_manually
             )
             SELECT
-              SUBSTR(authorised_value, 1, 16),
+              SUBSTR(authorised_value, 1, 64),
               lib,
               authorised_value,
               1
@@ -73,7 +73,7 @@ if ( CheckVersion($DBversion) ) {
         qq{
             ALTER IGNORE TABLE accountlines
             ADD
-              debit_type varchar(16) DEFAULT NULL
+              debit_type varchar(64) DEFAULT NULL
             AFTER
               accounttype
           }
diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql
index a70c5c2b31..0064348a75 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -2627,7 +2627,7 @@ CREATE TABLE `cash_registers` (
 
 DROP TABLE IF EXISTS `account_debit_types`;
 CREATE TABLE `account_debit_types` (
-  `code` varchar(16) NOT NULL,
+  `code` varchar(64) NOT NULL,
   `default_amount` decimal(28,6) DEFAULT NULL,
   `description` varchar(200) DEFAULT NULL,
   `can_be_added_manually` tinyint(4) NOT NULL DEFAULT '1',
@@ -2640,7 +2640,7 @@ CREATE TABLE `account_debit_types` (
 
 DROP TABLE IF EXISTS `ac_debit_types_branches`;
 CREATE TABLE `ac_debit_types_branches` (
-    `debit_type_code` VARCHAR(16),
+    `debit_type_code` VARCHAR(64),
     `branchcode` VARCHAR(10),
     FOREIGN KEY (`debit_type_code`) REFERENCES `account_debit_types` (`code`) ON DELETE CASCADE,
     FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE
@@ -2660,7 +2660,7 @@ CREATE TABLE `accountlines` (
   `amount` decimal(28,6) default NULL,
   `description` LONGTEXT,
   `accounttype` varchar(80) default NULL,
-  `debit_type` varchar(16) default NULL,
+  `debit_type` varchar(64) default NULL,
   `status` varchar(16) default NULL,
   `payment_type` varchar(80) default NULL, -- optional authorised value PAYMENT_TYPE
   `amountoutstanding` decimal(28,6) default NULL,
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/debit_types.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/debit_types.tt
index 174656440a..16e056a717 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/debit_types.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/debit_types.tt
@@ -6,18 +6,18 @@
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Administration &rsaquo;
     [% IF op =='add_form' %]
-        Account types &rsaquo;
+       Debit types &rsaquo;
        [% IF debit_type.code %]
-           Modify account [% type %] type
+           Modify debit type
        [% ELSE %]
-           New account [% type %] type
+           New debit type
        [% END %]
     [% ELSE %]
-        [% IF op == 'delete_confirm' %]
-            Account types &rsaquo; Confirm deletion of account [% type %] type
-        [% ELSE %]
-            Account types
-        [% END %]
+       [% IF op == 'delete_confirm' %]
+           Debit types &rsaquo; Confirm deletion of debit type
+       [% ELSE %]
+           Debit types
+       [% END %]
     [% END %]
 </title>
 [% INCLUDE 'doc-head-close.inc' %]
@@ -30,11 +30,11 @@
 <div id="breadcrumbs">
     <a href="/cgi-bin/koha/mainpage.pl">Home</a>
 &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
-&rsaquo; <a href="/cgi-bin/koha/admin/debit_types.pl">Account types</a>
+&rsaquo; <a href="/cgi-bin/koha/admin/debit_types.pl">Debit types</a>
 [% IF op == 'add_form' %]
-&rsaquo; [% IF debit_type.code %]Modify[% ELSE %]New[% END %] Account [% type %] type
+&rsaquo; [% IF debit_type.code %]Modify[% ELSE %]New[% END %] debit type
 [% ELSIF op == 'delete_confirm' %]
-&rsaquo; Confirm deletion of account [% type %] type
+&rsaquo; Confirm deletion of debit type
 [% END %]
 </div>
 
@@ -47,13 +47,13 @@
                 <div class="dialog [% m.type %]">
                     [% SWITCH m.code %]
                     [% CASE 'error_on_saving' %]
-                        An error occurred when saving this account type.
+                        An error occurred when saving this debit type.
                     [% CASE 'error_on_delete' %]
-                        An error occurred when deleting this account type. Check the logs.
+                        An error occurred when deleting this debit type. Check the logs.
                     [% CASE 'success_on_saving' %]
-                        Account type saved successfully.
+                        Debit type saved successfully.
                     [% CASE 'success_on_delete' %]
-                        Account type deleted successfully.
+                        Debit type deleted successfully.
                     [% CASE %]
                         [% m.code %]
                     [% END %]
@@ -62,9 +62,9 @@
 
                 [% IF op == 'add_form' %]
                     [% IF debit_type %]
-                        <h3>Modify an account [% type %] type</h3>
+                        <h3>Modify a debit type</h3>
                     [% ELSE %]
-                        <h3>New account [% type %] type</h3>
+                        <h3>New debit type</h3>
                     [% END %]
 
                     <form action="/cgi-bin/koha/admin/debit_types.pl" name="Aform" method="post" class="validated">
@@ -73,20 +73,18 @@
                         <fieldset class="rows">
                             <ol>
                                 <li>
-                                    <label for="code" class="required">Account [% type | html %] type code: </label>
+                                    <label for="code" class="required">Debit type code: </label>
                                     [% IF debit_type %]
                                         <strong>[% debit_type.code | html %]</strong>
                                         <input type="hidden" name="code" value="[% code %]" />
                                     [% ELSE %]
-                                    <input type="text" name="code" id="code" size="10" maxlength="5" class="required" required="required"><span class="required">Required. Maximum length is 16 letters</span>
+                                    <input type="text" name="code" id="code" size="80" maxlength="64" class="required" required="required"><span class="required">Required. Maximum length is 64 letters</span>
                                     [% END %]
                                 </li>
-                                [% IF type == 'debit' %]
                                 <li>
                                     <label for="default_amount">Default amount: </label>
-                                    <input type="text" name="default_amount" id="default_amount" size="80" maxlength="100" value="[% debit_type.default_amount | html %]" />
+                                    <input type="text" pattern="^\d+(\.\d{2})?$" name="default_amount" id="default_amount" size="80" maxlength="100" value="[% debit_type.default_amount | $Price on_editing => 1 %]" step="any" min="0"/>
                                 </li>
-                                [% END %]
                                 <li>
                                     <label for="description" class="required">Description: </label>
                                     <input type="text" name="description" id="description" required="required" class="required" size="80" maxlength="100" value="[% debit_type.description | html %]" /> <span class="required">Required</span>
@@ -125,12 +123,12 @@
 
                 [% IF op == 'delete_confirm' %]
                     <div class="dialog alert">
-                        <h3>Delete account [% type | html %] type "[% debit_type.description | html %]?"</h3>
+                        <h3>Delete debit type "[% debit_type.description | html %]?"</h3>
                         <table>
-                            <tr><th>Account type code</th>
+                            <tr><th>Debit type code</th>
                                 <td>[% debit_type.code | html %]</td>
                             </tr>
-                            <tr><th>Account type description</th>
+                            <tr><th>Debit type description</th>
                                 <td>[% debit_type.description | html %]</td>
                             </tr>
                         </table>
@@ -156,7 +154,7 @@
                         <table id="table_debit_types">
                             <thead>
                                 <th>System</th>
-                                <th>Account type code</th>
+                                <th>Code</th>
                                 <th>Description</th>
                                 <th>Default amount</th>
                                 <th>Can be added manually</th>
-- 
2.20.1