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();
93 if ($lizenzen && $form->{vc} eq "customer") {
94 if ($form->{type} =~ /sales_order/) {
95 @column_index = (runningnumber, partnumber, description, ship, qty);
96 } elsif ($form->{type} =~ /sales_quotation/) {
97 @column_index = (runningnumber, partnumber, description, qty);
99 @column_index = (runningnumber, partnumber, description, qty);
102 if ( ($form->{type} =~ /purchase_order/)
103 || ($form->{type} =~ /sales_order/)) {
104 @column_index = (runningnumber, partnumber, description, ship, qty);
106 @column_index = (runningnumber, partnumber, description, qty);
109 ############## ENDE Neueintrag ##################
111 my $dimension_units = AM->retrieve_units(\%myconfig, $form, "dimension");
112 my $service_units = AM->retrieve_units(\%myconfig, $form, "service");
113 my $all_units = AM->retrieve_units(\%myconfig, $form);
115 push @column_index, qw(unit);
117 #for pricegroups column
118 if ( $form->{type} =~ (/sales_quotation/)
119 or (($form->{level} =~ /Sales/) and ($form->{type} =~ /invoice/))
120 or (($form->{level} eq undef) and ($form->{type} =~ /invoice/))
121 or ($form->{type} =~ /sales_order/)) {
122 push @column_index, qw(sellprice_pg);
125 push @column_index, qw(sellprice);
127 if ($form->{vc} eq 'customer') {
128 push @column_index, qw(discount);
131 push @column_index, "linetotal";
133 my $colspan = $#column_index + 1;
135 $form->{invsubtotal} = 0;
136 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
138 ########################################
139 # Eintrag fuer Version 2.2.0 geaendert #
140 # neue Optik im Rechnungsformular #
141 ########################################
142 $column_data{runningnumber} =
143 qq|<th align=left nowrap width=5 class=listheading>|
144 . $locale->text('No.')
146 $column_data{partnumber} =
147 qq|<th align=left nowrap width=12 class=listheading>|
148 . $locale->text('Number')
150 $column_data{description} =
151 qq|<th align=left nowrap width=30 class=listheading>|
152 . $locale->text('Part Description')
155 qq|<th align=left nowrap width=5 class=listheading>|
156 . $locale->text('Ship')
159 qq|<th align=left nowrap width=5 class=listheading>|
160 . $locale->text('Qty')
163 qq|<th align=left nowrap width=5 class=listheading>|
164 . $locale->text('Unit')
166 $column_data{license} =
167 qq|<th align=left nowrap width=10 class=listheading>|
168 . $locale->text('License')
170 $column_data{serialnr} =
171 qq|<th align=left nowrap width=10 class=listheading>|
172 . $locale->text('Serial No.')
174 $column_data{projectnr} =
175 qq|<th align=left nowrap width=10 class=listheading>|
176 . $locale->text('Project')
178 $column_data{sellprice} =
179 qq|<th align=left nowrap width=15 class=listheading>|
180 . $locale->text('Price')
182 $column_data{sellprice_pg} =
183 qq|<th align=left nowrap width=15 class=listheading>|
184 . $locale->text('Pricegroup')
186 $column_data{discount} =
187 qq|<th align=left class=listheading>|
188 . $locale->text('Discount')
190 $column_data{linetotal} =
191 qq|<th align=left nowrap width=10 class=listheading>|
192 . $locale->text('Extended')
195 qq|<th align=left nowrap width=10 class=listheading>|
196 . $locale->text('Bin')
198 ############## ENDE Neueintrag ##################
204 <tr class=listheading>|;
206 map { print "\n$column_data{$_}" } @column_index;
212 $runningnumber = $locale->text('No.');
213 $deliverydate = $locale->text('Delivery Date');
214 $serialnumber = $locale->text('Serial No.');
215 $projectnumber = $locale->text('Project');
216 $partsgroup = $locale->text('Group');
217 $reqdate = $locale->text('Reqdate');
219 $delvar = 'deliverydate';
221 if ($form->{type} =~ /_order$/ || $form->{type} =~ /_quotation$/) {
222 $deliverydate = $locale->text('Required by');
226 for $i (1 .. $numrows) {
231 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
232 } qw(qty ship discount sellprice price_new price_old) unless ($form->{simple_save});
234 if (!$form->{"unit_old_$i"}) {
235 # Neue Ware aus der Datenbank. In diesem Fall ist unit_$i die
236 # Einheit, wie sie in den Stammdaten hinterlegt wurde.
237 # Es sollte also angenommen werden, dass diese ausgewaehlt war.
238 $form->{"unit_old_$i"} = $form->{"unit_$i"};
243 # Die zuletzt ausgewaehlte mit der aktuell ausgewaehlten Einheit
244 # vergleichen und bei Unterschied den Preis entsprechend umrechnen.
245 $form->{"selected_unit_$i"} = $form->{"unit_$i"} unless ($form->{"selected_unit_$i"});
247 my $check_units = $form->{"inventory_accno_$i"} ? $dimension_units : $service_units;
248 if (!$check_units->{$form->{"selected_unit_$i"}} ||
249 ($check_units->{$form->{"selected_unit_$i"}}->{"base_unit"} ne
250 $all_units->{$form->{"unit_old_$i"}}->{"base_unit"})) {
251 # Die ausgewaehlte Einheit ist fuer diesen Artikel nicht gueltig
252 # (z.B. Dimensionseinheit war ausgewaehlt, es handelt sich aber
253 # um eine Dienstleistung). Dann keinerlei Umrechnung vornehmen.
254 $form->{"unit_old_$i"} = $form->{"selected_unit_$i"} = $form->{"unit_$i"};
256 if ((!$form->{"prices_$i"}) || ($form->{"new_pricegroup_$i"} == $form->{"old_pricegroup_$i"})) {
257 if ($form->{"unit_old_$i"} ne $form->{"selected_unit_$i"}) {
259 if (defined($all_units->{$form->{"unit_old_$i"}}->{"factor"}) &&
260 $all_units->{$form->{"unit_old_$i"}}->{"factor"}) {
261 $basefactor = $all_units->{$form->{"selected_unit_$i"}}->{"factor"} /
262 $all_units->{$form->{"unit_old_$i"}}->{"factor"};
264 $form->{"sellprice_$i"} *= $basefactor;
265 $form->{"unit_old_$i"} = $form->{"selected_unit_$i"};
268 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
270 $decimalplaces = ($dec > 2) ? $dec : 2;
274 $form->{"sellprice_$i"} * $form->{"discount_$i"} / 100,
278 $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
279 $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
281 # convert " to "
282 map { $form->{"${_}_$i"} =~ s/\"/"/g }
283 qw(partnumber description unit unit_old);
285 ########################################
286 # Eintrag fuer Version 2.2.0 geaendert #
287 # neue Optik im Rechnungsformular #
288 ########################################
289 $column_data{runningnumber} =
290 qq|<td><input name="runningnumber_$i" size=5 value=$i></td>|; # HuT
291 ############## ENDE Neueintrag ##################
293 $column_data{partnumber} =
294 qq|<td><input name="partnumber_$i" size=12 value="$form->{"partnumber_$i"}"></td>|;
296 if (($rows = $form->numtextrows($form->{"description_$i"}, 30, 6)) > 1) {
297 $column_data{description} =
298 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>|;
300 $column_data{description} =
301 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>|;
304 (my $qty_dec) = ($form->{"qty_$i"} =~ /\.(\d+)/);
305 $qty_dec = length $qty_dec;
308 qq|<td align=right><input name="qty_$i" size=5 value=|
309 . $form->format_amount(\%myconfig, $form->{"qty_$i"}, $qty_dec) .qq|>|;
310 if ($form->{"formel_$i"}) {
311 $column_data{qty} .= qq|<button type="button" onclick="calculate_qty_selection_window('qty_$i','alu_$i', 'formel_$i', $i)">| . $locale->text('*/') . qq|</button>
312 <input type=hidden name="formel_$i" value="$form->{"formel_$i"}"><input type=hidden name="alu_$i" value="$form->{"alu_$i"}"></td>|;
315 qq|<td align=right><input name="ship_$i" size=5 value=|
316 . $form->format_amount(\%myconfig, $form->{"ship_$i"})
319 my $is_part = $form->{"inventory_accno_$i"};
320 my $is_assigned = $form->{"id_$i"};
321 my $this_unit = $form->{"unit_$i"};
322 if ($form->{"selected_unit_$i"} && $this_unit &&
323 $all_units->{$form->{"selected_unit_$i"}} && $all_units->{$this_unit} &&
324 ($all_units->{$form->{"selected_unit_$i"}}->{"base_unit"} eq $all_units->{$this_unit}->{"base_unit"})) {
325 $this_unit = $form->{"selected_unit_$i"};
326 } elsif (!$is_assigned ||
327 ($is_part && !$this_unit && ($all_units->{$this_unit} && ($all_units->{$this_unit}->{"base_unit"} eq $all_units->{"kg"}->{"base_unit"})))) {
331 $column_data{"unit"} = "<td>" .
332 ($qty_readonly ? " " :
333 AM->unit_select_html($is_part ? $dimension_units :
334 $is_assigned ? $service_units : $all_units,
335 "unit_$i", $this_unit,
336 $is_assigned ? $form->{"unit_$i"} : undef))
339 # build in drop down list for pricesgroups
340 if ($form->{"prices_$i"}) {
341 if ($form->{"new_pricegroup_$i"} != $form->{"old_pricegroup_$i"}) {
342 $price_tmp = $form->format_amount(\%myconfig, $form->{"price_new_$i"}, $decimalplaces);
344 $price_tmp = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
347 $column_data{sellprice_pg} =
348 qq|<td align=right><select name="sellprice_pg_$i">$form->{"prices_$i"}</select></td>|;
349 $column_data{sellprice} =
350 qq|<td><input name="sellprice_$i" size=10 value=$price_tmp></td>|;
353 # for last row and report
354 # set pricegroup drop down list from report menu
355 if ($form->{"sellprice_$i"} != 0) {
357 qq|<option value="$form->{"sellprice_$i"}--$form->{"pricegroup_id_$i"}" selected>$form->{"pricegroup_$i"}</option>\n|;
359 $form->{"pricegroup_old_$i"} = $form->{"pricegroup_id_$i"};
361 $column_data{sellprice_pg} =
362 qq|<td align=right><select name="sellprice_pg_$i">$prices</select></td>|;
367 $column_data{sellprice_pg} = qq|<td align=right> </td>|;
370 $column_data{sellprice} =
371 qq|<td><input name="sellprice_$i" size=10 value=|
372 . $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
376 $column_data{discount} =
377 qq|<td align=right><input name="discount_$i" size=3 value=|
378 . $form->format_amount(\%myconfig, $form->{"discount_$i"})
380 $column_data{linetotal} =
382 . $form->format_amount(\%myconfig, $linetotal, 2)
384 $column_data{bin} = qq|<td>$form->{"bin_$i"}</td>|;
386 ########################################
387 # Eintrag fuer Version 2.2.0 geaendert #
388 # neue Optik im Rechnungsformular #
389 ########################################
390 # if ($lizenzen && $form->{type} eq "invoice" && $form->{vc} eq "customer") {
391 # $column_data{license} = qq|<td><select name="licensenumber_$i">$form->{"lizenzen_$i"}></select></td>|;
394 # if ($form->{type} !~ /_quotation/) {
395 # $column_data{serialnr} = qq|<td><input name="serialnumber_$i" size=10 value="$form->{"serialnumber_$i"}"></td>|;
398 # $column_data{projectnr} = qq|<td><input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}"></td>|;
399 ############## ENDE Neueintrag ##################
403 <tr valign=top class=listrow$j>|;
405 map { print "\n$column_data{$_}" } @column_index;
410 <input type=hidden name="orderitems_id_$i" value=$form->{"orderitems_id_$i"}>
411 <input type=hidden name="bo_$i" value=$form->{"bo_$i"}>
413 <input type=hidden name="pricegroup_old_$i" value=$form->{"pricegroup_old_$i"}>
414 <input type=hidden name="price_old_$i" value=$form->{"price_old_$i"}>
415 <input type=hidden name="unit_old_$i" value="$form->{"selected_unit_$i"}">
416 <input type=hidden name="price_new_$i" value=|
417 . $form->format_amount(\%myconfig, $form->{"price_new_$i"}) . qq|>
419 <input type=hidden name="id_$i" value=$form->{"id_$i"}>
420 <input type=hidden name="inventory_accno_$i" value=$form->{"inventory_accno_$i"}>
421 <input type=hidden name="bin_$i" value="$form->{"bin_$i"}">
422 <input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">
423 <input type=hidden name="partnotes_$i" value="$form->{"partnotes_$i"}">
424 <input type=hidden name="income_accno_$i" value=$form->{"income_accno_$i"}>
425 <input type=hidden name="expense_accno_$i" value=$form->{"expense_accno_$i"}>
426 <input type=hidden name="listprice_$i" value="$form->{"listprice_$i"}">
427 <input type=hidden name="assembly_$i" value="$form->{"assembly_$i"}">
428 <input type=hidden name="taxaccounts_$i" value="$form->{"taxaccounts_$i"}">
429 <input type=hidden name="ordnumber_$i" value="$form->{"ordnumber_$i"}">
430 <input type=hidden name="transdate_$i" value="$form->{"transdate_$i"}">
431 <input type=hidden name="cusordnumber_$i" value="$form->{"cusordnumber_$i"}">
432 <input type=hidden name="longdescription_$i" value="$form->{"longdescription_$i"}">
433 <input type=hidden name="basefactor_$i" value="$form->{"basefactor_$i"}">
437 ########################################
438 # Eintrag fuer Version 2.2.0 geaendert #
439 # neue Optik im Rechnungsformular #
440 ########################################
444 <td colspan=$colspan>
446 if ($lizenzen && $form->{type} eq "invoice" && $form->{vc} eq "customer") {
447 my $selected = $form->{"licensenumber_$i"};
449 $form->{"lizenzen_$i"} =~ s/ selected//g;
450 $form->{"lizenzen_$i"} =~
451 s/value="${selected}"\>/value="${selected}" selected\>/;
452 $lizenzen_quoted = $form->{"lizenzen_$i"};
453 $lizenzen_quoted =~ s/\"/"/g;
455 <b>Lizenz\#</b> <select name="licensenumber_$i" size=1>
456 $form->{"lizenzen_$i"}
458 <input type=hidden name="lizenzen_$i" value="${lizenzen_quoted}">
461 if ($form->{type} !~ /_quotation/) {
463 <b>$serialnumber</b> <input name="serialnumber_$i" size=15 value="$form->{"serialnumber_$i"}">|;
467 <b>$projectnumber</b> <input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}">
468 <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}">
469 <input type=hidden name="project_id_$i" value="$form->{"project_id_$i"}">
471 if ($form->{type} eq 'invoice' or $form->{type} =~ /order/) {
473 ($form->{type} eq 'invoice')
475 : 'reqdate'; # invoice uses a different term for the same thing.
477 <b>${$reqdate_term}</b> <input name="${reqdate_term}_$i" size=11 value="$form->{"${reqdate_term}_$i"}">
480 my $subtotalchecked = ($form->{"subtotal_$i"}) ? "checked" : "";
482 <b>|.$locale->text('Subtotal').qq|</b> <input type="checkbox" name="subtotal_$i" value="1" "$subtotalchecked">
488 ############## ENDE Neueintrag ##################
490 map { $form->{"${_}_base"} += $linetotal }
491 (split / /, $form->{"taxaccounts_$i"});
493 $form->{invsubtotal} += $linetotal;
502 $lxdebug->leave_sub();
505 ##################################################
506 # build html-code for pricegroups in variable $form->{prices_$j}
509 $lxdebug->enter_sub();
510 my $rowcount = shift;
511 for $j (1 .. $rowcount) {
512 my $pricegroup_old = $form->{"pricegroup_old_$i"};
513 if ($form->{PRICES}{$j}) {
515 $prices = '<option value="--">' . $locale->text("none (pricegroup)") . '</option>';
517 foreach $item (@{ $form->{PRICES}{$j} }) {
519 #$price = $form->round_amount($myconfig, $item->{price}, 5);
520 #$price = $form->format_amount($myconfig, $item->{price}, 2);
521 $price = $item->{price};
522 $pricegroup_id = $item->{pricegroup_id};
523 $pricegroup = $item->{pricegroup};
525 # build drop down list for pricegroups
527 qq|<option value="$price--$pricegroup_id"$item->{selected}>$pricegroup</option>\n|;
532 # $form->{"${_}_$j"} =
533 # $form->format_amount(\%myconfig, $form->{"${_}_$j"})
534 # } qw(sellprice price_new price_old);
536 # set new selectedpricegroup_id and prices for "Preis"
537 if ($item->{selected} && ($pricegroup_id != 0)) {
538 $form->{"pricegroup_old_$j"} = $pricegroup_id;
539 $form->{"price_new_$j"} = $price;
540 $form->{"sellprice_$j"} = $price;
542 if ($pricegroup_id == 0) {
543 $form->{"price_new_$j"} = $form->{"sellprice_$j"};
546 $form->{"prices_$j"} = $prices;
549 $lxdebug->leave_sub();
553 $lxdebug->enter_sub();
554 @column_index = qw(ndx partnumber description onhand unit sellprice);
556 $column_data{ndx} = qq|<th> </th>|;
557 $column_data{partnumber} =
558 qq|<th class=listheading>| . $locale->text('Number') . qq|</th>|;
559 $column_data{description} =
560 qq|<th class=listheading>| . $locale->text('Part Description') . qq|</th>|;
561 $column_data{sellprice} =
562 qq|<th class=listheading>| . $locale->text('Price') . qq|</th>|;
563 $column_data{onhand} =
564 qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|;
566 qq|<th class=listheading>| . $locale->text('Unit') . qq|</th>|;
567 # list items with radio button on a form
570 $title = $locale->text('Select from one of the items below');
571 $colspan = $#column_index + 1;
576 <form method=post action=$form->{script}>
580 <th class=listtop colspan=$colspan>$title</th>
583 <tr class=listheading>|;
585 map { print "\n$column_data{$_}" } @column_index;
590 foreach $ref (@{ $form->{item_list} }) {
591 $checked = ($i++) ? "" : "checked";
594 if ($ref->{inventory_accno} > 0) {
595 $ref->{"lizenzen"} = qq|<option></option>|;
596 foreach $item (@{ $form->{LIZENZEN}{ $ref->{"id"} } }) {
597 $ref->{"lizenzen"} .=
598 qq|<option value=\"$item->{"id"}\">$item->{"licensenumber"}</option>|;
600 $ref->{"lizenzen"} .= qq|<option value=-1>Neue Lizenz</option>|;
601 $ref->{"lizenzen"} =~ s/\"/"/g;
605 map { $ref->{$_} =~ s/\"/"/g } qw(partnumber description unit);
609 $form->round_amount($ref->{sellprice} * (1 - $form->{tradediscount}), 2);
611 qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
612 $column_data{partnumber} =
613 qq|<td><input name="new_partnumber_$i" type=hidden value="$ref->{partnumber}">$ref->{partnumber}</td>|;
614 $column_data{description} =
615 qq|<td><input name="new_description_$i" type=hidden value="$ref->{description}">$ref->{description}</td>|;
616 $column_data{sellprice} =
617 qq|<td align=right><input name="new_sellprice_$i" type=hidden value=$ref->{sellprice}>|
618 . $form->format_amount(\%myconfig, $ref->{sellprice}, 2, " ")
620 $column_data{onhand} =
621 qq|<td align=right><input name="new_onhand_$i" type=hidden value=$ref->{onhand}>|
622 . $form->format_amount(\%myconfig, $ref->{onhand}, '', " ")
625 qq|<td>$ref->{unit}</td>|;
629 <tr class=listrow$j>|;
631 map { print "\n$column_data{$_}" } @column_index;
636 <input name="new_bin_$i" type=hidden value="$ref->{bin}">
637 <input name="new_listprice_$i" type=hidden value=$ref->{listprice}>
638 <input name="new_inventory_accno_$i" type=hidden value=$ref->{inventory_accno}>
639 <input name="new_income_accno_$i" type=hidden value=$ref->{income_accno}>
640 <input name="new_expense_accno_$i" type=hidden value=$ref->{expense_accno}>
641 <input name="new_unit_$i" type=hidden value="$ref->{unit}">
642 <input name="new_weight_$i" type=hidden value="$ref->{weight}">
643 <input name="new_assembly_$i" type=hidden value="$ref->{assembly}">
644 <input name="new_taxaccounts_$i" type=hidden value="$ref->{taxaccounts}">
645 <input name="new_partsgroup_$i" type=hidden value="$ref->{partsgroup}">
646 <input name="new_formel_$i" type=hidden value="$ref->{formel}">
647 <input name="new_longdescription_$i" type=hidden value="$ref->{longdescription}">
648 <input name="new_not_discountable_$i" type=hidden value="$ref->{not_discountable}">
649 <input name="new_part_payment_id_$i" type=hidden value="$ref->{part_payment_id}">
651 <input name="new_id_$i" type=hidden value=$ref->{id}>
656 <input name="new_lizenzen_$i" type=hidden value="$ref->{lizenzen}">
663 <tr><td colspan=8><hr size=3 noshade></td></tr>
666 <input name=lastndx type=hidden value=$i>
670 # delete action variable
671 map { delete $form->{$_} } qw(action item_list header);
673 # save all other form variables
674 foreach $key (keys %${form}) {
675 $form->{$key} =~ s/\"/"/g;
676 print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
680 <input type=hidden name=nextsub value=item_selected>
683 <input class=submit type=submit name=action value="|
684 . $locale->text('Continue') . qq|">
691 $lxdebug->leave_sub();
695 $lxdebug->enter_sub();
697 # replace the last row with the checked row
698 $i = $form->{rowcount};
699 $i = $form->{assembly_rows} if ($form->{item} eq 'assembly');
705 #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
706 #$form->{"sellprice_$i"} = $form->{"sellprice_$i"};
708 # if there was a price entered, override it
709 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
711 map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} }
712 qw(id partnumber description sellprice listprice inventory_accno income_accno expense_accno bin unit weight assembly taxaccounts partsgroup formel longdescription not_discountable);
713 if ($form->{"part_payment_id_$i"} ne "") {
714 $form->{payment_id} = $form->{"part_payment_id_$i"};
718 map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} } qw(lizenzen);
721 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
723 $decimalplaces = ($dec > 2) ? $dec : 2;
726 $form->{"sellprice_$i"} = $sellprice;
729 # if there is an exchange rate adjust sellprice
730 if (($form->{exchangerate} * 1) != 0) {
731 $form->{"sellprice_$i"} /= $form->{exchangerate};
732 $form->{"sellprice_$i"} =
733 $form->round_amount($form->{"sellprice_$i"}, $decimalplaces);
737 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
738 qw(sellprice listprice weight);
740 $form->{sellprice} += ($form->{"sellprice_$i"} * $form->{"qty_$i"});
741 $form->{weight} += ($form->{"weight_$i"} * $form->{"qty_$i"});
743 if ($form->{"not_discountable_$i"}) {
744 $form->{"discount_$i"} = 0;
748 $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) *
750 map { $form->{"${_}_base"} += $amount }
751 (split / /, $form->{"taxaccounts_$i"});
752 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /,
753 $form->{"taxaccounts_$i"}
754 if !$form->{taxincluded};
756 $form->{creditremaining} -= $amount;
758 $form->{"runningnumber_$i"} = $i;
760 # delete all the new_ variables
761 for $i (1 .. $form->{lastndx}) {
762 map { delete $form->{"new_${_}_$i"} }
763 qw(partnumber description sellprice bin listprice inventory_accno income_accno expense_accno unit assembly taxaccounts id);
766 map { delete $form->{$_} } qw(ndx lastndx nextsub);
771 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces)
772 } qw(sellprice listprice) if $form->{item} ne 'assembly';
774 # get pricegroups for parts
775 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
777 # build up html code for prices_$i
778 set_pricegroup($form->{rowcount});
782 $lxdebug->leave_sub();
786 $lxdebug->enter_sub();
789 $form->{old_callback} = $form->escape($form->{callback}, 1);
790 $form->{callback} = $form->escape("$form->{script}?action=display_form", 1);
793 delete $form->{action};
795 # save all other form variables in a previousform variable
796 foreach $key (keys %$form) {
799 $form->{$key} =~ s/&/%26/g;
800 $previousform .= qq|$key=$form->{$key}&|;
803 $previousform = $form->escape($previousform, 1);
805 $i = $form->{rowcount};
806 map { $form->{"${_}_$i"} =~ s/\"/"/g } qw(partnumber description);
813 <h4 class=error>| . $locale->text('Item not on file!') . qq|
816 | . $locale->text('What type of item is this?') . qq|</h4>
818 <form method=post action=ic.pl>
822 <input class=radio type=radio name=item value=part checked> |
823 . $locale->text('Part') . qq|<br>
824 <input class=radio type=radio name=item value=service> |
825 . $locale->text('Service')
828 <input type=hidden name=previousform value="$previousform">
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}>
839 <input type=hidden name=nextsub value=add>
842 <input class=submit type=submit name=action value="|
843 . $locale->text('Continue') . qq|">
850 $lxdebug->leave_sub();
854 $lxdebug->enter_sub();
858 $form->language_payment(\%myconfig);
860 # if we have a display_form
861 if ($form->{display_form}) {
862 &{"$form->{display_form}"};
866 # if ( $form->{print_and_post}
867 # && $form->{second_run}
868 # && ($form->{action} eq "display_form")) {
869 # for (keys %$form) { $old_form->{$_} = $form->{$_} }
870 # $old_form->{rowcount}++;
872 # #$form->{rowcount}--;
873 # #$form->{rowcount}--;
875 # $form->{print_and_post} = 0;
877 # &print_form($old_form);
881 # $form->{action} = "";
882 # $form->{resubmit} = 0;
884 # if ($form->{print_and_post} && !$form->{second_run}) {
885 # $form->{second_run} = 1;
886 # $form->{action} = "display_form";
887 # $form->{rowcount}--;
888 # my $rowcount = $form->{rowcount};
890 # # get pricegroups for parts
891 # IS->get_pricegroups_for_parts(\%myconfig, \%$form);
893 # # build up html code for prices_$i
894 # set_pricegroup($rowcount);
896 # $form->{resubmit} = 1;
901 $numrows = ++$form->{rowcount};
902 $subroutine = "display_row";
904 if ($form->{item} eq 'part') {
906 #set preisgruppenanzahl
907 $numrows = $form->{price_rows};
908 $subroutine = "price_row";
910 &{$subroutine}($numrows);
912 $numrows = ++$form->{makemodel_rows};
913 $subroutine = "makemodel_row";
915 if ($form->{item} eq 'assembly') {
916 $numrows = $form->{price_rows};
917 $subroutine = "price_row";
919 &{$subroutine}($numrows);
921 $numrows = ++$form->{makemodel_rows};
922 $subroutine = "makemodel_row";
924 # create makemodel rows
925 &{$subroutine}($numrows);
927 $numrows = ++$form->{assembly_rows};
928 $subroutine = "assembly_row";
930 if ($form->{item} eq 'service') {
931 $numrows = $form->{price_rows};
932 $subroutine = "price_row";
934 &{$subroutine}($numrows);
940 &{$subroutine}($numrows) if $numrows;
944 $lxdebug->leave_sub();
948 $lxdebug->enter_sub();
952 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)
956 # remove any makes or model rows
957 if ($form->{item} eq 'part') {
958 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
959 qw(listprice sellprice lastcost weight rop);
961 @flds = (make, model);
962 for my $i (1 .. ($form->{makemodel_rows})) {
963 if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
967 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
972 $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
973 $form->{makemodel_rows} = $count;
975 } elsif ($form->{item} eq 'assembly') {
977 $form->{sellprice} = 0;
979 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
980 qw(listprice rop stock);
983 qw(id qty unit bom partnumber description sellprice weight runningnumber partsgroup);
985 for my $i (1 .. ($form->{assembly_rows} - 1)) {
986 if ($form->{"qty_$i"}) {
990 $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
992 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
994 #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
996 $form->{sellprice} += ($form->{"qty_$i"} * $form->{"sellprice_$i"});
997 $form->{weight} += ($form->{"qty_$i"} * $form->{"weight_$i"});
1002 $form->{sellprice} = $form->round_amount($form->{sellprice}, 2);
1004 $form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows});
1005 $form->{assembly_rows} = $count;
1008 @flds = qw(make model);
1011 for my $i (1 .. ($form->{makemodel_rows})) {
1012 if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
1016 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1021 $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
1022 $form->{makemodel_rows} = $count;
1026 # this section applies to invoices and orders
1027 # remove any empty numbers
1028 if ($form->{rowcount}) {
1029 for my $i (1 .. $form->{rowcount} - 1) {
1030 if ($form->{"partnumber_$i"}) {
1034 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1037 if ($form->{"licensenumber_$i"} == -1) {
1045 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
1046 $form->{rowcount} = $count;
1048 $form->{creditremaining} -= &invoicetotal;
1055 if ( $form->{type} =~ (/sales_quotation/)
1056 or (($form->{level} =~ /Sales/) and ($form->{type} =~ /invoice/))
1057 or (($form->{level} eq undef) and ($form->{type} =~ /invoice/))
1058 or ($form->{type} =~ /sales_order/)) {
1060 # get pricegroups for parts
1061 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1063 # build up html code for prices_$i
1064 set_pricegroup($form->{rowcount});
1070 $lxdebug->leave_sub();
1074 $lxdebug->enter_sub();
1076 $form->{oldinvtotal} = 0;
1078 # add all parts and deduct paid
1079 map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
1081 my ($amount, $sellprice, $discount, $qty);
1083 for my $i (1 .. $form->{rowcount}) {
1084 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1085 $discount = $form->parse_amount(\%myconfig, $form->{"discount_$i"});
1086 $qty = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
1088 #($form->{"sellprice_$i"}, $form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
1090 $amount = $sellprice * (1 - $discount / 100) * $qty;
1091 map { $form->{"${_}_base"} += $amount }
1092 (split / /, $form->{"taxaccounts_$i"});
1093 $form->{oldinvtotal} += $amount;
1096 map { $form->{oldinvtotal} += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1097 split / /, $form->{taxaccounts}
1098 if !$form->{taxincluded};
1100 $form->{oldtotalpaid} = 0;
1101 for $i (1 .. $form->{paidaccounts}) {
1102 $form->{oldtotalpaid} += $form->{"paid_$i"};
1105 $lxdebug->leave_sub();
1108 return ($form->{oldinvtotal} - $form->{oldtotalpaid});
1111 sub validate_items {
1112 $lxdebug->enter_sub();
1114 # check if items are valid
1115 if ($form->{rowcount} == 1) {
1120 for $i (1 .. $form->{rowcount} - 1) {
1121 $form->isblank("partnumber_$i",
1122 $locale->text('Number missing in Row') . " $i");
1125 $lxdebug->leave_sub();
1129 $lxdebug->enter_sub();
1130 if ($form->{second_run}) {
1131 $form->{print_and_post} = 0;
1133 $form->{ordnumber} = $form->{invnumber};
1135 map { delete $form->{$_} } qw(id printed emailed queued);
1136 if ($form->{script} eq 'ir.pl' || $form->{type} eq 'request_quotation') {
1137 $form->{title} = $locale->text('Add Purchase Order');
1138 $form->{vc} = 'vendor';
1139 $form->{type} = 'purchase_order';
1142 if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_quotation') {
1143 $form->{title} = $locale->text('Add Sales Order');
1144 $form->{vc} = 'customer';
1145 $form->{type} = 'sales_order';
1148 $form->{script} = 'oe.pl';
1150 $form->{shipto} = 1;
1152 $form->{rowcount}--;
1154 $form->{cp_id} *= 1;
1156 require "$form->{path}/$form->{script}";
1158 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1160 $currency = $form->{currency};
1164 $form->{currency} = $currency;
1165 $form->{exchangerate} = "";
1166 $form->{forex} = "";
1167 $form->{exchangerate} = $exchangerate
1171 $form->check_exchangerate(
1172 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1175 for $i (1 .. $form->{rowcount}) {
1176 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
1177 $form->{"${_}_${i}"})
1178 if ($form->{"${_}_${i}"}) }
1179 qw(ship qty sellprice listprice basefactor));
1185 $lxdebug->leave_sub();
1189 $lxdebug->enter_sub();
1190 if ($form->{second_run}) {
1191 $form->{print_and_post} = 0;
1193 map { delete $form->{$_} } qw(id printed emailed queued);
1195 if ($form->{script} eq 'ir.pl' || $form->{type} eq 'purchase_order') {
1196 $form->{title} = $locale->text('Add Request for Quotation');
1197 $form->{vc} = 'vendor';
1198 $form->{type} = 'request_quotation';
1201 if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_order') {
1202 $form->{title} = $locale->text('Add Quotation');
1203 $form->{vc} = 'customer';
1204 $form->{type} = 'sales_quotation';
1208 $form->{cp_id} *= 1;
1210 $form->{script} = 'oe.pl';
1212 $form->{shipto} = 1;
1214 $form->{rowcount}--;
1216 require "$form->{path}/$form->{script}";
1218 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1220 $currency = $form->{currency};
1224 $form->{currency} = $currency;
1225 $form->{exchangerate} = "";
1226 $form->{forex} = "";
1227 $form->{exchangerate} = $exchangerate
1231 $form->check_exchangerate(
1232 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1235 for $i (1 .. $form->{rowcount}) {
1236 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
1237 $form->{"${_}_${i}"})
1238 if ($form->{"${_}_${i}"}) }
1239 qw(ship qty sellprice listprice basefactor));
1245 $lxdebug->leave_sub();
1248 sub request_for_quotation {
1253 $lxdebug->enter_sub();
1254 if ($form->{second_run}) {
1255 $form->{print_and_post} = 0;
1256 $form->{resubmit} = 0;
1258 if ($myconfig{role} eq 'admin') {
1260 <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
1261 <td><input name=bcc size=30 value="$form->{bcc}"></td>
1265 if ($form->{formname} =~ /(pick|packing|bin)_list/) {
1266 $form->{email} = $form->{shiptoemail} if $form->{shiptoemail};
1269 if ($form->{"cp_id"} && !$form->{"email"}) {
1270 CT->get_contact(\%myconfig, $form);
1271 $form->{"email"} = $form->{"cp_email"};
1274 $name = $form->{ $form->{vc} };
1276 $title = $locale->text('E-mail') . " $name";
1278 $form->{oldmedia} = $form->{media};
1279 $form->{media} = "email";
1286 <form method=post action=$form->{script}>
1290 <th class=listtop>$title</th>
1292 <tr height="5"></tr>
1297 <th align=right nowrap>| . $locale->text('To') . qq|</th>
1298 <td><input name=email size=30 value="$form->{email}"></td>
1299 <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
1300 <td><input name=cc size=30 value="$form->{cc}"></td>
1303 <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
1304 <td><input name=subject size=30 value="$form->{subject}"></td>
1314 <th align=left nowrap>| . $locale->text('Message') . qq|</th>
1317 <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
1328 map { delete $form->{$_} }
1329 qw(action email cc bcc subject message formname sendmode format header override);
1331 # save all other variables
1332 foreach $key (keys %$form) {
1333 $form->{$key} =~ s/\"/"/g;
1334 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1341 <td><hr size=3 noshade></td>
1345 <input type=hidden name=nextsub value=send_email>
1348 <input name=action class=submit type=submit value="|
1349 . $locale->text('Continue') . qq|">
1356 $lxdebug->leave_sub();
1360 $lxdebug->enter_sub();
1362 $old_form = new Form;
1364 map { $old_form->{$_} = $form->{$_} } keys %$form;
1365 $old_form->{media} = $form->{oldmedia};
1367 &print_form($old_form);
1369 $lxdebug->leave_sub();
1373 $lxdebug->enter_sub();
1374 $form->{sendmode} = "attachment";
1377 $form->{"format"} ? $form->{"format"} :
1378 $myconfig{"template_format"} ? $myconfig{"template_format"} :
1382 $form->{"copies"} ? $form->{"copies"} :
1383 $myconfig{"copies"} ? $myconfig{"copies"} :
1386 $form->{PD}{ $form->{formname} } = "selected";
1387 $form->{DF}{ $form->{format} } = "selected";
1388 $form->{OP}{ $form->{media} } = "selected";
1389 $form->{SM}{ $form->{sendmode} } = "selected";
1391 if ($form->{type} eq 'purchase_order') {
1392 $type = qq|<select name=formname>
1393 <option value=purchase_order $form->{PD}{purchase_order}>|
1394 . $locale->text('Purchase Order') . qq|
1395 <option value=bin_list $form->{PD}{bin_list}>|
1396 . $locale->text('Bin List');
1399 if ($form->{type} eq 'credit_note') {
1400 $type = qq|<select name=formname>
1401 <option value=credit_note $form->{PD}{credit_note}>|
1402 . $locale->text('Credit Note');
1405 if ($form->{type} eq 'sales_order') {
1406 $type = qq|<select name=formname>
1407 <option value=sales_order $form->{PD}{sales_order}>|
1408 . $locale->text('Confirmation') . qq|
1409 <option value=proforma $form->{PD}{proforma}>|
1410 . $locale->text('Proforma Invoice') . qq|
1411 <option value=pick_list $form->{PD}{pick_list}>|
1412 . $locale->text('Pick List') . qq|
1413 <option value=packing_list $form->{PD}{packing_list}>|
1414 . $locale->text('Packing List');
1417 if ($form->{type} =~ /_quotation$/) {
1418 $type = qq|<select name=formname>
1419 <option value="$`_quotation" $form->{PD}{"$`_quotation"}>|
1420 . $locale->text('Quotation');
1423 if ($form->{type} eq 'invoice') {
1424 $type = qq|<select name=formname>
1425 <option value=invoice $form->{PD}{invoice}>|
1426 . $locale->text('Invoice') . qq|
1427 <option value=proforma $form->{PD}{proforma}>|
1428 . $locale->text('Proforma Invoice') . qq|
1429 <option value=packing_list $form->{PD}{packing_list}>|
1430 . $locale->text('Packing List');
1433 if ($form->{type} eq 'invoice' && $form->{storno}) {
1434 $type = qq|<select name=formname>
1435 <option value=storno_invoice $form->{PD}{storno_invoice}>|
1436 . $locale->text('Storno Invoice') . qq|
1437 <option value=storno_packing_list $form->{PD}{storno_packing_list}>|
1438 . $locale->text('Storno Packing List');
1441 if ($form->{type} eq 'credit_note') {
1442 $type = qq|<select name=formname>
1443 <option value=credit_note $form->{PD}{credit_note}>|
1444 . $locale->text('Credit Note');
1447 if ($form->{type} eq 'ship_order') {
1448 $type = qq|<select name=formname>
1449 <option value=pick_list $form->{PD}{pick_list}>|
1450 . $locale->text('Pick List') . qq|
1451 <option value=packing_list $form->{PD}{packing_list}>|
1452 . $locale->text('Packing List');
1455 if ($form->{type} eq 'receive_order') {
1456 $type = qq|<select name=formname>
1457 <option value=bin_list $form->{PD}{bin_list}>|
1458 . $locale->text('Bin List');
1461 if ($form->{media} eq 'email') {
1462 $media = qq|<select name=sendmode>
1463 <option value=attachment $form->{SM}{attachment}>|
1464 . $locale->text('Attachment') . qq|
1465 <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
1467 $media = qq|<select name=media>
1468 <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
1469 if (scalar(keys (%{ $form->{printers} })) !=0 && $latex_templates) {
1471 <option value=printer $form->{OP}{printer}>|
1472 . $locale->text('Printer');
1474 if ($latex_templates) {
1476 <option value=queue $form->{OP}{queue}>| . $locale->text('Queue');
1480 $format = qq|<select name=format>|;
1481 if ($opendocument_templates && $openofficeorg_writer_bin &&
1482 $xvfb_bin && (-x $openofficeorg_writer_bin) && (-x $xvfb_bin)) {
1483 $format .= qq|<option value=opendocument_pdf | .
1484 $form->{DF}{"opendocument_pdf"} . qq|>| .
1485 $locale->text("PDF (OpenDocument/OASIS)") . qq|</option>|;
1488 if ($latex_templates) {
1489 $format .= qq|<option value=pdf $form->{DF}{pdf}>| .
1490 $locale->text('PDF') . qq|</option>|;
1493 $format .= qq|<option value=html $form->{DF}{html}>HTML</option>|;
1495 if ($latex_templates) {
1496 $format .= qq|<option value=postscript $form->{DF}{postscript}>| .
1497 $locale->text('Postscript') . qq|</option>|;
1500 if ($opendocument_templates) {
1501 $format .= qq|<option value=opendocument $form->{DF}{opendocument}>| .
1502 $locale->text("OpenDocument/OASIS") . qq|</option>|;
1504 $format .= qq|</select>|;
1506 if (scalar(keys (%{ $form->{languages} })) !=0) {
1507 $language_select = qq|<select name=language_id>
1508 <option value=""></option>}|;
1509 foreach $item (@{ $form->{languages} }) {
1510 if ($form->{language_id} eq $item->{id}) {
1511 $language_select .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
1513 $language_select .= qq|<option value="$item->{id}">$item->{description}</option>|;
1518 if (scalar(keys (%{ $form->{printers} })) !=0) {
1520 $printer_select = qq|<select name=printer_id>
1521 <option value=""></option>|;
1522 foreach $item (@{ $form->{printers} }) {
1523 $printer_select .= qq|<option value="$item->{id}">$item->{printer_description}</option>|;
1530 <table width=100% cellspacing=0 cellpadding=0>
1535 <td>$type</select></td>|;
1536 if (scalar(keys (%{ $form->{languages} })) !=0) {
1538 <td>${language_select}</select></td>|;
1541 <td>$format</select></td>
1542 <td>$media</select></td>|;
1543 if (scalar(keys (%{ $form->{printers} })) !=0) {
1545 <td>$printer_select</select></td>
1549 if (scalar(keys (%{ $form->{printers} })) !=0 && $latex_templates && $form->{media} ne 'email') {
1551 <td>| . $locale->text('Copies') . qq|
1552 <input name=copies size=2 value=$form->{copies}></td>
1556 $form->{groupitems} = "checked" if $form->{groupitems};
1559 <td>| . $locale->text('Group Items') . qq|</td>
1560 <td><input name=groupitems type=checkbox class=checkbox $form->{groupitems}></td>
1569 if ($form->{printed} =~ /$form->{formname}/) {
1571 <th>\|| . $locale->text('Printed') . qq|\|</th>
1575 if ($form->{emailed} =~ /$form->{formname}/) {
1577 <th>\|| . $locale->text('E-mailed') . qq|\|</th>
1581 if ($form->{queued} =~ /$form->{formname}/) {
1583 <th>\|| . $locale->text('Queued') . qq|\|</th>
1595 $lxdebug->leave_sub();
1599 $lxdebug->enter_sub();
1601 # if this goes to the printer pass through
1602 if ($form->{media} eq 'printer' || $form->{media} eq 'queue') {
1603 $form->error($locale->text('Select postscript or PDF!'))
1604 if ($form->{format} !~ /(postscript|pdf)/);
1606 $old_form = new Form;
1607 map { $old_form->{$_} = $form->{$_} } keys %$form;
1610 if (!$form->{id} || (($form->{formname} eq "proforma") && !$form->{proforma} && (($form->{type} =~ /_order$/) || ($form->{type} =~ /_quotation$/)))) {
1611 if ($form->{formname} eq "proforma") {
1612 $form->{proforma} = 1;
1614 $form->{print_and_save} = 1;
1615 my $formname = $form->{formname};
1617 $form->{formname} = $formname;
1622 &print_form($old_form);
1624 $lxdebug->leave_sub();
1628 $lxdebug->enter_sub();
1629 my ($old_form) = @_;
1633 $numberfld = "invnumber";
1636 ($form->{display_form}) ? $form->{display_form} : "display_form";
1638 # $form->{"notes"} will be overridden by the customer's/vendor's "notes" field. So save it here.
1639 $form->{ $form->{"formname"} . "notes" } = $form->{"notes"};
1641 if ($form->{formname} eq "invoice") {
1642 $form->{label} = $locale->text('Invoice');
1644 if ($form->{formname} eq "packing_list") {
1646 # this is from an invoice
1647 $form->{label} = $locale->text('Packing List');
1649 if ($form->{formname} eq 'sales_order') {
1652 $form->{"${inv}date"} = $form->{transdate};
1653 $form->{label} = $locale->text('Sales Order');
1654 $numberfld = "sonumber";
1658 if (($form->{type} eq 'invoice') && ($form->{formname} eq 'proforma') ) {
1661 $form->{"${inv}date"} = $form->{transdate};
1662 $form->{"invdate"} = $form->{transdate};
1663 $form->{label} = $locale->text('Proforma Invoice');
1664 $numberfld = "sonumber";
1668 if (($form->{type} eq 'sales_order') && ($form->{formname} eq 'proforma') ) {
1671 $form->{"${inv}date"} = $form->{transdate};
1672 $form->{"invdate"} = $form->{transdate};
1673 $form->{invnumber} = $form->{ordnumber};
1674 $form->{label} = $locale->text('Proforma Invoice');
1675 $numberfld = "sonumber";
1679 if ($form->{formname} eq 'packing_list' && $form->{type} ne 'invoice') {
1681 # we use the same packing list as from an invoice
1684 $form->{invdate} = $form->{"${inv}date"} = $form->{transdate};
1685 $form->{label} = $locale->text('Packing List');
1687 # set invnumber for template packing_list
1688 $form->{invnumber} = $form->{ordnumber};
1690 if ($form->{formname} eq 'pick_list') {
1693 $form->{"${inv}date"} =
1694 ($form->{transdate}) ? $form->{transdate} : $form->{invdate};
1695 $form->{label} = $locale->text('Pick List');
1696 $order = 1 unless $form->{type} eq 'invoice';
1698 if ($form->{formname} eq 'purchase_order') {
1701 $form->{"${inv}date"} = $form->{transdate};
1702 $form->{label} = $locale->text('Purchase Order');
1703 $numberfld = "ponumber";
1706 if ($form->{formname} eq 'bin_list') {
1709 $form->{"${inv}date"} = $form->{transdate};
1710 $form->{label} = $locale->text('Bin List');
1713 if ($form->{formname} eq 'sales_quotation') {
1716 $form->{"${inv}date"} = $form->{transdate};
1717 $form->{label} = $locale->text('Quotation');
1718 $numberfld = "sqnumber";
1722 if (($form->{type} eq 'sales_quotation') && ($form->{formname} eq 'proforma') ) {
1725 $form->{"${inv}date"} = $form->{transdate};
1726 $form->{"invdate"} = $form->{transdate};
1727 $form->{label} = $locale->text('Proforma Invoice');
1728 $numberfld = "sqnumber";
1732 if ($form->{formname} eq 'request_quotation') {
1735 $form->{"${inv}date"} = $form->{transdate};
1736 $form->{label} = $locale->text('Quotation');
1737 $numberfld = "rfqnumber";
1741 $form->isblank("email", $locale->text('E-mail address missing!'))
1742 if ($form->{media} eq 'email');
1743 $form->isblank("${inv}date",
1744 $locale->text($form->{label} . ' Date missing!'));
1746 # $locale->text('Invoice Number missing!')
1747 # $locale->text('Invoice Date missing!')
1748 # $locale->text('Packing List Number missing!')
1749 # $locale->text('Packing List Date missing!')
1750 # $locale->text('Order Number missing!')
1751 # $locale->text('Order Date missing!')
1752 # $locale->text('Quotation Number missing!')
1753 # $locale->text('Quotation Date missing!')
1756 if (!$form->{"${inv}number"} && !$form->{preview}) {
1757 $form->{"${inv}number"} = $form->update_defaults(\%myconfig, $numberfld);
1758 if ($form->{media} ne 'email') {
1760 # get pricegroups for parts
1761 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1763 # build up html code for prices_$i
1764 set_pricegroup($form->{rowcount});
1766 $form->{rowcount}--;
1775 # Save the email address given in the form because it should override the setting saved for the customer/vendor.
1776 my ($saved_email, $saved_cc, $saved_bcc) =
1777 ($form->{"email"}, $form->{"cc"}, $form->{"bcc"});
1779 $language_saved = $form->{language_id};
1780 $payment_id_saved = $form->{payment_id};
1782 &{"$form->{vc}_details"};
1784 $form->{language_id} = $language_saved;
1785 $form->{payment_id} = $payment_id_saved;
1787 $form->{"email"} = $saved_email if ($saved_email);
1788 $form->{"cc"} = $saved_cc if ($saved_cc);
1789 $form->{"bcc"} = $saved_bcc if ($saved_bcc);
1791 my ($language_tc, $output_numberformat, $output_dateformat, $output_longdates);
1792 if ($form->{"language_id"}) {
1793 ($language_tc, $output_numberformat, $output_dateformat, $output_longdates) =
1794 AM->get_language_details(\%myconfig, $form, $form->{language_id});
1796 $output_dateformat = $myconfig{"dateformat"};
1797 $output_numberformat = $myconfig{"numberformat"};
1798 $output_longdates = 1;
1801 ($form->{employee}) = split /--/, $form->{employee};
1802 ($form->{warehouse}, $form->{warehouse_id}) = split /--/, $form->{warehouse};
1804 # create the form variables
1806 OE->order_details(\%myconfig, \%$form);
1808 IS->invoice_details(\%myconfig, \%$form, $locale);
1811 if ($form->{shipto_id}) {
1812 $form->get_shipto(\%myconfig);
1815 @a = qw(name street zipcode city country);
1819 # if there is no shipto fill it in from billto
1820 foreach $item (@a) {
1821 if ($form->{"shipto$item"}) {
1828 if ( $form->{formname} eq 'purchase_order'
1829 || $form->{formname} eq 'request_quotation') {
1830 $form->{shiptoname} = $myconfig{company};
1831 $form->{shiptostreet} = $myconfig{address};
1833 map { $form->{"shipto$_"} = $form->{$_} } @a;
1837 $form->{notes} =~ s/^\s+//g;
1839 $form->{templates} = "$myconfig{templates}";
1841 $form->{language} = $form->get_template_language(\%myconfig);
1842 $form->{printer_code} = $form->get_printer_code(\%myconfig);
1844 if ($form->{language} ne "") {
1845 map({ $form->{"unit"}->[$_] =
1846 AM->translate_units($form, $form->{"language"},
1847 $form->{"unit"}->[$_], $form->{"qty"}->[$_]); }
1848 (0..scalar(@{$form->{"unit"}}) - 1));
1849 $form->{language} = "_" . $form->{language};
1853 format_dates($output_dateformat, $output_longdates,
1854 qw(invdate orddate quodate pldate duedate reqdate transdate
1855 shippingdate deliverydate validitydate paymentdate
1856 datepaid transdate_oe deliverydate_oe
1857 employee_startdate employee_enddate
1859 grep({ /^datepaid_\d+$/ ||
1860 /^transdate_oe_\d+$/ ||
1861 /^deliverydate_oe_\d+$/ ||
1863 /^deliverydate_\d+$/ ||
1867 reformat_numbers($output_numberformat, 2,
1868 qw(invtotal ordtotal quototal subtotal linetotal
1869 listprice sellprice netprice discount
1871 grep({ /^linetotal_\d+$/ ||
1872 /^listprice_\d+$/ ||
1873 /^sellprice_\d+$/ ||
1880 reformat_numbers($output_numberformat, undef,
1885 if ($form->{printer_code} ne "") {
1886 $form->{printer_code} = "_" . $form->{printer_code};
1889 $form->{IN} = "$form->{formname}$form->{language}$form->{printer_code}.html";
1890 if ($form->{format} eq 'postscript') {
1891 $form->{postscript} = 1;
1892 $form->{IN} =~ s/html$/tex/;
1893 } elsif ($form->{"format"} =~ /pdf/) {
1895 if ($form->{"format"} =~ /opendocument/) {
1896 $form->{IN} =~ s/html$/odt/;
1898 $form->{IN} =~ s/html$/tex/;
1900 } elsif ($form->{"format"} =~ /opendocument/) {
1901 $form->{"opendocument"} = 1;
1902 $form->{"IN"} =~ s/html$/odt/;
1905 if ($form->{media} eq 'printer') {
1906 $form->{OUT} = "| $form->{printer_command} &>/dev/null";
1907 $form->{printed} .= " $form->{formname}";
1908 $form->{printed} =~ s/^ //;
1910 $printed = $form->{printed};
1912 if ($form->{media} eq 'email') {
1913 $form->{subject} = qq|$form->{label} $form->{"${inv}number"}|
1914 unless $form->{subject};
1916 $form->{OUT} = "$sendmail";
1918 $form->{emailed} .= " $form->{formname}";
1919 $form->{emailed} =~ s/^ //;
1921 $emailed = $form->{emailed};
1923 if ($form->{media} eq 'queue') {
1924 %queued = split / /, $form->{queued};
1926 if ($filename = $queued{ $form->{formname} }) {
1927 $form->{queued} =~ s/$form->{formname} $filename//;
1928 unlink "$spool/$filename";
1929 $filename =~ s/\..*$//g;
1935 $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
1936 $form->{OUT} = ">$spool/$filename";
1939 $form->{queued} .= " $form->{formname} $filename";
1941 $form->{queued} =~ s/^ //;
1943 $queued = $form->{queued};
1945 $form->parse_template(\%myconfig, $userspath);
1947 $form->{callback} = "";
1949 if ($form->{media} eq 'email') {
1950 $form->{message} = $locale->text('sent') unless $form->{message};
1952 $message = $form->{message};
1954 # if we got back here restore the previous form
1955 if ($form->{media} =~ /(printer|email|queue)/) {
1957 $form->update_status(\%myconfig)
1958 if ($form->{media} eq 'queue' && $form->{id});
1962 $old_form->{"${inv}number"} = $form->{"${inv}number"};
1964 # restore and display form
1965 map { $form->{$_} = $old_form->{$_} } keys %$old_form;
1967 $form->{queued} = $queued;
1968 $form->{printed} = $printed;
1969 $form->{emailed} = $emailed;
1970 $form->{message} = $message;
1972 $form->{rowcount}--;
1973 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1974 qw(exchangerate creditlimit creditremaining);
1976 for $i (1 .. $form->{paidaccounts}) {
1978 $form->{"${_}_$i"} =
1979 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
1980 } qw(paid exchangerate);
1988 ($form->{media} eq 'printer')
1989 ? $locale->text('sent to printer')
1990 : $locale->text('emailed to') . " $form->{email}";
1991 $form->redirect(qq|$form->{label} $form->{"${inv}number"} $msg|);
1993 if ($form->{printing}) {
1998 $lxdebug->leave_sub();
2001 sub customer_details {
2002 $lxdebug->enter_sub();
2003 IS->customer_details(\%myconfig, \%$form);
2004 $lxdebug->leave_sub();
2007 sub vendor_details {
2008 $lxdebug->enter_sub();
2010 IR->vendor_details(\%myconfig, \%$form);
2012 $lxdebug->leave_sub();
2016 $lxdebug->enter_sub();
2018 $form->{postasnew} = 1;
2019 map { delete $form->{$_} } qw(printed emailed queued);
2023 $lxdebug->leave_sub();
2027 $lxdebug->enter_sub();
2028 if ($form->{second_run}) {
2029 $form->{print_and_post} = 0;
2032 $title = $form->{title};
2033 $form->{title} = $locale->text('Ship to');
2035 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2036 qw(exchangerate creditlimit creditremaining);
2038 # get details for name
2039 &{"$form->{vc}_details"};
2042 ($form->{vc} eq 'customer')
2043 ? $locale->text('Customer Number')
2044 : $locale->text('Vendor Number');
2046 # get pricegroups for parts
2047 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
2049 # build up html code for prices_$i
2050 set_pricegroup($form->{rowcount});
2052 $nextsub = ($form->{display_form}) ? $form->{display_form} : "display_form";
2054 $form->{rowcount}--;
2061 <form method=post action=$form->{script}>
2067 <tr class=listheading>
2068 <th class=listheading colspan=2 width=50%>|
2069 . $locale->text('Billing Address') . qq|</th>
2070 <th class=listheading width=50%>|
2071 . $locale->text('Shipping Address') . qq|</th>
2073 <tr height="5"></tr>
2075 <th align=right nowrap>$number</th>
2076 <td>$form->{"$form->{vc}number"}</td>
2079 <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
2080 <td>$form->{name}</td>
2081 <td><input name=shiptoname size=35 value="$form->{shiptoname}"></td>
2084 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
2085 <td>$form->{department_1}</td>
2086 <td><input name=shiptodepartment_1 size=35 value="$form->{shiptodepartment_1}"></td>
2089 <th align=right nowrap> </th>
2090 <td>$form->{department_2}</td>
2091 <td><input name=shiptodepartment_2 size=35 value="$form->{shiptodepartment_2}"></td>
2094 <th align=right nowrap>| . $locale->text('Street') . qq|</th>
2095 <td>$form->{street}</td>
2096 <td><input name=shiptostreet size=35 value="$form->{shiptostreet}"></td>
2099 <th align=right nowrap>| . $locale->text('Zipcode') . qq|</th>
2100 <td>$form->{zipcode}</td>
2101 <td><input name=shiptozipcode size=35 value="$form->{shiptozipcode}"></td>
2104 <th align=right nowrap>| . $locale->text('City') . qq|</th>
2105 <td>$form->{city}</td>
2106 <td><input name=shiptocity size=35 value="$form->{shiptocity}"></td>
2109 <th align=right nowrap>| . $locale->text('Country') . qq|</th>
2110 <td>$form->{country}</td>
2111 <td><input name=shiptocountry size=35 value="$form->{shiptocountry}"></td>
2114 <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
2115 <td>$form->{contact}</td>
2116 <td><input name=shiptocontact size=35 value="$form->{shiptocontact}"></td>
2119 <th align=right nowrap>| . $locale->text('Phone') . qq|</th>
2120 <td>$form->{"$form->{vc}phone"}</td>
2121 <td><input name=shiptophone size=20 value="$form->{shiptophone}"></td>
2124 <th align=right nowrap>| . $locale->text('Fax') . qq|</th>
2125 <td>$form->{"$form->{vc}fax"}</td>
2126 <td><input name=shiptofax size=20 value="$form->{shiptofax}"></td>
2129 <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
2130 <td>$form->{email}</td>
2131 <td><input name=shiptoemail size=35 value="$form->{shiptoemail}"></td>
2138 <input type=hidden name=nextsub value=$nextsub>
2142 map { delete $form->{$_} }
2143 qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax shiptoemail shiptodepartment_1 shiptodepartment_2 header);
2144 $form->{title} = $title;
2146 foreach $key (keys %$form) {
2147 $form->{$key} =~ s/\"/"/g;
2148 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2156 <input class=submit type=submit name=action value="|
2157 . $locale->text('Continue') . qq|">
2164 $lxdebug->leave_sub();
2168 $lxdebug->enter_sub();
2173 $form->{old_callback} = $form->escape($form->{callback}, 1);
2174 $form->{callback} = $form->escape("$form->{script}?action=display_form", 1);
2175 $form->{old_callback} = $form->escape($form->{old_callback}, 1);
2178 delete $form->{action};
2179 $customer = $form->{customer};
2180 map { $form->{"old_$_"} = $form->{"${_}_$row"} } qw(partnumber description);
2182 # save all other form variables in a previousform variable
2183 $form->{row} = $row;
2184 foreach $key (keys %$form) {
2187 $form->{$key} =~ s/&/%26/g;
2188 $previousform .= qq|$key=$form->{$key}&|;
2191 $previousform = $form->escape($previousform, 1);
2193 $form->{script} = "licenses.pl";
2195 map { $form->{$_} = $form->{"old_$_"} } qw(partnumber description);
2196 map { $form->{$_} = $form->escape($form->{$_}, 1) }
2197 qw(partnumber description);
2199 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|;
2202 $lxdebug->leave_sub();
2205 sub relink_accounts {
2206 $lxdebug->enter_sub();
2208 $form->{"taxaccounts"} =~ s/\s*$//;
2209 $form->{"taxaccounts"} =~ s/^\s*//;
2210 foreach my $accno (split(/\s*/, $form->{"taxaccounts"})) {
2211 map({ delete($form->{"${accno}_${_}"}); } qw(rate description taxnumber));
2213 $form->{"taxaccounts"} = "";
2215 for (my $i = 1; $i <= $form->{"rowcount"}; $i++) {
2216 if ($form->{"id_$i"}) {
2217 IC->retrieve_accounts(\%myconfig, $form, $form->{"id_$i"}, $i, 1);
2221 $lxdebug->leave_sub();
2226 $lxdebug->enter_sub();
2228 $form->get_duedate(\%myconfig);
2231 $result = "$form->{duedate}";
2234 $lxdebug->leave_sub();