dolibarr  19.0.0-dev
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 <https://www.gnu.org/licenses/>.
16  */
17 
24 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
25 
26 
31 {
32 
33  public $boxcode = "expiredservices"; // id of box
34  public $boximg = "object_contract";
35  public $boxlabel = "BoxOldestExpiredServices";
36  public $depends = array("contrat"); // conf->propal->enabled
37 
41  public $db;
42 
43  public $param;
44 
45  public $info_box_head = array();
46  public $info_box_contents = array();
47 
48 
55  public function __construct($db, $param)
56  {
57  global $user;
58 
59  $this->db = $db;
60 
61  $this->hidden = !($user->hasRight('contrat', 'lire'));
62  }
63 
70  public function loadBox($max = 5)
71  {
72  global $user, $langs, $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  // Select contracts with at least one expired service
84  $sql = "SELECT ";
85  $sql .= " c.rowid, c.ref, c.statut as fk_statut, c.date_contrat, c.ref_customer, c.ref_supplier,";
86  $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,";
87  $sql .= " MIN(cd.date_fin_validite) as date_line, COUNT(cd.rowid) as nb_services";
88  $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe s, ".MAIN_DB_PREFIX."contratdet as cd";
89  if (empty($user->rights->societe->client->voir) && !$user->socid) {
90  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
91  }
92  $sql .= " WHERE cd.statut = 4 AND cd.date_fin_validite <= '".$this->db->idate($now)."'";
93  $sql .= " AND c.entity = ".$conf->entity;
94  $sql .= " AND c.fk_soc=s.rowid AND cd.fk_contrat=c.rowid AND c.statut > 0";
95  if ($user->socid) {
96  $sql .= ' AND c.fk_soc = '.((int) $user->socid);
97  }
98  if (empty($user->rights->societe->client->voir) && !$user->socid) {
99  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
100  }
101  $sql .= " GROUP BY c.rowid, c.ref, c.statut, c.date_contrat, c.ref_customer, c.ref_supplier, s.nom, s.rowid";
102  $sql .= ", s.email, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
103  $sql .= " ORDER BY date_line ASC";
104  $sql .= $this->db->plimit($max, 0);
105 
106  $resql = $this->db->query($sql);
107  if ($resql) {
108  $num = $this->db->num_rows($resql);
109 
110  $i = 0;
111 
112  $thirdpartytmp = new Societe($this->db);
113  $contract = new Contrat($this->db);
114 
115  while ($i < $num) {
116  $late = '';
117 
118  $objp = $this->db->fetch_object($resql);
119 
120  $thirdpartytmp->name = $objp->name;
121  $thirdpartytmp->id = $objp->socid;
122  $thirdpartytmp->email = $objp->email;
123  $thirdpartytmp->client = $objp->client;
124  $thirdpartytmp->fournisseur = $objp->fournisseur;
125  $thirdpartytmp->code_client = $objp->code_client;
126  $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
127  $thirdpartytmp->code_compta = $objp->code_compta;
128  $thirdpartytmp->code_compta_fournisseur = $objp->code_compta_fournisseur;
129 
130  $contract->id = $objp->rowid;
131  $contract->ref = $objp->ref;
132  $contract->statut = $objp->fk_statut;
133  $contract->ref_customer = $objp->ref_customer;
134  $contract->ref_supplier = $objp->ref_supplier;
135 
136  $dateline = $this->db->jdate($objp->date_line);
137  if (($dateline + $conf->contrat->services->expires->warning_delay) < $now) {
138  $late = img_warning($langs->trans("Late"));
139  }
140 
141  $this->info_box_contents[$i][] = array(
142  'td' => 'class="nowraponall"',
143  'text' => $contract->getNomUrl(1),
144  'asis' => 1
145  );
146 
147  $this->info_box_contents[$i][] = array(
148  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone left"',
149  'text' => $thirdpartytmp->getNomUrl(1, 'customer'),
150  'asis' => 1
151  );
152 
153  $this->info_box_contents[$i][] = array(
154  'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateEndPlanned").': '.dol_print_date($dateline, 'dayhour', 'tzuserrel')).'"',
155  'text' => dol_print_date($dateline, 'day', 'tzuserrel'),
156  'text2'=> $late,
157  );
158 
159  $this->info_box_contents[$i][] = array(
160  'td' => 'class="right"',
161  'text' => $objp->nb_services,
162  );
163 
164 
165  $i++;
166  }
167 
168  if ($num == 0) {
169  $langs->load("contracts");
170  $this->info_box_contents[$i][] = array(
171  'td' => 'class="nohover opacitymedium center"',
172  'text' => $langs->trans("NoExpiredServices"),
173  );
174  }
175 
176  $this->db->free($resql);
177  } else {
178  $this->info_box_contents[0][] = array(
179  'td' => '',
180  'maxlength'=>500,
181  'text' => ($this->db->error().' sql='.$sql),
182  );
183  }
184  } else {
185  $this->info_box_contents[0][0] = array(
186  'td' => 'class="nohover opacitymedium left"',
187  'text' => $langs->trans("ReadPermissionNotAllowed")
188  );
189  }
190  }
191 
200  public function showBox($head = null, $contents = null, $nooutput = 0)
201  {
202  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
203  }
204 }
Class to manage contracts.
Class ModeleBoxes.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage the box to show expired services.
loadBox($max=5)
Load data for box to show them later.
__construct($db, $param)
Constructor.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...