| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- <?php
- /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
- * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
- * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
- /**
- * \file invoiceimport/lotcheck.php
- * \ingroup invoiceimport
- * \brief Home page of invoiceimport top menu
- */
- // Load Dolibarr environment
- $res = 0;
- // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
- if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
- $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
- }
- // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
- $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
- while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
- $i--; $j--;
- }
- if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
- $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
- }
- if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
- $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
- }
- // Try main.inc.php using relative path
- if (!$res && file_exists("../main.inc.php")) {
- $res = @include "../main.inc.php";
- }
- if (!$res && file_exists("../../main.inc.php")) {
- $res = @include "../../main.inc.php";
- }
- if (!$res && file_exists("../../../main.inc.php")) {
- $res = @include "../../../main.inc.php";
- }
- if (!$res) {
- die("Include of main fails");
- }
- require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
- // Load translation files required by the page
- $langs->loadLangs(array("invoiceimport@invoiceimport"));
- $action = GETPOST('action', 'aZ09');
- // Security check
- // if (! $user->rights->invoiceimport->myobject->read) {
- // accessforbidden();
- // }
- $socid = GETPOST('socid', 'int');
- if (isset($user->socid) && $user->socid > 0) {
- $action = '';
- $socid = $user->socid;
- }
- $max = 5;
- $now = dol_now();
- /*
- * Actions
- */
- if ($_REQUEST['action'] == 'getProducts') {
- $productsArray = getProductsList();
- if (is_array($productsArray)) {
- foreach ($productsArray as $product) {
- if ($product['lots'] == false) {
- $lots = '<span style="color: red;">(!)</span>';
- }
- else {
- $lotsQty = count(getProductsLOTS($product['data']->rowid));
- $lots = '<span style="color: green;">'.$lotsQty.' LOT in stock</span>';
- }
- print '<tr><td>'.$lots.'</td><td><a href="#" onclick="getProductLots(\''.$product['data']->rowid.'\')">'.$product['data']->label.'</a></td></tr>';
- }
- }
- else {
- print '<tr><td colspan="2">Products list is empty...</td></tr>';
- }
- die();
- }
- if ($_REQUEST['action'] == 'addlot') {
- $res = addNewLot($_REQUEST);
- print $res;
- die();
- }
- if ($_REQUEST['action'] == 'getLots') {
- if (isValidProduct($_REQUEST['productID'])) {
- $lots = getProductsLOTS($_REQUEST['productID']);
- if (is_array($lots)) {
- foreach ($lots as $lot) {
- print '<tr><td>'.$lot['batch']->batch.'</td><td>'.$lot['batch']->eatby.'</td><td>'.$lot['batch']->qty.' pcs.</td><td>'.$lot['entrepot']->ref.'</td></tr>';
- }
- }
- }
- else {
- print '<tr><td colspan="4">Invalid product ID...</td></tr>';
- }
- print '<tr>';
- print '<td colspan="4"><strong>Add new LOT</strong></td>';
- print '</tr>';
- if (is_array($lots)) {
- print '<tr>';
- print '<td><input type="text" id="code" placeholder="Serial number" /></td>';
- print '<td><input type="datetime-local" id="eatdate" placeholder="Income date" /></td>';
- print '<td><input type="number" id="qty" value="1" placeholder="Qty" /></td>';
- //print '<td><select name="etrepot"><option value="">Select location</option></select></td>';
- print '<td><input type="hidden" id="productID" value="'.$lots[0]['stock']->fk_product.'"><input type="hidden" id="stock" value="'.$lots[0]['stock']->rowid.'"><button type="button" name="addLot" onclick="addLOT()">Add</button></td>';
- print '</tr>';
- //print '<tr>';
- //print '<td colspan="4"><button type="button" name="addLot">Save</button></td>';
- //print '</tr>';
- }
- else {
- $entrepots = getEntrepots();
- print '<tr>';
- print '<td><input type="text" id="code" placeholder="Serial number" /></td>';
- print '<td><input type="datetime-local" id="eatdate" placeholder="Income date" /></td>';
- print '<td><input type="number" id="qty" value="1" placeholder="Qty" /></td>';
- print '<td><select id="etrepot"><option value="">Select location</option>'.$entrepots.'</select></td>';
- print '</tr>';
- print '<tr>';
- print '<td colspan="4"><input type="hidden" id="stock" value=""><input type="hidden" id="productID" value="'.$_REQUEST['productID'].'"><button type="button" name="addLot" onclick="addLOT()">Add</button></td>';
- print '</tr>';
- }
- die();
- }
- /*
- * View
- */
- $form = new Form($db);
- $formfile = new FormFile($db);
- llxHeader("", $langs->trans("LOTCheckerArea"));
- print '<script type="text/javascript" src="/custom/invoiceimport/js/lotcheck.js"></script>';
- print load_fiche_titre($langs->trans("LOTCheckerArea"), '', 'invoiceimport.png@invoiceimport');
- print '<div class="fichecenter"><div class="fichethirdleft">';
- print '<div class="nowrap">';
- print '<div class="div-table-responsive">';
- print '<table class="tagtable nobottomiftotal liste"><thead><tr><th>LOT</th><th>Product name</th></tr></thead><tbody id="prodlist"></tbody></table>';
- print '</div>';
- print '</div>';
- print '</div><div class="fichetwothirdright">';
- print '<div class="div-table-responsive">';
- print '<table class="tagtable nobottomiftotal liste"><thead><tr><th>Code</th><th>Date of income</th><th>Qty</th><th>Location</th></tr></thead><tbody id="lotlist"></tbody></table>';
- print '</div>';
- $NBMAX = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
- $max = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
- /* BEGIN MODULEBUILDER LASTMODIFIED MYOBJECT
- // Last modified myobject
- if (! empty($conf->invoiceimport->enabled) && $user->rights->invoiceimport->read)
- {
- $sql = "SELECT s.rowid, s.ref, s.label, s.date_creation, s.tms";
- $sql.= " FROM ".MAIN_DB_PREFIX."invoiceimport_myobject as s";
- //if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
- $sql.= " WHERE s.entity IN (".getEntity($myobjectstatic->element).")";
- //if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
- //if ($socid) $sql.= " AND s.rowid = $socid";
- $sql .= " ORDER BY s.tms DESC";
- $sql .= $db->plimit($max, 0);
- $resql = $db->query($sql);
- if ($resql)
- {
- $num = $db->num_rows($resql);
- $i = 0;
- print '<table class="noborder centpercent">';
- print '<tr class="liste_titre">';
- print '<th colspan="2">';
- print $langs->trans("BoxTitleLatestModifiedMyObjects", $max);
- print '</th>';
- print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
- print '</tr>';
- if ($num)
- {
- while ($i < $num)
- {
- $objp = $db->fetch_object($resql);
- $myobjectstatic->id=$objp->rowid;
- $myobjectstatic->ref=$objp->ref;
- $myobjectstatic->label=$objp->label;
- $myobjectstatic->status = $objp->status;
- print '<tr class="oddeven">';
- print '<td class="nowrap">'.$myobjectstatic->getNomUrl(1).'</td>';
- print '<td class="right nowrap">';
- print "</td>";
- print '<td class="right nowrap">'.dol_print_date($db->jdate($objp->tms), 'day')."</td>";
- print '</tr>';
- $i++;
- }
- $db->free($resql);
- } else {
- print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
- }
- print "</table><br>";
- }
- }
- */
- print '</div></div>';
- function hasProductLOTS($productID) {
- global $db;
- $resultset = $db->query("SELECT * FROM ".MAIN_DB_PREFIX."product_stock WHERE fk_product = ".$productID.";");
- if ($db->num_rows($resultset) > 0) {
- $stock = $db->fetch_object($resultset);
- $batchResults = $db->query("SELECT * FROM ".MAIN_DB_PREFIX."product_batch WHERE fk_product_stock='".$stock->rowid."';");
- if ($db->num_rows($batchResults) > 0) {
- return true;
- }
- else {
- return false;
- }
- }
- else {
- return false;
- }
- }
- function getProductsList() {
- global $db;
- $productList = array();
- $resultset = $db->query("SELECT * FROM ".MAIN_DB_PREFIX."product;");
- if ($db->num_rows($resultset) > 0) {
- while ($product = $db->fetch_object($resultset)) {
- $productList[] = array('data' => $product, 'lots' => hasProductLOTS($product->rowid));
- }
- return $productList;
- }
- else {
- return false;
- }
- }
- function isValidProduct($productID) {
- global $db;
- if (is_numeric($productID)) {
- $resultset = $db->query("SELECT * FROM ".MAIN_DB_PREFIX."product WHERE rowid='".$productID."';");
- if ($db->num_rows($resultset) > 0) {
- return true;
- }
- else {
- return false;
- }
- }
- else {
- return false;
- }
- }
- function getProductsLOTS($productID) {
- global $db;
- $lotList = array();
- $resultset = $db->query("SELECT * FROM ".MAIN_DB_PREFIX."product_stock WHERE fk_product = ".$productID.";");
- if ($db->num_rows($resultset) > 0) {
- $stock = $db->fetch_object($resultset);
- $entrepotResult = $db->query("SELECT * FROM ".MAIN_DB_PREFIX."entrepot WHERE rowid = ".$stock->fk_entrepot.";");
- $entrepot = $db->fetch_object($entrepotResult);
- $batchResults = $db->query("SELECT * FROM ".MAIN_DB_PREFIX."product_batch WHERE fk_product_stock='".$stock->rowid."';");
- if ($db->num_rows($batchResults) > 0) {
- while ($row = $db->fetch_object($batchResults)) {
- $lotList[] = array('stock' => $stock, 'batch' => $row, 'entrepot' => $entrepot);
- }
- return $lotList;
- }
- else {
- return false;
- }
- }
- else {
- return false;
- }
- }
- function addNewLot($lotData) {
- global $db;
- if ($lotData['fk_product_stock'] == '') {
- $resStock = $db->query("INSERT INTO ".MAIN_DB_PREFIX."product_stock (fk_product, fk_entrepot, reel) VALUES ('".$lotData['productID']."', '".$lotData['entrepot']."', '1')");
- $lotData['fk_product_stock'] = $db->last_insert_id(MAIN_DB_PREFIX."product_stock");
- }
- $resultset = $db->query("INSERT INTO ".MAIN_DB_PREFIX."product_batch (fk_product_stock, eatby, batch, qty) VALUES
- (
- '".$lotData['fk_product_stock']."',
- '".$lotData['eatby']."',
- '".$lotData['batch']."',
- '".$lotData['qty']."'
- );");
- return true;
- }
- function getEntrepots() {
- global $db;
- $options = '';
- $resultset = $db->query("SELECT * FROM ".MAIN_DB_PREFIX."entrepot;");
- if ($db->num_rows($resultset) > 0) {
- while ($row = $db->fetch_object($resultset)) {
- $options.= '<option value="'.$row->rowid.'">'.$row->ref.'</option>';
- }
- }
- return $options;
- }
- // End of page
- llxFooter();
- $db->close();
|