Hi All it is my first attempt to domain driven design so please bear with me
I have two Documents in system Good Receipt
and Goods Issue
. On Approval of these documents I need to update stock movement register I have following rules
On Goods Receipts Approval.
-
Update Average Cost in material Table
-
Add row with positive Quantity and new average cost in Stock movement table
ON Goods Issue Approval
- Check Stock Balance
- Add row in material movement with negative Quantity
Below is my design so for
public class MaterialMovementEntity
{
public DateTime MovementDate { get; }
public int Quantity { get; }
public int MaterialId { get; }
public string DocInstanceType { get; }
public int DocInstaanceId { get; set; }
public MaterialMovementEntity(DateTime _MovementDate
, string _Quantity
, string _DocInstanceType
, string _MaterialID
, int _DocInstaanceId)
{
MovementDate = _MovementDate;
MaterialID = _MaterialID;
Quantity = _Quantity;
DocInstanceType = _DocInstanceType;
DocInstaanceId = _DocInstaanceId;
}
public void Stockin()
{
if(quantity<0)
//through Exception invalid quantity
//... other rule check
//Shoudl I place new Average Cost Calculation here
}
public void StockOut()
{
if (quantity>0)
{
//through Exception invalid quantity
}
StockBalance=materialservice.GetCurrentStock(MaterialID);
if(StockBalance<-1*Quantity)
{
//through Exception
}
}
}
In Calling Service
First i prepare movement object then call Stockin And Stock Out
MovementID MaterialID MovementDate Quantity AverageCost DocInstanceID DocInstanceType 1 1 2019-09-28 50 68 1 GR 2 1 2019-09-28 -10 68 1 GI 3 1 2019-09-28 15 63.09 2 GR
My Queries
- Where to do Average Cost Calculation is it a value object or child entity
- As I Prepare the movement with overloaded constructor it is ready to persist. so should i remove stockin and Stockout method and move all rules in constructor?
I am not using docinstancetype as indicator of stockin and out as more docinstance type may arise that are doing stockin and out Average cost column need to be saved in material movement also. but I am confussed how to send it during object creation
Aucun commentaire:
Enregistrer un commentaire