<?php

require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include('includes/function.php');

$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);
$admin = $_SESSION["admin_" . $dbname];
$fseries = $_SESSION["society_" . $dbname];
$keycond = "and `series`= '$fseries'";
$tcsslab = $_SESSION["tcsslab"];

if (isset($_REQUEST['para'])) {
    $party = $_REQUEST['party'];

    $full2 = $_REQUEST['full2'];
    $full2_2 = $_REQUEST['full2_2'];
    $full2_3 = $_REQUEST['full2_3'];
    $fullno = $_REQUEST['fullno'];
    $fullno_2 = $_REQUEST['fullno_2'];
    $fullno_3 = $_REQUEST['fullno_3'];

    $ggst = $gtcs1 = $gtcs2 = $gtgst = $gtcs = $gftcs1 = $gftcs2 = 0;
    $ctr = 0;

//    for adult
    if ($full2 > 0 && $fullno > 0) {
        $fgst = round($full2 * 0.05, 0);
        $ftamt = $full2 + $fgst;
        if ($ftamt > $tcsslab) {
            $ftcs1 = round($tcsslab * .02, 0);
            $fbl = $ftamt - $tcsslab;
            $ftcs2 = round($fbl * 0.20, 0);
        } else {
            $ftcs1 = round($ftamt * .02, 0);
            $ftcs2 = 0;
        }
        $ftgst = $fgst * $fullno;
//        $ttcs = $ftcs1 + $ftcs2;
//        $ftcs = $ttcs * $fullno;
        $fgtcs1 = $ftcs1 * $fullno;
        $fgtcs2 = $ftcs2 * $fullno;


        echo "<tr>";
        echo "<td><input type='text' name='ppamt_$ctr' class='form-control ppamt text-right' value='$full2' readonly></td>";
        echo "<td><input type='text' name='tpax_$ctr' class='form-control tadult text-right' value='$fullno'></td>";
        echo "<td><input type='text' name='fgst_$ctr' class='form-control fgst text-right' value='$fgst' readonly></td>";
        echo "<td><input type='text' name='ftcs1_$ctr' class='form-control ftcs1 text-right' value='$ftcs1' readonly></td>";
        echo "<td><input type='text' name='ftcs2_$ctr' class='form-control ftcs2 text-right' value='$ftcs2' readonly></td>";
        echo "<td><input type='text' name='ftgst_$ctr' class='form-control ftgst text-right' value='$ftgst' readonly></td>";
        echo "<td><input type='text' name='fgtcs1_$ctr' class='form-control fgtcs1 text-right' value='$fgtcs1' readonly></td>";
        echo "<td><input type='text' name='fgtcs2_$ctr' class='form-control fgtcs2 text-right' value='$fgtcs2' readonly></td>";
        echo "</tr>";
        $ggst = $ggst + $fgst;
        $gtcs1 = $gtcs1 + $ftcs1;
        $gtcs2 = $gtcs2 + $ftcs2;
        $gtgst = $gtgst + $ftgst;
        $gftcs1 = $gftcs1 + $fgtcs1;
        $gftcs2 = $gftcs2 + $fgtcs2;
        $ctr++;
    }

//    for adult 2

    if ($full2_2 > 0 && $fullno_2 > 0) {
        $fgst = round($full2_2 * 0.02, 0);
        $ftamt = $full2_2 + $fgst;
        if ($ftamt > $tcsslab) {
            $ftcs1 = round($tcsslab * .02, 0);
            $fbl = $ftamt - $tcsslab;
            $ftcs2 = round($fbl * 0.20, 0);
        } else {
            $ftcs1 = round($ftamt * .02, 0);
            $ftcs2 = 0;
        }
        $ftgst = $fgst * $fullno_2;
//        $ttcs = $ftcs1 + $ftcs2;
//        $ftcs = $ttcs * $fullno;
        $fgtcs1 = $ftcs1 * $fullno_2;
        $fgtcs2 = $ftcs2 * $fullno_2;


        echo "<tr>";
        echo "<td><input type='text' name='ppamt_$ctr' class='form-control ppamt text-right' value='$full2_2' readonly></td>";
        echo "<td><input type='text' name='tpax_$ctr' class='form-control tadult text-right' value='$fullno_2'></td>";
        echo "<td><input type='text' name='fgst_$ctr' class='form-control fgst text-right' value='$fgst' readonly></td>";
        echo "<td><input type='text' name='ftcs1_$ctr' class='form-control ftcs1 text-right' value='$ftcs1' readonly></td>";
        echo "<td><input type='text' name='ftcs2_$ctr' class='form-control ftcs2 text-right' value='$ftcs2' readonly></td>";
        echo "<td><input type='text' name='ftgst_$ctr' class='form-control ftgst text-right' value='$ftgst' readonly></td>";
        echo "<td><input type='text' name='fgtcs1_$ctr' class='form-control fgtcs1 text-right' value='$fgtcs1' readonly></td>";
        echo "<td><input type='text' name='fgtcs2_$ctr' class='form-control fgtcs2 text-right' value='$fgtcs2' readonly></td>";
        echo "</tr>";
        $ggst = $ggst + $fgst;
        $gtcs1 = $gtcs1 + $ftcs1;
        $gtcs2 = $gtcs2 + $ftcs2;
        $gtgst = $gtgst + $ftgst;
        $gftcs1 = $gftcs1 + $fgtcs1;
        $gftcs2 = $gftcs2 + $fgtcs2;
        $ctr++;
    }

//    for adult 3

    if ($full2_3 > 0 && $fullno_3 > 0) {
        $fgst = round($full2_3 * 0.05, 0);
        $ftamt = $full2_3 + $fgst;
        if ($ftamt > $tcsslab) {
            $ftcs1 = round($tcsslab * .02, 0);
            $fbl = $ftamt - $tcsslab;
            $ftcs2 = round($fbl * 0.20, 0);
        } else {
            $ftcs1 = round($ftamt * .02, 0);
            $ftcs2 = 0;
        }
        $ftgst = $fgst * $fullno_3;
//        $ttcs = $ftcs1 + $ftcs2;
//        $ftcs = $ttcs * $fullno;
        $fgtcs1 = $ftcs1 * $fullno_3;
        $fgtcs2 = $ftcs2 * $fullno_3;


        echo "<tr>";
        echo "<td><input type='text' name='ppamt_$ctr' class='form-control ppamt text-right' value='$full2_3' readonly></td>";
        echo "<td><input type='text' name='tpax_$ctr' class='form-control tadult text-right' value='$fullno_3'></td>";
        echo "<td><input type='text' name='fgst_$ctr' class='form-control fgst text-right' value='$fgst' readonly></td>";
        echo "<td><input type='text' name='ftcs1_$ctr' class='form-control ftcs1 text-right' value='$ftcs1' readonly></td>";
        echo "<td><input type='text' name='ftcs2_$ctr' class='form-control ftcs2 text-right' value='$ftcs2' readonly></td>";
        echo "<td><input type='text' name='ftgst_$ctr' class='form-control ftgst text-right' value='$ftgst' readonly></td>";
        echo "<td><input type='text' name='fgtcs1_$ctr' class='form-control fgtcs1 text-right' value='$fgtcs1' readonly></td>";
        echo "<td><input type='text' name='fgtcs2_$ctr' class='form-control fgtcs2 text-right' value='$fgtcs2' readonly></td>";
        echo "</tr>";
        $ggst = $ggst + $fgst;
        $gtcs1 = $gtcs1 + $ftcs1;
        $gtcs2 = $gtcs2 + $ftcs2;
        $gtgst = $gtgst + $ftgst;
        $gftcs1 = $gftcs1 + $fgtcs1;
        $gftcs2 = $gftcs2 + $fgtcs2;
        $ctr++;
    }

//    for half

    $half2 = $_REQUEST['half2'];
    $halfno = $_REQUEST['halfno'];
    if ($half2 > 0 && $halfno > 0) {

        $hgst = round($half2 * 0.05, 0);
        $htamt = $half2 + $hgst;
        if ($htamt > $tcsslab) {
            $htcs1 = round($tcsslab * .02, 0);
            $hbl = $htamt - $tcsslab;
            $htcs2 = round($hbl * 0.20, 0);
        } else {
            $htcs1 = round($htamt * .02, 0);
            $htcs2 = 0;
        }
        $htgst = $hgst * $halfno;
//        $htcs = $htcs1 + $htcs2;
//        $httcs = $htcs * $halfno;
        $hgtcs1 = $htcs1 * $halfno;
        $hgtcs2 = $htcs2 * $halfno;

        echo "<tr>";
        echo "<td><input type='text' name='ppamt_$ctr' class='form-control pphamt ppamt text-right' value='$half2' readonly></td>";
        echo "<td><input type='text' name='tpax_$ctr' class='form-control thalf tadult text-right' value='$halfno'></td>";
        echo "<td><input type='text' name='fgst_$ctr' class='form-control hgst fgst text-right' value='$hgst' readonly></td>";
        echo "<td><input type='text' name='ftcs1_$ctr' class='form-control htcs1 ftcs1 text-right' value='$htcs1' readonly></td>";
        echo "<td><input type='text' name='ftcs2_$ctr' class='form-control htcs2 ftcs2 text-right' value='$htcs2' readonly></td>";
        echo "<td><input type='text' name='ftgst_$ctr' class='form-control htgst ftgst text-right' value='$htgst' readonly></td>";
//        echo "<td><input type='text' name='htcs' class='form-control htcs text-right' value='$httcs' readonly></td>";
        echo "<td><input type='text' name='fgtcs1_$ctr' class='form-control hgtcs1 fgtcs1 text-right' value='$hgtcs1' readonly></td>";
        echo "<td><input type='text' name='fgtcs2_$ctr' class='form-control hgtcs2 fgtcs2 text-right' value='$hgtcs2' readonly></td>";
        echo "</tr>";
        $ggst = $ggst + $hgst;
        $gtcs1 = $gtcs1 + $htcs1;
        $gtcs2 = $gtcs2 + $htcs2;
        $gtgst = $gtgst + $htgst;
//        $gtcs = $gtcs + $httcs;
        $gftcs1 = $gftcs1 + $hgtcs1;
        $gftcs2 = $gftcs2 + $hgtcs2;
        $ctr++;
    }

    //    for childwob
    $childwob2 = $_REQUEST['childwob2'];
    $childwobno = $_REQUEST['childwobno'];
    if ($childwob2 > 0 && $childwobno > 0) {


        $cgst = round($childwob2 * 0.05, 0);
        $ctamt = $childwob2 + $cgst;
        if ($ctamt > $tcsslab) {
            $ctcs1 = round($tcsslab * .02, 0);
            $cbl = $ctamt - $tcsslab;
            $ctcs2 = round($cbl * 0.20, 0);
        } else {
            $ctcs1 = round($ctamt * .02, 0);
            $ctcs2 = 0;
        }
        $ctgst = $cgst * $childwobno;
//        $ctcs = $ctcs1 + $ctcs2;
//        $cttcs = $ctcs * $childwobno;
        $cgtcs1 = $ctcs1 * $childwobno;
        $cgtcs2 = $ctcs2 * $childwobno;

        echo "<tr>";
        echo "<td><input type='text' name='ppamt_$ctr' class='form-control ppcamt ppamt text-right' value='$childwob2' readonly></td>";
        echo "<td><input type='text' name='tpax_$ctr' class='form-control tchild tpax text-right' value='$childwobno'></td>";
        echo "<td><input type='text' name='fgst_$ctr' class='form-control cgst fgst text-right' value='$cgst' readonly></td>";
        echo "<td><input type='text' name='ftcs1_$ctr' class='form-control ctcs1 ftcs1 text-right' value='$ctcs1' readonly></td>";
        echo "<td><input type='text' name='ftcs2_$ctr' class='form-control ctcs2 ftcs2 text-right' value='$ctcs2' readonly></td>";
        echo "<td><input type='text' name='ftgst_$ctr' class='form-control ctgst ftgst text-right' value='$ctgst' readonly></td>";
//        echo "<td><input type='text' name='ctcs' class='form-control ctcs text-right' value='$cttcs' readonly></td>";
        echo "<td><input type='text' name='fgtcs1_$ctr' class='form-control cgtcs1 fgtcs1 text-right' value='$cgtcs1' readonly></td>";
        echo "<td><input type='text' name='fgtcs2_$ctr' class='form-control cgtcs2 fgtcs2 text-right' value='$cgtcs2' readonly></td>";
        echo "</tr>";
        $ggst = $ggst + $cgst;
        $gtcs1 = $gtcs1 + $ctcs1;
        $gtcs2 = $gtcs2 + $ctcs2;
        $gtgst = $gtgst + $ctgst;
//        $gtcs = $gtcs + $cttcs;
        $gftcs1 = $gftcs1 + $cgtcs1;
        $gftcs2 = $gftcs2 + $cgtcs2;
        $ctr++;
    }
    //    for infant
    $inf2 = $_REQUEST['inf2'];
    $infno = $_REQUEST['infno'];

    if ($inf2 > 0 && $infno > 0) {

        $ingst = round($inf2 * 0.05, 0);
        $intamt = $inf2 + $ingst;
        if ($intamt > $tcsslab) {
            $intcs1 = round($tcsslab * .02, 0);
            $inbl = $intamt - $tcsslab;
            $intcs2 = round($inbl * 0.20, 0);
        } else {
            $intcs1 = round($intamt * .02, 0);
            $intcs2 = 0;
        }
        $intgst = $ingst * $infno;
//        $intcs = $intcs1 + $intcs2;
//        $inttcs = $intcs * $infno;
        $ingtcs1 = $intcs1 * $infno;
        $ingtcs2 = $intcs2 * $infno;

        echo "<tr>";
        echo "<td><input type='text' name='ppamt_$ctr' class='form-control ppiamt ppamt text-right' value='$inf2' readonly></td>";
        echo "<td><input type='text' name='tpax_$ctr' class='form-control tinf tadult text-right' value='$infno'></td>";
        echo "<td><input type='text' name='fgst_$ctr' class='form-control ingst fgst text-right' value='$ingst' readonly></td>";
        echo "<td><input type='text' name='ftcs1_$ctr' class='form-control intcs1 ftcs1 text-right' value='$intcs1' readonly></td>";
        echo "<td><input type='text' name='ftcs2_$ctr' class='form-control intcs2 ftcs2 text-right' value='$intcs2' readonly></td>";
        echo "<td><input type='text' name='ftgst_$ctr' class='form-control intgst ftgst text-right' value='$intgst' readonly></td>";
//        echo "<td><input type='text' name='intcs' class='form-control intcs text-right' value='$inttcs' readonly></td>";
        echo "<td><input type='text' name='fgtcs1_$ctr' class='form-control ingtcs1 fgtcs1 text-right' value='$ingtcs1' readonly></td>";
        echo "<td><input type='text' name='fgtcs2_$ctr' class='form-control ingtcs2 fgtcs2 text-right' value='$ingtcs2' readonly></td>";
        echo "</tr>";
        $ggst = $ggst + $ingst;
        $gtcs1 = $gtcs1 + $intcs1;
        $gtcs2 = $gtcs2 + $intcs2;
        $gtgst = $gtgst + $intgst;
//        $gtcs = $gtcs + $inttcs;
        $gftcs1 = $gftcs1 + $ingtcs1;
        $gftcs2 = $gftcs2 + $ingtcs2;
        $ctr++;
    }


    echo "<tr style='color:green'>";
    echo "<td></td>";
    echo "<td><b>Total Tax</b></td>";
    echo "<td><input type='text' style='color:green;font-size:15px' class='form-control ggst text-right' value='$ggst' readonly></td>";
    echo "<td><input type='text' style='color:green;font-size:15px' class='form-control gtcs1 text-right' value='$gtcs1' readonly></td>";
    echo "<td><input type='text' style='color:green;font-size:15px' class='form-control gtcs2 text-right' value='$gtcs2' readonly></td>";
    echo "<td><input type='text' style='color:green;font-size:15px' class='form-control gtgst text-right' value='$gtgst' readonly></td>";
    echo "<td><input type='text' style='color:green;font-size:15px' class='form-control gftcs1 text-right' value='$gftcs1' readonly></td>";
    echo "<td><input type='text' style='color:green;font-size:15px' class='form-control gftcs2 text-right' value='$gftcs2' readonly></td>";
    echo "</tr>";

    echo " <input type='hidden' name='itemstax' value='$ctr' id='itemstax'>";
}    