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';
38include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
40$action =
GETPOST(
"action",
"alpha");
41$barcode =
GETPOST(
"barcode",
"aZ09");
44$fk_entrepot =
GETPOST(
"fk_entrepot",
"int");
45$fk_inventory =
GETPOST(
"fk_inventory",
"int");
46$fk_product =
GETPOST(
"fk_product",
"int");
47$reelqty =
GETPOST(
"reelqty",
"int");
48$batch =
GETPOST(
"batch",
"int");
53$objectreturn = array();
54$usesublevelpermission =
'';
59if (!empty($user->socid)) {
60 $socid = $user->socid;
63$result =
restrictedArea($user, $object->module, $object, $object->table_element, $usesublevelpermission,
'fk_soc',
'rowid', 0, 1);
65 httponly_accessforbidden(
'Not allowed by restrictArea (module='.$object->module.
' table_element='.$object->table_element.
')');
74if ($action ==
"existbarcode" && !empty($barcode)) {
75 if (!empty($mode) && $mode ==
"lotserial") {
76 $sql =
"SELECT ps.fk_entrepot, ps.fk_product, p.barcode, ps.reel, pb.batch";
77 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_batch as pb";
78 $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";
79 $sql .=
" WHERE pb.batch = '".$db->escape($barcode).
"'";
81 $sql =
"SELECT ps.fk_entrepot, ps.fk_product, p.barcode,ps.reel";
82 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_stock as ps JOIN ".MAIN_DB_PREFIX.
"product as p ON ps.fk_product = p.rowid";
83 $sql .=
" WHERE p.barcode = '".$db->escape($barcode).
"'";
85 if (!empty($fk_entrepot)) {
86 $sql .=
" AND ps.fk_entrepot = '".$db->escape($fk_entrepot).
"'";
88 $result = $db->query($sql);
90 $nbline = $db->num_rows($result);
91 for ($i=0; $i < $nbline; $i++) {
92 $obj = $db->fetch_object($result);
93 if (($mode ==
"barcode" && $barcode == $obj->barcode) || ($mode ==
"lotserial" && $barcode == $obj->batch)) {
94 if (!empty($obj->fk_entrepot) && $fk_entrepot == $obj->fk_entrepot) {
96 $warehouseid = $obj->fk_entrepot;
97 $fk_product = $obj->fk_product;
98 $reelqty = $obj->reel;
100 $objectreturn = array(
'fk_warehouse'=>$warehouseid,
'fk_product'=>$fk_product,
'reelqty'=>$reelqty);
104 if ($warehousefound < 1) {
105 $response = array(
'status'=>
'error',
'errorcode'=>
'NotFound',
'message'=>
'No warehouse found for barcode'.$barcode);
106 } elseif ($warehousefound > 1) {
107 $response = array(
'status'=>
'error',
'errorcode'=>
'TooManyWarehouse',
'message'=>
'Too many warehouse found');
109 $response = array(
'status'=>
'success',
'message'=>
'Warehouse found',
'object'=>$objectreturn);
112 $response = array(
'status'=>
'error',
'errorcode'=>
'NotFound',
'message'=>
"No results found for barcode");
115 $response = array(
'status'=>
'error',
'errorcode'=>
'ActionError',
'message'=>
"Error on action");
118$response = json_encode($response);
Class to manage products or services.
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.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
httponly_accessforbidden($message=1, $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.