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 #######################################################################
40 require "$form->{path}/common.pl";
42 # any custom scripts for this one
43 if (-f "$form->{path}/custom_io.pl") {
44 eval { require "$form->{path}/custom_io.pl"; };
46 if (-f "$form->{path}/$form->{login}_io.pl") {
47 eval { require "$form->{path}/$form->{login}_io.pl"; };
54 # this is for our long dates
55 # $locale->text('January')
56 # $locale->text('February')
57 # $locale->text('March')
58 # $locale->text('April')
59 # $locale->text('May ')
60 # $locale->text('June')
61 # $locale->text('July')
62 # $locale->text('August')
63 # $locale->text('September')
64 # $locale->text('October')
65 # $locale->text('November')
66 # $locale->text('December')
68 # this is for our short month
69 # $locale->text('Jan')
70 # $locale->text('Feb')
71 # $locale->text('Mar')
72 # $locale->text('Apr')
73 # $locale->text('May')
74 # $locale->text('Jun')
75 # $locale->text('Jul')
76 # $locale->text('Aug')
77 # $locale->text('Sep')
78 # $locale->text('Oct')
79 # $locale->text('Nov')
80 # $locale->text('Dec')
85 ########################################
86 # Eintrag fuer Version 2.2.0 geaendert #
87 # neue Optik im Rechnungsformular #
88 ########################################
90 $lxdebug->enter_sub();
92 if ($lizenzen && $form->{vc} eq "customer") {
93 if ($form->{type} =~ /sales_order/) {
94 @column_index = (runningnumber, partnumber, description, ship, qty);
95 } elsif ($form->{type} =~ /sales_quotation/) {
96 @column_index = (runningnumber, partnumber, description, qty);
98 @column_index = (runningnumber, partnumber, description, qty);
101 if ( ($form->{type} =~ /purchase_order/)
102 || ($form->{type} =~ /sales_order/)) {
103 @column_index = (runningnumber, partnumber, description, ship, qty);
105 @column_index = (runningnumber, partnumber, description, qty);
108 ############## ENDE Neueintrag ##################
110 my $dimension_units = AM->retrieve_units(\%myconfig, $form, "dimension");
111 my $service_units = AM->retrieve_units(\%myconfig, $form, "service");
112 my $all_units = AM->retrieve_units(\%myconfig, $form);
114 push @column_index, qw(unit);
116 #for pricegroups column
117 if ( $form->{type} =~ (/sales_quotation/)
118 or (($form->{level} =~ /Sales/) and ($form->{type} =~ /invoice/))
119 or (($form->{level} eq undef) and ($form->{type} =~ /invoice/))
120 or ($form->{type} =~ /sales_order/)) {
121 push @column_index, qw(sellprice_pg);
124 push @column_index, qw(sellprice);
126 if ($form->{vc} eq 'customer') {
127 push @column_index, qw(discount);
130 push @column_index, "linetotal";
132 my $colspan = $#column_index + 1;
134 $form->{invsubtotal} = 0;
135 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
137 ########################################
138 # Eintrag fuer Version 2.2.0 geaendert #
139 # neue Optik im Rechnungsformular #
140 ########################################
141 $column_data{runningnumber} =
142 qq|<th align=left nowrap width=5 class=listheading>|
143 . $locale->text('No.')
145 $column_data{partnumber} =
146 qq|<th align=left nowrap width=12 class=listheading>|
147 . $locale->text('Number')
149 $column_data{description} =
150 qq|<th align=left nowrap width=30 class=listheading>|
151 . $locale->text('Part Description')
154 qq|<th align=left nowrap width=5 class=listheading>|
155 . $locale->text('Ship')
158 qq|<th align=left nowrap width=5 class=listheading>|
159 . $locale->text('Qty')
162 qq|<th align=left nowrap width=5 class=listheading>|
163 . $locale->text('Unit')
165 $column_data{license} =
166 qq|<th align=left nowrap width=10 class=listheading>|
167 . $locale->text('License')
169 $column_data{serialnr} =
170 qq|<th align=left nowrap width=10 class=listheading>|
171 . $locale->text('Serial No.')
173 $column_data{projectnr} =
174 qq|<th align=left nowrap width=10 class=listheading>|
175 . $locale->text('Project')
177 $column_data{sellprice} =
178 qq|<th align=left nowrap width=15 class=listheading>|
179 . $locale->text('Price')
181 $column_data{sellprice_pg} =
182 qq|<th align=left nowrap width=15 class=listheading>|
183 . $locale->text('Pricegroup')
185 $column_data{discount} =
186 qq|<th align=left class=listheading>|
187 . $locale->text('Discount')
189 $column_data{linetotal} =
190 qq|<th align=left nowrap width=10 class=listheading>|
191 . $locale->text('Extended')
194 qq|<th align=left nowrap width=10 class=listheading>|
195 . $locale->text('Bin')
197 ############## ENDE Neueintrag ##################
203 <tr class=listheading>|;
205 map { print "\n$column_data{$_}" } @column_index;
211 $runningnumber = $locale->text('No.');
212 $deliverydate = $locale->text('Delivery Date');
213 $serialnumber = $locale->text('Serial No.');
214 $projectnumber = $locale->text('Project');
215 $partsgroup = $locale->text('Group');
216 $reqdate = $locale->text('Reqdate');
218 $delvar = 'deliverydate';
220 if ($form->{type} =~ /_order$/ || $form->{type} =~ /_quotation$/) {
221 $deliverydate = $locale->text('Required by');
225 for $i (1 .. $numrows) {
230 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
231 } qw(qty ship discount sellprice price_new price_old) unless ($form->{simple_save});
233 if (!$form->{"unit_old_$i"}) {
234 # Neue Ware aus der Datenbank. In diesem Fall ist unit_$i die
235 # Einheit, wie sie in den Stammdaten hinterlegt wurde.
236 # Es sollte also angenommen werden, dass diese ausgewaehlt war.
237 $form->{"unit_old_$i"} = $form->{"unit_$i"};
242 # Die zuletzt ausgewaehlte mit der aktuell ausgewaehlten Einheit
243 # vergleichen und bei Unterschied den Preis entsprechend umrechnen.
244 $form->{"selected_unit_$i"} = $form->{"unit_$i"} unless ($form->{"selected_unit_$i"});
246 my $check_units = $form->{"inventory_accno_$i"} ? $dimension_units : $service_units;
247 if (!$check_units->{$form->{"selected_unit_$i"}} ||
248 ($check_units->{$form->{"selected_unit_$i"}}->{"base_unit"} ne
249 $all_units->{$form->{"unit_old_$i"}}->{"base_unit"})) {
250 # Die ausgewaehlte Einheit ist fuer diesen Artikel nicht gueltig
251 # (z.B. Dimensionseinheit war ausgewaehlt, es handelt sich aber
252 # um eine Dienstleistung). Dann keinerlei Umrechnung vornehmen.
253 $form->{"unit_old_$i"} = $form->{"selected_unit_$i"} = $form->{"unit_$i"};
255 if ((!$form->{"prices_$i"}) || ($form->{"new_pricegroup_$i"} == $form->{"old_pricegroup_$i"})) {
256 if ($form->{"unit_old_$i"} ne $form->{"selected_unit_$i"}) {
258 if (defined($all_units->{$form->{"unit_old_$i"}}->{"factor"}) &&
259 $all_units->{$form->{"unit_old_$i"}}->{"factor"}) {
260 $basefactor = $all_units->{$form->{"selected_unit_$i"}}->{"factor"} /
261 $all_units->{$form->{"unit_old_$i"}}->{"factor"};
263 $form->{"sellprice_$i"} *= $basefactor;
264 $form->{"unit_old_$i"} = $form->{"selected_unit_$i"};
267 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
269 $decimalplaces = ($dec > 2) ? $dec : 2;
273 $form->{"sellprice_$i"} * $form->{"discount_$i"} / 100,
277 $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
278 $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
280 # convert " to "
281 map { $form->{"${_}_$i"} =~ s/\"/"/g }
282 qw(partnumber description unit unit_old);
284 ########################################
285 # Eintrag fuer Version 2.2.0 geaendert #
286 # neue Optik im Rechnungsformular #
287 ########################################
288 $column_data{runningnumber} =
289 qq|<td><input name="runningnumber_$i" size=5 value=$i></td>|; # HuT
290 ############## ENDE Neueintrag ##################
292 $column_data{partnumber} =
293 qq|<td><input name="partnumber_$i" size=12 value="$form->{"partnumber_$i"}"></td>|;
295 if (($rows = $form->numtextrows($form->{"description_$i"}, 30, 6)) > 1) {
296 $column_data{description} =
297 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>|;
299 $column_data{description} =
300 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>|;
303 (my $qty_dec) = ($form->{"qty_$i"} =~ /\.(\d+)/);
304 $qty_dec = length $qty_dec;
307 qq|<td align=right><input name="qty_$i" size=5 value=|
308 . $form->format_amount(\%myconfig, $form->{"qty_$i"}, $qty_dec) .qq|>|;
309 if ($form->{"formel_$i"}) {
310 $column_data{qty} .= qq|<button type="button" onclick="calculate_qty_selection_window('qty_$i','alu_$i', 'formel_$i', $i)">| . $locale->text('*/') . qq|</button>
311 <input type=hidden name="formel_$i" value="$form->{"formel_$i"}"><input type=hidden name="alu_$i" value="$form->{"alu_$i"}"></td>|;
314 qq|<td align=right><input name="ship_$i" size=5 value=|
315 . $form->format_amount(\%myconfig, $form->{"ship_$i"})
318 my $is_part = $form->{"inventory_accno_$i"};
319 my $is_assigned = $form->{"id_$i"};
320 my $this_unit = $form->{"unit_$i"};
321 if ($form->{"selected_unit_$i"} && $this_unit &&
322 $all_units->{$form->{"selected_unit_$i"}} && $all_units->{$this_unit} &&
323 ($all_units->{$form->{"selected_unit_$i"}}->{"base_unit"} eq $all_units->{$this_unit}->{"base_unit"})) {
324 $this_unit = $form->{"selected_unit_$i"};
325 } elsif (!$is_assigned ||
326 ($is_part && !$this_unit && ($all_units->{$this_unit} && ($all_units->{$this_unit}->{"base_unit"} eq $all_units->{"kg"}->{"base_unit"})))) {
330 $column_data{"unit"} = "<td>" .
331 ($qty_readonly ? " " :
332 AM->unit_select_html($is_part ? $dimension_units :
333 $is_assigned ? $service_units : $all_units,
334 "unit_$i", $this_unit,
335 $is_assigned ? $form->{"unit_$i"} : undef))
338 # build in drop down list for pricesgroups
339 if ($form->{"prices_$i"}) {
340 if ($form->{"new_pricegroup_$i"} != $form->{"old_pricegroup_$i"}) {
341 $price_tmp = $form->format_amount(\%myconfig, $form->{"price_new_$i"}, $decimalplaces);
343 $price_tmp = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
346 $column_data{sellprice_pg} =
347 qq|<td align=right><select name="sellprice_pg_$i">$form->{"prices_$i"}</select></td>|;
348 $column_data{sellprice} =
349 qq|<td><input name="sellprice_$i" size=10 value=$price_tmp></td>|;
352 # for last row and report
353 # set pricegroup drop down list from report menu
354 if ($form->{"sellprice_$i"} != 0) {
356 qq|<option value="$form->{"sellprice_$i"}--$form->{"pricegroup_id_$i"}" selected>$form->{"pricegroup_$i"}</option>\n|;
358 $form->{"pricegroup_old_$i"} = $form->{"pricegroup_id_$i"};
360 $column_data{sellprice_pg} =
361 qq|<td align=right><select name="sellprice_pg_$i">$prices</select></td>|;
366 $column_data{sellprice_pg} = qq|<td align=right> </td>|;
369 $column_data{sellprice} =
370 qq|<td><input name="sellprice_$i" size=10 value=|
371 . $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
375 $column_data{discount} =
376 qq|<td align=right><input name="discount_$i" size=3 value=|
377 . $form->format_amount(\%myconfig, $form->{"discount_$i"})
379 $column_data{linetotal} =
381 . $form->format_amount(\%myconfig, $linetotal, 2)
383 $column_data{bin} = qq|<td>$form->{"bin_$i"}</td>|;
385 ########################################
386 # Eintrag fuer Version 2.2.0 geaendert #
387 # neue Optik im Rechnungsformular #
388 ########################################
389 # if ($lizenzen && $form->{type} eq "invoice" && $form->{vc} eq "customer") {
390 # $column_data{license} = qq|<td><select name="licensenumber_$i">$form->{"lizenzen_$i"}></select></td>|;
393 # if ($form->{type} !~ /_quotation/) {
394 # $column_data{serialnr} = qq|<td><input name="serialnumber_$i" size=10 value="$form->{"serialnumber_$i"}"></td>|;
397 # $column_data{projectnr} = qq|<td><input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}"></td>|;
398 ############## ENDE Neueintrag ##################
402 <tr valign=top class=listrow$j>|;
404 map { print "\n$column_data{$_}" } @column_index;
409 <input type=hidden name="orderitems_id_$i" value=$form->{"orderitems_id_$i"}>
410 <input type=hidden name="bo_$i" value=$form->{"bo_$i"}>
412 <input type=hidden name="pricegroup_old_$i" value=$form->{"pricegroup_old_$i"}>
413 <input type=hidden name="price_old_$i" value=$form->{"price_old_$i"}>
414 <input type=hidden name="unit_old_$i" value="$form->{"selected_unit_$i"}">
415 <input type=hidden name="price_new_$i" value=|
416 . $form->format_amount(\%myconfig, $form->{"price_new_$i"}) . qq|>
418 <input type=hidden name="id_$i" value=$form->{"id_$i"}>
419 <input type=hidden name="inventory_accno_$i" value=$form->{"inventory_accno_$i"}>
420 <input type=hidden name="bin_$i" value="$form->{"bin_$i"}">
421 <input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">
422 <input type=hidden name="partnotes_$i" value="$form->{"partnotes_$i"}">
423 <input type=hidden name="income_accno_$i" value=$form->{"income_accno_$i"}>
424 <input type=hidden name="expense_accno_$i" value=$form->{"expense_accno_$i"}>
425 <input type=hidden name="listprice_$i" value="$form->{"listprice_$i"}">
426 <input type=hidden name="assembly_$i" value="$form->{"assembly_$i"}">
427 <input type=hidden name="taxaccounts_$i" value="$form->{"taxaccounts_$i"}">
428 <input type=hidden name="ordnumber_$i" value="$form->{"ordnumber_$i"}">
429 <input type=hidden name="transdate_$i" value="$form->{"transdate_$i"}">
430 <input type=hidden name="cusordnumber_$i" value="$form->{"cusordnumber_$i"}">
431 <input type=hidden name="longdescription_$i" value="$form->{"longdescription_$i"}">
432 <input type=hidden name="basefactor_$i" value="$form->{"basefactor_$i"}">
436 ########################################
437 # Eintrag fuer Version 2.2.0 geaendert #
438 # neue Optik im Rechnungsformular #
439 ########################################
443 <td colspan=$colspan>
445 if ($lizenzen && $form->{type} eq "invoice" && $form->{vc} eq "customer") {
446 my $selected = $form->{"licensenumber_$i"};
448 $form->{"lizenzen_$i"} =~ s/ selected//g;
449 $form->{"lizenzen_$i"} =~
450 s/value="${selected}"\>/value="${selected}" selected\>/;
451 $lizenzen_quoted = $form->{"lizenzen_$i"};
452 $lizenzen_quoted =~ s/\"/"/g;
454 <b>Lizenz\#</b> <select name="licensenumber_$i" size=1>
455 $form->{"lizenzen_$i"}
457 <input type=hidden name="lizenzen_$i" value="${lizenzen_quoted}">
460 if ($form->{type} !~ /_quotation/) {
462 <b>$serialnumber</b> <input name="serialnumber_$i" size=15 value="$form->{"serialnumber_$i"}">|;
466 <b>$projectnumber</b> <input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}">
467 <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}">
468 <input type=hidden name="project_id_$i" value="$form->{"project_id_$i"}">
470 if ($form->{type} eq 'invoice' or $form->{type} =~ /order/) {
472 ($form->{type} eq 'invoice')
474 : 'reqdate'; # invoice uses a different term for the same thing.
476 <b>${$reqdate_term}</b> <input name="${reqdate_term}_$i" size=11 value="$form->{"${reqdate_term}_$i"}">
479 my $subtotalchecked = ($form->{"subtotal_$i"}) ? "checked" : "";
481 <b>|.$locale->text('Subtotal').qq|</b> <input type="checkbox" name="subtotal_$i" value="1" "$subtotalchecked">
487 ############## ENDE Neueintrag ##################
489 map { $form->{"${_}_base"} += $linetotal }
490 (split / /, $form->{"taxaccounts_$i"});
492 $form->{invsubtotal} += $linetotal;
501 $lxdebug->leave_sub();
504 ##################################################
505 # build html-code for pricegroups in variable $form->{prices_$j}
508 $lxdebug->enter_sub();
509 my $rowcount = shift;
510 for $j (1 .. $rowcount) {
511 my $pricegroup_old = $form->{"pricegroup_old_$i"};
512 if ($form->{PRICES}{$j}) {
514 $prices = '<option value="--">' . $locale->text("none (pricegroup)") . '</option>';
516 foreach $item (@{ $form->{PRICES}{$j} }) {
518 #$price = $form->round_amount($myconfig, $item->{price}, 5);
519 #$price = $form->format_amount($myconfig, $item->{price}, 2);
520 $price = $item->{price};
521 $pricegroup_id = $item->{pricegroup_id};
522 $pricegroup = $item->{pricegroup};
524 # build drop down list for pricegroups
526 qq|<option value="$price--$pricegroup_id"$item->{selected}>$pricegroup</option>\n|;
531 # $form->{"${_}_$j"} =
532 # $form->format_amount(\%myconfig, $form->{"${_}_$j"})
533 # } qw(sellprice price_new price_old);
535 # set new selectedpricegroup_id and prices for "Preis"
536 if ($item->{selected} && ($pricegroup_id != 0)) {
537 $form->{"pricegroup_old_$j"} = $pricegroup_id;
538 $form->{"price_new_$j"} = $price;
539 $form->{"sellprice_$j"} = $price;
541 if ($pricegroup_id == 0) {
542 $form->{"price_new_$j"} = $form->{"sellprice_$j"};
545 $form->{"prices_$j"} = $prices;
548 $lxdebug->leave_sub();
552 $lxdebug->enter_sub();
553 @column_index = qw(ndx partnumber description onhand unit sellprice);
555 $column_data{ndx} = qq|<th> </th>|;
556 $column_data{partnumber} =
557 qq|<th class=listheading>| . $locale->text('Number') . qq|</th>|;
558 $column_data{description} =
559 qq|<th class=listheading>| . $locale->text('Part Description') . qq|</th>|;
560 $column_data{sellprice} =
561 qq|<th class=listheading>| . $locale->text('Price') . qq|</th>|;
562 $column_data{onhand} =
563 qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|;
565 qq|<th class=listheading>| . $locale->text('Unit') . qq|</th>|;
566 # list items with radio button on a form
569 $title = $locale->text('Select from one of the items below');
570 $colspan = $#column_index + 1;
575 <form method=post action=$form->{script}>
579 <th class=listtop colspan=$colspan>$title</th>
582 <tr class=listheading>|;
584 map { print "\n$column_data{$_}" } @column_index;
589 foreach $ref (@{ $form->{item_list} }) {
590 $checked = ($i++) ? "" : "checked";
593 if ($ref->{inventory_accno} > 0) {
594 $ref->{"lizenzen"} = qq|<option></option>|;
595 foreach $item (@{ $form->{LIZENZEN}{ $ref->{"id"} } }) {
596 $ref->{"lizenzen"} .=
597 qq|<option value=\"$item->{"id"}\">$item->{"licensenumber"}</option>|;
599 $ref->{"lizenzen"} .= qq|<option value=-1>Neue Lizenz</option>|;
600 $ref->{"lizenzen"} =~ s/\"/"/g;
604 map { $ref->{$_} =~ s/\"/"/g } qw(partnumber description unit);
608 $form->round_amount($ref->{sellprice} * (1 - $form->{tradediscount}), 2);
610 qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
611 $column_data{partnumber} =
612 qq|<td><input name="new_partnumber_$i" type=hidden value="$ref->{partnumber}">$ref->{partnumber}</td>|;
613 $column_data{description} =
614 qq|<td><input name="new_description_$i" type=hidden value="$ref->{description}">$ref->{description}</td>|;
615 $column_data{sellprice} =
616 qq|<td align=right><input name="new_sellprice_$i" type=hidden value=$ref->{sellprice}>|
617 . $form->format_amount(\%myconfig, $ref->{sellprice}, 2, " ")
619 $column_data{onhand} =
620 qq|<td align=right><input name="new_onhand_$i" type=hidden value=$ref->{onhand}>|
621 . $form->format_amount(\%myconfig, $ref->{onhand}, '', " ")
624 qq|<td>$ref->{unit}</td>|;
628 <tr class=listrow$j>|;
630 map { print "\n$column_data{$_}" } @column_index;
635 <input name="new_bin_$i" type=hidden value="$ref->{bin}">
636 <input name="new_listprice_$i" type=hidden value=$ref->{listprice}>
637 <input name="new_inventory_accno_$i" type=hidden value=$ref->{inventory_accno}>
638 <input name="new_income_accno_$i" type=hidden value=$ref->{income_accno}>
639 <input name="new_expense_accno_$i" type=hidden value=$ref->{expense_accno}>
640 <input name="new_unit_$i" type=hidden value="$ref->{unit}">
641 <input name="new_weight_$i" type=hidden value="$ref->{weight}">
642 <input name="new_assembly_$i" type=hidden value="$ref->{assembly}">
643 <input name="new_taxaccounts_$i" type=hidden value="$ref->{taxaccounts}">
644 <input name="new_partsgroup_$i" type=hidden value="$ref->{partsgroup}">
645 <input name="new_formel_$i" type=hidden value="$ref->{formel}">
646 <input name="new_longdescription_$i" type=hidden value="$ref->{longdescription}">
647 <input name="new_not_discountable_$i" type=hidden value="$ref->{not_discountable}">
648 <input name="new_part_payment_id_$i" type=hidden value="$ref->{part_payment_id}">
650 <input name="new_id_$i" type=hidden value=$ref->{id}>
655 <input name="new_lizenzen_$i" type=hidden value="$ref->{lizenzen}">
662 <tr><td colspan=8><hr size=3 noshade></td></tr>
665 <input name=lastndx type=hidden value=$i>
669 # delete action variable
670 map { delete $form->{$_} } qw(action item_list header);
672 # save all other form variables
673 foreach $key (keys %${form}) {
674 $form->{$key} =~ s/\"/"/g;
675 print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
679 <input type=hidden name=nextsub value=item_selected>
682 <input class=submit type=submit name=action value="|
683 . $locale->text('Continue') . qq|">
690 $lxdebug->leave_sub();
694 $lxdebug->enter_sub();
696 # replace the last row with the checked row
697 $i = $form->{rowcount};
698 $i = $form->{assembly_rows} if ($form->{item} eq 'assembly');
704 #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
705 #$form->{"sellprice_$i"} = $form->{"sellprice_$i"};
707 # if there was a price entered, override it
708 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
710 map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} }
711 qw(id partnumber description sellprice listprice inventory_accno income_accno expense_accno bin unit weight assembly taxaccounts partsgroup formel longdescription not_discountable);
712 if ($form->{"part_payment_id_$i"} ne "") {
713 $form->{payment_id} = $form->{"part_payment_id_$i"};
717 map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} } qw(lizenzen);
720 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
722 $decimalplaces = ($dec > 2) ? $dec : 2;
725 $form->{"sellprice_$i"} = $sellprice;
728 # if there is an exchange rate adjust sellprice
729 if (($form->{exchangerate} * 1) != 0) {
730 $form->{"sellprice_$i"} /= $form->{exchangerate};
731 $form->{"sellprice_$i"} =
732 $form->round_amount($form->{"sellprice_$i"}, $decimalplaces);
736 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
737 qw(sellprice listprice weight);
739 $form->{sellprice} += ($form->{"sellprice_$i"} * $form->{"qty_$i"});
740 $form->{weight} += ($form->{"weight_$i"} * $form->{"qty_$i"});
742 if ($form->{"not_discountable_$i"}) {
743 $form->{"discount_$i"} = 0;
747 $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) *
749 map { $form->{"${_}_base"} += $amount }
750 (split / /, $form->{"taxaccounts_$i"});
751 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /,
752 $form->{"taxaccounts_$i"}
753 if !$form->{taxincluded};
755 $form->{creditremaining} -= $amount;
757 $form->{"runningnumber_$i"} = $i;
759 # delete all the new_ variables
760 for $i (1 .. $form->{lastndx}) {
761 map { delete $form->{"new_${_}_$i"} }
762 qw(partnumber description sellprice bin listprice inventory_accno income_accno expense_accno unit assembly taxaccounts id);
765 map { delete $form->{$_} } qw(ndx lastndx nextsub);
770 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces)
771 } qw(sellprice listprice) if $form->{item} ne 'assembly';
773 # get pricegroups for parts
774 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
776 # build up html code for prices_$i
777 set_pricegroup($form->{rowcount});
781 $lxdebug->leave_sub();
785 $lxdebug->enter_sub();
788 $form->{old_callback} = $form->escape($form->{callback}, 1);
789 $form->{callback} = $form->escape("$form->{script}?action=display_form", 1);
792 delete $form->{action};
794 # save all other form variables in a previousform variable
795 foreach $key (keys %$form) {
798 $form->{$key} =~ s/&/%26/g;
799 $previousform .= qq|$key=$form->{$key}&|;
802 $previousform = $form->escape($previousform, 1);
804 $i = $form->{rowcount};
805 map { $form->{"${_}_$i"} =~ s/\"/"/g } qw(partnumber description);
812 <h4 class=error>| . $locale->text('Item not on file!') . qq|
815 | . $locale->text('What type of item is this?') . qq|</h4>
817 <form method=post action=ic.pl>
821 <input class=radio type=radio name=item value=part checked> |
822 . $locale->text('Part') . qq|<br>
823 <input class=radio type=radio name=item value=service> |
824 . $locale->text('Service')
827 <input type=hidden name=previousform value="$previousform">
828 <input type=hidden name=partnumber value="$form->{"partnumber_$i"}">
829 <input type=hidden name=description value="$form->{"description_$i"}">
830 <input type=hidden name=rowcount value=$form->{rowcount}>
831 <input type=hidden name=taxaccount2 value=$form->{taxaccounts}>
832 <input type=hidden name=vc value=$form->{vc}>
834 <input type=hidden name=path value=$form->{path}>
835 <input type=hidden name=login value=$form->{login}>
836 <input type=hidden name=password value=$form->{password}>
838 <input type=hidden name=nextsub value=add>
841 <input class=submit type=submit name=action value="|
842 . $locale->text('Continue') . qq|">
849 $lxdebug->leave_sub();
853 $lxdebug->enter_sub();
857 $form->language_payment(\%myconfig);
859 # if we have a display_form
860 if ($form->{display_form}) {
861 &{"$form->{display_form}"};
865 # if ( $form->{print_and_post}
866 # && $form->{second_run}
867 # && ($form->{action} eq "display_form")) {
868 # for (keys %$form) { $old_form->{$_} = $form->{$_} }
869 # $old_form->{rowcount}++;
871 # #$form->{rowcount}--;
872 # #$form->{rowcount}--;
874 # $form->{print_and_post} = 0;
876 # &print_form($old_form);
880 # $form->{action} = "";
881 # $form->{resubmit} = 0;
883 # if ($form->{print_and_post} && !$form->{second_run}) {
884 # $form->{second_run} = 1;
885 # $form->{action} = "display_form";
886 # $form->{rowcount}--;
887 # my $rowcount = $form->{rowcount};
889 # # get pricegroups for parts
890 # IS->get_pricegroups_for_parts(\%myconfig, \%$form);
892 # # build up html code for prices_$i
893 # set_pricegroup($rowcount);
895 # $form->{resubmit} = 1;
900 $numrows = ++$form->{rowcount};
901 $subroutine = "display_row";
903 if ($form->{item} eq 'part') {
905 #set preisgruppenanzahl
906 $numrows = $form->{price_rows};
907 $subroutine = "price_row";
909 &{$subroutine}($numrows);
911 $numrows = ++$form->{makemodel_rows};
912 $subroutine = "makemodel_row";
914 if ($form->{item} eq 'assembly') {
915 $numrows = $form->{price_rows};
916 $subroutine = "price_row";
918 &{$subroutine}($numrows);
920 $numrows = ++$form->{makemodel_rows};
921 $subroutine = "makemodel_row";
923 # create makemodel rows
924 &{$subroutine}($numrows);
926 $numrows = ++$form->{assembly_rows};
927 $subroutine = "assembly_row";
929 if ($form->{item} eq 'service') {
930 $numrows = $form->{price_rows};
931 $subroutine = "price_row";
933 &{$subroutine}($numrows);
939 &{$subroutine}($numrows) if $numrows;
943 $lxdebug->leave_sub();
947 $lxdebug->enter_sub();
951 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)
955 # remove any makes or model rows
956 if ($form->{item} eq 'part') {
957 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
958 qw(listprice sellprice lastcost weight rop);
960 @flds = (make, model);
961 for my $i (1 .. ($form->{makemodel_rows})) {
962 if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
966 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
971 $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
972 $form->{makemodel_rows} = $count;
974 } elsif ($form->{item} eq 'assembly') {
976 $form->{sellprice} = 0;
978 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
979 qw(listprice rop stock);
982 qw(id qty unit bom partnumber description sellprice weight runningnumber partsgroup);
984 for my $i (1 .. ($form->{assembly_rows} - 1)) {
985 if ($form->{"qty_$i"}) {
989 $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
991 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
993 #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
995 $form->{sellprice} += ($form->{"qty_$i"} * $form->{"sellprice_$i"});
996 $form->{weight} += ($form->{"qty_$i"} * $form->{"weight_$i"});
1001 $form->{sellprice} = $form->round_amount($form->{sellprice}, 2);
1003 $form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows});
1004 $form->{assembly_rows} = $count;
1007 @flds = qw(make model);
1010 for my $i (1 .. ($form->{makemodel_rows})) {
1011 if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
1015 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1020 $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
1021 $form->{makemodel_rows} = $count;
1025 # this section applies to invoices and orders
1026 # remove any empty numbers
1027 if ($form->{rowcount}) {
1028 for my $i (1 .. $form->{rowcount} - 1) {
1029 if ($form->{"partnumber_$i"}) {
1033 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1036 if ($form->{"licensenumber_$i"} == -1) {
1044 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
1045 $form->{rowcount} = $count;
1047 $form->{creditremaining} -= &invoicetotal;
1054 if ( $form->{type} =~ (/sales_quotation/)
1055 or (($form->{level} =~ /Sales/) and ($form->{type} =~ /invoice/))
1056 or (($form->{level} eq undef) and ($form->{type} =~ /invoice/))
1057 or ($form->{type} =~ /sales_order/)) {
1059 # get pricegroups for parts
1060 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1062 # build up html code for prices_$i
1063 set_pricegroup($form->{rowcount});
1069 $lxdebug->leave_sub();
1073 $lxdebug->enter_sub();
1075 $form->{oldinvtotal} = 0;
1077 # add all parts and deduct paid
1078 map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
1080 my ($amount, $sellprice, $discount, $qty);
1082 for my $i (1 .. $form->{rowcount}) {
1083 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1084 $discount = $form->parse_amount(\%myconfig, $form->{"discount_$i"});
1085 $qty = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
1087 #($form->{"sellprice_$i"}, $form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
1089 $amount = $sellprice * (1 - $discount / 100) * $qty;
1090 map { $form->{"${_}_base"} += $amount }
1091 (split / /, $form->{"taxaccounts_$i"});
1092 $form->{oldinvtotal} += $amount;
1095 map { $form->{oldinvtotal} += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1096 split / /, $form->{taxaccounts}
1097 if !$form->{taxincluded};
1099 $form->{oldtotalpaid} = 0;
1100 for $i (1 .. $form->{paidaccounts}) {
1101 $form->{oldtotalpaid} += $form->{"paid_$i"};
1104 $lxdebug->leave_sub();
1107 return ($form->{oldinvtotal} - $form->{oldtotalpaid});
1110 sub validate_items {
1111 $lxdebug->enter_sub();
1113 # check if items are valid
1114 if ($form->{rowcount} == 1) {
1119 for $i (1 .. $form->{rowcount} - 1) {
1120 $form->isblank("partnumber_$i",
1121 $locale->text('Number missing in Row') . " $i");
1124 $lxdebug->leave_sub();
1128 $lxdebug->enter_sub();
1129 if ($form->{second_run}) {
1130 $form->{print_and_post} = 0;
1132 $form->{ordnumber} = $form->{invnumber};
1134 map { delete $form->{$_} } qw(id printed emailed queued);
1135 if ($form->{script} eq 'ir.pl' || $form->{type} eq 'request_quotation') {
1136 $form->{title} = $locale->text('Add Purchase Order');
1137 $form->{vc} = 'vendor';
1138 $form->{type} = 'purchase_order';
1141 if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_quotation') {
1142 $form->{title} = $locale->text('Add Sales Order');
1143 $form->{vc} = 'customer';
1144 $form->{type} = 'sales_order';
1147 $form->{script} = 'oe.pl';
1149 $form->{shipto} = 1;
1151 $form->{rowcount}--;
1153 $form->{cp_id} *= 1;
1155 require "$form->{path}/$form->{script}";
1157 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1159 $currency = $form->{currency};
1163 $form->{currency} = $currency;
1164 $form->{exchangerate} = "";
1165 $form->{forex} = "";
1166 $form->{exchangerate} = $exchangerate
1170 $form->check_exchangerate(
1171 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1174 for $i (1 .. $form->{rowcount}) {
1175 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
1176 $form->{"${_}_${i}"})
1177 if ($form->{"${_}_${i}"}) }
1178 qw(ship qty sellprice listprice basefactor));
1184 $lxdebug->leave_sub();
1188 $lxdebug->enter_sub();
1189 if ($form->{second_run}) {
1190 $form->{print_and_post} = 0;
1192 map { delete $form->{$_} } qw(id printed emailed queued);
1194 if ($form->{script} eq 'ir.pl' || $form->{type} eq 'purchase_order') {
1195 $form->{title} = $locale->text('Add Request for Quotation');
1196 $form->{vc} = 'vendor';
1197 $form->{type} = 'request_quotation';
1200 if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_order') {
1201 $form->{title} = $locale->text('Add Quotation');
1202 $form->{vc} = 'customer';
1203 $form->{type} = 'sales_quotation';
1207 $form->{cp_id} *= 1;
1209 $form->{script} = 'oe.pl';
1211 $form->{shipto} = 1;
1213 $form->{rowcount}--;
1215 require "$form->{path}/$form->{script}";
1217 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1219 $currency = $form->{currency};
1223 $form->{currency} = $currency;
1224 $form->{exchangerate} = "";
1225 $form->{forex} = "";
1226 $form->{exchangerate} = $exchangerate
1230 $form->check_exchangerate(
1231 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1234 for $i (1 .. $form->{rowcount}) {
1235 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
1236 $form->{"${_}_${i}"})
1237 if ($form->{"${_}_${i}"}) }
1238 qw(ship qty sellprice listprice basefactor));
1244 $lxdebug->leave_sub();
1247 sub request_for_quotation {
1252 $lxdebug->enter_sub();
1253 if ($form->{second_run}) {
1254 $form->{print_and_post} = 0;
1255 $form->{resubmit} = 0;
1257 if ($myconfig{role} eq 'admin') {
1259 <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
1260 <td><input name=bcc size=30 value="$form->{bcc}"></td>
1264 if ($form->{formname} =~ /(pick|packing|bin)_list/) {
1265 $form->{email} = $form->{shiptoemail} if $form->{shiptoemail};
1268 $name = $form->{ $form->{vc} };
1270 $title = $locale->text('E-mail') . " $name";
1272 $form->{oldmedia} = $form->{media};
1273 $form->{media} = "email";
1280 <form method=post action=$form->{script}>
1284 <th class=listtop>$title</th>
1286 <tr height="5"></tr>
1291 <th align=right nowrap>| . $locale->text('To') . qq|</th>
1292 <td><input name=email size=30 value="$form->{email}"></td>
1293 <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
1294 <td><input name=cc size=30 value="$form->{cc}"></td>
1297 <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
1298 <td><input name=subject size=30 value="$form->{subject}"></td>
1308 <th align=left nowrap>| . $locale->text('Message') . qq|</th>
1311 <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
1322 map { delete $form->{$_} }
1323 qw(action email cc bcc subject message formname sendmode format header override);
1325 # save all other variables
1326 foreach $key (keys %$form) {
1327 $form->{$key} =~ s/\"/"/g;
1328 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1335 <td><hr size=3 noshade></td>
1339 <input type=hidden name=nextsub value=send_email>
1342 <input name=action class=submit type=submit value="|
1343 . $locale->text('Continue') . qq|">
1350 $lxdebug->leave_sub();
1354 $lxdebug->enter_sub();
1356 $old_form = new Form;
1358 map { $old_form->{$_} = $form->{$_} } keys %$form;
1359 $old_form->{media} = $form->{oldmedia};
1361 &print_form($old_form);
1363 $lxdebug->leave_sub();
1367 $lxdebug->enter_sub();
1368 $form->{sendmode} = "attachment";
1371 $form->{"format"} ? $form->{"format"} :
1372 $myconfig{"template_format"} ? $myconfig{"template_format"} :
1376 $form->{"copies"} ? $form->{"copies"} :
1377 $myconfig{"copies"} ? $myconfig{"copies"} :
1380 $form->{PD}{ $form->{formname} } = "selected";
1381 $form->{DF}{ $form->{format} } = "selected";
1382 $form->{OP}{ $form->{media} } = "selected";
1383 $form->{SM}{ $form->{sendmode} } = "selected";
1385 if ($form->{type} eq 'purchase_order') {
1386 $type = qq|<select name=formname>
1387 <option value=purchase_order $form->{PD}{purchase_order}>|
1388 . $locale->text('Purchase Order') . qq|
1389 <option value=bin_list $form->{PD}{bin_list}>|
1390 . $locale->text('Bin List');
1393 if ($form->{type} eq 'credit_note') {
1394 $type = qq|<select name=formname>
1395 <option value=credit_note $form->{PD}{credit_note}>|
1396 . $locale->text('Credit Note');
1399 if ($form->{type} eq 'sales_order') {
1400 $type = qq|<select name=formname>
1401 <option value=sales_order $form->{PD}{sales_order}>|
1402 . $locale->text('Confirmation') . qq|
1403 <option value=proforma $form->{PD}{proforma}>|
1404 . $locale->text('Proforma Invoice') . qq|
1405 <option value=pick_list $form->{PD}{pick_list}>|
1406 . $locale->text('Pick List') . qq|
1407 <option value=packing_list $form->{PD}{packing_list}>|
1408 . $locale->text('Packing List');
1411 if ($form->{type} =~ /_quotation$/) {
1412 $type = qq|<select name=formname>
1413 <option value="$`_quotation" $form->{PD}{"$`_quotation"}>|
1414 . $locale->text('Quotation');
1417 if ($form->{type} eq 'invoice') {
1418 $type = qq|<select name=formname>
1419 <option value=invoice $form->{PD}{invoice}>|
1420 . $locale->text('Invoice') . qq|
1421 <option value=proforma $form->{PD}{proforma}>|
1422 . $locale->text('Proforma Invoice') . qq|
1423 <option value=packing_list $form->{PD}{packing_list}>|
1424 . $locale->text('Packing List');
1427 if ($form->{type} eq 'invoice' && $form->{storno}) {
1428 $type = qq|<select name=formname>
1429 <option value=storno_invoice $form->{PD}{storno_invoice}>|
1430 . $locale->text('Storno Invoice') . qq|
1431 <option value=storno_packing_list $form->{PD}{storno_packing_list}>|
1432 . $locale->text('Storno Packing List');
1435 if ($form->{type} eq 'credit_note') {
1436 $type = qq|<select name=formname>
1437 <option value=credit_note $form->{PD}{credit_note}>|
1438 . $locale->text('Credit Note');
1441 if ($form->{type} eq 'ship_order') {
1442 $type = qq|<select name=formname>
1443 <option value=pick_list $form->{PD}{pick_list}>|
1444 . $locale->text('Pick List') . qq|
1445 <option value=packing_list $form->{PD}{packing_list}>|
1446 . $locale->text('Packing List');
1449 if ($form->{type} eq 'receive_order') {
1450 $type = qq|<select name=formname>
1451 <option value=bin_list $form->{PD}{bin_list}>|
1452 . $locale->text('Bin List');
1455 if ($form->{media} eq 'email') {
1456 $media = qq|<select name=sendmode>
1457 <option value=attachment $form->{SM}{attachment}>|
1458 . $locale->text('Attachment') . qq|
1459 <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
1461 $media = qq|<select name=media>
1462 <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
1463 if (scalar(keys (%{ $form->{printers} })) !=0 && $latex_templates) {
1465 <option value=printer $form->{OP}{printer}>|
1466 . $locale->text('Printer');
1468 if ($latex_templates) {
1470 <option value=queue $form->{OP}{queue}>| . $locale->text('Queue');
1474 $format = qq|<select name=format>|;
1475 if ($opendocument_templates && $openofficeorg_writer_bin &&
1476 $xvfb_bin && (-x $openofficeorg_writer_bin) && (-x $xvfb_bin)) {
1477 $format .= qq|<option value=opendocument_pdf | .
1478 $form->{DF}{"opendocument_pdf"} . qq|>| .
1479 $locale->text("PDF (OpenDocument/OASIS)") . qq|</option>|;
1482 if ($latex_templates) {
1483 $format .= qq|<option value=pdf $form->{DF}{pdf}>| .
1484 $locale->text('PDF') . qq|</option>|;
1487 $format .= qq|<option value=html $form->{DF}{html}>HTML</option>|;
1489 if ($latex_templates) {
1490 $format .= qq|<option value=postscript $form->{DF}{postscript}>| .
1491 $locale->text('Postscript') . qq|</option>|;
1494 if ($opendocument_templates) {
1495 $format .= qq|<option value=opendocument $form->{DF}{opendocument}>| .
1496 $locale->text("OpenDocument/OASIS") . qq|</option>|;
1498 $format .= qq|</select>|;
1500 if (scalar(keys (%{ $form->{languages} })) !=0) {
1501 $language_select = qq|<select name=language_id>
1502 <option value=""></option>}|;
1503 foreach $item (@{ $form->{languages} }) {
1504 if ($form->{language_id} eq $item->{id}) {
1505 $language_select .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
1507 $language_select .= qq|<option value="$item->{id}">$item->{description}</option>|;
1512 if (scalar(keys (%{ $form->{printers} })) !=0) {
1514 $printer_select = qq|<select name=printer_id>
1515 <option value=""></option>|;
1516 foreach $item (@{ $form->{printers} }) {
1517 $printer_select .= qq|<option value="$item->{id}">$item->{printer_description}</option>|;
1524 <table width=100% cellspacing=0 cellpadding=0>
1529 <td>$type</select></td>|;
1530 if (scalar(keys (%{ $form->{languages} })) !=0) {
1532 <td>${language_select}</select></td>|;
1535 <td>$format</select></td>
1536 <td>$media</select></td>|;
1537 if (scalar(keys (%{ $form->{printers} })) !=0) {
1539 <td>$printer_select</select></td>
1543 if (scalar(keys (%{ $form->{printers} })) !=0 && $latex_templates && $form->{media} ne 'email') {
1545 <td>| . $locale->text('Copies') . qq|
1546 <input name=copies size=2 value=$form->{copies}></td>
1550 $form->{groupitems} = "checked" if $form->{groupitems};
1553 <td>| . $locale->text('Group Items') . qq|</td>
1554 <td><input name=groupitems type=checkbox class=checkbox $form->{groupitems}></td>
1563 if ($form->{printed} =~ /$form->{formname}/) {
1565 <th>\|| . $locale->text('Printed') . qq|\|</th>
1569 if ($form->{emailed} =~ /$form->{formname}/) {
1571 <th>\|| . $locale->text('E-mailed') . qq|\|</th>
1575 if ($form->{queued} =~ /$form->{formname}/) {
1577 <th>\|| . $locale->text('Queued') . qq|\|</th>
1589 $lxdebug->leave_sub();
1593 $lxdebug->enter_sub();
1595 # if this goes to the printer pass through
1596 if ($form->{media} eq 'printer' || $form->{media} eq 'queue') {
1597 $form->error($locale->text('Select postscript or PDF!'))
1598 if ($form->{format} !~ /(postscript|pdf)/);
1600 $old_form = new Form;
1601 map { $old_form->{$_} = $form->{$_} } keys %$form;
1604 if (!$form->{id} || (($form->{formname} eq "proforma") && !$form->{proforma} && (($form->{type} =~ /_order$/) || ($form->{type} =~ /_quotation$/)))) {
1605 if ($form->{formname} eq "proforma") {
1606 $form->{proforma} = 1;
1608 $form->{print_and_save} = 1;
1609 my $formname = $form->{formname};
1611 $form->{formname} = $formname;
1616 &print_form($old_form);
1618 $lxdebug->leave_sub();
1622 $lxdebug->enter_sub();
1623 my ($old_form) = @_;
1627 $numberfld = "invnumber";
1630 ($form->{display_form}) ? $form->{display_form} : "display_form";
1632 # $form->{"notes"} will be overridden by the customer's/vendor's "notes" field. So save it here.
1633 $form->{ $form->{"formname"} . "notes" } = $form->{"notes"};
1635 if ($form->{formname} eq "invoice") {
1636 $form->{label} = $locale->text('Invoice');
1638 if ($form->{formname} eq "packing_list") {
1640 # this is from an invoice
1641 $form->{label} = $locale->text('Packing List');
1643 if ($form->{formname} eq 'sales_order') {
1646 $form->{"${inv}date"} = $form->{transdate};
1647 $form->{label} = $locale->text('Sales Order');
1648 $numberfld = "sonumber";
1652 if (($form->{type} eq 'invoice') && ($form->{formname} eq 'proforma') ) {
1655 $form->{"${inv}date"} = $form->{transdate};
1656 $form->{"invdate"} = $form->{transdate};
1657 $form->{label} = $locale->text('Proforma Invoice');
1658 $numberfld = "sonumber";
1662 if (($form->{type} eq 'sales_order') && ($form->{formname} eq 'proforma') ) {
1665 $form->{"${inv}date"} = $form->{transdate};
1666 $form->{"invdate"} = $form->{transdate};
1667 $form->{invnumber} = $form->{ordnumber};
1668 $form->{label} = $locale->text('Proforma Invoice');
1669 $numberfld = "sonumber";
1673 if ($form->{formname} eq 'packing_list' && $form->{type} ne 'invoice') {
1675 # we use the same packing list as from an invoice
1678 $form->{invdate} = $form->{"${inv}date"} = $form->{transdate};
1679 $form->{label} = $locale->text('Packing List');
1681 # set invnumber for template packing_list
1682 $form->{invnumber} = $form->{ordnumber};
1684 if ($form->{formname} eq 'pick_list') {
1687 $form->{"${inv}date"} =
1688 ($form->{transdate}) ? $form->{transdate} : $form->{invdate};
1689 $form->{label} = $locale->text('Pick List');
1690 $order = 1 unless $form->{type} eq 'invoice';
1692 if ($form->{formname} eq 'purchase_order') {
1695 $form->{"${inv}date"} = $form->{transdate};
1696 $form->{label} = $locale->text('Purchase Order');
1697 $numberfld = "ponumber";
1700 if ($form->{formname} eq 'bin_list') {
1703 $form->{"${inv}date"} = $form->{transdate};
1704 $form->{label} = $locale->text('Bin List');
1707 if ($form->{formname} eq 'sales_quotation') {
1710 $form->{"${inv}date"} = $form->{transdate};
1711 $form->{label} = $locale->text('Quotation');
1712 $numberfld = "sqnumber";
1716 if (($form->{type} eq 'sales_quotation') && ($form->{formname} eq 'proforma') ) {
1719 $form->{"${inv}date"} = $form->{transdate};
1720 $form->{"invdate"} = $form->{transdate};
1721 $form->{label} = $locale->text('Proforma Invoice');
1722 $numberfld = "sqnumber";
1726 if ($form->{formname} eq 'request_quotation') {
1729 $form->{"${inv}date"} = $form->{transdate};
1730 $form->{label} = $locale->text('Quotation');
1731 $numberfld = "rfqnumber";
1735 $form->isblank("email", $locale->text('E-mail address missing!'))
1736 if ($form->{media} eq 'email');
1737 $form->isblank("${inv}date",
1738 $locale->text($form->{label} . ' Date missing!'));
1740 # $locale->text('Invoice Number missing!')
1741 # $locale->text('Invoice Date missing!')
1742 # $locale->text('Packing List Number missing!')
1743 # $locale->text('Packing List Date missing!')
1744 # $locale->text('Order Number missing!')
1745 # $locale->text('Order Date missing!')
1746 # $locale->text('Quotation Number missing!')
1747 # $locale->text('Quotation Date missing!')
1750 if (!$form->{"${inv}number"} && !$form->{preview}) {
1751 $form->{"${inv}number"} = $form->update_defaults(\%myconfig, $numberfld);
1752 if ($form->{media} ne 'email') {
1754 # get pricegroups for parts
1755 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1757 # build up html code for prices_$i
1758 set_pricegroup($form->{rowcount});
1760 $form->{rowcount}--;
1769 # Save the email address given in the form because it should override the setting saved for the customer/vendor.
1770 my ($saved_email, $saved_cc, $saved_bcc) =
1771 ($form->{"email"}, $form->{"cc"}, $form->{"bcc"});
1773 $language_saved = $form->{language_id};
1774 $payment_id_saved = $form->{payment_id};
1776 &{"$form->{vc}_details"};
1778 $form->{language_id} = $language_saved;
1779 $form->{payment_id} = $payment_id_saved;
1781 $form->{"email"} = $saved_email if ($saved_email);
1782 $form->{"cc"} = $saved_cc if ($saved_cc);
1783 $form->{"bcc"} = $saved_bcc if ($saved_bcc);
1785 my ($language_tc, $output_numberformat, $output_dateformat, $output_longdates);
1786 if ($form->{"language_id"}) {
1787 ($language_tc, $output_numberformat, $output_dateformat, $output_longdates) =
1788 AM->get_language_details(\%myconfig, $form, $form->{language_id});
1790 $output_dateformat = $myconfig{"dateformat"};
1791 $output_numberformat = $myconfig{"numberformat"};
1792 $output_longdates = 1;
1795 ($form->{employee}) = split /--/, $form->{employee};
1796 ($form->{warehouse}, $form->{warehouse_id}) = split /--/, $form->{warehouse};
1798 # create the form variables
1800 OE->order_details(\%myconfig, \%$form);
1802 IS->invoice_details(\%myconfig, \%$form, $locale);
1805 if ($form->{shipto_id}) {
1806 $form->get_shipto(\%myconfig);
1809 @a = qw(name street zipcode city country);
1813 # if there is no shipto fill it in from billto
1814 foreach $item (@a) {
1815 if ($form->{"shipto$item"}) {
1822 if ( $form->{formname} eq 'purchase_order'
1823 || $form->{formname} eq 'request_quotation') {
1824 $form->{shiptoname} = $myconfig{company};
1825 $form->{shiptostreet} = $myconfig{address};
1827 map { $form->{"shipto$_"} = $form->{$_} } @a;
1831 $form->{notes} =~ s/^\s+//g;
1833 $form->{templates} = "$myconfig{templates}";
1835 $form->{language} = $form->get_template_language(\%myconfig);
1836 $form->{printer_code} = $form->get_printer_code(\%myconfig);
1838 if ($form->{language} ne "") {
1839 map({ $form->{"unit"}->[$_] =
1840 AM->translate_units($form, $form->{"language"},
1841 $form->{"unit"}->[$_], $form->{"qty"}->[$_]); }
1842 (0..scalar(@{$form->{"unit"}}) - 1));
1843 $form->{language} = "_" . $form->{language};
1847 format_dates($output_dateformat, $output_longdates,
1848 qw(invdate orddate quodate pldate duedate reqdate transdate
1849 shippingdate deliverydate validitydate paymentdate
1850 datepaid transdate_oe deliverydate_oe
1851 employee_startdate employee_enddate
1853 grep({ /^datepaid_\d+$/ ||
1854 /^transdate_oe_\d+$/ ||
1855 /^deliverydate_oe_\d+$/ ||
1857 /^deliverydate_\d+$/ ||
1861 reformat_numbers($output_numberformat, 2,
1862 qw(invtotal ordtotal quototal subtotal linetotal
1863 listprice sellprice netprice discount
1865 grep({ /^linetotal_\d+$/ ||
1866 /^listprice_\d+$/ ||
1867 /^sellprice_\d+$/ ||
1874 reformat_numbers($output_numberformat, undef,
1879 if ($form->{printer_code} ne "") {
1880 $form->{printer_code} = "_" . $form->{printer_code};
1883 $form->{IN} = "$form->{formname}$form->{language}$form->{printer_code}.html";
1884 if ($form->{format} eq 'postscript') {
1885 $form->{postscript} = 1;
1886 $form->{IN} =~ s/html$/tex/;
1887 } elsif ($form->{"format"} =~ /pdf/) {
1889 if ($form->{"format"} =~ /opendocument/) {
1890 $form->{IN} =~ s/html$/odt/;
1892 $form->{IN} =~ s/html$/tex/;
1894 } elsif ($form->{"format"} =~ /opendocument/) {
1895 $form->{"opendocument"} = 1;
1896 $form->{"IN"} =~ s/html$/odt/;
1899 if ($form->{media} eq 'printer') {
1900 $form->{OUT} = "| $form->{printer_command} &>/dev/null";
1901 $form->{printed} .= " $form->{formname}";
1902 $form->{printed} =~ s/^ //;
1904 $printed = $form->{printed};
1906 if ($form->{media} eq 'email') {
1907 $form->{subject} = qq|$form->{label} $form->{"${inv}number"}|
1908 unless $form->{subject};
1910 $form->{OUT} = "$sendmail";
1912 $form->{emailed} .= " $form->{formname}";
1913 $form->{emailed} =~ s/^ //;
1915 $emailed = $form->{emailed};
1917 if ($form->{media} eq 'queue') {
1918 %queued = split / /, $form->{queued};
1920 if ($filename = $queued{ $form->{formname} }) {
1921 $form->{queued} =~ s/$form->{formname} $filename//;
1922 unlink "$spool/$filename";
1923 $filename =~ s/\..*$//g;
1929 $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
1930 $form->{OUT} = ">$spool/$filename";
1933 $form->{queued} .= " $form->{formname} $filename";
1935 $form->{queued} =~ s/^ //;
1937 $queued = $form->{queued};
1939 $form->parse_template(\%myconfig, $userspath);
1941 $form->{callback} = "";
1943 if ($form->{media} eq 'email') {
1944 $form->{message} = $locale->text('sent') unless $form->{message};
1946 $message = $form->{message};
1948 # if we got back here restore the previous form
1949 if ($form->{media} =~ /(printer|email|queue)/) {
1951 $form->update_status(\%myconfig)
1952 if ($form->{media} eq 'queue' && $form->{id});
1956 $old_form->{"${inv}number"} = $form->{"${inv}number"};
1958 # restore and display form
1959 map { $form->{$_} = $old_form->{$_} } keys %$old_form;
1961 $form->{queued} = $queued;
1962 $form->{printed} = $printed;
1963 $form->{emailed} = $emailed;
1964 $form->{message} = $message;
1966 $form->{rowcount}--;
1967 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1968 qw(exchangerate creditlimit creditremaining);
1970 for $i (1 .. $form->{paidaccounts}) {
1972 $form->{"${_}_$i"} =
1973 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
1974 } qw(paid exchangerate);
1982 ($form->{media} eq 'printer')
1983 ? $locale->text('sent to printer')
1984 : $locale->text('emailed to') . " $form->{email}";
1985 $form->redirect(qq|$form->{label} $form->{"${inv}number"} $msg|);
1987 if ($form->{printing}) {
1992 $lxdebug->leave_sub();
1995 sub customer_details {
1996 $lxdebug->enter_sub();
1997 IS->customer_details(\%myconfig, \%$form);
1998 $lxdebug->leave_sub();
2001 sub vendor_details {
2002 $lxdebug->enter_sub();
2004 IR->vendor_details(\%myconfig, \%$form);
2006 $lxdebug->leave_sub();
2010 $lxdebug->enter_sub();
2012 $form->{postasnew} = 1;
2013 map { delete $form->{$_} } qw(printed emailed queued);
2017 $lxdebug->leave_sub();
2021 $lxdebug->enter_sub();
2022 if ($form->{second_run}) {
2023 $form->{print_and_post} = 0;
2026 $title = $form->{title};
2027 $form->{title} = $locale->text('Ship to');
2029 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2030 qw(exchangerate creditlimit creditremaining);
2032 # get details for name
2033 &{"$form->{vc}_details"};
2036 ($form->{vc} eq 'customer')
2037 ? $locale->text('Customer Number')
2038 : $locale->text('Vendor Number');
2040 # get pricegroups for parts
2041 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
2043 # build up html code for prices_$i
2044 set_pricegroup($form->{rowcount});
2046 $nextsub = ($form->{display_form}) ? $form->{display_form} : "display_form";
2048 $form->{rowcount}--;
2055 <form method=post action=$form->{script}>
2061 <tr class=listheading>
2062 <th class=listheading colspan=2 width=50%>|
2063 . $locale->text('Billing Address') . qq|</th>
2064 <th class=listheading width=50%>|
2065 . $locale->text('Shipping Address') . qq|</th>
2067 <tr height="5"></tr>
2069 <th align=right nowrap>$number</th>
2070 <td>$form->{"$form->{vc}number"}</td>
2073 <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
2074 <td>$form->{name}</td>
2075 <td><input name=shiptoname size=35 value="$form->{shiptoname}"></td>
2078 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
2079 <td>$form->{department_1}</td>
2080 <td><input name=shiptodepartment_1 size=35 value="$form->{shiptodepartment_1}"></td>
2083 <th align=right nowrap> </th>
2084 <td>$form->{department_2}</td>
2085 <td><input name=shiptodepartment_2 size=35 value="$form->{shiptodepartment_2}"></td>
2088 <th align=right nowrap>| . $locale->text('Street') . qq|</th>
2089 <td>$form->{street}</td>
2090 <td><input name=shiptostreet size=35 value="$form->{shiptostreet}"></td>
2093 <th align=right nowrap>| . $locale->text('Zipcode') . qq|</th>
2094 <td>$form->{zipcode}</td>
2095 <td><input name=shiptozipcode size=35 value="$form->{shiptozipcode}"></td>
2098 <th align=right nowrap>| . $locale->text('City') . qq|</th>
2099 <td>$form->{city}</td>
2100 <td><input name=shiptocity size=35 value="$form->{shiptocity}"></td>
2103 <th align=right nowrap>| . $locale->text('Country') . qq|</th>
2104 <td>$form->{country}</td>
2105 <td><input name=shiptocountry size=35 value="$form->{shiptocountry}"></td>
2108 <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
2109 <td>$form->{contact}</td>
2110 <td><input name=shiptocontact size=35 value="$form->{shiptocontact}"></td>
2113 <th align=right nowrap>| . $locale->text('Phone') . qq|</th>
2114 <td>$form->{"$form->{vc}phone"}</td>
2115 <td><input name=shiptophone size=20 value="$form->{shiptophone}"></td>
2118 <th align=right nowrap>| . $locale->text('Fax') . qq|</th>
2119 <td>$form->{"$form->{vc}fax"}</td>
2120 <td><input name=shiptofax size=20 value="$form->{shiptofax}"></td>
2123 <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
2124 <td>$form->{email}</td>
2125 <td><input name=shiptoemail size=35 value="$form->{shiptoemail}"></td>
2132 <input type=hidden name=nextsub value=$nextsub>
2136 map { delete $form->{$_} }
2137 qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax shiptoemail shiptodepartment_1 shiptodepartment_2 header);
2138 $form->{title} = $title;
2140 foreach $key (keys %$form) {
2141 $form->{$key} =~ s/\"/"/g;
2142 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2150 <input class=submit type=submit name=action value="|
2151 . $locale->text('Continue') . qq|">
2158 $lxdebug->leave_sub();
2162 $lxdebug->enter_sub();
2167 $form->{old_callback} = $form->escape($form->{callback}, 1);
2168 $form->{callback} = $form->escape("$form->{script}?action=display_form", 1);
2169 $form->{old_callback} = $form->escape($form->{old_callback}, 1);
2172 delete $form->{action};
2173 $customer = $form->{customer};
2174 map { $form->{"old_$_"} = $form->{"${_}_$row"} } qw(partnumber description);
2176 # save all other form variables in a previousform variable
2177 $form->{row} = $row;
2178 foreach $key (keys %$form) {
2181 $form->{$key} =~ s/&/%26/g;
2182 $previousform .= qq|$key=$form->{$key}&|;
2185 $previousform = $form->escape($previousform, 1);
2187 $form->{script} = "licenses.pl";
2189 map { $form->{$_} = $form->{"old_$_"} } qw(partnumber description);
2190 map { $form->{$_} = $form->escape($form->{$_}, 1) }
2191 qw(partnumber description);
2193 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|;
2196 $lxdebug->leave_sub();
2199 sub relink_accounts {
2200 $lxdebug->enter_sub();
2202 $form->{"taxaccounts"} =~ s/\s*$//;
2203 $form->{"taxaccounts"} =~ s/^\s*//;
2204 foreach my $accno (split(/\s*/, $form->{"taxaccounts"})) {
2205 map({ delete($form->{"${accno}_${_}"}); } qw(rate description taxnumber));
2207 $form->{"taxaccounts"} = "";
2209 for (my $i = 1; $i <= $form->{"rowcount"}; $i++) {
2210 if ($form->{"id_$i"}) {
2211 IC->retrieve_accounts(\%myconfig, $form, $form->{"id_$i"}, $i, 1);
2215 $lxdebug->leave_sub();
2220 $lxdebug->enter_sub();
2222 $form->get_duedate(\%myconfig);
2225 $result = "$form->{duedate}";
2228 $lxdebug->leave_sub();