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

(-)a/installer/data/mysql/kohastructure.sql (-44 / +91 lines)
Lines 265-270 CREATE TABLE `borrowers` ( -- this table includes information about your patrons Link Here
265
  `altcontactphone` varchar(50) default NULL, -- the phone number for the alternate contact for the patron/borrower
265
  `altcontactphone` varchar(50) default NULL, -- the phone number for the alternate contact for the patron/borrower
266
  `smsalertnumber` varchar(50) default NULL, -- the mobile phone number where the patron/borrower would like to receive notices (if SNS turned on)
266
  `smsalertnumber` varchar(50) default NULL, -- the mobile phone number where the patron/borrower would like to receive notices (if SNS turned on)
267
  `privacy` integer(11) DEFAULT '1' NOT NULL, -- patron/borrower's privacy settings related to their reading history
267
  `privacy` integer(11) DEFAULT '1' NOT NULL, -- patron/borrower's privacy settings related to their reading history
268
  `account_balance` decimal(28,6) NOT NULL,
268
  UNIQUE KEY `cardnumber` (`cardnumber`),
269
  UNIQUE KEY `cardnumber` (`cardnumber`),
269
  PRIMARY KEY `borrowernumber` (`borrowernumber`),
270
  PRIMARY KEY `borrowernumber` (`borrowernumber`),
270
  KEY `categorycode` (`categorycode`),
271
  KEY `categorycode` (`categorycode`),
Lines 2708-2757 CREATE TABLE `messages` ( -- circulation messages left via the patron's check ou Link Here
2708
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2709
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2709
2710
2710
--
2711
--
2711
-- Table structure for table `accountlines`
2712
--
2713
2714
DROP TABLE IF EXISTS `accountlines`;
2715
CREATE TABLE `accountlines` (
2716
  `accountlines_id` int(11) NOT NULL AUTO_INCREMENT,
2717
  `borrowernumber` int(11) NOT NULL default 0,
2718
  `accountno` smallint(6) NOT NULL default 0,
2719
  `itemnumber` int(11) default NULL,
2720
  `date` date default NULL,
2721
  `amount` decimal(28,6) default NULL,
2722
  `description` mediumtext,
2723
  `dispute` mediumtext,
2724
  `accounttype` varchar(5) default NULL,
2725
  `amountoutstanding` decimal(28,6) default NULL,
2726
  `lastincrement` decimal(28,6) default NULL,
2727
  `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
2728
  `notify_id` int(11) NOT NULL default 0,
2729
  `notify_level` int(2) NOT NULL default 0,
2730
  `note` text NULL default NULL,
2731
  `manager_id` int(11) NULL,
2732
  PRIMARY KEY (`accountlines_id`),
2733
  KEY `acctsborridx` (`borrowernumber`),
2734
  KEY `timeidx` (`timestamp`),
2735
  KEY `itemnumber` (`itemnumber`),
2736
  CONSTRAINT `accountlines_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
2737
  CONSTRAINT `accountlines_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE SET NULL ON UPDATE SET NULL
2738
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2739
2740
--
2741
-- Table structure for table `accountoffsets`
2742
--
2743
2744
DROP TABLE IF EXISTS `accountoffsets`;
2745
CREATE TABLE `accountoffsets` (
2746
  `borrowernumber` int(11) NOT NULL default 0,
2747
  `accountno` smallint(6) NOT NULL default 0,
2748
  `offsetaccount` smallint(6) NOT NULL default 0,
2749
  `offsetamount` decimal(28,6) default NULL,
2750
  `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
2751
  CONSTRAINT `accountoffsets_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
2752
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2753
2754
--
2755
-- Table structure for table `action_logs`
2712
-- Table structure for table `action_logs`
2756
--
2713
--
2757
2714
Lines 3458-3463 CREATE TABLE IF NOT EXISTS columns_settings ( Link Here
3458
    PRIMARY KEY(module, page, tablename, columnname)
3415
    PRIMARY KEY(module, page, tablename, columnname)
3459
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3416
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3460
3417
3418
--
3419
-- Table structure for table 'account_credits'
3420
--
3421
DROP TABLE IF EXISTS account_credits;
3422
CREATE TABLE IF account_credits (
3423
    credit_id int(11) NOT NULL AUTO_INCREMENT,     -- The unique id for this credit
3424
    borrowernumber int(11) NOT NULL,               -- The borrower this credit applies to
3425
    `type` varchar(255) NOT NULL,                  -- The type of credit this is ( defined by Koha::Accounts::CreditTypes )
3426
    amount_received decimal(28,6) DEFAULT NULL,    -- If this was a cash payment, the amount of money given
3427
    amount_paid decimal(28,6) NOT NULL,            -- The actual ammount paid, if less than amount_recieved, change was given back
3428
    amount_remaining decimal(28,6) NOT NULL,       -- The amount of this credit that has not been applied to outstanding debits
3429
    amount_voided decimal(28,6) NULL DEFAULT NULL, -- The amount of this credit was for before it was voided
3430
    notes text,                                    -- Misc notes for this credit
3431
    branchcode VARCHAR( 10 ) NULL DEFAULT NULL,    -- Branchcode where the credit was created ( if any )
3432
    manager_id int(11) DEFAULT NULL,               -- The borrowernumber of the user who created this credit ( if any )
3433
    created_on timestamp NULL DEFAULT NULL,        -- Timestamp for when this credit was created
3434
    updated_on timestamp NULL DEFAULT NULL,        -- Timestamp for when this credit was last modified
3435
    PRIMARY KEY (credit_id),
3436
    KEY borrowernumber (borrowernumber),
3437
    KEY branchcode (branchcode)
3438
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
3439
3440
--
3441
-- Constraints for table `account_credits`
3442
--
3443
ALTER TABLE `account_credits`
3444
  ADD CONSTRAINT account_credits_ibfk_1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE,
3445
  ADD CONSTRAINT account_credits_ibfk_2 FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE;
3446
3447
--
3448
-- Table structure for table 'account_debits'
3449
--
3450
3451
DROP TABLE IF EXISTS account_debits;
3452
CREATE TABLE account_debits (
3453
    debit_id int(11) NOT NULL AUTO_INCREMENT,           -- The unique id for this debit
3454
    borrowernumber int(11) NOT NULL DEFAULT '0',        -- The borrower this debit applies to
3455
    itemnumber int(11) DEFAULT NULL,                    -- The item related to this debit ( for fines, lost fees, etc )
3456
    issue_id int(11) DEFAULT NULL,                      -- The checkout this debit is related to ( again, for fines, lost fees, etc )
3457
    `type` varchar(255) NOT NULL,                       -- The type of debit this is ( defined by Koha::Accounts::DebitTypes )
3458
    accruing tinyint(1) NOT NULL DEFAULT '0',           -- Boolean flag, tells of if this is a fine that is still accruing
3459
    amount_original decimal(28,6) DEFAULT NULL,         -- The total amount of this debit
3460
    amount_outstanding decimal(28,6) DEFAULT NULL,      -- The amount still owed on this debit
3461
    amount_last_increment decimal(28,6) DEFAULT NULL,   -- The amount by which this debit last changed
3462
    description mediumtext,                             -- The description for this debit
3463
    notes text,                                         -- Misc notes for this debit
3464
    branchcode VARCHAR( 10 ) NULL DEFAULT NULL,         -- Branchcode where the debit was created ( if any )
3465
    manager_id int(11) DEFAULT NULL,                    -- The borrowernumber of the user who created this debit ( if any )
3466
    created_on timestamp NULL DEFAULT NULL,             -- Timestamp for when this credit was created
3467
    updated_on timestamp NULL DEFAULT NULL,             -- Timestamp for when this credit was last modified
3468
    PRIMARY KEY (debit_id),
3469
    KEY acctsborridx (borrowernumber),
3470
    KEY itemnumber (itemnumber),
3471
    KEY borrowernumber (borrowernumber),
3472
    KEY issue_id (issue_id),
3473
    KEY branchcode (branchcode)
3474
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
3475
3476
--
3477
-- Constraints for table `account_debits`
3478
--
3479
ALTER TABLE `account_debits`
3480
    ADD CONSTRAINT account_debits_ibfk_1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE,
3481
    ADD CONSTRAINT account_debits_ibfk_2 FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE;
3482
3483
--
3484
-- Table structure for table 'account_offsets'
3485
--
3486
3487
DROP TABLE IF EXISTS account_offsets;
3488
CREATE TABLE account_offsets (
3489
    offset_id int(11) NOT NULL AUTO_INCREMENT,                                              -- Unique id for this offset
3490
    debit_id int(11) DEFAULT NULL,                                                          -- Related debit
3491
    credit_id int(11) DEFAULT NULL,                                                         -- Related credit ( if any )
3492
    `type` varchar(255) DEFAULT NULL,                                                       -- The type of this offset ( defined by Koha::Accounts::OffsetTypes ), if any
3493
    amount decimal(28,6) NOT NULL,                                                          -- The amount of the offset, positive means patron owes more, negative means patron owes less
3494
    created_on timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,    -- Timestamp for when this offset was created
3495
    PRIMARY KEY (offset_id),
3496
    KEY fee_id (debit_id),
3497
    KEY payment_id (credit_id)
3498
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
3499
3500
--
3501
-- Constraints for table `account_offsets`
3502
--
3503
ALTER TABLE `account_offsets`
3504
    ADD CONSTRAINT account_offsets_ibfk_1 FOREIGN KEY (debit_id) REFERENCES account_debits (debit_id) ON DELETE CASCADE ON UPDATE CASCADE,
3505
    ADD CONSTRAINT account_offsets_ibfk_2 FOREIGN KEY (credit_id) REFERENCES account_credits (credit_id) ON DELETE CASCADE ON UPDATE CASCADE;
3506
3507
3461
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
3508
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
3462
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
3509
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
3463
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
3510
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
(-)a/installer/data/mysql/updatedatabase.pl (-1 / +184 lines)
Lines 37-42 use Getopt::Long; Link Here
37
use C4::Context;
37
use C4::Context;
38
use C4::Installer;
38
use C4::Installer;
39
use C4::Dates;
39
use C4::Dates;
40
use Koha::Database;
40
41
41
use MARC::Record;
42
use MARC::Record;
42
use MARC::File::XML ( BinaryEncoding => 'utf8' );
43
use MARC::File::XML ( BinaryEncoding => 'utf8' );
Lines 7257-7262 if ( CheckVersion($DBversion) ) { Link Here
7257
7258
7258
    $dbh->{AutoCommit} = 1;
7259
    $dbh->{AutoCommit} = 1;
7259
    $dbh->{RaiseError} = 0;
7260
    $dbh->{RaiseError} = 0;
7261
   SetVersion ($DBversion);
7260
}
7262
}
7261
7263
7262
$DBversion = "3.13.00.031";
7264
$DBversion = "3.13.00.031";
Lines 8815-8820 if ( CheckVersion($DBversion) ) { Link Here
8815
    $dbh->do("ALTER TABLE  `biblioitems` CHANGE  `cn_sort`  `cn_sort` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL");
8817
    $dbh->do("ALTER TABLE  `biblioitems` CHANGE  `cn_sort`  `cn_sort` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL");
8816
    $dbh->do("ALTER TABLE  `deletedbiblioitems` CHANGE  `cn_sort`  `cn_sort` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL");
8818
    $dbh->do("ALTER TABLE  `deletedbiblioitems` CHANGE  `cn_sort`  `cn_sort` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL");
8817
    print "Upgrade to $DBversion done (Bug 12424 - ddc sorting of call numbers truncates long Cutter parts)\n";
8819
    print "Upgrade to $DBversion done (Bug 12424 - ddc sorting of call numbers truncates long Cutter parts)\n";
8820
    SetVersion($DBversion);
8821
}
8822
8823
$DBversion = "3.17.00.XXX";
8824
if ( CheckVersion($DBversion) ) {
8825
    $dbh->do(q{
8826
        ALTER TABLE old_issues ADD issue_id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST
8827
    });
8828
    $dbh->do(q{
8829
        ALTER TABLE issues ADD issue_id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;
8830
    });
8831
    $dbh->do(q{
8832
        UPDATE issues SET issue_id = issue_id + ( SELECT COUNT(*) FROM old_issues ) ORDER BY issue_id DESC
8833
    });
8834
8835
    $dbh->do("
8836
        CREATE TABLE IF NOT EXISTS account_credits (
8837
            credit_id int(11) NOT NULL AUTO_INCREMENT,
8838
            borrowernumber int(11) NOT NULL,
8839
            `type` varchar(255) NOT NULL,
8840
            amount_received decimal(28,6) DEFAULT NULL,
8841
            amount_paid decimal(28,6) NOT NULL,
8842
            amount_remaining decimal(28,6) NOT NULL,
8843
            amount_voided decimal(28,6) NULL DEFAULT NULL,
8844
            notes text,
8845
            branchcode VARCHAR( 10 ) NULL DEFAULT NULL,
8846
            manager_id int(11) DEFAULT NULL,
8847
            created_on timestamp NULL DEFAULT NULL,
8848
            updated_on timestamp NULL DEFAULT NULL,
8849
            PRIMARY KEY (credit_id),
8850
            KEY borrowernumber (borrowernumber),
8851
            KEY branchcode (branchcode)
8852
        ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
8853
    ");
8854
    $dbh->do("
8855
        CREATE TABLE IF NOT EXISTS account_debits (
8856
            debit_id int(11) NOT NULL AUTO_INCREMENT,
8857
            borrowernumber int(11) NOT NULL DEFAULT '0',
8858
            itemnumber int(11) DEFAULT NULL,
8859
            issue_id int(11) DEFAULT NULL,
8860
            `type` varchar(255) NOT NULL,
8861
            accruing tinyint(1) NOT NULL DEFAULT '0',
8862
            amount_original decimal(28,6) DEFAULT NULL,
8863
            amount_outstanding decimal(28,6) DEFAULT NULL,
8864
            amount_last_increment decimal(28,6) DEFAULT NULL,
8865
            description mediumtext,
8866
            notes text,
8867
            branchcode VARCHAR( 10 ) NULL DEFAULT NULL,
8868
            manager_id int(11) DEFAULT NULL,
8869
            created_on timestamp NULL DEFAULT NULL,
8870
            updated_on timestamp NULL DEFAULT NULL,
8871
            PRIMARY KEY (debit_id),
8872
            KEY acctsborridx (borrowernumber),
8873
            KEY itemnumber (itemnumber),
8874
            KEY borrowernumber (borrowernumber),
8875
            KEY issue_id (issue_id),
8876
            KEY branchcode (branchcode)
8877
        ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
8878
    ");
8879
8880
    $dbh->do("
8881
        CREATE TABLE account_offsets (
8882
            offset_id int(11) NOT NULL AUTO_INCREMENT,
8883
            debit_id int(11) DEFAULT NULL,
8884
            credit_id int(11) DEFAULT NULL,
8885
            `type` varchar(255) DEFAULT NULL,
8886
            amount decimal(28,6) NOT NULL COMMENT 'A positive number here represents a payment, a negative is a increase in a fine.',
8887
            created_on timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
8888
            PRIMARY KEY (offset_id),
8889
            KEY fee_id (debit_id),
8890
            KEY payment_id (credit_id)
8891
        ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
8892
    ");
8893
8894
    $dbh->do("
8895
        ALTER TABLE `account_credits`
8896
          ADD CONSTRAINT account_credits_ibfk_1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE,
8897
          ADD CONSTRAINT account_credits_ibfk_2 FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE;
8898
    ");
8899
    $dbh->do("
8900
        ALTER TABLE `account_debits`
8901
          ADD CONSTRAINT account_debits_ibfk_1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE,
8902
          ADD CONSTRAINT account_debits_ibfk_2 FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE;
8903
    ");
8904
    $dbh->do("
8905
        ALTER TABLE `account_offsets`
8906
          ADD CONSTRAINT account_offsets_ibfk_1 FOREIGN KEY (debit_id) REFERENCES account_debits (debit_id) ON DELETE CASCADE ON UPDATE CASCADE,
8907
          ADD CONSTRAINT account_offsets_ibfk_2 FOREIGN KEY (credit_id) REFERENCES account_credits (credit_id) ON DELETE CASCADE ON UPDATE CASCADE;
8908
    ");
8909
8910
    $dbh->do("
8911
        ALTER TABLE borrowers ADD account_balance DECIMAL( 28, 6 ) NOT NULL;
8912
    ");
8913
8914
    my $schema = Koha::Database->new()->schema;
8915
    my $debit_rs = $schema->resultset('AccountDebit');
8916
    my $credit_rs = $schema->resultset('AccountCredit');
8917
    my $issues_rs = $schema->resultset('Issue');
8918
8919
    use Koha::Accounts::DebitTypes;
8920
    use Koha::Accounts::CreditTypes;
8921
8922
    my $debit_types_map = {
8923
        'A'    => Koha::Accounts::DebitTypes::AccountManagementFee,
8924
        'F'    => Koha::Accounts::DebitTypes::Fine,
8925
        'FU'   => Koha::Accounts::DebitTypes::Fine,
8926
        'L'    => Koha::Accounts::DebitTypes::Lost,
8927
        'M'    => Koha::Accounts::DebitTypes::Sundry,
8928
        'N'    => Koha::Accounts::DebitTypes::NewCard,
8929
        'Rent' => Koha::Accounts::DebitTypes::Rental,
8930
    };
8931
8932
    my $credit_types_map = {
8933
        'FOR' => Koha::Accounts::CreditTypes::Forgiven,
8934
        'LR'  => Koha::Accounts::CreditTypes::Found,
8935
        'Pay' => Koha::Accounts::CreditTypes::Payment,
8936
        'PAY' => Koha::Accounts::CreditTypes::Payment,
8937
        'WO'  => Koha::Accounts::CreditTypes::WriteOff,
8938
        'W'   => Koha::Accounts::CreditTypes::WriteOff,
8939
        'C'   => Koha::Accounts::CreditTypes::Credit,
8940
        'CR'  => Koha::Accounts::CreditTypes::Credit,
8941
    };
8942
8943
    my $sth = $dbh->prepare("SELECT * FROM accountlines");
8944
    $sth->execute();
8945
    while ( my $a = $sth->fetchrow_hashref() ) {
8946
        if ( $debit_types_map->{ $a->{accounttype} } ) {
8947
            $debit_rs->create(
8948
                {
8949
                    borrowernumber     => $a->{borrowernumber},
8950
                    itemnumber         => $a->{itemnumber},
8951
                    amount_original    => $a->{amount},
8952
                    amount_outstanding => $a->{amountoutstanding},
8953
                    created_on         => $a->{timestamp},
8954
                    description        => $a->{description},
8955
                    notes              => $a->{note},
8956
                    manager_id         => $a->{manager_id},
8957
                    accruing           => $a->{accounttype} eq 'FU',
8958
                    type     => $debit_types_map->{ $a->{accounttype} },
8959
                    issue_id => $a->{accounttype} eq 'FU'
8960
                    ? $issues_rs->single(
8961
                        {
8962
                            borrowernumber => $a->{borrowernumber},
8963
                            itemnumber     => $a->{itemnumber},
8964
                        }
8965
                      )->issue_id()
8966
                    : undef,
8967
                }
8968
            );
8969
        }
8970
        elsif ( $credit_types_map->{ $a->{accounttype} } ) {
8971
            $credit_rs->create(
8972
                {
8973
                    borrowernumber   => $a->{borrowernumber},
8974
                    amount_paid      => $a->{amount} * -1,
8975
                    amount_remaining => $a->{amountoutstanding} * -1,
8976
                    created_on       => $a->{timestamp},
8977
                    notes            => $a->{note},
8978
                    manager_id       => $a->{manager_id},
8979
                    type => $credit_types_map->{ $a->{accounttype} },
8980
                }
8981
            );
8982
        }
8983
        else {
8984
            # Everything else must be a MANUAL_INV
8985
            $debit_rs->create(
8986
                {
8987
                    borrowernumber     => $a->{borrowernumber},
8988
                    itemnumber         => $a->{itemnumber},
8989
                    amount_original    => $a->{amount},
8990
                    amount_outstanding => $a->{amountoutstanding},
8991
                    created_on         => $a->{timestamp},
8992
                    description        => $a->{description},
8993
                    notes              => $a->{note},
8994
                    manager_id         => $a->{manager_id},
8995
                    type               => Koha::Accounts::DebitTypes::Sundry,
8996
                }
8997
            );
8998
        }
8999
    }
9000
9001
    print "Upgrade to $DBversion done ( Bug 6427 - Rewrite of the accounts system )\n";
8818
    SetVersion ($DBversion);
9002
    SetVersion ($DBversion);
8819
}
9003
}
8820
9004
8821
- 

Return to bug 6427