inventory changes
This commit is contained in:
@@ -91,6 +91,9 @@ class InventoryItemForm extends Model{
|
||||
public function save(){
|
||||
if ( $this->validate()) {
|
||||
|
||||
|
||||
$this->loadLastInventory();
|
||||
|
||||
$this->loadLastInventoryItem();
|
||||
$this->loadProductIn();
|
||||
$this->loadProductSold();
|
||||
@@ -99,7 +102,9 @@ class InventoryItemForm extends Model{
|
||||
$item = new InventoryItem();
|
||||
$item->count_in = $this->product_in;
|
||||
$item->count_sold = $this->product_out;
|
||||
$item->count = $this->product_stock;
|
||||
$item->count = $this->count;
|
||||
$item->count_system = $this->product_stock;
|
||||
|
||||
|
||||
if ( isset( $this->last_inventory_item ) ){
|
||||
$item->id_inventory_item_prev = $this->last_inventory_item->id_inventory_item;
|
||||
@@ -198,6 +203,7 @@ class InventoryItemForm extends Model{
|
||||
protected function loadLastInventoryItem( ){
|
||||
if ( isset( $this->last_inventory ) ){
|
||||
$query = InventoryItem::find();
|
||||
|
||||
$query->andWhere(['id_inventory' => $this->last_inventory->id_inventory]);
|
||||
|
||||
if ( $this->type == 'product'){
|
||||
@@ -211,8 +217,8 @@ class InventoryItemForm extends Model{
|
||||
}
|
||||
|
||||
public function read(){
|
||||
|
||||
$this->loadInventory();
|
||||
$this->loadLastInventory();
|
||||
|
||||
$this->loadProducts();
|
||||
$this->loadInventoryGroups();
|
||||
@@ -229,6 +235,14 @@ class InventoryItemForm extends Model{
|
||||
}
|
||||
public function loadLastInventory(){
|
||||
$query = Inventory::find();
|
||||
$query->innerJoin(InventoryItem::tableName(),"inventory_item.id_inventory = inventory.id_inventory");
|
||||
|
||||
if ( $this->type == 'product'){
|
||||
$query->andWhere(['inventory_item.id_product' => $this->product->id_product]);
|
||||
}else{
|
||||
$query->andWhere(['inventory_item.id_inventory_group' => $this->inventoryGroup->id_inventory_group]);
|
||||
}
|
||||
|
||||
$query->andWhere(['<', 'inventory.created_at' , $this->inventory->created_at]);
|
||||
$query->orderBy(['created_at' => SORT_DESC ]);
|
||||
$this->last_inventory =$query->limit(1)->one();
|
||||
@@ -265,7 +279,8 @@ class InventoryItemForm extends Model{
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'count' => 'Mennyiség'
|
||||
'count' => 'Mennyiség',
|
||||
'name' => "Termék/Termék csoport neve"
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user