1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
6 #############################################################################
7 # Veraendert 2005-01-05 - Marco Welter <mawe@linux-studio.de> - Neue Optik #
8 #############################################################################
9 # SQL-Ledger, Accounting
10 # Copyright (c) 1998-2002
12 # Author: Dieter Simader
13 # Email: dsimader@sql-ledger.org
14 # Web: http://www.sql-ledger.org
17 # This program is free software; you can redistribute it and/or modify
18 # it under the terms of the GNU General Public License as published by
19 # the Free Software Foundation; either version 2 of the License, or
20 # (at your option) any later version.
22 # This program is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU General Public License for more details.
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write to the Free Software
28 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #######################################################################
32 # common routines used in is, ir, oe
34 #######################################################################
41 require "bin/mozilla/common.pl";
43 # any custom scripts for this one
44 if (-f "bin/mozilla/custom_io.pl") {
45 eval { require "bin/mozilla/custom_io.pl"; };
47 if (-f "bin/mozilla/$form->{login}_io.pl") {
48 eval { require "bin/mozilla/$form->{login}_io.pl"; };
55 # this is for our long dates
56 # $locale->text('January')
57 # $locale->text('February')
58 # $locale->text('March')
59 # $locale->text('April')
60 # $locale->text('May ')
61 # $locale->text('June')
62 # $locale->text('July')
63 # $locale->text('August')
64 # $locale->text('September')
65 # $locale->text('October')
66 # $locale->text('November')
67 # $locale->text('December')
69 # this is for our short month
70 # $locale->text('Jan')
71 # $locale->text('Feb')
72 # $locale->text('Mar')
73 # $locale->text('Apr')
74 # $locale->text('May')
75 # $locale->text('Jun')
76 # $locale->text('Jul')
77 # $locale->text('Aug')
78 # $locale->text('Sep')
79 # $locale->text('Oct')
80 # $locale->text('Nov')
81 # $locale->text('Dec')
86 ########################################
87 # Eintrag fuer Version 2.2.0 geaendert #
88 # neue Optik im Rechnungsformular #
89 ########################################
91 $lxdebug->enter_sub();
94 if ($lizenzen && $form->{vc} eq "customer") {
95 if ($form->{type} =~ /sales_order/) {
96 @column_index = (runningnumber, partnumber, description, ship, qty);
97 } elsif ($form->{type} =~ /sales_quotation/) {
98 @column_index = (runningnumber, partnumber, description, qty);
100 @column_index = (runningnumber, partnumber, description, qty);
103 if ( ($form->{type} =~ /purchase_order/)
104 || ($form->{type} =~ /sales_order/)) {
105 @column_index = (runningnumber, partnumber, description, ship, qty);
107 @column_index = (runningnumber, partnumber, description, qty);
110 ############## ENDE Neueintrag ##################
112 my $dimension_units = AM->retrieve_units(\%myconfig, $form, "dimension");
113 my $service_units = AM->retrieve_units(\%myconfig, $form, "service");
114 my $all_units = AM->retrieve_units(\%myconfig, $form);
116 push @column_index, qw(unit);
118 #for pricegroups column
119 if ( $form->{type} =~ (/sales_quotation/)
120 or (($form->{level} =~ /Sales/) and ($form->{type} =~ /invoice/))
121 or (($form->{level} eq undef) and ($form->{type} =~ /invoice/))
122 or ($form->{type} =~ /sales_order/)) {
123 push @column_index, qw(sellprice_pg);
126 push @column_index, qw(sellprice);
128 if ($form->{vc} eq 'customer') {
129 push @column_index, qw(discount);
132 push @column_index, "linetotal";
134 my $colspan = $#column_index + 1;
136 $form->{invsubtotal} = 0;
137 map { $form->{"${_}_base"} = 0 } (split(/ /, $form->{taxaccounts}));
139 ########################################
140 # Eintrag fuer Version 2.2.0 geaendert #
141 # neue Optik im Rechnungsformular #
142 ########################################
143 $column_data{runningnumber} =
144 qq|<th align="left" nowrap width="5" class="listheading">|
145 . $locale->text('No.')
147 $column_data{partnumber} =
148 qq|<th align="left" nowrap width="12" class="listheading">|
149 . $locale->text('Number')
151 $column_data{description} =
152 qq|<th align="left" nowrap width="30" class="listheading">|
153 . $locale->text('Part Description')
155 if ($form->{"type"} eq "purchase_order") {
157 qq|<th align="left" nowrap width="5" class="listheading">|
158 . $locale->text('Ship rcvd')
162 qq|<th align="left" nowrap width="5" class="listheading">|
163 . $locale->text('Ship')
167 qq|<th align="left" nowrap width="5" class="listheading">|
168 . $locale->text('Qty')
171 qq|<th align="left" nowrap width="5" class="listheading">|
172 . $locale->text('Unit')
174 $column_data{license} =
175 qq|<th align="left" nowrap width="10" class="listheading">|
176 . $locale->text('License')
178 $column_data{serialnr} =
179 qq|<th align="left" nowrap width="10" class="listheading">|
180 . $locale->text('Serial No.')
182 $column_data{projectnr} =
183 qq|<th align="left" nowrap width="10" class="listheading">|
184 . $locale->text('Project')
186 $column_data{sellprice} =
187 qq|<th align="left" nowrap width="15" class="listheading">|
188 . $locale->text('Price')
190 $column_data{sellprice_pg} =
191 qq|<th align="left" nowrap width="15" class="listheading">|
192 . $locale->text('Pricegroup')
194 $column_data{discount} =
195 qq|<th align="left" class="listheading">|
196 . $locale->text('Discount')
198 $column_data{linetotal} =
199 qq|<th align="left" nowrap width="10" class="listheading">|
200 . $locale->text('Extended')
203 qq|<th align="left" nowrap width="10" class="listheading">|
204 . $locale->text('Bin')
206 ############## ENDE Neueintrag ##################
208 $myconfig{"show_form_details"} = 1
209 unless (defined($myconfig{"show_form_details"}));
210 $form->{"show_details"} = $myconfig{"show_form_details"}
211 unless (defined($form->{"show_details"}));
212 $form->{"show_details"} = $form->{"show_details"} ? 1 : 0;
213 my $show_details_new = 1 - $form->{"show_details"};
214 my $show_details_checked = $form->{"show_details"} ? "checked" : "";
218 <td>| . $cgi->hidden("-name" => "show_details", "-value" => $form->{show_details}) . qq|
219 <input type="checkbox" id="cb_show_details" onclick="show_form_details($show_details_new);" $show_details_checked>
220 <label for="cb_show_details">| . $locale->text("Show details") . qq|</label><br>
222 <tr class="listheading">|;
224 map { print "\n$column_data{$_}" } @column_index;
230 $runningnumber = $locale->text('No.');
231 $deliverydate = $locale->text('Delivery Date');
232 $serialnumber = $locale->text('Serial No.');
233 $projectnumber = $locale->text('Project');
234 $partsgroup = $locale->text('Group');
235 $reqdate = $locale->text('Reqdate');
237 $delvar = 'deliverydate';
239 if ($form->{type} =~ /_order$/ || $form->{type} =~ /_quotation$/) {
240 $deliverydate = $locale->text('Required by');
244 $form->{marge_total} = 0;
245 $form->{sellprice_total} = 0;
246 $form->{lastcost_total} = 0;
247 my %projectnumber_labels = ();
248 my @projectnumber_values = ("");
249 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
250 push(@projectnumber_values, $item->{"id"});
251 $projectnumber_labels{$item->{"id"}} = $item->{"projectnumber"};
254 for $i (1 .. $numrows) {
259 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
260 } qw(qty ship discount sellprice price_new price_old) unless ($form->{simple_save});
262 if (!$form->{"unit_old_$i"}) {
263 # Neue Ware aus der Datenbank. In diesem Fall ist unit_$i die
264 # Einheit, wie sie in den Stammdaten hinterlegt wurde.
265 # Es sollte also angenommen werden, dass diese ausgewaehlt war.
266 $form->{"unit_old_$i"} = $form->{"unit_$i"};
269 # Die zuletzt ausgewaehlte mit der aktuell ausgewaehlten Einheit
270 # vergleichen und bei Unterschied den Preis entsprechend umrechnen.
271 $form->{"selected_unit_$i"} = $form->{"unit_$i"} unless ($form->{"selected_unit_$i"});
273 my $check_units = $form->{"inventory_accno_$i"} ? $dimension_units : $service_units;
274 if (!$check_units->{$form->{"selected_unit_$i"}} ||
275 ($check_units->{$form->{"selected_unit_$i"}}->{"base_unit"} ne
276 $all_units->{$form->{"unit_old_$i"}}->{"base_unit"})) {
277 # Die ausgewaehlte Einheit ist fuer diesen Artikel nicht gueltig
278 # (z.B. Dimensionseinheit war ausgewaehlt, es handelt sich aber
279 # um eine Dienstleistung). Dann keinerlei Umrechnung vornehmen.
280 $form->{"unit_old_$i"} = $form->{"selected_unit_$i"} = $form->{"unit_$i"};
282 if ((!$form->{"prices_$i"}) || ($form->{"new_pricegroup_$i"} == $form->{"old_pricegroup_$i"})) {
283 if ($form->{"unit_old_$i"} ne $form->{"selected_unit_$i"}) {
285 if (defined($all_units->{$form->{"unit_old_$i"}}->{"factor"}) &&
286 $all_units->{$form->{"unit_old_$i"}}->{"factor"}) {
287 $basefactor = $all_units->{$form->{"selected_unit_$i"}}->{"factor"} /
288 $all_units->{$form->{"unit_old_$i"}}->{"factor"};
290 $form->{"sellprice_$i"} *= $basefactor;
291 $form->{"unit_old_$i"} = $form->{"selected_unit_$i"};
294 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
296 $decimalplaces = ($dec > 2) ? $dec : 2;
300 $form->{"sellprice_$i"} * $form->{"discount_$i"} / 100,
304 $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
305 $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
306 my $real_sellprice = $form->{"sellprice_$i"} - $discount;
309 my ($marge_font_start, $marge_font_end);
310 $form->{"lastcost_$i"} *= 1;
311 if ($real_sellprice && ($form->{"qty_$i"} * 1)) {
312 $form->{"marge_percent_$i"} =
313 ($real_sellprice - $form->{"lastcost_$i"}) * 100 / $real_sellprice;
315 $myconfig{"marge_percent_warn"} = 15
316 unless (defined($myconfig{"marge_percent_warn"}));
317 if ($form->{"id_$i"} &&
318 ($form->{"marge_percent_$i"} <
319 (1 * $myconfig{"marge_percent_warn"}))) {
320 $marge_font_start = "<font color=\"#ff0000\">";
321 $marge_font_end = "</font>";
324 $form->{"marge_percent_$i"} = 0;
326 $form->{"marge_absolut_$i"} =
327 ($real_sellprice - $form->{"lastcost_$i"}) * $form->{"qty_$i"};
328 $form->{"marge_total"} += $form->{"marge_absolut_$i"};
329 $form->{"lastcost_total"} += $form->{"lastcost_$i"} * $form->{"qty_$i"};
330 $form->{"sellprice_total"} += $real_sellprice * $form->{"qty_$i"};
334 $form->format_amount(\%myconfig, $form->{"${_}_$i"},
336 } qw(marge_absolut marge_percent);
338 # convert " to "
339 map { $form->{"${_}_$i"} =~ s/\"/"/g }
340 qw(partnumber description unit unit_old);
342 ########################################
343 # Eintrag fuer Version 2.2.0 geaendert #
344 # neue Optik im Rechnungsformular #
345 ########################################
346 $column_data{runningnumber} =
347 qq|<td><input name="runningnumber_$i" size="5" value="$i"></td>|; # HuT
348 ############## ENDE Neueintrag ##################
350 $column_data{partnumber} =
351 qq|<td><input name="partnumber_$i" size=12 value="$form->{"partnumber_$i"}"></td>|;
353 if (($rows = $form->numtextrows($form->{"description_$i"}, 30, 6)) > 1) {
354 $column_data{description} =
355 qq|<td><textarea name="description_$i" rows="$rows" cols="30" wrap="soft">| . H($form->{"description_$i"}) . qq|</textarea><button type="button" onclick="set_longdescription_window('longdescription_$i')">| . $locale->text('L') . qq|</button></td>|;
357 $column_data{description} =
358 qq|<td><input name="description_$i" size="30" value="| . $form->quote($form->{"description_$i"}) . qq|"><button type="button" onclick="set_longdescription_window('longdescription_$i')">| . $locale->text('L') . qq|</button></td>|;
361 (my $qty_dec) = ($form->{"qty_$i"} =~ /\.(\d+)/);
362 $qty_dec = length $qty_dec;
365 qq|<td align="right"><input name="qty_$i" size="5" value="|
366 . $form->format_amount(\%myconfig, $form->{"qty_$i"}, $qty_dec) .qq|">|;
367 if ($form->{"formel_$i"}) {
368 $column_data{qty} .= qq|<button type="button" onclick="calculate_qty_selection_window('qty_$i','alu_$i', 'formel_$i', $i)">| . $locale->text('*/') . qq|</button>| .
369 $cgi->hidden("-name" => "formel_$i", "-value" => $form->{"formel_$i"}) . $cgi->hidden("-name" => "alu_$i", "-value" => $form->{"alu_$i"}). qq|</td>|;
372 qq|<td align="right"><input name="ship_$i" size=5 value="|
373 . $form->format_amount(\%myconfig, $form->{"ship_$i"})
376 my $is_part = $form->{"inventory_accno_$i"};
377 my $is_assembly = $form->{"assembly_$i"};
378 my $is_assigned = $form->{"id_$i"};
379 my $this_unit = $form->{"unit_$i"};
380 if ($form->{"selected_unit_$i"} && $this_unit &&
381 $all_units->{$form->{"selected_unit_$i"}} && $all_units->{$this_unit} &&
382 ($all_units->{$form->{"selected_unit_$i"}}->{"base_unit"} eq $all_units->{$this_unit}->{"base_unit"})) {
383 $this_unit = $form->{"selected_unit_$i"};
384 } elsif (!$is_assigned ||
385 ($is_part && !$this_unit && ($all_units->{$this_unit} && ($all_units->{$this_unit}->{"base_unit"} eq $all_units->{"kg"}->{"base_unit"})))) {
389 $column_data{"unit"} = "<td>" .
390 AM->unit_select_html($is_part || $is_assembly ? $dimension_units :
391 $is_assigned ? $service_units : $all_units,
392 "unit_$i", $this_unit,
393 $is_assigned ? $form->{"unit_$i"} : undef)
396 # build in drop down list for pricesgroups
397 if ($form->{"prices_$i"}) {
398 if ($form->{"new_pricegroup_$i"} != $form->{"old_pricegroup_$i"}) {
399 $price_tmp = $form->format_amount(\%myconfig, $form->{"price_new_$i"}, $decimalplaces);
401 $price_tmp = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
404 $column_data{sellprice_pg} =
405 qq|<td align="right"><select name="sellprice_pg_$i">$form->{"prices_$i"}</select></td>|;
406 $column_data{sellprice} =
407 qq|<td><input name="sellprice_$i" size="10" value="$price_tmp" onBlur=\"check_right_number_format(this)\"></td>|;
410 # for last row and report
411 # set pricegroup drop down list from report menu
412 if ($form->{"sellprice_$i"} != 0) {
414 qq|<option value="$form->{"sellprice_$i"}--$form->{"pricegroup_id_$i"}" selected>$form->{"pricegroup_$i"}</option>\n|;
416 $form->{"pricegroup_old_$i"} = $form->{"pricegroup_id_$i"};
418 $column_data{sellprice_pg} =
419 qq|<td align="right"><select name="sellprice_pg_$i">$prices</select></td>|;
424 $column_data{sellprice_pg} = qq|<td align="right"> </td>|;
427 $column_data{sellprice} =
428 qq|<td><input name="sellprice_$i" size="10" onBlur=\"check_right_number_format(this)\" value="|
429 . $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
433 $column_data{discount} =
434 qq|<td align="right"><input name="discount_$i" size=3 value="|
435 . $form->format_amount(\%myconfig, $form->{"discount_$i"})
437 $column_data{linetotal} =
438 qq|<td align="right">|
439 . $form->format_amount(\%myconfig, $linetotal, 2)
441 $column_data{bin} = qq|<td>$form->{"bin_$i"}</td>|;
443 ########################################
444 # Eintrag fuer Version 2.2.0 geaendert #
445 # neue Optik im Rechnungsformular #
446 ########################################
447 # if ($lizenzen && $form->{type} eq "invoice" && $form->{vc} eq "customer") {
448 # $column_data{license} = qq|<td><select name="licensenumber_$i">$form->{"lizenzen_$i"}></select></td>|;
451 # if ($form->{type} !~ /_quotation/) {
452 # $column_data{serialnr} = qq|<td><input name="serialnumber_$i" size=10 value="$form->{"serialnumber_$i"}"></td>|;
455 # $column_data{projectnr} = qq|<td><input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}"></td>|;
456 ############## ENDE Neueintrag ##################
460 <tr valign="top" class="listrow$j">|;
462 map { print "\n$column_data{$_}" } @column_index;
465 $cgi->hidden("-name" => "unit_old_$i",
466 "-value" => $form->{"selected_unit_$i"})
468 $cgi->hidden("-name" => "price_new_$i",
469 "-value" => $form->format_amount(\%myconfig, $form->{"price_new_$i"}))
471 map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_}) . "\n"); }
472 ("orderitems_id_$i", "bo_$i", "pricegroup_old_$i", "price_old_$i",
473 "id_$i", "inventory_accno_$i", "bin_$i", "partsgroup_$i", "partnotes_$i",
474 "income_accno_$i", "expense_accno_$i", "listprice_$i", "assembly_$i",
475 "taxaccounts_$i", "ordnumber_$i", "transdate_$i", "cusordnumber_$i",
476 "longdescription_$i", "basefactor_$i", "marge_absolut_$i", "marge_percent_$i", "lastcost_$i"));
478 ########################################
479 # Eintrag fuer Version 2.2.0 geaendert #
480 # neue Optik im Rechnungsformular #
481 ########################################
484 'style="display:none;"' if (!$form->{"show_details"});
488 <tr class="listrow$j" $row_style_attr>
489 <td colspan="$colspan">
491 if ($lizenzen && $form->{type} eq "invoice" && $form->{vc} eq "customer") {
492 my $selected = $form->{"licensenumber_$i"};
494 $form->{"lizenzen_$i"} =~ s/ selected//g;
495 $form->{"lizenzen_$i"} =~
496 s/value="${selected}"\>/value="${selected}" selected\>/;
497 $lizenzen_quoted = $form->{"lizenzen_$i"};
498 $lizenzen_quoted =~ s/\"/"/g;
500 <b>Lizenz\#</b> <select name="licensenumber_$i" size="1">
501 $form->{"lizenzen_$i"}
503 <input type="hidden" name="lizenzen_$i" value="${lizenzen_quoted}">
506 if ($form->{type} !~ /_quotation/) {
508 <b>$serialnumber</b> <input name="serialnumber_$i" size="15" value="$form->{"serialnumber_$i"}">|;
511 print qq|<b>$projectnumber</b> | .
512 NTI($cgi->popup_menu('-name' => "project_id_$i",
513 '-values' => \@projectnumber_values,
514 '-labels' => \%projectnumber_labels,
515 '-default' => $form->{"project_id_$i"}));
517 if ($form->{type} eq 'invoice' or $form->{type} =~ /order/) {
519 ($form->{type} eq 'invoice')
521 : 'reqdate'; # invoice uses a different term for the same thing.
523 <b>${$reqdate_term}</b> <input name="${reqdate_term}_$i" size="11" onBlur="check_right_date_format(this)" value="$form->{"${reqdate_term}_$i"}">
526 my $subtotalchecked = ($form->{"subtotal_$i"}) ? "checked" : "";
528 <b>|.$locale->text('Subtotal').qq|</b> <input type="checkbox" name="subtotal_$i" value="1" "$subtotalchecked">
532 ${marge_font_start}<b>|.$locale->text('Ertrag').qq|</b> $form->{"marge_absolut_$i"} $form->{"marge_percent_$i"} % ${marge_font_end}
533 <b>|.$locale->text('LP').qq|</b> |.$form->format_amount(\%myconfig,$form->{"listprice_$i"},2).qq|
534 <b>|.$locale->text('EK').qq|</b> |.$form->format_amount(\%myconfig,$form->{"lastcost_$i"},2).qq|
539 ############## ENDE Neueintrag ##################
541 map { $form->{"${_}_base"} += $linetotal }
542 (split(/ /, $form->{"taxaccounts_$i"}));
544 $form->{invsubtotal} += $linetotal;
553 if (0 != ($form->{sellprice_total} * 1)) {
554 $form->{marge_percent} = ($form->{sellprice_total} - $form->{lastcost_total}) / $form->{sellprice_total} * 100;
557 $lxdebug->leave_sub();
560 ##################################################
561 # build html-code for pricegroups in variable $form->{prices_$j}
564 $lxdebug->enter_sub();
565 my $rowcount = shift;
566 for $j (1 .. $rowcount) {
567 my $pricegroup_old = $form->{"pricegroup_old_$i"};
568 if ($form->{PRICES}{$j}) {
570 $prices = '<option value="--">' . $locale->text("none (pricegroup)") . '</option>';
572 foreach $item (@{ $form->{PRICES}{$j} }) {
574 #$price = $form->round_amount($myconfig, $item->{price}, 5);
575 #$price = $form->format_amount($myconfig, $item->{price}, 2);
576 $price = $item->{price};
577 $pricegroup_id = $item->{pricegroup_id};
578 $pricegroup = $item->{pricegroup};
580 # build drop down list for pricegroups
582 qq|<option value="$price--$pricegroup_id"$item->{selected}>$pricegroup</option>\n|;
587 # $form->{"${_}_$j"} =
588 # $form->format_amount(\%myconfig, $form->{"${_}_$j"})
589 # } qw(sellprice price_new price_old);
591 # set new selectedpricegroup_id and prices for "Preis"
592 if ($item->{selected} && ($pricegroup_id != 0)) {
593 $form->{"pricegroup_old_$j"} = $pricegroup_id;
594 $form->{"price_new_$j"} = $price;
595 $form->{"sellprice_$j"} = $price;
597 if ($pricegroup_id == 0) {
598 $form->{"price_new_$j"} = $form->{"sellprice_$j"};
601 $form->{"prices_$j"} = $prices;
604 $lxdebug->leave_sub();
608 $lxdebug->enter_sub();
609 @column_index = qw(ndx partnumber description onhand unit sellprice);
611 $column_data{ndx} = qq|<th> </th>|;
612 $column_data{partnumber} =
613 qq|<th class="listheading">| . $locale->text('Number') . qq|</th>|;
614 $column_data{description} =
615 qq|<th class="listheading">| . $locale->text('Part Description') . qq|</th>|;
616 $column_data{sellprice} =
617 qq|<th class="listheading">| . $locale->text('Price') . qq|</th>|;
618 $column_data{onhand} =
619 qq|<th class="listheading">| . $locale->text('Qty') . qq|</th>|;
621 qq|<th class="listheading">| . $locale->text('Unit') . qq|</th>|;
622 # list items with radio button on a form
625 $title = $locale->text('Select from one of the items below');
626 $colspan = $#column_index + 1;
631 <form method="post" action="$form->{script}">
635 <th class="listtop" colspan="$colspan">$title</th>
638 <tr class="listheading">|;
640 map { print "\n$column_data{$_}" } @column_index;
645 foreach $ref (@{ $form->{item_list} }) {
646 $checked = ($i++) ? "" : "checked";
649 if ($ref->{inventory_accno} > 0) {
650 $ref->{"lizenzen"} = qq|<option></option>|;
651 foreach $item (@{ $form->{LIZENZEN}{ $ref->{"id"} } }) {
652 $ref->{"lizenzen"} .=
653 qq|<option value=\"$item->{"id"}\">$item->{"licensenumber"}</option>|;
655 $ref->{"lizenzen"} .= qq|<option value="-1">Neue Lizenz</option>|;
656 $ref->{"lizenzen"} =~ s/\"/"/g;
660 map { $ref->{$_} =~ s/\"/"/g } qw(partnumber description unit);
664 $form->round_amount($ref->{sellprice} * (1 - $form->{tradediscount}), 2);
666 qq|<td><input name="ndx" class="radio" type="radio" value="$i" $checked></td>|;
667 $column_data{partnumber} =
668 qq|<td><input name="new_partnumber_$i" type="hidden" value="$ref->{partnumber}">$ref->{partnumber}</td>|;
669 $column_data{description} =
670 qq|<td><input name="new_description_$i" type="hidden" value="$ref->{description}">$ref->{description}</td>|;
671 $column_data{sellprice} =
672 qq|<td align="right"><input name="new_sellprice_$i" type="hidden" value="$ref->{sellprice}">|
673 . $form->format_amount(\%myconfig, $ref->{sellprice}, 2, " ")
675 $column_data{onhand} =
676 qq|<td align="right"><input name="new_onhand_$i" type="hidden" value="$ref->{onhand}">|
677 . $form->format_amount(\%myconfig, $ref->{onhand}, '', " ")
680 qq|<td>$ref->{unit}</td>|;
684 <tr class=listrow$j>|;
686 map { print "\n$column_data{$_}" } @column_index;
691 qw(bin listprice inventory_accno income_accno expense_accno unit weight
692 assembly taxaccounts partsgroup formel longdescription not_discountable
693 part_payment_id partnotes id lastcost);
694 push(@new_fields, "lizenzen") if ($lizenzen);
696 print join "\n", map { $cgi->hidden("-name" => "new_${_}_$i", "-value" => $ref->{$_}) } @new_fields;
701 <tr><td colspan="8"><hr size="3" noshade></td></tr>
704 <input name="lastndx" type="hidden" value="$i">
708 # delete action variable
709 map { delete $form->{$_} } qw(action item_list header);
711 # save all other form variables
712 foreach $key (keys %${form}) {
713 $form->{$key} =~ s/\"/"/g;
714 print qq|<input name="$key" type="hidden" value="$form->{$key}">\n|;
718 <input type="hidden" name="nextsub" value="item_selected">
721 <input class="submit" type="submit" name="action" value="|
722 . $locale->text('Continue') . qq|">
729 $lxdebug->leave_sub();
733 $lxdebug->enter_sub();
735 # replace the last row with the checked row
736 $i = $form->{rowcount};
737 $i = $form->{assembly_rows} if ($form->{item} eq 'assembly');
743 #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
744 #$form->{"sellprice_$i"} = $form->{"sellprice_$i"};
746 # if there was a price entered, override it
747 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
749 map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} }
750 qw(id partnumber description sellprice listprice inventory_accno
751 income_accno expense_accno bin unit weight assembly taxaccounts
752 partsgroup formel longdescription not_discountable partnotes lastcost);
753 if ($form->{"part_payment_id_$i"} ne "") {
754 $form->{payment_id} = $form->{"part_payment_id_$i"};
758 map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} } qw(lizenzen);
761 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
763 $decimalplaces = ($dec > 2) ? $dec : 2;
766 $form->{"sellprice_$i"} = $sellprice;
769 # if there is an exchange rate adjust sellprice
770 if (($form->{exchangerate} * 1) != 0) {
771 $form->{"sellprice_$i"} /= $form->{exchangerate};
772 $form->{"sellprice_$i"} =
773 $form->round_amount($form->{"sellprice_$i"}, $decimalplaces);
777 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
778 qw(sellprice listprice weight);
780 $form->{sellprice} += ($form->{"sellprice_$i"} * $form->{"qty_$i"});
781 $form->{weight} += ($form->{"weight_$i"} * $form->{"qty_$i"});
783 if ($form->{"not_discountable_$i"}) {
784 $form->{"discount_$i"} = 0;
788 $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) *
790 map { $form->{"${_}_base"} += $amount }
791 (split / /, $form->{"taxaccounts_$i"});
792 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /,
793 $form->{"taxaccounts_$i"}
794 if !$form->{taxincluded};
796 $form->{creditremaining} -= $amount;
798 $form->{"runningnumber_$i"} = $i;
800 # delete all the new_ variables
801 for $i (1 .. $form->{lastndx}) {
802 map { delete $form->{"new_${_}_$i"} }
803 qw(partnumber description sellprice bin listprice inventory_accno income_accno expense_accno unit assembly taxaccounts id);
806 map { delete $form->{$_} } qw(ndx lastndx nextsub);
811 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces)
812 } qw(sellprice listprice) if $form->{item} ne 'assembly';
814 # get pricegroups for parts
815 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
817 # build up html code for prices_$i
818 set_pricegroup($form->{rowcount});
822 $lxdebug->leave_sub();
826 $lxdebug->enter_sub();
829 $form->{old_callback} = $form->escape($form->{callback}, 1);
830 $form->{callback} = $form->escape("$form->{script}?action=display_form", 1);
833 delete $form->{action};
835 # save all other form variables in a previousform variable
836 foreach $key (keys %$form) {
839 $form->{$key} =~ s/&/%26/g;
840 $previousform .= qq|$key=$form->{$key}&|;
843 $previousform = $form->escape($previousform, 1);
845 $i = $form->{rowcount};
846 map { $form->{"${_}_$i"} =~ s/\"/"/g } qw(partnumber description);
853 <h4 class="error">| . $locale->text('Item not on file!') . qq|
856 | . $locale->text('What type of item is this?') . qq|</h4>
858 <form method="post" action="ic.pl">
862 <input class="radio" type="radio" name="item" value="part" checked> |
863 . $locale->text('Part') . qq|<br>
864 <input class="radio" type="radio" name="item" value="service"> |
865 . $locale->text('Service');
866 print $cgi->hidden("-name" => "previousform", "-value" => $previousform);
867 map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); }
868 qw(rowcount vc login password));
869 map({ print($cgi->hidden("-name" => $_, "-value" => $form->{"$__$i"})); }
870 ("partnumber", "description"));
871 print $cgi->hidden("-name" => "taxaccount2", "-value" => $form->{taxaccounts});
874 <input type="hidden" name="nextsub" value="add">
877 <input class="submit" type="submit" name="action" value="|
878 . $locale->text('Continue') . qq|">
885 $lxdebug->leave_sub();
889 $lxdebug->enter_sub();
893 my $new_rowcount = $form->{"rowcount"} * 1 + 1;
894 $form->{"project_id_${new_rowcount}"} = $form->{"globalproject_id"};
896 $form->language_payment(\%myconfig);
898 # if we have a display_form
899 if ($form->{display_form}) {
900 call_sub($form->{"display_form"});
904 Common::webdav_folder($form) if ($webdav);
906 # if ( $form->{print_and_post}
907 # && $form->{second_run}
908 # && ($form->{action} eq "display_form")) {
909 # for (keys %$form) { $old_form->{$_} = $form->{$_} }
910 # $old_form->{rowcount}++;
912 # #$form->{rowcount}--;
913 # #$form->{rowcount}--;
915 # $form->{print_and_post} = 0;
917 # &print_form($old_form);
921 # $form->{action} = "";
922 # $form->{resubmit} = 0;
924 # if ($form->{print_and_post} && !$form->{second_run}) {
925 # $form->{second_run} = 1;
926 # $form->{action} = "display_form";
927 # $form->{rowcount}--;
928 # my $rowcount = $form->{rowcount};
930 # # get pricegroups for parts
931 # IS->get_pricegroups_for_parts(\%myconfig, \%$form);
933 # # build up html code for prices_$i
934 # set_pricegroup($rowcount);
936 # $form->{resubmit} = 1;
941 $numrows = ++$form->{rowcount};
942 $subroutine = "display_row";
944 if ($form->{item} eq 'part') {
946 #set preisgruppenanzahl
947 $numrows = $form->{price_rows};
948 $subroutine = "price_row";
950 &{$subroutine}($numrows);
952 $numrows = ++$form->{makemodel_rows};
953 $subroutine = "makemodel_row";
955 if ($form->{item} eq 'assembly') {
956 $numrows = $form->{price_rows};
957 $subroutine = "price_row";
959 &{$subroutine}($numrows);
961 $numrows = ++$form->{makemodel_rows};
962 $subroutine = "makemodel_row";
964 # create makemodel rows
965 &{$subroutine}($numrows);
967 $numrows = ++$form->{assembly_rows};
968 $subroutine = "assembly_row";
970 if ($form->{item} eq 'service') {
971 $numrows = $form->{price_rows};
972 $subroutine = "price_row";
974 &{$subroutine}($numrows);
980 &{$subroutine}($numrows) if $numrows;
984 $lxdebug->leave_sub();
988 $lxdebug->enter_sub();
992 qw(id partnumber description qty ship sellprice unit discount inventory_accno income_accno expense_accno listprice taxaccounts bin assembly weight projectnumber project_id oldprojectnumber runningnumber serialnumber partsgroup payment_id not_discountable shop ve gv buchungsgruppen_id language_values sellprice_pg pricegroup_old price_old price_new unit_old ordnumber transdate longdescription basefactor marge_absolut marge_percent lastcost )
996 # remove any makes or model rows
997 if ($form->{item} eq 'part') {
998 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
999 qw(listprice sellprice lastcost weight rop);
1001 @flds = (make, model);
1002 for my $i (1 .. ($form->{makemodel_rows})) {
1003 if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
1007 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1012 $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
1013 $form->{makemodel_rows} = $count;
1015 } elsif ($form->{item} eq 'assembly') {
1017 $form->{sellprice} = 0;
1018 $form->{weight} = 0;
1019 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1020 qw(listprice rop stock);
1023 qw(id qty unit bom partnumber description sellprice weight runningnumber partsgroup);
1025 for my $i (1 .. ($form->{assembly_rows} - 1)) {
1026 if ($form->{"qty_$i"}) {
1030 $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
1032 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1034 #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
1036 $form->{sellprice} += ($form->{"qty_$i"} * $form->{"sellprice_$i"});
1037 $form->{weight} += ($form->{"qty_$i"} * $form->{"weight_$i"});
1042 $form->{sellprice} = $form->round_amount($form->{sellprice}, 2);
1044 $form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows});
1045 $form->{assembly_rows} = $count;
1048 @flds = qw(make model);
1051 for my $i (1 .. ($form->{makemodel_rows})) {
1052 if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
1056 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1061 $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
1062 $form->{makemodel_rows} = $count;
1066 # this section applies to invoices and orders
1067 # remove any empty numbers
1068 if ($form->{rowcount}) {
1069 for my $i (1 .. $form->{rowcount} - 1) {
1070 if ($form->{"partnumber_$i"}) {
1074 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1077 if ($form->{"licensenumber_$i"} == -1) {
1085 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
1086 $form->{rowcount} = $count;
1088 $form->{creditremaining} -= &invoicetotal;
1095 if ( $form->{type} =~ (/sales_quotation/)
1096 or (($form->{level} =~ /Sales/) and ($form->{type} =~ /invoice/))
1097 or (($form->{level} eq undef) and ($form->{type} =~ /invoice/))
1098 or ($form->{type} =~ /sales_order/)) {
1100 # get pricegroups for parts
1101 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1103 # build up html code for prices_$i
1104 set_pricegroup($form->{rowcount});
1110 $lxdebug->leave_sub();
1114 $lxdebug->enter_sub();
1116 $form->{oldinvtotal} = 0;
1118 # add all parts and deduct paid
1119 map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
1121 my ($amount, $sellprice, $discount, $qty);
1123 for my $i (1 .. $form->{rowcount}) {
1124 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1125 $discount = $form->parse_amount(\%myconfig, $form->{"discount_$i"});
1126 $qty = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
1128 #($form->{"sellprice_$i"}, $form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
1130 $amount = $sellprice * (1 - $discount / 100) * $qty;
1131 map { $form->{"${_}_base"} += $amount }
1132 (split (/ /, $form->{"taxaccounts_$i"}));
1133 $form->{oldinvtotal} += $amount;
1136 map { $form->{oldinvtotal} += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1137 split(/ /, $form->{taxaccounts})
1138 if !$form->{taxincluded};
1140 $form->{oldtotalpaid} = 0;
1141 for $i (1 .. $form->{paidaccounts}) {
1142 $form->{oldtotalpaid} += $form->{"paid_$i"};
1145 $lxdebug->leave_sub();
1148 return ($form->{oldinvtotal} - $form->{oldtotalpaid});
1151 sub validate_items {
1152 $lxdebug->enter_sub();
1154 # check if items are valid
1155 if ($form->{rowcount} == 1) {
1160 for $i (1 .. $form->{rowcount} - 1) {
1161 $form->isblank("partnumber_$i",
1162 $locale->text('Number missing in Row') . " $i");
1165 $lxdebug->leave_sub();
1169 $lxdebug->enter_sub();
1170 if ($form->{second_run}) {
1171 $form->{print_and_post} = 0;
1173 $form->{ordnumber} = $form->{invnumber};
1175 $form->{old_employee_id} = $form->{employee_id};
1176 $form->{old_salesman_id} = $form->{salesman_id};
1178 map { delete $form->{$_} } qw(id printed emailed queued);
1179 if ($form->{script} eq 'ir.pl' || $form->{type} eq 'request_quotation') {
1180 $form->{title} = $locale->text('Add Purchase Order');
1181 $form->{vc} = 'vendor';
1182 $form->{type} = 'purchase_order';
1185 if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_quotation') {
1186 $form->{title} = $locale->text('Add Sales Order');
1187 $form->{vc} = 'customer';
1188 $form->{type} = 'sales_order';
1191 $form->{script} = 'oe.pl';
1193 $form->{shipto} = 1;
1195 $form->{rowcount}--;
1197 $form->{cp_id} *= 1;
1199 require "bin/mozilla/$form->{script}";
1200 my $script = $form->{"script"};
1202 $script =~ s|.pl$||;
1203 $locale = new Locale($language, $script);
1205 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1207 $currency = $form->{currency};
1211 $form->{currency} = $currency;
1212 $form->{exchangerate} = "";
1213 $form->{forex} = "";
1214 $form->{exchangerate} = $exchangerate
1218 $form->check_exchangerate(
1219 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1222 for $i (1 .. $form->{rowcount}) {
1223 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
1224 $form->{"${_}_${i}"})
1225 if ($form->{"${_}_${i}"}) }
1226 qw(ship qty sellprice listprice basefactor));
1232 $lxdebug->leave_sub();
1236 $lxdebug->enter_sub();
1237 if ($form->{second_run}) {
1238 $form->{print_and_post} = 0;
1240 map { delete $form->{$_} } qw(id printed emailed queued);
1242 if ($form->{script} eq 'ir.pl' || $form->{type} eq 'purchase_order') {
1243 $form->{title} = $locale->text('Add Request for Quotation');
1244 $form->{vc} = 'vendor';
1245 $form->{type} = 'request_quotation';
1248 if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_order') {
1249 $form->{title} = $locale->text('Add Quotation');
1250 $form->{vc} = 'customer';
1251 $form->{type} = 'sales_quotation';
1255 $form->{cp_id} *= 1;
1257 $form->{script} = 'oe.pl';
1259 $form->{shipto} = 1;
1261 $form->{rowcount}--;
1263 require "bin/mozilla/$form->{script}";
1265 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1267 $currency = $form->{currency};
1271 $form->{currency} = $currency;
1272 $form->{exchangerate} = "";
1273 $form->{forex} = "";
1274 $form->{exchangerate} = $exchangerate
1278 $form->check_exchangerate(
1279 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1282 for $i (1 .. $form->{rowcount}) {
1283 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
1284 $form->{"${_}_${i}"})
1285 if ($form->{"${_}_${i}"}) }
1286 qw(ship qty sellprice listprice basefactor));
1292 $lxdebug->leave_sub();
1295 sub request_for_quotation {
1300 $lxdebug->enter_sub();
1301 if ($form->{second_run}) {
1302 $form->{print_and_post} = 0;
1303 $form->{resubmit} = 0;
1306 $form->{email} = $form->{shiptoemail} if $form->{shiptoemail} && $form->{formname} =~ /(pick|packing|bin)_list/;
1308 if ($form->{"cp_id"} && !$form->{"email"}) {
1309 CT->get_contact(\%myconfig, $form);
1310 $form->{"email"} = $form->{"cp_email"};
1313 $form->{ $form->{vc} } =~ /--/;
1314 $title = $locale->text('E-mail') . " $`";
1316 $form->{oldmedia} = $form->{media};
1317 $form->{media} = "email";
1319 my $attachment_filename = $form->generate_attachment_filename();
1321 $form->{"fokus"} = $form->{"email"} ? "Form.subject" : "Form.email";
1324 my (@dont_hide_key_list, %dont_hide_key, @hidden_keys);
1325 @dont_hide_key_list = qw(action email cc bcc subject message formname sendmode format header override);
1326 @dont_hide_key{@dont_hide_key_list} = (1) x @dont_hide_key_list;
1327 @hidden_keys = grep { !$dont_hide_key{$_} } grep { !ref $form->{$_} } keys %$form;
1329 print $form->parse_html_template('generic/edit_email',
1331 a_filename => $attachment_filename,
1332 _print_options_ => print_options({ 'inline' => 1 }),
1333 HIDDEN => [ map +{ name => $_, value => $form->{$_} }, @hidden_keys ],
1334 SHOW_BCC => $myconfig{role} eq 'admin' });
1336 $lxdebug->leave_sub();
1340 $lxdebug->enter_sub();
1342 my $callback = $form->{script} . "?action=edit";
1343 map({ $callback .= "\&${_}=" . E($form->{$_}); }
1344 qw(login password type id));
1346 print_form("return");
1348 $form->{callback} = $callback;
1351 $lxdebug->leave_sub();
1354 # generate the printing options displayed at the bottom of oe and is forms.
1355 # this function will attempt to guess what type of form is displayed, and will generate according options
1358 # this version builds the arrays of options pretty directly. if you have trouble understanding how,
1359 # the opthash function builds hashrefs which are then pieced together for the template arrays.
1360 # unneeded options are "undef"ed out, and then grepped out.
1362 # the inline options is untested, but intended to be used later in metatemplating
1364 $lxdebug->enter_sub();
1370 # names 3 parameters and returns a hashref, for use in templates
1371 sub opthash { +{ value => shift, selected => shift, oname => shift } }
1372 (@FORMNAME, @FORMNAME, @LANGUAGE_ID, @FORMAT, @SENDMODE, @MEDIA, @PRINTER_ID, @SELECTS) = ();
1374 # note: "||"-selection is only correct for values where "0" is _not_ a correct entry
1375 $form->{sendmode} = "attachment";
1376 $form->{format} = $form->{format} || $myconfig{template_format} || "pdf";
1377 $form->{copies} = $form->{copies} || $myconfig{copies} || 3;
1378 $form->{media} = $form->{media} || $myconfig{default_media} || "screen";
1379 $form->{printer_id} = defined $form->{printer_id} ? $form->{printer_id} :
1380 defined $myconfig{default_printer_id} ? $myconfig{default_printer_id} : "";
1382 $form->{PD}{ $form->{formname} } = "selected";
1383 $form->{DF}{ $form->{format} } = "selected";
1384 $form->{OP}{ $form->{media} } = "selected";
1385 $form->{SM}{ $form->{formname} } = "selected";
1387 push @FORMNAME, grep $_,
1388 ($form->{type} eq 'purchase_order') ? (
1389 opthash("purchase_order", $form->{PD}{purchase_order}, $locale->text('Purchase Order')),
1390 opthash("bin_list", $form->{PD}{bin_list}, $locale->text('Bin List'))
1392 ($form->{type} eq 'credit_note') ?
1393 opthash("credit_note", $form->{PD}{credit_note}, $locale->text('Credit Note')) : undef,
1394 ($form->{type} eq 'sales_order') ? (
1395 opthash("sales_order", $form->{PD}{sales_order}, $locale->text('Confirmation')),
1396 opthash("proforma", $form->{PD}{proforma}, $locale->text('Proforma Invoice')),
1397 opthash("pick_list", $form->{PD}{pick_list}, $locale->text('Pick List')),
1398 opthash("packing_list", $form->{PD}{packing_list}, $locale->text('Packing List'))
1400 ($form->{type} =~ /_quotation$/) ?
1401 opthash("$`_quotation", $form->{PD}{"$`_quotation"}, $locale->text('Quotation')) : undef,
1402 ($form->{type} eq 'invoice') ? (
1403 opthash("invoice", $form->{PD}{invoice}, $locale->text('Invoice')),
1404 opthash("proforma", $form->{PD}{proforma}, $locale->text('Proforma Invoice')),
1405 opthash("packing_list", $form->{PD}{packing_list}, $locale->text('Packing List'))
1407 ($form->{type} eq 'invoice' && $form->{storno}) ? (
1408 opthash("storno_invoice", $form->{PD}{storno_invoice}, $locale->text('Storno Invoice')),
1409 opthash("storno_packing_list", $form->{PD}{storno_packing_list}, $locale->text('Storno Packing List'))
1411 ($form->{type} eq 'credit_note') ?
1412 opthash("credit_note", $form->{PD}{credit_note}, $locale->text('Credit Note')) : undef;
1415 opthash("attachment", $form->{SM}{attachment}, $locale->text('Attachment')),
1416 opthash("inline", $form->{SM}{inline}, $locale->text('In-line'))
1417 if ($form->{media} eq 'email');
1419 push @MEDIA, grep $_,
1420 opthash("screen", $form->{OP}{screen}, $locale->text('Screen')),
1421 (scalar @{ $form->{printers} } && $latex_templates) ?
1422 opthash("printer", $form->{OP}{printer}, $locale->text('Printer')) : undef,
1423 ($latex_templates && !$options->{no_queue}) ?
1424 opthash("queue", $form->{OP}{queue}, $locale->text('Queue')) : undef
1425 if ($form->{media} ne 'email');
1427 push @FORMAT, grep $_,
1428 ($opendocument_templates && $openofficeorg_writer_bin && $xvfb_bin && (-x $openofficeorg_writer_bin) && (-x $xvfb_bin)
1429 && !$options->{no_opendocument_pdf}) ?
1430 opthash("opendocument_pdf", $form->{DF}{"opendocument_pdf"}, $locale->text("PDF (OpenDocument/OASIS)")) : undef,
1431 ($latex_templates) ?
1432 opthash("pdf", $form->{DF}{pdf}, $locale->text('PDF')) : undef,
1433 ($latex_templates && !$options->{no_postscript}) ?
1434 opthash("postscript", $form->{DF}{postscript}, $locale->text('Postscript')) : undef,
1435 (!$options->{no_html}) ?
1436 opthash("html", $form->{DF}{html}, "HTML") : undef,
1437 ($opendocument_templates && !$options->{no_opendocument}) ?
1438 opthash("opendocument", $form->{DF}{opendocument}, $locale->text("OpenDocument/OASIS")) : undef;
1441 map { opthash($_->{id}, ($_->{id} eq $form->{language} ? 'selected' : ''), $_->{description}) } +{}, @{ $form->{languages} }
1442 if (ref $form->{languages} eq 'ARRAY');
1445 map { opthash($_->{id}, ($_->{id} eq $form->{printer_id} ? 'selected' : ''), $_->{printer_description}) } +{}, @{ $form->{printers} }
1446 if ((ref $form->{printers} eq 'ARRAY') && scalar @{ $form->{printers } });
1448 @SELECTS = map { sname => lc $_, DATA => \@$_, show => scalar @$_ }, qw(FORMNAME LANGUAGE_ID FORMAT SENDMODE MEDIA PRINTER_ID);
1450 my %dont_display_groupitems = (
1455 display_copies => scalar @{ $form->{printers} } && $latex_templates && $form->{media} ne 'email',
1456 display_remove_draft => (!$form->{id} && $form->{draft_id}),
1457 display_groupitems => !$dont_display_groupitems{$form->{type}},
1458 groupitems_checked => $form->{groupitems} ? "checked" : '',
1459 remove_draft_checked => $form->{remove_draft} ? "checked" : ''
1462 my $print_options = $form->parse_html_template("generic/print_options", { SELECTS => \@SELECTS, %template_vars } );
1464 if ($options->{inline}) {
1465 $lxdebug->leave_sub() and return $print_options;
1467 print $print_options; $lxdebug->leave_sub();
1472 $lxdebug->enter_sub();
1474 if ($form->{print_nextsub}) {
1475 call_sub($form->{print_nextsub});
1476 $lxdebug->leave_sub();
1480 # if this goes to the printer pass through
1481 if ($form->{media} eq 'printer' || $form->{media} eq 'queue') {
1482 $form->error($locale->text('Select postscript or PDF!'))
1483 if ($form->{format} !~ /(postscript|pdf)/);
1485 $old_form = new Form;
1486 map { $old_form->{$_} = $form->{$_} } keys %$form;
1489 if (!$form->{id} || (($form->{formname} eq "proforma") && !$form->{proforma} && (($form->{type} =~ /_order$/) || ($form->{type} =~ /_quotation$/)))) {
1490 if ($form->{formname} eq "proforma") {
1491 $form->{proforma} = 1;
1493 $form->{print_and_save} = 1;
1494 my $formname = $form->{formname};
1496 $form->{formname} = $formname;
1501 &print_form($old_form);
1503 $lxdebug->leave_sub();
1507 $lxdebug->enter_sub();
1508 my ($old_form) = @_;
1512 $numberfld = "invnumber";
1515 ($form->{display_form}) ? $form->{display_form} : "display_form";
1517 # $form->{"notes"} will be overridden by the customer's/vendor's "notes" field. So save it here.
1518 $form->{ $form->{"formname"} . "notes" } = $form->{"notes"};
1520 if ($form->{formname} eq "invoice") {
1521 $form->{label} = $locale->text('Invoice');
1523 if ($form->{formname} eq "packing_list") {
1525 # this is from an invoice
1526 $form->{label} = $locale->text('Packing List');
1528 if ($form->{formname} eq 'sales_order') {
1531 $form->{"${inv}date"} = $form->{transdate};
1532 $form->{label} = $locale->text('Sales Order');
1533 $numberfld = "sonumber";
1537 if (($form->{type} eq 'invoice') && ($form->{formname} eq 'proforma') ) {
1540 $form->{"${inv}date"} = $form->{invdate};
1541 $form->{label} = $locale->text('Proforma Invoice');
1542 $numberfld = "sonumber";
1546 if (($form->{type} eq 'sales_order') && ($form->{formname} eq 'proforma') ) {
1549 $form->{"${inv}date"} = $form->{transdate};
1550 $form->{"invdate"} = $form->{transdate};
1551 $form->{invnumber} = $form->{ordnumber};
1552 $form->{label} = $locale->text('Proforma Invoice');
1553 $numberfld = "sonumber";
1557 if ($form->{formname} eq 'packing_list' && $form->{type} ne 'invoice') {
1559 # we use the same packing list as from an invoice
1562 $form->{invdate} = $form->{"${inv}date"} = $form->{transdate};
1563 $form->{label} = $locale->text('Packing List');
1565 # set invnumber for template packing_list
1566 $form->{invnumber} = $form->{ordnumber};
1568 if ($form->{formname} eq 'pick_list') {
1571 $form->{"${inv}date"} =
1572 ($form->{transdate}) ? $form->{transdate} : $form->{invdate};
1573 $form->{label} = $locale->text('Pick List');
1574 $order = 1 unless $form->{type} eq 'invoice';
1576 if ($form->{formname} eq 'purchase_order') {
1579 $form->{"${inv}date"} = $form->{transdate};
1580 $form->{label} = $locale->text('Purchase Order');
1581 $numberfld = "ponumber";
1584 if ($form->{formname} eq 'bin_list') {
1587 $form->{"${inv}date"} = $form->{transdate};
1588 $form->{label} = $locale->text('Bin List');
1591 if ($form->{formname} eq 'sales_quotation') {
1594 $form->{"${inv}date"} = $form->{transdate};
1595 $form->{label} = $locale->text('Quotation');
1596 $numberfld = "sqnumber";
1600 if (($form->{type} eq 'sales_quotation') && ($form->{formname} eq 'proforma') ) {
1603 $form->{"${inv}date"} = $form->{transdate};
1604 $form->{"invdate"} = $form->{transdate};
1605 $form->{label} = $locale->text('Proforma Invoice');
1606 $numberfld = "sqnumber";
1610 if ($form->{formname} eq 'request_quotation') {
1613 $form->{"${inv}date"} = $form->{transdate};
1614 $form->{label} = $locale->text('Quotation');
1615 $numberfld = "rfqnumber";
1619 $form->isblank("email", $locale->text('E-mail address missing!'))
1620 if ($form->{media} eq 'email');
1621 $form->isblank("${inv}date",
1622 $locale->text($form->{label})
1624 . $locale->text(' Date missing!'));
1626 # $locale->text('Invoice Number missing!')
1627 # $locale->text('Invoice Date missing!')
1628 # $locale->text('Packing List Number missing!')
1629 # $locale->text('Packing List Date missing!')
1630 # $locale->text('Order Number missing!')
1631 # $locale->text('Order Date missing!')
1632 # $locale->text('Quotation Number missing!')
1633 # $locale->text('Quotation Date missing!')
1636 $form->{what_done} = $form->{formname};
1637 if (!$form->{"${inv}number"} && !$form->{preview} && !$form->{id}) {
1638 $form->{"${inv}number"} = $form->update_defaults(\%myconfig, $numberfld);
1639 if ($form->{media} ne 'email') {
1641 # get pricegroups for parts
1642 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1644 # build up html code for prices_$i
1645 set_pricegroup($form->{rowcount});
1647 $form->{rowcount}--;
1649 call_sub($display_form);
1650 # saving the history
1651 if(!exists $form->{addition}) {
1652 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1653 $form->{addition} = "PRINTED";
1654 $form->save_history($form->dbconnect(\%myconfig));
1656 # /saving the history
1663 # Save the email address given in the form because it should override the setting saved for the customer/vendor.
1664 my ($saved_email, $saved_cc, $saved_bcc) =
1665 ($form->{"email"}, $form->{"cc"}, $form->{"bcc"});
1667 $language_saved = $form->{language_id};
1668 $payment_id_saved = $form->{payment_id};
1669 $salesman_id_saved = $form->{salesman_id};
1670 $cp_id_saved = $form->{cp_id};
1672 call_sub("$form->{vc}_details");
1674 $form->{language_id} = $language_saved;
1675 $form->{payment_id} = $payment_id_saved;
1677 $form->{"email"} = $saved_email if ($saved_email);
1678 $form->{"cc"} = $saved_cc if ($saved_cc);
1679 $form->{"bcc"} = $saved_bcc if ($saved_bcc);
1681 if (!$cp_id_saved) {
1682 # No contact was selected. Delete all contact variables because
1683 # IS->customer_details() and IR->vendor_details() get the default
1685 map({ delete($form->{$_}); } grep(/^cp_/, keys(%{ $form })));
1688 my ($language_tc, $output_numberformat, $output_dateformat, $output_longdates);
1689 if ($form->{"language_id"}) {
1690 ($language_tc, $output_numberformat, $output_dateformat, $output_longdates) =
1691 AM->get_language_details(\%myconfig, $form, $form->{language_id});
1693 $output_dateformat = $myconfig{"dateformat"};
1694 $output_numberformat = $myconfig{"numberformat"};
1695 $output_longdates = 1;
1698 ($form->{employee}) = split /--/, $form->{employee};
1700 # create the form variables
1702 OE->order_details(\%myconfig, \%$form);
1704 IS->invoice_details(\%myconfig, \%$form, $locale);
1707 $form->get_salesman(\%myconfig, $salesman_id_saved);
1709 if ($form->{shipto_id}) {
1710 $form->get_shipto(\%myconfig);
1713 @a = qw(name street zipcode city country);
1717 # if there is no shipto fill it in from billto
1718 foreach $item (@a) {
1719 if ($form->{"shipto$item"}) {
1726 if ( $form->{formname} eq 'purchase_order'
1727 || $form->{formname} eq 'request_quotation') {
1728 $form->{shiptoname} = $myconfig{company};
1729 $form->{shiptostreet} = $myconfig{address};
1731 map { $form->{"shipto$_"} = $form->{$_} } @a;
1735 $form->{notes} =~ s/^\s+//g;
1737 $form->{templates} = "$myconfig{templates}";
1739 delete $form->{printer_command};
1741 $form->{language} = $form->get_template_language(\%myconfig);
1744 if ($form->{media} ne 'email') {
1745 $printer_code = $form->get_printer_code(\%myconfig);
1746 if ($printer_code ne "") {
1747 $printer_code = "_" . $printer_code;
1751 if ($form->{language} ne "") {
1752 map({ $form->{"unit"}->[$_] =
1753 AM->translate_units($form, $form->{"language"},
1754 $form->{"unit"}->[$_], $form->{"qty"}->[$_]); }
1755 (0..scalar(@{$form->{"unit"}}) - 1));
1756 $form->{language} = "_" . $form->{language};
1760 format_dates($output_dateformat, $output_longdates,
1761 qw(invdate orddate quodate pldate duedate reqdate transdate
1762 shippingdate deliverydate validitydate paymentdate
1763 datepaid transdate_oe deliverydate_oe
1764 employee_startdate employee_enddate
1766 grep({ /^datepaid_\d+$/ ||
1767 /^transdate_oe_\d+$/ ||
1768 /^deliverydate_oe_\d+$/ ||
1770 /^deliverydate_\d+$/ ||
1774 reformat_numbers($output_numberformat, 2,
1775 qw(invtotal ordtotal quototal subtotal linetotal
1776 listprice sellprice netprice discount
1777 tax taxbase total paid),
1778 grep({ /^linetotal_\d+$/ ||
1779 /^listprice_\d+$/ ||
1780 /^sellprice_\d+$/ ||
1790 reformat_numbers($output_numberformat, undef,
1795 $form->{IN} = "$form->{formname}$form->{language}${printer_code}.html";
1796 if ($form->{format} eq 'postscript') {
1797 $form->{postscript} = 1;
1798 $form->{IN} =~ s/html$/tex/;
1799 } elsif ($form->{"format"} =~ /pdf/) {
1801 if ($form->{"format"} =~ /opendocument/) {
1802 $form->{IN} =~ s/html$/odt/;
1804 $form->{IN} =~ s/html$/tex/;
1806 } elsif ($form->{"format"} =~ /opendocument/) {
1807 $form->{"opendocument"} = 1;
1808 $form->{"IN"} =~ s/html$/odt/;
1811 delete $form->{OUT};
1813 if ($form->{media} eq 'printer') {
1814 $form->{OUT} = "| $form->{printer_command} &>/dev/null";
1815 $form->{printed} .= " $form->{formname}";
1816 $form->{printed} =~ s/^ //;
1818 $printed = $form->{printed};
1820 if ($form->{media} eq 'email') {
1821 $form->{subject} = qq|$form->{label} $form->{"${inv}number"}|
1822 unless $form->{subject};
1824 $form->{emailed} .= " $form->{formname}";
1825 $form->{emailed} =~ s/^ //;
1827 $emailed = $form->{emailed};
1829 if ($form->{media} eq 'queue') {
1830 %queued = map { s|.*/|| } split / /, $form->{queued};
1832 if ($filename = $queued{ $form->{formname} }) {
1833 $form->{queued} =~ s/$form->{formname} $filename//;
1834 unlink "$spool/$filename";
1835 $filename =~ s/\..*$//g;
1841 $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
1842 $form->{OUT} = ">$spool/$filename";
1845 $form->{queued} .= " $form->{formname} $filename";
1847 $form->{queued} =~ s/^ //;
1849 $queued = $form->{queued};
1851 # saving the history
1852 if(!exists $form->{addition}) {
1853 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1854 if($form->{media} =~ /printer/) {
1855 $form->{addition} = "PRINTED";
1857 elsif($form->{media} =~ /email/) {
1858 $form->{addition} = "MAILED";
1860 elsif($form->{media} =~ /queue/) {
1861 $form->{addition} = "QUEUED";
1863 elsif($form->{media} =~ /screen/) {
1864 $form->{addition} = "SCREENED";
1866 $form->save_history($form->dbconnect(\%myconfig));
1868 # /saving the history
1870 $form->parse_template(\%myconfig, $userspath);
1872 $form->{callback} = "";
1874 if ($form->{media} eq 'email') {
1875 $form->{message} = $locale->text('sent') unless $form->{message};
1877 $message = $form->{message};
1879 # if we got back here restore the previous form
1880 if ($form->{media} =~ /(printer|email|queue)/) {
1882 $form->update_status(\%myconfig)
1883 if ($form->{media} eq 'queue' && $form->{id});
1885 return $lxdebug->leave_sub() if ($old_form eq "return");
1889 $old_form->{"${inv}number"} = $form->{"${inv}number"};
1891 # restore and display form
1892 map { $form->{$_} = $old_form->{$_} } keys %$old_form;
1894 $form->{queued} = $queued;
1895 $form->{printed} = $printed;
1896 $form->{emailed} = $emailed;
1897 $form->{message} = $message;
1899 $form->{rowcount}--;
1900 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1901 qw(exchangerate creditlimit creditremaining);
1903 for $i (1 .. $form->{paidaccounts}) {
1905 $form->{"${_}_$i"} =
1906 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
1907 } qw(paid exchangerate);
1910 call_sub($display_form);
1915 ($form->{media} eq 'printer')
1916 ? $locale->text('sent to printer')
1917 : $locale->text('emailed to') . " $form->{email}";
1918 $form->redirect(qq|$form->{label} $form->{"${inv}number"} $msg|);
1920 if ($form->{printing}) {
1921 call_sub($display_form);
1925 $lxdebug->leave_sub();
1928 sub customer_details {
1929 $lxdebug->enter_sub();
1930 IS->customer_details(\%myconfig, \%$form, @_);
1931 $lxdebug->leave_sub();
1934 sub vendor_details {
1935 $lxdebug->enter_sub();
1937 IR->vendor_details(\%myconfig, \%$form, @_);
1939 $lxdebug->leave_sub();
1943 $lxdebug->enter_sub();
1945 $form->{postasnew} = 1;
1946 map { delete $form->{$_} } qw(printed emailed queued);
1950 $lxdebug->leave_sub();
1954 $lxdebug->enter_sub();
1955 if ($form->{second_run}) {
1956 $form->{print_and_post} = 0;
1959 $title = $form->{title};
1960 $form->{title} = $locale->text('Ship to');
1962 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1963 qw(exchangerate creditlimit creditremaining);
1966 qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry
1967 shiptocontact shiptophone shiptofax shiptoemail
1968 shiptodepartment_1 shiptodepartment_2);
1971 (qw(name department_1 department_2 street zipcode city country
1972 contact email phone fax));
1974 # get details for name
1975 call_sub("$form->{vc}_details", @addr_vars);
1978 ($form->{vc} eq 'customer')
1979 ? $locale->text('Customer Number')
1980 : $locale->text('Vendor Number');
1982 # get pricegroups for parts
1983 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1985 # build up html code for prices_$i
1986 set_pricegroup($form->{rowcount});
1988 $nextsub = ($form->{display_form}) ? $form->{display_form} : "display_form";
1990 $form->{rowcount}--;
1997 <form method="post" action="$form->{script}">
1999 <table width="100%">
2003 <tr class="listheading">
2004 <th class="listheading" colspan="2" width="50%">|
2005 . $locale->text('Billing Address') . qq|</th>
2006 <th class="listheading" width="50%">|
2007 . $locale->text('Shipping Address') . qq|</th>
2009 <tr height="5"></tr>
2011 <th align="right" nowrap>$number</th>
2012 <td>$form->{"$form->{vc}number"}</td>
2015 <th align="right" nowrap>| . $locale->text('Company Name') . qq|</th>
2016 <td>$form->{name}</td>
2017 <td><input name="shiptoname" size="35" value="$form->{shiptoname}"></td>
2020 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
2021 <td>$form->{department_1}</td>
2022 <td><input name="shiptodepartment_1" size="35" value="$form->{shiptodepartment_1}"></td>
2025 <th align="right" nowrap> </th>
2026 <td>$form->{department_2}</td>
2027 <td><input name="shiptodepartment_2" size="35" value="$form->{shiptodepartment_2}"></td>
2030 <th align="right" nowrap>| . $locale->text('Street') . qq|</th>
2031 <td>$form->{street}</td>
2032 <td><input name="shiptostreet" size="35" value="$form->{shiptostreet}"></td>
2035 <th align="right" nowrap>| . $locale->text('Zipcode') . qq|</th>
2036 <td>$form->{zipcode}</td>
2037 <td><input name="shiptozipcode" size="35" value="$form->{shiptozipcode}"></td>
2040 <th align="right" nowrap>| . $locale->text('City') . qq|</th>
2041 <td>$form->{city}</td>
2042 <td><input name="shiptocity" size="35" value="$form->{shiptocity}"></td>
2045 <th align="right" nowrap>| . $locale->text('Country') . qq|</th>
2046 <td>$form->{country}</td>
2047 <td><input name="shiptocountry" size="35" value="$form->{shiptocountry}"></td>
2050 <th align="right" nowrap>| . $locale->text('Contact') . qq|</th>
2051 <td>$form->{contact}</td>
2052 <td><input name="shiptocontact" size="35" value="$form->{shiptocontact}"></td>
2055 <th align="right" nowrap>| . $locale->text('Phone') . qq|</th>
2056 <td>$form->{phone}</td>
2057 <td><input name="shiptophone" size="20" value="$form->{shiptophone}"></td>
2060 <th align="right" nowrap>| . $locale->text('Fax') . qq|</th>
2061 <td>$form->{fax}</td>
2062 <td><input name="shiptofax" size="20" value="$form->{shiptofax}"></td>
2065 <th align="right" nowrap>| . $locale->text('E-mail') . qq|</th>
2066 <td>$form->{email}</td>
2067 <td><input name="shiptoemail" size="35" value="$form->{shiptoemail}"></td>
2073 | . $cgi->hidden("-name" => "nextsub", "-value" => $nextsub);
2079 map({ delete $form->{$_} } (@shipto_vars, qw(header)));
2080 $form->{title} = $title;
2082 foreach $key (keys %$form) {
2083 $form->{$key} =~ s/\"/"/g;
2084 print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
2089 <hr size="3" noshade>
2092 <input class="submit" type="submit" name="action" value="|
2093 . $locale->text('Continue') . qq|">
2100 $lxdebug->leave_sub();
2104 $lxdebug->enter_sub();
2109 $form->{old_callback} = $form->escape($form->{callback}, 1);
2110 $form->{callback} = $form->escape("$form->{script}?action=display_form", 1);
2111 $form->{old_callback} = $form->escape($form->{old_callback}, 1);
2114 delete $form->{action};
2115 $customer = $form->{customer};
2116 map { $form->{"old_$_"} = $form->{"${_}_$row"} } qw(partnumber description);
2118 # save all other form variables in a previousform variable
2119 $form->{row} = $row;
2120 foreach $key (keys %$form) {
2123 $form->{$key} =~ s/&/%26/g;
2124 $previousform .= qq|$key=$form->{$key}&|;
2127 $previousform = $form->escape($previousform, 1);
2129 $form->{script} = "licenses.pl";
2131 map { $form->{$_} = $form->{"old_$_"} } qw(partnumber description);
2132 map { $form->{$_} = $form->escape($form->{$_}, 1) }
2133 qw(partnumber description);
2135 qq|$form->{script}?login=$form->{login}&password=$form->{password}&action=add&vc=$form->{db}&$form->{db}_id=$form->{id}&$form->{db}=$name&type=$form->{type}&customer=$customer&partnumber=$form->{partnumber}&description=$form->{description}&previousform="$previousform"&initial=1|;
2138 $lxdebug->leave_sub();
2141 sub relink_accounts {
2142 $lxdebug->enter_sub();
2144 $form->{"taxaccounts"} =~ s/\s*$//;
2145 $form->{"taxaccounts"} =~ s/^\s*//;
2146 foreach my $accno (split(/\s*/, $form->{"taxaccounts"})) {
2147 map({ delete($form->{"${accno}_${_}"}); } qw(rate description taxnumber));
2149 $form->{"taxaccounts"} = "";
2151 for (my $i = 1; $i <= $form->{"rowcount"}; $i++) {
2152 if ($form->{"id_$i"}) {
2153 IC->retrieve_accounts(\%myconfig, $form, $form->{"id_$i"}, $i, 1);
2157 $lxdebug->leave_sub();
2161 $lxdebug->enter_sub();
2163 $form->get_duedate(\%myconfig);
2166 $result = "$form->{duedate}";
2169 $lxdebug->leave_sub();