29 require
'../../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facturestats.class.php';
35 if (!empty($conf->category->enabled)) require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
41 $langs->loadLangs(array(
'bills',
'companies',
'other'));
44 if ($mode ==
'customer' && !$user->rights->facture->lire)
accessforbidden();
45 if ($mode ==
'supplier' && !$user->rights->fournisseur->facture->lire)
accessforbidden();
47 $object_status =
GETPOST(
'object_status',
'intcomma');
48 $typent_id =
GETPOST(
'typent_id',
'int');
49 $categ_id =
GETPOST(
'categ_id',
'categ_id');
51 $userid =
GETPOST(
'userid',
'int');
52 $socid =
GETPOST(
'socid',
'int');
53 $custcats =
GETPOST(
'custcats',
'array');
58 $socid = $user->socid;
61 $nowyear = strftime(
"%Y",
dol_now());
63 if (!empty($conf->global->INVOICE_STATS_GRAPHS_SHOW_2_YEARS)) $startyear = $year - 2;
64 else $startyear = $year - 1;
71 if (!empty($conf->category->enabled)) $langs->load(
'categories');
72 $form =
new Form($db);
79 $title = $langs->trans(
"BillsStatistics");
80 $dir = $conf->facture->dir_temp;
82 if ($mode ==
'supplier')
84 $picto =
'supplier_invoice';
85 $title = $langs->trans(
"BillsStatisticsSuppliers");
86 $dir = $conf->fournisseur->facture->dir_temp;
94 $stats =
new FactureStats($db, $socid, $mode, ($userid > 0 ? $userid : 0), ($typent_id > 0 ? $typent_id : 0), ($categ_id > 0 ? $categ_id : 0));
95 if ($mode ==
'customer')
97 if ($object_status !=
'' && $object_status >= 0) $stats->where .=
' AND f.fk_statut IN ('.$db->sanitize($db->escape($object_status)).
')';
98 if (is_array($custcats) && !empty($custcats)) {
99 $stats->from .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'categorie_societe as cat ON (f.fk_soc = cat.fk_soc)';
100 $stats->where .=
' AND cat.fk_categorie IN ('.implode(
',', $custcats).
')';
103 if ($mode ==
'supplier')
105 if ($object_status !=
'' && $object_status >= 0) $stats->where .=
' AND f.fk_statut IN ('.$db->sanitize($db->escape($object_status)).
')';
110 $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
113 $filenamenb = $dir.
"/invoicesnbinyear-".$year.
".png";
114 if ($mode ==
'customer') $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstats&file=invoicesnbinyear-'.$year.
'.png';
115 if ($mode ==
'supplier') $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstatssupplier&file=invoicesnbinyear-'.$year.
'.png';
118 $mesg = $px1->isGraphKo();
121 $px1->SetData($data);
122 $i = $startyear; $legend = array();
123 while ($i <= $endyear)
128 $px1->SetLegend($legend);
129 $px1->SetMaxValue($px1->GetCeilMaxValue());
130 $px1->SetWidth($WIDTH);
131 $px1->SetHeight($HEIGHT);
132 $px1->SetYLabel($langs->trans(
"NumberOfBills"));
134 $px1->SetHorizTickIncrement(1);
135 $px1->mode =
'depth';
136 $px1->SetTitle($langs->trans(
"NumberOfBillsByMonth"));
138 $px1->draw($filenamenb, $fileurlnb);
142 $data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
146 $filenameamount = $dir.
"/invoicesamountinyear-".$year.
".png";
147 if ($mode ==
'customer') $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstats&file=invoicesamountinyear-'.$year.
'.png';
148 if ($mode ==
'supplier') $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=billstatssupplier&file=invoicesamountinyear-'.$year.
'.png';
151 $mesg = $px2->isGraphKo();
154 $px2->SetData($data);
155 $i = $startyear; $legend = array();
156 while ($i <= $endyear)
161 $px2->SetLegend($legend);
162 $px2->SetMaxValue($px2->GetCeilMaxValue());
163 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
164 $px2->SetWidth($WIDTH);
165 $px2->SetHeight($HEIGHT);
166 $px2->SetYLabel($langs->trans(
"AmountOfBills"));
168 $px2->SetHorizTickIncrement(1);
169 $px2->mode =
'depth';
170 $px2->SetTitle($langs->trans(
"AmountOfBillsByMonthHT"));
172 $px2->draw($filenameamount, $fileurlamount);
176 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
178 if (!$user->rights->societe->client->voir || $user->socid)
180 $filename_avg = $dir.
'/ordersaverage-'.$user->id.
'-'.$year.
'.png';
181 if ($mode ==
'customer') $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
182 if ($mode ==
'supplier') $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
184 $filename_avg = $dir.
'/ordersaverage-'.$year.
'.png';
185 if ($mode ==
'customer') $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.
'.png';
186 if ($mode ==
'supplier') $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.
'.png';
190 $mesg = $px3->isGraphKo();
193 $px3->SetData($data);
194 $i = $startyear; $legend = array();
195 while ($i <= $endyear)
200 $px3->SetLegend($legend);
201 $px3->SetYLabel($langs->trans(
"AmountAverage"));
202 $px3->SetMaxValue($px3->GetCeilMaxValue());
203 $px3->SetMinValue($px3->GetFloorMinValue());
204 $px3->SetWidth($WIDTH);
205 $px3->SetHeight($HEIGHT);
207 $px3->SetHorizTickIncrement(1);
208 $px3->mode =
'depth';
209 $px3->SetTitle($langs->trans(
"AmountAverage"));
211 $px3->draw($filename_avg, $fileurl_avg);
216 $data = $stats->getAllByYear();
217 $arrayyears = array();
218 foreach ($data as $val) {
219 $arrayyears[$val[
'year']] = $val[
'year'];
221 if (!count($arrayyears)) $arrayyears[$nowyear] = $nowyear;
226 $head[$h][0] = DOL_URL_ROOT.
'/compta/facture/stats/index.php?mode='.$mode;
227 $head[$h][1] = $langs->trans(
"ByMonthYear");
228 $head[$h][2] =
'byyear';
231 if ($mode ==
'customer') $type =
'invoice_stats';
232 if ($mode ==
'supplier') $type =
'supplier_invoice_stats';
239 $tmp_companies = $form->select_thirdparty_list($socid,
'socid', $filter, 1, 0, 0, array(),
'', 1);
241 $companies = array();
243 foreach ($tmp_companies as $value) {
244 $companies[$value[
'key']] = $value[
'label'];
247 print '<div class="fichecenter"><div class="fichethirdleft">';
251 print '<form name="stats" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
252 print '<input type="hidden" name="token" value="'.newToken().
'">';
253 print '<input type="hidden" name="mode" value="'.$mode.
'">';
255 print '<table class="noborder centpercent">';
256 print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
258 print '<tr><td>'.$langs->trans(
"ThirdParty").
'</td><td>';
259 if ($mode ==
'customer') $filter =
's.client in (1,2,3)';
260 if ($mode ==
'supplier') $filter =
's.fournisseur = 1';
261 print $form->selectarray(
'socid', $companies, $socid, 1, 0, 0,
'style="width: 95%"', 0, 0, 0,
'',
'', 1);
265 print '<tr><td>'.$langs->trans(
"ThirdPartyType").
'</td><td>';
266 $sortparam_typent = (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ?
'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT);
267 print $form->selectarray(
"typent_id", $formcompany->typent_array(0), $typent_id, 0, 0, 0,
'', 0, 0, 0, $sortparam_typent);
268 if ($user->admin)
print ' '.info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
272 if (!empty($conf->category->enabled)) {
273 if ($mode ==
'customer')
275 $cat_type = Categorie::TYPE_CUSTOMER;
276 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Customer"));
278 if ($mode ==
'supplier')
280 $cat_type = Categorie::TYPE_SUPPLIER;
281 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Supplier"));
283 print '<tr><td>'.$cat_label.
'</td><td>';
284 $cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null,
'parent', null, null, 1);
285 print $form->multiselectarray(
'custcats', $cate_arbo,
GETPOST(
'custcats',
'array'), null, null, null, null,
"90%");
291 print '<tr><td>'.$langs->trans(
"CreatedBy").
'</td><td>';
292 print $form->select_dolusers($userid,
'userid', 1,
'', 0,
'',
'', 0, 0, 0,
'', 0,
'',
'maxwidth300');
295 print '<tr><td class="left">'.$langs->trans(
"Status").
'</td><td class="left">';
296 if ($mode ==
'customer')
298 $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"));
299 print $form->selectarray(
'object_status', $liststatus, $object_status, 1);
301 if ($mode ==
'supplier')
303 $liststatus = array(
'0'=>$langs->trans(
"BillStatusDraft"),
'1'=>$langs->trans(
"BillStatusNotPaid"),
'2'=>$langs->trans(
"BillStatusPaid"));
304 print $form->selectarray(
'object_status', $liststatus, $object_status, 1);
308 print '<tr><td>'.$langs->trans(
"Year").
'</td><td>';
309 if (!in_array($year, $arrayyears)) $arrayyears[$year] = $year;
310 if (!in_array($nowyear, $arrayyears)) $arrayyears[$nowyear] = $nowyear;
312 print $form->selectarray(
'year', $arrayyears, $year, 0);
314 print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
319 print '<div class="div-table-responsive-no-min">';
320 print '<table class="noborder centpercent">';
321 print '<tr class="liste_titre" height="24">';
322 print '<td class="center">'.$langs->trans(
"Year").
'</td>';
323 print '<td class="right">'.$langs->trans(
"NumberOfBills").
'</td>';
324 print '<td class="right">%</td>';
325 print '<td class="right">'.$langs->trans(
"AmountTotal").
'</td>';
326 print '<td class="right">%</td>';
327 print '<td class="right">'.$langs->trans(
"AmountAverage").
'</td>';
328 print '<td class="right">%</td>';
332 foreach ($data as $val)
334 $year = $val[
'year'];
335 while ($year && $oldyear > $year + 1)
339 print '<tr class="oddeven" height="24">';
340 print '<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$oldyear.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$oldyear.
'</a></td>';
341 print '<td class="right">0</td>';
342 print '<td class="right"></td>';
343 print '<td class="right">0</td>';
344 print '<td class="right"></td>';
345 print '<td class="right">0</td>';
346 print '<td class="right"></td>';
350 print '<tr class="oddeven" height="24">';
351 print '<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$year.
'</a></td>';
352 print '<td class="right">'.$val[
'nb'].
'</td>';
353 print '<td class="right" style="'.(($val[
'nb_diff'] >= 0) ?
'color: green;' :
'color: red;').
'">'.round($val[
'nb_diff']).
'</td>';
354 print '<td class="right">'.price(
price2num($val[
'total'],
'MT'), 1).
'</td>';
355 print '<td class="right" style="'.(($val[
'total_diff'] >= 0) ?
'color: green;' :
'color: red;').
'">'.round($val[
'total_diff']).
'</td>';
356 print '<td class="right">'.price(
price2num($val[
'avg'],
'MT'), 1).
'</td>';
357 print '<td class="right" style="'.(($val[
'avg_diff'] >= 0) ?
'color: green;' :
'color: red;').
'">'.round($val[
'avg_diff']).
'</td>';
365 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
369 print '<table class="border centpercent"><tr class="pair nohover"><td align="center">';
370 if ($mesg) {
print $mesg; }
else {
377 print '</td></tr></table>';
380 print '</div></div></div>';
381 print '<div style="clear:both"></div>';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_now($mode= 'auto')
Return date for now.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
static getDefaultGraphSizeForStats($direction, $defaultsize= '')
getDefaultGraphSizeForStats
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode= 'add')
Complete or removed entries into a head array (used to build tabs).
Class to manage stats for invoices (customer and supplier)
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)