public void SavingGoodsReceivedWCF(PostWCFReceivingGoodData[] goodwcflist) { PostWCFReceivingGoodData good = goodwcflist[1]; GoodsReceivedRecord grr = new GoodsReceivedRecord(); grr.POID = Convert.ToInt32(good.PoId); grr.StoreStaffID = Convert.ToInt32(good.StoreStaffID); grr.ReceivedDate = DateTime.Now; List <GoodsReceivedRecordDetail> grrdlist = new List <GoodsReceivedRecordDetail>(); foreach (PostWCFReceivingGoodData wcfgood in goodwcflist) { GoodsReceivedRecordDetail gooddetail = new GoodsReceivedRecordDetail(); gooddetail.ItemCode = wcfgood.ItemCode; gooddetail.ReceivedQuantity = Convert.ToInt32(wcfgood.Quantity); good.Remark = wcfgood.Remark; grrdlist.Add(gooddetail); } Data.SavingGoodsReceived((int)grr.POID, grr, grrdlist); }
//Saving goods received data into 5 tables public static void SavingGoodsReceived(int poid, GoodsReceivedRecord grr, List <GoodsReceivedRecordDetail> grrdlist) { Team10ADModel context = new Team10ADModel(); context.GoodsReceivedRecords.Add(grr); context.SaveChanges(); foreach (GoodsReceivedRecordDetail detail in grrdlist) { Catalogue item = context.Catalogues.Where(i => i.ItemCode == detail.ItemCode).First(); item.BalanceQuantity += detail.ReceivedQuantity; item.PendingDeliveryQuantity -= detail.ReceivedQuantity; context.SaveChanges(); detail.GoodReceiveID = grr.GoodReceiveID; detail.QuantityAfter = item.BalanceQuantity; context.GoodsReceivedRecordDetails.Add(detail); context.SaveChanges(); } List <PurchaseOrderDetail> podetaillist = context.PurchaseOrderDetails.Where(x => x.POID == poid).ToList(); foreach (PurchaseOrderDetail detail in podetaillist) { if (GetTotalGoodsReceived(poid, detail.ItemCode) >= detail.Quantity) { detail.Status = "Received"; } else if (GetTotalGoodsReceived(poid, detail.ItemCode) == 0) { detail.Status = "Unreceived"; } else { detail.Status = "Partial"; } context.SaveChanges(); } PurchaseOrder po = context.PurchaseOrders.Where(x => x.POID == poid).First(); int counter = 0; int partial = 0; foreach (PurchaseOrderDetail detail in podetaillist) { if (detail.Status == "Partial") { counter++; partial++; } else if (detail.Status == "Unreceived") { counter++; } } if (counter == 0) { po.Status = "Received"; } if (partial > 0) { po.Status = "Received"; } context.SaveChanges(); }