diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 81f101359f8..48e0919e7a0 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -376,32 +376,7 @@ if (empty($reshook)) $error++; } - // Now we create same links to contact than the ones found on origin object - if (! empty($conf->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN)) - { - $originforcontact = $object->origin; - $originidforcontact = $object->origin_id; - if ($originforcontact == 'shipping') // shipment and order share the same contacts. If creating from shipment we take data of order - { - $originforcontact=$srcobject->origin; - $originidforcontact=$srcobject->origin_id; - } - $sqlcontact = "SELECT code, fk_socpeople FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as ctc"; - $sqlcontact.= " WHERE element_id = ".$originidforcontact." AND ec.fk_c_type_contact = ctc.rowid AND ctc.element = '".$originforcontact."'"; - - $resqlcontact = $db->query($sqlcontact); - if ($resqlcontact) - { - while($objcontact = $db->fetch_object($resqlcontact)) - { - //print $objcontact->code.'-'.$objcontact->fk_socpeople."\n"; - $object->add_contact($objcontact->fk_socpeople, $objcontact->code); - } - } - else dol_print_error($resqlcontact); - } - - // Hooks + // Hooks $parameters = array('objFrom' => $srcobject); $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been // modified by hook diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 523efb99cae..dbb815bb663 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -879,30 +879,40 @@ class Commande extends CommonOrder $error++; } - // TODO mutualiser - if ($origin == 'propal' && $origin_id) + if (! empty($conf->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN)) { - // On recupere les differents contact interne et externe - $prop = new Propal($this->db); - $prop->fetch($origin_id); - - // We get ids of sales representatives of proposal - $this->userid = $prop->getIdcontact('internal', 'SALESREPFOLL'); - - if ($this->userid) - { - //On passe le commercial suivi propale en commercial suivi commande - $this->add_contact($this->userid[0], 'SALESREPFOLL', 'internal'); - } - - // We get ids of customer follower of proposal - $this->contactid = $prop->getIdcontact('external', 'CUSTOMER'); - - if ($this->contactid) - { - //On passe le contact client suivi propale en contact client suivi commande - $this->add_contact($this->contactid[0], 'CUSTOMER', 'external'); - } + $originforcontact = $origin; + $originidforcontact = $origin_id; + if ($originforcontact == 'shipping') // shipment and order share the same contacts. If creating from shipment we take data of order + { + require_once DOL_DOCUMENT_ROOT . '/expedition/class/expedition.class.php'; + $exp = new Expedition($db); + $exp->fetch($origin_id); + $exp->fetchObjectLinked(); + if (count($exp->linkedObjectsIds['commande']) > 0) + { + foreach ($exp->linkedObjectsIds['commande'] as $key => $value) + { + $originforcontact = 'commande'; + $originidforcontact = $value->id; + break; // We take first one + } + } + } + + $sqlcontact = "SELECT ctc.code, ctc.source, ec.fk_socpeople FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as ctc"; + $sqlcontact.= " WHERE element_id = ".$originidforcontact." AND ec.fk_c_type_contact = ctc.rowid AND ctc.element = '".$originforcontact."'"; + + $resqlcontact = $this->db->query($sqlcontact); + if ($resqlcontact) + { + while($objcontact = $this->db->fetch_object($resqlcontact)) + { + //print $objcontact->code.'-'.$objcontact->source.'-'.$objcontact->fk_socpeople."\n"; + $this->add_contact($objcontact->fk_socpeople, $objcontact->code, $objcontact->source); // May failed because of duplicate key or because code of contact type does not exists for new object + } + } + else dol_print_error($resqlcontact); } } } @@ -910,22 +920,8 @@ class Commande extends CommonOrder if (! $error) { - //$action='create'; - - // Actions on extra fields (by external module or standard code) - // TODO le hook fait double emploi avec le trigger !! - /*$hookmanager->initHooks(array('orderdao')); - $parameters=array('socid'=>$this->id); - $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks - if (empty($reshook)) - { - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used - {*/ - $result=$this->insertExtraFields(); - if ($result < 0) $error++; - /* } - } - else if ($reshook < 0) $error++;*/ + $result=$this->insertExtraFields(); + if ($result < 0) $error++; } if (! $error && ! $notrigger) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index b6e7fc463e1..68d0d1b5567 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -864,7 +864,7 @@ if (empty($reshook)) } } - // Standard invoice or Deposit invoice created from a Predefined template invoice + // Standard invoice or Deposit invoice, created from a Predefined template invoice if (($_POST['type'] == Facture::TYPE_STANDARD || $_POST['type'] == Facture::TYPE_DEPOSIT) && GETPOST('fac_rec') > 0) { $dateinvoice = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); @@ -904,6 +904,7 @@ if (empty($reshook)) $object->fac_rec = GETPOST('fac_rec'); $id = $object->create($user); + var_dump('ggg'); } } @@ -1011,8 +1012,8 @@ if (empty($reshook)) $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']); } - $id = $object->create($user); - + $id = $object->create($user); // This include class to add_object_linked() and add add_contact() + if ($id > 0) { dol_include_once('/' . $element . '/class/' . $subelement . '.class.php'); @@ -1183,32 +1184,7 @@ if (empty($reshook)) $error ++; } } - - // Now we create same links to contact than the ones found on origin object - if (! empty($conf->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN)) - { - $originforcontact = $object->origin; - $originidforcontact = $object->origin_id; - if ($originforcontact == 'shipping') // shipment and order share the same contacts. If creating from shipment we take data of order - { - $originforcontact=$srcobject->origin; - $originidforcontact=$srcobject->origin_id; - } - $sqlcontact = "SELECT code, fk_socpeople FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as ctc"; - $sqlcontact.= " WHERE element_id = ".$originidforcontact." AND ec.fk_c_type_contact = ctc.rowid AND ctc.element = '".$originforcontact."'"; - - $resqlcontact = $db->query($sqlcontact); - if ($resqlcontact) - { - while($objcontact = $db->fetch_object($resqlcontact)) - { - //print $objcontact->code.'-'.$objcontact->fk_socpeople."\n"; - $object->add_contact($objcontact->fk_socpeople, $objcontact->code); - } - } - else dol_print_error($resqlcontact); - } - + // Hooks $parameters = array('objFrom' => $srcobject); $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index c88648900cc..1cc4abce751 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -408,30 +408,40 @@ class Facture extends CommonInvoice $error++; } - // TODO mutualiser - if ($origin == 'commande') + if (! empty($conf->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN)) { - // On recupere les differents contact interne et externe - $order = new Commande($this->db); - $order->id = $origin_id; - - // On recupere le commercial suivi propale - $this->userid = $order->getIdcontact('internal', 'SALESREPFOLL'); - - if ($this->userid) - { - //On passe le commercial suivi commande en commercial suivi paiement - $this->add_contact($this->userid[0], 'SALESREPFOLL', 'internal'); - } - - // On recupere le contact client facturation commande - $this->contactid = $order->getIdcontact('external', 'BILLING'); - - if ($this->contactid) - { - //On passe le contact client facturation commande en contact client facturation - $this->add_contact($this->contactid[0], 'BILLING', 'external'); - } + $originforcontact = $origin; + $originidforcontact = $origin_id; + if ($originforcontact == 'shipping') // shipment and order share the same contacts. If creating from shipment we take data of order + { + require_once DOL_DOCUMENT_ROOT . '/expedition/class/expedition.class.php'; + $exp = new Expedition($db); + $exp->fetch($origin_id); + $exp->fetchObjectLinked(); + if (count($exp->linkedObjectsIds['commande']) > 0) + { + foreach ($exp->linkedObjectsIds['commande'] as $key => $value) + { + $originforcontact = 'commande'; + $originidforcontact = $value->id; + break; // We take first one + } + } + } + + $sqlcontact = "SELECT ctc.code, ctc.source, ec.fk_socpeople FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as ctc"; + $sqlcontact.= " WHERE element_id = ".$originidforcontact." AND ec.fk_c_type_contact = ctc.rowid AND ctc.element = '".$originforcontact."'"; + + $resqlcontact = $this->db->query($sqlcontact); + if ($resqlcontact) + { + while($objcontact = $this->db->fetch_object($resqlcontact)) + { + //print $objcontact->code.'-'.$objcontact->source.'-'.$objcontact->fk_socpeople."\n"; + $this->add_contact($objcontact->fk_socpeople, $objcontact->code, $objcontact->source); // May failed because of duplicate key or because code of contact type does not exists for new object + } + } + else dol_print_error($resqlcontact); } } } @@ -595,21 +605,22 @@ class Facture extends CommonInvoice // Actions on extra fields (by external module or standard code) // TODO le hook fait double emploi avec le trigger !! + /* $hookmanager->initHooks(array('invoicedao')); $parameters=array('invoiceid'=>$this->id); $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks if (empty($reshook)) { if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used - { - $result=$this->insertExtraFields(); - if ($result < 0) - { - $error++; - } - } + {*/ + if (! $error) + { + $result=$this->insertExtraFields(); + if ($result < 0) $error++; } - else if ($reshook < 0) $error++; + /*} + } + else if ($reshook < 0) $error++;*/ // Call trigger $result=$this->call_trigger('BILL_CREATE',$user); diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 5a9c8a267ea..0f7ffb8c72f 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -368,31 +368,6 @@ if (empty($reshook)) $error++; } - // Now we create same links to contact than the ones found on origin object - if (! empty($conf->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN)) - { - $originforcontact = $object->origin; - $originidforcontact = $object->origin_id; - if ($originforcontact == 'shipping') // shipment and order share the same contacts. If creating from shipment we take data of order - { - $originforcontact=$srcobject->origin; - $originidforcontact=$srcobject->origin_id; - } - $sqlcontact = "SELECT code, fk_socpeople FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as ctc"; - $sqlcontact.= " WHERE element_id = ".$originidforcontact." AND ec.fk_c_type_contact = ctc.rowid AND ctc.element = '".$originforcontact."'"; - - $resqlcontact = $db->query($sqlcontact); - if ($resqlcontact) - { - while($objcontact = $db->fetch_object($resqlcontact)) - { - //print $objcontact->code.'-'.$objcontact->fk_socpeople."\n"; - $object->add_contact($objcontact->fk_socpeople, $objcontact->code); - } - } - else dol_print_error($resqlcontact); - } - // Hooks $parameters = array('objFrom' => $srcobject); $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index e08d148064b..578a1888ecb 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -957,27 +957,87 @@ class Contrat extends CommonObject } } + if (! $error) + { + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + { + $result=$this->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + } + // Insert contacts commerciaux ('SALESREPSIGN','contrat') - $result=$this->add_contact($this->commercial_signature_id,'SALESREPSIGN','internal'); - if ($result < 0) $error++; + if (! $error) + { + $result=$this->add_contact($this->commercial_signature_id,'SALESREPSIGN','internal'); + if ($result < 0) $error++; + } // Insert contacts commerciaux ('SALESREPFOLL','contrat') - $result=$this->add_contact($this->commercial_suivi_id,'SALESREPFOLL','internal'); - if ($result < 0) $error++; - + if (! $error) + { + $result=$this->add_contact($this->commercial_suivi_id,'SALESREPFOLL','internal'); + if ($result < 0) $error++; + } if (! $error) { - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used - { - $result=$this->insertExtraFields(); - if ($result < 0) - { - $error++; - } - } - } + // Add object linked + if (is_array($this->linked_objects) && ! empty($this->linked_objects)) + { + foreach($this->linked_objects as $origin => $origin_id) + { + $ret = $this->add_object_linked($origin, $origin_id); + if (! $ret) + { + dol_print_error($this->db); + $error++; + } + + if (! empty($conf->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN)) + { + $originforcontact = $origin; + $originidforcontact = $origin_id; + if ($originforcontact == 'shipping') // shipment and order share the same contacts. If creating from shipment we take data of order + { + require_once DOL_DOCUMENT_ROOT . '/expedition/class/expedition.class.php'; + $exp = new Expedition($db); + $exp->fetch($origin_id); + $exp->fetchObjectLinked(); + if (count($exp->linkedObjectsIds['commande']) > 0) + { + foreach ($exp->linkedObjectsIds['commande'] as $key => $value) + { + $originforcontact = 'commande'; + $originidforcontact = $value->id; + break; // We take first one + } + } + } + + $sqlcontact = "SELECT ctc.code, ctc.source, ec.fk_socpeople FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as ctc"; + $sqlcontact.= " WHERE element_id = ".$originidforcontact." AND ec.fk_c_type_contact = ctc.rowid AND ctc.element = '".$originforcontact."'"; + + $resqlcontact = $this->db->query($sqlcontact); + if ($resqlcontact) + { + while($objcontact = $this->db->fetch_object($resqlcontact)) + { + if ($objcontact->source == 'internal' && in_array($objcontact->code, array('SALESREPSIGN', 'SALESREPFOLL'))) continue; // ignore this, already forced previously + //print $objcontact->code.'-'.$objcontact->source.'-'.$objcontact->fk_socpeople."\n"; + $this->add_contact($objcontact->fk_socpeople, $objcontact->code, $objcontact->source); // May failed because of duplicate key or because code of contact type does not exists for new object + } + } + else dol_print_error($resqlcontact); + } + } + } + } + if (! $error) { // Call trigger @@ -987,19 +1047,12 @@ class Contrat extends CommonObject if (! $error) { - // 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(); return $this->id; } else { dol_syslog(get_class($this)."::create - 30 - ".$this->error, LOG_ERR); - $this->db->rollback(); return -3; } @@ -1008,7 +1061,6 @@ class Contrat extends CommonObject { $this->error="Failed to add contact"; dol_syslog(get_class($this)."::create - 20 - ".$this->error, LOG_ERR); - $this->db->rollback(); return -2; } diff --git a/htdocs/contrat/contact.php b/htdocs/contrat/contact.php index cd070f6078d..f5c8ab2cafa 100644 --- a/htdocs/contrat/contact.php +++ b/htdocs/contrat/contact.php @@ -156,7 +156,7 @@ if ($id > 0 || ! empty($ref)) else print $langs->trans("CompanyHasNoRelativeDiscount"); $absolute_discount=$object->thirdparty->getAvailableDiscounts(); print '. '; - if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->currency)); + if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->currency)); else print $langs->trans("CompanyHasNoAbsoluteDiscount"); print '.'; print ''; diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 7d7d1af898f..d3eff2f8173 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -541,7 +541,7 @@ abstract class CommonObject * Add a link between element $this->element and a contact * * @param int $fk_socpeople Id of thirdparty contact (if source = 'external') or id of user (if souce = 'internal') to link - * @param int $type_contact Type of contact (code or id). Must be if or code found into table llx_c_type_contact. For example: SALESREPFOLL + * @param int $type_contact Type of contact (code or id). Must be id or code found into table llx_c_type_contact. For example: SALESREPFOLL * @param string $source external=Contact extern (llx_socpeople), internal=Contact intern (llx_user) * @param int $notrigger Disable all triggers * @return int <0 if KO, >0 if OK @@ -551,7 +551,7 @@ abstract class CommonObject global $user,$langs; - dol_syslog(get_class($this)."::add_contact $fk_socpeople, $type_contact, $source"); + dol_syslog(get_class($this)."::add_contact $fk_socpeople, $type_contact, $source, $notrigger"); // Check parameters if ($fk_socpeople <= 0) @@ -587,10 +587,17 @@ abstract class CommonObject if ($resql) { $obj = $this->db->fetch_object($resql); - $id_type_contact=$obj->rowid; + if ($obj) $id_type_contact=$obj->rowid; } } + if ($id_type_contact == 0) + { + $this->error='CODE_NOT_VALID_FOR_THIS_ELEMENT'; + dol_syslog("CODE_NOT_VALID_FOR_THIS_ELEMENT"); + return -3; + } + $datecreate = dol_now(); $this->db->begin(); @@ -602,7 +609,6 @@ abstract class CommonObject $sql.= "'".$this->db->idate($datecreate)."'"; $sql.= ", 4, '". $id_type_contact . "' "; $sql.= ")"; - dol_syslog(get_class($this)."::add_contact", LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index 4002f437ede..e30b0fbd478 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -481,6 +481,9 @@ class Conf // Default max file size for upload $this->maxfilesize = (empty($this->global->MAIN_UPLOAD_DOC) ? 0 : $this->global->MAIN_UPLOAD_DOC * 1024); + // By default, we propagate contacts + if (! isset($this->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN)) $this->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN='*'; // Can be also '*' or '^(BILLING|SHIPPING|CUSTOMER|.*)$' (regex not yet implemented) + // Define list of limited modules if (! isset($this->global->MAIN_MODULES_FOR_EXTERNAL)) $this->global->MAIN_MODULES_FOR_EXTERNAL='user,supplier_proposal,facture,categorie,commande,fournisseur,contact,propal,projet,contrat,societe,ficheinter,expedition,agenda,adherent'; // '' means 'all'. Note that contact is added here as it should be a module later. diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index 7453a6b1b2f..0331ce6efda 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -830,6 +830,9 @@ div.ficheaddleft { div.ficheaddleft tr.liste_titre:first-child td table.nobordernopadding td { padding: 0 0 0 0; } +div.nopadding { + padding: 0 !important; +} .containercenter { display : table; diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php index d28e9c59dac..d5e7fbb0246 100644 --- a/htdocs/theme/md/style.css.php +++ b/htdocs/theme/md/style.css.php @@ -866,9 +866,12 @@ div.ficheaddleft { } /* For table into table into card */ -div.ficheaddleft tr.liste_titre:first-child td table.nobordernopadding td { +div.ficheaddleft tr.liste_titre:first-child td table.nobordernopadding td, div.nopadding { padding: 0 0 0 0; } +div.nopadding { + padding: 0 !important; +} table.noborder tr.liste_titre td { padding: 3px !important; diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index d10585fe12d..6e843f61e5a 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -2023,22 +2023,22 @@ class User extends CommonObject $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks if ($reshook > 0) $linkclose = $hookmanager->resPrint; - $link.=$linkclose.'>'; + $link.=$linkclose.'>'; $linkend=''; - //if ($withpictoimg == -1) $result.='