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 if (!$::instance_conf->get_allow_new_purchase_invoice) {
62 $::form->show_generic_error($::locale->text("You do not have the permissions to access this function."));
65 return $main::lxdebug->leave_sub() if (load_draft_maybe());
67 $form->{title} = $locale->text('Record Vendor Invoice');
73 $main::lxdebug->leave_sub();
77 $main::lxdebug->enter_sub();
79 my $form = $main::form;
80 my $locale = $main::locale;
82 $main::auth->assert('vendor_invoice_edit');
85 $form->{javascript} = qq|<script type=text/javascript src=js/show_history.js></script>|;
86 #/show hhistory button
88 $form->{title} = $locale->text('Edit Vendor Invoice');
94 $main::lxdebug->leave_sub();
98 $main::lxdebug->enter_sub();
100 my $form = $main::form;
101 my %myconfig = %main::myconfig;
103 $main::auth->assert('vendor_invoice_edit');
105 $form->{vc} = 'vendor';
108 $form->{webdav} = $::instance_conf->get_webdav;
110 $form->create_links("AP", \%myconfig, "vendor");
112 #quote all_vendor Bug 133
113 foreach my $ref (@{ $form->{all_vendor} }) {
114 $ref->{name} = $form->quote($ref->{name});
117 if ($form->{all_vendor}) {
118 unless ($form->{vendor_id}) {
119 $form->{vendor_id} = $form->{all_vendor}->[0]->{id};
123 $form->backup_vars(qw(payment_id language_id taxzone_id
124 currency delivery_term_id intnotes cp_id));
126 IR->get_vendor(\%myconfig, \%$form);
127 IR->retrieve_invoice(\%myconfig, \%$form);
129 $form->restore_vars(qw(payment_id language_id taxzone_id
130 currency delivery_term_id intnotes cp_id));
132 my @curr = $form->get_all_currencies();
133 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
135 $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
137 # build vendor/customer drop down comatibility... don't ask
138 if (@{ $form->{"all_vendor"} || [] }) {
139 $form->{"selectvendor"} = 1;
140 $form->{vendor} = qq|$form->{vendor}--$form->{vendor_id}|;
144 if ($form->{all_departments}) {
145 $form->{selectdepartment} = "<option>\n";
146 $form->{department} = "$form->{department}--$form->{department_id}";
149 $form->{selectdepartment} .=
150 "<option>$_->{description}--$_->{id}\n"
151 } (@{ $form->{all_departments} || [] });
155 $form->{forex} = $form->{exchangerate};
156 my $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
158 foreach my $key (keys %{ $form->{AP_links} }) {
160 foreach my $ref (@{ $form->{AP_links}{$key} }) {
161 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}</option>";
164 next unless $form->{acc_trans}{$key};
166 if ($key eq "AP_paid") {
167 for my $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
168 $form->{"AP_paid_$i"} =
169 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
171 $form->{"acc_trans_id_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{acc_trans_id};
173 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount};
174 $form->{"datepaid_$i"} =
175 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
176 $form->{"gldate_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{gldate};
177 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
178 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
179 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
180 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
182 $form->{paidaccounts} = $i;
186 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
191 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
193 $form->{AP} = $form->{AP_1} unless $form->{id};
196 ($form->datetonum($form->{invdate}, \%myconfig) <=
197 $form->datetonum($form->{closedto}, \%myconfig));
199 $main::lxdebug->leave_sub();
202 sub prepare_invoice {
203 $main::lxdebug->enter_sub();
205 my $form = $main::form;
206 my %myconfig = %main::myconfig;
208 $main::auth->assert('vendor_invoice_edit');
210 $form->{type} = "purchase_invoice";
214 map { $form->{$_} =~ s/\"/"/g } qw(invnumber ordnumber quonumber);
217 foreach my $ref (@{ $form->{invoice_details} }) {
219 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
220 # übernommen aus is.pl Fix für Bug 1642. Nebenwirkungen? jb 12.5.2011
221 # getestet: Lieferantenauftrag -> Rechnung i.O.
222 # Lieferantenauftrag -> Lieferschein -> Rechnung i.O.
223 # Werte: 20% (Lieferantenrabatt), 12,4% individuell und 0,4 individuell s.a.
224 # Screenshot zu Bug 1642
225 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
227 my ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
229 my $decimalplaces = ($dec > 2) ? $dec : 2;
231 $form->{"sellprice_$i"} =
232 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
235 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
236 $dec_qty = length $dec_qty;
239 $form->format_amount(\%myconfig, ($form->{"qty_$i"} * -1), $dec_qty);
241 $form->{rowcount} = $i;
245 $main::lxdebug->leave_sub();
249 $main::lxdebug->enter_sub();
251 my $form = $main::form;
252 my %myconfig = %main::myconfig;
253 my $locale = $main::locale;
254 my $cgi = $::request->{cgi};
256 $main::auth->assert('vendor_invoice_edit');
261 $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
262 $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
264 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
266 my @old_project_ids = ($form->{"globalproject_id"});
267 map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"};
269 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
271 "old_id" => \@old_project_ids },
272 "taxzones" => "ALL_TAXZONES",
273 "currencies" => "ALL_CURRENCIES",
274 "vendors" => "ALL_VENDORS",
275 "departments" => "all_departments",
276 "price_factors" => "ALL_PRICE_FACTORS");
278 $TMPL_VAR{ALL_EMPLOYEES} = SL::DB::Manager::Employee->get_all_sorted(query => [ or => [ id => $::form->{employee_id}, deleted => 0 ] ]);
279 $TMPL_VAR{ALL_CONTACTS} = SL::DB::Manager::Contact->get_all_sorted(query => [
281 cp_cv_id => $::form->{"$::form->{vc}_id"} * 1,
284 cp_id => $::form->{cp_id} * 1
288 $TMPL_VAR{department_labels} = sub { "$_[0]->{description}--$_[0]->{id}" };
291 $TMPL_VAR{vc_keys} = sub { "$_[0]->{name}--$_[0]->{id}" };
292 $TMPL_VAR{vclimit} = $myconfig{vclimit};
293 $TMPL_VAR{vc_select} = "customer_or_vendor_selection_window('vendor', '', 1, 0)";
294 push @custom_hiddens, "vendor_id";
295 push @custom_hiddens, "oldvendor";
296 push @custom_hiddens, "selectvendor";
298 # currencies and exchangerate
299 my @values = map { $_ } @{ $form->{ALL_CURRENCIES} };
300 my %labels = map { $_ => $_ } @{ $form->{ALL_CURRENCIES} };
301 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
302 # show_exchangerate is also later needed in another template
303 $form->{show_exchangerate} = $form->{currency} ne $form->{defaultcurrency};
304 $TMPL_VAR{currencies} = NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
305 '-values' => \@values, '-labels' => \%labels,
306 '-onchange' => "document.getElementById('update_button').click();"
307 )) if scalar @values;
308 push @custom_hiddens, "forex";
309 push @custom_hiddens, "exchangerate" if $form->{forex};
311 $TMPL_VAR{creditwarning} = ($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update};
312 $TMPL_VAR{is_credit_remaining_negativ} = $form->{creditremaining} =~ /-/;
314 my $follow_up_vc = $form->{vendor};
315 $follow_up_vc =~ s/--\d*\s*$//;
316 $TMPL_VAR{vendor_name} = $follow_up_vc;
318 # set option selected
319 foreach my $item (qw(AP)) {
320 $form->{"select$item"} =~ s/ selected//;
321 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
324 $TMPL_VAR{is_type_credit_note} = $form->{type} eq "credit_note";
325 $TMPL_VAR{is_format_html} = $form->{format} eq 'html';
326 $TMPL_VAR{dateformat} = $myconfig{dateformat};
327 $TMPL_VAR{numberformat} = $myconfig{numberformat};
330 $TMPL_VAR{HIDDENS} = [qw(
331 id action type media format queued printed emailed title vc discount
332 title creditlimit creditremaining tradediscount business closedto locked shipped storno storno_id
333 max_dunning_level dunning_amount
334 shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax
335 shiptoemail shiptodepartment_1 shiptodepartment_2 message email subject cc bcc taxaccounts cursor_fokus
336 convert_from_do_ids convert_from_oe_ids show_details gldate
338 map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts}];
340 $::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.SalesPurchase ckeditor/ckeditor ckeditor/adapters/jquery kivi.io));
344 print $form->parse_html_template("ir/form_header", \%TMPL_VAR);
346 $main::lxdebug->leave_sub();
350 $main::lxdebug->enter_sub();
352 my $form = $main::form;
353 my %myconfig = %main::myconfig;
354 my $locale = $main::locale;
356 $main::auth->assert('vendor_invoice_edit');
358 $form->{invtotal} = $form->{invsubtotal};
359 $form->{oldinvtotal} = $form->{invtotal};
362 $form->{rows} = max 2,
363 $form->numtextrows($form->{notes}, 26, 8),
364 $form->numtextrows($form->{intnotes}, 35, 8);
367 # tax, total and subtotal calculations
368 my ($tax, $subtotal);
369 $form->{taxaccounts_array} = [ split / /, $form->{taxaccounts} ];
371 foreach my $item (@{ $form->{taxaccounts_array} }) {
372 if ($form->{"${item}_base"}) {
373 if ($form->{taxincluded}) {
374 $form->{"${item}_total"} = $form->round_amount( ($form->{"${item}_base"} * $form->{"${item}_rate"}
375 / (1 + $form->{"${item}_rate"})), 2);
376 $form->{"${item}_netto"} = $form->round_amount( ($form->{"${item}_base"} - $form->{"${item}_total"}), 2);
378 $form->{"${item}_total"} = $form->round_amount( $form->{"${item}_base"} * $form->{"${item}_rate"}, 2);
379 $form->{invtotal} += $form->{"${item}_total"};
386 $form->{follow_ups} = FU->follow_ups('trans_id' => $form->{id}) || [];
387 $form->{follow_ups_unfinished} = ( sum map { $_->{due} * 1 } @{ $form->{follow_ups} } ) || 0;
392 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
393 $form->{paid_indices} = [ 1 .. $form->{paidaccounts} ];
395 # Standard Konto für Umlaufvermögen
396 my $accno_arap = IS->get_standard_accno_current_assets(\%myconfig, \%$form);
398 for my $i (1 .. $form->{paidaccounts}) {
399 $form->{"changeable_$i"} = 1;
400 if (SL::DB::Default->get->payments_changeable == 0) {
402 $form->{"changeable_$i"} = ($form->{"acc_trans_id_$i"})? 0 : 1;
403 } elsif (SL::DB::Default->get->payments_changeable == 2) {
405 $form->{"changeable_$i"} = (($form->{"gldate_$i"} eq '') ||
406 ($form->current_date(\%myconfig) eq $form->{"gldate_$i"}));
409 $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
410 if (!$form->{"AP_paid_$i"}) {
411 $form->{"selectAP_paid_$i"} =~ s/option>$accno_arap--(.*?)>/option selected>$accno_arap--$1>/;
413 $form->{"selectAP_paid_$i"} =~ s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
416 $totalpaid += $form->{"paid_$i"};
419 $form->{ALL_DELIVERY_TERMS} = SL::DB::Manager::DeliveryTerm->get_all_sorted();
421 print $form->parse_html_template('ir/form_footer', {
422 is_type_credit_note => ($form->{type} eq "credit_note"),
423 totalpaid => $totalpaid,
424 paid_missing => $form->{invtotal} - $totalpaid,
425 show_storno => $form->{id} && !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ap") && !$totalpaid,
426 show_delete => ($::instance_conf->get_ir_changeable == 2)
427 ? ($form->current_date(\%myconfig) eq $form->{gldate})
428 : ($::instance_conf->get_ir_changeable == 1),
430 ##print $form->parse_html_template('ir/_payments'); # parser
431 ##print $form->parse_html_template('webdav/_list'); # parser
433 $main::lxdebug->leave_sub();
437 $main::lxdebug->enter_sub();
439 my $form = $main::form;
440 my %myconfig = %main::myconfig;
442 $main::auth->assert('vendor_invoice_edit');
444 &mark_as_paid_common(\%myconfig,"ap");
446 $main::lxdebug->leave_sub();
450 $main::lxdebug->enter_sub();
452 my $form = $main::form;
453 my %myconfig = %main::myconfig;
455 $main::auth->assert('vendor_invoice_edit');
457 &check_name('vendor');
459 if (!$form->{forex}) { # read exchangerate from input field (not hidden)
460 $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate});
462 $form->{forex} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'sell');
463 $form->{exchangerate} = $form->{forex} if $form->{forex};
465 for my $i (1 .. $form->{paidaccounts}) {
466 next unless $form->{"paid_$i"};
467 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
468 $form->{"forex_$i"} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell');
469 $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
472 my $i = $form->{rowcount};
473 my $exchangerate = ($form->{exchangerate} * 1) || 1;
475 if ( ($form->{"partnumber_$i"} eq "")
476 && ($form->{"description_$i"} eq "")
477 && ($form->{"partsgroup_$i"} eq "")) {
478 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
483 IR->retrieve_item(\%myconfig, \%$form);
485 my $rows = scalar @{ $form->{item_list} };
488 $form->{"qty_$i"} = 1 unless $form->parse_amount(\%myconfig, $form->{"qty_$i"});
492 select_item(mode => 'IR');
497 # override sellprice if there is one entered
498 my $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
500 # ergaenzung fuer bug 736 Lieferanten-Rabatt auch in Einkaufsrechnungen vorbelegen jb
501 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{vendor_discount} * 100 );
502 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
503 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
505 $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
507 ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
508 my $dec_qty = length $1;
509 my $decimalplaces = max 2, $dec_qty;
512 $form->{"sellprice_$i"} = $sellprice;
514 my $record = _make_record();
515 my $price_source = SL::PriceSource->new(record_item => $record->items->[$i-1], record => $record);
516 my $best_price = $price_source->best_price;
517 my $best_discount = $price_source->best_discount;
520 $::form->{"sellprice_$i"} = $best_price->price;
521 $::form->{"active_price_source_$i"} = $best_price->source;
523 if ($best_discount) {
524 $::form->{"discount_$i"} = $best_discount->discount;
525 $::form->{"active_discount_source_$i"} = $best_discount->source;
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();
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 transaction above the maximum future booking date!'))
723 if ($form->date_max_future($invdate, \%myconfig));
724 $form->error($locale->text('Cannot post invoice for a closed period!'))
725 if ($invdate <= $closedto);
727 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
728 if ($form->{currency} ne $form->{defaultcurrency});
731 for $i (1 .. $form->{paidaccounts}) {
732 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
733 my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
735 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
737 $form->error($locale->text('Cannot post payment for a closed period!'))
738 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
740 if ($form->{currency} ne $form->{defaultcurrency}) {
741 $form->{"exchangerate_$i"} = $form->{exchangerate}
742 if ($invdate == $datepaid);
743 $form->isblank("exchangerate_$i",
744 $locale->text('Exchangerate for payment missing!'));
749 ($form->{AP}) = split /--/, $form->{AP};
750 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
751 $form->{storno} ||= 0;
753 $form->{id} = 0 if $form->{postasnew};
757 if (IR->post_invoice(\%myconfig, \%$form)){
759 if(!exists $form->{addition} && $form->{id} ne "") {
760 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
761 $form->{addition} = "POSTED";
762 #$form->{what_done} = $locale->text("Rechnungsnummer") . qq| | . $form->{invnumber};
765 # /saving the history
766 remove_draft() if $form->{remove_draft};
767 $form->redirect( $locale->text('Invoice')
768 . " $form->{invnumber} "
769 . $locale->text('posted!'));
771 $form->error($locale->text('Cannot post invoice!'));
773 $main::lxdebug->leave_sub();
777 $main::lxdebug->enter_sub();
779 my $form = $main::form;
780 my $locale = $main::locale;
782 $main::auth->assert('vendor_invoice_edit');
786 <form method=post action=$form->{script}>
789 # delete action variable
790 map { delete $form->{$_} } qw(action header);
792 foreach my $key (keys %$form) {
793 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
794 $form->{$key} =~ s/\"/"/g;
795 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
799 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
802 . $locale->text('Are you sure you want to delete Invoice Number')
803 . qq| $form->{invnumber}</h4>
805 <input name=action class=submit type=submit value="|
806 . $locale->text('Yes') . qq|">
810 $main::lxdebug->leave_sub();
814 $main::lxdebug->enter_sub();
816 my $form = $main::form;
817 my %myconfig = %main::myconfig;
818 my $locale = $main::locale;
820 $main::auth->assert('vendor_invoice_edit');
822 if (IR->delete_invoice(\%myconfig, \%$form)) {
824 if(!exists $form->{addition}) {
825 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
826 $form->{addition} = "DELETED";
829 # /saving the history
830 $form->redirect($locale->text('Invoice deleted!'));
832 $form->error($locale->text('Cannot delete invoice!'));
834 $main::lxdebug->leave_sub();
837 sub get_duedate_vendor {
838 $::lxdebug->enter_sub;
840 my $result = IR->get_duedate(
841 vendor_id => $::form->{vendor_id},
842 invdate => $::form->{invdate},
843 default => $::form->{old_duedate},
846 print $::form->ajax_response_header, $result;
847 $::lxdebug->leave_sub;