diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index 3b5dbd664d6..68af8236fc3 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -1338,4 +1338,118 @@ class FormOther $resultautomanual .= ''."\n"; return $resultautomanual; } + + + /** + * Return HTML select list to select a group by field + * + * @param mixed $object Object analyzed + * @param array $search_groupby Array of preselected fields + * @param array $arrayofgroupby Array of groupby to fill + * @return string HTML string component + */ + public function selectGroupByField($object, $search_groupby, &$arrayofgroupby) { + global $langs, $extrafields, $form; + + $YYYY=substr($langs->trans("Year"), 0, 1).substr($langs->trans("Year"), 0, 1).substr($langs->trans("Year"), 0, 1).substr($langs->trans("Year"), 0, 1); + $MM=substr($langs->trans("Month"), 0, 1).substr($langs->trans("Month"), 0, 1); + $DD=substr($langs->trans("Day"), 0, 1).substr($langs->trans("Day"), 0, 1); + $HH=substr($langs->trans("Hour"), 0, 1).substr($langs->trans("Hour"), 0, 1); + $MI=substr($langs->trans("Minute"), 0, 1).substr($langs->trans("Minute"), 0, 1); + $SS=substr($langs->trans("Second"), 0, 1).substr($langs->trans("Second"), 0, 1); + + foreach ($object->fields as $key => $val) { + if (!$val['measure']) { + if (in_array($key, array( + 'id', 'ref_int', 'ref_ext', 'rowid', 'entity', 'last_main_doc', 'logo', 'logo_squarred', 'extraparams', + 'parent', 'photo', 'socialnetworks', 'webservices_url', 'webservices_key'))) continue; + if (isset($val['enabled']) && !dol_eval($val['enabled'], 1)) continue; + if (isset($val['visible']) && !dol_eval($val['visible'], 1)) continue; + if (preg_match('/^fk_/', $key) && !preg_match('/^fk_statu/', $key)) continue; + if (preg_match('/^pass/', $key)) continue; + if (in_array($val['type'], array('html', 'text'))) continue; + if (in_array($val['type'], array('timestamp', 'date', 'datetime'))) { + $arrayofgroupby['t.'.$key.'-year'] = array('label' => $langs->trans($val['label']).' ('.$YYYY.')', 'position' => $val['position'].'-y'); + $arrayofgroupby['t.'.$key.'-month'] = array('label' => $langs->trans($val['label']).' ('.$YYYY.'-'.$MM.')', 'position' => $val['position'].'-m'); + $arrayofgroupby['t.'.$key.'-day'] = array('label' => $langs->trans($val['label']).' ('.$YYYY.'-'.$MM.'-'.$DD.')', 'position' => $val['position'].'-d'); + } else { + $arrayofgroupby['t.'.$key] = array('label' => $langs->trans($val['label']), 'position' => (int) $val['position']); + } + } + } + // Add extrafields to Group by + if ($object->isextrafieldmanaged) { + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { + if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') continue; + if (!empty($extrafields->attributes[$object->table_element]['totalizable'][$key])) continue; + $arrayofgroupby['te.'.$key] = array('label' => $langs->trans($extrafields->attributes[$object->table_element]['label'][$key]), 'position' => 1000 + (int) $extrafields->attributes[$object->table_element]['pos'][$key]); + } + } + + $arrayofgroupby = dol_sort_array($arrayofgroupby, 'position', 'asc', 1); + $arrayofgroupbylabel = array(); + foreach ($arrayofgroupby as $key => $val) { + $arrayofgroupbylabel[$key] = $val['label']; + } + $result = $form->selectarray('search_groupby', $arrayofgroupbylabel, $search_groupby, 1, 0, 0, '', 0, 0, 0, '', 'minwidth250', 1); + + return $result; + } + + /** + * Return HTML select list to select a group by field + * + * @param mixed $object Object analyzed + * @param array $search_xaxis Array of preselected fields + * @param array $arrayofxaxis Array of groupby to fill + * @return string HTML string component + */ + public function selectXAxisField($object, $search_xaxis, &$arrayofxaxis) { + global $langs, $extrafields, $form; + + $YYYY=substr($langs->trans("Year"), 0, 1).substr($langs->trans("Year"), 0, 1).substr($langs->trans("Year"), 0, 1).substr($langs->trans("Year"), 0, 1); + $MM=substr($langs->trans("Month"), 0, 1).substr($langs->trans("Month"), 0, 1); + $DD=substr($langs->trans("Day"), 0, 1).substr($langs->trans("Day"), 0, 1); + $HH=substr($langs->trans("Hour"), 0, 1).substr($langs->trans("Hour"), 0, 1); + $MI=substr($langs->trans("Minute"), 0, 1).substr($langs->trans("Minute"), 0, 1); + $SS=substr($langs->trans("Second"), 0, 1).substr($langs->trans("Second"), 0, 1); + + + foreach ($object->fields as $key => $val) { + if (!$val['measure']) { + if (in_array($key, array( + 'id', 'ref_int', 'ref_ext', 'rowid', 'entity', 'last_main_doc', 'logo', 'logo_squarred', 'extraparams', + 'parent', 'photo', 'socialnetworks', 'webservices_url', 'webservices_key'))) continue; + if (isset($val['enabled']) && !dol_eval($val['enabled'], 1)) continue; + if (isset($val['visible']) && !dol_eval($val['visible'], 1)) continue; + if (preg_match('/^fk_/', $key) && !preg_match('/^fk_statu/', $key)) continue; + if (preg_match('/^pass/', $key)) continue; + if (in_array($val['type'], array('html', 'text'))) continue; + if (in_array($val['type'], array('timestamp', 'date', 'datetime'))) { + $arrayofxaxis['t.'.$key.'-year'] = array('label' => $langs->trans($val['label']).' ('.$YYYY.')', 'position' => $val['position'].'-y'); + $arrayofxaxis['t.'.$key.'-month'] = array('label' => $langs->trans($val['label']).' ('.$YYYY.'-'.$MM.')', 'position' => $val['position'].'-m'); + $arrayofxaxis['t.'.$key.'-day'] = array('label' => $langs->trans($val['label']).' ('.$YYYY.'-'.$MM.'-'.$DD.')', 'position' => $val['position'].'-d'); + } else { + $arrayofxaxis['t.'.$key] = array('label' => $val['label'], 'position' => (int) $val['position']); + } + } + } + // Add extrafields to X-Axis + if ($object->isextrafieldmanaged) { + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { + if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') continue; + if (!empty($extrafields->attributes[$object->table_element]['totalizable'][$key])) continue; + $arrayofxaxis['te.'.$key] = array('label' => $extrafields->attributes[$object->table_element]['label'][$key], 'position' => (int) $extrafields->attributes[$object->table_element]['pos'][$key]); + } + } + + $arrayofxaxis = dol_sort_array($arrayofxaxis, 'position', 'asc', 1); + $arrayofxaxislabel = array(); + foreach ($arrayofxaxis as $key => $val) { + $arrayofxaxislabel[$key] = $val['label']; + } + $result = $form->selectarray('search_xaxis', $arrayofxaxislabel, $search_xaxis, 0, 0, 0, '', 0, 0, 0, '', 'minwidth250', 1); + + return $result; + } } diff --git a/htdocs/core/customreports.php b/htdocs/core/customreports.php index 01874092d4d..e0e8012e21c 100644 --- a/htdocs/core/customreports.php +++ b/htdocs/core/customreports.php @@ -28,10 +28,6 @@ if (!defined('USE_CUSTOME_REPORT_AS_INCLUDE')) { require '../main.inc.php'; - require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php"; - require_once DOL_DOCUMENT_ROOT."/core/lib/company.lib.php"; - require_once DOL_DOCUMENT_ROOT."/core/class/dolgraph.class.php"; - require_once DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php"; // Get parameters $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ... @@ -45,8 +41,14 @@ if (!defined('USE_CUSTOME_REPORT_AS_INCLUDE')) $search_filters = GETPOST('search_filters', 'array'); $search_measures = GETPOST('search_measures', 'array'); - $search_xaxis = GETPOST('search_xaxis', 'array'); - $search_groupby = GETPOST('search_groupby', 'array'); + + //$search_xaxis = GETPOST('search_xaxis', 'array'); + if (GETPOST('search_xaxis', 'alpha') && GETPOST('search_xaxis', 'alpha') != '-1') $search_xaxis = array(GETPOST('search_xaxis', 'alpha')); + else $search_xaxis = array(); + //$search_groupby = GETPOST('search_groupby', 'array'); + if (GETPOST('search_groupby', 'alpha') && GETPOST('search_groupby', 'alpha') != '-1') $search_groupby = array(GETPOST('search_groupby', 'alpha')); + else $search_groupby = array(); + $search_yaxis = GETPOST('search_yaxis', 'array'); $search_graph = GETPOST('search_graph', 'none'); @@ -63,6 +65,12 @@ if (!defined('USE_CUSTOME_REPORT_AS_INCLUDE')) $diroutputmassaction = $conf->user->dir_temp.'/'.$user->id.'/customreport'; } +require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php"; +require_once DOL_DOCUMENT_ROOT."/core/lib/company.lib.php"; +require_once DOL_DOCUMENT_ROOT."/core/class/dolgraph.class.php"; +require_once DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php"; +require_once DOL_DOCUMENT_ROOT."/core/class/html.formother.class.php"; + // Load traductions files requiredby by page $langs->loadLangs(array("companies", "other", "exports")); @@ -144,6 +152,7 @@ $search_component_params = array(''); $MAXUNIQUEVALFORGROUP = 20; $MAXMEASURESINBARGRAPH = 20; + $YYYY=substr($langs->trans("Year"), 0, 1).substr($langs->trans("Year"), 0, 1).substr($langs->trans("Year"), 0, 1).substr($langs->trans("Year"), 0, 1); $MM=substr($langs->trans("Month"), 0, 1).substr($langs->trans("Month"), 0, 1); $DD=substr($langs->trans("Day"), 0, 1).substr($langs->trans("Day"), 0, 1); @@ -172,6 +181,7 @@ $arrayofvaluesforgroupby = array(); */ $form = new Form($db); +$formother = new FormOther($db); if (!defined('USE_CUSTOME_REPORT_AS_INCLUDE')) { llxHeader('', $langs->transnoentitiesnoconv('CustomReports'), ''); @@ -200,7 +210,6 @@ if ($action == 'viewgraph') { } } - // Get all possible values of fields when a 'group by' is set and save this into $arrayofvaluesforgroupby if (is_array($search_groupby) && count($search_groupby)) { foreach($search_groupby as $gkey => $gval) { @@ -330,86 +339,21 @@ print ''; // Group by print '
'; -foreach ($object->fields as $key => $val) { - if (!$val['measure']) { - if (in_array($key, array( - 'id', 'ref_int', 'ref_ext', 'rowid', 'entity', 'last_main_doc', 'logo', 'logo_squarred', 'extraparams', - 'parent', 'photo', 'socialnetworks', 'webservices_url', 'webservices_key'))) continue; - if (isset($val['enabled']) && !dol_eval($val['enabled'], 1)) continue; - if (isset($val['visible']) && !dol_eval($val['visible'], 1)) continue; - if (preg_match('/^fk_/', $key) && !preg_match('/^fk_statu/', $key)) continue; - if (preg_match('/^pass/', $key)) continue; - if (in_array($val['type'], array('html', 'text'))) continue; - if (in_array($val['type'], array('timestamp', 'date', 'datetime'))) { - $arrayofgroupby['t.'.$key.'-year'] = array('label' => $langs->trans($val['label']).' ('.$YYYY.')', 'position' => $val['position'].'-y'); - $arrayofgroupby['t.'.$key.'-month'] = array('label' => $langs->trans($val['label']).' ('.$YYYY.'-'.$MM.')', 'position' => $val['position'].'-m'); - $arrayofgroupby['t.'.$key.'-day'] = array('label' => $langs->trans($val['label']).' ('.$YYYY.'-'.$MM.'-'.$DD.')', 'position' => $val['position'].'-d'); - } else { - $arrayofgroupby['t.'.$key] = array('label' => $val['label'], 'position' => (int) $val['position']); - } - } -} -// Add extrafields to Group by -if ($object->isextrafieldmanaged) { - foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { - if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') continue; - if (!empty($extrafields->attributes[$object->table_element]['totalizable'][$key])) continue; - $arrayofgroupby['te.'.$key] = array('label' => $extrafields->attributes[$object->table_element]['label'][$key], 'position' => (int) $extrafields->attributes[$object->table_element]['pos'][$key]); - } -} - -$arrayofgroupby = dol_sort_array($arrayofgroupby, 'position', 'asc', 1); -$arrayofgroupbylabel = array(); -foreach ($arrayofgroupby as $key => $val) { - $arrayofgroupbylabel[$key] = $val['label']; -} print '
'.$langs->trans("GroupBy").'
'; -print $form->multiselectarray('search_groupby', $arrayofgroupbylabel, $search_groupby, 0, 0, 'minwidth250', 1); +print $formother->selectGroupByField($object, $search_groupby, $arrayofgroupby); print '
'; // XAxis print '
'; -foreach ($object->fields as $key => $val) { - if (!$val['measure']) { - if (in_array($key, array( - 'id', 'ref_int', 'ref_ext', 'rowid', 'entity', 'last_main_doc', 'logo', 'logo_squarred', 'extraparams', - 'parent', 'photo', 'socialnetworks', 'webservices_url', 'webservices_key'))) continue; - if (isset($val['enabled']) && !dol_eval($val['enabled'], 1)) continue; - if (isset($val['visible']) && !dol_eval($val['visible'], 1)) continue; - if (preg_match('/^fk_/', $key) && !preg_match('/^fk_statu/', $key)) continue; - if (preg_match('/^pass/', $key)) continue; - if (in_array($val['type'], array('html', 'text'))) continue; - if (in_array($val['type'], array('timestamp', 'date', 'datetime'))) { - $arrayofxaxis['t.'.$key.'-year'] = array('label' => $langs->trans($val['label']).' ('.$YYYY.')', 'position' => $val['position'].'-y'); - $arrayofxaxis['t.'.$key.'-month'] = array('label' => $langs->trans($val['label']).' ('.$YYYY.'-'.$MM.')', 'position' => $val['position'].'-m'); - $arrayofxaxis['t.'.$key.'-day'] = array('label' => $langs->trans($val['label']).' ('.$YYYY.'-'.$MM.'-'.$DD.')', 'position' => $val['position'].'-d'); - } else { - $arrayofxaxis['t.'.$key] = array('label' => $val['label'], 'position' => (int) $val['position']); - } - } -} -// Add extrafields to X-Axis -if ($object->isextrafieldmanaged) { - foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { - if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') continue; - if (!empty($extrafields->attributes[$object->table_element]['totalizable'][$key])) continue; - $arrayofxaxis['te.'.$key] = array('label' => $extrafields->attributes[$object->table_element]['label'][$key], 'position' => (int) $extrafields->attributes[$object->table_element]['pos'][$key]); - } -} - -$arrayofxaxis = dol_sort_array($arrayofxaxis, 'position', 'asc', 1); -$arrayofxaxislabel = array(); -foreach ($arrayofxaxis as $key => $val) { - $arrayofxaxislabel[$key] = $val['label']; -} print '
'.$langs->trans("XAxis").'
'; -print $form->multiselectarray('search_xaxis', $arrayofxaxislabel, $search_xaxis, 0, 0, 'minwidth250', 1); +print $formother->selectXAxisField($object, $search_xaxis, $arrayofxaxis); print '
'; -// YAxis + if ($mode == 'grid') { - print '
'; + // YAxis + print '
'; foreach ($object->fields as $key => $val) { if (!$val['measure']) { if (in_array($key, array('id', 'rowid', 'entity', 'last_main_doc', 'extraparams'))) continue; @@ -527,7 +471,7 @@ if (!empty($search_measures) && !empty($search_xaxis)) $sql .= ' AND entity IN ('.getEntity($object->element).')'; } foreach ($search_filters as $key => $val) { - // TODO + // TODO Add the where here } $sql .= ' GROUP BY '; foreach ($search_xaxis as $key => $val) { diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 2e9d4f91499..22c9d180f97 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -234,7 +234,7 @@ ErrorLanguageOfTranslatedPageIsSameThanThisPage=Error, language of translated pa ErrorBatchNoFoundForProductInWarehouse=No lot/serial found for product "%s" in warehouse "%s". ErrorBatchNoFoundEnoughQuantityForProductInWarehouse=No enough quantity for this lot/serial for product "%s" in warehouse "%s". ErrorOnlyOneFieldForGroupByIsPossible=Only 1 field for the 'Group by' is possible (others are discarded) -ErrorTooManyDifferentValueForSelectedGroupBy=Too many different value (more than %s) for field '%s' to use it as a 'Group by' for graphics. Group By field has been removed. May be you wanted to use it as an X-Axis +ErrorTooManyDifferentValueForSelectedGroupBy=Found too many different value (more than %s) for the field '%s', so we can't user it as a 'Group by' for graphics. The field 'Group By' has been removed. May be you wanted to use it as an X-Axis ? # Warnings WarningParamUploadMaxFileSizeHigherThanPostMaxSize=Your PHP parameter upload_max_filesize (%s) is higher than PHP parameter post_max_size (%s). This is not a consistent setup. WarningPasswordSetWithNoAccount=A password was set for this member. However, no user account was created. So this password is stored but can't be used to login to Dolibarr. It may be used by an external module/interface but if you don't need to define any login nor password for a member, you can disable option "Manage a login for each member" from Member module setup. If you need to manage a login but don't need any password, you can keep this field empty to avoid this warning. Note: Email can also be used as a login if the member is linked to a user.