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 use List::Util qw(max sum);
40 require "bin/mozilla/io.pl";
41 require "bin/mozilla/invoice_io.pl";
42 require "bin/mozilla/arap.pl";
43 require "bin/mozilla/common.pl";
44 require "bin/mozilla/drafts.pl";
51 $lxdebug->enter_sub();
53 $auth->assert('vendor_invoice_edit');
55 return $lxdebug->leave_sub() if (load_draft_maybe());
57 $form->{title} = $locale->text('Add Vendor Invoice');
63 $lxdebug->leave_sub();
67 $lxdebug->enter_sub();
69 $auth->assert('vendor_invoice_edit');
72 $form->{javascript} = qq|<script type=text/javascript src=js/show_history.js></script>|;
73 #/show hhistory button
75 $form->{title} = $locale->text('Edit Vendor Invoice');
81 $lxdebug->leave_sub();
85 $lxdebug->enter_sub();
87 $auth->assert('vendor_invoice_edit');
90 $form->{webdav} = $webdav;
91 $form->{jsscript} = 1;
93 $form->create_links("AP", \%myconfig, "vendor");
95 #quote all_vendor Bug 133
96 foreach $ref (@{ $form->{all_vendor} }) {
97 $ref->{name} = $form->quote($ref->{name});
100 if ($form->{all_vendor}) {
101 unless ($form->{vendor_id}) {
102 $form->{vendor_id} = $form->{all_vendor}->[0]->{id};
105 if ($form->{payment_id}) {
106 $payment_id = $form->{payment_id};
108 if ($form->{language_id}) {
109 $language_id = $form->{language_id};
111 if ($form->{taxzone_id}) {
112 $taxzone_id = $form->{taxzone_id};
115 $cp_id = $form->{cp_id};
116 IR->get_vendor(\%myconfig, \%$form);
117 IR->retrieve_invoice(\%myconfig, \%$form);
118 $form->{cp_id} = $cp_id;
121 $form->{payment_id} = $payment_id;
124 $form->{language_id} = $language_id;
127 $form->{taxzone_id} = $taxzone_id;
130 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
132 $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
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();
192 $auth->assert('vendor_invoice_edit');
196 map { $form->{$_} =~ s/\"/"/g } qw(invnumber ordnumber quonumber);
199 foreach $ref (@{ $form->{invoice_details} }) {
201 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
203 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
205 $decimalplaces = ($dec > 2) ? $dec : 2;
207 $form->{"sellprice_$i"} =
208 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
211 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
212 $dec_qty = length $dec_qty;
215 $form->format_amount(\%myconfig, ($form->{"qty_$i"} * -1), $dec_qty);
217 $form->{rowcount} = $i;
221 $lxdebug->leave_sub();
225 $lxdebug->enter_sub();
227 $auth->assert('vendor_invoice_edit');
229 # set option selected
230 foreach $item (qw(AP vendor currency department)) {
231 $form->{"select$item"} =~ s/ selected//;
232 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
235 $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
236 $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
237 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
238 $form->{radier} = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
239 $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
240 $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
241 $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
244 if ($form->{currency} ne $form->{defaultcurrency}) {
245 if ($form->{forex}) {
246 $exchangerate .= qq| <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
247 <td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>\n|;
249 $exchangerate .= qq| <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
250 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>\n|;
253 $exchangerate .= qq| <input type=hidden name=forex value=$form->{forex}>\n|;
255 my @old_project_ids = ($form->{"globalproject_id"});
256 map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"};
258 $form->get_lists("contacts" => "ALL_CONTACTS",
259 "projects" => { "key" => "ALL_PROJECTS",
261 "old_id" => \@old_project_ids },
262 "taxzones" => "ALL_TAXZONES",
263 "employees" => "ALL_SALESMEN",
264 "currencies" => "ALL_CURRENCIES",
265 "vendors" => "ALL_VENDORS",
266 "price_factors" => "ALL_PRICE_FACTORS");
269 my @values = (undef);
270 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
271 push(@values, $item->{"cp_id"});
272 $labels{$item->{"cp_id"}} = $item->{"cp_name"} . ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
276 if (scalar @values > 1) {
279 <th align="right">| . $locale->text('Contact Person') . qq|</th>
280 <td>| . NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
281 '-labels' => \%labels, '-default' => $form->{"cp_id"})) . qq|
288 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
289 push(@values, $item->{"id"});
290 $labels{$item->{"id"}} = $item->{"projectnumber"};
292 my $globalprojectnumber = NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values, '-labels' => \%labels,
293 '-default' => $form->{"globalproject_id"}));
298 foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
299 push(@values, $item);
300 $labels{$item} = $item;
303 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
305 if (scalar @values) {
308 <th align="right">| . $locale->text('Currency') . qq|</th>
309 <td>| . NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
310 '-values' => \@values, '-labels' => \%labels)) . qq|
318 foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
319 push(@values, $item->{"id"});
320 $labels{$item->{"id"}} = $item->{"name"};
324 <th align="right">| . $locale->text('Employee') . qq|</th>
325 <td>| . NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
326 '-values' => \@values, '-labels' => \%labels)) . qq|
333 foreach my $item (@{ $form->{"ALL_VENDORS"} }) {
334 push(@values, $item->{name}.qq|--|.$item->{"id"});
335 $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
338 $form->{selectvendor} = ($myconfig{vclimit} > scalar(@values));
341 <th align="right">| . $locale->text('Vendor') . qq|</th>
343 (($myconfig{vclimit} <= scalar(@values))
344 ? qq|<input type="text" value="| . H($form->{vendor}) . qq|" name="vendor">|
345 : (NTI($cgi->popup_menu('-name' => 'vendor', '-default' => $form->{oldvendor},
346 '-onChange' => 'document.getElementById(\'update_button\').click();',
347 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq|
348 <input type="button" value="?" onclick="show_vc_details('vendor')">
353 foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
354 push(@values, $item->{"id"});
355 $labels{$item->{"id"}} = $item->{"description"};
358 if (!$form->{"id"}) {
361 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
362 <td>| . NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
363 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')) . qq|
369 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
371 <input type="hidden" name="taxzone_id" value="| . H($form->{"taxzone_id"}) . qq|">
372 | . H($labels{$form->{"taxzone_id"}}) . qq|
379 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
380 <td colspan="3"><select name="department" style="width: 250px">$form->{selectdepartment}</select>
381 <input type="hidden" name="selectdepartment" value="$form->{selectdepartment}">
383 </tr>\n| if $form->{selectdepartment};
385 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
387 # use JavaScript Calendar or not
388 $form->{jsscript} = 1;
392 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
393 <input type=button name=invdate id="trigger1" value=| . $locale->text('button') . qq|></td>\n|;
395 <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\">
396 <input type=button name=duedate id="trigger2" value=| . $locale->text('button') . qq|></td>\n|;
400 Form->write_trigger(\%myconfig, "2",
401 "invdate", "BL", "trigger1",
402 "duedate", "BL", "trigger2");
404 my $follow_up_vc = $form->{vendor};
405 $follow_up_vc =~ s/--.*?//;
406 my $follow_up_trans_info = "$form->{invnumber} ($follow_up_vc)";
408 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
409 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
410 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
411 $form->{javascript} .= qq|<script type="text/javascript" src="js/follow_up.js"></script>|;
413 $jsscript .= $form->write_trigger(\%myconfig, 2, "orddate", "BL", "trigger_orddate", "quodate", "BL", "trigger_quodate");
416 $onload = qq|focus()|;
417 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
418 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
420 <body onLoad="$onload">
422 <form method=post action=$form->{script}>
425 $form->hide_form(qw(id title vc type level creditlimit creditremaining closedto locked shippted storno storno_id
426 max_dunning_level dunning_amount vendor_id oldvendor selectvendor taxaccounts
427 fxgain_accno fxloss_accno taxpart taxservice),
428 map { $_.'_rate', $_.'_description' } split / /, $form->{taxaccounts} );
430 print qq|<p>$form->{saved_message}</p>| if $form->{saved_message};
434 <div class="listtop" width="100%">$form->{title}</div>
443 <td align="right">| . $locale->text('Credit Limit') . qq|</td>
444 <td>$form->{creditlimit}; | . $locale->text('Remaining') . qq| <span class="plus$n">$form->{creditremaining}</span></td>
447 <th align="right">| . $locale->text('Record in') . qq|</th>
448 <td colspan="3"><select name="AP" style="width: 250px">$form->{selectAP}</select></td>
449 <input type="hidden" name="selectAP" value="$form->{selectAP}">
463 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
464 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
467 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
471 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
475 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
476 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
477 <input type=hidden name=quonumber value="$form->{quonumber}">
480 <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
481 <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|" onBlur=\"check_right_date_format(this)\">
482 <input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
485 <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
486 <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|" onBlur=\"check_right_date_format(this)\">
487 <input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
490 <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
491 <td>$globalprojectnumber</td>
502 <input type=hidden name=webdav value=$webdav>
505 foreach $item (split / /, $form->{taxaccounts}) {
507 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
508 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
512 $lxdebug->leave_sub();
516 $lxdebug->enter_sub();
518 $auth->assert('vendor_invoice_edit');
520 $form->{invtotal} = $form->{invsubtotal};
522 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
525 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
528 $rows = ($rows > $introws) ? $rows : $introws;
530 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
532 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
534 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
537 if ($form->{taxaccounts}) {
539 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
540 . $locale->text('Tax Included') . qq|</b>
544 if (!$form->{taxincluded}) {
546 foreach $item (split / /, $form->{taxaccounts}) {
547 if ($form->{"${item}_base"}) {
548 $form->{invtotal} += $form->{"${item}_total"} =
550 $form->{"${item}_base"} * $form->{"${item}_rate"},
552 $form->{"${item}_total"} =
553 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
557 <th align=right>$form->{"${item}_description"} |
558 . $form->{"${item}_rate"} * 100 .qq|%</th>
559 <td align=right>$form->{"${item}_total"}</td>
565 $form->{invsubtotal} =
566 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
570 <th align=right>| . $locale->text('Subtotal') . qq|</th>
571 <td align=right>$form->{invsubtotal}</td>
577 if ($form->{taxincluded}) {
578 foreach $item (split / /, $form->{taxaccounts}) {
579 if ($form->{"${item}_base"}) {
580 $form->{"${item}_total"} =
582 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
583 (1 + $form->{"${item}_rate"})
586 $form->{"${item}_base"} =
587 $form->round_amount($form->{"${item}_base"}, 2);
588 $form->{"${item}_netto"} =
590 ($form->{"${item}_base"} - $form->{"${item}_total"}),
592 $form->{"${item}_netto"} =
593 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
594 $form->{"${item}_total"} =
595 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
599 <th align=right>Enthaltene $form->{"${item}_description"} |
600 . $form->{"${item}_rate"} * 100 .qq|%</th>
601 <td align=right>$form->{"${item}_total"}</td>
604 <th align=right>Nettobetrag</th>
605 <td align=right>$form->{"${item}_netto"}</td>
613 $form->{oldinvtotal} = $form->{invtotal};
615 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
617 my $follow_ups_block;
619 my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
621 if (@{ $follow_ups} ) {
622 my $num_due = sum map { $_->{due} * 1 } @{ $follow_ups };
623 $follow_ups_block = qq|
625 <td colspan="2">| . $locale->text("There are #1 unfinished follow-ups of which #2 are due.", scalar @{ $follow_ups }, $num_due) . qq|</td>
633 <td colspan=$colspan>
634 <table cellspacing="0">
639 <th align=left>| . $locale->text('Notes') . qq|</th>
640 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
649 <td colspan=2 align=right width=100%>
656 <th align=right>| . $locale->text('Total') . qq|</th>
657 <td align=right>$form->{invtotal}</td>
669 <td><hr size=3 noshade></td>
672 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
675 <td align=left width=30%><b>Dateiname</b></td>
676 <td align=left width=70%><b>Webdavlink</b></td>
678 foreach $file (@{ $form->{WEBDAV} }) {
681 <td align="left">$file->{name}</td>
682 <td align="left"><a href="$file->{link}">$file->{type}</a></td>
695 <td colspan=$colspan>
698 <th colspan=6 class=listheading>| . $locale->text('Payments') . qq|</th>
702 if ($form->{currency} eq $form->{defaultcurrency}) {
703 @column_index = qw(datepaid source memo paid AP_paid);
705 @column_index = qw(datepaid source memo paid exchangerate AP_paid);
708 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
709 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
710 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
711 $column_data{AP_paid} = "<th>" . $locale->text('Account') . "</th>";
712 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
713 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
718 map { print "$column_data{$_}\n" } @column_index;
726 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
727 for $i (1 .. $form->{paidaccounts}) {
733 $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
734 $form->{"selectAP_paid_$i"} =~
735 s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
737 $totalpaid += $form->{"paid_$i"};
740 if ($form->{"paid_$i"}) {
742 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
744 $form->{"exchangerate_$i"} =
745 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
747 $exchangerate = qq| |;
748 if ($form->{currency} ne $form->{defaultcurrency}) {
749 if ($form->{"forex_$i"}) {
751 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
754 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
758 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
761 $column_data{"paid_$i"} =
762 qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
763 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
764 $column_data{"AP_paid_$i"} =
765 qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;
766 $column_data{"datepaid_$i"} =
767 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)\">
768 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
769 $column_data{"source_$i"} =
770 qq|<td align=center><input name="source_$i" size=11 value=$form->{"source_$i"}></td>|;
771 $column_data{"memo_$i"} =
772 qq|<td align=center><input name="memo_$i" size=11 value=$form->{"memo_$i"}></td>|;
774 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
779 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
782 my $paid_missing = $form->{oldinvtotal} - $totalpaid;
788 <td align="center">| . $locale->text('Total') . qq|</td>
789 <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
794 <td align="center">| . $locale->text('Missing amount') . qq|</td>
795 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
798 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
799 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
800 <input type=hidden name=selectAP_paid value="$form->{selectAP_paid}">
805 <td><hr size=3 noshade></td>
811 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
812 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
814 print qq|<input class=submit type=submit name=action id=update_button value="|
815 . $locale->text('Update') . qq|">
819 my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ap");
821 print qq|<input class=submit type=submit name=action value="|
822 . $locale->text('Post Payment') . qq|">
824 print qq|<input class=submit type=submit name=action value="|
825 . $locale->text('Storno') . qq|">
827 if ($form->{radier}) {
829 <input class=submit type=submit name=action value="|
830 . $locale->text('Delete') . qq|">
833 print qq|<input class=submit type=submit name=action value="|
834 . $locale->text('Use As Template') . qq|">
835 <input type="button" class="submit" onclick="follow_up_window()" value="|
836 . $locale->text('Follow-Up')
842 if (!$form->{id} && ($invdate > $closedto)) {
843 print qq| <input class=submit type=submit name=action value="|
844 . $locale->text('Post') . qq|"> | .
845 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
846 '-class' => 'submit'));
849 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers);
850 $form->hide_form(qw(rowcount callback draft_id draft_description));
852 # button for saving history
853 if($form->{id} ne "") {
855 <input type="button" class="submit" onclick="set_history_window(|
857 . qq|);" name="history" id="history" value="|
858 . $locale->text('history')
861 # /button for saving history
862 # mark_as_paid button
863 if($form->{id} ne "") {
864 print qq| <input type="submit" class="submit" name="action" value="|
865 . $locale->text('mark as paid') . qq|">|;
867 # /mark_as_paid button
874 $lxdebug->leave_sub();
878 $lxdebug->enter_sub();
880 $auth->assert('vendor_invoice_edit');
882 &mark_as_paid_common(\%myconfig,"ap");
884 $lxdebug->leave_sub();
888 $lxdebug->enter_sub();
890 $auth->assert('vendor_invoice_edit');
892 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
896 $form->{exchangerate} = $exchangerate if
897 $form->{forex} = $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'sell');
899 for $i (1 .. $form->{paidaccounts}) {
900 next unless $form->{"paid_$i"};
901 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
902 $form->{"exchangerate_$i"} = $exchangerate if
903 $form->{"forex_$i"} = $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell');
906 $i = $form->{rowcount};
907 $exchangerate = ($form->{exchangerate} * 1) || 1;
909 if ( ($form->{"partnumber_$i"} eq "")
910 && ($form->{"description_$i"} eq "")
911 && ($form->{"partsgroup_$i"} eq "")) {
912 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
917 IR->retrieve_item(\%myconfig, \%$form);
919 my $rows = scalar @{ $form->{item_list} };
922 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
931 # override sellprice if there is one entered
932 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
934 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
935 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
937 $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
939 ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
940 $decimalplaces = max 2, length $1;
943 $form->{"sellprice_$i"} = $sellprice;
945 # if there is an exchange rate adjust sellprice
946 $form->{"sellprice_$i"} /= $exchangerate;
949 $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
950 $form->{creditremaining} -= $amount;
951 $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
952 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
959 # ok, so this is a new part
960 # ask if it is a part or service item
962 if ( $form->{"partsgroup_$i"}
963 && ($form->{"partsnumber_$i"} eq "")
964 && ($form->{"description_$i"} eq "")) {
966 $form->{"discount_$i"} = "";
970 $form->{"id_$i"} = 0;
975 $lxdebug->leave_sub();
979 $lxdebug->enter_sub();
981 $auth->assert('vendor_invoice_edit');
983 if ($form->{storno}) {
984 $form->error($locale->text('Cannot storno storno invoice!'));
987 if (IS->has_storno(\%myconfig, $form, "ap")) {
988 $form->error($locale->text("Invoice has already been storno'd!"));
991 my $employee_id = $form->{employee_id};
996 # Payments must not be recorded for the new storno invoice.
997 $form->{paidaccounts} = 0;
998 map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
1000 # saving the history
1001 if(!exists $form->{addition} && $form->{id} ne "") {
1002 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1003 $form->{addition} = "CANCELED";
1004 $form->save_history($form->dbconnect(\%myconfig));
1006 # /saving the history
1008 $form->{storno_id} = $form->{id};
1009 $form->{storno} = 1;
1011 $form->{invnumber} = "Storno zu " . $form->{invnumber};
1012 $form->{rowcount}++;
1013 $form->{employee_id} = $employee_id;
1015 $lxdebug->leave_sub();
1019 sub use_as_template {
1020 $lxdebug->enter_sub();
1022 $auth->assert('vendor_invoice_edit');
1024 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);
1025 $form->{paidaccounts} = 1;
1026 $form->{rowcount}--;
1027 $form->{invdate} = $form->current_date(\%myconfig);
1030 $lxdebug->leave_sub();
1034 $lxdebug->enter_sub();
1036 $auth->assert('vendor_invoice_edit');
1038 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1039 for $i (1 .. $form->{paidaccounts}) {
1040 if ($form->{"paid_$i"}) {
1041 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1043 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1045 $form->error($locale->text('Cannot post payment for a closed period!'))
1046 if ($datepaid <= $closedto);
1048 if ($form->{currency} ne $form->{defaultcurrency}) {
1049 $form->{"exchangerate_$i"} = $form->{exchangerate}
1050 if ($invdate == $datepaid);
1051 $form->isblank("exchangerate_$i",
1052 $locale->text('Exchangerate for payment missing!'));
1057 ($form->{AP}) = split /--/, $form->{AP};
1058 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1059 if (IR->post_payment(\%myconfig, \%$form)){
1060 if (!exists $form->{addition} && $form->{id} ne "") {
1061 # saving the history
1062 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1063 $form->{addition} = "PAYMENT POSTED";
1064 $form->{what_done} = $form->{currency} . qq| | . $form->{paid} . qq| | . $locale->text("POSTED");
1065 $form->save_history($form->dbconnect(\%myconfig));
1066 # /saving the history
1069 $form->redirect($locale->text('Payment posted!'));
1072 $form->error($locale->text('Cannot post payment!'));
1074 $lxdebug->leave_sub();
1078 $lxdebug->enter_sub();
1080 $auth->assert('vendor_invoice_edit');
1082 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1084 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1085 $form->isblank("vendor", $locale->text('Vendor missing!'));
1087 $form->{invnumber} =~ s/^\s*//g;
1088 $form->{invnumber} =~ s/\s*$//g;
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};
1127 $form->{storno} = 0;
1129 $form->{id} = 0 if $form->{postasnew};
1133 if (IR->post_invoice(\%myconfig, \%$form)){
1134 # saving the history
1135 if(!exists $form->{addition} && $form->{id} ne "") {
1136 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1137 $form->{addition} = "POSTED";
1138 #$form->{what_done} = $locale->text("Rechnungsnummer") . qq| | . $form->{invnumber};
1139 $form->save_history($form->dbconnect(\%myconfig));
1141 # /saving the history
1142 remove_draft() if $form->{remove_draft};
1143 $form->redirect( $locale->text('Invoice')
1144 . " $form->{invnumber} "
1145 . $locale->text('posted!'));
1147 $form->error($locale->text('Cannot post invoice!'));
1149 $lxdebug->leave_sub();
1153 $lxdebug->enter_sub();
1155 $auth->assert('vendor_invoice_edit');
1161 <form method=post action=$form->{script}>
1164 # delete action variable
1165 map { delete $form->{$_} } qw(action header);
1167 foreach $key (keys %$form) {
1168 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1169 $form->{$key} =~ s/\"/"/g;
1170 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1174 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1177 . $locale->text('Are you sure you want to delete Invoice Number')
1178 . qq| $form->{invnumber}</h4>
1180 <input name=action class=submit type=submit value="|
1181 . $locale->text('Yes') . qq|">
1185 $lxdebug->leave_sub();
1189 $lxdebug->enter_sub();
1191 $auth->assert('vendor_invoice_edit');
1193 if (IR->delete_invoice(\%myconfig, \%$form)) {
1194 # saving the history
1195 if(!exists $form->{addition}) {
1196 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1197 $form->{addition} = "DELETED";
1198 $form->save_history($form->dbconnect(\%myconfig));
1200 # /saving the history
1201 $form->redirect($locale->text('Invoice deleted!'));
1203 $form->error($locale->text('Cannot delete invoice!'));
1205 $lxdebug->leave_sub();