diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index e7533d0055d..7bd1544fe14 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -2221,6 +2221,24 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G } } + // Create intervention + if ($conf->ficheinter->enabled) + { + $langs->load("interventions"); + + if ($object->statut > 0 && $object->statut < 3 && $object->getNbOfServicesLines() > 0) + { + if ($user->rights->ficheinter->creer) + { + print ''.$langs->trans('AddIntervention').''; + } + else + { + print ''.$langs->trans('AddIntervention').''; + } + } + } + // Reopen a closed order if ($object->statut == 3) { diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index 3ebee6ed04a..86b7a8a067d 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -156,6 +156,14 @@ class Fichinter extends CommonObject if ($result) { $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."fichinter"); + + // Add linked object + if (! $error && $this->origin && $this->origin_id) + { + $ret = $this->add_object_linked(); + if (! $ret) dol_print_error($this->db); + } + $this->db->commit(); // Appel des triggers diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php index d0b09b22279..e821bc3ab91 100644 --- a/htdocs/fichinter/fiche.php +++ b/htdocs/fichinter/fiche.php @@ -141,16 +141,144 @@ else if ($action == 'add' && $user->rights->ficheinter->creer) if ($object->socid > 0) { - $result = $object->create(); - if ($result > 0) - { - $id=$result; // Force raffraichissement sur fiche venant d'etre cree - } - else - { - $langs->load("errors"); - $mesg='
'.$langs->trans($object->error).'
'; - $action = 'create'; + // If creation from another object of another module (Example: origin=propal, originid=1) + if ($_POST['origin'] && $_POST['originid']) + { + // Parse element/subelement (ex: project_task) + $element = $subelement = $_POST['origin']; + if (preg_match('/^([^_]+)_([^_]+)/i',$_POST['origin'],$regs)) + { + $element = $regs[1]; + $subelement = $regs[2]; + } + + // For compatibility + if ($element == 'order') { $element = $subelement = 'commande'; } + if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; } + if ($element == 'contract') { $element = $subelement = 'contrat'; } + + $object->origin = $_POST['origin']; + $object->origin_id = $_POST['originid']; + + // Possibility to add external linked objects with hooks + $object->linked_objects[$object->origin] = $object->origin_id; + if (is_array($_POST['other_linked_objects']) && ! empty($_POST['other_linked_objects'])) + { + $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']); + } + + $object_id = $object->create($user); + + if ($object_id > 0) + { + dol_include_once('/'.$element.'/class/'.$subelement.'.class.php'); + + $classname = ucfirst($subelement); + $srcobject = new $classname($db); + + dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines"); + $result=$srcobject->fetch($object->origin_id); + if ($result > 0) + { + $srcobject->fetch_thirdparty(); + $lines = $srcobject->lines; + if (empty($lines) && method_exists($srcobject,'fetch_lines')) $lines = $srcobject->fetch_lines(); + + $fk_parent_line=0; + $num=count($lines); + + for ($i=0;$i<$num;$i++) + { + $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0); + + if ($product_type == 1) { //only services + // service prédéfini + if ($lines[$i]->fk_product > 0) + { + $product_static = new Product($db); + + // Define output language + if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) + { + $prod = new Product($db, $lines[$i]->fk_product); + + $outputlangs = $langs; + $newlang=''; + if (empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id'); + if (empty($newlang)) $newlang=$srcobject->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + + $label = (! empty($prod->multilangs[$outputlangs->defaultlang]["libelle"])) ? $prod->multilangs[$outputlangs->defaultlang]["libelle"] : $lines[$i]->product_label; + } + else + { + $label = $lines[$i]->product_label; + } + + $product_static->type=$lines[$i]->fk_product_type; + $product_static->id=$lines[$i]->fk_product; + $product_static->ref=$lines[$i]->ref; + $product_static->libelle=$label; + $desc=$product_static->getNomUrl(0); + $desc.= ' - '.$label; + $desc .= ' ('.$langs->trans('Quantity').': '.$lines[$i]->qty.')'; + if ($conf->global->PRODUIT_DESC_IN_FORM) + $desc .= ($lines[$i]->desc && $lines[$i]->desc!=$lines[$i]->libelle)?'
'.dol_htmlentitiesbr($lines[$i]->desc):''; + } + else { + $desc = dol_htmlentitiesbr($lines[$i]->desc); + $desc .= ' ('.$langs->trans('Quantity').': '.$lines[$i]->qty.')'; + } + $timearray=dol_getdate(mktime()); + $date_intervention=dol_mktime(0,0,0,$timearray['mon'],$timearray['mday'],$timearray['year']); + $duration = 3600; + + $result = $object->addline( + $object_id, + $desc, + $date_intervention, + $duration + ); + + if ($result < 0) + { + $error++; + break; + } + + } + } + + } + else + { + $mesg=$srcobject->error; + $error++; + } + } + else + { + $mesg=$object->error; + $error++; + } + } + else + { + $result = $object->create(); + if ($result > 0) + { + $id=$result; // Force raffraichissement sur fiche venant d'etre cree + } + else + { + $langs->load("errors"); + $mesg='
'.$langs->trans($object->error).'
'; + $action = 'create'; + } } } else @@ -732,6 +860,54 @@ if ($action == 'create') dol_htmloutput_mesg($mesg); + if ($socid) $res=$soc->fetch($socid); + + if (GETPOST('origin') && GETPOST('originid')) + { + // Parse element/subelement (ex: project_task) + $element = $subelement = GETPOST('origin'); + if (preg_match('/^([^_]+)_([^_]+)/i',GETPOST('origin'),$regs)) + { + $element = $regs[1]; + $subelement = $regs[2]; + } + + if ($element == 'project') + { + $projectid=GETPOST('originid'); + } + else + { + // For compatibility + if ($element == 'order' || $element == 'commande') { $element = $subelement = 'commande'; } + if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; } + if ($element == 'contract') { $element = $subelement = 'contrat'; } + + dol_include_once('/'.$element.'/class/'.$subelement.'.class.php'); + + $classname = ucfirst($subelement); + $objectsrc = new $classname($db); + $objectsrc->fetch(GETPOST('originid')); + if (empty($objectsrc->lines) && method_exists($objectsrc,'fetch_lines')) $objectsrc->fetch_lines(); + $objectsrc->fetch_thirdparty(); + + $projectid = (!empty($objectsrc->fk_project)?$objectsrc->fk_project:''); + + $soc = $objectsrc->client; + + $note_private = (! empty($objectsrc->note) ? $objectsrc->note : (! empty($objectsrc->note_private) ? $objectsrc->note_private : '')); + $note_public = (! empty($objectsrc->note_public) ? $objectsrc->note_public : ''); + + // Object source contacts list + $srccontactslist = $objectsrc->liste_contact(-1,'external',1); + } + } + else { + $projectid = GETPOST('projectid','int'); + $note_private = ''; + $note_public = ''; + } + if (! $conf->global->FICHEINTER_ADDON) { dol_print_error($db,$langs->trans("Error")." ".$langs->trans("Error_FICHEINTER_ADDON_NotDefined")); @@ -802,7 +978,7 @@ if ($action == 'create') print ''; print ''.$langs->trans('NotePublic').''; print ''; - print ''; + print ''; print ''; // Private note @@ -811,7 +987,7 @@ if ($action == 'create') print ''; print ''.$langs->trans('NotePrivate').''; print ''; - print ''; + print ''; print ''; } @@ -821,6 +997,12 @@ if ($action == 'create') print ''; + if (is_object($objectsrc)) + { + print ''; + print ''; + } + print '

'; print ''; print '
';