22use Luracast\Restler\RestException;
24require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
25require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
39 public static $FIELDS = array(
57 $this->commande =
new Commande($this->db);
72 public function get(
$id, $contact_list = -1)
74 return $this->
_fetch(
$id,
'',
'', $contact_list);
91 public function getByRef($ref, $contact_list = -1)
93 return $this->
_fetch(0, $ref,
'', $contact_list);
112 return $this->
_fetch(0,
'', $ref_ext, $contact_list);
128 private function _fetch(
$id, $ref =
'', $ref_ext =
'', $contact_list = -1)
130 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
131 throw new RestException(403);
133 if (empty(
$id) && empty($ref) && empty($ref_ext)) {
134 throw new RestException(400,
'No ID or Ref provided');
136 $result = $this->commande->fetch(
$id, $ref, $ref_ext);
138 throw new RestException(404,
'Order not found');
142 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
145 if ($contact_list > -1) {
147 $tmparray = $this->commande->liste_contact(-1,
'external', $contact_list);
148 if (is_array($tmparray)) {
149 $this->commande->contacts_ids = $tmparray;
151 $tmparray = $this->commande->liste_contact(-1,
'internal', $contact_list);
152 if (is_array($tmparray)) {
153 $this->commande->contacts_ids_internal = $tmparray;
157 $this->commande->fetchObjectLinked();
160 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
161 $this->commande->online_payment_url = getOnlinePaymentUrl(0,
'order', (
string) $this->commande->ref);
190 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $thirdparty_ids =
'', $sqlfilters =
'', $sqlfilterlines =
'', $properties =
'', $pagination_data =
false, $loadlinkedobjects = 0)
194 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
195 throw new RestException(403);
201 $socids = DolibarrApiAccess::$user->socid ?: $thirdparty_ids;
205 if (!DolibarrApiAccess::$user->hasRight(
'societe',
'client',
'voir') && !$socids) {
206 $search_sale = DolibarrApiAccess::$user->id;
209 $sql =
"SELECT t.rowid";
210 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande AS t";
211 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe AS s ON (s.rowid = t.fk_soc)";
212 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"commande_extrafields AS ef ON (ef.fk_object = t.rowid)";
213 $sql .=
' WHERE t.entity IN ('.getEntity(
'commande').
')';
215 $sql .=
" AND t.fk_soc IN (".$this->db->sanitize($socids).
")";
218 if ($search_sale && $search_sale !=
'-1') {
219 if ($search_sale == -2) {
220 $sql .=
" AND ".getSalesRepresentativeSqlFilter(
't.fk_soc', 0, 1);
221 } elseif ($search_sale > 0) {
222 $sql .=
" AND ".getSalesRepresentativeSqlFilter(
't.fk_soc', (
int) $search_sale);
225 $parameters = array();
226 $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $this->commande);
227 $sql .= $hookmanager->resPrint;
233 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
237 if ($sqlfilterlines) {
239 $sql .=
" AND EXISTS (SELECT tl.rowid FROM ".MAIN_DB_PREFIX.
"commandedet AS tl WHERE tl.fk_commande = t.rowid";
243 throw new RestException(400,
'Error when validating parameter sqlfilterlines -> '.$errormessage);
248 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
250 $sql .= $this->db->order($sortfield, $sortorder);
255 $offset = $limit * $page;
257 $sql .= $this->db->plimit($limit + 1, $offset);
261 $result = $this->db->query($sql);
264 $num = $this->db->num_rows($result);
265 $min = min($num, ($limit <= 0 ? $num : $limit));
268 $obj = $this->db->fetch_object($result);
269 $commande_static =
new Commande($this->db);
270 if ($commande_static->fetch($obj->rowid) > 0) {
272 $tmparray = $commande_static->liste_contact(-1,
'external', 1);
273 if (is_array($tmparray)) {
274 $commande_static->contacts_ids = $tmparray;
277 if ($loadlinkedobjects) {
279 $commande_static->fetchObjectLinked();
283 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
284 $commande_static->online_payment_url = getOnlinePaymentUrl(0,
'order', (
string) $commande_static->ref);
291 throw new RestException(503,
'Error when retrieve commande list : '.$this->db->lasterror());
295 if ($pagination_data) {
296 $totalsResult = $this->db->query($sqlTotals);
297 $total = $this->db->fetch_object($totalsResult)->total;
302 $obj_ret[
'data'] = $tmp;
303 $obj_ret[
'pagination'] = [
304 'total' => (int) $total,
306 'page_count' => ceil((
int) $total / $limit),
328 public function post($request_data =
null)
331 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
332 throw new RestException(403,
"Insufficiant rights");
339 $socid = (int) $request_data[
'socid'];
340 $thirdpartytmp =
new Societe($this->db);
341 $thirdparty_result = $thirdpartytmp->fetch($socid);
342 if ($thirdparty_result < 1) {
343 throw new RestException(404,
'Third party with id='.$socid.
' not found or not allowed');
346 throw new RestException(404,
'Third party with id='.$thirdpartytmp->id.
' not found or not allowed');
349 foreach ($request_data as $field => $value) {
350 if ($field ===
'caller') {
352 $this->commande->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
355 if ($field ==
'id') {
356 throw new RestException(400,
'Creating with id field is forbidden');
358 if ($field ==
'entity' && ((
int) $value) != ((
int)
$conf->entity)) {
359 throw new RestException(403,
'Creating with entity='.((
int) $value).
' MUST be the same entity='.((
int)
$conf->entity).
' as your API user/key belongs to');
362 $this->commande->$field = $this->
_checkValForAPI($field, $value, $this->commande);
372 if ($this->commande->create(DolibarrApiAccess::$user) < 0) {
373 throw new RestException(500,
"Error creating order", array_merge(array($this->commande->error), $this->commande->errors));
376 return ((
int) $this->commande->id);
393 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
394 throw new RestException(403);
397 $result = $this->commande->fetch(
$id);
399 throw new RestException(404,
'Order not found');
403 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
405 $this->commande->getLinesArray();
407 foreach ($this->commande->lines as $line) {
427 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
428 throw new RestException(403);
431 $result = $this->commande->fetch(
$id);
433 throw new RestException(404,
'Order not found');
437 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
440 $this->commande->fetch_lines();
441 foreach ($this->commande->lines as $line) {
442 if ($line->id == $lineid) {
446 throw new RestException(404,
'Line not found');
464 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
465 throw new RestException(403);
468 $result = $this->commande->fetch(
$id);
470 throw new RestException(404,
'Order not found');
474 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
477 $request_data = (object) $request_data;
479 $request_data->desc =
sanitizeVal($request_data->desc,
'restricthtml');
480 $request_data->label =
sanitizeVal($request_data->label);
482 $updateRes = $this->commande->addline(
484 $request_data->subprice,
486 $request_data->tva_tx,
487 $request_data->localtax1_tx,
488 $request_data->localtax2_tx,
489 $request_data->fk_product,
490 $request_data->remise_percent,
491 $request_data->info_bits,
492 $request_data->fk_remise_except,
493 $request_data->price_base_type ? $request_data->price_base_type :
'HT',
494 $request_data->subprice,
495 $request_data->date_start,
496 $request_data->date_end,
497 $request_data->product_type,
499 $request_data->special_code,
500 $request_data->fk_parent_line,
501 $request_data->fk_fournprice,
502 $request_data->pa_ht,
503 $request_data->label,
504 $request_data->array_options,
505 $request_data->fk_unit,
506 $request_data->origin,
507 $request_data->origin_id,
508 $request_data->multicurrency_subprice,
509 $request_data->ref_ext
512 if ($updateRes > 0) {
515 throw new RestException(400, $this->commande->error);
534 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
535 throw new RestException(403);
538 $result = $this->commande->fetch(
$id);
540 throw new RestException(404,
'Order not found');
544 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
547 $request_data = (object) $request_data;
549 $request_data->desc =
sanitizeVal($request_data->desc,
'restricthtml');
550 $request_data->label =
sanitizeVal($request_data->label);
552 $updateRes = $this->commande->updateline(
555 $request_data->subprice,
557 $request_data->remise_percent,
558 $request_data->tva_tx,
559 $request_data->localtax1_tx,
560 $request_data->localtax2_tx,
561 $request_data->price_base_type ? $request_data->price_base_type :
'HT',
562 $request_data->info_bits,
563 $request_data->date_start,
564 $request_data->date_end,
565 $request_data->product_type,
566 $request_data->fk_parent_line,
568 $request_data->fk_fournprice,
569 $request_data->pa_ht,
570 $request_data->label,
571 $request_data->special_code,
572 $request_data->array_options,
573 $request_data->fk_unit,
574 $request_data->multicurrency_subprice,
576 $request_data->ref_ext,
580 if ($updateRes > 0) {
581 $result = $this->
get(
$id);
582 unset($result->line);
603 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
604 throw new RestException(403);
607 $result = $this->commande->fetch(
$id);
609 throw new RestException(404,
'Order not found');
613 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
616 $updateRes = $this->commande->deleteLine(DolibarrApiAccess::$user, $lineid,
$id);
617 if ($updateRes > 0) {
618 return $this->
get(
$id);
620 throw new RestException(405, $this->commande->error);
640 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
641 throw new RestException(403);
644 $result = $this->commande->fetch(
$id);
646 throw new RestException(404,
'Order not found');
650 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
653 $contacts = $this->commande->liste_contact(-1,
'external', 0, $type);
654 $socpeoples = $this->commande->liste_contact(-1,
'internal', 0, $type);
656 $contacts = array_merge($contacts, $socpeoples);
681 public function postContact(
$id, $contactid, $type, $source =
"external", $notrigger = 0)
683 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
684 throw new RestException(403);
688 if (empty($source)) {
689 throw new RestException(400,
'Source can not be empty');
691 $sql_distinct_source =
"SELECT DISTINCT source";
692 $sql_distinct_source .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact";
693 $sql_distinct_source .=
" WHERE element LIKE 'commande'";
694 $sql_distinct_source .=
" AND source is NOT NULL";
695 $sql_distinct_source .=
" AND active != 0";
696 $source_result = $this->db->query($sql_distinct_source);
697 $source_array = array();
699 if ($source_result) {
700 $num = $this->db->num_rows($source_result);
703 $obj = $this->db->fetch_object($source_result);
704 $source_kind = (
string) $obj->source;
705 array_push($source_array, $source_kind);
710 throw new RestException(503,
'Error when retrieving a list of order contact sources: '.$this->db->lasterror());
712 if (!in_array($source, (array) $source_array,
true)) {
713 throw new RestException(400,
'Combo of Source='.$source.
' and Type='.$type.
' not found in dictionary with active order contact types');
718 throw new RestException(400,
'type can not be empty');
721 $sql_distinct_type =
"SELECT DISTINCT code";
722 $sql_distinct_type .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact";
723 $sql_distinct_type .=
" WHERE element LIKE 'commande'";
724 $sql_distinct_type .=
" AND source='".$this->db->escape($source).
"'";
725 $sql_distinct_type .=
" AND code is NOT NULL";
726 $sql_distinct_type .=
" AND active != 0";
727 $type_result = $this->db->query($sql_distinct_type);
728 $type_array = array();
731 $num = $this->db->num_rows($type_result);
734 $obj = $this->db->fetch_object($type_result);
736 $type_kind = (
string) $obj->code;
737 array_push($type_array, $type_kind);
742 throw new RestException(503,
'Error when retrieving a list of order contact types: '.$this->db->lasterror());
744 if (!in_array($type, (array) $type_array,
true)) {
745 throw new RestException(400,
'Combo of Type='.$type.
' and Source='.$source.
' not found in dictionary with active order contact types');
749 $result = $this->commande->fetch(
$id);
751 throw new RestException(404,
'Order not found');
754 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
757 $result = $this->commande->add_contact($contactid, $type, $source, $notrigger);
760 throw new RestException(400,
'Already exists: Contact='.$contactid.
' is already linked to the order='.
$id.
' as source='.$source.
' and type='.$type);
761 } elseif ($result == -1) {
762 throw new RestException(400,
'Wrong contact='.$contactid);
763 } elseif ($result == -2) {
764 throw new RestException(400,
'Wrong type='.$type);
765 } elseif ($result == -3) {
766 throw new RestException(400,
'Not allowed contacts');
767 } elseif ($result == -4) {
768 throw new RestException(400,
'ErrorCommercialNotAllowedForThirdparty');
769 } elseif ($result == -5) {
770 throw new RestException(400,
'Trigger failed');
771 } elseif ($result == -6) {
772 throw new RestException(400,
'DB_ERROR_RECORD_ALREADY_EXISTS');
773 } elseif ($result == -7) {
774 throw new RestException(400,
'Some other error');
780 'message' =>
'Contact='.$contactid.
' linked to the order='.
$id.
' as '.$source.
' '.$type
805 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
806 throw new RestException(403);
809 $result = $this->commande->fetch(
$id);
811 throw new RestException(404,
'Order not found');
815 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
818 foreach (array(
'internal',
'external') as $source) {
819 $contacts = $this->commande->liste_contact(-1, $source);
820 foreach ($contacts as $contact) {
821 if ($contact[
'id'] == $contactid && $contact[
'code'] == $type) {
822 $result = $this->commande->delete_contact($contact[
'rowid']);
825 throw new RestException(500,
'Error when deleting the contact '.$contact[
'rowid']);
834 'message' =>
'Contact unlinked from order'
849 public function put(
$id, $request_data =
null)
851 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
852 throw new RestException(403);
855 throw new RestException(400,
'No order with id=0 can exist');
857 $result = $this->commande->fetch(
$id);
859 throw new RestException(404,
'Order not found');
863 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
865 foreach ($request_data as $field => $value) {
866 if ($field ==
'id') {
869 if ($field ===
'caller') {
871 $this->commande->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
874 if ($field ==
'array_options' && is_array($value)) {
875 foreach ($value as $index => $val) {
881 $this->commande->$field = $this->
_checkValForAPI($field, $value, $this->commande);
885 if (!empty($this->commande->availability_id)) {
886 if ($this->commande->availability($this->commande->availability_id) < 0) {
887 throw new RestException(400,
'Error while updating availability');
891 if ($this->commande->update(DolibarrApiAccess::$user) > 0) {
892 return $this->
get(
$id);
894 throw new RestException(500, $this->commande->error);
907 public function delete(
$id)
909 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'supprimer')) {
910 throw new RestException(403);
913 throw new RestException(400,
'No order with id=0 can exist');
915 $result = $this->commande->fetch(
$id);
917 throw new RestException(404,
'Order not found');
921 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
924 if ($this->commande->delete(DolibarrApiAccess::$user) <= 0) {
925 throw new RestException(500,
'Error when deleting order : '.$this->commande->error);
931 'message' =>
'Order deleted'
960 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
961 throw new RestException(403);
963 $result = $this->commande->fetch(
$id);
965 throw new RestException(404,
'Order not found');
968 $result = $this->commande->fetch_thirdparty();
971 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
974 $result = $this->commande->valid(DolibarrApiAccess::$user, $idwarehouse, $notrigger);
976 throw new RestException(304,
'Error nothing done. May be object is already validated');
979 throw new RestException(500,
'Error when validating Order: '.$this->commande->error);
981 $result = $this->commande->fetch(
$id);
983 $this->commande->fetchObjectLinked();
986 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
987 $this->commande->online_payment_url = getOnlinePaymentUrl(0,
'order', (
string) $this->commande->ref);
1012 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
1013 throw new RestException(403);
1016 throw new RestException(400,
'Order ID is mandatory');
1018 $result = $this->commande->fetch(
$id);
1020 throw new RestException(404,
'Order not found');
1024 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1027 $result = $this->commande->set_reopen(DolibarrApiAccess::$user);
1029 throw new RestException(405, $this->commande->error);
1030 } elseif ($result == 0) {
1031 throw new RestException(304);
1053 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
1054 throw new RestException(403);
1057 throw new RestException(400,
'Order ID is mandatory');
1059 $result = $this->commande->fetch(
$id);
1061 throw new RestException(404,
'Order not found');
1065 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1068 $result = $this->commande->classifyBilled(DolibarrApiAccess::$user);
1070 throw new RestException(400, $this->commande->error);
1073 $this->commande->fetchObjectLinked();
1090 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
1091 throw new RestException(403);
1093 $result = $this->commande->fetch(
$id);
1095 throw new RestException(404,
'Order not found');
1099 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1102 $result = $this->commande->cloture(DolibarrApiAccess::$user, $notrigger);
1104 throw new RestException(304,
'Error nothing done. May be object is already closed');
1107 throw new RestException(500,
'Error when closing Order: '.$this->commande->error);
1110 $result = $this->commande->fetch(
$id);
1112 throw new RestException(404,
'Order not found');
1120 $this->commande->fetchObjectLinked();
1137 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
1138 throw new RestException(403);
1140 $result = $this->commande->fetch(
$id);
1142 throw new RestException(404,
'Order not found');
1146 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1149 $result = $this->commande->setDraft(DolibarrApiAccess::$user, $idwarehouse);
1151 throw new RestException(304,
'Nothing done. May be object is already closed');
1154 throw new RestException(500,
'Error when closing Order: '.$this->commande->error);
1157 $result = $this->commande->fetch(
$id);
1159 throw new RestException(404,
'Order not found');
1167 $this->commande->fetchObjectLinked();
1189 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
1191 if (!DolibarrApiAccess::$user->hasRight(
'propal',
'lire')) {
1192 throw new RestException(403);
1194 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
1195 throw new RestException(403);
1197 if (empty($proposalid)) {
1198 throw new RestException(400,
'Proposal ID is mandatory');
1201 $propal =
new Propal($this->db);
1202 $result = $propal->fetch($proposalid);
1204 throw new RestException(404,
'Proposal not found');
1207 $result = $this->commande->createFromProposal($propal, DolibarrApiAccess::$user);
1209 throw new RestException(405, $this->commande->error);
1211 $this->commande->fetchObjectLinked();
1234 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1235 if (!DolibarrApiAccess::$user->hasRight(
'expedition',
'lire')) {
1236 throw new RestException(403);
1239 $sql =
"SELECT e.rowid";
1240 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expedition as e";
1241 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"expeditiondet as edet";
1242 $sql .=
" ON e.rowid = edet.fk_expedition";
1243 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"commandedet as cdet";
1244 $sql .=
" ON edet.fk_elementdet = cdet.rowid";
1245 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"commande as c";
1246 $sql .=
" ON cdet.fk_commande = c.rowid";
1247 $sql .=
" WHERE c.rowid = ".((int)
$id);
1248 $sql .=
" GROUP BY e.rowid";
1249 $sql .= $this->db->order(
"e.rowid",
"ASC");
1252 $result = $this->db->query($sql);
1256 $num = $this->db->num_rows($result);
1258 throw new RestException(404,
'Shipments not found ');
1263 $obj = $this->db->fetch_object($result);
1264 $shipment_static =
new Expedition($this->db);
1265 if ($shipment_static->fetch($obj->rowid)) {
1271 throw new RestException(500,
'Error when retrieve shipment list : '.$this->db->lasterror());
1293 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1294 if (!DolibarrApiAccess::$user->hasRight(
'expedition',
'creer')) {
1295 throw new RestException(403);
1297 if ($warehouse_id <= 0) {
1298 throw new RestException(404,
'Warehouse not found');
1300 $result = $this->commande->fetch(
$id);
1302 throw new RestException(404,
'Order not found');
1305 $shipment->socid = $this->commande->socid;
1306 $shipment->origin_id = $this->commande->id;
1307 $shipment->origin = $this->commande->element;
1308 $result = $shipment->create(DolibarrApiAccess::$user);
1310 throw new RestException(500,
'Error on creating expedition :'.$this->db->lasterror());
1312 foreach ($this->commande->lines as $line) {
1313 $result = $shipment->create_line($warehouse_id, $line->id, $line->qty);
1315 throw new RestException(500,
'Error on creating expedition lines:'.$this->db->lasterror());
1318 return $shipment->id;
1339 unset(
$object->barcode_type_code);
1340 unset(
$object->barcode_type_label);
1341 unset(
$object->barcode_type_coder);
1355 if ($data ===
null) {
1358 $commande = array();
1359 foreach (Orders::$FIELDS as $field) {
1360 if (!isset($data[$field])) {
1361 throw new RestException(400, $field.
" field missing");
1363 $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.
_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.
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, $forbiddenfields=array())
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.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string