38 public $element =
'stockmouvement';
43 public $table_element =
'stock_mouvement';
81 public $fk_user_author;
111 public $line_id_oject_src;
112 public $line_id_oject_origin;
115 public $inventorycode;
118 public $line_id_object_src;
119 public $line_id_object_origin;
126 public $fields = array(
127 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10,
'showoncombobox' => 1),
128 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 15),
129 'datem' => array(
'type' =>
'datetime',
'label' =>
'Datem',
'enabled' => 1,
'visible' => -1,
'position' => 20),
130 'fk_product' => array(
'type' =>
'integer:Product:product/class/product.class.php:1',
'label' =>
'Product',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 25),
131 'fk_entrepot' => array(
'type' =>
'integer:Entrepot:product/stock/class/entrepot.class.php',
'label' =>
'Warehouse',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 30),
132 'value' => array(
'type' =>
'double',
'label' =>
'Value',
'enabled' => 1,
'visible' => -1,
'position' => 35),
133 'price' => array(
'type' =>
'double(24,8)',
'label' =>
'Price',
'enabled' => 1,
'visible' => -1,
'position' => 40),
134 'type_mouvement' => array(
'type' =>
'smallint(6)',
'label' =>
'Type mouvement',
'enabled' => 1,
'visible' => -1,
'position' => 45),
135 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'Fk user author',
'enabled' => 1,
'visible' => -1,
'position' => 50),
136 'label' => array(
'type' =>
'varchar(255)',
'label' =>
'Label',
'enabled' => 1,
'visible' => -1,
'position' => 55),
137 'fk_origin' => array(
'type' =>
'integer',
'label' =>
'Fk origin',
'enabled' => 1,
'visible' => -1,
'position' => 60),
138 'origintype' => array(
'type' =>
'varchar(32)',
'label' =>
'Origintype',
'enabled' => 1,
'visible' => -1,
'position' => 65),
139 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Model pdf',
'enabled' => 1,
'visible' => 0,
'position' => 70),
140 'fk_projet' => array(
'type' =>
'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)',
'label' =>
'Project',
'enabled' =>
'$conf->project->enabled',
'visible' => -1,
'notnull' => 1,
'position' => 75),
141 'inventorycode' => array(
'type' =>
'varchar(128)',
'label' =>
'InventoryCode',
'enabled' => 1,
'visible' => -1,
'position' => 80),
142 'batch' => array(
'type' =>
'varchar(30)',
'label' =>
'Batch',
'enabled' => 1,
'visible' => -1,
'position' => 85),
143 'eatby' => array(
'type' =>
'date',
'label' =>
'Eatby',
'enabled' => 1,
'visible' => -1,
'position' => 90),
144 'sellby' => array(
'type' =>
'date',
'label' =>
'Sellby',
'enabled' => 1,
'visible' => -1,
'position' => 95),
145 'fk_project' => array(
'type' =>
'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)',
'label' =>
'Fk project',
'enabled' => 1,
'visible' => -1,
'position' => 100),
188 public function _create($user, $fk_product, $entrepot_id, $qty, $type, $price = 0, $label =
'', $inventorycode =
'', $datem =
'', $eatby =
'', $sellby =
'', $batch =
'', $skip_batch =
false, $id_product_batch = 0, $disablestockchangeforsubproduct = 0, $donotcleanemptylines = 0, $force_update_batch =
false)
191 global $conf, $langs;
193 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
194 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/productlot.class.php';
197 dol_syslog(get_class($this).
"::_create start userid=$user->id, fk_product=$fk_product, warehouse_id=$entrepot_id, qty=$qty, type=$type, price=$price, label=$label, inventorycode=$inventorycode, datem=".$datem.
", eatby=".$eatby.
", sellby=".$sellby.
", batch=".$batch.
", skip_batch=".json_encode($skip_batch));
200 global $action, $hookmanager;
201 $hookmanager->initHooks(array(
'mouvementstock'));
203 if (is_object($hookmanager)) {
205 'currentcontext' =>
'mouvementstock',
207 'fk_product' => &$fk_product,
208 'entrepot_id' => &$entrepot_id,
213 'inventorycode' => &$inventorycode,
216 'sellby' => &$sellby,
218 'skip_batch' => &$skip_batch,
219 'id_product_batch' => &$id_product_batch
221 $reshook = $hookmanager->executeHooks(
'stockMovementCreate', $parameters, $this, $action);
224 if (!empty($hookmanager->resPrint)) {
228 } elseif ($reshook > 0) {
229 return $hookmanager->resPrint;
239 $now = (!empty($datem) ? $datem :
dol_now());
242 if (!($fk_product > 0)) {
245 if (!($entrepot_id > 0)) {
249 if (is_numeric($eatby) && $eatby < 0) {
250 dol_syslog(get_class($this).
"::_create start ErrorBadValueForParameterEatBy eatby = ".$eatby);
251 $this->errors[] =
'ErrorBadValueForParameterEatBy';
254 if (is_numeric($sellby) && $sellby < 0) {
255 dol_syslog(get_class($this).
"::_create start ErrorBadValueForParameterSellBy sellby = ".$sellby);
256 $this->errors[] =
'ErrorBadValueForParameterSellBy';
261 $this->product_id = $fk_product;
262 $this->entrepot_id = $entrepot_id;
263 $this->warehouse_id = $entrepot_id;
267 $this->label = $label;
268 $this->inventorycode = $inventorycode;
270 $this->batch = $batch;
274 $product =
new Product($this->db);
276 $result = $product->fetch($fk_product);
278 $this->error = $product->error;
279 $this->errors = $product->errors;
283 if ($product->id <= 0) {
298 $product->load_stock(
'novirtual');
302 if (
isModEnabled(
'productbatch') && $product->hasbatch() && !$skip_batch) {
304 $langs->load(
"errors");
305 $this->errors[] = $langs->transnoentitiesnoconv(
"ErrorTryToMakeMoveOnProductRequiringBatchData", $product->ref);
306 dol_syslog(
"Try to make a movement of a product with status_batch on without any batch data");
308 $this->db->rollback();
318 $sql =
"SELECT pb.rowid, pb.batch, pb.eatby, pb.sellby FROM ".$this->db->prefix().
"product_lot as pb";
319 $sql .=
" WHERE pb.fk_product = ".((int) $fk_product).
" AND pb.batch = '".$this->db->escape($batch).
"'";
321 dol_syslog(get_class($this).
"::_create scan serial for this product to check if eatby and sellby match", LOG_DEBUG);
323 $resql = $this->db->query(
$sql);
325 $num = $this->db->num_rows($resql);
329 $obj = $this->db->fetch_object($resql);
333 $eatbywithouthour =
dol_mktime(0, 0, 0, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year']);
334 if ($this->db->jdate($obj->eatby) != $eatby && $this->db->jdate($obj->eatby) != $eatbywithouthour) {
336 $langs->load(
"stocks");
337 $this->errors[] = $langs->transnoentitiesnoconv(
"ThisSerialAlreadyExistWithDifferentDate", $batch,
dol_print_date($this->db->jdate($obj->eatby),
'dayhour'),
dol_print_date($eatbywithouthour,
'dayhour'));
338 dol_syslog(
"ThisSerialAlreadyExistWithDifferentDate batch=".$batch.
", eatby found into product_lot = ".$obj->eatby.
" = ".
dol_print_date($this->db->jdate($obj->eatby),
'dayhourrfc').
" so eatbywithouthour = ".$eatbywithouthour.
" = ".
dol_print_date($eatbywithouthour).
" - eatby provided = ".$eatby.
" = ".
dol_print_date($eatby,
'dayhourrfc'), LOG_ERR);
339 $this->db->rollback();
343 $eatby = $obj->eatby;
348 $result = $productlot->fetch($obj->rowid);
349 $productlot->eatby = $eatby;
350 $result = $productlot->update($user);
352 $this->error = $productlot->error;
353 $this->errors = $productlot->errors;
354 $this->db->rollback();
362 $sellbywithouthour =
dol_mktime(0, 0, 0, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year']);
363 if ($this->db->jdate($obj->sellby) != $sellby && $this->db->jdate($obj->sellby) != $sellbywithouthour) {
365 $this->errors[] = $langs->transnoentitiesnoconv(
"ThisSerialAlreadyExistWithDifferentDate", $batch,
dol_print_date($this->db->jdate($obj->sellby)),
dol_print_date($sellby));
367 $this->db->rollback();
371 $sellby = $obj->sellby;
376 $result = $productlot->fetch($obj->rowid);
377 $productlot->sellby = $sellby;
378 $result = $productlot->update($user);
380 $this->error = $productlot->error;
381 $this->errors = $productlot->errors;
382 $this->db->rollback();
392 $productlot->origin = !empty($this->origin_type) ? $this->origin_type :
'';
393 $productlot->origin_id = !empty($this->origin_id) ? $this->origin_id : 0;
394 $productlot->entity = $conf->entity;
395 $productlot->fk_product = $fk_product;
396 $productlot->batch = $batch;
398 $productlot->eatby = $eatby;
399 $productlot->sellby = $sellby;
400 $result = $productlot->create($user);
402 $this->error = $productlot->error;
403 $this->errors = $productlot->errors;
404 $this->db->rollback();
410 $this->db->rollback();
417 if ($movestock && $qty < 0 && !
getDolGlobalInt(
'STOCK_ALLOW_NEGATIVE_TRANSFER')) {
418 if (
isModEnabled(
'productbatch') && $product->hasbatch() && !$skip_batch) {
422 foreach ($product->stock_warehouse[$entrepot_id]->detail_batch as $batchcursor => $prodbatch) {
423 if ((
string) $batch != (
string) $batchcursor) {
428 if ($prodbatch->qty < abs($qty)) {
429 $qtyisnotenough = $prodbatch->qty;
433 if (!$foundforbatch || $qtyisnotenough) {
434 $langs->load(
"stocks");
435 include_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
436 $tmpwarehouse =
new Entrepot($this->db);
437 $tmpwarehouse->fetch($entrepot_id);
439 $this->error = $langs->trans(
'qtyToTranferLotIsNotEnough', $product->ref, $batch, $qtyisnotenough, $tmpwarehouse->ref);
440 $this->errors[] = $langs->trans(
'qtyToTranferLotIsNotEnough', $product->ref, $batch, $qtyisnotenough, $tmpwarehouse->ref);
441 $this->db->rollback();
445 if (empty($product->stock_warehouse[$entrepot_id]->real) || $product->stock_warehouse[$entrepot_id]->real < abs($qty)) {
446 $langs->load(
"stocks");
447 $this->error = $langs->trans(
'qtyToTranferIsNotEnough').
' : '.$product->ref;
448 $this->errors[] = $langs->trans(
'qtyToTranferIsNotEnough').
' : '.$product->ref;
449 $this->db->rollback();
457 $fk_project = $this->fk_project;
458 if (!empty($this->origin_type)) {
459 $origin_type = $this->origin_type;
460 $origin_id = $this->origin_id;
461 if (empty($fk_project) && $origin_type ==
'project') {
462 $fk_project = $origin_id;
472 $sql =
"INSERT INTO ".$this->db->prefix().
"stock_mouvement(";
473 $sql .=
" datem, fk_product, batch, eatby, sellby,";
474 $sql .=
" fk_entrepot, value, type_mouvement, fk_user_author, label, inventorycode, price, fk_origin, origintype, fk_projet";
476 $sql .=
" VALUES ('".$this->db->idate($this->datem).
"', ".((int) $this->product_id).
", ";
477 $sql .=
" ".($batch ?
"'".$this->db->escape($batch).
"'" :
"null").
", ";
478 $sql .=
" ".($eatby ?
"'".$this->db->idate($eatby).
"'" :
"null").
", ";
479 $sql .=
" ".($sellby ?
"'".$this->db->idate($sellby).
"'" :
"null").
", ";
480 $sql .=
" ".((int) $this->entrepot_id).
", ".((
float) $this->qty).
", ".((int) $this->
type).
",";
481 $sql .=
" ".((int) $user->id).
",";
482 $sql .=
" '".$this->db->escape($label).
"',";
483 $sql .=
" ".($inventorycode ?
"'".$this->db->escape($inventorycode).
"'" :
"null").
",";
485 $sql .=
" ".((int) $origin_id).
",";
486 $sql .=
" '".$this->db->escape($origin_type).
"',";
487 $sql .=
" ".((int) $fk_project);
490 dol_syslog(get_class($this).
"::_create insert record into stock_mouvement", LOG_DEBUG);
491 $resql = $this->db->query(
$sql);
494 $mvid = $this->db->last_insert_id($this->db->prefix().
"stock_mouvement");
497 $this->error = $this->db->lasterror();
498 $this->errors[] = $this->error;
503 $oldqty = $product->stock_reel;
504 $oldpmp = $product->pmp;
505 $oldqtywarehouse = 0;
510 $sql =
"SELECT rowid, reel FROM ".$this->db->prefix().
"product_stock";
511 $sql .=
" WHERE fk_entrepot = ".((int) $entrepot_id).
" AND fk_product = ".((int) $fk_product);
513 dol_syslog(get_class($this).
"::_create check if a record already exists in product_stock", LOG_DEBUG);
514 $resql = $this->db->query(
$sql);
516 $obj = $this->db->fetch_object($resql);
519 $oldqtywarehouse = $obj->reel;
520 $fk_product_stock = $obj->rowid;
522 $this->db->free($resql);
524 $this->errors[] = $this->db->lasterror();
532 if ($type == 0 || $type == 3) {
536 if ($price > 0 || (
getDolGlobalString(
'STOCK_UPDATE_AWP_EVEN_WHEN_ENTRY_PRICE_IS_NULL') && $price == 0 && in_array($this->origin_type, array(
'order_supplier',
'invoice_supplier')))) {
537 $oldqtytouse = ($oldqty >= 0 ? $oldqty : 0);
540 $newpmp =
price2num((($oldqtytouse * $oldpmp) + ($qty * $price)) / ($oldqtytouse + $qty),
'MU');
560 if ($alreadyarecord > 0) {
561 $sql =
"UPDATE ".$this->db->prefix().
"product_stock SET reel = " . ((
float) $oldqtywarehouse + (
float) $qty);
562 $sql .=
" WHERE fk_entrepot = ".((int) $entrepot_id).
" AND fk_product = ".((int) $fk_product);
564 $sql =
"INSERT INTO ".$this->db->prefix().
"product_stock";
565 $sql .=
" (reel, fk_entrepot, fk_product) VALUES ";
566 $sql .=
" (".((float) $qty).
", ".((int) $entrepot_id).
", ".((int) $fk_product).
")";
569 dol_syslog(get_class($this).
"::_create update stock value", LOG_DEBUG);
570 $resql = $this->db->query(
$sql);
572 $this->errors[] = $this->db->lasterror();
574 } elseif (empty($fk_product_stock)) {
575 $fk_product_stock = $this->db->last_insert_id($this->db->prefix().
"product_stock");
580 if (!$error &&
isModEnabled(
'productbatch') && (($product->hasbatch() && !$skip_batch) || $force_update_batch)) {
581 if ($id_product_batch > 0) {
582 $result = $this->
createBatch($id_product_batch, $qty);
583 if ($result == -2 && $fk_product_stock > 0) {
584 $param_batch = array(
'fk_product_stock' => $fk_product_stock,
'batchnumber' => $batch);
588 $param_batch = array(
'fk_product_stock' => $fk_product_stock,
'batchnumber' => $batch);
603 $sql =
"UPDATE ".$this->db->prefix().
"product as p SET pmp = ".((
float) $newpmp).
",";
604 $sql .=
" stock=(SELECT SUM(ps.reel) FROM ".$this->db->prefix().
"product_stock as ps WHERE ps.fk_product = p.rowid)";
605 $sql .=
" WHERE rowid = ".((int) $fk_product);
607 dol_syslog(get_class($this).
"::_create update AWP", LOG_DEBUG);
608 $resql = $this->db->query(
$sql);
610 $this->errors[] = $this->db->lasterror();
615 if (empty($donotcleanemptylines)) {
618 $sql =
"DELETE FROM ".$this->db->prefix().
"product_stock WHERE reel = 0 AND rowid NOT IN (SELECT fk_product_stock FROM ".$this->db->prefix().
"product_batch as pb)";
619 $resql = $this->db->query(
$sql);
626 $error = $this->
_createSubProduct($user, $fk_product, $entrepot_id, $qty, $type, 0, $label, $inventorycode, $datem);
629 if ($movestock && !$error) {
638 if (!$error &&
isModEnabled(
'productbatch') && $product->hasbatch() && !$skip_batch) {
639 if ($product->status_batch == 2 && $qty > 0) {
642 $this->errors[] = $langs->trans(
"TooManyQtyForSerialNumber", $product->ref, $batch);
652 $this->db->rollback();
653 dol_syslog(get_class($this).
"::_create error code=".$error, LOG_ERR);
675 $sql .=
" t.fk_product,";
676 $sql .=
" t.fk_entrepot,";
679 $sql .=
" t.type_mouvement,";
680 $sql .=
" t.fk_user_author,";
682 $sql .=
" t.fk_origin as origin_id,";
683 $sql .=
" t.origintype as origin_type,";
684 $sql .=
" t.inventorycode,";
687 $sql .=
" t.sellby,";
688 $sql .=
" t.fk_projet as fk_project";
689 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
690 $sql .=
" WHERE t.rowid = ".((int) $id);
692 $resql = $this->db->query(
$sql);
694 $numrows = $this->db->num_rows($resql);
696 $obj = $this->db->fetch_object($resql);
698 $this->
id = $obj->rowid;
700 $this->product_id = $obj->fk_product;
701 $this->warehouse_id = $obj->fk_entrepot;
702 $this->qty = $obj->value;
703 $this->
type = $obj->type_mouvement;
705 $this->tms = $this->db->jdate($obj->tms);
706 $this->datem = $this->db->jdate($obj->datem);
707 $this->
price = $obj->price;
708 $this->fk_user_author = $obj->fk_user_author;
709 $this->label = $obj->label;
710 $this->fk_origin = $obj->origin_id;
711 $this->origintype = $obj->origin_type;
712 $this->origin_id = $obj->origin_id;
713 $this->origin_type = $obj->origin_type;
714 $this->inventorycode = $obj->inventorycode;
715 $this->batch = $obj->batch;
716 $this->eatby = $this->db->jdate($obj->eatby);
717 $this->sellby = $this->db->jdate($obj->sellby);
718 $this->fk_project = $obj->fk_project;
726 $this->db->free($resql);
734 $this->errors[] =
'Error '.$this->db->lasterror();
735 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
758 private function _createSubProduct($user, $idProduct, $entrepot_id, $qty, $type, $price = 0, $label =
'', $inventorycode =
'', $datem =
'')
766 $sql =
"SELECT fk_product_pere, fk_product_fils, qty";
767 $sql .=
" FROM ".$this->db->prefix().
"product_association";
768 $sql .=
" WHERE fk_product_pere = ".((int) $idProduct);
769 $sql .=
" AND incdec = 1";
771 dol_syslog(get_class($this).
"::_createSubProduct for parent product ".$idProduct, LOG_DEBUG);
772 $resql = $this->db->query(
$sql);
775 while ($obj = $this->db->fetch_object($resql)) {
776 $pids[$i] = $obj->fk_product_fils;
777 $pqtys[$i] = $obj->qty;
780 $this->db->free($resql);
786 foreach ($pids as $key => $value) {
790 $result = $tmpmove->_create($user, $pids[$key], $entrepot_id, ($qty * $pqtys[$key]), $type, 0, $label, $inventorycode, $datem);
792 $this->error = $tmpmove->error;
793 $this->errors = array_merge($this->errors, $tmpmove->errors);
795 $this->errors[] = $langs->trans(
"ErrorNoteAlsoThatSubProductCantBeFollowedByLot");
825 public function livraison($user, $fk_product, $entrepot_id, $qty, $price = 0, $label =
'', $datem =
'', $eatby =
'', $sellby =
'', $batch =
'', $id_product_batch = 0, $inventorycode =
'', $donotcleanemptylines = 0)
829 $skip_batch = empty($conf->productbatch->enabled);
831 return $this->
_create($user, $fk_product, $entrepot_id, (0 - $qty), 2, $price, $label, $inventorycode, $datem, $eatby, $sellby, $batch, $skip_batch, $id_product_batch, 0, $donotcleanemptylines);
852 public function reception($user, $fk_product, $entrepot_id, $qty, $price = 0, $label =
'', $eatby =
'', $sellby =
'', $batch =
'', $datem =
'', $id_product_batch = 0, $inventorycode =
'', $donotcleanemptylines = 0)
856 $skip_batch = empty($conf->productbatch->enabled);
858 return $this->
_create($user, $fk_product, $entrepot_id, $qty, 3, $price, $label, $inventorycode, $datem, $eatby, $sellby, $batch, $skip_batch, $id_product_batch, 0, $donotcleanemptylines);
872 $sql =
"SELECT SUM(value) as nb from ".$this->db->prefix().
"stock_mouvement";
873 $sql .=
" WHERE fk_product = ".((int) $productidselected);
874 $sql .=
" AND datem < '".$this->db->idate($datebefore).
"'";
876 dol_syslog(get_class($this).__METHOD__, LOG_DEBUG);
877 $resql = $this->db->query(
$sql);
879 $obj = $this->db->fetch_object($resql);
883 return (empty($nb) ? 0 : $nb);
901 global $user, $langs;
903 $langs->load(
'productbatch');
910 if (is_numeric($dluo)) {
911 $result = $pdluo->fetch($dluo);
912 if (empty($pdluo->id)) {
914 $this->error = $langs->trans(
'CantMoveNonExistantSerial');
915 $this->errors[] = $this->error;
918 } elseif (is_array($dluo)) {
919 if (isset($dluo[
'fk_product_stock'])) {
920 $vfk_product_stock = $dluo[
'fk_product_stock'];
921 $vbatchnumber = $dluo[
'batchnumber'];
923 $result = $pdluo->find($vfk_product_stock,
'',
'', $vbatchnumber);
925 dol_syslog(get_class($this).
"::createBatch array param dluo must contain at least key fk_product_stock", LOG_ERR);
929 dol_syslog(get_class($this).
"::createBatch error invalid param dluo", LOG_ERR);
935 if ($pdluo->id > 0) {
938 if ($pdluo->qty == 0) {
939 $result = $pdluo->delete($user, 1);
941 $result = $pdluo->update($user, 1);
944 $pdluo->fk_product_stock = $vfk_product_stock;
946 $pdluo->eatby = empty($dluo[
'eatby']) ?
'' : $dluo[
'eatby'];
947 $pdluo->sellby = empty($dluo[
'sellby']) ?
'' : $dluo[
'sellby'];
948 $pdluo->batch = $vbatchnumber;
950 $result = $pdluo->create($user, 1);
952 $this->error = $pdluo->error;
953 $this->errors = $pdluo->errors;
974 switch ($origin_type) {
976 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
980 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
984 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
985 $origin =
new Facture($this->db);
987 case 'order_supplier':
988 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
991 case 'invoice_supplier':
992 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
996 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
997 $origin =
new Project($this->db);
1000 require_once DOL_DOCUMENT_ROOT.
'/mrp/class/mo.class.php';
1001 $origin =
new Mo($this->db);
1004 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
1005 $origin =
new User($this->db);
1008 require_once DOL_DOCUMENT_ROOT.
'/reception/class/reception.class.php';
1012 require_once DOL_DOCUMENT_ROOT.
'/product/inventory/class/inventory.class.php';
1018 $origin_type_array = explode(
'@', $origin_type);
1019 $classname = $origin_type_array[0];
1020 $modulename = empty($origin_type_array[1]) ? strtolower($classname) : $origin_type_array[1];
1022 $result =
dol_include_once(
'/'.$modulename.
'/class/'.$classname.
'.class.php');
1025 $classname = ucfirst($classname);
1026 $origin =
new $classname($this->db);
1032 if (empty($origin) || !is_object($origin)) {
1036 if ($origin->fetch($origin_id) > 0) {
1037 return $origin->getNomUrl(1);
1053 public function setOrigin($origin_element, $origin_id, $line_id_object_src = 0, $line_id_object_origin = 0)
1055 $this->origin_type = $origin_element;
1056 $this->origin_id = $origin_id;
1057 $this->line_id_object_src = $line_id_object_src;
1058 $this->line_id_object_origin = $line_id_object_origin;
1060 $this->origintype = $origin_element;
1061 $this->fk_origin = $origin_id;
1093 switch ($this->
type) {
1095 $s =
'<span class="fa fa-level-down-alt stockmovemententry stockmovementtransfer" title="'.$langs->trans(
'StockIncreaseAfterCorrectTransfer').
'"></span>';
1097 $s .= $langs->trans(
'StockIncreaseAfterCorrectTransfer');
1101 $s =
'<span class="fa fa-level-up-alt stockmovementexit stockmovementtransfer" title="'.$langs->trans(
'StockDecreaseAfterCorrectTransfer').
'"></span>';
1103 $s .= $langs->trans(
'StockDecreaseAfterCorrectTransfer');
1107 $s =
'<span class="fa fa-long-arrow-alt-up stockmovementexit stockmovement" title="'.$langs->trans(
'StockDecrease').
'"></span>';
1109 $s .= $langs->trans(
'StockDecrease');
1113 $s =
'<span class="fa fa-long-arrow-alt-down stockmovemententry stockmovement" title="'.$langs->trans(
'StockIncrease').
'"></span>';
1115 $s .= $langs->trans(
'StockIncrease');
1134 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'')
1136 global $langs, $conf, $db;
1140 $label =
img_picto(
'',
'stock',
'class="pictofixedwidth"').
'<u>'.$langs->trans(
"StockMovement").
'</u>';
1141 $label .=
'<div width="100%">';
1142 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->id;
1143 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
1144 $qtylabel = (($this->qty > 0) ?
'<span class="stockmovemententry">+' :
'<span class="stockmovementexit">') . $this->qty .
'</span>';
1145 $label .=
'<br><b>'.$langs->trans(
'Qty').
':</b> ' . $qtylabel;
1147 $label .=
'<br><b>'.$langs->trans(
'Batch').
':</b> '.$this->batch;
1156 if ($option ==
'movements') {
1157 $url = DOL_URL_ROOT.
'/product/stock/movement_list.php?search_ref='.$this->id;
1159 $url = DOL_URL_ROOT.
'/product/stock/movement_list.php?id='.$this->warehouse_id.
'&msid='.$this->id;
1162 $link =
'<a href="'.$url.
'"'.($notooltip ?
'' :
' title="'.dol_escape_htmltag($label, 1).
'" class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"');
1167 $result .= ($link.img_object(($notooltip ?
'' : $label),
'stock', ($notooltip ?
'' :
'class="classfortooltip"')).$linkend);
1168 if ($withpicto != 2) {
1172 $result .= $link.$this->id.$linkend;
1199 if ($mode == 0 || $mode == 1) {
1200 return $langs->trans(
'StatusNotApplicable');
1201 } elseif ($mode == 2) {
1202 return img_picto($langs->trans(
'StatusNotApplicable'),
'statut9').
' '.$langs->trans(
'StatusNotApplicable');
1203 } elseif ($mode == 3) {
1204 return img_picto($langs->trans(
'StatusNotApplicable'),
'statut9');
1205 } elseif ($mode == 4) {
1206 return img_picto($langs->trans(
'StatusNotApplicable'),
'statut9').
' '.$langs->trans(
'StatusNotApplicable');
1207 } elseif ($mode == 5) {
1208 return $langs->trans(
'StatusNotApplicable').
' '.
img_picto($langs->trans(
'StatusNotApplicable'),
'statut9');
1211 return 'Bad value for mode';
1224 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1226 global $conf, $user, $langs;
1228 $langs->load(
"stocks");
1229 $outputlangs->load(
"products");
1232 $modele =
'stdmovement';
1234 if ($this->model_pdf) {
1235 $modele = $this->model_pdf;
1241 $modelpath =
"core/modules/stock/doc/";
1243 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1253 public function delete(
User $user, $notrigger = 0)
1270 $sql =
"SELECT sum(pb.qty) as cpt";
1271 $sql .=
" FROM ".$this->db->prefix().
"product_batch as pb";
1272 $sql .=
" INNER JOIN ".$this->db->prefix().
"product_stock as ps ON ps.rowid = pb.fk_product_stock";
1273 $sql .=
" WHERE ps.fk_product = " . ((int) $fk_product);
1274 $sql .=
" AND pb.batch = '" . $this->db->escape($batch) .
"'";
1276 $result = $this->db->query(
$sql);
1278 if ($this->db->num_rows($result)) {
1279 $obj = $this->db->fetch_object($result);
1283 $this->db->free($result);
1298 $formattedDate =
"REVERTMV" .dol_print_date($this->datem,
'%Y%m%d%His');
1299 if ($this->label ==
'Annulation movement ID'.$this->
id) {
1302 if ($this->inventorycode == $formattedDate) {
1306 $sql =
"UPDATE ".$this->db->prefix().
"stock_mouvement SET";
1307 $sql .=
" label = 'Annulation movement ID ".((int) $this->
id).
"',";
1308 $sql .=
"inventorycode = '".($formattedDate).
"'";
1309 $sql .=
" WHERE rowid = ".((int) $this->
id);
1311 $resql = $this->db->query(
$sql);
1314 $this->db->commit();
1317 $this->db->rollback();
Class to manage predefined suppliers products.
Class to manage customers orders.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage warehouses.
Class to manage shipments.
Class to manage suppliers invoices.
Class to manage invoices.
Class to manage stock movements.
__construct($db)
Constructor.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create object on disk.
getNomUrl($withpicto=0, $option='', $notooltip=0, $maxlen=24, $morecss='')
Return a link (with optionally the picto) Use this->id,this->lastname, this->firstname.
setOrigin($origin_element, $origin_id, $line_id_object_src=0, $line_id_object_origin=0)
Set attribute origin_type and fk_origin to object.
LibStatut($mode=0)
Return the label of the status.
createBatch($dluo, $qty)
Create or update batch record (update table llx_product_batch).
getBatchCount($fk_product, $batch)
Retrieve number of equipment for a product lot/serial.
get_origin($origin_id, $origin_type)
Return Url link of origin object.
livraison($user, $fk_product, $entrepot_id, $qty, $price=0, $label='', $datem='', $eatby='', $sellby='', $batch='', $id_product_batch=0, $inventorycode='', $donotcleanemptylines=0)
Decrease stock for product and subproducts.
_create($user, $fk_product, $entrepot_id, $qty, $type, $price=0, $label='', $inventorycode='', $datem='', $eatby='', $sellby='', $batch='', $skip_batch=false, $id_product_batch=0, $disablestockchangeforsubproduct=0, $donotcleanemptylines=0, $force_update_batch=false)
Add a movement of stock (in one direction only).
fetch($id)
Load object in memory from the database.
reception($user, $fk_product, $entrepot_id, $qty, $price=0, $label='', $eatby='', $sellby='', $batch='', $datem='', $id_product_batch=0, $inventorycode='', $donotcleanemptylines=0)
Increase stock for product and subproducts.
_createSubProduct($user, $idProduct, $entrepot_id, $qty, $type, $price=0, $label='', $inventorycode='', $datem='')
Create movement in database for all subproducts.
initAsSpecimen()
Initialise an instance with random values.
getTypeMovement($withlabel=0)
Return html string with picto for type of movement.
calculateBalanceForProductBefore($productidselected, $datebefore)
Count number of product in stock before a specific date.
getLibStatut($mode=0)
Return label statut.
reverseMouvement()
reverse movement for object by updating infos
Class to manage products or services.
const TYPE_SERVICE
Service.
Manage record for batch number management.
Class with list of lots and properties.
Class to manage projects.
Class to manage receptions.
Class to manage Dolibarr users.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
div float
Buy price without taxes.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type