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

(-)a/installer/data/mysql/atomicupdate/bug_13323.perl (+51 lines)
Line 0 Link Here
1
#!/usr/bin/env perl
2
3
use Modern::Perl;
4
use C4::Context;
5
6
my $dbh = C4::Context->dbh;
7
8
# Add the new columns
9
$dbh->do(q|
10
    ALTER TABLE aqorders
11
        ADD COLUMN tax_rate_on_ordering   decimal(6,4) default NULL AFTER tax_rate,
12
        ADD COLUMN tax_rate_on_receiving  decimal(6,4) default NULL AFTER tax_rate_on_ordering,
13
        ADD COLUMN tax_value_on_ordering  decimal(28,6) default NULL AFTER tax_value,
14
        ADD COLUMN tax_value_on_receiving decimal(28,6) default NULL AFTER tax_value_on_ordering
15
|);
16
17
my $orders = $dbh->selectall_arrayref(q|
18
    SELECT * FROM aqorders
19
|, { Slice => {} } );
20
21
my $sth_update_order = $dbh->prepare(q|
22
    UPDATE aqorders
23
    SET tax_rate_on_ordering = tax_rate,
24
        tax_rate_on_receiving = tax_rate,
25
        tax_value_on_ordering = ?,
26
        tax_value_on_receiving = ?
27
    WHERE ordernumber = ?
28
|);
29
30
require Koha::Number::Price;
31
for my $order (@$orders) {
32
    my $tax_value_on_ordering =
33
      $order->{quantity} *
34
      $order->{ecost_tax_excluded} *
35
      $order->{tax_rate};
36
37
    my $tax_value_on_receiving =
38
      ( defined $order->{unitprice_tax_excluded} )
39
      ? $order->{quantity} * $order->{unitprice_tax_excluded} * $order->{tax_rate}
40
      : undef;
41
42
    $sth_update_order->execute( $tax_value_on_ordering,
43
        $tax_value_on_receiving, $order->{ordernumber} );
44
}
45
46
# Remove the old columns
47
$dbh->do(q|
48
    ALTER TABLE aqorders
49
        CHANGE COLUMN tax_value tax_value_bak  decimal(28,6) default NULL,
50
        CHANGE COLUMN tax_rate tax_rate_bak decimal(6,4) default NULL
51
|);
(-)a/installer/data/mysql/kohastructure.sql (-3 / +6 lines)
Lines 3102-3109 CREATE TABLE `aqorders` ( -- information related to the basket line items Link Here
3102
  `ecost` decimal(13,2) DEFAULT NULL, -- the replacement cost for this line item
3102
  `ecost` decimal(13,2) DEFAULT NULL, -- the replacement cost for this line item
3103
  `ecost_tax_excluded` decimal(28,6) default NULL, -- the estimated cost excluding tax
3103
  `ecost_tax_excluded` decimal(28,6) default NULL, -- the estimated cost excluding tax
3104
  `ecost_tax_included` decimal(28,6) default NULL, -- the estimated cost including tax
3104
  `ecost_tax_included` decimal(28,6) default NULL, -- the estimated cost including tax
3105
  `tax_rate` decimal(6,4) DEFAULT NULL, -- the tax rate for this line item (%)
3105
  `tax_rate_bak` decimal(6,4) DEFAULT NULL, -- the tax rate for this line item (%)
3106
  `tax_value` decimal(28,6) default NULL, -- the tax value for this line item
3106
  `tax_rate_on_ordering` decimal(6,4) DEFAULT NULL, -- the tax rate on ordering for this line item (%)
3107
  `tax_rate_on_receiving` decimal(6,4) DEFAULT NULL, -- the tax rate on receiving for this line item (%)
3108
  `tax_value_bak` decimal(28,6) default NULL, -- the tax value for this line item
3109
  `tax_value_on_ordering` decimal(28,6) DEFAULT NULL, -- the tax value on ordering for this line item
3110
  `tax_value_on_receiving` decimal(28,6) DEFAULT NULL, -- the tax value on receiving for this line item
3107
  `discount` float(6,4) default NULL, -- the discount for this line item (%)
3111
  `discount` float(6,4) default NULL, -- the discount for this line item (%)
3108
  `budget_id` int(11) NOT NULL, -- the fund this order goes against (aqbudgets.budget_id)
3112
  `budget_id` int(11) NOT NULL, -- the fund this order goes against (aqbudgets.budget_id)
3109
  `budgetgroup_id` int(11) NOT NULL, -- not used? always zero
3113
  `budgetgroup_id` int(11) NOT NULL, -- not used? always zero
3110
- 

Return to bug 13323