new pmp column
This commit is contained in:
parent
5c2c06de3b
commit
595a6c2782
@ -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_mailing ADD UNIQUE uk_mailing(titre, entity);
|
||||||
|
|
||||||
ALTER TABLE llx_inventorydet ADD COLUMN pmp_real double DEFAULT NULL;
|
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;
|
||||||
|
|
||||||
|
|||||||
@ -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_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_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.
|
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.
|
pmp_real double DEFAULT NULL,
|
||||||
valuation_real double DEFAULT NULL, -- Never used. Deprecated because we already have the fk_movement now.
|
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
|
fk_movement integer NULL -- can contain the id of stock movement we recorded to make the inventory regulation of this line
|
||||||
)
|
)
|
||||||
ENGINE=innodb;
|
ENGINE=innodb;
|
||||||
|
|||||||
@ -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_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_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)'),
|
'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_stock;
|
||||||
public $qty_view;
|
public $qty_view;
|
||||||
public $qty_regulated;
|
public $qty_regulated;
|
||||||
|
public $pmp_real;
|
||||||
|
public $pmp_expected;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -127,7 +127,7 @@ if (empty($reshook)) {
|
|||||||
$db->begin();
|
$db->begin();
|
||||||
|
|
||||||
$sql = 'SELECT id.rowid, id.datec as date_creation, id.tms as date_modification, id.fk_inventory, id.fk_warehouse,';
|
$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 .= ' FROM '.MAIN_DB_PREFIX.'inventorydet as id';
|
||||||
$sql .= ' WHERE id.fk_inventory = '.((int) $object->id);
|
$sql .= ' WHERE id.fk_inventory = '.((int) $object->id);
|
||||||
|
|
||||||
@ -176,14 +176,26 @@ if (empty($reshook)) {
|
|||||||
$datemovement = '';
|
$datemovement = '';
|
||||||
//$inventorycode = 'INV'.$object->id;
|
//$inventorycode = 'INV'.$object->id;
|
||||||
$inventorycode = 'INV-'.$object->ref;
|
$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) {
|
if ($idstockmove < 0) {
|
||||||
$error++;
|
$error++;
|
||||||
setEventMessages($stockmovment->error, $stockmovment->errors, 'errors');
|
setEventMessages($stockmovment->error, $stockmovment->errors, 'errors');
|
||||||
break;
|
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)
|
// 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 = "UPDATE ".MAIN_DB_PREFIX."inventorydet";
|
||||||
$sqlupdate .= " SET fk_movement = ".((int) $idstockmove);
|
$sqlupdate .= " SET fk_movement = ".((int) $idstockmove);
|
||||||
@ -247,6 +259,8 @@ if (empty($reshook)) {
|
|||||||
if ($result > 0) {
|
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_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->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);
|
$resultupdate = $inventoryline->update($user);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -584,6 +598,7 @@ if ($object->id > 0) {
|
|||||||
var object = $(this)[0];
|
var object = $(this)[0];
|
||||||
var objecttofill = $("#"+object.id+"_input")[0];
|
var objecttofill = $("#"+object.id+"_input")[0];
|
||||||
objecttofill.value = object.innerText;
|
objecttofill.value = object.innerText;
|
||||||
|
jQuery(".realqty").trigger("change");
|
||||||
})
|
})
|
||||||
console.log("Values filled (after click on fillwithexpected)");
|
console.log("Values filled (after click on fillwithexpected)");
|
||||||
disablebuttonmakemovementandclose();
|
disablebuttonmakemovementandclose();
|
||||||
@ -829,6 +844,7 @@ if ($object->id > 0) {
|
|||||||
$("#clearqty").on("click", function() {
|
$("#clearqty").on("click", function() {
|
||||||
console.log("Clear all values");
|
console.log("Clear all values");
|
||||||
jQuery(".realqty").val("");
|
jQuery(".realqty").val("");
|
||||||
|
jQuery(".realqty").trigger("change");
|
||||||
return false; /* disable submit */
|
return false; /* disable submit */
|
||||||
});
|
});
|
||||||
$(".undochangesqty").on("click", function undochangesqty() {
|
$(".undochangesqty").on("click", function undochangesqty() {
|
||||||
@ -919,7 +935,7 @@ if ($object->id > 0) {
|
|||||||
|
|
||||||
// Request to show lines of inventory (prefilled after start/validate step)
|
// 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 = '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 .= ' FROM '.MAIN_DB_PREFIX.'inventorydet as id';
|
||||||
$sql .= ' WHERE id.fk_inventory = '.((int) $object->id);
|
$sql .= ' WHERE id.fk_inventory = '.((int) $object->id);
|
||||||
|
|
||||||
@ -1007,9 +1023,12 @@ if ($object->id > 0) {
|
|||||||
print '</td>';
|
print '</td>';
|
||||||
if(! empty($conf->global->INVENTORY_MANAGE_REAL_PMP)) {
|
if(! empty($conf->global->INVENTORY_MANAGE_REAL_PMP)) {
|
||||||
//PMP Expected
|
//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 '<td class="right">';
|
print '<td class="right">';
|
||||||
print price($product_static->pmp);
|
print price($pmp_expected);
|
||||||
|
print '<input type="hidden" name="expectedpmp_'.$obj->rowid.'" value="'.$pmp_expected.'"/>';
|
||||||
print '</td>';
|
print '</td>';
|
||||||
print '<td class="right">';
|
print '<td class="right">';
|
||||||
print price($pmp_valuation);
|
print price($pmp_valuation);
|
||||||
@ -1021,10 +1040,10 @@ if ($object->id > 0) {
|
|||||||
if(! empty($obj->pmp_real)) $pmp_real = $obj->pmp_real;
|
if(! empty($obj->pmp_real)) $pmp_real = $obj->pmp_real;
|
||||||
else $pmp_real = $product_static->pmp;
|
else $pmp_real = $product_static->pmp;
|
||||||
$pmp_valuation_real = $pmp_real * $qty_view;
|
$pmp_valuation_real = $pmp_real * $qty_view;
|
||||||
print '<input type="text" class="maxwidth75 right realpmp'.$obj->fk_product.'" name="realpmp_'.$obj->fk_product.'" id="id_'.$obj->rowid.'_input_pmp" value="'.price2num($pmp_real).'">';
|
print '<input type="text" class="maxwidth75 right realpmp'.$obj->fk_product.'" name="realpmp_'.$obj->rowid.'" id="id_'.$obj->rowid.'_input_pmp" value="'.price2num($pmp_real).'">';
|
||||||
print '</td>';
|
print '</td>';
|
||||||
print '<td class="right">';
|
print '<td class="right">';
|
||||||
print '<input type="text" class="maxwidth75 right realvaluation'.$obj->fk_product.'" name="realvaluation_'.$obj->fk_product.'" id="id_'.$obj->rowid.'_input_real_valuation" value="'.$pmp_real * $qty_view.'">';
|
print '<input type="text" class="maxwidth75 right realvaluation'.$obj->fk_product.'" name="realvaluation_'.$obj->rowid.'" id="id_'.$obj->rowid.'_input_real_valuation" value="'.$pmp_valuation_real.'">';
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
$totalExpectedValuation += $pmp_valuation;
|
$totalExpectedValuation += $pmp_valuation;
|
||||||
@ -1043,10 +1062,11 @@ if ($object->id > 0) {
|
|||||||
print '</td>';
|
print '</td>';
|
||||||
if(!empty($conf->global->INVENTORY_MANAGE_REAL_PMP)) {
|
if(!empty($conf->global->INVENTORY_MANAGE_REAL_PMP)) {
|
||||||
//PMP Expected
|
//PMP Expected
|
||||||
$pmp_valuation = $product_static->pmp * $valuetoshow;
|
if(! empty($obj->pmp_expected)) $pmp_expected = $obj->pmp_expected;
|
||||||
$pmp_valuation_real = $pmp_real * $obj->qty_view;
|
else $pmp_expected = $product_static->pmp;
|
||||||
|
$pmp_valuation = $pmp_expected * $valuetoshow;
|
||||||
print '<td class="right">';
|
print '<td class="right">';
|
||||||
print price($product_static->pmp);
|
print price($pmp_expected);
|
||||||
print '</td>';
|
print '</td>';
|
||||||
print '<td class="right">';
|
print '<td class="right">';
|
||||||
print price($pmp_valuation);
|
print price($pmp_valuation);
|
||||||
@ -1056,6 +1076,7 @@ if ($object->id > 0) {
|
|||||||
print '<td class="right">';
|
print '<td class="right">';
|
||||||
if(! empty($obj->pmp_real)) $pmp_real = $obj->pmp_real;
|
if(! empty($obj->pmp_real)) $pmp_real = $obj->pmp_real;
|
||||||
else $pmp_real = $product_static->pmp;
|
else $pmp_real = $product_static->pmp;
|
||||||
|
$pmp_valuation_real = $pmp_real * $obj->qty_view;
|
||||||
print price($pmp_real);
|
print price($pmp_real);
|
||||||
print '</td>';
|
print '</td>';
|
||||||
print '<td class="right">';
|
print '<td class="right">';
|
||||||
@ -1117,25 +1138,26 @@ if ($object->id > 0) {
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$('.realqty').on('change', function () {
|
$('.realqty').on('change', function () {
|
||||||
let realqty = $(this).closest('tr').find('.realqty').val();
|
let realqty = $(this).closest('tr').find('.realqty').val();
|
||||||
let inputPmp = $(this).closest('tr').find('input[name^=realpmp]');
|
let inputPmp = $(this).closest('tr').find('input[class*=realpmp]');
|
||||||
let realpmp = $(inputPmp).val();
|
let realpmp = $(inputPmp).val();
|
||||||
if (!isNaN(realqty) && !isNaN(realpmp) && realpmp !== '' && realqty !== '') {
|
if (!isNaN(realqty) && !isNaN(realpmp)) {
|
||||||
let realval = realqty * realpmp;
|
let realval = realqty * realpmp;
|
||||||
$(this).closest('tr').find('input[name^=realvaluation]').val(realval.toFixed(2));
|
$(this).closest('tr').find('input[name^=realvaluation]').val(realval.toFixed(2));
|
||||||
}
|
}
|
||||||
updateTotalValuation();
|
updateTotalValuation();
|
||||||
});
|
});
|
||||||
|
|
||||||
$('input[name^=realpmp]').on('change', function () {
|
$('input[class*=realpmp]').on('change', function () {
|
||||||
let inputQtyReal = $(this).closest('tr').find('.realqty');
|
let inputQtyReal = $(this).closest('tr').find('.realqty');
|
||||||
let realqty = $(inputQtyReal).val();
|
let realqty = $(inputQtyReal).val();
|
||||||
let inputPmp = $(this).closest('tr').find('input[name^=realpmp]');
|
let inputPmp = $(this).closest('tr').find('input[class*=realpmp]');
|
||||||
|
console.log(inputPmp);
|
||||||
let realPmpClassname = $(inputPmp).attr('class').match(/[\w-]*realpmp[\w-]*/g)[0];
|
let realPmpClassname = $(inputPmp).attr('class').match(/[\w-]*realpmp[\w-]*/g)[0];
|
||||||
let realpmp = $(inputPmp).val();
|
let realpmp = $(inputPmp).val();
|
||||||
if (!isNaN(realpmp) && realpmp !== '') {
|
if (!isNaN(realpmp)) {
|
||||||
$('.'+realPmpClassname).val(realpmp); //For batch case if pmp is changed we change it everywhere it's same product and calc back everything
|
$('.'+realPmpClassname).val(realpmp); //For batch case if pmp is changed we change it everywhere it's same product and calc back everything
|
||||||
|
|
||||||
if (!isNaN(realqty) && realqty !== '') {
|
if (!isNaN(realqty)) {
|
||||||
let realval = realqty * realpmp;
|
let realval = realqty * realpmp;
|
||||||
$(this).closest('tr').find('input[name^=realvaluation]').val(realval.toFixed(2));
|
$(this).closest('tr').find('input[name^=realvaluation]').val(realval.toFixed(2));
|
||||||
}
|
}
|
||||||
@ -1147,7 +1169,7 @@ if ($object->id > 0) {
|
|||||||
$('input[name^=realvaluation]').on('change', function () {
|
$('input[name^=realvaluation]').on('change', function () {
|
||||||
let inputQtyReal = $(this).closest('tr').find('.realqty');
|
let inputQtyReal = $(this).closest('tr').find('.realqty');
|
||||||
let realqty = $(inputQtyReal).val();
|
let realqty = $(inputQtyReal).val();
|
||||||
let inputPmp = $(this).closest('tr').find('input[name^=realpmp]');
|
let inputPmp = $(this).closest('tr').find('input[class*=realpmp]');
|
||||||
let inputRealValuation = $(this).closest('tr').find('input[name^=realvaluation]');
|
let inputRealValuation = $(this).closest('tr').find('input[name^=realvaluation]');
|
||||||
let realPmpClassname = $(inputPmp).attr('class').match(/[\w-]*realpmp[\w-]*/g)[0];
|
let realPmpClassname = $(inputPmp).attr('class').match(/[\w-]*realpmp[\w-]*/g)[0];
|
||||||
let realvaluation = $(inputRealValuation).val();
|
let realvaluation = $(inputRealValuation).val();
|
||||||
@ -1165,8 +1187,12 @@ if ($object->id > 0) {
|
|||||||
let val = $(this).val();
|
let val = $(this).val();
|
||||||
if(!isNaN(val)) total += parseFloat($(this).val());
|
if(!isNaN(val)) total += parseFloat($(this).val());
|
||||||
});
|
});
|
||||||
|
let currencyFractionDigits = new Intl.NumberFormat('fr-FR', {
|
||||||
|
style: 'currency',
|
||||||
|
currency: 'EUR',
|
||||||
|
}).resolvedOptions().maximumFractionDigits;
|
||||||
$('#totalRealValuation').html(total.toLocaleString('fr-FR', {
|
$('#totalRealValuation').html(total.toLocaleString('fr-FR', {
|
||||||
style: 'currency', currency: 'EUR'
|
maximumFractionDigits: currencyFractionDigits
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user