|  | #=====================================================================
 | 
  
    |  | # LX-Office ERP
 | 
  
    |  | # Copyright (C) 2004
 | 
  
    |  | # Based on SQL-Ledger Version 2.1.9
 | 
  
    |  | # Web http://www.lx-office.org
 | 
  
    |  | #
 | 
  
    |  | #=====================================================================
 | 
  
    |  | # SQL-Ledger, Accounting
 | 
  
    |  | # Copyright (c) 1998-2002
 | 
  
    |  | #
 | 
  
    |  | #  Author: Dieter Simader
 | 
  
    |  | #   Email: dsimader@sql-ledger.org
 | 
  
    |  | #     Web: http://www.sql-ledger.org
 | 
  
    |  | #
 | 
  
    |  | #
 | 
  
    |  | # This program is free software; you can redistribute it and/or modify
 | 
  
    |  | # it under the terms of the GNU General Public License as published by
 | 
  
    |  | # the Free Software Foundation; either version 2 of the License, or
 | 
  
    |  | # (at your option) any later version.
 | 
  
    |  | #
 | 
  
    |  | # This program is distributed in the hope that it will be useful,
 | 
  
    |  | # but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
  
    |  | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
  
    |  | # GNU General Public License for more details.
 | 
  
    |  | # You should have received a copy of the GNU General Public License
 | 
  
    |  | # along with this program; if not, write to the Free Software
 | 
  
    |  | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 | 
  
    |  | # MA 02110-1335, USA.
 | 
  
    |  | #======================================================================
 | 
  
    |  | #
 | 
  
    |  | # Inventory received module
 | 
  
    |  | #
 | 
  
    |  | #======================================================================
 | 
  
    |  | 
 | 
  
    |  | use SL::FU;
 | 
  
    |  | use SL::Helper::Flash qw(flash_later);
 | 
  
    |  | use SL::Helper::UserPreferences::DisplayPreferences;
 | 
  
    |  | use SL::IR;
 | 
  
    |  | use SL::IS;
 | 
  
    |  | use SL::DB::BankTransactionAccTrans;
 | 
  
    |  | use SL::DB::Default;
 | 
  
    |  | use SL::DB::Department;
 | 
  
    |  | use SL::DB::Project;
 | 
  
    |  | use SL::DB::PurchaseInvoice;
 | 
  
    |  | use SL::DB::Vendor;
 | 
  
    |  | use List::MoreUtils qw(uniq);
 | 
  
    |  | use List::Util qw(max sum);
 | 
  
    |  | use List::UtilsBy qw(sort_by);
 | 
  
    |  | "ir.pl.html#L647" data-txt="647">
 | 
 | 
  
    |  | sub block_or_unblock_sepa_transfer {
 | 
  
    |  |   $::auth->assert('ap_transactions');
 | 
  
    |  | 
 | 
  
    |  |   my $invoice = SL::DB::PurchaseInvoice->new(id => $::form->{id})->load;
 | 
  
    |  |   $invoice->update_attributes(is_sepa_blocked => 0) if  $::form->{unblock_sepa} &&  $invoice->is_sepa_blocked;
 | 
  
    |  |   $invoice->update_attributes(is_sepa_blocked => 1) if !$::form->{unblock_sepa} && !$invoice->is_sepa_blocked;
 | 
  
    |  | 
 | 
  
    |  |   $::form->redirect($::form->{unblock_sepa} ? t8('Bank transfer via SEPA is unblocked') : t8('Bank transfer via SEPA is blocked'));
 | 
  
    |  | }
 | 
  
    |  | 
 | 
  
    |  | sub show_draft {
 | 
  
    |  |   update();
 | 
  
    |  | }
 | 
  
    |  | 
 | 
  
    |  | sub update {
 | 
  
    |  |   $main::lxdebug->enter_sub();
 | 
  
    |  | 
 | 
  
    |  |   my $form     = $main::form;
 | 
  
    |  |   my %myconfig = %main::myconfig;
 | 
  
    |  | 
 | 
  
    |  |   $main::auth->assert('vendor_invoice_edit');
 | 
  
    |  | 
 | 
  
    |  |   if (($form->{previous_vendor_id} || $form->{vendor_id}) != $form->{vendor_id}) {
 | 
  
    |  |     IR->get_vendor(\%myconfig, $form);
 | 
  
    |  |   }
 | 
  
    |  |   #
 | 
  
    |  |   $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
 | 
  
    |  |   if ($form->{defaultcurrency} ne $form->{currency}) {
 | 
  
    |  |     if ($form->{exchangerate}) { # user input OR first default ->  leave this value
 | 
  
    |  |       $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate});
 | 
  
    |  |       # does this differ from daily default?
 | 
  
    |  |       my $current_daily_rate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'sell');
 | 
  
    |  |       $form->{record_forex}  = $current_daily_rate > 0 && $current_daily_rate != $form->{exchangerate}
 | 
  
    |  |                            ?   1 : 0;
 | 
  
    |  |     } else {                     # no value, but get defaults -> maybe user changes invdate as well ...
 | 
  
    |  |       ($form->{exchangerate}, $form->{record_forex}) = $form->check_exchangerate(\%myconfig, $form->{currency},
 | 
  
    |  |                                                                                  $form->{invdate}, 'sell', $form->{id}, 'ap');
 | 
  
    |  |     }
 | 
  
    |  |   }
 | 
  
    |  |   for my $i (1 .. $form->{paidaccounts}) {
 | 
  
    |  |     next unless $form->{"paid_$i"};
 | 
  
    |  |     map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
 | 
  
    |  |     $form->{"forex_$i"}        = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell') unless $form->{"record_forex_$i"};
 | 
  
    |  |     $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
 | 
  
    |  |   }
 | 
  
    |  | 
 | 
  
    |  |   my $i            = $form->{rowcount};
 | 
  
    |  |   my $exchangerate = ($form->{exchangerate} * 1) || 1;
 | 
  
    |  | 
 | 
  
    |  |   if (   ($form->{"partnumber_$i"} eq "")
 | 
  
    |  |       && ($form->{"description_$i"} eq "")
 | 
  
    |  |       && ($form->{"partsgroup_$i"} eq "")) {
 | 
  
    |  |     $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
 | 
  
    |  |     &check_form;
 | 
  
    |  | 
 | 
  
    |  |   } else {
 | 
  
    |  | 
 | 
  
    |  |     IR->retrieve_item(\%myconfig, \%$form);
 | 
  
    |  | 
 | 
  
    |  |     my $rows = scalar @{ $form->{item_list} };
 | 
  
    |  | 
 | 
  
    |  |     $form->{"discount_$i"}   = $form->parse_amount(\%myconfig, $form->{"discount_$i"}) / 100.0;
 | 
  
    |  |     $form->{"discount_$i"} ||= $form->{vendor_discount};
 | 
  
    |  | 
 | 
  
    |  |     if ($rows) {
 | 
  
    |  |       $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
 | 
  
    |  |       if( !$form->{"qty_$i"} ) {
 | 
  
    |  |         $form->{"qty_$i"} = 1;
 | 
  
    |  |       }
 | 
  
    |  | 
 | 
  
    |  |       if ($rows > 1) {
 | 
  
    |  | 
 | 
  
    |  |         select_item(mode => 'IR', pre_entered_qty => $form->{"qty_$i"});
 | 
  
    |  |         $::dispatcher->end_request;
 | 
  
    |  | 
 | 
  
    |  |       } else {
 | 
  
    |  | 
 | 
  
    |  |         # override sellprice if there is one entered
 | 
  
    |  |         my $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
 | 
  
    |  | 
 | 
  
    |  |         map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
 | 
  
    |  |         map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
 | 
  
    |  | 
 | 
  
    |  |         $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
 | 
  
    |  | 
 | 
  
    |  |         ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
 | 
  
    |  |         my $dec_qty       = length $1;
 | 
  
    |  |         my $decimalplaces = max 2, $dec_qty;
 | 
  
    |  | 
 | 
  
    |  |         if ($sellprice) {
 | 
  
    |  |           $form->{"sellprice_$i"} = $sellprice;
 | 
  
    |  |         } else {
 | 
  
    |  |           my $record        = _make_record();
 | 
  
    |  |           my $price_source  = SL::PriceSource->new(record_item => $record->items->[$i-1], record => $record);
 | 
  
    |  |           my $best_price    = $price_source->best_price;
 | 
  
    |  |           my $best_discount = $price_source->best_discount;
 | 
  
    |  | 
 | 
  
    |  |           if ($best_price) {
 | 
  
    |  |             $::form->{"sellprice_$i"}           = $best_price->price;
 | 
  
    |  |             $::form->{"active_price_source_$i"} = $best_price->source;
 | 
  
    |  |           }
 | 
  
    |  |           if ($best_discount) {
 | 
  
    |  |             $::form->{"discount_$i"}               = $best_discount->discount;
 | 
  
    |  |             $::form->{"active_discount_source_$i"} = $best_discount->source;
 | 
  
    |  |           }
 | 
  
    |  | 
 | 
  
    |  |           # if there is an exchange rate adjust sellprice
 | 
  
    |  |           $form->{"sellprice_$i"} /= $exchangerate;
 | 
  
    |  |         }
 | 
  
    |  | 
 | 
  
    |  |         my $amount                = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"});
 | 
  
    |  |         $form->{creditremaining} -= $amount;
 | 
  
    |  |         $form->{"sellprice_$i"}   = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
 | 
  
    |  |         $form->{"qty_$i"}         = $form->format_amount(\%myconfig, $form->{"qty_$i"},       $dec_qty);
 | 
  
    |  |         $form->{"discount_$i"}    = $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100.0);
 | 
  
    |  |       }
 | 
  
    |  | 
 | 
  
    |  |       &display_form;
 | 
  
    |  | 
 | 
  
    |  |     } else {
 | 
  
    |  | 
 | 
  
    |  |       # ok, so this is a new part
 | 
  
    |  |       # ask if it is a part or service item
 | 
  
    |  | 
 | 
  
    |  |       if (   $form->{"partsgroup_$i"}
 | 
  
    |  |           && ($form->{"partsnumber_$i"} eq "")
 | 
  
    |  |           && ($form->{"description_$i"} eq "")) {
 | 
  
    |  |         $form->{rowcount}--;
 | 
  
    |  |         $form->{"discount_$i"} = "";
 | 
  
    |  |         display_form();
 | 
  
    |  | 
 | 
  
    |  |       } else {
 | 
  
    |  |         $form->{"id_$i"}   = 0;
 | 
  
    |  |         new_item();
 | 
  
    |  |       }
 | 
  
    |  |     }
 | 
  
    |  |   }
 | 
  
    |  |   $main::lxdebug->leave_sub();
 | 
  
    |  | }
 | 
  
    |  | 
 | 
  
    |  | sub storno {
 | 
  
    |  |   $main::lxdebug->enter_sub();
 | 
  
    |  | 
 | 
  
    |  |   my $form     = $main::form;
 | 
  
    |  |   my %myconfig = %main::myconfig;
 | 
  
    |  |   my $locale   = $main::locale;
 | 
  
    |  | 
 | 
  
    |  |   $main::auth->assert('vendor_invoice_edit');
 | 
  
    |  | 
 | 
  
    |  |   if ($form->{storno}) {
 | 
  
    |  |     $form->error($locale->text('Cannot storno storno invoice!'));
 | 
  
    |  |   }
 | 
  
    |  | 
 | 
  
    |  |   if (IS->has_storno(\%myconfig, $form, "ap")) {
 | 
  
    |  |     $form->error($locale->text("Invoice has already been storno'd!"));
 | 
  
    |  |   }
 | 
  
    |  | 
 | 
  
    |  |   $form->error($locale->text('Cannot post storno for a closed period!'))
 | 
  
    |  |     if ( $form->date_closed($form->{invdate}, \%myconfig));
 | 
  
    |  | 
 | 
  
    |  |   my $employee_id = $form->{employee_id};
 | 
  
    |  |   invoice_links();
 | 
  
    |  |   prepare_invoice();
 | 
  
    |  |   relink_accounts();
 | 
  
    |  | 
 | 
  
    |  |   # Payments must not be recorded for the new storno invoice.
 | 
  
    |  |   $form->{paidaccounts} = 0;
 | 
  
    |  |   map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ gldate_ acc_trans_id_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
 | 
  
    |  |   # set new ids for storno invoice
 | 
  
    |  |   # set new persistent ids for storno invoice items
 | 
  
    |  |   $form->{"converted_from_invoice_id_$_"} = delete $form->{"invoice_id_$_"} for 1 .. $form->{"rowcount"};
 | 
  
    |  | 
 | 
  
    |  |   # saving the history
 | 
  
    |  |   if(!exists $form->{addition} && $form->{id} ne "") {
 | 
  
    |  |     $form->{snumbers}  = qq|invnumber_| . $form->{invnumber};
 | 
  
    |  |     $form->{what_done} = "invoice";
 | 
  
    |  |     $form->{addition}  = "CANCELED";
 | 
  
    |  |     $form->save_history;
 | 
  
    |  |   }
 | 
  
    |  |   # /saving the history
 | 
  
    |  | 
 | 
  
    |  |   # record link invoice to storno
 | 
  
    |  |   $form->{convert_from_ap_ids} = $form->{id};
 | 
  
    |  |   $form->{storno_id} = $form->{id};
 | 
  
    |  |   $form->{storno} = 1;
 | 
  
    |  |   $form->{id} = "";
 | 
  
    |  |   $form->{invnumber} = "Storno zu " . $form->{invnumber};
 | 
  
    |  |   $form->{rowcount}++;
 | 
  
    |  |   $form->{employee_id} = $employee_id;
 | 
  
    |  |   # post expects the field as user input
 | 
  
    |  |   $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
 | 
  
    |  | 
 | 
  
    |  |   post();
 | 
  
    |  |   $main::lxdebug->leave_sub();
 | 
  
    |  | 
 | 
  
    |  | }
 | 
  
    |  | 
 | 
  
    |  | sub use_as_new {
 | 
  
    |  |   $main::lxdebug->enter_sub();
 | 
  
    |  | 
 | 
  
    |  |   my $form     = $main::form;
 | 
  
    |  |   my %myconfig = %main::myconfig;
 | 
  
    |  | 
 | 
  
    |  |   $main::auth->assert('vendor_invoice_edit');
 | 
  
    |  | 
 | 
  
    |  |   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);
 | 
  
    |  |   $form->{paidaccounts} = 1;
 | 
  
    |  |   $form->{rowcount}--;
 | 
  
    |  |   $form->{invdate} = $form->current_date(\%myconfig);
 | 
  
    |  | 
 | 
  
    |  |   $form->{"converted_from_invoice_id_$_"} = delete $form->{"invoice_id_$_"} for 1 .. $form->{"rowcount"};
 | 
  
    |  | 
 | 
  
    |  |   $form->{exchangerate} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'sell');
 | 
  
    |  |   $form->{useasnew} = 1;
 | 
  
    |  |   &display_form;
 | 
  
    |  | 
 | 
  
    |  |   $main::lxdebug->leave_sub();
 | 
  
    |  | }
 | 
  
    |  | 
 | 
  
    |  | sub post_payment {
 | 
  
    |  |   $main::lxdebug->enter_sub();
 | 
  
    |  | 
 | 
  
    |  |   my $form     = $main::form;
 | 
  
    |  |   my %myconfig = %main::myconfig;
 | 
  
    |  |   my $locale   = $main::locale;
 | 
  
    |  | 
 | 
  
    |  |   $main::auth->assert('vendor_invoice_edit');
 | 
  
    |  | 
 | 
  
    |  |   $form->mtime_ischanged('ap') ;
 | 
  
    |  |   $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
 | 
  
    |  |   for my $i (1 .. $form->{paidaccounts}) {
 | 
  
    |  |     if ($form->{"paid_$i"}) {
 | 
  
    |  |       my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
 | 
  
    |  | 
 | 
  
    |  |       $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
 | 
  
    |  | 
 | 
  
    |  |       $form->error($locale->text('Cannot post transaction above the maximum future booking date!'))
 | 
  
    |  |         if ($form->date_max_future($form->{"datepaid_$i"}, \%myconfig));
 | 
  
    |  | 
 | 
  
    |  |       #Zusätzlich noch das Buchungsdatum in die Bücherkontrolle einbeziehen
 | 
  
    |  |       # (Dient zur Prüfung ob ZE oder ZA geprüft werden soll)
 | 
  
    |  |       $form->error($locale->text('Cannot post payment for a closed period!'))
 | 
  
    |  |         if ($form->date_closed($form->{"datepaid_$i"})  && !$form->date_closed($form->{"gldate_$i"}, \%myconfig));
 | 
  
    |  | 
 | 
  
    |  |       if ($form->{currency} ne $form->{defaultcurrency}) {
 | 
  
    |  | #        $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid); # invdate isn't set here
 | 
  
    |  |         $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
 | 
  
    |  |       }
 | 
  
    |  |     }
 | 
  
    |  |   }
 | 
  
    |  | 
 | 
  
    |  |   ($form->{AP})      = split /--/, $form->{AP};
 | 
  
    |  |   ($form->{AP_paid}) = split /--/, $form->{AP_paid};
 | 
  
    |  |   if (IR->post_payment(\%myconfig, \%$form)){
 | 
  
    |  |     if (!exists $form->{addition} && $form->{id} ne "") {
 | 
  
    |  |       # saving the history
 | 
  
    |  |       $form->{snumbers}  = qq|invnumber_| . $form->{invnumber};
 | 
  
    |  |       $form->{addition}  = "PAYMENT POSTED";
 | 
  
    |  |       $form->{what_done} = "invoice";
 | 
  
    |  |       $form->save_history;
 | 
  
    |  |       # /saving the history
 | 
  
    |  |     }
 | 
  
    |  | 
 | 
  
    |  |     $form->redirect($locale->text('Payment posted!'));
 | 
  
    |  |   }
 | 
  
    |  | 
 | 
  
    |  |   $form->error($locale->text('Cannot post payment!'));
 | 
  
    |  | 
 | 
  
    |  |   $main::lxdebug->leave_sub();
 | 
  
    |  | }
 | 
  
    |  | 
 | 
  
    |  | sub _max_datepaid {
 | 
  
    |  |   my $form  =  $main::form;
 | 
  
    |  | 
 | 
  
    |  |   my @dates = sort { $b->[1] cmp $a->[1] }
 | 
  
    |  |               map  { [ $_, $main::locale->reformat_date(\%main::myconfig, $_, 'yyyy-mm-dd') ] }
 | 
  
    |  |               grep { $_ }
 | 
  
    |  |               map  { $form->{"datepaid_${_}"} }
 | 
  
    |  |               (1..$form->{rowcount});
 | 
  
    |  | 
 | 
  
    |  |   return @dates ? $dates[0]->[0] : undef;
 | 
  
    |  | }
 | 
  
    |  | 
 | 
  
    |  | 
 | 
  
    |  | sub post {
 | 
  
    |  |   $main::lxdebug->enter_sub();
 | 
  
    |  | 
 | 
  
    |  |   my $form     = $main::form;
 | 
  
    |  |   my %myconfig = %main::myconfig;
 | 
  
    |  |   my $locale   = $main::locale;
 | 
  
    |  | 
 | 
  
    |  |   $main::auth->assert('vendor_invoice_edit');
 | 
  
    |  | 
 | 
  
    |  |   $form->mtime_ischanged('ap');
 | 
  
    |  |   $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
 | 
  
    |  | 
 | 
  
    |  |   $form->isblank("invdate",   $locale->text('Invoice Date missing!'));
 | 
  
    |  |   $form->isblank("vendor_id", $locale->text('Vendor missing!'));
 | 
  
    |  |   $form->isblank("invnumber", $locale->text('Invnumber missing!'));
 | 
  
    |  | 
 | 
  
    |  |   $form->{invnumber} =~ s/^\s*//g;
 | 
  
    |  |   $form->{invnumber} =~ s/\s*$//g;
 | 
  
    |  | 
 | 
  
    |  |   # if the vendor changed get new values
 | 
  
    |  |   if (($form->{previous_vendor_id} || $form->{vendor_id}) != $form->{vendor_id}) {
 | 
  
    |  |     &update;
 | 
  
    |  |     $::dispatcher->end_request;
 | 
  
    |  |   }
 | 
  
    |  | 
 | 
  
    |  |   if ($myconfig{mandatory_departments} && !$form->{department_id}) {
 | 
  
    |  |     $form->{saved_message} = $::locale->text('You have to specify a department.');
 | 
  
    |  |     update();
 | 
  
    |  |     exit;
 | 
  
    |  |   }
 | 
  
    |  | 
 | 
  
    |  |   remove_emptied_rows();
 | 
  
    |  |   &validate_items;
 | 
  
    |  | 
 | 
  
    |  |   my $closedto     = $form->datetonum($form->{closedto}, \%myconfig);
 | 
  
    |  |   my $invdate      = $form->datetonum($form->{invdate},  \%myconfig);
 | 
  
    |  |   my $max_datepaid = _max_datepaid();
 | 
  
    |  | 
 | 
  
    |  |   $form->error($locale->text('Cannot post transaction above the maximum future booking date!'))
 | 
  
    |  |     if ($form->date_max_future($invdate, \%myconfig));
 | 
  
    |  |   $form->error($locale->text('Cannot post invoice for a closed period!'))
 | 
  
    |  |     if ($invdate <= $closedto);
 | 
  
    |  | 
 | 
  
    |  |   if ($form->{currency} ne $form->{defaultcurrency}) {
 | 
  
    |  |     $form->isblank("exchangerate", $locale->text('Exchangerate missing!'));
 | 
  
    |  |     $form->error($locale->text('Cannot post invoice with negative exchange rate'))
 | 
  
    |  |       unless ($form->parse_amount(\%myconfig, $form->{"exchangerate"}) > 0);
 | 
  
    |  |   }
 | 
  
    |  |   my $i;
 | 
  
    |  |   for $i (1 .. $form->{paidaccounts}) {
 | 
  
    |  |     if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
 | 
  
    |  |       my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
 | 
  
    |  | 
 | 
  
    |  |       $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
 | 
  
    |  | 
 | 
  
    |  |       $form->error($locale->text('Cannot post transaction above the maximum future booking date!'))
 | 
  
    |  |         if ($form->date_max_future($form->{"datepaid_$i"}, \%myconfig));
 | 
  
    |  | 
 | 
  
    |  |       #Zusätzlich noch das Buchungsdatum in die Bücherkontrolle einbeziehen
 | 
  
    |  |       # (Dient zur Prüfung ob ZE oder ZA geprüft werden soll)
 | 
  
    |  |       $form->error($locale->text('Cannot post payment for a closed period!'))
 | 
  
    |  |         if ($form->date_closed($form->{"datepaid_$i"})  && !$form->date_closed($form->{"gldate_$i"}, \%myconfig));
 | 
  
    |  | 
 | 
  
    |  |       if ($form->{currency} ne $form->{defaultcurrency}) {
 | 
  
    |  |         $form->{"exchangerate_$i"} = $form->{exchangerate}
 | 
  
    |  |           if ($invdate == $datepaid);
 | 
  
    |  |         $form->isblank("exchangerate_$i",
 | 
  
    |  |                        $locale->text('Exchangerate for payment missing!'));
 | 
  
    |  |       }
 | 
  
    |  |     }
 | 
  
    |  |   }
 | 
  
    |  | 
 | 
  
    |  |   ($form->{AP})      = split /--/, $form->{AP};
 | 
  
    |  |   ($form->{AP_paid}) = split /--/, $form->{AP_paid};
 | 
  
    |  |   $form->{storno}  ||= 0;
 | 
  
    |  | 
 | 
  
    |  |   $form->{id} = 0 if $form->{postasnew};
 | 
  
    |  | 
 | 
  
    |  | 
 | 
  
    |  |   relink_accounts();
 | 
  
    |  |   if (IR->post_invoice(\%myconfig, \%$form)){
 | 
  
    |  |     # saving the history
 | 
  
    |  |     if(!exists $form->{addition} && $form->{id} ne "") {
 | 
  
    |  |       $form->{snumbers}  = qq|invnumber_| . $form->{invnumber};
 | 
  
    |  |       $form->{addition}  = "POSTED";
 | 
  
    |  |       $form->{what_done} = 'invoice';
 | 
  
    |  |       $form->save_history;
 | 
  
    |  |     }
 | 
  
    |  |     # /saving the history
 | 
  
    |  | 
 | 
  
    |  |     my $redirect_url;
 | 
  
    |  |     if ('doc-tab' eq $form->{after_action}) {
 | 
  
    |  |       $redirect_url = build_std_url("script=ir.pl", 'action=edit', 'id=' . E($form->{id}), 'fragment=ui-tabs-docs');
 | 
  
    |  |     } else {
 | 
  
    |  |       $redirect_url = build_std_url("script=ir.pl", 'action=edit', 'id=' . E($form->{id}));
 | 
  
    |  |     }
 | 
  
    |  |     SL::Helper::Flash::flash_later('info',
 | 
  
    |  |                                    $locale->text('Invoice')
 | 
  
    |  |                                    . " $form->{invnumber} "
 | 
  
    |  |                                    . ", " . $locale->text('ID')
 | 
  
    |  |                                    . ': ' . $form->{id} . ' '
 | 
  
    |  |                                    . $locale->text('posted!'));
 | 
  
    |  |     print $form->redirect_header($redirect_url);
 | 
  
    |  |     $::dispatcher->end_request;
 | 
  
    |  |   }
 | 
  
    |  |   $form->error($locale->text('Cannot post invoice!'));
 | 
  
    |  | 
 | 
  
    |  |   $main::lxdebug->leave_sub();
 | 
  
    |  | }
 | 
  
    |  | 
 | 
  
    |  | sub delete {
 | 
  
    |  |   $main::lxdebug->enter_sub();
 | 
  
    |  | 
 | 
  
    |  |   my $form     = $main::form;
 | 
  
    |  |   my $locale   = $main::locale;
 | 
  
    |  | 
 | 
  
    |  |   $main::auth->assert('vendor_invoice_edit');
 | 
  
    |  | 
 | 
  
    |  |   $form->header;
 | 
  
    |  |   print qq|
 | 
  
    |  | <form method=post action=$form->{script}>
 | 
  
    |  | |;
 | 
  
    |  | 
 | 
  
    |  |   # delete action variable
 | 
  
    |  |   map { delete $form->{$_} } qw(action header);
 | 
  
    |  | 
 | 
  
    |  |   foreach my $key (keys %$form) {
 | 
  
    |  |     next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
 | 
  
    |  |     $form->{$key} =~ s/\"/"/g;
 | 
  
    |  |     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
 | 
  
    |  |   }
 | 
  
    |  | 
 | 
  
    |  |   print qq|
 | 
  
    |  | <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
 | 
  
    |  | 
 | 
  
    |  | <h4>|
 | 
  
    |  |     . $locale->text('Are you sure you want to delete Invoice Number')
 | 
  
    |  |     . qq| $form->{invnumber}</h4>
 | 
  
    |  | <p>
 | 
  
    |  | <input name=action class=submit type=submit value="|
 | 
  
    |  |     . $locale->text('Yes') . qq|">
 | 
  
    |  | </form>
 | 
  
    |  | |;
 | 
  
    |  | 
 | 
  
    |  |   $main::lxdebug->leave_sub();
 | 
  
    |  | }
 | 
  
    |  | 
 | 
  
    |  | sub display_form {
 | 
  
    |  |   $::lxdebug->enter_sub;
 | 
  
    |  | 
 | 
  
    |  |   _assert_access();
 | 
  
    |  | 
 | 
  
    |  |   relink_accounts();
 | 
  
    |  | 
 | 
  
    |  |   my $new_rowcount = $::form->{"rowcount"} * 1 + 1;
 | 
  
    |  |   $::form->{"project_id_${new_rowcount}"} = $::form->{"globalproject_id"};
 | 
  
    |  | 
 | 
  
    |  |   $::form->language_payment(\%::myconfig);
 | 
  
    |  | 
 | 
  
    |  |   Common::webdav_folder($::form);
 | 
  
    |  | 
 | 
  
    |  |   form_header();
 | 
  
    |  |   display_row(++$::form->{rowcount});
 | 
  
    |  |   form_footer();
 | 
  
    |  | 
 | 
  
    |  |   $::lxdebug->leave_sub;
 | 
  
    |  | }
 | 
  
    |  | 
 | 
  
    |  | sub yes {
 | 
  
    |  |   $main::lxdebug->enter_sub();
 | 
  
    |  | 
 | 
  
    |  |   my $form     = $main::form;
 | 
  
    |  |   my %myconfig = %main::myconfig;
 | 
  
    |  |   my $locale   = $main::locale;
 | 
  
    |  | 
 | 
  
    |  |   $main::auth->assert('vendor_invoice_edit');
 | 
  
    |  | 
 | 
  
    |  |   if (IR->delete_invoice(\%myconfig, \%$form)) {
 | 
  
    |  |     # saving the history
 | 
  
    |  |     if(!exists $form->{addition}) {
 | 
  
    |  |       $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
 | 
  
    |  |       $form->{addition} = "DELETED";
 | 
  
    |  |       $form->save_history;
 | 
  
    |  |     }
 | 
  
    |  |     # /saving the history
 | 
  
    |  |     $form->redirect($locale->text('Invoice deleted!'));
 | 
  
    |  |   }
 | 
  
    |  |   $form->error($locale->text('Cannot delete invoice!'));
 | 
  
    |  | 
 | 
  
    |  |   $main::lxdebug->leave_sub();
 | 
  
    |  | }
 | 
  
    |  | 
 | 
  
    |  | sub get_duedate_vendor {
 | 
  
    |  |   $::lxdebug->enter_sub;
 | 
  
    |  | 
 | 
  
    |  |   my $result = IR->get_duedate(
 | 
  
    |  |     vendor_id => $::form->{vendor_id},
 | 
  
    |  |     invdate   => $::form->{invdate},
 | 
  
    |  |     default   => $::form->{old_duedate},
 | 
  
    |  |   );
 | 
  
    |  | 
 | 
  
    |  |   print $::form->ajax_response_header, $result;
 | 
  
    |  |   $::lxdebug->leave_sub;
 | 
  
    |  | }
 |