5 use Test
::More tests
=> 34;
9 use t
::lib
::TestBuilder
;
13 my $schema = Koha
::Database
->new()->schema();
14 $schema->storage->txn_begin();
16 my $dbh = C4
::Context
->dbh;
17 $dbh->{RaiseError
} = 1;
19 my $builder = t
::lib
::TestBuilder
->new;
21 my $bookseller_inc_tax = Koha
::Acquisition
::Bookseller
->new(
23 name
=> "Tax included",
24 address1
=> "bookseller's address",
32 my $bookseller_exc_tax = Koha
::Acquisition
::Bookseller
->new(
34 name
=> "Tax excluded",
35 address1
=> "bookseller's address",
51 #Vendor prices exclude tax, no rounding, ordering
52 t
::lib
::Mocks
::mock_preference
('OrderPriceRounding', '');
53 my $order_with_prices = C4
::Acquisition
::populate_order_with_prices
({
55 booksellerid
=> $bookseller_exc_tax->id,
56 order
=> $order_exc_tax,
59 is
( $order_with_prices->{rrp_tax_excluded
}+0 ,16.99 ,"Ordering tax excluded, no round: rrp tax excluded is rrp");
60 is
( $order_with_prices->{rrp_tax_included
}+0 ,20.328535 ,"Ordering tax excluded, no round: rrp tax included is rr tax excluded * (1 + tax rate on ordering)");
61 is
( $order_with_prices->{ecost_tax_excluded
}+0 ,9.8542 ,"Ordering tax excluded, no round: ecost tax excluded is rrp * ( 1 - discount )");
62 is
( $order_with_prices->{ecost_tax_included
}+0 ,11.7905503 ,"Ordering tax excluded, no round: ecost tax included is ecost tax excluded * (1 + tax rate on ordering)");
63 is
( $order_with_prices->{tax_value_on_ordering
}+0 ,15.4908024 ,"Ordering tax excluded, no round: tax value on ordering is quantity * ecost_tax_excluded * tax rate on ordering");
65 #Vendor prices exclude tax, no rounding, receiving
66 $order_with_prices = C4
::Acquisition
::populate_order_with_prices
({
68 booksellerid
=> $bookseller_exc_tax->id,
69 order
=> $order_exc_tax,
72 is
( $order_with_prices->{unitprice
}+0 ,9.8542 ,"Receiving tax excluded, no round, rounded ecost tax excluded = rounded unitprice : unitprice is ecost tax excluded");
73 is
( $order_with_prices->{unitprice_tax_excluded
}+0 ,9.8542 ,"Receiving tax excluded, no round, rounded ecost tax excluded = rounded unitprice : unitprice tax excluded is ecost tax excluded");
74 is
( $order_with_prices->{unitprice_tax_included
}+0 ,11.7905503 ,"Receiving tax excluded, no round: unitprice tax included is unitprice tax excluded * (1 + tax rate on ordering)");
75 is
( $order_with_prices->{tax_value_on_ordering
}+0 ,15.4908024 ,"Receiving tax excluded, no round: tax value on receiving is quantity * unitprice_tax_excluded * tax rate on receiving");
77 #Vendor prices exclude tax, rounding to nearest cent, ordering
78 t
::lib
::Mocks
::mock_preference
('OrderPriceRounding', 'nearest_cent');
79 $order_with_prices = C4
::Acquisition
::populate_order_with_prices
({
81 booksellerid
=> $bookseller_exc_tax->id,
82 order
=> $order_exc_tax,
85 is
( $order_with_prices->{rrp_tax_excluded
}+0 ,16.99 ,"Ordering tax excluded, round: rrp tax excluded is rrp");
86 is
( $order_with_prices->{rrp_tax_included
}+0 ,20.328535 ,"Ordering tax excluded, round: rrp tax included is rr tax excluded * (1 + tax rate on ordering)");
87 is
( $order_with_prices->{ecost_tax_excluded
}+0 ,9.8542 ,"Ordering tax excluded, round: ecost tax excluded is rrp * ( 1 - discount )");
88 is
( $order_with_prices->{ecost_tax_included
}+0 ,11.7905503 ,"Ordering tax excluded, round: ecost tax included is ecost tax excluded * (1 + tax rate on ordering)");
89 is
( $order_with_prices->{tax_value_on_ordering
}+0 ,15.4842 ,"Ordering tax excluded, round: tax value on ordering is quantity * ecost_tax_excluded * tax rate on ordering");
91 #Vendor prices exclude tax, no rounding, receiving
92 $order_with_prices = C4
::Acquisition
::populate_order_with_prices
({
94 booksellerid
=> $bookseller_exc_tax->id,
95 order
=> $order_exc_tax,
98 is
( $order_with_prices->{unitprice_tax_excluded
}+0 ,9.8542 ,"Receiving tax excluded, round, rounded ecost tax excluded = rounded unitprice : unitprice tax excluded is ecost tax excluded");
99 is
( $order_with_prices->{unitprice_tax_included
}+0 ,11.7905503 ,"Receiving tax excluded, round: unitprice tax included is unitprice tax excluded * (1 + tax rate on ordering)");
100 is
( $order_with_prices->{tax_value_on_receiving
}+0 ,15.4842 ,"Receiving tax excluded, round: tax value on receiving is quantity * unitprice_tax_excluded * tax rate on receiving");
104 my $order_inc_tax = {
112 #Vendor prices include tax, no rounding, ordering
113 t
::lib
::Mocks
::mock_preference
('OrderPriceRounding', '');
114 $order_with_prices = C4
::Acquisition
::populate_order_with_prices
({
116 booksellerid
=> $bookseller_inc_tax->id,
117 order
=> $order_inc_tax,
120 is
( $order_with_prices->{rrp_tax_included
}+0 ,20.33 ,"Ordering tax included, no round: rrp tax included is rrp");
121 is
( $order_with_prices->{rrp_tax_excluded
}+0 ,16.9912244045132 ,"Ordering tax included, no round: rrp tax excluded is rrp tax included / (1 + tax rate on ordering)");
122 is
( $order_with_prices->{ecost_tax_included
}+0 ,11.7914 ,"Ordering tax included, no round: ecost tax included is rrp tax included * (1 - discount)");
123 is
( $order_with_prices->{ecost_tax_excluded
}+0 ,9.85491015461764 ,"Ordering tax included, no round: ecost tax excluded is rrp tax excluded * ( 1 - discount )");
124 is
( $order_with_prices->{tax_value_on_ordering
}+0 ,15.4919187630589 ,"Ordering tax included, no round: tax value on ordering is ( ecost tax included - ecost tax excluded ) * quantity");
127 #Vendor prices include tax, no rounding, receiving
128 $order_with_prices = C4
::Acquisition
::populate_order_with_prices
({
130 booksellerid
=> $bookseller_inc_tax->id,
131 order
=> $order_inc_tax,
134 is
( $order_with_prices->{unitprice
}+0 ,11.7914 ,"Receiving tax included, no round, rounded ecost tax excluded = rounded unitprice : unitprice is ecost tax excluded");
135 is
( $order_with_prices->{unitprice_tax_included
}+0 ,11.7914 ,"Receiving tax included, no round: unitprice tax included is unitprice");
136 is
( $order_with_prices->{unitprice_tax_excluded
}+0 ,9.85491015461764 ,"Receiving tax included, no round: unitprice tax excluded is unitprice tax included / (1 + tax rate on receiving)");
137 is
( $order_with_prices->{tax_value_on_ordering
}+0 ,15.4919187630589 ,"Receiving tax included, no round: tax value on receiving is quantity * unitprice_tax_excluded * tax rate on receiving");
139 #Vendor prices include tax, rounding to nearest cent, ordering
140 t
::lib
::Mocks
::mock_preference
('OrderPriceRounding', 'nearest_cent');
141 $order_with_prices = C4
::Acquisition
::populate_order_with_prices
({
143 booksellerid
=> $bookseller_inc_tax->id,
144 order
=> $order_inc_tax,
147 is
( $order_with_prices->{rrp_tax_included
}+0 ,20.33 ,"Ordering tax included, round: rrp tax included is rrp");
148 is
( $order_with_prices->{rrp_tax_excluded
}+0 ,16.9912244045132 ,"Ordering tax included, round: rrp tax excluded is rounded rrp tax included * (1 + tax rate on ordering)");
149 is
( $order_with_prices->{ecost_tax_included
}+0 ,11.7914 ,"Ordering tax included, round: ecost tax included is rounded rrp * ( 1 - discount )");
150 is
( $order_with_prices->{ecost_tax_excluded
}+0 ,9.85491015461764 ,"Ordering tax included, round: ecost tax excluded is rounded ecost tax excluded * (1 - discount)");
151 is
( $order_with_prices->{tax_value_on_ordering
}+0 ,15.52 ,"Ordering tax included, round: tax value on ordering is (ecost_tax_included - ecost_tax_excluded) * quantity");
153 #Vendor prices include tax, no rounding, receiving
154 $order_with_prices = C4
::Acquisition
::populate_order_with_prices
({
156 booksellerid
=> $bookseller_inc_tax->id,
157 order
=> $order_inc_tax,
160 is
( $order_with_prices->{unitprice_tax_included
}+0 ,11.7914 ,"Receiving tax included, round: rounded ecost tax included = rounded unitprice : unitprice tax excluded is ecost tax included");
161 is
( $order_with_prices->{unitprice_tax_excluded
}+0 ,9.85491015461764 ,"Receiving tax included, round: unitprice tax excluded is unitprice tax included / (1 + tax rate on ordering)");
162 is
( $order_with_prices->{tax_value_on_receiving
}+0 ,15.4842 ,"Receiving tax included, round: tax value on receiving is quantity * (rounded unitprice_tax_excluded) * tax rate on receiving");
165 $schema->storage->txn_rollback();