mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-01-07 17:42:53 +01:00
code syntax project
This commit is contained in:
@@ -33,7 +33,7 @@ class Projects extends DolibarrApi
|
||||
/**
|
||||
* @var array $FIELDS Mandatory fields, checked when create and update object
|
||||
*/
|
||||
static $FIELDS = array(
|
||||
public static $FIELDS = array(
|
||||
'ref',
|
||||
'title'
|
||||
);
|
||||
@@ -110,23 +110,34 @@ class Projects 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."projet as t";
|
||||
if ($category > 0) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."categorie_project as c";
|
||||
}
|
||||
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('project').')';
|
||||
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;
|
||||
}
|
||||
// Select projects of given category
|
||||
@@ -134,10 +145,8 @@ class Projects extends DolibarrApi
|
||||
$sql .= " AND c.fk_categorie = ".$this->db->escape($category)." AND c.fk_project = t.rowid ";
|
||||
}
|
||||
// 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 = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
|
||||
@@ -157,8 +166,7 @@ class Projects 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;
|
||||
@@ -197,12 +205,12 @@ class Projects extends DolibarrApi
|
||||
$this->project->$field = $value;
|
||||
}
|
||||
/*if (isset($request_data["lines"])) {
|
||||
$lines = array();
|
||||
foreach ($request_data["lines"] as $line) {
|
||||
array_push($lines, (object) $line);
|
||||
}
|
||||
$this->project->lines = $lines;
|
||||
}*/
|
||||
$lines = array();
|
||||
foreach ($request_data["lines"] as $line) {
|
||||
array_push($lines, (object) $line);
|
||||
}
|
||||
$this->project->lines = $lines;
|
||||
}*/
|
||||
if ($this->project->create(DolibarrApiAccess::$user) < 0) {
|
||||
throw new RestException(500, "Error creating project", array_merge(array($this->project->error), $this->project->errors));
|
||||
}
|
||||
@@ -236,14 +244,11 @@ class Projects extends DolibarrApi
|
||||
}
|
||||
$this->project->getLinesArray(DolibarrApiAccess::$user);
|
||||
$result = array();
|
||||
foreach ($this->project->lines as $line) // $line is a task
|
||||
{
|
||||
if ($includetimespent == 1)
|
||||
{
|
||||
foreach ($this->project->lines as $line) { // $line is a task
|
||||
if ($includetimespent == 1) {
|
||||
$timespent = $line->getSummaryOfTimeSpent(0);
|
||||
}
|
||||
if ($includetimespent == 1)
|
||||
{
|
||||
if ($includetimespent == 1) {
|
||||
// TODO
|
||||
// Add class for timespent records and loop and fill $line->lines with records of timespent
|
||||
}
|
||||
@@ -283,8 +288,7 @@ class Projects extends DolibarrApi
|
||||
require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
|
||||
$taskstatic = new Task($this->db);
|
||||
$userp = DolibarrApiAccess::$user;
|
||||
if ($userid > 0)
|
||||
{
|
||||
if ($userid > 0) {
|
||||
$userp = new User($this->db);
|
||||
$userp->fetch($userid);
|
||||
}
|
||||
@@ -308,56 +312,56 @@ class Projects extends DolibarrApi
|
||||
* @return int
|
||||
*/
|
||||
/*
|
||||
public function postLine($id, $request_data = null)
|
||||
{
|
||||
if(! DolibarrApiAccess::$user->rights->projet->creer) {
|
||||
throw new RestException(401);
|
||||
}
|
||||
public function postLine($id, $request_data = null)
|
||||
{
|
||||
if(! DolibarrApiAccess::$user->rights->projet->creer) {
|
||||
throw new RestException(401);
|
||||
}
|
||||
|
||||
$result = $this->project->fetch($id);
|
||||
if( ! $result ) {
|
||||
throw new RestException(404, 'Project not found');
|
||||
}
|
||||
$result = $this->project->fetch($id);
|
||||
if( ! $result ) {
|
||||
throw new RestException(404, 'Project not found');
|
||||
}
|
||||
|
||||
if( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) {
|
||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
$request_data = (object) $request_data;
|
||||
$updateRes = $this->project->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,
|
||||
$fk_parent_line,
|
||||
$request_data->fk_fournprice,
|
||||
$request_data->pa_ht,
|
||||
$request_data->label,
|
||||
$request_data->array_options,
|
||||
$request_data->fk_unit,
|
||||
$this->element,
|
||||
$request_data->id
|
||||
);
|
||||
if( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) {
|
||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
$request_data = (object) $request_data;
|
||||
$updateRes = $this->project->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,
|
||||
$fk_parent_line,
|
||||
$request_data->fk_fournprice,
|
||||
$request_data->pa_ht,
|
||||
$request_data->label,
|
||||
$request_data->array_options,
|
||||
$request_data->fk_unit,
|
||||
$this->element,
|
||||
$request_data->id
|
||||
);
|
||||
|
||||
if ($updateRes > 0) {
|
||||
return $updateRes;
|
||||
if ($updateRes > 0) {
|
||||
return $updateRes;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
}
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Update a task to given project
|
||||
@@ -371,52 +375,52 @@ class Projects extends DolibarrApi
|
||||
* @return object
|
||||
*/
|
||||
/*
|
||||
public function putLine($id, $lineid, $request_data = null)
|
||||
{
|
||||
if(! DolibarrApiAccess::$user->rights->projet->creer) {
|
||||
throw new RestException(401);
|
||||
}
|
||||
public function putLine($id, $lineid, $request_data = null)
|
||||
{
|
||||
if(! DolibarrApiAccess::$user->rights->projet->creer) {
|
||||
throw new RestException(401);
|
||||
}
|
||||
|
||||
$result = $this->project->fetch($id);
|
||||
if( ! $result ) {
|
||||
throw new RestException(404, 'Project not found');
|
||||
}
|
||||
$result = $this->project->fetch($id);
|
||||
if( ! $result ) {
|
||||
throw new RestException(404, 'Project not found');
|
||||
}
|
||||
|
||||
if( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) {
|
||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
$request_data = (object) $request_data;
|
||||
$updateRes = $this->project->updateline(
|
||||
$lineid,
|
||||
$request_data->desc,
|
||||
$request_data->subprice,
|
||||
$request_data->qty,
|
||||
$request_data->remise_percent,
|
||||
$request_data->tva_tx,
|
||||
$request_data->localtax1_tx,
|
||||
$request_data->localtax2_tx,
|
||||
'HT',
|
||||
$request_data->info_bits,
|
||||
$request_data->date_start,
|
||||
$request_data->date_end,
|
||||
$request_data->product_type,
|
||||
$request_data->fk_parent_line,
|
||||
0,
|
||||
$request_data->fk_fournprice,
|
||||
$request_data->pa_ht,
|
||||
$request_data->label,
|
||||
$request_data->special_code,
|
||||
$request_data->array_options,
|
||||
$request_data->fk_unit
|
||||
);
|
||||
if( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) {
|
||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
$request_data = (object) $request_data;
|
||||
$updateRes = $this->project->updateline(
|
||||
$lineid,
|
||||
$request_data->desc,
|
||||
$request_data->subprice,
|
||||
$request_data->qty,
|
||||
$request_data->remise_percent,
|
||||
$request_data->tva_tx,
|
||||
$request_data->localtax1_tx,
|
||||
$request_data->localtax2_tx,
|
||||
'HT',
|
||||
$request_data->info_bits,
|
||||
$request_data->date_start,
|
||||
$request_data->date_end,
|
||||
$request_data->product_type,
|
||||
$request_data->fk_parent_line,
|
||||
0,
|
||||
$request_data->fk_fournprice,
|
||||
$request_data->pa_ht,
|
||||
$request_data->label,
|
||||
$request_data->special_code,
|
||||
$request_data->array_options,
|
||||
$request_data->fk_unit
|
||||
);
|
||||
|
||||
if ($updateRes > 0) {
|
||||
$result = $this->get($id);
|
||||
unset($result->line);
|
||||
return $this->_cleanObjectDatas($result);
|
||||
}
|
||||
return false;
|
||||
}*/
|
||||
if ($updateRes > 0) {
|
||||
$result = $this->get($id);
|
||||
unset($result->line);
|
||||
return $this->_cleanObjectDatas($result);
|
||||
}
|
||||
return false;
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
@@ -443,12 +447,13 @@ class Projects 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->project->$field = $value;
|
||||
}
|
||||
|
||||
if ($this->project->update(DolibarrApiAccess::$user) >= 0)
|
||||
{
|
||||
if ($this->project->update(DolibarrApiAccess::$user) >= 0) {
|
||||
return $this->get($id);
|
||||
} else {
|
||||
throw new RestException(500, $this->project->error);
|
||||
@@ -600,8 +605,9 @@ class Projects extends DolibarrApi
|
||||
{
|
||||
$object = array();
|
||||
foreach (self::$FIELDS as $field) {
|
||||
if (!isset($data[$field]))
|
||||
if (!isset($data[$field])) {
|
||||
throw new RestException(400, "$field field missing");
|
||||
}
|
||||
$object[$field] = $data[$field];
|
||||
}
|
||||
return $object;
|
||||
|
||||
Reference in New Issue
Block a user