public ActionResult ReportPurchaseInvoice(int Id) { var company = _companyService.GetQueryable().FirstOrDefault(); var q = _customPurchaseInvoiceDetailService.GetQueryableObjectsByCustomPurchaseInvoiceId(Id).Include("CustomPurchaseInvoice").Include("Item").Include("UoM"); string user = AuthenticationModel.GetUserName(); var query = (from model in q select new { SKU = model.Item.Sku, Name = model.Item.Name, UoM = model.Item.UoM.Name, model.Quantity, Price = model.ListedUnitPrice, model.Discount, GlobalDiscount = model.CustomPurchaseInvoice.Discount, Tax = model.CustomPurchaseInvoice.Tax, Allowance = model.CustomPurchaseInvoice.Allowance, Code = model.CustomPurchaseInvoice.Code, Date = model.CustomPurchaseInvoice.ConfirmationDate.Value, contact = "", CompanyName = company.Name, CompanyAddress = company.Address, CompanyContactNo = company.ContactNo, User = user, Description = model.CustomPurchaseInvoice.Description, }).ToList(); var rd = new ReportDocument(); //Loading Report rd.Load(Server.MapPath("~/") + "Reports/General/PurchaseInvoice.rpt"); // Setting report data source rd.SetDataSource(query); var stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat); return(File(stream, "application/pdf")); }
public dynamic GetListDetail(string _search, long nd, int rows, int?page, string sidx, string sord, int id, string filters = "") { // Construct where statement string strWhere = GeneralFunction.ConstructWhere(filters); string filter = null; GeneralFunction.ConstructWhereInLinq(strWhere, out filter); if (filter == "") { filter = "true"; } // Get Data var q = _customPurchaseInvoiceDetailService.GetQueryableObjectsByCustomPurchaseInvoiceId(id).Include("CustomPurchaseInvoice").Include("Item"); var query = (from model in q select new { model.Id, model.Code, model.CustomPurchaseInvoiceId, custompurchaseinvoice = model.CustomPurchaseInvoice.Code, model.ItemId, item = model.Item.Name, model.Quantity, model.Discount, model.ListedUnitPrice, model.Amount, model.CoGS, }).Where(filter).OrderBy(sidx + " " + sord); //.ToList(); var list = query.AsEnumerable(); var pageIndex = Convert.ToInt32(page) - 1; var pageSize = rows; var totalRecords = query.Count(); var totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize); // default last page if (totalPages > 0) { if (!page.HasValue) { pageIndex = totalPages - 1; page = totalPages; } } list = list.Skip(pageIndex * pageSize).Take(pageSize); return(Json(new { total = totalPages, page = page, records = totalRecords, rows = ( from model in list select new { id = model.Id, cell = new object[] { model.Code, model.CustomPurchaseInvoiceId, model.custompurchaseinvoice, model.ItemId, model.item, model.Quantity, model.Discount, model.ListedUnitPrice, model.Amount, model.CoGS, } }).ToArray() }, JsonRequestBehavior.AllowGet)); }