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 $/;
sub non_issues_charges {
my ($self) = @_;
- # FIXME REMOVE And add a warning in the about page + update DB if length(MANUAL_INV) > 5
- my $ACCOUNT_TYPE_LENGTH = 5; # this is plain ridiculous...
-
+ #NOTE: With bug 23049 these preferences could be moved to being attached
+ #to individual debit types to give more flexability and specificity.
my @not_fines;
push @not_fines, 'Res'
unless C4::Context->preference('HoldsInNoissuesCharge');
- push @not_fines, 'Rent'
+ push @not_fines, ( 'RENT', 'RENT_DAILY', 'RENT_RENEW', 'RENT_DAILY_RENEW' )
unless C4::Context->preference('RentalsInNoissuesCharge');
unless ( C4::Context->preference('ManInvInNoissuesCharge') ) {
- my $dbh = C4::Context->dbh;
- push @not_fines,
- @{
- $dbh->selectcol_arrayref(q|
- SELECT authorised_value FROM authorised_values WHERE category = 'MANUAL_INV'
- |)
- };
+ my @man_inv = Koha::Account::DebitTypes->search({ system => 0 })->get_column('code');
+ push @not_fines, @man_inv;
}
- @not_fines = map { substr( $_, 0, $ACCOUNT_TYPE_LENGTH ) } uniq(@not_fines);
return $self->lines->search(
{
- accounttype => { -not_in => \@not_fines }
+ debit_type => { -not_in => \@not_fines }
},
)->total_outstanding;
}
--- /dev/null
+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 API
+
+=head2 Class Methods
+
+=cut
+
+=head3 delete
+
+Overridden delete method to prevent system default deletions
+
+=cut
+
+sub delete {
+ my ($self) = @_;
+
+ Koha::Exceptions::CannotDeleteDefault->throw if $self->is_system;
+
+ return $self->SUPER::delete;
+}
+
+=head3 type
+
+=cut
+
+sub _type {
+ return 'AccountDebitType';
+}
+
+1;
--- /dev/null
+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 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;
+ for my $type (@set) {
+ if ( $type->is_system ) {
+ Koha::Exceptions::CannotDeleteDefault->throw;
+ }
+ }
+
+ return $self->SUPER::delete;
+}
+
+=head3 type
+
+=cut
+
+sub _type {
+ return 'AccountDebitType';
+}
+
+=head3 object_class
+
+=cut
+
+sub object_class {
+ return 'Koha::Account::DebitType';
+}
+
+1;
is_nullable: 1
size: 80
+=head2 debit_type
+
+ data_type: 'varchar'
+ is_foreign_key: 1
+ is_nullable: 1
+ size: 16
+
=head2 status
data_type: 'varchar'
{ data_type => "longtext", is_nullable => 1 },
"accounttype",
{ data_type => "varchar", is_nullable => 1, size => 80 },
+ "debit_type",
+ { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 16 },
"status",
{ data_type => "varchar", is_nullable => 1, size => 16 },
"payment_type",
},
);
+=head2 debit_type
+
+Type: belongs_to
+
+Related object: L<Koha::Schema::Result::AccountDebitType>
+
+=cut
+
+__PACKAGE__->belongs_to(
+ "debit_type",
+ "Koha::Schema::Result::AccountDebitType",
+ { code => "debit_type" },
+ {
+ is_deferrable => 1,
+ join_type => "LEFT",
+ on_delete => "SET NULL",
+ on_update => "CASCADE",
+ },
+);
+
=head2 itemnumber
Type: belongs_to
);
-# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-09-23 10:45:21
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:L+QlTTT+MdGoA3shpyaBgQ
+# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-10-11 10:47:58
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:RKg4gDSu0WwJ1C9YmDv3pw
sub koha_objects_class {
'Koha::Account::Lines';
=head1 RELATIONS
+=head2 ac_debit_types_branches
+
+Type: has_many
+
+Related object: L<Koha::Schema::Result::AcDebitTypesBranch>
+
+=cut
+
+__PACKAGE__->has_many(
+ "ac_debit_types_branches",
+ "Koha::Schema::Result::AcDebitTypesBranch",
+ { "foreign.branchcode" => "self.branchcode" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
+
=head2 accountlines
Type: has_many
);
-# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-09-23 10:45:22
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:KDg4i49bpMxXQ1LP6OZFWQ
+# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-09-26 15:59:23
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:IiEBfDpMBAi9cv7OqevVRQ
__PACKAGE__->add_columns(
'+pickup_location' => { is_boolean => 1 }
--- /dev/null
+INSERT INTO account_debit_types ( code, description, can_be_added_manually, default_amount, is_system ) VALUES
+('ACCOUNT', 'Account creation fee', 0, NULL, 1),
+('ACCOUNT_RENEW', 'Account renewal fee', 0, NULL, 1),
+('HE', 'Hold waiting too long', 0, NULL, 1),
+('LOST', 'Lost item', 1, NULL, 1),
+('M', 'Manual fee', 1, NULL, 0),
+('N', 'New card fee', 1, NULL, 1),
+('OVERDUE', 'Overdue fine', 0, NULL, 1),
+('PF', 'Lost item processing fee', 0, NULL, 1),
+('RENT', 'Rental fee', 0, NULL, 1),
+('RENT_DAILY', 'Daily rental fee', 0, NULL, 1),
+('RENT_RENEW', 'Renewal of rental item', 0, NULL, 1),
+('RENT_DAILY_RENEW', 'Rewewal of daily rental item', 0, NULL, 1),
+('Res', 'Hold fee', 0, NULL, 1);
--- /dev/null
+$DBversion = 'XXX'; # will be replaced by the RM
+if ( CheckVersion($DBversion) ) {
+
+ $dbh->do(
+ qq{
+ CREATE TABLE IF NOT EXISTS account_debit_types (
+ code varchar(64) NOT NULL,
+ description varchar(200) NULL,
+ can_be_added_manually tinyint(4) NOT NULL DEFAULT 1,
+ default_amount decimal(28, 6) NULL,
+ is_system tinyint(1) NOT NULL DEFAULT 0,
+ PRIMARY KEY (code)
+ ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci
+ }
+ );
+
+ $dbh->do(
+ qq{
+ CREATE TABLE IF NOT EXISTS ac_debit_types_branches (
+ debit_type_code VARCHAR(64),
+ branchcode VARCHAR(10),
+ FOREIGN KEY (debit_type_code) REFERENCES account_debit_types(code) ON DELETE CASCADE,
+ FOREIGN KEY (branchcode) REFERENCES branches(branchcode) ON DELETE CASCADE
+ ) 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,
+ is_system
+ )
+ VALUES
+ ('ACCOUNT', 'Account creation fee', 0, NULL, 1),
+ ('ACCOUNT_RENEW', 'Account renewal fee', 0, NULL, 1),
+ ('HE', 'Hold waiting too long', 0, NULL, 1),
+ ('LOST', 'Lost item', 1, NULL, 1),
+ ('M', 'Manual fee', 1, NULL, 0),
+ ('N', 'New card fee', 1, NULL, 1),
+ ('OVERDUE', 'Overdue fine', 0, NULL, 1),
+ ('PF', 'Lost item processing fee', 0, NULL, 1),
+ ('RENT', 'Rental fee', 0, NULL, 1),
+ ('RENT_DAILY', 'Daily rental fee', 0, NULL, 1),
+ ('RENT_RENEW', 'Renewal of rental item', 0, NULL, 1),
+ ('RENT_DAILY_RENEW', 'Rewewal of daily rental item', 0, NULL, 1),
+ ('Res', 'Hold fee', 0, NULL, 1)
+ }
+ );
+
+ $dbh->do(
+ qq{
+ INSERT IGNORE INTO account_debit_types (
+ code,
+ default_amount,
+ description,
+ can_be_added_manually,
+ is_system
+ )
+ SELECT
+ SUBSTR(authorised_value, 1, 64),
+ lib,
+ authorised_value,
+ 1,
+ 0
+ FROM
+ authorised_values
+ WHERE
+ category = 'MANUAL_INV'
+ }
+ );
+
+ $dbh->do(
+ qq{
+ ALTER IGNORE TABLE accountlines
+ ADD
+ debit_type varchar(64) 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
+ }
+ );
+
+ $dbh->do(
+ qq{
+ UPDATE accountlines SET debit_type = accounttype, accounttype = NULL WHERE accounttype IN (SELECT code from account_debit_types)
+ }
+ );
+
+ # Clean up MANUAL_INV
+ $dbh->do(
+ qq{
+ DELETE FROM authorised_values WHERE category = 'MANUAL_INV'
+ }
+ );
+ $dbh->do(
+ qq{
+ DELETE FROM authorised_value_categories WHERE category_name = 'MANUAL_INV'
+ }
+ );
+
+ # 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";
+}
--- /dev/null
+INSERT INTO account_debit_types ( code, description, can_be_added_manually, default_amount, is_system ) VALUES
+('ACCOUNT', 'Account creation fee', 0, NULL, 1),
+('ACCOUNT_RENEW', 'Account renewal fee', 0, NULL, 1),
+('HE', 'Hold waiting too long', 0, NULL, 1),
+('LOST', 'Lost item', 1, NULL, 1),
+('M', 'Manual fee', 1, NULL, 0),
+('N', 'New card fee', 1, NULL, 1),
+('OVERDUE', 'Overdue fine', 0, NULL, 1),
+('PF', 'Lost item processing fee', 0, NULL, 1),
+('RENT', 'Rental fee', 0, NULL, 1),
+('RENT_DAILY', 'Daily rental fee', 0, NULL, 1),
+('RENT_RENEW', 'Renewal of rental item', 0, NULL, 1),
+('RENT_DAILY_RENEW', 'Rewewal of daily rental item', 0, NULL, 1),
+('Res', 'Hold fee', 0, NULL, 1);
-- 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');
) 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(64) NOT NULL,
+ `description` varchar(200) DEFAULT NULL,
+ `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,
+ PRIMARY KEY (`code`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+--
+-- Table structure for table `ac_debit_types_branches`
+--
+
+DROP TABLE IF EXISTS `ac_debit_types_branches`;
+CREATE TABLE `ac_debit_types_branches` (
+ `debit_type_code` VARCHAR(64),
+ `branchcode` VARCHAR(10),
+ FOREIGN KEY (`debit_type_code`) REFERENCES `account_debit_types` (`code`) ON DELETE CASCADE,
+ FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+--
-- Table structure for table `accountlines`
--
`amount` decimal(28,6) default NULL,
`description` LONGTEXT,
`accounttype` varchar(80) default NULL,
+ `debit_type` varchar(64) default NULL,
`status` varchar(16) default NULL,
`payment_type` varchar(80) default NULL, -- optional authorised value PAYMENT_TYPE
`amountoutstanding` decimal(28,6) default NULL,
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`),
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;
--
('NOT_LOAN'),
('CCODE'),
('LOC'),
- ('MANUAL_INV'),
('BOR_NOTES'),
('OPAC_SUG'),
('SIP_MEDIA_TYPE'),
<p>Shelving location (usually appears when adding or editing an item). LOC maps to items.location in the Koha database.</p>
[% CASE 'LOST' %]
<p>Descriptions for the items marked as lost (appears when adding or editing an item)</p>
- [% CASE 'MANUAL_INV' %]
- <p>Values for manual invoicing types</p>
[% CASE 'NOT_LOAN' %]
<p>Reasons why a title is not for loan</p>
[% CASE 'OPAC_SUG' %]
choices:
yes: Include
no: "Don't include"
- - MANUAL_INV charges when summing up charges for noissuescharge.
+ - custom debit type charges when summing up charges for noissuescharge.
-
- pref: HoldsInNoissuesCharge
choices:
"$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" );
interface => 'commandline'
}
);
+ Koha::Account::DebitTypes->new(
+ {
+ code => 'Copie',
+ description => 'Fee for copie',
+ is_system => 0
+ }
+ )->store;
Koha::Account::Line->new(
{
borrowernumber => $patron->borrowernumber,
date => $today,
description => 'a Manual invoice fee',
- accounttype => 'Copie',
+ debit_type => 'Copie',
amountoutstanding => $manual,
interface => 'commandline'
}
)->store;
- Koha::AuthorisedValue->new(
- {
- category => 'MANUAL_INV',
- authorised_value => 'Copie',
- lib => 'Fee for copie',
- }
- )->store;
t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 0 );