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