Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions htdocs/product/stock/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -716,15 +716,24 @@
$sql .= "p.accountancy_code_buy_export,";
$sql .= 'p.barcode,';
if ($separatedPMP) {
$sql .= " pa.pmp as ppmp,";
// COALESCE: a product may have no row yet in llx_product_perentity (rows are created
// on the first stock movement), so fall back on the global p.pmp like Product::fetch()
// does, instead of showing an empty AWP.
$sql .= " COALESCE(pa.pmp, p.pmp) as ppmp,";
} else {
$sql .= " p.pmp as ppmp,";
}
$sql .= " ps.reel as value";
if (getDolGlobalString('PRODUCT_USE_UNITS')) {
$sql .= ",fk_unit";
}
$sql .= ", (ps.reel * p.pmp) as svalue";
// svalue is the sort key of the "estimated value" column, so it must use the same AWP
// as ppmp above (the displayed value is recomputed in PHP from ppmp).
if ($separatedPMP) {
$sql .= ", (ps.reel * COALESCE(pa.pmp, p.pmp)) as svalue";
} else {
$sql .= ", (ps.reel * p.pmp) as svalue";
}
// Add fields from hooks
$parameters = array('context' => 'warehousecard');
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
Expand All @@ -735,7 +744,9 @@
$sql .= " FROM ".MAIN_DB_PREFIX."product_stock as ps, ".MAIN_DB_PREFIX."product as p";

if ($separatedPMP) {
$sql .= ", ".MAIN_DB_PREFIX."product_perentity as pa";
// LEFT JOIN (not an inner join): a product with no llx_product_perentity row must
// still be listed in the warehouse content, falling back on the global p.pmp.
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_perentity as pa ON pa.fk_product = p.rowid AND pa.entity = ".((int) $conf->entity);
}
$parameters = array('context' => 'warehousecard');
$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters); // Note that $action and $object may have been modified by hook
Expand All @@ -748,9 +759,6 @@
$sql .= " AND ps.reel <> 0"; // We do not show if stock is 0 (no product in this warehouse)
$sql .= " AND ps.fk_entrepot = ".((int) $object->id);

if ($separatedPMP) {
$sql .= " AND pa.fk_product = p.rowid AND pa.entity = ".(int) $conf->entity;
}
$parameters = array('context' => 'warehousecard');
$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
if ($reshook > 0) { //Note that $sql is replaced if reshook > 0
Expand Down
12 changes: 7 additions & 5 deletions htdocs/product/stock/class/entrepot.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -723,19 +723,21 @@ public function nb_products()
}

if ($separatedPMP) {
$sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * pa.pmp) as value";
// COALESCE: a product may have no row yet in llx_product_perentity (rows are created on
// the first stock movement), so fall back on the global p.pmp like Product::fetch() does,
// instead of valuing such a product at 0.
$sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * COALESCE(pa.pmp, p.pmp)) as value";
} else {
$sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * p.pmp) as value";
}
$sql .= " FROM ".$this->db->prefix()."product_stock as ps";
$sql .= ", ".$this->db->prefix()."product as p";
if ($separatedPMP) {
$sql .= ", ".$this->db->prefix()."product_perentity as pa";
// LEFT JOIN (not an inner join): a product with no llx_product_perentity row must still
// be counted in nb and valued using the global p.pmp.
$sql .= " LEFT JOIN ".$this->db->prefix()."product_perentity as pa ON pa.fk_product = p.rowid AND pa.entity = ".((int) $conf->entity);
}
$sql .= " WHERE ps.fk_entrepot = ".((int) $this->id);
if ($separatedPMP) {
$sql .= " AND pa.fk_product = p.rowid AND pa.entity = ". (int) $conf->entity;
}
$sql .= " AND ps.fk_product = p.rowid";
//print $sql;
$result = $this->db->query($sql);
Expand Down
5 changes: 4 additions & 1 deletion htdocs/product/stock/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,10 @@
$separatedPMP = false;
if (getDolGlobalString('MULTICOMPANY_PRODUCT_SHARING_ENABLED') && getDolGlobalString('MULTICOMPANY_PMP_PER_ENTITY_ENABLED')) {
$separatedPMP = true;
$sql .= ", SUM(pa.pmp * ps.reel) as estimatedvalue, SUM(p.price * ps.reel) as sellvalue, SUM(ps.reel) as stockqty";
// COALESCE: a product may have no row yet in llx_product_perentity (rows are created on the
// first stock movement), so fall back on the global p.pmp like Product::fetch() does, instead
// of valuing such a product at 0.
$sql .= ", SUM(COALESCE(pa.pmp, p.pmp) * ps.reel) as estimatedvalue, SUM(p.price * ps.reel) as sellvalue, SUM(ps.reel) as stockqty";
} else {
$sql .= ", SUM(p.pmp * ps.reel) as estimatedvalue, SUM(p.price * ps.reel) as sellvalue, SUM(ps.reel) as stockqty";
}
Expand Down