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