36 public $element =
'stockmouvement';
41 public $table_element =
'stock_mouvement';
80 public $fk_user_author;
112 public $inventorycode;
115 public $line_id_object_src;
116 public $line_id_object_origin;
119 public $fields = array(
120 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10,
'showoncombobox'=>1),
121 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>15),
122 'datem' =>array(
'type'=>
'datetime',
'label'=>
'Datem',
'enabled'=>1,
'visible'=>-1,
'position'=>20),
123 'fk_product' =>array(
'type'=>
'integer:Product:product/class/product.class.php:1',
'label'=>
'Product',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>25),
124 'fk_entrepot' =>array(
'type'=>
'integer:Entrepot:product/stock/class/entrepot.class.php',
'label'=>
'Warehouse',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>30),
125 'value' =>array(
'type'=>
'double',
'label'=>
'Value',
'enabled'=>1,
'visible'=>-1,
'position'=>35),
126 'price' =>array(
'type'=>
'double(24,8)',
'label'=>
'Price',
'enabled'=>1,
'visible'=>-1,
'position'=>40),
127 'type_mouvement' =>array(
'type'=>
'smallint(6)',
'label'=>
'Type mouvement',
'enabled'=>1,
'visible'=>-1,
'position'=>45),
128 'fk_user_author' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'Fk user author',
'enabled'=>1,
'visible'=>-1,
'position'=>50),
129 'label' =>array(
'type'=>
'varchar(255)',
'label'=>
'Label',
'enabled'=>1,
'visible'=>-1,
'position'=>55),
130 'fk_origin' =>array(
'type'=>
'integer',
'label'=>
'Fk origin',
'enabled'=>1,
'visible'=>-1,
'position'=>60),
131 'origintype' =>array(
'type'=>
'varchar(32)',
'label'=>
'Origintype',
'enabled'=>1,
'visible'=>-1,
'position'=>65),
132 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'Model pdf',
'enabled'=>1,
'visible'=>0,
'position'=>70),
133 '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),
134 'inventorycode' =>array(
'type'=>
'varchar(128)',
'label'=>
'InventoryCode',
'enabled'=>1,
'visible'=>-1,
'position'=>80),
135 'batch' =>array(
'type'=>
'varchar(30)',
'label'=>
'Batch',
'enabled'=>1,
'visible'=>-1,
'position'=>85),
136 'eatby' =>array(
'type'=>
'date',
'label'=>
'Eatby',
'enabled'=>1,
'visible'=>-1,
'position'=>90),
137 'sellby' =>array(
'type'=>
'date',
'label'=>
'Sellby',
'enabled'=>1,
'visible'=>-1,
'position'=>95),
138 'fk_project' =>array(
'type'=>
'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)',
'label'=>
'Fk project',
'enabled'=>1,
'visible'=>-1,
'position'=>100),
180 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)
183 global $conf, $langs;
185 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
186 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/productlot.class.php';
189 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);
192 global $action, $hookmanager;
193 $hookmanager->initHooks(array(
'mouvementstock'));
195 if (is_object($hookmanager)) {
197 'currentcontext' =>
'mouvementstock',
199 'fk_product' => &$fk_product,
200 'entrepot_id' => &$entrepot_id,
205 'inventorycode' => &$inventorycode,
208 'sellby' => &$sellby,
210 'skip_batch' => &$skip_batch,
211 'id_product_batch' => &$id_product_batch
213 $reshook = $hookmanager->executeHooks(
'stockMovementCreate', $parameters, $this, $action);
216 if (!empty($hookmanager->resPrint)) {
220 } elseif ($reshook > 0) {
221 return $hookmanager->resPrint;
228 if (empty($price)) $price = 0;
229 $now = (!empty($datem) ? $datem :
dol_now());
232 if (!($fk_product > 0))
return 0;
233 if (!($entrepot_id > 0))
return 0;
235 if (is_numeric($eatby) && $eatby < 0) {
236 dol_syslog(get_class($this).
"::_create start ErrorBadValueForParameterEatBy eatby = ".$eatby);
237 $this->errors[] =
'ErrorBadValueForParameterEatBy';
240 if (is_numeric($sellby) && $sellby < 0) {
241 dol_syslog(get_class($this).
"::_create start ErrorBadValueForParameterSellBy sellby = ".$sellby);
242 $this->errors[] =
'ErrorBadValueForParameterSellBy';
247 $this->product_id = $fk_product;
248 $this->entrepot_id = $entrepot_id;
249 $this->warehouse_id = $entrepot_id;
253 $this->label = $label;
254 $this->inventorycode = $inventorycode;
256 $this->batch = $batch;
260 $product =
new Product($this->db);
262 $result = $product->fetch($fk_product);
264 $this->error = $product->error;
265 $this->errors = $product->errors;
269 if ($product->id <= 0) {
276 if ($product->type !=
Product::TYPE_SERVICE || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) $movestock = 1;
282 $product->load_stock(
'novirtual');
286 if (
isModEnabled(
'productbatch') && $product->hasbatch() && !$skip_batch) {
288 $langs->load(
"errors");
289 $this->errors[] = $langs->transnoentitiesnoconv(
"ErrorTryToMakeMoveOnProductRequiringBatchData", $product->ref);
290 dol_syslog(
"Try to make a movement of a product with status_batch on without any batch data");
292 $this->db->rollback();
302 $sql =
"SELECT pb.rowid, pb.batch, pb.eatby, pb.sellby FROM ".$this->db->prefix().
"product_lot as pb";
303 $sql .=
" WHERE pb.fk_product = ".((int) $fk_product).
" AND pb.batch = '".$this->db->escape($batch).
"'";
305 dol_syslog(get_class($this).
"::_create scan serial for this product to check if eatby and sellby match", LOG_DEBUG);
307 $resql = $this->db->query(
$sql);
309 $num = $this->db->num_rows($resql);
313 $obj = $this->db->fetch_object($resql);
317 $eatbywithouthour =
dol_mktime(0, 0, 0, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year']);
318 if ($this->db->jdate($obj->eatby) != $eatby && $this->db->jdate($obj->eatby) != $eatbywithouthour) {
320 $langs->load(
"stocks");
321 $this->errors[] = $langs->transnoentitiesnoconv(
"ThisSerialAlreadyExistWithDifferentDate", $batch,
dol_print_date($this->db->jdate($obj->eatby),
'dayhour'),
dol_print_date($eatbywithouthour,
'dayhour'));
322 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);
323 $this->db->rollback();
327 $eatby = $obj->eatby;
332 $result = $productlot->fetch($obj->rowid);
333 $productlot->eatby = $eatby;
334 $result = $productlot->update($user);
336 $this->error = $productlot->error;
337 $this->errors = $productlot->errors;
338 $this->db->rollback();
346 $sellbywithouthour =
dol_mktime(0, 0, 0, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year']);
347 if ($this->db->jdate($obj->sellby) != $sellby && $this->db->jdate($obj->sellby) != $sellbywithouthour) {
349 $this->errors[] = $langs->transnoentitiesnoconv(
"ThisSerialAlreadyExistWithDifferentDate", $batch,
dol_print_date($this->db->jdate($obj->sellby)),
dol_print_date($sellby));
351 $this->db->rollback();
355 $sellby = $obj->sellby;
360 $result = $productlot->fetch($obj->rowid);
361 $productlot->sellby = $sellby;
362 $result = $productlot->update($user);
364 $this->error = $productlot->error;
365 $this->errors = $productlot->errors;
366 $this->db->rollback();
376 $productlot->origin = !empty($this->origin) ? (empty($this->origin->origin_type) ? $this->origin->element : $this->origin->origin_type) :
'';
377 $productlot->origin_id = !empty($this->origin) ? $this->origin->id : 0;
378 $productlot->entity = $conf->entity;
379 $productlot->fk_product = $fk_product;
380 $productlot->batch = $batch;
382 $productlot->eatby = $eatby;
383 $productlot->sellby = $sellby;
384 $result = $productlot->create($user);
386 $this->error = $productlot->error;
387 $this->errors = $productlot->errors;
388 $this->db->rollback();
394 $this->db->rollback();
401 if ($movestock && $qty < 0 && !
getDolGlobalInt(
'STOCK_ALLOW_NEGATIVE_TRANSFER')) {
402 if (
isModEnabled(
'productbatch') && $product->hasbatch() && !$skip_batch) {
406 foreach ($product->stock_warehouse[$entrepot_id]->detail_batch as $batchcursor => $prodbatch) {
407 if ((
string) $batch != (
string) $batchcursor) {
412 if ($prodbatch->qty < abs($qty)) $qtyisnotenough = $prodbatch->qty;
415 if (!$foundforbatch || $qtyisnotenough) {
416 $langs->load(
"stocks");
417 include_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
418 $tmpwarehouse =
new Entrepot($this->db);
419 $tmpwarehouse->fetch($entrepot_id);
421 $this->error = $langs->trans(
'qtyToTranferLotIsNotEnough', $product->ref, $batch, $qtyisnotenough, $tmpwarehouse->ref);
422 $this->errors[] = $langs->trans(
'qtyToTranferLotIsNotEnough', $product->ref, $batch, $qtyisnotenough, $tmpwarehouse->ref);
423 $this->db->rollback();
427 if (empty($product->stock_warehouse[$entrepot_id]->real) || $product->stock_warehouse[$entrepot_id]->real < abs($qty)) {
428 $langs->load(
"stocks");
429 $this->error = $langs->trans(
'qtyToTranferIsNotEnough').
' : '.$product->ref;
430 $this->errors[] = $langs->trans(
'qtyToTranferIsNotEnough').
' : '.$product->ref;
431 $this->db->rollback();
439 $fk_project = $this->fk_project;
440 if (!empty($this->origin_type)) {
441 $origin_type = $this->origin_type;
442 $origin_id = $this->origin_id;
443 if (empty($fk_project) && $origin_type ==
'project') {
444 $fk_project = $origin_id;
454 $sql =
"INSERT INTO ".$this->db->prefix().
"stock_mouvement(";
455 $sql .=
" datem, fk_product, batch, eatby, sellby,";
456 $sql .=
" fk_entrepot, value, type_mouvement, fk_user_author, label, inventorycode, price, fk_origin, origintype, fk_projet";
458 $sql .=
" VALUES ('".$this->db->idate($this->datem).
"', ".((int) $this->product_id).
", ";
459 $sql .=
" ".($batch ?
"'".$this->db->escape($batch).
"'" :
"null").
", ";
460 $sql .=
" ".($eatby ?
"'".$this->db->idate($eatby).
"'" :
"null").
", ";
461 $sql .=
" ".($sellby ?
"'".$this->db->idate($sellby).
"'" :
"null").
", ";
462 $sql .=
" ".((int) $this->entrepot_id).
", ".((
float) $this->qty).
", ".((int) $this->
type).
",";
463 $sql .=
" ".((int) $user->id).
",";
464 $sql .=
" '".$this->db->escape($label).
"',";
465 $sql .=
" ".($inventorycode ?
"'".$this->db->escape($inventorycode).
"'" :
"null").
",";
467 $sql .=
" ".((int) $origin_id).
",";
468 $sql .=
" '".$this->db->escape($origin_type).
"',";
469 $sql .=
" ".((int) $fk_project);
472 dol_syslog(get_class($this).
"::_create insert record into stock_mouvement", LOG_DEBUG);
473 $resql = $this->db->query(
$sql);
476 $mvid = $this->db->last_insert_id($this->db->prefix().
"stock_mouvement");
479 $this->error = $this->db->lasterror();
480 $this->errors[] = $this->error;
485 $oldqty = $product->stock_reel;
486 $oldpmp = $product->pmp;
487 $oldqtywarehouse = 0;
492 $sql =
"SELECT rowid, reel FROM ".$this->db->prefix().
"product_stock";
493 $sql .=
" WHERE fk_entrepot = ".((int) $entrepot_id).
" AND fk_product = ".((int) $fk_product);
495 dol_syslog(get_class($this).
"::_create check if a record already exists in product_stock", LOG_DEBUG);
496 $resql = $this->db->query(
$sql);
498 $obj = $this->db->fetch_object($resql);
501 $oldqtywarehouse = $obj->reel;
502 $fk_product_stock = $obj->rowid;
504 $this->db->free($resql);
506 $this->errors[] = $this->db->lasterror();
514 if ($type == 0 || $type == 3) {
518 if ($price > 0 || (!empty($conf->global->STOCK_UPDATE_AWP_EVEN_WHEN_ENTRY_PRICE_IS_NULL) && $price == 0)) {
519 $oldqtytouse = ($oldqty >= 0 ? $oldqty : 0);
522 $newpmp =
price2num((($oldqtytouse * $oldpmp) + ($qty * $price)) / ($oldqtytouse + $qty),
'MU');
532 } elseif ($type == 1 || $type == 2) {
542 if ($alreadyarecord > 0) {
543 $sql =
"UPDATE ".$this->db->prefix().
"product_stock SET reel = reel + ".((
float) $qty);
544 $sql .=
" WHERE fk_entrepot = ".((int) $entrepot_id).
" AND fk_product = ".((int) $fk_product);
546 $sql =
"INSERT INTO ".$this->db->prefix().
"product_stock";
547 $sql .=
" (reel, fk_entrepot, fk_product) VALUES ";
548 $sql .=
" (".((float) $qty).
", ".((int) $entrepot_id).
", ".((int) $fk_product).
")";
551 dol_syslog(get_class($this).
"::_create update stock value", LOG_DEBUG);
552 $resql = $this->db->query(
$sql);
554 $this->errors[] = $this->db->lasterror();
556 } elseif (empty($fk_product_stock)) {
557 $fk_product_stock = $this->db->last_insert_id($this->db->prefix().
"product_stock");
562 if (!$error &&
isModEnabled(
'productbatch') && $product->hasbatch() && !$skip_batch) {
563 if ($id_product_batch > 0) {
564 $result = $this->
createBatch($id_product_batch, $qty);
565 if ($result == -2 && $fk_product_stock > 0) {
566 $param_batch = array(
'fk_product_stock' =>$fk_product_stock,
'batchnumber'=>$batch);
570 $param_batch = array(
'fk_product_stock' =>$fk_product_stock,
'batchnumber'=>$batch);
585 $sql =
"UPDATE ".$this->db->prefix().
"product as p SET pmp = ".((
float) $newpmp).
",";
586 $sql .=
" stock=(SELECT SUM(ps.reel) FROM ".$this->db->prefix().
"product_stock as ps WHERE ps.fk_product = p.rowid)";
587 $sql .=
" WHERE rowid = ".((int) $fk_product);
589 dol_syslog(get_class($this).
"::_create update AWP", LOG_DEBUG);
590 $resql = $this->db->query(
$sql);
592 $this->errors[] = $this->db->lasterror();
597 if (empty($donotcleanemptylines)) {
600 $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)";
601 $resql = $this->db->query(
$sql);
607 if (!$error && !empty($conf->global->PRODUIT_SOUSPRODUITS) && empty($conf->global->INDEPENDANT_SUBPRODUCT_STOCK) && empty($disablestockchangeforsubproduct)) {
608 $error = $this->
_createSubProduct($user, $fk_product, $entrepot_id, $qty, $type, 0, $label, $inventorycode, $datem);
611 if ($movestock && !$error) {
614 if ($result < 0) $error++;
618 if (!$error &&
isModEnabled(
'productbatch') && $product->hasbatch() && !$skip_batch) {
619 if ($product->status_batch == 2 && $qty > 0) {
622 $this->errors[] = $langs->trans(
"TooManyQtyForSerialNumber", $product->ref, $batch);
632 $this->db->rollback();
633 dol_syslog(get_class($this).
"::_create error code=".$error, LOG_ERR);
655 $sql .=
" t.fk_product,";
656 $sql .=
" t.fk_entrepot,";
659 $sql .=
" t.type_mouvement,";
660 $sql .=
" t.fk_user_author,";
662 $sql .=
" t.fk_origin as origin_id,";
663 $sql .=
" t.origintype as origin_type,";
664 $sql .=
" t.inventorycode,";
667 $sql .=
" t.sellby,";
668 $sql .=
" t.fk_projet as fk_project";
669 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
670 $sql .=
" WHERE t.rowid = ".((int) $id);
672 $resql = $this->db->query(
$sql);
674 $numrows = $this->db->num_rows($resql);
676 $obj = $this->db->fetch_object($resql);
678 $this->
id = $obj->rowid;
680 $this->product_id = $obj->fk_product;
681 $this->warehouse_id = $obj->fk_entrepot;
682 $this->qty = $obj->value;
683 $this->
type = $obj->type_mouvement;
685 $this->tms = $this->db->jdate($obj->tms);
686 $this->datem = $this->db->jdate($obj->datem);
687 $this->
price = $obj->price;
688 $this->fk_user_author = $obj->fk_user_author;
689 $this->label = $obj->label;
690 $this->fk_origin = $obj->origin_id;
691 $this->origintype = $obj->origin_type;
692 $this->origin_id = $obj->origin_id;
693 $this->origin_type = $obj->origin_type;
694 $this->inventorycode = $obj->inventorycode;
695 $this->batch = $obj->batch;
696 $this->eatby = $this->db->jdate($obj->eatby);
697 $this->sellby = $this->db->jdate($obj->sellby);
698 $this->fk_project = $obj->fk_project;
706 $this->db->free($resql);
714 $this->errors[] =
'Error '.$this->db->lasterror();
715 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
738 private function _createSubProduct($user, $idProduct, $entrepot_id, $qty, $type, $price = 0, $label =
'', $inventorycode =
'', $datem =
'')
746 $sql =
"SELECT fk_product_pere, fk_product_fils, qty";
747 $sql .=
" FROM ".$this->db->prefix().
"product_association";
748 $sql .=
" WHERE fk_product_pere = ".((int) $idProduct);
749 $sql .=
" AND incdec = 1";
751 dol_syslog(get_class($this).
"::_createSubProduct for parent product ".$idProduct, LOG_DEBUG);
752 $resql = $this->db->query(
$sql);
755 while ($obj = $this->db->fetch_object($resql)) {
756 $pids[$i] = $obj->fk_product_fils;
757 $pqtys[$i] = $obj->qty;
760 $this->db->free($resql);
766 foreach ($pids as $key => $value) {
770 $result = $tmpmove->_create($user, $pids[$key], $entrepot_id, ($qty * $pqtys[$key]), $type, 0, $label, $inventorycode, $datem);
772 $this->error = $tmpmove->error;
773 $this->errors = array_merge($this->errors, $tmpmove->errors);
775 $this->errors[] = $langs->trans(
"ErrorNoteAlsoThatSubProductCantBeFollowedByLot");
805 public function livraison($user, $fk_product, $entrepot_id, $qty, $price = 0, $label =
'', $datem =
'', $eatby =
'', $sellby =
'', $batch =
'', $id_product_batch = 0, $inventorycode =
'', $donotcleanemptylines = 0)
809 $skip_batch = empty($conf->productbatch->enabled);
811 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);
832 public function reception($user, $fk_product, $entrepot_id, $qty, $price = 0, $label =
'', $eatby =
'', $sellby =
'', $batch =
'', $datem =
'', $id_product_batch = 0, $inventorycode =
'', $donotcleanemptylines = 0)
836 $skip_batch = empty($conf->productbatch->enabled);
838 return $this->
_create($user, $fk_product, $entrepot_id, $qty, 3, $price, $label, $inventorycode, $datem, $eatby, $sellby, $batch, $skip_batch, $id_product_batch, 0, $donotcleanemptylines);
852 $sql =
"SELECT SUM(value) as nb from ".$this->db->prefix().
"stock_mouvement";
853 $sql .=
" WHERE fk_product = ".((int) $productidselected);
854 $sql .=
" AND datem < '".$this->db->idate($datebefore).
"'";
856 dol_syslog(get_class($this).__METHOD__, LOG_DEBUG);
857 $resql = $this->db->query(
$sql);
859 $obj = $this->db->fetch_object($resql);
860 if ($obj) $nb = $obj->nb;
861 return (empty($nb) ? 0 : $nb);
879 global $user, $langs;
881 $langs->load(
'productbatch');
888 if (is_numeric($dluo)) {
889 $result = $pdluo->fetch($dluo);
890 if (empty($pdluo->id)) {
892 $this->error = $langs->trans(
'CantMoveNonExistantSerial');
893 $this->errors[] = $this->error;
896 } elseif (is_array($dluo)) {
897 if (isset($dluo[
'fk_product_stock'])) {
898 $vfk_product_stock = $dluo[
'fk_product_stock'];
899 $vbatchnumber = $dluo[
'batchnumber'];
901 $result = $pdluo->find($vfk_product_stock,
'',
'', $vbatchnumber);
903 dol_syslog(get_class($this).
"::createBatch array param dluo must contain at least key fk_product_stock", LOG_ERR);
907 dol_syslog(get_class($this).
"::createBatch error invalid param dluo", LOG_ERR);
913 if ($pdluo->id > 0) {
916 if ($pdluo->qty == 0) {
917 $result = $pdluo->delete($user, 1);
919 $result = $pdluo->update($user, 1);
922 $pdluo->fk_product_stock = $vfk_product_stock;
924 $pdluo->eatby = empty($dluo[
'eatby']) ?
'' : $dluo[
'eatby'];
925 $pdluo->sellby = empty($dluo[
'sellby']) ?
'' : $dluo[
'sellby'];
926 $pdluo->batch = $vbatchnumber;
928 $result = $pdluo->create($user, 1);
930 $this->error = $pdluo->error;
931 $this->errors = $pdluo->errors;
952 switch ($origin_type) {
954 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
958 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
962 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
963 $origin =
new Facture($this->db);
965 case 'order_supplier':
966 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
969 case 'invoice_supplier':
970 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
974 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
975 $origin =
new Project($this->db);
978 require_once DOL_DOCUMENT_ROOT.
'/mrp/class/mo.class.php';
979 $origin =
new Mo($this->db);
982 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
983 $origin =
new User($this->db);
986 require_once DOL_DOCUMENT_ROOT.
'/reception/class/reception.class.php';
990 require_once DOL_DOCUMENT_ROOT.
'/product/inventory/class/inventory.class.php';
997 $origin_type_array = explode(
'@', $origin_type);
998 $classname = ucfirst($origin_type_array[0]);
999 $modulename = empty($origin_type_array[1]) ? strtolower($classname) : $origin_type_array[1];
1000 $result =
dol_include_once(
'/'.$modulename.
'/class/'.strtolower($classname).
'.class.php');
1002 $origin =
new $classname($this->db);
1008 if (empty($origin) || !is_object($origin)) {
1012 if ($origin->fetch($origin_id) > 0) {
1013 return $origin->getNomUrl(1);
1029 public function setOrigin($origin_element, $origin_id, $line_id_object_src = 0, $line_id_object_origin = 0)
1031 $this->origin_type = $origin_element;
1032 $this->origin_id = $origin_id;
1033 $this->line_id_oject_src = $line_id_object_src;
1034 $this->line_id_oject_origin = $line_id_object_origin;
1036 $this->origintype = $origin_element;
1037 $this->fk_origin = $origin_id;
1050 global $user, $langs, $conf, $mysoc;
1069 switch ($this->
type) {
1071 $s =
'<span class="fa fa-level-down-alt stockmovemententry stockmovementtransfer" title="'.$langs->trans(
'StockIncreaseAfterCorrectTransfer').
'"></span>';
1073 $s .= $langs->trans(
'StockIncreaseAfterCorrectTransfer');
1077 $s =
'<span class="fa fa-level-up-alt stockmovementexit stockmovementtransfer" title="'.$langs->trans(
'StockDecreaseAfterCorrectTransfer').
'"></span>';
1079 $s .= $langs->trans(
'StockDecreaseAfterCorrectTransfer');
1083 $s =
'<span class="fa fa-long-arrow-alt-up stockmovementexit stockmovement" title="'.$langs->trans(
'StockDecrease').
'"></span>';
1085 $s .= $langs->trans(
'StockDecrease');
1089 $s =
'<span class="fa fa-long-arrow-alt-down stockmovemententry stockmovement" title="'.$langs->trans(
'StockIncrease').
'"></span>';
1091 $s .= $langs->trans(
'StockIncrease');
1110 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'')
1112 global $langs, $conf, $db;
1116 $label =
img_picto(
'',
'stock',
'class="pictofixedwidth"').
'<u>'.$langs->trans(
"Movement").
' '.$this->
id.
'</u>';
1117 $label .=
'<div width="100%">';
1118 $label .=
'<b>'.$langs->trans(
'Label').
':</b> '.$this->label;
1119 $label .=
'<br><b>'.$langs->trans(
'Qty').
':</b> '.($this->qty > 0 ?
'+' :
'').$this->qty;
1121 $label .=
'<br><b>'.$langs->trans(
'Batch').
':</b> '.$this->batch;
1130 if ($option ==
'movements') {
1131 $url = DOL_URL_ROOT.
'/product/stock/movement_list.php?search_ref='.$this->id;
1133 $url = DOL_URL_ROOT.
'/product/stock/movement_list.php?id='.$this->warehouse_id.
'&msid='.$this->id;
1136 $link =
'<a href="'.$url.
'"'.($notooltip ?
'' :
' title="'.dol_escape_htmltag($label, 1).
'" class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"');
1141 $result .= ($link.img_object(($notooltip ?
'' : $label),
'stock', ($notooltip ?
'' :
'class="classfortooltip"')).$linkend);
1142 if ($withpicto != 2) {
1146 $result .= $link.$this->id.$linkend;
1173 if ($mode == 0 || $mode == 1) {
1174 return $langs->trans(
'StatusNotApplicable');
1175 } elseif ($mode == 2) {
1176 return img_picto($langs->trans(
'StatusNotApplicable'),
'statut9').
' '.$langs->trans(
'StatusNotApplicable');
1177 } elseif ($mode == 3) {
1178 return img_picto($langs->trans(
'StatusNotApplicable'),
'statut9');
1179 } elseif ($mode == 4) {
1180 return img_picto($langs->trans(
'StatusNotApplicable'),
'statut9').
' '.$langs->trans(
'StatusNotApplicable');
1181 } elseif ($mode == 5) {
1182 return $langs->trans(
'StatusNotApplicable').
' '.
img_picto($langs->trans(
'StatusNotApplicable'),
'statut9');
1196 public function generateDocument($modele, $outputlangs =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1198 global $conf, $user, $langs;
1200 $langs->load(
"stocks");
1201 $outputlangs->load(
"products");
1204 $modele =
'stdmovement';
1206 if ($this->model_pdf) {
1207 $modele = $this->model_pdf;
1208 } elseif (!empty($conf->global->MOUVEMENT_ADDON_PDF)) {
1209 $modele = $conf->global->MOUVEMENT_ADDON_PDF;
1213 $modelpath =
"core/modules/stock/doc/";
1215 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1225 public function delete(
User $user, $notrigger =
false)
1242 $sql =
"SELECT sum(pb.qty) as cpt";
1243 $sql .=
" FROM ".$this->db->prefix().
"product_batch as pb";
1244 $sql .=
" INNER JOIN ".$this->db->prefix().
"product_stock as ps ON ps.rowid = pb.fk_product_stock";
1245 $sql .=
" WHERE ps.fk_product = " . ((int) $fk_product);
1246 $sql .=
" AND pb.batch = '" . $this->db->escape($batch) .
"'";
1248 $result = $this->db->query(
$sql);
1250 if ($this->db->num_rows($result)) {
1251 $obj = $this->db->fetch_object($result);
1255 $this->db->free($result);