dolibarr 25.0.0-alpha
api_supplier_orders.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) 2025-2026 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2025 Frédéric France <frederic.france@free.fr>
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.'/fourn/class/fournisseur.commande.class.php';
24require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
25
33{
37 public static $FIELDS = array(
38 'socid'
39 );
40
44 public $order;
45
49 public function __construct()
50 {
51 global $db, $conf;
52 $this->db = $db;
53 $this->order = new CommandeFournisseur($this->db);
54 }
55
66 public function get($id)
67 {
68 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "commande", "lire")) {
69 throw new RestException(403);
70 }
71
72 $result = $this->order->fetch($id);
73 if (!$result) {
74 throw new RestException(404, 'Supplier order not found');
75 }
76
77 if (!DolibarrApi::_checkAccessToResource('fournisseur', $this->order->id, 'commande_fournisseur', 'commande')) {
78 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
79 }
80
81 $this->order->fetchObjectLinked();
82 return $this->_cleanObjectDatas($this->order);
83 }
84
107 public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $product_ids = '', $status = '', $sqlfilters = '', $sqlfilterlines = '', $properties = '', $pagination_data = false)
108 {
109 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "commande", "lire")) {
110 throw new RestException(403);
111 }
112
113 $obj_ret = array();
114
115 // case of external user, $thirdparty_ids param is ignored and replaced by user's socid
116 $socids = DolibarrApiAccess::$user->socid ?: $thirdparty_ids;
117
118 // If the internal user must only see his customers, force searching by him
119 $search_sale = 0;
120 if (!DolibarrApiAccess::$user->hasRight("societe", "client", "voir") && !empty($socids)) {
121 $search_sale = DolibarrApiAccess::$user->id;
122 }
123
124 $sql = "SELECT t.rowid";
125 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur AS t";
126 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseur_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
127 if (!empty($product_ids)) {
128 $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseurdet as cd"; // We need this table joined to the select in order to filter by product
129 }
130 $sql .= ' WHERE t.entity IN ('.getEntity('supplier_order').')';
131 if (!empty($product_ids)) {
132 $sql .= " AND cd.fk_commande = t.rowid AND cd.fk_product IN (".$this->db->sanitize($product_ids).")";
133 }
134 if ($socids) {
135 $sql .= " AND t.fk_soc IN (".$this->db->sanitize($socids).")";
136 }
137 // Filter by status
138 if ($status == 'draft') {
139 $sql .= " AND t.fk_statut IN (0)";
140 }
141 if ($status == 'validated') {
142 $sql .= " AND t.fk_statut IN (1)";
143 }
144 if ($status == 'approved') {
145 $sql .= " AND t.fk_statut IN (2)";
146 }
147 if ($status == 'running') {
148 $sql .= " AND t.fk_statut IN (3)";
149 }
150 if ($status == 'received_start') {
151 $sql .= " AND t.fk_statut IN (4)";
152 }
153 if ($status == 'received_end') {
154 $sql .= " AND t.fk_statut IN (5)";
155 }
156 if ($status == 'cancelled') {
157 $sql .= " AND t.fk_statut IN (6,7)";
158 }
159 if ($status == 'refused') {
160 $sql .= " AND t.fk_statut IN (9)";
161 }
162 // Search on sale representative
163 if ($search_sale && $search_sale != '-1') {
164 if ($search_sale == -2) {
165 $sql .= " AND ".getSalesRepresentativeSqlFilter('t.fk_soc', 0, 1);
166 } elseif ($search_sale > 0) {
167 $sql .= " AND ".getSalesRepresentativeSqlFilter('t.fk_soc', (int) $search_sale);
168 }
169 }
170 // Add sql filters
171 if ($sqlfilters) {
172 $errormessage = '';
173 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
174 if ($errormessage) {
175 throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
176 }
177 }
178 // Add sql filters for lines
179 if ($sqlfilterlines) {
180 $errormessage = '';
181 $sql .= " AND EXISTS (SELECT tl.rowid FROM ".MAIN_DB_PREFIX."commande_fournisseurdet AS tl WHERE tl.fk_commande = t.rowid";
182 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilterlines, $errormessage);
183 $sql .= ")";
184 if ($errormessage) {
185 throw new RestException(400, 'Error when validating parameter sqlfilterlines -> '.$errormessage);
186 }
187 }
188
189 //this query will return total supplier orders with the filters given
190 $sqlTotals = str_replace('SELECT t.rowid', 'SELECT count(t.rowid) as total', $sql);
191
192 $sql .= $this->db->order($sortfield, $sortorder);
193 if ($limit) {
194 if ($page < 0) {
195 $page = 0;
196 }
197 $offset = $limit * $page;
198
199 $sql .= $this->db->plimit($limit + 1, $offset);
200 }
201
202 $result = $this->db->query($sql);
203 if ($result) {
204 $i = 0;
205 $num = $this->db->num_rows($result);
206 $min = min($num, ($limit <= 0 ? $num : $limit));
207 while ($i < $min) {
208 $obj = $this->db->fetch_object($result);
209 $order_static = new CommandeFournisseur($this->db);
210 if ($order_static->fetch($obj->rowid)) {
211 $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($order_static), $properties);
212 }
213 $i++;
214 }
215 } else {
216 throw new RestException(503, 'Error when retrieve supplier order list : '.$this->db->lasterror());
217 }
218
219 //if $pagination_data is true the response will contain element data with all values and element pagination with pagination data(total,page,limit)
220 if ($pagination_data) {
221 $totalsResult = $this->db->query($sqlTotals);
222 $total = $this->db->fetch_object($totalsResult)->total;
223
224 $tmp = $obj_ret;
225 $obj_ret = [];
226
227 $obj_ret['data'] = $tmp;
228 $obj_ret['pagination'] = [
229 'total' => (int) $total,
230 'page' => $page, //count starts from 0
231 'page_count' => (int) ceil((int) $total / $limit),
232 'limit' => $limit
233 ];
234 }
235
236 return $obj_ret;
237 }
238
249 public function post($request_data = null)
250 {
251 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "commande", "creer") && !DolibarrApiAccess::$user->hasRight("supplier_order", "creer")) {
252 throw new RestException(403, "Insufficiant rights");
253 }
254
255 if (!is_array($request_data)) {
256 $request_data = array();
257 }
258
259 // Check mandatory fields (not using output, only possible exception is important)
260 $this->_validate($request_data);
261
262 foreach ($request_data as $field => $value) {
263 if ($field === 'caller') {
264 // 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
265 $this->order->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
266 continue;
267 }
268
269 $this->order->$field = $this->_checkValForAPI($field, $value, $this->order);
270 }
271 if (!array_keys($request_data, 'date')) {
272 $this->order->date = dol_now();
273 }
274 /* We keep lines as an array
275 if (isset($request_data["lines"])) {
276 $lines = array();
277 foreach ($request_data["lines"] as $line) {
278 array_push($lines, (object) $line);
279 }
280 $this->order->lines = $lines;
281 }*/
282
283 if ($this->order->create(DolibarrApiAccess::$user) < 0) {
284 throw new RestException(500, "Error creating order", array_merge(array($this->order->error), $this->order->errors));
285 }
286 return $this->order->id;
287 }
288
298 public function put($id, $request_data = null)
299 {
300 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "commande", "creer") && !DolibarrApiAccess::$user->hasRight("supplier_order", "creer")) {
301 throw new RestException(403);
302 }
303
304 $result = $this->order->fetch($id);
305 if (!$result) {
306 throw new RestException(404, 'Supplier order not found');
307 }
308
309 if (!DolibarrApi::_checkAccessToResource('fournisseur', $this->order->id, 'commande_fournisseur', 'commande')) {
310 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
311 }
312
313 foreach ($request_data as $field => $value) {
314 if ($field == 'id') {
315 continue;
316 }
317 if ($field === 'caller') {
318 // 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
319 $this->order->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
320 continue;
321 }
322 if ($field == 'array_options' && is_array($value)) {
323 foreach ($value as $index => $val) {
324 $this->order->array_options[$index] = $this->_checkValExtrafieldsForAPI($index, $val, $this->order);
325 }
326 continue;
327 }
328
329 $this->order->$field = $this->_checkValForAPI($field, $value, $this->order);
330 }
331
332 if ($this->order->update(DolibarrApiAccess::$user)) {
333 return $this->get($id);
334 }
335
336 return false;
337 }
338
351 public function postLine($id, $request_data = null)
352 {
353 if (!DolibarrApiAccess::$user->hasRight('fournisseur', 'commande', 'creer')) {
354 throw new RestException(403);
355 }
356
357 $result = $this->order->fetch($id);
358 if (!$result) {
359 throw new RestException(404, 'Supplier order not found');
360 }
361
362 if (!DolibarrApi::_checkAccessToResource('fournisseur', $this->order->id, 'commande_fournisseur', 'commande')) {
363 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
364 }
365
366 $request_data = (object) $request_data;
367
368 $request_data->desc = sanitizeVal($request_data->desc, 'restricthtml');
369
370 $updateRes = $this->order->addline(
371 $request_data->desc,
372 $request_data->subprice,
373 $request_data->qty,
374 $request_data->tva_tx,
375 $request_data->localtax1_tx,
376 $request_data->localtax2_tx,
377 $request_data->fk_product,
378 $request_data->fk_prod_fourn_price,
379 $request_data->ref_fourn,
380 $request_data->remise_percent,
381 $request_data->price_base_type ? $request_data->price_base_type : 'HT',
382 $request_data->pu_ttc,
383 $request_data->product_type,
384 $request_data->info_bits,
385 $request_data->notrigger,
386 $request_data->date_start,
387 $request_data->date_end,
388 $request_data->array_options,
389 $request_data->fk_unit,
390 $request_data->multicurrency_subprice,
391 $request_data->origin,
392 $request_data->origin_id,
393 $request_data->rang,
394 $request_data->special_code
395 );
396
397 if ($updateRes > 0) {
398 return $updateRes;
399 } else {
400 throw new RestException(400, $this->order->error);
401 }
402 }
403
418 public function getContacts($id, $source, $type = '')
419 {
420 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "commande", "lire")) {
421 throw new RestException(403);
422 }
423
424 $result = $this->order->fetch($id);
425 if (!$result) {
426 throw new RestException(404, 'Supplier order not found');
427 }
428
429 if (!DolibarrApi::_checkAccessToResource('fournisseur', $this->order->id, 'commande_fournisseur', 'commande')) {
430 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
431 }
432 $contacts = array();
433
434 if ($source == 'all' || $source == 'external') {
435 $tmpContacts = $this->order->liste_contact(-1, 'external', 0, $type);
436 $contacts = array_merge($contacts, $tmpContacts);
437 }
438
439 if ($source == 'all' || $source == 'internal') {
440 $tmpContacts = $this->order->liste_contact(-1, 'internal', 0, $type);
441 $contacts = array_merge($contacts, $tmpContacts);
442 }
443
444 return $contacts;
445 }
446
463 public function postContact($id, $contactid, $type, $source)
464 {
465 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "commande", "creer")) {
466 throw new RestException(403);
467 }
468
469 $result = $this->order->fetch($id);
470 if (!$result) {
471 throw new RestException(404, 'Supplier order not found');
472 }
473
474 if (!DolibarrApi::_checkAccessToResource('fournisseur', $this->order->id, 'commande_fournisseur', 'commande')) {
475 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
476 }
477
478 $result = $this->order->add_contact($contactid, $type, $source);
479
480 if ($result < 0) {
481 throw new RestException(500, 'Error when added the contact');
482 }
483
484 if ($result == 0) {
485 throw new RestException(304, 'contact already added');
486 }
487
488 return array(
489 'success' => array(
490 'code' => 200,
491 'message' => 'Contact linked to the order'
492 )
493 );
494 }
495
514 public function deleteContact($id, $contactid, $type, $source)
515 {
516 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "commande", "creer")) {
517 throw new RestException(403);
518 }
519
520 $result = $this->order->fetch($id);
521 if (!$result) {
522 throw new RestException(404, 'Supplier order not found');
523 }
524
525 if (!DolibarrApi::_checkAccessToResource('fournisseur', $this->order->id, 'commande_fournisseur', 'commande')) {
526 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
527 }
528
529 $contacts = $this->order->liste_contact(-1, $source, 0, $type);
530
531 $contactToUnlink = 0;
532 foreach ($contacts as $contact) {
533 if ($contact['id'] == $contactid && $contact['code'] == $type) {
534 $contactToUnlink = $contact['rowid'];
535 break;
536 }
537 }
538
539 if ($contactToUnlink == 0) {
540 throw new RestException(404, 'Linked contact not found');
541 }
542
543 $result = $this->order->delete_contact($contactToUnlink);
544
545 if (!$result) {
546 throw new RestException(500, 'Error when deleting the contact');
547 }
548
549 return array(
550 'success' => array(
551 'code' => 200,
552 'message' => 'Contact unlinked from supplier order'
553 )
554 );
555 }
556
565 public function delete($id)
566 {
567 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "commande", "supprimer")) {
568 throw new RestException(403);
569 }
570 $result = $this->order->fetch($id);
571 if (!$result) {
572 throw new RestException(404, 'Supplier order not found');
573 }
574
575 if (!DolibarrApi::_checkAccessToResource('fournisseur', $this->order->id, 'commande_fournisseur', 'commande')) {
576 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
577 }
578
579 if ($this->order->delete(DolibarrApiAccess::$user) < 0) {
580 throw new RestException(500, 'Error when deleting order');
581 }
582
583 return array(
584 'success' => array(
585 'code' => 200,
586 'message' => 'Supplier order deleted'
587 )
588 );
589 }
590
591
613 public function validate($id, $idwarehouse = 0, $notrigger = 0)
614 {
615 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "commande", "creer") && !DolibarrApiAccess::$user->hasRight("supplier_order", "creer")) {
616 throw new RestException(403);
617 }
618 $result = $this->order->fetch($id);
619 if (!$result) {
620 throw new RestException(404, 'Order not found');
621 }
622
623 if (!DolibarrApi::_checkAccessToResource('fournisseur', $this->order->id, 'commande_fournisseur', 'commande')) {
624 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
625 }
626
627 $result = $this->order->valid(DolibarrApiAccess::$user, $idwarehouse, $notrigger);
628 if ($result == 0) {
629 throw new RestException(304, 'Error nothing done. May be object is already validated');
630 }
631 if ($result < 0) {
632 throw new RestException(500, 'Error when validating Order: '.$this->order->error);
633 }
634
635 return array(
636 'success' => array(
637 'code' => 200,
638 'message' => 'Order validated (Ref='.$this->order->ref.')'
639 )
640 );
641 }
642
664 public function approve($id, $idwarehouse = 0, $secondlevel = 0)
665 {
666 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "commande", "creer") && !DolibarrApiAccess::$user->hasRight("supplier_order", "creer")) {
667 throw new RestException(403);
668 }
669 $result = $this->order->fetch($id);
670 if (!$result) {
671 throw new RestException(404, 'Order not found');
672 }
673
674 if (!DolibarrApi::_checkAccessToResource('fournisseur', $this->order->id, 'commande_fournisseur', 'commande')) {
675 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
676 }
677
678 $result = $this->order->approve(DolibarrApiAccess::$user, $idwarehouse, $secondlevel);
679 if ($result == 0) {
680 throw new RestException(304, 'Error nothing done. May be object is already approved');
681 }
682 if ($result < 0) {
683 throw new RestException(500, 'Error when approve Order: '.$this->order->error);
684 }
685
686 return array(
687 'success' => array(
688 'code' => 200,
689 'message' => 'Order approved (Ref='.$this->order->ref.')'
690 )
691 );
692 }
693
694
718 public function makeOrder($id, $date, $method, $comment = '')
719 {
720 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "commande", "creer") && !DolibarrApiAccess::$user->hasRight("supplier_order", "creer")) {
721 throw new RestException(403);
722 }
723 $result = $this->order->fetch($id);
724 if (!$result) {
725 throw new RestException(404, 'Order not found');
726 }
727
728 if (!DolibarrApi::_checkAccessToResource('fournisseur', $this->order->id, 'commande_fournisseur', 'commande')) {
729 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
730 }
731
732 $result = $this->order->commande(DolibarrApiAccess::$user, $date, $method, $comment);
733 if ($result == 0) {
734 throw new RestException(304, 'Error nothing done. May be object is already sent');
735 }
736 if ($result < 0) {
737 throw new RestException(500, 'Error when sending Order: '.$this->order->error);
738 }
739
740 return array(
741 'success' => array(
742 'code' => 200,
743 'message' => 'Order sent (Ref='.$this->order->ref.')'
744 )
745 );
746 }
747
785 public function receiveOrder($id, $closeopenorder, $comment, $lines)
786 {
787 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "commande", "creer") && !DolibarrApiAccess::$user->hasRight("supplier_order", "creer")) {
788 throw new RestException(403);
789 }
790 $result = $this->order->fetch($id);
791 if (!$result) {
792 throw new RestException(404, 'Order not found');
793 }
794
795 if (!DolibarrApi::_checkAccessToResource('fournisseur', $this->order->id, 'commande_fournisseur', 'commande')) {
796 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
797 }
798
799 foreach ($lines as $line) {
800 $lineObj = (object) $line;
801
802 $result = $this->order->dispatchProduct(
803 DolibarrApiAccess::$user,
804 $lineObj->fk_product,
805 $lineObj->qty,
806 $lineObj->warehouse,
807 $lineObj->price,
808 $lineObj->comment,
809 $lineObj->eatby,
810 $lineObj->sellby,
811 $lineObj->batch,
812 (int) $lineObj->id,
813 $lineObj->notrigger
814 );
815
816 if ($result < 0) {
817 throw new RestException(500, 'Error dispatch order line '.$lineObj->id.': '.$this->order->error);
818 }
819 }
820
821 $result = $this->order->calcAndSetStatusDispatch(DolibarrApiAccess::$user, $closeopenorder, $comment);
822
823 if ($result == 0) {
824 throw new RestException(304, 'Error nothing done. May be object is already dispatched');
825 }
826 if ($result < 0) {
827 throw new RestException(500, 'Error when receivce order: '.$this->order->error);
828 }
829
830 return array(
831 'success' => array(
832 'code' => 200,
833 'message' => 'Order received (Ref='.$this->order->ref.')'
834 )
835 );
836 }
837
838 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
848 protected function _cleanObjectDatas($object)
849 {
850 // phpcs:enable
851 $object = parent::_cleanObjectDatas($object);
852
853 unset($object->rowid);
854 unset($object->barcode_type);
855 unset($object->barcode_type_code);
856 unset($object->barcode_type_label);
857 unset($object->barcode_type_coder);
858
859 return $object;
860 }
861
870 private function _validate($data)
871 {
872 if ($data === null) {
873 $data = array();
874 }
875 $order = array();
876 foreach (SupplierOrders::$FIELDS as $field) {
877 if (!isset($data[$field])) {
878 throw new RestException(400, "$field field missing");
879 }
880 $order[$field] = $data[$field];
881 }
882 return $order;
883 }
884}
$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 predefined suppliers products.
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.
validate($id, $idwarehouse=0, $notrigger=0)
Validate an order.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $thirdparty_ids='', $product_ids='', $status='', $sqlfilters='', $sqlfilterlines='', $properties='', $pagination_data=false)
List orders.
put($id, $request_data=null)
Update supplier order.
post($request_data=null)
Create supplier order object.
_cleanObjectDatas($object)
Clean sensible object datas @phpstan-template T.
postLine($id, $request_data=null)
Add a line to a given supplier order.
deleteContact($id, $contactid, $type, $source)
Unlink a contact type of given supplier order.
makeOrder($id, $date, $method, $comment='')
Sends an order to the vendor.
postContact($id, $contactid, $type, $source)
Add a contact type of given supplier order.
getContacts($id, $source, $type='')
Get contacts of given supplier order.
_validate($data)
Validate fields before create or update object.
approve($id, $idwarehouse=0, $secondlevel=0)
Approve an order.
receiveOrder($id, $closeopenorder, $comment, $lines)
Receives the order, dispatches products.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.