X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/4f3a0ab534d137dee45c52b3e9ae17f48e13f084..b8b6cdf3aa11e1dd23b55493f9357585e2b06547:/bin/mozilla/io.pl diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index febe26776..6b4cad7a6 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -41,8 +41,10 @@ use CGI; use List::MoreUtils qw(any uniq apply); use List::Util qw(min max first); +use SL::ClientJS; use SL::CVar; use SL::Common; +use SL::Controller::Base; use SL::CT; use SL::Locale::String qw(t8); use SL::IC; @@ -760,15 +762,6 @@ sub check_form { $form->{creditremaining} -= &invoicetotal; } - #sk - # if pricegroups - if ( $form->{type} =~ (/sales_quotation/) - or (($form->{level} =~ /Sales/) and ($form->{type} =~ /invoice/)) - or (($form->{level} eq undef) and ($form->{type} =~ /invoice/)) - or ($form->{type} =~ /sales_order/)) { - - } - &display_form; $main::lxdebug->leave_sub(); @@ -918,7 +911,7 @@ sub order { my $script = $form->{"script"}; $script =~ s|.*/||; $script =~ s|.pl$||; - $locale = new Locale($::lx_office_conf{system}->{language}, $script); + $locale = Locale->new($::lx_office_conf{system}->{language}, $script); map { $form->{"select$_"} = "" } ($form->{vc}, "currency"); @@ -1247,7 +1240,7 @@ sub print { $form->error($locale->text('Select postscript or PDF!')) if ($form->{format} !~ /(postscript|pdf)/); - $old_form = new Form; + $old_form = Form->new; map { $old_form->{$_} = $form->{$_} } keys %$form; } @@ -1805,20 +1798,35 @@ sub relink_accounts { $main::lxdebug->leave_sub(); } -sub set_duedate { - $main::lxdebug->enter_sub(); +sub get_payment_terms_for_invoice { + my $terms = $::form->{payment_id} ? SL::DB::PaymentTerm->new(id => $::form->{payment_id}) ->load + : $::form->{customer_id} ? SL::DB::Customer ->new(id => $::form->{customer_id})->load->payment + : $::form->{vendor_id} ? SL::DB::Vendor ->new(id => $::form->{vendor_id}) ->load->payment + : undef; - my $form = $main::form; - my %myconfig = %main::myconfig; + return $terms; +} +sub set_duedate { _check_io_auth(); - my $invdate = $form->{invdate} eq 'undefined' ? undef : $form->{invdate}; - my $duedate = $form->get_duedate(\%myconfig, $invdate); + my $js = SL::ClientJS->new(controller => SL::Controller::Base->new); + my $terms = get_payment_terms_for_invoice(); + my $invdate = $::form->{invdate} eq 'undefined' ? DateTime->today_local : DateTime->from_kivitendo($::form->{invdate}); + my $duedate = $terms ? $terms->calc_date(reference_date => $invdate, due_date => $::form->{duedate})->to_kivitendo : ($::form->{duedate} || $invdate->to_kivitendo); - print $form->ajax_response_header() . ($duedate || $invdate); + if ($terms && $terms->auto_calculation) { + $js->hide('#duedate_container') + ->show('#duedate_fixed') + ->html('#duedate_fixed', $duedate); - $main::lxdebug->leave_sub(); + } else { + $js->show('#duedate_container') + ->hide('#duedate_fixed'); + } + + $js->val('#duedate', $duedate) + ->render; } sub _update_part_information {