dolibarr  13.0.2
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 <https://www.gnu.org/licenses/>.
18  */
19 
26 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
27 
28 
33 {
34  public $boxcode = "ficheinter";
35  public $boximg = "object_intervention";
36  public $boxlabel = "BoxFicheInter";
37  public $depends = array("ficheinter"); // conf->contrat->enabled
38 
42  public $db;
43 
44  public $param;
45 
46  public $info_box_head = array();
47  public $info_box_contents = array();
48 
49 
56  public function __construct($db, $param)
57  {
58  global $user;
59 
60  $this->db = $db;
61 
62  $this->hidden = !($user->rights->ficheinter->lire);
63  }
64 
71  public function loadBox($max = 10)
72  {
73  global $user, $langs, $conf;
74 
75  $this->max = $max;
76 
77  include_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
78  $ficheinterstatic = new Fichinter($this->db);
79  $thirdpartystatic = new Societe($this->db);
80 
81  $this->info_box_head = array('text' => $langs->trans("BoxTitleLastFicheInter", $max));
82 
83  if (!empty($user->rights->ficheinter->lire))
84  {
85  $sql = "SELECT f.rowid, f.ref, f.fk_soc, f.fk_statut as status";
86  $sql .= ", f.datec";
87  $sql .= ", f.date_valid as datev";
88  $sql .= ", f.tms as datem";
89  $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
90  $sql .= ", s.code_client, s.code_compta, s.client";
91  $sql .= ", s.logo, s.email, s.entity";
92  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
93  if (!$user->rights->societe->client->voir) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
94  $sql .= ", ".MAIN_DB_PREFIX."fichinter as f";
95  $sql .= " WHERE f.fk_soc = s.rowid ";
96  $sql .= " AND f.entity = ".$conf->entity;
97  if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
98  if ($user->socid) $sql .= " AND s.rowid = ".$user->socid;
99  $sql .= " ORDER BY f.tms DESC";
100  $sql .= $this->db->plimit($max, 0);
101 
102  dol_syslog(get_class($this).'::loadBox', LOG_DEBUG);
103  $resql = $this->db->query($sql);
104  if ($resql)
105  {
106  $num = $this->db->num_rows($resql);
107  $now = dol_now();
108 
109  $i = 0;
110 
111  while ($i < $num)
112  {
113  $objp = $this->db->fetch_object($resql);
114  $datec = $this->db->jdate($objp->datec);
115 
116  $ficheinterstatic->statut = $objp->status;
117  $ficheinterstatic->status = $objp->status;
118  $ficheinterstatic->id = $objp->rowid;
119  $ficheinterstatic->ref = $objp->ref;
120 
121  $thirdpartystatic->id = $objp->socid;
122  $thirdpartystatic->name = $objp->name;
123  //$thirdpartystatic->name_alias = $objp->name_alias;
124  $thirdpartystatic->code_client = $objp->code_client;
125  $thirdpartystatic->code_compta = $objp->code_compta;
126  $thirdpartystatic->client = $objp->client;
127  $thirdpartystatic->logo = $objp->logo;
128  $thirdpartystatic->email = $objp->email;
129  $thirdpartystatic->entity = $objp->entity;
130 
131  $this->info_box_contents[$i][] = array(
132  'td' => 'class="nowraponall"',
133  'text' => $ficheinterstatic->getNomUrl(1),
134  'asis' => 1,
135  );
136 
137  $this->info_box_contents[$i][] = array(
138  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
139  'text' => $thirdpartystatic->getNomUrl(1),
140  'asis' => 1,
141  );
142 
143  $this->info_box_contents[$i][] = array(
144  'td' => 'class="right"',
145  'text' => dol_print_date($datec, 'day'),
146  );
147 
148  $this->info_box_contents[$i][] = array(
149  'td' => 'class="nowrap right"',
150  'text' => $ficheinterstatic->getLibStatut(3),
151  'asis' => 1,
152  );
153 
154  $i++;
155  }
156 
157  if ($num == 0) $this->info_box_contents[$i][0] = array(
158  'td' => 'class="center opacitymedium"',
159  'text'=>$langs->trans("NoRecordedInterventions")
160  );
161 
162  $this->db->free($resql);
163  } else {
164  $this->info_box_contents[0][0] = array(
165  'td' => '',
166  'maxlength'=>500,
167  'text' => ($this->db->error().' sql='.$sql),
168  );
169  }
170  } else {
171  $this->info_box_contents[0][0] = array(
172  'td' => 'class="nohover opacitymedium left"',
173  'text' => $langs->trans("ReadPermissionNotAllowed")
174  );
175  }
176  }
177 
186  public function showBox($head = null, $contents = null, $nooutput = 0)
187  {
188  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
189  }
190 }
Class to manage interventions.
dol_now($mode= 'auto')
Return date for now.
Class ModeleBoxes.
$conf db
API class for accounts.
Definition: inc.php:54
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
__construct($db, $param)
Constructor.
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
loadBox($max=10)
Load data for box to show them later.
Class to manage the box to show last interventions.