--- /tmp/dsg/dolibarr/htdocs/projet/class/github_19.0.3_api_projects.class.php +++ /tmp/dsg/dolibarr/htdocs/projet/class/client_api_projects.class.php @@ -32,71 +32,66 @@ - /** - * @var array $FIELDS Mandatory fields, checked when create and update object - */ - public static $FIELDS = array( - 'ref', - 'title' - ); - - /** - * @var Project $project {@type Project} - */ - public $project; - - /** - * @var Task $task {@type Task} - */ - public $task; - - - /** - * Constructor - */ - public function __construct() - { - global $db, $conf; - $this->db = $db; - $this->project = new Project($this->db); - $this->task = new Task($this->db); - } - - /** - * Get properties of a project object - * - * Return an array with project informations - * - * @param int $id ID of project - * @return Object Object with cleaned properties - * - * @throws RestException - */ - public function get($id) - { - if (!DolibarrApiAccess::$user->rights->projet->lire) { - throw new RestException(401); - } - - $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->fetchObjectLinked(); - return $this->_cleanObjectDatas($this->project); - } - - - - /** - * List projects - * - * Get a list of projects - * - * @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 projects of (example '1' or '1,2,3') {@pattern /^[0-9,]*$/i} + + /** + * @var array $FIELDS Mandatory fields, checked when create and update object + */ + static $FIELDS = array( + 'ref', + 'title' + ); + + /** + * @var Project $project {@type Project} + */ + public $project; + + /** + * Constructor + */ + public function __construct() + { + global $db, $conf; + $this->db = $db; + $this->project = new Project($this->db); + $this->task = new Task($this->db); + } + + /** + * Get properties of a project object + * + * Return an array with project informations + * + * @param int $id ID of project + * @return array|mixed data without useless information + * + * @throws RestException + */ + public function get($id) + { + if (!DolibarrApiAccess::$user->rights->projet->lire) { + throw new RestException(401); + } + + $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->fetchObjectLinked(); + return $this->_cleanObjectDatas($this->project); + } + + + + /** + * List projects + * + * Get a list of projects + * + * @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 projects of (example '1' or '1,2,3') {@pattern /^[0-9,]*$/i} @@ -105,27 +100,19 @@ - * @param string $properties Restrict the data returned to theses properties. Ignored if empty. Comma separated list of properties names - * @return array Array of project objects - */ - public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $category = 0, $sqlfilters = '', $properties = '') - { - if (!DolibarrApiAccess::$user->rights->projet->lire) { - throw new RestException(401); - } - - $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; - - // 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; - } - - $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) - } - $sql .= " FROM ".MAIN_DB_PREFIX."projet as t"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_extrafields AS ef ON ef.fk_object = t.rowid"; // So we will be able to filter on extrafields - if ($category > 0) { + * @return array Array of project objects + */ + public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $category = 0, $sqlfilters = '') + { + global $db, $conf; + + $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; + + // 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; + + $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) + $sql .= " FROM ".MAIN_DB_PREFIX."projet as t"; + if ($category > 0) { @@ -133,512 +120,497 @@ - } - 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 (".$this->db->sanitize($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) { - $sql .= " AND sc.fk_user = ".((int) $search_sale); - } - // Select projects of given category - if ($category > 0) { - $sql .= " AND c.fk_categorie = ".((int) $category)." AND c.fk_project = t.rowid "; - } - // Add sql filters - if ($sqlfilters) { - $errormessage = ''; - $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage); - if ($errormessage) { - throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage); - } - } - - $sql .= $this->db->order($sortfield, $sortorder); - if ($limit) { - if ($page < 0) { - $page = 0; - } - $offset = $limit * $page; - - $sql .= $this->db->plimit($limit + 1, $offset); - } - - dol_syslog("API Rest request"); - $result = $this->db->query($sql); - - if ($result) { - $num = $this->db->num_rows($result); - $min = min($num, ($limit <= 0 ? $num : $limit)); - $i = 0; - while ($i < $min) { - $obj = $this->db->fetch_object($result); - $project_static = new Project($this->db); - if ($project_static->fetch($obj->rowid)) { - $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($project_static), $properties); - } - $i++; - } - } else { - throw new RestException(503, 'Error when retrieve project list : '.$this->db->lasterror()); - } - - return $obj_ret; - } - - /** - * Create project object - * - * @param array $request_data Request data - * @return int ID of project - */ - public function post($request_data = null) - { - if (!DolibarrApiAccess::$user->rights->projet->creer) { - throw new RestException(401, "Insuffisant rights"); - } - // Check mandatory fields - $result = $this->_validate($request_data); - - foreach ($request_data as $field => $value) { - if ($field === 'caller') { - // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again whith the caller - $this->project->context['caller'] = $request_data['caller']; - continue; - } - - $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; - }*/ - if ($this->project->create(DolibarrApiAccess::$user) < 0) { - throw new RestException(500, "Error creating project", array_merge(array($this->project->error), $this->project->errors)); - } - - return $this->project->id; - } - - /** - * Get tasks of a project. - * See also API /tasks - * - * @param int $id Id of project - * @param int $includetimespent 0=Return only list of tasks. 1=Include a summary of time spent, 2=Include details of time spent lines - * @return array - * - * @url GET {id}/tasks - */ - 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'); - } - - 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 == 2) { - $timespent = $line->fetchTimeSpentOnTask(); - } - array_push($result, $this->_cleanObjectDatas($line)); - } - return $result; - } - - - /** - * Get roles a user is assigned to a project with - * - * @param int $id Id of project - * @param int $userid Id of user (0 = connected user) - * @return array - * - * @url GET {id}/roles - */ - public function getRoles($id, $userid = 0) - { - global $db; - - if (!DolibarrApiAccess::$user->rights->projet->lire) { - throw new RestException(401); - } - - $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); - } - - require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php'; - $taskstatic = new Task($this->db); - $userp = DolibarrApiAccess::$user; - if ($userid > 0) { - $userp = new User($this->db); - $userp->fetch($userid); - } - $this->project->roles = $taskstatic->getUserRolesForProjectsOrTasks($userp, null, $id, 0); - $result = array(); - foreach ($this->project->roles as $line) { - array_push($result, $this->_cleanObjectDatas($line)); - } - - return $result; - } - - - /** - * Add a task to given project - * - * @param int $id Id of project to update - * @param array $request_data Projectline data - * - * @url POST {id}/tasks - * - * @return int - */ - /* - 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'); - } - - if( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - $request_data = (object) $request_data; - - $request_data->desc = sanitizeVal($request_data->desc, 'restricthtml'); - - $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; - - } - return false; - } - */ - - /** - * Update a task to given project - * - * @param int $id Id of project to update - * @param int $taskid Id of task to update - * @param array $request_data Projectline data - * - * @url PUT {id}/tasks/{taskid} - * - * @return object - */ - /* - 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'); - } - - if( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - $request_data = (object) $request_data; - - $request_data->desc = sanitizeVal($request_data->desc, 'restricthtml'); - - $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; - }*/ - - - - /** - * Update project general fields (won't touch lines of project) - * - * @param int $id Id of project to update - * @param array $request_data Datas - * - * @return int - */ - public function put($id, $request_data = null) - { - if (!DolibarrApiAccess::$user->rights->projet->creer) { - throw new RestException(401); - } - - $result = $this->project->fetch($id); - if ($result <= 0) { - 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); - } - foreach ($request_data as $field => $value) { - if ($field == 'id') { - continue; - } - if ($field === 'caller') { - // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again whith the caller - $this->project->context['caller'] = $request_data['caller']; - continue; - } - - $this->project->$field = $value; - } - - if ($this->project->update(DolibarrApiAccess::$user) >= 0) { - return $this->get($id); - } else { - throw new RestException(500, $this->project->error); - } - } - - /** - * Delete project - * - * @param int $id Project ID - * - * @return array - */ - public function delete($id) - { - if (!DolibarrApiAccess::$user->rights->projet->supprimer) { - throw new RestException(401); - } - $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); - } - - if (!$this->project->delete(DolibarrApiAccess::$user)) { - throw new RestException(500, 'Error when delete project : '.$this->project->error); - } - - return array( - 'success' => array( - 'code' => 200, - 'message' => 'Project deleted' - ) - ); - } - - /** - * Validate a project. - * You can test this API with the following input message - * { "notrigger": 0 } - * - * @param int $id Project 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 - * { - * "notrigger": 0 - * } - */ - public function validate($id, $notrigger = 0) - { - if (!DolibarrApiAccess::$user->rights->projet->creer) { - throw new RestException(401); - } - $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); - } - - $result = $this->project->setValid(DolibarrApiAccess::$user, $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 Project: '.$this->project->error); - } - - return array( - 'success' => array( - 'code' => 200, - 'message' => 'Project validated' - ) - ); - } - - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore - /** - * Clean sensible object datas - * - * @param Object $object Object to clean - * @return Object Object with cleaned properties - */ - protected function _cleanObjectDatas($object) - { - // phpcs:enable - $object = parent::_cleanObjectDatas($object); - - unset($object->datec); - unset($object->datem); - unset($object->barcode_type); - unset($object->barcode_type_code); - unset($object->barcode_type_label); - unset($object->barcode_type_coder); - unset($object->cond_reglement_id); - unset($object->cond_reglement); - unset($object->fk_delivery_address); - unset($object->shipping_method_id); - unset($object->fk_account); - unset($object->note); - unset($object->fk_incoterms); - unset($object->label_incoterms); - unset($object->location_incoterms); - unset($object->name); - unset($object->lastname); - unset($object->firstname); - unset($object->civility_id); - unset($object->mode_reglement_id); - unset($object->country); - unset($object->country_id); - unset($object->country_code); - - unset($object->weekWorkLoad); - unset($object->weekWorkLoad); - - //unset($object->lines); // for task we use timespent_lines, but for project we use lines - - unset($object->total_ht); - unset($object->total_tva); - unset($object->total_localtax1); - unset($object->total_localtax2); - unset($object->total_ttc); - - unset($object->comments); - - return $object; - } - - /** - * Validate fields before create or update object - * - * @param array $data Array with data to verify - * @return array - * @throws RestException - */ - private function _validate($data) - { - $object = array(); - foreach (self::$FIELDS as $field) { - if (!isset($data[$field])) { - throw new RestException(400, "$field field missing"); - } - $object[$field] = $data[$field]; - } - return $object; - } - - - // TODO - // getSummaryOfTimeSpent + } + 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 + // Insert sale filter + if ($search_sale > 0) + { + $sql .= " AND sc.fk_user = ".$search_sale; + } + // Select projects of given category + if ($category > 0) { + $sql .= " AND c.fk_categorie = ".$db->escape($category)." AND c.fk_project = t.rowid "; + } + // 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->plimit($limit + 1, $offset); + } + + dol_syslog("API Rest request"); + $result = $db->query($sql); + + if ($result) + { + $num = $db->num_rows($result); + $min = min($num, ($limit <= 0 ? $num : $limit)); + while ($i < $min) + { + $obj = $db->fetch_object($result); + $project_static = new Project($db); + if ($project_static->fetch($obj->rowid)) { + $obj_ret[] = $this->_cleanObjectDatas($project_static); + } + $i++; + } + } + else { + throw new RestException(503, 'Error when retrieve project list : '.$db->lasterror()); + } + if (!count($obj_ret)) { + throw new RestException(404, 'No project found'); + } + return $obj_ret; + } + + /** + * Create project object + * + * @param array $request_data Request data + * @return int ID of project + */ + public function post($request_data = null) + { + if (!DolibarrApiAccess::$user->rights->projet->creer) { + throw new RestException(401, "Insuffisant rights"); + } + // Check mandatory fields + $result = $this->_validate($request_data); + + foreach ($request_data as $field => $value) { + $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; + }*/ + if ($this->project->create(DolibarrApiAccess::$user) < 0) { + throw new RestException(500, "Error creating project", array_merge(array($this->project->error), $this->project->errors)); + } + + return $this->project->id; + } + + /** + * Get tasks of a project. + * See also API /tasks + * + * @param int $id Id of project + * @param int $includetimespent 0=Return only list of tasks. 1=Include a summary of time spent, 2=Include details of time spent lines (2 is no implemented yet) + * @return int + * + * @url GET {id}/tasks + */ + 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'); + } + + 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 project with + * + * @param int $id Id of project + * @param int $userid Id of user (0 = connected user) + * + * @url GET {id}/roles + * + * @return int + */ + public function getRoles($id, $userid = 0) + { + global $db; + + if (!DolibarrApiAccess::$user->rights->projet->lire) { + throw new RestException(401); + } + + $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); + } + + require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php'; + $taskstatic = new Task($this->db); + $userp = DolibarrApiAccess::$user; + if ($userid > 0) + { + $userp = new User($this->db); + $userp->fetch($userid); + } + $this->project->roles = $taskstatic->getUserRolesForProjectsOrTasks($userp, 0, $id, 0); + $result = array(); + foreach ($this->project->roles as $line) { + array_push($result, $this->_cleanObjectDatas($line)); + } + return $result; + } + + + /** + * Add a task to given project + * + * @param int $id Id of project to update + * @param array $request_data Projectline data + * + * @url POST {id}/tasks + * + * @return int + */ + /* + 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'); + } + + 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; + + } + return false; + } + */ + + /** + * Update a task to given project + * + * @param int $id Id of project to update + * @param int $taskid Id of task to update + * @param array $request_data Projectline data + * + * @url PUT {id}/tasks/{taskid} + * + * @return object + */ + /* + 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'); + } + + 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; + }*/ + + + + /** + * Update project general fields (won't touch lines of project) + * + * @param int $id Id of project to update + * @param array $request_data Datas + * + * @return int + */ + public function put($id, $request_data = null) + { + if (!DolibarrApiAccess::$user->rights->projet->creer) { + throw new RestException(401); + } + + $result = $this->project->fetch($id); + if ($result <= 0) { + 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); + } + foreach ($request_data as $field => $value) { + if ($field == 'id') continue; + $this->project->$field = $value; + } + + if ($this->project->update(DolibarrApiAccess::$user) >= 0) + { + return $this->get($id); + } + else + { + throw new RestException(500, $this->project->error); + } + } + + /** + * Delete project + * + * @param int $id Project ID + * + * @return array + */ + public function delete($id) + { + if (!DolibarrApiAccess::$user->rights->projet->supprimer) { + throw new RestException(401); + } + $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); + } + + if (!$this->project->delete(DolibarrApiAccess::$user)) { + throw new RestException(500, 'Error when delete project : '.$this->project->error); + } + + return array( + 'success' => array( + 'code' => 200, + 'message' => 'Project deleted' + ) + ); + } + + /** + * Validate a project. + * You can test this API with the following input message + * { "notrigger": 0 } + * + * @param int $id Project 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 + * { + * "notrigger": 0 + * } + */ + public function validate($id, $notrigger = 0) + { + if (!DolibarrApiAccess::$user->rights->projet->creer) { + throw new RestException(401); + } + $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); + } + + $result = $this->project->setValid(DolibarrApiAccess::$user, $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 Project: '.$this->project->error); + } + + return array( + 'success' => array( + 'code' => 200, + 'message' => 'Project validated' + ) + ); + } + + + // 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->datec); + unset($object->datem); + unset($object->barcode_type); + unset($object->barcode_type_code); + unset($object->barcode_type_label); + unset($object->barcode_type_coder); + unset($object->cond_reglement_id); + unset($object->cond_reglement); + unset($object->fk_delivery_address); + unset($object->shipping_method_id); + unset($object->fk_account); + unset($object->note); + unset($object->fk_incoterms); + unset($object->label_incoterms); + unset($object->location_incoterms); + unset($object->name); + unset($object->lastname); + unset($object->firstname); + unset($object->civility_id); + unset($object->mode_reglement_id); + unset($object->country); + unset($object->country_id); + unset($object->country_code); + + unset($object->weekWorkLoad); + unset($object->weekWorkLoad); + + //unset($object->lines); // for task we use timespent_lines, but for project we use lines + + unset($object->total_ht); + unset($object->total_tva); + unset($object->total_localtax1); + unset($object->total_localtax2); + unset($object->total_ttc); + + unset($object->comments); + + return $object; + } + + /** + * Validate fields before create or update object + * + * @param array $data Array with data to verify + * @return array + * @throws RestException + */ + private function _validate($data) + { + $object = array(); + foreach (self::$FIELDS as $field) { + if (!isset($data[$field])) + throw new RestException(400, "$field field missing"); + $object[$field] = $data[$field]; + } + return $object; + } + + + // TODO + // getSummaryOfTimeSpent --- /tmp/dsg/dolibarr/htdocs/projet/class/github_19.0.3_api_tasks.class.php +++ /tmp/dsg/dolibarr/htdocs/projet/class/client_api_tasks.class.php @@ -19,5 +19,4 @@ -use Luracast\Restler\RestException; - -require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; - + use Luracast\Restler\RestException; + + require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php'; + require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; @@ -33,26 +32,32 @@ - /** - * @var array $FIELDS Mandatory fields, checked when create and update object - */ - public static $FIELDS = array( - 'ref', - 'label', - 'fk_project' - ); - - /** - * @var Task $task {@type Task} - */ - public $task; - - /** - * Constructor - */ - public function __construct() - { - global $db, $conf; - $this->db = $db; - $this->task = new Task($this->db); - } - - /** - * Get properties of a task object + + /** + * @var array $FIELDS Mandatory fields, checked when create and update object + */ + static $FIELDS = array( + 'ref', + 'label' + ); + + /** + * @var Task $task {@type Task} + */ + public $task; + + /** + * Constructor + */ + public function __construct() + { + global $db, $conf; + $this->db = $db; + $this->task = new Task($this->db); + } + + /** + * Get properties of a task object + * + * Return an array with task informations + * + * @param int $id ID of task + * @param int $includetimespent 0=Return only task. 1=Include a summary of time spent, 2=Include details of time spent lines (2 is no implemented yet) + * @return array|mixed data without useless information @@ -60,10 +65,4 @@ - * Return an array with task informations - * - * @param int $id ID of task - * @param int $includetimespent 0=Return only task. 1=Include a summary of time spent, 2=Include details of time spent lines - * @return array|mixed data without useless information - * - * @throws RestException - */ - public function get($id, $includetimespent = 0) - { + * @throws RestException + */ + public function get($id, $includetimespent = 0) + { @@ -74,4 +73,4 @@ - $result = $this->task->fetch($id); - if (!$result) { - throw new RestException(404, 'Task not found'); - } + $result = $this->task->fetch($id); + if (!$result) { + throw new RestException(404, 'Task not found'); + } @@ -83,2 +82,3 @@ - if ($includetimespent == 1) { - $timespent = $this->task->getSummaryOfTimeSpent(0); + if ($includetimespent == 1) + { + $timespent = $this->task->getSummaryOfTimeSpent(0); @@ -86,2 +86,4 @@ - if ($includetimespent == 2) { - $timespent = $this->task->fetchTimeSpentOnTask(); + if ($includetimespent == 1) + { + // TODO + // Add class for timespent records and loop and fill $line->lines with records of timespent @@ -91,98 +93,90 @@ - } - - - - /** - * List tasks - * - * Get a list of tasks - * - * @param string $sortfield Sort field - * @param string $sortorder Sort order - * @param int $limit Limit for list - * @param int $page Page number - * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')" - * @param string $properties Restrict the data returned to theses properties. Ignored if empty. Comma separated list of properties names - * @return array Array of project objects - */ - public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '', $properties = '') - { - global $db, $conf; - - if (!DolibarrApiAccess::$user->rights->projet->lire) { - throw new RestException(401); - } - - $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 : ''; - - // 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; - } - - $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) - } - $sql .= " FROM ".MAIN_DB_PREFIX."projet_task AS t LEFT JOIN ".MAIN_DB_PREFIX."projet_task_extrafields AS ef ON (ef.fk_object = t.rowid)"; // Modification VMR Global Solutions to include extrafields as search parameters in the API GET call, so we will be able to filter on extrafields - - 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 (".$this->db->sanitize($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) { - $sql .= " AND sc.fk_user = ".((int) $search_sale); - } - // Add sql filters - if ($sqlfilters) { - $errormessage = ''; - $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage); - if ($errormessage) { - throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage); - } - } - - $sql .= $this->db->order($sortfield, $sortorder); - if ($limit) { - if ($page < 0) { - $page = 0; - } - $offset = $limit * $page; - - $sql .= $this->db->plimit($limit + 1, $offset); - } - - dol_syslog("API Rest request"); - $result = $this->db->query($sql); - - if ($result) { - $num = $this->db->num_rows($result); - $min = min($num, ($limit <= 0 ? $num : $limit)); - $i = 0; - while ($i < $min) { - $obj = $this->db->fetch_object($result); - $task_static = new Task($this->db); - if ($task_static->fetch($obj->rowid)) { - $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($task_static), $properties); - } - $i++; - } - } else { - throw new RestException(503, 'Error when retrieve task list : '.$this->db->lasterror()); - } - + } + + + + /** + * List tasks + * + * Get a list of tasks + * + * @param string $sortfield Sort field + * @param string $sortorder Sort order + * @param int $limit Limit for list + * @param int $page Page number + * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')" + * @return array Array of project objects + */ + public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '') + { + global $db, $conf; + + $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 : ''; + + // 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; + + $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) + $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 + + $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 + // 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->plimit($limit + 1, $offset); + } + + dol_syslog("API Rest request"); + $result = $db->query($sql); + + if ($result) + { + $num = $db->num_rows($result); + $min = min($num, ($limit <= 0 ? $num : $limit)); + $i = 0; + while ($i < $min) + { + $obj = $db->fetch_object($result); + $task_static = new Task($db); + if ($task_static->fetch($obj->rowid)) { + $obj_ret[] = $this->_cleanObjectDatas($task_static); + } + $i++; + } + } + else { + throw new RestException(503, 'Error when retrieve task list : '.$db->lasterror()); + } + if (!count($obj_ret)) { + throw new RestException(404, 'No task found'); + } @@ -190,60 +184,259 @@ - } - - /** - * Create task object - * - * @param array $request_data Request data - * @return int ID of project - */ - public function post($request_data = null) - { - if (!DolibarrApiAccess::$user->rights->projet->creer) { - throw new RestException(401, "Insuffisant rights"); - } - // Check mandatory fields - $result = $this->_validate($request_data); - - foreach ($request_data as $field => $value) { - if ($field === 'caller') { - // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again whith the caller - $this->task->context['caller'] = $request_data['caller']; - continue; - } - - $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; - }*/ - if ($this->task->create(DolibarrApiAccess::$user) < 0) { - throw new RestException(500, "Error creating task", array_merge(array($this->task->error), $this->task->errors)); - } - - return $this->task->id; - } - - // /** - // * Get time spent of a task - // * - // * @param int $id Id of task - // * @return int - // * - // * @url GET {id}/tasks - // */ - /* - 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'); - } - - if( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) { + } + + /** + * Create task object + * + * @param array $request_data Request data + * @return int ID of project + */ + public function post($request_data = null) + { + if (!DolibarrApiAccess::$user->rights->projet->creer) { + throw new RestException(401, "Insuffisant rights"); + } + // Check mandatory fields + $result = $this->_validate($request_data); + + foreach ($request_data as $field => $value) { + $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; + }*/ + if ($this->task->create(DolibarrApiAccess::$user) < 0) { + throw new RestException(500, "Error creating task", array_merge(array($this->task->error), $this->task->errors)); + } + + return $this->task->id; + } + + // /** + // * Get time spent of a task + // * + // * @param int $id Id of task + // * @return int + // * + // * @url GET {id}/tasks + // */ + /* + 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'); + } + + 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 + * + * @param int $id Id of task + * @param int $userid Id of user (0 = connected user) + * + * @url GET {id}/roles + * + * @return int + */ + public function getRoles($id, $userid = 0) + { + global $db; + + if (!DolibarrApiAccess::$user->rights->projet->lire) { + throw new RestException(401); + } + + $result = $this->task->fetch($id); + if (!$result) { + throw new RestException(404, 'Task not found'); + } + + if (!DolibarrApi::_checkAccessToResource('tasks', $this->task->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $usert = DolibarrApiAccess::$user; + if ($userid > 0) + { + $usert = new User($this->db); + $usert->fetch($userid); + } + $this->task->roles = $this->task->getUserRolesForProjectsOrTasks(0, $usert, 0, $id); + $result = array(); + foreach ($this->task->roles as $line) { + array_push($result, $this->_cleanObjectDatas($line)); + } + return $result; + } + + + // /** + // * Add a task to given project + // * + // * @param int $id Id of project to update + // * @param array $request_data Projectline data + // * + // * @url POST {id}/tasks + // * + // * @return int + // */ + /* + 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'); + } + + 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; + + } + return false; + } + */ + + // /** + // * Update a task to given project + // * + // * @param int $id Id of project to update + // * @param int $taskid Id of task to update + // * @param array $request_data Projectline data + // * + // * @url PUT {id}/tasks/{taskid} + // * + // * @return object + // */ + /* + 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'); + } + + 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; + }*/ + + + /** + * Update task general fields (won't touch time spent of task) + * + * @param int $id Id of task to update + * @param array $request_data Datas + * + * @return int + */ + public function put($id, $request_data = null) + { + if (!DolibarrApiAccess::$user->rights->projet->creer) { + throw new RestException(401); + } + + $result = $this->task->fetch($id); + if (!$result) { + throw new RestException(404, 'Task not found'); + } + + if (!DolibarrApi::_checkAccessToResource('tasks', $this->project->id)) { @@ -252,43 +445,33 @@ - $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 - * - * @param int $id Id of task - * @param int $userid Id of user (0 = connected user) - * @return array Array of roles - * - * @url GET {id}/roles - * - */ - public function getRoles($id, $userid = 0) - { - global $db; - - if (!DolibarrApiAccess::$user->rights->projet->lire) { - throw new RestException(401); - } - - $result = $this->task->fetch($id); - if (!$result) { - throw new RestException(404, 'Task not found'); - } - - if (!DolibarrApi::_checkAccessToResource('tasks', $this->task->id)) { + foreach ($request_data as $field => $value) { + if ($field == 'id') continue; + $this->task->$field = $value; + } + + if ($this->task->update(DolibarrApiAccess::$user) > 0) + { + return $this->get($id); + } + else + { + throw new RestException(500, $this->task->error); + } + } + + /** + * Delete task + * + * @param int $id Task ID + * + * @return array + */ + public function delete($id) + { + if (!DolibarrApiAccess::$user->rights->projet->supprimer) { + throw new RestException(401); + } + $result = $this->task->fetch($id); + if (!$result) { + throw new RestException(404, 'Task not found'); + } + + if (!DolibarrApi::_checkAccessToResource('tasks', $this->project->id)) { @@ -298,457 +481,141 @@ - $usert = DolibarrApiAccess::$user; - if ($userid > 0) { - $usert = new User($this->db); - $usert->fetch($userid); - } - $this->task->roles = $this->task->getUserRolesForProjectsOrTasks(null, $usert, 0, $id); - $result = array(); - foreach ($this->task->roles as $line) { - array_push($result, $this->_cleanObjectDatas($line)); - } - - return $result; - } - - - // /** - // * Add a task to given project - // * - // * @param int $id Id of project to update - // * @param array $request_data Projectline data - // * - // * @url POST {id}/tasks - // * - // * @return int - // */ - /* - 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'); - } - - if( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - $request_data = (object) $request_data; - - $request_data->desc = sanitizeVal($request_data->desc, 'restricthtml'); - - $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; - - } - return false; - } - */ - - // /** - // * Update a task of a given project - // * - // * @param int $id Id of project to update - // * @param int $taskid Id of task to update - // * @param array $request_data Projectline data - // * - // * @url PUT {id}/tasks/{taskid} - // * - // * @return object - // */ - /* - 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'); - } - - if( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - $request_data = (object) $request_data; - - $request_data->desc = sanitizeVal($request_data->desc, 'restricthtml'); - - $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; - }*/ - - - /** - * Update task general fields (won't touch time spent of task) - * - * @param int $id Id of task to update - * @param array $request_data Datas - * - * @return int - */ - public function put($id, $request_data = null) - { - if (!DolibarrApiAccess::$user->rights->projet->creer) { - throw new RestException(401); - } - - $result = $this->task->fetch($id); - if (!$result) { - throw new RestException(404, 'Task not found'); - } - - if (!DolibarrApi::_checkAccessToResource('task', $this->task->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - foreach ($request_data as $field => $value) { - if ($field == 'id') { - continue; - } - if ($field === 'caller') { - // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again whith the caller - $this->task->context['caller'] = $request_data['caller']; - continue; - } - - $this->task->$field = $value; - } - - if ($this->task->update(DolibarrApiAccess::$user) > 0) { - return $this->get($id); - } else { - throw new RestException(500, $this->task->error); - } - } - - /** - * Delete task - * - * @param int $id Task ID - * - * @return array - */ - public function delete($id) - { - if (!DolibarrApiAccess::$user->rights->projet->supprimer) { - throw new RestException(401); - } - $result = $this->task->fetch($id); - if (!$result) { - throw new RestException(404, 'Task not found'); - } - - if (!DolibarrApi::_checkAccessToResource('task', $this->task->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - if (!$this->task->delete(DolibarrApiAccess::$user)) { - throw new RestException(500, 'Error when delete task : '.$this->task->error); - } - - return array( - 'success' => array( - 'code' => 200, - 'message' => 'Task deleted' - ) - ); - } - - - /** - * Add time spent to a task of a project. - * You can test this API with the following input message - * { "date": "2016-12-31 23:15:00", "duration": 1800, "user_id": 1, "note": "My time test" } - * - * @param int $id Task ID - * @param datetime $date Date (YYYY-MM-DD HH:MI:SS in GMT) - * @param int $duration Duration in seconds (3600 = 1h) - * @param int $user_id User (Use 0 for connected user) - * @param string $note Note - * - * @url POST {id}/addtimespent - * NOTE: Should be "POST {id}/timespent", since POST already implies "add" - * - * @return array - */ - public function addTimeSpent($id, $date, $duration, $user_id = 0, $note = '') - { - if (!DolibarrApiAccess::$user->rights->projet->creer) { - throw new RestException(401); - } - $result = $this->task->fetch($id); - if ($result <= 0) { - throw new RestException(404, 'Task not found'); - } - - if (!DolibarrApi::_checkAccessToResource('project', $this->task->fk_project)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - $uid = $user_id; - if (empty($uid)) { - $uid = DolibarrApiAccess::$user->id; - } - - $newdate = dol_stringtotime($date, 1); - $this->task->timespent_date = $newdate; - $this->task->timespent_datehour = $newdate; - $this->task->timespent_withhour = 1; - $this->task->timespent_duration = $duration; - $this->task->timespent_fk_user = $uid; - $this->task->timespent_note = $note; - - $result = $this->task->addTimeSpent(DolibarrApiAccess::$user, 0); - 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 adding time: '.$this->task->error); - } - - return array( - 'success' => array( - 'code' => 200, - 'message' => 'Time spent added' - ) - ); - } - - /** - * Update time spent for a task of a project. - * You can test this API with the following input message - * { "date": "2016-12-31 23:15:00", "duration": 1800, "user_id": 1, "note": "My time test" } - * - * @param int $id Task ID - * @param int $timespent_id Time spent ID (llx_element_time.rowid) - * @param datetime $date Date (YYYY-MM-DD HH:MI:SS in GMT) - * @param int $duration Duration in seconds (3600 = 1h) - * @param int $user_id User (Use 0 for connected user) - * @param string $note Note - * - * @url PUT {id}/timespent/{timespent_id} - * - * @return array - */ - public function putTimeSpent($id, $timespent_id, $date, $duration, $user_id = 0, $note = '') - { - if (!DolibarrApiAccess::$user->rights->projet->creer) { - throw new RestException(401); - } - $this->timespentRecordChecks($id, $timespent_id); - - if (!DolibarrApi::_checkAccessToResource('task', $this->task->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - $newdate = dol_stringtotime($date, 1); - $this->task->timespent_date = $newdate; - $this->task->timespent_datehour = $newdate; - $this->task->timespent_withhour = 1; - $this->task->timespent_duration = $duration; - $this->task->timespent_fk_user = $user_id ?? DolibarrApiAccess::$user->id; - $this->task->timespent_note = $note; - - $result = $this->task->updateTimeSpent(DolibarrApiAccess::$user, 0); - if ($result == 0) { - throw new RestException(304, 'Error nothing done.'); - } - if ($result < 0) { - throw new RestException(500, 'Error when updating time spent: '.$this->task->error); - } - - return array( - 'success' => array( - 'code' => 200, - 'message' => 'Time spent updated' - ) - ); - } - - /** - * Delete time spent for a task of a project. - * - * @param int $id Task ID - * @param int $timespent_id Time spent ID (llx_element_time.rowid) - * - * @url DELETE {id}/timespent/{timespent_id} - * - * @return array - */ - public function deleteTimeSpent($id, $timespent_id) - { - if (!DolibarrApiAccess::$user->rights->projet->supprimer) { - throw new RestException(401); - } - $this->timespentRecordChecks($id, $timespent_id); - - if (!DolibarrApi::_checkAccessToResource('task', $this->task->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - if ($this->task->delTimeSpent(DolibarrApiAccess::$user, 0) < 0) { - throw new RestException(500, 'Error when deleting time spent: '.$this->task->error); - } - - return array( - 'success' => array( - 'code' => 200, - 'message' => 'Time spent deleted' - ) - ); - } - - /** - * Validate task & timespent IDs for timespent API methods. - * Loads the selected task & timespent records. - * - * @param int $id Task ID - * @param int $timespent_id Time spent ID (llx_element_time.rowid) - * - * @return void - */ - protected function timespentRecordChecks($id, $timespent_id) - { - if ($this->task->fetch($id) <= 0) { - throw new RestException(404, 'Task not found'); - } - if ($this->task->fetchTimeSpent($timespent_id) <= 0) { - throw new RestException(404, 'Timespent not found'); - } elseif ($this->task->id != $id) { - throw new RestException(404, 'Timespent not found in selected task'); - } - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore - /** - * Clean sensible object datas - * - * @param Object $object Object to clean - * @return Object Object with cleaned properties - */ - protected function _cleanObjectDatas($object) - { - // phpcs:enable - $object = parent::_cleanObjectDatas($object); - - unset($object->barcode_type); - unset($object->barcode_type_code); - unset($object->barcode_type_label); - unset($object->barcode_type_coder); - unset($object->cond_reglement_id); - unset($object->cond_reglement); - unset($object->fk_delivery_address); - unset($object->shipping_method_id); - unset($object->fk_account); - unset($object->note); - unset($object->fk_incoterms); - unset($object->label_incoterms); - unset($object->location_incoterms); - unset($object->name); - unset($object->lastname); - unset($object->firstname); - unset($object->civility_id); - unset($object->mode_reglement_id); - unset($object->country); - unset($object->country_id); - unset($object->country_code); - - unset($object->weekWorkLoad); - unset($object->weekWorkLoad); - - //unset($object->lines); // for task we use timespent_lines, but for project we use lines - - unset($object->total_ht); - unset($object->total_tva); - unset($object->total_localtax1); - unset($object->total_localtax2); - unset($object->total_ttc); - - unset($object->comments); - - return $object; - } - - /** - * Validate fields before create or update object - * - * @param array $data Array with data to verify - * @return array - * @throws RestException - */ - private function _validate($data) - { - $object = array(); - foreach (self::$FIELDS as $field) { - if (!isset($data[$field])) { - throw new RestException(400, "$field field missing"); - } - $object[$field] = $data[$field]; - } - return $object; - } - - - // \todo - // getSummaryOfTimeSpent + if (!$this->task->delete(DolibarrApiAccess::$user)) { + throw new RestException(500, 'Error when delete task : '.$this->task->error); + } + + return array( + 'success' => array( + 'code' => 200, + 'message' => 'Task deleted' + ) + ); + } + + + /** + * Add time spent to a task of a project. + * You can test this API with the following input message + * { "date": "2016-12-31 23:15:00", "duration": 1800, "user_id": 1, "note": "My time test" } + * + * @param int $id Task ID + * @param datetime $date Date (YYYY-MM-DD HH:MI:SS in GMT) + * @param int $duration Duration in seconds (3600 = 1h) + * @param int $user_id User (Use 0 for connected user) + * @param string $note Note + * + * @url POST {id}/addtimespent + * + * @return array + */ + public function addTimeSpent($id, $date, $duration, $user_id = 0, $note = '') + { + if (!DolibarrApiAccess::$user->rights->projet->creer) { + throw new RestException(401); + } + $result = $this->task->fetch($id); + if ($result <= 0) { + throw new RestException(404, 'Task not found'); + } + + if (!DolibarrApi::_checkAccessToResource('project', $this->task->fk_project)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $uid = $user_id; + if (empty($uid)) $uid = DolibarrApiAccess::$user->id; + + $newdate = dol_stringtotime($date, 1); + $this->task->timespent_date = $newdate; + $this->task->timespent_datehour = $newdate; + $this->task->timespent_withhour = 1; + $this->task->timespent_duration = $duration; + $this->task->timespent_fk_user = $user_id; + $this->task->timespent_note = $note; + + $result = $this->task->addTimeSpent(DolibarrApiAccess::$user, 0); + 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 adding time: '.$this->task->error); + } + + return array( + 'success' => array( + 'code' => 200, + 'message' => 'Time spent added' + ) + ); + } + + + // 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->barcode_type); + unset($object->barcode_type_code); + unset($object->barcode_type_label); + unset($object->barcode_type_coder); + unset($object->cond_reglement_id); + unset($object->cond_reglement); + unset($object->fk_delivery_address); + unset($object->shipping_method_id); + unset($object->fk_account); + unset($object->note); + unset($object->fk_incoterms); + unset($object->label_incoterms); + unset($object->location_incoterms); + unset($object->name); + unset($object->lastname); + unset($object->firstname); + unset($object->civility_id); + unset($object->mode_reglement_id); + unset($object->country); + unset($object->country_id); + unset($object->country_code); + + unset($object->weekWorkLoad); + unset($object->weekWorkLoad); + + //unset($object->lines); // for task we use timespent_lines, but for project we use lines + + unset($object->total_ht); + unset($object->total_tva); + unset($object->total_localtax1); + unset($object->total_localtax2); + unset($object->total_ttc); + + unset($object->comments); + + return $object; + } + + /** + * Validate fields before create or update object + * + * @param array $data Array with data to verify + * @return array + * @throws RestException + */ + private function _validate($data) + { + $object = array(); + foreach (self::$FIELDS as $field) { + if (!isset($data[$field])) + throw new RestException(400, "$field field missing"); + $object[$field] = $data[$field]; + } + return $object; + } + + + // \todo + // getSummaryOfTimeSpent --- /tmp/dsg/dolibarr/htdocs/projet/class/github_19.0.3_project.class.php +++ /tmp/dsg/dolibarr/htdocs/projet/class/client_project.class.php @@ -9,2 +8,0 @@ - * Copyright (C) 2022 Charlene Benke - * Copyright (C) 2023 Gauthier VERDOL @@ -37,0 +36 @@ + @@ -49 +48 @@ - * @var string Name of subtable line + * @var int Name of subtable line @@ -54 +53 @@ - * @var string Name of field date + * @var int Name of field date @@ -59 +58 @@ - * @var string Field with ID of parent key if this field has a parent + * @var int Field with ID of parent key if this field has a parent @@ -70,5 +68,0 @@ - * @var int Does object support extrafields ? 0=No, 1=Yes - */ - public $isextrafieldmanaged = 1; - - /** @@ -85,5 +78,0 @@ - * @var int parent project - */ - public $fk_project; - - /** @@ -99,10 +87,0 @@ - /** - * @var int Date start - * @deprecated - * @see $date_start - */ - public $dateo; - - /** - * @var int Date start - */ @@ -110,11 +88,0 @@ - - /** - * @var int Date end - * @deprecated - * @see $date_end - */ - public $datee; - - /** - * @var int Date end - */ @@ -122,19 +89,0 @@ - - /** - * @var int Date start event - */ - public $date_start_event; - - /** - * @var int Date end event - */ - public $date_end_event; - - /** - * @var string Location - */ - public $location; - - /** - * @var int Date close - */ @@ -152,0 +102,4 @@ + /** + * @var int user close id + */ + public $user_close_id; @@ -154,4 +106,0 @@ - - /** - * @var float budget Amount - */ @@ -159,14 +107,0 @@ - - /** - * @var integer Can use projects to follow opportunities - */ - public $usage_opportunity; - - /** - * @var integer Can follow tasks on project and enter time spent on it - */ - public $usage_task; - - /** - * @var integer Use to bill task spend time - */ @@ -175,32 +110,2 @@ - /** - * @var integer Event organization: Use Event Organization - */ - public $usage_organize_event; - - /** - * @var integer Event organization: Allow unknown people to suggest new conferences - */ - public $accept_conference_suggestions; - - /** - * @var integer Event organization: Allow unknown people to suggest new booth - */ - public $accept_booth_suggestions; - - /** - * @var float Event organization: registration price - */ - public $price_registration; - - /** - * @var float Event organization: booth price - */ - public $price_booth; - - /** - * @var float Max attendees - */ - public $max_attendees; - - public $labelStatusShort; - public $labelStatus; + public $statuts_short; + public $statuts_long; @@ -209 +113,0 @@ - @@ -211,3 +114,0 @@ - public $opp_status_code; - public $fk_opp_status; // opportunity status, into table llx_c_lead_status - public $opp_amount; // opportunity amount @@ -215,3 +115,0 @@ - public $opp_weighted_amount; // opportunity weighted amount - - public $email_msgid; @@ -223,10 +120,0 @@ - - /** - * @var array Used to store workload details of a projet - */ - public $monthWorkLoad; - - /** - * @var array Used to store workload details of tasks of a projet - */ - public $monthWorkLoadPerTask; @@ -259,5 +146,0 @@ - * @var string Ip address - */ - public $ip; - - /** @@ -269,28 +152,16 @@ - * 'type' if the field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password') - * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)" - * 'label' the translation key. - * 'enabled' is a condition when the field must be managed. - * 'position' is the sort order of field. - * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0). - * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). 5=Visible on list and view only (not create/not update). Using a negative value means field is not shown by default on list but can be selected for viewing) - * 'noteditable' says if field is not editable (1 or 0) - * 'default' is a default value for creation (can still be overwrote by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created. - * 'index' if we want an index in database. - * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...). - * 'searchall' is 1 if we want to search in this field when making a search from the quick search button. - * 'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8). - * 'css' is the CSS style to use on field. For example: 'maxwidth200' - * 'help' is a string visible as a tooltip on field - * 'showoncombobox' if value of the field must be visible into the label of the combobox that list record - * 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute. In most cases, this is never set into the definition of $fields into class, but is set dynamically by some part of code. - * 'arrayofkeyval' to set list of value if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel") - * 'comment' is not used. You can store here any text of your choice. It is not used by application. - * - * Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor. - */ - - // BEGIN MODULEBUILDER PROPERTIES - /** - * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. - */ - public $fields = array( + * Draft status + */ + const STATUS_DRAFT = 0; + + /** + * Open/Validated status + */ + const STATUS_VALIDATED = 1; + + /** + * Closed status + */ + const STATUS_CLOSED = 2; + + + public $fields=array( @@ -298,39 +169,27 @@ - 'fk_project' =>array('type'=>'integer', 'label'=>'Parent', 'enabled'=>1, 'visible'=>1, 'notnull'=>0, 'position'=>12), - 'ref' =>array('type'=>'varchar(50)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'showoncombobox'=>1, 'position'=>15, 'searchall'=>1), - 'title' =>array('type'=>'varchar(255)', 'label'=>'ProjectLabel', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'position'=>17, 'showoncombobox'=>2, 'searchall'=>1), - 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'default'=>1, 'enabled'=>1, 'visible'=>3, 'notnull'=>1, 'position'=>19), - 'fk_soc' =>array('type'=>'integer', 'label'=>'Thirdparty', 'enabled'=>1, 'visible'=>0, 'position'=>20), - 'dateo' =>array('type'=>'date', 'label'=>'DateStart', 'enabled'=>1, 'visible'=>1, 'position'=>30), - 'datee' =>array('type'=>'date', 'label'=>'DateEnd', 'enabled'=>1, 'visible'=>1, 'position'=>35), - 'description' =>array('type'=>'text', 'label'=>'Description', 'enabled'=>1, 'visible'=>3, 'position'=>55, 'searchall'=>1), - 'public' =>array('type'=>'integer', 'label'=>'Visibility', 'enabled'=>1, 'visible'=>1, 'position'=>65), - 'fk_opp_status' =>array('type'=>'integer', 'label'=>'OpportunityStatusShort', 'enabled'=>'getDolGlobalString("PROJECT_USE_OPPORTUNITIES")', 'visible'=>1, 'position'=>75), - 'opp_percent' =>array('type'=>'double(5,2)', 'label'=>'OpportunityProbabilityShort', 'enabled'=>'getDolGlobalString("PROJECT_USE_OPPORTUNITIES")', 'visible'=>1, 'position'=>80), - 'note_private' =>array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>85, 'searchall'=>1), - 'note_public' =>array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>90, 'searchall'=>1), - 'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'ModelPdf', 'enabled'=>1, 'visible'=>0, 'position'=>95), - 'date_close' =>array('type'=>'datetime', 'label'=>'DateClosing', 'enabled'=>1, 'visible'=>0, 'position'=>105), - 'fk_user_close' =>array('type'=>'integer', 'label'=>'UserClosing', 'enabled'=>1, 'visible'=>0, 'position'=>110), - 'opp_amount' =>array('type'=>'double(24,8)', 'label'=>'OpportunityAmountShort', 'enabled'=>1, 'visible'=>'getDolGlobalString("PROJECT_USE_OPPORTUNITIES")', 'position'=>115), - 'budget_amount' =>array('type'=>'double(24,8)', 'label'=>'Budget', 'enabled'=>1, 'visible'=>-1, 'position'=>119), - 'usage_opportunity' =>array('type'=>'integer', 'label'=>'UsageOpportunity', 'enabled'=>1, 'visible'=>-1, 'position'=>130), - 'usage_task' =>array('type'=>'integer', 'label'=>'UsageTasks', 'enabled'=>1, 'visible'=>-1, 'position'=>135), - 'usage_bill_time' =>array('type'=>'integer', 'label'=>'UsageBillTimeShort', 'enabled'=>1, 'visible'=>-1, 'position'=>140), - 'usage_organize_event' =>array('type'=>'integer', 'label'=>'UsageOrganizeEvent', 'enabled'=>1, 'visible'=>-1, 'position'=>145), - // Properties for event organization - 'date_start_event' =>array('type'=>'date', 'label'=>'DateStartEvent', 'enabled'=>"isModEnabled('eventorganization')", 'visible'=>1, 'position'=>200), - 'date_end_event' =>array('type'=>'date', 'label'=>'DateEndEvent', 'enabled'=>"isModEnabled('eventorganization')", 'visible'=>1, 'position'=>201), - 'location' =>array('type'=>'text', 'label'=>'Location', 'enabled'=>1, 'visible'=>3, 'position'=>55, 'searchall'=>202), - 'accept_conference_suggestions' =>array('type'=>'integer', 'label'=>'AllowUnknownPeopleSuggestConf', 'enabled'=>1, 'visible'=>-1, 'position'=>210), - 'accept_booth_suggestions' =>array('type'=>'integer', 'label'=>'AllowUnknownPeopleSuggestBooth', 'enabled'=>1, 'visible'=>-1, 'position'=>211), - 'price_registration' =>array('type'=>'double(24,8)', 'label'=>'PriceOfRegistration', 'enabled'=>1, 'visible'=>-1, 'position'=>212), - 'price_booth' =>array('type'=>'double(24,8)', 'label'=>'PriceOfBooth', 'enabled'=>1, 'visible'=>-1, 'position'=>215), - 'max_attendees' =>array('type'=>'integer', 'label'=>'MaxNbOfAttendees', 'enabled'=>1, 'visible'=>-1, 'position'=>215), - // Generic - 'datec' =>array('type'=>'datetime', 'label'=>'DateCreationShort', 'enabled'=>1, 'visible'=>-2, 'position'=>400), - 'tms' =>array('type'=>'timestamp', 'label'=>'DateModificationShort', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>405), - 'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserCreation', 'enabled'=>1, 'visible'=>0, 'notnull'=>1, 'position'=>410), - 'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModification', 'enabled'=>1, 'visible'=>0, 'position'=>415), - 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-1, 'position'=>420), - 'email_msgid'=>array('type'=>'varchar(255)', 'label'=>'EmailMsgID', 'enabled'=>1, 'visible'=>-1, 'position'=>450, 'help'=>'EmailMsgIDWhenSourceisEmail', 'csslist'=>'tdoverflowmax125'), - 'fk_statut' =>array('type'=>'smallint(6)', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'position'=>500), + 'fk_soc' =>array('type'=>'integer', 'label'=>'Fk soc', 'enabled'=>1, 'visible'=>-1, 'position'=>15), + 'datec' =>array('type'=>'datetime', 'label'=>'Datec', 'enabled'=>1, 'visible'=>-1, 'position'=>20), + 'tms' =>array('type'=>'timestamp', 'label'=>'Tms', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>25), + 'dateo' =>array('type'=>'date', 'label'=>'Dateo', 'enabled'=>1, 'visible'=>-1, 'position'=>30), + 'datee' =>array('type'=>'date', 'label'=>'Datee', 'enabled'=>1, 'visible'=>-1, 'position'=>35), + 'ref' =>array('type'=>'varchar(50)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>-1, 'showoncombobox'=>1, 'position'=>40), + 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'default'=>1, 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>45), + 'title' =>array('type'=>'varchar(255)', 'label'=>'Title', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>50, 'showoncombobox'=>1), + 'description' =>array('type'=>'text', 'label'=>'Description', 'enabled'=>1, 'visible'=>-1, 'position'=>55), + 'fk_user_creat' =>array('type'=>'integer', 'label'=>'Fk user creat', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>60), + 'public' =>array('type'=>'integer', 'label'=>'Public', 'enabled'=>1, 'visible'=>-1, 'position'=>65), + 'fk_statut' =>array('type'=>'smallint(6)', 'label'=>'Fk statut', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>500), + 'fk_opp_status' =>array('type'=>'integer', 'label'=>'Fk opp status', 'enabled'=>1, 'visible'=>-1, 'position'=>75), + 'opp_percent' =>array('type'=>'double(5,2)', 'label'=>'Opp percent', 'enabled'=>1, 'visible'=>-1, 'position'=>80), + 'note_private' =>array('type'=>'text', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>85), + 'note_public' =>array('type'=>'text', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>90), + 'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>1, 'visible'=>0, 'position'=>95), + 'budget_amount' =>array('type'=>'double(24,8)', 'label'=>'Budget amount', 'enabled'=>1, 'visible'=>-1, 'position'=>100), + 'date_close' =>array('type'=>'datetime', 'label'=>'Date close', 'enabled'=>1, 'visible'=>-1, 'position'=>105), + 'fk_user_close' =>array('type'=>'integer', 'label'=>'Fk user close', 'enabled'=>1, 'visible'=>-1, 'position'=>110), + 'opp_amount' =>array('type'=>'double(24,8)', 'label'=>'Opp amount', 'enabled'=>1, 'visible'=>-1, 'position'=>115), + 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-1, 'position'=>120), + 'fk_user_modif' =>array('type'=>'integer', 'label'=>'Fk user modif', 'enabled'=>1, 'visible'=>-1, 'position'=>125), + 'usage_bill_time' =>array('type'=>'integer', 'label'=>'Usage bill time', 'enabled'=>1, 'visible'=>-1, 'position'=>130), + 'usage_opportunity' =>array('type'=>'integer', 'label'=>'Usage opportunity', 'enabled'=>1, 'visible'=>-1, 'position'=>135), + 'usage_task' =>array('type'=>'integer', 'label'=>'Usage task', 'enabled'=>1, 'visible'=>-1, 'position'=>140), + 'usage_organize_event' =>array('type'=>'integer', 'label'=>'Usage organize event', 'enabled'=>1, 'visible'=>-1, 'position'=>145), @@ -338,16 +197 @@ - // END MODULEBUILDER PROPERTIES - - /** - * Draft status - */ - const STATUS_DRAFT = 0; - - /** - * Open/Validated status - */ - const STATUS_VALIDATED = 1; - - /** - * Closed status - */ - const STATUS_CLOSED = 2; + @@ -362,2 +205,0 @@ - global $conf; - @@ -366,29 +208,2 @@ - $this->labelStatusShort = array(0 => 'Draft', 1 => 'Opened', 2 => 'Closed'); - $this->labelStatus = array(0 => 'Draft', 1 => 'Opened', 2 => 'Closed'); - - global $conf; - - if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID')) { - $this->fields['rowid']['visible'] = 0; - } - - if (!getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) { - $this->fields['fk_opp_status']['enabled'] = 0; - $this->fields['opp_percent']['enabled'] = 0; - $this->fields['opp_amount']['enabled'] = 0; - $this->fields['usage_opportunity']['enabled'] = 0; - } - - if (getDolGlobalString('PROJECT_HIDE_TASKS')) { - $this->fields['usage_bill_time']['visible'] = 0; - $this->fields['usage_task']['visible'] = 0; - } - - if (empty($conf->eventorganization->enabled)) { - $this->fields['usage_organize_event']['visible'] = 0; - $this->fields['accept_conference_suggestions']['enabled'] = 0; - $this->fields['accept_booth_suggestions']['enabled'] = 0; - $this->fields['price_registration']['enabled'] = 0; - $this->fields['price_booth']['enabled'] = 0; - $this->fields['max_attendees']['enabled'] = 0; - } + $this->statuts_short = array(0 => 'Draft', 1 => 'Opened', 2 => 'Closed'); + $this->statuts_long = array(0 => 'Draft', 1 => 'Opened', 2 => 'Closed'); @@ -402 +217 @@ - * @return int Return integer <0 if KO, id of created project if OK + * @return int <0 if KO, id of created project if OK @@ -418 +233,2 @@ - if (!trim($this->ref)) { + if (!trim($this->ref)) + { @@ -423 +239,2 @@ - if (getDolGlobalString('PROJECT_THIRDPARTY_REQUIRED') && !($this->socid > 0)) { + if (!empty($conf->global->PROJECT_THIRDPARTY_REQUIRED) && !($this->socid > 0)) + { @@ -434 +250,0 @@ - $sql .= ", fk_project"; @@ -452,9 +267,0 @@ - $sql .= ", accept_conference_suggestions"; - $sql .= ", accept_booth_suggestions"; - $sql .= ", price_registration"; - $sql .= ", price_booth"; - $sql .= ", max_attendees"; - $sql .= ", date_start_event"; - $sql .= ", date_end_event"; - $sql .= ", location"; - $sql .= ", email_msgid"; @@ -464 +270,0 @@ - $sql .= ", ip"; @@ -467 +272,0 @@ - $sql .= ", ".($this->fk_project ? ((int) $this->fk_project) : "null"); @@ -471,4 +276,4 @@ - $sql .= ", ".((int) $user->id); - $sql .= ", ".(is_numeric($this->statut) ? ((int) $this->statut) : '0'); - $sql .= ", ".((is_numeric($this->opp_status) && $this->opp_status > 0) ? ((int) $this->opp_status) : 'NULL'); - $sql .= ", ".(is_numeric($this->opp_percent) ? ((int) $this->opp_percent) : 'NULL'); + $sql .= ", ".$user->id; + $sql .= ", ".(is_numeric($this->statut) ? $this->statut : '0'); + $sql .= ", ".((is_numeric($this->opp_status) && $this->opp_status > 0) ? $this->opp_status : 'NULL'); + $sql .= ", ".(is_numeric($this->opp_percent) ? $this->opp_percent : 'NULL'); @@ -485,9 +289,0 @@ - $sql .= ", ".($this->accept_conference_suggestions ? 1 : 0); - $sql .= ", ".($this->accept_booth_suggestions ? 1 : 0); - $sql .= ", ".(strcmp($this->price_registration, '') ? price2num($this->price_registration) : 'null'); - $sql .= ", ".(strcmp($this->price_booth, '') ? price2num($this->price_booth) : 'null'); - $sql .= ", ".(strcmp($this->max_attendees, '') ? ((int) $this->max_attendees) : 'null'); - $sql .= ", ".($this->date_start_event != '' ? "'".$this->db->idate($this->date_start_event)."'" : 'null'); - $sql .= ", ".($this->date_end_event != '' ? "'".$this->db->idate($this->date_end_event)."'" : 'null'); - $sql .= ", ".($this->location ? "'".$this->db->escape($this->location)."'" : 'null'); - $sql .= ", ".($this->email_msgid ? "'".$this->db->escape($this->email_msgid)."'" : 'null'); @@ -496,2 +292 @@ - $sql .= ", ".((int) $conf->entity); - $sql .= ", ".(!isset($this->ip) ? 'NULL' : "'".$this->db->escape($this->ip)."'"); + $sql .= ", ".$conf->entity; @@ -502 +297,2 @@ - if ($resql) { + if ($resql) + { @@ -506 +302,2 @@ - if (!$notrigger) { + if (!$notrigger) + { @@ -509,3 +306 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) { $error++; } @@ -514 +309,3 @@ - } else { + } + else + { @@ -515,0 +313 @@ + $this->errno = $this->db->lasterrno(); @@ -522 +320,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -527 +326,2 @@ - if (!$error && (getDolGlobalString('MAIN_DISABLEDRAFTSTATUS') || getDolGlobalString('MAIN_DISABLEDRAFTSTATUS_PROJECT'))) { + if (!$error && !empty($conf->global->MAIN_DISABLEDRAFTSTATUS)) + { @@ -529,6 +329,5 @@ - if ($res < 0) { - $error++; - } - } - - if (!$error) { + if ($res < 0) $error++; + } + + if (!$error) + { @@ -537 +336,3 @@ - } else { + } + else + { @@ -548 +349 @@ - * @return int Return integer <=0 if KO, >0 if OK + * @return int <=0 if KO, >0 if OK @@ -559,7 +360,4 @@ - if ($this->opp_amount < 0) { - $this->opp_amount = ''; - } - if ($this->opp_percent < 0) { - $this->opp_percent = ''; - } - if ($this->date_end && $this->date_end < $this->date_start) { + if ($this->opp_amount < 0) $this->opp_amount = ''; + if ($this->opp_percent < 0) $this->opp_percent = ''; + if ($this->date_end && $this->date_end < $this->date_start) + { @@ -573,3 +371,2 @@ - $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity); - - if (dol_strlen(trim($this->ref)) > 0) { + if (dol_strlen(trim($this->ref)) > 0) + { @@ -580 +376,0 @@ - $sql .= ", fk_project=".($this->fk_project ? ((int) $this->fk_project) : "null"); @@ -584 +380 @@ - $sql .= ", fk_statut = ".((int) $this->statut); + $sql .= ", fk_statut = ".$this->statut; @@ -588,7 +384,5 @@ - $sql .= ", datec = ".($this->date_c != '' ? "'".$this->db->idate($this->date_c)."'" : 'null'); - $sql .= ", dateo = ".($this->date_start != '' ? "'".$this->db->idate($this->date_start)."'" : 'null'); - $sql .= ", datee = ".($this->date_end != '' ? "'".$this->db->idate($this->date_end)."'" : 'null'); - $sql .= ", date_close = ".($this->date_close != '' ? "'".$this->db->idate($this->date_close)."'" : 'null'); - $sql .= ", note_public = ".($this->note_public ? "'".$this->db->escape($this->note_public)."'" : "null"); - $sql .= ", note_private = ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null"); - $sql .= ", fk_user_close = ".($this->fk_user_close > 0 ? $this->fk_user_close : "null"); + $sql .= ", datec=".($this->date_c != '' ? "'".$this->db->idate($this->date_c)."'" : 'null'); + $sql .= ", dateo=".($this->date_start != '' ? "'".$this->db->idate($this->date_start)."'" : 'null'); + $sql .= ", datee=".($this->date_end != '' ? "'".$this->db->idate($this->date_end)."'" : 'null'); + $sql .= ", date_close=".($this->date_close != '' ? "'".$this->db->idate($this->date_close)."'" : 'null'); + $sql .= ", fk_user_close=".($this->fk_user_close > 0 ? $this->fk_user_close : "null"); @@ -602,10 +396 @@ - $sql .= ", accept_conference_suggestions = ".($this->accept_conference_suggestions ? 1 : 0); - $sql .= ", accept_booth_suggestions = ".($this->accept_booth_suggestions ? 1 : 0); - $sql .= ", price_registration = ".(strcmp($this->price_registration, '') ? price2num($this->price_registration) : "null"); - $sql .= ", price_booth = ".(strcmp($this->price_booth, '') ? price2num($this->price_booth) : "null"); - $sql .= ", max_attendees = ".(strcmp($this->max_attendees, '') ? price2num($this->max_attendees) : "null"); - $sql .= ", date_start_event = ".($this->date_start_event != '' ? "'".$this->db->idate($this->date_start_event)."'" : 'null'); - $sql .= ", date_end_event = ".($this->date_end_event != '' ? "'".$this->db->idate($this->date_end_event)."'" : 'null'); - $sql .= ", location = '".$this->db->escape($this->location)."'"; - $sql .= ", entity = ".((int) $this->entity); - $sql .= " WHERE rowid = ".((int) $this->id); + $sql .= " WHERE rowid = ".$this->id; @@ -615 +400,2 @@ - if ($resql) { + if ($resql) + { @@ -617 +403,2 @@ - if (!$error) { + if (!$error) + { @@ -619 +406,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -624 +412,2 @@ - if (!$error && !$notrigger) { + if (!$error && !$notrigger) + { @@ -627,3 +416 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) { $error++; } @@ -633 +420,2 @@ - if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref)) { + if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref)) + { @@ -635,4 +423,6 @@ - if ($conf->project->dir_output) { - $olddir = $conf->project->dir_output."/".dol_sanitizeFileName($this->oldcopy->ref); - $newdir = $conf->project->dir_output."/".dol_sanitizeFileName($this->ref); - if (file_exists($olddir)) { + if ($conf->projet->dir_output) + { + $olddir = $conf->projet->dir_output."/".dol_sanitizeFileName($this->oldcopy->ref); + $newdir = $conf->projet->dir_output."/".dol_sanitizeFileName($this->ref); + if (file_exists($olddir)) + { @@ -641 +431,2 @@ - if (!$res) { + if (!$res) + { @@ -649 +440,2 @@ - if (!$error) { + if (!$error) + { @@ -652 +444,3 @@ - } else { + } + else + { @@ -656 +450,3 @@ - } else { + } + else + { @@ -660 +456,2 @@ - if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { + if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { @@ -662 +459,3 @@ - } else { + } + else + { @@ -667 +466,3 @@ - } else { + } + else + { @@ -678,17 +479,13 @@ - * @param int $id Id of object to load - * @param string $ref Ref of project - * @param string $ref_ext Ref ext of project - * @param string $email_msgid Email msgid - * @return int >0 if OK, 0 if not found, <0 if KO - */ - public function fetch($id, $ref = '', $ref_ext = '', $email_msgid = '') - { - if (empty($id) && empty($ref) && empty($ref_ext) && empty($email_msgid)) { - dol_syslog(get_class($this)."::fetch Bad parameters", LOG_WARNING); - return -1; - } - - $sql = "SELECT rowid, entity, fk_project, ref, title, description, public, datec, opp_amount, budget_amount,"; - $sql .= " tms, dateo as date_start, datee as date_end, date_close, fk_soc, fk_user_creat, fk_user_modif, fk_user_close, fk_statut as status, fk_opp_status, opp_percent,"; - $sql .= " note_private, note_public, model_pdf, usage_opportunity, usage_task, usage_bill_time, usage_organize_event, email_msgid,"; - $sql .= " accept_conference_suggestions, accept_booth_suggestions, price_registration, price_booth, max_attendees, date_start_event, date_end_event, location, extraparams"; + * @param int $id Id of object to load + * @param string $ref Ref of project + * @return int >0 if OK, 0 if not found, <0 if KO + */ + public function fetch($id, $ref = '') + { + global $conf; + + if (empty($id) && empty($ref)) return -1; + + $sql = "SELECT rowid, ref, title, description, public, datec, opp_amount, budget_amount,"; + $sql .= " tms, dateo, datee, date_close, fk_soc, fk_user_creat, fk_user_modif, fk_user_close, fk_statut as status, fk_opp_status, opp_percent,"; + $sql .= " note_private, note_public, model_pdf, usage_opportunity, usage_task, usage_bill_time, usage_organize_event, entity"; @@ -696,11 +493,8 @@ - if (!empty($id)) { - $sql .= " WHERE rowid = ".((int) $id); - } else { - $sql .= " WHERE entity IN (".getEntity('project').")"; - if (!empty($ref)) { - $sql .= " AND ref = '".$this->db->escape($ref)."'"; - } elseif (!empty($ref_ext)) { - $sql .= " AND ref_ext = '".$this->db->escape($ref_ext)."'"; - } else { - $sql .= " AND email_msgid = '".$this->db->escape($email_msgid)."'"; - } + if (!empty($id)) + { + $sql .= " WHERE rowid=".$id; + } + elseif (!empty($ref)) + { + $sql .= " WHERE ref='".$this->db->escape($ref)."'"; + $sql .= " AND entity IN (".getEntity('project').")"; @@ -711 +505,2 @@ - if ($resql) { + if ($resql) + { @@ -714 +509,2 @@ - if ($num_rows) { + if ($num_rows) + { @@ -718 +513,0 @@ - $this->entity = $obj->entity; @@ -720 +514,0 @@ - $this->fk_project = $obj->fk_project; @@ -727,2 +521,2 @@ - $this->date_start = $this->db->jdate($obj->date_start); - $this->date_end = $this->db->jdate($obj->date_end); + $this->date_start = $this->db->jdate($obj->dateo); + $this->date_end = $this->db->jdate($obj->datee); @@ -735 +529 @@ - $this->user_closing_id = $obj->fk_user_close; + $this->user_close_id = $obj->fk_user_close; @@ -743 +537 @@ - $this->model_pdf = $obj->model_pdf; + $this->modelpdf = $obj->model_pdf; @@ -748,10 +542 @@ - $this->accept_conference_suggestions = (int) $obj->accept_conference_suggestions; - $this->accept_booth_suggestions = (int) $obj->accept_booth_suggestions; - $this->price_registration = $obj->price_registration; - $this->price_booth = $obj->price_booth; - $this->max_attendees = $obj->max_attendees; - $this->date_start_event = $this->db->jdate($obj->date_start_event); - $this->date_end_event = $this->db->jdate($obj->date_end_event); - $this->location = $obj->location; - $this->email_msgid = $obj->email_msgid; - $this->extraparams = !empty($obj->extraparams) ? (array) json_decode($obj->extraparams, true) : array(); + $this->entity = $obj->entity; @@ -761 +546 @@ - // Retrieve all extrafield + // Retreive all extrafield @@ -771 +556,3 @@ - } else { + } + else + { @@ -773 +559,0 @@ - $this->errors[] = $this->db->lasterror(); @@ -776,32 +561,0 @@ - } - - /** - * Fetch object and substitute key - * - * @param int $id Project id - * @param string $key Key to substitute - * @param bool $fetched [=false] Not already fetched - * @return string Substitute key - */ - public function fetchAndSetSubstitution($id, $key, $fetched = false) - { - $substitution = ''; - - if ($fetched === false) { - $res = $this->fetch($id); - if ($res > 0) { - $fetched = true; - } - } - - if ($fetched === true) { - if ($key == '__PROJECT_ID__') { - $substitution = ($this->id > 0 ? $this->id : ''); - } elseif ($key == '__PROJECT_REF__') { - $substitution = $this->ref; - } elseif ($key == '__PROJECT_NAME__') { - $substitution = $this->title; - } - } - - return $substitution; @@ -817,2 +571,2 @@ - * @param int $date_start Start date - * @param int $date_end End date + * @param int $dates Start date + * @param int $datee End date @@ -822 +576 @@ - public function get_element_list($type, $tablename, $datefieldname = '', $date_start = '', $date_end = '', $projectkey = 'fk_projet') + public function get_element_list($type, $tablename, $datefieldname = '', $dates = '', $datee = '', $projectkey = 'fk_projet') @@ -825,3 +578,0 @@ - - global $hookmanager; - @@ -830,3 +581 @@ - if ($this->id <= 0) { - return $elements; - } + if ($this->id <= 0) return $elements; @@ -836,60 +585,49 @@ - if ($type == 'agenda') { - $sql = "SELECT id as rowid FROM ".MAIN_DB_PREFIX."actioncomm WHERE fk_project IN (".$this->db->sanitize($ids).") AND entity IN (".getEntity('agenda').")"; - } elseif ($type == 'expensereport') { - $sql = "SELECT ed.rowid FROM ".MAIN_DB_PREFIX."expensereport as e, ".MAIN_DB_PREFIX."expensereport_det as ed WHERE e.rowid = ed.fk_expensereport AND e.entity IN (".getEntity('expensereport').") AND ed.fk_projet IN (".$this->db->sanitize($ids).")"; - } elseif ($type == 'project_task') { - $sql = "SELECT DISTINCT pt.rowid FROM ".MAIN_DB_PREFIX."projet_task as pt WHERE pt.fk_projet IN (".$this->db->sanitize($ids).")"; - } elseif ($type == 'element_time') { // Case we want to duplicate line foreach user - $sql = "SELECT DISTINCT pt.rowid, ptt.fk_user FROM ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."element_time as ptt WHERE pt.rowid = ptt.fk_element AND ptt.elementtype = 'task' AND pt.fk_projet IN (".$this->db->sanitize($ids).")"; - } elseif ($type == 'stocktransfer_stocktransfer') { - $sql = "SELECT ms.rowid, ms.fk_user_author as fk_user FROM ".MAIN_DB_PREFIX."stocktransfer_stocktransfer as ms, ".MAIN_DB_PREFIX."entrepot as e WHERE e.rowid = ms.fk_entrepot AND e.entity IN (".getEntity('stock').") AND ms.origintype = 'project' AND ms.fk_origin IN (".$this->db->sanitize($ids).") AND ms.type_mouvement = 1"; - } elseif ($type == 'loan') { - $sql = "SELECT l.rowid, l.fk_user_author as fk_user FROM ".MAIN_DB_PREFIX."loan as l WHERE l.entity IN (".getEntity('loan').") AND l.fk_projet IN (".$this->db->sanitize($ids).")"; - } else { - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$tablename." WHERE ".$projectkey." IN (".$this->db->sanitize($ids).") AND entity IN (".getEntity($type).")"; - } - - if ($date_start > 0 && $type == 'loan') { - $sql .= " AND (dateend > '".$this->db->idate($date_start)."' OR dateend IS NULL)"; - } elseif ($date_start > 0 && ($type != 'project_task')) { // For table project_taks, we want the filter on date apply on project_time_spent table - if (empty($datefieldname) && !empty($this->table_element_date)) { - $datefieldname = $this->table_element_date; - } - if (empty($datefieldname)) { - return 'Error this object has no date field defined'; - } - $sql .= " AND (".$datefieldname." >= '".$this->db->idate($date_start)."' OR ".$datefieldname." IS NULL)"; - } - - if ($date_end > 0 && $type == 'loan') { - $sql .= " AND (datestart < '".$this->db->idate($date_end)."' OR datestart IS NULL)"; - } elseif ($date_end > 0 && ($type != 'project_task')) { // For table project_taks, we want the filter on date apply on project_time_spent table - if (empty($datefieldname) && !empty($this->table_element_date)) { - $datefieldname = $this->table_element_date; - } - if (empty($datefieldname)) { - return 'Error this object has no date field defined'; - } - $sql .= " AND (".$datefieldname." <= '".$this->db->idate($date_end)."' OR ".$datefieldname." IS NULL)"; - } - - $parameters = array( - 'sql'=>$sql, - 'type' => $type, - 'tablename' => $tablename, - 'datefieldname' => $datefieldname, - 'dates' => $date_start, - 'datee' => $date_end, - 'fk_projet' => $projectkey, - 'ids' => $ids, - ); - $reshook = $hookmanager->executeHooks('getElementList', $parameters); - if ($reshook > 0) { - $sql = $hookmanager->resPrint; - } else { - $sql .= $hookmanager->resPrint; - } - - if (!$sql) { - return -1; - } + if ($type == 'agenda') + { + $sql = "SELECT id as rowid FROM ".MAIN_DB_PREFIX."actioncomm WHERE fk_project IN (".$ids.") AND entity IN (".getEntity('agenda').")"; + } + elseif ($type == 'expensereport') + { + $sql = "SELECT ed.rowid FROM ".MAIN_DB_PREFIX."expensereport as e, ".MAIN_DB_PREFIX."expensereport_det as ed WHERE e.rowid = ed.fk_expensereport AND e.entity IN (".getEntity('expensereport').") AND ed.fk_projet IN (".$ids.")"; + } + elseif ($type == 'project_task') + { + $sql = "SELECT DISTINCT pt.rowid FROM ".MAIN_DB_PREFIX."projet_task as pt WHERE pt.fk_projet IN (".$ids.")"; + } + elseif ($type == 'project_task_time') // Case we want to duplicate line foreach user + { + $sql = "SELECT DISTINCT pt.rowid, ptt.fk_user FROM ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."projet_task_time as ptt WHERE pt.rowid = ptt.fk_task AND pt.fk_projet IN (".$ids.")"; + } + elseif ($type == 'stock_mouvement') + { + $sql = 'SELECT ms.rowid, ms.fk_user_author as fk_user FROM '.MAIN_DB_PREFIX."stock_mouvement as ms, ".MAIN_DB_PREFIX."entrepot as e WHERE e.rowid = ms.fk_entrepot AND e.entity IN (".getEntity('stock').") AND ms.origintype = 'project' AND ms.fk_origin IN (".$ids.") AND ms.type_mouvement = 1"; + } + elseif ($type == 'loan') + { + $sql = 'SELECT l.rowid, l.fk_user_author as fk_user FROM '.MAIN_DB_PREFIX."loan as l WHERE l.entity IN (".getEntity('loan').") AND l.fk_projet IN (".$ids.")"; + } + else + { + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$tablename." WHERE ".$projectkey." IN (".$ids.") AND entity IN (".getEntity($type).")"; + } + + if($dates > 0 && $type == 'loan'){ + $sql .= " AND (dateend > '".$this->db->idate($dates)."' OR dateend IS NULL)"; + } + elseif ($dates > 0 && ($type != 'project_task')) // For table project_taks, we want the filter on date apply on project_time_spent table + { + if (empty($datefieldname) && !empty($this->table_element_date)) $datefieldname = $this->table_element_date; + if (empty($datefieldname)) return 'Error this object has no date field defined'; + $sql .= " AND (".$datefieldname." >= '".$this->db->idate($dates)."' OR ".$datefieldname." IS NULL)"; + } + + if($datee > 0 && $type == 'loan'){ + $sql .= " AND (datestart < '".$this->db->idate($datee)."' OR datestart IS NULL)"; + } + elseif ($datee > 0 && ($type != 'project_task')) // For table project_taks, we want the filter on date apply on project_time_spent table + { + if (empty($datefieldname) && !empty($this->table_element_date)) $datefieldname = $this->table_element_date; + if (empty($datefieldname)) return 'Error this object has no date field defined'; + $sql .= " AND (".$datefieldname." <= '".$this->db->idate($datee)."' OR ".$datefieldname." IS NULL)"; + } + if (!$sql) return -1; @@ -900 +638,2 @@ - if ($result) { + if ($result) + { @@ -902 +641,2 @@ - if ($nump) { + if ($nump) + { @@ -904 +644,2 @@ - while ($i < $nump) { + while ($i < $nump) + { @@ -916 +657,3 @@ - } else { + } + else + { @@ -926 +669 @@ - * @return int Return integer <0 if KO, 0 if not possible, >0 if OK + * @return int <0 if KO, 0 if not possible, >0 if OK @@ -937 +680,2 @@ - if (!$error) { + if (!$error) + { @@ -940 +684,2 @@ - if ($res < 0) { + if ($res < 0) + { @@ -952,6 +697,2 @@ - 'expensereport_det'=>'fk_projet', 'contrat'=>'fk_projet', - 'fichinter'=>'fk_projet', - 'don'=>array('field'=>'fk_projet', 'module'=>'don'), - 'actioncomm'=>'fk_project', - 'mrp_mo'=>'fk_project', - 'entrepot'=>'fk_project' + 'expensereport_det'=>'fk_projet', 'contrat'=>'fk_projet', 'fichinter'=>'fk_projet', 'don'=>'fk_projet', + 'actioncomm'=>'fk_project', 'mrp_mo'=>'fk_project' @@ -959,11 +700,3 @@ - foreach ($listoftables as $key => $value) { - if (is_array($value)) { - if (!isModEnabled($value['module'])) { - continue; - } - $fieldname = $value['field']; - } else { - $fieldname = $value; - } - $sql = "UPDATE ".MAIN_DB_PREFIX.$key." SET ".$fieldname." = NULL where ".$fieldname." = ".((int) $this->id); - + foreach ($listoftables as $key => $value) + { + $sql = "UPDATE ".MAIN_DB_PREFIX.$key." SET ".$value." = NULL where ".$value." = ".$this->id; @@ -971 +704,2 @@ - if (!$resql) { + if (!$resql) + { @@ -981 +715 @@ - $sql .= " WHERE fk_project = ".((int) $this->id); + $sql .= " WHERE fk_project = ".$this->id; @@ -991 +725 @@ - $this->getLinesArray($user, 0); + $this->getLinesArray($user); @@ -995,3 +729 @@ - if ($ret < 0) { - $error++; - } + if ($ret < 0) $error++; @@ -1003 +735,2 @@ - foreach ($elements as $table) { + foreach ($elements as $table) + { @@ -1006 +739 @@ - $sql .= " WHERE fk_project = ".((int) $this->id); + $sql .= " WHERE fk_project = ".$this->id; @@ -1017 +750,2 @@ - if (!$error) { + if (!$error) + { @@ -1019 +753 @@ - $sql .= " WHERE fk_object = ".((int) $this->id); + $sql .= " WHERE fk_object=".$this->id; @@ -1022 +756,2 @@ - if (!$resql) { + if (!$resql) + { @@ -1029 +764,2 @@ - if (!$error) { + if (!$error) + { @@ -1031 +767 @@ - $sql .= " WHERE rowid=".((int) $this->id); + $sql .= " WHERE rowid=".$this->id; @@ -1034 +770,2 @@ - if (!$resql) { + if (!$resql) + { @@ -1045,2 +782,2 @@ - if ($conf->project->dir_output) { - $dir = $conf->project->dir_output."/".$projectref; + if ($conf->projet->dir_output) { + $dir = $conf->projet->dir_output."/".$projectref; @@ -1056 +793,2 @@ - if (!$notrigger) { + if (!$notrigger) + { @@ -1067 +805,2 @@ - if (empty($error)) { + if (empty($error)) + { @@ -1070,2 +809,5 @@ - } else { - foreach ($this->errors as $errmsg) { + } + else + { + foreach ($this->errors as $errmsg) + { @@ -1082,43 +823,0 @@ - * Return the count of a type of linked elements of this project - * - * @param string $type The type of the linked elements (e.g. 'propal', 'order', 'invoice', 'order_supplier', 'invoice_supplier') - * @param string $tablename The name of table associated of the type - * @param string $projectkey (optional) Equivalent key to fk_projet for actual type - * @return integer The count of the linked elements (the count is zero on request error too) - */ - public function getElementCount($type, $tablename, $projectkey = 'fk_projet') - { - if ($this->id <= 0) { - return 0; - } - - if ($type == 'agenda') { - $sql = "SELECT COUNT(id) as nb FROM ".MAIN_DB_PREFIX."actioncomm WHERE fk_project = ".((int) $this->id)." AND entity IN (".getEntity('agenda').")"; - } elseif ($type == 'expensereport') { - $sql = "SELECT COUNT(ed.rowid) as nb FROM ".MAIN_DB_PREFIX."expensereport as e, ".MAIN_DB_PREFIX."expensereport_det as ed WHERE e.rowid = ed.fk_expensereport AND e.entity IN (".getEntity('expensereport').") AND ed.fk_projet = ".((int) $this->id); - } elseif ($type == 'project_task') { - $sql = "SELECT DISTINCT COUNT(pt.rowid) as nb FROM ".MAIN_DB_PREFIX."projet_task as pt WHERE pt.fk_projet = ".((int) $this->id); - } elseif ($type == 'element_time') { // Case we want to duplicate line foreach user - $sql = "SELECT DISTINCT COUNT(pt.rowid) as nb FROM ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."element_time as ptt WHERE pt.rowid = ptt.fk_element AND ptt.elementtype = 'task' AND pt.fk_projet = ".((int) $this->id); - } elseif ($type == 'stock_mouvement') { - $sql = "SELECT COUNT(ms.rowid) as nb FROM ".MAIN_DB_PREFIX."stock_mouvement as ms, ".MAIN_DB_PREFIX."entrepot as e WHERE e.rowid = ms.fk_entrepot AND e.entity IN (".getEntity('stock').") AND ms.origintype = 'project' AND ms.fk_origin = ".((int) $this->id)." AND ms.type_mouvement = 1"; - } elseif ($type == 'loan') { - $sql = "SELECT COUNT(l.rowid) as nb FROM ".MAIN_DB_PREFIX."loan as l WHERE l.entity IN (".getEntity('loan').") AND l.fk_projet = ".((int) $this->id); - } else { - $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.$tablename." WHERE ".$projectkey." = ".((int) $this->id)." AND entity IN (".getEntity($type).")"; - } - - $result = $this->db->query($sql); - - if (!$result) { - return 0; - } - - $obj = $this->db->fetch_object($result); - - $this->db->free($result); - - return $obj->nb; - } - - /** @@ -1128 +827 @@ - * @return int Return integer <0 if KO, 1 if OK + * @return int <0 if KO, 1 if OK @@ -1134,2 +833,4 @@ - if ($countTasks) { - foreach ($this->lines as $task) { + if ($countTasks) + { + foreach ($this->lines as $task) + { @@ -1139 +840,2 @@ - if ($ret <= 0) { + if ($ret <= 0) + { @@ -1147,4 +849,3 @@ - if ($deleted && count($this->lines) < $countTasks) { - if (count($this->lines)) { - $this->deleteTasks($this->lines); - } + if ($deleted && count($this->lines) < $countTasks) + { + if (count($this->lines)) $this->deleteTasks($this->lines); @@ -1161 +862 @@ - * @return int Return integer <0 if KO, 0=Nothing done, >0 if KO + * @return int <0 if KO, >0 if OK @@ -1169,36 +870,44 @@ - // Protection - if ($this->status == self::STATUS_VALIDATED) { - dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING); - return 0; - } - - // Check parameters - if (preg_match('/^'.preg_quote($langs->trans("CopyOf").' ').'/', $this->title)) { - $this->error = $langs->trans("ErrorFieldFormat", $langs->transnoentities("Label")).'. '.$langs->trans('RemoveString', $langs->transnoentitiesnoconv("CopyOf")); - return -1; - } - - $this->db->begin(); - - $sql = "UPDATE ".MAIN_DB_PREFIX."projet"; - $sql .= " SET fk_statut = ".self::STATUS_VALIDATED; - $sql .= " WHERE rowid = ".((int) $this->id); - //$sql .= " AND entity = ".((int) $conf->entity); // Disabled, when we use the ID for the where, we must not add any other search condition - - dol_syslog(get_class($this)."::setValid", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) { - // Call trigger - if (empty($notrigger)) { - $result = $this->call_trigger('PROJECT_VALIDATE', $user); - if ($result < 0) { - $error++; - } - // End call triggers - } - - if (!$error) { - $this->statut = 1; - $this->db->commit(); - return 1; - } else { + if ($this->statut != 1) + { + // Check parameters + if (preg_match('/^'.preg_quote($langs->trans("CopyOf").' ').'/', $this->title)) + { + $this->error = $langs->trans("ErrorFieldFormat", $langs->transnoentities("Label")).'. '.$langs->trans('RemoveString', $langs->transnoentitiesnoconv("CopyOf")); + return -1; + } + + $this->db->begin(); + + $sql = "UPDATE ".MAIN_DB_PREFIX."projet"; + $sql .= " SET fk_statut = 1"; + $sql .= " WHERE rowid = ".$this->id; + $sql .= " AND entity = ".$conf->entity; + + dol_syslog(get_class($this)."::setValid", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) + { + // Call trigger + if (empty($notrigger)) + { + $result = $this->call_trigger('PROJECT_VALIDATE', $user); + if ($result < 0) { $error++; } + // End call triggers + } + + if (!$error) + { + $this->statut = 1; + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + $this->error = join(',', $this->errors); + dol_syslog(get_class($this)."::setValid ".$this->error, LOG_ERR); + return -1; + } + } + else + { @@ -1206,2 +915 @@ - $this->error = join(',', $this->errors); - dol_syslog(get_class($this)."::setValid ".$this->error, LOG_ERR); + $this->error = $this->db->lasterror(); @@ -1210,4 +917,0 @@ - } else { - $this->db->rollback(); - $this->error = $this->db->lasterror(); - return -1; @@ -1221 +925 @@ - * @return int Return integer <0 if KO, 0 if already closed, >0 if OK + * @return int <0 if KO, 0 if already closed, >0 if OK @@ -1231 +935,2 @@ - if ($this->statut != self::STATUS_CLOSED) { + if ($this->statut != self::STATUS_CLOSED) + { @@ -1235,2 +940,2 @@ - $sql .= " SET fk_statut = ".self::STATUS_CLOSED.", fk_user_close = ".((int) $user->id).", date_close = '".$this->db->idate($now)."'"; - $sql .= " WHERE rowid = ".((int) $this->id); + $sql .= " SET fk_statut = ".self::STATUS_CLOSED.", fk_user_close = ".$user->id.", date_close = '".$this->db->idate($now)."'"; + $sql .= " WHERE rowid = ".$this->id; @@ -1239 +944,2 @@ - if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) { + if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) + { @@ -1245 +951,2 @@ - if ($resql) { + if ($resql) + { @@ -1248,3 +955 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) { $error++; } @@ -1253 +958,2 @@ - if (!$error) { + if (!$error) + { @@ -1257 +963,3 @@ - } else { + } + else + { @@ -1263 +971,3 @@ - } else { + } + else + { @@ -1296,4 +1005,0 @@ - - if (is_null($status)) { - return ''; - } @@ -1312,45 +1018 @@ - return dolGetStatus($langs->transnoentitiesnoconv($this->labelStatus[$status]), $langs->transnoentitiesnoconv($this->labelStatusShort[$status]), '', $statusClass, $mode); - } - - /** - * getTooltipContentArray - * - * @param array $params ex option, infologin - * @since v18 - * @return array - */ - public function getTooltipContentArray($params) - { - global $conf, $langs; - - $langs->load('projects'); - $option = $params['option'] ?? ''; - $moreinpopup = $params['moreinpopup'] ?? ''; - - $datas = []; - if ($option != 'nolink') { - $datas['picto'] = img_picto('', $this->picto, 'class="pictofixedwidth"').' '.$langs->trans("Project").''; - } - if (isset($this->status)) { - $datas['picto'] .= ' '.$this->getLibStatut(5); - } - $datas['ref'] = (isset($datas['picto']) ? '
' : '').''.$langs->trans('Ref').': '.$this->ref; // The space must be after the : to not being explode when showing the title in img_picto - $datas['label'] = '
'.$langs->trans('Label').': '.$this->title; // The space must be after the : to not being explode when showing the title in img_picto - if (isset($this->public)) { - $datas['visibility'] = '
'.$langs->trans("Visibility").": "; - $datas['visibility'] .= ($this->public ? img_picto($langs->trans('SharedProject'), 'world', 'class="pictofixedwidth"').$langs->trans("SharedProject") : img_picto($langs->trans('PrivateProject'), 'private', 'class="pictofixedwidth"').$langs->trans("PrivateProject")); - } - if (!empty($this->thirdparty_name)) { - $datas['thirdparty'] = '
'.$langs->trans('ThirdParty').': '.$this->thirdparty_name; // The space must be after the : to not being explode when showing the title in img_picto - } - if (!empty($this->date_start)) { - $datas['datestart'] = '
'.$langs->trans('DateStart').': '.dol_print_date($this->date_start, 'day'); // The space must be after the : to not being explode when showing the title in img_picto - } - if (!empty($this->date_end)) { - $datas['dateend'] = '
'.$langs->trans('DateEnd').': '.dol_print_date($this->date_end, 'day'); // The space must be after the : to not being explode when showing the title in img_picto - } - if ($moreinpopup) { - $datas['moreinpopup'] = '
'.$moreinpopup; - } - - return $datas; + return dolGetStatus($langs->trans($this->statuts_long[$status]), $langs->trans($this->statuts_short[$status]), '', $statusClass, $mode); @@ -1370 +1031,0 @@ - * @param string $save_pageforbacktolist Back to this page 'context:url' @@ -1373 +1034 @@ - public function getNomUrl($withpicto = 0, $option = '', $addlabel = 0, $moreinpopup = '', $sep = ' - ', $notooltip = 0, $save_lastsearch_value = -1, $morecss = '', $save_pageforbacktolist = '') + public function getNomUrl($withpicto = 0, $option = '', $addlabel = 0, $moreinpopup = '', $sep = ' - ', $notooltip = 0, $save_lastsearch_value = -1, $morecss = '') @@ -1377,3 +1038 @@ - if (!empty($conf->dol_no_mouse_hover)) { - $notooltip = 1; // Force disable tooltips - } + if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips @@ -1382 +1041 @@ - if (getDolGlobalString('PROJECT_OPEN_ALWAYS_ON_TAB')) { + if (! empty($conf->global->PROJECT_OPEN_ALWAYS_ON_TAB)) { @@ -1385,14 +1044,20 @@ - $params = [ - 'id' => $this->id, - 'objecttype' => $this->element, - 'moreinpopup' => $moreinpopup, - 'option' => $option, - ]; - $classfortooltip = 'classfortooltip'; - $dataparams = ''; - if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) { - $classfortooltip = 'classforajaxtooltip'; - $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"'; - $label = ''; - } else { - $label = implode($this->getTooltipContentArray($params)); + + $label = ''; + if ($option != 'nolink') $label = ''.$langs->trans("Project").''; + $label .= ($label ? '
' : '').''.$langs->trans('Ref').': '.$this->ref; // The space must be after the : to not being explode when showing the title in img_picto + $label .= ($label ? '
' : '').''.$langs->trans('Label').': '.$this->title; // The space must be after the : to not being explode when showing the title in img_picto + if (isset($this->public)) { + $label .= '
'.$langs->trans("Visibility").": ".($this->public ? $langs->trans("SharedProject") : $langs->trans("PrivateProject")); + } + if (!empty($this->thirdparty_name)) { + $label .= ($label ? '
' : '').''.$langs->trans('ThirdParty').': '.$this->thirdparty_name; // The space must be after the : to not being explode when showing the title in img_picto + } + if (!empty($this->dateo)) { + $label .= ($label ? '
' : '').''.$langs->trans('DateStart').': '.dol_print_date($this->dateo, 'day'); // The space must be after the : to not being explode when showing the title in img_picto + } + if (!empty($this->datee)) { + $label .= ($label ? '
' : '').''.$langs->trans('DateEnd').': '.dol_print_date($this->datee, 'day'); // The space must be after the : to not being explode when showing the title in img_picto + } + if ($moreinpopup) $label .= '
'.$moreinpopup; + if (isset($this->status)) { + $label .= '
'.$langs->trans("Status").": ".$this->getLibStatut(5); @@ -1402 +1067,2 @@ - if ($option != 'nolink') { + if ($option != 'nolink') + { @@ -1405 +1071,3 @@ - } elseif ($option == 'task') { + } + elseif ($option == 'task') + { @@ -1407 +1075,3 @@ - } elseif ($option == 'preview') { + } + elseif ($option == 'preview') + { @@ -1409,3 +1079,3 @@ - } elseif ($option == 'eventorganization') { - $url = DOL_URL_ROOT.'/eventorganization/conferenceorbooth_list.php?projectid='.$this->id; - } else { + } + else + { @@ -1416,10 +1086,2 @@ - if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { - $add_save_lastsearch_values = 1; - } - if ($add_save_lastsearch_values) { - $url .= '&save_lastsearch_values=1'; - } - $add_save_backpagefor = ($save_pageforbacktolist ? 1 : 0); - if ($add_save_backpagefor) { - $url .= "&save_pageforbacktolist=".urlencode($save_pageforbacktolist); - } + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; + if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; @@ -1429,2 +1091,4 @@ - if (empty($notooltip) && $user->hasRight('projet', 'lire')) { - if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) { + if (empty($notooltip) && $user->rights->projet->lire) + { + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) + { @@ -1434,5 +1098,4 @@ - $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"'); - $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"'; - } else { - $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); - } + $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; + $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"'; + } + else $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); @@ -1441,3 +1104 @@ - if (!$this->public) { - $picto = 'project'; - } + if (!$this->public) $picto = 'project'; @@ -1450,6 +1111,2 @@ - if ($withpicto) { - $result .= img_object(($notooltip ? '' : $label), $picto, 'class="pictofixedwidth em088"', 0, 0, $notooltip ? 0 : 1); - } - if ($withpicto != 2) { - $result .= $this->ref; - } + if ($withpicto) $result .= img_object(($notooltip ? '' : $label), $picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + if ($withpicto != 2) $result .= $this->ref; @@ -1457,3 +1114 @@ - if ($withpicto != 2) { - $result .= (($addlabel && $this->title) ? ''.$sep.dol_trunc($this->title, ($addlabel > 1 ? $addlabel : 0)).'' : ''); - } + if ($withpicto != 2) $result .= (($addlabel && $this->title) ? $sep.dol_trunc($this->title, ($addlabel > 1 ? $addlabel : 0)) : ''); @@ -1463 +1118 @@ - $parameters = array('id'=>$this->id, 'getnomurl' => &$result); + $parameters = array('id'=>$this->id, 'getnomurl'=>$result); @@ -1465,5 +1120,2 @@ - if ($reshook > 0) { - $result = $hookmanager->resPrint; - } else { - $result .= $hookmanager->resPrint; - } + if ($reshook > 0) $result = $hookmanager->resPrint; + else $result .= $hookmanager->resPrint; @@ -1490 +1141,0 @@ - $this->entity = $conf->entity; @@ -1498 +1149 @@ - $this->fk_element = 20000; + $this->fk_ele = 20000; @@ -1530 +1181 @@ - public function restrictedProjectArea(User $user, $mode = 'read') + public function restrictedProjectArea($user, $mode = 'read') @@ -1534 +1185,2 @@ - if (($mode == 'read' && $user->hasRight('projet', 'all', 'lire')) || ($mode == 'write' && $user->hasRight('projet', 'all', 'creer')) || ($mode == 'delete' && $user->hasRight('projet', 'all', 'supprimer'))) { + if (($mode == 'read' && !empty($user->rights->projet->all->lire)) || ($mode == 'write' && !empty($user->rights->projet->all->creer)) || ($mode == 'delete' && !empty($user->rights->projet->all->supprimer))) + { @@ -1536 +1188,3 @@ - } elseif ($this->public && (($mode == 'read' && $user->hasRight('projet', 'lire')) || ($mode == 'write' && $user->hasRight('projet', 'creer')) || ($mode == 'delete' && $user->hasRight('projet', 'supprimer')))) { + } + elseif ($this->public && (($mode == 'read' && !empty($user->rights->projet->lire)) || ($mode == 'write' && !empty($user->rights->projet->creer)) || ($mode == 'delete' && !empty($user->rights->projet->supprimer)))) + { @@ -1538,2 +1192,5 @@ - } else { // No access due to permission to read all projects, so we check if we are a contact of project - foreach (array('internal', 'external') as $source) { + } + else + { + foreach (array('internal', 'external') as $source) + { @@ -1544,22 +1201,7 @@ - while ($nblinks < $num) { - if ($source == 'internal' && $user->id == $userRole[$nblinks]['id']) { // $userRole[$nblinks]['id'] is id of user (llx_user) for internal contacts - if ($mode == 'read' && $user->hasRight('projet', 'lire')) { - $userAccess++; - } - if ($mode == 'write' && $user->hasRight('projet', 'creer')) { - $userAccess++; - } - if ($mode == 'delete' && $user->hasRight('projet', 'supprimer')) { - $userAccess++; - } - } - if ($source == 'external' && $user->socid > 0 && $user->socid == $userRole[$nblinks]['socid']) { // $userRole[$nblinks]['id'] is id of contact (llx_socpeople) or external contacts - if ($mode == 'read' && $user->hasRight('projet', 'lire')) { - $userAccess++; - } - if ($mode == 'write' && $user->hasRight('projet', 'creer')) { - $userAccess++; - } - if ($mode == 'delete' && $user->hasRight('projet', 'supprimer')) { - $userAccess++; - } + while ($nblinks < $num) + { + if ($source == 'internal' && preg_match('/^PROJECT/', $userRole[$nblinks]['code']) && $user->id == $userRole[$nblinks]['id']) + { + if ($mode == 'read' && $user->rights->projet->lire) $userAccess++; + if ($mode == 'write' && $user->rights->projet->creer) $userAccess++; + if ($mode == 'delete' && $user->rights->projet->supprimer) $userAccess++; @@ -1590 +1232 @@ - * @return array|string Array of projects id, or string with projects id separated with "," if list is 1 + * @return array or string Array of projects id, or string with projects id separated with "," if list is 1 @@ -1598,6 +1240,11 @@ - $sql .= " FROM ".MAIN_DB_PREFIX."projet as p"; - if ($mode == 0) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_contact as ec ON ec.element_id = p.rowid"; - } elseif ($mode == 1) { - $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec"; - } elseif ($mode == 2) { + $sql.= " FROM " . MAIN_DB_PREFIX . "projet as p"; + if ($mode == 0) + { + $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "element_contact as ec ON ec.element_id = p.rowid"; + } + elseif ($mode == 1) + { + $sql.= ", " . MAIN_DB_PREFIX . "element_contact as ec"; + } + elseif ($mode == 2) + { @@ -1606 +1253 @@ - $sql .= " WHERE p.entity IN (".getEntity('project').")"; + $sql.= " WHERE p.entity IN (".getEntity('project').")"; @@ -1608,4 +1255,2 @@ - //if ($socid || ! $user->rights->societe->client->voir) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).")"; - if ($socid > 0) { - $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).")"; - } + //if ($socid || ! $user->rights->societe->client->voir) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")"; + if ($socid > 0) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = " . $socid . ")"; @@ -1614 +1259 @@ - $listofprojectcontacttype = array(); + $listofprojectcontacttype=array(); @@ -1616,2 +1261,2 @@ - $sql2 .= " WHERE ctc.element = '".$this->db->escape($this->element)."'"; - $sql2 .= " AND ctc.source = 'internal'"; + $sql2.= " WHERE ctc.element = '" . $this->db->escape($this->element) . "'"; + $sql2.= " AND ctc.source = 'internal'"; @@ -1619,23 +1264,27 @@ - if ($resql) { - while ($obj = $this->db->fetch_object($resql)) { - $listofprojectcontacttype[$obj->rowid] = $obj->code; - } - } else { - dol_print_error($this->db); - } - if (count($listofprojectcontacttype) == 0) { - $listofprojectcontacttype[0] = '0'; // To avoid syntax error if not found - } - - if ($mode == 0) { - $sql .= " AND ( p.public = 1"; - $sql .= " OR ( ec.fk_c_type_contact IN (".$this->db->sanitize(join(',', array_keys($listofprojectcontacttype))).")"; - $sql .= " AND ec.fk_socpeople = ".((int) $user->id).")"; - $sql .= " )"; - } elseif ($mode == 1) { - $sql .= " AND ec.element_id = p.rowid"; - $sql .= " AND ("; - $sql .= " ( ec.fk_c_type_contact IN (".$this->db->sanitize(join(',', array_keys($listofprojectcontacttype))).")"; - $sql .= " AND ec.fk_socpeople = ".((int) $user->id).")"; - $sql .= " )"; - } elseif ($mode == 2) { + if ($resql) + { + while($obj = $this->db->fetch_object($resql)) + { + $listofprojectcontacttype[$obj->rowid]=$obj->code; + } + } + else dol_print_error($this->db); + if (count($listofprojectcontacttype) == 0) $listofprojectcontacttype[0]='0'; // To avoid syntax error if not found + + if ($mode == 0) + { + $sql.= " AND ( p.public = 1"; + $sql.= " OR ( ec.fk_c_type_contact IN (".join(',', array_keys($listofprojectcontacttype)).")"; + $sql.= " AND ec.fk_socpeople = ".$user->id.")"; + $sql.= " )"; + } + elseif ($mode == 1) + { + $sql.= " AND ec.element_id = p.rowid"; + $sql.= " AND ("; + $sql.= " ( ec.fk_c_type_contact IN (".join(',', array_keys($listofprojectcontacttype)).")"; + $sql.= " AND ec.fk_socpeople = ".$user->id.")"; + $sql.= " )"; + } + elseif ($mode == 2) + { @@ -1645 +1294 @@ - $sql .= $filter; + $sql.= $filter; @@ -1649 +1298,2 @@ - if ($resql) { + if ($resql) + { @@ -1652 +1302,2 @@ - while ($i < $num) { + while ($i < $num) + { @@ -1661,4 +1312,3 @@ - if ($list) { - if (empty($temp)) { - return '0'; - } + if ($list) + { + if (empty($temp)) return '0'; @@ -1668 +1318,3 @@ - } else { + } + else + { @@ -1709,3 +1361 @@ - if ($newthirdpartyid > 0) { - $clone_project->socid = $newthirdpartyid; - } + if ($newthirdpartyid > 0) $clone_project->socid = $newthirdpartyid; @@ -1720 +1370,2 @@ - if (!(empty($clone_project->date_end))) { + if (!(empty($clone_project->date_end))) + { @@ -1725,3 +1376,4 @@ - $clone_project->date_c = $now; - - if (!$clone_note) { + $clone_project->datec = $now; + + if (!$clone_note) + { @@ -1734 +1386 @@ - $obj = !getDolGlobalString('PROJECT_ADDON') ? 'mod_project_simple' : $conf->global->PROJECT_ADDON; + $obj = empty($conf->global->PROJECT_ADDON) ? 'mod_project_simple' : $conf->global->PROJECT_ADDON; @@ -1736,3 +1388 @@ - $file = ''; - $classname = ''; - $filefound = 0; + $file = ''; $classname = ''; $filefound = 0; @@ -1740 +1390,2 @@ - foreach ($dirmodels as $reldir) { + foreach ($dirmodels as $reldir) + { @@ -1742 +1393,2 @@ - if (file_exists($file)) { + if (file_exists($file)) + { @@ -1745 +1397 @@ - $modProject = new $obj(); + $modProject = new $obj; @@ -1750,3 +1402 @@ - if (is_numeric($defaultref) && $defaultref <= 0) { - $defaultref = ''; - } + if (is_numeric($defaultref) && $defaultref <= 0) $defaultref = ''; @@ -1761 +1411,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -1766 +1417,2 @@ - if (!$error) { + if (!$error) + { @@ -1771 +1423,2 @@ - if (!$clone_note) { + if (!$clone_note) + { @@ -1774 +1427,3 @@ - } else { + } + else + { @@ -1776,2 +1431,3 @@ - $res = $clone_project->update_note(dol_html_entity_decode($clone_project->note_public, ENT_QUOTES | ENT_HTML5), '_public'); - if ($res < 0) { + $res = $clone_project->update_note(dol_html_entity_decode($clone_project->note_public, ENT_QUOTES), '_public'); + if ($res < 0) + { @@ -1781 +1437,3 @@ - } else { + } + else + { @@ -1786,2 +1444,3 @@ - $res = $clone_project->update_note(dol_html_entity_decode($clone_project->note_private, ENT_QUOTES | ENT_HTML5), '_private'); - if ($res < 0) { + $res = $clone_project->update_note(dol_html_entity_decode($clone_project->note_private, ENT_QUOTES), '_private'); + if ($res < 0) + { @@ -1791 +1450,3 @@ - } else { + } + else + { @@ -1797 +1458,2 @@ - if ($clone_contact) { + if ($clone_contact) + { @@ -1801 +1463,2 @@ - foreach (array('internal', 'external') as $source) { + foreach (array('internal', 'external') as $source) + { @@ -1803,6 +1466,15 @@ - if (is_array($tab) && count($tab)>0) { - foreach ($tab as $contacttoadd) { - $clone_project->add_contact($contacttoadd['id'], $contacttoadd['code'], $contacttoadd['source'], $notrigger); - if ($clone_project->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { - $langs->load("errors"); - $this->error .= $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"); + + foreach ($tab as $contacttoadd) + { + $clone_project->add_contact($contacttoadd['id'], $contacttoadd['code'], $contacttoadd['source'], $notrigger); + if ($clone_project->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + $langs->load("errors"); + $this->error .= $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"); + $error++; + } + else + { + if ($clone_project->error != '') + { + $this->error .= $clone_project->error; @@ -1810,5 +1481,0 @@ - } else { - if ($clone_project->error != '') { - $this->error .= $clone_project->error; - $error++; - } @@ -1817,3 +1483,0 @@ - } elseif ($tab < 0) { - $this->error .= $origin_project->error; - $error++; @@ -1825 +1489,2 @@ - if ($clone_project_file) { + if ($clone_project_file) + { @@ -1828,4 +1493,5 @@ - $clone_project_dir = $conf->project->dir_output."/".dol_sanitizeFileName($defaultref); - $ori_project_dir = $conf->project->dir_output."/".dol_sanitizeFileName($orign_project_ref); - - if (dol_mkdir($clone_project_dir) >= 0) { + $clone_project_dir = $conf->projet->dir_output."/".dol_sanitizeFileName($defaultref); + $ori_project_dir = $conf->projet->dir_output."/".dol_sanitizeFileName($orign_project_ref); + + if (dol_mkdir($clone_project_dir) >= 0) + { @@ -1833 +1499,2 @@ - foreach ($filearray as $key => $file) { + foreach ($filearray as $key => $file) + { @@ -1835 +1502,2 @@ - if (is_numeric($rescopy) && $rescopy < 0) { + if (is_numeric($rescopy) && $rescopy < 0) + { @@ -1840 +1508,3 @@ - } else { + } + else + { @@ -1847,2 +1517,3 @@ - if ($clone_task) { - require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php'; + if ($clone_task) + { + require_once DOL_DOCUMENT_ROOT . '/projet/class/task.class.php'; @@ -1853,8 +1524,6 @@ - $socid = 0; - if ($user->socid > 0) { - $socid = $user->socid; - } - - $tasksarray = $taskstatic->getTasksArray(0, 0, $fromid, $socid, 0); - - $tab_conv_child_parent = array(); + $socid=0; + if ($user->socid > 0) $socid = $user->socid; + + $tasksarray=$taskstatic->getTasksArray(0, 0, $fromid, $socid, 0); + + $tab_conv_child_parent=array(); @@ -1863,4 +1532,6 @@ - foreach ($tasksarray as $tasktoclone) { - $result_clone = $taskstatic->createFromClone($user, $tasktoclone->id, $clone_project_id, $tasktoclone->fk_task_parent, $move_date, true, false, $clone_task_file, true, false); - if ($result_clone <= 0) { - $this->error .= $taskstatic->error; + foreach ($tasksarray as $tasktoclone) + { + $result_clone = $taskstatic->createFromClone($user, $tasktoclone->id, $clone_project_id, $tasktoclone->fk_parent, $move_date, true, false, $clone_task_file, true, false); + if ($result_clone <= 0) + { + $this->error .= $result_clone->error; @@ -1868 +1539,3 @@ - } else { + } + else + { @@ -1874 +1547,2 @@ - if (($taskstatic->hasChildren()) && !array_key_exists($tasktoclone->id, $tab_conv_child_parent)) { + if (($taskstatic->hasChildren()) && !array_key_exists($tasktoclone->id, $tab_conv_child_parent)) + { @@ -1882 +1556,2 @@ - foreach ($tasksarray as $task_cloned) { + foreach ($tasksarray as $task_cloned) + { @@ -1884 +1559,2 @@ - if ($taskstatic->fk_task_parent != 0) { + if ($taskstatic->fk_task_parent != 0) + { @@ -1888 +1564,2 @@ - if ($result_clone <= 0) { + if ($result_clone <= 0) + { @@ -1898 +1575,2 @@ - if (!$error) { + if (!$error) + { @@ -1901 +1579,3 @@ - } else { + } + else + { @@ -1919,2 +1599 @@ - $error = 0; - $result = 0; + $error=0; @@ -1925,9 +1604,8 @@ - $socid = 0; - if ($user->socid > 0) { - $socid = $user->socid; - } - - $tasksarray = $taskstatic->getTasksArray(0, 0, $this->id, $socid, 0); - - foreach ($tasksarray as $tasktoshiftdate) { - $to_update = false; + $socid=0; + if ($user->socid > 0) $socid = $user->socid; + + $tasksarray=$taskstatic->getTasksArray(0, 0, $this->id, $socid, 0); + + foreach ($tasksarray as $tasktoshiftdate) + { + $to_update=false; @@ -1935 +1613,2 @@ - if ((!empty($tasktoshiftdate->date_start)) || (!empty($tasktoshiftdate->date_end))) { + if ((!empty($tasktoshiftdate->date_start)) || (!empty($tasktoshiftdate->date_end))) + { @@ -1937 +1616 @@ - $to_update = true; + $to_update=true; @@ -1940 +1619,25 @@ - if (!$result) { + if (!$result) + { + $error++; + $this->error.=$task->error; + } + } + //print "$this->date_start + $tasktoshiftdate->date_start - $old_project_dt_start";exit; + + //Calcultate new task start date with difference between old proj start date and origin task start date + if (!empty($tasktoshiftdate->date_start)) + { + $task->date_start = $this->date_start + ($tasktoshiftdate->date_start - $old_project_dt_start); + } + + //Calcultate new task end date with difference between origin proj end date and origin task end date + if (!empty($tasktoshiftdate->date_end)) + { + $task->date_end = $this->date_start + ($tasktoshiftdate->date_end - $old_project_dt_start); + } + + if ($to_update) + { + $result = $task->update($user); + if (!$result) + { @@ -1945,21 +1648,3 @@ - //print "$this->date_start + $tasktoshiftdate->date_start - $old_project_dt_start";exit; - - //Calcultate new task start date with difference between old proj start date and origin task start date - if (!empty($tasktoshiftdate->date_start)) { - $task->date_start = $this->date_start + ($tasktoshiftdate->date_start - $old_project_dt_start); - } - - //Calcultate new task end date with difference between origin proj end date and origin task end date - if (!empty($tasktoshiftdate->date_end)) { - $task->date_end = $this->date_start + ($tasktoshiftdate->date_end - $old_project_dt_start); - } - - if ($to_update) { - $result = $task->update($user); - if (!$result) { - $error++; - $this->error .= $task->error; - } - } - } - if ($error != 0) { + } + if ($error != 0) + { @@ -1985 +1670,2 @@ - if ($tableName == "actioncomm") { + if ($tableName == "actioncomm") + { @@ -1987,5 +1673,4 @@ - $sql .= " WHERE id=".((int) $elementSelectId); - } elseif (in_array($tableName, ["entrepot","mrp_mo","stocktransfer_stocktransfer"])) { - $sql .= " SET fk_project=".$this->id; - $sql .= " WHERE rowid=".((int) $elementSelectId); - } else { + $sql .= " WHERE id=".$elementSelectId; + } + else + { @@ -1993 +1678 @@ - $sql .= " WHERE rowid=".((int) $elementSelectId); + $sql .= " WHERE rowid=".$elementSelectId; @@ -2021 +1706,2 @@ - if ($tableName == "actioncomm") { + if ($tableName == "actioncomm") + { @@ -2023,2 +1709,3 @@ - $sql .= " WHERE id=".((int) $elementSelectId); - } else { + $sql .= " WHERE id=".$elementSelectId; + } else + { @@ -2026 +1713 @@ - $sql .= " WHERE rowid=".((int) $elementSelectId); + $sql .= " WHERE rowid=".$elementSelectId; @@ -2051 +1738 @@ - global $conf, $langs; + global $conf,$langs; @@ -2055 +1742 @@ - if (!dol_strlen($modele)) { + if (! dol_strlen($modele)) { @@ -2058,3 +1745,3 @@ - if ($this->model_pdf) { - $modele = $this->model_pdf; - } elseif (getDolGlobalString('PROJECT_ADDON_PDF')) { + if ($this->modelpdf) { + $modele = $this->modelpdf; + } elseif (! empty($conf->global->PROJECT_ADDON_PDF)) { @@ -2078 +1765 @@ - * @return int Return integer <0 if OK, >0 if KO + * @return int <0 if OK, >0 if KO @@ -2082,22 +1769,15 @@ - $error = 0; - - $this->weekWorkLoad = array(); - $this->weekWorkLoadPerTask = array(); - - if (empty($datestart)) { - dol_print_error('', 'Error datestart parameter is empty'); - } - - $sql = "SELECT ptt.rowid as taskid, ptt.element_duration, ptt.element_date, ptt.element_datehour, ptt.fk_element"; - $sql .= " FROM ".MAIN_DB_PREFIX."element_time AS ptt, ".MAIN_DB_PREFIX."projet_task as pt"; - $sql .= " WHERE ptt.fk_element = pt.rowid"; - $sql .= " AND ptt.elementtype = 'task'"; - $sql .= " AND pt.fk_projet = ".((int) $this->id); - $sql .= " AND (ptt.element_date >= '".$this->db->idate($datestart)."' "; - $sql .= " AND ptt.element_date <= '".$this->db->idate(dol_time_plus_duree($datestart, 1, 'w') - 1)."')"; - if ($taskid) { - $sql .= " AND ptt.fk_element=".((int) $taskid); - } - if (is_numeric($userid)) { - $sql .= " AND ptt.fk_user=".((int) $userid); - } + $error=0; + + $this->weekWorkLoad=array(); + $this->weekWorkLoadPerTask=array(); + + if (empty($datestart)) dol_print_error('', 'Error datestart parameter is empty'); + + $sql = "SELECT ptt.rowid as taskid, ptt.task_duration, ptt.task_date, ptt.task_datehour, ptt.fk_task"; + $sql.= " FROM ".MAIN_DB_PREFIX."projet_task_time AS ptt, ".MAIN_DB_PREFIX."projet_task as pt"; + $sql.= " WHERE ptt.fk_task = pt.rowid"; + $sql.= " AND pt.fk_projet = ".$this->id; + $sql.= " AND (ptt.task_date >= '".$this->db->idate($datestart)."' "; + $sql.= " AND ptt.task_date <= '".$this->db->idate(dol_time_plus_duree($datestart, 1, 'w') - 1)."')"; + if ($taskid) $sql.= " AND ptt.fk_task=".$taskid; + if (is_numeric($userid)) $sql.= " AND ptt.fk_user=".$userid; @@ -2106,3 +1786,4 @@ - $resql = $this->db->query($sql); - if ($resql) { - $daylareadyfound = array(); + $resql=$this->db->query($sql); + if ($resql) + { + $daylareadyfound=array(); @@ -2113,11 +1794,15 @@ - while ($i < $num) { - $obj = $this->db->fetch_object($resql); - $day = $this->db->jdate($obj->element_date); // task_date is date without hours - if (empty($daylareadyfound[$day])) { - $this->weekWorkLoad[$day] = $obj->element_duration; - $this->weekWorkLoadPerTask[$day][$obj->fk_element] = $obj->element_duration; - } else { - $this->weekWorkLoad[$day] += $obj->element_duration; - $this->weekWorkLoadPerTask[$day][$obj->fk_element] += $obj->element_duration; - } - $daylareadyfound[$day] = 1; + while ($i < $num) + { + $obj=$this->db->fetch_object($resql); + $day=$this->db->jdate($obj->task_date); // task_date is date without hours + if (empty($daylareadyfound[$day])) + { + $this->weekWorkLoad[$day] = $obj->task_duration; + $this->weekWorkLoadPerTask[$day][$obj->fk_task] = $obj->task_duration; + } + else + { + $this->weekWorkLoad[$day] += $obj->task_duration; + $this->weekWorkLoadPerTask[$day][$obj->fk_task] += $obj->task_duration; + } + $daylareadyfound[$day]=1; @@ -2128 +1813,3 @@ - } else { + } + else + { @@ -2142 +1829 @@ - * @return int Return integer <0 if OK, >0 if KO + * @return int <0 if OK, >0 if KO @@ -2151,17 +1838,10 @@ - if (empty($datestart)) { - dol_print_error('', 'Error datestart parameter is empty'); - } - - $sql = "SELECT ptt.rowid as taskid, ptt.element_duration, ptt.element_date, ptt.element_datehour, ptt.fk_element"; - $sql .= " FROM ".MAIN_DB_PREFIX."element_time AS ptt, ".MAIN_DB_PREFIX."projet_task as pt"; - $sql .= " WHERE ptt.fk_element = pt.rowid"; - $sql .= " AND ptt.elementtype = 'task'"; - $sql .= " AND pt.fk_projet = ".((int) $this->id); - $sql .= " AND (ptt.element_date >= '".$this->db->idate($datestart)."' "; - $sql .= " AND ptt.element_date <= '".$this->db->idate(dol_time_plus_duree($datestart, 1, 'm') - 1)."')"; - if ($taskid) { - $sql .= " AND ptt.fk_element=".((int) $taskid); - } - if (is_numeric($userid)) { - $sql .= " AND ptt.fk_user=".((int) $userid); - } + if (empty($datestart)) dol_print_error('', 'Error datestart parameter is empty'); + + $sql = "SELECT ptt.rowid as taskid, ptt.task_duration, ptt.task_date, ptt.task_datehour, ptt.fk_task"; + $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time AS ptt, ".MAIN_DB_PREFIX."projet_task as pt"; + $sql .= " WHERE ptt.fk_task = pt.rowid"; + $sql .= " AND pt.fk_projet = ".$this->id; + $sql .= " AND (ptt.task_date >= '".$this->db->idate($datestart)."' "; + $sql .= " AND ptt.task_date <= '".$this->db->idate(dol_time_plus_duree($datestart, 1, 'm') - 1)."')"; + if ($task_id) $sql .= " AND ptt.fk_task=".$taskid; + if (is_numeric($userid)) $sql .= " AND ptt.fk_user=".$userid; @@ -2171 +1851,2 @@ - if ($resql) { + if ($resql) + { @@ -2177 +1858,2 @@ - while ($i < $num) { + while ($i < $num) + { @@ -2179,2 +1861,2 @@ - if (!empty($obj->element_date)) { - $date = explode('-', $obj->element_date); + if (!empty($obj->task_date)) { + $date = explode('-', $obj->task_date); @@ -2183,6 +1865,9 @@ - if (empty($weekalreadyfound[$week_number])) { - $this->monthWorkLoad[$week_number] = $obj->element_duration; - $this->monthWorkLoadPerTask[$week_number][$obj->fk_element] = $obj->element_duration; - } else { - $this->monthWorkLoad[$week_number] += $obj->element_duration; - $this->monthWorkLoadPerTask[$week_number][$obj->fk_element] += $obj->element_duration; + if (empty($weekalreadyfound[$week_number])) + { + $this->monthWorkLoad[$week_number] = $obj->task_duration; + $this->monthWorkLoadPerTask[$week_number][$obj->fk_task] = $obj->task_duration; + } + else + { + $this->monthWorkLoad[$week_number] += $obj->task_duration; + $this->monthWorkLoadPerTask[$week_number][$obj->fk_task] += $obj->task_duration; @@ -2195 +1880,3 @@ - } else { + } + else + { @@ -2201,0 +1889 @@ + @@ -2207 +1895 @@ - * @return WorkboardResponse|int Return integer <0 if KO, WorkboardResponse if OK + * @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK @@ -2217,8 +1905,2 @@ - $response = new WorkboardResponse(); - $response->warning_delay = $conf->project->warning_delay / 60 / 60 / 24; - $response->label = $langs->trans("OpenedProjects"); - $response->labelShort = $langs->trans("Opened"); - $response->url = DOL_URL_ROOT.'/projet/list.php?search_project_user=-1&search_status=1&mainmenu=project'; - $response->img = img_object('', "projectpub"); - $response->nbtodo = 0; - $response->nbtodolate = 0; + $projectsListId = null; + if (!$user->rights->projet->all->lire) $projectsListId = $this->getProjectsAuthorizedForUser($user, 0, 1); @@ -2234,13 +1916 @@ - - - $projectsListId = null; - if (!$user->hasRight("projet", "all", "lire")) { - $response->url = DOL_URL_ROOT.'/projet/list.php?search_status=1&mainmenu=project'; - $projectsListId = $this->getProjectsAuthorizedForUser($user, 0, 1); - if (empty($projectsListId)) { - return $response; - } - - $sql .= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")"; - } - + if (!empty($projectsListId)) $sql .= " AND p.rowid IN (".$projectsListId.")"; @@ -2248 +1918 @@ - //if ($socid || ! $user->rights->societe->client->voir) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).")"; + //if ($socid || ! $user->rights->societe->client->voir) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")"; @@ -2250 +1920 @@ - //if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id).") OR (s.rowid IS NULL))"; + //if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id.") OR (s.rowid IS NULL))"; @@ -2254 +1924,2 @@ - if ($resql) { + if ($resql) + { @@ -2256,0 +1928,7 @@ + $response = new WorkboardResponse(); + $response->warning_delay = $conf->projet->warning_delay / 60 / 60 / 24; + $response->label = $langs->trans("OpenedProjects"); + $response->labelShort = $langs->trans("Opened"); + if ($user->rights->projet->all->lire) $response->url = DOL_URL_ROOT.'/projet/list.php?search_status=1&mainmenu=project'; + else $response->url = DOL_URL_ROOT.'/projet/list.php?search_project_user=-1&search_status=1&mainmenu=project'; + $response->img = img_object('', "projectpub"); @@ -2259 +1937,2 @@ - while ($obj = $this->db->fetch_object($resql)) { + while ($obj = $this->db->fetch_object($resql)) + { @@ -2263,2 +1942,2 @@ - $project_static->opp_status = $obj->fk_opp_status; - $project_static->date_end = $this->db->jdate($obj->datee); + $project_static->opp_status = $obj->opp_status; + $project_static->datee = $this->db->jdate($obj->datee); @@ -2273,4 +1952,7 @@ - - $this->error = $this->db->error(); - return -1; - } + else + { + $this->error = $this->db->error(); + return -1; + } + } + @@ -2281,3 +1963,3 @@ - * @param DoliDB $dbs Database handler - * @param int $origin_id Old thirdparty id - * @param int $dest_id New thirdparty id + * @param DoliDB $db Database handler + * @param int $origin_id Old thirdparty id + * @param int $dest_id New thirdparty id @@ -2286 +1968 @@ - public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id) + public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id) @@ -2292 +1974 @@ - return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables); + return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables); @@ -2300 +1982 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -2313 +1995,2 @@ - if (!$user->hasRight('projet', 'all', 'lire')) { + if (!$user->rights->projet->all->lire) + { @@ -2315 +1998 @@ - $sql .= "AND p.rowid IN (".$this->db->sanitize($projectsListId).")"; + $sql .= "AND p.rowid IN (".$projectsListId.")"; @@ -2319,2 +2002,4 @@ - if ($resql) { - while ($obj = $this->db->fetch_object($resql)) { + if ($resql) + { + while ($obj = $this->db->fetch_object($resql)) + { @@ -2325 +2010,3 @@ - } else { + } + else + { @@ -2342,6 +2029,2 @@ - if (!($this->statut == self::STATUS_VALIDATED)) { - return false; - } - if (!$this->date_end) { - return false; - } + if (!($this->statut == self::STATUS_VALIDATED)) return false; + if (!$this->datee && !$this->date_end) return false; @@ -2351 +2034 @@ - return ($this->date_end) < ($now - $conf->project->warning_delay); + return ($this->datee ? $this->datee : $this->date_end) < ($now - $conf->projet->warning_delay); @@ -2365 +2048 @@ - $sql .= ' fk_user_creat as fk_user_author, fk_user_close as fk_user_cloture'; + $sql .= ' fk_user_creat as fk_user_author, fk_user_close as fk_use_cloture'; @@ -2367 +2050 @@ - $sql .= ' WHERE c.rowid = '.((int) $id); + $sql .= ' WHERE c.rowid = '.$id; @@ -2369,2 +2052,4 @@ - if ($result) { - if ($this->db->num_rows($result)) { + if ($result) + { + if ($this->db->num_rows($result)) + { @@ -2372 +2056,0 @@ - @@ -2374,3 +2058,13 @@ - - $this->user_creation_id = $obj->fk_user_author; - $this->user_closing_id = $obj->fk_user_cloture; + if ($obj->fk_user_author) + { + $cuser = new User($this->db); + $cuser->fetch($obj->fk_user_author); + $this->user_creation = $cuser; + } + + if ($obj->fk_user_cloture) + { + $cluser = new User($this->db); + $cluser->fetch($obj->fk_user_cloture); + $this->user_cloture = $cluser; + } @@ -2384 +2078,3 @@ - } else { + } + else + { @@ -2396,2 +2092,2 @@ - * @param int[]|int $categories Category or categories IDs - * @return int Return integer <0 if KO, >0 if OK + * @param int[]|int $categories Category or categories IDs + * @return void @@ -2400,0 +2097,8 @@ + $type_categ = Categorie::TYPE_PROJECT; + + // Handle single category + if (!is_array($categories)) { + $categories = array($categories); + } + + // Get current categories @@ -2402,12 +2106,45 @@ - return parent::setCategoriesCommon($categories, Categorie::TYPE_PROJECT); - } - - - /** - * Create an array of tasks of current project - * - * @param User $user Object user we want project allowed to - * @param int $loadRoleMode 1= will test Roles on task; 0 used in delete project action - * @return int >0 if OK, <0 if KO - */ - public function getLinesArray($user, $loadRoleMode = 1) + $c = new Categorie($this->db); + $existing = $c->containing($this->id, $type_categ, 'id'); + + // Diff + if (is_array($existing)) { + $to_del = array_diff($existing, $categories); + $to_add = array_diff($categories, $existing); + } else { + $to_del = array(); // Nothing to delete + $to_add = $categories; + } + + // Process + foreach ($to_del as $del) { + if ($c->fetch($del) > 0) { + $result = $c->del_type($this, $type_categ); + if ($result < 0) { + $this->errors = $c->errors; + $this->error = $c->error; + return -1; + } + } + } + foreach ($to_add as $add) { + if ($c->fetch($add) > 0) { + $result = $c->add_type($this, $type_categ); + if ($result < 0) { + $this->errors = $c->errors; + $this->error = $c->error; + return -1; + } + } + } + + return 1; + } + + + /** + * Create an array of tasks of current project + * + * @param User $user Object user we want project allowed to + * @return int >0 if OK, <0 if KO + */ + public function getLinesArray($user) @@ -2418,135 +2155 @@ - $this->lines = $taskstatic->getTasksArray(0, $user, $this->id, 0, 0, '', '-1', '', 0, 0, array(), 0, array(), 0, $loadRoleMode); - return 1; - } - - /** - * Function sending an email to the current member with the text supplied in parameter. - * - * @param string $text Content of message (not html entities encoded) - * @param string $subject Subject of message - * @param array $filename_list Array of attached files - * @param array $mimetype_list Array of mime types of attached files - * @param array $mimefilename_list Array of public names of attached files - * @param string $addr_cc Email cc - * @param string $addr_bcc Email bcc - * @param int $deliveryreceipt Ask a delivery receipt - * @param int $msgishtml 1=String IS already html, 0=String IS NOT html, -1=Unknown need autodetection - * @param string $errors_to erros to - * @param string $moreinheader Add more html headers - * @since V18 - * @return int Return integer <0 if KO, >0 if OK - */ - public function sendEmail($text, $subject, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array(), $addr_cc = "", $addr_bcc = "", $deliveryreceipt = 0, $msgishtml = -1, $errors_to = '', $moreinheader = '') - { - global $conf, $langs; - // TODO EMAIL - - return 1; - } - /** - * Return clicable link of object (with eventually picto) - * - * @param string $option Where point the link (0=> main card, 1,2 => shipment, 'nolink'=>No link) - * @param array $arraydata Array of data - * @return string HTML Code for Kanban thumb. - */ - public function getKanbanView($option = '', $arraydata = null) - { - global $langs; - - $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']); - - $return = '
'; - $return .= '
'; - $return .= ''; - $return .= img_picto('', $this->public ? 'projectpub' : $this->picto); - //$return .= ''; // Can be image - $return .= ''; - $return .= '
'; - $return .= ''.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref); - if ($this->hasDelay()) { - $return .= img_warning($langs->trans('Late')); - } - $return .= ''; - if ($selected >= 0) { - $return .= ''; - } - // Date - /* - if (property_exists($this, 'date_start') && $this->date_start) { - $return .= '
'.dol_print_date($this->date_start, 'day').''; - } - if (property_exists($this, 'date_end') && $this->date_end) { - if ($this->date_start) { - $return .= ' - '; - } else { - $return .= '
'; - } - $return .= ''.dol_print_date($this->date_end, 'day').''; - }*/ - if (property_exists($this, 'thirdparty') && is_object($this->thirdparty)) { - $return .= '
'.$this->thirdparty->getNomUrl(1); - $return .= '
'; - $return .= dol_print_phone($this->thirdparty->phone, $this->thirdparty->country_code, 0, $this->thirdparty->id, 'tel', 'hidenum', 'phone'); - $return .='
'; - } - if (!empty($arraydata['assignedusers'])) { - $return .= '
'; - if ($this->public) { - $return .= img_picto($langs->trans('Visibility').': '.$langs->trans('SharedProject'), 'world', 'class="paddingrightonly valignmiddle"'); - //print $langs->trans('SharedProject'); - } else { - $return .= img_picto($langs->trans('Visibility').': '.$langs->trans('PrivateProject'), 'private', 'class="paddingrightonly valignmiddle"'); - //print $langs->trans('PrivateProject'); - } - - $return .= ' '.$arraydata['assignedusers'].''; - } - /*if (property_exists($this, 'user_author_id')) { - $return .= '
'.$langs->trans("Author").''; - $return .= ' : '.$user->getNomUrl(1).''; - }*/ - $return .= '
'; // start div line status - if ($this->usage_opportunity && $this->opp_status_code) { - //$return .= '
'.$langs->trans("OpportunityStatusShort").''; - //$return .= '
'.dol_trunc($langs->trans("OppStatus".$this->opp_status_code), 5).'
'; - $return .= '
opp_status_code)).'">'.round($this->opp_percent).'%
'; - $return .= '
'.price($this->opp_amount).'
'; - } - if (method_exists($this, 'getLibStatut')) { - $return .= '
'.$this->getLibStatut(3).'
'; - } - $return .= '
'; // end div line status - - $return .= '
'; - $return .= '
'; - $return .= '
'; - - return $return; - } - - /** - * Return array of sub-projects of the current project - * - * @return array Children of this project as objects with rowid & title as members - */ - public function getChildren() - { - $children = []; - $sql = 'SELECT rowid,title'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'projet'; - $sql .= ' WHERE fk_project = '.((int) $this->id); - $sql .= ' ORDER BY title'; - $result = $this->db->query($sql); - if ($result) { - $n = $this->db->num_rows($result); - while ($n) { - $children[] = $this->db->fetch_object($result); - $n--; - } - $this->db->free($result); - } else { - dol_print_error($this->db); - } - - return $children; + $this->lines = $taskstatic->getTasksArray(0, $user, $this->id, 0, 0); --- /tmp/dsg/dolibarr/htdocs/projet/class/github_19.0.3_projectstats.class.php +++ /tmp/dsg/dolibarr/htdocs/projet/class/client_projectstats.class.php @@ -27,38 +27,19 @@ - private $project; - public $userid; - public $socid; - public $status; - public $opp_status; - - //SQL stat - public $field; - public $from; - public $where; - - - /** - * Constructor - * - * @param DoliDB $db Database handler - */ - public function __construct($db) - { - global $conf, $user; - - $this->db = $db; - - require_once 'project.class.php'; - $this->project = new Project($this->db); - - $this->from = MAIN_DB_PREFIX.$this->project->table_element; - $this->field = 'opp_amount'; - $this->where = " entity = ".$conf->entity; - if ($this->socid > 0) { - $this->where .= " AND fk_soc = ".((int) $this->socid); - } - if (is_array($this->userid) && count($this->userid) > 0) { - $this->where .= ' AND fk_user IN ('.$this->db->sanitize(join(',', $this->userid)).')'; - } elseif ($this->userid > 0) { - $this->where .= " AND fk_user = ".((int) $this->userid); - } - } + private $project; + public $userid; + public $socid; + public $year; + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct($db) + { + global $conf, $user; + + $this->db = $db; + + require_once 'project.class.php'; + $this->project = new Project($this->db); + } @@ -86 +67 @@ - // $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user = ".((int) $user->id); + // $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id; @@ -90,3 +71,3 @@ - //if ($socid > 0) $sql.= " AND t.fk_soc = ".((int) $socid); - // No check is done on company permission because readability is managed by public status of project and assignement. - //if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id).") OR (s.rowid IS NULL))"; + //if ($socid > 0) $sql.= " AND t.fk_soc = ".$socid; + // No check is done on company permission because readability is managed by public status of project and assignement. + //if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id.") OR (s.rowid IS NULL))"; @@ -99 +80 @@ - dol_syslog(get_class($this).'::'.__METHOD__, LOG_DEBUG); + dol_syslog(get_class($this).'::'.__METHOD__."", LOG_DEBUG); @@ -107 +88,2 @@ - if ($i < $limit || $num == $limit) { + if ($i < $limit || $num == $limit) + { @@ -113 +95,2 @@ - } else { + } + else @@ -115,4 +98,3 @@ - } - $i++; - } - if ($num > $limit) { + $i++; + } + if ($num > $limit) @@ -123,2 +105 @@ - } - $this->db->free($resql); + $this->db->free($resql); @@ -152 +133 @@ - // $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user = ".((int) $user->id); + // $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id; @@ -155,3 +136,3 @@ - //if ($socid > 0) $sql.= " AND t.fk_soc = ".((int) $socid); - // No check is done on company permission because readability is managed by public status of project and assignement. - //if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id).") OR (s.rowid IS NULL))"; + //if ($socid > 0) $sql.= " AND t.fk_soc = ".$socid; + // No check is done on company permission because readability is managed by public status of project and assignement. + //if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id.") OR (s.rowid IS NULL))"; @@ -180,3 +161 @@ - if (!$user->hasRight('projet', 'all', 'lire')) { - $projectsListId = $object->getProjectsAuthorizedForUser($user, 0, 1, $user->socid); - } + if (!$user->rights->projet->all->lire) $projectsListId = $object->getProjectsAuthorizedForUser($user, 0, 1, $user->socid); @@ -186,3 +165,2 @@ - if (!empty($this->userid)) { - $sqlwhere[] = ' t.fk_user_resp = '.((int) $this->userid); - } + if (!empty($this->userid)) + $sqlwhere[] = ' t.fk_user_resp='.$this->userid; @@ -191,35 +169,11 @@ - if (!empty($this->socid)) { - $sqlwhere[] = ' t.fk_soc = '.((int) $this->socid); - } - if (!empty($this->year) && empty($this->month)) { - $sqlwhere[] = " t.datec BETWEEN '".$this->db->idate(dol_get_first_day($this->year, 1))."' AND '".$this->db->idate(dol_get_last_day($this->year, 12))."'"; - } - if (!empty($this->year) && !empty($this->month)) { - $sqlwhere[] = " t.datec BETWEEN '".$this->db->idate(dol_get_first_day($this->year, $this->month))."' AND '".$this->db->idate(dol_get_last_day($this->year, $this->month))."'"; - } - - if (!empty($this->status)) { - $sqlwhere[] = " t.fk_statut IN (".$this->db->sanitize($this->status).")"; - } - - if (!empty($this->opp_status)) { - if (is_numeric($this->opp_status) && $this->opp_status > 0) { - $sqlwhere[] = " t.fk_opp_status = ".((int) $this->opp_status); - } - if ($this->opp_status == 'all') { - $sqlwhere[] = " (t.fk_opp_status IS NOT NULL AND t.fk_opp_status <> -1)"; - } - if ($this->opp_status == 'openedopp') { - $sqlwhere[] = " (t.fk_opp_status IS NOT NULL AND t.fk_opp_status <> -1 AND t.fk_opp_status NOT IN (SELECT rowid FROM ".MAIN_DB_PREFIX."c_lead_status WHERE code IN ('WON','LOST')))"; - } - if ($this->opp_status == 'notopenedopp') { - $sqlwhere[] = " (t.fk_opp_status IS NULL OR t.fk_opp_status = -1 OR t.fk_opp_status IN (SELECT rowid FROM ".MAIN_DB_PREFIX."c_lead_status WHERE code = 'WON'))"; - } - if ($this->opp_status == 'none') { - $sqlwhere[] = " (t.fk_opp_status IS NULL OR t.fk_opp_status = -1)"; - } - } - - if (!$user->hasRight('projet', 'all', 'lire')) { - $sqlwhere[] = " t.rowid IN (".$this->db->sanitize($projectsListId).")"; // public and assigned to, or restricted to company for external users - } + if (!empty($this->socid)) + $sqlwhere[] = ' t.fk_soc='.$this->socid; + if (!empty($this->year) && empty($this->yearmonth)) + $sqlwhere[] = " date_format(t.datec,'%Y')='".$this->db->escape($this->year)."'"; + if (!empty($this->yearmonth)) + $sqlwhere[] = " t.datec BETWEEN '".$this->db->idate(dol_get_first_day($this->yearmonth))."' AND '".$this->db->idate(dol_get_last_day($this->yearmonth))."'"; + + if (!empty($this->status)) + $sqlwhere[] = " t.fk_opp_status IN (".$this->status.")"; + + if (!$user->rights->projet->all->lire) $sqlwhere[] = " t.rowid IN (".$projectsListId.")"; // public and assigned to, or restricted to company for external users @@ -243 +197,3 @@ - $this->year = $year; + global $user; + + $this->yearmonth = $year; @@ -249 +205 @@ - // $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user = ".((int) $user->id); + // $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id; @@ -252,0 +209,2 @@ + + $this->yearmonth = 0; @@ -268 +226,3 @@ - $this->year = $year; + global $user; + + $this->yearmonth = $year; @@ -274 +234 @@ - // $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user = ".((int) $user->id); + // $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id; @@ -277,0 +238 @@ + $this->yearmonth = 0; @@ -292 +253 @@ - * @return array|int Array of values or <0 if error + * @return array Array of values @@ -298,3 +259 @@ - if ($startyear > $endyear) { - return -1; - } + if ($startyear > $endyear) return -1; @@ -305 +264,124 @@ - if (!empty($cachedelay)) { + if (!empty($cachedelay)) + { + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.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'; + $newmask = '0644'; + + $nowgmt = dol_now(); + + $foundintocache = 0; + if ($cachedelay > 0) + { + $filedate = dol_filemtime($newpathofdestfile); + if ($filedate >= ($nowgmt - $cachedelay)) + { + $foundintocache = 1; + + $this->lastfetchdate[get_class($this).'_'.__FUNCTION__] = $filedate; + } + 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."); + } + } + + // Load file into $data + if ($foundintocache) // Cache file found and is not too old + { + dol_syslog(get_class($this).'::'.__FUNCTION__." read data from cache file ".$newpathofdestfile." ".$filedate."."); + $data = json_decode(file_get_contents($newpathofdestfile), true); + } + else + { + $year = $startyear; + while ($year <= $endyear) + { + $datay[$year] = $this->getWeightedAmountByMonth($year, $wonlostfilter); + $year++; + } + + $data = array(); + // $data = array('xval'=>array(0=>xlabel,1=>yval1,2=>yval2...),...) + for ($i = 0; $i < 12; $i++) + { + $data[$i][] = $datay[$endyear][$i][0]; // set label + $year = $startyear; + while ($year <= $endyear) + { + $data[$i][] = $datay[$year][$i][1]; // set yval for x=i + $year++; + } + } + } + + // Save cache file + if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1)) + { + dol_syslog(get_class($this).'::'.__FUNCTION__." save cache file ".$newpathofdestfile." onto disk."); + if (!dol_is_dir($conf->user->dir_temp)) dol_mkdir($conf->user->dir_temp); + $fp = fopen($newpathofdestfile, 'w'); + if ($fp) + { + fwrite($fp, json_encode($data)); + fclose($fp); + if (!empty($conf->global->MAIN_UMASK)) $newmask = $conf->global->MAIN_UMASK; + @chmod($newpathofdestfile, octdec($newmask)); + } + else dol_syslog("Failed to write cache file", LOG_ERR); + $this->lastfetchdate[get_class($this).'_'.__FUNCTION__] = $nowgmt; + } + + return $data; + } + + + /** + * Return the Project weighted opp amount by month for a year. + * + * @param int $year Year to scan + * @param int $wonlostfilter Add a filter on status won/lost + * @return array Array with amount by month + */ + public function getWeightedAmountByMonth($year, $wonlostfilter = 1) + { + global $user; + + $this->yearmonth = $year; + + $sql = "SELECT date_format(t.datec,'%m') as dm, SUM(t.opp_amount * ".$this->db->ifsql("t.opp_percent IS NULL".($wonlostfilter ? " OR cls.code IN ('WON','LOST')" : ""), '0', 't.opp_percent')." / 100)"; + $sql .= " FROM ".MAIN_DB_PREFIX."projet as t LEFT JOIN ".MAIN_DB_PREFIX.'c_lead_status as cls ON t.fk_opp_status = cls.rowid'; + // 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 .= " GROUP BY dm"; + $sql .= $this->db->order('dm', 'DESC'); + $this->yearmonth = 0; + + $res = $this->_getAmountByMonth($year, $sql); + // var_dump($res);print '
'; + return $res; + } + + /** + * Return amount of elements by month for several years + * + * @param int $endyear End year + * @param int $startyear Start year + * @param int $cachedelay accept for cache file (0=No read, no save of cache, -1=No read but save) + * @return array of values + */ + public function getTransformRateByMonthWithPrevYear($endyear, $startyear, $cachedelay = 0) + { + global $conf, $user, $langs; + + if ($startyear > $endyear) return -1; + + $datay = array(); + + // Search into cache + if (!empty($cachedelay)) + { @@ -328 +410,2 @@ - if ($foundintocache) { // Cache file found and is not too old + if ($foundintocache) // Cache file found and is not too old + { @@ -334 +417 @@ - $datay[$year] = $this->getWeightedAmountByMonth($year, $wonlostfilter); + $datay[$year] = $this->getTransformRateByMonth($year); @@ -351,110 +433,0 @@ - if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1)) { - dol_syslog(get_class($this).'::'.__FUNCTION__." save cache file ".$newpathofdestfile." onto disk."); - if (!dol_is_dir($conf->user->dir_temp)) { - dol_mkdir($conf->user->dir_temp); - } - $fp = fopen($newpathofdestfile, 'w'); - if ($fp) { - fwrite($fp, json_encode($data)); - fclose($fp); - dolChmod($newpathofdestfile); - } else { - dol_syslog("Failed to write cache file", LOG_ERR); - } - $this->lastfetchdate[get_class($this).'_'.__FUNCTION__] = $nowgmt; - } - - return $data; - } - - - /** - * Return the Project weighted opp amount by month for a year. - * - * @param int $year Year to scan - * @param int $wonlostfilter Add a filter on status won/lost - * @return array Array with amount by month - */ - public function getWeightedAmountByMonth($year, $wonlostfilter = 1) - { - $this->year = $year; - - $sql = "SELECT date_format(t.datec,'%m') as dm, SUM(t.opp_amount * ".$this->db->ifsql("t.opp_percent IS NULL".($wonlostfilter ? " OR cls.code IN ('WON','LOST')" : ""), '0', 't.opp_percent')." / 100)"; - $sql .= " FROM ".MAIN_DB_PREFIX."projet as t LEFT JOIN ".MAIN_DB_PREFIX.'c_lead_status as cls ON t.fk_opp_status = cls.rowid'; - // 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 = ".((int) $user->id); - $sql .= $this->buildWhere(); - $sql .= " GROUP BY dm"; - $sql .= $this->db->order('dm', 'DESC'); - - $res = $this->_getAmountByMonth($year, $sql); - // var_dump($res);print '
'; - return $res; - } - - /** - * Return amount of elements by month for several years - * - * @param int $endyear End year - * @param int $startyear Start year - * @param int $cachedelay accept for cache file (0=No read, no save of cache, -1=No read but save) - * @return array|int Array of values or <0 if error - */ - public function getTransformRateByMonthWithPrevYear($endyear, $startyear, $cachedelay = 0) - { - global $conf, $user, $langs; - - if ($startyear > $endyear) { - return -1; - } - - $datay = array(); - - // Search into cache - if (!empty($cachedelay)) { - include_once DOL_DOCUMENT_ROOT.'/core/lib/files.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'; - $newmask = '0644'; - - $nowgmt = dol_now(); - - $foundintocache = 0; - if ($cachedelay > 0) { - $filedate = dol_filemtime($newpathofdestfile); - if ($filedate >= ($nowgmt - $cachedelay)) { - $foundintocache = 1; - - $this->lastfetchdate[get_class($this).'_'.__FUNCTION__] = $filedate; - } 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."); - } - } - - // Load file into $data - if ($foundintocache) { // Cache file found and is not too old - dol_syslog(get_class($this).'::'.__FUNCTION__." read data from cache file ".$newpathofdestfile." ".$filedate."."); - $data = json_decode(file_get_contents($newpathofdestfile), true); - } else { - $year = $startyear; - while ($year <= $endyear) { - $datay[$year] = $this->getTransformRateByMonth($year); - $year++; - } - - $data = array(); - // $data = array('xval'=>array(0=>xlabel,1=>yval1,2=>yval2...),...) - for ($i = 0; $i < 12; $i++) { - $data[$i][] = $datay[$endyear][$i][0]; // set label - $year = $startyear; - while ($year <= $endyear) { - $data[$i][] = $datay[$year][$i][1]; // set yval for x=i - $year++; - } - } - } - - // Save cache file @@ -463 +436 @@ - if (!dol_is_dir($conf->user->dir_temp)) { + if (!dol_is_dir($conf->user->dir_temp)) @@ -465 +437,0 @@ - } @@ -467,5 +439,5 @@ - if ($fp) { - fwrite($fp, json_encode($data)); - fclose($fp); - dolChmod($newpathofdestfile); - } + fwrite($fp, json_encode($data)); + fclose($fp); + if (!empty($conf->global->MAIN_UMASK)) + $newmask = $conf->global->MAIN_UMASK; + @chmod($newpathofdestfile, octdec($newmask)); @@ -488 +460,3 @@ - $this->year = $year; + global $user; + + $this->yearmonth = $year; @@ -494 +468 @@ - // $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user = ".((int) $user->id); + // $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id; @@ -507 +481 @@ - // $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user = ".((int) $user->id); + // $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id; @@ -512,0 +487 @@ + $this->yearmonth = 0; @@ -518 +493 @@ - foreach ($res_total as $key => $total_row) { + foreach ($res_total as $key=>$total_row) { @@ -529,17 +503,0 @@ - - /** - * Return average of entity by month - * @param int $year year number - * @return array - */ - protected function getAverageByMonth($year) - { - $sql = "SELECT date_format(datef,'%m') as dm, AVG(f.".$this->field.")"; - $sql .= " FROM ".$this->from; - $sql .= " WHERE f.datef BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; - $sql .= " AND ".$this->where; - $sql .= " GROUP BY dm"; - $sql .= $this->db->order('dm', 'DESC'); - - return $this->_getAverageByMonth($year, $sql); - } --- /tmp/dsg/dolibarr/htdocs/projet/class/github_19.0.3_task.class.php +++ /tmp/dsg/dolibarr/htdocs/projet/class/client_task.class.php @@ -5 +5 @@ - * Copyright (C) 2018-2023 Frédéric France + * Copyright (C) 2018 Frédéric France @@ -7,2 +6,0 @@ - * Copyright (C) 2022 Charlene Benke - * Copyright (C) 2023 Gauthier VERDOL @@ -31 +28,0 @@ -require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php'; @@ -33 +29,0 @@ -require_once DOL_DOCUMENT_ROOT.'/core/class/timespent.class.php'; @@ -39 +35 @@ -class Task extends CommonObjectLine +class Task extends CommonObject @@ -47 +43 @@ - * @var string Name of table without prefix where object is stored + * @var string Name of table without prefix where object is stored @@ -52,8 +48,8 @@ - * @var string Field with ID of parent key if this field has a parent - */ - public $fk_element = 'fk_element'; - - /** - * @var string String with name of icon for myobject. - */ - public $picto = 'projecttask'; + * @var int Field with ID of parent key if this field has a parent + */ + public $fk_element = 'fk_task'; + + /** + * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png + */ + public $picto = 'task'; @@ -64,13 +60,11 @@ - protected $childtables = array( - 'element_time' => array('name' => 'Task', 'parent' => 'projet_task', 'parentkey' => 'fk_element', 'parenttypefield' => 'elementtype', 'parenttypevalue' => 'task') - ); - - /** - * @var int ID parent task - */ - public $fk_task_parent = 0; - - /** - * @var string Label of task - */ - public $label; + protected $childtables = array('projet_task_time'); + + /** + * @var int ID parent task + */ + public $fk_task_parent; + + /** + * @var string Label of task + */ + public $label; @@ -91,7 +85,2 @@ - * @deprecated Use date_end instead - */ - public $datee; - - /** - * @var int ID - */ + * @var int ID + */ @@ -103,2 +92,2 @@ - * @var int ID - */ + * @var int ID + */ @@ -108,2 +97,2 @@ - * @var int ID - */ + * @var int ID + */ @@ -130 +118,0 @@ - public $timespent_thm; @@ -132,3 +119,0 @@ - public $timespent_fk_product; - public $timespent_invoiceid; - public $timespent_invoicelineid; @@ -138,47 +123 @@ - /** - * @var array - */ - public $labelStatus; - - /** - * @var array - */ - public $labelStatusShort; - - // Properties calculated from sum of llx_element_time linked to task - public $tobill; - public $billed; - - // Properties to store project informations - public $projectref; - public $projectstatus; - public $projectlabel; - public $opp_amount; - public $opp_percent; - public $fk_opp_status; - public $usage_bill_time; - public $public; - public $array_options_project; - - // Properties to store thirdparty of project information - public $socid; - public $thirdparty_id; - public $thirdparty_name; - public $thirdparty_email; - - // store parent ref and position - public $task_parent_ref; - public $task_parent_position; - - - - /** - * @var float budget_amount - */ - public $budget_amount; - - /** - * @var float project_budget_amount - */ - public $project_budget_amount; - + public $oldcopy; @@ -203 +142 @@ - * @return int Return integer <0 if KO, Id of created object if OK + * @return int <0 if KO, Id of created object if OK @@ -208,3 +146,0 @@ - - //For the date - $now = dol_now(); @@ -217,7 +152,0 @@ - $this->note_public = trim($this->note_public); - $this->note_private = trim($this->note_private); - - if (!empty($this->date_start) && !empty($this->date_end) && $this->date_start > $this->date_end) { - $this->errors[] = $langs->trans('StartDateCannotBeAfterEndDate'); - return -1; - } @@ -236,2 +164,0 @@ - $sql .= ", note_public"; - $sql .= ", note_private"; @@ -244,2 +170,0 @@ - $sql .= ", budget_amount"; - $sql .= ", priority"; @@ -247,2 +172,2 @@ - $sql .= (!empty($this->entity) ? (int) $this->entity : (int) $conf->entity); - $sql .= ", ".((int) $this->fk_project); + $sql .= $conf->entity; + $sql .= ", ".$this->fk_project; @@ -250 +175 @@ - $sql .= ", ".((int) $this->fk_task_parent); + $sql .= ", ".$this->fk_task_parent; @@ -253,10 +178,6 @@ - $sql .= ", '".$this->db->escape($this->note_public)."'"; - $sql .= ", '".$this->db->escape($this->note_private)."'"; - $sql .= ", '".$this->db->idate($now)."'"; - $sql .= ", ".((int) $user->id); - $sql .= ", ".($this->date_start ? "'".$this->db->idate($this->date_start)."'" : 'null'); - $sql .= ", ".($this->date_end ? "'".$this->db->idate($this->date_end)."'" : 'null'); - $sql .= ", ".(($this->planned_workload != '' && $this->planned_workload >= 0) ? ((int) $this->planned_workload) : 'null'); - $sql .= ", ".(($this->progress != '' && $this->progress >= 0) ? ((int) $this->progress) : 'null'); - $sql .= ", ".(($this->budget_amount != '' && $this->budget_amount >= 0) ? ((int) $this->budget_amount) : 'null'); - $sql .= ", ".(($this->priority != '' && $this->priority >= 0) ? (int) $this->priority : 'null'); + $sql .= ", '".$this->db->idate($this->date_c)."'"; + $sql .= ", ".$user->id; + $sql .= ", ".($this->date_start != '' ? "'".$this->db->idate($this->date_start)."'" : 'null'); + $sql .= ", ".($this->date_end != '' ? "'".$this->db->idate($this->date_end)."'" : 'null'); + $sql .= ", ".(($this->planned_workload != '' && $this->planned_workload >= 0) ? $this->planned_workload : 'null'); + $sql .= ", ".(($this->progress != '' && $this->progress >= 0) ? $this->progress : 'null'); @@ -269,6 +190,4 @@ - if (!$resql) { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); - } - - if (!$error) { + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + + if (!$error) + { @@ -276,9 +195,3 @@ - // Update extrafield - $result = $this->insertExtraFields(); - if ($result < 0) { - $error++; - } - } - - if (!$error) { - if (!$notrigger) { + + if (!$notrigger) + { @@ -287 +200,13 @@ - if ($result < 0) { + if ($result < 0) { $error++; } + // End call triggers + } + } + + // Update extrafield + if (!$error) + { + if (!$error) + { + $result = $this->insertExtraFields(); + if ($result < 0) + { @@ -290 +214,0 @@ - // End call triggers @@ -295,2 +219,4 @@ - if ($error) { - foreach ($this->errors as $errmsg) { + if ($error) + { + foreach ($this->errors as $errmsg) + { @@ -302 +228,3 @@ - } else { + } + else + { @@ -315 +243 @@ - * @return int Return integer <0 if KO, 0 if not found, >0 if OK + * @return int <0 if KO, 0 if not found, >0 if OK @@ -324 +251,0 @@ - $sql .= " t.entity,"; @@ -338 +264,0 @@ - $sql .= " t.budget_amount,"; @@ -343 +269,2 @@ - if (!empty($loadparentdata)) { + if (!empty($loadparentdata)) + { @@ -348,3 +275 @@ - if (!empty($loadparentdata)) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t2 ON t.fk_task_parent = t2.rowid"; - } + if (!empty($loadparentdata)) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t2 ON t.fk_task_parent = t2.rowid"; @@ -353,2 +278 @@ - $sql .= "entity IN (".getEntity('project').")"; - $sql .= " AND t.ref = '".$this->db->escape($ref)."'"; + $sql .= "t.ref = '".$this->db->escape($ref)."'"; @@ -356 +280 @@ - $sql .= "t.rowid = ".((int) $id); + $sql .= "t.rowid = ".$id; @@ -361 +285,2 @@ - if ($resql) { + if ($resql) + { @@ -364 +289,2 @@ - if ($num_rows) { + if ($num_rows) + { @@ -369 +294,0 @@ - $this->entity = $obj->entity; @@ -383 +307,0 @@ - $this->budget_amount = $obj->budget_amount; @@ -389 +313,2 @@ - if (!empty($loadparentdata)) { + if (!empty($loadparentdata)) + { @@ -394 +319 @@ - // Retrieve all extrafield + // Retreive all extrafield @@ -400 +325,2 @@ - if ($num_rows) { + if ($num_rows) + { @@ -405 +331,3 @@ - } else { + } + else + { @@ -417 +345 @@ - * @return int Return integer <=0 if KO, >0 if OK + * @return int <=0 if KO, >0 if OK @@ -425,35 +353,7 @@ - if (isset($this->fk_project)) { - $this->fk_project = trim($this->fk_project); - } - if (isset($this->ref)) { - $this->ref = trim($this->ref); - } - if (isset($this->fk_task_parent)) { - $this->fk_task_parent = (int) $this->fk_task_parent; - } - if (isset($this->label)) { - $this->label = trim($this->label); - } - if (isset($this->description)) { - $this->description = trim($this->description); - } - if (isset($this->note_public)) { - $this->note_public = trim($this->note_public); - } - if (isset($this->note_private)) { - $this->note_private = trim($this->note_private); - } - if (isset($this->duration_effective)) { - $this->duration_effective = trim($this->duration_effective); - } - if (isset($this->planned_workload)) { - $this->planned_workload = trim($this->planned_workload); - } - if (isset($this->budget_amount)) { - $this->budget_amount = trim($this->budget_amount); - } - - if (!empty($this->date_start) && !empty($this->date_end) && $this->date_start > $this->date_end) { - $this->errors[] = $langs->trans('StartDateCannotBeAfterEndDate'); - return -1; - } + if (isset($this->fk_project)) $this->fk_project = trim($this->fk_project); + if (isset($this->ref)) $this->ref = trim($this->ref); + if (isset($this->fk_task_parent)) $this->fk_task_parent = (int) $this->fk_task_parent; + if (isset($this->label)) $this->label = trim($this->label); + if (isset($this->description)) $this->description = trim($this->description); + if (isset($this->duration_effective)) $this->duration_effective = trim($this->duration_effective); + if (isset($this->planned_workload)) $this->planned_workload = trim($this->planned_workload); @@ -471,2 +370,0 @@ - $sql .= " note_public=".(isset($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null").","; - $sql .= " note_private=".(isset($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null").","; @@ -478,4 +376,2 @@ - $sql .= " budget_amount=".(($this->budget_amount != '' && $this->budget_amount >= 0) ? $this->budget_amount : 'null').","; - $sql .= " rang=".((!empty($this->rang)) ? ((int) $this->rang) : "0").","; - $sql .= " priority=".((!empty($this->priority)) ? ((int) $this->priority) : "0"); - $sql .= " WHERE rowid=".((int) $this->id); + $sql .= " rang=".((!empty($this->rang)) ? $this->rang : "0"); + $sql .= " WHERE rowid=".$this->id; @@ -487,4 +383 @@ - if (!$resql) { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); - } + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } @@ -494,24 +387,6 @@ - $result = $this->insertExtraFields(); - if ($result < 0) { - $error++; - } - } - - if (!$error && getDolGlobalString('PROJECT_CLASSIFY_CLOSED_WHEN_ALL_TASKS_DONE')) { - // Close the parent project if it is open (validated) and its tasks are 100% completed - $project = new Project($this->db); - if ($project->fetch($this->fk_project) > 0) { - if ($project->statut == Project::STATUS_VALIDATED) { - $project->getLinesArray(null); // this method does not return <= 0 if fails - $projectCompleted = array_reduce( - $project->lines, - function ($allTasksCompleted, $task) { - return $allTasksCompleted && $task->progress >= 100; - }, - 1 - ); - if ($projectCompleted) { - if ($project->setClose($user) <= 0) { - $error++; - } - } + if (!$error) + { + $result = $this->insertExtraFields(); + if ($result < 0) + { + $error++; @@ -519,10 +394,7 @@ - } else { - $error++; - } - if ($error) { - $this->errors[] = $project->error; - } - } - - if (!$error) { - if (!$notrigger) { + } + } + + if (!$error) + { + if (!$notrigger) + { @@ -531,3 +403 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) { $error++; } @@ -538 +408,2 @@ - if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref)) { + if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref)) + { @@ -540 +411,2 @@ - if ($conf->project->dir_output) { + if ($conf->projet->dir_output) + { @@ -544,3 +416,4 @@ - $olddir = $conf->project->dir_output.'/'.dol_sanitizeFileName($project->ref).'/'.dol_sanitizeFileName($this->oldcopy->ref); - $newdir = $conf->project->dir_output.'/'.dol_sanitizeFileName($project->ref).'/'.dol_sanitizeFileName($this->ref); - if (file_exists($olddir)) { + $olddir = $conf->projet->dir_output.'/'.dol_sanitizeFileName($project->ref).'/'.dol_sanitizeFileName($this->oldcopy->ref); + $newdir = $conf->projet->dir_output.'/'.dol_sanitizeFileName($project->ref).'/'.dol_sanitizeFileName($this->ref); + if (file_exists($olddir)) + { @@ -548,2 +421,3 @@ - $res = dol_move_dir($olddir, $newdir); - if (!$res) { + $res = dol_move($olddir, $newdir); + if (!$res) + { @@ -559,2 +433,4 @@ - if ($error) { - foreach ($this->errors as $errmsg) { + if ($error) + { + foreach ($this->errors as $errmsg) + { @@ -566 +442,3 @@ - } else { + } + else + { @@ -578 +456 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -581,0 +460 @@ + @@ -589 +468,2 @@ - if ($this->hasChildren() > 0) { + if ($this->hasChildren() > 0) + { @@ -597 +477,2 @@ - if (!empty($objectisused)) { + if (!empty($objectisused)) + { @@ -604 +485,2 @@ - if (!$error) { + if (!$error) + { @@ -607 +489,2 @@ - if ($res < 0) { + if ($res < 0) + { @@ -615,3 +498,4 @@ - if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_time"; - $sql .= " WHERE fk_element = ".((int) $this->id)." AND elementtype = 'task'"; + if (!$error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet_task_time"; + $sql .= " WHERE fk_task=".$this->id; @@ -620,7 +504,5 @@ - if (!$resql) { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); - } - } - - if (!$error) { + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + } + + if (!$error) + { @@ -628 +510 @@ - $sql .= " WHERE fk_object = ".((int) $this->id); + $sql .= " WHERE fk_object=".$this->id; @@ -631,7 +513,5 @@ - if (!$resql) { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); - } - } - - if (!$error) { + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + } + + if (!$error) + { @@ -639 +519 @@ - $sql .= " WHERE rowid=".((int) $this->id); + $sql .= " WHERE rowid=".$this->id; @@ -642,8 +522,7 @@ - if (!$resql) { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); - } - } - - if (!$error) { - if (!$notrigger) { + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + } + + if (!$error) + { + if (!$notrigger) + { @@ -652,3 +531 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) { $error++; } @@ -660,2 +537,4 @@ - if ($error) { - foreach ($this->errors as $errmsg) { + if ($error) + { + foreach ($this->errors as $errmsg) + { @@ -667 +546,3 @@ - } else { + } + else + { @@ -669 +550,2 @@ - if ($conf->project->dir_output) { + if ($conf->projet->dir_output) + { @@ -673 +555 @@ - $dir = $conf->project->dir_output."/".dol_sanitizeFileName($projectstatic->ref).'/'.dol_sanitizeFileName($this->id); + $dir = $conf->projet->dir_output."/".dol_sanitizeFileName($projectstatic->ref).'/'.dol_sanitizeFileName($this->id); @@ -675 +557,2 @@ - if (file_exists($dir)) { + if (file_exists($dir)) + { @@ -678 +561,2 @@ - if (!$res) { + if (!$res) + { @@ -695 +579 @@ - * @return int Return integer <0 if KO, 0 if no children, >0 if OK + * @return int <0 if KO, 0 if no children, >0 if OK @@ -704 +588 @@ - $sql .= " WHERE fk_task_parent = ".((int) $this->id); + $sql .= " WHERE fk_task_parent=".$this->id; @@ -708,4 +592,3 @@ - if (!$resql) { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); - } else { + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + else + { @@ -713,3 +596 @@ - if ($obj) { - $ret = $obj->nb; - } + if ($obj) $ret = $obj->nb; @@ -719 +600,2 @@ - if (!$error) { + if (!$error) + { @@ -721 +603,3 @@ - } else { + } + else + { @@ -729 +613 @@ - * @return int Return integer <0 if KO, 0 if no children, >0 if OK + * @return int <0 if KO, 0 if no children, >0 if OK @@ -737,3 +621,2 @@ - $sql .= " FROM ".MAIN_DB_PREFIX."element_time"; - $sql .= " WHERE fk_element = ".((int) $this->id); - $sql .= " AND elementtype = 'task'"; + $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time"; + $sql .= " WHERE fk_task=".$this->id; @@ -743,4 +626,3 @@ - if (!$resql) { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); - } else { + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + else + { @@ -748,3 +630 @@ - if ($obj) { - $ret = $obj->nb; - } + if ($obj) $ret = $obj->nb; @@ -754 +634,2 @@ - if (!$error) { + if (!$error) + { @@ -756 +637,3 @@ - } else { + } + else + { @@ -761,28 +643,0 @@ - - /** - * getTooltipContentArray - * - * @param array $params ex option, infologin - * @since v18 - * @return array - */ - public function getTooltipContentArray($params) - { - global $langs; - - $langs->load('projects'); - - $datas = []; - $datas['picto'] = img_picto('', $this->picto).' '.$langs->trans("Task").''; - if (!empty($this->ref)) { - $datas['ref'] = '
'.$langs->trans('Ref').': '.$this->ref; - } - if (!empty($this->label)) { - $datas['label'] = '
'.$langs->trans('LabelTask').': '.$this->label; - } - if ($this->date_start || $this->date_end) { - $datas['range'] = "
".get_date_range($this->date_start, $this->date_end, '', $langs, 0); - } - - return $datas; - } @@ -804,5 +659,3 @@ - global $action, $conf, $hookmanager, $langs; - - if (!empty($conf->dol_no_mouse_hover)) { - $notooltip = 1; // Force disable tooltips - } + global $conf, $langs, $user; + + if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips @@ -811,12 +664,8 @@ - $params = [ - 'id' => $this->id, - 'objecttype' => $this->element, - ]; - $classfortooltip = 'classfortooltip'; - $dataparams = ''; - if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) { - $classfortooltip = 'classforajaxtooltip'; - $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"'; - $label = ''; - } else { - $label = implode($this->getTooltipContentArray($params)); + $label = ''.$langs->trans("ShowTask").''; + if (!empty($this->ref)) + $label .= '
'.$langs->trans('Ref').': '.$this->ref; + if (!empty($this->label)) + $label .= '
'.$langs->trans('LabelTask').': '.$this->label; + if ($this->date_start || $this->date_end) + { + $label .= "
".get_date_range($this->date_start, $this->date_end, '', $langs, 0); @@ -828,6 +677,2 @@ - if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { - $add_save_lastsearch_values = 1; - } - if ($add_save_lastsearch_values) { - $url .= '&save_lastsearch_values=1'; - } + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; + if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; @@ -836,2 +681,4 @@ - if (empty($notooltip)) { - if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) { + if (empty($notooltip)) + { + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) + { @@ -841,4 +688,2 @@ - $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"'); - $linkclose .= $dataparams.' class="'.$classfortooltip.' nowraponall"'; - } else { - $linkclose .= ' class="nowraponall"'; + $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; + $linkclose .= ' class="classfortooltip"'; @@ -854,6 +699,2 @@ - if ($withpicto) { - $result .= img_object(($notooltip ? '' : $label), $picto, 'class="paddingright"', 0, 0, $notooltip ? 0 : 1); - } - if ($withpicto != 2) { - $result .= $this->ref; - } + if ($withpicto) $result .= img_object(($notooltip ? '' : $label), $picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + if ($withpicto != 2) $result .= $this->ref; @@ -861,11 +702 @@ - if ($withpicto != 2) { - $result .= (($addlabel && $this->label) ? $sep.dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : ''); - } - - $parameters = array('id'=>$this->id, 'getnomurl' => &$result); - $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook > 0) { - $result = $hookmanager->resPrint; - } else { - $result .= $hookmanager->resPrint; - } + if ($withpicto != 2) $result .= (($addlabel && $this->label) ? $sep.dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : ''); @@ -894 +724,0 @@ - $this->priority = 0; @@ -903,20 +733,16 @@ - * @param User $usert Object user to limit tasks affected to a particular user - * @param User $userp Object user to limit projects of a particular user and public projects - * @param int $projectid Project id - * @param int $socid Third party id - * @param int $mode 0=Return list of tasks and their projects, 1=Return projects and tasks if exists - * @param string $filteronproj Filter on project ref or label - * @param string $filteronprojstatus Filter on project status ('-1'=no filter, '0,1'=Draft+Validated only) - * @param string $morewherefilter Add more filter into where SQL request (must start with ' AND ...') - * @param string $filteronprojuser Filter on user that is a contact of project - * @param string $filterontaskuser Filter on user assigned to task - * @param Extrafields $extrafields Show additional column from project or task - * @param int $includebilltime Calculate also the time to bill and billed - * @param array $search_array_options Array of search filters. Not Used yet. - * @param int $loadextras Fetch all Extrafields on each project and task - * @param int $loadRoleMode 1= will test Roles on task; 0 used in delete project action - * @param string $sortfield Sort field - * @param string $sortorder Sort order - * @return array|string Array of tasks - */ - public function getTasksArray($usert = null, $userp = null, $projectid = 0, $socid = 0, $mode = 0, $filteronproj = '', $filteronprojstatus = '-1', $morewherefilter = '', $filteronprojuser = 0, $filterontaskuser = 0, $extrafields = array(), $includebilltime = 0, $search_array_options = array(), $loadextras = 0, $loadRoleMode = 1, $sortfield = '', $sortorder = '') + * @param User $usert Object user to limit tasks affected to a particular user + * @param User $userp Object user to limit projects of a particular user and public projects + * @param int $projectid Project id + * @param int $socid Third party id + * @param int $mode 0=Return list of tasks and their projects, 1=Return projects and tasks if exists + * @param string $filteronproj Filter on project ref or label + * @param string $filteronprojstatus Filter on project status ('-1'=no filter, '0,1'=Draft+Validated only) + * @param string $morewherefilter Add more filter into where SQL request (must start with ' AND ...') + * @param string $filteronprojuser Filter on user that is a contact of project + * @param string $filterontaskuser Filter on user assigned to task + * @param array $extrafields Show additional column from project or task + * @param int $includebilltime Calculate also the time to bill and billed + * @param array $search_array_options Array of search + * @return array Array of tasks + */ + public function getTasksArray($usert = null, $userp = null, $projectid = 0, $socid = 0, $mode = 0, $filteronproj = '', $filteronprojstatus = '-1', $morewherefilter = '', $filteronprojuser = 0, $filterontaskuser = 0, $extrafields = array(), $includebilltime = 0, $search_array_options = array()) @@ -932,3 +758 @@ - if ($filteronprojuser > 0 || $filterontaskuser > 0) { - $sql .= " DISTINCT"; // We may get several time the same record if user has several roles on same project/task - } + if ($filteronprojuser > 0 || $filterontaskuser > 0) $sql .= " DISTINCT"; // We may get several time the same record if user has several roles on same project/task @@ -937,3 +761,2 @@ - $sql .= " t.dateo as date_start, t.datee as date_end, t.planned_workload, t.rang, t.priority,"; - $sql .= " t.budget_amount,"; - $sql .= " t.note_public, t.note_private,"; + $sql .= " t.dateo as date_start, t.datee as date_end, t.planned_workload, t.rang,"; + $sql .= " t.description, "; @@ -941,15 +764,12 @@ - $sql .= " p.fk_opp_status, p.opp_amount, p.opp_percent, p.budget_amount as project_budget_amount"; - if ($loadextras) { // TODO Replace this with a fetch_optionnal() on the project after the fetch_object of line. - if (!empty($extrafields->attributes['projet']['label'])) { - foreach ($extrafields->attributes['projet']['label'] as $key => $val) { - $sql .= ($extrafields->attributes['projet']['type'][$key] != 'separate' ? ",efp.".$key." as options_".$key : ''); - } - } - if (!empty($extrafields->attributes['projet_task']['label'])) { - foreach ($extrafields->attributes['projet_task']['label'] as $key => $val) { - $sql .= ($extrafields->attributes['projet_task']['type'][$key] != 'separate' ? ",efpt.".$key." as options_".$key : ''); - } - } - } - if ($includebilltime) { - $sql .= ", SUM(tt.element_duration * ".$this->db->ifsql("invoice_id IS NULL", "1", "0").") as tobill, SUM(tt.element_duration * ".$this->db->ifsql("invoice_id IS NULL", "0", "1").") as billed"; + $sql .= " p.fk_opp_status, p.opp_amount, p.opp_percent, p.budget_amount"; + if (!empty($extrafields->attributes['projet']['label'])) + { + foreach ($extrafields->attributes['projet']['label'] as $key => $val) $sql .= ($extrafields->attributes['projet']['type'][$key] != 'separate' ? ",efp.".$key.' as options_'.$key : ''); + } + if (!empty($extrafields->attributes['projet_task']['label'])) + { + foreach ($extrafields->attributes['projet_task']['label'] as $key => $val) $sql .= ($extrafields->attributes['projet_task']['type'][$key] != 'separate' ? ",efpt.".$key.' as options_'.$key : ''); + } + if ($includebilltime) + { + $sql .= ", SUM(tt.task_duration * ".$this->db->ifsql("invoice_id IS NULL", "1", "0").") as tobill, SUM(tt.task_duration * ".$this->db->ifsql("invoice_id IS NULL", "0", "1").") as billed"; @@ -960,6 +780,6 @@ - if ($loadextras) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_extrafields as efp ON (p.rowid = efp.fk_object)"; - } - - if ($mode == 0) { - if ($filteronprojuser > 0) { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_extrafields as efp ON (p.rowid = efp.fk_object)"; + + if ($mode == 0) + { + if ($filteronprojuser > 0) + { @@ -970,7 +790,6 @@ - if ($loadextras) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task_extrafields as efpt ON (t.rowid = efpt.fk_object)"; - } - if ($includebilltime) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_time as tt ON (tt.fk_element = t.rowid AND tt.elementtype='task')"; - } - if ($filterontaskuser > 0) { + if ($includebilltime) + { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task_time as tt ON tt.fk_task = t.rowid"; + } + if ($filterontaskuser > 0) + { @@ -980 +799,2 @@ - $sql .= " WHERE p.entity IN (".getEntity('project').")"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task_extrafields as efpt ON (t.rowid = efpt.fk_object)"; + $sql .= " WHERE p.entity IN (".getEntity('project').")"; @@ -982,2 +802,5 @@ - } elseif ($mode == 1) { - if ($filteronprojuser > 0) { + } + elseif ($mode == 1) + { + if ($filteronprojuser > 0) + { @@ -987 +810,2 @@ - if ($filterontaskuser > 0) { + if ($filterontaskuser > 0) + { @@ -989,2 +813,3 @@ - if ($includebilltime) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_time as tt ON (tt.fk_element = t.rowid AND tt.elementtype='task')"; + if ($includebilltime) + { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task_time as tt ON tt.fk_task = t.rowid"; @@ -994 +819,3 @@ - } else { + } + else + { @@ -996,2 +823,3 @@ - if ($includebilltime) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_time as tt ON (tt.fk_element = t.rowid AND tt.elementtype = 'task')"; + if ($includebilltime) + { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task_time as tt ON tt.fk_task = t.rowid"; @@ -1000,6 +828,7 @@ - $sql .= " WHERE p.entity IN (".getEntity('project').")"; - } else { - return 'BadValueForParameterMode'; - } - - if ($filteronprojuser > 0) { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task_extrafields as efpt ON (t.rowid = efpt.fk_object)"; + $sql .= " WHERE p.entity IN (".getEntity('project').")"; + } + else return 'BadValueForParameterMode'; + + if ($filteronprojuser > 0) + { @@ -1009 +838 @@ - $sql .= " AND ec.fk_socpeople = ".((int) $filteronprojuser); + $sql .= " AND ec.fk_socpeople = ".$filteronprojuser; @@ -1013 +842,2 @@ - if ($filterontaskuser > 0) { + if ($filterontaskuser > 0) + { @@ -1018 +848 @@ - $sql .= " AND ec2.fk_socpeople = ".((int) $filterontaskuser); + $sql .= " AND ec2.fk_socpeople = ".$filterontaskuser; @@ -1022,15 +852,5 @@ - if ($socid) { - $sql .= " AND p.fk_soc = ".((int) $socid); - } - if ($projectid) { - $sql .= " AND p.rowid IN (".$this->db->sanitize($projectid).")"; - } - if ($filteronproj) { - $sql .= natural_search(array("p.ref", "p.title"), $filteronproj); - } - if ($filteronprojstatus && $filteronprojstatus != '-1') { - $sql .= " AND p.fk_statut IN (".$this->db->sanitize($filteronprojstatus).")"; - } - if ($morewherefilter) { - $sql .= $morewherefilter; - } + if ($socid) $sql .= " AND p.fk_soc = ".$socid; + if ($projectid) $sql .= " AND p.rowid in (".$projectid.")"; + if ($filteronproj) $sql .= natural_search(array("p.ref", "p.title"), $filteronproj); + if ($filteronprojstatus && $filteronprojstatus != '-1') $sql .= " AND p.fk_statut IN (".$filteronprojstatus.")"; + if ($morewherefilter) $sql .= $morewherefilter; @@ -1040 +859,0 @@ - global $db; // needed for extrafields_list_search_sql.tpl @@ -1046,8 +865,8 @@ - if ($includebilltime) { - $sql .= " GROUP BY p.rowid, p.ref, p.title, p.public, p.fk_statut, p.usage_bill_time,"; - $sql .= " t.datec, t.dateo, t.datee, t.tms,"; - $sql .= " t.rowid, t.ref, t.label, t.description, t.fk_task_parent, t.duration_effective, t.progress, t.fk_statut,"; - $sql .= " t.dateo, t.datee, t.planned_workload, t.rang, t.priority,"; - $sql .= " t.budget_amount,"; - $sql .= " t.note_public, t.note_private,"; - $sql .= " s.rowid, s.nom, s.email,"; + if ($includebilltime) + { + $sql .= " GROUP BY p.rowid, p.ref, p.title, p.public, p.fk_statut, p.usage_bill_time,"; + $sql .= " t.datec, t.dateo, t.datee, t.tms,"; + $sql .= " t.rowid, t.ref, t.label, t.description, t.fk_task_parent, t.duration_effective, t.progress, t.fk_statut,"; + $sql .= " t.dateo, t.datee, t.planned_workload, t.rang,"; + $sql .= " t.description, "; + $sql .= " s.rowid, s.nom, s.email,"; @@ -1055,19 +874,12 @@ - if ($loadextras) { - if (!empty($extrafields->attributes['projet']['label'])) { - foreach ($extrafields->attributes['projet']['label'] as $key => $val) { - $sql .= ($extrafields->attributes['projet']['type'][$key] != 'separate' ? ",efp.".$key : ''); - } - } - if (!empty($extrafields->attributes['projet_task']['label'])) { - foreach ($extrafields->attributes['projet_task']['label'] as $key => $val) { - $sql .= ($extrafields->attributes['projet_task']['type'][$key] != 'separate' ? ",efpt.".$key : ''); - } - } - } - } - - if ($sortfield && $sortorder) { - $sql .= $this->db->order($sortfield, $sortorder); - } else { - $sql .= " ORDER BY p.ref, t.rang, t.dateo"; - } + if (!empty($extrafields->attributes['projet']['label'])) + { + foreach ($extrafields->attributes['projet']['label'] as $key => $val) $sql .= ($extrafields->attributes['projet']['type'][$key] != 'separate' ? ",efp.".$key : ''); + } + if (!empty($extrafields->attributes['projet_task']['label'])) + { + foreach ($extrafields->attributes['projet_task']['label'] as $key => $val) $sql .= ($extrafields->attributes['projet_task']['type'][$key] != 'separate' ? ",efpt.".$key : ''); + } + } + + + $sql .= " ORDER BY p.ref, t.rang, t.dateo"; @@ -1078 +890,2 @@ - if ($resql) { + if ($resql) + { @@ -1082 +895,2 @@ - while ($i < $num) { + while ($i < $num) + { @@ -1087,10 +901,5 @@ - if ($loadRoleMode) { - if ((!$obj->public) && (is_object($userp))) { // If not public project and we ask a filter on project owned by a user - if (!$this->getUserRolesForProjectsOrTasks($userp, null, $obj->projectid, 0)) { - $error++; - } - } - if (is_object($usert)) { // If we ask a filter on a user affected to a task - if (!$this->getUserRolesForProjectsOrTasks(null, $usert, $obj->projectid, $obj->taskid)) { - $error++; - } + if ((!$obj->public) && (is_object($userp))) // If not public project and we ask a filter on project owned by a user + { + if (!$this->getUserRolesForProjectsOrTasks($userp, 0, $obj->projectid, 0)) + { + $error++; @@ -1099,2 +908,10 @@ - - if (!$error) { + if (is_object($usert)) // If we ask a filter on a user affected to a task + { + if (!$this->getUserRolesForProjectsOrTasks(0, $usert, $obj->projectid, $obj->taskid)) + { + $error++; + } + } + + if (!$error) + { @@ -1104,4 +921,2 @@ - $tasks[$i]->fk_project = $obj->projectid; - - // Data from project - $tasks[$i]->projectref = $obj->ref; + $tasks[$i]->fk_project = $obj->projectid; + $tasks[$i]->projectref = $obj->ref; @@ -1110,5 +924,0 @@ - $tasks[$i]->fk_opp_status = $obj->fk_opp_status; - $tasks[$i]->opp_amount = $obj->opp_amount; - $tasks[$i]->opp_percent = $obj->opp_percent; - $tasks[$i]->budget_amount = $obj->budget_amount; - $tasks[$i]->project_budget_amount = $obj->project_budget_amount; @@ -1116 +925,0 @@ - @@ -1119 +928 @@ - + $tasks[$i]->fk_parent = $obj->fk_task_parent; // deprecated @@ -1121,3 +930 @@ - $tasks[$i]->note_public = $obj->note_public; - $tasks[$i]->note_private = $obj->note_private; - $tasks[$i]->duration_effective = $obj->duration_effective; + $tasks[$i]->duration = $obj->duration_effective; @@ -1126,5 +933,2 @@ - if ($includebilltime) { - // Data summed from element_time linked to task - $tasks[$i]->tobill = $obj->tobill; - $tasks[$i]->billed = $obj->billed; - } + $tasks[$i]->tobill = $obj->tobill; + $tasks[$i]->billed = $obj->billed; @@ -1138 +941,0 @@ - $tasks[$i]->priority = $obj->priority; @@ -1145,16 +948,24 @@ - if ($loadextras) { - if (!empty($extrafields->attributes['projet']['label'])) { - foreach ($extrafields->attributes['projet']['label'] as $key => $val) { - if ($extrafields->attributes['projet']['type'][$key] != 'separate') { - $tmpvar = 'options_'.$key; - $tasks[$i]->array_options_project['options_'.$key] = $obj->$tmpvar; - } - } - } - } - - if ($loadextras) { - $tasks[$i]->fetch_optionals(); - } - - $tasks[$i]->obj = $obj; // Needed for tpl/extrafields_list_print + + $tasks[$i]->fk_opp_status = $obj->fk_opp_status; + $tasks[$i]->opp_amount = $obj->opp_amount; + $tasks[$i]->opp_percent = $obj->opp_percent; + $tasks[$i]->budget_amount = $obj->budget_amount; + $tasks[$i]->usage_bill_time = $obj->usage_bill_time; + + if (!empty($extrafields->attributes['projet']['label'])) + { + foreach ($extrafields->attributes['projet']['label'] as $key => $val) + { + if ($extrafields->attributes['projet']['type'][$key] != 'separate') + $tasks[$i]->{'options_'.$key} = $obj->{'options_'.$key}; + } + } + + if (!empty($extrafields->attributes['projet_task']['label'])) + { + foreach ($extrafields->attributes['projet_task']['label'] as $key => $val) + { + if ($extrafields->attributes['projet_task']['type'][$key] != 'separate') + $tasks[$i]->{'options_'.$key} = $obj->{'options_'.$key}; + } + } @@ -1166 +977,3 @@ - } else { + } + else + { @@ -1176,6 +989,6 @@ - * @param User|null $userp Return roles on project for this internal user. If set, usert and taskid must not be defined. - * @param User|null $usert Return roles on task for this internal user. If set userp must NOT be defined. -1 means no filter. - * @param int $projectid Project id list separated with , to filter on project - * @param int $taskid Task id to filter on a task - * @param integer $filteronprojstatus Filter on project status if userp is set. Not used if userp not defined. - * @return array|int Array (projectid => 'list of roles for project' or taskid => 'list of roles for task') + * @param User $userp Return roles on project for this internal user. If set, usert and taskid must not be defined. + * @param User $usert Return roles on task for this internal user. If set userp must NOT be defined. -1 means no filter. + * @param int $projectid Project id list separated with , to filter on project + * @param int $taskid Task id to filter on a task + * @param integer $filteronprojstatus Filter on project status if userp is set. Not used if userp not defined. + * @return array Array (projectid => 'list of roles for project' or taskid => 'list of roles for task') @@ -1190 +1003,2 @@ - if (empty($userp) && empty($usert)) { + if (empty($userp) && empty($usert)) + { @@ -1194 +1008,2 @@ - if (!empty($userp) && !empty($usert)) { + if (!empty($userp) && !empty($usert)) + { @@ -1201,9 +1016,3 @@ - if ($userp) { - $sql .= " FROM ".MAIN_DB_PREFIX."projet as pt"; - } - if ($usert && $filteronprojstatus > -1) { - $sql .= " FROM ".MAIN_DB_PREFIX."projet as p, ".MAIN_DB_PREFIX."projet_task as pt"; - } - if ($usert && $filteronprojstatus <= -1) { - $sql .= " FROM ".MAIN_DB_PREFIX."projet_task as pt"; - } + if ($userp) $sql .= " FROM ".MAIN_DB_PREFIX."projet as pt"; + if ($usert && $filteronprojstatus > -1) $sql .= " FROM ".MAIN_DB_PREFIX."projet as p, ".MAIN_DB_PREFIX."projet_task as pt"; + if ($usert && $filteronprojstatus <= -1) $sql .= " FROM ".MAIN_DB_PREFIX."projet_task as pt"; @@ -1213,12 +1022,4 @@ - if ($userp && $filteronprojstatus > -1) { - $sql .= " AND pt.fk_statut = ".((int) $filteronprojstatus); - } - if ($usert && $filteronprojstatus > -1) { - $sql .= " AND pt.fk_projet = p.rowid AND p.fk_statut = ".((int) $filteronprojstatus); - } - if ($userp) { - $sql .= " AND ctc.element = 'project'"; - } - if ($usert) { - $sql .= " AND ctc.element = 'project_task'"; - } + if ($userp && $filteronprojstatus > -1) $sql .= " AND pt.fk_statut = ".$filteronprojstatus; + if ($usert && $filteronprojstatus > -1) $sql .= " AND pt.fk_projet = p.rowid AND p.fk_statut = ".$filteronprojstatus; + if ($userp) $sql .= " AND ctc.element = 'project'"; + if ($usert) $sql .= " AND ctc.element = 'project_task'"; @@ -1226,6 +1027,2 @@ - if ($userp) { - $sql .= " AND ec.fk_socpeople = ".((int) $userp->id); - } - if ($usert) { - $sql .= " AND ec.fk_socpeople = ".((int) $usert->id); - } + if ($userp) $sql .= " AND ec.fk_socpeople = ".$userp->id; + if ($usert) $sql .= " AND ec.fk_socpeople = ".$usert->id; @@ -1234,15 +1031,9 @@ - if ($projectid) { - if ($userp) { - $sql .= " AND pt.rowid IN (".$this->db->sanitize($projectid).")"; - } - if ($usert) { - $sql .= " AND pt.fk_projet IN (".$this->db->sanitize($projectid).")"; - } - } - if ($taskid) { - if ($userp) { - $sql .= " ERROR SHOULD NOT HAPPENS"; - } - if ($usert) { - $sql .= " AND pt.rowid = ".((int) $taskid); - } + if ($projectid) + { + if ($userp) $sql .= " AND pt.rowid in (".$projectid.")"; + if ($usert) $sql .= " AND pt.fk_projet in (".$projectid.")"; + } + if ($taskid) + { + if ($userp) $sql .= " ERROR SHOULD NOT HAPPENS"; + if ($usert) $sql .= " AND pt.rowid = ".$taskid; @@ -1254 +1045,2 @@ - if ($resql) { + if ($resql) + { @@ -1257 +1049,2 @@ - while ($i < $num) { + while ($i < $num) + { @@ -1259,5 +1052,2 @@ - if (empty($arrayroles[$obj->pid])) { - $arrayroles[$obj->pid] = $obj->code; - } else { - $arrayroles[$obj->pid] .= ','.$obj->code; - } + if (empty($arrayroles[$obj->pid])) $arrayroles[$obj->pid] = $obj->code; + else $arrayroles[$obj->pid] .= ','.$obj->code; @@ -1267 +1057,3 @@ - } else { + } + else + { @@ -1288,6 +1080,4 @@ - while ($i < $num) { - if ($source == 'thirdparty') { - $contactAlreadySelected[$i] = $tab[$i]['socid']; - } else { - $contactAlreadySelected[$i] = $tab[$i]['id']; - } + while ($i < $num) + { + if ($source == 'thirdparty') $contactAlreadySelected[$i] = $tab[$i]['socid']; + else $contactAlreadySelected[$i] = $tab[$i]['id']; @@ -1305 +1095 @@ - * @return int Return integer <=0 if KO, >0 if OK + * @return int <=0 if KO, >0 if OK @@ -1314 +1103,0 @@ - $now = dol_now(); @@ -1317 +1106,2 @@ - if (!is_object($user)) { + if (!is_object($user)) + { @@ -1323,18 +1113,2 @@ - if (isset($this->timespent_note)) { - $this->timespent_note = trim($this->timespent_note); - } - if (empty($this->timespent_datehour) || ($this->timespent_date != $this->timespent_datehour)) { - $this->timespent_datehour = $this->timespent_date; - } - - if (getDolGlobalString('PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS')) { - require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; - $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm'); - - if ($this->timespent_date < $restrictBefore) { - $this->error = $langs->trans('TimeRecordingRestrictedToNMonthsBack', $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS); - $this->errors[] = $this->error; - return -1; - } - } - + if (isset($this->timespent_note)) $this->timespent_note = trim($this->timespent_note); + if (empty($this->timespent_datehour)) $this->timespent_datehour = $this->timespent_date; @@ -1344,19 +1118,27 @@ - $timespent = new TimeSpent($this->db); - $timespent->fk_element = $this->id; - $timespent->elementtype = 'task'; - $timespent->element_date = $this->timespent_date; - $timespent->element_datehour = $this->timespent_datehour; - $timespent->element_date_withhour = $this->timespent_withhour; - $timespent->element_duration = $this->timespent_duration; - $timespent->fk_user = $this->timespent_fk_user; - $timespent->fk_product = $this->timespent_fk_product; - $timespent->note = $this->timespent_note; - $timespent->datec = $this->db->idate($now); - - $result = $timespent->create($user); - - if ($result > 0) { - $ret = $result; - $this->timespent_id = $result; - - if (!$notrigger) { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task_time ("; + $sql .= "fk_task"; + $sql .= ", task_date"; + $sql .= ", task_datehour"; + $sql .= ", task_date_withhour"; + $sql .= ", task_duration"; + $sql .= ", fk_user"; + $sql .= ", note"; + $sql .= ") VALUES ("; + $sql .= $this->id; + $sql .= ", '".$this->db->idate($this->timespent_date)."'"; + $sql .= ", '".$this->db->idate($this->timespent_datehour)."'"; + $sql .= ", ".(empty($this->timespent_withhour) ? 0 : 1); + $sql .= ", ".$this->timespent_duration; + $sql .= ", ".$this->timespent_fk_user; + $sql .= ", ".(isset($this->timespent_note) ? "'".$this->db->escape($this->timespent_note)."'" : "null"); + $sql .= ")"; + + $resql = $this->db->query($sql); + if ($resql) + { + $tasktime_id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task_time"); + $ret = $tasktime_id; + $this->timespent_id = $ret; + + if (!$notrigger) + { @@ -1365,3 +1147 @@ - if ($result < 0) { - $ret = -1; - } + if ($result < 0) { $ret = -1; } @@ -1370 +1150,3 @@ - } else { + } + else + { @@ -1375 +1157,2 @@ - if ($ret > 0) { + if ($ret > 0) + { @@ -1378,5 +1161,3 @@ - $sql .= " SET duration_effective = (SELECT SUM(element_duration) FROM ".MAIN_DB_PREFIX."element_time as ptt where ptt.elementtype = 'task' AND ptt.fk_element = ".((int) $this->id).")"; - if (isset($this->progress)) { - $sql .= ", progress = ".((float) $this->progress); // Do not overwrite value if not provided - } - $sql .= " WHERE rowid = ".((int) $this->id); + $sql .= " SET duration_effective = (SELECT SUM(task_duration) FROM ".MAIN_DB_PREFIX."projet_task_time as ptt where ptt.fk_task = ".$this->id.")"; + if (isset($this->progress)) $sql .= ", progress = ".$this->progress; // Do not overwrite value if not provided + $sql .= " WHERE rowid = ".$this->id; @@ -1385 +1166,2 @@ - if (!$this->db->query($sql)) { + if (!$this->db->query($sql)) + { @@ -1390,7 +1172,3 @@ - // Update hourly rate of this time spent entry - $resql_thm_user = $this->db->query("SELECT thm FROM " . MAIN_DB_PREFIX . "user WHERE rowid = " . ((int) $timespent->fk_user)); - if (!empty($resql_thm_user)) { - $obj_thm_user = $this->db->fetch_object($resql_thm_user); - $timespent->thm = $obj_thm_user->thm; - } - $res_update = $timespent->update($user); + $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task_time"; + $sql .= " SET thm = (SELECT thm FROM ".MAIN_DB_PREFIX."user WHERE rowid = ".$this->timespent_fk_user.")"; // set average hour rate of user + $sql .= " WHERE rowid = ".$tasktime_id; @@ -1399 +1177,2 @@ - if ($res_update <= 0) { + if (!$this->db->query($sql)) + { @@ -1405 +1184,2 @@ - if ($ret > 0) { + if ($ret > 0) + { @@ -1407 +1187,3 @@ - } else { + } + else + { @@ -1414,2 +1196,175 @@ - * Fetch records of time spent of this task - * + * Calculate total of time spent for task + * + * @param User|int $userobj Filter on user. null or 0=No filter + * @param string $morewherefilter Add more filter into where SQL request (must start with ' AND ...') + * @return array Array of info for task array('min_date', 'max_date', 'total_duration', 'total_amount', 'nblines', 'nblinesnull') + */ + public function getSummaryOfTimeSpent($userobj = null, $morewherefilter = '') + { + global $langs; + + if (is_object($userobj)) $userid = $userobj->id; + else $userid = $userobj; // old method + + $id = $this->id; + if (empty($id) && empty($userid)) + { + dol_syslog("getSummaryOfTimeSpent called on a not loaded task without user param defined", LOG_ERR); + return -1; + } + + $result = array(); + + $sql = "SELECT"; + $sql .= " MIN(t.task_datehour) as min_date,"; + $sql .= " MAX(t.task_datehour) as max_date,"; + $sql .= " SUM(t.task_duration) as total_duration,"; + $sql .= " SUM(t.task_duration / 3600 * ".$this->db->ifsql("t.thm IS NULL", 0, "t.thm").") as total_amount,"; + $sql .= " COUNT(t.rowid) as nblines,"; + $sql .= " SUM(".$this->db->ifsql("t.thm IS NULL", 1, 0).") as nblinesnull"; + $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t"; + $sql .= " WHERE 1 = 1"; + if ($morewherefilter) $sql .= $morewherefilter; + if ($id > 0) $sql .= " AND t.fk_task = ".$id; + if ($userid > 0) $sql .= " AND t.fk_user = ".$userid; + + dol_syslog(get_class($this)."::getSummaryOfTimeSpent", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) + { + $obj = $this->db->fetch_object($resql); + + $result['min_date'] = $obj->min_date; // deprecated. use the ->timespent_xxx instead + $result['max_date'] = $obj->max_date; // deprecated. use the ->timespent_xxx instead + $result['total_duration'] = $obj->total_duration; // deprecated. use the ->timespent_xxx instead + + $this->timespent_min_date = $this->db->jdate($obj->min_date); + $this->timespent_max_date = $this->db->jdate($obj->max_date); + $this->timespent_total_duration = $obj->total_duration; + $this->timespent_total_amount = $obj->total_amount; + $this->timespent_nblinesnull = ($obj->nblinesnull ? $obj->nblinesnull : 0); + $this->timespent_nblines = ($obj->nblines ? $obj->nblines : 0); + + $this->db->free($resql); + } + else + { + dol_print_error($this->db); + } + return $result; + } + + /** + * Calculate quantity and value of time consumed using the thm (hourly amount value of work for user entering time) + * + * @param User $fuser Filter on a dedicated user + * @param string $dates Start date (ex 00:00:00) + * @param string $datee End date (ex 23:59:59) + * @return array Array of info for task array('amount','nbseconds','nblinesnull') + */ + public function getSumOfAmount($fuser = '', $dates = '', $datee = '') + { + global $langs; + + if (empty($id)) $id = $this->id; + + $result = array(); + + $sql = "SELECT"; + $sql .= " SUM(t.task_duration) as nbseconds,"; + $sql .= " SUM(t.task_duration / 3600 * ".$this->db->ifsql("t.thm IS NULL", 0, "t.thm").") as amount, SUM(".$this->db->ifsql("t.thm IS NULL", 1, 0).") as nblinesnull"; + $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t"; + $sql .= " WHERE t.fk_task = ".$id; + if (is_object($fuser) && $fuser->id > 0) + { + $sql .= " AND fk_user = ".$fuser->id; + } + if ($dates > 0) + { + $datefieldname = "task_datehour"; + $sql .= " AND (".$datefieldname." >= '".$this->db->idate($dates)."' OR ".$datefieldname." IS NULL)"; + } + if ($datee > 0) + { + $datefieldname = "task_datehour"; + $sql .= " AND (".$datefieldname." <= '".$this->db->idate($datee)."' OR ".$datefieldname." IS NULL)"; + } + //print $sql; + + dol_syslog(get_class($this)."::getSumOfAmount", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) + { + $obj = $this->db->fetch_object($resql); + + $result['amount'] = $obj->amount; + $result['nbseconds'] = $obj->nbseconds; + $result['nblinesnull'] = $obj->nblinesnull; + + $this->db->free($resql); + return $result; + } + else + { + dol_print_error($this->db); + return $result; + } + } + + /** + * Load one record of time spent + * + * @param int $id Id object + * @return int <0 if KO, >0 if OK + */ + public function fetchTimeSpent($id) + { + global $langs; + + $sql = "SELECT"; + $sql .= " t.rowid,"; + $sql .= " t.fk_task,"; + $sql .= " t.task_date,"; + $sql .= " t.task_datehour,"; + $sql .= " t.task_date_withhour,"; + $sql .= " t.task_duration,"; + $sql .= " t.fk_user,"; + $sql .= " t.thm,"; + $sql .= " t.note"; + $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t"; + $sql .= " WHERE t.rowid = ".$id; + + dol_syslog(get_class($this)."::fetchTimeSpent", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->timespent_id = $obj->rowid; + $this->id = $obj->fk_task; + $this->timespent_date = $this->db->jdate($obj->task_date); + $this->timespent_datehour = $this->db->jdate($obj->task_datehour); + $this->timespent_withhour = $obj->task_date_withhour; + $this->timespent_duration = $obj->task_duration; + $this->timespent_fk_user = $obj->fk_user; + $this->timespent_thm = $obj->thm; // hourly rate + $this->timespent_note = $obj->note; + } + + $this->db->free($resql); + + return 1; + } + else + { + $this->error = "Error ".$this->db->lasterror(); + return -1; + } + } + + /** + * Load all records of time spent + * + * @param User $userobj User object @@ -1417,3 +1372,3 @@ - * @return int Return integer <0 if KO, array of time spent if OK - */ - public function fetchTimeSpentOnTask($morewherefilter = '') + * @return int <0 if KO, array of time spent if OK + */ + public function fetchAllTimeSpent(User $userobj, $morewherefilter = '') @@ -1430,6 +1385,5 @@ - $sql .= " ptt.ref_ext,"; - $sql .= " ptt.fk_element as fk_task,"; - $sql .= " ptt.element_date as task_date,"; - $sql .= " ptt.element_datehour as task_datehour,"; - $sql .= " ptt.element_date_withhour as task_date_withhour,"; - $sql .= " ptt.element_duration as task_duration,"; + $sql .= " ptt.fk_task,"; + $sql .= " ptt.task_date,"; + $sql .= " ptt.task_datehour,"; + $sql .= " ptt.task_date_withhour,"; + $sql .= " ptt.task_duration,"; @@ -1438 +1391,0 @@ - $sql .= " ptt.thm,"; @@ -1446 +1399 @@ - $sql .= " FROM ".MAIN_DB_PREFIX."element_time as ptt, ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."projet as p"; + $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as ptt, ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."projet as p"; @@ -1448,3 +1401,2 @@ - $sql .= " WHERE ptt.fk_element = pt.rowid AND pt.fk_projet = p.rowid"; - $sql .= " AND ptt.elementtype = 'task'"; - $sql .= " AND pt.rowid = ".((int) $this->id); + $sql .= " WHERE ptt.fk_task = pt.rowid AND pt.fk_projet = p.rowid"; + $sql .= " AND ptt.fk_user = ".$userobj->id; @@ -1452,3 +1404 @@ - if ($morewherefilter) { - $sql .= $morewherefilter; - } + if ($morewherefilter) $sql .= $morewherefilter; @@ -1458 +1408,2 @@ - if ($resql) { + if ($resql) + { @@ -1462,240 +1413,2 @@ - while ($i < $num) { - $obj = $this->db->fetch_object($resql); - - $newobj = new stdClass(); - - $newobj->socid = $obj->socid; - $newobj->thirdparty_name = $obj->thirdparty_name; - $newobj->thirdparty_email = $obj->thirdparty_email; - - $newobj->fk_project = $obj->project_id; - $newobj->project_ref = $obj->project_ref; - $newobj->project_label = $obj->project_label; - $newobj->public = $obj->project_public; - - $newobj->fk_task = $obj->task_id; - $newobj->task_ref = $obj->task_ref; - $newobj->task_label = $obj->task_label; - - $newobj->timespent_line_id = $obj->rowid; - $newobj->timespent_line_ref_ext = $obj->ref_ext; - $newobj->timespent_line_date = $this->db->jdate($obj->task_date); - $newobj->timespent_line_datehour = $this->db->jdate($obj->task_datehour); - $newobj->timespent_line_withhour = $obj->task_date_withhour; - $newobj->timespent_line_duration = $obj->task_duration; - $newobj->timespent_line_fk_user = $obj->fk_user; - $newobj->timespent_line_thm = $obj->thm; // hourly rate - $newobj->timespent_line_note = $obj->note; - - $arrayres[] = $newobj; - - $i++; - } - - $this->db->free($resql); - - $this->lines = $arrayres; - return 1; - } else { - dol_print_error($this->db); - $this->error = "Error ".$this->db->lasterror(); - return -1; - } - } - - - /** - * Calculate total of time spent for task - * - * @param User|int $userobj Filter on user. null or 0=No filter - * @param string $morewherefilter Add more filter into where SQL request (must start with ' AND ...') - * @return array|int Array of info for task array('min_date', 'max_date', 'total_duration', 'total_amount', 'nblines', 'nblinesnull') - */ - public function getSummaryOfTimeSpent($userobj = null, $morewherefilter = '') - { - if (is_object($userobj)) { - $userid = $userobj->id; - } else { - $userid = $userobj; // old method - } - - $id = $this->id; - if (empty($id) && empty($userid)) { - dol_syslog("getSummaryOfTimeSpent called on a not loaded task without user param defined", LOG_ERR); - return -1; - } - - $result = array(); - - $sql = "SELECT"; - $sql .= " MIN(t.element_datehour) as min_date,"; - $sql .= " MAX(t.element_datehour) as max_date,"; - $sql .= " SUM(t.element_duration) as total_duration,"; - $sql .= " SUM(t.element_duration / 3600 * ".$this->db->ifsql("t.thm IS NULL", 0, "t.thm").") as total_amount,"; - $sql .= " COUNT(t.rowid) as nblines,"; - $sql .= " SUM(".$this->db->ifsql("t.thm IS NULL", 1, 0).") as nblinesnull"; - $sql .= " FROM ".MAIN_DB_PREFIX."element_time as t"; - $sql .= " WHERE t.elementtype='task'"; - if ($morewherefilter) { - $sql .= $morewherefilter; - } - if ($id > 0) { - $sql .= " AND t.fk_element = ".((int) $id); - } - if ($userid > 0) { - $sql .= " AND t.fk_user = ".((int) $userid); - } - - dol_syslog(get_class($this)."::getSummaryOfTimeSpent", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) { - $obj = $this->db->fetch_object($resql); - - $result['min_date'] = $obj->min_date; // deprecated. use the ->timespent_xxx instead - $result['max_date'] = $obj->max_date; // deprecated. use the ->timespent_xxx instead - $result['total_duration'] = $obj->total_duration; // deprecated. use the ->timespent_xxx instead - - $this->timespent_min_date = $this->db->jdate($obj->min_date); - $this->timespent_max_date = $this->db->jdate($obj->max_date); - $this->timespent_total_duration = $obj->total_duration; - $this->timespent_total_amount = $obj->total_amount; - $this->timespent_nblinesnull = ($obj->nblinesnull ? $obj->nblinesnull : 0); - $this->timespent_nblines = ($obj->nblines ? $obj->nblines : 0); - - $this->db->free($resql); - } else { - dol_print_error($this->db); - } - return $result; - } - - /** - * Calculate quantity and value of time consumed using the thm (hourly amount value of work for user entering time) - * - * @param User $fuser Filter on a dedicated user - * @param string $dates Start date (ex 00:00:00) - * @param string $datee End date (ex 23:59:59) - * @return array Array of info for task array('amount','nbseconds','nblinesnull') - */ - public function getSumOfAmount($fuser = '', $dates = '', $datee = '') - { - $id = $this->id; - - $result = array(); - - $sql = "SELECT"; - $sql .= " SUM(t.element_duration) as nbseconds,"; - $sql .= " SUM(t.element_duration / 3600 * ".$this->db->ifsql("t.thm IS NULL", 0, "t.thm").") as amount, SUM(".$this->db->ifsql("t.thm IS NULL", 1, 0).") as nblinesnull"; - $sql .= " FROM ".MAIN_DB_PREFIX."element_time as t"; - $sql .= " WHERE t.elementtype='task' AND t.fk_element = ".((int) $id); - if (is_object($fuser) && $fuser->id > 0) { - $sql .= " AND fk_user = ".((int) $fuser->id); - } - if ($dates > 0) { - $datefieldname = "element_datehour"; - $sql .= " AND (".$datefieldname." >= '".$this->db->idate($dates)."' OR ".$datefieldname." IS NULL)"; - } - if ($datee > 0) { - $datefieldname = "element_datehour"; - $sql .= " AND (".$datefieldname." <= '".$this->db->idate($datee)."' OR ".$datefieldname." IS NULL)"; - } - //print $sql; - - dol_syslog(get_class($this)."::getSumOfAmount", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) { - $obj = $this->db->fetch_object($resql); - - $result['amount'] = $obj->amount; - $result['nbseconds'] = $obj->nbseconds; - $result['nblinesnull'] = $obj->nblinesnull; - - $this->db->free($resql); - return $result; - } else { - dol_print_error($this->db); - return $result; - } - } - - /** - * Load properties of timespent of a task from the time spent ID. - * - * @param int $id Id in time spent table - * @return int Return integer <0 if KO, >0 if OK - */ - public function fetchTimeSpent($id) - { - global $langs; - - $timespent = new TimeSpent($this->db); - $timespent->fetch($id); - - dol_syslog(get_class($this)."::fetchTimeSpent", LOG_DEBUG); - - if ($timespent->id > 0) { - $this->timespent_id = $timespent->id; - $this->id = $timespent->fk_element; - $this->timespent_date = $timespent->element_date; - $this->timespent_datehour = $timespent->element_datehour; - $this->timespent_withhour = $timespent->element_date_withhour; - $this->timespent_duration = $timespent->element_duration; - $this->timespent_fk_user = $timespent->fk_user; - $this->timespent_fk_product = $timespent->fk_product; - $this->timespent_thm = $timespent->thm; // hourly rate - $this->timespent_note = $timespent->note; - - return 1; - } - - return 0; - } - - /** - * Load all records of time spent - * - * @param User $userobj User object - * @param string $morewherefilter Add more filter into where SQL request (must start with ' AND ...') - * @return array|int Return integer <0 if KO, array of time spent if OK - */ - public function fetchAllTimeSpent(User $userobj, $morewherefilter = '') - { - $arrayres = array(); - - $sql = "SELECT"; - $sql .= " s.rowid as socid,"; - $sql .= " s.nom as thirdparty_name,"; - $sql .= " s.email as thirdparty_email,"; - $sql .= " ptt.rowid,"; - $sql .= " ptt.fk_element as fk_task,"; - $sql .= " ptt.element_date as task_date,"; - $sql .= " ptt.element_datehour as task_datehour,"; - $sql .= " ptt.element_date_withhour as task_date_withhour,"; - $sql .= " ptt.element_duration as task_duration,"; - $sql .= " ptt.fk_user,"; - $sql .= " ptt.note,"; - $sql .= " ptt.thm,"; - $sql .= " pt.rowid as task_id,"; - $sql .= " pt.ref as task_ref,"; - $sql .= " pt.label as task_label,"; - $sql .= " p.rowid as project_id,"; - $sql .= " p.ref as project_ref,"; - $sql .= " p.title as project_label,"; - $sql .= " p.public as public"; - $sql .= " FROM ".MAIN_DB_PREFIX."element_time as ptt, ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."projet as p"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON p.fk_soc = s.rowid"; - $sql .= " WHERE ptt.fk_element = pt.rowid AND pt.fk_projet = p.rowid"; - $sql .= " AND ptt.elementtype = 'task'"; - $sql .= " AND ptt.fk_user = ".((int) $userobj->id); - $sql .= " AND pt.entity IN (".getEntity('project').")"; - if ($morewherefilter) { - $sql .= $morewherefilter; - } - - dol_syslog(get_class($this)."::fetchAllTimeSpent", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) { - $num = $this->db->num_rows($resql); - - $i = 0; - while ($i < $num) { + while ($i < $num) + { @@ -1725 +1437,0 @@ - $newobj->timespent_thm = $obj->thm; // hourly rate @@ -1734 +1446,3 @@ - } else { + } + else + { @@ -1748 +1462 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -1757,7 +1471,9 @@ - if ($this->timespent_date == '') { - $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")); - return -1; - } - if (!($this->timespent_fk_user > 0)) { - $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("User")); - return -1; + if ($this->timespent_date == '') + { + $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")); + return -1; + } + if (!($this->timespent_fk_user > 0)) + { + $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("User")); + return -1; @@ -1767,17 +1483,2 @@ - if (empty($this->timespent_datehour)) { - $this->timespent_datehour = $this->timespent_date; - } - if (isset($this->timespent_note)) { - $this->timespent_note = trim($this->timespent_note); - } - - if (getDolGlobalString('PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS')) { - require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; - $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm'); - - if ($this->timespent_date < $restrictBefore) { - $this->error = $langs->trans('TimeRecordingRestrictedToNMonthsBack', $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS); - $this->errors[] = $this->error; - return -1; - } - } + if (empty($this->timespent_datehour)) $this->timespent_datehour = $this->timespent_date; + if (isset($this->timespent_note)) $this->timespent_note = trim($this->timespent_note); @@ -1787,11 +1488,8 @@ - $timespent = new TimeSpent($this->db); - $timespent->fetch($this->timespent_id); - $timespent->element_date = $this->timespent_date; - $timespent->element_datehour = $this->timespent_datehour; - $timespent->element_date_withhour = $this->timespent_withhour; - $timespent->element_duration = $this->timespent_duration; - $timespent->fk_user = $this->timespent_fk_user; - $timespent->fk_product = $this->timespent_fk_product; - $timespent->note = $this->timespent_note; - $timespent->invoice_id = $this->timespent_invoiceid; - $timespent->invoice_line_id = $this->timespent_invoicelineid; + $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task_time SET"; + $sql .= " task_date = '".$this->db->idate($this->timespent_date)."',"; + $sql .= " task_datehour = '".$this->db->idate($this->timespent_datehour)."',"; + $sql .= " task_date_withhour = ".(empty($this->timespent_withhour) ? 0 : 1).","; + $sql .= " task_duration = ".$this->timespent_duration.","; + $sql .= " fk_user = ".$this->timespent_fk_user.","; + $sql .= " note = ".(isset($this->timespent_note) ? "'".$this->db->escape($this->timespent_note)."'" : "null"); + $sql .= " WHERE rowid = ".$this->timespent_id; @@ -1800,2 +1498,4 @@ - if ($timespent->update($user) > 0) { - if (!$notrigger) { + if ($this->db->query($sql)) + { + if (!$notrigger) + { @@ -1804 +1504,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -1807,2 +1507,0 @@ - } else { - $ret = 1; @@ -1809,0 +1509 @@ + else $ret = 1; @@ -1811,4 +1511,5 @@ - } else { - $ret = 1; - } - } else { + } + else $ret = 1; + } + else + { @@ -1820,28 +1521,7 @@ - if ($ret == 1 && (($this->timespent_old_duration != $this->timespent_duration) || getDolGlobalString('TIMESPENT_ALWAYS_UPDATE_THM'))) { - if ($this->timespent_old_duration != $this->timespent_duration) { - // Recalculate amount of time spent for task and update denormalized field - $sql = "UPDATE " . MAIN_DB_PREFIX . "projet_task"; - $sql .= " SET duration_effective = (SELECT SUM(element_duration) FROM " . MAIN_DB_PREFIX . "element_time as ptt where ptt.elementtype = 'task' AND ptt.fk_element = " . ((int) $this->id) . ")"; - if (isset($this->progress)) { - $sql .= ", progress = " . ((float) $this->progress); // Do not overwrite value if not provided - } - $sql .= " WHERE rowid = " . ((int) $this->id); - - dol_syslog(get_class($this) . "::updateTimeSpent", LOG_DEBUG); - if (!$this->db->query($sql)) { - $this->error = $this->db->lasterror(); - $this->db->rollback(); - $ret = -2; - } - } - - // Update hourly rate of this time spent entry, but only if it was not set initialy - $res_update = 1; - if (empty($timespent->thm) || getDolGlobalString('TIMESPENT_ALWAYS_UPDATE_THM')) { - $resql_thm_user = $this->db->query("SELECT thm FROM " . MAIN_DB_PREFIX . "user WHERE rowid = " . ((int) $timespent->fk_user)); - if (!empty($resql_thm_user)) { - $obj_thm_user = $this->db->fetch_object($resql_thm_user); - $timespent->thm = $obj_thm_user->thm; - } - $res_update = $timespent->update($user); - } + if ($ret == 1 && ($this->timespent_old_duration != $this->timespent_duration)) + { + $newDuration = $this->timespent_duration - $this->timespent_old_duration; + + $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task"; + $sql .= " SET duration_effective = (SELECT SUM(task_duration) FROM ".MAIN_DB_PREFIX."projet_task_time as ptt where ptt.fk_task = ".$this->db->escape($this->id).")"; + $sql .= " WHERE rowid = ".$this->id; @@ -1850 +1530,2 @@ - if ($res_update <= 0) { + if (!$this->db->query($sql)) + { @@ -1851,0 +1533 @@ + $this->db->rollback(); @@ -1856,3 +1538 @@ - if ($ret >= 0) { - $this->db->commit(); - } + if ($ret >= 0) $this->db->commit(); @@ -1867 +1547 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -1875,11 +1554,0 @@ - if (getDolGlobalString('PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS')) { - require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; - $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm'); - - if ($this->timespent_date < $restrictBefore) { - $this->error = $langs->trans('TimeRecordingRestrictedToNMonthsBack', $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS); - $this->errors[] = $this->error; - return -1; - } - } - @@ -1888,22 +1557,20 @@ - if (!$notrigger) { - // Call trigger - $result = $this->call_trigger('TASK_TIMESPENT_DELETE', $user); - if ($result < 0) { - $error++; - } - // End call triggers - } - - if (!$error) { - $timespent = new TimeSpent($this->db); - $timespent->fetch($this->timespent_id); - - $res_del = $timespent->delete($user); - - if ($res_del < 0) { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); - } - } - - if (!$error) { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet_task_time"; + $sql .= " WHERE rowid = ".$this->timespent_id; + + dol_syslog(get_class($this)."::delTimeSpent", LOG_DEBUG); + $resql = $this->db->query($sql); + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + + if (!$error) + { + if (!$notrigger) + { + // Call trigger + $result = $this->call_trigger('TASK_TIMESPENT_DELETE', $user); + if ($result < 0) { $error++; } + // End call triggers + } + } + + if (!$error) + { @@ -1912 +1579 @@ - $sql .= " WHERE rowid = ".((int) $this->id); + $sql .= " WHERE rowid = ".$this->id; @@ -1915 +1582,2 @@ - if ($this->db->query($sql)) { + if ($this->db->query($sql)) + { @@ -1917 +1585,3 @@ - } else { + } + else + { @@ -1924,2 +1594,4 @@ - if ($error) { - foreach ($this->errors as $errmsg) { + if ($error) + { + foreach ($this->errors as $errmsg) + { @@ -1931 +1603,3 @@ - } else { + } + else + { @@ -1937,2 +1611,2 @@ - /** Load an object from its id and create a new one in database - * + /** Load an object from its id and create a new one in database + * @@ -1950 +1624 @@ - */ + */ @@ -1977,4 +1651,5 @@ - $obj = !getDolGlobalString('PROJECT_TASK_ADDON') ? 'mod_task_simple' : $conf->global->PROJECT_TASK_ADDON; - if (getDolGlobalString('PROJECT_TASK_ADDON') && is_readable(DOL_DOCUMENT_ROOT."/core/modules/project/task/" . getDolGlobalString('PROJECT_TASK_ADDON').".php")) { - require_once DOL_DOCUMENT_ROOT."/core/modules/project/task/" . getDolGlobalString('PROJECT_TASK_ADDON').'.php'; - $modTask = new $obj(); + $obj = empty($conf->global->PROJECT_TASK_ADDON) ? 'mod_task_simple' : $conf->global->PROJECT_TASK_ADDON; + if (!empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.".php")) + { + require_once DOL_DOCUMENT_ROOT."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.'.php'; + $modTask = new $obj; @@ -1993 +1667,0 @@ - $clone_task->priority = $origin_task->priority; @@ -1996 +1670,2 @@ - if ($clone_change_dt) { + if ($clone_change_dt) + { @@ -2004 +1679,2 @@ - if (!empty($clone_task->date_start)) { + if (!empty($clone_task->date_start)) + { @@ -2009 +1685,2 @@ - if (!empty($clone_task->date_end)) { + if (!empty($clone_task->date_end)) + { @@ -2014,2 +1691,3 @@ - if (!$clone_prog) { - $clone_task->progress = 0; + if (!$clone_prog) + { + $clone_task->progress = 0; @@ -2022 +1700,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -2028 +1707,2 @@ - if (!$error) { + if (!$error) + { @@ -2032,2 +1712,3 @@ - //Note Update - if (!$clone_note) { + //Note Update + if (!$clone_note) + { @@ -2036 +1717,3 @@ - } else { + } + else + { @@ -2038,2 +1721,3 @@ - $res = $clone_task->update_note(dol_html_entity_decode($clone_task->note_public, ENT_QUOTES | ENT_HTML5), '_public'); - if ($res < 0) { + $res = $clone_task->update_note(dol_html_entity_decode($clone_task->note_public, ENT_QUOTES), '_public'); + if ($res < 0) + { @@ -2043 +1727,3 @@ - } else { + } + else + { @@ -2048,2 +1734,3 @@ - $res = $clone_task->update_note(dol_html_entity_decode($clone_task->note_private, ENT_QUOTES | ENT_HTML5), '_private'); - if ($res < 0) { + $res = $clone_task->update_note(dol_html_entity_decode($clone_task->note_private, ENT_QUOTES), '_private'); + if ($res < 0) + { @@ -2053 +1740,3 @@ - } else { + } + else + { @@ -2059 +1748,2 @@ - if ($clone_file) { + if ($clone_file) + { @@ -2062 +1752 @@ - //retrieve project origin ref to know folder to copy + //retreive project origin ref to know folder to copy @@ -2067 +1757,2 @@ - if ($ori_project_id != $project_id) { + if ($ori_project_id != $project_id) + { @@ -2070 +1761,3 @@ - } else { + } + else + { @@ -2074,2 +1767,2 @@ - $clone_task_dir = $conf->project->dir_output."/".dol_sanitizeFileName($clone_project_ref)."/".dol_sanitizeFileName($clone_task_ref); - $ori_task_dir = $conf->project->dir_output."/".dol_sanitizeFileName($ori_project_ref)."/".dol_sanitizeFileName($fromid); + $clone_task_dir = $conf->projet->dir_output."/".dol_sanitizeFileName($clone_project_ref)."/".dol_sanitizeFileName($clone_task_ref); + $ori_task_dir = $conf->projet->dir_output."/".dol_sanitizeFileName($ori_project_ref)."/".dol_sanitizeFileName($fromid); @@ -2078,3 +1771,6 @@ - foreach ($filearray as $key => $file) { - if (!file_exists($clone_task_dir)) { - if (dol_mkdir($clone_task_dir) < 0) { + foreach ($filearray as $key => $file) + { + if (!file_exists($clone_task_dir)) + { + if (dol_mkdir($clone_task_dir) < 0) + { @@ -2087 +1783,2 @@ - if (is_numeric($rescopy) && $rescopy < 0) { + if (is_numeric($rescopy) && $rescopy < 0) + { @@ -2095 +1792,2 @@ - if ($clone_affectation) { + if ($clone_affectation) + { @@ -2099 +1797,2 @@ - foreach (array('internal', 'external') as $source) { + foreach (array('internal', 'external') as $source) + { @@ -2103 +1802,2 @@ - while ($i < $num) { + while ($i < $num) + { @@ -2105 +1805,2 @@ - if ($clone_task->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { + if ($clone_task->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { @@ -2109,2 +1810,5 @@ - } else { - if ($clone_task->error != '') { + } + else + { + if ($clone_task->error != '') + { @@ -2120 +1824,2 @@ - if ($clone_time) { + if ($clone_time) + { @@ -2127 +1832,2 @@ - if (!$error) { + if (!$error) + { @@ -2130 +1836,3 @@ - } else { + } + else + { @@ -2149 +1857 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -2159 +1867 @@ - // phpcs:enable + // phpcs:enable @@ -2163,64 +1871,54 @@ - $this->labelStatus[0] = 'Draft'; - $this->labelStatus[1] = 'ToDo'; - $this->labelStatus[2] = 'Running'; - $this->labelStatus[3] = 'Finish'; - $this->labelStatus[4] = 'Transfered'; - $this->labelStatusShort[0] = 'Draft'; - $this->labelStatusShort[1] = 'ToDo'; - $this->labelStatusShort[2] = 'Running'; - $this->labelStatusShort[3] = 'Completed'; - $this->labelStatusShort[4] = 'Transfered'; - - if ($mode == 0) { - return $langs->trans($this->labelStatus[$status]); - } elseif ($mode == 1) { - return $langs->trans($this->labelStatusShort[$status]); - } elseif ($mode == 2) { - if ($status == 0) { - return img_picto($langs->trans($this->labelStatusShort[$status]), 'statut0').' '.$langs->trans($this->labelStatusShort[$status]); - } elseif ($status == 1) { - return img_picto($langs->trans($this->labelStatusShort[$status]), 'statut1').' '.$langs->trans($this->labelStatusShort[$status]); - } elseif ($status == 2) { - return img_picto($langs->trans($this->labelStatusShort[$status]), 'statut3').' '.$langs->trans($this->labelStatusShort[$status]); - } elseif ($status == 3) { - return img_picto($langs->trans($this->labelStatusShort[$status]), 'statut6').' '.$langs->trans($this->labelStatusShort[$status]); - } elseif ($status == 4) { - return img_picto($langs->trans($this->labelStatusShort[$status]), 'statut6').' '.$langs->trans($this->labelStatusShort[$status]); - } elseif ($status == 5) { - return img_picto($langs->trans($this->labelStatusShort[$status]), 'statut5').' '.$langs->trans($this->labelStatusShort[$status]); - } - } elseif ($mode == 3) { - if ($status == 0) { - return img_picto($langs->trans($this->labelStatusShort[$status]), 'statut0'); - } elseif ($status == 1) { - return img_picto($langs->trans($this->labelStatusShort[$status]), 'statut1'); - } elseif ($status == 2) { - return img_picto($langs->trans($this->labelStatusShort[$status]), 'statut3'); - } elseif ($status == 3) { - return img_picto($langs->trans($this->labelStatusShort[$status]), 'statut6'); - } elseif ($status == 4) { - return img_picto($langs->trans($this->labelStatusShort[$status]), 'statut6'); - } elseif ($status == 5) { - return img_picto($langs->trans($this->labelStatusShort[$status]), 'statut5'); - } - } elseif ($mode == 4) { - if ($status == 0) { - return img_picto($langs->trans($this->labelStatusShort[$status]), 'statut0').' '.$langs->trans($this->labelStatus[$status]); - } elseif ($status == 1) { - return img_picto($langs->trans($this->labelStatusShort[$status]), 'statut1').' '.$langs->trans($this->labelStatus[$status]); - } elseif ($status == 2) { - return img_picto($langs->trans($this->labelStatusShort[$status]), 'statut3').' '.$langs->trans($this->labelStatus[$status]); - } elseif ($status == 3) { - return img_picto($langs->trans($this->labelStatusShort[$status]), 'statut6').' '.$langs->trans($this->labelStatus[$status]); - } elseif ($status == 4) { - return img_picto($langs->trans($this->labelStatusShort[$status]), 'statut6').' '.$langs->trans($this->labelStatus[$status]); - } elseif ($status == 5) { - return img_picto($langs->trans($this->labelStatusShort[$status]), 'statut5').' '.$langs->trans($this->labelStatus[$status]); - } - } elseif ($mode == 5) { - /*if ($status==0) return $langs->trans($this->labelStatusShort[$status]).' '.img_picto($langs->trans($this->labelStatusShort[$status]),'statut0'); - elseif ($status==1) return $langs->trans($this->labelStatusShort[$status]).' '.img_picto($langs->trans($this->labelStatusShort[$status]),'statut1'); - elseif ($status==2) return $langs->trans($this->labelStatusShort[$status]).' '.img_picto($langs->trans($this->labelStatusShort[$status]),'statut3'); - elseif ($status==3) return $langs->trans($this->labelStatusShort[$status]).' '.img_picto($langs->trans($this->labelStatusShort[$status]),'statut6'); - elseif ($status==4) return $langs->trans($this->labelStatusShort[$status]).' '.img_picto($langs->trans($this->labelStatusShort[$status]),'statut6'); - elseif ($status==5) return $langs->trans($this->labelStatusShort[$status]).' '.img_picto($langs->trans($this->labelStatusShort[$status]),'statut5'); + $this->statuts[0] = 'Draft'; + $this->statuts[1] = 'ToDo'; + $this->statuts[2] = 'Running'; + $this->statuts[3] = 'Finish'; + $this->statuts[4] = 'Transfered'; + $this->statuts_short[0] = 'Draft'; + $this->statuts_short[1] = 'ToDo'; + $this->statuts_short[2] = 'Running'; + $this->statuts_short[3] = 'Completed'; + $this->statuts_short[4] = 'Transfered'; + + if ($mode == 0) + { + return $langs->trans($this->statuts[$status]); + } + elseif ($mode == 1) + { + return $langs->trans($this->statuts_short[$status]); + } + elseif ($mode == 2) + { + if ($status == 0) return img_picto($langs->trans($this->statuts_short[$status]), 'statut0').' '.$langs->trans($this->statuts_short[$status]); + elseif ($status == 1) return img_picto($langs->trans($this->statuts_short[$status]), 'statut1').' '.$langs->trans($this->statuts_short[$status]); + elseif ($status == 2) return img_picto($langs->trans($this->statuts_short[$status]), 'statut3').' '.$langs->trans($this->statuts_short[$status]); + elseif ($status == 3) return img_picto($langs->trans($this->statuts_short[$status]), 'statut6').' '.$langs->trans($this->statuts_short[$status]); + elseif ($status == 4) return img_picto($langs->trans($this->statuts_short[$status]), 'statut6').' '.$langs->trans($this->statuts_short[$status]); + elseif ($status == 5) return img_picto($langs->trans($this->statuts_short[$status]), 'statut5').' '.$langs->trans($this->statuts_short[$status]); + } + elseif ($mode == 3) + { + if ($status == 0) return img_picto($langs->trans($this->statuts_short[$status]), 'statut0'); + elseif ($status == 1) return img_picto($langs->trans($this->statuts_short[$status]), 'statut1'); + elseif ($status == 2) return img_picto($langs->trans($this->statuts_short[$status]), 'statut3'); + elseif ($status == 3) return img_picto($langs->trans($this->statuts_short[$status]), 'statut6'); + elseif ($status == 4) return img_picto($langs->trans($this->statuts_short[$status]), 'statut6'); + elseif ($status == 5) return img_picto($langs->trans($this->statuts_short[$status]), 'statut5'); + } + elseif ($mode == 4) + { + if ($status == 0) return img_picto($langs->trans($this->statuts_short[$status]), 'statut0').' '.$langs->trans($this->statuts[$status]); + elseif ($status == 1) return img_picto($langs->trans($this->statuts_short[$status]), 'statut1').' '.$langs->trans($this->statuts[$status]); + elseif ($status == 2) return img_picto($langs->trans($this->statuts_short[$status]), 'statut3').' '.$langs->trans($this->statuts[$status]); + elseif ($status == 3) return img_picto($langs->trans($this->statuts_short[$status]), 'statut6').' '.$langs->trans($this->statuts[$status]); + elseif ($status == 4) return img_picto($langs->trans($this->statuts_short[$status]), 'statut6').' '.$langs->trans($this->statuts[$status]); + elseif ($status == 5) return img_picto($langs->trans($this->statuts_short[$status]), 'statut5').' '.$langs->trans($this->statuts[$status]); + } + elseif ($mode == 5) + { + /*if ($status==0) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]),'statut0'); + elseif ($status==1) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]),'statut1'); + elseif ($status==2) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]),'statut3'); + elseif ($status==3) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]),'statut6'); + elseif ($status==4) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]),'statut6'); + elseif ($status==5) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]),'statut5'); @@ -2230,7 +1928,9 @@ - } elseif ($mode == 6) { - /*if ($status==0) return $langs->trans($this->labelStatus[$status]).' '.img_picto($langs->trans($this->labelStatusShort[$status]),'statut0'); - elseif ($status==1) return $langs->trans($this->labelStatus[$status]).' '.img_picto($langs->trans($this->labelStatusShort[$status]),'statut1'); - elseif ($status==2) return $langs->trans($this->labelStatus[$status]).' '.img_picto($langs->trans($this->labelStatusShort[$status]),'statut3'); - elseif ($status==3) return $langs->trans($this->labelStatus[$status]).' '.img_picto($langs->trans($this->labelStatusShort[$status]),'statut6'); - elseif ($status==4) return $langs->trans($this->labelStatus[$status]).' '.img_picto($langs->trans($this->labelStatusShort[$status]),'statut6'); - elseif ($status==5) return $langs->trans($this->labelStatus[$status]).' '.img_picto($langs->trans($this->labelStatusShort[$status]),'statut5'); + } + elseif ($mode == 6) + { + /*if ($status==0) return $langs->trans($this->statuts[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]),'statut0'); + elseif ($status==1) return $langs->trans($this->statuts[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]),'statut1'); + elseif ($status==2) return $langs->trans($this->statuts[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]),'statut3'); + elseif ($status==3) return $langs->trans($this->statuts[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]),'statut6'); + elseif ($status==4) return $langs->trans($this->statuts[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]),'statut6'); + elseif ($status==5) return $langs->trans($this->statuts[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]),'statut5'); @@ -2241 +1940,0 @@ - return ""; @@ -2256,3 +1955,3 @@ - global $conf; - - $outputlangs->load("projects"); + global $conf, $langs; + + $langs->load("projects"); @@ -2263,3 +1962,3 @@ - if (!empty($this->model_pdf)) { - $modele = $this->model_pdf; - } elseif (getDolGlobalString('PROJECT_TASK_ADDON_PDF')) { + if ($this->modelpdf) { + $modele = $this->modelpdf; + } elseif (!empty($conf->global->PROJECT_TASK_ADDON_PDF)) { @@ -2276 +1975 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -2281 +1980 @@ - * @return WorkboardResponse|int Return integer <0 if KO, WorkboardResponse if OK + * @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK @@ -2285 +1984 @@ - // phpcs:enable + // phpcs:enable @@ -2289,2 +1988 @@ - //$socid = $user->socid; - $socid = 0; + //$socid=$user->socid; @@ -2300 +1998 @@ - //$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid"; @@ -2307,3 +2005 @@ - if (!$user->hasRight('projet', 'all', 'lire')) { - $sql .= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")"; - } + if (!$user->rights->projet->all->lire) $sql .= " AND p.rowid IN (".$projectsListId.")"; @@ -2311 +2007,2 @@ - //if ($socid || ! $user->rights->societe->client->voir) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).")"; + //if ($socid || ! $user->rights->societe->client->voir) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")"; + if ($socid) $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")"; @@ -2313 +2010 @@ - // if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id).") OR (s.rowid IS NULL))"; + // if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id.") OR (s.rowid IS NULL))"; @@ -2317 +2014,2 @@ - if ($resql) { + if ($resql) + { @@ -2321 +2019 @@ - $response->warning_delay = $conf->project->task->warning_delay / 60 / 60 / 24; + $response->warning_delay = $conf->projet->task->warning_delay / 60 / 60 / 24; @@ -2323,5 +2021,2 @@ - if ($user->hasRight("projet", "all", "lire")) { - $response->url = DOL_URL_ROOT.'/projet/tasks/list.php?mainmenu=project'; - } else { - $response->url = DOL_URL_ROOT.'/projet/tasks/list.php?mode=mine&mainmenu=project'; - } + if ($user->rights->projet->all->lire) $response->url = DOL_URL_ROOT.'/projet/tasks/list.php?mainmenu=project'; + else $response->url = DOL_URL_ROOT.'/projet/tasks/list.php?mode=mine&mainmenu=project'; @@ -2331 +2026,2 @@ - while ($obj = $this->db->fetch_object($resql)) { + while ($obj = $this->db->fetch_object($resql)) + { @@ -2345 +2041,3 @@ - } else { + } + else + { @@ -2352 +2050 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -2356 +2054 @@ - * @return int Return integer <0 if ko, >0 if ok + * @return int <0 if ko, >0 if ok @@ -2360 +2058 @@ - // phpcs:enable + // phpcs:enable @@ -2363,2 +2061 @@ - $mine = 0; - $socid = $user->socid; + $mine = 0; $socid = $user->socid; @@ -2373,3 +2070 @@ - if (!$user->hasRight('societe', 'client', 'voir') && !$socid) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc = s.rowid"; - } + if (!$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc = s.rowid"; @@ -2379,3 +2074 @@ - if ($mine || !$user->hasRight('projet', 'all', 'lire')) { - $sql .= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")"; - } + if ($mine || !$user->rights->projet->all->lire) $sql .= " AND p.rowid IN (".$projectsListId.")"; @@ -2383,7 +2076,3 @@ - //if ($socid || ! $user->rights->societe->client->voir) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).")"; - if ($socid) { - $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).")"; - } - if (!$user->hasRight('societe', 'client', 'voir') && !$socid) { - $sql .= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id).") OR (s.rowid IS NULL))"; - } + //if ($socid || ! $user->rights->societe->client->voir) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")"; + if ($socid) $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")"; + if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id.") OR (s.rowid IS NULL))"; @@ -2392 +2081,2 @@ - if ($resql) { + if ($resql) + { @@ -2394 +2084,2 @@ - while ($obj = $this->db->fetch_object($resql)) { + while ($obj = $this->db->fetch_object($resql)) + { @@ -2399 +2090,3 @@ - } else { + } + else + { @@ -2421,42 +2114,3 @@ - $datetouse = ($this->date_end > 0) ? $this->date_end : ((isset($this->datee) && $this->datee > 0) ? $this->datee : 0); - - return ($datetouse > 0 && ($datetouse < ($now - $conf->project->task->warning_delay))); - } - - /** - * Return clicable link of object (with eventually picto) - * - * @param string $option Where point the link (0=> main card, 1,2 => shipment, 'nolink'=>No link) - * @param array $arraydata Array of data - * @return string HTML Code for Kanban thumb. - */ - public function getKanbanView($option = '', $arraydata = null) - { - $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']); - - $return = '
'; - $return .= '
'; - $return .= ''; - $return .= img_picto('', $this->picto); - //$return .= ''; // Can be image - $return .= ''; - $return .= '
'; - $return .= ''.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : $this->ref).''; - if ($selected >= 0) { - $return .= ''; - } - if (!empty($arraydata['projectlink'])) { - //$tmpproject = $arraydata['project']; - //$return .= '
'.$tmpproject->getNomProject().''; - $return .= '
'.$arraydata['projectlink'].''; - } - if (property_exists($this, 'budget_amount')) { - //$return .= '
'.$langs->trans("Budget").' : '.price($this->budget_amount, 0, $langs, 1, 0, 0, $conf->currency).''; - } - if (property_exists($this, 'duration_effective')) { - $return .= '

'.getTaskProgressView($this, false, true).'
'; - } - $return .= '
'; - $return .= '
'; - $return .= '
'; - return $return; + $datetouse = ($this->date_end > 0) ? $this->date_end : ($this->datee > 0 ? $this->datee : 0); + + return ($datetouse > 0 && ($datetouse < ($now - $conf->projet->task->warning_delay))); --- /tmp/dsg/dolibarr/htdocs/projet/class/github_19.0.3_taskstats.class.php +++ /tmp/dsg/dolibarr/htdocs/projet/class/client_taskstats.class.php @@ -2 +2,2 @@ -/* Copyright (C) 2014-2015 Florian HENRY +/* Lead + * Copyright (C) 2014-2015 Florian HENRY @@ -17 +17,0 @@ - @@ -29,0 +30 @@ + public $year; @@ -31,10 +32,5 @@ - /** - * @var int priority - */ - public $priority; - - /** - * Constructor of the class - * - * @param DoliDb $db Database handler - */ + /** + * Constructor of the class + * + * @param DoliDb $db Database handler + */ @@ -43,0 +40,3 @@ + + require_once 'task.class.php'; + $this->task = new Task($this->db); @@ -56 +55,3 @@ - global $user, $langs; + global $conf, $user, $langs; + + $datay = array(); @@ -61,3 +62,2 @@ - if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc=p.fk_soc AND sc.fk_user=".((int) $user->id); - } + 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; @@ -68,0 +69 @@ + $res = array(); @@ -70 +71 @@ - dol_syslog(get_class($this).'::'.__METHOD__, LOG_DEBUG); + dol_syslog(get_class($this).'::'.__METHOD__."", LOG_DEBUG); @@ -78 +79,2 @@ - if ($i < $limit || $num == $limit) { + if ($i < $limit || $num == $limit) + { @@ -83 +85,2 @@ - } else { + } + else @@ -85 +87,0 @@ - } @@ -88 +90 @@ - if ($num > $limit) { + if ($num > $limit) @@ -93 +94,0 @@ - } @@ -111 +112,5 @@ - global $user; + global $conf, $user, $langs; + + $datay = array(); + + $wonlostfilter = 0; // No filter on status WON/LOST @@ -115,3 +120,2 @@ - if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc=p.fk_soc AND sc.fk_user=".((int) $user->id); - } + 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; @@ -138,3 +142,2 @@ - if (!empty($this->userid)) { - $sqlwhere[] = ' t.fk_user_resp = '.((int) $this->userid); - } + if (!empty($this->userid)) + $sqlwhere[] = ' t.fk_user_resp='.$this->userid; @@ -142,12 +145,9 @@ - if (!empty($this->socid)) { - $sqlwhere[] = ' p.fk_soc = '.((int) $this->socid); // Link on thirdparty is on project, not on task - } - if (!empty($this->year) && empty($this->month)) { - $sqlwhere[] = " t.datec BETWEEN '".$this->db->idate(dol_get_first_day($this->year, 1))."' AND '".$this->db->idate(dol_get_last_day($this->year, 12))."'"; - } - if (!empty($this->year) && !empty($this->month)) { - $sqlwhere[] = " t.datec BETWEEN '".$this->db->idate(dol_get_first_day($this->year, $this->month))."' AND '".$this->db->idate(dol_get_last_day($this->year, $this->month))."'"; - } - if (!empty($this->priority)) { - $sqlwhere[] = " t.priority IN (".$this->db->sanitize($this->priority, 1).")"; - } + if (!empty($this->socid)) + $sqlwhere[] = ' p.fk_soc='.$this->socid; // Link on thirdparty is on project, not on task + if (!empty($this->year) && empty($this->yearmonth)) + $sqlwhere[] = " date_format(t.datec,'%Y')='".$this->db->escape($this->year)."'"; + if (!empty($this->yearmonth)) + $sqlwhere[] = " t.datec BETWEEN '".$this->db->idate(dol_get_first_day($this->yearmonth))."' AND '".$this->db->idate(dol_get_last_day($this->yearmonth))."'"; + + if (!empty($this->status)) + $sqlwhere[] = " t.priority IN (".$this->priority.")"; @@ -166 +166 @@ - * @param int $format 0=Label of abscissa is a translated text, 1=Label of abscissa is month number, 2=Label of abscissa is first letter of month + * @param int $format 0=Label of abscissa is a translated text, 1=Label of abscissa is month number, 2=Label of abscissa is first letter of month @@ -173 +173 @@ - $this->year = $year; + $this->yearmonth = $year; @@ -177,3 +177,2 @@ - if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc=p.fk_soc AND sc.fk_user=".((int) $user->id); - } + 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; @@ -182,0 +182,2 @@ + + $this->yearmonth = 0; @@ -188,31 +188,0 @@ - - - /** - * Return the Task amount by month for a year - * - * @param int $year Year to scan - * @param int $format 0=Label of abscissa is a translated text, 1=Label of abscissa is month number, 2=Label of abscissa is first letter of month - * @return array Array with amount by month - */ - public function getAmountByMonth($year, $format = 0) - { - // Return an empty array at the moment because task has no amount - return array(); - } - - /** - * Return average of entity by month - * @param int $year year number - * @return array array of values - */ - protected function getAverageByMonth($year) - { - $sql = "SELECT date_format(datef,'%m') as dm, AVG(f.".$this->field.")"; - $sql .= " FROM ".$this->from; - $sql .= " WHERE f.datef BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; - $sql .= " AND ".$this->where; - $sql .= " GROUP BY dm"; - $sql .= $this->db->order('dm', 'DESC'); - - return $this->_getAverageByMonth($year, $sql); - }