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;
82 $form->{jsscript} = 1;
84 $form->create_links("AP", \%myconfig, "vendor");
86 #quote all_vendor Bug 133
87 foreach $ref (@{ $form->{all_vendor} }) {
88 $ref->{name} = $form->quote($ref->{name});
91 if ($form->{all_vendor}) {
92 unless ($form->{vendor_id}) {
93 $form->{vendor_id} = $form->{all_vendor}->[0]->{id};
96 if ($form->{payment_id}) {
97 $payment_id = $form->{payment_id};
99 if ($form->{language_id}) {
100 $language_id = $form->{language_id};
102 if ($form->{taxzone_id}) {
103 $taxzone_id = $form->{taxzone_id};
106 $cp_id = $form->{cp_id};
107 IR->get_vendor(\%myconfig, \%$form);
108 IR->retrieve_invoice(\%myconfig, \%$form);
109 $form->{cp_id} = $cp_id;
112 $form->{payment_id} = $payment_id;
115 $form->{language_id} = $language_id;
118 $form->{taxzone_id} = $taxzone_id;
121 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
123 $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
126 if ($form->{all_departments}) {
127 $form->{selectdepartment} = "<option>\n";
128 $form->{department} = "$form->{department}--$form->{department_id}";
131 $form->{selectdepartment} .=
132 "<option>$_->{description}--$_->{id}\n"
133 } (@{ $form->{all_departments} });
137 $form->{forex} = $form->{exchangerate};
138 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
140 foreach $key (keys %{ $form->{AP_links} }) {
142 foreach $ref (@{ $form->{AP_links}{$key} }) {
143 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
146 if ($key eq "AP_paid") {
147 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
148 $form->{"AP_paid_$i"} =
149 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
152 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount};
153 $form->{"datepaid_$i"} =
154 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
155 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
156 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
157 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
158 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
160 $form->{paidaccounts} = $i;
164 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
169 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
171 $form->{AP} = $form->{AP_1} unless $form->{id};
174 ($form->datetonum($form->{invdate}, \%myconfig) <=
175 $form->datetonum($form->{closedto}, \%myconfig));
177 $lxdebug->leave_sub();
180 sub prepare_invoice {
181 $lxdebug->enter_sub();
185 map { $form->{$_} =~ s/\"/"/g } qw(invnumber ordnumber quonumber);
188 foreach $ref (@{ $form->{invoice_details} }) {
190 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
192 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
194 $decimalplaces = ($dec > 2) ? $dec : 2;
196 $form->{"sellprice_$i"} =
197 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
200 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
201 $dec_qty = length $dec_qty;
204 $form->format_amount(\%myconfig, ($form->{"qty_$i"} * -1), $dec_qty);
206 $form->{rowcount} = $i;
210 $lxdebug->leave_sub();
214 $lxdebug->enter_sub();
216 # set option selected
217 foreach $item (qw(AP vendor currency department)) {
218 $form->{"select$item"} =~ s/ selected//;
219 $form->{"select$item"} =~
220 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
223 $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
224 $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
225 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
226 $form->{radier} = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
227 $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
228 $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
229 $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
232 if ($form->{currency} ne $form->{defaultcurrency}) {
233 if ($form->{forex}) {
234 $exchangerate .= qq| <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
235 <td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>\n|;
237 $exchangerate .= qq| <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
238 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>\n|;
241 $exchangerate .= qq| <input type=hidden name=forex value=$form->{forex}>\n|;
243 my @old_project_ids = ($form->{"globalproject_id"});
244 map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"};
246 $form->get_lists("contacts" => "ALL_CONTACTS",
247 "projects" => { "key" => "ALL_PROJECTS",
249 "old_id" => \@old_project_ids },
250 "taxzones" => "ALL_TAXZONES",
251 "employees" => "ALL_SALESMEN",
252 "currencies" => "ALL_CURRENCIES",
253 "vendors" => "ALL_VENDORS");
256 my @values = (undef);
257 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
258 push(@values, $item->{"cp_id"});
259 $labels{$item->{"cp_id"}} = $item->{"cp_name"} . ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
263 if (scalar @values > 1) {
266 <th align="right">| . $locale->text('Contact Person') . qq|</th>
267 <td>| . NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
268 '-labels' => \%labels, '-default' => $form->{"cp_id"})) . qq|
275 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
276 push(@values, $item->{"id"});
277 $labels{$item->{"id"}} = $item->{"projectnumber"};
279 my $globalprojectnumber = NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values, '-labels' => \%labels,
280 '-default' => $form->{"globalproject_id"}));
285 foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
286 push(@values, $item);
287 $labels{$item} = $item;
290 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
292 if (scalar @values) {
295 <th align="right">| . $locale->text('Currency') . qq|</th>
296 <td>| . NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
297 '-values' => \@values, '-labels' => \%labels)) . qq|
305 foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
306 push(@values, $item->{"id"});
307 $labels{$item->{"id"}} = $item->{"name"};
311 <th align="right">| . $locale->text('Employee') . qq|</th>
312 <td>| . NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
313 '-values' => \@values, '-labels' => \%labels)) . qq|
320 foreach my $item (@{ $form->{"ALL_VENDORS"} }) {
321 push(@values, $item->{name}.qq|--|.$item->{"id"});
322 $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
325 $form->{selectvendor} = ($myconfig{vclimit} > scalar(@values));
328 <th align="right">| . $locale->text('Vendor') . qq|</th>
330 (($myconfig{vclimit} <= scalar(@values))
331 ? qq|<input type="text" value="| . H($form->{vendor}) . qq|" name="vendor">|
332 : (NTI($cgi->popup_menu('-name' => 'vendor', '-default' => $form->{oldvendor},
333 '-onChange' => 'document.getElementById(\'update_button\').click();',
334 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq|
335 <input type="button" value="?" onclick="show_vc_details('vendor')">
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>
349 <td>| . NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
350 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')) . qq|
356 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
358 <input type="hidden" name="taxzone_id" value="| . H($form->{"taxzone_id"}) . qq|">
359 | . H($labels{$form->{"taxzone_id"}}) . qq|
366 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
367 <td colspan="3"><select name="department" style="width: 250px">$form->{selectdepartment}</select>
368 <input type="hidden" name="selectdepartment" value="$form->{selectdepartment}">
371 | if $form->{selectdepartment};
373 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
375 # use JavaScript Calendar or not
376 $form->{jsscript} = 1;
380 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
381 <input type=button name=invdate id="trigger1" value=| . $locale->text('button') . qq|></td>\n|;
383 <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\">
384 <input type=button name=duedate id="trigger2" value=| . $locale->text('button') . qq|></td></td>\n|;
388 Form->write_trigger(\%myconfig, "2", "invdate", "BL", "trigger1",
389 "duedate", "BL", "trigger2");
391 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
392 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
393 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
395 $jsscript .= $form->write_trigger(\%myconfig, 2, "orddate", "BL", "trigger_orddate", "quodate", "BL", "trigger_quodate");
398 $onload = qq|focus()|;
399 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
400 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
402 <body onLoad="$onload">
404 <form method=post action=$form->{script}>
407 $form->hide_form(qw(id title vc type level creditlimit creditremaining
408 closedto locked shippted storno storno_id
409 max_dunning_level dunning_amount));
411 print qq|<p>$form->{saved_message}</p>| if $form->{saved_message};
415 <div class="listtop" width="100%">$form->{title}</div>
422 <input type="hidden" name="vendor_id" value="$form->{vendor_id}">
423 <input type="hidden" name="oldvendor" value="$form->{oldvendor}">
424 <input type="hidden" name="selectvendor" value= "$form->{selectvendor}">
427 <td align="right">| . $locale->text('Credit Limit') . qq|</td>
428 <td>$form->{creditlimit}; | . $locale->text('Remaining') . qq| <span class="plus$n">$form->{creditremaining}</span></td>
431 <th align="right">| . $locale->text('Record in') . qq|</th>
432 <td colspan="3"><select name="AP" style="width: 250px">$form->{selectAP}</select></td>
433 <input type="hidden" name="selectAP" value="$form->{selectAP}">
447 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
448 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
451 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
455 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
459 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
460 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
461 <input type=hidden name=quonumber value="$form->{quonumber}">
464 <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
465 <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|" onBlur=\"check_right_date_format(this)\">
466 <input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
469 <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
470 <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|" onBlur=\"check_right_date_format(this)\">
471 <input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
474 <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
475 <td>$globalprojectnumber</td>
486 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
487 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
488 <input type=hidden name=webdav value=$webdav>
490 <input type=hidden name=taxpart value="$form->{taxpart}">
491 <input type=hidden name=taxservice value="$form->{taxservice}">
493 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
496 foreach $item (split / /, $form->{taxaccounts}) {
498 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
499 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
503 $lxdebug->leave_sub();
507 $lxdebug->enter_sub();
509 $form->{invtotal} = $form->{invsubtotal};
511 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
514 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
517 $rows = ($rows > $introws) ? $rows : $introws;
519 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
521 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
523 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
526 if ($form->{taxaccounts}) {
528 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
529 . $locale->text('Tax Included') . qq|</b>
533 if (!$form->{taxincluded}) {
535 foreach $item (split / /, $form->{taxaccounts}) {
536 if ($form->{"${item}_base"}) {
537 $form->{invtotal} += $form->{"${item}_total"} =
539 $form->{"${item}_base"} * $form->{"${item}_rate"},
541 $form->{"${item}_total"} =
542 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
546 <th align=right>$form->{"${item}_description"} |
547 . $form->{"${item}_rate"} * 100 .qq|%</th>
548 <td align=right>$form->{"${item}_total"}</td>
554 $form->{invsubtotal} =
555 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
559 <th align=right>| . $locale->text('Subtotal') . qq|</th>
560 <td align=right>$form->{invsubtotal}</td>
566 if ($form->{taxincluded}) {
567 foreach $item (split / /, $form->{taxaccounts}) {
568 if ($form->{"${item}_base"}) {
569 $form->{"${item}_total"} =
571 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
572 (1 + $form->{"${item}_rate"})
575 $form->{"${item}_base"} =
576 $form->round_amount($form->{"${item}_base"}, 2);
577 $form->{"${item}_netto"} =
579 ($form->{"${item}_base"} - $form->{"${item}_total"}),
581 $form->{"${item}_netto"} =
582 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
583 $form->{"${item}_total"} =
584 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
588 <th align=right>Enthaltene $form->{"${item}_description"} |
589 . $form->{"${item}_rate"} * 100 .qq|%</th>
590 <td align=right>$form->{"${item}_total"}</td>
593 <th align=right>Nettobetrag</th>
594 <td align=right>$form->{"${item}_netto"}</td>
602 $form->{oldinvtotal} = $form->{invtotal};
604 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
608 <td colspan=$colspan>
609 <table cellspacing="0">
614 <th align=left>| . $locale->text('Notes') . qq|</th>
615 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
623 <td colspan=2 align=right width=100%>
630 <th align=right>| . $locale->text('Total') . qq|</th>
631 <td align=right>$form->{invtotal}</td>
643 <td><hr size=3 noshade></td>
646 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
649 <td align=left width=30%><b>Dateiname</b></td>
650 <td align=left width=70%><b>Webdavlink</b></td>
652 foreach $file (@{ $form->{WEBDAV} }) {
655 <td align="left">$file->{name}</td>
656 <td align="left"><a href="$file->{link}">$file->{type}</a></td>
669 <td colspan=$colspan>
672 <th colspan=6 class=listheading>| . $locale->text('Payments') . qq|</th>
676 if ($form->{currency} eq $form->{defaultcurrency}) {
677 @column_index = qw(datepaid source memo paid AP_paid);
679 @column_index = qw(datepaid source memo paid exchangerate AP_paid);
682 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
683 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
684 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
685 $column_data{AP_paid} = "<th>" . $locale->text('Account') . "</th>";
686 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
687 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
692 map { print "$column_data{$_}\n" } @column_index;
700 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
701 for $i (1 .. $form->{paidaccounts}) {
707 $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
708 $form->{"selectAP_paid_$i"} =~
709 s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
711 $totalpaid += $form->{"paid_$i"};
714 if ($form->{"paid_$i"}) {
716 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
718 $form->{"exchangerate_$i"} =
719 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
721 $exchangerate = qq| |;
722 if ($form->{currency} ne $form->{defaultcurrency}) {
723 if ($form->{"forex_$i"}) {
725 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
728 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
732 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
735 $column_data{"paid_$i"} =
736 qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
737 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
738 $column_data{"AP_paid_$i"} =
739 qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;
740 $column_data{"datepaid_$i"} =
741 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)\">
742 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
743 $column_data{"source_$i"} =
744 qq|<td align=center><input name="source_$i" size=11 value=$form->{"source_$i"}></td>|;
745 $column_data{"memo_$i"} =
746 qq|<td align=center><input name="memo_$i" size=11 value=$form->{"memo_$i"}></td>|;
748 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
753 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
756 my $paid_missing = $form->{oldinvtotal} - $totalpaid;
762 <td align="center">| . $locale->text('Total') . qq|</td>
763 <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
768 <td align="center">| . $locale->text('Missing amount') . qq|</td>
769 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
772 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
773 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
774 <input type=hidden name=selectAP_paid value="$form->{selectAP_paid}">
779 <td><hr size=3 noshade></td>
785 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
786 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
788 print qq|<input class=submit type=submit name=action id=update_button value="|
789 . $locale->text('Update') . qq|">
793 my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ap");
795 print qq|<input class=submit type=submit name=action value="|
796 . $locale->text('Post Payment') . qq|">
798 print qq|<input class=submit type=submit name=action value="|
799 . $locale->text('Storno') . qq|">
801 if ($form->{radier}) {
803 <input class=submit type=submit name=action value="|
804 . $locale->text('Delete') . qq|">
807 print qq|<input class=submit type=submit name=action value="|
808 . $locale->text('Use As Template') . qq|">
813 if (!$form->{id} && ($invdate > $closedto)) {
814 print qq| <input class=submit type=submit name=action value="|
815 . $locale->text('Post') . qq|"> | .
816 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
817 '-class' => 'submit'));
820 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers);
821 $form->hide_form(qw(rowcount callback draft_id draft_description login password));
823 # button for saving history
824 if($form->{id} ne "") {
826 <input type="button" class="submit" onclick="set_history_window(|
828 . qq|);" name="history" id="history" value="|
829 . $locale->text('history')
832 # /button for saving history
833 # mark_as_paid button
834 if($form->{id} ne "") {
835 print qq| <input type="submit" class="submit" name="action" value="|
836 . $locale->text('mark as paid') . qq|">|;
838 # /mark_as_paid button
845 $lxdebug->leave_sub();
849 $lxdebug->enter_sub();
850 &mark_as_paid_common(\%myconfig,"ap");
851 $lxdebug->leave_sub();
855 $lxdebug->enter_sub();
857 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
858 qw(exchangerate creditlimit creditremaining);
862 $form->{exchangerate} = $exchangerate
866 $form->check_exchangerate(
867 \%myconfig, $form->{currency}, $form->{invdate}, 'sell'
870 for $i (1 .. $form->{paidaccounts}) {
871 if ($form->{"paid_$i"}) {
874 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
875 } qw(paid exchangerate);
877 $form->{"exchangerate_$i"} = $exchangerate
879 $form->{"forex_$i"} = (
881 $form->check_exchangerate(
882 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell'
887 $i = $form->{rowcount};
888 $exchangerate = ($form->{exchangerate} * 1) ? $form->{exchangerate} * 1 : 1;
890 if ( ($form->{"partnumber_$i"} eq "")
891 && ($form->{"description_$i"} eq "")
892 && ($form->{"partsgroup_$i"} eq "")) {
893 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
898 IR->retrieve_item(\%myconfig, \%$form);
900 my $rows = scalar @{ $form->{item_list} };
903 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
912 # override sellprice if there is one entered
913 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
915 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
916 qw(partnumber description unit);
918 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
919 keys %{ $form->{item_list}[0] };
921 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
923 ($dec) = ($s =~ /\.(\d+)/);
925 $decimalplaces = ($dec > 2) ? $dec : 2;
928 $form->{"sellprice_$i"} = $sellprice;
931 # if there is an exchange rate adjust sellprice
932 $form->{"sellprice_$i"} /= $exchangerate;
936 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
937 (1 - $form->{"discount_$i"} / 100);
938 $form->{creditremaining} -= $amount;
939 $form->{"sellprice_$i"} =
940 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
943 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
950 # ok, so this is a new part
951 # ask if it is a part or service item
953 if ( $form->{"partsgroup_$i"}
954 && ($form->{"partsnumber_$i"} eq "")
955 && ($form->{"description_$i"} eq "")) {
957 $form->{"discount_$i"} = "";
961 $form->{"id_$i"} = 0;
966 $lxdebug->leave_sub();
970 $lxdebug->enter_sub();
972 if ($form->{storno}) {
973 $form->error($locale->text('Cannot storno storno invoice!'));
976 if (IS->has_storno(\%myconfig, $form, "ap")) {
977 $form->error($locale->text("Invoice has already been storno'd!"));
980 my $employee_id = $form->{employee_id};
985 # Payments must not be recorded for the new storno invoice.
986 $form->{paidaccounts} = 0;
987 map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
990 if(!exists $form->{addition} && $form->{id} ne "") {
991 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
992 $form->{addition} = "CANCELED";
993 $form->save_history($form->dbconnect(\%myconfig));
995 # /saving the history
997 $form->{storno_id} = $form->{id};
1000 $form->{invnumber} = "Storno zu " . $form->{invnumber};
1001 $form->{rowcount}++;
1002 $form->{employee_id} = $employee_id;
1004 $lxdebug->leave_sub();
1008 sub use_as_template {
1009 $lxdebug->enter_sub();
1011 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);
1012 $form->{paidaccounts} = 1;
1013 $form->{rowcount}--;
1014 $form->{invdate} = $form->current_date(\%myconfig);
1017 $lxdebug->leave_sub();
1021 $lxdebug->enter_sub();
1023 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1024 for $i (1 .. $form->{paidaccounts}) {
1025 if ($form->{"paid_$i"}) {
1026 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1028 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1030 $form->error($locale->text('Cannot post payment for a closed period!'))
1031 if ($datepaid <= $closedto);
1033 if ($form->{currency} ne $form->{defaultcurrency}) {
1034 $form->{"exchangerate_$i"} = $form->{exchangerate}
1035 if ($invdate == $datepaid);
1036 $form->isblank("exchangerate_$i",
1037 $locale->text('Exchangerate for payment missing!'));
1042 ($form->{AP}) = split /--/, $form->{AP};
1043 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1044 if (IR->post_payment(\%myconfig, \%$form)){
1045 if (!exists $form->{addition} && $form->{id} ne "") {
1046 # saving the history
1047 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1048 $form->{addition} = "PAYMENT POSTED";
1049 $form->{what_done} = $form->{currency} . qq| | . $form->{paid} . qq| | . $locale->text("POSTED");
1050 $form->save_history($form->dbconnect(\%myconfig));
1051 # /saving the history
1054 $form->redirect($locale->text('Payment posted!'));
1057 $form->error($locale->text('Cannot post payment!'));
1059 $lxdebug->leave_sub();
1063 $lxdebug->enter_sub();
1065 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1067 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1068 $form->isblank("vendor", $locale->text('Vendor missing!'));
1070 $form->{invnumber} =~ s/^\s*//g;
1071 $form->{invnumber} =~ s/\s*$//g;
1073 # if the vendor changed get new values
1074 if (&check_name(vendor)) {
1081 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1082 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1084 $form->error($locale->text('Cannot post invoice for a closed period!'))
1085 if ($invdate <= $closedto);
1087 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1088 if ($form->{currency} ne $form->{defaultcurrency});
1090 for $i (1 .. $form->{paidaccounts}) {
1091 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1092 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1094 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1096 $form->error($locale->text('Cannot post payment for a closed period!'))
1097 if ($datepaid <= $closedto);
1099 if ($form->{currency} ne $form->{defaultcurrency}) {
1100 $form->{"exchangerate_$i"} = $form->{exchangerate}
1101 if ($invdate == $datepaid);
1102 $form->isblank("exchangerate_$i",
1103 $locale->text('Exchangerate for payment missing!'));
1108 ($form->{AP}) = split /--/, $form->{AP};
1109 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1110 $form->{storno} = 0;
1112 $form->{id} = 0 if $form->{postasnew};
1116 if (IR->post_invoice(\%myconfig, \%$form)){
1117 # saving the history
1118 if(!exists $form->{addition} && $form->{id} ne "") {
1119 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1120 $form->{addition} = "POSTED";
1121 #$form->{what_done} = $locale->text("Rechnungsnummer") . qq| | . $form->{invnumber};
1122 $form->save_history($form->dbconnect(\%myconfig));
1124 # /saving the history
1125 remove_draft() if $form->{remove_draft};
1126 $form->redirect( $locale->text('Invoice')
1127 . " $form->{invnumber} "
1128 . $locale->text('posted!'));
1130 $form->error($locale->text('Cannot post invoice!'));
1132 $lxdebug->leave_sub();
1136 $lxdebug->enter_sub();
1142 <form method=post action=$form->{script}>
1145 # delete action variable
1146 map { delete $form->{$_} } qw(action header);
1148 foreach $key (keys %$form) {
1149 $form->{$key} =~ s/\"/"/g;
1150 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1154 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1157 . $locale->text('Are you sure you want to delete Invoice Number')
1158 . qq| $form->{invnumber}</h4>
1160 <input name=action class=submit type=submit value="|
1161 . $locale->text('Yes') . qq|">
1165 $lxdebug->leave_sub();
1169 $lxdebug->enter_sub();
1170 if (IR->delete_invoice(\%myconfig, \%$form)) {
1171 # saving the history
1172 if(!exists $form->{addition}) {
1173 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1174 $form->{addition} = "DELETED";
1175 $form->save_history($form->dbconnect(\%myconfig));
1177 # /saving the history
1178 $form->redirect($locale->text('Invoice deleted!'));
1180 $form->error($locale->text('Cannot delete invoice!'));
1182 $lxdebug->leave_sub();