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('Record 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');
100 $form->{vc} = 'vendor';
103 $form->{webdav} = $::lx_office_conf{features}->{webdav};
104 $form->{jsscript} = 1;
106 $form->create_links("AP", \%myconfig, "vendor");
108 #quote all_vendor Bug 133
109 foreach my $ref (@{ $form->{all_vendor} }) {
110 $ref->{name} = $form->quote($ref->{name});
113 if ($form->{all_vendor}) {
114 unless ($form->{vendor_id}) {
115 $form->{vendor_id} = $form->{all_vendor}->[0]->{id};
119 my ($payment_id, $language_id, $taxzone_id, $currency);
120 if ($form->{payment_id}) {
121 $payment_id = $form->{payment_id};
123 if ($form->{language_id}) {
124 $language_id = $form->{language_id};
126 if ($form->{taxzone_id}) {
127 $taxzone_id = $form->{taxzone_id};
129 if ($form->{currency}) {
130 $currency = $form->{currency};
133 my $cp_id = $form->{cp_id};
134 IR->get_vendor(\%myconfig, \%$form);
135 IR->retrieve_invoice(\%myconfig, \%$form);
136 $form->{cp_id} = $cp_id;
139 $form->{payment_id} = $payment_id;
142 $form->{language_id} = $language_id;
145 $form->{taxzone_id} = $taxzone_id;
148 $form->{currency} = $currency;
151 my @curr = split(/:/, $form->{currencies}); #seems to be missing
152 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
154 $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
156 # build vendor/customer drop down comatibility... don't ask
157 if (@{ $form->{"all_vendor"} || [] }) {
158 $form->{"selectvendor"} = 1;
159 $form->{vendor} = qq|$form->{vendor}--$form->{vendor_id}|;
163 if ($form->{all_departments}) {
164 $form->{selectdepartment} = "<option>\n";
165 $form->{department} = "$form->{department}--$form->{department_id}";
168 $form->{selectdepartment} .=
169 "<option>$_->{description}--$_->{id}\n"
170 } (@{ $form->{all_departments} || [] });
174 $form->{forex} = $form->{exchangerate};
175 my $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
177 foreach my $key (keys %{ $form->{AP_links} }) {
179 foreach my $ref (@{ $form->{AP_links}{$key} }) {
180 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}</option>";
183 next unless $form->{acc_trans}{$key};
185 if ($key eq "AP_paid") {
186 for my $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
187 $form->{"AP_paid_$i"} =
188 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
190 $form->{"acc_trans_id_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{acc_trans_id};
192 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount};
193 $form->{"datepaid_$i"} =
194 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
195 $form->{"gldate_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{gldate};
196 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
197 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
198 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
199 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
201 $form->{paidaccounts} = $i;
205 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
210 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
212 $form->{AP} = $form->{AP_1} unless $form->{id};
215 ($form->datetonum($form->{invdate}, \%myconfig) <=
216 $form->datetonum($form->{closedto}, \%myconfig));
218 $main::lxdebug->leave_sub();
221 sub prepare_invoice {
222 $main::lxdebug->enter_sub();
224 my $form = $main::form;
225 my %myconfig = %main::myconfig;
227 $main::auth->assert('vendor_invoice_edit');
231 map { $form->{$_} =~ s/\"/"/g } qw(invnumber ordnumber quonumber);
234 foreach my $ref (@{ $form->{invoice_details} }) {
236 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
237 # übernommen aus is.pl Fix für Bug 1642. Nebenwirkungen? jb 12.5.2011
238 # getestet: Lieferantenauftrag -> Rechnung i.O.
239 # Lieferantenauftrag -> Lieferschein -> Rechnung i.O.
240 # Werte: 20% (Lieferantenrabatt), 12,4% individuell und 0,4 individuell s.a.
241 # Screenshot zu Bug 1642
242 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
244 my ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
246 my $decimalplaces = ($dec > 2) ? $dec : 2;
248 $form->{"sellprice_$i"} =
249 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
252 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
253 $dec_qty = length $dec_qty;
256 $form->format_amount(\%myconfig, ($form->{"qty_$i"} * -1), $dec_qty);
258 $form->{rowcount} = $i;
262 $main::lxdebug->leave_sub();
266 $main::lxdebug->enter_sub();
268 my $form = $main::form;
269 my %myconfig = %main::myconfig;
270 my $locale = $main::locale;
271 my $cgi = $::request->{cgi};
273 $main::auth->assert('vendor_invoice_edit');
278 $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
279 $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
281 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
283 my @old_project_ids = ($form->{"globalproject_id"});
284 map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"};
286 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
288 "old_id" => \@old_project_ids },
289 "taxzones" => "ALL_TAXZONES",
290 "currencies" => "ALL_CURRENCIES",
291 "vendors" => "ALL_VENDORS",
292 "departments" => "all_departments",
293 "price_factors" => "ALL_PRICE_FACTORS");
295 $TMPL_VAR{ALL_EMPLOYEES} = SL::DB::Manager::Employee->get_all(query => [ or => [ id => $::form->{employee_id}, deleted => 0 ] ]);
296 $TMPL_VAR{ALL_CONTACTS} = SL::DB::Manager::Contact->get_all(query => [
298 cp_cv_id => $::form->{"$::form->{vc}_id"} * 1,
301 cp_id => $::form->{cp_id} * 1
305 $TMPL_VAR{department_labels} = sub { "$_[0]->{description}--$_[0]->{id}" };
308 $TMPL_VAR{vc_keys} = sub { "$_[0]->{name}--$_[0]->{id}" };
309 $TMPL_VAR{vclimit} = $myconfig{vclimit};
310 $TMPL_VAR{vc_select} = "customer_or_vendor_selection_window('vendor', '', 1, 0)";
311 push @custom_hiddens, "vendor_id";
312 push @custom_hiddens, "oldvendor";
313 push @custom_hiddens, "selectvendor";
315 # currencies and exchangerate
316 my @values = map { $_ } @{ $form->{ALL_CURRENCIES} };
317 my %labels = map { $_ => $_ } @{ $form->{ALL_CURRENCIES} };
318 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
319 # show_exchangerate is also later needed in another template
320 $form->{show_exchangerate} = $form->{currency} ne $form->{defaultcurrency};
321 $TMPL_VAR{currencies} = NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
322 '-values' => \@values, '-labels' => \%labels,
323 '-onchange' => "document.getElementById('update_button').click();"
324 )) if scalar @values;
325 push @custom_hiddens, "forex";
326 push @custom_hiddens, "exchangerate" if $form->{forex};
328 $TMPL_VAR{creditwarning} = ($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update};
329 $TMPL_VAR{is_credit_remaining_negativ} = $form->{creditremaining} =~ /-/;
331 $form->{fokus} = "invoice.vendor";
333 my $follow_up_vc = $form->{vendor};
334 $follow_up_vc =~ s/--\d*\s*$//;
335 $TMPL_VAR{vendor_name} = $follow_up_vc;
337 # set option selected
338 foreach my $item (qw(AP)) {
339 $form->{"select$item"} =~ s/ selected//;
340 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
343 $TMPL_VAR{is_type_credit_note} = $form->{type} eq "credit_note";
344 $TMPL_VAR{is_format_html} = $form->{format} eq 'html';
345 $TMPL_VAR{dateformat} = $myconfig{dateformat};
346 $TMPL_VAR{numberformat} = $myconfig{numberformat};
349 $TMPL_VAR{HIDDENS} = [qw(
350 id action type media format queued printed emailed title vc discount
351 title creditlimit creditremaining tradediscount business closedto locked shipped storno storno_id
352 max_dunning_level dunning_amount
353 shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax
354 shiptoemail shiptodepartment_1 shiptodepartment_2 message email subject cc bcc taxaccounts cursor_fokus
355 convert_from_do_ids convert_from_oe_ids
357 map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts}];
359 $form->{jsscript} = 1;
362 print $form->parse_html_template("ir/form_header", \%TMPL_VAR);
364 $main::lxdebug->leave_sub();
368 $main::lxdebug->enter_sub();
370 my $form = $main::form;
371 my %myconfig = %main::myconfig;
372 my $locale = $main::locale;
374 $main::auth->assert('vendor_invoice_edit');
376 $form->{invtotal} = $form->{invsubtotal};
377 $form->{oldinvtotal} = $form->{invtotal};
380 $form->{rows} = max 2,
381 $form->numtextrows($form->{notes}, 26, 8),
382 $form->numtextrows($form->{intnotes}, 35, 8);
385 # tax, total and subtotal calculations
386 my ($tax, $subtotal);
387 $form->{taxaccounts_array} = [ split / /, $form->{taxaccounts} ];
389 foreach my $item (@{ $form->{taxaccounts_array} }) {
390 if ($form->{"${item}_base"}) {
391 if ($form->{taxincluded}) {
392 $form->{"${item}_total"} = $form->round_amount( ($form->{"${item}_base"} * $form->{"${item}_rate"}
393 / (1 + $form->{"${item}_rate"})), 2);
394 $form->{"${item}_netto"} = $form->round_amount( ($form->{"${item}_base"} - $form->{"${item}_total"}), 2);
396 $form->{"${item}_total"} = $form->round_amount( $form->{"${item}_base"} * $form->{"${item}_rate"}, 2);
397 $form->{invtotal} += $form->{"${item}_total"};
404 $form->{follow_ups} = FU->follow_ups('trans_id' => $form->{id}) || [];
405 $form->{follow_ups_unfinished} = ( sum map { $_->{due} * 1 } @{ $form->{follow_ups} } ) || 0;
410 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
411 $form->{paid_indices} = [ 1 .. $form->{paidaccounts} ];
413 # Standard Konto für Umlaufvermögen
414 my $accno_arap = IS->get_standard_accno_current_assets(\%myconfig, \%$form);
416 for my $i (1 .. $form->{paidaccounts}) {
417 $form->{"changeable_$i"} = 1;
418 if ($::lx_office_conf{features}->{payments_changeable} == 0) {
420 $form->{"changeable_$i"} = ($form->{"acc_trans_id_$i"})? 0 : 1;
421 } elsif ($::lx_office_conf{features}->{payments_changeable} == 2) {
423 $form->{"changeable_$i"} = (($form->{"gldate_$i"} eq '') ||
424 ($form->current_date(\%myconfig) eq $form->{"gldate_$i"}));
427 $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
428 if (!$form->{"AP_paid_$i"}) {
429 $form->{"selectAP_paid_$i"} =~ s/option>$accno_arap--(.*?)>/option selected>$accno_arap--$1>/;
431 $form->{"selectAP_paid_$i"} =~ s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
434 $totalpaid += $form->{"paid_$i"};
437 print $form->parse_html_template('ir/form_footer', {
438 is_type_credit_note => ($form->{type} eq "credit_note"),
439 totalpaid => $totalpaid,
440 paid_missing => $form->{invtotal} - $totalpaid,
441 show_storno => $form->{id} && !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ap") && !$totalpaid,
442 show_delete => ($form->current_date(\%myconfig) eq $form->{gldate}),
444 ##print $form->parse_html_template('ir/_payments'); # parser
445 ##print $form->parse_html_template('webdav/_list'); # parser
447 $main::lxdebug->leave_sub();
451 $main::lxdebug->enter_sub();
453 my $form = $main::form;
454 my %myconfig = %main::myconfig;
456 $main::auth->assert('vendor_invoice_edit');
458 &mark_as_paid_common(\%myconfig,"ap");
460 $main::lxdebug->leave_sub();
464 $main::lxdebug->enter_sub();
466 my $form = $main::form;
467 my %myconfig = %main::myconfig;
469 $main::auth->assert('vendor_invoice_edit');
471 &check_name('vendor');
473 if (!$form->{forex}) { # read exchangerate from input field (not hidden)
474 $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate});
476 $form->{forex} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'sell');
477 $form->{exchangerate} = $form->{forex} if $form->{forex};
479 for my $i (1 .. $form->{paidaccounts}) {
480 next unless $form->{"paid_$i"};
481 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
482 $form->{"forex_$i"} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell');
483 $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
486 my $i = $form->{rowcount};
487 my $exchangerate = ($form->{exchangerate} * 1) || 1;
489 if ( ($form->{"partnumber_$i"} eq "")
490 && ($form->{"description_$i"} eq "")
491 && ($form->{"partsgroup_$i"} eq "")) {
492 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
497 IR->retrieve_item(\%myconfig, \%$form);
499 my $rows = scalar @{ $form->{item_list} };
502 $form->{"qty_$i"} = 1 unless $form->parse_amount(\%myconfig, $form->{"qty_$i"});
506 select_item(mode => 'IR');
511 # override sellprice if there is one entered
512 my $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
514 # ergaenzung fuer bug 736 Lieferanten-Rabatt auch in Einkaufsrechnungen vorbelegen jb
515 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{vendor_discount} * 100 );
516 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
517 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
519 $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
521 ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
522 my $dec_qty = length $1;
523 my $decimalplaces = max 2, $dec_qty;
526 $form->{"sellprice_$i"} = $sellprice;
528 # if there is an exchange rate adjust sellprice
529 $form->{"sellprice_$i"} /= $exchangerate;
532 my $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
533 $form->{creditremaining} -= $amount;
534 $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
535 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
542 # ok, so this is a new part
543 # ask if it is a part or service item
545 if ( $form->{"partsgroup_$i"}
546 && ($form->{"partsnumber_$i"} eq "")
547 && ($form->{"description_$i"} eq "")) {
549 $form->{"discount_$i"} = "";
553 $form->{"id_$i"} = 0;
558 $main::lxdebug->leave_sub();
562 $main::lxdebug->enter_sub();
564 my $form = $main::form;
565 my %myconfig = %main::myconfig;
566 my $locale = $main::locale;
568 $main::auth->assert('vendor_invoice_edit');
570 if ($form->{storno}) {
571 $form->error($locale->text('Cannot storno storno invoice!'));
574 if (IS->has_storno(\%myconfig, $form, "ap")) {
575 $form->error($locale->text("Invoice has already been storno'd!"));
578 my $employee_id = $form->{employee_id};
583 # Payments must not be recorded for the new storno invoice.
584 $form->{paidaccounts} = 0;
585 map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ gldate_ acc_trans_id_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
588 if(!exists $form->{addition} && $form->{id} ne "") {
589 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
590 $form->{addition} = "CANCELED";
593 # /saving the history
595 $form->{storno_id} = $form->{id};
598 $form->{invnumber} = "Storno zu " . $form->{invnumber};
600 $form->{employee_id} = $employee_id;
602 $main::lxdebug->leave_sub();
606 sub use_as_template {
607 $main::lxdebug->enter_sub();
609 my $form = $main::form;
610 my %myconfig = %main::myconfig;
612 $main::auth->assert('vendor_invoice_edit');
614 map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 gldate_1 acc_trans_id_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno);
615 $form->{paidaccounts} = 1;
617 $form->{invdate} = $form->current_date(\%myconfig);
620 $main::lxdebug->leave_sub();
624 $main::lxdebug->enter_sub();
626 my $form = $main::form;
627 my %myconfig = %main::myconfig;
628 my $locale = $main::locale;
630 $main::auth->assert('vendor_invoice_edit');
632 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
633 for my $i (1 .. $form->{paidaccounts}) {
634 if ($form->{"paid_$i"}) {
635 my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
637 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
639 $form->error($locale->text('Cannot post payment for a closed period!'))
640 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
642 if ($form->{currency} ne $form->{defaultcurrency}) {
643 # $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid); # invdate isn't set here
644 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
649 ($form->{AP}) = split /--/, $form->{AP};
650 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
651 if (IR->post_payment(\%myconfig, \%$form)){
652 if (!exists $form->{addition} && $form->{id} ne "") {
654 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
655 $form->{addition} = "PAYMENT POSTED";
656 $form->{what_done} = $form->{currency} . qq| | . $form->{paid} . qq| | . $locale->text("POSTED");
658 # /saving the history
661 $form->redirect($locale->text('Payment posted!'));
664 $form->error($locale->text('Cannot post payment!'));
666 $main::lxdebug->leave_sub();
670 my $form = $main::form;
672 my @dates = sort { $b->[1] cmp $a->[1] }
673 map { [ $_, $main::locale->reformat_date(\%main::myconfig, $_, 'yyyy-mm-dd') ] }
675 map { $form->{"datepaid_${_}"} }
676 (1..$form->{rowcount});
678 return @dates ? $dates[0]->[0] : undef;
683 $main::lxdebug->enter_sub();
685 my $form = $main::form;
686 my %myconfig = %main::myconfig;
687 my $locale = $main::locale;
689 $main::auth->assert('vendor_invoice_edit');
691 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
693 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
694 $form->isblank("vendor", $locale->text('Vendor missing!'));
695 $form->isblank("invnumber", $locale->text('Invnumber missing!'));
697 $form->{invnumber} =~ s/^\s*//g;
698 $form->{invnumber} =~ s/\s*$//g;
700 # if the vendor changed get new values
701 if (&check_name('vendor')) {
706 if ($myconfig{mandatory_departments} && !$form->{department_id}) {
707 $form->{saved_message} = $::locale->text('You have to specify a department.');
712 remove_emptied_rows();
715 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
716 my $invdate = $form->datetonum($form->{invdate}, \%myconfig);
717 my $max_datepaid = _max_datepaid();
719 $form->error($locale->text('Cannot post invoice for a closed period!')) if $max_datepaid && $form->date_closed($max_datepaid, \%myconfig);
721 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
722 if ($form->{currency} ne $form->{defaultcurrency});
725 for $i (1 .. $form->{paidaccounts}) {
726 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
727 my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
729 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
731 $form->error($locale->text('Cannot post payment for a closed period!'))
732 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
734 if ($form->{currency} ne $form->{defaultcurrency}) {
735 $form->{"exchangerate_$i"} = $form->{exchangerate}
736 if ($invdate == $datepaid);
737 $form->isblank("exchangerate_$i",
738 $locale->text('Exchangerate for payment missing!'));
743 ($form->{AP}) = split /--/, $form->{AP};
744 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
745 $form->{storno} ||= 0;
747 $form->{id} = 0 if $form->{postasnew};
751 if (IR->post_invoice(\%myconfig, \%$form)){
753 if(!exists $form->{addition} && $form->{id} ne "") {
754 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
755 $form->{addition} = "POSTED";
756 #$form->{what_done} = $locale->text("Rechnungsnummer") . qq| | . $form->{invnumber};
759 # /saving the history
760 remove_draft() if $form->{remove_draft};
761 $form->redirect( $locale->text('Invoice')
762 . " $form->{invnumber} "
763 . $locale->text('posted!'));
765 $form->error($locale->text('Cannot post invoice!'));
767 $main::lxdebug->leave_sub();
771 $main::lxdebug->enter_sub();
773 my $form = $main::form;
774 my $locale = $main::locale;
776 $main::auth->assert('vendor_invoice_edit');
782 <form method=post action=$form->{script}>
785 # delete action variable
786 map { delete $form->{$_} } qw(action header);
788 foreach my $key (keys %$form) {
789 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
790 $form->{$key} =~ s/\"/"/g;
791 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
795 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
798 . $locale->text('Are you sure you want to delete Invoice Number')
799 . qq| $form->{invnumber}</h4>
801 <input name=action class=submit type=submit value="|
802 . $locale->text('Yes') . qq|">
806 $main::lxdebug->leave_sub();
810 $main::lxdebug->enter_sub();
812 my $form = $main::form;
813 my %myconfig = %main::myconfig;
814 my $locale = $main::locale;
816 $main::auth->assert('vendor_invoice_edit');
818 if (IR->delete_invoice(\%myconfig, \%$form)) {
820 if(!exists $form->{addition}) {
821 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
822 $form->{addition} = "DELETED";
825 # /saving the history
826 $form->redirect($locale->text('Invoice deleted!'));
828 $form->error($locale->text('Cannot delete invoice!'));
830 $main::lxdebug->leave_sub();
833 sub get_duedate_vendor {
834 $::lxdebug->enter_sub;
836 my $result = IR->get_duedate(
837 vendor_id => $::form->{vendor_id},
838 invdate => $::form->{invdate},
839 default => $::form->{old_duedate},
842 print $::form->ajax_response_header, $result;
843 $::lxdebug->leave_sub;