dolibarr  7.0.0-beta
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 
38  var $db;
39  var $param;
40 
41  var $info_box_head = array();
42  var $info_box_contents = array();
43 
44 
51  function __construct($db,$param)
52  {
53  global $user;
54 
55  $this->db=$db;
56 
57  $this->hidden=! ($user->rights->contrat->lire);
58  }
59 
66  function loadBox($max=5)
67  {
68  global $user, $langs, $db, $conf;
69 
70  $this->max=$max;
71 
72  include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
73 
74  $now=dol_now();
75 
76  $this->info_box_head = array('text' => $langs->trans("BoxLastExpiredServices",$max));
77 
78  if ($user->rights->contrat->lire)
79  {
80  // Select contracts with at least one expired service
81  $sql = "SELECT ";
82  $sql.= " c.rowid, c.ref, c.statut as fk_statut, c.date_contrat, c.ref_customer, c.ref_supplier,";
83  $sql.= " s.nom as name, s.rowid as socid,";
84  $sql.= " MIN(cd.date_fin_validite) as date_line, COUNT(cd.rowid) as nb_services";
85  $sql.= " FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe s, ".MAIN_DB_PREFIX."contratdet as cd";
86  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
87  $sql.= " WHERE cd.statut = 4 AND cd.date_fin_validite <= '".$db->idate($now)."'";
88  $sql.= " AND c.entity = ".$conf->entity;
89  $sql.= " AND c.fk_soc=s.rowid AND cd.fk_contrat=c.rowid AND c.statut > 0";
90  if ($user->societe_id) $sql.=' AND c.fk_soc = '.$user->societe_id;
91  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
92  $sql.= " GROUP BY c.rowid, c.ref, c.statut, c.date_contrat, c.ref_customer, c.ref_supplier, s.nom, s.rowid";
93  $sql.= " ORDER BY date_line ASC";
94  $sql.= $db->plimit($max, 0);
95 
96  $resql = $db->query($sql);
97  if ($resql)
98  {
99  $num = $db->num_rows($resql);
100 
101  $i = 0;
102 
103  $thirdpartytmp = new Societe($this->db);
104  $contract = new Contrat($this->db);
105 
106  while ($i < $num)
107  {
108  $late='';
109 
110  $objp = $db->fetch_object($resql);
111 
112  $thirdpartytmp->id = $objp->socid;
113  $thirdpartytmp->name = $objp->name;
114 
115  $contract->id = $objp->rowid;
116  $contract->ref = $objp->ref;
117  $contract->statut = $objp->fk_statut;
118  $contract->ref_customer = $objp->ref_customer;
119  $contract->ref_supplier = $objp->ref_supplier;
120 
121  $dateline=$db->jdate($objp->date_line);
122  if (($dateline + $conf->contrat->services->expires->warning_delay) < $now) $late=img_warning($langs->trans("Late"));
123 
124  $this->info_box_contents[$i][] = array('td' => '',
125  'text' => $contract->getNomUrl(1),
126  'asis' => 1
127  );
128 
129  $this->info_box_contents[$i][] = array('td' => 'class="tdoverflowmax100 maxwidth100onsmartphone" align="left"',
130  'text' => $thirdpartytmp->getNomUrl(1, 'customer'),
131  'asis' => 1
132  );
133 
134  $this->info_box_contents[$i][] = array('td' => 'align="center"',
135  'text' => dol_print_date($dateline,'day'),
136  'text2'=> $late);
137 
138  $this->info_box_contents[$i][] = array('td' => 'class="right"',
139  'text' => $objp->nb_services);
140 
141 
142  $i++;
143  }
144 
145  if ($num==0)
146  {
147  $langs->load("contracts");
148  $this->info_box_contents[$i][] = array('td' => 'align="center" class="nohover opacitymedium"','text'=>$langs->trans("NoExpiredServices"));
149  }
150 
151  $db->free($resql);
152  }
153  else
154  {
155  $this->info_box_contents[0][] = array( 'td' => '',
156  'maxlength'=>500,
157  'text' => ($db->error().' sql='.$sql));
158  }
159 
160 
161  }
162  else
163  {
164  $this->info_box_contents[0][0] = array(
165  'td' => 'align="left" class="nohover opacitymedium"',
166  'text' => $langs->trans("ReadPermissionNotAllowed")
167  );
168  }
169  }
170 
179  function showBox($head = null, $contents = null, $nooutput=0)
180  {
181  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
182  }
183 
184  }
185 
loadBox($max=5)
Load data for box to show them later.
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...)
img_warning($titlealt= 'default', $moreatt= '')
Show warning logo.
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).
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
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.