Fix filter on product on statistic page

This commit is contained in:
Laurent Destailleur 2021-10-31 12:54:08 +01:00
parent 82a35f82b4
commit dcc98b6026
2 changed files with 38 additions and 21 deletions

View File

@ -178,7 +178,7 @@ $arrayofmode = array(
'facture' => 'Facture'
);
$title .= ' '.$form->selectarray('mode', $arrayofmode, $mode, 1);
$title .= ' <input type="submit" class="button" name="refresh" value="'.$langs->trans("Refresh").'">';
$title .= ' <input type="submit" class="button small" name="refresh" value="'.$langs->trans("Refresh").'">';
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
@ -198,7 +198,7 @@ print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sort
print '<table class="noborder centpercent">';
print "<tr class=\"liste_titre\">";
print '<tr class="liste_titre">';
print_liste_field_titre('Ref', $_SERVER["PHP_SELF"], 'p.ref', '', $param, '', $sortfield, $sortorder);
print_liste_field_titre('Type', $_SERVER["PHP_SELF"], 'p.fk_product_type', '', $param, '', $sortfield, $sortorder);
print_liste_field_titre('Label', $_SERVER["PHP_SELF"], 'p.label', '', $param, '', $sortfield, $sortorder);

View File

@ -45,6 +45,7 @@ $ref = GETPOST('ref', 'alpha');
$mode = (GETPOST('mode', 'alpha') ? GETPOST('mode', 'alpha') : 'byunit');
$search_year = GETPOST('search_year', 'int');
$search_categ = GETPOST('search_categ', 'int');
$notab = GETPOST('notab', 'int');
$error = 0;
$mesg = '';
@ -56,7 +57,7 @@ if (!empty($user->socid)) {
}
// Security check
$fieldvalue = (!empty($id) ? $id : $ref);
$fieldvalue = ($id > 0 ? $id : $ref);
$fieldtype = (!empty($ref) ? 'ref' : 'rowid');
$tmp = dol_getdate(dol_now());
@ -65,6 +66,11 @@ if (empty($search_year)) {
$search_year = $currentyear;
}
$object = new Product($db);
if ($id > 0 || !empty($ref)) {
$result = $object->fetch($id, $ref);
}
$result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
@ -81,9 +87,10 @@ $result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product
$form = new Form($db);
$htmlother = new FormOther($db);
$object = new Product($db);
if (!$id && empty($ref)) {
if (!($id > 0) && empty($ref) || $notab) {
$notab = 1;
llxHeader("", $langs->trans("ProductStatistics"));
$type = GETPOST('type', 'int');
@ -128,7 +135,7 @@ if (!$id && empty($ref)) {
}
if ($result && (!empty($id) || !empty($ref))) {
if ($result && ($id > 0 || !empty($ref)) && empty($notab)) {
$head = product_prepare_head($object);
$titre = $langs->trans("CardProduct".$object->type);
$picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
@ -141,11 +148,11 @@ if ($result && (!empty($id) || !empty($ref))) {
print dol_get_fiche_end();
}
if (empty($id) && empty($ref)) {
if ((!($id > 0) && empty($ref)) || $notab) {
$h = 0;
$head = array();
$head[$h][0] = DOL_URL_ROOT.'/product/stats/card.php'.($type != '' ? '?type='.$type : '');
$head[$h][0] = DOL_URL_ROOT.'/product/stats/card.php'.($type != '' ? '?type='.((int) $type) : '');
$head[$h][1] = $langs->trans("Chart");
$head[$h][2] = 'chart';
$h++;
@ -158,7 +165,7 @@ if (empty($id) && empty($ref)) {
$title = $langs->trans("ListProductByPopularity");
}
$head[$h][0] = DOL_URL_ROOT.'/product/popuprop.php'.($type != '' ? '?type='.$type : '');
$head[$h][0] = DOL_URL_ROOT.'/product/popuprop.php'.($type != '' ? '?type='.((int) $type) : '');
$head[$h][1] = $langs->trans("ProductsPerPopularity");
$head[$h][2] = 'popularity';
$h++;
@ -167,21 +174,29 @@ if (empty($id) && empty($ref)) {
}
if ($result || empty($id)) {
if ($result || !($id > 0)) {
print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="id" value="'.$id.'">';
if (empty($id) || $notab) {
print '<input type="hidden" name="notab" value="1">';
}
print '<table class="noborder centpercent">';
print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
if (empty($id)) {
if (!($id > 0) || $notab) {
// Type
print '<tr><td class="titlefield">'.$langs->trans("ProductsAndServices").'</td><td>';
print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td>';
$array = array('-1'=>'&nbsp;', '0'=>$langs->trans('Product'), '1'=>$langs->trans('Service'));
print $form->selectarray('type', $array, $type);
print '</td></tr>';
// Product
print '<tr><td class="titlefield">'.$langs->trans("ProductOrService").'</td><td>';
print img_picto('', 'product', 'class="pictofixedwidth"');
print $form->select_produits($id, 'id', '', 0, 0, 1, 2, '', 0, array(), 0, '1', 0, 'maxwidth500');
print '</td></tr>';
// Tag
if ($conf->categorie->enabled) {
print '<tr><td class="titlefield">'.$langs->trans("Categories").'</td><td>';
@ -190,6 +205,8 @@ if ($result || empty($id)) {
print $moreforfilter;
print '</td></tr>';
}
} else {
print '<input type="hidden" name="id" value="'.$id.'">';
}
// Year
@ -220,7 +237,7 @@ if ($result || empty($id)) {
}
if ($mode == 'bynumber') {
print '<a class="a-mesure-disabled" href="'.$_SERVER["PHP_SELF"].'?id='.(GETPOST('id') ?GETPOST('id') : $object->id).($type != '' ? '&type='.$type : '').'&mode=byunit&search_year='.$search_year.'">';
print '<a class="a-mesure-disabled" href="'.$_SERVER["PHP_SELF"].'?'.(GETPOSTISSET('id') ? 'id='.GETPOST('id', 'int') : 'id='.$object->id).(($type != '' && $type != '-1') ? '&type='.((int) $type) : '').'&mode=byunit&search_year='.((int) $search_year).($notab ? '&notab='.$notab : '').'">';
} else {
print '<span class="a-mesure">';
}
@ -238,7 +255,7 @@ if ($result || empty($id)) {
}
if ($mode == 'byunit') {
print '<a class="a-mesure-disabled" href="'.$_SERVER["PHP_SELF"].'?id='.(GETPOST('id') ?GETPOST('id') : $object->id).($type != '' ? '&type='.$type : '').'&mode=bynumber&search_year='.$search_year.'">';
print '<a class="a-mesure-disabled" href="'.$_SERVER["PHP_SELF"].'?'.(GETPOSTISSET('id') ? 'id='.GETPOST('id', 'int') : 'id='.$object->id).(($type != '' && $type != '-1') ? '&type='.((int) $type) : '').'&mode=bynumber&search_year='.((int) $search_year).($notab ? '&notab='.$notab : '').'">';
} else {
print '<span class="a-mesure">';
}
@ -256,9 +273,7 @@ if ($result || empty($id)) {
}
print '<br>';
//print '<table width="100%">';
// Generation des graphs
// Generation of graphs
$dir = (!empty($conf->product->multidir_temp[$object->entity]) ? $conf->product->multidir_temp[$object->entity] : $conf->service->multidir_temp[$object->entity]);
if ($object->id > 0) { // We are on statistics for a dedicated product
if (!file_exists($dir.'/'.$object->id)) {
@ -383,7 +398,7 @@ if ($result || empty($id)) {
$px->SetShading(3);
//print 'x '.$key.' '.$graphfiles[$key]['file'];
$url = DOL_URL_ROOT.'/viewimage.php?modulepart='.$graphfiles[$key]['modulepart'].'&entity='.$object->entity.'&file='.urlencode($graphfiles[$key]['file']);
$url = DOL_URL_ROOT.'/viewimage.php?modulepart='.$graphfiles[$key]['modulepart'].'&entity='.((int) $object->entity).'&file='.urlencode($graphfiles[$key]['file']).($notab ? '&notab='.$notab : '');
$px->draw($dir."/".$graphfiles[$key]['file'], $url);
$graphfiles[$key]['total'] = $px->total();
@ -444,7 +459,9 @@ if ($result || empty($id)) {
} else {
$dategenerated = ($mesg ? '<font class="error">'.$mesg.'</font>' : $langs->trans("ChartNotGenerated"));
}
$linktoregenerate = '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.(GETPOST('id') ?GETPOST('id') : $object->id).((string) $type != '' ? '&type='.$type : '').'&action=recalcul&mode='.$mode.'&search_year='.$search_year.'&search_categ='.$search_categ.'">'.img_picto($langs->trans("ReCalculate").' ('.$dategenerated.')', 'refresh').'</a>';
$linktoregenerate = '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?'.(GETPOSTISSET('id') ? 'id='.GETPOST('id', 'int') : 'id='.$object->id).(((string) $type != '' && $type != '-1') ? '&type='.((int) $type) : '').'&action=recalcul&mode='.urlencode($mode).'&search_year='.((int) $search_year).($search_categ > 0 ? '&search_categ='.((int) $search_categ) : '').'">';
$linktoregenerate .= img_picto($langs->trans("ReCalculate").' ('.$dategenerated.')', 'refresh');
$linktoregenerate .= '</a>';
// Show graph
print '<table class="noborder centpercent">';
@ -478,7 +495,7 @@ if ($result || empty($id)) {
}
}
if (!$id) {
if (!($id > 0)) {
print dol_get_fiche_end();
}