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

(-)a/installer/data/mysql/atomicupdate/bug_32450-add_debit_type_flag.pl (+77 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number => "32450",
5
    description => "Create a database flag for whether a debit type should be included in the noissuescharge block on circulation and remove redundant sysprefs.",
6
    up => sub {
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
9
10
        if( !column_exists( 'account_debit_types', 'restricts_checkouts' ) ) {
11
          $dbh->do(q{
12
              ALTER TABLE account_debit_types ADD COLUMN `restricts_checkouts` tinyint(1) NOT NULL DEFAULT 1 AFTER `archived`
13
          });
14
15
          say $out "Added column 'account_debit_types.restricts_checkouts'";
16
        }
17
18
        # Before deleting the redundant system preferences we need to check if they had been modified and update the new database flags accordingly
19
        my @sysprefs = ('ManInvInNoissuesCharge', 'RentalsInNoissuesCharge', 'HoldsInNoissuesCharge');
20
21
        # Hardcoded values from sub non_issues_charges
22
        my @holds = ('RESERVE');
23
        my @renewals = ('RENT', 'RENT_DAILY', 'RENT_RENEW', 'RENT_DAILY_RENEW');
24
        my @manual;
25
        my $sth = $dbh->prepare("SELECT code FROM account_debit_types WHERE is_system = 0");
26
        $sth->execute;
27
        while (my $code = $sth->fetchrow_array) {
28
            push @manual, $code;
29
        }
30
31
        for (@sysprefs){
32
            # Check if the syspref exists in the database
33
            my $check_syspref_exists = "SELECT COUNT(*) FROM systempreferences WHERE variable = '$_'";
34
            my $sth = $dbh->prepare($check_syspref_exists);
35
            $sth->execute;
36
            my $exists = $sth->fetchrow();
37
            $sth->finish;
38
39
            if($exists) {
40
                # If it exists, retrieve its value
41
                my $find_syspref_value = "SELECT value FROM systempreferences WHERE variable = '$_'";
42
                my $sth = $dbh->prepare($find_syspref_value);
43
                $sth->execute;
44
                my $value = $sth->fetchrow();
45
                $sth->finish;
46
47
                if($value){
48
                    say $out "$_ is included in the charge, default database value of 1 can be applied.";
49
                } else {
50
                    # Update account_debit_types to reflect existing syspref value.
51
                    my @debit_types_to_update;
52
53
                    if($_ eq 'ManInvInNoissuesCharge') { push @debit_types_to_update, @manual};
54
                    if($_ eq 'RentalsInNoissuesCharge') { push @debit_types_to_update, @renewals};
55
                    if($_ eq 'HoldsInNoissuesCharge') { push @debit_types_to_update, @holds};
56
57
                    my $string = join(",", map { $dbh->quote($_) } @debit_types_to_update);
58
                    my $update_query = "UPDATE account_debit_types SET restricts_checkouts = 0 WHERE code IN (" . $string . ")";
59
                    my $sth = $dbh->prepare($update_query);
60
                    $sth->execute;
61
                    $sth->finish;
62
63
                    say $out "$_ has been updated to not be included in the charge, account_debit_types has been updated to match this.";
64
                }
65
66
                # Delete syspref as it is no longer required and the value has been transferred to account_debit_types
67
                my $delete_redundant_syspref = "DELETE FROM systempreferences WHERE variable = '$_'";
68
                $dbh->do($delete_redundant_syspref);
69
70
            } else {
71
                # If it doesn't exist then revert to default value in the database schema
72
                say $out "$_ was not found in this Koha instance, default value has been applied.";
73
            }
74
75
        }
76
    },
77
};
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 65-70 CREATE TABLE `account_debit_types` ( Link Here
65
  `default_amount` decimal(28,6) DEFAULT NULL,
65
  `default_amount` decimal(28,6) DEFAULT NULL,
66
  `is_system` tinyint(1) NOT NULL DEFAULT 0,
66
  `is_system` tinyint(1) NOT NULL DEFAULT 0,
67
  `archived` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'boolean flag to denote if this till is archived or not',
67
  `archived` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'boolean flag to denote if this till is archived or not',
68
  `restricts_checkouts` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'boolean flag to denote if the noissuescharge syspref for this debit type is active',
68
  PRIMARY KEY (`code`)
69
  PRIMARY KEY (`code`)
69
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
70
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
70
/*!40101 SET character_set_client = @saved_cs_client */;
71
/*!40101 SET character_set_client = @saved_cs_client */;
(-)a/installer/data/mysql/mandatory/sysprefs.sql (-2 lines)
Lines 358-364 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
358
('LockExpiredDelay','','','Delay for locking expired patrons (empty means no locking)','Integer'),
358
('LockExpiredDelay','','','Delay for locking expired patrons (empty means no locking)','Integer'),
359
('makePreviousSerialAvailable','0','','make previous serial automatically available when collecting a new serial. Please note that the item-level_itypes syspref must be set to specific item.','YesNo'),
359
('makePreviousSerialAvailable','0','','make previous serial automatically available when collecting a new serial. Please note that the item-level_itypes syspref must be set to specific item.','YesNo'),
360
('Mana','2',NULL,'request to Mana Webservice. Mana centralize common information between other Koha to facilitate the creation of new subscriptions, vendors, report queries etc... You can search, share, import and comment the content of Mana.','Choice'),
360
('Mana','2',NULL,'request to Mana Webservice. Mana centralize common information between other Koha to facilitate the creation of new subscriptions, vendors, report queries etc... You can search, share, import and comment the content of Mana.','Choice'),
361
('ManInvInNoissuesCharge','1',NULL,'MANUAL_INV charges block checkouts (added to noissuescharge).','YesNo'),
362
('MARCAuthorityControlField008','|| aca||aabn           | a|a     d',NULL,'Define the contents of MARC21 authority control field 008 position 06-39','Textarea'),
361
('MARCAuthorityControlField008','|| aca||aabn           | a|a     d',NULL,'Define the contents of MARC21 authority control field 008 position 06-39','Textarea'),
363
('MarcFieldDocURL', NULL, NULL, 'URL used for MARC field documentation. Following substitutions are available: {MARC} = marc flavour, eg. "MARC21" or "UNIMARC". {FIELD} = field number, eg. "000" or "048". {LANG} = user language, eg. "en" or "fi-FI"', 'free'),
362
('MarcFieldDocURL', NULL, NULL, 'URL used for MARC field documentation. Following substitutions are available: {MARC} = marc flavour, eg. "MARC21" or "UNIMARC". {FIELD} = field number, eg. "000" or "048". {LANG} = user language, eg. "en" or "fi-FI"', 'free'),
364
('MarcFieldForCreatorId','',NULL,'Where to store the borrowernumber of the record''s creator','Free'),
363
('MarcFieldForCreatorId','',NULL,'Where to store the borrowernumber of the record''s creator','Free'),
Lines 605-611 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
605
('RenewalSendNotice','0','',NULL,'YesNo'),
604
('RenewalSendNotice','0','',NULL,'YesNo'),
606
('RenewSerialAddsSuggestion','0',NULL,'If ON, adds a new suggestion at serial subscription renewal','YesNo'),
605
('RenewSerialAddsSuggestion','0',NULL,'If ON, adds a new suggestion at serial subscription renewal','YesNo'),
607
('RentalFeesCheckoutConfirmation', '0', NULL , 'Allow user to confirm when checking out an item with rental fees.', 'YesNo'),
606
('RentalFeesCheckoutConfirmation', '0', NULL , 'Allow user to confirm when checking out an item with rental fees.', 'YesNo'),
608
('RentalsInNoissuesCharge','1',NULL,'Rental charges block checkouts (added to noissuescharge).','YesNo'),
609
('ReplyToDefault','',NULL,'Use this email address as the replyto in emails','Free'),
607
('ReplyToDefault','',NULL,'Use this email address as the replyto in emails','Free'),
610
('ReportsLog','0',NULL,'If ON, log information about reports.','YesNo'),
608
('ReportsLog','0',NULL,'If ON, log information about reports.','YesNo'),
611
('RequireCashRegister','0',NULL,'Require a cash register when collecting a payment','YesNo'),
609
('RequireCashRegister','0',NULL,'Require a cash register when collecting a payment','YesNo'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (-19 lines)
Lines 375-398 Circulation: Link Here
375
            - pref: NoIssuesChargeGuarantorsWithGuarantees
375
            - pref: NoIssuesChargeGuarantorsWithGuarantees
376
              class: integer
376
              class: integer
377
            - '[% local_currency %] in fines.'
377
            - '[% local_currency %] in fines.'
378
        -
379
            - pref: RentalsInNoissuesCharge
380
              choices:
381
                  1: Include
382
                  0: "Don't include"
383
            - rental charges when summing up charges for limit set in the <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=noissuescharge">noissuescharge</a> system preference.
384
        -
385
            - pref: ManInvInNoissuesCharge
386
              choices:
387
                  1: Include
388
                  0: "Don't include"
389
            - custom debit type charges when summing up charges for limit set in the <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=noissuescharge">noissuescharge</a> system preference.
390
        -
391
            - pref: HoldsInNoissuesCharge
392
              choices:
393
                  1: Include
394
                  0: "Don't include"
395
            - hold charges when summing up charges for limit set in the <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=noissuescharge">noissuescharge</a> system preference.
396
        -
378
        -
397
            - pref: ReturnBeforeExpiry
379
            - pref: ReturnBeforeExpiry
398
              choices:
380
              choices:
399
- 

Return to bug 32450