dolibarr  9.0.0
box_ficheinter.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
3  * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
4  * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
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 <http://www.gnu.org/licenses/>.
18  */
19 
26 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
27 
28 
33 {
34  var $boxcode="ficheinter";
35  var $boximg="object_intervention";
36  var $boxlabel="BoxFicheInter";
37  var $depends = array("ficheinter"); // conf->contrat->enabled
38 
42  public $db;
43 
44  var $param;
45 
46  var $info_box_head = array();
47  var $info_box_contents = array();
48 
49 
56  function __construct($db,$param)
57  {
58  global $user;
59 
60  $this->db=$db;
61 
62  $this->hidden=! ($user->rights->ficheinter->lire);
63  }
64 
71  function loadBox($max=10)
72  {
73  global $user, $langs, $db, $conf;
74 
75  $this->max=$max;
76 
77  include_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
78  $ficheinterstatic=new Fichinter($db);
79 
80  $this->info_box_head = array('text' => $langs->trans("BoxTitleLastFicheInter",$max));
81 
82  if (! empty($user->rights->ficheinter->lire))
83  {
84  $sql = "SELECT f.rowid, f.ref, f.fk_soc, f.fk_statut,";
85  $sql.= " f.datec,";
86  $sql.= " f.date_valid as datev,";
87  $sql.= " f.tms as datem,";
88  $sql.= " s.nom as name, s.rowid as socid, s.client";
89  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
90  if (! $user->rights->societe->client->voir) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
91  $sql.= ", ".MAIN_DB_PREFIX."fichinter as f";
92  $sql.= " WHERE f.fk_soc = s.rowid ";
93  $sql.= " AND f.entity = ".$conf->entity;
94  if (! $user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
95  if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
96  $sql.= " ORDER BY f.tms DESC";
97  $sql.= $db->plimit($max, 0);
98 
99  dol_syslog(get_class($this).'::loadBox', LOG_DEBUG);
100  $resql = $db->query($sql);
101  if ($resql)
102  {
103  $num = $db->num_rows($resql);
104  $now=dol_now();
105 
106  $i = 0;
107 
108  while ($i < $num)
109  {
110  $objp = $db->fetch_object($resql);
111  $datec=$db->jdate($objp->datec);
112 
113  $ficheinterstatic->statut=$objp->fk_statut;
114  $ficheinterstatic->id=$objp->rowid;
115  $ficheinterstatic->ref=$objp->ref;
116 
117  $this->info_box_contents[$i][] = array('td' => '',
118  'text' => $ficheinterstatic->getNomUrl(1),
119  'asis' => 1
120  );
121 
122  $this->info_box_contents[$i][] = array('td' => 'align="left" width="16"',
123  'logo' => 'company',
124  'url' => DOL_URL_ROOT."/comm/card.php?socid=".$objp->socid);
125 
126  $this->info_box_contents[$i][] = array('td' => '',
127  'text' => dol_trunc($objp->name,40),
128  'url' => DOL_URL_ROOT."/comm/card.php?socid=".$objp->socid);
129 
130  $this->info_box_contents[$i][] = array('td' => 'class="right"',
131  'text' => dol_print_date($datec,'day'));
132 
133  $this->info_box_contents[$i][] = array('td' => 'align="right" class="nowrap"',
134  'text' => $ficheinterstatic->getLibStatut(6),
135  'asis'=>1
136  );
137 
138  $i++;
139  }
140 
141  if ($num==0) $this->info_box_contents[$i][] = array('td' => 'align="center"','text'=>$langs->trans("NoRecordedInterventions"));
142 
143  $db->free($resql);
144  }
145  else
146  {
147  $this->info_box_contents[0][] = array( 'td' => '',
148  'maxlength'=>500,
149  'text' => ($db->error().' sql='.$sql));
150  }
151  }
152  else
153  {
154  $this->info_box_contents[0][] = array(
155  'td' => 'align="left" class="nohover opacitymedium"',
156  'text' => $langs->trans("ReadPermissionNotAllowed")
157  );
158  }
159  }
160 
169  function showBox($head = null, $contents = null, $nooutput=0)
170  {
171  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
172  }
173 }
174 
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding &#39;...&#39; if string larger than length.
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 interventions.
Class ModeleBoxes.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
dol_now($mode='gmt')
Return date for now.
__construct($db, $param)
Constructor.
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
loadBox($max=10)
Load data for box to show them later.
Class to manage the box to show last interventions.