Student Accounting

 avatar
shinta0x01
perl
21 days ago
19 kB
9
Indexable
Never
#JQuery

$().ready(function () {
    $('.display').hide()
    $(".btn").click(function () {

        if ($('#stud_id').val() == "" || $('#lname') == "" || $('#fname') == "") {
            alert("Some fields are empty")
        } else { 


        $('.ass').show()
        $('.display').show()
        $.post('../Home/postStudentAccounting', {
            stud_id: $('#stud_id').val(),
            lname: $('#lname').val(),
            fname: $('#fname').val(),
            gender: $('input[name="gender"]:checked').val(),
            course_code: $('#course_code').val(),
            year: $('#year').val(),
            subject: $('#subject').val()



        }, function (data) {
            $('#d_studid').text('Student ID: ' + data[0].stud_id)
            $('#d_name').text('Name: ' + data[0].lname + ", " + data[0].fname)
            $('#d_gender').text('Gender: ' + data[0].gender)
            $('#d_coursecode').text('Course Code: ' + data[0].course_code)
            $('#d_course').text('Course: ' + data[0].course)
            $('#d_year').text('Year: ' + data[0].year)
            $('#d_subject').text('Subjects: ' + data[0].subject)
            $('#d_totalunit').text('Total Unit: ' + data[0].total_unit)
            $('#d_tuitionperunit').text('Tuition Per Unit: ' + data[0].tuition_unit)
            $('#d_totaltuition').text('Total Tuition: ' + data[0].total_tuition)
            $('#d_reg').text('Registration: ' + data[0].reg)
            $('#d_misc').text('Miscellaneous: ' + data[0].misc)
            $('#d_labfee').text('Lab Fee: ' + data[0].lab_fee)
            $('#d_totalfee').text('Total Fee: ' + data[0].total_fee)
            $('#p').text(data[0].prelim_fee)
            $('#m').text(data[0].midterm_fee)
            $('#s').text(data[0].semi_fee)
            $('#f').text(data[0].final_fee)
            $('#d_mop').text('Mode of Payment: ' + data[0].mop)

        })
    }
    })

    $('.ass').hide()
    $('#btnfee').click(function () {
        $.post('../Home/postStudentFee', {
            radio_val:  $('input[name="fee"]:checked').val(),
            pre_val: $('#p').text(),
            mid_val: $('#m').text(),
            semi_val: $('#s').text(),
            final_val: $('#f').text(),
            tendered_amt: $('#tendered_amt').val(),
        }, function (data) {
            console.log(data[0].final_tendered)

            if (data[0].final_tendered < data[0].amount) {
                alert("Insufficient Balance")
            } else {
                $('#word').text(data[0].word + " and " + data[0].cents + " cents")
                $('#change').html("<b>" + "Change: " + data[0].change + "</b>")
            }

            

            
        })
    })

})



#HTML

<div class="container">
    <div class="row">
        <h2 class=" text-center">Student Accounting</h2>
        <div class="col-md-4">
            Student ID
            <input class="form-control" type="number" id="stud_id" placeholder="Student ID" /><br />
            Lastname
            <input class="form-control" type="text" id="lname" placeholder="Lastname" /><br />
            Firstname
            <input class="form-control" type="text" id="fname" placeholder="Firstname" /><br />
            Gender: <br /><input type="radio" name="gender" id="male" value="Male" /> Male<br />
            <input type="radio" name="gender" id="female" value="Female" /> Female<br />
            <input type="radio" name="gender" id="others" value="Prefer not to say" /> Prefer not to say<br /><br />
            <select class="form-control" id="course_code">
                <option value="" selected disabled hidden>Course Code</option>
                <option>0001</option>
                <option>0002</option>
                <option>0003</option>
                <option>0004</option>
                <option>0005</option>
                <option>0006</option>
                <option>0007</option>
                <option>0008</option>
            </select>
            <br />
            <select class="form-control" id="subject">
                <option value="" selected disabled hidden>Subjects</option>
                <option>1</option>
                <option>2</option>
                <option>3</option>
                <option>4</option>
                <option>5</option>
                <option>6</option>
                <option>7</option>
                <option>8</option>
                <option>9</option>
                <option>10</option>
            </select>
            <br />
            <select class="form-control" id="year">
                <option value="" selected disabled hidden>Year</option>
                <option>1</option>
                <option>2</option>
                <option>3</option>
                <option>4</option>
            </select><br />
            <br /><br />
            <button class="btn btn-primary">Submit</button>
        </div>
        <div class="display col-md-4">
            <p id="d_studid">Student ID: </p>
            <p id="d_name">Name: </p>
            <p id="d_gender">Gender: </p>
            <p id="d_coursecode">Course Code: </p>
            <p id="d_course">Course: </p>
            <p id="d_year">Year: </p>
            <p id="d_subject">Subjects: </p>
            <p id="d_totalunit">Total Unit: </p>
            <p id="d_tuitionperunit">Tuition Per Unit: </p>
            <p id="d_totaltuition"><b>Total Tuition: </b></p>
            <p id="d_reg">Registration: </p>
            <p id="d_misc">Miscellaneous: </p>
            <p id="d_labfee">Lab Fee: </p>
            <p id="d_totalfee">Total Fee: </p>
            <p id="d_mop"><b>Mode of Payment: </b></p>
        </div>
        <div class="ass col-md-4">  
            <input type="radio" id="pre" name="fee" value="1" /><span id="d_prelimfee"> Prelim Fee </span><span id="p"></span><br />
            <input type="radio" id="mid" name="fee" value="2" /><span id="d_midfee"> Midterm Fee </span><span id="m"></span><br />
            <input type="radio" id="semi" name="fee" value="3" /><span id="d_semifee"> Semi Final Fee </span><span id="s"></span><br />
            <input type="radio" id="final" name="fee" value="4" /><span id="d_finalfee"> Final Fee </span><span id="f"></span><br />
            <input type="number" id="tendered_amt" />
            <button class="btn btn-primary" id="btnfee">Save</button>
            <br />
            <p id="word"></p>
            <p id="change"></p>
        </div>
    </div>
</div>


<script src="~/Scripts/jQuery/jquery-3.7.1.min.js"></script>
<script src="~/Scripts/js/studentaccounting.js"></script>


# CSharp

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace WebApplication1.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }

        public ActionResult StudentAccouting()
        {
            return View();
        }

        public ActionResult postStudentAccounting()
        {
            var data = new List<object>();
            var stud_id = Request["stud_id"];
            var lname = Request["lname"];
            var fname = Request["fname"];
            var gender = Request["gender"];
            var course_code = Convert.ToInt32(Request["course_code"]);
            var course = "";
            var year = Request["year"];
            var subject = Convert.ToInt32(Request["subject"]);
            var total_unit = subject * 3.00;
            var tuition_unit = 0.0;
            var reg = 0.0;
            var misc = 0.0;
            var lab_fee = 0.0;
            var mop = "";


            if (course_code == 0001)
            {
                course = "C1";
                tuition_unit = 356.75;
                reg = 545.00;
                misc = 1000.45;
                lab_fee = 1900.75;

            }
            else if (course_code == 0002)
            {
                course = "C2";
                tuition_unit = 387.75;
                reg = 550.00;
                misc = 1050.35;
                lab_fee = 1920.20;

            }
            else if (course_code == 0003)
            {
                course = "C3";
                tuition_unit = 345.94;
                reg = 555.00;
                misc = 1100.25;
                lab_fee = 1939.65;

            }
            else if (course_code == 0004)
            {
                course = "C4";
                tuition_unit = 351.26;
                reg = 560.00;
                misc = 1150.15;
                lab_fee = 1959.10;

            }
            else if (course_code == 0005)
            {
                course = "C5";
                tuition_unit = 378.44;
                reg = 565.00;
                misc = 1200.05;
                lab_fee = 1978.55;

            }
            else if (course_code == 0006)
            {
                course = "C6";
                tuition_unit = 326.11;
                reg = 570.00;
                misc = 1249.05;
                lab_fee = 1998.00;

            }
            else if (course_code == 0007)
            {
                course = "C7";
                tuition_unit = 310.45;
                reg = 610.00;
                misc = 1299.85;
                lab_fee = 2017.45;

            }
            else if (course_code == 0008)
            {
                course = "C8";
                tuition_unit = 399.79;
                reg = 624.00;
                misc = 1349.75;
                lab_fee = 2036.90;

            }

            var total_tuition = Math.Round(total_unit * tuition_unit);
            var total_fee = Math.Round(total_tuition + reg + misc + lab_fee, 2);
            var prelim_fee = Math.Round(total_fee * .53, 2);
            var midterm_fee = Math.Round(total_fee * .64, 2);
            var semi_fee = Math.Round(total_fee * .75, 2);
            var final_fee = Math.Round(total_fee, 2);

            if (total_fee >= 8000)
            {
                mop = "CASH";
            }
            else if (total_fee >= 5000)
            {
                mop = "CHECK";
            }
            else
            {
                mop = "CREDIT";
            }

            data.Add(new
            {
                stud_id = stud_id,
                lname = lname,
                fname = fname,
                gender = gender,
                tuition_unit = tuition_unit,
                course_code = course_code,
                course = course,
                year = year,
                subject = subject,
                total_unit = total_unit,
                total_tuition = total_tuition,
                reg = reg,
                misc = misc,
                lab_fee = lab_fee,
                total_fee = total_fee,
                prelim_fee = prelim_fee,
                midterm_fee = midterm_fee,
                semi_fee = semi_fee,
                final_fee = final_fee,
                mop = mop


            });

            return Json(data, JsonRequestBehavior.AllowGet);
        }

        public ActionResult postStudentFee()
        {
            var data = new List<object>();
            var radio_val = Convert.ToInt32(Request["radio_val"]);
            var pre_val = Convert.ToDouble(Request["pre_val"]);
            var mid_val = Convert.ToDouble(Request["mid_val"]);
            var semi_val = Convert.ToDouble(Request["semi_val"]);
            var final_val = Convert.ToDouble(Request["final_val"]);
            double amount = 0.0;
            

            var tendered_amt = Convert.ToDouble(Request["tendered_amt"]);
            double final_tendered = tendered_amt / 100;



            if (radio_val == 1)
                amount = pre_val;
            else if(radio_val == 2)
                amount = mid_val;
            else if (radio_val == 3)
                amount = semi_val;
            else if(radio_val == 4)
                amount = final_val;

            var cents = Convert.ToInt32(amount * 100) % 100;

            var word_amount = (int)amount;

            int ones = word_amount % 10;
            word_amount /= 10;
            int tens = word_amount % 10;
            word_amount /= 10;
            int hundreds = word_amount % 10;
            word_amount /= 10;
            int thousands = word_amount % 10;
            word_amount /= 10;
            int tenThousands = word_amount % 10;

            string word = "";

            // Handling ten thousands place
            if (tenThousands == 1)
            {
                if (thousands == 0)
                    word = "Ten Thousand";
                else if (thousands == 1)
                    word = "Eleven Thousand";
                else if (thousands == 2)
                    word = "Twelve Thousand";
                else if (thousands == 3)
                    word = "Thirteen Thousand";
                else if (thousands == 4)
                    word = "Fourteen Thousand";
                else if (thousands == 5)
                    word = "Fifteen Thousand";
                else if (thousands == 6)
                    word = "Sixteen Thousand";
                else if (thousands == 7)
                    word = "Seventeen Thousand";
                else if (thousands == 8)
                    word = "Eighteen Thousand";
                else if (thousands == 9)
                    word = "Nineteen Thousand";
            }
            else if (tenThousands == 2)
                word = "Twenty Thousand";
            else if (tenThousands == 3)
                word = "Thirty Thousand";
            else if (tenThousands == 4)
                word = "Forty Thousand";
            else if (tenThousands == 5)
                word = "Fifty Thousand";
            else if (tenThousands == 6)
                word = "Sixty Thousand";
            else if (tenThousands == 7)
                word = "Seventy Thousand";
            else if (tenThousands == 8)
                word = "Eighty Thousand";
            else if (tenThousands == 9)
                word = "Ninety Thousand";

            // Handling thousands place
            if (thousands != 0 && tenThousands != 1)
            {
                word += " ";
                if (thousands == 1)
                    word += "One Thousand";
                else if (thousands == 2)
                    word += "Two Thousand";
                else if (thousands == 3)
                    word += "Three Thousand";
                else if (thousands == 4)
                    word += "Four Thousand";
                else if (thousands == 5)
                    word += "Five Thousand";
                else if (thousands == 6)
                    word += "Six Thousand";
                else if (thousands == 7)
                    word += "Seven Thousand";
                else if (thousands == 8)
                    word += "Eight Thousand";
                else if (thousands == 9)
                    word += "Nine Thousand";
            }

            // Handling hundreds place
            if (hundreds != 0)
            {
                word += " ";
                if (hundreds == 1)
                    word += "One Hundred";
                else if (hundreds == 2)
                    word += "Two Hundred";
                else if (hundreds == 3)
                    word += "Three Hundred";
                else if (hundreds == 4)
                    word += "Four Hundred";
                else if (hundreds == 5)
                    word += "Five Hundred";
                else if (hundreds == 6)
                    word += "Six Hundred";
                else if (hundreds == 7)
                    word += "Seven Hundred";
                else if (hundreds == 8)
                    word += "Eight Hundred";
                else if (hundreds == 9)
                    word += "Nine Hundred";
            }

            // Handling tens and ones place
            if (tens != 0)
            {
                word += " ";
                if (tens == 1)
                {
                    if (ones == 0)
                        word += "Ten";
                    else if (ones == 1)
                        word += "Eleven";
                    else if (ones == 2)
                        word += "Twelve";
                    else if (ones == 3)
                        word += "Thirteen";
                    else if (ones == 4)
                        word += "Fourteen";
                    else if (ones == 5)
                        word += "Fifteen";
                    else if (ones == 6)
                        word += "Sixteen";
                    else if (ones == 7)
                        word += "Seventeen";
                    else if (ones == 8)
                        word += "Eighteen";
                    else if (ones == 9)
                        word += "Nineteen";
                }
                else
                {
                    if (tens == 2)
                        word += "Twenty";
                    else if (tens == 3)
                        word += "Thirty";
                    else if (tens == 4)
                        word += "Forty";
                    else if (tens == 5)
                        word += "Fifty";
                    else if (tens == 6)
                        word += "Sixty";
                    else if (tens == 7)
                        word += "Seventy";
                    else if (tens == 8)
                        word += "Eighty";
                    else if (tens == 9)
                        word += "Ninety";
                }

                if (tens != 1 && ones != 0)
                    word += " ";
            }

            if (ones != 0 && tens != 1)
            {
                if (tens == 0)
                    word += " ";
                if (ones == 1)
                    word += "One";
                else if (ones == 2)
                    word += "Two";
                else if (ones == 3)
                    word += "Three";
                else if (ones == 4)
                    word += "Four";
                else if (ones == 5)
                    word += "Five";
                else if (ones == 6)
                    word += "Six";
                else if (ones == 7)
                    word += "Seven";
                else if (ones == 8)
                    word += "Eight";
                else if (ones == 9)
                    word += "Nine";
            }

            


            var change = Math.Round(final_tendered - amount, 2);

            data.Add(new
            {
                cents = cents,
                amount = amount,
                final_tendered = final_tendered,
                word = word,
                change = change,
            });

            return Json(data, JsonRequestBehavior.AllowGet);
        }

    }
}
Leave a Comment