Close #18770 : Can enter buying price on line

This commit is contained in:
lmarcouiller 2021-09-22 14:56:44 +02:00
parent 8cfccdcc5f
commit 7361941420
7 changed files with 43 additions and 9 deletions

View File

@ -103,6 +103,7 @@ class CommandeFournisseurDispatch extends CommonObjectLine
public $batch;
public $eatby = '';
public $sellby = '';
public $cost_price = 0;
@ -189,7 +190,8 @@ class CommandeFournisseurDispatch extends CommonObjectLine
$sql .= "batch,";
$sql .= "eatby,";
$sql .= "sellby,";
$sql .= "fk_reception";
$sql .= "fk_reception,";
$sql .= "cost_price";
$sql .= ") VALUES (";
@ -205,7 +207,8 @@ class CommandeFournisseurDispatch extends CommonObjectLine
$sql .= " ".(!isset($this->batch) ? 'NULL' : "'".$this->db->escape($this->batch)."'").",";
$sql .= " ".(!isset($this->eatby) || dol_strlen($this->eatby) == 0 ? 'NULL' : "'".$this->db->idate($this->eatby)."'").",";
$sql .= " ".(!isset($this->sellby) || dol_strlen($this->sellby) == 0 ? 'NULL' : "'".$this->db->idate($this->sellby)."'").",";
$sql .= " ".(!isset($this->fk_reception) ? 'NULL' : "'".$this->db->escape($this->fk_reception)."'")."";
$sql .= " ".(!isset($this->fk_reception) ? 'NULL' : "'".$this->db->escape($this->fk_reception)."'").",";
$sql .= " ".(!isset($this->cost_price) ? '0' : "'".$this->db->escape($this->cost_price)."'")."";
$sql .= ")";
$this->db->begin();

View File

@ -111,3 +111,5 @@ ALTER TABLE llx_product_lot ADD COLUMN barcode varchar(180) DEFAULT NULL;
ALTER TABLE llx_product_lot ADD COLUMN fk_barcode_type integer DEFAULT NULL;
ALTER TABLE llx_projet ADD COLUMN max_attendees integer DEFAULT 0;
ALTER TABLE llx_commande_fournisseur_dispatch ADD COLUMN cost_price double(24,8) DEFAULT 0;

View File

@ -36,5 +36,6 @@ create table llx_commande_fournisseur_dispatch
sellby date DEFAULT NULL,
status integer,
datec datetime,
tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
cost_price double(24,8) DEFAULT 0
)ENGINE=innodb;

View File

@ -45,3 +45,4 @@ ReceptionsNumberingModules=Numbering module for receptions
ReceptionsReceiptModel=Document templates for receptions
NoMorePredefinedProductToDispatch=No more predefined products to dispatch
ReceptionExist=A reception exists
ByingPrice=Bying price

View File

@ -45,3 +45,4 @@ ReceptionsNumberingModules=Module de numérotation pour les réceptions
ReceptionsReceiptModel=Modèles de document pour les réceptions
NoMorePredefinedProductToDispatch=Plus de produits prédéfinis à expédier
ReceptionExist=Une réception existe
ByingPrice=Prix d'achat

View File

@ -340,6 +340,7 @@ if (empty($reshook)) {
$eatby = "dlc".$i;
$sellby = "dluo".$i;
$batch = "batch".$i;
$cost_price = "cost_price".$i;
if (GETPOST($qty, 'int') > 0 || (GETPOST($qty, 'int') == 0 && $conf->global->RECEPTION_GETS_ALL_ORDER_PRODUCTS)) {
$ent = "entl".$i;
@ -364,8 +365,11 @@ if (empty($reshook)) {
$sellby = GETPOST($sellby, 'alpha');
$eatbydate = str_replace('/', '-', $eatby);
$sellbydate = str_replace('/', '-', $sellby);
$ret = $object->addline($entrepot_id, GETPOST($idl, 'int'), GETPOST($qty, 'int'), $array_options[$i], GETPOST($comment, 'alpha'), strtotime($eatbydate), strtotime($sellbydate), GETPOST($batch, 'alpha'));
if (!empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
$ret = $object->addline($entrepot_id, GETPOST($idl, 'int'), GETPOST($qty, 'int'), $array_options[$i], GETPOST($comment, 'alpha'), strtotime($eatbydate), strtotime($sellbydate), GETPOST($batch, 'alpha'), GETPOST($cost_price, 'double'));
} else {
$ret = $object->addline($entrepot_id, GETPOST($idl, 'int'), GETPOST($qty, 'int'), $array_options[$i], GETPOST($comment, 'alpha'), strtotime($eatbydate), strtotime($sellbydate), GETPOST($batch, 'alpha'));
}
if ($ret < 0) {
setEventMessages($object->error, $object->errors, 'errors');
$error++;
@ -989,6 +993,9 @@ if ($action == 'create') {
print '<td class="center">'.$langs->trans("QtyOrdered").'</td>';
print '<td class="center">'.$langs->trans("QtyReceived").'</td>';
print '<td class="center">'.$langs->trans("QtyToReceive");
if (!empty($conf->global->STOCK_CALCULATE_ON_RECEPTION || $conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
print '<td>'.$langs->trans("ByingPrice").'</td>';
}
if (empty($conf->productbatch->enabled)) {
print ' <br>(<a href="#" id="autofill">'.$langs->trans("Fill").'</a>';
print ' / <a href="#" id="autoreset">'.$langs->trans("Reset").'</a>)';
@ -1118,6 +1125,7 @@ if ($action == 'create') {
$stock = + $product->stock_warehouse[$dispatchLines[$indiceAsked]['ent']]->real; // Convert to number
$deliverableQty = $dispatchLines[$indiceAsked]['qty'];
$cost_price = $dispatchLines[$indiceAsked]['pu'];
// Quantity to send
print '<td class="center">';
@ -1132,6 +1140,12 @@ if ($action == 'create') {
}
print '</td>';
if (!empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
print '<td>';
print '<input name="cost_price'.$indiceAsked.'" id="cost_price'.$indiceAsked.'" value="'.$cost_price.'">';
print '</td>';
}
// Stock
if (!empty($conf->stock->enabled)) {
print '<td class="left">';

View File

@ -562,6 +562,9 @@ class Reception extends CommonObject
$sql = "SELECT cd.fk_product, cd.subprice,";
$sql .= " ed.rowid, ed.qty, ed.fk_entrepot,";
$sql .= " ed.eatby, ed.sellby, ed.batch";
if (!empty($conf->global->STOCK_CALCULATE_ON_RECEPTION || $conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
$sql .= ", ed.cost_price";
}
$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
$sql .= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
$sql .= " WHERE ed.fk_reception = ".((int) $this->id);
@ -589,7 +592,11 @@ class Reception extends CommonObject
// line without batch detail
// We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record.
$result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionValidatedInDolibarr", $numref));
if (!empty($conf->global->STOCK_CALCULATE_ON_RECEPTION || $conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
$result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans("ReceptionValidatedInDolibarr", $numref));
} else {
$result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionValidatedInDolibarr", $numref));
}
if ($result < 0) {
$error++;
$this->errors[] = $mouvS->error;
@ -601,7 +608,11 @@ class Reception extends CommonObject
// We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record.
// Note: ->fk_origin_stock = id into table llx_product_batch (may be rename into llx_product_stock_batch in another version)
$result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionValidatedInDolibarr", $numref), $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch);
if (!empty($conf->global->STOCK_CALCULATE_ON_RECEPTION || $conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
$result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans("ReceptionValidatedInDolibarr", $numref), $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch);
} else {
$result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionValidatedInDolibarr", $numref), $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch);
}
if ($result < 0) {
$error++;
$this->errors[] = $mouvS->error;
@ -704,9 +715,10 @@ class Reception extends CommonObject
* @param integer $eatby eat-by date
* @param integer $sellby sell-by date
* @param string $batch Lot number
* @param double $cost_price Line cost
* @return int <0 if KO, index of line if OK
*/
public function addline($entrepot_id, $id, $qty, $array_options = 0, $comment = '', $eatby = '', $sellby = '', $batch = '')
public function addline($entrepot_id, $id, $qty, $array_options = 0, $comment = '', $eatby = '', $sellby = '', $batch = '', $cost_price = 0)
{
global $conf, $langs, $user;
@ -746,8 +758,8 @@ class Reception extends CommonObject
$line->eatby = $eatby;
$line->sellby = $sellby;
$line->status = 1;
$line->cost_price = $cost_price;
$line->fk_reception = $this->id;
$this->lines[$num] = $line;
return $num;