25if (!defined(
'NOREQUIRESOC')) {
26 define(
'NOREQUIRESOC',
'1');
28if (!defined(
'NOCSRFCHECK')) {
29 define(
'NOCSRFCHECK',
'1');
31if (!defined(
'NOTOKENRENEWAL')) {
32 define(
'NOTOKENRENEWAL',
'1');
34if (!defined(
'NOREQUIREMENU')) {
35 define(
'NOREQUIREMENU',
'1');
37if (!defined(
'NOREQUIREHTML')) {
38 define(
'NOREQUIREHTML',
'1');
40if (!defined(
'NOREQUIREAJAX')) {
41 define(
'NOREQUIREAJAX',
'1');
44require
'../../main.inc.php';
52$batch =
GETPOST(
'batch',
'alphanohtml');
54$action =
GETPOST(
'action',
'alphanohtml');
58$permissiontowrite = $user->hasRight(
'expedition',
'write');
70if ($action ==
'updateselectbatchbywarehouse' && $permissiontowrite) {
73 $sql =
"SELECT pb.batch, pb.rowid, ps.fk_entrepot, pb.qty, e.ref as label, ps.fk_product";
74 if ($is_eat_by_enabled) {
77 if ($is_sell_by_enabled) {
78 $sql .=
", pl.sellby";
80 $sql .=
" FROM ".$db->prefix().
"product_batch as pb";
81 $sql .=
" LEFT JOIN ".$db->prefix().
"product_stock as ps on ps.rowid = pb.fk_product_stock";
82 $sql .=
" LEFT JOIN ".$db->prefix().
"entrepot as e on e.rowid = ps.fk_entrepot AND e.entity IN (".
getEntity(
'stock').
")";
83 if ($is_eat_by_enabled || $is_sell_by_enabled) {
84 $sql .=
" LEFT JOIN ".$db->prefix().
"product_lot as pl on ps.fk_product = pl.fk_product AND pb.batch = pl.batch";
86 $sql .=
" WHERE ps.fk_product = ".((int) $product_id);
87 if ($warehouse_id > 0) {
88 $sql .=
" AND fk_entrepot = ".((int) $warehouse_id);
90 $sql .=
" ORDER BY e.ref, pb.batch";
92 $resql =
$db->query($sql);
95 while ($obj =
$db->fetch_object($resql)) {
96 $eat_by_date_formatted =
'';
97 if ($is_eat_by_enabled && !empty($obj->eatby)) {
100 $sell_by_date_formatted =
'';
101 if ($is_sell_by_enabled && !empty($obj->sellby)) {
106 if (!isset($resArr[$obj->batch])) {
107 $resArr[$obj->batch] = array(
108 'qty' => (
float) $obj->qty,
111 $resArr[$obj->batch][
'qty'] += $obj->qty;
115 if (!isset($resArr[$obj->batch][
'eatbydate'])) {
116 $resArr[$obj->batch][
'eatbydate'] = $eat_by_date_formatted;
120 if (!isset($resArr[$obj->batch][
'sellbydate'])) {
121 $resArr[$obj->batch][
'sellbydate'] = $sell_by_date_formatted;
126 echo json_encode($resArr);
127} elseif ($action ==
'updateselectwarehousebybatch' && $permissiontowrite) {
130 $sql =
"SELECT pb.batch, pb.rowid, ps.fk_entrepot, e.ref, pb.qty";
131 $sql .=
" FROM ".$db->prefix().
"product_batch as pb";
132 $sql .=
" JOIN ".$db->prefix().
"product_stock as ps on ps.rowid = pb.fk_product_stock";
133 $sql .=
" JOIN ".$db->prefix().
"entrepot as e on e.rowid = ps.fk_entrepot AND e.entity IN (".
getEntity(
'stock').
")";
134 $sql .=
" WHERE ps.fk_product = ".((int) $product_id);
136 $sql .=
" AND pb.batch = '".$db->escape($batch).
"'";
138 $sql .=
" ORDER BY e.ref, pb.batch";
140 $resql =
$db->query($sql);
143 if (
$db->num_rows($resql) == 1) {
144 $obj =
$db->fetch_object($resql);
145 $res = $obj->fk_entrepot;
149 echo json_encode($res);
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
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.