dolibarr 21.0.0-alpha
product_lot.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2023 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2023 Lionel Vessiller <lvessiller@easya.solutions>
4 * Copyright (C) 2024 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('NOTOKENRENEWAL')) {
26 define('NOTOKENRENEWAL', '1');
27}
28if (!defined('NOREQUIREMENU')) {
29 define('NOREQUIREMENU', '1');
30}
31if (!defined('NOREQUIREHTML')) {
32 define('NOREQUIREHTML', '1');
33}
34if (!defined('NOREQUIREAJAX')) {
35 define('NOREQUIREAJAX', '1');
36}
37if (!defined('NOBROWSERNOTIF')) {
38 define('NOBROWSERNOTIF', '1');
39}
40
41// Load Dolibarr environment
42require '../../main.inc.php'; // Load $user and permissions
43require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
44
45$action = GETPOST('action', 'aZ09');
46$productId = GETPOSTINT('product_id');
47$batch = GETPOST('batch', 'alphanohtml');
48
49// Security check
50restrictedArea($user, 'produit|service', $productId, 'product&product');
51
52$permissiontoread = $user->hasRight('stock', 'lire');
53
54/*
55 * View
56 */
57
58top_httphead('application/json');
59
60$rows = array();
61
62if ($action == 'search' && $batch != '' && $permissiontoread) {
63 $productLot = new Productlot($db);
64 $result = $productLot->fetch(0, $productId, $batch);
65
66 if ($result > 0 && $productLot->id > 0) {
67 $rows[] = array(
68 'rowid' => $productLot->id,
69 'sellby' => ($productLot->sellby ? dol_print_date($productLot->sellby, 'day') : ''),
70 'eatby' => ($productLot->eatby ? dol_print_date($productLot->eatby, 'day') : ''),
71 );
72 }
73}
74
75echo json_encode($rows);
76exit();
Class with list of lots and properties.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
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.