24if (!defined(
'NOREQUIRESOC')) {
25 define(
'NOREQUIRESOC',
'1');
27if (!defined(
'NOCSRFCHECK')) {
28 define(
'NOCSRFCHECK',
'1');
30if (!defined(
'NOTOKENRENEWAL')) {
31 define(
'NOTOKENRENEWAL',
'1');
33if (!defined(
'NOREQUIREMENU')) {
34 define(
'NOREQUIREMENU',
'1');
36if (!defined(
'NOREQUIREHTML')) {
37 define(
'NOREQUIREHTML',
'1');
39if (!defined(
'NOREQUIREAJAX')) {
40 define(
'NOREQUIREAJAX',
'1');
43require
'../../main.inc.php';
51$batch =
GETPOST(
'batch',
'alphanohtml');
53$action =
GETPOST(
'action',
'alphanohtml');
57$permissiontowrite = $user->hasRight(
'expedition',
'write');
69if ($action ==
'updateselectbatchbywarehouse' && $permissiontowrite) {
72 $sql =
"SELECT pb.batch, pb.rowid, ps.fk_entrepot, pb.qty, e.ref as label, ps.fk_product";
73 if ($is_eat_by_enabled) {
76 if ($is_sell_by_enabled) {
77 $sql .=
", pl.sellby";
79 $sql .=
" FROM ".$db->prefix().
"product_batch as pb";
80 $sql .=
" LEFT JOIN ".$db->prefix().
"product_stock as ps on ps.rowid = pb.fk_product_stock";
81 $sql .=
" LEFT JOIN ".$db->prefix().
"entrepot as e on e.rowid = ps.fk_entrepot AND e.entity IN (".
getEntity(
'stock').
")";
82 if ($is_eat_by_enabled || $is_sell_by_enabled) {
83 $sql .=
" LEFT JOIN ".$db->prefix().
"product_lot as pl on ps.fk_product = pl.fk_product AND pb.batch = pl.batch";
85 $sql .=
" WHERE ps.fk_product = ".((int) $product_id);
86 if ($warehouse_id > 0) {
87 $sql .=
" AND fk_entrepot = '".((int) $warehouse_id).
"'";
89 $sql .=
" ORDER BY e.ref, pb.batch";
91 $resql = $db->query($sql);
94 while ($obj = $db->fetch_object($resql)) {
95 $eat_by_date_formatted =
'';
96 if ($is_eat_by_enabled && !empty($obj->eatby)) {
97 $eat_by_date_formatted =
dol_print_date($db->jdate($obj->eatby),
'day');
99 $sell_by_date_formatted =
'';
100 if ($is_sell_by_enabled && !empty($obj->sellby)) {
101 $sell_by_date_formatted =
dol_print_date($db->jdate($obj->sellby),
'day');
105 if (!isset($resArr[$obj->batch])) {
106 $resArr[$obj->batch] = array(
107 'qty' => (
float) $obj->qty,
110 $resArr[$obj->batch][
'qty'] += $obj->qty;
114 if (!isset($resArr[$obj->batch][
'eatbydate'])) {
115 $resArr[$obj->batch][
'eatbydate'] = $eat_by_date_formatted;
119 if (!isset($resArr[$obj->batch][
'sellbydate'])) {
120 $resArr[$obj->batch][
'sellbydate'] = $sell_by_date_formatted;
125 echo json_encode($resArr);
126} elseif ($action ==
'updateselectwarehousebybatch' && $permissiontowrite) {
129 $sql =
"SELECT pb.batch, pb.rowid, ps.fk_entrepot, e.ref, pb.qty";
130 $sql .=
" FROM ".$db->prefix().
"product_batch as pb";
131 $sql .=
" JOIN ".$db->prefix().
"product_stock as ps on ps.rowid = pb.fk_product_stock";
132 $sql .=
" JOIN ".$db->prefix().
"entrepot as e on e.rowid = ps.fk_entrepot AND e.entity IN (".
getEntity(
'stock').
")";
133 $sql .=
" WHERE ps.fk_product = ".((int) $product_id);
135 $sql .=
" AND pb.batch = '".$db->escape($batch).
"'";
137 $sql .=
" ORDER BY e.ref, pb.batch";
139 $resql = $db->query($sql);
142 if ($db->num_rows($resql) == 1) {
143 $obj = $db->fetch_object($resql);
144 $res = $obj->fk_entrepot;
148 echo json_encode($res);
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.