Lines 126-131
use C4::Auth; # get_template_and_user
Link Here
|
126 |
use C4::Acquisition; # NewOrder DelOrder ModOrder |
126 |
use C4::Acquisition; # NewOrder DelOrder ModOrder |
127 |
use C4::Suggestions; # ModStatus |
127 |
use C4::Suggestions; # ModStatus |
128 |
use C4::Biblio; # AddBiblio TransformKohaToMarc |
128 |
use C4::Biblio; # AddBiblio TransformKohaToMarc |
|
|
129 |
use C4::Budgets; |
129 |
use C4::Items; |
130 |
use C4::Items; |
130 |
use C4::Output; |
131 |
use C4::Output; |
131 |
|
132 |
|
Lines 135-141
use C4::Output;
Link Here
|
135 |
# not just blindly call C4 functions and print a redirect. |
136 |
# not just blindly call C4 functions and print a redirect. |
136 |
|
137 |
|
137 |
my $input = new CGI; |
138 |
my $input = new CGI; |
138 |
### $input |
139 |
|
|
|
140 |
# Check if order total amount exceed allowed budget |
141 |
my $confirm_budget_exceeding = $input->param('confirm_budget_exceeding'); |
142 |
unless($confirm_budget_exceeding) { |
143 |
my $budget_id = $input->param('budget_id'); |
144 |
my $total = $input->param('total'); |
145 |
my $budget = GetBudget($budget_id); |
146 |
my $budget_spent = GetBudgetSpent($budget_id); |
147 |
my $budget_ordered = GetBudgetOrdered($budget_id); |
148 |
my $budget_used = $budget_spent + $budget_ordered; |
149 |
my $budget_remaining = $budget->{budget_amount} - $budget_used; |
150 |
my $budget_encumbrance = $budget->{budget_amount} * $budget->{budget_encumb} / 100; |
151 |
my $budget_expenditure = $budget->{budget_expend}; |
152 |
|
153 |
if ( $total > $budget_remaining |
154 |
|| ( ($budget_encumbrance+0) && ($budget_used + $total) > $budget_encumbrance) |
155 |
|| ( ($budget_expenditure+0) && ($budget_used + $total) > $budget_expenditure) ) |
156 |
{ |
157 |
my ($template, $loggedinuser, $cookie) = get_template_and_user({ |
158 |
template_name => "acqui/addorder.tmpl", |
159 |
query => $input, |
160 |
type => "intranet", |
161 |
authnotrequired => 0, |
162 |
flagsrequired => {acquisition => 'order_manage'}, |
163 |
}); |
164 |
|
165 |
my $url = $input->referer(); |
166 |
unless ( defined $url ) { |
167 |
my $basketno = $input->param('basketno'); |
168 |
$url = "/cgi-bin/koha/acqui/basket.pl?basketno=$basketno"; |
169 |
} |
170 |
|
171 |
my $vars = $input->Vars; |
172 |
my @vars_loop; |
173 |
foreach (keys %$vars) { |
174 |
push @vars_loop, { |
175 |
name => $_, |
176 |
values => [$input->param($_)], |
177 |
}; |
178 |
} |
179 |
|
180 |
if( ($budget_encumbrance+0) && ($budget_used + $total) > $budget_encumbrance |
181 |
&& $total <= $budget_remaining) |
182 |
{ |
183 |
$template->param( |
184 |
encumbrance_exceeded => 1, |
185 |
encumbrance => sprintf("%.2f", $budget->{'budget_encumb'}), |
186 |
); |
187 |
} |
188 |
if( ($budget_expenditure+0) && ($budget_used + $total) > $budget_expenditure |
189 |
&& $total <= $budget_remaining ) |
190 |
{ |
191 |
my $currency = GetCurrency; |
192 |
$template->param( |
193 |
expenditure_exceeded => 1, |
194 |
expenditure => sprintf("%.2f", $budget_expenditure), |
195 |
currency => ($currency) ? $currency->{'symbol'} : '', |
196 |
); |
197 |
} |
198 |
if($total > $budget_remaining){ |
199 |
$template->param(budget_exceeded => 1); |
200 |
} |
201 |
|
202 |
$template->param( |
203 |
not_enough_budget => 1, |
204 |
referer => $url, |
205 |
vars_loop => \@vars_loop, |
206 |
); |
207 |
output_html_with_http_headers $input, $cookie, $template->output; |
208 |
exit; |
209 |
} |
210 |
} |
139 |
|
211 |
|
140 |
# get_template_and_user used only to check auth & get user id |
212 |
# get_template_and_user used only to check auth & get user id |
141 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
213 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |