From: Moritz Bunkus Date: Mon, 7 Jul 2008 15:48:09 +0000 (+0000) Subject: Eingangsrechnungen: Wird das Rechnungsdatum verändert, so wird per AJAX das Fälligkei... X-Git-Tag: release-2.6.0beta1~72 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=bbc63419b26661a6d5c9bf859dc79cfb63069048;p=kivitendo-erp.git Eingangsrechnungen: Wird das Rechnungsdatum verändert, so wird per AJAX das Fälligkeitsdatum anhand der beim Lieferanten hinterlegten Zahlungsbedingungen berechnet und im Formular ersetzt. --- diff --git a/SL/IR.pm b/SL/IR.pm index f3c2674b0..f1c9197ee 100644 --- a/SL/IR.pm +++ b/SL/IR.pm @@ -1277,4 +1277,42 @@ sub post_payment { return $rc; } +sub get_duedate { + $main::lxdebug->enter_sub(); + + my $self = shift; + my %params = @_; + + if (!$params{vendor_id} || !$params{invdate}) { + $main::lxdebug->leave_sub(); + return $params{default}; + } + + my $myconfig = \%main::myconfig; + my $form = $main::form; + + my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); + + my $query = qq|SELECT ?::date + pt.terms_netto + FROM vendor v + LEFT JOIN payment_terms pt ON (pt.id = v.payment_id) + WHERE v.id = ?|; + + my ($sth, $duedate); + + if (($sth = $dbh->prepare($query)) && $sth->execute($params{invdate}, conv_i($params{vendor_id}))) { + ($duedate) = $sth->fetchrow_array(); + $sth->finish(); + } else { + $dbh->rollback(); + } + + $duedate ||= $params{default}; + + $main::lxdebug->leave_sub(); + + return $duedate; +} + + 1; diff --git a/bin/mozilla/ir.pl b/bin/mozilla/ir.pl index ce28fff92..07efa666a 100644 --- a/bin/mozilla/ir.pl +++ b/bin/mozilla/ir.pl @@ -226,6 +226,8 @@ sub form_header { $auth->assert('vendor_invoice_edit'); + push @{ $form->{AJAX} }, CGI::Ajax->new('set_duedate_vendor' => "$form->{script}?action=set_duedate_vendor"); + # set option selected foreach $item (qw(AP vendor currency department)) { $form->{"select$item"} =~ s/ selected//; @@ -389,11 +391,18 @@ sub form_header { $jsscript = ""; $button1 = qq| - - text('button') . qq|>\n|; + + + + \n|; + +#, 'old_duedate__'' + document.getElementsByName('duedate')[0].value, 'vendor_id__' + document.getElementsByName('vendor_id')[0].value],['duedate'])"> $button2 = qq| - - text('button') . qq|>\n|; + + + text('button') . qq|> + \n|; #write Trigger $jsscript = @@ -419,7 +428,7 @@ sub form_header { print qq| -
{script}> + |; $form->hide_form(qw(id title vc type level creditlimit creditremaining closedto locked shippted storno storno_id @@ -1206,3 +1215,13 @@ sub yes { $lxdebug->leave_sub(); } + +sub set_duedate_vendor { + $lxdebug->enter_sub(); + + print $cgi->header(), IR->get_duedate('vendor_id' => $form->{vendor_id}, + 'invdate' => $form->{invdate}, + 'default' => $form->{old_duedate}); + + $lxdebug->leave_sub(); +} diff --git a/locale/de/ir b/locale/de/ir index eaa4aa73d..b0f4da265 100644 --- a/locale/de/ir +++ b/locale/de/ir @@ -377,6 +377,7 @@ $self->{subs} = { 'select_project' => 'select_project', 'send_email' => 'send_email', 'set_duedate' => 'set_duedate', + 'set_duedate_vendor' => 'set_duedate_vendor', 'set_longdescription' => 'set_longdescription', 'set_pricegroup' => 'set_pricegroup', 'ship_to' => 'ship_to',