Lines 37-127
use C4::Bookseller qw/GetBookSellerFromId/;
Link Here
|
37 |
use C4::Budgets; |
37 |
use C4::Budgets; |
38 |
|
38 |
|
39 |
my $input = new CGI; |
39 |
my $input = new CGI; |
40 |
my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( { |
40 |
my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( |
41 |
template_name => 'acqui/invoice.tmpl', |
41 |
{ |
42 |
query => $input, |
42 |
template_name => 'acqui/invoice.tmpl', |
43 |
type => 'intranet', |
43 |
query => $input, |
44 |
authnotrequired => 0, |
44 |
type => 'intranet', |
45 |
flagsrequired => { 'acquisition' => '*' }, |
45 |
authnotrequired => 0, |
46 |
debug => 1, |
46 |
flagsrequired => { 'acquisition' => '*' }, |
47 |
} ); |
47 |
debug => 1, |
|
|
48 |
} |
49 |
); |
48 |
|
50 |
|
49 |
my $invoiceid = $input->param('invoiceid'); |
51 |
my $invoiceid = $input->param('invoiceid'); |
50 |
my $op = $input->param('op'); |
52 |
my $op = $input->param('op'); |
51 |
|
53 |
|
52 |
if($op && $op eq 'close') { |
54 |
if ( $op && $op eq 'close' ) { |
53 |
CloseInvoice($invoiceid); |
55 |
CloseInvoice($invoiceid); |
54 |
my $referer = $input->param('referer'); |
56 |
my $referer = $input->param('referer'); |
55 |
if($referer) { |
57 |
if ($referer) { |
56 |
print $input->redirect($referer); |
58 |
print $input->redirect($referer); |
57 |
exit 0; |
59 |
exit 0; |
58 |
} |
60 |
} |
59 |
}elsif($op && $op eq 'reopen') { |
61 |
} |
|
|
62 |
elsif ( $op && $op eq 'reopen' ) { |
60 |
ReopenInvoice($invoiceid); |
63 |
ReopenInvoice($invoiceid); |
61 |
my $referer = $input->param('referer'); |
64 |
my $referer = $input->param('referer'); |
62 |
if($referer) { |
65 |
if ($referer) { |
63 |
print $input->redirect($referer); |
66 |
print $input->redirect($referer); |
64 |
exit 0; |
67 |
exit 0; |
65 |
} |
68 |
} |
66 |
}elsif($op && $op eq 'mod') { |
69 |
} |
67 |
my $shipmentdate = $input->param('shipmentdate'); |
70 |
elsif ( $op && $op eq 'mod' ) { |
68 |
my $billingdate = $input->param('billingdate'); |
71 |
my $shipmentdate = $input->param('shipmentdate'); |
69 |
my $shipmentcost = $input->param('shipmentcost'); |
72 |
my $billingdate = $input->param('billingdate'); |
|
|
73 |
my $shipmentcost = $input->param('shipmentcost'); |
70 |
my $shipment_budget_id = $input->param('shipment_budget_id'); |
74 |
my $shipment_budget_id = $input->param('shipment_budget_id'); |
71 |
ModInvoice( |
75 |
ModInvoice( |
72 |
invoiceid => $invoiceid, |
76 |
invoiceid => $invoiceid, |
73 |
shipmentdate => C4::Dates->new($shipmentdate)->output("iso"), |
77 |
shipmentdate => C4::Dates->new($shipmentdate)->output("iso"), |
74 |
billingdate => C4::Dates->new($billingdate)->output("iso"), |
78 |
billingdate => C4::Dates->new($billingdate)->output("iso"), |
75 |
shipmentcost => $shipmentcost, |
79 |
shipmentcost => $shipmentcost, |
76 |
shipmentcost_budgetid => $shipment_budget_id |
80 |
shipmentcost_budgetid => $shipment_budget_id |
77 |
); |
81 |
); |
78 |
$template->param(modified => 1); |
82 |
$template->param( modified => 1 ); |
79 |
} |
83 |
} |
80 |
|
84 |
|
81 |
my $details = GetInvoiceDetails($invoiceid); |
85 |
my $details = GetInvoiceDetails($invoiceid); |
82 |
my $bookseller = GetBookSellerFromId($details->{booksellerid}); |
86 |
my $bookseller = GetBookSellerFromId( $details->{booksellerid} ); |
83 |
my @orders_loop = (); |
87 |
my @orders_loop = (); |
84 |
my $orders = $details->{'orders'}; |
88 |
my $orders = $details->{'orders'}; |
85 |
my $qty_total; |
89 |
my $qty_total; |
86 |
my @books_loop; |
90 |
my @books_loop; |
87 |
my @book_foot_loop; |
91 |
my @book_foot_loop; |
88 |
my %foot; |
92 |
my %foot; |
89 |
my $total_quantity = 0; |
93 |
my $total_quantity = 0; |
90 |
my $total_rrp = 0; |
94 |
my $total_rrp = 0; |
91 |
my $total_est = 0; |
95 |
my $total_est = 0; |
|
|
96 |
|
92 |
foreach my $order (@$orders) { |
97 |
foreach my $order (@$orders) { |
93 |
my $line = get_infos( $order, $bookseller); |
98 |
my $line = get_infos( $order, $bookseller ); |
94 |
|
99 |
|
95 |
$total_quantity += $$line{quantity}; |
100 |
$total_quantity += $$line{quantity}; |
96 |
$total_rrp += $order->{quantity} * $order->{rrp}; |
101 |
$total_rrp += $order->{quantity} * $order->{rrp}; |
97 |
$total_est += $order->{quantity} * $order->{'ecost'}; |
102 |
$total_est += $order->{quantity} * $order->{'ecost'}; |
98 |
|
103 |
|
99 |
my %row = (%$order, %$line); |
104 |
my %row = ( %$order, %$line ); |
100 |
push @orders_loop, \%row; |
105 |
push @orders_loop, \%row; |
101 |
} |
106 |
} |
102 |
|
107 |
|
103 |
my $gist = $bookseller->{gstrate} // C4::Context->preference("gist") // 0; |
108 |
my $gist = $bookseller->{gstrate} // C4::Context->preference("gist") // 0; |
104 |
my $discount = $bookseller->{'discount'} ? ($bookseller->{discount} / 100) : 0; |
109 |
my $discount = |
|
|
110 |
$bookseller->{'discount'} ? ( $bookseller->{discount} / 100 ) : 0; |
105 |
my $total_est_gste; |
111 |
my $total_est_gste; |
106 |
my $total_est_gsti; |
112 |
my $total_est_gsti; |
107 |
my $total_rrp_gsti; # RRP Total, GST included |
113 |
my $total_rrp_gsti; # RRP Total, GST included |
108 |
my $total_rrp_gste; # RRP Total, GST excluded |
114 |
my $total_rrp_gste; # RRP Total, GST excluded |
109 |
my $gist_est; |
115 |
my $gist_est; |
110 |
my $gist_rrp; |
116 |
my $gist_rrp; |
111 |
if ($gist){ |
117 |
if ($gist) { |
|
|
118 |
|
112 |
# if we have GST |
119 |
# if we have GST |
113 |
if ( $bookseller->{'listincgst'} ) { |
120 |
if ( $bookseller->{'listincgst'} ) { |
|
|
121 |
|
114 |
# if prices already includes GST |
122 |
# if prices already includes GST |
115 |
|
123 |
|
116 |
# we know $total_rrp_gsti |
124 |
# we know $total_rrp_gsti |
117 |
$total_rrp_gsti = $total_rrp; |
125 |
$total_rrp_gsti = $total_rrp; |
|
|
126 |
|
118 |
# and can reverse compute other values |
127 |
# and can reverse compute other values |
119 |
$total_rrp_gste = $total_rrp_gsti / ( $gist + 1 ); |
128 |
$total_rrp_gste = $total_rrp_gsti / ( $gist + 1 ); |
120 |
|
129 |
|
121 |
$gist_rrp = $total_rrp_gsti - $total_rrp_gste; |
130 |
$gist_rrp = $total_rrp_gsti - $total_rrp_gste; |
122 |
$total_est_gste = $total_rrp_gste - ( $total_rrp_gste * $discount ); |
131 |
$total_est_gste = $total_rrp_gste - ( $total_rrp_gste * $discount ); |
123 |
$total_est_gsti = $total_est; |
132 |
$total_est_gsti = $total_est; |
124 |
} else { |
133 |
} |
|
|
134 |
else { |
125 |
# if prices does not include GST |
135 |
# if prices does not include GST |
126 |
|
136 |
|
127 |
# then we use the common way to compute other values |
137 |
# then we use the common way to compute other values |
Lines 130-163
if ($gist){
Link Here
|
130 |
$total_rrp_gsti = $total_rrp_gste + $gist_rrp; |
140 |
$total_rrp_gsti = $total_rrp_gste + $gist_rrp; |
131 |
$total_est_gste = $total_est; |
141 |
$total_est_gste = $total_est; |
132 |
$total_est_gsti = $total_rrp_gsti - ( $total_rrp_gsti * $discount ); |
142 |
$total_est_gsti = $total_rrp_gsti - ( $total_rrp_gsti * $discount ); |
133 |
} |
143 |
} |
134 |
$gist_est = $gist_rrp - ( $gist_rrp * $discount ); |
144 |
$gist_est = $gist_rrp - ( $gist_rrp * $discount ); |
135 |
} else { |
145 |
} |
|
|
146 |
else { |
136 |
$total_rrp_gste = $total_rrp_gsti = $total_rrp; |
147 |
$total_rrp_gste = $total_rrp_gsti = $total_rrp; |
137 |
$total_est_gste = $total_est_gsti = $total_est; |
148 |
$total_est_gste = $total_est_gsti = $total_est; |
138 |
$gist_rrp = $gist_est = 0; |
149 |
$gist_rrp = $gist_est = 0; |
139 |
} |
150 |
} |
140 |
my $total_gsti_shipment = $total_est_gsti + $details->{shipmentcost}; |
151 |
my $total_gsti_shipment = $total_est_gsti + $details->{shipmentcost}; |
141 |
|
152 |
|
142 |
my $format = "%.2f"; |
153 |
my $format = "%.2f"; |
143 |
$template->param( |
154 |
$template->param( |
144 |
total_rrp_gste => sprintf($format, $total_rrp_gste), |
155 |
total_rrp_gste => sprintf( $format, $total_rrp_gste ), |
145 |
total_rrp_gsti => sprintf($format, $total_rrp_gsti), |
156 |
total_rrp_gsti => sprintf( $format, $total_rrp_gsti ), |
146 |
total_est_gste => sprintf($format, $total_est_gste), |
157 |
total_est_gste => sprintf( $format, $total_est_gste ), |
147 |
total_est_gsti => sprintf($format, $total_est_gsti), |
158 |
total_est_gsti => sprintf( $format, $total_est_gsti ), |
148 |
gist_rrp => sprintf($format, $gist_rrp), |
159 |
gist_rrp => sprintf( $format, $gist_rrp ), |
149 |
gist_est => sprintf($format, $gist_est), |
160 |
gist_est => sprintf( $format, $gist_est ), |
150 |
total_gsti_shipment => sprintf($format, $total_gsti_shipment), |
161 |
total_gsti_shipment => sprintf( $format, $total_gsti_shipment ), |
151 |
gist => sprintf($format, $gist * 100), |
162 |
gist => sprintf( $format, $gist * 100 ), |
152 |
); |
163 |
); |
153 |
|
164 |
|
154 |
my $budgets = GetBudgets(); |
165 |
my $budgets = GetBudgets(); |
155 |
my @budgets_loop; |
166 |
my @budgets_loop; |
156 |
my $shipmentcost_budgetid = $details->{shipmentcost_budgetid}; |
167 |
my $shipmentcost_budgetid = $details->{shipmentcost_budgetid}; |
157 |
foreach my $budget (@$budgets) { |
168 |
foreach my $budget (@$budgets) { |
158 |
next unless CanUserUseBudget($loggedinuser, $budget, $flags); |
169 |
next unless CanUserUseBudget( $loggedinuser, $budget, $flags ); |
159 |
my %line = %{ $budget }; |
170 |
my %line = %{$budget}; |
160 |
if($shipmentcost_budgetid and $budget->{budget_id} == $shipmentcost_budgetid) { |
171 |
if ( $shipmentcost_budgetid |
|
|
172 |
and $budget->{budget_id} == $shipmentcost_budgetid ) |
173 |
{ |
161 |
$line{selected} = 1; |
174 |
$line{selected} = 1; |
162 |
} |
175 |
} |
163 |
push @budgets_loop, \%line; |
176 |
push @budgets_loop, \%line; |
Lines 172-199
$template->param(
Link Here
|
172 |
shipmentdate => $details->{'shipmentdate'}, |
185 |
shipmentdate => $details->{'shipmentdate'}, |
173 |
billingdate => $details->{'billingdate'}, |
186 |
billingdate => $details->{'billingdate'}, |
174 |
invoiceclosedate => $details->{'closedate'}, |
187 |
invoiceclosedate => $details->{'closedate'}, |
175 |
shipmentcost => sprintf($format, $details->{'shipmentcost'} || 0), |
188 |
shipmentcost => sprintf( $format, $details->{'shipmentcost'} || 0 ), |
176 |
orders_loop => \@orders_loop, |
189 |
orders_loop => \@orders_loop, |
177 |
total_quantity => $total_quantity, |
190 |
total_quantity => $total_quantity, |
178 |
invoiceincgst => $bookseller->{invoiceincgst}, |
191 |
invoiceincgst => $bookseller->{invoiceincgst}, |
179 |
currency => $bookseller->{listprice}, |
192 |
currency => $bookseller->{listprice}, |
180 |
DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), |
193 |
DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), |
181 |
budgets_loop => \@budgets_loop, |
194 |
budgets_loop => \@budgets_loop, |
182 |
); |
195 |
); |
183 |
|
196 |
|
184 |
sub get_infos { |
197 |
sub get_infos { |
185 |
my $order = shift; |
198 |
my $order = shift; |
186 |
my $bookseller = shift; |
199 |
my $bookseller = shift; |
187 |
my $qty = $order->{'quantity'} || 0; |
200 |
my $qty = $order->{'quantity'} || 0; |
188 |
if ( !defined $order->{quantityreceived} ) { |
201 |
if ( !defined $order->{quantityreceived} ) { |
189 |
$order->{quantityreceived} = 0; |
202 |
$order->{quantityreceived} = 0; |
190 |
} |
203 |
} |
191 |
my $budget = GetBudget( $order->{'budget_id'} ); |
204 |
my $budget = GetBudget( $order->{'budget_id'} ); |
192 |
|
205 |
|
193 |
my %line = %{ $order }; |
206 |
my %line = %{$order}; |
194 |
$line{order_received} = ( $qty == $order->{'quantityreceived'} ); |
207 |
$line{order_received} = ( $qty == $order->{'quantityreceived'} ); |
195 |
$line{budget_name} = $budget->{budget_name}; |
208 |
$line{budget_name} = $budget->{budget_name}; |
196 |
$line{total} = $qty * $order->{ecost}; |
209 |
$line{total} = $qty * $order->{ecost}; |
197 |
|
210 |
|
198 |
if ( $line{uncertainprice} ) { |
211 |
if ( $line{uncertainprice} ) { |
199 |
$line{rrp} .= ' (Uncertain)'; |
212 |
$line{rrp} .= ' (Uncertain)'; |
Lines 203-209
sub get_infos {
Link Here
|
203 |
my $seriestitle = $order->{'seriestitle'}; |
216 |
my $seriestitle = $order->{'seriestitle'}; |
204 |
$line{'title'} .= " / $seriestitle" if $seriestitle; |
217 |
$line{'title'} .= " / $seriestitle" if $seriestitle; |
205 |
$line{'title'} .= " / $volume" if $volume; |
218 |
$line{'title'} .= " / $volume" if $volume; |
206 |
} else { |
219 |
} |
|
|
220 |
else { |
207 |
$line{'title'} = "Deleted bibliographic notice, can't find title."; |
221 |
$line{'title'} = "Deleted bibliographic notice, can't find title."; |
208 |
} |
222 |
} |
209 |
|
223 |
|