Add new params to extrafields forms to allow extrafields to be displayed on pdf documents

This commit is contained in:
ATM john 2020-02-23 11:32:38 +01:00
parent ff6dc735ee
commit fe4e00b139
8 changed files with 39 additions and 30 deletions

View File

@ -183,7 +183,8 @@ if ($action == 'add')
(GETPOST('entitycurrentorall', 'alpha')?0:''),
GETPOST('langfile', 'alpha'),
1,
(GETPOST('totalizable', 'alpha')?1:0)
(GETPOST('totalizable', 'alpha')?1:0),
(GETPOST('documentpdf', 'alpha')?1:0)
);
if ($result > 0)
{
@ -352,7 +353,8 @@ if ($action == 'update')
(GETPOST('entitycurrentorall', 'alpha')?0:''),
GETPOST('langfile'),
1,
(GETPOST('totalizable', 'alpha')?1:0)
(GETPOST('totalizable', 'alpha')?1:0),
(GETPOST('documentpdf', 'alpha')?1:0)
);
if ($result > 0)
{

View File

@ -1187,16 +1187,7 @@ abstract class CommonDocGenerator
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label)
{
// Enable extrafield ?
$enabled = 1;
if ($enabled && isset($extrafields->attributes[$object->table_element]['enabled'][$key])){
$enabled = dol_eval($extrafields->attributes[$object->table_element]['enabled'][$key], 1);
}
if ($enabled && isset($extrafields->attributes[$object->table_element]['list'][$key])){
$enabled = dol_eval($extrafields->attributes[$object->table_element]['list'][$key], 1);
}
// TODO : add extrafields enabled for display from extrafield config panel
$enabled = !empty($extrafields->attributes[$object->table_element]['documentpdf'][$key]);
if(empty($enabled)){
continue;
@ -1338,16 +1329,8 @@ abstract class CommonDocGenerator
}
// Enable extrafield ?
$enabled = 1;
if ($enabled && isset($extrafields->attributes[$object->table_element]['enabled'][$key])){
$enabled = dol_eval($extrafields->attributes[$object->table_element]['enabled'][$key], 1);
}
$enabled = !empty($extrafields->attributes[$object->table_element]['documentpdf'][$key]);
if ($enabled && isset($extrafields->attributes[$object->table_element]['list'][$key])){
$enabled = dol_eval($extrafields->attributes[$object->table_element]['list'][$key], 1);
}
// TODO : add extrafields $enabled from extrafield config panel
// Load language if required
if (!empty($extrafields->attributes[$object->table_element]['langfile'][$key])) $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);

View File

@ -374,9 +374,11 @@ class ExtraFields
* @param string $langfile Language file
* @param string $enabled Condition to have the field enabled or not
* @param int $totalizable Is a measure. Must show a total on lists
* @param int $documentpdf Is extrafield displayed on PDF
* @return int <=0 if KO, >0 if OK
* @throws Exception
*/
private function create_label($attrname, $label = '', $type = '', $pos = 0, $size = 0, $elementtype = 'member', $unique = 0, $required = 0, $param = '', $alwayseditable = 0, $perms = '', $list = '-1', $help = '', $default = '', $computed = '', $entity = '', $langfile = '', $enabled = '1', $totalizable = 0)
private function create_label($attrname, $label = '', $type = '', $pos = 0, $size = 0, $elementtype = 'member', $unique = 0, $required = 0, $param = '', $alwayseditable = 0, $perms = '', $list = '-1', $help = '', $default = '', $computed = '', $entity = '', $langfile = '', $enabled = '1', $totalizable = 0, $documentpdf = 0)
{
// phpcs:enable
global $conf, $user;
@ -421,6 +423,7 @@ class ExtraFields
$sql .= " perms,";
$sql .= " langs,";
$sql .= " list,";
$sql .= " documentpdf,";
$sql .= " fielddefault,";
$sql .= " fieldcomputed,";
$sql .= " fk_user_author,";
@ -444,6 +447,7 @@ class ExtraFields
$sql .= " ".($perms ? "'".$this->db->escape($perms)."'" : "null").",";
$sql .= " ".($langfile ? "'".$this->db->escape($langfile)."'" : "null").",";
$sql .= " '".$this->db->escape($list)."',";
$sql .= " '".$this->db->escape($documentpdf)."',";
$sql .= " ".($default ? "'".$this->db->escape($default)."'" : "null").",";
$sql .= " ".($computed ? "'".$this->db->escape($computed)."'" : "null").",";
$sql .= " ".(is_object($user) ? $user->id : 0).",";
@ -590,9 +594,11 @@ class ExtraFields
* @param string $langfile Language file
* @param string $enabled Condition to have the field enabled or not
* @param int $totalizable Is extrafield totalizable on list
* @param int $documentpdf Is extrafield displayed on PDF
* @return int >0 if OK, <=0 if KO
* @throws Exception
*/
public function update($attrname, $label, $type, $length, $elementtype, $unique = 0, $required = 0, $pos = 0, $param = '', $alwayseditable = 0, $perms = '', $list = '', $help = '', $default = '', $computed = '', $entity = '', $langfile = '', $enabled = '1', $totalizable = 0)
public function update($attrname, $label, $type, $length, $elementtype, $unique = 0, $required = 0, $pos = 0, $param = '', $alwayseditable = 0, $perms = '', $list = '', $help = '', $default = '', $computed = '', $entity = '', $langfile = '', $enabled = '1', $totalizable = 0, $documentpdf = 0)
{
if ($elementtype == 'thirdparty') $elementtype = 'societe';
if ($elementtype == 'contact') $elementtype = 'socpeople';
@ -642,7 +648,7 @@ class ExtraFields
{
if ($label)
{
$result = $this->update_label($attrname, $label, $type, $length, $elementtype, $unique, $required, $pos, $param, $alwayseditable, $perms, $list, $help, $default, $computed, $entity, $langfile, $enabled, $totalizable);
$result = $this->update_label($attrname, $label, $type, $length, $elementtype, $unique, $required, $pos, $param, $alwayseditable, $perms, $list, $help, $default, $computed, $entity, $langfile, $enabled, $totalizable, $documentpdf);
}
if ($result > 0)
{
@ -700,13 +706,15 @@ class ExtraFields
* @param string $langfile Language file
* @param string $enabled Condition to have the field enabled or not
* @param int $totalizable Is extrafield totalizable on list
* @param int $documentpdf Is extrafield displayed on PDF
* @return int <=0 if KO, >0 if OK
* @throws Exception
*/
private function update_label($attrname, $label, $type, $size, $elementtype, $unique = 0, $required = 0, $pos = 0, $param = '', $alwayseditable = 0, $perms = '', $list = '0', $help = '', $default = '', $computed = '', $entity = '', $langfile = '', $enabled = '1', $totalizable = 0)
private function update_label($attrname, $label, $type, $size, $elementtype, $unique = 0, $required = 0, $pos = 0, $param = '', $alwayseditable = 0, $perms = '', $list = '0', $help = '', $default = '', $computed = '', $entity = '', $langfile = '', $enabled = '1', $totalizable = 0, $documentpdf = 0)
{
// phpcs:enable
global $conf, $user;
dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required.", ".$pos.", ".$alwayseditable.", ".$perms.", ".$list.", ".$default.", ".$computed.", ".$entity.", ".$langfile.", ".$enabled.", ".$totalizable);
dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required.", ".$pos.", ".$alwayseditable.", ".$perms.", ".$list.", ".$default.", ".$computed.", ".$entity.", ".$langfile.", ".$enabled.", ".$totalizable.", ".$documentpdf);
// Clean parameters
if ($elementtype == 'thirdparty') $elementtype = 'societe';
@ -771,6 +779,7 @@ class ExtraFields
$sql .= " alwayseditable,";
$sql .= " param,";
$sql .= " list,";
$sql .= " documentpdf,";
$sql .= " totalizable,";
$sql .= " fielddefault,";
$sql .= " fieldcomputed,";
@ -794,6 +803,7 @@ class ExtraFields
$sql .= " '".$this->db->escape($alwayseditable)."',";
$sql .= " '".$this->db->escape($params)."',";
$sql .= " '".$this->db->escape($list)."', ";
$sql .= " '".$this->db->escape($documentpdf)."', ";
$sql .= " ".$totalizable.",";
$sql .= " ".(($default != '') ? "'".$this->db->escape($default)."'" : "null").",";
$sql .= " ".($computed ? "'".$this->db->escape($computed)."'" : "null").",";
@ -871,7 +881,7 @@ class ExtraFields
}*/
// We should not have several time this request. If we have, there is some optimization to do by calling a simple $extrafields->fetch_optionals() in top of code and not into subcode
$sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,langs,list,totalizable,fielddefault,fieldcomputed,entity,enabled,help";
$sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,langs,list,documentpdf,totalizable,fielddefault,fieldcomputed,entity,enabled,help";
$sql .= " FROM ".MAIN_DB_PREFIX."extrafields";
//$sql.= " WHERE entity IN (0,".$conf->entity.")"; // Filter is done later
if ($elementtype) $sql .= " WHERE elementtype = '".$elementtype."'"; // Filed with object->table_element
@ -933,6 +943,7 @@ class ExtraFields
$this->attributes[$tab->elementtype]['perms'][$tab->name] = (strlen($tab->perms) == 0 ? 1 : $tab->perms);
$this->attributes[$tab->elementtype]['langfile'][$tab->name] = $tab->langs;
$this->attributes[$tab->elementtype]['list'][$tab->name] = $tab->list;
$this->attributes[$tab->elementtype]['documentpdf'][$tab->name] = $tab->documentpdf;
$this->attributes[$tab->elementtype]['totalizable'][$tab->name] = $tab->totalizable;
$this->attributes[$tab->elementtype]['entityid'][$tab->name] = $tab->entity;
$this->attributes[$tab->elementtype]['enabled'][$tab->name] = $tab->enabled;

View File

@ -196,6 +196,9 @@ $langs->load("modulebuilder");
<!-- Visibility -->
<tr><td class="extra_list"><?php echo $form->textwithpicto($langs->trans("Visibility"), $langs->trans("VisibleDesc")); ?>
</td><td class="valeur"><input id="list" class="minwidth100" type="text" name="list" value="<?php echo GETPOST('list', 'int')!='' ? GETPOST('list', 'int') : '1'; ?>"></td></tr>
<!-- Visibility for PDF-->
<tr><td class="extra_pdf"><?php echo $form->textwithpicto($langs->trans("DisplayOnPdf"), $langs->trans("DisplayOnPdfDesc")); ?>
</td><td class="valeur"><input id="documentpdf" type="checkbox" name="documentpdf"<?php echo GETPOST('documentpdf', 'alpha')?' checked':''; ?>></td></tr>
<!-- Totalizable -->
<tr class="extra_totalizable"><td><?php echo $langs->trans("Totalizable"); ?></td><td class="valeur"><input id="totalizable" type="checkbox" name="totalizable"<?php echo ((GETPOST('totalizable', 'alpha') || GETPOST('button', 'alpha'))?' checked':''); ?>></td></tr>
<!-- Help tooltip -->

View File

@ -165,6 +165,7 @@ $list=$extrafields->attributes[$elementtype]['list'][$attrname];
$totalizable = $extrafields->attributes[$elementtype]['totalizable'][$attrname];
$help=$extrafields->attributes[$elementtype]['help'][$attrname];
$entitycurrentorall=$extrafields->attributes[$elementtype]['entityid'][$attrname];
$documentpdf=$extrafields->attributes[$elementtype]['documentpdf'][$attrname];
if((($type == 'select') || ($type == 'checkbox') || ($type == 'radio')) && is_array($param))
{
@ -261,8 +262,12 @@ else
<tr class="extra_required"><td><?php echo $langs->trans("Required"); ?></td><td class="valeur"><input id="required" type="checkbox" name="required"<?php echo ($required?' checked':''); ?>></td></tr>
<!-- Always editable -->
<tr class="extra_alwayseditable"><td><?php echo $langs->trans("AlwaysEditable"); ?></td><td class="valeur"><input id="alwayseditable" type="checkbox" name="alwayseditable"<?php echo ($alwayseditable?' checked':''); ?>></td></tr>
<!-- Visibility -->
<tr><td class="extra_list"><?php echo $form->textwithpicto($langs->trans("Visibility"), $langs->trans("VisibleDesc")); ?>
</td><td class="valeur"><input id="list" class="minwidth100" type="text" name="list" value="<?php echo ($list!=''?$list:'1'); ?>"></td></tr>
<!-- Visibility for PDF-->
<tr><td class="extra_pdf"><?php echo $form->textwithpicto($langs->trans("DisplayOnPdf"), $langs->trans("DisplayOnPdfDesc")); ?>
</td><td class="valeur"><input id="documentpdf" type="checkbox" name="documentpdf"<?php echo !empty($documentpdf)?' checked':''; ?>></td></tr>
<tr class="extra_totalizable"><td><?php echo $form->textwithpicto($langs->trans("Totalizable"), $langs->trans("TotalizableDesc")); ?></td><td class="valeur"><input id="totalizable" type="checkbox" name="totalizable"<?php echo ($totalizable?' checked':''); ?>></td></tr>
<!-- Help tooltip -->
<tr class="help"><td><?php echo $form->textwithpicto($langs->trans("HelpOnTooltip"), $langs->trans("HelpOnTooltipDesc")); ?></td><td class="valeur"><input id="help" class="quatrevingtpercent" type="text" name="help" value="<?php echo dol_escape_htmltag($help); ?>"></td></tr>
@ -270,7 +275,6 @@ else
<!-- Multicompany entity -->
<tr><td><?php echo $langs->trans("AllEntities"); ?></td><td class="valeur"><input id="entitycurrentorall" type="checkbox" name="entitycurrentorall"<?php echo (empty($entitycurrentorall) ?' checked':''); ?>></td></tr>
<?php } ?>
<!-- Visibility -->
</table>
<?php dol_fiche_end(); ?>

View File

@ -64,8 +64,9 @@ print '<td class="center">'.$langs->trans("Unique").'</td>';
print '<td class="center">'.$langs->trans("Required").'</td>';
print '<td class="center">'.$langs->trans("AlwaysEditable").'</td>';
print '<td class="center">'.$form->textwithpicto($langs->trans("Visible"), $langs->trans("VisibleDesc")).'</td>';
print '<td class="center">'.$form->textwithpicto($langs->trans("DisplayOnPdf"), $langs->trans("DisplayOnPdfDesc")).'</td>';
print '<td class="center">'.$form->textwithpicto($langs->trans("Totalizable"), $langs->trans("TotalizableDesc")).'</td>';
if ($conf->multicompany->enabled) {
if ($conf->multicompany->enabled){
print '<td class="center">'.$langs->trans("Entities").'</td>';
}
print '<td width="80">&nbsp;</td>';
@ -92,6 +93,7 @@ if (is_array($extrafields->attributes[$elementtype]['type']) && count($extrafiel
print '<td class="center">'.yn($extrafields->attributes[$elementtype]['required'][$key])."</td>\n";
print '<td class="center">'.yn($extrafields->attributes[$elementtype]['alwayseditable'][$key])."</td>\n";
print '<td class="center">'.$extrafields->attributes[$elementtype]['list'][$key]."</td>\n";
print '<td class="center">'.yn($extrafields->attributes[$elementtype]['documentpdf'][$key])."</td>\n";
print '<td class="center">'.yn($extrafields->attributes[$elementtype]['totalizable'][$key])."</td>\n";
if (! empty($conf->multicompany->enabled)) {
print '<td class="center">';

View File

@ -179,4 +179,6 @@ INSERT INTO llx_c_ticket_resolution (code, pos, label, active, use_default, desc
INSERT INTO llx_c_ticket_resolution (code, pos, label, active, use_default, description) VALUES('CANCELED', '50', 'Canceled', 1, 0, NULL);
INSERT INTO llx_c_ticket_resolution (code, pos, label, active, use_default, description) VALUES('OTHER', '90', 'Other', 1, 0, NULL);
DELETE FROM llx_const WHERE name = __ENCRYPT('DONATION_ART885')__;
DELETE FROM llx_const WHERE name = __ENCRYPT('DONATION_ART885')__;
ALTER TABLE llx_extrafields ADD COLUMN documentpdf integer DEFAULT 0;

View File

@ -84,6 +84,8 @@ ListOfPermissionsDefined=List of defined permissions
SeeExamples=See examples here
EnabledDesc=Condition to have this field active (Examples: 1 or $conf->global->MYMODULE_MYOPTION)
VisibleDesc=Is the field visible ? (Examples: 0=Never visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create), 5=Visible on list end view form only (not create, not update). Using a negative value means field is not shown by default on list but can be selected for viewing). It can be an expression, for example:<br>preg_match('/public/', $_SERVER['PHP_SELF'])?0:1<br>($user->rights->holiday->define_holiday ? 1 : 0)
DisplayOnPdfDesc=Display this field on compatible PDF documents, you can manage position with "Position" field.<br/>Currently, known compatibles PDF models are : eratostene (order), espadon (ship), sponge (invoices), cyan (propal/quotation), cornas (supplier order)
DisplayOnPdf=Display on PDF
IsAMeasureDesc=Can the value of field be cumulated to get a total into list? (Examples: 1 or 0)
SearchAllDesc=Is the field used to make a search from the quick search tool? (Examples: 1 or 0)
SpecDefDesc=Enter here all documentation you want to provide with your module that is not already defined by other tabs. You can use .md or better, the rich .asciidoc syntax.