checkbox + improve order detection
This commit is contained in:
parent
c09b05a05f
commit
6bf95db95e
106
htdocs/product/stock/lib/replenishment.lib.php
Normal file
106
htdocs/product/stock/lib/replenishment.lib.php
Normal file
@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/product/stock/replenishment.lib.php
|
||||
* \ingroup produit
|
||||
* \brief Contains functions used in replenish.php and replenishorders.php
|
||||
*/
|
||||
|
||||
function dispatched($order_id)
|
||||
{
|
||||
global $db;
|
||||
$sql = 'SELECT fk_product, SUM(qty) from llx_commande_fournisseur_dispatch';
|
||||
$sql .= ' WHERE fk_commande = ' . $order_id . ' GROUP BY fk_product';
|
||||
$sql .= ' ORDER by fk_product';
|
||||
$resql = $db->query($sql);
|
||||
$dispatched = array();
|
||||
$ordered = array();
|
||||
if($resql && $db->num_rows($resql)) {
|
||||
while($res = $db->fetch_object($resql))
|
||||
$dispatched[] = $res;
|
||||
}
|
||||
$sql = 'SELECT fk_product, SUM(qty) from llx_commande_fournisseurdet';
|
||||
$sql .= ' WHERE fk_commande = ' . $order_id . ' GROUP BY fk_product';
|
||||
$sql .= ' ORDER by fk_product';
|
||||
$resql = $db->query($sql);
|
||||
if($resql && $db->num_rows($resql)) {
|
||||
while($res = $db->fetch_object($resql))
|
||||
$ordered[] = $res;
|
||||
}
|
||||
return $dispatched == $ordered;
|
||||
}
|
||||
|
||||
function dispatchedOrders()
|
||||
{
|
||||
global $db;
|
||||
$sql = 'SELECT rowid FROM ' . MAIN_DB_PREFIX . 'commande_fournisseur';
|
||||
$resql = $db->query($sql);
|
||||
$res = array();
|
||||
if ($resql && $db->num_rows($resql) > 0) {
|
||||
while ($obj = $db->fetch_object($resql)) {
|
||||
if (dispatched($obj->rowid)) {
|
||||
$res[] = $obj->rowid;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($res) {
|
||||
$res = '(' . implode(',', $res) . ')';
|
||||
} else {
|
||||
//hack to make sure ordered SQL request won't syntax error
|
||||
$res = '(0)';
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
function ordered($product_id)
|
||||
{
|
||||
global $db, $langs, $conf;
|
||||
$sql = 'SELECT DISTINCT cfd.fk_product, SUM(cfd.qty) FROM';
|
||||
$sql .= ' ' . MAIN_DB_PREFIX . 'commande_fournisseurdet as cfd ';
|
||||
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'commande_fournisseur as cf';
|
||||
$sql .= ' ON cfd.fk_commande = cf.rowid WHERE';
|
||||
if ($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) {
|
||||
$sql .= ' cf.fk_statut < 3';
|
||||
} else if ($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) {
|
||||
$sql .= ' cf.fk_statut < 6 AND cf.rowid NOT IN ' . dispatchedOrders();
|
||||
} else {
|
||||
$sql .= ' cf.fk_statut < 5';
|
||||
}
|
||||
$sql .= ' AND cfd.fk_product = ' . $product_id;
|
||||
$sql .= ' GROUP BY cfd.fk_product';
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql) {
|
||||
$exists = $db->num_rows($resql);
|
||||
if ($exists) {
|
||||
$obj = $db->fetch_array($resql);
|
||||
return $obj['SUM(cfd.qty)']; //. ' ' . img_picto('','tick');
|
||||
} else {
|
||||
return null;//img_picto('', 'stcomm-1');
|
||||
}
|
||||
} else {
|
||||
$error = $db->lasterror();
|
||||
dol_print_error($db);
|
||||
dol_syslog('replenish.php: ' . $error, LOG_ERROR);
|
||||
|
||||
return $langs->trans('error');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@ -27,6 +27,7 @@ require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
|
||||
require_once './lib/replenishment.lib.php';
|
||||
|
||||
$langs->load("products");
|
||||
$langs->load("stocks");
|
||||
@ -39,34 +40,7 @@ if ($user->societe_id) {
|
||||
$result=restrictedArea($user,'produit|service');
|
||||
|
||||
//checks if a product has been ordered
|
||||
function ordered($product_id)
|
||||
{
|
||||
global $db;
|
||||
$sql = 'SELECT DISTINCT cfd.fk_product, SUM(cfd.qty) from ';
|
||||
$sql .= MAIN_DB_PREFIX . 'commande_fournisseurdet as cfd ';
|
||||
$sql .= 'LEFT JOIN ' . MAIN_DB_PREFIX . 'commande_fournisseur as cf';
|
||||
$sql .= ' ON cfd.fk_commande = cf.rowid WHERE cf.source = 42 ';
|
||||
$sql .= 'AND cf.fk_statut < 5 AND cfd.fk_product = ' . $product_id;
|
||||
$sql .= ' GROUP BY cfd.fk_product';
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql) {
|
||||
$exists = $db->num_rows($resql);
|
||||
if ($exists) {
|
||||
$obj = $db->fetch_array($resql);
|
||||
|
||||
return $obj['SUM(cfd.qty)'] . ' ' . img_picto('','tick');
|
||||
} else {
|
||||
return img_picto('', 'stcomm-1');
|
||||
}
|
||||
} else {
|
||||
$error = $db->lasterror();
|
||||
dol_print_error($db);
|
||||
dol_syslog('replenish.php: ' . $error, LOG_ERROR);
|
||||
|
||||
return $langs->trans('error');
|
||||
}
|
||||
}
|
||||
|
||||
$action = GETPOST('action','alpha');
|
||||
$sref = GETPOST('sref', 'alpha');
|
||||
@ -94,6 +68,7 @@ $offset = $limit * $page ;
|
||||
*/
|
||||
|
||||
//orders creation
|
||||
//could go in the lib
|
||||
if ($action == 'order') {
|
||||
$linecount = GETPOST('linecount', 'int');
|
||||
unset($_POST['linecount']);
|
||||
@ -280,7 +255,7 @@ if ($resql) {
|
||||
|
||||
// Lignes des titres
|
||||
echo '<tr class="liste_titre">',
|
||||
'<td> </td>';
|
||||
'<td><input type="checkbox" onClick="toggle(this)" /></td>';
|
||||
print_liste_field_titre($langs->trans('Ref'),
|
||||
'replenish.php',
|
||||
'p.ref',
|
||||
@ -415,28 +390,7 @@ if ($resql) {
|
||||
$prod->ref = $objp->ref;
|
||||
$prod->id = $objp->rowid;
|
||||
$prod->type = $objp->fk_product_type;
|
||||
echo '<tr ' . $bc[$var] . '>',
|
||||
'<td><input type="checkbox" name="' . $i . '"></td>',
|
||||
'<td class="nowrap">',
|
||||
$prod->getNomUrl(1, '', 16),
|
||||
'</td>',
|
||||
'<td>' . $objp->label . '</td>',
|
||||
'<input type="hidden" name="desc' . $i . '" value="' . $objp->label . '" >';
|
||||
|
||||
if (!empty($conf->service->enabled) && $type == 1) {
|
||||
if (preg_match('/([0-9]+)y/i', $objp->duration, $regs)) {
|
||||
$duration = $regs[1] . ' ' . $langs->trans('DurationYear');
|
||||
} elseif (preg_match('/([0-9]+)m/i', $objp->duration, $regs)) {
|
||||
$duration = $regs[1] . ' ' . $langs->trans('DurationMonth');
|
||||
} elseif (preg_match('/([0-9]+)d/i', $objp->duration, $regs)) {
|
||||
$duration = $regs[1] . ' ' . $langs->trans('DurationDay');
|
||||
} else {
|
||||
$duration = $objp->duration;
|
||||
}
|
||||
echo '<td align="center">',
|
||||
$duration,
|
||||
'</td>';
|
||||
}
|
||||
$ordered = ordered($prod->id);
|
||||
|
||||
if (!$objp->stock_physique) {
|
||||
$objp->stock_physique = 0;
|
||||
@ -466,6 +420,38 @@ if ($resql) {
|
||||
//depending on conf, use either physical stock or
|
||||
//virtual stock to compute the stock to buy value
|
||||
$stocktobuy = $objp->desiredstock - $stock;
|
||||
|
||||
if($ordered) {
|
||||
$picto = img_picto('','tick');
|
||||
if($ordered >= $stocktobuy) {
|
||||
$disabled = 'disabled="disabled"';
|
||||
}
|
||||
} else {
|
||||
$picto = img_picto('', 'stcomm-1');
|
||||
}
|
||||
echo '<tr ' . $bc[$var] . '>',
|
||||
'<td><input type="checkbox" class="check" name="' . $i . '"' . $disabled . '></td>',
|
||||
'<td class="nowrap">',
|
||||
$prod->getNomUrl(1, '', 16),
|
||||
'</td>',
|
||||
'<td>' . $objp->label . '</td>',
|
||||
'<input type="hidden" name="desc' . $i . '" value="' . $objp->label . '" >';
|
||||
|
||||
if (!empty($conf->service->enabled) && $type == 1) {
|
||||
if (preg_match('/([0-9]+)y/i', $objp->duration, $regs)) {
|
||||
$duration = $regs[1] . ' ' . $langs->trans('DurationYear');
|
||||
} elseif (preg_match('/([0-9]+)m/i', $objp->duration, $regs)) {
|
||||
$duration = $regs[1] . ' ' . $langs->trans('DurationMonth');
|
||||
} elseif (preg_match('/([0-9]+)d/i', $objp->duration, $regs)) {
|
||||
$duration = $regs[1] . ' ' . $langs->trans('DurationDay');
|
||||
} else {
|
||||
$duration = $objp->duration;
|
||||
}
|
||||
echo '<td align="center">',
|
||||
$duration,
|
||||
'</td>';
|
||||
}
|
||||
|
||||
echo '<td align="right">' . $objp->desiredstock . '</td>',
|
||||
'<td align="right">',
|
||||
$stock,
|
||||
@ -473,7 +459,7 @@ if ($resql) {
|
||||
'<td align="right">', $warning, $stocktobuy , '</td>',
|
||||
'<input type="hidden" name="tobuy' . $i . '" value="' . $stocktobuy . '" >',
|
||||
'<td align="right">',
|
||||
ordered($prod->id),
|
||||
$ordered, ' ', $picto,
|
||||
'</td>',
|
||||
'<td align="right">',
|
||||
$form->select_product_fourn_price($prod->id,
|
||||
@ -529,7 +515,15 @@ if ($resql) {
|
||||
}
|
||||
|
||||
$db->free($resql);
|
||||
|
||||
echo ' <script type="text/javascript">
|
||||
function toggle(source) {
|
||||
checkboxes = document.getElementsByClassName("check");
|
||||
for(var i=0; i < checkboxes.length;i++) {
|
||||
if(!checkboxes[i].disabled) {
|
||||
checkboxes[i].checked = source.checked;
|
||||
}
|
||||
}
|
||||
} </script>';
|
||||
} else {
|
||||
dol_print_error($db);
|
||||
}
|
||||
|
||||
@ -27,6 +27,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
|
||||
require_once './lib/replenishment.lib.php';
|
||||
|
||||
$langs->load("products");
|
||||
$langs->load("stocks");
|
||||
@ -75,7 +76,7 @@ if (!$sortfield) {
|
||||
$offset = $conf->liste_limit * $page ;
|
||||
|
||||
$sql = 'SELECT s.rowid as socid, s.nom, cf.date_creation as dc,';
|
||||
$sql .= ' cf.rowid,cf.ref, cf.fk_statut, cf.total_ttc';
|
||||
$sql .= ' cf.rowid, cf.ref, cf.fk_statut, cf.total_ttc';
|
||||
$sql .= ", cf.fk_user_author, u.login";
|
||||
$sql .= ' FROM (' . MAIN_DB_PREFIX . 'societe as s,';
|
||||
$sql .= ' ' . MAIN_DB_PREFIX . 'commande_fournisseur as cf';
|
||||
@ -90,7 +91,14 @@ $sql .= 'ON cf.fk_user_author = u.rowid';
|
||||
$sql .= ' WHERE cf.fk_soc = s.rowid ';
|
||||
$sql .= ' AND cf.entity = ' . $conf->entity;
|
||||
$sql .= ' AND cf.source = 42';
|
||||
$sql .= ' AND cf.fk_statut < 5';
|
||||
|
||||
if ($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) {
|
||||
$sql .= ' AND cf.fk_statut < 3';
|
||||
} else if ($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) {
|
||||
$sql .= ' AND cf.fk_statut < 6';
|
||||
} else {
|
||||
$sql .= ' AND cf.fk_statut < 5';
|
||||
}
|
||||
|
||||
if (!$user->rights->societe->client->voir && !$socid) {
|
||||
$sql .= ' AND s.rowid = sc.fk_soc AND sc.fk_user = ' . $user->id;
|
||||
@ -149,11 +157,11 @@ if ($socid) {
|
||||
if (GETPOST('statut', 'int')) {
|
||||
$sql .= ' AND fk_statut = ' . GETPOST('statut', 'int');
|
||||
}
|
||||
|
||||
$sql .= ' GROUP BY cf.rowid, cf.ref, cf.date_creation, cf.fk_statut';
|
||||
$sql .= ', cf.total_ttc, cf.fk_user_author, u.login, s.rowid, s.nom';
|
||||
$sql .= ' ORDER BY ' . $sortfield . ' ' . $sortorder . ' ';
|
||||
$sql .= $db->plimit($conf->liste_limit+1, $offset);
|
||||
$resql = $db->query($sql);
|
||||
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
@ -256,50 +264,52 @@ if ($resql) {
|
||||
$obj = $db->fetch_object($resql);
|
||||
$var = !$var;
|
||||
|
||||
$href = DOL_URL_ROOT . '/fourn/commande/fiche.php?id=' . $obj->rowid;
|
||||
echo '<tr ' . $bc[$var] . '>',
|
||||
// Ref
|
||||
'<td>',
|
||||
'<a href="' . $href . '">',
|
||||
img_object($langs->trans('ShowOrder'), 'order') . ' ' . $obj->ref,
|
||||
'</a></td>';
|
||||
if(!dispatched($obj->rowid)) {
|
||||
$href = DOL_URL_ROOT . '/fourn/commande/fiche.php?id=' . $obj->rowid;
|
||||
echo '<tr ' . $bc[$var] . '>',
|
||||
// Ref
|
||||
'<td>',
|
||||
'<a href="' . $href . '">',
|
||||
img_object($langs->trans('ShowOrder'), 'order') . ' ' . $obj->ref,
|
||||
'</a></td>';
|
||||
|
||||
// Company
|
||||
$href = DOL_URL_ROOT . '/fourn/fiche.php?socid=' . $obj->socid;
|
||||
echo '<td>',
|
||||
'<a href="' . $href .'">',
|
||||
img_object($langs->trans('ShowCompany'), 'company'), ' ',
|
||||
$obj->nom . '</a></td>';
|
||||
// Company
|
||||
$href = DOL_URL_ROOT . '/fourn/fiche.php?socid=' . $obj->socid;
|
||||
echo '<td>',
|
||||
'<a href="' . $href .'">',
|
||||
img_object($langs->trans('ShowCompany'), 'company'), ' ',
|
||||
$obj->nom . '</a></td>';
|
||||
|
||||
// Author
|
||||
$userstatic->id = $obj->fk_user_author;
|
||||
$userstatic->login = $obj->login;
|
||||
if ($userstatic->id) {
|
||||
$txt = $userstatic->getLoginUrl(1);
|
||||
} else {
|
||||
$txt = ' ';
|
||||
// Author
|
||||
$userstatic->id = $obj->fk_user_author;
|
||||
$userstatic->login = $obj->login;
|
||||
if ($userstatic->id) {
|
||||
$txt = $userstatic->getLoginUrl(1);
|
||||
} else {
|
||||
$txt = ' ';
|
||||
}
|
||||
echo '<td>',
|
||||
$txt,
|
||||
'</td>',
|
||||
// Amount
|
||||
'<td>',
|
||||
price($obj->total_ttc),
|
||||
'</td>';
|
||||
// Date
|
||||
if ($obj->dc) {
|
||||
$date = dol_print_date($db->jdate($obj->dc), 'day');
|
||||
} else {
|
||||
$date = '-';
|
||||
}
|
||||
echo '<td>',
|
||||
$date,
|
||||
'</td>',
|
||||
// Statut
|
||||
'<td align="right">',
|
||||
$commandestatic->LibStatut($obj->fk_statut, 5),
|
||||
'</td>',
|
||||
'</tr>';
|
||||
}
|
||||
echo '<td>',
|
||||
$txt,
|
||||
'</td>',
|
||||
// Amount
|
||||
'<td>',
|
||||
price($obj->total_ttc),
|
||||
'</td>';
|
||||
// Date
|
||||
if ($obj->dc) {
|
||||
$date = dol_print_date($db->jdate($obj->dc), 'day');
|
||||
} else {
|
||||
$date = '-';
|
||||
}
|
||||
echo '<td>',
|
||||
$date,
|
||||
'</td>',
|
||||
// Statut
|
||||
'<td align="right">',
|
||||
$commandestatic->LibStatut($obj->fk_statut, 5),
|
||||
'</td>',
|
||||
'</tr>';
|
||||
$i++;
|
||||
}
|
||||
echo '</table>',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user