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 received module
32 #======================================================================
38 require "bin/mozilla/io.pl";
39 require "bin/mozilla/arap.pl";
40 require "bin/mozilla/common.pl";
41 require "bin/mozilla/drafts.pl";
48 $lxdebug->enter_sub();
50 return $lxdebug->leave_sub() if (load_draft_maybe());
52 $form->{title} = $locale->text('Add Vendor Invoice');
58 $lxdebug->leave_sub();
62 $lxdebug->enter_sub();
65 $form->{javascript} = qq|<script type=text/javascript src=js/show_history.js></script>|;
66 #/show hhistory button
68 $form->{title} = $locale->text('Edit Vendor Invoice');
74 $lxdebug->leave_sub();
78 $lxdebug->enter_sub();
81 $form->{webdav} = $webdav;
84 $form->{jscalendar} = $jscalendar;
86 $form->create_links("AP", \%myconfig, "vendor");
88 #quote all_vendor Bug 133
89 foreach $ref (@{ $form->{all_vendor} }) {
90 $ref->{name} = $form->quote($ref->{name});
93 if ($form->{all_vendor}) {
94 unless ($form->{vendor_id}) {
95 $form->{vendor_id} = $form->{all_vendor}->[0]->{id};
98 if ($form->{payment_id}) {
99 $payment_id = $form->{payment_id};
101 if ($form->{language_id}) {
102 $language_id = $form->{language_id};
104 if ($form->{taxzone_id}) {
105 $taxzone_id = $form->{taxzone_id};
108 $cp_id = $form->{cp_id};
109 IR->get_vendor(\%myconfig, \%$form);
110 IR->retrieve_invoice(\%myconfig, \%$form);
111 $form->{cp_id} = $cp_id;
114 $form->{payment_id} = $payment_id;
117 $form->{language_id} = $language_id;
120 $form->{taxzone_id} = $taxzone_id;
123 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
125 $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
128 if (@{ $form->{all_vendor} }) {
129 $form->{vendor} = "$form->{vendor}--$form->{vendor_id}";
130 map { $form->{selectvendor} .= "<option>$_->{name}--$_->{id}\n" }
131 (@{ $form->{all_vendor} });
135 if ($form->{all_departments}) {
136 $form->{selectdepartment} = "<option>\n";
137 $form->{department} = "$form->{department}--$form->{department_id}";
140 $form->{selectdepartment} .=
141 "<option>$_->{description}--$_->{id}\n"
142 } (@{ $form->{all_departments} });
146 $form->{forex} = $form->{exchangerate};
147 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
149 foreach $key (keys %{ $form->{AP_links} }) {
151 foreach $ref (@{ $form->{AP_links}{$key} }) {
152 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
155 if ($key eq "AP_paid") {
156 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
157 $form->{"AP_paid_$i"} =
158 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
161 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount};
162 $form->{"datepaid_$i"} =
163 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
164 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
165 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
166 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
167 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
169 $form->{paidaccounts} = $i;
173 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
178 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
180 $form->{AP} = $form->{AP_1} unless $form->{id};
183 ($form->datetonum($form->{invdate}, \%myconfig) <=
184 $form->datetonum($form->{closedto}, \%myconfig));
186 $lxdebug->leave_sub();
189 sub prepare_invoice {
190 $lxdebug->enter_sub();
194 map { $form->{$_} =~ s/\"/"/g } qw(invnumber ordnumber quonumber);
197 foreach $ref (@{ $form->{invoice_details} }) {
199 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
201 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
203 $decimalplaces = ($dec > 2) ? $dec : 2;
205 $form->{"sellprice_$i"} =
206 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
209 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
210 $dec_qty = length $dec_qty;
213 $form->format_amount(\%myconfig, ($form->{"qty_$i"} * -1), $dec_qty);
215 $form->{rowcount} = $i;
219 $lxdebug->leave_sub();
223 $lxdebug->enter_sub();
225 # set option selected
226 foreach $item (qw(AP vendor currency department employee)) {
227 $form->{"select$item"} =~ s/ selected//;
228 $form->{"select$item"} =~
229 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
233 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
235 #quote selectvendor Bug 133
236 $form->{"selectvendor"} = $form->quote($form->{"selectvendor"});
238 #substitute \n and \r to \s (bug 543)
239 $form->{"selectvendor"} =~ s/[\n\r]/ /g;
241 $form->{exchangerate} =
242 $form->format_amount(\%myconfig, $form->{exchangerate});
244 $form->{creditlimit} =
245 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
246 $form->{creditremaining} =
247 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
250 if ($form->{currency} ne $form->{defaultcurrency}) {
251 if ($form->{forex}) {
253 <th align=right nowrap>|
254 . $locale->text('Exchangerate') . qq|</th>
255 <td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>
259 <th align=right nowrap>|
260 . $locale->text('Exchangerate') . qq|</th>
261 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
266 <input type=hidden name=forex value=$form->{forex}>
269 my @old_project_ids = ($form->{"globalproject_id"});
270 map({ push(@old_project_ids, $form->{"project_id_$_"})
271 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
273 $form->get_lists("contacts" => "ALL_CONTACTS",
274 "projects" => { "key" => "ALL_PROJECTS",
276 "old_id" => \@old_project_ids },
277 "taxzones" => "ALL_TAXZONES",
278 "employees" => "ALL_SALESMEN",
279 "currencies" => "ALL_CURRENCIES");
282 my @values = (undef);
283 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
284 push(@values, $item->{"cp_id"});
285 $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
286 ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
289 NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
290 '-labels' => \%labels, '-default' => $form->{"cp_id"}));
294 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
295 push(@values, $item->{"id"});
296 $labels{$item->{"id"}} = $item->{"projectnumber"};
298 my $globalprojectnumber =
299 NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
300 '-labels' => \%labels,
301 '-default' => $form->{"globalproject_id"}));
306 foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
307 push(@values, $item);
308 $labels{$item} = $item;
311 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
314 <th align="right">| . $locale->text('Currency') . qq|</th>
316 NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
317 '-values' => \@values, '-labels' => \%labels)) . qq|
325 foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
326 push(@values, $item->{"id"});
327 $labels{$item->{"id"}} = $item->{"name"};
331 <th align="right">| . $locale->text('Employee') . qq|</th>
333 NTI($cgi->popup_menu('-name' => 'employee', '-default' => $form->{"employee"},
334 '-values' => \@values, '-labels' => \%labels)) . qq|
340 foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
341 push(@values, $item->{"id"});
342 $labels{$item->{"id"}} = $item->{"description"};
345 if (!$form->{"id"}) {
348 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
350 NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
351 '-values' => \@values, '-labels' => \%labels)) . qq|
358 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
360 <input type="hidden" name="taxzone_id" value="| . H($form->{"taxzone_id"}) . qq|">
361 | . H($labels{$form->{"taxzone_id"}}) . qq|
367 ($form->{selectvendor})
368 ? qq|<select name="vendor"
369 onchange="document.getElementById('update_button').click();">| .
370 qq|$form->{selectvendor}</select>\n<input type="hidden" name="selectvendor" value="| .
371 Q($form->{selectvendor}) . qq|">|
372 : qq|<input name="vendor" value="$form->{vendor}" size="35">|;
376 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
377 <td colspan="3"><select name="department">$form->{selectdepartment}</select>
378 <input type="hidden" name="selectdepartment" value="$form->{selectdepartment}">
381 | if $form->{selectdepartment};
383 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
385 # use JavaScript Calendar or not
386 $form->{jsscript} = $form->{jscalendar};
388 if ($form->{jsscript}) {
390 # with JavaScript Calendar
392 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\"></td>
393 <td><input type=button name=invdate id="trigger1" value=|
394 . $locale->text('button') . qq|></td>
397 <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"></td>
398 <td width="4"><input type=button name=duedate id="trigger2" value=|
399 . $locale->text('button') . qq|></td></td>
404 Form->write_trigger(\%myconfig, "2", "invdate", "BL", "trigger1",
405 "duedate", "BL", "trigger2");
408 # without JavaScript Calendar
410 qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\"></td>|;
412 qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"></td>|;
415 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
416 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
419 $form->write_trigger(\%myconfig, 2,
420 "orddate", "BL", "trigger_orddate",
421 "quodate", "BL", "trigger_quodate");
424 $onload = qq|focus()|;
425 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
426 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
428 <body onLoad="$onload">
430 <form method=post action=$form->{script}>
432 <input type=hidden name=id value=$form->{id}>
433 <input type=hidden name=title value="$form->{title}">
434 <input type=hidden name=vc value="vendor">
435 <input type=hidden name=type value=$form->{type}>
436 <input type=hidden name=level value=$form->{level}>
438 <input type=hidden name=creditlimit value=$form->{creditlimit}>
439 <input type=hidden name=creditremaining value=$form->{creditremaining}>
441 <input type=hidden name=closedto value=$form->{closedto}>
442 <input type=hidden name=locked value=$form->{locked}>
444 <input type=hidden name=shipped value=$form->{shipped}>
445 <input type=hidden name=storno value=$form->{storno}>
446 <input type=hidden name=storno_id value=$form->{storno_id}>
448 | . ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") . qq|
452 <th class=listtop>$form->{title}</th>
462 <th align=right nowrap>| . $locale->text('Vendor') . qq|</th>
463 <td colspan=3>$vendor</td>
465 <th align=richt nowrap>|
466 . $locale->text('Contact Person') . qq|</th>
467 <td colspan=3>$contact</td>
469 <input type=hidden name=vendor_id value=$form->{vendor_id}>
470 <input type=hidden name=oldvendor value="$form->{oldvendor}">
477 <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
478 <td>$form->{creditlimit}</td>
480 <th nowrap>| . $locale->text('Remaining') . qq|</th>
481 <td class="plus$n">$form->{creditremaining}</td>
486 <th align="right">| . $locale->text('Record in') . qq|</th>
487 <td colspan="3"><select name="AP">$form->{selectAP}</select></td>
488 <input type="hidden" name="selectAP" value="$form->{selectAP}">
502 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
503 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
506 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
510 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
514 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
515 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
516 <input type=hidden name=quonumber value="$form->{quonumber}">
519 <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
520 <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|" onBlur=\"check_right_date_format(this)\"></td>
521 <td><input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
524 <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
525 <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|" onBlur=\"check_right_date_format(this)\"></td>
526 <td><input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
529 <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
530 <td>$globalprojectnumber</td>
541 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
542 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
543 <input type=hidden name=webdav value=$webdav>
545 <input type=hidden name=taxpart value="$form->{taxpart}">
546 <input type=hidden name=taxservice value="$form->{taxservice}">
548 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
551 foreach $item (split / /, $form->{taxaccounts}) {
553 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
554 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
558 $lxdebug->leave_sub();
562 $lxdebug->enter_sub();
564 $form->{invtotal} = $form->{invsubtotal};
566 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
569 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
572 $rows = ($rows > $introws) ? $rows : $introws;
574 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
576 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
578 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
581 if ($form->{taxaccounts}) {
583 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
584 . $locale->text('Tax Included') . qq|</b>
588 if (!$form->{taxincluded}) {
590 foreach $item (split / /, $form->{taxaccounts}) {
591 if ($form->{"${item}_base"}) {
592 $form->{invtotal} += $form->{"${item}_total"} =
594 $form->{"${item}_base"} * $form->{"${item}_rate"},
596 $form->{"${item}_total"} =
597 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
601 <th align=right>$form->{"${item}_description"} |
602 . $form->{"${item}_rate"} * 100 .qq|%</th>
603 <td align=right>$form->{"${item}_total"}</td>
609 $form->{invsubtotal} =
610 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
614 <th align=right>| . $locale->text('Subtotal') . qq|</th>
615 <td align=right>$form->{invsubtotal}</td>
621 if ($form->{taxincluded}) {
622 foreach $item (split / /, $form->{taxaccounts}) {
623 if ($form->{"${item}_base"}) {
624 $form->{"${item}_total"} =
626 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
627 (1 + $form->{"${item}_rate"})
630 $form->{"${item}_base"} =
631 $form->round_amount($form->{"${item}_base"}, 2);
632 $form->{"${item}_netto"} =
634 ($form->{"${item}_base"} - $form->{"${item}_total"}),
636 $form->{"${item}_netto"} =
637 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
638 $form->{"${item}_total"} =
639 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
643 <th align=right>Enthaltene $form->{"${item}_description"} |
644 . $form->{"${item}_rate"} * 100 .qq|%</th>
645 <td align=right>$form->{"${item}_total"}</td>
648 <th align=right>Nettobetrag</th>
649 <td align=right>$form->{"${item}_netto"}</td>
657 $form->{oldinvtotal} = $form->{invtotal};
659 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
663 <td colspan=$colspan>
664 <table cellspacing="0">
669 <th align=left>| . $locale->text('Notes') . qq|</th>
670 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
678 <td colspan=2 align=right width=100%>
685 <th align=right>| . $locale->text('Total') . qq|</th>
686 <td align=right>$form->{invtotal}</td>
698 <td><hr size=3 noshade></td>
701 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
704 <td align=left width=30%><b>Dateiname</b></td>
705 <td align=left width=70%><b>Webdavlink</b></td>
707 foreach $file (keys %{ $form->{WEBDAV} }) {
710 <td align=left>$file</td>
711 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
723 <input type=hidden name=jscalendar value=$form->{jscalendar}>
727 <td colspan=$colspan>
730 <th colspan=6 class=listheading>| . $locale->text('Payments') . qq|</th>
734 if ($form->{currency} eq $form->{defaultcurrency}) {
735 @column_index = qw(datepaid source memo paid AP_paid);
737 @column_index = qw(datepaid source memo paid exchangerate AP_paid);
740 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
741 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
742 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
743 $column_data{AP_paid} = "<th>" . $locale->text('Account') . "</th>";
744 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
745 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
750 map { print "$column_data{$_}\n" } @column_index;
756 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
757 for $i (1 .. $form->{paidaccounts}) {
763 $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
764 $form->{"selectAP_paid_$i"} =~
765 s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
768 if ($form->{"paid_$i"}) {
770 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
772 $form->{"exchangerate_$i"} =
773 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
775 $exchangerate = qq| |;
776 if ($form->{currency} ne $form->{defaultcurrency}) {
777 if ($form->{"forex_$i"}) {
779 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
782 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
786 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
789 $column_data{"paid_$i"} =
790 qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
791 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
792 $column_data{"AP_paid_$i"} =
793 qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;
794 $column_data{"datepaid_$i"} =
795 qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 title="$myconfig{dateformat}" value="$form->{"datepaid_$i"}" onBlur=\"check_right_date_format(this)\">
796 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
797 $column_data{"source_$i"} =
798 qq|<td align=center><input name="source_$i" size=11 value=$form->{"source_$i"}></td>|;
799 $column_data{"memo_$i"} =
800 qq|<td align=center><input name="memo_$i" size=11 value=$form->{"memo_$i"}></td>|;
802 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
807 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
811 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
812 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
813 <input type=hidden name=selectAP_paid value="$form->{selectAP_paid}">
818 <td><hr size=3 noshade></td>
824 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
825 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
828 my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ap");
830 print qq|<input class=submit type=submit name=action value="|
831 . $locale->text('Post Payment') . qq|">
833 print qq|<input class=submit type=submit name=action value="|
834 . $locale->text('Storno') . qq|">
836 if ($form->{radier}) {
838 <input class=submit type=submit name=action value="|
839 . $locale->text('Delete') . qq|">
842 print qq|<input class=submit type=submit name=action value="|
843 . $locale->text('Use As Template') . qq|">
848 print qq|<input class=submit type=submit name=action id=update_button value="|
849 . $locale->text('Update') . qq|">|;
851 if (!$form->{id} && ($invdate > $closedto)) {
852 print qq| <input class=submit type=submit name=action value="|
853 . $locale->text('Post') . qq|"> | .
854 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
855 '-class' => 'submit'));
858 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers);
859 $form->hide_form(qw(rowcount callback draft_id draft_description login password));
861 # button for saving history
862 if($form->{id} ne "") {
864 <input type="button" class="submit" onclick="set_history_window(|
866 . qq|);" name="history" id="history" value="|
867 . $locale->text('history')
870 # /button for saving history
878 $lxdebug->leave_sub();
882 $lxdebug->enter_sub();
884 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
885 qw(exchangerate creditlimit creditremaining);
889 $form->{exchangerate} = $exchangerate
893 $form->check_exchangerate(
894 \%myconfig, $form->{currency}, $form->{invdate}, 'sell'
897 for $i (1 .. $form->{paidaccounts}) {
898 if ($form->{"paid_$i"}) {
901 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
902 } qw(paid exchangerate);
904 $form->{"exchangerate_$i"} = $exchangerate
906 $form->{"forex_$i"} = (
908 $form->check_exchangerate(
909 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell'
914 $i = $form->{rowcount};
915 $exchangerate = ($form->{exchangerate} * 1) ? $form->{exchangerate} * 1 : 1;
917 if ( ($form->{"partnumber_$i"} eq "")
918 && ($form->{"description_$i"} eq "")
919 && ($form->{"partsgroup_$i"} eq "")) {
920 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
925 IR->retrieve_item(\%myconfig, \%$form);
927 my $rows = scalar @{ $form->{item_list} };
930 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
939 # override sellprice if there is one entered
940 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
942 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
943 qw(partnumber description unit);
945 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
946 keys %{ $form->{item_list}[0] };
948 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
950 ($dec) = ($s =~ /\.(\d+)/);
952 $decimalplaces = ($dec > 2) ? $dec : 2;
955 $form->{"sellprice_$i"} = $sellprice;
958 # if there is an exchange rate adjust sellprice
959 $form->{"sellprice_$i"} /= $exchangerate;
963 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
964 (1 - $form->{"discount_$i"} / 100);
965 $form->{creditremaining} -= $amount;
966 $form->{"sellprice_$i"} =
967 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
970 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
977 # ok, so this is a new part
978 # ask if it is a part or service item
980 if ( $form->{"partsgroup_$i"}
981 && ($form->{"partsnumber_$i"} eq "")
982 && ($form->{"description_$i"} eq "")) {
984 $form->{"discount_$i"} = "";
988 $form->{"id_$i"} = 0;
989 $form->{"unit_$i"} = $locale->text('ea');
996 $lxdebug->leave_sub();
1000 $lxdebug->enter_sub();
1002 if ($form->{storno}) {
1003 $form->error($locale->text('Cannot storno storno invoice!'));
1006 if (IS->has_storno(\%myconfig, $form, "ap")) {
1007 $form->error($locale->text("Invoice has already been storno'd!"));
1014 # saving the history
1015 if(!exists $form->{addition} && $form->{id} ne "") {
1016 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1017 $form->{addition} = "CANCELED";
1018 $form->save_history($form->dbconnect(\%myconfig));
1020 # /saving the history
1022 $form->{storno_id} = $form->{id};
1023 $form->{storno} = 1;
1025 $form->{invnumber} = "Storno zu " . $form->{invnumber};
1026 $form->{rowcount}++;
1028 $lxdebug->leave_sub();
1032 sub use_as_template {
1033 $lxdebug->enter_sub();
1035 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);
1036 $form->{paidaccounts} = 1;
1037 $form->{rowcount}--;
1038 $form->{invdate} = $form->current_date(\%myconfig);
1041 $lxdebug->leave_sub();
1045 $lxdebug->enter_sub();
1046 for $i (1 .. $form->{paidaccounts}) {
1047 if ($form->{"paid_$i"}) {
1048 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1050 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1052 $form->error($locale->text('Cannot post payment for a closed period!'))
1053 if ($datepaid <= $closedto);
1055 if ($form->{currency} ne $form->{defaultcurrency}) {
1056 $form->{"exchangerate_$i"} = $form->{exchangerate}
1057 if ($invdate == $datepaid);
1058 $form->isblank("exchangerate_$i",
1059 $locale->text('Exchangerate for payment missing!'));
1064 ($form->{AP}) = split /--/, $form->{AP};
1065 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1066 if (IR->post_payment(\%myconfig, \%$form)){
1068 if(!exists $form->{addition} && $form->{id} ne "") {
1069 # saving the history
1070 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1071 $form->{addition} = "PAYMENT POSTED";
1072 $form->{what_done} = $form->{currency} . qq| | . $form->{paid} . qq| | . $locale->text("POSTED");
1073 $form->save_history($form->dbconnect(\%myconfig));
1074 # /saving the history
1075 $form->redirect($locale->text(' Payment posted!'));
1078 $form->error($locale->text('Cannot post payment!'));
1081 $lxdebug->leave_sub();
1085 $lxdebug->enter_sub();
1087 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1088 $form->isblank("vendor", $locale->text('Vendor missing!'));
1090 # if the vendor changed get new values
1091 if (&check_name(vendor)) {
1098 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1099 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1101 $form->error($locale->text('Cannot post invoice for a closed period!'))
1102 if ($invdate <= $closedto);
1104 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1105 if ($form->{currency} ne $form->{defaultcurrency});
1107 for $i (1 .. $form->{paidaccounts}) {
1108 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1109 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1111 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1113 $form->error($locale->text('Cannot post payment for a closed period!'))
1114 if ($datepaid <= $closedto);
1116 if ($form->{currency} ne $form->{defaultcurrency}) {
1117 $form->{"exchangerate_$i"} = $form->{exchangerate}
1118 if ($invdate == $datepaid);
1119 $form->isblank("exchangerate_$i",
1120 $locale->text('Exchangerate for payment missing!'));
1125 ($form->{AP}) = split /--/, $form->{AP};
1126 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1128 $form->{id} = 0 if $form->{postasnew};
1132 if (IR->post_invoice(\%myconfig, \%$form)){
1133 # saving the history
1134 if(!exists $form->{addition} && $form->{id} ne "") {
1135 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1136 $form->{addition} = "POSTED";
1137 #$form->{what_done} = $locale->text("Rechnungsnummer") . qq| | . $form->{invnumber};
1138 $form->save_history($form->dbconnect(\%myconfig));
1140 # /saving the history
1141 remove_draft() if $form->{remove_draft};
1142 $form->redirect( $locale->text('Invoice')
1143 . " $form->{invnumber} "
1144 . $locale->text('posted!'));
1146 $form->error($locale->text('Cannot post invoice!'));
1148 $lxdebug->leave_sub();
1152 $lxdebug->enter_sub();
1158 <form method=post action=$form->{script}>
1161 # delete action variable
1162 map { delete $form->{$_} } qw(action header);
1164 foreach $key (keys %$form) {
1165 $form->{$key} =~ s/\"/"/g;
1166 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1170 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1173 . $locale->text('Are you sure you want to delete Invoice Number')
1174 . qq| $form->{invnumber}</h4>
1176 <input name=action class=submit type=submit value="|
1177 . $locale->text('Yes') . qq|">
1181 $lxdebug->leave_sub();
1185 $lxdebug->enter_sub();
1186 if (IR->delete_invoice(\%myconfig, \%$form)) {
1187 # saving the history
1188 if(!exists $form->{addition}) {
1189 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1190 $form->{addition} = "DELETED";
1191 $form->save_history($form->dbconnect(\%myconfig));
1193 # /saving the history
1194 $form->redirect($locale->text('Invoice deleted!'));
1196 $form->error($locale->text('Cannot delete invoice!'));
1198 $lxdebug->leave_sub();