19 use Luracast\Restler\RestException;
21 require_once DOL_DOCUMENT_ROOT.
'/reception/class/reception.class.php';
35 public static $FIELDS = array(
66 public function get($id)
68 if (!DolibarrApiAccess::$user->rights->reception->lire) {
69 throw new RestException(401);
72 $result = $this->reception->fetch($id);
74 throw new RestException(404,
'Reception not found');
78 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
81 $this->reception->fetchObjectLinked();
102 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $thirdparty_ids =
'', $sqlfilters =
'')
106 if (!DolibarrApiAccess::$user->rights->reception->lire) {
107 throw new RestException(401);
113 $socids = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $thirdparty_ids;
117 if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) {
118 $search_sale = DolibarrApiAccess::$user->id;
121 $sql =
"SELECT t.rowid";
122 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
123 $sql .=
", sc.fk_soc, sc.fk_user";
125 $sql .=
" FROM ".MAIN_DB_PREFIX.
"reception as t";
127 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
128 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
131 $sql .=
' WHERE t.entity IN ('.getEntity(
'reception').
')';
132 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
133 $sql .=
" AND t.fk_soc = sc.fk_soc";
136 $sql .=
" AND t.fk_soc IN (".$this->db->sanitize($socids).
")";
138 if ($search_sale > 0) {
139 $sql .=
" AND t.rowid = sc.fk_soc";
142 if ($search_sale > 0) {
143 $sql .=
" AND sc.fk_user = ".((int) $search_sale);
149 throw new RestException(503,
'Error when validating parameter sqlfilters -> '.$errormessage);
151 $regexstring =
'\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
152 $sql .=
" AND (".preg_replace_callback(
'/'.$regexstring.
'/',
'DolibarrApi::_forge_criteria_callback', $sqlfilters).
")";
155 $sql .= $this->
db->order($sortfield, $sortorder);
160 $offset = $limit * $page;
162 $sql .= $this->
db->plimit($limit + 1, $offset);
166 $result = $this->
db->query($sql);
169 $num = $this->
db->num_rows($result);
170 $min = min($num, ($limit <= 0 ? $num : $limit));
173 $obj = $this->
db->fetch_object($result);
175 if ($reception_static->fetch($obj->rowid)) {
181 throw new RestException(503,
'Error when retrieve commande list : '.$this->
db->lasterror());
183 if (!count($obj_ret)) {
184 throw new RestException(404,
'No reception found');
195 public function post($request_data =
null)
197 if (!DolibarrApiAccess::$user->rights->reception->creer) {
198 throw new RestException(401,
"Insuffisant rights");
201 $result = $this->
_validate($request_data);
203 foreach ($request_data as $field => $value) {
204 $this->reception->$field = $value;
206 if (isset($request_data[
"lines"])) {
208 foreach ($request_data[
"lines"] as $line) {
209 array_push($lines, (
object) $line);
211 $this->reception->lines = $lines;
214 if ($this->reception->create(DolibarrApiAccess::$user) < 0) {
215 throw new RestException(500,
"Error creating reception", array_merge(array($this->reception->error), $this->reception->errors));
218 return $this->reception->id;
402 if (!DolibarrApiAccess::$user->rights->reception->creer) {
403 throw new RestException(401);
406 $result = $this->reception->fetch($id);
408 throw new RestException(404,
'Reception not found');
412 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
417 $updateRes = $this->reception->deleteline(DolibarrApiAccess::$user, $lineid);
418 if ($updateRes > 0) {
419 return $this->
get($id);
421 throw new RestException(405, $this->reception->error);
433 public function put($id, $request_data =
null)
435 if (!DolibarrApiAccess::$user->rights->reception->creer) {
436 throw new RestException(401);
439 $result = $this->reception->fetch($id);
441 throw new RestException(404,
'Reception not found');
445 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
447 foreach ($request_data as $field => $value) {
448 if ($field ==
'id') {
451 $this->reception->$field = $value;
454 if ($this->reception->update(DolibarrApiAccess::$user) > 0) {
455 return $this->
get($id);
457 throw new RestException(500, $this->reception->error);
468 public function delete($id)
470 if (!DolibarrApiAccess::$user->rights->reception->supprimer) {
471 throw new RestException(401);
473 $result = $this->reception->fetch($id);
475 throw new RestException(404,
'Reception not found');
479 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
482 if (!$this->reception->delete(DolibarrApiAccess::$user)) {
483 throw new RestException(500,
'Error when deleting reception : '.$this->reception->error);
489 'message' =>
'Reception deleted'
515 if (!DolibarrApiAccess::$user->rights->reception->creer) {
516 throw new RestException(401);
518 $result = $this->reception->fetch($id);
520 throw new RestException(404,
'Reception not found');
524 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
527 $result = $this->reception->valid(DolibarrApiAccess::$user, $notrigger);
529 throw new RestException(304,
'Error nothing done. May be object is already validated');
532 throw new RestException(500,
'Error when validating Reception: '.$this->reception->error);
536 $result = $this->reception->fetch($id);
538 $this->reception->fetchObjectLinked();
635 public function close($id, $notrigger = 0)
637 if (!DolibarrApiAccess::$user->rights->reception->creer) {
638 throw new RestException(401);
641 $result = $this->reception->fetch($id);
643 throw new RestException(404,
'Reception not found');
647 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
650 $result = $this->reception->setClosed();
652 throw new RestException(304,
'Error nothing done. May be object is already closed');
655 throw new RestException(500,
'Error when closing Order: '.$this->commande->error);
659 $result = $this->reception->fetch($id);
661 $this->reception->fetchObjectLinked();
676 $object = parent::_cleanObjectDatas($object);
678 unset($object->thirdparty);
680 unset($object->note);
681 unset($object->address);
682 unset($object->barcode_type);
683 unset($object->barcode_type_code);
684 unset($object->barcode_type_label);
685 unset($object->barcode_type_coder);
687 if (!empty($object->lines) && is_array($object->lines)) {
688 foreach ($object->lines as $line) {
689 unset($line->tva_tx);
690 unset($line->vat_src_code);
691 unset($line->total_ht);
692 unset($line->total_ttc);
693 unset($line->total_tva);
694 unset($line->total_localtax1);
695 unset($line->total_localtax2);
696 unset($line->remise_percent);
712 $reception = array();
713 foreach (Shipments::$FIELDS as $field) {
714 if (!isset($data[$field])) {
715 throw new RestException(400,
"$field field missing");
717 $reception[$field] = $data[$field];
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid')
Check access by user to a given resource.
_checkFilters($sqlfilters, &$error='')
Return if a $sqlfilters parameter is valid.
Class to manage receptions.
close($id, $notrigger=0)
Close a reception (Classify it as "Delivered")
validate($id, $notrigger=0)
Validate a reception.
post($request_data=null)
Create reception object.
deleteLine($id, $lineid)
Delete a line to given reception.
_cleanObjectDatas($object)
Clean sensible object datas.
__construct()
Constructor.
_validate($data)
Validate fields before create or update object.
put($id, $request_data=null)
Update reception general fields (won't touch lines of reception)
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $thirdparty_ids='', $sqlfilters='')
List receptions.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.