97 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'')
103 if (!DolibarrApiAccess::$user->rights->stock->lire) {
104 throw new RestException(401);
107 $sql =
"SELECT t.rowid";
108 $sql .=
" FROM ".MAIN_DB_PREFIX.
"stock_mouvement AS t LEFT JOIN ".MAIN_DB_PREFIX.
"stock_mouvement_extrafields AS ef ON (ef.fk_object = t.rowid)";
111 $sql .=
' WHERE 1 = 1';
117 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
121 $sql .= $this->db->order($sortfield, $sortorder);
126 $offset = $limit * $page;
128 $sql .= $this->db->plimit($limit + 1, $offset);
131 $result = $this->db->query($sql);
134 $num = $this->db->num_rows($result);
135 $min = min($num, ($limit <= 0 ? $num : $limit));
137 $obj = $this->db->fetch_object($result);
139 if ($stockmovement_static->fetch($obj->rowid)) {
145 throw new RestException(503,
'Error when retrieve stock movement list : '.$this->db->lasterror());
176 public function post($product_id, $warehouse_id, $qty, $type = 2, $lot =
'', $movementcode =
'', $movementlabel =
'', $price =
'', $datem =
'', $dlc =
'', $dluo =
'', $origin_type =
'', $origin_id = 0)
178 if (!DolibarrApiAccess::$user->rights->stock->creer) {
179 throw new RestException(401);
183 throw new RestException(503,
"Making a stock movement with a quantity of 0 is not possible");
187 if ($type == 1 && $qty >= 0) {
190 if ($type == 2 && $qty >= 0) {
194 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
199 $this->stockmovement->setOrigin($origin_type, $origin_id);
200 if ($this->stockmovement->_create(DolibarrApiAccess::$user, $product_id, $warehouse_id, $qty, $type, $price, $movementlabel, $movementcode, $dateMvt, $eatBy, $sellBy, $lot) <= 0) {
201 $errormessage = $this->stockmovement->error;
202 if (empty($errormessage)) {
203 $errormessage = join(
',', $this->stockmovement->errors);
205 throw new RestException(503,
'Error when create stock movement : '.$errormessage);
208 return $this->stockmovement->id;
290 $object = parent::_cleanObjectDatas($object);
293 unset($object->civility_id);
294 unset($object->firstname);
295 unset($object->lastname);
296 unset($object->name);
297 unset($object->location_incoterms);
298 unset($object->label_incoterms);
299 unset($object->fk_incoterms);
300 unset($object->lines);
301 unset($object->total_ht);
302 unset($object->total_ttc);
303 unset($object->total_tva);
304 unset($object->total_localtax1);
305 unset($object->total_localtax2);
306 unset($object->note);
307 unset($object->note_private);
308 unset($object->note_public);
309 unset($object->shipping_method_id);
310 unset($object->fk_account);
311 unset($object->model_pdf);
312 unset($object->fk_delivery_address);
313 unset($object->cond_reglement);
314 unset($object->cond_reglement_id);
315 unset($object->mode_reglement_id);
316 unset($object->barcode_type_coder);
317 unset($object->barcode_type_label);
318 unset($object->barcode_type_code);
319 unset($object->barcode_type);
320 unset($object->country_code);
321 unset($object->country_id);
322 unset($object->country);
323 unset($object->thirdparty);
324 unset($object->contact);
325 unset($object->contact_id);
326 unset($object->user);
327 unset($object->fk_project);
328 unset($object->project);
329 unset($object->canvas);