diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index d2c094fb0254f..47cde8e3f4071 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -2220,18 +2220,18 @@ public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id) */ class ContratLigne extends CommonObjectLine { - + public $element='contratdet'; + public $table_element='contratdet'; + var $id; var $ref; var $tms; + var $fk_contrat; var $fk_product; var $statut; // 0 inactive, 4 active, 5 closed + var $type; // 0 for product, 1 for service var $label; - - public $element='contratdet'; - public $table_element='contratdet'; - /** * @var string * @deprecated Use $label instead @@ -2240,6 +2240,10 @@ class ContratLigne extends CommonObjectLine public $libelle; var $description; + + var $product_ref; + var $product_label; + var $date_commande; var $date_ouverture_prevue; // date start planned var $date_ouverture; // date start real @@ -2379,16 +2383,17 @@ function getNomUrl($withpicto=0,$maxlength=0) $result=''; $label=$langs->trans("ShowContractOfService").': '.$this->label; - + if (empty($label)) $label=$this->description; + $link = ''; $linkend=''; - $picto='contract'; - + $picto='service'; + if ($this->type == 0) $picto='product'; if ($withpicto) $result.=($link.img_object($label, $picto, 'class="classfortooltip"').$linkend); if ($withpicto && $withpicto != 2) $result.=' '; - if ($withpicto != 2) $result.=$link.$this->label.$linkend; + if ($withpicto != 2) $result.=$link.($this->product_ref?$this->product_ref.' ':'').($this->label?$this->label:$this->description).$linkend; return $result; } @@ -2417,6 +2422,7 @@ function fetch($id, $ref='') $sql.= " p.ref as product_ref,"; $sql.= " p.label as product_label,"; $sql.= " p.description as product_desc,"; + $sql.= " p.type as product_type,"; $sql.= " t.description,"; $sql.= " t.date_commande,"; $sql.= " t.date_ouverture_prevue as date_ouverture_prevue,"; @@ -2467,6 +2473,7 @@ function fetch($id, $ref='') $this->product_ref = $obj->product_ref; $this->product_label = $obj->product_label; $this->product_description = $obj->product_description; + $this->product_type = $obj->product_type; $this->label = $obj->label; // deprecated. We do not use this field. Only ref and label of product, and description of contract line $this->description = $obj->description; $this->date_commande = $this->db->jdate($obj->date_commande); diff --git a/htdocs/core/boxes/box_contracts.php b/htdocs/core/boxes/box_contracts.php index 58b5dc7f1fae7..665bff4c6dad2 100644 --- a/htdocs/core/boxes/box_contracts.php +++ b/htdocs/core/boxes/box_contracts.php @@ -55,13 +55,15 @@ function loadBox($max=5) $this->max=$max; include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php'; - $contractstatic=new Contrat($db); - + $this->info_box_head = array('text' => $langs->trans("BoxTitleLastContracts",$max)); if ($user->rights->contrat->lire) { - $sql = "SELECT s.nom as name, s.rowid as socid,"; + $contractstatic=new Contrat($db); + $thirdpartytmp=new Societe($db); + + $sql = "SELECT s.nom as name, s.rowid as socid,"; $sql.= " c.rowid, c.ref, c.statut as fk_statut, c.date_contrat, c.datec, c.fin_validite, c.date_cloture"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; @@ -80,7 +82,10 @@ function loadBox($max=5) $line = 0; - while ($line < $num) { + $langs->load("contracts"); + + while ($line < $num) + { $objp = $db->fetch_object($resql); $datec=$db->jdate($objp->datec); $dateterm=$db->jdate($objp->fin_validite); @@ -89,38 +94,26 @@ function loadBox($max=5) $contractstatic->statut=$objp->fk_statut; $contractstatic->id=$objp->rowid; + $contractstatic->ref=$objp->ref; $result=$contractstatic->fetch_lines(); + $thirdpartytmp->name = $objp->name; + $thirdpartytmp->id = $objp->socid; + // fin_validite is no more on contract but on services // if ($objp->fk_statut == 1 && $dateterm < ($now - $conf->contrat->cloture->warning_delay)) { $late = img_warning($langs->trans("Late")); } - $this->info_box_contents[$line][] = array( - 'td' => 'align="left" width="16"', - 'logo' => $this->boximg, - 'tooltip' => $langs->trans('Contract').': '.($objp->ref?$objp->ref:$objp->rowid), - 'url' => DOL_URL_ROOT."/contrat/card.php?id=".$objp->rowid, - ); - $this->info_box_contents[$line][] = array( 'td' => 'align="left"', - 'text' => ($objp->ref?$objp->ref:$objp->rowid), // Some contracts have no ref - 'tooltip' => $langs->trans('Contract').': '.($objp->ref?$objp->ref:$objp->rowid), + 'text' => $contractstatic->getNomUrl(1), 'text2'=> $late, - 'url' => DOL_URL_ROOT."/contrat/card.php?id=".$objp->rowid, - ); - - $this->info_box_contents[$line][] = array( - 'td' => 'align="left" width="16"', - 'logo' => 'company', - 'tooltip' => $langs->trans('Customer').': '.$objp->name, - 'url' => DOL_URL_ROOT."/comm/card.php?socid=".$objp->socid, + 'asis'=>1 ); $this->info_box_contents[$line][] = array( 'td' => 'align="left"', - 'text' => dol_trunc($objp->name,40), - 'tooltip' => $langs->trans('Customer').': '.$objp->name, - 'url' => DOL_URL_ROOT."/comm/card.php?socid=".$objp->socid, + 'text' => $thirdpartytmp->getNomUrl(1), + 'asis'=>1 ); $this->info_box_contents[$line][] = array( diff --git a/htdocs/core/boxes/box_services_contracts.php b/htdocs/core/boxes/box_services_contracts.php index eb48fc83d2b75..c38b99263ba08 100644 --- a/htdocs/core/boxes/box_services_contracts.php +++ b/htdocs/core/boxes/box_services_contracts.php @@ -56,26 +56,28 @@ function loadBox($max=5) $this->max=$max; include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php'; - $contratlignestatic=new ContratLigne($db); $this->info_box_head = array('text' => $langs->trans("BoxLastProductsInContract",$max)); if ($user->rights->service->lire && $user->rights->contrat->lire) { + $contractstatic=new Contrat($db); + $contratlignestatic=new ContratLigne($db); + $thirdpartytmp = new Societe($db); + $sql = "SELECT s.nom as name, s.rowid as socid,"; - $sql.= " c.rowid,"; - $sql.= " cd.rowid as cdid, cd.tms as datem, cd.statut,"; - $sql.= " p.rowid as pid, p.label, p.fk_product_type"; + $sql.= " c.rowid, c.ref, c.statut as contract_status,"; + $sql.= " cd.rowid as cdid, cd.tms as datem, cd.statut, cd.label, cd.description, cd.product_type as type,"; + $sql.= " p.rowid as product_id, p.ref as product_ref"; $sql.= " FROM (".MAIN_DB_PREFIX."societe as s"; $sql.= ", ".MAIN_DB_PREFIX."contrat as c"; $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd"; - $sql.= ", ".MAIN_DB_PREFIX."product as p"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= ")"; $sql.= " WHERE c.entity = ".$conf->entity; $sql.= " AND s.rowid = c.fk_soc"; $sql.= " AND c.rowid = cd.fk_contrat"; - $sql.= " AND cd.fk_product = p.rowid"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id; $sql.= $db->order("c.tms","DESC"); @@ -94,12 +96,27 @@ function loadBox($max=5) $objp = $db->fetch_object($result); $datem=$db->jdate($objp->datem); + $contratlignestatic->id=$objp->cdid; + $contratlignestatic->fk_contrat=$objp->rowid; + $contratlignestatic->label=$objp->label; + $contratlignestatic->description=$objp->description; + $contratlignestatic->type=$objp->type; + $contratlignestatic->product_id=$objp->product_id; + $contratlignestatic->product_ref=$objp->product_ref; + + $contractstatic->statut=$objp->contract_status; + $contractstatic->id=$objp->rowid; + $contractstatic->ref=$objp->ref; + + $thirdpartytmp->name = $objp->name; + $thirdpartytmp->id = $objp->socid; + // Multilangs if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active { $sqld = "SELECT label"; $sqld.= " FROM ".MAIN_DB_PREFIX."product_lang"; - $sqld.= " WHERE fk_product=".$objp->pid; + $sqld.= " WHERE fk_product=".$objp->product_id; $sqld.= " AND lang='". $langs->getDefaultLang() ."'"; $sqld.= " LIMIT 1"; @@ -107,32 +124,29 @@ function loadBox($max=5) if ($resultd) { $objtp = $db->fetch_object($resultd); - if ($objtp->label != '') $objp->label = $objtp->label; + if ($objtp->label != '') $contratlignestatic->label = $objtp->label; } } - $this->info_box_contents[$i][0] = array('td' => 'align="left" width="16"', - 'logo' => ($objp->fk_product_type==1?'object_service':'object_product'), - 'url' => DOL_URL_ROOT."/contrat/card.php?id=".$objp->rowid); - - $this->info_box_contents[$i][1] = array('td' => 'align="left"', - 'text' => $objp->label, - 'maxlength' => 16, - 'url' => DOL_URL_ROOT."/contrat/card.php?id=".$objp->rowid); - - $this->info_box_contents[$i][2] = array('td' => 'align="left" width="16"', - 'logo' => 'company', - 'url' => DOL_URL_ROOT."/comm/card.php?socid=".$objp->socid); - - $this->info_box_contents[$i][3] = array('td' => 'align="left"', - 'text' => $objp->name, - 'maxlength' => 28, - 'url' => DOL_URL_ROOT."/comm/card.php?socid=".$objp->socid); - - $this->info_box_contents[$i][4] = array('td' => 'align="right"', + $this->info_box_contents[$i][] = array('td' => 'align="left"', + 'text' => $contratlignestatic->getNomUrl(1), + 'asis' => 1 + ); + + $this->info_box_contents[$i][] = array('td' => 'align="left"', + 'text' => $contractstatic->getNomUrl(1), + 'asis' => 1 + ); + + $this->info_box_contents[$i][] = array('td' => 'align="left"', + 'text' => $thirdpartytmp->getNomUrl(1), + 'asis' => 1 + ); + + $this->info_box_contents[$i][] = array('td' => 'align="right"', 'text' => dol_print_date($datem,'day')); - $this->info_box_contents[$i][5] = array('td' => 'align="right" width="18"', + $this->info_box_contents[$i][] = array('td' => 'align="right" width="18"', 'text' => $contratlignestatic->LibStatut($objp->statut,3) );