18 use Luracast\Restler\RestException;
20 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
34 static $FIELDS = array(
43 public $stockmovement;
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";
109 $sql .=
' WHERE 1 = 1';
115 throw new RestException(503,
'Error when validating parameter sqlfilters '.$sqlfilters);
117 $regexstring =
'\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
118 $sql .=
" AND (".preg_replace_callback(
'/'.$regexstring.
'/',
'DolibarrApi::_forge_criteria_callback', $sqlfilters).
")";
121 $sql .= $this->
db->order($sortfield, $sortorder);
127 $offset = $limit * $page;
129 $sql .= $this->
db->plimit($limit + 1, $offset);
132 $result = $this->
db->query($sql);
136 $num = $this->
db->num_rows($result);
137 $min = min($num, ($limit <= 0 ? $num : $limit));
140 $obj = $this->
db->fetch_object($result);
142 if ($stockmovement_static->fetch($obj->rowid)) {
148 throw new RestException(503,
'Error when retrieve stock movement list : '.$this->
db->lasterror());
150 if (!count($obj_ret)) {
151 throw new RestException(404,
'No stock movement found');
177 public function post($product_id, $warehouse_id, $qty, $lot =
'', $movementcode =
'', $movementlabel =
'', $price =
'', $dlc =
'', $dluo =
'')
179 if (!DolibarrApiAccess::$user->rights->stock->creer) {
180 throw new RestException(401);
184 throw new RestException(503,
"Making a stock movement with a quentity of 0 is not possible");
193 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
197 if ($this->stockmovement->_create(DolibarrApiAccess::$user, $product_id, $warehouse_id, $qty, $type, $price, $movementlabel, $movementcode,
'', $eatBy, $sellBy, $lot) <= 0) {
198 $errormessage = $this->stockmovement->error;
199 if (empty($errormessage)) $errormessage = join(
',', $this->stockmovement->errors);
200 throw new RestException(503,
'Error when create stock movement : '.$errormessage);
203 return $this->stockmovement->id;
285 $object = parent::_cleanObjectDatas($object);
288 unset($object->civility_id);
289 unset($object->firstname);
290 unset($object->lastname);
291 unset($object->name);
292 unset($object->location_incoterms);
293 unset($object->label_incoterms);
294 unset($object->fk_incoterms);
295 unset($object->lines);
296 unset($object->total_ht);
297 unset($object->total_ttc);
298 unset($object->total_tva);
299 unset($object->total_localtax1);
300 unset($object->total_localtax2);
301 unset($object->note);
302 unset($object->note_private);
303 unset($object->note_public);
304 unset($object->shipping_method_id);
305 unset($object->fk_account);
306 unset($object->model_pdf);
307 unset($object->fk_delivery_address);
308 unset($object->cond_reglement);
309 unset($object->cond_reglement_id);
310 unset($object->mode_reglement_id);
311 unset($object->barcode_type_coder);
312 unset($object->barcode_type_label);
313 unset($object->barcode_type_code);
314 unset($object->barcode_type);
315 unset($object->country_code);
316 unset($object->country_id);
317 unset($object->country);
318 unset($object->thirdparty);
319 unset($object->contact);
320 unset($object->contact_id);
321 unset($object->user);
322 unset($object->fk_project);
323 unset($object->project);
324 unset($object->canvas);
342 $stockmovement = array();
343 foreach (self::$FIELDS as $field) {
344 if (!isset($data[$field]))
345 throw new RestException(400,
"$field field missing");
346 $stockmovement[$field] = $data[$field];
348 return $stockmovement;
Class to manage stock movements.
index($sortfield="t.rowid", $sortorder= 'ASC', $limit=100, $page=0, $sqlfilters= '')
Get properties of a stock movement object.
_cleanObjectDatas($object)
Update stock movement.
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
$conf db
API class for accounts.
_checkFilters($sqlfilters)
Return if a $sqlfilters parameter is valid.
__construct()
Constructor.
_validate($data)
Validate fields before create or update object.