1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger, Accounting
9 # Copyright (c) 1998-2003
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #======================================================================
32 #======================================================================
40 require "$form->{path}/io.pl";
41 require "$form->{path}/arap.pl";
48 $lxdebug->enter_sub();
50 if ($form->{type} eq 'purchase_order') {
51 $form->{title} = $locale->text('Add Purchase Order');
52 $form->{vc} = 'vendor';
54 if ($form->{type} eq 'sales_order') {
55 $form->{title} = $locale->text('Add Sales Order');
56 $form->{vc} = 'customer';
58 if ($form->{type} eq 'request_quotation') {
59 $form->{title} = $locale->text('Add Request for Quotation');
60 $form->{vc} = 'vendor';
62 if ($form->{type} eq 'sales_quotation') {
63 $form->{title} = $locale->text('Add Quotation');
64 $form->{vc} = 'customer';
67 $form->{callback} = "$form->{script}?action=add&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&path=$form->{path}&password=$form->{password}" unless $form->{callback};
73 $lxdebug->leave_sub();
78 $lxdebug->enter_sub();
80 if ($form->{type} eq 'purchase_order') {
81 $form->{title} = $locale->text('Edit Purchase Order');
82 $form->{heading} = $locale->text('Purchase Order');
83 $form->{vc} = 'vendor';
85 if ($form->{type} eq 'sales_order') {
86 $form->{title} = $locale->text('Edit Sales Order');
87 $form->{heading} = $locale->text('Sales Order');
88 $form->{vc} = 'customer';
90 if ($form->{type} eq 'request_quotation') {
91 $form->{title} = $locale->text('Edit Request for Quotation');
92 $form->{heading} = $locale->text('Request for Quotation');
93 $form->{vc} = 'vendor';
95 if ($form->{type} eq 'sales_quotation') {
96 $form->{title} = $locale->text('Edit Quotation');
97 $form->{heading} = $locale->text('Quotation');
98 $form->{vc} = 'customer';
105 $lxdebug->leave_sub();
111 $lxdebug->enter_sub();
112 # get customer/vendor
113 $form->all_vc(\%myconfig, $form->{vc}, ($form->{vc} eq 'customer') ? "AR" : "AP");
115 # retrieve order/quotation
116 $form->{webdav} = $webdav;
119 $form->{jscalendar} = $jscalendar;
121 OE->retrieve(\%myconfig, \%$form);
123 $taxincluded = $form->{taxincluded};
124 $form->{shipto} = 1 if $form->{id};
126 if ($form->{"all_$form->{vc}"}) {
127 unless ($form->{"$form->{vc}_id"}) {
128 $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
132 $cp_id = $form->{cp_id};
133 $intnotes=$form->{intnotes};
134 # get customer / vendor
135 if ($form->{type} =~ /(purchase_order|request_quotation|receive_order)/ ) {
136 IR->get_vendor(\%myconfig, \%$form);
138 if ($form->{type} =~ /(sales|ship)_(order|quotation)/) {
139 IS->get_customer(\%myconfig, \%$form);
141 $form->{cp_id} = $cp_id;
143 $form->{intnotes}=$intnotes;
144 ($form->{$form->{vc}}) = split /--/, $form->{$form->{vc}};
145 $form->{"old$form->{vc}"} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
147 # build the popup menus
148 if (@{ $form->{"all_$form->{vc}"} }) {
149 $form->{$form->{vc}} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
150 map { $form->{"select$form->{vc}"} .= "<option>$_->{name}--$_->{id}\n" } (@{ $form->{"all_$form->{vc}"} });
154 @curr = split /:/, $form->{currencies};
156 $form->{defaultcurrency} = $curr[0];
157 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
159 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
161 $form->{taxincluded} = $taxincluded if ($form->{id});
164 if (@{ $form->{all_departments} }) {
165 $form->{selectdepartment} = "<option>\n";
166 $form->{department} = "$form->{department}--$form->{department_id}";
168 map { $form->{selectdepartment} .= "<option>$_->{description}--$_->{id}\n" } (@{ $form->{all_departments} });
171 $form->{employee} = "$form->{employee}--$form->{employee_id}";
173 if (@{ $form->{all_employees} }) {
174 $form->{selectemployee} = "";
175 map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" } (@{ $form->{all_employees} });
179 $form->{forex} = $form->{exchangerate};
181 $lxdebug->leave_sub();
186 $lxdebug->enter_sub();
187 $form->{format} = "html";
188 $form->{media} = "screen";
189 $form->{formname} = $form->{type};
193 map { $form->{$_} =~ s/\"/"/g } qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact);
195 foreach $ref (@{ $form->{form_details} } ) {
197 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{ $ref };
198 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
200 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
202 $decimalplaces = ($dec > 2) ? $dec : 2;
204 $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
205 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
207 map { $form->{"${_}_$i"} =~ s/\"/"/g } qw(partnumber description unit);
208 $form->{rowcount} = $i;
212 $lxdebug->leave_sub();
217 $lxdebug->enter_sub();
219 $checkedopen = ($form->{closed}) ? "" : "checked";
220 $checkedclosed = ($form->{closed}) ? "checked" : "";
222 # use JavaScript Calendar or not
223 $form->{jsscript} = $form->{jscalendar};
226 if ($form->{jsscript})
228 # with JavaScript Calendar
230 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
231 <td><input type=button name=transdate id="trigger1" value=|.$locale->text('button').qq|></td>
234 <td width="13"><input name=reqdate id=reqdate size=11 title="$myconfig{dateformat}" value=$form->{reqdate}></td>
235 <td width="4"><input type=button name=reqdate name=reqdate id="trigger2" value=|.$locale->text('button').qq|></td>
238 $jsscript = Form->write_trigger(\%myconfig,"2","transdate","BL","trigger1","reqdate","BL","trigger2");
243 # without JavaScript Calendar
245 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>|;
247 <td width="13"><input name=reqdate id=reqdate size=11 title="$myconfig{dateformat}" value=$form->{reqdate}></td>|;
254 <td colspan=2 align=center>
257 <th nowrap><input name=closed type=radio class=radio value=0 $checkedopen> |.$locale->text('Open').qq|</th>
258 <th nowrap><input name=closed type=radio class=radio value=1 $checkedclosed> |.$locale->text('Closed').qq|</th>
266 # set option selected
267 foreach $item ($form->{vc}, currency, department, employee, contact) {
268 $form->{"select$item"} =~ s/ selected//;
269 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
273 if ($form->{all_contacts}) {
275 $form->{selectcontact} = "";
276 foreach $item (@{$form->{all_contacts}}) {
277 if ($form->{cp_id} == $item->{cp_id})
279 $form->{selectcontact} .= "<option selected>$item->{cp_name}--$item->{cp_id}";
283 $form->{selectcontact} .= "<option>$item->{cp_name}--$item->{cp_id}";
288 $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
290 $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
291 $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
293 $contact = ($form->{selectcontact}) ? qq|<select name=contact>$form->{selectcontact}</select>\n<input type=hidden name="selectcontact" value="$form->{selectcontact}">| : qq|<input name=contact value="$form->{contact}" size=35>|;
296 <input type=hidden name=forex value=$form->{forex}>
299 if ($form->{currency} ne $form->{defaultcurrency}) {
300 if ($form->{forex}) {
301 $exchangerate .= qq|<th align=right>|.$locale->text('Exchangerate').qq|</th><td>$form->{exchangerate}</td>
302 <input type=hidden name=exchangerate value=$form->{exchangerate}>
305 $exchangerate .= qq|<th align=right>|.$locale->text('Exchangerate').qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
310 $vclabel = ucfirst $form->{vc};
311 $vclabel = $locale->text($vclabel);
315 <th align=right nowrap>|.$locale->text('Terms: Net').qq|</th>
316 <td nowrap><input name=terms size="3" maxlength="3" value=$form->{terms}> |.$locale->text('days').qq|</td>
321 if ($form->{business}) {
324 <th align=right>|.$locale->text('Business').qq|</th>
325 <td>$form->{business}</td>
326 <th align=right>|.$locale->text('Trade Discount').qq|</th>
327 <td>|.$form->format_amount(\%myconfig, $form->{tradediscount} * 100).qq| %</td>
333 if ($form->{type} !~ /_quotation$/) {
336 <th width=70% align=right nowrap>|.$locale->text('Order Number').qq|</th>
337 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
340 <th width=70% align=right nowrap>|.$locale->text('Quotation Number').qq|</th>
341 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
344 <th width=70% align=right nowrap>|.$locale->text('Customer Order Number').qq|</th>
345 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
348 <th align=right nowrap>|.$locale->text('Order Date').qq|</th>
353 <th align=right nowrap=true>|.$locale->text('Required by').qq|</th>
358 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
360 $creditremaining = qq|
366 <th nowrap>|.$locale->text('Credit Limit').qq|</th>
367 <td>$form->{creditlimit}</td>
369 <th nowrap>|.$locale->text('Remaining').qq|</th>
370 <td class="plus$n">$form->{creditremaining}</td>
377 $reqlabel = ($form->{type} eq 'sales_quotation') ? $locale->text('Valid until') : $locale->text('Required by');
378 if ($form->{type} eq 'sales_quotation') {
381 <th width=70% align=right nowrap>|.$locale->text('Quotation Number').qq|</th>
382 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
383 <input type=hidden name=ordnumber value="$form->{ordnumber}">
389 <th width=70% align=right nowrap>|.$locale->text('RFQ Number').qq|</th>
390 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
391 <input type=hidden name=ordnumber value="$form->{ordnumber}">
401 <th align=right nowrap>|.$locale->text('Quotation Date').qq|</th>
405 <th align=right nowrap=true>$reqlabel</th>
412 $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>|;
416 <th align="right" nowrap>|.$locale->text('Department').qq|</th>
417 <td colspan=3><select name=department>$form->{selectdepartment}</select>
418 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
421 | if $form->{selectdepartment};
424 <input type=hidden name=employee value="$form->{employee}">
427 if ($form->{type} eq 'sales_order') {
428 if ($form->{selectemployee}) {
431 <th align=right nowrap>|.$locale->text('Salesperson').qq|</th>
432 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
433 <input type=hidden name=selectemployee value="$form->{selectemployee}">
441 <th align=right nowrap>|.$locale->text('Employee').qq|</th>
442 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
443 <input type=hidden name=selectemployee value="$form->{selectemployee}">
455 <form method=post action=$form->{script}>
457 <input type=hidden name=id value=$form->{id}>
459 <input type=hidden name=type value=$form->{type}>
460 <input type=hidden name=formname value=$form->{formname}>
461 <input type=hidden name=media value=$form->{media}>
462 <input type=hidden name=format value=$form->{format}>
464 <input type=hidden name=queued value="$form->{queued}">
465 <input type=hidden name=printed value="$form->{printed}">
466 <input type=hidden name=emailed value="$form->{emailed}">
468 <input type=hidden name=vc value=$form->{vc}>
470 <input type=hidden name=title value="$form->{title}">
472 <input type=hidden name=discount value=$form->{discount}>
473 <input type=hidden name=creditlimit value=$form->{creditlimit}>
474 <input type=hidden name=creditremaining value=$form->{creditremaining}>
476 <input type=hidden name=tradediscount value=$form->{tradediscount}>
477 <input type=hidden name=business value=$form->{business}>
478 <input type=hidden name=webdav value=$webdav>
482 <th class=listtop>$form->{title}</th>
492 <th align=right>$vclabel</th>
493 <td colspan=3>$vc</td>
494 <input type=hidden name=$form->{vc}_id value=$form->{"$form->{vc}_id"}>
495 <input type=hidden name="old$form->{vc}" value="$form->{"old$form->{vc}"}">
496 <th align=richt nowrap>|.$locale->text('Contact Person').qq|</th>
497 <td colspan=3>$contact</td>
503 <th align=right>|.$locale->text('Currency').qq|</th>
504 <td><select name=currency>$form->{selectcurrency}</select></td>
505 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
506 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
510 <th align=right>|.$locale->text('Shipping Point').qq|</th>
511 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
514 <th align=right>|.$locale->text('Ship via').qq|</th>
515 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
534 <!-- shipto are in hidden variables -->
536 <input type=hidden name=shiptoname value="$form->{shiptoname}">
537 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
538 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
539 <input type=hidden name=shiptocity value="$form->{shiptocity}">
540 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
541 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
542 <input type=hidden name=shiptophone value="$form->{shiptophone}">
543 <input type=hidden name=shiptofax value="$form->{shiptofax}">
544 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
546 <!-- email variables -->
547 <input type=hidden name=message value="$form->{message}">
548 <input type=hidden name=email value="$form->{email}">
549 <input type=hidden name=subject value="$form->{subject}">
550 <input type=hidden name=cc value="$form->{cc}">
551 <input type=hidden name=bcc value="$form->{bcc}">
553 <input type=hidden name=taxpart value="$form->{taxpart}">
554 <input type=hidden name=taxservice value="$form->{taxservice}">
556 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
559 foreach $item (split / /, $form->{taxaccounts}) {
561 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
562 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
565 $lxdebug->leave_sub();
570 $lxdebug->enter_sub();
572 $form->{invtotal} = $form->{invsubtotal};
574 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
577 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
580 $rows = ($rows > $introws) ? $rows : $introws;
581 $notes = qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
582 $intnotes = qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
584 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
587 if ($form->{taxaccounts}) {
589 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|.$locale->text('Tax Included').qq|</b><br><br>
593 if (!$form->{taxincluded}) {
595 foreach $item (split / /, $form->{taxaccounts}) {
596 if ($form->{"${item}_base"}) {
597 $form->{invtotal} += $form->{"${item}_total"} = $form->round_amount($form->{"${item}_base"} * $form->{"${item}_rate"}, 2);
598 $form->{"${item}_total"} = $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
602 <th align=right>$form->{"${item}_description"}</th>
603 <td align=right>$form->{"${item}_total"}</td>
609 $form->{invsubtotal} = $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
613 <th align=right>|.$locale->text('Subtotal').qq|</th>
614 <td align=right>$form->{invsubtotal}</td>
620 if ($form->{taxincluded}) {
621 foreach $item (split / /, $form->{taxaccounts}) {
622 if ($form->{"${item}_base"}) {
623 $form->{"${item}_total"} = $form->round_amount(($form->{"${item}_base"} * $form->{"${item}_rate"} / (1 + $form->{"${item}_rate"})) , 2);
624 $form->{"${item}_netto"} = $form->round_amount(($form->{"${item}_base"}-$form->{"${item}_total"}), 2);
625 $form->{"${item}_total"} = $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
626 $form->{"${item}_netto"} = $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
631 <th align=right>Enthaltene $form->{"${item}_description"}</th>
632 <td align=right>$form->{"${item}_total"}</td>
635 <th align=right>Nettobetrag</th>
636 <td align=right>$form->{"${item}_netto"}</td>
645 $form->{oldinvtotal} = $form->{invtotal};
646 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
657 <th align=left>|.$locale->text('Notes').qq|</th>
658 <th align=left>|.$locale->text('Internal Notes').qq|</th>
666 <td align=right width=100%>
672 <th align=right>|.$locale->text('Total').qq|</th>
673 <td align=right>$form->{invtotal}</td>
681 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
682 <input type=hidden name=oldtotalpaid value=$totalpaid>
684 <td><hr size=3 noshade></td>
693 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
696 <td align=left width=30%><b>Dateiname</b></td>
697 <td align=left width=70%><b>Webdavlink</b></td>
699 foreach $file (keys %{ $form->{WEBDAV}}) {
702 <td align=left>$file</td>
703 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
711 <td><hr size=3 noshade></td>
718 <input type=hidden name=jscalendar value=$form->{jscalendar}>
731 Bearbeiten des $form->{heading}<br>
732 <input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
733 <input class=submit type=submit name=action value="|.$locale->text('Ship to').qq|">
734 <input class=submit type=submit name=action value="|.$locale->text('Print').qq|">
735 <input class=submit type=submit name=action value="|.$locale->text('E-mail').qq|">
736 <input class=submit type=submit name=action value="|.$locale->text('Save').qq|">
741 <br>Workflow $form->{heading}<br>
742 <input class=submit type=submit name=action value="|.$locale->text('Save as new').qq|">
743 <input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">|;
744 if ($form->{type} =~ /quotation$/) {
746 <input class=submit type=submit name=action value="|.$locale->text('Order').qq|">|;
749 <input class=submit type=submit name=action value="|.$locale->text('Invoice').qq|">
752 if ($form->{type} =~ /sales_order$/) {
754 <br>$form->{heading} als neue Vorlage verwenden für<br>
755 <input class=submit type=submit name=action value="|.$locale->text('Purchase Order').qq|">
756 <input class=submit type=submit name=action value="|.$locale->text('Quotation').qq|">
759 } elsif ($form->{type} =~ /purchase_order$/) {
761 <br>$form->{heading} als neue Vorlage verwenden für<br>
762 <input class=submit type=submit name=action value="|.$locale->text('Sales Order').qq|">
763 <input class=submit type=submit name=action value="|.$locale->text('Quotation').qq|">
768 <br>$form->{heading} als neue Vorlage verwenden für<br>
769 <input class=submit type=submit name=action value="|.$locale->text('Order').qq|">
774 if ($form->{menubar}) {
775 require "$form->{path}/menu.pl";
781 <input type=hidden name=rowcount value=$form->{rowcount}>
783 <input name=callback type=hidden value="$form->{callback}">
785 <input type=hidden name=path value=$form->{path}>
786 <input type=hidden name=login value=$form->{login}>
787 <input type=hidden name=password value=$form->{password}>
794 $lxdebug->leave_sub();
799 $lxdebug->enter_sub();
801 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
803 &check_name($form->{vc});
808 $buysell = 'sell' if ($form->{vc} eq 'vendor');
809 $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell)));
812 my $i = $form->{rowcount};
813 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
815 if (($form->{"partnumber_$i"} eq "") && ($form->{"description_$i"} eq "") && ($form->{"partsgroup_$i"} eq "")) {
817 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
822 if ($form->{type} eq 'purchase_order' || $form->{type} eq 'request_quotation') {
823 IR->retrieve_item(\%myconfig, \%$form);
825 if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
826 IS->retrieve_item(\%myconfig, \%$form);
829 my $rows = scalar @{ $form->{item_list} };
831 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{discount} * 100);
834 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
843 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
845 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
846 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
848 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
850 ($dec) = ($s =~ /\.(\d+)/);
852 $decimalplaces = ($dec > 2) ? $dec : 2;
855 $form->{"sellprice_$i"} = $sellprice;
857 # if there is an exchange rate adjust sellprice
858 $form->{"sellprice_$i"} /= $exchangerate;
861 $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
862 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
863 map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"});
864 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{taxaccounts} if !$form->{taxincluded};
866 $form->{creditremaining} -= $amount;
868 $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
869 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
875 # ok, so this is a new part
876 # ask if it is a part or service item
878 if ($form->{"partsgroup_$i"} && ($form->{"partsnumber_$i"} eq "") && ($form->{"description_$i"} eq "")) {
880 $form->{"discount_$i"} = "";
884 $form->{"id_$i"} = 0;
885 $form->{"unit_$i"} = $locale->text('ea');
892 $lxdebug->leave_sub();
898 $lxdebug->enter_sub();
900 if ($form->{type} eq 'purchase_order') {
901 $form->{title} = $locale->text('Purchase Orders');
902 $form->{vc} = 'vendor';
903 $ordlabel = $locale->text('Order Number');
904 $ordnumber = 'ordnumber';
905 $employee = $locale->text('Employee');
907 if ($form->{type} eq 'request_quotation') {
908 $form->{title} = $locale->text('Request for Quotations');
909 $form->{vc} = 'vendor';
910 $ordlabel = $locale->text('RFQ Number');
911 $ordnumber = 'quonumber';
912 $employee = $locale->text('Employee');
914 if ($form->{type} eq 'receive_order') {
915 $form->{title} = $locale->text('Receive Merchandise');
916 $form->{vc} = 'vendor';
917 $ordlabel = $locale->text('Order Number');
918 $ordnumber = 'ordnumber';
919 $employee = $locale->text('Employee');
921 if ($form->{type} eq 'sales_order') {
922 $form->{title} = $locale->text('Sales Orders');
923 $form->{vc} = 'customer';
924 $ordlabel = $locale->text('Order Number');
925 $ordnumber = 'ordnumber';
926 $employee = $locale->text('Salesperson');
928 if ($form->{type} eq 'ship_order') {
929 $form->{title} = $locale->text('Ship Merchandise');
930 $form->{vc} = 'customer';
931 $ordlabel = $locale->text('Order Number');
932 $ordnumber = 'ordnumber';
933 $employee = $locale->text('Salesperson');
937 if ($form->{type} eq 'sales_quotation') {
938 $form->{title} = $locale->text('Quotations');
939 $form->{vc} = 'customer';
940 $ordlabel = $locale->text('Quotation Number');
941 $ordnumber = 'quonumber';
942 $employee = $locale->text('Employee');
945 if ($form->{type} =~ /(ship|receive)_order/) {
946 OE->get_warehouses(\%myconfig, \%$form);
949 if (@{ $form->{all_warehouses} }) {
950 $form->{selectwarehouse} = "<option>\n";
951 $form->{warehouse} = qq|$form->{warehouse}--$form->{warehouse_id}|;
953 map { $form->{selectwarehouse} .= "<option>$_->{description}--$_->{id}\n" } (@{ $form->{all_warehouses} });
957 <th align=right>|.$locale->text('Warehouse').qq|</th>
958 <td colspan=3><select name=warehouse>$form->{selectwarehouse}</select></td>
959 <input type=hidden name=selectwarehouse value="$form->{selectwarehouse}">
966 # setup vendor / customer selection
967 $form->all_vc(\%myconfig, $form->{vc}, ($form->{vc} eq 'customer') ? "AR" : "AP");
969 map { $vc .= "<option>$_->{name}--$_->{id}\n" } @{ $form->{"all_$form->{vc}"} };
971 $vclabel = ucfirst $form->{vc};
972 $vclabel = $locale->text($vclabel);
974 # $locale->text('Vendor')
975 # $locale->text('Customer')
977 $vc = ($vc) ? qq|<select name=$form->{vc}><option>\n$vc</select>| : qq|<input name=$form->{vc} size=35>|;
980 if (@{ $form->{all_departments} }) {
981 $form->{selectdepartment} = "<option>\n";
983 map { $form->{selectdepartment} .= "<option>$_->{description}--$_->{id}\n" } (@{ $form->{all_departments} });
988 <th align=right nowrap>|.$locale->text('Department').qq|</th>
989 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
991 | if $form->{selectdepartment};
993 if ($form->{type} !~ /(ship_order|receive_order)/) {
996 <td><input name="open" class=checkbox type=checkbox value=1 checked> |.$locale->text('Open').qq|</td>
997 <td><input name="closed" class=checkbox type=checkbox value=1 $form->{closed}> |.$locale->text('Closed').qq|</td>
1003 <input type=hidden name="open" value=1>
1007 # use JavaScript Calendar or not
1008 $form->{jsscript} = $jscalendar;
1010 if ($form->{jsscript})
1012 # with JavaScript Calendar
1014 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}">
1015 <input type=button name=transdatefrom id="trigger3" value=|.$locale->text('button').qq|></td>
1018 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}">
1019 <input type=button name=transdateto name=transdateto id="trigger4" value=|.$locale->text('button').qq|></td>
1022 $jsscript = Form->write_trigger(\%myconfig,"2","transdatefrom","BR","trigger3","transdateto","BL","trigger4")
1026 # without JavaScript Calendar
1028 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
1030 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}"></td>|;
1038 <form method=post action=$form->{script}>
1042 <th class=listtop>$form->{title}</th>
1044 <tr height="5"></tr>
1049 <th align=right>$vclabel</th>
1050 <td colspan=3>$vc</td>
1055 <th align=right>$ordlabel</th>
1056 <td colspan=3><input name="$ordnumber" size=20></td>
1059 <th align=right>|.$locale->text('From').qq|</th>
1061 <th align=right>|.$locale->text('Bis').qq|</th>
1064 <input type=hidden name=sort value=transdate>
1066 <th align=right>|.$locale->text('Include in Report').qq|</th>
1071 <td><input name="l_id" class=checkbox type=checkbox value=Y>
1072 |.$locale->text('ID').qq|</td>
1073 <td><input name="l_$ordnumber" class=checkbox type=checkbox value=Y checked> $ordlabel</td>
1074 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked> |.$locale->text('Date').qq|</td>
1075 <td><input name="l_reqdate" class=checkbox type=checkbox value=Y checked> |.$locale->text('Required by').qq|</td>
1078 <td><input name="l_name" class=checkbox type=checkbox value=Y checked> $vclabel</td>
1079 <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
1080 <td><input name="l_shipvia" class=checkbox type=checkbox value=Y> |.$locale->text('Ship via').qq|</td>
1083 <td><input name="l_netamount" class=checkbox type=checkbox value=Y> |.$locale->text('Amount').qq|</td>
1084 <td><input name="l_tax" class=checkbox type=checkbox value=Y> |.$locale->text('Tax').qq|</td>
1085 <td><input name="l_amount" class=checkbox type=checkbox value=Y checked> |.$locale->text('Total').qq|</td>
1088 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|</td>
1096 <tr><td colspan=4><hr size=3 noshade></td></tr>
1102 <input type=hidden name=nextsub value=orders>
1103 <input type=hidden name=path value=$form->{path}>
1104 <input type=hidden name=login value=$form->{login}>
1105 <input type=hidden name=password value=$form->{password}>
1106 <input type=hidden name=vc value=$form->{vc}>
1107 <input type=hidden name=type value=$form->{type}>
1109 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
1116 $lxdebug->leave_sub();
1121 $lxdebug->enter_sub();
1123 # split vendor / customer
1124 ($form->{$form->{vc}}, $form->{"$form->{vc}_id"}) = split(/--/, $form->{$form->{vc}});
1126 OE->transactions(\%myconfig, \%$form);
1128 $ordnumber = ($form->{type} =~ /_order$/) ? "ordnumber" : "quonumber";
1130 $number = $form->escape($form->{$ordnumber});
1131 $name = $form->escape($form->{$form->{vc}});
1132 $department = $form->escape($form->{department});
1133 $warehouse = $form->escape($form->{warehouse});
1136 $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=$number&$form->{vc}=$name&department=$department&warehouse=$warehouse";
1138 # construct callback
1139 $number = $form->escape($form->{$ordnumber},1);
1140 $name = $form->escape($form->{$form->{vc}},1);
1141 $department = $form->escape($form->{department},1);
1142 $warehouse = $form->escape($form->{warehouse},1);
1144 $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=$number&$form->{vc}=$name&department=$department&warehouse=$warehouse";
1146 @columns = $form->sort_columns("transdate", "reqdate", "id", "$ordnumber", "name", "netamount", "tax", "amount", "curr", "employee", "shipvia", "open", "closed");
1148 $form->{l_open} = $form->{l_closed} = "Y" if ($form->{open} && $form->{closed}) ;
1150 foreach $item (@columns) {
1151 if ($form->{"l_$item"} eq "Y") {
1152 push @column_index, $item;
1154 # add column to href and callback
1155 $callback .= "&l_$item=Y";
1156 $href .= "&l_$item=Y";
1160 if ($form->{l_subtotal} eq 'Y') {
1161 $callback .= "&l_subtotal=Y";
1162 $href .= "&l_subtotal=Y";
1166 if ($form->{vc} eq 'vendor') {
1167 if ($form->{type} eq 'receive_order') {
1168 $form->{title} = $locale->text('Receive Merchandise');
1169 } elsif ($form->{type} eq 'purchase_order') {
1170 $form->{title} = $locale->text('Purchase Orders');
1172 $form->{title} = $locale->text('Request for Quotations');
1174 $name = $locale->text('Vendor');
1175 $employee = $locale->text('Employee');
1177 if ($form->{vc} eq 'customer') {
1178 if ($form->{type} eq 'sales_order') {
1179 $form->{title} = $locale->text('Sales Orders');
1180 $employee = $locale->text('Salesperson');
1181 } elsif ($form->{type} eq 'ship_order') {
1182 $form->{title} = $locale->text('Ship Merchandise');
1183 $employee = $locale->text('Salesperson');
1185 $form->{title} = $locale->text('Quotations');
1186 $employee = $locale->text('Employee');
1188 $name = $locale->text('Customer');
1191 $column_header{id} = qq|<th><a class=listheading href=$href&sort=id>|.$locale->text('ID').qq|</a></th>|;
1192 $column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>|.$locale->text('Date').qq|</a></th>|;
1193 $column_header{reqdate} = qq|<th><a class=listheading href=$href&sort=reqdate>|.$locale->text('Required by').qq|</a></th>|;
1194 $column_header{ordnumber} = qq|<th><a class=listheading href=$href&sort=ordnumber>|.$locale->text('Order').qq|</a></th>|;
1195 $column_header{quonumber} = qq|<th><a class=listheading href=$href&sort=quonumber>|.$locale->text('Quotation').qq|</a></th>|;
1196 $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>$name</a></th>|;
1197 $column_header{netamount} = qq|<th class=listheading>|.$locale->text('Amount').qq|</th>|;
1198 $column_header{tax} = qq|<th class=listheading>|.$locale->text('Tax').qq|</th>|;
1199 $column_header{amount} = qq|<th class=listheading>|.$locale->text('Total').qq|</th>|;
1200 $column_header{curr} = qq|<th class=listheading>|.$locale->text('Curr').qq|</th>|;
1201 $column_header{shipvia} = qq|<th><a class=listheading href=$href&sort=shipvia>|.$locale->text('Ship via').qq|</a></th>|;
1202 $column_header{open} = qq|<th class=listheading>|.$locale->text('O').qq|</th>|;
1203 $column_header{closed} = qq|<th class=listheading>|.$locale->text('C').qq|</th>|;
1205 $column_header{employee} = qq|<th><a class=listheading href=$href&sort=employee>$employee</a></th>|;
1208 if ($form->{$form->{vc}}) {
1209 $option = $locale->text(ucfirst $form->{vc});
1210 $option .= " : $form->{$form->{vc}}";
1212 if ($form->{warehouse}) {
1213 ($warehouse) = split /--/, $form->{warehouse};
1214 $option .= "\n<br>" if ($option);
1215 $option .= $locale->text('Warehouse');
1216 $option .= " : $warehouse";
1218 if ($form->{department}) {
1219 $option .= "\n<br>" if ($option);
1220 ($department) = split /--/, $form->{department};
1221 $option .= $locale->text('Department')." : $department";
1223 if ($form->{transdatefrom}) {
1224 $option .= "\n<br>".$locale->text('From')." ".$locale->date(\%myconfig, $form->{transdatefrom}, 1);
1226 if ($form->{transdateto}) {
1227 $option .= "\n<br>".$locale->text('Bis')." ".$locale->date(\%myconfig, $form->{transdateto}, 1);
1229 if ($form->{open}) {
1230 $option .= "\n<br>" if ($option);
1231 $option .= $locale->text('Open');
1233 if ($form->{closed}) {
1234 $option .= "\n<br>" if ($option);
1235 $option .= $locale->text('Closed');
1245 <th class=listtop>$form->{title}</th>
1247 <tr height="5"></tr>
1254 <tr class=listheading>|;
1256 map { print "\n$column_header{$_}" } @column_index;
1262 # add sort and escape callback
1263 $callback = $form->escape($callback . "&sort=$form->{sort}");
1265 if (@{ $form->{OE} }) {
1266 $sameitem = $form->{OE}->[0]->{$form->{sort}};
1270 $action = "ship_receive" if ($form->{type} =~ /(ship|receive)_order/);
1272 $warehouse = $form->escape($form->{warehouse});
1274 foreach $oe (@{ $form->{OE} }) {
1276 if ($form->{l_subtotal} eq 'Y') {
1277 if ($sameitem ne $oe->{$form->{sort}}) {
1279 $sameitem = $oe->{$form->{sort}};
1283 map { $oe->{$_} *= $oe->{exchangerate} } (qw(netamount amount));
1285 $column_data{netamount} = "<td align=right>".$form->format_amount(\%myconfig, $oe->{netamount}, 2, " ")."</td>";
1286 $column_data{tax} = "<td align=right>".$form->format_amount(\%myconfig, $oe->{amount} - $oe->{netamount}, 2, " ")."</td>";
1287 $column_data{amount} = "<td align=right>".$form->format_amount(\%myconfig, $oe->{amount}, 2, " ")."</td>";
1289 $totalnetamount += $oe->{netamount};
1290 $totalamount += $oe->{amount};
1292 $subtotalnetamount += $oe->{netamount};
1293 $subtotalamount += $oe->{amount};
1295 $column_data{id} = "<td>$oe->{id}</td>";
1296 $column_data{transdate} = "<td>$oe->{transdate} </td>";
1297 $column_data{reqdate} = "<td>$oe->{reqdate} </td>";
1299 $column_data{$ordnumber} = "<td><a href=oe.pl?path=$form->{path}&action=$action&type=$form->{type}&id=$oe->{id}&warehouse=$warehouse&vc=$form->{vc}&login=$form->{login}&password=$form->{password}&callback=$callback>$oe->{$ordnumber}</a></td>";
1300 $column_data{name} = "<td>$oe->{name}</td>";
1302 $column_data{employee} = "<td>$oe->{employee} </td>";
1303 $column_data{shipvia} = "<td>$oe->{shipvia} </td>";
1305 if ($oe->{closed}) {
1306 $column_data{closed} = "<td align=center>X</td>";
1307 $column_data{open} = "<td> </td>";
1309 $column_data{closed} = "<td> </td>";
1310 $column_data{open} = "<td align=center>X</td>";
1315 <tr class=listrow$i>";
1317 map { print "\n$column_data{$_}" } @column_index;
1325 if ($form->{l_subtotal} eq 'Y') {
1331 <tr class=listtotal>|;
1333 map { $column_data{$_} = "<td> </td>" } @column_index;
1335 $column_data{netamount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalnetamount, 2, " ")."</th>";
1336 $column_data{tax} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount - $totalnetamount, 2, " ")."</th>";
1337 $column_data{amount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount, 2, " ")."</th>";
1339 map { print "\n$column_data{$_}" } @column_index;
1347 <td><hr size=3 noshade></td>
1352 <form method=post action=$form->{script}>
1354 <input name=callback type=hidden value="$form->{callback}">
1356 <input type=hidden name=type value=$form->{type}>
1357 <input type=hidden name=vc value=$form->{vc}>
1359 <input type=hidden name=path value=$form->{path}>
1360 <input type=hidden name=login value=$form->{login}>
1361 <input type=hidden name=password value=$form->{password}>
1364 if ($form->{type} !~ /(ship|receive)_order/) {
1366 <input class=submit type=submit name=action value="|.$locale->text('Add').qq|">|;
1369 if ($form->{menubar}) {
1370 require "$form->{path}/menu.pl";
1381 $lxdebug->leave_sub();
1387 $lxdebug->enter_sub();
1389 map { $column_data{$_} = "<td> </td>" } @column_index;
1391 $column_data{netamount} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalnetamount, 2, " ")."</th>";
1392 $column_data{tax} = "<td class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount, 2, " ")."</th>";
1393 $column_data{amount} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalamount, 2, " ")."</th>";
1395 $subtotalnetamount = 0;
1396 $subtotalamount = 0;
1399 <tr class=listsubtotal>
1402 map { print "\n$column_data{$_}" } @column_index;
1408 $lxdebug->leave_sub();
1413 $lxdebug->enter_sub();
1415 if ($form->{type} =~ /_order$/) {
1416 $form->isblank("transdate", $locale->text('Order Date missing!'));
1418 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1421 $msg = ucfirst $form->{vc};
1422 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1424 # $locale->text('Customer missing!');
1425 # $locale->text('Vendor missing!');
1427 $form->isblank("exchangerate", $locale->text('Exchangerate missing!')) if ($form->{currency} ne $form->{defaultcurrency});
1431 # if the name changed get new values
1432 if (&check_name($form->{vc})) {
1437 $form->{id} = 0 if $form->{saveasnew};
1439 # this is for the internal notes section for the [email] Subject
1440 if ($form->{type} =~ /_order$/) {
1441 if ($form->{type} eq 'sales_order') {
1442 $form->{label} = $locale->text('Sales Order');
1444 $numberfld = "sonumber";
1445 $ordnumber = "ordnumber";
1447 $form->{label} = $locale->text('Purchase Order');
1449 $numberfld = "ponumber";
1450 $ordnumber = "ordnumber";
1453 $err = $locale->text('Cannot save order!');
1456 if ($form->{type} eq 'sales_quotation') {
1457 $form->{label} = $locale->text('Quotation');
1459 $numberfld = "sqnumber";
1460 $ordnumber = "quonumber";
1462 $form->{label} = $locale->text('Request for Quotation');
1464 $numberfld = "rfqnumber";
1465 $ordnumber = "quonumber";
1468 $err = $locale->text('Cannot save quotation!');
1472 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld) unless $form->{$ordnumber};
1474 $form->redirect($form->{label}." $form->{$ordnumber} ".$locale->text('saved!')) if (OE->save(\%myconfig, \%$form));
1477 $lxdebug->leave_sub();
1483 $lxdebug->enter_sub();
1487 if ($form->{type} =~ /_order$/) {
1488 $msg = $locale->text('Are you sure you want to delete Order Number');
1489 $ordnumber = 'ordnumber';
1491 $msg = $locale->text('Are you sure you want to delete Quotation Number');
1492 $ordnumber = 'quonumber';
1498 <form method=post action=$form->{script}>
1501 # delete action variable
1502 map { delete $form->{$_} } qw(action header);
1504 foreach $key (keys %$form) {
1505 $form->{$key} =~ s/\"/"/g;
1506 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1510 <h2 class=confirm>|.$locale->text('Confirm!').qq|</h2>
1512 <h4>$msg $form->{$ordnumber}</h4>
1514 <input name=action class=submit type=submit value="|.$locale->text('Yes').qq|">
1522 $lxdebug->leave_sub();
1528 $lxdebug->enter_sub();
1530 if ($form->{type} =~ /_order$/) {
1531 $msg = $locale->text('Order deleted!');
1532 $err = $locale->text('Cannot delete order!');
1534 $msg = $locale->text('Quotation deleted!');
1535 $err = $locale->text('Cannot delete quotation!');
1538 $form->redirect($msg) if (OE->delete(\%myconfig, \%$form, $spool));
1541 $lxdebug->leave_sub();
1547 $lxdebug->enter_sub();
1549 if ($form->{type} =~ /_order$/) {
1550 $form->isblank("ordnumber", $locale->text('Order Number missing!'));
1551 $form->isblank("transdate", $locale->text('Order Date missing!'));
1554 $form->isblank("quonumber", $locale->text('Quotation Number missing!'));
1555 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1556 $form->{ordnumber} = "";
1559 # if the name changed get new values
1560 if (&check_name($form->{vc})) {
1565 ($null, $form->{cp_id}) = split /--/, $form->{contact};
1566 $form->{cp_id} *= 1;
1568 if ($form->{type} =~ /_order/ && $form->{currency} ne $form->{defaultcurrency}) {
1569 # check if we need a new exchangerate
1570 $buysell = ($form->{type} eq 'sales_order') ? "buy" : "sell";
1572 $orddate = $form->current_date(\%myconfig);
1573 $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $orddate, $buysell);
1575 if (!$exchangerate) {
1576 &backorder_exchangerate($orddate, $buysell);
1582 # close orders/quotations
1583 $form->{closed} = 1;
1584 OE->save(\%myconfig, \%$form);
1587 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
1588 $form->{duedate} = $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
1591 $form->{closed} = 0;
1592 $form->{rowcount}--;
1593 $form->{shipto} = 1;
1595 if ($form->{type} =~ /_order$/) {
1596 $form->{exchangerate} = $exchangerate;
1601 if ($form->{type} eq 'purchase_order' || $form->{type} eq 'request_quotation') {
1602 $form->{title} = $locale->text('Add Vendor Invoice');
1603 $form->{script} = 'ir.pl';
1607 if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
1608 $form->{title} = $locale->text('Add Sales Invoice');
1609 $form->{script} = 'is.pl';
1615 # bo creates the id, reset it
1616 map { delete $form->{$_} } qw(id subject message cc bcc printed emailed queued);
1617 $form->{$form->{vc}} =~ s/--.*//g;
1618 $form->{type} = "invoice";
1621 $locale = new Locale "$myconfig{countrycode}", "$script";
1623 require "$form->{path}/$form->{script}";
1625 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1627 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(creditlimit creditremaining);
1629 $currency = $form->{currency};
1632 $form->{currency} = $currency;
1633 $form->{exchangerate} = "";
1634 $form->{forex} = "";
1635 $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, $buysell)));
1637 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
1642 for $i (1 .. $form->{rowcount}) {
1643 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"});
1645 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
1647 $decimalplaces = ($dec > 2) ? $dec : 2;
1649 $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
1650 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
1652 map { $form->{"${_}_$i"} =~ s/\"/"/g } qw(partnumber description unit);
1659 $lxdebug->leave_sub();
1664 sub backorder_exchangerate {
1665 $lxdebug->enter_sub();
1666 my ($orddate, $buysell) = @_;
1673 <form method=post action=$form->{script}>
1676 # delete action variable
1677 map { delete $form->{$_} } qw(action header exchangerate);
1679 foreach $key (keys %$form) {
1680 $form->{$key} =~ s/\"/"/g;
1681 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1684 $form->{title} = $locale->text('Add Exchangerate');
1688 <input type=hidden name=path value=$form->{path}>
1689 <input type=hidden name=login value=$form->{login}>
1690 <input type=hidden name=password value=$form->{password}>
1692 <input type=hidden name=exchangeratedate value=$orddate>
1693 <input type=hidden name=buysell value=$buysell>
1696 <tr><th class=listtop>$form->{title}</th></tr>
1697 <tr height="5"></tr>
1702 <th align=right>|.$locale->text('Currency').qq|</th>
1703 <td>$form->{currency}</td>
1706 <th align=right>|.$locale->text('Date').qq|</th>
1710 <th align=right>|.$locale->text('Exchangerate').qq|</th>
1711 <td><input name=exchangerate size=11></td>
1721 <input type=hidden name=nextsub value=save_exchangerate>
1723 <input name=action class=submit type=submit value="|.$locale->text('Continue').qq|">
1732 $lxdebug->leave_sub();
1736 sub save_exchangerate {
1737 $lxdebug->enter_sub();
1739 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'));
1740 $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate});
1741 $form->save_exchangerate(\%myconfig, $form->{currency}, $form->{exchangeratedate}, $form->{exchangerate}, $form->{buysell});
1745 $lxdebug->leave_sub();
1749 sub create_backorder {
1750 $lxdebug->enter_sub();
1752 $form->{shipped} = 1;
1754 # figure out if we need to create a backorder
1755 # items aren't saved if qty != 0
1757 for $i (1 .. $form->{rowcount}) {
1758 $totalqty += $qty = $form->{"qty_$i"};
1759 $totalship += $ship = $form->{"ship_$i"};
1761 $form->{"qty_$i"} = $qty - $ship;
1764 if ($totalship == 0) {
1765 map { $form->{"ship_$_"} = $form->{"qty_$_"} } (1 .. $form->{rowcount});
1766 $form->{ordtotal} = 0;
1767 $form->{shipped} = 0;
1771 if ($totalqty == $totalship) {
1772 map { $form->{"qty_$_"} = $form->{"ship_$_"} } (1 .. $form->{rowcount});
1773 $form->{ordtotal} = 0;
1777 @flds = (qw(partnumber description qty ship unit sellprice discount id inventory_accno bin income_accno expense_accno listprice assembly taxaccounts partsgroup));
1779 for $i (1 .. $form->{rowcount}) {
1780 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}) } qw(sellprice discount);
1784 OE->save(\%myconfig, \%$form);
1786 # rebuild rows for invoice
1790 for $i (1 .. $form->{rowcount}) {
1791 $form->{"qty_$i"} = $form->{"ship_$i"};
1793 if ($form->{"qty_$i"}) {
1796 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1801 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
1802 $form->{rowcount} = $count;
1804 $lxdebug->leave_sub();
1810 $lxdebug->enter_sub();
1812 $form->{saveasnew} = 1;
1813 $form->{closed} = 0;
1814 map { delete $form->{$_} } qw(printed emailed queued);
1818 $lxdebug->leave_sub();
1822 sub purchase_order {
1823 $lxdebug->enter_sub();
1825 $form->{title} = $locale->text('Add Purchase Order');
1826 $form->{vc} = "vendor";
1827 $form->{type} = "purchase_order";
1831 $lxdebug->leave_sub();
1836 $lxdebug->enter_sub();
1839 if ($form->{type} eq 'sales_quotation'|| $form->{type} eq 'request_quotation') {
1840 $form->{closed} = 1;
1841 OE->save(\%myconfig, \%$form);
1844 ($null, $form->{cp_id}) = split /--/, $form->{contact};
1845 $form->{cp_id} *= 1;
1847 $form->{title} = $locale->text('Add Sales Order');
1848 $form->{vc} = "customer";
1849 $form->{type} = "sales_order";
1853 $lxdebug->leave_sub();
1858 $lxdebug->enter_sub();
1861 $form->{transdate} = $form->current_date(\%myconfig);
1862 delete $form->{duedate};
1864 $form->{closed} = 0;
1867 map { delete $form->{$_} } qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal);
1874 for $i (1 .. $form->{rowcount} - 1) {
1875 map { $form->{"${_}_$i"} =~ s/\"/"/g } qw(partnumber description unit);
1878 map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 0, "0") } qw(creditlimit creditremaining);
1882 $lxdebug->leave_sub();
1887 $lxdebug->enter_sub();
1893 OE->get_warehouses(\%myconfig, \%$form);
1896 if (@{ $form->{all_warehouses} }) {
1897 $form->{selectwarehouse} = "<option>\n";
1899 map { $form->{selectwarehouse} .= "<option>$_->{description}--$_->{id}\n" } (@{ $form->{all_warehouses} });
1901 if ($form->{warehouse}) {
1902 $form->{selectwarehouse} = "<option>$form->{warehouse}";
1906 $form->{shippingdate} = $form->current_date(\%myconfig);
1907 $form->{"$form->{vc}"} =~ s/--.*//;
1912 foreach $key (keys %$form) {
1913 if ($key =~ /_1$/) {
1919 for $i (1 .. $form->{rowcount}) {
1920 # undo formatting from prepare_order
1921 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(qty ship);
1922 $n = ($form->{"qty_$i"} -= $form->{"ship_$i"});
1923 if (abs($n) > 0 && ($form->{"inventory_accno_$i"} || $form->{"assembly_$i"})) {
1924 $form->{"ship_$i"} = "";
1925 $form->{"serialnumber_$i"} = "";
1930 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1935 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
1936 $form->{rowcount} = $count;
1938 &display_ship_receive;
1940 $lxdebug->leave_sub();
1944 sub display_ship_receive {
1945 $lxdebug->enter_sub();
1947 $vclabel = ucfirst $form->{vc};
1948 $vclabel = $locale->text($vclabel);
1950 $form->{rowcount}++;
1952 if ($form->{vc} eq 'customer') {
1953 $form->{title} = $locale->text('Ship Merchandise');
1954 $shipped = $locale->text('Shipping Date');
1956 $form->{title} = $locale->text('Receive Merchandise');
1957 $shipped = $locale->text('Date Received');
1960 # set option selected
1961 foreach $item (warehouse, employee) {
1962 $form->{"select$item"} =~ s/ selected//;
1963 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
1969 <th align=right>|.$locale->text('Warehouse').qq|</th>
1970 <td><select name=warehouse>$form->{selectwarehouse}</select></td>
1971 <input type=hidden name=selectwarehouse value="$form->{selectwarehouse}">
1973 | if $form->{selectwarehouse};
1977 <th align=right nowrap>|.$locale->text('Contact').qq|</th>
1978 <td><select name=employee>$form->{selectemployee}</select></td>
1979 <input type=hidden name=selectemployee value="$form->{selectemployee}">
1989 <form method=post action=$form->{script}>
1991 <input type=hidden name=id value=$form->{id}>
1993 <input type=hidden name=display_form value=display_ship_receive>
1995 <input type=hidden name=type value=$form->{type}>
1996 <input type=hidden name=media value=$form->{media}>
1997 <input type=hidden name=format value=$form->{format}>
1999 <input type=hidden name=queued value="$form->{queued}">
2000 <input type=hidden name=printed value="$form->{printed}">
2001 <input type=hidden name=emailed value="$form->{emailed}">
2003 <input type=hidden name=vc value=$form->{vc}>
2007 <th class=listtop>$form->{title}</th>
2009 <tr height="5"></tr>
2012 <table width="100%">
2017 <th align=right>$vclabel</th>
2018 <td colspan=3>$form->{$form->{vc}}</td>
2019 <input type=hidden name=$form->{vc} value="$form->{$form->{vc}}">
2020 <input type=hidden name="$form->{vc}_id" value=$form->{"$form->{vc}_id"}>
2024 <th align=right>|.$locale->text('Shipping Point').qq|</th>
2026 <input name=shippingpoint size=35 value="$form->{shippingpoint}">
2029 <th align=right>|.$locale->text('Ship via').qq|</th>
2031 <input name=shipvia size=35 value="$form->{shipvia}">
2040 <th align=right nowrap>|.$locale->text('Order Number').qq|</th>
2041 <td>$form->{ordnumber}</td>
2042 <input type=hidden name=ordnumber value="$form->{ordnumber}">
2045 <th align=right nowrap>|.$locale->text('Order Date').qq|</th>
2046 <td>$form->{transdate}</td>
2047 <input type=hidden name=transdate value=$form->{transdate}>
2050 <th align=right nowrap>$shipped</th>
2051 <td><input name=shippingdate size=11 value=$form->{shippingdate}></td>
2060 <!-- shipto are in hidden variables -->
2062 <input type=hidden name=shiptoname value="$form->{shiptoname}">
2063 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
2064 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
2065 <input type=hidden name=shiptocity value="$form->{shiptocity}">
2066 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
2067 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
2068 <input type=hidden name=shiptophone value="$form->{shiptophone}">
2069 <input type=hidden name=shiptofax value="$form->{shiptofax}">
2070 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
2072 <!-- email variables -->
2073 <input type=hidden name=message value="$form->{message}">
2074 <input type=hidden name=email value="$form->{email}">
2075 <input type=hidden name=subject value="$form->{subject}">
2076 <input type=hidden name=cc value="$form->{cc}">
2077 <input type=hidden name=bcc value="$form->{bcc}">
2082 @column_index = (partnumber, description, qty, ship, unit, bin, serialnumber);
2084 if ($form->{type} eq "ship_order") {
2085 $column_data{ship} = qq|<th class=listheading align=center width="auto">|.$locale->text('Ship').qq|</th>|;
2087 if ($form->{type} eq "receive_order") {
2088 $column_data{ship} = qq|<th class=listheading align=center width="auto">|.$locale->text('Recd').qq|</th>|;
2091 my $colspan = $#column_index + 1;
2093 $column_data{partnumber} = qq|<th class=listheading nowrap>|.$locale->text('Number').qq|</th>|;
2094 $column_data{description} = qq|<th class=listheading nowrap>|.$locale->text('Description').qq|</th>|;
2095 $column_data{qty} = qq|<th class=listheading nowrap>|.$locale->text('Qty').qq|</th>|;
2096 $column_data{unit} = qq|<th class=listheading nowrap>|.$locale->text('Unit').qq|</th>|;
2097 $column_data{bin} = qq|<th class=listheading nowrap>|.$locale->text('Bin').qq|</th>|;
2098 $column_data{serialnumber} = qq|<th class=listheading nowrap>|.$locale->text('Serial No.').qq|</th>|;
2104 <tr class=listheading>|;
2106 map { print "\n$column_data{$_}" } @column_index;
2113 for $i (1 .. $form->{rowcount} - 1) {
2116 $form->{"ship_$i"} = $form->parse_amount(\%myconfig, $form->{"ship_$i"});
2118 # convert " to "
2119 map { $form->{"${_}_$i"} =~ s/\"/"/g } qw(partnumber description unit bin serialnumber);
2121 $description = $form->{"description_$i"};
2122 $description =~ s/\n/<br>/g;
2124 $column_data{partnumber} = qq|<td>$form->{"partnumber_$i"}<input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}"></td>|;
2125 $column_data{description} = qq|<td>$description<input type=hidden name="description_$i" value="$form->{"description_$i"}"></td>|;
2126 $column_data{qty} = qq|<td align=right>|.$form->format_amount(\%myconfig, $form->{"qty_$i"}).qq|<input type=hidden name="qty_$i" value="$form->{"qty_$i"}"></td>|;
2127 $column_data{ship} = qq|<td align=right><input name="ship_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"ship_$i"}).qq|></td>|;
2128 $column_data{unit} = qq|<td>$form->{"unit_$i"}<input type=hidden name="unit_$i" value="$form->{"unit_$i"}"></td>|;
2129 $column_data{bin} = qq|<td>$form->{"bin_$i"}<input type=hidden name="bin_$i" value="$form->{"bin_$i"}"></td>|;
2131 $column_data{serialnumber} = qq|<td><input name="serialnumber_$i" size=15 value="$form->{"serialnumber_$i"}"></td>|;
2136 map { print "\n$column_data{$_}" } @column_index;
2141 <input type=hidden name="orderitems_id_$i" value=$form->{"orderitems_id_$i"}>
2142 <input type=hidden name="id_$i" value=$form->{"id_$i"}>
2143 <input type=hidden name="assembly_$i" value="$form->{"assembly_$i"}">
2144 <input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">
2155 <td><hr size=3 noshade></td>
2161 $form->{copies} = 1;
2170 <input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
2171 <input class=submit type=submit name=action value="|.$locale->text('Print').qq|">
2174 if ($form->{type} eq 'ship_order') {
2176 <input class=submit type=submit name=action value="|.$locale->text('Ship to').qq|">
2177 <input class=submit type=submit name=action value="|.$locale->text('E-mail').qq|">
2183 <input class=submit type=submit name=action value="|.$locale->text('Done').qq|">
2186 if ($form->{menubar}) {
2187 require "$form->{path}/menu.pl";
2193 <input type=hidden name=rowcount value=$form->{rowcount}>
2195 <input name=callback type=hidden value="$callback">
2197 <input type=hidden name=path value=$form->{path}>
2198 <input type=hidden name=login value=$form->{login}>
2199 <input type=hidden name=password value=$form->{password}>
2208 $lxdebug->leave_sub();
2213 $lxdebug->enter_sub();
2215 if ($form->{type} eq 'ship_order') {
2216 $form->isblank("shippingdate", $locale->text('Shipping Date missing!'));
2218 $form->isblank("shippingdate", $locale->text('Date received missing!'));
2222 map { $total += $form->{"ship_$_"} = $form->parse_amount(\%myconfig, $form->{"ship_$_"}) } (1 .. $form->{rowcount} - 1);
2224 $form->error($locale->text('Nothing entered!')) unless $total;
2226 $form->redirect($locale->text('Inventory saved!')) if OE->save_inventory(\%myconfig, \%$form);
2227 $form->error($locale->text('Could not save!'));
2229 $lxdebug->leave_sub();
2233 sub search_transfer {
2234 $lxdebug->enter_sub();
2236 OE->get_warehouses(\%myconfig, \%$form);
2239 if (@{ $form->{all_warehouses} }) {
2240 $form->{selectwarehouse} = "<option>\n";
2241 $form->{warehouse} = qq|$form->{warehouse}--$form->{warehouse_id}|;
2243 map { $form->{selectwarehouse} .= "<option>$_->{description}--$_->{id}\n" } (@{ $form->{all_warehouses} });
2245 $form->error($locale->text('Nothing to transfer!'));
2248 $form->{title} = $locale->text('Transfer Inventory');
2255 <form method=post action=$form->{script}>
2259 <th class=listtop>$form->{title}</th>
2261 <tr height="5"></tr>
2266 <th align=right nowrap>|.$locale->text('Transfer to').qq|</th>
2267 <td><select name=warehouse>$form->{selectwarehouse}</select></td>
2270 <th align="right" nowrap="true">|.$locale->text('Part Number').qq|</th>
2271 <td><input name=partnumber size=20></td>
2274 <th align="right" nowrap="true">|.$locale->text('Description').qq|</th>
2275 <td><input name=description size=40></td>
2278 <th align=right nowrap>|.$locale->text('Group').qq|</th>
2279 <td><input name=partsgroup size=20></td>
2285 <td><hr size=3 noshade></td>
2290 <input type=hidden name=sort value=partnumber>
2291 <input type=hidden name=nextsub value=list_transfer>
2293 <input type=hidden name=path value=$form->{path}>
2294 <input type=hidden name=login value=$form->{login}>
2295 <input type=hidden name=password value=$form->{password}>
2297 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
2304 $lxdebug->leave_sub();
2309 $lxdebug->enter_sub();
2311 OE->get_inventory(\%myconfig, \%$form);
2313 $partnumber = $form->escape($form->{partnumber});
2314 $warehouse = $form->escape($form->{warehouse});
2315 $description = $form->escape($form->{description});
2316 $partsgroup = $form->escape($form->{partsgroup});
2319 $href = "$form->{script}?path=$form->{path}&action=list_transfer&partnumber=$partnumber&warehouse=$warehouse&description=$description&partsgroup=$partsgroup&login=$form->{login}&password=$form->{password}";
2321 # construct callback
2322 $partnumber = $form->escape($form->{partnumber},1);
2323 $warehouse = $form->escape($form->{warehouse},1);
2324 $description = $form->escape($form->{description},1);
2325 $partsgroup = $form->escape($form->{partsgroup},1);
2327 $callback = "$form->{script}?path=$form->{path}&action=list_transfer&partnumber=$partnumber&warehouse=$warehouse&description=$description&partsgroup=$partsgroup&login=$form->{login}&password=$form->{password}";
2329 @column_index = $form->sort_columns(qw(partnumber description partsgroup make model warehouse qty transfer));
2332 $column_header{partnumber} = qq|<th><a class=listheading href=$href&sort=partnumber>|.$locale->text('Part Number').qq|</a></th>|;
2333 $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
2334 $column_header{partsgroup} = qq|<th><a class=listheading href=$href&sort=partsgroup>|.$locale->text('Group').qq|</a></th>|;
2335 $column_header{warehouse} = qq|<th><a class=listheading href=$href&sort=warehouse>|.$locale->text('From').qq|</a></th>|;
2336 $column_header{qty} = qq|<th><a class=listheading>|.$locale->text('Qty').qq|</a></th>|;
2337 $column_header{transfer} = qq|<th><a class=listheading>|.$locale->text('Transfer').qq|</a></th>|;
2340 $option = $locale->text('Transfer to');
2342 ($warehouse, $warehouse_id) = split /--/, $form->{warehouse};
2344 if ($form->{warehouse}) {
2345 $option .= " : $warehouse";
2347 if ($form->{partnumber}) {
2348 $option .= "\n<br>" if ($option);
2349 $option .= $locale->text('Part Number')." : $form->{partnumber}";
2351 if ($form->{description}) {
2352 $option .= "\n<br>" if ($option);
2353 $option .= $locale->text('Description')." : $form->{description}";
2355 if ($form->{partsgroup}) {
2356 $option .= "\n<br>" if ($option);
2357 $option .= $locale->text('Group')." : $form->{partsgroup}";
2360 $form->{title} = $locale->text('Transfer Inventory');
2367 <form method=post action=$form->{script}>
2369 <input type=hidden name=warehouse_id value=$warehouse_id>
2373 <th class=listtop>$form->{title}</th>
2375 <tr height="5"></tr>
2382 <tr class=listheading>|;
2384 map { print "\n$column_header{$_}" } @column_index;
2391 if (@{ $form->{all_inventory} }) {
2392 $sameitem = $form->{all_inventory}->[0]->{$form->{sort}};
2396 foreach $ref (@{ $form->{all_inventory} }) {
2400 $column_data{partnumber} = qq|<td><input type=hidden name="id_$i" value=$ref->{id}>$ref->{partnumber}</td>|;
2401 $column_data{description} = "<td>$ref->{description} </td>";
2402 $column_data{partsgroup} = "<td>$ref->{partsgroup} </td>";
2403 $column_data{warehouse} = qq|<td><input type=hidden name="warehouse_id_$i" value=$ref->{warehouse_id}>$ref->{warehouse} </td>|;
2404 $column_data{qty} = qq|<td><input type=hidden name="qty_$i" value=$ref->{qty}>|.$form->format_amount(\%myconfig, $ref->{qty}).qq|</td>|;
2405 $column_data{transfer} = qq|<td><input name="transfer_$i" size=4></td>|;
2409 <tr class=listrow$j>";
2411 map { print "\n$column_data{$_}" } @column_index;
2425 <td><hr size=3 noshade></td>
2431 <input name=callback type=hidden value="$callback">
2433 <input type=hidden name=rowcount value=$i>
2435 <input type=hidden name=path value=$form->{path}>
2436 <input type=hidden name=login value=$form->{login}>
2437 <input type=hidden name=password value=$form->{password}>
2439 <input class=submit type=submit name=action value="|.$locale->text('Transfer').qq|">|;
2441 if ($form->{menubar}) {
2442 require "$form->{path}/menu.pl";
2454 $lxdebug->leave_sub();
2459 $lxdebug->enter_sub();
2461 $form->redirect($locale->text('Inventory transferred!')) if OE->transfer(\%myconfig, \%$form);
2462 $form->error($locale->text('Could not transfer Inventory!'));
2464 $lxdebug->leave_sub();