public Tuple <CrudStatus, int> SaveInvoice(InvoiceDetails invoiceDetails) { if (invoiceDetails != null && invoiceDetails.Products != null) { _myshopDb = new MyshopDb(); Sale_Tr_Invoice _SaleTrans = new Sale_Tr_Invoice(); _SaleTrans.BalanceAmount = invoiceDetails.BalanceAmount; _SaleTrans.CustomerId = invoiceDetails.CustomerId; _SaleTrans.GrandTotal = invoiceDetails.GrandTotal; _SaleTrans.GstAmount = invoiceDetails.GstAmount; _SaleTrans.GstRate = WebSession.GstRate; _SaleTrans.InvoiceDate = DateTime.Now; _SaleTrans.PaidAmount = invoiceDetails.PaidAmount; _SaleTrans.PayModeId = invoiceDetails.PayModeId; _SaleTrans.PayModeRefNo = invoiceDetails.PayModeRefNo; _SaleTrans.SubTotalAmount = invoiceDetails.SubTotalAmount; _SaleTrans.IsSync = false; _SaleTrans.IsDeleted = false; _SaleTrans.IsCancelled = false; _SaleTrans.IsAmountRefunded = false; _SaleTrans.CreatedDate = DateTime.Now; _SaleTrans.CreatedBy = WebSession.UserId; _SaleTrans.ShopId = WebSession.ShopId; _myshopDb.Sale_Tr_Invoice.Add(_SaleTrans); if (_myshopDb.SaveChanges() > 0) { foreach (InvoiceProduct item in invoiceDetails.Products) { Sale_Dtl_Invoice _newDetails = new Sale_Dtl_Invoice(); _newDetails.CreatedBy = WebSession.UserId; _newDetails.CreatedDate = DateTime.Now; _newDetails.Discount = item.Discount; _newDetails.InvoiceId = _SaleTrans.InvoiceId; _newDetails.IsDeleted = false; _newDetails.IsSync = false; _newDetails.Price = item.SalePrice; _newDetails.ProductId = item.ProductId; _newDetails.Qty = item.Qty; _newDetails.ShopId = WebSession.ShopId; _newDetails.Remark = item.Remark; _newDetails.ReturnQty = 0; _myshopDb.Sale_Dtl_Invoice.Add(_newDetails); } int _result = _myshopDb.SaveChanges(); return(_result > 0 ? new Tuple <CrudStatus, int>(CrudStatus.Inserted, _SaleTrans.InvoiceId) : new Tuple <CrudStatus, int>(CrudStatus.NoEffect, 0)); } else { return(new Tuple <CrudStatus, int>(CrudStatus.NoEffect, 0)); } } else { return(new Tuple <CrudStatus, int>(CrudStatus.InvalidParameter, 0)); } }
public List <InvoiceDetails> SearchInvoice(string searchValue) { _myshopDb = new MyshopDb(); List <InvoiceDetails> _lstInvoice = new List <InvoiceDetails>(); var _proList = _myshopDb.Sale_Tr_Invoice.Where(x => (searchValue.Equals(string.Empty) || x.InvoiceId.ToString().IndexOf(searchValue) > -1 || x.Gbl_Master_Customer.FirstName.IndexOf(searchValue) > -1 || x.Gbl_Master_Customer.LastName.IndexOf(searchValue) > -1 || x.Gbl_Master_Customer.MiddleName.IndexOf(searchValue) > -1) && !x.IsDeleted && x.ShopId.Equals(WebSession.ShopId)) .ToList(); foreach (Sale_Tr_Invoice _currentInvoice in _proList) { InvoiceDetails _newInvoice = new InvoiceDetails(); _newInvoice.BalanceAmount = _currentInvoice.BalanceAmount; _newInvoice.CustomerId = _currentInvoice.CustomerId; _newInvoice.CustomerName = string.Format("{0} {1} {2}", _currentInvoice.Gbl_Master_Customer.FirstName ?? string.Empty, _currentInvoice.Gbl_Master_Customer.MiddleName ?? string.Empty, _currentInvoice.Gbl_Master_Customer.LastName ?? string.Empty); _newInvoice.CustomerAddress = string.Format("{0}\n{1}, {2}", _currentInvoice.Gbl_Master_Customer.Address ?? string.Empty, _currentInvoice.Gbl_Master_Customer.Gbl_Master_City.CityName ?? string.Empty, _currentInvoice.Gbl_Master_Customer.Gbl_Master_State.StateName.ToString() ?? string.Empty); _newInvoice.GrandTotal = _currentInvoice.GrandTotal; _newInvoice.GstAmount = Convert.ToDecimal(_currentInvoice.GstAmount); _newInvoice.InvoiceDate = _currentInvoice.InvoiceDate; _newInvoice.PaidAmount = _currentInvoice.PaidAmount; _newInvoice.PayModeId = _currentInvoice.PayModeId; _newInvoice.PayModeRefNo = _currentInvoice.PayModeRefNo; _newInvoice.SubTotalAmount = _currentInvoice.SubTotalAmount; _newInvoice.InvoiceId = _currentInvoice.InvoiceId; _newInvoice.IsRefund = _currentInvoice.IsAmountRefunded; _newInvoice.IsCancelled = _currentInvoice.IsCancelled; _newInvoice.CancelDate = _currentInvoice.CancelledDate ?? default(DateTime); _newInvoice.CancelRemark = _currentInvoice.CancelRemark; _newInvoice.GstRate = Convert.ToDecimal(_currentInvoice.GstRate); List <InvoiceProduct> _lstProducts = new List <InvoiceProduct>(); foreach (Sale_Dtl_Invoice _currentDetails in _myshopDb.Sale_Dtl_Invoice.Where(x => x.InvoiceId.Equals(_newInvoice.InvoiceId) && x.IsDeleted == false)) { InvoiceProduct _newProduct = new InvoiceProduct(); _newProduct.Discount = Convert.ToInt32(_currentDetails.Discount); _newProduct.ProductId = _currentDetails.ProductId; _newProduct.ProductName = _currentDetails.Gbl_Master_Product.ProductName; _newProduct.Qty = _currentDetails.Qty; _newProduct.Remark = _currentDetails.Remark; _newProduct.SalePrice = _currentDetails.Price; _newProduct.ReturnAmount = _currentDetails.ReturnAmount ?? 0.00M; _newProduct.ReturnDate = _currentDetails.ReturnDate ?? default(DateTime); _newProduct.ReturnRemark = _currentDetails.ReturnRemark ?? string.Empty; _newProduct.ReturnQty = _currentDetails.ReturnQty ?? 0; _newProduct.IsReturn = _currentDetails.IsReturn ?? false; _lstProducts.Add(_newProduct); } _newInvoice.Products = _lstProducts; _lstInvoice.Add(_newInvoice); } return(_lstInvoice); }