@@ -, +, @@ --- C4/Installer.pm | 1 + Koha/Account/DebitType.pm | 93 +++++++++++++++++++ Koha/Account/DebitTypes.pm | 68 ++++++++++++++ installer/data/mysql/account_debit_types.sql | 14 +++ .../mysql/atomicupdate/bug_23049_debit.perl | 92 ++++++++++++++++++ .../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 --- a/C4/Installer.pm +++ a/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 $/; --- a/Koha/Account/DebitType.pm +++ a/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; --- a/Koha/Account/DebitTypes.pm +++ a/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; --- a/installer/data/mysql/account_debit_types.sql +++ a/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); --- a/installer/data/mysql/atomicupdate/bug_23049_debit.perl +++ a/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"; +} --- a/installer/data/mysql/en/mandatory/account_debit_types.sql +++ a/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); --- a/installer/data/mysql/en/optional/auth_val.sql +++ a/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'); --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -2621,6 +2621,19 @@ CREATE TABLE `cash_registers` ( CONSTRAINT cash_registers_branch FOREIGN KEY (branch) REFERENCES branches (branchcode) ON UPDATE CASCADE ON DELETE CASCADE ) 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; -- --- a/misc/devel/populate_db.pl +++ a/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" ); --