diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index d8eaef777ad..d1ef8b0f17a 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -993,6 +993,69 @@ class CommandeFournisseur extends CommonOrder } } + /** + * Load an object from its id and create a new one in database + * + * @param HookManager $hookmanager Hook manager instance + * @return int New id of clone + */ + function createFromClone($hookmanager=false) + { + global $conf,$user,$langs; + + $error=0; + + $this->db->begin(); + + // Load source object + $objFrom = dol_clone($this); + + $this->id=0; + $this->statut=0; + + // Clear fields + $this->user_author_id = $user->id; + $this->user_valid = ''; + $this->date_creation = ''; + $this->date_validation = ''; + $this->ref_supplier = ''; + + // Create clone + $result=$this->create($user); + if ($result < 0) $error++; + + if (! $error) + { + // Hook of thirdparty module + if (is_object($hookmanager)) + { + $parameters=array('objFrom'=>$objFrom); + $action=''; + $reshook=$hookmanager->executeHooks('createFrom',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + if ($reshook < 0) $error++; + } + + // Appel des triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('ORDER_SUPPLIER_CLONE',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + } + + // End + if (! $error) + { + $this->db->commit(); + return $this->id; + } + else + { + $this->db->rollback(); + return -1; + } + } + /** * Add order line * diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index c57d9e12bfc..1bdc263c05f 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -78,13 +78,18 @@ $errors=array(); $object = new CommandeFournisseur($db); +// Load object +if ($id > 0 || ! empty($ref)) +{ + $object->fetch($id, $ref); + $object->fetch_thirdparty(); +} /* * Actions */ if ($action == 'setref_supplier' && $user->rights->fournisseur->commande->creer) { - $object->fetch($id); $result=$object->setValueFrom('ref_supplier',GETPOST('ref_supplier','alpha')); if ($result < 0) dol_print_error($db, $object->error); } @@ -92,14 +97,12 @@ if ($action == 'setref_supplier' && $user->rights->fournisseur->commande->creer) // conditions de reglement if ($action == 'setconditions' && $user->rights->fournisseur->commande->creer) { - $object->fetch($id); $result=$object->setPaymentTerms(GETPOST('cond_reglement_id','int')); } // mode de reglement else if ($action == 'setmode' && $user->rights->fournisseur->commande->creer) { - $object->fetch($id); $result = $object->setPaymentMethods(GETPOST('mode_reglement_id','int')); } @@ -119,13 +122,11 @@ if ($action == 'setdate_livraison' && $user->rights->fournisseur->commande->cree // Set project else if ($action == 'classin' && $user->rights->fournisseur->commande->creer) { - $object->fetch($id); $object->setProject($projectid); } else if ($action == 'setremisepercent' && $user->rights->fournisseur->commande->creer) { - $object->fetch($id); $result = $object->set_remise($user, $_POST['remise_percent']); } @@ -381,7 +382,6 @@ else if ($action == 'updateligne' && $user->rights->fournisseur->commande->creer else if ($action == 'confirm_deleteproductline' && $confirm == 'yes' && $user->rights->fournisseur->commande->creer) { - $object->fetch($id); $result = $object->deleteline(GETPOST('lineid')); if ($result >= 0) @@ -413,7 +413,6 @@ else if ($action == 'confirm_deleteproductline' && $confirm == 'yes' && $user->r else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->fournisseur->commande->valider) { - $object->fetch($id); $object->fetch_thirdparty(); $object->date_commande=dol_now(); @@ -448,7 +447,6 @@ else if ($action == 'confirm_approve' && $confirm == 'yes' && $user->rights->fou { $idwarehouse=GETPOST('idwarehouse', 'int'); - $object->fetch($id); $object->fetch_thirdparty(); // Check parameters @@ -479,7 +477,6 @@ else if ($action == 'confirm_approve' && $confirm == 'yes' && $user->rights->fou else if ($action == 'confirm_refuse' && $confirm == 'yes' && $user->rights->fournisseur->commande->approuver) { - $object->fetch($id); $result = $object->refuse($user); if ($result > 0) { @@ -494,7 +491,6 @@ else if ($action == 'confirm_refuse' && $confirm == 'yes' && $user->rights->four else if ($action == 'confirm_commande' && $confirm == 'yes' && $user->rights->fournisseur->commande->commander) { - $object->fetch($id); $result = $object->commande($user, $_REQUEST["datecommande"], $_REQUEST["methode"], $_REQUEST['comment']); if ($result > 0) { @@ -510,7 +506,6 @@ else if ($action == 'confirm_commande' && $confirm == 'yes' && $user->rights->fo else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisseur->commande->supprimer) { - $object->fetch($id); $object->fetch_thirdparty(); $result=$object->delete($user); if ($result > 0) @@ -524,10 +519,35 @@ else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->four } } +// Action clone object +else if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->fournisseur->commande->creer) +{ + if (1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers')) + { + $mesg='