FIX Test when date of invoie is in future (pb with TZ and offset)
This commit is contained in:
parent
2bd0fdd364
commit
51b6318f88
@ -393,13 +393,21 @@ if (empty($reshook)) {
|
||||
} elseif ($action == 'setinvoicedate' && $usercancreate) {
|
||||
$object->fetch($id);
|
||||
$old_date_lim_reglement = $object->date_lim_reglement;
|
||||
$date = dol_mktime(12, 0, 0, GETPOST('invoicedatemonth', 'int'), GETPOST('invoicedateday', 'int'), GETPOST('invoicedateyear', 'int'));
|
||||
if (empty($date)) {
|
||||
$newdate = dol_mktime(0, 0, 0, GETPOST('invoicedatemonth', 'int'), GETPOST('invoicedateday', 'int'), GETPOST('invoicedateyear', 'int'), 'tzserver');
|
||||
if (empty($newdate)) {
|
||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
|
||||
header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$id.'&action=editinvoicedate');
|
||||
header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$id.'&action=editinvoicedate&token='.newToken());
|
||||
exit;
|
||||
}
|
||||
$object->date = $date;
|
||||
if ($newdate > (dol_now('tzuserrel') + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
|
||||
if (empty($conf->global->INVOICE_MAX_FUTURE_DELAY)) {
|
||||
setEventMessages($langs->trans("WarningInvoiceDateInFuture"), null, 'warnings');
|
||||
} else {
|
||||
setEventMessages($langs->trans("WarningInvoiceDateTooFarInFuture"), null, 'warnings');
|
||||
}
|
||||
}
|
||||
|
||||
$object->date = $newdate;
|
||||
$new_date_lim_reglement = $object->calculate_date_lim_reglement();
|
||||
if ($new_date_lim_reglement > $old_date_lim_reglement) {
|
||||
$object->date_lim_reglement = $new_date_lim_reglement;
|
||||
@ -413,7 +421,9 @@ if (empty($reshook)) {
|
||||
}
|
||||
} elseif ($action == 'setdate_pointoftax' && $usercancreate) {
|
||||
$object->fetch($id);
|
||||
$date_pointoftax = dol_mktime(12, 0, 0, $_POST['date_pointoftaxmonth'], $_POST['date_pointoftaxday'], $_POST['date_pointoftaxyear']);
|
||||
|
||||
$date_pointoftax = dol_mktime(0, 0, 0, GETPOST('date_pointoftaxmonth', 'int'), GETPOST('date_pointoftaxday', 'int'), GETPOST('date_pointoftaxyear', 'int'), 'tzserver');
|
||||
|
||||
$object->date_pointoftax = $date_pointoftax;
|
||||
$result = $object->update($user);
|
||||
if ($result < 0) {
|
||||
@ -986,14 +996,16 @@ if (empty($reshook)) {
|
||||
$error++;
|
||||
}
|
||||
|
||||
$dateinvoice = dol_mktime(0, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'), 'tzserver'); // If we enter the 02 january, we need to save the 02 january for server
|
||||
$date_pointoftax = dol_mktime(0, 0, 0, GETPOST('date_pointoftaxmonth', 'int'), GETPOST('date_pointoftaxday', 'int'), GETPOST('date_pointoftaxyear', 'int'), 'tzserver');
|
||||
|
||||
// Replacement invoice
|
||||
if (GETPOST('type') == Facture::TYPE_REPLACEMENT) {
|
||||
$dateinvoice = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
|
||||
if (empty($dateinvoice)) {
|
||||
$error++;
|
||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
|
||||
$action = 'create';
|
||||
} elseif ($dateinvoice > (dol_get_last_hour(dol_now()) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
|
||||
} elseif ($dateinvoice > (dol_get_last_hour(dol_now('tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
|
||||
$error++;
|
||||
setEventMessages($langs->trans("ErrorDateIsInFuture"), null, 'errors');
|
||||
$action = 'create';
|
||||
@ -1005,8 +1017,6 @@ if (empty($reshook)) {
|
||||
$action = 'create';
|
||||
}
|
||||
|
||||
$date_pointoftax = dol_mktime(12, 0, 0, GETPOST('date_pointoftaxmonth', 'int'), GETPOST('date_pointoftaxday', 'int'), GETPOST('date_pointoftaxyear', 'int'));
|
||||
|
||||
if (!$error) {
|
||||
// This is a replacement invoice
|
||||
$result = $object->fetch(GETPOST('fac_replacement', 'int'));
|
||||
@ -1049,19 +1059,16 @@ if (empty($reshook)) {
|
||||
$action = 'create';
|
||||
}
|
||||
|
||||
$dateinvoice = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
|
||||
if (empty($dateinvoice)) {
|
||||
$error++;
|
||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
|
||||
$action = 'create';
|
||||
} elseif ($dateinvoice > (dol_get_last_hour(dol_now()) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
|
||||
} elseif ($dateinvoice > (dol_get_last_hour(dol_now('tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
|
||||
$error++;
|
||||
setEventMessages($langs->trans("ErrorDateIsInFuture"), null, 'errors');
|
||||
$action = 'create';
|
||||
}
|
||||
|
||||
$date_pointoftax = dol_mktime(12, 0, 0, GETPOST('date_pointoftaxmonth', 'int'), GETPOST('date_pointoftaxday', 'int'), GETPOST('date_pointoftaxyear', 'int'));
|
||||
|
||||
if (!$error) {
|
||||
if (!empty($originentity)) {
|
||||
$object->entity = $originentity;
|
||||
@ -1265,19 +1272,16 @@ if (empty($reshook)) {
|
||||
|
||||
// Standard invoice or Deposit invoice, created from a Predefined template invoice
|
||||
if ((GETPOST('type') == Facture::TYPE_STANDARD || GETPOST('type') == Facture::TYPE_DEPOSIT) && GETPOST('fac_rec', 'int') > 0) {
|
||||
$dateinvoice = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
|
||||
if (empty($dateinvoice)) {
|
||||
$error++;
|
||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
|
||||
$action = 'create';
|
||||
} elseif ($dateinvoice > (dol_get_last_hour(dol_now()) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
|
||||
} elseif ($dateinvoice > (dol_get_last_hour(dol_now('tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
|
||||
$error++;
|
||||
setEventMessages($langs->trans("ErrorDateIsInFuture"), null, 'errors');
|
||||
$action = 'create';
|
||||
}
|
||||
|
||||
$date_pointoftax = dol_mktime(12, 0, 0, $_POST['date_pointoftaxmonth'], $_POST['date_pointoftaxday'], $_POST['date_pointoftaxyear']);
|
||||
|
||||
if (!$error) {
|
||||
$object->socid = GETPOST('socid', 'int');
|
||||
$object->type = GETPOST('type');
|
||||
@ -1312,8 +1316,6 @@ if (empty($reshook)) {
|
||||
$typeamount = GETPOST('typedeposit', 'aZ09');
|
||||
$valuestandardinvoice = price2num(str_replace('%', '', GETPOST('valuestandardinvoice', 'alpha')), 'MU');
|
||||
$valuedeposit = price2num(str_replace('%', '', GETPOST('valuedeposit', 'alpha')), 'MU');
|
||||
$dateinvoice = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
|
||||
$date_pointoftax = dol_mktime(12, 0, 0, GETPOST('date_pointoftaxmonth', 'int'), GETPOST('date_pointoftaxday', 'int'), GETPOST('date_pointoftaxyear', 'int'));
|
||||
|
||||
if (GETPOST('socid', 'int') < 1) {
|
||||
$error++;
|
||||
@ -1325,7 +1327,7 @@ if (empty($reshook)) {
|
||||
$error++;
|
||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
|
||||
$action = 'create';
|
||||
} elseif ($dateinvoice > (dol_get_last_hour(dol_now()) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
|
||||
} elseif ($dateinvoice > (dol_get_last_hour(dol_now('tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
|
||||
$error++;
|
||||
setEventMessages($langs->trans("ErrorDateIsInFuture"), null, 'errors');
|
||||
$action = 'create';
|
||||
@ -1807,19 +1809,16 @@ if (empty($reshook)) {
|
||||
|
||||
// Situation invoices
|
||||
if (GETPOST('type') == Facture::TYPE_SITUATION && GETPOST('situations')) {
|
||||
$dateinvoice = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
|
||||
if (empty($dateinvoice)) {
|
||||
$error++;
|
||||
$mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date"));
|
||||
setEventMessages($mesg, null, 'errors');
|
||||
} elseif ($dateinvoice > (dol_get_last_hour(dol_now()) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
|
||||
} elseif ($dateinvoice > (dol_get_last_hour(dol_now('tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
|
||||
$error++;
|
||||
setEventMessages($langs->trans("ErrorDateIsInFuture"), null, 'errors');
|
||||
$action = 'create';
|
||||
}
|
||||
|
||||
$date_pointoftax = dol_mktime(12, 0, 0, GETPOST('date_pointoftaxmonth', 'int'), GETPOST('date_pointoftaxday', 'int'), GETPOST('date_pointoftaxyear', 'int'));
|
||||
|
||||
if (!(GETPOST('situations', 'int') > 0)) {
|
||||
$error++;
|
||||
$mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("InvoiceSituation"));
|
||||
@ -3514,7 +3513,8 @@ if ($action == 'create') {
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
$newdateinvoice = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
|
||||
$newdateinvoice = dol_mktime(0, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'), 'tzserver');
|
||||
$date_pointoftax = dol_mktime(0, 0, 0, GETPOST('date_pointoftaxmonth', 'int'), GETPOST('date_pointoftaxday', 'int'), GETPOST('date_pointoftaxyear', 'int'), 'tzserver');
|
||||
|
||||
// Date invoice
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans('DateInvoice').'</td><td colspan="2">';
|
||||
@ -3524,7 +3524,6 @@ if ($action == 'create') {
|
||||
// Date point of tax
|
||||
if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans('DatePointOfTax').'</td><td colspan="2">';
|
||||
$date_pointoftax = dol_mktime(12, 0, 0, GETPOST('date_pointoftaxmonth', 'int'), GETPOST('date_pointoftaxday', 'int'), GETPOST('date_pointoftaxyear', 'int'));
|
||||
print $form->selectDate($date_pointoftax ? $date_pointoftax : -1, 'date_pointoftax', '', '', '', "add", 1, 1);
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
@ -2487,7 +2487,7 @@ function dol_getdate($timestamp, $fast = false, $forcetimezone = '')
|
||||
* False or 0 or 'tzserver' = local to server TZ
|
||||
* 'auto'
|
||||
* 'tzuser' = local to user TZ taking dst into account at the current date. Not yet implemented.
|
||||
* 'tzuserrel' = local to user TZ taking dst into account at the given date. Use this one to convert date input from user.
|
||||
* 'tzuserrel' = local to user TZ taking dst into account at the given date. Use this one to convert date input from user into a GMT date.
|
||||
* 'tz,TimeZone' = use specified timezone
|
||||
* @param int $check 0=No check on parameters (Can use day 32, etc...)
|
||||
* @return int|string Date as a timestamp, '' or false if error
|
||||
|
||||
@ -408,9 +408,9 @@ if (empty($reshook)) {
|
||||
dol_print_error($db);
|
||||
}
|
||||
} elseif ($action == 'setdatef' && $usercancreate) {
|
||||
$newdate = dol_mktime(0, 0, 0, $_POST['datefmonth'], $_POST['datefday'], $_POST['datefyear']);
|
||||
if ($newdate > (dol_now() + (empty($conf->global->INVOICE_MAX_OFFSET_IN_FUTURE) ? 0 : $conf->global->INVOICE_MAX_OFFSET_IN_FUTURE))) {
|
||||
if (empty($conf->global->INVOICE_MAX_OFFSET_IN_FUTURE)) {
|
||||
$newdate = dol_mktime(0, 0, 0, GETPOST('datefmonth', 'int'), GETPOST('datefday', 'int'), GETPOST('datefyear', 'int'), 'tzserver');
|
||||
if ($newdate > (dol_now('tzuserrel') + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
|
||||
if (empty($conf->global->INVOICE_MAX_FUTURE_DELAY)) {
|
||||
setEventMessages($langs->trans("WarningInvoiceDateInFuture"), null, 'warnings');
|
||||
} else {
|
||||
setEventMessages($langs->trans("WarningInvoiceDateTooFarInFuture"), null, 'warnings');
|
||||
@ -434,7 +434,7 @@ if (empty($reshook)) {
|
||||
}
|
||||
} elseif ($action == 'setdate_lim_reglement' && $usercancreate) {
|
||||
$object->fetch($id);
|
||||
$object->date_echeance = dol_mktime(12, 0, 0, $_POST['date_lim_reglementmonth'], $_POST['date_lim_reglementday'], $_POST['date_lim_reglementyear']);
|
||||
$object->date_echeance = dol_mktime(12, 0, 0, GETPOST('date_lim_reglementmonth', 'int'), GETPOST('date_lim_reglementday', 'int'), GETPOST('date_lim_reglementyear', 'int'));
|
||||
if (!empty($object->date_echeance) && $object->date_echeance < $object->date) {
|
||||
$object->date_echeance = $object->date;
|
||||
setEventMessages($langs->trans("DatePaymentTermCantBeLowerThanObjectDate"), null, 'warnings');
|
||||
@ -692,8 +692,12 @@ if (empty($reshook)) {
|
||||
$error++;
|
||||
}
|
||||
|
||||
$dateinvoice = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
|
||||
$datedue = dol_mktime(12, 0, 0, GETPOST('echmonth', 'int'), GETPOST('echday', 'int'), GETPOST('echyear', 'int'));
|
||||
$dateinvoice = dol_mktime(0, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'), 'tzserver'); // If we enter the 02 january, we need to save the 02 january for server
|
||||
$datedue = dol_mktime(0, 0, 0, GETPOST('echmonth', 'int'), GETPOST('echday', 'int'), GETPOST('echyear', 'int'), 'tzserver');
|
||||
/*var_dump($dateinvoice.' '.dol_print_date($dateinvoice, 'dayhour'));
|
||||
var_dump(dol_now('tzuserrel').' '.dol_get_last_hour(dol_now('tzuserrel')).' '.dol_print_date(dol_now('tzuserrel'),'dayhour').' '.dol_print_date(dol_get_last_hour(dol_now('tzuserrel')), 'dayhour'));
|
||||
var_dump($db->idate($dateinvoice));
|
||||
exit;*/
|
||||
|
||||
// Replacement invoice
|
||||
if (GETPOST('type') == FactureFournisseur::TYPE_REPLACEMENT) {
|
||||
@ -702,7 +706,7 @@ if (empty($reshook)) {
|
||||
$action = 'create';
|
||||
$_GET['socid'] = $_POST['socid'];
|
||||
$error++;
|
||||
} elseif ($dateinvoice > (dol_get_last_hour(dol_now()) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
|
||||
} elseif ($dateinvoice > (dol_get_last_hour(dol_now('tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
|
||||
$error++;
|
||||
setEventMessages($langs->trans("ErrorDateIsInFuture"), null, 'errors');
|
||||
$action = 'create';
|
||||
@ -766,7 +770,7 @@ if (empty($reshook)) {
|
||||
$action = 'create';
|
||||
$_GET['socid'] = $_POST['socid'];
|
||||
$error++;
|
||||
} elseif ($dateinvoice > (dol_get_last_hour(dol_now()) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
|
||||
} elseif ($dateinvoice > (dol_get_last_hour(dol_now('tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
|
||||
$error++;
|
||||
setEventMessages($langs->trans("ErrorDateIsInFuture"), null, 'errors');
|
||||
$action = 'create';
|
||||
@ -875,7 +879,7 @@ if (empty($reshook)) {
|
||||
$action = 'create';
|
||||
$_GET['socid'] = $_POST['socid'];
|
||||
$error++;
|
||||
} elseif ($dateinvoice > (dol_get_last_hour(dol_now()) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
|
||||
} elseif ($dateinvoice > (dol_get_last_hour(dol_now('tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
|
||||
$error++;
|
||||
setEventMessages($langs->trans("ErrorDateIsInFuture"), null, 'errors');
|
||||
$action = 'create';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user