From 90bca8b4d7dd411cda5de4eb6847839fc45774b5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 10 Apr 2023 15:55:58 +0200 Subject: [PATCH] NEW Can go back to draft on shipment when stock change not on validate --- htdocs/core/class/commonobject.class.php | 2 +- htdocs/core/class/html.form.class.php | 30 ++++++++--------- htdocs/expedition/card.php | 35 ++++++++++++++------ htdocs/expedition/class/expedition.class.php | 19 ++++++++++- 4 files changed, 59 insertions(+), 27 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index e53cc85c21f..10a85c3a16f 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -9982,7 +9982,7 @@ abstract class CommonObject $this->db->begin(); $statusfield = 'status'; - if ($this->element == 'don' || $this->element == 'donation') { + if (in_array($this->element, array('don', 'donation', 'shipping'))) { $statusfield = 'fk_statut'; } diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index eea1047bc51..5484fea6663 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -5087,21 +5087,21 @@ class Form * print '});'."\n"; * print ''."\n"; * - * @param string $page Url of page to call if confirmation is OK. Can contains parameters (param 'action' and 'confirm' will be reformated) - * @param string $title Title - * @param string $question Question - * @param string $action Action - * @param array|string $formquestion An array with complementary inputs to add into forms: array(array('label'=> ,'type'=> , 'size'=>, 'morecss'=>, 'moreattr'=>'autofocus' or 'style=...')) - * 'type' can be 'text', 'password', 'checkbox', 'radio', 'date', 'datetime', 'select', 'multiselect', 'morecss', - * 'other', 'onecolumn' or 'hidden'... - * @param int|string $selectedchoice '' or 'no', or 'yes' or '1', 1, '0' or 0 - * @param int|string $useajax 0=No, 1=Yes use Ajax to show the popup, 2=Yes and also submit page with &confirm=no if choice is No, 'xxx'=Yes and preoutput confirm box with div id=dialog-confirm-xxx - * @param int|string $height Force height of box (0 = auto) - * @param int $width Force width of box ('999' or '90%'). Ignored and forced to 90% on smartphones. - * @param int $disableformtag 1=Disable form tag. Can be used if we are already inside a
section. - * @param string $labelbuttonyes Label for Yes - * @param string $labelbuttonno Label for No - * @return string HTML ajax code if a confirm ajax popup is required, Pure HTML code if it's an html form + * @param string $page Url of page to call if confirmation is OK. Can contains parameters (param 'action' and 'confirm' will be reformated) + * @param string $title Title + * @param string $question Question + * @param string $action Action + * @param array|string $formquestion An array with complementary inputs to add into forms: array(array('label'=> ,'type'=> , 'size'=>, 'morecss'=>, 'moreattr'=>'autofocus' or 'style=...')) + * 'type' can be 'text', 'password', 'checkbox', 'radio', 'date', 'datetime', 'select', 'multiselect', 'morecss', + * 'other', 'onecolumn' or 'hidden'... + * @param int|string $selectedchoice '' or 'no', or 'yes' or '1', 1, '0' or 0 + * @param int|string $useajax 0=No, 1=Yes use Ajax to show the popup, 2=Yes and also submit page with &confirm=no if choice is No, 'xxx'=Yes and preoutput confirm box with div id=dialog-confirm-xxx + * @param int|string $height Force height of box (0 = auto) + * @param int $width Force width of box ('999' or '90%'). Ignored and forced to 90% on smartphones. + * @param int $disableformtag 1=Disable form tag. Can be used if we are already inside a section. + * @param string $labelbuttonyes Label for Yes + * @param string $labelbuttonno Label for No + * @return string HTML ajax code if a confirm ajax popup is required, Pure HTML code if it's an html form */ public function formconfirm($page, $title, $question, $action, $formquestion = '', $selectedchoice = '', $useajax = 0, $height = 0, $width = 500, $disableformtag = 0, $labelbuttonyes = 'Yes', $labelbuttonno = 'No') { diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index dfa33478e66..34ed7f80f84 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -157,6 +157,14 @@ if (empty($reshook)) { $upload_dir = $conf->expedition->dir_output.'/sending'; include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; + // Back to draft + if ($action == 'setdraft' && $user->rights->expedition->creer) { + $object->fetch($id); + $result = $object->setDraft($user, 0); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + } // Reopen if ($action == 'reopen' && $user->rights->expedition->creer) { $object->fetch($id); @@ -1740,9 +1748,9 @@ if ($action == 'create') { $text = $langs->trans("ConfirmValidateSending", $numref); if (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT')) { - $text .= ' '.$langs->trans("StockMovementWillBeRecorded").'.'; + $text .= '
'.$langs->trans("StockMovementWillBeRecorded").'.'; } elseif (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) { - $text .= ' '.$langs->trans("StockMovementNotYetRecorded").'.'; + $text .= '
'.$langs->trans("StockMovementNotYetRecorded").'.'; } if (isModEnabled('notification')) { @@ -1752,7 +1760,7 @@ if ($action == 'create') { $text .= $notify->confirmMessage('SHIPPING_VALIDATE', $object->socid, $object); } - $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('ValidateSending'), $text, 'confirm_valid', '', 0, 1); + $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('ValidateSending'), $text, 'confirm_valid', '', 0, 1, 250); } // Confirm cancelation if ($action == 'cancel') { @@ -2540,13 +2548,20 @@ if ($action == 'create') { } } - // TODO add alternative status - // 0=draft, 1=validated, 2=billed, we miss a status "delivered" (only available on order) - if ($object->statut == Expedition::STATUS_CLOSED && $user->rights->expedition->creer) { - if (isModEnabled('facture') && !empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) { // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ? - print dolGetButtonAction('', $langs->trans('ClassifyUnbilled'), 'default', $_SERVER["PHP_SELF"].'?action=reopen&token='.newToken().'&id='.$object->id, ''); - } else { - print dolGetButtonAction('', $langs->trans('ReOpen'), 'default', $_SERVER["PHP_SELF"].'?action=reopen&token='.newToken().'&id='.$object->id, ''); + // 0=draft, 1=validated/delivered, 2=closed/delivered + // If WORKFLOW_BILL_ON_SHIPMENT: 0=draft, 1=validated, 2=billed (no status delivered) + if ($object->statut == Expedition::STATUS_VALIDATED && !getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT')) { + if ($user->hasRight('expedition', 'creer')) { + print dolGetButtonAction('', $langs->trans('SetToDraft'), 'default', $_SERVER["PHP_SELF"].'?action=setdraft&token='.newToken().'&id='.$object->id, ''); + } + } + if ($object->statut == Expedition::STATUS_CLOSED) { + if ($user->hasRight('expedition', 'creer')) { + if (isModEnabled('facture') && !empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) { // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ? + print dolGetButtonAction('', $langs->trans('ClassifyUnbilled'), 'default', $_SERVER["PHP_SELF"].'?action=reopen&token='.newToken().'&id='.$object->id, ''); + } else { + print dolGetButtonAction('', $langs->trans('ReOpen'), 'default', $_SERVER["PHP_SELF"].'?action=reopen&token='.newToken().'&id='.$object->id, ''); + } } } diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 4eb81a980bb..c3ddf973049 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -2318,6 +2318,23 @@ class Expedition extends CommonObject } } + /** + * 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->statut <= self::STATUS_DRAFT) { + return 0; + } + + return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'SHIPMENT_UNVALIDATE'); + } + /** * Classify the shipping as validated/opened * @@ -2338,7 +2355,7 @@ class Expedition extends CommonObject $oldbilled = $this->billed; - $sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut=1'; + $sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut = 1'; $sql .= " WHERE rowid = ".((int) $this->id).' AND fk_statut > 0'; $resql = $this->db->query($sql);