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();
49 $form->{"Watchdog::invdate,duedate,vendor,vendor_id"} = 1;
51 return $lxdebug->leave_sub() if (load_draft_maybe());
53 $form->{title} = $locale->text('Add Vendor Invoice');
59 $lxdebug->leave_sub();
63 $lxdebug->enter_sub();
66 $form->{javascript} = qq|<script type=text/javascript src=js/show_history.js></script>|;
67 #/show hhistory button
69 $form->{title} = $locale->text('Edit Vendor Invoice');
75 $lxdebug->leave_sub();
79 $lxdebug->enter_sub();
82 $form->{webdav} = $webdav;
83 $form->{jsscript} = 1;
85 $form->create_links("AP", \%myconfig, "vendor");
87 #quote all_vendor Bug 133
88 foreach $ref (@{ $form->{all_vendor} }) {
89 $ref->{name} = $form->quote($ref->{name});
92 if ($form->{all_vendor}) {
93 unless ($form->{vendor_id}) {
94 $form->{vendor_id} = $form->{all_vendor}->[0]->{id};
97 if ($form->{payment_id}) {
98 $payment_id = $form->{payment_id};
100 if ($form->{language_id}) {
101 $language_id = $form->{language_id};
103 if ($form->{taxzone_id}) {
104 $taxzone_id = $form->{taxzone_id};
107 $cp_id = $form->{cp_id};
108 IR->get_vendor(\%myconfig, \%$form);
109 IR->retrieve_invoice(\%myconfig, \%$form);
110 $form->{cp_id} = $cp_id;
113 $form->{payment_id} = $payment_id;
116 $form->{language_id} = $language_id;
119 $form->{taxzone_id} = $taxzone_id;
122 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
124 $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
127 if ($form->{all_departments}) {
128 $form->{selectdepartment} = "<option>\n";
129 $form->{department} = "$form->{department}--$form->{department_id}";
132 $form->{selectdepartment} .=
133 "<option>$_->{description}--$_->{id}\n"
134 } (@{ $form->{all_departments} });
138 $form->{forex} = $form->{exchangerate};
139 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
141 foreach $key (keys %{ $form->{AP_links} }) {
143 foreach $ref (@{ $form->{AP_links}{$key} }) {
144 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
147 if ($key eq "AP_paid") {
148 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
149 $form->{"AP_paid_$i"} =
150 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
153 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount};
154 $form->{"datepaid_$i"} =
155 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
156 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
157 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
158 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
159 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
161 $form->{paidaccounts} = $i;
165 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
170 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
172 $form->{AP} = $form->{AP_1} unless $form->{id};
175 ($form->datetonum($form->{invdate}, \%myconfig) <=
176 $form->datetonum($form->{closedto}, \%myconfig));
178 $lxdebug->leave_sub();
181 sub prepare_invoice {
182 $lxdebug->enter_sub();
186 map { $form->{$_} =~ s/\"/"/g } qw(invnumber ordnumber quonumber);
189 foreach $ref (@{ $form->{invoice_details} }) {
191 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
193 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
195 $decimalplaces = ($dec > 2) ? $dec : 2;
197 $form->{"sellprice_$i"} =
198 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
201 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
202 $dec_qty = length $dec_qty;
205 $form->format_amount(\%myconfig, ($form->{"qty_$i"} * -1), $dec_qty);
207 $form->{rowcount} = $i;
211 $lxdebug->leave_sub();
215 $lxdebug->enter_sub();
217 # set option selected
218 foreach $item (qw(AP vendor currency department)) {
219 $form->{"select$item"} =~ s/ selected//;
220 $form->{"select$item"} =~
221 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
224 if ($form->{old_employee_id}) {
225 $form->{employee_id} = $form->{old_employee_id};
227 if ($form->{old_salesman_id}) {
228 $form->{salesman_id} = $form->{old_salesman_id};
231 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
235 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
237 $form->{exchangerate} =
238 $form->format_amount(\%myconfig, $form->{exchangerate});
240 $form->{creditlimit} =
241 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
242 $form->{creditremaining} =
243 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
246 if ($form->{currency} ne $form->{defaultcurrency}) {
247 if ($form->{forex}) {
249 <th align=right nowrap>|
250 . $locale->text('Exchangerate') . qq|</th>
251 <td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>
255 <th align=right nowrap>|
256 . $locale->text('Exchangerate') . qq|</th>
257 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
262 <input type=hidden name=forex value=$form->{forex}>
265 my @old_project_ids = ($form->{"globalproject_id"});
266 map({ push(@old_project_ids, $form->{"project_id_$_"})
267 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
269 $form->get_lists("contacts" => "ALL_CONTACTS",
270 "projects" => { "key" => "ALL_PROJECTS",
272 "old_id" => \@old_project_ids },
273 "taxzones" => "ALL_TAXZONES",
274 "employees" => "ALL_SALESMEN",
275 "currencies" => "ALL_CURRENCIES",
276 "vendors" => "ALL_VENDORS");
279 my @values = (undef);
280 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
281 push(@values, $item->{"cp_id"});
282 $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
283 ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
287 if (scalar @values > 1) {
290 <th align="right">| . $locale->text('Contact Person') . qq|</th>
292 NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
293 '-labels' => \%labels, '-default' => $form->{"cp_id"}))
301 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
302 push(@values, $item->{"id"});
303 $labels{$item->{"id"}} = $item->{"projectnumber"};
305 my $globalprojectnumber =
306 NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
307 '-labels' => \%labels,
308 '-default' => $form->{"globalproject_id"}));
313 foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
314 push(@values, $item);
315 $labels{$item} = $item;
318 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
320 if (scalar @values) {
323 <th align="right">| . $locale->text('Currency') . qq|</th>
325 NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
326 '-values' => \@values, '-labels' => \%labels)) . qq|
334 foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
335 push(@values, $item->{"id"});
336 $labels{$item->{"id"}} = $item->{"name"};
340 <th align="right">| . $locale->text('Employee') . qq|</th>
342 NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
343 '-values' => \@values, '-labels' => \%labels)) . qq|
350 foreach my $item (@{ $form->{"ALL_VENDORS"} }) {
351 push(@values, $item->{name}.qq|--|.$item->{"id"});
352 $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
355 $form->{selectvendor} = ($myconfig{vclimit} > scalar(@values));
358 <th align="right">| . $locale->text('Vendor') . qq|</th>
360 (($myconfig{vclimit} <= scalar(@values))
361 ? qq|<input type="text" value="| . H($form->{vendor}) . qq|" name="vendor">|
362 : (NTI($cgi->popup_menu('-name' => 'vendor', '-default' => $form->{oldvendor},
363 '-onChange' => 'document.getElementById(\'update_button\').click();',
364 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq|
365 <input type="button" value="?" onclick="show_vc_details('vendor')">
370 foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
371 push(@values, $item->{"id"});
372 $labels{$item->{"id"}} = $item->{"description"};
375 if (!$form->{"id"}) {
378 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
380 NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
381 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')) . qq|
388 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
390 <input type="hidden" name="taxzone_id" value="| . H($form->{"taxzone_id"}) . qq|">
391 | . H($labels{$form->{"taxzone_id"}}) . qq|
398 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
399 <td colspan="3"><select name="department" style="width: 250px">$form->{selectdepartment}</select>
400 <input type="hidden" name="selectdepartment" value="$form->{selectdepartment}">
403 | if $form->{selectdepartment};
405 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
407 # use JavaScript Calendar or not
408 $form->{jsscript} = 1;
412 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
413 <input type=button name=invdate id="trigger1" value=|
414 . $locale->text('button') . qq|></td>
417 <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\">
418 <input type=button name=duedate id="trigger2" value=|
419 . $locale->text('button') . qq|></td></td>
424 Form->write_trigger(\%myconfig, "2", "invdate", "BL", "trigger1",
425 "duedate", "BL", "trigger2");
427 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
428 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
429 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
432 $form->write_trigger(\%myconfig, 2,
433 "orddate", "BL", "trigger_orddate",
434 "quodate", "BL", "trigger_quodate");
437 $onload = qq|focus()|;
438 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
439 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
441 <body onLoad="$onload">
443 <form method=post action=$form->{script}>
446 $form->hide_form(qw(id title vc type level creditlimit creditremaining
447 closedto locked shippted storno storno_id
448 max_dunning_level dunning_amount));
450 print qq|<p>$form->{saved_message}</p>| if $form->{saved_message};
454 <div class="listtop" width="100%">$form->{title}</div>
461 <input type="hidden" name="vendor_id" value="$form->{vendor_id}">
462 <input type="hidden" name="oldvendor" value="$form->{oldvendor}">
463 <input type="hidden" name="selectvendor" value= "$form->{selectvendor}">
466 <td align="right">| . $locale->text('Credit Limit') . qq|</td>
467 <td>$form->{creditlimit}; | . $locale->text('Remaining') . qq| <span class="plus$n">$form->{creditremaining}</span></td>
470 <th align="right">| . $locale->text('Record in') . qq|</th>
471 <td colspan="3"><select name="AP" style="width: 250px">$form->{selectAP}</select></td>
472 <input type="hidden" name="selectAP" value="$form->{selectAP}">
486 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
487 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
490 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
494 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
498 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
499 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
500 <input type=hidden name=quonumber value="$form->{quonumber}">
503 <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
504 <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|" onBlur=\"check_right_date_format(this)\">
505 <input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
508 <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
509 <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|" onBlur=\"check_right_date_format(this)\">
510 <input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
513 <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
514 <td>$globalprojectnumber</td>
525 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
526 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
527 <input type=hidden name=webdav value=$webdav>
529 <input type=hidden name=taxpart value="$form->{taxpart}">
530 <input type=hidden name=taxservice value="$form->{taxservice}">
532 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
535 foreach $item (split / /, $form->{taxaccounts}) {
537 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
538 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
542 $lxdebug->leave_sub();
546 $lxdebug->enter_sub();
548 $form->{invtotal} = $form->{invsubtotal};
550 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
553 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
556 $rows = ($rows > $introws) ? $rows : $introws;
558 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
560 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
562 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
565 if ($form->{taxaccounts}) {
567 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
568 . $locale->text('Tax Included') . qq|</b>
572 if (!$form->{taxincluded}) {
574 foreach $item (split / /, $form->{taxaccounts}) {
575 if ($form->{"${item}_base"}) {
576 $form->{invtotal} += $form->{"${item}_total"} =
578 $form->{"${item}_base"} * $form->{"${item}_rate"},
580 $form->{"${item}_total"} =
581 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
585 <th align=right>$form->{"${item}_description"} |
586 . $form->{"${item}_rate"} * 100 .qq|%</th>
587 <td align=right>$form->{"${item}_total"}</td>
593 $form->{invsubtotal} =
594 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
598 <th align=right>| . $locale->text('Subtotal') . qq|</th>
599 <td align=right>$form->{invsubtotal}</td>
605 if ($form->{taxincluded}) {
606 foreach $item (split / /, $form->{taxaccounts}) {
607 if ($form->{"${item}_base"}) {
608 $form->{"${item}_total"} =
610 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
611 (1 + $form->{"${item}_rate"})
614 $form->{"${item}_base"} =
615 $form->round_amount($form->{"${item}_base"}, 2);
616 $form->{"${item}_netto"} =
618 ($form->{"${item}_base"} - $form->{"${item}_total"}),
620 $form->{"${item}_netto"} =
621 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
622 $form->{"${item}_total"} =
623 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
627 <th align=right>Enthaltene $form->{"${item}_description"} |
628 . $form->{"${item}_rate"} * 100 .qq|%</th>
629 <td align=right>$form->{"${item}_total"}</td>
632 <th align=right>Nettobetrag</th>
633 <td align=right>$form->{"${item}_netto"}</td>
641 $form->{oldinvtotal} = $form->{invtotal};
643 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
647 <td colspan=$colspan>
648 <table cellspacing="0">
653 <th align=left>| . $locale->text('Notes') . qq|</th>
654 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
662 <td colspan=2 align=right width=100%>
669 <th align=right>| . $locale->text('Total') . qq|</th>
670 <td align=right>$form->{invtotal}</td>
682 <td><hr size=3 noshade></td>
685 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
688 <td align=left width=30%><b>Dateiname</b></td>
689 <td align=left width=70%><b>Webdavlink</b></td>
691 foreach $file (keys %{ $form->{WEBDAV} }) {
694 <td align=left>$file</td>
695 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
708 <td colspan=$colspan>
711 <th colspan=6 class=listheading>| . $locale->text('Payments') . qq|</th>
715 if ($form->{currency} eq $form->{defaultcurrency}) {
716 @column_index = qw(datepaid source memo paid AP_paid);
718 @column_index = qw(datepaid source memo paid exchangerate AP_paid);
721 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
722 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
723 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
724 $column_data{AP_paid} = "<th>" . $locale->text('Account') . "</th>";
725 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
726 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
731 map { print "$column_data{$_}\n" } @column_index;
739 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
740 for $i (1 .. $form->{paidaccounts}) {
746 $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
747 $form->{"selectAP_paid_$i"} =~
748 s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
750 $totalpaid += $form->{"paid_$i"};
753 if ($form->{"paid_$i"}) {
755 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
757 $form->{"exchangerate_$i"} =
758 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
760 $exchangerate = qq| |;
761 if ($form->{currency} ne $form->{defaultcurrency}) {
762 if ($form->{"forex_$i"}) {
764 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
767 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
771 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
774 $column_data{"paid_$i"} =
775 qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
776 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
777 $column_data{"AP_paid_$i"} =
778 qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;
779 $column_data{"datepaid_$i"} =
780 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)\">
781 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
782 $column_data{"source_$i"} =
783 qq|<td align=center><input name="source_$i" size=11 value=$form->{"source_$i"}></td>|;
784 $column_data{"memo_$i"} =
785 qq|<td align=center><input name="memo_$i" size=11 value=$form->{"memo_$i"}></td>|;
787 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
792 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
795 my $paid_missing = $form->{oldinvtotal} - $totalpaid;
801 <td align="center">| . $locale->text('Total') . qq|</td>
802 <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
807 <td align="center">| . $locale->text('Missing amount') . qq|</td>
808 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
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);
827 print qq|<input class=submit type=submit name=action id=update_button value="|
828 . $locale->text('Update') . qq|">
832 my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ap");
834 print qq|<input class=submit type=submit name=action value="|
835 . $locale->text('Post Payment') . qq|">
837 print qq|<input class=submit type=submit name=action value="|
838 . $locale->text('Storno') . qq|">
840 if ($form->{radier}) {
842 <input class=submit type=submit name=action value="|
843 . $locale->text('Delete') . qq|">
846 print qq|<input class=submit type=submit name=action value="|
847 . $locale->text('Use As Template') . qq|">
852 if (!$form->{id} && ($invdate > $closedto)) {
853 print qq| <input class=submit type=submit name=action value="|
854 . $locale->text('Post') . qq|"> | .
855 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
856 '-class' => 'submit'));
859 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers);
860 $form->hide_form(qw(rowcount callback draft_id draft_description login password));
862 # button for saving history
863 if($form->{id} ne "") {
865 <input type="button" class="submit" onclick="set_history_window(|
867 . qq|);" name="history" id="history" value="|
868 . $locale->text('history')
871 # /button for saving history
872 # mark_as_paid button
873 if($form->{id} ne "") {
874 print qq|<input type="submit" class="submit" name="action" value="|
875 . $locale->text('mark as paid') . qq|">|;
877 # /mark_as_paid button
884 $lxdebug->leave_sub();
888 $lxdebug->enter_sub();
889 &mark_as_paid_common(\%myconfig,"ap");
890 $lxdebug->leave_sub();
894 $lxdebug->enter_sub();
896 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
897 qw(exchangerate creditlimit creditremaining);
901 $form->{exchangerate} = $exchangerate
905 $form->check_exchangerate(
906 \%myconfig, $form->{currency}, $form->{invdate}, 'sell'
909 for $i (1 .. $form->{paidaccounts}) {
910 if ($form->{"paid_$i"}) {
913 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
914 } qw(paid exchangerate);
916 $form->{"exchangerate_$i"} = $exchangerate
918 $form->{"forex_$i"} = (
920 $form->check_exchangerate(
921 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell'
926 $i = $form->{rowcount};
927 $exchangerate = ($form->{exchangerate} * 1) ? $form->{exchangerate} * 1 : 1;
929 if ( ($form->{"partnumber_$i"} eq "")
930 && ($form->{"description_$i"} eq "")
931 && ($form->{"partsgroup_$i"} eq "")) {
932 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
937 IR->retrieve_item(\%myconfig, \%$form);
939 my $rows = scalar @{ $form->{item_list} };
942 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
951 # override sellprice if there is one entered
952 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
954 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
955 qw(partnumber description unit);
957 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
958 keys %{ $form->{item_list}[0] };
960 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
962 ($dec) = ($s =~ /\.(\d+)/);
964 $decimalplaces = ($dec > 2) ? $dec : 2;
967 $form->{"sellprice_$i"} = $sellprice;
970 # if there is an exchange rate adjust sellprice
971 $form->{"sellprice_$i"} /= $exchangerate;
975 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
976 (1 - $form->{"discount_$i"} / 100);
977 $form->{creditremaining} -= $amount;
978 $form->{"sellprice_$i"} =
979 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
982 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
989 # ok, so this is a new part
990 # ask if it is a part or service item
992 if ( $form->{"partsgroup_$i"}
993 && ($form->{"partsnumber_$i"} eq "")
994 && ($form->{"description_$i"} eq "")) {
996 $form->{"discount_$i"} = "";
1000 $form->{"id_$i"} = 0;
1001 $form->{"unit_$i"} = $locale->text('ea');
1008 $lxdebug->leave_sub();
1012 $lxdebug->enter_sub();
1014 if ($form->{storno}) {
1015 $form->error($locale->text('Cannot storno storno invoice!'));
1018 if (IS->has_storno(\%myconfig, $form, "ap")) {
1019 $form->error($locale->text("Invoice has already been storno'd!"));
1022 my $employee_id = $form->{employee_id};
1027 # Payments must not be recorded for the new storno invoice.
1028 $form->{paidaccounts} = 0;
1029 map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
1031 # saving the history
1032 if(!exists $form->{addition} && $form->{id} ne "") {
1033 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1034 $form->{addition} = "CANCELED";
1035 $form->save_history($form->dbconnect(\%myconfig));
1037 # /saving the history
1039 $form->{storno_id} = $form->{id};
1040 $form->{storno} = 1;
1042 $form->{invnumber} = "Storno zu " . $form->{invnumber};
1043 $form->{rowcount}++;
1044 $form->{employee_id} = $employee_id;
1046 $lxdebug->leave_sub();
1050 sub use_as_template {
1051 $lxdebug->enter_sub();
1053 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);
1054 $form->{paidaccounts} = 1;
1055 $form->{rowcount}--;
1056 $form->{invdate} = $form->current_date(\%myconfig);
1059 $lxdebug->leave_sub();
1063 $lxdebug->enter_sub();
1065 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1066 for $i (1 .. $form->{paidaccounts}) {
1067 if ($form->{"paid_$i"}) {
1068 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1070 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1072 $form->error($locale->text('Cannot post payment for a closed period!'))
1073 if ($datepaid <= $closedto);
1075 if ($form->{currency} ne $form->{defaultcurrency}) {
1076 $form->{"exchangerate_$i"} = $form->{exchangerate}
1077 if ($invdate == $datepaid);
1078 $form->isblank("exchangerate_$i",
1079 $locale->text('Exchangerate for payment missing!'));
1084 ($form->{AP}) = split /--/, $form->{AP};
1085 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1086 if (IR->post_payment(\%myconfig, \%$form)){
1087 if (!exists $form->{addition} && $form->{id} ne "") {
1088 # saving the history
1089 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1090 $form->{addition} = "PAYMENT POSTED";
1091 $form->{what_done} = $form->{currency} . qq| | . $form->{paid} . qq| | . $locale->text("POSTED");
1092 $form->save_history($form->dbconnect(\%myconfig));
1093 # /saving the history
1096 $form->redirect($locale->text('Payment posted!'));
1099 $form->error($locale->text('Cannot post payment!'));
1101 $lxdebug->leave_sub();
1105 $lxdebug->enter_sub();
1107 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1109 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1110 $form->isblank("vendor", $locale->text('Vendor missing!'));
1112 $form->{invnumber} =~ s/^\s*//g;
1113 $form->{invnumber} =~ s/\s*$//g;
1115 # if the vendor changed get new values
1116 if (&check_name(vendor)) {
1123 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1124 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1126 $form->error($locale->text('Cannot post invoice for a closed period!'))
1127 if ($invdate <= $closedto);
1129 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1130 if ($form->{currency} ne $form->{defaultcurrency});
1132 for $i (1 .. $form->{paidaccounts}) {
1133 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1134 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1136 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1138 $form->error($locale->text('Cannot post payment for a closed period!'))
1139 if ($datepaid <= $closedto);
1141 if ($form->{currency} ne $form->{defaultcurrency}) {
1142 $form->{"exchangerate_$i"} = $form->{exchangerate}
1143 if ($invdate == $datepaid);
1144 $form->isblank("exchangerate_$i",
1145 $locale->text('Exchangerate for payment missing!'));
1150 ($form->{AP}) = split /--/, $form->{AP};
1151 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1152 $form->{storno} = 0;
1154 $form->{id} = 0 if $form->{postasnew};
1158 if (IR->post_invoice(\%myconfig, \%$form)){
1159 # saving the history
1160 if(!exists $form->{addition} && $form->{id} ne "") {
1161 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1162 $form->{addition} = "POSTED";
1163 #$form->{what_done} = $locale->text("Rechnungsnummer") . qq| | . $form->{invnumber};
1164 $form->save_history($form->dbconnect(\%myconfig));
1166 # /saving the history
1167 remove_draft() if $form->{remove_draft};
1168 $form->redirect( $locale->text('Invoice')
1169 . " $form->{invnumber} "
1170 . $locale->text('posted!'));
1172 $form->error($locale->text('Cannot post invoice!'));
1174 $lxdebug->leave_sub();
1178 $lxdebug->enter_sub();
1184 <form method=post action=$form->{script}>
1187 # delete action variable
1188 map { delete $form->{$_} } qw(action header);
1190 foreach $key (keys %$form) {
1191 $form->{$key} =~ s/\"/"/g;
1192 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1196 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1199 . $locale->text('Are you sure you want to delete Invoice Number')
1200 . qq| $form->{invnumber}</h4>
1202 <input name=action class=submit type=submit value="|
1203 . $locale->text('Yes') . qq|">
1207 $lxdebug->leave_sub();
1211 $lxdebug->enter_sub();
1212 if (IR->delete_invoice(\%myconfig, \%$form)) {
1213 # saving the history
1214 if(!exists $form->{addition}) {
1215 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1216 $form->{addition} = "DELETED";
1217 $form->save_history($form->dbconnect(\%myconfig));
1219 # /saving the history
1220 $form->redirect($locale->text('Invoice deleted!'));
1222 $form->error($locale->text('Cannot delete invoice!'));
1224 $lxdebug->leave_sub();