5 use Test
::More tests
=> 44;
9 use t
::lib
::TestBuilder
;
13 my $schema = Koha
::Database
->new()->schema();
14 $schema->storage->txn_begin();
16 my $builder = t
::lib
::TestBuilder
->new;
18 my $bookseller_inc_tax = Koha
::Acquisition
::Bookseller
->new(
20 name
=> "Tax included",
21 address1
=> "bookseller's address",
29 my $bookseller_exc_tax = Koha
::Acquisition
::Bookseller
->new(
31 name
=> "Tax excluded",
32 address1
=> "bookseller's address",
48 #Vendor prices exclude tax, no rounding, ordering
49 t
::lib
::Mocks
::mock_preference
('OrderPriceRounding', '');
50 my $order_with_prices = C4
::Acquisition
::populate_order_with_prices
({
52 booksellerid
=> $bookseller_exc_tax->id,
53 order
=> $order_exc_tax,
56 is
( $order_with_prices->{rrp_tax_excluded
}+0 ,16.99 ,"Ordering tax excluded, no round: rrp tax excluded is rrp");
57 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)");
58 is
( $order_with_prices->{ecost_tax_excluded
}+0 ,9.8542 ,"Ordering tax excluded, no round: ecost tax excluded is rrp * ( 1 - discount )");
59 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)");
60 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 if no unitprice");
62 $order_exc_tax->{unitprice
} = 9.85;
64 $order_with_prices = C4
::Acquisition
::populate_order_with_prices
({
66 booksellerid
=> $bookseller_exc_tax->id,
67 order
=> $order_exc_tax,
70 is
( $order_with_prices->{unitprice_tax_excluded
}+0 ,9.85 ,"Ordering tax excluded, no round: rrp tax excluded is rrp");
71 is
( $order_with_prices->{unitprice_tax_included
}+0 ,11.785525 ,"Ordering tax excluded, no round: rrp tax included is rr tax excluded * (1 + tax rate on ordering)");
72 is
( $order_with_prices->{tax_value_on_ordering
}+0 ,15.4842 ,"Ordering tax excluded, no round: tax value on ordering is quantity * unitprice_tax_excluded * tax rate on ordering if unitprice");
74 #Vendor prices exclude tax, no rounding, receiving
75 $order_with_prices = C4
::Acquisition
::populate_order_with_prices
({
77 booksellerid
=> $bookseller_exc_tax->id,
78 order
=> $order_exc_tax,
81 is
( $order_with_prices->{unitprice
}+0 ,9.8542 ,"Receiving tax excluded, no round, rounded ecost tax excluded = rounded unitprice : unitprice is ecost tax excluded");
82 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");
83 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)");
84 is
( $order_with_prices->{tax_value_on_receiving
}+0 ,15.4908024 ,"Receiving tax excluded, no round: tax value on receiving is quantity * unitprice_tax_excluded * tax rate on receiving");
87 $order_exc_tax->{unitprice
} = 9.85;
88 #populate order with prices updates the passed in order hashref
89 #we need to reset after additional tests and changes
91 #Vendor prices exclude tax, rounding to nearest cent, ordering
92 t
::lib
::Mocks
::mock_preference
('OrderPriceRounding', 'nearest_cent');
93 $order_with_prices = C4
::Acquisition
::populate_order_with_prices
({
95 booksellerid
=> $bookseller_exc_tax->id,
96 order
=> $order_exc_tax,
99 is
( $order_with_prices->{unitprice_tax_excluded
}+0 ,9.85 ,"Ordering tax excluded, round: unitprice tax excluded is unitprice");
100 is
( $order_with_prices->{unitprice_tax_included
}+0 ,11.785525 ,"Ordering tax excluded, round: unitprice tax included is unitprice tax excluded * (1 + tax rate on ordering)");
101 is
( $order_with_prices->{rrp_tax_excluded
}+0 ,16.99 ,"Ordering tax excluded, round: rrp tax excluded is rrp");
102 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)");
103 is
( $order_with_prices->{ecost_tax_excluded
}+0 ,9.8542 ,"Ordering tax excluded, round: ecost tax excluded is rrp * ( 1 - discount )");
104 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)");
105 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");
107 #Vendor prices exclude tax, no rounding, receiving
108 $order_with_prices = C4
::Acquisition
::populate_order_with_prices
({
110 booksellerid
=> $bookseller_exc_tax->id,
111 order
=> $order_exc_tax,
114 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");
115 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)");
116 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");
120 my $order_inc_tax = {
128 #Vendor prices include tax, no rounding, ordering
129 t
::lib
::Mocks
::mock_preference
('OrderPriceRounding', '');
130 $order_with_prices = C4
::Acquisition
::populate_order_with_prices
({
132 booksellerid
=> $bookseller_inc_tax->id,
133 order
=> $order_inc_tax,
136 is
( $order_with_prices->{rrp_tax_included
}+0 ,20.33 ,"Ordering tax included, no round: rrp tax included is rrp");
137 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)");
138 is
( $order_with_prices->{ecost_tax_included
}+0 ,11.7914 ,"Ordering tax included, no round: ecost tax included is rrp tax included * (1 - discount)");
139 is
( $order_with_prices->{ecost_tax_excluded
}+0 ,9.85491015461764 ,"Ordering tax included, no round: ecost tax excluded is rrp tax excluded * ( 1 - discount )");
140 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 if no unitprice");
142 $order_inc_tax->{unitprice
} = 11.79;
143 $order_with_prices = C4
::Acquisition
::populate_order_with_prices
({
145 booksellerid
=> $bookseller_inc_tax->id,
146 order
=> $order_inc_tax,
149 is
( $order_with_prices->{unitprice_tax_included
}+0 ,11.79 ,"Ordering tax included, no round: unitprice tax included is unitprice");
150 is
( $order_with_prices->{unitprice_tax_excluded
}+0 ,9.85374007521939 ,"Ordering tax included, no round: unitprice tax excluded is unitprice tax included / (1 + tax_rate_on_ordering ");
151 is
( $order_with_prices->{tax_value_on_ordering
}+0 ,15.4900793982449 ,"Ordering tax included, no round: tax value on ordering is ( unitprice tax included - unitprice tax excluded ) * quantity if unitprice");
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
}+0 ,11.7914 ,"Receiving tax included, no round, rounded ecost tax excluded = rounded unitprice : unitprice is ecost tax excluded");
161 is
( $order_with_prices->{unitprice_tax_included
}+0 ,11.7914 ,"Receiving tax included, no round: unitprice tax included is unitprice");
162 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)");
163 is
( $order_with_prices->{tax_value_on_receiving
}+0 ,15.4919187630589 ,"Receiving tax included, no round: tax value on receiving is quantity * unitprice_tax_excluded * tax rate on receiving");
165 #Vendor prices include tax, rounding to nearest cent, ordering
166 t
::lib
::Mocks
::mock_preference
('OrderPriceRounding', 'nearest_cent');
167 $order_inc_tax->{unitprice
} = 11.79;
168 $order_with_prices = C4
::Acquisition
::populate_order_with_prices
({
170 booksellerid
=> $bookseller_inc_tax->id,
171 order
=> $order_inc_tax,
174 is
( $order_with_prices->{unitprice_tax_included
}+0 ,11.79 ,"Ordering tax included, round: unitprice tax included is unitprice");
175 is
( $order_with_prices->{unitprice_tax_excluded
}+0,9.85374007521939 ,"Ordering tax included, round: unitprice tax excluded is unitprice tax included / (1 + tax_rate_on_ordering ");
176 is
( $order_with_prices->{rrp_tax_included
}+0 ,20.33 ,"Ordering tax included, round: rrp tax included is rrp");
177 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)");
178 is
( $order_with_prices->{ecost_tax_included
}+0 ,11.7914 ,"Ordering tax included, round: ecost tax included is rounded rrp * ( 1 - discount )");
179 is
( $order_with_prices->{ecost_tax_excluded
}+0 ,9.85491015461764 ,"Ordering tax included, round: ecost tax excluded is rounded ecost tax excluded * (1 - discount)");
180 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");
182 #Vendor prices include tax, no rounding, receiving
183 $order_with_prices = C4
::Acquisition
::populate_order_with_prices
({
185 booksellerid
=> $bookseller_inc_tax->id,
186 order
=> $order_inc_tax,
189 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");
190 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)");
191 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");
194 $schema->storage->txn_rollback();