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