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"; };
49 # this is for our long dates
50 # $locale->text('January')
51 # $locale->text('February')
52 # $locale->text('March')
53 # $locale->text('April')
54 # $locale->text('May ')
55 # $locale->text('June')
56 # $locale->text('July')
57 # $locale->text('August')
58 # $locale->text('September')
59 # $locale->text('October')
60 # $locale->text('November')
61 # $locale->text('December')
63 # this is for our short month
64 # $locale->text('Jan')
65 # $locale->text('Feb')
66 # $locale->text('Mar')
67 # $locale->text('Apr')
68 # $locale->text('May')
69 # $locale->text('Jun')
70 # $locale->text('Jul')
71 # $locale->text('Aug')
72 # $locale->text('Sep')
73 # $locale->text('Oct')
74 # $locale->text('Nov')
75 # $locale->text('Dec')
77 ########################################
78 # Eintrag fuer Version 2.2.0 geaendert #
79 # neue Optik im Rechnungsformular #
80 ########################################
82 $lxdebug->enter_sub();
86 if ($lizenzen && $form->{vc} eq "customer") {
87 if ($form->{type} =~ /sales_order/) {
88 @column_index = (runningnumber, partnumber, description, ship, qty);
90 elsif ($form->{type} =~ /sales_quotation/){
91 @column_index = (runningnumber, partnumber, description, qty);
94 @column_index = (runningnumber, partnumber, description, qty);
98 if (($form->{type} =~ /purchase_order/) || ($form->{type} =~ /sales_order/)) {
99 @column_index = (runningnumber, partnumber, description, ship, qty);
102 @column_index = (runningnumber, partnumber, description, qty);
105 ############## ENDE Neueintrag ##################
107 push @column_index, qw(unit sellprice);
109 if ($form->{vc} eq 'customer') {
110 push @column_index, qw(discount);
113 push @column_index, "linetotal";
115 my $colspan = $#column_index + 1;
118 $form->{invsubtotal} = 0;
119 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
121 ########################################
122 # Eintrag fuer Version 2.2.0 geaendert #
123 # neue Optik im Rechnungsformular #
124 ########################################
125 $column_data{runningnumber} = qq|<th align=left nowrap width=5 class=listheading>|.$locale->text('No.').qq|</th>|;
126 $column_data{partnumber} = qq|<th align=left nowrap width=12 class=listheading>|.$locale->text('Number').qq|</th>|;
127 $column_data{description} = qq|<th align=left nowrap width=30 class=listheading>|.$locale->text('Part Description').qq|</th>|;
128 $column_data{ship} = qq|<th align=left nowrap width=5 class=listheading>|.$locale->text('Ship').qq|</th>|;
129 $column_data{qty} = qq|<th align=left nowrap width=5 class=listheading>|.$locale->text('Qty').qq|</th>|;
130 $column_data{unit} = qq|<th align=left nowrap width=5 class=listheading>|.$locale->text('Unit').qq|</th>|;
131 $column_data{license} = qq|<th align=left nowrap width=10 class=listheading>|.$locale->text('License').qq|</th>|;
132 $column_data{serialnr} = qq|<th align=left nowrap width=10 class=listheading>|.$locale->text('Serial No.').qq|</th>|;
133 $column_data{projectnr} = qq|<th align=left nowrap width=10 class=listheading>|.$locale->text('Project').qq|</th>|;
134 $column_data{sellprice} = qq|<th align=left nowrap width=10 class=listheading>|.$locale->text('Price').qq|</th>|;
135 $column_data{discount} = qq|<th align=left class=listheading>|.$locale->text('Discount').qq|</th>|;
136 $column_data{linetotal} = qq|<th align=left nowrap width=10 class=listheading>|.$locale->text('Extended').qq|</th>|;
137 $column_data{bin} = qq|<th align=left nowrap width=10 class=listheading>|.$locale->text('Bin').qq|</th>|;
138 ############## ENDE Neueintrag ##################
144 <tr class=listheading>|;
146 map { print "\n$column_data{$_}" } @column_index;
153 $runningnumber = $locale->text('No.');
154 $deliverydate = $locale->text('Delivery Date');
155 $serialnumber = $locale->text('Serial No.');
156 $projectnumber = $locale->text('Project');
157 $partsgroup = $locale->text('Group');
159 $delvar = 'deliverydate';
161 if ($form->{type} =~ /_order$/ || $form->{type} =~ /_quotation$/) {
162 $deliverydate = $locale->text('Required by');
167 for $i (1 .. $numrows) {
169 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(qty ship discount sellprice);
172 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
174 $decimalplaces = ($dec > 2) ? $dec : 2;
176 $discount = $form->round_amount($form->{"sellprice_$i"} * $form->{"discount_$i"}/100, $decimalplaces);
177 $linetotal = $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
178 $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
180 # convert " to "
181 map { $form->{"${_}_$i"} =~ s/\"/"/g } qw(partnumber description unit);
183 ########################################
184 # Eintrag fuer Version 2.2.0 geaendert #
185 # neue Optik im Rechnungsformular #
186 ########################################
187 $column_data{runningnumber} = qq|<td><input name="runningnumber_$i" size=5 value=$i></td>|; # HuT
188 ############## ENDE Neueintrag ##################
190 $column_data{partnumber} = qq|<td><input name="partnumber_$i" size=12 value="$form->{"partnumber_$i"}"></td>|;
192 if (($rows = $form->numtextrows($form->{"description_$i"}, 30, 6)) > 1) {
193 $column_data{description} = qq|<td><textarea name="description_$i" rows=$rows cols=30 wrap=soft>$form->{"description_$i"}</textarea></td>|;
195 $column_data{description} = qq|<td><input name="description_$i" size=30 value="$form->{"description_$i"}"></td>|;
198 $column_data{qty} = qq|<td align=right><input name="qty_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"qty_$i"}).qq|></td>|;
199 $column_data{ship} = qq|<td align=right><input name="ship_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"ship_$i"}).qq|></td>|;
200 $column_data{unit} = qq|<td><input name="unit_$i" size=5 value="$form->{"unit_$i"}"></td>|;
201 $column_data{sellprice} = qq|<td align=right><input name="sellprice_$i" size=9 value=|.$form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces).qq|></td>|;
202 $column_data{discount} = qq|<td align=right><input name="discount_$i" size=3 value=|.$form->format_amount(\%myconfig, $form->{"discount_$i"}).qq|></td>|;
203 $column_data{linetotal} = qq|<td align=right>|.$form->format_amount(\%myconfig, $linetotal, 2).qq|</td>|;
204 $column_data{bin} = qq|<td>$form->{"bin_$i"}</td>|;
207 ########################################
208 # Eintrag fuer Version 2.2.0 geaendert #
209 # neue Optik im Rechnungsformular #
210 ########################################
211 # if ($lizenzen && $form->{type} eq "invoice" && $form->{vc} eq "customer") {
212 # $column_data{license} = qq|<td><select name="licensenumber_$i">$form->{"lizenzen_$i"}></select></td>|;
215 # if ($form->{type} !~ /_quotation/) {
216 # $column_data{serialnr} = qq|<td><input name="serialnumber_$i" size=10 value="$form->{"serialnumber_$i"}"></td>|;
219 # $column_data{projectnr} = qq|<td><input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}"></td>|;
220 ############## ENDE Neueintrag ##################
226 map { print "\n$column_data{$_}" } @column_index;
231 <input type=hidden name="orderitems_id_$i" value=$form->{"orderitems_id_$i"}>
232 <input type=hidden name="bo_$i" value=$form->{"bo_$i"}>
234 <input type=hidden name="id_$i" value=$form->{"id_$i"}>
235 <input type=hidden name="inventory_accno_$i" value=$form->{"inventory_accno_$i"}>
236 <input type=hidden name="bin_$i" value="$form->{"bin_$i"}">
237 <input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">
238 <input type=hidden name="partnotes_$i" value="$form->{"partnotes_$i"}">
239 <input type=hidden name="income_accno_$i" value=$form->{"income_accno_$i"}>
240 <input type=hidden name="expense_accno_$i" value=$form->{"expense_accno_$i"}>
241 <input type=hidden name="listprice_$i" value="$form->{"listprice_$i"}">
242 <input type=hidden name="assembly_$i" value="$form->{"assembly_$i"}">
243 <input type=hidden name="taxaccounts_$i" value="$form->{"taxaccounts_$i"}">
247 ########################################
248 # Eintrag fuer Version 2.2.0 geaendert #
249 # neue Optik im Rechnungsformular #
250 ########################################
254 <td colspan=$colspan>
256 if ($lizenzen && $form->{type} eq "invoice" && $form->{vc} eq "customer") {
257 my $selected = $form->{"licensenumber_$i"};
259 $form->{"lizenzen_$i"} =~ s/ selected//g;
260 $form->{"lizenzen_$i"} =~ s/value="${selected}"\>/value="${selected}" selected\>/;
261 $lizenzen_quoted = $form->{"lizenzen_$i"};
262 $lizenzen_quoted =~ s/\"/"/g;
264 <b>Lizenz\#</b> <select name="licensenumber_$i" size=1>
265 $form->{"lizenzen_$i"}
267 <input type=hidden name="lizenzen_$i" value="${lizenzen_quoted}">
270 if ($form->{type} !~ /_quotation/) {
272 <b>$serialnumber</b> <input name="serialnumber_$i" size=15 value="$form->{"serialnumber_$i"}">|;
276 <b>$projectnumber</b> <input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}">
277 <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}">
278 <input type=hidden name="project_id_$i" value="$form->{"project_id_$i"}">
284 ############## ENDE Neueintrag ##################
287 map { $form->{"${_}_base"} += $linetotal } (split / /, $form->{"taxaccounts_$i"});
289 $form->{invsubtotal} += $linetotal;
298 $lxdebug->leave_sub();
303 $lxdebug->enter_sub();
305 @column_index = qw(ndx partnumber description onhand sellprice);
307 $column_data{ndx} = qq|<th> </th>|;
308 $column_data{partnumber} = qq|<th class=listheading>|.$locale->text('Number').qq|</th>|;
309 $column_data{description} = qq|<th class=listheading>|.$locale->text('Part Description').qq|</th>|;
310 $column_data{sellprice} = qq|<th class=listheading>|.$locale->text('Price').qq|</th>|;
311 $column_data{onhand} = qq|<th class=listheading>|.$locale->text('Qty').qq|</th>|;
314 # list items with radio button on a form
317 $title = $locale->text('Select from one of the items below');
318 $colspan = $#column_index + 1;
325 <form method=post action=$form->{script}>
329 <th class=listtop colspan=$colspan>$title</th>
332 <tr class=listheading>|;
334 map { print "\n$column_data{$_}" } @column_index;
339 foreach $ref (@{ $form->{item_list} }) {
340 $checked = ($i++) ? "" : "checked";
343 if ($ref->{inventory_accno} > 0) {
344 $ref->{"lizenzen"} = qq|<option></option>|;
345 foreach $item (@{ $form->{LIZENZEN}{$ref->{"id"}}}) {
346 $ref->{"lizenzen"} .= qq|<option value=\"$item->{"id"}\">$item->{"licensenumber"}</option>|;
348 $ref->{"lizenzen"} .= qq|<option value=-1>Neue Lizenz</option>|;
349 $ref->{"lizenzen"} =~ s/\"/"/g;
354 map { $ref->{$_} =~ s/\"/"/g } qw(partnumber description unit);
356 $ref->{sellprice} = $form->round_amount($ref->{sellprice} * (1 - $form->{tradediscount}), 2);
358 $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
359 $column_data{partnumber} = qq|<td><input name="new_partnumber_$i" type=hidden value="$ref->{partnumber}">$ref->{partnumber}</td>|;
360 $column_data{description} = qq|<td><input name="new_description_$i" type=hidden value="$ref->{description}">$ref->{description}</td>|;
361 $column_data{sellprice} = qq|<td align=right><input name="new_sellprice_$i" type=hidden value=$ref->{sellprice}>|.$form->format_amount(\%myconfig, $ref->{sellprice}, 2, " ").qq|</td>|;
362 $column_data{onhand} = qq|<td align=right><input name="new_onhand_$i" type=hidden value=$ref->{onhand}>|.$form->format_amount(\%myconfig, $ref->{onhand}, '', " ").qq|</td>|;
366 <tr class=listrow$j>|;
368 map { print "\n$column_data{$_}" } @column_index;
373 <input name="new_bin_$i" type=hidden value="$ref->{bin}">
374 <input name="new_listprice_$i" type=hidden value=$ref->{listprice}>
375 <input name="new_inventory_accno_$i" type=hidden value=$ref->{inventory_accno}>
376 <input name="new_income_accno_$i" type=hidden value=$ref->{income_accno}>
377 <input name="new_expense_accno_$i" type=hidden value=$ref->{expense_accno}>
378 <input name="new_unit_$i" type=hidden value="$ref->{unit}">
379 <input name="new_weight_$i" type=hidden value="$ref->{weight}">
380 <input name="new_assembly_$i" type=hidden value="$ref->{assembly}">
381 <input name="new_taxaccounts_$i" type=hidden value="$ref->{taxaccounts}">
382 <input name="new_partsgroup_$i" type=hidden value="$ref->{partsgroup}">
384 <input name="new_id_$i" type=hidden value=$ref->{id}>
389 <input name="new_lizenzen_$i" type=hidden value="$ref->{lizenzen}">
396 <tr><td colspan=8><hr size=3 noshade></td></tr>
399 <input name=lastndx type=hidden value=$i>
403 # delete action variable
404 map { delete $form->{$_} } qw(action item_list header);
406 # save all other form variables
407 foreach $key (keys %${form}) {
408 $form->{$key} =~ s/\"/"/g;
409 print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
413 <input type=hidden name=nextsub value=item_selected>
416 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
423 $lxdebug->leave_sub();
429 $lxdebug->enter_sub();
431 # replace the last row with the checked row
432 $i = $form->{rowcount};
433 $i = $form->{assembly_rows} if ($form->{item} eq 'assembly');
438 # if there was a price entered, override it
439 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
441 map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} } qw(id partnumber description sellprice listprice inventory_accno income_accno expense_accno bin unit weight assembly taxaccounts partsgroup);
444 map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} } qw(lizenzen);
447 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
449 $decimalplaces = ($dec > 2) ? $dec : 2;
452 $form->{"sellprice_$i"} = $sellprice;
454 # if there is an exchange rate adjust sellprice
455 if (($form->{exchangerate} * 1) != 0) {
456 $form->{"sellprice_$i"} /= $form->{exchangerate};
457 $form->{"sellprice_$i"} = $form->round_amount($form->{"sellprice_$i"}, $decimalplaces);
461 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(sellprice listprice weight);
463 $form->{sellprice} += ($form->{"sellprice_$i"} * $form->{"qty_$i"});
464 $form->{weight} += ($form->{"weight_$i"} * $form->{"qty_$i"});
466 $amount = $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) * $form->{"qty_$i"};
467 map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"});
468 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
470 $form->{creditremaining} -= $amount;
472 $form->{"runningnumber_$i"} = $i;
474 # delete all the new_ variables
475 for $i (1 .. $form->{lastndx}) {
476 map { delete $form->{"new_${_}_$i"} } qw(partnumber description sellprice bin listprice inventory_accno income_accno expense_accno unit assembly taxaccounts id);
479 map { delete $form->{$_} } qw(ndx lastndx nextsub);
482 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice) if $form->{item} ne 'assembly';
486 $lxdebug->leave_sub();
491 $lxdebug->enter_sub();
494 $form->{old_callback} = $form->escape($form->{callback},1);
495 $form->{callback} = $form->escape("$form->{script}?action=display_form",1);
498 delete $form->{action};
500 # save all other form variables in a previousform variable
501 foreach $key (keys %$form) {
503 $form->{$key} =~ s/&/%26/g;
504 $previousform .= qq|$key=$form->{$key}&|;
507 $previousform = $form->escape($previousform, 1);
509 $i = $form->{rowcount};
510 map { $form->{"${_}_$i"} =~ s/\"/"/g } qw(partnumber description);
517 <h4 class=error>|.$locale->text('Item not on file!').qq|
520 |.$locale->text('What type of item is this?').qq|</h4>
522 <form method=post action=ic.pl>
526 <input class=radio type=radio name=item value=part checked> |.$locale->text('Part')
528 <input class=radio type=radio name=item value=service> |.$locale->text('Service')
531 <input type=hidden name=previousform value="$previousform">
532 <input type=hidden name=partnumber value="$form->{"partnumber_$i"}">
533 <input type=hidden name=description value="$form->{"description_$i"}">
534 <input type=hidden name=rowcount value=$form->{rowcount}>
535 <input type=hidden name=taxaccount2 value=$form->{taxaccounts}>
536 <input type=hidden name=vc value=$form->{vc}>
538 <input type=hidden name=path value=$form->{path}>
539 <input type=hidden name=login value=$form->{login}>
540 <input type=hidden name=password value=$form->{password}>
542 <input type=hidden name=nextsub value=add>
545 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
552 $lxdebug->leave_sub();
558 $lxdebug->enter_sub();
560 # if we have a display_form
561 if ($form->{display_form}) {
562 &{ "$form->{display_form}" };
568 $numrows = ++$form->{rowcount};
569 $subroutine = "display_row";
571 if ($form->{item} eq 'part') {
572 $numrows = ++$form->{makemodel_rows};
573 $subroutine = "makemodel_row";
575 if ($form->{item} eq 'assembly') {
576 $numrows = ++$form->{makemodel_rows};
577 $subroutine = "makemodel_row";
579 # create makemodel rows
580 &{ $subroutine }($numrows);
582 $numrows = ++$form->{assembly_rows};
583 $subroutine = "assembly_row";
585 if ($form->{item} eq 'service') {
590 &{ $subroutine }($numrows) if $numrows;
594 $lxdebug->leave_sub();
600 $lxdebug->enter_sub();
604 my @flds = (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));
606 # remove any makes or model rows
607 if ($form->{item} eq 'part') {
608 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(listprice sellprice lastcost weight rop);
610 @flds = (make, model);
611 for my $i (1 .. ($form->{makemodel_rows})) {
612 if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
616 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
621 $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
622 $form->{makemodel_rows} = $count;
624 } elsif ($form->{item} eq 'assembly') {
626 $form->{sellprice} = 0;
628 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(listprice rop stock);
630 @flds = qw(id qty unit bom partnumber description sellprice weight runningnumber partsgroup);
632 for my $i (1 .. ($form->{assembly_rows} - 1)) {
633 if ($form->{"qty_$i"}) {
637 $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
639 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
641 $form->{sellprice} += ($form->{"qty_$i"} * $form->{"sellprice_$i"});
642 $form->{weight} += ($form->{"qty_$i"} * $form->{"weight_$i"});
647 $form->{sellprice} = $form->round_amount($form->{sellprice}, 2);
649 $form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows});
650 $form->{assembly_rows} = $count;
653 @flds = qw(make model);
656 for my $i (1 .. ($form->{makemodel_rows})) {
657 if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
661 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
666 $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
667 $form->{makemodel_rows} = $count;
671 # this section applies to invoices and orders
672 # remove any empty numbers
673 if ($form->{rowcount}) {
674 for my $i (1 .. $form->{rowcount} - 1) {
675 if ($form->{"partnumber_$i"}) {
679 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
682 if ($form->{"licensenumber_$i"} == -1) {
690 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
691 $form->{rowcount} = $count;
693 $form->{creditremaining} -= &invoicetotal;
700 $lxdebug->leave_sub();
705 $lxdebug->enter_sub();
707 $form->{oldinvtotal} = 0;
708 # add all parts and deduct paid
709 map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
711 my ($amount, $sellprice, $discount, $qty);
713 for my $i (1 .. $form->{rowcount}) {
714 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
715 $discount = $form->parse_amount(\%myconfig, $form->{"discount_$i"});
716 $qty = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
718 $amount = $sellprice * (1 - $discount / 100) * $qty;
719 map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"});
720 $form->{oldinvtotal} += $amount;
723 map { $form->{oldinvtotal} += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{taxaccounts} if !$form->{taxincluded};
725 $form->{oldtotalpaid} = 0;
726 for $i (1 .. $form->{paidaccounts}) {
727 $form->{oldtotalpaid} += $form->{"paid_$i"};
730 $lxdebug->leave_sub();
733 return ($form->{oldinvtotal} - $form->{oldtotalpaid});
738 $lxdebug->enter_sub();
740 # check if items are valid
741 if ($form->{rowcount} == 1) {
746 for $i (1 .. $form->{rowcount} - 1) {
747 $form->isblank("partnumber_$i", $locale->text('Number missing in Row') . " $i");
750 $lxdebug->leave_sub();
755 $lxdebug->enter_sub();
757 $form->{ordnumber} = $form->{invnumber};
760 map { delete $form->{$_} } qw(id printed emailed queued);
762 if ($form->{script} eq 'ir.pl' || $form->{type} eq 'request_quotation') {
763 $form->{title} = $locale->text('Add Purchase Order');
764 $form->{vc} = 'vendor';
765 $form->{type} = 'purchase_order';
768 if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_quotation') {
769 $form->{title} = $locale->text('Add Sales Order');
770 $form->{vc} = 'customer';
771 $form->{type} = 'sales_order';
774 $form->{script} = 'oe.pl';
780 ($null, $form->{cp_id}) = split /--/, $form->{contact};
783 require "$form->{path}/$form->{script}";
785 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
787 $currency = $form->{currency};
791 $form->{currency} = $currency;
792 $form->{exchangerate} = "";
794 $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell)));
799 $lxdebug->leave_sub();
804 $lxdebug->enter_sub();
806 map { delete $form->{$_} } qw(id printed emailed queued);
808 if ($form->{script} eq 'ir.pl' || $form->{type} eq 'purchase_order') {
809 $form->{title} = $locale->text('Add Request for Quotation');
810 $form->{vc} = 'vendor';
811 $form->{type} = 'request_quotation';
814 if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_order') {
815 $form->{title} = $locale->text('Add Quotation');
816 $form->{vc} = 'customer';
817 $form->{type} = 'sales_quotation';
821 ($null, $form->{cp_id}) = split /--/, $form->{contact};
824 $form->{script} = 'oe.pl';
830 require "$form->{path}/$form->{script}";
832 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
834 $currency = $form->{currency};
838 $form->{currency} = $currency;
839 $form->{exchangerate} = "";
841 $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell)));
846 $lxdebug->leave_sub();
852 $lxdebug->enter_sub();
854 if ($myconfig{role} eq 'admin') {
856 <th align=right nowrap=true>|.$locale->text('Bcc').qq|</th>
857 <td><input name=bcc size=30 value="$form->{bcc}"></td>
861 if ($form->{formname} =~ /(pick|packing|bin)_list/) {
862 $form->{email} = $form->{shiptoemail} if $form->{shiptoemail};
865 $name = $form->{$form->{vc}};
867 $title = $locale->text('E-mail')." $name";
869 $form->{oldmedia} = $form->{media};
870 $form->{media} = "email";
877 <form method=post action=$form->{script}>
881 <th class=listtop>$title</th>
888 <th align=right nowrap>|.$locale->text('To').qq|</th>
889 <td><input name=email size=30 value="$form->{email}"></td>
890 <th align=right nowrap>|.$locale->text('Cc').qq|</th>
891 <td><input name=cc size=30 value="$form->{cc}"></td>
894 <th align=right nowrap>|.$locale->text('Subject').qq|</th>
895 <td><input name=subject size=30 value="$form->{subject}"></td>
905 <th align=left nowrap>|.$locale->text('Message').qq|</th>
908 <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
919 map { delete $form->{$_} } qw(action email cc bcc subject message formname sendmode format header override);
921 # save all other variables
922 foreach $key (keys %$form) {
923 $form->{$key} =~ s/\"/"/g;
924 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
931 <td><hr size=3 noshade></td>
935 <input type=hidden name=nextsub value=send_email>
938 <input name=action class=submit type=submit value="|.$locale->text('Continue').qq|">
945 $lxdebug->leave_sub();
950 $lxdebug->enter_sub();
952 $old_form = new Form;
954 map { $old_form->{$_} = $form->{$_} } keys %$form;
955 $old_form->{media} = $form->{oldmedia};
957 &print_form($old_form);
959 $lxdebug->leave_sub();
965 $lxdebug->enter_sub();
967 $form->{sendmode} = "attachment";
968 $form->{copies} = 3 unless $form->{copies};
970 $form->{PD}{$form->{formname}} = "selected";
971 $form->{DF}{$form->{format}} = "";
972 $form->{OP}{$form->{media}} = "selected";
973 $form->{SM}{$form->{sendmode}} = "selected";
976 if ($form->{type} eq 'purchase_order') {
977 $type = qq|<select name=formname>
978 <option value=purchase_order $form->{PD}{purchase_order}>|.$locale->text('Purchase Order').qq|
979 <option value=bin_list $form->{PD}{bin_list}>|.$locale->text('Bin List');
982 if ($form->{type} eq 'sales_order') {
983 $type = qq|<select name=formname>
984 <option value=sales_order $form->{PD}{sales_order}>|.$locale->text('Confirmation').qq|
985 <option value=pick_list $form->{PD}{pick_list}>|.$locale->text('Pick List').qq|
986 <option value=packing_list $form->{PD}{packing_list}>|.$locale->text('Packing List');
989 if ($form->{type} =~ /_quotation$/) {
990 $type = qq|<select name=formname>
991 <option value="$`_quotation" $form->{PD}{"$`_quotation"}>|.$locale->text('Quotation').qq|
995 if ($form->{type} eq 'invoice') {
996 $type = qq|<select name=formname>
997 <option value=invoice $form->{PD}{invoice}>|.$locale->text('Invoice');
1000 if ($form->{type} eq 'ship_order') {
1001 $type = qq|<select name=formname>
1002 <option value=pick_list $form->{PD}{pick_list}>|.$locale->text('Pick List').qq|
1003 <option value=packing_list $form->{PD}{packing_list}>|.$locale->text('Packing List');
1006 if ($form->{type} eq 'receive_order') {
1007 $type = qq|<select name=formname>
1008 <option value=bin_list $form->{PD}{bin_list}>|.$locale->text('Bin List');
1011 if ($form->{media} eq 'email') {
1012 $media = qq|<select name=sendmode>
1013 <option value=attachment $form->{SM}{attachment}>|.$locale->text('Attachment').qq|
1014 <option value=inline $form->{SM}{inline}>|.$locale->text('In-line');
1016 $media = qq|<select name=media>
1017 <option value=screen $form->{OP}{screen}>|.$locale->text('Screen');
1018 if ($myconfig{printer} && $latex) {
1020 <option value=printer $form->{OP}{printer}>|.$locale->text('Printer');
1024 <option value=queue $form->{OP}{queue}>|.$locale->text('Queue');
1028 $format = qq|<select name=format>
1029 <option value=html $form->{DF}{html}>html|;
1032 $format = qq|<select name=format>
1033 <option value=pdf $form->{DF}{pdf}>|.$locale->text('PDF').qq|
1034 <option value=html $form->{DF}{html}>html
1035 <option value=postscript $form->{DF}{postscript}>|.$locale->text('Postscript');
1038 $language = qq|<select name=language>
1039 <option value=""></option>|;
1040 %lang = (de=>"deutsch", en=>"englisch", fr=>"französisch");
1041 foreach $item (keys %lang) {
1042 if ($form->{language} eq $item) {
1043 $language .= qq|<option value="$item" selected>$lang{$item}</option>|;
1045 $language .= qq|<option value="$item">$lang{$item}</option>|;
1050 <table width=100% cellspacing=0 cellpadding=0>
1055 <td>$type</select></td>
1056 <td>$language</select</td>
1057 <td>$format</select></td>
1058 <td>$media</select></td>
1061 if ($myconfig{printer} && $latex && $form->{media} ne 'email') {
1063 <td>|.$locale->text('Copies').qq|
1064 <input name=copies size=2 value=$form->{copies}></td>
1068 $form->{groupitems} = "checked" if $form->{groupitems};
1071 <td>|.$locale->text('Group Items').qq|</td>
1072 <td><input name=groupitems type=checkbox class=checkbox $form->{groupitems}></td>
1081 if ($form->{printed} =~ /$form->{formname}/) {
1083 <th>\||.$locale->text('Printed').qq|\|</th>
1087 if ($form->{emailed} =~ /$form->{formname}/) {
1089 <th>\||.$locale->text('E-mailed').qq|\|</th>
1093 if ($form->{queued} =~ /$form->{formname}/) {
1095 <th>\||.$locale->text('Queued').qq|\|</th>
1108 $lxdebug->leave_sub();
1114 $lxdebug->enter_sub();
1116 # if this goes to the printer pass through
1117 if ($form->{media} eq 'printer' || $form->{media} eq 'queue') {
1118 $form->error($locale->text('Select postscript or PDF!')) if ($form->{format} !~ /(postscript|pdf)/);
1120 $old_form = new Form;
1121 map { $old_form->{$_} = $form->{$_} } keys %$form;
1124 &print_form($old_form);
1126 $lxdebug->leave_sub();
1131 $lxdebug->enter_sub();
1132 my ($old_form) = @_;
1137 $numberfld = "invnumber";
1139 $display_form = ($form->{display_form}) ? $form->{display_form} : "display_form";
1141 # $form->{"notes"} will be overridden by the customer's/vendor's "notes" field. So save it here.
1142 $form->{$form->{"formname"} . "notes"} = $form->{"notes"};
1144 if ($form->{formname} eq "invoice") {
1145 $form->{label} = $locale->text('Invoice');
1147 if ($form->{formname} eq "packing_list") {
1148 # this is from an invoice
1149 $form->{label} = $locale->text('Packing List');
1151 if ($form->{formname} eq 'sales_order') {
1154 $form->{"${inv}date"} = $form->{transdate};
1155 $form->{label} = $locale->text('Sales Order');
1156 $numberfld = "sonumber";
1159 if ($form->{formname} eq 'packing_list' && $form->{type} ne 'invoice') {
1160 # we use the same packing list as from an invoice
1163 $form->{invdate} = $form->{"${inv}date"} = $form->{transdate};
1164 $form->{label} = $locale->text('Packing List');
1167 if ($form->{formname} eq 'pick_list') {
1170 $form->{"${inv}date"} = ($form->{transdate}) ? $form->{transdate} : $form->{invdate};
1171 $form->{label} = $locale->text('Pick List');
1172 $order = 1 unless $form->{type} eq 'invoice';
1174 if ($form->{formname} eq 'purchase_order') {
1177 $form->{"${inv}date"} = $form->{transdate};
1178 $form->{label} = $locale->text('Purchase Order');
1179 $numberfld = "ponumber";
1182 if ($form->{formname} eq 'bin_list') {
1185 $form->{"${inv}date"} = $form->{transdate};
1186 $form->{label} = $locale->text('Bin List');
1189 if ($form->{formname} eq 'sales_quotation') {
1192 $form->{"${inv}date"} = $form->{transdate};
1193 $form->{label} = $locale->text('Quotation');
1194 $numberfld = "sqnumber";
1197 if ($form->{formname} eq 'request_quotation') {
1200 $form->{"${inv}date"} = $form->{transdate};
1201 $form->{label} = $locale->text('Quotation');
1202 $numberfld = "rfqnumber";
1206 $form->isblank("email", $locale->text('E-mail address missing!')) if ($form->{media} eq 'email');
1207 $form->isblank("${inv}date", $locale->text($form->{label} .' Date missing!'));
1209 # $locale->text('Invoice Number missing!')
1210 # $locale->text('Invoice Date missing!')
1211 # $locale->text('Packing List Number missing!')
1212 # $locale->text('Packing List Date missing!')
1213 # $locale->text('Order Number missing!')
1214 # $locale->text('Order Date missing!')
1215 # $locale->text('Quotation Number missing!')
1216 # $locale->text('Quotation Date missing!')
1220 if (! $form->{"${inv}number"}) {
1221 $form->{"${inv}number"} = $form->update_defaults(\%myconfig, $numberfld);
1222 if ($form->{media} ne 'email') {
1223 $form->{rowcount}--;
1224 &{ "$display_form" };
1231 # Save the email address given in the form because it should override the setting saved for the customer/vendor.
1232 my ($saved_email, $saved_cc, $saved_bcc) = ($form->{"email"}, $form->{"cc"}, $form->{"bcc"});
1234 $language = $form->{language};
1235 &{ "$form->{vc}_details" };
1236 $form->{language} = $language;
1238 $form->{"email"} = $saved_email if ($saved_email);
1239 $form->{"cc"} = $saved_cc if ($saved_cc);
1240 $form->{"bcc"} = $saved_bcc if ($saved_bcc);
1243 foreach $i (1 .. $form->{rowcount}) {
1244 push @a, ("partnumber_$i", "description_$i", "partsgroup_$i", "serialnumber_$i", "bin_$i", "unit_$i");
1246 map { push @a, "${_}_description" } split / /, $form->{taxaccounts};
1248 $ARAP = ($form->{vc} eq 'customer') ? "AR" : "AP";
1251 # format payment dates
1252 for $i (1 .. $form->{paidaccounts} - 1) {
1253 $form->{"datepaid_$i"} = $locale->date(\%myconfig, $form->{"datepaid_$i"});
1254 push @a, "${ARAP}_paid_$i", "source_$i", "memo_$i";
1257 $form->format_string(@a);
1259 ($form->{employee}) = split /--/, $form->{employee};
1260 ($form->{warehouse}, $form->{warehouse_id}) = split /--/, $form->{warehouse};
1262 # create the form variables
1264 OE->order_details(\%myconfig, \%$form);
1266 IS->invoice_details(\%myconfig, \%$form, $locale);
1269 map { $form->{$_} = $locale->date(\%myconfig, $form->{$_}, 1) } ("${inv}date", "${due}date", "shippingdate");
1272 @a = qw(name street zipcode city country);
1275 # if there is no shipto fill it in from billto
1276 foreach $item (@a) {
1277 if ($form->{"shipto$item"}) {
1284 if ($form->{formname} eq 'purchase_order' || $form->{formname} eq 'request_quotation') {
1285 $form->{shiptoname} = $myconfig{company};
1286 $form->{shiptostreet} = $myconfig{address};
1288 map { $form->{"shipto$_"} = $form->{$_} } @a;
1292 $form->{notes} =~ s/^\s+//g;
1294 # some of the stuff could have umlauts so we translate them
1295 push @a, qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptoemail shippingpoint shipvia company address signature employee contact);
1298 push @a, ("${inv}date", "${due}date", email, cc, bcc);
1300 $form->format_string(@a);
1303 $form->{templates} = "$myconfig{templates}";
1304 if ($form->{language} ne "") {
1305 $form->{language} = "_".$form->{language};
1308 $form->{IN} = "$form->{formname}$form->{language}.html";
1309 if ($form->{format} eq 'postscript') {
1310 $form->{postscript} = 1;
1311 $form->{IN} =~ s/html$/tex/;
1313 if ($form->{format} eq 'pdf') {
1315 $form->{IN} =~ s/html$/tex/;
1318 if ($form->{media} eq 'printer') {
1319 $form->{OUT} = "| $myconfig{printer}";
1320 $form->{printed} .= " $form->{formname}";
1321 $form->{printed} =~ s/^ //;
1323 $printed = $form->{printed};
1325 if ($form->{media} eq 'email') {
1326 $form->{subject} = qq|$form->{label} $form->{"${inv}number"}| unless $form->{subject};
1328 $form->{OUT} = "$sendmail";
1330 $form->{emailed} .= " $form->{formname}";
1331 $form->{emailed} =~ s/^ //;
1333 $emailed = $form->{emailed};
1336 if ($form->{media} eq 'queue') {
1337 %queued = split / /, $form->{queued};
1339 if ($filename = $queued{$form->{formname}}) {
1340 $form->{queued} =~ s/$form->{formname} $filename//;
1341 unlink "$spool/$filename";
1342 $filename =~ s/\..*$//g;
1349 $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
1350 $form->{OUT} = ">$spool/$filename";
1353 $form->{queued} .= " $form->{formname} $filename";
1355 $form->{queued} =~ s/^ //;
1357 $queued = $form->{queued};
1360 $form->parse_template(\%myconfig, $userspath);
1362 $form->{callback} = "";
1364 if ($form->{media} eq 'email') {
1365 $form->{message} = $locale->text('sent') unless $form->{message};
1367 $message = $form->{message};
1369 # if we got back here restore the previous form
1370 if ($form->{media} =~ /(printer|email|queue)/) {
1372 $form->update_status(\%myconfig) if ($form->{media} eq 'queue' && $form->{id});
1376 $old_form->{"${inv}number"} = $form->{"${inv}number"};
1378 # restore and display form
1379 map { $form->{$_} = $old_form->{$_} } keys %$old_form;
1381 $form->{queued} = $queued;
1382 $form->{printed} = $printed;
1383 $form->{emailed} = $emailed;
1384 $form->{message} = $message;
1386 $form->{rowcount}--;
1387 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
1389 for $i (1 .. $form->{paidaccounts}) {
1390 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
1393 &{ "$display_form" };
1397 $msg = ($form->{media} eq 'printer') ? $locale->text('sent to printer') : $locale->text('emailed to')." $form->{email}";
1398 $form->redirect(qq|$form->{label} $form->{"${inv}number"} $msg|);
1401 $lxdebug->leave_sub();
1405 sub customer_details {
1406 $lxdebug->enter_sub();
1408 IS->customer_details(\%myconfig, \%$form);
1409 $lxdebug->leave_sub();
1413 sub vendor_details {
1414 $lxdebug->enter_sub();
1416 IR->vendor_details(\%myconfig, \%$form);
1418 $lxdebug->leave_sub();
1423 $lxdebug->enter_sub();
1425 $form->{postasnew} = 1;
1426 map { delete $form->{$_} } qw(printed emailed queued);
1430 $lxdebug->leave_sub();
1435 $lxdebug->enter_sub();
1437 $title = $form->{title};
1438 $form->{title} = $locale->text('Ship to');
1440 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
1442 # get details for name
1443 &{ "$form->{vc}_details" };
1445 $number = ($form->{vc} eq 'customer') ? $locale->text('Customer Number') : $locale->text('Vendor Number');
1447 $nextsub = ($form->{display_form}) ? $form->{display_form} : "display_form";
1449 $form->{rowcount}--;
1456 <form method=post action=$form->{script}>
1462 <tr class=listheading>
1463 <th class=listheading colspan=2 width=50%>|.$locale->text('Billing Address').qq|</th>
1464 <th class=listheading width=50%>|.$locale->text('Shipping Address').qq|</th>
1466 <tr height="5"></tr>
1468 <th align=right nowrap>$number</th>
1469 <td>$form->{"$form->{vc}number"}</td>
1472 <th align=right nowrap>|.$locale->text('Company Name').qq|</th>
1473 <td>$form->{name}</td>
1474 <td><input name=shiptoname size=35 value="$form->{shiptoname}"></td>
1477 <th align=right nowrap>|.$locale->text('Street').qq|</th>
1478 <td>$form->{street}</td>
1479 <td><input name=shiptostreet size=35 value="$form->{shiptostreet}"></td>
1482 <th align=right nowrap>|.$locale->text('Zipcode').qq|</th>
1483 <td>$form->{zipcode}</td>
1484 <td><input name=shiptozipcode size=35 value="$form->{shiptozipcode}"></td>
1487 <th align=right nowrap>|.$locale->text('City').qq|</th>
1488 <td>$form->{city}</td>
1489 <td><input name=shiptocity size=35 value="$form->{shiptocity}"></td>
1492 <th align=right nowrap>|.$locale->text('Country').qq|</th>
1493 <td>$form->{country}</td>
1494 <td><input name=shiptocountry size=35 value="$form->{shiptocountry}"></td>
1497 <th align=right nowrap>|.$locale->text('Contact').qq|</th>
1498 <td>$form->{contact}</td>
1499 <td><input name=shiptocontact size=35 value="$form->{shiptocontact}"></td>
1502 <th align=right nowrap>|.$locale->text('Phone').qq|</th>
1503 <td>$form->{"$form->{vc}phone"}</td>
1504 <td><input name=shiptophone size=20 value="$form->{shiptophone}"></td>
1507 <th align=right nowrap>|.$locale->text('Fax').qq|</th>
1508 <td>$form->{"$form->{vc}fax"}</td>
1509 <td><input name=shiptofax size=20 value="$form->{shiptofax}"></td>
1512 <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
1513 <td>$form->{email}</td>
1514 <td><input name=shiptoemail size=35 value="$form->{shiptoemail}"></td>
1521 <input type=hidden name=nextsub value=$nextsub>
1525 map { delete $form->{$_} } qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax shiptoemail header);
1526 $form->{title} = $title;
1528 foreach $key (keys %$form) {
1529 $form->{$key} =~ s/\"/"/g;
1530 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1538 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
1545 $lxdebug->leave_sub();
1550 $lxdebug->enter_sub();
1555 $form->{old_callback} = $form->escape($form->{callback},1);
1556 $form->{callback} = $form->escape("$form->{script}?action=display_form",1);
1557 $form->{old_callback} = $form->escape($form->{old_callback},1);
1559 delete $form->{action};
1560 $customer = $form->{customer};
1561 map { $form->{"old_$_"} = $form->{"${_}_$row"} } qw(partnumber description);
1563 # save all other form variables in a previousform variable
1564 $form->{row} = $row;
1565 foreach $key (keys %$form) {
1567 $form->{$key} =~ s/&/%26/g;
1568 $previousform .= qq|$key=$form->{$key}&|;
1571 $previousform = $form->escape($previousform, 1);
1573 $form->{script} = "licenses.pl";
1577 map { $form->{$_} = $form->{"old_$_"} } qw(partnumber description);
1578 map { $form->{$_} = $form->escape($form->{$_},1) } qw(partnumber description);
1579 $form->{callback} = 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|;
1582 $lxdebug->leave_sub();