dolibarr  7.0.0-beta
box_contracts.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2010 Regis Houssin <regis.houssin@capnetworks.com>
3  * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
4  * Copyright (C) 2016-2017 Laurent Destailleur <eldy@users.sourceforge.net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
26 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
27 
28 
33 {
34  var $boxcode="lastcontracts";
35  var $boximg="object_contract";
36  var $boxlabel="BoxLastContracts";
37  var $depends = array("contrat"); // conf->contrat->enabled
38 
39  var $db;
40  var $param;
41 
42  var $info_box_head = array();
43  var $info_box_contents = array();
44 
45 
52  function __construct($db,$param)
53  {
54  global $user;
55 
56  $this->db=$db;
57 
58  $this->hidden=! ($user->rights->contrat->lire);
59  }
60 
67  function loadBox($max=5)
68  {
69  global $user, $langs, $db, $conf;
70 
71  $this->max=$max;
72 
73  include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
74 
75  $this->info_box_head = array('text' => $langs->trans("BoxTitleLastContracts",$max));
76 
77  if ($user->rights->contrat->lire)
78  {
79  $contractstatic=new Contrat($db);
80  $thirdpartytmp=new Societe($db);
81 
82  $sql = "SELECT s.nom as name, s.rowid as socid,";
83  $sql.= " c.rowid, c.ref, c.statut as fk_statut, c.date_contrat, c.datec, c.fin_validite, c.date_cloture";
84  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c";
85  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
86  $sql.= " WHERE c.fk_soc = s.rowid";
87  $sql.= " AND c.entity = ".$conf->entity;
88  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
89  if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
90  if ($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) $sql.= " ORDER BY c.date_contrat DESC, c.ref DESC ";
91  else $sql.= " ORDER BY c.tms DESC, c.ref DESC ";
92  $sql.= $db->plimit($max, 0);
93 
94  $resql = $db->query($sql);
95  if ($resql)
96  {
97  $num = $db->num_rows($resql);
98  $now=dol_now();
99 
100  $line = 0;
101 
102  $langs->load("contracts");
103 
104  while ($line < $num)
105  {
106  $objp = $db->fetch_object($resql);
107  $datec=$db->jdate($objp->datec);
108  $dateterm=$db->jdate($objp->fin_validite);
109  $dateclose=$db->jdate($objp->date_cloture);
110  $late = '';
111 
112  $contractstatic->statut=$objp->fk_statut;
113  $contractstatic->id=$objp->rowid;
114  $contractstatic->ref=$objp->ref;
115  $result=$contractstatic->fetch_lines();
116 
117  $thirdpartytmp->name = $objp->name;
118  $thirdpartytmp->id = $objp->socid;
119 
120  // fin_validite is no more on contract but on services
121  // if ($objp->fk_statut == 1 && $dateterm < ($now - $conf->contrat->cloture->warning_delay)) { $late = img_warning($langs->trans("Late")); }
122 
123  $this->info_box_contents[$line][] = array(
124  'td' => '',
125  'text' => $contractstatic->getNomUrl(1),
126  'text2'=> $late,
127  'asis'=>1
128  );
129 
130  $this->info_box_contents[$line][] = array(
131  'td' => 'class="tdoverflowmax100 maxwidth100onsmartphone"',
132  'text' => $thirdpartytmp->getNomUrl(1),
133  'asis'=>1
134  );
135 
136  $this->info_box_contents[$line][] = array(
137  'td' => 'class="right"',
138  'text' => dol_print_date($datec,'day'),
139  );
140 
141  $this->info_box_contents[$line][] = array(
142  'td' => 'class="nowrap right"',
143  'text' => $contractstatic->getLibStatut(7),
144  'asis'=>1,
145  );
146 
147  $line++;
148  }
149 
150  if ($num==0)
151  $this->info_box_contents[$line][0] = array(
152  'td' => 'align="center opacitymedium"',
153  'text'=>$langs->trans("NoRecordedContracts"),
154  );
155 
156  $db->free($resql);
157  } else {
158  $this->info_box_contents[0][0] = array(
159  'td' => '',
160  'maxlength'=>500,
161  'text' => ($db->error().' sql='.$sql),
162  );
163  }
164  } else {
165  $this->info_box_contents[0][0] = array(
166  'td' => 'align="left" class="nohover opacitymedium"',
167  'text' => $langs->trans("ReadPermissionNotAllowed")
168  );
169  }
170  }
171 
180  function showBox($head = null, $contents = null, $nooutput=0)
181  {
182  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
183  }
184 
185 }
186 
__construct($db, $param)
Constructor.
Class to manage contracts.
Class ModeleBoxes.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage the box to show last contracts.
dol_now($mode='gmt')
Return date for now.
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
loadBox($max=5)
Load data for box to show them later.