public ActionResult GetPaidPaymentDetailMoeView(string model)
        {
            var filters = JsonConvert.DeserializeObject <List <FilterModel> >(model);
            List <SupplierPaymentRequestPaidDetail> lstPayment = new List <SupplierPaymentRequestPaidDetail>();

            using (var conn = new SqlConnection(_strConnection))
                using (var cmd = conn.CreateCommand())
                {
                    var filter = filters.FirstOrDefault();
                    conn.Open();

                    cmd.CommandText = $"EXEC GetSupplierPaymentMOEPaidDetail {filter?.Year},'{filter?.Month}',{false}";
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    DataTable      dt = new DataTable();
                    da.Fill(dt);

                    foreach (DataRow dr in dt.Rows)
                    {
                        SupplierPaymentRequestPaidDetail row = new SupplierPaymentRequestPaidDetail();
                        row.PaymentNo         = Convert.ToDecimal(dr["PaymentNo"]);
                        row.PaymentDateString = Convert.ToDateTime(dr["PaymentDate"]).ToShortDateString();
                        row.ChequeDateString  = Convert.ToDateTime(dr["ChequeDate"]).ToString("yyyy MMMM dd");
                        row.Amount            = Convert.ToDecimal(dr["Amount"]);
                        row.BankName          = Convert.ToString(dr["BankName"]);
                        row.ChequeNumber      = Convert.ToString(dr["ChequeNumber"]);
                        row.Month             = Convert.ToString(dr["Month"]);
                        row.Year = Convert.ToInt32(dr["Year"]);


                        lstPayment.Add(row);
                    }
                }
            if (lstPayment.Any())
            {
                return(PartialView("_SupplierPaymentPaidMOEView", lstPayment));
            }

            return(Json(new { status = false }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult SupplierPaymentMoeTextGenerate(string model)
        {
            var filters = JsonConvert.DeserializeObject <List <FilterModel> >(model);
            List <SupplierPaymentRequestPaidDetail> lstPayment = new List <SupplierPaymentRequestPaidDetail>();

            using (var conn = new SqlConnection(_strConnection))
                using (var cmd = conn.CreateCommand())
                {
                    var filter = filters.FirstOrDefault();
                    conn.Open();
                    cmd.CommandText = $"EXEC GetSupplierPaymentMOEPaidDetail {filter?.Year},'{filter?.Month}',{true}";
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    DataTable      dt = new DataTable();
                    da.Fill(dt);

                    foreach (DataRow dr in dt.Rows)
                    {
                        SupplierPaymentRequestPaidDetail row = new SupplierPaymentRequestPaidDetail();
                        row.PaymentNo    = Convert.ToDecimal(dr["PaymentNo"]);
                        row.PaymentDate  = Convert.ToDateTime(dr["PaymentDate"]);
                        row.ChequeDate   = Convert.ToDateTime(dr["ChequeDate"]);
                        row.Amount       = Convert.ToDecimal(dr["Amount"]);
                        row.BankName     = Convert.ToString(dr["BankName"]);
                        row.BankCode     = Convert.ToString(dr["BankCode"]);
                        row.BranchCode   = Convert.ToString(dr["BranchCode"]);
                        row.AccountNo    = Convert.ToString(dr["AccountNo"]);
                        row.SupplierName = Convert.ToString(dr["SupplierName"]);
                        row.ChequeNumber = Convert.ToString(dr["ChequeNumber"]);
                        row.Month        = Convert.ToString(dr["Month"]);
                        row.Year         = Convert.ToInt32(dr["Year"]);


                        lstPayment.Add(row);
                    }
                }
            if (lstPayment.Any())
            {
                var           year   = lstPayment.First().Year;
                var           month  = lstPayment.First().Month;
                StringBuilder record = new StringBuilder();
                foreach (var re in lstPayment)
                {
                    StringBuilder payment = new StringBuilder();
                    payment.Append("0000");
                    payment.Append(re.BankCode.PadLeft(4, '0'));
                    payment.Append(re.BranchCode.PadLeft(3, '0'));
                    payment.Append(re.AccountNo.PadLeft(12, '0'));
                    payment.Append(re.SupplierName.PadLeft(23, ' '));
                    payment.Append("23");     // txn code
                    payment.Append("00");     // return code
                    payment.Append("0");      // filler
                    payment.Append("000000"); // filler
                    var amount = re.Amount.ToString(CultureInfo.InvariantCulture).Split('.');

                    var amountString = string.Join("", amount);

                    payment.Append(amountString.PadLeft(12, '0')); // amount
                    payment.Append("SLR");                         // filler
                    var oBankNo = ConfigurationManager.AppSettings["OBankNo"];
                    payment.Append(oBankNo.PadLeft(4, '0'));       // originating Bank  no

                    var oBranchNo = ConfigurationManager.AppSettings["oBranchNo"];
                    payment.Append(oBranchNo.PadLeft(3, '0')); // originating Branch  no

                    var oAccNo = ConfigurationManager.AppSettings["oAccNo"];
                    payment.Append(oAccNo.PadLeft(12, '0')); // originating Acc  no

                    var oAccName = ConfigurationManager.AppSettings["oAccName"];
                    payment.Append(oAccName.PadLeft(12, ' ')); // originating Acc Name

                    var particulars = ConfigurationManager.AppSettings["particulars"];
                    payment.Append(particulars.PadLeft(15, ' ')); // particulars

                    var reference = ConfigurationManager.AppSettings["reference"];
                    payment.Append(reference.PadLeft(15, ' '));                       // reference

                    payment.Append(re.ChequeDate.ToString("yyMMdd").PadLeft(6, '0')); // Value Date
                    payment.Append("000000");                                         // filler

                    record.Append(payment);
                    record.Append(Environment.NewLine);
                }
                var byteArray = Encoding.ASCII.GetBytes(record.ToString());
                var stream    = new MemoryStream(byteArray);

                return(File(stream, "text/plain", $"Paid_{year}_{month}.txt"));
            }
            return(null);
        }