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 #======================================================================
39 use List::Util qw(max sum);
41 require "bin/mozilla/io.pl";
42 require "bin/mozilla/invoice_io.pl";
43 require "bin/mozilla/arap.pl";
44 require "bin/mozilla/common.pl";
45 require "bin/mozilla/drafts.pl";
54 $main::lxdebug->enter_sub();
56 my $form = $main::form;
57 my $locale = $main::locale;
59 $main::auth->assert('vendor_invoice_edit');
61 return $main::lxdebug->leave_sub() if (load_draft_maybe());
63 $form->{title} = $locale->text('Record Vendor Invoice');
69 $main::lxdebug->leave_sub();
73 $main::lxdebug->enter_sub();
75 my $form = $main::form;
76 my $locale = $main::locale;
78 $main::auth->assert('vendor_invoice_edit');
81 $form->{javascript} = qq|<script type=text/javascript src=js/show_history.js></script>|;
82 #/show hhistory button
84 $form->{title} = $locale->text('Edit Vendor Invoice');
90 $main::lxdebug->leave_sub();
94 $main::lxdebug->enter_sub();
96 my $form = $main::form;
97 my %myconfig = %main::myconfig;
99 $main::auth->assert('vendor_invoice_edit');
101 $form->{vc} = 'vendor';
104 $form->{webdav} = $::instance_conf->get_webdav;
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 $form->backup_vars(qw(payment_id language_id taxzone_id
120 currency delivery_term_id intnotes cp_id));
122 IR->get_vendor(\%myconfig, \%$form);
123 IR->retrieve_invoice(\%myconfig, \%$form);
125 $form->restore_vars(qw(payment_id language_id taxzone_id
126 currency delivery_term_id intnotes cp_id));
128 my @curr = $form->get_all_currencies();
129 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
131 $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
133 # build vendor/customer drop down comatibility... don't ask
134 if (@{ $form->{"all_vendor"} || [] }) {
135 $form->{"selectvendor"} = 1;
136 $form->{vendor} = qq|$form->{vendor}--$form->{vendor_id}|;
140 if ($form->{all_departments}) {
141 $form->{selectdepartment} = "<option>\n";
142 $form->{department} = "$form->{department}--$form->{department_id}";
145 $form->{selectdepartment} .=
146 "<option>$_->{description}--$_->{id}\n"
147 } (@{ $form->{all_departments} || [] });
151 $form->{forex} = $form->{exchangerate};
152 my $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
154 foreach my $key (keys %{ $form->{AP_links} }) {
156 foreach my $ref (@{ $form->{AP_links}{$key} }) {
157 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}</option>";
160 next unless $form->{acc_trans}{$key};
162 if ($key eq "AP_paid") {
163 for my $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
164 $form->{"AP_paid_$i"} =
165 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
167 $form->{"acc_trans_id_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{acc_trans_id};
169 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount};
170 $form->{"datepaid_$i"} =
171 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
172 $form->{"gldate_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{gldate};
173 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
174 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
175 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
176 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
178 $form->{paidaccounts} = $i;
182 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
187 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
189 $form->{AP} = $form->{AP_1} unless $form->{id};
192 ($form->datetonum($form->{invdate}, \%myconfig) <=
193 $form->datetonum($form->{closedto}, \%myconfig));
195 $main::lxdebug->leave_sub();
198 sub prepare_invoice {
199 $main::lxdebug->enter_sub();
201 my $form = $main::form;
202 my %myconfig = %main::myconfig;
204 $main::auth->assert('vendor_invoice_edit');
208 map { $form->{$_} =~ s/\"/"/g } qw(invnumber ordnumber quonumber);
211 foreach my $ref (@{ $form->{invoice_details} }) {
213 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
214 # übernommen aus is.pl Fix für Bug 1642. Nebenwirkungen? jb 12.5.2011
215 # getestet: Lieferantenauftrag -> Rechnung i.O.
216 # Lieferantenauftrag -> Lieferschein -> Rechnung i.O.
217 # Werte: 20% (Lieferantenrabatt), 12,4% individuell und 0,4 individuell s.a.
218 # Screenshot zu Bug 1642
219 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
221 my ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
223 my $decimalplaces = ($dec > 2) ? $dec : 2;
225 $form->{"sellprice_$i"} =
226 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
229 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
230 $dec_qty = length $dec_qty;
233 $form->format_amount(\%myconfig, ($form->{"qty_$i"} * -1), $dec_qty);
235 $form->{rowcount} = $i;
239 $main::lxdebug->leave_sub();
243 $main::lxdebug->enter_sub();
245 my $form = $main::form;
246 my %myconfig = %main::myconfig;
247 my $locale = $main::locale;
248 my $cgi = $::request->{cgi};
250 $main::auth->assert('vendor_invoice_edit');
255 $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
256 $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
258 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
260 my @old_project_ids = ($form->{"globalproject_id"});
261 map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"};
263 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
265 "old_id" => \@old_project_ids },
266 "taxzones" => "ALL_TAXZONES",
267 "currencies" => "ALL_CURRENCIES",
268 "vendors" => "ALL_VENDORS",
269 "departments" => "all_departments",
270 "price_factors" => "ALL_PRICE_FACTORS");
272 $TMPL_VAR{ALL_EMPLOYEES} = SL::DB::Manager::Employee->get_all(query => [ or => [ id => $::form->{employee_id}, deleted => 0 ] ]);
273 $TMPL_VAR{ALL_CONTACTS} = SL::DB::Manager::Contact->get_all(query => [
275 cp_cv_id => $::form->{"$::form->{vc}_id"} * 1,
278 cp_id => $::form->{cp_id} * 1
282 $TMPL_VAR{department_labels} = sub { "$_[0]->{description}--$_[0]->{id}" };
285 $TMPL_VAR{vc_keys} = sub { "$_[0]->{name}--$_[0]->{id}" };
286 $TMPL_VAR{vclimit} = $myconfig{vclimit};
287 $TMPL_VAR{vc_select} = "customer_or_vendor_selection_window('vendor', '', 1, 0)";
288 push @custom_hiddens, "vendor_id";
289 push @custom_hiddens, "oldvendor";
290 push @custom_hiddens, "selectvendor";
292 # currencies and exchangerate
293 my @values = map { $_ } @{ $form->{ALL_CURRENCIES} };
294 my %labels = map { $_ => $_ } @{ $form->{ALL_CURRENCIES} };
295 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
296 # show_exchangerate is also later needed in another template
297 $form->{show_exchangerate} = $form->{currency} ne $form->{defaultcurrency};
298 $TMPL_VAR{currencies} = NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
299 '-values' => \@values, '-labels' => \%labels,
300 '-onchange' => "document.getElementById('update_button').click();"
301 )) if scalar @values;
302 push @custom_hiddens, "forex";
303 push @custom_hiddens, "exchangerate" if $form->{forex};
305 $TMPL_VAR{creditwarning} = ($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update};
306 $TMPL_VAR{is_credit_remaining_negativ} = $form->{creditremaining} =~ /-/;
308 my $follow_up_vc = $form->{vendor};
309 $follow_up_vc =~ s/--\d*\s*$//;
310 $TMPL_VAR{vendor_name} = $follow_up_vc;
312 # set option selected
313 foreach my $item (qw(AP)) {
314 $form->{"select$item"} =~ s/ selected//;
315 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
318 $TMPL_VAR{is_type_credit_note} = $form->{type} eq "credit_note";
319 $TMPL_VAR{is_format_html} = $form->{format} eq 'html';
320 $TMPL_VAR{dateformat} = $myconfig{dateformat};
321 $TMPL_VAR{numberformat} = $myconfig{numberformat};
324 $TMPL_VAR{HIDDENS} = [qw(
325 id action type media format queued printed emailed title vc discount
326 title creditlimit creditremaining tradediscount business closedto locked shipped storno storno_id
327 max_dunning_level dunning_amount
328 shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax
329 shiptoemail shiptodepartment_1 shiptodepartment_2 message email subject cc bcc taxaccounts cursor_fokus
330 convert_from_do_ids convert_from_oe_ids show_details gldate
332 map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts}];
334 $::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.SalesPurchase));
338 print $form->parse_html_template("ir/form_header", \%TMPL_VAR);
340 $main::lxdebug->leave_sub();
344 $main::lxdebug->enter_sub();
346 my $form = $main::form;
347 my %myconfig = %main::myconfig;
348 my $locale = $main::locale;
350 $main::auth->assert('vendor_invoice_edit');
352 $form->{invtotal} = $form->{invsubtotal};
353 $form->{oldinvtotal} = $form->{invtotal};
356 $form->{rows} = max 2,
357 $form->numtextrows($form->{notes}, 26, 8),
358 $form->numtextrows($form->{intnotes}, 35, 8);
361 # tax, total and subtotal calculations
362 my ($tax, $subtotal);
363 $form->{taxaccounts_array} = [ split / /, $form->{taxaccounts} ];
365 foreach my $item (@{ $form->{taxaccounts_array} }) {
366 if ($form->{"${item}_base"}) {
367 if ($form->{taxincluded}) {
368 $form->{"${item}_total"} = $form->round_amount( ($form->{"${item}_base"} * $form->{"${item}_rate"}
369 / (1 + $form->{"${item}_rate"})), 2);
370 $form->{"${item}_netto"} = $form->round_amount( ($form->{"${item}_base"} - $form->{"${item}_total"}), 2);
372 $form->{"${item}_total"} = $form->round_amount( $form->{"${item}_base"} * $form->{"${item}_rate"}, 2);
373 $form->{invtotal} += $form->{"${item}_total"};
380 $form->{follow_ups} = FU->follow_ups('trans_id' => $form->{id}) || [];
381 $form->{follow_ups_unfinished} = ( sum map { $_->{due} * 1 } @{ $form->{follow_ups} } ) || 0;
386 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
387 $form->{paid_indices} = [ 1 .. $form->{paidaccounts} ];
389 # Standard Konto für Umlaufvermögen
390 my $accno_arap = IS->get_standard_accno_current_assets(\%myconfig, \%$form);
392 for my $i (1 .. $form->{paidaccounts}) {
393 $form->{"changeable_$i"} = 1;
394 if (SL::DB::Default->get->payments_changeable == 0) {
396 $form->{"changeable_$i"} = ($form->{"acc_trans_id_$i"})? 0 : 1;
397 } elsif (SL::DB::Default->get->payments_changeable == 2) {
399 $form->{"changeable_$i"} = (($form->{"gldate_$i"} eq '') ||
400 ($form->current_date(\%myconfig) eq $form->{"gldate_$i"}));
403 $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
404 if (!$form->{"AP_paid_$i"}) {
405 $form->{"selectAP_paid_$i"} =~ s/option>$accno_arap--(.*?)>/option selected>$accno_arap--$1>/;
407 $form->{"selectAP_paid_$i"} =~ s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
410 $totalpaid += $form->{"paid_$i"};
413 $form->{ALL_DELIVERY_TERMS} = SL::DB::Manager::DeliveryTerm->get_all_sorted();
415 print $form->parse_html_template('ir/form_footer', {
416 is_type_credit_note => ($form->{type} eq "credit_note"),
417 totalpaid => $totalpaid,
418 paid_missing => $form->{invtotal} - $totalpaid,
419 show_storno => $form->{id} && !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ap") && !$totalpaid,
420 show_delete => ($::instance_conf->get_ir_changeable == 2)
421 ? ($form->current_date(\%myconfig) eq $form->{gldate})
422 : ($::instance_conf->get_ir_changeable == 1),
424 ##print $form->parse_html_template('ir/_payments'); # parser
425 ##print $form->parse_html_template('webdav/_list'); # parser
427 $main::lxdebug->leave_sub();
431 $main::lxdebug->enter_sub();
433 my $form = $main::form;
434 my %myconfig = %main::myconfig;
436 $main::auth->assert('vendor_invoice_edit');
438 &mark_as_paid_common(\%myconfig,"ap");
440 $main::lxdebug->leave_sub();
444 $main::lxdebug->enter_sub();
446 my $form = $main::form;
447 my %myconfig = %main::myconfig;
449 $main::auth->assert('vendor_invoice_edit');
451 &check_name('vendor');
453 if (!$form->{forex}) { # read exchangerate from input field (not hidden)
454 $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate});
456 $form->{forex} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'sell');
457 $form->{exchangerate} = $form->{forex} if $form->{forex};
459 for my $i (1 .. $form->{paidaccounts}) {
460 next unless $form->{"paid_$i"};
461 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
462 $form->{"forex_$i"} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell');
463 $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
466 my $i = $form->{rowcount};
467 my $exchangerate = ($form->{exchangerate} * 1) || 1;
469 if ( ($form->{"partnumber_$i"} eq "")
470 && ($form->{"description_$i"} eq "")
471 && ($form->{"partsgroup_$i"} eq "")) {
472 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
477 IR->retrieve_item(\%myconfig, \%$form);
479 my $rows = scalar @{ $form->{item_list} };
482 $form->{"qty_$i"} = 1 unless $form->parse_amount(\%myconfig, $form->{"qty_$i"});
486 select_item(mode => 'IR');
491 # override sellprice if there is one entered
492 my $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
494 # ergaenzung fuer bug 736 Lieferanten-Rabatt auch in Einkaufsrechnungen vorbelegen jb
495 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{vendor_discount} * 100 );
496 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
497 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
499 $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
501 ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
502 my $dec_qty = length $1;
503 my $decimalplaces = max 2, $dec_qty;
506 $form->{"sellprice_$i"} = $sellprice;
508 # if there is an exchange rate adjust sellprice
509 $form->{"sellprice_$i"} /= $exchangerate;
512 my $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
513 $form->{creditremaining} -= $amount;
514 $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
515 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
522 # ok, so this is a new part
523 # ask if it is a part or service item
525 if ( $form->{"partsgroup_$i"}
526 && ($form->{"partsnumber_$i"} eq "")
527 && ($form->{"description_$i"} eq "")) {
529 $form->{"discount_$i"} = "";
533 $form->{"id_$i"} = 0;
538 $main::lxdebug->leave_sub();
542 $main::lxdebug->enter_sub();
544 my $form = $main::form;
545 my %myconfig = %main::myconfig;
546 my $locale = $main::locale;
548 $main::auth->assert('vendor_invoice_edit');
550 if ($form->{storno}) {
551 $form->error($locale->text('Cannot storno storno invoice!'));
554 if (IS->has_storno(\%myconfig, $form, "ap")) {
555 $form->error($locale->text("Invoice has already been storno'd!"));
558 $form->error($locale->text('Cannot post storno for a closed period!'))
559 if ( $form->date_closed($form->{invdate}, \%myconfig));
561 my $employee_id = $form->{employee_id};
566 # Payments must not be recorded for the new storno invoice.
567 $form->{paidaccounts} = 0;
568 map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ gldate_ acc_trans_id_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
571 if(!exists $form->{addition} && $form->{id} ne "") {
572 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
573 $form->{addition} = "CANCELED";
576 # /saving the history
578 $form->{storno_id} = $form->{id};
581 $form->{invnumber} = "Storno zu " . $form->{invnumber};
583 $form->{employee_id} = $employee_id;
585 $main::lxdebug->leave_sub();
590 $main::lxdebug->enter_sub();
592 my $form = $main::form;
593 my %myconfig = %main::myconfig;
595 $main::auth->assert('vendor_invoice_edit');
597 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);
598 $form->{paidaccounts} = 1;
600 $form->{invdate} = $form->current_date(\%myconfig);
603 $main::lxdebug->leave_sub();
607 $main::lxdebug->enter_sub();
609 my $form = $main::form;
610 my %myconfig = %main::myconfig;
611 my $locale = $main::locale;
613 $main::auth->assert('vendor_invoice_edit');
615 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
616 for my $i (1 .. $form->{paidaccounts}) {
617 if ($form->{"paid_$i"}) {
618 my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
620 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
622 $form->error($locale->text('Cannot post payment for a closed period!'))
623 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
625 if ($form->{currency} ne $form->{defaultcurrency}) {
626 # $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid); # invdate isn't set here
627 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
632 ($form->{AP}) = split /--/, $form->{AP};
633 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
634 if (IR->post_payment(\%myconfig, \%$form)){
635 if (!exists $form->{addition} && $form->{id} ne "") {
637 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
638 $form->{addition} = "PAYMENT POSTED";
639 $form->{what_done} = $form->{currency} . qq| | . $form->{paid} . qq| | . $locale->text("POSTED");
641 # /saving the history
644 $form->redirect($locale->text('Payment posted!'));
647 $form->error($locale->text('Cannot post payment!'));
649 $main::lxdebug->leave_sub();
653 my $form = $main::form;
655 my @dates = sort { $b->[1] cmp $a->[1] }
656 map { [ $_, $main::locale->reformat_date(\%main::myconfig, $_, 'yyyy-mm-dd') ] }
658 map { $form->{"datepaid_${_}"} }
659 (1..$form->{rowcount});
661 return @dates ? $dates[0]->[0] : undef;
666 $main::lxdebug->enter_sub();
668 my $form = $main::form;
669 my %myconfig = %main::myconfig;
670 my $locale = $main::locale;
672 $main::auth->assert('vendor_invoice_edit');
674 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
676 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
677 $form->isblank("vendor", $locale->text('Vendor missing!'));
678 $form->isblank("invnumber", $locale->text('Invnumber missing!'));
680 $form->{invnumber} =~ s/^\s*//g;
681 $form->{invnumber} =~ s/\s*$//g;
683 # if the vendor changed get new values
684 if (&check_name('vendor')) {
689 if ($myconfig{mandatory_departments} && !$form->{department_id}) {
690 $form->{saved_message} = $::locale->text('You have to specify a department.');
695 remove_emptied_rows();
698 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
699 my $invdate = $form->datetonum($form->{invdate}, \%myconfig);
700 my $max_datepaid = _max_datepaid();
702 $form->error($locale->text('Cannot post transaction above the maximum future booking date!'))
703 if ($form->date_max_future($invdate, \%myconfig));
704 $form->error($locale->text('Cannot post invoice for a closed period!')) if $max_datepaid && $form->date_closed($max_datepaid, \%myconfig);
706 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
707 if ($form->{currency} ne $form->{defaultcurrency});
710 for $i (1 .. $form->{paidaccounts}) {
711 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
712 my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
714 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
716 $form->error($locale->text('Cannot post payment for a closed period!'))
717 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
719 if ($form->{currency} ne $form->{defaultcurrency}) {
720 $form->{"exchangerate_$i"} = $form->{exchangerate}
721 if ($invdate == $datepaid);
722 $form->isblank("exchangerate_$i",
723 $locale->text('Exchangerate for payment missing!'));
728 ($form->{AP}) = split /--/, $form->{AP};
729 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
730 $form->{storno} ||= 0;
732 $form->{id} = 0 if $form->{postasnew};
736 if (IR->post_invoice(\%myconfig, \%$form)){
738 if(!exists $form->{addition} && $form->{id} ne "") {
739 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
740 $form->{addition} = "POSTED";
741 #$form->{what_done} = $locale->text("Rechnungsnummer") . qq| | . $form->{invnumber};
744 # /saving the history
745 remove_draft() if $form->{remove_draft};
746 $form->redirect( $locale->text('Invoice')
747 . " $form->{invnumber} "
748 . $locale->text('posted!'));
750 $form->error($locale->text('Cannot post invoice!'));
752 $main::lxdebug->leave_sub();
756 $main::lxdebug->enter_sub();
758 my $form = $main::form;
759 my $locale = $main::locale;
761 $main::auth->assert('vendor_invoice_edit');
765 <form method=post action=$form->{script}>
768 # delete action variable
769 map { delete $form->{$_} } qw(action header);
771 foreach my $key (keys %$form) {
772 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
773 $form->{$key} =~ s/\"/"/g;
774 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
778 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
781 . $locale->text('Are you sure you want to delete Invoice Number')
782 . qq| $form->{invnumber}</h4>
784 <input name=action class=submit type=submit value="|
785 . $locale->text('Yes') . qq|">
789 $main::lxdebug->leave_sub();
793 $main::lxdebug->enter_sub();
795 my $form = $main::form;
796 my %myconfig = %main::myconfig;
797 my $locale = $main::locale;
799 $main::auth->assert('vendor_invoice_edit');
801 if (IR->delete_invoice(\%myconfig, \%$form)) {
803 if(!exists $form->{addition}) {
804 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
805 $form->{addition} = "DELETED";
808 # /saving the history
809 $form->redirect($locale->text('Invoice deleted!'));
811 $form->error($locale->text('Cannot delete invoice!'));
813 $main::lxdebug->leave_sub();
816 sub get_duedate_vendor {
817 $::lxdebug->enter_sub;
819 my $result = IR->get_duedate(
820 vendor_id => $::form->{vendor_id},
821 invdate => $::form->{invdate},
822 default => $::form->{old_duedate},
825 print $::form->ajax_response_header, $result;
826 $::lxdebug->leave_sub;