18use Luracast\Restler\RestException;
20require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
34 public static $FIELDS = array(
43 public $stockmovement;
97 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'')
103 if (!DolibarrApiAccess::$user->hasRight(
'stock',
'lire')) {
104 throw new RestException(403);
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->hasRight(
'stock',
'creer')) {
179 throw new RestException(403);
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 = implode(
',', $this->stockmovement->errors);
205 throw new RestException(503,
'Error when create stock movement : '.$errormessage);
208 return $this->stockmovement->id;
297 unset(
$object->location_incoterms);
298 unset(
$object->label_incoterms);
304 unset(
$object->total_localtax1);
305 unset(
$object->total_localtax2);
309 unset(
$object->shipping_method_id);
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);
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;
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
_filterObjectProperties($object, $properties)
Filter properties that will be returned on object.
Class to manage stock movements.
_validate($data)
Validate fields before create or update object.
_cleanObjectDatas($object)
Update stock movement.
post($product_id, $warehouse_id, $qty, $type=2, $lot='', $movementcode='', $movementlabel='', $price='', $datem='', $dlc='', $dluo='', $origin_type='', $origin_id=0)
Create stock movement object.
__construct()
Constructor.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $sqlfilters='', $properties='')
Get properties of a stock movement object.
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, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria