public int SaveStockData(StockModel JForm) { //int autoId = 0; // UnpaidSalesInvoice obj = new UnpaidSalesInvoice(); try { using (SASEntitiesEDM entities = new SASEntitiesEDM()) { Stock obj1; if (JForm.StockDetailsData != null) { foreach (StockEntity JEntity in JForm.StockDetailsData) { //save entity value obj1 = new Stock(); obj1.Product_ID = JEntity.ID; obj1.Quantity_In_Stock = JEntity.QtyInStock; obj1.Average_Cost = JEntity.AverageCost; obj1.Amount = JEntity.Amount; obj1.CreatedDate = DateTime.Now; if (entities.Stocks.AsNoTracking().FirstOrDefault(x => x.ID == JEntity.ID) == null) { entities.Stocks.Add(obj1); entities.SaveChanges(); } else { entities.Entry(obj1).State = EntityState.Modified; entities.SaveChanges(); } } } else { } } return(1); } catch (Exception e) { return(0); throw e; } }
public int CreateCustomer(Customer entity) { Customer obj = new Customer(); using (SASEntitiesEDM entities = new SASEntitiesEDM()) { if (entities.Customers.AsNoTracking().FirstOrDefault(x => x.ID == entity.ID) == null) { entities.Customers.Add(entity); } else { entities.Entry(entity).State = EntityState.Modified; } return(entities.SaveChanges()); } }
/// <summary> /// This method is used to convert the Sales order to order /// </summary> /// <param name="orderData"></param> /// <returns></returns> public int ConvertToSalesOrder(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_Date = orderData.Order.OrderDate; obj.SO_Del_Date = DateTime.Now; obj.SO_GST_Amt = Convert.ToDecimal(orderData.Order.TotalTax); obj.SO_No = "SO-" + GetLastOrderNo(); 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.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(); } } } SalesOrder objQ = entities.SalesOrders.Where(e => e.SO_No == orderData.Order.OrderNo ).SingleOrDefault(); if (objQ != null) { //objQ.SO_Conv_to_SO = true; objQ.ModifiedDate = DateTime.Now; entities.SaveChanges(); } } } return(autoId); } 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 int ConvertToSalesInvoice(SalesQuotationForm quotationData) { int autoId = 0; //Add purchase quotation SalesInvoice obj = new SalesInvoice(); // obj.ID = quotationData.Quotation.ID; obj.Cus_Id = quotationData.Quotation.CustomerID; obj.SI_Date = quotationData.Quotation.QuotationDate; obj.Salesman = quotationData.Quotation.SalesmanID; obj.SI_GST_Amt = Convert.ToDecimal(quotationData.Quotation.TotalTax); obj.SI_No = "SI-" + (GetLastInvoiceNo() + 1); obj.SI_TandC = quotationData.Quotation.TermsAndConditions; obj.SI_Tot_aft_Tax = Convert.ToDecimal(quotationData.Quotation.TotalAfterTax); obj.SI_Tot_bef_Tax = Convert.ToDecimal(quotationData.Quotation.TotalBeforeTax); obj.SI_Status = Convert.ToByte(SI_Status.UnPaid); obj.Exc_Inc_GST = quotationData.Quotation.ExcIncGST; obj.IsDeleted = false; try { using (SASEntitiesEDM entities = new SASEntitiesEDM()) { if (entities.SalesInvoices.AsNoTracking().FirstOrDefault(x => x.ID == quotationData.Quotation.ID) == null) { //obj.CreatedBy = quotationData.SQModel.CreatedBy; obj.CreatedDate = DateTime.Now; entities.SalesInvoices.Add(obj); entities.SaveChanges(); autoId = obj.ID; } else { // obj.ModifiedBy = quotationData.SQModel.ModifiedBy; obj.ModifiedDate = DateTime.Now; entities.Entry(obj).State = EntityState.Modified; autoId = entities.SaveChanges(); } if (autoId > 0) { SalesInvoiceDetail SQDetails; if (quotationData.QuotationDetails != null) { foreach (SalesQuotationDetailEntity SQDetailEntity in quotationData.QuotationDetails) { SQDetails = new SalesInvoiceDetail(); SQDetails.SI_ID = autoId; SQDetails.SI_No = SQDetailEntity.SQNo; SQDetails.PandS_Code = SQDetailEntity.PandSCode; SQDetails.PandS_Name = SQDetailEntity.PandSName; SQDetails.SI_Amount = SQDetailEntity.SQAmount; SQDetails.SI_Discount = SQDetailEntity.SQDiscount; SQDetails.SI_No = SQDetailEntity.SQNo; SQDetails.SI_Price = Convert.ToDecimal(SQDetailEntity.SQPrice); SQDetails.SI_Qty = SQDetailEntity.SQQty; SQDetails.GST_Code = SQDetailEntity.GSTCode; SQDetails.GST_Rate = SQDetailEntity.GSTRate; if (entities.SalesInvoiceDetails.AsNoTracking().FirstOrDefault(x => x.ID == SQDetailEntity.ID) == null) { entities.SalesInvoiceDetails.Add(SQDetails); entities.SaveChanges(); } else { entities.Entry(SQDetails).State = EntityState.Modified; entities.SaveChanges(); } } } SalesQuotation objQ = entities.SalesQuotations.Where(e => e.SQ_No == quotationData.Quotation.QuotationNo ).SingleOrDefault(); if (objQ != null) { objQ.SQ_Conv_to_SI = true; objQ.ModifiedDate = DateTime.Now; objQ.Conv_to_No = obj.SI_No; entities.SaveChanges(); } } } return(autoId); } catch (Exception ex) { throw ex; } }
/// <summary> /// This method is used to add or edit purchase quotation /// </summary> /// <param name="quotationData"></param> /// <returns></returns> public int AddUpdateQuotation(SalesQuotationForm quotationData) { int autoId = 0; //Add purchase quotation SalesQuotation obj = new SalesQuotation(); obj.ID = quotationData.Quotation.ID; obj.Cus_Id = quotationData.Quotation.CustomerID; obj.Salesman = quotationData.Quotation.SalesmanID; obj.SQ_Conv_to_SO = quotationData.Quotation.SQ_Conv_to_SO; obj.SQ_Conv_to_SI = quotationData.Quotation.SQ_Conv_to_SI; obj.SQ_Date = quotationData.Quotation.QuotationDate; obj.SQ_GST_Amt = Convert.ToDecimal(quotationData.Quotation.TotalTax); obj.SQ_No = quotationData.Quotation.QuotationNo; obj.SQ_TandC = quotationData.Quotation.TermsAndConditions; obj.SQ_Tot_aft_Tax = Convert.ToDecimal(quotationData.Quotation.TotalAfterTax); obj.SQ_Tot_bef_Tax = Convert.ToDecimal(quotationData.Quotation.TotalBeforeTax); obj.SQ_Valid_for = quotationData.Quotation.ValidForDays; obj.Exc_Inc_GST = quotationData.Quotation.ExcIncGST; obj.IsDeleted = false; try { using (SASEntitiesEDM entities = new SASEntitiesEDM()) { if (entities.SalesQuotations.AsNoTracking().FirstOrDefault(x => x.ID == quotationData.Quotation.ID) == null) { //obj.CreatedBy = quotationData.SQModel.CreatedBy; obj.CreatedDate = DateTime.Now; entities.SalesQuotations.Add(obj); entities.SaveChanges(); autoId = obj.ID; } else { // obj.ModifiedBy = quotationData.SQModel.ModifiedBy; obj.ModifiedDate = DateTime.Now; entities.Entry(obj).State = EntityState.Modified; autoId = entities.SaveChanges(); } if (autoId > 0) { SalesQuotationDetail SQDetails; if (quotationData.QuotationDetails != null) { foreach (SalesQuotationDetailEntity SQDetailEntity in quotationData.QuotationDetails) { SQDetails = new SalesQuotationDetail(); SQDetails.SQ_ID = autoId; SQDetails.SQ_No = SQDetailEntity.SQNo; SQDetails.PandS_Code = SQDetailEntity.PandSCode; SQDetails.PandS_Name = SQDetailEntity.PandSName; SQDetails.SQ_Amount = SQDetailEntity.SQAmount; SQDetails.SQ_Discount = SQDetailEntity.SQDiscount; SQDetails.SQ_No = SQDetailEntity.SQNo; SQDetails.SQ_Price = Convert.ToDecimal(SQDetailEntity.SQPrice); SQDetails.SQ_Qty = SQDetailEntity.SQQty; SQDetails.GST_Code = SQDetailEntity.GSTCode; SQDetails.GST_Rate = SQDetailEntity.GSTRate; if (entities.SalesQuotationDetails.AsNoTracking().FirstOrDefault(x => x.ID == SQDetailEntity.ID) == null) { entities.SalesQuotationDetails.Add(SQDetails); entities.SaveChanges(); } else { entities.Entry(SQDetails).State = EntityState.Modified; entities.SaveChanges(); } } } } } return(autoId); } 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 (SASEntitiesEDM entities = new SASEntitiesEDM()) { 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 UpdateAdjustDebitNote(AdjustDebitNoteForm psForm, int Type) { int autoID = 0; string AdjustedNo = string.Empty; try { using (SASEntitiesEDM entities = new SASEntitiesEDM()) { //adjusted table entity //adjusted debit note AdjustedDebitNote Adn = new AdjustedDebitNote(); Adn.SupplierID = psForm.AdjustDebitNote.SupplierID; Adn.AdjustDebitNoteNumber = psForm.AdjustDebitNote.AdjustDebitNoteNumber; Adn.AdjustDebitNoteDate = Convert.ToDateTime(psForm.AdjustDebitNote.AdjustDebitNoteDateStr); Adn.DebitNoteNumber = psForm.AdjustDebitNote.DebitNoteNo; Adn.DebitNoteDate = psForm.AdjustDebitNote.Date; Adn.DebitNoteAmount = psForm.AdjustDebitNote.Amount; Adn.CreatedBy = 0; if (entities.AdjustedDebitNotes.AsNoTracking().FirstOrDefault(x => x.ID == psForm.AdjustDebitNote.ID) == null) { //obj.CreatedBy = invoiceData.SIModel.CreatedBy; Adn.CreatedDate = DateTime.Now; entities.AdjustedDebitNotes.Add(Adn); entities.SaveChanges(); autoID = Adn.ID; AdjustedNo = Adn.AdjustDebitNoteNumber; } else { // obj.ModifiedBy = invoiceData.SIModel.ModifiedBy; Adn.ModifiedDate = DateTime.Now; entities.Entry(Adn).State = EntityState.Modified; autoID = entities.SaveChanges(); } foreach (var item in psForm.AdjustDebitNoteDetails) { if (item.CheckAmountAdjusted == true) { AdjustedDebitNoteDetail ADN = new AdjustedDebitNoteDetail(); if (autoID > 0) { ADN.ADN_ID = autoID; ADN.PurchaseInvoiceNo = item.PurchaseNo; ADN.PurchaseInvoiceDate = item.PurchaseDate; ADN.PaymentDueDate = item.PaymentDueDate; ADN.PurchaseInvoiceAmount = item.PurchaseAmount; ADN.AmountDue = item.AmountDue; ADN.AmountAdjusted = item.AmountAdjusted; ADN.CreatedBy = 0; ADN.CreatedDate = DateTime.Now; if (entities.AdjustedDebitNoteDetails.AsNoTracking().FirstOrDefault(x => x.ID == psForm.AdjustDebitNote.ID) == null) { entities.AdjustedDebitNoteDetails.Add(ADN); entities.SaveChanges(); } else { entities.Entry(ADN).State = EntityState.Modified; entities.SaveChanges(); } } } } //adjusted table entity foreach (var item in psForm.AdjustDebitNoteDetails) { if (item.CheckAmountAdjusted == true) { CashAndBankTransaction obj = entities.CashAndBankTransactions.Where(e => e.SO_CN_PO_DN_No == item.PurchaseNo).OrderByDescending(x => x.ID).ToList().FirstOrDefault(); if (obj != null) { obj.Acc_Id = psForm.AdjustDebitNote.AccountId; obj.Amount = psForm.AdjustDebitNote.Amount; //obj.Cash_Cheque_No = psForm.AdjustDebitNote.CashChequeNo; obj.Cash_Cheque_Date = psForm.AdjustDebitNote.Date; obj.Remarks = psForm.AdjustDebitNote.Remarks; obj.Is_Cheque = psForm.AdjustDebitNote.IsCheque; //saving details entity obj.SO_CN_PO_DN_No = item.PurchaseNo; obj.SO_CN_PO_DN_Date = item.PurchaseDate; obj.SO_CN_PO_DN_Amt = item.PurchaseAmount; obj.Amt_Due = item.AmountDue - item.AmountAdjusted; obj.Amt_Refunded = item.AmountAdjusted; obj.Discount = item.Discount; obj.DN_CN_No = psForm.AdjustDebitNote.DebitNoteNo; obj.Type = Type.ToString(); obj.UpdatedBy = 0; obj.UpdatedDate = DateTime.Now.Date; obj.AD_AC_NO = AdjustedNo; entities.SaveChanges(); if (item.AmountAdjusted == item.PurchaseAmount) { PurchaseInvoice invoice = entities.PurchaseInvoices.Where(e => e.PI_No == item.PurchaseNo).SingleOrDefault(); //PurchaseOrder order = entities.PurchaseOrders.Where(e => e.PO_No == item.PurchaseNo).SingleOrDefault(); if (invoice != null) { invoice.PI_Status = Convert.ToByte(PI_Status.Paid); entities.SaveChanges(); } //else if (order != null) //{ //} } DebitNote debit = entities.DebitNotes.Where(e => e.DN_No == psForm.AdjustDebitNote.DebitNoteNo).SingleOrDefault(); if (debit != null) { debit.DN_Status = Convert.ToByte(DN_Status.Adjusted); entities.SaveChanges(); } } else { CashAndBankTransaction cashbankobj = new CashAndBankTransaction() { Acc_Id = psForm.AdjustDebitNote.AccountId, Amount = psForm.AdjustDebitNote.Amount, Cash_Cheque_Date = psForm.AdjustDebitNote.Date, Remarks = psForm.AdjustDebitNote.Remarks, Is_Cheque = psForm.AdjustDebitNote.IsCheque, SO_CN_PO_DN_No = item.PurchaseNo, SO_CN_PO_DN_Date = item.PurchaseDate, SO_CN_PO_DN_Amt = item.PurchaseAmount, Amt_Due = item.AmountDue - item.AmountAdjusted, Amt_Refunded = item.AmountAdjusted, Discount = item.Discount, UpdatedBy = 0, UpdatedDate = DateTime.Now.Date, Cus_Sup_Id = psForm.AdjustDebitNote.SupplierID, DN_CN_No = psForm.AdjustDebitNote.DebitNoteNo, Type = Type.ToString(), AD_AC_NO = AdjustedNo }; entities.CashAndBankTransactions.Add(cashbankobj); entities.SaveChanges(); if (item.AmountAdjusted == item.PurchaseAmount) { PurchaseInvoice invoice = entities.PurchaseInvoices.Where(e => e.PI_No == item.PurchaseNo).SingleOrDefault(); //PurchaseOrder order = entities.PurchaseOrders.Where(e => e.PO_No == item.PurchaseNo).SingleOrDefault(); if (invoice != null) { invoice.PI_Status = Convert.ToByte(PI_Status.Paid); entities.SaveChanges(); } //else if (order != null) //{ //} } DebitNote debit = entities.DebitNotes.Where(e => e.DN_No == psForm.AdjustDebitNote.DebitNoteNo).SingleOrDefault(); if (debit != null) { debit.DN_Status = Convert.ToByte(DN_Status.Adjusted); entities.SaveChanges(); } } } } } } catch (Exception ex) { throw ex; } return(psForm.AdjustDebitNote.ID); }
public int SaveJournalData(JournalForm JForm) { int autoId = 0; Journal obj = new Journal(); obj.J_No = JForm.JournalData.JournalNo; obj.J_Date = JForm.JournalData.JournalDate; try { using (SASEntitiesEDM entities = new SASEntitiesEDM()) { if (entities.Journals.AsNoTracking().FirstOrDefault(x => x.ID == JForm.JournalData.ID) == null) { //obj.CreatedBy = invoiceData.SIModel.CreatedBy; obj.J_CreatedDate = DateTime.Now; entities.Journals.Add(obj); entities.SaveChanges(); autoId = obj.ID; } else { // obj.ModifiedBy = invoiceData.SIModel.ModifiedBy; obj.J_ModifiedDate = DateTime.Now; entities.Entry(obj).State = EntityState.Modified; autoId = entities.SaveChanges(); } JForm.JournalData.ID = autoId; if (autoId > 0) { JournalDetail obj1; if (JForm.JournalaDataDetails != null) { foreach (JournalFormEntity JEntity in JForm.JournalaDataDetails) { //save entity value obj1 = new JournalDetail(); obj1.Acc_ID = JEntity.ID; obj1.JO_ID_ = autoId; obj1.JO_No = JForm.JournalData.JournalNo; obj1.JO_Date = JForm.JournalData.JournalDate; obj1.JO_Debit_ = JEntity.Debit; obj1.JO_Credit_ = JEntity.Credit; if (entities.JournalDetails.AsNoTracking().FirstOrDefault(x => x.ID == JEntity.ID) == null) { entities.JournalDetails.Add(obj1); entities.SaveChanges(); } else { entities.Entry(obj1).State = EntityState.Modified; entities.SaveChanges(); } } } } else { } } return(autoId); } catch (Exception ex) { return(0); throw ex; } //return 1; }
/// <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 BusinessExpens obj = new BusinessExpens(); 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 (SASEntitiesEDM entities = new SASEntitiesEDM()) { if (entities.PurchaseInvoices.AsNoTracking().FirstOrDefault(x => x.ID == invoiceData.Invoice.ID) == null) { //obj.CreatedBy = invoiceData.PIModel.CreatedBy; obj.CreatedDate = DateTime.Now; entities.BusinessExpenses.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) { BusinessExpensesDetail PIDetails; if (invoiceData.BEInvoiceDetails != null) { foreach (PurchaseInvoiceBEDetailsEntity beDetailEntity in invoiceData.BEInvoiceDetails) { PIDetails = new BusinessExpensesDetail(); PIDetails.PI_ID = autoId; PIDetails.Bus_Expenses_Acc_Name = beDetailEntity.AccountName; PIDetails.PI_Amount = beDetailEntity.PQAmount; PIDetails.GST_Code = beDetailEntity.GSTCode; PIDetails.GST_Rate = beDetailEntity.GSTRate; PIDetails.Bus_Expenses_Desc = beDetailEntity.Description; if (entities.PurchaseInvoiceDetails.AsNoTracking().FirstOrDefault(x => x.ID == beDetailEntity.ID) == null) { entities.BusinessExpensesDetails.Add(PIDetails); entities.SaveChanges(); } else { entities.Entry(PIDetails).State = EntityState.Modified; entities.SaveChanges(); } } } } } return(autoId); } 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 (SASEntitiesEDM entities = new SASEntitiesEDM()) { 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; PIDetails.Type = PIDetailEntity.PIType; 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; } }
/// <summary> /// This method is used to convert the Purchase quotation to order /// </summary> /// <param name="quotationData"></param> /// <returns></returns> public int ConvertToPurchaseOrder(PurchaseQuotationForm quotationData) { int autoId = 0; PurchaseOrder obj = new PurchaseOrder(); //obj.ID = quotationData.Quotation.ID; obj.Sup_Id = quotationData.Quotation.SupplierID; obj.PO_Date = quotationData.Quotation.QuotationDate; obj.PO_Del_Date = DateTime.Now; obj.PO_GST_Amt = Convert.ToDecimal(quotationData.Quotation.TotalTax); obj.PO_No = "PO-" + (GetLastOrderNo() + 1); obj.PO_TandC = quotationData.Quotation.TermsAndConditions; obj.PO_Tot_aft_Tax = Convert.ToDecimal(quotationData.Quotation.TotalAfterTax); obj.PO_Tot_bef_Tax = Convert.ToDecimal(quotationData.Quotation.TotalBeforeTax); obj.PO_Status = Convert.ToByte(PO_Status.unDeposited); obj.Exc_Inc_GST = quotationData.Quotation.ExcIncGST; obj.IsDeleted = false; try { using (SASEntitiesEDM entities = new SASEntitiesEDM()) { if (entities.PurchaseOrders.AsNoTracking().FirstOrDefault(x => x.ID == quotationData.Quotation.ID) == null) { //obj.CreatedBy = quotationData.PQModel.CreatedBy; obj.CreatedDate = DateTime.Now; entities.PurchaseOrders.Add(obj); entities.SaveChanges(); autoId = obj.ID; } else { // obj.ModifiedBy = quotationData.PQModel.ModifiedBy; obj.ModifiedDate = DateTime.Now; entities.Entry(obj).State = EntityState.Modified; autoId = entities.SaveChanges(); } if (autoId > 0) { PurchaseOrderDetail PQDetails; if (quotationData.QuotationDetails != null) { foreach (PurchaseQuotationDetailEntity PQDetailEntity in quotationData.QuotationDetails) { PQDetails = new PurchaseOrderDetail(); PQDetails.PO_ID = autoId; PQDetails.PO_No = PQDetailEntity.PQNo; PQDetails.PandS_Code = PQDetailEntity.PandSCode; PQDetails.PandS_Name = PQDetailEntity.PandSName; PQDetails.PO_Amount = PQDetailEntity.PQAmount; PQDetails.PO_Discount = PQDetailEntity.PQDiscount; PQDetails.PO_No = PQDetailEntity.PQNo; PQDetails.PO_Price = Convert.ToDecimal(PQDetailEntity.PQPrice); PQDetails.PO_Qty = PQDetailEntity.PQQty; PQDetails.GST_Code = PQDetailEntity.GSTCode; PQDetails.GST_Rate = PQDetailEntity.GSTRate; if (entities.PurchaseOrderDetails.AsNoTracking().FirstOrDefault(x => x.ID == PQDetailEntity.ID) == null) { entities.PurchaseOrderDetails.Add(PQDetails); entities.SaveChanges(); } else { entities.Entry(PQDetails).State = EntityState.Modified; entities.SaveChanges(); } } } PurchaseQuotation objQ = entities.PurchaseQuotations.Where(e => e.PQ_No == quotationData.Quotation.QuotationNo ).SingleOrDefault(); if (objQ != null) { objQ.PQ_Conv_to_PO = true; objQ.Conv_to_No = obj.PO_No; objQ.ModifiedDate = DateTime.Now; entities.SaveChanges(); } } } return(autoId); } 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 (SASEntitiesEDM entities = new SASEntitiesEDM()) { 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_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 (SASEntitiesEDM entities = new SASEntitiesEDM()) { 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; } }