NEW Add option CONTRACT_SYNC_PLANNED_DATE_OF_SERVICES
This commit is contained in:
parent
f3f39fb1ee
commit
9d0314dbae
@ -657,43 +657,53 @@ 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'))
|
||||||
{
|
{
|
||||||
if (!empty($date_start_update) && !empty($date_end_update) && $date_start_update > $date_end_update)
|
$error = 0;
|
||||||
{
|
|
||||||
setEventMessages($langs->trans("Error").': '.$langs->trans("DateStartPlanned").' > '.$langs->trans("DateEndPlanned"), null, 'errors');
|
|
||||||
$action = 'editline';
|
|
||||||
$_GET['rowid'] = GETPOST('elrowid');
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$error) {
|
if (!empty($date_start_update) && !empty($date_end_update) && $date_start_update > $date_end_update)
|
||||||
$objectline = new ContratLigne($db);
|
{
|
||||||
if ($objectline->fetch(GETPOST('elrowid')))
|
setEventMessages($langs->trans("Error").': '.$langs->trans("DateStartPlanned").' > '.$langs->trans("DateEndPlanned"), null, 'errors');
|
||||||
{
|
$action = 'editline';
|
||||||
$db->begin();
|
$_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')) < 0)
|
||||||
|
{
|
||||||
|
setEventMessages($objectline->error, $objectline->errors, 'errors');
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$vat_rate = GETPOST('eltva_tx');
|
$db->begin();
|
||||||
// Define info_bits
|
|
||||||
$info_bits = 0;
|
if (! $error)
|
||||||
if (preg_match('/\*/', $vat_rate))
|
{
|
||||||
|
if ($date_start_real_update == '') $date_start_real_update=$objectline->date_ouverture;
|
||||||
|
if ($date_end_real_update == '') $date_end_real_update=$objectline->date_cloture;
|
||||||
|
|
||||||
|
$vat_rate = GETPOST('eltva_tx');
|
||||||
|
// Define info_bits
|
||||||
|
$info_bits = 0;
|
||||||
|
if (preg_match('/\*/', $vat_rate))
|
||||||
$info_bits |= 0x01;
|
$info_bits |= 0x01;
|
||||||
|
|
||||||
// Define vat_rate
|
// Define vat_rate
|
||||||
$vat_rate = str_replace('*', '', $vat_rate);
|
$vat_rate = str_replace('*', '', $vat_rate);
|
||||||
$localtax1_tx=get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
|
$localtax1_tx=get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
|
||||||
$localtax2_tx=get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
|
$localtax2_tx=get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
|
||||||
|
|
||||||
$txtva = $vat_rate;
|
$txtva = $vat_rate;
|
||||||
|
|
||||||
// Clean vat code
|
// Clean vat code
|
||||||
$vat_src_code='';
|
$vat_src_code='';
|
||||||
if (preg_match('/\((.*)\)/', $txtva, $reg))
|
if (preg_match('/\((.*)\)/', $txtva, $reg))
|
||||||
{
|
{
|
||||||
$vat_src_code = $reg[1];
|
$vat_src_code = $reg[1];
|
||||||
$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
|
$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
|
||||||
}
|
}
|
||||||
|
|
||||||
// ajout prix d'achat
|
// ajout prix d'achat
|
||||||
$fk_fournprice = $_POST['fournprice'];
|
$fk_fournprice = $_POST['fournprice'];
|
||||||
@ -704,22 +714,22 @@ if (empty($reshook))
|
|||||||
|
|
||||||
$fk_unit = GETPOST('unit', 'alpha');
|
$fk_unit = GETPOST('unit', 'alpha');
|
||||||
|
|
||||||
$objectline->description=GETPOST('product_desc','none');
|
$objectline->description=GETPOST('product_desc','none');
|
||||||
$objectline->price_ht=GETPOST('elprice');
|
$objectline->price_ht=GETPOST('elprice');
|
||||||
$objectline->subprice=GETPOST('elprice');
|
$objectline->subprice=GETPOST('elprice');
|
||||||
$objectline->qty=GETPOST('elqty');
|
$objectline->qty=GETPOST('elqty');
|
||||||
$objectline->remise_percent=GETPOST('elremise_percent');
|
$objectline->remise_percent=GETPOST('elremise_percent');
|
||||||
$objectline->tva_tx=($txtva?$txtva:0); // Field may be disabled, so we use vat rate 0
|
$objectline->tva_tx=($txtva?$txtva:0); // Field may be disabled, so we use vat rate 0
|
||||||
$objectline->vat_src_code=$vat_src_code;
|
$objectline->vat_src_code=$vat_src_code;
|
||||||
$objectline->localtax1_tx=is_numeric($localtax1_tx)?$localtax1_tx:0;
|
$objectline->localtax1_tx=is_numeric($localtax1_tx)?$localtax1_tx:0;
|
||||||
$objectline->localtax2_tx=is_numeric($localtax2_tx)?$localtax2_tx:0;
|
$objectline->localtax2_tx=is_numeric($localtax2_tx)?$localtax2_tx:0;
|
||||||
$objectline->date_ouverture_prevue=$date_start_update;
|
$objectline->date_ouverture_prevue=$date_start_update;
|
||||||
$objectline->date_ouverture=$date_start_real_update;
|
$objectline->date_ouverture=$date_start_real_update;
|
||||||
$objectline->date_fin_validite=$date_end_update;
|
$objectline->date_fin_validite=$date_end_update;
|
||||||
$objectline->date_cloture=$date_end_real_update;
|
$objectline->date_cloture=$date_end_real_update;
|
||||||
$objectline->fk_user_cloture=$user->id;
|
$objectline->fk_user_cloture=$user->id;
|
||||||
$objectline->fk_fournprice=$fk_fournprice;
|
$objectline->fk_fournprice=$fk_fournprice;
|
||||||
$objectline->pa_ht=$pa_ht;
|
$objectline->pa_ht=$pa_ht;
|
||||||
|
|
||||||
if ($fk_unit > 0) {
|
if ($fk_unit > 0) {
|
||||||
$objectline->fk_unit = GETPOST('unit');
|
$objectline->fk_unit = GETPOST('unit');
|
||||||
@ -727,30 +737,30 @@ if (empty($reshook))
|
|||||||
$objectline->fk_unit = null;
|
$objectline->fk_unit = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extrafields
|
// Extrafields
|
||||||
$extrafieldsline = new ExtraFields($db);
|
$extrafieldsline = new ExtraFields($db);
|
||||||
$extralabelsline = $extrafieldsline->fetch_name_optionals_label($objectline->table_element);
|
$extralabelsline = $extrafieldsline->fetch_name_optionals_label($objectline->table_element);
|
||||||
$array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef);
|
$array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef);
|
||||||
$objectline->array_options=$array_options;
|
$objectline->array_options=$array_options;
|
||||||
|
|
||||||
// TODO verifier price_min si fk_product et multiprix
|
// TODO verifier price_min si fk_product et multiprix
|
||||||
|
|
||||||
$result=$objectline->update($user);
|
$result=$objectline->update($user);
|
||||||
if ($result > 0)
|
if ($result < 0)
|
||||||
{
|
{
|
||||||
$db->commit();
|
$error++;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setEventMessages($objectline->error, $objectline->errors, 'errors');
|
setEventMessages($objectline->error, $objectline->errors, 'errors');
|
||||||
$db->rollback();
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
if (! $error)
|
||||||
{
|
{
|
||||||
setEventMessages($objectline->error, $objectline->errors, 'errors');
|
$db->commit();
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
$db->rollback();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->contrat->creer)
|
else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->contrat->creer)
|
||||||
|
|||||||
@ -2911,22 +2911,14 @@ class ContratLigne extends CommonObjectLine
|
|||||||
|
|
||||||
dol_syslog(get_class($this)."::update", LOG_DEBUG);
|
dol_syslog(get_class($this)."::update", LOG_DEBUG);
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql)
|
if (! $resql)
|
||||||
{
|
|
||||||
$contrat=new Contrat($this->db);
|
|
||||||
$contrat->fetch($this->fk_contrat);
|
|
||||||
$result=$contrat->update_statut($user);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
$this->error="Error ".$this->db->lasterror();
|
$this->error="Error ".$this->db->lasterror();
|
||||||
$error++;
|
$error++;
|
||||||
//return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options)>0) // For avoid conflicts if trigger used
|
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options)>0) // For avoid conflicts if trigger used
|
||||||
{
|
{
|
||||||
|
|
||||||
$result=$this->insertExtraFields();
|
$result=$this->insertExtraFields();
|
||||||
if ($result < 0)
|
if ($result < 0)
|
||||||
{
|
{
|
||||||
@ -2934,19 +2926,37 @@ class ContratLigne extends CommonObjectLine
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($error)) {
|
// Sync dates of all services
|
||||||
if (! $notrigger)
|
if (! $error && ! empty($conf->global->CONTRACT_SYNC_PLANNED_DATE_OF_SERVICES))
|
||||||
{
|
{
|
||||||
// Call trigger
|
$sql ='UPDATE '.MAIN_DB_PREFIX.'contratdet SET';
|
||||||
$result=$this->call_trigger('LINECONTRACT_UPDATE',$user);
|
$sql.= " date_ouverture_prevue = ".($this->date_ouverture_prevue!=''?"'".$this->db->idate($this->date_ouverture_prevue)."'":"null").",";
|
||||||
if ($result < 0) { $error++; $this->db->rollback(); return -1; }
|
$sql.= " date_fin_validite = ".($this->date_fin_validite!=''?"'".$this->db->idate($this->date_fin_validite)."'":"null");
|
||||||
// End call triggers
|
$sql.= " WHERE fk_contrat = ".$this->fk_contrat;
|
||||||
}
|
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
|
if (! $resql)
|
||||||
|
{
|
||||||
|
$error++;
|
||||||
|
$this->error="Error ".$this->db->lasterror();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($error)) {
|
if (! $error)
|
||||||
$this->db->commit();
|
{
|
||||||
return 1;
|
if (! $notrigger)
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('LINECONTRACT_UPDATE', $user);
|
||||||
|
if ($result < 0) { $error++; $this->db->rollback(); }
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
$this->errors[]=$this->error;
|
$this->errors[]=$this->error;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user