From 2324834b73936629feb73fe22f930c2fb986f8fd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 1 Jun 2020 16:44:22 +0200 Subject: [PATCH] Debug modulebuilder for doc generation Conflicts: htdocs/core/class/html.formfile.class.php htdocs/modulebuilder/template/admin/setup.php --- htdocs/core/class/html.formfile.class.php | 12 ++-- .../install/mysql/migration/11.0.0-12.0.0.sql | 2 + .../mysql/tables/llx_document_model.sql | 2 +- htdocs/modulebuilder/index.php | 5 +- htdocs/modulebuilder/template/admin/setup.php | 3 +- .../core/modules/modMyModule.class.php | 51 ++++++++------ .../doc/pdf_standard_myobject.modules.php | 68 ++----------------- .../modules/mymodule/modules_myobject.php | 2 +- .../modulebuilder/template/myobject_card.php | 2 +- 9 files changed, 51 insertions(+), 96 deletions(-) diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 32deb0667e8..0da4b2ca390 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -672,7 +672,7 @@ class FormFile { $submodulepart = $modulepart; - // modulepart = 'nameofmodule' or 'nameofmodule:nameofsubmodule' + // modulepart = 'nameofmodule' or 'nameofmodule:NameOfObject' $tmp = explode(':', $modulepart); if (!empty($tmp[1])) { $modulepart = $tmp[0]; @@ -680,18 +680,18 @@ class FormFile } // For normalized standard modules - $file = dol_buildpath('/core/modules/'.$modulepart.'/modules_'.$submodulepart.'.php', 0); + $file = dol_buildpath('/core/modules/'.$modulepart.'/modules_'.strtolower($submodulepart).'.php', 0); if (file_exists($file)) { $res = include_once $file; } // For normalized external modules. - else - { - $file = dol_buildpath('/'.$modulepart.'/core/modules/'.$modulepart.'/modules_'.$submodulepart.'.php', 0); + else { + $file = dol_buildpath('/'.$modulepart.'/core/modules/'.$modulepart.'/modules_'.strtolower($submodulepart).'.php', 0); $res = include_once $file; } - $class = 'ModelePDF'.ucfirst($submodulepart); + + $class = 'ModelePDF'.$submodulepart; if (class_exists($class)) { diff --git a/htdocs/install/mysql/migration/11.0.0-12.0.0.sql b/htdocs/install/mysql/migration/11.0.0-12.0.0.sql index dd448ccdb39..bbf25a40a77 100644 --- a/htdocs/install/mysql/migration/11.0.0-12.0.0.sql +++ b/htdocs/install/mysql/migration/11.0.0-12.0.0.sql @@ -75,6 +75,8 @@ ALTER TABLE llx_prelevement_bons ADD COLUMN type varchar(16) DEFAULT 'debit-orde ALTER TABLE llx_ecm_files MODIFY COLUMN src_object_type varchar(64); +ALTER TABLE llx_document_model MODIFY COLUMN type varchar(64); + -- Delete an old index that is duplicated -- VMYSQL4.1 DROP INDEX ix_fk_product_stock on llx_product_batch; diff --git a/htdocs/install/mysql/tables/llx_document_model.sql b/htdocs/install/mysql/tables/llx_document_model.sql index 6fe6913fa68..66b1f3db88f 100644 --- a/htdocs/install/mysql/tables/llx_document_model.sql +++ b/htdocs/install/mysql/tables/llx_document_model.sql @@ -25,7 +25,7 @@ create table llx_document_model rowid integer AUTO_INCREMENT PRIMARY KEY, nom varchar(50), entity integer DEFAULT 1 NOT NULL, -- multi company id - type varchar(20) NOT NULL, + type varchar(64) NOT NULL, libelle varchar(255), description text )ENGINE=innodb; diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 2a01a282a90..89a1d20628e 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -926,6 +926,9 @@ if ($dirins && $action == 'initobject' && $module && $objectname) dolReplaceInFile($destdir.'/core/modules/mod'.$module.'.class.php', $arrayreplacement, '', 0, 0, 1); } + // TODO Update entries '$myTmpObjects['MyObject']=array('includerefgeneration'=>0, 'includedocgeneration'=>0);' + + // Scan for object class files $listofobject = dol_dir_list($destdir.'/class', 'files', 0, '\.class\.php$'); @@ -1057,7 +1060,7 @@ if ($dirins && ($action == 'droptable' || $action == 'droptableextrafields') && $objectname = $tabobj; $arrayoftables = array(); - if ($action == 'droptable') $arrayoftables[] = MAIN_DB_PREFIX.strtolower($module).'_'.strtolower($tabobj); + if ($action == 'droptable') $arrayoftables[] = MAIN_DB_PREFIX.strtoslower($module).'_'.strtolower($tabobj); if ($action == 'droptableextrafields') $arrayoftables[] = MAIN_DB_PREFIX.strtolower($module).'_'.strtolower($tabobj).'_extrafields'; foreach ($arrayoftables as $tabletodrop) diff --git a/htdocs/modulebuilder/template/admin/setup.php b/htdocs/modulebuilder/template/admin/setup.php index 8a116783637..d66ede05696 100644 --- a/htdocs/modulebuilder/template/admin/setup.php +++ b/htdocs/modulebuilder/template/admin/setup.php @@ -257,7 +257,8 @@ $myTmpObjects = array(); $myTmpObjects['MyObject']=array('includerefgeneration'=>0, 'includedocgeneration'=>0); -foreach($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) { +foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) { + if ($myTmpObjectKey == 'MyObject') continue; if ($myTmpObjectArray['includerefgeneration']) { /* * Orders Numbering model diff --git a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php index 74dbac7b870..3deba218b59 100644 --- a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php +++ b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php @@ -407,31 +407,40 @@ class modMyModule extends DolibarrModules $sql = array(); - // ODT template - /* - $src=DOL_DOCUMENT_ROOT.'/install/doctemplates/mymodule/template_myobjects.odt'; - $dirodt=DOL_DATA_ROOT.'/doctemplates/mymodule'; - $dest=$dirodt.'/template_myobjects.odt'; + // Document templates + $moduledir = 'mymodule'; + $myTmpObjects = array(); + $myTmpObjects['MyObject']=array('includerefgeneration'=>0, 'includedocgeneration'=>0); - if (file_exists($src) && ! file_exists($dest)) - { - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - dol_mkdir($dirodt); - $result=dol_copy($src, $dest, 0, 0); - if ($result < 0) - { - $langs->load("errors"); - $this->error=$langs->trans('ErrorFailToCopyFile', $src, $dest); - return 0; + foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) { + if ($myTmpObjectKey == 'MyObject') continue; + if ($myTmpObjectArray['includerefgeneration']) { + $src=DOL_DOCUMENT_ROOT.'/install/doctemplates/mymodule/template_myobjects.odt'; + $dirodt=DOL_DATA_ROOT.'/doctemplates/mymodule'; + $dest=$dirodt.'/template_myobjects.odt'; + + if (file_exists($src) && ! file_exists($dest)) + { + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + dol_mkdir($dirodt); + $result=dol_copy($src, $dest, 0, 0); + if ($result < 0) + { + $langs->load("errors"); + $this->error=$langs->trans('ErrorFailToCopyFile', $src, $dest); + return 0; + } + } + + $sql = array_merge($sql, array( + "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = 'standard_".strtolower($myTmpObjectKey)."' AND type = '".strtolower($myTmpObjectKey)."' AND entity = ".$conf->entity, + "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('standard_".strtolower($myTmpObjectKey)."','".strtolower($myTmpObjectKey)."',".$conf->entity.")", + "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = 'generic_".strtolower($myTmpObjectKey)."_odt' AND type = '".strtolower($myTmpObjectKey)."' AND entity = ".$conf->entity, + "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('generic_".strtolower($myTmpObjectKey)."_odt', '".strtolower($myTmpObjectKey)."', ".$conf->entity.")" + )); } } - $sql = array( - "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'mymodule' AND entity = ".$conf->entity, - "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','mymodule',".$conf->entity.")" - ); - */ - return $this->_init($sql, $options); } diff --git a/htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php b/htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php index 4c0ff154a04..7c242c26444 100644 --- a/htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php +++ b/htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php @@ -358,10 +358,10 @@ class pdf_standard_myobject extends ModelePDFMyObject $pdf->SetDrawColor(128, 128, 128); $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref)); - $pdf->SetSubject($outputlangs->transnoentities("PdfInvoiceTitle")); + $pdf->SetSubject($outputlangs->transnoentities("PdfTitle")); $pdf->SetCreator("Dolibarr ".DOL_VERSION); $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); - $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfInvoiceTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name)); + $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name)); if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); // Set certificate @@ -633,22 +633,6 @@ class pdf_standard_myobject extends ModelePDFMyObject $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut - // VAT Rate - if ($this->getColumnStatus('vat')) - { - $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails); - $this->printStdColumnContent($pdf, $curY, 'vat', $vat_rate); - $nexY = max($pdf->GetY(), $nexY); - } - - // Unit price before discount - if ($this->getColumnStatus('subprice')) - { - $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails); - $this->printStdColumnContent($pdf, $curY, 'subprice', $up_excl_tax); - $nexY = max($pdf->GetY(), $nexY); - } - // Quantity // Enough for 6 chars if ($this->getColumnStatus('qty')) @@ -658,38 +642,6 @@ class pdf_standard_myobject extends ModelePDFMyObject $nexY = max($pdf->GetY(), $nexY); } - // Situation progress - if ($this->getColumnStatus('progress')) - { - $progress = pdf_getlineprogress($object, $i, $outputlangs, $hidedetails); - $this->printStdColumnContent($pdf, $curY, 'progress', $progress); - $nexY = max($pdf->GetY(), $nexY); - } - - // Unit - if ($this->getColumnStatus('unit')) - { - $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager); - $this->printStdColumnContent($pdf, $curY, 'unit', $unit); - $nexY = max($pdf->GetY(), $nexY); - } - - // Discount on line - if ($this->getColumnStatus('discount') && $object->lines[$i]->remise_percent) - { - $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails); - $this->printStdColumnContent($pdf, $curY, 'discount', $remise_percent); - $nexY = max($pdf->GetY(), $nexY); - } - - // Total HT line - if ($this->getColumnStatus('totalexcltax')) - { - $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails); - $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax); - $nexY = max($pdf->GetY(), $nexY); - } - // Extrafields if (!empty($object->lines[$i]->array_options)) { foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) { @@ -716,7 +668,6 @@ class pdf_standard_myobject extends ModelePDFMyObject $sign = 1; - if (isset($object->type) && $object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign = -1; // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva $prev_progress = $object->lines[$i]->get_prev_progress($object->id); if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) // Compute progress from previous situation @@ -1006,21 +957,10 @@ class pdf_standard_myobject extends ModelePDFMyObject $pdf->SetFont('', 'B', $default_font_size + 3); $pdf->SetXY($posx, $posy); $pdf->SetTextColor(0, 0, 60); - $title = $outputlangs->transnoentities("PdfInvoiceTitle"); - if ($object->type == 1) $title = $outputlangs->transnoentities("InvoiceReplacement"); - if ($object->type == 2) $title = $outputlangs->transnoentities("InvoiceAvoir"); - if ($object->type == 3) $title = $outputlangs->transnoentities("InvoiceDeposit"); - if ($object->type == 4) $title = $outputlangs->transnoentities("InvoiceProForma"); - if ($this->situationinvoice) $title = $outputlangs->transnoentities("InvoiceSituation"); + $title = $outputlangs->transnoentities("PdfTitle"); if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) { $title .= ' - '; - if ($object->type == 0) { - if ($this->situationinvoice) $title .= $outputlangsbis->transnoentities("InvoiceSituation"); - $title .= $outputlangsbis->transnoentities("PdfInvoiceTitle"); - } elseif ($object->type == 1) $title .= $outputlangsbis->transnoentities("InvoiceReplacement"); - elseif ($object->type == 2) $title .= $outputlangsbis->transnoentities("InvoiceAvoir"); - elseif ($object->type == 3) $title .= $outputlangsbis->transnoentities("InvoiceDeposit"); - elseif ($object->type == 4) $title .= $outputlangsbis->transnoentities("InvoiceProForma"); + $title .= $outputlangsbis->transnoentities("PdfTitle"); } $pdf->MultiCell($w, 3, $title, '', 'R'); diff --git a/htdocs/modulebuilder/template/core/modules/mymodule/modules_myobject.php b/htdocs/modulebuilder/template/core/modules/mymodule/modules_myobject.php index a16f56e137c..78711e33a4d 100644 --- a/htdocs/modulebuilder/template/core/modules/mymodule/modules_myobject.php +++ b/htdocs/modulebuilder/template/core/modules/mymodule/modules_myobject.php @@ -51,7 +51,7 @@ abstract class ModelePDFMyObject extends CommonDocGenerator // phpcs:enable global $conf; - $type = 'mymodule_myobject'; + $type = 'myobject'; $list = array(); include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; diff --git a/htdocs/modulebuilder/template/myobject_card.php b/htdocs/modulebuilder/template/myobject_card.php index 41a679b6292..ceeb30d5d3e 100644 --- a/htdocs/modulebuilder/template/myobject_card.php +++ b/htdocs/modulebuilder/template/myobject_card.php @@ -570,7 +570,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id; $genallowed = $user->rights->mymodule->myobject->read; // If you can read, you can build the PDF to read content $delallowed = $user->rights->mymodule->myobject->write; // If you can create/edit, you can remove a file on card - print $formfile->showdocuments('mymodule:myobject', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang); + print $formfile->showdocuments('mymodule:MyObject', $object->element.'/'.$objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang); } // Show links to link elements