View | Details | Raw Unified | Return to bug 23049
Collapse All | Expand All

(-)a/C4/Installer.pm (+1 lines)
Lines 332-337 sub load_sql_in_order { Link Here
332
    push @fnames, C4::Context->config('intranetdir') . "/installer/data/mysql/userpermissions.sql";
332
    push @fnames, C4::Context->config('intranetdir') . "/installer/data/mysql/userpermissions.sql";
333
    push @fnames, C4::Context->config('intranetdir') . "/installer/data/mysql/audio_alerts.sql";
333
    push @fnames, C4::Context->config('intranetdir') . "/installer/data/mysql/audio_alerts.sql";
334
    push @fnames, C4::Context->config('intranetdir') . "/installer/data/mysql/account_offset_types.sql";
334
    push @fnames, C4::Context->config('intranetdir') . "/installer/data/mysql/account_offset_types.sql";
335
    push @fnames, C4::Context->config('intranetdir') . "/installer/data/mysql/account_debit_types.sql";
335
    foreach my $file (@fnames) {
336
    foreach my $file (@fnames) {
336
        #      warn $file;
337
        #      warn $file;
337
        undef $/;
338
        undef $/;
(-)a/Koha/Account/DebitType.pm (+93 lines)
Line 0 Link Here
1
package Koha::Account::DebitType;
2
3
# Copyright PTFS Europe 2019
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
use List::Util qw/any/;
22
23
use Koha::Database;
24
use Koha::Exceptions;
25
26
use base qw(Koha::Object);
27
28
=head1 NAME
29
30
Koha::Account::DebitType - Koha Account debit type Object class
31
32
=head1 CONSTANTS
33
34
=head2 System defaults
35
36
A list of system default debit types which should not be deleted
37
38
=cut
39
40
our @defaults = (
41
    "ACCOUNT", "ACCOUNT_RENEW", "HE", "LOST", "M", "N", "OVERDUE", "PF",
42
    "RENT", "RENT_DAILY", "RENT_RENEW", "RENT_DAILY_RENEW", "Res"
43
);
44
45
=head1 API
46
47
=head2 Class Methods
48
49
=cut
50
51
=head3 delete
52
53
Overridden delete method to prevent system default deletions
54
55
=cut
56
57
sub delete {
58
    my ($self) = @_;
59
60
    if ( any { $self->code eq $_ } @defaults ) {
61
        Koha::Exceptions::CannotDeleteDefault->throw;
62
    }
63
    return $self->SUPER::delete;
64
}
65
66
=head1 is_system
67
68
Accessor returning boolean signalling system default DebitType
69
70
=cut
71
72
sub is_system {
73
    my ($self) = @_;
74
    return ( any { $self->code eq $_ } @defaults ) ? 1 : 0;
75
}
76
77
=head3 defaults
78
79
=cut
80
81
sub defaults {
82
    return \@defaults;
83
}
84
85
=head3 type
86
87
=cut
88
89
sub _type {
90
    return 'AccountDebitType';
91
}
92
93
1;
(-)a/Koha/Account/DebitTypes.pm (+68 lines)
Line 0 Link Here
1
package Koha::Account::DebitTypes;
2
3
# Copyright PTFS Europe 2019
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
use List::Util qw/any/;
22
23
use Koha::Database;
24
use Koha::Account::DebitType;
25
26
use base qw(Koha::Objects);
27
28
=head1 NAME
29
30
Koha::Account::DebitTypes - Koha Account debit types Object set class
31
32
=head1 API
33
34
=head2 Class Methods
35
36
=head3 delete
37
38
Overridden delete method to prevent system default deletions
39
40
=cut
41
42
sub delete {
43
    my ($self) = @_;
44
45
    my @set = $self->as_list;
46
    my $defaults = Koha::Account::DebitType::defaults;
47
    for my $type (@set) {
48
        if ( any { $type->code eq $_ } @{$defaults} ) {
49
            Koha::Exceptions::CannotDeleteDefault->throw;
50
        }
51
    }
52
53
    return $self->SUPER::delete;
54
}
55
56
=head3 type
57
58
=cut
59
60
sub _type {
61
    return 'AccountDebitType';
62
}
63
64
sub object_class {
65
    return 'Koha::Account::DebitType';
66
}
67
68
1;
(-)a/installer/data/mysql/account_debit_types.sql (+14 lines)
Line 0 Link Here
1
INSERT INTO account_debit_types ( code, description, can_be_added_manually, default_amount ) VALUES
2
('ACCOUNT', 'Account creation fee', 0, NULL),
3
('ACCOUNT_RENEW', 'Account renewal fee', 0, NULL),
4
('HE', 'Hold waiting too long', 0, NULL),
5
('LOST', 'Lost item', 1, NULL),
6
('M', 'Manual fee', 1, NULL),
7
('N', 'New card fee', 1, NULL),
8
('OVERDUE', 'Overdue fine', 0, NULL),
9
('PF', 'Lost item processing fee', 0, NULL),
10
('RENT', 'Rental fee', 0, NULL),
11
('RENT_DAILY', 'Daily rental fee', 0, NULL),
12
('RENT_RENEW', 'Renewal of rental item', 0, NULL),
13
('RENT_DAILY_RENEW', 'Rewewal of daily rental item', 0, NULL),
14
('Res', 'Hold fee', 0, NULL);
(-)a/installer/data/mysql/atomicupdate/bug_23049_debit.perl (+92 lines)
Line 0 Link Here
1
$DBversion = 'XXX';    # will be replaced by the RM
2
if ( CheckVersion($DBversion) ) {
3
4
    $dbh->do(
5
        qq{
6
            CREATE TABLE IF NOT EXISTS account_debit_types (
7
              code varchar(16) NOT NULL,
8
              description varchar(200) NULL,
9
              can_be_added_manually tinyint(4) NOT NULL DEFAULT '1',
10
              default_amount decimal(28, 6) NULL,
11
              PRIMARY KEY (code)
12
            ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci
13
          }
14
    );
15
16
    $dbh->do(
17
        qq{
18
            INSERT IGNORE INTO account_debit_types (
19
              code,
20
              description,
21
              can_be_added_manually,
22
              default_amount
23
            )
24
            VALUES
25
              ('ACCOUNT', 'Account creation fee', 0, NULL),
26
              ('ACCOUNT_RENEW', 'Account renewal fee', 0, NULL),
27
              ('HE', 'Hold waiting too long', 0, NULL),
28
              ('LOST', 'Lost item', 1, NULL),
29
              ('M', 'Manual fee', 1, NULL),
30
              ('N', 'New card fee', 1, NULL),
31
              ('OVERDUE', 'Overdue fine', 0, NULL),
32
              ('PF', 'Lost item processing fee', 0, NULL),
33
              ('RENT', 'Rental fee', 0, NULL),
34
              ('RENT_DAILY', 'Daily rental fee', 0, NULL),
35
              ('RENT_RENEW', 'Renewal of rental item', 0, NULL),
36
              ('RENT_DAILY_RENEW', 'Rewewal of daily rental item', 0, NULL),
37
              ('Res', 'Hold fee', 0, NULL)
38
        }
39
    );
40
41
    $dbh->do(
42
        qq{
43
            INSERT IGNORE INTO account_debit_types (
44
              code,
45
              default_amount,
46
              description,
47
              can_be_added_manually
48
            )
49
            SELECT
50
              SUBSTR(authorised_value, 1, 16),
51
              lib,
52
              authorised_value,
53
              1
54
            FROM
55
              authorised_values
56
            WHERE
57
              category = 'MANUAL_INV'
58
          }
59
    );
60
61
    $dbh->do(
62
        qq{
63
            ALTER IGNORE TABLE accountlines
64
            ADD
65
              debit_type varchar(16) DEFAULT NULL
66
            AFTER
67
              accounttype
68
          }
69
    );
70
71
    $dbh->do(
72
        qq{
73
        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
74
          }
75
    );
76
77
    # Add new permission
78
    $dbh->do(
79
        q{
80
            INSERT IGNORE INTO permissions (module_bit, code, description)
81
            VALUES
82
              (
83
                3,
84
                'manage_accounts',
85
                'Manage Account Debit and Credit Types'
86
              )
87
        }
88
    );
89
90
    SetVersion($DBversion);
91
    print "Upgrade to $DBversion done (Bug 23049 - Add account debit_types)\n";
92
}
(-)a/installer/data/mysql/en/mandatory/account_debit_types.sql (+13 lines)
Line 0 Link Here
1
INSERT INTO account_debit_types (code, default_amount, description, can_be_added_manually) VALUES
2
    ('A',   NULL,   'Account management fee',   1),
3
    ('F',   NULL,   'Overdue fine', 1),
4
    ('FU',  NULL,   'Accruing overdue fine',    0),
5
    ('L',   NULL,   'Lost item',    1),
6
    ('LR',  NULL,   'Lost and returned',    0),
7
    ('M',   NULL,   'Sundry',   1),
8
    ('N',   NULL,   'New card', 1),
9
    ('O',   NULL,   'Overdue fine', 0),
10
    ('Rent',    NULL,   'Rental fee',   1),
11
    ('Rep', NULL,   'Replacement',  0),
12
    ('Res', NULL,   'Reserve charge',   1),
13
    ('Copie', 0.5,  'Copier fees', 1);
(-)a/installer/data/mysql/en/optional/auth_val.sql (-3 lines)
Lines 48-56 INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('NOT_L Link Here
48
-- restricted status of an item, linked to items.restricted
48
-- restricted status of an item, linked to items.restricted
49
INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('RESTRICTED','1','Restricted Access');
49
INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('RESTRICTED','1','Restricted Access');
50
50
51
-- manual invoice types
52
INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('MANUAL_INV','Copier Fees','.25');
53
54
-- custom borrower notes
51
-- custom borrower notes
55
INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('BOR_NOTES','ADDR','Address Notes');
52
INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('BOR_NOTES','ADDR','Address Notes');
56
53
(-)a/installer/data/mysql/kohastructure.sql (-1 / +17 lines)
Lines 2622-2627 CREATE TABLE `cash_registers` ( Link Here
2622
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
2622
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
2623
2623
2624
--
2624
--
2625
-- Table structure for table `account_debit_types`
2626
--
2627
2628
DROP TABLE IF EXISTS `account_debit_types`;
2629
CREATE TABLE `account_debit_types` (
2630
  `code` varchar(16) NOT NULL,
2631
  `default_amount` decimal(28,6) DEFAULT NULL,
2632
  `description` varchar(200) DEFAULT NULL,
2633
  `can_be_added_manually` tinyint(4) NOT NULL DEFAULT '1',
2634
  PRIMARY KEY (`code`)
2635
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2636
2637
--
2625
-- Table structure for table `accountlines`
2638
-- Table structure for table `accountlines`
2626
--
2639
--
2627
2640
Lines 2635-2640 CREATE TABLE `accountlines` ( Link Here
2635
  `amount` decimal(28,6) default NULL,
2648
  `amount` decimal(28,6) default NULL,
2636
  `description` LONGTEXT,
2649
  `description` LONGTEXT,
2637
  `accounttype` varchar(80) default NULL,
2650
  `accounttype` varchar(80) default NULL,
2651
  `debit_type` varchar(16) default NULL,
2638
  `status` varchar(16) default NULL,
2652
  `status` varchar(16) default NULL,
2639
  `payment_type` varchar(80) default NULL, -- optional authorised value PAYMENT_TYPE
2653
  `payment_type` varchar(80) default NULL, -- optional authorised value PAYMENT_TYPE
2640
  `amountoutstanding` decimal(28,6) default NULL,
2654
  `amountoutstanding` decimal(28,6) default NULL,
Lines 2647-2652 CREATE TABLE `accountlines` ( Link Here
2647
  PRIMARY KEY (`accountlines_id`),
2661
  PRIMARY KEY (`accountlines_id`),
2648
  KEY `acctsborridx` (`borrowernumber`),
2662
  KEY `acctsborridx` (`borrowernumber`),
2649
  KEY `timeidx` (`timestamp`),
2663
  KEY `timeidx` (`timestamp`),
2664
  KEY `debit_type` (`debit_type`),
2650
  KEY `itemnumber` (`itemnumber`),
2665
  KEY `itemnumber` (`itemnumber`),
2651
  KEY `branchcode` (`branchcode`),
2666
  KEY `branchcode` (`branchcode`),
2652
  KEY `manager_id` (`manager_id`),
2667
  KEY `manager_id` (`manager_id`),
Lines 2654-2660 CREATE TABLE `accountlines` ( Link Here
2654
  CONSTRAINT `accountlines_ibfk_items` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE SET NULL ON UPDATE CASCADE,
2669
  CONSTRAINT `accountlines_ibfk_items` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE SET NULL ON UPDATE CASCADE,
2655
  CONSTRAINT `accountlines_ibfk_borrowers_2` FOREIGN KEY (`manager_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
2670
  CONSTRAINT `accountlines_ibfk_borrowers_2` FOREIGN KEY (`manager_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
2656
  CONSTRAINT `accountlines_ibfk_branches` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE,
2671
  CONSTRAINT `accountlines_ibfk_branches` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE,
2657
  CONSTRAINT `accountlines_ibfk_registers` FOREIGN KEY (`register_id`) REFERENCES `cash_registers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
2672
  CONSTRAINT `accountlines_ibfk_registers` FOREIGN KEY (`register_id`) REFERENCES `cash_registers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
2673
  CONSTRAINT `accountlines_ibfk_debit_type` FOREIGN KEY (`debit_type`) REFERENCES `account_debit_types` (`code`) ON DELETE SET NULL ON UPDATE CASCADE
2658
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2674
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2659
2675
2660
--
2676
--
(-)a/misc/devel/populate_db.pl (-1 / +1 lines)
Lines 108-113 my @sample_files_mandatory = ( Link Here
108
    "$data_dir/userflags.sql",
108
    "$data_dir/userflags.sql",
109
    "$data_dir/userpermissions.sql",
109
    "$data_dir/userpermissions.sql",
110
    "$data_dir/account_offset_types.sql",
110
    "$data_dir/account_offset_types.sql",
111
    "$data_dir/account_debit_types.sql",
111
);
112
);
112
my @sample_lang_files_mandatory    = ( glob $root . "/installer/data/mysql/$lang/mandatory/*.sql" );
113
my @sample_lang_files_mandatory    = ( glob $root . "/installer/data/mysql/$lang/mandatory/*.sql" );
113
my @sample_lang_files_optional     = ( glob $root . "/installer/data/mysql/$lang/optional/*.sql" );
114
my @sample_lang_files_optional     = ( glob $root . "/installer/data/mysql/$lang/optional/*.sql" );
114
- 

Return to bug 23049