From 14a043a3097c6b098a585807274176dfb6d5c43f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charl=C3=A8ne=20Benke?= <1179011+defrance@users.noreply.github.com> Date: Fri, 4 Aug 2023 10:35:32 +0200 Subject: [PATCH 01/15] add contract field --- htdocs/ticket/card.php | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/htdocs/ticket/card.php b/htdocs/ticket/card.php index 043ef502092..af4eef06909 100755 --- a/htdocs/ticket/card.php +++ b/htdocs/ticket/card.php @@ -805,7 +805,7 @@ if ($action == 'create' || $action == 'presend') { print ''; */ } elseif (empty($action) || $action == 'view' || $action == 'addlink' || $action == 'dellink' || $action == 'presend' || $action == 'presend_addmessage' || $action == 'close' || $action == 'abandon' || $action == 'delete' || $action == 'editcustomer' || $action == 'progression' || $action == 'categories' || $action == 'reopen' - || $action == 'editsubject' || $action == 'edit_extras' || $action == 'update_extras' || $action == 'edit_extrafields' || $action == 'set_extrafields' || $action == 'classify' || $action == 'sel_contract' || $action == 'edit_message_init' || $action == 'set_status' || $action == 'dellink') { + || $action== 'contrat' || $action == 'editsubject' || $action == 'edit_extras' || $action == 'update_extras' || $action == 'edit_extrafields' || $action == 'set_extrafields' || $action == 'classify' || $action == 'sel_contract' || $action == 'edit_message_init' || $action == 'set_status' || $action == 'dellink') { if ($res > 0) { // or for unauthorized internals users if (!$user->socid && (!empty($conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY) && $object->fk_user_assign != $user->id) && !$user->rights->ticket->manage) { @@ -1000,6 +1000,33 @@ if ($action == 'create' || $action == 'presend') { } } + // Contract + if (isModEnabled('contrat')) { + $langs->load('contracts'); + $morehtmlref .= '
'; + + $morehtmlref .= $langs->trans('Contract'); + + if ($action != 'contrat') { + $morehtmlref .= 'id.'">'; + $morehtmlref .= img_edit($langs->trans('SetContract'), 1); + $morehtmlref .= ''; + } + if ($action == 'contrat') { + $formcontract = new Formcontract($db); + $morehtmlref .= $formcontract->formSelectContract($_SERVER["PHP_SELF"].'?id='.$object->id, $object->socid, $object->fk_contract, 'contratid', 0, 1, 1,1); + } else { + if ($object->fk_contract) { + $contratstatic = new Contrat($db); + $contratstatic->fetch($object->fk_contract); + //print ''.$projet->title.''; + $morehtmlref .= $contratstatic->getNomUrl(0, '', 1); + } else { + $morehtmlref .= " "; + } + } + } + $morehtmlref .= ''; $linkback = ''.$langs->trans("BackToList").' '; From 8d370554c3412aace0fc6d3f0b71c75241f6260d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charl=C3=A8ne=20Benke?= <1179011+defrance@users.noreply.github.com> Date: Fri, 4 Aug 2023 10:36:46 +0200 Subject: [PATCH 02/15] add contract field on utl --- htdocs/ticket/list.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/htdocs/ticket/list.php b/htdocs/ticket/list.php index f1bd192fcd8..27e7ca09d3f 100644 --- a/htdocs/ticket/list.php +++ b/htdocs/ticket/list.php @@ -681,6 +681,9 @@ if ($search_societe) { if ($projectid > 0) { $param .= '&projectid='.urlencode($projectid); } +if ($contractid > 0) { + $param .= '&contractid='.urlencode($contractid); +} if ($search_date_start) { $tmparray = dol_getdate($search_date_start); $param .= '&search_date_startday='.urlencode($tmparray['mday']); From 357df19d534f1b3de799701e10ae5eb7e3ee4086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charl=C3=A8ne=20Benke?= <1179011+defrance@users.noreply.github.com> Date: Fri, 4 Aug 2023 10:40:02 +0200 Subject: [PATCH 03/15] Update ticket.class.php --- htdocs/ticket/class/ticket.class.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index 1ed2a82ad60..94da313a3db 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -3,6 +3,7 @@ * Copyright (C) 2016 Christophe Battarel * Copyright (C) 2019-2023 Frédéric France * Copyright (C) 2020 Laurent Destailleur + * Copyright (C) 2023 Charlene Benke * * 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 @@ -81,6 +82,11 @@ class Ticket extends CommonObject */ public $fk_project; + /** + * @var int Contract ID + */ + public $fk_contract; + /** * @var string Person email who have create ticket */ @@ -308,6 +314,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), @@ -482,6 +489,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,"; @@ -507,6 +515,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').","; @@ -925,7 +934,11 @@ class Ticket extends CommonObject if (isset($this->fk_project)) { $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); } @@ -987,6 +1000,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").","; From 65d48d10f117a36ef2cb3f63ba2834ac858736dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charl=C3=A8ne=20Benke?= <1179011+defrance@users.noreply.github.com> Date: Fri, 4 Aug 2023 14:44:04 +0200 Subject: [PATCH 04/15] add getTicketsArray function --- htdocs/contrat/class/contrat.class.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 7db2cf5546b..a91c83ec393 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -2486,6 +2486,23 @@ class Contrat extends CommonObject return $this->fetch_lines(); } + /** + * Create an array of associated tickets + * + * @return int >0 if OK, <0 if KO + */ + + public function getTicketsArray() + { + global $user; + + $ticket = new Ticket($this->db); + + $nbTicket = $ticket->fetchAll($user, 'ASC', 't.datec', '', 0, '', array('t.fk_contract' => $this->id)); + $this->tickets = $ticket->lines; + return $nbTicket; + } + /** * Create a document onto disk according to template module. From ffc76242452e5b2fa3fc5eabf87016610d14fccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charl=C3=A8ne=20Benke?= <1179011+defrance@users.noreply.github.com> Date: Fri, 4 Aug 2023 14:50:31 +0200 Subject: [PATCH 05/15] Update ticket.class.php for link to contract --- htdocs/ticket/class/ticket.class.php | 57 ++++++++++++++++++---------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index 94da313a3db..0029dcdc454 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -36,6 +36,12 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php'; */ class Ticket extends CommonObject { + + /** + * @var db connector + */ + public $bd; + /** * @var string ID to identify managed object */ @@ -628,6 +634,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,"; @@ -680,6 +687,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; @@ -759,6 +767,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,"; @@ -778,8 +787,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"; @@ -788,8 +799,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"; @@ -810,6 +823,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)."%'"; } @@ -847,6 +862,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 +897,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++; } @@ -2054,17 +2071,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; } } From 55ee3dc0a235bc5c5a92eb33bd94247d29ca6b29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charl=C3=A8ne=20Benke?= <1179011+defrance@users.noreply.github.com> Date: Fri, 4 Aug 2023 14:52:01 +0200 Subject: [PATCH 06/15] Create ticket.php --- htdocs/contrat/ticket.php | 197 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100644 htdocs/contrat/ticket.php diff --git a/htdocs/contrat/ticket.php b/htdocs/contrat/ticket.php new file mode 100644 index 00000000000..519739e5343 --- /dev/null +++ b/htdocs/contrat/ticket.php @@ -0,0 +1,197 @@ + + * + * 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 + * along with this program. If not, see . + */ + +/** + * \file management/contrat/ticket.php + * \ingroup contrat + * \brief Page of associated ticket + */ + + +$res=0; +if (! $res && file_exists("../../main.inc.php")) + $res=@include("../../main.inc.php"); // For root directory +if (! $res && file_exists("../../../main.inc.php")) + $res=@include("../../../main.inc.php"); // For "custom" directory + +require_once DOL_DOCUMENT_ROOT.'/core/lib/contract.lib.php'; +require_once DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php"; +require_once DOL_DOCUMENT_ROOT."/contact/class/contact.class.php"; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; +require_once DOL_DOCUMENT_ROOT."/ticket/class/ticket.class.php"; + +$langs->load("contracts"); +$langs->load("tickets"); + +$socid=GETPOST('socid', 'int'); +$id=GETPOST('id', 'int'); +$ref=GETPOST('ref', 'alpha'); +$action=GETPOST('action', 'alpha'); + +if ($id == '' && $ref == '') { + dol_print_error('', 'Bad parameter'); + exit; +} + +// Security check +$socid=0; +if ($user->socid > 0) + $socid=$user->socid; + +$result=restrictedArea($user, 'contrat', $id); + + +/* + * View + */ + +llxHeader("", $langs->trans("Tickets"), "Contrat"); + +$form = new Form($db); + +$userstatic=new User($db); + +$object = new Contrat($db); + + +$object= new Contrat($db); +$result=$object->fetch($id, $ref); +$ret=$object->fetch_thirdparty(); +$head = contract_prepare_head($object); + + +dol_fiche_head($head, 'ticket', $langs->trans("Contract"), -1, 'contract'); + +$linkback = ''; +$linkback.= $langs->trans("BackToList").''; + +$morehtmlref=''; +$morehtmlref.=$object->ref; + +$morehtmlref.='
'; +// Ref customer +$morehtmlref.=$form->editfieldkey( + "RefCustomer", 'ref_customer', $object->ref_customer, + $object, 0, 'string', '', 0, 1 +); +$morehtmlref.=$form->editfieldval( + "RefCustomer", 'ref_customer', $object->ref_customer, + $object, 0, 'string', '', null, null, '', 1 +); +// Ref supplier +$morehtmlref.='
'; +$morehtmlref.=$form->editfieldkey( + "RefSupplier", 'ref_supplier', $object->ref_supplier, + $object, 0, 'string', '', 0, 1 +); +$morehtmlref.=$form->editfieldval( + "RefSupplier", 'ref_supplier', $object->ref_supplier, + $object, 0, 'string', '', null, null, '', 1 +); +// Thirdparty +$morehtmlref.='
'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1); +// Project +if (! empty($conf->projet->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php'; + + $langs->load("projects"); + $morehtmlref.='
'.$langs->trans('Project') . ' : '; + if (! empty($object->fk_project)) { + $proj = new Project($db); + $proj->fetch($object->fk_project); + $morehtmlref.=''; + $morehtmlref.=$proj->ref; + $morehtmlref.=''; + } else { + $morehtmlref.=''; + } +} +$morehtmlref.='
'; + +dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'none', $morehtmlref); + +print '
'; + + +/* + * Referers types + */ + +$title=$langs->trans("ListTicketsLinkToContract"); + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + // on récupère la totalité des tickets liés au contrat + $allticketarray = $object->getTicketsArray(); + if ($allticketarray >0) { + //var_dump($object->tickets); + foreach ($object->tickets as $key => $value) { + $total_ht = 0; + $total_ttc = 0; + $num=count($object->tickets); + + for ($i = 0; $i < $num; $i++) { + $element = new Ticket($db); + $element->fetch($value->rowid); + + print ""; + + // Ref + print '\n"; + + // Informaitons + print ''; + print ''; + print ''; + print ''; + + // Date + print ''; + print ''; + + // Durée + print ''; + + // Status + print ''; + print ''; + + } + print "
'.$langs->trans("Ref").''.$langs->trans("Subject").''.$langs->trans("Type").''.$langs->trans("TicketCategory").''.$langs->trans("Severity").''.$langs->trans("Date").''.$langs->trans("DateEnd").''.$langs->trans("Progress").''.$langs->trans("Status").'
'; + print $element->getNomUrl(1); + print "'.$value->subject.''.$value->type_label.''.$value->category_label.''.$value->severity_label.''.dol_print_date($element->datec, 'day').''.dol_print_date($element->date_close, 'day').''; + print (isset($element->progress)?$element->progress:' '). '%'; + print ''.$element->getLibStatut(5).'
"; + + } + } + + +llxFooter(); +$db->close(); From 3281db874322f9e416e293a36d32ab11154f0513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charl=C3=A8ne=20Benke?= <1179011+defrance@users.noreply.github.com> Date: Fri, 4 Aug 2023 14:54:57 +0200 Subject: [PATCH 07/15] Update ticket.php --- htdocs/contrat/ticket.php | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/htdocs/contrat/ticket.php b/htdocs/contrat/ticket.php index 519739e5343..d0dc2b368c3 100644 --- a/htdocs/contrat/ticket.php +++ b/htdocs/contrat/ticket.php @@ -1,5 +1,7 @@ +/* Copyright (C) 2004 Rodolphe Quiedeville + * Copyright (C) 2004-2016 Laurent Destailleur + * Copyright (C) 2012-2023 Charlene BENKE * * 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 @@ -16,27 +18,24 @@ */ /** - * \file management/contrat/ticket.php - * \ingroup contrat - * \brief Page of associated ticket + * \file htdocs/contrat/ticket.php + * \ingroup contrat + * \brief Page of associated ticket */ -$res=0; -if (! $res && file_exists("../../main.inc.php")) - $res=@include("../../main.inc.php"); // For root directory -if (! $res && file_exists("../../../main.inc.php")) - $res=@include("../../../main.inc.php"); // For "custom" directory - +require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/contract.lib.php'; -require_once DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php"; -require_once DOL_DOCUMENT_ROOT."/contact/class/contact.class.php"; +require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php'; +if (isModEnabled('project')) { + require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; +} + require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT."/ticket/class/ticket.class.php"; -$langs->load("contracts"); -$langs->load("tickets"); +$langs->loadLangs(array('companies', 'contracts', 'tickets')); $socid=GETPOST('socid', 'int'); $id=GETPOST('id', 'int'); @@ -63,12 +62,8 @@ $result=restrictedArea($user, 'contrat', $id); llxHeader("", $langs->trans("Tickets"), "Contrat"); $form = new Form($db); - $userstatic=new User($db); -$object = new Contrat($db); - - $object= new Contrat($db); $result=$object->fetch($id, $ref); $ret=$object->fetch_thirdparty(); From 37b13d97b568436993ef1c0f8b75a17a928ebabe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charl=C3=A8ne=20Benke?= <1179011+defrance@users.noreply.github.com> Date: Fri, 4 Aug 2023 15:01:21 +0200 Subject: [PATCH 08/15] Update contract.lib.php --- htdocs/core/lib/contract.lib.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/htdocs/core/lib/contract.lib.php b/htdocs/core/lib/contract.lib.php index 75ffdbf9a7c..e1780914ed4 100644 --- a/htdocs/core/lib/contract.lib.php +++ b/htdocs/core/lib/contract.lib.php @@ -1,6 +1,7 @@ * Copyright (C) 2009-2012 Regis Houssin + * Copyright (C) 2023 Charlene BENKE * * 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 @@ -51,6 +52,13 @@ function contract_prepare_head(Contrat $object) $h++; } + if (isModEnabled('ticket')) { + $head[$h][0] = DOL_URL_ROOT.'/contrat/ticket.php?id='.$object->id; + $head[$h][1] = $langs->trans("Tickets"); + $head[$h][2] = 'ticket'; + $h++; + } + // Show more tabs from modules // Entries must be declared in modules descriptor with line // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab From 311d41a6b305c37c69d74d4474d5b8d6fe34ab99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charl=C3=A8ne=20Benke?= <1179011+defrance@users.noreply.github.com> Date: Fri, 4 Aug 2023 15:42:25 +0200 Subject: [PATCH 09/15] Update card.php --- htdocs/ticket/card.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/ticket/card.php b/htdocs/ticket/card.php index af4eef06909..d03ecf4b902 100755 --- a/htdocs/ticket/card.php +++ b/htdocs/ticket/card.php @@ -240,6 +240,7 @@ if (empty($reshook)) { } $object->fk_project = $projectid; + $object->fk_contract = GETPOST('fk_contract','int'); $id = $object->create($user); if ($id <= 0) { From 8539fa5cfa8d5e55e1207c13581b9871873f6040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charl=C3=A8ne=20Benke?= <1179011+defrance@users.noreply.github.com> Date: Fri, 4 Aug 2023 15:44:23 +0200 Subject: [PATCH 10/15] Update html.formticket.class.php --- htdocs/core/class/html.formticket.class.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/htdocs/core/class/html.formticket.class.php b/htdocs/core/class/html.formticket.class.php index e395166fd1d..8ab549c3690 100644 --- a/htdocs/core/class/html.formticket.class.php +++ b/htdocs/core/class/html.formticket.class.php @@ -4,6 +4,7 @@ * Copyright (C) 2019-2022 Frédéric France * Copyright (C) 2021 Juanjo Menent * Copyright (C) 2021 Alexandre Spangaro + * Copyright (C) 2023 Charlene Benke * * 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 @@ -650,6 +651,16 @@ class FormTicket print ''; } } + + if ($subelement != 'contract') { + if (isModEnabled('contract') && !$this->ispublic) { + $formcontract = new FormContract($this->db); + print ''; + print img_picto('', 'contract'); + print $formcontract->select_contract(-1, GETPOST('contactid', 'int'), 'contractid', 0, 1, 1); + print ''; + } + } // Other attributes $parameters = array(); From 6ce2b54a3a49a9a8e47a378dd1a38adfabd2ffbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charl=C3=A8ne=20Benke?= <1179011+defrance@users.noreply.github.com> Date: Wed, 9 Aug 2023 18:01:02 +0200 Subject: [PATCH 11/15] Asked change made --- htdocs/ticket/card.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/htdocs/ticket/card.php b/htdocs/ticket/card.php index d03ecf4b902..134ef391e6a 100755 --- a/htdocs/ticket/card.php +++ b/htdocs/ticket/card.php @@ -4,7 +4,7 @@ * Copyright (C) 2018 Laurent Destailleur * Copyright (C) 2021 Frédéric France * Copyright (C) 2021 Alexandre Spangaro - * Copyright (C) 2022 Charlene Benke + * Copyright (C) 2022-2023 Charlene Benke * Copyright (C) 2023 Benjamin Falière * * This program is free software; you can redistribute it and/or modify @@ -806,7 +806,7 @@ if ($action == 'create' || $action == 'presend') { print ''; */ } elseif (empty($action) || $action == 'view' || $action == 'addlink' || $action == 'dellink' || $action == 'presend' || $action == 'presend_addmessage' || $action == 'close' || $action == 'abandon' || $action == 'delete' || $action == 'editcustomer' || $action == 'progression' || $action == 'categories' || $action == 'reopen' - || $action== 'contrat' || $action == 'editsubject' || $action == 'edit_extras' || $action == 'update_extras' || $action == 'edit_extrafields' || $action == 'set_extrafields' || $action == 'classify' || $action == 'sel_contract' || $action == 'edit_message_init' || $action == 'set_status' || $action == 'dellink') { + || $action== 'edit_contrat' || $action == 'editsubject' || $action == 'edit_extras' || $action == 'update_extras' || $action == 'edit_extrafields' || $action == 'set_extrafields' || $action == 'classify' || $action == 'sel_contract' || $action == 'edit_message_init' || $action == 'set_status' || $action == 'dellink') { if ($res > 0) { // or for unauthorized internals users if (!$user->socid && (!empty($conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY) && $object->fk_user_assign != $user->id) && !$user->rights->ticket->manage) { @@ -1005,15 +1005,14 @@ if ($action == 'create' || $action == 'presend') { if (isModEnabled('contrat')) { $langs->load('contracts'); $morehtmlref .= '
'; - $morehtmlref .= $langs->trans('Contract'); - if ($action != 'contrat') { - $morehtmlref .= 'id.'">'; + if ($action != 'edit_contrat') { + $morehtmlref .= 'id.'">'; $morehtmlref .= img_edit($langs->trans('SetContract'), 1); $morehtmlref .= ''; } - if ($action == 'contrat') { + if ($action == 'edit_contrat') { $formcontract = new Formcontract($db); $morehtmlref .= $formcontract->formSelectContract($_SERVER["PHP_SELF"].'?id='.$object->id, $object->socid, $object->fk_contract, 'contratid', 0, 1, 1,1); } else { From 637e9788efdc2f1e3242d3cde9399831ee9a1760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charl=C3=A8ne=20Benke?= <1179011+defrance@users.noreply.github.com> Date: Fri, 11 Aug 2023 09:00:51 +0200 Subject: [PATCH 12/15] Update ticket.class.php dislexic time sorry --- htdocs/ticket/class/ticket.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index ca4c9357752..eb6a61ed152 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -40,7 +40,7 @@ class Ticket extends CommonObject /** * @var db connector */ - public $bd; + public $db; /** * @var string ID to identify managed object From a5a68cfe0a8307207321edd626b0c6ddc8316015 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 11 Aug 2023 11:24:23 +0200 Subject: [PATCH 13/15] Update contrat.class.php --- htdocs/contrat/class/contrat.class.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index f8f2bff9de0..ceb4eb39ade 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -2495,18 +2495,16 @@ class Contrat extends CommonObject /** * Create an array of associated tickets * - * @return int >0 if OK, <0 if KO + * @return array|int Array o tickets or <0 if KO */ - public function getTicketsArray() { global $user; $ticket = new Ticket($this->db); - $nbTicket = $ticket->fetchAll($user, 'ASC', 't.datec', '', 0, '', array('t.fk_contract' => $this->id)); - $this->tickets = $ticket->lines; - return $nbTicket; + + return ($nbTicket < 0 ? $nbTicket : $ticket->lines); } From 6275926f4bc3a01fd2a20a9003545a4542aa748e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 11 Aug 2023 11:26:21 +0200 Subject: [PATCH 14/15] Update ticket.php --- htdocs/contrat/ticket.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/htdocs/contrat/ticket.php b/htdocs/contrat/ticket.php index d0dc2b368c3..af61a385a9b 100644 --- a/htdocs/contrat/ticket.php +++ b/htdocs/contrat/ticket.php @@ -144,12 +144,11 @@ $title=$langs->trans("ListTicketsLinkToContract"); print ''; // on récupère la totalité des tickets liés au contrat $allticketarray = $object->getTicketsArray(); - if ($allticketarray >0) { - //var_dump($object->tickets); - foreach ($object->tickets as $key => $value) { + if (is_array($allticketarray) && count($allticketarray) > 0) { + foreach ($allticketarray as $key => $value) { $total_ht = 0; $total_ttc = 0; - $num=count($object->tickets); + $num = count($allticketarray); for ($i = 0; $i < $num; $i++) { $element = new Ticket($db); From a15f317a4fe06ffdb54c32355a6e7c068a835f2c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 11 Aug 2023 11:46:31 +0200 Subject: [PATCH 15/15] Update ticket.php --- htdocs/contrat/ticket.php | 88 ++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 47 deletions(-) diff --git a/htdocs/contrat/ticket.php b/htdocs/contrat/ticket.php index af61a385a9b..f2ed7bdce4f 100644 --- a/htdocs/contrat/ticket.php +++ b/htdocs/contrat/ticket.php @@ -130,61 +130,55 @@ print '
'; $title=$langs->trans("ListTicketsLinkToContract"); - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - // on récupère la totalité des tickets liés au contrat - $allticketarray = $object->getTicketsArray(); - if (is_array($allticketarray) && count($allticketarray) > 0) { - foreach ($allticketarray as $key => $value) { - $total_ht = 0; - $total_ttc = 0; - $num = count($allticketarray); - - for ($i = 0; $i < $num; $i++) { - $element = new Ticket($db); - $element->fetch($value->rowid); +print '
'.$langs->trans("Ref").''.$langs->trans("Subject").''.$langs->trans("Type").''.$langs->trans("TicketCategory").''.$langs->trans("Severity").''.$langs->trans("Date").''.$langs->trans("DateEnd").''.$langs->trans("Progress").''.$langs->trans("Status").'
'; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +// on récupère la totalité des tickets liés au contrat +$allticketarray = $object->getTicketsArray(); +if (is_array($allticketarray) && count($allticketarray) > 0) { + foreach ($allticketarray as $key => $value) { + $total_ht = 0; + $total_ttc = 0; - print ""; + $element = $value; - // Ref - print '\n"; + print ""; - // Informaitons - print ''; - print ''; - print ''; - print ''; + // Ref + print '\n"; - // Date - print ''; - print ''; + // Information + print ''; + print ''; + print ''; + print ''; - // Durée - print ''; + // Date + print ''; + print ''; - // Status - print ''; - print ''; + // Duration + print ''; - } - print "
'.$langs->trans("Ref").''.$langs->trans("Subject").''.$langs->trans("Type").''.$langs->trans("TicketCategory").''.$langs->trans("Severity").''.$langs->trans("Date").''.$langs->trans("DateEnd").''.$langs->trans("Progress").''.$langs->trans("Status").'
'; - print $element->getNomUrl(1); - print "
'.$value->subject.''.$value->type_label.''.$value->category_label.''.$value->severity_label.''; + print $element->getNomUrl(1); + print "'.dol_print_date($element->datec, 'day').''.dol_print_date($element->date_close, 'day').''.$value->subject.''.$value->type_label.''.$value->category_label.''.$value->severity_label.''; - print (isset($element->progress)?$element->progress:' '). '%'; - print ''.dol_print_date($element->datec, 'day').''.dol_print_date($element->date_close, 'day').''.$element->getLibStatut(5).'
'; + print (isset($element->progress) ? $element->progress.'%' : ''); + print '
"; - - } + // Status + print ''.$element->getLibStatut(5).''; + print ''; } +} +print ""; llxFooter();