2004-10-19 22:35:36 +02:00
|
|
|
<?php
|
2012-03-16 16:01:45 +01:00
|
|
|
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
|
|
|
|
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
2018-10-27 14:43:12 +02:00
|
|
|
* Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
|
2013-04-09 17:18:07 +02:00
|
|
|
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
|
2024-02-29 15:26:53 +01:00
|
|
|
* Copyright (C) 2019-2024 Frédéric France <frederic.france@free.fr>
|
2024-08-07 01:20:43 +02:00
|
|
|
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
|
2010-01-15 00:21:22 +01:00
|
|
|
*
|
2003-09-02 19:41:30 +02: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
|
2013-01-16 15:36:08 +01:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-09-02 19:41:30 +02:00
|
|
|
* (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/>.
|
2003-09-02 19:41:30 +02:00
|
|
|
*/
|
|
|
|
|
|
2006-11-11 02:50:38 +01:00
|
|
|
/**
|
2010-04-25 14:55:26 +02:00
|
|
|
* \file htdocs/compta/deplacement/class/deplacement.class.php
|
2009-12-10 14:08:19 +01:00
|
|
|
* \ingroup deplacement
|
2011-05-25 20:16:58 +02:00
|
|
|
* \brief File of class to manage trips
|
2009-12-10 14:08:19 +01:00
|
|
|
*/
|
2006-11-11 02:50:38 +01:00
|
|
|
|
2020-04-10 10:59:32 +02:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
|
2008-05-26 01:46:19 +02:00
|
|
|
|
|
|
|
|
/**
|
2014-01-05 16:19:25 +01:00
|
|
|
* Class to manage trips and working credit notes
|
2009-12-10 14:08:19 +01:00
|
|
|
*/
|
2008-05-26 01:46:19 +02:00
|
|
|
class Deplacement extends CommonObject
|
2003-09-02 19:41:30 +02:00
|
|
|
{
|
2018-08-23 17:07:27 +02:00
|
|
|
/**
|
|
|
|
|
* @var string ID to identify managed object
|
|
|
|
|
*/
|
2020-04-10 10:59:32 +02:00
|
|
|
public $element = 'deplacement';
|
2018-09-02 13:38:11 +02:00
|
|
|
|
2018-08-22 18:34:50 +02:00
|
|
|
/**
|
|
|
|
|
* @var string Name of table without prefix where object is stored
|
|
|
|
|
*/
|
2020-04-10 10:59:32 +02:00
|
|
|
public $table_element = 'deplacement';
|
2018-09-02 13:38:11 +02:00
|
|
|
|
2018-09-02 11:08:41 +02:00
|
|
|
/**
|
2020-12-05 23:53:55 +01:00
|
|
|
* @var string Name of subtable line
|
2018-09-02 11:08:41 +02:00
|
|
|
*/
|
2011-09-20 19:19:46 +02:00
|
|
|
public $table_element_line = '';
|
2018-09-01 15:13:59 +02:00
|
|
|
|
|
|
|
|
/**
|
2020-12-05 23:53:55 +01:00
|
|
|
* @var string Fieldname with ID of parent key if this field has a parent
|
2018-09-01 15:13:59 +02:00
|
|
|
*/
|
2011-09-20 19:19:46 +02:00
|
|
|
public $fk_element = '';
|
2018-09-01 15:13:59 +02:00
|
|
|
|
2024-10-25 21:00:02 +02:00
|
|
|
/**
|
|
|
|
|
* @var int
|
|
|
|
|
*/
|
2023-08-06 12:39:16 +02:00
|
|
|
public $fk_soc;
|
2024-10-25 21:00:02 +02:00
|
|
|
/**
|
|
|
|
|
* @var int|string
|
|
|
|
|
*/
|
2023-08-06 12:39:16 +02:00
|
|
|
public $date;
|
2024-10-25 21:00:02 +02:00
|
|
|
/**
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2023-08-06 12:39:16 +02:00
|
|
|
public $type;
|
|
|
|
|
|
2019-03-21 15:01:09 +01:00
|
|
|
/**
|
2020-10-31 14:32:18 +01:00
|
|
|
* Date creation record (datec)
|
|
|
|
|
*
|
|
|
|
|
* @var integer
|
|
|
|
|
*/
|
|
|
|
|
public $datec;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Date (dated)
|
|
|
|
|
*
|
|
|
|
|
* @var integer
|
|
|
|
|
*/
|
2018-09-02 11:08:41 +02:00
|
|
|
public $dated;
|
2018-10-09 15:38:42 +02:00
|
|
|
|
|
|
|
|
/**
|
2020-10-31 14:32:18 +01:00
|
|
|
* @var int ID
|
|
|
|
|
*/
|
2018-09-02 11:08:41 +02:00
|
|
|
public $fk_user_author;
|
2018-08-31 18:06:17 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var int User ID
|
|
|
|
|
*/
|
|
|
|
|
public $fk_user;
|
|
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
/**
|
2024-02-28 16:20:06 +01:00
|
|
|
* @var float km value formatted
|
2020-10-31 14:32:18 +01:00
|
|
|
*/
|
|
|
|
|
public $km;
|
2019-12-08 22:37:19 +01:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
/**
|
|
|
|
|
* @var int Thirdparty id
|
|
|
|
|
*/
|
2018-09-02 11:08:41 +02:00
|
|
|
public $socid;
|
2019-12-08 22:37:19 +01:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
/**
|
|
|
|
|
* @var int Status 0=draft, 1=validated, 2=Refunded
|
|
|
|
|
*/
|
|
|
|
|
public $statut;
|
2024-09-12 21:16:42 +02:00
|
|
|
/**
|
|
|
|
|
* @var array<string,string> (Encoded as JSON in database)
|
|
|
|
|
*/
|
2020-04-10 10:59:32 +02:00
|
|
|
public $extraparams = array();
|
2010-01-15 00:21:22 +01:00
|
|
|
|
2012-07-09 10:08:56 +02:00
|
|
|
|
2019-12-08 22:46:22 +01:00
|
|
|
/**
|
|
|
|
|
* Draft status
|
|
|
|
|
*/
|
|
|
|
|
const STATUS_DRAFT = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Validated status
|
|
|
|
|
*/
|
|
|
|
|
const STATUS_VALIDATED = 1;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Refunded status
|
|
|
|
|
*/
|
|
|
|
|
const STATUS_REFUNDED = 2;
|
|
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
/**
|
2019-10-26 14:42:25 +02:00
|
|
|
* Constructor
|
|
|
|
|
*
|
|
|
|
|
* @param DoliDB $db Database handler
|
|
|
|
|
*/
|
2022-05-18 11:00:43 +02:00
|
|
|
public function __construct(DoliDB $db)
|
2003-09-02 19:41:30 +02:00
|
|
|
{
|
2011-10-20 14:23:39 +02:00
|
|
|
$this->db = $db;
|
2024-05-05 00:34:19 +02:00
|
|
|
|
|
|
|
|
$this->ismultientitymanaged = 0;
|
2003-09-02 19:41:30 +02:00
|
|
|
}
|
2006-11-11 02:50:38 +01:00
|
|
|
|
2008-05-26 01:46:19 +02:00
|
|
|
/**
|
|
|
|
|
* Create object in database
|
2010-10-28 00:41:40 +02:00
|
|
|
* TODO Add ref number
|
2011-10-20 14:23:39 +02:00
|
|
|
*
|
|
|
|
|
* @param User $user User that creates
|
2023-12-01 19:51:32 +01:00
|
|
|
* @return int Return integer <0 if KO, >0 if OK
|
2008-05-26 01:46:19 +02:00
|
|
|
*/
|
2019-02-25 23:15:48 +01:00
|
|
|
public function create($user)
|
2003-09-02 19:41:30 +02:00
|
|
|
{
|
2009-12-10 14:08:19 +01:00
|
|
|
global $conf;
|
2010-01-15 00:21:22 +01:00
|
|
|
|
2008-05-26 01:46:19 +02:00
|
|
|
// Check parameters
|
2021-02-23 21:09:01 +01:00
|
|
|
if (empty($this->type) || $this->type < 0) {
|
2020-04-10 10:59:32 +02:00
|
|
|
$this->error = 'ErrorBadParameter';
|
2008-05-26 01:46:19 +02:00
|
|
|
return -1;
|
|
|
|
|
}
|
2021-02-23 21:09:01 +01:00
|
|
|
if (empty($this->fk_user) || $this->fk_user < 0) {
|
2020-04-10 10:59:32 +02:00
|
|
|
$this->error = 'ErrorBadParameter';
|
2008-05-26 02:03:51 +02:00
|
|
|
return -1;
|
|
|
|
|
}
|
2010-01-15 00:21:22 +01:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
$now = dol_now();
|
2011-05-25 20:16:58 +02:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
$this->db->begin();
|
2010-01-15 00:21:22 +01:00
|
|
|
|
2009-12-10 14:08:19 +01:00
|
|
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."deplacement (";
|
2020-04-10 10:59:32 +02:00
|
|
|
$sql .= "datec";
|
2011-05-25 20:16:58 +02:00
|
|
|
//$sql.= ", dated";
|
2020-04-10 10:59:32 +02:00
|
|
|
$sql .= ", entity";
|
|
|
|
|
$sql .= ", fk_user_author";
|
|
|
|
|
$sql .= ", fk_user";
|
|
|
|
|
$sql .= ", type";
|
|
|
|
|
$sql .= ", note_private";
|
|
|
|
|
$sql .= ", note_public";
|
|
|
|
|
$sql .= ", fk_projet";
|
|
|
|
|
$sql .= ", fk_soc";
|
|
|
|
|
$sql .= ") VALUES (";
|
|
|
|
|
$sql .= " '".$this->db->idate($now)."'";
|
2021-09-03 21:25:17 +02:00
|
|
|
$sql .= ", ".((int) $conf->entity);
|
|
|
|
|
$sql .= ", ".((int) $user->id);
|
|
|
|
|
$sql .= ", ".((int) $this->fk_user);
|
2020-04-10 10:59:32 +02:00
|
|
|
$sql .= ", '".$this->db->escape($this->type)."'";
|
|
|
|
|
$sql .= ", ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null");
|
|
|
|
|
$sql .= ", ".($this->note_public ? "'".$this->db->escape($this->note_public)."'" : "null");
|
2021-09-03 21:25:17 +02:00
|
|
|
$sql .= ", ".($this->fk_project > 0 ? ((int) $this->fk_project) : 0);
|
|
|
|
|
$sql .= ", ".($this->fk_soc > 0 ? ((int) $this->fk_soc) : "null");
|
2020-04-10 10:59:32 +02:00
|
|
|
$sql .= ")";
|
2006-11-11 02:50:38 +01:00
|
|
|
|
2014-06-12 11:31:53 +02:00
|
|
|
dol_syslog(get_class($this)."::create", LOG_DEBUG);
|
2006-11-11 02:50:38 +01:00
|
|
|
$result = $this->db->query($sql);
|
2021-02-23 21:09:01 +01:00
|
|
|
if ($result) {
|
2006-11-11 02:50:38 +01:00
|
|
|
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."deplacement");
|
Add: hooks and triggers for a lot of core modules (action/calendrier, deplacement, dons, tva, contact/tiers, contrat, product lines, expedition, fournisseur commandes et factures, fiche intervention, projet et taches)
Signed-off-by: Stephen L. <lrq3000@gmail.com>
2012-08-14 15:50:45 +02:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
// Call trigger
|
|
|
|
|
$result = $this->call_trigger('DEPLACEMENT_CREATE', $user);
|
2021-02-23 21:09:01 +01:00
|
|
|
if ($result < 0) {
|
2020-10-31 14:32:18 +01:00
|
|
|
$this->db->rollback();
|
|
|
|
|
return -2;
|
|
|
|
|
}
|
|
|
|
|
// End call triggers
|
2014-09-06 17:16:24 +02:00
|
|
|
|
2020-04-10 10:59:32 +02:00
|
|
|
$result = $this->update($user);
|
2021-02-23 21:09:01 +01:00
|
|
|
if ($result > 0) {
|
2006-11-11 02:50:38 +01:00
|
|
|
$this->db->commit();
|
|
|
|
|
return $this->id;
|
2020-05-21 15:05:19 +02:00
|
|
|
} else {
|
2020-04-10 10:59:32 +02:00
|
|
|
$this->error = $this->db->error();
|
2006-11-11 02:50:38 +01:00
|
|
|
$this->db->rollback();
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
2020-05-21 15:05:19 +02:00
|
|
|
} else {
|
2020-04-10 10:59:32 +02:00
|
|
|
$this->error = $this->db->error()." sql=".$sql;
|
2006-11-11 02:50:38 +01:00
|
|
|
$this->db->rollback();
|
2010-01-15 00:21:22 +01:00
|
|
|
return -1;
|
2006-11-11 02:50:38 +01:00
|
|
|
}
|
2003-09-02 19:41:30 +02:00
|
|
|
}
|
2006-11-11 02:50:38 +01:00
|
|
|
|
2008-11-15 22:18:40 +01:00
|
|
|
/**
|
2011-10-20 14:23:39 +02:00
|
|
|
* Update record
|
2010-01-15 00:21:22 +01:00
|
|
|
*
|
2011-10-20 14:23:39 +02:00
|
|
|
* @param User $user User making update
|
2023-12-01 19:51:32 +01:00
|
|
|
* @return int Return integer <0 if KO, >0 if OK
|
2008-11-15 22:18:40 +01:00
|
|
|
*/
|
2019-02-25 23:15:48 +01:00
|
|
|
public function update($user)
|
2003-09-02 19:41:30 +02:00
|
|
|
{
|
2008-11-11 21:23:44 +01:00
|
|
|
// Clean parameters
|
2024-02-29 15:26:53 +01:00
|
|
|
$this->km = (float) price2num($this->km);
|
2010-01-15 00:21:22 +01:00
|
|
|
|
2008-05-26 01:46:19 +02:00
|
|
|
// Check parameters
|
2021-02-23 21:09:01 +01:00
|
|
|
if (!is_numeric($this->km)) {
|
|
|
|
|
$this->km = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->date)) {
|
2020-10-31 14:32:18 +01:00
|
|
|
$this->error = 'ErrorBadParameter';
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2021-02-23 21:09:01 +01:00
|
|
|
if (empty($this->type) || $this->type < 0) {
|
2020-04-10 10:59:32 +02:00
|
|
|
$this->error = 'ErrorBadParameter';
|
2008-05-26 01:46:19 +02:00
|
|
|
return -1;
|
2006-11-11 02:50:38 +01:00
|
|
|
}
|
2021-02-23 21:09:01 +01:00
|
|
|
if (empty($this->fk_user) || $this->fk_user < 0) {
|
2020-04-10 10:59:32 +02:00
|
|
|
$this->error = 'ErrorBadParameter';
|
2008-05-26 02:03:51 +02:00
|
|
|
return -1;
|
|
|
|
|
}
|
2010-01-15 00:21:22 +01:00
|
|
|
|
2010-03-21 15:01:39 +01:00
|
|
|
$this->db->begin();
|
|
|
|
|
|
2006-11-11 02:50:38 +01:00
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."deplacement ";
|
2021-03-30 03:37:54 +02:00
|
|
|
$sql .= " SET km = ".((float) $this->km); // This is a distance or amount
|
2006-11-11 02:50:38 +01:00
|
|
|
$sql .= " , dated = '".$this->db->idate($this->date)."'";
|
2017-05-12 16:55:11 +02:00
|
|
|
$sql .= " , type = '".$this->db->escape($this->type)."'";
|
|
|
|
|
$sql .= " , fk_statut = '".$this->db->escape($this->statut)."'";
|
2021-03-30 03:37:54 +02:00
|
|
|
$sql .= " , fk_user = ".((int) $this->fk_user);
|
|
|
|
|
$sql .= " , fk_user_modif = ".((int) $user->id);
|
2020-04-10 10:59:32 +02:00
|
|
|
$sql .= " , fk_soc = ".($this->socid > 0 ? $this->socid : 'null');
|
|
|
|
|
$sql .= " , note_private = ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null");
|
|
|
|
|
$sql .= " , note_public = ".($this->note_public ? "'".$this->db->escape($this->note_public)."'" : "null");
|
|
|
|
|
$sql .= " , fk_projet = ".($this->fk_project > 0 ? $this->fk_project : 0);
|
2021-08-27 16:33:03 +02:00
|
|
|
$sql .= " WHERE rowid = ".((int) $this->id);
|
2006-11-11 02:50:38 +01:00
|
|
|
|
2014-06-12 11:31:53 +02:00
|
|
|
dol_syslog(get_class($this)."::update", LOG_DEBUG);
|
2006-11-11 02:50:38 +01:00
|
|
|
$result = $this->db->query($sql);
|
2021-02-23 21:09:01 +01:00
|
|
|
if ($result) {
|
2010-03-21 15:01:39 +01:00
|
|
|
$this->db->commit();
|
2006-11-11 02:50:38 +01:00
|
|
|
return 1;
|
2020-05-21 15:05:19 +02:00
|
|
|
} else {
|
2020-04-10 10:59:32 +02:00
|
|
|
$this->error = $this->db->lasterror();
|
2011-10-25 12:50:12 +02:00
|
|
|
$this->db->rollback();
|
2006-11-11 02:50:38 +01:00
|
|
|
return -1;
|
|
|
|
|
}
|
2003-09-02 19:41:30 +02:00
|
|
|
}
|
2006-11-11 02:50:38 +01:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
/**
|
2019-10-26 14:42:25 +02:00
|
|
|
* Load an object from database
|
|
|
|
|
*
|
|
|
|
|
* @param int $id Id of record to load
|
|
|
|
|
* @param string $ref Ref of record
|
2023-12-01 19:51:32 +01:00
|
|
|
* @return int Return integer <0 if KO, >0 if OK
|
2019-10-26 14:42:25 +02:00
|
|
|
*/
|
2019-02-25 23:15:48 +01:00
|
|
|
public function fetch($id, $ref = '')
|
2003-09-02 19:41:30 +02:00
|
|
|
{
|
2019-02-27 15:32:18 +01:00
|
|
|
$sql = "SELECT rowid, fk_user, type, fk_statut, km, fk_soc, dated, note_private, note_public, fk_projet as fk_project, extraparams";
|
2020-04-10 10:59:32 +02:00
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."deplacement";
|
|
|
|
|
$sql .= " WHERE entity IN (".getEntity('deplacement').")";
|
2021-02-23 21:09:01 +01:00
|
|
|
if ($ref) {
|
|
|
|
|
$sql .= " AND ref ='".$this->db->escape($ref)."'";
|
|
|
|
|
} else {
|
2021-03-14 11:48:39 +01:00
|
|
|
$sql .= " AND rowid = ".((int) $id);
|
2021-02-23 21:09:01 +01:00
|
|
|
}
|
2003-09-02 19:41:30 +02:00
|
|
|
|
2014-06-12 11:31:53 +02:00
|
|
|
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
|
2011-09-20 15:32:16 +02:00
|
|
|
$result = $this->db->query($sql);
|
2021-02-23 21:09:01 +01:00
|
|
|
if ($result) {
|
2008-05-26 01:46:19 +02:00
|
|
|
$obj = $this->db->fetch_object($result);
|
2006-11-11 02:50:38 +01:00
|
|
|
|
2020-04-10 10:59:32 +02:00
|
|
|
$this->id = $obj->rowid;
|
|
|
|
|
$this->ref = $obj->rowid;
|
2011-10-25 12:50:12 +02:00
|
|
|
$this->date = $this->db->jdate($obj->dated);
|
2020-04-10 10:59:32 +02:00
|
|
|
$this->fk_user = $obj->fk_user;
|
2011-10-25 12:50:12 +02:00
|
|
|
$this->socid = $obj->fk_soc;
|
2020-04-10 10:59:32 +02:00
|
|
|
$this->km = $obj->km;
|
2011-10-25 12:50:12 +02:00
|
|
|
$this->type = $obj->type;
|
2012-01-18 01:05:26 +01:00
|
|
|
$this->statut = $obj->fk_statut;
|
2020-04-10 10:59:32 +02:00
|
|
|
$this->note_private = $obj->note_private;
|
2011-10-25 12:50:12 +02:00
|
|
|
$this->note_public = $obj->note_public;
|
2019-02-27 15:32:18 +01:00
|
|
|
$this->fk_project = $obj->fk_project;
|
2012-07-09 10:08:56 +02:00
|
|
|
|
2012-03-18 19:59:38 +01:00
|
|
|
$this->extraparams = (array) json_decode($obj->extraparams, true);
|
2006-11-11 02:50:38 +01:00
|
|
|
|
|
|
|
|
return 1;
|
2020-05-21 15:05:19 +02:00
|
|
|
} else {
|
2020-04-10 10:59:32 +02:00
|
|
|
$this->error = $this->db->error();
|
2006-11-11 02:50:38 +01:00
|
|
|
return -1;
|
|
|
|
|
}
|
2003-09-02 19:41:30 +02:00
|
|
|
}
|
2006-11-11 02:50:38 +01:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
/**
|
2019-10-26 14:42:25 +02:00
|
|
|
* Delete record
|
|
|
|
|
*
|
2022-06-22 16:07:03 +02:00
|
|
|
* @param User $user USer that Delete
|
2023-12-01 19:51:32 +01:00
|
|
|
* @return int Return integer <0 if KO, >0 if OK
|
2019-10-26 14:42:25 +02:00
|
|
|
*/
|
2022-06-22 16:07:03 +02:00
|
|
|
public function delete($user)
|
2003-09-02 19:41:30 +02:00
|
|
|
{
|
2011-10-25 12:50:12 +02:00
|
|
|
$this->db->begin();
|
2012-01-18 01:05:26 +01:00
|
|
|
|
2022-06-22 16:07:03 +02:00
|
|
|
$id = $this->id;
|
|
|
|
|
|
2021-03-14 11:48:39 +01:00
|
|
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."deplacement WHERE rowid = ".((int) $id);
|
2006-11-11 02:50:38 +01:00
|
|
|
|
2014-06-12 11:31:53 +02:00
|
|
|
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
|
2006-11-11 02:50:38 +01:00
|
|
|
$result = $this->db->query($sql);
|
2021-02-23 21:09:01 +01:00
|
|
|
if ($result) {
|
2011-10-25 12:50:12 +02:00
|
|
|
$this->db->commit();
|
2006-11-11 02:50:38 +01:00
|
|
|
return 1;
|
2020-05-21 15:05:19 +02:00
|
|
|
} else {
|
2020-04-10 10:59:32 +02:00
|
|
|
$this->error = $this->db->error();
|
2011-10-25 12:50:12 +02:00
|
|
|
$this->db->rollback();
|
2006-11-11 02:50:38 +01:00
|
|
|
return -1;
|
|
|
|
|
}
|
2003-09-02 19:41:30 +02:00
|
|
|
}
|
|
|
|
|
|
2010-03-21 15:01:39 +01:00
|
|
|
|
|
|
|
|
/**
|
2023-04-08 15:08:55 +02:00
|
|
|
* Return the label of the status
|
2011-10-20 14:23:39 +02:00
|
|
|
*
|
2023-04-08 15:08:55 +02:00
|
|
|
* @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
|
|
|
|
|
* @return string Label of status
|
2010-03-21 15:01:39 +01:00
|
|
|
*/
|
2019-02-25 23:15:48 +01:00
|
|
|
public function getLibStatut($mode = 0)
|
2010-03-21 15:01:39 +01:00
|
|
|
{
|
2019-01-27 11:55:16 +01:00
|
|
|
return $this->LibStatut($this->statut, $mode);
|
2010-03-21 15:01:39 +01:00
|
|
|
}
|
|
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
2010-03-21 15:01:39 +01:00
|
|
|
/**
|
2023-04-08 15:08:55 +02:00
|
|
|
* Return the label of a given status
|
2011-10-20 14:23:39 +02:00
|
|
|
*
|
2023-04-08 15:08:55 +02:00
|
|
|
* @param int $status Id status
|
|
|
|
|
* @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
|
|
|
|
|
* @return string Label of status
|
2010-03-21 15:01:39 +01:00
|
|
|
*/
|
2019-11-01 23:58:14 +01:00
|
|
|
public function LibStatut($status, $mode = 0)
|
2010-03-21 15:01:39 +01:00
|
|
|
{
|
2020-10-31 14:32:18 +01:00
|
|
|
// phpcs:enable
|
2010-03-21 15:01:39 +01:00
|
|
|
global $langs;
|
|
|
|
|
|
2023-09-01 00:02:16 +02:00
|
|
|
if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
|
|
|
|
|
global $langs;
|
|
|
|
|
//$langs->load("mymodule@mymodule");
|
|
|
|
|
$this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
|
|
|
|
|
$this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
|
|
|
|
|
$this->labelStatus[self::STATUS_REFUNDED] = $langs->transnoentitiesnoconv('Refunded');
|
|
|
|
|
$this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
|
|
|
|
|
$this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
|
|
|
|
|
$this->labelStatusShort[self::STATUS_REFUNDED] = $langs->transnoentitiesnoconv('Refunded');
|
|
|
|
|
}
|
2022-07-26 10:54:03 +02:00
|
|
|
|
2024-08-07 01:20:43 +02:00
|
|
|
$status_logo = array(0 => 'status0', 1 => 'status4', 2 => 'status1', 4 => 'status6', 5 => 'status4', 6 => 'status6', 99 => 'status5');
|
2023-09-01 00:02:16 +02:00
|
|
|
$statusType = $status_logo[$status];
|
2022-07-26 10:54:03 +02:00
|
|
|
|
2023-09-01 00:02:16 +02:00
|
|
|
return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
|
2010-03-21 15:01:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-08-07 01:20:43 +02:00
|
|
|
* Return clickable name (with picto eventually)
|
2011-10-20 14:23:39 +02:00
|
|
|
*
|
2015-03-15 14:04:07 +01:00
|
|
|
* @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto
|
2011-10-20 14:23:39 +02:00
|
|
|
* @return string Chaine avec URL
|
2010-03-21 15:01:39 +01:00
|
|
|
*/
|
2019-02-25 23:15:48 +01:00
|
|
|
public function getNomUrl($withpicto = 0)
|
2010-03-21 15:01:39 +01:00
|
|
|
{
|
|
|
|
|
global $langs;
|
|
|
|
|
|
2020-04-10 10:59:32 +02:00
|
|
|
$result = '';
|
2020-10-31 14:32:18 +01:00
|
|
|
$label = $langs->trans("Show").': '.$this->ref;
|
2010-03-21 15:01:39 +01:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
$link = '<a href="'.DOL_URL_ROOT.'/compta/deplacement/card.php?id='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
|
2020-04-10 10:59:32 +02:00
|
|
|
$linkend = '</a>';
|
2010-03-21 15:01:39 +01:00
|
|
|
|
2020-04-10 10:59:32 +02:00
|
|
|
$picto = 'trip';
|
2010-03-21 15:01:39 +01:00
|
|
|
|
|
|
|
|
|
2021-02-23 21:09:01 +01:00
|
|
|
if ($withpicto) {
|
|
|
|
|
$result .= ($link.img_object($label, $picto, 'class="classfortooltip"').$linkend);
|
|
|
|
|
}
|
|
|
|
|
if ($withpicto && $withpicto != 2) {
|
|
|
|
|
$result .= ' ';
|
|
|
|
|
}
|
|
|
|
|
if ($withpicto != 2) {
|
|
|
|
|
$result .= $link.$this->ref.$linkend;
|
|
|
|
|
}
|
2010-03-21 15:01:39 +01:00
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-29 19:55:32 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* List of types
|
2011-10-20 14:23:39 +02:00
|
|
|
*
|
|
|
|
|
* @param int $active Active or not
|
2024-10-25 21:00:02 +02:00
|
|
|
* @return array<string,string>
|
2011-06-29 19:55:32 +02:00
|
|
|
*/
|
2019-02-25 23:15:48 +01:00
|
|
|
public function listOfTypes($active = 1)
|
2011-06-29 19:55:32 +02:00
|
|
|
{
|
2020-10-31 14:32:18 +01:00
|
|
|
global $langs;
|
|
|
|
|
|
|
|
|
|
$ret = array();
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT id, code, label";
|
|
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."c_type_fees";
|
2021-03-30 17:53:25 +02:00
|
|
|
$sql .= " WHERE active = ".((int) $active);
|
2020-10-31 14:32:18 +01:00
|
|
|
|
|
|
|
|
dol_syslog(get_class($this)."::listOfTypes", LOG_DEBUG);
|
|
|
|
|
$result = $this->db->query($sql);
|
2021-02-23 21:09:01 +01:00
|
|
|
if ($result) {
|
2020-10-31 14:32:18 +01:00
|
|
|
$num = $this->db->num_rows($result);
|
|
|
|
|
$i = 0;
|
2021-02-23 21:09:01 +01:00
|
|
|
while ($i < $num) {
|
2020-10-31 14:32:18 +01:00
|
|
|
$obj = $this->db->fetch_object($result);
|
|
|
|
|
$ret[$obj->code] = (($langs->trans($obj->code) != $obj->code) ? $langs->trans($obj->code) : $obj->label);
|
|
|
|
|
$i++;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
dol_print_error($this->db);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $ret;
|
2011-06-29 19:55:32 +02:00
|
|
|
}
|
2011-10-20 14:23:39 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Information on record
|
|
|
|
|
*
|
|
|
|
|
* @param int $id Id of record
|
|
|
|
|
* @return void
|
2011-10-19 22:17:39 +02:00
|
|
|
*/
|
2019-02-25 23:15:48 +01:00
|
|
|
public function info($id)
|
2011-10-19 22:17:39 +02:00
|
|
|
{
|
|
|
|
|
$sql = 'SELECT c.rowid, c.datec, c.fk_user_author, c.fk_user_modif,';
|
2022-06-28 13:09:53 +02:00
|
|
|
$sql .= ' c.tms as datem';
|
2020-04-10 10:59:32 +02:00
|
|
|
$sql .= ' FROM '.MAIN_DB_PREFIX.'deplacement as c';
|
2021-03-14 11:48:39 +01:00
|
|
|
$sql .= ' WHERE c.rowid = '.((int) $id);
|
2011-10-19 22:17:39 +02:00
|
|
|
|
2014-06-13 01:34:39 +02:00
|
|
|
dol_syslog(get_class($this).'::info', LOG_DEBUG);
|
2011-10-19 22:17:39 +02:00
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
2021-02-23 21:09:01 +01:00
|
|
|
if ($result) {
|
|
|
|
|
if ($this->db->num_rows($result)) {
|
2011-10-19 22:17:39 +02:00
|
|
|
$obj = $this->db->fetch_object($result);
|
2023-10-24 11:37:29 +02:00
|
|
|
|
2011-10-19 22:17:39 +02:00
|
|
|
$this->id = $obj->rowid;
|
2022-06-28 13:09:53 +02:00
|
|
|
|
|
|
|
|
$this->user_creation_id = $obj->fk_user_author;
|
|
|
|
|
$this->user_modification_id = $obj->fk_user_modif;
|
2011-10-19 22:17:39 +02:00
|
|
|
$this->date_creation = $this->db->jdate($obj->datec);
|
2022-06-28 13:09:53 +02:00
|
|
|
$this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
|
2011-10-19 22:17:39 +02:00
|
|
|
}
|
|
|
|
|
$this->db->free($result);
|
2020-05-21 15:05:19 +02:00
|
|
|
} else {
|
2011-10-19 22:17:39 +02:00
|
|
|
dol_print_error($this->db);
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-09-02 19:41:30 +02:00
|
|
|
}
|