dolibarr  9.0.0
box_contracts.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2010 Regis Houssin <regis.houssin@inodbox.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 
42  public $db;
43 
44  var $param;
45 
46  var $info_box_head = array();
47  var $info_box_contents = array();
48 
49 
56  function __construct($db,$param)
57  {
58  global $user;
59 
60  $this->db=$db;
61 
62  $this->hidden=! ($user->rights->contrat->lire);
63  }
64 
71  function loadBox($max=5)
72  {
73  global $user, $langs, $db, $conf;
74 
75  $this->max=$max;
76 
77  include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
78 
79  $this->info_box_head = array('text' => $langs->trans("BoxTitleLastContracts",$max));
80 
81  if ($user->rights->contrat->lire)
82  {
83  $contractstatic=new Contrat($db);
84  $thirdpartytmp=new Societe($db);
85 
86  $sql = "SELECT s.nom as name, s.rowid as socid, s.email, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,";
87  $sql.= " c.rowid, c.ref, c.statut as fk_statut, c.date_contrat, c.datec, c.fin_validite, c.date_cloture";
88  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c";
89  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
90  $sql.= " WHERE c.fk_soc = s.rowid";
91  $sql.= " AND c.entity = ".$conf->entity;
92  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
93  if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
94  if ($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) $sql.= " ORDER BY c.date_contrat DESC, c.ref DESC ";
95  else $sql.= " ORDER BY c.tms DESC, c.ref DESC ";
96  $sql.= $db->plimit($max, 0);
97 
98  $resql = $db->query($sql);
99  if ($resql)
100  {
101  $num = $db->num_rows($resql);
102  $now=dol_now();
103 
104  $line = 0;
105 
106  $langs->load("contracts");
107 
108  while ($line < $num)
109  {
110  $objp = $db->fetch_object($resql);
111 
112  $datec=$db->jdate($objp->datec);
113  $dateterm=$db->jdate($objp->fin_validite);
114  $dateclose=$db->jdate($objp->date_cloture);
115  $late = '';
116 
117  $contractstatic->statut=$objp->fk_statut;
118  $contractstatic->id=$objp->rowid;
119  $contractstatic->ref=$objp->ref;
120  $result=$contractstatic->fetch_lines();
121 
122  $thirdpartytmp->name = $objp->name;
123  $thirdpartytmp->id = $objp->socid;
124  $thirdpartytmp->email = $objp->email;
125  $thirdpartytmp->client = $objp->client;
126  $thirdpartytmp->fournisseur = $objp->fournisseur;
127  $thirdpartytmp->code_client = $objp->code_client;
128  $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
129  $thirdpartytmp->code_compta = $objp->code_compta;
130  $thirdpartytmp->code_compta_fournisseur = $objp->code_compta_fournisseur;
131 
132  // fin_validite is no more on contract but on services
133  // if ($objp->fk_statut == 1 && $dateterm < ($now - $conf->contrat->cloture->warning_delay)) { $late = img_warning($langs->trans("Late")); }
134 
135  $this->info_box_contents[$line][] = array(
136  'td' => '',
137  'text' => $contractstatic->getNomUrl(1),
138  'text2'=> $late,
139  'asis'=>1
140  );
141 
142  $this->info_box_contents[$line][] = array(
143  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
144  'text' => $thirdpartytmp->getNomUrl(1),
145  'asis'=>1
146  );
147 
148  $this->info_box_contents[$line][] = array(
149  'td' => 'class="right"',
150  'text' => dol_print_date($datec,'day'),
151  );
152 
153  $this->info_box_contents[$line][] = array(
154  'td' => 'class="nowrap right"',
155  'text' => $contractstatic->getLibStatut(7),
156  'asis'=>1,
157  );
158 
159  $line++;
160  }
161 
162  if ($num==0)
163  $this->info_box_contents[$line][0] = array(
164  'td' => 'align="center opacitymedium"',
165  'text'=>$langs->trans("NoRecordedContracts"),
166  );
167 
168  $db->free($resql);
169  } else {
170  $this->info_box_contents[0][0] = array(
171  'td' => '',
172  'maxlength'=>500,
173  'text' => ($db->error().' sql='.$sql),
174  );
175  }
176  } else {
177  $this->info_box_contents[0][0] = array(
178  'td' => 'align="left" class="nohover opacitymedium"',
179  'text' => $langs->trans("ReadPermissionNotAllowed")
180  );
181  }
182  }
183 
192  function showBox($head = null, $contents = null, $nooutput=0)
193  {
194  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
195  }
196 }
197 
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:1053
__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.
loadBox($max=5)
Load data for box to show them later.