dolibarr 20.0.0
searchfrombarcode.php
Go to the documentation of this file.
1<?php
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <https://www.gnu.org/licenses/>.
15 */
16
22if (!defined('NOTOKENRENEWAL')) {
23 define('NOTOKENRENEWAL', 1); // Disables token renewal
24}
25if (!defined('NOREQUIREMENU')) {
26 define('NOREQUIREMENU', '1');
27}
28if (!defined('NOREQUIREHTML')) {
29 define('NOREQUIREHTML', '1');
30}
31if (!defined('NOREQUIREAJAX')) {
32 define('NOREQUIREAJAX', '1');
33}
34if (!defined('NOREQUIRESOC')) {
35 define('NOREQUIRESOC', '1');
36}
37require '../../main.inc.php';
38include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
39
40$action = GETPOST("action", "alpha");
41$barcode = GETPOST("barcode", "aZ09");
42$response = "";
43
44$fk_entrepot = GETPOSTINT("fk_entrepot");
45$fk_inventory = GETPOSTINT("fk_inventory");
46$fk_product = GETPOSTINT("fk_product");
47$reelqty = GETPOSTINT("reelqty");
48$batch = GETPOSTINT("batch");
49$mode = GETPOST("mode", "aZ");
50
51$warehousefound = 0;
52$warehouseid = 0;
53$objectreturn = array();
54$usesublevelpermission = '';
55
56$object= new Product($db);
57
58// Security check
59if (!empty($user->socid)) {
60 $socid = $user->socid;
61}
62
63$result = restrictedArea($user, $object->module, $object, $object->table_element, $usesublevelpermission, 'fk_soc', 'rowid', 0, 1); // Call with mode return
64if (!$result) {
65 httponly_accessforbidden('Not allowed by restrictArea (module='.$object->module.' table_element='.$object->table_element.')');
66}
67
68/*
69 * View
70 */
71
72top_httphead('application/json');
73
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)."'";
80 } else {
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)."'";
84 }
85 if (!empty($fk_entrepot)) {
86 $sql .= " AND ps.fk_entrepot = '".$db->escape($fk_entrepot)."'";
87 }
88 $result = $db->query($sql);
89 if ($result) {
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) {
95 $warehousefound++;
96 $warehouseid = $obj->fk_entrepot;
97 $fk_product = $obj->fk_product;
98 $reelqty = $obj->reel;
99
100 $objectreturn = array('fk_warehouse'=>$warehouseid,'fk_product'=>$fk_product,'reelqty'=>$reelqty);
101 }
102 }
103 }
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');
108 } else {
109 $response = array('status'=>'success','message'=>'Warehouse found','object'=>$objectreturn);
110 }
111 } else {
112 $response = array('status'=>'error','errorcode'=>'NotFound','message'=>"No results found for barcode");
113 }
114} else {
115 $response = array('status'=>'error','errorcode'=>'ActionError','message'=>"Error on action");
116}
117
118$response = json_encode($response);
119echo $response;
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Class to manage products or services.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.
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.