32require
'../../../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facturestats.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
54$langs->loadLangs(array(
'bills',
'companies',
'other'));
58$hookmanager->initHooks(array(
'invoicestats',
'globalcard'));
60if ($mode ==
'customer' && !$user->hasRight(
'facture',
'lire')) {
63if ($mode ==
'supplier' && !$user->hasRight(
'fournisseur',
'facture',
'lire')) {
67$object_status =
GETPOST(
'object_status',
'intcomma');
73$select_categ_categ_id =
GETPOST(
'select_categ_categ_id',
'array:int');
74$select_categ_invoice_id=
GETPOST(
'select_categ_invoice_id',
'array:int');
76if ($user->socid > 0) {
78 $socid = $user->socid;
82$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
97 $langs->load(
'categories');
105$title = $langs->trans(
"BillsStatistics");
106$dir = $conf->facture->dir_temp;
108if ($mode ==
'supplier') {
109 $picto =
'supplier_invoice';
110 $title = $langs->trans(
"BillsStatisticsSuppliers");
111 $dir = $conf->fournisseur->facture->dir_temp;
120$stats =
new FactureStats($db, $socid, $mode, ($userid > 0 ? $userid : 0), ($typent_id > 0 ? $typent_id : 0), ($categ_id > 0 ? $categ_id : 0));
121if ($mode ==
'customer') {
122 if ($object_status !=
'' && $object_status >= 0) {
123 $stats->where .=
' AND f.fk_statut IN ('.$db->sanitize($object_status).
')';
125 if (is_array($select_categ_categ_id) && !empty($select_categ_categ_id)) {
126 $stats->from .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'categorie_societe as cat ON (f.fk_soc = cat.fk_soc)';
127 $stats->where .=
' AND cat.fk_categorie IN ('.$db->sanitize(implode(
',', $select_categ_categ_id)).
')';
129 if (is_array($select_categ_invoice_id) && !empty($select_categ_invoice_id)) {
130 $stats->from .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'categorie_invoice as cat ON (f.rowid = cat.fk_invoice)';
131 $stats->where .=
' AND cat.fk_categorie IN ('.$db->sanitize(implode(
',', $select_categ_invoice_id)).
')';
134if ($mode ==
'supplier') {
135 if ($object_status !=
'' && $object_status >= 0) {
136 $stats->where .=
' AND f.fk_statut IN ('.$db->sanitize($object_status).
')';
138 if (is_array($select_categ_categ_id) && !empty($select_categ_categ_id)) {
139 $stats->from .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'categorie_fournisseur as cat ON (f.fk_soc = cat.fk_soc)';
140 $stats->where .=
' AND cat.fk_categorie IN ('.$db->sanitize(implode(
',', $select_categ_categ_id)).
')';
142 if (is_array($select_categ_invoice_id) && !empty($select_categ_invoice_id)) {
143 $stats->from .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'categorie_supplier_invoice as cat ON (f.rowid = cat.fk_supplier_invoice)';
144 $stats->where .=
' AND cat.fk_categorie IN ('.$db->sanitize(implode(
',', $select_categ_invoice_id)).
')';
150$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
153$filenamenb = $dir.
"/invoicesnbinyear-".$year.
".png";
155if ($mode ==
'customer') {
156 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstats&file=invoicesnbinyear-'.$year.
'.png';
158if ($mode ==
'supplier') {
159 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstatssupplier&file=invoicesnbinyear-'.$year.
'.png';
163$mesg = $px1->isGraphKo();
165 $px1->SetData($data);
168 while ($i <= $endyear) {
172 $px1->SetLegend($legend);
173 $px1->SetMaxValue($px1->GetCeilMaxValue());
174 $px1->SetWidth($WIDTH);
175 $px1->SetHeight($HEIGHT);
176 $px1->SetYLabel($langs->trans(
"NumberOfBills"));
178 $px1->SetHorizTickIncrement(1);
179 $px1->mode =
'depth';
180 $px1->SetTitle($langs->trans(
"NumberOfBillsByMonth"));
182 $px1->draw($filenamenb, $fileurlnb);
186$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
190$filenameamount = $dir.
"/invoicesamountinyear-".$year.
".png";
192if ($mode ==
'customer') {
193 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstats&file=invoicesamountinyear-'.$year.
'.png';
195if ($mode ==
'supplier') {
196 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstatssupplier&file=invoicesamountinyear-'.$year.
'.png';
200$mesg = $px2->isGraphKo();
202 $px2->SetData($data);
205 while ($i <= $endyear) {
209 $px2->SetLegend($legend);
210 $px2->SetMaxValue($px2->GetCeilMaxValue());
211 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
212 $px2->SetWidth($WIDTH);
213 $px2->SetHeight($HEIGHT);
214 $px2->SetYLabel($langs->trans(
"AmountOfBills"));
216 $px2->SetHorizTickIncrement(1);
217 $px2->mode =
'depth';
218 $px2->SetTitle($langs->trans(
"AmountOfBillsByMonthHT"));
220 $px2->draw($filenameamount, $fileurlamount);
224$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
227if (!$user->hasRight(
'societe',
'client',
'voir')) {
228 $filename_avg = $dir.
'/ordersaverage-'.$user->id.
'-'.$year.
'.png';
229 if ($mode ==
'customer') {
230 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
232 if ($mode ==
'supplier') {
233 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
236 $filename_avg = $dir.
'/ordersaverage-'.$year.
'.png';
237 if ($mode ==
'customer') {
238 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.
'.png';
240 if ($mode ==
'supplier') {
241 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.
'.png';
246$mesg = $px3->isGraphKo();
248 $px3->SetData($data);
251 while ($i <= $endyear) {
255 $px3->SetLegend($legend);
256 $px3->SetYLabel($langs->trans(
"AmountAverage"));
257 $px3->SetMaxValue($px3->GetCeilMaxValue());
258 $px3->SetMinValue((
int) $px3->GetFloorMinValue());
259 $px3->SetWidth($WIDTH);
260 $px3->SetHeight($HEIGHT);
262 $px3->SetHorizTickIncrement(1);
263 $px3->mode =
'depth';
264 $px3->SetTitle($langs->trans(
"AmountAverage"));
266 $px3->draw($filename_avg, $fileurl_avg);
271$data = $stats->getAllByYear();
272$arrayyears = array();
273foreach ($data as $val) {
274 $arrayyears[$val[
'year']] = $val[
'year'];
276if (!count($arrayyears)) {
277 $arrayyears[$nowyear] = $nowyear;
283$head[$h][0] = DOL_URL_ROOT.
'/compta/facture/stats/index.php?mode='.urlencode($mode);
284$head[$h][1] = $langs->trans(
"ByMonthYear");
285$head[$h][2] =
'byyear';
288if ($mode ==
'customer') {
289 $type =
'invoice_stats';
291if ($mode ==
'supplier') {
292 $type =
'supplier_invoice_stats';
299print
'<div class="fichecenter"><div class="fichethirdleft">';
303print
'<form name="stats" method="POST" action="'.dolBuildUrl($_SERVER[
"PHP_SELF"]).
'">';
304print
'<input type="hidden" name="token" value="'.newToken().
'">';
305print
'<input type="hidden" name="mode" value="'.$mode.
'">';
307print
'<table class="noborder centpercent">';
308print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
310print
'<tr><td>'.$langs->trans(
"ThirdParty").
'</td><td>';
312if ($mode ==
'customer') {
313 $filter =
'(s.client:IN:1,2,3)';
315if ($mode ==
'supplier') {
316 $filter =
'(s.fournisseur:=:1)';
318print
img_picto(
'',
'company',
'class="pictofixedwidth"');
319print $form->select_company($socid,
'socid', $filter, 1, 0, 0, array(), 0,
'widthcentpercentminusx maxwidth300');
323print
'<tr><td>'.$langs->trans(
"ThirdPartyType").
'</td><td>';
325print $form->selectarray(
"typent_id", $formcompany->typent_array(0), $typent_id, 1, 0, 0,
'', 0, 0, 0, $sortparam_typent,
'', 1);
327 print
' '.info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
335 if ($mode ==
'customer') {
336 $cat_type = Categorie::TYPE_CUSTOMER;
337 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Customer"));
339 if ($mode ==
'supplier') {
340 $cat_type = Categorie::TYPE_SUPPLIER;
341 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Supplier"));
343 print
'<tr><td>'.$cat_label.
'</td><td>';
344 $cate_arbo = $form->select_all_categories($cat_type,
'',
'parent', 0, 0, 1);
345 print
img_picto(
'',
'category',
'class="pictofixedwidth"');
346 print $form->multiselectarray(
'select_categ_categ_id', $cate_arbo,
GETPOST(
'select_categ_categ_id',
'array'), 0, 0,
'widthcentpercentminusx maxwidth300');
356 if ($mode ==
'customer') {
357 $cat_type = Categorie::TYPE_INVOICE;
358 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"BillsCustomers"));
360 if ($mode ==
'supplier') {
361 $cat_type = Categorie::TYPE_SUPPLIER_INVOICE;
362 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"BillsSuppliers"));
364 print
'<tr><td>'.$cat_label.
'</td><td>';
365 $cate_arbo = $form->select_all_categories($cat_type,
'',
'parent', 0, 0, 1);
366 print
img_picto(
'',
'category',
'class="pictofixedwidth"');
367 print $form->multiselectarray(
'select_categ_invoice_id', $cate_arbo,
GETPOST(
'select_categ_invoice_id',
'array'), 0, 0,
'widthcentpercentminusx maxwidth300');
374print
'<tr><td>'.$langs->trans(
"CreatedBy").
'</td><td>';
375print
img_picto(
'',
'user',
'class="pictofixedwidth"');
376print $form->select_dolusers($userid ? $userid : -1,
'userid', 1, null, 0,
'',
'',
'0', 0, 0,
'', 0,
'',
'widthcentpercentminusx maxwidth300');
379print
'<tr><td>'.$langs->trans(
"Status").
'</td><td>';
380if ($mode ==
'customer') {
381 $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"));
382 print $form->selectarray(
'object_status', $liststatus, $object_status, 1);
384if ($mode ==
'supplier') {
385 $liststatus = array(
'0' => $langs->trans(
"BillStatusDraft"),
'1' => $langs->trans(
"BillStatusNotPaid"),
'2' => $langs->trans(
"BillStatusPaid"));
386 print $form->selectarray(
'object_status', $liststatus, $object_status, 1);
390print
'<tr><td>'.$langs->trans(
"Year").
'</td><td>';
391if (!in_array($year, $arrayyears)) {
392 $arrayyears[$year] = $year;
394if (!in_array($nowyear, $arrayyears)) {
395 $arrayyears[$nowyear] = $nowyear;
398print
img_picto(
'',
'calendar',
'class="pictofixedwidth"');
399print $form->selectarray(
'year', $arrayyears, $year, 0, 0, 0,
'', 0, 0, 0,
'',
'width75');
401print
'<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
406print
'<div class="div-table-responsive-no-min">';
407print
'<table class="noborder centpercent">';
408print
'<tr class="liste_titre" height="24">';
409print
'<td class="center">'.$langs->trans(
"Year").
'</td>';
410print
'<td class="right">'.$langs->trans(
"NumberOfBills").
'</td>';
411print
'<td class="right">%</td>';
412print
'<td class="right">'.$langs->trans(
"AmountTotal").
'</td>';
413print
'<td class="right">%</td>';
414print
'<td class="right">'.$langs->trans(
"AmountAverage").
'</td>';
415print
'<td class="right">%</td>';
419foreach ($data as $val) {
420 $year = (int) $val[
'year'];
421 while ($year && $oldyear > $year + 1) {
424 print
'<tr class="oddeven" height="24">';
425 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$oldyear.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$oldyear.
'</a></td>';
426 print
'<td class="right">0</td>';
427 print
'<td class="right"></td>';
428 print
'<td class="right amount">0</td>';
429 print
'<td class="right"></td>';
430 print
'<td class="right amount">0</td>';
431 print
'<td class="right"></td>';
435 if ($mode ==
'supplier') {
436 $greennb = (empty($val[
'nb_diff']) || $val[
'nb_diff'] <= 0);
437 $greentotal = (empty($val[
'total_diff']) || $val[
'total_diff'] <= 0);
438 $greenavg = (empty($val[
'avg_diff']) || $val[
'avg_diff'] <= 0);
440 $greennb = (empty($val[
'nb_diff']) || $val[
'nb_diff'] >= 0);
441 $greentotal = (empty($val[
'total_diff']) || $val[
'total_diff'] >= 0);
442 $greenavg = (empty($val[
'avg_diff']) || $val[
'avg_diff'] >= 0);
445 print
'<tr class="oddeven" height="24">';
446 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$year.
'</a></td>';
447 print
'<td class="right">'.$val[
'nb'].
'</td>';
448 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>';
449 print
'<td class="right"><span class="amount">'.price(
price2num($val[
'total'],
'MT'), 1).
'</span></td>';
450 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>';
451 print
'<td class="right"><span class="amount">'.price(
price2num($val[
'avg'],
'MT'), 1).
'</span></td>';
452 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>';
460print
'</div><div class="fichetwothirdright">';
464print
'<table class="border centpercent"><tr class="pair nohover"><td align="center">';
474print
'</td></tr></table>';
478print
'<div class="clearboth"></div>';
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Class to manage stats for invoices (customer and supplier)
dol_now($mode='gmt')
Return date for now.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
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, $morecssdiv='')
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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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 a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.