api_tasks.class.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. <?php
  2. /* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  3. * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. use Luracast\Restler\RestException;
  19. require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
  20. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  21. /**
  22. * API class for projects
  23. *
  24. * @access protected
  25. * @class DolibarrApiAccess {@requires user,external}
  26. */
  27. class Tasks extends DolibarrApi
  28. {
  29. /**
  30. * @var array $FIELDS Mandatory fields, checked when create and update object
  31. */
  32. public static $FIELDS = array(
  33. 'ref',
  34. 'label',
  35. 'fk_project'
  36. );
  37. /**
  38. * @var Task $task {@type Task}
  39. */
  40. public $task;
  41. /**
  42. * Constructor
  43. */
  44. public function __construct()
  45. {
  46. global $db, $conf;
  47. $this->db = $db;
  48. $this->task = new Task($this->db);
  49. }
  50. /**
  51. * Get properties of a task object
  52. *
  53. * Return an array with task informations
  54. *
  55. * @param int $id ID of task
  56. * @param int $includetimespent 0=Return only task. 1=Include a summary of time spent, 2=Include details of time spent lines
  57. * @return array|mixed data without useless information
  58. *
  59. * @throws RestException
  60. */
  61. public function get($id, $includetimespent = 0)
  62. {
  63. if (!DolibarrApiAccess::$user->rights->projet->lire) {
  64. throw new RestException(401);
  65. }
  66. $result = $this->task->fetch($id);
  67. if (!$result) {
  68. throw new RestException(404, 'Task not found');
  69. }
  70. if (!DolibarrApi::_checkAccessToResource('task', $this->task->id)) {
  71. throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
  72. }
  73. if ($includetimespent == 1) {
  74. $timespent = $this->task->getSummaryOfTimeSpent(0);
  75. }
  76. if ($includetimespent == 2) {
  77. $timespent = $this->task->fetchTimeSpentOnTask();
  78. }
  79. return $this->_cleanObjectDatas($this->task);
  80. }
  81. /**
  82. * List tasks
  83. *
  84. * Get a list of tasks
  85. *
  86. * @param string $sortfield Sort field
  87. * @param string $sortorder Sort order
  88. * @param int $limit Limit for list
  89. * @param int $page Page number
  90. * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
  91. * @return array Array of project objects
  92. */
  93. public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '')
  94. {
  95. global $db, $conf;
  96. if (!DolibarrApiAccess::$user->rights->projet->lire) {
  97. throw new RestException(401);
  98. }
  99. $obj_ret = array();
  100. // case of external user, $thirdparty_ids param is ignored and replaced by user's socid
  101. $socids = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : '';
  102. // If the internal user must only see his customers, force searching by him
  103. $search_sale = 0;
  104. if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) {
  105. $search_sale = DolibarrApiAccess::$user->id;
  106. }
  107. $sql = "SELECT t.rowid";
  108. if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
  109. $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)
  110. }
  111. $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
  112. if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
  113. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
  114. }
  115. $sql .= ' WHERE t.entity IN ('.getEntity('project').')';
  116. if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
  117. $sql .= " AND t.fk_soc = sc.fk_soc";
  118. }
  119. if ($socids) {
  120. $sql .= " AND t.fk_soc IN (".$this->db->sanitize($socids).")";
  121. }
  122. if ($search_sale > 0) {
  123. $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
  124. }
  125. // Insert sale filter
  126. if ($search_sale > 0) {
  127. $sql .= " AND sc.fk_user = ".((int) $search_sale);
  128. }
  129. // Add sql filters
  130. if ($sqlfilters) {
  131. $errormessage = '';
  132. $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
  133. if ($errormessage) {
  134. throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
  135. }
  136. }
  137. $sql .= $this->db->order($sortfield, $sortorder);
  138. if ($limit) {
  139. if ($page < 0) {
  140. $page = 0;
  141. }
  142. $offset = $limit * $page;
  143. $sql .= $this->db->plimit($limit + 1, $offset);
  144. }
  145. dol_syslog("API Rest request");
  146. $result = $this->db->query($sql);
  147. if ($result) {
  148. $num = $this->db->num_rows($result);
  149. $min = min($num, ($limit <= 0 ? $num : $limit));
  150. $i = 0;
  151. while ($i < $min) {
  152. $obj = $this->db->fetch_object($result);
  153. $task_static = new Task($this->db);
  154. if ($task_static->fetch($obj->rowid)) {
  155. $obj_ret[] = $this->_cleanObjectDatas($task_static);
  156. }
  157. $i++;
  158. }
  159. } else {
  160. throw new RestException(503, 'Error when retrieve task list : '.$this->db->lasterror());
  161. }
  162. if (!count($obj_ret)) {
  163. throw new RestException(404, 'No task found');
  164. }
  165. return $obj_ret;
  166. }
  167. /**
  168. * Create task object
  169. *
  170. * @param array $request_data Request data
  171. * @return int ID of project
  172. */
  173. public function post($request_data = null)
  174. {
  175. if (!DolibarrApiAccess::$user->rights->projet->creer) {
  176. throw new RestException(401, "Insuffisant rights");
  177. }
  178. // Check mandatory fields
  179. $result = $this->_validate($request_data);
  180. foreach ($request_data as $field => $value) {
  181. $this->task->$field = $value;
  182. }
  183. /*if (isset($request_data["lines"])) {
  184. $lines = array();
  185. foreach ($request_data["lines"] as $line) {
  186. array_push($lines, (object) $line);
  187. }
  188. $this->project->lines = $lines;
  189. }*/
  190. if ($this->task->create(DolibarrApiAccess::$user) < 0) {
  191. throw new RestException(500, "Error creating task", array_merge(array($this->task->error), $this->task->errors));
  192. }
  193. return $this->task->id;
  194. }
  195. // /**
  196. // * Get time spent of a task
  197. // *
  198. // * @param int $id Id of task
  199. // * @return int
  200. // *
  201. // * @url GET {id}/tasks
  202. // */
  203. /*
  204. public function getLines($id, $includetimespent=0)
  205. {
  206. if(! DolibarrApiAccess::$user->rights->projet->lire) {
  207. throw new RestException(401);
  208. }
  209. $result = $this->project->fetch($id);
  210. if( ! $result ) {
  211. throw new RestException(404, 'Project not found');
  212. }
  213. if( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) {
  214. throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
  215. }
  216. $this->project->getLinesArray(DolibarrApiAccess::$user);
  217. $result = array();
  218. foreach ($this->project->lines as $line) // $line is a task
  219. {
  220. if ($includetimespent == 1)
  221. {
  222. $timespent = $line->getSummaryOfTimeSpent(0);
  223. }
  224. if ($includetimespent == 1)
  225. {
  226. // TODO
  227. // Add class for timespent records and loop and fill $line->lines with records of timespent
  228. }
  229. array_push($result,$this->_cleanObjectDatas($line));
  230. }
  231. return $result;
  232. }
  233. */
  234. /**
  235. * Get roles a user is assigned to a task with
  236. *
  237. * @param int $id Id of task
  238. * @param int $userid Id of user (0 = connected user)
  239. * @return array Array of roles
  240. *
  241. * @url GET {id}/roles
  242. *
  243. */
  244. public function getRoles($id, $userid = 0)
  245. {
  246. global $db;
  247. if (!DolibarrApiAccess::$user->rights->projet->lire) {
  248. throw new RestException(401);
  249. }
  250. $result = $this->task->fetch($id);
  251. if (!$result) {
  252. throw new RestException(404, 'Task not found');
  253. }
  254. if (!DolibarrApi::_checkAccessToResource('tasks', $this->task->id)) {
  255. throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
  256. }
  257. $usert = DolibarrApiAccess::$user;
  258. if ($userid > 0) {
  259. $usert = new User($this->db);
  260. $usert->fetch($userid);
  261. }
  262. $this->task->roles = $this->task->getUserRolesForProjectsOrTasks(null, $usert, 0, $id);
  263. $result = array();
  264. foreach ($this->task->roles as $line) {
  265. array_push($result, $this->_cleanObjectDatas($line));
  266. }
  267. return $result;
  268. }
  269. // /**
  270. // * Add a task to given project
  271. // *
  272. // * @param int $id Id of project to update
  273. // * @param array $request_data Projectline data
  274. // *
  275. // * @url POST {id}/tasks
  276. // *
  277. // * @return int
  278. // */
  279. /*
  280. public function postLine($id, $request_data = null)
  281. {
  282. if(! DolibarrApiAccess::$user->rights->projet->creer) {
  283. throw new RestException(401);
  284. }
  285. $result = $this->project->fetch($id);
  286. if( ! $result ) {
  287. throw new RestException(404, 'Project not found');
  288. }
  289. if( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) {
  290. throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
  291. }
  292. $request_data = (object) $request_data;
  293. $request_data->desc = sanitizeVal($request_data->desc, 'restricthtml');
  294. $updateRes = $this->project->addline(
  295. $request_data->desc,
  296. $request_data->subprice,
  297. $request_data->qty,
  298. $request_data->tva_tx,
  299. $request_data->localtax1_tx,
  300. $request_data->localtax2_tx,
  301. $request_data->fk_product,
  302. $request_data->remise_percent,
  303. $request_data->info_bits,
  304. $request_data->fk_remise_except,
  305. 'HT',
  306. 0,
  307. $request_data->date_start,
  308. $request_data->date_end,
  309. $request_data->product_type,
  310. $request_data->rang,
  311. $request_data->special_code,
  312. $fk_parent_line,
  313. $request_data->fk_fournprice,
  314. $request_data->pa_ht,
  315. $request_data->label,
  316. $request_data->array_options,
  317. $request_data->fk_unit,
  318. $this->element,
  319. $request_data->id
  320. );
  321. if ($updateRes > 0) {
  322. return $updateRes;
  323. }
  324. return false;
  325. }
  326. */
  327. // /**
  328. // * Update a task to given project
  329. // *
  330. // * @param int $id Id of project to update
  331. // * @param int $taskid Id of task to update
  332. // * @param array $request_data Projectline data
  333. // *
  334. // * @url PUT {id}/tasks/{taskid}
  335. // *
  336. // * @return object
  337. // */
  338. /*
  339. public function putLine($id, $lineid, $request_data = null)
  340. {
  341. if(! DolibarrApiAccess::$user->rights->projet->creer) {
  342. throw new RestException(401);
  343. }
  344. $result = $this->project->fetch($id);
  345. if( ! $result ) {
  346. throw new RestException(404, 'Project not found');
  347. }
  348. if( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) {
  349. throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
  350. }
  351. $request_data = (object) $request_data;
  352. $request_data->desc = sanitizeVal($request_data->desc, 'restricthtml');
  353. $updateRes = $this->project->updateline(
  354. $lineid,
  355. $request_data->desc,
  356. $request_data->subprice,
  357. $request_data->qty,
  358. $request_data->remise_percent,
  359. $request_data->tva_tx,
  360. $request_data->localtax1_tx,
  361. $request_data->localtax2_tx,
  362. 'HT',
  363. $request_data->info_bits,
  364. $request_data->date_start,
  365. $request_data->date_end,
  366. $request_data->product_type,
  367. $request_data->fk_parent_line,
  368. 0,
  369. $request_data->fk_fournprice,
  370. $request_data->pa_ht,
  371. $request_data->label,
  372. $request_data->special_code,
  373. $request_data->array_options,
  374. $request_data->fk_unit
  375. );
  376. if ($updateRes > 0) {
  377. $result = $this->get($id);
  378. unset($result->line);
  379. return $this->_cleanObjectDatas($result);
  380. }
  381. return false;
  382. }*/
  383. /**
  384. * Update task general fields (won't touch time spent of task)
  385. *
  386. * @param int $id Id of task to update
  387. * @param array $request_data Datas
  388. *
  389. * @return int
  390. */
  391. public function put($id, $request_data = null)
  392. {
  393. if (!DolibarrApiAccess::$user->rights->projet->creer) {
  394. throw new RestException(401);
  395. }
  396. $result = $this->task->fetch($id);
  397. if (!$result) {
  398. throw new RestException(404, 'Task not found');
  399. }
  400. if (!DolibarrApi::_checkAccessToResource('task', $this->task->id)) {
  401. throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
  402. }
  403. foreach ($request_data as $field => $value) {
  404. if ($field == 'id') {
  405. continue;
  406. }
  407. $this->task->$field = $value;
  408. }
  409. if ($this->task->update(DolibarrApiAccess::$user) > 0) {
  410. return $this->get($id);
  411. } else {
  412. throw new RestException(500, $this->task->error);
  413. }
  414. }
  415. /**
  416. * Delete task
  417. *
  418. * @param int $id Task ID
  419. *
  420. * @return array
  421. */
  422. public function delete($id)
  423. {
  424. if (!DolibarrApiAccess::$user->rights->projet->supprimer) {
  425. throw new RestException(401);
  426. }
  427. $result = $this->task->fetch($id);
  428. if (!$result) {
  429. throw new RestException(404, 'Task not found');
  430. }
  431. if (!DolibarrApi::_checkAccessToResource('task', $this->task->id)) {
  432. throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
  433. }
  434. if (!$this->task->delete(DolibarrApiAccess::$user)) {
  435. throw new RestException(500, 'Error when delete task : '.$this->task->error);
  436. }
  437. return array(
  438. 'success' => array(
  439. 'code' => 200,
  440. 'message' => 'Task deleted'
  441. )
  442. );
  443. }
  444. /**
  445. * Add time spent to a task of a project.
  446. * You can test this API with the following input message
  447. * { "date": "2016-12-31 23:15:00", "duration": 1800, "user_id": 1, "note": "My time test" }
  448. *
  449. * @param int $id Task ID
  450. * @param datetime $date Date (YYYY-MM-DD HH:MI:SS in GMT)
  451. * @param int $duration Duration in seconds (3600 = 1h)
  452. * @param int $user_id User (Use 0 for connected user)
  453. * @param string $note Note
  454. *
  455. * @url POST {id}/addtimespent
  456. * NOTE: Should be "POST {id}/timespent", since POST already implies "add"
  457. *
  458. * @return array
  459. */
  460. public function addTimeSpent($id, $date, $duration, $user_id = 0, $note = '')
  461. {
  462. if (!DolibarrApiAccess::$user->rights->projet->creer) {
  463. throw new RestException(401);
  464. }
  465. $result = $this->task->fetch($id);
  466. if ($result <= 0) {
  467. throw new RestException(404, 'Task not found');
  468. }
  469. if (!DolibarrApi::_checkAccessToResource('project', $this->task->fk_project)) {
  470. throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
  471. }
  472. $uid = $user_id;
  473. if (empty($uid)) {
  474. $uid = DolibarrApiAccess::$user->id;
  475. }
  476. $newdate = dol_stringtotime($date, 1);
  477. $this->task->timespent_date = $newdate;
  478. $this->task->timespent_datehour = $newdate;
  479. $this->task->timespent_withhour = 1;
  480. $this->task->timespent_duration = $duration;
  481. $this->task->timespent_fk_user = $uid;
  482. $this->task->timespent_note = $note;
  483. $result = $this->task->addTimeSpent(DolibarrApiAccess::$user, 0);
  484. if ($result == 0) {
  485. throw new RestException(304, 'Error nothing done. May be object is already validated');
  486. }
  487. if ($result < 0) {
  488. throw new RestException(500, 'Error when adding time: '.$this->task->error);
  489. }
  490. return array(
  491. 'success' => array(
  492. 'code' => 200,
  493. 'message' => 'Time spent added'
  494. )
  495. );
  496. }
  497. /**
  498. * Update time spent for a task of a project.
  499. * You can test this API with the following input message
  500. * { "date": "2016-12-31 23:15:00", "duration": 1800, "user_id": 1, "note": "My time test" }
  501. *
  502. * @param int $id Task ID
  503. * @param int $timespent_id Time spent ID (llx_projet_task_time.rowid)
  504. * @param datetime $date Date (YYYY-MM-DD HH:MI:SS in GMT)
  505. * @param int $duration Duration in seconds (3600 = 1h)
  506. * @param int $user_id User (Use 0 for connected user)
  507. * @param string $note Note
  508. *
  509. * @url PUT {id}/timespent/{timespent_id}
  510. *
  511. * @return array
  512. */
  513. public function putTimeSpent($id, $timespent_id, $date, $duration, $user_id = 0, $note = '')
  514. {
  515. if (!DolibarrApiAccess::$user->rights->projet->creer) {
  516. throw new RestException(401);
  517. }
  518. $this->timespentRecordChecks($id, $timespent_id);
  519. if (!DolibarrApi::_checkAccessToResource('task', $this->task->id)) {
  520. throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
  521. }
  522. $newdate = dol_stringtotime($date, 1);
  523. $this->task->timespent_date = $newdate;
  524. $this->task->timespent_datehour = $newdate;
  525. $this->task->timespent_withhour = 1;
  526. $this->task->timespent_duration = $duration;
  527. $this->task->timespent_fk_user = $user_id ?? DolibarrApiAccess::$user->id;
  528. $this->task->timespent_note = $note;
  529. $result = $this->task->updateTimeSpent(DolibarrApiAccess::$user, 0);
  530. if ($result == 0) {
  531. throw new RestException(304, 'Error nothing done.');
  532. }
  533. if ($result < 0) {
  534. throw new RestException(500, 'Error when updating time spent: '.$this->task->error);
  535. }
  536. return array(
  537. 'success' => array(
  538. 'code' => 200,
  539. 'message' => 'Time spent updated'
  540. )
  541. );
  542. }
  543. /**
  544. * Delete time spent for a task of a project.
  545. *
  546. * @param int $id Task ID
  547. * @param int $timespent_id Time spent ID (llx_projet_task_time.rowid)
  548. *
  549. * @url DELETE {id}/timespent/{timespent_id}
  550. *
  551. * @return array
  552. */
  553. public function deleteTimeSpent($id, $timespent_id)
  554. {
  555. if (!DolibarrApiAccess::$user->rights->projet->supprimer) {
  556. throw new RestException(401);
  557. }
  558. $this->timespentRecordChecks($id, $timespent_id);
  559. if (!DolibarrApi::_checkAccessToResource('task', $this->task->id)) {
  560. throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
  561. }
  562. if ($this->task->delTimeSpent(DolibarrApiAccess::$user, 0) < 0) {
  563. throw new RestException(500, 'Error when deleting time spent: '.$this->task->error);
  564. }
  565. return array(
  566. 'success' => array(
  567. 'code' => 200,
  568. 'message' => 'Time spent deleted'
  569. )
  570. );
  571. }
  572. /**
  573. * Validate task & timespent IDs for timespent API methods.
  574. * Loads the selected task & timespent records.
  575. *
  576. * @param int $id Task ID
  577. * @param int $timespent_id Time spent ID (llx_projet_task_time.rowid)
  578. *
  579. * @return void
  580. */
  581. protected function timespentRecordChecks($id, $timespent_id)
  582. {
  583. if ($this->task->fetch($id) <= 0) {
  584. throw new RestException(404, 'Task not found');
  585. }
  586. if ($this->task->fetchTimeSpent($timespent_id) <= 0) {
  587. throw new RestException(404, 'Timespent not found');
  588. } elseif ($this->task->id != $id) {
  589. throw new RestException(404, 'Timespent not found in selected task');
  590. }
  591. }
  592. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  593. /**
  594. * Clean sensible object datas
  595. *
  596. * @param Object $object Object to clean
  597. * @return Object Object with cleaned properties
  598. */
  599. protected function _cleanObjectDatas($object)
  600. {
  601. // phpcs:enable
  602. $object = parent::_cleanObjectDatas($object);
  603. unset($object->barcode_type);
  604. unset($object->barcode_type_code);
  605. unset($object->barcode_type_label);
  606. unset($object->barcode_type_coder);
  607. unset($object->cond_reglement_id);
  608. unset($object->cond_reglement);
  609. unset($object->fk_delivery_address);
  610. unset($object->shipping_method_id);
  611. unset($object->fk_account);
  612. unset($object->note);
  613. unset($object->fk_incoterms);
  614. unset($object->label_incoterms);
  615. unset($object->location_incoterms);
  616. unset($object->name);
  617. unset($object->lastname);
  618. unset($object->firstname);
  619. unset($object->civility_id);
  620. unset($object->mode_reglement_id);
  621. unset($object->country);
  622. unset($object->country_id);
  623. unset($object->country_code);
  624. unset($object->weekWorkLoad);
  625. unset($object->weekWorkLoad);
  626. //unset($object->lines); // for task we use timespent_lines, but for project we use lines
  627. unset($object->total_ht);
  628. unset($object->total_tva);
  629. unset($object->total_localtax1);
  630. unset($object->total_localtax2);
  631. unset($object->total_ttc);
  632. unset($object->comments);
  633. return $object;
  634. }
  635. /**
  636. * Validate fields before create or update object
  637. *
  638. * @param array $data Array with data to verify
  639. * @return array
  640. * @throws RestException
  641. */
  642. private function _validate($data)
  643. {
  644. $object = array();
  645. foreach (self::$FIELDS as $field) {
  646. if (!isset($data[$field])) {
  647. throw new RestException(400, "$field field missing");
  648. }
  649. $object[$field] = $data[$field];
  650. }
  651. return $object;
  652. }
  653. // \todo
  654. // getSummaryOfTimeSpent
  655. }