96 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'')
102 if (!DolibarrApiAccess::$user->rights->stock->lire) {
103 throw new RestException(401);
106 $sql =
"SELECT t.rowid";
107 $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)";
110 $sql .=
' WHERE 1 = 1';
116 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
120 $sql .= $this->db->order($sortfield, $sortorder);
125 $offset = $limit * $page;
127 $sql .= $this->db->plimit($limit + 1, $offset);
130 $result = $this->db->query($sql);
133 $num = $this->db->num_rows($result);
134 $min = min($num, ($limit <= 0 ? $num : $limit));
136 $obj = $this->db->fetch_object($result);
138 if ($stockmovement_static->fetch($obj->rowid)) {
144 throw new RestException(503,
'Error when retrieve stock movement list : '.$this->db->lasterror());
146 if (!count($obj_ret)) {
147 throw new RestException(404,
'No stock movement found');
177 public function post($product_id, $warehouse_id, $qty, $type = 2, $lot =
'', $movementcode =
'', $movementlabel =
'', $price =
'', $datem =
'', $dlc =
'', $dluo =
'', $origin_type =
'', $origin_id = 0)
179 if (!DolibarrApiAccess::$user->rights->stock->creer) {
180 throw new RestException(401);
184 throw new RestException(503,
"Making a stock movement with a quantity of 0 is not possible");
188 if ($type == 1 && $qty >= 0) {
191 if ($type == 2 && $qty >= 0) {
195 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
200 $this->stockmovement->setOrigin($origin_type, $origin_id);
201 if ($this->stockmovement->_create(DolibarrApiAccess::$user, $product_id, $warehouse_id, $qty, $type, $price, $movementlabel, $movementcode, $dateMvt, $eatBy, $sellBy, $lot) <= 0) {
202 $errormessage = $this->stockmovement->error;
203 if (empty($errormessage)) {
204 $errormessage = join(
',', $this->stockmovement->errors);
206 throw new RestException(503,
'Error when create stock movement : '.$errormessage);
209 return $this->stockmovement->id;
291 $object = parent::_cleanObjectDatas($object);
294 unset($object->civility_id);
295 unset($object->firstname);
296 unset($object->lastname);
297 unset($object->name);
298 unset($object->location_incoterms);
299 unset($object->label_incoterms);
300 unset($object->fk_incoterms);
301 unset($object->lines);
302 unset($object->total_ht);
303 unset($object->total_ttc);
304 unset($object->total_tva);
305 unset($object->total_localtax1);
306 unset($object->total_localtax2);
307 unset($object->note);
308 unset($object->note_private);
309 unset($object->note_public);
310 unset($object->shipping_method_id);
311 unset($object->fk_account);
312 unset($object->model_pdf);
313 unset($object->fk_delivery_address);
314 unset($object->cond_reglement);
315 unset($object->cond_reglement_id);
316 unset($object->mode_reglement_id);
317 unset($object->barcode_type_coder);
318 unset($object->barcode_type_label);
319 unset($object->barcode_type_code);
320 unset($object->barcode_type);
321 unset($object->country_code);
322 unset($object->country_id);
323 unset($object->country);
324 unset($object->thirdparty);
325 unset($object->contact);
326 unset($object->contact_id);
327 unset($object->user);
328 unset($object->fk_project);
329 unset($object->project);
330 unset($object->canvas);