FIX : New add limit stock product by warehouse #5764 for PgSQL
This commit is contained in:
parent
e17eea5ea5
commit
d3146234b8
@ -95,7 +95,7 @@ ALTER TABLE llx_subscription ADD UNIQUE INDEX uk_subscription (fk_adherent,datea
|
||||
ALTER TABLE llx_subscription CHANGE COLUMN cotisation subscription real;
|
||||
ALTER TABLE llx_adherent_type CHANGE COLUMN cotisation subscription varchar(3) NOT NULL DEFAULT 'yes';
|
||||
|
||||
create table llx_product_lot_extrafields
|
||||
CREATE TABLE llx_product_lot_extrafields
|
||||
(
|
||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||
tms timestamp,
|
||||
@ -107,14 +107,14 @@ ALTER TABLE llx_product_lot_extrafields ADD INDEX idx_product_lot_extrafields (f
|
||||
|
||||
ALTER TABLE llx_website_page MODIFY content MEDIUMTEXT;
|
||||
|
||||
create table llx_product_warehouse_properties
|
||||
CREATE TABLE llx_product_warehouse_properties
|
||||
(
|
||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||
tms timestamp,
|
||||
fk_product integer NOT NULL,
|
||||
fk_entrepot integer NOT NULL,
|
||||
seuil_stock_alerte integer DEFAULT '0',
|
||||
desiredstock integer DEFAULT '0',
|
||||
seuil_stock_alerte integer DEFAULT 0,
|
||||
desiredstock integer DEFAULT 0,
|
||||
import_key varchar(14) -- Import key
|
||||
)ENGINE=innodb;
|
||||
|
||||
|
||||
@ -131,19 +131,19 @@ if ($action == 'order' && isset($_POST['valid']))
|
||||
$line = new CommandeFournisseurLigne($db);
|
||||
$line->qty = $qty;
|
||||
$line->fk_product = $obj->fk_product;
|
||||
|
||||
|
||||
$product = new Product($db);
|
||||
$product->fetch($obj->fk_product);
|
||||
if (! empty($conf->global->MAIN_MULTILANGS))
|
||||
if (! empty($conf->global->MAIN_MULTILANGS))
|
||||
{
|
||||
$product->getMultiLangs();
|
||||
$product->getMultiLangs();
|
||||
}
|
||||
$line->desc = $product->description;
|
||||
if (! empty($conf->global->MAIN_MULTILANGS))
|
||||
{
|
||||
// TODO Get desc in language of thirdparty
|
||||
}
|
||||
|
||||
|
||||
$line->tva_tx = $obj->tva_tx;
|
||||
$line->subprice = $obj->unitprice;
|
||||
$line->total_ht = $obj->unitprice * $qty;
|
||||
@ -256,21 +256,31 @@ $formproduct = new FormProduct($db);
|
||||
|
||||
$title = $langs->trans('Status');
|
||||
|
||||
if(!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
|
||||
$sqldesiredtock=$db->ifsql("pse.desiredstock IS NULL", "p.desiredstock", "pse.desiredstock");
|
||||
$sqlalertstock=$db->ifsql("pse.seuil_stock_alerte IS NULL", "p.seuil_stock_alerte", "pse.seuil_stock_alerte");
|
||||
} else {
|
||||
$sqldesiredtock='p.desiredstock';
|
||||
$sqlalertstock='p.seuil_stock_alerte';
|
||||
}
|
||||
|
||||
|
||||
$sql = 'SELECT p.rowid, p.ref, p.label, p.description, p.price,';
|
||||
$sql.= ' p.price_ttc, p.price_base_type,p.fk_product_type,';
|
||||
$sql.= ' p.tms as datem, p.duration, p.tobuy,';
|
||||
$sql.= ' p.tms as datem, p.duration, p.tobuy';
|
||||
$sql.= ' ,p.desiredstock,p.seuil_stock_alerte';
|
||||
if(!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
|
||||
$sql.= ' '.$db->ifsql("pse.desiredstock IS NULL", "p.desiredstock", "pse.desiredstock").' as desiredstock,';
|
||||
$sql.= ' '.$db->ifsql("pse.seuil_stock_alerte IS NULL", "p.seuil_stock_alerte", "pse.seuil_stock_alerte").' as alertstock,';
|
||||
} else {
|
||||
$sql.= ' p.desiredstock, p.seuil_stock_alerte as alertstock,';
|
||||
$sql.= ', pse.desiredstock' ;
|
||||
$sql.= ', pse.seuil_stock_alerte' ;
|
||||
}
|
||||
$sql.= ' ,'.$sqldesiredtock.' as desiredstock, '.$sqlalertstock.' as alertstock,';
|
||||
|
||||
$sql.= ' SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").') as stock_physique';
|
||||
$sql.= ' FROM ' . MAIN_DB_PREFIX . 'product as p';
|
||||
$sql.= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product_stock as s';
|
||||
$sql.= ' ON p.rowid = s.fk_product';
|
||||
if(!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_warehouse_properties pse ON (p.rowid = pse.fk_product AND pse.fk_entrepot = '.$fk_entrepot.')';
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_warehouse_properties AS pse ON (p.rowid = pse.fk_product AND pse.fk_entrepot = '.$fk_entrepot.')';
|
||||
}
|
||||
$sql.= ' WHERE p.entity IN (' . getEntity("product", 1) . ')';
|
||||
if ($sall) {
|
||||
@ -306,10 +316,11 @@ if (!empty($canvas)) $sql .= ' AND p.canvas = "' . $db->escape($canvas) . '"';
|
||||
$sql.= ' GROUP BY p.rowid, p.ref, p.label, p.description, p.price';
|
||||
$sql.= ', p.price_ttc, p.price_base_type,p.fk_product_type, p.tms';
|
||||
$sql.= ', p.duration, p.tobuy';
|
||||
$sql.= ', p.desiredstock';
|
||||
$sql.= ', p.seuil_stock_alerte';
|
||||
if(!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
|
||||
$sql.= ', desiredstock, alertstock';
|
||||
} else {
|
||||
$sql.= ', p.desiredstock, p.seuil_stock_alerte';
|
||||
$sql.= ', pse.desiredstock' ;
|
||||
$sql.= ', pse.seuil_stock_alerte' ;
|
||||
}
|
||||
$sql.= ', s.fk_product';
|
||||
|
||||
@ -346,24 +357,24 @@ if ($usevirtualstock)
|
||||
$sqlReceptionFourn.= " AND fd.fk_product = p.rowid";
|
||||
$sqlReceptionFourn.= " AND cf.fk_statut IN (3,4))";
|
||||
|
||||
$sql.= ' HAVING ((('.$db->ifsql("desiredstock IS NULL", "0", "desiredstock").' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
|
||||
$sql.= ' HAVING ((('.$db->ifsql($sqldesiredtock." IS NULL", "0", $sqldesiredtock).' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
|
||||
$sql.= ' - ('.$sqlCommandesCli.' - '.$sqlExpeditionsCli.') + ('.$sqlCommandesFourn.' - '.$sqlReceptionFourn.')))';
|
||||
$sql.= ' OR (alertstock >= 0 AND (alertstock > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
|
||||
$sql.= ' OR ('.$sqlalertstock.' >= 0 AND ('.$sqlalertstock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
|
||||
$sql.= ' - ('.$sqlCommandesCli.' - '.$sqlExpeditionsCli.') + ('.$sqlCommandesFourn.' - '.$sqlReceptionFourn.'))))';
|
||||
|
||||
if ($salert == 'on') // Option to see when stock is lower than alert
|
||||
{
|
||||
$sql.= ' AND (alertstock > 0 AND (alertstock > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
|
||||
$sql.= ' AND ('.$sqlalertstock.' > 0 AND ('.$sqlalertstock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
|
||||
$sql.= ' - ('.$sqlCommandesCli.' - '.$sqlExpeditionsCli.') + ('.$sqlCommandesFourn.' - '.$sqlReceptionFourn.')))';
|
||||
$alertchecked = 'checked';
|
||||
}
|
||||
} else {
|
||||
$sql.= ' HAVING ((desiredstock > 0 AND (desiredstock > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')))';
|
||||
$sql.= ' OR (alertstock > 0 AND (alertstock > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").'))))';
|
||||
$sql.= ' HAVING (('.$sqldesiredtock.' > 0 AND ('.$sqldesiredtock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')))';
|
||||
$sql.= ' OR ('.$sqlalertstock.' > 0 AND ('.$sqlalertstock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").'))))';
|
||||
|
||||
if ($salert == 'on') // Option to see when stock is lower than alert
|
||||
{
|
||||
$sql.= ' AND (alertstock > 0 AND (alertstock > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')))';
|
||||
$sql.= ' AND ('.$sqlalertstock.' > 0 AND ('.$sqlalertstock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')))';
|
||||
$alertchecked = 'checked';
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user