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')
155 if ($form->{"type"} eq "purchase_order") {
157 qq|<th align=left nowrap width=5 class=listheading>|
158 . $locale->text('Ship rcvd')
162 qq|<th align=left nowrap width=5 class=listheading>|
163 . $locale->text('Ship')
167 qq|<th align=left nowrap width=5 class=listheading>|
168 . $locale->text('Qty')
171 qq|<th align=left nowrap width=5 class=listheading>|
172 . $locale->text('Unit')
174 $column_data{license} =
175 qq|<th align=left nowrap width=10 class=listheading>|
176 . $locale->text('License')
178 $column_data{serialnr} =
179 qq|<th align=left nowrap width=10 class=listheading>|
180 . $locale->text('Serial No.')
182 $column_data{projectnr} =
183 qq|<th align=left nowrap width=10 class=listheading>|
184 . $locale->text('Project')
186 $column_data{sellprice} =
187 qq|<th align=left nowrap width=15 class=listheading>|
188 . $locale->text('Price')
190 $column_data{sellprice_pg} =
191 qq|<th align=left nowrap width=15 class=listheading>|
192 . $locale->text('Pricegroup')
194 $column_data{discount} =
195 qq|<th align=left class=listheading>|
196 . $locale->text('Discount')
198 $column_data{linetotal} =
199 qq|<th align=left nowrap width=10 class=listheading>|
200 . $locale->text('Extended')
203 qq|<th align=left nowrap width=10 class=listheading>|
204 . $locale->text('Bin')
206 ############## ENDE Neueintrag ##################
208 $myconfig{"show_form_details"} = 1
209 unless (defined($myconfig{"show_form_details"}));
210 $form->{"show_details"} = $myconfig{"show_form_details"}
211 unless (defined($form->{"show_details"}));
212 $form->{"show_details"} = $form->{"show_details"} ? 1 : 0;
213 my $show_details_new = 1 - $form->{"show_details"};
214 my $show_details_checked = $form->{"show_details"} ? "checked" : "";
219 <input type="hidden" name="show_details" value="$form->{show_details}">
220 <input type="checkbox" id="cb_show_details" onclick="show_form_details($show_details_new);" $show_details_checked>
221 <label for="cb_show_details">| . $locale->text("Show details") . qq|</label><br>
223 <tr class=listheading>|;
225 map { print "\n$column_data{$_}" } @column_index;
231 $runningnumber = $locale->text('No.');
232 $deliverydate = $locale->text('Delivery Date');
233 $serialnumber = $locale->text('Serial No.');
234 $projectnumber = $locale->text('Project');
235 $partsgroup = $locale->text('Group');
236 $reqdate = $locale->text('Reqdate');
238 $delvar = 'deliverydate';
240 if ($form->{type} =~ /_order$/ || $form->{type} =~ /_quotation$/) {
241 $deliverydate = $locale->text('Required by');
245 my %projectnumber_labels = ();
246 my @projectnumber_values = ("");
247 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
248 push(@projectnumber_values, $item->{"id"});
249 $projectnumber_labels{$item->{"id"}} = $item->{"projectnumber"};
252 for $i (1 .. $numrows) {
257 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
258 } qw(qty ship discount sellprice price_new price_old) unless ($form->{simple_save});
260 if (!$form->{"unit_old_$i"}) {
261 # Neue Ware aus der Datenbank. In diesem Fall ist unit_$i die
262 # Einheit, wie sie in den Stammdaten hinterlegt wurde.
263 # Es sollte also angenommen werden, dass diese ausgewaehlt war.
264 $form->{"unit_old_$i"} = $form->{"unit_$i"};
269 # Die zuletzt ausgewaehlte mit der aktuell ausgewaehlten Einheit
270 # vergleichen und bei Unterschied den Preis entsprechend umrechnen.
271 $form->{"selected_unit_$i"} = $form->{"unit_$i"} unless ($form->{"selected_unit_$i"});
273 my $check_units = $form->{"inventory_accno_$i"} ? $dimension_units : $service_units;
274 if (!$check_units->{$form->{"selected_unit_$i"}} ||
275 ($check_units->{$form->{"selected_unit_$i"}}->{"base_unit"} ne
276 $all_units->{$form->{"unit_old_$i"}}->{"base_unit"})) {
277 # Die ausgewaehlte Einheit ist fuer diesen Artikel nicht gueltig
278 # (z.B. Dimensionseinheit war ausgewaehlt, es handelt sich aber
279 # um eine Dienstleistung). Dann keinerlei Umrechnung vornehmen.
280 $form->{"unit_old_$i"} = $form->{"selected_unit_$i"} = $form->{"unit_$i"};
282 if ((!$form->{"prices_$i"}) || ($form->{"new_pricegroup_$i"} == $form->{"old_pricegroup_$i"})) {
283 if ($form->{"unit_old_$i"} ne $form->{"selected_unit_$i"}) {
285 if (defined($all_units->{$form->{"unit_old_$i"}}->{"factor"}) &&
286 $all_units->{$form->{"unit_old_$i"}}->{"factor"}) {
287 $basefactor = $all_units->{$form->{"selected_unit_$i"}}->{"factor"} /
288 $all_units->{$form->{"unit_old_$i"}}->{"factor"};
290 $form->{"sellprice_$i"} *= $basefactor;
291 $form->{"unit_old_$i"} = $form->{"selected_unit_$i"};
294 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
296 $decimalplaces = ($dec > 2) ? $dec : 2;
300 $form->{"sellprice_$i"} * $form->{"discount_$i"} / 100,
304 $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
305 $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
307 # convert " to "
308 map { $form->{"${_}_$i"} =~ s/\"/"/g }
309 qw(partnumber description unit unit_old);
311 ########################################
312 # Eintrag fuer Version 2.2.0 geaendert #
313 # neue Optik im Rechnungsformular #
314 ########################################
315 $column_data{runningnumber} =
316 qq|<td><input name="runningnumber_$i" size=5 value=$i></td>|; # HuT
317 ############## ENDE Neueintrag ##################
319 $column_data{partnumber} =
320 qq|<td><input name="partnumber_$i" size=12 value="$form->{"partnumber_$i"}"></td>|;
322 if (($rows = $form->numtextrows($form->{"description_$i"}, 30, 6)) > 1) {
323 $column_data{description} =
324 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>|;
326 $column_data{description} =
327 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>|;
330 (my $qty_dec) = ($form->{"qty_$i"} =~ /\.(\d+)/);
331 $qty_dec = length $qty_dec;
334 qq|<td align=right><input name="qty_$i" size=5 value=|
335 . $form->format_amount(\%myconfig, $form->{"qty_$i"}, $qty_dec) .qq|>|;
336 if ($form->{"formel_$i"}) {
337 $column_data{qty} .= qq|<button type="button" onclick="calculate_qty_selection_window('qty_$i','alu_$i', 'formel_$i', $i)">| . $locale->text('*/') . qq|</button>
338 <input type=hidden name="formel_$i" value="$form->{"formel_$i"}"><input type=hidden name="alu_$i" value="$form->{"alu_$i"}"></td>|;
341 qq|<td align=right><input name="ship_$i" size=5 value=|
342 . $form->format_amount(\%myconfig, $form->{"ship_$i"})
345 my $is_part = $form->{"inventory_accno_$i"};
346 my $is_assigned = $form->{"id_$i"};
347 my $this_unit = $form->{"unit_$i"};
348 if ($form->{"selected_unit_$i"} && $this_unit &&
349 $all_units->{$form->{"selected_unit_$i"}} && $all_units->{$this_unit} &&
350 ($all_units->{$form->{"selected_unit_$i"}}->{"base_unit"} eq $all_units->{$this_unit}->{"base_unit"})) {
351 $this_unit = $form->{"selected_unit_$i"};
352 } elsif (!$is_assigned ||
353 ($is_part && !$this_unit && ($all_units->{$this_unit} && ($all_units->{$this_unit}->{"base_unit"} eq $all_units->{"kg"}->{"base_unit"})))) {
357 $column_data{"unit"} = "<td>" .
358 ($qty_readonly ? " " :
359 AM->unit_select_html($is_part ? $dimension_units :
360 $is_assigned ? $service_units : $all_units,
361 "unit_$i", $this_unit,
362 $is_assigned ? $form->{"unit_$i"} : undef))
365 # build in drop down list for pricesgroups
366 if ($form->{"prices_$i"}) {
367 if ($form->{"new_pricegroup_$i"} != $form->{"old_pricegroup_$i"}) {
368 $price_tmp = $form->format_amount(\%myconfig, $form->{"price_new_$i"}, $decimalplaces);
370 $price_tmp = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
373 $column_data{sellprice_pg} =
374 qq|<td align=right><select name="sellprice_pg_$i">$form->{"prices_$i"}</select></td>|;
375 $column_data{sellprice} =
376 qq|<td><input name="sellprice_$i" size=10 value=$price_tmp></td>|;
379 # for last row and report
380 # set pricegroup drop down list from report menu
381 if ($form->{"sellprice_$i"} != 0) {
383 qq|<option value="$form->{"sellprice_$i"}--$form->{"pricegroup_id_$i"}" selected>$form->{"pricegroup_$i"}</option>\n|;
385 $form->{"pricegroup_old_$i"} = $form->{"pricegroup_id_$i"};
387 $column_data{sellprice_pg} =
388 qq|<td align=right><select name="sellprice_pg_$i">$prices</select></td>|;
393 $column_data{sellprice_pg} = qq|<td align=right> </td>|;
396 $column_data{sellprice} =
397 qq|<td><input name="sellprice_$i" size=10 value=|
398 . $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
402 $column_data{discount} =
403 qq|<td align=right><input name="discount_$i" size=3 value=|
404 . $form->format_amount(\%myconfig, $form->{"discount_$i"})
406 $column_data{linetotal} =
408 . $form->format_amount(\%myconfig, $linetotal, 2)
410 $column_data{bin} = qq|<td>$form->{"bin_$i"}</td>|;
412 ########################################
413 # Eintrag fuer Version 2.2.0 geaendert #
414 # neue Optik im Rechnungsformular #
415 ########################################
416 # if ($lizenzen && $form->{type} eq "invoice" && $form->{vc} eq "customer") {
417 # $column_data{license} = qq|<td><select name="licensenumber_$i">$form->{"lizenzen_$i"}></select></td>|;
420 # if ($form->{type} !~ /_quotation/) {
421 # $column_data{serialnr} = qq|<td><input name="serialnumber_$i" size=10 value="$form->{"serialnumber_$i"}"></td>|;
424 # $column_data{projectnr} = qq|<td><input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}"></td>|;
425 ############## ENDE Neueintrag ##################
429 <tr valign=top class=listrow$j>|;
431 map { print "\n$column_data{$_}" } @column_index;
436 <input type=hidden name="orderitems_id_$i" value=$form->{"orderitems_id_$i"}>
437 <input type=hidden name="bo_$i" value=$form->{"bo_$i"}>
439 <input type=hidden name="pricegroup_old_$i" value=$form->{"pricegroup_old_$i"}>
440 <input type=hidden name="price_old_$i" value=$form->{"price_old_$i"}>
441 <input type=hidden name="unit_old_$i" value="| . $form->quote($form->{"selected_unit_$i"}) . qq|">
442 <input type=hidden name="price_new_$i" value=|
443 . $form->format_amount(\%myconfig, $form->{"price_new_$i"}) . qq|>
445 <input type=hidden name="id_$i" value=$form->{"id_$i"}>
446 <input type=hidden name="inventory_accno_$i" value=$form->{"inventory_accno_$i"}>
447 <input type=hidden name="bin_$i" value="$form->{"bin_$i"}">
448 <input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">
449 <input type=hidden name="partnotes_$i" value="| . $form->quote($form->{"partnotes_$i"}) . qq|">
450 <input type=hidden name="income_accno_$i" value=$form->{"income_accno_$i"}>
451 <input type=hidden name="expense_accno_$i" value=$form->{"expense_accno_$i"}>
452 <input type=hidden name="listprice_$i" value="$form->{"listprice_$i"}">
453 <input type=hidden name="assembly_$i" value="$form->{"assembly_$i"}">
454 <input type=hidden name="taxaccounts_$i" value="$form->{"taxaccounts_$i"}">
455 <input type=hidden name="ordnumber_$i" value="$form->{"ordnumber_$i"}">
456 <input type=hidden name="transdate_$i" value="$form->{"transdate_$i"}">
457 <input type=hidden name="cusordnumber_$i" value="$form->{"cusordnumber_$i"}">
458 <input type=hidden name="longdescription_$i" value="| . $form->quote($form->{"longdescription_$i"}) . qq|">
459 <input type=hidden name="basefactor_$i" value="$form->{"basefactor_$i"}">
463 ########################################
464 # Eintrag fuer Version 2.2.0 geaendert #
465 # neue Optik im Rechnungsformular #
466 ########################################
469 'style="display:none;"' if (!$form->{"show_details"});
473 <tr class=listrow$j $row_style_attr>
474 <td colspan=$colspan>
476 if ($lizenzen && $form->{type} eq "invoice" && $form->{vc} eq "customer") {
477 my $selected = $form->{"licensenumber_$i"};
479 $form->{"lizenzen_$i"} =~ s/ selected//g;
480 $form->{"lizenzen_$i"} =~
481 s/value="${selected}"\>/value="${selected}" selected\>/;
482 $lizenzen_quoted = $form->{"lizenzen_$i"};
483 $lizenzen_quoted =~ s/\"/"/g;
485 <b>Lizenz\#</b> <select name="licensenumber_$i" size=1>
486 $form->{"lizenzen_$i"}
488 <input type=hidden name="lizenzen_$i" value="${lizenzen_quoted}">
491 if ($form->{type} !~ /_quotation/) {
493 <b>$serialnumber</b> <input name="serialnumber_$i" size=15 value="$form->{"serialnumber_$i"}">|;
496 print qq|<b>$projectnumber</b> | .
497 NTI($cgi->popup_menu('-name' => "project_id_$i",
498 '-values' => \@projectnumber_values,
499 '-labels' => \%projectnumber_labels,
500 '-default' => $form->{"project_id_$i"}));
502 if ($form->{type} eq 'invoice' or $form->{type} =~ /order/) {
504 ($form->{type} eq 'invoice')
506 : 'reqdate'; # invoice uses a different term for the same thing.
508 <b>${$reqdate_term}</b> <input name="${reqdate_term}_$i" size=11 value="$form->{"${reqdate_term}_$i"}">
511 my $subtotalchecked = ($form->{"subtotal_$i"}) ? "checked" : "";
513 <b>|.$locale->text('Subtotal').qq|</b> <input type="checkbox" name="subtotal_$i" value="1" "$subtotalchecked">
519 ############## ENDE Neueintrag ##################
521 map { $form->{"${_}_base"} += $linetotal }
522 (split(/ /, $form->{"taxaccounts_$i"}));
524 $form->{invsubtotal} += $linetotal;
533 $lxdebug->leave_sub();
536 ##################################################
537 # build html-code for pricegroups in variable $form->{prices_$j}
540 $lxdebug->enter_sub();
541 my $rowcount = shift;
542 for $j (1 .. $rowcount) {
543 my $pricegroup_old = $form->{"pricegroup_old_$i"};
544 if ($form->{PRICES}{$j}) {
546 $prices = '<option value="--">' . $locale->text("none (pricegroup)") . '</option>';
548 foreach $item (@{ $form->{PRICES}{$j} }) {
550 #$price = $form->round_amount($myconfig, $item->{price}, 5);
551 #$price = $form->format_amount($myconfig, $item->{price}, 2);
552 $price = $item->{price};
553 $pricegroup_id = $item->{pricegroup_id};
554 $pricegroup = $item->{pricegroup};
556 # build drop down list for pricegroups
558 qq|<option value="$price--$pricegroup_id"$item->{selected}>$pricegroup</option>\n|;
563 # $form->{"${_}_$j"} =
564 # $form->format_amount(\%myconfig, $form->{"${_}_$j"})
565 # } qw(sellprice price_new price_old);
567 # set new selectedpricegroup_id and prices for "Preis"
568 if ($item->{selected} && ($pricegroup_id != 0)) {
569 $form->{"pricegroup_old_$j"} = $pricegroup_id;
570 $form->{"price_new_$j"} = $price;
571 $form->{"sellprice_$j"} = $price;
573 if ($pricegroup_id == 0) {
574 $form->{"price_new_$j"} = $form->{"sellprice_$j"};
577 $form->{"prices_$j"} = $prices;
580 $lxdebug->leave_sub();
584 $lxdebug->enter_sub();
585 @column_index = qw(ndx partnumber description onhand unit sellprice);
587 $column_data{ndx} = qq|<th> </th>|;
588 $column_data{partnumber} =
589 qq|<th class=listheading>| . $locale->text('Number') . qq|</th>|;
590 $column_data{description} =
591 qq|<th class=listheading>| . $locale->text('Part Description') . qq|</th>|;
592 $column_data{sellprice} =
593 qq|<th class=listheading>| . $locale->text('Price') . qq|</th>|;
594 $column_data{onhand} =
595 qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|;
597 qq|<th class=listheading>| . $locale->text('Unit') . qq|</th>|;
598 # list items with radio button on a form
601 $title = $locale->text('Select from one of the items below');
602 $colspan = $#column_index + 1;
607 <form method=post action=$form->{script}>
611 <th class=listtop colspan=$colspan>$title</th>
614 <tr class=listheading>|;
616 map { print "\n$column_data{$_}" } @column_index;
621 foreach $ref (@{ $form->{item_list} }) {
622 $checked = ($i++) ? "" : "checked";
625 if ($ref->{inventory_accno} > 0) {
626 $ref->{"lizenzen"} = qq|<option></option>|;
627 foreach $item (@{ $form->{LIZENZEN}{ $ref->{"id"} } }) {
628 $ref->{"lizenzen"} .=
629 qq|<option value=\"$item->{"id"}\">$item->{"licensenumber"}</option>|;
631 $ref->{"lizenzen"} .= qq|<option value=-1>Neue Lizenz</option>|;
632 $ref->{"lizenzen"} =~ s/\"/"/g;
636 map { $ref->{$_} =~ s/\"/"/g } qw(partnumber description unit);
640 $form->round_amount($ref->{sellprice} * (1 - $form->{tradediscount}), 2);
642 qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
643 $column_data{partnumber} =
644 qq|<td><input name="new_partnumber_$i" type=hidden value="$ref->{partnumber}">$ref->{partnumber}</td>|;
645 $column_data{description} =
646 qq|<td><input name="new_description_$i" type=hidden value="$ref->{description}">$ref->{description}</td>|;
647 $column_data{sellprice} =
648 qq|<td align=right><input name="new_sellprice_$i" type=hidden value=$ref->{sellprice}>|
649 . $form->format_amount(\%myconfig, $ref->{sellprice}, 2, " ")
651 $column_data{onhand} =
652 qq|<td align=right><input name="new_onhand_$i" type=hidden value=$ref->{onhand}>|
653 . $form->format_amount(\%myconfig, $ref->{onhand}, '', " ")
656 qq|<td>$ref->{unit}</td>|;
660 <tr class=listrow$j>|;
662 map { print "\n$column_data{$_}" } @column_index;
667 <input name="new_bin_$i" type=hidden value="$ref->{bin}">
668 <input name="new_listprice_$i" type=hidden value=$ref->{listprice}>
669 <input name="new_inventory_accno_$i" type=hidden value=$ref->{inventory_accno}>
670 <input name="new_income_accno_$i" type=hidden value=$ref->{income_accno}>
671 <input name="new_expense_accno_$i" type=hidden value=$ref->{expense_accno}>
672 <input name="new_unit_$i" type=hidden value="$ref->{unit}">
673 <input name="new_weight_$i" type=hidden value="$ref->{weight}">
674 <input name="new_assembly_$i" type=hidden value="$ref->{assembly}">
675 <input name="new_taxaccounts_$i" type=hidden value="$ref->{taxaccounts}">
676 <input name="new_partsgroup_$i" type=hidden value="$ref->{partsgroup}">
677 <input name="new_formel_$i" type=hidden value="$ref->{formel}">
678 <input name="new_longdescription_$i" type=hidden value="| . Q($ref->{longdescription}) . qq|">
679 <input name="new_not_discountable_$i" type=hidden value="$ref->{not_discountable}">
680 <input name="new_part_payment_id_$i" type=hidden value="$ref->{part_payment_id}">
681 <input name="new_partnotes_$i" type="hidden" value="| . Q($ref->{"partnotes"}) . qq|">
683 <input name="new_id_$i" type=hidden value=$ref->{id}>
688 <input name="new_lizenzen_$i" type=hidden value="$ref->{lizenzen}">
695 <tr><td colspan=8><hr size=3 noshade></td></tr>
698 <input name=lastndx type=hidden value=$i>
702 # delete action variable
703 map { delete $form->{$_} } qw(action item_list header);
705 # save all other form variables
706 foreach $key (keys %${form}) {
707 $form->{$key} =~ s/\"/"/g;
708 print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
712 <input type=hidden name=nextsub value=item_selected>
715 <input class=submit type=submit name=action value="|
716 . $locale->text('Continue') . qq|">
723 $lxdebug->leave_sub();
727 $lxdebug->enter_sub();
729 # replace the last row with the checked row
730 $i = $form->{rowcount};
731 $i = $form->{assembly_rows} if ($form->{item} eq 'assembly');
737 #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
738 #$form->{"sellprice_$i"} = $form->{"sellprice_$i"};
740 # if there was a price entered, override it
741 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
743 map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} }
744 qw(id partnumber description sellprice listprice inventory_accno
745 income_accno expense_accno bin unit weight assembly taxaccounts
746 partsgroup formel longdescription not_discountable partnotes);
747 if ($form->{"part_payment_id_$i"} ne "") {
748 $form->{payment_id} = $form->{"part_payment_id_$i"};
752 map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} } qw(lizenzen);
755 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
757 $decimalplaces = ($dec > 2) ? $dec : 2;
760 $form->{"sellprice_$i"} = $sellprice;
763 # if there is an exchange rate adjust sellprice
764 if (($form->{exchangerate} * 1) != 0) {
765 $form->{"sellprice_$i"} /= $form->{exchangerate};
766 $form->{"sellprice_$i"} =
767 $form->round_amount($form->{"sellprice_$i"}, $decimalplaces);
771 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
772 qw(sellprice listprice weight);
774 $form->{sellprice} += ($form->{"sellprice_$i"} * $form->{"qty_$i"});
775 $form->{weight} += ($form->{"weight_$i"} * $form->{"qty_$i"});
777 if ($form->{"not_discountable_$i"}) {
778 $form->{"discount_$i"} = 0;
782 $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) *
784 map { $form->{"${_}_base"} += $amount }
785 (split / /, $form->{"taxaccounts_$i"});
786 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /,
787 $form->{"taxaccounts_$i"}
788 if !$form->{taxincluded};
790 $form->{creditremaining} -= $amount;
792 $form->{"runningnumber_$i"} = $i;
794 # delete all the new_ variables
795 for $i (1 .. $form->{lastndx}) {
796 map { delete $form->{"new_${_}_$i"} }
797 qw(partnumber description sellprice bin listprice inventory_accno income_accno expense_accno unit assembly taxaccounts id);
800 map { delete $form->{$_} } qw(ndx lastndx nextsub);
805 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces)
806 } qw(sellprice listprice) if $form->{item} ne 'assembly';
808 # get pricegroups for parts
809 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
811 # build up html code for prices_$i
812 set_pricegroup($form->{rowcount});
816 $lxdebug->leave_sub();
820 $lxdebug->enter_sub();
823 $form->{old_callback} = $form->escape($form->{callback}, 1);
824 $form->{callback} = $form->escape("$form->{script}?action=display_form", 1);
827 delete $form->{action};
829 # save all other form variables in a previousform variable
830 foreach $key (keys %$form) {
833 $form->{$key} =~ s/&/%26/g;
834 $previousform .= qq|$key=$form->{$key}&|;
837 $previousform = $form->escape($previousform, 1);
839 $i = $form->{rowcount};
840 map { $form->{"${_}_$i"} =~ s/\"/"/g } qw(partnumber description);
847 <h4 class=error>| . $locale->text('Item not on file!') . qq|
850 | . $locale->text('What type of item is this?') . qq|</h4>
852 <form method=post action=ic.pl>
856 <input class=radio type=radio name=item value=part checked> |
857 . $locale->text('Part') . qq|<br>
858 <input class=radio type=radio name=item value=service> |
859 . $locale->text('Service')
862 <input type=hidden name=previousform value="$previousform">
863 <input type=hidden name=partnumber value="$form->{"partnumber_$i"}">
864 <input type=hidden name=description value="$form->{"description_$i"}">
865 <input type=hidden name=rowcount value=$form->{rowcount}>
866 <input type=hidden name=taxaccount2 value=$form->{taxaccounts}>
867 <input type=hidden name=vc value=$form->{vc}>
869 <input type=hidden name=path value=$form->{path}>
870 <input type=hidden name=login value=$form->{login}>
871 <input type=hidden name=password value=$form->{password}>
873 <input type=hidden name=nextsub value=add>
876 <input class=submit type=submit name=action value="|
877 . $locale->text('Continue') . qq|">
884 $lxdebug->leave_sub();
888 $lxdebug->enter_sub();
892 my $new_rowcount = $form->{"rowcount"} * 1 + 1;
893 $form->{"project_id_${new_rowcount}"} = $form->{"globalproject_id"};
895 $form->language_payment(\%myconfig);
897 # if we have a display_form
898 if ($form->{display_form}) {
899 &{"$form->{display_form}"};
903 Common::webdav_folder($form) if ($webdav);
905 # if ( $form->{print_and_post}
906 # && $form->{second_run}
907 # && ($form->{action} eq "display_form")) {
908 # for (keys %$form) { $old_form->{$_} = $form->{$_} }
909 # $old_form->{rowcount}++;
911 # #$form->{rowcount}--;
912 # #$form->{rowcount}--;
914 # $form->{print_and_post} = 0;
916 # &print_form($old_form);
920 # $form->{action} = "";
921 # $form->{resubmit} = 0;
923 # if ($form->{print_and_post} && !$form->{second_run}) {
924 # $form->{second_run} = 1;
925 # $form->{action} = "display_form";
926 # $form->{rowcount}--;
927 # my $rowcount = $form->{rowcount};
929 # # get pricegroups for parts
930 # IS->get_pricegroups_for_parts(\%myconfig, \%$form);
932 # # build up html code for prices_$i
933 # set_pricegroup($rowcount);
935 # $form->{resubmit} = 1;
940 $numrows = ++$form->{rowcount};
941 $subroutine = "display_row";
943 if ($form->{item} eq 'part') {
945 #set preisgruppenanzahl
946 $numrows = $form->{price_rows};
947 $subroutine = "price_row";
949 &{$subroutine}($numrows);
951 $numrows = ++$form->{makemodel_rows};
952 $subroutine = "makemodel_row";
954 if ($form->{item} eq 'assembly') {
955 $numrows = $form->{price_rows};
956 $subroutine = "price_row";
958 &{$subroutine}($numrows);
960 $numrows = ++$form->{makemodel_rows};
961 $subroutine = "makemodel_row";
963 # create makemodel rows
964 &{$subroutine}($numrows);
966 $numrows = ++$form->{assembly_rows};
967 $subroutine = "assembly_row";
969 if ($form->{item} eq 'service') {
970 $numrows = $form->{price_rows};
971 $subroutine = "price_row";
973 &{$subroutine}($numrows);
979 &{$subroutine}($numrows) if $numrows;
983 $lxdebug->leave_sub();
987 $lxdebug->enter_sub();
991 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)
995 # remove any makes or model rows
996 if ($form->{item} eq 'part') {
997 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
998 qw(listprice sellprice lastcost weight rop);
1000 @flds = (make, model);
1001 for my $i (1 .. ($form->{makemodel_rows})) {
1002 if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
1006 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1011 $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
1012 $form->{makemodel_rows} = $count;
1014 } elsif ($form->{item} eq 'assembly') {
1016 $form->{sellprice} = 0;
1017 $form->{weight} = 0;
1018 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1019 qw(listprice rop stock);
1022 qw(id qty unit bom partnumber description sellprice weight runningnumber partsgroup);
1024 for my $i (1 .. ($form->{assembly_rows} - 1)) {
1025 if ($form->{"qty_$i"}) {
1029 $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
1031 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1033 #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
1035 $form->{sellprice} += ($form->{"qty_$i"} * $form->{"sellprice_$i"});
1036 $form->{weight} += ($form->{"qty_$i"} * $form->{"weight_$i"});
1041 $form->{sellprice} = $form->round_amount($form->{sellprice}, 2);
1043 $form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows});
1044 $form->{assembly_rows} = $count;
1047 @flds = qw(make model);
1050 for my $i (1 .. ($form->{makemodel_rows})) {
1051 if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
1055 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1060 $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
1061 $form->{makemodel_rows} = $count;
1065 # this section applies to invoices and orders
1066 # remove any empty numbers
1067 if ($form->{rowcount}) {
1068 for my $i (1 .. $form->{rowcount} - 1) {
1069 if ($form->{"partnumber_$i"}) {
1073 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1076 if ($form->{"licensenumber_$i"} == -1) {
1084 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
1085 $form->{rowcount} = $count;
1087 $form->{creditremaining} -= &invoicetotal;
1094 if ( $form->{type} =~ (/sales_quotation/)
1095 or (($form->{level} =~ /Sales/) and ($form->{type} =~ /invoice/))
1096 or (($form->{level} eq undef) and ($form->{type} =~ /invoice/))
1097 or ($form->{type} =~ /sales_order/)) {
1099 # get pricegroups for parts
1100 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1102 # build up html code for prices_$i
1103 set_pricegroup($form->{rowcount});
1109 $lxdebug->leave_sub();
1113 $lxdebug->enter_sub();
1115 $form->{oldinvtotal} = 0;
1117 # add all parts and deduct paid
1118 map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
1120 my ($amount, $sellprice, $discount, $qty);
1122 for my $i (1 .. $form->{rowcount}) {
1123 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1124 $discount = $form->parse_amount(\%myconfig, $form->{"discount_$i"});
1125 $qty = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
1127 #($form->{"sellprice_$i"}, $form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
1129 $amount = $sellprice * (1 - $discount / 100) * $qty;
1130 map { $form->{"${_}_base"} += $amount }
1131 (split (/ /, $form->{"taxaccounts_$i"}));
1132 $form->{oldinvtotal} += $amount;
1135 map { $form->{oldinvtotal} += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1136 split(/ /, $form->{taxaccounts})
1137 if !$form->{taxincluded};
1139 $form->{oldtotalpaid} = 0;
1140 for $i (1 .. $form->{paidaccounts}) {
1141 $form->{oldtotalpaid} += $form->{"paid_$i"};
1144 $lxdebug->leave_sub();
1147 return ($form->{oldinvtotal} - $form->{oldtotalpaid});
1150 sub validate_items {
1151 $lxdebug->enter_sub();
1153 # check if items are valid
1154 if ($form->{rowcount} == 1) {
1159 for $i (1 .. $form->{rowcount} - 1) {
1160 $form->isblank("partnumber_$i",
1161 $locale->text('Number missing in Row') . " $i");
1164 $lxdebug->leave_sub();
1168 $lxdebug->enter_sub();
1169 if ($form->{second_run}) {
1170 $form->{print_and_post} = 0;
1172 $form->{ordnumber} = $form->{invnumber};
1174 map { delete $form->{$_} } qw(id printed emailed queued);
1175 if ($form->{script} eq 'ir.pl' || $form->{type} eq 'request_quotation') {
1176 $form->{title} = $locale->text('Add Purchase Order');
1177 $form->{vc} = 'vendor';
1178 $form->{type} = 'purchase_order';
1181 if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_quotation') {
1182 $form->{title} = $locale->text('Add Sales Order');
1183 $form->{vc} = 'customer';
1184 $form->{type} = 'sales_order';
1187 $form->{script} = 'oe.pl';
1189 $form->{shipto} = 1;
1191 $form->{rowcount}--;
1193 $form->{cp_id} *= 1;
1195 require "$form->{path}/$form->{script}";
1196 my $script = $form->{"script"};
1198 $script =~ s|.pl$||;
1199 $locale = new Locale($language, $script);
1201 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1203 $currency = $form->{currency};
1207 $form->{currency} = $currency;
1208 $form->{exchangerate} = "";
1209 $form->{forex} = "";
1210 $form->{exchangerate} = $exchangerate
1214 $form->check_exchangerate(
1215 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1218 for $i (1 .. $form->{rowcount}) {
1219 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
1220 $form->{"${_}_${i}"})
1221 if ($form->{"${_}_${i}"}) }
1222 qw(ship qty sellprice listprice basefactor));
1228 $lxdebug->leave_sub();
1232 $lxdebug->enter_sub();
1233 if ($form->{second_run}) {
1234 $form->{print_and_post} = 0;
1236 map { delete $form->{$_} } qw(id printed emailed queued);
1238 if ($form->{script} eq 'ir.pl' || $form->{type} eq 'purchase_order') {
1239 $form->{title} = $locale->text('Add Request for Quotation');
1240 $form->{vc} = 'vendor';
1241 $form->{type} = 'request_quotation';
1244 if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_order') {
1245 $form->{title} = $locale->text('Add Quotation');
1246 $form->{vc} = 'customer';
1247 $form->{type} = 'sales_quotation';
1251 $form->{cp_id} *= 1;
1253 $form->{script} = 'oe.pl';
1255 $form->{shipto} = 1;
1257 $form->{rowcount}--;
1259 require "$form->{path}/$form->{script}";
1261 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1263 $currency = $form->{currency};
1267 $form->{currency} = $currency;
1268 $form->{exchangerate} = "";
1269 $form->{forex} = "";
1270 $form->{exchangerate} = $exchangerate
1274 $form->check_exchangerate(
1275 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1278 for $i (1 .. $form->{rowcount}) {
1279 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
1280 $form->{"${_}_${i}"})
1281 if ($form->{"${_}_${i}"}) }
1282 qw(ship qty sellprice listprice basefactor));
1288 $lxdebug->leave_sub();
1291 sub request_for_quotation {
1296 $lxdebug->enter_sub();
1297 if ($form->{second_run}) {
1298 $form->{print_and_post} = 0;
1299 $form->{resubmit} = 0;
1301 if ($myconfig{role} eq 'admin') {
1304 <th align="right" nowrap="true">| . $locale->text('Bcc') . qq|</th>
1305 <td><input name="bcc" size="30" value="| . Q($form->{bcc}) . qq|"></td>
1310 if ($form->{formname} =~ /(pick|packing|bin)_list/) {
1311 $form->{email} = $form->{shiptoemail} if $form->{shiptoemail};
1314 if ($form->{"cp_id"} && !$form->{"email"}) {
1315 CT->get_contact(\%myconfig, $form);
1316 $form->{"email"} = $form->{"cp_email"};
1319 $name = $form->{ $form->{vc} };
1321 $title = $locale->text('E-mail') . " $name";
1323 $form->{oldmedia} = $form->{media};
1324 $form->{media} = "email";
1326 my %formname_translations =
1328 "bin_list" => $locale->text('Bin List'),
1329 "credit_note" => $locale->text('Credit Note'),
1330 "invoice" => $locale->text('Invoice'),
1331 "packing_list" => $locale->text('Packing List'),
1332 "pick_list" => $locale->text('Pick List'),
1333 "proforma" => $locale->text('Proforma Invoice'),
1334 "purchase_order" => $locale->text('Purchase Order'),
1335 "request_quotation" => $locale->text('RFQ'),
1336 "sales_order" => $locale->text('Confirmation'),
1337 "sales_quotation" => $locale->text('Quotation'),
1338 "storno_invoice" => $locale->text('Storno Invoice'),
1339 "storno_packing_list" => $locale->text('Storno Packing List'),
1342 my $attachment_filename = $formname_translations{$form->{"formname"}};
1345 if (grep({ $form->{"type"} eq $_ } qw(invoice credit_note))) {
1347 } elsif ($form->{"type"} =~ /_quotation$/) {
1353 if ($attachment_filename && $form->{"${prefix}number"}) {
1354 $attachment_filename .= "_" . $form->{"${prefix}number"} .
1355 ($form->{"format"} =~ /pdf/i ? ".pdf" :
1356 $form->{"format"} =~ /postscript/i ? ".ps" :
1357 $form->{"format"} =~ /opendocument/i ? ".odt" :
1358 $form->{"format"} =~ /html/i ? ".html" : "");
1359 $attachment_filename =~ s/ /_/g;