public JsonResult PrintCustomerDueReportAsPdf([FromBody] dynamic reportParam)
        {
            try
            {
                var viewName = "CustomerWiseDueReportGenerated";

                var customerId     = ((JObject)reportParam).SelectToken("customers").ToString();
                var isPaidIncluded = Convert.ToBoolean(((JObject)reportParam).SelectToken("isPaidIncluded").ToString());

                var _fromDateString = ((JObject)reportParam).SelectToken("startDate").ToString();
                var _toDateString   = ((JObject)reportParam).SelectToken("endDate").ToString();

                DateTime _fromDate = DateTime.Now;
                DateTime _toDate   = DateTime.Now;
                if (DateTime.TryParse(_fromDateString, out _fromDate))
                {
                    //code
                }
                else
                {
                    _fromDate = DateTime.Now.AddMonths(-1);
                }
                if (!DateTime.TryParse(_toDateString, out _toDate))
                {
                    //code
                }

                _companyInfoLogic = new Lms_CompanyInfoLogic(_cache, new EntityFrameworkGenericRepository <Lms_CompanyInfoPoco>(_dbContext));
                var companyInfo = _companyInfoLogic.GetSingleById(1);
                if (companyInfo != null)
                {
                    SessionData.CompanyName = !string.IsNullOrEmpty(companyInfo.CompanyName) ? companyInfo.CompanyName : "";
                    SessionData.CompanyLogo = companyInfo.CompanyLogo != null?Convert.ToBase64String(companyInfo.CompanyLogo) : null;

                    SessionData.CompanyAddress   = !string.IsNullOrEmpty(companyInfo.MainAddress) ? companyInfo.MainAddress.ToUpper() : "";
                    SessionData.CompanyTelephone = !string.IsNullOrEmpty(companyInfo.Telephone) ? companyInfo.Telephone : "";
                    SessionData.CompanyFax       = companyInfo.Fax;
                    SessionData.CompanyEmail     = !string.IsNullOrEmpty(companyInfo.EmailAddress) ? companyInfo.EmailAddress : "";
                    SessionData.CompanyTaxNumber = !string.IsNullOrEmpty(companyInfo.TaxNumber) ? companyInfo.TaxNumber : "";
                }

                string rptDuration = _fromDate.ToString("dd/MMM/yyyy") + " - " + _toDate.ToString("dd/MMM/yyyy");
                _toDate = _toDate.AddDays(1);



                ViewModel_Report_CustomerDue viewModel_Report_CustomerDue = new ViewModel_Report_CustomerDue();

                if (string.IsNullOrEmpty(customerId))
                {
                    return(Json(""));
                }

                var customerInfo = _customerLogic.GetSingleById(Convert.ToInt32(customerId));
                viewModel_Report_CustomerDue.CustomerId         = customerInfo.Id;
                viewModel_Report_CustomerDue.CustomerName       = customerInfo.CustomerName;
                viewModel_Report_CustomerDue.TotalAmountPayable = 0;
                viewModel_Report_CustomerDue.InvoiceDueDays     = customerInfo.InvoiceDueDays;

                var addressMappingInfo = _addressMappingLogic.GetList().Where(c => c.CustomerId == customerInfo.Id && c.AddressTypeId == (byte)Enum_AddressType.Billing).FirstOrDefault();
                var addressInfo        = _addressLogic.GetSingleById(addressMappingInfo.AddressId);

                viewModel_Report_CustomerDue.AddressLine1 = addressInfo.UnitNumber + " " + addressInfo.AddressLine;

                viewModel_Report_CustomerDue.City         = _cityLogic.GetSingleById(addressInfo.CityId).CityName;
                viewModel_Report_CustomerDue.ProvinceCode = _provinceLogic.GetSingleById(addressInfo.ProvinceId).ShortCode;
                viewModel_Report_CustomerDue.PostCode     = addressInfo.PostCode;

                var invoices = _invoiceLogic.GetList().Where(c => c.BillerCustomerId == Convert.ToInt32(customerId) && c.CreateDate >= _fromDate && c.CreateDate <= _toDate).ToList();

                if (isPaidIncluded == false)
                {
                    invoices = invoices.Where(c => c.PaidAmount == null || c.PaidAmount < c.TotalInvoiceAmount).ToList();
                }

                if (invoices.Count < 1)
                {
                    return(Json(""));
                }

                var paymentCollections = _paymentCollectionLogic.GetList();
                var paymentMethods     = _paymentMethodLogic.GetList();
                var banks = _bankLogic.GetList();

                List <ViewModel_InvoiceDueData> invoiceDataList = new List <ViewModel_InvoiceDueData>();
                foreach (var invoice in invoices)
                {
                    ViewModel_InvoiceDueData invoiceDueData = new ViewModel_InvoiceDueData();

                    invoiceDueData.InvoiceNo          = invoice.Id;
                    invoiceDueData.InvoiceDate        = invoice.CreateDate.ToString("M/d/yyyy");
                    invoiceDueData.TotalInvoiceAmount = invoice.TotalInvoiceAmount;
                    invoiceDueData.PaidAmount         = invoice.PaidAmount == null ? 0 : invoice.PaidAmount;
                    invoiceDueData.BalanceDueAmount   = invoice.TotalInvoiceAmount - invoiceDueData.PaidAmount;

                    var paymentCollectionList = paymentCollections.Where(c => c.InvoiceId == invoice.Id).ToList();
                    if (paymentCollectionList.Count > 0)
                    {
                        var paymentCollection = paymentCollectionList.LastOrDefault();
                        if (paymentCollection != null)
                        {
                            invoiceDueData.PaymentMethod = paymentMethods.Where(c => c.Id == paymentCollection.PaymentMethodId).FirstOrDefault().MethodName;
                            invoiceDueData.PaymentDate   = paymentCollection.PaymentDate.ToString("M/d/yyyy");
                            decimal chqAmount = 0;
                            foreach (var coll in paymentCollectionList)
                            {
                                chqAmount += coll.ChequeAmount != null ? (decimal)coll.ChequeAmount : 0;
                            }
                            invoiceDueData.ChqDate = paymentCollection.ChequeDate != null?Convert.ToDateTime(paymentCollection.ChequeDate).ToString("M/d/yyyy") : "";

                            invoiceDueData.ChqNo         = paymentCollection.ChequeNo;
                            invoiceDueData.ChqAmount     = chqAmount.ToString("0.00");
                            invoiceDueData.BankShortName = banks.Where(c => c.Id == paymentCollection.BankId).FirstOrDefault().BankShortName;
                        }
                    }

                    invoiceDataList.Add(invoiceDueData);

                    viewModel_Report_CustomerDue.TotalAmountPayable += invoiceDueData.BalanceDueAmount;
                }

                viewModel_Report_CustomerDue.InvoiceData = invoiceDataList;

                var webrootPath   = _hostingEnvironment.WebRootPath;
                var uniqueId      = DateTime.Now.ToFileTime();
                var fileName      = "CustomerDueReport_" + uniqueId + ".pdf";
                var directoryPath = webrootPath + "/contents/reports/";
                var filePath      = directoryPath + fileName;

                if (!System.IO.Directory.Exists(directoryPath))
                {
                    System.IO.Directory.CreateDirectory(directoryPath);
                }

                var pdfReport = new ViewAsPdf(viewName, viewModel_Report_CustomerDue)
                {
                    PageSize = Rotativa.AspNetCore.Options.Size.Letter
                };
                var file = pdfReport.BuildFile(ControllerContext).Result;

                System.IO.File.WriteAllBytes(filePath, file);

                string returnPath = "/contents/reports/" + fileName;

                //_emailService.SendEmail("*****@*****.**", "test subject", "test body content", returnPath);

                return(Json(returnPath));
            }
            catch (Exception ex)
            {
                return(null);
            }
            //return View();
        }
 public CompanyInfoController(IMemoryCache cache, LogisticsContext dbContext)
 {
     _dbContext        = dbContext;
     _companyInfoLogic = new Lms_CompanyInfoLogic(_cache, new EntityFrameworkGenericRepository <Lms_CompanyInfoPoco>(_dbContext));
 }