NEW Add trigget FICHINTER_UNVALIDATE

Standardize code of setDraft.
This commit is contained in:
Laurent Destailleur 2019-03-21 17:37:56 +01:00
parent 5d21547854
commit 90df30e412
7 changed files with 114 additions and 35 deletions

View File

@ -604,7 +604,7 @@ class BOM extends CommonObject
*/
public function setDraft($user)
{
global $conf,$langs;
global $conf, $langs;
$error=0;
@ -630,6 +630,11 @@ class BOM extends CommonObject
dol_syslog(get_class($this)."::setDraft", LOG_DEBUG);
if ($this->db->query($sql))
{
if (! $error)
{
$this->oldcopy= clone $this;
}
if (!$error) {
// Call trigger
$result=$this->call_trigger('BOM_UNVALIDATE', $user);
@ -640,7 +645,7 @@ class BOM extends CommonObject
$this->status=self::STATUS_DRAFT;
$this->db->commit();
return 1;
}else {
} else {
$this->db->rollback();
return -1;
}

View File

@ -2610,12 +2610,20 @@ class Propal extends CommonObject
// phpcs:enable
$error=0;
// Protection
if ($this->statut <= self::STATUS_DRAFT)
{
return 0;
}
dol_syslog(get_class($this)."::setDraft", LOG_DEBUG);
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_statut = ".self::STATUS_DRAFT;
$sql = "UPDATE ".MAIN_DB_PREFIX."propal";
$sql.= " SET fk_statut = ".self::STATUS_DRAFT;
$sql.= " WHERE rowid = ".$this->id;
dol_syslog(__METHOD__, LOG_DEBUG);
$resql=$this->db->query($sql);
if (!$resql)
{
@ -2626,8 +2634,6 @@ class Propal extends CommonObject
if (! $error)
{
$this->oldcopy= clone $this;
$this->statut = self::STATUS_DRAFT;
$this->brouillon = 1;
}
if (! $notrigger && empty($error))
@ -2640,7 +2646,10 @@ class Propal extends CommonObject
if (! $error)
{
$this->db->commit();
$this->statut = self::STATUS_DRAFT;
$this->brouillon = 1;
$this->db->commit();
return 1;
}
else

View File

@ -499,16 +499,22 @@ class Commande extends CommonOrder
return -1;
}
dol_syslog(get_class($this)."::set_draft", LOG_DEBUG);
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."commande";
$sql.= " SET fk_statut = ".self::STATUS_DRAFT;
$sql.= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this)."::set_draft", LOG_DEBUG);
if ($this->db->query($sql))
{
// If stock is decremented on validate order, we must reincrement it
if (! $error)
{
$this->oldcopy= clone $this;
}
// If stock is decremented on validate order, we must reincrement it
if (! empty($conf->stock->enabled) && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1)
{
$result = 0;

View File

@ -2554,16 +2554,22 @@ class Facture extends CommonInvoice
return 0;
}
dol_syslog(get_class($this)."::set_draft", LOG_DEBUG);
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."facture";
$sql.= " SET fk_statut = ".self::STATUS_DRAFT;
$sql.= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this)."::set_draft", LOG_DEBUG);
$result=$this->db->query($sql);
if ($result)
{
if (! $error)
{
$this->oldcopy= clone $this;
}
// Si on decremente le produit principal et ses composants a la validation de facture, on réincrement
if ($this->type != self::TYPE_DEPOSIT && $result >= 0 && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_BILL))
{
@ -2589,6 +2595,7 @@ class Facture extends CommonInvoice
$old_statut=$this->statut;
$this->brouillon = 1;
$this->statut = self::STATUS_DRAFT;
// Call trigger
$result=$this->call_trigger('BILL_UNVALIDATE', $user);
if ($result < 0)

View File

@ -445,35 +445,56 @@ class Fichinter extends CommonObject
* Set status to draft
*
* @param User $user User that set draft
* @return int <0 if KO, >0 if OK
* @return int <0 if KO, >0 if OK
*/
public function setDraft($user)
{
global $langs, $conf;
if ($this->statut != 0)
$error=0;
// Protection
if ($this->statut <= self::STATUS_DRAFT)
{
$this->db->begin();
return 0;
}
$sql = "UPDATE ".MAIN_DB_PREFIX."fichinter";
$sql.= " SET fk_statut = 0";
$sql.= " WHERE rowid = ".$this->id;
$sql.= " AND entity = ".$conf->entity;
dol_syslog(get_class($this)."::setDraft", LOG_DEBUG);
dol_syslog("Fichinter::setDraft", LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
$this->error=$this->db->lasterror();
return -1;
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."fichinter";
$sql.= " SET fk_statut = ".self::STATUS_DRAFT;
$sql.= " WHERE rowid = ".$this->id;
$resql=$this->db->query($sql);
if ($resql)
{
if (!$error) {
$this->oldcopy = clone $this;
}
if (!$error) {
// Call trigger
$result=$this->call_trigger('FICHINTER_UNVALIDATE', $user);
if ($result < 0) $error++;
}
if (!$error) {
$this->statut=self::STATUS_DRAFT;
$this->db->commit();
return 1;
} else {
$this->db->rollback();
return -1;
}
}
else
{
$this->db->rollback();
$this->error=$this->db->lasterror();
return -1;
}
}
/**

View File

@ -1471,16 +1471,22 @@ class FactureFournisseur extends CommonInvoice
return 0;
}
dol_syslog(get_class($this)."::set_draft", LOG_DEBUG);
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn";
$sql.= " SET fk_statut = 0";
$sql.= " SET fk_statut = ".self::STATUS_DRAFT;
$sql.= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this)."::set_draft", LOG_DEBUG);
$result=$this->db->query($sql);
if ($result)
{
if (! $error)
{
$this->oldcopy= clone $this;
}
// Si on incremente le produit principal et ses composants a la validation de facture fournisseur, on decremente
if ($result >= 0 && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL))
{

View File

@ -1883,14 +1883,39 @@ class SupplierProposal extends CommonObject
// phpcs:enable
global $conf,$langs;
$sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal SET fk_statut = 0";
$error = 0;
if ($this->statut == self::STATUS_DRAFT)
{
dol_syslog(get_class($this)."::setDraft already draft status", LOG_WARNING);
return 0;
}
$sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal";
$sql.= " SET fk_statut = ".self::STATUS_DRAFT;
$sql.= " WHERE rowid = ".$this->id;
if ($this->db->query($sql))
{
$this->statut = 0;
$this->brouillon = 1;
return 1;
if (!$error) {
$this->oldcopy = clone $this;
}
if (!$error) {
// Call trigger
$result=$this->call_trigger('SUPPLIER_PROPOSAL_UNVALIDATE', $user);
if ($result < 0) $error++;
}
if (!$error) {
$this->statut=self::STATUS_DRAFT;
$this->brouillon = 1;
$this->db->commit();
return 1;
} else {
$this->db->rollback();
return -1;
}
}
else
{