fix: uniformize extrafeild replacemnt for ODT docs

This commit is contained in:
florian HENRY 2020-04-23 15:50:42 +02:00
parent 86928efb95
commit 882b39628f
2 changed files with 46 additions and 67 deletions

View File

@ -170,12 +170,13 @@ abstract class CommonDocGenerator
* *
* @param Societe $object Object * @param Societe $object Object
* @param Translate $outputlangs Language object for output * @param Translate $outputlangs Language object for output
* @param string $array_key Name of the key for return array
* @return array Array of substitution key->code * @return array Array of substitution key->code
*/ */
public function get_substitutionarray_thirdparty($object, $outputlangs) public function get_substitutionarray_thirdparty($object, $outputlangs, $array_key = 'company')
{ {
// phpcs:enable // phpcs:enable
global $conf; global $conf, $extrafields;
if (empty($object->country) && !empty($object->country_code)) if (empty($object->country) && !empty($object->country_code))
{ {
@ -221,27 +222,14 @@ abstract class CommonDocGenerator
'company_default_bank_bic'=>$object->bank_account->bic 'company_default_bank_bic'=>$object->bank_account->bic
); );
// Retrieve extrafields // Retrieve extrafields
if (is_array($object->array_options) && count($object->array_options)) if (is_array($object->array_options) && count($object->array_options))
{ {
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $object->fetch_optionals();
$extrafields = new ExtraFields($this->db);
$extrafields->fetch_name_optionals_label($object->table_element, true);
$object->fetch_optionals();
foreach ($extrafields->attributes[$object->table_element]['label'] as $key=>$label) $array_thirdparty = $this->fill_substitutionarray_with_extrafields($object, $array_thirdparty, $extrafields, $array_key, $outputlangs);
{
if ($extrafields->attributes[$object->table_element]['type'][$key] == 'price') }
{
$object->array_options['options_'.$key] = price($object->array_options['options_'.$key], 0, $outputlangs, 0, 0, -1, $conf->currency);
}
elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'select' || $extrafields->attributes[$object->table_element]['type'][$key] == 'checkbox')
{
$object->array_options['options_'.$key] = $extrafields->attributes[$object->table_element]['param'][$key]['options'][$object->array_options['options_'.$key]];
}
$array_thirdparty = array_merge($array_thirdparty, array('company_options_'.$key => $object->array_options ['options_'.$key]));
}
}
return $array_thirdparty; return $array_thirdparty;
} }
@ -251,13 +239,13 @@ abstract class CommonDocGenerator
* *
* @param Contact $object contact * @param Contact $object contact
* @param Translate $outputlangs object for output * @param Translate $outputlangs object for output
* @param array $array_key Name of the key for return array * @param string $array_key Name of the key for return array
* @return array Array of substitution key->code * @return array Array of substitution key->code
*/ */
public function get_substitutionarray_contact($object, $outputlangs, $array_key = 'object') public function get_substitutionarray_contact($object, $outputlangs, $array_key = 'object')
{ {
// phpcs:enable // phpcs:enable
global $conf; global $conf, $extrafields;
if (empty($object->country) && !empty($object->country_code)) if (empty($object->country) && !empty($object->country_code))
{ {
@ -298,24 +286,14 @@ abstract class CommonDocGenerator
$array_key.'_civility' => $object->civility, $array_key.'_civility' => $object->civility,
); );
// Retrieve extrafields // Retrieve extrafields
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; if (is_array($object->array_options) && count($object->array_options))
$extrafields = new ExtraFields($this->db); {
$extrafields->fetch_name_optionals_label($object->table_element, true); $object->fetch_optionals();
$object->fetch_optionals();
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) $array_contact = $this->fill_substitutionarray_with_extrafields($object, $array_contact, $extrafields, $array_key, $outputlangs);
{
if ($extrafields->attributes[$object->table_element]['type'][$key] == 'price') }
{
$object->array_options['options_'.$key] = price($object->array_options ['options_'.$key], 0, $outputlangs, 0, 0, - 1, $conf->currency);
}
elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'select' || $extrafields->attributes[$object->table_element]['type'][$key] == 'checkbox')
{
$object->array_options['options_'.$key] = $extrafields->attributes[$object->table_element]['param'][$key]['options'][$object->array_options['options_'.$key]];
}
$array_contact = array_merge($array_contact, array($array_key.'_options_'.$key => $object->array_options['options_'.$key]));
}
return $array_contact; return $array_contact;
} }
@ -370,7 +348,7 @@ abstract class CommonDocGenerator
public function get_substitutionarray_object($object, $outputlangs, $array_key = 'object') public function get_substitutionarray_object($object, $outputlangs, $array_key = 'object')
{ {
// phpcs:enable // phpcs:enable
global $conf; global $conf, $extrafields;
$sumpayed = $sumdeposit = $sumcreditnote = ''; $sumpayed = $sumdeposit = $sumcreditnote = '';
$already_payed_all = 0; $already_payed_all = 0;
@ -528,14 +506,10 @@ abstract class CommonDocGenerator
// Retrieve extrafields // Retrieve extrafields
if (is_array($object->array_options) && count($object->array_options)) if (is_array($object->array_options) && count($object->array_options))
{ {
$extrafieldkey = $object->element;
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$extrafields = new ExtraFields($this->db);
$extrafields->fetch_name_optionals_label($extrafieldkey, true);
$object->fetch_optionals(); $object->fetch_optionals();
$resarray = $this->fill_substitutionarray_with_extrafields($object, $resarray, $extrafields, $array_key, $outputlangs); $resarray = $this->fill_substitutionarray_with_extrafields($object, $resarray, $extrafields, $array_key, $outputlangs);
} }
return $resarray; return $resarray;
@ -605,7 +579,7 @@ abstract class CommonDocGenerator
} }
// Retrieve extrafields // Retrieve extrafields
$extrafieldkey = $line->element; $extrafieldkey = $line->table_element;
$array_key = "line"; $array_key = "line";
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$extrafields = new ExtraFields($this->db); $extrafields = new ExtraFields($this->db);
@ -672,7 +646,7 @@ abstract class CommonDocGenerator
public function get_substitutionarray_shipment($object, $outputlangs, $array_key = 'object') public function get_substitutionarray_shipment($object, $outputlangs, $array_key = 'object')
{ {
// phpcs:enable // phpcs:enable
global $conf; global $conf, $extrafields;
dol_include_once('/core/lib/product.lib.php'); dol_include_once('/core/lib/product.lib.php');
$object->list_delivery_methods($object->shipping_method_id); $object->list_delivery_methods($object->shipping_method_id);
$calculatedVolume = ($object->trueWidth * $object->trueHeight * $object->trueDepth); $calculatedVolume = ($object->trueWidth * $object->trueHeight * $object->trueDepth);
@ -708,16 +682,14 @@ abstract class CommonDocGenerator
$array_shipment[$array_key.'_total_vat_'.$line->tva_tx] += $line->total_tva; $array_shipment[$array_key.'_total_vat_'.$line->tva_tx] += $line->total_tva;
} }
// Retrieve extrafields // Retrieve extrafields
if (is_array($object->array_options) && count($object->array_options)) if (is_array($object->array_options) && count($object->array_options))
{ {
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $object->fetch_optionals();
$extrafields = new ExtraFields($this->db);
$extrafields->fetch_name_optionals_label('expedition', true);
$object->fetch_optionals();
$array_shipment = $this->fill_substitutionarray_with_extrafields($object, $array_shipment, $extrafields, $array_key, $outputlangs); $array_shipment = $this->fill_substitutionarray_with_extrafields($object, $array_shipment, $extrafields, $array_key, $outputlangs);
}
}
return $array_shipment; return $array_shipment;
} }

View File

@ -130,7 +130,7 @@ class doc_generic_task_odt extends ModelePDFTask
public function get_substitutionarray_object($object, $outputlangs, $array_key = 'object') public function get_substitutionarray_object($object, $outputlangs, $array_key = 'object')
{ {
// phpcs:enable // phpcs:enable
global $conf; global $conf, $extrafields;
$resarray = array( $resarray = array(
$array_key.'_id'=>$object->id, $array_key.'_id'=>$object->id,
@ -150,14 +150,10 @@ class doc_generic_task_odt extends ModelePDFTask
// Retrieve extrafields // Retrieve extrafields
if (is_array($object->array_options) && count($object->array_options)) if (is_array($object->array_options) && count($object->array_options))
{ {
$extrafieldkey = $object->element;
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$extrafields = new ExtraFields($this->db);
$extrafields->fetch_name_optionals_label($extrafieldkey, true);
$object->fetch_optionals(); $object->fetch_optionals();
$resarray = $this->fill_substitutionarray_with_extrafields($object, $resarray, $extrafields, $array_key, $outputlangs); $resarray = $this->fill_substitutionarray_with_extrafields($object, $resarray, $extrafields, $array_key, $outputlangs);
} }
return $resarray; return $resarray;
@ -169,14 +165,15 @@ class doc_generic_task_odt extends ModelePDFTask
* *
* @param array $task Task Object * @param array $task Task Object
* @param Translate $outputlangs Lang object to use for output * @param Translate $outputlangs Lang object to use for output
* @param string $array_key Name of the key for return array
* @return array Return a substitution array * @return array Return a substitution array
*/ */
public function get_substitutionarray_tasks($task, $outputlangs) public function get_substitutionarray_tasks($task, $outputlangs, $array_key = 'task')
{ {
// phpcs:enable // phpcs:enable
global $conf; global $conf, $extrafields;
return array( $resarray = array(
'task_ref'=>$task->ref, 'task_ref'=>$task->ref,
'task_fk_project'=>$task->fk_project, 'task_fk_project'=>$task->fk_project,
'task_projectref'=>$task->projectref, 'task_projectref'=>$task->projectref,
@ -192,6 +189,16 @@ class doc_generic_task_odt extends ModelePDFTask
'task_note_private'=>$task->note_private, 'task_note_private'=>$task->note_private,
'task_note_public'=>$task->note_public 'task_note_public'=>$task->note_public
); );
// Retrieve extrafields
if (is_array($task->array_options) && count($task->array_options))
{
$task->fetch_optionals();
$resarray = $this->fill_substitutionarray_with_extrafields($task, $resarray, $extrafields, $array_key, $outputlangs);
}
return $resarray;
} }
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps