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