Fix: Date was lost if error during submit.

This commit is contained in:
Laurent Destailleur 2014-03-20 00:05:20 +01:00
parent 4bf822225e
commit a9aaac8e15

View File

@ -244,7 +244,9 @@ else if ($action == 'setmode' && $user->rights->facture->creer) {
$result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
if ($result < 0)
dol_print_error($db, $object->error);
} else if ($action == 'setinvoicedate' && $user->rights->facture->creer) {
}
else if ($action == 'setinvoicedate' && $user->rights->facture->creer) {
$object->fetch($id);
$old_date_lim_reglement = $object->date_lim_reglement;
$object->date = dol_mktime(12, 0, 0, $_POST['invoicedatemonth'], $_POST['invoicedateday'], $_POST['invoicedateyear']);
@ -256,7 +258,9 @@ else if ($action == 'setmode' && $user->rights->facture->creer) {
$result = $object->update($user);
if ($result < 0)
dol_print_error($db, $object->error);
} else if ($action == 'setconditions' && $user->rights->facture->creer) {
}
else if ($action == 'setconditions' && $user->rights->facture->creer) {
$object->fetch($id);
$object->cond_reglement_code = 0; // To clean property
$object->cond_reglement_id = 0; // To clean property
@ -273,7 +277,9 @@ else if ($action == 'setmode' && $user->rights->facture->creer) {
$result = $object->update($user);
if ($result < 0)
dol_print_error($db, $object->error);
} else if ($action == 'setpaymentterm' && $user->rights->facture->creer) {
}
else if ($action == 'setpaymentterm' && $user->rights->facture->creer) {
$object->fetch($id);
$object->date_lim_reglement = dol_mktime(12, 0, 0, $_POST['paymenttermmonth'], $_POST['paymenttermday'], $_POST['paymenttermyear']);
if ($object->date_lim_reglement < $object->date) {
@ -283,17 +289,23 @@ else if ($action == 'setmode' && $user->rights->facture->creer) {
$result = $object->update($user);
if ($result < 0)
dol_print_error($db, $object->error);
} else if ($action == 'setrevenuestamp' && $user->rights->facture->creer) {
}
else if ($action == 'setrevenuestamp' && $user->rights->facture->creer) {
$object->fetch($id);
$object->revenuestamp = GETPOST('revenuestamp');
$result = $object->update($user);
$object->update_price(1);
if ($result < 0)
dol_print_error($db, $object->error);
} else if ($action == 'setremisepercent' && $user->rights->facture->creer) {
}
else if ($action == 'setremisepercent' && $user->rights->facture->creer) {
$object->fetch($id);
$result = $object->set_remise($user, $_POST['remise_percent']);
} else if ($action == "setabsolutediscount" && $user->rights->facture->creer) {
}
else if ($action == "setabsolutediscount" && $user->rights->facture->creer) {
// POST[remise_id] ou POST[remise_id_for_payment]
if (! empty($_POST["remise_id"])) {
$ret = $object->fetch($id);
@ -564,9 +576,9 @@ else if ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $user->righ
/*
* Insert new invoice in database
*/
else if ($action == 'add' && $user->rights->facture->creer) {
if ($socid > 0)
$object->socid = GETPOST('socid', 'int');
else if ($action == 'add' && $user->rights->facture->creer)
{
if ($socid > 0) $object->socid = GETPOST('socid', 'int');
$db->begin();
@ -575,11 +587,11 @@ else if ($action == 'add' && $user->rights->facture->creer) {
// Fill array 'array_options' with data from add form
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels, $object);
if ($ret < 0)
$error ++;
if ($ret < 0) $error ++;
// Replacement invoice
if ($_POST ['type'] == 1) {
if ($_POST['type'] == Facture::TYPE_REPLACEMENT)
{
$datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
if (empty($datefacture)) {
$error ++;
@ -619,19 +631,23 @@ else if ($action == 'add' && $user->rights->facture->creer) {
}
// Credit note invoice
if ($_POST ['type'] == 2) {
if (! $_POST ['fac_avoir'] > 0) {
if ($_POST['type'] == Facture::TYPE_CREDIT_NOTE)
{
if (! ($_POST['fac_avoir'] > 0))
{
$error ++;
setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CorrectInvoice")), 'errors');
}
$datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
if (empty($datefacture)) {
if (empty($datefacture))
{
$error ++;
setEventMessage($langs->trans("ErrorFieldRequired", $langs->trans("Date")), 'errors');
}
if (! $error) {
if (! $error)
{
// Si facture avoir
$datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
@ -993,11 +1009,14 @@ else if ($action == 'add' && $user->rights->facture->creer) {
}
// End of object creation, we show it
if ($id > 0 && ! $error) {
if ($id > 0 && ! $error)
{
$db->commit();
header('Location: ' . $_SERVER ["PHP_SELF"] . '?facid=' . $id);
exit();
} else {
}
else
{
$db->rollback();
$action = 'create';
$_GET ["origin"] = $_POST["origin"];
@ -1007,26 +1026,30 @@ else if ($action == 'add' && $user->rights->facture->creer) {
}
// Add a new line
else if (($action == 'addline' || $action == 'addline_predef') && $user->rights->facture->creer) {
else if (($action == 'addline' || $action == 'addline_predef') && $user->rights->facture->creer)
{
$langs->load('errors');
$error = 0;
// Set if we used free entry or predefined product
if (GETPOST('addline_libre')) {
if (GETPOST('addline_libre'))
{
$predef = '';
$idprod = 0;
$product_desc = (GETPOST('dp_desc') ? GETPOST('dp_desc') : '');
$price_ht = GETPOST('price_ht');
$tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
}
if (GETPOST('addline_predefined')) {
if (GETPOST('addline_predefined'))
{
$predef = (($conf->global->MAIN_FEATURES_LEVEL < 2) ? '_predef' : '');
$idprod = GETPOST('idprod', 'int');
$product_desc = (GETPOST('product_desc') ? GETPOST('product_desc') : (GETPOST('np_desc') ? GETPOST('np_desc') : ''));
$price_ht = '';
$tva_tx = '';
}
if (GETPOST('usenewaddlineform')) { // TODO Remove this
if (GETPOST('usenewaddlineform')) // TODO Remove this
{
$idprod = GETPOST('idprod', 'int');
$product_desc = (GETPOST('product_desc') ? GETPOST('product_desc') : (GETPOST('np_desc') ? GETPOST('np_desc') : (GETPOST('dp_desc') ? GETPOST('dp_desc') : '')));
$price_ht = GETPOST('price_ht');
@ -1795,7 +1818,8 @@ if ($action == 'create')
if ($socid > 0)
$res = $soc->fetch($socid);
if (! empty($origin) && ! empty($originid)) {
if (! empty($origin) && ! empty($originid))
{
// Parse element/subelement (ex: project_task)
$element = $subelement = $origin;
if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) {
@ -2115,7 +2139,8 @@ if ($action == 'create')
print '</table>';
print '</td></tr>';
if ($socid > 0) {
if ($socid > 0)
{
// Discounts for third party
print '<tr><td>' . $langs->trans('Discounts') . '</td><td colspan="2">';
if ($soc->remise_percent)
@ -2136,7 +2161,8 @@ if ($action == 'create')
// Date invoice
print '<tr><td class="fieldrequired">' . $langs->trans('Date') . '</td><td colspan="2">';
$form->select_date($dateinvoice, '', '', '', '', "add", 1, 1);
$datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
$form->select_date($datefacture?$datefacture:$dateinvoice, '', '', '', '', "add", 1, 1);
print '</td></tr>';
// Payment term