--- /tmp/dsg/dolibarr/htdocs/commande/stats/github_19.0.3_index.php +++ /tmp/dsg/dolibarr/htdocs/commande/stats/client_index.php @@ -29 +28,0 @@ -// Load Dolibarr environment @@ -42,23 +41,5 @@ -$mode = GETPOSTISSET("mode") ? GETPOST("mode", 'aZ09') : 'customer'; - -$usercanreadcustumerstatistic = $user->hasRight('commande', 'lire'); -$usercanreadsupplierstatistic = $user->hasRight('fournisseur', 'commande', 'lire'); -if (getDolGlobalInt('MAIN_NEED_EXPORT_PERMISSION_TO_READ_STATISTICS')) { - $usercanreadcustumerstatistic = $user->hasRight('commande', 'commande', 'export'); - $usercanreadsupplierstatistic = $user->hasRight('fournisseur', 'commande', 'export'); -} -if ($mode == 'customer' && !$usercanreadcustumerstatistic) { - accessforbidden(); -} -if ($mode == 'supplier' && !$usercanreadsupplierstatistic) { - accessforbidden(); -} - -if ($mode == 'supplier') { - $object_status = GETPOST('object_status', 'array:int'); - $object_status = implode(',', $object_status); -} else { - $object_status = GETPOST('object_status', 'intcomma'); -} - - +$mode = GETPOST("mode") ?GETPOST("mode") : 'customer'; +if ($mode == 'customer' && !$user->rights->commande->lire) accessforbidden(); +if ($mode == 'supplier' && !$user->rights->fournisseur->commande->lire) accessforbidden(); + +$object_status = GETPOST('object_status'); @@ -71,8 +52,10 @@ -if ($user->socid > 0) { - $action = ''; - $socid = $user->socid; -} - -$nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt'); -$year = GETPOST('year') > 0 ? GETPOST('year') : $nowyear; -$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS')))); +if ($user->socid > 0) +{ + $action = ''; + $socid = $user->socid; +} + +$nowyear = strftime("%Y", dol_now()); +$year = GETPOST('year') > 0 ?GETPOST('year') : $nowyear; +//$startyear=$year-2; +$startyear = $year - 1; @@ -98 +81,2 @@ -if ($mode == 'supplier') { +if ($mode == 'supplier') +{ @@ -100,2 +84,2 @@ - $title = $langs->trans("OrdersStatisticsSuppliers"); - $dir = $conf->fournisseur->commande->dir_temp; + $title = $langs->trans("OrdersStatisticsSuppliers").' ('.$langs->trans("SentToSuppliers").")"; + $dir = $conf->fournisseur->commande->dir_temp; @@ -111,9 +95,7 @@ -if ($mode == 'customer') { - if ($object_status != '' && $object_status >= -1) { - $stats->where .= ' AND c.fk_statut IN ('.$db->sanitize($object_status).')'; - } -} -if ($mode == 'supplier') { - if ($object_status != '' && $object_status >= 0) { - $stats->where .= ' AND c.fk_statut IN ('.$db->sanitize($object_status).')'; - } +if ($mode == 'customer') +{ + if ($object_status != '' && $object_status >= -1) $stats->where .= ' AND c.fk_statut IN ('.$db->escape($object_status).')'; +} +if ($mode == 'supplier') +{ + if ($object_status != '' && $object_status >= 0) $stats->where .= ' AND c.fk_statut IN ('.$db->escape($object_status).')'; @@ -130,16 +112,11 @@ -if (!$user->hasRight('societe', 'client', 'voir') || $user->socid) { - $filenamenb = $dir.'/ordersnbinyear-'.$user->id.'-'.$year.'.png'; - if ($mode == 'customer') { - $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$user->id.'-'.$year.'.png'; - } - if ($mode == 'supplier') { - $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$user->id.'-'.$year.'.png'; - } -} else { - $filenamenb = $dir.'/ordersnbinyear-'.$year.'.png'; - if ($mode == 'customer') { - $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$year.'.png'; - } - if ($mode == 'supplier') { - $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$year.'.png'; - } +if (!$user->rights->societe->client->voir || $user->socid) +{ + $filenamenb = $dir.'/ordersnbinyear-'.$user->id.'-'.$year.'.png'; + if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$user->id.'-'.$year.'.png'; + if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$user->id.'-'.$year.'.png'; +} +else +{ + $filenamenb = $dir.'/ordersnbinyear-'.$year.'.png'; + if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$year.'.png'; + if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$year.'.png'; @@ -150,20 +127,21 @@ -if (!$mesg) { - $px1->SetData($data); - $i = $startyear; - $legend = array(); - while ($i <= $endyear) { - $legend[] = $i; - $i++; - } - $px1->SetLegend($legend); - $px1->SetMaxValue($px1->GetCeilMaxValue()); - $px1->SetMinValue(min(0, $px1->GetFloorMinValue())); - $px1->SetWidth($WIDTH); - $px1->SetHeight($HEIGHT); - $px1->SetYLabel($langs->trans("NbOfOrder")); - $px1->SetShading(3); - $px1->SetHorizTickIncrement(1); - $px1->mode = 'depth'; - $px1->SetTitle($langs->trans("NumberOfOrdersByMonth")); - - $px1->draw($filenamenb, $fileurlnb); +if (!$mesg) +{ + $px1->SetData($data); + $i = $startyear; $legend = array(); + while ($i <= $endyear) + { + $legend[] = $i; + $i++; + } + $px1->SetLegend($legend); + $px1->SetMaxValue($px1->GetCeilMaxValue()); + $px1->SetMinValue(min(0, $px1->GetFloorMinValue())); + $px1->SetWidth($WIDTH); + $px1->SetHeight($HEIGHT); + $px1->SetYLabel($langs->trans("NbOfOrder")); + $px1->SetShading(3); + $px1->SetHorizTickIncrement(1); + $px1->mode = 'depth'; + $px1->SetTitle($langs->trans("NumberOfOrdersByMonth")); + + $px1->draw($filenamenb, $fileurlnb); @@ -177,16 +155,11 @@ -if (!$user->hasRight('societe', 'client', 'voir') || $user->socid) { - $filenameamount = $dir.'/ordersamountinyear-'.$user->id.'-'.$year.'.png'; - if ($mode == 'customer') { - $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$user->id.'-'.$year.'.png'; - } - if ($mode == 'supplier') { - $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$user->id.'-'.$year.'.png'; - } -} else { - $filenameamount = $dir.'/ordersamountinyear-'.$year.'.png'; - if ($mode == 'customer') { - $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$year.'.png'; - } - if ($mode == 'supplier') { - $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$year.'.png'; - } +if (!$user->rights->societe->client->voir || $user->socid) +{ + $filenameamount = $dir.'/ordersamountinyear-'.$user->id.'-'.$year.'.png'; + if ($mode == 'customer') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$user->id.'-'.$year.'.png'; + if ($mode == 'supplier') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$user->id.'-'.$year.'.png'; +} +else +{ + $filenameamount = $dir.'/ordersamountinyear-'.$year.'.png'; + if ($mode == 'customer') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$year.'.png'; + if ($mode == 'supplier') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$year.'.png'; @@ -197,20 +170,21 @@ -if (!$mesg) { - $px2->SetData($data); - $i = $startyear; - $legend = array(); - while ($i <= $endyear) { - $legend[] = $i; - $i++; - } - $px2->SetLegend($legend); - $px2->SetMaxValue($px2->GetCeilMaxValue()); - $px2->SetMinValue(min(0, $px2->GetFloorMinValue())); - $px2->SetWidth($WIDTH); - $px2->SetHeight($HEIGHT); - $px2->SetYLabel($langs->trans("AmountOfOrders")); - $px2->SetShading(3); - $px2->SetHorizTickIncrement(1); - $px2->mode = 'depth'; - $px2->SetTitle($langs->trans("AmountOfOrdersByMonthHT")); - - $px2->draw($filenameamount, $fileurlamount); +if (!$mesg) +{ + $px2->SetData($data); + $i = $startyear; $legend = array(); + while ($i <= $endyear) + { + $legend[] = $i; + $i++; + } + $px2->SetLegend($legend); + $px2->SetMaxValue($px2->GetCeilMaxValue()); + $px2->SetMinValue(min(0, $px2->GetFloorMinValue())); + $px2->SetWidth($WIDTH); + $px2->SetHeight($HEIGHT); + $px2->SetYLabel($langs->trans("AmountOfOrders")); + $px2->SetShading(3); + $px2->SetHorizTickIncrement(1); + $px2->mode = 'depth'; + $px2->SetTitle($langs->trans("AmountOfOrdersByMonthHT")); + + $px2->draw($filenameamount, $fileurlamount); @@ -222,16 +196,11 @@ -if (!$user->hasRight('societe', 'client', 'voir') || $user->socid) { - $filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png'; - if ($mode == 'customer') { - $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png'; - } - if ($mode == 'supplier') { - $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png'; - } -} else { - $filename_avg = $dir.'/ordersaverage-'.$year.'.png'; - if ($mode == 'customer') { - $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png'; - } - if ($mode == 'supplier') { - $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png'; - } +if (!$user->rights->societe->client->voir || $user->socid) +{ + $filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png'; + if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png'; + if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png'; +} +else +{ + $filename_avg = $dir.'/ordersaverage-'.$year.'.png'; + if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png'; + if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png'; @@ -242,20 +211,21 @@ -if (!$mesg) { - $px3->SetData($data); - $i = $startyear; - $legend = array(); - while ($i <= $endyear) { - $legend[] = $i; - $i++; - } - $px3->SetLegend($legend); - $px3->SetYLabel($langs->trans("AmountAverage")); - $px3->SetMaxValue($px3->GetCeilMaxValue()); - $px3->SetMinValue($px3->GetFloorMinValue()); - $px3->SetWidth($WIDTH); - $px3->SetHeight($HEIGHT); - $px3->SetShading(3); - $px3->SetHorizTickIncrement(1); - $px3->mode = 'depth'; - $px3->SetTitle($langs->trans("AmountAverage")); - - $px3->draw($filename_avg, $fileurl_avg); +if (!$mesg) +{ + $px3->SetData($data); + $i = $startyear; $legend = array(); + while ($i <= $endyear) + { + $legend[] = $i; + $i++; + } + $px3->SetLegend($legend); + $px3->SetYLabel($langs->trans("AmountAverage")); + $px3->SetMaxValue($px3->GetCeilMaxValue()); + $px3->SetMinValue($px3->GetFloorMinValue()); + $px3->SetWidth($WIDTH); + $px3->SetHeight($HEIGHT); + $px3->SetShading(3); + $px3->SetHorizTickIncrement(1); + $px3->mode = 'depth'; + $px3->SetTitle($langs->trans("AmountAverage")); + + $px3->draw($filename_avg, $fileurl_avg); @@ -274,3 +244 @@ -if (!count($arrayyears)) { - $arrayyears[$nowyear] = $nowyear; -} +if (!count($arrayyears)) $arrayyears[$nowyear] = $nowyear; @@ -285,6 +253,2 @@ -if ($mode == 'customer') { - $type = 'order_stats'; -} -if ($mode == 'supplier') { - $type = 'supplier_order_stats'; -} +if ($mode == 'customer') $type = 'order_stats'; +if ($mode == 'supplier') $type = 'supplier_order_stats'; @@ -294 +258 @@ -print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1); +dol_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1); @@ -309,9 +273,3 @@ -$filter = ''; -if ($mode == 'customer') { - $filter = '(s.client:IN:1,2,3)'; -} -if ($mode == 'supplier') { - $filter = '(s.fournisseur:=:1)'; -} -print img_picto('', 'company', 'class="pictofixedwidth"'); -print $form->select_company($socid, 'socid', $filter, 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300'); +if ($mode == 'customer') $filter = 's.client IN (1,2,3)'; +if ($mode == 'supplier') $filter = 's.fournisseur = 1'; +print $form->select_company($socid, 'socid', $filter, 1, 0, 0, array(), 0, '', 'style="width: 95%"'); @@ -321,5 +279,3 @@ -$sortparam_typent = (!getDolGlobalString('SOCIETE_SORT_ON_TYPEENT') ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT); // NONE means we keep sort of original array, so we sort on position. ASC, means next function will sort on label. -print $form->selectarray("typent_id", $formcompany->typent_array(0), $typent_id, 1, 0, 0, '', 0, 0, 0, $sortparam_typent, '', 1); -if ($user->admin) { - print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); -} +$sortparam_typent = (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT); // NONE means we keep sort of original array, so we sort on position. ASC, means next function will sort on label. +print $form->selectarray("typent_id", $formcompany->typent_array(0), $typent_id, 0, 0, 0, '', 0, 0, 0, $sortparam_typent); +if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); @@ -328,7 +284,9 @@ -if ($mode == 'customer') { - $cat_type = Categorie::TYPE_CUSTOMER; - $cat_label = $langs->trans("Category").' '.lcfirst($langs->trans("Customer")); -} -if ($mode == 'supplier') { - $cat_type = Categorie::TYPE_SUPPLIER; - $cat_label = $langs->trans("Category").' '.lcfirst($langs->trans("Supplier")); +if ($mode == 'customer') +{ + $cat_type = Categorie::TYPE_CUSTOMER; + $cat_label = $langs->trans("Category").' '.lcfirst($langs->trans("Customer")); +} +if ($mode == 'supplier') +{ + $cat_type = Categorie::TYPE_SUPPLIER; + $cat_label = $langs->trans("Supplier").' '.lcfirst($langs->trans("Customer")); @@ -337,2 +295 @@ -print img_picto('', 'category', 'class="pictofixedwidth"'); -print $formother->select_categories($cat_type, $categ_id, 'categ_id', 0, 1, 'widthcentpercentminusx maxwidth300'); +print $formother->select_categories($cat_type, $categ_id, 'categ_id', true); @@ -341,3 +298,2 @@ -print '