/// <summary> /// making sure that it can update stock without violating specified /// codition in each helper method. /// </summary> /// <param name="doctype"></param> /// <param name="tranquantity"></param> /// <returns>bool</returns> public bool CanUpdateValid(SouceDocType doctype, int tranquantity) { bool canupdate = false; switch (doctype) { case SouceDocType.INVOICE: canupdate = ByInvoice(tranquantity); break; case SouceDocType.GRNTOSTORSE: canupdate = ByGrn(tranquantity); break; case SouceDocType.GTNTOSUPPLIER: canupdate = ByGtn(tranquantity); break; case SouceDocType.INVREMOVE: canupdate = ByInvoiceRemove(tranquantity); break; default: break; } return(canupdate); }
/// <summary> /// update stock quntities based on soucedocument type /// </summary> /// <param name="doctype"></param> /// <param name="quantity"></param> /// <returns>int</returns> public int MakeUpdate(SouceDocType doctype, int quantity) { int updatequantity = 0; switch (doctype) { case SouceDocType.INVOICE: this.Quntity -= quantity; break; case SouceDocType.GRNTOSTORSE: this.Quntity += quantity; break; case SouceDocType.GTNTOSUPPLIER: this.Quntity -= quantity; break; case SouceDocType.INVREMOVE: this.Quntity += quantity; break; default: break; } return(updatequantity = quantity); }
/// <summary> /// Update stock when add /delete and update trasaction happend /// in the system /// </summary> /// <param name="doctype"></param> /// <param name="productid"></param> /// <param name="quantity"></param> /// <returns>int</returns> public int UpdateStock(SouceDocType doctype, string productid, int quantity) { int updatedQty = 0; using (var stockItems = _stock.GetEnumerator()) { while (stockItems.MoveNext()) { // making sure that product is correct available and apdate is valid //one based on the soucedocument if (stockItems.Current.IsCorrectProductId(productid) && stockItems.Current.CanUpdateValid(doctype, quantity)) { // update stock based on the souce document type updatedQty += stockItems.Current.MakeUpdate(doctype, quantity); } } } return(updatedQty); }