dolibarr 25.0.0-alpha
api_receptions.class.php
1<?php
2/* Copyright (C) 2022 Quatadah Nasdami <quatadah.nasdami@gmail.com>
3 * Copyright (C) 2022 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2025 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2026 Nick Fragoulis
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22use Luracast\Restler\RestException;
23
24require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
25require_once DOL_DOCUMENT_ROOT.'/reception/class/receptionlinebatch.class.php';
26require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
27require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
28require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php';
29
37{
41 public static $FIELDS = array(
42 'socid',
43 'origin_id',
44 'origin_type',
45 );
46
50 public $reception;
51
55 public function __construct()
56 {
57 global $db, $conf;
58 $this->db = $db;
59 $this->reception = new Reception($this->db);
60 }
61
71 public function get($id)
72 {
73 if (!DolibarrApiAccess::$user->hasRight('reception', 'lire')) {
74 throw new RestException(403);
75 }
76
77 $result = $this->reception->fetch($id);
78 if (!$result) {
79 throw new RestException(404, 'Reception not found');
80 }
81
82 if (!DolibarrApi::_checkAccessToResource('reception', $this->reception->id)) {
83 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
84 }
85
86 $this->reception->fetchObjectLinked();
87 return $this->_cleanObjectDatas($this->reception);
88 }
89
90
91
111 public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '', $properties = '', $pagination_data = false)
112 {
113 if (!DolibarrApiAccess::$user->hasRight('reception', 'lire')) {
114 throw new RestException(403);
115 }
116
117 $obj_ret = array();
118
119 // case of external user, $thirdparty_ids param is ignored and replaced by user's socid
120 $socids = DolibarrApiAccess::$user->socid ?: $thirdparty_ids;
121
122 // If the internal user must only see his customers, force searching by him
123 $search_sale = 0;
124 if (!DolibarrApiAccess::$user->hasRight('societe', 'client', 'voir') && !$socids) {
125 $search_sale = DolibarrApiAccess::$user->id;
126 }
127
128 $sql = "SELECT t.rowid";
129 $sql .= " FROM ".MAIN_DB_PREFIX."reception AS t";
130 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."reception_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
131 if (preg_match("/el\.fk_source:=:\d+/", $sqlfilters)) {
132 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = t.rowid AND el.targettype = 'reception' AND el.sourcetype = 'order_supplier'";
133 }
134 $sql .= ' WHERE t.entity IN ('.getEntity('reception').')';
135 if ($socids) {
136 $sql .= " AND t.fk_soc IN (".$this->db->sanitize($socids).")";
137 }
138 // Search on sale representative
139 if ($search_sale && $search_sale != '-1') {
140 if ($search_sale == -2) {
141 $sql .= " AND ".getSalesRepresentativeSqlFilter('t.fk_soc', 0, 1);
142 } elseif ($search_sale > 0) {
143 $sql .= " AND ".getSalesRepresentativeSqlFilter('t.fk_soc', (int) $search_sale);
144 }
145 }
146 // Add sql filters
147 if ($sqlfilters) {
148 $errormessage = '';
149 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
150 if ($errormessage) {
151 throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
152 }
153 }
154
155 //this query will return total receptions with the filters given
156 $sqlTotals = str_replace('SELECT t.rowid', 'SELECT count(t.rowid) as total', $sql);
157
158 $sql .= $this->db->order($sortfield, $sortorder);
159 if ($limit) {
160 if ($page < 0) {
161 $page = 0;
162 }
163 $offset = $limit * $page;
164
165 $sql .= $this->db->plimit($limit + 1, $offset);
166 }
167
168 dol_syslog("API Rest request");
169 $result = $this->db->query($sql);
170
171 if ($result) {
172 $num = $this->db->num_rows($result);
173 $min = min($num, ($limit <= 0 ? $num : $limit));
174 $i = 0;
175 while ($i < $min) {
176 $obj = $this->db->fetch_object($result);
177 $reception_static = new Reception($this->db);
178 if ($reception_static->fetch($obj->rowid)) {
179 $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($reception_static), $properties);
180 }
181 $i++;
182 }
183 } else {
184 throw new RestException(503, 'Error when retrieve commande list : '.$this->db->lasterror());
185 }
186
187 //if $pagination_data is true the response will contain element data with all values and element pagination with pagination data(total,page,limit)
188 if ($pagination_data) {
189 $totalsResult = $this->db->query($sqlTotals);
190 $total = $this->db->fetch_object($totalsResult)->total;
191
192 $tmp = $obj_ret;
193 $obj_ret = [];
194
195 $obj_ret['data'] = $tmp;
196 $obj_ret['pagination'] = [
197 'total' => (int) $total,
198 'page' => $page, //count starts from 0
199 'page_count' => ceil((int) $total / $limit),
200 'limit' => $limit
201 ];
202 }
203
204 return $obj_ret;
205 }
206
215 public function post($request_data = null)
216 {
217 if (!DolibarrApiAccess::$user->hasRight('reception', 'creer')) {
218 throw new RestException(403, "Insufficiant rights");
219 }
220 // Check mandatory fields
221 $result = $this->_validate($request_data);
222
223 foreach ($request_data as $field => $value) {
224 if ($field === 'caller') {
225 // 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
226 $this->reception->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
227 continue;
228 }
229
230 $this->reception->$field = $this->_checkValForAPI($field, $value, $this->reception);
231 }
232 if (isset($request_data["lines"]) && is_array($request_data['lines'])) {
233 $lines = array();
234 foreach ($request_data["lines"] as $line) {
235 $receptionline = new ReceptionLineBatch($this->db);
236
237 $receptionline->fk_product = $line['fk_product'];
238 $receptionline->fk_entrepot = $line['fk_entrepot'];
239 $receptionline->fk_element = $line['fk_element'] ?? $line['origin_id']; // example: purchase order id. this->origin is 'supplier_order'
240 $receptionline->origin_line_id = $line['fk_elementdet'] ?? $line['origin_line_id']; // example: purchase order id
241 $receptionline->fk_elementdet = $line['fk_elementdet'] ?? $line['origin_line_id']; // example: purchase order line id
242 $receptionline->origin_type = $line['element_type'] ?? $line['origin_type']; // example 'supplier_order'
243 $receptionline->element_type = $line['element_type'] ?? $line['origin_type']; // example 'supplier_order'
244 $receptionline->qty = $line['qty'];
245 //$receptionline->rang = $line['rang'];
246 $receptionline->array_options = $line['array_options'];
247 $receptionline->batch = $line['batch'];
248 $receptionline->eatby = $line['eatby'];
249 $receptionline->sellby = $line['sellby'];
250 $receptionline->cost_price = $line['cost_price'];
251 $receptionline->status = $line['status'];
252
253 $lines[] = $receptionline;
254 }
255 $this->reception->lines = $lines;
256 }
257
258 if ($this->reception->create(DolibarrApiAccess::$user) < 0) {
259 throw new RestException(500, "Error creating reception", array_merge(array($this->reception->error), $this->reception->errors));
260 }
261
262 return $this->reception->id;
263 }
264
279 public function getLines($id)
280 {
281 if (!DolibarrApiAccess::$user->hasRight('reception', 'lire')) {
282 throw new RestException(403);
283 }
284
285 $result = $this->reception->fetch($id);
286 if (!$result) {
287 throw new RestException(404, 'Reception not found');
288 }
289
290 if (!DolibarrApi::_checkAccessToResource('reception', $this->reception->id)) {
291 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
292 }
293
294 // fetch() already loaded the lines with the right reader (fetch_lines() when the reception
295 // comes from a supplier order, fetch_lines_free() otherwise), so we don't reload them here.
296 $result = array();
297 foreach ($this->reception->lines as $line) {
298 array_push($result, $this->_cleanObjectDatas($line));
299 }
300 return $result;
301 }
302
330 public function postLine($id, $fk_origin_line = 0, $qty = 0, $warehouse_id = 0, $batch = '', $eatby = '', $sellby = '', $cost_price = 0, $comment = '')
331 {
332 if (!DolibarrApiAccess::$user->hasRight('reception', 'creer')) {
333 throw new RestException(403);
334 }
335
336 $result = $this->reception->fetch($id);
337 if (!$result) {
338 throw new RestException(404, 'Reception not found');
339 }
340
341 if (!DolibarrApi::_checkAccessToResource('reception', $this->reception->id)) {
342 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
343 }
344
345 // A line can only be added while the reception is a draft (no stock movement yet).
346 if ((int) $this->reception->status != Reception::STATUS_DRAFT) {
347 throw new RestException(405, 'Lines can only be added to a draft reception');
348 }
349
350 $fk_origin_line = (int) $fk_origin_line;
351 if ($fk_origin_line <= 0) {
352 throw new RestException(400, 'Field fk_origin_line is mandatory');
353 }
354
355 $qty = (float) $qty;
356 if ($qty <= 0) {
357 throw new RestException(400, 'Field qty is mandatory and must be greater than 0');
358 }
359
360 $orderline = new CommandeFournisseurLigne($this->db);
361 $resorderline = $orderline->fetch($fk_origin_line);
362 if ($resorderline <= 0) {
363 throw new RestException(404, 'Origin supplier order line '.$fk_origin_line.' not found');
364 }
365 // A reception is linked to one supplier order only (Reception::fetch() joins a single
366 // origin), and Reception::getStatusDispatch() counts the lines of that order: refuse a
367 // line taken from another order, which would be lost for both objects.
368 if ($this->reception->origin_id > 0 && (int) $orderline->fk_commande != (int) $this->reception->origin_id) {
369 throw new RestException(400, 'Origin line '.$fk_origin_line.' does not belong to the supplier order of this reception');
370 }
371 // ReceptionLineBatch::create() refuses a line without product, and a line without
372 // product would move no stock anyway.
373 if (empty($orderline->fk_product)) {
374 throw new RestException(400, 'Origin line '.$fk_origin_line.' has no product: only product lines can be received');
375 }
376
377 $eatbydate = (dol_strlen((string) $eatby) == 0 ? null : (is_numeric($eatby) ? (int) $eatby : dol_stringtotime($eatby)));
378 $sellbydate = (dol_strlen((string) $sellby) == 0 ? null : (is_numeric($sellby) ? (int) $sellby : dol_stringtotime($sellby)));
379
380 // addline() stacks the line in memory and runs native validation (warehouse requirement,
381 // lot number requirement, mandatory eat-by/sell-by dates).
382 $addResult = $this->reception->addline((int) $warehouse_id, $fk_origin_line, $qty, array(), trim((string) $comment), $eatbydate, $sellbydate, trim((string) $batch), $cost_price);
383 if ($addResult < 0) {
384 // Every rejection of addline() comes from a value provided by the caller.
385 throw new RestException(400, $this->reception->errorsToString() ? $this->reception->errorsToString() : 'Error while adding reception line');
386 }
387
388 // addline() only fills $this->reception->lines; persist the line just stacked, the same
389 // way Reception::create() does.
390 $line = end($this->reception->lines);
391
392 $createRes = $line->create(DolibarrApiAccess::$user);
393 if ($createRes > 0) {
394 return $createRes;
395 }
396
397 throw new RestException(500, $line->errorsToString());
398 }
399
423 public function putLine($id, $lineid, $qty = 0, $warehouse_id = 0)
424 {
425 if (!DolibarrApiAccess::$user->hasRight('reception', 'creer')) {
426 throw new RestException(403);
427 }
428
429 $result = $this->reception->fetch($id);
430 if (!$result) {
431 throw new RestException(404, 'Reception not found');
432 }
433
434 if (!DolibarrApi::_checkAccessToResource('reception', $this->reception->id)) {
435 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
436 }
437
438 // A line can only be edited while the reception is a draft (no stock movement yet).
439 if ((int) $this->reception->status != Reception::STATUS_DRAFT) {
440 throw new RestException(405, 'Only draft reception lines can be updated');
441 }
442
443 $qty = (float) $qty;
444 if ($qty <= 0) {
445 throw new RestException(400, 'Field qty is mandatory and must be greater than 0');
446 }
447
448 $line = $this->fetchLineOfReception($lineid);
449
450 $line->qty = $qty;
451 if ($warehouse_id > 0) {
452 $line->fk_entrepot = (int) $warehouse_id;
453 }
454
455 $updateRes = $line->update(DolibarrApiAccess::$user);
456 if ($updateRes > 0) {
457 return $this->get($id);
458 }
459
460 throw new RestException(500, $line->errorsToString());
461 }
462
481 public function deleteLine($id, $lineid)
482 {
483 if (!DolibarrApiAccess::$user->hasRight('reception', 'creer')) {
484 throw new RestException(403);
485 }
486
487 $result = $this->reception->fetch($id);
488 if (!$result) {
489 throw new RestException(404, 'Reception not found');
490 }
491
492 if (!DolibarrApi::_checkAccessToResource('reception', $this->reception->id)) {
493 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
494 }
495
496 // A line can only be deleted while the reception is a draft (no stock movement yet).
497 if ((int) $this->reception->status != Reception::STATUS_DRAFT) {
498 throw new RestException(405, 'Only draft reception lines can be deleted');
499 }
500
501 $line = $this->fetchLineOfReception($lineid);
502
503 $deleteRes = $line->delete(DolibarrApiAccess::$user);
504 if ($deleteRes > 0) {
505 return $this->get($id);
506 }
507
508 throw new RestException(500, $line->errorsToString());
509 }
510
519 private function fetchLineOfReception($lineid)
520 {
521 $line = new ReceptionLineBatch($this->db);
522 // fetch() returns 1 even when no row matches, so we check the loaded id.
523 $resline = $line->fetch($lineid);
524 if ($resline <= 0 || empty($line->id)) {
525 throw new RestException(404, 'Reception line not found');
526 }
527 if ((int) $line->fk_reception != (int) $this->reception->id) {
528 throw new RestException(404, 'Line '.((int) $lineid).' is not a line of reception '.((int) $this->reception->id));
529 }
530
531 return $line;
532 }
533
543 public function put($id, $request_data = null)
544 {
545 if (!DolibarrApiAccess::$user->hasRight('reception', 'creer')) {
546 throw new RestException(403);
547 }
548
549 $result = $this->reception->fetch($id);
550 if (!$result) {
551 throw new RestException(404, 'Reception not found');
552 }
553
554 if (!DolibarrApi::_checkAccessToResource('reception', $this->reception->id)) {
555 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
556 }
557 foreach ($request_data as $field => $value) {
558 if ($field == 'id') {
559 continue;
560 }
561 if ($field === 'caller') {
562 // 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
563 $this->reception->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
564 continue;
565 }
566
567 if ($field == 'array_options' && is_array($value)) {
568 foreach ($value as $index => $val) {
569 $this->reception->array_options[$index] = $this->_checkValExtrafieldsForAPI($index, $val, $this->reception);
570 }
571 continue;
572 }
573
574 $this->reception->$field = $this->_checkValForAPI($field, $value, $this->reception);
575 }
576
577 if ($this->reception->update(DolibarrApiAccess::$user) > 0) {
578 return $this->get($id);
579 } else {
580 throw new RestException(500, $this->reception->errorsToString());
581 }
582 }
583
592 public function delete($id)
593 {
594 if (!DolibarrApiAccess::$user->hasRight('reception', 'supprimer')) {
595 throw new RestException(403);
596 }
597 $result = $this->reception->fetch($id);
598 if (!$result) {
599 throw new RestException(404, 'Reception not found');
600 }
601
602 if (!DolibarrApi::_checkAccessToResource('reception', $this->reception->id)) {
603 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
604 }
605
606 if (!$this->reception->delete(DolibarrApiAccess::$user)) {
607 throw new RestException(500, 'Error when deleting reception : '.$this->reception->errorsToString());
608 }
609
610 return array(
611 'success' => array(
612 'code' => 200,
613 'message' => 'Reception deleted'
614 )
615 );
616 }
617
631 public function validate($id, $notrigger = 0)
632 {
633 if (!DolibarrApiAccess::$user->hasRight('reception', 'creer')) {
634 throw new RestException(403);
635 }
636 $result = $this->reception->fetch($id);
637 if (!$result) {
638 throw new RestException(404, 'Reception not found');
639 }
640
641 if (!DolibarrApi::_checkAccessToResource('reception', $this->reception->id)) {
642 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
643 }
644
645 $result = $this->reception->valid(DolibarrApiAccess::$user, $notrigger);
646 if ($result == 0) {
647 throw new RestException(304, 'Error nothing done. May be object is already validated');
648 }
649 if ($result < 0) {
650 throw new RestException(500, 'Error when validating Reception: '.$this->reception->errorsToString());
651 }
652
653 // Reload reception
654 $result = $this->reception->fetch($id);
655
656 $this->reception->fetchObjectLinked();
657 return $this->_cleanObjectDatas($this->reception);
658 }
659
660
661 // /**
662 // * Classify the reception as invoiced
663 // *
664 // * @param int $id Id of the reception
665 // *
666 // * @url POST {id}/setinvoiced
667 // *
668 // * @return int
669 // *
670 // * @throws RestException 400
671 // * @throws RestException 401
672 // * @throws RestException 404
673 // * @throws RestException 405
674 // */
675 /*
676 public function setinvoiced($id)
677 {
678
679 if (!DolibarrApiAccess::$user->hasRight('reception', 'creer')) {
680 throw new RestException(403);
681 }
682 if (empty($id)) {
683 throw new RestException(400, 'Reception ID is mandatory');
684 }
685 $result = $this->reception->fetch($id);
686 if (!$result) {
687 throw new RestException(404, 'Reception not found');
688 }
689
690 $result = $this->reception->classifyBilled(DolibarrApiAccess::$user);
691 if ($result < 0) {
692 throw new RestException(400, $this->reception->errorsToString());
693 }
694 return $result;
695 }
696 */
697
698
699 // /**
700 // * Create a reception using an existing order.
701 // *
702 // * @param int $orderid Id of the order
703 // *
704 // * @url POST /createfromorder/{orderid}
705 // *
706 // * @return int
707 // * @throws RestException 400
708 // * @throws RestException 401
709 // * @throws RestException 404
710 // * @throws RestException 405
711 // */
712 /*
713 public function createShipmentFromOrder($orderid)
714 {
715
716 require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php';
717
718 if (!DolibarrApiAccess::$user->hasRight('reception', 'lire')) {
719 throw new RestException(403);
720 }
721 if (!DolibarrApiAccess::$user->hasRight('reception', 'creer')) {
722 throw new RestException(403);
723 }
724 if (empty($proposalid)) {
725 throw new RestException(400, 'Order ID is mandatory');
726 }
727
728 $order = new Commande($this->db);
729 $result = $order->fetch($proposalid);
730 if (!$result) {
731 throw new RestException(404, 'Order not found');
732 }
733
734 $result = $this->reception->createFromOrder($order, DolibarrApiAccess::$user);
735 if( $result < 0) {
736 throw new RestException(405, $this->reception->errorsToString());
737 }
738 $this->reception->fetchObjectLinked();
739 return $this->_cleanObjectDatas($this->reception);
740 }
741 */
742
753 public function close($id, $notrigger = 0)
754 {
755 if (!DolibarrApiAccess::$user->hasRight('reception', 'creer')) {
756 throw new RestException(403);
757 }
758
759 $result = $this->reception->fetch($id);
760 if (!$result) {
761 throw new RestException(404, 'Reception not found');
762 }
763
764 if (!DolibarrApi::_checkAccessToResource('reception', $this->reception->id)) {
765 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
766 }
767
768 $result = $this->reception->setClosed();
769 if ($result == 0) {
770 throw new RestException(304, 'Error nothing done. May be object is already closed');
771 }
772 if ($result < 0) {
773 throw new RestException(500, 'Error when closing Reception: '.$this->reception->errorsToString());
774 }
775
776 // Reload reception
777 $result = $this->reception->fetch($id);
778
779 $this->reception->fetchObjectLinked();
780
781 return $this->_cleanObjectDatas($this->reception);
782 }
783
803 public function setToDraft($id)
804 {
805 // Same permission as the one checked by Reception::setDraft().
806 if (!((!getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && DolibarrApiAccess::$user->hasRight('reception', 'creer'))
807 || (getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && DolibarrApiAccess::$user->hasRight('reception', 'reception_advance', 'validate')))) {
808 throw new RestException(403);
809 }
810
811 $result = $this->reception->fetch($id);
812 if (!$result) {
813 throw new RestException(404, 'Reception not found');
814 }
815
816 if (!DolibarrApi::_checkAccessToResource('reception', $this->reception->id)) {
817 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
818 }
819
820 $result = $this->reception->setDraft(DolibarrApiAccess::$user);
821 if ($result == 0) {
822 throw new RestException(304, 'Error nothing done. May be object is already draft');
823 }
824 if ($result < 0) {
825 throw new RestException(500, 'Error when setting reception back to draft: '.$this->reception->errorsToString());
826 }
827
828 // Reload reception
829 $result = $this->reception->fetch($id);
830
831 $this->reception->fetchObjectLinked();
832
833 return $this->_cleanObjectDatas($this->reception);
834 }
835
836 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
846 protected function _cleanObjectDatas($object)
847 {
848 // phpcs:enable
849 $object = parent::_cleanObjectDatas($object);
850
851 unset($object->thirdparty); // id already returned
852
853 unset($object->note);
854 unset($object->address);
855 unset($object->barcode_type);
856 unset($object->barcode_type_code);
857 unset($object->barcode_type_label);
858 unset($object->barcode_type_coder);
859
860 if (!empty($object->lines) && is_array($object->lines)) {
861 foreach ($object->lines as $line) {
862 unset($line->canvas);
863
864 unset($line->tva_tx);
865 unset($line->vat_src_code);
866 unset($line->total_ht);
867 unset($line->total_ttc);
868 unset($line->total_tva);
869 unset($line->total_localtax1);
870 unset($line->total_localtax2);
871 unset($line->remise_percent);
872 }
873 }
874
875 return $object;
876 }
877
885 private function _validate($data)
886 {
887 if ($data === null) {
888 $data = array();
889 }
890 $reception = array();
891 // A standalone reception carries no source document, exactly as the card
892 // allows when RECEPTION_STANDALONE is enabled: do not demand an origin the
893 // user is entitled to omit.
894 $mandatory = Receptions::$FIELDS;
895 if (getDolGlobalString('RECEPTION_STANDALONE') && !isset($data['origin_id']) && !isset($data['origin_type'])) {
896 $mandatory = array_values(array_diff($mandatory, array('origin_id', 'origin_type')));
897 }
898 foreach ($mandatory as $field) {
899 if (!isset($data[$field])) {
900 throw new RestException(400, "$field field missing");
901 }
902 $reception[$field] = $data[$field];
903 }
904 return $reception;
905 }
906}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class to manage line orders.
Class for API REST v1.
Definition api.class.php:35
_checkValExtrafieldsForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
_filterObjectProperties($object, $properties)
Filter properties that will be returned on object.
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $parenttableforentity='')
Check access by user to a given resource.
Class to manage receptions.
Class to manage table commandefournisseurdispatch.
close($id, $notrigger=0)
Classify the reception as invoiced.
validate($id, $notrigger=0)
Validate a reception.
post($request_data=null)
Create reception object.
getLines($id)
Get lines of a reception.
deleteLine($id, $lineid)
Delete a line of a given reception.
setToDraft($id)
Set a reception back to draft status.
putLine($id, $lineid, $qty=0, $warehouse_id=0)
Update a line of a given reception.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $thirdparty_ids='', $sqlfilters='', $properties='', $pagination_data=false)
List receptions.
_cleanObjectDatas($object)
Clean sensible object datas @phpstan-template T.
__construct()
Constructor.
fetchLineOfReception($lineid)
Load a line and check it belongs to the reception currently loaded.
_validate($data)
Validate fields before create or update object.
put($id, $request_data=null)
Update reception general fields (won't touch lines of reception)
postLine($id, $fk_origin_line=0, $qty=0, $warehouse_id=0, $batch='', $eatby='', $sellby='', $cost_price=0, $comment='')
Add a line to a given reception.
dol_stringtotime($string, $gm=1, $processnotimeasnoon=0)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
Definition date.lib.php:442
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.