Merge pull request #494 from atm-maxime/mko608

Task # 608 : add clone function on supplier order
This commit is contained in:
Laurent Destailleur 2012-11-27 11:07:03 -08:00
commit 53d997f59b
3 changed files with 175 additions and 46 deletions

View File

@ -953,35 +953,68 @@ class CommandeFournisseur extends CommonOrder
if ($this->db->query($sql))
{
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."commande_fournisseur");
if ($this->id) {
$num=count($this->lines);
$sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur";
$sql.= " SET ref='(PROV".$this->id.")'";
$sql.= " WHERE rowid=".$this->id;
dol_syslog(get_class($this)."::create sql=".$sql);
if ($this->db->query($sql))
{
// On logue creation pour historique
$this->log($user, 0, time());
/*
* Insertion du detail des produits dans la base
*/
for ($i=0;$i<$num;$i++)
{
$result = $this->addline(
$this->lines[$i]->desc,
$this->lines[$i]->subprice,
$this->lines[$i]->qty,
$this->lines[$i]->tva_tx,
$this->lines[$i]->localtax1_tx,
$this->lines[$i]->localtax2_tx,
$this->lines[$i]->fk_product,
0,
$this->lines[$i]->ref_fourn,
$this->lines[$i]->remise_percent,
'HT',
0,
$this->lines[$i]->info_bits
);
if ($result < 0)
{
$this->error=$this->db->lasterror();
dol_print_error($this->db);
$this->db->rollback();
return -1;
}
}
if (! $notrigger)
{
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('ORDER_SUPPLIER_CREATE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
}
$this->db->commit();
return $this->id;
}
else
{
$this->error=$this->db->error();
dol_syslog(get_class($this)."::create: Failed -2 - ".$this->error, LOG_ERR);
$this->db->rollback();
return -2;
$sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur";
$sql.= " SET ref='(PROV".$this->id.")'";
$sql.= " WHERE rowid=".$this->id;
dol_syslog(get_class($this)."::create sql=".$sql);
if ($this->db->query($sql))
{
// On logue creation pour historique
$this->log($user, 0, time());
if (! $notrigger)
{
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('ORDER_SUPPLIER_CREATE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
}
$this->db->commit();
return $this->id;
}
else
{
$this->error=$this->db->error();
dol_syslog(get_class($this)."::create: Failed -2 - ".$this->error, LOG_ERR);
$this->db->rollback();
return -2;
}
}
}
else
@ -993,6 +1026,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
*
@ -1044,7 +1140,6 @@ class CommandeFournisseur extends CommonOrder
}
$desc=trim($desc);
// Check parameters
if ($qty < 1 && ! $fk_product)
{
@ -1053,7 +1148,6 @@ class CommandeFournisseur extends CommonOrder
}
if ($type < 0) return -1;
if ($this->statut == 0)
{
$this->db->begin();

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
*/
@ -1655,6 +1684,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)

View File

@ -122,7 +122,7 @@ if ($resql)
print_barre_liste($title, $page, "liste.php", "", $sortfield, $sortorder, '', $num);
print '<form action="liste.php" method="GET">';
print '<table class="liste">';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"cf.ref","","",'',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","",'',$sortfield,$sortorder);