Add inventory changes ( tax, net purchase price

This commit is contained in:
2017-01-06 18:24:43 +01:00
parent 6de07dac93
commit f3d00953c8
16 changed files with 547 additions and 287 deletions

View File

@@ -26,11 +26,16 @@ use common\components\ProductAwareBehavior;
* @property integer $id_user
* @property integer $id_inventory_item_prev
* @property integer $price_brutto
* @property integer $total_price_brutto
* @property string $created_at
* @property string $updated_at
* @property mixed productName
* @property mixed product
* @property integer tax
* @property integer purchase_price_net
* @property integer net_stock_money
* @property integer stock_missing_count
* @property integer stock_missing_money
* @property \common\models\InventoryGroup inventoryGroup
*/
class InventoryItem extends BaseFitnessActiveRecord
{
@@ -133,6 +138,7 @@ class InventoryItem extends BaseFitnessActiveRecord
return $result;
}
public function getInventoryGroupName(){
$result = "";
@@ -158,32 +164,6 @@ class InventoryItem extends BaseFitnessActiveRecord
return $name;
}
public function getDifference(){
$diff = $this->count - ( $this->count_prev + $this->count_in - $this->count_sold );
return $diff;
}
public function recalculateTotalPriceBrutto(){
$diff = $this->difference;
if (!isset($diff) || !is_numeric($diff)){
$diff = 0;
}
$price = $this->price_brutto;
if (!isset($price) || !is_numeric($price)){
$price = 0;
}
$this->total_price_brutto = $price * $diff;
}
public static function findNextItemAlphabetical($id_inventory_item){
@@ -227,6 +207,65 @@ class InventoryItem extends BaseFitnessActiveRecord
return null;
}
/**
* Recalculate the next values:
*
netto készlet érték
leltárhiány db
leltárhiány összeg
*
* @param boolean $insert whether this method called while inserting a record.
* If false, it means the method is called while updating a record.
* @return boolean whether the insertion or updating should continue.
* If false, the insertion or updating will be cancelled.
*/
public function beforeSave($insert)
{
$result = parent::beforeSave($insert);
if ( $result ){
if ( !isset($this->id_inventory_group) ){
$count = 0;
$purchase_price_net = 0;
$count_prev = 0;
$count_in = 0;
$count_sold = 0;
$price = 0;
if (isset($price) && is_numeric($price)){
$price = $this->price_brutto;
}
if ( isset($this->count)){
$count = $this->count;
}
if ( isset($this->purchase_price_net)){
$purchase_price_net = $this->purchase_price_net;
}
if ( isset($this->count_prev) ){
$count_prev = $this->count_prev;
}
if ( isset($this->count_in)){
$count_in = $this->count_in;
}
if ( isset($this->count_sold)){
$count_sold = $this->count_sold;
}
//netto készlet érték
$this->net_stock_money = $count * $purchase_price_net;
//leltárhiány db
$this->stock_missing_count = $this->count - ($count_prev + $count_in - $count_sold) ;
//leltárhiány összeg
$this->stock_missing_money = $price * $this->stock_missing_count;
}
}
return $result;
}
public function afterSave($insert, $changedAttributes){
if ( !$insert ){