diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index a3fb1c4d3e2..b18bcac8aca 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -113,9 +113,16 @@ class Commande extends CommonOrder /** * Status of the order * @var int + * @deprecated Use status */ public $statut; + /** + * Status of the order + * @var int + */ + public $status; + /** * @var int Status Billed or not */ @@ -792,12 +799,10 @@ class Commande extends CommonOrder * * @param User $user Object user that close * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers - * @return int Return integer <0 if KO, >0 if OK + * @return int Return integer <0 if KO, 0=Nothing done, >0 if OK */ public function cloture($user, $notrigger = 0) { - global $conf; - $error = 0; $usercanclose = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('commande', 'creer')) @@ -1890,7 +1895,7 @@ class Commande extends CommonOrder return -1; } - $sql = 'SELECT c.rowid, c.entity, c.date_creation, c.ref, c.fk_soc, c.fk_user_author, c.fk_user_valid, c.fk_user_modif, c.fk_statut'; + $sql = 'SELECT c.rowid, c.entity, c.date_creation, c.ref, c.fk_soc, c.fk_user_author, c.fk_user_valid, c.fk_user_modif, c.fk_statut as status'; $sql .= ', c.amount_ht, c.total_ht, c.total_ttc, c.total_tva, c.localtax1 as total_localtax1, c.localtax2 as total_localtax2, c.fk_cond_reglement, c.deposit_percent, c.fk_mode_reglement, c.fk_availability, c.fk_input_reason'; $sql .= ', c.fk_account'; $sql .= ', c.date_commande, c.date_valid, c.tms'; @@ -1946,8 +1951,8 @@ class Commande extends CommonOrder $this->fk_project = $obj->fk_project; $this->project = null; // Clear if another value was already set by fetch_projet - $this->statut = $obj->fk_statut; - $this->status = $obj->fk_statut; + $this->statut = $obj->status; + $this->status = $obj->status; $this->user_author_id = $obj->fk_user_author; $this->user_creation_id = $obj->fk_user_author; diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index 245c4f4072f..b5d9785da63 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -766,14 +766,16 @@ if (empty($reshook)) { } } } + if ($action == 'validate' && $permissiontoadd && $objectclass !== null) { if (GETPOST('confirm') == 'yes') { + /** @var Commande $objecttmp */ $objecttmp = new $objectclass($db); $db->begin(); $error = 0; foreach ($toselect as $checked) { if ($objecttmp->fetch($checked)) { - if ($objecttmp->statut == 0) { + if ($objecttmp->status == $objecttmp::STATUS_DRAFT) { if (!empty($objecttmp->fk_warehouse)) { $idwarehouse = $objecttmp->fk_warehouse; } else { @@ -804,21 +806,23 @@ if ($action == 'validate' && $permissiontoadd && $objectclass !== null) { } if ($action == 'shipped' && $permissiontoadd && $objectclass !== null) { if (GETPOST('confirm') == 'yes') { + /** @var Commande $objecttmp */ $objecttmp = new $objectclass($db); $db->begin(); $error = 0; foreach ($toselect as $checked) { if ($objecttmp->fetch($checked)) { - if ($objecttmp->statut == 1 || $objecttmp->statut == 2) { - if ($objecttmp->cloture($user)) { + if ($objecttmp->status == $objecttmp::STATUS_VALIDATED || $objecttmp->status == $objecttmp::STATUS_SHIPMENTONPROCESS || $objecttmp->status == $objecttmp::STATUS_CLOSED) { + $result = $objecttmp->cloture($user); + if ($result > 0) { setEventMessages($langs->trans('StatusOrderDelivered', $objecttmp->ref), null, 'mesgs'); - } else { + } elseif ($result < 0) { setEventMessages($langs->trans('ErrorOrderStatusCantBeSetToDelivered'), null, 'errors'); $error++; } } else { $langs->load("errors"); - setEventMessages($langs->trans('ErrorIsNotADraft', $objecttmp->ref), null, 'errors'); + setEventMessages($langs->trans('ErrorObjectHasWrongStatus', $objecttmp->ref), null, 'errors'); $error++; } } else { diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index ed6c0f707c8..fc7a83c44e6 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -232,6 +232,7 @@ ErrorBadLinkSourceSetButBadValueForRef=The link you use is not valid. A 'source' ErrorTooManyErrorsProcessStopped=Too many errors. Process was stopped. ErrorMassValidationNotAllowedWhenStockIncreaseOnAction=Mass validation is not possible when option to increase/decrease stock is set on this action (you must validate one by one so you can define the warehouse to increase/decrease) ErrorObjectMustHaveStatusDraftToBeValidated=Object %s must have status 'Draft' to be validated. +ErrorObjectHasWrongStatus=Object %s must have another status for this operation. ErrorObjectMustHaveLinesToBeValidated=Object %s must have lines to be validated. ErrorOnlyInvoiceValidatedCanBeSentInMassAction=Only validated invoices can be sent using the "Send by email" mass action. ErrorChooseBetweenFreeEntryOrPredefinedProduct=You must choose if article is a predefined product or not