Merge branch '7.0' of git@github.com:Dolibarr/dolibarr.git into develop

Conflicts:
	htdocs/fourn/class/fournisseur.product.class.php
	htdocs/projet/class/projectstats.class.php
This commit is contained in:
Laurent Destailleur 2018-06-20 21:56:10 +02:00
commit 07c514b85c
2 changed files with 50 additions and 46 deletions

View File

@ -434,8 +434,9 @@ class ProductFournisseur extends Product
function fetch_product_fournisseur_price($rowid, $ignore_expression = 0) function fetch_product_fournisseur_price($rowid, $ignore_expression = 0)
{ {
global $conf; global $conf;
$sql = "SELECT pfp.rowid, pfp.price, pfp.quantity, pfp.unitprice, pfp.remise_percent, pfp.remise, pfp.tva_tx, pfp.default_vat_code, pfp.fk_availability,";
$sql.= " pfp.fk_soc, pfp.ref_fourn, pfp.fk_product, pfp.charges, pfp.fk_supplier_price_expression, pfp.delivery_time_days,"; // , pfp.recuperableonly as fourn_tva_npr"; FIXME this field not exist in llx_product_fournisseur_price $sql = "SELECT pfp.rowid, pfp.price, pfp.quantity, pfp.unitprice, pfp.remise_percent, pfp.remise, pfp.tva_tx, pfp.default_vat_code, pfp.info_bits as fourn_tva_npr, pfp.fk_availability,";
$sql.= " pfp.fk_soc, pfp.ref_fourn, pfp.fk_product, pfp.charges, pfp.fk_supplier_price_expression, pfp.delivery_time_days,";
$sql.= " pfp.supplier_reputation"; $sql.= " pfp.supplier_reputation";
$sql.= " ,pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code"; $sql.= " ,pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code";
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp"; $sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
@ -462,8 +463,7 @@ class ProductFournisseur extends Product
$this->fourn_remise = $obj->remise; $this->fourn_remise = $obj->remise;
$this->fourn_unitprice = $obj->unitprice; $this->fourn_unitprice = $obj->unitprice;
$this->fourn_tva_tx = $obj->tva_tx; $this->fourn_tva_tx = $obj->tva_tx;
// TODO $this->fourn_tva_npr = $obj->fourn_tva_npr;
// $this->fourn_tva_npr = $obj->fourn_tva_npr; // TODO this field not exist in llx_product_fournisseur_price. We should add it ?
// Add also localtaxes // Add also localtaxes
$this->fk_availability = $obj->fk_availability; $this->fk_availability = $obj->fk_availability;
$this->delivery_time_days = $obj->delivery_time_days; $this->delivery_time_days = $obj->delivery_time_days;

View File

@ -83,22 +83,22 @@ class ProjectStats extends Stats
$row = $this->db->fetch_row($resql); $row = $this->db->fetch_row($resql);
if ($i < $limit || $num == $limit) if ($i < $limit || $num == $limit)
{ {
$label = (($langs->trans("OppStatus".$row[2]) != "OppStatus".$row[2]) ? $langs->trans("OppStatus".$row[2]) : $row[2]); $label = (($langs->trans("OppStatus".$row[2]) != "OppStatus".$row[2]) ? $langs->trans("OppStatus".$row[2]) : $row[2]);
$result[$i] = array( $result[$i] = array(
$label. ' (' . price(price2num($row[0], 'MT'), 1, $langs, 1, -1, -1, $conf->currency) . ')', $label. ' (' . price(price2num($row[0], 'MT'), 1, $langs, 1, -1, -1, $conf->currency) . ')',
$row[0] $row[0]
); );
} }
else else
$other += $row[1]; $other += $row[1];
$i++; $i++;
} }
if ($num > $limit) if ($num > $limit)
$result[$i] = array ( $result[$i] = array (
$langs->transnoentitiesnoconv("Other"), $langs->transnoentitiesnoconv("Other"),
$other $other
); );
$this->db->free($resql); $this->db->free($resql);
} else { } else {
$this->error = "Error " . $this->db->lasterror(); $this->error = "Error " . $this->db->lasterror();
dol_syslog(get_class($this) . '::' . __METHOD__ . ' ' . $this->error, LOG_ERR); dol_syslog(get_class($this) . '::' . __METHOD__ . ' ' . $this->error, LOG_ERR);
@ -124,6 +124,9 @@ class ProjectStats extends Stats
$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,"; $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,";
$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"; $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";
$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"; $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";
// No check is done on company permission because readability is managed by public status of project and assignement.
//if (! $user->rights->societe->client->voir && ! $user->soc_id)
// $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id;
$sql.= $this->buildWhere(); $sql.= $this->buildWhere();
// For external user, no check is done on company permission because readability is managed by public status of project and assignement. // For external user, no check is done on company permission because readability is managed by public status of project and assignement.
//if ($socid > 0) $sql.= " AND t.fk_soc = ".$socid; //if ($socid > 0) $sql.= " AND t.fk_soc = ".$socid;
@ -157,6 +160,7 @@ class ProjectStats extends Stats
if (! empty($this->userid)) if (! empty($this->userid))
$sqlwhere[] = ' t.fk_user_resp=' . $this->userid; $sqlwhere[] = ' t.fk_user_resp=' . $this->userid;
// Forced filter on socid is similar to forced filter on project. TODO Use project assignement to allow to not use filter on project // Forced filter on socid is similar to forced filter on project. TODO Use project assignement to allow to not use filter on project
if (! empty($this->socid)) if (! empty($this->socid))
$sqlwhere[] = ' t.fk_soc=' . $this->socid; $sqlwhere[] = ' t.fk_soc=' . $this->socid;
@ -181,7 +185,7 @@ class ProjectStats extends Stats
* Return Project number by month for a year * Return Project number by month for a year
* *
* @param int $year Year to scan * @param int $year Year to scan
* @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is month number, 2=Label of absiss is first letter of month * @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is month number, 2=Label of absiss is first letter of month
* @return array Array of values * @return array Array of values
*/ */
function getNbByMonth($year, $format=0) function getNbByMonth($year, $format=0)
@ -210,7 +214,7 @@ class ProjectStats extends Stats
* Return the Project amount by month for a year * Return the Project amount by month for a year
* *
* @param int $year Year to scan * @param int $year Year to scan
* @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is month number, 2=Label of absiss is first letter of month * @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is month number, 2=Label of absiss is first letter of month
* @return array Array with amount by month * @return array Array with amount by month
*/ */
function getAmountByMonth($year, $format=0) function getAmountByMonth($year, $format=0)
@ -248,45 +252,45 @@ class ProjectStats extends Stats
{ {
global $conf,$user,$langs; global $conf,$user,$langs;
if ($startyear > $endyear) return -1; if ($startyear > $endyear) return -1;
$datay=array(); $datay=array();
// Search into cache // Search into cache
if (! empty($cachedelay)) if (! empty($cachedelay))
{ {
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php';
} }
$newpathofdestfile=$conf->user->dir_temp.'/'.get_class($this).'_'.__FUNCTION__.'_'.(empty($this->cachefilesuffix)?'':$this->cachefilesuffix.'_').$langs->defaultlang.'_user'.$user->id.'.cache'; $newpathofdestfile=$conf->user->dir_temp.'/'.get_class($this).'_'.__FUNCTION__.'_'.(empty($this->cachefilesuffix)?'':$this->cachefilesuffix.'_').$langs->defaultlang.'_user'.$user->id.'.cache';
$newmask='0644'; $newmask='0644';
$nowgmt = dol_now(); $nowgmt = dol_now();
$foundintocache=0; $foundintocache=0;
if ($cachedelay > 0) if ($cachedelay > 0)
{ {
$filedate=dol_filemtime($newpathofdestfile); $filedate=dol_filemtime($newpathofdestfile);
if ($filedate >= ($nowgmt - $cachedelay)) if ($filedate >= ($nowgmt - $cachedelay))
{ {
$foundintocache=1; $foundintocache=1;
$this->_lastfetchdate[get_class($this).'_'.__FUNCTION__]=$filedate; $this->_lastfetchdate[get_class($this).'_'.__FUNCTION__]=$filedate;
} }
else else
{ {
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."); 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.");
} }
} }
// Load file into $data // Load file into $data
if ($foundintocache) // Cache file found and is not too old if ($foundintocache) // Cache file found and is not too old
{ {
dol_syslog(get_class($this).'::'.__FUNCTION__." read data from cache file ".$newpathofdestfile." ".$filedate."."); dol_syslog(get_class($this).'::'.__FUNCTION__." read data from cache file ".$newpathofdestfile." ".$filedate.".");
$data = json_decode(file_get_contents($newpathofdestfile), true); $data = json_decode(file_get_contents($newpathofdestfile), true);
} }
else else
{ {
$year=$startyear; $year=$startyear;
while($year <= $endyear) while($year <= $endyear)
@ -444,7 +448,7 @@ class ProjectStats extends Stats
* Return the Project transformation rate by month for a year * Return the Project transformation rate by month for a year
* *
* @param int $year Year to scan * @param int $year Year to scan
* @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is month number, 2=Label of absiss is first letter of month * @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is month number, 2=Label of absiss is first letter of month
* @return array Array with amount by month * @return array Array with amount by month
*/ */
function getTransformRateByMonth($year, $format=0) function getTransformRateByMonth($year, $format=0)