dolibarr  9.0.0
box_services_expired.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
24 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
25 
26 
31 {
32 
33  var $boxcode="expiredservices"; // id of box
34  var $boximg="object_contract";
35  var $boxlabel="BoxOldestExpiredServices";
36  var $depends = array("contrat"); // conf->propal->enabled
37 
41  public $db;
42 
43  var $param;
44 
45  var $info_box_head = array();
46  var $info_box_contents = array();
47 
48 
55  function __construct($db,$param)
56  {
57  global $user;
58 
59  $this->db=$db;
60 
61  $this->hidden=! ($user->rights->contrat->lire);
62  }
63 
70  function loadBox($max=5)
71  {
72  global $user, $langs, $db, $conf;
73 
74  $this->max=$max;
75 
76  include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
77 
78  $now=dol_now();
79 
80  $this->info_box_head = array('text' => $langs->trans("BoxLastExpiredServices",$max));
81 
82  if ($user->rights->contrat->lire)
83  {
84  // Select contracts with at least one expired service
85  $sql = "SELECT ";
86  $sql.= " c.rowid, c.ref, c.statut as fk_statut, c.date_contrat, c.ref_customer, c.ref_supplier,";
87  $sql.= " 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,";
88  $sql.= " MIN(cd.date_fin_validite) as date_line, COUNT(cd.rowid) as nb_services";
89  $sql.= " FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe s, ".MAIN_DB_PREFIX."contratdet as cd";
90  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
91  $sql.= " WHERE cd.statut = 4 AND cd.date_fin_validite <= '".$db->idate($now)."'";
92  $sql.= " AND c.entity = ".$conf->entity;
93  $sql.= " AND c.fk_soc=s.rowid AND cd.fk_contrat=c.rowid AND c.statut > 0";
94  if ($user->societe_id) $sql.=' AND c.fk_soc = '.$user->societe_id;
95  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
96  $sql.= " GROUP BY c.rowid, c.ref, c.statut, c.date_contrat, c.ref_customer, c.ref_supplier, s.nom, s.rowid";
97  $sql.= " ORDER BY date_line ASC";
98  $sql.= $db->plimit($max, 0);
99 
100  $resql = $db->query($sql);
101  if ($resql)
102  {
103  $num = $db->num_rows($resql);
104 
105  $i = 0;
106 
107  $thirdpartytmp = new Societe($this->db);
108  $contract = new Contrat($this->db);
109 
110  while ($i < $num)
111  {
112  $late='';
113 
114  $objp = $db->fetch_object($resql);
115 
116  $thirdpartytmp->name = $objp->name;
117  $thirdpartytmp->id = $objp->socid;
118  $thirdpartytmp->email = $objp->email;
119  $thirdpartytmp->client = $objp->client;
120  $thirdpartytmp->fournisseur = $objp->fournisseur;
121  $thirdpartytmp->code_client = $objp->code_client;
122  $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
123  $thirdpartytmp->code_compta = $objp->code_compta;
124  $thirdpartytmp->code_compta_fournisseur = $objp->code_compta_fournisseur;
125 
126  $contract->id = $objp->rowid;
127  $contract->ref = $objp->ref;
128  $contract->statut = $objp->fk_statut;
129  $contract->ref_customer = $objp->ref_customer;
130  $contract->ref_supplier = $objp->ref_supplier;
131 
132  $dateline=$db->jdate($objp->date_line);
133  if (($dateline + $conf->contrat->services->expires->warning_delay) < $now) $late=img_warning($langs->trans("Late"));
134 
135  $this->info_box_contents[$i][] = array('td' => '',
136  'text' => $contract->getNomUrl(1),
137  'asis' => 1
138  );
139 
140  $this->info_box_contents[$i][] = array('td' => 'class="tdoverflowmax150 maxwidth150onsmartphone" align="left"',
141  'text' => $thirdpartytmp->getNomUrl(1, 'customer'),
142  'asis' => 1
143  );
144 
145  $this->info_box_contents[$i][] = array('td' => 'align="center"',
146  'text' => dol_print_date($dateline,'day'),
147  'text2'=> $late);
148 
149  $this->info_box_contents[$i][] = array('td' => 'class="right"',
150  'text' => $objp->nb_services);
151 
152 
153  $i++;
154  }
155 
156  if ($num==0)
157  {
158  $langs->load("contracts");
159  $this->info_box_contents[$i][] = array('td' => 'align="center" class="nohover opacitymedium"','text'=>$langs->trans("NoExpiredServices"));
160  }
161 
162  $db->free($resql);
163  }
164  else
165  {
166  $this->info_box_contents[0][] = array( 'td' => '',
167  'maxlength'=>500,
168  'text' => ($db->error().' sql='.$sql));
169  }
170  }
171  else
172  {
173  $this->info_box_contents[0][0] = array(
174  'td' => 'align="left" class="nohover opacitymedium"',
175  'text' => $langs->trans("ReadPermissionNotAllowed")
176  );
177  }
178  }
179 
188  function showBox($head = null, $contents = null, $nooutput=0)
189  {
190  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
191  }
192 }
193 
loadBox($max=5)
Load data for box to show them later.
img_warning($titlealt='default', $moreatt='')
Show warning logo.
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
Class to manage contracts.
Class ModeleBoxes.
__construct($db, $param)
Constructor.
Class to manage the box to show expired services.
Class to manage third parties objects (customers, suppliers, prospects...)
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.