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 |
unless($_ eq "field_value" || $_ eq "itemid" || $_ eq "kohafield" || $_ eq "tag" || $_ eq "subfield" || $_ eq "mandatory") { |
175 |
push @vars_loop, { |
176 |
name => $_, |
177 |
value => $vars->{$_}, |
178 |
}; |
179 |
} |
180 |
} |
181 |
|
182 |
my @field_value_loop; |
183 |
push @field_value_loop, {value => $_} for $input->param('field_value'); |
184 |
|
185 |
my @itemid_loop; |
186 |
push @itemid_loop, {value => $_} for $input->param('itemid'); |
187 |
|
188 |
my @kohafield_loop; |
189 |
push @kohafield_loop, {value => $_} for $input->param('kohafield'); |
190 |
|
191 |
my @tag_loop; |
192 |
push @tag_loop, {value => $_} for $input->param('tag'); |
193 |
|
194 |
my @subfield_loop; |
195 |
push @subfield_loop, {value => $_} for $input->param('subfield'); |
196 |
|
197 |
my @mandatory_loop; |
198 |
push @mandatory_loop, {value => $_} for $input->param('mandatory'); |
199 |
|
200 |
if( ($budget_encumbrance+0) && ($budget_used + $total) > $budget_encumbrance |
201 |
&& $total <= $budget_remaining) |
202 |
{ |
203 |
$template->param( |
204 |
encumbrance_exceeded => 1, |
205 |
encumbrance => sprintf("%.2f", $budget->{'budget_encumb'}), |
206 |
); |
207 |
} |
208 |
if( ($budget_expenditure+0) && ($budget_used + $total) > $budget_expenditure |
209 |
&& $total <= $budget_remaining ) |
210 |
{ |
211 |
my $currency = GetCurrency; |
212 |
$template->param( |
213 |
expenditure_exceeded => 1, |
214 |
expenditure => sprintf("%.2f", $budget_expenditure), |
215 |
currency => ($currency) ? $currency->{'symbol'} : '', |
216 |
); |
217 |
} |
218 |
if($total > $budget_remaining){ |
219 |
$template->param(budget_exceeded => 1); |
220 |
} |
221 |
|
222 |
$template->param( |
223 |
not_enough_budget => 1, |
224 |
referer => $url, |
225 |
vars_loop => \@vars_loop, |
226 |
field_value => \@field_value_loop, |
227 |
itemid => \@itemid_loop, |
228 |
kohafield => \@kohafield_loop, |
229 |
tag => \@tag_loop, |
230 |
subfield => \@subfield_loop, |
231 |
mandatory => \@mandatory_loop, |
232 |
); |
233 |
output_html_with_http_headers $input, $cookie, $template->output; |
234 |
exit; |
235 |
} |
236 |
} |
139 |
|
237 |
|
140 |
# get_template_and_user used only to check auth & get user id |
238 |
# get_template_and_user used only to check auth & get user id |
141 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
239 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |