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";
53 $main::lxdebug->enter_sub();
55 my $form = $main::form;
56 my $locale = $main::locale;
58 $main::auth->assert('vendor_invoice_edit');
60 return $main::lxdebug->leave_sub() if (load_draft_maybe());
62 $form->{title} = $locale->text('Add Vendor Invoice');
68 $main::lxdebug->leave_sub();
72 $main::lxdebug->enter_sub();
74 my $form = $main::form;
75 my $locale = $main::locale;
77 $main::auth->assert('vendor_invoice_edit');
80 $form->{javascript} = qq|<script type=text/javascript src=js/show_history.js></script>|;
81 #/show hhistory button
83 $form->{title} = $locale->text('Edit Vendor Invoice');
89 $main::lxdebug->leave_sub();
93 $main::lxdebug->enter_sub();
95 my $form = $main::form;
96 my %myconfig = %main::myconfig;
98 $main::auth->assert('vendor_invoice_edit');
101 $form->{webdav} = $main::webdav;
102 $form->{jsscript} = 1;
104 $form->create_links("AP", \%myconfig, "vendor");
106 #quote all_vendor Bug 133
107 foreach my $ref (@{ $form->{all_vendor} }) {
108 $ref->{name} = $form->quote($ref->{name});
111 if ($form->{all_vendor}) {
112 unless ($form->{vendor_id}) {
113 $form->{vendor_id} = $form->{all_vendor}->[0]->{id};
117 my ($payment_id, $language_id, $taxzone_id);
118 if ($form->{payment_id}) {
119 $payment_id = $form->{payment_id};
121 if ($form->{language_id}) {
122 $language_id = $form->{language_id};
124 if ($form->{taxzone_id}) {
125 $taxzone_id = $form->{taxzone_id};
128 my $cp_id = $form->{cp_id};
129 IR->get_vendor(\%myconfig, \%$form);
130 IR->retrieve_invoice(\%myconfig, \%$form);
131 $form->{cp_id} = $cp_id;
134 $form->{payment_id} = $payment_id;
137 $form->{language_id} = $language_id;
140 $form->{taxzone_id} = $taxzone_id;
143 my @curr = split(/:/, $form->{currencies}); #seems to be missing
144 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
146 $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
149 if ($form->{all_departments}) {
150 $form->{selectdepartment} = "<option>\n";
151 $form->{department} = "$form->{department}--$form->{department_id}";
154 $form->{selectdepartment} .=
155 "<option>$_->{description}--$_->{id}\n"
156 } (@{ $form->{all_departments} });
160 $form->{forex} = $form->{exchangerate};
161 my $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
163 foreach my $key (keys %{ $form->{AP_links} }) {
165 foreach my $ref (@{ $form->{AP_links}{$key} }) {
166 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
169 next unless $form->{acc_trans}{$key};
171 if ($key eq "AP_paid") {
172 for my $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
173 $form->{"AP_paid_$i"} =
174 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
177 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount};
178 $form->{"datepaid_$i"} =
179 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
180 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
181 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
182 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
183 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
185 $form->{paidaccounts} = $i;
189 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
194 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
196 $form->{AP} = $form->{AP_1} unless $form->{id};
199 ($form->datetonum($form->{invdate}, \%myconfig) <=
200 $form->datetonum($form->{closedto}, \%myconfig));
202 $main::lxdebug->leave_sub();
205 sub prepare_invoice {
206 $main::lxdebug->enter_sub();
208 my $form = $main::form;
209 my %myconfig = %main::myconfig;
211 $main::auth->assert('vendor_invoice_edit');
215 map { $form->{$_} =~ s/\"/"/g } qw(invnumber ordnumber quonumber);
218 foreach my $ref (@{ $form->{invoice_details} }) {
220 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
222 my ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
224 my $decimalplaces = ($dec > 2) ? $dec : 2;
226 $form->{"sellprice_$i"} =
227 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
230 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
231 $dec_qty = length $dec_qty;
234 $form->format_amount(\%myconfig, ($form->{"qty_$i"} * -1), $dec_qty);
236 $form->{rowcount} = $i;
240 $main::lxdebug->leave_sub();
244 $main::lxdebug->enter_sub();
246 my $form = $main::form;
247 my %myconfig = %main::myconfig;
248 my $locale = $main::locale;
249 my $cgi = $main::cgi;
251 $main::auth->assert('vendor_invoice_edit');
253 push @{ $form->{AJAX} }, CGI::Ajax->new('set_duedate_vendor' => "$form->{script}?action=set_duedate_vendor");
255 # set option selected
256 foreach my $item (qw(AP vendor currency department)) {
257 $form->{"select$item"} =~ s/ selected//;
258 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
261 $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
262 $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
263 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
264 $form->{radier} = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
265 $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
266 $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
267 $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
269 my $exchangerate = "";
270 if ($form->{currency} ne $form->{defaultcurrency}) {
271 if ($form->{forex}) {
272 $exchangerate .= qq| <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
273 <td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>\n|;
275 $exchangerate .= qq| <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
276 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>\n|;
279 $exchangerate .= qq| <input type=hidden name=forex value=$form->{forex}>\n|;
281 my @old_project_ids = ($form->{"globalproject_id"});
282 map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"};
284 $form->get_lists("contacts" => "ALL_CONTACTS",
285 "projects" => { "key" => "ALL_PROJECTS",
287 "old_id" => \@old_project_ids },
288 "taxzones" => "ALL_TAXZONES",
289 "employees" => "ALL_SALESMEN",
290 "currencies" => "ALL_CURRENCIES",
291 "vendors" => "ALL_VENDORS",
292 "price_factors" => "ALL_PRICE_FACTORS");
295 my @values = (undef);
296 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
297 push(@values, $item->{"cp_id"});
298 $labels{$item->{"cp_id"}} = $item->{"cp_name"} . ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
302 if (scalar @values > 1) {
305 <th align="right">| . $locale->text('Contact Person') . qq|</th>
306 <td>| . NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
307 '-labels' => \%labels, '-default' => $form->{"cp_id"})) . qq|
314 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
315 push(@values, $item->{"id"});
316 $labels{$item->{"id"}} = $item->{"projectnumber"};
318 my $globalprojectnumber = NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values, '-labels' => \%labels,
319 '-default' => $form->{"globalproject_id"}));
324 foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
325 push(@values, $item);
326 $labels{$item} = $item;
329 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
331 if (scalar @values) {
334 <th align="right">| . $locale->text('Currency') . qq|</th>
335 <td>| . NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
336 '-values' => \@values, '-labels' => \%labels)) . qq|
343 foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
344 push(@values, $item->{"id"});
345 $labels{$item->{"id"}} = $item->{"name"};
349 <th align="right">| . $locale->text('Employee') . qq|</th>
350 <td>| . NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
351 '-values' => \@values, '-labels' => \%labels)) . qq|
357 foreach my $item (@{ $form->{"ALL_VENDORS"} }) {
358 push(@values, $item->{name}.qq|--|.$item->{"id"});
359 $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
362 $form->{selectvendor} = ($myconfig{vclimit} > scalar(@values));
365 <th align="right">| . $locale->text('Vendor') . qq|</th>
367 (($myconfig{vclimit} <= scalar(@values))
368 ? qq|<input type="text" value="| . H($form->{vendor}) . qq|" name="vendor">|
369 : (NTI($cgi->popup_menu('-name' => 'vendor', '-default' => $form->{oldvendor},
370 '-onChange' => 'document.getElementById(\'update_button\').click();',
371 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq|
372 <input type="button" value="| . $locale->text('Details (one letter abbreviation)') . qq|" onclick="show_vc_details('vendor')">
377 foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
378 push(@values, $item->{"id"});
379 $labels{$item->{"id"}} = $item->{"description"};
383 if (!$form->{"id"}) {
386 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
387 <td>| . NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
388 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')) . qq|
394 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
396 <input type="hidden" name="taxzone_id" value="| . H($form->{"taxzone_id"}) . qq|">
397 | . H($labels{$form->{"taxzone_id"}}) . qq|
404 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
405 <td colspan="3"><select name="department" style="width: 250px">$form->{selectdepartment}</select>
406 <input type="hidden" name="selectdepartment" value="$form->{selectdepartment}">
408 </tr>\n| if $form->{selectdepartment};
410 my $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
412 # use JavaScript Calendar or not
413 $form->{jsscript} = 1;
418 <input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\"
419 onChange="if (this.value) set_duedate_vendor(['invdate__' + this.value, 'old_duedate__' + document.getElementsByName('duedate')[0].value, 'vendor_id__' + document.getElementsByName('vendor_id')[0].value],['duedate'])">
420 <input type=button name=invdate id="trigger1" value="?">
423 #, 'old_duedate__'' + document.getElementsByName('duedate')[0].value, 'vendor_id__' + document.getElementsByName('vendor_id')[0].value],['duedate'])">
425 <td width="13" nowrap>
426 <input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\">
427 <input type=button name=duedate id="trigger2" value=| . $locale->text('button') . qq|>
432 Form->write_trigger(\%myconfig, "2",
433 "invdate", "BL", "trigger1",
434 "duedate", "BL", "trigger2");
436 my $follow_up_vc = $form->{vendor};
437 $follow_up_vc =~ s/--\d*\s*$//;
438 my $follow_up_trans_info = "$form->{invnumber} ($follow_up_vc)";
440 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
441 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
442 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
443 $form->{javascript} .= qq|<script type="text/javascript" src="js/follow_up.js"></script>|;
445 $jsscript .= $form->write_trigger(\%myconfig, 2, "orddate", "BL", "trigger_orddate", "quodate", "BL", "trigger_quodate");
448 my $onload = qq|focus()|;
449 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
450 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
452 <body onLoad="$onload">
453 <script type="text/javascript" src="js/common.js"></script>
454 <form method="post" action="ir.pl" name="Form">
457 $form->hide_form(qw(id title vc type level creditlimit creditremaining closedto locked shippted storno storno_id
458 max_dunning_level dunning_amount vendor_id oldvendor selectvendor taxaccounts
459 fxgain_accno fxloss_accno taxpart taxservice cursor_fokus
460 convert_from_oe_ids convert_from_do_ids),
461 map { $_.'_rate', $_.'_description' } split / /, $form->{taxaccounts} );
463 print qq|<p>$form->{saved_message}</p>| if $form->{saved_message};
467 <div class="listtop" width="100%">$form->{title}</div>
476 <td align="right">| . $locale->text('Credit Limit') . qq|</td>
477 <td>$form->{creditlimit}; | . $locale->text('Remaining') . qq| <span class="plus$n">$form->{creditremaining}</span></td>
480 <th align="right">| . $locale->text('Record in') . qq|</th>
481 <td colspan="3"><select name="AP" style="width: 250px">$form->{selectAP}</select></td>
482 <input type="hidden" name="selectAP" value="$form->{selectAP}">
496 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
497 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
500 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
504 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
508 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
509 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
510 <input type=hidden name=quonumber value="$form->{quonumber}">
513 <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
514 <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|" onBlur=\"check_right_date_format(this)\">
515 <input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
518 <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
519 <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|" onBlur=\"check_right_date_format(this)\">
520 <input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
523 <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
524 <td>$globalprojectnumber</td>
535 <input type=hidden name=webdav value=$main::webdav>
538 foreach my $item (split / /, $form->{taxaccounts}) {
540 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
541 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
545 $main::lxdebug->leave_sub();
549 $main::lxdebug->enter_sub();
551 my $form = $main::form;
552 my %myconfig = %main::myconfig;
553 my $locale = $main::locale;
554 my $cgi = $main::cgi;
556 $main::auth->assert('vendor_invoice_edit');
558 $form->{invtotal} = $form->{invsubtotal};
560 my ($rows, $introws);
561 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
564 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
567 $rows = ($rows > $introws) ? $rows : $introws;
569 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
571 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
573 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
575 my $taxincluded = "";
576 if ($form->{taxaccounts}) {
578 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
579 . $locale->text('Tax Included') . qq|</b>
583 my ($tax, $subtotal);
584 if (!$form->{taxincluded}) {
586 foreach my $item (split / /, $form->{taxaccounts}) {
587 if ($form->{"${item}_base"}) {
588 $form->{invtotal} += $form->{"${item}_total"} =
590 $form->{"${item}_base"} * $form->{"${item}_rate"},
592 $form->{"${item}_total"} =
593 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
597 <th align=right>$form->{"${item}_description"} |
598 . $form->{"${item}_rate"} * 100 .qq|%</th>
599 <td align=right>$form->{"${item}_total"}</td>
605 $form->{invsubtotal} =
606 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
610 <th align=right>| . $locale->text('Subtotal') . qq|</th>
611 <td align=right>$form->{invsubtotal}</td>
617 if ($form->{taxincluded}) {
618 foreach my $item (split / /, $form->{taxaccounts}) {
619 if ($form->{"${item}_base"}) {
620 $form->{"${item}_total"} =
622 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
623 (1 + $form->{"${item}_rate"})
626 $form->{"${item}_base"} =
627 $form->round_amount($form->{"${item}_base"}, 2);
628 $form->{"${item}_netto"} =
630 ($form->{"${item}_base"} - $form->{"${item}_total"}),
632 $form->{"${item}_netto"} =
633 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
634 $form->{"${item}_total"} =
635 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
639 <th align=right>Enthaltene $form->{"${item}_description"} |
640 . $form->{"${item}_rate"} * 100 .qq|%</th>
641 <td align=right>$form->{"${item}_total"}</td>
644 <th align=right>Nettobetrag</th>
645 <td align=right>$form->{"${item}_netto"}</td>
653 $form->{oldinvtotal} = $form->{invtotal};
655 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
657 my $follow_ups_block;
659 my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
661 if (@{ $follow_ups} ) {
662 my $num_due = sum map { $_->{due} * 1 } @{ $follow_ups };
663 $follow_ups_block = qq|
665 <td colspan="2">| . $locale->text("There are #1 unfinished follow-ups of which #2 are due.", scalar @{ $follow_ups }, $num_due) . qq|</td>
674 <td colspan=$colspan>
675 <table cellspacing="0">
680 <th align=left>| . $locale->text('Notes') . qq|</th>
681 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
690 <td colspan=2 align=right width=100%>
697 <th align=right>| . $locale->text('Total') . qq|</th>
698 <td align=right>$form->{invtotal}</td>
711 <td><hr size=3 noshade></td>
714 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
717 <td align=left width=30%><b>Dateiname</b></td>
718 <td align=left width=70%><b>Webdavlink</b></td>
720 foreach my $file (@{ $form->{WEBDAV} }) {
723 <td align="left">$file->{name}</td>
724 <td align="left"><a href="$file->{link}">$file->{type}</a></td>
737 <td colspan=$colspan>
740 <th colspan=6 class=listheading>| . $locale->text('Payments') . qq|</th>
745 if ($form->{currency} eq $form->{defaultcurrency}) {
746 @column_index = qw(datepaid source memo paid AP_paid);
748 @column_index = qw(datepaid source memo paid exchangerate AP_paid);
752 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
753 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
754 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
755 $column_data{AP_paid} = "<th>" . $locale->text('Account') . "</th>";
756 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
757 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
762 map { print "$column_data{$_}\n" } @column_index;
770 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
771 for my $i (1 .. $form->{paidaccounts}) {
777 $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
778 $form->{"selectAP_paid_$i"} =~
779 s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
781 $totalpaid += $form->{"paid_$i"};
784 if ($form->{"paid_$i"}) {
786 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
788 $form->{"exchangerate_$i"} =
789 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
791 my $exchangerate = qq| |;
792 if ($form->{currency} ne $form->{defaultcurrency}) {
793 if ($form->{"forex_$i"}) {
795 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
798 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
802 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
805 $column_data{"paid_$i"} =
806 qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
807 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
808 $column_data{"AP_paid_$i"} =
809 qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;
810 $column_data{"datepaid_$i"} =
811 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)\">
812 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
813 $column_data{"source_$i"} =
814 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
815 $column_data{"memo_$i"} =
816 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
818 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
823 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
826 my $paid_missing = $form->{oldinvtotal} - $totalpaid;
832 <td align="center">| . $locale->text('Total') . qq|</td>
833 <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
838 <td align="center">| . $locale->text('Missing amount') . qq|</td>
839 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
842 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
843 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
844 <input type=hidden name=selectAP_paid value="$form->{selectAP_paid}">
849 <td><hr size=3 noshade></td>
855 my $invdate = $form->datetonum($form->{invdate}, \%myconfig);
856 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
858 print qq|<input class=submit type=submit name=action id=update_button value="|
859 . $locale->text('Update') . qq|">
863 my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ap") && (($totalpaid == 0) || ($totalpaid eq ""));
865 print qq|<input class=submit type=submit name=action value="|
866 . $locale->text('Post Payment') . qq|">
868 print qq|<input class=submit type=submit name=action value="|
869 . $locale->text('Storno') . qq|">
871 if ($form->{radier}) {
873 <input class=submit type=submit name=action value="|
874 . $locale->text('Delete') . qq|">
877 print qq|<input class=submit type=submit name=action value="|
878 . $locale->text('Use As Template') . qq|">
879 <input type="button" class="submit" onclick="follow_up_window()" value="|
880 . $locale->text('Follow-Up')
886 if (!$form->{id} && ($invdate > $closedto)) {
887 print qq| <input class=submit type=submit name=action value="|
888 . $locale->text('Post') . qq|"> | .
889 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
890 '-class' => 'submit'));
893 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers);
894 $form->hide_form(qw(rowcount callback draft_id draft_description vendor_discount));
896 # button for saving history
897 if($form->{id} ne "") {
899 <input type="button" class="submit" onclick="set_history_window(|
901 . qq|);" name="history" id="history" value="|
902 . $locale->text('history')
905 # /button for saving history
906 # mark_as_paid button
907 if($form->{id} ne "") {
908 print qq| <input type="submit" class="submit" name="action" value="|
909 . $locale->text('mark as paid') . qq|">|;
911 # /mark_as_paid button
917 $main::lxdebug->leave_sub();
921 $main::lxdebug->enter_sub();
923 my $form = $main::form;
924 my %myconfig = %main::myconfig;
926 $main::auth->assert('vendor_invoice_edit');
928 &mark_as_paid_common(\%myconfig,"ap");
930 $main::lxdebug->leave_sub();
934 $main::lxdebug->enter_sub();
936 my $form = $main::form;
937 my %myconfig = %main::myconfig;
939 $main::auth->assert('vendor_invoice_edit');
941 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
943 &check_name('vendor');
945 $form->{forex} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'sell');
946 $form->{exchangerate} = $form->{forex} if $form->{forex};
948 for my $i (1 .. $form->{paidaccounts}) {
949 next unless $form->{"paid_$i"};
950 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
951 $form->{"forex_$i"} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell');
952 $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
955 my $i = $form->{rowcount};
956 my $exchangerate = ($form->{exchangerate} * 1) || 1;
958 if ( ($form->{"partnumber_$i"} eq "")
959 && ($form->{"description_$i"} eq "")
960 && ($form->{"partsgroup_$i"} eq "")) {
961 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
966 IR->retrieve_item(\%myconfig, \%$form);
968 my $rows = scalar @{ $form->{item_list} };
971 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
980 # override sellprice if there is one entered
981 my $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
983 # ergaenzung fuer bug 736 Lieferanten-Rabatt auch in Einkaufsrechnungen vorbelegen jb
984 $form->{"discount_$i"} = $form->format_amount(\%myconfig,
985 $form->{vendor_discount} * 100 );
986 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
987 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
989 $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
991 ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
992 my $dec_qty = length $1;
993 my $decimalplaces = max 2, $dec_qty;
996 $form->{"sellprice_$i"} = $sellprice;
998 # if there is an exchange rate adjust sellprice
999 $form->{"sellprice_$i"} /= $exchangerate;
1002 my $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
1003 $form->{creditremaining} -= $amount;
1004 $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
1005 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
1012 # ok, so this is a new part
1013 # ask if it is a part or service item
1015 if ( $form->{"partsgroup_$i"}
1016 && ($form->{"partsnumber_$i"} eq "")
1017 && ($form->{"description_$i"} eq "")) {
1018 $form->{rowcount}--;
1019 $form->{"discount_$i"} = "";
1023 $form->{"id_$i"} = 0;
1028 $main::lxdebug->leave_sub();
1032 $main::lxdebug->enter_sub();
1034 my $form = $main::form;
1035 my %myconfig = %main::myconfig;
1036 my $locale = $main::locale;
1038 $main::auth->assert('vendor_invoice_edit');
1040 if ($form->{storno}) {
1041 $form->error($locale->text('Cannot storno storno invoice!'));
1044 if (IS->has_storno(\%myconfig, $form, "ap")) {
1045 $form->error($locale->text("Invoice has already been storno'd!"));
1048 my $employee_id = $form->{employee_id};
1053 # Payments must not be recorded for the new storno invoice.
1054 $form->{paidaccounts} = 0;
1055 map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
1057 # saving the history
1058 if(!exists $form->{addition} && $form->{id} ne "") {
1059 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1060 $form->{addition} = "CANCELED";
1061 $form->save_history($form->dbconnect(\%myconfig));
1063 # /saving the history
1065 $form->{storno_id} = $form->{id};
1066 $form->{storno} = 1;
1068 $form->{invnumber} = "Storno zu " . $form->{invnumber};
1069 $form->{rowcount}++;
1070 $form->{employee_id} = $employee_id;
1072 $main::lxdebug->leave_sub();
1076 sub use_as_template {
1077 $main::lxdebug->enter_sub();
1079 my $form = $main::form;
1080 my %myconfig = %main::myconfig;
1082 $main::auth->assert('vendor_invoice_edit');
1084 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);
1085 $form->{paidaccounts} = 1;
1086 $form->{rowcount}--;
1087 $form->{invdate} = $form->current_date(\%myconfig);
1090 $main::lxdebug->leave_sub();
1094 $main::lxdebug->enter_sub();
1096 my $form = $main::form;
1097 my %myconfig = %main::myconfig;
1098 my $locale = $main::locale;
1100 $main::auth->assert('vendor_invoice_edit');
1102 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1103 for my $i (1 .. $form->{paidaccounts}) {
1104 if ($form->{"paid_$i"}) {
1105 my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1107 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1109 $form->error($locale->text('Cannot post payment for a closed period!'))
1110 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
1112 if ($form->{currency} ne $form->{defaultcurrency}) {
1113 # $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid); # invdate isn't set here
1114 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
1119 ($form->{AP}) = split /--/, $form->{AP};
1120 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1121 if (IR->post_payment(\%myconfig, \%$form)){
1122 if (!exists $form->{addition} && $form->{id} ne "") {
1123 # saving the history
1124 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1125 $form->{addition} = "PAYMENT POSTED";
1126 $form->{what_done} = $form->{currency} . qq| | . $form->{paid} . qq| | . $locale->text("POSTED");
1127 $form->save_history($form->dbconnect(\%myconfig));
1128 # /saving the history
1131 $form->redirect($locale->text('Payment posted!'));
1134 $form->error($locale->text('Cannot post payment!'));
1136 $main::lxdebug->leave_sub();
1140 $main::lxdebug->enter_sub();
1142 my $form = $main::form;
1143 my %myconfig = %main::myconfig;
1144 my $locale = $main::locale;
1146 $main::auth->assert('vendor_invoice_edit');
1148 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1150 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1151 $form->isblank("vendor", $locale->text('Vendor missing!'));
1152 $form->isblank("invnumber", $locale->text('Invnumber missing!'));
1154 $form->{invnumber} =~ s/^\s*//g;
1155 $form->{invnumber} =~ s/\s*$//g;
1157 # if the vendor changed get new values
1158 if (&check_name('vendor')) {
1165 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1166 my $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1167 my $i = $form->{rowcount};
1169 $form->error($locale->text('Cannot post invoice for a closed period!'))
1170 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
1172 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1173 if ($form->{currency} ne $form->{defaultcurrency});
1175 for $i (1 .. $form->{paidaccounts}) {
1176 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1177 my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1179 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1181 $form->error($locale->text('Cannot post payment for a closed period!'))
1182 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
1184 if ($form->{currency} ne $form->{defaultcurrency}) {
1185 $form->{"exchangerate_$i"} = $form->{exchangerate}
1186 if ($invdate == $datepaid);
1187 $form->isblank("exchangerate_$i",
1188 $locale->text('Exchangerate for payment missing!'));
1193 ($form->{AP}) = split /--/, $form->{AP};
1194 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1195 $form->{storno} ||= 0;
1197 $form->{id} = 0 if $form->{postasnew};
1201 if (IR->post_invoice(\%myconfig, \%$form)){
1202 # saving the history
1203 if(!exists $form->{addition} && $form->{id} ne "") {
1204 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1205 $form->{addition} = "POSTED";
1206 #$form->{what_done} = $locale->text("Rechnungsnummer") . qq| | . $form->{invnumber};
1207 $form->save_history($form->dbconnect(\%myconfig));
1209 # /saving the history
1210 remove_draft() if $form->{remove_draft};
1211 $form->redirect( $locale->text('Invoice')
1212 . " $form->{invnumber} "
1213 . $locale->text('posted!'));
1215 $form->error($locale->text('Cannot post invoice!'));
1217 $main::lxdebug->leave_sub();
1221 $main::lxdebug->enter_sub();
1223 my $form = $main::form;
1224 my $locale = $main::locale;
1226 $main::auth->assert('vendor_invoice_edit');
1232 <form method=post action=$form->{script}>
1235 # delete action variable
1236 map { delete $form->{$_} } qw(action header);
1238 foreach my $key (keys %$form) {
1239 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1240 $form->{$key} =~ s/\"/"/g;
1241 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1245 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1248 . $locale->text('Are you sure you want to delete Invoice Number')
1249 . qq| $form->{invnumber}</h4>
1251 <input name=action class=submit type=submit value="|
1252 . $locale->text('Yes') . qq|">
1256 $main::lxdebug->leave_sub();
1260 $main::lxdebug->enter_sub();
1262 my $form = $main::form;
1263 my %myconfig = %main::myconfig;
1264 my $locale = $main::locale;
1266 $main::auth->assert('vendor_invoice_edit');
1268 if (IR->delete_invoice(\%myconfig, \%$form)) {
1269 # saving the history
1270 if(!exists $form->{addition}) {
1271 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1272 $form->{addition} = "DELETED";
1273 $form->save_history($form->dbconnect(\%myconfig));
1275 # /saving the history
1276 $form->redirect($locale->text('Invoice deleted!'));
1278 $form->error($locale->text('Cannot delete invoice!'));
1280 $main::lxdebug->leave_sub();
1283 sub set_duedate_vendor {
1284 $main::lxdebug->enter_sub();
1286 my $form = $main::form;
1288 print $form->ajax_response_header(), IR->get_duedate('vendor_id' => $form->{vendor_id},
1289 'invdate' => $form->{invdate},
1290 'default' => $form->{old_duedate});
1292 $main::lxdebug->leave_sub();