private IEnumerable <fees_payment> GetFeesPaymentByReg(int reg_num)
        {
            List <fees_payment> payment = new List <fees_payment>();

            out_standingMain outstd = new out_standingMain();

            IEnumerable <out_standing> std = new List <out_standing>();

            std = outstd.AllOutStandingByReg(reg_num);

            foreach (out_standing val in std)
            {
                payment.Add(new fees_payment {
                    acc_id = val.acc_id, Fees_type = val.acc_name, amount_to_be_paid = val.outstd_amount, due_amount = val.outstd_amount, serial = val.serial, reg_num = val.reg_num, reg_date = val.dt_date, session = val.session
                });
            }


            return(payment);
        }
        private IEnumerable <fees_payment> GetFeesPayment(int sr_num, string session)
        {
            using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString()))
            {
                List <fees_payment> payment = new List <fees_payment>();



                out_standingMain outstd       = new out_standingMain();
                std_discount     discount     = new std_discount();
                std_discountMain discountMain = new std_discountMain();

                IEnumerable <out_standing> std = new List <out_standing>();

                std = outstd.AllOutStanding(sr_num, session);

                string query = @"SELECT 
                                    fine, start_date, upper_limit
                                FROM
                                    mst_fine_rule
                                WHERE
                                    session = @session AND acc_id = @acc_id and enable = 1";

                string start_yr = @"SELECT 
                                YEAR(session_start_date)
                            FROM
                                mst_session
                            WHERE
                                session = @session";

                string end_yr = @"SELECT 
                                YEAR(session_end_date)
                            FROM
                                mst_session
                            WHERE
                                session = @session";


                foreach (out_standing val in std)
                {
                    decimal       amt_fine = 0;
                    int           year     = 0;
                    mst_fine_rule result   = con.Query <mst_fine_rule>(query, new { acc_id = val.acc_id, session = val.session }).FirstOrDefault();

                    if (val.month_no >= 4 && val.month_no <= 12)
                    {
                        year = con.Query <int>(start_yr, new { session = val.session }).FirstOrDefault();
                    }
                    else
                    {
                        year = con.Query <int>(end_yr, new { session = val.session }).FirstOrDefault();
                    }

                    if (result != null)
                    {
                        DateTime dt = new DateTime(year, val.month_no, result.start_date);

                        if (dt < System.DateTime.Now.AddMinutes(dateTimeOffSet))
                        {
                            amt_fine = (decimal)((System.DateTime.Now.Date - dt).TotalDays) * result.fine;

                            if (amt_fine >= result.upper_limit)
                            {
                                amt_fine = result.upper_limit;
                            }
                        }
                    }
                    payment.Add(new fees_payment {
                        fine = amt_fine, acc_id = val.acc_id, Fees_type = val.acc_name, amount_to_be_paid = val.outstd_amount, due_amount = val.outstd_amount, serial = val.serial, sr_num = val.sr_number, session = val.session
                    });
                }



                return(payment);
            }
        }
        public ActionResult submit_fees(List <fees_payment> fees)
        {
            List <fees_receipt> rec  = new List <fees_receipt>();
            fees_receiptMain    main = new fees_receiptMain();

            foreach (fees_payment fee in fees)
            {
                if (fee.check)
                {
                    if (fee.serial == 0)
                    {
                        out_standing     out_std     = new out_standing();
                        out_standingMain out_stdMain = new out_standingMain();

                        out_std.outstd_amount = fee.due_amount;
                        out_std.rmt_amount    = fee.due_amount;
                        out_std.sr_number     = fee.sr_num;
                        out_std.acc_id        = fee.acc_id;
                        out_std.month_no      = fee.month_no;
                        out_std.month_name    = fee.month_name;
                        out_std.clear_flag    = fee.clear_flag;
                        out_std.session       = fee.session;
                        out_stdMain.AddOutStanding(out_std);


                        rec.Add(new fees_receipt
                        {
                            acc_id      = fee.acc_id,
                            amount      = fee.amount_to_be_paid,
                            fees_name   = fee.Fees_type,
                            sr_number   = fee.sr_num,
                            dc_fine     = fee.fine,
                            dc_discount = fee.discount,
                            narration   = fee.Narration,
                            serial      = out_std.serial,
                            clear_flag  = fee.clear_flag,
                            bnk_name    = fee.Bank_name,
                            chq_no      = fee.cheque_no,
                            chq_date    = fee.cheque_date,
                            mode_flag   = fee.mode_flag,
                            month_no    = fee.month_no,
                            session     = fee.session,
                            due_amount  = fee.due_amount,
                            user_id     = Int32.Parse(Request.Cookies["loginUserId"].Value.ToString())
                        });
                    }
                    else
                    {
                        rec.Add(new fees_receipt
                        {
                            acc_id      = fee.acc_id,
                            amount      = fee.amount_to_be_paid,
                            fees_name   = fee.Fees_type,
                            sr_number   = fee.sr_num,
                            dc_fine     = fee.fine,
                            dc_discount = fee.discount,
                            narration   = fee.Narration,
                            serial      = fee.serial,
                            dt_date     = fee.dt_date,
                            reg_no      = fee.reg_num,
                            reg_date    = fee.reg_date,
                            clear_flag  = fee.clear_flag,
                            bnk_name    = fee.Bank_name,
                            chq_no      = fee.cheque_no,
                            chq_date    = fee.cheque_date,
                            mode_flag   = fee.mode_flag,
                            session     = fee.session,
                            due_amount  = fee.due_amount,
                            user_id     = Int32.Parse(Request.Cookies["loginUserId"].Value.ToString())
                        });
                    }
                }
            }



            int rcpt_no = main.AddReceipt(rec);

            return(RedirectToAction("fees_collect", new { rcpt_no = rcpt_no }));
        }