34require
'../../main.inc.php';
42require_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/contrat/class/contratstats.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
52$mode = GETPOSTISSET(
"mode") ?
GETPOST(
"mode",
'aZ09') :
'customer';
54$hookmanager->initHooks(array(
'contratstats',
'globalcard'));
56$usercanreadcustumerstatistic = $user->hasRight(
'commande',
'lire');
57$usercanreadsupplierstatistic = $user->hasRight(
'fournisseur',
'commande',
'lire');
59 $usercanreadcustumerstatistic = $user->hasRight(
'commande',
'commande',
'export');
60 $usercanreadsupplierstatistic = $user->hasRight(
'fournisseur',
'commande',
'export');
62if ($mode ==
'customer' && !$usercanreadcustumerstatistic) {
65if ($mode ==
'supplier' && !$usercanreadsupplierstatistic) {
69if ($mode ==
'supplier') {
70 $object_status =
GETPOST(
'object_status',
'array:int');
71 $object_status = implode(
',', $object_status);
73 $object_status =
GETPOST(
'object_status',
'intcomma');
83if ($user->socid > 0) {
85 $socid = $user->socid;
89$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
100$langs->loadLangs(array(
'contracts',
'companies',
'other',
'suppliers'));
112$title = $langs->trans(
"ContractsStatistics");
113$dir =
$conf->contract->dir_temp;
117llxHeader(
'', $title,
'',
'', 0, 0,
'',
'',
'',
'mod-contract page-stats');
123$massactionbutton =
'';
125$nbtotalofrecords = $langs->trans(
"Statistics");
128$urlnew = DOL_URL_ROOT.
'/contrat/card.php?action=create';
130 $urlnew .=
'&socid='.$socid;
134$newcardbutton .= dolGetButtonTitle($langs->trans(
'ViewList'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/contrat/list.php?mode=common',
'', 1, array(
'morecss' =>
'reposition'));
135$newcardbutton .= dolGetButtonTitle($langs->trans(
'ViewKanban'),
'',
'fa fa-th-list imgforviewmode', DOL_URL_ROOT.
'/contrat/list.php?mode=kanban',
'', 1, array(
'morecss' =>
'reposition'));
136$newcardbutton .= dolGetButtonTitle($langs->trans(
'Statistics'),
'',
'fa fa-chart-bar imgforviewmode', DOL_URL_ROOT.
'/contrat/stats/index.php',
'', 2, array(
'morecss' =>
'reposition'));
137$newcardbutton .= dolGetButtonTitleSeparator();
138$newcardbutton .= dolGetButtonTitle($langs->trans(
'NewContractSubscription'),
'',
'fa fa-plus-circle', $urlnew,
'', $user->hasRight(
'contrat',
'creer'));
140print_barre_liste($title, $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $picto, 0, $newcardbutton,
'', $limit, 0, 0, 1);
144$stats =
new ContratStats(
$db, $socid, $mode, ($userid > 0 ? $userid : 0), ($typent_id > 0 ? $typent_id : 0), ($categ_id > 0 ? $categ_id : 0));
146if ($object_status !=
'' && $object_status >= -1) {
147 $stats->where .=
' AND c.statut IN ('.$db->sanitize($object_status).
')';
153$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
160if (!$user->hasRight(
'societe',
'client',
'voir')) {
161 $filenamenb = $dir.
'/contractsnbinyear-'.$user->id.
'-'.$year.
'.png';
162 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=contractstats&file=contractsnbinyear-'.$user->id.
'-'.$year.
'.png';
164 $filenamenb = $dir.
'/contractsnbinyear-'.$year.
'.png';
165 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=contractstats&file=contractsnbinyear-'.$year.
'.png';
169$mesg = $px1->isGraphKo();
171 $px1->SetData($data);
174 while ($i <= $endyear) {
178 $px1->SetLegend($legend);
179 $px1->SetMaxValue($px1->GetCeilMaxValue());
180 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
181 $px1->SetWidth($WIDTH);
182 $px1->SetHeight($HEIGHT);
183 $px1->SetYLabel($langs->trans(
"NbOfContracts"));
185 $px1->SetHorizTickIncrement(1);
186 $px1->mode =
'depth';
187 $px1->SetTitle($langs->trans(
"NumberOfContractsByMonth"));
189 $px1->draw($filenamenb, $fileurlnb);
193$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
198if (!$user->hasRight(
'societe',
'client',
'voir')) {
199 $filenameamount = $dir.
'/contractsamountinyear-'.$user->id.
'-'.$year.
'.png';
200 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=contractstats&file=contractsamountinyear-'.$user->id.
'-'.$year.
'.png';
202 $filenameamount = $dir.
'/contractsamountinyear-'.$year.
'.png';
203 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=contractstats&file=contractsamountinyear-'.$year.
'.png';
207$mesg = $px2->isGraphKo();
209 $px2->SetData($data);
212 while ($i <= $endyear) {
216 $px2->SetLegend($legend);
217 $px2->SetMaxValue($px2->GetCeilMaxValue());
218 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
219 $px2->SetWidth($WIDTH);
220 $px2->SetHeight($HEIGHT);
221 $px2->SetYLabel($langs->trans(
"AmountOfServices"));
223 $px2->SetHorizTickIncrement(1);
224 $px2->mode =
'depth';
225 $px2->SetTitle($langs->trans(
"AmountOfServicesByMonthHT"));
227 $px2->draw($filenameamount, $fileurlamount);
235$data = $stats->getAllByYear();
236$arrayyears = array();
237foreach ($data as $val) {
238 if (!empty($val[
'year'])) {
239 $arrayyears[$val[
'year']] = $val[
'year'];
242if (!count($arrayyears)) {
243 $arrayyears[$nowyear] = $nowyear;
248$head[$h][0] = DOL_URL_ROOT.
'/contrat/stats/index.php?mode='.$mode;
249$head[$h][1] = $langs->trans(
"ByMonthYear");
250$head[$h][2] =
'byyear';
253$type =
'contract_stats';
261print
'<div class="fichecenter"><div class="fichethirdleft">';
265print
'<form name="stats" method="POST" action="'.dolBuildUrl($_SERVER[
"PHP_SELF"]).
'">';
266print
'<input type="hidden" name="token" value="'.newToken().
'">';
267print
'<input type="hidden" name="mode" value="'.$mode.
'">';
269print
'<table class="noborder centpercent">';
270print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
272print
'<tr><td class="left">'.$langs->trans(
"ThirdParty").
'</td><td class="left">';
274if ($mode ==
'customer') {
275 $filter =
'(s.client:IN:1,2,3)';
277if ($mode ==
'supplier') {
278 $filter =
'(s.fournisseur:=:1)';
280print
img_picto(
'',
'company',
'class="pictofixedwidth"');
281print $form->select_company($socid,
'socid', $filter, 1, 0, 0, array(), 0,
'widthcentpercentminusx maxwidth300');
284print
'<tr><td>'.$langs->trans(
"ThirdPartyType").
'</td><td>';
285$sortparam_typent = (!
getDolGlobalString(
'SOCIETE_SORT_ON_TYPEENT') ?
'ASC' :
$conf->global->SOCIETE_SORT_ON_TYPEENT);
286print $form->selectarray(
"typent_id", $formcompany->typent_array(0), $typent_id, 1, 0, 0,
'', 0, 0, 0, $sortparam_typent,
'', 1);
288 print
' '.info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
294if ($mode ==
'customer') {
295 $cat_type = Categorie::TYPE_CUSTOMER;
296 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Customer"));
298if ($mode ==
'supplier') {
299 $cat_type = Categorie::TYPE_SUPPLIER;
300 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Supplier"));
302print
'<tr><td>'.$cat_label.
'</td><td>';
303print
img_picto(
'',
'category',
'class="pictofixedwidth"');
304print $formother->select_categories($cat_type, $categ_id,
'categ_id', 0, 1,
'widthcentpercentminusx maxwidth300');
307print
'<tr><td>'.$langs->trans(
"CreatedBy").
'</td><td>';
308print
img_picto(
'',
'user',
'class="pictofixedwidth"');
309print $form->select_dolusers($userid,
'userid', 1,
null, 0,
'',
'',
'0', 0, 0,
'', 0,
'',
'widthcentpercentminusx maxwidth300');
311print
'<tr><td>'.$langs->trans(
"Status").
'</td><td>';
314 Contrat::STATUS_DRAFT => $langs->trans(
"ContractStatusDraft"),
315 Contrat::STATUS_VALIDATED => $langs->trans(
"ContractStatusValidated"),
316 Contrat::STATUS_CLOSED => $langs->trans(
"ContractStatusClosed"),
318print $form->selectarray(
'object_status', $liststatus,
GETPOST(
'object_status',
'intcomma'), -4);
323print
'<tr><td class="left">'.$langs->trans(
"Year").
'</td><td class="left">';
324if (!in_array($year, $arrayyears)) {
325 $arrayyears[$year] = $year;
327if (!in_array($nowyear, $arrayyears)) {
328 $arrayyears[$nowyear] = $nowyear;
331print
img_picto(
'',
'calendar',
'class="pictofixedwidth"');
332print $form->selectarray(
'year', $arrayyears, $year, 0, 0, 0,
'', 0, 0, 0,
'',
'width75');
334print
'<tr><td align="center" colspan="2"><input type="submit" class="button small" name="submit" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
340print
'<div class="div-table-responsive-no-min">';
341print
'<table class="noborder centpercent">';
342print
'<tr class="liste_titre" height="24">';
343print
'<td class="center">'.$langs->trans(
"Year").
'</td>';
344print
'<td class="right">'.$langs->trans(
"NbOfContracts").
'</td>';
345print
'<td class="right">%</td>';
346print
'<td class="right">'.$langs->trans(
"AmountTotal").
'</td>';
347print
'<td class="right">%</td>';
348print
'<td class="right">'.$langs->trans(
"AmountAverage").
'</td>';
349print
'<td class="right">%</td>';
353foreach ($data as $val) {
354 $year = $val[
'year'];
355 while (!empty($year) && $oldyear > (
int) $year + 1) {
358 print
'<tr class="oddeven" height="24">';
359 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$oldyear.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$oldyear.
'</a></td>';
360 print
'<td class="right">0</td>';
361 print
'<td class="right"></td>';
362 print
'<td class="right">0</td>';
363 print
'<td class="right"></td>';
364 print
'<td class="right">0</td>';
365 print
'<td class="right"></td>';
370 print
'<tr class="oddeven" height="24">';
371 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$year.
'</a></td>';
372 print
'<td class="right">'.$val[
'nb'].
'</td>';
373 print
'<td class="right opacitylow" style="'.((!isset($val[
'nb_diff']) || $val[
'nb_diff'] >= 0) ?
'color: green;' :
'color: red;').
'">'.(isset($val[
'nb_diff']) ? round($val[
'nb_diff']) :
"0").
'%</td>';
374 print
'<td class="right">'.price(
price2num($val[
'total'],
'MT'), 1).
'</td>';
375 print
'<td class="right opacitylow" style="'.((!isset($val[
'total_diff']) || $val[
'total_diff'] >= 0) ?
'color: green;' :
'color: red;').
'">'.(isset($val[
'total_diff']) ? round($val[
'total_diff']) :
"0").
'%</td>';
376 print
'<td class="right">'.price(
price2num($val[
'avg'],
'MT'), 1).
'</td>';
377 print
'<td class="right opacitylow" style="'.((!isset($val[
'avg_diff']) || $val[
'avg_diff'] >= 0) ?
'color: green;' :
'color: red;').
'">'.(isset($val[
'avg_diff']) ? round($val[
'avg_diff']) :
"0").
'%</td>';
386print
'</div><div class="fichetwothirdright">';
390print
'<table class="border centpercent"><tr class="pair nohover"><td align="center">';
398print
'</td></tr></table>';
402print
'<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.
Class to manage contract statistics.
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
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.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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).
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.
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.