dolibarr/htdocs/core/boxes/box_ficheinter.php

196 lines
5.6 KiB
PHP
Raw Normal View History

<?php
2017-11-02 17:58:46 +01:00
/* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2015 Frederic France <frederic.france@free.fr>
*
2015-01-25 01:20:58 +01:00
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2015-01-25 01:20:58 +01:00
*/
/**
2013-08-22 16:49:23 +02:00
* \file htdocs/core/boxes/box_ficheinter.php
* \ingroup ficheinter
2013-08-22 16:49:23 +02:00
* \brief Box to show last interventions
*/
include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
/**
2013-08-22 16:49:23 +02:00
* Class to manage the box to show last interventions
*/
class box_ficheinter extends ModeleBoxes
{
public $boxcode = "ficheinter";
public $boximg = "object_intervention";
public $boxlabel = "BoxFicheInter";
public $depends = array("ficheinter"); // conf->contrat->enabled
2018-08-22 10:51:55 +02:00
/**
* @var DoliDB Database handler.
*/
public $db;
2019-02-09 15:24:21 +01:00
public $param;
public $info_box_head = array();
public $info_box_contents = array();
2017-06-12 14:09:00 +02:00
/**
* Constructor
*
* @param DoliDB $db Database handler
* @param string $param More parameters
*/
2019-02-28 20:48:07 +01:00
public function __construct($db, $param)
2017-06-12 14:09:00 +02:00
{
global $user;
2017-06-12 14:09:00 +02:00
$this->db = $db;
2017-06-12 14:09:00 +02:00
$this->hidden = !($user->rights->ficheinter->lire);
2017-06-12 14:09:00 +02:00
}
/**
* Load data for box to show them later
*
* @param int $max Maximum number of records to load
* @return void
*/
2019-02-28 20:48:07 +01:00
public function loadBox($max = 10)
{
2019-09-23 18:13:26 +02:00
global $user, $langs, $conf;
2013-06-08 00:52:02 +02:00
$this->max = $max;
include_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
$ficheinterstatic = new Fichinter($this->db);
2020-12-08 09:55:07 +01:00
$thirdpartystatic = new Societe($this->db);
2013-06-08 00:52:02 +02:00
$this->info_box_head = array('text' => $langs->trans("BoxTitleLastFicheInter", $max));
2021-02-23 22:03:23 +01:00
if (!empty($user->rights->ficheinter->lire)) {
2021-02-27 19:43:56 +01:00
$sql = "SELECT f.rowid, f.ref, f.fk_soc, f.fk_statut as status";
2020-12-08 09:55:07 +01:00
$sql .= ", f.datec";
$sql .= ", f.date_valid as datev";
$sql .= ", f.tms as datem";
$sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
$sql .= ", s.code_client, s.code_compta, s.client";
$sql .= ", s.logo, s.email, s.entity";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
2021-10-22 22:15:59 +02:00
if (empty($user->rights->societe->client->voir)) {
2021-02-23 22:03:23 +01:00
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= ", ".MAIN_DB_PREFIX."fichinter as f";
$sql .= " WHERE f.fk_soc = s.rowid ";
$sql .= " AND f.entity = ".$conf->entity;
2021-10-22 22:15:59 +02:00
if (empty($user->rights->societe->client->voir) && !$user->socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
2021-02-23 22:03:23 +01:00
}
if ($user->socid) {
$sql .= " AND s.rowid = ".((int) $user->socid);
2021-02-23 22:03:23 +01:00
}
$sql .= " ORDER BY f.tms DESC";
$sql .= $this->db->plimit($max, 0);
2014-06-13 01:34:39 +02:00
dol_syslog(get_class($this).'::loadBox', LOG_DEBUG);
2019-09-23 18:13:26 +02:00
$resql = $this->db->query($sql);
2021-02-23 22:03:23 +01:00
if ($resql) {
2019-09-23 18:13:26 +02:00
$num = $this->db->num_rows($resql);
$now = dol_now();
$i = 0;
2021-02-23 22:03:23 +01:00
while ($i < $num) {
2019-09-23 18:13:26 +02:00
$objp = $this->db->fetch_object($resql);
$datec = $this->db->jdate($objp->datec);
2021-02-27 19:43:56 +01:00
$ficheinterstatic->statut = $objp->status;
$ficheinterstatic->status = $objp->status;
$ficheinterstatic->id = $objp->rowid;
$ficheinterstatic->ref = $objp->ref;
2013-06-08 00:52:02 +02:00
2020-12-08 09:55:07 +01:00
$thirdpartystatic->id = $objp->socid;
$thirdpartystatic->name = $objp->name;
//$thirdpartystatic->name_alias = $objp->name_alias;
$thirdpartystatic->code_client = $objp->code_client;
$thirdpartystatic->code_compta = $objp->code_compta;
$thirdpartystatic->client = $objp->client;
$thirdpartystatic->logo = $objp->logo;
$thirdpartystatic->email = $objp->email;
$thirdpartystatic->entity = $objp->entity;
2019-09-23 18:13:26 +02:00
2019-02-09 15:24:21 +01:00
$this->info_box_contents[$i][] = array(
'td' => 'class="nowraponall"',
'text' => $ficheinterstatic->getNomUrl(1),
'asis' => 1,
2017-11-11 00:28:00 +01:00
);
2019-02-09 15:24:21 +01:00
$this->info_box_contents[$i][] = array(
2021-06-20 16:35:49 +02:00
'td' => 'class="tdoverflowmax150"',
2020-12-08 09:55:07 +01:00
'text' => $thirdpartystatic->getNomUrl(1),
'asis' => 1,
);
2019-02-09 15:24:21 +01:00
$this->info_box_contents[$i][] = array(
'td' => 'class="right"',
2021-05-25 00:29:32 +02:00
'text' => dol_print_date($datec, 'day', 'tzuserrel'),
);
2019-02-09 15:24:21 +01:00
$this->info_box_contents[$i][] = array(
'td' => 'class="nowrap right"',
'text' => $ficheinterstatic->getLibStatut(3),
'asis' => 1,
);
$i++;
}
2021-02-23 22:03:23 +01:00
if ($num == 0) {
$this->info_box_contents[$i][0] = array(
2020-05-14 14:56:15 +02:00
'td' => 'class="center opacitymedium"',
'text'=>$langs->trans("NoRecordedInterventions")
2021-02-23 22:03:23 +01:00
);
}
2013-06-08 00:52:02 +02:00
2019-09-23 18:13:26 +02:00
$this->db->free($resql);
2020-05-21 15:05:19 +02:00
} else {
2020-05-14 14:56:15 +02:00
$this->info_box_contents[0][0] = array(
'td' => '',
'maxlength'=>500,
'text' => ($this->db->error().' sql='.$sql),
);
}
2020-05-21 15:05:19 +02:00
} else {
2020-05-14 14:56:15 +02:00
$this->info_box_contents[0][0] = array(
'td' => 'class="nohover opacitymedium left"',
'text' => $langs->trans("ReadPermissionNotAllowed")
);
}
}
/**
* Method to show box
*
* @param array $head Array with properties of box title
* @param array $contents Array with properties of box lines
2016-06-27 13:57:10 +02:00
* @param int $nooutput No print, only return string
2017-06-12 14:09:00 +02:00
* @return string
*/
public function showBox($head = null, $contents = null, $nooutput = 0)
{
2017-06-12 14:09:00 +02:00
return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
}
}