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 $form->error($locale->text('Cannot post storno for a closed period!'))
579 if ( $form->date_closed($form->{invdate}, \%myconfig));
581 my $employee_id = $form->{employee_id};
586 # Payments must not be recorded for the new storno invoice.
587 $form->{paidaccounts} = 0;
588 map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ gldate_ acc_trans_id_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
591 if(!exists $form->{addition} && $form->{id} ne "") {
592 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
593 $form->{addition} = "CANCELED";
596 # /saving the history
598 $form->{storno_id} = $form->{id};
601 $form->{invnumber} = "Storno zu " . $form->{invnumber};
603 $form->{employee_id} = $employee_id;
605 $main::lxdebug->leave_sub();
609 sub use_as_template {
610 $main::lxdebug->enter_sub();
612 my $form = $main::form;
613 my %myconfig = %main::myconfig;
615 $main::auth->assert('vendor_invoice_edit');
617 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);
618 $form->{paidaccounts} = 1;
620 $form->{invdate} = $form->current_date(\%myconfig);
623 $main::lxdebug->leave_sub();
627 $main::lxdebug->enter_sub();
629 my $form = $main::form;
630 my %myconfig = %main::myconfig;
631 my $locale = $main::locale;
633 $main::auth->assert('vendor_invoice_edit');
635 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
636 for my $i (1 .. $form->{paidaccounts}) {
637 if ($form->{"paid_$i"}) {
638 my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
640 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
642 $form->error($locale->text('Cannot post payment for a closed period!'))
643 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
645 if ($form->{currency} ne $form->{defaultcurrency}) {
646 # $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid); # invdate isn't set here
647 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
652 ($form->{AP}) = split /--/, $form->{AP};
653 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
654 if (IR->post_payment(\%myconfig, \%$form)){
655 if (!exists $form->{addition} && $form->{id} ne "") {
657 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
658 $form->{addition} = "PAYMENT POSTED";
659 $form->{what_done} = $form->{currency} . qq| | . $form->{paid} . qq| | . $locale->text("POSTED");
661 # /saving the history
664 $form->redirect($locale->text('Payment posted!'));
667 $form->error($locale->text('Cannot post payment!'));
669 $main::lxdebug->leave_sub();
673 my $form = $main::form;
675 my @dates = sort { $b->[1] cmp $a->[1] }
676 map { [ $_, $main::locale->reformat_date(\%main::myconfig, $_, 'yyyy-mm-dd') ] }
678 map { $form->{"datepaid_${_}"} }
679 (1..$form->{rowcount});
681 return @dates ? $dates[0]->[0] : undef;
686 $main::lxdebug->enter_sub();
688 my $form = $main::form;
689 my %myconfig = %main::myconfig;
690 my $locale = $main::locale;
692 $main::auth->assert('vendor_invoice_edit');
694 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
696 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
697 $form->isblank("vendor", $locale->text('Vendor missing!'));
698 $form->isblank("invnumber", $locale->text('Invnumber missing!'));
700 $form->{invnumber} =~ s/^\s*//g;
701 $form->{invnumber} =~ s/\s*$//g;
703 # if the vendor changed get new values
704 if (&check_name('vendor')) {
709 if ($myconfig{mandatory_departments} && !$form->{department_id}) {
710 $form->{saved_message} = $::locale->text('You have to specify a department.');
715 remove_emptied_rows();
718 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
719 my $invdate = $form->datetonum($form->{invdate}, \%myconfig);
720 my $max_datepaid = _max_datepaid();
722 $form->error($locale->text('Cannot post invoice for a closed period!')) if $max_datepaid && $form->date_closed($max_datepaid, \%myconfig);
724 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
725 if ($form->{currency} ne $form->{defaultcurrency});
728 for $i (1 .. $form->{paidaccounts}) {
729 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
730 my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
732 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
734 $form->error($locale->text('Cannot post payment for a closed period!'))
735 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
737 if ($form->{currency} ne $form->{defaultcurrency}) {
738 $form->{"exchangerate_$i"} = $form->{exchangerate}
739 if ($invdate == $datepaid);
740 $form->isblank("exchangerate_$i",
741 $locale->text('Exchangerate for payment missing!'));
746 ($form->{AP}) = split /--/, $form->{AP};
747 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
748 $form->{storno} ||= 0;
750 $form->{id} = 0 if $form->{postasnew};
754 if (IR->post_invoice(\%myconfig, \%$form)){
756 if(!exists $form->{addition} && $form->{id} ne "") {
757 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
758 $form->{addition} = "POSTED";
759 #$form->{what_done} = $locale->text("Rechnungsnummer") . qq| | . $form->{invnumber};
762 # /saving the history
763 remove_draft() if $form->{remove_draft};
764 $form->redirect( $locale->text('Invoice')
765 . " $form->{invnumber} "
766 . $locale->text('posted!'));
768 $form->error($locale->text('Cannot post invoice!'));
770 $main::lxdebug->leave_sub();
774 $main::lxdebug->enter_sub();
776 my $form = $main::form;
777 my $locale = $main::locale;
779 $main::auth->assert('vendor_invoice_edit');
783 <form method=post action=$form->{script}>
786 # delete action variable
787 map { delete $form->{$_} } qw(action header);
789 foreach my $key (keys %$form) {
790 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
791 $form->{$key} =~ s/\"/"/g;
792 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
796 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
799 . $locale->text('Are you sure you want to delete Invoice Number')
800 . qq| $form->{invnumber}</h4>
802 <input name=action class=submit type=submit value="|
803 . $locale->text('Yes') . qq|">
807 $main::lxdebug->leave_sub();
811 $main::lxdebug->enter_sub();
813 my $form = $main::form;
814 my %myconfig = %main::myconfig;
815 my $locale = $main::locale;
817 $main::auth->assert('vendor_invoice_edit');
819 if (IR->delete_invoice(\%myconfig, \%$form)) {
821 if(!exists $form->{addition}) {
822 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
823 $form->{addition} = "DELETED";
826 # /saving the history
827 $form->redirect($locale->text('Invoice deleted!'));
829 $form->error($locale->text('Cannot delete invoice!'));
831 $main::lxdebug->leave_sub();
834 sub get_duedate_vendor {
835 $::lxdebug->enter_sub;
837 my $result = IR->get_duedate(
838 vendor_id => $::form->{vendor_id},
839 invdate => $::form->{invdate},
840 default => $::form->{old_duedate},
843 print $::form->ajax_response_header, $result;
844 $::lxdebug->leave_sub;