Skip to content

Commit

Permalink
#30 [Certificate] fix: clean code files
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Nov 2, 2022
1 parent 77f1cdb commit 5983d48
Show file tree
Hide file tree
Showing 9 changed files with 499 additions and 1,137 deletions.
565 changes: 219 additions & 346 deletions class/certificate.class.php

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,19 @@ public function info($langs)
/**
* Function to build a document on disk using the generic odt module.
*
* @param Certificate $object Object source to build document
* @param Translate $outputlangs Lang output object
* @param string $srctemplatepath Full path of source filename for generator using a template file
* @param int $hidedetails Do not show line details
* @param int $hidedesc Do not show desc
* @param int $hideref Do not show ref
* @return int 1 if OK, <=0 if KO
* @param CertificateDocument $objectDocument Object source to build document
* @param Translate $outputlangs Lang output object
* @param string $srctemplatepath Full path of source filename for generator using a template file
* @param int $hidedetails Do not show line details
* @param int $hidedesc Do not show desc
* @param int $hideref Do not show ref
* @param Certificate $object Certificate Object
* @return int 1 if OK, <=0 if KO
*/
public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
public function write_file($objectDocument, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $object)
{
// phpcs:enable
global $user, $langs, $conf, $mysoc, $hookmanager;
global $action, $conf, $hookmanager, $langs, $mysoc, $user;

if (empty($srctemplatepath)) {
dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
Expand All @@ -188,7 +189,6 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails
$hookmanager = new HookManager($this->db);
}
$hookmanager->initHooks(array('odtgeneration'));
global $action;

if (!is_object($outputlangs)) {
$outputlangs = $langs;
Expand All @@ -198,26 +198,34 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails

$outputlangs->loadLangs(array("main", "dict", "companies", "bills"));

$mod = new $conf->global->DOLISIRH_TIMESHEETDOCUMENT_ADDON($this->db);
$ref = $mod->getNextValue($objectDocument);

$objectDocument->ref = $ref;
$id = $objectDocument->create($user, true, $object);

$objectDocument->fetch($id);

if ($conf->dolisirh->dir_output) {
// If $object is id instead of object
if (!is_object($object)) {
$id = $object;
$object = new Certificate($this->db);
$result = $object->fetch($id);
if ($result < 0) {
dol_print_error($this->db, $object->error);
return -1;
}
}

$object->fetch_thirdparty();
// if (!is_object($object)) {
// $id = $object;
// $object = new Certificate($this->db);
// $result = $object->fetch($id);
// if ($result < 0) {
// dol_print_error($this->db, $object->error);
// return -1;
// }
// }

//$object->fetch_thirdparty();

$dir = $conf->dolisirh->multidir_output[isset($object->entity) ? $object->entity : 1];
$objectref = dol_sanitizeFileName($object->ref);
if (!preg_match('/specimen/i', $objectref)) {
$dir .= "/".$objectref;
}
$file = $dir."/".$objectref.".odt";
$dir = $conf->dolisirh->multidir_output[isset($object->entity) ? $object->entity : 1] . '/certificatedocument/' . $object->ref;
// if (!preg_match('/specimen/i', $objectref)) {
// $dir .= "/".$objectref;
// }
//$file = $dir."/".$objectref.".odt";

if (!file_exists($dir)) {
if (dol_mkdir($dir) < 0) {
Expand All @@ -232,7 +240,22 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails
$newfiletmp = preg_replace('/\.od(t|s)/i', '', $newfile);
$newfiletmp = preg_replace('/template_/i', '', $newfiletmp);
$newfiletmp = preg_replace('/modele_/i', '', $newfiletmp);
$newfiletmp = $objectref.'_'.$newfiletmp;

$date = dol_print_date(dol_now(), 'dayxcard');
$newfiletmp = $objectref . '_' . $date . '_' . $newfiletmp . '_' . $conf->global->MAIN_INFO_SOCIETE_NOM;
$newfiletmp = str_replace(' ', '_', $newfiletmp);
$newfiletmp = dol_sanitizeFileName($newfiletmp);

$objectDocument->last_main_doc = $newfiletmp;

$sql = "UPDATE " . MAIN_DB_PREFIX . "dolisirh_dolisirhdocuments";
$sql .= " SET last_main_doc =" . ( ! empty($newfiletmp) ? "'" . $this->db->escape($newfiletmp) . "'" : 'null');
$sql .= " WHERE rowid = " . $objectDocument->id;

dol_syslog("admin.lib::Insert last main doc", LOG_DEBUG);
$this->db->query($sql);

//$newfiletmp = $objectref.'_'.$newfiletmp;
//$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt';
// Get extension (ods or odt)
$newfileformat = substr($newfile, strrpos($newfile, '.') + 1);
Expand All @@ -259,29 +282,29 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails
}

// If CUSTOMER contact defined on order, we use it
$usecontact = false;
$arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
if (count($arrayidcontact) > 0) {
$usecontact = true;
$result = $object->fetch_contact($arrayidcontact[0]);
}
// $usecontact = false;
// $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
// if (count($arrayidcontact) > 0) {
// $usecontact = true;
// $result = $object->fetch_contact($arrayidcontact[0]);
// }

// Recipient name
$contactobject = null;
if (!empty($usecontact)) {
// We can use the company of contact instead of thirdparty company
if ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT))) {
$object->contact->fetch_thirdparty();
$socobject = $object->contact->thirdparty;
$contactobject = $object->contact;
} else {
$socobject = $object->thirdparty;
// if we have a CUSTOMER contact and we dont use it as thirdparty recipient we store the contact object for later use
$contactobject = $object->contact;
}
} else {
$socobject = $object->thirdparty;
}
// $contactobject = null;
// if (!empty($usecontact)) {
// // We can use the company of contact instead of thirdparty company
// if ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT))) {
// $object->contact->fetch_thirdparty();
// $socobject = $object->contact->thirdparty;
// $contactobject = $object->contact;
// } else {
// $socobject = $object->thirdparty;
// // if we have a CUSTOMER contact and we dont use it as thirdparty recipient we store the contact object for later use
// $contactobject = $object->contact;
// }
// } else {
// $socobject = $object->thirdparty;
// }

// Make substitution
$substitutionarray = array(
Expand Down
2 changes: 1 addition & 1 deletion sql/certificate/llx_dolisirh_certificate.key.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ALTER TABLE llx_dolisirh_certificate ADD INDEX idx_dolisirh_certificate_ref (ref
ALTER TABLE llx_dolisirh_certificate ADD INDEX idx_dolisirh_certificate_status (status);
ALTER TABLE llx_dolisirh_certificate ADD INDEX idx_dolisirh_certificate_fk_element (fk_element);
ALTER TABLE llx_dolisirh_certificate ADD INDEX idx_dolisirh_certificate_fk_product (fk_product);
ALTER TABLE llx_dolisirh_certificate ADD INDEX idx_dolisirh_certificate_fk_societe (fk_societe);
ALTER TABLE llx_dolisirh_certificate ADD INDEX idx_dolisirh_certificate_fk_soc (fk_soc);
ALTER TABLE llx_dolisirh_certificate ADD INDEX idx_dolisirh_certificate_fk_project (fk_project);
ALTER TABLE llx_dolisirh_certificate ADD UNIQUE INDEX uk_dolisirh_certificate_ref (ref, entity);
ALTER TABLE llx_dolisirh_certificate ADD CONSTRAINT llx_dolisirh_certificate_fk_user_creat FOREIGN KEY (fk_user_creat) REFERENCES llx_user(rowid);
2 changes: 1 addition & 1 deletion sql/certificate/llx_dolisirh_certificate.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ CREATE TABLE llx_dolisirh_certificate(
element_type text,
fk_element integer,
fk_product integer,
fk_societe integer,
fk_soc integer,
fk_project integer,
fk_user_creat integer NOT NULL,
fk_user_modif integer
Expand Down
9 changes: 2 additions & 7 deletions view/certificate/certificate_agenda.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,6 @@
// Load object
include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be included, not include_once // Must be included, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals

if ($id > 0 || !empty($ref)) {
$upload_dir = $conf->dolisirh->multidir_output[!empty($object->entity) ? $object->entity : $conf->entity]."/".$object->id;
}

// There is several ways to check permission.
$permissiontoread = $user->rights->dolisirh->certificate->read;
$permissiontoadd = $user->rights->dolisirh->certificate->write;
Expand Down Expand Up @@ -182,7 +178,7 @@
$morehtmlref = '<div class="refidno">';
// Thirdparty
if (! empty($conf->societe->enabled)) {
$object->fetch_thirdparty($object->fk_societe);
$object->fetch_thirdparty();
$morehtmlref .= $langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
}
// Project
Expand Down Expand Up @@ -243,15 +239,14 @@
print '</div>';

if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
$param = '&id='.$object->id.'&socid='.$socid;
$param = '&id='.$object->id;
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
$param .= '&contextpage='.urlencode($contextpage);
}
if ($limit > 0 && $limit != $conf->liste_limit) {
$param .= '&limit='.urlencode($limit);
}


print load_fiche_titre($langs->trans("ActionsOnCertificate"), '', '');

// List of all actions
Expand Down
Loading

0 comments on commit 5983d48

Please sign in to comment.