1 ######################################################################
2 # SQL-Ledger, Accounting
3 # Copyright (c) 1998-2002
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.
23 #######################################################################
25 # common routines used in is, ir, oe
27 #######################################################################
29 # any custom scripts for this one
30 if (-f "$form->{path}/custom_io.pl") {
31 eval { require "$form->{path}/custom_io.pl"; };
33 if (-f "$form->{path}/$form->{login}_io.pl") {
34 eval { require "$form->{path}/$form->{login}_io.pl"; };
42 # this is for our long dates
43 # $locale->text('January')
44 # $locale->text('February')
45 # $locale->text('March')
46 # $locale->text('April')
47 # $locale->text('May ')
48 # $locale->text('June')
49 # $locale->text('July')
50 # $locale->text('August')
51 # $locale->text('September')
52 # $locale->text('October')
53 # $locale->text('November')
54 # $locale->text('December')
56 # this is for our short month
57 # $locale->text('Jan')
58 # $locale->text('Feb')
59 # $locale->text('Mar')
60 # $locale->text('Apr')
61 # $locale->text('May')
62 # $locale->text('Jun')
63 # $locale->text('Jul')
64 # $locale->text('Aug')
65 # $locale->text('Sep')
66 # $locale->text('Oct')
67 # $locale->text('Nov')
68 # $locale->text('Dec')
74 @column_index = (partnumber, description, qty);
76 if ($form->{type} eq "sales_order") {
78 push @column_index, "ship";
79 $column_data{ship} = qq|<th class=listheading align=left width="auto">|.$locale->text('Ship').qq|</th>|;
82 if ($form->{type} eq "purchase_order") {
84 push @column_index, "ship";
85 $column_data{ship} = qq|<th class=listheading align=left width="auto">|.$locale->text('Recd').qq|</th>|;
89 push @column_index, qw(unit sellprice);
91 if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_order') {
92 push @column_index, qw(discount);
95 push @column_index, "linetotal";
97 my $colspan = $#column_index + 1;
100 $form->{invsubtotal} = 0;
101 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
103 $column_data{partnumber} = qq|<th class=listheading nowrap>|.$locale->text('Number').qq|</th>|;
104 $column_data{description} = qq|<th class=listheading nowrap>|.$locale->text('Description').qq|</th>|;
105 $column_data{qty} = qq|<th class=listheading nowrap>|.$locale->text('Qty').qq|</th>|;
106 $column_data{unit} = qq|<th class=listheading nowrap>|.$locale->text('Unit').qq|</th>|;
107 $column_data{sellprice} = qq|<th class=listheading nowrap>|.$locale->text('Price').qq|</th>|;
108 $column_data{discount} = qq|<th class=listheading>%</th>|;
109 $column_data{linetotal} = qq|<th class=listheading nowrap>|.$locale->text('Extended').qq|</th>|;
110 $column_data{bin} = qq|<th class=listheading nowrap>|.$locale->text('Bin').qq|</th>|;
116 <tr class=listheading>|;
118 map { print "\n$column_data{$_}" } @column_index;
125 $projectnumber = $locale->text('Project');
126 $runningnumber = $locale->text('No.');
127 $partsgroup = $locale->text('Group');
129 if ($form->{type} =~ /_order/) {
130 $reqdate = $locale->text('Required by');
133 $deliverydate = $locale->text('Delivery Date');
134 $delvar = "deliverydate";
138 for $i (1 .. $numrows) {
140 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(qty ship discount sellprice);
142 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
144 $decimalplaces = ($dec > 2) ? $dec : 2;
146 $discount = $form->round_amount($form->{"sellprice_$i"} * $form->{"discount_$i"}/100, $decimalplaces);
147 $linetotal = $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
148 $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
150 # convert " to "
151 map { $form->{"${_}_$i"} =~ s/"/"/g } qw(partnumber description unit);
153 $column_data{partnumber} = qq|<td><input name="partnumber_$i" size=20 value="$form->{"partnumber_$i"}"></td>|;
155 if (($rows = $form->numtextrows($form->{"description_$i"}, 30, 6)) > 1) {
156 $column_data{description} = qq|<td><textarea name="description_$i" rows=$rows cols=30 wrap=soft>$form->{"description_$i"}</textarea></td>|;
158 $column_data{description} = qq|<td><input name="description_$i" size=30 value="$form->{"description_$i"}"></td>|;
161 $column_data{qty} = qq|<td align=right><input name="qty_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"qty_$i"}).qq|></td>|;
162 $column_data{ship} = qq|<td align=right><input name="ship_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"ship_$i"}).qq|></td>|;
163 $column_data{unit} = qq|<td><input name="unit_$i" size=5 maxsize=5 value="$form->{"unit_$i"}"></td>|;
164 $column_data{sellprice} = qq|<td align=right><input name="sellprice_$i" size=9 value=|.$form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces).qq|></td>|;
165 $column_data{discount} = qq|<td align=right><input name="discount_$i" size=3 value=|.$form->format_amount(\%myconfig, $form->{"discount_$i"}).qq|></td>|;
166 $column_data{linetotal} = qq|<td align=right>|.$form->format_amount(\%myconfig, $linetotal, 2).qq|</td>|;
167 $column_data{bin} = qq|<td>$form->{"bin_$i"}</td>|;
172 map { print "\n$column_data{$_}" } @column_index;
177 <input type=hidden name="id_$i" value=$form->{"id_$i"}>
178 <input type=hidden name="inventory_accno_$i" value=$form->{"inventory_accno_$i"}>
179 <input type=hidden name="bin_$i" value="$form->{"bin_$i"}">
180 <input type=hidden name="income_accno_$i" value=$form->{"income_accno_$i"}>
181 <input type=hidden name="expense_accno_$i" value=$form->{"expense_accno_$i"}>
182 <input type=hidden name="listprice_$i" value="$form->{"listprice_$i"}">
183 <input type=hidden name="assembly_$i" value="$form->{"assembly_$i"}">
184 <input type=hidden name="taxaccounts_$i" value="$form->{"taxaccounts_$i"}">
191 <td colspan=$colspan>
194 <th>$runningnumber</th>
195 <td><input name="runningnumber_$i" size=3 value=$i></td>
198 <td><input name="partsgroup_$i" size=10 value="$form->{"partsgroup_$i"}">
200 <td><input name="${delvar}_$i" size=11 title="$myconfig{dateformat}" value="$form->{"${delvar}_$i"}"></td>
201 <th>$projectnumber</th>
202 <td><input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}">
203 <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}">
204 <input type=hidden name="project_id_$i" value="$form->{"project_id_$i"}"></td>
210 <td colspan=$colspan><hr size=1 noshade></td>
215 map { $form->{"${_}_base"} += $linetotal } (split / /, $form->{"taxaccounts_$i"});
217 $form->{invsubtotal} += $linetotal;
231 @column_index = qw(ndx partnumber description onhand sellprice);
233 $column_data{ndx} = qq|<th> </th>|;
234 $column_data{partnumber} = qq|<th class=listheading>|.$locale->text('Number').qq|</th>|;
235 $column_data{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</th>|;
236 $column_data{sellprice} = qq|<th class=listheading>|.$locale->text('Price').qq|</th>|;
237 $column_data{onhand} = qq|<th class=listheading>|.$locale->text('Qty').qq|</th>|;
240 # list items with radio button on a form
243 $title = $locale->text('Select from one of the items below');
244 $colspan = $#column_index + 1;
249 <form method=post action=$form->{script}>
253 <th class=listtop colspan=$colspan>$title</th>
256 <tr class=listheading>|;
258 map { print "\n$column_data{$_}" } @column_index;
263 foreach $ref (@{ $form->{item_list} }) {
264 $checked = ($i++) ? "" : "checked";
266 map { $ref->{$_} =~ s/"/"/g } qw(partnumber description unit);
268 $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
269 $column_data{partnumber} = qq|<td><input name="new_partnumber_$i" type=hidden value="$ref->{partnumber}">$ref->{partnumber}</td>|;
270 $column_data{description} = qq|<td><input name="new_description_$i" type=hidden value="$ref->{description}">$ref->{description}</td>|;
271 $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>|;
272 $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>|;
276 <tr class=listrow$j>|;
278 map { print "\n$column_data{$_}" } @column_index;
283 <input name="new_bin_$i" type=hidden value="$ref->{bin}">
284 <input name="new_listprice_$i" type=hidden value=$ref->{listprice}>
285 <input name="new_inventory_accno_$i" type=hidden value=$ref->{inventory_accno}>
286 <input name="new_income_accno_$i" type=hidden value=$ref->{income_accno}>
287 <input name="new_expense_accno_$i" type=hidden value=$ref->{expense_accno}>
288 <input name="new_unit_$i" type=hidden value="$ref->{unit}">
289 <input name="new_weight_$i" type=hidden value="$ref->{weight}">
290 <input name="new_assembly_$i" type=hidden value="$ref->{assembly}">
291 <input name="new_taxaccounts_$i" type=hidden value="$ref->{taxaccounts}">
292 <input name="new_partsgroup_$i" type=hidden value="$ref->{partsgroup}">
294 <input name="new_id_$i" type=hidden value=$ref->{id}>
301 <tr><td colspan=8><hr size=3 noshade></td></tr>
304 <input name=lastndx type=hidden value=$i>
308 # delete action variable
309 delete $form->{action};
310 delete $form->{item_list};
312 # save all other form variables
313 foreach $key (keys %${form}) {
314 $form->{$key} =~ s/"/"/g;
315 print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
319 <input type=hidden name=nextsub value=item_selected>
322 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
335 # replace the last row with the checked row
336 $i = $form->{rowcount};
337 $i = $form->{assembly_rows} if ($form->{item} eq 'assembly');
342 # if there was a price entered, override it
343 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
345 map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} } qw(id partnumber description sellprice listprice inventory_accno income_accno expense_accno bin unit weight assembly taxaccounts partsgroup);
347 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
349 $decimalplaces = ($dec > 2) ? $dec : 2;
352 $form->{"sellprice_$i"} = $sellprice;
354 # if there is an exchange rate adjust sellprice
355 if (($form->{exchangerate} * 1) != 0) {
356 $form->{"sellprice_$i"} /= $form->{exchangerate};
357 $form->{"sellprice_$i"} = $form->round_amount($form->{"sellprice_$i"}, $decimalplaces);
361 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(sellprice weight);
363 $form->{sellprice} += ($form->{"sellprice_$i"} * $form->{"qty_$i"});
364 $form->{weight} += ($form->{"weight_$i"} * $form->{"qty_$i"});
366 $amount = $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) * $form->{"qty_$i"};
367 map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"});
368 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
370 $form->{creditremaining} -= $amount;
372 $form->{"runningnumber_$i"} = $i;
374 # delete all the new_ variables
375 for $i (1 .. $form->{lastndx}) {
376 map { delete $form->{"new_${_}_$i"} } qw(partnumber description sellprice bin listprice inventory_accno income_accno expense_accno unit assembly taxaccounts id);
379 map { delete $form->{$_} } qw(ndx lastndx nextsub);
381 if ($form->{item} eq 'assembly') {
382 map { $form->{"qty_$_"} = $form->parse_amount(\%myconfig, $form->{"qty_$_"}) } (1 .. $i);
384 # format amounts for invoice / order
385 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice);
396 $form->{old_callback} = $form->escape($form->{callback},1);
397 $form->{callback} = $form->escape("$form->{script}?action=display_form",1);
400 delete $form->{action};
402 # save all other form variables in a previous_form variable
403 foreach $key (keys %$form) {
405 $form->{$key} =~ s/&/%26/g;
406 $previous_form .= qq|$key=$form->{$key}&|;
409 $previous_form = $form->escape($previous_form, 1);
411 $i = $form->{rowcount};
412 map { $form->{"${_}_$i"} =~ s/"/"/g } qw(partnumber description);
419 <h4 class=error>|.$locale->text('Item not on file!').qq|
422 |.$locale->text('What type of item is this?').qq|</h4>
424 <form method=post action=ic.pl>
428 <input class=radio type=radio name=item value=part checked> |.$locale->text('Part')
430 <input class=radio type=radio name=item value=service> |.$locale->text('Service')
433 <input type=hidden name=previous_form value="$previous_form">
434 <input type=hidden name=partnumber value="$form->{"partnumber_$i"}">
435 <input type=hidden name=description value="$form->{"description_$i"}">
436 <input type=hidden name=rowcount value=$form->{rowcount}>
438 <input type=hidden name=path value=$form->{path}>
439 <input type=hidden name=login value=$form->{login}>
440 <input type=hidden name=password value=$form->{password}>
442 <input type=hidden name=nextsub value=add>
445 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
460 $numrows = ++$form->{rowcount};
461 $subroutine = "display_row";
463 if ($form->{item} eq 'part') {
464 $numrows = ++$form->{makemodel_rows};
465 $subroutine = "makemodel_row";
467 if ($form->{item} eq 'assembly') {
468 $numrows = ++$form->{makemodel_rows};
469 $subroutine = "makemodel_row";
471 # create makemodel rows
472 &{ $subroutine }($numrows);
474 $numrows = ++$form->{assembly_rows};
475 $subroutine = "assembly_row";
477 if ($form->{item} eq 'service') {
482 &{ $subroutine }($numrows) if $numrows;
494 my @flds = (qw(id partnumber description qty sellprice unit discount inventory_accno income_accno expense_accno listprice taxaccounts bin assembly weight projectnumber project_id oldprojectnumber runningnumber partsgroup));
496 # remove any makes or model rows
497 if ($form->{item} eq 'part') {
498 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(listprice sellprice lastcost weight rop);
500 @flds = (make, model);
501 for my $i (1 .. ($form->{makemodel_rows})) {
502 if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
506 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
511 $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
512 $form->{makemodel_rows} = $count;
514 } elsif ($form->{item} eq 'assembly') {
516 $form->{sellprice} = 0;
518 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(listprice rop);
520 @flds = qw(id qty unit bom partnumber description sellprice weight runningnumber partsgroup);
522 for my $i (1 .. ($form->{assembly_rows} - 1)) {
523 if ($form->{"qty_$i"}) {
527 $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
529 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
531 $form->{sellprice} += ($form->{"qty_$i"} * $form->{"sellprice_$i"});
532 $form->{weight} += ($form->{"qty_$i"} * $form->{"weight_$i"});
537 $form->{sellprice} = $form->round_amount($form->{sellprice}, 2);
539 $form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows});
540 $form->{assembly_rows} = $count;
543 @flds = qw(make model);
546 for my $i (1 .. ($form->{makemodel_rows})) {
547 if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
551 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
556 $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
557 $form->{makemodel_rows} = $count;
561 # this section applies to invoices and orders
562 # remove any empty numbers
564 if ($form->{rowcount}) {
565 for my $i (1 .. $form->{rowcount} - 1) {
566 if ($form->{"partnumber_$i"}) {
570 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
575 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
576 $form->{rowcount} = $count;
578 $form->{creditremaining} -= &invoicetotal;
590 $form->{oldinvtotal} = 0;
591 # add all parts and deduct paid
592 map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
594 my ($amount, $sellprice, $discount, $qty);
596 for my $i (1 .. $form->{rowcount}) {
597 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
598 $discount = $form->parse_amount(\%myconfig, $form->{"discount_$i"});
599 $qty = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
601 $amount = $sellprice * (1 - $discount / 100) * $qty;
602 map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"});
603 $form->{oldinvtotal} += $amount;
606 map { $form->{oldinvtotal} += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{taxaccounts} if !$form->{taxincluded};
608 $form->{oldtotalpaid} = 0;
609 for $i (1 .. $form->{paidaccounts}) {
610 $form->{oldtotalpaid} += $form->{"paid_$i"};
614 ($form->{oldinvtotal} - $form->{oldtotalpaid});
621 # check if items are valid
622 if ($form->{rowcount} == 1) {
627 for $i (1 .. $form->{rowcount} - 1) {
628 $form->isblank("partnumber_$i", $locale->text('Number missing in Row') . " $i");
636 $form->{ordnumber} = $form->{invnumber};
640 if ($form->{script} eq 'ir.pl') {
641 $form->{title} = $locale->text('Add Purchase Order');
642 $form->{vc} = 'vendor';
643 $form->{type} = 'purchase_order';
646 if ($form->{script} eq 'is.pl') {
647 $form->{title} = $locale->text('Add Sales Order');
648 $form->{vc} = 'customer';
649 $form->{type} = 'sales_order';
652 $form->{script} = 'oe.pl';
658 require "$form->{path}/$form->{script}";
660 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
662 $currency = $form->{currency};
666 $form->{currency} = $currency;
667 $form->{exchangerate} = "";
669 $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{orddate}, $buysell)));
680 if ($myconfig{admin}) {
682 <th align=right nowrap=true>|.$locale->text('Bcc').qq|</th>
683 <td><input name=bcc size=30 value="$form->{bcc}"></td>
687 if ($form->{type} eq 'packing_list') {
688 $form->{email} = $form->{shiptoemail} if $form->{shiptoemail};
691 $name = $form->{$form->{vc}};
693 $title = $locale->text('E-mail')." $name";
695 $form->{oldmedia} = $form->{media};
696 $form->{media} = "email";
703 <form method=post action=$form->{script}>
707 <th class=listtop>$title</th>
714 <th align=right nowrap>|.$locale->text('To').qq|</th>
715 <td><input name=email size=30 value="$form->{email}"></td>
716 <th align=right nowrap>|.$locale->text('Cc').qq|</th>
717 <td><input name=cc size=30 value="$form->{cc}"></td>
720 <th align=right nowrap>|.$locale->text('Subject').qq|</th>
721 <td><input name=subject size=30 value="$form->{subject}"></td>
731 <th align=left nowrap>|.$locale->text('Message').qq|</th>
734 <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
745 map { delete $form->{$_} } qw(action email cc bcc subject message type sendmode format);
747 # save all other variables
748 foreach $key (keys %$form) {
749 $form->{$key} =~ s/"/"/g;
750 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
757 <td><hr size=3 noshade></td>
761 <input type=hidden name=nextsub value=send_email>
764 <input name=action class=submit type=submit value="|.$locale->text('Continue').qq|">
776 $old_form = new Form;
777 map { $old_form->{$_} = $form->{$_} } keys %$form;
778 $old_form->{media} = $form->{oldmedia};
779 &print_form($old_form);
787 $form->{sendmode} = "attachment";
788 $form->{copies} = 3 unless $form->{copies};
790 $form->{PD}{$form->{type}} = "checked";
791 $form->{DF}{$form->{format}} = "checked";
792 $form->{OP}{$form->{media}} = "checked";
793 $form->{SM}{$form->{sendmode}} = "checked";
795 if ($form->{type} =~ /_order/) {
797 <td align=right><input class=radio type=radio name=type value="$`_order" $form->{PD}{"$`_order"}></td><td>|.$locale->text('Order').qq|</td>
801 <td align=right><input class=radio type=radio name=type value=invoice $form->{PD}{invoice}></td><td>|.$locale->text('Invoice').qq|</td>
802 <td align=right><input class=radio type=radio name=type value=packing_list $form->{PD}{packing_list}></td><td>|.$locale->text('Packing List').qq|</td>
806 if ($form->{media} eq 'email') {
808 <td align=center><input class=radio type=radio name=sendmode value=attachment $form->{SM}{attachment}> |.$locale->text('Attachment')
809 .qq| <input class=radio type=radio name=sendmode value=inline $form->{SM}{inline}> |.$locale->text('In-line').qq|</td>
813 <td align=right><input class=radio type=radio name=media value=screen $form->{OP}{screen}></td>
814 <td>|.$locale->text('Screen').qq|</td>
823 <td align=right><input class=radio type=radio name=format value=html $form->{DF}{html}></td>
829 <td align=right><input class=radio type=radio name=format value=postscript $form->{DF}{postscript}></td>
830 <td>|.$locale->text('Postscript').qq|</td>
831 <td align=right><input class=radio type=radio name=format value=pdf $form->{DF}{pdf}></td>
832 <td>|.$locale->text('PDF').qq|</td>
841 if ($myconfig{printer} && $latex) {
843 <td align=right><input class=radio type=radio name=media value=printer $form->{OP}{printer}></td>
844 <td>|.$locale->text('Printer')
845 .qq| (|.$locale->text('Copies')
846 .qq| <input name=copies size=2 value=$form->{copies}>)</td>
852 $form->{groupitems} = "checked" if $form->{groupitems};
856 <td align=right><input name=groupitems type=checkbox class=checkbox $form->{groupitems}></td>
857 <td>|.$locale->text('Group Items').qq|</td>
867 # if this goes to the printer pass through
868 if ($form->{media} eq 'printer') {
869 $form->error($locale->text('Select postscript or PDF!')) if ($form->{format} !~ /(postscript|pdf)/);
871 $old_form = new Form;
872 map { $old_form->{$_} = $form->{$_} } keys %$form;
875 &print_form($old_form);
881 my $old_form = shift;
886 if ($form->{type} eq "invoice") {
887 $form->{label} = $locale->text('Invoice');
889 if ($form->{type} eq "packing_list") {
890 $form->{label} = $locale->text('Packing List');
892 if ($form->{type} eq 'sales_order') {
895 $form->{label} = $locale->text('Sales Order');
897 if ($form->{type} eq 'purchase_order') {
900 $form->{label} = $locale->text('Purchase Order');
903 $form->isblank("email", $locale->text('E-mail address missing!')) if ($form->{media} eq 'email');
904 $form->isblank("${inv}number", $locale->text($form->{label} .' Number missing!'));
905 $form->isblank("${inv}date", $locale->text($form->{label} .' Date missing!'));
907 # $locale->text('Invoice Number missing!')
908 # $locale->text('Invoice Date missing!')
909 # $locale->text('Packing List Number missing!')
910 # $locale->text('Packing List Date missing!')
911 # $locale->text('Order Number missing!')
912 # $locale->text('Order Date missing!')
916 &{ "$form->{vc}_details" };
919 map { push @a, ("partnumber_$_", "description_$_") } (1 .. $form->{rowcount});
920 map { push @a, "${_}_description" } split / /, $form->{taxaccounts};
921 $form->format_string(@a);
923 # format payment dates
924 map { $form->{"datepaid_$_"} = $locale->date(\%myconfig, $form->{"datepaid_$_"}) } (1 .. $form->{paidaccounts});
926 # create the form variables for the invoice, packing list or order
927 if ($form->{type} =~ /order$/) {
928 OE->order_details(\%myconfig, \%$form);
930 IS->invoice_details(\%myconfig, \%$form);
933 $form->{"${inv}date"} = $locale->date(\%myconfig, $form->{"${inv}date"}, 1);
934 $form->{"${due}date"} = $locale->date(\%myconfig, $form->{"${due}date"}, 1);
937 @a = qw(name addr1 addr2 addr3 addr4);
940 # if there is no shipto fill it in from billto
942 if ($form->{"shipto$item"}) {
949 if ($form->{type} eq 'purchase_order') {
950 $form->{shiptoname} = $myconfig{company};
951 $form->{shiptoaddr1} = $myconfig{address};
953 map { $form->{"shipto$_"} = $form->{$_} } @a;
957 $form->{notes} =~ s/^\s+//g;
959 # some of the stuff could have umlauts so we translate them
960 push @a, qw(shiptoname shiptoaddr1 shiptoaddr2 shiptoaddr3 shiptoaddr4 shippingpoint company address signature notes);
962 push @a, ("${inv}date", "${due}date");
964 $form->format_string(@a);
967 $form->{templates} = "$myconfig{templates}";
968 $form->{IN} = "$form->{type}.html";
970 if ($form->{format} eq 'postscript') {
971 $form->{postscript} = 1;
972 $form->{IN} =~ s/html$/tex/;
974 if ($form->{format} eq 'pdf') {
976 $form->{IN} =~ s/html$/tex/;
979 $form->format_string(email, shiptoemail, cc, bcc) if $form->{format} =~ /(pdf|postscript)/;
981 if ($form->{media} eq 'printer') {
982 $form->{OUT} = "| $myconfig{printer}";
985 if ($form->{media} eq 'email') {
986 $form->{subject} = qq|$form->{label} $form->{"${inv}number"}| unless $form->{subject};
988 $form->{OUT} = "$sendmail";
992 $form->parse_template(\%myconfig, $userspath);
994 $form->{callback} = "";
996 # if we got back here restore the previous form
997 if ($form->{media} =~ /(printer|email)/) {
999 # restore and display form
1000 map { $form->{$_} = $old_form->{$_} } keys %$old_form;
1001 $form->{rowcount}--;
1002 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
1004 for $i (1 .. $form->{paidaccounts}) {
1005 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
1012 $msg = ($form->{media} eq 'printer') ? $locale->text('sent to printer') : $locale->text('emailed to')." $form->{email}";
1013 $form->redirect(qq|$form->{label} $form->{"${inv}number"} $msg|);
1019 sub customer_details {
1021 IS->customer_details(\%myconfig, \%$form);
1026 sub vendor_details {
1028 IR->vendor_details(\%myconfig, \%$form);
1035 $form->{postasnew} = 1;
1043 $title = $form->{title};
1044 $form->{title} = $locale->text('Ship to');
1046 $form->{rowcount}--;
1048 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
1050 # get details for name
1051 &{ "$form->{vc}_details" };
1058 <form method=post action=$form->{script}>
1064 <tr class=listheading>
1065 <th class=listheading colspan=2 width=50%>|.$locale->text('To').qq|</th>
1066 <th class=listheading width=50%>|.$locale->text('Ship to').qq|</th>
1068 <tr height="5"></tr>
1070 <th align=right nowrap>|.$locale->text('Number').qq|</th>
1071 <td>$form->{"$form->{vc}number"}</td>
1074 <th align=right nowrap>|.$locale->text('Name').qq|</th>
1075 <td>$form->{name}</td>
1076 <td><input name=shiptoname size=35 maxsize=35 value="$form->{shiptoname}"></td>
1079 <th align=right nowrap>|.$locale->text('Address').qq|</th>
1080 <td>$form->{addr1}</td>
1081 <td><input name=shiptoaddr1 size=35 maxsize=35 value="$form->{shiptoaddr1}"></td>
1085 <td>$form->{addr2}</td>
1086 <td><input name=shiptoaddr2 size=35 maxsize=35 value="$form->{shiptoaddr2}"></td>
1090 <td>$form->{addr3}</td>
1091 <td><input name=shiptoaddr3 size=35 maxsize=35 value="$form->{shiptoaddr3}"></td>
1095 <td>$form->{addr4}</td>
1096 <td><input name=shiptoaddr4 size=35 maxsize=35 value="$form->{shiptoaddr4}"></td>
1099 <th align=right nowrap>|.$locale->text('Contact').qq|</th>
1100 <td>$form->{contact}</td>
1101 <td><input name=shiptocontact size=35 maxsize=35 value="$form->{shiptocontact}"></td>
1104 <th align=right nowrap>|.$locale->text('Phone').qq|</th>
1105 <td>$form->{"$form->{vc}phone"}</td>
1106 <td><input name=shiptophone size=20 maxsize=20 value="$form->{shiptophone}"></td>
1109 <th align=right nowrap>|.$locale->text('Fax').qq|</th>
1110 <td>$form->{"$form->{vc}fax"}</td>
1111 <td><input name=shiptofax size=20 maxsize=20 value="$form->{shiptofax}"></td>
1114 <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
1115 <td>$form->{email}</td>
1116 <td><input name=shiptoemail size=35 value="$form->{shiptoemail}"></td>
1125 map { delete $form->{$_} } qw(shiptoname shiptoaddr1 shiptoaddr2 shiptoaddr3 shiptoaddr4 shiptocontact shiptophone shiptofax shiptoemail);
1126 $form->{title} = $title;
1128 foreach $key (keys %$form) {
1129 $form->{$key} =~ s/"/"/g;
1130 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1135 <input type=hidden name=nextsub value=display_form>
1140 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">