New add test dates order for start and end dates of a line of a contract

This commit is contained in:
KHELIFA 2017-10-06 17:58:15 +02:00
parent 43d85af5ae
commit e715a680bf

View File

@ -440,6 +440,14 @@ if (empty($reshook))
$error++; $error++;
} }
$date_start = dol_mktime(GETPOST('date_start' . $predef . 'hour'), GETPOST('date_start' . $predef . 'min'), GETPOST('date_start' . $predef . 'sec'), GETPOST('date_start' . $predef . 'month'), GETPOST('date_start' . $predef . 'day'), GETPOST('date_start' . $predef . 'year'));
$date_end = dol_mktime(GETPOST('date_end' . $predef . 'hour'), GETPOST('date_end' . $predef . 'min'), GETPOST('date_end' . $predef . 'sec'), GETPOST('date_end' . $predef . 'month'), GETPOST('date_end' . $predef . 'day'), GETPOST('date_end' . $predef . 'year'));
if (!empty($date_end) && $date_start > $date_end)
{
setEventMessages($langs->trans("Error").': '.$langs->trans("DateStartPlanned").' > '.$langs->trans("DateEndPlanned"), null, 'errors');
$error++;
}
// Extrafields // Extrafields
$extrafieldsline = new ExtraFields($db); $extrafieldsline = new ExtraFields($db);
$extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
@ -638,90 +646,100 @@ if (empty($reshook))
else if ($action == 'updateline' && $user->rights->contrat->creer && ! GETPOST('cancel','alpha')) else if ($action == 'updateline' && $user->rights->contrat->creer && ! GETPOST('cancel','alpha'))
{ {
$objectline = new ContratLigne($db); if (!empty($date_end_update) && $date_start_update > $date_end_update)
if ($objectline->fetch(GETPOST('elrowid'))) {
{ setEventMessages($langs->trans("Error").': '.$langs->trans("DateStartPlanned").' > '.$langs->trans("DateEndPlanned"), null, 'errors');
$db->begin(); $action = 'editline';
$_GET['rowid'] = GETPOST('elrowid');
$error++;
}
if ($date_start_real_update == '') $date_start_real_update=$objectline->date_ouverture; if (!$error) {
if ($date_end_real_update == '') $date_end_real_update=$objectline->date_cloture; $objectline = new ContratLigne($db);
if ($objectline->fetch(GETPOST('elrowid')))
{
$db->begin();
$vat_rate = GETPOST('eltva_tx'); if ($date_start_real_update == '') $date_start_real_update=$objectline->date_ouverture;
// Define info_bits if ($date_end_real_update == '') $date_end_real_update=$objectline->date_cloture;
$info_bits = 0;
if (preg_match('/\*/', $vat_rate))
$info_bits |= 0x01;
// Define vat_rate $vat_rate = GETPOST('eltva_tx');
$vat_rate = str_replace('*', '', $vat_rate); // Define info_bits
$localtax1_tx=get_localtax($vat_rate, 1, $object->thirdparty, $mysoc); $info_bits = 0;
$localtax2_tx=get_localtax($vat_rate, 2, $object->thirdparty, $mysoc); if (preg_match('/\*/', $vat_rate))
$info_bits |= 0x01;
$txtva = $vat_rate; // Define vat_rate
$vat_rate = str_replace('*', '', $vat_rate);
$localtax1_tx=get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
$localtax2_tx=get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
// Clean vat code $txtva = $vat_rate;
$vat_src_code='';
if (preg_match('/\((.*)\)/', $txtva, $reg))
{
$vat_src_code = $reg[1];
$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
}
// ajout prix d'achat // Clean vat code
$fk_fournprice = $_POST['fournprice']; $vat_src_code='';
if ( ! empty($_POST['buying_price']) ) if (preg_match('/\((.*)\)/', $txtva, $reg))
$pa_ht = $_POST['buying_price']; {
else $vat_src_code = $reg[1];
$pa_ht = null; $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
}
$fk_unit = GETPOST('unit', 'alpha'); // ajout prix d'achat
$fk_fournprice = $_POST['fournprice'];
if ( ! empty($_POST['buying_price']) )
$pa_ht = $_POST['buying_price'];
else
$pa_ht = null;
$objectline->description=GETPOST('product_desc','none'); $fk_unit = GETPOST('unit', 'alpha');
$objectline->price_ht=GETPOST('elprice');
$objectline->subprice=GETPOST('elprice');
$objectline->qty=GETPOST('elqty');
$objectline->remise_percent=GETPOST('elremise_percent');
$objectline->tva_tx=($txtva?$txtva:0); // Field may be disabled, so we use vat rate 0
$objectline->vat_src_code=$vat_src_code;
$objectline->localtax1_tx=is_numeric($localtax1_tx)?$localtax1_tx:0;
$objectline->localtax2_tx=is_numeric($localtax2_tx)?$localtax2_tx:0;
$objectline->date_ouverture_prevue=$date_start_update;
$objectline->date_ouverture=$date_start_real_update;
$objectline->date_fin_validite=$date_end_update;
$objectline->date_cloture=$date_end_real_update;
$objectline->fk_user_cloture=$user->id;
$objectline->fk_fournprice=$fk_fournprice;
$objectline->pa_ht=$pa_ht;
if ($fk_unit > 0) { $objectline->description=GETPOST('product_desc','none');
$objectline->fk_unit = GETPOST('unit'); $objectline->price_ht=GETPOST('elprice');
} else { $objectline->subprice=GETPOST('elprice');
$objectline->fk_unit = null; $objectline->qty=GETPOST('elqty');
} $objectline->remise_percent=GETPOST('elremise_percent');
$objectline->tva_tx=($txtva?$txtva:0); // Field may be disabled, so we use vat rate 0
$objectline->vat_src_code=$vat_src_code;
$objectline->localtax1_tx=is_numeric($localtax1_tx)?$localtax1_tx:0;
$objectline->localtax2_tx=is_numeric($localtax2_tx)?$localtax2_tx:0;
$objectline->date_ouverture_prevue=$date_start_update;
$objectline->date_ouverture=$date_start_real_update;
$objectline->date_fin_validite=$date_end_update;
$objectline->date_cloture=$date_end_real_update;
$objectline->fk_user_cloture=$user->id;
$objectline->fk_fournprice=$fk_fournprice;
$objectline->pa_ht=$pa_ht;
// Extrafields if ($fk_unit > 0) {
$extrafieldsline = new ExtraFields($db); $objectline->fk_unit = GETPOST('unit');
$extralabelsline = $extrafieldsline->fetch_name_optionals_label($objectline->table_element); } else {
$array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef); $objectline->fk_unit = null;
$objectline->array_options=$array_options; }
// TODO verifier price_min si fk_product et multiprix // Extrafields
$extrafieldsline = new ExtraFields($db);
$extralabelsline = $extrafieldsline->fetch_name_optionals_label($objectline->table_element);
$array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef);
$objectline->array_options=$array_options;
$result=$objectline->update($user); // TODO verifier price_min si fk_product et multiprix
if ($result > 0)
{ $result=$objectline->update($user);
$db->commit(); if ($result > 0)
} {
else $db->commit();
{ }
setEventMessages($objectline->error, $objectline->errors, 'errors'); else
$db->rollback(); {
} setEventMessages($objectline->error, $objectline->errors, 'errors');
} $db->rollback();
else }
{ }
setEventMessages($objectline->error, $objectline->errors, 'errors'); else
} {
setEventMessages($objectline->error, $objectline->errors, 'errors');
}
}
} }
else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->contrat->creer) else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->contrat->creer)