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

(-)a/installer/data/mysql/kohastructure.sql (-44 / +90 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 2678-2727 CREATE TABLE `messages` ( -- circulation messages left via the patron's check ou Link Here
2678
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2679
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2679
2680
2680
--
2681
--
2681
-- Table structure for table `accountlines`
2682
--
2683
2684
DROP TABLE IF EXISTS `accountlines`;
2685
CREATE TABLE `accountlines` (
2686
  `accountlines_id` int(11) NOT NULL AUTO_INCREMENT,
2687
  `borrowernumber` int(11) NOT NULL default 0,
2688
  `accountno` smallint(6) NOT NULL default 0,
2689
  `itemnumber` int(11) default NULL,
2690
  `date` date default NULL,
2691
  `amount` decimal(28,6) default NULL,
2692
  `description` mediumtext,
2693
  `dispute` mediumtext,
2694
  `accounttype` varchar(5) default NULL,
2695
  `amountoutstanding` decimal(28,6) default NULL,
2696
  `lastincrement` decimal(28,6) default NULL,
2697
  `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
2698
  `notify_id` int(11) NOT NULL default 0,
2699
  `notify_level` int(2) NOT NULL default 0,
2700
  `note` text NULL default NULL,
2701
  `manager_id` int(11) NULL,
2702
  PRIMARY KEY (`accountlines_id`),
2703
  KEY `acctsborridx` (`borrowernumber`),
2704
  KEY `timeidx` (`timestamp`),
2705
  KEY `itemnumber` (`itemnumber`),
2706
  CONSTRAINT `accountlines_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
2707
  CONSTRAINT `accountlines_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE SET NULL ON UPDATE SET NULL
2708
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2709
2710
--
2711
-- Table structure for table `accountoffsets`
2712
--
2713
2714
DROP TABLE IF EXISTS `accountoffsets`;
2715
CREATE TABLE `accountoffsets` (
2716
  `borrowernumber` int(11) NOT NULL default 0,
2717
  `accountno` smallint(6) NOT NULL default 0,
2718
  `offsetaccount` smallint(6) NOT NULL default 0,
2719
  `offsetamount` decimal(28,6) default NULL,
2720
  `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
2721
  CONSTRAINT `accountoffsets_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
2722
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2723
2724
--
2725
-- Table structure for table `action_logs`
2682
-- Table structure for table `action_logs`
2726
--
2683
--
2727
2684
Lines 3387-3392 CREATE TABLE IF NOT EXISTS marc_modification_template_actions ( Link Here
3387
  CONSTRAINT `mmta_ibfk_1` FOREIGN KEY (`template_id`) REFERENCES `marc_modification_templates` (`template_id`) ON DELETE CASCADE ON UPDATE CASCADE
3344
  CONSTRAINT `mmta_ibfk_1` FOREIGN KEY (`template_id`) REFERENCES `marc_modification_templates` (`template_id`) ON DELETE CASCADE ON UPDATE CASCADE
3388
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
3345
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
3389
3346
3347
--
3348
-- Table structure for table 'account_credits'
3349
--
3350
DROP TABLE IF EXISTS account_credits;
3351
CREATE TABLE IF account_credits (
3352
    credit_id int(11) NOT NULL AUTO_INCREMENT,  -- The unique id for this credit
3353
    borrowernumber int(11) NOT NULL,            -- The borrower this credit applies to
3354
    `type` varchar(255) NOT NULL,               -- The type of credit this is ( defined by Koha::Accounts::CreditTypes )
3355
    amount_received decimal(28,6) DEFAULT NULL, -- If this was a cash payment, the amount of money given
3356
    amount_paid decimal(28,6) NOT NULL,         -- The actual ammount paid, if less than amount_recieved, change was given back
3357
    amount_remaining decimal(28,6) NOT NULL,    -- The amount of this credit that has not been applied to outstanding debits
3358
    notes text,                                 -- Misc notes for this credit
3359
    branchcode VARCHAR( 10 ) NULL DEFAULT NULL, -- Branchcode where the credit was created ( if any )
3360
    manager_id int(11) DEFAULT NULL,            -- The borrowernumber of the user who created this credit ( if any )
3361
    created_on timestamp NULL DEFAULT NULL,     -- Timestamp for when this credit was created
3362
    updated_on timestamp NULL DEFAULT NULL,     -- Timestamp for when this credit was last modified
3363
    PRIMARY KEY (credit_id),
3364
    KEY borrowernumber (borrowernumber),
3365
    KEY branchcode (branchcode)
3366
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
3367
3368
--
3369
-- Constraints for table `account_credits`
3370
--
3371
ALTER TABLE `account_credits`
3372
  ADD CONSTRAINT account_credits_ibfk_1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE,
3373
  ADD CONSTRAINT account_credits_ibfk_2 FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE;
3374
3375
--
3376
-- Table structure for table 'account_debits'
3377
--
3378
3379
DROP TABLE IF EXISTS account_debits;
3380
CREATE TABLE account_debits (
3381
    debit_id int(11) NOT NULL AUTO_INCREMENT,           -- The unique id for this debit
3382
    borrowernumber int(11) NOT NULL DEFAULT '0',        -- The borrower this debit applies to
3383
    itemnumber int(11) DEFAULT NULL,                    -- The item related to this debit ( for fines, lost fees, etc )
3384
    issue_id int(11) DEFAULT NULL,                      -- The checkout this debit is related to ( again, for fines, lost fees, etc )
3385
    `type` varchar(255) NOT NULL,                       -- The type of debit this is ( defined by Koha::Accounts::DebitTypes )
3386
    accruing tinyint(1) NOT NULL DEFAULT '0',           -- Boolean flag, tells of if this is a fine that is still accruing
3387
    amount_original decimal(28,6) DEFAULT NULL,         -- The total amount of this debit
3388
    amount_outstanding decimal(28,6) DEFAULT NULL,      -- The amount still owed on this debit
3389
    amount_last_increment decimal(28,6) DEFAULT NULL,   -- The amount by which this debit last changed
3390
    description mediumtext,                             -- The description for this debit
3391
    notes text,                                         -- Misc notes for this debit
3392
    branchcode VARCHAR( 10 ) NULL DEFAULT NULL,         -- Branchcode where the debit was created ( if any )
3393
    manager_id int(11) DEFAULT NULL,                    -- The borrowernumber of the user who created this debit ( if any )
3394
    created_on timestamp NULL DEFAULT NULL,             -- Timestamp for when this credit was created
3395
    updated_on timestamp NULL DEFAULT NULL,             -- Timestamp for when this credit was last modified
3396
    PRIMARY KEY (debit_id),
3397
    KEY acctsborridx (borrowernumber),
3398
    KEY itemnumber (itemnumber),
3399
    KEY borrowernumber (borrowernumber),
3400
    KEY issue_id (issue_id),
3401
    KEY branchcode (branchcode)
3402
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
3403
3404
--
3405
-- Constraints for table `account_debits`
3406
--
3407
ALTER TABLE `account_debits`
3408
    ADD CONSTRAINT account_debits_ibfk_1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE,
3409
    ADD CONSTRAINT account_debits_ibfk_2 FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE;
3410
3411
--
3412
-- Table structure for table 'account_offsets'
3413
--
3414
3415
DROP TABLE IF EXISTS account_offsets;
3416
CREATE TABLE account_offsets (
3417
    offset_id int(11) NOT NULL AUTO_INCREMENT,                                              -- Unique id for this offset
3418
    debit_id int(11) DEFAULT NULL,                                                          -- Related debit
3419
    credit_id int(11) DEFAULT NULL,                                                         -- Related credit ( if any )
3420
    `type` varchar(255) DEFAULT NULL,                                                       -- The type of this offset ( defined by Koha::Accounts::OffsetTypes ), if any
3421
    amount decimal(28,6) NOT NULL,                                                          -- The amount of the offset, positive means patron owes more, negative means patron owes less
3422
    created_on timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,    -- Timestamp for when this offset was created
3423
    PRIMARY KEY (offset_id),
3424
    KEY fee_id (debit_id),
3425
    KEY payment_id (credit_id)
3426
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
3427
3428
--
3429
-- Constraints for table `account_offsets`
3430
--
3431
ALTER TABLE `account_offsets`
3432
    ADD CONSTRAINT account_offsets_ibfk_1 FOREIGN KEY (debit_id) REFERENCES account_debits (debit_id) ON DELETE CASCADE ON UPDATE CASCADE,
3433
    ADD CONSTRAINT account_offsets_ibfk_2 FOREIGN KEY (credit_id) REFERENCES account_credits (credit_id) ON DELETE CASCADE ON UPDATE CASCADE;
3434
3435
3390
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
3436
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
3391
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
3437
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
3392
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
3438
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
(-)a/installer/data/mysql/updatedatabase.pl (-1 / +182 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 7259-7264 if ( CheckVersion($DBversion) ) { Link Here
7259
7260
7260
    $dbh->{AutoCommit} = 1;
7261
    $dbh->{AutoCommit} = 1;
7261
    $dbh->{RaiseError} = 0;
7262
    $dbh->{RaiseError} = 0;
7263
   SetVersion ($DBversion);
7262
}
7264
}
7263
7265
7264
$DBversion = "3.13.00.031";
7266
$DBversion = "3.13.00.031";
Lines 7824-7829 if ( CheckVersion($DBversion) ) { Link Here
7824
    SetVersion($DBversion);
7826
    SetVersion($DBversion);
7825
}
7827
}
7826
7828
7829
$DBversion = "3.15.00.XXX";
7830
if ( CheckVersion($DBversion) ) {
7831
    $dbh->do(q{
7832
        ALTER TABLE old_issues ADD issue_id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST
7833
    });
7834
    $dbh->do(q{
7835
        ALTER TABLE issues ADD issue_id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;
7836
    });
7837
    $dbh->do(q{
7838
        UPDATE issues SET issue_id = issue_id + ( SELECT COUNT(*) FROM old_issues ) ORDER BY issue_id DESC
7839
    });
7840
7841
    $dbh->do("
7842
        CREATE TABLE IF NOT EXISTS account_credits (
7843
            credit_id int(11) NOT NULL AUTO_INCREMENT,
7844
            borrowernumber int(11) NOT NULL,
7845
            `type` varchar(255) NOT NULL,
7846
            amount_received decimal(28,6) DEFAULT NULL,
7847
            amount_paid decimal(28,6) NOT NULL,
7848
            amount_remaining decimal(28,6) NOT NULL,
7849
            notes text,
7850
            branchcode VARCHAR( 10 ) NULL DEFAULT NULL,
7851
            manager_id int(11) DEFAULT NULL,
7852
            created_on timestamp NULL DEFAULT NULL,
7853
            updated_on timestamp NULL DEFAULT NULL,
7854
            PRIMARY KEY (credit_id),
7855
            KEY borrowernumber (borrowernumber),
7856
            KEY branchcode (branchcode)
7857
        ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
7858
    ");
7859
    $dbh->do("
7860
        CREATE TABLE IF NOT EXISTS account_debits (
7861
            debit_id int(11) NOT NULL AUTO_INCREMENT,
7862
            borrowernumber int(11) NOT NULL DEFAULT '0',
7863
            itemnumber int(11) DEFAULT NULL,
7864
            issue_id int(11) DEFAULT NULL,
7865
            `type` varchar(255) NOT NULL,
7866
            accruing tinyint(1) NOT NULL DEFAULT '0',
7867
            amount_original decimal(28,6) DEFAULT NULL,
7868
            amount_outstanding decimal(28,6) DEFAULT NULL,
7869
            amount_last_increment decimal(28,6) DEFAULT NULL,
7870
            description mediumtext,
7871
            notes text,
7872
            branchcode VARCHAR( 10 ) NULL DEFAULT NULL,
7873
            manager_id int(11) DEFAULT NULL,
7874
            created_on timestamp NULL DEFAULT NULL,
7875
            updated_on timestamp NULL DEFAULT NULL,
7876
            PRIMARY KEY (debit_id),
7877
            KEY acctsborridx (borrowernumber),
7878
            KEY itemnumber (itemnumber),
7879
            KEY borrowernumber (borrowernumber),
7880
            KEY issue_id (issue_id),
7881
            KEY branchcode (branchcode)
7882
        ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
7883
    ");
7884
7885
    $dbh->do("
7886
        CREATE TABLE account_offsets (
7887
            offset_id int(11) NOT NULL AUTO_INCREMENT,
7888
            debit_id int(11) DEFAULT NULL,
7889
            credit_id int(11) DEFAULT NULL,
7890
            `type` varchar(255) DEFAULT NULL,
7891
            amount decimal(28,6) NOT NULL COMMENT 'A positive number here represents a payment, a negative is a increase in a fine.',
7892
            created_on timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
7893
            PRIMARY KEY (offset_id),
7894
            KEY fee_id (debit_id),
7895
            KEY payment_id (credit_id)
7896
        ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
7897
    ");
7898
7899
    $dbh->do("
7900
        ALTER TABLE `account_credits`
7901
          ADD CONSTRAINT account_credits_ibfk_1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE,
7902
          ADD CONSTRAINT account_credits_ibfk_2 FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE;
7903
    ");
7904
    $dbh->do("
7905
        ALTER TABLE `account_debits`
7906
          ADD CONSTRAINT account_debits_ibfk_1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE,
7907
          ADD CONSTRAINT account_debits_ibfk_2 FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE;
7908
    ");
7909
    $dbh->do("
7910
        ALTER TABLE `account_offsets`
7911
          ADD CONSTRAINT account_offsets_ibfk_1 FOREIGN KEY (debit_id) REFERENCES account_debits (debit_id) ON DELETE CASCADE ON UPDATE CASCADE,
7912
          ADD CONSTRAINT account_offsets_ibfk_2 FOREIGN KEY (credit_id) REFERENCES account_credits (credit_id) ON DELETE CASCADE ON UPDATE CASCADE;
7913
    ");
7914
7915
    $dbh->do("
7916
        ALTER TABLE borrowers ADD account_balance DECIMAL( 28, 6 ) NOT NULL;
7917
    ");
7918
7919
    my $schema = Koha::Database->new()->schema;
7920
    my $debit_rs = $schema->resultset('AccountDebit');
7921
    my $credit_rs = $schema->resultset('AccountCredit');
7922
    my $issues_rs = $schema->resultset('Issue');
7923
7924
    use Koha::Accounts::DebitTypes;
7925
    use Koha::Accounts::CreditTypes;
7926
7927
    my $debit_types_map = {
7928
        'A'    => Koha::Accounts::DebitTypes::AccountManagementFee,
7929
        'F'    => Koha::Accounts::DebitTypes::Fine,
7930
        'FU'   => Koha::Accounts::DebitTypes::Fine,
7931
        'L'    => Koha::Accounts::DebitTypes::Lost,
7932
        'M'    => Koha::Accounts::DebitTypes::Sundry,
7933
        'N'    => Koha::Accounts::DebitTypes::NewCard,
7934
        'Rent' => Koha::Accounts::DebitTypes::Rental,
7935
    };
7936
7937
    my $credit_types_map = {
7938
        'FOR' => Koha::Accounts::CreditTypes::Forgiven,
7939
        'LR'  => Koha::Accounts::CreditTypes::Found,
7940
        'Pay' => Koha::Accounts::CreditTypes::Payment,
7941
        'PAY' => Koha::Accounts::CreditTypes::Payment,
7942
        'WO'  => Koha::Accounts::CreditTypes::WriteOff,
7943
        'W'   => Koha::Accounts::CreditTypes::WriteOff,
7944
        'C'   => Koha::Accounts::CreditTypes::Credit,
7945
        'CR'  => Koha::Accounts::CreditTypes::Credit,
7946
    };
7947
7948
    my $sth = $dbh->prepare("SELECT * FROM accountlines");
7949
    $sth->execute();
7950
    while ( my $a = $sth->fetchrow_hashref() ) {
7951
        if ( $debit_types_map->{ $a->{accounttype} } ) {
7952
            $debit_rs->create(
7953
                {
7954
                    borrowernumber     => $a->{borrowernumber},
7955
                    itemnumber         => $a->{itemnumber},
7956
                    amount_original    => $a->{amount},
7957
                    amount_outstanding => $a->{amountoutstanding},
7958
                    created_on         => $a->{timestamp},
7959
                    description        => $a->{description},
7960
                    notes              => $a->{note},
7961
                    manager_id         => $a->{manager_id},
7962
                    accruing           => $a->{accounttype} eq 'FU',
7963
                    type     => $debit_types_map->{ $a->{accounttype} },
7964
                    issue_id => $a->{accounttype} eq 'FU'
7965
                    ? $issues_rs->single(
7966
                        {
7967
                            borrowernumber => $a->{borrowernumber},
7968
                            itemnumber     => $a->{itemnumber},
7969
                        }
7970
                      )->issue_id()
7971
                    : undef,
7972
                }
7973
            );
7974
        }
7975
        elsif ( $credit_types_map->{ $a->{accounttype} } ) {
7976
            $credit_rs->create(
7977
                {
7978
                    borrowernumber   => $a->{borrowernumber},
7979
                    amount_paid      => $a->{amount} * -1,
7980
                    amount_remaining => $a->{amountoutstanding} * -1,
7981
                    created_on       => $a->{timestamp},
7982
                    notes            => $a->{note},
7983
                    manager_id       => $a->{manager_id},
7984
                    type => $credit_types_map->{ $a->{accounttype} },
7985
                }
7986
            );
7987
        }
7988
        else {
7989
            # Everything else must be a MANUAL_INV
7990
            $debit_rs->create(
7991
                {
7992
                    borrowernumber     => $a->{borrowernumber},
7993
                    itemnumber         => $a->{itemnumber},
7994
                    amount_original    => $a->{amount},
7995
                    amount_outstanding => $a->{amountoutstanding},
7996
                    created_on         => $a->{timestamp},
7997
                    description        => $a->{description},
7998
                    notes              => $a->{note},
7999
                    manager_id         => $a->{manager_id},
8000
                    type               => Koha::Accounts::DebitTypes::Sundry,
8001
                }
8002
            );
8003
        }
8004
    }
8005
8006
    print "Upgrade to $DBversion done ( Bug 6427 - Rewrite of the accounts system )\n";
8007
    SetVersion ($DBversion);
8008
}
7827
8009
7828
=head1 FUNCTIONS
8010
=head1 FUNCTIONS
7829
8011
7830
- 

Return to bug 6427