19 use Luracast\Restler\RestException;
21 require_once DOL_DOCUMENT_ROOT.
'/reception/class/reception.class.php';
35 public static $FIELDS = array(
53 $this->reception =
new Reception($this->db);
65 public function get($id)
67 if (!DolibarrApiAccess::$user->rights->reception->lire) {
68 throw new RestException(401);
71 $result = $this->reception->fetch($id);
73 throw new RestException(404,
'Reception not found');
77 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
80 $this->reception->fetchObjectLinked();
101 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $thirdparty_ids =
'', $sqlfilters =
'')
105 if (!DolibarrApiAccess::$user->rights->reception->lire) {
106 throw new RestException(401);
112 $socids = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $thirdparty_ids;
116 if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) {
117 $search_sale = DolibarrApiAccess::$user->id;
120 $sql =
"SELECT t.rowid";
121 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
122 $sql .=
", sc.fk_soc, sc.fk_user";
124 $sql .=
" FROM ".MAIN_DB_PREFIX.
"reception AS t LEFT JOIN ".MAIN_DB_PREFIX.
"reception_extrafields AS ef ON (ef.fk_object = t.rowid)";
126 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
127 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
130 $sql .=
' WHERE t.entity IN ('.getEntity(
'reception').
')';
131 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
132 $sql .=
" AND t.fk_soc = sc.fk_soc";
135 $sql .=
" AND t.fk_soc IN (".$this->db->sanitize($socids).
")";
137 if ($search_sale > 0) {
138 $sql .=
" AND t.rowid = sc.fk_soc";
141 if ($search_sale > 0) {
142 $sql .=
" AND sc.fk_user = ".((int) $search_sale);
149 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
153 $sql .= $this->db->order($sortfield, $sortorder);
158 $offset = $limit * $page;
160 $sql .= $this->db->plimit($limit + 1, $offset);
164 $result = $this->db->query($sql);
167 $num = $this->db->num_rows($result);
168 $min = min($num, ($limit <= 0 ? $num : $limit));
171 $obj = $this->db->fetch_object($result);
172 $reception_static =
new Reception($this->db);
173 if ($reception_static->fetch($obj->rowid)) {
179 throw new RestException(503,
'Error when retrieve commande list : '.$this->db->lasterror());
181 if (!count($obj_ret)) {
182 throw new RestException(404,
'No reception found');
193 public function post($request_data =
null)
195 if (!DolibarrApiAccess::$user->rights->reception->creer) {
196 throw new RestException(401,
"Insuffisant rights");
199 $result = $this->
_validate($request_data);
201 foreach ($request_data as $field => $value) {
202 $this->reception->$field = $value;
204 if (isset($request_data[
"lines"])) {
206 foreach ($request_data[
"lines"] as $line) {
207 array_push($lines, (
object) $line);
209 $this->reception->lines = $lines;
212 if ($this->reception->create(DolibarrApiAccess::$user) < 0) {
213 throw new RestException(500,
"Error creating reception", array_merge(array($this->reception->error), $this->reception->errors));
216 return $this->reception->id;
398 if (!DolibarrApiAccess::$user->rights->reception->creer) {
399 throw new RestException(401);
402 $result = $this->reception->fetch($id);
404 throw new RestException(404,
'Reception not found');
408 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
413 $updateRes = $this->reception->deleteline(DolibarrApiAccess::$user, $lineid);
414 if ($updateRes < 0) {
415 throw new RestException(405, $this->reception->error);
421 'message' =>
'Line deleted'
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);
467 public function delete($id)
469 if (!DolibarrApiAccess::$user->rights->reception->supprimer) {
470 throw new RestException(401);
472 $result = $this->reception->fetch($id);
474 throw new RestException(404,
'Reception not found');
478 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
481 if (!$this->reception->delete(DolibarrApiAccess::$user)) {
482 throw new RestException(500,
'Error when deleting reception : '.$this->reception->error);
488 'message' =>
'Reception deleted'
514 if (!DolibarrApiAccess::$user->rights->reception->creer) {
515 throw new RestException(401);
517 $result = $this->reception->fetch($id);
519 throw new RestException(404,
'Reception not found');
523 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
526 $result = $this->reception->valid(DolibarrApiAccess::$user, $notrigger);
528 throw new RestException(304,
'Error nothing done. May be object is already validated');
531 throw new RestException(500,
'Error when validating Reception: '.$this->reception->error);
535 $result = $this->reception->fetch($id);
537 $this->reception->fetchObjectLinked();
634 public function close($id, $notrigger = 0)
636 if (!DolibarrApiAccess::$user->rights->reception->creer) {
637 throw new RestException(401);
640 $result = $this->reception->fetch($id);
642 throw new RestException(404,
'Reception not found');
646 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
649 $result = $this->reception->setClosed();
651 throw new RestException(304,
'Error nothing done. May be object is already closed');
654 throw new RestException(500,
'Error when closing Order: '.$this->commande->error);
658 $result = $this->reception->fetch($id);
660 $this->reception->fetchObjectLinked();
675 $object = parent::_cleanObjectDatas($object);
677 unset($object->thirdparty);
679 unset($object->note);
680 unset($object->address);
681 unset($object->barcode_type);
682 unset($object->barcode_type_code);
683 unset($object->barcode_type_label);
684 unset($object->barcode_type_coder);
686 if (!empty($object->lines) && is_array($object->lines)) {
687 foreach ($object->lines as $line) {
688 unset($line->tva_tx);
689 unset($line->vat_src_code);
690 unset($line->total_ht);
691 unset($line->total_ttc);
692 unset($line->total_tva);
693 unset($line->total_localtax1);
694 unset($line->total_localtax2);
695 unset($line->remise_percent);
711 $reception = array();
712 foreach (Receptions::$FIELDS as $field) {
713 if (!isset($data[$field])) {
714 throw new RestException(400,
"$field field missing");
716 $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.
Class to manage receptions.
close($id, $notrigger=0)
Classify the reception as invoiced.
validate($id, $notrigger=0)
Validate a reception.
post($request_data=null)
Create reception object.
deleteLine($id, $lineid)
Get lines of an 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.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.