23 if (!defined(
'NOTOKENRENEWAL')) {
24 define(
'NOTOKENRENEWAL', 1);
26 if (!defined(
'NOREQUIREMENU')) {
27 define(
'NOREQUIREMENU',
'1');
29 if (!defined(
'NOREQUIREHTML')) {
30 define(
'NOREQUIREHTML',
'1');
32 if (!defined(
'NOREQUIREAJAX')) {
33 define(
'NOREQUIREAJAX',
'1');
35 if (!defined(
'NOREQUIRESOC')) {
36 define(
'NOREQUIRESOC',
'1');
38 if (!defined(
'NOCSRFCHECK')) {
39 define(
'NOCSRFCHECK',
'1');
41 require
'../../../main.inc.php';
42 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/entrepot.class.php";
45 $action =
GETPOST(
"action",
"alpha");
46 $barcode =
GETPOST(
"barcode",
"aZ09");
50 $fk_entrepot =
GETPOST(
"fk_entrepot",
"int");
51 $fk_inventory =
GETPOST(
"fk_inventory",
"int");
52 $fk_product =
GETPOST(
"fk_product",
"int");
53 $reelqty =
GETPOST(
"reelqty",
"int");
54 $batch =
GETPOST(
"batch",
"int");
59 $objectreturn = array();
61 if ($action ==
"existbarcode" && !empty($barcode)) {
62 if (!empty($mode) && $mode ==
"lotserial") {
63 $sql =
"SELECT ps.fk_entrepot, ps.fk_product, p.barcode, ps.reel, pb.batch";
64 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_batch as pb";
65 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"product_stock as ps ON pb.fk_product_stock = ps.rowid JOIN ".MAIN_DB_PREFIX.
"product as p ON ps.fk_product = p.rowid";
66 $sql .=
" WHERE pb.batch = '".$db->escape($barcode).
"'";
68 $sql =
"SELECT ps.fk_entrepot, ps.fk_product, p.barcode,ps.reel";
69 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_stock as ps JOIN ".MAIN_DB_PREFIX.
"product as p ON ps.fk_product = p.rowid";
70 $sql .=
" WHERE p.barcode = '".$db->escape($barcode).
"'";
72 if (!empty($fk_entrepot)) {
73 $sql .=
" AND ps.fk_entrepot = '".$db->escape($fk_entrepot).
"'";
75 if (!empty($fk_product)) {
76 $sql .=
" AND ps.fk_product = '".$db->escape($fk_product).
"'";
78 $result = $db->query($sql);
80 $nbline = $db->num_rows($result);
81 for ($i=0; $i < $nbline; $i++) {
82 $object = $db->fetch_object($result);
83 if (($mode ==
"barcode" && $barcode == $object->barcode) || ($mode ==
"lotserial" && $barcode == $object->batch)) {
84 $warehouse->fetch(0, $product[
"Warehouse"]);
85 if (!empty($object->fk_entrepot) && $warehouse->id == $object->fk_entrepot) {
87 $warehouseid = $object->fk_entrepot;
88 $fk_product = $object->fk_product;
89 $reelqty = $object->reel;
91 $objectreturn = array(
'fk_warehouse'=>$warehouseid,
'fk_product'=>$fk_product,
'reelqty'=>$reelqty);
95 if ($warehousefound < 1) {
96 $response = array(
'status'=>
'error',
'errorcode'=>
'NotFound',
'message'=>
'No warehouse found for barcode'.$barcode);
97 } elseif ($warehousefound > 1) {
98 $response = array(
'status'=>
'error',
'errorcode'=>
'TooManyWarehouse',
'message'=>
'Too many warehouse found');
100 $response = array(
'status'=>
'success',
'message'=>
'Warehouse found',
'object'=>$objectreturn);
103 $response = array(
'status'=>
'error',
'errorcode'=>
'NotFound',
'message'=>
"No results found for barcode");
106 $response = array(
'status'=>
'error',
'errorcode'=>
'ActionError',
'message'=>
"Error on action");
109 if ($action ==
"addnewlineproduct") {
110 require_once DOL_DOCUMENT_ROOT.
"/product/inventory/class/inventory.class.php";
112 if (!empty($fk_inventory)) {
113 $inventoryline->fk_inventory = $fk_inventory;
115 $inventoryline->fk_warehouse = $fk_entrepot;
116 $inventoryline->fk_product = $fk_product;
117 $inventoryline->qty_stock = $reelqty;
118 if (!empty($batch)) {
119 $inventoryline->batch = $batch;
121 $inventoryline->datec =
dol_now();
123 $result = $inventoryline->create($user);
125 $response = array(
'status'=>
'success',
'message'=>
'Success on creating line',
'id_line'=>$result);
127 $response = array(
'status'=>
'error',
'errorcode'=>
'ErrorCreation',
'message'=>
"Error on line creation");
130 $response = array(
'status'=>
'error',
'errorcode'=>
'NoIdForInventory',
'message'=>
"No id for inventory");
134 $response = json_encode($response);