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

(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 3031-3036 CREATE TABLE `aqorders` ( -- information related to the basket line items Link Here
3031
  KEY `basketno` (`basketno`),
3031
  KEY `basketno` (`basketno`),
3032
  KEY `biblionumber` (`biblionumber`),
3032
  KEY `biblionumber` (`biblionumber`),
3033
  KEY `budget_id` (`budget_id`),
3033
  KEY `budget_id` (`budget_id`),
3034
  CONSTRAINT `aqorders_budget_id_fk` FOREIGN KEY (`budget_id`) REFERENCES `aqbudgets` (`budget_id`) ON DELETE CASCADE ON UPDATE CASCADE,
3034
  CONSTRAINT `aqorders_ibfk_1` FOREIGN KEY (`basketno`) REFERENCES `aqbasket` (`basketno`) ON DELETE CASCADE ON UPDATE CASCADE,
3035
  CONSTRAINT `aqorders_ibfk_1` FOREIGN KEY (`basketno`) REFERENCES `aqbasket` (`basketno`) ON DELETE CASCADE ON UPDATE CASCADE,
3035
  CONSTRAINT `aqorders_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE CASCADE,
3036
  CONSTRAINT `aqorders_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE CASCADE,
3036
  CONSTRAINT aqorders_ibfk_3 FOREIGN KEY (invoiceid) REFERENCES aqinvoices (invoiceid) ON DELETE SET NULL ON UPDATE CASCADE,
3037
  CONSTRAINT aqorders_ibfk_3 FOREIGN KEY (invoiceid) REFERENCES aqinvoices (invoiceid) ON DELETE SET NULL ON UPDATE CASCADE,
(-)a/installer/data/mysql/updatedatabase.pl (+41 lines)
Lines 8570-8575 if ( CheckVersion($DBversion) ) { Link Here
8570
    SetVersion($DBversion);
8570
    SetVersion($DBversion);
8571
}
8571
}
8572
8572
8573
$DBversion = "3.17.00.XXX";
8574
if ( CheckVersion($DBversion) ) {
8575
    my $number_of_orders_not_linked = $dbh->selectcol_arrayref(q|
8576
        SELECT COUNT(*)
8577
        FROM aqorders o
8578
        WHERE NOT EXISTS (
8579
            SELECT NULL
8580
            FROM aqbudgets b
8581
            WHERE b.budget_id = o.budget_id
8582
        );
8583
    |);
8584
8585
    if ( $number_of_orders_not_linked->[0] > 0 ) {
8586
        $dbh->do(q|
8587
            INSERT INTO aqbudgetperiods(budget_period_startdate, budget_period_enddate, budget_period_active, budget_period_description, budget_period_total) VALUES ( CAST(NOW() AS date), CAST(NOW() AS date), 0, "WARNING: This budget has been automatically created by the updatedatabase script, please see bug 12601 for more information", 0)
8588
        |);
8589
        my $budget_period_id = $dbh->last_insert_id( undef, undef, 'aqbudgetperiods', undef );
8590
        $dbh->do(qq|
8591
            INSERT INTO aqbudgets(budget_code, budget_name, budget_amount, budget_period_id) VALUES ( "BACKUP_TMP", "WARNING: fund created by the updatedatabase script, please see bug 12601", 0, $budget_period_id );
8592
        |);
8593
        my $budget_id = $dbh->last_insert_id( undef, undef, 'aqbudgets', undef );
8594
        $dbh->do(qq|
8595
            UPDATE aqorders o
8596
            SET budget_id = $budget_id
8597
            WHERE NOT EXISTS (
8598
                SELECT NULL
8599
                FROM aqbudgets b
8600
                WHERE b.budget_id = o.budget_id
8601
            )
8602
        |);
8603
    }
8604
8605
    $dbh->do(q|
8606
        ALTER TABLE aqorders
8607
        ADD CONSTRAINT aqorders_budget_id_fk FOREIGN KEY (budget_id) REFERENCES aqbudgets(budget_id) ON DELETE CASCADE ON UPDATE CASCADE
8608
    |);
8609
8610
    print "Upgrade to $DBversion done (Bug 12601 - Add new foreign key aqorders.budget_id" . ( ( $number_of_orders_not_linked->[0] > 0 )  ? ' WARNING: temporary budget and fund have been created (search for "BACKUP_TMP"). At least one of your order was not linked to a budget' : '' ) . ")\n";
8611
    SetVersion($DBversion);
8612
}
8613
8573
=head1 FUNCTIONS
8614
=head1 FUNCTIONS
8574
8615
8575
=head2 TableExists($table)
8616
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt (-1 / +1 lines)
Lines 593-598 var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") Link Here
593
593
594
[% IF op == 'delete_confirm' %]
594
[% IF op == 'delete_confirm' %]
595
<div class="dialog alert"> <h3>Delete fund [% budget_name %]?</h3>
595
<div class="dialog alert"> <h3>Delete fund [% budget_name %]?</h3>
596
If you delete this fund, all orders linked to this fund will be deleted!
596
<table>
597
<table>
597
    <tr>
598
    <tr>
598
    <th scope="row">Fund amount:</th>
599
    <th scope="row">Fund amount:</th>
599
- 

Return to bug 12601