Skip to content

Commit

Permalink
Ticket generate doc (#28031)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
frederic34 and eldy authored Feb 7, 2024
1 parent 92b9527 commit 0972ba1
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 17 deletions.
2 changes: 1 addition & 1 deletion htdocs/admin/ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
$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;
Expand Down
9 changes: 4 additions & 5 deletions htdocs/core/class/commondocgenerator.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ public function get_substitutionarray_other($outputlangs)
* 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
Expand All @@ -515,6 +515,7 @@ public function get_substitutionarray_object($object, $outputlangs, $array_key =
$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);
Expand All @@ -528,7 +529,7 @@ public function get_substitutionarray_object($object, $outputlangs, $array_key =
$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;
}
Expand Down Expand Up @@ -703,7 +704,7 @@ public function get_substitutionarray_object($object, $outputlangs, $array_key =
* 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
Expand Down Expand Up @@ -927,8 +928,6 @@ public function get_substitutionarray_each_var_object(&$object, $outputlangs, $r
}
}

//var_dump($array_other);

return $array_other;
}

Expand Down
6 changes: 4 additions & 2 deletions htdocs/core/modules/modTicket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ public function init($options = '')
//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';
Expand All @@ -394,8 +394,10 @@ public function init($options = '')
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails
}

// 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);
Expand Down
16 changes: 13 additions & 3 deletions htdocs/ticket/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -707,7 +708,6 @@

// Actions to build doc
include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
//var_dump($action);exit;

// Actions to send emails
$triggersendname = 'TICKET_SENTBYMAIL';
Expand All @@ -729,6 +729,7 @@

$userstat = new User($db);
$form = new Form($db);
$formfile = new FormFile($db);
$formticket = new FormTicket($db);
if (isModEnabled('project')) {
$formproject = new FormProjets($db);
Expand Down Expand Up @@ -811,8 +812,7 @@
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')) {
Expand Down Expand Up @@ -1613,6 +1613,16 @@
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'));
Expand Down
52 changes: 47 additions & 5 deletions htdocs/ticket/class/ticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -526,6 +528,7 @@ public function create($user, $notrigger = 0)
$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)."'").",";
Expand All @@ -552,6 +555,7 @@ public function create($user, $notrigger = 0)
$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 .= ")";

Expand Down Expand Up @@ -665,6 +669,8 @@ public function fetch($id = 0, $ref = '', $track_id = '', $email_msgid = '')
$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";
Expand Down Expand Up @@ -706,6 +712,8 @@ public function fetch($id = 0, $ref = '', $track_id = '', $email_msgid = '')
$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;
Expand Down Expand Up @@ -1022,7 +1030,9 @@ public function update($user, $notrigger = 0)
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
Expand All @@ -1047,6 +1057,7 @@ public function update($user, $notrigger = 0)
$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);

Expand Down Expand Up @@ -2600,9 +2611,6 @@ public function newMessage($user, &$action, $private = 1, $public_area = 0)
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
Expand Down Expand Up @@ -3142,6 +3150,40 @@ public function getKanbanView($option = '', $arraydata = null)
$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);
}
}

0 comments on commit 0972ba1

Please sign in to comment.