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("contacts" => "ALL_CONTACTS",
287 "shipto" => "ALL_SHIPTO",
288 "projects" => { "key" => "ALL_PROJECTS",
290 "old_id" => \@old_project_ids },
291 "employees" => "ALL_EMPLOYEES",
292 "taxzones" => "ALL_TAXZONES",
293 "currencies" => "ALL_CURRENCIES",
294 "vendors" => "ALL_VENDORS",
295 "departments" => "all_departments",
296 "price_factors" => "ALL_PRICE_FACTORS");
298 $TMPL_VAR{sales_employee_labels} = sub { $_[0]->{name} || $_[0]->{login} };
299 # $TMPL_VAR{shipto_labels} = sub { join "; ", grep { $_ } map { $_[0]->{"shipto${_}" } } qw(name department_1 street city) };
300 $TMPL_VAR{contact_labels} = sub { join(', ', $_[0]->{"cp_name"}, $_[0]->{"cp_givenname"}) . ($_[0]->{cp_abteilung} ? " ($_[0]->{cp_abteilung})" : "") };
301 $TMPL_VAR{department_labels} = sub { "$_[0]->{description}--$_[0]->{id}" };
304 $TMPL_VAR{vc_keys} = sub { "$_[0]->{name}--$_[0]->{id}" };
305 $TMPL_VAR{vclimit} = $myconfig{vclimit};
306 $TMPL_VAR{vc_select} = "customer_or_vendor_selection_window('vendor', '', 1, 0)";
307 push @custom_hiddens, "vendor_id";
308 push @custom_hiddens, "oldvendor";
309 push @custom_hiddens, "selectvendor";
311 # currencies and exchangerate
312 my @values = map { $_ } @{ $form->{ALL_CURRENCIES} };
313 my %labels = map { $_ => $_ } @{ $form->{ALL_CURRENCIES} };
314 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
315 $TMPL_VAR{show_exchangerate} = $form->{currency} ne $form->{defaultcurrency};
316 $TMPL_VAR{currencies} = NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
317 '-values' => \@values, '-labels' => \%labels,
318 '-onchange' => "document.getElementById('update_button').click();"
319 )) if scalar @values;
320 push @custom_hiddens, "forex";
321 push @custom_hiddens, "exchangerate" if $form->{forex};
323 $TMPL_VAR{creditwarning} = ($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update};
324 $TMPL_VAR{is_credit_remaining_negativ} = $form->{creditremaining} =~ /-/;
326 $form->{fokus} = "invoice.vendor";
328 my $follow_up_vc = $form->{vendor};
329 $follow_up_vc =~ s/--\d*\s*$//;
330 $TMPL_VAR{vendor_name} = $follow_up_vc;
332 # set option selected
333 foreach my $item (qw(AP)) {
334 $form->{"select$item"} =~ s/ selected//;
335 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
338 $TMPL_VAR{is_type_credit_note} = $form->{type} eq "credit_note";
339 $TMPL_VAR{is_format_html} = $form->{format} eq 'html';
340 $TMPL_VAR{dateformat} = $myconfig{dateformat};
341 $TMPL_VAR{numberformat} = $myconfig{numberformat};
344 $TMPL_VAR{HIDDENS} = [qw(
345 id action type media format queued printed emailed title vc discount
346 title creditlimit creditremaining tradediscount business closedto locked shipped storno storno_id
347 max_dunning_level dunning_amount
348 shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax
349 shiptoemail shiptodepartment_1 shiptodepartment_2 message email subject cc bcc taxaccounts cursor_fokus
350 convert_from_do_ids convert_from_oe_ids
352 map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts}];
354 $form->{jsscript} = 1;
357 print $form->parse_html_template("ir/form_header", \%TMPL_VAR);
359 $main::lxdebug->leave_sub();
363 $main::lxdebug->enter_sub();
365 my $form = $main::form;
366 my %myconfig = %main::myconfig;
367 my $locale = $main::locale;
369 $main::auth->assert('vendor_invoice_edit');
371 $form->{invtotal} = $form->{invsubtotal};
372 $form->{oldinvtotal} = $form->{invtotal};
375 $form->{rows} = max 2,
376 $form->numtextrows($form->{notes}, 26, 8),
377 $form->numtextrows($form->{intnotes}, 35, 8);
380 # tax, total and subtotal calculations
381 my ($tax, $subtotal);
382 $form->{taxaccounts_array} = [ split / /, $form->{taxaccounts} ];
384 foreach my $item (@{ $form->{taxaccounts_array} }) {
385 if ($form->{"${item}_base"}) {
386 if ($form->{taxincluded}) {
387 $form->{"${item}_total"} = $form->round_amount( ($form->{"${item}_base"} * $form->{"${item}_rate"}
388 / (1 + $form->{"${item}_rate"})), 2);
389 $form->{"${item}_netto"} = $form->round_amount( ($form->{"${item}_base"} - $form->{"${item}_total"}), 2);
391 $form->{"${item}_total"} = $form->round_amount( $form->{"${item}_base"} * $form->{"${item}_rate"}, 2);
392 $form->{invtotal} += $form->{"${item}_total"};
399 $form->{follow_ups} = FU->follow_ups('trans_id' => $form->{id}) || [];
400 $form->{follow_ups_unfinished} = ( sum map { $_->{due} * 1 } @{ $form->{follow_ups} } ) || 0;
405 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
406 $form->{paid_indices} = [ 1 .. $form->{paidaccounts} ];
408 # Standard Konto für Umlaufvermögen
409 my $accno_arap = IS->get_standard_accno_current_assets(\%myconfig, \%$form);
411 for my $i (1 .. $form->{paidaccounts}) {
412 $form->{"changeable_$i"} = 1;
413 if ($::lx_office_conf{features}->{payments_changeable} == 0) {
415 $form->{"changeable_$i"} = ($form->{"acc_trans_id_$i"})? 0 : 1;
416 } elsif ($::lx_office_conf{features}->{payments_changeable} == 2) {
418 $form->{"changeable_$i"} = (($form->{"gldate_$i"} eq '') ||
419 ($form->current_date(\%myconfig) eq $form->{"gldate_$i"}));
422 $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
423 if (!$form->{"AP_paid_$i"}) {
424 $form->{"selectAP_paid_$i"} =~ s/option>$accno_arap--(.*?)>/option selected>$accno_arap--$1>/;
426 $form->{"selectAP_paid_$i"} =~ s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
429 $totalpaid += $form->{"paid_$i"};
432 print $form->parse_html_template('ir/form_footer', {
433 is_type_credit_note => ($form->{type} eq "credit_note"),
434 totalpaid => $totalpaid,
435 paid_missing => $form->{invtotal} - $totalpaid,
436 show_storno => $form->{id} && !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ap") && !$totalpaid,
437 show_delete => ($form->current_date(\%myconfig) eq $form->{gldate}),
439 ##print $form->parse_html_template('ir/_payments'); # parser
440 ##print $form->parse_html_template('webdav/_list'); # parser
442 $main::lxdebug->leave_sub();
446 $main::lxdebug->enter_sub();
448 my $form = $main::form;
449 my %myconfig = %main::myconfig;
451 $main::auth->assert('vendor_invoice_edit');
453 &mark_as_paid_common(\%myconfig,"ap");
455 $main::lxdebug->leave_sub();
459 $main::lxdebug->enter_sub();
461 my $form = $main::form;
462 my %myconfig = %main::myconfig;
464 $main::auth->assert('vendor_invoice_edit');
466 # map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
468 &check_name('vendor');
470 $form->{forex} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'sell');
471 $form->{exchangerate} = $form->{forex} if $form->{forex};
473 for my $i (1 .. $form->{paidaccounts}) {
474 next unless $form->{"paid_$i"};
475 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
476 $form->{"forex_$i"} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell');
477 $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
480 my $i = $form->{rowcount};
481 my $exchangerate = ($form->{exchangerate} * 1) || 1;
483 if ( ($form->{"partnumber_$i"} eq "")
484 && ($form->{"description_$i"} eq "")
485 && ($form->{"partsgroup_$i"} eq "")) {
486 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
491 IR->retrieve_item(\%myconfig, \%$form);
493 my $rows = scalar @{ $form->{item_list} };
496 $form->{"qty_$i"} = 1 unless $form->parse_amount(\%myconfig, $form->{"qty_$i"});
500 select_item(mode => 'IR');
505 # override sellprice if there is one entered
506 my $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
508 # ergaenzung fuer bug 736 Lieferanten-Rabatt auch in Einkaufsrechnungen vorbelegen jb
509 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{vendor_discount} * 100 );
510 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
511 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
513 $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
515 ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
516 my $dec_qty = length $1;
517 my $decimalplaces = max 2, $dec_qty;
520 $form->{"sellprice_$i"} = $sellprice;
522 # if there is an exchange rate adjust sellprice
523 $form->{"sellprice_$i"} /= $exchangerate;
526 my $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
527 $form->{creditremaining} -= $amount;
528 $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
529 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
536 # ok, so this is a new part
537 # ask if it is a part or service item
539 if ( $form->{"partsgroup_$i"}
540 && ($form->{"partsnumber_$i"} eq "")
541 && ($form->{"description_$i"} eq "")) {
543 $form->{"discount_$i"} = "";
547 $form->{"id_$i"} = 0;
552 $main::lxdebug->leave_sub();
556 $main::lxdebug->enter_sub();
558 my $form = $main::form;
559 my %myconfig = %main::myconfig;
560 my $locale = $main::locale;
562 $main::auth->assert('vendor_invoice_edit');
564 if ($form->{storno}) {
565 $form->error($locale->text('Cannot storno storno invoice!'));
568 if (IS->has_storno(\%myconfig, $form, "ap")) {
569 $form->error($locale->text("Invoice has already been storno'd!"));
572 my $employee_id = $form->{employee_id};
577 # Payments must not be recorded for the new storno invoice.
578 $form->{paidaccounts} = 0;
579 map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ gldate_ acc_trans_id_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
582 if(!exists $form->{addition} && $form->{id} ne "") {
583 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
584 $form->{addition} = "CANCELED";
587 # /saving the history
589 $form->{storno_id} = $form->{id};
592 $form->{invnumber} = "Storno zu " . $form->{invnumber};
594 $form->{employee_id} = $employee_id;
596 $main::lxdebug->leave_sub();
600 sub use_as_template {
601 $main::lxdebug->enter_sub();
603 my $form = $main::form;
604 my %myconfig = %main::myconfig;
606 $main::auth->assert('vendor_invoice_edit');
608 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);
609 $form->{paidaccounts} = 1;
611 $form->{invdate} = $form->current_date(\%myconfig);
614 $main::lxdebug->leave_sub();
618 $main::lxdebug->enter_sub();
620 my $form = $main::form;
621 my %myconfig = %main::myconfig;
622 my $locale = $main::locale;
624 $main::auth->assert('vendor_invoice_edit');
626 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
627 for my $i (1 .. $form->{paidaccounts}) {
628 if ($form->{"paid_$i"}) {
629 my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
631 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
633 $form->error($locale->text('Cannot post payment for a closed period!'))
634 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
636 if ($form->{currency} ne $form->{defaultcurrency}) {
637 # $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid); # invdate isn't set here
638 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
643 ($form->{AP}) = split /--/, $form->{AP};
644 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
645 if (IR->post_payment(\%myconfig, \%$form)){
646 if (!exists $form->{addition} && $form->{id} ne "") {
648 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
649 $form->{addition} = "PAYMENT POSTED";
650 $form->{what_done} = $form->{currency} . qq| | . $form->{paid} . qq| | . $locale->text("POSTED");
652 # /saving the history
655 $form->redirect($locale->text('Payment posted!'));
658 $form->error($locale->text('Cannot post payment!'));
660 $main::lxdebug->leave_sub();
664 my $form = $main::form;
666 my @dates = sort { $b->[1] cmp $a->[1] }
667 map { [ $_, $main::locale->reformat_date(\%main::myconfig, $_, 'yyyy-mm-dd') ] }
669 map { $form->{"datepaid_${_}"} }
670 (1..$form->{rowcount});
672 return @dates ? $dates[0]->[0] : undef;
677 $main::lxdebug->enter_sub();
679 my $form = $main::form;
680 my %myconfig = %main::myconfig;
681 my $locale = $main::locale;
683 $main::auth->assert('vendor_invoice_edit');
685 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
687 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
688 $form->isblank("vendor", $locale->text('Vendor missing!'));
689 $form->isblank("invnumber", $locale->text('Invnumber missing!'));
691 $form->{invnumber} =~ s/^\s*//g;
692 $form->{invnumber} =~ s/\s*$//g;
694 # if the vendor changed get new values
695 if (&check_name('vendor')) {
700 if ($myconfig{mandatory_departments} && !$form->{department_id}) {
701 $form->{saved_message} = $::locale->text('You have to specify a department.');
706 remove_emptied_rows();
709 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
710 my $invdate = $form->datetonum($form->{invdate}, \%myconfig);
711 my $max_datepaid = _max_datepaid();
713 $form->error($locale->text('Cannot post invoice for a closed period!')) if $max_datepaid && $form->date_closed($max_datepaid, \%myconfig);
715 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
716 if ($form->{currency} ne $form->{defaultcurrency});
719 for $i (1 .. $form->{paidaccounts}) {
720 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
721 my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
723 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
725 $form->error($locale->text('Cannot post payment for a closed period!'))
726 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
728 if ($form->{currency} ne $form->{defaultcurrency}) {
729 $form->{"exchangerate_$i"} = $form->{exchangerate}
730 if ($invdate == $datepaid);
731 $form->isblank("exchangerate_$i",
732 $locale->text('Exchangerate for payment missing!'));
737 ($form->{AP}) = split /--/, $form->{AP};
738 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
739 $form->{storno} ||= 0;
741 $form->{id} = 0 if $form->{postasnew};
745 if (IR->post_invoice(\%myconfig, \%$form)){
747 if(!exists $form->{addition} && $form->{id} ne "") {
748 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
749 $form->{addition} = "POSTED";
750 #$form->{what_done} = $locale->text("Rechnungsnummer") . qq| | . $form->{invnumber};
753 # /saving the history
754 remove_draft() if $form->{remove_draft};
755 $form->redirect( $locale->text('Invoice')
756 . " $form->{invnumber} "
757 . $locale->text('posted!'));
759 $form->error($locale->text('Cannot post invoice!'));
761 $main::lxdebug->leave_sub();
765 $main::lxdebug->enter_sub();
767 my $form = $main::form;
768 my $locale = $main::locale;
770 $main::auth->assert('vendor_invoice_edit');
776 <form method=post action=$form->{script}>
779 # delete action variable
780 map { delete $form->{$_} } qw(action header);
782 foreach my $key (keys %$form) {
783 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
784 $form->{$key} =~ s/\"/"/g;
785 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
789 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
792 . $locale->text('Are you sure you want to delete Invoice Number')
793 . qq| $form->{invnumber}</h4>
795 <input name=action class=submit type=submit value="|
796 . $locale->text('Yes') . qq|">
800 $main::lxdebug->leave_sub();
804 $main::lxdebug->enter_sub();
806 my $form = $main::form;
807 my %myconfig = %main::myconfig;
808 my $locale = $main::locale;
810 $main::auth->assert('vendor_invoice_edit');
812 if (IR->delete_invoice(\%myconfig, \%$form)) {
814 if(!exists $form->{addition}) {
815 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
816 $form->{addition} = "DELETED";
819 # /saving the history
820 $form->redirect($locale->text('Invoice deleted!'));
822 $form->error($locale->text('Cannot delete invoice!'));
824 $main::lxdebug->leave_sub();
827 sub get_duedate_vendor {
828 $::lxdebug->enter_sub;
830 my $result = IR->get_duedate(
831 vendor_id => $::form->{vendor_id},
832 invdate => $::form->{invdate},
833 default => $::form->{old_duedate},
836 print $::form->ajax_response_header, $result;
837 $::lxdebug->leave_sub;