From b2b651d13db5471f674e82c7ff0693f2ad7ec410 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 17 Oct 2019 12:28:18 +0100 Subject: [PATCH] Bug 23049: (follow-up) Types should not be deletable This patch rmeoves the 'delete' option from the debit_types system and replaces it with an 'archive/restore' workflow. This will help maintained referential integrity. Signed-off-by: Marcel de Rooy Signed-off-by: Martin Renvoize --- Koha/Schema/Result/Accountline.pm | 6 +- admin/debit_types.pl | 43 ++++++++------ .../mysql/atomicupdate/bug_23049_debit.perl | 1 + installer/data/mysql/kohastructure.sql | 1 + .../prog/en/modules/admin/debit_types.tt | 58 ++++++------------- 5 files changed, 46 insertions(+), 63 deletions(-) diff --git a/Koha/Schema/Result/Accountline.pm b/Koha/Schema/Result/Accountline.pm index a30290dcab..1561f99d68 100644 --- a/Koha/Schema/Result/Accountline.pm +++ b/Koha/Schema/Result/Accountline.pm @@ -276,7 +276,7 @@ __PACKAGE__->belongs_to( { is_deferrable => 1, join_type => "LEFT", - on_delete => "SET NULL", + on_delete => "RESTRICT", on_update => "CASCADE", }, ); @@ -342,8 +342,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-10-11 11:36:33 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:WZ2Mcd5gwQc69yDSEsJHGA +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-10-17 11:33:03 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:5FjSicyeyUnnNh/pGs78zQ sub koha_objects_class { 'Koha::Account::Lines'; diff --git a/admin/debit_types.pl b/admin/debit_types.pl index 8750d70c9d..89decf1160 100755 --- a/admin/debit_types.pl +++ b/admin/debit_types.pl @@ -19,6 +19,8 @@ use Modern::Perl; use CGI qw ( -utf8 ); +use Try::Tiny; + use C4::Context; use C4::Auth; use C4::Output; @@ -85,38 +87,41 @@ elsif ( $op eq 'add_validate' ) { $debit_type->can_be_added_manually($can_be_added_manually); $debit_type->default_amount($default_amount); - eval { + try { $debit_type->store; $debit_type->replace_library_limits( \@branches ); - }; - if ($@) { - push @messages, { type => 'error', code => 'error_on_saving' }; - } - else { push @messages, { type => 'message', code => 'success_on_saving' }; } + catch { + push @messages, { type => 'error', code => 'error_on_saving' }; + }; $op = 'list'; } -elsif ( $op eq 'delete_confirm' ) { - $template->param( debit_type => $debit_type ); -} -elsif ( $op eq 'delete_confirmed' ) { - my $deleted = eval { $debit_type->delete; }; - - if ( $@ or not $deleted ) { - push @messages, { type => 'error', code => 'error_on_delete' }; +elsif ( $op eq 'archive' ) { + try { + $debit_type->archived(1)->store(); + push @messages, { code => 'success_on_archive', type => 'message' }; } - else { - push @messages, { type => 'message', code => 'success_on_delete' }; + catch { + push @messages, { code => 'error_on_archive', type => 'alert' }; + + }; + $op = 'list'; +} +elsif ( $op eq 'unarchive' ) { + try { + $debit_type->archived(0)->store(); + push @messages, { code => 'success_on_restore', type => 'message' }; } + catch { + push @messages, { code => 'error_on_restore', type => 'alert' }; + }; $op = 'list'; } if ( $op eq 'list' ) { my $debit_types = Koha::Account::DebitTypes->search(); - $template->param( - debit_types => $debit_types, - ); + $template->param( debit_types => $debit_types, ); } $template->param( diff --git a/installer/data/mysql/atomicupdate/bug_23049_debit.perl b/installer/data/mysql/atomicupdate/bug_23049_debit.perl index c55dc27e26..8ed3820b9c 100644 --- a/installer/data/mysql/atomicupdate/bug_23049_debit.perl +++ b/installer/data/mysql/atomicupdate/bug_23049_debit.perl @@ -10,6 +10,7 @@ if ( CheckVersion($DBversion) ) { can_be_added_manually tinyint(4) NOT NULL DEFAULT 1, default_amount decimal(28, 6) NULL, is_system tinyint(1) NOT NULL DEFAULT 0, + archived tinyint(1) NOT NULL DEFAULT 0, PRIMARY KEY (code) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci } diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 67b087e8f9..c11e9e245a 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2632,6 +2632,7 @@ CREATE TABLE `account_debit_types` ( `can_be_added_manually` tinyint(4) NOT NULL DEFAULT 1, `default_amount` decimal(28,6) DEFAULT NULL, `is_system` tinyint(1) NOT NULL DEFAULT 0, + `archived` tinyint(1) NOT NULL DEFAULT 0, -- boolean flag to denote if this till is archived or not PRIMARY KEY (`code`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; 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 05b5161519..2fdf187ff2 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 @@ -13,11 +13,7 @@ New debit type [% END %] [% ELSE %] - [% IF op == 'delete_confirm' %] - Debit types › Confirm deletion of debit type - [% ELSE %] - Debit types - [% END %] + Debit types [% END %] [% INCLUDE 'doc-head-close.inc' %] @@ -33,8 +29,6 @@ › Debit types [% IF op == 'add_form' %] › [% IF debit_type.code %]Modify[% ELSE %]New[% END %] debit type -[% ELSIF op == 'delete_confirm' %] -› Confirm deletion of debit type [% END %] @@ -46,14 +40,14 @@ [% FOREACH m IN messages %]
[% SWITCH m.code %] - [% CASE 'error_on_saving' %] - An error occurred when saving this debit type. - [% CASE 'error_on_delete' %] - An error occurred when deleting this debit type. Check the logs. [% CASE 'success_on_saving' %] Debit type saved successfully. - [% CASE 'success_on_delete' %] - Debit type deleted successfully. + [% CASE 'error_on_saving' %] + An error occurred when saving this debit type. + [% CASE 'success_on_archive' %] + Debit type archived successfully. + [% CASE 'success_on_restore' %] + Debit type restored successfully. [% CASE %] [% m.code | html %] [% END %] @@ -120,28 +114,6 @@ [% END %] - [% IF op == 'delete_confirm' %] -
-

Delete debit type "[% debit_type.description | html %]?"

- - - - - - - -
Debit type code[% debit_type.code | html %]
Debit type description[% debit_type.description | html %]
-
- - - -
-
- -
-
- [% END %] - [% IF op == 'list' %]
New debit type @@ -151,6 +123,7 @@ [% IF debit_types.count %] + @@ -162,6 +135,7 @@ [% FOREACH debit_type IN debit_types %] + @@ -188,9 +162,11 @@ [% END %] @@ -224,9 +200,9 @@ var table_debit_types = $("#table_debit_types").dataTable($.extend(true, {}, dataTablesDefaults, { "aoColumnDefs": [ { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false }, - { "aTargets": [ 0 ], "bSortable": false, "bVisible": false }, + { "aTargets": [ 0, 1 ], "bSortable": false, "bVisible": false }, ], - "aaSorting": [[ 1, "asc" ]], + "aaSorting": [[ 0, "asc" ],[ 2, "asc" ]], "sDom": 'C<"top pager"ilpfB><"#filter_s">tr<"bottom pager"ip>', "iDisplayLength": 20, "sPaginationType": "full_numbers" @@ -241,7 +217,7 @@ var filteredValue = '0'; $(this).html(' '+txtInactivefilter); } - table_debit_types.fnFilter(filteredValue, 0, false, false); + table_debit_types.fnFilter(filteredValue, 1, false, false); $(this).toggleClass('filtered'); }); -- 2.39.5
Archived System Code Description
[% debit_type.archived | html %] [% debit_type.is_system | html %] [% debit_type.code | html %] [% debit_type.description | html %] - [% IF !debit_type.is_system %] - Edit - Delete + [% IF !debit_type.is_system && !debit_type.archived %] + Edit + Archive + [% ELSIF debit_type.archived %] + Restore [% END %]