NEW Can change supplier when cloning a Purchase Order

This commit is contained in:
Laurent Destailleur 2019-11-02 20:50:25 +01:00
parent 2ee002fc80
commit ab7c300f43
3 changed files with 31 additions and 10 deletions

View File

@ -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);
}

View File

@ -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;

View File

@ -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);