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';
54$hookmanager->initHooks(array(
'contratstats',
'globalcard'));
56$object_status =
GETPOST(
'object_status',
'intcomma');
65if ($user->socid > 0) {
67 $socid = $user->socid;
71$usercanreadcustumerstatistic = $user->hasRight(
'contrat',
'lire');
73 $usercanreadcustumerstatistic = $user->hasRight(
'contrat',
'export');
75if (!$usercanreadcustumerstatistic) {
80$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
82 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
91$langs->loadLangs(array(
'contracts',
'companies',
'other',
'suppliers'));
103$title = $langs->trans(
"Contracts");
104$dir =
$conf->contract->dir_temp;
107llxHeader(
'', $title,
'',
'', 0, 0,
'',
'',
'',
'mod-contract page-stats');
113$massactionbutton =
'';
115$nbtotalofrecords = $langs->trans(
"Statistics");
118$urlnew = DOL_URL_ROOT.
'/contrat/card.php?action=create';
120 $urlnew .=
'&socid='.$socid;
124$newcardbutton .=
dolGetButtonTitle($langs->trans(
'ViewList'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/contrat/list.php?mode=common',
'', 1, array(
'morecss' =>
'reposition'));
125$newcardbutton .=
dolGetButtonTitle($langs->trans(
'ViewKanban'),
'',
'fa fa-th-list imgforviewmode', DOL_URL_ROOT.
'/contrat/list.php?mode=kanban',
'', 1, array(
'morecss' =>
'reposition'));
126$newcardbutton .=
dolGetButtonTitle($langs->trans(
'Statistics'),
'',
'fa fa-chart-bar imgforviewmode', DOL_URL_ROOT.
'/contrat/stats/index.php',
'', 2, array(
'morecss' =>
'reposition'));
128$newcardbutton .=
dolGetButtonTitle($langs->trans(
'NewContractSubscription'),
'',
'fa fa-plus-circle', $urlnew,
'', $user->hasRight(
'contrat',
'creer'));
130print_barre_liste($title, $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $picto, 0, $newcardbutton,
'', $limit, 0, 0, 1);
134$stats =
new ContratStats($db, $socid, $mode, ($userid > 0 ? $userid : 0), ($typent_id > 0 ? $typent_id : 0), ($categ_id > 0 ? $categ_id : 0));
136if ($object_status !=
'' && $object_status >= -1) {
137 $stats->where .=
' AND c.statut IN ('.$db->sanitize($object_status).
')';
143$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
150if (!$user->hasRight(
'societe',
'client',
'voir')) {
151 $filenamenb = $dir.
'/contractsnbinyear-'.$user->id.
'-'.$year.
'.png';
152 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=contractstats&file=contractsnbinyear-'.$user->id.
'-'.$year.
'.png';
154 $filenamenb = $dir.
'/contractsnbinyear-'.$year.
'.png';
155 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=contractstats&file=contractsnbinyear-'.$year.
'.png';
159$mesg = $px1->isGraphKo();
161 $px1->SetData($data);
164 while ($i <= $endyear) {
168 $px1->SetLegend($legend);
169 $px1->SetMaxValue($px1->GetCeilMaxValue());
170 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
171 $px1->SetWidth($WIDTH);
172 $px1->SetHeight($HEIGHT);
173 $px1->SetYLabel($langs->trans(
"NbOfContracts"));
175 $px1->SetHorizTickIncrement(1);
176 $px1->mode =
'depth';
177 $px1->SetTitle($langs->trans(
"NumberOfContractsByMonth"));
179 $px1->draw($filenamenb, $fileurlnb);
183$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
188if (!$user->hasRight(
'societe',
'client',
'voir')) {
189 $filenameamount = $dir.
'/contractsamountinyear-'.$user->id.
'-'.$year.
'.png';
190 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=contractstats&file=contractsamountinyear-'.$user->id.
'-'.$year.
'.png';
192 $filenameamount = $dir.
'/contractsamountinyear-'.$year.
'.png';
193 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=contractstats&file=contractsamountinyear-'.$year.
'.png';
197$mesg = $px2->isGraphKo();
199 $px2->SetData($data);
202 while ($i <= $endyear) {
206 $px2->SetLegend($legend);
207 $px2->SetMaxValue($px2->GetCeilMaxValue());
208 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
209 $px2->SetWidth($WIDTH);
210 $px2->SetHeight($HEIGHT);
211 $px2->SetYLabel($langs->trans(
"AmountOfServices"));
213 $px2->SetHorizTickIncrement(1);
214 $px2->mode =
'depth';
215 $px2->SetTitle($langs->trans(
"AmountOfServicesByMonthHT"));
217 $px2->draw($filenameamount, $fileurlamount);
223$data = $stats->getAllByYear();
224$arrayyears = array();
225foreach ($data as $val) {
226 if (!empty($val[
'year'])) {
227 $arrayyears[$val[
'year']] = $val[
'year'];
230if (!count($arrayyears)) {
231 $arrayyears[$nowyear] = $nowyear;
236$head[$h][0] = DOL_URL_ROOT.
'/contrat/stats/index.php?mode='.$mode;
237$head[$h][1] = $langs->trans(
"ByMonthYear");
238$head[$h][2] =
'byyear';
241$type =
'contract_stats';
249print
'<div class="fichecenter"><div class="fichethirdleft">';
253print
'<form name="stats" method="POST" action="'.dolBuildUrl($_SERVER[
"PHP_SELF"]).
'">';
254print
'<input type="hidden" name="token" value="'.newToken().
'">';
255print
'<input type="hidden" name="mode" value="'.$mode.
'">';
257print
'<table class="noborder centpercent">';
258print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
260print
'<tr><td class="left">'.$langs->trans(
"ThirdParty").
'</td><td class="left">';
262if ($mode ==
'customer') {
263 $filter =
'(s.client:IN:1,2,3)';
265if ($mode ==
'supplier') {
266 $filter =
'(s.fournisseur:=:1)';
268print img_picto(
'',
'company',
'class="pictofixedwidth"');
269print $form->select_company($socid,
'socid', $filter, 1, 0, 0, array(), 0,
'widthcentpercentminusx maxwidth300');
272print
'<tr><td>'.$langs->trans(
"ThirdPartyType").
'</td><td>';
273$sortparam_typent = (!
getDolGlobalString(
'SOCIETE_SORT_ON_TYPEENT') ?
'ASC' :
$conf->global->SOCIETE_SORT_ON_TYPEENT);
274print $form->selectarray(
"typent_id", $formcompany->typent_array(0), $typent_id, 1, 0, 0,
'', 0, 0, 0, $sortparam_typent,
'', 1);
276 print
' '.info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
282if ($mode ==
'customer') {
283 $cat_type = Categorie::TYPE_CUSTOMER;
284 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Customer"));
286if ($mode ==
'supplier') {
287 $cat_type = Categorie::TYPE_SUPPLIER;
288 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Supplier"));
290print
'<tr><td>'.$cat_label.
'</td><td>';
291print img_picto(
'',
'category',
'class="pictofixedwidth"');
292print $formother->select_categories($cat_type, $categ_id,
'categ_id', 0, 1,
'widthcentpercentminusx maxwidth300');
295print
'<tr><td>'.$langs->trans(
"CreatedBy").
'</td><td>';
296print img_picto(
'',
'user',
'class="pictofixedwidth"');
297print $form->select_dolusers($userid,
'userid', 1,
null, 0,
'',
'',
'0', 0, 0,
'', 0,
'',
'widthcentpercentminusx maxwidth300');
299print
'<tr><td>'.$langs->trans(
"Status").
'</td><td>';
302 Contrat::STATUS_DRAFT => $langs->trans(
"ContractStatusDraft"),
303 Contrat::STATUS_VALIDATED => $langs->trans(
"ContractStatusValidated"),
304 Contrat::STATUS_CLOSED => $langs->trans(
"ContractStatusClosed"),
306print $form->selectarray(
'object_status', $liststatus,
GETPOST(
'object_status',
'intcomma'), -4);
311print
'<tr><td class="left">'.$langs->trans(
"Year").
'</td><td class="left">';
312if (!in_array($year, $arrayyears)) {
313 $arrayyears[$year] = $year;
315if (!in_array($nowyear, $arrayyears)) {
316 $arrayyears[$nowyear] = $nowyear;
319print img_picto(
'',
'calendar',
'class="pictofixedwidth"');
320print $form->selectarray(
'year', $arrayyears, $year, 0, 0, 0,
'', 0, 0, 0,
'',
'width75');
322print
'<tr><td align="center" colspan="2"><input type="submit" class="button small" name="submit" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
328print
'<div class="div-table-responsive-no-min">';
329print
'<table class="noborder centpercent">';
330print
'<tr class="liste_titre" height="24">';
331print
'<td class="center">'.$langs->trans(
"Year").
'</td>';
332print
'<td class="right">'.$langs->trans(
"NbOfContracts").
'</td>';
333print
'<td class="right">%</td>';
334print
'<td class="right">'.$langs->trans(
"AmountTotal").
'</td>';
335print
'<td class="right">%</td>';
336print
'<td class="right">'.$langs->trans(
"AmountAverage").
'</td>';
337print
'<td class="right">%</td>';
341foreach ($data as $val) {
342 $year = $val[
'year'];
343 while (!empty($year) && $oldyear > (
int) $year + 1) {
346 print
'<tr class="oddeven" height="24">';
347 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$oldyear.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$oldyear.
'</a></td>';
349 $isyearbeforeval = ($oldyear == (int) $year + 1);
350 print
'<td class="right">0</td>';
351 print
'<td class="right opacitylow" style="color: red;">'.(($isyearbeforeval && $val[
'nb'] > 0) ?
'-100%' :
'').
'</td>';
352 print
'<td class="right">0</td>';
353 print
'<td class="right opacitylow" style="color: red;">'.(($isyearbeforeval && $val[
'total'] > 0) ?
'-100%' :
'').
'</td>';
354 print
'<td class="right">0</td>';
355 print
'<td class="right opacitylow" style="color: red;">'.(($isyearbeforeval && $val[
'avg'] > 0) ?
'-100%' :
'').
'</td>';
360 print
'<tr class="oddeven" height="24">';
361 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$year.
'</a></td>';
362 print
'<td class="right">'.$val[
'nb'].
'</td>';
363 print
'<td class="right opacitylow" style="'.((!isset($val[
'nb_diff']) || $val[
'nb_diff'] >= 0) ?
'color: green;' :
'color: red;').
'">'.(isset($val[
'nb_diff']) ? ($val[
'nb_diff'] < 0 ?
'' :
'+').round($val[
'nb_diff']).
'%' :
'').
'</td>';
364 print
'<td class="right">'.price(
price2num($val[
'total'],
'MT'), 1).
'</td>';
365 print
'<td class="right opacitylow" style="'.((!isset($val[
'total_diff']) || $val[
'total_diff'] >= 0) ?
'color: green;' :
'color: red;').
'">'.(isset($val[
'total_diff']) ? ($val[
'total_diff'] < 0 ?
'' :
'+').round($val[
'total_diff']).
'%' :
'').
'</td>';
366 print
'<td class="right">'.price(
price2num($val[
'avg'],
'MT'), 1).
'</td>';
367 print
'<td class="right opacitylow" style="'.((!isset($val[
'avg_diff']) || $val[
'avg_diff'] >= 0) ?
'color: green;' :
'color: red;').
'">'.(isset($val[
'avg_diff']) ? ($val[
'avg_diff'] < 0 ?
'' :
'+').round($val[
'avg_diff']).
'%' :
'').
'</td>';
376print
'</div><div class="fichetwothirdright">';
380print
'<table class="border centpercent"><tr class="pair nohover"><td align="center">';
388print
'</td></tr></table>';
392print
'<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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage contract statistics.
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
dol_now($mode='gmt')
Return date for now.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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)
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.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.