22if (!defined(
'NOTOKENRENEWAL')) {
23 define(
'NOTOKENRENEWAL', 1);
25if (!defined(
'NOREQUIREMENU')) {
26 define(
'NOREQUIREMENU',
'1');
28if (!defined(
'NOREQUIREHTML')) {
29 define(
'NOREQUIREHTML',
'1');
31if (!defined(
'NOREQUIREAJAX')) {
32 define(
'NOREQUIREAJAX',
'1');
34if (!defined(
'NOREQUIRESOC')) {
35 define(
'NOREQUIRESOC',
'1');
37require
'../../../main.inc.php';
38require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/entrepot.class.php";
41$action =
GETPOST(
"action",
"alpha");
42$barcode =
GETPOST(
"barcode",
"aZ09");
55$objectreturn = array();
64if ($action ==
"existbarcode" && !empty($barcode)) {
65 if (!empty($mode) && $mode ==
"lotserial") {
66 $sql =
"SELECT ps.fk_entrepot, ps.fk_product, p.barcode, ps.reel, pb.batch";
67 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_batch as pb";
68 $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";
69 $sql .=
" WHERE pb.batch = '".$db->escape($barcode).
"'";
71 $sql =
"SELECT ps.fk_entrepot, ps.fk_product, p.barcode,ps.reel";
72 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_stock as ps JOIN ".MAIN_DB_PREFIX.
"product as p ON ps.fk_product = p.rowid";
73 $sql .=
" WHERE p.barcode = '".$db->escape($barcode).
"'";
75 if (!empty($fk_entrepot)) {
76 $sql .=
" AND ps.fk_entrepot = '".$db->escape($fk_entrepot).
"'";
78 if (!empty($fk_product)) {
79 $sql .=
" AND ps.fk_product = '".$db->escape($fk_product).
"'";
81 $result = $db->query($sql);
83 $nbline = $db->num_rows($result);
84 for ($i=0; $i < $nbline; $i++) {
85 $object = $db->fetch_object($result);
86 if (($mode ==
"barcode" && $barcode ==
$object->barcode) || ($mode ==
"lotserial" && $barcode ==
$object->batch)) {
87 $warehouse->fetch(0, $product[
"Warehouse"]);
88 if (!empty(
$object->fk_entrepot) && $warehouse->id ==
$object->fk_entrepot) {
90 $warehouseid =
$object->fk_entrepot;
91 $fk_product =
$object->fk_product;
94 $objectreturn = array(
'fk_warehouse'=>$warehouseid,
'fk_product'=>$fk_product,
'reelqty'=>$reelqty);
98 if ($warehousefound < 1) {
99 $response = array(
'status'=>
'error',
'errorcode'=>
'NotFound',
'message'=>
'No warehouse found for barcode'.$barcode);
100 } elseif ($warehousefound > 1) {
101 $response = array(
'status'=>
'error',
'errorcode'=>
'TooManyWarehouse',
'message'=>
'Too many warehouse found');
103 $response = array(
'status'=>
'success',
'message'=>
'Warehouse found',
'object'=>$objectreturn);
106 $response = array(
'status'=>
'error',
'errorcode'=>
'NotFound',
'message'=>
"No results found for barcode");
109 $response = array(
'status'=>
'error',
'errorcode'=>
'ActionError',
'message'=>
"Error on action");
112if ($action ==
"addnewlineproduct") {
113 require_once DOL_DOCUMENT_ROOT.
"/product/inventory/class/inventory.class.php";
115 if (!empty($fk_inventory)) {
116 $inventoryline->fk_inventory = $fk_inventory;
118 $inventoryline->fk_warehouse = $fk_entrepot;
119 $inventoryline->fk_product = $fk_product;
120 $inventoryline->qty_stock = $reelqty;
121 if (!empty($batch)) {
122 $inventoryline->batch = $batch;
124 $inventoryline->datec =
dol_now();
126 $result = $inventoryline->create($user);
128 $response = array(
'status'=>
'success',
'message'=>
'Success on creating line',
'id_line'=>$result);
130 $response = array(
'status'=>
'error',
'errorcode'=>
'ErrorCreation',
'message'=>
"Error on line creation");
133 $response = array(
'status'=>
'error',
'errorcode'=>
'NoIdForInventory',
'message'=>
"No id for inventory");
137$response = json_encode($response);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Class to manage warehouses.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_now($mode='auto')
Return date for now.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.