public void UpdateRefreshData(int psID) { try { using (SASEntitiesEDM objEntities = new SASEntitiesEDM()) { ProductsAndService pands = objEntities.ProductsAndServices.Where(p => p.ID == psID).SingleOrDefault(); if (pands != null) { pands.IsRefresh = true; pands.RefreshDate = DateTime.Now.Date; objEntities.SaveChanges(); } List <ProductsAndService> pandsOther = objEntities.ProductsAndServices.Where(e => e.ID != psID).ToList(); if (pandsOther != null) { foreach (var item in pandsOther) { item.IsRefresh = false; item.RefreshDate = null; objEntities.SaveChanges(); } } } } catch (Exception ex) { throw ex; } }
public int SaveCountAndAdjustStock(CountAndAdjustStockForm casForm) { try { using (SASEntitiesEDM entities = new SASEntitiesEDM()) { foreach (var item in casForm.CountAndAdjustStockDetails) { StockCount obj = new StockCount(); obj.Stock_count_no = casForm.CountAndAdjustStock.StockCountNo; obj.StockDate = casForm.CountAndAdjustStock.StockDate; obj.StockType = casForm.CountAndAdjustStock.StockType; //saving details entity obj.PSID = item.PSID; obj.PandS_Code = item.PandSCode; obj.PandS_Name = item.PandSName; //obj.SysQty = Math.Abs(Convert.ToInt32(item.SystemQty)); obj.SysQty = item.SystemQty; obj.CountQty = item.CountQty; obj.Difference = item.Difference; obj.Average_Cost = Convert.ToDecimal(item.AvgCost); obj.Amount = item.Amount; obj.Adjusted_Amount = Convert.ToDecimal(item.AdjustedAmount); obj.UpdatedBy = 0; obj.UpdatedDate = DateTime.Now; entities.StockCounts.Add(obj); entities.SaveChanges(); ProductsAndService ps = entities.ProductsAndServices.SingleOrDefault(e => e.ID == item.PSID); if (ps != null) { if (casForm.CountAndAdjustStock.StockType == Convert.ToByte(Stock_Type.StockTake)) { ps.PandS_Qty_in_stock = ps.PandS_Qty_in_stock + item.Difference; ps.PandS_Stock_Value = ps.PandS_Stock_Value - Convert.ToDecimal(item.AdjustedAmount); entities.SaveChanges(); } else { ps.PandS_Qty_in_stock = ps.PandS_Qty_in_stock + item.Difference; entities.SaveChanges(); } } } } } catch (Exception ex) { return(0); throw ex; } return(1); }
public bool DeleteQuotatoin(int pqID) { bool result = false; try { using (SASEntitiesEDM entities = new SASEntitiesEDM()) { var detailList = entities.SalesOrderDetails.Where(x => x.SO_ID == pqID).ToList(); if (detailList != null) { foreach (SalesOrderDetail pqdetail in detailList) { int PSId = Convert.ToInt32(pqdetail.SO_No); if (PSId != 0) { ProductsAndService ps = entities.ProductsAndServices.SingleOrDefault(e => e.ID == PSId); if (ps != null) { ps.PandS_Qty_for_SO = ps.PandS_Qty_for_SO - pqdetail.SO_Qty; entities.SaveChanges(); } } pqdetail.SO_Qty = 0; pqdetail.SO_Price = 0; pqdetail.SO_Discount = 0; pqdetail.SO_Amount = 0; pqdetail.GST_Rate = 0; entities.SaveChanges(); } } var obj = entities.SalesOrders.Where(x => x.ID == pqID).FirstOrDefault(); //entities.SalesOrders.Remove(obj); if (obj != null) { obj.SO_Status = Convert.ToByte(PO_Status.Cancelled); obj.SO_Tot_bef_Tax = 0; obj.SO_Tot_aft_Tax = 0; obj.SO_GST_Amt = 0; obj.IsDeleted = true; obj.ModifiedDate = DateTime.Now; entities.SaveChanges(); } } result = true; } catch { result = false; } return(result); }
public void UpdatePandS(PandSDetailsModel pandsModel) { try { using (SASEntitiesEDM objEntities = new SASEntitiesEDM()) { ProductsAndService pands = objEntities.ProductsAndServices.Where(p => p.ID == pandsModel.ID).SingleOrDefault(); if (pands != null) { pands.PandS_Code = pandsModel.PSCode; pands.PandS_Name = pandsModel.PSName; pands.PandS_Type = pandsModel.PSType; pands.PandS_Cat1 = pandsModel.PSCategory1; pands.PandS_Cat2 = pandsModel.PSCategory2; pands.Tax_Rate = pandsModel.TaxRate; pands.Tax_ID = pandsModel.TaxID; pands.PandS_Description = pandsModel.PSDescription; pands.PandS_Inactive = pandsModel.IsInActive == null ? null : pandsModel.IsInActive; pands.PandS_Stock_Picture = pandsModel.ImgSource; //Standard Sell and cost price pands.PandS_Std_Sell_Price_bef_GST = Convert.ToDecimal(pandsModel.StandardSellPriceBeforeGST); pands.PandS_Std_Sell_Price_aft_GST = Convert.ToDecimal(pandsModel.StandardSellPriceAfterGST); pands.PandS_Std_Cost_Price_bef_GST = Convert.ToDecimal(pandsModel.StandardCostpriceBeforeGST); pands.PandS_Std_Cost_Price_aft_GST = Convert.ToDecimal(pandsModel.StandardCostpriceAfterGST); //Average pands.PandS_Ave_Sell_Price_bef_GST = Convert.ToDecimal(pandsModel.AverageSellPriceBeforeGST); pands.PandS_Ave_Sell_Price_aft_GST = Convert.ToDecimal(pandsModel.AverageSellPriceAfterGST); pands.PandS_Ave_Cost_Price_bef_GST = Convert.ToDecimal(pandsModel.AverageCostPriceBeforeGST); pands.PandS_Ave_Cost_Price_aft_GST = Convert.ToDecimal(pandsModel.AverageCostPriceAfterGST); //Last pands.PandS_Last_Sold_Price_bef_GST = Convert.ToDecimal(pandsModel.LastSoldPriceBeforeGST); pands.PandS_Last_Sold_Price_aft_GST = Convert.ToDecimal(pandsModel.LastSoldPriceAfterGST); pands.PandS_Last_Pur_Price_bef_GST = Convert.ToDecimal(pandsModel.LastPurchasePriceBeforeGST); pands.PandS_Last_Pur_Price_aft_GST = Convert.ToDecimal(pandsModel.LastPurchasePriceAfterGST); //Stock pands.PandS_Min_Qty = pandsModel.MinimumQuantity; pands.PandS_Qty_in_stock = pandsModel.QuantityInStock; pands.PandS_Qty_for_SO = pandsModel.ReservedForSalesOrders; pands.PandS_Qty_on_PO = pandsModel.OnPurchaseOrders; pands.PandS_Stock_Value = pandsModel.StockValue; pands.ModifiedBy = pandsModel.LoggedinUserID; pands.ModifiedDate = DateTime.Now; pands.IsRefresh = false; pands.RefreshDate = null; objEntities.SaveChanges(); } } } catch (Exception ex) { throw ex; } }
public void DeletePandS(PandSDetailsModel pandsModel) { try { using (SASEntitiesEDM objEntities = new SASEntitiesEDM()) { ProductsAndService pands = objEntities.ProductsAndServices.Where(p => p.ID == pandsModel.ID).SingleOrDefault(); if (pands != null) { pands.IsDeleted = true; pands.ModifiedBy = pandsModel.LoggedinUserID; pands.ModifiedDate = DateTime.Now; objEntities.SaveChanges(); } } } catch (Exception ex) { throw ex; } }
/// <summary> /// This method is used to add or edit purchase invoice /// </summary> /// <param name="invoiceData"></param> /// <returns></returns> public int AddUpdateInvoice(SalesInvoiceForm invoiceData) { int autoId = 0; //Add purchase invoice SalesInvoice obj = new SalesInvoice(); obj.ID = invoiceData.Invoice.ID; obj.Cus_Id = invoiceData.Invoice.CustomerID; obj.SI_Date = invoiceData.Invoice.InvoiceDate; obj.SI_GST_Amt = Convert.ToDecimal(invoiceData.Invoice.TotalTax); obj.SI_No = invoiceData.Invoice.InvoiceNo; obj.SI_TandC = invoiceData.Invoice.TermsAndConditions; obj.SI_Tot_aft_Tax = Convert.ToDecimal(invoiceData.Invoice.TotalAfterTax); obj.SI_Tot_bef_Tax = Convert.ToDecimal(invoiceData.Invoice.TotalBeforeTax); obj.Cus_PO_No = invoiceData.Invoice.OurSONo; obj.SI_Credit_Days = invoiceData.Invoice.CreditDays; obj.Salesman = invoiceData.Invoice.SalesmanID; obj.Exc_Inc_GST = invoiceData.Invoice.ExcIncGST; obj.SI_Status = Convert.ToByte(SI_Status.UnPaid); obj.IsDeleted = false; try { using (SDNSalesDBEntities entities = new SDNSalesDBEntities()) { if (entities.SalesInvoices.AsNoTracking().FirstOrDefault(x => x.ID == invoiceData.Invoice.ID) == null) { //obj.CreatedBy = invoiceData.SIModel.CreatedBy; obj.CreatedDate = DateTime.Now; entities.SalesInvoices.Add(obj); entities.SaveChanges(); autoId = obj.ID; } else { // obj.ModifiedBy = invoiceData.SIModel.ModifiedBy; obj.ModifiedDate = DateTime.Now; entities.Entry(obj).State = EntityState.Modified; autoId = entities.SaveChanges(); } invoiceData.Invoice.ID = autoId; CreateCreditNote(invoiceData); if (autoId > 0) { SalesInvoiceDetail SIDetails; if (invoiceData.InvoiceDetails != null) { foreach (SalesInvoiceDetailEntity SIDetailEntity in invoiceData.InvoiceDetails) { SIDetails = new SalesInvoiceDetail(); SIDetails.SI_ID = autoId; SIDetails.SI_No = SIDetailEntity.SINo; SIDetails.PandS_Code = SIDetailEntity.PandSCode; SIDetails.PandS_Name = SIDetailEntity.PandSName; SIDetails.SI_Amount = SIDetailEntity.SIAmount; SIDetails.SI_Discount = SIDetailEntity.SIDiscount; SIDetails.SI_No = SIDetailEntity.SINo; SIDetails.SI_Price = Convert.ToDecimal(SIDetailEntity.SIPrice); SIDetails.SI_Qty = SIDetailEntity.SIQty; SIDetails.GST_Code = SIDetailEntity.GSTCode; SIDetails.GST_Rate = SIDetailEntity.GSTRate; if (entities.SalesInvoiceDetails.AsNoTracking().FirstOrDefault(x => x.ID == SIDetailEntity.ID) == null) { entities.SalesInvoiceDetails.Add(SIDetails); entities.SaveChanges(); } else { entities.Entry(SIDetails).State = EntityState.Modified; entities.SaveChanges(); } int SIId = Convert.ToInt32(SIDetailEntity.SINo); ProductsAndService ps = entities.ProductsAndServices.SingleOrDefault(e => e.ID == SIId); if (ps != null) { if (ps.PandS_Qty_in_stock != null || ps.PandS_Qty_in_stock >= 0) { ps.PandS_Qty_in_stock = ps.PandS_Qty_in_stock - SIDetailEntity.SIQty; entities.SaveChanges(); } } } } } } return(autoId); } catch (Exception ex) { throw ex; } }
public int ConvertToSalesInvoice(SalesOrderForm orderData) { int autoId = 0; //Add sales order SalesInvoice obj = new SalesInvoice(); // obj.ID = orderData.Order.ID; obj.Cus_Id = orderData.Order.CustomerID; obj.SI_Date = orderData.Order.OrderDate; obj.SI_GST_Amt = Convert.ToDecimal(orderData.Order.TotalTax); obj.SI_No = "SI-" + (GetLastInvoiceNo() + 1); obj.SI_TandC = orderData.Order.TermsAndConditions; obj.SI_Tot_aft_Tax = Convert.ToDecimal(orderData.Order.TotalAfterTax); obj.SI_Tot_bef_Tax = Convert.ToDecimal(orderData.Order.TotalBeforeTax); obj.SI_Status = 2; obj.Exc_Inc_GST = orderData.Order.ExcIncGST; obj.IsDeleted = false; try { using (SASEntitiesEDM entities = new SASEntitiesEDM()) { if (entities.SalesInvoices.AsNoTracking().FirstOrDefault(x => x.ID == orderData.Order.ID) == null) { //obj.CreatedBy = orderData.SOModel.CreatedBy; obj.CreatedDate = DateTime.Now; entities.SalesInvoices.Add(obj); entities.SaveChanges(); autoId = obj.ID; } else { // obj.ModifiedBy = orderData.SOModel.ModifiedBy; obj.ModifiedDate = DateTime.Now; entities.Entry(obj).State = EntityState.Modified; autoId = entities.SaveChanges(); } if (autoId > 0) { SalesInvoiceDetail SODetails; if (orderData.OrderDetails != null) { foreach (SalesOrderDetailEntity SODetailEntity in orderData.OrderDetails) { SODetails = new SalesInvoiceDetail(); SODetails.SI_ID = autoId; SODetails.SI_No = SODetailEntity.SONo; SODetails.PandS_Code = SODetailEntity.PandSCode; SODetails.PandS_Name = SODetailEntity.PandSName; SODetails.SI_Amount = SODetailEntity.SOAmount; SODetails.SI_Discount = SODetailEntity.SODiscount; SODetails.SI_No = SODetailEntity.SONo; SODetails.SI_Price = Convert.ToDecimal(SODetailEntity.SOPrice); SODetails.SI_Qty = SODetailEntity.SOQty; SODetails.GST_Code = SODetailEntity.GSTCode; SODetails.GST_Rate = SODetailEntity.GSTRate; if (entities.SalesInvoiceDetails.AsNoTracking().FirstOrDefault(x => x.ID == SODetailEntity.ID) == null) { entities.SalesInvoiceDetails.Add(SODetails); entities.SaveChanges(); } else { entities.Entry(SODetails).State = EntityState.Modified; entities.SaveChanges(); } int PSId = Convert.ToInt32(SODetailEntity.SONo); if (PSId != 0) { ProductsAndService ps = entities.ProductsAndServices.SingleOrDefault(e => e.ID == PSId); if (ps != null) { ps.PandS_Qty_in_stock = ps.PandS_Qty_in_stock - SODetailEntity.SOQty; entities.SaveChanges(); } } } } SalesOrder objQ = entities.SalesOrders.Where(e => e.SO_No == orderData.Order.OrderNo ).SingleOrDefault(); if (objQ != null) { objQ.SO_Conv_to_SI = true; objQ.Conv_to_No = obj.SI_No; objQ.ModifiedDate = DateTime.Now; entities.SaveChanges(); } } } return(autoId); } catch (Exception ex) { throw ex; } }
public int UpdationOrder(SalesOrderForm orderData) { try { using (SASEntitiesEDM entities = new SASEntitiesEDM()) { SalesOrder obj = entities.SalesOrders.Where(e => e.SO_No == orderData.Order.OrderNo ).SingleOrDefault(); if (obj != null) { //obj.ID = orderData.Order.ID; obj.Cus_Id = orderData.Order.CustomerID; // obj.SO_Conv_to_SO = orderData.Order.SO_Conv_to_SO; // obj.SO_Conv_to_SI = orderData.Order.SO_Conv_to_SI; obj.SO_Date = orderData.Order.OrderDate; obj.SO_GST_Amt = Convert.ToDecimal(orderData.Order.TotalTax); obj.SO_No = orderData.Order.OrderNo; obj.SO_TandC = orderData.Order.TermsAndConditions; obj.SO_Tot_aft_Tax = Convert.ToDecimal(orderData.Order.TotalAfterTax); obj.SO_Tot_bef_Tax = Convert.ToDecimal(orderData.Order.TotalBeforeTax); //obj.SO_Valid_for = orderData.Order.ValidForDays; obj.SO_Del_Date = orderData.Order.DeliveryDate; obj.Cus_PO_No = orderData.Order.Cus_Po_No; obj.Exc_Inc_GST = orderData.Order.ExcIncGST; obj.ModifiedDate = DateTime.Now; entities.SaveChanges(); } var objSales = entities.SalesOrderDetails.Where (e => e.SO_ID == obj.ID).ToList(); if (objSales != null) { foreach (var item in objSales) { int PSId = Convert.ToInt32(item.SO_No); if (PSId != 0) { ProductsAndService ps = entities.ProductsAndServices.SingleOrDefault(e => e.ID == PSId); if (ps != null) { ps.PandS_Qty_for_SO = ps.PandS_Qty_for_SO - item.SO_Qty; entities.SaveChanges(); } } entities.SalesOrderDetails.Remove(item); entities.SaveChanges(); } } SalesOrderDetail SODetails; if (orderData.OrderDetails != null) { foreach (SalesOrderDetailEntity SODetailEntity in orderData.OrderDetails) { SODetails = new SalesOrderDetail(); SODetails.SO_ID = obj.ID; SODetails.SO_No = SODetailEntity.SONo; SODetails.PandS_Code = SODetailEntity.PandSCode; SODetails.PandS_Name = SODetailEntity.PandSName; SODetails.SO_Amount = SODetailEntity.SOAmount; SODetails.SO_Discount = SODetailEntity.SODiscount; SODetails.SO_No = SODetailEntity.SONo; SODetails.SO_Price = Convert.ToDecimal(SODetailEntity.SOPrice); SODetails.SO_Qty = SODetailEntity.SOQty; SODetails.GST_Code = SODetailEntity.GSTCode; SODetails.GST_Rate = SODetailEntity.GSTRate; entities.SalesOrderDetails.Add(SODetails); entities.SaveChanges(); int PSId = Convert.ToInt32(SODetailEntity.SONo); if (PSId != 0) { ProductsAndService ps = entities.ProductsAndServices.SingleOrDefault(e => e.ID == PSId); if (ps != null) { ps.PandS_Qty_for_SO = ps.PandS_Qty_for_SO + SODetailEntity.SOQty; entities.SaveChanges(); } } } } return(obj.ID); } } catch (Exception ex) { throw ex; } }
/// <summary> /// This method is used to add or edit sales order /// </summary> /// <param name="orderData"></param> /// <returns></returns> public int AddUpdateOrder(SalesOrderForm orderData) { int autoId = 0; //Add sales order SalesOrder obj = new SalesOrder(); obj.ID = orderData.Order.ID; obj.Cus_Id = orderData.Order.CustomerID; //obj.SO_Conv_to_SO = orderData.Order.SO_Conv_to_SO; obj.SO_Conv_to_SI = orderData.Order.SO_Conv_to_SI; obj.SO_Date = orderData.Order.OrderDate; obj.SO_GST_Amt = Convert.ToDecimal(orderData.Order.TotalTax); obj.SO_No = orderData.Order.OrderNo; obj.SO_TandC = orderData.Order.TermsAndConditions; obj.SO_Tot_aft_Tax = Convert.ToDecimal(orderData.Order.TotalAfterTax); obj.SO_Tot_bef_Tax = Convert.ToDecimal(orderData.Order.TotalBeforeTax); //obj.SO_Valid_for = orderData.Order.ValidForDays; obj.SO_Del_Date = orderData.Order.DeliveryDate; obj.Cus_PO_No = orderData.Order.Cus_Po_No; obj.Exc_Inc_GST = orderData.Order.ExcIncGST; obj.IsDeleted = false; try { using (SASEntitiesEDM entities = new SASEntitiesEDM()) { if (entities.SalesOrders.AsNoTracking().FirstOrDefault(x => x.ID == orderData.Order.ID) == null) { //obj.CreatedBy = orderData.SOModel.CreatedBy; obj.CreatedDate = DateTime.Now; entities.SalesOrders.Add(obj); entities.SaveChanges(); autoId = obj.ID; } else { // obj.ModifiedBy = orderData.SOModel.ModifiedBy; obj.ModifiedDate = DateTime.Now; entities.Entry(obj).State = EntityState.Modified; autoId = entities.SaveChanges(); } if (autoId > 0) { SalesOrderDetail SODetails; if (orderData.OrderDetails != null) { foreach (SalesOrderDetailEntity SODetailEntity in orderData.OrderDetails) { SODetails = new SalesOrderDetail(); SODetails.SO_ID = autoId; SODetails.SO_No = SODetailEntity.SONo; SODetails.PandS_Code = SODetailEntity.PandSCode; SODetails.PandS_Name = SODetailEntity.PandSName; SODetails.SO_Amount = SODetailEntity.SOAmount; SODetails.SO_Discount = SODetailEntity.SODiscount; SODetails.SO_No = SODetailEntity.SONo; SODetails.SO_Price = Convert.ToDecimal(SODetailEntity.SOPrice); SODetails.SO_Qty = SODetailEntity.SOQty; SODetails.GST_Code = SODetailEntity.GSTCode; SODetails.GST_Rate = SODetailEntity.GSTRate; if (entities.SalesOrderDetails.AsNoTracking().FirstOrDefault(x => x.ID == SODetailEntity.ID) == null) { entities.SalesOrderDetails.Add(SODetails); entities.SaveChanges(); } else { entities.Entry(SODetails).State = EntityState.Modified; entities.SaveChanges(); } int PSId = Convert.ToInt32(SODetailEntity.SONo); if (PSId != 0) { ProductsAndService ps = entities.ProductsAndServices.SingleOrDefault(e => e.ID == PSId); if (ps != null) { ps.PandS_Qty_for_SO = ps.PandS_Qty_for_SO + SODetailEntity.SOQty; entities.SaveChanges(); } } } } } } return(autoId); } catch (Exception ex) { throw ex; } }
public void getPandsDetailsList(List <PandS_Details> pands, bool RUBool) { List <PandS_Details> duplicate = new List <PandS_Details>(); List <PandS_Details> unique = new List <PandS_Details>(); var PandServiceResult = (from c1 in entities.Categories join c2 in entities.ProductsAndServices on c1.ID equals c2.ID select new { masterId = c1.ID, c2.Tax_ID, c1.Cat_Code }).ToList(); List <PandS_Details> productandservicesource = entities.ProductsAndServices.Where(x => x.IsDeleted != true).Select(x => new PandS_Details { Product_and_Service_Type = x.PandS_Type, Isinactive = x.PandS_Inactive, PandS_Code = x.PandS_Code, PandS_Name = x.PandS_Name, Category1 = (x.PandS_Cat1 == null ? "0" : Convert.ToString(x.PandS_Cat1)), Category2 = (x.PandS_Cat2 == null ? "0" : Convert.ToString(x.PandS_Cat2)), Description = x.PandS_Description, Tax_Rate = (x.Tax_Rate == null ? "" : Convert.ToString(x.Tax_Rate)), Std_Cost_Price_bef_Tax = x.PandS_Ave_Cost_Price_bef_GST == null ? "" : Convert.ToString(x.PandS_Ave_Cost_Price_bef_GST), Std_Cost_Price_aft_Tax = x.PandS_Ave_Sell_Price_aft_GST == null ? "" : Convert.ToString(x.PandS_Ave_Sell_Price_aft_GST), }).OrderBy(e => e.PandS_Code).ToList(); var namearray = (from PabdServices in productandservicesource select PabdServices.PandS_Code).ToArray(); duplicate = (from PandSlist in pands where namearray.Contains(PandSlist.PandS_Code) select PandSlist).ToList(); unique = pands.Except(duplicate).ToList(); var ThirdList = productandservicesource.Except(pands).ToList(); if (RUBool == true) { try { foreach (var item in unique) { ProductsAndService taxCodesAndRate = new ProductsAndService() { PandS_Type = item.Product_and_Service_Type, PandS_Inactive = item.Isinactive, PandS_Code = item.PandS_Code, PandS_Name = item.PandS_Name, //PandS_Cat1 = (item.Category1 == string.Empty ? null as int ? : Convert.ToInt32(item.Category1)), //PandS_Cat2 = (item.Category2 == string.Empty ? null as int ? : Convert.ToInt32(item.Category2)), PandS_Description = item.Description, Tax_Rate = (item.Tax_Rate == string.Empty ? null as decimal? : Convert.ToDecimal(item.Tax_Rate)), PandS_Ave_Cost_Price_bef_GST = item.Ave_Cost_Price_bef_Tax == string.Empty ? null as decimal? : Convert.ToDecimal(item.Ave_Cost_Price_bef_Tax), PandS_Ave_Cost_Price_aft_GST = item.Ave_Cost_Price_aft_Tax == string.Empty ? null as decimal? : Convert.ToDecimal(item.Ave_Cost_Price_aft_Tax), }; var category1 = PandServiceResult.Where(p => p.Cat_Code == item.PandS_Code).FirstOrDefault(); taxCodesAndRate.PandS_Cat1 = (category1 == null) ? 0 : category1.Tax_ID; var category2 = PandServiceResult.Where(p => p.Cat_Code == item.PandS_Code).FirstOrDefault(); taxCodesAndRate.PandS_Cat2 = (category2 == null) ? 0 : category2.Tax_ID; entities.ProductsAndServices.Add(taxCodesAndRate); entities.SaveChanges(); } } catch (Exception e) { throw e; } } else { try { foreach (var item in ThirdList) { var pandservices = entities.ProductsAndServices.FirstOrDefault(x => x.PandS_Name == item.PandS_Code); pandservices.PandS_Type = item.Product_and_Service_Type; pandservices.PandS_Inactive = item.Isinactive; pandservices.PandS_Code = item.PandS_Code; pandservices.PandS_Name = item.PandS_Name; pandservices.PandS_Cat1 = (item.Category1 == string.Empty ? null as int? : Convert.ToInt32(item.Category1)); pandservices.PandS_Cat2 = (item.Category2 == string.Empty ? null as int? : Convert.ToInt32(item.Category2)); pandservices.PandS_Description = item.Description; pandservices.Tax_Rate = (item.Tax_Rate == string.Empty ? null as decimal? : Convert.ToDecimal(item.Tax_Rate)); pandservices.PandS_Ave_Cost_Price_bef_GST = item.Ave_Cost_Price_bef_Tax == string.Empty ? null as decimal? : Convert.ToDecimal(item.Ave_Cost_Price_bef_Tax); pandservices.PandS_Ave_Cost_Price_aft_GST = item.Ave_Cost_Price_aft_Tax == string.Empty ? null as decimal? : Convert.ToDecimal(item.Ave_Cost_Price_aft_Tax); entities.SaveChanges(); } } catch (Exception e) { throw e; } } }
public int DeleteInvoice(string pqNo) { int SIStatus = 0; try { using (SDNSalesDBEntities entities = new SDNSalesDBEntities()) { var SInvoice = entities.SalesInvoices.Where(e => e.SI_No == pqNo).FirstOrDefault(); if (SInvoice != null) { var SO_SI = entities.CashAndBankTransactions.Where(x => x.SO_CN_PO_DN_No == pqNo ).FirstOrDefault(); if (SO_SI != null) { if (SO_SI.Amt_Due != null) { SInvoice.SI_Status = Convert.ToByte(SI_Status.UnPaid); SIStatus = Convert.ToByte(SI_Status.UnPaid); } else { SInvoice.SI_Status = Convert.ToByte(SI_Status.Paid); SIStatus = Convert.ToByte(SI_Status.Paid); } } else { SInvoice.SI_Status = Convert.ToByte(SI_Status.Cancelled); SIStatus = Convert.ToByte(SI_Status.Cancelled); SInvoice.SI_Tot_bef_Tax = 0; SInvoice.SI_Tot_aft_Tax = 0; SInvoice.SI_GST_Amt = 0; entities.SaveChanges(); var pd = entities.SalesInvoiceDetails.Where(e => e.SI_ID == SInvoice.ID).ToList(); if (pd != null) { foreach (var item in pd) { int PSId = Convert.ToInt32(item.SI_No); if (PSId != 0) { ProductsAndService ps = entities.ProductsAndServices.SingleOrDefault(e => e.ID == PSId); if (ps != null) { ps.PandS_Qty_in_stock = ps.PandS_Qty_in_stock + item.SI_Qty; entities.SaveChanges(); } } item.SI_Qty = 0; item.SI_Price = 0; item.SI_Discount = 0; item.SI_Amount = 0; item.GST_Rate = 0; entities.SaveChanges(); } } } } } } catch (Exception ex) { throw ex; } return(SIStatus); }
public int UpdateCountAndAdjustStock(CountAndAdjustStockForm casForm) { try { using (SDNProductDBEntities entities = new SDNProductDBEntities()) { var data = entities.StockCounts.Where(e => e.Stock_count_no == casForm.CountAndAdjustStock.StockCountNo).ToList(); if (data != null) { foreach (var d in data) { ProductsAndService psOld = entities.ProductsAndServices.SingleOrDefault(e => e.ID == d.PSID); if (psOld != null) { if (d.StockType == Convert.ToByte(Stock_Type.StockDamaged)) { psOld.PandS_Qty_in_stock = psOld.PandS_Qty_in_stock + Convert.ToInt32(Math.Abs(Convert.ToInt32(d.CountQty))); entities.SaveChanges(); } else { psOld.PandS_Qty_in_stock = psOld.PandS_Qty_in_stock - d.CountQty; entities.SaveChanges(); } } var item = casForm.CountAndAdjustStockDetails.SingleOrDefault(e => e.PSID == d.PSID); if (item != null) { //saving details entity d.PandS_Code = item.PandSCode; d.PandS_Name = item.PandSName; d.SysQty = item.SystemQty; d.CountQty = item.CountQty; d.Difference = item.Difference; d.Average_Cost = Convert.ToDecimal(item.AvgCost); d.Amount = item.Amount; d.Adjusted_Amount = item.AdjustedAmount; d.UpdatedBy = 0; d.UpdatedDate = DateTime.Now; entities.SaveChanges(); } ProductsAndService ps = entities.ProductsAndServices.SingleOrDefault(e => e.ID == d.PSID); if (ps != null) { if (casForm.CountAndAdjustStock.StockType == Convert.ToByte(Stock_Type.StockDamaged)) { ps.PandS_Qty_in_stock = ps.PandS_Qty_in_stock - Convert.ToInt32(Math.Abs(Convert.ToInt32(d.CountQty))); entities.SaveChanges(); } else { ps.PandS_Qty_in_stock = ps.PandS_Qty_in_stock + d.CountQty; entities.SaveChanges(); } } } } } } catch (Exception ex) { return(0); throw ex; } return(1); }
public int UpdationInvoice(SalesInvoiceForm invoiceData) { try { using (SDNSalesDBEntities entities = new SDNSalesDBEntities()) { SalesInvoice obj = entities.SalesInvoices.Where(e => e.SI_No == invoiceData.Invoice.InvoiceNo ).SingleOrDefault(); if (obj != null) { //obj.ID = invoiceData.Invoice.ID; obj.Cus_Id = invoiceData.Invoice.CustomerID; obj.SI_Date = invoiceData.Invoice.InvoiceDate; obj.SI_GST_Amt = Convert.ToDecimal(invoiceData.Invoice.TotalTax); obj.SI_No = invoiceData.Invoice.InvoiceNo; obj.SI_TandC = invoiceData.Invoice.TermsAndConditions; obj.SI_Tot_aft_Tax = Convert.ToDecimal(invoiceData.Invoice.TotalAfterTax); obj.SI_Tot_bef_Tax = Convert.ToDecimal(invoiceData.Invoice.TotalBeforeTax); //obj.SI_Pmt_Due_Date = invoiceData.Invoice.PaymentDueDate; obj.Cus_PO_No = invoiceData.Invoice.OurSONo; obj.SI_Credit_Days = invoiceData.Invoice.CreditDays; obj.Salesman = invoiceData.Invoice.SalesmanID; obj.Exc_Inc_GST = invoiceData.Invoice.ExcIncGST; obj.ModifiedDate = DateTime.Now; entities.SaveChanges(); } invoiceData.Invoice.ID = obj.ID; CreateCreditNote(invoiceData); var objSales = entities.SalesInvoiceDetails.Where (e => e.SI_ID == obj.ID).ToList(); if (objSales != null) { foreach (var item in objSales) { int PSId = Convert.ToInt32(item.SI_No); if (PSId != 0) { ProductsAndService ps = entities.ProductsAndServices.SingleOrDefault(e => e.ID == PSId); if (ps != null) { ps.PandS_Qty_in_stock = ps.PandS_Qty_in_stock + item.SI_Qty; entities.SaveChanges(); } } entities.SalesInvoiceDetails.Remove(item); entities.SaveChanges(); } } SalesInvoiceDetail SIDetails; if (invoiceData.InvoiceDetails != null) { foreach (SalesInvoiceDetailEntity SIDetailEntity in invoiceData.InvoiceDetails) { SIDetails = new SalesInvoiceDetail(); SIDetails.SI_ID = obj.ID; SIDetails.SI_No = SIDetailEntity.SINo; SIDetails.PandS_Code = SIDetailEntity.PandSCode; SIDetails.PandS_Name = SIDetailEntity.PandSName; SIDetails.SI_Amount = SIDetailEntity.SIAmount; SIDetails.SI_Discount = SIDetailEntity.SIDiscount; SIDetails.SI_No = SIDetailEntity.SINo; SIDetails.SI_Price = Convert.ToDecimal(SIDetailEntity.SIPrice); SIDetails.SI_Qty = SIDetailEntity.SIQty; SIDetails.GST_Code = SIDetailEntity.GSTCode; SIDetails.GST_Rate = SIDetailEntity.GSTRate; entities.SalesInvoiceDetails.Add(SIDetails); entities.SaveChanges(); int PSId = Convert.ToInt32(SIDetailEntity.SINo); if (PSId != 0) { ProductsAndService ps = entities.ProductsAndServices.SingleOrDefault(e => e.ID == PSId); if (ps != null) { ps.PandS_Qty_in_stock = ps.PandS_Qty_in_stock - SIDetailEntity.SIQty; entities.SaveChanges(); } } } } return(obj.ID); } } catch (Exception ex) { throw ex; } }
public int ConvertToPurchaseInvoice(PurchaseOrderForm orderData) { int autoId = 0; PurchaseInvoice obj = new PurchaseInvoice(); // obj.ID = orderData.Order.ID; obj.Sup_Id = orderData.Order.SupplierID; obj.PI_Date = orderData.Order.OrderDate; obj.PI_GST_Amt = Convert.ToDecimal(orderData.Order.TotalTax); obj.PI_No = "PI-" + (GetLastInvoiceNo() + 1); obj.PI_TandC = orderData.Order.TermsAndConditions; obj.PI_Tot_aft_Tax = Convert.ToDecimal(orderData.Order.TotalAfterTax); obj.PI_Tot_bef_Tax = Convert.ToDecimal(orderData.Order.TotalBeforeTax); obj.PI_Status = 2; obj.Exc_Inc_GST = orderData.Order.ExcIncGST; obj.IsDeleted = false; try { using (SDNPurchasingDBEntities entities = new SDNPurchasingDBEntities()) { if (entities.PurchaseInvoices.AsNoTracking().FirstOrDefault(x => x.ID == orderData.Order.ID) == null) { //obj.CreatedBy = orderData.POModel.CreatedBy; obj.CreatedDate = DateTime.Now; entities.PurchaseInvoices.Add(obj); entities.SaveChanges(); autoId = obj.ID; } else { // obj.ModifiedBy = orderData.POModel.ModifiedBy; obj.ModifiedDate = DateTime.Now; entities.Entry(obj).State = EntityState.Modified; autoId = entities.SaveChanges(); } if (autoId > 0) { PurchaseInvoiceDetail PODetails; if (orderData.OrderDetails != null) { foreach (PurchaseOrderDetailEntity PODetailEntity in orderData.OrderDetails) { PODetails = new PurchaseInvoiceDetail(); PODetails.PI_ID = autoId; PODetails.PI_No = PODetailEntity.PONo; PODetails.PandS_Code = PODetailEntity.PandSCode; PODetails.PandS_Name = PODetailEntity.PandSName; PODetails.PI_Amount = PODetailEntity.POAmount; PODetails.PI_Discount = PODetailEntity.PODiscount; PODetails.PI_No = PODetailEntity.PONo; PODetails.PI_Price = Convert.ToDecimal(PODetailEntity.POPrice); PODetails.PI_Qty = PODetailEntity.POQty; PODetails.GST_Code = PODetailEntity.GSTCode; PODetails.GST_Rate = PODetailEntity.GSTRate; if (entities.PurchaseInvoiceDetails.AsNoTracking().FirstOrDefault(x => x.ID == PODetailEntity.ID) == null) { entities.PurchaseInvoiceDetails.Add(PODetails); entities.SaveChanges(); } else { entities.Entry(PODetails).State = EntityState.Modified; entities.SaveChanges(); } int PSId = Convert.ToInt32(PODetailEntity.PONo); if (PSId != 0) { ProductsAndService ps = entities.ProductsAndServices.SingleOrDefault(e => e.ID == PSId); if (ps != null) { ps.PandS_Qty_in_stock = ps.PandS_Qty_in_stock + PODetailEntity.POQty; entities.SaveChanges(); } } } } PurchaseOrder objQ = entities.PurchaseOrders.Where(e => e.PO_No == orderData.Order.OrderNo ).SingleOrDefault(); if (objQ != null) { objQ.PO_Conv_to_PI = true; objQ.Conv_to_No = obj.PI_No; objQ.ModifiedDate = DateTime.Now; entities.SaveChanges(); } } } return(autoId); } catch (Exception ex) { throw ex; } }
/// <summary> /// This method is used to add or edit purchase order /// </summary> /// <param name="orderData"></param> /// <returns></returns> public int AddUpdateOrder(PurchaseOrderForm orderData) { int autoId = 0; //Add purchase order PurchaseOrder obj = new PurchaseOrder(); obj.ID = orderData.Order.ID; obj.Sup_Id = orderData.Order.SupplierID; //obj.PO_Conv_to_PO = orderData.Order.PO_Conv_to_PO; obj.PO_Conv_to_PI = orderData.Order.PO_Conv_to_PI; obj.PO_Date = orderData.Order.OrderDate; obj.PO_GST_Amt = Convert.ToDecimal(orderData.Order.TotalTax); obj.PO_No = orderData.Order.OrderNo; obj.PO_TandC = orderData.Order.TermsAndConditions; obj.PO_Tot_aft_Tax = Convert.ToDecimal(orderData.Order.TotalAfterTax); obj.PO_Tot_bef_Tax = Convert.ToDecimal(orderData.Order.TotalBeforeTax); obj.PO_Status = Convert.ToByte(PO_Status.unDeposited); obj.PO_Del_Date = orderData.Order.DeliveryDate; obj.Exc_Inc_GST = orderData.Order.ExcIncGST; obj.IsDeleted = false; try { using (SDNPurchasingDBEntities entities = new SDNPurchasingDBEntities()) { if (entities.PurchaseOrders.AsNoTracking().FirstOrDefault(x => x.ID == orderData.Order.ID) == null) { //obj.CreatedBy = orderData.POModel.CreatedBy; obj.CreatedDate = DateTime.Now; entities.PurchaseOrders.Add(obj); entities.SaveChanges(); autoId = obj.ID; } else { // obj.ModifiedBy = orderData.POModel.ModifiedBy; obj.ModifiedDate = DateTime.Now; entities.Entry(obj).State = EntityState.Modified; autoId = entities.SaveChanges(); } if (autoId > 0) { PurchaseOrderDetail PODetails; if (orderData.OrderDetails != null) { foreach (PurchaseOrderDetailEntity PODetailEntity in orderData.OrderDetails) { PODetails = new PurchaseOrderDetail(); PODetails.PO_ID = autoId; PODetails.PO_No = PODetailEntity.PONo; PODetails.PandS_Code = PODetailEntity.PandSCode; PODetails.PandS_Name = PODetailEntity.PandSName; PODetails.PO_Amount = PODetailEntity.POAmount; PODetails.PO_Discount = PODetailEntity.PODiscount; PODetails.PO_No = PODetailEntity.PONo; PODetails.PO_Price = Convert.ToDecimal(PODetailEntity.POPrice); PODetails.PO_Qty = PODetailEntity.POQty; PODetails.GST_Code = PODetailEntity.GSTCode; PODetails.GST_Rate = PODetailEntity.GSTRate; if (entities.PurchaseOrderDetails.AsNoTracking().FirstOrDefault(x => x.ID == PODetailEntity.ID) == null) { entities.PurchaseOrderDetails.Add(PODetails); entities.SaveChanges(); } else { entities.Entry(PODetails).State = EntityState.Modified; entities.SaveChanges(); } int PSId = Convert.ToInt32(PODetailEntity.PONo); if (PSId != 0) { ProductsAndService ps = entities.ProductsAndServices.SingleOrDefault(e => e.ID == PSId); if (ps != null) { ps.PandS_Qty_on_PO = ps.PandS_Qty_on_PO + PODetailEntity.POQty; entities.SaveChanges(); } } } } } } return(autoId); } catch (Exception ex) { throw ex; } }
public int UpdationOrder(PurchaseOrderForm orderData) { try { using (SDNPurchasingDBEntities entities = new SDNPurchasingDBEntities()) { PurchaseOrder obj = entities.PurchaseOrders.Where(e => e.PO_No == orderData.Order.OrderNo ).SingleOrDefault(); if (obj != null) { //obj.ID = orderData.Order.ID; obj.Sup_Id = orderData.Order.SupplierID; // obj.PO_Conv_to_PO = orderData.Order.PO_Conv_to_PO; // obj.PO_Conv_to_PI = orderData.Order.PO_Conv_to_PI; obj.PO_Date = orderData.Order.OrderDate; obj.PO_GST_Amt = Convert.ToDecimal(orderData.Order.TotalTax); obj.PO_No = orderData.Order.OrderNo; obj.PO_TandC = orderData.Order.TermsAndConditions; obj.PO_Tot_aft_Tax = Convert.ToDecimal(orderData.Order.TotalAfterTax); obj.PO_Tot_bef_Tax = Convert.ToDecimal(orderData.Order.TotalBeforeTax); //obj.PO_Valid_for = orderData.Order.ValidForDays; obj.PO_Del_Date = orderData.Order.DeliveryDate; obj.Exc_Inc_GST = orderData.Order.ExcIncGST; obj.ModifiedDate = DateTime.Now; entities.SaveChanges(); } var objPurchase = entities.PurchaseOrderDetails.Where (e => e.PO_ID == obj.ID).ToList(); if (objPurchase != null) { foreach (var item in objPurchase) { int PSId = Convert.ToInt32(item.PO_No); if (PSId != 0) { ProductsAndService ps = entities.ProductsAndServices.SingleOrDefault(e => e.ID == PSId); if (ps != null) { ps.PandS_Qty_on_PO = ps.PandS_Qty_on_PO - item.PO_Qty; entities.SaveChanges(); } } entities.PurchaseOrderDetails.Remove(item); entities.SaveChanges(); } } PurchaseOrderDetail PODetails; if (orderData.OrderDetails != null) { foreach (PurchaseOrderDetailEntity PODetailEntity in orderData.OrderDetails) { PODetails = new PurchaseOrderDetail(); PODetails.PO_ID = obj.ID; PODetails.PO_No = PODetailEntity.PONo; PODetails.PandS_Code = PODetailEntity.PandSCode; PODetails.PandS_Name = PODetailEntity.PandSName; PODetails.PO_Amount = PODetailEntity.POAmount; PODetails.PO_Discount = PODetailEntity.PODiscount; PODetails.PO_No = PODetailEntity.PONo; PODetails.PO_Price = Convert.ToDecimal(PODetailEntity.POPrice); PODetails.PO_Qty = PODetailEntity.POQty; PODetails.GST_Code = PODetailEntity.GSTCode; PODetails.GST_Rate = PODetailEntity.GSTRate; entities.PurchaseOrderDetails.Add(PODetails); entities.SaveChanges(); int PSId = Convert.ToInt32(PODetailEntity.PONo); if (PSId != 0) { ProductsAndService ps = entities.ProductsAndServices.SingleOrDefault(e => e.ID == PSId); if (ps != null) { ps.PandS_Qty_on_PO = ps.PandS_Qty_on_PO + PODetailEntity.POQty; entities.SaveChanges(); } } } } return(obj.ID); } } catch (Exception ex) { throw ex; } }
/// <summary> /// This method is used to add or edit purchase invoice /// </summary> /// <param name="invoiceData"></param> /// <returns></returns> public int AddUpdateInvoice(PurchaseInvoiceForm invoiceData) { int autoId = 0; //Add purchase invoice PurchaseInvoice obj = new PurchaseInvoice(); obj.ID = invoiceData.Invoice.ID; obj.Sup_Id = invoiceData.Invoice.SupplierID; obj.PI_Date = invoiceData.Invoice.InvoiceDate; obj.PI_GST_Amt = Convert.ToDecimal(invoiceData.Invoice.TotalTax); obj.PI_No = invoiceData.Invoice.InvoiceNo; obj.PI_TandC = invoiceData.Invoice.TermsAndConditions; obj.PI_Tot_aft_Tax = Convert.ToDecimal(invoiceData.Invoice.TotalAfterTax); obj.PI_Tot_bef_Tax = Convert.ToDecimal(invoiceData.Invoice.TotalBeforeTax); obj.Our_PO_No = invoiceData.Invoice.OurPONo; obj.PI_Pmt_Due_Date = invoiceData.Invoice.PaymentDueDate; obj.Exc_Inc_GST = invoiceData.Invoice.ExcIncGST; obj.PI_Status = Convert.ToByte(PI_Status.UnPaid); obj.IsDeleted = false; try { using (SDNPurchasingDBEntities entities = new SDNPurchasingDBEntities()) { if (entities.PurchaseInvoices.AsNoTracking().FirstOrDefault(x => x.ID == invoiceData.Invoice.ID) == null) { //obj.CreatedBy = invoiceData.PIModel.CreatedBy; obj.CreatedDate = DateTime.Now; entities.PurchaseInvoices.Add(obj); entities.SaveChanges(); autoId = obj.ID; } else { // obj.ModifiedBy = invoiceData.PIModel.ModifiedBy; obj.ModifiedDate = DateTime.Now; entities.Entry(obj).State = EntityState.Modified; autoId = entities.SaveChanges(); } invoiceData.Invoice.ID = autoId; CreateDebitNote(invoiceData); if (autoId > 0) { PurchaseInvoiceDetail PIDetails; if (invoiceData.InvoiceDetails != null) { foreach (PurchaseInvoiceDetailEntity PIDetailEntity in invoiceData.InvoiceDetails) { PIDetails = new PurchaseInvoiceDetail(); PIDetails.PI_ID = autoId; PIDetails.PI_No = PIDetailEntity.PINo; PIDetails.PandS_Code = PIDetailEntity.PandSCode; PIDetails.PandS_Name = PIDetailEntity.PandSName; PIDetails.PI_Amount = PIDetailEntity.PIAmount; PIDetails.PI_Discount = PIDetailEntity.PIDiscount; PIDetails.PI_No = PIDetailEntity.PINo; PIDetails.PI_Price = Convert.ToDecimal(PIDetailEntity.PIPrice); PIDetails.PI_Qty = PIDetailEntity.PIQty; PIDetails.GST_Code = PIDetailEntity.GSTCode; PIDetails.GST_Rate = PIDetailEntity.GSTRate; if (entities.PurchaseInvoiceDetails.AsNoTracking().FirstOrDefault(x => x.ID == PIDetailEntity.ID) == null) { entities.PurchaseInvoiceDetails.Add(PIDetails); entities.SaveChanges(); } else { entities.Entry(PIDetails).State = EntityState.Modified; entities.SaveChanges(); } int PSId = Convert.ToInt32(PIDetailEntity.PINo); if (PSId != 0) { ProductsAndService ps = entities.ProductsAndServices.SingleOrDefault(e => e.ID == PSId); if (ps != null) { ps.PandS_Qty_in_stock = ps.PandS_Qty_in_stock + PIDetailEntity.PIQty; entities.SaveChanges(); } } } } } int i = entities.Database.ExecuteSqlCommand("exec PRC_Insert_PurchaseInvoiceData {0}", obj.ID); } return(autoId); } catch (Exception ex) { throw ex; } }
public int UpdationInvoice(PurchaseInvoiceForm invoiceData) { try { using (SDNPurchasingDBEntities entities = new SDNPurchasingDBEntities()) { PurchaseInvoice obj = entities.PurchaseInvoices.Where(e => e.PI_No == invoiceData.Invoice.InvoiceNo ).SingleOrDefault(); if (obj != null) { //obj.ID = invoiceData.Invoice.ID; obj.Sup_Id = invoiceData.Invoice.SupplierID; obj.PI_Date = invoiceData.Invoice.InvoiceDate; obj.PI_GST_Amt = Convert.ToDecimal(invoiceData.Invoice.TotalTax); obj.PI_No = invoiceData.Invoice.InvoiceNo; obj.PI_TandC = invoiceData.Invoice.TermsAndConditions; obj.PI_Tot_aft_Tax = Convert.ToDecimal(invoiceData.Invoice.TotalAfterTax); obj.PI_Tot_bef_Tax = Convert.ToDecimal(invoiceData.Invoice.TotalBeforeTax); obj.PI_Pmt_Due_Date = invoiceData.Invoice.PaymentDueDate; obj.Our_PO_No = invoiceData.Invoice.OurPONo; obj.Exc_Inc_GST = invoiceData.Invoice.ExcIncGST; obj.ModifiedDate = DateTime.Now; entities.SaveChanges(); } invoiceData.Invoice.ID = obj.ID; CreateDebitNote(invoiceData); var objPurchase = entities.PurchaseInvoiceDetails.Where (e => e.PI_ID == obj.ID).ToList(); if (objPurchase != null) { foreach (var item in objPurchase) { int PSId = Convert.ToInt32(item.PI_No); if (PSId != 0) { ProductsAndService ps = entities.ProductsAndServices.SingleOrDefault(e => e.ID == PSId); if (ps != null) { ps.PandS_Qty_in_stock = ps.PandS_Qty_in_stock - item.PI_Qty; entities.SaveChanges(); } } entities.PurchaseInvoiceDetails.Remove(item); entities.SaveChanges(); } } PurchaseInvoiceDetail PIDetails; if (invoiceData.InvoiceDetails != null) { foreach (PurchaseInvoiceDetailEntity PIDetailEntity in invoiceData.InvoiceDetails) { PIDetails = new PurchaseInvoiceDetail(); PIDetails.PI_ID = obj.ID; PIDetails.PI_No = PIDetailEntity.PINo; PIDetails.PandS_Code = PIDetailEntity.PandSCode; PIDetails.PandS_Name = PIDetailEntity.PandSName; PIDetails.PI_Amount = PIDetailEntity.PIAmount; PIDetails.PI_Discount = PIDetailEntity.PIDiscount; PIDetails.PI_No = PIDetailEntity.PINo; PIDetails.PI_Price = Convert.ToDecimal(PIDetailEntity.PIPrice); PIDetails.PI_Qty = PIDetailEntity.PIQty; PIDetails.GST_Code = PIDetailEntity.GSTCode; PIDetails.GST_Rate = PIDetailEntity.GSTRate; entities.PurchaseInvoiceDetails.Add(PIDetails); entities.SaveChanges(); int PSId = Convert.ToInt32(PIDetailEntity.PINo); if (PSId != 0) { ProductsAndService ps = entities.ProductsAndServices.SingleOrDefault(e => e.ID == PSId); if (ps != null) { ps.PandS_Qty_in_stock = ps.PandS_Qty_in_stock + PIDetailEntity.PIQty; entities.SaveChanges(); } } } } int i = entities.Database.ExecuteSqlCommand("exec PRC_Update_PurchaseInvoiceData {0}", obj.ID); return(obj.ID); } } catch (Exception ex) { throw ex; } }