dolibarr  13.0.2
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->rights->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  {
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->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
91  $sql .= " WHERE cd.statut = 4 AND cd.date_fin_validite <= '".$this->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->socid) $sql .= ' AND c.fk_soc = '.$user->socid;
95  if (!$user->rights->societe->client->voir && !$user->socid) $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 .= ", s.email, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
98  $sql .= " ORDER BY date_line ASC";
99  $sql .= $this->db->plimit($max, 0);
100 
101  $resql = $this->db->query($sql);
102  if ($resql)
103  {
104  $num = $this->db->num_rows($resql);
105 
106  $i = 0;
107 
108  $thirdpartytmp = new Societe($this->db);
109  $contract = new Contrat($this->db);
110 
111  while ($i < $num)
112  {
113  $late = '';
114 
115  $objp = $this->db->fetch_object($resql);
116 
117  $thirdpartytmp->name = $objp->name;
118  $thirdpartytmp->id = $objp->socid;
119  $thirdpartytmp->email = $objp->email;
120  $thirdpartytmp->client = $objp->client;
121  $thirdpartytmp->fournisseur = $objp->fournisseur;
122  $thirdpartytmp->code_client = $objp->code_client;
123  $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
124  $thirdpartytmp->code_compta = $objp->code_compta;
125  $thirdpartytmp->code_compta_fournisseur = $objp->code_compta_fournisseur;
126 
127  $contract->id = $objp->rowid;
128  $contract->ref = $objp->ref;
129  $contract->statut = $objp->fk_statut;
130  $contract->ref_customer = $objp->ref_customer;
131  $contract->ref_supplier = $objp->ref_supplier;
132 
133  $dateline = $this->db->jdate($objp->date_line);
134  if (($dateline + $conf->contrat->services->expires->warning_delay) < $now) $late = img_warning($langs->trans("Late"));
135 
136  $this->info_box_contents[$i][] = array(
137  'td' => 'class="nowraponall"',
138  'text' => $contract->getNomUrl(1),
139  'asis' => 1
140  );
141 
142  $this->info_box_contents[$i][] = array(
143  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone left"',
144  'text' => $thirdpartytmp->getNomUrl(1, 'customer'),
145  'asis' => 1
146  );
147 
148  $this->info_box_contents[$i][] = array(
149  'td' => 'class="center nowraponall"',
150  'text' => dol_print_date($dateline, 'day'),
151  'text2'=> $late,
152  );
153 
154  $this->info_box_contents[$i][] = array(
155  'td' => 'class="right"',
156  'text' => $objp->nb_services,
157  );
158 
159 
160  $i++;
161  }
162 
163  if ($num == 0)
164  {
165  $langs->load("contracts");
166  $this->info_box_contents[$i][] = array(
167  'td' => 'class="nohover opacitymedium center"',
168  'text' => $langs->trans("NoExpiredServices"),
169  );
170  }
171 
172  $this->db->free($resql);
173  } else {
174  $this->info_box_contents[0][] = array(
175  'td' => '',
176  'maxlength'=>500,
177  'text' => ($this->db->error().' sql='.$sql),
178  );
179  }
180  } else {
181  $this->info_box_contents[0][0] = array(
182  'td' => 'class="nohover opacitymedium left"',
183  'text' => $langs->trans("ReadPermissionNotAllowed")
184  );
185  }
186  }
187 
196  public function showBox($head = null, $contents = null, $nooutput = 0)
197  {
198  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
199  }
200 }
loadBox($max=5)
Load data for box to show them later.
dol_now($mode= 'auto')
Return date for now.
Class to manage contracts.
Class ModeleBoxes.
$conf db
API class for accounts.
Definition: inc.php:54
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
__construct($db, $param)
Constructor.
Class to manage the box to show expired services.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_print_date($time, $format= '', $tzoutput= 'auto', $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)&&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
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.