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 "$form->{path}/common.pl";
43 # any custom scripts for this one
44 if (-f "$form->{path}/custom_io.pl") {
45 eval { require "$form->{path}/custom_io.pl"; };
47 if (-f "$form->{path}/$form->{login}_io.pl") {
48 eval { require "$form->{path}/$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 my %projectnumber_labels = ();
245 my @projectnumber_values = ("");
246 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
247 push(@projectnumber_values, $item->{"id"});
248 $projectnumber_labels{$item->{"id"}} = $item->{"projectnumber"};
251 for $i (1 .. $numrows) {
256 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
257 } qw(qty ship discount sellprice price_new price_old) unless ($form->{simple_save});
259 if (!$form->{"unit_old_$i"}) {
260 # Neue Ware aus der Datenbank. In diesem Fall ist unit_$i die
261 # Einheit, wie sie in den Stammdaten hinterlegt wurde.
262 # Es sollte also angenommen werden, dass diese ausgewaehlt war.
263 $form->{"unit_old_$i"} = $form->{"unit_$i"};
266 # Die zuletzt ausgewaehlte mit der aktuell ausgewaehlten Einheit
267 # vergleichen und bei Unterschied den Preis entsprechend umrechnen.
268 $form->{"selected_unit_$i"} = $form->{"unit_$i"} unless ($form->{"selected_unit_$i"});
270 my $check_units = $form->{"inventory_accno_$i"} ? $dimension_units : $service_units;
271 if (!$check_units->{$form->{"selected_unit_$i"}} ||
272 ($check_units->{$form->{"selected_unit_$i"}}->{"base_unit"} ne
273 $all_units->{$form->{"unit_old_$i"}}->{"base_unit"})) {
274 # Die ausgewaehlte Einheit ist fuer diesen Artikel nicht gueltig
275 # (z.B. Dimensionseinheit war ausgewaehlt, es handelt sich aber
276 # um eine Dienstleistung). Dann keinerlei Umrechnung vornehmen.
277 $form->{"unit_old_$i"} = $form->{"selected_unit_$i"} = $form->{"unit_$i"};
279 if ((!$form->{"prices_$i"}) || ($form->{"new_pricegroup_$i"} == $form->{"old_pricegroup_$i"})) {
280 if ($form->{"unit_old_$i"} ne $form->{"selected_unit_$i"}) {
282 if (defined($all_units->{$form->{"unit_old_$i"}}->{"factor"}) &&
283 $all_units->{$form->{"unit_old_$i"}}->{"factor"}) {
284 $basefactor = $all_units->{$form->{"selected_unit_$i"}}->{"factor"} /
285 $all_units->{$form->{"unit_old_$i"}}->{"factor"};
287 $form->{"sellprice_$i"} *= $basefactor;
288 $form->{"unit_old_$i"} = $form->{"selected_unit_$i"};
291 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
293 $decimalplaces = ($dec > 2) ? $dec : 2;
297 $form->{"sellprice_$i"} * $form->{"discount_$i"} / 100,
301 $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
302 $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
304 # convert " to "
305 map { $form->{"${_}_$i"} =~ s/\"/"/g }
306 qw(partnumber description unit unit_old);
308 ########################################
309 # Eintrag fuer Version 2.2.0 geaendert #
310 # neue Optik im Rechnungsformular #
311 ########################################
312 $column_data{runningnumber} =
313 qq|<td><input name="runningnumber_$i" size="5" value="$i"></td>|; # HuT
314 ############## ENDE Neueintrag ##################
316 $column_data{partnumber} =
317 qq|<td><input name="partnumber_$i" size=12 value="$form->{"partnumber_$i"}"></td>|;
319 if (($rows = $form->numtextrows($form->{"description_$i"}, 30, 6)) > 1) {
320 $column_data{description} =
321 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>|;
323 $column_data{description} =
324 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>|;
327 (my $qty_dec) = ($form->{"qty_$i"} =~ /\.(\d+)/);
328 $qty_dec = length $qty_dec;
331 qq|<td align="right"><input name="qty_$i" size="5" value="|
332 . $form->format_amount(\%myconfig, $form->{"qty_$i"}, $qty_dec) .qq|">|;
333 if ($form->{"formel_$i"}) {
334 $column_data{qty} .= qq|<button type="button" onclick="calculate_qty_selection_window('qty_$i','alu_$i', 'formel_$i', $i)">| . $locale->text('*/') . qq|</button>| .
335 $cgi->hidden("-name" => "formel_$i", "-value" => $form->{"formel_$i"}) . $cgi->hidden("-name" => "alu_$i", "-value" => $form->{"alu_$i"}). qq|</td>|;
338 qq|<td align="right"><input name="ship_$i" size=5 value="|
339 . $form->format_amount(\%myconfig, $form->{"ship_$i"})
342 my $is_part = $form->{"inventory_accno_$i"};
343 my $is_assembly = $form->{"assembly_$i"};
344 my $is_assigned = $form->{"id_$i"};
345 my $this_unit = $form->{"unit_$i"};
346 if ($form->{"selected_unit_$i"} && $this_unit &&
347 $all_units->{$form->{"selected_unit_$i"}} && $all_units->{$this_unit} &&
348 ($all_units->{$form->{"selected_unit_$i"}}->{"base_unit"} eq $all_units->{$this_unit}->{"base_unit"})) {
349 $this_unit = $form->{"selected_unit_$i"};
350 } elsif (!$is_assigned ||
351 ($is_part && !$this_unit && ($all_units->{$this_unit} && ($all_units->{$this_unit}->{"base_unit"} eq $all_units->{"kg"}->{"base_unit"})))) {
355 $column_data{"unit"} = "<td>" .
356 AM->unit_select_html($is_part || $is_assembly ? $dimension_units :
357 $is_assigned ? $service_units : $all_units,
358 "unit_$i", $this_unit,
359 $is_assigned ? $form->{"unit_$i"} : undef)
362 # build in drop down list for pricesgroups
363 if ($form->{"prices_$i"}) {
364 if ($form->{"new_pricegroup_$i"} != $form->{"old_pricegroup_$i"}) {
365 $price_tmp = $form->format_amount(\%myconfig, $form->{"price_new_$i"}, $decimalplaces);
367 $price_tmp = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
370 $column_data{sellprice_pg} =
371 qq|<td align="right"><select name="sellprice_pg_$i">$form->{"prices_$i"}</select></td>|;
372 $column_data{sellprice} =
373 qq|<td><input name="sellprice_$i" size="10" value="$price_tmp"></td>|;
376 # for last row and report
377 # set pricegroup drop down list from report menu
378 if ($form->{"sellprice_$i"} != 0) {
380 qq|<option value="$form->{"sellprice_$i"}--$form->{"pricegroup_id_$i"}" selected>$form->{"pricegroup_$i"}</option>\n|;
382 $form->{"pricegroup_old_$i"} = $form->{"pricegroup_id_$i"};
384 $column_data{sellprice_pg} =
385 qq|<td align="right"><select name="sellprice_pg_$i">$prices</select></td>|;
390 $column_data{sellprice_pg} = qq|<td align="right"> </td>|;
393 $column_data{sellprice} =
394 qq|<td><input name="sellprice_$i" size="10" value="|
395 . $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
399 $column_data{discount} =
400 qq|<td align="right"><input name="discount_$i" size=3 value="|
401 . $form->format_amount(\%myconfig, $form->{"discount_$i"})
403 $column_data{linetotal} =
404 qq|<td align="right">|
405 . $form->format_amount(\%myconfig, $linetotal, 2)
407 $column_data{bin} = qq|<td>$form->{"bin_$i"}</td>|;
409 ########################################
410 # Eintrag fuer Version 2.2.0 geaendert #
411 # neue Optik im Rechnungsformular #
412 ########################################
413 # if ($lizenzen && $form->{type} eq "invoice" && $form->{vc} eq "customer") {
414 # $column_data{license} = qq|<td><select name="licensenumber_$i">$form->{"lizenzen_$i"}></select></td>|;
417 # if ($form->{type} !~ /_quotation/) {
418 # $column_data{serialnr} = qq|<td><input name="serialnumber_$i" size=10 value="$form->{"serialnumber_$i"}"></td>|;
421 # $column_data{projectnr} = qq|<td><input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}"></td>|;
422 ############## ENDE Neueintrag ##################
426 <tr valign="top" class="listrow$j">|;
428 map { print "\n$column_data{$_}" } @column_index;
431 $cgi->hidden("-name" => "unit_old_$i",
432 "-value" => $form->{"selected_unit_$i"})
434 $cgi->hidden("-name" => "price_new_$i",
435 "-value" => $form->format_amount(\%myconfig, $form->{"price_new_$i"}))
437 map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_}) . "\n"); }
438 ("orderitems_id_$i", "bo_$i", "pricegroup_old_$i", "price_old_$i",
439 "id_$i", "inventory_accno_$i", "bin_$i", "partsgroup_$i", "partnotes_$i",
440 "income_accno_$i", "expense_accno_$i", "listprice_$i", "assembly_$i",
441 "taxaccounts_$i", "ordnumber_$i", "transdate_$i", "cusordnumber_$i",
442 "longdescription_$i", "basefactor_$i"));
444 ########################################
445 # Eintrag fuer Version 2.2.0 geaendert #
446 # neue Optik im Rechnungsformular #
447 ########################################
450 'style="display:none;"' if (!$form->{"show_details"});
454 <tr class="listrow$j" $row_style_attr>
455 <td colspan="$colspan">
457 if ($lizenzen && $form->{type} eq "invoice" && $form->{vc} eq "customer") {
458 my $selected = $form->{"licensenumber_$i"};
460 $form->{"lizenzen_$i"} =~ s/ selected//g;
461 $form->{"lizenzen_$i"} =~
462 s/value="${selected}"\>/value="${selected}" selected\>/;
463 $lizenzen_quoted = $form->{"lizenzen_$i"};
464 $lizenzen_quoted =~ s/\"/"/g;
466 <b>Lizenz\#</b> <select name="licensenumber_$i" size="1">
467 $form->{"lizenzen_$i"}
469 <input type="hidden" name="lizenzen_$i" value="${lizenzen_quoted}">
472 if ($form->{type} !~ /_quotation/) {
474 <b>$serialnumber</b> <input name="serialnumber_$i" size="15" value="$form->{"serialnumber_$i"}">|;
477 print qq|<b>$projectnumber</b> | .
478 NTI($cgi->popup_menu('-name' => "project_id_$i",
479 '-values' => \@projectnumber_values,
480 '-labels' => \%projectnumber_labels,
481 '-default' => $form->{"project_id_$i"}));
483 if ($form->{type} eq 'invoice' or $form->{type} =~ /order/) {
485 ($form->{type} eq 'invoice')
487 : 'reqdate'; # invoice uses a different term for the same thing.
489 <b>${$reqdate_term}</b> <input name="${reqdate_term}_$i" size="11" value="$form->{"${reqdate_term}_$i"}">
492 my $subtotalchecked = ($form->{"subtotal_$i"}) ? "checked" : "";
494 <b>|.$locale->text('Subtotal').qq|</b> <input type="checkbox" name="subtotal_$i" value="1" "$subtotalchecked">
500 ############## ENDE Neueintrag ##################
502 map { $form->{"${_}_base"} += $linetotal }
503 (split(/ /, $form->{"taxaccounts_$i"}));
505 $form->{invsubtotal} += $linetotal;
514 $lxdebug->leave_sub();
517 ##################################################
518 # build html-code for pricegroups in variable $form->{prices_$j}
521 $lxdebug->enter_sub();
522 my $rowcount = shift;
523 for $j (1 .. $rowcount) {
524 my $pricegroup_old = $form->{"pricegroup_old_$i"};
525 if ($form->{PRICES}{$j}) {
527 $prices = '<option value="--">' . $locale->text("none (pricegroup)") . '</option>';
529 foreach $item (@{ $form->{PRICES}{$j} }) {
531 #$price = $form->round_amount($myconfig, $item->{price}, 5);
532 #$price = $form->format_amount($myconfig, $item->{price}, 2);
533 $price = $item->{price};
534 $pricegroup_id = $item->{pricegroup_id};
535 $pricegroup = $item->{pricegroup};
537 # build drop down list for pricegroups
539 qq|<option value="$price--$pricegroup_id"$item->{selected}>$pricegroup</option>\n|;
544 # $form->{"${_}_$j"} =
545 # $form->format_amount(\%myconfig, $form->{"${_}_$j"})
546 # } qw(sellprice price_new price_old);
548 # set new selectedpricegroup_id and prices for "Preis"
549 if ($item->{selected} && ($pricegroup_id != 0)) {
550 $form->{"pricegroup_old_$j"} = $pricegroup_id;
551 $form->{"price_new_$j"} = $price;
552 $form->{"sellprice_$j"} = $price;
554 if ($pricegroup_id == 0) {
555 $form->{"price_new_$j"} = $form->{"sellprice_$j"};
558 $form->{"prices_$j"} = $prices;
561 $lxdebug->leave_sub();
565 $lxdebug->enter_sub();
566 @column_index = qw(ndx partnumber description onhand unit sellprice);
568 $column_data{ndx} = qq|<th> </th>|;
569 $column_data{partnumber} =
570 qq|<th class="listheading">| . $locale->text('Number') . qq|</th>|;
571 $column_data{description} =
572 qq|<th class="listheading">| . $locale->text('Part Description') . qq|</th>|;
573 $column_data{sellprice} =
574 qq|<th class="listheading">| . $locale->text('Price') . qq|</th>|;
575 $column_data{onhand} =
576 qq|<th class="listheading">| . $locale->text('Qty') . qq|</th>|;
578 qq|<th class="listheading">| . $locale->text('Unit') . qq|</th>|;
579 # list items with radio button on a form
582 $title = $locale->text('Select from one of the items below');
583 $colspan = $#column_index + 1;
588 <form method="post" action="$form->{script}">
592 <th class="listtop" colspan="$colspan">$title</th>
595 <tr class="listheading">|;
597 map { print "\n$column_data{$_}" } @column_index;
602 foreach $ref (@{ $form->{item_list} }) {
603 $checked = ($i++) ? "" : "checked";
606 if ($ref->{inventory_accno} > 0) {
607 $ref->{"lizenzen"} = qq|<option></option>|;
608 foreach $item (@{ $form->{LIZENZEN}{ $ref->{"id"} } }) {
609 $ref->{"lizenzen"} .=
610 qq|<option value=\"$item->{"id"}\">$item->{"licensenumber"}</option>|;
612 $ref->{"lizenzen"} .= qq|<option value="-1">Neue Lizenz</option>|;
613 $ref->{"lizenzen"} =~ s/\"/"/g;
617 map { $ref->{$_} =~ s/\"/"/g } qw(partnumber description unit);
621 $form->round_amount($ref->{sellprice} * (1 - $form->{tradediscount}), 2);
623 qq|<td><input name="ndx" class="radio" type="radio" value="$i" $checked></td>|;
624 $column_data{partnumber} =
625 qq|<td><input name="new_partnumber_$i" type="hidden" value="$ref->{partnumber}">$ref->{partnumber}</td>|;
626 $column_data{description} =
627 qq|<td><input name="new_description_$i" type="hidden" value=$ref->{description}>$ref->{description}</td>|;
628 $column_data{sellprice} =
629 qq|<td align="right"><input name="new_sellprice_$i" type="hidden" value="$ref->{sellprice}">|
630 . $form->format_amount(\%myconfig, $ref->{sellprice}, 2, " ")
632 $column_data{onhand} =
633 qq|<td align="right"><input name="new_onhand_$i" type="hidden" value="$ref->{onhand}">|
634 . $form->format_amount(\%myconfig, $ref->{onhand}, '', " ")
637 qq|<td>$ref->{unit}</td>|;
641 <tr class=listrow$j>|;
643 map { print "\n$column_data{$_}" } @column_index;
648 map({ print($cgi->hidden("-name" => "new_$__$i", "-value" => $ref->{$_})); }
649 qw(bin listprice inventory_accno income_accno expense_accno unit weight assembly taxaccounts partsgroup
650 formel logdescription not_discountable part_payment_id partnodes id));
653 <input name="new_lizenzen_$i" type="hidden" value="$ref->{lizenzen}">
660 <tr><td colspan="8"><hr size="3" noshade></td></tr>
663 <input name="lastndx" type="hidden" value="$i">
667 # delete action variable
668 map { delete $form->{$_} } qw(action item_list header);
670 # save all other form variables
671 foreach $key (keys %${form}) {
672 $form->{$key} =~ s/\"/"/g;
673 print qq|<input name="$key" type="hidden" value="$form->{$key}">\n|;
677 <input type="hidden" name="nextsub" value="item_selected">
680 <input class="submit" type="submit" name="action" value="|
681 . $locale->text('Continue') . qq|">
688 $lxdebug->leave_sub();
692 $lxdebug->enter_sub();
694 # replace the last row with the checked row
695 $i = $form->{rowcount};
696 $i = $form->{assembly_rows} if ($form->{item} eq 'assembly');
702 #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
703 #$form->{"sellprice_$i"} = $form->{"sellprice_$i"};
705 # if there was a price entered, override it
706 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
708 map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} }
709 qw(id partnumber description sellprice listprice inventory_accno
710 income_accno expense_accno bin unit weight assembly taxaccounts
711 partsgroup formel longdescription not_discountable partnotes);
712 if ($form->{"part_payment_id_$i"} ne "") {
713 $form->{payment_id} = $form->{"part_payment_id_$i"};
717 map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} } qw(lizenzen);
720 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
722 $decimalplaces = ($dec > 2) ? $dec : 2;
725 $form->{"sellprice_$i"} = $sellprice;
728 # if there is an exchange rate adjust sellprice
729 if (($form->{exchangerate} * 1) != 0) {
730 $form->{"sellprice_$i"} /= $form->{exchangerate};
731 $form->{"sellprice_$i"} =
732 $form->round_amount($form->{"sellprice_$i"}, $decimalplaces);
736 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
737 qw(sellprice listprice weight);
739 $form->{sellprice} += ($form->{"sellprice_$i"} * $form->{"qty_$i"});
740 $form->{weight} += ($form->{"weight_$i"} * $form->{"qty_$i"});
742 if ($form->{"not_discountable_$i"}) {
743 $form->{"discount_$i"} = 0;
747 $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) *
749 map { $form->{"${_}_base"} += $amount }
750 (split / /, $form->{"taxaccounts_$i"});
751 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /,
752 $form->{"taxaccounts_$i"}
753 if !$form->{taxincluded};
755 $form->{creditremaining} -= $amount;
757 $form->{"runningnumber_$i"} = $i;
759 # delete all the new_ variables
760 for $i (1 .. $form->{lastndx}) {
761 map { delete $form->{"new_${_}_$i"} }
762 qw(partnumber description sellprice bin listprice inventory_accno income_accno expense_accno unit assembly taxaccounts id);
765 map { delete $form->{$_} } qw(ndx lastndx nextsub);
770 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces)
771 } qw(sellprice listprice) if $form->{item} ne 'assembly';
773 # get pricegroups for parts
774 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
776 # build up html code for prices_$i
777 set_pricegroup($form->{rowcount});
781 $lxdebug->leave_sub();
785 $lxdebug->enter_sub();
788 $form->{old_callback} = $form->escape($form->{callback}, 1);
789 $form->{callback} = $form->escape("$form->{script}?action=display_form", 1);
792 delete $form->{action};
794 # save all other form variables in a previousform variable
795 foreach $key (keys %$form) {
798 $form->{$key} =~ s/&/%26/g;
799 $previousform .= qq|$key=$form->{$key}&|;
802 $previousform = $form->escape($previousform, 1);
804 $i = $form->{rowcount};
805 map { $form->{"${_}_$i"} =~ s/\"/"/g } qw(partnumber description);
812 <h4 class="error">| . $locale->text('Item not on file!') . qq|
815 | . $locale->text('What type of item is this?') . qq|</h4>
817 <form method="post" action="ic.pl">
821 <input class="radio" type="radio" name="item" value="part" checked> |
822 . $locale->text('Part') . qq|<br>
823 <input class="radio" type="radio" name="item" value="service"> |
824 . $locale->text('Service');
825 print $cgi->hidden("-name" => "previousform", "-value" => $previousform);
826 map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); }
827 ("partnumber_$i", "description_$i", "rowcount", "taxaccounts", "vc", "path", "login", "password"));
829 #<input type="hidden" name="partnumber" value="$form->{"partnumber_$i"}">
830 #<input type="hidden" name="description" value="$form->{"description_$i"}">
831 #<input type="hidden" name="rowcount" value="$form->{rowcount}">
832 #<input type="hidden" name="taxaccount2" value="$form->{taxaccounts}">
833 #<input type="hidden" name="vc" value="$form->{vc}">
835 #<input type="hidden" name="path" value="$form->{path}">
836 #<input type="hidden" name="login" value="$form->{login}">
837 #<input type="hidden" name="password" value="$form->{password}">
840 <input type="hidden" name="nextsub" value="add">
843 <input class="submit" type="submit" name="action" value="|
844 . $locale->text('Continue') . qq|">
851 $lxdebug->leave_sub();
855 $lxdebug->enter_sub();
859 my $new_rowcount = $form->{"rowcount"} * 1 + 1;
860 $form->{"project_id_${new_rowcount}"} = $form->{"globalproject_id"};
862 $form->language_payment(\%myconfig);
864 # if we have a display_form
865 if ($form->{display_form}) {
866 &{"$form->{display_form}"};
870 Common::webdav_folder($form) if ($webdav);
872 # if ( $form->{print_and_post}
873 # && $form->{second_run}
874 # && ($form->{action} eq "display_form")) {
875 # for (keys %$form) { $old_form->{$_} = $form->{$_} }
876 # $old_form->{rowcount}++;
878 # #$form->{rowcount}--;
879 # #$form->{rowcount}--;
881 # $form->{print_and_post} = 0;
883 # &print_form($old_form);
887 # $form->{action} = "";
888 # $form->{resubmit} = 0;
890 # if ($form->{print_and_post} && !$form->{second_run}) {
891 # $form->{second_run} = 1;
892 # $form->{action} = "display_form";
893 # $form->{rowcount}--;
894 # my $rowcount = $form->{rowcount};
896 # # get pricegroups for parts
897 # IS->get_pricegroups_for_parts(\%myconfig, \%$form);
899 # # build up html code for prices_$i
900 # set_pricegroup($rowcount);
902 # $form->{resubmit} = 1;
907 $numrows = ++$form->{rowcount};
908 $subroutine = "display_row";
910 if ($form->{item} eq 'part') {
912 #set preisgruppenanzahl
913 $numrows = $form->{price_rows};
914 $subroutine = "price_row";
916 &{$subroutine}($numrows);
918 $numrows = ++$form->{makemodel_rows};
919 $subroutine = "makemodel_row";
921 if ($form->{item} eq 'assembly') {
922 $numrows = $form->{price_rows};
923 $subroutine = "price_row";
925 &{$subroutine}($numrows);
927 $numrows = ++$form->{makemodel_rows};
928 $subroutine = "makemodel_row";
930 # create makemodel rows
931 &{$subroutine}($numrows);
933 $numrows = ++$form->{assembly_rows};
934 $subroutine = "assembly_row";
936 if ($form->{item} eq 'service') {
937 $numrows = $form->{price_rows};
938 $subroutine = "price_row";
940 &{$subroutine}($numrows);
946 &{$subroutine}($numrows) if $numrows;
950 $lxdebug->leave_sub();
954 $lxdebug->enter_sub();
958 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)
962 # remove any makes or model rows
963 if ($form->{item} eq 'part') {
964 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
965 qw(listprice sellprice lastcost weight rop);
967 @flds = (make, model);
968 for my $i (1 .. ($form->{makemodel_rows})) {
969 if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
973 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
978 $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
979 $form->{makemodel_rows} = $count;
981 } elsif ($form->{item} eq 'assembly') {
983 $form->{sellprice} = 0;
985 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
986 qw(listprice rop stock);
989 qw(id qty unit bom partnumber description sellprice weight runningnumber partsgroup);
991 for my $i (1 .. ($form->{assembly_rows} - 1)) {
992 if ($form->{"qty_$i"}) {
996 $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
998 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1000 #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
1002 $form->{sellprice} += ($form->{"qty_$i"} * $form->{"sellprice_$i"});
1003 $form->{weight} += ($form->{"qty_$i"} * $form->{"weight_$i"});
1008 $form->{sellprice} = $form->round_amount($form->{sellprice}, 2);
1010 $form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows});
1011 $form->{assembly_rows} = $count;
1014 @flds = qw(make model);
1017 for my $i (1 .. ($form->{makemodel_rows})) {
1018 if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
1022 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1027 $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
1028 $form->{makemodel_rows} = $count;
1032 # this section applies to invoices and orders
1033 # remove any empty numbers
1034 if ($form->{rowcount}) {
1035 for my $i (1 .. $form->{rowcount} - 1) {
1036 if ($form->{"partnumber_$i"}) {
1040 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1043 if ($form->{"licensenumber_$i"} == -1) {
1051 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
1052 $form->{rowcount} = $count;
1054 $form->{creditremaining} -= &invoicetotal;
1061 if ( $form->{type} =~ (/sales_quotation/)
1062 or (($form->{level} =~ /Sales/) and ($form->{type} =~ /invoice/))
1063 or (($form->{level} eq undef) and ($form->{type} =~ /invoice/))
1064 or ($form->{type} =~ /sales_order/)) {
1066 # get pricegroups for parts
1067 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1069 # build up html code for prices_$i
1070 set_pricegroup($form->{rowcount});
1076 $lxdebug->leave_sub();
1080 $lxdebug->enter_sub();
1082 $form->{oldinvtotal} = 0;
1084 # add all parts and deduct paid
1085 map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
1087 my ($amount, $sellprice, $discount, $qty);
1089 for my $i (1 .. $form->{rowcount}) {
1090 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1091 $discount = $form->parse_amount(\%myconfig, $form->{"discount_$i"});
1092 $qty = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
1094 #($form->{"sellprice_$i"}, $form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
1096 $amount = $sellprice * (1 - $discount / 100) * $qty;
1097 map { $form->{"${_}_base"} += $amount }
1098 (split (/ /, $form->{"taxaccounts_$i"}));
1099 $form->{oldinvtotal} += $amount;
1102 map { $form->{oldinvtotal} += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1103 split(/ /, $form->{taxaccounts})
1104 if !$form->{taxincluded};
1106 $form->{oldtotalpaid} = 0;
1107 for $i (1 .. $form->{paidaccounts}) {
1108 $form->{oldtotalpaid} += $form->{"paid_$i"};
1111 $lxdebug->leave_sub();
1114 return ($form->{oldinvtotal} - $form->{oldtotalpaid});
1117 sub validate_items {
1118 $lxdebug->enter_sub();
1120 # check if items are valid
1121 if ($form->{rowcount} == 1) {
1126 for $i (1 .. $form->{rowcount} - 1) {
1127 $form->isblank("partnumber_$i",
1128 $locale->text('Number missing in Row') . " $i");
1131 $lxdebug->leave_sub();
1135 $lxdebug->enter_sub();
1136 if ($form->{second_run}) {
1137 $form->{print_and_post} = 0;
1139 $form->{ordnumber} = $form->{invnumber};
1141 map { delete $form->{$_} } qw(id printed emailed queued);
1142 if ($form->{script} eq 'ir.pl' || $form->{type} eq 'request_quotation') {
1143 $form->{title} = $locale->text('Add Purchase Order');
1144 $form->{vc} = 'vendor';
1145 $form->{type} = 'purchase_order';
1148 if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_quotation') {
1149 $form->{title} = $locale->text('Add Sales Order');
1150 $form->{vc} = 'customer';
1151 $form->{type} = 'sales_order';
1154 $form->{script} = 'oe.pl';
1156 $form->{shipto} = 1;
1158 $form->{rowcount}--;
1160 $form->{cp_id} *= 1;
1162 require "$form->{path}/$form->{script}";
1163 my $script = $form->{"script"};
1165 $script =~ s|.pl$||;
1166 $locale = new Locale($language, $script);
1168 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1170 $currency = $form->{currency};
1174 $form->{currency} = $currency;
1175 $form->{exchangerate} = "";
1176 $form->{forex} = "";
1177 $form->{exchangerate} = $exchangerate
1181 $form->check_exchangerate(
1182 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1185 for $i (1 .. $form->{rowcount}) {
1186 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
1187 $form->{"${_}_${i}"})
1188 if ($form->{"${_}_${i}"}) }
1189 qw(ship qty sellprice listprice basefactor));
1195 $lxdebug->leave_sub();
1199 $lxdebug->enter_sub();
1200 if ($form->{second_run}) {
1201 $form->{print_and_post} = 0;
1203 map { delete $form->{$_} } qw(id printed emailed queued);
1205 if ($form->{script} eq 'ir.pl' || $form->{type} eq 'purchase_order') {
1206 $form->{title} = $locale->text('Add Request for Quotation');
1207 $form->{vc} = 'vendor';
1208 $form->{type} = 'request_quotation';
1211 if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_order') {
1212 $form->{title} = $locale->text('Add Quotation');
1213 $form->{vc} = 'customer';
1214 $form->{type} = 'sales_quotation';
1218 $form->{cp_id} *= 1;
1220 $form->{script} = 'oe.pl';
1222 $form->{shipto} = 1;
1224 $form->{rowcount}--;
1226 require "$form->{path}/$form->{script}";
1228 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1230 $currency = $form->{currency};
1234 $form->{currency} = $currency;
1235 $form->{exchangerate} = "";
1236 $form->{forex} = "";
1237 $form->{exchangerate} = $exchangerate
1241 $form->check_exchangerate(
1242 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1245 for $i (1 .. $form->{rowcount}) {
1246 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
1247 $form->{"${_}_${i}"})
1248 if ($form->{"${_}_${i}"}) }
1249 qw(ship qty sellprice listprice basefactor));
1255 $lxdebug->leave_sub();
1258 sub request_for_quotation {
1263 $lxdebug->enter_sub();
1264 if ($form->{second_run}) {
1265 $form->{print_and_post} = 0;
1266 $form->{resubmit} = 0;
1268 if ($myconfig{role} eq 'admin') {
1271 <th align="right" nowrap="true">| . $locale->text('Bcc') . qq|</th>
1272 <td><input name="bcc" size="30" value="| . Q($form->{bcc}) . qq|"></td>
1277 if ($form->{formname} =~ /(pick|packing|bin)_list/) {
1278 $form->{email} = $form->{shiptoemail} if $form->{shiptoemail};
1281 if ($form->{"cp_id"} && !$form->{"email"}) {
1282 CT->get_contact(\%myconfig, $form);
1283 $form->{"email"} = $form->{"cp_email"};
1286 $name = $form->{ $form->{vc} };
1288 $title = $locale->text('E-mail') . " $name";
1290 $form->{oldmedia} = $form->{media};
1291 $form->{media} = "email";
1293 my %formname_translations =
1295 "bin_list" => $locale->text('Bin List'),
1296 "credit_note" => $locale->text('Credit Note'),
1297 "invoice" => $locale->text('Invoice'),
1298 "packing_list" => $locale->text('Packing List'),
1299 "pick_list" => $locale->text('Pick List'),
1300 "proforma" => $locale->text('Proforma Invoice'),
1301 "purchase_order" => $locale->text('Purchase Order'),
1302 "request_quotation" => $locale->text('RFQ'),
1303 "sales_order" => $locale->text('Confirmation'),
1304 "sales_quotation" => $locale->text('Quotation'),
1305 "storno_invoice" => $locale->text('Storno Invoice'),
1306 "storno_packing_list" => $locale->text('Storno Packing List'),
1309 my $attachment_filename = $formname_translations{$form->{"formname"}};
1312 if (grep({ $form->{"type"} eq $_ } qw(invoice credit_note))) {
1314 } elsif ($form->{"type"} =~ /_quotation$/) {
1320 if ($attachment_filename && $form->{"${prefix}number"}) {
1321 $attachment_filename .= "_" . $form->{"${prefix}number"} .
1322 ($form->{"format"} =~ /pdf/i ? ".pdf" :
1323 $form->{"format"} =~ /postscript/i ? ".ps" :
1324 $form->{"format"} =~ /opendocument/i ? ".odt" :
1325 $form->{"format"} =~ /html/i ? ".html" : "");
1326 $attachment_filename =~ s/ /_/g;
1329 "ä" => "ae", "ö" => "oe", "ü" => "ue",
1330 "Ä" => "Ae", "Ö" => "Oe", "Ü" => "Ue",
1333 map({ $attachment_filename =~ s/$_/$umlaute{$_}/g; } keys(%umlaute));
1335 $attachment_filename = "";
1338 if ($form->{"email"}) {
1339 $form->{"fokus"} = "Form.subject";
1341 $form->{"fokus"} = "Form.email";
1346 <body onload="fokus()">
1348 <form name="Form" method="post" action="$form->{script}">
1350 <table width="100%">
1351 <tr class="listtop">
1352 <th class="listtop">$title</th>
1354 <tr height="5"></tr>
1359 <th align="right" nowrap>| . $locale->text('To') . qq|</th>
1360 <td><input name="email" size="30" value="| .
1361 Q($form->{"email"}) . qq|"></td>
1364 <th align="right" nowrap>| . $locale->text('Cc') . qq|</th>
1365 <td><input name="cc" size="30" value="| .
1366 Q($form->{"cc"}) . qq|"></td>
1370 <th align="right" nowrap>| . $locale->text('Subject') . qq|</th>
1371 <td><input name="subject" size="30" value="| .
1372 Q($form->{"subject"}) . qq|"></td>
1375 <th align="right" nowrap>| . $locale->text('Attachment name') .
1377 <td><input name="attachment_filename" size="30" value="| .
1378 Q($attachment_filename) . qq|"></td>
1386 <th align="left" nowrap>| . $locale->text('Message') . qq|</th>
1389 <td><textarea name="message" rows="15" cols="60" wrap="soft">| .
1390 H($form->{"message"}) . qq|</textarea></td>
1401 map { delete $form->{$_} }
1402 qw(action email cc bcc subject message formname sendmode format header override);
1404 # save all other variables
1405 foreach $key (keys %$form) {
1406 $form->{$key} =~ s/\"/"/g;
1407 print qq|<input type="hidden" name="$key" value="| . Q($form->{$key}) . qq|">\n|;
1414 <td><hr size="3" noshade></td>
1418 <input type="hidden" name="nextsub" value="send_email">
1421 <input name="action" class="submit" type="submit" value="|
1422 . $locale->text('Continue') . qq|">
1429 $lxdebug->leave_sub();
1433 $lxdebug->enter_sub();
1435 my $callback = $form->{script} . "?action=edit";
1436 map({ $callback .= "\&${_}=" . E($form->{$_}); }
1437 qw(login password path type id));
1439 print_form("return");
1441 $form->{callback} = $callback;
1444 $lxdebug->leave_sub();
1447 # generate the printing options displayed at the bottom of oe and is forms.
1448 # this function will attempt to guess what type of form is displayed, and will generate according options
1451 # this version builds the arrays of options pretty directly. if you have trouble understanding how,
1452 # the opthash function builds hashrefs which are then pieced together for the template arrays.
1453 # unneeded options are "undef"ed out, and then grepped out.
1455 # the inline options is untested, but intended to be used later in metatemplating
1457 $lxdebug->enter_sub() and my ($inline) = @_;
1459 # names 3 parameters and returns a hashref, for use in templates
1460 sub opthash { +{ value => shift, selected => shift, oname => shift } }
1461 (@FORMNAME, @FORMNAME, @LANGUAGE_ID, @FORMAT, @SENDMODE, @MEDIA, @PRINTER_ID, @SELECTS) = ();
1463 # note: "||"-selection is only correct for values where "0" is _not_ a correct entry
1464 $form->{sendmode} = "attachment";
1465 $form->{format} = $form->{format} || $myconfig{template_format} || "pdf";
1466 $form->{copies} = $form->{copies} || $myconfig{copies} || 3;
1467 $form->{media} = $form->{media} || $myconfig{default_media} || "screen";
1468 $form->{printer_id} = defined $form->{printer_id} ? $form->{printer_id} :
1469 defined $myconfig{default_printer_id} ? $myconfig{default_printer_id} : "";
1471 $form->{PD}{ $form->{formname} } = "selected";
1472 $form->{DF}{ $form->{format} } = "selected";
1473 $form->{OP}{ $form->{media} } = "selected";
1474 $form->{SM}{ $form->{formname} } = "selected";
1476 push @FORMNAME, grep $_,
1477 ($form->{type} eq 'purchase_order') ? (
1478 opthash("purchase_order", $form->{PD}{purchase_order}, $locale->text('Purchase Order')),
1479 opthash("bin_list", $form->{PD}{bin_list}, $locale->text('Bin List'))
1481 ($form->{type} eq 'credit_note') ?
1482 opthash("credit_note", $form->{PD}{credit_note}, $locale->text('Credit Note')) : undef,
1483 ($form->{type} eq 'sales_order') ? (
1484 opthash("sales_order", $form->{PD}{sales_order}, $locale->text('Confirmation')),
1485 opthash("proforma", $form->{PD}{proforma}, $locale->text('Proforma Invoice')),
1486 opthash("pick_list", $form->{PD}{pick_list}, $locale->text('Pick List')),
1487 opthash("packing_list", $form->{PD}{packing_list}, $locale->text('Packing List'))
1489 ($form->{type} =~ /_quotation$/) ?
1490 opthash("$`_quotation", $form->{PD}{"$`_quotation"}, $locale->text('Quotation')) : undef,
1491 ($form->{type} eq 'invoice') ? (
1492 opthash("invoice", $form->{PD}{invoice}, $locale->text('Invoice')),
1493 opthash("proforma", $form->{PD}{proforma}, $locale->text('Proforma Invoice')),
1494 opthash("packing_list", $form->{PD}{packing_list}, $locale->text('Packing List'))
1496 ($form->{type} eq 'invoice' && $form->{storno}) ? (
1497 opthash("storno_invoice", $form->{PD}{storno_invoice}, $locale->text('Storno Invoice')),
1498 opthash("storno_packing_list", $form->{PD}{storno_packing_list}, $locale->text('Storno Packing List'))
1500 ($form->{type} eq 'credit_note') ?
1501 opthash("credit_note", $form->{PD}{credit_note}, $locale->text('Credit Note')) : undef;
1504 opthash("attachment", $form->{SM}{attachment}, $locale->text('Attachment')),
1505 opthash("inline", $form->{SM}{inline}, $locale->text('In-line'))
1506 if ($form->{media} eq 'email');
1508 push @MEDIA, grep $_,
1509 opthash("screen", $form->{OP}{screen}, $locale->text('Screen')),
1510 (scalar keys %{ $form->{printers} } && $latex_templates) ?
1511 opthash("printer", $form->{OP}{printer}, $locale->text('Printer')) : undef,
1512 ($latex_templates) ?
1513 opthash("queue", $form->{OP}{queue}, $locale->text('Queue')) : undef
1514 if ($form->{media} ne 'email');
1516 push @FORMAT, grep $_,
1517 ($opendocument_templates && $openofficeorg_writer_bin && $xvfb_bin && (-x $openofficeorg_writer_bin) && (-x $xvfb_bin)) ?
1518 opthash("opendocument_pdf", $form->{DF}{"opendocument_pdf"}, $locale->text("PDF (OpenDocument/OASIS)")) : undef,
1519 ($latex_templates) ? (
1520 opthash("pdf", $form->{DF}{pdf}, $locale->text('PDF')),
1521 opthash("postscript", $form->{DF}{postscript}, $locale->text('Postscript'))
1523 opthash("html", $form->{DF}{html}, "HTML"),
1524 ($opendocument_templates) ?
1525 opthash("opendocument", $form->{DF}{opendocument}, $locale->text("OpenDocument/OASIS")) : undef;
1528 map { opthash($_->{id}, ($_->{id} eq $form->{language} ? 'selected' : ''), $_->{description}) } +{}, @{ $form->{languages} }
1529 if (ref $form->{languages} eq 'ARRAY');
1532 map { opthash($_->{id}, ($_->{id} eq $form->{printer_id} ? 'selected' : ''), $_->{printer_description}) } +{}, @{ $form->{printers} }
1533 if (ref $form->{printers} eq 'ARRAY');
1535 @SELECTS = map { sname => lc $_, DATA => \@$_, show => scalar @$_ }, qw(FORMNAME LANGUAGE_ID FORMAT SENDMODE MEDIA PRINTER_ID);
1538 display_copies => scalar keys %{ $form->{printers} } && $latex_templates && $form->{media} ne 'email',
1539 display_remove_draft => (!$form->{id} && $form->{draft_id}),
1540 groupitems_checked => $form->{groupitems} ? "checked" : '',
1541 remove_draft_checked => $form->{remove_draft} ? "checked" : ''
1544 my $print_options = $form->parse_html_template("generic/print_options", { SELECTS => \@SELECTS, %template_vars } );
1547 $lxdebug->leave_sub() and return $print_options;
1549 print $print_options; $lxdebug->leave_sub();
1554 $lxdebug->enter_sub();
1556 # if this goes to the printer pass through
1557 if ($form->{media} eq 'printer' || $form->{media} eq 'queue') {
1558 $form->error($locale->text('Select postscript or PDF!'))
1559 if ($form->{format} !~ /(postscript|pdf)/);
1561 $old_form = new Form;
1562 map { $old_form->{$_} = $form->{$_} } keys %$form;
1565 if (!$form->{id} || (($form->{formname} eq "proforma") && !$form->{proforma} && (($form->{type} =~ /_order$/) || ($form->{type} =~ /_quotation$/)))) {
1566 if ($form->{formname} eq "proforma") {
1567 $form->{proforma} = 1;
1569 $form->{print_and_save} = 1;
1570 my $formname = $form->{formname};
1572 $form->{formname} = $formname;
1577 &print_form($old_form);
1579 $lxdebug->leave_sub();
1583 $lxdebug->enter_sub();
1584 my ($old_form) = @_;
1588 $numberfld = "invnumber";
1591 ($form->{display_form}) ? $form->{display_form} : "display_form";
1593 # $form->{"notes"} will be overridden by the customer's/vendor's "notes" field. So save it here.
1594 $form->{ $form->{"formname"} . "notes" } = $form->{"notes"};
1596 if ($form->{formname} eq "invoice") {
1597 $form->{label} = $locale->text('Invoice');
1599 if ($form->{formname} eq "packing_list") {
1601 # this is from an invoice
1602 $form->{label} = $locale->text('Packing List');
1604 if ($form->{formname} eq 'sales_order') {
1607 $form->{"${inv}date"} = $form->{transdate};
1608 $form->{label} = $locale->text('Sales Order');
1609 $numberfld = "sonumber";
1613 if (($form->{type} eq 'invoice') && ($form->{formname} eq 'proforma') ) {
1616 $form->{"${inv}date"} = $form->{invdate};
1617 $form->{label} = $locale->text('Proforma Invoice');
1618 $numberfld = "sonumber";
1622 if (($form->{type} eq 'sales_order') && ($form->{formname} eq 'proforma') ) {
1625 $form->{"${inv}date"} = $form->{transdate};
1626 $form->{"invdate"} = $form->{transdate};
1627 $form->{invnumber} = $form->{ordnumber};
1628 $form->{label} = $locale->text('Proforma Invoice');
1629 $numberfld = "sonumber";
1633 if ($form->{formname} eq 'packing_list' && $form->{type} ne 'invoice') {
1635 # we use the same packing list as from an invoice
1638 $form->{invdate} = $form->{"${inv}date"} = $form->{transdate};
1639 $form->{label} = $locale->text('Packing List');
1641 # set invnumber for template packing_list
1642 $form->{invnumber} = $form->{ordnumber};
1644 if ($form->{formname} eq 'pick_list') {
1647 $form->{"${inv}date"} =
1648 ($form->{transdate}) ? $form->{transdate} : $form->{invdate};
1649 $form->{label} = $locale->text('Pick List');
1650 $order = 1 unless $form->{type} eq 'invoice';
1652 if ($form->{formname} eq 'purchase_order') {
1655 $form->{"${inv}date"} = $form->{transdate};
1656 $form->{label} = $locale->text('Purchase Order');
1657 $numberfld = "ponumber";
1660 if ($form->{formname} eq 'bin_list') {
1663 $form->{"${inv}date"} = $form->{transdate};
1664 $form->{label} = $locale->text('Bin List');
1667 if ($form->{formname} eq 'sales_quotation') {
1670 $form->{"${inv}date"} = $form->{transdate};
1671 $form->{label} = $locale->text('Quotation');
1672 $numberfld = "sqnumber";
1676 if (($form->{type} eq 'sales_quotation') && ($form->{formname} eq 'proforma') ) {
1679 $form->{"${inv}date"} = $form->{transdate};
1680 $form->{"invdate"} = $form->{transdate};
1681 $form->{label} = $locale->text('Proforma Invoice');
1682 $numberfld = "sqnumber";
1686 if ($form->{formname} eq 'request_quotation') {
1689 $form->{"${inv}date"} = $form->{transdate};
1690 $form->{label} = $locale->text('Quotation');
1691 $numberfld = "rfqnumber";
1695 $form->isblank("email", $locale->text('E-mail address missing!'))
1696 if ($form->{media} eq 'email');
1697 $form->isblank("${inv}date",
1698 $locale->text($form->{label})
1700 . $locale->text(' Date missing!'));
1702 # $locale->text('Invoice Number missing!')
1703 # $locale->text('Invoice Date missing!')
1704 # $locale->text('Packing List Number missing!')
1705 # $locale->text('Packing List Date missing!')
1706 # $locale->text('Order Number missing!')
1707 # $locale->text('Order Date missing!')
1708 # $locale->text('Quotation Number missing!')
1709 # $locale->text('Quotation Date missing!')
1712 $form->{what_done} = $form->{formname};
1713 if (!$form->{"${inv}number"} && !$form->{preview} && !$form->{id}) {
1714 $form->{"${inv}number"} = $form->update_defaults(\%myconfig, $numberfld);
1715 if ($form->{media} ne 'email') {
1717 # get pricegroups for parts
1718 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1720 # build up html code for prices_$i
1721 set_pricegroup($form->{rowcount});
1723 $form->{rowcount}--;
1726 # saving the history
1727 if(!exists $form->{addition}) {
1728 $form->{addition} = "PRINTED";
1729 $form->save_history($form->dbconnect(\%myconfig));
1731 # /saving the history
1738 # Save the email address given in the form because it should override the setting saved for the customer/vendor.
1739 my ($saved_email, $saved_cc, $saved_bcc) =
1740 ($form->{"email"}, $form->{"cc"}, $form->{"bcc"});
1742 $language_saved = $form->{language_id};
1743 $payment_id_saved = $form->{payment_id};
1744 $salesman_id_saved = $form->{salesman_id};
1745 $cp_id_saved = $form->{cp_id};
1747 &{"$form->{vc}_details"}();
1749 $form->{language_id} = $language_saved;
1750 $form->{payment_id} = $payment_id_saved;
1752 $form->{"email"} = $saved_email if ($saved_email);
1753 $form->{"cc"} = $saved_cc if ($saved_cc);
1754 $form->{"bcc"} = $saved_bcc if ($saved_bcc);
1756 if (!$cp_id_saved) {
1757 # No contact was selected. Delete all contact variables because
1758 # IS->customer_details() and IR->vendor_details() get the default
1760 map({ delete($form->{$_}); } grep(/^cp_/, keys(%{ $form })));
1763 my ($language_tc, $output_numberformat, $output_dateformat, $output_longdates);
1764 if ($form->{"language_id"}) {
1765 ($language_tc, $output_numberformat, $output_dateformat, $output_longdates) =
1766 AM->get_language_details(\%myconfig, $form, $form->{language_id});
1768 $output_dateformat = $myconfig{"dateformat"};
1769 $output_numberformat = $myconfig{"numberformat"};
1770 $output_longdates = 1;
1773 ($form->{employee}) = split /--/, $form->{employee};
1775 # create the form variables
1777 OE->order_details(\%myconfig, \%$form);
1779 IS->invoice_details(\%myconfig, \%$form, $locale);
1782 $form->get_salesman(\%myconfig, $salesman_id_saved);
1784 if ($form->{shipto_id}) {
1785 $form->get_shipto(\%myconfig);
1788 @a = qw(name street zipcode city country);
1792 # if there is no shipto fill it in from billto
1793 foreach $item (@a) {
1794 if ($form->{"shipto$item"}) {
1801 if ( $form->{formname} eq 'purchase_order'
1802 || $form->{formname} eq 'request_quotation') {
1803 $form->{shiptoname} = $myconfig{company};
1804 $form->{shiptostreet} = $myconfig{address};
1806 map { $form->{"shipto$_"} = $form->{$_} } @a;
1810 $form->{notes} =~ s/^\s+//g;
1812 $form->{templates} = "$myconfig{templates}";
1814 $form->{language} = $form->get_template_language(\%myconfig);
1815 $form->{printer_code} = $form->get_printer_code(\%myconfig);
1817 if ($form->{language} ne "") {
1818 map({ $form->{"unit"}->[$_] =
1819 AM->translate_units($form, $form->{"language"},
1820 $form->{"unit"}->[$_], $form->{"qty"}->[$_]); }
1821 (0..scalar(@{$form->{"unit"}}) - 1));
1822 $form->{language} = "_" . $form->{language};
1826 format_dates($output_dateformat, $output_longdates,
1827 qw(invdate orddate quodate pldate duedate reqdate transdate
1828 shippingdate deliverydate validitydate paymentdate
1829 datepaid transdate_oe deliverydate_oe
1830 employee_startdate employee_enddate
1832 grep({ /^datepaid_\d+$/ ||
1833 /^transdate_oe_\d+$/ ||
1834 /^deliverydate_oe_\d+$/ ||
1836 /^deliverydate_\d+$/ ||
1840 reformat_numbers($output_numberformat, 2,
1841 qw(invtotal ordtotal quototal subtotal linetotal
1842 listprice sellprice netprice discount
1844 grep({ /^linetotal_\d+$/ ||
1845 /^listprice_\d+$/ ||
1846 /^sellprice_\d+$/ ||
1853 reformat_numbers($output_numberformat, undef,
1858 if ($form->{printer_code} ne "") {
1859 $form->{printer_code} = "_" . $form->{printer_code};
1862 $form->{IN} = "$form->{formname}$form->{language}$form->{printer_code}.html";
1863 if ($form->{format} eq 'postscript') {
1864 $form->{postscript} = 1;
1865 $form->{IN} =~ s/html$/tex/;
1866 } elsif ($form->{"format"} =~ /pdf/) {
1868 if ($form->{"format"} =~ /opendocument/) {
1869 $form->{IN} =~ s/html$/odt/;
1871 $form->{IN} =~ s/html$/tex/;
1873 } elsif ($form->{"format"} =~ /opendocument/) {
1874 $form->{"opendocument"} = 1;
1875 $form->{"IN"} =~ s/html$/odt/;
1878 if ($form->{media} eq 'printer') {
1879 $form->{OUT} = "| $form->{printer_command} &>/dev/null";
1880 $form->{printed} .= " $form->{formname}";
1881 $form->{printed} =~ s/^ //;
1883 $printed = $form->{printed};
1885 if ($form->{media} eq 'email') {
1886 $form->{subject} = qq|$form->{label} $form->{"${inv}number"}|
1887 unless $form->{subject};
1889 $form->{OUT} = "$sendmail";
1891 $form->{emailed} .= " $form->{formname}";
1892 $form->{emailed} =~ s/^ //;
1894 $emailed = $form->{emailed};
1896 if ($form->{media} eq 'queue') {
1897 %queued = split / /, $form->{queued};
1899 if ($filename = $queued{ $form->{formname} }) {
1900 $form->{queued} =~ s/$form->{formname} $filename//;
1901 unlink "$spool/$filename";
1902 $filename =~ s/\..*$//g;
1908 $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
1909 $form->{OUT} = ">$spool/$filename";
1912 $form->{queued} .= " $form->{formname} $filename";
1914 $form->{queued} =~ s/^ //;
1916 $queued = $form->{queued};
1918 # saving the history
1919 if(!exists $form->{addition}) {
1920 if($form->{media} =~ /printer/) {
1921 $form->{addition} = "PRINTED";
1923 elsif($form->{media} =~ /email/) {
1924 $form->{addition} = "MAILED";
1926 elsif($form->{media} =~ /queue/) {
1927 $form->{addition} = "QUEUED";
1929 elsif($form->{media} =~ /screen/) {
1930 $form->{addition} = "SCREENED";
1932 $form->save_history($form->dbconnect(\%myconfig));
1934 # /saving the history
1936 $form->parse_template(\%myconfig, $userspath);
1938 $form->{callback} = "";
1940 if ($form->{media} eq 'email') {
1941 $form->{message} = $locale->text('sent') unless $form->{message};
1943 $message = $form->{message};
1945 # if we got back here restore the previous form
1946 if ($form->{media} =~ /(printer|email|queue)/) {
1948 $form->update_status(\%myconfig)
1949 if ($form->{media} eq 'queue' && $form->{id});
1951 return $lxdebug->leave_sub() if ($old_form eq "return");
1955 $old_form->{"${inv}number"} = $form->{"${inv}number"};
1957 # restore and display form
1958 map { $form->{$_} = $old_form->{$_} } keys %$old_form;
1960 $form->{queued} = $queued;
1961 $form->{printed} = $printed;
1962 $form->{emailed} = $emailed;
1963 $form->{message} = $message;
1965 $form->{rowcount}--;
1966 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1967 qw(exchangerate creditlimit creditremaining);
1969 for $i (1 .. $form->{paidaccounts}) {
1971 $form->{"${_}_$i"} =
1972 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
1973 } qw(paid exchangerate);
1981 ($form->{media} eq 'printer')
1982 ? $locale->text('sent to printer')
1983 : $locale->text('emailed to') . " $form->{email}";
1984 $form->redirect(qq|$form->{label} $form->{"${inv}number"} $msg|);
1986 if ($form->{printing}) {
1991 $lxdebug->leave_sub();
1994 sub customer_details {
1995 $lxdebug->enter_sub();
1996 IS->customer_details(\%myconfig, \%$form, @_);
1997 $lxdebug->leave_sub();
2000 sub vendor_details {
2001 $lxdebug->enter_sub();
2003 IR->vendor_details(\%myconfig, \%$form, @_);
2005 $lxdebug->leave_sub();
2009 $lxdebug->enter_sub();
2011 $form->{postasnew} = 1;
2012 map { delete $form->{$_} } qw(printed emailed queued);
2016 $lxdebug->leave_sub();
2020 $lxdebug->enter_sub();
2021 if ($form->{second_run}) {
2022 $form->{print_and_post} = 0;
2025 $title = $form->{title};
2026 $form->{title} = $locale->text('Ship to');
2028 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2029 qw(exchangerate creditlimit creditremaining);
2032 qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry
2033 shiptocontact shiptophone shiptofax shiptoemail
2034 shiptodepartment_1 shiptodepartment_2);
2037 (qw(name department_1 department_2 street zipcode city country
2038 contact email phone fax));
2040 # get details for name
2041 &{"$form->{vc}_details"}(@addr_vars);
2044 ($form->{vc} eq 'customer')
2045 ? $locale->text('Customer Number')
2046 : $locale->text('Vendor Number');
2048 # get pricegroups for parts
2049 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
2051 # build up html code for prices_$i
2052 set_pricegroup($form->{rowcount});
2054 $nextsub = ($form->{display_form}) ? $form->{display_form} : "display_form";
2056 $form->{rowcount}--;
2063 <form method="post" action="$form->{script}">
2065 <table width="100%">
2069 <tr class="listheading">
2070 <th class="listheading" colspan="2" width="50%">|
2071 . $locale->text('Billing Address') . qq|</th>
2072 <th class="listheading" width="50%">|
2073 . $locale->text('Shipping Address') . qq|</th>
2075 <tr height="5"></tr>
2077 <th align="right" nowrap>$number</th>
2078 <td>$form->{"$form->{vc}number"}</td>
2081 <th align="right" nowrap>| . $locale->text('Company Name') . qq|</th>
2082 <td>$form->{name}</td>
2083 <td><input name="shiptoname" size="35" value="$form->{shiptoname}"></td>
2086 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
2087 <td>$form->{department_1}</td>
2088 <td><input name="shiptodepartment_1" size="35" value="$form->{shiptodepartment_1}"></td>
2091 <th align="right" nowrap> </th>
2092 <td>$form->{department_2}</td>
2093 <td><input name="shiptodepartment_2" size="35" value="$form->{shiptodepartment_2}"></td>
2096 <th align="right" nowrap>| . $locale->text('Street') . qq|</th>
2097 <td>$form->{street}</td>
2098 <td><input name="shiptostreet" size="35" value="$form->{shiptostreet}"></td>
2101 <th align="right" nowrap>| . $locale->text('Zipcode') . qq|</th>
2102 <td>$form->{zipcode}</td>
2103 <td><input name="shiptozipcode" size="35" value="$form->{shiptozipcode}"></td>
2106 <th align="right" nowrap>| . $locale->text('City') . qq|</th>
2107 <td>$form->{city}</td>
2108 <td><input name="shiptocity" size="35" value="$form->{shiptocity}"></td>
2111 <th align="right" nowrap>| . $locale->text('Country') . qq|</th>
2112 <td>$form->{country}</td>
2113 <td><input name="shiptocountry" size="35" value="$form->{shiptocountry}"></td>
2116 <th align="right" nowrap>| . $locale->text('Contact') . qq|</th>
2117 <td>$form->{contact}</td>
2118 <td><input name="shiptocontac"t size="35" value="$form->{shiptocontact}"></td>
2121 <th align="right" nowrap>| . $locale->text('Phone') . qq|</th>
2122 <td>$form->{phone}</td>
2123 <td><input name="shiptophone" size="20" value="$form->{shiptophone}"></td>
2126 <th align="right" nowrap>| . $locale->text('Fax') . qq|</th>
2127 <td>$form->{fax}</td>
2128 <td><input name="shiptofax" size="20" value="$form->{shiptofax}"></td>
2131 <th align="right" nowrap>| . $locale->text('E-mail') . qq|</th>
2132 <td>$form->{email}</td>
2133 <td><input name="shiptoemail" size="35" value="$form->{shiptoemail}"></td>
2139 | . $cgi->hidden("-name" => "nexsub", "-value" => $nextsub);
2145 map({ delete $form->{$_} } (@shipto_vars, qw(header)));
2146 $form->{title} = $title;
2148 foreach $key (keys %$form) {
2149 $form->{$key} =~ s/\"/"/g;
2150 print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
2155 <hr size="3" noshade>
2158 <input class="submit" type="submit" name="action" value="|
2159 . $locale->text('Continue') . qq|">
2166 $lxdebug->leave_sub();
2170 $lxdebug->enter_sub();
2175 $form->{old_callback} = $form->escape($form->{callback}, 1);
2176 $form->{callback} = $form->escape("$form->{script}?action=display_form", 1);
2177 $form->{old_callback} = $form->escape($form->{old_callback}, 1);
2180 delete $form->{action};
2181 $customer = $form->{customer};
2182 map { $form->{"old_$_"} = $form->{"${_}_$row"} } qw(partnumber description);
2184 # save all other form variables in a previousform variable
2185 $form->{row} = $row;
2186 foreach $key (keys %$form) {
2189 $form->{$key} =~ s/&/%26/g;
2190 $previousform .= qq|$key=$form->{$key}&|;
2193 $previousform = $form->escape($previousform, 1);
2195 $form->{script} = "licenses.pl";
2197 map { $form->{$_} = $form->{"old_$_"} } qw(partnumber description);
2198 map { $form->{$_} = $form->escape($form->{$_}, 1) }
2199 qw(partnumber description);
2201 qq|$form->{script}?login=$form->{login}&path=$form->{path}&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|;
2204 $lxdebug->leave_sub();
2207 sub relink_accounts {
2208 $lxdebug->enter_sub();
2210 $form->{"taxaccounts"} =~ s/\s*$//;
2211 $form->{"taxaccounts"} =~ s/^\s*//;
2212 foreach my $accno (split(/\s*/, $form->{"taxaccounts"})) {
2213 map({ delete($form->{"${accno}_${_}"}); } qw(rate description taxnumber));
2215 $form->{"taxaccounts"} = "";
2217 for (my $i = 1; $i <= $form->{"rowcount"}; $i++) {
2218 if ($form->{"id_$i"}) {
2219 IC->retrieve_accounts(\%myconfig, $form, $form->{"id_$i"}, $i, 1);
2223 $lxdebug->leave_sub();
2227 $lxdebug->enter_sub();
2229 $form->get_duedate(\%myconfig);
2232 $result = "$form->{duedate}";
2235 $lxdebug->leave_sub();