kivitendo/bin/mozilla/ir.pl @ a19bbbbc
d319704a | Moritz Bunkus | #=====================================================================
|
||
# 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
|
||||
f7b15d43 | Christian Wittmer | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
# MA 02110-1335, USA.
|
||||
d319704a | Moritz Bunkus | #======================================================================
|
||
#
|
||||
# Inventory received module
|
||||
#
|
||||
#======================================================================
|
||||
7a7f33b5 | Moritz Bunkus | use SL::FU;
|
||
f850f64b | Bernd Bleßmann | use SL::Helper::Flash qw(flash_later);
|
||
94f5cb15 | Bernd Bleßmann | use SL::Helper::UserPreferences::DisplayPreferences;
|
||
d319704a | Moritz Bunkus | use SL::IR;
|
||
a1a3bfd8 | Moritz Bunkus | use SL::IS;
|
||
b3259be1 | Jan Büren | use SL::DB::BankTransactionAccTrans;
|
||
2e2873a4 | Werner Hahn | use SL::DB::Chart;
|
||
97954312 | Bernd Bleßmann | use SL::DB::Default;
|
||
da413cb1 | Moritz Bunkus | use SL::DB::Department;
|
||
70220684 | Moritz Bunkus | use SL::DB::Project;
|
||
ba85807b | Moritz Bunkus | use SL::DB::PurchaseInvoice;
|
||
1927b931 | Bernd Bleßmann | use SL::DB::ValidityToken;
|
||
1dbba310 | Moritz Bunkus | use SL::DB::Vendor;
|
||
fc3b49d6 | Tamino Steinert | use SL::DB::Tax;
|
||
use SL::DB::Chart;
|
||||
70220684 | Moritz Bunkus | use List::MoreUtils qw(uniq);
|
||
7a7f33b5 | Moritz Bunkus | use List::Util qw(max sum);
|
||
0d37f1e8 | Moritz Bunkus | use List::UtilsBy qw(sort_by);
|
||
d319704a | Moritz Bunkus | |||
d629acd8 | Sven Schöling | require "bin/mozilla/io.pl";
|
||
require "bin/mozilla/common.pl";
|
||||
d319704a | Moritz Bunkus | |||
1668bc2d | Sven Schöling | use strict;
|
||
d319704a | Moritz Bunkus | 1;
|
||
# end of main
|
||||
894ac4ca | Moritz Bunkus | sub _may_view_or_edit_this_invoice {
|
||
d53d7a0a | Bernd Bleßmann | return 1 if $::auth->assert('ap_transactions', 1); # may edit all invoices
|
||
return 0 if !$::form->{id}; # creating new invoices isn't allowed without invoice_edit
|
||||
return 1 if $::auth->assert('purchase_invoice_view', 1); # viewing is allowed with this right
|
||||
return 0 if !$::form->{globalproject_id}; # existing records without a project ID are not allowed
|
||||
894ac4ca | Moritz Bunkus | return SL::DB::Project->new(id => $::form->{globalproject_id})->load->may_employee_view_project_invoices(SL::DB::Manager::Employee->current);
|
||
}
|
||||
sub _assert_access {
|
||||
my $cache = $::request->cache('ap.pl::_assert_access');
|
||||
$cache->{_may_view_or_edit_this_invoice} = _may_view_or_edit_this_invoice() if !exists $cache->{_may_view_or_edit_this_invoice};
|
||||
$::form->show_generic_error($::locale->text("You do not have the permissions to access this function.")) if ! $cache->{_may_view_or_edit_this_invoice};
|
||||
}
|
||||
d319704a | Moritz Bunkus | sub add {
|
||
1668bc2d | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
my $locale = $main::locale;
|
||||
58b14f96 | Stephan Köhler | |||
1668bc2d | Sven Schöling | $main::auth->assert('vendor_invoice_edit');
|
||
8c7e4493 | Moritz Bunkus | |||
f775b88a | Moritz Bunkus | if (!$::instance_conf->get_allow_new_purchase_invoice) {
|
||
$::form->show_generic_error($::locale->text("You do not have the permissions to access this function."));
|
||||
}
|
||||
519f43a2 | Moritz Bunkus | $form->{show_details} = $::myconfig{show_form_details};
|
||
4b937d1a | Sven Donath | $form->{title} = $locale->text('Record Vendor Invoice');
|
||
d319704a | Moritz Bunkus | |||
1927b931 | Bernd Bleßmann | if (!$form->{form_validity_token}) {
|
||
$form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_PURCHASE_INVOICE_POST())->token;
|
||||
}
|
||||
d319704a | Moritz Bunkus | &invoice_links;
|
||
&prepare_invoice;
|
||||
&display_form;
|
||||
1668bc2d | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
sub edit {
|
||||
1668bc2d | Sven Schöling | $main::lxdebug->enter_sub();
|
||
6ebad56e | Moritz Bunkus | |||
894ac4ca | Moritz Bunkus | # Delay access check to after the invoice's been loaded in
|
||
# "create_links" so that project-specific invoice rights can be
|
||||
# evaluated.
|
||||
1668bc2d | Sven Schöling | my $form = $main::form;
|
||
my $locale = $main::locale;
|
||||
519f43a2 | Moritz Bunkus | $form->{show_details} = $::myconfig{show_form_details};
|
||
ec93aab7 | Thomas Kasulke | # show history button
|
||
$form->{javascript} = qq|<script type=text/javascript src=js/show_history.js></script>|;
|
||||
#/show hhistory button
|
||||
f83ca506 | Sven Schöling | |||
d319704a | Moritz Bunkus | $form->{title} = $locale->text('Edit Vendor Invoice');
|
||
&invoice_links;
|
||||
&prepare_invoice;
|
||||
&display_form;
|
||||
1668bc2d | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
sub invoice_links {
|
||||
1668bc2d | Sven Schöling | $main::lxdebug->enter_sub();
|
||
894ac4ca | Moritz Bunkus | # Delay access check to after the invoice's been loaded so that
|
||
# project-specific invoice rights can be evaluated.
|
||||
1668bc2d | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
58b14f96 | Stephan Köhler | |||
67b0f6a6 | Sven Schöling | $form->{vc} = 'vendor';
|
||
d319704a | Moritz Bunkus | # create links
|
||
$form->create_links("AP", \%myconfig, "vendor");
|
||||
894ac4ca | Moritz Bunkus | _assert_access();
|
||
c102d51f | Bernd Bleßmann | $form->backup_vars(qw(payment_id language_id taxzone_id
|
||
currency delivery_term_id intnotes cp_id));
|
||||
d319704a | Moritz Bunkus | |||
IR->get_vendor(\%myconfig, \%$form);
|
||||
IR->retrieve_invoice(\%myconfig, \%$form);
|
||||
f83ca506 | Sven Schöling | |||
c102d51f | Bernd Bleßmann | $form->restore_vars(qw(payment_id language_id taxzone_id
|
||
currency delivery_term_id intnotes cp_id));
|
||||
d319704a | Moritz Bunkus | |||
d331a3d7 | Niclas Zimmermann | my @curr = $form->get_all_currencies();
|
||
d319704a | Moritz Bunkus | map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
|
||
# forex
|
||||
$form->{forex} = $form->{exchangerate};
|
||||
1668bc2d | Sven Schöling | my $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
|
||
d319704a | Moritz Bunkus | |||
1668bc2d | Sven Schöling | foreach my $key (keys %{ $form->{AP_links} }) {
|
||
d319704a | Moritz Bunkus | |||
1668bc2d | Sven Schöling | foreach my $ref (@{ $form->{AP_links}{$key} }) {
|
||
0e0ff150 | Jan Büren | $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}</option>";
|
||
d319704a | Moritz Bunkus | }
|
||
56e9d812 | Sven Schöling | next unless $form->{acc_trans}{$key};
|
||
d319704a | Moritz Bunkus | if ($key eq "AP_paid") {
|
||
1668bc2d | Sven Schöling | for my $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
|
||
d319704a | Moritz Bunkus | $form->{"AP_paid_$i"} =
|
||
"$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
|
||||
b56c0cd7 | Bernd Bleßmann | $form->{"acc_trans_id_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{acc_trans_id};
|
||
d319704a | Moritz Bunkus | # reverse paid
|
||
$form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount};
|
||||
$form->{"datepaid_$i"} =
|
||||
$form->{acc_trans}{$key}->[$i - 1]->{transdate};
|
||||
b56c0cd7 | Bernd Bleßmann | $form->{"gldate_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{gldate};
|
||
d319704a | Moritz Bunkus | $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
|
||
$form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
|
||||
$form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
|
||||
$form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
|
||||
$form->{paidaccounts} = $i;
|
||||
607163f5 | Jan Büren | # hook for calc of of fx_paid and check if banktransaction has a record exchangerate
|
||
if ($form->{"exchangerate_$i"}) {
|
||||
my $bt_acc_trans = SL::DB::Manager::BankTransactionAccTrans->find_by(acc_trans_id => $form->{"acc_trans_id_$i"});
|
||||
if ($bt_acc_trans) {
|
||||
if ($bt_acc_trans->bank_transaction->exchangerate > 0) {
|
||||
$form->{"exchangerate_$i"} = $bt_acc_trans->bank_transaction->exchangerate;
|
||||
$form->{"forex_$i"} = $form->{"exchangerate_$i"};
|
||||
$form->{"record_forex_$i"} = 1;
|
||||
}
|
||||
}
|
||||
$form->{"fx_paid_$i"} = $form->{"paid_$i"} / $form->{"exchangerate_$i"};
|
||||
$form->{"fx_totalpaid"} += $form->{"fx_paid_$i"};
|
||||
} # end hook fx_paid
|
||||
d319704a | Moritz Bunkus | }
|
||
} else {
|
||||
$form->{$key} =
|
||||
"$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
|
||||
}
|
||||
}
|
||||
$form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
|
||||
2e2873a4 | Werner Hahn | foreach my $ref (@{ $form->{AP_links}{AP} } ) {
|
||
if ( $ref->{chart_id} == $::instance_conf->get_ap_chart_id ) {
|
||||
$form->{AP_1} = "$ref->{accno}--$ref->{description}";
|
||||
}
|
||||
}
|
||||
d319704a | Moritz Bunkus | $form->{AP} = $form->{AP_1} unless $form->{id};
|
||
2e2873a4 | Werner Hahn | my ($chart_accno) = split /--/, $form->{AP};
|
||
$form->{AP_chart_id} = $form->{id} ? SL::DB::Manager::Chart->find_by( accno => $chart_accno)->id : $::instance_conf->get_ap_chart_id ;
|
||||
d319704a | Moritz Bunkus | |||
$form->{locked} =
|
||||
($form->datetonum($form->{invdate}, \%myconfig) <=
|
||||
$form->datetonum($form->{closedto}, \%myconfig));
|
||||
1668bc2d | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
sub prepare_invoice {
|
||||
1668bc2d | Sven Schöling | $main::lxdebug->enter_sub();
|
||
894ac4ca | Moritz Bunkus | _assert_access();
|
||
1668bc2d | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
58b14f96 | Stephan Köhler | |||
c653b98f | Sven Schöling | $form->{type} = "purchase_invoice";
|
||
d319704a | Moritz Bunkus | if ($form->{id}) {
|
||
map { $form->{$_} =~ s/\"/"/g } qw(invnumber ordnumber quonumber);
|
||||
ef255c4e | Moritz Bunkus | my $i = 0;
|
||
1668bc2d | Sven Schöling | foreach my $ref (@{ $form->{invoice_details} }) {
|
||
d319704a | Moritz Bunkus | $i++;
|
||
map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
|
||||
cbe2c598 | Jan Büren | # übernommen aus is.pl Fix für Bug 1642. Nebenwirkungen? jb 12.5.2011
|
||
# getestet: Lieferantenauftrag -> Rechnung i.O.
|
||||
# Lieferantenauftrag -> Lieferschein -> Rechnung i.O.
|
||||
cb253140 | Moritz Bunkus | # Werte: 20% (Lieferantenrabatt), 12,4% individuell und 0,4 individuell s.a.
|
||
cbe2c598 | Jan Büren | # Screenshot zu Bug 1642
|
||
$form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
|
||||
d319704a | Moritz Bunkus | |||
1668bc2d | Sven Schöling | my ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
|
||
d319704a | Moritz Bunkus | $dec = length $dec;
|
||
1668bc2d | Sven Schöling | my $decimalplaces = ($dec > 2) ? $dec : 2;
|
||
d319704a | Moritz Bunkus | |||
$form->{"sellprice_$i"} =
|
||||
$form->format_amount(\%myconfig, $form->{"sellprice_$i"},
|
||||
$decimalplaces);
|
||||
58b14f96 | Stephan Köhler | |||
7933b6bd | Udo Spallek | (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
|
||
58b14f96 | Stephan Köhler | $dec_qty = length $dec_qty;
|
||
d319704a | Moritz Bunkus | $form->{"qty_$i"} =
|
||
7933b6bd | Udo Spallek | $form->format_amount(\%myconfig, ($form->{"qty_$i"} * -1), $dec_qty);
|
||
d319704a | Moritz Bunkus | |||
$form->{rowcount} = $i;
|
||||
}
|
||||
}
|
||||
1668bc2d | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
a3a6d136 | Moritz Bunkus | sub setup_ir_action_bar {
|
||
93d8a5ea | Jan Büren | my ($tmpl_var) = @_;
|
||
a3a6d136 | Moritz Bunkus | my $form = $::form;
|
||
my $change_never = $::instance_conf->get_ir_changeable == 0;
|
||||
my $change_on_same_day_only = $::instance_conf->get_ir_changeable == 2 && ($form->current_date(\%::myconfig) ne $form->{gldate});
|
||||
f38ccc2d | Jan Büren | my $has_storno = ($::form->{storno} && !$::form->{storno_id});
|
||
my $payments_balanced = ($::form->{oldtotalpaid} == 0);
|
||||
894ac4ca | Moritz Bunkus | my $may_edit_create = $::auth->assert('vendor_invoice_edit', 1);
|
||
a3a6d136 | Moritz Bunkus | |||
b231d037 | Jan Büren | my $has_sepa_exports;
|
||
301fdeba | Bernd Bleßmann | my $is_sepa_blocked;
|
||
b231d037 | Jan Büren | if ($form->{id}) {
|
||
my $invoice = SL::DB::Manager::PurchaseInvoice->find_by(id => $form->{id});
|
||||
$has_sepa_exports = 1 if ($invoice->find_sepa_export_items()->[0]);
|
||||
301fdeba | Bernd Bleßmann | $is_sepa_blocked = !!$invoice->is_sepa_blocked;
|
||
b231d037 | Jan Büren | }
|
||
b3259be1 | Jan Büren | my $is_linked_bank_transaction;
|
||
if ($::form->{id}
|
||||
&& SL::DB::Default->get->payments_changeable != 0
|
||||
&& SL::DB::Manager::BankTransactionAccTrans->find_by(ap_id => $::form->{id})) {
|
||||
$is_linked_bank_transaction = 1;
|
||||
}
|
||||
93d8a5ea | Jan Büren | # add readonly state in tmpl_vars
|
||
$tmpl_var->{readonly} = !$may_edit_create ? 1
|
||||
: $form->{locked} ? 1
|
||||
: $form->{storno} ? 1
|
||||
: ($form->{id} && $change_never) ? 1
|
||||
: ($form->{id} && $change_on_same_day_only) ? 1
|
||||
: $is_linked_bank_transaction ? 1
|
||||
: $has_sepa_exports ? 1
|
||||
: 0;
|
||||
a59c4c73 | Bernd Bleßmann | |||
my $create_post_action = sub {
|
||||
# $_[0]: description
|
||||
# $_[1]: after_action
|
||||
action => [
|
||||
$_[0],
|
||||
submit => [ '#form', { action => "post", after_action => $_[1] } ],
|
||||
checks => [ 'kivi.validate_form' ],
|
||||
checks => [ 'kivi.validate_form', 'kivi.AP.check_fields_before_posting', 'kivi.AP.check_duplicate_invnumber' ],
|
||||
disabled => !$may_edit_create ? t8('You must not change this invoice.')
|
||||
: $form->{locked} ? t8('The billing period has already been locked.')
|
||||
: $form->{storno} ? t8('A canceled invoice cannot be posted.')
|
||||
: ($form->{id} && $change_never) ? t8('Changing invoices has been disabled in the configuration.')
|
||||
: ($form->{id} && $change_on_same_day_only) ? t8('Invoices can only be changed on the day they are posted.')
|
||||
93d8a5ea | Jan Büren | : $has_sepa_exports ? t8('This invoice has been linked with a sepa export, undo this first.')
|
||
a59c4c73 | Bernd Bleßmann | : $is_linked_bank_transaction ? t8('This transaction is linked with a bank transaction. Please undo and redo the bank transaction booking if needed.')
|
||
: undef,
|
||||
],
|
||||
};
|
||||
my @post_entries;
|
||||
if ($::instance_conf->get_ir_add_doc && $::instance_conf->get_doc_storage) {
|
||||
@post_entries = ( $create_post_action->(t8('Post'), 'doc-tab') );
|
||||
} elsif ($::instance_conf->get_doc_storage) {
|
||||
@post_entries = ( $create_post_action->(t8('Post')),
|
||||
$create_post_action->(t8('Post and upload document'), 'doc-tab') );
|
||||
} else {
|
||||
@post_entries = ( $create_post_action->(t8('Post')) );
|
||||
}
|
||||
a3a6d136 | Moritz Bunkus | for my $bar ($::request->layout->get('actionbar')) {
|
||
ff424b75 | Moritz Bunkus | $bar->add(
|
||
action => [
|
||||
t8('Update'),
|
||||
c2aaf253 | Moritz Bunkus | submit => [ '#form', { action => "update" } ],
|
||
ff424b75 | Moritz Bunkus | id => 'update_button',
|
||
accesskey => 'enter',
|
||||
894ac4ca | Moritz Bunkus | disabled => !$may_edit_create ? t8('You must not change this invoice.') : undef,
|
||
ff424b75 | Moritz Bunkus | ],
|
||
combobox => [
|
||||
a59c4c73 | Bernd Bleßmann | @post_entries,
|
||
ff424b75 | Moritz Bunkus | action => [
|
||
t8('Post Payment'),
|
||||
c2aaf253 | Moritz Bunkus | submit => [ '#form', { action => "post_payment" } ],
|
||
f260a8cc | Sven Schöling | checks => [ 'kivi.validate_form' ],
|
||
b3259be1 | Jan Büren | disabled => !$may_edit_create ? t8('You must not change this invoice.')
|
||
: !$form->{id} ? t8('This invoice has not been posted yet.')
|
||||
: $is_linked_bank_transaction ? t8('This transaction is linked with a bank transaction. Please undo and redo the bank transaction booking if needed.')
|
||||
: undef,
|
||||
ff424b75 | Moritz Bunkus | ],
|
||
301fdeba | Bernd Bleßmann | action => [ $is_sepa_blocked ? t8('Unblock Bank transfer via SEPA') : t8('Block Bank transfer via SEPA'),
|
||
submit => [ '#form', { action => "block_or_unblock_sepa_transfer", unblock_sepa => !!$is_sepa_blocked } ],
|
||||
disabled => !$may_edit_create ? t8('You must not change this AP transaction.')
|
||||
: !$::form->{id} ? t8('This invoice has not been posted yet.')
|
||||
: undef,
|
||||
],
|
||||
36c8af52 | Moritz Bunkus | action => [
|
||
965a8ee1 | Moritz Bunkus | t8('Mark as paid'),
|
||
c2aaf253 | Moritz Bunkus | submit => [ '#form', { action => "mark_as_paid" } ],
|
||
f260a8cc | Sven Schöling | checks => [ 'kivi.validate_form' ],
|
||
ff424b75 | Moritz Bunkus | confirm => t8('This will remove the invoice from showing as unpaid even if the unpaid amount does not match the amount. Proceed?'),
|
||
894ac4ca | Moritz Bunkus | disabled => !$may_edit_create ? t8('You must not change this invoice.')
|
||
: !$form->{id} ? t8('This invoice has not been posted yet.')
|
||||
: undef,
|
||||
36c8af52 | Moritz Bunkus | only_if => $::instance_conf->get_ir_show_mark_as_paid,
|
||
],
|
||||
ff424b75 | Moritz Bunkus | ], # end of combobox "Post"
|
||
combobox => [
|
||||
action => [ t8('Storno'),
|
||||
c2aaf253 | Moritz Bunkus | submit => [ '#form', { action => "storno" } ],
|
||
f260a8cc | Sven Schöling | checks => [ 'kivi.validate_form' ],
|
||
ff424b75 | Moritz Bunkus | confirm => t8('Do you really want to cancel this invoice?'),
|
||
894ac4ca | Moritz Bunkus | disabled => !$may_edit_create ? t8('You must not change this invoice.')
|
||
: !$form->{id} ? t8('This invoice has not been posted yet.')
|
||||
: $has_sepa_exports ? t8('This invoice has been linked with a sepa export, undo this first.')
|
||||
: !$payments_balanced ? t8('Cancelling is disallowed. Either undo or balance the current payments until the open amount matches the invoice amount')
|
||||
: undef,
|
||||
ff424b75 | Moritz Bunkus | ],
|
||
action => [ t8('Delete'),
|
||||
c2aaf253 | Moritz Bunkus | submit => [ '#form', { action => "delete" } ],
|
||
f260a8cc | Sven Schöling | checks => [ 'kivi.validate_form' ],
|
||
ff424b75 | Moritz Bunkus | confirm => t8('Do you really want to delete this object?'),
|
||
b3259be1 | Jan Büren | disabled => !$may_edit_create ? t8('You must not change this invoice.')
|
||
: !$form->{id} ? t8('This invoice has not been posted yet.')
|
||||
: $form->{locked} ? t8('The billing period has already been locked.')
|
||||
: $change_never ? t8('Changing invoices has been disabled in the configuration.')
|
||||
: $change_on_same_day_only ? t8('Invoices can only be changed on the day they are posted.')
|
||||
: $has_sepa_exports ? t8('This invoice has been linked with a sepa export, undo this first.')
|
||||
: $has_storno ? t8('Can only delete the "Storno zu" part of the cancellation pair.')
|
||||
: $is_linked_bank_transaction ? t8('This transaction is linked with a bank transaction. Please undo and redo the bank transaction booking if needed.')
|
||||
ff424b75 | Moritz Bunkus | : undef,
|
||
],
|
||||
], # end of combobox "Storno"
|
||||
'separator',
|
||||
9595eb7c | Jan Büren | combobox => [
|
||
action => [ t8('Workflow') ],
|
||||
action => [
|
||||
t8('Use As New'),
|
||||
submit => [ '#form', { action => "use_as_new" } ],
|
||||
f260a8cc | Sven Schöling | checks => [ 'kivi.validate_form' ],
|
||
894ac4ca | Moritz Bunkus | disabled => !$may_edit_create ? t8('You must not change this invoice.')
|
||
: !$form->{id} ? t8('This invoice has not been posted yet.')
|
||||
: undef,
|
||||
9595eb7c | Jan Büren | ],
|
||
fab2b3f1 | Tamino Steinert | action => [
|
||
t8('Reclamation'),
|
||||
submit => ['#form', { action => "purchase_reclamation" }], # can't call Reclamation directly
|
||||
disabled => !$form->{id} ? t8('This invoice has not been posted yet.') : undef,
|
||||
only_if => ($::form->{type} eq 'purchase_invoice')
|
||||
],
|
||||
9595eb7c | Jan Büren | ], # end of combobox "Workflow"
|
||
ff424b75 | Moritz Bunkus | combobox => [
|
||
action => [ t8('more') ],
|
||||
action => [
|
||||
t8('History'),
|
||||
f737afd4 | Jan Büren | call => [ 'set_history_window', $::form->{id} * 1, 'glid' ],
|
||
ff424b75 | Moritz Bunkus | disabled => !$form->{id} ? t8('This invoice has not been posted yet.') : undef,
|
||
],
|
||||
action => [
|
||||
t8('Follow-Up'),
|
||||
call => [ 'follow_up_window' ],
|
||||
disabled => !$form->{id} ? t8('This invoice has not been posted yet.') : undef,
|
||||
],
|
||||
action => [
|
||||
t8('Drafts'),
|
||||
call => [ 'kivi.Draft.popup', 'ir', 'invoice', $::form->{draft_id}, $::form->{draft_description} ],
|
||||
894ac4ca | Moritz Bunkus | disabled => !$may_edit_create ? t8('You must not change this invoice.')
|
||
: $form->{id} ? t8('This invoice has already been posted.')
|
||||
: $form->{locked} ? t8('The billing period has already been locked.')
|
||||
: undef,
|
||||
ff424b75 | Moritz Bunkus | ],
|
||
], # end of combobox "more"
|
||||
);
|
||||
a3a6d136 | Moritz Bunkus | }
|
||
9275429a | Jan Büren | $::request->layout->add_javascripts('kivi.Validator.js', 'kivi.AP.js');
|
||
a3a6d136 | Moritz Bunkus | }
|
||
d319704a | Moritz Bunkus | sub form_header {
|
||
1668bc2d | Sven Schöling | $main::lxdebug->enter_sub();
|
||
894ac4ca | Moritz Bunkus | _assert_access();
|
||
1668bc2d | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
5494f687 | Sven Schöling | my $cgi = $::request->{cgi};
|
||
58b14f96 | Stephan Köhler | |||
e39369ab | Sven Schöling | my $TMPL_VAR = $::request->cache('tmpl_var', {});
|
||
67b0f6a6 | Sven Schöling | my @custom_hiddens;
|
||
bbc63419 | Moritz Bunkus | |||
e39369ab | Sven Schöling | $TMPL_VAR->{invoice_obj} = SL::DB::PurchaseInvoice->load_cached($form->{id}) if $form->{id};
|
||
$TMPL_VAR->{vendor_obj} = SL::DB::Vendor->load_cached($form->{vendor_id}) if $form->{vendor_id};
|
||||
2392ce9e | freiphone | my $current_employee = SL::DB::Manager::Employee->current;
|
||
$form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
|
||||
$form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
|
||||
$form->{employee_id} ||= $current_employee->id;
|
||||
$form->{salesman_id} ||= $current_employee->id;
|
||||
d319704a | Moritz Bunkus | |||
a326f385 | Moritz Bunkus | $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
|
||
67b0f6a6 | Sven Schöling | |||
70220684 | Moritz Bunkus | my @old_project_ids = uniq grep { $_ } map { $_ * 1 } ($form->{"globalproject_id"}, map { $form->{"project_id_$_"} } 1..$form->{"rowcount"});
|
||
my @conditions = @old_project_ids ? (id => \@old_project_ids) : ();
|
||||
e39369ab | Sven Schöling | $TMPL_VAR->{ALL_PROJECTS} = SL::DB::Manager::Project->get_all_sorted(query => [ or => [ active => 1, @conditions ]]);
|
||
$form->{ALL_PROJECTS} = $TMPL_VAR->{ALL_PROJECTS}; # make projects available for second row drop-down in io.pl
|
||||
cfc6a60d | Moritz Bunkus | |||
da413cb1 | Moritz Bunkus | $form->get_lists("taxzones" => ($form->{id} ? "ALL_TAXZONES" : "ALL_ACTIVE_TAXZONES"),
|
||
1e251313 | Moritz Bunkus | "currencies" => "ALL_CURRENCIES",
|
||
"price_factors" => "ALL_PRICE_FACTORS");
|
||||
15682dc4 | Moritz Bunkus | |||
e39369ab | Sven Schöling | $TMPL_VAR->{ALL_DEPARTMENTS} = SL::DB::Manager::Department->get_all_sorted;
|
||
2f5363d2 | Moritz Bunkus | $TMPL_VAR->{ALL_DELIVERY_TERMS} = SL::DB::Manager::DeliveryTerm->get_valid($::form->{delivery_term_id});
|
||
e39369ab | Sven Schöling | $TMPL_VAR->{ALL_EMPLOYEES} = SL::DB::Manager::Employee->get_all_sorted(query => [ or => [ id => $::form->{employee_id}, deleted => 0 ] ]);
|
||
$TMPL_VAR->{ALL_CONTACTS} = SL::DB::Manager::Contact->get_all_sorted(query => [
|
||||
cb2abccd | Sven Schöling | or => [
|
||
cp_cv_id => $::form->{"$::form->{vc}_id"} * 1,
|
||||
and => [
|
||||
cp_cv_id => undef,
|
||||
cp_id => $::form->{cp_id} * 1
|
||||
]
|
||||
]
|
||||
]);
|
||||
67b0f6a6 | Sven Schöling | |||
# currencies and exchangerate
|
||||
my @values = map { $_ } @{ $form->{ALL_CURRENCIES} };
|
||||
my %labels = map { $_ => $_ } @{ $form->{ALL_CURRENCIES} };
|
||||
$form->{currency} = $form->{defaultcurrency} unless $form->{currency};
|
||||
175dd1fb | Niclas Zimmermann | # show_exchangerate is also later needed in another template
|
||
$form->{show_exchangerate} = $form->{currency} ne $form->{defaultcurrency};
|
||||
e39369ab | Sven Schöling | $TMPL_VAR->{currencies} = NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
|
||
69f32836 | Bernd Bleßmann | '-values' => \@values, '-labels' => \%labels,
|
||
'-onchange' => "document.getElementById('update_button').click();"
|
||||
)) if scalar @values;
|
||||
67b0f6a6 | Sven Schöling | push @custom_hiddens, "forex";
|
||
push @custom_hiddens, "exchangerate" if $form->{forex};
|
||||
e39369ab | Sven Schöling | $TMPL_VAR->{creditwarning} = ($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update};
|
||
$TMPL_VAR->{is_credit_remaining_negativ} = $form->{creditremaining} =~ /-/;
|
||||
67b0f6a6 | Sven Schöling | |||
# set option selected
|
||||
foreach my $item (qw(AP)) {
|
||||
$form->{"select$item"} =~ s/ selected//;
|
||||
$form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
|
||||
ddbe3ea5 | Moritz Bunkus | }
|
||
54e4131e | Moritz Bunkus | |||
e39369ab | Sven Schöling | $TMPL_VAR->{is_format_html} = $form->{format} eq 'html';
|
||
$TMPL_VAR->{dateformat} = $myconfig{dateformat};
|
||||
$TMPL_VAR->{numberformat} = $myconfig{numberformat};
|
||||
$TMPL_VAR->{longdescription_dialog_size_percentage} = SL::Helper::UserPreferences::DisplayPreferences->new()->get_longdescription_dialog_size_percentage();
|
||||
67b0f6a6 | Sven Schöling | |||
# hiddens
|
||||
e39369ab | Sven Schöling | $TMPL_VAR->{HIDDENS} = [qw(
|
||
c2aaf253 | Moritz Bunkus | id type queued printed emailed title vc discount
|
||
67b0f6a6 | Sven Schöling | title creditlimit creditremaining tradediscount business closedto locked shipped storno storno_id
|
||
max_dunning_level dunning_amount
|
||||
1c181c11 | Bernd Bleßmann | shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptogln shiptocontact shiptophone shiptofax
|
||
67b0f6a6 | Sven Schöling | shiptoemail shiptodepartment_1 shiptodepartment_2 message email subject cc bcc taxaccounts cursor_fokus
|
||
96ab68a3 | Jan Büren | convert_from_do_ids convert_from_oe_ids convert_from_ap_ids show_details gldate useasnew
|
||
67b0f6a6 | Sven Schöling | ), @custom_hiddens,
|
||
4e8e33e9 | Geoffrey Richardson | map { $_.'_rate', $_.'_description', $_.'_taxnumber', $_.'_tax_id' } split / /, $form->{taxaccounts}];
|
||
d319704a | Moritz Bunkus | |||
e39369ab | Sven Schöling | $TMPL_VAR->{payment_terms_obj} = get_payment_terms_for_invoice();
|
||
$form->{duedate} = $TMPL_VAR->{payment_terms_obj}->calc_date(reference_date => $form->{invdate}, due_date => $form->{duedate})->to_kivitendo if $TMPL_VAR->{payment_terms_obj};
|
||||
5bc87ade | Moritz Bunkus | |||
fdb9921e | Sven Schöling | $::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.Draft kivi.File kivi.SalesPurchase kivi.Part kivi.CustomerVendor kivi.Validator ckeditor5/ckeditor ckeditor5/translations/de kivi.io autocomplete_project client_js autocomplete_chart));
|
||
ff058663 | Moritz Bunkus | |||
068d65bc | Jan Büren | setup_ir_action_bar($TMPL_VAR);
|
||
96e475c1 | Sven Schöling | |||
67b0f6a6 | Sven Schöling | $form->header();
|
||
d319704a | Moritz Bunkus | |||
4b0fcc90 | Bernd Bleßmann | print $form->parse_html_template("ir/form_header", {%$TMPL_VAR});
|
||
d319704a | Moritz Bunkus | |||
1668bc2d | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
0d37f1e8 | Moritz Bunkus | sub _sort_payments {
|
||
83b760fb | Martin Helmling | my @fields = qw(acc_trans_id gldate datepaid source memo paid AP_paid);
|
||
0d37f1e8 | Moritz Bunkus | my @payments =
|
||
grep { $_->{paid} != 0 }
|
||||
map {
|
||||
my $idx = $_;
|
||||
+{ map { ($_ => delete($::form->{"${_}_${idx}"})) } @fields }
|
||||
} (1..$::form->{paidaccounts});
|
||||
@payments = sort_by { DateTime->from_kivitendo($_->{datepaid}) } @payments;
|
||||
$::form->{paidaccounts} = max scalar(@payments), 1;
|
||||
foreach my $idx (1 .. scalar(@payments)) {
|
||||
my $payment = $payments[$idx - 1];
|
||||
$::form->{"${_}_${idx}"} = $payment->{$_} for @fields;
|
||||
}
|
||||
}
|
||||
d319704a | Moritz Bunkus | sub form_footer {
|
||
1668bc2d | Sven Schöling | $main::lxdebug->enter_sub();
|
||
894ac4ca | Moritz Bunkus | _assert_access();
|
||
1668bc2d | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
d319704a | Moritz Bunkus | |||
e50a00d2 | Sven Schöling | $form->{invtotal} = $form->{invsubtotal};
|
||
$form->{oldinvtotal} = $form->{invtotal};
|
||||
d319704a | Moritz Bunkus | |||
e39369ab | Sven Schöling | my $TMPL_VAR = $::request->cache('tmpl_var', {});
|
||
e50a00d2 | Sven Schöling | # tax, total and subtotal calculations
|
||
my ($tax, $subtotal);
|
||||
$form->{taxaccounts_array} = [ split / /, $form->{taxaccounts} ];
|
||||
foreach my $item (@{ $form->{taxaccounts_array} }) {
|
||||
if ($form->{"${item}_base"}) {
|
||||
if ($form->{taxincluded}) {
|
||||
$form->{"${item}_total"} = $form->round_amount( ($form->{"${item}_base"} * $form->{"${item}_rate"}
|
||||
/ (1 + $form->{"${item}_rate"})), 2);
|
||||
$form->{"${item}_netto"} = $form->round_amount( ($form->{"${item}_base"} - $form->{"${item}_total"}), 2);
|
||||
} else {
|
||||
$form->{"${item}_total"} = $form->round_amount( $form->{"${item}_base"} * $form->{"${item}_rate"}, 2);
|
||||
$form->{invtotal} += $form->{"${item}_total"};
|
||||
d319704a | Moritz Bunkus | }
|
||
}
|
||||
}
|
||||
e50a00d2 | Sven Schöling | # follow ups
|
||
7a7f33b5 | Moritz Bunkus | if ($form->{id}) {
|
||
a7b92129 | Waldemar Toews | $form->{follow_ups} = FU->follow_ups('trans_id' => $form->{id}, 'not_done' => 1) || [];
|
||
e50a00d2 | Sven Schöling | $form->{follow_ups_unfinished} = ( sum map { $_->{due} * 1 } @{ $form->{follow_ups} } ) || 0;
|
||
7a7f33b5 | Moritz Bunkus | }
|
||
e50a00d2 | Sven Schöling | # payments
|
||
0d37f1e8 | Moritz Bunkus | _sort_payments();
|
||
4d20c181 | Moritz Bunkus | my $totalpaid = 0;
|
||
d319704a | Moritz Bunkus | $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
|
||
e50a00d2 | Sven Schöling | $form->{paid_indices} = [ 1 .. $form->{paidaccounts} ];
|
||
d319704a | Moritz Bunkus | |||
0e0ff150 | Jan Büren | # Standard Konto für Umlaufvermögen
|
||
my $accno_arap = IS->get_standard_accno_current_assets(\%myconfig, \%$form);
|
||||
e50a00d2 | Sven Schöling | for my $i (1 .. $form->{paidaccounts}) {
|
||
b56c0cd7 | Bernd Bleßmann | $form->{"changeable_$i"} = 1;
|
||
97954312 | Bernd Bleßmann | if (SL::DB::Default->get->payments_changeable == 0) {
|
||
b56c0cd7 | Bernd Bleßmann | # never
|
||
$form->{"changeable_$i"} = ($form->{"acc_trans_id_$i"})? 0 : 1;
|
||||
97954312 | Bernd Bleßmann | } elsif (SL::DB::Default->get->payments_changeable == 2) {
|
||
b56c0cd7 | Bernd Bleßmann | # on the same day
|
||
c79db65d | Bernd Bleßmann | $form->{"changeable_$i"} = (($form->{"gldate_$i"} eq '') ||
|
||
b56c0cd7 | Bernd Bleßmann | ($form->current_date(\%myconfig) eq $form->{"gldate_$i"}));
|
||
}
|
||||
60fd9199 | Frank Messerschmidt | $form->error($locale->text('Cannot post transaction above the maximum future booking date!'))
|
||
if ($form->date_max_future($form->{"datepaid_$i"}, \%myconfig));
|
||||
#deaktivieren von Zahlungen ausserhalb der Bücherkontrolle
|
||||
if ($form->date_closed($form->{"gldate_$i"})) {
|
||||
$form->{"changeable_$i"} = 0;
|
||||
}
|
||||
22ad5a29 | Jan Büren | # don't add manual bookings for charts which are assigned to real bank accounts
|
||
67da170f | Cem Aydin | # and are flagged for use with bank import
|
||
22ad5a29 | Jan Büren | my $bank_accounts = SL::DB::Manager::BankAccount->get_all();
|
||
foreach my $bank (@{ $bank_accounts }) {
|
||||
67da170f | Cem Aydin | if ($bank->use_with_bank_import) {
|
||
my $accno_paid_bank = $bank->chart->accno;
|
||||
$form->{selectAP_paid} =~ s/<option>$accno_paid_bank--(.*?)<\/option>//;
|
||||
}
|
||||
22ad5a29 | Jan Büren | }
|
||
d319704a | Moritz Bunkus | $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
|
||
0e0ff150 | Jan Büren | if (!$form->{"AP_paid_$i"}) {
|
||
$form->{"selectAP_paid_$i"} =~ s/option>$accno_arap--(.*?)>/option selected>$accno_arap--$1>/;
|
||||
} else {
|
||||
$form->{"selectAP_paid_$i"} =~ s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
|
||||
}
|
||||
4d20c181 | Moritz Bunkus | $totalpaid += $form->{"paid_$i"};
|
||
9e117fbd | Philip Reetz | }
|
||
d77b981f | Moritz Bunkus | |||
e50a00d2 | Sven Schöling | print $form->parse_html_template('ir/form_footer', {
|
||
e39369ab | Sven Schöling | %$TMPL_VAR,
|
||
e50a00d2 | Sven Schöling | totalpaid => $totalpaid,
|
||
paid_missing => $form->{invtotal} - $totalpaid,
|
||||
show_storno => $form->{id} && !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ap") && !$totalpaid,
|
||||
4ac2976f | Bernd Bleßmann | show_delete => ($::instance_conf->get_ir_changeable == 2)
|
||
? ($form->current_date(\%myconfig) eq $form->{gldate})
|
||||
: ($::instance_conf->get_ir_changeable == 1),
|
||||
01678c87 | Sven Schöling | today => DateTime->today,
|
||
e50a00d2 | Sven Schöling | });
|
||
##print $form->parse_html_template('ir/_payments'); # parser
|
||||
##print $form->parse_html_template('webdav/_list'); # parser
|
||||
d319704a | Moritz Bunkus | |||
1668bc2d | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
ce47a234 | Thomas Kasulke | sub mark_as_paid {
|
||
59adfa36 | Moritz Bunkus | $::auth->assert('vendor_invoice_edit');
|
||
1668bc2d | Sven Schöling | |||
59adfa36 | Moritz Bunkus | SL::DB::PurchaseInvoice->new(id => $::form->{id})->load->mark_as_paid;
|
||
8c7e4493 | Moritz Bunkus | |||
59adfa36 | Moritz Bunkus | $::form->redirect($::locale->text("Marked as paid"));
|
||
ce47a234 | Thomas Kasulke | }
|
||
301fdeba | Bernd Bleßmann | 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'));
|
||||
}
|
||||
46aa98a9 | Martin Helmling | sub show_draft {
|
||
1927b931 | Bernd Bleßmann | $::form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_PURCHASE_INVOICE_POST())->token;
|
||
46aa98a9 | Martin Helmling | update();
|
||
}
|
||||
d319704a | Moritz Bunkus | sub update {
|
||
1668bc2d | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
d319704a | Moritz Bunkus | |||
1668bc2d | Sven Schöling | $main::auth->assert('vendor_invoice_edit');
|
||
8c7e4493 | Moritz Bunkus | |||
1dbba310 | Moritz Bunkus | if (($form->{previous_vendor_id} || $form->{vendor_id}) != $form->{vendor_id}) {
|
||
IR->get_vendor(\%myconfig, $form);
|
||||
}
|
||||
607163f5 | Jan Büren | #
|
||
$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');
|
||||
}
|
||||
2e26ccd5 | Bernd Bleßmann | }
|
||
1668bc2d | Sven Schöling | for my $i (1 .. $form->{paidaccounts}) {
|
||
52983c08 | Sven Schöling | next unless $form->{"paid_$i"};
|
||
map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
|
||||
607163f5 | Jan Büren | $form->{"forex_$i"} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell') unless $form->{"record_forex_$i"};
|
||
a53233e5 | Sven Schöling | $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
|
||
d319704a | Moritz Bunkus | }
|
||
1668bc2d | Sven Schöling | my $i = $form->{rowcount};
|
||
my $exchangerate = ($form->{exchangerate} * 1) || 1;
|
||||
d319704a | Moritz Bunkus | |||
if ( ($form->{"partnumber_$i"} eq "")
|
||||
&& ($form->{"description_$i"} eq "")
|
||||
&& ($form->{"partsgroup_$i"} eq "")) {
|
||||
$form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
|
||||
&check_form;
|
||||
54e4131e | Moritz Bunkus | } else {
|
||
d319704a | Moritz Bunkus | IR->retrieve_item(\%myconfig, \%$form);
|
||
my $rows = scalar @{ $form->{item_list} };
|
||||
97908d77 | Bernd Bleßmann | $form->{"discount_$i"} = $form->parse_amount(\%myconfig, $form->{"discount_$i"}) / 100.0;
|
||
$form->{"discount_$i"} ||= $form->{vendor_discount};
|
||||
d319704a | Moritz Bunkus | if ($rows) {
|
||
11fcc435 | Bernd Bleßmann | $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
|
||
if( !$form->{"qty_$i"} ) {
|
||||
$form->{"qty_$i"} = 1;
|
||||
}
|
||||
d319704a | Moritz Bunkus | |||
if ($rows > 1) {
|
||||
6ea1dd9b | Bernd Bleßmann | select_item(mode => 'IR', pre_entered_qty => $form->{"qty_$i"});
|
||
09479f02 | Moritz Bunkus | $::dispatcher->end_request;
|
||
d319704a | Moritz Bunkus | |||
} else {
|
||||
# override sellprice if there is one entered
|
||||
1668bc2d | Sven Schöling | my $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
|
||
d319704a | Moritz Bunkus | |||
52983c08 | Sven Schöling | map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
|
||
map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
|
||||
d319704a | Moritz Bunkus | |||
1e251313 | Moritz Bunkus | $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
|
||
52983c08 | Sven Schöling | ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
|
||
1668bc2d | Sven Schöling | my $dec_qty = length $1;
|
||
my $decimalplaces = max 2, $dec_qty;
|
||||
d319704a | Moritz Bunkus | |||
if ($sellprice) {
|
||||
$form->{"sellprice_$i"} = $sellprice;
|
||||
} else {
|
||||
89b26688 | Sven Schöling | 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;
|
||||
}
|
||||
d319704a | Moritz Bunkus | # if there is an exchange rate adjust sellprice
|
||
$form->{"sellprice_$i"} /= $exchangerate;
|
||||
}
|
||||
97908d77 | Bernd Bleßmann | my $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"});
|
||
d319704a | Moritz Bunkus | $form->{creditremaining} -= $amount;
|
||
52983c08 | Sven Schöling | $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
|
||
$form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
|
||||
97908d77 | Bernd Bleßmann | $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100.0);
|
||
d319704a | Moritz Bunkus | }
|
||
&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"} = "";
|
||||
d83df93a | Moritz Bunkus | display_form();
|
||
d319704a | Moritz Bunkus | |||
d83df93a | Moritz Bunkus | } else {
|
||
d319704a | Moritz Bunkus | $form->{"id_$i"} = 0;
|
||
d83df93a | Moritz Bunkus | new_item();
|
||
d319704a | Moritz Bunkus | }
|
||
}
|
||||
}
|
||||
1668bc2d | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
54e4131e | Moritz Bunkus | sub storno {
|
||
1668bc2d | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
85f5b26d | Thomas Kasulke | |||
1668bc2d | Sven Schöling | $main::auth->assert('vendor_invoice_edit');
|
||
8c7e4493 | Moritz Bunkus | |||
54e4131e | Moritz Bunkus | if ($form->{storno}) {
|
||
$form->error($locale->text('Cannot storno storno invoice!'));
|
||||
}
|
||||
a1a3bfd8 | Moritz Bunkus | if (IS->has_storno(\%myconfig, $form, "ap")) {
|
||
5ceaf343 | Moritz Bunkus | $form->error($locale->text("Invoice has already been storno'd!"));
|
||
}
|
||||
16a12c3c | Niclas Zimmermann | $form->error($locale->text('Cannot post storno for a closed period!'))
|
||
if ( $form->date_closed($form->{invdate}, \%myconfig));
|
||||
408a65ca | Moritz Bunkus | my $employee_id = $form->{employee_id};
|
||
379aa61a | Moritz Bunkus | invoice_links();
|
||
prepare_invoice();
|
||||
relink_accounts();
|
||||
fc3b49d6 | Tamino Steinert | set_taxaccounts_and_accnos();
|
||
3740b503 | Moritz Bunkus | |||
# Payments must not be recorded for the new storno invoice.
|
||||
$form->{paidaccounts} = 0;
|
||||
b56c0cd7 | Bernd Bleßmann | map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ gldate_ acc_trans_id_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
|
||
f087c373 | Jan Büren | # set new ids for storno invoice
|
||
96ab68a3 | Jan Büren | # set new persistent ids for storno invoice items
|
||
$form->{"converted_from_invoice_id_$_"} = delete $form->{"invoice_id_$_"} for 1 .. $form->{"rowcount"};
|
||||
f83ca506 | Sven Schöling | |||
18db0f54 | Thomas Kasulke | # saving the history
|
||
if(!exists $form->{addition} && $form->{id} ne "") {
|
||||
281696eb | Geoffrey Richardson | $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
|
||
$form->{what_done} = "invoice";
|
||||
$form->{addition} = "CANCELED";
|
||||
a590a651 | Sven Schöling | $form->save_history;
|
||
18db0f54 | Thomas Kasulke | }
|
||
# /saving the history
|
||||
f83ca506 | Sven Schöling | |||
96ab68a3 | Jan Büren | # record link invoice to storno
|
||
$form->{convert_from_ap_ids} = $form->{id};
|
||||
54e4131e | Moritz Bunkus | $form->{storno_id} = $form->{id};
|
||
$form->{storno} = 1;
|
||||
$form->{id} = "";
|
||||
$form->{invnumber} = "Storno zu " . $form->{invnumber};
|
||||
18db0f54 | Thomas Kasulke | $form->{rowcount}++;
|
||
408a65ca | Moritz Bunkus | $form->{employee_id} = $employee_id;
|
||
1927b931 | Bernd Bleßmann | $form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_PURCHASE_INVOICE_POST())->token;
|
||
f909691a | Jan Büren | # post expects the field as user input
|
||
$form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
|
||||
408a65ca | Moritz Bunkus | post();
|
||
1668bc2d | Sven Schöling | $main::lxdebug->leave_sub();
|
||
54e4131e | Moritz Bunkus | |||
}
|
||||
3cd3e832 | Moritz Bunkus | sub use_as_new {
|
||
1668bc2d | Sven Schöling | $main::lxdebug->enter_sub();
|
||
98764afa | Philip Reetz | |||
1668bc2d | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
$main::auth->assert('vendor_invoice_edit');
|
||||
8c7e4493 | Moritz Bunkus | |||
b56c0cd7 | Bernd Bleßmann | 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);
|
||
98764afa | Philip Reetz | $form->{paidaccounts} = 1;
|
||
$form->{rowcount}--;
|
||||
$form->{invdate} = $form->current_date(\%myconfig);
|
||||
b8125c17 | Bernd Bleßmann | |||
1927b931 | Bernd Bleßmann | $form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_PURCHASE_INVOICE_POST())->token;
|
||
b8125c17 | Bernd Bleßmann | $form->{"converted_from_invoice_id_$_"} = delete $form->{"invoice_id_$_"} for 1 .. $form->{"rowcount"};
|
||
f909691a | Jan Büren | $form->{exchangerate} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'sell');
|
||
b8125c17 | Bernd Bleßmann | $form->{useasnew} = 1;
|
||
98764afa | Philip Reetz | &display_form;
|
||
1668bc2d | Sven Schöling | $main::lxdebug->leave_sub();
|
||
98764afa | Philip Reetz | }
|
||
54e4131e | Moritz Bunkus | sub post_payment {
|
||
1668bc2d | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
a326f385 | Moritz Bunkus | |||
1668bc2d | Sven Schöling | $main::auth->assert('vendor_invoice_edit');
|
||
8c7e4493 | Moritz Bunkus | |||
d735aab3 | Martin Helmling | $form->mtime_ischanged('ap') ;
|
||
a326f385 | Moritz Bunkus | $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
|
||
1668bc2d | Sven Schöling | for my $i (1 .. $form->{paidaccounts}) {
|
||
bd32b607 | Philip Reetz | if ($form->{"paid_$i"}) {
|
||
1668bc2d | Sven Schöling | my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
|
||
54e4131e | Moritz Bunkus | |||
$form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
|
||||
60fd9199 | Frank Messerschmidt | $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)
|
||||
54e4131e | Moritz Bunkus | $form->error($locale->text('Cannot post payment for a closed period!'))
|
||
60fd9199 | Frank Messerschmidt | if ($form->date_closed($form->{"datepaid_$i"}) && !$form->date_closed($form->{"gldate_$i"}, \%myconfig));
|
||
54e4131e | Moritz Bunkus | |||
if ($form->{currency} ne $form->{defaultcurrency}) {
|
||||
1668bc2d | Sven Schöling | # $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid); # invdate isn't set here
|
||
$form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
|
||||
54e4131e | Moritz Bunkus | }
|
||
}
|
||||
}
|
||||
2e2873a4 | Werner Hahn | $form->{AP} = SL::DB::Manager::Chart->find_by( id => $form->{AP_chart_id} )->accno;
|
||
54e4131e | Moritz Bunkus | ($form->{AP_paid}) = split /--/, $form->{AP_paid};
|
||
ec93aab7 | Thomas Kasulke | if (IR->post_payment(\%myconfig, \%$form)){
|
||
b65a230d | Sven Schöling | if (!exists $form->{addition} && $form->{id} ne "") {
|
||
# saving the history
|
||||
7a98647b | Geoffrey Richardson | $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
|
||
$form->{addition} = "PAYMENT POSTED";
|
||||
$form->{what_done} = "invoice";
|
||||
a590a651 | Sven Schöling | $form->save_history;
|
||
b65a230d | Sven Schöling | # /saving the history
|
||
}
|
||||
d5c1e4fa | Moritz Bunkus | |||
$form->redirect($locale->text('Payment posted!'));
|
||||
ec93aab7 | Thomas Kasulke | }
|
||
54e4131e | Moritz Bunkus | |||
d5c1e4fa | Moritz Bunkus | $form->error($locale->text('Cannot post payment!'));
|
||
54e4131e | Moritz Bunkus | |||
1668bc2d | Sven Schöling | $main::lxdebug->leave_sub();
|
||
54e4131e | Moritz Bunkus | }
|
||
d03b2877 | Moritz Bunkus | 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;
|
||||
}
|
||||
d319704a | Moritz Bunkus | sub post {
|
||
1668bc2d | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
d319704a | Moritz Bunkus | |||
1668bc2d | Sven Schöling | $main::auth->assert('vendor_invoice_edit');
|
||
8c7e4493 | Moritz Bunkus | |||
d735aab3 | Martin Helmling | $form->mtime_ischanged('ap');
|
||
1927b931 | Bernd Bleßmann | |||
fa640585 | Philip Reetz | $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
|
||
168c0a5f | Sven Schöling | $form->isblank("invdate", $locale->text('Invoice Date missing!'));
|
||
1dbba310 | Moritz Bunkus | $form->isblank("vendor_id", $locale->text('Vendor missing!'));
|
||
168c0a5f | Sven Schöling | $form->isblank("invnumber", $locale->text('Invnumber missing!'));
|
||
d319704a | Moritz Bunkus | |||
a426a839 | Moritz Bunkus | $form->{invnumber} =~ s/^\s*//g;
|
||
$form->{invnumber} =~ s/\s*$//g;
|
||||
d319704a | Moritz Bunkus | # if the vendor changed get new values
|
||
1dbba310 | Moritz Bunkus | if (($form->{previous_vendor_id} || $form->{vendor_id}) != $form->{vendor_id}) {
|
||
d319704a | Moritz Bunkus | &update;
|
||
09479f02 | Moritz Bunkus | $::dispatcher->end_request;
|
||
d319704a | Moritz Bunkus | }
|
||
05174f19 | Sven Schöling | if ($myconfig{mandatory_departments} && !$form->{department_id}) {
|
||
$form->{saved_message} = $::locale->text('You have to specify a department.');
|
||||
update();
|
||||
exit;
|
||||
}
|
||||
0a5317e7 | Moritz Bunkus | remove_emptied_rows();
|
||
d319704a | Moritz Bunkus | &validate_items;
|
||
d03b2877 | Moritz Bunkus | my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
|
||
my $invdate = $form->datetonum($form->{invdate}, \%myconfig);
|
||||
my $max_datepaid = _max_datepaid();
|
||||
d319704a | Moritz Bunkus | |||
a11d7a85 | Jan Büren | $form->error($locale->text('Cannot post transaction above the maximum future booking date!'))
|
||
if ($form->date_max_future($invdate, \%myconfig));
|
||||
9b30f204 | Sven Schöling | $form->error($locale->text('Cannot post invoice for a closed period!'))
|
||
if ($invdate <= $closedto);
|
||||
d319704a | Moritz Bunkus | |||
eaa30664 | Jan Büren | 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);
|
||||
}
|
||||
d03b2877 | Moritz Bunkus | my $i;
|
||
d319704a | Moritz Bunkus | for $i (1 .. $form->{paidaccounts}) {
|
||
5563e116 | Moritz Bunkus | if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
|
||
1668bc2d | Sven Schöling | my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
|
||
d319704a | Moritz Bunkus | |||
$form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
|
||||
60fd9199 | Frank Messerschmidt | $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)
|
||||
d319704a | Moritz Bunkus | $form->error($locale->text('Cannot post payment for a closed period!'))
|
||
60fd9199 | Frank Messerschmidt | if ($form->date_closed($form->{"datepaid_$i"}) && !$form->date_closed($form->{"gldate_$i"}, \%myconfig));
|
||
d319704a | Moritz Bunkus | |||
if ($form->{currency} ne $form->{defaultcurrency}) {
|
||||
$form->{"exchangerate_$i"} = $form->{exchangerate}
|
||||
if ($invdate == $datepaid);
|
||||
$form->isblank("exchangerate_$i",
|
||||
$locale->text('Exchangerate for payment missing!'));
|
||||
}
|
||||
}
|
||||
}
|
||||
2e2873a4 | Werner Hahn | $form->{AP} = SL::DB::Manager::Chart->find_by( id => $form->{AP_chart_id} )->accno;
|
||
d319704a | Moritz Bunkus | ($form->{AP_paid}) = split /--/, $form->{AP_paid};
|
||
dd88b408 | Sven Schöling | $form->{storno} ||= 0;
|
||
d319704a | Moritz Bunkus | |||
b3501bdf | Moritz Bunkus | relink_accounts();
|
||
fc3b49d6 | Tamino Steinert | set_taxaccounts_and_accnos();
|
||
bde667c2 | Moritz Bunkus | if (IR->post_invoice(\%myconfig, \%$form)){
|
||
b65a230d | Sven Schöling | # saving the history
|
||
if(!exists $form->{addition} && $form->{id} ne "") {
|
||||
281696eb | Geoffrey Richardson | $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
|
||
$form->{addition} = "POSTED";
|
||||
$form->{what_done} = 'invoice';
|
||||
a590a651 | Sven Schöling | $form->save_history;
|
||
b65a230d | Sven Schöling | }
|
||
# /saving the history
|
||||
f850f64b | Bernd Bleßmann | |||
my $redirect_url;
|
||||
a59c4c73 | Bernd Bleßmann | if ('doc-tab' eq $form->{after_action}) {
|
||
f850f64b | Bernd Bleßmann | $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;
|
||||
ec93aab7 | Thomas Kasulke | }
|
||
d319704a | Moritz Bunkus | $form->error($locale->text('Cannot post invoice!'));
|
||
1668bc2d | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
sub delete {
|
||||
1668bc2d | Sven Schöling | $main::lxdebug->enter_sub();
|
||
d319704a | Moritz Bunkus | |||
1668bc2d | Sven Schöling | my $form = $main::form;
|
||
my $locale = $main::locale;
|
||||
$main::auth->assert('vendor_invoice_edit');
|
||||
8c7e4493 | Moritz Bunkus | |||
d319704a | Moritz Bunkus | $form->header;
|
||
print qq|
|
||||
<form method=post action=$form->{script}>
|
||||
|;
|
||||
# delete action variable
|
||||
map { delete $form->{$_} } qw(action header);
|
||||
1668bc2d | Sven Schöling | foreach my $key (keys %$form) {
|
||
8c7e4493 | Moritz Bunkus | next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
|
||
d319704a | Moritz Bunkus | $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>
|
||||
|;
|
||||
1668bc2d | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
a2546588 | Sven Schöling | sub display_form {
|
||
$::lxdebug->enter_sub;
|
||||
894ac4ca | Moritz Bunkus | _assert_access();
|
||
a2546588 | Sven Schöling | |||
relink_accounts();
|
||||
fc3b49d6 | Tamino Steinert | set_taxaccounts_and_accnos();
|
||
a2546588 | Sven Schöling | |||
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;
|
||||
}
|
||||
d319704a | Moritz Bunkus | sub yes {
|
||
1668bc2d | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
8c7e4493 | Moritz Bunkus | |||
1668bc2d | Sven Schöling | $main::auth->assert('vendor_invoice_edit');
|
||
8c7e4493 | Moritz Bunkus | |||
ec93aab7 | Thomas Kasulke | if (IR->delete_invoice(\%myconfig, \%$form)) {
|
||
# saving the history
|
||||
if(!exists $form->{addition}) {
|
||||
f83ca506 | Sven Schöling | $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
|
||
b65a230d | Sven Schöling | $form->{addition} = "DELETED";
|
||
a590a651 | Sven Schöling | $form->save_history;
|
||
ec93aab7 | Thomas Kasulke | }
|
||
f83ca506 | Sven Schöling | # /saving the history
|
||
ec93aab7 | Thomas Kasulke | $form->redirect($locale->text('Invoice deleted!'));
|
||
}
|
||||
d319704a | Moritz Bunkus | $form->error($locale->text('Cannot delete invoice!'));
|
||
1668bc2d | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
bbc63419 | Moritz Bunkus | |||
4e5c422e | Sven Schöling | sub get_duedate_vendor {
|
||
$::lxdebug->enter_sub;
|
||||
bbc63419 | Moritz Bunkus | |||
4e5c422e | Sven Schöling | my $result = IR->get_duedate(
|
||
vendor_id => $::form->{vendor_id},
|
||||
invdate => $::form->{invdate},
|
||||
default => $::form->{old_duedate},
|
||||
);
|
||||
bbc63419 | Moritz Bunkus | |||
4e5c422e | Sven Schöling | print $::form->ajax_response_header, $result;
|
||
$::lxdebug->leave_sub;
|
||||
bbc63419 | Moritz Bunkus | }
|
||
fc3b49d6 | Tamino Steinert | |||
# set values form relink_accounts as default
|
||||
c988246c | Tamino Steinert | # otherwise override with user selected values
|
||
fc3b49d6 | Tamino Steinert | # recalc taxaccounts string
|
||
sub set_taxaccounts_and_accnos {
|
||||
$main::lxdebug->enter_sub;
|
||||
for my $i (1 .. $::form->{rowcount}) {
|
||||
# fill with default, ids can be 0
|
||||
if ('' eq $::form->{"expense_chart_id_$i"}) {
|
||||
$::form->{"expense_chart_id_$i"} = $::form->{"expense_accno_id_$i"};
|
||||
}
|
||||
if ('' eq $::form->{"tax_id_$i"}) {
|
||||
$::form->{"tax_id_$i"} = $::form->{"expense_accno_tax_id_$i"};
|
||||
}
|
||||
if ('' eq $::form->{"inventory_chart_id_$i"}) {
|
||||
$::form->{"inventory_chart_id_$i"} = $::form->{"inventory_accno_id_$i"};
|
||||
}
|
||||
# if changed override with user values
|
||||
if ($::form->{"expense_chart_id_$i"} ne $::form->{"expense_accno_id_$i"}) {
|
||||
$::form->{"expense_accno_id_$i"} = $::form->{"expense_chart_id_$i"};
|
||||
my $chart = SL::DB::Chart->new(id => $::form->{"expense_chart_id_$i"})->load;
|
||||
$::form->{"expense_accno_$i"} = $chart->accno;
|
||||
}
|
||||
if ($::form->{"tax_id_$i"} ne $::form->{"expense_accno_tax_id_$i"}) {
|
||||
$::form->{"expense_accno_tax_id_$i"} = $::form->{"tax_id_$i"};
|
||||
my $tax = SL::DB::Tax->new(id => $::form->{"tax_id_$i"})->load;
|
||||
my $tax_accno;
|
||||
if (defined $tax->chart_id) {
|
||||
my $chart = SL::DB::Chart->new(id => $tax->chart_id)->load;
|
||||
$tax_accno = $chart->accno;
|
||||
} else {
|
||||
$tax_accno = "NO_ACCNO_" . $tax->id;
|
||||
}
|
||||
$::form->{"taxaccounts_$i"} = $tax_accno;
|
||||
if (!($::form->{taxaccounts} =~ /\Q$tax_accno\E/)) {
|
||||
# add tax info if missing
|
||||
$::form->{"${tax_accno}_rate"} = $tax->rate;
|
||||
$::form->{"${tax_accno}_description"} = $tax->taxdescription;
|
||||
$::form->{"${tax_accno}_tax_id"} = $tax->id;
|
||||
$::form->{"${tax_accno}_taxnumber"} = $::form->{"expense_accno_$i"};
|
||||
}
|
||||
}
|
||||
if ($::form->{"inventory_chart_id_$i"} ne $::form->{"inventory_accno_id_$i"}) {
|
||||
$::form->{"inventory_accno_id_$i"} = $::form->{"inventory_chart_id_$i"};
|
||||
my $chart = SL::DB::Chart->new(id => $::form->{"inventory_chart_id_$i"})->load;
|
||||
$::form->{"inventory_accno_$i"} = $chart->accno;
|
||||
}
|
||||
}
|
||||
# recalc taxaccounts string
|
||||
$::form->{taxaccounts} = "";
|
||||
for my $i (1 .. $::form->{rowcount}) {
|
||||
my $taxaccounts_i = $::form->{"taxaccounts_$i"};
|
||||
if (!($::form->{taxaccounts} =~ /\Q$taxaccounts_i\E/)) {
|
||||
$::form->{taxaccounts} .= "$taxaccounts_i ";
|
||||
}
|
||||
}
|
||||
$::lxdebug->leave_sub;
|
||||
}
|