|
@@ -3,6 +3,7 @@
|
|
|
* Copyright (C) 2016 Christophe Battarel <christophe@altairis.fr>
|
|
|
* Copyright (C) 2019-2023 Frédéric France <frederic.france@netlogic.fr>
|
|
|
* Copyright (C) 2020 Laurent Destailleur <eldy@users.sourceforge.net>
|
|
|
+ * Copyright (C) 2023 Charlene Benke <charlene@patas-monkey.com>
|
|
|
*
|
|
|
* 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
|
|
@@ -35,6 +36,12 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php';
|
|
|
*/
|
|
|
class Ticket extends CommonObject
|
|
|
{
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var db connector
|
|
|
+ */
|
|
|
+ public $db;
|
|
|
+
|
|
|
/**
|
|
|
* @var string ID to identify managed object
|
|
|
*/
|
|
@@ -324,6 +331,7 @@ class Ticket extends CommonObject
|
|
|
'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'visible'=>1, 'enabled'=>'isModEnabled("societe")', 'position'=>50, 'notnull'=>-1, 'index'=>1, 'searchall'=>1, 'help'=>"OrganizationEventLinkToThirdParty", 'css'=>'tdoverflowmax150 maxwidth150onsmartphone'),
|
|
|
'notify_tiers_at_create' => array('type'=>'integer', 'label'=>'NotifyThirdparty', 'visible'=>-1, 'enabled'=>0, 'position'=>51, 'notnull'=>1, 'index'=>1),
|
|
|
'fk_project' => array('type'=>'integer:Project:projet/class/project.class.php', 'label'=>'Project', 'visible'=>-1, 'enabled'=>'$conf->project->enabled', 'position'=>52, 'notnull'=>-1, 'index'=>1, 'help'=>"LinkToProject"),
|
|
|
+ 'fk_contract' => array('type'=>'integer:Contrat:contrat/class/contrat.class.php', 'label'=>'Contract', 'visible'=>-1, 'enabled'=>'$conf->contract->enabled', 'position'=>53, 'notnull'=>-1, 'index'=>1, 'help'=>"LinkToContract"),
|
|
|
//'timing' => array('type'=>'varchar(20)', 'label'=>'Timing', 'visible'=>-1, 'enabled'=>1, 'position'=>42, 'notnull'=>-1, 'help'=>""), // what is this ?
|
|
|
'datec' => array('type'=>'datetime', 'label'=>'DateCreation', 'visible'=>1, 'enabled'=>1, 'position'=>500, 'notnull'=>1, 'csslist'=>'nowraponall'),
|
|
|
'date_read' => array('type'=>'datetime', 'label'=>'TicketReadOn', 'visible'=>-1, 'enabled'=>1, 'position'=>501, 'notnull'=>1),
|
|
@@ -498,6 +506,7 @@ class Ticket extends CommonObject
|
|
|
$sql .= "track_id,";
|
|
|
$sql .= "fk_soc,";
|
|
|
$sql .= "fk_project,";
|
|
|
+ $sql .= "fk_contract,";
|
|
|
$sql .= "origin_email,";
|
|
|
$sql .= "fk_user_create,";
|
|
|
$sql .= "fk_user_assign,";
|
|
@@ -523,6 +532,7 @@ class Ticket extends CommonObject
|
|
|
$sql .= " ".(!isset($this->track_id) ? 'NULL' : "'".$this->db->escape($this->track_id)."'").",";
|
|
|
$sql .= " ".($this->fk_soc > 0 ? $this->db->escape($this->fk_soc) : "null").",";
|
|
|
$sql .= " ".($this->fk_project > 0 ? $this->db->escape($this->fk_project) : "null").",";
|
|
|
+ $sql .= " ".($this->fk_contract > 0 ? $this->db->escape($this->fk_contract) : "null").",";
|
|
|
$sql .= " ".(!isset($this->origin_email) ? 'NULL' : "'".$this->db->escape($this->origin_email)."'").",";
|
|
|
$sql .= " ".(!isset($this->fk_user_create) ? ($user->id > 0 ? $user->id : 'NULL') : ($this->fk_user_create > 0 ? $this->fk_user_create : 'NULL')).",";
|
|
|
$sql .= " ".($this->fk_user_assign > 0 ? $this->fk_user_assign : 'NULL').",";
|
|
@@ -635,6 +645,7 @@ class Ticket extends CommonObject
|
|
|
$sql .= " t.track_id,";
|
|
|
$sql .= " t.fk_soc,";
|
|
|
$sql .= " t.fk_project,";
|
|
|
+ $sql .= " t.fk_contract,";
|
|
|
$sql .= " t.origin_email,";
|
|
|
$sql .= " t.fk_user_create,";
|
|
|
$sql .= " t.fk_user_assign,";
|
|
@@ -687,6 +698,7 @@ class Ticket extends CommonObject
|
|
|
$this->fk_soc = $obj->fk_soc;
|
|
|
$this->socid = $obj->fk_soc; // for fetch_thirdparty() method
|
|
|
$this->fk_project = $obj->fk_project;
|
|
|
+ $this->fk_contract = $obj->fk_contract;
|
|
|
$this->origin_email = $obj->origin_email;
|
|
|
$this->fk_user_create = $obj->fk_user_create;
|
|
|
$this->fk_user_assign = $obj->fk_user_assign;
|
|
@@ -763,6 +775,7 @@ class Ticket extends CommonObject
|
|
|
$sql .= " t.track_id,";
|
|
|
$sql .= " t.fk_soc,";
|
|
|
$sql .= " t.fk_project,";
|
|
|
+ $sql .= " t.fk_contract,";
|
|
|
$sql .= " t.origin_email,";
|
|
|
$sql .= " t.fk_user_create, uc.lastname as user_create_lastname, uc.firstname as user_create_firstname,";
|
|
|
$sql .= " t.fk_user_assign, ua.lastname as user_assign_lastname, ua.firstname as user_assign_firstname,";
|
|
@@ -782,8 +795,10 @@ class Ticket extends CommonObject
|
|
|
$sql .= " t.tms";
|
|
|
$sql .= ", type.label as type_label, category.label as category_label, severity.label as severity_label";
|
|
|
// Add fields for extrafields
|
|
|
- foreach ($extrafields->attributes[$this->table_element]['label'] as $key => $val) {
|
|
|
- $sql .= ($extrafields->attributes[$this->table_element]['type'][$key] != 'separate' ? ",ef.".$key." as options_".$key : '');
|
|
|
+ if ($extrafields->attributes[$this->table_element]['count']> 0) {
|
|
|
+ foreach ($extrafields->attributes[$this->table_element]['label'] as $key => $val) {
|
|
|
+ $sql .= ($extrafields->attributes[$this->table_element]['type'][$key] != 'separate' ? ",ef.".$key." as options_".$key : '');
|
|
|
+ }
|
|
|
}
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
|
|
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_type as type ON type.code=t.type_code";
|
|
@@ -792,8 +807,10 @@ class Ticket extends CommonObject
|
|
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid=t.fk_soc";
|
|
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as uc ON uc.rowid=t.fk_user_create";
|
|
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as ua ON ua.rowid=t.fk_user_assign";
|
|
|
- if (is_array($extrafields->attributes[$this->table_element]['label']) && count($extrafields->attributes[$this->table_element]['label'])) {
|
|
|
- $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."ticket_extrafields as ef on (t.rowid = ef.fk_object)";
|
|
|
+ if ($extrafields->attributes[$this->table_element]['count']> 0) {
|
|
|
+ if (is_array($extrafields->attributes[$this->table_element]['label']) && count($extrafields->attributes[$this->table_element]['label'])) {
|
|
|
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."ticket_extrafields as ef on (t.rowid = ef.fk_object)";
|
|
|
+ }
|
|
|
}
|
|
|
if (empty($user->rights->societe->client->voir) && !$user->socid) {
|
|
|
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
|
@@ -814,6 +831,8 @@ class Ticket extends CommonObject
|
|
|
} else {
|
|
|
$sql .= " AND ".$key.' = '.((int) $value);
|
|
|
}
|
|
|
+ } elseif ($key == 't.fk_contract') {
|
|
|
+ $sql .= " AND ".$key.' = '.((int) $value);
|
|
|
} else {
|
|
|
$sql .= " AND ".$key." LIKE '%".$this->db->escape($value)."%'";
|
|
|
}
|
|
@@ -851,6 +870,7 @@ class Ticket extends CommonObject
|
|
|
$line->track_id = $obj->track_id;
|
|
|
$line->fk_soc = $obj->fk_soc;
|
|
|
$line->fk_project = $obj->fk_project;
|
|
|
+ $line->fk_contract = $obj->fk_contract;
|
|
|
$line->origin_email = $obj->origin_email;
|
|
|
|
|
|
$line->fk_user_create = $obj->fk_user_create;
|
|
@@ -881,13 +901,14 @@ class Ticket extends CommonObject
|
|
|
$line->date_close = $this->db->jdate($obj->date_close);
|
|
|
|
|
|
// Extra fields
|
|
|
- if (is_array($extrafields->attributes[$this->table_element]['label']) && count($extrafields->attributes[$this->table_element]['label'])) {
|
|
|
- foreach ($extrafields->attributes[$this->table_element]['label'] as $key => $val) {
|
|
|
- $tmpkey = 'options_'.$key;
|
|
|
- $line->{$tmpkey} = $obj->$tmpkey;
|
|
|
+ if ($extrafields->attributes[$this->table_element]['count']> 0) {
|
|
|
+ if (is_array($extrafields->attributes[$this->table_element]['label']) && count($extrafields->attributes[$this->table_element]['label'])) {
|
|
|
+ foreach ($extrafields->attributes[$this->table_element]['label'] as $key => $val) {
|
|
|
+ $tmpkey = 'options_'.$key;
|
|
|
+ $line->{$tmpkey} = $obj->$tmpkey;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
$this->lines[$i] = $line;
|
|
|
$i++;
|
|
|
}
|
|
@@ -934,6 +955,10 @@ class Ticket extends CommonObject
|
|
|
$this->fk_project = (int) $this->fk_project;
|
|
|
}
|
|
|
|
|
|
+ if (isset($this->fk_contract)) {
|
|
|
+ $this->fk_contract = (int) $this->fk_contract;
|
|
|
+ }
|
|
|
+
|
|
|
if (isset($this->origin_email)) {
|
|
|
$this->origin_email = trim($this->origin_email);
|
|
|
}
|
|
@@ -995,6 +1020,7 @@ class Ticket extends CommonObject
|
|
|
$sql .= " track_id=".(isset($this->track_id) ? "'".$this->db->escape($this->track_id)."'" : "null").",";
|
|
|
$sql .= " fk_soc=".(isset($this->fk_soc) ? "'".$this->db->escape($this->fk_soc)."'" : "null").",";
|
|
|
$sql .= " fk_project=".(isset($this->fk_project) ? "'".$this->db->escape($this->fk_project)."'" : "null").",";
|
|
|
+ $sql .= " fk_contract=".(isset($this->fk_contract) ? "'".$this->db->escape($this->fk_contract)."'" : "null").",";
|
|
|
$sql .= " origin_email=".(isset($this->origin_email) ? "'".$this->db->escape($this->origin_email)."'" : "null").",";
|
|
|
$sql .= " fk_user_create=".(isset($this->fk_user_create) ? $this->fk_user_create : "null").",";
|
|
|
$sql .= " fk_user_assign=".(isset($this->fk_user_assign) ? $this->fk_user_assign : "null").",";
|
|
@@ -2048,17 +2074,19 @@ class Ticket extends CommonObject
|
|
|
*/
|
|
|
public function setContract($contractid)
|
|
|
{
|
|
|
- if (!$this->table_element) {
|
|
|
- dol_syslog(get_class($this)."::setContract was called on objet with property table_element not defined", LOG_ERR);
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
- $result = $this->add_object_linked('contrat', $contractid);
|
|
|
- if ($result) {
|
|
|
- $this->fk_contract = $contractid;
|
|
|
- return 1;
|
|
|
+ if ($this->id) {
|
|
|
+ $sql = "UPDATE ".MAIN_DB_PREFIX."ticket";
|
|
|
+ $sql .= " SET fk_contract = ".($contractid > 0 ? $contractid : "null");
|
|
|
+ $sql .= " WHERE rowid = ".((int) $this->id);
|
|
|
+ dol_syslog(get_class($this).'::setContract sql='.$sql);
|
|
|
+ $resql = $this->db->query($sql);
|
|
|
+ print $sql;
|
|
|
+ if ($resql) {
|
|
|
+ return 1;
|
|
|
+ } else {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
} else {
|
|
|
- dol_print_error($this->db);
|
|
|
return -1;
|
|
|
}
|
|
|
}
|