dolibarr 21.0.0-beta
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
26if (!defined('NOTOKENRENEWAL')) {
27 define('NOTOKENRENEWAL', '1');
28}
29if (!defined('NOREQUIREMENU')) {
30 define('NOREQUIREMENU', '1');
31}
32if (!defined('NOREQUIREHTML')) {
33 define('NOREQUIREHTML', '1');
34}
35if (!defined('NOREQUIREAJAX')) {
36 define('NOREQUIREAJAX', '1');
37}
38if (!defined('NOBROWSERNOTIF')) {
39 define('NOBROWSERNOTIF', '1');
40}
41
42// Load Dolibarr environment
43require '../../main.inc.php'; // Load $user and permissions
44require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
45
54$action = GETPOST('action', 'aZ09');
55$productId = GETPOSTINT('product_id');
56$batch = GETPOST('batch', 'alphanohtml');
57
58// Security check
59restrictedArea($user, 'produit|service', $productId, 'product&product');
60
61$permissiontoread = $user->hasRight('stock', 'lire');
62
63/*
64 * View
65 */
66
67top_httphead('application/json');
68
69$rows = array();
70
71if ($action == 'search' && $batch != '' && $permissiontoread) {
72 $productLot = new Productlot($db);
73 $result = $productLot->fetch(0, $productId, $batch);
74
75 if ($result > 0 && $productLot->id > 0) {
76 $rows[] = array(
77 'rowid' => $productLot->id,
78 'sellby' => ($productLot->sellby ? dol_print_date($productLot->sellby, 'day') : ''),
79 'eatby' => ($productLot->eatby ? dol_print_date($productLot->eatby, 'day') : ''),
80 );
81 }
82}
83
84echo json_encode($rows);
85exit();
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.