Ejemplo n.º 1
0
        public ActionResult Index()
        {
            sdtoUser sessionUser = UtilityHelper.UserSession.GetSession(UtilityHelper.UserSession.LoggedInUser) as sdtoUser;
            long cCompanyId = 0;
            if (sessionUser != null && sessionUser.CompanyId != null)
                cCompanyId = sessionUser.CompanyId.Value;
            var cmpList = db.Companies.Where(x => x.IsDeleted == false).Select(x => new { CompanyId = x.CompanyId.ToString(), CompanyName = x.CompanyName.ToString() }).ToList();
            cmpList.Insert(0, new { CompanyId = "0", CompanyName = "Select a company" });
            sdtoViewReportFilter filter = new sdtoViewReportFilter() { CompanyId = cCompanyId.ToString() };

            //setup properties
            var modelAccountHeads = new MultipleSelectionModel();
            var selectedAccounts = new List<MutipleSelectionItem>();
            //setup a view model
            modelAccountHeads.Items = db.AccountHeads.Select(x => new MutipleSelectionItem() { Value = x.AccountHeadId.ToString(), Text = x.AccountName }).ToList();
            // model.SelectedFruits = selectedFruits;
            filter.Accounts = modelAccountHeads;

            filter.Companies = new SelectList(cmpList, "CompanyId", "CompanyName", cCompanyId);

            var membersMultiModel = new MultipleSelectionModel();
            membersMultiModel.Items = db.User.Where(x => x.UserType == Data.Models.Enumerations.UserType.Member).Select(x => new MutipleSelectionItem() { Value = x.UserID.ToString(), Text = x.FirstName + " " + x.LastName }).ToList();
            filter.Members = membersMultiModel;

            var statusMultiModel = new MultipleSelectionModel();
            List<MutipleSelectionItem> statusItems = new List<MutipleSelectionItem>();
            statusItems.Add(new MutipleSelectionItem() { Text = Data.Models.Enumerations.LoanStatus.Active.ToString(), Value = Convert.ToInt16(Data.Models.Enumerations.LoanStatus.Active).ToString() });
            statusItems.Add(new MutipleSelectionItem() { Text = Data.Models.Enumerations.LoanStatus.Approved.ToString(), Value = Convert.ToInt16(Data.Models.Enumerations.LoanStatus.Approved).ToString() });
            statusItems.Add(new MutipleSelectionItem() { Text = Data.Models.Enumerations.LoanStatus.Cancelled.ToString(), Value = Convert.ToInt16(Data.Models.Enumerations.LoanStatus.Cancelled).ToString() });
            statusItems.Add(new MutipleSelectionItem() { Text = Data.Models.Enumerations.LoanStatus.Completed.ToString(), Value = Convert.ToInt16(Data.Models.Enumerations.LoanStatus.Completed).ToString() });
            statusItems.Add(new MutipleSelectionItem() { Text = Data.Models.Enumerations.LoanStatus.Inactive.ToString(), Value = Convert.ToInt16(Data.Models.Enumerations.LoanStatus.Inactive).ToString() });
            statusItems.Add(new MutipleSelectionItem() { Text = Data.Models.Enumerations.LoanStatus.Recalled.ToString(), Value = Convert.ToInt16(Data.Models.Enumerations.LoanStatus.Recalled).ToString() });
            statusMultiModel.Items = statusItems;
            filter.Status = statusMultiModel;

            var loansMultiModel = new MultipleSelectionModel();
            loansMultiModel.Items = db.sdtoLoanInfoes.Where(x => x.IsDeleted == false && x.Status == Data.Models.Enumerations.LoanStatus.Active).Select(x => new MutipleSelectionItem() { Value = x.LoanId.ToString(), Text = x.LoanId.ToString() }).ToList(); //+ " [" + x.Member.FirstName + " " + x.Member.LastName + "]" }).ToList();
            filter.Loans = loansMultiModel;

            var depositsMultiModel = new MultipleSelectionModel();
            depositsMultiModel.Items = db.sdtoDepositInfoes.Where(x => x.IsDeleted == false && x.Status == Data.Models.Enumerations.DepositStatus.Active).Select(x => new MutipleSelectionItem() { Value = x.DepositId.ToString(), Text = x.DepositId.ToString() }).ToList(); //+ " [" + x.Member.FirstName + " " + x.Member.LastName + "]" }).ToList();
            filter.Loans = depositsMultiModel;

            return View(filter);
        }
        public ActionResult LedgerReport()
        {
            sdtoViewReportFilter filter = new sdtoViewReportFilter() { };

            //setup properties
            var modelAccountHeads = new MultipleSelectionModel();
            var selectedAccounts = new List<MutipleSelectionItem>();
            //setup a view model
            modelAccountHeads.Items = dbContext.AccountHeads.Select(x => new MutipleSelectionItem() { Value = x.AccountHeadId.ToString(), Text = x.AccountName }).ToList();
            // model.SelectedFruits = selectedFruits;
            filter.Accounts = modelAccountHeads;

            sdtoUser sessionUser = UtilityHelper.UserSession.GetSession(UtilityHelper.UserSession.LoggedInUser) as sdtoUser;
            long cCompanyId = 0;
            if (sessionUser != null && sessionUser.CompanyId != null)
                cCompanyId = sessionUser.CompanyId.Value;
            var cmpList = dbContext.Companies.Where(x => x.IsDeleted == false).Select(x => new { CompanyId = x.CompanyId.ToString(), CompanyName = x.CompanyName.ToString() }).ToList();
            cmpList.Insert(0, new { CompanyId = "0", CompanyName = "Select a company" });
            filter.Companies = new SelectList(cmpList, "CompanyId", "CompanyName", cCompanyId);

            return View(filter);
        }
        public ActionResult TrialBalance(sdtoViewReportFilter filter)
        {
            //sdtoLedgerReport sessionUser = UtilityHelper.UserSession.GetSession(UtilityHelper.UserSession.LoggedInUser) as sdtoLedgerReport;
            //long CompanyId = 0;

            //bfReport objReport = new bfReport(null);
            //List<sdtoLedgerReport> lst = new List<sdtoLedgerReport>();
            //lst = objReport.GetRptLedgerReport(CompanyId, 1, DateTime.Now.Date.AddDays(-20), DateTime.Now, "1,2,3,4,5,6,7,8,9,10").ToList();

            //ReportDocument rd = new ReportDocument();
            //rd.Load(Path.Combine(Server.MapPath("~/Report"), "TrailBalance.rpt"));
            ////rd.SetParameterValue("Heading", "Ledger Report");
            //rd.SetDatabaseLogon("sa", "TechnoCrunchLabs", @"DELL-PC\SQLEXPRESS", "LoanManagement");
            //rd.SetDataSource(lst);
            //Response.Buffer = false;
            //Response.ClearContent();
            //Response.ClearHeaders();
            //try
            //{
            //    System.IO.MemoryStream mem = (System.IO.MemoryStream)rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
            //    Response.Clear();
            //    Response.Buffer = true;
            //    Response.ContentType = "application/pdf";
            //    Response.BinaryWrite(mem.ToArray());

            //    Stream str = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
            //    str.Seek(0, SeekOrigin.Begin);
            //    return File(str, "application/pdf", "TrialBalance.pdf");
            //}
            //catch (Exception e)
            //{
            //    throw e.InnerException;
            //}

            var filterModel = GetMutipleSelectionModel(filter.Accounts.PostedItems);

            // ledger report -> account id
            // cash book -> account id (book type cash only)
            // bank book -> account (book type bank only)
            // trial balance

            long CompanyId = 0;
            sdtoUser sessionUser = UtilityHelper.UserSession.GetSession(UtilityHelper.UserSession.LoggedInUser) as sdtoUser;
            if (sessionUser != null)
                CompanyId = sessionUser.CompanyId.Value;

            List<int> l = new List<int>();
            string.Join(",", l.Select(x => x));

            bfReport objReport = new bfReport(null);
            List<sdtoLedgerReport> lst = new List<sdtoLedgerReport>();
            lst = objReport.GetRptLedgerReport(Convert.ToInt64(filter.CompanyId), filter.OperationId, filter.StartDate, filter.EndDate, filter.Accounts != null && filter.Accounts.PostedItems != null && filter.Accounts.PostedItems.Ids != null ? string.Join(",", filter.Accounts.PostedItems.Ids.Select(x => x)) : "");

            //setup properties
            var modelAccountHeads = new MultipleSelectionModel();
            var selectedAccounts = new List<MutipleSelectionItem>();
            //setup a view model
            modelAccountHeads.Items = dbContext.AccountHeads.Select(x => new MutipleSelectionItem() { Value = x.AccountHeadId.ToString(), Text = x.AccountName }).ToList();
            // model.SelectedFruits = selectedFruits;
            filter.Accounts = modelAccountHeads;

            long cCompanyId = 0;
            if (sessionUser != null && sessionUser.CompanyId != null)
                cCompanyId = sessionUser.CompanyId.Value;
            var cmpList = dbContext.Companies.Where(x => x.IsDeleted == false).ToList();
            cmpList.Insert(0, new sdtoCompany() { CompanyId = 0, CompanyName = "Select a company" });
            filter.Companies = new SelectList(cmpList, "CompanyId", "CompanyName", cCompanyId);

            ReportDocument rd = new ReportDocument();
            rd.Load(Path.Combine(Server.MapPath("~/Report"), "TrailBalance.rpt"));
            //rd.SetParameterValue("Heading", "Ledger Report");
            string strConn = ConfigurationManager.ConnectionStrings["LoanDBContext"].ConnectionString;
            System.Data.SqlClient.SqlConnection obj = new System.Data.SqlClient.SqlConnection(strConn);
            string uName = ConfigurationManager.AppSettings["DbUserName"];
            string uPassword = ConfigurationManager.AppSettings["DbPassword"];
            rd.SetDatabaseLogon(uName, uPassword, obj.DataSource, obj.Database);

            rd.SetDataSource(lst);
            Response.Buffer = false;
            Response.ClearContent();
            Response.ClearHeaders();
            try
            {
                //System.IO.MemoryStream mem = (System.IO.MemoryStream)rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                //Response.Clear();
                //Response.Buffer = true;
                //Response.ContentType = "application/pdf";
                //Response.BinaryWrite(mem.ToArray());

                Stream str = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                str.Seek(0, SeekOrigin.Begin);
                return File(str, "application/pdf", "TrialBalance.pdf");
            }
            catch (Exception e)
            {
                throw e.InnerException;
            }

            return View(filter);
        }