clean code
This commit is contained in:
parent
04bfbb5723
commit
0d3fdbe408
@ -216,11 +216,6 @@ class BOM extends CommonObject
|
|||||||
*/
|
*/
|
||||||
public $lines = array();
|
public $lines = array();
|
||||||
|
|
||||||
/**
|
|
||||||
* @var BOMLine Bom line
|
|
||||||
*/
|
|
||||||
public $line;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int Calculated cost for the BOM
|
* @var int Calculated cost for the BOM
|
||||||
*/
|
*/
|
||||||
@ -232,7 +227,6 @@ class BOM extends CommonObject
|
|||||||
public $unit_cost = 0;
|
public $unit_cost = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
@ -632,33 +626,33 @@ class BOM extends CommonObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Insert line
|
// Insert line
|
||||||
$this->line = new BOMLine($this->db);
|
$line = new BOMLine($this->db);
|
||||||
|
|
||||||
$this->line->context = $this->context;
|
$line->context = $this->context;
|
||||||
|
|
||||||
$this->line->fk_bom = $this->id;
|
$line->fk_bom = $this->id;
|
||||||
$this->line->fk_product = $fk_product;
|
$line->fk_product = $fk_product;
|
||||||
$this->line->qty = $qty;
|
$line->qty = $qty;
|
||||||
$this->line->qty_frozen = $qty_frozen;
|
$line->qty_frozen = $qty_frozen;
|
||||||
$this->line->disable_stock_change = $disable_stock_change;
|
$line->disable_stock_change = $disable_stock_change;
|
||||||
$this->line->efficiency = $efficiency;
|
$line->efficiency = $efficiency;
|
||||||
$this->line->fk_bom_child = $fk_bom_child;
|
$line->fk_bom_child = $fk_bom_child;
|
||||||
$this->line->import_key = $import_key;
|
$line->import_key = $import_key;
|
||||||
$this->line->position = $rankToUse;
|
$line->position = $rankToUse;
|
||||||
$this->line->fk_unit = $fk_unit;
|
$line->fk_unit = $fk_unit;
|
||||||
|
|
||||||
if (is_array($array_options) && count($array_options) > 0) {
|
if (is_array($array_options) && count($array_options) > 0) {
|
||||||
$this->line->array_options = $array_options;
|
$line->array_options = $array_options;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->line->create($user);
|
$result = $line->create($user);
|
||||||
|
|
||||||
if ($result > 0) {
|
if ($result > 0) {
|
||||||
$this->calculateCosts();
|
$this->calculateCosts();
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return $result;
|
return $result;
|
||||||
} else {
|
} else {
|
||||||
$this->error = $this->line->error;
|
$this->error = $line->error;
|
||||||
dol_syslog(get_class($this)."::addLine error=".$this->error, LOG_ERR);
|
dol_syslog(get_class($this)."::addLine error=".$this->error, LOG_ERR);
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -2;
|
return -2;
|
||||||
@ -727,8 +721,7 @@ class BOM extends CommonObject
|
|||||||
|
|
||||||
$staticLine = clone $line;
|
$staticLine = clone $line;
|
||||||
$line->oldcopy = $staticLine;
|
$line->oldcopy = $staticLine;
|
||||||
$this->line = $line;
|
$line->context = $this->context;
|
||||||
$this->line->context = $this->context;
|
|
||||||
|
|
||||||
// Rank to use
|
// Rank to use
|
||||||
$rankToUse = (int) $position;
|
$rankToUse = (int) $position;
|
||||||
@ -746,32 +739,32 @@ class BOM extends CommonObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$this->line->fk_bom = $this->id;
|
$line->fk_bom = $this->id;
|
||||||
$this->line->qty = $qty;
|
$line->qty = $qty;
|
||||||
$this->line->qty_frozen = $qty_frozen;
|
$line->qty_frozen = $qty_frozen;
|
||||||
$this->line->disable_stock_change = $disable_stock_change;
|
$line->disable_stock_change = $disable_stock_change;
|
||||||
$this->line->efficiency = $efficiency;
|
$line->efficiency = $efficiency;
|
||||||
$this->line->import_key = $import_key;
|
$line->import_key = $import_key;
|
||||||
$this->line->position = $rankToUse;
|
$line->position = $rankToUse;
|
||||||
if (!empty($fk_unit)) {
|
if (!empty($fk_unit)) {
|
||||||
$this->line->fk_unit = $fk_unit;
|
$line->fk_unit = $fk_unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($array_options) && count($array_options) > 0) {
|
if (is_array($array_options) && count($array_options) > 0) {
|
||||||
// We replace values in this->line->array_options only for entries defined into $array_options
|
// We replace values in this->line->array_options only for entries defined into $array_options
|
||||||
foreach ($array_options as $key => $value) {
|
foreach ($array_options as $key => $value) {
|
||||||
$this->line->array_options[$key] = $array_options[$key];
|
$line->array_options[$key] = $array_options[$key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->line->update($user);
|
$result = $line->update($user);
|
||||||
|
|
||||||
if ($result > 0) {
|
if ($result > 0) {
|
||||||
$this->calculateCosts();
|
$this->calculateCosts();
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return $result;
|
return $result;
|
||||||
} else {
|
} else {
|
||||||
$this->error = $this->line->error;
|
$this->error = $line->error;
|
||||||
dol_syslog(get_class($this)."::addLine error=".$this->error, LOG_ERR);
|
dol_syslog(get_class($this)."::addLine error=".$this->error, LOG_ERR);
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -2;
|
return -2;
|
||||||
@ -806,10 +799,9 @@ class BOM extends CommonObject
|
|||||||
|
|
||||||
$staticLine = clone $line;
|
$staticLine = clone $line;
|
||||||
$line->oldcopy = $staticLine;
|
$line->oldcopy = $staticLine;
|
||||||
$this->line = $line;
|
$line->context = $this->context;
|
||||||
$this->line->context = $this->context;
|
|
||||||
|
|
||||||
$result = $this->line->delete($user, $notrigger);
|
$result = $line->delete($user, $notrigger);
|
||||||
|
|
||||||
//Positions (rank) reordering
|
//Positions (rank) reordering
|
||||||
foreach ($this->lines as $bl) {
|
foreach ($this->lines as $bl) {
|
||||||
@ -824,7 +816,7 @@ class BOM extends CommonObject
|
|||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return $result;
|
return $result;
|
||||||
} else {
|
} else {
|
||||||
$this->error = $this->line->error;
|
$this->error = $line->error;
|
||||||
dol_syslog(get_class($this)."::addLine error=".$this->error, LOG_ERR);
|
dol_syslog(get_class($this)."::addLine error=".$this->error, LOG_ERR);
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -2;
|
return -2;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user