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 #######################################################################
36 # any custom scripts for this one
37 if (-f "$form->{path}/custom_io.pl") {
38 eval { require "$form->{path}/custom_io.pl"; };
40 if (-f "$form->{path}/$form->{login}_io.pl") {
41 eval { require "$form->{path}/$form->{login}_io.pl"; };
48 # this is for our long dates
49 # $locale->text('January')
50 # $locale->text('February')
51 # $locale->text('March')
52 # $locale->text('April')
53 # $locale->text('May ')
54 # $locale->text('June')
55 # $locale->text('July')
56 # $locale->text('August')
57 # $locale->text('September')
58 # $locale->text('October')
59 # $locale->text('November')
60 # $locale->text('December')
62 # this is for our short month
63 # $locale->text('Jan')
64 # $locale->text('Feb')
65 # $locale->text('Mar')
66 # $locale->text('Apr')
67 # $locale->text('May')
68 # $locale->text('Jun')
69 # $locale->text('Jul')
70 # $locale->text('Aug')
71 # $locale->text('Sep')
72 # $locale->text('Oct')
73 # $locale->text('Nov')
74 # $locale->text('Dec')
76 ########################################
77 # Eintrag fuer Version 2.2.0 geaendert #
78 # neue Optik im Rechnungsformular #
79 ########################################
81 $lxdebug->enter_sub();
84 if ($lizenzen && $form->{vc} eq "customer") {
85 if ($form->{type} =~ /sales_order/) {
86 @column_index = (runningnumber, partnumber, description, ship, qty);
87 } elsif ($form->{type} =~ /sales_quotation/) {
88 @column_index = (runningnumber, partnumber, description, qty);
90 @column_index = (runningnumber, partnumber, description, qty);
93 if ( ($form->{type} =~ /purchase_order/)
94 || ($form->{type} =~ /sales_order/)) {
95 @column_index = (runningnumber, partnumber, description, ship, qty);
97 @column_index = (runningnumber, partnumber, description, qty);
100 ############## ENDE Neueintrag ##################
102 push @column_index, qw(unit sellprice);
104 if ($form->{vc} eq 'customer') {
105 push @column_index, qw(discount);
108 push @column_index, "linetotal";
110 my $colspan = $#column_index + 1;
112 $form->{invsubtotal} = 0;
113 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
115 ########################################
116 # Eintrag fuer Version 2.2.0 geaendert #
117 # neue Optik im Rechnungsformular #
118 ########################################
119 $column_data{runningnumber} =
120 qq|<th align=left nowrap width=5 class=listheading>|
121 . $locale->text('No.')
123 $column_data{partnumber} =
124 qq|<th align=left nowrap width=12 class=listheading>|
125 . $locale->text('Number')
127 $column_data{description} =
128 qq|<th align=left nowrap width=30 class=listheading>|
129 . $locale->text('Part Description')
132 qq|<th align=left nowrap width=5 class=listheading>|
133 . $locale->text('Ship')
136 qq|<th align=left nowrap width=5 class=listheading>|
137 . $locale->text('Qty')
140 qq|<th align=left nowrap width=5 class=listheading>|
141 . $locale->text('Unit')
143 $column_data{license} =
144 qq|<th align=left nowrap width=10 class=listheading>|
145 . $locale->text('License')
147 $column_data{serialnr} =
148 qq|<th align=left nowrap width=10 class=listheading>|
149 . $locale->text('Serial No.')
151 $column_data{projectnr} =
152 qq|<th align=left nowrap width=10 class=listheading>|
153 . $locale->text('Project')
155 $column_data{sellprice} =
156 qq|<th align=left nowrap width=10 class=listheading>|
157 . $locale->text('Price')
159 $column_data{discount} =
160 qq|<th align=left class=listheading>|
161 . $locale->text('Discount')
163 $column_data{linetotal} =
164 qq|<th align=left nowrap width=10 class=listheading>|
165 . $locale->text('Extended')
168 qq|<th align=left nowrap width=10 class=listheading>|
169 . $locale->text('Bin')
171 ############## ENDE Neueintrag ##################
177 <tr class=listheading>|;
179 map { print "\n$column_data{$_}" } @column_index;
185 $runningnumber = $locale->text('No.');
186 $deliverydate = $locale->text('Delivery Date');
187 $serialnumber = $locale->text('Serial No.');
188 $projectnumber = $locale->text('Project');
189 $partsgroup = $locale->text('Group');
191 $delvar = 'deliverydate';
193 if ($form->{type} =~ /_order$/ || $form->{type} =~ /_quotation$/) {
194 $deliverydate = $locale->text('Required by');
198 for $i (1 .. $numrows) {
202 $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
203 } qw(qty ship discount sellprice);
205 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
207 $decimalplaces = ($dec > 2) ? $dec : 2;
211 $form->{"sellprice_$i"} * $form->{"discount_$i"} / 100,
214 $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
215 $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
217 # convert " to "
218 map { $form->{"${_}_$i"} =~ s/\"/"/g }
219 qw(partnumber description unit);
221 ########################################
222 # Eintrag fuer Version 2.2.0 geaendert #
223 # neue Optik im Rechnungsformular #
224 ########################################
225 $column_data{runningnumber} =
226 qq|<td><input name="runningnumber_$i" size=5 value=$i></td>|; # HuT
227 ############## ENDE Neueintrag ##################
229 $column_data{partnumber} =
230 qq|<td><input name="partnumber_$i" size=12 value="$form->{"partnumber_$i"}"></td>|;
232 if (($rows = $form->numtextrows($form->{"description_$i"}, 30, 6)) > 1) {
233 $column_data{description} =
234 qq|<td><textarea name="description_$i" rows=$rows cols=30 wrap=soft>$form->{"description_$i"}</textarea></td>|;
236 $column_data{description} =
237 qq|<td><input name="description_$i" size=30 value="$form->{"description_$i"}"></td>|;
241 qq|<td align=right><input name="qty_$i" size=5 value=|
242 . $form->format_amount(\%myconfig, $form->{"qty_$i"})
245 qq|<td align=right><input name="ship_$i" size=5 value=|
246 . $form->format_amount(\%myconfig, $form->{"ship_$i"})
249 qq|<td><input name="unit_$i" size=5 value="$form->{"unit_$i"}"></td>|;
250 $column_data{sellprice} =
251 qq|<td align=right><input name="sellprice_$i" size=9 value=|
252 . $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
255 $column_data{discount} =
256 qq|<td align=right><input name="discount_$i" size=3 value=|
257 . $form->format_amount(\%myconfig, $form->{"discount_$i"})
259 $column_data{linetotal} =
261 . $form->format_amount(\%myconfig, $linetotal, 2)
263 $column_data{bin} = qq|<td>$form->{"bin_$i"}</td>|;
265 ########################################
266 # Eintrag fuer Version 2.2.0 geaendert #
267 # neue Optik im Rechnungsformular #
268 ########################################
269 # if ($lizenzen && $form->{type} eq "invoice" && $form->{vc} eq "customer") {
270 # $column_data{license} = qq|<td><select name="licensenumber_$i">$form->{"lizenzen_$i"}></select></td>|;
273 # if ($form->{type} !~ /_quotation/) {
274 # $column_data{serialnr} = qq|<td><input name="serialnumber_$i" size=10 value="$form->{"serialnumber_$i"}"></td>|;
277 # $column_data{projectnr} = qq|<td><input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}"></td>|;
278 ############## ENDE Neueintrag ##################
283 map { print "\n$column_data{$_}" } @column_index;
288 <input type=hidden name="orderitems_id_$i" value=$form->{"orderitems_id_$i"}>
289 <input type=hidden name="bo_$i" value=$form->{"bo_$i"}>
291 <input type=hidden name="id_$i" value=$form->{"id_$i"}>
292 <input type=hidden name="inventory_accno_$i" value=$form->{"inventory_accno_$i"}>
293 <input type=hidden name="bin_$i" value="$form->{"bin_$i"}">
294 <input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">
295 <input type=hidden name="partnotes_$i" value="$form->{"partnotes_$i"}">
296 <input type=hidden name="income_accno_$i" value=$form->{"income_accno_$i"}>
297 <input type=hidden name="expense_accno_$i" value=$form->{"expense_accno_$i"}>
298 <input type=hidden name="listprice_$i" value="$form->{"listprice_$i"}">
299 <input type=hidden name="assembly_$i" value="$form->{"assembly_$i"}">
300 <input type=hidden name="taxaccounts_$i" value="$form->{"taxaccounts_$i"}">
304 ########################################
305 # Eintrag fuer Version 2.2.0 geaendert #
306 # neue Optik im Rechnungsformular #
307 ########################################
311 <td colspan=$colspan>
313 if ($lizenzen && $form->{type} eq "invoice" && $form->{vc} eq "customer") {
314 my $selected = $form->{"licensenumber_$i"};
316 $form->{"lizenzen_$i"} =~ s/ selected//g;
317 $form->{"lizenzen_$i"} =~
318 s/value="${selected}"\>/value="${selected}" selected\>/;
319 $lizenzen_quoted = $form->{"lizenzen_$i"};
320 $lizenzen_quoted =~ s/\"/"/g;
322 <b>Lizenz\#</b> <select name="licensenumber_$i" size=1>
323 $form->{"lizenzen_$i"}
325 <input type=hidden name="lizenzen_$i" value="${lizenzen_quoted}">
328 if ($form->{type} !~ /_quotation/) {
330 <b>$serialnumber</b> <input name="serialnumber_$i" size=15 value="$form->{"serialnumber_$i"}">|;
334 <b>$projectnumber</b> <input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}">
335 <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}">
336 <input type=hidden name="project_id_$i" value="$form->{"project_id_$i"}">
342 ############## ENDE Neueintrag ##################
344 map { $form->{"${_}_base"} += $linetotal }
345 (split / /, $form->{"taxaccounts_$i"});
347 $form->{invsubtotal} += $linetotal;
356 $lxdebug->leave_sub();
360 $lxdebug->enter_sub();
362 @column_index = qw(ndx partnumber description onhand sellprice);
364 $column_data{ndx} = qq|<th> </th>|;
365 $column_data{partnumber} =
366 qq|<th class=listheading>| . $locale->text('Number') . qq|</th>|;
367 $column_data{description} =
368 qq|<th class=listheading>| . $locale->text('Part Description') . qq|</th>|;
369 $column_data{sellprice} =
370 qq|<th class=listheading>| . $locale->text('Price') . qq|</th>|;
371 $column_data{onhand} =
372 qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|;
374 # list items with radio button on a form
377 $title = $locale->text('Select from one of the items below');
378 $colspan = $#column_index + 1;
383 <form method=post action=$form->{script}>
387 <th class=listtop colspan=$colspan>$title</th>
390 <tr class=listheading>|;
392 map { print "\n$column_data{$_}" } @column_index;
397 foreach $ref (@{ $form->{item_list} }) {
398 $checked = ($i++) ? "" : "checked";
401 if ($ref->{inventory_accno} > 0) {
402 $ref->{"lizenzen"} = qq|<option></option>|;
403 foreach $item (@{ $form->{LIZENZEN}{ $ref->{"id"} } }) {
404 $ref->{"lizenzen"} .=
405 qq|<option value=\"$item->{"id"}\">$item->{"licensenumber"}</option>|;
407 $ref->{"lizenzen"} .= qq|<option value=-1>Neue Lizenz</option>|;
408 $ref->{"lizenzen"} =~ s/\"/"/g;
412 map { $ref->{$_} =~ s/\"/"/g } qw(partnumber description unit);
415 $form->round_amount($ref->{sellprice} * (1 - $form->{tradediscount}), 2);
418 qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
419 $column_data{partnumber} =
420 qq|<td><input name="new_partnumber_$i" type=hidden value="$ref->{partnumber}">$ref->{partnumber}</td>|;
421 $column_data{description} =
422 qq|<td><input name="new_description_$i" type=hidden value="$ref->{description}">$ref->{description}</td>|;
423 $column_data{sellprice} =
424 qq|<td align=right><input name="new_sellprice_$i" type=hidden value=$ref->{sellprice}>|
425 . $form->format_amount(\%myconfig, $ref->{sellprice}, 2, " ")
427 $column_data{onhand} =
428 qq|<td align=right><input name="new_onhand_$i" type=hidden value=$ref->{onhand}>|
429 . $form->format_amount(\%myconfig, $ref->{onhand}, '', " ")
435 <tr class=listrow$j>|;
437 map { print "\n$column_data{$_}" } @column_index;
442 <input name="new_bin_$i" type=hidden value="$ref->{bin}">
443 <input name="new_listprice_$i" type=hidden value=$ref->{listprice}>
444 <input name="new_inventory_accno_$i" type=hidden value=$ref->{inventory_accno}>
445 <input name="new_income_accno_$i" type=hidden value=$ref->{income_accno}>
446 <input name="new_expense_accno_$i" type=hidden value=$ref->{expense_accno}>
447 <input name="new_unit_$i" type=hidden value="$ref->{unit}">
448 <input name="new_weight_$i" type=hidden value="$ref->{weight}">
449 <input name="new_assembly_$i" type=hidden value="$ref->{assembly}">
450 <input name="new_taxaccounts_$i" type=hidden value="$ref->{taxaccounts}">
451 <input name="new_partsgroup_$i" type=hidden value="$ref->{partsgroup}">
453 <input name="new_id_$i" type=hidden value=$ref->{id}>
458 <input name="new_lizenzen_$i" type=hidden value="$ref->{lizenzen}">
465 <tr><td colspan=8><hr size=3 noshade></td></tr>
468 <input name=lastndx type=hidden value=$i>
472 # delete action variable
473 map { delete $form->{$_} } qw(action item_list header);
475 # save all other form variables
476 foreach $key (keys %${form}) {
477 $form->{$key} =~ s/\"/"/g;
478 print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
482 <input type=hidden name=nextsub value=item_selected>
485 <input class=submit type=submit name=action value="|
486 . $locale->text('Continue') . qq|">
493 $lxdebug->leave_sub();
497 $lxdebug->enter_sub();
499 # replace the last row with the checked row
500 $i = $form->{rowcount};
501 $i = $form->{assembly_rows} if ($form->{item} eq 'assembly');
506 # if there was a price entered, override it
507 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
509 map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} }
510 qw(id partnumber description sellprice listprice inventory_accno income_accno expense_accno bin unit weight assembly taxaccounts partsgroup);
513 map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} } qw(lizenzen);
516 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
518 $decimalplaces = ($dec > 2) ? $dec : 2;
521 $form->{"sellprice_$i"} = $sellprice;
524 # if there is an exchange rate adjust sellprice
525 if (($form->{exchangerate} * 1) != 0) {
526 $form->{"sellprice_$i"} /= $form->{exchangerate};
527 $form->{"sellprice_$i"} =
528 $form->round_amount($form->{"sellprice_$i"}, $decimalplaces);
532 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
533 qw(sellprice listprice weight);
535 $form->{sellprice} += ($form->{"sellprice_$i"} * $form->{"qty_$i"});
536 $form->{weight} += ($form->{"weight_$i"} * $form->{"qty_$i"});
539 $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) *
541 map { $form->{"${_}_base"} += $amount }
542 (split / /, $form->{"taxaccounts_$i"});
543 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /,
544 $form->{"taxaccounts_$i"}
545 if !$form->{taxincluded};
547 $form->{creditremaining} -= $amount;
549 $form->{"runningnumber_$i"} = $i;
551 # delete all the new_ variables
552 for $i (1 .. $form->{lastndx}) {
553 map { delete $form->{"new_${_}_$i"} }
554 qw(partnumber description sellprice bin listprice inventory_accno income_accno expense_accno unit assembly taxaccounts id);
557 map { delete $form->{$_} } qw(ndx lastndx nextsub);
562 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces)
563 } qw(sellprice listprice) if $form->{item} ne 'assembly';
567 $lxdebug->leave_sub();
571 $lxdebug->enter_sub();
574 $form->{old_callback} = $form->escape($form->{callback}, 1);
575 $form->{callback} = $form->escape("$form->{script}?action=display_form", 1);
578 delete $form->{action};
580 # save all other form variables in a previousform variable
581 foreach $key (keys %$form) {
584 $form->{$key} =~ s/&/%26/g;
585 $previousform .= qq|$key=$form->{$key}&|;
588 $previousform = $form->escape($previousform, 1);
590 $i = $form->{rowcount};
591 map { $form->{"${_}_$i"} =~ s/\"/"/g } qw(partnumber description);
598 <h4 class=error>| . $locale->text('Item not on file!') . qq|
601 | . $locale->text('What type of item is this?') . qq|</h4>
603 <form method=post action=ic.pl>
607 <input class=radio type=radio name=item value=part checked> |
608 . $locale->text('Part') . qq|<br>
609 <input class=radio type=radio name=item value=service> |
610 . $locale->text('Service')
613 <input type=hidden name=previousform value="$previousform">
614 <input type=hidden name=partnumber value="$form->{"partnumber_$i"}">
615 <input type=hidden name=description value="$form->{"description_$i"}">
616 <input type=hidden name=rowcount value=$form->{rowcount}>
617 <input type=hidden name=taxaccount2 value=$form->{taxaccounts}>
618 <input type=hidden name=vc value=$form->{vc}>
620 <input type=hidden name=path value=$form->{path}>
621 <input type=hidden name=login value=$form->{login}>
622 <input type=hidden name=password value=$form->{password}>
624 <input type=hidden name=nextsub value=add>
627 <input class=submit type=submit name=action value="|
628 . $locale->text('Continue') . qq|">
635 $lxdebug->leave_sub();
639 $lxdebug->enter_sub();
641 # if we have a display_form
642 if ($form->{display_form}) {
643 &{"$form->{display_form}"};
649 $numrows = ++$form->{rowcount};
650 $subroutine = "display_row";
652 if ($form->{item} eq 'part') {
653 $numrows = ++$form->{makemodel_rows};
654 $subroutine = "makemodel_row";
656 if ($form->{item} eq 'assembly') {
657 $numrows = ++$form->{makemodel_rows};
658 $subroutine = "makemodel_row";
660 # create makemodel rows
661 &{$subroutine}($numrows);
663 $numrows = ++$form->{assembly_rows};
664 $subroutine = "assembly_row";
666 if ($form->{item} eq 'service') {
671 &{$subroutine}($numrows) if $numrows;
675 $lxdebug->leave_sub();
679 $lxdebug->enter_sub();
684 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)
687 # remove any makes or model rows
688 if ($form->{item} eq 'part') {
689 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
690 qw(listprice sellprice lastcost weight rop);
692 @flds = (make, model);
693 for my $i (1 .. ($form->{makemodel_rows})) {
694 if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
698 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
703 $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
704 $form->{makemodel_rows} = $count;
706 } elsif ($form->{item} eq 'assembly') {
708 $form->{sellprice} = 0;
710 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
711 qw(listprice rop stock);
714 qw(id qty unit bom partnumber description sellprice weight runningnumber partsgroup);
716 for my $i (1 .. ($form->{assembly_rows} - 1)) {
717 if ($form->{"qty_$i"}) {
721 $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
723 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
725 $form->{sellprice} += ($form->{"qty_$i"} * $form->{"sellprice_$i"});
726 $form->{weight} += ($form->{"qty_$i"} * $form->{"weight_$i"});
731 $form->{sellprice} = $form->round_amount($form->{sellprice}, 2);
733 $form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows});
734 $form->{assembly_rows} = $count;
737 @flds = qw(make model);
740 for my $i (1 .. ($form->{makemodel_rows})) {
741 if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
745 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
750 $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
751 $form->{makemodel_rows} = $count;
755 # this section applies to invoices and orders
756 # remove any empty numbers
757 if ($form->{rowcount}) {
758 for my $i (1 .. $form->{rowcount} - 1) {
759 if ($form->{"partnumber_$i"}) {
763 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
766 if ($form->{"licensenumber_$i"} == -1) {
774 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
775 $form->{rowcount} = $count;
777 $form->{creditremaining} -= &invoicetotal;
784 $lxdebug->leave_sub();
788 $lxdebug->enter_sub();
790 $form->{oldinvtotal} = 0;
792 # add all parts and deduct paid
793 map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
795 my ($amount, $sellprice, $discount, $qty);
797 for my $i (1 .. $form->{rowcount}) {
798 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
799 $discount = $form->parse_amount(\%myconfig, $form->{"discount_$i"});
800 $qty = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
802 $amount = $sellprice * (1 - $discount / 100) * $qty;
803 map { $form->{"${_}_base"} += $amount }
804 (split / /, $form->{"taxaccounts_$i"});
805 $form->{oldinvtotal} += $amount;
808 map { $form->{oldinvtotal} += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
809 split / /, $form->{taxaccounts}
810 if !$form->{taxincluded};
812 $form->{oldtotalpaid} = 0;
813 for $i (1 .. $form->{paidaccounts}) {
814 $form->{oldtotalpaid} += $form->{"paid_$i"};
817 $lxdebug->leave_sub();
820 return ($form->{oldinvtotal} - $form->{oldtotalpaid});
824 $lxdebug->enter_sub();
826 # check if items are valid
827 if ($form->{rowcount} == 1) {
832 for $i (1 .. $form->{rowcount} - 1) {
833 $form->isblank("partnumber_$i",
834 $locale->text('Number missing in Row') . " $i");
837 $lxdebug->leave_sub();
841 $lxdebug->enter_sub();
843 $form->{ordnumber} = $form->{invnumber};
845 map { delete $form->{$_} } qw(id printed emailed queued);
847 if ($form->{script} eq 'ir.pl' || $form->{type} eq 'request_quotation') {
848 $form->{title} = $locale->text('Add Purchase Order');
849 $form->{vc} = 'vendor';
850 $form->{type} = 'purchase_order';
853 if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_quotation') {
854 $form->{title} = $locale->text('Add Sales Order');
855 $form->{vc} = 'customer';
856 $form->{type} = 'sales_order';
859 $form->{script} = 'oe.pl';
865 ($null, $form->{cp_id}) = split /--/, $form->{contact};
868 require "$form->{path}/$form->{script}";
870 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
872 $currency = $form->{currency};
876 $form->{currency} = $currency;
877 $form->{exchangerate} = "";
879 $form->{exchangerate} = $exchangerate
883 $form->check_exchangerate(
884 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
890 $lxdebug->leave_sub();
894 $lxdebug->enter_sub();
896 map { delete $form->{$_} } qw(id printed emailed queued);
898 if ($form->{script} eq 'ir.pl' || $form->{type} eq 'purchase_order') {
899 $form->{title} = $locale->text('Add Request for Quotation');
900 $form->{vc} = 'vendor';
901 $form->{type} = 'request_quotation';
904 if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_order') {
905 $form->{title} = $locale->text('Add Quotation');
906 $form->{vc} = 'customer';
907 $form->{type} = 'sales_quotation';
911 ($null, $form->{cp_id}) = split /--/, $form->{contact};
914 $form->{script} = 'oe.pl';
920 require "$form->{path}/$form->{script}";
922 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
924 $currency = $form->{currency};
928 $form->{currency} = $currency;
929 $form->{exchangerate} = "";
931 $form->{exchangerate} = $exchangerate
935 $form->check_exchangerate(
936 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
942 $lxdebug->leave_sub();
946 $lxdebug->enter_sub();
948 if ($myconfig{role} eq 'admin') {
950 <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
951 <td><input name=bcc size=30 value="$form->{bcc}"></td>
955 if ($form->{formname} =~ /(pick|packing|bin)_list/) {
956 $form->{email} = $form->{shiptoemail} if $form->{shiptoemail};
959 $name = $form->{ $form->{vc} };
961 $title = $locale->text('E-mail') . " $name";
963 $form->{oldmedia} = $form->{media};
964 $form->{media} = "email";
971 <form method=post action=$form->{script}>
975 <th class=listtop>$title</th>
982 <th align=right nowrap>| . $locale->text('To') . qq|</th>
983 <td><input name=email size=30 value="$form->{email}"></td>
984 <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
985 <td><input name=cc size=30 value="$form->{cc}"></td>
988 <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
989 <td><input name=subject size=30 value="$form->{subject}"></td>
999 <th align=left nowrap>| . $locale->text('Message') . qq|</th>
1002 <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
1013 map { delete $form->{$_} }
1014 qw(action email cc bcc subject message formname sendmode format header override);
1016 # save all other variables
1017 foreach $key (keys %$form) {
1018 $form->{$key} =~ s/\"/"/g;
1019 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1026 <td><hr size=3 noshade></td>
1030 <input type=hidden name=nextsub value=send_email>
1033 <input name=action class=submit type=submit value="|
1034 . $locale->text('Continue') . qq|">
1041 $lxdebug->leave_sub();
1045 $lxdebug->enter_sub();
1047 $old_form = new Form;
1049 map { $old_form->{$_} = $form->{$_} } keys %$form;
1050 $old_form->{media} = $form->{oldmedia};
1052 &print_form($old_form);
1054 $lxdebug->leave_sub();
1058 $lxdebug->enter_sub();
1060 $form->{sendmode} = "attachment";
1061 $form->{copies} = 3 unless $form->{copies};
1063 $form->{PD}{ $form->{formname} } = "selected";
1064 $form->{DF}{ $form->{format} } = "";
1065 $form->{OP}{ $form->{media} } = "selected";
1066 $form->{SM}{ $form->{sendmode} } = "selected";
1068 if ($form->{type} eq 'purchase_order') {
1069 $type = qq|<select name=formname>
1070 <option value=purchase_order $form->{PD}{purchase_order}>|
1071 . $locale->text('Purchase Order') . qq|
1072 <option value=bin_list $form->{PD}{bin_list}>|
1073 . $locale->text('Bin List');
1076 if ($form->{type} eq 'sales_order') {
1077 $type = qq|<select name=formname>
1078 <option value=sales_order $form->{PD}{sales_order}>|
1079 . $locale->text('Confirmation') . qq|
1080 <option value=pick_list $form->{PD}{pick_list}>|
1081 . $locale->text('Pick List') . qq|
1082 <option value=packing_list $form->{PD}{packing_list}>|
1083 . $locale->text('Packing List');
1086 if ($form->{type} =~ /_quotation$/) {
1087 $type = qq|<select name=formname>
1088 <option value="$`_quotation" $form->{PD}{"$`_quotation"}>|
1089 . $locale->text('Quotation') . qq|
1093 if ($form->{type} eq 'invoice') {
1094 $type = qq|<select name=formname>
1095 <option value=invoice $form->{PD}{invoice}>| . $locale->text('Invoice');
1098 if ($form->{type} eq 'ship_order') {
1099 $type = qq|<select name=formname>
1100 <option value=pick_list $form->{PD}{pick_list}>|
1101 . $locale->text('Pick List') . qq|
1102 <option value=packing_list $form->{PD}{packing_list}>|
1103 . $locale->text('Packing List');
1106 if ($form->{type} eq 'receive_order') {
1107 $type = qq|<select name=formname>
1108 <option value=bin_list $form->{PD}{bin_list}>|
1109 . $locale->text('Bin List');
1112 if ($form->{media} eq 'email') {
1113 $media = qq|<select name=sendmode>
1114 <option value=attachment $form->{SM}{attachment}>|
1115 . $locale->text('Attachment') . qq|
1116 <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
1118 $media = qq|<select name=media>
1119 <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
1120 if ($myconfig{printer} && $latex) {
1122 <option value=printer $form->{OP}{printer}>|
1123 . $locale->text('Printer');
1127 <option value=queue $form->{OP}{queue}>| . $locale->text('Queue');
1131 $format = qq|<select name=format>
1132 <option value=html $form->{DF}{html}>html|;
1135 $format = qq|<select name=format>
1136 <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF') . qq|
1137 <option value=html $form->{DF}{html}>html
1138 <option value=postscript $form->{DF}{postscript}>|
1139 . $locale->text('Postscript');
1142 $language = qq|<select name=language>
1143 <option value=""></option>|;
1144 %lang = (de => "deutsch", en => "englisch", fr => "französisch");
1145 foreach $item (keys %lang) {
1146 if ($form->{language} eq $item) {
1147 $language .= qq|<option value="$item" selected>$lang{$item}</option>|;
1149 $language .= qq|<option value="$item">$lang{$item}</option>|;
1154 <table width=100% cellspacing=0 cellpadding=0>
1159 <td>$type</select></td>
1160 <td>$language</select</td>
1161 <td>$format</select></td>
1162 <td>$media</select></td>
1165 if ($myconfig{printer} && $latex && $form->{media} ne 'email') {
1167 <td>| . $locale->text('Copies') . qq|
1168 <input name=copies size=2 value=$form->{copies}></td>
1172 $form->{groupitems} = "checked" if $form->{groupitems};
1175 <td>| . $locale->text('Group Items') . qq|</td>
1176 <td><input name=groupitems type=checkbox class=checkbox $form->{groupitems}></td>
1185 if ($form->{printed} =~ /$form->{formname}/) {
1187 <th>\|| . $locale->text('Printed') . qq|\|</th>
1191 if ($form->{emailed} =~ /$form->{formname}/) {
1193 <th>\|| . $locale->text('E-mailed') . qq|\|</th>
1197 if ($form->{queued} =~ /$form->{formname}/) {
1199 <th>\|| . $locale->text('Queued') . qq|\|</th>
1211 $lxdebug->leave_sub();
1215 $lxdebug->enter_sub();
1217 # if this goes to the printer pass through
1218 if ($form->{media} eq 'printer' || $form->{media} eq 'queue') {
1219 $form->error($locale->text('Select postscript or PDF!'))
1220 if ($form->{format} !~ /(postscript|pdf)/);
1222 $old_form = new Form;
1223 map { $old_form->{$_} = $form->{$_} } keys %$form;
1226 &print_form($old_form);
1228 $lxdebug->leave_sub();
1232 $lxdebug->enter_sub();
1233 my ($old_form) = @_;
1238 $numberfld = "invnumber";
1241 ($form->{display_form}) ? $form->{display_form} : "display_form";
1243 # $form->{"notes"} will be overridden by the customer's/vendor's "notes" field. So save it here.
1244 $form->{ $form->{"formname"} . "notes" } = $form->{"notes"};
1246 if ($form->{formname} eq "invoice") {
1247 $form->{label} = $locale->text('Invoice');
1249 if ($form->{formname} eq "packing_list") {
1251 # this is from an invoice
1252 $form->{label} = $locale->text('Packing List');
1254 if ($form->{formname} eq 'sales_order') {
1257 $form->{"${inv}date"} = $form->{transdate};
1258 $form->{label} = $locale->text('Sales Order');
1259 $numberfld = "sonumber";
1262 if ($form->{formname} eq 'packing_list' && $form->{type} ne 'invoice') {
1264 # we use the same packing list as from an invoice
1267 $form->{invdate} = $form->{"${inv}date"} = $form->{transdate};
1268 $form->{label} = $locale->text('Packing List');
1271 if ($form->{formname} eq 'pick_list') {
1274 $form->{"${inv}date"} =
1275 ($form->{transdate}) ? $form->{transdate} : $form->{invdate};
1276 $form->{label} = $locale->text('Pick List');
1277 $order = 1 unless $form->{type} eq 'invoice';
1279 if ($form->{formname} eq 'purchase_order') {
1282 $form->{"${inv}date"} = $form->{transdate};
1283 $form->{label} = $locale->text('Purchase Order');
1284 $numberfld = "ponumber";
1287 if ($form->{formname} eq 'bin_list') {
1290 $form->{"${inv}date"} = $form->{transdate};
1291 $form->{label} = $locale->text('Bin List');
1294 if ($form->{formname} eq 'sales_quotation') {
1297 $form->{"${inv}date"} = $form->{transdate};
1298 $form->{label} = $locale->text('Quotation');
1299 $numberfld = "sqnumber";
1302 if ($form->{formname} eq 'request_quotation') {
1305 $form->{"${inv}date"} = $form->{transdate};
1306 $form->{label} = $locale->text('Quotation');
1307 $numberfld = "rfqnumber";
1311 $form->isblank("email", $locale->text('E-mail address missing!'))
1312 if ($form->{media} eq 'email');
1313 $form->isblank("${inv}date",
1314 $locale->text($form->{label} . ' Date missing!'));
1316 # $locale->text('Invoice Number missing!')
1317 # $locale->text('Invoice Date missing!')
1318 # $locale->text('Packing List Number missing!')
1319 # $locale->text('Packing List Date missing!')
1320 # $locale->text('Order Number missing!')
1321 # $locale->text('Order Date missing!')
1322 # $locale->text('Quotation Number missing!')
1323 # $locale->text('Quotation Date missing!')
1326 if (!$form->{"${inv}number"}) {
1327 $form->{"${inv}number"} = $form->update_defaults(\%myconfig, $numberfld);
1328 if ($form->{media} ne 'email') {
1329 $form->{rowcount}--;
1337 # Save the email address given in the form because it should override the setting saved for the customer/vendor.
1338 my ($saved_email, $saved_cc, $saved_bcc) =
1339 ($form->{"email"}, $form->{"cc"}, $form->{"bcc"});
1341 $language = $form->{language};
1342 &{"$form->{vc}_details"};
1343 $form->{language} = $language;
1345 $form->{"email"} = $saved_email if ($saved_email);
1346 $form->{"cc"} = $saved_cc if ($saved_cc);
1347 $form->{"bcc"} = $saved_bcc if ($saved_bcc);
1350 foreach $i (1 .. $form->{rowcount}) {
1352 ("partnumber_$i", "description_$i",
1353 "partsgroup_$i", "serialnumber_$i",
1354 "bin_$i", "unit_$i");
1356 map { push @a, "${_}_description" } split / /, $form->{taxaccounts};
1358 $ARAP = ($form->{vc} eq 'customer') ? "AR" : "AP";
1361 # format payment dates
1362 for $i (1 .. $form->{paidaccounts} - 1) {
1363 $form->{"datepaid_$i"} = $locale->date(\%myconfig, $form->{"datepaid_$i"});
1364 push @a, "${ARAP}_paid_$i", "source_$i", "memo_$i";
1367 $form->format_string(@a);
1369 ($form->{employee}) = split /--/, $form->{employee};
1370 ($form->{warehouse}, $form->{warehouse_id}) = split /--/, $form->{warehouse};
1372 # create the form variables
1374 OE->order_details(\%myconfig, \%$form);
1376 IS->invoice_details(\%myconfig, \%$form, $locale);
1379 map { $form->{$_} = $locale->date(\%myconfig, $form->{$_}, 1) }
1380 ("${inv}date", "${due}date", "shippingdate");
1382 @a = qw(name street zipcode city country);
1386 # if there is no shipto fill it in from billto
1387 foreach $item (@a) {
1388 if ($form->{"shipto$item"}) {
1395 if ( $form->{formname} eq 'purchase_order'
1396 || $form->{formname} eq 'request_quotation') {
1397 $form->{shiptoname} = $myconfig{company};
1398 $form->{shiptostreet} = $myconfig{address};
1400 map { $form->{"shipto$_"} = $form->{$_} } @a;
1404 $form->{notes} =~ s/^\s+//g;
1406 # some of the stuff could have umlauts so we translate them
1408 qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptoemail shippingpoint shipvia company address signature employee contact);
1410 push @a, ("${inv}date", "${due}date", email, cc, bcc);
1412 $form->format_string(@a);
1414 $form->{templates} = "$myconfig{templates}";
1415 if ($form->{language} ne "") {
1416 $form->{language} = "_" . $form->{language};
1419 $form->{IN} = "$form->{formname}$form->{language}.html";
1420 if ($form->{format} eq 'postscript') {
1421 $form->{postscript} = 1;
1422 $form->{IN} =~ s/html$/tex/;
1424 if ($form->{format} eq 'pdf') {
1426 $form->{IN} =~ s/html$/tex/;
1429 if ($form->{media} eq 'printer') {
1430 $form->{OUT} = "| $myconfig{printer}";
1431 $form->{printed} .= " $form->{formname}";
1432 $form->{printed} =~ s/^ //;
1434 $printed = $form->{printed};
1436 if ($form->{media} eq 'email') {
1437 $form->{subject} = qq|$form->{label} $form->{"${inv}number"}|
1438 unless $form->{subject};
1440 $form->{OUT} = "$sendmail";
1442 $form->{emailed} .= " $form->{formname}";
1443 $form->{emailed} =~ s/^ //;
1445 $emailed = $form->{emailed};
1447 if ($form->{media} eq 'queue') {
1448 %queued = split / /, $form->{queued};
1450 if ($filename = $queued{ $form->{formname} }) {
1451 $form->{queued} =~ s/$form->{formname} $filename//;
1452 unlink "$spool/$filename";
1453 $filename =~ s/\..*$//g;
1459 $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
1460 $form->{OUT} = ">$spool/$filename";
1463 $form->{queued} .= " $form->{formname} $filename";
1465 $form->{queued} =~ s/^ //;
1467 $queued = $form->{queued};
1469 $form->parse_template(\%myconfig, $userspath);
1471 $form->{callback} = "";
1473 if ($form->{media} eq 'email') {
1474 $form->{message} = $locale->text('sent') unless $form->{message};
1476 $message = $form->{message};
1478 # if we got back here restore the previous form
1479 if ($form->{media} =~ /(printer|email|queue)/) {
1481 $form->update_status(\%myconfig)
1482 if ($form->{media} eq 'queue' && $form->{id});
1486 $old_form->{"${inv}number"} = $form->{"${inv}number"};
1488 # restore and display form
1489 map { $form->{$_} = $old_form->{$_} } keys %$old_form;
1491 $form->{queued} = $queued;
1492 $form->{printed} = $printed;
1493 $form->{emailed} = $emailed;
1494 $form->{message} = $message;
1496 $form->{rowcount}--;
1497 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1498 qw(exchangerate creditlimit creditremaining);
1500 for $i (1 .. $form->{paidaccounts}) {
1502 $form->{"${_}_$i"} =
1503 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
1504 } qw(paid exchangerate);
1512 ($form->{media} eq 'printer')
1513 ? $locale->text('sent to printer')
1514 : $locale->text('emailed to') . " $form->{email}";
1515 $form->redirect(qq|$form->{label} $form->{"${inv}number"} $msg|);
1518 $lxdebug->leave_sub();
1521 sub customer_details {
1522 $lxdebug->enter_sub();
1524 IS->customer_details(\%myconfig, \%$form);
1525 $lxdebug->leave_sub();
1528 sub vendor_details {
1529 $lxdebug->enter_sub();
1531 IR->vendor_details(\%myconfig, \%$form);
1533 $lxdebug->leave_sub();
1537 $lxdebug->enter_sub();
1539 $form->{postasnew} = 1;
1540 map { delete $form->{$_} } qw(printed emailed queued);
1544 $lxdebug->leave_sub();
1548 $lxdebug->enter_sub();
1550 $title = $form->{title};
1551 $form->{title} = $locale->text('Ship to');
1553 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1554 qw(exchangerate creditlimit creditremaining);
1555 $form_id = $form->{id};
1556 # get details for name
1557 &{"$form->{vc}_details"};
1558 $form->{id} = $form_id;
1561 ($form->{vc} eq 'customer')
1562 ? $locale->text('Customer Number')
1563 : $locale->text('Vendor Number');
1565 $nextsub = ($form->{display_form}) ? $form->{display_form} : "display_form";
1567 $form->{rowcount}--;
1574 <form method=post action=$form->{script}>
1580 <tr class=listheading>
1581 <th class=listheading colspan=2 width=50%>|
1582 . $locale->text('Billing Address')
1584 <th class=listheading width=50%>|
1585 . $locale->text('Shipping Address')
1588 <tr height="5"></tr>
1590 <th align=right nowrap>$number</th>
1591 <td>$form->{"$form->{vc}number"}</td>
1594 <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
1595 <td>$form->{name}</td>
1596 <td><input name=shiptoname size=35 value="$form->{shiptoname}"></td>
1599 <th align=right nowrap>| . $locale->text('Street') . qq|</th>
1600 <td>$form->{street}</td>
1601 <td><input name=shiptostreet size=35 value="$form->{shiptostreet}"></td>
1604 <th align=right nowrap>| . $locale->text('Zipcode') . qq|</th>
1605 <td>$form->{zipcode}</td>
1606 <td><input name=shiptozipcode size=35 value="$form->{shiptozipcode}"></td>
1609 <th align=right nowrap>| . $locale->text('City') . qq|</th>
1610 <td>$form->{city}</td>
1611 <td><input name=shiptocity size=35 value="$form->{shiptocity}"></td>
1614 <th align=right nowrap>| . $locale->text('Country') . qq|</th>
1615 <td>$form->{country}</td>
1616 <td><input name=shiptocountry size=35 value="$form->{shiptocountry}"></td>
1619 <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
1620 <td>$form->{contact}</td>
1621 <td><input name=shiptocontact size=35 value="$form->{shiptocontact}"></td>
1624 <th align=right nowrap>| . $locale->text('Phone') . qq|</th>
1625 <td>$form->{"$form->{vc}phone"}</td>
1626 <td><input name=shiptophone size=20 value="$form->{shiptophone}"></td>
1629 <th align=right nowrap>| . $locale->text('Fax') . qq|</th>
1630 <td>$form->{"$form->{vc}fax"}</td>
1631 <td><input name=shiptofax size=20 value="$form->{shiptofax}"></td>
1634 <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
1635 <td>$form->{email}</td>
1636 <td><input name=shiptoemail size=35 value="$form->{shiptoemail}"></td>
1643 <input type=hidden name=nextsub value=$nextsub>
1647 map { delete $form->{$_} }
1648 qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax shiptoemail header);
1649 $form->{title} = $title;
1651 foreach $key (keys %$form) {
1652 $form->{$key} =~ s/\"/"/g;
1653 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1661 <input class=submit type=submit name=action value="|
1662 . $locale->text('Continue') . qq|">
1669 $lxdebug->leave_sub();
1673 $lxdebug->enter_sub();
1678 $form->{old_callback} = $form->escape($form->{callback}, 1);
1679 $form->{callback} = $form->escape("$form->{script}?action=display_form", 1);
1680 $form->{old_callback} = $form->escape($form->{old_callback}, 1);
1683 delete $form->{action};
1684 $customer = $form->{customer};
1685 map { $form->{"old_$_"} = $form->{"${_}_$row"} } qw(partnumber description);
1687 # save all other form variables in a previousform variable
1688 $form->{row} = $row;
1689 foreach $key (keys %$form) {
1692 $form->{$key} =~ s/&/%26/g;
1693 $previousform .= qq|$key=$form->{$key}&|;
1696 $previousform = $form->escape($previousform, 1);
1698 $form->{script} = "licenses.pl";
1700 map { $form->{$_} = $form->{"old_$_"} } qw(partnumber description);
1701 map { $form->{$_} = $form->escape($form->{$_}, 1) }
1702 qw(partnumber description);
1704 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|;
1707 $lxdebug->leave_sub();