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-2002
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 #======================================================================
30 # Inventory invoicing module
32 #======================================================================
38 require "$form->{path}/io.pl";
39 require "$form->{path}/arap.pl";
46 $lxdebug->enter_sub();
48 if ($form->{type} eq "credit_note") {
49 $form->{title} = $locale->text('Add Credit Note');
51 if ($form->{storno}) {
52 $form->{title} = $locale->text('Add Storno Credit Note');
55 $form->{title} = $locale->text('Add Sales Invoice');
61 "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&path=$form->{path}&password=$form->{password}"
62 unless $form->{callback};
64 $form{jsscript} = "date";
66 if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR")
68 $form->error("Access Denied");
74 $lxdebug->leave_sub();
78 $lxdebug->enter_sub();
81 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
82 #/show hhistory button
84 if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR")
86 $form->error("Access Denied");
89 if ($form->{print_and_post}) {
90 $form->{action} = "print";
91 $form->{resubmit} = 1;
92 $language_id = $form->{language_id};
93 $printer_id = $form->{printer_id};
97 if ($form->{print_and_post}) {
98 $form->{language_id} = $language_id;
99 $form->{printer_id} = $printer_id;
104 $lxdebug->leave_sub();
108 $lxdebug->enter_sub();
110 $form->{vc} = 'customer';
113 $form->{webdav} = $webdav;
114 $form->{lizenzen} = $lizenzen;
116 $form->create_links("AR", \%myconfig, "customer");
118 if ($form->{all_customer}) {
119 unless ($form->{customer_id}) {
120 $form->{customer_id} = $form->{all_customer}->[0]->{id};
124 if ($form->{payment_id}) {
125 $payment_id = $form->{payment_id};
127 if ($form->{language_id}) {
128 $language_id = $form->{language_id};
130 if ($form->{taxzone_id}) {
131 $taxzone_id = $form->{taxzone_id};
136 if ($form->{shipto_id}) {
137 $shipto_id = $form->{shipto_id};
140 $cp_id = $form->{cp_id};
141 IS->get_customer(\%myconfig, \%$form);
143 #quote all_customer Bug 133
144 foreach $ref (@{ $form->{all_customer} }) {
145 $ref->{name} = $form->quote($ref->{name});
150 IS->retrieve_invoice(\%myconfig, \%$form);
151 $form->{cp_id} = $cp_id;
154 $form->{payment_id} = $payment_id;
157 $form->{language_id} = $language_id;
160 $form->{taxzone_id} = $taxzone_id;
163 $form->{shipto_id} = $shipto_id;
167 @curr = split(/:/, $form->{currencies});
169 $form->{defaultcurrency} = $curr[0];
171 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
173 $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
175 if (@{ $form->{all_customer} }) {
176 $form->{customer} = "$form->{customer}--$form->{customer_id}";
177 map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" }
178 (@{ $form->{all_customer} });
182 if ($form->{all_departments}) {
183 $form->{selectdepartment} = "<option>\n";
184 $form->{department} = "$form->{department}--$form->{department_id}";
187 $form->{selectdepartment} .=
188 "<option>$_->{description}--$_->{id}\n"
189 } (@{ $form->{all_departments} });
192 $form->{employee} = "$form->{employee}--$form->{employee_id}";
195 if ($form->{all_employees}) {
196 $form->{selectemployee} = "";
197 map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" }
198 (@{ $form->{all_employees} });
202 $form->{forex} = $form->{exchangerate};
203 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
205 foreach $key (keys %{ $form->{AR_links} }) {
206 foreach $ref (@{ $form->{AR_links}{$key} }) {
207 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
210 if ($key eq "AR_paid") {
211 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
212 $form->{"AR_paid_$i"} =
213 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
216 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
217 $form->{"datepaid_$i"} =
218 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
219 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
220 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
221 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
222 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
224 $form->{paidaccounts} = $i;
228 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
233 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
235 $form->{AR} = $form->{AR_1} unless $form->{id};
238 ($form->datetonum($form->{invdate}, \%myconfig) <=
239 $form->datetonum($form->{closedto}, \%myconfig));
241 $lxdebug->leave_sub();
244 sub prepare_invoice {
245 $lxdebug->enter_sub();
247 if ($form->{type} eq "credit_note") {
248 $form->{type} = "credit_note";
249 $form->{formname} = "credit_note";
251 $form->{type} = "invoice";
252 $form->{formname} = "invoice";
257 map { $form->{$_} =~ s/\"/"/g }
258 qw(invnumber ordnumber quonumber shippingpoint shipvia notes intnotes);
260 # # get pricegroups for parts
261 # IS->get_pricegroups_for_parts(\%myconfig, \%$form);
265 foreach $ref (@{ $form->{invoice_details} }) {
268 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
269 $form->{"discount_$i"} =
270 $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
271 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
273 $decimalplaces = ($dec > 2) ? $dec : 2;
275 $form->{"sellprice_$i"} =
276 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
279 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
280 $dec_qty = length $dec_qty;
283 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
285 map { $form->{"${_}_$i"} =~ s/\"/"/g }
286 qw(partnumber description unit partnotes);
287 $form->{rowcount} = $i;
291 $lxdebug->leave_sub();
295 $lxdebug->enter_sub();
299 if ($form->{type} eq "credit_note") {
300 $form->{title} = $locale->text('Edit Credit Note');
302 if ($form->{storno}) {
303 $form->{title} = $locale->text('Edit Storno Credit Note');
306 $form->{title} = $locale->text('Edit Sales Invoice');
308 if ($form->{storno}) {
309 $form->{title} = $locale->text('Edit Storno Invoice');
315 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
317 $payment = qq|<option value=""></option>|;
318 foreach $item (@{ $form->{payment_terms} }) {
319 if ($form->{payment_id} eq $item->{id}) {
320 $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
322 $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
326 my $set_duedate_url =
327 "$form->{script}?login=$form->{login}&path=$form->{path}&password=$form->{password}&action=set_duedate";
329 my $pjx = new CGI::Ajax( 'set_duedate' => $set_duedate_url );
330 push(@ { $form->{AJAX} }, $pjx);
332 if (@{ $form->{TAXZONE} }) {
333 $form->{selecttaxzone} = "";
334 foreach $item (@{ $form->{TAXZONE} }) {
335 if ($item->{id} == $form->{taxzone_id}) {
336 $form->{selecttaxzone} .=
337 "<option value=$item->{id} selected>" . H($item->{description}) .
340 $form->{selecttaxzone} .=
341 "<option value=$item->{id}>" . H($item->{description}) . "</option>";
346 $form->{selecttaxzone} =~ s/ selected//g;
347 if ($form->{taxzone_id} ne "") {
348 $form->{selecttaxzone} =~ s/value=$form->{taxzone_id}/value=$form->{taxzone_id} selected/;
354 <th align=right>| . $locale->text('Steuersatz') . qq|</th>
355 <td><select name=taxzone_id>$form->{selecttaxzone}</select></td>
356 <input type=hidden name=selecttaxzone value="$form->{selecttaxzone}">
359 my @old_project_ids = ($form->{"globalproject_id"});
360 map({ push(@old_project_ids, $form->{"project_id_$_"})
361 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
363 $form->get_lists("contacts" => "ALL_CONTACTS",
364 "shipto" => "ALL_SHIPTO",
365 "projects" => { "key" => "ALL_PROJECTS",
367 "old_id" => \@old_project_ids });
369 my (%labels, @values);
370 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
371 push(@values, $item->{"cp_id"});
372 $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
373 ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
376 NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
377 '-labels' => \%labels, '-default' => $form->{"cp_id"}));
381 foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
382 push(@values, $item->{"shipto_id"});
383 $labels{$item->{"shipto_id"}} =
384 $item->{"shiptoname"} . " " . $item->{"shiptodepartment_1"};
388 <th align=right>| . $locale->text('Shipping Address') . qq|</th>
390 NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values,
391 '-labels' => \%labels, '-default' => $form->{"shipto_id"}))
396 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
397 push(@values, $item->{"id"});
398 $labels{$item->{"id"}} = $item->{"projectnumber"};
400 my $globalprojectnumber =
401 NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
402 '-labels' => \%labels,
403 '-default' => $form->{"globalproject_id"}));
405 # set option selected
406 foreach $item (qw(AR customer currency department employee)) {
407 $form->{"select$item"} =~ s/ selected//;
408 $form->{"select$item"} =~
409 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
412 #quote customer Bug 133
413 $form->{selectcustomer} = $form->quote($form->{selectcustomer});
415 if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) {
421 $form->{exchangerate} =
422 $form->format_amount(\%myconfig, $form->{exchangerate});
424 $form->{creditlimit} =
425 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
426 $form->{creditremaining} =
427 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
430 if ($form->{currency} ne $form->{defaultcurrency}) {
431 if ($form->{forex}) {
434 . $locale->text('Exchangerate')
435 . qq|</th><td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>|;
439 . $locale->text('Exchangerate')
440 . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
444 <input type=hidden name=forex value=$form->{forex}>
448 ($form->{selectcustomer})
449 ? qq|<select name=customer>$form->{selectcustomer}</select>\n<input type=hidden name="selectcustomer" value="$form->{selectcustomer}">|
450 : qq|<input name=customer value="$form->{customer}" size=35>|;
454 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
455 <td colspan=3><select name=department>$form->{selectdepartment}</select>
456 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
459 | if $form->{selectdepartment};
461 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
463 if ($form->{business}) {
466 <th align=right>| . $locale->text('Business') . qq|</th>
467 <td>$form->{business}</td>
468 <th align=right>| . $locale->text('Trade Discount') . qq|</th>
470 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
476 if ($form->{max_dunning_level}) {
482 <th align=right>| . $locale->text('Max. Dunning Level') . qq|:</th>
483 <td><b>$form->{max_dunning_level}</b></td>
484 <th align=right>| . $locale->text('Dunning Amount') . qq|:</th>
486 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
495 $form->{fokus} = "invoice.customer";
497 # use JavaScript Calendar or not
498 $form->{jsscript} = $jscalendar;
500 if ($form->{type} eq "credit_note") {
501 if ($form->{jsscript}) {
503 # with JavaScript Calendar
505 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
506 <td><input type=button name=invdate id="trigger1" value=|
507 . $locale->text('button') . qq|></td>
512 Form->write_trigger(\%myconfig, "1",
517 # without JavaScript Calendar
519 qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
521 qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
524 if ($form->{jsscript}) {
526 # with JavaScript Calendar
528 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
529 <td><input type=button name=invdate id="trigger1" value=|
530 . $locale->text('button') . qq|></td>
533 <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
534 <td width="4"><input type=button name=duedate id="trigger2" value=|
535 . $locale->text('button') . qq|></td></td>
538 <td width="13"><input name=deliverydate id=deliverydate size=11 title="$myconfig{dateformat}" value=$form->{deliverydate}></td>
539 <td width="4"><input type=button name=deliverydate id="trigger3" value=|
540 . $locale->text('button') . qq|></td></td>
545 Form->write_trigger(\%myconfig, "3",
547 "trigger1", "duedate",
549 "deliverydate", "BL",
553 # without JavaScript Calendar
555 qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
557 qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
560 if ($form->{resubmit} && ($form->{format} eq "html")) {
562 qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|;
563 } elsif ($form->{resubmit}) {
564 $onload = qq|document.invoice.submit()|;
569 $credittext = $locale->text('Credit Limit exceeded!!!');
570 if ($creditwarning) {
571 $onload = qq|alert('$credittext')|;
574 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
577 $form->write_trigger(\%myconfig, 2,
578 "orddate", "BL", "trigger_orddate",
579 "quodate", "BL", "trigger_quodate");
580 # show history button js
581 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
582 #/show history button js
586 <body onLoad="$onload">
587 <script type="text/javascript" src="js/common.js"></script>
588 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
589 <script type="text/javascript" src="js/vendor_selection.js"></script>
590 <script type="text/javascript" src="js/calculate_qty.js"></script>
592 <form method=post name="invoice" action=$form->{script}>
595 <input type=hidden name=id value=$form->{id}>
596 <input type=hidden name=action value=$form->{action}>
598 <input type=hidden name=type value=$form->{type}>
599 <input type=hidden name=media value=$form->{media}>
600 <input type=hidden name=format value=$form->{format}>
602 <input type=hidden name=queued value="$form->{queued}">
603 <input type=hidden name=printed value="$form->{printed}">
604 <input type=hidden name=emailed value="$form->{emailed}">
606 <input type=hidden name=title value="$form->{title}">
607 <input type=hidden name=vc value=$form->{vc}>
609 <input type=hidden name=discount value=$form->{discount}>
610 <input type=hidden name=creditlimit value=$form->{creditlimit}>
611 <input type=hidden name=creditremaining value=$form->{creditremaining}>
613 <input type=hidden name=tradediscount value=$form->{tradediscount}>
614 <input type=hidden name=business value=$form->{business}>
616 <input type=hidden name=closedto value=$form->{closedto}>
617 <input type=hidden name=locked value=$form->{locked}>
619 <input type=hidden name=shipped value=$form->{shipped}>
620 <input type=hidden name=lizenzen value=$lizenzen>
621 <input type=hidden name=storno value=$form->{storno}>
622 <input type=hidden name=storno_id value=$form->{storno_id}>
628 <th class=listtop>$form->{title}</th>
638 <th align=right nowrap>| . $locale->text('Customer') . qq|</th>
639 <td colspan=3>$customer</td>
640 <input type=hidden name=customer_klass value=$form->{customer_klass}>
641 <input type=hidden name=customer_id value=$form->{customer_id}>
642 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
643 <th align=richt nowrap>|
644 . $locale->text('Contact Person') . qq|</th>
645 <td colspan=3>$contact</td>
652 <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
653 <td>$form->{creditlimit}</td>
655 <th nowrap>| . $locale->text('Remaining') . qq|</th>
656 <td class="plus$n">$form->{creditremaining}</td>
665 <th align=right nowrap>| . $locale->text('Record in') . qq|</th>
666 <td colspan=3><select name=AR style="width:280px;">$form->{selectAR}</select></td>
667 <input type=hidden name=selectAR value="$form->{selectAR}">
672 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
673 <td><select name=currency>$form->{selectcurrency}</select></td>
674 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
675 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
676 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
677 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
681 <th align=right nowrap>| . $locale->text('Shipping Point') . qq|</th>
682 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
685 <th align=right nowrap>| . $locale->text('Ship via') . qq|</th>
686 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
693 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
695 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
696 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
700 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
702 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
703 # <input size=45 id=delivery_vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
713 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
714 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
715 <input type=hidden name=selectemployee value="$form->{selectemployee}">
718 if ($form->{type} eq "credit_note") {
720 <th align=right nowrap>| . $locale->text('Credit Note Number') . qq|</th>
721 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
724 <th align=right>| . $locale->text('Credit Note Date') . qq|</th>
729 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
730 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
733 <th align=right>| . $locale->text('Invoice Date') . qq|</th>
737 <th align=right>| . $locale->text('Due Date') . qq|</th>
741 <th align=right>| . $locale->text('Delivery Date') . qq|</th>
746 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
747 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
750 <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
751 <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|"></td>
752 <td><input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
755 <th align=right nowrap>| . $locale->text('Quotation Number') . qq|</th>
756 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
759 <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
760 <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|"></td>
761 <td><input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
764 <th align=right nowrap>| . $locale->text('Customer Order Number') . qq|</th>
765 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
768 <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
769 <td>$globalprojectnumber</td>
784 <!-- shipto are in hidden variables -->
786 <input type=hidden name=shiptoname value="$form->{shiptoname}">
787 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
788 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
789 <input type=hidden name=shiptocity value="$form->{shiptocity}">
790 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
791 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
792 <input type=hidden name=shiptophone value="$form->{shiptophone}">
793 <input type=hidden name=shiptofax value="$form->{shiptofax}">
794 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
796 <!-- email variables -->
797 <input type=hidden name=message value="$form->{message}">
798 <input type=hidden name=email value="$form->{email}">
799 <input type=hidden name=subject value="$form->{subject}">
800 <input type=hidden name=cc value="$form->{cc}">
801 <input type=hidden name=bcc value="$form->{bcc}">
802 <input type=hidden name=webdav value=$webdav>
803 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
806 foreach $item (split / /, $form->{taxaccounts}) {
808 <input type=hidden name="${item}_rate" value="$form->{"${item}_rate"}">
809 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
810 <input type=hidden name="${item}_taxnumber" value="$form->{"${item}_taxnumber"}">
813 $lxdebug->leave_sub();
817 $lxdebug->enter_sub();
819 $form->{invtotal} = $form->{invsubtotal};
821 if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
824 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
827 $rows = ($rows > $introws) ? $rows : $introws;
829 qq|<textarea name=notes rows=$rows cols=26 wrap=soft>$form->{notes}</textarea>|;
831 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
833 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
836 if ($form->{taxaccounts}) {
838 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
839 . $locale->text('Tax Included') . qq|</b><br><br>|;
842 if (!$form->{taxincluded}) {
844 foreach $item (split / /, $form->{taxaccounts}) {
845 if ($form->{"${item}_base"}) {
846 $form->{"${item}_total"} =
848 $form->{"${item}_base"} * $form->{"${item}_rate"},
850 $form->{invtotal} += $form->{"${item}_total"};
851 $form->{"${item}_total"} =
852 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
856 <th align=right>$form->{"${item}_description"} |
857 . $form->{"${item}_rate"} * 100 .qq|%</th>
858 <td align=right>$form->{"${item}_total"}</td>
864 $form->{invsubtotal} =
865 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
869 <th align=right>| . $locale->text('Subtotal') . qq|</th>
870 <td align=right>$form->{invsubtotal}</td>
876 if ($form->{taxincluded}) {
877 foreach $item (split / /, $form->{taxaccounts}) {
878 if ($form->{"${item}_base"}) {
879 $form->{"${item}_total"} =
881 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
882 (1 + $form->{"${item}_rate"})
885 $form->{"${item}_netto"} =
887 ($form->{"${item}_base"} - $form->{"${item}_total"}),
889 $form->{"${item}_total"} =
890 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
891 $form->{"${item}_netto"} =
892 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
896 <th align=right>Enthaltene $form->{"${item}_description"} |
897 . $form->{"${item}_rate"} * 100 .qq|%</th>
898 <td align=right>$form->{"${item}_total"}</td>
901 <th align=right>Nettobetrag</th>
902 <td align=right>$form->{"${item}_netto"}</td>
910 $form->{oldinvtotal} = $form->{invtotal};
912 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
922 <th align=left>| . $locale->text('Notes') . qq|</th>
923 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
924 <th align=right>| . $locale->text('Payment Terms') . qq|</th>
929 <td><select name=payment_id onChange="if (this.value) set_duedate(['payment_id__' + this.value],['duedate'])">$payment
934 <td align=right width=100%>
940 <th align=right>| . $locale->text('Total') . qq|</th>
941 <td align=right>$form->{invtotal}</td>
953 <td><hr size=3 noshade></td>
956 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
959 <td align=left width=30%><b>Dateiname</b></td>
960 <td align=left width=70%><b>Webdavlink</b></td>
962 foreach $file (keys %{ $form->{WEBDAV} }) {
965 <td align=left>$file</td>
966 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
977 if ($form->{type} eq "credit_note") {
982 <tr class=listheading>
983 <th colspan=6 class=listheading>|
984 . $locale->text('Payments') . qq|</th>
992 <tr class=listheading>
993 <th colspan=6 class=listheading>|
994 . $locale->text('Incoming Payments') . qq|</th>
999 if ($form->{currency} eq $form->{defaultcurrency}) {
1000 @column_index = qw(datepaid source memo paid AR_paid);
1002 @column_index = qw(datepaid source memo paid exchangerate AR_paid);
1005 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
1006 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
1007 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
1008 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
1009 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
1010 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
1015 map { print "$column_data{$_}\n" } @column_index;
1022 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
1023 for $i (1 .. $form->{paidaccounts}) {
1028 $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
1029 $form->{"selectAR_paid_$i"} =~
1030 s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
1033 $totalpaid += $form->{"paid_$i"};
1034 if ($form->{"paid_$i"}) {
1035 $form->{"paid_$i"} =
1036 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
1038 $form->{"exchangerate_$i"} =
1039 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
1041 $exchangerate = qq| |;
1042 if ($form->{currency} ne $form->{defaultcurrency}) {
1043 if ($form->{"forex_$i"}) {
1045 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
1048 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
1052 $exchangerate .= qq|
1053 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
1056 $column_data{"paid_$i"} =
1057 qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
1058 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
1059 $column_data{"AR_paid_$i"} =
1060 qq|<td align=center><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
1061 $column_data{"datepaid_$i"} =
1062 qq|<td align=center><input id="datepaid_$i" name="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}>
1063 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
1064 $column_data{"source_$i"} =
1065 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
1066 $column_data{"memo_$i"} =
1067 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
1069 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
1072 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
1076 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
1077 <input type=hidden name=selectAR_paid value="$form->{selectAR_paid}">
1078 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
1079 <input type=hidden name=oldtotalpaid value=$totalpaid>
1084 <td><hr size=3 noshade></td>
1098 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1099 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1103 <input class=submit type=submit accesskey="u" name=action id=update_button value="|
1104 . $locale->text('Update') . qq|">
1105 <input class=submit type=submit name=action value="|
1106 . $locale->text('Ship to') . qq|">
1107 <input class=submit type=submit name=action value="|
1108 . $locale->text('Print') . qq|">
1109 <input class=submit type=submit name=action value="|
1110 . $locale->text('E-mail') . qq|">|;
1111 print qq|<input class=submit type=submit name=action value="|
1112 . $locale->text('Storno') . qq|">| unless ($form->{storno});
1113 print qq|<input class=submit type=submit name=action value="|
1114 . $locale->text('Post Payment') . qq|">
1116 print qq|<input class=submit type=submit name=action value="|
1117 . $locale->text('Use As Template') . qq|">
1119 if ($form->{id} && !($form->{type} eq "credit_note")) {
1121 <input class=submit type=submit name=action value="|
1122 . $locale->text('Credit Note') . qq|">
1125 if ($form->{radier}) {
1127 <input class=submit type=submit name=action value="|
1128 . $locale->text('Delete') . qq|">
1133 if ($invdate > $closedto) {
1135 <input class=submit type=submit name=action value="|
1136 . $locale->text('Order') . qq|">
1141 if ($invdate > $closedto) {
1142 print qq|<input class=submit type=submit name=action id=update_button value="|
1143 . $locale->text('Update') . qq|">
1144 <input class=submit type=submit name=action value="|
1145 . $locale->text('Ship to') . qq|">
1146 <input class=submit type=submit name=action value="|
1147 . $locale->text('Preview') . qq|">
1148 <input class=submit type=submit name=action value="|
1149 . $locale->text('E-mail') . qq|">
1150 <input class=submit type=submit name=action value="|
1151 . $locale->text('Print and Post') . qq|">
1152 <input class=submit type=submit name=action value="|
1153 . $locale->text('Post') . qq|">|;
1157 # button for saving history
1158 if($form->{id} ne "") {
1160 <input type=button class=submit onclick=set_history_window(|
1162 . qq|); name=history id=history value=|
1163 . $locale->text('history')
1166 # /button for saving history
1169 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
1172 <input type=hidden name=rowcount value=$form->{rowcount}>
1174 <input name=callback type=hidden value="$form->{callback}">
1176 <input type=hidden name=path value=$form->{path}>
1177 <input type=hidden name=login value=$form->{login}>
1178 <input type=hidden name=password value=$form->{password}>
1187 $lxdebug->leave_sub();
1191 $lxdebug->enter_sub();
1193 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1194 qw(exchangerate creditlimit creditremaining);
1195 if ($form->{second_run}) {
1196 $form->{print_and_post} = 0;
1199 $form->{update} = 1;
1201 &check_name(customer);
1203 $form->{exchangerate} = $exchangerate
1207 $form->check_exchangerate(
1208 \%myconfig, $form->{currency}, $form->{invdate}, 'buy'
1211 for $i (1 .. $form->{paidaccounts}) {
1212 if ($form->{"paid_$i"}) {
1214 $form->{"${_}_$i"} =
1215 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
1216 } qw(paid exchangerate);
1218 $form->{"exchangerate_$i"} = $exchangerate
1220 $form->{"forex_$i"} = (
1222 $form->check_exchangerate(
1223 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'
1228 $i = $form->{rowcount};
1229 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
1231 # if last row empty, check the form otherwise retrieve new item
1232 if ( ($form->{"partnumber_$i"} eq "")
1233 && ($form->{"description_$i"} eq "")
1234 && ($form->{"partsgroup_$i"} eq "")) {
1236 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1241 IS->retrieve_item(\%myconfig, \%$form);
1243 $rows = scalar @{ $form->{item_list} };
1245 $form->{"discount_$i"} =
1246 $form->format_amount(\%myconfig, $form->{discount} * 100);
1249 $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
1258 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1260 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
1261 qw(partnumber description unit);
1262 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
1263 keys %{ $form->{item_list}[0] };
1264 if ($form->{"part_payment_id_$i"} ne "") {
1265 $form->{payment_id} = $form->{"part_payment_id_$i"};
1268 if ($form->{"not_discountable_$i"}) {
1269 $form->{"discount_$i"} = 0;
1272 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
1273 ($dec) = ($s =~ /\.(\d+)/);
1275 $decimalplaces = ($dec > 2) ? $dec : 2;
1278 $form->{"sellprice_$i"} = $sellprice;
1281 # if there is an exchange rate adjust sellprice
1282 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1283 $form->{"sellprice_$i"} /= $exchangerate;
1286 $form->{"listprice_$i"} /= $exchangerate;
1289 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
1290 (1 - $form->{"discount_$i"} / 100);
1291 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
1292 map { $form->{"${_}_base"} += $amount }
1293 (split / /, $form->{"taxaccounts_$i"});
1294 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1295 split / /, $form->{"taxaccounts_$i"}
1296 if !$form->{taxincluded};
1298 $form->{creditremaining} -= $amount;
1301 $form->{"${_}_$i"} =
1302 $form->format_amount(\%myconfig, $form->{"${_}_$i"},
1304 } qw(sellprice listprice);
1307 $form->format_amount(\%myconfig, $form->{"qty_$i"});
1310 if ($form->{"inventory_accno_$i"} ne "") {
1311 $form->{"lizenzen_$i"} = qq|<option></option>|;
1312 foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
1313 $form->{"lizenzen_$i"} .=
1314 qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
1316 $form->{"lizenzen_$i"} .=
1317 qq|<option value=-1>Neue Lizenz</option>|;
1321 # get pricegroups for parts
1322 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1324 # build up html code for prices_$i
1325 &set_pricegroup($i);
1332 # ok, so this is a new part
1333 # ask if it is a part or service item
1335 if ( $form->{"partsgroup_$i"}
1336 && ($form->{"partsnumber_$i"} eq "")
1337 && ($form->{"description_$i"} eq "")) {
1338 $form->{rowcount}--;
1339 $form->{"discount_$i"} = "";
1343 $form->{"id_$i"} = 0;
1344 $form->{"unit_$i"} = $locale->text('ea');
1351 $lxdebug->leave_sub();
1355 $lxdebug->enter_sub();
1356 for $i (1 .. $form->{paidaccounts}) {
1357 if ($form->{"paid_$i"}) {
1358 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1360 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1362 $form->error($locale->text('Cannot post payment for a closed period!'))
1363 if ($datepaid <= $closedto);
1365 if ($form->{currency} ne $form->{defaultcurrency}) {
1366 $form->{"exchangerate_$i"} = $form->{exchangerate}
1367 if ($invdate == $datepaid);
1368 $form->isblank("exchangerate_$i",
1369 $locale->text('Exchangerate for payment missing!'));
1374 ($form->{AR}) = split /--/, $form->{AR};
1375 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1377 $form->redirect($locale->text(' Payment posted!'))
1378 if (IS->post_payment(\%myconfig, \%$form));
1379 $form->error($locale->text('Cannot post payment!'));
1382 $lxdebug->leave_sub();
1386 $lxdebug->enter_sub();
1387 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1388 $form->isblank("customer", $locale->text('Customer missing!'));
1390 # if oldcustomer ne customer redo form
1391 if (&check_name(customer)) {
1395 if ($form->{second_run}) {
1396 $form->{print_and_post} = 0;
1401 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1402 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1404 $form->error($locale->text('Cannot post invoice for a closed period!'))
1405 if ($invdate <= $closedto);
1407 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1408 if ($form->{currency} ne $form->{defaultcurrency});
1410 for $i (1 .. $form->{paidaccounts}) {
1411 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1412 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1414 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1416 $form->error($locale->text('Cannot post payment for a closed period!'))
1417 if ($datepaid <= $closedto);
1419 if ($form->{currency} ne $form->{defaultcurrency}) {
1420 $form->{"exchangerate_$i"} = $form->{exchangerate}
1421 if ($invdate == $datepaid);
1422 $form->isblank("exchangerate_$i",
1423 $locale->text('Exchangerate for payment missing!'));
1428 ($form->{AR}) = split /--/, $form->{AR};
1429 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1431 $form->{label} = $locale->text('Invoice');
1433 $form->{id} = 0 if $form->{postasnew};
1435 # get new invnumber in sequence if no invnumber is given or if posasnew was requested
1436 if (!$form->{invnumber} || $form->{postasnew}) {
1437 if ($form->{type} eq "credit_note") {
1438 $form->{invnumber} = $form->update_defaults(\%myconfig, "cnnumber");
1440 $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber");
1445 if (!(IS->post_invoice(\%myconfig, \%$form))) {
1446 $form->error($locale->text('Cannot post invoice!'));
1448 # saving the history
1449 if(!exists $form->{addition}) {
1450 $form->{addition} = "PRINTED AND POSTED";
1451 $form->save_history($form->dbconnect(\%myconfig));
1453 # /saving the history
1456 if (IS->post_invoice(\%myconfig, \%$form)){
1457 # saving the history
1458 if(!exists $form->{addition}) {
1459 if($form->{storno}) {
1460 $form->{addition} = "STORNO";
1463 $form->{addition} = "POSTED";
1465 $form->save_history($form->dbconnect(\%myconfig));
1467 # /saving the history
1470 $form->{label} . " $form->{invnumber} " . $locale->text('posted!'));
1472 $form->error($locale->text('Cannot post invoice!'));
1475 $lxdebug->leave_sub();
1478 sub print_and_post {
1479 $lxdebug->enter_sub();
1481 $old_form = new Form;
1483 $form->{print_and_post} = 1;
1487 $lxdebug->leave_sub();
1491 sub use_as_template {
1492 $lxdebug->enter_sub();
1494 map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno);
1495 $form->{paidaccounts} = 1;
1496 $form->{rowcount}--;
1497 $form->{invdate} = $form->current_date(\%myconfig);
1500 $lxdebug->leave_sub();
1504 $lxdebug->enter_sub();
1506 if ($form->{storno}) {
1507 $form->error($locale->text('Cannot storno storno invoice!'));
1510 $form->{storno_id} = $form->{id};
1511 $form->{storno} = 1;
1513 $form->{invnumber} = "Storno zu " . $form->{invnumber};
1516 $lxdebug->leave_sub();
1521 $lxdebug->enter_sub();
1523 $form->{preview} = 1;
1524 $old_form = new Form;
1525 for (keys %$form) { $old_form->{$_} = $form->{$_} }
1526 $old_form->{rowcount}++;
1528 &print_form($old_form);
1529 $lxdebug->leave_sub();
1534 $lxdebug->enter_sub();
1535 if ($form->{second_run}) {
1536 $form->{print_and_post} = 0;
1543 <form method=post action=$form->{script}>
1546 # delete action variable
1547 map { delete $form->{$_} } qw(action header);
1549 foreach $key (keys %$form) {
1550 $form->{$key} =~ s/\"/"/g;
1551 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1555 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1558 . $locale->text('Are you sure you want to delete Invoice Number')
1559 . qq| $form->{invnumber}
1563 <input name=action class=submit type=submit value="|
1564 . $locale->text('Yes') . qq|">
1568 $lxdebug->leave_sub();
1572 $lxdebug->enter_sub();
1574 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
1576 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
1579 $form->{rowcount}--;
1580 $form->{shipto} = 1;
1583 $form->{title} = $locale->text('Add Credit Note');
1584 $form->{script} = 'is.pl';
1589 # bo creates the id, reset it
1590 map { delete $form->{$_} }
1591 qw(id invnumber subject message cc bcc printed emailed queued);
1592 $form->{ $form->{vc} } =~ s/--.*//g;
1593 $form->{type} = "credit_note";
1596 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1598 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1599 qw(creditlimit creditremaining);
1601 $currency = $form->{currency};
1604 $form->{currency} = $currency;
1605 $form->{exchangerate} = "";
1606 $form->{forex} = "";
1607 $form->{exchangerate} = $exchangerate
1611 $form->check_exchangerate(
1612 \%myconfig, $form->{currency}, $form->{invdate}, $buysell
1615 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
1622 $lxdebug->leave_sub();
1626 $lxdebug->enter_sub();
1627 if (IS->delete_invoice(\%myconfig, \%$form, $spool)) {
1628 # saving the history
1629 if(!exists $form->{addition}) {
1630 $form->{addition} = "DELETED";
1631 $form->save_history($form->dbconnect(\%myconfig));
1633 # /saving the history
1634 $form->redirect($locale->text('Invoice deleted!'));
1636 $form->error($locale->text('Cannot delete invoice!'));
1638 $lxdebug->leave_sub();