From 595a6c2782b6b2c9df9b373f1e6172dfb8fed3b4 Mon Sep 17 00:00:00 2001 From: Quentin VIAL-GOUTEYRON Date: Mon, 21 Feb 2022 14:25:18 +0100 Subject: [PATCH] new pmp column --- .../install/mysql/migration/15.0.0-16.0.0.sql | 2 +- .../mysql/tables/llx_inventorydet-stock.sql | 4 +- .../inventory/class/inventory.class.php | 4 ++ htdocs/product/inventory/inventory.php | 62 +++++++++++++------ 4 files changed, 51 insertions(+), 21 deletions(-) diff --git a/htdocs/install/mysql/migration/15.0.0-16.0.0.sql b/htdocs/install/mysql/migration/15.0.0-16.0.0.sql index 85d8763a4fe..2667ac03e0e 100644 --- a/htdocs/install/mysql/migration/15.0.0-16.0.0.sql +++ b/htdocs/install/mysql/migration/15.0.0-16.0.0.sql @@ -238,5 +238,5 @@ ALTER TABLE llx_advtargetemailing RENAME TO llx_mailing_advtarget; ALTER TABLE llx_mailing ADD UNIQUE uk_mailing(titre, entity); ALTER TABLE llx_inventorydet ADD COLUMN pmp_real double DEFAULT NULL; -ALTER TABLE llx_inventorydet ADD COLUMN valuation_real double DEFAULT NULL; +ALTER TABLE llx_inventorydet ADD COLUMN pmp_expected double DEFAULT NULL; diff --git a/htdocs/install/mysql/tables/llx_inventorydet-stock.sql b/htdocs/install/mysql/tables/llx_inventorydet-stock.sql index 5ce878124b6..8999b0e298b 100644 --- a/htdocs/install/mysql/tables/llx_inventorydet-stock.sql +++ b/htdocs/install/mysql/tables/llx_inventorydet-stock.sql @@ -29,8 +29,8 @@ CREATE TABLE llx_inventorydet qty_stock double DEFAULT NULL, -- Value or real stock we have, when we start the inventory (may be updated during intermediary steps). qty_view double DEFAULT NULL, -- Quantity found during inventory. It is the targeted value, filled during edition of inventory. qty_regulated double DEFAULT NULL, -- Never used. Deprecated because we already have the fk_movement now. - pmp_real double DEFAULT NULL, -- Never used. Deprecated because we already have the fk_movement now. - valuation_real double DEFAULT NULL, -- Never used. Deprecated because we already have the fk_movement now. + pmp_real double DEFAULT NULL, + pmp_expected double DEFAULT NULL, fk_movement integer NULL -- can contain the id of stock movement we recorded to make the inventory regulation of this line ) ENGINE=innodb; diff --git a/htdocs/product/inventory/class/inventory.class.php b/htdocs/product/inventory/class/inventory.class.php index 92061972e60..81300d6bac8 100644 --- a/htdocs/product/inventory/class/inventory.class.php +++ b/htdocs/product/inventory/class/inventory.class.php @@ -755,6 +755,8 @@ class InventoryLine extends CommonObjectLine 'qty_stock' => array('type'=>'double', 'label'=>'QtyFound', 'visible'=>1, 'enabled'=>1, 'position'=>32, 'index'=>1, 'help'=>'Qty we found/want (to define during draft edition)'), 'qty_view' => array('type'=>'double', 'label'=>'QtyBefore', 'visible'=>1, 'enabled'=>1, 'position'=>33, 'index'=>1, 'help'=>'Qty before (filled once movements are validated)'), 'qty_regulated' => array('type'=>'double', 'label'=>'QtyDelta', 'visible'=>1, 'enabled'=>1, 'position'=>34, 'index'=>1, 'help'=>'Qty aadded or removed (filled once movements are validated)'), + 'pmp_real' => array('type'=>'double', 'label'=>'PMPReal', 'visible'=>1, 'enabled'=>1, 'position'=>35), + 'pmp_expected' => array('type'=>'double', 'label'=>'PMPExpected', 'visible'=>1, 'enabled'=>1, 'position'=>36), ); /** @@ -771,6 +773,8 @@ class InventoryLine extends CommonObjectLine public $qty_stock; public $qty_view; public $qty_regulated; + public $pmp_real; + public $pmp_expected; /** diff --git a/htdocs/product/inventory/inventory.php b/htdocs/product/inventory/inventory.php index 06c8ae0d2f5..b593fc1b414 100644 --- a/htdocs/product/inventory/inventory.php +++ b/htdocs/product/inventory/inventory.php @@ -127,7 +127,7 @@ if (empty($reshook)) { $db->begin(); $sql = 'SELECT id.rowid, id.datec as date_creation, id.tms as date_modification, id.fk_inventory, id.fk_warehouse,'; - $sql .= ' id.fk_product, id.batch, id.qty_stock, id.qty_view, id.qty_regulated'; + $sql .= ' id.fk_product, id.batch, id.qty_stock, id.qty_view, id.qty_regulated, id.pmp_real'; $sql .= ' FROM '.MAIN_DB_PREFIX.'inventorydet as id'; $sql .= ' WHERE id.fk_inventory = '.((int) $object->id); @@ -176,14 +176,26 @@ if (empty($reshook)) { $datemovement = ''; //$inventorycode = 'INV'.$object->id; $inventorycode = 'INV-'.$object->ref; + $price = 0; + if(!empty($line->pmp_real) && !empty($conf->global->INVENTORY_MANAGE_REAL_PMP)) $price = $line->pmp_real; - $idstockmove = $stockmovment->_create($user, $line->fk_product, $line->fk_warehouse, $stock_movement_qty, $movement_type, 0, $langs->trans('LabelOfInventoryMovemement', $object->ref), $inventorycode, $datemovement, '', '', $line->batch); + $idstockmove = $stockmovment->_create($user, $line->fk_product, $line->fk_warehouse, $stock_movement_qty, $movement_type, $price, $langs->trans('LabelOfInventoryMovemement', $object->ref), $inventorycode, $datemovement, '', '', $line->batch); if ($idstockmove < 0) { $error++; setEventMessages($stockmovment->error, $stockmovment->errors, 'errors'); break; } + if(!empty($line->pmp_real) && !empty($conf->global->INVENTORY_MANAGE_REAL_PMP)) { + $sqlpmp = 'UPDATE '.MAIN_DB_PREFIX.'product SET pmp = '.((float) $line->pmp_real).' WHERE rowid = '.((int) $line->fk_product); + $resqlpmp = $db->query($sqlpmp); + if(! $resqlpmp) { + $error++; + setEventMessages($db->lasterror(), null, 'errors'); + break; + } + } + // Update line with id of stock movement (and the start quantity if it has changed this last recording) $sqlupdate = "UPDATE ".MAIN_DB_PREFIX."inventorydet"; $sqlupdate .= " SET fk_movement = ".((int) $idstockmove); @@ -247,6 +259,8 @@ if (empty($reshook)) { if ($result > 0) { $inventoryline->qty_stock = price2num(GETPOST('stock_qty_'.$lineid, 'alpha'), 'MS'); // The new value that was set in as hidden field $inventoryline->qty_view = $qtytoupdate; // The new value we want + $inventoryline->pmp_real = price2num(GETPOST('realpmp_'.$lineid, 'alpha'), 'MS'); + $inventoryline->pmp_expected = price2num(GETPOST('expectedpmp_'.$lineid, 'alpha'), 'MS'); $resultupdate = $inventoryline->update($user); } } else { @@ -584,6 +598,7 @@ if ($object->id > 0) { var object = $(this)[0]; var objecttofill = $("#"+object.id+"_input")[0]; objecttofill.value = object.innerText; + jQuery(".realqty").trigger("change"); }) console.log("Values filled (after click on fillwithexpected)"); disablebuttonmakemovementandclose(); @@ -829,6 +844,7 @@ if ($object->id > 0) { $("#clearqty").on("click", function() { console.log("Clear all values"); jQuery(".realqty").val(""); + jQuery(".realqty").trigger("change"); return false; /* disable submit */ }); $(".undochangesqty").on("click", function undochangesqty() { @@ -919,7 +935,7 @@ if ($object->id > 0) { // Request to show lines of inventory (prefilled after start/validate step) $sql = 'SELECT id.rowid, id.datec as date_creation, id.tms as date_modification, id.fk_inventory, id.fk_warehouse,'; - $sql .= ' id.fk_product, id.batch, id.qty_stock, id.qty_view, id.qty_regulated, id.fk_movement, id.pmp_real, id.valuation_real'; + $sql .= ' id.fk_product, id.batch, id.qty_stock, id.qty_view, id.qty_regulated, id.fk_movement, id.pmp_real, id.pmp_expected'; $sql .= ' FROM '.MAIN_DB_PREFIX.'inventorydet as id'; $sql .= ' WHERE id.fk_inventory = '.((int) $object->id); @@ -1007,9 +1023,12 @@ if ($object->id > 0) { print ''; if(! empty($conf->global->INVENTORY_MANAGE_REAL_PMP)) { //PMP Expected - $pmp_valuation = $product_static->pmp * $valuetoshow; + if(! empty($obj->pmp_expected)) $pmp_expected = $obj->pmp_expected; + else $pmp_expected = $product_static->pmp; + $pmp_valuation = $pmp_expected * $valuetoshow; print ''; - print price($product_static->pmp); + print price($pmp_expected); + print ''; print ''; print ''; print price($pmp_valuation); @@ -1021,10 +1040,10 @@ if ($object->id > 0) { if(! empty($obj->pmp_real)) $pmp_real = $obj->pmp_real; else $pmp_real = $product_static->pmp; $pmp_valuation_real = $pmp_real * $qty_view; - print ''; + print ''; print ''; print ''; - print ''; + print ''; print ''; $totalExpectedValuation += $pmp_valuation; @@ -1043,10 +1062,11 @@ if ($object->id > 0) { print ''; if(!empty($conf->global->INVENTORY_MANAGE_REAL_PMP)) { //PMP Expected - $pmp_valuation = $product_static->pmp * $valuetoshow; - $pmp_valuation_real = $pmp_real * $obj->qty_view; + if(! empty($obj->pmp_expected)) $pmp_expected = $obj->pmp_expected; + else $pmp_expected = $product_static->pmp; + $pmp_valuation = $pmp_expected * $valuetoshow; print ''; - print price($product_static->pmp); + print price($pmp_expected); print ''; print ''; print price($pmp_valuation); @@ -1056,6 +1076,7 @@ if ($object->id > 0) { print ''; if(! empty($obj->pmp_real)) $pmp_real = $obj->pmp_real; else $pmp_real = $product_static->pmp; + $pmp_valuation_real = $pmp_real * $obj->qty_view; print price($pmp_real); print ''; print ''; @@ -1117,25 +1138,26 @@ if ($object->id > 0) {