mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
NEW functionality : Clone company (#29755)
* New functionality for clone company * New functionality for clone company + * Fix pre-commit
This commit is contained in:
parent
e1200132f1
commit
c15e2f888f
|
|
@ -461,3 +461,5 @@ ExternalSystemID=External system ID
|
|||
IDOfPaymentInAnExternalSystem=ID of the payment mode into an external system (like Stripe, Paypal, ...)
|
||||
AADEWebserviceCredentials=AADE Webservice Credentials
|
||||
ThirdPartyMustBeACustomerToCreateBANOnStripe=The third-party must be a customer to allow the creation of its bank info on Stripe side
|
||||
NewSocNameForClone=New company name
|
||||
ConfirmCloneThirdparties=Are you sure that you want to clone <b>%s</b> company ?
|
||||
|
|
@ -839,6 +839,63 @@ if (empty($reshook)) {
|
|||
$result = $object->setWarehouse(GETPOSTINT('fk_warehouse'));
|
||||
}
|
||||
|
||||
if ($action == 'confirm_clone' && $confirm != 'yes') {
|
||||
$action = '';
|
||||
}
|
||||
//clone company essential info
|
||||
if ($action == 'confirm_clone' && $confirm == 'yes' && $user->hasRight('societe', 'creer')) {
|
||||
if ($object->id > 0) {
|
||||
$error = 0;
|
||||
|
||||
$clone = dol_clone($object, 1);
|
||||
|
||||
if (!empty(GETPOST('clone_name'))) {
|
||||
$clone->id = 0;
|
||||
$clone->name = GETPOST('clone_name', 'alphanohtml');
|
||||
$clone->status = 1;
|
||||
$clone->fournisseur = 0;
|
||||
$clone->client = 0;
|
||||
|
||||
|
||||
$db->begin();
|
||||
|
||||
$clone->context['createfromclone'] = 'createfromclone';
|
||||
$id = $clone->create($user);
|
||||
if ($id > 0) {
|
||||
$clone->id = $id;
|
||||
} else {
|
||||
if ($clone->error == 'ErrorProductAlreadyExists') {
|
||||
$refalreadyexists++;
|
||||
$action = "";
|
||||
|
||||
$mesg = $langs->trans("ErrorProductAlreadyExists", $clone->ref);
|
||||
$mesg .= ' <a href="' . $_SERVER["PHP_SELF"] . '?ref=' . $clone->ref . '">' . $langs->trans("ShowCardHere") . '</a>.';
|
||||
setEventMessages($mesg, null, 'errors');
|
||||
} else {
|
||||
setEventMessages(empty($clone->error) ? '' : $langs->trans($clone->error), $clone->errors, 'errors');
|
||||
}
|
||||
$error++;
|
||||
}
|
||||
|
||||
unset($clone->context['createfromclone']);
|
||||
|
||||
if ($error) {
|
||||
$db->rollback();
|
||||
} else {
|
||||
$db->commit();
|
||||
$db->close();
|
||||
header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NewRefForClone")), null, 'errors');
|
||||
}
|
||||
} else {
|
||||
dol_print_error($db, $object->error, $object->errors);
|
||||
}
|
||||
$action = 'clone';
|
||||
}
|
||||
|
||||
$id = $socid;
|
||||
$object->fetch($socid);
|
||||
|
||||
|
|
@ -2722,6 +2779,17 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($canvasdisplayactio
|
|||
$formconfirm .= $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("MergeThirdparties"), $langs->trans("ConfirmMergeThirdparties"), "confirm_merge", $formquestion, 'no', 1, 250);
|
||||
}
|
||||
|
||||
// Clone confirmation
|
||||
if (($action == 'clone' && (empty($conf->use_javascript_ajax) || !empty($conf->dol_use_jmobile))) // Output when action = clone if jmobile or no js
|
||||
|| (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))) { // Always output when not jmobile nor js
|
||||
// Define confirmation messages
|
||||
$formquestionclone = array(
|
||||
'text' => $langs->trans("ConfirmClone"),
|
||||
0 => array('type' => 'text', 'name' => 'clone_name', 'label' => $langs->trans("NewSocNameForClone"), 'value' => empty($tmpcode) ? $langs->trans("CopyOf").' '.$object->nom : $tmpcode, 'morecss' => 'width250'),
|
||||
);
|
||||
$formconfirm .= $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneThirdparties', $object->name), 'confirm_clone', $formquestionclone, 'yes', 'action-clone', 350, 600);
|
||||
}
|
||||
|
||||
// Call Hook formConfirm
|
||||
$parameters = array('formConfirm' => $formconfirm);
|
||||
$reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
||||
|
|
@ -3237,6 +3305,14 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($canvasdisplayactio
|
|||
|
||||
print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=edit&token='.newToken(), '', $permissiontoadd);
|
||||
|
||||
if (!isset($object->no_button_copy) || $object->no_button_copy != 1) {
|
||||
if (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile)) {
|
||||
$cloneSocietetUrl = '';
|
||||
$cloneButtonId = 'action-clone';
|
||||
}
|
||||
print dolGetButtonAction($langs->trans('ToClone'), '', 'default', $cloneSocietetUrl, $cloneButtonId, $user->hasRight('societe', 'creer'));
|
||||
}
|
||||
|
||||
if (isModEnabled('member')) {
|
||||
$adh = new Adherent($db);
|
||||
$result = $adh->fetch('', '', $object->id);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user