int IPurchaseInvoiceBERepository.AddUpdateInvoice(PurchaseInvoiceForm invoiceData) { IPurchaseInvoiceBEBL pqBL = new PurchaseInvoiceBEBL(); int i = pqBL.AddUpdateInvoice(invoiceData); return(i); }
/// <summary> /// This method is used to get Purchase Invoice details /// </summary> /// <param name="pqId"></param> /// <returns></returns> public PurchaseInvoiceForm GetPurchaseInvoice(string pqno) { PurchaseInvoiceForm pqf = new PurchaseInvoiceForm(); try { using (SASEntitiesEDM entities = new SASEntitiesEDM()) { var pq = (from pqs in entities.BusinessExpenses where pqs.PI_No == pqno && (pqs.IsDeleted == false || pqs.IsDeleted == null) select new PurchaseInvoiceEntity { ID = pqs.ID, SupplierID = pqs.Sup_Id, InvoiceNo = pqs.PI_No, InvoiceDate = pqs.PI_Date, PaymentDueDate = pqs.PI_Pmt_Due_Date, TermsAndConditions = pqs.PI_TandC, TotalBeforeTax = pqs.PI_Tot_bef_Tax, TotalTax = pqs.PI_GST_Amt, TotalAfterTax = pqs.PI_Tot_aft_Tax, ExcIncGST = pqs.Exc_Inc_GST, OurPONo = pqs.Our_PO_No, PIStatus = pqs.PI_Status }).SingleOrDefault(); if (pq != null) { pqf.Invoice = pq; var pqd = (from pqds in entities.BusinessExpensesDetails where pqds.PI_ID == pq.ID select new PurchaseInvoiceBEDetailsEntity { ID = pqds.ID, Description = pqds.Bus_Expenses_Desc, AccountName = pqds.Bus_Expenses_Acc_Name, PQAmount = pqds.PI_Amount, GSTRate = pqds.GST_Rate }).ToList <PurchaseInvoiceBEDetailsEntity>(); if (pqd != null) { pqf.BEInvoiceDetails = pqd; } } return(pqf); } } catch (Exception ex) { throw ex; } }
private void CreateDebitNote(PurchaseInvoiceForm invoiceData) { try { using (SDNPurchasingDBEntities entities = new SDNPurchasingDBEntities()) { DebitNote deb = entities.DebitNotes.Where(e => e.PI_Id == invoiceData.Invoice.ID).SingleOrDefault(); if (Convert.ToDecimal(invoiceData.Invoice.TotalBeforeTax) < 0) { if (deb != null) { deb.DN_Date = DateTime.Now.Date; // deb.DN_No = "DN-" + (GetLastDebitNoteNo() + 1); //deb.PI_Id = obj.ID; deb.Sup_Id = invoiceData.Invoice.SupplierID; // deb.Sup_CN_Amount = Convert.ToDecimal(invoiceData.Invoice.TotalBeforeTax); //deb.ModifiedDate = DateTime.Now; entities.SaveChanges(); } else { deb = new DebitNote(); deb.DN_Date = DateTime.Now.Date; deb.DN_No = "DN-" + (GetLastDebitNoteNo() + 1); deb.PI_Id = invoiceData.Invoice.ID; deb.Sup_Id = invoiceData.Invoice.SupplierID; deb.DN_Status = Convert.ToByte(DN_Status.UnAdjusted); // deb.Sup_CN_Amount = Convert.ToDecimal(invoiceData.Invoice.TotalBeforeTax); deb.CreatedDate = DateTime.Now; entities.DebitNotes.Add(deb); entities.SaveChanges(); } } else { if (deb != null) { entities.DebitNotes.Remove(deb); entities.SaveChanges(); } } } } catch (Exception ex) { throw ex; } }
public PurchaseInvoiceForm GetDataIntoModel() { PurchaseInvoiceForm PQForm = new PurchaseInvoiceForm(); PQForm.InvoiceDetails = new List <PurchaseInvoiceDetailEntity>(); PurchaseInvoiceEntity model = new PurchaseInvoiceEntity(); model.InvoiceNo = this.InvoiceNo; model.InvoiceDate = this.InvoiceDate; model.TotalBeforeTax = this.TotalBeforeTax; model.TotalTax = this.TotalTax; model.TotalAfterTax = this.TotalAfterTax; model.PaymentDueDate = this.PaymentDueDate; model.OurPONo = this.OurPONo; model.SupplierID = this.SelectedSupplierID; model.TermsAndConditions = this.TermsAndConditions; if (ExcludingTax == true) { model.ExcIncGST = false; } else { model.ExcIncGST = true; } PQForm.Invoice = model; foreach (var item in PQDetailsEntity) { PurchaseInvoiceDetailEntity pqEntity = new PurchaseInvoiceDetailEntity(); pqEntity.PINo = Convert.ToString(item.SelectedPSID); pqEntity.PandSCode = item.PandSCode; pqEntity.PandSName = item.PandSName; pqEntity.PIQty = item.PQQty; pqEntity.PIPrice = item.PQPrice; pqEntity.PIDiscount = item.PQDiscount; pqEntity.GSTRate = item.GSTRate; pqEntity.GSTRateStr = Convert.ToString(item.GSTRate) + "%"; pqEntity.PIAmount = item.PQAmount; if (item.SelectedPSID != null && Convert.ToInt32(item.SelectedPSID) > 0) { PQForm.InvoiceDetails.Add(pqEntity); } } return(PQForm); }
/// <summary> /// This method is used to save and edit pq /// </summary> /// <param name="param"></param> public void SavePurchaseInvoice(object param) { MessageBoxResult result = System.Windows.MessageBox.Show("Do you want to save changes?", "Save Confirmation", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { Mouse.OverrideCursor = Cursors.Wait; string msg = ValidatePurchaseInvoice(); if (msg != string.Empty) { PQErrors = msg; Mouse.OverrideCursor = null; return; } PQErrors = string.Empty; PurchaseInvoiceForm PQForm = GetDataIntoModel(); int i = 0; if (IsNew == true) { i = pqRepository.AddUpdateInvoice(PQForm); } else { i = pqRepository.UpdationInvoice(PQForm); } if (i > 0) { //GetNewPQ(); SupplierEnabled = false; // added on 23 may 2017 IsNew = false; // added on 23 may 2017 } Mouse.OverrideCursor = null; } }
public int UpdationInvoice(PurchaseInvoiceForm quotationData) { IPurchaseInvoicePandSDAL PQDAL = new PurchaseInvoicePandSDAL(); return(PQDAL.UpdationInvoice(quotationData)); }
public int UpdationInvoice(PurchaseInvoiceForm invoiceData) { IPurchaseInvoiceBEBL pqBL = new PurchaseInvoiceBEBL(); return(pqBL.UpdationInvoice(invoiceData)); }
public void GetPurchaseInvoice(string pqNo) { // Mouse.OverrideCursor = Cursors.Wait; PurchaseInvoiceForm pqf = pqRepository.GetPurchaseInvoice(pqNo); this.ID = pqf.Invoice.ID; this.InvoiceNo = pqf.Invoice.InvoiceNo; this.OurPONo = pqf.Invoice.OurPONo; this.InvoiceDate = pqf.Invoice.InvoiceDate; this.PaymentDueDate = pqf.Invoice.PaymentDueDate; this.SelectedSupplierID = pqf.Invoice.SupplierID; //if (this.SelectedSupplierID > 0) //{ // GetSupplierDetails(); //} this.TermsAndConditions = pqf.Invoice.TermsAndConditions; this.TotalBeforeTax = pqf.Invoice.TotalBeforeTax; this.TotalTax = pqf.Invoice.TotalTax; this.TotalAfterTax = pqf.Invoice.TotalAfterTax; this.TotalBeforeTaxStr = Convert.ToString(this.TotalBeforeTax); this.TotalTaxStr = Convert.ToString(TotalTax); this.TotalAfterTaxStr = Convert.ToString(TotalAfterTax); if (pqf.Invoice.ExcIncGST == true) { ExcludingTax = false; IncludingTax = true; // PQDEntity.GSTRate = 0; } else { ExcludingTax = true; IncludingTax = false; // PQDEntity.GSTRate = TaxRate; } if (this.PIStatus == Convert.ToByte(PI_Status.Paid)) { AllFieldsReadonly = true; AllFieldsEnabled = false; } else { AllFieldsReadonly = false; AllFieldsEnabled = true; LstSuppliers = supplierRepository.GetAllSupplier().Where(s => s.IsInActive != "Y").ToList(); ProductAndServices = ProductAndServices.OrderBy(x => x.PSName).Where(x => x.IsInActive != "Y").ToObservable(); } this.PIStatus = pqf.Invoice.PIStatus; if (PIStatus == Convert.ToByte(PI_Status.Cancelled)) { StatusString = "Cancelled"; VisibilityForImage = Visibility.Visible; AllFieldsEnabled = false; AllFieldsReadonly = true; } else if (PIStatus == Convert.ToByte(PI_Status.Paid)) { StatusString = " Paid"; VisibilityForImage = Visibility.Visible; AllFieldsEnabled = false; AllFieldsReadonly = true; } else if (PIStatus == Convert.ToByte(PI_Status.Adjusted)) { StatusString = "Adjusted"; VisibilityForImage = Visibility.Visible; AllFieldsEnabled = false; AllFieldsReadonly = true; } else { StatusString = ""; VisibilityForImage = Visibility.Collapsed; AllFieldsEnabled = true; AllFieldsReadonly = false; } SupplierEnabled = false;// added on 23 may 2017 this.PQDetailsEntity = new ObservableCollection <DataGridViewModel>(); foreach (var item in pqf.InvoiceDetails) { DataGridViewModel pqEntity = new DataGridViewModel(ProductList); pqEntity.SelectedPSID = Convert.ToString(item.PINo); pqEntity.PandSCode = item.PandSCode; pqEntity.PandSName = item.PandSName; pqEntity.GSTRate = Math.Round(Convert.ToDecimal(item.GSTRate), DecimalPlaces); pqEntity.GSTRateStr = Convert.ToString(pqEntity.GSTRate) + "%"; pqEntity.PQQty = item.PIQty; pqEntity.PQPrice = Convert.ToString(item.Price); pqEntity.PQDiscount = item.PIDiscount; // PQDEntity.GSTRate = item.GSTRate; pqEntity.PQAmount = item.PIAmount; PQDetailsEntity.Add(pqEntity); } }
public PurchaseInvoiceForm GetDataIntoModel() { try { OptionsEntity oData = new OptionsEntity(); oData = customerRepository.GetOptionSettings(); PurchaseInvoiceForm PQForm = new PurchaseInvoiceForm(); PQForm.BEInvoiceDetails = new List <PurchaseInvoiceBEDetailsEntity>(); PurchaseInvoiceEntity model = new PurchaseInvoiceEntity(); // model.InvoiceNo = this.InvoiceNo; model.InvoiceDate = DateTime.ParseExact(this.InvoiceDateStr, oData.DateFormat, null); model.TotalBeforeTax = this.TotalBeforeTax; model.TotalTax = this.TotalTax; model.TotalAfterTax = this.TotalAfterTax; model.PaymentDueDate = DateTime.ParseExact(this.PaymentDueDateStr, oData.DateFormat, null); model.OurPONo = this.OurPONo; if (!string.IsNullOrEmpty(InvoiceNo)) { model.InvoiceNo = this.InvoiceNo; } else { model.InvoiceNo = this.OurPONo; this.InvoiceNo = this.OurPONo; } model.SupplierID = this.SelectedSupplierID; model.TermsAndConditions = this.TermsAndConditions; if (ExcludingTax == true) { model.ExcIncGST = false; } else { model.ExcIncGST = true; } PQForm.Invoice = model; foreach (var item in BEDetailsEntity) { PurchaseInvoiceBEDetailsEntity pqEntity = new PurchaseInvoiceBEDetailsEntity(); pqEntity.SelectedAccountId = item.SelectedAccountId; if (item.SelectedAccountId != null) { var acc = Accounts.Where(e => e.AccountID == item.SelectedAccountId).SingleOrDefault(); if (acc != null) { pqEntity.AccountName = acc.AccountName; } } pqEntity.Description = item.Description; pqEntity.SelectedTaxID = item.SelectedTaxID; if (item.SelectedTaxID != null) { var tax = Taxes.Where(e => e.TaxID == item.SelectedTaxID).SingleOrDefault(); if (tax != null) { pqEntity.GSTCode = tax.TaxCode; pqEntity.GSTRate = tax.TaxRate; } } pqEntity.PQAmountStr = item.PQAmountStr; pqEntity.PQAmount = Convert.ToDecimal(item.PQAmountStr); //pqEntity.TaxList = item.TaxList; pqEntity.PIType = "BE"; //pqEntity.Amount= item.PQAmountStr; //pqEntity.AmountBeforeTax= Convert.ToDecimal(item.PQAmountStr); //pqEntity.TaxAmount = Convert.ToDecimal(item.PQAmountStr) * pqEntity.GSTRate; //pqEntity.AmountAfterTax = pqEntity.AmountBeforeTax + pqEntity.TaxAmount; if (item.SelectedAccountId != null && Convert.ToInt32(item.SelectedAccountId) > 0) { PQForm.BEInvoiceDetails.Add(pqEntity); } } return(PQForm); } catch (Exception ex) { throw ex; } }
public void GetPurchaseInvoice(string pqNo) { OptionsEntity oData = new OptionsEntity(); IPurchaseQuotationListRepository purchaseRepository = new PurchaseQuotationListRepository(); oData = purchaseRepository.GetOptionSettings(); // Mouse.OverrideCursor = Cursors.Wait; PurchaseInvoiceForm pqf = pqRepository.GetPurchaseInvoice(pqNo); if (pqf.Invoice != null) { this.ID = pqf.Invoice.ID; this.InvoiceNo = pqf.Invoice.InvoiceNo; this.OurPONo = pqf.Invoice.OurPONo; this.InvoiceDateStr = pqf.Invoice.InvoiceDate.ToString(oData.DateFormat); DateTime Dateinstr = (DateTime)pqf.Invoice.PaymentDueDate; this.PaymentDueDateStr = Dateinstr.ToString(oData.DateFormat); this.SelectedSupplierID = pqf.Invoice.SupplierID; if (this.SelectedSupplierID > 0) { GetSupplierDetails(); } this.TermsAndConditions = pqf.Invoice.TermsAndConditions; this.TotalBeforeTax = pqf.Invoice.TotalBeforeTax; this.TotalTax = pqf.Invoice.TotalTax; this.TotalAfterTax = pqf.Invoice.TotalAfterTax; this.TotalBeforeTaxStr = Convert.ToString(this.TotalBeforeTax); this.TotalTaxStr = Convert.ToString(TotalTax); this.TotalAfterTaxStr = Convert.ToString(TotalAfterTax); if (pqf.Invoice.ExcIncGST == true) { ExcludingTax = false; IncludingTax = true; // PQDEntity.GSTRate = 0; } else { ExcludingTax = true; IncludingTax = false; // PQDEntity.GSTRate = TaxRate; } this.PIStatus = pqf.Invoice.PIStatus; if (this.PIStatus == Convert.ToByte(PI_Status.Paid)) { AllFieldsReadonly = true; AllFieldsEnabled = false; } else { AllFieldsReadonly = false; AllFieldsEnabled = true; } this.BEDetailsEntity = new ObservableCollection <AccountDataGridViewModel>(); if (pqf.BEInvoiceDetails.Count() > 0) { foreach (var item in pqf.BEInvoiceDetails) { AccountDataGridViewModel pqEntity = new AccountDataGridViewModel(AccountsList); pqEntity.SelectedAccountName = item.AccountName; var acc = Accounts.Where(e => e.AccountName == item.AccountName).FirstOrDefault(); if (acc != null) { pqEntity.SelectedAccountId = acc.AccountID; } pqEntity.PQAmount = item.PQAmount; pqEntity.PQAmountStr = Convert.ToString(item.PQAmount); pqEntity.GSTRate = item.GSTRate; pqEntity.Description = item.Description; var tax = Taxes.Where(e => e.TaxRate == item.GSTRate).FirstOrDefault(); if (tax != null) { pqEntity.SelectedTaxID = tax.TaxID; } BEDetailsEntity.Add(pqEntity); } } else { var row = new AccountDataGridViewModel(AccountsList); BEDetailsEntity.Add(row); OnPropertyChanged("BEDetailsEntity"); } } else { GetNewPQ(); } }
/// <summary> /// This method is used to get Purchase Invoice details /// </summary> /// <param name="pqId"></param> /// <returns></returns> public PurchaseInvoiceForm GetPurchaseInvoice(string pqno) { PurchaseInvoiceForm pqf = new PurchaseInvoiceForm(); try { using (SDNPurchasingDBEntities entities = new SDNPurchasingDBEntities()) { var pq = (from pqs in entities.PurchaseInvoices where pqs.PI_No == pqno && (pqs.IsDeleted == false || pqs.IsDeleted == null) select new PurchaseInvoiceEntity { ID = pqs.ID, SupplierID = pqs.Sup_Id, InvoiceNo = pqs.PI_No, InvoiceDate = pqs.PI_Date, PaymentDueDate = pqs.PI_Pmt_Due_Date, TermsAndConditions = pqs.PI_TandC, TotalBeforeTax = pqs.PI_Tot_bef_Tax, TotalTax = pqs.PI_GST_Amt, TotalAfterTax = pqs.PI_Tot_aft_Tax, ExcIncGST = pqs.Exc_Inc_GST, OurPONo = pqs.Our_PO_No, PIStatus = pqs.PI_Status }).SingleOrDefault(); if (pq != null) { pqf.Invoice = pq; } var pqd = (from pqds in entities.PurchaseInvoiceDetails where pqds.PI_ID == pq.ID select new PurchaseInvoiceDetailEntity { ID = pqds.ID, PIID = pqds.PI_ID, PINo = pqds.PI_No, PandSCode = pqds.PandS_Code, PandSName = pqds.PandS_Name, PIQty = pqds.PI_Qty, Price = pqds.PI_Price, PIDiscount = pqds.PI_Discount, PIAmount = pqds.PI_Amount, GSTRate = pqds.GST_Rate }).ToList <PurchaseInvoiceDetailEntity>(); if (pqd != null) { pqf.InvoiceDetails = pqd; } return(pqf); } } 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; } }
/// <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; } }
public int UpdationInvoice(PurchaseInvoiceForm invoiceData) { try { using (SASEntitiesEDM entities = new SASEntitiesEDM()) { BusinessExpens obj = entities.BusinessExpenses.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 = Convert.ToDateTime(invoiceData.Invoice.InvoiceDateStr); 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 = Convert.ToDateTime(invoiceData.Invoice.PaymentDueDateStr); 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 && e.Type == "BE").ToList(); if (objPurchase != null) { foreach (var item in objPurchase) { entities.PurchaseInvoiceDetails.Remove(item); entities.SaveChanges(); } } BusinessExpensesDetail PIDetails; if (invoiceData.BEInvoiceDetails != null) { foreach (PurchaseInvoiceBEDetailsEntity beDetailEntity in invoiceData.BEInvoiceDetails) { PIDetails = new BusinessExpensesDetail(); PIDetails.PI_ID = obj.ID; 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; entities.BusinessExpensesDetails.Add(PIDetails); entities.SaveChanges(); } } return(obj.ID); } } catch (Exception ex) { throw ex; } }
public int AddUpdateInvoice(PurchaseInvoiceForm quotationData) { IPurchaseInvoiceBEDAL PQDAL = new PurchaseInvoiceBEDAL(); return(PQDAL.AddUpdateInvoice(quotationData)); }