18 use Luracast\Restler\RestException;
20 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
34 public 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 ".$this->db->prefix().
"stock_mouvement as t";
109 $sql .=
' WHERE 1 = 1';
115 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
119 $sql .= $this->
db->order($sortfield, $sortorder);
124 $offset = $limit * $page;
126 $sql .= $this->
db->plimit($limit + 1, $offset);
129 $result = $this->
db->query($sql);
132 $num = $this->
db->num_rows($result);
133 $min = min($num, ($limit <= 0 ? $num : $limit));
135 $obj = $this->
db->fetch_object($result);
137 if ($stockmovement_static->fetch($obj->rowid)) {
143 throw new RestException(503,
'Error when retrieve stock movement list : '.$this->
db->lasterror());
145 if (!count($obj_ret)) {
146 throw new RestException(404,
'No stock movement found');
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);
347 $stockmovement = array();
348 foreach (self::$FIELDS as $field) {
349 if (!isset($data[$field])) {
350 throw new RestException(400,
"$field field missing");
352 $stockmovement[$field] = $data[$field];
354 return $stockmovement;
Class to manage stock movements.
_validate($data)
Validate fields before create or update object.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $sqlfilters='')
Get properties of a stock movement object.
_cleanObjectDatas($object)
Update stock movement.
__construct()
Constructor.
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...
forgeSQLFromUniversalSearchCriteria($filter, &$error='')
forgeSQLFromUniversalSearchCriteria
$conf db
API class for accounts.