Lines 98-183
elsif ( $op && $op eq 'delete' ) {
Link Here
|
98 |
} |
98 |
} |
99 |
} |
99 |
} |
100 |
|
100 |
|
101 |
my $details = GetInvoiceDetails($invoiceid); |
101 |
|
102 |
my $bookseller = GetBookSellerFromId( $details->{booksellerid} ); |
102 |
my $details = GetInvoiceDetails($invoiceid); |
|
|
103 |
my ($bookseller) = GetBookSellerFromId($details->{supplierid}); |
103 |
my @orders_loop = (); |
104 |
my @orders_loop = (); |
104 |
my $orders = $details->{'orders'}; |
105 |
my $orders = $details->{'orders'}; |
105 |
my $qty_total; |
106 |
my $qty_total; |
106 |
my @books_loop; |
107 |
my @foot_loop; |
107 |
my @book_foot_loop; |
|
|
108 |
my %foot; |
108 |
my %foot; |
109 |
my $total_quantity = 0; |
109 |
my $total_quantity = 0; |
110 |
my $total_rrp = 0; |
110 |
my $total_gste = 0; |
111 |
my $total_est = 0; |
111 |
my $total_gsti = 0; |
112 |
|
112 |
my $total_gstvalue = 0; |
113 |
foreach my $order (@$orders) { |
113 |
foreach my $order (@$orders) { |
114 |
my $line = get_infos( $order, $bookseller ); |
114 |
my $line = get_infos( $order, $bookseller); |
115 |
|
115 |
|
|
|
116 |
$foot{$$line{gstgsti}}{gstgsti} = $$line{gstgsti}; |
117 |
$foot{$$line{gstgsti}}{gstvalue} += $$line{gstvalue}; |
118 |
$total_gstvalue += $$line{gstvalue}; |
119 |
$foot{$$line{gstgsti}}{quantity} += $$line{quantity}; |
116 |
$total_quantity += $$line{quantity}; |
120 |
$total_quantity += $$line{quantity}; |
117 |
$total_rrp += $order->{quantity} * $order->{rrp}; |
121 |
$foot{$$line{gstgsti}}{totalgste} += $$line{totalgste}; |
118 |
$total_est += $order->{quantity} * $order->{'ecost'}; |
122 |
$total_gste += $$line{totalgste}; |
|
|
123 |
$foot{$$line{gstgsti}}{totalgsti} += $$line{totalgsti}; |
124 |
$total_gsti += $$line{totalgsti}; |
119 |
|
125 |
|
120 |
my %row = ( %$order, %$line ); |
126 |
my %row = %{ $order, $line }; |
|
|
127 |
$row{'orderline'} = $row{'parent_ordernumber'}; |
121 |
push @orders_loop, \%row; |
128 |
push @orders_loop, \%row; |
122 |
} |
129 |
} |
123 |
|
130 |
|
124 |
my $gist = $bookseller->{gstrate} // C4::Context->preference("gist") // 0; |
131 |
push @foot_loop, map {$_} values %foot; |
125 |
my $discount = |
|
|
126 |
$bookseller->{'discount'} ? ( $bookseller->{discount} / 100 ) : 0; |
127 |
my $total_est_gste; |
128 |
my $total_est_gsti; |
129 |
my $total_rrp_gsti; # RRP Total, GST included |
130 |
my $total_rrp_gste; # RRP Total, GST excluded |
131 |
my $gist_est; |
132 |
my $gist_rrp; |
133 |
if ($gist) { |
134 |
|
135 |
# if we have GST |
136 |
if ( $bookseller->{'listincgst'} ) { |
137 |
|
138 |
# if prices already includes GST |
139 |
|
140 |
# we know $total_rrp_gsti |
141 |
$total_rrp_gsti = $total_rrp; |
142 |
|
143 |
# and can reverse compute other values |
144 |
$total_rrp_gste = $total_rrp_gsti / ( $gist + 1 ); |
145 |
|
146 |
$gist_rrp = $total_rrp_gsti - $total_rrp_gste; |
147 |
$total_est_gste = $total_rrp_gste - ( $total_rrp_gste * $discount ); |
148 |
$total_est_gsti = $total_est; |
149 |
} |
150 |
else { |
151 |
# if prices does not include GST |
152 |
|
153 |
# then we use the common way to compute other values |
154 |
$total_rrp_gste = $total_rrp; |
155 |
$gist_rrp = $total_rrp_gste * $gist; |
156 |
$total_rrp_gsti = $total_rrp_gste + $gist_rrp; |
157 |
$total_est_gste = $total_est; |
158 |
$total_est_gsti = $total_rrp_gsti - ( $total_rrp_gsti * $discount ); |
159 |
} |
160 |
$gist_est = $gist_rrp - ( $gist_rrp * $discount ); |
161 |
} |
162 |
else { |
163 |
$total_rrp_gste = $total_rrp_gsti = $total_rrp; |
164 |
$total_est_gste = $total_est_gsti = $total_est; |
165 |
$gist_rrp = $gist_est = 0; |
166 |
} |
167 |
my $total_gsti_shipment = $total_est_gsti + $details->{shipmentcost}; |
168 |
|
132 |
|
169 |
my $format = "%.2f"; |
133 |
my $format = "%.2f"; |
170 |
$template->param( |
|
|
171 |
total_rrp_gste => sprintf( $format, $total_rrp_gste ), |
172 |
total_rrp_gsti => sprintf( $format, $total_rrp_gsti ), |
173 |
total_est_gste => sprintf( $format, $total_est_gste ), |
174 |
total_est_gsti => sprintf( $format, $total_est_gsti ), |
175 |
gist_rrp => sprintf( $format, $gist_rrp ), |
176 |
gist_est => sprintf( $format, $gist_est ), |
177 |
total_gsti_shipment => sprintf( $format, $total_gsti_shipment ), |
178 |
gist => sprintf( $format, $gist * 100 ), |
179 |
); |
180 |
|
181 |
my $budgets = GetBudgets(); |
134 |
my $budgets = GetBudgets(); |
182 |
my @budgets_loop; |
135 |
my @budgets_loop; |
183 |
my $shipmentcost_budgetid = $details->{shipmentcost_budgetid}; |
136 |
my $shipmentcost_budgetid = $details->{shipmentcost_budgetid}; |
Lines 196-229
$template->param(
Link Here
|
196 |
invoiceid => $details->{'invoiceid'}, |
149 |
invoiceid => $details->{'invoiceid'}, |
197 |
invoicenumber => $details->{'invoicenumber'}, |
150 |
invoicenumber => $details->{'invoicenumber'}, |
198 |
suppliername => $details->{'suppliername'}, |
151 |
suppliername => $details->{'suppliername'}, |
199 |
booksellerid => $details->{'booksellerid'}, |
152 |
booksellerid => $details->{'booksellerid'}, |
200 |
datereceived => $details->{'datereceived'}, |
153 |
datereceived => $details->{'datereceived'}, |
201 |
shipmentdate => $details->{'shipmentdate'}, |
154 |
billingdate => C4::Dates->new($details->{'billingdate'}, "iso")->output(), |
202 |
billingdate => $details->{'billingdate'}, |
155 |
invoiceclosedate => $details->{'invoiceclosedate'}, |
203 |
invoiceclosedate => $details->{'closedate'}, |
156 |
shipmentcost => $details->{'shipmentcost'}, |
204 |
shipmentcost => sprintf( $format, $details->{'shipmentcost'} || 0 ), |
|
|
205 |
orders_loop => \@orders_loop, |
157 |
orders_loop => \@orders_loop, |
|
|
158 |
foot_loop => \@foot_loop, |
206 |
total_quantity => $total_quantity, |
159 |
total_quantity => $total_quantity, |
|
|
160 |
total_gste => sprintf( $format, $total_gste ), |
161 |
total_gsti => sprintf( $format, $total_gsti ), |
162 |
total_gstvalue => sprintf( $format, $total_gstvalue ), |
163 |
total_gste_shipment => sprintf( $format, $total_gste + $details->{shipmentcost}), |
164 |
total_gsti_shipment => sprintf( $format, $total_gsti + $details->{shipmentcost}), |
207 |
invoiceincgst => $bookseller->{invoiceincgst}, |
165 |
invoiceincgst => $bookseller->{invoiceincgst}, |
208 |
currency => $bookseller->{listprice}, |
166 |
currency => GetCurrency()->{currency}, |
209 |
budgets_loop => \@budgets_loop, |
167 |
budgets_loop => \@budgets_loop, |
210 |
); |
168 |
); |
211 |
|
169 |
|
|
|
170 |
# FIXME |
171 |
# Fonction dupplicated from basket.pl |
172 |
# Code must to be exported. Where ?? |
212 |
sub get_infos { |
173 |
sub get_infos { |
213 |
my $order = shift; |
174 |
my $order = shift; |
214 |
my $bookseller = shift; |
175 |
my $bookseller = shift; |
215 |
my $qty = $order->{'quantity'} || 0; |
176 |
my $qty = $order->{'quantity'} || 0; |
216 |
if ( !defined $order->{quantityreceived} ) { |
177 |
if ( !defined $order->{quantityreceived} ) { |
217 |
$order->{quantityreceived} = 0; |
178 |
$order->{quantityreceived} = 0; |
218 |
} |
179 |
} |
219 |
my $budget = GetBudget( $order->{'budget_id'} ); |
180 |
my $budget = GetBudget( $order->{'budget_id'} ); |
220 |
|
181 |
|
221 |
my %line = %{$order}; |
182 |
my %line = %{ $order }; |
222 |
$line{order_received} = ( $qty == $order->{'quantityreceived'} ); |
183 |
$line{order_received} = ( $qty == $order->{'quantityreceived'} ); |
223 |
$line{budget_name} = $budget->{budget_name}; |
184 |
$line{budget_name} = $budget->{budget_name}; |
224 |
$line{total} = $qty * $order->{ecost}; |
185 |
if ( $bookseller->{'listincgst'} ) { |
|
|
186 |
$line{gstgsti} = sprintf( "%.2f", $line{gstrate} * 100 ); |
187 |
$line{gstgste} = sprintf( "%.2f", $line{gstgsti} / ( 1 + ( $line{gstgsti} / 100 ) ) ); |
188 |
$line{actualcostgsti} = sprintf( "%.2f", $line{unitprice} ); |
189 |
$line{actualcostgste} = sprintf( "%.2f", $line{unitprice} / ( 1 + ( $line{gstgsti} / 100 ) ) ); |
190 |
$line{gstvalue} = sprintf( "%.2f", ( $line{actualcostgsti} - $line{actualcostgste} ) * $line{quantity}); |
191 |
$line{totalgste} = sprintf( "%.2f", $order->{quantity} * $line{actualcostgste} ); |
192 |
$line{totalgsti} = sprintf( "%.2f", $order->{quantity} * $line{actualcostgsti} ); |
193 |
} else { |
194 |
$line{gstgsti} = sprintf( "%.2f", $line{gstrate} * 100 ); |
195 |
$line{gstgste} = sprintf( "%.2f", $line{gstrate} * 100 ); |
196 |
$line{actualcostgsti} = sprintf( "%.2f", $line{unitprice} * ( 1 + ( $line{gstrate} ) ) ); |
197 |
$line{actualcostgste} = sprintf( "%.2f", $line{unitprice} ); |
198 |
$line{gstvalue} = sprintf( "%.2f", ( $line{actualcostgsti} - $line{actualcostgste} ) * $line{quantity}); |
199 |
$line{totalgste} = sprintf( "%.2f", $order->{quantity} * $line{actualcostgste} ); |
200 |
$line{totalgsti} = sprintf( "%.2f", $order->{quantity} * $line{actualcostgsti} ); |
201 |
} |
225 |
|
202 |
|
226 |
if ( $line{uncertainprice} ) { |
203 |
if ( $line{uncertainprice} ) { |
|
|
204 |
$template->param( uncertainprices => 1 ); |
227 |
$line{rrp} .= ' (Uncertain)'; |
205 |
$line{rrp} .= ' (Uncertain)'; |
228 |
} |
206 |
} |
229 |
if ( $line{'title'} ) { |
207 |
if ( $line{'title'} ) { |
Lines 231-238
sub get_infos {
Link Here
|
231 |
my $seriestitle = $order->{'seriestitle'}; |
209 |
my $seriestitle = $order->{'seriestitle'}; |
232 |
$line{'title'} .= " / $seriestitle" if $seriestitle; |
210 |
$line{'title'} .= " / $seriestitle" if $seriestitle; |
233 |
$line{'title'} .= " / $volume" if $volume; |
211 |
$line{'title'} .= " / $volume" if $volume; |
234 |
} |
212 |
} else { |
235 |
else { |
|
|
236 |
$line{'title'} = "Deleted bibliographic notice, can't find title."; |
213 |
$line{'title'} = "Deleted bibliographic notice, can't find title."; |
237 |
} |
214 |
} |
238 |
|
215 |
|