36 public $element =
'stockmouvement';
41 public $table_element =
'stock_mouvement';
72 public $fk_user_author;
104 public $inventorycode;
108 public $fields = array(
109 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10,
'showoncombobox'=>1),
110 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>15),
111 'datem' =>array(
'type'=>
'datetime',
'label'=>
'Datem',
'enabled'=>1,
'visible'=>-1,
'position'=>20),
112 'fk_product' =>array(
'type'=>
'integer:Product:product/class/product.class.php:1',
'label'=>
'Product',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>25),
113 'fk_entrepot' =>array(
'type'=>
'integer:Entrepot:product/stock/class/entrepot.class.php',
'label'=>
'Warehouse',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>30),
114 'value' =>array(
'type'=>
'double',
'label'=>
'Value',
'enabled'=>1,
'visible'=>-1,
'position'=>35),
115 'price' =>array(
'type'=>
'double(24,8)',
'label'=>
'Price',
'enabled'=>1,
'visible'=>-1,
'position'=>40),
116 'type_mouvement' =>array(
'type'=>
'smallint(6)',
'label'=>
'Type mouvement',
'enabled'=>1,
'visible'=>-1,
'position'=>45),
117 'fk_user_author' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'Fk user author',
'enabled'=>1,
'visible'=>-1,
'position'=>50),
118 'label' =>array(
'type'=>
'varchar(255)',
'label'=>
'Label',
'enabled'=>1,
'visible'=>-1,
'position'=>55),
119 'fk_origin' =>array(
'type'=>
'integer',
'label'=>
'Fk origin',
'enabled'=>1,
'visible'=>-1,
'position'=>60),
120 'origintype' =>array(
'type'=>
'varchar(32)',
'label'=>
'Origintype',
'enabled'=>1,
'visible'=>-1,
'position'=>65),
121 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'Model pdf',
'enabled'=>1,
'visible'=>0,
'position'=>70),
122 '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),
123 'inventorycode' =>array(
'type'=>
'varchar(128)',
'label'=>
'InventoryCode',
'enabled'=>1,
'visible'=>-1,
'position'=>80),
124 'batch' =>array(
'type'=>
'varchar(30)',
'label'=>
'Batch',
'enabled'=>1,
'visible'=>-1,
'position'=>85),
125 'eatby' =>array(
'type'=>
'date',
'label'=>
'Eatby',
'enabled'=>1,
'visible'=>-1,
'position'=>90),
126 'sellby' =>array(
'type'=>
'date',
'label'=>
'Sellby',
'enabled'=>1,
'visible'=>-1,
'position'=>95),
127 'fk_project' =>array(
'type'=>
'integer:Project:projet/class/project.class.php:1:fk_statut=1',
'label'=>
'Fk project',
'enabled'=>1,
'visible'=>-1,
'position'=>100),
169 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)
172 global $conf, $langs;
174 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
175 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/productlot.class.php';
178 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=".$skip_batch);
181 global $action, $hookmanager;
182 $hookmanager->initHooks(array(
'mouvementstock'));
184 if (is_object($hookmanager)) {
186 'currentcontext' =>
'mouvementstock',
188 'fk_product' => &$fk_product,
189 'entrepot_id' => &$entrepot_id,
194 'inventorycode' => &$inventorycode,
197 'sellby' => &$sellby,
199 'skip_batch' => &$skip_batch,
200 'id_product_batch' => &$id_product_batch
202 $reshook = $hookmanager->executeHooks(
'stockMovementCreate', $parameters, $this, $action);
205 if (!empty($hookmanager->resPrint)) {
209 } elseif ($reshook > 0) {
210 return $hookmanager->resPrint;
217 if (empty($price)) $price = 0;
218 $now = (!empty($datem) ? $datem :
dol_now());
221 if (!($fk_product > 0))
return 0;
222 if (!($entrepot_id > 0))
return 0;
224 if (is_numeric($eatby) && $eatby < 0) {
225 dol_syslog(get_class($this).
"::_create start ErrorBadValueForParameterEatBy eatby = ".$eatby);
226 $this->errors[] =
'ErrorBadValueForParameterEatBy';
229 if (is_numeric($sellby) && $sellby < 0) {
230 dol_syslog(get_class($this).
"::_create start ErrorBadValueForParameterSellBy sellby = ".$sellby);
231 $this->errors[] =
'ErrorBadValueForParameterSellBy';
236 $this->product_id = $fk_product;
237 $this->entrepot_id = $entrepot_id;
238 $this->warehouse_id = $entrepot_id;
242 $this->label = $label;
243 $this->inventorycode = $inventorycode;
245 $this->batch = $batch;
251 $result = $product->fetch($fk_product);
253 $this->error = $product->error;
254 $this->errors = $product->errors;
258 if ($product->id <= 0) {
265 if ($product->type !=
Product::TYPE_SERVICE || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) $movestock = 1;
271 $product->load_stock(
'novirtual');
275 if (
isModEnabled(
'productbatch') && $product->hasbatch() && !$skip_batch) {
277 $langs->load(
"errors");
278 $this->errors[] = $langs->transnoentitiesnoconv(
"ErrorTryToMakeMoveOnProductRequiringBatchData", $product->ref);
279 dol_syslog(
"Try to make a movement of a product with status_batch on without any batch data");
281 $this->
db->rollback();
291 $sql =
"SELECT pb.rowid, pb.batch, pb.eatby, pb.sellby FROM ".$this->db->prefix().
"product_lot as pb";
292 $sql .=
" WHERE pb.fk_product = ".((int) $fk_product).
" AND pb.batch = '".$this->
db->escape($batch).
"'";
293 dol_syslog(get_class($this).
"::_create scan serial for this product to check if eatby and sellby match", LOG_DEBUG);
300 $obj = $this->
db->fetch_object(
$resql);
304 $eatbywithouthour =
dol_mktime(0, 0, 0, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year']);
305 if ($this->
db->jdate($obj->eatby) != $eatby && $this->db->jdate($obj->eatby) != $eatbywithouthour) {
307 $langs->load(
"stocks");
308 $this->errors[] = $langs->transnoentitiesnoconv(
"ThisSerialAlreadyExistWithDifferentDate", $batch,
dol_print_date($this->
db->jdate($obj->eatby),
'dayhour'),
dol_print_date($eatbywithouthour,
'dayhour'));
309 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);
310 $this->
db->rollback();
314 $eatby = $obj->eatby;
319 $result = $productlot->fetch($obj->rowid);
320 $productlot->eatby = $eatby;
321 $result = $productlot->update($user);
323 $this->error = $productlot->error;
324 $this->errors = $productlot->errors;
325 $this->
db->rollback();
333 $sellbywithouthour =
dol_mktime(0, 0, 0, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year']);
334 if ($this->
db->jdate($obj->sellby) != $sellby && $this->db->jdate($obj->sellby) != $sellbywithouthour) {
336 $this->errors[] = $langs->transnoentitiesnoconv(
"ThisSerialAlreadyExistWithDifferentDate", $batch,
dol_print_date($this->
db->jdate($obj->sellby)),
dol_print_date($sellby));
338 $this->
db->rollback();
342 $sellby = $obj->sellby;
347 $result = $productlot->fetch($obj->rowid);
348 $productlot->sellby = $sellby;
349 $result = $productlot->update($user);
351 $this->error = $productlot->error;
352 $this->errors = $productlot->errors;
353 $this->
db->rollback();
363 $productlot->entity = $conf->entity;
364 $productlot->fk_product = $fk_product;
365 $productlot->batch = $batch;
367 $productlot->eatby = $eatby;
368 $productlot->sellby = $sellby;
369 $result = $productlot->create($user);
371 $this->error = $productlot->error;
372 $this->errors = $productlot->errors;
373 $this->
db->rollback();
379 $this->
db->rollback();
386 if ($movestock && $qty < 0 && empty($conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER)) {
387 if (
isModEnabled(
'productbatch') && $product->hasbatch() && !$skip_batch) {
391 foreach ($product->stock_warehouse[$entrepot_id]->detail_batch as $batchcursor => $prodbatch) {
392 if ((
string) $batch != (
string) $batchcursor) {
397 if ($prodbatch->qty < abs($qty)) $qtyisnotenough = $prodbatch->qty;
400 if (!$foundforbatch || $qtyisnotenough) {
401 $langs->load(
"stocks");
402 include_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
404 $tmpwarehouse->fetch($entrepot_id);
406 $this->error = $langs->trans(
'qtyToTranferLotIsNotEnough', $product->ref, $batch, $qtyisnotenough, $tmpwarehouse->ref);
407 $this->errors[] = $langs->trans(
'qtyToTranferLotIsNotEnough', $product->ref, $batch, $qtyisnotenough, $tmpwarehouse->ref);
408 $this->
db->rollback();
412 if (empty($product->stock_warehouse[$entrepot_id]->real) || $product->stock_warehouse[$entrepot_id]->real < abs($qty)) {
413 $langs->load(
"stocks");
414 $this->error = $langs->trans(
'qtyToTranferIsNotEnough').
' : '.$product->ref;
415 $this->errors[] = $langs->trans(
'qtyToTranferIsNotEnough').
' : '.$product->ref;
416 $this->
db->rollback();
424 $fk_project = $this->fk_project;
425 if (!empty($this->origin_type)) {
426 $origin_type = $this->origin_type;
427 $origin_id = $this->origin_id;
428 if (empty($fk_project) && $origin_type ==
'project') {
429 $fk_project = $origin_id;
439 $sql =
"INSERT INTO ".$this->db->prefix().
"stock_mouvement(";
440 $sql .=
" datem, fk_product, batch, eatby, sellby,";
441 $sql .=
" fk_entrepot, value, type_mouvement, fk_user_author, label, inventorycode, price, fk_origin, origintype, fk_projet";
443 $sql .=
" VALUES ('".$this->db->idate($this->datem).
"', ".((int) $this->product_id).
", ";
444 $sql .=
" ".($batch ?
"'".$this->db->escape($batch).
"'" :
"null").
", ";
445 $sql .=
" ".($eatby ?
"'".$this->db->idate($eatby).
"'" :
"null").
", ";
446 $sql .=
" ".($sellby ?
"'".$this->db->idate($sellby).
"'" :
"null").
", ";
447 $sql .=
" ".((int) $this->entrepot_id).
", ".((
float) $this->qty).
", ".((int) $this->
type).
",";
448 $sql .=
" ".((int) $user->id).
",";
449 $sql .=
" '".$this->db->escape($label).
"',";
450 $sql .=
" ".($inventorycode ?
"'".$this->db->escape($inventorycode).
"'" :
"null").
",";
451 $sql .=
" ".((float)
price2num($price)).
",";
452 $sql .=
" ".((int) $origin_id).
",";
453 $sql .=
" '".$this->db->escape($origin_type).
"',";
454 $sql .=
" ".((int) $fk_project);
457 dol_syslog(get_class($this).
"::_create insert record into stock_mouvement", LOG_DEBUG);
461 $mvid = $this->
db->last_insert_id($this->
db->prefix().
"stock_mouvement");
464 $this->error = $this->
db->lasterror();
465 $this->errors[] = $this->error;
470 $oldqty = $product->stock_reel;
471 $oldpmp = $product->pmp;
472 $oldqtywarehouse = 0;
477 $sql =
"SELECT rowid, reel FROM ".$this->db->prefix().
"product_stock";
478 $sql .=
" WHERE fk_entrepot = ".((int) $entrepot_id).
" AND fk_product = ".((int) $fk_product);
480 dol_syslog(get_class($this).
"::_create check if a record already exists in product_stock", LOG_DEBUG);
483 $obj = $this->
db->fetch_object(
$resql);
486 $oldqtywarehouse = $obj->reel;
487 $fk_product_stock = $obj->rowid;
491 $this->errors[] = $this->
db->lasterror();
499 if ($type == 0 || $type == 3) {
503 if ($price > 0 || (!empty($conf->global->STOCK_UPDATE_AWP_EVEN_WHEN_ENTRY_PRICE_IS_NULL) && $price == 0)) {
504 $oldqtytouse = ($oldqty >= 0 ? $oldqty : 0);
507 $newpmp =
price2num((($oldqtytouse * $oldpmp) + ($qty * $price)) / ($oldqtytouse + $qty),
'MU');
517 } elseif ($type == 1 || $type == 2) {
527 if ($alreadyarecord > 0) {
528 $sql =
"UPDATE ".$this->db->prefix().
"product_stock SET reel = reel + ".((
float) $qty);
529 $sql .=
" WHERE fk_entrepot = ".((int) $entrepot_id).
" AND fk_product = ".((int) $fk_product);
531 $sql =
"INSERT INTO ".$this->db->prefix().
"product_stock";
532 $sql .=
" (reel, fk_entrepot, fk_product) VALUES ";
533 $sql .=
" (".((float) $qty).
", ".((int) $entrepot_id).
", ".((int) $fk_product).
")";
536 dol_syslog(get_class($this).
"::_create update stock value", LOG_DEBUG);
539 $this->errors[] = $this->
db->lasterror();
541 } elseif (empty($fk_product_stock)) {
542 $fk_product_stock = $this->
db->last_insert_id($this->
db->prefix().
"product_stock");
547 if (!$error &&
isModEnabled(
'productbatch') && $product->hasbatch() && !$skip_batch) {
548 if ($id_product_batch > 0) {
549 $result = $this->
createBatch($id_product_batch, $qty);
551 $param_batch = array(
'fk_product_stock' =>$fk_product_stock,
'batchnumber'=>$batch);
566 $sql =
"UPDATE ".$this->db->prefix().
"product as p SET pmp = ".((
float) $newpmp).
",";
567 $sql .=
" stock=(SELECT SUM(ps.reel) FROM ".$this->db->prefix().
"product_stock as ps WHERE ps.fk_product = p.rowid)";
568 $sql .=
" WHERE rowid = ".((int) $fk_product);
570 dol_syslog(get_class($this).
"::_create update AWP", LOG_DEBUG);
573 $this->errors[] = $this->
db->lasterror();
578 if (empty($donotcleanemptylines)) {
581 $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)";
588 if (!$error && !empty($conf->global->PRODUIT_SOUSPRODUITS) && empty($conf->global->INDEPENDANT_SUBPRODUCT_STOCK) && empty($disablestockchangeforsubproduct)) {
589 $error = $this->
_createSubProduct($user, $fk_product, $entrepot_id, $qty, $type, 0, $label, $inventorycode, $datem);
592 if ($movestock && !$error) {
595 if ($result < 0) $error++;
599 if (!$error &&
isModEnabled(
'productbatch') && $product->hasbatch() && !$skip_batch) {
600 if ($product->status_batch == 2 && $qty > 0) {
603 $this->errors[] = $langs->trans(
"TooManyQtyForSerialNumber", $product->ref, $batch);
613 $this->
db->rollback();
614 dol_syslog(get_class($this).
"::_create error code=".$error, LOG_ERR);
636 $sql .=
" t.fk_product,";
637 $sql .=
" t.fk_entrepot,";
640 $sql .=
" t.type_mouvement,";
641 $sql .=
" t.fk_user_author,";
643 $sql .=
" t.fk_origin as origin_id,";
644 $sql .=
" t.origintype as origin_type,";
645 $sql .=
" t.inventorycode,";
648 $sql .=
" t.sellby,";
649 $sql .=
" t.fk_projet as fk_project";
650 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
651 $sql .=
" WHERE t.rowid = ".((int) $id);
655 $numrows = $this->
db->num_rows(
$resql);
657 $obj = $this->
db->fetch_object(
$resql);
659 $this->
id = $obj->rowid;
661 $this->product_id = $obj->fk_product;
662 $this->warehouse_id = $obj->fk_entrepot;
663 $this->qty = $obj->value;
664 $this->
type = $obj->type_mouvement;
666 $this->tms = $this->
db->jdate($obj->tms);
667 $this->datem = $this->
db->jdate($obj->datem);
668 $this->
price = $obj->price;
669 $this->fk_user_author = $obj->fk_user_author;
670 $this->label = $obj->label;
671 $this->fk_origin = $obj->origin_id;
672 $this->origintype = $obj->origin_type;
673 $this->origin_id = $obj->origin_id;
674 $this->origin_type = $obj->origin_type;
675 $this->inventorycode = $obj->inventorycode;
676 $this->batch = $obj->batch;
677 $this->eatby = $this->
db->jdate($obj->eatby);
678 $this->sellby = $this->
db->jdate($obj->sellby);
679 $this->fk_project = $obj->fk_project;
695 $this->errors[] =
'Error '.$this->db->lasterror();
696 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
719 private function _createSubProduct($user, $idProduct, $entrepot_id, $qty, $type, $price = 0, $label =
'', $inventorycode =
'', $datem =
'')
727 $sql =
"SELECT fk_product_pere, fk_product_fils, qty";
728 $sql .=
" FROM ".$this->db->prefix().
"product_association";
729 $sql .=
" WHERE fk_product_pere = ".((int) $idProduct);
730 $sql .=
" AND incdec = 1";
732 dol_syslog(get_class($this).
"::_createSubProduct for parent product ".$idProduct, LOG_DEBUG);
736 while ($obj = $this->
db->fetch_object(
$resql)) {
737 $pids[$i] = $obj->fk_product_fils;
738 $pqtys[$i] = $obj->qty;
747 foreach ($pids as $key => $value) {
751 $result = $tmpmove->_create($user, $pids[$key], $entrepot_id, ($qty * $pqtys[$key]), $type, 0, $label, $inventorycode, $datem);
753 $this->error = $tmpmove->error;
754 $this->errors = array_merge($this->errors, $tmpmove->errors);
756 $this->errors[] = $langs->trans(
"ErrorNoteAlsoThatSubProductCantBeFollowedByLot");
786 public function livraison($user, $fk_product, $entrepot_id, $qty, $price = 0, $label =
'', $datem =
'', $eatby =
'', $sellby =
'', $batch =
'', $id_product_batch = 0, $inventorycode =
'', $donotcleanemptylines = 0)
790 $skip_batch = empty($conf->productbatch->enabled);
792 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);
813 public function reception($user, $fk_product, $entrepot_id, $qty, $price = 0, $label =
'', $eatby =
'', $sellby =
'', $batch =
'', $datem =
'', $id_product_batch = 0, $inventorycode =
'', $donotcleanemptylines = 0)
817 $skip_batch = empty($conf->productbatch->enabled);
819 return $this->
_create($user, $fk_product, $entrepot_id, $qty, 3, $price, $label, $inventorycode, $datem, $eatby, $sellby, $batch, $skip_batch, $id_product_batch, 0, $donotcleanemptylines);
833 $sql =
"SELECT SUM(value) as nb from ".$this->db->prefix().
"stock_mouvement";
834 $sql .=
" WHERE fk_product = ".((int) $productidselected);
835 $sql .=
" AND datem < '".$this->db->idate($datebefore).
"'";
837 dol_syslog(get_class($this).__METHOD__, LOG_DEBUG);
840 $obj = $this->
db->fetch_object(
$resql);
841 if ($obj) $nb = $obj->nb;
842 return (empty($nb) ? 0 : $nb);
860 global $user, $langs;
862 $langs->load(
'productbatch');
869 if (is_numeric($dluo)) {
870 $result = $pdluo->fetch($dluo);
871 if (empty($pdluo->id)) {
873 $this->error = $langs->trans(
'CantMoveNonExistantSerial');
874 $this->errors[] = $this->error;
877 } elseif (is_array($dluo)) {
878 if (isset($dluo[
'fk_product_stock'])) {
879 $vfk_product_stock = $dluo[
'fk_product_stock'];
880 $vbatchnumber = $dluo[
'batchnumber'];
882 $result = $pdluo->find($vfk_product_stock,
'',
'', $vbatchnumber);
884 dol_syslog(get_class($this).
"::createBatch array param dluo must contain at least key fk_product_stock", LOG_ERR);
888 dol_syslog(get_class($this).
"::createBatch error invalid param dluo", LOG_ERR);
894 if ($pdluo->id > 0) {
897 if ($pdluo->qty == 0) {
898 $result = $pdluo->delete($user, 1);
900 $result = $pdluo->update($user, 1);
903 $pdluo->fk_product_stock = $vfk_product_stock;
905 $pdluo->eatby = empty($dluo[
'eatby']) ?
'' : $dluo[
'eatby'];
906 $pdluo->sellby = empty($dluo[
'sellby']) ?
'' : $dluo[
'sellby'];
907 $pdluo->batch = $vbatchnumber;
909 $result = $pdluo->create($user, 1);
911 $this->error = $pdluo->error;
912 $this->errors = $pdluo->errors;
933 switch ($origin_type) {
935 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
939 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
943 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
946 case 'order_supplier':
947 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
950 case 'invoice_supplier':
951 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
955 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
959 require_once DOL_DOCUMENT_ROOT.
'/mrp/class/mo.class.php';
960 $origin =
new Mo($this->
db);
963 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
964 $origin =
new User($this->
db);
967 require_once DOL_DOCUMENT_ROOT.
'/reception/class/reception.class.php';
971 require_once DOL_DOCUMENT_ROOT.
'/product/inventory/class/inventory.class.php';
978 $origin_type_array = explode(
'@', $origin_type);
979 $classname = ucfirst($origin_type_array[0]);
980 $modulename = empty($origin_type_array[1]) ? strtolower($classname) : $origin_type_array[1];
981 $result =
dol_include_once(
'/'.$modulename.
'/class/'.strtolower($classname).
'.class.php');
983 $origin =
new $classname($this->
db);
989 if (empty($origin) || !is_object($origin)) {
993 if ($origin->fetch($origin_id) > 0) {
994 return $origin->getNomUrl(1);
1010 $this->origin_type = $origin_element;
1011 $this->origin_id = $origin_id;
1013 $this->origintype = $origin_element;
1014 $this->fk_origin = $origin_id;
1027 global $user, $langs, $conf, $mysoc;
1046 switch ($this->
type) {
1048 $s =
'<span class="fa fa-level-down-alt stockmovemententry stockmovementtransfer" title="'.$langs->trans(
'StockIncreaseAfterCorrectTransfer').
'"></span>';
1050 $s .= $langs->trans(
'StockIncreaseAfterCorrectTransfer');
1054 $s =
'<span class="fa fa-level-up-alt stockmovementexit stockmovementtransfer" title="'.$langs->trans(
'StockDecreaseAfterCorrectTransfer').
'"></span>';
1056 $s .= $langs->trans(
'StockDecreaseAfterCorrectTransfer');
1060 $s =
'<span class="fa fa-long-arrow-alt-up stockmovementexit stockmovement" title="'.$langs->trans(
'StockDecrease').
'"></span>';
1062 $s .= $langs->trans(
'StockDecrease');
1066 $s =
'<span class="fa fa-long-arrow-alt-down stockmovemententry stockmovement" title="'.$langs->trans(
'StockIncrease').
'"></span>';
1068 $s .= $langs->trans(
'StockIncrease');
1087 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'')
1089 global $langs, $conf, $db;
1093 $label =
img_picto(
'',
'stock',
'class="pictofixedwidth"').
'<u>'.$langs->trans(
"Movement").
' '.$this->
id.
'</u>';
1094 $label .=
'<div width="100%">';
1095 $label .=
'<b>'.$langs->trans(
'Label').
':</b> '.$this->label;
1096 $label .=
'<br><b>'.$langs->trans(
'Qty').
':</b> '.($this->qty > 0 ?
'+' :
'').$this->qty;
1098 $label .=
'<br><b>'.$langs->trans(
'Batch').
':</b> '.$this->batch;
1107 if ($option ==
'movements') {
1108 $url = DOL_URL_ROOT.
'/product/stock/movement_list.php?search_ref='.$this->id;
1110 $url = DOL_URL_ROOT.
'/product/stock/movement_list.php?id='.$this->warehouse_id.
'&msid='.$this->id;
1113 $link =
'<a href="'.$url.
'"'.($notooltip ?
'' :
' title="'.dol_escape_htmltag($label, 1).
'" class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"');
1118 $result .= ($link.img_object(($notooltip ?
'' : $label),
'stock', ($notooltip ?
'' :
'class="classfortooltip"')).$linkend);
1119 if ($withpicto != 2) {
1123 $result .= $link.$this->id.$linkend;
1150 if ($mode == 0 || $mode == 1) {
1151 return $langs->trans(
'StatusNotApplicable');
1152 } elseif ($mode == 2) {
1153 return img_picto($langs->trans(
'StatusNotApplicable'),
'statut9').
' '.$langs->trans(
'StatusNotApplicable');
1154 } elseif ($mode == 3) {
1155 return img_picto($langs->trans(
'StatusNotApplicable'),
'statut9');
1156 } elseif ($mode == 4) {
1157 return img_picto($langs->trans(
'StatusNotApplicable'),
'statut9').
' '.$langs->trans(
'StatusNotApplicable');
1158 } elseif ($mode == 5) {
1159 return $langs->trans(
'StatusNotApplicable').
' '.
img_picto($langs->trans(
'StatusNotApplicable'),
'statut9');
1173 public function generateDocument($modele, $outputlangs =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1175 global $conf, $user, $langs;
1177 $langs->load(
"stocks");
1178 $outputlangs->load(
"products");
1181 $modele =
'stdmovement';
1183 if ($this->model_pdf) {
1184 $modele = $this->model_pdf;
1185 } elseif (!empty($conf->global->MOUVEMENT_ADDON_PDF)) {
1186 $modele = $conf->global->MOUVEMENT_ADDON_PDF;
1190 $modelpath =
"core/modules/stock/doc/";
1192 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1202 public function delete(
User $user, $notrigger =
false)
1219 $sql =
"SELECT sum(pb.qty) as cpt";
1220 $sql .=
" FROM ".$this->db->prefix().
"product_batch as pb";
1221 $sql .=
" INNER JOIN ".$this->db->prefix().
"product_stock as ps ON ps.rowid = pb.fk_product_stock";
1222 $sql .=
" WHERE ps.fk_product = " . ((int) $fk_product);
1223 $sql .=
" AND pb.batch = '" . $this->
db->escape($batch) .
"'";
1225 $result = $this->
db->query($sql);
1227 if ($this->
db->num_rows($result)) {
1228 $obj = $this->
db->fetch_object($result);
1232 $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.
deleteCommon(User $user, $notrigger=false, $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.
getNomUrl($withpicto=0, $option='', $notooltip=0, $maxlen=24, $morecss='')
Return a link (with optionaly the picto) Use this->id,this->lastname, this->firstname.
generateDocument($modele, $outputlangs='', $hidedetails=0, $hidedesc=0, $hideref=0)
Create object on disk.
LibStatut($mode=0)
Renvoi le libelle d'un status donne.
createBatch($dluo, $qty)
Create or update batch record (update table llx_product_batch).
getBatchCount($fk_product, $batch)
Retrieve number of equipments 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.
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.
_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)
Add a movement of stock (in one direction only).
initAsSpecimen()
Initialise an instance with random values.
getTypeMovement($withlabel=0)
Return html string with picto for type of movement.
setOrigin($origin_element, $origin_id)
Set attribute origin_type and fk_origin to object.
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 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('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
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
$conf db
API class for accounts.