Yii Framework Forum: where and how to calculate the stock balance using yii2 - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

where and how to calculate the stock balance using yii2

#1 User is offline   haftu hagos 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 13-April 17

Posted 13 April 2017 - 04:14 AM

Your help is too much appreciated. I am working on Stock Management System using Yii2. I am really too much happy by using the framework.And I have four Models as follows:
a. Items model which stores all items available in the store. and have the following attributes 
   return [
        [['category_id','store_id'], 'integer'],
        [['category_id','store_id','item_code'],'required'],
        [['id','item_code'],'unique'],
        [['quantity','unit_price','total_price','balance','model_19'], 'number'],
        [['category_id','store_id','item_code','entry_date', 'expire_date','specification','supplier'], 'safe'],
        [['item_code', 'item_name', 'item_type','specification','supplier'], 'string', 'max' => 45],
        [['category_id'], 'exist', 'skipOnError' => true, 'targetClass' => Category::className(), 'targetAttribute' => ['category_id' => 'id']],
    ];

   b. requested_items model which stores issued items and has the following attributes
   return [
        [['id'],'unique'],
        [['requisition_id','items_id'], 'integer'],          
        [['measurment','dept_approve','man_approve','keeper_approve'], 'string', 'max' => 45],
        [['requested','allowed'],'number'],
        [['items_id'], 'exist', 'skipOnError' => true, 'targetClass' => Items::className(), 'targetAttribute' => ['items_id' => 'id']],
        [['requisition_id'], 'exist', 'skipOnError' => true, 'targetClass' => Requisition::className(), 'targetAttribute' => ['requisition_id' => 'id']],
    ];       

  c. borrowed_items model which store which stores all list of items which are borrowed by employees and has the following attributes.
    return [
        [['id'],'unique'],
        [['borrow_id','items_id'], 'integer'],
        [['request','allowed'],'number'],          
        [['measurment','dept_approve','man_approve','keeper_approve'], 'string', 'max' => 45],
        [['items_id'], 'exist', 'skipOnError' => true, 'targetClass' => Items::className(), 'targetAttribute' => ['items_id' => 'id']],
        [['borrow_id'], 'exist', 'skipOnError' => true, 'targetClass' => Borrow::className(), 'targetAttribute' => ['borrow_id' => 'id']],
    ];

   d. returend_items model which stores all items which are returned back to the store by employees. And has the following attributes:
    return [
        [['id'],'unique'],
        [['ireturn_id','items_id'], 'integer'],
        [['amount'],'number'],          
        [['measurment','status','dept_approve','man_approve','keeper_approve'], 'string', 'max' => 45],
        [['items_id'], 'exist', 'skipOnError' => true, 'targetClass' => Items::className(), 'targetAttribute' => ['items_id' => 'id']],
        [['ireturn_id'], 'exist', 'skipOnError' => true, 'targetClass' => Ireturn::className(), 'targetAttribute' => ['ireturn_id' => 'id']],
    ];

As you can see from the above attributes of all the four models; all the three models:returend_items, borrowed_items and requested_items have a relation with the items model. so my question is:

1) if an employee returns, or borrows or issues and item, the item->balance of items model should be changed.where could I handle such calculation,(View, Model or Controller) and how?

thanks for your invaluable help.
0

#2 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,957
  • Joined: 17-January 09
  • Location:Russia

Posted 17 April 2017 - 09:10 AM

Model but in MVC terms. Not Active Record:

https://github.com/s...ok/mvc.md#model

i.e. create a separate class that is getting all the required classes/models/data in its constructor and does the calculation.
Yii 2.0 Development Cookbook

Enjoying Yii? Star us at github

Support me so I work on Yii fulltime: https://www.patreon.com/samdark
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users