From ab7c300f4396f366de3aff5fc7d0977ab53663ec Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 2 Nov 2019 20:50:25 +0100 Subject: [PATCH] NEW Can change supplier when cloning a Purchase Order --- htdocs/commande/card.php | 8 ++---- .../class/fournisseur.commande.class.php | 26 +++++++++++++++++-- htdocs/fourn/commande/card.php | 7 +++-- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 7fd0d7326c4..1b7636c70f9 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -2057,12 +2057,8 @@ if ($action == 'create' && $usercancreate) if ($action == 'clone') { // Create an array for form $formquestion = array( - // 'text' => $langs->trans("ConfirmClone"), - // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => - // 1), - // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' - // => 1), - array('type' => 'other','name' => 'socid','label' => $langs->trans("SelectThirdParty"),'value' => $form->select_company(GETPOST('socid', 'int'), 'socid', '(s.client=1 OR s.client=3)'))); + array('type' => 'other','name' => 'socid','label' => $langs->trans("SelectThirdParty"),'value' => $form->select_company(GETPOST('socid', 'int'), 'socid', '(s.client=1 OR s.client=3)')) + ); $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneOrder', $object->ref), 'confirm_clone', $formquestion, 'yes', 1); } diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 96d56d98fdf..ab5f2204c83 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -1393,19 +1393,41 @@ class CommandeFournisseur extends CommonOrder * Load an object from its id and create a new one in database * * @param User $user User making the clone + * @param int $socid Id of thirdparty * @return int New id of clone */ - public function createFromClone(User $user) + public function createFromClone(User $user, $socid = 0) { - global $hookmanager; + global $conf, $user,$hookmanager; $error=0; $this->db->begin(); + // get lines so they will be clone + foreach($this->lines as $line) + $line->fetch_optionals(); + // Load source object $objFrom = clone $this; + // Change socid if needed + if (! empty($socid) && $socid != $this->socid) + { + $objsoc = new Societe($this->db); + + if ($objsoc->fetch($socid)>0) + { + $this->socid = $objsoc->id; + $this->cond_reglement_id = (! empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0); + $this->mode_reglement_id = (! empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0); + $this->fk_project = 0; + $this->fk_delivery_address = 0; + } + + // TODO Change product price if multi-prices + } + $this->id=0; $this->statut=self::STATUS_DRAFT; diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index 2475b251f56..af9dbac8c0b 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -963,7 +963,9 @@ if (empty($reshook)) { if ($object->id > 0) { - $result=$object->createFromClone($user); + $orig = clone $object; + + $result=$object->createFromClone($user, $socid); if ($result > 0) { header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result); @@ -972,6 +974,7 @@ if (empty($reshook)) else { setEventMessages($object->error, $object->errors, 'errors'); + $object = $orig; $action=''; } } @@ -1789,7 +1792,7 @@ elseif (! empty($object->id)) { // Create an array for form $formquestion=array( - //array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1) + array('type' => 'other','name' => 'socid','label' => $langs->trans("SelectThirdParty"),'value' => $form->select_company(GETPOST('socid', 'int'), 'socid', '(s.fournisseur=1)')) ); // Paiement incomplet. On demande si motif = escompte ou autre $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneOrder', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);