2
0
forked from Wavyzz/dolibarr

code syntax project

This commit is contained in:
Frédéric FRANCE
2021-02-26 18:49:22 +01:00
parent 50ae2d33b2
commit a82df7e6ea
39 changed files with 5067 additions and 4218 deletions

View File

@@ -33,7 +33,7 @@ class Tasks extends DolibarrApi
/**
* @var array $FIELDS Mandatory fields, checked when create and update object
*/
static $FIELDS = array(
public static $FIELDS = array(
'ref',
'label',
'fk_project'
@@ -80,12 +80,10 @@ class Tasks extends DolibarrApi
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
if ($includetimespent == 1)
{
if ($includetimespent == 1) {
$timespent = $this->task->getSummaryOfTimeSpent(0);
}
if ($includetimespent == 1)
{
if ($includetimespent == 1) {
// TODO
// Add class for timespent records and loop and fill $line->lines with records of timespent
}
@@ -118,28 +116,37 @@ class Tasks 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_task 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('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;
}
// 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 = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
@@ -148,8 +155,7 @@ class Tasks extends DolibarrApi
$sql .= $this->db->order($sortfield, $sortorder);
if ($limit) {
if ($page < 0)
{
if ($page < 0) {
$page = 0;
}
$offset = $limit * $page;
@@ -160,13 +166,11 @@ class Tasks 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);
$task_static = new Task($this->db);
if ($task_static->fetch($obj->rowid)) {
@@ -201,12 +205,12 @@ class Tasks extends DolibarrApi
$this->task->$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->task->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, "Error creating task", array_merge(array($this->task->error), $this->task->errors));
}
@@ -223,38 +227,38 @@ class Tasks extends DolibarrApi
// * @url GET {id}/tasks
// */
/*
public function getLines($id, $includetimespent=0)
{
if(! DolibarrApiAccess::$user->rights->projet->lire) {
throw new RestException(401);
}
public function getLines($id, $includetimespent=0)
{
if(! DolibarrApiAccess::$user->rights->projet->lire) {
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);
}
$this->project->getLinesArray(DolibarrApiAccess::$user);
$result = array();
foreach ($this->project->lines as $line) // $line is a task
{
if ($includetimespent == 1)
{
$timespent = $line->getSummaryOfTimeSpent(0);
}
if ($includetimespent == 1)
{
// TODO
// Add class for timespent records and loop and fill $line->lines with records of timespent
}
array_push($result,$this->_cleanObjectDatas($line));
}
return $result;
}
*/
if( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$this->project->getLinesArray(DolibarrApiAccess::$user);
$result = array();
foreach ($this->project->lines as $line) // $line is a task
{
if ($includetimespent == 1)
{
$timespent = $line->getSummaryOfTimeSpent(0);
}
if ($includetimespent == 1)
{
// TODO
// Add class for timespent records and loop and fill $line->lines with records of timespent
}
array_push($result,$this->_cleanObjectDatas($line));
}
return $result;
}
*/
/**
* Get roles a user is assigned to a task with
@@ -284,8 +288,7 @@ class Tasks extends DolibarrApi
}
$usert = DolibarrApiAccess::$user;
if ($userid > 0)
{
if ($userid > 0) {
$usert = new User($this->db);
$usert->fetch($userid);
}
@@ -309,56 +312,56 @@ class Tasks 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
@@ -372,52 +375,52 @@ class Tasks 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 +446,13 @@ class Tasks 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->task->$field = $value;
}
if ($this->task->update(DolibarrApiAccess::$user) > 0)
{
if ($this->task->update(DolibarrApiAccess::$user) > 0) {
return $this->get($id);
} else {
throw new RestException(500, $this->task->error);
@@ -519,7 +523,9 @@ class Tasks extends DolibarrApi
}
$uid = $user_id;
if (empty($uid)) $uid = DolibarrApiAccess::$user->id;
if (empty($uid)) {
$uid = DolibarrApiAccess::$user->id;
}
$newdate = dol_stringtotime($date, 1);
$this->task->timespent_date = $newdate;
@@ -607,8 +613,9 @@ class Tasks 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;