30 require
'../../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facturestats.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
44 $langs->loadLangs(array(
'bills',
'companies',
'other'));
47 if ($mode ==
'customer' && !$user->rights->facture->lire) {
50 if ($mode ==
'supplier' && empty($user->rights->fournisseur->facture->lire)) {
54 $object_status =
GETPOST(
'object_status',
'intcomma');
55 $typent_id =
GETPOST(
'typent_id',
'int');
56 $categ_id =
GETPOST(
'categ_id',
'categ_id');
58 $userid =
GETPOST(
'userid',
'int');
59 $socid =
GETPOST(
'socid',
'int');
60 $custcats =
GETPOST(
'custcats',
'array');
62 if ($user->socid > 0) {
64 $socid = $user->socid;
69 $startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
77 $langs->load(
'categories');
86 $title = $langs->trans(
"BillsStatistics");
87 $dir = $conf->facture->dir_temp;
89 if ($mode ==
'supplier') {
90 $picto =
'supplier_invoice';
91 $title = $langs->trans(
"BillsStatisticsSuppliers");
92 $dir = $conf->fournisseur->facture->dir_temp;
100 $stats =
new FactureStats($db, $socid, $mode, ($userid > 0 ? $userid : 0), ($typent_id > 0 ? $typent_id : 0), ($categ_id > 0 ? $categ_id : 0));
101 if ($mode ==
'customer') {
102 if ($object_status !=
'' && $object_status >= 0) {
103 $stats->where .=
' AND f.fk_statut IN ('.$db->sanitize($object_status).
')';
105 if (is_array($custcats) && !empty($custcats)) {
106 $stats->from .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'categorie_societe as cat ON (f.fk_soc = cat.fk_soc)';
107 $stats->where .=
' AND cat.fk_categorie IN ('.$db->sanitize(implode(
',', $custcats)).
')';
110 if ($mode ==
'supplier') {
111 if ($object_status !=
'' && $object_status >= 0) {
112 $stats->where .=
' AND f.fk_statut IN ('.$db->sanitize($object_status).
')';
114 if (is_array($custcats) && !empty($custcats)) {
115 $stats->from .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'categorie_fournisseur as cat ON (f.fk_soc = cat.fk_soc)';
116 $stats->where .=
' AND cat.fk_categorie IN ('.$db->sanitize(implode(
',', $custcats)).
')';
122 $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
125 $filenamenb = $dir.
"/invoicesnbinyear-".$year.
".png";
126 if ($mode ==
'customer') {
127 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstats&file=invoicesnbinyear-'.$year.
'.png';
129 if ($mode ==
'supplier') {
130 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstatssupplier&file=invoicesnbinyear-'.$year.
'.png';
134 $mesg = $px1->isGraphKo();
136 $px1->SetData($data);
139 while ($i <= $endyear) {
143 $px1->SetLegend($legend);
144 $px1->SetMaxValue($px1->GetCeilMaxValue());
145 $px1->SetWidth($WIDTH);
146 $px1->SetHeight($HEIGHT);
147 $px1->SetYLabel($langs->trans(
"NumberOfBills"));
149 $px1->SetHorizTickIncrement(1);
150 $px1->mode =
'depth';
151 $px1->SetTitle($langs->trans(
"NumberOfBillsByMonth"));
153 $px1->draw($filenamenb, $fileurlnb);
157 $data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
161 $filenameamount = $dir.
"/invoicesamountinyear-".$year.
".png";
162 if ($mode ==
'customer') {
163 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstats&file=invoicesamountinyear-'.$year.
'.png';
165 if ($mode ==
'supplier') {
166 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstatssupplier&file=invoicesamountinyear-'.$year.
'.png';
170 $mesg = $px2->isGraphKo();
172 $px2->SetData($data);
175 while ($i <= $endyear) {
179 $px2->SetLegend($legend);
180 $px2->SetMaxValue($px2->GetCeilMaxValue());
181 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
182 $px2->SetWidth($WIDTH);
183 $px2->SetHeight($HEIGHT);
184 $px2->SetYLabel($langs->trans(
"AmountOfBills"));
186 $px2->SetHorizTickIncrement(1);
187 $px2->mode =
'depth';
188 $px2->SetTitle($langs->trans(
"AmountOfBillsByMonthHT"));
190 $px2->draw($filenameamount, $fileurlamount);
194 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
196 if (empty($user->rights->societe->client->voir) || $user->socid) {
197 $filename_avg = $dir.
'/ordersaverage-'.$user->id.
'-'.$year.
'.png';
198 if ($mode ==
'customer') {
199 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
201 if ($mode ==
'supplier') {
202 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
205 $filename_avg = $dir.
'/ordersaverage-'.$year.
'.png';
206 if ($mode ==
'customer') {
207 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.
'.png';
209 if ($mode ==
'supplier') {
210 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.
'.png';
215 $mesg = $px3->isGraphKo();
217 $px3->SetData($data);
220 while ($i <= $endyear) {
224 $px3->SetLegend($legend);
225 $px3->SetYLabel($langs->trans(
"AmountAverage"));
226 $px3->SetMaxValue($px3->GetCeilMaxValue());
227 $px3->SetMinValue($px3->GetFloorMinValue());
228 $px3->SetWidth($WIDTH);
229 $px3->SetHeight($HEIGHT);
231 $px3->SetHorizTickIncrement(1);
232 $px3->mode =
'depth';
233 $px3->SetTitle($langs->trans(
"AmountAverage"));
235 $px3->draw($filename_avg, $fileurl_avg);
240 $data = $stats->getAllByYear();
241 $arrayyears = array();
242 foreach ($data as $val) {
243 $arrayyears[$val[
'year']] = $val[
'year'];
245 if (!count($arrayyears)) {
246 $arrayyears[$nowyear] = $nowyear;
252 $head[$h][0] = DOL_URL_ROOT.
'/compta/facture/stats/index.php?mode='.urlencode($mode);
253 $head[$h][1] = $langs->trans(
"ByMonthYear");
254 $head[$h][2] =
'byyear';
257 if ($mode ==
'customer') {
258 $type =
'invoice_stats';
260 if ($mode ==
'supplier') {
261 $type =
'supplier_invoice_stats';
270 if ($mode ==
'customer') {
271 $filter =
's.client in (1,2,3)';
273 if ($mode ==
'supplier') {
274 $filter =
's.fournisseur = 1';
277 print
'<div class="fichecenter"><div class="fichethirdleft">';
281 print
'<form name="stats" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
282 print
'<input type="hidden" name="token" value="'.newToken().
'">';
283 print
'<input type="hidden" name="mode" value="'.$mode.
'">';
285 print
'<table class="noborder centpercent">';
286 print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
288 print
'<tr><td>'.$langs->trans(
"ThirdParty").
'</td><td>';
289 print
img_picto(
'',
'company',
'class="pictofixedwidth"');
290 print
$form->select_company($socid,
'socid', $filter, 1, 0, 0, array(), 0,
'widthcentpercentminusx maxwidth300');
294 print
'<tr><td>'.$langs->trans(
"ThirdPartyType").
'</td><td>';
295 $sortparam_typent = (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ?
'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT);
296 print
$form->selectarray(
"typent_id", $formcompany->typent_array(0), $typent_id, 1, 0, 0,
'', 0, 0, 0, $sortparam_typent,
'', 1);
298 print
' '.info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
304 if ($mode ==
'customer') {
305 $cat_type = Categorie::TYPE_CUSTOMER;
306 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Customer"));
308 if ($mode ==
'supplier') {
309 $cat_type = Categorie::TYPE_SUPPLIER;
310 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Supplier"));
312 print
'<tr><td>'.$cat_label.
'</td><td>';
313 $cate_arbo =
$form->select_all_categories($cat_type,
null,
'parent',
null,
null, 1);
314 print
img_picto(
'',
'category',
'class="pictofixedwidth"');
315 print
$form->multiselectarray(
'custcats', $cate_arbo,
GETPOST(
'custcats',
'array'), 0, 0,
'widthcentpercentminusx maxwidth300');
321 print
'<tr><td>'.$langs->trans(
"CreatedBy").
'</td><td>';
322 print
img_picto(
'',
'user',
'class="pictofixedwidth"');
323 print
$form->select_dolusers($userid,
'userid', 1,
'', 0,
'',
'', 0, 0, 0,
'', 0,
'',
'widthcentpercentminusx maxwidth300');
326 print
'<tr><td>'.$langs->trans(
"Status").
'</td><td>';
327 if ($mode ==
'customer') {
328 $liststatus = array(
'0'=>$langs->trans(
"BillStatusDraft"),
'1'=>$langs->trans(
"BillStatusNotPaid"),
'2'=>$langs->trans(
"BillStatusPaid"),
'1,2'=>$langs->trans(
"BillStatusNotPaid").
' / '.$langs->trans(
"BillStatusPaid"),
'3'=>$langs->trans(
"BillStatusCanceled"));
329 print
$form->selectarray(
'object_status', $liststatus, $object_status, 1);
331 if ($mode ==
'supplier') {
332 $liststatus = array(
'0'=>$langs->trans(
"BillStatusDraft"),
'1'=>$langs->trans(
"BillStatusNotPaid"),
'2'=>$langs->trans(
"BillStatusPaid"));
333 print
$form->selectarray(
'object_status', $liststatus, $object_status, 1);
337 print
'<tr><td>'.$langs->trans(
"Year").
'</td><td>';
338 if (!in_array($year, $arrayyears)) {
339 $arrayyears[$year] = $year;
341 if (!in_array($nowyear, $arrayyears)) {
342 $arrayyears[$nowyear] = $nowyear;
345 print
$form->selectarray(
'year', $arrayyears, $year, 0, 0, 0,
'', 0, 0, 0,
'',
'width75');
347 print
'<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
352 print
'<div class="div-table-responsive-no-min">';
353 print
'<table class="noborder centpercent">';
354 print
'<tr class="liste_titre" height="24">';
355 print
'<td class="center">'.$langs->trans(
"Year").
'</td>';
356 print
'<td class="right">'.$langs->trans(
"NumberOfBills").
'</td>';
357 print
'<td class="right">%</td>';
358 print
'<td class="right">'.$langs->trans(
"AmountTotal").
'</td>';
359 print
'<td class="right">%</td>';
360 print
'<td class="right">'.$langs->trans(
"AmountAverage").
'</td>';
361 print
'<td class="right">%</td>';
365 foreach ($data as $val) {
366 $year = $val[
'year'];
367 while ($year && $oldyear > $year + 1) {
370 print
'<tr class="oddeven" height="24">';
371 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$oldyear.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$oldyear.
'</a></td>';
372 print
'<td class="right">0</td>';
373 print
'<td class="right"></td>';
374 print
'<td class="right amount">0</td>';
375 print
'<td class="right"></td>';
376 print
'<td class="right amount">0</td>';
377 print
'<td class="right"></td>';
381 if ($mode ==
'supplier') {
382 $greennb = (empty($val[
'nb_diff']) || $val[
'nb_diff'] <= 0);
383 $greentotal = (empty($val[
'total_diff']) || $val[
'total_diff'] <= 0);
384 $greenavg = (empty($val[
'avg_diff']) || $val[
'avg_diff'] <= 0);
386 $greennb = (empty($val[
'nb_diff']) || $val[
'nb_diff'] >= 0);
387 $greentotal = (empty($val[
'total_diff']) || $val[
'total_diff'] >= 0);
388 $greenavg = (empty($val[
'avg_diff']) || $val[
'avg_diff'] >= 0);
391 print
'<tr class="oddeven" height="24">';
392 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$year.
'</a></td>';
393 print
'<td class="right">'.$val[
'nb'].
'</td>';
394 print
'<td class="right opacitylow" style="'.($greennb ?
'color: green;' :
'color: red;').
'">'.(!empty($val[
'nb_diff']) && $val[
'nb_diff'] < 0 ?
'' :
'+').round(!empty($val[
'nb_diff']) ? $val[
'nb_diff'] : 0).
'%</td>';
395 print
'<td class="right"><span class="amount">'.price(
price2num($val[
'total'],
'MT'), 1).
'</span></td>';
396 print
'<td class="right opacitylow" style="'.($greentotal ?
'color: green;' :
'color: red;').
'">'.( !empty($val[
'total_diff']) && $val[
'total_diff'] < 0 ?
'' :
'+').round(!empty($val[
'total_diff']) ? $val[
'total_diff'] : 0).
'%</td>';
397 print
'<td class="right"><span class="amount">'.price(
price2num($val[
'avg'],
'MT'), 1).
'</span></td>';
398 print
'<td class="right opacitylow" style="'.($greenavg ?
'color: green;' :
'color: red;').
'">'.(!empty($val[
'avg_diff']) && $val[
'avg_diff'] < 0 ?
'' :
'+').round(!empty($val[
'avg_diff']) ? $val[
'avg_diff'] : 0).
'%</td>';
406 print
'</div><div class="fichetwothirdright">';
410 print
'<table class="border centpercent"><tr class="pair nohover"><td align="center">';
420 print
'</td></tr></table>';
423 print
'</div></div>';
424 print
'<div style="clear:both"></div>';
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Class to manage stats for invoices (customer and supplier)
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
isModEnabled($module)
Is Dolibarr module enabled.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.