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 #######################################################################
38 require "$form->{path}/common.pl";
40 # any custom scripts for this one
41 if (-f "$form->{path}/custom_io.pl") {
42 eval { require "$form->{path}/custom_io.pl"; };
44 if (-f "$form->{path}/$form->{login}_io.pl") {
45 eval { require "$form->{path}/$form->{login}_io.pl"; };
52 # this is for our long dates
53 # $locale->text('January')
54 # $locale->text('February')
55 # $locale->text('March')
56 # $locale->text('April')
57 # $locale->text('May ')
58 # $locale->text('June')
59 # $locale->text('July')
60 # $locale->text('August')
61 # $locale->text('September')
62 # $locale->text('October')
63 # $locale->text('November')
64 # $locale->text('December')
66 # this is for our short month
67 # $locale->text('Jan')
68 # $locale->text('Feb')
69 # $locale->text('Mar')
70 # $locale->text('Apr')
71 # $locale->text('May')
72 # $locale->text('Jun')
73 # $locale->text('Jul')
74 # $locale->text('Aug')
75 # $locale->text('Sep')
76 # $locale->text('Oct')
77 # $locale->text('Nov')
78 # $locale->text('Dec')
83 ########################################
84 # Eintrag fuer Version 2.2.0 geaendert #
85 # neue Optik im Rechnungsformular #
86 ########################################
88 $lxdebug->enter_sub();
90 if ($lizenzen && $form->{vc} eq "customer") {
91 if ($form->{type} =~ /sales_order/) {
92 @column_index = (runningnumber, partnumber, description, ship, qty);
93 } elsif ($form->{type} =~ /sales_quotation/) {
94 @column_index = (runningnumber, partnumber, description, qty);
96 @column_index = (runningnumber, partnumber, description, qty);
99 if ( ($form->{type} =~ /purchase_order/)
100 || ($form->{type} =~ /sales_order/)) {
101 @column_index = (runningnumber, partnumber, description, ship, qty);
103 @column_index = (runningnumber, partnumber, description, qty);
106 ############## ENDE Neueintrag ##################
108 my $dimension_units = AM->retrieve_units(\%myconfig, $form, "dimension");
109 my $service_units = AM->retrieve_units(\%myconfig, $form, "service");
110 my $all_units = AM->retrieve_units(\%myconfig, $form);
112 push @column_index, qw(unit);
114 #for pricegroups column
115 if ( $form->{type} =~ (/sales_quotation/)
116 or (($form->{level} =~ /Sales/) and ($form->{type} =~ /invoice/))
117 or (($form->{level} eq undef) and ($form->{type} =~ /invoice/))
118 or ($form->{type} =~ /sales_order/)) {
119 push @column_index, qw(sellprice_pg);
122 push @column_index, qw(sellprice);
124 if ($form->{vc} eq 'customer') {
125 push @column_index, qw(discount);
128 push @column_index, "linetotal";
130 my $colspan = $#column_index + 1;
132 $form->{invsubtotal} = 0;
133 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
135 ########################################
136 # Eintrag fuer Version 2.2.0 geaendert #
137 # neue Optik im Rechnungsformular #
138 ########################################
139 $column_data{runningnumber} =
140 qq|<th align=left nowrap width=5 class=listheading>|
141 . $locale->text('No.')
143 $column_data{partnumber} =
144 qq|<th align=left nowrap width=12 class=listheading>|
145 . $locale->text('Number')
147 $column_data{description} =
148 qq|<th align=left nowrap width=30 class=listheading>|
149 . $locale->text('Part Description')
152 qq|<th align=left nowrap width=5 class=listheading>|
153 . $locale->text('Ship')
156 qq|<th align=left nowrap width=5 class=listheading>|
157 . $locale->text('Qty')
160 qq|<th align=left nowrap width=5 class=listheading>|
161 . $locale->text('Unit')
163 $column_data{license} =
164 qq|<th align=left nowrap width=10 class=listheading>|
165 . $locale->text('License')
167 $column_data{serialnr} =
168 qq|<th align=left nowrap width=10 class=listheading>|
169 . $locale->text('Serial No.')
171 $column_data{projectnr} =
172 qq|<th align=left nowrap width=10 class=listheading>|
173 . $locale->text('Project')
175 $column_data{sellprice} =
176 qq|<th align=left nowrap width=15 class=listheading>|
177 . $locale->text('Price')
179 $column_data{sellprice_pg} =
180 qq|<th align=left nowrap width=15 class=listheading>|
181 . $locale->text('Pricegroup')
183 $column_data{discount} =
184 qq|<th align=left class=listheading>|
185 . $locale->text('Discount')
187 $column_data{linetotal} =
188 qq|<th align=left nowrap width=10 class=listheading>|
189 . $locale->text('Extended')
192 qq|<th align=left nowrap width=10 class=listheading>|
193 . $locale->text('Bin')
195 ############## ENDE Neueintrag ##################
201 <tr class=listheading>|;
203 map { print "\n$column_data{$_}" } @column_index;
209 $runningnumber = $locale->text('No.');
210 $deliverydate = $locale->text('Delivery Date');
211 $serialnumber = $locale->text('Serial No.');
212 $projectnumber = $locale->text('Project');
213 $partsgroup = $locale->text('Group');
214 $reqdate = $locale->text('Reqdate');
216 $delvar = 'deliverydate';
218 if ($form->{type} =~ /_order$/ || $form->{type} =~ /_quotation$/) {
219 $deliverydate = $locale->text('Required by');
223 for $i (1 .. $numrows) {
228 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
229 } qw(qty ship discount sellprice price_new price_old) unless ($form->{simple_save});
231 if (!$form->{"unit_old_$i"}) {
232 # Neue Ware aus der Datenbank. In diesem Fall ist unit_$i die
233 # Einheit, wie sie in den Stammdaten hinterlegt wurde.
234 # Es sollte also angenommen werden, dass diese ausgewaehlt war.
235 $form->{"unit_old_$i"} = $form->{"unit_$i"};
240 # Die zuletzt ausgewaehlte mit der aktuell ausgewaehlten Einheit
241 # vergleichen und bei Unterschied den Preis entsprechend umrechnen.
242 $form->{"selected_unit_$i"} = $form->{"unit_$i"} unless ($form->{"selected_unit_$i"});
244 my $check_units = $form->{"inventory_accno_$i"} ? $dimension_units : $service_units;
245 if (!$check_units->{$form->{"selected_unit_$i"}} ||
246 ($check_units->{$form->{"selected_unit_$i"}}->{"base_unit"} ne
247 $all_units->{$form->{"unit_old_$i"}}->{"base_unit"})) {
248 # Die ausgewaehlte Einheit ist fuer diesen Artikel nicht gueltig
249 # (z.B. Dimensionseinheit war ausgewaehlt, es handelt sich aber
250 # um eine Dienstleistung). Dann keinerlei Umrechnung vornehmen.
251 $form->{"unit_old_$i"} = $form->{"selected_unit_$i"} = $form->{"unit_$i"};
253 if ((!$form->{"prices_$i"}) || ($form->{"new_pricegroup_$i"} == $form->{"old_pricegroup_$i"})) {
254 if ($form->{"unit_old_$i"} ne $form->{"selected_unit_$i"}) {
256 if (defined($all_units->{$form->{"unit_old_$i"}}->{"factor"}) &&
257 $all_units->{$form->{"unit_old_$i"}}->{"factor"}) {
258 $basefactor = $all_units->{$form->{"selected_unit_$i"}}->{"factor"} /
259 $all_units->{$form->{"unit_old_$i"}}->{"factor"};
261 $form->{"sellprice_$i"} *= $basefactor;
262 $form->{"unit_old_$i"} = $form->{"selected_unit_$i"};
265 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
267 $decimalplaces = ($dec > 2) ? $dec : 2;
271 $form->{"sellprice_$i"} * $form->{"discount_$i"} / 100,
275 $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
276 $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
278 # convert " to "
279 map { $form->{"${_}_$i"} =~ s/\"/"/g }
280 qw(partnumber description unit unit_old);
282 ########################################
283 # Eintrag fuer Version 2.2.0 geaendert #
284 # neue Optik im Rechnungsformular #
285 ########################################
286 $column_data{runningnumber} =
287 qq|<td><input name="runningnumber_$i" size=5 value=$i></td>|; # HuT
288 ############## ENDE Neueintrag ##################
290 $column_data{partnumber} =
291 qq|<td><input name="partnumber_$i" size=12 value="$form->{"partnumber_$i"}"></td>|;
293 if (($rows = $form->numtextrows($form->{"description_$i"}, 30, 6)) > 1) {
294 $column_data{description} =
295 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>|;
297 $column_data{description} =
298 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>|;
301 (my $qty_dec) = ($form->{"qty_$i"} =~ /\.(\d+)/);
302 $qty_dec = length $qty_dec;
305 qq|<td align=right><input name="qty_$i" size=5 value=|
306 . $form->format_amount(\%myconfig, $form->{"qty_$i"}, $qty_dec) .qq|>|;
307 if ($form->{"formel_$i"}) {
308 $column_data{qty} .= qq|<button type="button" onclick="calculate_qty_selection_window('qty_$i','alu_$i', 'formel_$i', $i)">| . $locale->text('*/') . qq|</button>
309 <input type=hidden name="formel_$i" value="$form->{"formel_$i"}"><input type=hidden name="alu_$i" value="$form->{"alu_$i"}"></td>|;
312 qq|<td align=right><input name="ship_$i" size=5 value=|
313 . $form->format_amount(\%myconfig, $form->{"ship_$i"})
316 my $is_part = $form->{"inventory_accno_$i"};
317 my $is_assigned = $form->{"id_$i"};
318 my $this_unit = $form->{"unit_$i"};
319 if ($form->{"selected_unit_$i"} && $this_unit &&
320 $all_units->{$form->{"selected_unit_$i"}} && $all_units->{$this_unit} &&
321 ($all_units->{$form->{"selected_unit_$i"}}->{"base_unit"} eq $all_units->{$this_unit}->{"base_unit"})) {
322 $this_unit = $form->{"selected_unit_$i"};
323 } elsif (!$is_assigned ||
324 ($is_part && !$this_unit && ($all_units->{$this_unit} && ($all_units->{$this_unit}->{"base_unit"} eq $all_units->{"kg"}->{"base_unit"})))) {
328 $column_data{"unit"} = "<td>" .
329 ($qty_readonly ? " " :
330 AM->unit_select_html($is_part ? $dimension_units :
331 $is_assigned ? $service_units : $all_units,
332 "unit_$i", $this_unit,
333 $is_assigned ? $form->{"unit_$i"} : undef))
336 # build in drop down list for pricesgroups
337 if ($form->{"prices_$i"}) {
338 if ($form->{"new_pricegroup_$i"} != $form->{"old_pricegroup_$i"}) {
339 $price_tmp = $form->format_amount(\%myconfig, $form->{"price_new_$i"}, $decimalplaces);
341 $price_tmp = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
344 $column_data{sellprice_pg} =
345 qq|<td align=right><select name="sellprice_pg_$i">$form->{"prices_$i"}</select></td>|;
346 $column_data{sellprice} =
347 qq|<td><input name="sellprice_$i" size=10 value=$price_tmp></td>|;
350 # for last row and report
351 # set pricegroup drop down list from report menu
352 if ($form->{"sellprice_$i"} != 0) {
354 qq|<option value="$form->{"sellprice_$i"}--$form->{"pricegroup_id_$i"}" selected>$form->{"pricegroup_$i"}</option>\n|;
356 $form->{"pricegroup_old_$i"} = $form->{"pricegroup_id_$i"};
358 $column_data{sellprice_pg} =
359 qq|<td align=right><select name="sellprice_pg_$i">$prices</select></td>|;
364 $column_data{sellprice_pg} = qq|<td align=right> </td>|;
367 $column_data{sellprice} =
368 qq|<td><input name="sellprice_$i" size=10 value=|
369 . $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
373 $column_data{discount} =
374 qq|<td align=right><input name="discount_$i" size=3 value=|
375 . $form->format_amount(\%myconfig, $form->{"discount_$i"})
377 $column_data{linetotal} =
379 . $form->format_amount(\%myconfig, $linetotal, 2)
381 $column_data{bin} = qq|<td>$form->{"bin_$i"}</td>|;
383 ########################################
384 # Eintrag fuer Version 2.2.0 geaendert #
385 # neue Optik im Rechnungsformular #
386 ########################################
387 # if ($lizenzen && $form->{type} eq "invoice" && $form->{vc} eq "customer") {
388 # $column_data{license} = qq|<td><select name="licensenumber_$i">$form->{"lizenzen_$i"}></select></td>|;
391 # if ($form->{type} !~ /_quotation/) {
392 # $column_data{serialnr} = qq|<td><input name="serialnumber_$i" size=10 value="$form->{"serialnumber_$i"}"></td>|;
395 # $column_data{projectnr} = qq|<td><input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}"></td>|;
396 ############## ENDE Neueintrag ##################
400 <tr valign=top class=listrow$j>|;
402 map { print "\n$column_data{$_}" } @column_index;
407 <input type=hidden name="orderitems_id_$i" value=$form->{"orderitems_id_$i"}>
408 <input type=hidden name="bo_$i" value=$form->{"bo_$i"}>
410 <input type=hidden name="pricegroup_old_$i" value=$form->{"pricegroup_old_$i"}>
411 <input type=hidden name="price_old_$i" value=$form->{"price_old_$i"}>
412 <input type=hidden name="unit_old_$i" value="$form->{"selected_unit_$i"}">
413 <input type=hidden name="price_new_$i" value=|
414 . $form->format_amount(\%myconfig, $form->{"price_new_$i"}) . qq|>
416 <input type=hidden name="id_$i" value=$form->{"id_$i"}>
417 <input type=hidden name="inventory_accno_$i" value=$form->{"inventory_accno_$i"}>
418 <input type=hidden name="bin_$i" value="$form->{"bin_$i"}">
419 <input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">
420 <input type=hidden name="partnotes_$i" value="$form->{"partnotes_$i"}">
421 <input type=hidden name="income_accno_$i" value=$form->{"income_accno_$i"}>
422 <input type=hidden name="expense_accno_$i" value=$form->{"expense_accno_$i"}>
423 <input type=hidden name="listprice_$i" value="$form->{"listprice_$i"}">
424 <input type=hidden name="assembly_$i" value="$form->{"assembly_$i"}">
425 <input type=hidden name="taxaccounts_$i" value="$form->{"taxaccounts_$i"}">
426 <input type=hidden name="ordnumber_$i" value="$form->{"ordnumber_$i"}">
427 <input type=hidden name="transdate_$i" value="$form->{"transdate_$i"}">
428 <input type=hidden name="cusordnumber_$i" value="$form->{"cusordnumber_$i"}">
429 <input type=hidden name="longdescription_$i" value="$form->{"longdescription_$i"}">
430 <input type=hidden name="basefactor_$i" value="$form->{"basefactor_$i"}">
434 ########################################
435 # Eintrag fuer Version 2.2.0 geaendert #
436 # neue Optik im Rechnungsformular #
437 ########################################
441 <td colspan=$colspan>
443 if ($lizenzen && $form->{type} eq "invoice" && $form->{vc} eq "customer") {
444 my $selected = $form->{"licensenumber_$i"};
446 $form->{"lizenzen_$i"} =~ s/ selected//g;
447 $form->{"lizenzen_$i"} =~
448 s/value="${selected}"\>/value="${selected}" selected\>/;
449 $lizenzen_quoted = $form->{"lizenzen_$i"};
450 $lizenzen_quoted =~ s/\"/"/g;
452 <b>Lizenz\#</b> <select name="licensenumber_$i" size=1>
453 $form->{"lizenzen_$i"}
455 <input type=hidden name="lizenzen_$i" value="${lizenzen_quoted}">
458 if ($form->{type} !~ /_quotation/) {
460 <b>$serialnumber</b> <input name="serialnumber_$i" size=15 value="$form->{"serialnumber_$i"}">|;
464 <b>$projectnumber</b> <input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}">
465 <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}">
466 <input type=hidden name="project_id_$i" value="$form->{"project_id_$i"}">
468 if ($form->{type} eq 'invoice' or $form->{type} =~ /order/) {
470 ($form->{type} eq 'invoice')
472 : 'reqdate'; # invoice uses a different term for the same thing.
474 <b>${$reqdate_term}</b> <input name="${reqdate_term}_$i" size=11 value="$form->{"${reqdate_term}_$i"}">
477 my $subtotalchecked = ($form->{"subtotal_$i"}) ? "checked" : "";
479 <b>|.$locale->text('Subtotal').qq|</b> <input type="checkbox" name="subtotal_$i" value="1" "$subtotalchecked">
485 ############## ENDE Neueintrag ##################
487 map { $form->{"${_}_base"} += $linetotal }
488 (split / /, $form->{"taxaccounts_$i"});
490 $form->{invsubtotal} += $linetotal;
499 $lxdebug->leave_sub();
502 ##################################################
503 # build html-code for pricegroups in variable $form->{prices_$j}
506 $lxdebug->enter_sub();
507 my $rowcount = shift;
508 for $j (1 .. $rowcount) {
509 my $pricegroup_old = $form->{"pricegroup_old_$i"};
510 if ($form->{PRICES}{$j}) {
512 $prices = '<option value="--">' . $locale->text("none (pricegroup)") . '</option>';
514 foreach $item (@{ $form->{PRICES}{$j} }) {
516 #$price = $form->round_amount($myconfig, $item->{price}, 5);
517 #$price = $form->format_amount($myconfig, $item->{price}, 2);
518 $price = $item->{price};
519 $pricegroup_id = $item->{pricegroup_id};
520 $pricegroup = $item->{pricegroup};
522 # build drop down list for pricegroups
524 qq|<option value="$price--$pricegroup_id"$item->{selected}>$pricegroup</option>\n|;
529 # $form->{"${_}_$j"} =
530 # $form->format_amount(\%myconfig, $form->{"${_}_$j"})
531 # } qw(sellprice price_new price_old);
533 # set new selectedpricegroup_id and prices for "Preis"
534 if ($item->{selected} && ($pricegroup_id != 0)) {
535 $form->{"pricegroup_old_$j"} = $pricegroup_id;
536 $form->{"price_new_$j"} = $price;
537 $form->{"sellprice_$j"} = $price;
539 if ($pricegroup_id == 0) {
540 $form->{"price_new_$j"} = $form->{"sellprice_$j"};
543 $form->{"prices_$j"} = $prices;
546 $lxdebug->leave_sub();
550 $lxdebug->enter_sub();
551 @column_index = qw(ndx partnumber description onhand sellprice);
553 $column_data{ndx} = qq|<th> </th>|;
554 $column_data{partnumber} =
555 qq|<th class=listheading>| . $locale->text('Number') . qq|</th>|;
556 $column_data{description} =
557 qq|<th class=listheading>| . $locale->text('Part Description') . qq|</th>|;
558 $column_data{sellprice} =
559 qq|<th class=listheading>| . $locale->text('Price') . qq|</th>|;
560 $column_data{onhand} =
561 qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|;
563 # list items with radio button on a form
566 $title = $locale->text('Select from one of the items below');
567 $colspan = $#column_index + 1;
572 <form method=post action=$form->{script}>
576 <th class=listtop colspan=$colspan>$title</th>
579 <tr class=listheading>|;
581 map { print "\n$column_data{$_}" } @column_index;
586 foreach $ref (@{ $form->{item_list} }) {
587 $checked = ($i++) ? "" : "checked";
590 if ($ref->{inventory_accno} > 0) {
591 $ref->{"lizenzen"} = qq|<option></option>|;
592 foreach $item (@{ $form->{LIZENZEN}{ $ref->{"id"} } }) {
593 $ref->{"lizenzen"} .=
594 qq|<option value=\"$item->{"id"}\">$item->{"licensenumber"}</option>|;
596 $ref->{"lizenzen"} .= qq|<option value=-1>Neue Lizenz</option>|;
597 $ref->{"lizenzen"} =~ s/\"/"/g;
601 map { $ref->{$_} =~ s/\"/"/g } qw(partnumber description unit);
605 $form->round_amount($ref->{sellprice} * (1 - $form->{tradediscount}), 2);
607 qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
608 $column_data{partnumber} =
609 qq|<td><input name="new_partnumber_$i" type=hidden value="$ref->{partnumber}">$ref->{partnumber}</td>|;
610 $column_data{description} =
611 qq|<td><input name="new_description_$i" type=hidden value="$ref->{description}">$ref->{description}</td>|;
612 $column_data{sellprice} =
613 qq|<td align=right><input name="new_sellprice_$i" type=hidden value=$ref->{sellprice}>|
614 . $form->format_amount(\%myconfig, $ref->{sellprice}, 2, " ")
616 $column_data{onhand} =
617 qq|<td align=right><input name="new_onhand_$i" type=hidden value=$ref->{onhand}>|
618 . $form->format_amount(\%myconfig, $ref->{onhand}, '', " ")
624 <tr class=listrow$j>|;
626 map { print "\n$column_data{$_}" } @column_index;
631 <input name="new_bin_$i" type=hidden value="$ref->{bin}">
632 <input name="new_listprice_$i" type=hidden value=$ref->{listprice}>
633 <input name="new_inventory_accno_$i" type=hidden value=$ref->{inventory_accno}>
634 <input name="new_income_accno_$i" type=hidden value=$ref->{income_accno}>
635 <input name="new_expense_accno_$i" type=hidden value=$ref->{expense_accno}>
636 <input name="new_unit_$i" type=hidden value="$ref->{unit}">
637 <input name="new_weight_$i" type=hidden value="$ref->{weight}">
638 <input name="new_assembly_$i" type=hidden value="$ref->{assembly}">
639 <input name="new_taxaccounts_$i" type=hidden value="$ref->{taxaccounts}">
640 <input name="new_partsgroup_$i" type=hidden value="$ref->{partsgroup}">
641 <input name="new_formel_$i" type=hidden value="$ref->{formel}">
642 <input name="new_longdescription_$i" type=hidden value="$ref->{longdescription}">
643 <input name="new_not_discountable_$i" type=hidden value="$ref->{not_discountable}">
644 <input name="new_part_payment_id_$i" type=hidden value="$ref->{part_payment_id}">
646 <input name="new_id_$i" type=hidden value=$ref->{id}>
651 <input name="new_lizenzen_$i" type=hidden value="$ref->{lizenzen}">
658 <tr><td colspan=8><hr size=3 noshade></td></tr>
661 <input name=lastndx type=hidden value=$i>
665 # delete action variable
666 map { delete $form->{$_} } qw(action item_list header);
668 # save all other form variables
669 foreach $key (keys %${form}) {
670 $form->{$key} =~ s/\"/"/g;
671 print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
675 <input type=hidden name=nextsub value=item_selected>
678 <input class=submit type=submit name=action value="|
679 . $locale->text('Continue') . qq|">
686 $lxdebug->leave_sub();
690 $lxdebug->enter_sub();
692 # replace the last row with the checked row
693 $i = $form->{rowcount};
694 $i = $form->{assembly_rows} if ($form->{item} eq 'assembly');
700 #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
701 #$form->{"sellprice_$i"} = $form->{"sellprice_$i"};
703 # if there was a price entered, override it
704 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
706 map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} }
707 qw(id partnumber description sellprice listprice inventory_accno income_accno expense_accno bin unit weight assembly taxaccounts partsgroup formel longdescription not_discountable);
708 if ($form->{"part_payment_id_$i"} ne "") {
709 $form->{payment_id} = $form->{"part_payment_id_$i"};
713 map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} } qw(lizenzen);
716 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
718 $decimalplaces = ($dec > 2) ? $dec : 2;
721 $form->{"sellprice_$i"} = $sellprice;
724 # if there is an exchange rate adjust sellprice
725 if (($form->{exchangerate} * 1) != 0) {
726 $form->{"sellprice_$i"} /= $form->{exchangerate};
727 $form->{"sellprice_$i"} =
728 $form->round_amount($form->{"sellprice_$i"}, $decimalplaces);
732 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
733 qw(sellprice listprice weight);
735 $form->{sellprice} += ($form->{"sellprice_$i"} * $form->{"qty_$i"});
736 $form->{weight} += ($form->{"weight_$i"} * $form->{"qty_$i"});
738 if ($form->{"not_discountable_$i"}) {
739 $form->{"discount_$i"} = 0;
743 $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) *
745 map { $form->{"${_}_base"} += $amount }
746 (split / /, $form->{"taxaccounts_$i"});
747 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /,
748 $form->{"taxaccounts_$i"}
749 if !$form->{taxincluded};
751 $form->{creditremaining} -= $amount;
753 $form->{"runningnumber_$i"} = $i;
755 # delete all the new_ variables
756 for $i (1 .. $form->{lastndx}) {
757 map { delete $form->{"new_${_}_$i"} }
758 qw(partnumber description sellprice bin listprice inventory_accno income_accno expense_accno unit assembly taxaccounts id);
761 map { delete $form->{$_} } qw(ndx lastndx nextsub);
766 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces)
767 } qw(sellprice listprice) if $form->{item} ne 'assembly';
769 # get pricegroups for parts
770 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
772 # build up html code for prices_$i
773 set_pricegroup($form->{rowcount});
777 $lxdebug->leave_sub();
781 $lxdebug->enter_sub();
784 $form->{old_callback} = $form->escape($form->{callback}, 1);
785 $form->{callback} = $form->escape("$form->{script}?action=display_form", 1);
788 delete $form->{action};
790 # save all other form variables in a previousform variable
791 foreach $key (keys %$form) {
794 $form->{$key} =~ s/&/%26/g;
795 $previousform .= qq|$key=$form->{$key}&|;
798 $previousform = $form->escape($previousform, 1);
800 $i = $form->{rowcount};
801 map { $form->{"${_}_$i"} =~ s/\"/"/g } qw(partnumber description);
808 <h4 class=error>| . $locale->text('Item not on file!') . qq|
811 | . $locale->text('What type of item is this?') . qq|</h4>
813 <form method=post action=ic.pl>
817 <input class=radio type=radio name=item value=part checked> |
818 . $locale->text('Part') . qq|<br>
819 <input class=radio type=radio name=item value=service> |
820 . $locale->text('Service')
823 <input type=hidden name=previousform value="$previousform">
824 <input type=hidden name=partnumber value="$form->{"partnumber_$i"}">
825 <input type=hidden name=description value="$form->{"description_$i"}">
826 <input type=hidden name=rowcount value=$form->{rowcount}>
827 <input type=hidden name=taxaccount2 value=$form->{taxaccounts}>
828 <input type=hidden name=vc value=$form->{vc}>
830 <input type=hidden name=path value=$form->{path}>
831 <input type=hidden name=login value=$form->{login}>
832 <input type=hidden name=password value=$form->{password}>
834 <input type=hidden name=nextsub value=add>
837 <input class=submit type=submit name=action value="|
838 . $locale->text('Continue') . qq|">
845 $lxdebug->leave_sub();
849 $lxdebug->enter_sub();
853 $form->language_payment(\%myconfig);
855 # if we have a display_form
856 if ($form->{display_form}) {
857 &{"$form->{display_form}"};
861 # if ( $form->{print_and_post}
862 # && $form->{second_run}
863 # && ($form->{action} eq "display_form")) {
864 # for (keys %$form) { $old_form->{$_} = $form->{$_} }
865 # $old_form->{rowcount}++;
867 # #$form->{rowcount}--;
868 # #$form->{rowcount}--;
870 # $form->{print_and_post} = 0;
872 # &print_form($old_form);
876 # $form->{action} = "";
877 # $form->{resubmit} = 0;
879 # if ($form->{print_and_post} && !$form->{second_run}) {
880 # $form->{second_run} = 1;
881 # $form->{action} = "display_form";
882 # $form->{rowcount}--;
883 # my $rowcount = $form->{rowcount};
885 # # get pricegroups for parts
886 # IS->get_pricegroups_for_parts(\%myconfig, \%$form);
888 # # build up html code for prices_$i
889 # set_pricegroup($rowcount);
891 # $form->{resubmit} = 1;
896 $numrows = ++$form->{rowcount};
897 $subroutine = "display_row";
899 if ($form->{item} eq 'part') {
901 #set preisgruppenanzahl
902 $numrows = $form->{price_rows};
903 $subroutine = "price_row";
905 &{$subroutine}($numrows);
907 $numrows = ++$form->{makemodel_rows};
908 $subroutine = "makemodel_row";
910 if ($form->{item} eq 'assembly') {
911 $numrows = $form->{price_rows};
912 $subroutine = "price_row";
914 &{$subroutine}($numrows);
916 $numrows = ++$form->{makemodel_rows};
917 $subroutine = "makemodel_row";
919 # create makemodel rows
920 &{$subroutine}($numrows);
922 $numrows = ++$form->{assembly_rows};
923 $subroutine = "assembly_row";
925 if ($form->{item} eq 'service') {
926 $numrows = $form->{price_rows};
927 $subroutine = "price_row";
929 &{$subroutine}($numrows);
935 &{$subroutine}($numrows) if $numrows;
939 $lxdebug->leave_sub();
943 $lxdebug->enter_sub();
947 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)
951 # remove any makes or model rows
952 if ($form->{item} eq 'part') {
953 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
954 qw(listprice sellprice lastcost weight rop);
956 @flds = (make, model);
957 for my $i (1 .. ($form->{makemodel_rows})) {
958 if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
962 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
967 $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
968 $form->{makemodel_rows} = $count;
970 } elsif ($form->{item} eq 'assembly') {
972 $form->{sellprice} = 0;
974 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
975 qw(listprice rop stock);
978 qw(id qty unit bom partnumber description sellprice weight runningnumber partsgroup);
980 for my $i (1 .. ($form->{assembly_rows} - 1)) {
981 if ($form->{"qty_$i"}) {
985 $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
987 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
989 #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
991 $form->{sellprice} += ($form->{"qty_$i"} * $form->{"sellprice_$i"});
992 $form->{weight} += ($form->{"qty_$i"} * $form->{"weight_$i"});
997 $form->{sellprice} = $form->round_amount($form->{sellprice}, 2);
999 $form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows});
1000 $form->{assembly_rows} = $count;
1003 @flds = qw(make model);
1006 for my $i (1 .. ($form->{makemodel_rows})) {
1007 if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
1011 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1016 $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
1017 $form->{makemodel_rows} = $count;
1021 # this section applies to invoices and orders
1022 # remove any empty numbers
1023 if ($form->{rowcount}) {
1024 for my $i (1 .. $form->{rowcount} - 1) {
1025 if ($form->{"partnumber_$i"}) {
1029 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1032 if ($form->{"licensenumber_$i"} == -1) {
1040 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
1041 $form->{rowcount} = $count;
1043 $form->{creditremaining} -= &invoicetotal;
1050 if ( $form->{type} =~ (/sales_quotation/)
1051 or (($form->{level} =~ /Sales/) and ($form->{type} =~ /invoice/))
1052 or (($form->{level} eq undef) and ($form->{type} =~ /invoice/))
1053 or ($form->{type} =~ /sales_order/)) {
1055 # get pricegroups for parts
1056 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1058 # build up html code for prices_$i
1059 set_pricegroup($form->{rowcount});
1065 $lxdebug->leave_sub();
1069 $lxdebug->enter_sub();
1071 $form->{oldinvtotal} = 0;
1073 # add all parts and deduct paid
1074 map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
1076 my ($amount, $sellprice, $discount, $qty);
1078 for my $i (1 .. $form->{rowcount}) {
1079 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1080 $discount = $form->parse_amount(\%myconfig, $form->{"discount_$i"});
1081 $qty = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
1083 #($form->{"sellprice_$i"}, $form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
1085 $amount = $sellprice * (1 - $discount / 100) * $qty;
1086 map { $form->{"${_}_base"} += $amount }
1087 (split / /, $form->{"taxaccounts_$i"});
1088 $form->{oldinvtotal} += $amount;
1091 map { $form->{oldinvtotal} += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1092 split / /, $form->{taxaccounts}
1093 if !$form->{taxincluded};
1095 $form->{oldtotalpaid} = 0;
1096 for $i (1 .. $form->{paidaccounts}) {
1097 $form->{oldtotalpaid} += $form->{"paid_$i"};
1100 $lxdebug->leave_sub();
1103 return ($form->{oldinvtotal} - $form->{oldtotalpaid});
1106 sub validate_items {
1107 $lxdebug->enter_sub();
1109 # check if items are valid
1110 if ($form->{rowcount} == 1) {
1115 for $i (1 .. $form->{rowcount} - 1) {
1116 $form->isblank("partnumber_$i",
1117 $locale->text('Number missing in Row') . " $i");
1120 $lxdebug->leave_sub();
1124 $lxdebug->enter_sub();
1125 if ($form->{second_run}) {
1126 $form->{print_and_post} = 0;
1128 $form->{ordnumber} = $form->{invnumber};
1130 map { delete $form->{$_} } qw(id printed emailed queued);
1131 if ($form->{script} eq 'ir.pl' || $form->{type} eq 'request_quotation') {
1132 $form->{title} = $locale->text('Add Purchase Order');
1133 $form->{vc} = 'vendor';
1134 $form->{type} = 'purchase_order';
1137 if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_quotation') {
1138 $form->{title} = $locale->text('Add Sales Order');
1139 $form->{vc} = 'customer';
1140 $form->{type} = 'sales_order';
1143 $form->{script} = 'oe.pl';
1145 $form->{shipto} = 1;
1147 $form->{rowcount}--;
1149 $form->{cp_id} *= 1;
1151 require "$form->{path}/$form->{script}";
1153 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1155 $currency = $form->{currency};
1159 $form->{currency} = $currency;
1160 $form->{exchangerate} = "";
1161 $form->{forex} = "";
1162 $form->{exchangerate} = $exchangerate
1166 $form->check_exchangerate(
1167 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1173 $lxdebug->leave_sub();
1177 $lxdebug->enter_sub();
1178 if ($form->{second_run}) {
1179 $form->{print_and_post} = 0;
1181 map { delete $form->{$_} } qw(id printed emailed queued);
1183 if ($form->{script} eq 'ir.pl' || $form->{type} eq 'purchase_order') {
1184 $form->{title} = $locale->text('Add Request for Quotation');
1185 $form->{vc} = 'vendor';
1186 $form->{type} = 'request_quotation';
1189 if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_order') {
1190 $form->{title} = $locale->text('Add Quotation');
1191 $form->{vc} = 'customer';
1192 $form->{type} = 'sales_quotation';
1196 $form->{cp_id} *= 1;
1198 $form->{script} = 'oe.pl';
1200 $form->{shipto} = 1;
1202 $form->{rowcount}--;
1204 require "$form->{path}/$form->{script}";
1206 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1208 $currency = $form->{currency};
1212 $form->{currency} = $currency;
1213 $form->{exchangerate} = "";
1214 $form->{forex} = "";
1215 $form->{exchangerate} = $exchangerate
1219 $form->check_exchangerate(
1220 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1226 $lxdebug->leave_sub();
1229 sub request_for_quotation {
1234 $lxdebug->enter_sub();
1235 if ($form->{second_run}) {
1236 $form->{print_and_post} = 0;
1237 $form->{resubmit} = 0;
1239 if ($myconfig{role} eq 'admin') {
1241 <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
1242 <td><input name=bcc size=30 value="$form->{bcc}"></td>
1246 if ($form->{formname} =~ /(pick|packing|bin)_list/) {
1247 $form->{email} = $form->{shiptoemail} if $form->{shiptoemail};
1250 $name = $form->{ $form->{vc} };
1252 $title = $locale->text('E-mail') . " $name";
1254 $form->{oldmedia} = $form->{media};
1255 $form->{media} = "email";
1262 <form method=post action=$form->{script}>
1266 <th class=listtop>$title</th>
1268 <tr height="5"></tr>
1273 <th align=right nowrap>| . $locale->text('To') . qq|</th>
1274 <td><input name=email size=30 value="$form->{email}"></td>
1275 <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
1276 <td><input name=cc size=30 value="$form->{cc}"></td>
1279 <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
1280 <td><input name=subject size=30 value="$form->{subject}"></td>
1290 <th align=left nowrap>| . $locale->text('Message') . qq|</th>
1293 <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
1304 map { delete $form->{$_} }
1305 qw(action email cc bcc subject message formname sendmode format header override);
1307 # save all other variables
1308 foreach $key (keys %$form) {
1309 $form->{$key} =~ s/\"/"/g;
1310 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1317 <td><hr size=3 noshade></td>
1321 <input type=hidden name=nextsub value=send_email>
1324 <input name=action class=submit type=submit value="|
1325 . $locale->text('Continue') . qq|">
1332 $lxdebug->leave_sub();
1336 $lxdebug->enter_sub();
1338 $old_form = new Form;
1340 map { $old_form->{$_} = $form->{$_} } keys %$form;
1341 $old_form->{media} = $form->{oldmedia};
1343 &print_form($old_form);
1345 $lxdebug->leave_sub();
1349 $lxdebug->enter_sub();
1350 $form->{sendmode} = "attachment";
1351 $form->{copies} = 3 unless $form->{copies};
1353 $form->{PD}{ $form->{formname} } = "selected";
1354 $form->{DF}{ $form->{format} } = "selected";
1355 $form->{OP}{ $form->{media} } = "selected";
1356 $form->{SM}{ $form->{sendmode} } = "selected";
1358 if ($form->{type} eq 'purchase_order') {
1359 $type = qq|<select name=formname>
1360 <option value=purchase_order $form->{PD}{purchase_order}>|
1361 . $locale->text('Purchase Order') . qq|
1362 <option value=bin_list $form->{PD}{bin_list}>|
1363 . $locale->text('Bin List');
1366 if ($form->{type} eq 'credit_note') {
1367 $type = qq|<select name=formname>
1368 <option value=credit_note $form->{PD}{credit_note}>|
1369 . $locale->text('Credit Note');
1372 if ($form->{type} eq 'sales_order') {
1373 $type = qq|<select name=formname>
1374 <option value=sales_order $form->{PD}{sales_order}>|
1375 . $locale->text('Confirmation') . qq|
1376 <option value=proforma $form->{PD}{proforma}>|
1377 . $locale->text('Proforma Invoice') . qq|
1378 <option value=pick_list $form->{PD}{pick_list}>|
1379 . $locale->text('Pick List') . qq|
1380 <option value=packing_list $form->{PD}{packing_list}>|
1381 . $locale->text('Packing List');
1384 if ($form->{type} =~ /_quotation$/) {
1385 $type = qq|<select name=formname>
1386 <option value="$`_quotation" $form->{PD}{"$`_quotation"}>|
1387 . $locale->text('Quotation');
1390 if ($form->{type} eq 'invoice') {
1391 $type = qq|<select name=formname>
1392 <option value=invoice $form->{PD}{invoice}>|
1393 . $locale->text('Invoice') . qq|
1394 <option value=proforma $form->{PD}{proforma}>|
1395 . $locale->text('Proforma Invoice') . qq|
1396 <option value=packing_list $form->{PD}{packing_list}>|
1397 . $locale->text('Packing List');
1400 if ($form->{type} eq 'invoice' && $form->{storno}) {
1401 $type = qq|<select name=formname>
1402 <option value=storno_invoice $form->{PD}{storno_invoice}>|
1403 . $locale->text('Storno Invoice') . qq|
1404 <option value=storno_packing_list $form->{PD}{storno_packing_list}>|
1405 . $locale->text('Storno Packing List');
1408 if ($form->{type} eq 'credit_note') {
1409 $type = qq|<select name=formname>
1410 <option value=credit_note $form->{PD}{credit_note}>|
1411 . $locale->text('Credit Note');
1414 if ($form->{type} eq 'ship_order') {
1415 $type = qq|<select name=formname>
1416 <option value=pick_list $form->{PD}{pick_list}>|
1417 . $locale->text('Pick List') . qq|
1418 <option value=packing_list $form->{PD}{packing_list}>|
1419 . $locale->text('Packing List');
1422 if ($form->{type} eq 'receive_order') {
1423 $type = qq|<select name=formname>
1424 <option value=bin_list $form->{PD}{bin_list}>|
1425 . $locale->text('Bin List');
1428 if ($form->{media} eq 'email') {
1429 $media = qq|<select name=sendmode>
1430 <option value=attachment $form->{SM}{attachment}>|
1431 . $locale->text('Attachment') . qq|
1432 <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
1434 $media = qq|<select name=media>
1435 <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
1436 if (scalar(keys (%{ $form->{printers} })) !=0 && $latex_templates) {
1438 <option value=printer $form->{OP}{printer}>|
1439 . $locale->text('Printer');
1441 if ($latex_templates) {
1443 <option value=queue $form->{OP}{queue}>| . $locale->text('Queue');
1447 $format = qq|<select name=format>|;
1448 if ($opendocument_templates && $openofficeorg_writer_bin &&
1449 $xvfb_bin && (-x $openofficeorg_writer_bin) && (-x $xvfb_bin)) {
1450 $format .= qq|<option value=opendocument_pdf | .
1451 $form->{DF}{"opendocument_pdf"} . qq|>| .
1452 $locale->text("PDF (OpenDocument/OASIS)") . qq|</option>|;
1455 if ($latex_templates) {
1456 $format .= qq|<option value=pdf $form->{DF}{pdf}>| .
1457 $locale->text('PDF') . qq|</option>|;
1460 $format .= qq|<option value=html $form->{DF}{html}>HTML</option>|;
1462 if ($latex_templates) {
1463 $format .= qq|<option value=postscript $form->{DF}{postscript}>| .
1464 $locale->text('Postscript') . qq|</option>|;
1467 if ($opendocument_templates) {
1468 $format .= qq|<option value=opendocument $form->{DF}{opendocument}>| .
1469 $locale->text("OpenDocument/OASIS") . qq|</option>|;
1471 $format .= qq|</select>|;
1473 if (scalar(keys (%{ $form->{languages} })) !=0) {
1474 $language_select = qq|<select name=language_id>
1475 <option value=""></option>}|;
1476 foreach $item (@{ $form->{languages} }) {
1477 if ($form->{language_id} eq $item->{id}) {
1478 $language_select .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
1480 $language_select .= qq|<option value="$item->{id}">$item->{description}</option>|;
1485 if (scalar(keys (%{ $form->{printers} })) !=0) {
1487 $printer_select = qq|<select name=printer_id>
1488 <option value=""></option>|;
1489 foreach $item (@{ $form->{printers} }) {
1490 $printer_select .= qq|<option value="$item->{id}">$item->{printer_description}</option>|;
1497 <table width=100% cellspacing=0 cellpadding=0>
1502 <td>$type</select></td>|;
1503 if (scalar(keys (%{ $form->{languages} })) !=0) {
1505 <td>${language_select}</select></td>|;
1508 <td>$format</select></td>
1509 <td>$media</select></td>|;
1510 if (scalar(keys (%{ $form->{printers} })) !=0) {
1512 <td>$printer_select</select></td>
1516 if (scalar(keys (%{ $form->{printers} })) !=0 && $latex_templates && $form->{media} ne 'email') {
1518 <td>| . $locale->text('Copies') . qq|
1519 <input name=copies size=2 value=$form->{copies}></td>
1523 $form->{groupitems} = "checked" if $form->{groupitems};
1526 <td>| . $locale->text('Group Items') . qq|</td>
1527 <td><input name=groupitems type=checkbox class=checkbox $form->{groupitems}></td>
1536 if ($form->{printed} =~ /$form->{formname}/) {
1538 <th>\|| . $locale->text('Printed') . qq|\|</th>
1542 if ($form->{emailed} =~ /$form->{formname}/) {
1544 <th>\|| . $locale->text('E-mailed') . qq|\|</th>
1548 if ($form->{queued} =~ /$form->{formname}/) {
1550 <th>\|| . $locale->text('Queued') . qq|\|</th>
1562 $lxdebug->leave_sub();
1566 $lxdebug->enter_sub();
1568 # if this goes to the printer pass through
1569 if ($form->{media} eq 'printer' || $form->{media} eq 'queue') {
1570 $form->error($locale->text('Select postscript or PDF!'))
1571 if ($form->{format} !~ /(postscript|pdf)/);
1573 $old_form = new Form;
1574 map { $old_form->{$_} = $form->{$_} } keys %$form;
1577 if (!$form->{id} || (($form->{formname} eq "proforma") && !$form->{proforma} && (($form->{type} =~ /_order$/) || ($form->{type} =~ /_quotation$/)))) {
1578 if ($form->{formname} eq "proforma") {
1579 $form->{proforma} = 1;
1581 $form->{print_and_save} = 1;
1582 my $formname = $form->{formname};
1584 $form->{formname} = $formname;
1589 &print_form($old_form);
1591 $lxdebug->leave_sub();
1595 $lxdebug->enter_sub();
1596 my ($old_form) = @_;
1600 $numberfld = "invnumber";
1603 ($form->{display_form}) ? $form->{display_form} : "display_form";
1605 # $form->{"notes"} will be overridden by the customer's/vendor's "notes" field. So save it here.
1606 $form->{ $form->{"formname"} . "notes" } = $form->{"notes"};
1608 if ($form->{formname} eq "invoice") {
1609 $form->{label} = $locale->text('Invoice');
1611 if ($form->{formname} eq "packing_list") {
1613 # this is from an invoice
1614 $form->{label} = $locale->text('Packing List');
1616 if ($form->{formname} eq 'sales_order') {
1619 $form->{"${inv}date"} = $form->{transdate};
1620 $form->{label} = $locale->text('Sales Order');
1621 $numberfld = "sonumber";
1625 if (($form->{type} eq 'invoice') && ($form->{formname} eq 'proforma') ) {
1628 $form->{"${inv}date"} = $form->{transdate};
1629 $form->{"invdate"} = $form->{transdate};
1630 $form->{label} = $locale->text('Proforma Invoice');
1631 $numberfld = "sonumber";
1635 if (($form->{type} eq 'sales_order') && ($form->{formname} eq 'proforma') ) {
1638 $form->{"${inv}date"} = $form->{transdate};
1639 $form->{"invdate"} = $form->{transdate};
1640 $form->{invnumber} = $form->{ordnumber};
1641 $form->{label} = $locale->text('Proforma Invoice');
1642 $numberfld = "sonumber";
1646 if ($form->{formname} eq 'packing_list' && $form->{type} ne 'invoice') {
1648 # we use the same packing list as from an invoice
1651 $form->{invdate} = $form->{"${inv}date"} = $form->{transdate};
1652 $form->{label} = $locale->text('Packing List');
1654 # set invnumber for template packing_list
1655 $form->{invnumber} = $form->{ordnumber};
1657 if ($form->{formname} eq 'pick_list') {
1660 $form->{"${inv}date"} =
1661 ($form->{transdate}) ? $form->{transdate} : $form->{invdate};
1662 $form->{label} = $locale->text('Pick List');
1663 $order = 1 unless $form->{type} eq 'invoice';
1665 if ($form->{formname} eq 'purchase_order') {
1668 $form->{"${inv}date"} = $form->{transdate};
1669 $form->{label} = $locale->text('Purchase Order');
1670 $numberfld = "ponumber";
1673 if ($form->{formname} eq 'bin_list') {
1676 $form->{"${inv}date"} = $form->{transdate};
1677 $form->{label} = $locale->text('Bin List');
1680 if ($form->{formname} eq 'sales_quotation') {
1683 $form->{"${inv}date"} = $form->{transdate};
1684 $form->{label} = $locale->text('Quotation');
1685 $numberfld = "sqnumber";
1689 if (($form->{type} eq 'sales_quotation') && ($form->{formname} eq 'proforma') ) {
1692 $form->{"${inv}date"} = $form->{transdate};
1693 $form->{"invdate"} = $form->{transdate};
1694 $form->{label} = $locale->text('Proforma Invoice');
1695 $numberfld = "sqnumber";
1699 if ($form->{formname} eq 'request_quotation') {
1702 $form->{"${inv}date"} = $form->{transdate};
1703 $form->{label} = $locale->text('Quotation');
1704 $numberfld = "rfqnumber";
1708 $form->isblank("email", $locale->text('E-mail address missing!'))
1709 if ($form->{media} eq 'email');
1710 $form->isblank("${inv}date",
1711 $locale->text($form->{label} . ' Date missing!'));
1713 # $locale->text('Invoice Number missing!')
1714 # $locale->text('Invoice Date missing!')
1715 # $locale->text('Packing List Number missing!')
1716 # $locale->text('Packing List Date missing!')
1717 # $locale->text('Order Number missing!')
1718 # $locale->text('Order Date missing!')
1719 # $locale->text('Quotation Number missing!')
1720 # $locale->text('Quotation Date missing!')
1723 if (!$form->{"${inv}number"} && !$form->{preview}) {
1724 $form->{"${inv}number"} = $form->update_defaults(\%myconfig, $numberfld);
1725 if ($form->{media} ne 'email') {
1727 # get pricegroups for parts
1728 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1730 # build up html code for prices_$i
1731 set_pricegroup($form->{rowcount});
1733 $form->{rowcount}--;
1742 # Save the email address given in the form because it should override the setting saved for the customer/vendor.
1743 my ($saved_email, $saved_cc, $saved_bcc) =
1744 ($form->{"email"}, $form->{"cc"}, $form->{"bcc"});
1746 $language_saved = $form->{language_id};
1747 $payment_id_saved = $form->{payment_id};
1749 &{"$form->{vc}_details"};
1751 $form->{language_id} = $language_saved;
1752 $form->{payment_id} = $payment_id_saved;
1754 $form->{"email"} = $saved_email if ($saved_email);
1755 $form->{"cc"} = $saved_cc if ($saved_cc);
1756 $form->{"bcc"} = $saved_bcc if ($saved_bcc);
1758 my ($language_tc, $output_numberformat, $output_dateformat, $output_longdates);
1759 if ($form->{"language_id"}) {
1760 ($language_tc, $output_numberformat, $output_dateformat, $output_longdates) =
1761 AM->get_language_details(\%myconfig, $form, $form->{language_id});
1763 $output_dateformat = $myconfig{"dateformat"};
1764 $output_numberformat = $myconfig{"numberformat"};
1765 $output_longdates = 1;
1768 ($form->{employee}) = split /--/, $form->{employee};
1769 ($form->{warehouse}, $form->{warehouse_id}) = split /--/, $form->{warehouse};
1771 # create the form variables
1773 OE->order_details(\%myconfig, \%$form);
1775 IS->invoice_details(\%myconfig, \%$form, $locale);
1778 if ($form->{shipto_id}) {
1779 $form->get_shipto(\%myconfig);
1782 @a = qw(name street zipcode city country);
1786 # if there is no shipto fill it in from billto
1787 foreach $item (@a) {
1788 if ($form->{"shipto$item"}) {
1795 if ( $form->{formname} eq 'purchase_order'
1796 || $form->{formname} eq 'request_quotation') {
1797 $form->{shiptoname} = $myconfig{company};
1798 $form->{shiptostreet} = $myconfig{address};
1800 map { $form->{"shipto$_"} = $form->{$_} } @a;
1804 $form->{notes} =~ s/^\s+//g;
1806 map({ $form->{$_} =~ s/\\n/\n/g; } qw(company address));
1808 $form->{templates} = "$myconfig{templates}";
1810 $form->{language} = $form->get_template_language(\%myconfig);
1811 $form->{printer_code} = $form->get_printer_code(\%myconfig);
1813 if ($form->{language} ne "") {
1814 map({ $form->{"unit"}->[$_] =
1815 AM->translate_units($form, $form->{"language"},
1816 $form->{"unit"}->[$_], $form->{"qty"}->[$_]); }
1817 (0..scalar(@{$form->{"unit"}}) - 1));
1818 $form->{language} = "_" . $form->{language};
1822 format_dates($output_dateformat, $output_longdates,
1823 qw(invdate orddate quodate pldate duedate reqdate transdate
1824 shippingdate deliverydate validitydate paymentdate
1825 datepaid transdate_oe deliverydate_oe
1826 employee_startdate employee_enddate
1828 grep({ /^datepaid_\d+$/ ||
1829 /^transdate_oe_\d+$/ ||
1830 /^deliverydate_oe_\d+$/ ||
1832 /^deliverydate_\d+$/ ||
1836 reformat_numbers($output_numberformat, 2,
1837 qw(invtotal ordtotal quototal subtotal linetotal
1838 listprice sellprice netprice discount
1840 grep({ /^linetotal_\d+$/ ||
1841 /^listprice_\d+$/ ||
1842 /^sellprice_\d+$/ ||
1849 reformat_numbers($output_numberformat, undef,
1854 if ($form->{printer_code} ne "") {
1855 $form->{printer_code} = "_" . $form->{printer_code};
1858 $form->{IN} = "$form->{formname}$form->{language}$form->{printer_code}.html";
1859 if ($form->{format} eq 'postscript') {
1860 $form->{postscript} = 1;
1861 $form->{IN} =~ s/html$/tex/;
1862 } elsif ($form->{"format"} =~ /pdf/) {
1864 if ($form->{"format"} =~ /opendocument/) {
1865 $form->{IN} =~ s/html$/odt/;
1867 $form->{IN} =~ s/html$/tex/;
1869 } elsif ($form->{"format"} =~ /opendocument/) {
1870 $form->{"opendocument"} = 1;
1871 $form->{"IN"} =~ s/html$/odt/;
1874 if ($form->{media} eq 'printer') {
1875 $form->{OUT} = "| $form->{printer_command} &>/dev/null";
1876 $form->{printed} .= " $form->{formname}";
1877 $form->{printed} =~ s/^ //;
1879 $printed = $form->{printed};
1881 if ($form->{media} eq 'email') {
1882 $form->{subject} = qq|$form->{label} $form->{"${inv}number"}|
1883 unless $form->{subject};
1885 $form->{OUT} = "$sendmail";
1887 $form->{emailed} .= " $form->{formname}";
1888 $form->{emailed} =~ s/^ //;
1890 $emailed = $form->{emailed};
1892 if ($form->{media} eq 'queue') {
1893 %queued = split / /, $form->{queued};
1895 if ($filename = $queued{ $form->{formname} }) {
1896 $form->{queued} =~ s/$form->{formname} $filename//;
1897 unlink "$spool/$filename";
1898 $filename =~ s/\..*$//g;
1904 $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
1905 $form->{OUT} = ">$spool/$filename";
1908 $form->{queued} .= " $form->{formname} $filename";
1910 $form->{queued} =~ s/^ //;
1912 $queued = $form->{queued};
1914 $form->parse_template(\%myconfig, $userspath);
1916 $form->{callback} = "";
1918 if ($form->{media} eq 'email') {
1919 $form->{message} = $locale->text('sent') unless $form->{message};
1921 $message = $form->{message};
1923 # if we got back here restore the previous form
1924 if ($form->{media} =~ /(printer|email|queue)/) {
1926 $form->update_status(\%myconfig)
1927 if ($form->{media} eq 'queue' && $form->{id});
1931 $old_form->{"${inv}number"} = $form->{"${inv}number"};
1933 # restore and display form
1934 map { $form->{$_} = $old_form->{$_} } keys %$old_form;
1936 $form->{queued} = $queued;
1937 $form->{printed} = $printed;
1938 $form->{emailed} = $emailed;
1939 $form->{message} = $message;
1941 $form->{rowcount}--;
1942 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1943 qw(exchangerate creditlimit creditremaining);
1945 for $i (1 .. $form->{paidaccounts}) {
1947 $form->{"${_}_$i"} =
1948 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
1949 } qw(paid exchangerate);
1957 ($form->{media} eq 'printer')
1958 ? $locale->text('sent to printer')
1959 : $locale->text('emailed to') . " $form->{email}";
1960 $form->redirect(qq|$form->{label} $form->{"${inv}number"} $msg|);
1962 if ($form->{printing}) {
1967 $lxdebug->leave_sub();
1970 sub customer_details {
1971 $lxdebug->enter_sub();
1972 IS->customer_details(\%myconfig, \%$form);
1973 $lxdebug->leave_sub();
1976 sub vendor_details {
1977 $lxdebug->enter_sub();
1979 IR->vendor_details(\%myconfig, \%$form);
1981 $lxdebug->leave_sub();
1985 $lxdebug->enter_sub();
1987 $form->{postasnew} = 1;
1988 map { delete $form->{$_} } qw(printed emailed queued);
1992 $lxdebug->leave_sub();
1996 $lxdebug->enter_sub();
1997 if ($form->{second_run}) {
1998 $form->{print_and_post} = 0;
2001 $title = $form->{title};
2002 $form->{title} = $locale->text('Ship to');
2004 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2005 qw(exchangerate creditlimit creditremaining);
2007 # get details for name
2008 &{"$form->{vc}_details"};
2011 ($form->{vc} eq 'customer')
2012 ? $locale->text('Customer Number')
2013 : $locale->text('Vendor Number');
2015 # get pricegroups for parts
2016 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
2018 # build up html code for prices_$i
2019 set_pricegroup($form->{rowcount});
2021 $nextsub = ($form->{display_form}) ? $form->{display_form} : "display_form";
2023 $form->{rowcount}--;
2030 <form method=post action=$form->{script}>
2036 <tr class=listheading>
2037 <th class=listheading colspan=2 width=50%>|
2038 . $locale->text('Billing Address') . qq|</th>
2039 <th class=listheading width=50%>|
2040 . $locale->text('Shipping Address') . qq|</th>
2042 <tr height="5"></tr>
2044 <th align=right nowrap>$number</th>
2045 <td>$form->{"$form->{vc}number"}</td>
2048 <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
2049 <td>$form->{name}</td>
2050 <td><input name=shiptoname size=35 value="$form->{shiptoname}"></td>
2053 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
2054 <td>$form->{department_1}</td>
2055 <td><input name=shiptodepartment_1 size=35 value="$form->{shiptodepartment_1}"></td>
2058 <th align=right nowrap> </th>
2059 <td>$form->{department_2}</td>
2060 <td><input name=shiptodepartment_2 size=35 value="$form->{shiptodepartment_2}"></td>
2063 <th align=right nowrap>| . $locale->text('Street') . qq|</th>
2064 <td>$form->{street}</td>
2065 <td><input name=shiptostreet size=35 value="$form->{shiptostreet}"></td>
2068 <th align=right nowrap>| . $locale->text('Zipcode') . qq|</th>
2069 <td>$form->{zipcode}</td>
2070 <td><input name=shiptozipcode size=35 value="$form->{shiptozipcode}"></td>
2073 <th align=right nowrap>| . $locale->text('City') . qq|</th>
2074 <td>$form->{city}</td>
2075 <td><input name=shiptocity size=35 value="$form->{shiptocity}"></td>
2078 <th align=right nowrap>| . $locale->text('Country') . qq|</th>
2079 <td>$form->{country}</td>
2080 <td><input name=shiptocountry size=35 value="$form->{shiptocountry}"></td>
2083 <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
2084 <td>$form->{contact}</td>
2085 <td><input name=shiptocontact size=35 value="$form->{shiptocontact}"></td>
2088 <th align=right nowrap>| . $locale->text('Phone') . qq|</th>
2089 <td>$form->{"$form->{vc}phone"}</td>
2090 <td><input name=shiptophone size=20 value="$form->{shiptophone}"></td>
2093 <th align=right nowrap>| . $locale->text('Fax') . qq|</th>
2094 <td>$form->{"$form->{vc}fax"}</td>
2095 <td><input name=shiptofax size=20 value="$form->{shiptofax}"></td>
2098 <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
2099 <td>$form->{email}</td>
2100 <td><input name=shiptoemail size=35 value="$form->{shiptoemail}"></td>
2107 <input type=hidden name=nextsub value=$nextsub>
2111 map { delete $form->{$_} }
2112 qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax shiptoemail shiptodepartment_1 shiptodepartment_2 header);
2113 $form->{title} = $title;
2115 foreach $key (keys %$form) {
2116 $form->{$key} =~ s/\"/"/g;
2117 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2125 <input class=submit type=submit name=action value="|
2126 . $locale->text('Continue') . qq|">
2133 $lxdebug->leave_sub();
2137 $lxdebug->enter_sub();
2142 $form->{old_callback} = $form->escape($form->{callback}, 1);
2143 $form->{callback} = $form->escape("$form->{script}?action=display_form", 1);
2144 $form->{old_callback} = $form->escape($form->{old_callback}, 1);
2147 delete $form->{action};
2148 $customer = $form->{customer};
2149 map { $form->{"old_$_"} = $form->{"${_}_$row"} } qw(partnumber description);
2151 # save all other form variables in a previousform variable
2152 $form->{row} = $row;
2153 foreach $key (keys %$form) {
2156 $form->{$key} =~ s/&/%26/g;
2157 $previousform .= qq|$key=$form->{$key}&|;
2160 $previousform = $form->escape($previousform, 1);
2162 $form->{script} = "licenses.pl";
2164 map { $form->{$_} = $form->{"old_$_"} } qw(partnumber description);
2165 map { $form->{$_} = $form->escape($form->{$_}, 1) }
2166 qw(partnumber description);
2168 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|;
2171 $lxdebug->leave_sub();
2174 sub relink_accounts {
2175 $lxdebug->enter_sub();
2177 $form->{"taxaccounts"} =~ s/\s*$//;
2178 $form->{"taxaccounts"} =~ s/^\s*//;
2179 foreach my $accno (split(/\s*/, $form->{"taxaccounts"})) {
2180 map({ delete($form->{"${accno}_${_}"}); } qw(rate description taxnumber));
2182 $form->{"taxaccounts"} = "";
2184 for (my $i = 1; $i <= $form->{"rowcount"}; $i++) {
2185 if ($form->{"id_$i"}) {
2186 IC->retrieve_accounts(\%myconfig, $form, $form->{"id_$i"}, $i, 1);
2190 $lxdebug->leave_sub();