Fix better management of export of extrafield computed.
This commit is contained in:
parent
c8856182a6
commit
c088ccea32
@ -350,7 +350,7 @@ llxHeader('',$langs->trans('CustomersInvoices'),'EN:Customers_Invoices|FR:Factur
|
||||
|
||||
$sql = 'SELECT';
|
||||
if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT';
|
||||
$sql.= ' f.rowid as facid, f.facnumber, f.ref_client, f.type, f.note_private, f.note_public, f.increment, f.fk_mode_reglement, f.total as total_ht, f.tva as total_vat, f.total_ttc,';
|
||||
$sql.= ' f.rowid as id, f.facnumber as ref, f.ref_client, f.type, f.note_private, f.note_public, f.increment, f.fk_mode_reglement, f.total as total_ht, f.tva as total_vat, f.total_ttc,';
|
||||
$sql.= ' f.localtax1 as total_localtax1, f.localtax2 as total_localtax2,';
|
||||
$sql.= ' f.datef as df, f.date_lim_reglement as datelimite,';
|
||||
$sql.= ' f.paye as paye, f.fk_statut,';
|
||||
@ -998,8 +998,8 @@ if ($resql)
|
||||
$obj = $db->fetch_object($resql);
|
||||
|
||||
$datelimit=$db->jdate($obj->datelimite);
|
||||
$facturestatic->id=$obj->facid;
|
||||
$facturestatic->ref=$obj->facnumber;
|
||||
$facturestatic->id=$obj->id;
|
||||
$facturestatic->ref=$obj->ref;
|
||||
$facturestatic->type=$obj->type;
|
||||
$facturestatic->statut=$obj->fk_statut;
|
||||
$facturestatic->date_lim_reglement=$db->jdate($obj->datelimite);
|
||||
@ -1025,9 +1025,9 @@ if ($resql)
|
||||
print '</td>';
|
||||
|
||||
print '<td style="min-width: 20px" class="nobordernopadding nowrap">';
|
||||
$filename=dol_sanitizeFileName($obj->facnumber);
|
||||
$filedir=$conf->facture->dir_output . '/' . dol_sanitizeFileName($obj->facnumber);
|
||||
$urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->facid;
|
||||
$filename=dol_sanitizeFileName($obj->ref);
|
||||
$filedir=$conf->facture->dir_output . '/' . dol_sanitizeFileName($obj->ref);
|
||||
$urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->id;
|
||||
print $formfile->getDocumentsLink($facturestatic->element, $filename, $filedir);
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
@ -1262,8 +1262,8 @@ if ($resql)
|
||||
if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
|
||||
{
|
||||
$selected=0;
|
||||
if (in_array($obj->facid, $arrayofselected)) $selected=1;
|
||||
print '<input id="cb'.$obj->facid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->facid.'"'.($selected?' checked="checked"':'').'>';
|
||||
if (in_array($obj->id, $arrayofselected)) $selected=1;
|
||||
print '<input id="cb'.$obj->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->id.'"'.($selected?' checked="checked"':'').'>';
|
||||
}
|
||||
print '</td>' ;
|
||||
if (! $i) $totalarray['nbfield']++;
|
||||
|
||||
@ -8,7 +8,7 @@ if (empty($keyforselect) || empty($keyforelement) || empty($keyforaliasextra))
|
||||
}
|
||||
|
||||
// Add extra fields
|
||||
$sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = '".$keyforselect."' AND type != 'separate' AND entity IN (0, ".$conf->entity.')';
|
||||
$sql="SELECT name, label, type, param, fieldcomputed, fielddefault FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = '".$keyforselect."' AND type != 'separate' AND entity IN (0, ".$conf->entity.')';
|
||||
//print $sql;
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql) // This can fail when class is used on old database (during migration for example)
|
||||
@ -42,10 +42,23 @@ if ($resql) // This can fail when class is used on old database (during migra
|
||||
if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
|
||||
break;
|
||||
}
|
||||
if ($obj->type!='separate') {
|
||||
$this->export_fields_array[$r][$fieldname]=$fieldlabel;
|
||||
$this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
|
||||
$this->export_entities_array[$r][$fieldname]=$keyforelement;
|
||||
if ($obj->type!='separate')
|
||||
{
|
||||
// If not a computed field
|
||||
if (empty($obj->fieldcomputed))
|
||||
{
|
||||
$this->export_fields_array[$r][$fieldname]=$fieldlabel;
|
||||
$this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
|
||||
$this->export_entities_array[$r][$fieldname]=$keyforelement;
|
||||
}
|
||||
// If this is a computed field
|
||||
else
|
||||
{
|
||||
$this->export_fields_array[$r][$fieldname]=$fieldlabel;
|
||||
$this->export_TypeFields_array[$r][$fieldname]=$typeFilter.'Compute';
|
||||
$this->export_special_array[$r][$fieldname]=$obj->fieldcomputed;
|
||||
$this->export_entities_array[$r][$fieldname]=$keyforelement;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -215,6 +215,9 @@ class DolibarrModules // Can not be abstract, because we need to insta
|
||||
*/
|
||||
public $descriptionlong;
|
||||
|
||||
|
||||
// For exports
|
||||
|
||||
/**
|
||||
* @var string Module export code
|
||||
*/
|
||||
@ -225,6 +228,19 @@ class DolibarrModules // Can not be abstract, because we need to insta
|
||||
*/
|
||||
public $export_label;
|
||||
|
||||
public $export_permission;
|
||||
public $export_fields_array;
|
||||
public $export_TypeFields_array;
|
||||
public $export_entities_array;
|
||||
public $export_special_array; // special or computed field
|
||||
public $export_dependencies_array;
|
||||
public $export_sql_start;
|
||||
public $export_sql_end;
|
||||
public $export_sql_order;
|
||||
|
||||
|
||||
// For import
|
||||
|
||||
/**
|
||||
* @var string Module import code
|
||||
*/
|
||||
@ -235,6 +251,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
|
||||
*/
|
||||
public $import_label;
|
||||
|
||||
|
||||
/**
|
||||
* @var string Module constant name
|
||||
*/
|
||||
@ -343,6 +360,13 @@ class DolibarrModules // Can not be abstract, because we need to insta
|
||||
public $hidden = false;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructor. Define names, constants, directories, boxes, permissions
|
||||
*
|
||||
|
||||
@ -243,12 +243,13 @@ class modProjet extends DolibarrModules
|
||||
|
||||
// Add fields for project
|
||||
$this->export_fields_array[$r]=array_merge($this->export_fields_array[$r], array());
|
||||
// Add extra fields for project
|
||||
$keyforselect='projet'; $keyforelement='project'; $keyforaliasextra='extra';
|
||||
include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
|
||||
// Add fields for tasks
|
||||
$this->export_fields_array[$r]=array_merge($this->export_fields_array[$r], array('pt.rowid'=>'RefTask','pt.label'=>'LabelTask','pt.dateo'=>"TaskDateStart",'pt.datee'=>"TaskDateEnd",'pt.duration_effective'=>"DurationEffective",'pt.planned_workload'=>"PlannedWorkload",'pt.progress'=>"Progress",'pt.description'=>"TaskDescription"));
|
||||
$this->export_entities_array[$r]=array_merge($this->export_entities_array[$r], array('pt.rowid'=>'projecttask','pt.label'=>'projecttask','pt.dateo'=>"projecttask",'pt.datee'=>"projecttask",'pt.duration_effective'=>"projecttask",'pt.planned_workload'=>"projecttask",'pt.progress'=>"projecttask",'pt.description'=>"projecttask"));
|
||||
// Add extra fields
|
||||
// Add extra fields for task
|
||||
$keyforselect='projet_task'; $keyforelement='projecttask'; $keyforaliasextra='extra2';
|
||||
include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
|
||||
// End add extra fields
|
||||
|
||||
@ -38,6 +38,7 @@ class Export
|
||||
var $array_export_sql_start=array(); // Tableau des "requetes sql"
|
||||
var $array_export_sql_end=array(); // Tableau des "requetes sql"
|
||||
var $array_export_sql_order=array(); // Tableau des "requetes sql"
|
||||
|
||||
var $array_export_fields=array(); // Tableau des listes de champ+libelle a exporter
|
||||
var $array_export_TypeFields=array(); // Tableau des listes de champ+Type de filtre
|
||||
var $array_export_FilterValue=array(); // Tableau des listes de champ+Valeur a filtrer
|
||||
@ -281,7 +282,7 @@ class Export
|
||||
if (! (strpos($ValueField, '%') === false))
|
||||
$szFilterQuery.=" ".$NameField." LIKE '".$ValueField."'";
|
||||
else
|
||||
$szFilterQuery.=" ".$NameField."='".$ValueField."'";
|
||||
$szFilterQuery.=" ".$NameField." = '".$ValueField."'";
|
||||
break;
|
||||
case 'Date':
|
||||
if (strpos($ValueField, "+") > 0)
|
||||
@ -325,8 +326,12 @@ class Export
|
||||
case 'List':
|
||||
if (is_numeric($ValueField))
|
||||
$szFilterQuery=" ".$NameField."=".$ValueField;
|
||||
else
|
||||
$szFilterQuery=" ".$NameField."='".$ValueField."'";
|
||||
else {
|
||||
if (! (strpos($ValueField, '%') === false))
|
||||
$szFilterQuery=" ".$NameField." LIKE '".$ValueField."'";
|
||||
else
|
||||
$szFilterQuery=" ".$NameField." = '".$ValueField."'";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
dol_syslog("Error we try to forge an sql export request with a condition on a field with type '".$InfoFieldList[0]."' (defined into module descriptor) but this type is unknown/not supported. It looks like a bug into module descriptor.", LOG_ERR);
|
||||
@ -589,10 +594,8 @@ class Export
|
||||
|
||||
$var=true;
|
||||
|
||||
while ($objp = $this->db->fetch_object($resql))
|
||||
while ($obj = $this->db->fetch_object($resql))
|
||||
{
|
||||
|
||||
|
||||
// Process special operations
|
||||
if (! empty($this->array_export_special[$indice]))
|
||||
{
|
||||
@ -604,14 +607,14 @@ class Export
|
||||
{
|
||||
//$alias=$this->array_export_alias[$indice][$key];
|
||||
$alias=str_replace(array('.', '-','(',')'),'_',$key);
|
||||
if ($objp->$alias < 0) $objp->$alias='';
|
||||
if ($obj->$alias < 0) $obj->$alias='';
|
||||
}
|
||||
// Operation ZEROIFNEG
|
||||
elseif ($this->array_export_special[$indice][$key]=='ZEROIFNEG')
|
||||
{
|
||||
//$alias=$this->array_export_alias[$indice][$key];
|
||||
$alias=str_replace(array('.', '-','(',')'),'_',$key);
|
||||
if ($objp->$alias < 0) $objp->$alias='0';
|
||||
if ($obj->$alias < 0) $obj->$alias='0';
|
||||
}
|
||||
// Operation INVOICEREMAINTOPAY
|
||||
elseif ($this->array_export_special[$indice][$key]=='getRemainToPay')
|
||||
@ -619,7 +622,7 @@ class Export
|
||||
//$alias=$this->array_export_alias[$indice][$key];
|
||||
$alias=str_replace(array('.', '-','(',')'),'_',$key);
|
||||
$remaintopay='';
|
||||
if ($objp->f_rowid > 0)
|
||||
if ($obj->f_rowid > 0)
|
||||
{
|
||||
global $tmpobjforcomputecall;
|
||||
if (! is_object($tmpobjforcomputecall))
|
||||
@ -627,21 +630,26 @@ class Export
|
||||
include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
|
||||
$tmpobjforcomputecall=new Facture($this->db);
|
||||
}
|
||||
$tmpobjforcomputecall->id = $objp->f_rowid;
|
||||
$tmpobjforcomputecall->total_ttc = $objp->f_total_ttc;
|
||||
$tmpobjforcomputecall->id = $obj->f_rowid;
|
||||
$tmpobjforcomputecall->total_ttc = $obj->f_total_ttc;
|
||||
$remaintopay=$tmpobjforcomputecall->getRemainToPay();
|
||||
}
|
||||
$objp->$alias=$remaintopay;
|
||||
$obj->$alias=$remaintopay;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error='Operation '.$this->array_export_special[$indice][$key].' not supported.';
|
||||
// TODO FIXME Export of compute field does not work. $obj containt $obj->alias_field and formulat will contains $obj->field
|
||||
$computestring=$this->array_export_special[$indice][$key];
|
||||
$tmp=dol_eval($computestring, 1, 0);
|
||||
$obj->$alias=$tmp;
|
||||
|
||||
$this->error="ERROPNOTSUPPORTED. Operation ".$this->array_export_special[$indice][$key]." not supported. Export of 'computed' extrafields is not yet supported, please remove field.";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
// end of special operation processing
|
||||
$objmodel->write_record($array_selected,$objp,$outputlangs,$this->array_export_TypeFields[$indice]);
|
||||
$objmodel->write_record($array_selected,$obj,$outputlangs,$this->array_export_TypeFields[$indice]);
|
||||
}
|
||||
|
||||
// Genere en-tete
|
||||
|
||||
@ -561,7 +561,7 @@ if ($step == 2 && $datatoexport)
|
||||
print '<td>'.$langs->trans("ExportableFields").'</td>';
|
||||
print '<td width="100" align="center">';
|
||||
print '<a class="liste_titre" title='.$langs->trans("All").' alt='.$langs->trans("All").' href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=selectfield&field=all">'.$langs->trans("All")."</a>";
|
||||
print '/';
|
||||
print ' / ';
|
||||
print '<a class="liste_titre" title='.$langs->trans("None").' alt='.$langs->trans("None").' href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=unselectfield&field=all">'.$langs->trans("None")."</a>";
|
||||
print '</td>';
|
||||
print '<td width="44%">'.$langs->trans("ExportedFields").'</td>';
|
||||
@ -606,7 +606,9 @@ if ($step == 2 && $datatoexport)
|
||||
}
|
||||
print img_object('',$entityicon).' '.$langs->trans($entitylang);
|
||||
print '</td>';
|
||||
$text=$langs->trans($label);
|
||||
|
||||
$text=(empty($objexport->array_export_special[0][$code])?'':'<i>').$langs->trans($label).(empty($objexport->array_export_special[0][$code])?'':'</i>');
|
||||
|
||||
$tablename=getablenamefromfield($code,$sqlmaxforexport);
|
||||
$htmltext ='<b>'.$langs->trans("Name").":</b> ".$text.'<br>';
|
||||
if (! empty($objexport->array_export_special[0][$code]))
|
||||
@ -617,11 +619,16 @@ if ($step == 2 && $datatoexport)
|
||||
{
|
||||
$htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>";
|
||||
}
|
||||
if (! empty($objexport->array_export_examplevalues[0][$code]))
|
||||
if (! empty($objexport->array_export_examplevalues[0][$code]))
|
||||
{
|
||||
$htmltext.=$langs->trans("SourceExample").': <b>'.$objexport->array_export_examplevalues[0][$code].'</b><br>';
|
||||
}
|
||||
if (isset($array_selected[$code]) && $array_selected[$code])
|
||||
if (! empty($objexport->array_export_TypeFields[0][$code]))
|
||||
{
|
||||
$htmltext.=$langs->trans("Type").': <b>'.$objexport->array_export_TypeFields[0][$code].'</b><br>';
|
||||
}
|
||||
|
||||
if (isset($array_selected[$code]) && $array_selected[$code])
|
||||
{
|
||||
// Selected fields
|
||||
print '<td> </td>';
|
||||
@ -772,7 +779,6 @@ if ($step == 3 && $datatoexport)
|
||||
// on boucle sur les champs
|
||||
foreach($fieldsarray as $code => $label)
|
||||
{
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
|
||||
$i++;
|
||||
@ -794,15 +800,27 @@ if ($step == 3 && $datatoexport)
|
||||
// Field name
|
||||
$labelName=(! empty($fieldsarray[$code])?$fieldsarray[$code]:'');
|
||||
$ValueFilter=(! empty($array_filtervalue[$code])?$array_filtervalue[$code]:'');
|
||||
$text=$langs->trans($labelName);
|
||||
$text=(empty($objexport->array_export_special[0][$code])?'':'<i>').$langs->trans($labelName).(empty($objexport->array_export_special[0][$code])?'':'</i>');
|
||||
|
||||
$tablename=getablenamefromfield($code,$sqlmaxforexport);
|
||||
$htmltext ='<b>'.$langs->trans("Name").':</b> '.$text.'<br>';
|
||||
$htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>";
|
||||
if (! empty($objexport->array_export_special[0][$code]))
|
||||
{
|
||||
$htmltext.='<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>";
|
||||
}
|
||||
else
|
||||
{
|
||||
$htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>";
|
||||
}
|
||||
if (! empty($objexport->array_export_examplevalues[0][$code]))
|
||||
{
|
||||
$htmltext.=$langs->trans("SourceExample").': <b>'.$objexport->array_export_examplevalues[0][$code].'</b><br>';
|
||||
}
|
||||
if (! empty($objexport->array_export_TypeFields[0][$code]))
|
||||
{
|
||||
$htmltext.=$langs->trans("Type").': <b>'.$objexport->array_export_TypeFields[0][$code].'</b><br>';
|
||||
}
|
||||
|
||||
print '<td>';
|
||||
print $form->textwithpicto($text,$htmltext);
|
||||
print '</td>';
|
||||
@ -957,7 +975,6 @@ if ($step == 4 && $datatoexport)
|
||||
$var=true;
|
||||
foreach($array_selected as $code=>$value)
|
||||
{
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
|
||||
$entity=(! empty($objexport->array_export_entities[0][$code])?$objexport->array_export_entities[0][$code]:$objexport->array_export_icon[0]);
|
||||
@ -975,15 +992,30 @@ if ($step == 4 && $datatoexport)
|
||||
print img_object('',$entityicon).' '.$langs->trans($entitylang);
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
$text=$langs->trans($objexport->array_export_fields[0][$code]);
|
||||
$labelName=$objexport->array_export_fields[0][$code];
|
||||
|
||||
$text=(empty($objexport->array_export_special[0][$code])?'':'<i>').$langs->trans($labelName).(empty($objexport->array_export_special[0][$code])?'':'</i>');
|
||||
|
||||
$tablename=getablenamefromfield($code,$sqlmaxforexport);
|
||||
$htmltext ='<b>'.$langs->trans("Name").":</b> ".$text.'<br>';
|
||||
$htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>";
|
||||
if (! empty($objexport->array_export_examplevalues[0][$code]))
|
||||
{
|
||||
$htmltext.=$langs->trans("SourceExample").': <b>'.$objexport->array_export_examplevalues[0][$code].'</b><br>';
|
||||
}
|
||||
$htmltext ='<b>'.$langs->trans("Name").':</b> '.$text.'<br>';
|
||||
if (! empty($objexport->array_export_special[0][$code]))
|
||||
{
|
||||
$htmltext.='<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>";
|
||||
}
|
||||
else
|
||||
{
|
||||
$htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>";
|
||||
}
|
||||
if (! empty($objexport->array_export_examplevalues[0][$code]))
|
||||
{
|
||||
$htmltext.=$langs->trans("SourceExample").': <b>'.$objexport->array_export_examplevalues[0][$code].'</b><br>';
|
||||
}
|
||||
if (! empty($objexport->array_export_TypeFields[0][$code]))
|
||||
{
|
||||
$htmltext.=$langs->trans("Type").': <b>'.$objexport->array_export_TypeFields[0][$code].'</b><br>';
|
||||
}
|
||||
|
||||
print '<td>';
|
||||
print $form->textwithpicto($text,$htmltext);
|
||||
//print ' ('.$code.')';
|
||||
print '</td>';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user