30require
'../../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facturestats.class.php';
36if (isModEnabled(
'category')) {
37 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
44$langs->loadLangs(array(
'bills',
'companies',
'other'));
48$hookmanager->initHooks(array(
'invoicestats',
'globalcard'));
50if ($mode ==
'customer' && !$user->hasRight(
'facture',
'lire')) {
53if ($mode ==
'supplier' && !$user->hasRight(
'fournisseur',
'facture',
'lire')) {
57$object_status =
GETPOST(
'object_status',
'intcomma');
63$custcats =
GETPOST(
'custcats',
'array');
65if ($user->socid > 0) {
67 $socid = $user->socid;
71$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
85if (isModEnabled(
'category')) {
86 $langs->load(
'categories');
95$title = $langs->trans(
"BillsStatistics");
96$dir = $conf->facture->dir_temp;
98if ($mode ==
'supplier') {
99 $picto =
'supplier_invoice';
100 $title = $langs->trans(
"BillsStatisticsSuppliers");
101 $dir = $conf->fournisseur->facture->dir_temp;
109$stats =
new FactureStats($db, $socid, $mode, ($userid > 0 ? $userid : 0), ($typent_id > 0 ? $typent_id : 0), ($categ_id > 0 ? $categ_id : 0));
110if ($mode ==
'customer') {
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_societe as cat ON (f.fk_soc = cat.fk_soc)';
116 $stats->where .=
' AND cat.fk_categorie IN ('.$db->sanitize(implode(
',', $custcats)).
')';
119if ($mode ==
'supplier') {
120 if ($object_status !=
'' && $object_status >= 0) {
121 $stats->where .=
' AND f.fk_statut IN ('.$db->sanitize($object_status).
')';
123 if (is_array($custcats) && !empty($custcats)) {
124 $stats->from .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'categorie_fournisseur as cat ON (f.fk_soc = cat.fk_soc)';
125 $stats->where .=
' AND cat.fk_categorie IN ('.$db->sanitize(implode(
',', $custcats)).
')';
131$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
134$filenamenb = $dir.
"/invoicesnbinyear-".$year.
".png";
135if ($mode ==
'customer') {
136 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstats&file=invoicesnbinyear-'.$year.
'.png';
138if ($mode ==
'supplier') {
139 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstatssupplier&file=invoicesnbinyear-'.$year.
'.png';
143$mesg = $px1->isGraphKo();
145 $px1->SetData($data);
148 while ($i <= $endyear) {
152 $px1->SetLegend($legend);
153 $px1->SetMaxValue($px1->GetCeilMaxValue());
154 $px1->SetWidth($WIDTH);
155 $px1->SetHeight($HEIGHT);
156 $px1->SetYLabel($langs->trans(
"NumberOfBills"));
158 $px1->SetHorizTickIncrement(1);
159 $px1->mode =
'depth';
160 $px1->SetTitle($langs->trans(
"NumberOfBillsByMonth"));
162 $px1->draw($filenamenb, $fileurlnb);
166$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
170$filenameamount = $dir.
"/invoicesamountinyear-".$year.
".png";
171if ($mode ==
'customer') {
172 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstats&file=invoicesamountinyear-'.$year.
'.png';
174if ($mode ==
'supplier') {
175 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstatssupplier&file=invoicesamountinyear-'.$year.
'.png';
179$mesg = $px2->isGraphKo();
181 $px2->SetData($data);
184 while ($i <= $endyear) {
188 $px2->SetLegend($legend);
189 $px2->SetMaxValue($px2->GetCeilMaxValue());
190 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
191 $px2->SetWidth($WIDTH);
192 $px2->SetHeight($HEIGHT);
193 $px2->SetYLabel($langs->trans(
"AmountOfBills"));
195 $px2->SetHorizTickIncrement(1);
196 $px2->mode =
'depth';
197 $px2->SetTitle($langs->trans(
"AmountOfBillsByMonthHT"));
199 $px2->draw($filenameamount, $fileurlamount);
203$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
205if (!$user->hasRight(
'societe',
'client',
'voir')) {
206 $filename_avg = $dir.
'/ordersaverage-'.$user->id.
'-'.$year.
'.png';
207 if ($mode ==
'customer') {
208 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
210 if ($mode ==
'supplier') {
211 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
214 $filename_avg = $dir.
'/ordersaverage-'.$year.
'.png';
215 if ($mode ==
'customer') {
216 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.
'.png';
218 if ($mode ==
'supplier') {
219 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.
'.png';
224$mesg = $px3->isGraphKo();
226 $px3->SetData($data);
229 while ($i <= $endyear) {
233 $px3->SetLegend($legend);
234 $px3->SetYLabel($langs->trans(
"AmountAverage"));
235 $px3->SetMaxValue($px3->GetCeilMaxValue());
236 $px3->SetMinValue($px3->GetFloorMinValue());
237 $px3->SetWidth($WIDTH);
238 $px3->SetHeight($HEIGHT);
240 $px3->SetHorizTickIncrement(1);
241 $px3->mode =
'depth';
242 $px3->SetTitle($langs->trans(
"AmountAverage"));
244 $px3->draw($filename_avg, $fileurl_avg);
249$data = $stats->getAllByYear();
250$arrayyears = array();
251foreach ($data as $val) {
252 $arrayyears[$val[
'year']] = $val[
'year'];
254if (!count($arrayyears)) {
255 $arrayyears[$nowyear] = $nowyear;
261$head[$h][0] = DOL_URL_ROOT.
'/compta/facture/stats/index.php?mode='.urlencode($mode);
262$head[$h][1] = $langs->trans(
"ByMonthYear");
263$head[$h][2] =
'byyear';
266if ($mode ==
'customer') {
267 $type =
'invoice_stats';
269if ($mode ==
'supplier') {
270 $type =
'supplier_invoice_stats';
277print
'<div class="fichecenter"><div class="fichethirdleft">';
281print
'<form name="stats" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
282print
'<input type="hidden" name="token" value="'.newToken().
'">';
283print
'<input type="hidden" name="mode" value="'.$mode.
'">';
285print
'<table class="noborder centpercent">';
286print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
288print
'<tr><td>'.$langs->trans(
"ThirdParty").
'</td><td>';
290if ($mode ==
'customer') {
291 $filter =
'(s.client:IN:1,2,3)';
293if ($mode ==
'supplier') {
294 $filter =
'(s.fournisseur:=:1)';
296print
img_picto(
'',
'company',
'class="pictofixedwidth"');
297print $form->select_company($socid,
'socid', $filter, 1, 0, 0, array(), 0,
'widthcentpercentminusx maxwidth300');
301print
'<tr><td>'.$langs->trans(
"ThirdPartyType").
'</td><td>';
302$sortparam_typent = (!
getDolGlobalString(
'SOCIETE_SORT_ON_TYPEENT') ?
'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT);
303print $form->selectarray(
"typent_id", $formcompany->typent_array(0), $typent_id, 1, 0, 0,
'', 0, 0, 0, $sortparam_typent,
'', 1);
305 print
' '.info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
310if (isModEnabled(
'category')) {
311 if ($mode ==
'customer') {
312 $cat_type = Categorie::TYPE_CUSTOMER;
313 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Customer"));
315 if ($mode ==
'supplier') {
316 $cat_type = Categorie::TYPE_SUPPLIER;
317 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Supplier"));
319 print
'<tr><td>'.$cat_label.
'</td><td>';
320 $cate_arbo = $form->select_all_categories($cat_type,
null,
'parent',
null,
null, 1);
321 print
img_picto(
'',
'category',
'class="pictofixedwidth"');
322 print $form->multiselectarray(
'custcats', $cate_arbo,
GETPOST(
'custcats',
'array'), 0, 0,
'widthcentpercentminusx maxwidth300');
328print
'<tr><td>'.$langs->trans(
"CreatedBy").
'</td><td>';
329print
img_picto(
'',
'user',
'class="pictofixedwidth"');
330print $form->select_dolusers($userid,
'userid', 1,
'', 0,
'',
'', 0, 0, 0,
'', 0,
'',
'widthcentpercentminusx maxwidth300');
333print
'<tr><td>'.$langs->trans(
"Status").
'</td><td>';
334if ($mode ==
'customer') {
335 $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"));
336 print $form->selectarray(
'object_status', $liststatus, $object_status, 1);
338if ($mode ==
'supplier') {
339 $liststatus = array(
'0'=>$langs->trans(
"BillStatusDraft"),
'1'=>$langs->trans(
"BillStatusNotPaid"),
'2'=>$langs->trans(
"BillStatusPaid"));
340 print $form->selectarray(
'object_status', $liststatus, $object_status, 1);
344print
'<tr><td>'.$langs->trans(
"Year").
'</td><td>';
345if (!in_array($year, $arrayyears)) {
346 $arrayyears[$year] = $year;
348if (!in_array($nowyear, $arrayyears)) {
349 $arrayyears[$nowyear] = $nowyear;
352print $form->selectarray(
'year', $arrayyears, $year, 0, 0, 0,
'', 0, 0, 0,
'',
'width75');
354print
'<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
359print
'<div class="div-table-responsive-no-min">';
360print
'<table class="noborder centpercent">';
361print
'<tr class="liste_titre" height="24">';
362print
'<td class="center">'.$langs->trans(
"Year").
'</td>';
363print
'<td class="right">'.$langs->trans(
"NumberOfBills").
'</td>';
364print
'<td class="right">%</td>';
365print
'<td class="right">'.$langs->trans(
"AmountTotal").
'</td>';
366print
'<td class="right">%</td>';
367print
'<td class="right">'.$langs->trans(
"AmountAverage").
'</td>';
368print
'<td class="right">%</td>';
372foreach ($data as $val) {
373 $year = $val[
'year'];
374 while ($year && $oldyear > $year + 1) {
377 print
'<tr class="oddeven" height="24">';
378 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$oldyear.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$oldyear.
'</a></td>';
379 print
'<td class="right">0</td>';
380 print
'<td class="right"></td>';
381 print
'<td class="right amount">0</td>';
382 print
'<td class="right"></td>';
383 print
'<td class="right amount">0</td>';
384 print
'<td class="right"></td>';
388 if ($mode ==
'supplier') {
389 $greennb = (empty($val[
'nb_diff']) || $val[
'nb_diff'] <= 0);
390 $greentotal = (empty($val[
'total_diff']) || $val[
'total_diff'] <= 0);
391 $greenavg = (empty($val[
'avg_diff']) || $val[
'avg_diff'] <= 0);
393 $greennb = (empty($val[
'nb_diff']) || $val[
'nb_diff'] >= 0);
394 $greentotal = (empty($val[
'total_diff']) || $val[
'total_diff'] >= 0);
395 $greenavg = (empty($val[
'avg_diff']) || $val[
'avg_diff'] >= 0);
398 print
'<tr class="oddeven" height="24">';
399 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$year.
'</a></td>';
400 print
'<td class="right">'.$val[
'nb'].
'</td>';
401 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>';
402 print
'<td class="right"><span class="amount">'.price(
price2num($val[
'total'],
'MT'), 1).
'</span></td>';
403 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>';
404 print
'<td class="right"><span class="amount">'.price(
price2num($val[
'avg'],
'MT'), 1).
'</span></td>';
405 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>';
413print
'</div><div class="fichetwothirdright">';
417print
'<table class="border centpercent"><tr class="pair nohover"><td align="center">';
427print
'</td></tr></table>';
431print
'<div class="clearboth"></div>';
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Class to manage stats for invoices (customer and supplier)
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
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_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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).
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.