Bugzilla – Attachment 93567 Details for
Bug 23049
Replace MANUAL_INV authorised value with a dedicated table
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23049: Add debit_type
Bug-23049-Add-debittype.patch (text/plain), 14.56 KB, created by
Biblibre Sandboxes
on 2019-10-03 11:54:18 UTC
(
hide
)
Description:
Bug 23049: Add debit_type
Filename:
MIME Type:
Creator:
Biblibre Sandboxes
Created:
2019-10-03 11:54:18 UTC
Size:
14.56 KB
patch
obsolete
>From 59997faed91bafcc158a2170d3d8c49fe2a4cf2a Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Thu, 28 Feb 2019 16:58:06 +0000 >Subject: [PATCH] Bug 23049: Add debit_type >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >* Add account_debit_types table >* Add account_debit_types defaults >* Add Koha::Account::DebitType and Koha::Account::DebitTypes >* Prevent deletion of defaults >* Update database to insert existing values > >Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr> >--- > C4/Installer.pm | 1 + > Koha/Account/DebitType.pm | 93 ++++++++++++++++++++++ > Koha/Account/DebitTypes.pm | 68 ++++++++++++++++ > installer/data/mysql/account_debit_types.sql | 14 ++++ > .../data/mysql/atomicupdate/bug_23049_debit.perl | 92 +++++++++++++++++++++ > .../mysql/en/mandatory/account_debit_types.sql | 13 +++ > installer/data/mysql/en/optional/auth_val.sql | 3 - > installer/data/mysql/kohastructure.sql | 18 ++++- > misc/devel/populate_db.pl | 1 + > 9 files changed, 299 insertions(+), 4 deletions(-) > create mode 100644 Koha/Account/DebitType.pm > create mode 100644 Koha/Account/DebitTypes.pm > create mode 100644 installer/data/mysql/account_debit_types.sql > create mode 100644 installer/data/mysql/atomicupdate/bug_23049_debit.perl > create mode 100644 installer/data/mysql/en/mandatory/account_debit_types.sql > >diff --git a/C4/Installer.pm b/C4/Installer.pm >index 9b24ff3..e4cae05 100644 >--- a/C4/Installer.pm >+++ b/C4/Installer.pm >@@ -332,6 +332,7 @@ sub load_sql_in_order { > push @fnames, C4::Context->config('intranetdir') . "/installer/data/mysql/userpermissions.sql"; > push @fnames, C4::Context->config('intranetdir') . "/installer/data/mysql/audio_alerts.sql"; > push @fnames, C4::Context->config('intranetdir') . "/installer/data/mysql/account_offset_types.sql"; >+ push @fnames, C4::Context->config('intranetdir') . "/installer/data/mysql/account_debit_types.sql"; > foreach my $file (@fnames) { > # warn $file; > undef $/; >diff --git a/Koha/Account/DebitType.pm b/Koha/Account/DebitType.pm >new file mode 100644 >index 0000000..1ded508 >--- /dev/null >+++ b/Koha/Account/DebitType.pm >@@ -0,0 +1,93 @@ >+package Koha::Account::DebitType; >+ >+# Copyright PTFS Europe 2019 >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+use List::Util qw/any/; >+ >+use Koha::Database; >+use Koha::Exceptions; >+ >+use base qw(Koha::Object); >+ >+=head1 NAME >+ >+Koha::Account::DebitType - Koha Account debit type Object class >+ >+=head1 CONSTANTS >+ >+=head2 System defaults >+ >+A list of system default debit types which should not be deleted >+ >+=cut >+ >+our @defaults = ( >+ "ACCOUNT", "ACCOUNT_RENEW", "HE", "LOST", "M", "N", "OVERDUE", "PF", >+ "RENT", "RENT_DAILY", "RENT_RENEW", "RENT_DAILY_RENEW", "Res" >+); >+ >+=head1 API >+ >+=head2 Class Methods >+ >+=cut >+ >+=head3 delete >+ >+Overridden delete method to prevent system default deletions >+ >+=cut >+ >+sub delete { >+ my ($self) = @_; >+ >+ if ( any { $self->code eq $_ } @defaults ) { >+ Koha::Exceptions::CannotDeleteDefault->throw; >+ } >+ return $self->SUPER::delete; >+} >+ >+=head1 is_system >+ >+Accessor returning boolean signalling system default DebitType >+ >+=cut >+ >+sub is_system { >+ my ($self) = @_; >+ return ( any { $self->code eq $_ } @defaults ) ? 1 : 0; >+} >+ >+=head3 defaults >+ >+=cut >+ >+sub defaults { >+ return \@defaults; >+} >+ >+=head3 type >+ >+=cut >+ >+sub _type { >+ return 'AccountDebitType'; >+} >+ >+1; >diff --git a/Koha/Account/DebitTypes.pm b/Koha/Account/DebitTypes.pm >new file mode 100644 >index 0000000..7f4a258 >--- /dev/null >+++ b/Koha/Account/DebitTypes.pm >@@ -0,0 +1,68 @@ >+package Koha::Account::DebitTypes; >+ >+# Copyright PTFS Europe 2019 >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+use List::Util qw/any/; >+ >+use Koha::Database; >+use Koha::Account::DebitType; >+ >+use base qw(Koha::Objects); >+ >+=head1 NAME >+ >+Koha::Account::DebitTypes - Koha Account debit types Object set class >+ >+=head1 API >+ >+=head2 Class Methods >+ >+=head3 delete >+ >+Overridden delete method to prevent system default deletions >+ >+=cut >+ >+sub delete { >+ my ($self) = @_; >+ >+ my @set = $self->as_list; >+ my $defaults = Koha::Account::DebitType::defaults; >+ for my $type (@set) { >+ if ( any { $type->code eq $_ } @{$defaults} ) { >+ Koha::Exceptions::CannotDeleteDefault->throw; >+ } >+ } >+ >+ return $self->SUPER::delete; >+} >+ >+=head3 type >+ >+=cut >+ >+sub _type { >+ return 'AccountDebitType'; >+} >+ >+sub object_class { >+ return 'Koha::Account::DebitType'; >+} >+ >+1; >diff --git a/installer/data/mysql/account_debit_types.sql b/installer/data/mysql/account_debit_types.sql >new file mode 100644 >index 0000000..78ee2f8 >--- /dev/null >+++ b/installer/data/mysql/account_debit_types.sql >@@ -0,0 +1,14 @@ >+INSERT INTO account_debit_types ( code, description, can_be_added_manually, default_amount ) VALUES >+('ACCOUNT', 'Account creation fee', 0, NULL), >+('ACCOUNT_RENEW', 'Account renewal fee', 0, NULL), >+('HE', 'Hold waiting too long', 0, NULL), >+('LOST', 'Lost item', 1, NULL), >+('M', 'Manual fee', 1, NULL), >+('N', 'New card fee', 1, NULL), >+('OVERDUE', 'Overdue fine', 0, NULL), >+('PF', 'Lost item processing fee', 0, NULL), >+('RENT', 'Rental fee', 0, NULL), >+('RENT_DAILY', 'Daily rental fee', 0, NULL), >+('RENT_RENEW', 'Renewal of rental item', 0, NULL), >+('RENT_DAILY_RENEW', 'Rewewal of daily rental item', 0, NULL), >+('Res', 'Hold fee', 0, NULL); >diff --git a/installer/data/mysql/atomicupdate/bug_23049_debit.perl b/installer/data/mysql/atomicupdate/bug_23049_debit.perl >new file mode 100644 >index 0000000..b834704 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_23049_debit.perl >@@ -0,0 +1,92 @@ >+$DBversion = 'XXX'; # will be replaced by the RM >+if ( CheckVersion($DBversion) ) { >+ >+ $dbh->do( >+ qq{ >+ CREATE TABLE IF NOT EXISTS account_debit_types ( >+ code varchar(16) NOT NULL, >+ description varchar(200) NULL, >+ can_be_added_manually tinyint(4) NOT NULL DEFAULT '1', >+ default_amount decimal(28, 6) NULL, >+ PRIMARY KEY (code) >+ ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci >+ } >+ ); >+ >+ $dbh->do( >+ qq{ >+ INSERT IGNORE INTO account_debit_types ( >+ code, >+ description, >+ can_be_added_manually, >+ default_amount >+ ) >+ VALUES >+ ('ACCOUNT', 'Account creation fee', 0, NULL), >+ ('ACCOUNT_RENEW', 'Account renewal fee', 0, NULL), >+ ('HE', 'Hold waiting too long', 0, NULL), >+ ('LOST', 'Lost item', 1, NULL), >+ ('M', 'Manual fee', 1, NULL), >+ ('N', 'New card fee', 1, NULL), >+ ('OVERDUE', 'Overdue fine', 0, NULL), >+ ('PF', 'Lost item processing fee', 0, NULL), >+ ('RENT', 'Rental fee', 0, NULL), >+ ('RENT_DAILY', 'Daily rental fee', 0, NULL), >+ ('RENT_RENEW', 'Renewal of rental item', 0, NULL), >+ ('RENT_DAILY_RENEW', 'Rewewal of daily rental item', 0, NULL), >+ ('Res', 'Hold fee', 0, NULL) >+ } >+ ); >+ >+ $dbh->do( >+ qq{ >+ INSERT IGNORE INTO account_debit_types ( >+ code, >+ default_amount, >+ description, >+ can_be_added_manually >+ ) >+ SELECT >+ SUBSTR(authorised_value, 1, 16), >+ lib, >+ authorised_value, >+ 1 >+ FROM >+ authorised_values >+ WHERE >+ category = 'MANUAL_INV' >+ } >+ ); >+ >+ $dbh->do( >+ qq{ >+ ALTER IGNORE TABLE accountlines >+ ADD >+ debit_type varchar(16) DEFAULT NULL >+ AFTER >+ accounttype >+ } >+ ); >+ >+ $dbh->do( >+ qq{ >+ ALTER TABLE accountlines ADD CONSTRAINT `accountlines_ibfk_debit_type` FOREIGN KEY (`debit_type`) REFERENCES `account_debit_types` (`code`) ON DELETE SET NULL ON UPDATE CASCADE >+ } >+ ); >+ >+ # Add new permission >+ $dbh->do( >+ q{ >+ INSERT IGNORE INTO permissions (module_bit, code, description) >+ VALUES >+ ( >+ 3, >+ 'manage_accounts', >+ 'Manage Account Debit and Credit Types' >+ ) >+ } >+ ); >+ >+ SetVersion($DBversion); >+ print "Upgrade to $DBversion done (Bug 23049 - Add account debit_types)\n"; >+} >diff --git a/installer/data/mysql/en/mandatory/account_debit_types.sql b/installer/data/mysql/en/mandatory/account_debit_types.sql >new file mode 100644 >index 0000000..8befd9a >--- /dev/null >+++ b/installer/data/mysql/en/mandatory/account_debit_types.sql >@@ -0,0 +1,13 @@ >+INSERT INTO account_debit_types (code, default_amount, description, can_be_added_manually) VALUES >+ ('A', NULL, 'Account management fee', 1), >+ ('F', NULL, 'Overdue fine', 1), >+ ('FU', NULL, 'Accruing overdue fine', 0), >+ ('L', NULL, 'Lost item', 1), >+ ('LR', NULL, 'Lost and returned', 0), >+ ('M', NULL, 'Sundry', 1), >+ ('N', NULL, 'New card', 1), >+ ('O', NULL, 'Overdue fine', 0), >+ ('Rent', NULL, 'Rental fee', 1), >+ ('Rep', NULL, 'Replacement', 0), >+ ('Res', NULL, 'Reserve charge', 1), >+ ('Copie', 0.5, 'Copier fees', 1); >diff --git a/installer/data/mysql/en/optional/auth_val.sql b/installer/data/mysql/en/optional/auth_val.sql >index 24f036b..b4e00fd 100644 >--- a/installer/data/mysql/en/optional/auth_val.sql >+++ b/installer/data/mysql/en/optional/auth_val.sql >@@ -48,9 +48,6 @@ INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('NOT_L > -- restricted status of an item, linked to items.restricted > INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('RESTRICTED','1','Restricted Access'); > >--- manual invoice types >-INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('MANUAL_INV','Copier Fees','.25'); >- > -- custom borrower notes > INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('BOR_NOTES','ADDR','Address Notes'); > >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index 7073c9a..4a9889b 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -2622,6 +2622,19 @@ CREATE TABLE `cash_registers` ( > ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci; > > -- >+-- Table structure for table `account_debit_types` >+-- >+ >+DROP TABLE IF EXISTS `account_debit_types`; >+CREATE TABLE `account_debit_types` ( >+ `code` varchar(16) NOT NULL, >+ `default_amount` decimal(28,6) DEFAULT NULL, >+ `description` varchar(200) DEFAULT NULL, >+ `can_be_added_manually` tinyint(4) NOT NULL DEFAULT '1', >+ PRIMARY KEY (`code`) >+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; >+ >+-- > -- Table structure for table `accountlines` > -- > >@@ -2635,6 +2648,7 @@ CREATE TABLE `accountlines` ( > `amount` decimal(28,6) default NULL, > `description` LONGTEXT, > `accounttype` varchar(80) default NULL, >+ `debit_type` varchar(16) default NULL, > `status` varchar(16) default NULL, > `payment_type` varchar(80) default NULL, -- optional authorised value PAYMENT_TYPE > `amountoutstanding` decimal(28,6) default NULL, >@@ -2647,6 +2661,7 @@ CREATE TABLE `accountlines` ( > PRIMARY KEY (`accountlines_id`), > KEY `acctsborridx` (`borrowernumber`), > KEY `timeidx` (`timestamp`), >+ KEY `debit_type` (`debit_type`), > KEY `itemnumber` (`itemnumber`), > KEY `branchcode` (`branchcode`), > KEY `manager_id` (`manager_id`), >@@ -2654,7 +2669,8 @@ CREATE TABLE `accountlines` ( > CONSTRAINT `accountlines_ibfk_items` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE SET NULL ON UPDATE CASCADE, > CONSTRAINT `accountlines_ibfk_borrowers_2` FOREIGN KEY (`manager_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE, > CONSTRAINT `accountlines_ibfk_branches` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE, >- CONSTRAINT `accountlines_ibfk_registers` FOREIGN KEY (`register_id`) REFERENCES `cash_registers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE >+ CONSTRAINT `accountlines_ibfk_registers` FOREIGN KEY (`register_id`) REFERENCES `cash_registers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, >+ CONSTRAINT `accountlines_ibfk_debit_type` FOREIGN KEY (`debit_type`) REFERENCES `account_debit_types` (`code`) ON DELETE SET NULL ON UPDATE CASCADE > ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; > > -- >diff --git a/misc/devel/populate_db.pl b/misc/devel/populate_db.pl >index f2cb974..341c530 100755 >--- a/misc/devel/populate_db.pl >+++ b/misc/devel/populate_db.pl >@@ -108,6 +108,7 @@ my @sample_files_mandatory = ( > "$data_dir/userflags.sql", > "$data_dir/userpermissions.sql", > "$data_dir/account_offset_types.sql", >+ "$data_dir/account_debit_types.sql", > ); > my @sample_lang_files_mandatory = ( glob $root . "/installer/data/mysql/$lang/mandatory/*.sql" ); > my @sample_lang_files_optional = ( glob $root . "/installer/data/mysql/$lang/optional/*.sql" ); >-- >2.7.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 23049
:
93513
|
93514
|
93515
|
93516
|
93518
|
93519
|
93520
|
93521
|
93522
|
93523
|
93529
|
93557
|
93564
|
93565
|
93567
|
93568
|
93569
|
93570
|
93571
|
93572
|
93573
|
93574
|
93575
|
93576
|
93577
|
93578
|
93579
|
93960
|
93961
|
93962
|
93963
|
93964
|
93965
|
93966
|
93967
|
93968
|
93969
|
93970
|
93972
|
93973
|
93974
|
93975
|
93976
|
93977
|
93978
|
93979
|
93989
|
93990
|
93991
|
93992
|
93993
|
93994
|
93995
|
93996
|
93997
|
93998
|
93999
|
94000
|
94001
|
94002
|
94003
|
94004
|
94005
|
94006
|
94007
|
94008
|
94073
|
94074
|
94075
|
94076
|
94077
|
94078
|
94079
|
94080
|
94081
|
94082
|
94083
|
94084
|
94085
|
94086
|
94087
|
94088
|
94089
|
94090
|
94091
|
94092
|
94093
|
94111
|
94112
|
94113
|
94114
|
94115
|
94116
|
94117
|
94118
|
94119
|
94120
|
94121
|
94122
|
94123
|
94124
|
94125
|
94126
|
94127
|
94128
|
94129
|
94130
|
94131
|
94132
|
94133
|
94134
|
94135
|
94136
|
94137
|
94138
|
94139
|
94140
|
94141
|
94142
|
94143
|
94144
|
94145
|
94146
|
94147
|
94148
|
94149
|
94150
|
94151
|
94152
|
94165
|
94307
|
94308
|
94309
|
94310
|
94311
|
94312
|
94313
|
94314
|
94315
|
94316
|
94317
|
94318
|
94319
|
94320
|
94321
|
94323
|
94324
|
94325
|
94326
|
94327
|
94328
|
94329
|
94331
|
94332
|
94333
|
94334
|
94335
|
94336
|
94337
|
94338
|
94339
|
94340
|
94341
|
94342
|
94343
|
94344
|
94345
|
94346
|
94347
|
94348
|
94349
|
94350
|
94351
|
94352
|
94648