diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index 899fcdbe0e6..15ae8f3c21f 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -178,90 +178,6 @@ if (empty($reshook)) $action = ''; } } - - if ($action == 'confirm_validate' && $confirm == 'yes' && $permissionedit) - { - $result = $object->valid($user); - if ($result >= 0) - { - // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - $outputlangs = $langs; - $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; - if (! empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - $model=$object->modelpdf; - $ret = $object->fetch($id); // Reload to get new records - - $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); - } - } - else - { - setEventMessages($object->error, $object->errors, 'errors'); - } - } - - if ($action == 'confirm_close' && $confirm == 'yes' && $permissionedit) - { - $result = $object->cancel($user); - if ($result >= 0) - { - // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - $outputlangs = $langs; - $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; - if (! empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - $model=$object->modelpdf; - $ret = $object->fetch($id); // Reload to get new records - - $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); - } - } - else - { - setEventMessages($object->error, $object->errors, 'errors'); - } - } - - if ($action == 'confirm_reopen' && $confirm == 'yes' && $permissionedit) - { - $result = $object->reopen($user); - if ($result >= 0) - { - // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - $outputlangs = $langs; - $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; - if (! empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - $model=$object->modelpdf; - $ret = $object->fetch($id); // Reload to get new records - - $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); - } - } - else - { - setEventMessages($object->error, $object->errors, 'errors'); - } - } } diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php index 3968c6d2813..284191d0672 100644 --- a/htdocs/bom/class/bom.class.php +++ b/htdocs/bom/class/bom.class.php @@ -513,7 +513,7 @@ class BOM extends CommonObject * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <=0 if OK, 0=Nothing done, >0 if KO */ - public function valid($user, $notrigger = 0) + public function validate($user, $notrigger = 0) { global $conf, $langs; @@ -553,7 +553,7 @@ class BOM extends CommonObject $this->newref = $num; // Validate - $sql = "UPDATE ".MAIN_DB_PREFIX."bom_bom"; + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; $sql.= " SET ref = '".$this->db->escape($num)."',"; $sql.= " status = ".self::STATUS_VALIDATED.","; $sql.= " date_valid='".$this->db->idate($now)."',"; @@ -683,7 +683,7 @@ class BOM extends CommonObject return -1; }*/ - return $this->setStatusCommon($user, self::STATUS_CANCELED, 'BOM_CLOSE'); + return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'BOM_CLOSE'); } /** @@ -708,9 +708,10 @@ class BOM extends CommonObject return -1; }*/ - return $this->setStatusCommon($user, self::STATUS_VALIDATED, 'BOM_REOPEN'); + return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'BOM_REOPEN'); } + /** * Return a link to the object card (with optionaly the picto) * diff --git a/htdocs/core/actions_addupdatedelete.inc.php b/htdocs/core/actions_addupdatedelete.inc.php index 66428eea974..abe80b5a832 100644 --- a/htdocs/core/actions_addupdatedelete.inc.php +++ b/htdocs/core/actions_addupdatedelete.inc.php @@ -18,7 +18,7 @@ /** * \file htdocs/core/actions_addupdatedelete.inc.php - * \brief Code for common actions cancel / add / update / delete / clone + * \brief Code for common actions cancel / add / update / update_extras / delete / deleteline / validate / cancel / reopen / clone */ @@ -231,6 +231,92 @@ if ($action == 'confirm_deleteline' && $confirm == 'yes' && ! empty($permissiont } } +// Action validate object +if ($action == 'confirm_validate' && $confirm == 'yes' && $permissionedit) +{ + $result = $object->valid($user); + if ($result >= 0) + { + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (! empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model=$object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } +} + +// Action close object +if ($action == 'confirm_close' && $confirm == 'yes' && $permissionedit) +{ + $result = $object->cancel($user); + if ($result >= 0) + { + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (! empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model=$object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } +} + +// Action reopen object +if ($action == 'confirm_reopen' && $confirm == 'yes' && $permissionedit) +{ + $result = $object->reopen($user); + if ($result >= 0) + { + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (! empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model=$object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } +} // Action clone object if ($action == 'confirm_clone' && $confirm == 'yes' && ! empty($permissiontoadd)) diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index 371c4498da8..5c17723e4dd 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -489,6 +489,82 @@ class MyObject extends CommonObject return $this->deleteLineCommon($user, $idline, $notrigger); } + + /** + * Set draft status + * + * @param User $user Object user that modify + * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers + * @return int <0 if KO, >0 if OK + */ + public function setDraft($user, $notrigger = 0) + { + // Protection + if ($this->status <= self::STATUS_DRAFT) + { + return 0; + } + + /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->mymodule->write)) + || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->mymodule->mymodule_advance->validate)))) + { + $this->error='Permission denied'; + return -1; + }*/ + + return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'BOM_UNVALIDATE'); + } + + /** + * Set cancel status + * + * @param User $user Object user that modify + * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers + * @return int <0 if KO, 0=Nothing done, >0 if OK + */ + public function cancel($user, $notrigger = 0) + { + // Protection + if ($this->status != self::STATUS_VALIDATED) + { + return 0; + } + + /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->mymodule->write)) + || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->mymodule->mymodule_advance->validate)))) + { + $this->error='Permission denied'; + return -1; + }*/ + + return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'BOM_CLOSE'); + } + + /** + * Set back to validated status + * + * @param User $user Object user that modify + * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers + * @return int <0 if KO, 0=Nothing done, >0 if OK + */ + public function reopen($user, $notrigger = 0) + { + // Protection + if ($this->status != self::STATUS_CANCELED) + { + return 0; + } + + /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->mymodule->write)) + || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->mymodule->mymodule_advance->validate)))) + { + $this->error='Permission denied'; + return -1; + }*/ + + return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'BOM_REOPEN'); + } + /** * Return a link to the object card (with optionaly the picto) *