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);
537 $result = $orderline->fetch($lineid);
539 throw new RestException(404,
'Order line not found');
542 if ($orderline->fk_commande !=
$id) {
543 throw new RestException(403,
'Line does not belong to this order');
546 $updateRes = $this->commande->updateline(
549 $request_data->subprice,
551 $request_data->remise_percent,
552 $request_data->tva_tx,
553 $request_data->localtax1_tx,
554 $request_data->localtax2_tx,
555 $request_data->price_base_type ? $request_data->price_base_type :
'HT',
556 $request_data->info_bits,
557 $request_data->date_start,
558 $request_data->date_end,
559 $request_data->product_type,
560 $request_data->fk_parent_line,
562 $request_data->fk_fournprice,
563 $request_data->pa_ht,
564 $request_data->label,
565 $request_data->special_code,
566 $request_data->array_options,
567 $request_data->fk_unit,
568 $request_data->multicurrency_subprice,
570 $request_data->ref_ext,
574 if ($updateRes > 0) {
575 $result = $this->
get(
$id);
576 unset($result->line);
596 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
597 throw new RestException(403);
600 $result = $this->commande->fetch(
$id);
602 throw new RestException(404,
'Order not found');
606 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
609 $updateRes = $this->commande->deleteLine(DolibarrApiAccess::$user, $lineid,
$id);
610 if ($updateRes > 0) {
611 return $this->
get(
$id);
613 throw new RestException(405, $this->commande->error);
632 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
633 throw new RestException(403);
636 $result = $this->commande->fetch(
$id);
638 throw new RestException(404,
'Order not found');
642 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
645 $contacts = $this->commande->liste_contact(-1,
'external', 0, $type);
646 $socpeoples = $this->commande->liste_contact(-1,
'internal', 0, $type);
648 $contacts = array_merge($contacts, $socpeoples);
672 public function postContact(
$id, $contactid, $type, $source =
"external", $notrigger = 0)
674 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
675 throw new RestException(403);
679 if (empty($source)) {
680 throw new RestException(400,
'Source can not be empty');
682 $sql_distinct_source =
"SELECT DISTINCT source";
683 $sql_distinct_source .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact";
684 $sql_distinct_source .=
" WHERE element LIKE 'commande'";
685 $sql_distinct_source .=
" AND source is NOT NULL";
686 $sql_distinct_source .=
" AND active != 0";
687 $source_result = $this->db->query($sql_distinct_source);
688 $source_array = array();
690 if ($source_result) {
691 $num = $this->db->num_rows($source_result);
694 $obj = $this->db->fetch_object($source_result);
695 $source_kind = (string) $obj->source;
696 array_push($source_array, $source_kind);
701 throw new RestException(503,
'Error when retrieving a list of order contact sources: '.$this->db->lasterror());
703 if (!in_array($source, (array) $source_array,
true)) {
704 throw new RestException(400,
'Combo of Source='.$source.
' and Type='.$type.
' not found in dictionary with active order contact types');
709 throw new RestException(400,
'type can not be empty');
712 $sql_distinct_type =
"SELECT DISTINCT code";
713 $sql_distinct_type .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact";
714 $sql_distinct_type .=
" WHERE element LIKE 'commande'";
715 $sql_distinct_type .=
" AND source='".$this->db->escape($source).
"'";
716 $sql_distinct_type .=
" AND code is NOT NULL";
717 $sql_distinct_type .=
" AND active != 0";
718 $type_result = $this->db->query($sql_distinct_type);
719 $type_array = array();
722 $num = $this->db->num_rows($type_result);
725 $obj = $this->db->fetch_object($type_result);
727 $type_kind = (string) $obj->code;
728 array_push($type_array, $type_kind);
733 throw new RestException(503,
'Error when retrieving a list of order contact types: '.$this->db->lasterror());
735 if (!in_array($type, (array) $type_array,
true)) {
736 throw new RestException(400,
'Combo of Type='.$type.
' and Source='.$source.
' not found in dictionary with active order contact types');
740 $result = $this->commande->fetch(
$id);
742 throw new RestException(404,
'Order not found');
745 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
748 $result = $this->commande->add_contact($contactid, $type, $source, $notrigger);
751 throw new RestException(400,
'Already exists: Contact='.$contactid.
' is already linked to the order='.
$id.
' as source='.$source.
' and type='.$type);
752 } elseif ($result == -1) {
753 throw new RestException(400,
'Wrong contact='.$contactid);
754 } elseif ($result == -2) {
755 throw new RestException(400,
'Wrong type='.$type);
756 } elseif ($result == -3) {
757 throw new RestException(400,
'Not allowed contacts');
758 } elseif ($result == -4) {
759 throw new RestException(400,
'ErrorCommercialNotAllowedForThirdparty');
760 } elseif ($result == -5) {
761 throw new RestException(400,
'Trigger failed');
762 } elseif ($result == -6) {
763 throw new RestException(400,
'DB_ERROR_RECORD_ALREADY_EXISTS');
764 } elseif ($result == -7) {
765 throw new RestException(400,
'Some other error');
771 'message' =>
'Contact='.$contactid.
' linked to the order='.
$id.
' as '.$source.
' '.$type
795 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
796 throw new RestException(403);
799 $result = $this->commande->fetch(
$id);
801 throw new RestException(404,
'Order not found');
805 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
808 foreach (array(
'internal',
'external') as $source) {
809 $contacts = $this->commande->liste_contact(-1, $source);
810 foreach ($contacts as $contact) {
811 if ($contact[
'id'] == $contactid && $contact[
'code'] == $type) {
812 $result = $this->commande->delete_contact($contact[
'rowid']);
815 throw new RestException(500,
'Error when deleting the contact '.$contact[
'rowid']);
824 'message' =>
'Contact unlinked from order'
838 public function put(
$id, $request_data =
null)
840 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
841 throw new RestException(403);
844 throw new RestException(400,
'No order with id=0 can exist');
846 $result = $this->commande->fetch(
$id);
848 throw new RestException(404,
'Order not found');
852 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
854 foreach ($request_data as $field => $value) {
855 if ($field ==
'id') {
858 if ($field ===
'caller') {
860 $this->commande->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
863 if ($field ==
'array_options' && is_array($value)) {
864 foreach ($value as $index => $val) {
865 $this->commande->array_options[$index] = $this->
_checkValForAPI($field, $val, $this->commande);
870 $this->commande->$field = $this->
_checkValForAPI($field, $value, $this->commande);
874 if (!empty($this->commande->availability_id)) {
875 if ($this->commande->availability($this->commande->availability_id) < 0) {
876 throw new RestException(400,
'Error while updating availability');
880 if ($this->commande->update(DolibarrApiAccess::$user) > 0) {
881 return $this->
get(
$id);
883 throw new RestException(500, $this->commande->error);
895 public function delete(
$id)
897 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'supprimer')) {
898 throw new RestException(403);
901 throw new RestException(400,
'No order with id=0 can exist');
903 $result = $this->commande->fetch(
$id);
905 throw new RestException(404,
'Order not found');
909 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
912 if ($this->commande->delete(DolibarrApiAccess::$user) <= 0) {
913 throw new RestException(500,
'Error when deleting order : '.$this->commande->error);
919 'message' =>
'Order deleted'
947 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
948 throw new RestException(403);
950 $result = $this->commande->fetch(
$id);
952 throw new RestException(404,
'Order not found');
955 $result = $this->commande->fetch_thirdparty();
958 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
961 $result = $this->commande->valid(DolibarrApiAccess::$user, $idwarehouse, $notrigger);
963 throw new RestException(304,
'Error nothing done. May be object is already validated');
966 throw new RestException(500,
'Error when validating Order: '.$this->commande->error);
968 $result = $this->commande->fetch(
$id);
970 $this->commande->fetchObjectLinked();
973 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
974 $this->commande->online_payment_url = getOnlinePaymentUrl(0,
'order', $this->commande->ref);
998 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
999 throw new RestException(403);
1002 throw new RestException(400,
'Order ID is mandatory');
1004 $result = $this->commande->fetch(
$id);
1006 throw new RestException(404,
'Order not found');
1009 $result = $this->commande->set_reopen(DolibarrApiAccess::$user);
1011 throw new RestException(405, $this->commande->error);
1012 } elseif ($result == 0) {
1013 throw new RestException(304);
1034 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
1035 throw new RestException(403);
1038 throw new RestException(400,
'Order ID is mandatory');
1040 $result = $this->commande->fetch(
$id);
1042 throw new RestException(404,
'Order not found');
1045 $result = $this->commande->classifyBilled(DolibarrApiAccess::$user);
1047 throw new RestException(400, $this->commande->error);
1050 $result = $this->commande->fetch(
$id);
1052 throw new RestException(404,
'Order not found');
1056 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1059 $this->commande->fetchObjectLinked();
1075 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
1076 throw new RestException(403);
1078 $result = $this->commande->fetch(
$id);
1080 throw new RestException(404,
'Order not found');
1084 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1087 $result = $this->commande->cloture(DolibarrApiAccess::$user, $notrigger);
1089 throw new RestException(304,
'Error nothing done. May be object is already closed');
1092 throw new RestException(500,
'Error when closing Order: '.$this->commande->error);
1095 $result = $this->commande->fetch(
$id);
1097 throw new RestException(404,
'Order not found');
1105 $this->commande->fetchObjectLinked();
1121 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
1122 throw new RestException(403);
1124 $result = $this->commande->fetch(
$id);
1126 throw new RestException(404,
'Order not found');
1130 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1133 $result = $this->commande->setDraft(DolibarrApiAccess::$user, $idwarehouse);
1135 throw new RestException(304,
'Nothing done. May be object is already closed');
1138 throw new RestException(500,
'Error when closing Order: '.$this->commande->error);
1141 $result = $this->commande->fetch(
$id);
1143 throw new RestException(404,
'Order not found');
1151 $this->commande->fetchObjectLinked();
1172 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
1174 if (!DolibarrApiAccess::$user->hasRight(
'propal',
'lire')) {
1175 throw new RestException(403);
1177 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
1178 throw new RestException(403);
1180 if (empty($proposalid)) {
1181 throw new RestException(400,
'Proposal ID is mandatory');
1184 $propal =
new Propal($this->db);
1185 $result = $propal->fetch($proposalid);
1187 throw new RestException(404,
'Proposal not found');
1190 $result = $this->commande->createFromProposal($propal, DolibarrApiAccess::$user);
1192 throw new RestException(405, $this->commande->error);
1194 $this->commande->fetchObjectLinked();
1216 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1217 if (!DolibarrApiAccess::$user->hasRight(
'expedition',
'lire')) {
1218 throw new RestException(403);
1221 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1224 $sql =
"SELECT e.rowid";
1225 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expedition as e";
1226 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"expeditiondet as edet";
1227 $sql .=
" ON e.rowid = edet.fk_expedition";
1228 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"commandedet as cdet";
1229 $sql .=
" ON edet.fk_elementdet = cdet.rowid";
1230 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"commande as c";
1231 $sql .=
" ON cdet.fk_commande = c.rowid";
1232 $sql .=
" WHERE c.rowid = ".((int)
$id);
1233 $sql .=
" GROUP BY e.rowid";
1234 $sql .= $this->db->order(
"e.rowid",
"ASC");
1237 $result = $this->db->query($sql);
1241 $num = $this->db->num_rows($result);
1243 throw new RestException(404,
'Shipments not found ');
1248 $obj = $this->db->fetch_object($result);
1249 $shipment_static =
new Expedition($this->db);
1250 if ($shipment_static->fetch($obj->rowid)) {
1256 throw new RestException(500,
'Error when retrieve shipment list : '.$this->db->lasterror());
1277 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1278 if (!DolibarrApiAccess::$user->hasRight(
'expedition',
'creer')) {
1279 throw new RestException(403);
1281 if ($warehouse_id <= 0) {
1282 throw new RestException(404,
'Warehouse not found');
1284 $result = $this->commande->fetch(
$id);
1286 throw new RestException(404,
'Order not found');
1289 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1292 $shipment->socid = $this->commande->socid;
1293 $shipment->origin_id = $this->commande->id;
1294 $shipment->origin = $this->commande->element;
1295 $result = $shipment->create(DolibarrApiAccess::$user);
1297 throw new RestException(500,
'Error on creating expedition :'.$this->db->lasterror());
1299 foreach ($this->commande->lines as $line) {
1300 $result = $shipment->create_line($warehouse_id, $line->id, $line->qty);
1302 throw new RestException(500,
'Error on creating expedition lines:'.$this->db->lasterror());
1305 return $shipment->id;
1326 unset(
$object->barcode_type_code);
1327 unset(
$object->barcode_type_label);
1328 unset(
$object->barcode_type_coder);
1342 if ($data ===
null) {
1345 $commande = array();
1346 foreach (Orders::$FIELDS as $field) {
1347 if (!isset($data[$field])) {
1348 throw new RestException(400, $field.
" field missing");
1350 $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.
Class to manage order lines.
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.