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);
365 if ($this->commande->create(DolibarrApiAccess::$user) < 0) {
366 throw new RestException(500,
"Error creating order", array_merge(array($this->commande->error), $this->commande->errors));
369 return ((
int) $this->commande->id);
386 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
387 throw new RestException(403);
390 $result = $this->commande->fetch(
$id);
392 throw new RestException(404,
'Order not found');
396 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
398 $this->commande->getLinesArray();
400 foreach ($this->commande->lines as $line) {
420 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
421 throw new RestException(403);
424 $result = $this->commande->fetch(
$id);
426 throw new RestException(404,
'Order not found');
430 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
433 $this->commande->fetch_lines();
434 foreach ($this->commande->lines as $line) {
435 if ($line->id == $lineid) {
439 throw new RestException(404,
'Line not found');
457 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
458 throw new RestException(403);
461 $result = $this->commande->fetch(
$id);
463 throw new RestException(404,
'Order not found');
467 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
470 $request_data = (object) $request_data;
472 $request_data->desc =
sanitizeVal($request_data->desc,
'restricthtml');
473 $request_data->label =
sanitizeVal($request_data->label);
475 $updateRes = $this->commande->addline(
477 $request_data->subprice,
479 $request_data->tva_tx,
480 $request_data->localtax1_tx,
481 $request_data->localtax2_tx,
482 $request_data->fk_product,
483 $request_data->remise_percent,
484 $request_data->info_bits,
485 $request_data->fk_remise_except,
486 $request_data->price_base_type ? $request_data->price_base_type :
'HT',
487 $request_data->subprice,
488 $request_data->date_start,
489 $request_data->date_end,
490 $request_data->product_type,
492 $request_data->special_code,
493 $request_data->fk_parent_line,
494 $request_data->fk_fournprice,
495 $request_data->pa_ht,
496 $request_data->label,
497 $request_data->array_options,
498 $request_data->fk_unit,
499 $request_data->origin,
500 $request_data->origin_id,
501 $request_data->multicurrency_subprice,
502 $request_data->ref_ext
505 if ($updateRes > 0) {
508 throw new RestException(400, $this->commande->errorsToString());
527 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
528 throw new RestException(403);
531 $result = $this->commande->fetch(
$id);
533 throw new RestException(404,
'Order not found');
537 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
540 $request_data = (object) $request_data;
542 $request_data->desc =
sanitizeVal($request_data->desc,
'restricthtml');
543 $request_data->label =
sanitizeVal($request_data->label);
546 $result = $orderline->fetch($lineid);
548 throw new RestException(404,
'Order line not found');
551 if ($orderline->fk_commande !=
$id) {
552 throw new RestException(403,
'Line does not belong to this order');
555 $updateRes = $this->commande->updateline(
558 $request_data->subprice,
560 $request_data->remise_percent,
561 $request_data->tva_tx,
562 $request_data->localtax1_tx,
563 $request_data->localtax2_tx,
564 $request_data->price_base_type ? $request_data->price_base_type :
'HT',
565 $request_data->info_bits,
566 $request_data->date_start,
567 $request_data->date_end,
568 $request_data->product_type,
569 $request_data->fk_parent_line,
571 $request_data->fk_fournprice,
572 $request_data->pa_ht,
573 $request_data->label,
574 $request_data->special_code,
575 $request_data->array_options,
576 $request_data->fk_unit,
577 $request_data->multicurrency_subprice,
579 $request_data->ref_ext,
583 if ($updateRes > 0) {
584 $result = $this->
get(
$id);
585 unset($result->line);
606 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
607 throw new RestException(403);
610 $result = $this->commande->fetch(
$id);
612 throw new RestException(404,
'Order not found');
616 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
619 $updateRes = $this->commande->deleteLine(DolibarrApiAccess::$user, $lineid,
$id);
620 if ($updateRes > 0) {
621 return $this->
get(
$id);
623 throw new RestException(405, $this->commande->errorsToString());
643 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
644 throw new RestException(403);
647 $result = $this->commande->fetch(
$id);
649 throw new RestException(404,
'Order not found');
653 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
656 $contacts = $this->commande->liste_contact(-1,
'external', 0, $type);
657 $socpeoples = $this->commande->liste_contact(-1,
'internal', 0, $type);
659 $contacts = array_merge($contacts, $socpeoples);
684 public function postContact(
$id, $contactid, $type, $source =
"external", $notrigger = 0)
686 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
687 throw new RestException(403);
691 if (empty($source)) {
692 throw new RestException(400,
'Source can not be empty');
694 $sql_distinct_source =
"SELECT DISTINCT source";
695 $sql_distinct_source .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact";
696 $sql_distinct_source .=
" WHERE element LIKE 'commande'";
697 $sql_distinct_source .=
" AND source is NOT NULL";
698 $sql_distinct_source .=
" AND active != 0";
699 $source_result = $this->db->query($sql_distinct_source);
700 $source_array = array();
702 if ($source_result) {
703 $num = $this->db->num_rows($source_result);
706 $obj = $this->db->fetch_object($source_result);
707 $source_kind = (string) $obj->source;
708 array_push($source_array, $source_kind);
713 throw new RestException(503,
'Error when retrieving a list of order contact sources: '.$this->db->lasterror());
715 if (!in_array($source, (array) $source_array,
true)) {
716 throw new RestException(400,
'Combo of Source='.$source.
' and Type='.$type.
' not found in dictionary with active order contact types');
721 throw new RestException(400,
'type can not be empty');
724 $sql_distinct_type =
"SELECT DISTINCT code";
725 $sql_distinct_type .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact";
726 $sql_distinct_type .=
" WHERE element LIKE 'commande'";
727 $sql_distinct_type .=
" AND source='".$this->db->escape($source).
"'";
728 $sql_distinct_type .=
" AND code is NOT NULL";
729 $sql_distinct_type .=
" AND active != 0";
730 $type_result = $this->db->query($sql_distinct_type);
731 $type_array = array();
734 $num = $this->db->num_rows($type_result);
737 $obj = $this->db->fetch_object($type_result);
739 $type_kind = (string) $obj->code;
740 array_push($type_array, $type_kind);
745 throw new RestException(503,
'Error when retrieving a list of order contact types: '.$this->db->lasterror());
747 if (!in_array($type, (array) $type_array,
true)) {
748 throw new RestException(400,
'Combo of Type='.$type.
' and Source='.$source.
' not found in dictionary with active order contact types');
752 $result = $this->commande->fetch(
$id);
754 throw new RestException(404,
'Order not found');
757 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
760 $result = $this->commande->add_contact($contactid, $type, $source, $notrigger);
763 throw new RestException(400,
'Already exists: Contact='.$contactid.
' is already linked to the order='.
$id.
' as source='.$source.
' and type='.$type);
764 } elseif ($result == -1) {
765 throw new RestException(400,
'Wrong contact='.$contactid);
766 } elseif ($result == -2) {
767 throw new RestException(400,
'Wrong type='.$type);
768 } elseif ($result == -3) {
769 throw new RestException(400,
'Not allowed contacts');
770 } elseif ($result == -4) {
771 throw new RestException(400,
'ErrorCommercialNotAllowedForThirdparty');
772 } elseif ($result == -5) {
773 throw new RestException(400,
'Trigger failed');
774 } elseif ($result == -6) {
775 throw new RestException(400,
'DB_ERROR_RECORD_ALREADY_EXISTS');
776 } elseif ($result == -7) {
777 throw new RestException(400,
'Some other error');
783 'message' =>
'Contact='.$contactid.
' linked to the order='.
$id.
' as '.$source.
' '.$type
808 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
809 throw new RestException(403);
812 $result = $this->commande->fetch(
$id);
814 throw new RestException(404,
'Order not found');
818 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
821 foreach (array(
'internal',
'external') as $source) {
822 $contacts = $this->commande->liste_contact(-1, $source);
823 foreach ($contacts as $contact) {
824 if ($contact[
'id'] == $contactid && $contact[
'code'] == $type) {
825 $result = $this->commande->delete_contact($contact[
'rowid']);
828 throw new RestException(500,
'Error when deleting the contact '.$contact[
'rowid']);
837 'message' =>
'Contact unlinked from order'
852 public function put(
$id, $request_data =
null)
854 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
855 throw new RestException(403);
858 throw new RestException(400,
'No order with id=0 can exist');
860 $result = $this->commande->fetch(
$id);
862 throw new RestException(404,
'Order not found');
866 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
868 foreach ($request_data as $field => $value) {
869 if ($field ==
'id') {
872 if ($field ===
'caller') {
874 $this->commande->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
877 if ($field ==
'array_options' && is_array($value)) {
878 foreach ($value as $index => $val) {
884 $this->commande->$field = $this->
_checkValForAPI($field, $value, $this->commande);
888 if (!empty($this->commande->availability_id)) {
889 if ($this->commande->availability($this->commande->availability_id) < 0) {
890 throw new RestException(400,
'Error while updating availability');
894 if ($this->commande->update(DolibarrApiAccess::$user) > 0) {
895 return $this->
get(
$id);
897 throw new RestException(500, $this->commande->errorsToString());
910 public function delete(
$id)
912 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'supprimer')) {
913 throw new RestException(403);
916 throw new RestException(400,
'No order with id=0 can exist');
918 $result = $this->commande->fetch(
$id);
920 throw new RestException(404,
'Order not found');
924 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
927 if ($this->commande->delete(DolibarrApiAccess::$user) <= 0) {
928 throw new RestException(500,
'Error when deleting order : '.$this->commande->errorsToString());
934 'message' =>
'Order deleted'
963 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
964 throw new RestException(403);
966 $result = $this->commande->fetch(
$id);
968 throw new RestException(404,
'Order not found');
971 $result = $this->commande->fetch_thirdparty();
974 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
977 $result = $this->commande->valid(DolibarrApiAccess::$user, $idwarehouse, $notrigger);
979 throw new RestException(304,
'Error nothing done. May be object is already validated');
982 throw new RestException(500,
'Error when validating Order: '.$this->commande->errorsToString());
984 $result = $this->commande->fetch(
$id);
986 $this->commande->fetchObjectLinked();
989 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
990 $this->commande->online_payment_url = getOnlinePaymentUrl(0,
'order', (
string) $this->commande->ref);
1015 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
1016 throw new RestException(403);
1019 throw new RestException(400,
'Order ID is mandatory');
1021 $result = $this->commande->fetch(
$id);
1023 throw new RestException(404,
'Order not found');
1027 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1030 $result = $this->commande->set_reopen(DolibarrApiAccess::$user);
1032 throw new RestException(405, $this->commande->errorsToString());
1033 } elseif ($result == 0) {
1034 throw new RestException(304);
1056 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
1057 throw new RestException(403);
1060 throw new RestException(400,
'Order ID is mandatory');
1062 $result = $this->commande->fetch(
$id);
1064 throw new RestException(404,
'Order not found');
1068 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1071 $result = $this->commande->classifyBilled(DolibarrApiAccess::$user);
1073 throw new RestException(400, $this->commande->errorsToString());
1076 $this->commande->fetchObjectLinked();
1093 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
1094 throw new RestException(403);
1096 $result = $this->commande->fetch(
$id);
1098 throw new RestException(404,
'Order not found');
1102 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1105 $result = $this->commande->cloture(DolibarrApiAccess::$user, $notrigger);
1107 throw new RestException(304,
'Error nothing done. May be object is already closed');
1110 throw new RestException(500,
'Error when closing Order: '.$this->commande->errorsToString());
1113 $result = $this->commande->fetch(
$id);
1115 throw new RestException(404,
'Order not found');
1123 $this->commande->fetchObjectLinked();
1140 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
1141 throw new RestException(403);
1143 $result = $this->commande->fetch(
$id);
1145 throw new RestException(404,
'Order not found');
1149 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1152 $result = $this->commande->setDraft(DolibarrApiAccess::$user, $idwarehouse);
1154 throw new RestException(304,
'Nothing done. May be object is already closed');
1157 throw new RestException(500,
'Error when closing Order: '.$this->commande->errorsToString());
1160 $result = $this->commande->fetch(
$id);
1162 throw new RestException(404,
'Order not found');
1170 $this->commande->fetchObjectLinked();
1192 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
1194 if (!DolibarrApiAccess::$user->hasRight(
'propal',
'lire')) {
1195 throw new RestException(403);
1197 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
1198 throw new RestException(403);
1200 if (empty($proposalid)) {
1201 throw new RestException(400,
'Proposal ID is mandatory');
1204 $propal =
new Propal($this->db);
1205 $result = $propal->fetch($proposalid);
1207 throw new RestException(404,
'Proposal not found');
1211 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1214 $result = $this->commande->createFromProposal($propal, DolibarrApiAccess::$user);
1216 throw new RestException(405, $this->commande->errorsToString());
1218 $this->commande->fetchObjectLinked();
1241 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1242 if (!DolibarrApiAccess::$user->hasRight(
'expedition',
'lire')) {
1243 throw new RestException(403);
1246 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1249 $sql =
"SELECT e.rowid";
1250 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expedition as e";
1251 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"expeditiondet as edet";
1252 $sql .=
" ON e.rowid = edet.fk_expedition";
1253 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"commandedet as cdet";
1254 $sql .=
" ON edet.fk_elementdet = cdet.rowid";
1255 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"commande as c";
1256 $sql .=
" ON cdet.fk_commande = c.rowid";
1257 $sql .=
" WHERE c.rowid = ".((int)
$id);
1258 $sql .=
" GROUP BY e.rowid";
1259 $sql .= $this->db->order(
"e.rowid",
"ASC");
1262 $result = $this->db->query($sql);
1266 $num = $this->db->num_rows($result);
1268 throw new RestException(404,
'Shipments not found ');
1273 $obj = $this->db->fetch_object($result);
1274 $shipment_static =
new Expedition($this->db);
1275 if ($shipment_static->fetch($obj->rowid)) {
1281 throw new RestException(500,
'Error when retrieve shipment list : '.$this->db->lasterror());
1303 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1304 if (!DolibarrApiAccess::$user->hasRight(
'expedition',
'creer')) {
1305 throw new RestException(403);
1307 if ($warehouse_id <= 0) {
1308 throw new RestException(404,
'Warehouse not found');
1310 $result = $this->commande->fetch(
$id);
1312 throw new RestException(404,
'Order not found');
1315 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1318 $shipment->socid = $this->commande->socid;
1319 $shipment->origin_id = $this->commande->id;
1320 $shipment->origin = $this->commande->element;
1321 $result = $shipment->create(DolibarrApiAccess::$user);
1323 throw new RestException(500,
'Error on creating expedition :'.$this->db->lasterror());
1325 foreach ($this->commande->lines as $line) {
1326 $result = $shipment->create_line($warehouse_id, $line->id, $line->qty);
1328 throw new RestException(500,
'Error on creating expedition lines:'.$this->db->lasterror());
1331 return $shipment->id;
1352 unset(
$object->barcode_type_code);
1353 unset(
$object->barcode_type_label);
1354 unset(
$object->barcode_type_coder);
1355 unset(
$object->fk_remise_except);
1366 unset(
$object->civility_code);
1368 unset(
$object->actiontypecode);
1382 if ($data ===
null) {
1385 $commande = array();
1386 foreach (Orders::$FIELDS as $field) {
1387 if (!isset($data[$field])) {
1388 throw new RestException(400, $field.
" field missing");
1390 $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.
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, $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.