25if (!defined(
'NOTOKENRENEWAL')) {
26 define(
'NOTOKENRENEWAL', 1);
28if (!defined(
'NOREQUIREMENU')) {
29 define(
'NOREQUIREMENU',
'1');
31if (!defined(
'NOREQUIREHTML')) {
32 define(
'NOREQUIREHTML',
'1');
34if (!defined(
'NOREQUIREAJAX')) {
35 define(
'NOREQUIREAJAX',
'1');
37if (!defined(
'NOREQUIRESOC')) {
38 define(
'NOREQUIRESOC',
'1');
40require
'../../../main.inc.php';
41require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/entrepot.class.php";
52$action =
GETPOST(
"action",
"alpha");
53$barcode =
GETPOST(
"barcode",
"aZ09");
61$batch =
GETPOST(
"batch",
"aZ09");
66$objectreturn = array();
81if ($action ==
"existbarcode" && !empty($barcode) && $user->hasRight(
'stock',
'lire')) {
82 if (!empty($mode) && $mode ==
"lotserial") {
83 $sql =
"SELECT ps.fk_entrepot, ps.fk_product, p.barcode, ps.reel, pb.batch";
84 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_batch as pb";
85 $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";
86 $sql .=
" WHERE pb.batch = '".$db->escape($barcode).
"'";
88 $sql =
"SELECT ps.fk_entrepot, ps.fk_product, p.barcode,ps.reel";
89 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_stock as ps JOIN ".MAIN_DB_PREFIX.
"product as p ON ps.fk_product = p.rowid";
90 $sql .=
" WHERE p.barcode = '".$db->escape($barcode).
"'";
92 if (!empty($fk_entrepot)) {
93 $sql .=
" AND ps.fk_entrepot = '".$db->escape($fk_entrepot).
"'";
95 if (!empty($fk_product)) {
96 $sql .=
" AND ps.fk_product = '".$db->escape($fk_product).
"'";
98 $result = $db->query($sql);
100 $nbline = $db->num_rows($result);
101 for ($i = 0; $i < $nbline; $i++) {
102 $object = $db->fetch_object($result);
103 if (($mode ==
"barcode" && $barcode ==
$object->barcode) || ($mode ==
"lotserial" && $barcode ==
$object->batch)) {
104 $warehouse->fetch(0, $product[
"Warehouse"]);
105 if (!empty(
$object->fk_entrepot) && $warehouse->id ==
$object->fk_entrepot) {
107 $warehouseid =
$object->fk_entrepot;
108 $fk_product =
$object->fk_product;
111 $objectreturn = array(
'fk_warehouse' => $warehouseid,
'fk_product' => $fk_product,
'reelqty' => $reelqty);
115 if ($warehousefound < 1) {
116 $response = array(
'status' =>
'error',
'errorcode' =>
'NotFound',
'message' =>
'No warehouse found for barcode'.$barcode);
117 } elseif ($warehousefound > 1) {
118 $response = array(
'status' =>
'error',
'errorcode' =>
'TooManyWarehouse',
'message' =>
'Too many warehouse found');
120 $response = array(
'status' =>
'success',
'message' =>
'Warehouse found',
'object' => $objectreturn);
123 $response = array(
'status' =>
'error',
'errorcode' =>
'NotFound',
'message' =>
"No results found for barcode");
126 $response = array(
'status' =>
'error',
'errorcode' =>
'ActionError',
'message' =>
"Error on action");
129if ($action ==
"addnewlineproduct" && $user->hasRight(
'stock',
'creer')) {
130 require_once DOL_DOCUMENT_ROOT.
"/product/inventory/class/inventory.class.php";
132 if (!empty($fk_inventory)) {
133 $inventoryline->fk_inventory = $fk_inventory;
135 $inventoryline->fk_warehouse = $fk_entrepot;
136 $inventoryline->fk_product = $fk_product;
137 $inventoryline->qty_stock = $reelqty;
138 if (!empty($batch)) {
139 $inventoryline->batch = $batch;
141 $inventoryline->datec =
dol_now();
143 $result = $inventoryline->create($user);
145 $response = array(
'status' =>
'success',
'message' =>
'Success on creating line',
'id_line' => $result);
147 $response = array(
'status' =>
'error',
'errorcode' =>
'ErrorCreation',
'message' =>
"Error on line creation");
150 $response = array(
'status' =>
'error',
'errorcode' =>
'NoIdForInventory',
'message' =>
"No id for inventory");
154$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.