Ticket generate doc (#28031)

* add doc generation to tickets

* add doc generation to tickets

* add doc generation

* add doc generation

* add extraparams fetch

add extraparams fetch

fix call

fix call

fix call

* fix doc

* remove bad setting

* fix default settings on init

* fix template name

---------

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
Frédéric FRANCE 2024-02-07 19:36:23 +01:00 committed by GitHub
parent 92b9527ac0
commit 0972ba137d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 70 additions and 17 deletions

View File

@ -45,7 +45,7 @@ $action = GETPOST('action', 'aZ09');
$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
$label = GETPOST('label', 'alpha');
$scandir = GETPOST('scandir', 'alpha');
$scandir = GETPOST('scan_dir', 'alpha');
$type = 'ticket';
$error = 0;

View File

@ -501,7 +501,7 @@ abstract class CommonDocGenerator
* Define array with couple substitution key => substitution value
* Note that vars into substitutions array are formatted.
*
* @param Object $object Main object to use as data source
* @param CommonObject $object Main object to use as data source
* @param Translate $outputlangs Lang object to use for output
* @param string $array_key Name of the key for return array
* @return array Array of substitution
@ -515,6 +515,7 @@ abstract class CommonDocGenerator
$already_payed_all = 0;
if ($object->element == 'facture') {
/** @var Facture $object */
$invoice_source = new Facture($this->db);
if ($object->fk_facture_source > 0) {
$invoice_source->fetch($object->fk_facture_source);
@ -528,7 +529,7 @@ abstract class CommonDocGenerator
$date = (isset($object->element) && $object->element == 'contrat' && isset($object->date_contrat)) ? $object->date_contrat : (isset($object->date) ? $object->date : null);
if (get_class($object) == 'CommandeFournisseur') {
/* @var $object CommandeFournisseur*/
/** @var CommandeFournisseur $object*/
$object->date_validation = $object->date_valid;
$object->date_commande = $object->date;
}
@ -703,7 +704,7 @@ abstract class CommonDocGenerator
* Define array with couple substitution key => substitution value
* Note that vars into substitutions array are formatted.
*
* @param Object $line Object line
* @param CommonObjectLine $line Object line
* @param Translate $outputlangs Lang object to use for output
* @param int $linenumber The number of the line for the substitution of "object_line_pos"
* @return array Return a substitution array
@ -927,8 +928,6 @@ abstract class CommonDocGenerator
}
}
//var_dump($array_other);
return $array_other;
}

View File

@ -376,7 +376,7 @@ class modTicket extends DolibarrModules
//ODT template
$src = DOL_DOCUMENT_ROOT.'/install/doctemplates/tickets/template_ticket.odt';
$dirodt = DOL_DATA_ROOT.'/doctemplates/tickets';
$dest = $dirodt.'/template_order.odt';
$dest = $dirodt.'/template_ticket.odt';
if (file_exists($src) && !file_exists($dest)) {
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@ -394,8 +394,10 @@ class modTicket extends DolibarrModules
array("sql" => "insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (110121, 'ticket', 'internal', 'CONTRIBUTOR', 'Intervenant', 1);", "ignoreerror" => 1),
array("sql" => "insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (110122, 'ticket', 'external', 'SUPPORTCLI', 'Contact client suivi incident', 1);", "ignoreerror" => 1),
array("sql" => "insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (110123, 'ticket', 'external', 'CONTRIBUTOR', 'Intervenant', 1);", "ignoreerror" => 1),
// remove old settings
"DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = 'TICKET_ADDON_PDF_ODT_PATH' AND type = 'ticket' AND entity = ".((int) $conf->entity),
"INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('TICKET_ADDON_PDF_ODT_PATH','ticket',".((int) $conf->entity).")"
// activate default odt templates
array("sql" =>"INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, libelle, entity, description) VALUES('generic_ticket_odt','ticket','ODT templates',".((int) $conf->entity).",'TICKET_ADDON_PDF_ODT_PATH');", "ignoreerror" =>1),
);
return $this->_init($sql, $options);

View File

@ -322,7 +322,7 @@ class doc_generic_ticket_odt extends ModelePDFTicket
}
// Make substitutions into odt
$array_user = $this->get_substitutionarray_user($object, $outputlangs);
$array_user = $this->get_substitutionarray_user($user, $outputlangs);
$array_soc = $this->get_substitutionarray_mysoc($mysoc, $outputlangs);
$array_thirdparty = $this->get_substitutionarray_thirdparty($socobject, $outputlangs);
$array_other = $this->get_substitutionarray_other($outputlangs);

View File

@ -31,6 +31,7 @@
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/ticket/class/actions_ticket.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formticket.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
@ -707,7 +708,6 @@ if (empty($reshook)) {
// Actions to build doc
include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
//var_dump($action);exit;
// Actions to send emails
$triggersendname = 'TICKET_SENTBYMAIL';
@ -729,6 +729,7 @@ if (empty($reshook)) {
$userstat = new User($db);
$form = new Form($db);
$formfile = new FormFile($db);
$formticket = new FormTicket($db);
if (isModEnabled('project')) {
$formproject = new FormProjets($db);
@ -811,8 +812,7 @@ if ($action == 'create' || $action == 'presend') {
print $form->buttonsSaveCancel();
print '</form>'; */
} 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== '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') {
} elseif (empty($action) || in_array($action, ['builddoc', 'view', 'addlink', 'dellink', 'presend', 'presend_addmessage', 'close', 'abandon', 'delete', 'editcustomer', 'progression', 'categories', 'reopen', 'edit_contrat', 'editsubject', 'edit_extras', 'update_extras', 'edit_extrafields', 'set_extrafields', 'classify', 'sel_contract', 'edit_message_init', 'set_status', 'dellink'])) {
if ($res > 0) {
// or for unauthorized internals users
if (!$user->socid && (getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY') && $object->fk_user_assign != $user->id) && !$user->hasRight('ticket', 'manage')) {
@ -1613,6 +1613,16 @@ if ($action == 'create' || $action == 'presend') {
if ($action != 'presend' && $action != 'presend_addmessage' && $action != 'add_message') {
print '<div class="fichecenter"><div class="fichehalfleft">';
print '<a name="builddoc"></a>'; // ancre
/*
* Generated documents
*/
$filename = dol_sanitizeFileName($object->ref);
$filedir = $upload_dir."/".dol_sanitizeFileName($object->ref);
$urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
$genallowed = $permissiontoadd;
$delallowed = $permissiontodelete;
print $formfile->showdocuments('ticket', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', 0, '', $thirdparty->default_lang);
// Show links to link elements
$linktoelem = $form->showLinkToObjectBlock($object, null, array('ticket'));

View File

@ -344,7 +344,9 @@ class Ticket extends CommonObject
'email_date' => array('type'=>'datetime', 'label'=>'EmailDate', 'visible'=>-2, 'enabled'=>1, 'position'=>541),
'progress' => array('type'=>'integer', 'label'=>'Progression', 'visible'=>-1, 'enabled'=>1, 'position'=>540, 'notnull'=>-1, 'css'=>'right', 'help'=>"", 'isameasure'=>2, 'csslist'=>'width50'),
'resolution' => array('type'=>'integer', 'label'=>'Resolution', 'visible'=>-1, 'enabled'=>'getDolGlobalString("TICKET_ENABLE_RESOLUTION")', 'position'=>550, 'notnull'=>1),
'fk_statut' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'position'=>600, 'notnull'=>1, 'index'=>1, 'arrayofkeyval'=>array(0 => 'Unread', 1 => 'Read', 3 => 'Answered', 4 => 'Assigned', 5 => 'InProgress', 6 => 'Waiting', 8 => 'SolvedClosed', 9 => 'Deleted')),
'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'PDFTemplate', 'enabled'=>1, 'visible'=>0, 'position'=>560),
'extraparams' =>array('type'=>'varchar(255)', 'label'=>'Extraparams', 'enabled'=>1, 'visible'=>-1, 'position'=>570),
'fk_statut' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'position'=>600, 'notnull'=>1, 'index'=>1, 'arrayofkeyval'=>array(0 => 'Unread', 1 => 'Read', 3 => 'TicketAnswered', 4 => 'Assigned', 5 => 'InProgress', 6 => 'Waiting', 8 => 'SolvedClosed', 9 => 'Deleted')),
'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>900),
);
// END MODULEBUILDER PROPERTIES
@ -526,6 +528,7 @@ class Ticket extends CommonObject
$sql .= "date_close,";
$sql .= "entity,";
$sql .= "notify_tiers_at_create,";
$sql .= "model_pdf,";
$sql .= "ip";
$sql .= ") VALUES (";
$sql .= " ".(!isset($this->ref) ? '' : "'".$this->db->escape($this->ref)."'").",";
@ -552,6 +555,7 @@ class Ticket extends CommonObject
$sql .= " ".(!isset($this->date_close) || dol_strlen($this->date_close) == 0 ? 'NULL' : "'".$this->db->idate($this->date_close)."'");
$sql .= ", ".((int) $this->entity);
$sql .= ", ".(!isset($this->notify_tiers_at_create) ? '1' : "'".$this->db->escape($this->notify_tiers_at_create)."'");
$sql .= ", '".$this->db->escape($this->model_pdf)."'";
$sql .= ", ".(!isset($this->ip) ? 'NULL' : "'".$this->db->escape($this->ip)."'");
$sql .= ")";
@ -665,6 +669,8 @@ class Ticket extends CommonObject
$sql .= " t.date_last_msg_sent,";
$sql .= " t.date_close,";
$sql .= " t.tms,";
$sql .= " t.model_pdf,";
$sql .= " t.extraparams,";
$sql .= " t.ip,";
$sql .= " type.label as type_label, category.label as category_label, severity.label as severity_label";
$sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
@ -706,6 +712,8 @@ class Ticket extends CommonObject
$this->email_date = $this->db->jdate($obj->email_date);
$this->subject = $obj->subject;
$this->message = $obj->message;
$this->model_pdf = $obj->model_pdf;
$this->extraparams = !empty($obj->extraparams) ? (array) json_decode($obj->extraparams, true) : array();
$this->ip = $obj->ip;
$this->status = $obj->status;
@ -1022,7 +1030,9 @@ class Ticket extends CommonObject
if (isset($this->severity_code)) {
$this->timing = trim($this->severity_code);
}
if (isset($this->model_pdf)) {
$this->model_pdf = trim($this->model_pdf);
}
// Check parameters
// Put here code to add a control on parameters values
// Update request
@ -1047,6 +1057,7 @@ class Ticket extends CommonObject
$sql .= " datec=".(dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').",";
$sql .= " date_read=".(dol_strlen($this->date_read) != 0 ? "'".$this->db->idate($this->date_read)."'" : 'null').",";
$sql .= " date_last_msg_sent=".(dol_strlen($this->date_last_msg_sent) != 0 ? "'".$this->db->idate($this->date_last_msg_sent)."'" : 'null').",";
$sql .= " model_pdf=".(isset($this->model_pdf) ? "'".$this->db->escape($this->model_pdf)."'" : "null").",";
$sql .= " date_close=".(dol_strlen($this->date_close) != 0 ? "'".$this->db->idate($this->date_close)."'" : 'null');
$sql .= " WHERE rowid=".((int) $this->id);
@ -2600,9 +2611,6 @@ class Ticket extends CommonObject
if (!$error && $id > 0) {
setEventMessages($langs->trans('TicketMessageSuccessfullyAdded'), null, 'mesgs');
//var_dump($_SESSION);
//var_dump($listofpaths);exit;
if (!empty($public_area)) {
/*
* Message created from the Public interface
@ -3142,6 +3150,40 @@ class Ticket extends CommonObject
$return .= '</div>';
$return .= '</div>';
$return .= '</div>';
return $return;
}
/**
* Create a document onto disk according to template module.
*
* @param string $modele Force template to use ('' to not force)
* @param Translate $outputlangs object lang a utiliser pour traduction
* @param int $hidedetails Hide details of lines
* @param int $hidedesc Hide description
* @param int $hideref Hide ref
* @param null|array $moreparams Array to provide more information
* @return int 0 if KO, 1 if OK
*/
public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
{
global $langs;
$langs->load("ticket");
$outputlangs->load("ticket");
if (!dol_strlen($modele)) {
$modele = 'generic_ticket_odt';
if (!empty($this->model_pdf)) {
$modele = $this->model_pdf;
} elseif (getDolGlobalString('TICKET_ADDON_PDF')) {
$modele = getDolGlobalString('TICKET_ADDON_PDF');
}
}
$modelpath = "core/modules/ticket/doc/";
return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
}
}