Scrutinizer Auto-Fixes

This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com
This commit is contained in:
Scrutinizer Auto-Fixer 2019-11-02 00:17:45 +00:00
parent a14aab5eb1
commit 50f55cac35
3 changed files with 374 additions and 374 deletions

View File

@ -28,180 +28,180 @@ require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
*/
class SupplierOrders extends DolibarrApi
{
/**
*
* @var array $FIELDS Mandatory fields, checked when create and update object
*/
static $FIELDS = array(
'socid'
);
/**
*
* @var array $FIELDS Mandatory fields, checked when create and update object
*/
static $FIELDS = array(
'socid'
);
/**
* @var CommandeFournisseur $order {@type CommandeFournisseur}
*/
public $order;
/**
* @var CommandeFournisseur $order {@type CommandeFournisseur}
*/
public $order;
/**
* Constructor
*/
public function __construct()
{
global $db, $conf;
$this->db = $db;
$this->order = new CommandeFournisseur($this->db);
}
/**
* Constructor
*/
public function __construct()
{
global $db, $conf;
$this->db = $db;
$this->order = new CommandeFournisseur($this->db);
}
/**
* Get properties of a supplier order object
*
* Return an array with supplier order information
*
* @param int $id ID of supplier order
* @return array|mixed data without useless information
*
* @throws RestException
*/
public function get($id)
{
if(! DolibarrApiAccess::$user->rights->fournisseur->commande->lire) {
throw new RestException(401);
}
/**
* Get properties of a supplier order object
*
* Return an array with supplier order information
*
* @param int $id ID of supplier order
* @return array|mixed data without useless information
*
* @throws RestException
*/
public function get($id)
{
if(! DolibarrApiAccess::$user->rights->fournisseur->commande->lire) {
throw new RestException(401);
}
$result = $this->order->fetch($id);
if ( ! $result ) {
throw new RestException(404, 'Supplier order not found');
}
$result = $this->order->fetch($id);
if ( ! $result ) {
throw new RestException(404, 'Supplier order not found');
}
if ( ! DolibarrApi::_checkAccessToResource('fournisseur', $this->order->id, '', 'commande')) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
if ( ! DolibarrApi::_checkAccessToResource('fournisseur', $this->order->id, '', 'commande')) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$this->order->fetchObjectLinked();
return $this->_cleanObjectDatas($this->order);
}
$this->order->fetchObjectLinked();
return $this->_cleanObjectDatas($this->order);
}
/**
* List orders
*
* Get a list of supplier orders
*
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Limit for list
* @param int $page Page number
* @param string $thirdparty_ids Thirdparty ids to filter orders of (example '1' or '1,2,3') {@pattern /^[0-9,]*$/i}
* @param string $status Filter by order status : draft | validated | approved | running | received_start | received_end | cancelled | refused
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.datec:<:'20160101')"
* @return array Array of order objects
*
* @throws RestException
*/
public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $status = '', $sqlfilters = '')
{
global $db, $conf;
/**
* List orders
*
* Get a list of supplier orders
*
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Limit for list
* @param int $page Page number
* @param string $thirdparty_ids Thirdparty ids to filter orders of (example '1' or '1,2,3') {@pattern /^[0-9,]*$/i}
* @param string $status Filter by order status : draft | validated | approved | running | received_start | received_end | cancelled | refused
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.datec:<:'20160101')"
* @return array Array of order objects
*
* @throws RestException
*/
public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $status = '', $sqlfilters = '')
{
global $db, $conf;
$obj_ret = array();
$obj_ret = array();
// case of external user, $thirdparty_ids param is ignored and replaced by user's socid
$socids = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $thirdparty_ids;
// case of external user, $thirdparty_ids param is ignored and replaced by user's socid
$socids = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $thirdparty_ids;
// If the internal user must only see his customers, force searching by him
$search_sale = 0;
if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
// If the internal user must only see his customers, force searching by him
$search_sale = 0;
if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
$sql = "SELECT t.rowid";
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as t";
$sql = "SELECT t.rowid";
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as t";
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
$sql.= ' WHERE t.entity IN ('.getEntity('supplier_order').')';
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND t.fk_soc = sc.fk_soc";
if ($socids) $sql.= " AND t.fk_soc IN (".$socids.")";
if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
$sql.= ' WHERE t.entity IN ('.getEntity('supplier_order').')';
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND t.fk_soc = sc.fk_soc";
if ($socids) $sql.= " AND t.fk_soc IN (".$socids.")";
if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
// Filter by status
if ($status == 'draft') $sql.= " AND t.fk_statut IN (0)";
if ($status == 'validated') $sql.= " AND t.fk_statut IN (1)";
if ($status == 'approved') $sql.= " AND t.fk_statut IN (2)";
if ($status == 'running') $sql.= " AND t.fk_statut IN (3)";
if ($status == 'received_start') $sql.= " AND t.fk_statut IN (4)";
if ($status == 'received_end') $sql.= " AND t.fk_statut IN (5)";
if ($status == 'cancelled') $sql.= " AND t.fk_statut IN (6,7)";
if ($status == 'refused') $sql.= " AND t.fk_statut IN (9)";
// Insert sale filter
if ($search_sale > 0)
{
$sql .= " AND sc.fk_user = ".$search_sale;
}
// Add sql filters
if ($sqlfilters)
{
if (! DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
}
$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
}
// Filter by status
if ($status == 'draft') $sql.= " AND t.fk_statut IN (0)";
if ($status == 'validated') $sql.= " AND t.fk_statut IN (1)";
if ($status == 'approved') $sql.= " AND t.fk_statut IN (2)";
if ($status == 'running') $sql.= " AND t.fk_statut IN (3)";
if ($status == 'received_start') $sql.= " AND t.fk_statut IN (4)";
if ($status == 'received_end') $sql.= " AND t.fk_statut IN (5)";
if ($status == 'cancelled') $sql.= " AND t.fk_statut IN (6,7)";
if ($status == 'refused') $sql.= " AND t.fk_statut IN (9)";
// Insert sale filter
if ($search_sale > 0)
{
$sql .= " AND sc.fk_user = ".$search_sale;
}
// Add sql filters
if ($sqlfilters)
{
if (! DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
}
$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
}
$sql.= $db->order($sortfield, $sortorder);
if ($limit) {
if ($page < 0)
{
$page = 0;
}
$offset = $limit * $page;
$sql.= $db->order($sortfield, $sortorder);
if ($limit) {
if ($page < 0)
{
$page = 0;
}
$offset = $limit * $page;
$sql.= $db->plimit($limit + 1, $offset);
}
$sql.= $db->plimit($limit + 1, $offset);
}
$result = $db->query($sql);
if ($result)
{
$i = 0;
$num = $db->num_rows($result);
$min = min($num, ($limit <= 0 ? $num : $limit));
while ($i < $min)
{
$obj = $db->fetch_object($result);
$order_static = new CommandeFournisseur($db);
if($order_static->fetch($obj->rowid)) {
$obj_ret[] = $this->_cleanObjectDatas($order_static);
}
$i++;
}
}
else {
throw new RestException(503, 'Error when retrieve supplier order list : '.$db->lasterror());
}
if( ! count($obj_ret)) {
throw new RestException(404, 'No supplier order found');
}
return $obj_ret;
}
$result = $db->query($sql);
if ($result)
{
$i = 0;
$num = $db->num_rows($result);
$min = min($num, ($limit <= 0 ? $num : $limit));
while ($i < $min)
{
$obj = $db->fetch_object($result);
$order_static = new CommandeFournisseur($db);
if($order_static->fetch($obj->rowid)) {
$obj_ret[] = $this->_cleanObjectDatas($order_static);
}
$i++;
}
}
else {
throw new RestException(503, 'Error when retrieve supplier order list : '.$db->lasterror());
}
if( ! count($obj_ret)) {
throw new RestException(404, 'No supplier order found');
}
return $obj_ret;
}
/**
* Create supplier order object
*
* @param array $request_data Request datas
* @return int ID of supplier order
*/
public function post($request_data = null)
{
if(! DolibarrApiAccess::$user->rights->fournisseur->commande->creer) {
throw new RestException(401, "Insuffisant rights");
}
// Check mandatory fields
$result = $this->_validate($request_data);
/**
* Create supplier order object
*
* @param array $request_data Request datas
* @return int ID of supplier order
*/
public function post($request_data = null)
{
if(! DolibarrApiAccess::$user->rights->fournisseur->commande->creer) {
throw new RestException(401, "Insuffisant rights");
}
// Check mandatory fields
$result = $this->_validate($request_data);
foreach($request_data as $field => $value) {
$this->order->$field = $value;
}
if(! array_keys($request_data, 'date')) {
$this->order->date = dol_now();
}
/* We keep lines as an array
foreach($request_data as $field => $value) {
$this->order->$field = $value;
}
if(! array_keys($request_data, 'date')) {
$this->order->date = dol_now();
}
/* We keep lines as an array
if (isset($request_data["lines"])) {
$lines = array();
foreach ($request_data["lines"] as $line) {
@ -210,163 +210,163 @@ class SupplierOrders extends DolibarrApi
$this->order->lines = $lines;
}*/
if ($this->order->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, "Error creating order", array_merge(array($this->order->error), $this->order->errors));
}
return $this->order->id;
}
if ($this->order->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, "Error creating order", array_merge(array($this->order->error), $this->order->errors));
}
return $this->order->id;
}
/**
* Update supplier order
*
* @param int $id Id of supplier order to update
* @param array $request_data Datas
* @return int
*/
public function put($id, $request_data = null)
{
if(! DolibarrApiAccess::$user->rights->fournisseur->commande->creer) {
throw new RestException(401);
}
/**
* Update supplier order
*
* @param int $id Id of supplier order to update
* @param array $request_data Datas
* @return int
*/
public function put($id, $request_data = null)
{
if(! DolibarrApiAccess::$user->rights->fournisseur->commande->creer) {
throw new RestException(401);
}
$result = $this->order->fetch($id);
if( ! $result ) {
throw new RestException(404, 'Supplier order not found');
}
$result = $this->order->fetch($id);
if( ! $result ) {
throw new RestException(404, 'Supplier order not found');
}
if( ! DolibarrApi::_checkAccessToResource('fournisseur', $this->order->id, '', 'commande')) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
if( ! DolibarrApi::_checkAccessToResource('fournisseur', $this->order->id, '', 'commande')) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
foreach($request_data as $field => $value) {
if ($field == 'id') continue;
$this->order->$field = $value;
}
foreach($request_data as $field => $value) {
if ($field == 'id') continue;
$this->order->$field = $value;
}
if($this->order->update($id, DolibarrApiAccess::$user))
return $this->get($id);
if($this->order->update($id, DolibarrApiAccess::$user))
return $this->get($id);
return false;
}
return false;
}
/**
* Delete supplier order
*
* @param int $id Supplier order ID
* @return type
*/
public function delete($id)
{
if (! DolibarrApiAccess::$user->rights->fournisseur->commande->supprimer) {
throw new RestException(401);
}
$result = $this->order->fetch($id);
if ( ! $result) {
throw new RestException(404, 'Supplier order not found');
}
/**
* Delete supplier order
*
* @param int $id Supplier order ID
* @return type
*/
public function delete($id)
{
if (! DolibarrApiAccess::$user->rights->fournisseur->commande->supprimer) {
throw new RestException(401);
}
$result = $this->order->fetch($id);
if ( ! $result) {
throw new RestException(404, 'Supplier order not found');
}
if ( ! DolibarrApi::_checkAccessToResource('fournisseur', $this->order->id, '', 'commande')) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
if ( ! DolibarrApi::_checkAccessToResource('fournisseur', $this->order->id, '', 'commande')) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
if ( $this->order->delete(DolibarrApiAccess::$user) < 0) {
throw new RestException(500);
}
if ( $this->order->delete(DolibarrApiAccess::$user) < 0) {
throw new RestException(500);
}
return array(
'success' => array(
'code' => 200,
'message' => 'Supplier order deleted'
)
);
}
return array(
'success' => array(
'code' => 200,
'message' => 'Supplier order deleted'
)
);
}
/**
* Validate an order
*
* @param int $id Order ID
* @param int $idwarehouse Warehouse ID
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
*
* @url POST {id}/validate
*
* @return array
* FIXME An error 403 is returned if the request has an empty body.
* Error message: "Forbidden: Content type `text/plain` is not supported."
* Workaround: send this in the body
* {
* "idwarehouse": 0,
* "notrigger": 0
* }
*/
public function validate($id, $idwarehouse = 0, $notrigger = 0)
{
if(! DolibarrApiAccess::$user->rights->fournisseur->commande->creer) {
throw new RestException(401);
}
$result = $this->order->fetch($id);
if( ! $result ) {
throw new RestException(404, 'Order not found');
}
/**
* Validate an order
*
* @param int $id Order ID
* @param int $idwarehouse Warehouse ID
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
*
* @url POST {id}/validate
*
* @return array
* FIXME An error 403 is returned if the request has an empty body.
* Error message: "Forbidden: Content type `text/plain` is not supported."
* Workaround: send this in the body
* {
* "idwarehouse": 0,
* "notrigger": 0
* }
*/
public function validate($id, $idwarehouse = 0, $notrigger = 0)
{
if(! DolibarrApiAccess::$user->rights->fournisseur->commande->creer) {
throw new RestException(401);
}
$result = $this->order->fetch($id);
if( ! $result ) {
throw new RestException(404, 'Order not found');
}
if( ! DolibarrApi::_checkAccessToResource('fournisseur', $this->order->id, '', 'commande')) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
if( ! DolibarrApi::_checkAccessToResource('fournisseur', $this->order->id, '', 'commande')) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$result = $this->order->valid(DolibarrApiAccess::$user, $idwarehouse, $notrigger);
if ($result == 0) {
throw new RestException(304, 'Error nothing done. May be object is already validated');
}
if ($result < 0) {
throw new RestException(500, 'Error when validating Order: '.$this->order->error);
}
$result = $this->order->valid(DolibarrApiAccess::$user, $idwarehouse, $notrigger);
if ($result == 0) {
throw new RestException(304, 'Error nothing done. May be object is already validated');
}
if ($result < 0) {
throw new RestException(500, 'Error when validating Order: '.$this->order->error);
}
return array(
'success' => array(
'code' => 200,
'message' => 'Order validated (Ref='.$this->order->ref.')'
)
);
}
return array(
'success' => array(
'code' => 200,
'message' => 'Order validated (Ref='.$this->order->ref.')'
)
);
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
/**
* Clean sensible object datas
*
* @param Object $object Object to clean
* @return array Array of cleaned object properties
*/
protected function _cleanObjectDatas($object)
{
// phpcs:enable
$object = parent::_cleanObjectDatas($object);
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
/**
* Clean sensible object datas
*
* @param Object $object Object to clean
* @return array Array of cleaned object properties
*/
protected function _cleanObjectDatas($object)
{
// phpcs:enable
$object = parent::_cleanObjectDatas($object);
unset($object->rowid);
unset($object->barcode_type);
unset($object->barcode_type_code);
unset($object->barcode_type_label);
unset($object->barcode_type_coder);
unset($object->rowid);
unset($object->barcode_type);
unset($object->barcode_type_code);
unset($object->barcode_type_label);
unset($object->barcode_type_coder);
return $object;
}
return $object;
}
/**
* Validate fields before create or update object
*
* @param array $data Datas to validate
* @return array
*
* @throws RestException
*/
private function _validate($data)
{
$order = array();
foreach (SupplierOrders::$FIELDS as $field) {
if (!isset($data[$field]))
throw new RestException(400, "$field field missing");
$order[$field] = $data[$field];
}
return $order;
}
/**
* Validate fields before create or update object
*
* @param array $data Datas to validate
* @return array
*
* @throws RestException
*/
private function _validate($data)
{
$order = array();
foreach (SupplierOrders::$FIELDS as $field) {
if (!isset($data[$field]))
throw new RestException(400, "$field field missing");
$order[$field] = $data[$field];
}
return $order;
}
}

View File

@ -38,10 +38,10 @@ $hookmanager->initHooks(array('thirdpartiesindex'));
$langs->load("companies");
$socid = GETPOST('socid', 'int');
if ($user->societe_id) $socid=$user->societe_id;
if ($user->societe_id) $socid = $user->societe_id;
// Security check
$result=restrictedArea($user, 'societe', 0, '', '', '', '');
$result = restrictedArea($user, 'societe', 0, '', '', '', '');
$thirdparty_static = new Societe($db);
@ -51,10 +51,10 @@ $thirdparty_static = new Societe($db);
*/
$transAreaType = $langs->trans("ThirdPartiesArea");
$helpurl='EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Terceros';
$helpurl = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Terceros';
llxHeader("", $langs->trans("ThirdParties"), $helpurl);
$linkback='';
$linkback = '';
print load_fiche_titre($transAreaType, $linkback, 'companies');
@ -73,26 +73,26 @@ $third = array(
'supplier' => 0,
'other' =>0
);
$total=0;
$total = 0;
$sql = "SELECT s.rowid, s.client, s.fournisseur";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= ' WHERE s.entity IN ('.getEntity('societe').')';
if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid) $sql.= " AND s.rowid = ".$socid;
if (! $user->rights->fournisseur->lire) $sql.=" AND (s.fournisseur <> 1 OR s.client <> 0)"; // client=0, fournisseur=0 must be visible
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql .= ' WHERE s.entity IN ('.getEntity('societe').')';
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if ($socid) $sql .= " AND s.rowid = ".$socid;
if (!$user->rights->fournisseur->lire) $sql .= " AND (s.fournisseur <> 1 OR s.client <> 0)"; // client=0, fournisseur=0 must be visible
//print $sql;
$result = $db->query($sql);
if ($result)
{
while ($objp = $db->fetch_object($result))
{
$found=0;
if (! empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS) && ($objp->client == 2 || $objp->client == 3)) { $found=1; $third['prospect']++; }
if (! empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS) && ($objp->client == 1 || $objp->client == 3)) { $found=1; $third['customer']++; }
if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS) && $objp->fournisseur) { $found=1; $third['supplier']++; }
if (! empty($conf->societe->enabled) && $objp->client == 0 && $objp->fournisseur == 0) { $found=1; $third['other']++; }
$found = 0;
if (!empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS) && ($objp->client == 2 || $objp->client == 3)) { $found = 1; $third['prospect']++; }
if (!empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS) && ($objp->client == 1 || $objp->client == 3)) { $found = 1; $third['customer']++; }
if (!empty($conf->fournisseur->enabled) && $user->rights->fournisseur->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS) && $objp->fournisseur) { $found = 1; $third['supplier']++; }
if (!empty($conf->societe->enabled) && $objp->client == 0 && $objp->fournisseur == 0) { $found = 1; $third['other']++; }
if ($found) $total++;
}
}
@ -101,14 +101,14 @@ else dol_print_error($db);
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder nohover" width="100%">'."\n";
print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
if (! empty($conf->use_javascript_ajax) && ((round($third['prospect'])?1:0)+(round($third['customer'])?1:0)+(round($third['supplier'])?1:0)+(round($third['other'])?1:0) >= 2))
if (!empty($conf->use_javascript_ajax) && ((round($third['prospect']) ? 1 : 0) + (round($third['customer']) ? 1 : 0) + (round($third['supplier']) ? 1 : 0) + (round($third['other']) ? 1 : 0) >= 2))
{
print '<tr><td class="center" colspan="2">';
$dataseries=array();
if (! empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS)) $dataseries[]=array($langs->trans("Prospects"), round($third['prospect']));
if (! empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS)) $dataseries[]=array($langs->trans("Customers"), round($third['customer']));
if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS)) $dataseries[]=array($langs->trans("Suppliers"), round($third['supplier']));
if (! empty($conf->societe->enabled)) $dataseries[]=array($langs->trans("Others"), round($third['other']));
$dataseries = array();
if (!empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS)) $dataseries[] = array($langs->trans("Prospects"), round($third['prospect']));
if (!empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS)) $dataseries[] = array($langs->trans("Customers"), round($third['customer']));
if (!empty($conf->fournisseur->enabled) && $user->rights->fournisseur->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS)) $dataseries[] = array($langs->trans("Suppliers"), round($third['supplier']));
if (!empty($conf->societe->enabled)) $dataseries[] = array($langs->trans("Others"), round($third['other']));
include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
$dolgraph = new DolGraph();
$dolgraph->SetData($dataseries);
@ -122,23 +122,23 @@ if (! empty($conf->use_javascript_ajax) && ((round($third['prospect'])?1:0)+(rou
}
else
{
if (! empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS))
if (!empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS))
{
$statstring = "<tr>";
$statstring.= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=p">'.$langs->trans("Prospects").'</a></td><td class="right">'.round($third['prospect']).'</td>';
$statstring.= "</tr>";
$statstring .= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=p">'.$langs->trans("Prospects").'</a></td><td class="right">'.round($third['prospect']).'</td>';
$statstring .= "</tr>";
}
if (! empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS))
if (!empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS))
{
$statstring.= "<tr>";
$statstring.= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=c">'.$langs->trans("Customers").'</a></td><td class="right">'.round($third['customer']).'</td>';
$statstring.= "</tr>";
$statstring .= "<tr>";
$statstring .= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=c">'.$langs->trans("Customers").'</a></td><td class="right">'.round($third['customer']).'</td>';
$statstring .= "</tr>";
}
if (! empty($conf->fournisseur->enabled) && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS) && $user->rights->fournisseur->lire)
if (!empty($conf->fournisseur->enabled) && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS) && $user->rights->fournisseur->lire)
{
$statstring2 = "<tr>";
$statstring2.= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=f">'.$langs->trans("Suppliers").'</a></td><td class="right">'.round($third['supplier']).'</td>';
$statstring2.= "</tr>";
$statstring2 .= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=f">'.$langs->trans("Suppliers").'</a></td><td class="right">'.round($third['supplier']).'</td>';
$statstring2 .= "</tr>";
}
print $statstring;
print $statstring2;
@ -149,7 +149,7 @@ print '</td></tr>';
print '</table>';
print '</div>';
if (! empty($conf->categorie->enabled) && ! empty($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES))
if (!empty($conf->categorie->enabled) && !empty($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES))
{
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
$elementtype = 'societe';
@ -161,41 +161,41 @@ if (! empty($conf->categorie->enabled) && ! empty($conf->global->CATEGORY_GRAPHS
print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Categories").'</th></tr>';
print '<tr><td class="center" colspan="2">';
$sql = "SELECT c.label, count(*) as nb";
$sql.= " FROM ".MAIN_DB_PREFIX."categorie_societe as cs";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON cs.fk_categorie = c.rowid";
$sql.= " WHERE c.type = 2";
if (! is_numeric($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES)) $sql.= " AND c.label like '".$db->escape($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES)."'";
$sql.= " AND c.entity IN (".getEntity('category').")";
$sql.= " GROUP BY c.label";
$total=0;
$sql .= " FROM ".MAIN_DB_PREFIX."categorie_societe as cs";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON cs.fk_categorie = c.rowid";
$sql .= " WHERE c.type = 2";
if (!is_numeric($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES)) $sql .= " AND c.label like '".$db->escape($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES)."'";
$sql .= " AND c.entity IN (".getEntity('category').")";
$sql .= " GROUP BY c.label";
$total = 0;
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows($result);
$i=0;
if (! empty($conf->use_javascript_ajax) )
$i = 0;
if (!empty($conf->use_javascript_ajax))
{
$dataseries=array();
$rest=0;
$nbmax=10;
$dataseries = array();
$rest = 0;
$nbmax = 10;
while ($i < $num)
{
$obj = $db->fetch_object($result);
if ($i < $nbmax)
{
$dataseries[]=array($obj->label, round($obj->nb));
$dataseries[] = array($obj->label, round($obj->nb));
}
else
{
$rest+=$obj->nb;
$rest += $obj->nb;
}
$total+=$obj->nb;
$total += $obj->nb;
$i++;
}
if ($i > $nbmax)
{
$dataseries[]=array($langs->trans("Other"), round($rest));
$dataseries[] = array($langs->trans("Other"), round($rest));
}
include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
$dolgraph = new DolGraph();
@ -214,7 +214,7 @@ if (! empty($conf->categorie->enabled) && ! empty($conf->global->CATEGORY_GRAPHS
$obj = $db->fetch_object($result);
print '<tr class="oddeven"><td>'.$obj->label.'</td><td>'.$obj->nb.'</td></tr>';
$total+=$obj->nb;
$total += $obj->nb;
$i++;
}
}
@ -234,20 +234,20 @@ print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
/*
* Latest modified third parties
*/
$max=15;
$max = 15;
$sql = "SELECT s.rowid, s.nom as name, s.email, s.client, s.fournisseur";
$sql.= ", s.code_client";
$sql.= ", s.code_fournisseur";
$sql.= ", s.logo";
$sql.= ", s.canvas, s.tms as datem, s.status as status";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= ' WHERE s.entity IN ('.getEntity('societe').')';
if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid) $sql.= " AND s.rowid = ".$socid;
if (! $user->rights->fournisseur->lire) $sql.=" AND (s.fournisseur != 1 OR s.client != 0)";
$sql.= $db->order("s.tms", "DESC");
$sql.= $db->plimit($max, 0);
$sql .= ", s.code_client";
$sql .= ", s.code_fournisseur";
$sql .= ", s.logo";
$sql .= ", s.canvas, s.tms as datem, s.status as status";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql .= ' WHERE s.entity IN ('.getEntity('societe').')';
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if ($socid) $sql .= " AND s.rowid = ".$socid;
if (!$user->rights->fournisseur->lire) $sql .= " AND (s.fournisseur != 1 OR s.client != 0)";
$sql .= $db->order("s.tms", "DESC");
$sql .= $db->plimit($max, 0);
//print $sql;
$result = $db->query($sql);
@ -274,16 +274,16 @@ if ($result)
{
$objp = $db->fetch_object($result);
$thirdparty_static->id=$objp->rowid;
$thirdparty_static->name=$objp->name;
$thirdparty_static->client=$objp->client;
$thirdparty_static->fournisseur=$objp->fournisseur;
$thirdparty_static->id = $objp->rowid;
$thirdparty_static->name = $objp->name;
$thirdparty_static->client = $objp->client;
$thirdparty_static->fournisseur = $objp->fournisseur;
$thirdparty_static->logo = $objp->logo;
$thirdparty_static->datem=$db->jdate($objp->datem);
$thirdparty_static->status=$objp->status;
$thirdparty_static->datem = $db->jdate($objp->datem);
$thirdparty_static->status = $objp->status;
$thirdparty_static->code_client = $objp->code_client;
$thirdparty_static->code_fournisseur = $objp->code_fournisseur;
$thirdparty_static->canvas=$objp->canvas;
$thirdparty_static->canvas = $objp->canvas;
$thirdparty_static->email = $objp->email;
print '<tr class="oddeven">';
@ -293,21 +293,21 @@ if ($result)
print "</td>\n";
// Type
print '<td class="center">';
if ($thirdparty_static->client==1 || $thirdparty_static->client==3)
if ($thirdparty_static->client == 1 || $thirdparty_static->client == 3)
{
$thirdparty_static->name=$langs->trans("Customer");
$thirdparty_static->name = $langs->trans("Customer");
print $thirdparty_static->getNomUrl(0, 'customer', 0, 1);
}
if ($thirdparty_static->client == 3 && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print " / ";
if (($thirdparty_static->client==2 || $thirdparty_static->client==3) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS))
if (($thirdparty_static->client == 2 || $thirdparty_static->client == 3) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS))
{
$thirdparty_static->name=$langs->trans("Prospect");
$thirdparty_static->name = $langs->trans("Prospect");
print $thirdparty_static->getNomUrl(0, 'prospect', 0, 1);
}
if (! empty($conf->fournisseur->enabled) && $thirdparty_static->fournisseur)
if (!empty($conf->fournisseur->enabled) && $thirdparty_static->fournisseur)
{
if ($thirdparty_static->client) print " / ";
$thirdparty_static->name=$langs->trans("Supplier");
$thirdparty_static->name = $langs->trans("Supplier");
print $thirdparty_static->getNomUrl(0, 'supplier', 0, 1);
}
print '</td>';

View File

@ -46,13 +46,13 @@ $stripearrayofkeysbyenv = array(
$stripearrayofkeys = array();
if (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'alpha'))
{
$stripearrayofkeys = $stripearrayofkeysbyenv[0]; // Test
$stripearrayofkeys = $stripearrayofkeysbyenv[0]; // Test
}
else
{
$stripearrayofkeys = $stripearrayofkeysbyenv[1]; // Live
$stripearrayofkeys = $stripearrayofkeysbyenv[1]; // Live
}
\Stripe\Stripe::setApiKey($stripearrayofkeys['secret_key']);
\Stripe\Stripe::setAppInfo("Dolibarr Stripe", DOL_VERSION, "https://www.dolibarr.org"); // add dolibarr version
\Stripe\Stripe::setApiVersion(empty($conf->global->STRIPE_FORCE_VERSION)?"2019-05-16":$conf->global->STRIPE_FORCE_VERSION); // force version API
\Stripe\Stripe::setApiVersion(empty($conf->global->STRIPE_FORCE_VERSION) ? "2019-05-16" : $conf->global->STRIPE_FORCE_VERSION); // force version API