forked from Wavyzz/dolibarr
code syntax commande directory
This commit is contained in:
@@ -165,28 +165,37 @@ class Orders extends DolibarrApi
|
||||
|
||||
// If the internal user must only see his customers, force searching by him
|
||||
$search_sale = 0;
|
||||
if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id;
|
||||
if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) {
|
||||
$search_sale = DolibarrApiAccess::$user->id;
|
||||
}
|
||||
|
||||
$sql = "SELECT t.rowid";
|
||||
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $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)
|
||||
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $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 as t";
|
||||
|
||||
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $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 && !$socids) || $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('commande').')';
|
||||
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $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
|
||||
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $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
|
||||
}
|
||||
// Insert sale filter
|
||||
if ($search_sale > 0)
|
||||
{
|
||||
if ($search_sale > 0) {
|
||||
$sql .= " AND sc.fk_user = ".$search_sale;
|
||||
}
|
||||
// Add sql filters
|
||||
if ($sqlfilters)
|
||||
{
|
||||
if (!DolibarrApi::_checkFilters($sqlfilters))
|
||||
{
|
||||
if ($sqlfilters) {
|
||||
if (!DolibarrApi::_checkFilters($sqlfilters)) {
|
||||
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
|
||||
}
|
||||
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
|
||||
@@ -195,8 +204,7 @@ class Orders extends DolibarrApi
|
||||
|
||||
$sql .= $this->db->order($sortfield, $sortorder);
|
||||
if ($limit) {
|
||||
if ($page < 0)
|
||||
{
|
||||
if ($page < 0) {
|
||||
$page = 0;
|
||||
}
|
||||
$offset = $limit * $page;
|
||||
@@ -207,13 +215,11 @@ class Orders extends DolibarrApi
|
||||
dol_syslog("API Rest request");
|
||||
$result = $this->db->query($sql);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
if ($result) {
|
||||
$num = $this->db->num_rows($result);
|
||||
$min = min($num, ($limit <= 0 ? $num : $limit));
|
||||
$i = 0;
|
||||
while ($i < $min)
|
||||
{
|
||||
while ($i < $min) {
|
||||
$obj = $this->db->fetch_object($result);
|
||||
$commande_static = new Commande($this->db);
|
||||
if ($commande_static->fetch($obj->rowid)) {
|
||||
@@ -252,12 +258,12 @@ class Orders extends DolibarrApi
|
||||
$this->commande->$field = $value;
|
||||
}
|
||||
/*if (isset($request_data["lines"])) {
|
||||
$lines = array();
|
||||
foreach ($request_data["lines"] as $line) {
|
||||
array_push($lines, (object) $line);
|
||||
}
|
||||
$this->commande->lines = $lines;
|
||||
}*/
|
||||
$lines = array();
|
||||
foreach ($request_data["lines"] as $line) {
|
||||
array_push($lines, (object) $line);
|
||||
}
|
||||
$this->commande->lines = $lines;
|
||||
}*/
|
||||
|
||||
if ($this->commande->create(DolibarrApiAccess::$user) < 0) {
|
||||
throw new RestException(500, "Error creating order", array_merge(array($this->commande->error), $this->commande->errors));
|
||||
@@ -323,33 +329,33 @@ class Orders extends DolibarrApi
|
||||
}
|
||||
$request_data = (object) $request_data;
|
||||
$updateRes = $this->commande->addline(
|
||||
$request_data->desc,
|
||||
$request_data->subprice,
|
||||
$request_data->qty,
|
||||
$request_data->tva_tx,
|
||||
$request_data->localtax1_tx,
|
||||
$request_data->localtax2_tx,
|
||||
$request_data->fk_product,
|
||||
$request_data->remise_percent,
|
||||
$request_data->info_bits,
|
||||
$request_data->fk_remise_except,
|
||||
'HT',
|
||||
0,
|
||||
$request_data->date_start,
|
||||
$request_data->date_end,
|
||||
$request_data->product_type,
|
||||
$request_data->rang,
|
||||
$request_data->special_code,
|
||||
$request_data->fk_parent_line,
|
||||
$request_data->fk_fournprice,
|
||||
$request_data->pa_ht,
|
||||
$request_data->label,
|
||||
$request_data->array_options,
|
||||
$request_data->fk_unit,
|
||||
$request_data->origin,
|
||||
$request_data->origin_id,
|
||||
$request_data->multicurrency_subprice,
|
||||
$request_data->ref_ext
|
||||
$request_data->desc,
|
||||
$request_data->subprice,
|
||||
$request_data->qty,
|
||||
$request_data->tva_tx,
|
||||
$request_data->localtax1_tx,
|
||||
$request_data->localtax2_tx,
|
||||
$request_data->fk_product,
|
||||
$request_data->remise_percent,
|
||||
$request_data->info_bits,
|
||||
$request_data->fk_remise_except,
|
||||
'HT',
|
||||
0,
|
||||
$request_data->date_start,
|
||||
$request_data->date_end,
|
||||
$request_data->product_type,
|
||||
$request_data->rang,
|
||||
$request_data->special_code,
|
||||
$request_data->fk_parent_line,
|
||||
$request_data->fk_fournprice,
|
||||
$request_data->pa_ht,
|
||||
$request_data->label,
|
||||
$request_data->array_options,
|
||||
$request_data->fk_unit,
|
||||
$request_data->origin,
|
||||
$request_data->origin_id,
|
||||
$request_data->multicurrency_subprice,
|
||||
$request_data->ref_ext
|
||||
);
|
||||
|
||||
if ($updateRes > 0) {
|
||||
@@ -407,9 +413,9 @@ class Orders extends DolibarrApi
|
||||
$request_data->special_code,
|
||||
$request_data->array_options,
|
||||
$request_data->fk_unit,
|
||||
$request_data->multicurrency_subprice,
|
||||
$request_data->multicurrency_subprice,
|
||||
0,
|
||||
$request_data->ref_ext
|
||||
$request_data->ref_ext
|
||||
);
|
||||
|
||||
if ($updateRes > 0) {
|
||||
@@ -613,18 +619,20 @@ class Orders extends DolibarrApi
|
||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
foreach ($request_data as $field => $value) {
|
||||
if ($field == 'id') continue;
|
||||
if ($field == 'id') {
|
||||
continue;
|
||||
}
|
||||
$this->commande->$field = $value;
|
||||
}
|
||||
|
||||
// Update availability
|
||||
if (!empty($this->commande->availability_id)) {
|
||||
if ($this->commande->availability($this->commande->availability_id) < 0)
|
||||
throw new RestException(400, 'Error while updating availability');
|
||||
if ($this->commande->availability($this->commande->availability_id) < 0) {
|
||||
throw new RestException(400, 'Error while updating availability');
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->commande->update(DolibarrApiAccess::$user) > 0)
|
||||
{
|
||||
if ($this->commande->update(DolibarrApiAccess::$user) > 0) {
|
||||
return $this->get($id);
|
||||
} else {
|
||||
throw new RestException(500, $this->commande->error);
|
||||
@@ -979,8 +987,9 @@ class Orders extends DolibarrApi
|
||||
{
|
||||
$commande = array();
|
||||
foreach (Orders::$FIELDS as $field) {
|
||||
if (!isset($data[$field]))
|
||||
if (!isset($data[$field])) {
|
||||
throw new RestException(400, $field." field missing");
|
||||
}
|
||||
$commande[$field] = $data[$field];
|
||||
}
|
||||
return $commande;
|
||||
|
||||
Reference in New Issue
Block a user