/** * Load an object from its id and create a new one in database * @param fromid Id of object to clone * @param invertdetail Reverse sign of amounts for lines * @param socid Id of thirdparty * @return int New id of clone */ function createFromClone($fromid, $invertdetail = 0, $socid = 0) { global $user, $langs, $conf; $error = 0; $now = dol_now(); $object = new Propal($this->db); // Instantiate hooks of thirdparty module if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules)) { $object->callHooks('propalcard'); } $this->db->begin(); // Load source object $object->fetch($fromid); $objFrom = $object; $objsoc = new Societe($this->db); // Change socid if needed if (!empty($socid) && $socid != $object->socid) { if ($objsoc->fetch($socid) > 0) { $object->socid = $objsoc->id; $object->cond_reglement_id = !empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0; $object->mode_reglement_id = !empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0; $object->fk_project = ''; $object->fk_delivery_address = ''; } // TODO Change product price if multi-prices } else { $objsoc->fetch($object->socid); } $object->id = 0; $object->statut = 0; $objsoc->fetch($object->socid); if (empty($conf->global->PROPALE_ADDON) || !is_readable(DOL_DOCUMENT_ROOT . "/includes/modules/propale/" . $conf->global->PROPALE_ADDON . ".php")) { $this->error = 'ErrorSetupNotComplete'; return -1; } // Clear fields $object->user_author = $user->id; $object->user_valid = ''; $object->date = ''; $object->datep = $now; $object->fin_validite = $object->datep + $this->duree_validite * 24 * 3600; $object->ref_client = ''; // Set ref require_once DOL_DOCUMENT_ROOT . "/includes/modules/propale/" . $conf->global->PROPALE_ADDON . ".php"; $obj = $conf->global->PROPALE_ADDON; $modPropale = new $obj(); $object->ref = $modPropale->getNextValue($objsoc, $object); // Create clone $result = $object->create($user); // Other options if ($result < 0) { $this->error = $object->error; $error++; } if (!$error) { // Hook for external modules if (!empty($object->hooks)) { foreach ($object->hooks as $hook) { if (!empty($hook['modules'])) { foreach ($hook['modules'] as $module) { if (method_exists($module, 'createfrom')) { $result = $module->createfrom($objFrom, $result, $object->element); if ($result < 0) { $error++; } } } } } } // Appel des triggers include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"; $interface = new Interfaces($this->db); $result = $interface->run_triggers('PROPAL_CLONE', $object, $user, $langs, $conf); if ($result < 0) { $error++; $this->errors = $interface->errors; } // Fin appel triggers } // End if (!$error) { $this->db->commit(); return $object->id; } else { $this->db->rollback(); return -1; } }
$module='societe'; $dbtable=''; } else if (isset($id) && $id > 0) { $objectid=$id; $module='propale'; $dbtable='propal'; } if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, $module, $objectid, $dbtable); // Instantiate hooks of thirdparty module if (is_array($conf->hooks_modules) && ! empty($conf->hooks_modules)) { $object->callHooks('propalcard'); } /******************************************************************************/ /* Actions */ /******************************************************************************/ // Hook of actions if (! empty($object->hooks)) { foreach($object->hooks as $hook) { if (! empty($hook['modules'])) { foreach($hook['modules'] as $module)