5 use Test::More tests => 44;
8 use Koha::Acquisition::Bookseller;
9 use Koha::Acquisition::Order;
10 use t::lib::TestBuilder;
14 my $schema = Koha::Database->new()->schema();
15 $schema->storage->txn_begin();
17 my $builder = t::lib::TestBuilder->new;
19 my $bookseller_inc_tax = Koha::Acquisition::Bookseller->new(
21 name => "Tax included",
22 address1 => "bookseller's address",
30 my $bookseller_exc_tax = Koha::Acquisition::Bookseller->new(
32 name => "Tax excluded",
33 address1 => "bookseller's address",
41 my $basket_exc_tax = Koha::Acquisition::Basket->new(
43 basketname => 'Basket tax excluded',
44 booksellerid => $bookseller_exc_tax->id,
48 my $order_exc_tax = Koha::Acquisition::Order->new({
49 tax_rate_on_ordering => .1965,
50 tax_rate_on_receiving => .1965,
55 basketno => $basket_exc_tax->basketno,
58 #Vendor prices exclude tax, no rounding, ordering
59 t::lib::Mocks::mock_preference('OrderPriceRounding', '');
60 $order_exc_tax->populate_with_prices_for_ordering();
62 is( $order_exc_tax->rrp_tax_excluded+0 ,16.99 ,"Ordering tax excluded, no round: rrp tax excluded is rrp");
63 is( $order_exc_tax->rrp_tax_included+0 ,20.328535 ,"Ordering tax excluded, no round: rrp tax included is rr tax excluded * (1 + tax rate on ordering)");
64 is( $order_exc_tax->ecost_tax_excluded+0 ,9.8542 ,"Ordering tax excluded, no round: ecost tax excluded is rrp * ( 1 - discount )");
65 is( $order_exc_tax->ecost_tax_included+0 ,11.7905503 ,"Ordering tax excluded, no round: ecost tax included is ecost tax excluded * (1 + tax rate on ordering)");
66 is( $order_exc_tax->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");
68 $order_exc_tax->unitprice(9.85);
70 $order_exc_tax->populate_with_prices_for_ordering();
72 is( $order_exc_tax->unitprice_tax_excluded+0 ,9.85 ,"Ordering tax excluded, no round: rrp tax excluded is rrp");
73 is( $order_exc_tax->unitprice_tax_included+0 ,11.785525 ,"Ordering tax excluded, no round: rrp tax included is rr tax excluded * (1 + tax rate on ordering)");
74 is( $order_exc_tax->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");
76 #Vendor prices exclude tax, no rounding, receiving
77 $order_exc_tax->populate_with_prices_for_receiving();
79 is( $order_exc_tax->unitprice+0 ,9.8542 ,"Receiving tax excluded, no round, rounded ecost tax excluded = rounded unitprice : unitprice is ecost tax excluded");
80 is( $order_exc_tax->unitprice_tax_excluded+0 ,9.8542 ,"Receiving tax excluded, no round, rounded ecost tax excluded = rounded unitprice : unitprice tax excluded is ecost tax excluded");
81 is( $order_exc_tax->unitprice_tax_included+0 ,11.7905503 ,"Receiving tax excluded, no round: unitprice tax included is unitprice tax excluded * (1 + tax rate on ordering)");
82 is( $order_exc_tax->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");
85 $order_exc_tax->unitprice(9.85);
86 #populate order with prices updates the passed in order hashref
87 #we need to reset after additional tests and changes
89 #Vendor prices exclude tax, rounding to nearest cent, ordering
90 t::lib::Mocks::mock_preference('OrderPriceRounding', 'nearest_cent');
91 $order_exc_tax->populate_with_prices_for_ordering();
93 is( $order_exc_tax->unitprice_tax_excluded+0 ,9.85 ,"Ordering tax excluded, round: unitprice tax excluded is unitprice");
94 is( $order_exc_tax->unitprice_tax_included+0 ,11.785525 ,"Ordering tax excluded, round: unitprice tax included is unitprice tax excluded * (1 + tax rate on ordering)");
95 is( $order_exc_tax->rrp_tax_excluded+0 ,16.99 ,"Ordering tax excluded, round: rrp tax excluded is rrp");
96 is( $order_exc_tax->rrp_tax_included+0 ,20.328535 ,"Ordering tax excluded, round: rrp tax included is rr tax excluded * (1 + tax rate on ordering)");
97 is( $order_exc_tax->ecost_tax_excluded+0 ,9.8542 ,"Ordering tax excluded, round: ecost tax excluded is rrp * ( 1 - discount )");
98 is( $order_exc_tax->ecost_tax_included+0 ,11.7905503 ,"Ordering tax excluded, round: ecost tax included is ecost tax excluded * (1 + tax rate on ordering)");
99 is( $order_exc_tax->tax_value_on_ordering+0 ,15.4842 ,"Ordering tax excluded, round: tax value on ordering is quantity * ecost_tax_excluded * tax rate on ordering");
101 #Vendor prices exclude tax, no rounding, receiving
102 $order_exc_tax->populate_with_prices_for_receiving();
104 is( $order_exc_tax->unitprice_tax_excluded+0 ,9.8542 ,"Receiving tax excluded, round, rounded ecost tax excluded = rounded unitprice : unitprice tax excluded is ecost tax excluded");
105 is( $order_exc_tax->unitprice_tax_included+0 ,11.7905503 ,"Receiving tax excluded, round: unitprice tax included is unitprice tax excluded * (1 + tax rate on ordering)");
106 is( $order_exc_tax->tax_value_on_receiving+0 ,15.4842 ,"Receiving tax excluded, round: tax value on receiving is quantity * unitprice_tax_excluded * tax rate on receiving");
109 my $basket_inc_tax = Koha::Acquisition::Basket->new(
111 basketname => 'Basket tax included',
112 booksellerid => $bookseller_inc_tax->id,
116 my $order_inc_tax = Koha::Acquisition::Order->new({
117 tax_rate_on_ordering => .1965,
118 tax_rate_on_receiving => .1965,
123 basketno => $basket_inc_tax->basketno,
126 #Vendor prices include tax, no rounding, ordering
127 t::lib::Mocks::mock_preference('OrderPriceRounding', '');
128 $order_inc_tax->populate_with_prices_for_ordering();
130 is( $order_inc_tax->rrp_tax_included+0 ,20.33 ,"Ordering tax included, no round: rrp tax included is rrp");
131 is( $order_inc_tax->rrp_tax_excluded+0 ,16.9912244045132 ,"Ordering tax included, no round: rrp tax excluded is rrp tax included / (1 + tax rate on ordering)");
132 is( $order_inc_tax->ecost_tax_included+0 ,11.7914 ,"Ordering tax included, no round: ecost tax included is rrp tax included * (1 - discount)");
133 is( $order_inc_tax->ecost_tax_excluded+0 ,9.85491015461764 ,"Ordering tax included, no round: ecost tax excluded is rrp tax excluded * ( 1 - discount )");
134 is( $order_inc_tax->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");
136 $order_inc_tax->unitprice(11.79);
137 $order_inc_tax->populate_with_prices_for_ordering();
139 is( $order_inc_tax->unitprice_tax_included+0 ,11.79 ,"Ordering tax included, no round: unitprice tax included is unitprice");
140 is( $order_inc_tax->unitprice_tax_excluded+0 ,9.85374007521939 ,"Ordering tax included, no round: unitprice tax excluded is unitprice tax included / (1 + tax_rate_on_ordering ");
141 is( $order_inc_tax->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");
143 #Vendor prices include tax, no rounding, receiving
144 $order_inc_tax->populate_with_prices_for_receiving();
146 is( $order_inc_tax->unitprice+0 ,11.7914 ,"Receiving tax included, no round, rounded ecost tax excluded = rounded unitprice : unitprice is ecost tax excluded");
147 is( $order_inc_tax->unitprice_tax_included+0 ,11.7914 ,"Receiving tax included, no round: unitprice tax included is unitprice");
148 is( $order_inc_tax->unitprice_tax_excluded+0 ,9.85491015461764 ,"Receiving tax included, no round: unitprice tax excluded is unitprice tax included / (1 + tax rate on receiving)");
149 is( $order_inc_tax->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");
151 #Vendor prices include tax, rounding to nearest cent, ordering
152 t::lib::Mocks::mock_preference('OrderPriceRounding', 'nearest_cent');
153 $order_inc_tax->unitprice(11.79);
154 $order_inc_tax->populate_with_prices_for_ordering();
156 is( $order_inc_tax->unitprice_tax_included+0 ,11.79 ,"Ordering tax included, round: unitprice tax included is unitprice");
157 is( $order_inc_tax->unitprice_tax_excluded+0,9.85374007521939 ,"Ordering tax included, round: unitprice tax excluded is unitprice tax included / (1 + tax_rate_on_ordering ");
158 is( $order_inc_tax->rrp_tax_included+0 ,20.33 ,"Ordering tax included, round: rrp tax included is rrp");
159 is( $order_inc_tax->rrp_tax_excluded+0 ,16.9912244045132 ,"Ordering tax included, round: rrp tax excluded is rounded rrp tax included * (1 + tax rate on ordering)");
160 is( $order_inc_tax->ecost_tax_included+0 ,11.7914 ,"Ordering tax included, round: ecost tax included is rounded rrp * ( 1 - discount )");
161 is( $order_inc_tax->ecost_tax_excluded+0 ,9.85491015461764 ,"Ordering tax included, round: ecost tax excluded is rounded ecost tax excluded * (1 - discount)");
162 is( $order_inc_tax->tax_value_on_ordering+0 ,15.52 ,"Ordering tax included, round: tax value on ordering is (ecost_tax_included - ecost_tax_excluded) * quantity");
164 #Vendor prices include tax, no rounding, receiving
165 $order_inc_tax->populate_with_prices_for_receiving();
167 is( $order_inc_tax->unitprice_tax_included+0 ,11.7914 ,"Receiving tax included, round: rounded ecost tax included = rounded unitprice : unitprice tax excluded is ecost tax included");
168 is( $order_inc_tax->unitprice_tax_excluded+0 ,9.85491015461764 ,"Receiving tax included, round: unitprice tax excluded is unitprice tax included / (1 + tax rate on ordering)");
169 is( $order_inc_tax->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");
172 $schema->storage->txn_rollback();