@@ -, +, @@ --- Koha/Schema/Result/Accountline.pm | 28 ++++ Koha/Schema/Result/Branch.pm | 19 ++- Koha/Schema/Result/CashRegister.pm | 153 ++++++++++++++++++ .../data/mysql/atomicupdate/bug_23321.perl | 30 ++++ installer/data/mysql/kohastructure.sql | 22 ++- 5 files changed, 249 insertions(+), 3 deletions(-) create mode 100644 Koha/Schema/Result/CashRegister.pm create mode 100644 installer/data/mysql/atomicupdate/bug_23321.perl --- a/Koha/Schema/Result/Accountline.pm +++ a/Koha/Schema/Result/Accountline.pm @@ -105,6 +105,12 @@ __PACKAGE__->table("accountlines"); is_foreign_key: 1 is_nullable: 1 +=head2 register_id + + data_type: 'integer' + is_foreign_key: 1 + is_nullable: 1 + =head2 interface data_type: 'varchar' @@ -154,6 +160,8 @@ __PACKAGE__->add_columns( { data_type => "mediumtext", is_nullable => 1 }, "manager_id", { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, + "register_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, "interface", { data_type => "varchar", is_nullable => 0, size => 16 }, "branchcode", @@ -284,6 +292,26 @@ __PACKAGE__->belongs_to( }, ); +=head2 register + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "register", + "Koha::Schema::Result::CashRegister", + { id => "register_id" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "SET NULL", + on_update => "CASCADE", + }, +); + # Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-09-06 12:23:55 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:/8Qeh530PbLC6ryxC1Dw9w --- a/Koha/Schema/Result/Branch.pm +++ a/Koha/Schema/Result/Branch.pm @@ -346,6 +346,21 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +=head2 cash_registers + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "cash_registers", + "Koha::Schema::Result::CashRegister", + { "foreign.branch" => "self.branchcode" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 categories_branches Type: has_many @@ -662,8 +677,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07048 @ 2019-07-04 04:56:47 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:15/s0/8d2cNB9YLLlsEY4w +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-07-17 07:15:23 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:qGiu+y4MHq5CvBQTj0m8QQ __PACKAGE__->add_columns( '+pickup_location' => { is_boolean => 1 } --- a/Koha/Schema/Result/CashRegister.pm +++ a/Koha/Schema/Result/CashRegister.pm @@ -0,0 +1,153 @@ +use utf8; +package Koha::Schema::Result::CashRegister; + +# Created by DBIx::Class::Schema::Loader +# DO NOT MODIFY THE FIRST PART OF THIS FILE + +=head1 NAME + +Koha::Schema::Result::CashRegister + +=cut + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; + +=head1 TABLE: C + +=cut + +__PACKAGE__->table("cash_registers"); + +=head1 ACCESSORS + +=head2 id + + data_type: 'integer' + is_auto_increment: 1 + is_nullable: 0 + +=head2 name + + data_type: 'varchar' + is_nullable: 0 + size: 24 + +=head2 description + + data_type: 'longtext' + is_nullable: 0 + +=head2 branch + + data_type: 'varchar' + is_foreign_key: 1 + is_nullable: 0 + size: 10 + +=head2 branch_default + + data_type: 'tinyint' + default_value: 0 + is_nullable: 0 + +=head2 starting_float + + data_type: 'decimal' + is_nullable: 1 + size: [28,6] + +=head2 archived + + data_type: 'tinyint' + default_value: 0 + is_nullable: 0 + +=cut + +__PACKAGE__->add_columns( + "id", + { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, + "name", + { data_type => "varchar", is_nullable => 0, size => 24 }, + "description", + { data_type => "longtext", is_nullable => 0 }, + "branch", + { data_type => "varchar", is_foreign_key => 1, is_nullable => 0, size => 10 }, + "branch_default", + { data_type => "tinyint", default_value => 0, is_nullable => 0 }, + "starting_float", + { data_type => "decimal", is_nullable => 1, size => [28, 6] }, + "archived", + { data_type => "tinyint", default_value => 0, is_nullable => 0 }, +); + +=head1 PRIMARY KEY + +=over 4 + +=item * L + +=back + +=cut + +__PACKAGE__->set_primary_key("id"); + +=head1 UNIQUE CONSTRAINTS + +=head2 C + +=over 4 + +=item * L + +=item * L + +=back + +=cut + +__PACKAGE__->add_unique_constraint("name", ["name", "branch"]); + +=head1 RELATIONS + +=head2 accountlines + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "accountlines", + "Koha::Schema::Result::Accountline", + { "foreign.register_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + +=head2 branch + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "branch", + "Koha::Schema::Result::Branch", + { branchcode => "branch" }, + { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, +); + + +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-07-23 13:14:31 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:TfGf0U/vWS7IviRlvDdE1w + + +# You can replace this text with custom code or comments, and it will be preserved on regeneration +1; --- a/installer/data/mysql/atomicupdate/bug_23321.perl +++ a/installer/data/mysql/atomicupdate/bug_23321.perl @@ -0,0 +1,30 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if ( CheckVersion($DBversion) ) { + + $dbh->do(qq{ +CREATE TABLE `cash_registers` ( + `id` int(11) NOT NULL auto_increment, -- unique identifier for each account register + `name` varchar(24) NOT NULL, -- the user friendly identifier for each account register + `description` longtext NOT NULL, -- the user friendly description for each account register + `branch` varchar(10) NOT NULL, -- the foreign key the library this account register belongs + `branch_default` tinyint(1) NOT NULL DEFAULT 0, -- boolean flag to denote that this till is the branch default + `starting_float` decimal(28, 6), -- the starting float this account register should be assigned + `archived` tinyint(1) NOT NULL DEFAULT 0, -- boolean flag to denote if this till is archived or not + PRIMARY KEY (`id`), + UNIQUE KEY `name` (`name`,`branch`), + 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; + }); + + unless ( column_exists( 'accountlines', 'register_id' ) ) { + $dbh->do(qq{ALTER TABLE `accountlines` ADD `register_id` int(11) NULL DEFAULT NULL AFTER `manager_id`}); + $dbh->do(qq{ + ALTER TABLE `accountlines` + ADD CONSTRAINT `accountlines_ibfk_registers` FOREIGN KEY (`register_id`) + REFERENCES `cash_registers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE + }); + } + + SetVersion($DBversion); + print "Upgrade to $DBversion done (Bug 23321 - Add cash_registers table)\n"; +} --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -2600,6 +2600,24 @@ CREATE TABLE `messages` ( -- circulation messages left via the patron's check ou CONSTRAINT `messages_borrowernumber` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +-- +-- Table structure for table `cash_registers` +-- + +DROP TABLE IF EXISTS `cash_registers`; +CREATE TABLE `cash_registers` ( + `id` int(11) NOT NULL auto_increment, -- unique identifier for each account register + `name` varchar(24) NOT NULL, -- the user friendly identifier for each account register + `description` longtext NOT NULL, -- the user friendly description for each account register + `branch` varchar(10) NOT NULL, -- the foreign key the library this account register belongs + `branch_default` tinyint(1) NOT NULL DEFAULT 0, -- boolean flag to denote that this till is the branch default + `starting_float` decimal(28, 6), -- the starting float this account register should be assigned + `archived` tinyint(1) NOT NULL DEFAULT 0, -- boolean flag to denote if this till is archived or not + PRIMARY KEY (`id`), + UNIQUE KEY `name` (`name`,`branch`), + 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 `accountlines` -- @@ -2620,6 +2638,7 @@ CREATE TABLE `accountlines` ( `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, `note` MEDIUMTEXT NULL default NULL, `manager_id` int(11) NULL DEFAULT NULL, + `register_id` int(11) NULL DEFAULT NULL, `interface` VARCHAR(16) NOT NULL, `branchcode` VARCHAR( 10 ) NULL DEFAULT NULL, -- the branchcode of the library where a payment was made, a manual invoice created, etc. PRIMARY KEY (`accountlines_id`), @@ -2631,7 +2650,8 @@ CREATE TABLE `accountlines` ( CONSTRAINT `accountlines_ibfk_borrowers` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE, 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_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 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- --