Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop
This commit is contained in:
commit
1f31b5851b
@ -796,7 +796,7 @@ if ($rowid > 0) {
|
||||
print $form->selectyesno("subscription", $object->subscription, 1);
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td>'.$langs->trans("DefineAmountMemberType").'</td><td>';
|
||||
print '<tr><td>'.$langs->trans("Amount").'</td><td>';
|
||||
print '<input name="amount" size="5" value="'.price($object->amount).'">';
|
||||
print '</td></tr>';
|
||||
|
||||
|
||||
@ -317,7 +317,8 @@ create table llx_product_perentity
|
||||
accountancy_code_sell_export varchar(32), -- Selling accountancy code for vat export
|
||||
accountancy_code_buy varchar(32), -- Buying accountancy code
|
||||
accountancy_code_buy_intra varchar(32), -- Buying accountancy code for vat intracommunity
|
||||
accountancy_code_buy_export varchar(32) -- Buying accountancy code for vat import
|
||||
accountancy_code_buy_export varchar(32), -- Buying accountancy code for vat import
|
||||
pmp double(24,8)
|
||||
)ENGINE=innodb;
|
||||
|
||||
ALTER TABLE llx_product_perentity ADD INDEX idx_product_perentity_fk_product (fk_product);
|
||||
|
||||
@ -26,5 +26,6 @@ create table llx_product_perentity
|
||||
accountancy_code_sell_export varchar(32), -- Selling accountancy code for vat export
|
||||
accountancy_code_buy varchar(32), -- Buying accountancy code
|
||||
accountancy_code_buy_intra varchar(32), -- Buying accountancy code for vat intracommunity
|
||||
accountancy_code_buy_export varchar(32) -- Buying accountancy code for vat import
|
||||
accountancy_code_buy_export varchar(32), -- Buying accountancy code for vat import
|
||||
pmp double(24,8)
|
||||
)ENGINE=innodb;
|
||||
|
||||
@ -2183,12 +2183,43 @@ class Product extends CommonObject
|
||||
} else {
|
||||
$sql .= " ppe.accountancy_code_buy, ppe.accountancy_code_buy_intra, ppe.accountancy_code_buy_export, ppe.accountancy_code_sell, ppe.accountancy_code_sell_intra, ppe.accountancy_code_sell_export,";
|
||||
}
|
||||
$sql .= " p.stock,p.pmp, p.datec, p.tms, p.import_key, p.entity, p.desiredstock, p.tobatch, p.batch_mask, p.fk_unit,";
|
||||
|
||||
//For MultiCompany
|
||||
//PMP per entity & Stocks Sharings stock_reel includes only stocks shared with this entity
|
||||
$separatedEntityPMP = false;
|
||||
$separatedStock = false;
|
||||
if (!empty($conf->global->MULTICOMPANY_PRODUCT_SHARING_ENABLED)) {
|
||||
if (!empty($conf->global->MULTICOMPANY_PMP_PER_ENTITY_ENABLED)) {
|
||||
$checkPMPPerEntity = $this->db->query("SELECT pmp FROM " . MAIN_DB_PREFIX . "product_perentity WHERE fk_product = ".((int) $id)." AND entity = ".(int) $conf->entity);
|
||||
if ($this->db->num_rows($checkPMPPerEntity)>0) {
|
||||
$separatedEntityPMP = true;
|
||||
}
|
||||
}
|
||||
global $mc;
|
||||
$separatedStock = true;
|
||||
$visibleWarehousesEntities = $conf->entity;
|
||||
if (isset($mc->sharings['stock']) && !empty($mc->sharings['stock'])) {
|
||||
$visibleWarehousesEntities .= "," . implode(",", $mc->sharings['stock']);
|
||||
}
|
||||
}
|
||||
if ($separatedStock) {
|
||||
$sql .= " SUM(sp.reel) as stock,";
|
||||
} else {
|
||||
$sql .= " p.stock,";
|
||||
}
|
||||
if ($separatedEntityPMP) {
|
||||
$sql .= " pa.pmp, p.datec, p.tms, p.import_key, p.entity, p.desiredstock, p.tobatch, p.batch_mask, p.fk_unit,";
|
||||
} else {
|
||||
$sql .= " p.pmp, p.datec, p.tms, p.import_key, p.entity, p.desiredstock, p.tobatch, p.batch_mask, p.fk_unit,";
|
||||
}
|
||||
$sql .= " p.fk_price_expression, p.price_autogen, p.model_pdf";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."product as p";
|
||||
if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
|
||||
if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED) || $separatedEntityPMP) {
|
||||
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
|
||||
}
|
||||
if ($separatedStock) {
|
||||
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_stock as sp ON sp.fk_product = p.rowid";
|
||||
}
|
||||
if ($id) {
|
||||
$sql .= " WHERE p.rowid = ".((int) $id);
|
||||
} else {
|
||||
@ -2201,6 +2232,12 @@ class Product extends CommonObject
|
||||
$sql .= " AND p.barcode = '".$this->db->escape($barcode)."'";
|
||||
}
|
||||
}
|
||||
if ($separatedStock) {
|
||||
$sql .= " AND sp.fk_entrepot IN (
|
||||
SELECT rowid
|
||||
FROM ".MAIN_DB_PREFIX."entrepot WHERE entity IN (" . $this->db->sanitize($visibleWarehousesEntities) ."))";
|
||||
}
|
||||
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql) {
|
||||
|
||||
@ -605,7 +605,18 @@ if ($action == 'create') {
|
||||
$totalunit = 0;
|
||||
$totalvalue = $totalvaluesell = 0;
|
||||
|
||||
$sql = "SELECT p.rowid as rowid, p.ref, p.label as produit, p.tobatch, p.fk_product_type as type, p.pmp as ppmp, p.price, p.price_ttc, p.entity,";
|
||||
//For MultiCompany PMP per entity
|
||||
$separatedPMP = false;
|
||||
if (!empty($conf->global->MULTICOMPANY_PRODUCT_SHARING_ENABLED) && !empty($conf->global->MULTICOMPANY_PMP_PER_ENTITY_ENABLED)) {
|
||||
$separatedPMP = true;
|
||||
}
|
||||
|
||||
$sql = "SELECT p.rowid as rowid, p.ref, p.label as produit, p.tobatch, p.fk_product_type as type, p.price, p.price_ttc, p.entity,";
|
||||
if ($separatedPMP) {
|
||||
$sql .= " pa.pmp as ppmp,";
|
||||
} else {
|
||||
$sql .= " p.pmp as ppmp,";
|
||||
}
|
||||
$sql .= " ps.reel as value";
|
||||
if (!empty($conf->global->PRODUCT_USE_UNITS)) {
|
||||
$sql .= ",fk_unit";
|
||||
@ -618,9 +629,19 @@ if ($action == 'create') {
|
||||
}
|
||||
$sql .= $hookmanager->resPrint;
|
||||
$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";
|
||||
}
|
||||
|
||||
$sql .= " WHERE ps.fk_product = p.rowid";
|
||||
$sql .= " AND ps.reel <> 0"; // We do not show if stock is 0 (no product in this warehouse)
|
||||
$sql .= " AND ps.fk_entrepot = ".$object->id;
|
||||
|
||||
if ($separatedPMP) {
|
||||
$sql .= " AND pa.fk_product = p.rowid AND pa.entity = ". (int) $conf->entity;
|
||||
}
|
||||
|
||||
$sql .= $db->order($sortfield, $sortorder);
|
||||
|
||||
dol_syslog('List products', LOG_DEBUG);
|
||||
|
||||
@ -610,15 +610,31 @@ class Entrepot extends CommonObject
|
||||
*/
|
||||
public function nb_products()
|
||||
{
|
||||
global $conf;
|
||||
// phpcs:enable
|
||||
$ret = array();
|
||||
|
||||
$sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * p.pmp) as value";
|
||||
//For MultiCompany PMP per entity
|
||||
$separatedPMP = false;
|
||||
if (!empty($conf->global->MULTICOMPANY_PRODUCT_SHARING_ENABLED) && !empty($conf->global->MULTICOMPANY_PMP_PER_ENTITY_ENABLED)) {
|
||||
$separatedPMP = true;
|
||||
}
|
||||
|
||||
if ($separatedPMP) {
|
||||
$sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * pa.pmp) as value";
|
||||
} else {
|
||||
$sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * p.pmp) as value";
|
||||
}
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."product_stock as ps";
|
||||
$sql .= ", ".MAIN_DB_PREFIX."product as p";
|
||||
if ($separatedPMP) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."product_perentity as pa";
|
||||
}
|
||||
$sql .= " WHERE ps.fk_entrepot = ".$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);
|
||||
if ($result) {
|
||||
|
||||
@ -208,7 +208,16 @@ if (!empty($extrafields->attributes[$object->table_element]['label'])) {
|
||||
$sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.' as options_'.$key.', ' : '');
|
||||
}
|
||||
}
|
||||
$sql .= " SUM(p.pmp * ps.reel) as estimatedvalue, SUM(p.price * ps.reel) as sellvalue, SUM(ps.reel) as stockqty";
|
||||
|
||||
//For Multicompany PMP per entity
|
||||
$separatedPMP = false;
|
||||
if (!empty($conf->global->MULTICOMPANY_PRODUCT_SHARING_ENABLED) && !empty($conf->global->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";
|
||||
} else {
|
||||
$sql .= " SUM(p.pmp * ps.reel) as estimatedvalue, SUM(p.price * ps.reel) as sellvalue, SUM(ps.reel) as stockqty";
|
||||
}
|
||||
|
||||
// Add fields from hooks
|
||||
$parameters = array();
|
||||
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
|
||||
@ -225,7 +234,12 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON t.rowid = ps.fk_ent
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON ps.fk_product = p.rowid";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as c_dep ON c_dep.rowid = t.fk_departement";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as ccount ON ccount.rowid = t.fk_pays";
|
||||
if ($separatedPMP) {
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_perentity as pa ON pa.fk_product = p.rowid AND pa.fk_product = ps.fk_product AND pa.entity = ". (int) $conf->entity;
|
||||
}
|
||||
|
||||
$sql .= " WHERE t.entity IN (".getEntity('stock').")";
|
||||
|
||||
if (!empty($conf->categorie->enabled)) {
|
||||
$sql .= Categorie::getFilterSelectQuery(Categorie::TYPE_WAREHOUSE, "t.rowid", $search_category_list);
|
||||
}
|
||||
@ -273,6 +287,7 @@ $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters); //
|
||||
$sql .= $hookmanager->resPrint;
|
||||
$sql = preg_replace('/,\s*$/', '', $sql);
|
||||
$totalnboflines = 0;
|
||||
|
||||
$result = $db->query($sql);
|
||||
if ($result) {
|
||||
$totalnboflines = $db->num_rows($result);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user