21use Luracast\Restler\RestException;
23require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
36 public static $FIELDS = array(
54 $this->commande =
new Commande($this->db);
68 public function get(
$id, $contact_list = -1)
70 return $this->
_fetch(
$id,
'',
'', $contact_list);
86 public function getByRef($ref, $contact_list = -1)
88 return $this->
_fetch(0, $ref,
'', $contact_list);
106 return $this->
_fetch(0,
'', $ref_ext, $contact_list);
122 private function _fetch(
$id, $ref =
'', $ref_ext =
'', $contact_list = -1)
124 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
125 throw new RestException(403);
127 if (empty(
$id) && empty($ref) && empty($ref_ext)) {
128 throw new RestException(400,
'No ID or Ref provided');
130 $result = $this->commande->fetch(
$id, $ref, $ref_ext);
132 throw new RestException(404,
'Order not found');
136 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
139 if ($contact_list > -1) {
141 $tmparray = $this->commande->liste_contact(-1,
'external', $contact_list);
142 if (is_array($tmparray)) {
143 $this->commande->contacts_ids = $tmparray;
145 $tmparray = $this->commande->liste_contact(-1,
'internal', $contact_list);
146 if (is_array($tmparray)) {
147 $this->commande->contacts_ids_internal = $tmparray;
151 $this->commande->fetchObjectLinked();
154 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
155 $this->commande->online_payment_url = getOnlinePaymentUrl(0,
'order', $this->commande->ref);
182 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $thirdparty_ids =
'', $sqlfilters =
'', $sqlfilterlines =
'', $properties =
'', $pagination_data =
false, $loadlinkedobjects = 0)
186 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
187 throw new RestException(403);
193 $socids = DolibarrApiAccess::$user->socid ?: $thirdparty_ids;
197 if (!DolibarrApiAccess::$user->hasRight(
'societe',
'client',
'voir') && !$socids) {
198 $search_sale = DolibarrApiAccess::$user->id;
201 $sql =
"SELECT t.rowid";
202 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande AS t";
203 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe AS s ON (s.rowid = t.fk_soc)";
204 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"commande_extrafields AS ef ON (ef.fk_object = t.rowid)";
205 $sql .=
' WHERE t.entity IN ('.getEntity(
'commande').
')';
207 $sql .=
" AND t.fk_soc IN (".$this->db->sanitize($socids).
")";
210 if ($search_sale && $search_sale !=
'-1') {
211 if ($search_sale == -2) {
212 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc)";
213 } elseif ($search_sale > 0) {
214 $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).
")";
217 $parameters = array();
218 $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $this->commande);
219 $sql .= $hookmanager->resPrint;
225 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
229 if ($sqlfilterlines) {
231 $sql .=
" AND EXISTS (SELECT tl.rowid FROM ".MAIN_DB_PREFIX.
"commandedet AS tl WHERE tl.fk_commande = t.rowid";
235 throw new RestException(400,
'Error when validating parameter sqlfilterlines -> '.$errormessage);
240 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
242 $sql .= $this->db->order($sortfield, $sortorder);
247 $offset = $limit * $page;
249 $sql .= $this->db->plimit($limit + 1, $offset);
253 $result = $this->db->query($sql);
256 $num = $this->db->num_rows($result);
257 $min = min($num, ($limit <= 0 ? $num : $limit));
260 $obj = $this->db->fetch_object($result);
261 $commande_static =
new Commande($this->db);
262 if ($commande_static->fetch($obj->rowid) > 0) {
264 $tmparray = $commande_static->liste_contact(-1,
'external', 1);
265 if (is_array($tmparray)) {
266 $commande_static->contacts_ids = $tmparray;
269 if ($loadlinkedobjects) {
271 $commande_static->fetchObjectLinked();
275 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
276 $commande_static->online_payment_url = getOnlinePaymentUrl(0,
'order', $commande_static->ref);
283 throw new RestException(503,
'Error when retrieve commande list : '.$this->db->lasterror());
287 if ($pagination_data) {
288 $totalsResult = $this->db->query($sqlTotals);
289 $total = $this->db->fetch_object($totalsResult)->total;
294 $obj_ret[
'data'] = $tmp;
295 $obj_ret[
'pagination'] = [
296 'total' => (int) $total,
298 'page_count' => ceil((
int) $total / $limit),
316 public function post($request_data =
null)
319 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
320 throw new RestException(403,
"Insufficiant rights");
327 $socid = (int) $request_data[
'socid'];
328 $thirdpartytmp =
new Societe($this->db);
329 $thirdparty_result = $thirdpartytmp->fetch($socid);
330 if ($thirdparty_result < 1) {
331 throw new RestException(404,
'Thirdparty with id='.$socid.
' not found or not allowed');
334 throw new RestException(404,
'Thirdparty with id='.$thirdpartytmp->id.
' not found or not allowed');
337 foreach ($request_data as $field => $value) {
338 if ($field ===
'caller') {
340 $this->commande->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
343 if ($field ==
'id') {
344 throw new RestException(400,
'Creating with id field is forbidden');
346 if ($field ==
'entity' && ((
int) $value) != ((
int) $conf->entity)) {
347 throw new RestException(403,
'Creating with entity='.((
int) $value).
' MUST be the same entity='.((
int) $conf->entity).
' as your API user/key belongs to');
350 $this->commande->$field = $this->
_checkValForAPI($field, $value, $this->commande);
360 if ($this->commande->create(DolibarrApiAccess::$user) < 0) {
361 throw new RestException(500,
"Error creating order", array_merge(array($this->commande->error), $this->commande->errors));
364 return ((
int) $this->commande->id);
380 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
381 throw new RestException(403);
384 $result = $this->commande->fetch(
$id);
386 throw new RestException(404,
'Order not found');
390 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
392 $this->commande->getLinesArray();
394 foreach ($this->commande->lines as $line) {
413 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
414 throw new RestException(403);
417 $result = $this->commande->fetch(
$id);
419 throw new RestException(404,
'Order not found');
423 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
426 $this->commande->fetch_lines();
427 foreach ($this->commande->lines as $line) {
428 if ($line->id == $lineid) {
432 throw new RestException(404,
'Line not found');
449 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
450 throw new RestException(403);
453 $result = $this->commande->fetch(
$id);
455 throw new RestException(404,
'Order not found');
459 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
462 $request_data = (object) $request_data;
464 $request_data->desc =
sanitizeVal($request_data->desc,
'restricthtml');
465 $request_data->label =
sanitizeVal($request_data->label);
467 $updateRes = $this->commande->addline(
469 $request_data->subprice,
471 $request_data->tva_tx,
472 $request_data->localtax1_tx,
473 $request_data->localtax2_tx,
474 $request_data->fk_product,
475 $request_data->remise_percent,
476 $request_data->info_bits,
477 $request_data->fk_remise_except,
478 $request_data->price_base_type ? $request_data->price_base_type :
'HT',
479 $request_data->subprice,
480 $request_data->date_start,
481 $request_data->date_end,
482 $request_data->product_type,
484 $request_data->special_code,
485 $request_data->fk_parent_line,
486 $request_data->fk_fournprice,
487 $request_data->pa_ht,
488 $request_data->label,
489 $request_data->array_options,
490 $request_data->fk_unit,
491 $request_data->origin,
492 $request_data->origin_id,
493 $request_data->multicurrency_subprice,
494 $request_data->ref_ext
497 if ($updateRes > 0) {
500 throw new RestException(400, $this->commande->error);
518 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
519 throw new RestException(403);
522 $result = $this->commande->fetch(
$id);
524 throw new RestException(404,
'Order not found');
528 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
531 $request_data = (object) $request_data;
533 $request_data->desc =
sanitizeVal($request_data->desc,
'restricthtml');
534 $request_data->label =
sanitizeVal($request_data->label);
536 $updateRes = $this->commande->updateline(
539 $request_data->subprice,
541 $request_data->remise_percent,
542 $request_data->tva_tx,
543 $request_data->localtax1_tx,
544 $request_data->localtax2_tx,
545 $request_data->price_base_type ? $request_data->price_base_type :
'HT',
546 $request_data->info_bits,
547 $request_data->date_start,
548 $request_data->date_end,
549 $request_data->product_type,
550 $request_data->fk_parent_line,
552 $request_data->fk_fournprice,
553 $request_data->pa_ht,
554 $request_data->label,
555 $request_data->special_code,
556 $request_data->array_options,
557 $request_data->fk_unit,
558 $request_data->multicurrency_subprice,
560 $request_data->ref_ext,
564 if ($updateRes > 0) {
565 $result = $this->
get(
$id);
566 unset($result->line);
586 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
587 throw new RestException(403);
590 $result = $this->commande->fetch(
$id);
592 throw new RestException(404,
'Order not found');
596 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
599 $updateRes = $this->commande->deleteLine(DolibarrApiAccess::$user, $lineid,
$id);
600 if ($updateRes > 0) {
601 return $this->
get(
$id);
603 throw new RestException(405, $this->commande->error);
622 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
623 throw new RestException(403);
626 $result = $this->commande->fetch(
$id);
628 throw new RestException(404,
'Order not found');
632 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
635 $contacts = $this->commande->liste_contact(-1,
'external', 0, $type);
636 $socpeoples = $this->commande->liste_contact(-1,
'internal', 0, $type);
638 $contacts = array_merge($contacts, $socpeoples);
662 public function postContact(
$id, $contactid, $type, $source =
"external", $notrigger = 0)
664 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
665 throw new RestException(403);
669 if (empty($source)) {
670 throw new RestException(400,
'Source can not be empty');
672 $sql_distinct_source =
"SELECT DISTINCT source";
673 $sql_distinct_source .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact";
674 $sql_distinct_source .=
" WHERE element LIKE 'commande'";
675 $sql_distinct_source .=
" AND source is NOT NULL";
676 $sql_distinct_source .=
" AND active != 0";
677 $source_result = $this->db->query($sql_distinct_source);
678 $source_array = array();
680 if ($source_result) {
681 $num = $this->db->num_rows($source_result);
684 $obj = $this->db->fetch_object($source_result);
685 $source_kind = (string) $obj->source;
686 array_push($source_array, $source_kind);
691 throw new RestException(503,
'Error when retrieving a list of order contact sources: '.$this->db->lasterror());
693 if (!in_array($source, (array) $source_array,
true)) {
694 throw new RestException(400,
'Combo of Source='.$source.
' and Type='.$type.
' not found in dictionary with active order contact types');
699 throw new RestException(400,
'type can not be empty');
702 $sql_distinct_type =
"SELECT DISTINCT code";
703 $sql_distinct_type .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact";
704 $sql_distinct_type .=
" WHERE element LIKE 'commande'";
705 $sql_distinct_type .=
" AND source='".$this->db->escape($source).
"'";
706 $sql_distinct_type .=
" AND code is NOT NULL";
707 $sql_distinct_type .=
" AND active != 0";
708 $type_result = $this->db->query($sql_distinct_type);
709 $type_array = array();
712 $num = $this->db->num_rows($type_result);
715 $obj = $this->db->fetch_object($type_result);
717 $type_kind = (string) $obj->code;
718 array_push($type_array, $type_kind);
723 throw new RestException(503,
'Error when retrieving a list of order contact types: '.$this->db->lasterror());
725 if (!in_array($type, (array) $type_array,
true)) {
726 throw new RestException(400,
'Combo of Type='.$type.
' and Source='.$source.
' not found in dictionary with active order contact types');
730 $result = $this->commande->fetch(
$id);
732 throw new RestException(404,
'Order not found');
735 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
738 $result = $this->commande->add_contact($contactid, $type, $source, $notrigger);
741 throw new RestException(400,
'Already exists: Contact='.$contactid.
' is already linked to the order='.
$id.
' as source='.$source.
' and type='.$type);
742 } elseif ($result == -1) {
743 throw new RestException(400,
'Wrong contact='.$contactid);
744 } elseif ($result == -2) {
745 throw new RestException(400,
'Wrong type='.$type);
746 } elseif ($result == -3) {
747 throw new RestException(400,
'Not allowed contacts');
748 } elseif ($result == -4) {
749 throw new RestException(400,
'ErrorCommercialNotAllowedForThirdparty');
750 } elseif ($result == -5) {
751 throw new RestException(400,
'Trigger failed');
752 } elseif ($result == -6) {
753 throw new RestException(400,
'DB_ERROR_RECORD_ALREADY_EXISTS');
754 } elseif ($result == -7) {
755 throw new RestException(400,
'Some other error');
761 'message' =>
'Contact='.$contactid.
' linked to the order='.
$id.
' as '.$source.
' '.$type
785 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
786 throw new RestException(403);
789 $result = $this->commande->fetch(
$id);
791 throw new RestException(404,
'Order not found');
795 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
798 foreach (array(
'internal',
'external') as $source) {
799 $contacts = $this->commande->liste_contact(-1, $source);
800 foreach ($contacts as $contact) {
801 if ($contact[
'id'] == $contactid && $contact[
'code'] == $type) {
802 $result = $this->commande->delete_contact($contact[
'rowid']);
805 throw new RestException(500,
'Error when deleting the contact '.$contact[
'rowid']);
814 'message' =>
'Contact unlinked from order'
828 public function put(
$id, $request_data =
null)
830 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
831 throw new RestException(403);
834 throw new RestException(400,
'No order with id=0 can exist');
836 $result = $this->commande->fetch(
$id);
838 throw new RestException(404,
'Order not found');
842 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
844 foreach ($request_data as $field => $value) {
845 if ($field ==
'id') {
848 if ($field ===
'caller') {
850 $this->commande->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
853 if ($field ==
'array_options' && is_array($value)) {
854 foreach ($value as $index => $val) {
855 $this->commande->array_options[$index] = $this->
_checkValForAPI($field, $val, $this->commande);
860 $this->commande->$field = $this->
_checkValForAPI($field, $value, $this->commande);
864 if (!empty($this->commande->availability_id)) {
865 if ($this->commande->availability($this->commande->availability_id) < 0) {
866 throw new RestException(400,
'Error while updating availability');
870 if ($this->commande->update(DolibarrApiAccess::$user) > 0) {
871 return $this->
get(
$id);
873 throw new RestException(500, $this->commande->error);
885 public function delete(
$id)
887 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'supprimer')) {
888 throw new RestException(403);
891 throw new RestException(400,
'No order with id=0 can exist');
893 $result = $this->commande->fetch(
$id);
895 throw new RestException(404,
'Order not found');
899 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
902 if ($this->commande->delete(DolibarrApiAccess::$user) <= 0) {
903 throw new RestException(500,
'Error when deleting order : '.$this->commande->error);
909 'message' =>
'Order deleted'
937 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
938 throw new RestException(403);
940 $result = $this->commande->fetch(
$id);
942 throw new RestException(404,
'Order not found');
945 $result = $this->commande->fetch_thirdparty();
948 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
951 $result = $this->commande->valid(DolibarrApiAccess::$user, $idwarehouse, $notrigger);
953 throw new RestException(304,
'Error nothing done. May be object is already validated');
956 throw new RestException(500,
'Error when validating Order: '.$this->commande->error);
958 $result = $this->commande->fetch(
$id);
960 $this->commande->fetchObjectLinked();
963 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
964 $this->commande->online_payment_url = getOnlinePaymentUrl(0,
'order', $this->commande->ref);
988 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
989 throw new RestException(403);
992 throw new RestException(400,
'Order ID is mandatory');
994 $result = $this->commande->fetch(
$id);
996 throw new RestException(404,
'Order not found');
999 $result = $this->commande->set_reopen(DolibarrApiAccess::$user);
1001 throw new RestException(405, $this->commande->error);
1002 } elseif ($result == 0) {
1003 throw new RestException(304);
1024 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
1025 throw new RestException(403);
1028 throw new RestException(400,
'Order ID is mandatory');
1030 $result = $this->commande->fetch(
$id);
1032 throw new RestException(404,
'Order not found');
1035 $result = $this->commande->classifyBilled(DolibarrApiAccess::$user);
1037 throw new RestException(400, $this->commande->error);
1040 $result = $this->commande->fetch(
$id);
1042 throw new RestException(404,
'Order not found');
1046 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1049 $this->commande->fetchObjectLinked();
1065 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
1066 throw new RestException(403);
1068 $result = $this->commande->fetch(
$id);
1070 throw new RestException(404,
'Order not found');
1074 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1077 $result = $this->commande->cloture(DolibarrApiAccess::$user, $notrigger);
1079 throw new RestException(304,
'Error nothing done. May be object is already closed');
1082 throw new RestException(500,
'Error when closing Order: '.$this->commande->error);
1085 $result = $this->commande->fetch(
$id);
1087 throw new RestException(404,
'Order not found');
1095 $this->commande->fetchObjectLinked();
1111 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
1112 throw new RestException(403);
1114 $result = $this->commande->fetch(
$id);
1116 throw new RestException(404,
'Order not found');
1120 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1123 $result = $this->commande->setDraft(DolibarrApiAccess::$user, $idwarehouse);
1125 throw new RestException(304,
'Nothing done. May be object is already closed');
1128 throw new RestException(500,
'Error when closing Order: '.$this->commande->error);
1131 $result = $this->commande->fetch(
$id);
1133 throw new RestException(404,
'Order not found');
1141 $this->commande->fetchObjectLinked();
1162 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
1164 if (!DolibarrApiAccess::$user->hasRight(
'propal',
'lire')) {
1165 throw new RestException(403);
1167 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
1168 throw new RestException(403);
1170 if (empty($proposalid)) {
1171 throw new RestException(400,
'Proposal ID is mandatory');
1174 $propal =
new Propal($this->db);
1175 $result = $propal->fetch($proposalid);
1177 throw new RestException(404,
'Proposal not found');
1180 $result = $this->commande->createFromProposal($propal, DolibarrApiAccess::$user);
1182 throw new RestException(405, $this->commande->error);
1184 $this->commande->fetchObjectLinked();
1206 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1207 if (!DolibarrApiAccess::$user->hasRight(
'expedition',
'lire')) {
1208 throw new RestException(403);
1211 $sql =
"SELECT e.rowid";
1212 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expedition as e";
1213 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"expeditiondet as edet";
1214 $sql .=
" ON e.rowid = edet.fk_expedition";
1215 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"commandedet as cdet";
1216 $sql .=
" ON edet.fk_elementdet = cdet.rowid";
1217 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"commande as c";
1218 $sql .=
" ON cdet.fk_commande = c.rowid";
1219 $sql .=
" WHERE c.rowid = ".((int)
$id);
1220 $sql .=
" GROUP BY e.rowid";
1221 $sql .= $this->db->order(
"e.rowid",
"ASC");
1224 $result = $this->db->query($sql);
1228 $num = $this->db->num_rows($result);
1230 throw new RestException(404,
'Shipments not found ');
1235 $obj = $this->db->fetch_object($result);
1236 $shipment_static =
new Expedition($this->db);
1237 if ($shipment_static->fetch($obj->rowid)) {
1243 throw new RestException(500,
'Error when retrieve shipment list : '.$this->db->lasterror());
1264 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1265 if (!DolibarrApiAccess::$user->hasRight(
'expedition',
'creer')) {
1266 throw new RestException(403);
1268 if ($warehouse_id <= 0) {
1269 throw new RestException(404,
'Warehouse not found');
1271 $result = $this->commande->fetch(
$id);
1273 throw new RestException(404,
'Order not found');
1276 $shipment->socid = $this->commande->socid;
1277 $shipment->origin_id = $this->commande->id;
1278 $shipment->origin = $this->commande->element;
1279 $result = $shipment->create(DolibarrApiAccess::$user);
1281 throw new RestException(500,
'Error on creating expedition :'.$this->db->lasterror());
1283 foreach ($this->commande->lines as $line) {
1284 $result = $shipment->create_line($warehouse_id, $line->id, $line->qty);
1286 throw new RestException(500,
'Error on creating expedition lines:'.$this->db->lasterror());
1289 return $shipment->id;
1310 unset(
$object->barcode_type_code);
1311 unset(
$object->barcode_type_label);
1312 unset(
$object->barcode_type_coder);
1326 if ($data ===
null) {
1329 $commande = array();
1330 foreach (Orders::$FIELDS as $field) {
1331 if (!isset($data[$field])) {
1332 throw new RestException(400, $field.
" field missing");
1334 $commande[$field] = $data[$field];
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
Class to manage customers orders.
_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.
deleteContact($id, $contactid, $type)
Unlink a contact type of given order.
__construct()
Constructor.
_validate($data)
Validate fields before create or update object.
deleteLine($id, $lineid)
Delete a line of a given order.
getByRef($ref, $contact_list=-1)
Get properties of an order object by ref.
close($id, $notrigger=0)
Close an order (Classify it as "Delivered")
postContact($id, $contactid, $type, $source="external", $notrigger=0)
Add a contact type of given order.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $thirdparty_ids='', $sqlfilters='', $sqlfilterlines='', $properties='', $pagination_data=false, $loadlinkedobjects=0)
List orders.
_cleanObjectDatas($object)
Clean sensible object datas @phpstan-template T.
_fetch($id, $ref='', $ref_ext='', $contact_list=-1)
Get properties of an order object.
put($id, $request_data=null)
Update order general fields (won't touch lines of order)
getLines($id)
Get lines of an order.
reopen($id)
Tag the order as validated (opened)
setinvoiced($id)
Classify the order as invoiced.
getContacts($id, $type='')
Get contacts of a given order.
getLine($id, $lineid, $properties='')
Get properties of a line of an order object by id.
postLine($id, $request_data=null)
Add a line to given order.
post($request_data=null)
Create a sale order.
validate($id, $idwarehouse=0, $notrigger=0)
Validate an order.
createOrderFromProposal($proposalid)
Create an order using an existing proposal.
putLine($id, $lineid, $request_data=null)
Update a line to given order.
getOrderShipments($id)
Get the shipments of an order.
settodraft($id, $idwarehouse=-1)
Set an order to draft.
createOrderShipment($id, $warehouse_id)
Create the shipment of an order.
getByRefExt($ref_ext, $contact_list=-1)
Get properties of an order object by ref_ext.
Class to manage proposals.
Class to manage third parties objects (customers, suppliers, prospects...)
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
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.