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')
156 qq|<th align=left nowrap width=5 class=listheading>|
157 . $locale->text('Ship')
160 qq|<th align=left nowrap width=5 class=listheading>|
161 . $locale->text('Qty')
164 qq|<th align=left nowrap width=5 class=listheading>|
165 . $locale->text('Unit')
167 $column_data{license} =
168 qq|<th align=left nowrap width=10 class=listheading>|
169 . $locale->text('License')
171 $column_data{serialnr} =
172 qq|<th align=left nowrap width=10 class=listheading>|
173 . $locale->text('Serial No.')
175 $column_data{projectnr} =
176 qq|<th align=left nowrap width=10 class=listheading>|
177 . $locale->text('Project')
179 $column_data{sellprice} =
180 qq|<th align=left nowrap width=15 class=listheading>|
181 . $locale->text('Price')
183 $column_data{sellprice_pg} =
184 qq|<th align=left nowrap width=15 class=listheading>|
185 . $locale->text('Pricegroup')
187 $column_data{discount} =
188 qq|<th align=left class=listheading>|
189 . $locale->text('Discount')
191 $column_data{linetotal} =
192 qq|<th align=left nowrap width=10 class=listheading>|
193 . $locale->text('Extended')
196 qq|<th align=left nowrap width=10 class=listheading>|
197 . $locale->text('Bin')
199 ############## ENDE Neueintrag ##################
201 $form->{"show_details"} =
202 !defined($form->{"show_details"}) ? 1 :
203 $form->{"show_details"} ? 1 : 0;
204 my $show_details_new = 1 - $form->{"show_details"};
205 my $show_details_checked = $form->{"show_details"} ? "checked" : "";
210 <input type="hidden" name="show_details" value="$form->{show_details}">
211 <input type="checkbox" id="cb_show_details" onclick="show_form_details($show_details_new);" $show_details_checked>
212 <label for="cb_show_details">| . $locale->text("Show details") . qq|</label><br>
214 <tr class=listheading>|;
216 map { print "\n$column_data{$_}" } @column_index;
222 $runningnumber = $locale->text('No.');
223 $deliverydate = $locale->text('Delivery Date');
224 $serialnumber = $locale->text('Serial No.');
225 $projectnumber = $locale->text('Project');
226 $partsgroup = $locale->text('Group');
227 $reqdate = $locale->text('Reqdate');
229 $delvar = 'deliverydate';
231 if ($form->{type} =~ /_order$/ || $form->{type} =~ /_quotation$/) {
232 $deliverydate = $locale->text('Required by');
236 for $i (1 .. $numrows) {
241 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
242 } qw(qty ship discount sellprice price_new price_old) unless ($form->{simple_save});
244 if (!$form->{"unit_old_$i"}) {
245 # Neue Ware aus der Datenbank. In diesem Fall ist unit_$i die
246 # Einheit, wie sie in den Stammdaten hinterlegt wurde.
247 # Es sollte also angenommen werden, dass diese ausgewaehlt war.
248 $form->{"unit_old_$i"} = $form->{"unit_$i"};
253 # Die zuletzt ausgewaehlte mit der aktuell ausgewaehlten Einheit
254 # vergleichen und bei Unterschied den Preis entsprechend umrechnen.
255 $form->{"selected_unit_$i"} = $form->{"unit_$i"} unless ($form->{"selected_unit_$i"});
257 my $check_units = $form->{"inventory_accno_$i"} ? $dimension_units : $service_units;
258 if (!$check_units->{$form->{"selected_unit_$i"}} ||
259 ($check_units->{$form->{"selected_unit_$i"}}->{"base_unit"} ne
260 $all_units->{$form->{"unit_old_$i"}}->{"base_unit"})) {
261 # Die ausgewaehlte Einheit ist fuer diesen Artikel nicht gueltig
262 # (z.B. Dimensionseinheit war ausgewaehlt, es handelt sich aber
263 # um eine Dienstleistung). Dann keinerlei Umrechnung vornehmen.
264 $form->{"unit_old_$i"} = $form->{"selected_unit_$i"} = $form->{"unit_$i"};
266 if ((!$form->{"prices_$i"}) || ($form->{"new_pricegroup_$i"} == $form->{"old_pricegroup_$i"})) {
267 if ($form->{"unit_old_$i"} ne $form->{"selected_unit_$i"}) {
269 if (defined($all_units->{$form->{"unit_old_$i"}}->{"factor"}) &&
270 $all_units->{$form->{"unit_old_$i"}}->{"factor"}) {
271 $basefactor = $all_units->{$form->{"selected_unit_$i"}}->{"factor"} /
272 $all_units->{$form->{"unit_old_$i"}}->{"factor"};
274 $form->{"sellprice_$i"} *= $basefactor;
275 $form->{"unit_old_$i"} = $form->{"selected_unit_$i"};
278 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
280 $decimalplaces = ($dec > 2) ? $dec : 2;
284 $form->{"sellprice_$i"} * $form->{"discount_$i"} / 100,
288 $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
289 $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
291 # convert " to "
292 map { $form->{"${_}_$i"} =~ s/\"/"/g }
293 qw(partnumber description unit unit_old);
295 ########################################
296 # Eintrag fuer Version 2.2.0 geaendert #
297 # neue Optik im Rechnungsformular #
298 ########################################
299 $column_data{runningnumber} =
300 qq|<td><input name="runningnumber_$i" size=5 value=$i></td>|; # HuT
301 ############## ENDE Neueintrag ##################
303 $column_data{partnumber} =
304 qq|<td><input name="partnumber_$i" size=12 value="$form->{"partnumber_$i"}"></td>|;
306 if (($rows = $form->numtextrows($form->{"description_$i"}, 30, 6)) > 1) {
307 $column_data{description} =
308 qq|<td><textarea name="description_$i" rows=$rows cols=30 wrap=soft>$form->{"description_$i"}</textarea><button type="button" onclick="set_longdescription_window('longdescription_$i')">| . $locale->text('L') . qq|</button></td>|;
310 $column_data{description} =
311 qq|<td><input name="description_$i" size=30 value="$form->{"description_$i"}"><button type="button" onclick="set_longdescription_window('longdescription_$i')">| . $locale->text('L') . qq|</button></td>|;
314 (my $qty_dec) = ($form->{"qty_$i"} =~ /\.(\d+)/);
315 $qty_dec = length $qty_dec;
318 qq|<td align=right><input name="qty_$i" size=5 value=|
319 . $form->format_amount(\%myconfig, $form->{"qty_$i"}, $qty_dec) .qq|>|;
320 if ($form->{"formel_$i"}) {
321 $column_data{qty} .= qq|<button type="button" onclick="calculate_qty_selection_window('qty_$i','alu_$i', 'formel_$i', $i)">| . $locale->text('*/') . qq|</button>
322 <input type=hidden name="formel_$i" value="$form->{"formel_$i"}"><input type=hidden name="alu_$i" value="$form->{"alu_$i"}"></td>|;
325 qq|<td align=right><input name="ship_$i" size=5 value=|
326 . $form->format_amount(\%myconfig, $form->{"ship_$i"})
329 my $is_part = $form->{"inventory_accno_$i"};
330 my $is_assigned = $form->{"id_$i"};
331 my $this_unit = $form->{"unit_$i"};
332 if ($form->{"selected_unit_$i"} && $this_unit &&
333 $all_units->{$form->{"selected_unit_$i"}} && $all_units->{$this_unit} &&
334 ($all_units->{$form->{"selected_unit_$i"}}->{"base_unit"} eq $all_units->{$this_unit}->{"base_unit"})) {
335 $this_unit = $form->{"selected_unit_$i"};
336 } elsif (!$is_assigned ||
337 ($is_part && !$this_unit && ($all_units->{$this_unit} && ($all_units->{$this_unit}->{"base_unit"} eq $all_units->{"kg"}->{"base_unit"})))) {
341 $column_data{"unit"} = "<td>" .
342 ($qty_readonly ? " " :
343 AM->unit_select_html($is_part ? $dimension_units :
344 $is_assigned ? $service_units : $all_units,
345 "unit_$i", $this_unit,
346 $is_assigned ? $form->{"unit_$i"} : undef))
349 # build in drop down list for pricesgroups
350 if ($form->{"prices_$i"}) {
351 if ($form->{"new_pricegroup_$i"} != $form->{"old_pricegroup_$i"}) {
352 $price_tmp = $form->format_amount(\%myconfig, $form->{"price_new_$i"}, $decimalplaces);
354 $price_tmp = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
357 $column_data{sellprice_pg} =
358 qq|<td align=right><select name="sellprice_pg_$i">$form->{"prices_$i"}</select></td>|;
359 $column_data{sellprice} =
360 qq|<td><input name="sellprice_$i" size=10 value=$price_tmp></td>|;
363 # for last row and report
364 # set pricegroup drop down list from report menu
365 if ($form->{"sellprice_$i"} != 0) {
367 qq|<option value="$form->{"sellprice_$i"}--$form->{"pricegroup_id_$i"}" selected>$form->{"pricegroup_$i"}</option>\n|;
369 $form->{"pricegroup_old_$i"} = $form->{"pricegroup_id_$i"};
371 $column_data{sellprice_pg} =
372 qq|<td align=right><select name="sellprice_pg_$i">$prices</select></td>|;
377 $column_data{sellprice_pg} = qq|<td align=right> </td>|;
380 $column_data{sellprice} =
381 qq|<td><input name="sellprice_$i" size=10 value=|
382 . $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
386 $column_data{discount} =
387 qq|<td align=right><input name="discount_$i" size=3 value=|
388 . $form->format_amount(\%myconfig, $form->{"discount_$i"})
390 $column_data{linetotal} =
392 . $form->format_amount(\%myconfig, $linetotal, 2)
394 $column_data{bin} = qq|<td>$form->{"bin_$i"}</td>|;
396 ########################################
397 # Eintrag fuer Version 2.2.0 geaendert #
398 # neue Optik im Rechnungsformular #
399 ########################################
400 # if ($lizenzen && $form->{type} eq "invoice" && $form->{vc} eq "customer") {
401 # $column_data{license} = qq|<td><select name="licensenumber_$i">$form->{"lizenzen_$i"}></select></td>|;
404 # if ($form->{type} !~ /_quotation/) {
405 # $column_data{serialnr} = qq|<td><input name="serialnumber_$i" size=10 value="$form->{"serialnumber_$i"}"></td>|;
408 # $column_data{projectnr} = qq|<td><input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}"></td>|;
409 ############## ENDE Neueintrag ##################
413 <tr valign=top class=listrow$j>|;
415 map { print "\n$column_data{$_}" } @column_index;
420 <input type=hidden name="orderitems_id_$i" value=$form->{"orderitems_id_$i"}>
421 <input type=hidden name="bo_$i" value=$form->{"bo_$i"}>
423 <input type=hidden name="pricegroup_old_$i" value=$form->{"pricegroup_old_$i"}>
424 <input type=hidden name="price_old_$i" value=$form->{"price_old_$i"}>
425 <input type=hidden name="unit_old_$i" value="$form->{"selected_unit_$i"}">
426 <input type=hidden name="price_new_$i" value=|
427 . $form->format_amount(\%myconfig, $form->{"price_new_$i"}) . qq|>
429 <input type=hidden name="id_$i" value=$form->{"id_$i"}>
430 <input type=hidden name="inventory_accno_$i" value=$form->{"inventory_accno_$i"}>
431 <input type=hidden name="bin_$i" value="$form->{"bin_$i"}">
432 <input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">
433 <input type=hidden name="partnotes_$i" value="$form->{"partnotes_$i"}">
434 <input type=hidden name="income_accno_$i" value=$form->{"income_accno_$i"}>
435 <input type=hidden name="expense_accno_$i" value=$form->{"expense_accno_$i"}>
436 <input type=hidden name="listprice_$i" value="$form->{"listprice_$i"}">
437 <input type=hidden name="assembly_$i" value="$form->{"assembly_$i"}">
438 <input type=hidden name="taxaccounts_$i" value="$form->{"taxaccounts_$i"}">
439 <input type=hidden name="ordnumber_$i" value="$form->{"ordnumber_$i"}">
440 <input type=hidden name="transdate_$i" value="$form->{"transdate_$i"}">
441 <input type=hidden name="cusordnumber_$i" value="$form->{"cusordnumber_$i"}">
442 <input type=hidden name="longdescription_$i" value="$form->{"longdescription_$i"}">
443 <input type=hidden name="basefactor_$i" value="$form->{"basefactor_$i"}">
447 ########################################
448 # Eintrag fuer Version 2.2.0 geaendert #
449 # neue Optik im Rechnungsformular #
450 ########################################
453 'style="display:none;"' if (!$form->{"show_details"});
457 <tr class=listrow$j $row_style_attr>
458 <td colspan=$colspan>
460 if ($lizenzen && $form->{type} eq "invoice" && $form->{vc} eq "customer") {
461 my $selected = $form->{"licensenumber_$i"};
463 $form->{"lizenzen_$i"} =~ s/ selected//g;
464 $form->{"lizenzen_$i"} =~
465 s/value="${selected}"\>/value="${selected}" selected\>/;
466 $lizenzen_quoted = $form->{"lizenzen_$i"};
467 $lizenzen_quoted =~ s/\"/"/g;
469 <b>Lizenz\#</b> <select name="licensenumber_$i" size=1>
470 $form->{"lizenzen_$i"}
472 <input type=hidden name="lizenzen_$i" value="${lizenzen_quoted}">
475 if ($form->{type} !~ /_quotation/) {
477 <b>$serialnumber</b> <input name="serialnumber_$i" size=15 value="$form->{"serialnumber_$i"}">|;
481 <b>$projectnumber</b> <input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}">
482 <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}">
483 <input type=hidden name="project_id_$i" value="$form->{"project_id_$i"}">
485 if ($form->{type} eq 'invoice' or $form->{type} =~ /order/) {
487 ($form->{type} eq 'invoice')
489 : 'reqdate'; # invoice uses a different term for the same thing.
491 <b>${$reqdate_term}</b> <input name="${reqdate_term}_$i" size=11 value="$form->{"${reqdate_term}_$i"}">
494 my $subtotalchecked = ($form->{"subtotal_$i"}) ? "checked" : "";
496 <b>|.$locale->text('Subtotal').qq|</b> <input type="checkbox" name="subtotal_$i" value="1" "$subtotalchecked">
502 ############## ENDE Neueintrag ##################
504 map { $form->{"${_}_base"} += $linetotal }
505 (split / /, $form->{"taxaccounts_$i"});
507 $form->{invsubtotal} += $linetotal;
516 $lxdebug->leave_sub();
519 ##################################################
520 # build html-code for pricegroups in variable $form->{prices_$j}
523 $lxdebug->enter_sub();
524 my $rowcount = shift;
525 for $j (1 .. $rowcount) {
526 my $pricegroup_old = $form->{"pricegroup_old_$i"};
527 if ($form->{PRICES}{$j}) {
529 $prices = '<option value="--">' . $locale->text("none (pricegroup)") . '</option>';
531 foreach $item (@{ $form->{PRICES}{$j} }) {
533 #$price = $form->round_amount($myconfig, $item->{price}, 5);
534 #$price = $form->format_amount($myconfig, $item->{price}, 2);
535 $price = $item->{price};
536 $pricegroup_id = $item->{pricegroup_id};
537 $pricegroup = $item->{pricegroup};
539 # build drop down list for pricegroups
541 qq|<option value="$price--$pricegroup_id"$item->{selected}>$pricegroup</option>\n|;
546 # $form->{"${_}_$j"} =
547 # $form->format_amount(\%myconfig, $form->{"${_}_$j"})
548 # } qw(sellprice price_new price_old);
550 # set new selectedpricegroup_id and prices for "Preis"
551 if ($item->{selected} && ($pricegroup_id != 0)) {
552 $form->{"pricegroup_old_$j"} = $pricegroup_id;
553 $form->{"price_new_$j"} = $price;
554 $form->{"sellprice_$j"} = $price;
556 if ($pricegroup_id == 0) {
557 $form->{"price_new_$j"} = $form->{"sellprice_$j"};
560 $form->{"prices_$j"} = $prices;
563 $lxdebug->leave_sub();
567 $lxdebug->enter_sub();
568 @column_index = qw(ndx partnumber description onhand unit sellprice);
570 $column_data{ndx} = qq|<th> </th>|;
571 $column_data{partnumber} =
572 qq|<th class=listheading>| . $locale->text('Number') . qq|</th>|;
573 $column_data{description} =
574 qq|<th class=listheading>| . $locale->text('Part Description') . qq|</th>|;
575 $column_data{sellprice} =
576 qq|<th class=listheading>| . $locale->text('Price') . qq|</th>|;
577 $column_data{onhand} =
578 qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|;
580 qq|<th class=listheading>| . $locale->text('Unit') . qq|</th>|;
581 # list items with radio button on a form
584 $title = $locale->text('Select from one of the items below');
585 $colspan = $#column_index + 1;
590 <form method=post action=$form->{script}>
594 <th class=listtop colspan=$colspan>$title</th>
597 <tr class=listheading>|;
599 map { print "\n$column_data{$_}" } @column_index;
604 foreach $ref (@{ $form->{item_list} }) {
605 $checked = ($i++) ? "" : "checked";
608 if ($ref->{inventory_accno} > 0) {
609 $ref->{"lizenzen"} = qq|<option></option>|;
610 foreach $item (@{ $form->{LIZENZEN}{ $ref->{"id"} } }) {
611 $ref->{"lizenzen"} .=
612 qq|<option value=\"$item->{"id"}\">$item->{"licensenumber"}</option>|;
614 $ref->{"lizenzen"} .= qq|<option value=-1>Neue Lizenz</option>|;
615 $ref->{"lizenzen"} =~ s/\"/"/g;
619 map { $ref->{$_} =~ s/\"/"/g } qw(partnumber description unit);
623 $form->round_amount($ref->{sellprice} * (1 - $form->{tradediscount}), 2);
625 qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
626 $column_data{partnumber} =
627 qq|<td><input name="new_partnumber_$i" type=hidden value="$ref->{partnumber}">$ref->{partnumber}</td>|;
628 $column_data{description} =
629 qq|<td><input name="new_description_$i" type=hidden value="$ref->{description}">$ref->{description}</td>|;
630 $column_data{sellprice} =
631 qq|<td align=right><input name="new_sellprice_$i" type=hidden value=$ref->{sellprice}>|
632 . $form->format_amount(\%myconfig, $ref->{sellprice}, 2, " ")
634 $column_data{onhand} =
635 qq|<td align=right><input name="new_onhand_$i" type=hidden value=$ref->{onhand}>|
636 . $form->format_amount(\%myconfig, $ref->{onhand}, '', " ")
639 qq|<td>$ref->{unit}</td>|;
643 <tr class=listrow$j>|;
645 map { print "\n$column_data{$_}" } @column_index;
650 <input name="new_bin_$i" type=hidden value="$ref->{bin}">
651 <input name="new_listprice_$i" type=hidden value=$ref->{listprice}>
652 <input name="new_inventory_accno_$i" type=hidden value=$ref->{inventory_accno}>
653 <input name="new_income_accno_$i" type=hidden value=$ref->{income_accno}>
654 <input name="new_expense_accno_$i" type=hidden value=$ref->{expense_accno}>
655 <input name="new_unit_$i" type=hidden value="$ref->{unit}">
656 <input name="new_weight_$i" type=hidden value="$ref->{weight}">
657 <input name="new_assembly_$i" type=hidden value="$ref->{assembly}">
658 <input name="new_taxaccounts_$i" type=hidden value="$ref->{taxaccounts}">
659 <input name="new_partsgroup_$i" type=hidden value="$ref->{partsgroup}">
660 <input name="new_formel_$i" type=hidden value="$ref->{formel}">
661 <input name="new_longdescription_$i" type=hidden value="$ref->{longdescription}">
662 <input name="new_not_discountable_$i" type=hidden value="$ref->{not_discountable}">
663 <input name="new_part_payment_id_$i" type=hidden value="$ref->{part_payment_id}">
665 <input name="new_id_$i" type=hidden value=$ref->{id}>
670 <input name="new_lizenzen_$i" type=hidden value="$ref->{lizenzen}">
677 <tr><td colspan=8><hr size=3 noshade></td></tr>
680 <input name=lastndx type=hidden value=$i>
684 # delete action variable
685 map { delete $form->{$_} } qw(action item_list header);
687 # save all other form variables
688 foreach $key (keys %${form}) {
689 $form->{$key} =~ s/\"/"/g;
690 print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
694 <input type=hidden name=nextsub value=item_selected>
697 <input class=submit type=submit name=action value="|
698 . $locale->text('Continue') . qq|">
705 $lxdebug->leave_sub();
709 $lxdebug->enter_sub();
711 # replace the last row with the checked row
712 $i = $form->{rowcount};
713 $i = $form->{assembly_rows} if ($form->{item} eq 'assembly');
719 #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
720 #$form->{"sellprice_$i"} = $form->{"sellprice_$i"};
722 # if there was a price entered, override it
723 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
725 map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} }
726 qw(id partnumber description sellprice listprice inventory_accno income_accno expense_accno bin unit weight assembly taxaccounts partsgroup formel longdescription not_discountable);
727 if ($form->{"part_payment_id_$i"} ne "") {
728 $form->{payment_id} = $form->{"part_payment_id_$i"};
732 map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} } qw(lizenzen);
735 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
737 $decimalplaces = ($dec > 2) ? $dec : 2;
740 $form->{"sellprice_$i"} = $sellprice;
743 # if there is an exchange rate adjust sellprice
744 if (($form->{exchangerate} * 1) != 0) {
745 $form->{"sellprice_$i"} /= $form->{exchangerate};
746 $form->{"sellprice_$i"} =
747 $form->round_amount($form->{"sellprice_$i"}, $decimalplaces);
751 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
752 qw(sellprice listprice weight);
754 $form->{sellprice} += ($form->{"sellprice_$i"} * $form->{"qty_$i"});
755 $form->{weight} += ($form->{"weight_$i"} * $form->{"qty_$i"});
757 if ($form->{"not_discountable_$i"}) {
758 $form->{"discount_$i"} = 0;
762 $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) *
764 map { $form->{"${_}_base"} += $amount }
765 (split / /, $form->{"taxaccounts_$i"});
766 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /,
767 $form->{"taxaccounts_$i"}
768 if !$form->{taxincluded};
770 $form->{creditremaining} -= $amount;
772 $form->{"runningnumber_$i"} = $i;
774 # delete all the new_ variables
775 for $i (1 .. $form->{lastndx}) {
776 map { delete $form->{"new_${_}_$i"} }
777 qw(partnumber description sellprice bin listprice inventory_accno income_accno expense_accno unit assembly taxaccounts id);
780 map { delete $form->{$_} } qw(ndx lastndx nextsub);
785 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces)
786 } qw(sellprice listprice) if $form->{item} ne 'assembly';
788 # get pricegroups for parts
789 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
791 # build up html code for prices_$i
792 set_pricegroup($form->{rowcount});
796 $lxdebug->leave_sub();
800 $lxdebug->enter_sub();
803 $form->{old_callback} = $form->escape($form->{callback}, 1);
804 $form->{callback} = $form->escape("$form->{script}?action=display_form", 1);
807 delete $form->{action};
809 # save all other form variables in a previousform variable
810 foreach $key (keys %$form) {
813 $form->{$key} =~ s/&/%26/g;
814 $previousform .= qq|$key=$form->{$key}&|;
817 $previousform = $form->escape($previousform, 1);
819 $i = $form->{rowcount};
820 map { $form->{"${_}_$i"} =~ s/\"/"/g } qw(partnumber description);
827 <h4 class=error>| . $locale->text('Item not on file!') . qq|
830 | . $locale->text('What type of item is this?') . qq|</h4>
832 <form method=post action=ic.pl>
836 <input class=radio type=radio name=item value=part checked> |
837 . $locale->text('Part') . qq|<br>
838 <input class=radio type=radio name=item value=service> |
839 . $locale->text('Service')
842 <input type=hidden name=previousform value="$previousform">
843 <input type=hidden name=partnumber value="$form->{"partnumber_$i"}">
844 <input type=hidden name=description value="$form->{"description_$i"}">
845 <input type=hidden name=rowcount value=$form->{rowcount}>
846 <input type=hidden name=taxaccount2 value=$form->{taxaccounts}>
847 <input type=hidden name=vc value=$form->{vc}>
849 <input type=hidden name=path value=$form->{path}>
850 <input type=hidden name=login value=$form->{login}>
851 <input type=hidden name=password value=$form->{password}>
853 <input type=hidden name=nextsub value=add>
856 <input class=submit type=submit name=action value="|
857 . $locale->text('Continue') . qq|">
864 $lxdebug->leave_sub();
868 $lxdebug->enter_sub();
872 $form->language_payment(\%myconfig);
874 # if we have a display_form
875 if ($form->{display_form}) {
876 &{"$form->{display_form}"};
880 # if ( $form->{print_and_post}
881 # && $form->{second_run}
882 # && ($form->{action} eq "display_form")) {
883 # for (keys %$form) { $old_form->{$_} = $form->{$_} }
884 # $old_form->{rowcount}++;
886 # #$form->{rowcount}--;
887 # #$form->{rowcount}--;
889 # $form->{print_and_post} = 0;
891 # &print_form($old_form);
895 # $form->{action} = "";
896 # $form->{resubmit} = 0;
898 # if ($form->{print_and_post} && !$form->{second_run}) {
899 # $form->{second_run} = 1;
900 # $form->{action} = "display_form";
901 # $form->{rowcount}--;
902 # my $rowcount = $form->{rowcount};
904 # # get pricegroups for parts
905 # IS->get_pricegroups_for_parts(\%myconfig, \%$form);
907 # # build up html code for prices_$i
908 # set_pricegroup($rowcount);
910 # $form->{resubmit} = 1;
915 $numrows = ++$form->{rowcount};
916 $subroutine = "display_row";
918 if ($form->{item} eq 'part') {
920 #set preisgruppenanzahl
921 $numrows = $form->{price_rows};
922 $subroutine = "price_row";
924 &{$subroutine}($numrows);
926 $numrows = ++$form->{makemodel_rows};
927 $subroutine = "makemodel_row";
929 if ($form->{item} eq 'assembly') {
930 $numrows = $form->{price_rows};
931 $subroutine = "price_row";
933 &{$subroutine}($numrows);
935 $numrows = ++$form->{makemodel_rows};
936 $subroutine = "makemodel_row";
938 # create makemodel rows
939 &{$subroutine}($numrows);
941 $numrows = ++$form->{assembly_rows};
942 $subroutine = "assembly_row";
944 if ($form->{item} eq 'service') {
945 $numrows = $form->{price_rows};
946 $subroutine = "price_row";
948 &{$subroutine}($numrows);
954 &{$subroutine}($numrows) if $numrows;
958 $lxdebug->leave_sub();
962 $lxdebug->enter_sub();
966 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)
970 # remove any makes or model rows
971 if ($form->{item} eq 'part') {
972 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
973 qw(listprice sellprice lastcost weight rop);
975 @flds = (make, model);
976 for my $i (1 .. ($form->{makemodel_rows})) {
977 if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
981 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
986 $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
987 $form->{makemodel_rows} = $count;
989 } elsif ($form->{item} eq 'assembly') {
991 $form->{sellprice} = 0;
993 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
994 qw(listprice rop stock);
997 qw(id qty unit bom partnumber description sellprice weight runningnumber partsgroup);
999 for my $i (1 .. ($form->{assembly_rows} - 1)) {
1000 if ($form->{"qty_$i"}) {
1004 $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
1006 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1008 #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
1010 $form->{sellprice} += ($form->{"qty_$i"} * $form->{"sellprice_$i"});
1011 $form->{weight} += ($form->{"qty_$i"} * $form->{"weight_$i"});
1016 $form->{sellprice} = $form->round_amount($form->{sellprice}, 2);
1018 $form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows});
1019 $form->{assembly_rows} = $count;
1022 @flds = qw(make model);
1025 for my $i (1 .. ($form->{makemodel_rows})) {
1026 if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
1030 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1035 $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
1036 $form->{makemodel_rows} = $count;
1040 # this section applies to invoices and orders
1041 # remove any empty numbers
1042 if ($form->{rowcount}) {
1043 for my $i (1 .. $form->{rowcount} - 1) {
1044 if ($form->{"partnumber_$i"}) {
1048 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1051 if ($form->{"licensenumber_$i"} == -1) {
1059 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
1060 $form->{rowcount} = $count;
1062 $form->{creditremaining} -= &invoicetotal;
1069 if ( $form->{type} =~ (/sales_quotation/)
1070 or (($form->{level} =~ /Sales/) and ($form->{type} =~ /invoice/))
1071 or (($form->{level} eq undef) and ($form->{type} =~ /invoice/))
1072 or ($form->{type} =~ /sales_order/)) {
1074 # get pricegroups for parts
1075 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1077 # build up html code for prices_$i
1078 set_pricegroup($form->{rowcount});
1084 $lxdebug->leave_sub();
1088 $lxdebug->enter_sub();
1090 $form->{oldinvtotal} = 0;
1092 # add all parts and deduct paid
1093 map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
1095 my ($amount, $sellprice, $discount, $qty);
1097 for my $i (1 .. $form->{rowcount}) {
1098 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1099 $discount = $form->parse_amount(\%myconfig, $form->{"discount_$i"});
1100 $qty = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
1102 #($form->{"sellprice_$i"}, $form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
1104 $amount = $sellprice * (1 - $discount / 100) * $qty;
1105 map { $form->{"${_}_base"} += $amount }
1106 (split / /, $form->{"taxaccounts_$i"});
1107 $form->{oldinvtotal} += $amount;
1110 map { $form->{oldinvtotal} += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1111 split / /, $form->{taxaccounts}
1112 if !$form->{taxincluded};
1114 $form->{oldtotalpaid} = 0;
1115 for $i (1 .. $form->{paidaccounts}) {
1116 $form->{oldtotalpaid} += $form->{"paid_$i"};
1119 $lxdebug->leave_sub();
1122 return ($form->{oldinvtotal} - $form->{oldtotalpaid});
1125 sub validate_items {
1126 $lxdebug->enter_sub();
1128 # check if items are valid
1129 if ($form->{rowcount} == 1) {
1134 for $i (1 .. $form->{rowcount} - 1) {
1135 $form->isblank("partnumber_$i",
1136 $locale->text('Number missing in Row') . " $i");
1139 $lxdebug->leave_sub();
1143 $lxdebug->enter_sub();
1144 if ($form->{second_run}) {
1145 $form->{print_and_post} = 0;
1147 $form->{ordnumber} = $form->{invnumber};
1149 map { delete $form->{$_} } qw(id printed emailed queued);
1150 if ($form->{script} eq 'ir.pl' || $form->{type} eq 'request_quotation') {
1151 $form->{title} = $locale->text('Add Purchase Order');
1152 $form->{vc} = 'vendor';
1153 $form->{type} = 'purchase_order';
1156 if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_quotation') {
1157 $form->{title} = $locale->text('Add Sales Order');
1158 $form->{vc} = 'customer';
1159 $form->{type} = 'sales_order';
1162 $form->{script} = 'oe.pl';
1164 $form->{shipto} = 1;
1166 $form->{rowcount}--;
1168 $form->{cp_id} *= 1;
1170 require "$form->{path}/$form->{script}";
1172 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1174 $currency = $form->{currency};
1178 $form->{currency} = $currency;
1179 $form->{exchangerate} = "";
1180 $form->{forex} = "";
1181 $form->{exchangerate} = $exchangerate
1185 $form->check_exchangerate(
1186 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1189 for $i (1 .. $form->{rowcount}) {
1190 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
1191 $form->{"${_}_${i}"})
1192 if ($form->{"${_}_${i}"}) }
1193 qw(ship qty sellprice listprice basefactor));
1199 $lxdebug->leave_sub();
1203 $lxdebug->enter_sub();
1204 if ($form->{second_run}) {
1205 $form->{print_and_post} = 0;
1207 map { delete $form->{$_} } qw(id printed emailed queued);
1209 if ($form->{script} eq 'ir.pl' || $form->{type} eq 'purchase_order') {
1210 $form->{title} = $locale->text('Add Request for Quotation');
1211 $form->{vc} = 'vendor';
1212 $form->{type} = 'request_quotation';
1215 if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_order') {
1216 $form->{title} = $locale->text('Add Quotation');
1217 $form->{vc} = 'customer';
1218 $form->{type} = 'sales_quotation';
1222 $form->{cp_id} *= 1;
1224 $form->{script} = 'oe.pl';
1226 $form->{shipto} = 1;
1228 $form->{rowcount}--;
1230 require "$form->{path}/$form->{script}";
1232 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1234 $currency = $form->{currency};
1238 $form->{currency} = $currency;
1239 $form->{exchangerate} = "";
1240 $form->{forex} = "";
1241 $form->{exchangerate} = $exchangerate
1245 $form->check_exchangerate(
1246 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1249 for $i (1 .. $form->{rowcount}) {
1250 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
1251 $form->{"${_}_${i}"})
1252 if ($form->{"${_}_${i}"}) }
1253 qw(ship qty sellprice listprice basefactor));
1259 $lxdebug->leave_sub();
1262 sub request_for_quotation {
1267 $lxdebug->enter_sub();
1268 if ($form->{second_run}) {
1269 $form->{print_and_post} = 0;
1270 $form->{resubmit} = 0;
1272 if ($myconfig{role} eq 'admin') {
1274 <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
1275 <td><input name=bcc size=30 value="$form->{bcc}"></td>
1279 if ($form->{formname} =~ /(pick|packing|bin)_list/) {
1280 $form->{email} = $form->{shiptoemail} if $form->{shiptoemail};
1283 if ($form->{"cp_id"} && !$form->{"email"}) {
1284 CT->get_contact(\%myconfig, $form);
1285 $form->{"email"} = $form->{"cp_email"};
1288 $name = $form->{ $form->{vc} };
1290 $title = $locale->text('E-mail') . " $name";
1292 $form->{oldmedia} = $form->{media};
1293 $form->{media} = "email";
1300 <form method=post action=$form->{script}>
1304 <th class=listtop>$title</th>
1306 <tr height="5"></tr>
1311 <th align=right nowrap>| . $locale->text('To') . qq|</th>
1312 <td><input name=email size=30 value="$form->{email}"></td>
1313 <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
1314 <td><input name=cc size=30 value="$form->{cc}"></td>
1317 <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
1318 <td><input name=subject size=30 value="$form->{subject}"></td>
1328 <th align=left nowrap>| . $locale->text('Message') . qq|</th>
1331 <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
1342 map { delete $form->{$_} }
1343 qw(action email cc bcc subject message formname sendmode format header override);
1345 # save all other variables
1346 foreach $key (keys %$form) {
1347 $form->{$key} =~ s/\"/"/g;
1348 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1355 <td><hr size=3 noshade></td>
1359 <input type=hidden name=nextsub value=send_email>
1362 <input name=action class=submit type=submit value="|
1363 . $locale->text('Continue') . qq|">
1370 $lxdebug->leave_sub();
1374 $lxdebug->enter_sub();
1376 $old_form = new Form;
1378 map { $old_form->{$_} = $form->{$_} } keys %$form;
1379 $old_form->{media} = $form->{oldmedia};
1381 &print_form($old_form);
1383 $lxdebug->leave_sub();
1387 $lxdebug->enter_sub();
1388 $form->{sendmode} = "attachment";
1391 $form->{"format"} ? $form->{"format"} :
1392 $myconfig{"template_format"} ? $myconfig{"template_format"} :
1396 $form->{"copies"} ? $form->{"copies"} :
1397 $myconfig{"copies"} ? $myconfig{"copies"} :
1400 $form->{PD}{ $form->{formname} } = "selected";
1401 $form->{DF}{ $form->{format} } = "selected";
1402 $form->{OP}{ $form->{media} } = "selected";
1403 $form->{SM}{ $form->{sendmode} } = "selected";
1405 if ($form->{type} eq 'purchase_order') {
1406 $type = qq|<select name=formname>
1407 <option value=purchase_order $form->{PD}{purchase_order}>|
1408 . $locale->text('Purchase Order') . qq|
1409 <option value=bin_list $form->{PD}{bin_list}>|
1410 . $locale->text('Bin List');
1413 if ($form->{type} eq 'credit_note') {
1414 $type = qq|<select name=formname>
1415 <option value=credit_note $form->{PD}{credit_note}>|
1416 . $locale->text('Credit Note');
1419 if ($form->{type} eq 'sales_order') {
1420 $type = qq|<select name=formname>
1421 <option value=sales_order $form->{PD}{sales_order}>|
1422 . $locale->text('Confirmation') . qq|
1423 <option value=proforma $form->{PD}{proforma}>|
1424 . $locale->text('Proforma Invoice') . qq|
1425 <option value=pick_list $form->{PD}{pick_list}>|
1426 . $locale->text('Pick List') . qq|
1427 <option value=packing_list $form->{PD}{packing_list}>|
1428 . $locale->text('Packing List');
1431 if ($form->{type} =~ /_quotation$/) {
1432 $type = qq|<select name=formname>
1433 <option value="$`_quotation" $form->{PD}{"$`_quotation"}>|
1434 . $locale->text('Quotation');
1437 if ($form->{type} eq 'invoice') {
1438 $type = qq|<select name=formname>
1439 <option value=invoice $form->{PD}{invoice}>|
1440 . $locale->text('Invoice') . qq|
1441 <option value=proforma $form->{PD}{proforma}>|
1442 . $locale->text('Proforma Invoice') . qq|
1443 <option value=packing_list $form->{PD}{packing_list}>|
1444 . $locale->text('Packing List');
1447 if ($form->{type} eq 'invoice' && $form->{storno}) {
1448 $type = qq|<select name=formname>
1449 <option value=storno_invoice $form->{PD}{storno_invoice}>|
1450 . $locale->text('Storno Invoice') . qq|
1451 <option value=storno_packing_list $form->{PD}{storno_packing_list}>|
1452 . $locale->text('Storno Packing List');
1455 if ($form->{type} eq 'credit_note') {
1456 $type = qq|<select name=formname>
1457 <option value=credit_note $form->{PD}{credit_note}>|
1458 . $locale->text('Credit Note');
1461 if ($form->{type} eq 'ship_order') {
1462 $type = qq|<select name=formname>
1463 <option value=pick_list $form->{PD}{pick_list}>|
1464 . $locale->text('Pick List') . qq|
1465 <option value=packing_list $form->{PD}{packing_list}>|
1466 . $locale->text('Packing List');
1469 if ($form->{type} eq 'receive_order') {
1470 $type = qq|<select name=formname>
1471 <option value=bin_list $form->{PD}{bin_list}>|
1472 . $locale->text('Bin List');
1475 if ($form->{media} eq 'email') {
1476 $media = qq|<select name=sendmode>
1477 <option value=attachment $form->{SM}{attachment}>|
1478 . $locale->text('Attachment') . qq|
1479 <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
1481 $media = qq|<select name=media>
1482 <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
1483 if (scalar(keys (%{ $form->{printers} })) !=0 && $latex_templates) {
1485 <option value=printer $form->{OP}{printer}>|
1486 . $locale->text('Printer');
1488 if ($latex_templates) {
1490 <option value=queue $form->{OP}{queue}>| . $locale->text('Queue');
1494 $format = qq|<select name=format>|;
1495 if ($opendocument_templates && $openofficeorg_writer_bin &&
1496 $xvfb_bin && (-x $openofficeorg_writer_bin) && (-x $xvfb_bin)) {
1497 $format .= qq|<option value=opendocument_pdf | .
1498 $form->{DF}{"opendocument_pdf"} . qq|>| .
1499 $locale->text("PDF (OpenDocument/OASIS)") . qq|</option>|;
1502 if ($latex_templates) {
1503 $format .= qq|<option value=pdf $form->{DF}{pdf}>| .
1504 $locale->text('PDF') . qq|</option>|;
1507 $format .= qq|<option value=html $form->{DF}{html}>HTML</option>|;
1509 if ($latex_templates) {
1510 $format .= qq|<option value=postscript $form->{DF}{postscript}>| .
1511 $locale->text('Postscript') . qq|</option>|;
1514 if ($opendocument_templates) {
1515 $format .= qq|<option value=opendocument $form->{DF}{opendocument}>| .
1516 $locale->text("OpenDocument/OASIS") . qq|</option>|;
1518 $format .= qq|</select>|;
1520 if (scalar(keys (%{ $form->{languages} })) !=0) {
1521 $language_select = qq|<select name=language_id>
1522 <option value=""></option>}|;
1523 foreach $item (@{ $form->{languages} }) {
1524 if ($form->{language_id} eq $item->{id}) {
1525 $language_select .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
1527 $language_select .= qq|<option value="$item->{id}">$item->{description}</option>|;
1532 if (scalar(keys (%{ $form->{printers} })) !=0) {
1534 $printer_select = qq|<select name=printer_id>
1535 <option value=""></option>|;
1536 foreach $item (@{ $form->{printers} }) {
1537 $printer_select .= qq|<option value="$item->{id}">$item->{printer_description}</option>|;
1544 <table width=100% cellspacing=0 cellpadding=0>
1549 <td>$type</select></td>|;
1550 if (scalar(keys (%{ $form->{languages} })) !=0) {
1552 <td>${language_select}</select></td>|;
1555 <td>$format</select></td>
1556 <td>$media</select></td>|;
1557 if (scalar(keys (%{ $form->{printers} })) !=0) {
1559 <td>$printer_select</select></td>
1563 if (scalar(keys (%{ $form->{printers} })) !=0 && $latex_templates && $form->{media} ne 'email') {
1565 <td>| . $locale->text('Copies') . qq|
1566 <input name=copies size=2 value=$form->{copies}></td>
1570 $form->{groupitems} = "checked" if $form->{groupitems};
1573 <td>| . $locale->text('Group Items') . qq|</td>
1574 <td><input name=groupitems type=checkbox class=checkbox $form->{groupitems}></td>
1583 if ($form->{printed} =~ /$form->{formname}/) {
1585 <th>\|| . $locale->text('Printed') . qq|\|</th>
1589 if ($form->{emailed} =~ /$form->{formname}/) {
1591 <th>\|| . $locale->text('E-mailed') . qq|\|</th>
1595 if ($form->{queued} =~ /$form->{formname}/) {
1597 <th>\|| . $locale->text('Queued') . qq|\|</th>
1609 $lxdebug->leave_sub();
1613 $lxdebug->enter_sub();
1615 # if this goes to the printer pass through
1616 if ($form->{media} eq 'printer' || $form->{media} eq 'queue') {
1617 $form->error($locale->text('Select postscript or PDF!'))
1618 if ($form->{format} !~ /(postscript|pdf)/);
1620 $old_form = new Form;
1621 map { $old_form->{$_} = $form->{$_} } keys %$form;
1624 if (!$form->{id} || (($form->{formname} eq "proforma") && !$form->{proforma} && (($form->{type} =~ /_order$/) || ($form->{type} =~ /_quotation$/)))) {
1625 if ($form->{formname} eq "proforma") {
1626 $form->{proforma} = 1;
1628 $form->{print_and_save} = 1;
1629 my $formname = $form->{formname};
1631 $form->{formname} = $formname;
1636 &print_form($old_form);
1638 $lxdebug->leave_sub();
1642 $lxdebug->enter_sub();
1643 my ($old_form) = @_;
1647 $numberfld = "invnumber";
1650 ($form->{display_form}) ? $form->{display_form} : "display_form";
1652 # $form->{"notes"} will be overridden by the customer's/vendor's "notes" field. So save it here.
1653 $form->{ $form->{"formname"} . "notes" } = $form->{"notes"};
1655 if ($form->{formname} eq "invoice") {
1656 $form->{label} = $locale->text('Invoice');
1658 if ($form->{formname} eq "packing_list") {
1660 # this is from an invoice
1661 $form->{label} = $locale->text('Packing List');
1663 if ($form->{formname} eq 'sales_order') {
1666 $form->{"${inv}date"} = $form->{transdate};
1667 $form->{label} = $locale->text('Sales Order');
1668 $numberfld = "sonumber";
1672 if (($form->{type} eq 'invoice') && ($form->{formname} eq 'proforma') ) {
1675 $form->{"${inv}date"} = $form->{transdate};
1676 $form->{"invdate"} = $form->{transdate};
1677 $form->{label} = $locale->text('Proforma Invoice');
1678 $numberfld = "sonumber";
1682 if (($form->{type} eq 'sales_order') && ($form->{formname} eq 'proforma') ) {
1685 $form->{"${inv}date"} = $form->{transdate};
1686 $form->{"invdate"} = $form->{transdate};
1687 $form->{invnumber} = $form->{ordnumber};
1688 $form->{label} = $locale->text('Proforma Invoice');
1689 $numberfld = "sonumber";
1693 if ($form->{formname} eq 'packing_list' && $form->{type} ne 'invoice') {
1695 # we use the same packing list as from an invoice
1698 $form->{invdate} = $form->{"${inv}date"} = $form->{transdate};
1699 $form->{label} = $locale->text('Packing List');
1701 # set invnumber for template packing_list
1702 $form->{invnumber} = $form->{ordnumber};
1704 if ($form->{formname} eq 'pick_list') {
1707 $form->{"${inv}date"} =
1708 ($form->{transdate}) ? $form->{transdate} : $form->{invdate};
1709 $form->{label} = $locale->text('Pick List');
1710 $order = 1 unless $form->{type} eq 'invoice';
1712 if ($form->{formname} eq 'purchase_order') {
1715 $form->{"${inv}date"} = $form->{transdate};
1716 $form->{label} = $locale->text('Purchase Order');
1717 $numberfld = "ponumber";
1720 if ($form->{formname} eq 'bin_list') {
1723 $form->{"${inv}date"} = $form->{transdate};
1724 $form->{label} = $locale->text('Bin List');
1727 if ($form->{formname} eq 'sales_quotation') {
1730 $form->{"${inv}date"} = $form->{transdate};
1731 $form->{label} = $locale->text('Quotation');
1732 $numberfld = "sqnumber";
1736 if (($form->{type} eq 'sales_quotation') && ($form->{formname} eq 'proforma') ) {
1739 $form->{"${inv}date"} = $form->{transdate};
1740 $form->{"invdate"} = $form->{transdate};
1741 $form->{label} = $locale->text('Proforma Invoice');
1742 $numberfld = "sqnumber";
1746 if ($form->{formname} eq 'request_quotation') {
1749 $form->{"${inv}date"} = $form->{transdate};
1750 $form->{label} = $locale->text('Quotation');
1751 $numberfld = "rfqnumber";
1755 $form->isblank("email", $locale->text('E-mail address missing!'))
1756 if ($form->{media} eq 'email');
1757 $form->isblank("${inv}date",
1758 $locale->text($form->{label} . ' Date missing!'));
1760 # $locale->text('Invoice Number missing!')
1761 # $locale->text('Invoice Date missing!')
1762 # $locale->text('Packing List Number missing!')
1763 # $locale->text('Packing List Date missing!')
1764 # $locale->text('Order Number missing!')
1765 # $locale->text('Order Date missing!')
1766 # $locale->text('Quotation Number missing!')
1767 # $locale->text('Quotation Date missing!')
1770 if (!$form->{"${inv}number"} && !$form->{preview}) {
1771 $form->{"${inv}number"} = $form->update_defaults(\%myconfig, $numberfld);
1772 if ($form->{media} ne 'email') {
1774 # get pricegroups for parts
1775 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1777 # build up html code for prices_$i
1778 set_pricegroup($form->{rowcount});
1780 $form->{rowcount}--;
1789 # Save the email address given in the form because it should override the setting saved for the customer/vendor.
1790 my ($saved_email, $saved_cc, $saved_bcc) =
1791 ($form->{"email"}, $form->{"cc"}, $form->{"bcc"});
1793 $language_saved = $form->{language_id};
1794 $payment_id_saved = $form->{payment_id};
1796 &{"$form->{vc}_details"};
1798 $form->{language_id} = $language_saved;
1799 $form->{payment_id} = $payment_id_saved;
1801 $form->{"email"} = $saved_email if ($saved_email);
1802 $form->{"cc"} = $saved_cc if ($saved_cc);
1803 $form->{"bcc"} = $saved_bcc if ($saved_bcc);
1805 my ($language_tc, $output_numberformat, $output_dateformat, $output_longdates);
1806 if ($form->{"language_id"}) {
1807 ($language_tc, $output_numberformat, $output_dateformat, $output_longdates) =
1808 AM->get_language_details(\%myconfig, $form, $form->{language_id});
1810 $output_dateformat = $myconfig{"dateformat"};
1811 $output_numberformat = $myconfig{"numberformat"};
1812 $output_longdates = 1;
1815 ($form->{employee}) = split /--/, $form->{employee};
1816 ($form->{warehouse}, $form->{warehouse_id}) = split /--/, $form->{warehouse};
1818 # create the form variables
1820 OE->order_details(\%myconfig, \%$form);
1822 IS->invoice_details(\%myconfig, \%$form, $locale);
1825 if ($form->{shipto_id}) {
1826 $form->get_shipto(\%myconfig);
1829 @a = qw(name street zipcode city country);
1833 # if there is no shipto fill it in from billto
1834 foreach $item (@a) {
1835 if ($form->{"shipto$item"}) {
1842 if ( $form->{formname} eq 'purchase_order'
1843 || $form->{formname} eq 'request_quotation') {
1844 $form->{shiptoname} = $myconfig{company};
1845 $form->{shiptostreet} = $myconfig{address};
1847 map { $form->{"shipto$_"} = $form->{$_} } @a;
1851 $form->{notes} =~ s/^\s+//g;
1853 $form->{templates} = "$myconfig{templates}";
1855 $form->{language} = $form->get_template_language(\%myconfig);
1856 $form->{printer_code} = $form->get_printer_code(\%myconfig);
1858 if ($form->{language} ne "") {
1859 map({ $form->{"unit"}->[$_] =
1860 AM->translate_units($form, $form->{"language"},
1861 $form->{"unit"}->[$_], $form->{"qty"}->[$_]); }
1862 (0..scalar(@{$form->{"unit"}}) - 1));
1863 $form->{language} = "_" . $form->{language};
1867 format_dates($output_dateformat, $output_longdates,
1868 qw(invdate orddate quodate pldate duedate reqdate transdate
1869 shippingdate deliverydate validitydate paymentdate
1870 datepaid transdate_oe deliverydate_oe
1871 employee_startdate employee_enddate
1873 grep({ /^datepaid_\d+$/ ||
1874 /^transdate_oe_\d+$/ ||
1875 /^deliverydate_oe_\d+$/ ||
1877 /^deliverydate_\d+$/ ||
1881 reformat_numbers($output_numberformat, 2,
1882 qw(invtotal ordtotal quototal subtotal linetotal
1883 listprice sellprice netprice discount
1885 grep({ /^linetotal_\d+$/ ||
1886 /^listprice_\d+$/ ||
1887 /^sellprice_\d+$/ ||
1894 reformat_numbers($output_numberformat, undef,
1899 if ($form->{printer_code} ne "") {
1900 $form->{printer_code} = "_" . $form->{printer_code};
1903 $form->{IN} = "$form->{formname}$form->{language}$form->{printer_code}.html";
1904 if ($form->{format} eq 'postscript') {
1905 $form->{postscript} = 1;
1906 $form->{IN} =~ s/html$/tex/;
1907 } elsif ($form->{"format"} =~ /pdf/) {
1909 if ($form->{"format"} =~ /opendocument/) {
1910 $form->{IN} =~ s/html$/odt/;
1912 $form->{IN} =~ s/html$/tex/;
1914 } elsif ($form->{"format"} =~ /opendocument/) {
1915 $form->{"opendocument"} = 1;
1916 $form->{"IN"} =~ s/html$/odt/;
1919 if ($form->{media} eq 'printer') {
1920 $form->{OUT} = "| $form->{printer_command} &>/dev/null";
1921 $form->{printed} .= " $form->{formname}";
1922 $form->{printed} =~ s/^ //;
1924 $printed = $form->{printed};
1926 if ($form->{media} eq 'email') {
1927 $form->{subject} = qq|$form->{label} $form->{"${inv}number"}|
1928 unless $form->{subject};
1930 $form->{OUT} = "$sendmail";
1932 $form->{emailed} .= " $form->{formname}";
1933 $form->{emailed} =~ s/^ //;
1935 $emailed = $form->{emailed};
1937 if ($form->{media} eq 'queue') {
1938 %queued = split / /, $form->{queued};
1940 if ($filename = $queued{ $form->{formname} }) {
1941 $form->{queued} =~ s/$form->{formname} $filename//;
1942 unlink "$spool/$filename";
1943 $filename =~ s/\..*$//g;
1949 $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
1950 $form->{OUT} = ">$spool/$filename";
1953 $form->{queued} .= " $form->{formname} $filename";
1955 $form->{queued} =~ s/^ //;
1957 $queued = $form->{queued};
1959 $form->parse_template(\%myconfig, $userspath);
1961 $form->{callback} = "";
1963 if ($form->{media} eq 'email') {
1964 $form->{message} = $locale->text('sent') unless $form->{message};
1966 $message = $form->{message};
1968 # if we got back here restore the previous form
1969 if ($form->{media} =~ /(printer|email|queue)/) {
1971 $form->update_status(\%myconfig)
1972 if ($form->{media} eq 'queue' && $form->{id});
1976 $old_form->{"${inv}number"} = $form->{"${inv}number"};
1978 # restore and display form
1979 map { $form->{$_} = $old_form->{$_} } keys %$old_form;
1981 $form->{queued} = $queued;
1982 $form->{printed} = $printed;
1983 $form->{emailed} = $emailed;
1984 $form->{message} = $message;
1986 $form->{rowcount}--;
1987 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1988 qw(exchangerate creditlimit creditremaining);
1990 for $i (1 .. $form->{paidaccounts}) {
1992 $form->{"${_}_$i"} =
1993 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
1994 } qw(paid exchangerate);
2002 ($form->{media} eq 'printer')
2003 ? $locale->text('sent to printer')
2004 : $locale->text('emailed to') . " $form->{email}";
2005 $form->redirect(qq|$form->{label} $form->{"${inv}number"} $msg|);
2007 if ($form->{printing}) {
2012 $lxdebug->leave_sub();
2015 sub customer_details {
2016 $lxdebug->enter_sub();
2017 IS->customer_details(\%myconfig, \%$form);
2018 $lxdebug->leave_sub();
2021 sub vendor_details {
2022 $lxdebug->enter_sub();
2024 IR->vendor_details(\%myconfig, \%$form);
2026 $lxdebug->leave_sub();
2030 $lxdebug->enter_sub();
2032 $form->{postasnew} = 1;
2033 map { delete $form->{$_} } qw(printed emailed queued);
2037 $lxdebug->leave_sub();
2041 $lxdebug->enter_sub();
2042 if ($form->{second_run}) {
2043 $form->{print_and_post} = 0;
2046 $title = $form->{title};
2047 $form->{title} = $locale->text('Ship to');
2049 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2050 qw(exchangerate creditlimit creditremaining);
2052 # get details for name
2053 &{"$form->{vc}_details"};
2056 ($form->{vc} eq 'customer')
2057 ? $locale->text('Customer Number')
2058 : $locale->text('Vendor Number');
2060 # get pricegroups for parts
2061 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
2063 # build up html code for prices_$i
2064 set_pricegroup($form->{rowcount});
2066 $nextsub = ($form->{display_form}) ? $form->{display_form} : "display_form";
2068 $form->{rowcount}--;
2075 <form method=post action=$form->{script}>
2081 <tr class=listheading>
2082 <th class=listheading colspan=2 width=50%>|
2083 . $locale->text('Billing Address') . qq|</th>
2084 <th class=listheading width=50%>|
2085 . $locale->text('Shipping Address') . qq|</th>
2087 <tr height="5"></tr>
2089 <th align=right nowrap>$number</th>
2090 <td>$form->{"$form->{vc}number"}</td>
2093 <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
2094 <td>$form->{name}</td>
2095 <td><input name=shiptoname size=35 value="$form->{shiptoname}"></td>
2098 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
2099 <td>$form->{department_1}</td>
2100 <td><input name=shiptodepartment_1 size=35 value="$form->{shiptodepartment_1}"></td>
2103 <th align=right nowrap> </th>
2104 <td>$form->{department_2}</td>
2105 <td><input name=shiptodepartment_2 size=35 value="$form->{shiptodepartment_2}"></td>
2108 <th align=right nowrap>| . $locale->text('Street') . qq|</th>
2109 <td>$form->{street}</td>
2110 <td><input name=shiptostreet size=35 value="$form->{shiptostreet}"></td>
2113 <th align=right nowrap>| . $locale->text('Zipcode') . qq|</th>
2114 <td>$form->{zipcode}</td>
2115 <td><input name=shiptozipcode size=35 value="$form->{shiptozipcode}"></td>
2118 <th align=right nowrap>| . $locale->text('City') . qq|</th>
2119 <td>$form->{city}</td>
2120 <td><input name=shiptocity size=35 value="$form->{shiptocity}"></td>
2123 <th align=right nowrap>| . $locale->text('Country') . qq|</th>
2124 <td>$form->{country}</td>
2125 <td><input name=shiptocountry size=35 value="$form->{shiptocountry}"></td>
2128 <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
2129 <td>$form->{contact}</td>
2130 <td><input name=shiptocontact size=35 value="$form->{shiptocontact}"></td>
2133 <th align=right nowrap>| . $locale->text('Phone') . qq|</th>
2134 <td>$form->{"$form->{vc}phone"}</td>
2135 <td><input name=shiptophone size=20 value="$form->{shiptophone}"></td>
2138 <th align=right nowrap>| . $locale->text('Fax') . qq|</th>
2139 <td>$form->{"$form->{vc}fax"}</td>
2140 <td><input name=shiptofax size=20 value="$form->{shiptofax}"></td>
2143 <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
2144 <td>$form->{email}</td>
2145 <td><input name=shiptoemail size=35 value="$form->{shiptoemail}"></td>
2152 <input type=hidden name=nextsub value=$nextsub>
2156 map { delete $form->{$_} }
2157 qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax shiptoemail shiptodepartment_1 shiptodepartment_2 header);
2158 $form->{title} = $title;
2160 foreach $key (keys %$form) {
2161 $form->{$key} =~ s/\"/"/g;
2162 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2170 <input class=submit type=submit name=action value="|
2171 . $locale->text('Continue') . qq|">
2178 $lxdebug->leave_sub();
2182 $lxdebug->enter_sub();
2187 $form->{old_callback} = $form->escape($form->{callback}, 1);
2188 $form->{callback} = $form->escape("$form->{script}?action=display_form", 1);
2189 $form->{old_callback} = $form->escape($form->{old_callback}, 1);
2192 delete $form->{action};
2193 $customer = $form->{customer};
2194 map { $form->{"old_$_"} = $form->{"${_}_$row"} } qw(partnumber description);
2196 # save all other form variables in a previousform variable
2197 $form->{row} = $row;
2198 foreach $key (keys %$form) {
2201 $form->{$key} =~ s/&/%26/g;
2202 $previousform .= qq|$key=$form->{$key}&|;
2205 $previousform = $form->escape($previousform, 1);
2207 $form->{script} = "licenses.pl";
2209 map { $form->{$_} = $form->{"old_$_"} } qw(partnumber description);
2210 map { $form->{$_} = $form->escape($form->{$_}, 1) }
2211 qw(partnumber description);
2213 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|;
2216 $lxdebug->leave_sub();
2219 sub relink_accounts {
2220 $lxdebug->enter_sub();
2222 $form->{"taxaccounts"} =~ s/\s*$//;
2223 $form->{"taxaccounts"} =~ s/^\s*//;
2224 foreach my $accno (split(/\s*/, $form->{"taxaccounts"})) {
2225 map({ delete($form->{"${accno}_${_}"}); } qw(rate description taxnumber));
2227 $form->{"taxaccounts"} = "";
2229 for (my $i = 1; $i <= $form->{"rowcount"}; $i++) {
2230 if ($form->{"id_$i"}) {
2231 IC->retrieve_accounts(\%myconfig, $form, $form->{"id_$i"}, $i, 1);
2235 $lxdebug->leave_sub();
2240 $lxdebug->enter_sub();
2242 $form->get_duedate(\%myconfig);
2245 $result = "$form->{duedate}";
2248 $lxdebug->leave_sub();