Exemplo n.º 1
0
        public ActionResult DcrPrint()
        {
            DcrPublishSearchModel searchModel     = new DcrPublishSearchModel();
            DcrPublishViewModel   dcrPublishModel = new DcrPublishViewModel();

            decimal?USER_NO = Session["sess_USER_NO"] as decimal?;


            //string path = Path.GetTempFileName();// file implementation with temp file in system
            //string path = @"d:\test\MyTest.txt";

            //creating file in a specified directory

            string publish_export_url = System.Configuration.ConfigurationManager.AppSettings["PUBLISH_EXPORT_URL"];


            string Search_User = Request.QueryString["Search_User"];

            searchModel.Search_pubno = decimal.Parse(Request.QueryString["Search_pubno"]);



            string[] user_dcr = Search_User.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);

            string directory_path = publish_export_url + "\\" + searchModel.Search_pubno;

            if (user_dcr.Length > 0)
            {
                if (!System.IO.Directory.Exists(directory_path))
                {
                    System.IO.Directory.CreateDirectory(directory_path);
                }
            }

            TRN_USER_PUBLISH user_publish = db.TRN_USER_PUBLISH.Where(q => q.PUBLISH_NO == searchModel.Search_pubno).FirstOrDefault();

            searchModel.Search_Date_From = user_publish.TRN_DATE_FROM;

            searchModel.Search_Date_To = user_publish.TRN_DATE_TO;


            string content = "";

            foreach (string user in user_dcr)
            {
                decimal   user_no  = decimal.Parse(user);
                SEC_USERS sec_user = db.SEC_USERS.Where(u => u.USER_NO == user_no).FirstOrDefault();

                string path = directory_path + "\\" + searchModel.Search_pubno + "_" + sec_user.USER_NAME + ".html";

                if (!System.IO.File.Exists(path))
                {
                    List <DCR_PUB_EXP_GET_Result> expense =
                        db.DCR_PUB_EXP_GET(user_no, null,
                                           searchModel.Search_Date_From, searchModel.Search_Date_To, 1).ToList();

                    content = "<html><title>DCR Publish Report</title><body>";
                    //content += "<table>";

                    content += "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" style=\"font-size:13px\"><tr>";
                    content += "<td colspan=\"9\" style=\"text-align:center;  border:solid 1px #e4e4e4;\"> <h4>DCR Top Sheet</h4>";

                    content += "<b>Publish No. : " + searchModel.Search_pubno + "<br />";
                    content += "User Full Name : " + sec_user.USER_FULL_NAME + "<br />";

                    content += "Contact : " + sec_user.USER_MOBILE + "<br />";

                    content += "User Name : " + sec_user.USER_NAME + "<br />";

                    content += "Date From : " + searchModel.Search_Date_From.Value.ToString("yyyy-MM-dd") + " Date To : " + searchModel.Search_Date_To.Value.ToString("yyyy-MM-dd");

                    content += "</b></td></tr>";

                    content += "\n<tr><th style=\"text-align:center; border:solid 1px #e4e4e4;\">Date</th><th style=\"text-align:center; border:solid 1px #e4e4e4;\">T.A.</th><th class=\"right\"> T.Entertainment  </th>  <th class=\"right\">P.B.</th><th class=\"right\"> D.A. </th><th class=\"right\"> Other</th><th style=\"text-align:center; border:solid 1px #e4e4e4;\">Total </th> </tr>";

                    int ta        = 0;
                    int te        = 0;
                    int pb        = 0;
                    int da        = 0;
                    int other     = 0;
                    int total_exp = 0;

                    int total_final = 0;

                    foreach (var exp in expense)
                    {
                        ta    += (int)exp.TA_AMT;
                        te    += (int)exp.TE_AMT;
                        pb    += (int)exp.PB_AMT;
                        da    += (int)exp.DA_AMT;
                        other += (int)exp.OB_AMT;

                        total_exp = (int)exp.TA_AMT + (int)exp.TE_AMT + (int)exp.PB_AMT + (int)exp.DA_AMT + (int)exp.OB_AMT;
                        content  += "\n<tr><td  style=\"text-align:center; border:solid 1px #e4e4e4; border-top:none;\">" + exp.DT.Value.ToString("yyyy-MM-dd") + "</td><td style=\"text-align:center; border:solid 1px #e4e4e4;\">" + exp.TA_AMT + " </td><td style=\"text-align:center; border:solid 1px #e4e4e4;\">" + exp.TE_AMT + "</td><td style=\"text-align:center; border:solid 1px #e4e4e4;\">" + exp.PB_AMT + "</td><td style=\"text-align:center; border:solid 1px #e4e4e4;\">" + exp.DA_AMT + "</td><td style=\"text-align:center; border:solid 1px #e4e4e4;\">" + exp.OB_AMT + "</td> <td style=\"text-align:center; border:solid 1px #e4e4e4;\"> " + total_exp + "</td> </tr>";
                    }

                    total_final = ta + te + pb + da + other;
                    content    += "<tr style=\"font-weight:bold\"><td style=\"text-align:center; border:solid 1px #e4e4e4; border-top:none;\">Total DCR Bill</td><td style=\" font-weight:bold; text-align:center; border:solid 1px #e4e4e4; border-left:none;\"> " + String.Format("{0:#,###0}", ta) + " <td style=\" font-weight:bold; text-align:center; border:solid 1px #e4e4e4; border-left:none;\">" + String.Format("{0:#,###0}", te) + "</td><td style=\" font-weight:bold; text-align:center; border:solid 1px #e4e4e4; border-left:none;\">" + String.Format("{0:#,###0}", pb) + "</td><td style=\" font-weight:bold; text-align:center; border:solid 1px #e4e4e4; border-left:none;\">" + String.Format("{0:#,###0}", da) + "</td> <td style=\" font-weight:bold; text-align:center; border:solid 1px #e4e4e4; border-left:none;\">" + String.Format("{0:#,###0}", other) + "</td><td style=\" font-weight:bold; text-align:center; border:solid 1px #e4e4e4; border-left:none;\">" + String.Format("{0:#,###0}", total_final) + "</td></tr>";

                    content += "</table>";

                    List <DCR_PUB_SPECIMEN_GET_Result> specimen =
                        db.DCR_PUB_SPECIMEN_GET(user_no, null,
                                                searchModel.Search_Date_From, searchModel.Search_Date_To, 1).ToList();


                    content += "<table  class =\"page-break\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" style=\"font-size:13px; margin-top:20px; border-width:5px;border-color:Black;\">";
                    content += "<td colspan=\"5\"  style=\"text-align:center;  border:solid 1px #e4e4e4;\"><h4> Specimen Report</h4></td>";


                    content += "\n <tr><th>SL No. </th><th> Specimen Code </th><th>Specimen Name (Eng) </th><th>Specimen Name (Bng) </th><th>Quantity</th></tr>";


                    int sl_no = 1;

                    int total = 0;

                    foreach (var spec in specimen)
                    {
                        content += "\n<tr> <td  style=\"text-align:center;  border:solid 1px #e4e4e4;  border-top:none;\">" + sl_no++ + "</td>   <td  style=\"text-align:center;  border:solid 1px #e4e4e4;  border-top:none;\">" + spec.SPECIMEN_CODE + "</td><td  style=\"text-align:center;  border:solid 1px #e4e4e4;  border-top:none;\">" + spec.SPECIMEN_NAME + "</td><td  style=\"text-align:center;  border:solid 1px #e4e4e4;  border-top:none;\">" + spec.SPECIMEN_NAME_BNG + "</td><td  style=\"text-align:center;  border:solid 1px #e4e4e4;  border-top:none;\">" + spec.QTY + "</td></tr>";

                        total += (int)spec.QTY;
                    }

                    content += "<tr style=\"font-weight:bold\">";
                    content += "<td colspan=\"4\" align=\"center\"  style=\"text-align:center;  border:solid 1px #e4e4e4;  border-top:none;\">Grand Total</td>";

                    content += "<td style=\"text-align:center; border:solid 1px #e4e4e4; border-left:none; border-top:none;\">" + String.Format("{0:#,###0}", total) + "</td>";
                    content += "</tr>";

                    content += "</table>";

                    dcrPublishModel.expenses = new DcrExpenseModel();
                    //dcrPublishModel.expenses.user = user;
                    dcrPublishModel.expenses.date    = DateTime.Now;
                    dcrPublishModel.expenses.expense = expense;

                    dcrPublishModel.specimens = new DcrSpecimenModel();
                    //dcrPublishModel.specimens.user = user;
                    dcrPublishModel.specimens.date     = DateTime.Now;
                    dcrPublishModel.specimens.specimen = specimen;

                    dcrPublishModel.details = new List <DcrDetailsModel>();

                    dcrPublishModel.expenses.date  = searchModel.Search_Date_From;
                    dcrPublishModel.specimens.date = searchModel.Search_Date_From;

                    for (DateTime?date = searchModel.Search_Date_From;
                         date <= searchModel.Search_Date_To; date = date.Value.AddDays(1))
                    {
                        DcrDetailsModel dcrDetails = new DcrDetailsModel();

                        List <DCR_PUB_DCR_DETAIL_GET_Result> detail =
                            db.DCR_PUB_DCR_DETAIL_GET(user_no, null, date, date, 1).ToList();

                        List <TRN_EXPENSE_APPROVAL_GET_Result> detailexpense =
                            db.TRN_EXPENSE_APPROVAL_GET(
                                user_no, decimal.Parse(Session["sess_USER_NO"].ToString()),//parent
                                null, null, null, date, date, 1, 1, null).ToList();

                        if (detail.Count > 0 || detailexpense.Count > 0)
                        {
                            content += "<table><tbody>";
                            if (detail.Count > 0)
                            {
                                content += "<tr style=\"height:0px; font-size:0px;\"></tr><tr style=\"height:0px; font-size:0px;\"><td width=\"5%\">&nbsp;</td><td width=\"18%\">&nbsp;</td><td width=\"18%\">&nbsp;</td><td width=\"5%\">&nbsp;</td><td width=\"5%\">&nbsp;</td><td width=\"25%\">&nbsp;</td><td width=\"8%\">&nbsp;</td><td width=\"4%\">&nbsp;</td><td width=\"4%\">&nbsp;</td><td width=\"4%\">&nbsp;</td><td width=\"3%\">&nbsp;</td><td width=\"3%\">&nbsp;</td></tr>";

                                content += "<tr><td colspan=\"7\" style=\"background:#DDDDDD; text-align:center; border:solid 1px #e4e4e4;\">&nbsp;</td> <td style=\"background:#DDDDDD; text-align:center; border:solid 1px #e4e4e4; border-left:none;\"/>DCR Date</td><td style=\" text-align:center; border:solid 1px #e4e4e4; border-left:none;\">" + date.Value.ToString("yyyy-MM-dd") + " </td></tr>";

                                content += "<tr style=\"font-size:13px; background:#DDDDDD; font-weight:bold;\"><td colspan=\"2\" style=\" text-align:center; border:solid 1px #e4e4e4; border-left:none;\">Area of Work </td><td colspan=\"2\" style=\" text-align:center; border:solid 1px #e4e4e4; border-left:none;\">Time of Work</td><td rowspan=\"2\" style=\" text-align:center; border:solid 1px #e4e4e4; border-left:none;\">Institution<br>Name</td><td rowspan=\"2\" style=\" text-align:center; border:solid 1px #e4e4e4; border-left:none;\">Teacher Number</td><td rowspan=\"2\" style=\" text-align:center; border:solid 1px #e4e4e4; border-left:none;\">P. Work</td><td rowspan=\"2\" style=\" text-align:center; border:solid 1px #e4e4e4; border-left:none;\">T. Type</td><td rowspan=\"2\" style=\" text-align:center; border:solid 1px #e4e4e4; border-left:none;\">Fare</td></tr><tr style=\"font-size:13px; background:#DDDDDD; font-weight:bold;\"><td style=\" text-align:center; border:solid 1px #e4e4e4; border-top:none;\">From</td><td style=\" text-align:center; border:solid 1px #e4e4e4; border-left:none; border-top:none;\">To</td><td style=\" text-align:center; border:solid 1px #e4e4e4; border-left:none; border-top:none;\">From</td><td style=\" text-align:center; border:solid 1px #e4e4e4; border-left:none; border-top:none;\">To</td> </tr>";
                            }
                            int sub_total = 0;

                            foreach (var det in detail)
                            {
                                content += "\n<tr><td style=\" text-align:center; border:solid 1px #e4e4e4; border-left:none; border-top:none;\">" + det.WORK_AREA_FROM_NAME + "</td><td style=\" text-align:center; border:solid 1px #e4e4e4; border-left:none; border-top:none;\">" + det.WORK_AREA_TO_NAME + "</td><td style=\" text-align:center; border:solid 1px #e4e4e4; border-left:none; border-top:none;\">" + det.TIME_FROM + "</td><td style=\" text-align:center; border:solid 1px #e4e4e4; border-left:none; border-top:none;\">" + det.TIME_TO + "</td><td style=\" text-align:center; border:solid 1px #e4e4e4; border-left:none; border-top:none;\">" + det.INSTITUTE_NAME + "</td><td style=\" text-align:center; border:solid 1px #e4e4e4; border-left:none; border-top:none;\">" + det.TEACHER_MOBILE + "</td><td style=\" text-align:center; border:solid 1px #e4e4e4; border-left:none; border-top:none;\">" + det.DCR_TYPE_CODE + "</td><td class=\"transtype\" style=\" text-align:center; border:solid 1px #e4e4e4; border-left:none; border-top:none;\"> " + det.TRANS_TYPE_CODE + "</td><td class=\"fareamt\" style=\" text-align:right; border:solid 1px #e4e4e4; border-left:none; border-top:none;\">" + det.APPROVE_FARE_AMT + "</td></tr>";

                                sub_total += (int)det.APPROVE_FARE_AMT;
                            }

                            if (detail.Count > 0)
                            {
                                content += " <tr> <td colspan=\"6\">&nbsp;</td><td colspan=\"2\" style=\" text-align:center;\"> <b>Sub Total : </b></td><td id=\"dcrSubTotal\" style=\" text-align:center;\" ><b>" + String.Format("{0:#,###0}", sub_total) + "</b></td></tr>";
                            }
                            content += "</tbody></table>";

                            content += " <table id=\"dcr_other\" style=\"font-size:13px; text-align:center; margin-top:20px\" width=\"50%\" border=\"1\" cellpadding=\"5\" cellspacing=\"0\">";
                            content += "<tr style=\"background:green; font-weight:bold;\"></tr>";
                            if (detailexpense.Count > 0)
                            {
                                content += "\n<tr><th>ExpType</th><th> Cost </th><th>  Vendor  </th></tr>";
                            }

                            foreach (var detexp in detailexpense)
                            {
                                content += "\n<tr><td>" + detexp.EXP_TYPE_CODE + "</td><td>" + detexp.APPROVE_EXP_AMT + "</td><td>" + detexp.VENDOR + "</td></tr>";
                            }

                            content += "</table>";
                        }
                    }


                    content += "\n</body></html>";

                    using (FileStream fs = System.IO.File.Open(path, FileMode.Create, FileAccess.Write, FileShare.None))
                    {
                        Byte[] info = new UTF8Encoding(true).GetBytes(content);
                        // Add some information to the file.
                        fs.Write(info, 0, info.Length);
                        fs.Close();
                    }
                }
            }

            //return PartialView("_DcrPublishPrint", dcrPublishModel);

            return(null);
        }
Exemplo n.º 2
0
        public ActionResult DcrPublish()
        {
            DcrPublishSearchModel searchModel     = new DcrPublishSearchModel();
            DcrPublishViewModel   dcrPublishModel = new DcrPublishViewModel();

            decimal?USER_NO = Session["sess_USER_NO"] as decimal?;

            ViewBag.Search_Division = new SelectList(db.SET_DIVISION, "DIVISION_NO", "DIVISION_NAME");
            ViewBag.Search_User     = new SelectList(db.SEC_USERS_GET_RPT_ZONAL(USER_NO,
                                                                                null, null, null).ToList(), "USER_NO", "USER_FULL_NAME");

            bool Is_ZonalOrAgent = (bool)Session["sess_Is_ZonalOrAgent"];

            ViewBag.Is_ZonalOrAgent = Is_ZonalOrAgent;

            string Search_User = Request.QueryString["Search_User"];

            if (string.IsNullOrEmpty(Search_User))
            {
                Search_User = Request.QueryString["USER_NO"];
            }

            if (Is_ZonalOrAgent)
            {
                Search_User = Session["sess_USER_NO"].ToString();
            }

            if (!string.IsNullOrEmpty(Request.QueryString["Search"]))
            {
                searchModel.Search_User = decimal.Parse(Search_User);
                ViewBag.Search_User     = new SelectList(db.SEC_USERS_GET_RPT_ZONAL(decimal.Parse(Session["sess_USER_NO"].ToString()),
                                                                                    null, null, null).ToList(), "USER_NO", "USER_FULL_NAME", searchModel.Search_User);

                SEC_USERS user = db.SEC_USERS.Single(u => u.USER_NO == searchModel.Search_User);

                if (!string.IsNullOrEmpty(Request.QueryString["Search_Date_From"]))
                {
                    searchModel.Search_Date_From = DateTime.Parse(Request.QueryString["Search_Date_From"]);
                }
                else
                {
                    DateTime now             = DateTime.Now;
                    DateTime FirstDayOfMonth = new DateTime(now.Year, now.Month, 1);
                    searchModel.Search_Date_From = FirstDayOfMonth;
                }
                if (!string.IsNullOrEmpty(Request.QueryString["Search_Date_To"]))
                {
                    searchModel.Search_Date_To = DateTime.Parse(Request.QueryString["Search_Date_To"]);
                }
                else
                {
                    searchModel.Search_Date_To = DateTime.Now;
                }

                List <DCR_PUB_EXP_GET_Result> expense =
                    db.DCR_PUB_EXP_GET(searchModel.Search_User, null,
                                       searchModel.Search_Date_From, searchModel.Search_Date_To, 0).ToList();

                List <DCR_PUB_SPECIMEN_GET_Result> specimen =
                    db.DCR_PUB_SPECIMEN_GET(searchModel.Search_User, null,
                                            searchModel.Search_Date_From, searchModel.Search_Date_To, 0).ToList();

                dcrPublishModel.expenses         = new DcrExpenseModel();
                dcrPublishModel.expenses.user    = user;
                dcrPublishModel.expenses.date    = DateTime.Now;
                dcrPublishModel.expenses.expense = expense;

                dcrPublishModel.specimens          = new DcrSpecimenModel();
                dcrPublishModel.specimens.user     = user;
                dcrPublishModel.specimens.date     = DateTime.Now;
                dcrPublishModel.specimens.specimen = specimen;

                if (!string.IsNullOrEmpty(Request.QueryString["Print"]))
                {
                    string print = Request.QueryString["Print"];
                    dcrPublishModel.details = new List <DcrDetailsModel>();

                    if (print.Length > 0 && print == "Y")
                    {
                        dcrPublishModel.expenses.date  = searchModel.Search_Date_From;
                        dcrPublishModel.specimens.date = searchModel.Search_Date_From;

                        for (DateTime?date = searchModel.Search_Date_From;
                             date <= searchModel.Search_Date_To; date = date.Value.AddDays(1))
                        {
                            DcrDetailsModel dcrDetails = new DcrDetailsModel();

                            List <DCR_PUB_DCR_DETAIL_GET_Result> detail =
                                db.DCR_PUB_DCR_DETAIL_GET(searchModel.Search_User, null, date, date, 0).ToList();

                            List <TRN_EXPENSE_APPROVAL_GET_Result> detailexpense =
                                db.TRN_EXPENSE_APPROVAL_GET(
                                    searchModel.Search_User, decimal.Parse(Session["sess_USER_NO"].ToString()),//parent
                                    null, null, null, date, date, 1, 1, null).ToList();

                            dcrDetails.date    = date;
                            dcrDetails.expense = detailexpense;
                            dcrDetails.detail  = detail;

                            dcrPublishModel.details.Add(dcrDetails);
                        }
                    }

                    ViewBag.Print = print;

                    return(PartialView("_DcrPublishPrint", dcrPublishModel));
                }

                ViewBag.Search_DcrPublish_Model = searchModel;

                Session["sess_Search_DcrPublish_Model"] = searchModel;

                return(View(dcrPublishModel));
            }

            return(View());
        }