From e221c3907d92474b09a2dc32fea9e874fdeba2a9 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 1 Sep 2017 07:51:49 -0400 Subject: [PATCH] Bug 14826 - Add account offset type table --- C4/Installer.pm | 1 + Koha/Schema/Result/AccountOffset.pm | 22 +++++++- Koha/Schema/Result/AccountOffsetType.pm | 74 +++++++++++++++++++++++++ installer/data/mysql/account_offset_types.sql | 11 ++++ installer/data/mysql/atomicupdate/bug_14826.sql | 21 ++++++- installer/data/mysql/kohastructure.sql | 13 ++++- misc/devel/populate_db.pl | 1 + 7 files changed, 137 insertions(+), 6 deletions(-) create mode 100644 Koha/Schema/Result/AccountOffsetType.pm create mode 100644 installer/data/mysql/account_offset_types.sql diff --git a/C4/Installer.pm b/C4/Installer.pm index 866d1f2..74ae288 100644 --- a/C4/Installer.pm +++ b/C4/Installer.pm @@ -327,6 +327,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/mandatory/refund_lost_item_fee_rules.sql"; + push @fnames, C4::Context->config('intranetdir') . "/installer/data/mysql/mandatory/account_offset_types.sql"; foreach my $file (@fnames) { # warn $file; undef $/; diff --git a/Koha/Schema/Result/AccountOffset.pm b/Koha/Schema/Result/AccountOffset.pm index dc9099f..013cb69 100644 --- a/Koha/Schema/Result/AccountOffset.pm +++ b/Koha/Schema/Result/AccountOffset.pm @@ -44,6 +44,7 @@ __PACKAGE__->table("account_offsets"); =head2 type data_type: 'varchar' + is_foreign_key: 1 is_nullable: 0 size: 16 @@ -70,7 +71,7 @@ __PACKAGE__->add_columns( "debit_id", { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, "type", - { data_type => "varchar", is_nullable => 0, size => 16 }, + { data_type => "varchar", is_foreign_key => 1, is_nullable => 0, size => 16 }, "amount", { data_type => "decimal", is_nullable => 0, size => [26, 6] }, "created_on", @@ -136,9 +137,24 @@ __PACKAGE__->belongs_to( }, ); +=head2 type + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "type", + "Koha::Schema::Result::AccountOffsetType", + { type => "type" }, + { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, +); + -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2017-02-15 16:13:26 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:CQ2SRBUEiVgEVhe88acqqA +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2017-09-01 11:00:44 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:EFxhLJ1SMRwknCaS5srYZA # You can replace this text with custom code or comments, and it will be preserved on regeneration diff --git a/Koha/Schema/Result/AccountOffsetType.pm b/Koha/Schema/Result/AccountOffsetType.pm new file mode 100644 index 0000000..636d8a0 --- /dev/null +++ b/Koha/Schema/Result/AccountOffsetType.pm @@ -0,0 +1,74 @@ +use utf8; +package Koha::Schema::Result::AccountOffsetType; + +# Created by DBIx::Class::Schema::Loader +# DO NOT MODIFY THE FIRST PART OF THIS FILE + +=head1 NAME + +Koha::Schema::Result::AccountOffsetType + +=cut + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; + +=head1 TABLE: C + +=cut + +__PACKAGE__->table("account_offset_types"); + +=head1 ACCESSORS + +=head2 type + + data_type: 'varchar' + is_nullable: 0 + size: 16 + +=cut + +__PACKAGE__->add_columns( + "type", + { data_type => "varchar", is_nullable => 0, size => 16 }, +); + +=head1 PRIMARY KEY + +=over 4 + +=item * L + +=back + +=cut + +__PACKAGE__->set_primary_key("type"); + +=head1 RELATIONS + +=head2 account_offsets + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "account_offsets", + "Koha::Schema::Result::AccountOffset", + { "foreign.type" => "self.type" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + + +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2017-09-01 11:00:44 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:PSvAX6W0Sv/MOy6pA/GB5Q + + +# You can replace this text with custom code or comments, and it will be preserved on regeneration +1; diff --git a/installer/data/mysql/account_offset_types.sql b/installer/data/mysql/account_offset_types.sql new file mode 100644 index 0000000..2f9004c --- /dev/null +++ b/installer/data/mysql/account_offset_types.sql @@ -0,0 +1,11 @@ +INSERT INTO account_offset_types ( type ) VALUES +('Writeoff'), +('Payment'), +('Lost Item'), +('Manual Debit'), +('Reverse Payment'), +('Forgiven'), +('Dropbox'), +('Rental Fee'), +('Fine Update'), +('Fine'); diff --git a/installer/data/mysql/atomicupdate/bug_14826.sql b/installer/data/mysql/atomicupdate/bug_14826.sql index 91d183b..bfbcf1b 100644 --- a/installer/data/mysql/atomicupdate/bug_14826.sql +++ b/installer/data/mysql/atomicupdate/bug_14826.sql @@ -1,4 +1,8 @@ -DROP TABLE IF EXISTS `accountoffsets`; +CREATE TABLE `account_offset_types` ( + `type` varchar(16) NOT NULL, -- The type of offset this is + PRIMARY KEY (`type`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + CREATE TABLE IF NOT EXISTS `account_offsets` ( `id` int(11) NOT NULL auto_increment, -- unique identifier for each offset `credit_id` int(11) NULL DEFAULT NULL, -- The id of the accountline the increased the patron's balance @@ -8,5 +12,18 @@ CREATE TABLE IF NOT EXISTS `account_offsets` ( `created_on` timestamp NOT NULL default CURRENT_TIMESTAMP, PRIMARY KEY (`id`), CONSTRAINT `account_offsets_ibfk_p` FOREIGN KEY (`credit_id`) REFERENCES `accountlines` (`accountlines_id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `account_offsets_ibfk_f` FOREIGN KEY (`debit_id`) REFERENCES `accountlines` (`accountlines_id`) ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT `account_offsets_ibfk_f` FOREIGN KEY (`debit_id`) REFERENCES `accountlines` (`accountlines_id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `account_offsets_ibfk_t` FOREIGN KEY (`type`) REFERENCES `account_offset_types` (`type`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +INSERT INTO account_offset_types ( type ) VALUES +('Writeoff'), +('Payment'), +('Lost Item'), +('Manual Debit'), +('Reverse Payment'), +('Forgiven'), +('Dropbox'), +('Rental Fee'), +('Fine Update'), +('Fine'); diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index e883ffb..bb0c31a 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2732,6 +2732,16 @@ CREATE TABLE `accountlines` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -- +-- Table structure for table `account_offset_types` +-- + +DROP TABLE IF EXISTS `account_offset_types`; +CREATE TABLE `account_offset_types` ( + `type` varchar(16) NOT NULL, -- The type of offset this is + PRIMARY KEY (`type`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +-- -- Table structure for table `account_offsets` -- @@ -2745,7 +2755,8 @@ CREATE TABLE `account_offsets` ( `created_on` timestamp NOT NULL default CURRENT_TIMESTAMP, PRIMARY KEY (`id`), CONSTRAINT `account_offsets_ibfk_p` FOREIGN KEY (`credit_id`) REFERENCES `accountlines` (`accountlines_id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `account_offsets_ibfk_f` FOREIGN KEY (`debit_id`) REFERENCES `accountlines` (`accountlines_id`) ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT `account_offsets_ibfk_f` FOREIGN KEY (`debit_id`) REFERENCES `accountlines` (`accountlines_id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `account_offsets_ibfk_t` FOREIGN KEY (`type`) REFERENCES `account_offset_types` (`type`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -- diff --git a/misc/devel/populate_db.pl b/misc/devel/populate_db.pl index 9bad049..e419e37 100755 --- a/misc/devel/populate_db.pl +++ b/misc/devel/populate_db.pl @@ -106,6 +106,7 @@ my @sample_files_mandatory = ( "$data_dir/sysprefs.sql", "$data_dir/userflags.sql", "$data_dir/userpermissions.sql", + "$data_dir/account_offset_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.10.2