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

(-)a/installer/data/mysql/kohastructure.sql (-2 / +6 lines)
Lines 3067-3074 CREATE TABLE `aqorders` ( -- information related to the basket line items Link Here
3067
  `ecost` decimal(13,2) DEFAULT NULL, -- the replacement cost for this line item
3067
  `ecost` decimal(13,2) DEFAULT NULL, -- the replacement cost for this line item
3068
  `ecost_tax_excluded` decimal(28,6) default NULL, -- the estimated cost excluding tax
3068
  `ecost_tax_excluded` decimal(28,6) default NULL, -- the estimated cost excluding tax
3069
  `ecost_tax_included` decimal(28,6) default NULL, -- the estimated cost including tax
3069
  `ecost_tax_included` decimal(28,6) default NULL, -- the estimated cost including tax
3070
  `tax_rate` decimal(6,4) DEFAULT NULL, -- the tax rate for this line item (%)
3070
  `tax_rate_bak` decimal(6,4) DEFAULT NULL, -- the tax rate for this line item (%)
3071
  `tax_value` decimal(28,6) default NULL, -- the tax value for this line item
3071
  `tax_rate_on_ordering` decimal(6,4) DEFAULT NULL, -- the tax rate on ordering for this line item (%)
3072
  `tax_rate_on_receiving` decimal(6,4) DEFAULT NULL, -- the tax rate on receiving for this line item (%)
3073
  `tax_value_bak` decimal(28,6) default NULL, -- the tax value for this line item
3074
  `tax_value_on_ordering` decimal(28,6) DEFAULT NULL, -- the tax value on ordering for this line item
3075
  `tax_value_on_receiving` decimal(28,6) DEFAULT NULL, -- the tax value on receiving for this line item
3072
  `discount` float(6,4) default NULL, -- the discount for this line item (%)
3076
  `discount` float(6,4) default NULL, -- the discount for this line item (%)
3073
  `budget_id` int(11) NOT NULL, -- the fund this order goes against (aqbudgets.budget_id)
3077
  `budget_id` int(11) NOT NULL, -- the fund this order goes against (aqbudgets.budget_id)
3074
  `budgetgroup_id` int(11) NOT NULL, -- not used? always zero
3078
  `budgetgroup_id` int(11) NOT NULL, -- not used? always zero
(-)a/installer/data/mysql/updatedatabase.pl (-1 / +55 lines)
Lines 9635-9640 if ( CheckVersion($DBversion) ) { Link Here
9635
    SetVersion($DBversion);
9635
    SetVersion($DBversion);
9636
}
9636
}
9637
9637
9638
$DBversion = '3.17.00.XXX';
9639
if ( CheckVersion($DBversion) ) {
9640
9641
    ## Add the new columns
9642
    $dbh->do(q|
9643
        ALTER TABLE aqorders
9644
            ADD COLUMN tax_rate_on_ordering   decimal(6,4) default NULL AFTER tax_rate,
9645
            ADD COLUMN tax_rate_on_receiving  decimal(6,4) default NULL AFTER tax_rate_on_ordering,
9646
            ADD COLUMN tax_value_on_ordering  decimal(28,6) default NULL AFTER tax_value,
9647
            ADD COLUMN tax_value_on_receiving decimal(28,6) default NULL AFTER tax_value_on_ordering
9648
    |);
9649
9650
    my $orders = $dbh->selectall_arrayref(q|
9651
        SELECT * FROM aqorders
9652
    |, { Slice => {} } );
9653
9654
    my $sth_update_order = $dbh->prepare(q|
9655
        UPDATE aqorders
9656
        SET tax_rate_on_ordering = tax_rate,
9657
            tax_rate_on_receiving = tax_rate,
9658
            tax_value_on_ordering = ?,
9659
            tax_value_on_receiving = ?
9660
        WHERE ordernumber = ?
9661
    |);
9662
9663
    require Koha::Number::Price;
9664
    for my $order (@$orders) {
9665
        my $tax_value_on_ordering =
9666
          $order->{quantity} *
9667
          $order->{ecost_tax_excluded} *
9668
          $order->{tax_rate};
9669
9670
        my $tax_value_on_receiving =
9671
          ( defined $order->{unitprice_tax_excluded} )
9672
          ? $order->{quantity} * $order->{unitprice_tax_excluded} * $order->{tax_rate}
9673
          : undef;
9674
9675
        $sth_update_order->execute( $tax_value_on_ordering,
9676
            $tax_value_on_receiving, $order->{ordernumber} );
9677
    }
9678
9679
    # Remove the old columns
9680
    $dbh->do(q|
9681
        ALTER TABLE aqorders
9682
            CHANGE COLUMN tax_value tax_value_bak  decimal(28,6) default NULL,
9683
            CHANGE COLUMN tax_rate tax_rate_bak decimal(6,4) default NULL
9684
    |);
9685
9686
9687
9688
    print "Upgrade to $DBversion done (Bug XXXXX - Tax rate can change on receiving)\n";
9689
    SetVersion($DBversion);
9690
9691
}
9692
9638
=head1 FUNCTIONS
9693
=head1 FUNCTIONS
9639
9694
9640
=head2 TableExists($table)
9695
=head2 TableExists($table)
9641
- 

Return to bug 13323