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;
$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//;
$jsscript = "";
$button1 = qq|
- <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
- <input type=button name=invdate id="trigger1" value=| . $locale->text('button') . qq|></td>\n|;
+ <td nowrap>
+ <input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\"
+ onChange="if (this.value) set_duedate_vendor(['invdate__' + this.value, 'old_duedate__' + document.getElementsByName('duedate')[0].value, 'vendor_id__' + document.getElementsByName('vendor_id')[0].value],['duedate'])">
+ <input type=button name=invdate id="trigger1" value="?">
+ </td>\n|;
+
+#, 'old_duedate__'' + document.getElementsByName('duedate')[0].value, 'vendor_id__' + document.getElementsByName('vendor_id')[0].value],['duedate'])">
$button2 = qq|
- <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\">
- <input type=button name=duedate id="trigger2" value=| . $locale->text('button') . qq|></td>\n|;
+ <td width="13" nowrap>
+ <input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\">
+ <input type=button name=duedate id="trigger2" value=| . $locale->text('button') . qq|>
+ </td>\n|;
#write Trigger
$jsscript =
print qq|
<body onLoad="$onload">
<script type="text/javascript" src="js/common.js"></script>
-<form method=post action=$form->{script}>
+<form method="post" action="ir.pl" name="Form">
|;
$form->hide_form(qw(id title vc type level creditlimit creditremaining closedto locked shippted storno storno_id
$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();
+}
'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',