dolibarr  13.0.2
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 <https://www.gnu.org/licenses/>.
18  */
19 
26 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
27 
28 
33 {
34  public $boxcode = "lastcontracts";
35  public $boximg = "object_contract";
36  public $boxlabel = "BoxLastContracts";
37  public $depends = array("contrat"); // conf->contrat->enabled
38 
42  public $db;
43 
44  public $param;
45 
46  public $info_box_head = array();
47  public $info_box_contents = array();
48 
49 
56  public function __construct($db, $param)
57  {
58  global $user;
59 
60  $this->db = $db;
61 
62  $this->hidden = !($user->rights->contrat->lire);
63  }
64 
71  public function loadBox($max = 5)
72  {
73  global $user, $langs, $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($this->db);
84  $thirdpartytmp = new Societe($this->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 .= ", c.ref_customer, c.ref_supplier";
89  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c";
90  if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
91  $sql .= " WHERE c.fk_soc = s.rowid";
92  $sql .= " AND c.entity = ".$conf->entity;
93  if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
94  if ($user->socid) $sql .= " AND s.rowid = ".$user->socid;
95  if ($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) $sql .= " ORDER BY c.date_contrat DESC, c.ref DESC ";
96  else $sql .= " ORDER BY c.tms DESC, c.ref DESC ";
97  $sql .= $this->db->plimit($max, 0);
98 
99  $resql = $this->db->query($sql);
100  if ($resql)
101  {
102  $num = $this->db->num_rows($resql);
103  $now = dol_now();
104 
105  $line = 0;
106 
107  $langs->load("contracts");
108 
109  while ($line < $num)
110  {
111  $objp = $this->db->fetch_object($resql);
112 
113  $datec = $this->db->jdate($objp->datec);
114  $dateterm = $this->db->jdate($objp->fin_validite);
115  $dateclose = $this->db->jdate($objp->date_cloture);
116  $late = '';
117 
118  $contractstatic->statut = $objp->fk_statut;
119  $contractstatic->id = $objp->rowid;
120  $contractstatic->ref = $objp->ref;
121  $contractstatic->ref_customer = $objp->ref_customer;
122  $contractstatic->ref_supplier = $objp->ref_supplier;
123  $result = $contractstatic->fetch_lines();
124 
125  $thirdpartytmp->name = $objp->name;
126  $thirdpartytmp->id = $objp->socid;
127  $thirdpartytmp->email = $objp->email;
128  $thirdpartytmp->client = $objp->client;
129  $thirdpartytmp->fournisseur = $objp->fournisseur;
130  $thirdpartytmp->code_client = $objp->code_client;
131  $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
132  $thirdpartytmp->code_compta = $objp->code_compta;
133  $thirdpartytmp->code_compta_fournisseur = $objp->code_compta_fournisseur;
134 
135  // fin_validite is no more on contract but on services
136  // if ($objp->fk_statut == 1 && $dateterm < ($now - $conf->contrat->cloture->warning_delay)) { $late = img_warning($langs->trans("Late")); }
137 
138  $this->info_box_contents[$line][] = array(
139  'td' => 'class="nowraponall"',
140  'text' => $contractstatic->getNomUrl(1),
141  'text2'=> $late,
142  'asis'=>1
143  );
144 
145  $this->info_box_contents[$line][] = array(
146  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
147  'text' => $thirdpartytmp->getNomUrl(1),
148  'asis'=>1
149  );
150 
151  $this->info_box_contents[$line][] = array(
152  'td' => 'class="right"',
153  'text' => dol_print_date($datec, 'day'),
154  );
155 
156  $this->info_box_contents[$line][] = array(
157  'td' => 'class="nowraponall right"',
158  'text' => $contractstatic->getLibStatut(7),
159  'asis'=>1,
160  );
161 
162  $line++;
163  }
164 
165  if ($num == 0)
166  $this->info_box_contents[$line][0] = array(
167  'td' => 'class="center opacitymedium"',
168  'text'=>$langs->trans("NoRecordedContracts"),
169  );
170 
171  $this->db->free($resql);
172  } else {
173  $this->info_box_contents[0][0] = array(
174  'td' => '',
175  'maxlength'=>500,
176  'text' => ($this->db->error().' sql='.$sql),
177  );
178  }
179  } else {
180  $this->info_box_contents[0][0] = array(
181  'td' => 'class="nohover opacitymedium left"',
182  'text' => $langs->trans("ReadPermissionNotAllowed")
183  );
184  }
185  }
186 
195  public function showBox($head = null, $contents = null, $nooutput = 0)
196  {
197  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
198  }
199 }
__construct($db, $param)
Constructor.
dol_now($mode= 'auto')
Return date for now.
Class to manage contracts.
Class ModeleBoxes.
$conf db
API class for accounts.
Definition: inc.php:54
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage the box to show last contracts.
dol_print_date($time, $format= '', $tzoutput= 'auto', $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)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->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)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
loadBox($max=5)
Load data for box to show them later.