示例#1
0
 /**
  *		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 $conf, $user, $langs;
     $error = 0;
     $object = new Commande($this->db);
     // Instantiate hooks of thirdparty module
     if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules)) {
         $object->callHooks('ordercard');
     }
     $this->db->begin();
     // Load source object
     $object->fetch($fromid);
     $objFrom = $object;
     // Change socid if needed
     if (!empty($socid) && $socid != $object->socid) {
         $objsoc = new Societe($this->db);
         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
     }
     $object->id = 0;
     $object->statut = 0;
     // Clear fields
     $object->user_author_id = $user->id;
     $object->user_valid = '';
     $object->date_creation = '';
     $object->date_validation = '';
     $object->ref_client = '';
     // Create clone
     $result = $object->create($user);
     // Other options
     if ($result < 0) {
         $this->error = $object->error;
         $error++;
     }
     if (!$error) {
         // Hook of thirdparty module
         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('ORDER_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;
     }
 }
示例#2
0
$id = GETPOST("id") ? GETPOST("id") : GETPOST("orderid");
$ref = GETPOST('ref');
$socid = GETPOST('socid');
$action = GETPOST('action');
$confirm = GETPOST('confirm');
$lineid = GETPOST('lineid');
$mesg = GETPOST('mesg');
$object = new Commande($db);
// Security check
if ($user->societe_id) {
    $socid = $user->societe_id;
}
$result = restrictedArea($user, 'commande', $id, '');
// Instantiate hooks of thirdparty module
if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules)) {
    $object->callHooks('ordercard');
}
/******************************************************************************/
/*                     Actions                                                */
/******************************************************************************/
// Hook of actions
if (!empty($object->hooks)) {
    foreach ($object->hooks as $hook) {
        if (!empty($hook['modules'])) {
            foreach ($hook['modules'] as $module) {
                if (method_exists($module, 'doActions')) {
                    $reshook += $module->doActions($object);
                    if (!empty($module->error) || !empty($module->errors) && sizeof($module->errors) > 0) {
                        $mesg = $module->error;
                        $mesgs = $module->errors;
                        if ($action == 'add') {