Merge branch 'develop' of github.com:Dolibarr/dolibarr into mko1011

This commit is contained in:
Maxime Kohlhaas 2013-07-30 16:22:13 +02:00
commit bfb01da04f
24 changed files with 1119 additions and 19 deletions

View File

@ -73,6 +73,11 @@ if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_BILL'
if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER", GETPOST('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER','alpha'),'chaine',0,'',$conf->entity);
}
if($action == 'USE_VIRTUAL_STOCK') {
$db->begin();
$res = dolibarr_set_const($db, "USE_VIRTUAL_STOCK", GETPOST('USE_VIRTUAL_STOCK','alpha'),'chaine',0,'',$conf->entity);
}
if($action)
{
if (! $res > 0) $error++;
@ -89,6 +94,7 @@ if($action)
}
}
/*
* View
*/
@ -243,6 +249,26 @@ if (! empty($conf->fournisseur->enabled))
print '</table>';
print '<br>';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print " <td>".$langs->trans("RuleForStockReplenishment")."</td>\n";
print " <td align=\"right\" width=\"160\">&nbsp;</td>\n";
print '</tr>'."\n";
$var = !$var;
print "<tr ".$bc[$var].">";
print '<td width="60%">'.$langs->trans("UseVirtualStock").'</td>';
print '<td width="160" align="right">';
print "<form method=\"post\" action=\"stock.php\">";
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print "<input type=\"hidden\" name=\"action\" value=\"USE_VIRTUAL_STOCK\">";
print $form->selectyesno("USE_VIRTUAL_STOCK",$conf->global->USE_VIRTUAL_STOCK,1);
print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
print '</form>';
print "</td>\n";
print "</tr>\n";
print '</table>';
dol_htmloutput_mesg($mesg);
$db->close();

View File

@ -1400,7 +1400,7 @@ class Form
$objp->remise = $objp2->remise;
$objp->price_by_qty_rowid = $objp2->rowid;
$this->constructProductListOption($objp, $opt, $optJson, 0, $selected);
$this->_construct_product_list_option($objp, $opt, $optJson, 0, $selected);
$j++;
@ -1414,7 +1414,7 @@ class Form
}
else
{
$this->constructProductListOption($objp, $opt, $optJson, $price_level, $selected);
$this->_construct_product_list_option($objp, $opt, $optJson, $price_level, $selected);
// Add new entry
// "key" value of json key array is used by jQuery automatically as selected value
// "label" value of json key array is used by jQuery automatically as text for combo box
@ -1870,6 +1870,10 @@ class Form
$objp = $this->db->fetch_object($result);
$opt = '<option value="'.$objp->idprodfournprice.'"';
//if there is only one supplier, preselect it
if($num == 1) {
$opt .= ' selected="selected"';
}
$opt.= '>'.$objp->nom.' - '.$objp->ref_fourn.' - ';
if ($objp->quantity == 1)

View File

@ -2,6 +2,7 @@
/* Copyright (C) 2010-2013 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2010 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2012-2013 Juanjo Menent <jmenent@2byte.es>
* 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
@ -1005,6 +1006,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
if (empty($leftmenu) || $leftmenu=="stock") $newmenu->add("/product/stock/liste.php", $langs->trans("List"), 1, $user->rights->stock->lire);
if (empty($leftmenu) || $leftmenu=="stock") $newmenu->add("/product/stock/valo.php", $langs->trans("EnhancedValue"), 1, $user->rights->stock->lire);
if (empty($leftmenu) || $leftmenu=="stock") $newmenu->add("/product/stock/mouvement.php", $langs->trans("Movements"), 1, $user->rights->stock->mouvement->lire);
if (empty($leftmenu) || $leftmenu=="stock") $newmenu->add("/product/stock/replenish.php", $langs->trans("Replenishment"), 1, $user->rights->stock->mouvement->lire);
}
// Expeditions

View File

@ -7,6 +7,7 @@
* Copyright (C) 2010-2013 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* 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
@ -921,6 +922,10 @@ class CommandeFournisseur extends CommonOrder
$error=0;
$now=dol_now();
if(!$this->source)
{
$this->source = 0;
}
/* On positionne en mode brouillon la commande */
$this->brouillon = 1;
@ -952,7 +957,7 @@ class CommandeFournisseur extends CommonOrder
//$sql.= ", ".$this->db->idate($now);
$sql.= ", ".$user->id;
$sql.= ", 0";
$sql.= ", 0";
$sql.= ", " . $this->source;
$sql.= ", '".$conf->global->COMMANDE_SUPPLIER_ADDON_PDF."'";
$sql.= ", ".$this->mode_reglement_id;
$sql.= ", ".$this->cond_reglement_id;

View File

@ -31,6 +31,8 @@ create table llx_fichinter_extrafields
) ENGINE=innodb;
ALTER TABLE llx_fichinter_extrafields ADD INDEX idx_ficheinter_extrafields (fk_object);
ALTER TABLE llx_product ADD COLUMN desiredstock integer DEFAULT 0;
create table llx_commandedet_extrafields
(
@ -284,4 +286,4 @@ ALTER TABLE llx_bordereau_cheque ADD tms timestamp;
-- Task 1011
ALTER TABLE `llx_societe` ADD `mode_reglement_supplier` TINYINT NOT NULL AFTER `cond_reglement` ,
ADD `cond_reglement_supplier` TINYINT NOT NULL AFTER `mode_reglement_supplier`;
ALTER TABLE `llx_facture_fourn` ADD `fk_mode_reglement` TINYINT NOT NULL AFTER `fk_cond_reglement`;
ALTER TABLE `llx_facture_fourn` ADD `fk_mode_reglement` TINYINT NOT NULL AFTER `fk_cond_reglement`;

View File

@ -3,6 +3,7 @@
-- Copyright (C) 2008-2010 Laurent Destailleur <eldy@users.sourceforge.net>
-- Copyright (C) 2005-2010 Regis Houssin <regis.houssin@capnetworks.com>
-- Copyright (C) 2010 juanjo Menent <jmenent@2byte.es>
-- 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
@ -70,5 +71,6 @@ create table llx_product
canvas varchar(32) DEFAULT NULL,
finished tinyint DEFAULT NULL,
hidden tinyint DEFAULT 0, -- Need permission see also hidden products
import_key varchar(14) -- Import key
import_key varchar(14), -- Import key
desiredstock integer DEFAULT 0
)ENGINE=innodb;

View File

@ -160,4 +160,9 @@ OrderByPhone=Phone
CreateInvoiceForThisCustomer=Bill orders
NoOrdersToInvoice=No orders billable
CloseProcessedOrdersAutomatically=Classify "Processed" all selected orders.
MenuOrdersToBill2=Billables orders
MenuOrdersToBill2=Billables orders
OrderCreation=Order creation
Ordered=Ordered
OrderCreated=Your orders have been created
OrderFail=An error happened during your orders creation
CreateOrders=Create orders

View File

@ -64,7 +64,6 @@ StockLimitShort=Limit
StockLimit=Stock limit for alerts
PhysicalStock=Physical stock
RealStock=Real Stock
TheoreticalStock=Therocial stock
VirtualStock=Virtual stock
MininumStock=Minimum stock
StockUp=Stock up
@ -88,4 +87,11 @@ ThisWarehouseIsPersonalStock=This warehouse represents personal stock of %s %s
SelectWarehouseForStockDecrease=Choose warehouse to use for stock decrease
SelectWarehouseForStockIncrease=Choose warehouse to use for stock increase
NoStockAction=No stock action
LastWaitingSupplierOrders=Orders waiting for receptions
LastWaitingSupplierOrders=Orders waiting for receptions
DesiredStock=Desired stock
StockToBuy=To order
Replenishment=Replenishment
ReplenishmentOrders=Replenishment orders
UseVirtualStock=Use virtual stock instead of physical stock
RuleForStockReplenishment=Rule for stocks replenishment
SelectProduct=Select at least one product

View File

@ -161,3 +161,8 @@ CreateInvoiceForThisCustomer=Facturer commandes
NoOrdersToInvoice=Pas de commandes facturables
CloseProcessedOrdersAutomatically=Classer automatiquement à "Traitées" les commandes sélectionnées.
MenuOrdersToBill2=Commandes à facturer
OrderCreation=Date de création
Ordered=Commandé
OrderCreated=Vos commandes ont été générées
OrderFail=Une erreur s'est produite pendant la création de vos commandes
CreateOrders=Créer commandes

View File

@ -64,7 +64,6 @@ StockLimitShort=Seuil
StockLimit=Seuil d'alerte de stock
PhysicalStock=Stock physique
RealStock=Stock réel
TheoreticalStock=Stock théorique
VirtualStock=Stock théorique
MininumStock=Stock minimum
StockUp=Stock maximum
@ -89,3 +88,10 @@ SelectWarehouseForStockDecrease=Sélectionner l'entrepôt à utiliser pour la d
SelectWarehouseForStockIncrease=Sélectionner l'entrepôt à utiliser pour l'incrémentation du stock
NoStockAction=Pas d'action sur l'entrepôt
LastWaitingSupplierOrders=Commandes en attente de réception
DesiredStock=Stock désiré
StockToBuy=À commander
Replenishment=Réapprovisionnement
ReplenishmentOrders=Commandes de réapprovisionnement
UseVirtualStock=Utiliser le stock théorique à la place du stock physique
RuleForStockReplenishment=Règle de gestion du réapprovisionnement des stocks
SelectProduct=Sélectionnez au moins un produit

View File

@ -83,7 +83,8 @@ class Product extends CommonObject
var $pmp;
//! Stock alert
var $seuil_stock_alerte;
//! Ask for replenishment when $desiredstock < $stock_reel
public $desiredstock;
//! Duree de validite du service
var $duration_value;
//! Unite de duree
@ -165,6 +166,7 @@ class Product extends CommonObject
$this->nbphoto = 0;
$this->stock_reel = 0;
$this->seuil_stock_alerte = 0;
$this->desiredstock = 0;
$this->canvas = '';
}
@ -489,6 +491,7 @@ class Product extends CommonObject
$sql.= ",duration = '" . $this->duration_value . $this->duration_unit ."'";
$sql.= ",accountancy_code_buy = '" . $this->accountancy_code_buy."'";
$sql.= ",accountancy_code_sell= '" . $this->accountancy_code_sell."'";
$sql.= ", desiredstock = " . ((isset($this->desiredstock) && $this->desiredstock != '') ? $this->desiredstock : "null");
$sql.= " WHERE rowid = " . $id;
dol_syslog(get_class($this)."update sql=".$sql);
@ -1135,7 +1138,7 @@ class Product extends CommonObject
$sql.= " tobuy, fk_product_type, duration, seuil_stock_alerte, canvas,";
$sql.= " weight, weight_units, length, length_units, surface, surface_units, volume, volume_units, barcode, fk_barcode_type, finished,";
$sql.= " accountancy_code_buy, accountancy_code_sell, stock, pmp,";
$sql.= " datec, tms, import_key, entity";
$sql.= " datec, tms, import_key, entity, desiredstock";
$sql.= " FROM ".MAIN_DB_PREFIX."product";
if ($id) $sql.= " WHERE rowid = '".$id."'";
else
@ -1199,6 +1202,7 @@ class Product extends CommonObject
$this->accountancy_code_sell = $obj->accountancy_code_sell;
$this->seuil_stock_alerte = $obj->seuil_stock_alerte;
$this->desiredstock = $obj->desiredstock;
$this->stock_reel = $obj->stock;
$this->pmp = $obj->pmp;
@ -2199,7 +2203,8 @@ class Product extends CommonObject
'stock'=>$this->stock_warehouse[1]->real, // Stock
'stock_alert'=>$this->seuil_stock_alerte, // Stock alert
'fullpath' => $compl_path.$label, // Label
'type'=>$type // Nb of units that compose parent product
'type'=>$type, // Nb of units that compose parent product
'desiredstock' => $this->desiredstock
);
// Recursive call if child is an array

View File

@ -7,6 +7,7 @@
* Copyright (C) 2006 Auguria SARL <info@auguria.org>
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013 Marcos García <marcosgdf@gmail.com>
* 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
@ -187,6 +188,7 @@ if (empty($reshook))
$object->duration_value = GETPOST('duration_value');
$object->duration_unit = GETPOST('duration_unit');
$object->seuil_stock_alerte = GETPOST('seuil_stock_alerte')?GETPOST('seuil_stock_alerte'):0;
$object->desiredstock = GETPOST('desiredstock')?GETPOST('desiredstock'):0;
$object->canvas = GETPOST('canvas');
$object->weight = GETPOST('weight');
$object->weight_units = GETPOST('weight_units');
@ -256,6 +258,7 @@ if (empty($reshook))
$object->status = GETPOST('statut');
$object->status_buy = GETPOST('statut_buy');
$object->seuil_stock_alerte = GETPOST('seuil_stock_alerte');
$object->desiredstock = GETPOST('desiredstock');
$object->duration_value = GETPOST('duration_value');
$object->duration_unit = GETPOST('duration_unit');
$object->canvas = GETPOST('canvas');
@ -723,12 +726,17 @@ else
print '<tr><td>'.$langs->trans("StockLimit").'</td><td>';
print '<input name="seuil_stock_alerte" size="4" value="'.GETPOST('seuil_stock_alerte').'">';
print '</td></tr>';
// Stock desired level
print '<tr><td>'.$langs->trans("DesiredStock").'</td><td>';
print '<input name="desiredstock" size="4" value="'.GETPOST('desiredstock').'">';
print '</td></tr>';
}
else
{
print '<input name="seuil_stock_alerte" type="hidden" value="0">';
print '<input name="desiredstock" type="hidden" value="0">';
}
// Description (used in invoice, propal...)
print '<tr><td valign="top">'.$langs->trans("Description").'</td><td>';
@ -934,10 +942,15 @@ else
print "<tr>".'<td>'.$langs->trans("StockLimit").'</td><td colspan="2">';
print '<input name="seuil_stock_alerte" size="4" value="'.$object->seuil_stock_alerte.'">';
print '</td></tr>';
print "<tr>".'<td>'.$langs->trans("DesiredStock").'</td><td colspan="2">';
print '<input name="desiredstock" size="4" value="'.$object->desiredstock.'">';
print '</td></tr>';
}
else
{
print '<input name="seuil_stock_alerte" type="hidden" value="'.$object->seuil_stock_alerte.'">';
print '<input name="desiredstock" type="hidden" value="'.$object->desiredstock.'">';
}
if ($object->isservice())

View File

@ -6,6 +6,7 @@
* Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2013 Jean Heimburger <jean@tiaris.info>
* 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
@ -130,6 +131,7 @@ else
$sql.= ' p.fk_product_type, p.tms as datem,';
$sql.= ' p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte,';
$sql.= ' MIN(pfp.unitprice) as minsellprice';
$sql .= ', p.desiredstock';
$sql.= ' FROM '.MAIN_DB_PREFIX.'product as p';
if (! empty($search_categ) || ! empty($catid)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_product as cp ON p.rowid = cp.fk_product"; // We'll need this table joined to the select in order to filter by categ
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
@ -195,6 +197,7 @@ else
$sql.= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,";
$sql.= " p.fk_product_type, p.tms,";
$sql.= " p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte";
$sql .= ', p.desiredstock';
//if (GETPOST("toolowstock")) $sql.= " HAVING SUM(s.reel) < p.seuil_stock_alerte"; // Not used yet
$sql.= $db->order($sortfield,$sortorder);
$sql.= $db->plimit($limit + 1, $offset);
@ -301,6 +304,7 @@ else
if (! empty($conf->service->enabled) && $type != 0) print_liste_field_titre($langs->trans("Duration"), $_SERVER["PHP_SELF"], "p.duration",$param,"",'align="center"',$sortfield,$sortorder);
if (empty($conf->global->PRODUIT_MULTIPRICES)) print_liste_field_titre($langs->trans("SellingPrice"), $_SERVER["PHP_SELF"], "p.price",$param,"",'align="right"',$sortfield,$sortorder);
print '<td class="liste_titre" align="right">'.$langs->trans("BuyingPriceMinShort").'</td>';
if (! empty($conf->stock->enabled) && $user->rights->stock->lire && $type != 1) print '<td class="liste_titre" align="right">'.$langs->trans("DesiredStock").'</td>';
if (! empty($conf->stock->enabled) && $user->rights->stock->lire && $type != 1) print '<td class="liste_titre" align="right">'.$langs->trans("PhysicalStock").'</td>';
print_liste_field_titre($langs->trans("Sell"), $_SERVER["PHP_SELF"], "p.tosell",$param,"",'align="right"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Buy"), $_SERVER["PHP_SELF"], "p.tobuy",$param,"",'align="right"',$sortfield,$sortorder);
@ -351,6 +355,10 @@ else
print '<td class="liste_titre">';
print '&nbsp;';
print '</td>';
//desiredstock
print '<td class="liste_titre">';
print '&nbsp;';
print '</td>';
}
print '<td class="liste_titre">';
@ -457,6 +465,9 @@ else
{
$product_static->id = $objp->rowid;
$product_static->load_stock();
print '<td align="right">';
print $objp->desiredstock;
print '</td>';
print '<td align="right">';
if ($product_static->stock_reel < $objp->seuil_stock_alerte) print img_warning($langs->trans("StockTooLow")).' ';
print $product_static->stock_reel;

View File

@ -2,6 +2,7 @@
/* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* 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
@ -104,6 +105,7 @@ $sql = 'SELECT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price
$sql.= ' p.fk_product_type, p.tms as datem,';
$sql.= ' p.duration, p.tosell as statut, p.tobuy, p.seuil_stock_alerte,';
$sql.= ' SUM(s.reel) as stock_physique';
$sql .= ', p.desiredstock';
$sql.= ' FROM ('.MAIN_DB_PREFIX.'product as p';
// We'll need this table joined to the select in order to filter by categ
if ($search_categ) $sql.= ", ".MAIN_DB_PREFIX."categorie_product as cp";
@ -157,6 +159,7 @@ if ($search_categ)
$sql.= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,";
$sql.= " p.fk_product_type, p.tms,";
$sql.= " p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte";
$sql .= ", p.desiredstock";
if ($toolowstock) $sql.= " HAVING SUM(s.reel) < p.seuil_stock_alerte"; // Not used yet
$sql.= $db->order($sortfield,$sortorder);
$sql.= $db->plimit($limit + 1, $offset);
@ -242,6 +245,7 @@ if ($resql)
print_liste_field_titre($langs->trans("Label"),"reassort.php", "p.label",$param,"","",$sortfield,$sortorder);
if (! empty($conf->service->enabled) && $type == 1) print_liste_field_titre($langs->trans("Duration"),"reassort.php", "p.duration",$param,"",'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("MininumStock"),"reassort.php", "p.seuil_stock_alerte",$param,"",'align="right"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("DesiredStock"),"reassort.php", "p.desiredstock",$param,"",'align="right"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("PhysicalStock"),"reassort.php", "stock_physique",$param,"",'align="right"',$sortfield,$sortorder);
// TODO Add info of running suppliers/customers orders
//print_liste_field_titre($langs->trans("TheoreticalStock"),"reassort.php", "stock_theorique",$param,"",'align="right"',$sortfield,$sortorder);
@ -267,7 +271,8 @@ if ($resql)
print '<td class="liste_titre">&nbsp;</td>';
print '<td class="liste_titre" align="right">&nbsp;</td>';
print '<td class="liste_titre">&nbsp;</td>';
print '<td class="liste_titre">&nbsp;</td>';
print '<td class="liste_titre">&nbsp;</td>';
print '<td class="liste_titre">&nbsp;</td>';
print '<td class="liste_titre" align="right">';
print '<input type="image" class="liste_titre" name="button_search" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" alt="'.$langs->trans("Search").'">';
print '<input type="image" class="liste_titre" name="button_removefilter" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/searchclear.png" alt="'.$langs->trans("RemoveFilter").'">';
@ -319,6 +324,7 @@ if ($resql)
}
//print '<td align="right">'.$objp->stock_theorique.'</td>';
print '<td align="right">'.$objp->seuil_stock_alerte.'</td>';
print '<td align="right">'.$objp->desiredstock.'</td>';
print '<td align="right">';
if ($objp->seuil_stock_alerte && ($objp->stock_physique < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' ';
print $objp->stock_physique;
@ -356,4 +362,4 @@ else
llxFooter();
$db->close();
?>
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 677 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 974 B

View File

@ -0,0 +1,123 @@
<?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
*/
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.class.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');
}
}
function getProducts($order_id)
{
global $db;
$order = new CommandeFournisseur($db);
$f = $order->fetch($order_id);
$products = array();
if($f) {
foreach($order->lines as $line) {
if (!in_array($line->fk_product, $products)) {
$products[] = $line->fk_product;
}
}
}
return $products;
}
?>

View File

@ -4,6 +4,7 @@
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
* 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
@ -43,6 +44,7 @@ $cancel=GETPOST('cancel');
$id = GETPOST('id')?GETPOST('id'):GETPOST('ref');
$ref = GETPOST('ref');
$stocklimit = GETPOST('stocklimit');
$desiredstock = GETPOST('desiredstock');
$cancel = GETPOST('cancel');
$fieldid = isset($_GET["ref"])?'ref':'rowid';
if ($user->societe_id) $socid=$user->societe_id;
@ -67,6 +69,19 @@ if ($action == 'setstocklimit')
$action='';
}
// Set desired stock
if ($action == 'setdesiredstock')
{
$product = new Product($db);
$result=$product->fetch($id);
$product->desiredstock=$desiredstock;
$result=$product->update($product->id,$user,1,0,1);
if ($result < 0)
setEventMessage($product->error, 'errors');
$action='';
}
// Correct stock
if ($action == "correct_stock" && ! $cancel)
{
@ -247,6 +262,11 @@ if ($id > 0 || $ref)
print '<tr><td>'.$form->editfieldkey("StockLimit",'stocklimit',$product->seuil_stock_alerte,$product,$user->rights->produit->creer).'</td><td colspan="2">';
print $form->editfieldval("StockLimit",'stocklimit',$product->seuil_stock_alerte,$product,$user->rights->produit->creer);
print '</td></tr>';
// Desired stock
print '<tr><td>'.$form->editfieldkey("DesiredStock",'desiredstock',$product->desiredstock,$product,$user->rights->produit->creer).'</td><td colspan="2">';
print $form->editfieldval("DesiredStock",'desiredstock',$product->desiredstock,$product,$user->rights->produit->creer);
print '</td></tr>';
// Real stock
$product->load_stock();

View File

@ -0,0 +1,541 @@
<?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/replenish.php
* \ingroup produit
* \brief Page to list stocks to replenish
*/
require '../../main.inc.php';
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");
$langs->load("orders");
// Security check
if ($user->societe_id) {
$socid = $user->societe_id;
}
$result=restrictedArea($user,'produit|service');
//checks if a product has been ordered
$action = GETPOST('action','alpha');
$sref = GETPOST('sref', 'alpha');
$snom = GETPOST('snom', 'alpha');
$sall = GETPOST('sall', 'alpha');
$type = GETPOST('type','int');
$tobuy = GETPOST('tobuy', 'int');
$sortfield = GETPOST('sortfield','alpha');
$sortorder = GETPOST('sortorder','alpha');
$page = GETPOST('page','int');
if (!$sortfield) {
$sortfield = 'p.ref';
}
if (!$sortorder) {
$sortorder = 'ASC';
}
$limit = $conf->liste_limit;
$offset = $limit * $page ;
/*
* Actions
*/
//orders creation
//FIXME: could go in the lib
if ($action == 'order') {
$linecount = GETPOST('linecount', 'int');
$box = 0;
unset($_POST['linecount']);
if ($linecount > 0) {
$suppliers = array();
for ($i = 0; $i < $linecount; $i++) {
if(GETPOST($i, 'alpha') === 'on'
&& GETPOST('fourn' . $i, 'int') > 0) { //one line
$box = $i;
$supplierpriceid = GETPOST('fourn'.$i, 'int');
//get all the parameters needed to create a line
$qty = GETPOST('tobuy'.$i, 'int');
$desc = GETPOST('desc'.$i, 'alpha');
$sql = 'SELECT fk_product, fk_soc, ref_fourn';
$sql .= ', tva_tx, unitprice FROM ';
$sql .= MAIN_DB_PREFIX . 'product_fournisseur_price';
$sql .= ' WHERE rowid = ' . $supplierpriceid;
$resql = $db->query($sql);
if ($resql && $db->num_rows($resql) > 0) {
//might need some value checks
$obj = $db->fetch_object($resql);
$line = new CommandeFournisseurLigne($db);
$line->qty = $qty;
$line->desc = $desc;
$line->fk_product = $obj->fk_product;
$line->tva_tx = $obj->tva_tx;
$line->subprice = $obj->unitprice;
$line->total_ht = $obj->unitprice * $qty;
$tva = $line->tva_tx / 100;
$line->total_tva = $line->total_ht * $tva;
$line->total_ttc = $line->total_ht + $line->total_tva;
$line->ref_fourn = $obj->ref_fourn;
$suppliers[$obj->fk_soc]['lines'][] = $line;
} else {
$error=$db->lasterror();
dol_print_error($db);
dol_syslog('replenish.php: '.$error, LOG_ERROR);
}
$db->free($resql);
unset($_POST['fourn' . $i]);
}
unset($_POST[$i]);
}
//we now know how many orders we need and what lines they have
$i = 0;
$orders = array();
$suppliersid = array_keys($suppliers);
foreach ($suppliers as $supplier) {
$order = new CommandeFournisseur($db);
$order->socid = $suppliersid[$i];
//trick to know which orders have been generated this way
$order->source = 42;
foreach ($supplier['lines'] as $line) {
$order->lines[] = $line;
}
$id = $order->create($user);
if ($id < 0) {
$fail++;
setEventMessage($langs->trans('OrderFail'), 'errors');
}
$i++;
}
if (!$fail && $id) {
setEventMessage($langs->trans('OrderCreated'), 'mesgs');
header('Location: replenishorders.php');
exit;
}
}
if ($box == 0) {
setEventMessage($langs->trans('SelectProduct'), 'warnings');
}
}
/*
* View
*/
$title = $langs->trans('Status');
$sql = 'SELECT p.rowid, p.ref, p.label, p.price';
$sql .= ', p.price_ttc, p.price_base_type,p.fk_product_type';
$sql .= ', p.tms as datem, p.duration, p.tobuy, p.seuil_stock_alerte,';
$sql .= ' SUM(s.reel) as stock_physique';
$sql .= ', p.desiredstock';
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'product as p';
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product_fournisseur_price as pf';
$sql .= ' ON p.rowid = pf.fk_product';
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product_stock as s';
$sql .= ' ON p.rowid = s.fk_product';
$sql.= ' WHERE p.entity IN (' . getEntity("product", 1) . ')';
if ($sall) {
$sql .= ' AND (p.ref LIKE "%'.$db->escape($sall).'%" ';
$sql .= 'OR p.label LIKE "%'.$db->escape($sall).'%" ';
$sql .= 'OR p.description LIKE "%'.$db->escape($sall).'%" ';
$sql .= 'OR p.note LIKE "%'.$db->escape($sall).'%")';
}
// if the type is not 1, we show all products (type = 0,2,3)
if (dol_strlen($type)) {
if ($type == 1) {
$sql .= ' AND p.fk_product_type = 1';
} else {
$sql .= ' AND p.fk_product_type != 1';
}
}
if ($sref) {
$sql .= ' AND p.ref LIKE "%' . $sref . '%"';
}
if ($snom) {
$sql .= ' AND p.label LIKE "%' . $db->escape($snom) . '%"';
}
$sql .= ' AND p.tobuy = 1';
if (!empty($canvas)) {
$sql .= ' AND p.canvas = "' . $db->escape($canvas) . '"';
}
$sql .= ' GROUP BY p.rowid, p.ref, p.label, p.price';
$sql .= ', p.price_ttc, p.price_base_type,p.fk_product_type, p.tms';
$sql .= ', p.duration, p.tobuy, p.seuil_stock_alerte';
$sql .= ', p.desiredstock';
$sql .= ' HAVING (p.desiredstock > SUM(s.reel) or SUM(s.reel) is NULL)';
$sql .= ' AND p.desiredstock > 0';
$sql .= $db->order($sortfield,$sortorder);
$sql .= $db->plimit($limit + 1, $offset);
$resql = $db->query($sql);
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
if ($num == 1 && ($sall or $snom or $sref)) {
$objp = $db->fetch_object($resql);
header('Location: ../fiche.php?id=' . $objp->rowid);
exit;
}
$helpurl = 'EN:Module_Stocks_En|FR:Module_Stock|';
$helpurl .= 'ES:M&oacute;dulo_Stocks';
llxHeader('', $title, $helpurl, $title);
$head = array();
$head[0][0] = DOL_URL_ROOT.'/product/stock/replenish.php';
$head[0][1] = $title;
$head[0][2] = 'replenish';
$head[1][0] = DOL_URL_ROOT.'/product/stock/replenishorders.php';
$head[1][1] = $langs->trans("ReplenishmentOrders");
$head[1][2] = 'replenishorders';
dol_fiche_head($head, 'replenish', $langs->trans('Replenishment'), 0, 'stock');
if ($sref || $snom || $sall || GETPOST('search', 'alpha')) {
$filters = '&sref=' . $sref . '&snom=' . $snom;
$filters .= '&amp;sall=' . $sall;
print_barre_liste($texte,
$page,
'replenish.php',
$filters,
$sortfield,
$sortorder,
'',
$num
);
} else {
$filters = '&sref=' . $sref . '&snom=' . $snom;
$filters .= '&fourn_id=' . $fourn_id;
$filters .= (isset($type)?'&amp;type=' . $type:'');
print_barre_liste($texte,
$page,
'replenish.php',
$filters,
$sortfield,
$sortorder,
'',
$num);
}
echo '<form action="replenish.php" method="post" name="formulaire">',
'<input type="hidden" name="token" value="' .$_SESSION['newtoken'] . '">',
'<input type="hidden" name="sortfield" value="' . $sortfield . '">',
'<input type="hidden" name="sortorder" value="' . $sortorder . '">',
'<input type="hidden" name="type" value="' . $type . '">',
'<input type="hidden" name="linecount" value="' . $num . '">',
'<input type="hidden" name="action" value="order">',
'<table class="liste" width="100%">';
$param = (isset($type)? '&type=' . $type : '');
$param .= '&fourn_id=' . $fourn_id . '&snom='. $snom;
$param .= '&sref=' . $sref;
// Lignes des titres
echo '<tr class="liste_titre">',
'<td><input type="checkbox" onClick="toggle(this)" /></td>';
print_liste_field_titre($langs->trans('Ref'),
'replenish.php',
'p.ref',
$param,
'',
'',
$sortfield,
$sortorder
);
print_liste_field_titre($langs->trans('Label'),
'replenish.php',
'p.label',
$param,
'',
'',
$sortfield,
$sortorder
);
if (!empty($conf->service->enabled) && $type == 1) {
print_liste_field_titre($langs->trans('Duration'),
'replenish.php',
'p.duration',
$param,
'',
'align="center"',
$sortfield,
$sortorder
);
}
print_liste_field_titre($langs->trans('DesiredStock'),
'replenish.php',
'p.desiredstock',
$param,
'',
'align="right"',
$sortfield,
$sortorder
);
if ($conf->global->USE_VIRTUAL_STOCK) {
$stocklabel = $langs->trans('VirtualStock');
} else {
$stocklabel = $langs->trans('PhysicalStock');
}
print_liste_field_titre($stocklabel,
'replenish.php',
'stock_physique',
$param,
'',
'align="right"',
$sortfield,
$sortorder
);
print_liste_field_titre($langs->trans('Ordered'),
'replenish.php',
'',
$param,
'',
'align="right"',
$sortfield,
$sortorder
);
print_liste_field_titre($langs->trans('StockToBuy'),
'replenish.php',
'',
$param,
'',
'align="right"',
$sortfield,
$sortorder
);
print_liste_field_titre($langs->trans('Supplier'),
'replenish.php',
'',
$param,
'',
'align="right"',
$sortfield,
$sortorder
);
echo '<td>&nbsp;</td>',
'</tr>',
// Lignes des champs de filtre
'<tr class="liste_titre">',
'<td class="liste_titre">&nbsp;</td>',
'<td class="liste_titre">',
'<input class="flat" type="text" name="sref" value="' . $sref . '">',
'</td>',
'<td class="liste_titre">',
'<input class="flat" type="text" name="snom" value="' . $snom . '">',
'</td>';
if (!empty($conf->service->enabled) && $type == 1) {
echo '<td class="liste_titre">',
'&nbsp;',
'</td>';
}
echo '<td class="liste_titre">&nbsp;</td>',
'<td class="liste_titre">&nbsp;</td>',
'<td class="liste_titre" align="right">&nbsp;</td>',
'<td class="liste_titre">&nbsp;</td>',
'<td class="liste_titre">&nbsp;</td>',
'<td class="liste_titre" align="right">',
'<input type="image" class="liste_titre" name="button_search"',
'src="' . DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/search.png" alt="' . $langs->trans("Search") . '">',
'</td>',
'</tr>';
$prod = new Product($db);
$var = True;
while ($i < min($num, $limit)) {
$objp = $db->fetch_object($resql);
if ($conf->global->STOCK_SUPPORTS_SERVICES
|| $objp->fk_product_type == 0) {
// Multilangs
if (! empty($conf->global->MAIN_MULTILANGS)) {
$sql = 'SELECT label';
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'product_lang';
$sql .= ' WHERE fk_product = ' . $objp->rowid;
$sql .= ' AND lang = "' . $langs->getDefaultLang() . '"';
$sql .= ' LIMIT 1';
$result = $db->query($sql);
if ($result) {
$objtp = $db->fetch_object($result);
if (!empty($objtp->label)) {
$objp->label = $objtp->label;
}
}
}
$form = new Form($db);
$var =! $var;
$prod->ref = $objp->ref;
$prod->id = $objp->rowid;
$prod->type = $objp->fk_product_type;
$ordered = ordered($prod->id);
if (!$objp->stock_physique) {
$objp->stock_physique = 0;
}
if ($conf->global->USE_VIRTUAL_STOCK) {
//compute virtual stock
$prod->fetch($prod->id);
$result=$prod->load_stats_commande(0, '1,2');
if ($result < 0) {
dol_print_error($db, $prod->error);
}
$stock_commande_client = $prod->stats_commande['qty'];
$result=$prod->load_stats_commande_fournisseur(0, '3');
if ($result < 0) {
dol_print_error($db,$prod->error);
}
$stock_commande_fournisseur = $prod->stats_commande_fournisseur['qty'];
$stock = $objp->stock_physique - $stock_commande_client + $stock_commande_fournisseur;
} else {
$stock = $objp->stock_physique;
}
$warning='';
if ($objp->seuil_stock_alerte
&& ($stock < $objp->seuil_stock_alerte)) {
$warning = img_warning($langs->trans('StockTooLow')) . ' ';
}
//depending on conf, use either physical stock or
//virtual stock to compute the stock to buy value
$stocktobuy = max($objp->desiredstock - $stock - $ordered, 0);
$disabled = '';
if($ordered > 0) {
if($ordered + $stock >= $objp->desiredstock) {
$picto = img_picto('', './img/yes', '', 1);
$disabled = 'disabled="disabled"';
}
else {
$picto = img_picto('', './img/no', '', 1);
}
} else {
$picto = img_picto('', './img/no', '', 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">',
$warning, $stock,
'</td>',
'<td align="right">',
'<a href="replenishorders.php?sproduct=' , $prod->id, '">',
$ordered, '</a> ', $picto,
'</td>',
'<td align="right">',
'<input type="text" name="tobuy' . $i .
'" value="' . $stocktobuy . '" ' . $disabled . '>',
'</td>',
'<td align="right">',
$form->select_product_fourn_price($prod->id,
'fourn' . $i,
1
),
'</td>',
'<td>&nbsp</td>',
'</tr>';
}
$i++;
}
$value = $langs->trans("CreateOrders");
echo '</table>',
'</div>',
'<table width="100%">',
'<tr><td align="right">',
'<input class="butAction" type="submit" value="' . $value . '">',
'</td></tr></table>',
'</form>';
if ($num > $conf->liste_limit) {
if ($sref || $snom || $sall || GETPOST('search', 'alpha')) {
$filters = '&sref=' . $sref . '&snom=' . $snom;
$filters .= '&amp;sall=' . $sall;
print_barre_liste('',
$page,
'replenish.php',
$filters,
$sortfield,
$sortorder,
'',
$num,
0,
''
);
} else {
$filters = '&sref=' . $sref . '&snom=' . $snom;
$filters .= '&fourn_id=' . $fourn_id;
$filters .= (isset($type)? '&amp;type=' . $type : '');
print_barre_liste('',
$page,
'replenish.php',
$filters,
$sortfield,
$sortorder,
'',
$num,
0,
''
);
}
}
$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);
}
llxFooter();
$db->close();

View File

@ -0,0 +1,318 @@
<?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/replenishorders.php
* \ingroup produit
* \brief Page to list replenishment orders
*/
require '../../main.inc.php';
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.'/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");
$langs->load("orders");
// Security check
if ($user->societe_id) $socid=$user->societe_id;
$result=restrictedArea($user,'produit|service');
$helpurl = 'EN:Module_Stocks_En|FR:Module_Stock|';
$helpurl .= 'ES:M&oacute;dulo_Stocks';
$texte = $langs->trans('ReplenishmentOrders');
llxHeader('', $texte, $helpurl, $texte);
$head = array();
$head[0][0] = DOL_URL_ROOT.'/product/stock/replenish.php';
$head[0][1] = $langs->trans('Status');
$head[0][2] = 'replenish';
$head[1][0] = DOL_URL_ROOT.'/product/stock/replenishorders.php';
$head[1][1] = $texte;
$head[1][2] = 'replenishorders';
dol_fiche_head($head,
'replenishorders',
$langs->trans('Replenishment'),
0,
'stock');
$commandestatic = new CommandeFournisseur($db);
$sref = GETPOST('search_ref', 'alpha');
$snom = GETPOST('search_nom', 'alpha');
$suser = GETPOST('search_user', 'alpha');
$sttc = GETPOST('search_ttc', 'int');
$sall = GETPOST('search_all', 'alpha');
$sdate = GETPOST('search_date', 'alpha');
$page = GETPOST('page', 'int');
$sproduct = GETPOST('sproduct', 'int');
$sortorder = GETPOST('sortorder', 'alpha');
$sortfield = GETPOST('sortfield', 'alpha');
if (!$sortorder) {
$sortorder = 'DESC';
}
if (!$sortfield) {
$sortfield = 'cf.date_creation';
}
$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.fk_user_author, u.login";
$sql .= ' FROM (' . MAIN_DB_PREFIX . 'societe as s,';
$sql .= ' ' . MAIN_DB_PREFIX . 'commande_fournisseur as cf';
if (!$user->rights->societe->client->voir && !$socid) {
$sql.= ', ' . MAIN_DB_PREFIX . 'societe_commerciaux as sc';
}
$sql .= ') LEFT JOIN ' . MAIN_DB_PREFIX . 'user as u ';
$sql .= 'ON cf.fk_user_author = u.rowid';
$sql .= ' WHERE cf.fk_soc = s.rowid ';
$sql .= ' AND cf.entity = ' . $conf->entity;
if ($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) {
$sql .= ' AND cf.fk_statut < 3';
} elseif ($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;
}
if ($sref) {
$sql .= ' AND cf.ref LIKE "%' . $db->escape($sref) . '%"';
}
if ($snom) {
$sql .= ' AND s.nom LIKE "%' . $db->escape($snom) . '%"';
}
if ($suser) {
$sql .= ' AND u.login LIKE "%' . $db->escape($suser) . '%"';
}
if ($sttc) {
$sql .= ' AND cf.total_ttc = ' . price2num($sttc);
}
if ($sdate) {
if(GETPOST('search_datemonth', 'int') && GETPOST('search_dateday', 'int')
&& GETPOST('search_dateyear', 'int')) {
$date = date('Y-m-d',
dol_mktime(0,
0,
0,
GETPOST('search_datemonth', 'int'),
GETPOST('search_dateday', 'int'),
GETPOST('search_dateyear', 'int')
)
);
} else {
$elts = explode('/', $sdate);
$datearray = array();
if ($elts[2]) {
$datearray[0] = $elts[2];
}
if ($elts[1]) {
$datearray[1] = $elts[1];
}
if ($elts[0]) {
$datearray[2] = $elts[0];
}
$date = implode('-', $datearray);
}
$sql .= ' AND cf.date_creation LIKE "%' . $date . '%"';
}
if ($sall) {
$sql .= ' AND (cf.ref LIKE "%' . $db->escape($sall) . '%" ';
$sql .= 'OR cf.note LIKE "%' . $db->escape($sall) . '%")';
}
if ($socid) {
$sql .= ' AND s.rowid = ' . $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;
print_barre_liste($langs->trans('ReplenishmentOrders'),
$page,
'replenishorders.php',
'',
$sortfield,
$sortorder,
'',
$num
);
echo '<form action="replenishorders.php" method="GET">',
'<table class="noborder" width="100%">',
'<tr class="liste_titre">';
print_liste_field_titre($langs->trans('Ref'),
$_SERVER['PHP_SELF'],
'cf.ref',
'',
'',
'',
$sortfield,
$sortorder
);
print_liste_field_titre($langs->trans('Company'),
$_SERVER['PHP_SELF'],
's.nom',
'',
'',
'',
$sortfield,
$sortorder
);
print_liste_field_titre($langs->trans('Author'),
$_SERVER['PHP_SELF'],
'u.login',
'',
'',
'',
$sortfield,
$sortorder
);
print_liste_field_titre($langs->trans('AmountTTC'),
$_SERVER['PHP_SELF'],
'cf.total_ttc',
'',
'',
'',
$sortfield,
$sortorder
);
print_liste_field_titre($langs->trans('OrderCreation'),
$_SERVER['PHP_SELF'],
'cf.date_creation',
'',
'',
'',
$sortfield,
$sortorder
);
print_liste_field_titre($langs->trans('Status'),
$_SERVER['PHP_SELF'],
'cf.fk_statut',
'',
'',
'align="right"',
$sortfield,
$sortorder
);
$form = new Form($db);
echo '</tr>',
'<tr class="liste_titre">',
'<td class="liste_titre">',
'<input type="text" class="flat" name="search_ref" value="' . $sref . '">',
'</td>',
'<td class="liste_titre">',
'<input type="text" class="flat" name="search_nom" value="' . $snom . '">',
'</td>',
'<td class="liste_titre">',
'<input type="text" class="flat" name="search_user" value="' . $suser . '">',
'</td>',
'<td class="liste_titre">',
'<input type="text" class="flat" name="search_ttc" value="' . $sttc . '">',
'</td>',
'<td class="liste_titre">',
$form->select_date('', 'search_date', 0, 0, 1, "", 1, 0, 1, 0, ''),
'</td>',
'<td class="liste_titre" align="right">';
$src = DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/search.png';
$value = dol_escape_htmltag($langs->trans('Search'));
echo '<input type="image" class="liste_titre" name="button_search" src="' . $src . '" value="' . $value . '" title="' . $value . '">',
'</td>',
'</tr>';
$var = true;
$userstatic = new User($db);
while ($i < min($num,$conf->liste_limit)) {
$obj = $db->fetch_object($resql);
$var = !$var;
if(!dispatched($obj->rowid) &&
(!$sproduct || in_array($sproduct, getProducts($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>';
// Author
$userstatic->id = $obj->fk_user_author;
$userstatic->login = $obj->login;
if ($userstatic->id) {
$txt = $userstatic->getLoginUrl(1);
} else {
$txt = '&nbsp;';
}
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>',
'</form>';
$db->free($resql);
}
llxFooter();
$db->close();

View File

@ -281,4 +281,4 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldcustomer,$dura
}
}
?>
?>

View File

@ -279,4 +279,4 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldsalerepresenta
}
}
?>
?>

View File

@ -256,4 +256,4 @@ function dolValidElement($element)
return (trim($element) != '');
}
?>
?>

View File

@ -311,4 +311,4 @@ function dolValidElement($element)
return (trim($element) != '');
}
?>
?>