22use Luracast\Restler\RestException;
24require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
38 public static $FIELDS = array(
56 $this->commande =
new Commande($this->db);
71 public function get(
$id, $contact_list = -1)
73 return $this->
_fetch(
$id,
'',
'', $contact_list);
90 public function getByRef($ref, $contact_list = -1)
92 return $this->
_fetch(0, $ref,
'', $contact_list);
111 return $this->
_fetch(0,
'', $ref_ext, $contact_list);
127 private function _fetch(
$id, $ref =
'', $ref_ext =
'', $contact_list = -1)
129 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
130 throw new RestException(403);
132 if (empty(
$id) && empty($ref) && empty($ref_ext)) {
133 throw new RestException(400,
'No ID or Ref provided');
135 $result = $this->commande->fetch(
$id, $ref, $ref_ext);
137 throw new RestException(404,
'Order not found');
141 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
144 if ($contact_list > -1) {
146 $tmparray = $this->commande->liste_contact(-1,
'external', $contact_list);
147 if (is_array($tmparray)) {
148 $this->commande->contacts_ids = $tmparray;
150 $tmparray = $this->commande->liste_contact(-1,
'internal', $contact_list);
151 if (is_array($tmparray)) {
152 $this->commande->contacts_ids_internal = $tmparray;
156 $this->commande->fetchObjectLinked();
159 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
160 $this->commande->online_payment_url = getOnlinePaymentUrl(0,
'order', (
string) $this->commande->ref);
189 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $thirdparty_ids =
'', $sqlfilters =
'', $sqlfilterlines =
'', $properties =
'', $pagination_data =
false, $loadlinkedobjects = 0)
193 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
194 throw new RestException(403);
200 $socids = DolibarrApiAccess::$user->socid ?: $thirdparty_ids;
204 if (!DolibarrApiAccess::$user->hasRight(
'societe',
'client',
'voir') && !$socids) {
205 $search_sale = DolibarrApiAccess::$user->id;
208 $sql =
"SELECT t.rowid";
209 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande AS t";
210 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe AS s ON (s.rowid = t.fk_soc)";
211 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"commande_extrafields AS ef ON (ef.fk_object = t.rowid)";
212 $sql .=
' WHERE t.entity IN ('.getEntity(
'commande').
')';
214 $sql .=
" AND t.fk_soc IN (".$this->db->sanitize($socids).
")";
217 if ($search_sale && $search_sale !=
'-1') {
218 if ($search_sale == -2) {
219 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc)";
220 } elseif ($search_sale > 0) {
221 $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).
")";
224 $parameters = array();
225 $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $this->commande);
226 $sql .= $hookmanager->resPrint;
232 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
236 if ($sqlfilterlines) {
238 $sql .=
" AND EXISTS (SELECT tl.rowid FROM ".MAIN_DB_PREFIX.
"commandedet AS tl WHERE tl.fk_commande = t.rowid";
242 throw new RestException(400,
'Error when validating parameter sqlfilterlines -> '.$errormessage);
247 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
249 $sql .= $this->db->order($sortfield, $sortorder);
254 $offset = $limit * $page;
256 $sql .= $this->db->plimit($limit + 1, $offset);
260 $result = $this->db->query($sql);
263 $num = $this->db->num_rows($result);
264 $min = min($num, ($limit <= 0 ? $num : $limit));
267 $obj = $this->db->fetch_object($result);
268 $commande_static =
new Commande($this->db);
269 if ($commande_static->fetch($obj->rowid) > 0) {
271 $tmparray = $commande_static->liste_contact(-1,
'external', 1);
272 if (is_array($tmparray)) {
273 $commande_static->contacts_ids = $tmparray;
276 if ($loadlinkedobjects) {
278 $commande_static->fetchObjectLinked();
282 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
283 $commande_static->online_payment_url = getOnlinePaymentUrl(0,
'order', (
string) $commande_static->ref);
290 throw new RestException(503,
'Error when retrieve commande list : '.$this->db->lasterror());
294 if ($pagination_data) {
295 $totalsResult = $this->db->query($sqlTotals);
296 $total = $this->db->fetch_object($totalsResult)->total;
301 $obj_ret[
'data'] = $tmp;
302 $obj_ret[
'pagination'] = [
303 'total' => (int) $total,
305 'page_count' => ceil((
int) $total / $limit),
327 public function post($request_data =
null)
330 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
331 throw new RestException(403,
"Insufficiant rights");
338 $socid = (int) $request_data[
'socid'];
339 $thirdpartytmp =
new Societe($this->db);
340 $thirdparty_result = $thirdpartytmp->fetch($socid);
341 if ($thirdparty_result < 1) {
342 throw new RestException(404,
'Third party with id='.$socid.
' not found or not allowed');
345 throw new RestException(404,
'Third party with id='.$thirdpartytmp->id.
' not found or not allowed');
348 foreach ($request_data as $field => $value) {
349 if ($field ===
'caller') {
351 $this->commande->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
354 if ($field ==
'id') {
355 throw new RestException(400,
'Creating with id field is forbidden');
357 if ($field ==
'entity' && ((
int) $value) != ((
int)
$conf->entity)) {
358 throw new RestException(403,
'Creating with entity='.((
int) $value).
' MUST be the same entity='.((
int)
$conf->entity).
' as your API user/key belongs to');
361 $this->commande->$field = $this->
_checkValForAPI($field, $value, $this->commande);
371 if ($this->commande->create(DolibarrApiAccess::$user) < 0) {
372 throw new RestException(500,
"Error creating order", array_merge(array($this->commande->error), $this->commande->errors));
375 return ((
int) $this->commande->id);
392 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
393 throw new RestException(403);
396 $result = $this->commande->fetch(
$id);
398 throw new RestException(404,
'Order not found');
402 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
404 $this->commande->getLinesArray();
406 foreach ($this->commande->lines as $line) {
426 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
427 throw new RestException(403);
430 $result = $this->commande->fetch(
$id);
432 throw new RestException(404,
'Order not found');
436 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
439 $this->commande->fetch_lines();
440 foreach ($this->commande->lines as $line) {
441 if ($line->id == $lineid) {
445 throw new RestException(404,
'Line not found');
463 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
464 throw new RestException(403);
467 $result = $this->commande->fetch(
$id);
469 throw new RestException(404,
'Order not found');
473 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
476 $request_data = (object) $request_data;
478 $request_data->desc =
sanitizeVal($request_data->desc,
'restricthtml');
479 $request_data->label =
sanitizeVal($request_data->label);
481 $updateRes = $this->commande->addline(
483 $request_data->subprice,
485 $request_data->tva_tx,
486 $request_data->localtax1_tx,
487 $request_data->localtax2_tx,
488 $request_data->fk_product,
489 $request_data->remise_percent,
490 $request_data->info_bits,
491 $request_data->fk_remise_except,
492 $request_data->price_base_type ? $request_data->price_base_type :
'HT',
493 $request_data->subprice,
494 $request_data->date_start,
495 $request_data->date_end,
496 $request_data->product_type,
498 $request_data->special_code,
499 $request_data->fk_parent_line,
500 $request_data->fk_fournprice,
501 $request_data->pa_ht,
502 $request_data->label,
503 $request_data->array_options,
504 $request_data->fk_unit,
505 $request_data->origin,
506 $request_data->origin_id,
507 $request_data->multicurrency_subprice,
508 $request_data->ref_ext
511 if ($updateRes > 0) {
514 throw new RestException(400, $this->commande->error);
533 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
534 throw new RestException(403);
537 $result = $this->commande->fetch(
$id);
539 throw new RestException(404,
'Order not found');
543 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
546 $request_data = (object) $request_data;
548 $request_data->desc =
sanitizeVal($request_data->desc,
'restricthtml');
549 $request_data->label =
sanitizeVal($request_data->label);
552 $result = $orderline->fetch($lineid);
554 throw new RestException(404,
'Order line not found');
557 if ($orderline->fk_commande !=
$id) {
558 throw new RestException(403,
'Line does not belong to this order');
561 $updateRes = $this->commande->updateline(
564 $request_data->subprice,
566 $request_data->remise_percent,
567 $request_data->tva_tx,
568 $request_data->localtax1_tx,
569 $request_data->localtax2_tx,
570 $request_data->price_base_type ? $request_data->price_base_type :
'HT',
571 $request_data->info_bits,
572 $request_data->date_start,
573 $request_data->date_end,
574 $request_data->product_type,
575 $request_data->fk_parent_line,
577 $request_data->fk_fournprice,
578 $request_data->pa_ht,
579 $request_data->label,
580 $request_data->special_code,
581 $request_data->array_options,
582 $request_data->fk_unit,
583 $request_data->multicurrency_subprice,
585 $request_data->ref_ext,
589 if ($updateRes > 0) {
590 $result = $this->
get(
$id);
591 unset($result->line);
612 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
613 throw new RestException(403);
616 $result = $this->commande->fetch(
$id);
618 throw new RestException(404,
'Order not found');
622 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
625 $updateRes = $this->commande->deleteLine(DolibarrApiAccess::$user, $lineid,
$id);
626 if ($updateRes > 0) {
627 return $this->
get(
$id);
629 throw new RestException(405, $this->commande->error);
649 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
650 throw new RestException(403);
653 $result = $this->commande->fetch(
$id);
655 throw new RestException(404,
'Order not found');
659 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
662 $contacts = $this->commande->liste_contact(-1,
'external', 0, $type);
663 $socpeoples = $this->commande->liste_contact(-1,
'internal', 0, $type);
665 $contacts = array_merge($contacts, $socpeoples);
690 public function postContact(
$id, $contactid, $type, $source =
"external", $notrigger = 0)
692 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
693 throw new RestException(403);
697 if (empty($source)) {
698 throw new RestException(400,
'Source can not be empty');
700 $sql_distinct_source =
"SELECT DISTINCT source";
701 $sql_distinct_source .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact";
702 $sql_distinct_source .=
" WHERE element LIKE 'commande'";
703 $sql_distinct_source .=
" AND source is NOT NULL";
704 $sql_distinct_source .=
" AND active != 0";
705 $source_result = $this->db->query($sql_distinct_source);
706 $source_array = array();
708 if ($source_result) {
709 $num = $this->db->num_rows($source_result);
712 $obj = $this->db->fetch_object($source_result);
713 $source_kind = (
string) $obj->source;
714 array_push($source_array, $source_kind);
719 throw new RestException(503,
'Error when retrieving a list of order contact sources: '.$this->db->lasterror());
721 if (!in_array($source, (array) $source_array,
true)) {
722 throw new RestException(400,
'Combo of Source='.$source.
' and Type='.$type.
' not found in dictionary with active order contact types');
727 throw new RestException(400,
'type can not be empty');
730 $sql_distinct_type =
"SELECT DISTINCT code";
731 $sql_distinct_type .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact";
732 $sql_distinct_type .=
" WHERE element LIKE 'commande'";
733 $sql_distinct_type .=
" AND source='".$this->db->escape($source).
"'";
734 $sql_distinct_type .=
" AND code is NOT NULL";
735 $sql_distinct_type .=
" AND active != 0";
736 $type_result = $this->db->query($sql_distinct_type);
737 $type_array = array();
740 $num = $this->db->num_rows($type_result);
743 $obj = $this->db->fetch_object($type_result);
745 $type_kind = (
string) $obj->code;
746 array_push($type_array, $type_kind);
751 throw new RestException(503,
'Error when retrieving a list of order contact types: '.$this->db->lasterror());
753 if (!in_array($type, (array) $type_array,
true)) {
754 throw new RestException(400,
'Combo of Type='.$type.
' and Source='.$source.
' not found in dictionary with active order contact types');
758 $result = $this->commande->fetch(
$id);
760 throw new RestException(404,
'Order not found');
763 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
766 $result = $this->commande->add_contact($contactid, $type, $source, $notrigger);
769 throw new RestException(400,
'Already exists: Contact='.$contactid.
' is already linked to the order='.
$id.
' as source='.$source.
' and type='.$type);
770 } elseif ($result == -1) {
771 throw new RestException(400,
'Wrong contact='.$contactid);
772 } elseif ($result == -2) {
773 throw new RestException(400,
'Wrong type='.$type);
774 } elseif ($result == -3) {
775 throw new RestException(400,
'Not allowed contacts');
776 } elseif ($result == -4) {
777 throw new RestException(400,
'ErrorCommercialNotAllowedForThirdparty');
778 } elseif ($result == -5) {
779 throw new RestException(400,
'Trigger failed');
780 } elseif ($result == -6) {
781 throw new RestException(400,
'DB_ERROR_RECORD_ALREADY_EXISTS');
782 } elseif ($result == -7) {
783 throw new RestException(400,
'Some other error');
789 'message' =>
'Contact='.$contactid.
' linked to the order='.
$id.
' as '.$source.
' '.$type
814 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
815 throw new RestException(403);
818 $result = $this->commande->fetch(
$id);
820 throw new RestException(404,
'Order not found');
824 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
827 foreach (array(
'internal',
'external') as $source) {
828 $contacts = $this->commande->liste_contact(-1, $source);
829 foreach ($contacts as $contact) {
830 if ($contact[
'id'] == $contactid && $contact[
'code'] == $type) {
831 $result = $this->commande->delete_contact($contact[
'rowid']);
834 throw new RestException(500,
'Error when deleting the contact '.$contact[
'rowid']);
843 'message' =>
'Contact unlinked from order'
858 public function put(
$id, $request_data =
null)
860 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
861 throw new RestException(403);
864 throw new RestException(400,
'No order with id=0 can exist');
866 $result = $this->commande->fetch(
$id);
868 throw new RestException(404,
'Order not found');
872 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
874 foreach ($request_data as $field => $value) {
875 if ($field ==
'id') {
878 if ($field ===
'caller') {
880 $this->commande->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
883 if ($field ==
'array_options' && is_array($value)) {
884 foreach ($value as $index => $val) {
890 $this->commande->$field = $this->
_checkValForAPI($field, $value, $this->commande);
894 if (!empty($this->commande->availability_id)) {
895 if ($this->commande->availability($this->commande->availability_id) < 0) {
896 throw new RestException(400,
'Error while updating availability');
900 if ($this->commande->update(DolibarrApiAccess::$user) > 0) {
901 return $this->
get(
$id);
903 throw new RestException(500, $this->commande->error);
916 public function delete(
$id)
918 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'supprimer')) {
919 throw new RestException(403);
922 throw new RestException(400,
'No order with id=0 can exist');
924 $result = $this->commande->fetch(
$id);
926 throw new RestException(404,
'Order not found');
930 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
933 if ($this->commande->delete(DolibarrApiAccess::$user) <= 0) {
934 throw new RestException(500,
'Error when deleting order : '.$this->commande->error);
940 'message' =>
'Order deleted'
969 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
970 throw new RestException(403);
972 $result = $this->commande->fetch(
$id);
974 throw new RestException(404,
'Order not found');
977 $result = $this->commande->fetch_thirdparty();
980 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
983 $result = $this->commande->valid(DolibarrApiAccess::$user, $idwarehouse, $notrigger);
985 throw new RestException(304,
'Error nothing done. May be object is already validated');
988 throw new RestException(500,
'Error when validating Order: '.$this->commande->error);
990 $result = $this->commande->fetch(
$id);
992 $this->commande->fetchObjectLinked();
995 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
996 $this->commande->online_payment_url = getOnlinePaymentUrl(0,
'order', (
string) $this->commande->ref);
1021 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
1022 throw new RestException(403);
1025 throw new RestException(400,
'Order ID is mandatory');
1027 $result = $this->commande->fetch(
$id);
1029 throw new RestException(404,
'Order not found');
1033 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1036 $result = $this->commande->set_reopen(DolibarrApiAccess::$user);
1038 throw new RestException(405, $this->commande->error);
1039 } elseif ($result == 0) {
1040 throw new RestException(304);
1062 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
1063 throw new RestException(403);
1066 throw new RestException(400,
'Order ID is mandatory');
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->classifyBilled(DolibarrApiAccess::$user);
1079 throw new RestException(400, $this->commande->error);
1082 $this->commande->fetchObjectLinked();
1099 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
1100 throw new RestException(403);
1102 $result = $this->commande->fetch(
$id);
1104 throw new RestException(404,
'Order not found');
1108 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1111 $result = $this->commande->cloture(DolibarrApiAccess::$user, $notrigger);
1113 throw new RestException(304,
'Error nothing done. May be object is already closed');
1116 throw new RestException(500,
'Error when closing Order: '.$this->commande->error);
1119 $result = $this->commande->fetch(
$id);
1121 throw new RestException(404,
'Order not found');
1129 $this->commande->fetchObjectLinked();
1146 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
1147 throw new RestException(403);
1149 $result = $this->commande->fetch(
$id);
1151 throw new RestException(404,
'Order not found');
1155 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1158 $result = $this->commande->setDraft(DolibarrApiAccess::$user, $idwarehouse);
1160 throw new RestException(304,
'Nothing done. May be object is already closed');
1163 throw new RestException(500,
'Error when closing Order: '.$this->commande->error);
1166 $result = $this->commande->fetch(
$id);
1168 throw new RestException(404,
'Order not found');
1176 $this->commande->fetchObjectLinked();
1198 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
1200 if (!DolibarrApiAccess::$user->hasRight(
'propal',
'lire')) {
1201 throw new RestException(403);
1203 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'creer')) {
1204 throw new RestException(403);
1206 if (empty($proposalid)) {
1207 throw new RestException(400,
'Proposal ID is mandatory');
1210 $propal =
new Propal($this->db);
1211 $result = $propal->fetch($proposalid);
1213 throw new RestException(404,
'Proposal not found');
1217 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1220 $result = $this->commande->createFromProposal($propal, DolibarrApiAccess::$user);
1222 throw new RestException(405, $this->commande->error);
1224 $this->commande->fetchObjectLinked();
1247 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1248 if (!DolibarrApiAccess::$user->hasRight(
'expedition',
'lire')) {
1249 throw new RestException(403);
1252 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1255 $sql =
"SELECT e.rowid";
1256 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expedition as e";
1257 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"expeditiondet as edet";
1258 $sql .=
" ON e.rowid = edet.fk_expedition";
1259 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"commandedet as cdet";
1260 $sql .=
" ON edet.fk_elementdet = cdet.rowid";
1261 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"commande as c";
1262 $sql .=
" ON cdet.fk_commande = c.rowid";
1263 $sql .=
" WHERE c.rowid = ".((int)
$id);
1264 $sql .=
" GROUP BY e.rowid";
1265 $sql .= $this->db->order(
"e.rowid",
"ASC");
1268 $result = $this->db->query($sql);
1272 $num = $this->db->num_rows($result);
1274 throw new RestException(404,
'Shipments not found ');
1279 $obj = $this->db->fetch_object($result);
1280 $shipment_static =
new Expedition($this->db);
1281 if ($shipment_static->fetch($obj->rowid)) {
1287 throw new RestException(500,
'Error when retrieve shipment list : '.$this->db->lasterror());
1309 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1310 if (!DolibarrApiAccess::$user->hasRight(
'expedition',
'creer')) {
1311 throw new RestException(403);
1313 if ($warehouse_id <= 0) {
1314 throw new RestException(404,
'Warehouse not found');
1316 $result = $this->commande->fetch(
$id);
1318 throw new RestException(404,
'Order not found');
1321 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1324 $shipment->socid = $this->commande->socid;
1325 $shipment->origin_id = $this->commande->id;
1326 $shipment->origin = $this->commande->element;
1327 $result = $shipment->create(DolibarrApiAccess::$user);
1329 throw new RestException(500,
'Error on creating expedition :'.$this->db->lasterror());
1331 foreach ($this->commande->lines as $line) {
1332 $result = $shipment->create_line($warehouse_id, $line->id, $line->qty);
1334 throw new RestException(500,
'Error on creating expedition lines:'.$this->db->lasterror());
1337 return $shipment->id;
1358 unset(
$object->barcode_type_code);
1359 unset(
$object->barcode_type_label);
1360 unset(
$object->barcode_type_coder);
1374 if ($data ===
null) {
1377 $commande = array();
1378 foreach (Orders::$FIELDS as $field) {
1379 if (!isset($data[$field])) {
1380 throw new RestException(400, $field.
" field missing");
1382 $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.
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
buildzip.php