<?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["series_" . $dbname];


$services = $_REQUEST['services'];
browse($services);

//////////   FOOD            

if ($services == "FO") {

//    if (isset($_POST['monthno'])) {

        echo "<tr style='height:10px;' class='dt'>";
        echo "<td style='width:12%;' class = 'td' align='center' style='width:20%' color=''><span style='font-size:20px;font-weight:bold;color:white'>Sunday</span>";
        echo "<td style='width:12%;' class = 'td' align='center' style='width:20%' color=''><span style='font-size:20px;font-weight:bold;color:white'>Monday</span>";
        echo "<td style='width:12%;' class = 'td' align='center' style='width:20%' color=''><span style='font-size:20px;font-weight:bold;color:white'>Tueday</span>";
        echo "<td style='width:12%;' class = 'td' align='center' style='width:20%' color=''><span style='font-size:20px;font-weight:bold;color:white'>Wednesday</span>";
        echo "<td style='width:12%;' class = 'td' align='center' style='width:20%' color=''><span style='font-size:20px;font-weight:bold;color:white'>Thursday</span>";
        echo "<td style='width:12%;' class = 'td' align='center' style='width:20%' color=''><span style='font-size:20px;font-weight:bold;color:white'>Friday</span>";
        echo "<td style='width:12%;' class = 'td' align='center' style='width:20%' color=''><span style='font-size:20px;font-weight:bold;color:white'>Saturday</span>";
        echo "<td style='width:12%;' class = 'td' align='center' style='width:20%' color=''><span style='font-size:20px;font-weight:bold;color:red'>Weekly Total</span>";
        echo "</tr>";

        $monthno = $_REQUEST['monthno'];
        $yearno = $_REQUEST['yearno'];


        if ($monthno > 9) {
            $month = $monthno;
        } else {
            $month = '0' . $monthno;
        }

        $mfrdate = $yearno . '-' . $month . '-01';
        $mtodate = date("Y-m-t", strtotime($mfrdate));

        $mfrdate2 = $mfrdate;

        $timestamp2 = strtotime($mtodate);
        $lastday = date('D', $timestamp2);

        $lastdt = date("d", strtotime($mtodate));

        $ctr = 0;
        $ctr2 = 0;
        $tsat = 0;
        $montotal = 0;
        $exit = 0;
        $satctr = 0;

        $pdate = 0;

//    browse($mfrdate);
//    browse($mtodate);

        while (strtotime($mfrdate) <= strtotime($mtodate)) {

            $timestamp1 = strtotime($mfrdate);
            $fday = date('D', $timestamp1);

            $ctr = 0;
            $ctr2 = 0;

            echo "<tr style='height:10px;' class=''>";
            if ($fday == 'Mon') {
                echo "<td>&nbsp;</td>";
                $ctr++;
            }

            if ($fday == 'Tue') {
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                $ctr = $ctr + 2;
            }

            if ($fday == 'Wed') {
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                $ctr = $ctr + 3;
            }

            if ($fday == 'Thu') {
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                $ctr = $ctr + 4;
            }

            if ($fday == 'Fri') {
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                $ctr = $ctr + 5;
            }

            if ($fday == 'Sat') {
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                $ctr = $ctr + 6;
            }


            while ($ctr < 7) {
                $i = $mfrdate;
                $pdate = date("d", strtotime($i));
                $timestamp = strtotime($i);

                $day = date('D', $timestamp);

                echo "<td style='width:12%;' class='td' align='center' ><span style='font-size:20px;font-weight:bold;color:blue'>$pdate</span>";
                echo "</td>";

                $mfrdate = date("Y-m-d", strtotime("+1 day", strtotime($mfrdate)));

                if ($day == "Sat") {
                    
                }


                $ctr++;
                if ($ctr == 8) {
                    $ctr = 0;
                }

                if ($pdate >= $lastdt) {
                    $exit = 1;
                    break;
                }
            }
            echo "</tr>";

            echo "<tr style='height:10px;'>";
            if ($fday == 'Mon') {
                echo "<td>&nbsp;</td>";
                $ctr2++;
            }

            if ($fday == 'Tue') {
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                $ctr2 = $ctr2 + 2;
            }

            if ($fday == 'Wed') {
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                $ctr2 = $ctr2 + 3;
            }

            if ($fday == 'Thu') {
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                $ctr2 = $ctr2 + 4;
            }

            if ($fday == 'Fri') {
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                $ctr2 = $ctr2 + 5;
            }

            if ($fday == 'Sat') {
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                $ctr2 = $ctr2 + 6;
            }

//        browse($ctr2) ;
            while ($ctr2 < 7) {
                $i = $mfrdate2;
                $bgcolor = 'white';

                $pdate = date("d", strtotime($i));
                $timestamp = strtotime($i);
                $day = date('D', $timestamp);


                $getsord = mysqli_query($conn, "SELECT vouchno, hotel, nopax as pax, nonights as night FROM `foodent` where '$i' between checkin and checkout ") or die(mysqli_error($conn));

                $getnum = mysqli_num_rows($getsord);
                if ($getnum > 0) {
                    $bgcolor = 'lightyellow';
                }

                $ttot = 0;
                echo "<td style='background-color:$bgcolor'>";

                while ($fetsord = mysqli_fetch_array($getsord)) {
                    $foodpax = $fetsord['pax'];
                    $foodnig = $fetsord['night'];
                    $hotel = $fetsord['hotel'];

                    $gethotel = mysqli_query($conn, "SELECT hotelnm from hotels where `code` = '$hotel' ") or die(mysqli_error($conn));
                    $fethotel = mysqli_fetch_array($gethotel);
                    $hoteldisp = 'Food : ' . $fethotel['hotelnm'];

                    $namedisp = ' Pax-' . $foodpax . '  N-' . $foodnig;

                    echo "<a href='fit_ent.php?vouchno=$fetsord[vouchno]&mode=edit' target='_blank' style='color:black'>$hoteldisp <span style='color:black;font-weight:bold'>$namedisp</span> </a><br>";

                    $ftot = $ftot + 1;
                    $fsat = $fsat + 1;
                    $montotal = $montotal + 1;
                }
                $ftot = 0;

                if ($ttot > 0) {
                    echo "<span style='color:maroon;font-size:16px;font-weight:bold;border-top:1px solid orange'>Total : $ftot</span>";
                }
                echo "</td>";

                if ($day == "Sat") {
                    echo "<td style='text-align:right;width:12%'><br><span  style='text-align:right; color:red;font-size:18px;font-weight:bold;'>Food - $fsat</span></td>";
                    $fsat = 0;
                }

                $mfrdate2 = date("Y-m-d", strtotime("+1 day", strtotime($mfrdate2)));
                $ctr2++;
                if ($ctr2 == 8) {
                    $ctr2 = 0;
                }

                if ($pdate >= $lastdt) {
                    for ($k = $ctr2; $k < 7; $k++) {
                        echo "<td style='width:12%'><br><span  style='text-align:right; color:red;font-size:18px;font-weight:bold;'>&nbsp;</span></td>";
                    }
                    echo "<td style='text-align:right;width:12%'><br><span  style='color:red;font-size:18px;font-weight:bold;'>Food - $fsat</span></td>";
                    $exit = 1;
                    break;
                }

            }
            echo "</tr>";
            if ($exit == 1) {
                break;
            }
        }
        echo "<tr>";
        echo "<td  colspan='7' style='text-align:right;color:purple;font-size:20px;font-weight:bold;border-top:1px solid green' >Month Total </td>";
        echo "<td  style='text-align:right;color:purple;font-size:20px;font-weight:bold;border-top:1px solid green' >$montotal</td>";
        echo "</tr>";
//    }
    
}
//
//                    $getsord = mysqli_query($conn, "SELECT vouchno, hotel, nopax as pax, nonights as night FROM `foodent` where '$i' between checkin and checkout ") or die(mysqli_error($conn));
//                    $getvisadt = mysqli_query($conn, "SELECT vouchdt FROM `pax` ") or die(mysqli_error($conn));
//                    $fetvs = mysqli_fetch_array($getvisadt);


 if ($services == 'VS') {

    if (isset($_POST['monthno'])) {

        echo "<tr style='height:10px;' class='dt'>";
        echo "<td style='width:12%;' class = 'td' align='center' style='width:20%' color=''><span style='font-size:20px;font-weight:bold;color:white'>Sunday</span>";
        echo "<td style='width:12%;' class = 'td' align='center' style='width:20%' color=''><span style='font-size:20px;font-weight:bold;color:white'>Monday</span>";
        echo "<td style='width:12%;' class = 'td' align='center' style='width:20%' color=''><span style='font-size:20px;font-weight:bold;color:white'>Tueday</span>";
        echo "<td style='width:12%;' class = 'td' align='center' style='width:20%' color=''><span style='font-size:20px;font-weight:bold;color:white'>Wednesday</span>";
        echo "<td style='width:12%;' class = 'td' align='center' style='width:20%' color=''><span style='font-size:20px;font-weight:bold;color:white'>Thursday</span>";
        echo "<td style='width:12%;' class = 'td' align='center' style='width:20%' color=''><span style='font-size:20px;font-weight:bold;color:white'>Friday</span>";
        echo "<td style='width:12%;' class = 'td' align='center' style='width:20%' color=''><span style='font-size:20px;font-weight:bold;color:white'>Saturday</span>";
        echo "<td style='width:12%;' class = 'td' align='center' style='width:20%' color=''><span style='font-size:20px;font-weight:bold;color:red'>Weekly Total</span>";
        echo "</tr>";

        $monthno = $_REQUEST['monthno'];
        $yearno = $_REQUEST['yearno'];


        if ($monthno > 9) {
            $month = $monthno;
        } else {
            $month = '0' . $monthno;
        }

        $mfrdate = $yearno . '-' . $month . '-01';
        $mtodate = date("Y-m-t", strtotime($mfrdate));

        $mfrdate2 = $mfrdate;

        $timestamp2 = strtotime($mtodate);
        $lastday = date('D', $timestamp2);

        $lastdt = date("d", strtotime($mtodate));

        $ctr = 0;
        $ctr2 = 0;
        $tsat = 0;
        $montotal = 0;
        $exit = 0;
        $satctr = 0;

        $pdate = 0;

//    browse($mfrdate);
//    browse($mtodate);

        while (strtotime($mfrdate) <= strtotime($mtodate)) {

            $timestamp1 = strtotime($mfrdate);
            $fday = date('D', $timestamp1);

            $ctr = 0;
            $ctr2 = 0;

            echo "<tr style='height:10px;' class=''>";
            if ($fday == 'Mon') {
                echo "<td>&nbsp;</td>";
                $ctr++;
            }

            if ($fday == 'Tue') {
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                $ctr = $ctr + 2;
            }

            if ($fday == 'Wed') {
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                $ctr = $ctr + 3;
            }

            if ($fday == 'Thu') {
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                $ctr = $ctr + 4;
            }

            if ($fday == 'Fri') {
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                $ctr = $ctr + 5;
            }

            if ($fday == 'Sat') {
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                $ctr = $ctr + 6;
            }


            while ($ctr < 7) {
                $i = $mfrdate;
                $pdate = date("d", strtotime($i));
                $timestamp = strtotime($i);

                $day = date('D', $timestamp);

                echo "<td style='width:12%;' class='td' align='center' ><span style='font-size:20px;font-weight:bold;color:blue'>$pdate</span>";
                echo "</td>";

                $mfrdate = date("Y-m-d", strtotime("+1 day", strtotime($mfrdate)));

                if ($day == "Sat") {
                    
                }

                $ctr++;
                if ($ctr == 8) {
                    $ctr = 0;
                }

                if ($pdate >= $lastdt) {
                    $exit = 1;
                    break;
                }
            }
            echo "</tr>";

            echo "<tr style='height:10px;'>";
            if ($fday == 'Mon') {
                echo "<td>&nbsp;</td>";
                $ctr2++;
            }

            if ($fday == 'Tue') {
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                $ctr2 = $ctr2 + 2;
            }

            if ($fday == 'Wed') {
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                $ctr2 = $ctr2 + 3;
            }

            if ($fday == 'Thu') {
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                $ctr2 = $ctr2 + 4;
            }

            if ($fday == 'Fri') {
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                $ctr2 = $ctr2 + 5;
            }

            if ($fday == 'Sat') {
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                echo "<td>&nbsp;</td>";
                $ctr2 = $ctr2 + 6;
            }

//        browse($ctr2) ;
            while ($ctr2 < 7) {
                $i = $mfrdate2;
                $bgcolor = 'white';

                $pdate = date("d", strtotime($i));
                $timestamp = strtotime($i);
                $day = date('D', $timestamp);

                $getsord = mysqli_query($conn, "SELECT a.*, b.date FROM `visaent` a, pax b where a.vouchno = b.vouchno and a.date = '$i'  ") or die(mysqli_error($conn));

                $getnum = mysqli_num_rows($getsord);
                if ($getnum > 0) {
                    $bgcolor = 'lightyellow';
                }

                $ttot = 0;
                echo "<td style='background-color:$bgcolor'>";

                while ($fetsord = mysqli_fetch_array($getsord)) {
                    $nopax = $fetsord['nopax'];
                    $councode = $fetsord['country'];

                    $getcoun = mysqli_query($conn, "SELECT country from visamain where `code` = '$councode' ") or die(mysqli_error($conn));
                    $fetcoun = mysqli_fetch_array($getcoun);
                    $visadisp = 'Visa : ' . $fetcoun['country'];

                    $namedisp = ' Pax-' . $nopax ;

                    echo "<a href='fit_ent.php?vouchno=$fetsord[vouchno]&mode=edit' target='_blank' style='color:black'>$visadisp <span style='color:black;font-weight:bold'>$namedisp</span> </a><br>";

                    $ftot = $ftot + 1;
                    $fsat = $fsat + 1;
                    $montotal = $montotal + 1;
                }
                $ftot = 0;

                if ($ttot > 0) {
                    echo "<span style='color:maroon;font-size:16px;font-weight:bold;border-top:1px solid orange'>Total : $ftot</span>";
                }
                echo "</td>";

                if ($day == "Sat") {
                    echo "<td style='text-align:right;width:12%'><br><span  style='text-align:right; color:red;font-size:18px;font-weight:bold;'>Food - $fsat</span></td>";
                    $fsat = 0;
                }

                $mfrdate2 = date("Y-m-d", strtotime("+1 day", strtotime($mfrdate2)));
                $ctr2++;
                if ($ctr2 == 8) {
                    $ctr2 = 0;
                }

                if ($pdate >= $lastdt) {
                    for ($k = $ctr2; $k < 7; $k++) {
                        echo "<td style='width:12%'><br><span  style='text-align:right; color:red;font-size:18px;font-weight:bold;'>&nbsp;</span></td>";
                    }
                    echo "<td style='text-align:right;width:12%'><br><span  style='color:red;font-size:18px;font-weight:bold;'>Food - $fsat</span></td>";
                    $exit = 1;
                    break;
                }

            }
            echo "</tr>";
            if ($exit == 1) {
                break;
            }
        }
        echo "<tr>";
        echo "<td  colspan='7' style='text-align:right;color:purple;font-size:20px;font-weight:bold;border-top:1px solid green' >Month Total </td>";
        echo "<td  style='text-align:right;color:purple;font-size:20px;font-weight:bold;border-top:1px solid green' >$montotal</td>";
        echo "</tr>";
    }
}

?>

<style> 
    .dt{
        background-color: #64CCFC !important;
    }
</style>
