Fix where is the clone of intervention ?

This commit is contained in:
Laurent Destailleur 2016-07-01 18:12:37 +02:00
parent 0e7889a68c
commit 02e35f8c76
3 changed files with 148 additions and 1 deletions

View File

@ -111,6 +111,36 @@ if (empty($reshook))
include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
// Action clone object
if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->ficheinter->creer)
{
if (1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers'))
{
setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
}
else
{
if ($object->id > 0)
{
// Because createFromClone modifies the object, we must clone it so that we can restore it later
$orig = clone $object;
$result=$object->createFromClone($socid);
if ($result > 0)
{
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
exit;
}
else
{
setEventMessages($object->error, $object->errors, 'errors');
$object = $orig;
$action='';
}
}
}
}
if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->ficheinter->creer)
{
$result = $object->setValid($user);
@ -1094,6 +1124,20 @@ else if ($id > 0 || ! empty($ref))
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&line_id='.$lineid, $langs->trans('DeleteInterventionLine'), $langs->trans('ConfirmDeleteInterventionLine'), 'confirm_deleteline','',0,1);
}
// Clone confirmation
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', '', '', 0, 0, null, 0, 'minwidth200')));
// Paiement incomplet. On demande si motif = escompte ou autre
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('CloneIntervention'), $langs->trans('ConfirmCloneIntervention', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
}
if (!$formconfirm)
{
$parameters=array('lineid'=>$lineid);
@ -1588,6 +1632,11 @@ else if ($id > 0 || ! empty($ref))
}
}
// Clone
if ($user->rights->ficheinter->creer) {
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&amp;socid=' . $object->socid . '&amp;action=clone&amp;object=ficheinter">' . $langs->trans("ToClone") . '</a></div>';
}
// Delete
if (($object->statut == 0 && $user->rights->ficheinter->creer) || $user->rights->ficheinter->supprimer)
{

View File

@ -220,7 +220,6 @@ class Fichinter extends CommonObject
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{
$result=$this->insertExtraFields();
if ($result < 0)
{
@ -926,6 +925,103 @@ class Fichinter extends CommonObject
return -2;
}
/**
* Load an object from its id and create a new one in database
*
* @param int $socid Id of thirdparty
* @return int New id of clone
*/
function createFromClone($socid=0)
{
global $user,$hookmanager;
$error=0;
$this->context['createfromclone'] = 'createfromclone';
$this->db->begin();
// get extrafields so they will be clone
foreach($this->lines as $line)
$line->fetch_optionals($line->rowid);
// 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 = '';
$this->fk_delivery_address = '';
}
// TODO Change product price if multi-prices
}
$this->id=0;
$this->ref = '';
$this->statut=0;
// Clear fields
$this->user_author_id = $user->id;
$this->user_valid = '';
$this->date_creation = '';
$this->date_validation = '';
$this->ref_client = '';
// Create clone
$result=$this->create($user);
if ($result < 0) $error++;
if (! $error)
{
// Add lines because it is not included into create function
foreach ($this->lines as $line)
{
// TODO
}
// 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++;
}
// Call trigger
$result=$this->call_trigger('INTERVENTION_CLONE',$user);
if ($result < 0) $error++;
// End call triggers
}
unset($this->context['createfromclone']);
// End
if (! $error)
{
$this->db->commit();
return $this->id;
}
else
{
$this->db->rollback();
return -1;
}
}
/**
* Adding a line of intervention into data base
*

View File

@ -14,10 +14,12 @@ DeleteIntervention=Delete intervention
ValidateIntervention=Validate intervention
ModifyIntervention=Modify intervention
DeleteInterventionLine=Delete intervention line
CloneIntervention=Clone intervention
ConfirmDeleteIntervention=Are you sure you want to delete this intervention ?
ConfirmValidateIntervention=Are you sure you want to validate this intervention under name <b>%s</b> ?
ConfirmModifyIntervention=Are you sure you want to modify this intervention ?
ConfirmDeleteInterventionLine=Are you sure you want to delete this intervention line ?
ConfirmCloneIntervention=Are you sure you want to clone this intervention ?
NameAndSignatureOfInternalContact=Name and signature of intervening :
NameAndSignatureOfExternalContact=Name and signature of customer :
DocumentModelStandard=Standard document model for interventions