dolibarr 25.0.0-alpha
interface.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2019 Laurent Destailleur (eldy) <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
25if (!defined('NOREQUIRESOC')) {
26 define('NOREQUIRESOC', '1');
27}
28if (!defined('NOCSRFCHECK')) {
29 define('NOCSRFCHECK', '1');
30}
31if (!defined('NOTOKENRENEWAL')) {
32 define('NOTOKENRENEWAL', '1');
33}
34if (!defined('NOREQUIREMENU')) {
35 define('NOREQUIREMENU', '1');
36}
37if (!defined('NOREQUIREHTML')) {
38 define('NOREQUIREHTML', '1');
39}
40if (!defined('NOREQUIREAJAX')) {
41 define('NOREQUIREAJAX', '1');
42}
43
44require '../../main.inc.php'; // Load $user and permissions
53$warehouse_id = GETPOSTINT('warehouse_id');
54$batch = GETPOST('batch', 'alphanohtml');
55$fk_product = GETPOSTINT('product_id');
56$action = GETPOST('action', 'alphanohtml');
57
58$result = restrictedArea($user, 'mrp');
59
60$permissiontoproduce = $user->hasRight('mrp', 'write');
61
62
63
64/*
65 * View
66 */
67
68top_httphead("application/json");
69
70if ($action == 'updateselectbatchbywarehouse' && $permissiontoproduce) {
71 $TRes = array();
72
73 $sql = "SELECT pb.batch, pb.rowid, ps.fk_entrepot, pb.qty, e.ref as label, ps.fk_product";
74 $sql .= " FROM " . MAIN_DB_PREFIX . "product_batch as pb";
75 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_stock as ps on ps.rowid = pb.fk_product_stock";
76 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "entrepot as e on e.rowid = ps.fk_entrepot AND e.entity IN (" . getEntity('stock') . ")";
77 $sql .= " WHERE ps.fk_product = " .((int) $fk_product);
78 if ($warehouse_id > 0) {
79 $sql .= " AND fk_entrepot = " . ((int) $warehouse_id);
80 }
81 $sql .= " ORDER BY e.ref, pb.batch";
82
83 $resql = $db->query($sql);
84
85 if ($resql) {
86 while ($obj = $db->fetch_object($resql)) {
87 if (empty($TRes[$obj->batch])) {
88 $TRes[$obj->batch] = $obj->qty;
89 } else {
90 $TRes[$obj->batch] += $obj->qty;
91 }
92 }
93 }
94
95 echo json_encode($TRes);
96} elseif ($action == 'updateselectwarehousebybatch' && $permissiontoproduce) {
97 $res = 0;
98
99 $sql = "SELECT pb.batch, pb.rowid, ps.fk_entrepot, e.ref, pb.qty";
100 $sql .= " FROM " . MAIN_DB_PREFIX . "product_batch as pb";
101 $sql .= " JOIN " . MAIN_DB_PREFIX . "product_stock as ps on ps.rowid = pb.fk_product_stock";
102 $sql .= " JOIN " . MAIN_DB_PREFIX . "entrepot as e on e.rowid = ps.fk_entrepot AND e.entity IN (" . getEntity('stock') . ")";
103 $sql .= " WHERE ps.fk_product = " .((int) $fk_product);
104 if ($batch) {
105 $sql.= " AND pb.batch = '" . $db->escape($batch) . "'";
106 }
107 $sql .= " ORDER BY e.ref, pb.batch";
108
109 $resql = $db->query($sql);
110
111 if ($resql) {
112 if ($db->num_rows($resql) == 1) {
113 $obj = $db->fetch_object($resql);
114 $res = $obj->fk_entrepot;
115 }
116 }
117
118 echo json_encode($res);
119}
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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.
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.