39 public $element =
'stockmouvement';
44 public $table_element =
'stock_mouvement';
91 public $fk_user_author;
124 public $line_id_oject_src;
128 public $line_id_oject_origin;
135 public $inventorycode;
140 public $movementcode;
150 public $line_id_object_src;
154 public $line_id_object_origin;
168 public $fields = array(
169 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10,
'showoncombobox' => 1),
170 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 15),
171 'datem' => array(
'type' =>
'datetime',
'label' =>
'Datem',
'enabled' => 1,
'visible' => -1,
'position' => 20),
172 'fk_product' => array(
'type' =>
'integer:Product:product/class/product.class.php:1',
'label' =>
'Product',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 25),
173 'fk_entrepot' => array(
'type' =>
'integer:Entrepot:product/stock/class/entrepot.class.php',
'label' =>
'Warehouse',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 30),
174 'value' => array(
'type' =>
'double',
'label' =>
'Value',
'enabled' => 1,
'visible' => -1,
'position' => 35),
175 'price' => array(
'type' =>
'double(24,8)',
'label' =>
'Price',
'enabled' => 1,
'visible' => -1,
'position' => 40),
176 'type_mouvement' => array(
'type' =>
'smallint(6)',
'label' =>
'Type mouvement',
'enabled' => 1,
'visible' => -1,
'position' => 45),
177 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => -1,
'position' => 50),
178 'label' => array(
'type' =>
'varchar(255)',
'label' =>
'Label',
'enabled' => 1,
'visible' => -1,
'position' => 55),
179 'fk_origin' => array(
'type' =>
'integer',
'label' =>
'Fk origin',
'enabled' => 1,
'visible' => -1,
'position' => 60),
180 'origintype' => array(
'type' =>
'varchar(32)',
'label' =>
'Origintype',
'enabled' => 1,
'visible' => -1,
'position' => 65),
181 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Model pdf',
'enabled' => 1,
'visible' => 0,
'position' => 70),
182 'fk_projet' => array(
'type' =>
'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)',
'label' =>
'Project',
'enabled' =>
'isModEnabled("project")',
'visible' => -1,
'notnull' => 1,
'position' => 75),
183 'inventorycode' => array(
'type' =>
'varchar(128)',
'label' =>
'InventoryCode',
'enabled' => 1,
'visible' => -1,
'position' => 80),
184 'batch' => array(
'type' =>
'varchar(30)',
'label' =>
'Batch',
'enabled' => 1,
'visible' => -1,
'position' => 85),
185 'eatby' => array(
'type' =>
'date',
'label' =>
'Eatby',
'enabled' => 1,
'visible' => -1,
'position' => 90),
186 'sellby' => array(
'type' =>
'date',
'label' =>
'Sellby',
'enabled' => 1,
'visible' => -1,
'position' => 95),
187 'fk_project' => array(
'type' =>
'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)',
'label' =>
'Fk project',
'enabled' => 1,
'visible' => -1,
'position' => 100),
230 public function _create($user, $fk_product, $entrepot_id, $qty, $type, $price = 0, $label =
'', $inventorycode =
'', $datem =
'', $eatby = 0, $sellby = 0, $batch =
'', $skip_batch =
false, $id_product_batch = 0, $disablestockchangeforsubproduct = 0, $donotcleanemptylines = 0, $force_update_batch =
false)
233 global
$conf, $langs;
235 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
236 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/productlot.class.php';
239 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));
242 global $action, $hookmanager;
243 $hookmanager->initHooks(array(
'mouvementstock'));
245 if (is_object($hookmanager)) {
247 'currentcontext' =>
'mouvementstock',
249 'fk_product' => &$fk_product,
250 'entrepot_id' => &$entrepot_id,
255 'inventorycode' => &$inventorycode,
258 'sellby' => &$sellby,
260 'skip_batch' => &$skip_batch,
261 'id_product_batch' => &$id_product_batch
263 $reshook = $hookmanager->executeHooks(
'stockMovementCreate', $parameters, $this, $action);
266 if (!empty($hookmanager->resPrint)) {
270 } elseif ($reshook > 0) {
281 $now = (!empty($datem) ? $datem :
dol_now());
286 if (!($fk_product > 0)) {
289 if (!($entrepot_id > 0)) {
293 if (is_numeric($eatby) && $eatby < 0) {
294 dol_syslog(get_class($this).
"::_create start ErrorBadValueForParameterEatBy eatby = ".$eatby);
295 $this->errors[] =
'ErrorBadValueForParameterEatBy';
298 if (is_numeric($sellby) && $sellby < 0) {
299 dol_syslog(get_class($this).
"::_create start ErrorBadValueForParameterSellBy sellby = ".$sellby);
300 $this->errors[] =
'ErrorBadValueForParameterSellBy';
305 $this->product_id = $fk_product;
306 $this->entrepot_id = $entrepot_id;
307 $this->warehouse_id = $entrepot_id;
311 $this->label = $label;
312 $this->inventorycode = $inventorycode;
314 $this->batch = $batch;
318 $product =
new Product($this->db);
320 $result = $product->fetch($fk_product);
326 if ($product->id <= 0) {
333 $productChildrenNb = 0;
335 $productChildrenNb = $product->hasFatherOrChild(1);
338 if ($product->isStockManaged() && ($productChildrenNb == 0 ||
getDolGlobalInt(
'PRODUIT_SOUSPRODUITS_ALSO_ENABLE_PARENT_STOCK_MOVE'))) {
346 $product->load_stock(
'novirtual');
350 if (
isModEnabled(
'productbatch') && $product->hasbatch() && !$skip_batch) {
352 $langs->load(
"errors");
353 $this->errors[] = $langs->transnoentitiesnoconv(
"ErrorTryToMakeMoveOnProductRequiringBatchData", $product->ref);
354 dol_syslog(
"Try to make a movement of a product with status_batch on without any batch data", LOG_ERR);
356 $this->db->rollback();
374 $sql =
"SELECT pb.rowid, pb.batch, pb.eatby, pb.sellby FROM ".$this->db->prefix().
"product_lot as pb";
375 $sql .=
" WHERE pb.fk_product = ".((int) $fk_product).
" AND pb.batch = '".$this->db->escape($batch).
"'";
377 dol_syslog(get_class($this).
"::_create scan serial for this product to check if eatby and sellby match", LOG_DEBUG);
379 $resql = $this->db->query($sql);
381 $num = $this->db->num_rows($resql);
384 while ($i < $num && $obj = $this->db->fetch_object($resql)) {
388 $eatbywithouthour =
dol_mktime(0, 0, 0, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year']);
389 if ($this->db->jdate($obj->eatby) != $eatby && $this->db->jdate($obj->eatby) != $eatbywithouthour) {
391 $langs->load(
"stocks");
392 $this->errors[] = $langs->transnoentitiesnoconv(
"ThisSerialAlreadyExistWithDifferentDate", $batch,
dol_print_date($this->db->jdate($obj->eatby),
'dayhour'),
dol_print_date($eatbywithouthour,
'dayhour'));
393 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);
394 $this->db->rollback();
398 $eatby = $obj->eatby;
403 $result = $productlot->fetch($obj->rowid);
404 $productlot->eatby = $eatby;
405 $result = $productlot->update($user);
408 $this->db->rollback();
416 $sellbywithouthour =
dol_mktime(0, 0, 0, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year']);
417 if ($this->db->jdate($obj->sellby) != $sellby && $this->db->jdate($obj->sellby) != $sellbywithouthour) {
419 $this->errors[] = $langs->transnoentitiesnoconv(
"ThisSerialAlreadyExistWithDifferentDate", $batch,
dol_print_date($this->db->jdate($obj->sellby)),
dol_print_date($sellby));
421 $this->db->rollback();
425 $sellby = $obj->sellby;
430 $result = $productlot->fetch($obj->rowid);
431 $productlot->sellby = $sellby;
432 $result = $productlot->update($user);
435 $this->db->rollback();
445 $productlot->origin_type = !empty($this->origin_type) ? $this->origin_type :
'';
446 $productlot->origin_id = !empty($this->origin_id) ? $this->origin_id : 0;
447 $productlot->entity =
$conf->entity;
448 $productlot->fk_product = $fk_product;
449 $productlot->batch = $batch;
451 $productlot->eatby = $eatby;
452 $productlot->sellby = $sellby;
453 $result = $productlot->create($user);
456 $this->db->rollback();
462 $this->db->rollback();
470 if ($movestock && $qty < 0 &&
getDolGlobalInt(
'STOCK_DISALLOW_NEGATIVE_TRANSFER')) {
471 if (
isModEnabled(
'productbatch') && $product->hasbatch() && !$skip_batch) {
474 if (isset($product->stock_warehouse[$entrepot_id])) {
475 foreach ($product->stock_warehouse[$entrepot_id]->detail_batch as $batchcursor => $prodbatch) {
477 if ((
string) $batch !== (
string) $batchcursor) {
482 if ($prodbatch->qty < abs($qty)) {
483 $qtyisnotenough = $prodbatch->qty;
488 if (!$foundforbatch || $qtyisnotenough) {
489 $langs->load(
"stocks");
490 include_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
491 $tmpwarehouse =
new Entrepot($this->db);
492 $tmpwarehouse->fetch($entrepot_id);
494 $this->error = $langs->trans(
'qtyToTranferLotIsNotEnough', $product->ref, (
string) $batch, $qtyisnotenough, $tmpwarehouse->ref);
495 $this->errors[] = $langs->trans(
'qtyToTranferLotIsNotEnough', $product->ref, (
string) $batch, $qtyisnotenough, $tmpwarehouse->ref);
496 $this->db->rollback();
500 if ($product->stockable_product == Product::ENABLED_STOCK && (empty($product->stock_warehouse[$entrepot_id]) || empty($product->stock_warehouse[$entrepot_id]->real) || $product->stock_warehouse[$entrepot_id]->real < abs($qty))) {
501 $langs->load(
"stocks");
502 $this->error = $langs->trans(
'qtyToTranferIsNotEnough').
' : '.$product->ref;
503 $this->errors[] = $langs->trans(
'qtyToTranferIsNotEnough').
' : '.$product->ref;
504 $this->db->rollback();
510 if ($movestock && $product->stockable_product == Product::ENABLED_STOCK) {
512 $fk_project = $this->fk_project;
513 if (!empty($this->origin_type)) {
514 $origin_type = $this->origin_type;
515 $origin_id = $this->origin_id;
516 if (empty($fk_project) && $origin_type ==
'project') {
517 $fk_project = $origin_id;
528 $label =
dol_trunc((
string) $label, 255,
'right',
'UTF-8', 1);
530 $sql =
"INSERT INTO ".$this->db->prefix().
"stock_mouvement(";
531 $sql .=
" datem, fk_product, batch, eatby, sellby,";
532 $sql .=
" fk_entrepot, value, type_mouvement, fk_user_author, label, inventorycode, price, fk_origin, origintype, fk_projet";
534 $sql .=
" VALUES ('".$this->db->idate($this->datem).
"', ".((int) $this->product_id).
", ";
535 $sql .=
" ".(isset($batch) ?
"'".$this->db->escape($batch).
"'" :
"null").
", ";
536 $sql .=
" ".($eatby ?
"'".$this->db->idate($eatby).
"'" :
"null").
", ";
537 $sql .=
" ".($sellby ?
"'".$this->db->idate($sellby).
"'" :
"null").
", ";
538 $sql .=
" ".((int) $this->entrepot_id).
", ".((float) $this->qty).
", ".((int) $this->
type).
",";
539 $sql .=
" ".((int) $user->id).
",";
540 $sql .=
" '".$this->db->escape($label).
"',";
541 $sql .=
" ".($inventorycode ?
"'".$this->db->escape($inventorycode).
"'" :
"null").
",";
542 $sql .=
" ".((float)
price2num($price)).
",";
543 $sql .=
" ".((int) $origin_id).
",";
544 $sql .=
" '".$this->db->escape($origin_type).
"',";
545 $sql .=
" ".((int) $fk_project);
548 dol_syslog(get_class($this).
"::_create insert record into stock_mouvement", LOG_DEBUG);
549 $resql = $this->db->query($sql);
552 $mvid = $this->db->last_insert_id($this->db->prefix().
"stock_mouvement");
555 $this->error = $this->db->lasterror();
556 $this->errors[] = $this->error;
561 $oldqty = $product->stock_reel;
562 $oldpmp = $product->pmp;
563 $oldqtywarehouse = 0;
567 $fk_product_stock = 0;
569 $sql =
"SELECT rowid, reel FROM ".$this->db->prefix().
"product_stock";
570 $sql .=
" WHERE fk_entrepot = ".((int) $entrepot_id).
" AND fk_product = ".((int) $fk_product);
572 dol_syslog(get_class($this).
"::_create check if a record already exists in product_stock", LOG_DEBUG);
573 $resql = $this->db->query($sql);
575 $obj = $this->db->fetch_object($resql);
578 $oldqtywarehouse = $obj->reel;
579 $fk_product_stock = $obj->rowid;
581 $this->db->free($resql);
583 $this->errors[] = $this->db->lasterror();
591 if ($type == 0 || $type == 3) {
595 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')))) {
596 $oldqtytouse = ($oldqty >= 0 ? $oldqty : 0);
598 if ($oldpmp > 0 && ($oldqtytouse + $qty) != 0) {
599 $newpmp =
price2num((($oldqtytouse * $oldpmp) + ($qty * $price)) / ($oldqtytouse + $qty),
'MU');
619 if ($alreadyarecord > 0) {
620 $sql =
"UPDATE ".$this->db->prefix().
"product_stock SET reel = " . ((float) $oldqtywarehouse + (
float) $qty);
621 $sql .=
" WHERE fk_entrepot = ".((int) $entrepot_id).
" AND fk_product = ".((int) $fk_product);
623 $sql =
"INSERT INTO ".$this->db->prefix().
"product_stock";
624 $sql .=
" (reel, fk_entrepot, fk_product) VALUES ";
625 $sql .=
" (".((float) $qty).
", ".((int) $entrepot_id).
", ".((int) $fk_product).
")";
628 dol_syslog(get_class($this).
"::_create update stock value", LOG_DEBUG);
629 $resql = $this->db->query($sql);
631 $this->errors[] = $this->db->lasterror();
633 } elseif (empty($fk_product_stock)) {
634 $fk_product_stock = $this->db->last_insert_id($this->db->prefix().
"product_stock");
639 if (!$error &&
isModEnabled(
'productbatch') && (($product->hasbatch() && !$skip_batch) || $force_update_batch)) {
640 if ($id_product_batch > 0) {
641 $result = $this->
createBatch($id_product_batch, $qty);
642 if ($result == -2 && $fk_product_stock > 0) {
643 $param_batch = array(
'fk_product_stock' => $fk_product_stock,
'batchnumber' => (
string) $batch);
647 $param_batch = array(
'fk_product_stock' => $fk_product_stock,
'batchnumber' => (
string) $batch);
662 $sql =
"UPDATE ".$this->db->prefix().
"product as p SET pmp = ".((float) $newpmp).
",";
663 $sql .=
" stock=(SELECT SUM(ps.reel) FROM ".$this->db->prefix().
"product_stock as ps WHERE ps.fk_product = p.rowid)";
664 $sql .=
" WHERE rowid = ".((int) $fk_product);
666 dol_syslog(get_class($this).
"::_create update AWP", LOG_DEBUG);
667 $resql = $this->db->query($sql);
669 $this->errors[] = $this->db->lasterror();
674 if (empty($donotcleanemptylines)) {
677 $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)";
678 $resql = $this->db->query($sql);
684 if (!$error &&
getDolGlobalString(
'PRODUIT_SOUSPRODUITS') && !
getDolGlobalString(
'PRODUIT_SOUSPRODUITS_ALWAYS_DISABLE_CHILDREN_STOCK_MOVE') && empty($disablestockchangeforsubproduct)) {
685 $error = $this->
_createSubProduct($user, $fk_product, $entrepot_id, $qty, $type, 0, $label, $inventorycode, $datem);
688 if ($movestock && !$error) {
691 $result = $this->call_trigger(
'STOCK_MOVEMENT', $user);
698 if (!$error &&
isModEnabled(
'productbatch') && $product->hasbatch() && !$skip_batch) {
699 if ($product->status_batch == 2 && $qty > 0) {
700 if ($this->
getBatchCount($fk_product, (
string) $batch) > 1) {
702 $this->errors[] = $langs->trans(
"TooManyQtyForSerialNumber", $product->ref, (
string) $batch);
712 $this->db->rollback();
713 dol_syslog(get_class($this).
"::_create error code=".$error, LOG_ERR);
735 $sql .=
" t.fk_product,";
736 $sql .=
" t.fk_entrepot,";
739 $sql .=
" t.type_mouvement,";
740 $sql .=
" t.fk_user_author,";
742 $sql .=
" t.fk_origin as origin_id,";
743 $sql .=
" t.origintype as origin_type,";
744 $sql .=
" t.inventorycode as movementcode,";
747 $sql .=
" t.sellby,";
748 $sql .=
" t.fk_projet as fk_project";
749 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
750 $sql .=
" WHERE t.rowid = ".((int) $id);
752 $resql = $this->db->query($sql);
754 $numrows = $this->db->num_rows($resql);
756 $obj = $this->db->fetch_object($resql);
758 $this->
id = $obj->rowid;
760 $this->product_id = $obj->fk_product;
761 $this->warehouse_id = $obj->fk_entrepot;
762 $this->qty = $obj->value;
763 $this->
type = $obj->type_mouvement;
765 $this->tms = $this->db->jdate($obj->tms);
766 $this->datem = $this->db->jdate($obj->datem);
767 $this->
price = $obj->price;
768 $this->fk_user_author = $obj->fk_user_author;
769 $this->label = $obj->label;
770 $this->fk_origin = $obj->origin_id;
771 $this->origintype = $obj->origin_type;
772 $this->origin_id = $obj->origin_id;
773 $this->origin_type = $obj->origin_type;
774 $this->inventorycode = $obj->movementcode;
775 $this->movementcode = $obj->movementcode;
776 $this->batch = $obj->batch;
777 $this->eatby = $this->db->jdate($obj->eatby);
778 $this->sellby = $this->db->jdate($obj->sellby);
779 $this->fk_project = $obj->fk_project;
787 $this->db->free($resql);
795 $this->errors[] =
'Error '.$this->db->lasterror();
796 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
819 private function _createSubProduct($user, $idProduct, $entrepot_id, $qty, $type, $price = 0, $label =
'', $inventorycode =
'', $datem =
'')
825 $sql =
"SELECT fk_product_pere, fk_product_fils, qty";
826 $sql .=
" FROM ".$this->db->prefix().
"product_association";
827 $sql .=
" WHERE fk_product_pere = ".((int) $idProduct);
828 $sql .=
" AND incdec = 1";
830 dol_syslog(__METHOD__.
' for parent product '.$idProduct, LOG_DEBUG);
831 $resql = $this->db->query($sql);
834 while ($obj = $this->db->fetch_object($resql)) {
836 $result = $tmpmove->_create($user, $obj->fk_product_fils, $entrepot_id, ($qty * $obj->qty), $type, 0, $label, $inventorycode, $datem);
838 $this->error = $tmpmove->error;
839 $this->errors = array_merge($this->errors, $tmpmove->errors);
841 $this->errors[] = $langs->trans(
'ErrorNoteAlsoThatSubProductCantBeFollowedByLot');
850 $this->db->free($resql);
877 public function livraison($user, $fk_product, $entrepot_id, $qty, $price = 0, $label =
'', $datem =
'', $eatby =
'', $sellby =
'', $batch =
'', $id_product_batch = 0, $inventorycode =
'', $donotcleanemptylines = 0)
881 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);
903 public function reception($user, $fk_product, $entrepot_id, $qty, $price = 0, $label =
'', $eatby =
'', $sellby =
'', $batch =
'', $datem =
'', $id_product_batch = 0, $inventorycode =
'', $donotcleanemptylines = 0, $disablestockchangeforsubproduct = 0)
907 return $this->
_create($user, $fk_product, $entrepot_id, $qty, 3, $price, $label, $inventorycode, $datem, $eatby, $sellby, $batch, $skip_batch, $id_product_batch, $disablestockchangeforsubproduct, $donotcleanemptylines);
921 $sql =
"SELECT SUM(value) as nb from ".$this->db->prefix().
"stock_mouvement";
922 $sql .=
" WHERE fk_product = ".((int) $productidselected);
923 $sql .=
" AND datem < '".$this->db->idate($datebefore).
"'";
925 dol_syslog(get_class($this).__METHOD__, LOG_DEBUG);
926 $resql = $this->db->query($sql);
928 $obj = $this->db->fetch_object($resql);
930 $nb = (float) $obj->nb;
932 return (empty($nb) ? 0 : $nb);
950 global $user, $langs;
952 $langs->load(
'productbatch');
957 $vfk_product_stock = 0;
961 if (is_numeric($dluo)) {
962 $result = $pdluo->fetch($dluo);
963 if (empty($pdluo->id)) {
965 $this->error = $langs->trans(
'CantMoveNonExistantSerial');
966 $this->errors[] = $this->error;
969 } elseif (is_array($dluo)) {
970 if (isset($dluo[
'fk_product_stock'])) {
971 $vfk_product_stock = $dluo[
'fk_product_stock'];
972 $vbatchnumber = $dluo[
'batchnumber'];
974 $result = $pdluo->find($vfk_product_stock, 0, 0, $vbatchnumber);
976 dol_syslog(get_class($this).
"::createBatch array param dluo must contain at least key fk_product_stock", LOG_ERR);
980 dol_syslog(get_class($this).
"::createBatch error invalid param dluo", LOG_ERR);
986 if ($pdluo->id > 0) {
989 if ($pdluo->qty == 0) {
990 $result = $pdluo->delete($user, 1);
992 $result = $pdluo->update($user, 1);
995 $pdluo->fk_product_stock = $vfk_product_stock;
997 $pdluo->eatby = empty($dluo[
'eatby']) ?
'' : $dluo[
'eatby'];
998 $pdluo->sellby = empty($dluo[
'sellby']) ?
'' : $dluo[
'sellby'];
999 $pdluo->batch = $vbatchnumber;
1001 $result = $pdluo->create($user, 1);
1024 switch ($origin_type) {
1026 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
1030 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1034 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1035 $origin =
new Facture($this->db);
1037 case 'order_supplier':
1038 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1041 case 'invoice_supplier':
1042 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1046 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
1047 $origin =
new Project($this->db);
1050 require_once DOL_DOCUMENT_ROOT.
'/mrp/class/mo.class.php';
1051 $origin =
new Mo($this->db);
1054 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
1055 $origin =
new User($this->db);
1058 require_once DOL_DOCUMENT_ROOT.
'/reception/class/reception.class.php';
1062 require_once DOL_DOCUMENT_ROOT.
'/product/inventory/class/inventory.class.php';
1068 $origin_type_array = explode(
'@', $origin_type);
1069 $classname = $origin_type_array[0];
1070 $modulename = empty($origin_type_array[1]) ? strtolower($classname) : $origin_type_array[1];
1074 $result =
dol_include_once(
'/'.$modulename.
'/class/'.strtolower($classname).
'.class.php');
1077 $classname = ucfirst($classname);
1078 $origin =
new $classname($this->db);
1084 if (empty($origin) || !is_object($origin)) {
1088 if ($origin->fetch($origin_id) > 0) {
1089 return $origin->getNomUrl(1);
1105 public function setOrigin($origin_element, $origin_id, $line_id_object_src = 0, $line_id_object_origin = 0)
1107 $this->origin_type = $origin_element;
1108 $this->origin_id = $origin_id;
1109 $this->line_id_object_src = $line_id_object_src;
1110 $this->line_id_object_origin = $line_id_object_origin;
1112 $this->origintype = $origin_element;
1113 $this->fk_origin = $origin_id;
1145 switch ($this->
type) {
1147 $s =
'<span class="invertforbadge"><span class="fa fa-level-down-alt stockmovemententry stockmovementtransfer" title="'.$langs->trans(
'StockIncreaseAfterCorrectTransfer').
'"></span></span>';
1149 $s .= $langs->trans(
'StockIncreaseAfterCorrectTransfer');
1153 $s =
'<span class="invertforbadge"><span class="fa fa-level-up-alt stockmovementexit stockmovementtransfer" title="'.$langs->trans(
'StockDecreaseAfterCorrectTransfer').
'"></span></span>';
1155 $s .= $langs->trans(
'StockDecreaseAfterCorrectTransfer');
1159 $s =
'<span class="invertforbadge"><span class="fa fa-long-arrow-alt-up stockmovementexit stockmovement" title="'.$langs->trans(
'StockDecrease').
'"></span></span>';
1161 $s .= $langs->trans(
'StockDecrease');
1165 $s =
'<span class="invertforbadge"><span class="fa fa-long-arrow-alt-down stockmovemententry stockmovement" title="'.$langs->trans(
'StockIncrease').
'"></span></span>';
1167 $s .= $langs->trans(
'StockIncrease');
1186 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'')
1192 $label =
img_picto(
'',
'stock',
'class="pictofixedwidth"').
'<u>'.$langs->trans(
"StockMovement").
'</u>';
1193 $label .=
'<div width="100%">';
1194 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->id;
1195 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
1196 $qtylabel = (($this->qty > 0) ?
'<span class="stockmovemententry">+' :
'<span class="stockmovementexit">') . $this->qty .
'</span>';
1197 if ($this->inventorycode) {
1198 $label .=
'<br><b>'.$langs->trans(
'InventoryCode').
':</b> '.$this->inventorycode;
1200 $label .=
'<br><b>'.$langs->trans(
'Qty').
':</b> ' . $qtylabel;
1202 $label .=
'<br><b>'.$langs->trans(
'Batch').
':</b> '.$this->batch;
1211 if ($option ==
'movements') {
1212 $url = DOL_URL_ROOT.
'/product/stock/movement_list.php?search_ref='.$this->id;
1214 $url = DOL_URL_ROOT.
'/product/stock/movement_list.php?id='.$this->warehouse_id.
'&msid='.$this->id;
1217 $link =
'<a href="'.$url.
'"'.($notooltip ?
'' :
' title="'.dol_escape_htmltag($label, 1).
'" class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"');
1222 $result .= ($link.img_object(($notooltip ?
'' : $label),
'stock', ($notooltip ?
'' :
'class="classfortooltip"')).$linkend);
1223 if ($withpicto != 2) {
1227 $result .= $link.$this->id.$linkend;
1254 if ($mode == 0 || $mode == 1) {
1255 return $langs->trans(
'StatusNotApplicable');
1256 } elseif ($mode == 2) {
1257 return img_picto($langs->trans(
'StatusNotApplicable'),
'statut9').
' '.$langs->trans(
'StatusNotApplicable');
1258 } elseif ($mode == 3) {
1259 return img_picto($langs->trans(
'StatusNotApplicable'),
'statut9');
1260 } elseif ($mode == 4) {
1261 return img_picto($langs->trans(
'StatusNotApplicable'),
'statut9').
' '.$langs->trans(
'StatusNotApplicable');
1262 } elseif ($mode == 5) {
1263 return $langs->trans(
'StatusNotApplicable').
' '.
img_picto($langs->trans(
'StatusNotApplicable'),
'statut9');
1266 return 'Bad value for mode';
1279 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1283 $langs->load(
"stocks");
1284 $outputlangs->load(
"products");
1287 $modele =
'stdmovement';
1289 if ($this->model_pdf) {
1290 $modele = $this->model_pdf;
1296 $modelpath =
"core/modules/stock/doc/";
1298 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1308 public function delete(
User $user, $notrigger = 0)
1325 $sql =
"SELECT sum(pb.qty) as cpt";
1326 $sql .=
" FROM ".$this->db->prefix().
"product_batch as pb";
1327 $sql .=
" INNER JOIN ".$this->db->prefix().
"product_stock as ps ON ps.rowid = pb.fk_product_stock";
1328 $sql .=
" WHERE ps.fk_product = " . ((int) $fk_product);
1329 $sql .=
" AND pb.batch = '" . $this->db->escape($batch) .
"'";
1331 $result = $this->db->query($sql);
1333 if ($this->db->num_rows($result)) {
1334 $obj = $this->db->fetch_object($result);
1338 $this->db->free($result);
1356 $formattedDate =
"REVERT-" .($this->inventorycode ? $this->inventorycode :
dol_print_date($this->datem,
'%Y%m%d%His'));
1357 if ($this->inventorycode == $formattedDate) {
1361 $newlabel =
'Revert '.$this->label;
1364 if ($this->
type == 0) {
1366 } elseif ($this->
type == 1) {
1368 } elseif ($this->
type == 2) {
1370 } elseif ($this->
type == 3) {
1375 $newqty = - $this->qty;
1379 $result = $this->
_create($user, $this->product_id, $this->warehouse_id, $newqty, $newtype, 0, $newlabel, $formattedDate,
'', 0, 0, $this->batch);
1382 $this->db->commit();
1385 $this->db->rollback();
1402 $sql =
"SELECT MAX(datem) as datem";
1403 $sql .=
" FROM ".MAIN_DB_PREFIX.
"stock_mouvement";
1404 $sql .=
" WHERE fk_product = " . ((int) $fk_product);
1405 $sql .=
" AND fk_entrepot = " .((int) $fk_entrepot);
1406 $sql .=
" AND batch = '" . $this->db->escape($batch) .
"'";
1408 $result = $this->db->query($sql);
1410 if ($this->db->num_rows($result)) {
1411 $dateObj = $this->db->fetch_object($result);
1412 $date = $dateObj->datem;
1414 $this->db->free($result);
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.
setErrorsFromObject($object)
setErrorsFromObject
errorsToString()
Method to output saved errors.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
Class to manage warehouses.
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.
_create($user, $fk_product, $entrepot_id, $qty, $type, $price=0, $label='', $inventorycode='', $datem='', $eatby=0, $sellby=0, $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).
LibStatut($mode=0)
Return the label of the status.
createBatch($dluo, $qty)
Create or update batch record (update table llx_product_batch).
reception($user, $fk_product, $entrepot_id, $qty, $price=0, $label='', $eatby='', $sellby='', $batch='', $datem='', $id_product_batch=0, $inventorycode='', $donotcleanemptylines=0, $disablestockchangeforsubproduct=0)
Increase stock for product and subproducts.
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.
fetch($id)
Load object in memory from the database.
_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.
getDateLastMovementProductBatch($fk_entrepot, $fk_product, $batch)
Retrieve date of last stock movement for.
getTypeMovement($withlabel=0)
Return html string with picto for type of movement.
reverseMovement()
Reverse movement for object by updating infos.
calculateBalanceForProductBefore($productidselected, $datebefore)
Count number of product in stock before a specific date.
getLibStatut($mode=0)
Return label statut.
Class to manage products or services.
const DISABLED_STOCK
Stockable product.
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.
dol_now($mode='gmt')
Return date for now.
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, $allowothertags=array())
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
getDolGlobalString($key, $default='')
Return a 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.
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...