19 use Luracast\Restler\RestException;
21 require_once DOL_DOCUMENT_ROOT.
'/reception/class/reception.class.php';
34 public static $FIELDS = array(
52 $this->reception =
new Reception($this->db);
64 public function get($id)
66 if (!DolibarrApiAccess::$user->rights->reception->lire) {
67 throw new RestException(401);
70 $result = $this->reception->fetch($id);
72 throw new RestException(404,
'Reception not found');
76 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
79 $this->reception->fetchObjectLinked();
101 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $thirdparty_ids =
'', $sqlfilters =
'', $properties =
'')
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());
191 public function post($request_data =
null)
193 if (!DolibarrApiAccess::$user->rights->reception->creer) {
194 throw new RestException(401,
"Insuffisant rights");
197 $result = $this->
_validate($request_data);
199 foreach ($request_data as $field => $value) {
200 if ($field ===
'caller') {
202 $this->reception->context[
'caller'] = $request_data[
'caller'];
206 $this->reception->$field = $value;
208 if (isset($request_data[
"lines"])) {
210 foreach ($request_data[
"lines"] as $line) {
211 array_push($lines, (
object) $line);
213 $this->reception->lines = $lines;
216 if ($this->reception->create(DolibarrApiAccess::$user) < 0) {
217 throw new RestException(500,
"Error creating reception", array_merge(array($this->reception->error), $this->reception->errors));
220 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 throw new RestException(405, $this->reception->error);
425 'message' =>
'Line deleted'
437 public function put($id, $request_data =
null)
439 if (!DolibarrApiAccess::$user->rights->reception->creer) {
440 throw new RestException(401);
443 $result = $this->reception->fetch($id);
445 throw new RestException(404,
'Reception not found');
449 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
451 foreach ($request_data as $field => $value) {
452 if ($field ==
'id') {
455 if ($field ===
'caller') {
457 $this->reception->context[
'caller'] = $request_data[
'caller'];
461 $this->reception->$field = $value;
464 if ($this->reception->update(DolibarrApiAccess::$user) > 0) {
465 return $this->
get($id);
467 throw new RestException(500, $this->reception->error);
477 public function delete($id)
479 if (!DolibarrApiAccess::$user->rights->reception->supprimer) {
480 throw new RestException(401);
482 $result = $this->reception->fetch($id);
484 throw new RestException(404,
'Reception not found');
488 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
491 if (!$this->reception->delete(DolibarrApiAccess::$user)) {
492 throw new RestException(500,
'Error when deleting reception : '.$this->reception->error);
498 'message' =>
'Reception deleted'
524 if (!DolibarrApiAccess::$user->rights->reception->creer) {
525 throw new RestException(401);
527 $result = $this->reception->fetch($id);
529 throw new RestException(404,
'Reception not found');
533 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
536 $result = $this->reception->valid(DolibarrApiAccess::$user, $notrigger);
538 throw new RestException(304,
'Error nothing done. May be object is already validated');
541 throw new RestException(500,
'Error when validating Reception: '.$this->reception->error);
545 $result = $this->reception->fetch($id);
547 $this->reception->fetchObjectLinked();
644 public function close($id, $notrigger = 0)
646 if (!DolibarrApiAccess::$user->rights->reception->creer) {
647 throw new RestException(401);
650 $result = $this->reception->fetch($id);
652 throw new RestException(404,
'Reception not found');
656 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
659 $result = $this->reception->setClosed();
661 throw new RestException(304,
'Error nothing done. May be object is already closed');
664 throw new RestException(500,
'Error when closing Reception: '.$this->reception->error);
668 $result = $this->reception->fetch($id);
670 $this->reception->fetchObjectLinked();
685 $object = parent::_cleanObjectDatas($object);
687 unset($object->thirdparty);
689 unset($object->note);
690 unset($object->address);
691 unset($object->barcode_type);
692 unset($object->barcode_type_code);
693 unset($object->barcode_type_label);
694 unset($object->barcode_type_coder);
696 if (!empty($object->lines) && is_array($object->lines)) {
697 foreach ($object->lines as $line) {
698 unset($line->tva_tx);
699 unset($line->vat_src_code);
700 unset($line->total_ht);
701 unset($line->total_ttc);
702 unset($line->total_tva);
703 unset($line->total_localtax1);
704 unset($line->total_localtax2);
705 unset($line->remise_percent);
721 $reception = array();
722 foreach (Receptions::$FIELDS as $field) {
723 if (!isset($data[$field])) {
724 throw new RestException(400,
"$field field missing");
726 $reception[$field] = $data[$field];
_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.
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.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $thirdparty_ids='', $sqlfilters='', $properties='')
List receptions.
put($id, $request_data=null)
Update reception general fields (won't touch lines of reception)
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.