public ActionResult FamilyReport(int p_id=0)
        {
            int school_id = SessionHandler.GetSchoolID();

            var parents = new ParentDetails().GetAll(school_id);

            ViewBag.parents = parents;

            if (p_id > 0)
            {
                ViewBag.isSelected = true;

                var stds = new StudentDetails().GetAllChildren(school_id, p_id);
                var length = parents.Count();

                if(length > 0)
                {
                    string stds_ids = "(";
                    int i = 0;
                    foreach (var std in stds)
                    {
                        stds_ids += std.user_id;
                        if ((i + 1) != length)
                        {
                            stds_ids += ",";
                        }
                        i++;
                    }
                    stds_ids += ")";

                    ViewBag.children = stds;
                    var student_fees = new StudentFeeDetails().GetAll(school_id, stds_ids);
                    return View("FamilyReport", student_fees);
                }
            }
            return View("FamilyReport");
        }
        private bool insertStudentFeeDetail(string type , int student_id, int class_id,int session_id,string month="")
        {
            StudentFee stdFee = new StudentFee();

            stdFee.paid_fee = 0;
            stdFee.paid_status = FeePaidStatus.UNPAID;
            stdFee.school_id = SessionHandler.GetSchoolID();
            stdFee.class_id = class_id;
            stdFee.updated_by = stdFee.created_by = SessionHandler.GetUserID();
            stdFee.type = type;
            stdFee.student_id = student_id;
            stdFee.fee = 0;
            stdFee.session_id = session_id;
            stdFee.month = month;

            var fees = new StudentFeeDetails();

            fees.Insert(stdFee);

            return true;
        }
        public ActionResult StudentFee(int student_id=0, int class_id=0)
        {
            int school_id = SessionHandler.GetSchoolID();
            var session_id = SessionHandler.GetSchoolSessionID();

            var classes = Utils.GetClasses(school_id);
            var _sd = Utils.GetClassStudent(school_id, class_id);

            var sds = (from s in _sd
                       select new { fullname = s.first_name + " " + s.last_name, id = s.user_id,class_id= s.class_id }).ToList().ToJSON();

            ViewBag.classes = classes;
            ViewBag.student_id = student_id;
            ViewBag.class_id = class_id;
            ViewBag.students = sds;

            if(student_id != 0 && class_id != 0)
            {
                ViewBag.isSelected = true;

                var fees = new StudentFeeDetails().GetAll(school_id, student_id, class_id);
                var std_itself = new StudentDetails().FindSingle(student_id, school_id);
                var parent = new ParentDetails().FindSingle(std_itself.parent_id, school_id);
                var cls = new ClassDetails().FindSingle(std_itself.class_id, school_id);
                std_itself.parent_name = parent.full_name;
                std_itself.class_name = cls.name;

                ViewBag.student = std_itself;

                var add_fee = (from f in fees
                               where f.type == FeeType.EXAMINATION_FEE || f.type == FeeType.ADMISSION_FEE || f.type == FeeType.OTHER_CHARGES
                               select f).ToList();

                var monthly_fee = (from f in fees
                               where f.type == FeeType.MONTHLY_FEE
                               select f).ToList();

                foreach (var f in add_fee)
                {
                    if (f.type == FeeType.ADMISSION_FEE)
                        f.fee = std_itself.admission_fee;
                    if (f.type == FeeType.EXAMINATION_FEE)
                        f.fee = std_itself.examination_fee;
                    if (f.type == FeeType.OTHER_CHARGES)
                        f.fee = std_itself.other_charges;
                }

                var total = 0;
                foreach (var f in fees)
                {
                    f.fee = std_itself.monthly_fee;
                    if (f.paid_status == FeePaidStatus.PAID)
                    {
                        total += f.fee;
                    }
                }

                //to find the discount amount

                int discount = (int)(from std in _sd
                             where std.user_id == student_id
                               select std.discount).FirstOrDefault();

                ViewBag.total = total - discount;
                ViewBag.discount = discount;
                ViewBag.add_fee = add_fee;
                return View("StudentFee", monthly_fee);
            }
            return View("StudentFee");
        }
        public ActionResult MineFee()
        {
            int school_id = SessionHandler.GetSchoolID();
            int student_id = SessionHandler.GetUserID();
            ViewBag.isSelected = true;

            var std_itself = new StudentDetails().FindSingle(student_id, school_id);
            var fees = new StudentFeeDetails().GetAll(school_id, student_id, std_itself.class_id);

            var parent = new ParentDetails().FindSingle(std_itself.parent_id, school_id);
            var cls = new ClassDetails().FindSingle(std_itself.class_id, school_id);
            std_itself.parent_name = parent.full_name;
            std_itself.class_name = cls.name;
            ViewBag.student = std_itself;

            var add_fee = (from f in fees
                           where f.type == FeeType.EXAMINATION_FEE || f.type == FeeType.ADMISSION_FEE || f.type == FeeType.OTHER_CHARGES
                           select f).ToList();

            var total = 0;

            foreach (var f in add_fee)
            {
                if (f.type == FeeType.ADMISSION_FEE)
                    f.fee = std_itself.admission_fee;
                if (f.type == FeeType.EXAMINATION_FEE)
                    f.fee = std_itself.examination_fee;
                if (f.type == FeeType.OTHER_CHARGES)
                    f.fee = std_itself.other_charges;

                if (f.paid_status == FeePaidStatus.PAID)
                    total += f.fee;
            }

            var monthly_fee = (from f in fees
                               where f.type == FeeType.MONTHLY_FEE
                               select f).ToList();

            foreach (var f in monthly_fee)
            {
                f.fee = std_itself.monthly_fee;
                if (f.paid_status == FeePaidStatus.PAID)
                {
                    total += f.fee;
                }
            }

            //to find the discount amount

            int discount = std_itself.discount;

            ViewBag.total = total - discount;
            ViewBag.discount = discount;
            ViewBag.add_fee = add_fee;
            return View("MineFee", monthly_fee);
        }