--- /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 ''.$langs->trans("CreatedBy").''; -print img_picto('', 'user', 'class="pictofixedwidth"'); -print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300'); +print ''.$langs->trans("CreatedBy").''; +print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300'); @@ -345,13 +301,15 @@ -print ''.$langs->trans("Status").''; -if ($mode == 'customer') { - $liststatus = array( - Commande::STATUS_DRAFT => $langs->trans("StatusOrderDraft"), - Commande::STATUS_VALIDATED => $langs->trans("StatusOrderValidated"), - Commande::STATUS_SHIPMENTONPROCESS => $langs->trans("StatusOrderSent"), - Commande::STATUS_CLOSED => $langs->trans("StatusOrderDelivered"), - Commande::STATUS_CANCELED => $langs->trans("StatusOrderCanceled") - ); - print $form->selectarray('object_status', $liststatus, GETPOST('object_status', 'intcomma'), -4); -} -if ($mode == 'supplier') { - $formorder->selectSupplierOrderStatus((strstr($object_status, ',') ? -1 : $object_status), 0, 'object_status'); +print ''.$langs->trans("Status").''; +if ($mode == 'customer') +{ + $liststatus = array( + Commande::STATUS_DRAFT=>$langs->trans("StatusOrderDraft"), + Commande::STATUS_VALIDATED=>$langs->trans("StatusOrderValidated"), + Commande::STATUS_SHIPMENTONPROCESS=>$langs->trans("StatusOrderSent"), + Commande::STATUS_CLOSED=>$langs->trans("StatusOrderDelivered"), + Commande::STATUS_CANCELED=>$langs->trans("StatusOrderCanceled") + ); + print $form->selectarray('object_status', $liststatus, GETPOST('object_status', 'int'), -4); +} +if ($mode == 'supplier') +{ + $formorder->selectSupplierOrderStatus((strstr($object_status, ',') ?-1 : $object_status), 0, 'object_status'); @@ -362,6 +320,2 @@ -if (!in_array($year, $arrayyears)) { - $arrayyears[$year] = $year; -} -if (!in_array($nowyear, $arrayyears)) { - $arrayyears[$nowyear] = $nowyear; -} +if (!in_array($year, $arrayyears)) $arrayyears[$year] = $year; +if (!in_array($nowyear, $arrayyears)) $arrayyears[$nowyear] = $nowyear; @@ -369 +323 @@ -print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75'); +print $form->selectarray('year', $arrayyears, $year, 0); @@ -371 +325 @@ -print ''; +print ''; @@ -390 +344,2 @@ -foreach ($data as $val) { +foreach ($data as $val) +{ @@ -392 +347,2 @@ - while (!empty($year) && $oldyear > $year + 1) { // If we have empty year + while (!empty($year) && $oldyear > $year + 1) + { // If we have empty year @@ -410 +366 @@ - print ''.(isset($val['nb_diff']) ? round($val['nb_diff']) : "0").'%'; + print ''.round($val['nb_diff']).''; @@ -412 +368 @@ - print ''.(isset($val['total_diff']) ? round($val['total_diff']) : "0").'%'; + print ''.round($val['total_diff']).''; @@ -414 +370 @@ - print ''.(isset($val['avg_diff']) ? round($val['avg_diff']) : "0").'%'; + print ''.round($val['avg_diff']).''; @@ -423 +379 @@ -print '
'; +print '
'; @@ -428,8 +384,7 @@ -if ($mesg) { - print $mesg; -} else { - print $px1->show(); - print "
\n"; - print $px2->show(); - print "
\n"; - print $px3->show(); +if ($mesg) { print $mesg; } +else { + print $px1->show(); + print "
\n"; + print $px2->show(); + print "
\n"; + print $px3->show(); @@ -440,4 +395,4 @@ -print '
'; -print '
'; - -print dol_get_fiche_end(); +print ''; +print '
'; + +dol_fiche_end();