<style>
    .avatar-upload {
        position: relative;
        max-width: 210px;
        margin-left: 10px;
        margin: -5px auto;
    }

    .avatar-upload .avatar-edit {
        position: absolute;
        right: 12px;
        z-index: 1;
        top: 10px;
    }

    .avatar-upload .avatar-edit input {
        display: none;
    }

    .avatar-upload .avatar-edit input+label {
        display: inline-block;
        width: 34px;
        height: 34px;
        margin-bottom: 0;

        background: #FFFFFF;
        border: 1px solid transparent;
        -webkit-box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.12);
        box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.12);
        cursor: pointer;
        font-weight: normal;
        -webkit-transition: all .2s ease-in-out;
        transition: all .2s ease-in-out;
    }

    .avatar-upload .avatar-edit input+label:hover {
        background: #f1f1f1;
        border-color: #d6d6d6;
    }

    .avatar-upload .avatar-edit input+label:after {
        color: #757575;
        position: absolute;
        top: 10px;
        left: 0;
        right: 0;
        text-align: center;
        margin: auto;
    }

    .avatar-upload .avatar-preview {
        width: 100px;
        height: 110px;
        position: relative;
        border: 6px solid #F8F8F8;
        -webkit-box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.1);
        box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.1);
    }

    .avatar-upload .avatar-preview>div {
        width: 100%;
        height: 100%;

        background-size: cover;
        background-repeat: no-repeat;
        background-position: center;
    }

    #time-table {
        width: max-content;
        border: 1px solid rgba(0, 0, 0, 0);
        width: 100%;
        /* border-bottom:1px solid rgba(0, 0, 0, 0); */

    }


    #time-table thead tr td {
        text-align: center;
        border: 1px solid rgba(0, 0, 0, 0);
        /* border: 1px solid black; */
        border-top: 1px solid #918c8c;
        border-right: 1px solid #918c8c;
        border-left: 1px solid #918c8c;
        border-bottom: 1px solid #918c8c;

    }

    #time-table tbody tr td {
        text-align: center;
        border: 1px solid rgba(0, 0, 0, 0);
        border-top: 1px solid #918c8c;
        border-left: 1px solid #918c8c;
        border-right: 1px solid #918c8c;
        border-bottom: 1px solid #918c8c;
        padding: 0px;
    }


    #seminar {
        font-weight: 800;
        font-family: sans-serif;
        background-color: #ffffff;
        text-transform: uppercase;
        width: 33.3%;
    }


    #sub {
        color: black;
        font-family: sans-serif;
        font-weight: 400;
        /* background-color: #ffffff; */
        text-transform: uppercase;
    }

    h1 {
        font-size: 18px !important;
    }
</style>

<?php
include($_SERVER['DOCUMENT_ROOT'] . "/COMPONENTS/root/path.php");
$idd = $_GET['idd'];
$year = $_GET['year'];
$month = $_GET['month'];
echo "<span class='searchParameters' data-year='$year' data-month='$month'>";

$query = mysqli_query($conn, "SELECT * FROM staff WHERE unique_user_id ='$idd'");
while ($spec = mysqli_fetch_assoc($query)) {
    $idd = $spec['unique_user_id'];
    $Image = $spec['profile_photo'];
    $Title = $spec['title'];
    $FirstName = $spec['first_name'];
    $LastName = $spec['last_name'];
    $Gender = $spec['gender'];
    $Department = $spec['department'];
    $Role = $spec['role'];
    $MobileNumber = $spec['phone'];
    $EmergencyContact = $spec['emergency_phone'];
    $SsnitNumber = $spec['ssnit_number'];
    $basicSalary = $spec['salary_wage_information'];
    echo "<span style='display:none;' class='basicSalary'>$basicSalary</span>";
}

$query = mysqli_query($conn, "SELECT * FROM payroll WHERE idd ='$idd' AND Year = '$year' AND Month = '$month'");
while ($spec = mysqli_fetch_assoc($query)) {
    $getAllowance = $spec['Allowances'];
    $getOtherDeductions = $spec['OtherDeductions'];
}
if (empty($getAllowance) && empty($getOtherDeductions)) {
    $getAllowance = 0.00;
    $getOtherDeductions = 0.00;
}

$query = mysqli_query($conn, "SELECT * FROM payroll_ssnit_deductions");
while ($spec = mysqli_fetch_assoc($query)) {
    if ($spec['Description'] == "TotalSSNITContribution") {
        $TotalSSNITContributionPercentage = $spec['DeductionPercentage'];
        echo "<span style='display:none;' class='TotalSSNITContributionPercentage'>$TotalSSNITContributionPercentage</span>";
    }

    if ($spec['Description'] == "EmployerSSNITContribution") {
        $EmployerSSNITContributionPercentage = $spec['DeductionPercentage'];
        echo "<span style='display:none;' class='EmployerSSNITContributionPercentage'>$EmployerSSNITContributionPercentage</span>";
    }

    if ($spec['Description'] == "EmployeeSSNITContribution") {
        $EmployeeSSNITContributionPercentage = $spec['DeductionPercentage'];
        echo "<span style='display:none;' class='EmployeeSSNITContributionPercentage'>$EmployeeSSNITContributionPercentage</span>";
    }

    if ($spec['Description'] == "Tier1EmployerSSNITContribution") {
        $Tier1EmployerSSNITContributionPercentage = $spec['DeductionPercentage'];
        echo "<span style='display:none;' class='Tier1EmployerSSNITContributionPercentage'>$Tier1EmployerSSNITContributionPercentage</span>";
    }

    if ($spec['Description'] == "Tier1EmployeeSSNITContribution") {
        $Tier1EmployeeSSNITContributionPercentage = $spec['DeductionPercentage'];
        echo "<span style='display:none;' class='Tier1EmployeeSSNITContributionPercentage'>$Tier1EmployeeSSNITContributionPercentage</span>";
    }

    if ($spec['Description'] == "Tier2EmployeeSSNITContribution") {
        $Tier2EmployeeSSNITContributionPercentage = $spec['DeductionPercentage'];
        echo "<span style='display:none;' class='Tier2EmployeeSSNITContributionPercentage'>$Tier2EmployeeSSNITContributionPercentage</span>";
    }
}

$query = mysqli_query($conn, "SELECT * FROM payroll_paye_rates");
while ($spec = mysqli_fetch_assoc($query)) {
    if ($spec['Description'] == "First") {
        $firstChargeableIncome = $spec['ChargeableIncome'];
        $firstChargeableIncomeMin = $spec['ChargeableIncomeMin'];
        $firstChargeableIncomeMax = $spec['ChargeableIncomeMax'];
        $firstRate = $spec['Rate'];
        echo "<span style='display:none;' class='firstChargeableIncome'>$firstChargeableIncome</span>";
        echo "<span style='display:none;' class='firstChargeableIncomeMin'>$firstChargeableIncomeMin</span>";
        echo "<span style='display:none;' class='firstChargeableIncomeMax'>$firstChargeableIncomeMax</span>";
        echo "<span style='display:none;' class='firstRate'>$firstRate</span>";
    } elseif ($spec['Description'] == "Next1") {
        $next1ChargeableIncome = $spec['ChargeableIncome'];
        $next1ChargeableIncomeMin = $spec['ChargeableIncomeMin'];
        $next1ChargeableIncomeMax = $spec['ChargeableIncomeMax'];
        $next1Rate = $spec['Rate'];
        echo "<span style='display:none;' class='next1ChargeableIncome'>$next1ChargeableIncome</span>";
        echo "<span style='display:none;' class='next1ChargeableIncomeMin'>$next1ChargeableIncomeMin</span>";
        echo "<span style='display:none;' class='next1ChargeableIncomeMax'>$next1ChargeableIncomeMax</span>";
        echo "<span style='display:none;' class='next1Rate'>$next1Rate</span>";
    } elseif ($spec['Description'] == "Next2") {
        $next2ChargeableIncome = $spec['ChargeableIncome'];
        $next2ChargeableIncomeMin = $spec['ChargeableIncomeMin'];
        $next2ChargeableIncomeMax = $spec['ChargeableIncomeMax'];
        $next2Rate = $spec['Rate'];
        echo "<span style='display:none;' class='next2ChargeableIncome'>$next2ChargeableIncome</span>";
        echo "<span style='display:none;' class='next2ChargeableIncomeMin'>$next2ChargeableIncomeMin</span>";
        echo "<span style='display:none;' class='next2ChargeableIncomeMax'>$next2ChargeableIncomeMax</span>";
        echo "<span style='display:none;' class='next2Rate'>$next2Rate</span>";
    } elseif ($spec['Description'] == "Next3") {
        $next3ChargeableIncome = $spec['ChargeableIncome'];
        $next3ChargeableIncomeMin = $spec['ChargeableIncomeMin'];
        $next3ChargeableIncomeMax = $spec['ChargeableIncomeMax'];
        $next3Rate = $spec['Rate'];
        echo "<span style='display:none;' class='next3ChargeableIncome'>$next3ChargeableIncome</span>";
        echo "<span style='display:none;' class='next3ChargeableIncomeMin'>$next3ChargeableIncomeMin</span>";
        echo "<span style='display:none;' class='next3ChargeableIncomeMax'>$next3ChargeableIncomeMax</span>";
        echo "<span style='display:none;' class='next3Rate'>$next3Rate</span>";
    } elseif ($spec['Description'] == "Next4") {
        $next4ChargeableIncome = $spec['ChargeableIncome'];
        $next4ChargeableIncomeMin = $spec['ChargeableIncomeMin'];
        $next4ChargeableIncomeMax = $spec['ChargeableIncomeMax'];
        $next4Rate = $spec['Rate'];
        echo "<span style='display:none;' class='next4ChargeableIncome'>$next4ChargeableIncome</span>";
        echo "<span style='display:none;' class='next4ChargeableIncomeMin'>$next4ChargeableIncomeMin</span>";
        echo "<span style='display:none;' class='next4ChargeableIncomeMax'>$next4ChargeableIncomeMax</span>";
        echo "<span style='display:none;' class='next4Rate'>$next4Rate</span>";
    } elseif ($spec['Description'] == "Exceeding") {
        $exceedingChargeableIncome = $spec['ChargeableIncome'];
        $exceedingChargeableIncomeMin = $spec['ChargeableIncomeMin'];
        $exceedingChargeableIncomeMax = $spec['ChargeableIncomeMax'];
        $exceedingRate = $spec['Rate'];
        echo "<span style='display:none;' class='exceedingChargeableIncome'>$exceedingChargeableIncome</span>";
        echo "<span style='display:none;' class='exceedingChargeableIncomeMin'>$exceedingChargeableIncomeMin</span>";
        echo "<span style='display:none;' class='exceedingChargeableIncomeMax'>$exceedingChargeableIncomeMax</span>";
        echo "<span style='display:none;' class='exceedingRate'>$exceedingRate</span>";
    }
}

$EmployerSSNITContribution = $basicSalary * $EmployerSSNITContributionPercentage / 100;
$EmployeeSSNITContribution = $basicSalary * $EmployeeSSNITContributionPercentage / 100;
$Tier1EmployeeSSNITContribution = $basicSalary * $Tier1EmployeeSSNITContributionPercentage / 100;
$Tier2EmployeeSSNITContribution = $basicSalary * $Tier2EmployeeSSNITContributionPercentage / 100;
$TotalSSNITContribution = $basicSalary * $TotalSSNITContributionPercentage / 100;
$Allowances = 0.00;
$GrossSalary = $basicSalary + $Allowances;
$TaxablePay = $GrossSalary - $EmployeeSSNITContribution;
$OtherDeductions = 0.00;


if ($TaxablePay <= $firstChargeableIncome) {
    $TotalTax = 0.0;
    $description = "first";
} else {
    $PayToBeTaxed = $TaxablePay - $firstChargeableIncome;
    if ($PayToBeTaxed >= $next1ChargeableIncome) {

        $PayToBeTaxed = $PayToBeTaxed - $next1ChargeableIncome;
        if ($PayToBeTaxed >= $next2ChargeableIncome) {

            $PayToBeTaxed = $PayToBeTaxed - $next2ChargeableIncome;
            if ($PayToBeTaxed >= $next3ChargeableIncome) {

                $PayToBeTaxed = $PayToBeTaxed - $next3ChargeableIncome;
                if ($PayToBeTaxed >= $next4ChargeableIncome) {

                    $PayToBeTaxed = $PayToBeTaxed - $next4ChargeableIncome;
                    if ($PayToBeTaxed >= $exceedingChargeableIncome) {

                        $PayToBeTaxed = $PayToBeTaxed * $exceedingRate / 100;
                        $TotalTax1 = $next1ChargeableIncome * $next1Rate / 100;
                        $TotalTax2 = $next2ChargeableIncome * $next2Rate / 100;
                        $TotalTax3 = $next3ChargeableIncome * $next3Rate / 100;
                        $TotalTax4 = $next4ChargeableIncome * $next4Rate / 100;
                        $TotalTax = $PayToBeTaxed + $TotalTax1 + $TotalTax2 + $TotalTax3 + $TotalTax4;
                        $description = "exceeding1";
                    } else {
                        $PayToBeTaxed = $PayToBeTaxed * $exceedingRate / 100;
                        $TotalTax1 = $next1ChargeableIncome * $next1Rate / 100;
                        $TotalTax2 = $next2ChargeableIncome * $next2Rate / 100;
                        $TotalTax3 = $next3ChargeableIncome * $next3Rate / 100;
                        $TotalTax4 = $next4ChargeableIncome * $next4Rate / 100;
                        $TotalTax = $PayToBeTaxed + $TotalTax1 + $TotalTax2 + $TotalTax3 + $TotalTax4;
                        $description = "exceeding";
                    }
                } else {
                    $PayToBeTaxed = $PayToBeTaxed * $next4Rate / 100;
                    $TotalTax1 = $next1ChargeableIncome * $next1Rate / 100;
                    $TotalTax2 = $next2ChargeableIncome * $next2Rate / 100;
                    $TotalTax3 = $next3ChargeableIncome * $next3Rate / 100;
                    $TotalTax = $PayToBeTaxed + $TotalTax1 + $TotalTax2 + $TotalTax3;
                    $description = "next4";
                }
            } else {
                $PayToBeTaxed = $PayToBeTaxed * $next3Rate / 100;
                $TotalTax1 = $next1ChargeableIncome * $next1Rate / 100;
                $TotalTax2 = $next2ChargeableIncome * $next2Rate / 100;
                $TotalTax = $PayToBeTaxed + $TotalTax1 + $TotalTax2;
                $description = "next3";
            }
        } else {
            $PayToBeTaxed = $PayToBeTaxed * $next2Rate / 100;
            $TotalTax1 = $next1ChargeableIncome * $next1Rate / 100;
            $TotalTax = $PayToBeTaxed + $TotalTax1;
            $description = "next2";
        }
    } else {
        $PayToBeTaxed = $PayToBeTaxed * $next1Rate / 100;
        $TotalTax = $PayToBeTaxed;
        $description = "next1";
    }
}
$TotalEmployeeDeductions = $TotalTax + $EmployeeSSNITContribution + $OtherDeductions;
$NetSalary = $GrossSalary - $TotalEmployeeDeductions;
?>

<input type='text' value='<?php echo $id1; ?>' id='id' hidden>
<input type='text' value='<?php echo $description; ?>' id='description' hidden>

<!-- <?php echo $image; ?><br><br><?php echo $newstudent; ?> -->
<div class="avatar-upload">
    <div class="avatar-preview ">
        <div class="imagePreview"></div>
    </div>
</div>

<div class='row'>
    <div class='col-md-6' style="text-align:left;">
        <h1><strong>STAFF: </strong> <?php echo $FirstName; ?> <?php echo $LastName; ?></h1>
        <h1><strong>DEPARTMENT: </strong> <?php echo $Department; ?> </h1>
        <h1><strong>SSNIT NUMBER: </strong> <?php echo $SsnitNumber; ?> </h1>
        <h1 style="margin-left:20px;"><i><u><?php echo $Gender; ?></u></i></h1>
    </div>

    <div class='col-md-6' style="text-align:right;">
        <h1><strong>ROLE: </strong> <?php echo $Role; ?></h1>
        <h1><strong>CURRENT TERM: </strong> <?php echo $term ?></h1>
        <h1><strong>BANK: </strong> <?php echo $Bank; ?> </h1>
        <h1><i><u><?php echo Date('l, d  F Y', strtotime('today')); ?></u></i></h1>
    </div>

    <div class='col-md-12' style="margin:0% auto; text-align:center;">
        <h1 style="margin-top:10px; font-size:14px;"><u>PAYROLL PREPARATION FOR <?php echo "<span style='text-transform:uppercase;'>" . Date('F', strtotime(DATE("Y-" . $month . ""))) . "</span> " . $year . ""; ?> </u></h1>
    </div>
</div>


<form method='POST' action='' id='formPayroll'>

    <div <?php echo "style=display:none;" ?>>
        <input type='text' name="idd" value="<?php echo $idd; ?>">
        <input type='text' name="Image" value="<?php echo $Image; ?>">
        <input type='text' name="Title" value="<?php echo $Title; ?>">
        <input type='text' name="FirstName" value="<?php echo $FirstName; ?>">
        <input type='text' name="LastName" value="<?php echo $LastName; ?>">
        <input type='text' name="Gender" value="<?php echo $Gender; ?>">
        <input type='text' name="StaffType" value="<?php echo $StaffType; ?>">
        <input type='text' name="Role" value="<?php echo $Role; ?>">
        <input type='text' name="MobileNumber" value="<?php echo $MobileNumber; ?>">
        <input type='text' name="EmergencyContact" value="<?php echo $EmergencyContact; ?>">
        <input type='text' name="SsnitNumber" value="<?php echo $SsnitNumber; ?>">
        <input type='text' name="Year" value="<?php echo $year; ?>">
        <input type='text' name="Month" value="<?php echo $month; ?>">

    </div>
    <div class='row'>
        <div class='col-md-12'>
            <table id='time-table'>
                <thead>
                    <tr>
                        <td scope="col" id="seminar">EARNINGS</td>
                        <td scope="col" id="seminar">TAXATION</td>
                        <td scope="col" id="seminar">DEDUCTIONS</td>
                    </tr>
                </thead>

                <tbody>
                    <tr>
                        <td id="sub">
                            <table>
                                <tr>
                                    <td style="padding-top:12px; padding-bottom:12px; border-left:1px solid rgba(0, 0, 0, 0); border-top:1px solid rgba(0, 0, 0, 0); border-bottom:1px solid rgba(0, 0, 0, 0);">

                                    </td>

                                    <td style='border-top:1px solid rgba(0, 0, 0, 0);'>
                                        GH&#8373;
                                    </td>

                                    <td style='border-top:1px solid rgba(0, 0, 0, 0); border-right:1px solid rgba(0, 0, 0, 0);'>
                                        GH&#8373;
                                    </td>
                                </tr>

                                <tr>
                                    <td style="padding-top:12px; padding-bottom:12px; border-left:1px solid rgba(0, 0, 0, 0); border-top:1px solid rgba(0, 0, 0, 0); border-bottom:1px solid rgba(0, 0, 0, 0);">
                                        Basic Salary:
                                    </td>

                                    <td style='border-bottom:1px solid rgba(0, 0, 0, 0);'>

                                    </td>

                                    <td style='border-right:1px solid rgba(0, 0, 0, 0); border-bottom:1px solid rgba(0, 0, 0, 0);'>
                                        <!-- <span ><?php echo number_format($basicSalary, 1, '.', ',') ?></span> -->
                                        <input id='basicSalary' name="BasicSalary" type='text' value='<?php echo $basicSalary; ?>' style='border:none; font-size:10px; text-align:center; color:rgb(80, 80, 80); width:80%;' readonly>
                                    </td>
                                </tr>

                                <tr>
                                    <td style="padding-top:12px; padding-bottom:12px; border-left:1px solid rgba(0, 0, 0, 0); border-bottom:1px solid rgba(0, 0, 0, 0);">
                                        Allowances / Incentives:
                                    </td>

                                    <td style='border-bottom:1px solid rgba(0, 0, 0, 0);'>
                                        <input type="text" class='allowance' value="<?php echo $getAllowance; ?>" placeholder="0.00" style='width:80%; text-align: center;'>
                                    </td>

                                    <td style='border-right:1px solid rgba(0, 0, 0, 0); border-bottom:1px solid rgba(0, 0, 0, 0); border-top:1px solid rgba(0, 0, 0, 0);'>
                                        <input class='allowanceTotal' name="Allowances" type='text' value='<?php echo number_format($Allowances, 2, '.', ',') ?>' style='border:none; font-size:10px; text-align:center; color:rgb(80, 80, 80); width:80%;' readonly>
                                    </td>
                                </tr>

                                <tr>
                                    <td style="padding-top:12px; padding-bottom:12px; border-left:1px solid rgba(0, 0, 0, 0); border-bottom:1px solid rgba(0, 0, 0, 0);">
                                        Gross Salary:
                                    </td>

                                    <td style='border-bottom:1px solid rgba(0, 0, 0, 0);'>

                                    </td>

                                    <td style='border-right:1px solid rgba(0, 0, 0, 0); border-bottom:1px solid rgba(0, 0, 0, 0);'>
                                        <input class='grossSalary' value="<?php echo number_format($GrossSalary, 2, '.', ',') ?>" style='border:none; font-size:10px; text-align:center; color:rgb(80, 80, 80); width:80%;'> <input class='grossSalary' name='GrossSalary' type='text' value='<?php echo $GrossSalary; ?>' style='border:none; font-size:10px; text-align:center; color:rgb(80, 80, 80); width:80%; <?php echo "display:none;" ?>' readonly>

                                    </td>
                                </tr>
                            </table>
                        </td>
                        <td id="sub">
                            <table style='width:100%;'>
                                <tr>
                                    <td style="padding-top:12px; padding-bottom:12px; border-left:1px solid rgba(0, 0, 0, 0); border-top:1px solid rgba(0, 0, 0, 0); border-bottom:1px solid rgba(0, 0, 0, 0);">

                                    </td>

                                    <td style='border-top:1px solid rgba(0, 0, 0, 0); border-right:1px solid rgba(0, 0, 0, 0);'>
                                        GH&#8373;
                                    </td>
                                </tr>

                                <tr>
                                    <td style="padding-top:12px; padding-bottom:12px; border-left:1px solid rgba(0, 0, 0, 0); border-top:1px solid rgba(0, 0, 0, 0); border-bottom:1px solid rgba(0, 0, 0, 0);">
                                        SSNIT Relief:
                                    </td>

                                    <td style='border-right:1px solid rgba(0, 0, 0, 0); border-bottom:1px solid rgba(0, 0, 0, 0);'>
                                        <input name="ssnitRelief1" type='text' value='<?php echo number_format($EmployeeSSNITContribution, 2, '.', ',') ?>' style='border:none; font-size:10px; text-align:center; color:rgb(80, 80, 80); width:80%;' readonly>
                                        <input class='ssnitRelief' name="SsnitRelief" type='text' value='<?php echo $EmployeeSSNITContribution ?>' style='border:none; font-size:10px; text-align:center; color:rgb(80, 80, 80); width:80%; <?php echo "display:none"; ?>' readonly>

                                    </td>
                                </tr>

                                <tr>
                                    <td style="padding-top:12px; padding-bottom:12px; border-left:1px solid rgba(0, 0, 0, 0); border-bottom:1px solid rgba(0, 0, 0, 0);">
                                        Taxable Pay:
                                    </td>

                                    <td style='border-right:1px solid rgba(0, 0, 0, 0); border-bottom:1px solid rgba(0, 0, 0, 0);'>
                                        <input class='taxablePay' type='text' value='<?php echo number_format($TaxablePay, 2, '.', ',') ?>' style='border:none; font-size:10px; text-align:center; color:rgb(80, 80, 80); width:80%;' readonly>
                                        <input class='taxablePay taxablePayForCalculationsPurposes' name="TaxablePay" type='text' value='<?php echo $TaxablePay ?>' style='border:none; font-size:10px; text-align:center; color:rgb(80, 80, 80); width:80%; <?php echo "display:none"; ?>' readonly>

                                    </td>
                                </tr>

                                <tr>
                                    <td style="padding-top:12px; padding-bottom:12px; border-left:1px solid rgba(0, 0, 0, 0); border-bottom:1px solid rgba(0, 0, 0, 0);">
                                        Total Tax:
                                    </td>

                                    <td style='border-right:1px solid rgba(0, 0, 0, 0); border-bottom:1px solid rgba(0, 0, 0, 0);'>
                                        <input class='totalTax' type='text' value='<?php echo number_format($TotalTax, 2, '.', ',') ?>' style='border:none; font-size:10px; text-align:center; color:rgb(80, 80, 80); width:80%;' readonly>
                                        <input class='totalTax1' name="TotalTax" type='text' value='<?php echo $TotalTax; ?>' style='<?php echo "display:none"; ?>'>

                                    </td>
                                </tr>
                            </table>
                        </td>
                        <td id="sub">
                            <table>
                                <tr>
                                    <td style="padding-top:12px; padding-bottom:12px; border-left:1px solid rgba(0, 0, 0, 0); border-top:1px solid rgba(0, 0, 0, 0); border-bottom:1px solid rgba(0, 0, 0, 0);">

                                    </td>

                                    <td style='border-top:1px solid rgba(0, 0, 0, 0);'>
                                        GH&#8373;
                                    </td>

                                    <td style='border-top:1px solid rgba(0, 0, 0, 0); border-right:1px solid rgba(0, 0, 0, 0);'>
                                        GH&#8373;
                                    </td>
                                </tr>

                                <tr>
                                    <td style="padding-top:12px; padding-bottom:12px; border-left:1px solid rgba(0, 0, 0, 0); border-top:1px solid rgba(0, 0, 0, 0); border-bottom:1px solid rgba(0, 0, 0, 0);">
                                        PAYE:
                                    </td>

                                    <td style='border-bottom:1px solid rgba(0, 0, 0, 0);'>

                                    </td>

                                    <td style='border-right:1px solid rgba(0, 0, 0, 0); border-bottom:1px solid rgba(0, 0, 0, 0);'>
                                        <input type='text' class='totalTax1' value='<?php echo number_format($TotalTax, 2, '.', ',') ?>' style='border:none; font-size:10px; text-align:center; color:rgb(80, 80, 80); width:80%;' readonly>
                                        <input name="PAYE" class='totalTax1' type='text' value='<?php echo $TotalTax; ?>' style='<?php echo "display:none;"; ?>'>
                                    </td>
                                </tr>


                                <tr>
                                    <td style="padding-top:12px; padding-bottom:12px; border-left:1px solid rgba(0, 0, 0, 0); border-bottom:1px solid rgba(0, 0, 0, 0);">
                                        SSNIT Contribution (<?php echo $EmployeeSSNITContributionPercentage; ?>%):
                                    </td>

                                    <td style='border-bottom:1px solid rgba(0, 0, 0, 0);'>

                                    </td>

                                    <td style='border-right:1px solid rgba(0, 0, 0, 0); border-bottom:1px solid rgba(0, 0, 0, 0);'>
                                        <input name="SsnitContribution" type='text' value='<?php echo number_format($EmployeeSSNITContribution, 2, '.', ',') ?>' style='border:none; font-size:10px; text-align:center; color:rgb(80, 80, 80); width:80%;' readonly>

                                    </td>
                                </tr>


                                <tr>
                                    <td style="padding-top:12px; padding-bottom:12px; border-left:1px solid rgba(0, 0, 0, 0); border-bottom:1px solid rgba(0, 0, 0, 0);">
                                        Other Deductions:
                                    </td>

                                    <td style='border-bottom:1px solid rgba(0, 0, 0, 0);'>
                                        <input type="text" class="otherDeductions" value="<?php echo $getOtherDeductions; ?>" placeholder="0.0" style='font-size:10px; text-align:center; color:rgb(80, 80, 80); width:80%;'>
                                    </td>

                                    <td style='border-right:1px solid rgba(0, 0, 0, 0); border-bottom:1px solid rgba(0, 0, 0, 0);'>
                                        <input name="OtherDeductions" type="text" class='otherDeductionsTotal' value="<?php echo number_format($OtherDeductions, 2, '.', ',') ?>" style='border:none; font-size:10px; text-align:center; color:rgb(80, 80, 80); width:80%;'>
                                    </td>
                                </tr>
                            </table>

                        </td>
                    </tr>
                </tbody>
            </table>

            <table id='time-table'>

                <tr>
                    <td style="padding-top:12px; padding-bottom:12px; border-right:1px solid #918c8c; border-bottom:1px solid #918c8c; border-left:1px solid #918c8c; border-top:1px solid rgba(0, 0, 0, 0);">
                        EMPLOYEE SSNIT DEDUCTIONS:
                    </td>

                    <td style="padding-top:12px; padding-bottom:12px; border-right:1px solid #918c8c; border-bottom:1px solid #918c8c; border-left:1px solid #918c8c; border-top:1px solid rgba(0, 0, 0, 0); ">
                        Staff SSNIT Contribution - Tier 1 (<?php echo $Tier1EmployeeSSNITContributionPercentage; ?>%): GH&#8373; <input name="StaffSsnitContributionTier1" type="text" value="<?php echo number_format($Tier1EmployeeSSNITContribution, 2, '.', ','); ?>" style='border:none; font-size:10px; color:rgb(80, 80, 80); width:105px;' readonly>
                    </td>

                    <td style="padding-top:12px; padding-bottom:12px; border-right:1px solid #918c8c; border-bottom:1px solid #918c8c; border-left:1px solid #918c8c; border-top:1px solid rgba(0, 0, 0, 0); ">

                        Staff SSNIT Contribution - Tier 2 (<?php echo $Tier2EmployeeSSNITContributionPercentage; ?>%): GH&#8373; <input name="StaffSsnitContributionTier2" type="text" value="<?php echo number_format($Tier2EmployeeSSNITContribution, 2, '.', ',') ?>" style='border:none; font-size:10px; color:rgb(80, 80, 80);width:105px;' readonly>
                    </td>
                </tr>


                <tr>
                    <td style="padding-top:12px; padding-bottom:12px; border-right:1px solid #918c8c; border-bottom:1px solid #918c8c; border-left:1px solid #918c8c; border-top:1px solid rgba(0, 0, 0, 0);">
                        EMPLOYER SSNIT DEDUCTIONS:
                    </td>

                    <td style="padding-top:12px; padding-bottom:12px; border-right:1px solid #918c8c; border-bottom:1px solid #918c8c; border-left:1px solid #918c8c; border-top:1px solid rgba(0, 0, 0, 0); ">
                        School SSNIT Contribution - Tier 1 (<?php echo $Tier1EmployerSSNITContributionPercentage; ?>%): GH&#8373; <input name="EmployerSsnitContributionTier1" type="text" value="<?php echo number_format($EmployerSSNITContribution, 2, '.', ',') ?>" style='border:none; font-size:10px; color:rgb(80, 80, 80); width:105px;' readonly>
                    </td>
                    <td style="padding-top:12px; padding-bottom:12px; border-right:1px solid #918c8c; border-bottom:1px solid #918c8c; border-left:1px solid #918c8c; border-top:1px solid rgba(0, 0, 0, 0); ">

                    </td>
                </tr>


                <tr>
                    <td style="padding-top:12px; padding-bottom:12px; border-right:1px solid #918c8c; border-bottom:1px solid #918c8c; border-left:1px solid #918c8c; border-top:1px solid rgba(0, 0, 0, 0);">
                        TOTAL SSNIT CONTRIBUTION:
                    </td>

                    <td style="padding-top:12px; padding-bottom:12px; border-right:1px solid #918c8c; border-bottom:1px solid #918c8c; border-left:1px solid #918c8c; border-top:1px solid rgba(0, 0, 0, 0); ">
                        GH&#8373; <input name="TotalContribution" type="text" value="<?php echo number_format($TotalSSNITContribution, 2, '.', ',') ?>" style='border:none; font-size:10px; color:rgb(80, 80, 80); width:105px;' readonly>
                    </td>
                    <td style="padding-top:12px; padding-bottom:12px; border-right:1px solid #918c8c; border-bottom:1px solid #918c8c; border-left:1px solid #918c8c; border-top:1px solid rgba(0, 0, 0, 0); ">

                    </td>
                </tr>


            </table>
        </div>

        <div class='col-md-12' style='text-align:center; margin-top:20px;'>
            <span id="seminar" style='font-size:15px;'>NET / TAKE HOME SALARY <br> <span>GH&#8373; <input class='NetSalary' type="text" value="<?php echo number_format($NetSalary, 2, '.', ','); ?>" style='border:none; font-size:10px;  color:rgb(80, 80, 80); width:105px;'></span> <input name="NetSalary" class='netSalary1' type="text" value="<?php echo $NetSalary; ?>" style='border:none; font-size:10px;  color:rgb(80, 80, 80); width:105px; <?php echo "display:none;"; ?>'></span>
        </div>

        <div class='col-md-11' style='padding:0px; margin:0% auto; margin-bottom:10px;'>
            <button type='submit' class='print-link raise' id='submitPayroll' style='background:#af4c4c; width:100%; height:50px; color:white; border:2px solid white; margin-top:17px;'><span id="button_textttt"><i class='fa fa-save' style='font-size:28px; color:white;'></i> Save Payroll</span></button>

        </div>
    </div>
</form>


<script>
    $('#goBack').on('click', function(e) {
        var id = $('#id').val();
        $('#myModal_loader').modal('show');
        $("#fees").load(WebsiteName + "/COMPONENTS/SYSTEMS-ADMINISTRATOR/school-fees/sub.payfees.php?id=" + id + "", function() {
            $('#myModal_payments').modal('hide');
            $("#myModal_payfees").modal('show');
            $("#fees").fadeIn('slow')
            setTimeout(function() {
                $('#myModal_loader').modal('hide');
            }, 500);
        });
        e.preventDefault();
        $(this).off("click");
    });

    $('.clickme_delete_fees').on('click', function(e) {

        var tr = $(this).closest('tr'),
            id = $(this).attr('id'),
            form = $(this).attr('data-class');
        var idd = $("#id").val();
        $("#body").hide();
        $.ajax({
            url: WebsiteName + "/COMPONENTS/SYSTEMS-ADMINISTRATOR/school-fees/database.delete.php?id=" + id + "&idd=" + idd + "",
            cache: false,
            beforeSend: function() {
                tr.fadeOut(500, function() {});
            },
            success: function(result) {
                tr.fadeOut(500, function() {
                    $("#body").load(WebsiteName + "/COMPONENTS/SYSTEMS-ADMINISTRATOR/school-fees/component.school-fees.php", function() {
                        $('#payfees_select_class').hide();
                        $("#payfees_select_student").load(WebsiteName + "/COMPONENTS/SYSTEMS-ADMINISTRATOR/school-fees/sub.payfees_select_student.php?id=" + encodeURIComponent(form) + "", function() {
                            $('#payfees_select_student').fadeIn('slow');

                            $("#body").fadeIn();

                        });

                    });
                });
            }
        });

        e.preventDefault();
        $(this).off("click");
    });

    // $(document).on('click', '.clickme_print', function(e) {
    //     var tr = $(this).closest('tr'),
    //         id = $(this).attr('id');
    //     window.open(WebsiteName + "/COMPONENTS/SYSTEMS-ADMINISTRATOR/school-fees/sub.paymentDoneReciept.php?idd=" + id + "", '_blank');
    //     //$("#paymentDoneReciept").load("../page_blocks/paymentDoneReciept.php?idd="+ id +"",function(){}).show('fast');
    //     e.preventDefault();
    //     $(this).off("click");
    // });


    $(document).on('click', '.clickme_print', function(e) {
        var tr = $(this).closest('tr'),
            id = $(this).attr('id');
        var url = WebsiteName + "/COMPONENTS/SYSTEMS-ADMINISTRATOR/school-fees/sub.paymentDoneReciept.php?idd=" + id + "";
        sessionStorage.setItem('url', url);
        $("#bill").load(WebsiteName + "/COMPONENTS/SYSTEMS-ADMINISTRATOR/school-fees/sub.view-school-fees-item-in-iframe.php", function() {
            $("#myModal_printIndividualStudentBill").modal('show');
        });

        e.preventDefault();
        $(this).off("click");
    });

    $('.allowance').on("blur", function() {
        var Allowance = $('.allowance').val();
        var OtherDeductions = $('.otherDeductions').val();
        var BasicSalary = $("#basicSalary").val();
        var TaxablePay = $('.taxablePay1').val();
        var SnittRelief = $('.ssnitRelief').val();
        var GrossSalary = parseInt(Allowance) + parseFloat(BasicSalary);
        var TaxablePay = parseFloat(GrossSalary) - parseFloat(SnittRelief);
        $('.allowanceTotal').val(Allowance);
        $('.grossSalary').val(GrossSalary);
        $('.taxablePay').val(TaxablePay.toFixed(2));

        $firstChargeableIncome = $(".firstChargeableIncome").html();
        $firstChargeableIncomeMin = $(".firstChargeableIncomeMin").html();
        $firstChargeableIncomeMax = $(".firstChargeableIncomeMax").html();
        $firstRate = $(".firstRate").html();
        $next1ChargeableIncome = $(".next1ChargeableIncome").html();
        $next1ChargeableIncomeMin = $(".next1ChargeableIncomeMin").html();
        $next1ChargeableIncomeMax = $(".next1ChargeableIncomeMax").html();
        $next1Rate = $(".next1Rate").html();
        $next2ChargeableIncome = $(".next2ChargeableIncome").html();
        $next2ChargeableIncomeMin = $(".next2ChargeableIncomeMin").html();
        $next2ChargeableIncomeMax = $(".next2ChargeableIncomeMax").html();
        $next2Rate = $(".next2Rate").html();
        $next3ChargeableIncome = $(".next3ChargeableIncome").html();
        $next3ChargeableIncomeMin = $(".next3ChargeableIncomeMin").html();
        $next3ChargeableIncomeMax = $(".next3ChargeableIncomeMax").html();
        $next3Rate = $(".next3Rate").html();
        $next4ChargeableIncome = $(".next4ChargeableIncome").html();
        $next4ChargeableIncomeMin = $(".next4ChargeableIncomeMin").html();
        $next4ChargeableIncomeMax = $(".next4ChargeableIncomeMax").html();
        $next4Rate = $(".next4Rate").html();
        $exceedingChargeableIncome = $(".exceedingChargeableIncome").html();
        $exceedingChargeableIncomeMin = $(".exceedingChargeableIncomeMin").html();
        $exceedingChargeableIncomeMax = $(".exceedingChargeableIncomeMax").html();
        $exceedingRate = $(".exceedingRate").html();

        $firstTax = TaxablePay - $firstChargeableIncome;
        if (TaxablePay <= $firstChargeableIncome) {
            if ($next1ChargeableIncome > $firstTax) {
                $TotalTax = 0.00;
                $(".totalTax").val($TotalTax.toFixed(2));
                $(".totalTax1").val($TotalTax.toFixed(2));
                var $NetSalary = TaxablePay - $TotalTax;
                var $NetSalary = $NetSalary - OtherDeductions;
                $(".netSalary").val($NetSalary.toFixed(2));
                $(".netSalary1").val($NetSalary.toFixed(2));
            }
        }
        $firstTax1 = $firstChargeableIncome * $firstRate / 100;

        $secondTax = $firstTax - $next1ChargeableIncome;
        if (TaxablePay > $next1ChargeableIncomeMin && TaxablePay <= $next1ChargeableIncomeMax) {
            if ($next1ChargeableIncome > $firstTax) {
                $secondTax1 = $firstTax * $next1Rate / 100;
                $TotalTax = $firstTax1 + $secondTax1;
                $(".totalTax").val($TotalTax.toFixed(2));
                $(".totalTax1").val($TotalTax.toFixed(2));
                var $NetSalary = TaxablePay - $TotalTax;
                var $NetSalary = $NetSalary - OtherDeductions;
                $(".netSalary").val($NetSalary.toFixed(2));
                $(".netSalary1").val($NetSalary.toFixed(2));
            }
        }
        $secondTax1 = $next1ChargeableIncome * $next1Rate / 100;

        $thirdTax = $secondTax - $next2ChargeableIncome;
        if (TaxablePay > $next2ChargeableIncomeMin && TaxablePay <= $next2ChargeableIncomeMax) {
            if ($next2ChargeableIncome > $secondTax) {
                $thirdTax1 = $secondTax * $next2Rate / 100;
                $TotalTax = $firstTax1 + $secondTax1 + $thirdTax1;
                $(".totalTax").val($TotalTax.toFixed(2));
                $(".totalTax1").val($TotalTax.toFixed(2));
                var $NetSalary = TaxablePay - $TotalTax;
                var $NetSalary = $NetSalary - OtherDeductions;
                $(".netSalary").val($NetSalary.toFixed(2));
                $(".netSalary1").val($NetSalary.toFixed(2));
            }
        }
        $thirdTax1 = $next2ChargeableIncome * $next2Rate / 100;

        $fourthTax = $thirdTax - $next3ChargeableIncome;
        if (TaxablePay > $next3ChargeableIncomeMin && TaxablePay <= $next3ChargeableIncomeMax) {
            if ($next3ChargeableIncome > $thirdTax) {
                $fourthTax1 = $thirdTax * $next3Rate / 100;
                $TotalTax = $firstTax1 + $secondTax1 + $thirdTax1 + $fourthTax1;
                // alert($TotalTax);
                $(".totalTax").val($TotalTax.toFixed(2));
                $(".totalTax1").val($TotalTax.toFixed(2));
                var $NetSalary = TaxablePay - $TotalTax;
                var $NetSalary = $NetSalary - OtherDeductions;
                $(".netSalary").val($NetSalary.toFixed(2));
                $(".netSalary1").val($NetSalary.toFixed(2));
            }
        }
        $fourthTax1 = $next3ChargeableIncome * $next3Rate / 100;

        $fifthTax = $fourthTax - $next4ChargeableIncome;
        if (TaxablePay > $next4ChargeableIncomeMin && TaxablePay <= $next4ChargeableIncomeMax) {
            if ($next4ChargeableIncome > $fourthTax) {
                $fifthTax1 = $fourthTax * $next4Rate / 100;
                $TotalTax = $firstTax1 + $secondTax1 + $thirdTax1 + $fourthTax1 + $fifthTax1;
                // alert($TotalTax);
                $(".totalTax").val($TotalTax.toFixed(2));
                $(".totalTax1").val($TotalTax.toFixed(2));
                var $NetSalary = TaxablePay - $TotalTax;
                var $NetSalary = $NetSalary - OtherDeductions;
                $(".netSalary").val($NetSalary.toFixed(2));
                $(".netSalary1").val($NetSalary.toFixed(2));
            }
        }
        $fifthTax1 = $next4ChargeableIncome * $next4Rate / 100;

        $sixthTax = $fifthTax - $exceedingChargeableIncome;
        if (TaxablePay > $exceedingChargeableIncomeMin) {
            if ($exceedingChargeableIncome > $fifthTax) {
                $sixthTax1 = $fifthTax * $exceedingRate / 100;
                $TotalTax = $firstTax1 + $secondTax1 + $thirdTax1 + $fourthTax1 + $fifthTax1 + $sixthTax1;
                // alert($TotalTax);
                $(".totalTax").val($TotalTax.toFixed(2));
                $(".totalTax1").val($TotalTax.toFixed(2));
                var $NetSalary = TaxablePay - $TotalTax;
                var $NetSalary = $NetSalary - OtherDeductions;
                $(".netSalary").val($NetSalary.toFixed(2));
                $(".netSalary1").val($NetSalary.toFixed(2));
            }
        }
        $sixthTax1 = $exceedingChargeableIncome * $exceedingRate / 100;

        // if (TaxablePay <= $firstChargeableIncome) {
        //     $TotalTax = 0.0;
        //     $(".totalTax").val($TotalTax.toFixed(2));
        //     $(".totalTax1").val($TotalTax.toFixed(2));
        //     var $NetSalary = TaxablePay - $TotalTax;
        //     var $NetSalary = $NetSalary - OtherDeductions;
        //     $(".netSalary").val($NetSalary.toFixed(2));
        //     $(".netSalary1").val($NetSalary.toFixed(2));
        // } else {
        //     $PayToBeTaxed = TaxablePay - $firstChargeableIncome;
        //     if ($PayToBeTaxed >= $next1ChargeableIncome) {
        //         $PayToBeTaxed = TaxablePay - $next1ChargeableIncome;
        //         if ($PayToBeTaxed >= $next2ChargeableIncome) {

        //             $PayToBeTaxed = TaxablePay - $next2ChargeableIncome;

        //             if ($PayToBeTaxed >= $next3ChargeableIncome) {

        //                 $PayToBeTaxed = TaxablePay - $next3ChargeableIncome;
        //                 if ($PayToBeTaxed >= $next4ChargeableIncome) {

        //                     $PayToBeTaxed = TaxablePay - $next4ChargeableIncome;
        //                     if ($PayToBeTaxed >= $exceedingChargeableIncome) {
        //                         $PayToBeTaxed = $PayToBeTaxed - $firstChargeableIncome;
        //                         $PayToBeTaxed = $PayToBeTaxed - $next1ChargeableIncome;
        //                         $PayToBeTaxed = $PayToBeTaxed - $next2ChargeableIncome;
        //                         $PayToBeTaxed = $PayToBeTaxed - $next3ChargeableIncome;
        //                         $PayToBeTaxed = $PayToBeTaxed * $exceedingRate / 100;
        //                         $TotalTax1 = $next1ChargeableIncome * $next1Rate / 100;
        //                         $TotalTax2 = $next2ChargeableIncome * $next2Rate / 100;
        //                         $TotalTax3 = $next3ChargeableIncome * $next3Rate / 100;
        //                         $TotalTax4 = $next4ChargeableIncome * $next4Rate / 100;
        //                         $TotalTax = $PayToBeTaxed + $TotalTax1 + $TotalTax2 + $TotalTax3 + $TotalTax4;
        //                         $(".totalTax").val($TotalTax.toFixed(2));
        //                         $(".totalTax1").val($TotalTax.toFixed(2));
        //                         var $NetSalary = TaxablePay - $TotalTax;
        //                         var $NetSalary = $NetSalary - OtherDeductions;
        //                         $(".netSalary").val($NetSalary.toFixed(2));
        //                         $(".netSalary1").val($NetSalary.toFixed(2));
        //                     } else {
        //                         $PayToBeTaxed = $PayToBeTaxed - $firstChargeableIncome;
        //                         $PayToBeTaxed = $PayToBeTaxed - $next1ChargeableIncome;
        //                         $PayToBeTaxed = $PayToBeTaxed - $next2ChargeableIncome;
        //                         $PayToBeTaxed = $PayToBeTaxed - $next3ChargeableIncome;
        //                         $PayToBeTaxed = $PayToBeTaxed * $exceedingRate / 100;
        //                         $TotalTax1 = $next1ChargeableIncome * $next1Rate / 100;
        //                         $TotalTax2 = $next2ChargeableIncome * $next2Rate / 100;
        //                         $TotalTax3 = $next3ChargeableIncome * $next3Rate / 100;
        //                         $TotalTax4 = $next4ChargeableIncome * $next4Rate / 100;
        //                         $TotalTax = $PayToBeTaxed + $TotalTax1 + $TotalTax2 + $TotalTax3 + $TotalTax4;
        //                         $(".totalTax").val($TotalTax.toFixed(2));
        //                         $(".totalTax1").val($TotalTax.toFixed(2));
        //                         var $NetSalary = TaxablePay - $TotalTax;
        //                         var $NetSalary = $NetSalary - OtherDeductions;
        //                         $(".netSalary").val($NetSalary.toFixed(2));
        //                         $(".netSalary1").val($NetSalary.toFixed(2));
        //                     }
        //                 } else {
        //                     $PayToBeTaxed = $PayToBeTaxed - $firstChargeableIncome;
        //                     $PayToBeTaxed1 = $PayToBeTaxed - $next1ChargeableIncome;
        //                     $PayToBeTaxed2 = $PayToBeTaxed1 - $next2ChargeableIncome;
        //                     $PayToBeTaxed3 = $PayToBeTaxed2 * $next4Rate / 100;
        //                     $TotalTax1 = $next1ChargeableIncome * $next1Rate / 100;
        //                     $TotalTax2 = $next2ChargeableIncome * $next2Rate / 100;
        //                     $TotalTax3 = $next3ChargeableIncome * $next3Rate / 100;
        //                     $TotalTax = $PayToBeTaxed3 + $TotalTax1 + $TotalTax2 + $TotalTax3;
        //                     if ($firstChargeableIncome > $PayToBeTaxed) {

        //                         $PayToBeTaxed = TaxablePay;
        //                         $PayToBeTaxed = $PayToBeTaxed - $firstChargeableIncome;
        //                         $PayToBeTaxed1 = $PayToBeTaxed - $next1ChargeableIncome;
        //                         $PayToBeTaxed2 = $PayToBeTaxed1 - $next2ChargeableIncome;
        //                         $TotalTax1 = $next1ChargeableIncome * $next1Rate / 100;
        //                         $TotalTax2 = $next2ChargeableIncome * $next2Rate / 100;
        //                         $TotalTax3 = $PayToBeTaxed2 * $next3Rate / 100;
        //                         $TotalTax = $TotalTax1 + $TotalTax2 + $TotalTax3;
        //                     }
        //                     $(".totalTax").val($TotalTax.toFixed(2));
        //                     $(".totalTax1").val($TotalTax.toFixed(2));
        //                     var $NetSalary = TaxablePay - $TotalTax;
        //                     var $NetSalary = $NetSalary - OtherDeductions;
        //                     $(".netSalary").val($NetSalary.toFixed(2));
        //                     $(".netSalary1").val($NetSalary.toFixed(2));
        //                 }
        //             } else {
        //                 $PayToBeTaxed = $PayToBeTaxed - $firstChargeableIncome;
        //                 $PayToBeTaxed1 = $PayToBeTaxed - $next1ChargeableIncome;
        //                 $PayToBeTaxed2 = $PayToBeTaxed1 * $next3Rate / 100;
        //                 $TotalTax1 = $next1ChargeableIncome * $next1Rate / 100;
        //                 $TotalTax2 = $next2ChargeableIncome * $next2Rate / 100;
        //                 $TotalTax = $PayToBeTaxed2 + $TotalTax1 + $TotalTax2;
        //                 if ($PayToBeTaxed < 0.00) {
        //                     $PayToBeTaxed = TaxablePay;
        //                     $PayToBeTaxed = $PayToBeTaxed - $firstChargeableIncome;
        //                     $TotalTax1 = $next1ChargeableIncome * $next1Rate / 100;
        //                     $TotalTax2 = $PayToBeTaxed - $next1ChargeableIncome;
        //                     $TotalTax2 = $TotalTax2 * $next2Rate / 100;
        //                     $TotalTax = $TotalTax1 + $TotalTax2;
        //                 }
        //                 $(".totalTax").val($TotalTax.toFixed(2));
        //                 $(".totalTax1").val($TotalTax.toFixed(2));
        //                 var $NetSalary = TaxablePay - $TotalTax;
        //                 var $NetSalary = $NetSalary - OtherDeductions;
        //                 $(".netSalary").val($NetSalary.toFixed(2));
        //                 $(".netSalary1").val($NetSalary.toFixed(2));
        //             }
        //         } else {
        //             $PayToBeTaxed = $PayToBeTaxed - $firstChargeableIncome;
        //             $PayToBeTaxed = $PayToBeTaxed * $next2Rate / 100;
        //             $TotalTax1 = $next1ChargeableIncome * $next1Rate / 100;
        //             $TotalTax = $PayToBeTaxed + $TotalTax1;
        //             $(".totalTax").val($TotalTax.toFixed(2));
        //             $(".totalTax1").val($TotalTax.toFixed(2));
        //             var $NetSalary = TaxablePay - $TotalTax;
        //             var $NetSalary = $NetSalary - OtherDeductions;
        //             $(".netSalary").val($NetSalary.toFixed(2));
        //             $(".netSalary1").val($NetSalary.toFixed(2));
        //         }

        //     } else {
        //         $PayToBeTaxed = $PayToBeTaxed * $next1Rate / 100;
        //         $TotalTax = $PayToBeTaxed;
        //         $(".totalTax").val($TotalTax.toFixed(2));
        //         $(".totalTax1").val($TotalTax.toFixed(2));
        //         var $NetSalary = TaxablePay - $TotalTax;
        //         var $NetSalary = $NetSalary - OtherDeductions;
        //         $(".netSalary").val($NetSalary.toFixed(2));
        //         $(".netSalary1").val($NetSalary.toFixed(2));
        //     }


        // }

    });

    $('.otherDeductions').on("blur", function() {
        var $TaxablePay = $('.taxablePayForCalculationsPurposes').val();
        var $TotalTax = $(".totalTax1").val();
        var OtherDeductions = $('.otherDeductions').val();
        var $NetSalary = $TaxablePay - $TotalTax;
        var $NetSalary = $NetSalary - OtherDeductions;
        $(".otherDeductionsTotal").val(OtherDeductions);
        $(".netSalary,.netSalary1").val($NetSalary.toFixed(2));
    });






    var Allowance = $('.allowance').val();
    var OtherDeductions = $('.otherDeductions').val();
    var BasicSalary = $("#basicSalary").val();
    var TaxablePay = $('.taxablePay1').val();
    var SnittRelief = $('.ssnitRelief').val();
    var GrossSalary = parseInt(Allowance) + parseFloat(BasicSalary);
    var TaxablePay = parseFloat(GrossSalary) - parseFloat(SnittRelief);
    $('.allowanceTotal').val(Allowance);
    $('.grossSalary').val(GrossSalary);
    $('.taxablePay').val(TaxablePay.toFixed(2));


    $firstChargeableIncome = $(".firstChargeableIncome").html();
    $firstChargeableIncomeMin = $(".firstChargeableIncomeMin").html();
    $firstChargeableIncomeMax = $(".firstChargeableIncomeMax").html();
    $firstRate = $(".firstRate").html();
    $next1ChargeableIncome = $(".next1ChargeableIncome").html();
    $next1ChargeableIncomeMin = $(".next1ChargeableIncomeMin").html();
    $next1ChargeableIncomeMax = $(".next1ChargeableIncomeMax").html();
    $next1Rate = $(".next1Rate").html();
    $next2ChargeableIncome = $(".next2ChargeableIncome").html();
    $next2ChargeableIncomeMin = $(".next2ChargeableIncomeMin").html();
    $next2ChargeableIncomeMax = $(".next2ChargeableIncomeMax").html();
    $next2Rate = $(".next2Rate").html();
    $next3ChargeableIncome = $(".next3ChargeableIncome").html();
    $next3ChargeableIncomeMin = $(".next3ChargeableIncomeMin").html();
    $next3ChargeableIncomeMax = $(".next3ChargeableIncomeMax").html();
    $next3Rate = $(".next3Rate").html();
    $next4ChargeableIncome = $(".next4ChargeableIncome").html();
    $next4ChargeableIncomeMin = $(".next4ChargeableIncomeMin").html();
    $next4ChargeableIncomeMax = $(".next4ChargeableIncomeMax").html();
    $next4Rate = $(".next4Rate").html();
    $exceedingChargeableIncome = $(".exceedingChargeableIncome").html();
    $exceedingChargeableIncomeMin = $(".exceedingChargeableIncomeMin").html();
    $exceedingChargeableIncomeMax = $(".exceedingChargeableIncomeMax").html();
    $exceedingRate = $(".exceedingRate").html();

    $firstTax = TaxablePay - $firstChargeableIncome;
    if (TaxablePay <= $firstChargeableIncome) {
        if ($next1ChargeableIncome > $firstTax) {
            $TotalTax = 0.00;
            $(".totalTax").val($TotalTax.toFixed(2));
            $(".totalTax1").val($TotalTax.toFixed(2));
            var $NetSalary = TaxablePay - $TotalTax;
            var $NetSalary = $NetSalary - OtherDeductions;
            $(".netSalary").val($NetSalary.toFixed(2));
            $(".netSalary1").val($NetSalary.toFixed(2));
        }
    }
    $firstTax1 = $firstChargeableIncome * $firstRate / 100;

    $secondTax = $firstTax - $next1ChargeableIncome;
    if (TaxablePay > $next1ChargeableIncomeMin && TaxablePay <= $next1ChargeableIncomeMax) {
        if ($next1ChargeableIncome > $firstTax) {
            $secondTax1 = $firstTax * $next1Rate / 100;
            $TotalTax = $firstTax1 + $secondTax1;
            $(".totalTax").val($TotalTax.toFixed(2));
            $(".totalTax1").val($TotalTax.toFixed(2));
            var $NetSalary = TaxablePay - $TotalTax;
            var $NetSalary = $NetSalary - OtherDeductions;
            $(".netSalary").val($NetSalary.toFixed(2));
            $(".netSalary1").val($NetSalary.toFixed(2));
        }
    }
    $secondTax1 = $next1ChargeableIncome * $next1Rate / 100;

    $thirdTax = $secondTax - $next2ChargeableIncome;
    if (TaxablePay > $next2ChargeableIncomeMin && TaxablePay <= $next2ChargeableIncomeMax) {
        if ($next2ChargeableIncome > $secondTax) {
            $thirdTax1 = $secondTax * $next2Rate / 100;
            $TotalTax = $firstTax1 + $secondTax1 + $thirdTax1;
            $(".totalTax").val($TotalTax.toFixed(2));
            $(".totalTax1").val($TotalTax.toFixed(2));
            var $NetSalary = TaxablePay - $TotalTax;
            var $NetSalary = $NetSalary - OtherDeductions;
            $(".netSalary").val($NetSalary.toFixed(2));
            $(".netSalary1").val($NetSalary.toFixed(2));
        }
    }
    $thirdTax1 = $next2ChargeableIncome * $next2Rate / 100;

    $fourthTax = $thirdTax - $next3ChargeableIncome;
    if (TaxablePay > $next3ChargeableIncomeMin && TaxablePay <= $next3ChargeableIncomeMax) {
        if ($next3ChargeableIncome > $thirdTax) {
            $fourthTax1 = $thirdTax * $next3Rate / 100;
            $TotalTax = $firstTax1 + $secondTax1 + $thirdTax1 + $fourthTax1;
            // alert($TotalTax);
            $(".totalTax").val($TotalTax.toFixed(2));
            $(".totalTax1").val($TotalTax.toFixed(2));
            var $NetSalary = TaxablePay - $TotalTax;
            var $NetSalary = $NetSalary - OtherDeductions;
            $(".netSalary").val($NetSalary.toFixed(2));
            $(".netSalary1").val($NetSalary.toFixed(2));
        }
    }
    $fourthTax1 = $next3ChargeableIncome * $next3Rate / 100;

    $fifthTax = $fourthTax - $next4ChargeableIncome;
    if (TaxablePay > $next4ChargeableIncomeMin && TaxablePay <= $next4ChargeableIncomeMax) {
        if ($next4ChargeableIncome > $fourthTax) {
            $fifthTax1 = $fourthTax * $next4Rate / 100;
            $TotalTax = $firstTax1 + $secondTax1 + $thirdTax1 + $fourthTax1 + $fifthTax1;
            // alert($TotalTax);
            $(".totalTax").val($TotalTax.toFixed(2));
            $(".totalTax1").val($TotalTax.toFixed(2));
            var $NetSalary = TaxablePay - $TotalTax;
            var $NetSalary = $NetSalary - OtherDeductions;
            $(".netSalary").val($NetSalary.toFixed(2));
            $(".netSalary1").val($NetSalary.toFixed(2));
        }
    }
    $fifthTax1 = $next4ChargeableIncome * $next4Rate / 100;

    $sixthTax = $fifthTax - $exceedingChargeableIncome;
    if (TaxablePay > $exceedingChargeableIncomeMin) {
        if ($exceedingChargeableIncome > $fifthTax) {
            $sixthTax1 = $fifthTax * $exceedingRate / 100;
            $TotalTax = $firstTax1 + $secondTax1 + $thirdTax1 + $fourthTax1 + $fifthTax1 + $sixthTax1;
            // alert($TotalTax);
            $(".totalTax").val($TotalTax.toFixed(2));
            $(".totalTax1").val($TotalTax.toFixed(2));
            var $NetSalary = TaxablePay - $TotalTax;
            var $NetSalary = $NetSalary - OtherDeductions;
            $(".netSalary").val($NetSalary.toFixed(2));
            $(".netSalary1").val($NetSalary.toFixed(2));
        }
    }
    $sixthTax1 = $exceedingChargeableIncome * $exceedingRate / 100;


    // if (TaxablePay <= $firstChargeableIncome) {
    //     $TotalTax = 0.0;
    //     $(".totalTax").val($TotalTax.toFixed(2));
    //     $(".totalTax1").val($TotalTax.toFixed(2));
    //     var $NetSalary = TaxablePay - $TotalTax;
    //     var $NetSalary = $NetSalary - OtherDeductions;
    //     $(".netSalary").val($NetSalary.toFixed(2));
    //     $(".netSalary1").val($NetSalary.toFixed(2));
    // } else {

    //     $PayToBeTaxed = TaxablePay - $firstChargeableIncome;
    //     if ($PayToBeTaxed >= $next1ChargeableIncome) {
    //         $PayToBeTaxed = TaxablePay - $next1ChargeableIncome;
    //         if ($PayToBeTaxed >= $next2ChargeableIncome) {

    //             $PayToBeTaxed = TaxablePay - $next2ChargeableIncome;
    //             if ($PayToBeTaxed >= $next3ChargeableIncome) {
    //                 $PayToBeTaxed = TaxablePay - $next3ChargeableIncome;
    //                 if ($PayToBeTaxed >= $next4ChargeableIncome) {
    //                     $PayToBeTaxed = TaxablePay - $next4ChargeableIncome;
    //                     if ($PayToBeTaxed >= $exceedingChargeableIncome) {
    //                         $PayToBeTaxed = $PayToBeTaxed - $firstChargeableIncome;
    //                         $PayToBeTaxed = $PayToBeTaxed - $next1ChargeableIncome;
    //                         $PayToBeTaxed = $PayToBeTaxed - $next2ChargeableIncome;
    //                         $PayToBeTaxed = $PayToBeTaxed - $next3ChargeableIncome;
    //                         $PayToBeTaxed = $PayToBeTaxed * $exceedingRate / 100;
    //                         $TotalTax1 = $next1ChargeableIncome * $next1Rate / 100;
    //                         $TotalTax2 = $next2ChargeableIncome * $next2Rate / 100;
    //                         $TotalTax3 = $next3ChargeableIncome * $next3Rate / 100;
    //                         $TotalTax4 = $next4ChargeableIncome * $next4Rate / 100;
    //                         $TotalTax = $PayToBeTaxed + $TotalTax1 + $TotalTax2 + $TotalTax3 + $TotalTax4;
    //                         $(".totalTax").val($TotalTax.toFixed(2));
    //                         $(".totalTax1").val($TotalTax.toFixed(2));
    //                         var $NetSalary = TaxablePay - $TotalTax;
    //                         var $NetSalary = $NetSalary - OtherDeductions;
    //                         $(".netSalary").val($NetSalary.toFixed(2));
    //                         $(".netSalary1").val($NetSalary.toFixed(2));

    //                     } else {
    //                         $PayToBeTaxed = $PayToBeTaxed - $firstChargeableIncome;
    //                         $PayToBeTaxed = $PayToBeTaxed - $next1ChargeableIncome;
    //                         $PayToBeTaxed = $PayToBeTaxed - $next2ChargeableIncome;
    //                         $PayToBeTaxed = $PayToBeTaxed - $next3ChargeableIncome;
    //                         $PayToBeTaxed = $PayToBeTaxed * $exceedingRate / 100;
    //                         $TotalTax1 = $next1ChargeableIncome * $next1Rate / 100;
    //                         $TotalTax2 = $next2ChargeableIncome * $next2Rate / 100;
    //                         $TotalTax3 = $next3ChargeableIncome * $next3Rate / 100;
    //                         $TotalTax4 = $next4ChargeableIncome * $next4Rate / 100;
    //                         $TotalTax = $PayToBeTaxed + $TotalTax1 + $TotalTax2 + $TotalTax3 + $TotalTax4;
    //                         $(".totalTax").val($TotalTax.toFixed(2));
    //                         $(".totalTax1").val($TotalTax.toFixed(2));
    //                         var $NetSalary = TaxablePay - $TotalTax;
    //                         var $NetSalary = $NetSalary - OtherDeductions;
    //                         $(".netSalary").val($NetSalary.toFixed(2));
    //                         $(".netSalary1").val($NetSalary.toFixed(2));
    //                     }
    //                 } else {

    //                     $PayToBeTaxed = $PayToBeTaxed - $firstChargeableIncome;
    //                     $PayToBeTaxed1 = $PayToBeTaxed - $next1ChargeableIncome;
    //                     $PayToBeTaxed2 = $PayToBeTaxed1 - $next2ChargeableIncome;
    //                     $PayToBeTaxed3 = $PayToBeTaxed2 * $next4Rate / 100;
    //                     $TotalTax1 = $next1ChargeableIncome * $next1Rate / 100;
    //                     $TotalTax2 = $next2ChargeableIncome * $next2Rate / 100;
    //                     $TotalTax3 = $next3ChargeableIncome * $next3Rate / 100;
    //                     $TotalTax = $PayToBeTaxed3 + $TotalTax1 + $TotalTax2 + $TotalTax3;

    //                     if ($firstChargeableIncome > $PayToBeTaxed) {
    //                         $PayToBeTaxed = TaxablePay;
    //                         $PayToBeTaxed = $PayToBeTaxed - $firstChargeableIncome;
    //                         $PayToBeTaxed1 = $PayToBeTaxed - $next1ChargeableIncome;
    //                         $PayToBeTaxed2 = $PayToBeTaxed1 - $next2ChargeableIncome;
    //                         $TotalTax1 = $next1ChargeableIncome * $next1Rate / 100;
    //                         $TotalTax2 = $next2ChargeableIncome * $next2Rate / 100;
    //                         $TotalTax3 = $PayToBeTaxed2 * $next3Rate / 100;
    //                         $TotalTax = $TotalTax1 + $TotalTax2 + $TotalTax3;
    //                     }

    //                     $(".totalTax").val($TotalTax.toFixed(2));
    //                     $(".totalTax1").val($TotalTax.toFixed(2));
    //                     var $NetSalary = TaxablePay - $TotalTax;
    //                     var $NetSalary = $NetSalary - OtherDeductions;
    //                     $(".netSalary").val($NetSalary.toFixed(2));
    //                     $(".netSalary1").val($NetSalary.toFixed(2));
    //                 }
    //             } else {

    //                 $PayToBeTaxed = $PayToBeTaxed - $firstChargeableIncome;
    //                 $PayToBeTaxed1 = $PayToBeTaxed - $next1ChargeableIncome;
    //                 $PayToBeTaxed2 = $PayToBeTaxed1 * $next3Rate / 100;
    //                 $TotalTax1 = $next1ChargeableIncome * $next1Rate / 100;
    //                 $TotalTax2 = $next2ChargeableIncome * $next2Rate / 100;
    //                 $TotalTax = $PayToBeTaxed2 + $TotalTax1 + $TotalTax2;

    //                 if ($PayToBeTaxed < 0.00) {     
    //                     $PayToBeTaxed = TaxablePay;
    //                     $PayToBeTaxed = $PayToBeTaxed - $firstChargeableIncome;
    //                     $TotalTax1 = $next1ChargeableIncome * $next1Rate / 100;
    //                     $TotalTax2 = $PayToBeTaxed - $next1ChargeableIncome;
    //                     $TotalTax2 = $TotalTax2 * $next2Rate / 100;
    //                     $TotalTax = $TotalTax1 + $TotalTax2;                     
    //                 }

    //                 $(".totalTax").val($TotalTax.toFixed(2));
    //                 $(".totalTax1").val($TotalTax.toFixed(2));
    //                 var $NetSalary = TaxablePay - $TotalTax;
    //                 var $NetSalary = $NetSalary - OtherDeductions;
    //                 $(".netSalary").val($NetSalary.toFixed(2));
    //                 $(".netSalary1").val($NetSalary.toFixed(2));
    //             }
    //         } else {
    //             $PayToBeTaxed = $PayToBeTaxed - $firstChargeableIncome;
    //             $PayToBeTaxed = $PayToBeTaxed * $next2Rate / 100;
    //             $TotalTax1 = $next1ChargeableIncome * $next1Rate / 100;
    //             $TotalTax = $PayToBeTaxed + $TotalTax1;
    //             $(".totalTax").val($TotalTax.toFixed(2));
    //             $(".totalTax1").val($TotalTax.toFixed(2));
    //             var $NetSalary = TaxablePay - $TotalTax;
    //             var $NetSalary = $NetSalary - OtherDeductions;
    //             $(".netSalary").val($NetSalary.toFixed(2));
    //             $(".netSalary1").val($NetSalary.toFixed(2));
    //         }

    //     } else {
    //         $PayToBeTaxed = $PayToBeTaxed * $next1Rate / 100;
    //         $TotalTax = $PayToBeTaxed;
    //         $(".totalTax").val($TotalTax.toFixed(2));
    //         $(".totalTax1").val($TotalTax.toFixed(2));
    //         var $NetSalary = TaxablePay - $TotalTax;
    //         var $NetSalary = $NetSalary - OtherDeductions;
    //         $(".netSalary").val($NetSalary.toFixed(2));
    //         $(".netSalary1").val($NetSalary.toFixed(2));
    //     }


    // }




    var $TaxablePay = $('.taxablePayForCalculationsPurposes').val();
    var $TotalTax = $(".totalTax1").val();
    var OtherDeductions = $('.otherDeductions').val();
    var $NetSalary = $TaxablePay - $TotalTax;
    var $NetSalary = $NetSalary - OtherDeductions;
    $(".otherDeductionsTotal").val(OtherDeductions);
    $(".netSalary,.netSalary1").val($NetSalary.toFixed(2));


    $('#submitPayroll').on('click', function() {
        $("#formPayroll").submit(function(e) {
            $.ajax({
                url: domain_api + "/payroll/save-payroll.php",
                type: "POST",
                data: $(this).serialize(),
                beforeSend: function() {
                    $('#submitPayroll').attr('disabled', 'disabled');
                    $('#button_textttt').replaceWith("<span  id='spinner'><i class='fa fa-spinner fa-spin fa-1x' style='color:rgb(255, 255, 255)' ></i></span>");
                },
                success: function(data) {
                    var year = $('.searchParameters').attr("data-year");
                    var month = $('.searchParameters').attr("data-month");
                    $(".payroll-totals").load(domain + "/COMPONENTS/sub-pages/payroll-totals.php?year=" + encodeURIComponent(year) + "&month=" + encodeURIComponent(month) + "", function() {
                        $('#spinner').replaceWith("<span  id='button_textttt'><i class='fa fa-save' style='font-size:28px; color:white;'></i> Save Payroll</span></span>");
                        $('#example').DataTable().ajax.reload();
                        swal("Succes!", "Payroll prepared successfully.", "success");
                        $("#myModal_profile").modal("hide");
                    });
                },
                error: function(request, error) {
                    // This callback function will trigger on unsuccessful action 
                    $('#spinner').replaceWith("<span id='button_text' style='font-size:17px;'>Proceed</span>");
                    $('#network-error-navbar').show();
                    setTimeout(function() {
                        $('#network-error-navbar').slideToggle('slow');
                    }, 5000);

                },
            });

            //$(this).unbind();
            e.preventDefault();
        });

        $(this).off("click");
    });
</script>