1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
6 #############################################################################
7 # Veraendert 2005-01-05 - Marco Welter <mawe@linux-studio.de> - Neue Optik #
8 #############################################################################
9 # SQL-Ledger, Accounting
10 # Copyright (c) 1998-2002
12 # Author: Dieter Simader
13 # Email: dsimader@sql-ledger.org
14 # Web: http://www.sql-ledger.org
17 # This program is free software; you can redistribute it and/or modify
18 # it under the terms of the GNU General Public License as published by
19 # the Free Software Foundation; either version 2 of the License, or
20 # (at your option) any later version.
22 # This program is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU General Public License for more details.
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write to the Free Software
28 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #######################################################################
32 # common routines used in is, ir, oe
34 #######################################################################
41 require "$form->{path}/common.pl";
43 # any custom scripts for this one
44 if (-f "$form->{path}/custom_io.pl") {
45 eval { require "$form->{path}/custom_io.pl"; };
47 if (-f "$form->{path}/$form->{login}_io.pl") {
48 eval { require "$form->{path}/$form->{login}_io.pl"; };
55 # this is for our long dates
56 # $locale->text('January')
57 # $locale->text('February')
58 # $locale->text('March')
59 # $locale->text('April')
60 # $locale->text('May ')
61 # $locale->text('June')
62 # $locale->text('July')
63 # $locale->text('August')
64 # $locale->text('September')
65 # $locale->text('October')
66 # $locale->text('November')
67 # $locale->text('December')
69 # this is for our short month
70 # $locale->text('Jan')
71 # $locale->text('Feb')
72 # $locale->text('Mar')
73 # $locale->text('Apr')
74 # $locale->text('May')
75 # $locale->text('Jun')
76 # $locale->text('Jul')
77 # $locale->text('Aug')
78 # $locale->text('Sep')
79 # $locale->text('Oct')
80 # $locale->text('Nov')
81 # $locale->text('Dec')
86 ########################################
87 # Eintrag fuer Version 2.2.0 geaendert #
88 # neue Optik im Rechnungsformular #
89 ########################################
91 $lxdebug->enter_sub();
94 if ($lizenzen && $form->{vc} eq "customer") {
95 if ($form->{type} =~ /sales_order/) {
96 @column_index = (runningnumber, partnumber, description, ship, qty);
97 } elsif ($form->{type} =~ /sales_quotation/) {
98 @column_index = (runningnumber, partnumber, description, qty);
100 @column_index = (runningnumber, partnumber, description, qty);
103 if ( ($form->{type} =~ /purchase_order/)
104 || ($form->{type} =~ /sales_order/)) {
105 @column_index = (runningnumber, partnumber, description, ship, qty);
107 @column_index = (runningnumber, partnumber, description, qty);
110 ############## ENDE Neueintrag ##################
112 my $dimension_units = AM->retrieve_units(\%myconfig, $form, "dimension");
113 my $service_units = AM->retrieve_units(\%myconfig, $form, "service");
114 my $all_units = AM->retrieve_units(\%myconfig, $form);
116 push @column_index, qw(unit);
118 #for pricegroups column
119 if ( $form->{type} =~ (/sales_quotation/)
120 or (($form->{level} =~ /Sales/) and ($form->{type} =~ /invoice/))
121 or (($form->{level} eq undef) and ($form->{type} =~ /invoice/))
122 or ($form->{type} =~ /sales_order/)) {
123 push @column_index, qw(sellprice_pg);
126 push @column_index, qw(sellprice);
128 if ($form->{vc} eq 'customer') {
129 push @column_index, qw(discount);
132 push @column_index, "linetotal";
134 my $colspan = $#column_index + 1;
136 $form->{invsubtotal} = 0;
137 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
139 ########################################
140 # Eintrag fuer Version 2.2.0 geaendert #
141 # neue Optik im Rechnungsformular #
142 ########################################
143 $column_data{runningnumber} =
144 qq|<th align=left nowrap width=5 class=listheading>|
145 . $locale->text('No.')
147 $column_data{partnumber} =
148 qq|<th align=left nowrap width=12 class=listheading>|
149 . $locale->text('Number')
151 $column_data{description} =
152 qq|<th align=left nowrap width=30 class=listheading>|
153 . $locale->text('Part Description')
156 qq|<th align=left nowrap width=5 class=listheading>|
157 . $locale->text('Ship')
160 qq|<th align=left nowrap width=5 class=listheading>|
161 . $locale->text('Qty')
164 qq|<th align=left nowrap width=5 class=listheading>|
165 . $locale->text('Unit')
167 $column_data{license} =
168 qq|<th align=left nowrap width=10 class=listheading>|
169 . $locale->text('License')
171 $column_data{serialnr} =
172 qq|<th align=left nowrap width=10 class=listheading>|
173 . $locale->text('Serial No.')
175 $column_data{projectnr} =
176 qq|<th align=left nowrap width=10 class=listheading>|
177 . $locale->text('Project')
179 $column_data{sellprice} =
180 qq|<th align=left nowrap width=15 class=listheading>|
181 . $locale->text('Price')
183 $column_data{sellprice_pg} =
184 qq|<th align=left nowrap width=15 class=listheading>|
185 . $locale->text('Pricegroup')
187 $column_data{discount} =
188 qq|<th align=left class=listheading>|
189 . $locale->text('Discount')
191 $column_data{linetotal} =
192 qq|<th align=left nowrap width=10 class=listheading>|
193 . $locale->text('Extended')
196 qq|<th align=left nowrap width=10 class=listheading>|
197 . $locale->text('Bin')
199 ############## ENDE Neueintrag ##################
201 $myconfig{"show_form_details"} = 1
202 unless (defined($myconfig{"show_form_details"}));
203 $form->{"show_details"} = $myconfig{"show_form_details"}
204 unless (defined($form->{"show_details"}));
205 $form->{"show_details"} = $form->{"show_details"} ? 1 : 0;
206 my $show_details_new = 1 - $form->{"show_details"};
207 my $show_details_checked = $form->{"show_details"} ? "checked" : "";
212 <input type="hidden" name="show_details" value="$form->{show_details}">
213 <input type="checkbox" id="cb_show_details" onclick="show_form_details($show_details_new);" $show_details_checked>
214 <label for="cb_show_details">| . $locale->text("Show details") . qq|</label><br>
216 <tr class=listheading>|;
218 map { print "\n$column_data{$_}" } @column_index;
224 $runningnumber = $locale->text('No.');
225 $deliverydate = $locale->text('Delivery Date');
226 $serialnumber = $locale->text('Serial No.');
227 $projectnumber = $locale->text('Project');
228 $partsgroup = $locale->text('Group');
229 $reqdate = $locale->text('Reqdate');
231 $delvar = 'deliverydate';
233 if ($form->{type} =~ /_order$/ || $form->{type} =~ /_quotation$/) {
234 $deliverydate = $locale->text('Required by');
238 for $i (1 .. $numrows) {
243 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
244 } qw(qty ship discount sellprice price_new price_old) unless ($form->{simple_save});
246 if (!$form->{"unit_old_$i"}) {
247 # Neue Ware aus der Datenbank. In diesem Fall ist unit_$i die
248 # Einheit, wie sie in den Stammdaten hinterlegt wurde.
249 # Es sollte also angenommen werden, dass diese ausgewaehlt war.
250 $form->{"unit_old_$i"} = $form->{"unit_$i"};
255 # Die zuletzt ausgewaehlte mit der aktuell ausgewaehlten Einheit
256 # vergleichen und bei Unterschied den Preis entsprechend umrechnen.
257 $form->{"selected_unit_$i"} = $form->{"unit_$i"} unless ($form->{"selected_unit_$i"});
259 my $check_units = $form->{"inventory_accno_$i"} ? $dimension_units : $service_units;
260 if (!$check_units->{$form->{"selected_unit_$i"}} ||
261 ($check_units->{$form->{"selected_unit_$i"}}->{"base_unit"} ne
262 $all_units->{$form->{"unit_old_$i"}}->{"base_unit"})) {
263 # Die ausgewaehlte Einheit ist fuer diesen Artikel nicht gueltig
264 # (z.B. Dimensionseinheit war ausgewaehlt, es handelt sich aber
265 # um eine Dienstleistung). Dann keinerlei Umrechnung vornehmen.
266 $form->{"unit_old_$i"} = $form->{"selected_unit_$i"} = $form->{"unit_$i"};
268 if ((!$form->{"prices_$i"}) || ($form->{"new_pricegroup_$i"} == $form->{"old_pricegroup_$i"})) {
269 if ($form->{"unit_old_$i"} ne $form->{"selected_unit_$i"}) {
271 if (defined($all_units->{$form->{"unit_old_$i"}}->{"factor"}) &&
272 $all_units->{$form->{"unit_old_$i"}}->{"factor"}) {
273 $basefactor = $all_units->{$form->{"selected_unit_$i"}}->{"factor"} /
274 $all_units->{$form->{"unit_old_$i"}}->{"factor"};
276 $form->{"sellprice_$i"} *= $basefactor;
277 $form->{"unit_old_$i"} = $form->{"selected_unit_$i"};
280 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
282 $decimalplaces = ($dec > 2) ? $dec : 2;
286 $form->{"sellprice_$i"} * $form->{"discount_$i"} / 100,
290 $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
291 $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
293 # convert " to "
294 map { $form->{"${_}_$i"} =~ s/\"/"/g }
295 qw(partnumber description unit unit_old);
297 ########################################
298 # Eintrag fuer Version 2.2.0 geaendert #
299 # neue Optik im Rechnungsformular #
300 ########################################
301 $column_data{runningnumber} =
302 qq|<td><input name="runningnumber_$i" size=5 value=$i></td>|; # HuT
303 ############## ENDE Neueintrag ##################
305 $column_data{partnumber} =
306 qq|<td><input name="partnumber_$i" size=12 value="$form->{"partnumber_$i"}"></td>|;
308 if (($rows = $form->numtextrows($form->{"description_$i"}, 30, 6)) > 1) {
309 $column_data{description} =
310 qq|<td><textarea name="description_$i" rows=$rows cols=30 wrap=soft>| . H($form->{"description_$i"}) . qq|</textarea><button type="button" onclick="set_longdescription_window('longdescription_$i')">| . $locale->text('L') . qq|</button></td>|;
312 $column_data{description} =
313 qq|<td><input name="description_$i" size=30 value="| . $form->quote($form->{"description_$i"}) . qq|"><button type="button" onclick="set_longdescription_window('longdescription_$i')">| . $locale->text('L') . qq|</button></td>|;
316 (my $qty_dec) = ($form->{"qty_$i"} =~ /\.(\d+)/);
317 $qty_dec = length $qty_dec;
320 qq|<td align=right><input name="qty_$i" size=5 value=|
321 . $form->format_amount(\%myconfig, $form->{"qty_$i"}, $qty_dec) .qq|>|;
322 if ($form->{"formel_$i"}) {
323 $column_data{qty} .= qq|<button type="button" onclick="calculate_qty_selection_window('qty_$i','alu_$i', 'formel_$i', $i)">| . $locale->text('*/') . qq|</button>
324 <input type=hidden name="formel_$i" value="$form->{"formel_$i"}"><input type=hidden name="alu_$i" value="$form->{"alu_$i"}"></td>|;
327 qq|<td align=right><input name="ship_$i" size=5 value=|
328 . $form->format_amount(\%myconfig, $form->{"ship_$i"})
331 my $is_part = $form->{"inventory_accno_$i"};
332 my $is_assigned = $form->{"id_$i"};
333 my $this_unit = $form->{"unit_$i"};
334 if ($form->{"selected_unit_$i"} && $this_unit &&
335 $all_units->{$form->{"selected_unit_$i"}} && $all_units->{$this_unit} &&
336 ($all_units->{$form->{"selected_unit_$i"}}->{"base_unit"} eq $all_units->{$this_unit}->{"base_unit"})) {
337 $this_unit = $form->{"selected_unit_$i"};
338 } elsif (!$is_assigned ||
339 ($is_part && !$this_unit && ($all_units->{$this_unit} && ($all_units->{$this_unit}->{"base_unit"} eq $all_units->{"kg"}->{"base_unit"})))) {
343 $column_data{"unit"} = "<td>" .
344 ($qty_readonly ? " " :
345 AM->unit_select_html($is_part ? $dimension_units :
346 $is_assigned ? $service_units : $all_units,
347 "unit_$i", $this_unit,
348 $is_assigned ? $form->{"unit_$i"} : undef))
351 # build in drop down list for pricesgroups
352 if ($form->{"prices_$i"}) {
353 if ($form->{"new_pricegroup_$i"} != $form->{"old_pricegroup_$i"}) {
354 $price_tmp = $form->format_amount(\%myconfig, $form->{"price_new_$i"}, $decimalplaces);
356 $price_tmp = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
359 $column_data{sellprice_pg} =
360 qq|<td align=right><select name="sellprice_pg_$i">$form->{"prices_$i"}</select></td>|;
361 $column_data{sellprice} =
362 qq|<td><input name="sellprice_$i" size=10 value=$price_tmp></td>|;
365 # for last row and report
366 # set pricegroup drop down list from report menu
367 if ($form->{"sellprice_$i"} != 0) {
369 qq|<option value="$form->{"sellprice_$i"}--$form->{"pricegroup_id_$i"}" selected>$form->{"pricegroup_$i"}</option>\n|;
371 $form->{"pricegroup_old_$i"} = $form->{"pricegroup_id_$i"};
373 $column_data{sellprice_pg} =
374 qq|<td align=right><select name="sellprice_pg_$i">$prices</select></td>|;
379 $column_data{sellprice_pg} = qq|<td align=right> </td>|;
382 $column_data{sellprice} =
383 qq|<td><input name="sellprice_$i" size=10 value=|
384 . $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
388 $column_data{discount} =
389 qq|<td align=right><input name="discount_$i" size=3 value=|
390 . $form->format_amount(\%myconfig, $form->{"discount_$i"})
392 $column_data{linetotal} =
394 . $form->format_amount(\%myconfig, $linetotal, 2)
396 $column_data{bin} = qq|<td>$form->{"bin_$i"}</td>|;
398 ########################################
399 # Eintrag fuer Version 2.2.0 geaendert #
400 # neue Optik im Rechnungsformular #
401 ########################################
402 # if ($lizenzen && $form->{type} eq "invoice" && $form->{vc} eq "customer") {
403 # $column_data{license} = qq|<td><select name="licensenumber_$i">$form->{"lizenzen_$i"}></select></td>|;
406 # if ($form->{type} !~ /_quotation/) {
407 # $column_data{serialnr} = qq|<td><input name="serialnumber_$i" size=10 value="$form->{"serialnumber_$i"}"></td>|;
410 # $column_data{projectnr} = qq|<td><input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}"></td>|;
411 ############## ENDE Neueintrag ##################
415 <tr valign=top class=listrow$j>|;
417 map { print "\n$column_data{$_}" } @column_index;
422 <input type=hidden name="orderitems_id_$i" value=$form->{"orderitems_id_$i"}>
423 <input type=hidden name="bo_$i" value=$form->{"bo_$i"}>
425 <input type=hidden name="pricegroup_old_$i" value=$form->{"pricegroup_old_$i"}>
426 <input type=hidden name="price_old_$i" value=$form->{"price_old_$i"}>
427 <input type=hidden name="unit_old_$i" value="| . $form->quote($form->{"selected_unit_$i"}) . qq|">
428 <input type=hidden name="price_new_$i" value=|
429 . $form->format_amount(\%myconfig, $form->{"price_new_$i"}) . qq|>
431 <input type=hidden name="id_$i" value=$form->{"id_$i"}>
432 <input type=hidden name="inventory_accno_$i" value=$form->{"inventory_accno_$i"}>
433 <input type=hidden name="bin_$i" value="$form->{"bin_$i"}">
434 <input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">
435 <input type=hidden name="partnotes_$i" value="| . $form->quote($form->{"partnotes_$i"}) . qq|">
436 <input type=hidden name="income_accno_$i" value=$form->{"income_accno_$i"}>
437 <input type=hidden name="expense_accno_$i" value=$form->{"expense_accno_$i"}>
438 <input type=hidden name="listprice_$i" value="$form->{"listprice_$i"}">
439 <input type=hidden name="assembly_$i" value="$form->{"assembly_$i"}">
440 <input type=hidden name="taxaccounts_$i" value="$form->{"taxaccounts_$i"}">
441 <input type=hidden name="ordnumber_$i" value="$form->{"ordnumber_$i"}">
442 <input type=hidden name="transdate_$i" value="$form->{"transdate_$i"}">
443 <input type=hidden name="cusordnumber_$i" value="$form->{"cusordnumber_$i"}">
444 <input type=hidden name="longdescription_$i" value="| . $form->quote($form->{"longdescription_$i"}) . qq|">
445 <input type=hidden name="basefactor_$i" value="$form->{"basefactor_$i"}">
449 ########################################
450 # Eintrag fuer Version 2.2.0 geaendert #
451 # neue Optik im Rechnungsformular #
452 ########################################
455 'style="display:none;"' if (!$form->{"show_details"});
459 <tr class=listrow$j $row_style_attr>
460 <td colspan=$colspan>
462 if ($lizenzen && $form->{type} eq "invoice" && $form->{vc} eq "customer") {
463 my $selected = $form->{"licensenumber_$i"};
465 $form->{"lizenzen_$i"} =~ s/ selected//g;
466 $form->{"lizenzen_$i"} =~
467 s/value="${selected}"\>/value="${selected}" selected\>/;
468 $lizenzen_quoted = $form->{"lizenzen_$i"};
469 $lizenzen_quoted =~ s/\"/"/g;
471 <b>Lizenz\#</b> <select name="licensenumber_$i" size=1>
472 $form->{"lizenzen_$i"}
474 <input type=hidden name="lizenzen_$i" value="${lizenzen_quoted}">
477 if ($form->{type} !~ /_quotation/) {
479 <b>$serialnumber</b> <input name="serialnumber_$i" size=15 value="$form->{"serialnumber_$i"}">|;
483 <b>$projectnumber</b> <input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}">
484 <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}">
485 <input type=hidden name="project_id_$i" value="$form->{"project_id_$i"}">
487 if ($form->{type} eq 'invoice' or $form->{type} =~ /order/) {
489 ($form->{type} eq 'invoice')
491 : 'reqdate'; # invoice uses a different term for the same thing.
493 <b>${$reqdate_term}</b> <input name="${reqdate_term}_$i" size=11 value="$form->{"${reqdate_term}_$i"}">
496 my $subtotalchecked = ($form->{"subtotal_$i"}) ? "checked" : "";
498 <b>|.$locale->text('Subtotal').qq|</b> <input type="checkbox" name="subtotal_$i" value="1" "$subtotalchecked">
504 ############## ENDE Neueintrag ##################
506 map { $form->{"${_}_base"} += $linetotal }
507 (split / /, $form->{"taxaccounts_$i"});
509 $form->{invsubtotal} += $linetotal;
518 $lxdebug->leave_sub();
521 ##################################################
522 # build html-code for pricegroups in variable $form->{prices_$j}
525 $lxdebug->enter_sub();
526 my $rowcount = shift;
527 for $j (1 .. $rowcount) {
528 my $pricegroup_old = $form->{"pricegroup_old_$i"};
529 if ($form->{PRICES}{$j}) {
531 $prices = '<option value="--">' . $locale->text("none (pricegroup)") . '</option>';
533 foreach $item (@{ $form->{PRICES}{$j} }) {
535 #$price = $form->round_amount($myconfig, $item->{price}, 5);
536 #$price = $form->format_amount($myconfig, $item->{price}, 2);
537 $price = $item->{price};
538 $pricegroup_id = $item->{pricegroup_id};
539 $pricegroup = $item->{pricegroup};
541 # build drop down list for pricegroups
543 qq|<option value="$price--$pricegroup_id"$item->{selected}>$pricegroup</option>\n|;
548 # $form->{"${_}_$j"} =
549 # $form->format_amount(\%myconfig, $form->{"${_}_$j"})
550 # } qw(sellprice price_new price_old);
552 # set new selectedpricegroup_id and prices for "Preis"
553 if ($item->{selected} && ($pricegroup_id != 0)) {
554 $form->{"pricegroup_old_$j"} = $pricegroup_id;
555 $form->{"price_new_$j"} = $price;
556 $form->{"sellprice_$j"} = $price;
558 if ($pricegroup_id == 0) {
559 $form->{"price_new_$j"} = $form->{"sellprice_$j"};
562 $form->{"prices_$j"} = $prices;
565 $lxdebug->leave_sub();
569 $lxdebug->enter_sub();
570 @column_index = qw(ndx partnumber description onhand unit sellprice);
572 $column_data{ndx} = qq|<th> </th>|;
573 $column_data{partnumber} =
574 qq|<th class=listheading>| . $locale->text('Number') . qq|</th>|;
575 $column_data{description} =
576 qq|<th class=listheading>| . $locale->text('Part Description') . qq|</th>|;
577 $column_data{sellprice} =
578 qq|<th class=listheading>| . $locale->text('Price') . qq|</th>|;
579 $column_data{onhand} =
580 qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|;
582 qq|<th class=listheading>| . $locale->text('Unit') . qq|</th>|;
583 # list items with radio button on a form
586 $title = $locale->text('Select from one of the items below');
587 $colspan = $#column_index + 1;
592 <form method=post action=$form->{script}>
596 <th class=listtop colspan=$colspan>$title</th>
599 <tr class=listheading>|;
601 map { print "\n$column_data{$_}" } @column_index;
606 foreach $ref (@{ $form->{item_list} }) {
607 $checked = ($i++) ? "" : "checked";
610 if ($ref->{inventory_accno} > 0) {
611 $ref->{"lizenzen"} = qq|<option></option>|;
612 foreach $item (@{ $form->{LIZENZEN}{ $ref->{"id"} } }) {
613 $ref->{"lizenzen"} .=
614 qq|<option value=\"$item->{"id"}\">$item->{"licensenumber"}</option>|;
616 $ref->{"lizenzen"} .= qq|<option value=-1>Neue Lizenz</option>|;
617 $ref->{"lizenzen"} =~ s/\"/"/g;
621 map { $ref->{$_} =~ s/\"/"/g } qw(partnumber description unit);
625 $form->round_amount($ref->{sellprice} * (1 - $form->{tradediscount}), 2);
627 qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
628 $column_data{partnumber} =
629 qq|<td><input name="new_partnumber_$i" type=hidden value="$ref->{partnumber}">$ref->{partnumber}</td>|;
630 $column_data{description} =
631 qq|<td><input name="new_description_$i" type=hidden value="$ref->{description}">$ref->{description}</td>|;
632 $column_data{sellprice} =
633 qq|<td align=right><input name="new_sellprice_$i" type=hidden value=$ref->{sellprice}>|
634 . $form->format_amount(\%myconfig, $ref->{sellprice}, 2, " ")
636 $column_data{onhand} =
637 qq|<td align=right><input name="new_onhand_$i" type=hidden value=$ref->{onhand}>|
638 . $form->format_amount(\%myconfig, $ref->{onhand}, '', " ")
641 qq|<td>$ref->{unit}</td>|;
645 <tr class=listrow$j>|;
647 map { print "\n$column_data{$_}" } @column_index;
652 <input name="new_bin_$i" type=hidden value="$ref->{bin}">
653 <input name="new_listprice_$i" type=hidden value=$ref->{listprice}>
654 <input name="new_inventory_accno_$i" type=hidden value=$ref->{inventory_accno}>
655 <input name="new_income_accno_$i" type=hidden value=$ref->{income_accno}>
656 <input name="new_expense_accno_$i" type=hidden value=$ref->{expense_accno}>
657 <input name="new_unit_$i" type=hidden value="$ref->{unit}">
658 <input name="new_weight_$i" type=hidden value="$ref->{weight}">
659 <input name="new_assembly_$i" type=hidden value="$ref->{assembly}">
660 <input name="new_taxaccounts_$i" type=hidden value="$ref->{taxaccounts}">
661 <input name="new_partsgroup_$i" type=hidden value="$ref->{partsgroup}">
662 <input name="new_formel_$i" type=hidden value="$ref->{formel}">
663 <input name="new_longdescription_$i" type=hidden value="$ref->{longdescription}">
664 <input name="new_not_discountable_$i" type=hidden value="$ref->{not_discountable}">
665 <input name="new_part_payment_id_$i" type=hidden value="$ref->{part_payment_id}">
667 <input name="new_id_$i" type=hidden value=$ref->{id}>
672 <input name="new_lizenzen_$i" type=hidden value="$ref->{lizenzen}">
679 <tr><td colspan=8><hr size=3 noshade></td></tr>
682 <input name=lastndx type=hidden value=$i>
686 # delete action variable
687 map { delete $form->{$_} } qw(action item_list header);
689 # save all other form variables
690 foreach $key (keys %${form}) {
691 $form->{$key} =~ s/\"/"/g;
692 print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
696 <input type=hidden name=nextsub value=item_selected>
699 <input class=submit type=submit name=action value="|
700 . $locale->text('Continue') . qq|">
707 $lxdebug->leave_sub();
711 $lxdebug->enter_sub();
713 # replace the last row with the checked row
714 $i = $form->{rowcount};
715 $i = $form->{assembly_rows} if ($form->{item} eq 'assembly');
721 #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
722 #$form->{"sellprice_$i"} = $form->{"sellprice_$i"};
724 # if there was a price entered, override it
725 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
727 map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} }
728 qw(id partnumber description sellprice listprice inventory_accno income_accno expense_accno bin unit weight assembly taxaccounts partsgroup formel longdescription not_discountable);
729 if ($form->{"part_payment_id_$i"} ne "") {
730 $form->{payment_id} = $form->{"part_payment_id_$i"};
734 map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} } qw(lizenzen);
737 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
739 $decimalplaces = ($dec > 2) ? $dec : 2;
742 $form->{"sellprice_$i"} = $sellprice;
745 # if there is an exchange rate adjust sellprice
746 if (($form->{exchangerate} * 1) != 0) {
747 $form->{"sellprice_$i"} /= $form->{exchangerate};
748 $form->{"sellprice_$i"} =
749 $form->round_amount($form->{"sellprice_$i"}, $decimalplaces);
753 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
754 qw(sellprice listprice weight);
756 $form->{sellprice} += ($form->{"sellprice_$i"} * $form->{"qty_$i"});
757 $form->{weight} += ($form->{"weight_$i"} * $form->{"qty_$i"});
759 if ($form->{"not_discountable_$i"}) {
760 $form->{"discount_$i"} = 0;
764 $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) *
766 map { $form->{"${_}_base"} += $amount }
767 (split / /, $form->{"taxaccounts_$i"});
768 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /,
769 $form->{"taxaccounts_$i"}
770 if !$form->{taxincluded};
772 $form->{creditremaining} -= $amount;
774 $form->{"runningnumber_$i"} = $i;
776 # delete all the new_ variables
777 for $i (1 .. $form->{lastndx}) {
778 map { delete $form->{"new_${_}_$i"} }
779 qw(partnumber description sellprice bin listprice inventory_accno income_accno expense_accno unit assembly taxaccounts id);
782 map { delete $form->{$_} } qw(ndx lastndx nextsub);
787 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces)
788 } qw(sellprice listprice) if $form->{item} ne 'assembly';
790 # get pricegroups for parts
791 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
793 # build up html code for prices_$i
794 set_pricegroup($form->{rowcount});
798 $lxdebug->leave_sub();
802 $lxdebug->enter_sub();
805 $form->{old_callback} = $form->escape($form->{callback}, 1);
806 $form->{callback} = $form->escape("$form->{script}?action=display_form", 1);
809 delete $form->{action};
811 # save all other form variables in a previousform variable
812 foreach $key (keys %$form) {
815 $form->{$key} =~ s/&/%26/g;
816 $previousform .= qq|$key=$form->{$key}&|;
819 $previousform = $form->escape($previousform, 1);
821 $i = $form->{rowcount};
822 map { $form->{"${_}_$i"} =~ s/\"/"/g } qw(partnumber description);
829 <h4 class=error>| . $locale->text('Item not on file!') . qq|
832 | . $locale->text('What type of item is this?') . qq|</h4>
834 <form method=post action=ic.pl>
838 <input class=radio type=radio name=item value=part checked> |
839 . $locale->text('Part') . qq|<br>
840 <input class=radio type=radio name=item value=service> |
841 . $locale->text('Service')
844 <input type=hidden name=previousform value="$previousform">
845 <input type=hidden name=partnumber value="$form->{"partnumber_$i"}">
846 <input type=hidden name=description value="$form->{"description_$i"}">
847 <input type=hidden name=rowcount value=$form->{rowcount}>
848 <input type=hidden name=taxaccount2 value=$form->{taxaccounts}>
849 <input type=hidden name=vc value=$form->{vc}>
851 <input type=hidden name=path value=$form->{path}>
852 <input type=hidden name=login value=$form->{login}>
853 <input type=hidden name=password value=$form->{password}>
855 <input type=hidden name=nextsub value=add>
858 <input class=submit type=submit name=action value="|
859 . $locale->text('Continue') . qq|">
866 $lxdebug->leave_sub();
870 $lxdebug->enter_sub();
874 $form->language_payment(\%myconfig);
876 # if we have a display_form
877 if ($form->{display_form}) {
878 &{"$form->{display_form}"};
882 # if ( $form->{print_and_post}
883 # && $form->{second_run}
884 # && ($form->{action} eq "display_form")) {
885 # for (keys %$form) { $old_form->{$_} = $form->{$_} }
886 # $old_form->{rowcount}++;
888 # #$form->{rowcount}--;
889 # #$form->{rowcount}--;
891 # $form->{print_and_post} = 0;
893 # &print_form($old_form);
897 # $form->{action} = "";
898 # $form->{resubmit} = 0;
900 # if ($form->{print_and_post} && !$form->{second_run}) {
901 # $form->{second_run} = 1;
902 # $form->{action} = "display_form";
903 # $form->{rowcount}--;
904 # my $rowcount = $form->{rowcount};
906 # # get pricegroups for parts
907 # IS->get_pricegroups_for_parts(\%myconfig, \%$form);
909 # # build up html code for prices_$i
910 # set_pricegroup($rowcount);
912 # $form->{resubmit} = 1;
917 $numrows = ++$form->{rowcount};
918 $subroutine = "display_row";
920 if ($form->{item} eq 'part') {
922 #set preisgruppenanzahl
923 $numrows = $form->{price_rows};
924 $subroutine = "price_row";
926 &{$subroutine}($numrows);
928 $numrows = ++$form->{makemodel_rows};
929 $subroutine = "makemodel_row";
931 if ($form->{item} eq 'assembly') {
932 $numrows = $form->{price_rows};
933 $subroutine = "price_row";
935 &{$subroutine}($numrows);
937 $numrows = ++$form->{makemodel_rows};
938 $subroutine = "makemodel_row";
940 # create makemodel rows
941 &{$subroutine}($numrows);
943 $numrows = ++$form->{assembly_rows};
944 $subroutine = "assembly_row";
946 if ($form->{item} eq 'service') {
947 $numrows = $form->{price_rows};
948 $subroutine = "price_row";
950 &{$subroutine}($numrows);
956 &{$subroutine}($numrows) if $numrows;
960 $lxdebug->leave_sub();
964 $lxdebug->enter_sub();
968 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)
972 # remove any makes or model rows
973 if ($form->{item} eq 'part') {
974 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
975 qw(listprice sellprice lastcost weight rop);
977 @flds = (make, model);
978 for my $i (1 .. ($form->{makemodel_rows})) {
979 if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
983 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
988 $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
989 $form->{makemodel_rows} = $count;
991 } elsif ($form->{item} eq 'assembly') {
993 $form->{sellprice} = 0;
995 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
996 qw(listprice rop stock);
999 qw(id qty unit bom partnumber description sellprice weight runningnumber partsgroup);
1001 for my $i (1 .. ($form->{assembly_rows} - 1)) {
1002 if ($form->{"qty_$i"}) {
1006 $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
1008 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1010 #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
1012 $form->{sellprice} += ($form->{"qty_$i"} * $form->{"sellprice_$i"});
1013 $form->{weight} += ($form->{"qty_$i"} * $form->{"weight_$i"});
1018 $form->{sellprice} = $form->round_amount($form->{sellprice}, 2);
1020 $form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows});
1021 $form->{assembly_rows} = $count;
1024 @flds = qw(make model);
1027 for my $i (1 .. ($form->{makemodel_rows})) {
1028 if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
1032 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1037 $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
1038 $form->{makemodel_rows} = $count;
1042 # this section applies to invoices and orders
1043 # remove any empty numbers
1044 if ($form->{rowcount}) {
1045 for my $i (1 .. $form->{rowcount} - 1) {
1046 if ($form->{"partnumber_$i"}) {
1050 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1053 if ($form->{"licensenumber_$i"} == -1) {
1061 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
1062 $form->{rowcount} = $count;
1064 $form->{creditremaining} -= &invoicetotal;
1071 if ( $form->{type} =~ (/sales_quotation/)
1072 or (($form->{level} =~ /Sales/) and ($form->{type} =~ /invoice/))
1073 or (($form->{level} eq undef) and ($form->{type} =~ /invoice/))
1074 or ($form->{type} =~ /sales_order/)) {
1076 # get pricegroups for parts
1077 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1079 # build up html code for prices_$i
1080 set_pricegroup($form->{rowcount});
1086 $lxdebug->leave_sub();
1090 $lxdebug->enter_sub();
1092 $form->{oldinvtotal} = 0;
1094 # add all parts and deduct paid
1095 map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
1097 my ($amount, $sellprice, $discount, $qty);
1099 for my $i (1 .. $form->{rowcount}) {
1100 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1101 $discount = $form->parse_amount(\%myconfig, $form->{"discount_$i"});
1102 $qty = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
1104 #($form->{"sellprice_$i"}, $form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
1106 $amount = $sellprice * (1 - $discount / 100) * $qty;
1107 map { $form->{"${_}_base"} += $amount }
1108 (split / /, $form->{"taxaccounts_$i"});
1109 $form->{oldinvtotal} += $amount;
1112 map { $form->{oldinvtotal} += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1113 split / /, $form->{taxaccounts}
1114 if !$form->{taxincluded};
1116 $form->{oldtotalpaid} = 0;
1117 for $i (1 .. $form->{paidaccounts}) {
1118 $form->{oldtotalpaid} += $form->{"paid_$i"};
1121 $lxdebug->leave_sub();
1124 return ($form->{oldinvtotal} - $form->{oldtotalpaid});
1127 sub validate_items {
1128 $lxdebug->enter_sub();
1130 # check if items are valid
1131 if ($form->{rowcount} == 1) {
1136 for $i (1 .. $form->{rowcount} - 1) {
1137 $form->isblank("partnumber_$i",
1138 $locale->text('Number missing in Row') . " $i");
1141 $lxdebug->leave_sub();
1145 $lxdebug->enter_sub();
1146 if ($form->{second_run}) {
1147 $form->{print_and_post} = 0;
1149 $form->{ordnumber} = $form->{invnumber};
1151 map { delete $form->{$_} } qw(id printed emailed queued);
1152 if ($form->{script} eq 'ir.pl' || $form->{type} eq 'request_quotation') {
1153 $form->{title} = $locale->text('Add Purchase Order');
1154 $form->{vc} = 'vendor';
1155 $form->{type} = 'purchase_order';
1158 if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_quotation') {
1159 $form->{title} = $locale->text('Add Sales Order');
1160 $form->{vc} = 'customer';
1161 $form->{type} = 'sales_order';
1164 $form->{script} = 'oe.pl';
1166 $form->{shipto} = 1;
1168 $form->{rowcount}--;
1170 $form->{cp_id} *= 1;
1172 require "$form->{path}/$form->{script}";
1174 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1176 $currency = $form->{currency};
1180 $form->{currency} = $currency;
1181 $form->{exchangerate} = "";
1182 $form->{forex} = "";
1183 $form->{exchangerate} = $exchangerate
1187 $form->check_exchangerate(
1188 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1191 for $i (1 .. $form->{rowcount}) {
1192 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
1193 $form->{"${_}_${i}"})
1194 if ($form->{"${_}_${i}"}) }
1195 qw(ship qty sellprice listprice basefactor));
1201 $lxdebug->leave_sub();
1205 $lxdebug->enter_sub();
1206 if ($form->{second_run}) {
1207 $form->{print_and_post} = 0;
1209 map { delete $form->{$_} } qw(id printed emailed queued);
1211 if ($form->{script} eq 'ir.pl' || $form->{type} eq 'purchase_order') {
1212 $form->{title} = $locale->text('Add Request for Quotation');
1213 $form->{vc} = 'vendor';
1214 $form->{type} = 'request_quotation';
1217 if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_order') {
1218 $form->{title} = $locale->text('Add Quotation');
1219 $form->{vc} = 'customer';
1220 $form->{type} = 'sales_quotation';
1224 $form->{cp_id} *= 1;
1226 $form->{script} = 'oe.pl';
1228 $form->{shipto} = 1;
1230 $form->{rowcount}--;
1232 require "$form->{path}/$form->{script}";
1234 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1236 $currency = $form->{currency};
1240 $form->{currency} = $currency;
1241 $form->{exchangerate} = "";
1242 $form->{forex} = "";
1243 $form->{exchangerate} = $exchangerate
1247 $form->check_exchangerate(
1248 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1251 for $i (1 .. $form->{rowcount}) {
1252 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
1253 $form->{"${_}_${i}"})
1254 if ($form->{"${_}_${i}"}) }
1255 qw(ship qty sellprice listprice basefactor));
1261 $lxdebug->leave_sub();
1264 sub request_for_quotation {
1269 $lxdebug->enter_sub();
1270 if ($form->{second_run}) {
1271 $form->{print_and_post} = 0;
1272 $form->{resubmit} = 0;
1274 if ($myconfig{role} eq 'admin') {
1276 <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
1277 <td><input name=bcc size=30 value="$form->{bcc}"></td>
1281 if ($form->{formname} =~ /(pick|packing|bin)_list/) {
1282 $form->{email} = $form->{shiptoemail} if $form->{shiptoemail};
1285 if ($form->{"cp_id"} && !$form->{"email"}) {
1286 CT->get_contact(\%myconfig, $form);
1287 $form->{"email"} = $form->{"cp_email"};
1290 $name = $form->{ $form->{vc} };
1292 $title = $locale->text('E-mail') . " $name";
1294 $form->{oldmedia} = $form->{media};
1295 $form->{media} = "email";
1302 <form method=post action=$form->{script}>
1306 <th class=listtop>$title</th>
1308 <tr height="5"></tr>
1313 <th align=right nowrap>| . $locale->text('To') . qq|</th>
1314 <td><input name=email size=30 value="$form->{email}"></td>
1315 <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
1316 <td><input name=cc size=30 value="$form->{cc}"></td>
1319 <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
1320 <td><input name=subject size=30 value="$form->{subject}"></td>
1330 <th align=left nowrap>| . $locale->text('Message') . qq|</th>
1333 <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
1344 map { delete $form->{$_} }
1345 qw(action email cc bcc subject message formname sendmode format header override);
1347 # save all other variables
1348 foreach $key (keys %$form) {
1349 $form->{$key} =~ s/\"/"/g;
1350 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1357 <td><hr size=3 noshade></td>
1361 <input type=hidden name=nextsub value=send_email>
1364 <input name=action class=submit type=submit value="|
1365 . $locale->text('Continue') . qq|">
1372 $lxdebug->leave_sub();
1376 $lxdebug->enter_sub();
1378 $old_form = new Form;
1380 map { $old_form->{$_} = $form->{$_} } keys %$form;
1381 $old_form->{media} = $form->{oldmedia};
1383 &print_form($old_form);
1385 $lxdebug->leave_sub();
1389 $lxdebug->enter_sub();
1390 $form->{sendmode} = "attachment";
1393 $form->{"format"} ? $form->{"format"} :
1394 $myconfig{"template_format"} ? $myconfig{"template_format"} :
1398 $form->{"copies"} ? $form->{"copies"} :
1399 $myconfig{"copies"} ? $myconfig{"copies"} :
1402 $form->{PD}{ $form->{formname} } = "selected";
1403 $form->{DF}{ $form->{format} } = "selected";
1404 $form->{OP}{ $form->{media} } = "selected";
1405 $form->{SM}{ $form->{sendmode} } = "selected";
1407 if ($form->{type} eq 'purchase_order') {
1408 $type = qq|<select name=formname>
1409 <option value=purchase_order $form->{PD}{purchase_order}>|
1410 . $locale->text('Purchase Order') . qq|
1411 <option value=bin_list $form->{PD}{bin_list}>|
1412 . $locale->text('Bin List');
1415 if ($form->{type} eq 'credit_note') {
1416 $type = qq|<select name=formname>
1417 <option value=credit_note $form->{PD}{credit_note}>|
1418 . $locale->text('Credit Note');
1421 if ($form->{type} eq 'sales_order') {
1422 $type = qq|<select name=formname>
1423 <option value=sales_order $form->{PD}{sales_order}>|
1424 . $locale->text('Confirmation') . qq|
1425 <option value=proforma $form->{PD}{proforma}>|
1426 . $locale->text('Proforma Invoice') . qq|
1427 <option value=pick_list $form->{PD}{pick_list}>|
1428 . $locale->text('Pick List') . qq|
1429 <option value=packing_list $form->{PD}{packing_list}>|
1430 . $locale->text('Packing List');
1433 if ($form->{type} =~ /_quotation$/) {
1434 $type = qq|<select name=formname>
1435 <option value="$`_quotation" $form->{PD}{"$`_quotation"}>|
1436 . $locale->text('Quotation');
1439 if ($form->{type} eq 'invoice') {
1440 $type = qq|<select name=formname>
1441 <option value=invoice $form->{PD}{invoice}>|
1442 . $locale->text('Invoice') . qq|
1443 <option value=proforma $form->{PD}{proforma}>|
1444 . $locale->text('Proforma Invoice') . qq|
1445 <option value=packing_list $form->{PD}{packing_list}>|
1446 . $locale->text('Packing List');
1449 if ($form->{type} eq 'invoice' && $form->{storno}) {
1450 $type = qq|<select name=formname>
1451 <option value=storno_invoice $form->{PD}{storno_invoice}>|
1452 . $locale->text('Storno Invoice') . qq|
1453 <option value=storno_packing_list $form->{PD}{storno_packing_list}>|
1454 . $locale->text('Storno Packing List');
1457 if ($form->{type} eq 'credit_note') {
1458 $type = qq|<select name=formname>
1459 <option value=credit_note $form->{PD}{credit_note}>|
1460 . $locale->text('Credit Note');
1463 if ($form->{type} eq 'ship_order') {
1464 $type = qq|<select name=formname>
1465 <option value=pick_list $form->{PD}{pick_list}>|
1466 . $locale->text('Pick List') . qq|
1467 <option value=packing_list $form->{PD}{packing_list}>|
1468 . $locale->text('Packing List');
1471 if ($form->{type} eq 'receive_order') {
1472 $type = qq|<select name=formname>
1473 <option value=bin_list $form->{PD}{bin_list}>|
1474 . $locale->text('Bin List');
1477 if ($form->{media} eq 'email') {
1478 $media = qq|<select name=sendmode>
1479 <option value=attachment $form->{SM}{attachment}>|
1480 . $locale->text('Attachment') . qq|
1481 <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
1483 $media = qq|<select name=media>
1484 <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
1485 if (scalar(keys (%{ $form->{printers} })) !=0 && $latex_templates) {
1487 <option value=printer $form->{OP}{printer}>|
1488 . $locale->text('Printer');
1490 if ($latex_templates) {
1492 <option value=queue $form->{OP}{queue}>| . $locale->text('Queue');
1496 $format = qq|<select name=format>|;
1497 if ($opendocument_templates && $openofficeorg_writer_bin &&
1498 $xvfb_bin && (-x $openofficeorg_writer_bin) && (-x $xvfb_bin)) {
1499 $format .= qq|<option value=opendocument_pdf | .
1500 $form->{DF}{"opendocument_pdf"} . qq|>| .
1501 $locale->text("PDF (OpenDocument/OASIS)") . qq|</option>|;
1504 if ($latex_templates) {
1505 $format .= qq|<option value=pdf $form->{DF}{pdf}>| .
1506 $locale->text('PDF') . qq|</option>|;
1509 $format .= qq|<option value=html $form->{DF}{html}>HTML</option>|;
1511 if ($latex_templates) {
1512 $format .= qq|<option value=postscript $form->{DF}{postscript}>| .
1513 $locale->text('Postscript') . qq|</option>|;
1516 if ($opendocument_templates) {
1517 $format .= qq|<option value=opendocument $form->{DF}{opendocument}>| .
1518 $locale->text("OpenDocument/OASIS") . qq|</option>|;
1520 $format .= qq|</select>|;
1522 if (scalar(keys (%{ $form->{languages} })) !=0) {
1523 $language_select = qq|<select name=language_id>
1524 <option value=""></option>}|;
1525 foreach $item (@{ $form->{languages} }) {
1526 if ($form->{language_id} eq $item->{id}) {
1527 $language_select .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
1529 $language_select .= qq|<option value="$item->{id}">$item->{description}</option>|;
1534 if (scalar(keys (%{ $form->{printers} })) !=0) {
1536 $printer_select = qq|<select name=printer_id>
1537 <option value=""></option>|;
1538 foreach $item (@{ $form->{printers} }) {
1539 $printer_select .= qq|<option value="$item->{id}">$item->{printer_description}</option>|;
1546 <table width=100% cellspacing=0 cellpadding=0>
1551 <td>$type</select></td>|;
1552 if (scalar(keys (%{ $form->{languages} })) !=0) {
1554 <td>${language_select}</select></td>|;
1557 <td>$format</select></td>
1558 <td>$media</select></td>|;
1559 if (scalar(keys (%{ $form->{printers} })) !=0) {
1561 <td>$printer_select</select></td>
1565 if (scalar(keys (%{ $form->{printers} })) !=0 && $latex_templates && $form->{media} ne 'email') {
1567 <td>| . $locale->text('Copies') . qq|
1568 <input name=copies size=2 value=$form->{copies}></td>
1572 $form->{groupitems} = "checked" if $form->{groupitems};
1575 <td>| . $locale->text('Group Items') . qq|</td>
1576 <td><input name=groupitems type=checkbox class=checkbox $form->{groupitems}></td>
1585 if ($form->{printed} =~ /$form->{formname}/) {
1587 <th>\|| . $locale->text('Printed') . qq|\|</th>
1591 if ($form->{emailed} =~ /$form->{formname}/) {
1593 <th>\|| . $locale->text('E-mailed') . qq|\|</th>
1597 if ($form->{queued} =~ /$form->{formname}/) {
1599 <th>\|| . $locale->text('Queued') . qq|\|</th>
1611 $lxdebug->leave_sub();
1615 $lxdebug->enter_sub();
1617 # if this goes to the printer pass through
1618 if ($form->{media} eq 'printer' || $form->{media} eq 'queue') {
1619 $form->error($locale->text('Select postscript or PDF!'))
1620 if ($form->{format} !~ /(postscript|pdf)/);
1622 $old_form = new Form;
1623 map { $old_form->{$_} = $form->{$_} } keys %$form;
1626 if (!$form->{id} || (($form->{formname} eq "proforma") && !$form->{proforma} && (($form->{type} =~ /_order$/) || ($form->{type} =~ /_quotation$/)))) {
1627 if ($form->{formname} eq "proforma") {
1628 $form->{proforma} = 1;
1630 $form->{print_and_save} = 1;
1631 my $formname = $form->{formname};
1633 $form->{formname} = $formname;
1638 &print_form($old_form);
1640 $lxdebug->leave_sub();
1644 $lxdebug->enter_sub();
1645 my ($old_form) = @_;
1649 $numberfld = "invnumber";
1652 ($form->{display_form}) ? $form->{display_form} : "display_form";
1654 # $form->{"notes"} will be overridden by the customer's/vendor's "notes" field. So save it here.
1655 $form->{ $form->{"formname"} . "notes" } = $form->{"notes"};
1657 if ($form->{formname} eq "invoice") {
1658 $form->{label} = $locale->text('Invoice');
1660 if ($form->{formname} eq "packing_list") {
1662 # this is from an invoice
1663 $form->{label} = $locale->text('Packing List');
1665 if ($form->{formname} eq 'sales_order') {
1668 $form->{"${inv}date"} = $form->{transdate};
1669 $form->{label} = $locale->text('Sales Order');
1670 $numberfld = "sonumber";
1674 if (($form->{type} eq 'invoice') && ($form->{formname} eq 'proforma') ) {
1677 $form->{"${inv}date"} = $form->{transdate};
1678 $form->{"invdate"} = $form->{transdate};
1679 $form->{label} = $locale->text('Proforma Invoice');
1680 $numberfld = "sonumber";
1684 if (($form->{type} eq 'sales_order') && ($form->{formname} eq 'proforma') ) {
1687 $form->{"${inv}date"} = $form->{transdate};
1688 $form->{"invdate"} = $form->{transdate};
1689 $form->{invnumber} = $form->{ordnumber};
1690 $form->{label} = $locale->text('Proforma Invoice');
1691 $numberfld = "sonumber";
1695 if ($form->{formname} eq 'packing_list' && $form->{type} ne 'invoice') {
1697 # we use the same packing list as from an invoice
1700 $form->{invdate} = $form->{"${inv}date"} = $form->{transdate};
1701 $form->{label} = $locale->text('Packing List');
1703 # set invnumber for template packing_list
1704 $form->{invnumber} = $form->{ordnumber};
1706 if ($form->{formname} eq 'pick_list') {
1709 $form->{"${inv}date"} =
1710 ($form->{transdate}) ? $form->{transdate} : $form->{invdate};
1711 $form->{label} = $locale->text('Pick List');
1712 $order = 1 unless $form->{type} eq 'invoice';
1714 if ($form->{formname} eq 'purchase_order') {
1717 $form->{"${inv}date"} = $form->{transdate};
1718 $form->{label} = $locale->text('Purchase Order');
1719 $numberfld = "ponumber";
1722 if ($form->{formname} eq 'bin_list') {
1725 $form->{"${inv}date"} = $form->{transdate};
1726 $form->{label} = $locale->text('Bin List');
1729 if ($form->{formname} eq 'sales_quotation') {
1732 $form->{"${inv}date"} = $form->{transdate};
1733 $form->{label} = $locale->text('Quotation');
1734 $numberfld = "sqnumber";
1738 if (($form->{type} eq 'sales_quotation') && ($form->{formname} eq 'proforma') ) {
1741 $form->{"${inv}date"} = $form->{transdate};
1742 $form->{"invdate"} = $form->{transdate};
1743 $form->{label} = $locale->text('Proforma Invoice');
1744 $numberfld = "sqnumber";
1748 if ($form->{formname} eq 'request_quotation') {
1751 $form->{"${inv}date"} = $form->{transdate};
1752 $form->{label} = $locale->text('Quotation');
1753 $numberfld = "rfqnumber";
1757 $form->isblank("email", $locale->text('E-mail address missing!'))
1758 if ($form->{media} eq 'email');
1759 $form->isblank("${inv}date",
1760 $locale->text($form->{label} . ' Date missing!'));
1762 # $locale->text('Invoice Number missing!')
1763 # $locale->text('Invoice Date missing!')
1764 # $locale->text('Packing List Number missing!')
1765 # $locale->text('Packing List Date missing!')
1766 # $locale->text('Order Number missing!')
1767 # $locale->text('Order Date missing!')
1768 # $locale->text('Quotation Number missing!')
1769 # $locale->text('Quotation Date missing!')
1772 if (!$form->{"${inv}number"} && !$form->{preview}) {
1773 $form->{"${inv}number"} = $form->update_defaults(\%myconfig, $numberfld);
1774 if ($form->{media} ne 'email') {
1776 # get pricegroups for parts
1777 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1779 # build up html code for prices_$i
1780 set_pricegroup($form->{rowcount});
1782 $form->{rowcount}--;
1791 # Save the email address given in the form because it should override the setting saved for the customer/vendor.
1792 my ($saved_email, $saved_cc, $saved_bcc) =
1793 ($form->{"email"}, $form->{"cc"}, $form->{"bcc"});
1795 $language_saved = $form->{language_id};
1796 $payment_id_saved = $form->{payment_id};
1798 &{"$form->{vc}_details"}();
1800 $form->{language_id} = $language_saved;
1801 $form->{payment_id} = $payment_id_saved;
1803 $form->{"email"} = $saved_email if ($saved_email);
1804 $form->{"cc"} = $saved_cc if ($saved_cc);
1805 $form->{"bcc"} = $saved_bcc if ($saved_bcc);
1807 my ($language_tc, $output_numberformat, $output_dateformat, $output_longdates);
1808 if ($form->{"language_id"}) {
1809 ($language_tc, $output_numberformat, $output_dateformat, $output_longdates) =
1810 AM->get_language_details(\%myconfig, $form, $form->{language_id});
1812 $output_dateformat = $myconfig{"dateformat"};
1813 $output_numberformat = $myconfig{"numberformat"};
1814 $output_longdates = 1;
1817 ($form->{employee}) = split /--/, $form->{employee};
1818 ($form->{warehouse}, $form->{warehouse_id}) = split /--/, $form->{warehouse};
1820 # create the form variables
1822 OE->order_details(\%myconfig, \%$form);
1824 IS->invoice_details(\%myconfig, \%$form, $locale);
1827 if ($form->{shipto_id}) {
1828 $form->get_shipto(\%myconfig);
1831 @a = qw(name street zipcode city country);
1835 # if there is no shipto fill it in from billto
1836 foreach $item (@a) {
1837 if ($form->{"shipto$item"}) {
1844 if ( $form->{formname} eq 'purchase_order'
1845 || $form->{formname} eq 'request_quotation') {
1846 $form->{shiptoname} = $myconfig{company};
1847 $form->{shiptostreet} = $myconfig{address};
1849 map { $form->{"shipto$_"} = $form->{$_} } @a;
1853 $form->{notes} =~ s/^\s+//g;
1855 $form->{templates} = "$myconfig{templates}";
1857 $form->{language} = $form->get_template_language(\%myconfig);
1858 $form->{printer_code} = $form->get_printer_code(\%myconfig);
1860 if ($form->{language} ne "") {
1861 map({ $form->{"unit"}->[$_] =
1862 AM->translate_units($form, $form->{"language"},
1863 $form->{"unit"}->[$_], $form->{"qty"}->[$_]); }
1864 (0..scalar(@{$form->{"unit"}}) - 1));
1865 $form->{language} = "_" . $form->{language};
1869 format_dates($output_dateformat, $output_longdates,
1870 qw(invdate orddate quodate pldate duedate reqdate transdate
1871 shippingdate deliverydate validitydate paymentdate
1872 datepaid transdate_oe deliverydate_oe
1873 employee_startdate employee_enddate
1875 grep({ /^datepaid_\d+$/ ||
1876 /^transdate_oe_\d+$/ ||
1877 /^deliverydate_oe_\d+$/ ||
1879 /^deliverydate_\d+$/ ||
1883 reformat_numbers($output_numberformat, 2,
1884 qw(invtotal ordtotal quototal subtotal linetotal
1885 listprice sellprice netprice discount
1887 grep({ /^linetotal_\d+$/ ||
1888 /^listprice_\d+$/ ||
1889 /^sellprice_\d+$/ ||
1896 reformat_numbers($output_numberformat, undef,
1901 if ($form->{printer_code} ne "") {
1902 $form->{printer_code} = "_" . $form->{printer_code};
1905 $form->{IN} = "$form->{formname}$form->{language}$form->{printer_code}.html";
1906 if ($form->{format} eq 'postscript') {
1907 $form->{postscript} = 1;
1908 $form->{IN} =~ s/html$/tex/;
1909 } elsif ($form->{"format"} =~ /pdf/) {
1911 if ($form->{"format"} =~ /opendocument/) {
1912 $form->{IN} =~ s/html$/odt/;
1914 $form->{IN} =~ s/html$/tex/;
1916 } elsif ($form->{"format"} =~ /opendocument/) {
1917 $form->{"opendocument"} = 1;
1918 $form->{"IN"} =~ s/html$/odt/;
1921 if ($form->{media} eq 'printer') {
1922 $form->{OUT} = "| $form->{printer_command} &>/dev/null";
1923 $form->{printed} .= " $form->{formname}";
1924 $form->{printed} =~ s/^ //;
1926 $printed = $form->{printed};
1928 if ($form->{media} eq 'email') {
1929 $form->{subject} = qq|$form->{label} $form->{"${inv}number"}|
1930 unless $form->{subject};
1932 $form->{OUT} = "$sendmail";
1934 $form->{emailed} .= " $form->{formname}";
1935 $form->{emailed} =~ s/^ //;
1937 $emailed = $form->{emailed};
1939 if ($form->{media} eq 'queue') {
1940 %queued = split / /, $form->{queued};
1942 if ($filename = $queued{ $form->{formname} }) {
1943 $form->{queued} =~ s/$form->{formname} $filename//;
1944 unlink "$spool/$filename";
1945 $filename =~ s/\..*$//g;
1951 $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
1952 $form->{OUT} = ">$spool/$filename";
1955 $form->{queued} .= " $form->{formname} $filename";
1957 $form->{queued} =~ s/^ //;
1959 $queued = $form->{queued};
1961 $form->parse_template(\%myconfig, $userspath);
1963 $form->{callback} = "";
1965 if ($form->{media} eq 'email') {
1966 $form->{message} = $locale->text('sent') unless $form->{message};
1968 $message = $form->{message};
1970 # if we got back here restore the previous form
1971 if ($form->{media} =~ /(printer|email|queue)/) {
1973 $form->update_status(\%myconfig)
1974 if ($form->{media} eq 'queue' && $form->{id});
1978 $old_form->{"${inv}number"} = $form->{"${inv}number"};
1980 # restore and display form
1981 map { $form->{$_} = $old_form->{$_} } keys %$old_form;
1983 $form->{queued} = $queued;
1984 $form->{printed} = $printed;
1985 $form->{emailed} = $emailed;
1986 $form->{message} = $message;
1988 $form->{rowcount}--;
1989 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1990 qw(exchangerate creditlimit creditremaining);
1992 for $i (1 .. $form->{paidaccounts}) {
1994 $form->{"${_}_$i"} =
1995 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
1996 } qw(paid exchangerate);
2004 ($form->{media} eq 'printer')
2005 ? $locale->text('sent to printer')
2006 : $locale->text('emailed to') . " $form->{email}";
2007 $form->redirect(qq|$form->{label} $form->{"${inv}number"} $msg|);
2009 if ($form->{printing}) {
2014 $lxdebug->leave_sub();
2017 sub customer_details {
2018 $lxdebug->enter_sub();
2019 IS->customer_details(\%myconfig, \%$form, @_);
2020 $lxdebug->leave_sub();
2023 sub vendor_details {
2024 $lxdebug->enter_sub();
2026 IR->vendor_details(\%myconfig, \%$form, @_);
2028 $lxdebug->leave_sub();
2032 $lxdebug->enter_sub();
2034 $form->{postasnew} = 1;
2035 map { delete $form->{$_} } qw(printed emailed queued);
2039 $lxdebug->leave_sub();
2043 $lxdebug->enter_sub();
2044 if ($form->{second_run}) {
2045 $form->{print_and_post} = 0;
2048 $title = $form->{title};
2049 $form->{title} = $locale->text('Ship to');
2051 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2052 qw(exchangerate creditlimit creditremaining);
2055 qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry
2056 shiptocontact shiptophone shiptofax shiptoemail
2057 shiptodepartment_1 shiptodepartment_2);
2060 (qw(name department_1 department_2 street zipcode city country
2061 contact email phone fax));
2063 # get details for name
2064 &{"$form->{vc}_details"}(@addr_vars);
2067 ($form->{vc} eq 'customer')
2068 ? $locale->text('Customer Number')
2069 : $locale->text('Vendor Number');
2071 # get pricegroups for parts
2072 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
2074 # build up html code for prices_$i
2075 set_pricegroup($form->{rowcount});
2077 $nextsub = ($form->{display_form}) ? $form->{display_form} : "display_form";
2079 $form->{rowcount}--;
2086 <form method=post action=$form->{script}>
2092 <tr class=listheading>
2093 <th class=listheading colspan=2 width=50%>|
2094 . $locale->text('Billing Address') . qq|</th>
2095 <th class=listheading width=50%>|
2096 . $locale->text('Shipping Address') . qq|</th>
2098 <tr height="5"></tr>
2100 <th align=right nowrap>$number</th>
2101 <td>$form->{"$form->{vc}number"}</td>
2104 <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
2105 <td>$form->{name}</td>
2106 <td><input name=shiptoname size=35 value="$form->{shiptoname}"></td>
2109 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
2110 <td>$form->{department_1}</td>
2111 <td><input name=shiptodepartment_1 size=35 value="$form->{shiptodepartment_1}"></td>
2114 <th align=right nowrap> </th>
2115 <td>$form->{department_2}</td>
2116 <td><input name=shiptodepartment_2 size=35 value="$form->{shiptodepartment_2}"></td>
2119 <th align=right nowrap>| . $locale->text('Street') . qq|</th>
2120 <td>$form->{street}</td>
2121 <td><input name=shiptostreet size=35 value="$form->{shiptostreet}"></td>
2124 <th align=right nowrap>| . $locale->text('Zipcode') . qq|</th>
2125 <td>$form->{zipcode}</td>
2126 <td><input name=shiptozipcode size=35 value="$form->{shiptozipcode}"></td>
2129 <th align=right nowrap>| . $locale->text('City') . qq|</th>
2130 <td>$form->{city}</td>
2131 <td><input name=shiptocity size=35 value="$form->{shiptocity}"></td>
2134 <th align=right nowrap>| . $locale->text('Country') . qq|</th>
2135 <td>$form->{country}</td>
2136 <td><input name=shiptocountry size=35 value="$form->{shiptocountry}"></td>
2139 <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
2140 <td>$form->{contact}</td>
2141 <td><input name=shiptocontact size=35 value="$form->{shiptocontact}"></td>
2144 <th align=right nowrap>| . $locale->text('Phone') . qq|</th>
2145 <td>$form->{phone}</td>
2146 <td><input name=shiptophone size=20 value="$form->{shiptophone}"></td>
2149 <th align=right nowrap>| . $locale->text('Fax') . qq|</th>
2150 <td>$form->{fax}</td>
2151 <td><input name=shiptofax size=20 value="$form->{shiptofax}"></td>
2154 <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
2155 <td>$form->{email}</td>
2156 <td><input name=shiptoemail size=35 value="$form->{shiptoemail}"></td>
2163 <input type=hidden name=nextsub value=$nextsub>
2167 map({ delete $form->{$_} } (@shipto_vars, qw(header)));
2168 $form->{title} = $title;
2170 foreach $key (keys %$form) {
2171 $form->{$key} =~ s/\"/"/g;
2172 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2180 <input class=submit type=submit name=action value="|
2181 . $locale->text('Continue') . qq|">
2188 $lxdebug->leave_sub();
2192 $lxdebug->enter_sub();
2197 $form->{old_callback} = $form->escape($form->{callback}, 1);
2198 $form->{callback} = $form->escape("$form->{script}?action=display_form", 1);
2199 $form->{old_callback} = $form->escape($form->{old_callback}, 1);
2202 delete $form->{action};
2203 $customer = $form->{customer};
2204 map { $form->{"old_$_"} = $form->{"${_}_$row"} } qw(partnumber description);
2206 # save all other form variables in a previousform variable
2207 $form->{row} = $row;
2208 foreach $key (keys %$form) {
2211 $form->{$key} =~ s/&/%26/g;
2212 $previousform .= qq|$key=$form->{$key}&|;
2215 $previousform = $form->escape($previousform, 1);
2217 $form->{script} = "licenses.pl";
2219 map { $form->{$_} = $form->{"old_$_"} } qw(partnumber description);
2220 map { $form->{$_} = $form->escape($form->{$_}, 1) }
2221 qw(partnumber description);
2223 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|;
2226 $lxdebug->leave_sub();
2229 sub relink_accounts {
2230 $lxdebug->enter_sub();
2232 $form->{"taxaccounts"} =~ s/\s*$//;
2233 $form->{"taxaccounts"} =~ s/^\s*//;
2234 foreach my $accno (split(/\s*/, $form->{"taxaccounts"})) {
2235 map({ delete($form->{"${accno}_${_}"}); } qw(rate description taxnumber));
2237 $form->{"taxaccounts"} = "";
2239 for (my $i = 1; $i <= $form->{"rowcount"}; $i++) {
2240 if ($form->{"id_$i"}) {
2241 IC->retrieve_accounts(\%myconfig, $form, $form->{"id_$i"}, $i, 1);
2245 $lxdebug->leave_sub();
2250 $lxdebug->enter_sub();
2252 $form->get_duedate(\%myconfig);
2255 $result = "$form->{duedate}";
2258 $lxdebug->leave_sub();