18 include_once DOL_DOCUMENT_ROOT.
'/core/class/stats.class.php';
19 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
43 require_once
'project.class.php';
58 global $conf, $user, $langs;
63 $sql .=
" SUM(t.opp_amount), t.fk_opp_status, cls.code, cls.label";
64 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as t";
68 $sql .=
", ".MAIN_DB_PREFIX.
"c_lead_status as cls";
74 $sql .=
" AND t.fk_opp_status = cls.rowid";
75 $sql .=
" AND t.fk_statut <> 0";
76 $sql .=
" GROUP BY t.fk_opp_status, cls.code, cls.label";
80 dol_syslog(get_class($this).
'::'.__METHOD__.
"", LOG_DEBUG);
88 if ($i < $limit || $num == $limit)
90 $label = (($langs->trans(
"OppStatus".$row[2]) !=
"OppStatus".$row[2]) ? $langs->trans(
"OppStatus".$row[2]) : $row[2]);
92 $label.
' ('.
price(
price2num($row[0],
'MT'), 1, $langs, 1, -1, -1, $conf->currency).
')',
95 }
else $other += $row[1];
100 $langs->transnoentitiesnoconv(
"Other"),
105 $this->error =
"Error ".$this->db->lasterror();
106 dol_syslog(get_class($this).
'::'.__METHOD__.
' '.$this->error, LOG_ERR);
120 global $conf, $user, $langs;
126 $sql =
"SELECT date_format(t.datec,'%Y') as year, COUNT(t.rowid) as nb, SUM(t.opp_amount) as total, AVG(t.opp_amount) as avg,";
127 $sql .=
" SUM(t.opp_amount * ".$this->db->ifsql(
"t.opp_percent IS NULL".($wonlostfilter ?
" OR cls.code IN ('WON','LOST')" :
""),
'0',
't.opp_percent').
" / 100) as weighted";
128 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as t LEFT JOIN ".MAIN_DB_PREFIX.
"c_lead_status as cls ON cls.rowid = t.fk_opp_status";
137 $sql .=
" GROUP BY year";
138 $sql .= $this->
db->order(
'year',
'DESC');
158 $projectsListId =
'';
159 if (!$user->rights->projet->all->lire) $projectsListId = $object->getProjectsAuthorizedForUser($user, 0, 1, $user->socid);
161 $sqlwhere[] =
' t.entity IN ('.getEntity(
'project').
')';
163 if (!empty($this->userid))
164 $sqlwhere[] =
' t.fk_user_resp='.$this->userid;
167 if (!empty($this->socid))
168 $sqlwhere[] =
' t.fk_soc='.$this->socid;
169 if (!empty($this->year) && empty($this->yearmonth))
170 $sqlwhere[] =
" date_format(t.datec,'%Y')='".$this->db->escape($this->year).
"'";
171 if (!empty($this->yearmonth))
174 if (!empty($this->status))
175 $sqlwhere[] =
" t.fk_opp_status IN (".$this->status.
")";
177 if (!$user->rights->projet->all->lire) $sqlwhere[] =
" t.rowid IN (".$projectsListId.
")";
179 if (count($sqlwhere) > 0) {
180 $sqlwhere_str =
' WHERE '.implode(
' AND ', $sqlwhere);
183 return $sqlwhere_str;
197 $this->yearmonth = $year;
199 $sql =
"SELECT date_format(t.datec,'%m') as dm, COUNT(*) as nb";
200 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as t";
205 $sql .=
" GROUP BY dm";
206 $sql .= $this->
db->order(
'dm',
'DESC');
208 $this->yearmonth = 0;
226 $this->yearmonth = $year;
228 $sql =
"SELECT date_format(t.datec,'%m') as dm, SUM(t.opp_amount)";
229 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as t";
234 $sql .=
" GROUP BY dm";
235 $sql .= $this->
db->order(
'dm',
'DESC');
236 $this->yearmonth = 0;
255 global $conf, $user, $langs;
257 if ($startyear > $endyear)
return -1;
262 if (!empty($cachedelay))
264 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
265 include_once DOL_DOCUMENT_ROOT.
'/core/lib/json.lib.php';
268 $newpathofdestfile = $conf->user->dir_temp.
'/'.get_class($this).
'_'.__FUNCTION__.
'_'.(empty($this->cachefilesuffix) ?
'' : $this->cachefilesuffix.
'_').$langs->defaultlang.
'_user'.$user->id.
'.cache';
277 if ($filedate >= ($nowgmt - $cachedelay))
281 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $filedate;
283 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" cache file ".$newpathofdestfile.
" is not found or older than now - cachedelay (".$nowgmt.
" - ".$cachedelay.
") so we can't use it.");
290 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" read data from cache file ".$newpathofdestfile.
" ".$filedate.
".");
291 $data = json_decode(file_get_contents($newpathofdestfile),
true);
294 while ($year <= $endyear)
302 for ($i = 0; $i < 12; $i++)
304 $data[$i][] = $datay[$endyear][$i][0];
306 while ($year <= $endyear)
308 $data[$i][] = $datay[$year][$i][1];
315 if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1))
317 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" save cache file ".$newpathofdestfile.
" onto disk.");
319 $fp = fopen($newpathofdestfile,
'w');
322 fwrite($fp, json_encode($data));
324 if (!empty($conf->global->MAIN_UMASK)) $newmask = $conf->global->MAIN_UMASK;
325 @chmod($newpathofdestfile, octdec($newmask));
326 }
else dol_syslog(
"Failed to write cache file", LOG_ERR);
327 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $nowgmt;
345 $this->yearmonth = $year;
347 $sql =
"SELECT date_format(t.datec,'%m') as dm, SUM(t.opp_amount * ".$this->db->ifsql(
"t.opp_percent IS NULL".($wonlostfilter ?
" OR cls.code IN ('WON','LOST')" :
""),
'0',
't.opp_percent').
" / 100)";
348 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as t LEFT JOIN ".MAIN_DB_PREFIX.
'c_lead_status as cls ON t.fk_opp_status = cls.rowid';
353 $sql .=
" GROUP BY dm";
354 $sql .= $this->
db->order(
'dm',
'DESC');
355 $this->yearmonth = 0;
372 global $conf, $user, $langs;
374 if ($startyear > $endyear)
return -1;
379 if (!empty($cachedelay))
381 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
382 include_once DOL_DOCUMENT_ROOT.
'/core/lib/json.lib.php';
385 $newpathofdestfile = $conf->user->dir_temp.
'/'.get_class($this).
'_'.__FUNCTION__.
'_'.(empty($this->cachefilesuffix) ?
'' : $this->cachefilesuffix.
'_').$langs->defaultlang.
'_user'.$user->id.
'.cache';
391 if ($cachedelay > 0) {
393 if ($filedate >= ($nowgmt - $cachedelay)) {
396 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $filedate;
398 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" cache file ".$newpathofdestfile.
" is not found or older than now - cachedelay (".$nowgmt.
" - ".$cachedelay.
") so we can't use it.");
405 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" read data from cache file ".$newpathofdestfile.
" ".$filedate.
".");
406 $data = json_decode(file_get_contents($newpathofdestfile),
true);
409 while ($year <= $endyear) {
416 for ($i = 0; $i < 12; $i++) {
417 $data[$i][] = $datay[$endyear][$i][0];
419 while ($year <= $endyear) {
420 $data[$i][] = $datay[$year][$i][1];
427 if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == - 1)) {
428 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" save cache file ".$newpathofdestfile.
" onto disk.");
431 $fp = fopen($newpathofdestfile,
'w');
432 fwrite($fp, json_encode($data));
434 if (!empty($conf->global->MAIN_UMASK))
435 $newmask = $conf->global->MAIN_UMASK;
436 @chmod($newpathofdestfile, octdec($newmask));
438 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $nowgmt;
455 $this->yearmonth = $year;
457 $sql =
"SELECT date_format(t.datec,'%m') as dm, count(t.opp_amount)";
458 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as t";
463 $sql .=
" GROUP BY dm";
464 $sql .= $this->
db->order(
'dm',
'DESC');
470 $sql =
"SELECT date_format(t.datec,'%m') as dm, count(t.opp_amount)";
471 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as t";
476 $sql .=
" GROUP BY dm";
477 $sql .= $this->
db->order(
'dm',
'DESC');
480 $this->yearmonth = 0;
482 $res_only_wined = $this->
_getNbByMonth($year, $sql, $format);
486 foreach ($res_total as $key=>$total_row) {
488 if (!empty($total_row[1])) {
489 $res[$key] = array($total_row[0], (100 * $res_only_wined[$key][1]) / $total_row[1]);
491 $res[$key] = array($total_row[0], 0);
Parent class of statistics class.
getAllProjectByStatus($limit=5)
Return all leads grouped by opportunity status.
dol_now($mode= 'auto')
Return date for now.
getWeightedAmountByMonthWithPrevYear($endyear, $startyear, $cachedelay=0, $wonlostfilter=1)
Return amount of elements by month for several years.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
getTransformRateByMonthWithPrevYear($endyear, $startyear, $cachedelay=0)
Return amount of elements by month for several years.
dol_is_dir($folder)
Test if filename is a directory.
getTransformRateByMonth($year, $format=0)
Return the Project transformation rate by month for a year.
_getNbByMonth($year, $sql, $format=0)
Renvoie le nombre de documents par mois pour une annee donnee Return number of documents per month fo...
$conf db
API class for accounts.
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
getAmountByMonth($year, $format=0)
Return the Project amount by month for a year.
buildWhere()
Build the where part.
Class to manage projects.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
_getAllByYear($sql)
Return nb of elements, total amount and avg amount each year.
getWeightedAmountByMonth($year, $wonlostfilter=1)
Return the Project weighted opp amount by month for a year.
getNbByMonth($year, $format=0)
Return Project number by month for a year.
Class to manage statistics on projects.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
dol_filemtime($pathoffile)
Return time of a file.
getAllByYear()
Return count, and sum of products.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
_getAmountByMonth($year, $sql, $format=0)
Return the amount per month for a given year.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)
__construct($db)
Constructor.