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.
22 #======================================================================
26 #======================================================================
34 require "$form->{path}/io.pl";
35 require "$form->{path}/arap.pl";
43 if ($form->{type} eq 'purchase_order') {
44 $form->{title} = $locale->text('Add Purchase Order');
45 $form->{vc} = 'vendor';
47 if ($form->{type} eq 'sales_order') {
48 $form->{title} = $locale->text('Add Sales Order');
49 $form->{vc} = 'customer';
61 if ($form->{type} eq 'purchase_order') {
62 $form->{title} = $locale->text('Edit Purchase Order');
63 $form->{vc} = 'vendor';
65 if ($form->{type} eq 'sales_order') {
66 $form->{title} = $locale->text('Edit Sales Order');
67 $form->{vc} = 'customer';
80 # get vendors / customers
81 $form->all_vc(\%myconfig, $form->{vc});
84 OE->retrieve_order(\%myconfig, \%$form);
86 $taxincluded = $form->{taxincluded};
87 $form->{shipto} = 1 if $form->{id};
89 # get customer / vendor
90 if ($form->{type} eq 'purchase_order') {
91 IR->get_vendor(\%myconfig, \%$form);
93 if ($form->{type} eq 'sales_order') {
94 IS->get_customer(\%myconfig, \%$form);
97 ($form->{$form->{vc}}) = split /--/, $form->{$form->{vc}};
98 $form->{"old$form->{vc}"} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
100 # build the popup menus
101 if (@{ $form->{"all_$form->{vc}"} }) {
102 $form->{$form->{vc}} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
103 map { $form->{"select$form->{vc}"} .= "<option>$_->{name}--$_->{id}\n" } (@{ $form->{"all_$form->{vc}"} });
107 @curr = split /:/, $form->{currencies};
109 $form->{defaultcurrency} = $curr[0];
111 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
113 $form->{taxincluded} = $taxincluded if ($form->{id});
116 $form->{forex} = $form->{exchangerate};
123 $form->{format} = "html";
124 $form->{media} = "screen";
128 map { $form->{$_} =~ s/"/"/g } qw(invnumber shippingpoint notes shiptoname shiptoaddr1 shiptoaddr2 shiptoaddr3 shiptoaddr4 shiptocontact);
130 foreach $ref (@{ $form->{order_details} } ) {
132 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{ $ref };
133 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
135 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
137 $decimalplaces = ($dec > 2) ? $dec : 2;
139 $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
140 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
142 map { $form->{"${_}_$i"} =~ s/"/"/g } qw(partnumber description unit);
143 $form->{rowcount} = $i;
152 $checkedopen = ($form->{closed}) ? "" : "checked";
153 $checkedclosed = ($form->{closed}) ? "checked" : "";
158 <td colspan=2 align=center>
161 <th nowrap><input name=closed type=radio class=radio value=0 $checkedopen> |.$locale->text('Open').qq|</th>
162 <th nowrap><input name=closed type=radio class=radio value=1 $checkedclosed> |.$locale->text('Closed').qq|</th>
170 # set option selected
171 foreach $item ($form->{vc}, currency) {
172 $form->{"select$item"} =~ s/ selected//;
173 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
176 $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
178 $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
179 $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
182 <input type=hidden name=forex value=$form->{forex}>
185 if ($form->{currency} ne $form->{defaultcurrency}) {
186 if ($form->{forex}) {
187 $exchangerate .= qq|<th align=right>|.$locale->text('Exchangerate').qq|</th><td>$form->{exchangerate}</td>
188 <input type=hidden name=exchangerate value=$form->{exchangerate}>
191 $exchangerate .= qq|<th align=right>|.$locale->text('Exchangerate').qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
196 $vclabel = ucfirst $form->{vc};
197 $vclabel = $locale->text($vclabel);
199 if ($form->{type} eq 'sales_order') {
201 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
203 $creditremaining = qq|
209 <th align=left nowrap>|.$locale->text('Credit Limit').qq|</th>
210 <td>$form->{creditlimit}</td>
211 <th align=left nowrap>|.$locale->text('Remaining').qq|</th>
212 <td class="plus$n">$form->{creditremaining}</td>
220 $vc = ($form->{"select$form->{vc}"}) ? qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}</select>\n<input type=hidden name="select$form->{vc}" value="$form->{"select$form->{vc}"}">| : qq|<input name=$form->{vc} value="$form->{$form->{vc}}" size=35>|;
228 <form method=post action=$form->{script}>
230 <input type=hidden name=id value=$form->{id}>
232 <input type=hidden name=type value=$form->{type}>
233 <input type=hidden name=media value=$form->{media}>
234 <input type=hidden name=format value=$form->{format}>
236 <input type=hidden name=vc value=$form->{vc}>
237 <input type=hidden name=employee value="$form->{employee}">
239 <input type=hidden name=title value="$form->{title}">
241 <input type=hidden name=discount value=$form->{discount}>
242 <input type=hidden name=creditlimit value=$form->{creditlimit}>
243 <input type=hidden name=creditremaining value=$form->{creditremaining}>
247 <th class=listtop>$form->{title}</th>
257 <th align=right>$vclabel</th>
258 <td colspan=3>$vc</td>
259 <input type=hidden name=$form->{vc}_id value=$form->{"$form->{vc}_id"}>
260 <input type=hidden name="old$form->{vc}" value="$form->{"old$form->{vc}"}">
264 <th align=right>|.$locale->text('Currency').qq|</th>
265 <td><select name=currency>$form->{selectcurrency}</select></td>
266 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
267 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
271 <th align=right>|.$locale->text('Ship via').qq|</th>
272 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
280 <th align=right nowrap>|.$locale->text('Order Number').qq|</th>
281 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
284 <th align=right nowrap>|.$locale->text('Order Date').qq|</th>
285 <td><input name=orddate size=11 title="$myconfig{dateformat}" value=$form->{orddate}></td>
288 <th align=right nowrap=true>|.$locale->text('Required by').qq|</th>
289 <td><input name=reqdate size=11 title="$myconfig{dateformat}" value=$form->{reqdate}></td>
292 <th align=right nowrap>|.$locale->text('Terms: Net').qq|</th>
293 <td nowrap=true><input name=terms size="3" maxlength="3" value=$form->{terms}> |.$locale->text('days').qq|</td>
302 <!-- shipto are in hidden variables -->
304 <input type=hidden name=shiptoname value="$form->{shiptoname}">
305 <input type=hidden name=shiptoaddr1 value="$form->{shiptoaddr1}">
306 <input type=hidden name=shiptoaddr2 value="$form->{shiptoaddr2}">
307 <input type=hidden name=shiptoaddr3 value="$form->{shiptoaddr3}">
308 <input type=hidden name=shiptoaddr4 value="$form->{shiptoaddr4}">
309 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
310 <input type=hidden name=shiptophone value="$form->{shiptophone}">
311 <input type=hidden name=shiptofax value="$form->{shiptofax}">
312 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
314 <!-- email variables -->
315 <input type=hidden name=message value="$form->{message}">
316 <input type=hidden name=email value="$form->{email}">
317 <input type=hidden name=subject value="$form->{subject}">
318 <input type=hidden name=cc value="$form->{cc}">
319 <input type=hidden name=bcc value="$form->{bcc}">
321 <input type=hidden name=taxpart value="$form->{taxpart}">
322 <input type=hidden name=taxservice value="$form->{taxservice}">
324 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
327 foreach $item (split / /, $form->{taxaccounts}) {
329 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
330 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
339 $form->{invtotal} = $form->{invsubtotal};
341 if (($rows = $form->numtextrows($form->{notes}, 50, 8)) < 2) {
344 $notes = qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
347 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
348 if ($form->{taxaccounts}) {
350 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|.$locale->text('Tax Included').qq|</b><br><br>
354 if (!$form->{taxincluded}) {
356 foreach $item (split / /, $form->{taxaccounts}) {
357 if ($form->{"${item}_base"}) {
358 $form->{invtotal} += $form->{"${item}_total"} = $form->round_amount($form->{"${item}_base"} * $form->{"${item}_rate"}, 2);
359 $form->{"${item}_total"} = $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
363 <th align=right>$form->{"${item}_description"}</th>
364 <td align=right>$form->{"${item}_total"}</td>
370 $form->{invsubtotal} = $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
374 <th align=right>|.$locale->text('Subtotal').qq|</th>
375 <td align=right>$form->{invsubtotal}</td>
381 $form->{oldinvtotal} = $form->{invtotal};
382 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
392 <th align=left>|.$locale->text('Notes').qq|</th>
399 <td align=right width=100%>
405 <th align=right>|.$locale->text('Total').qq|</th>
406 <td align=right>$form->{invtotal}</td>
414 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
415 <input type=hidden name=oldtotalpaid value=$totalpaid>
426 <td><hr size=3 noshade></td>
431 <input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
432 <input class=submit type=submit name=action value="|.$locale->text('Ship to').qq|">
433 <input class=submit type=submit name=action value="|.$locale->text('Print').qq|">
434 <input class=submit type=submit name=action value="|.$locale->text('E-mail').qq|">
435 <input class=submit type=submit name=action value="|.$locale->text('Save').qq|">
440 <input class=submit type=submit name=action value="|.$locale->text('Save as new').qq|">
441 <input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">
442 <input class=submit type=submit name=action value="|.$locale->text('Invoice').qq|">
448 <input type=hidden name=rowcount value=$form->{rowcount}>
450 <input name=callback type=hidden value="$form->{callback}">
452 <input type=hidden name=path value=$form->{path}>
453 <input type=hidden name=login value=$form->{login}>
454 <input type=hidden name=password value=$form->{password}>
467 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
469 &check_name($form->{vc});
474 $buysell = 'sell' if ($form->{vc} eq 'vendor');
475 $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{orddate}, $buysell)));
478 my $i = $form->{rowcount};
479 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
481 if (($form->{"partnumber_$i"} eq "") && ($form->{"description_$i"} eq "") && ($form->{"partsgroup_$i"} eq "")) {
483 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
488 if ($form->{type} eq 'purchase_order') {
489 IR->retrieve_item(\%myconfig, \%$form);
491 if ($form->{type} eq 'sales_order') {
492 IS->retrieve_item(\%myconfig, \%$form);
495 my $rows = scalar @{ $form->{item_list} };
497 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{discount} * 100);
500 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
509 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
511 map { $form->{item_list}[$i]{$_} =~ s/"/"/g } qw(partnumber description unit);
512 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
514 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
516 ($dec) = ($s =~ /\.(\d+)/);
518 $decimalplaces = ($dec > 2) ? $dec : 2;
521 $form->{"sellprice_$i"} = $sellprice;
523 # if there is an exchange rate adjust sellprice
524 $form->{"sellprice_$i"} /= $exchangerate;
527 $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
528 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
529 map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"});
530 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{taxaccounts} if !$form->{taxincluded};
532 $form->{creditremaining} -= $amount;
534 $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
535 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
541 # ok, so this is a new part
542 # ask if it is a part or service item
544 if ($form->{"partsgroup_$i"} && ($form->{"partsnumber_$i"} eq "") && ($form->{"description_$i"} eq "")) {
546 $form->{"discount_$i"} = "";
550 $form->{"id_$i"} = 0;
551 $form->{"unit_$i"} = $locale->text('ea');
564 if ($form->{type} eq 'purchase_order') {
565 $form->{title} = $locale->text('Purchase Orders');
566 $form->{vc} = 'vendor';
568 if ($form->{type} eq 'sales_order') {
569 $form->{title} = $locale->text('Sales Orders');
570 $form->{vc} = 'customer';
573 # setup vendor / customer selection
574 $form->all_vc(\%myconfig, "$form->{vc}");
576 map { $vc .= "<option>$_->{name}--$_->{id}\n" } @{ $form->{"all_$form->{vc}"} };
578 $vclabel = ucfirst $form->{vc};
579 $vclabel = $locale->text($vclabel);
581 # $locale->text('Vendor')
582 # $locale->text('Customer')
584 $vc = ($vc) ? qq|<select name=$form->{vc}><option>\n$vc</select>| : qq|<input name=$form->{vc} size=35>|;
591 <form method=post action=$form->{script}>
595 <th class=listtop>$form->{title}</th>
602 <th align=right>$vclabel</th>
603 <td colspan=3>$vc</td>
606 <th align=right>|.$locale->text('Order Number').qq|</th>
607 <td colspan=3><input name=ordnumber size=20></td>
610 <th align=right>|.$locale->text('From').qq|</th>
611 <td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td>
612 <th align=right>|.$locale->text('to').qq|</th>
613 <td><input name=transdateto size=11 title="$myconfig{dateformat}"></td>
615 <input type=hidden name=sort value=transdate>
617 <th align=right>|.$locale->text('Include in Report').qq|</th>
621 <td><input name="open" class=checkbox type=checkbox value=1 checked> |.$locale->text('Open').qq|</td>
622 <td><input name="closed" class=checkbox type=checkbox value=1 $form->{closed}> |.$locale->text('Closed').qq|</td>
625 <td><input name="l_id" class=checkbox type=checkbox value=Y> |.$locale->text('ID').qq|</td>
626 <td><input name="l_ordnumber" class=checkbox type=checkbox value=Y checked> |.$locale->text('Order Number').qq|</td>
627 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked> |.$locale->text('Order Date').qq|</td>
628 <td><input name="l_reqdate" class=checkbox type=checkbox value=Y checked> |.$locale->text('Required by').qq|</td>
631 <td><input name="l_name" class=checkbox type=checkbox value=Y checked> $vclabel</td>
632 <td><input name="l_netamount" class=checkbox type=checkbox value=Y> |.$locale->text('Amount').qq|</td>
633 <td><input name="l_tax" class=checkbox type=checkbox value=Y> |.$locale->text('Tax').qq|</td>
634 <td><input name="l_amount" class=checkbox type=checkbox value=Y checked> |.$locale->text('Total').qq|</td>
637 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|</td>
645 <tr><td colspan=4><hr size=3 noshade></td></tr>
649 <input type=hidden name=nextsub value=orders>
650 <input type=hidden name=path value=$form->{path}>
651 <input type=hidden name=login value=$form->{login}>
652 <input type=hidden name=password value=$form->{password}>
653 <input type=hidden name=vc value=$form->{vc}>
654 <input type=hidden name=type value=$form->{type}>
656 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
668 $name = $form->{$form->{vc}};
670 # split vendor / customer
671 ($form->{$form->{vc}}, $form->{"$form->{vc}_id"}) = split(/--/, $form->{$form->{vc}});
673 OE->transactions(\%myconfig, \%$form);
676 $href = "$form->{script}?path=$form->{path}&action=orders&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&password=$form->{password}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&open=$form->{open}&closed=$form->{closed}&ordnumber=" . $form->escape($form->{ordnumber}) . "&$form->{vc}=" . $form->escape($form->{$form->{vc}});
680 $callback = "$form->{script}?path=$form->{path}&action=orders&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&password=$form->{password}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&open=$form->{open}&closed=$form->{closed}&ordnumber=$form->{ordnumber}&$form->{vc}=$name";
682 @columns = $form->sort_columns(qw(transdate reqdate id ordnumber name netamount tax amount curr open closed));
684 $form->{l_open} = $form->{l_closed} = "Y" if ($form->{open} && $form->{closed}) ;
686 foreach $item (@columns) {
687 if ($form->{"l_$item"} eq "Y") {
688 push @column_index, $item;
690 # add column to href and callback
691 $callback .= "&l_$item=Y";
692 $href .= "&l_$item=Y";
696 if ($form->{l_subtotal} eq 'Y') {
697 $callback .= "&l_subtotal=Y";
698 $href .= "&l_subtotal=Y";
702 if ($form->{vc} eq 'vendor') {
703 $form->{title} = $locale->text('Purchase Orders');
704 $name = $locale->text('Vendor');
706 if ($form->{vc} eq 'customer') {
707 $form->{title} = $locale->text('Sales Orders');
708 $name = $locale->text('Customer');
711 $column_header{id} = qq|<th><a class=listheading href=$href&sort=id>|.$locale->text('ID').qq|</a></th>|;
712 $column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>|.$locale->text('Date').qq|</a></th>|;
713 $column_header{reqdate} = qq|<th><a class=listheading href=$href&sort=reqdate>|.$locale->text('Required by').qq|</a></th>|;
714 $column_header{ordnumber} = qq|<th><a class=listheading href=$href&sort=ordnumber>|.$locale->text('Order').qq|</a></th>|;
715 $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>$name</a></th>|;
716 $column_header{netamount} = qq|<th class=listheading>|.$locale->text('Amount').qq|</th>|;
717 $column_header{tax} = qq|<th class=listheading>|.$locale->text('Tax').qq|</th>|;
718 $column_header{amount} = qq|<th class=listheading>|.$locale->text('Total').qq|</th>|;
719 $column_header{curr} = qq|<th class=listheading>|.$locale->text('Curr').qq|</th>|;
720 $column_header{open} = qq|<th class=listheading>|.$locale->text('O').qq|</th>|;
721 $column_header{closed} = qq|<th class=listheading>|.$locale->text('C').qq|</th>|;
724 $option = $locale->text('Open');
726 if ($form->{closed}) {
727 $option .= " : " if $form->{open};
728 $option .= $locale->text('Closed');
730 if ($form->{$form->{vc}}) {
732 $option .= ucfirst $form->{vc};
733 $option .= " : $form->{$form->{vc}}";
735 if ($form->{transdatefrom}) {
736 $option .= "\n<br>".$locale->text('From')." ".$locale->date(\%myconfig, $form->{transdatefrom}, 1);
738 if ($form->{transdateto}) {
739 $option .= "\n<br>".$locale->text('to')." ".$locale->date(\%myconfig, $form->{transdateto}, 1);
744 $colspan = $#column_index + 1;
750 <tr><th class=listtop colspan=$colspan>$form->{title}</th></tr>
753 <td colspan=$colspan>$option</td>
755 <tr class=listheading>|;
757 map { print "\n$column_header{$_}" } @column_index;
763 # add sort and escape callback
764 $callback = $form->escape($callback . "&sort=$form->{sort}");
766 if (@{ $form->{OE} }) {
767 $sameitem = $form->{OE}->[0]->{$form->{sort}};
770 foreach $oe (@{ $form->{OE} }) {
772 if ($form->{l_subtotal} eq 'Y') {
773 if ($sameitem ne $oe->{$form->{sort}}) {
775 $sameitem = $oe->{$form->{sort}};
779 map { $oe->{$_} *= $oe->{exchangerate} } (qw(netamount amount));
781 $column_data{netamount} = "<td align=right>".$form->format_amount(\%myconfig, $oe->{netamount}, 2, " ")."</td>";
782 $column_data{tax} = "<td align=right>".$form->format_amount(\%myconfig, $oe->{amount} - $oe->{netamount}, 2, " ")."</td>";
783 $column_data{amount} = "<td align=right>".$form->format_amount(\%myconfig, $oe->{amount}, 2, " ")."</td>";
785 $totalnetamount += $oe->{netamount};
786 $totalamount += $oe->{amount};
788 $subtotalnetamount += $oe->{netamount};
789 $subtotalamount += $oe->{amount};
791 $column_data{id} = "<td>$oe->{id}</td>";
792 $column_data{transdate} = "<td>$oe->{transdate} </td>";
793 $column_data{reqdate} = "<td>$oe->{reqdate} </td>";
795 $column_data{ordnumber} = "<td><a href=oe.pl?path=$form->{path}&action=edit&type=$form->{type}&id=$oe->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$oe->{ordnumber}</a></td>";
796 $column_data{name} = "<td>$oe->{name}</td>";
799 $column_data{closed} = "<td align=center>X</td>";
800 $column_data{open} = "<td> </td>";
802 $column_data{closed} = "<td> </td>";
803 $column_data{open} = "<td align=center>X</td>";
807 print "<tr class=listrow$i>";
809 map { print "\n$column_data{$_}" } @column_index;
817 if ($form->{l_subtotal} eq 'Y') {
822 print qq|<tr class=listtotal>|;
824 map { $column_data{$_} = "<td> </td>" } @column_index;
826 $column_data{netamount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalnetamount, 2, " ")."</th>";
827 $column_data{tax} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount - $totalnetamount, 2, " ")."</th>";
828 $column_data{amount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount, 2, " ")."</th>";
830 map { print "\n$column_data{$_}" } @column_index;
834 <tr><td colspan=8><hr size=3 noshade></td></tr>
838 <form method=post action=$form->{script}>
840 <input name=callback type=hidden value="$form->{callback}">
842 <input type=hidden name=type value=$form->{type}>
843 <input type=hidden name=vc value=$form->{vc}>
845 <input type=hidden name=path value=$form->{path}>
846 <input type=hidden name=login value=$form->{login}>
847 <input type=hidden name=password value=$form->{password}>
849 <input class=submit type=submit name=action value=|.$locale->text('Add').qq|
863 map { $column_data{$_} = "<td> </td>" } @column_index;
865 $column_data{netamount} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalnetamount, 2, " ")."</th>";
866 $column_data{tax} = "<td class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount, 2, " ")."</th>";
867 $column_data{amount} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalamount, 2, " ")."</th>";
869 $subtotalnetamount = 0;
872 print "<tr class=listsubtotal>";
874 map { print "\n$column_data{$_}" } @column_index;
885 $form->isblank("ordnumber", $locale->text('Order Number missing!'));
886 $form->isblank("orddate", $locale->text('Order Date missing!'));
888 $msg = ucfirst $form->{vc};
889 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
891 # $locale->text('Customer missing!');
892 # $locale->text('Vendor missing!');
894 $form->isblank("exchangerate", $locale->text('Exchangerate missing!')) if ($form->{currency} ne $form->{defaultcurrency});
898 # if the name changed get new values
899 if (&check_name($form->{vc})) {
905 # this is for the notes section for the [email] Subject
906 $form->{label} = ($form->{type} eq 'sales_order') ? $locale->text('Sales Order') : $locale->text('Purchase Order');
908 $form->{id} = 0 if $form->{saveasnew};
910 $form->redirect($locale->text('Order saved!')) if (OE->save_order(\%myconfig, \%$form));
911 $form->error($locale->text('Cannot save order!'));
924 <form method=post action=$form->{script}>
927 # delete action variable
928 delete $form->{action};
930 foreach $key (keys %$form) {
931 $form->{$key} =~ s/"/"/g;
932 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
936 <h2 class=confirm>|.$locale->text('Confirm!').qq|</h2>
939 .$locale->text('Are you sure you want to delete Order Number').qq| $form->{ordnumber}
942 <input name=action class=submit type=submit value="|.$locale->text('Yes').qq|">
956 $form->redirect($locale->text('Order deleted!')) if (OE->delete_order(\%myconfig, \%$form));
957 $form->error($locale->text('Cannot delete order!'));
964 $form->isblank("ordnumber", $locale->text('Order Number missing!'));
965 $form->isblank("orddate", $locale->text('Order Date missing!'));
968 # if the name changed get new values
969 if (&check_name($form->{vc})) {
975 OE->save_order(\%myconfig, \%$form);
977 $form->{orddate} = $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
978 $form->{duedate} = $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
987 if ($form->{type} eq 'purchase_order') {
988 $form->{title} = $locale->text('Add Vendor Invoice');
989 $form->{script} = 'ir.pl';
993 if ($form->{type} eq 'sales_order') {
994 $form->{title} = $locale->text('Add Sales Invoice');
995 $form->{script} = 'is.pl';
1001 # bo creates the id, reset it
1002 map { $form->{$_} = "" } qw(id subject message cc bcc);
1003 $form->{$form->{vc}} =~ s/--.*//g;
1004 $form->{type} = "invoice";
1007 $locale = new Locale "$myconfig{countrycode}", "$script";
1009 require "$form->{path}/$form->{script}";
1011 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1013 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(creditlimit creditremaining);
1015 $currency = $form->{currency};
1018 $form->{currency} = $currency;
1019 $form->{exchangerate} = "";
1020 $form->{forex} = "";
1021 $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, $buysell)));
1023 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
1028 for $i (1 .. $form->{rowcount}) {
1029 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"});
1031 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
1033 $decimalplaces = ($dec > 2) ? $dec : 2;
1035 $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
1036 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
1038 map { $form->{"${_}_$i"} =~ s/"/"/g } qw(partnumber description unit);
1046 sub create_backorder {
1048 # figure out if we need to create a backorder
1049 # items aren't saved if qty != 0
1051 for $i (1 .. $form->{rowcount}) {
1052 $totalqty += $qty = $form->parse_amount($myconfig, $form->{"qty_$i"});
1053 $totalship += $ship = $form->parse_amount($myconfig, $form->{"ship_$i"});
1055 $form->{"qty_$i"} = $qty - $ship;
1058 if ($totalship == 0) {
1059 map { $form->{"ship_$_"} = $form->{"qty_$_"} } (1 .. $form->{rowcount});
1060 $form->{ordtotal} = 0;
1064 if ($totalqty == $totalship) {
1065 map { $form->{"qty_$_"} = $form->{"ship_$_"} } (1 .. $form->{rowcount});
1066 $form->{ordtotal} = 0;
1070 @flds = (qw(partnumber description qty ship unit sellprice discount id inventory_accno bin income_accno expense_accno listprice assembly taxaccounts));
1072 OE->save_order(\%myconfig, \%$form);
1074 # rebuild rows for invoice
1078 for $i (1 .. $form->{rowcount}) {
1080 # reformat values if there was a backorder quantity
1081 if ($form->{"qty_$i"}) {
1082 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"});
1083 $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"});
1086 $form->{"qty_$i"} = $form->{"ship_$i"};
1088 if ($form->{"qty_$i"}) {
1091 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1096 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
1097 $form->{rowcount} = $count;
1105 $form->{saveasnew} = 1;
1106 $form->{closed} = 0;