New : Add clone function on supplier order + global object fetch instead of each case

This commit is contained in:
Maxime Kohlhaas 2012-11-22 23:38:35 +01:00
parent 0d6aee24f3
commit 0bb3f766f6
2 changed files with 114 additions and 16 deletions

View File

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

View File

@ -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='<div class="error">'.$langs->trans("NoCloneOptionsSpecified").'</div>';
}
else
{
if ($object->id > 0)
{
$result=$object->createFromClone($hookmanager);
if ($result > 0)
{
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
exit;
}
else
{
$mesg='<div class="error">'.$object->error.'</div>';
$action='';
}
}
}
}
// Receive
else if ($action == 'livraison' && $user->rights->fournisseur->commande->receptionner)
{
$object->fetch($id);
if ($_POST["type"])
{
@ -557,7 +577,6 @@ else if ($action == 'livraison' && $user->rights->fournisseur->commande->recepti
else if ($action == 'confirm_cancel' && $confirm == 'yes' && $user->rights->fournisseur->commande->commander)
{
$object->fetch($id);
$result = $object->cancel($user);
if ($result > 0)
{
@ -573,7 +592,6 @@ else if ($action == 'confirm_cancel' && $confirm == 'yes' && $user->rights->four
// Line ordering
else if ($action == 'up' && $user->rights->fournisseur->commande->creer)
{
$object->fetch($id);
$object->line_up($_GET['rowid']);
$outputlangs = $langs;
@ -588,7 +606,6 @@ else if ($action == 'up' && $user->rights->fournisseur->commande->creer)
}
else if ($action == 'down' && $user->rights->fournisseur->commande->creer)
{
$object->fetch($id);
$object->line_down($_GET['rowid']);
$outputlangs = $langs;
@ -607,7 +624,6 @@ else if ($action == 'builddoc' && $user->rights->fournisseur->commande->creer) /
// Build document
// Sauvegarde le dernier module choisi pour generer un document
$object->fetch($id);
$object->fetch_thirdparty();
if ($_REQUEST['model'])
@ -984,6 +1000,18 @@ if ($id > 0 || ! empty($ref))
$ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 2);
if ($ret == 'html') print '<br>';
}
// Clone confirmation
if ($action == 'clone')
{
// Create an array for form
$formquestion=array(
//array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1)
);
// Paiement incomplet. On demande si motif = escompte ou autre
$ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneOrder'),$langs->trans('ConfirmCloneOrder',$object->ref),'confirm_clone',$formquestion,'yes',1);
if ($ret == 'html') print '<br>';
}
/*
* Confirmation de la validation
@ -1037,6 +1065,7 @@ if ($id > 0 || ! empty($ref))
$ret=$form->form_confirm("fiche.php?id=$object->id",$langs->trans("DenyingThisOrder"),$langs->trans("ConfirmDenyingThisOrder",$object->ref),"confirm_refuse", '', 0, 1);
if ($ret == 'html') print '<br>';
}
/*
* Confirmation de l'annulation
*/
@ -1645,6 +1674,12 @@ if ($id > 0 || ! empty($ref))
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=cancel">'.$langs->trans("CancelOrder").'</a>';
}
}
// Clone
if ($user->rights->fournisseur->commande->creer)
{
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;socid='.$object->socid.'&amp;action=clone&amp;object=order">'.$langs->trans("ToClone").'</a>';
}
// Delete
if ($user->rights->fournisseur->commande->supprimer)