dolibarr 22.0.5
api_contracts.class.php
1<?php
2/* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
3 * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21use Luracast\Restler\RestException;
22
23require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
24require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
25
33{
37 public static $FIELDS = array(
38 'socid',
39 'date_contrat',
40 'commercial_signature_id',
41 'commercial_suivi_id'
42 );
43
47 public $contract;
48
52 public function __construct()
53 {
54 global $db, $conf;
55 $this->db = $db;
56 $this->contract = new Contrat($this->db);
57 }
58
68 public function get($id)
69 {
70 if (!DolibarrApiAccess::$user->hasRight('contrat', 'lire')) {
71 throw new RestException(403);
72 }
73
74 $result = $this->contract->fetch($id);
75 if (!$result) {
76 throw new RestException(404, 'Contract not found');
77 }
78
79 if (!DolibarrApi::_checkAccessToResource('contrat', $this->contract->id)) {
80 throw new RestException(403, 'Access to this contract is not allowed for login '.DolibarrApiAccess::$user->login);
81 }
82
83 $this->contract->fetchObjectLinked();
84 return $this->_cleanObjectDatas($this->contract);
85 }
86
107 public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '', $properties = '', $pagination_data = false)
108 {
109 global $db, $conf;
110
111 if (!DolibarrApiAccess::$user->hasRight('contrat', 'lire')) {
112 throw new RestException(403);
113 }
114
115 $obj_ret = array();
116
117 // case of external user, $thirdparty_ids param is ignored and replaced by user's socid
118 $socids = DolibarrApiAccess::$user->socid ?: $thirdparty_ids;
119
120 // If the internal user must only see his customers, force searching by him
121 $search_sale = 0;
122 if (!DolibarrApiAccess::$user->hasRight('societe', 'client', 'voir') && !$socids) {
123 $search_sale = DolibarrApiAccess::$user->id;
124 }
125
126 $sql = "SELECT t.rowid";
127 $sql .= " FROM ".MAIN_DB_PREFIX."contrat AS t LEFT JOIN ".MAIN_DB_PREFIX."contrat_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
128 $sql .= ' WHERE t.entity IN ('.getEntity('contrat').')';
129 if ($socids) {
130 $sql .= " AND t.fk_soc IN (".$this->db->sanitize($socids).")";
131 }
132 // Search on sale representative
133 if ($search_sale && $search_sale != '-1') {
134 if ($search_sale == -2) {
135 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc)";
136 } elseif ($search_sale > 0) {
137 $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
138 }
139 }
140 // Add sql filters
141 if ($sqlfilters) {
142 $errormessage = '';
143 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
144 if ($errormessage) {
145 throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
146 }
147 }
148
149 //this query will return total orders with the filters given
150 $sqlTotals = str_replace('SELECT t.rowid', 'SELECT count(t.rowid) as total', $sql);
151
152 $sql .= $this->db->order($sortfield, $sortorder);
153 if ($limit) {
154 if ($page < 0) {
155 $page = 0;
156 }
157 $offset = $limit * $page;
158
159 $sql .= $this->db->plimit($limit + 1, $offset);
160 }
161
162 $result = $this->db->query($sql);
163
164 if ($result) {
165 $num = $this->db->num_rows($result);
166 $min = min($num, ($limit <= 0 ? $num : $limit));
167 $i = 0;
168 while ($i < $min) {
169 $obj = $this->db->fetch_object($result);
170 $contrat_static = new Contrat($this->db);
171 if ($contrat_static->fetch($obj->rowid)) {
172 $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($contrat_static), $properties);
173 }
174 $i++;
175 }
176 } else {
177 throw new RestException(503, 'Error when retrieve contrat list : '.$this->db->lasterror());
178 }
179
180 //if $pagination_data is true the response will contain element data with all values and element pagination with pagination data(total,page,limit)
181 if ($pagination_data) {
182 $totalsResult = $this->db->query($sqlTotals);
183 $total = $this->db->fetch_object($totalsResult)->total;
184
185 $tmp = $obj_ret;
186 $obj_ret = [];
187
188 $obj_ret['data'] = $tmp;
189 $obj_ret['pagination'] = [
190 'total' => (int) $total,
191 'page' => $page, //count starts from 0
192 'page_count' => ceil((int) $total / $limit),
193 'limit' => $limit
194 ];
195 }
196
197 return $obj_ret;
198 }
199
208 public function post($request_data = null)
209 {
210 if (!DolibarrApiAccess::$user->hasRight('contrat', 'creer')) {
211 throw new RestException(403, "Missing permission: Create/modify contracts/subscriptions");
212 }
213
214 $socid = (int) $request_data['socid'];
215 $thirdpartytmp = new Societe($this->db);
216 $thirdparty_result = $thirdpartytmp->fetch($socid);
217 if ($thirdparty_result < 1) {
218 throw new RestException(404, 'Thirdparty with id='.$socid.' not found or not allowed');
219 }
220 if (!DolibarrApi::_checkAccessToResource('societe', $thirdpartytmp->id)) {
221 throw new RestException(404, 'Thirdparty with id='.$thirdpartytmp->id.' not found or not allowed');
222 }
223
224 // Check mandatory fields
225 $result = $this->_validate($request_data);
226
227 foreach ($request_data as $field => $value) {
228 if ($field === 'caller') {
229 // 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 with the caller
230 $this->contract->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
231 continue;
232 }
233
234 $this->contract->$field = $this->_checkValForAPI($field, $value, $this->contract);
235 }
236 /*if (isset($request_data["lines"])) {
237 $lines = array();
238 foreach ($request_data["lines"] as $line) {
239 array_push($lines, (object) $line);
240 }
241 $this->contract->lines = $lines;
242 }*/
243 if ($this->contract->create(DolibarrApiAccess::$user) < 0) {
244 throw new RestException(500, "Error creating contract", array_merge(array($this->contract->error), $this->contract->errors));
245 }
246
247 return $this->contract->id;
248 }
249
270 public function getLines($id, $sortfield = "d.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '', $properties = '', $pagination_data = false)
271 {
272 if (!DolibarrApiAccess::$user->hasRight('contrat', 'lire')) {
273 throw new RestException(403);
274 }
275
276 $result = $this->contract->fetch($id);
277 if (!$result) {
278 throw new RestException(404, 'Contract not found');
279 }
280
281 if (!DolibarrApi::_checkAccessToResource('contrat', $this->contract->id)) {
282 throw new RestException(403, 'Access to this contract is not allowed for login '.DolibarrApiAccess::$user->login);
283 }
284
285 $obj_ret = [];
286
287 $sql = "SELECT d.rowid";
288 $sql .= " FROM ".$this->db->prefix()."contratdet AS d";
289 $sql .= " LEFT JOIN ".$this->db->prefix()."contrat AS c ON (c.rowid = d.fk_contrat)";
290 $sql .= " LEFT JOIN ".$this->db->prefix()."contratdet_extrafields AS ef ON (ef.fk_object = d.rowid)";
291 $sql .= " WHERE d.fk_contrat = ".((int) $id);
292 $sql .= ' AND c.entity IN ('.getEntity('contrat').')';
293
294 if ($sqlfilters) {
295 $errormessage = '';
296 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
297 if ($errormessage) {
298 throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
299 }
300 }
301
302 $sqlTotals = str_replace('SELECT d.rowid', 'SELECT count(d.rowid) as total', $sql);
303
304 $sql .= $this->db->order($sortfield, $sortorder);
305 if ($limit) {
306 if ($page < 0) {
307 $page = 0;
308 }
309 $offset = $limit * $page;
310
311 $sql .= $this->db->plimit($limit + 1, $offset);
312 }
313
314 $result = $this->db->query($sql);
315 if ($result) {
316 $num = $this->db->num_rows($result);
317 $min = min($num, ($limit <= 0 ? $num : $limit));
318 $i = 0;
319 while ($i < $min) {
320 $obj = $this->db->fetch_object($result);
321 $contratdet_static = new ContratLigne($this->db);
322 if ($contratdet_static->fetch($obj->rowid)) {
323 $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($contratdet_static), $properties);
324 }
325 $i++;
326 }
327 } else {
328 throw new RestException(503, 'Error when retrieve contratdet list : '.$this->db->lasterror());
329 }
330
331 if ($pagination_data) {
332 $totalsResult = $this->db->query($sqlTotals);
333 $total = $this->db->fetch_object($totalsResult)->total;
334
335 $tmp = $obj_ret;
336 $obj_ret = [];
337 $obj_ret['data'] = $tmp;
338 $obj_ret['pagination'] = [
339 'total' => (int) $total,
340 'page' => $page,
341 'page_count' => ceil((int) $total / $limit),
342 'limit' => $limit
343 ];
344 }
345
346 return $obj_ret;
347 }
348
361 public function postLine($id, $request_data = null)
362 {
363 if (!DolibarrApiAccess::$user->hasRight('contrat', 'creer')) {
364 throw new RestException(403);
365 }
366
367 $result = $this->contract->fetch($id);
368 if (!$result) {
369 throw new RestException(404, 'Contract not found');
370 }
371
372 if (!DolibarrApi::_checkAccessToResource('contrat', $this->contract->id)) {
373 throw new RestException(403, 'Access to this contract is not allowed for login '.DolibarrApiAccess::$user->login);
374 }
375
376 $request_data = (object) $request_data;
377
378 $request_data->desc = sanitizeVal($request_data->desc, 'restricthtml');
379 $request_data->price_base_type = sanitizeVal($request_data->price_base_type);
380
381 $updateRes = $this->contract->addline(
382 $request_data->desc,
383 $request_data->subprice,
384 $request_data->qty,
385 $request_data->tva_tx,
386 $request_data->localtax1_tx,
387 $request_data->localtax2_tx,
388 $request_data->fk_product,
389 $request_data->remise_percent,
390 $request_data->date_start,
391 $request_data->date_end,
392 $request_data->price_base_type ? $request_data->price_base_type : 'HT',
393 $request_data->subprice_excl_tax,
394 $request_data->info_bits,
395 $request_data->fk_fournprice,
396 $request_data->pa_ht,
397 $request_data->array_options,
398 $request_data->fk_unit,
399 $request_data->rang
400 );
401
402 if ($updateRes > 0) {
403 return $updateRes;
404 }
405 return false;
406 }
407
421 public function putLine($id, $lineid, $request_data = null)
422 {
423 if (!DolibarrApiAccess::$user->hasRight('contrat', 'creer')) {
424 throw new RestException(403);
425 }
426
427 $result = $this->contract->fetch($id);
428 if (!$result) {
429 throw new RestException(404, 'Contrat not found');
430 }
431
432 if (!DolibarrApi::_checkAccessToResource('contrat', $this->contract->id)) {
433 throw new RestException(403, 'Access to this contract is not allowed for login '.DolibarrApiAccess::$user->login);
434 }
435
436 $request_data = (object) $request_data;
437
438 $request_data->desc = sanitizeVal($request_data->desc, 'restricthtml');
439 $request_data->price_base_type = sanitizeVal($request_data->price_base_type);
440
441 $updateRes = $this->contract->updateline(
442 $lineid,
443 $request_data->desc,
444 $request_data->subprice,
445 $request_data->qty,
446 $request_data->remise_percent,
447 $request_data->date_start,
448 $request_data->date_end,
449 $request_data->tva_tx,
450 $request_data->localtax1_tx,
451 $request_data->localtax2_tx,
452 $request_data->date_start_real,
453 $request_data->date_end_real,
454 $request_data->price_base_type ? $request_data->price_base_type : 'HT',
455 $request_data->info_bits,
456 $request_data->fk_fourn_price,
457 $request_data->pa_ht,
458 $request_data->array_options,
459 $request_data->fk_unit
460 );
461
462 if ($updateRes > 0) {
463 if (getDolGlobalInt('API_CONTRAT_PUTLINE_OUTPUT_LINE_ONLY')) {
464 $result = new ContratLigne($this->db);
465 $result->fetch($lineid);
466 foreach (array(
467 'array_languages',
468 'contacts_ids',
469 'linked_objects',
470 'linkedObjectsIds',
471 'actiontypecode',
472 'module',
473 'canvas',
474 'user',
475 'origin',
476 'origin_id',
477 'ref_ext',
478 'status',
479 'country_id',
480 'country_code',
481 'state_id',
482 'region_id',
483 'barcode_type',
484 'barcode_type_coder',
485 'mode_reglement_id',
486 'cond_reglement_id',
487 'demand_reason_id',
488 'transport_mode_id',
489 'shipping_method',
490 'shipping_method_id',
491 'model_pdf',
492 'last_main_doc',
493 'fk_bank',
494 'fk_account',
495 'lines',
496 'name',
497 'firstname',
498 'lastname',
499 'date_creation',
500 'date_validation',
501 'date_modification',
502 'date_cloture',
503 'user_author',
504 'user_creation',
505 'user_creation_id',
506 'user_valid',
507 'user_validation',
508 'user_validation_id',
509 'user_modification',
510 'user_modification_id',
511 'cond_reglement_supplier_id',
512 'deposit_percent',
513 'retained_warranty_fk_cond_reglement',
514 'date_commande',
515 'fk_user_creat',
516 'fk_user_modif',
517 'specimen',
518 'fk_unit',
519 'date_debut_prevue',
520 'date_debut_reel',
521 'date_fin_prevue',
522 'date_fin_reel',
523 'weight',
524 'weight_units',
525 'width',
526 'width_units',
527 'length',
528 'length_units',
529 'height',
530 'height_units',
531 'surface',
532 'surface_units',
533 'volume',
534 'volume_units',
535 'multilangs',
536 'desc',
537 'product',
538 'fk_product_type',
539 'warehouse_id',
540 'totalpaid',
541 'type',
542 'libelle'
543 ) as $fieldToUnset) {
544 unset($result->{$fieldToUnset});
545 }
546 } else {
547 $result = $this->get($id);
548 unset($result->line);
549 }
550 return $this->_cleanObjectDatas($result);
551 }
552
553 return false;
554 }
555
569 public function activateLine($id, $lineid, $datestart, $dateend = null, $comment = null)
570 {
571 if (!DolibarrApiAccess::$user->hasRight('contrat', 'creer')) {
572 throw new RestException(403);
573 }
574
575 $result = $this->contract->fetch($id);
576 if (!$result) {
577 throw new RestException(404, 'Contrat not found');
578 }
579
580 if (!DolibarrApi::_checkAccessToResource('contrat', $this->contract->id)) {
581 throw new RestException(403, 'Access to this contract is not allowed for login '.DolibarrApiAccess::$user->login);
582 }
583
584 $updateRes = $this->contract->active_line(DolibarrApiAccess::$user, $lineid, (int) $datestart, $dateend, $comment);
585
586 if ($updateRes > 0) {
587 $result = $this->get($id);
588 unset($result->line);
589 return $this->_cleanObjectDatas($result);
590 }
591
592 return false;
593 }
594
607 public function unactivateLine($id, $lineid, $datestart, $comment = null)
608 {
609 if (!DolibarrApiAccess::$user->hasRight('contrat', 'creer')) {
610 throw new RestException(403);
611 }
612
613 $result = $this->contract->fetch($id);
614 if (!$result) {
615 throw new RestException(404, 'Contrat not found');
616 }
617
618 if (!DolibarrApi::_checkAccessToResource('contrat', $this->contract->id)) {
619 throw new RestException(403, 'Access to this contract is not allowed for login '.DolibarrApiAccess::$user->login);
620 }
621
622 $updateRes = $this->contract->close_line(DolibarrApiAccess::$user, $lineid, (int) $datestart, $comment);
623
624 if ($updateRes > 0) {
625 $result = $this->get($id);
626 unset($result->line);
627 return $this->_cleanObjectDatas($result);
628 }
629
630 return false;
631 }
632
647 public function deleteLine($id, $lineid)
648 {
649 if (!DolibarrApiAccess::$user->hasRight('contrat', 'creer')) {
650 throw new RestException(403);
651 }
652
653 $result = $this->contract->fetch($id);
654 if (!$result) {
655 throw new RestException(404, 'Contrat not found');
656 }
657
658 if (!DolibarrApi::_checkAccessToResource('contrat', $this->contract->id)) {
659 throw new RestException(403, 'Access to this contract is not allowed for login '.DolibarrApiAccess::$user->login);
660 }
661
662 // TODO Check the lineid $lineid is a line of object
663
664 $updateRes = $this->contract->deleteLine($lineid, DolibarrApiAccess::$user);
665 if ($updateRes > 0) {
666 return $this->get($id);
667 } else {
668 throw new RestException(405, $this->contract->error);
669 }
670 }
671
681 public function put($id, $request_data = null)
682 {
683 if (!DolibarrApiAccess::$user->hasRight('contrat', 'creer')) {
684 throw new RestException(403);
685 }
686 $result = $this->contract->fetch($id);
687 if (!$result) {
688 throw new RestException(404, 'Contrat not found');
689 }
690
691 $old_socid = $this->contract->socid;
692 $oldthirdpartytmp = new Societe($this->db);
693 $old_thirdparty_result = $oldthirdpartytmp->fetch($old_socid);
694 if ($old_thirdparty_result < 1) {
695 throw new RestException(404, 'Thirdparty with id='.$old_socid.' not found or not allowed');
696 }
697 if (!DolibarrApi::_checkAccessToResource('societe', $old_socid)) {
698 throw new RestException(403, 'Access to old thirdparty='.$old_socid.' is not allowed for login '.DolibarrApiAccess::$user->login);
699 }
700
701 if (!DolibarrApi::_checkAccessToResource('contrat', $this->contract->id)) {
702 throw new RestException(403, 'Access to this contract is not allowed for login '.DolibarrApiAccess::$user->login);
703 }
704 foreach ($request_data as $field => $value) {
705 if ($field == 'id') {
706 continue;
707 }
708 if ($field === 'caller') {
709 // 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 with the caller
710 $this->contract->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
711 continue;
712 }
713 if ($field == 'array_options' && is_array($value)) {
714 foreach ($value as $index => $val) {
715 $this->contract->array_options[$index] = $this->_checkValForAPI($field, $val, $this->contract);
716 }
717 continue;
718 }
719
720 if ($field == 'socid') {
721 $new_socid = (int) $value;
722 $loopthirdpartytmp = new Societe($this->db);
723 $new_thirdparty_result = $loopthirdpartytmp->fetch($new_socid);
724 if ($new_thirdparty_result < 1) {
725 throw new RestException(404, 'Thirdparty with id='.$new_socid.' not found or not allowed');
726 }
727 if (!DolibarrApi::_checkAccessToResource('societe', $new_socid)) {
728 throw new RestException(403, 'Access to new thirdparty='.$new_socid.' is not allowed for login '.DolibarrApiAccess::$user->login);
729 }
730 }
731
732 $this->contract->$field = $this->_checkValForAPI($field, $value, $this->contract);
733 }
734
735 if ($this->contract->update(DolibarrApiAccess::$user) > 0) {
736 return $this->get($id);
737 } else {
738 throw new RestException(500, $this->contract->error);
739 }
740 }
741
751 public function delete($id)
752 {
753 if (!DolibarrApiAccess::$user->hasRight('contrat', 'supprimer')) {
754 throw new RestException(403, 'Missing permission: Delete contracts/subscriptions');
755 }
756 $result = $this->contract->fetch($id);
757 if (!$result) {
758 throw new RestException(404, 'Contract not found');
759 }
760
761 if (!DolibarrApi::_checkAccessToResource('contrat', $this->contract->id)) {
762 throw new RestException(403, 'Access to this contract is not allowed for login '.DolibarrApiAccess::$user->login);
763 }
764
765 if (!$this->contract->delete(DolibarrApiAccess::$user)) {
766 throw new RestException(500, 'Error when delete contract : '.$this->contract->error);
767 }
768
769 return array(
770 'success' => array(
771 'code' => 200,
772 'message' => 'Contract deleted'
773 )
774 );
775 }
776
796 public function validate($id, $notrigger = 0)
797 {
798 if (!DolibarrApiAccess::$user->hasRight('contrat', 'creer')) {
799 throw new RestException(403);
800 }
801 $result = $this->contract->fetch($id);
802 if (!$result) {
803 throw new RestException(404, 'Contract not found');
804 }
805
806 if (!DolibarrApi::_checkAccessToResource('contrat', $this->contract->id)) {
807 throw new RestException(403, 'Access to this contract is not allowed for login '.DolibarrApiAccess::$user->login);
808 }
809
810 $result = $this->contract->validate(DolibarrApiAccess::$user, '', $notrigger);
811 if ($result == 0) {
812 throw new RestException(304, 'Error nothing done. May be object is already validated');
813 }
814 if ($result < 0) {
815 throw new RestException(500, 'Error when validating Contract: '.$this->contract->error);
816 }
817
818 return array(
819 'success' => array(
820 'code' => 200,
821 'message' => 'Contract validated (Ref='.$this->contract->ref.')'
822 )
823 );
824 }
825
845 public function close($id, $notrigger = 0)
846 {
847 if (!DolibarrApiAccess::$user->hasRight('contrat', 'creer')) {
848 throw new RestException(403);
849 }
850 $result = $this->contract->fetch($id);
851 if (!$result) {
852 throw new RestException(404, 'Contract not found');
853 }
854
855 if (!DolibarrApi::_checkAccessToResource('contrat', $this->contract->id)) {
856 throw new RestException(403, 'Access to this contract is not allowed for login '.DolibarrApiAccess::$user->login);
857 }
858
859 $result = $this->contract->closeAll(DolibarrApiAccess::$user, $notrigger);
860 if ($result == 0) {
861 throw new RestException(304, 'Error nothing done. May be object is already close');
862 }
863 if ($result < 0) {
864 throw new RestException(500, 'Error when closing Contract: '.$this->contract->error);
865 }
866
867 return array(
868 'success' => array(
869 'code' => 200,
870 'message' => 'Contract closed (Ref='.$this->contract->ref.'). All services were closed.'
871 )
872 );
873 }
874
875
876
877 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
884 protected function _cleanObjectDatas($object)
885 {
886 // phpcs:enable
887 $object = parent::_cleanObjectDatas($object);
888
889 unset($object->address);
890 unset($object->civility_id);
891
892 return $object;
893 }
894
902 private function _validate($data)
903 {
904 if ($data === null) {
905 $data = array();
906 }
907 $contrat = array();
908 foreach (Contracts::$FIELDS as $field) {
909 if (!isset($data[$field])) {
910 throw new RestException(400, "$field field missing");
911 }
912 $contrat[$field] = $data[$field];
913 }
914 return $contrat;
915 }
916}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $thirdparty_ids='', $sqlfilters='', $properties='', $pagination_data=false)
List contracts.
putLine($id, $lineid, $request_data=null)
Update a line to given contract.
_validate($data)
Validate fields before create or update object.
put($id, $request_data=null)
Update contract general fields (won't touch lines of contract)
deleteLine($id, $lineid)
Delete a line to given contract.
_cleanObjectDatas($object)
Clean sensible object datas.
activateLine($id, $lineid, $datestart, $dateend=null, $comment=null)
Activate a service line of a given contract.
validate($id, $notrigger=0)
Validate a contract.
post($request_data=null)
Create contract object.
unactivateLine($id, $lineid, $datestart, $comment=null)
Unactivate a service line of a given contract.
__construct()
Constructor.
close($id, $notrigger=0)
Close all services of a contract.
getLines($id, $sortfield="d.rowid", $sortorder='ASC', $limit=100, $page=0, $sqlfilters='', $properties='', $pagination_data=false)
Get lines of a contract.
postLine($id, $request_data=null)
Add a line to given contract.
Class to manage lines of contracts.
Class for API REST v1.
Definition api.class.php:33
_filterObjectProperties($object, $properties)
Filter properties that will be returned on object.
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid')
Check access by user to a given resource.
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
Definition api.class.php:98
Class to manage third parties objects (customers, suppliers, prospects...)
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79