1 ######################################################################
2 # SQL-Ledger, Accounting
5 # Author: Dieter Simader
6 # Email: dsimader@sql-ledger.org
7 # Web: http://www.sql-ledger.org
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #######################################################################
24 # common routines used in is, ir, oe
26 #######################################################################
28 # any custom scripts for this one
29 if (-f "$form->{path}/custom_io.pl") {
30 eval { require "$form->{path}/custom_io.pl"; };
32 if (-f "$form->{path}/$form->{login}_io.pl") {
33 eval { require "$form->{path}/$form->{login}_io.pl"; };
41 # this is for our long dates
42 # $locale->text('January')
43 # $locale->text('February')
44 # $locale->text('March')
45 # $locale->text('April')
46 # $locale->text('May ')
47 # $locale->text('June')
48 # $locale->text('July')
49 # $locale->text('August')
50 # $locale->text('September')
51 # $locale->text('October')
52 # $locale->text('November')
53 # $locale->text('December')
55 # this is for our short month
56 # $locale->text('Jan')
57 # $locale->text('Feb')
58 # $locale->text('Mar')
59 # $locale->text('Apr')
60 # $locale->text('May')
61 # $locale->text('Jun')
62 # $locale->text('Jul')
63 # $locale->text('Aug')
64 # $locale->text('Sep')
65 # $locale->text('Oct')
66 # $locale->text('Nov')
67 # $locale->text('Dec')
73 @column_index = qw(runningnumber partnumber description qty);
75 if ($form->{type} eq "sales_order") {
76 push @column_index, "ship";
77 $column_data{ship} = qq|<th class=listheading align=center width="auto">|.$locale->text('Ship').qq|</th>|;
79 if ($form->{type} eq "purchase_order") {
80 push @column_index, "ship";
81 $column_data{ship} = qq|<th class=listheading align=center width="auto">|.$locale->text('Recd').qq|</th>|;
84 foreach $item (qw(projectnumber partsgroup)) {
85 $form->{"select$item"} = $form->unescape($form->{"select$item"}) if $form->{"select$item"};
88 if ($form->{language_code} ne $form->{oldlanguage_code}) {
90 $form->get_partsgroup(\%myconfig, { language_code => $form->{language_code} });
91 if (@ { $form->{all_partsgroup} }) {
92 $form->{selectpartsgroup} = "<option>\n";
93 foreach $ref (@ { $form->{all_partsgroup} }) {
94 if ($ref->{translation}) {
95 $form->{selectpartsgroup} .= qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{translation}\n|;
97 $form->{selectpartsgroup} .= qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{partsgroup}\n|;
101 $form->{oldlanguage_code} = $form->{language_code};
105 push @column_index, qw(unit sellprice discount linetotal);
107 my $colspan = $#column_index + 1;
109 $form->{invsubtotal} = 0;
110 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
112 $column_data{runningnumber} = qq|<th class=listheading nowrap>|.$locale->text('No.').qq|</th>|;
113 $column_data{partnumber} = qq|<th class=listheading nowrap>|.$locale->text('Number').qq|</th>|;
114 $column_data{description} = qq|<th class=listheading nowrap>|.$locale->text('Description').qq|</th>|;
115 $column_data{qty} = qq|<th class=listheading nowrap>|.$locale->text('Qty').qq|</th>|;
116 $column_data{unit} = qq|<th class=listheading nowrap>|.$locale->text('Unit').qq|</th>|;
117 $column_data{sellprice} = qq|<th class=listheading nowrap>|.$locale->text('Price').qq|</th>|;
118 $column_data{discount} = qq|<th class=listheading>%</th>|;
119 $column_data{linetotal} = qq|<th class=listheading nowrap>|.$locale->text('Extended').qq|</th>|;
120 $column_data{bin} = qq|<th class=listheading nowrap>|.$locale->text('Bin').qq|</th>|;
126 <tr class=listheading>|;
128 map { print "\n$column_data{$_}" } @column_index;
135 $deliverydate = $locale->text('Delivery Date');
136 $serialnumber = $locale->text('Serial No.');
137 $projectnumber = $locale->text('Project');
138 $group = $locale->text('Group');
139 $sku = $locale->text('SKU');
141 $delvar = 'deliverydate';
143 if ($form->{type} =~ /_(order|quotation)$/) {
144 $reqdate = $locale->text('Required by');
148 $exchangerate = $form->parse_amount(\%myconfig, $form->{exchangerate});
149 $exchangerate = ($exchangerate) ? $exchangerate : 1;
151 for $i (1 .. $numrows) {
153 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(qty ship discount sellprice);
155 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
157 $decimalplaces = ($dec > 2) ? $dec : 2;
159 if (($form->{"qty_$i"} != $form->{"oldqty_$i"}) || ($form->{currency} ne $form->{oldcurrency})) {
160 # check for a pricematrix
161 @a = split / /, $form->{"pricematrix_$i"};
162 if ((scalar @a) > 2 || $form->{currency} ne $form->{oldcurrency}) {
164 ($q, $p) = split /:/, $item;
165 if ($p != 0 && $form->{"qty_$i"} > $q) {
166 $form->{"sellprice_$i"} = $form->round_amount($p / $exchangerate, $decimalplaces);
172 $discount = $form->round_amount($form->{"sellprice_$i"} * $form->{"discount_$i"}/100, $decimalplaces);
173 $linetotal = $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
174 $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
176 map { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) } qw(partnumber sku description unit);
179 <p><b>$sku</b> $form->{"sku_$i"}| if ($form->{vc} eq 'vendor' && $form->{"sku_$i"});
182 if ($form->{selectpartsgroup}) {
186 <input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">|;
187 ($form->{"partsgroup_$i"}) = split /--/, $form->{"partsgroup_$i"};
188 $partsgroup .= $form->{"partsgroup_$i"};
189 $partsgroup = "" unless $form->{"partsgroup_$i"};
195 <input name="${delvar}_$i" size=11 title="$myconfig{dateformat}" value="$form->{"${delvar}_$i"}">
198 $column_data{runningnumber} = qq|<td><input name="runningnumber_$i" size=3 value=$i></td>|;
199 $column_data{partnumber} = qq|<td><input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}">$skunumber</td>|;
201 if (($rows = $form->numtextrows($form->{"description_$i"}, 25, 6)) > 1) {
202 $column_data{description} = qq|<td><textarea name="description_$i" rows=$rows cols=25 wrap=soft>$form->{"description_$i"}</textarea>$partsgroup</td>|;
204 $column_data{description} = qq|<td><input name="description_$i" size=30 value="$form->{"description_$i"}">$partsgroup</td>|;
207 $column_data{qty} = qq|<td align=right><input name="qty_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"qty_$i"}).qq|></td>|;
208 $column_data{ship} = qq|<td align=right><input name="ship_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"ship_$i"}).qq|></td>|;
209 $column_data{unit} = qq|<td><input name="unit_$i" size=5 value="$form->{"unit_$i"}"></td>|;
210 $column_data{sellprice} = qq|<td align=right><input name="sellprice_$i" size=9 value=|.$form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces).qq|></td>|;
211 $column_data{discount} = qq|<td align=right><input name="discount_$i" size=3 value=|.$form->format_amount(\%myconfig, $form->{"discount_$i"}).qq|></td>|;
212 $column_data{linetotal} = qq|<td align=right>|.$form->format_amount(\%myconfig, $linetotal, 2).qq|</td>|;
213 $column_data{bin} = qq|<td>$form->{"bin_$i"}</td>|;
218 map { print "\n$column_data{$_}" } @column_index;
223 <input type=hidden name="orderitems_id_$i" value=$form->{"orderitems_id_$i"}>
225 <input type=hidden name="id_$i" value=$form->{"id_$i"}>
226 <input type=hidden name="inventory_accno_$i" value=$form->{"inventory_accno_$i"}>
227 <input type=hidden name="bin_$i" value="$form->{"bin_$i"}">
228 <input type=hidden name="weight_$i" value="$form->{"weight_$i"}">
229 <input type=hidden name="income_accno_$i" value=$form->{"income_accno_$i"}>
230 <input type=hidden name="expense_accno_$i" value=$form->{"expense_accno_$i"}>
231 <input type=hidden name="listprice_$i" value="$form->{"listprice_$i"}">
232 <input type=hidden name="assembly_$i" value="$form->{"assembly_$i"}">
233 <input type=hidden name="taxaccounts_$i" value="$form->{"taxaccounts_$i"}">
234 <input type=hidden name="pricematrix_$i" value="$form->{"pricematrix_$i"}">
235 <input type=hidden name="oldqty_$i" value="$form->{"qty_$i"}">
236 <input type=hidden name="sku_$i" value="$form->{"sku_$i"}">
240 $form->{selectprojectnumber} =~ s/ selected//;
241 $form->{selectprojectnumber} =~ s/(<option value="\Q$form->{"projectnumber_$i"}\E")/$1 selected/;
244 <b>$projectnumber</b>
245 <select name="projectnumber_$i">$form->{selectprojectnumber}</select>
246 | if $form->{selectprojectnumber};
249 <b>$serialnumber</b> <input name="serialnumber_$i" size=15 value="$form->{"serialnumber_$i"}">| if $form->{type} !~ /_quotation/;
252 if ($i == $numrows) {
253 if ($form->{selectpartsgroup}) {
256 <select name="partsgroup_$i">$form->{selectpartsgroup}</select>
269 <td colspan=$colspan>
277 <td colspan=$colspan><hr size=1 noshade></td>
283 map { $form->{"${_}_base"} += $linetotal } (split / /, $form->{"taxaccounts_$i"});
285 $form->{invsubtotal} += $linetotal;
296 <input type=hidden name=oldcurrency value=$form->{currency}>
297 <input type=hidden name=audittrail value="$form->{audittrail}">
299 <input type=hidden name=selectpartsgroup value="|.$form->escape($form->{selectpartsgroup},1).qq|">
300 <input type=hidden name=selectprojectnumber value="|.$form->escape($form->{selectprojectnumber},1).qq|">
308 if ($form->{vc} eq "vendor") {
309 @column_index = qw(ndx partnumber sku description partsgroup onhand sellprice);
311 @column_index = qw(ndx partnumber description partsgroup onhand sellprice);
314 $column_data{ndx} = qq|<th> </th>|;
315 $column_data{partnumber} = qq|<th class=listheading>|.$locale->text('Number').qq|</th>|;
316 $column_data{sku} = qq|<th class=listheading>|.$locale->text('SKU').qq|</th>|;
317 $column_data{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</th>|;
318 $column_data{partsgroup} = qq|<th class=listheading>|.$locale->text('Group').qq|</th>|;
319 $column_data{sellprice} = qq|<th class=listheading>|.$locale->text('Price').qq|</th>|;
320 $column_data{onhand} = qq|<th class=listheading>|.$locale->text('Qty').qq|</th>|;
322 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
324 # list items with radio button on a form
327 $title = $locale->text('Select from one of the items below');
332 <form method=post action="$form->{script}#end">
336 <th class=listtop>$title</th>
345 <tr class=listheading>|;
347 map { print "\n$column_data{$_}" } @column_index;
354 foreach $ref (@{ $form->{item_list} }) {
355 $checked = ($i++) ? "" : "checked";
357 map { $ref->{$_} = $form->quote($ref->{$_}) } qw(sku partnumber description unit);
359 $ref->{sellprice} = $form->round_amount($ref->{sellprice} * (1 - $form->{tradediscount}), 2);
361 $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
362 $column_data{partnumber} = qq|<td>$ref->{partnumber}</td>|;
363 $column_data{sku} = qq|<td>$ref->{sku}</td>|;
364 $column_data{description} = qq|<td>$ref->{description}</td>|;
365 $column_data{partsgroup} = qq|<td>$ref->{partsgroup}</td>|;
366 $column_data{sellprice} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{sellprice} / $exchangerate, 2, " ").qq|</td>|;
367 $column_data{onhand} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{onhand}, '', " ").qq|</td>|;
371 <tr class=listrow$j>|;
373 map { print "\n$column_data{$_}" } @column_index;
378 <input name="new_partnumber_$i" type=hidden value="$ref->{partnumber}">
379 <input name="new_sku_$i" type=hidden value="$ref->{sku}">
380 <input name="new_description_$i" type=hidden value="$ref->{description}">
381 <input name="new_partsgroup_$i" type=hidden value="$ref->{partsgroup}">
382 <input name="new_partsgroup_id_$i" type=hidden value="$ref->{partsgroup_id}">
383 <input name="new_bin_$i" type=hidden value="$ref->{bin}">
384 <input name="new_weight_$i" type=hidden value=$ref->{weight}>
385 <input name="new_sellprice_$i" type=hidden value=$ref->{sellprice}>
386 <input name="new_listprice_$i" type=hidden value=$ref->{listprice}>
387 <input name="new_lastcost_$i" type=hidden value=$ref->{lastcost}>
388 <input name="new_onhand_$i" type=hidden value=$ref->{onhand}>
389 <input name="new_inventory_accno_$i" type=hidden value=$ref->{inventory_accno}>
390 <input name="new_income_accno_$i" type=hidden value=$ref->{income_accno}>
391 <input name="new_expense_accno_$i" type=hidden value=$ref->{expense_accno}>
392 <input name="new_unit_$i" type=hidden value="$ref->{unit}">
393 <input name="new_weight_$i" type=hidden value="$ref->{weight}">
394 <input name="new_assembly_$i" type=hidden value="$ref->{assembly}">
395 <input name="new_taxaccounts_$i" type=hidden value="$ref->{taxaccounts}">
396 <input name="new_pricematrix_$i" type=hidden value="$ref->{pricematrix}">
398 <input name="new_id_$i" type=hidden value=$ref->{id}>
409 <td><hr size=3 noshade></td>
413 <input name=lastndx type=hidden value=$i>
417 # delete action variable
418 map { delete $form->{$_} } qw(action item_list header);
423 <input type=hidden name=nextsub value=item_selected>
426 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
439 # replace the last row with the checked row
440 $i = $form->{rowcount};
441 $i = $form->{assembly_rows} if ($form->{item} eq 'assembly');
446 # if there was a price entered, override it
447 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
449 map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} } qw(id partnumber sku description sellprice listprice lastcost inventory_accno income_accno expense_accno bin unit weight assembly taxaccounts pricematrix);
451 $form->{"partsgroup_$i"} = qq|$form->{"new_partsgroup_$j"}--$form->{"new_partsgroup_id_$j"}|;
453 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
455 $decimalplaces = ($dec > 2) ? $dec : 2;
458 $form->{"sellprice_$i"} = $sellprice;
460 # if there is an exchange rate adjust sellprice
461 if (($form->{exchangerate} * 1) != 0) {
462 $form->{"sellprice_$i"} /= $form->{exchangerate};
463 $form->{"sellprice_$i"} = $form->round_amount($form->{"sellprice_$i"}, $decimalplaces);
467 if (($form->{exchangerate} * 1) != 0) {
468 map { $form->{"${_}_$i"} /= $form->{exchangerate} } qw(listprice lastcost);
471 # this is for the assembly
472 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(sellprice listprice weight);
474 $form->{sellprice} += ($form->{"sellprice_$i"} * $form->{"qty_$i"});
475 $form->{weight} += ($form->{"weight_$i"} * $form->{"qty_$i"});
477 $amount = $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) * $form->{"qty_$i"};
478 map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"});
479 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
481 $form->{creditremaining} -= $amount;
483 $form->{"runningnumber_$i"} = $i;
485 # delete all the new_ variables
486 for $i (1 .. $form->{lastndx}) {
487 map { delete $form->{"new_${_}_$i"} } qw(partnumber sku description sellprice bin listprice lastcost inventory_accno income_accno expense_accno unit assembly taxaccounts id pricematrix weight);
490 map { delete $form->{$_} } qw(ndx lastndx nextsub);
493 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice lastcost) if $form->{item} ne 'assembly';
502 if ($form->{language_code} && $form->{"description_$form->{rowcount}"}) {
503 $form->error($locale->text('Translation not on file!'));
507 $form->{old_callback} = $form->escape($form->{callback},1);
508 $form->{callback} = $form->escape("$form->{script}?action=display_form",1);
511 delete $form->{action};
513 # save all other form variables in a previousform variable
514 if (!$form->{previousform}) {
515 foreach $key (keys %$form) {
517 $form->{$key} =~ s/&/%26/g;
518 $form->{previousform} .= qq|$key=$form->{$key}&|;
520 chop $form->{previousform};
521 $form->{previousform} = $form->escape($form->{previousform}, 1);
524 $i = $form->{rowcount};
525 map { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) } qw(partnumber description);
532 <h4 class=error>|.$locale->text('Item not on file!').qq|</h4>|;
534 if ($myconfig{acs} !~ /(Goods \& Services--Add Part|Goods \& Services--Add Service)/) {
537 <h4>|.$locale->text('What type of item is this?').qq|</h4>
539 <form method=post action=ic.pl>
543 <input class=radio type=radio name=item value=part checked> |.$locale->text('Part')
545 <input class=radio type=radio name=item value=service> |.$locale->text('Service')
548 <input type=hidden name=previousform value="$form->{previousform}">
549 <input type=hidden name=partnumber value="$form->{"partnumber_$i"}">
550 <input type=hidden name=description value="$form->{"description_$i"}">
551 <input type=hidden name=rowcount value=$form->{rowcount}>
553 <input type=hidden name=path value=$form->{path}>
554 <input type=hidden name=login value=$form->{login}>
555 <input type=hidden name=sessionid value=$form->{sessionid}>
557 <input type=hidden name=nextsub value=add>
560 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
576 # if we have a display_form
577 if ($form->{display_form}) {
578 &{ "$form->{display_form}" };
584 $numrows = ++$form->{rowcount};
585 $subroutine = "display_row";
587 if ($form->{item} eq 'part') {
588 # create makemodel rows
589 &makemodel_row(++$form->{makemodel_rows});
591 &vendor_row(++$form->{vendor_rows});
593 $numrows = ++$form->{customer_rows};
594 $subroutine = "customer_row";
596 if ($form->{item} eq 'assembly') {
597 # create makemodel rows
598 &makemodel_row(++$form->{makemodel_rows});
600 $numrows = ++$form->{customer_rows};
601 $subroutine = "customer_row";
603 if ($form->{item} eq 'service') {
604 &vendor_row(++$form->{vendor_rows});
606 $numrows = ++$form->{customer_rows};
607 $subroutine = "customer_row";
609 if ($form->{item} eq 'labor') {
614 &{ $subroutine }($numrows) if $numrows;
628 my @flds = qw(id partnumber sku description qty ship sellprice unit discount inventory_accno income_accno expense_accno listprice taxaccounts bin assembly weight projectnumber runningnumber serialnumber partsgroup reqdate pricematrix);
630 # remove any makes or model rows
631 if ($form->{item} eq 'part') {
632 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(listprice sellprice lastcost weight rop markup);
636 @flds = qw(make model);
639 for $i (1 .. $form->{makemodel_rows}) {
640 if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
644 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
649 $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
650 $form->{makemodel_rows} = $count;
655 } elsif ($form->{item} eq 'service') {
657 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(sellprice listprice lastcost markup);
663 } elsif ($form->{item} eq 'assembly') {
665 $form->{sellprice} = 0;
667 $form->{lastcost} = 0;
668 $form->{listprice} = 0;
670 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(rop stock markup);
673 @flds = qw(id qty unit bom adj partnumber description sellprice listprice weight runningnumber partsgroup);
677 for my $i (1 .. ($form->{assembly_rows} - 1)) {
678 if ($form->{"qty_$i"}) {
682 $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
684 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
686 map { $form->{$_} += ($form->{"${_}_$i"} * $form->{"qty_$i"}) } qw(sellprice listprice weight lastcost);
692 if ($form->{markup} && $form->{markup} != $form->{oldmarkup}) {
693 $form->{sellprice} = 0;
697 map { $form->{$_} = $form->round_amount($form->{$_}, 2) } qw(sellprice lastcost listprice);
699 $form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows});
700 $form->{assembly_rows} = $count;
703 @flds = qw(make model);
706 for my $i (1 .. ($form->{makemodel_rows})) {
707 if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
711 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
716 $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
717 $form->{makemodel_rows} = $count;
723 # this section applies to invoices and orders
724 # remove any empty numbers
728 if ($form->{rowcount}) {
729 for my $i (1 .. $form->{rowcount} - 1) {
730 if ($form->{"partnumber_$i"}) {
734 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
739 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
740 $form->{rowcount} = $count;
742 $form->{creditremaining} -= &invoicetotal;
754 if ($form->{markup}) {
755 if ($form->{markup} != $form->{oldmarkup}) {
756 if ($form->{lastcost}) {
757 $form->{sellprice} = $form->{lastcost} * (1 + $form->{markup}/100);
758 $form->{sellprice} = $form->round_amount($form->{sellprice}, 2);
760 $form->{lastcost} = $form->{sellprice} / (1 + $form->{markup}/100);
761 $form->{lastcost} = $form->round_amount($form->{lastcost}, 2);
765 if ($form->{lastcost}) {
766 $form->{markup} = $form->round_amount(((1 - $form->{sellprice} / $form->{lastcost}) * 100), 1);
768 $form->{markup} = "" if $form->{markup} == 0;
776 $form->{oldinvtotal} = 0;
777 # add all parts and deduct paid
778 map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
780 my ($amount, $sellprice, $discount, $qty);
782 for my $i (1 .. $form->{rowcount}) {
783 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
784 $discount = $form->parse_amount(\%myconfig, $form->{"discount_$i"});
785 $qty = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
787 $amount = $sellprice * (1 - $discount / 100) * $qty;
788 map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"});
789 $form->{oldinvtotal} += $amount;
792 map { $form->{oldinvtotal} += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{taxaccounts} if !$form->{taxincluded};
794 $form->{oldtotalpaid} = 0;
795 for $i (1 .. $form->{paidaccounts}) {
796 $form->{oldtotalpaid} += $form->{"paid_$i"};
800 ($form->{oldinvtotal} - $form->{oldtotalpaid});
807 # check if items are valid
808 if ($form->{rowcount} == 1) {
813 for $i (1 .. $form->{rowcount} - 1) {
814 $form->isblank("partnumber_$i", $locale->text('Number missing in Row') . " $i");
823 $form->{title} = $locale->text('Add Purchase Order');
824 $form->{vc} = 'vendor';
825 $form->{type} = 'purchase_order';
835 $form->{title} = $locale->text('Add Sales Order');
836 $form->{vc} = 'customer';
837 $form->{type} = 'sales_order';
847 $form->{title} = $locale->text('Add Request for Quotation');
848 $form->{vc} = 'vendor';
849 $form->{type} = 'request_quotation';
859 $form->{title} = $locale->text('Add Quotation');
860 $form->{vc} = 'customer';
861 $form->{type} = 'sales_quotation';
871 map { delete $form->{$_} } qw(id printed emailed queued);
873 $form->{script} = 'oe.pl';
877 $form->{rowcount}-- if $form->{rowcount};
879 require "$form->{path}/$form->{script}";
881 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
883 map { $temp{$_} = $form->{$_} } qw(currency employee department intnotes notes language_code);
887 map { $form->{$_} = $temp{$_} if $temp{$_} } keys %temp;
889 $form->{exchangerate} = "";
891 if ($form->{currency} ne $form->{defaultcurrency}) {
892 $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell)));
905 $bcc = qq|<input type=hidden name=bcc value="$form->{bcc}">|;
906 if ($myconfig{role} =~ /(admin|manager)/) {
908 <th align=right nowrap=true>|.$locale->text('Bcc').qq|</th>
909 <td><input name=bcc size=30 value="$form->{bcc}"></td>
913 if ($form->{formname} =~ /(pick|packing|bin)_list/) {
914 $form->{email} = $form->{shiptoemail} if $form->{shiptoemail};
917 $name = $form->{$form->{vc}};
919 $title = $locale->text('E-mail')." $name";
926 <form method=post action="$form->{script}#end">
930 <th class=listtop>$title</th>
937 <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
938 <td><input name=email size=30 value="$form->{email}"></td>
939 <th align=right nowrap>|.$locale->text('Cc').qq|</th>
940 <td><input name=cc size=30 value="$form->{cc}"></td>
943 <th align=right nowrap>|.$locale->text('Subject').qq|</th>
944 <td><input name=subject size=30 value="$form->{subject}"></td>
954 <th align=left nowrap>|.$locale->text('Message').qq|</th>
957 <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
966 $form->{oldmedia} = $form->{media};
967 $form->{media} = "email";
968 $form->{format} = "pdf";
972 map { delete $form->{$_} } qw(action email cc bcc subject message formname sendmode format header);
980 <td><hr size=3 noshade></td>
984 <input type=hidden name=nextsub value=send_email>
987 <input name=action class=submit type=submit value="|.$locale->text('Continue').qq|">
999 $old_form = new Form;
1001 map { $old_form->{$_} = $form->{$_} } keys %$form;
1002 $old_form->{media} = $old_form->{oldmedia};
1004 &print_form($old_form);
1012 $form->{sendmode} = "attachment";
1013 $form->{copies} = 1 unless $form->{copies};
1015 $form->{PD}{$form->{formname}} = "selected";
1016 $form->{DF}{$form->{format}} = "selected";
1017 $form->{SM}{$form->{sendmode}} = "selected";
1019 if ($form->{selectlanguage}) {
1020 $form->{"selectlanguage"} = $form->unescape($form->{"selectlanguage"});
1021 $form->{"selectlanguage"} =~ s/ selected//;
1022 $form->{"selectlanguage"} =~ s/(<option value="\Q$form->{language_code}\E")/$1 selected/;
1023 $lang = qq|<td><select name=language_code>$form->{selectlanguage}</select></td>
1024 <input type=hidden name=oldlanguage_code value=$form->{oldlanguage_code}>
1025 <input type=hidden name=selectlanguage value="|.
1026 $form->escape($form->{selectlanguage},1).qq|">|;
1029 if ($form->{type} eq 'purchase_order') {
1030 $type = qq|<td><select name=formname>
1031 <option value=purchase_order $form->{PD}{purchase_order}>|.$locale->text('Purchase Order').qq|
1032 <option value=bin_list $form->{PD}{bin_list}>|.$locale->text('Bin List').qq|</select></td>|;
1035 if ($form->{type} eq 'sales_order') {
1036 $type = qq|<td><select name=formname>
1037 <option value=sales_order $form->{PD}{sales_order}>|.$locale->text('Sales Order').qq|
1038 <option value=work_order $form->{PD}{work_order}>|.$locale->text('Work Order').qq|
1039 <option value=pick_list $form->{PD}{pick_list}>|.$locale->text('Pick List').qq|
1040 <option value=packing_list $form->{PD}{packing_list}>|.$locale->text('Packing List').qq|</select></td>|;
1043 if ($form->{type} =~ /_quotation$/) {
1044 $type = qq|<td><select name=formname>
1045 <option value="$`_quotation" $form->{PD}{"$`_quotation"}>|.$locale->text('Quotation').qq|</select></td>|;
1048 if ($form->{type} eq 'invoice') {
1049 $type = qq|<td><select name=formname>
1050 <option value=invoice $form->{PD}{invoice}>|.$locale->text('Invoice').qq|
1051 <option value=pick_list $form->{PD}{pick_list}>|.$locale->text('Pick List').qq|
1052 <option value=packing_list $form->{PD}{packing_list}>|.$locale->text('Packing List').qq|</select></td>|;
1055 if ($form->{type} eq 'ship_order') {
1056 $type = qq|<td><select name=formname>
1057 <option value=pick_list $form->{PD}{pick_list}>|.$locale->text('Pick List').qq|
1058 <option value=packing_list $form->{PD}{packing_list}>|.$locale->text('Packing List').qq|</select></td>|;
1061 if ($form->{type} eq 'receive_order') {
1062 $type = qq|<td><select name=formname>
1063 <option value=bin_list $form->{PD}{bin_list}>|.$locale->text('Bin List').qq|</select></td>|;
1066 if ($form->{media} eq 'email') {
1067 $media = qq|<td><select name=sendmode>
1068 <option value=attachment $form->{SM}{attachment}>|.$locale->text('Attachment').qq|
1069 <option value=inline $form->{SM}{inline}>|.$locale->text('In-line').qq|</select></td>|;
1071 $media = qq|<td><select name=media>
1072 <option value=screen>|.$locale->text('Screen');
1073 if (%printer && $latex) {
1075 <option value="$_">$_| } sort keys %printer;
1079 <option value="queue">|.$locale->text('Queue');
1081 $media .= qq|</select></td>|;
1083 # set option selected
1084 $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
1088 $format = qq|<td><select name=format>
1089 <option value=html $form->{DF}{html}>html|;
1091 # <option value=txt $form->{DF}{txt}>txt|;
1095 <option value=postscript $form->{DF}{postscript}>|.$locale->text('Postscript').qq|
1096 <option value=pdf $form->{DF}{pdf}>|.$locale->text('PDF');
1098 $format .= qq|</select></td>|;
1101 <table width=100% cellspacing=0 cellpadding=0>
1112 if (%printer && $latex && $form->{media} ne 'email') {
1114 <td>|.$locale->text('Copies').qq|
1115 <input name=copies size=2 value=$form->{copies}></td>
1119 $form->{groupprojectnumber} = "checked" if $form->{groupprojectnumber};
1120 $form->{grouppartsgroup} = "checked" if $form->{grouppartsgroup};
1123 <td>|.$locale->text('Group Items').qq|</td>
1125 <input name=groupprojectnumber type=checkbox class=checkbox $form->{groupprojectnumber}>
1126 |.$locale->text('Project').qq|
1127 <input name=grouppartsgroup type=checkbox class=checkbox $form->{grouppartsgroup}>
1128 |.$locale->text('Group').qq|
1136 if ($form->{printed} =~ /$form->{formname}/) {
1137 print $locale->text('Printed').qq|<br>|;
1140 if ($form->{emailed} =~ /$form->{formname}/) {
1141 print $locale->text('E-mailed').qq|<br>|;
1144 if ($form->{queued} =~ /$form->{formname}/) {
1145 print $locale->text('Queued');
1161 # if this goes to the printer pass through
1162 if ($form->{media} !~ /(screen|email)/) {
1163 $form->error($locale->text('Select txt, postscript or PDF!')) if ($form->{format} !~ /(txt|postscript|pdf)/);
1165 $old_form = new Form;
1166 map { $old_form->{$_} = $form->{$_} } keys %$form;
1170 &print_form($old_form);
1176 my ($old_form) = @_;
1181 $numberfld = "sinumber";
1183 $display_form = ($form->{display_form}) ? $form->{display_form} : "display_form";
1185 if ($form->{formname} eq "invoice") {
1186 $form->{label} = $locale->text('Invoice');
1188 if ($form->{formname} eq 'sales_order') {
1191 $form->{label} = $locale->text('Sales Order');
1192 $numberfld = "sonumber";
1195 if ($form->{formname} eq 'work_order') {
1198 $form->{label} = $locale->text('Work Order');
1199 $numberfld = "sonumber";
1202 if ($form->{formname} eq 'packing_list') {
1203 # we use the same packing list as from an invoice
1204 $form->{label} = $locale->text('Packing List');
1206 if ($form->{type} ne 'invoice') {
1209 $numberfld = "sonumber";
1213 if ($form->{formname} eq 'pick_list') {
1214 $form->{label} = $locale->text('Pick List');
1215 if ($form->{type} ne 'invoice') {
1219 $numberfld = "sonumber";
1222 if ($form->{formname} eq 'purchase_order') {
1225 $form->{label} = $locale->text('Purchase Order');
1226 $numberfld = "ponumber";
1229 if ($form->{formname} eq 'bin_list') {
1232 $form->{label} = $locale->text('Bin List');
1233 $numberfld = "ponumber";
1236 if ($form->{formname} eq 'sales_quotation') {
1239 $form->{label} = $locale->text('Quotation');
1240 $numberfld = "sqnumber";
1243 if ($form->{formname} eq 'request_quotation') {
1246 $form->{label} = $locale->text('Quotation');
1247 $numberfld = "rfqnumber";
1251 $form->{"${inv}date"} = $form->{transdate};
1253 $form->isblank("email", $locale->text('E-mail address missing!')) if ($form->{media} eq 'email');
1254 $form->isblank("${inv}date", $locale->text($form->{label} .' Date missing!'));
1257 if (! $form->{"${inv}number"}) {
1258 $form->{"${inv}number"} = $form->update_defaults(\%myconfig, $numberfld);
1259 if ($form->{media} eq 'screen') {
1266 # $locale->text('Invoice Number missing!')
1267 # $locale->text('Invoice Date missing!')
1268 # $locale->text('Packing List Number missing!')
1269 # $locale->text('Packing List Date missing!')
1270 # $locale->text('Order Number missing!')
1271 # $locale->text('Order Date missing!')
1272 # $locale->text('Quotation Number missing!')
1273 # $locale->text('Quotation Date missing!')
1277 &{ "$form->{vc}_details" };
1280 foreach $i (1 .. $form->{rowcount}) {
1281 push @a, ("partnumber_$i", "description_$i", "projectnumber_$i", "partsgroup_$i", "serialnumber_$i", "bin_$i", "unit_$i");
1283 map { push @a, "${_}_description" } split / /, $form->{taxaccounts};
1285 $ARAP = ($form->{vc} eq 'customer') ? "AR" : "AP";
1288 # format payment dates
1289 for $i (1 .. $form->{paidaccounts} - 1) {
1290 if (exists $form->{longformat}) {
1291 $form->{"datepaid_$i"} = $locale->date(\%myconfig, $form->{"datepaid_$i"}, $form->{longformat});
1294 push @a, "${ARAP}_paid_$i", "source_$i", "memo_$i";
1297 $form->format_string(@a);
1299 ($form->{employee}) = split /--/, $form->{employee};
1300 ($form->{warehouse}, $form->{warehouse_id}) = split /--/, $form->{warehouse};
1302 # this is a label for the subtotals
1303 $form->{groupsubtotaldescription} = $locale->text('Subtotal') if not exists $form->{groupsubtotaldescription};
1304 delete $form->{groupsubtotaldescription} if $form->{deletegroupsubtotal};
1306 # create the form variables
1308 OE->order_details(\%myconfig, \%$form);
1310 IS->invoice_details(\%myconfig, \%$form);
1313 if (exists $form->{longformat}) {
1314 map { $form->{$_} = $locale->date(\%myconfig, $form->{$_}, $form->{longformat}) } ("${inv}date", "${due}date", "shippingdate", "transdate");
1317 @a = qw(name address1 address2 city state zipcode country);
1320 # if there is no shipto fill it in from billto
1321 foreach $item (@a) {
1322 if ($form->{"shipto$item"}) {
1329 if ($form->{formname} eq 'purchase_order' || $form->{formname} eq 'request_quotation') {
1330 $form->{shiptoname} = $myconfig{company};
1331 $form->{shiptoaddress1} = $myconfig{address};
1333 if ($form->{formname} !~ /bin_list/) {
1334 map { $form->{"shipto$_"} = $form->{$_} } @a;
1339 $form->{notes} =~ s/^\s+//g;
1341 # some of the stuff could have umlauts so we translate them
1342 push @a, qw(contact shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact shiptoemail shippingpoint shipvia notes employee warehouse);
1344 push @a, ("${inv}number", "${inv}date", "${due}date", "email", "cc", "bcc");
1346 map { $form->{$_} = $myconfig{$_} } (qw(company address tel fax signature businessnumber));
1347 map { $form->{"user$_"} = $myconfig{$_} } qw(name email);
1348 push @a, qw(company address tel fax signature businessnumber username useremail);
1350 $form->format_string(@a);
1353 $form->{templates} = "$myconfig{templates}";
1354 $form->{IN} = "$form->{formname}.$form->{format}";
1356 if ($form->{format} =~ /(postscript|pdf)/) {
1357 $form->{IN} =~ s/$&$/tex/;
1360 $form->{pre} = "<body bgcolor=#ffffff>\n<pre>" if $form->{format} eq 'txt';
1362 if ($form->{media} !~ /(screen|queue|email)/) {
1363 $form->{OUT} = "| $printer{$form->{media}}";
1365 if ($form->{printed} !~ /$form->{formname}/) {
1367 $form->{printed} .= " $form->{formname}";
1368 $form->{printed} =~ s/^ //;
1370 $form->update_status(\%myconfig);
1373 $old_form->{printed} = $form->{printed};
1375 %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
1376 reference => $form->{"${inv}number"},
1377 formname => $form->{formname},
1378 action => 'printed',
1379 id => $form->{id} );
1381 $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
1386 if ($form->{media} eq 'email') {
1387 $form->{subject} = qq|$form->{label} $form->{"${inv}number"}| unless $form->{subject};
1389 $form->{plainpaper} = 1;
1390 $form->{OUT} = "$sendmail";
1392 if ($form->{emailed} !~ /$form->{formname}/) {
1393 $form->{emailed} .= " $form->{formname}";
1394 $form->{emailed} =~ s/^ //;
1397 $form->update_status(\%myconfig);
1400 $now = scalar localtime;
1401 $cc = $locale->text('Cc').qq|: $form->{cc}\n| if $form->{cc};
1402 $bcc = $locale->text('Bcc').qq|: $form->{bcc}\n| if $form->{bcc};
1404 $old_form->{intnotes} = qq|$old_form->{intnotes}\n\n| if $old_form->{intnotes};
1405 $old_form->{intnotes} .= qq|[email]
1406 |.$locale->text('Date').qq|: $now
1407 |.$locale->text('To').qq|: $form->{email}
1408 $cc${bcc}|.$locale->text('Subject').qq|: $form->{subject}\n|;
1410 $old_form->{intnotes} .= qq|\n|.$locale->text('Message').qq|: |;
1411 $old_form->{intnotes} .= ($form->{message}) ? $form->{message} : $locale->text('sent');
1413 $old_form->{message} = $form->{message};
1414 $old_form->{emailed} = $form->{emailed};
1416 $old_form->{format} = "postscript" if $myconfig{printer};
1417 $old_form->{media} = $myconfig{printer};
1419 $old_form->save_intnotes(\%myconfig, ($order) ? 'oe' : lc $ARAP);
1421 %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
1422 reference => $form->{"${inv}number"},
1423 formname => $form->{formname},
1424 action => 'emailed',
1425 id => $form->{id} );
1427 $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
1431 if ($form->{media} eq 'queue') {
1432 %queued = split / /, $form->{queued};
1434 if ($filename = $queued{$form->{formname}}) {
1435 $form->{queued} =~ s/$form->{formname} $filename//;
1436 unlink "$spool/$filename";
1437 $filename =~ s/\..*$//g;
1443 $filename .= ($form->{format} eq 'postscript') ? '.ps' : '.pdf';
1444 $form->{OUT} = ">$spool/$filename";
1446 $form->{queued} .= " $form->{formname} $filename";
1447 $form->{queued} =~ s/^ //;
1450 $form->update_status(\%myconfig);
1452 $old_form->{queued} = $form->{queued};
1454 %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
1455 reference => $form->{"${inv}number"},
1456 formname => $form->{formname},
1458 id => $form->{id} );
1460 $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
1465 $form->{fileid} = $form->{"${inv}number"};
1466 $form->{fileid} =~ s/(\s|\W)+//g;
1468 $form->parse_template(\%myconfig, $userspath);
1470 # if we got back here restore the previous form
1473 $old_form->{"${inv}number"} = $form->{"${inv}number"};
1475 # restore and display form
1476 map { $form->{$_} = $old_form->{$_} } keys %$old_form;
1477 delete $form->{pre};
1479 $form->{rowcount}--;
1481 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
1483 for $i (1 .. $form->{paidaccounts}) {
1484 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
1487 &{ "$display_form" };
1494 sub customer_details {
1496 IS->customer_details(\%myconfig, \%$form);
1501 sub vendor_details {
1503 IR->vendor_details(\%myconfig, \%$form);
1510 $form->{postasnew} = 1;
1511 map { delete $form->{$_} } qw(printed emailed queued);
1520 $title = $form->{title};
1521 $form->{title} = $locale->text('Ship to');
1523 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
1525 # get details for name
1526 &{ "$form->{vc}_details" };
1528 $number = ($form->{vc} eq 'customer') ? $locale->text('Customer Number') : $locale->text('Vendor Number');
1530 $nextsub = ($form->{display_form}) ? $form->{display_form} : "display_form";
1532 $form->{rowcount}--;
1539 <form method=post action=$form->{script}>
1545 <tr class=listheading>
1546 <th class=listheading colspan=2 width=50%>|.$locale->text('Billing Address').qq|</th>
1547 <th class=listheading width=50%>|.$locale->text('Shipping Address').qq|</th>
1549 <tr height="5"></tr>
1551 <th align=right nowrap>$number</th>
1552 <td>$form->{"$form->{vc}number"}</td>
1555 <th align=right nowrap>|.$locale->text('Company Name').qq|</th>
1556 <td>$form->{name}</td>
1557 <td><input name=shiptoname size=35 maxlength=64 value="$form->{shiptoname}"></td>
1560 <th align=right nowrap>|.$locale->text('Address').qq|</th>
1561 <td>$form->{address1}</td>
1562 <td><input name=shiptoaddress1 size=35 maxlength=32 value="$form->{shiptoaddress1}"></td>
1566 <td>$form->{address2}</td>
1567 <td><input name=shiptoaddress2 size=35 maxlength=32 value="$form->{shiptoaddress2}"></td>
1570 <th align=right nowrap>|.$locale->text('City').qq|</th>
1571 <td>$form->{city}</td>
1572 <td><input name=shiptocity size=35 maxlength=32 value="$form->{shiptocity}"></td>
1575 <th align=right nowrap>|.$locale->text('State/Province').qq|</th>
1576 <td>$form->{state}</td>
1577 <td><input name=shiptostate size=35 maxlength=32 value="$form->{shiptostate}"></td>
1580 <th align=right nowrap>|.$locale->text('Zip/Postal Code').qq|</th>
1581 <td>$form->{zipcode}</td>
1582 <td><input name=shiptozipcode size=10 maxlength=10 value="$form->{shiptozipcode}"></td>
1585 <th align=right nowrap>|.$locale->text('Country').qq|</th>
1586 <td>$form->{country}</td>
1587 <td><input name=shiptocountry size=35 maxlength=32 value="$form->{shiptocountry}"></td>
1590 <th align=right nowrap>|.$locale->text('Contact').qq|</th>
1591 <td>$form->{contact}</td>
1592 <td><input name=shiptocontact size=35 maxlength=64 value="$form->{shiptocontact}"></td>
1595 <th align=right nowrap>|.$locale->text('Phone').qq|</th>
1596 <td>$form->{"$form->{vc}phone"}</td>
1597 <td><input name=shiptophone size=20 value="$form->{shiptophone}"></td>
1600 <th align=right nowrap>|.$locale->text('Fax').qq|</th>
1601 <td>$form->{"$form->{vc}fax"}</td>
1602 <td><input name=shiptofax size=20 value="$form->{shiptofax}"></td>
1605 <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
1606 <td>$form->{email}</td>
1607 <td><input name=shiptoemail size=35 value="$form->{shiptoemail}"></td>
1614 <input type=hidden name=nextsub value=$nextsub>
1618 map { delete $form->{$_} } qw(shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact shiptophone shiptofax shiptoemail header);
1619 $form->{title} = $title;
1628 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">