<?php $this->load->view('includes/head') ?>
<?php $this->load->view('includes/topbar') ?>
<?php $this->load->view('includes/header') ?>
<link rel="stylesheet" type="text/css" href="<?php echo base_url('assets/css/calendar.css'); ?>">
<style type="text/css">
    /* Ensures the modal is centered and responsive */
    .modal-dialog-centered {
        display: flex;
        align-items: center;
        min-height: calc(100% - 1rem);
    }

    .icon-box {
        max-width: 100px;
        max-height: 100px;
    }

    @media (max-width: 767.98px) {
        .modal-lg {
            max-width: 100%;
            margin: 1.75rem auto;
        }
    }


    .fc-scroller.fc-day-grid-container {
        overflow: visible !important;
        height: 100% !important;
    }

    input::placeholder {
        color: var(--main-color-new-theme);
    }


    @media only screen and (max-width: 443px) and (min-width: 200px) {
        .top {
            margin-top: 16px !important;

        }
    }

    @media screen and (max-width: 494px) and (min-width: 200px) {
        #Religiouscalendar .fc-day-number {
            background: unset !important;
            margin-top: -13px !important;
        }
    }
</style>

<main id="main">

    <div class="container py-5">
        <div class="d-flex" style="align-content: stretch; justify-content: space-between;">
            <button onclick="generatePDF()" class="btn btn-success top" style="margin-bottom: 21px; background: var(--main-color-new-theme); border: 1px solid white; padding: 10px 17px; border-radius: 10px!important; font-size: 17px; box-shadow: 1px 1px 10px #5e5e5e;">
                <i class="fa fa-download"></i> Yearly Calendar
            </button>
            <ul id="tabs" class="nav nav-tabs nav-fill" style="border: 0px; box-shadow: 1px -4px 8px grey; margin: 15px; padding: 0px;">
                <li class="nav-item"><a href="javaScript:void(0)" tab-name="calendar" data-toggle="tab" class="calendar-type nav-link <?= !isset($_GET['q']) ? 'active' : '' ?> rounded-0 border-0 m-0">Calendar</a></li>
                <li class="nav-item"><a href="javaScript:void(0)" tab-name="Religious" data-toggle="tab" class="calendar-type nav-link rounded-0 border-0 m-0 <?= isset($_GET['q']) ? 'active' : '' ?>">Panchangam</a></li>
            </ul>
        </div>
        <?php
        $header_data = getWebSyncsData('Header Settings', 'headerSettings', '');
        ?>

        <!-- Modal Event HTML -->
        <div id="modalevent" class="modal modal-lg fade " tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-lg modal-dialog-centered modal-confirm px-5">


                <div class="modal-content" style="background-image:url('<?php echo base_url("assets/img/63f8592dd5885.jpg") ?>');position: relative;background-size: contain;">


                    <div class="modal-header">
                        <img src="<?php echo $header_data[0]['leftImage'] ? ApiBaseUrl()['url'] . $header_data[0]['leftImage'] : base_url('assets/img/logo-1.png') ?>" class="icon-box">
                        <h4 class="modal-title w-100 btottomborder">Panchangam Details</h4>

                    </div>


                    <div class="modal-body p-0">
                        <table class="table table-responsive table-bordered mt-4" style="background: #ffffff3b;">
                            <tbody id="calendarEventDetails">
                            </tbody>
                        </table>
                    </div>


                    <div class="modal-footer p-0">
                        <button type="button" class="mx-auto d-block btn btn-secondary" data-bs-dismiss="modal">Close</button>
                    </div>
                </div>
            </div>
        </div>
        <!-- End Modal HTML -->


        <!-- PANCHANGAM Modal  -->
        <div id="modalpanchangam" class="modal modal-lg fade" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-lg modal-dialog-centered modal-confirm px-5">


                <div class="modal-content" style="background-image:url('<?php echo base_url("assets/img/63f8592dd5885.jpg") ?>');position: relative;background-size: contain;">


                    <div class="modal-header">
                        <img src="<?php echo $header_data[0]['leftImage'] ? ApiBaseUrl()['url'] . $header_data[0]['leftImage'] : base_url('assets/img/logo-1.png') ?>" class="icon-box">
                        <h4 class="modal-title w-100 bottomborder">Panchangam Details</h4>

                    </div>


                    <div class="modal-body p-0">
                        <table class="table table-responsive table-bordered mt-4" style="background: #ffffff3b;;">
                            <tbody id="calendarPnachangamDetails" style="text-align: center; text-shadow: 1px 2px 4px var(--main-color-new-theme)69;">

                            </tbody>
                        </table>
                    </div>
                    <div class="modal-footer p-0">
                        <button type="button" class="mx-auto d-block btn btn-secondary" data-bs-dismiss="modal">Close</button>
                    </div>
                </div>

            </div>
        </div>
        <!-- End PANCHANGAM modal -->


        <!-- Modal Event HTML -->
        <div id="modalcalenderservice" class="modal modal-lg fade " tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-lg modal-dialog-centered modal-confirm px-5">


                <div class="modal-content" style="background-image:url('<?php echo base_url("assets/img/63f8592dd5885.jpg") ?>');position: relative;background-size: contain;" id="modalcalenderserviceDetails">



                </div>
            </div>
        </div>
        <!-- End Modal HTML -->


        <!-- Modal Event HTML -->
        <div id="modalcalendersponser" class="modal modal-lg fade " tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-lg modal-dialog-centered modal-confirm px-5">


                <div class="modal-content" style="background-image:url('<?php echo base_url("assets/img/63f8592dd5885.jpg") ?>');position: relative;background-size: contain;" id="modalcalenderersponserDetails">



                </div>
            </div>
        </div>
        <!-- End Modal HTML -->


        <!-- Modal Event HTML -->
        <div id="modalcalenderevent" class="modal modal-lg fade " tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-lg modal-dialog-centered modal-confirm px-5">


                <div class="modal-content" style="background-image:url('<?php echo base_url("assets/img/63f8592dd5885.jpg") ?>');position: relative;background-size: contain;" id="modalcalendereventDetails">


                    <!-- <div class="modal-header">
						<img src="<?php echo $header_data[0]['leftImage'] ? ApiBaseUrl()['url'] . $header_data[0]['leftImage'] : base_url('assets/img/logo-1.png') ?>" class="icon-box">
						<h4 class="modal-title w-100 btottomborder">Event Details</h4>

					</div>


					<div class="modal-body p-0">
						<table class="table table-responsive table-bordered mt-4" style="background: #ffffff3b;">
							<tbody id="modalcalendereventDetails">
							</tbody>
						</table>
					</div>


					<div class="modal-footer p-0">
						<button type="button" class="mx-auto d-block btn btn-secondary" data-bs-dismiss="modal">Close</button>
						<button type="button" class="mx-auto d-block btn btn-secondary" data-bs-dismiss="modal">Add To Cart</button>
					</div> -->
                </div>
            </div>
        </div>
        <!-- End Modal HTML -->
        <div class="calendar" id="calendar">
        </div>
        <!-- <a id="downloadPdfBtn" class="btn btn-primary mx-auto d-block" href="<?= base_url('Home/sendPanchangaPdfMail') ?>">Download PDF</a> -->

        <div class="Religiouscalendar" id="Religiouscalendar">
        </div>

    </div>
</main>

<?php

$evereyArray = [
    'EVERY SUNDAY'    => 0,
    'SUNDAY'          => 0,
    'EVERY MONDAY'    => 1,
    'MONDAY'          => 1,
    'EVERY TUESDAY'   => 2,
    'TUESDAY'         => 2,
    'EVERY WEDNESDAY' => 3,
    'WEDNESDAY'       => 3,
    'EVERY THURSDAY'  => 4,
    'THURSDAY'        => 4,
    'EVERY FRIDAY'    => 5,
    'FRIDAY'          => 5,
    'EVERY SATURDAY'  => 6,
    'SATURDAY'        => 6,
    'EVERY DAY'       => '0, 1, 2, 3, 4, 5, 6',
    ''                => '',

];

$allowedTithis = ["PRATIPADA", "DWITIYA", "TRITIYA", "CHATURTHI", "PANCHAMI", "SHASHDI", "SAPTAMI", "ASHTAMI", "NAVAMI", "DASHAMI", "EKADASHI", "DWADASHI", "TRAYODASHI", "CHATURDASHI", "PURNIMA", "AMAVASYA"];
$PRATIPADADateArray = [];
$PRATIPADADateArray = getThithis("PRATIPADA");
$DWITIYADateArray = [];
$DWITIYADateArray = getThithis("DWITIYA");
$TRITIYADateArray = [];
$TRITIYADateArray =  getThithis("TRITIYA");
$CHATURTHIDateArray = [];
$CHATURTHIDateArray =  getThithis("CHATURTHI");
$PANCHAMIDateArray = [];
$PANCHAMIDateArray = getThithis("PANCHAMI");
$SHASHDIDateArray = [];
$SHASHDIDateArray =  getThithis("SHASHDI");
$SAPTAMIDateArray = [];
$SAPTAMIDateArray =  getThithis("SAPTAMI");
$NAVAMIDateArray = [];
$NAVAMIDateArray = getThithis("NAVAMI");
$DASHAMIDateArray = [];
$DASHAMIDateArray =  getThithis("DASHAMI");
$EKADASHIDateArray = [];
$EKADASHIDateArray =  getThithis("EKADASHI");
$DWADASHIDateArray =  [];
$DWADASHIDateArray = getThithis("DWADASHI");
$TRAYODASHIDateArray = [];
$TRAYODASHIDateArray =  getThithis("TRAYODASHI");
$CHATURDASHIDateArray = [];
$CHATURDASHIDateArray =  getThithis("CHATURDASHI");
$PURNIMADateArray = [];
$PURNIMADateArray =  getThithis("PURNIMA");
$AMAVASYADateArray = [];
$AMAVASYADateArray =  getThithis("AMAVASYA");
$ASHTAMIDateArray = [];
$ASHTAMIDateArray =  getThithis("ASHTAMI");
// var_dump($PURNIMADateArray);
$html  = '';
$html1 = '';
if (! empty($calendar_events)) {
    foreach ($calendar_events as $key => $value) {

        $html .= ' {';
        $html .= 'title:"' . trim($value['refDataName']) . '",';
        // $html .= 'url:"newpage.php/'.trim($value['_id']).'",';
        if (! empty($value['eventDate'])) {
            if (empty($value['startTime'])) {
                $html .= 'start: "' . (date('Y-m-d', strtotime($value['eventDate']))) . '",';
            } else {
                $html .= 'start: "' . (date('Y-m-d', strtotime($value['eventDate'])) . 'T' . date('H:i:s', strtotime($value['startTime']))) . '",';
            }
            if (empty($value['endTime'])) {
                $html .= 'end: "' . (date('Y-m-d', strtotime($value['eventDate']))) . '",';
            } else {
                $html .= 'end: "' . (date('Y-m-d', strtotime($value['eventDate'])) . 'T' . date('H:i:s', strtotime($value['endTime']))) . '",';
            }
        } else {

            $html .= 'start: "' . (date('H:i', strtotime($value['startTime']))) . '",';
            $html .= 'end: "' . (date('H:i', strtotime($value['endTime']))) . '",';
        }
        if (! empty($value['colour'])) {
            $html .= 'backgroundColor:"' . $value['colour'] . '",';
        }

        if (! empty($value['dayTypes'])) {
            $html .= 'dow:"[' . @$evereyArray[$value['dayTypes']] . ']",';
        }

        if (isset($value['eventLink']) && ! empty($value['eventLink'])) {
            $html .= 'c_eventLink:"' . @$value['eventLink'] . '",';
        }

        $html .= 'c_id:"' . @$value['_id'] . '",';
        $html .= 'c_refDataName:"' . camelCase(@$value['refDataName']) . '",';
        $html .= 'c_dayTypes:"' . camelCase(@$value['dayTypes']) . '",';
        $html .= 'c_eventDate:"' . @$value['eventDate'] . '",';
        $html .= 'c_startTime:"' . @$value['startTime'] . '",';
        $html .= 'c_endTime:"' . @$value['endTime'] . '",';
        $html .= 'c_colour:"' . @$value['colour'] . '",';
        $html .= 'c_moduleName:"' . @$value['moduleName'] . '",';
        $html .= 'c_clientID:"' . @$value['clientID'] . '",';
        $html .= 'c_productID:"' . @$value['productID'] . '",';
        $html .= 'c_aspectType:"' . @$value['aspectType'] . '",';
        $html .= 'c_recCreBy:"' . @$value['recCreBy'] . '",';
        $html .= 'c_recCreDate:"' . @$value['recCreDate'] . '",';
        $html .= 'c_recModBy:"' . @$value['recModBy'] . '",';
        $html .= 'c_recModDate:"' . @$value['recModDate'] . '",';

        $html .= ' },';
    }
}

// echo  '<pre>'; print_r($calender_services);

if (! empty($calender_services)) {

    foreach ($calender_services as $key => $value) {
        // var_dump($is_availibility_check = checkServiceAvailabilityObjectType(@$value->isAvailable, $value));die();
        // service_descs, serviceOccurrencesNos, fullPackages

        if (isset($value->serviceCategoryTypes) && $value->serviceCategoryTypes == 'IN-TEMPLE') {

            if (isset($value->serviceAmount) && (float) $value->serviceAmount > 0 && ! empty($value->serviceAmount)) {
                $is_availibility_check = checkServiceAvailabilityObjectType(@$value->isAvailable, $value);

                if (($is_availibility_check == 1 || $is_availibility_check == 2) || ($is_availibility_check == 3 && ! isset($value->AvailableCount) && $value->AvailableCount <= 0)) {
                    $is_availibility = "false";
                } else {
                    $is_availibility = "true";
                }

                $startDate = ! empty($value->startDate) ? date('Y-m-d', strtotime($value->startDate)) : null;
                $endDate   = ! empty($value->endDate) ? date('Y-m-d', strtotime($value->endDate)) : null;

                // Convert `dayTypes` (e.g., "Monday,Tuesday") into an array of day numbers (0 = Sunday, ..., 6 = Saturday)
                $allowedDays = [];
                if (! empty($value->dayTypes)) {
                    $dayNames = explode(',', $value->dayTypes); // Split the day names

                    foreach ($dayNames as $day) {
                        if (isset($evereyArray[trim($day)])) {
                            $allowedDays[] = $evereyArray[trim($day)];
                        }
                    }
                }

                $includeSankalpam = 'NO';
                if (isset($value->includeSankalpam) && $value->includeSankalpam == 'YES') {

                    $includeSankalpam = 'YES';
                }

                if (isset($value->Image) && ! empty($value->Image)) {
                    $src = ApiBaseUrl()['url'] . $value->Image;
                } else {
                    $src = base_url('assets/img/') . "logo.png";
                }

                if (isset($value->bookingType) && CheckEmptyNullVar($value->bookingType) != '') {

                    if ($value->bookingType == 'PAY NOW' && $value->serviceAmount > 0) {

                        $bookingType = 'PAY NOW';
                    } else if ($value->bookingType == 'PAY LATER' && $value->serviceAmount > 0) {
                        $bookingType = 'PAY LATER';
                    } else if ($value->bookingType == 'OPTIONAL' && $value->serviceAmount > 0) {
                        $bookingType = 'OPTIONAL';
                    } else {
                        $bookingType = 'PAY NOW';
                    }
                } else {
                    $bookingType = 'PAY NOW';
                }

                if ($bookingType === 'PAY NOW') {

                    $isServicePaid = "YES";
                } else if ($bookingType === 'PAY LATER') {
                    $isServicePaid = "NO";
                } else {

                    $isServicePaid = "YES";
                }
                if (isset($value->serviceOccurrencesNo) && $value->serviceOccurrencesNo > 0) {
                    $fullPackage = 'true';
                } else {
                    $fullPackage = 'false';
                }

                if (! empty($startDate) && ! empty($endDate)) {
                    // $currentDate = $startDate;
                    $currentDate = date('Y-m-d');
                    while (strtotime($currentDate) <= strtotime($endDate)) {
                        $currentDay = date('w', strtotime($currentDate)); // Get day of the week (0 = Sunday, ..., 6 = Saturday)
                        // if($value->refDataName=="Service Test Tithi"){
                        if (isset($value->dayTypes) && !empty($value->dayTypes)) {
                            if (@explode(" ", $value->dayTypes)[0] == "EVERY") {
                                $value->dayTypes = @explode(" ", $value->dayTypes)[1];
                            }
                        }
                        $dayVisible = false;
                        if (isset($value->dayTypes) && ! empty($value->dayTypes)) {

                            $dayVisible = false;

                            $startDateArray = [];
                            if (in_array($value->dayTypes, $allowedTithis)) {
                                if ($value->dayTypes == 'DWITIYA') {

                                    $startDateArray = $DWITIYADateArray;
                                } else if ($value->dayTypes == 'TRITIYA') {

                                    $startDateArray = $TRITIYADateArray;
                                } else if ($value->dayTypes == 'DWADASHI') {

                                    $startDateArray = $DWADASHIDateArray;
                                } else if ($value->dayTypes == 'SAPTAMI') {

                                    $startDateArray = $SAPTAMIDateArray;
                                } else if ($value->dayTypes == 'ASHTAMI') {

                                    $startDateArray = $ASHTAMIDateArray;
                                } else if ($value->dayTypes == 'PURNIMA') {

                                    $startDateArray = $PURNIMADateArray;
                                } else if ($value->dayTypes == 'PANCHAMI') {

                                    $startDateArray = $PANCHAMIDateArray;
                                } else if ($value->dayTypes == 'TRAYODASHI') {

                                    $startDateArray = $TRAYODASHIDateArray;
                                } else if ($value->dayTypes == 'PRATIPADA') {

                                    $startDateArray = $PRATIPADADateArray;
                                } else if ($value->dayTypes == 'AMAVASYA') {

                                    $startDateArray = $AMAVASYADateArray;
                                } else if ($value->dayTypes == 'SHASHDI') {

                                    $startDateArray = $SHASHDIDateArray;
                                } else if ($value->dayTypes == 'DASHAMI') {

                                    $startDateArray = $DASHAMIDateArray;
                                } else if ($value->dayTypes == 'EKADASHI') {

                                    $startDateArray = $EKADASHIDateArray;
                                } else if ($value->dayTypes == 'NAVAMI') {

                                    $startDateArray = $NAVAMIDateArray;
                                } else if ($value->dayTypes == 'CHATURTHI') {

                                    $startDateArray = $CHATURTHIDateArray;
                                } else {

                                    $startDateArray = $CHATURDASHIDateArray;
                                }
                            }

                            if ($value->dayTypes == getWeekday($currentDate)) {
                                // echo "<br>".$value->refDataName."/22<br>";
                                $dayVisible = true;
                            } else if (getWeekdayOccurrence($currentDate) == $value->dayTypes) {
                                // echo "<br>".$value->refDataName."/33<br>";
                                $dayVisible = true;
                            } else {
                                // echo "<br>".$value->refDataName."/44<br>";
                                if (!empty($startDateArray)) {
                                    $dateToCheck = date('Y-m-d', strtotime($currentDate));

                                    $dayVisible = in_array($dateToCheck, $startDateArray) && (strtotime($currentDate) >= strtotime(date('Y-m-d'))) && in_array($value->dayTypes, $allowedTithis);
                                }
                            }
                        } else if (! isset($value->dayTypes) && empty($value->dayTypes)) {
                            $dayVisible = true;
                        } else if (strtotime($currentDate) <= strtotime($endDate) && strtotime($currentDate) >= strtotime($endDate)) {
                            $dayVisible = true;
                        }

                        if ($dayVisible) {
                            // Create the event for the valid date
                            $html .= ' {';
                            $html .= 'title:"' . trim($value->refDataName) . '",';
                            $html .= 'start: "' . $currentDate;

                            if (! empty($value->startTime)) {
                                $html .= 'T' . date('H:i:s', strtotime($value->startTime));
                            }
                            $html .= '",';

                            $html .= 'end: "' . $currentDate;
                            if (! empty($value->endTime)) {
                                $html .= 'T' . date('H:i:s', strtotime($value->endTime));
                            }
                            $html .= '",';

                            $html .= 'backgroundColor:"#b02f73f2",';

                            $html .= 'c_id:"' . @$value->_id . '",';
                            $html .= 'c_refDataName:"' . camelCase(@$value->refDataName) . '",';
                            $html .= 'c_serviceAmount:"' . camelCase(@$value->serviceAmount) . '",';
                            $html .= 'c_dayTypes:"' . camelCase(@$value->dayTypes) . '",';
                            $html .= 'c_eventDate:"' . @$currentDate . '",';
                            $html .= 'c_startTime:"' . @$value->startTime . '",';
                            $html .= 'c_endTime:"' . @$value->endTime . '",';
                            $html .= 'c_colour:"' . @$value->colour . '",';
                            $html .= 'c_moduleName:"' . @$value->moduleName . '",';
                            $html .= 'c_clientID:"' . @$value->clientID . '",';
                            $html .= 'c_productID:"' . @$value->productID . '",';
                            $html .= 'c_aspectType:"' . @$value->aspectType . '",';
                            $html .= 'c_recCreBy:"' . @$value->recCreBy . '",';
                            $html .= 'c_recCreDate:"' . @$value->recCreDate . '",';
                            $html .= 'c_recModBy:"' . @$value->recModBy . '",';
                            $html .= 'c_recModDate:"' . @$value->recModDate . '",';
                            $html .= 'c_serviceCategoryTypes:"' . @$value->serviceCategoryTypes . '",';
                            $html .= 'c_serviceTypes:"' . @$value->serviceTypes . '",';
                            $html .= 'c_serviceOccurrencesNo:"' . @$value->serviceOccurrencesNo . '",';
                            $html .= 'c_includeSankalpam:"' . @$includeSankalpam . '",';
                            $html .= 'c_Image:"' . @$src . '",';
                            $html .= 'c_bookingType:"' . @$bookingType . '",';
                            $html .= 'c_is_availibility_check:"' . @$is_availibility . '",';
                            $html .= "c_description:'" . str_replace("'", "\'", @$value->description) . "',";
                            $html .= 'c_is_date_required:"' . @$value->isDTVisible . '",';
                            $html .= 'c_isServicePaid:"' . @$isServicePaid . '",';
                            $html .= 'c_membershipDiscount:"' . @$value->membershipDiscount . '",';
                            $html .= 'c_membership_discount_amt:"' . @$value->membershipAmount . '",';
                            $html .= 'c_fullPackage:"' . @$fullPackage . '",';
                            $html .= 'c_service_desc:"",';
                            $html .= ' },';
                        }
                        // }

                        $currentDate = date('Y-m-d', strtotime($currentDate . ' +1 day'));
                    }
                } else if (empty($startDate) && empty($endDate) && isset($value->dayTypes) && ! empty($value->dayTypes)) {

                    // Handle daily events when startDate and endDate are blank
                    $currentDate = date('Y-m-d');                         // Start from today
                    $endDate     = date('Y-m-d', strtotime('+365 days')); // Display for the next 30 days (or adjust as needed)

                    while (strtotime($currentDate) <= strtotime($endDate)) {
                        if (isset($value->dayTypes) && !empty($value->dayTypes)) {
                            if (@explode(" ", $value->dayTypes)[0] == "EVERY") {
                                $value->dayTypes = @explode(" ", $value->dayTypes)[1];
                            }
                        }
                        $dayVisible = false;
                        if (isset($value->dayTypes) && ! empty($value->dayTypes)) {

                            $dayVisible = false;
                            $startDateArray = [];
                            if (in_array($value->dayTypes, $allowedTithis)) {
                                if ($value->dayTypes == 'DWITIYA') {

                                    $startDateArray = $DWITIYADateArray;
                                } else if ($value->dayTypes == 'TRITIYA') {

                                    $startDateArray = $TRITIYADateArray;
                                } else if ($value->dayTypes == 'DWADASHI') {

                                    $startDateArray = $DWADASHIDateArray;
                                } else if ($value->dayTypes == 'SAPTAMI') {

                                    $startDateArray = $SAPTAMIDateArray;
                                } else if ($value->dayTypes == 'ASHTAMI') {

                                    $startDateArray = $ASHTAMIDateArray;
                                } else if ($value->dayTypes == 'PURNIMA') {

                                    $startDateArray = $PURNIMADateArray;
                                } else if ($value->dayTypes == 'PANCHAMI') {

                                    $startDateArray = $PANCHAMIDateArray;
                                } else if ($value->dayTypes == 'TRAYODASHI') {

                                    $startDateArray = $TRAYODASHIDateArray;
                                } else if ($value->dayTypes == 'PRATIPADA') {

                                    $startDateArray = $PRATIPADADateArray;
                                } else if ($value->dayTypes == 'AMAVASYA') {

                                    $startDateArray = $AMAVASYADateArray;
                                } else if ($value->dayTypes == 'SHASHDI') {

                                    $startDateArray = $SHASHDIDateArray;
                                } else if ($value->dayTypes == 'DASHAMI') {

                                    $startDateArray = $DASHAMIDateArray;
                                } else if ($value->dayTypes == 'EKADASHI') {

                                    $startDateArray = $EKADASHIDateArray;
                                } else if ($value->dayTypes == 'NAVAMI') {

                                    $startDateArray = $NAVAMIDateArray;
                                } else if ($value->dayTypes == 'CHATURTHI') {

                                    $startDateArray = $CHATURTHIDateArray;
                                } else {

                                    $startDateArray = $CHATURDASHIDateArray;
                                }
                            }

                            if ($value->dayTypes == getWeekday($currentDate)) {
                                // echo "<br>".$value->refDataName."/22<br>";
                                $dayVisible = true;
                            } else if (getWeekdayOccurrence($currentDate) == $value->dayTypes) {
                                // echo "<br>".$value->refDataName."/33<br>";
                                $dayVisible = true;
                            } else {
                                // echo "<br>".$value->refDataName."/44<br>";
                                if (! empty($startDateArray)) {
                                    $dateToCheck = date('Y-m-d', strtotime($currentDate));

                                    $dayVisible = in_array($dateToCheck, $startDateArray) && (strtotime($currentDate) >= strtotime(date('Y-m-d'))) && in_array($value->dayTypes, $allowedTithis);
                                }
                            }
                        } else if (! isset($value->dayTypes) && empty($value->dayTypes)) {
                            $dayVisible = true;
                        } else if (strtotime($currentDate) <= strtotime($endDate) && strtotime($currentDate) >= strtotime($endDate)) {
                            $dayVisible = true;
                        }

                        if ($dayVisible) {

                            // Create daily event
                            $html .= ' {';
                            $html .= 'title:"' . trim($value->refDataName) . '",';
                            $html .= 'start: "' . $currentDate;

                            if (! empty($value->startTime)) {
                                $html .= 'T' . date('H:i:s', strtotime($value->startTime));
                            }
                            $html .= '",';

                            $html .= 'end: "' . $currentDate;
                            if (! empty($value->endTime)) {
                                $html .= 'T' . date('H:i:s', strtotime($value->endTime));
                            }
                            $html .= '",';

                            $html .= 'backgroundColor:"#b02f73f2",';

                            $html .= 'c_id:"' . @$value->_id . '",';
                            $html .= 'c_refDataName:"' . camelCase(@$value->refDataName) . '",';
                            $html .= 'c_serviceAmount:"' . camelCase(@$value->serviceAmount) . '",';
                            $html .= 'c_dayTypes:"' . camelCase(@$value->dayTypes) . '",';
                            $html .= 'c_eventDate:"' . @$currentDate . '",';
                            $html .= 'c_startTime:"' . @$value->startTime . '",';
                            $html .= 'c_endTime:"' . @$value->endTime . '",';
                            $html .= 'c_colour:"' . @$value->colour . '",';
                            $html .= 'c_moduleName:"' . @$value->moduleName . '",';
                            $html .= 'c_clientID:"' . @$value->clientID . '",';
                            $html .= 'c_productID:"' . @$value->productID . '",';
                            $html .= 'c_aspectType:"' . @$value->aspectType . '",';
                            $html .= 'c_recCreBy:"' . @$value->recCreBy . '",';
                            $html .= 'c_recCreDate:"' . @$value->recCreDate . '",';
                            $html .= 'c_recModBy:"' . @$value->recModBy . '",';
                            $html .= 'c_recModDate:"' . @$value->recModDate . '",';
                            $html .= 'c_serviceCategoryTypes:"' . @$value->serviceCategoryTypes . '",';
                            $html .= 'c_serviceTypes:"' . @$value->serviceTypes . '",';
                            $html .= 'c_serviceOccurrencesNo:"' . @$value->serviceOccurrencesNo . '",';
                            $html .= 'c_includeSankalpam:"' . @$includeSankalpam . '",';
                            $html .= 'c_Image:"' . @$src . '",';
                            $html .= 'c_bookingType:"' . @$bookingType . '",';
                            $html .= 'c_is_availibility_check:"' . @$is_availibility . '",';
                            $html .= "c_description:'" . str_replace("'", "\'", @$value->description) . "',";
                            $html .= 'c_is_date_required:"' . @$value->isDTVisible . '",';
                            $html .= 'c_isServicePaid:"' . @$isServicePaid . '",';
                            $html .= 'c_membershipDiscount:"' . @$value->membershipDiscount . '",';
                            $html .= 'c_membership_discount_amt:"' . @$value->membershipAmount . '",';
                            $html .= 'c_fullPackage:"' . @$fullPackage . '",';
                            $html .= 'c_service_desc:"",';
                            $html .= ' },';
                        }
                        $currentDate = date('Y-m-d', strtotime($currentDate . ' +1 day'));
                    }
                } else if (empty($startDate) && empty($endDate)) {

                    // Handle daily events when startDate and endDate are blank
                    $currentDate = date('Y-m-d');                         // Start from today
                    $endDate     = date('Y-m-d', strtotime('+365 days')); // Display for the next 30 days (or adjust as needed)

                    while (strtotime($currentDate) <= strtotime($endDate)) {
                        $dayVisible = false;
                        if (isset($value->dayTypes) && !empty($value->dayTypes)) {
                            if (@explode(" ", $value->dayTypes)[0] == "EVERY") {
                                $value->dayTypes = @explode(" ", $value->dayTypes)[1];
                            }
                        }
                        if (isset($value->dayTypes) && ! empty($value->dayTypes)) {

                            $dayVisible = false;

                            $startDateArray = [];
                            if (in_array($value->dayTypes, $allowedTithis)) {
                                if ($value->dayTypes == 'DWITIYA') {

                                    $startDateArray = $DWITIYADateArray;
                                } else if ($value->dayTypes == 'TRITIYA') {

                                    $startDateArray = $TRITIYADateArray;
                                } else if ($value->dayTypes == 'DWADASHI') {

                                    $startDateArray = $DWADASHIDateArray;
                                } else if ($value->dayTypes == 'SAPTAMI') {

                                    $startDateArray = $SAPTAMIDateArray;
                                } else if ($value->dayTypes == 'ASHTAMI') {

                                    $startDateArray = $ASHTAMIDateArray;
                                } else if ($value->dayTypes == 'PURNIMA') {

                                    $startDateArray = $PURNIMADateArray;
                                } else if ($value->dayTypes == 'PANCHAMI') {

                                    $startDateArray = $PANCHAMIDateArray;
                                } else if ($value->dayTypes == 'TRAYODASHI') {

                                    $startDateArray = $TRAYODASHIDateArray;
                                } else if ($value->dayTypes == 'PRATIPADA') {

                                    $startDateArray = $PRATIPADADateArray;
                                } else if ($value->dayTypes == 'AMAVASYA') {

                                    $startDateArray = $AMAVASYADateArray;
                                } else if ($value->dayTypes == 'SHASHDI') {

                                    $startDateArray = $SHASHDIDateArray;
                                } else if ($value->dayTypes == 'DASHAMI') {

                                    $startDateArray = $DASHAMIDateArray;
                                } else if ($value->dayTypes == 'EKADASHI') {

                                    $startDateArray = $EKADASHIDateArray;
                                } else if ($value->dayTypes == 'NAVAMI') {

                                    $startDateArray = $NAVAMIDateArray;
                                } else if ($value->dayTypes == 'CHATURTHI') {

                                    $startDateArray = $CHATURTHIDateArray;
                                } else {

                                    $startDateArray = $CHATURDASHIDateArray;
                                }
                            }

                            if ($value->dayTypes == getWeekday($currentDate)) {
                                // echo "<br>".$value->refDataName."/22<br>";
                                $dayVisible = true;
                            } else if (getWeekdayOccurrence($currentDate) == $value->dayTypes) {
                                // echo "<br>".$value->refDataName."/33<br>";
                                $dayVisible = true;
                            } else {
                                // echo "<br>".$value->refDataName."/44<br>";
                                if (! empty($startDateArray)) {
                                    $dateToCheck = date('Y-m-d', strtotime($currentDate));

                                    $dayVisible = in_array($dateToCheck, $startDateArray) && (strtotime($currentDate) >= strtotime(date('Y-m-d'))) && in_array($value->dayTypes, $allowedTithis);
                                }
                            }
                        } else if (! isset($value->dayTypes) && empty($value->dayTypes)) {
                            $dayVisible = true;
                        } else if (strtotime($currentDate) <= strtotime($endDate) && strtotime($currentDate) >= strtotime($endDate)) {
                            $dayVisible = true;
                        }

                        if ($dayVisible) {

                            $html .= ' {';
                            $html .= 'title:"' . trim($value->refDataName) . '",';
                            $html .= 'start: "' . $currentDate;

                            if (! empty($value->startTime)) {
                                $html .= 'T' . date('H:i:s', strtotime($value->startTime));
                            }
                            $html .= '",';

                            $html .= 'end: "' . $currentDate;
                            if (! empty($value->endTime)) {
                                $html .= 'T' . date('H:i:s', strtotime($value->endTime));
                            }
                            $html .= '",';

                            $html .= 'backgroundColor:"#b02f73f2",';

                            $html .= 'c_id:"' . @$value->_id . '",';
                            $html .= 'c_refDataName:"' . camelCase(@$value->refDataName) . '",';
                            $html .= 'c_serviceAmount:"' . camelCase(@$value->serviceAmount) . '",';
                            $html .= 'c_dayTypes:"' . camelCase(@$value->dayTypes) . '",';
                            $html .= 'c_eventDate:"' . @$currentDate . '",';
                            $html .= 'c_startTime:"' . @$value->startTime . '",';
                            $html .= 'c_endTime:"' . @$value->endTime . '",';
                            $html .= 'c_colour:"' . @$value->colour . '",';
                            $html .= 'c_moduleName:"' . @$value->moduleName . '",';
                            $html .= 'c_clientID:"' . @$value->clientID . '",';
                            $html .= 'c_productID:"' . @$value->productID . '",';
                            $html .= 'c_aspectType:"' . @$value->aspectType . '",';
                            $html .= 'c_recCreBy:"' . @$value->recCreBy . '",';
                            $html .= 'c_recCreDate:"' . @$value->recCreDate . '",';
                            $html .= 'c_recModBy:"' . @$value->recModBy . '",';
                            $html .= 'c_recModDate:"' . @$value->recModDate . '",';
                            $html .= 'c_serviceCategoryTypes:"' . @$value->serviceCategoryTypes . '",';
                            $html .= 'c_serviceTypes:"' . @$value->serviceTypes . '",';
                            $html .= 'c_serviceOccurrencesNo:"' . @$value->serviceOccurrencesNo . '",';
                            $html .= 'c_includeSankalpam:"' . @$includeSankalpam . '",';
                            $html .= 'c_Image:"' . @$src . '",';
                            $html .= 'c_bookingType:"' . @$bookingType . '",';
                            $html .= 'c_is_availibility_check:"' . @$is_availibility . '",';
                            $html .= "c_description:'" . str_replace("'", "\'", @$value->description) . "',";
                            $html .= 'c_is_date_required:"' . @$value->isDTVisible . '",';
                            $html .= 'c_isServicePaid:"' . @$isServicePaid . '",';
                            $html .= 'c_membershipDiscount:"' . @$value->membershipDiscount . '",';
                            $html .= 'c_membership_discount_amt:"' . @$value->membershipAmount . '",';
                            $html .= 'c_fullPackage:"' . @$fullPackage . '",';
                            $html .= 'c_service_desc:"",';
                            $html .= ' },';
                        }
                        $currentDate = date('Y-m-d', strtotime($currentDate . ' +1 day'));
                    }
                }
            }
        } else if (isset($value->serviceCategoryTypes) && $value->serviceCategoryTypes == 'SPONSORSHIP') {
            if (isset($value->serviceAmount) && (float) $value->serviceAmount > 0 && ! empty($value->serviceAmount)) {
                $is_availibility_check = checkServiceAvailabilityObjectType(@$value->isAvailable, $value);

                if (($is_availibility_check == 1 || $is_availibility_check == 2) || ($is_availibility_check == 3 && ! isset($value->AvailableCount) && $value->AvailableCount <= 0)) {
                    $is_availibility = "false";
                } else {
                    $is_availibility = "true";
                }

                $startDate = ! empty($value->startDate) ? date('Y-m-d', strtotime($value->startDate)) : null;
                $endDate   = ! empty($value->endDate) ? date('Y-m-d', strtotime($value->endDate)) : null;

                // Convert `dayTypes` (e.g., "Monday,Tuesday") into an array of day numbers (0 = Sunday, ..., 6 = Saturday)
                $allowedDays = [];
                if (! empty($value->dayTypes)) {
                    $dayNames = explode(',', $value->dayTypes); // Split the day names

                    foreach ($dayNames as $day) {
                        if (isset($evereyArray[trim($day)])) {
                            $allowedDays[] = $evereyArray[trim($day)];
                        }
                    }
                }

                $includeSankalpam = 'NO';
                if (isset($value->includeSankalpam) && $value->includeSankalpam == 'YES') {

                    $includeSankalpam = 'YES';
                }

                if (isset($value->Image) && ! empty($value->Image)) {
                    $src = ApiBaseUrl()['url'] . $value->Image;
                } else {
                    $src = base_url('assets/img/') . "logo.png";
                }

                if (isset($value->bookingType) && CheckEmptyNullVar($value->bookingType) != '') {

                    if ($value->bookingType == 'PAY NOW' && $value->serviceAmount > 0) {

                        $bookingType = 'PAY NOW';
                    } else if ($value->bookingType == 'PAY LATER' && $value->serviceAmount > 0) {
                        $bookingType = 'PAY LATER';
                    } else if ($value->bookingType == 'OPTIONAL' && $value->serviceAmount > 0) {
                        $bookingType = 'OPTIONAL';
                    } else {
                        $bookingType = 'PAY NOW';
                    }
                } else {
                    $bookingType = 'PAY NOW';
                }

                if ($bookingType === 'PAY NOW') {

                    $isServicePaid = "YES";
                } else if ($bookingType === 'PAY LATER') {
                    $isServicePaid = "NO";
                } else {

                    $isServicePaid = "YES";
                }
                if (isset($value->serviceOccurrencesNo) && $value->serviceOccurrencesNo > 0) {
                    $fullPackage = 'true';
                } else {
                    $fullPackage = 'false';
                }

                if (! empty($startDate) && ! empty($endDate)) {
                    // $currentDate = $startDate;
                    $currentDate = date('Y-m-d');
                    while (strtotime($currentDate) <= strtotime($endDate)) {
                        $currentDay = date('w', strtotime($currentDate)); // Get day of the week (0 = Sunday, ..., 6 = Saturday)
                        // if($value->refDataName=="Service Test Tithi"){

                        $dayVisible = false;
                        if (isset($value->dayTypes) && !empty($value->dayTypes)) {
                            if (@explode(" ", $value->dayTypes)[0] == "EVERY") {
                                $value->dayTypes = @explode(" ", $value->dayTypes)[1];
                            }
                        }
                        if (isset($value->dayTypes) && ! empty($value->dayTypes)) {

                            $dayVisible = false;

                            $startDateArray = [];
                            if (in_array($value->dayTypes, $allowedTithis)) {
                                if ($value->dayTypes == 'DWITIYA') {

                                    $startDateArray = $DWITIYADateArray;
                                } else if ($value->dayTypes == 'TRITIYA') {

                                    $startDateArray = $TRITIYADateArray;
                                } else if ($value->dayTypes == 'DWADASHI') {

                                    $startDateArray = $DWADASHIDateArray;
                                } else if ($value->dayTypes == 'SAPTAMI') {

                                    $startDateArray = $SAPTAMIDateArray;
                                } else if ($value->dayTypes == 'ASHTAMI') {

                                    $startDateArray = $ASHTAMIDateArray;
                                } else if ($value->dayTypes == 'PURNIMA') {

                                    $startDateArray = $PURNIMADateArray;
                                } else if ($value->dayTypes == 'PANCHAMI') {

                                    $startDateArray = $PANCHAMIDateArray;
                                } else if ($value->dayTypes == 'TRAYODASHI') {

                                    $startDateArray = $TRAYODASHIDateArray;
                                } else if ($value->dayTypes == 'PRATIPADA') {

                                    $startDateArray = $PRATIPADADateArray;
                                } else if ($value->dayTypes == 'AMAVASYA') {

                                    $startDateArray = $AMAVASYADateArray;
                                } else if ($value->dayTypes == 'SHASHDI') {

                                    $startDateArray = $SHASHDIDateArray;
                                } else if ($value->dayTypes == 'DASHAMI') {

                                    $startDateArray = $DASHAMIDateArray;
                                } else if ($value->dayTypes == 'EKADASHI') {

                                    $startDateArray = $EKADASHIDateArray;
                                } else if ($value->dayTypes == 'NAVAMI') {

                                    $startDateArray = $NAVAMIDateArray;
                                } else if ($value->dayTypes == 'CHATURTHI') {

                                    $startDateArray = $CHATURTHIDateArray;
                                } else {

                                    $startDateArray = $CHATURDASHIDateArray;
                                }
                            }
                            if ($value->dayTypes == getWeekday($currentDate)) {
                                // echo "<br>".$value->refDataName."/22<br>";
                                $dayVisible = true;
                            } else if (getWeekdayOccurrence($currentDate) == $value->dayTypes) {
                                // echo "<br>".$value->refDataName."/33<br>";
                                $dayVisible = true;
                            } else {
                                // echo "<br>".$value->refDataName."/44<br>";
                                if (! empty($startDateArray)) {
                                    $dateToCheck = date('Y-m-d', strtotime($currentDate));

                                    $dayVisible = in_array($dateToCheck, $startDateArray) && (strtotime($currentDate) >= strtotime(date('Y-m-d'))) && in_array($value->dayTypes, $allowedTithis);
                                }
                            }
                        } else if (! isset($value->dayTypes) && empty($value->dayTypes)) {
                            $dayVisible = true;
                        } else if (strtotime($currentDate) <= strtotime($endDate) && strtotime($currentDate) >= strtotime($endDate)) {
                            $dayVisible = true;
                        }

                        if ($dayVisible) {
                            // Create the event for the valid date
                            $html .= ' {';
                            $html .= 'title:"' . trim($value->refDataName) . '",';
                            $html .= 'start: "' . $currentDate;

                            if (! empty($value->startTime)) {
                                $html .= 'T' . date('H:i:s', strtotime($value->startTime));
                            }
                            $html .= '",';

                            $html .= 'end: "' . $currentDate;
                            if (! empty($value->endTime)) {
                                $html .= 'T' . date('H:i:s', strtotime($value->endTime));
                            }
                            $html .= '",';

                            $html .= 'backgroundColor:"#b02f73f2",';

                            $html .= 'c_id:"' . @$value->_id . '",';
                            $html .= 'c_refDataName:"' . camelCase(@$value->refDataName) . '",';
                            $html .= 'c_serviceAmount:"' . camelCase(@$value->serviceAmount) . '",';
                            $html .= 'c_dayTypes:"' . camelCase(@$value->dayTypes) . '",';
                            $html .= 'c_eventDate:"' . @$currentDate . '",';
                            $html .= 'c_startTime:"' . @$value->startTime . '",';
                            $html .= 'c_endTime:"' . @$value->endTime . '",';
                            $html .= 'c_colour:"' . @$value->colour . '",';
                            $html .= 'c_moduleName:"' . @$value->moduleName . '",';
                            $html .= 'c_clientID:"' . @$value->clientID . '",';
                            $html .= 'c_productID:"' . @$value->productID . '",';
                            $html .= 'c_aspectType:"' . @$value->aspectType . '",';
                            $html .= 'c_recCreBy:"' . @$value->recCreBy . '",';
                            $html .= 'c_recCreDate:"' . @$value->recCreDate . '",';
                            $html .= 'c_recModBy:"' . @$value->recModBy . '",';
                            $html .= 'c_recModDate:"' . @$value->recModDate . '",';
                            $html .= 'c_serviceCategoryTypes:"' . @$value->serviceCategoryTypes . '",';
                            $html .= 'c_serviceTypes:"' . @$value->serviceTypes . '",';
                            $html .= 'c_serviceOccurrencesNo:"' . @$value->serviceOccurrencesNo . '",';
                            $html .= 'c_includeSankalpam:"' . @$includeSankalpam . '",';
                            $html .= 'c_Image:"' . @$src . '",';
                            $html .= 'c_bookingType:"' . @$bookingType . '",';
                            $html .= 'c_is_availibility_check:"' . @$is_availibility . '",';
                            $html .= "c_description:'" . str_replace("'", "\'", @$value->description) . "',";
                            $html .= 'c_is_date_required:"' . @$value->isDTVisible . '",';
                            $html .= 'c_isServicePaid:"' . @$isServicePaid . '",';
                            $html .= 'c_membershipDiscount:"' . @$value->membershipDiscount . '",';
                            $html .= 'c_membership_discount_amt:"' . @$value->membershipAmount . '",';
                            $html .= 'c_fullPackage:"' . @$fullPackage . '",';
                            $html .= 'c_service_desc:"",';
                            $html .= ' },';
                        }
                        // }

                        $currentDate = date('Y-m-d', strtotime($currentDate . ' +1 day'));
                    }
                } else if (empty($startDate) && empty($endDate) && isset($value->dayTypes) && ! empty($value->dayTypes)) {

                    // Handle daily events when startDate and endDate are blank
                    $currentDate = date('Y-m-d');                         // Start from today
                    $endDate     = date('Y-m-d', strtotime('+365 days')); // Display for the next 30 days (or adjust as needed)

                    while (strtotime($currentDate) <= strtotime($endDate)) {

                        $dayVisible = false;
                        if (isset($value->dayTypes) && !empty($value->dayTypes)) {
                            if (@explode(" ", $value->dayTypes)[0] == "EVERY") {
                                $value->dayTypes = @explode(" ", $value->dayTypes)[1];
                            }
                        }
                        if (isset($value->dayTypes) && ! empty($value->dayTypes)) {

                            $dayVisible = false;

                            $startDateArray = [];
                            if (in_array($value->dayTypes, $allowedTithis)) {
                                if ($value->dayTypes == 'DWITIYA') {

                                    $startDateArray = $DWITIYADateArray;
                                } else if ($value->dayTypes == 'TRITIYA') {

                                    $startDateArray = $TRITIYADateArray;
                                } else if ($value->dayTypes == 'DWADASHI') {

                                    $startDateArray = $DWADASHIDateArray;
                                } else if ($value->dayTypes == 'SAPTAMI') {

                                    $startDateArray = $SAPTAMIDateArray;
                                } else if ($value->dayTypes == 'ASHTAMI') {

                                    $startDateArray = $ASHTAMIDateArray;
                                } else if ($value->dayTypes == 'PURNIMA') {

                                    $startDateArray = $PURNIMADateArray;
                                } else if ($value->dayTypes == 'PANCHAMI') {

                                    $startDateArray = $PANCHAMIDateArray;
                                } else if ($value->dayTypes == 'TRAYODASHI') {

                                    $startDateArray = $TRAYODASHIDateArray;
                                } else if ($value->dayTypes == 'PRATIPADA') {

                                    $startDateArray = $PRATIPADADateArray;
                                } else if ($value->dayTypes == 'AMAVASYA') {

                                    $startDateArray = $AMAVASYADateArray;
                                } else if ($value->dayTypes == 'SHASHDI') {

                                    $startDateArray = $SHASHDIDateArray;
                                } else if ($value->dayTypes == 'DASHAMI') {

                                    $startDateArray = $DASHAMIDateArray;
                                } else if ($value->dayTypes == 'EKADASHI') {

                                    $startDateArray = $EKADASHIDateArray;
                                } else if ($value->dayTypes == 'NAVAMI') {

                                    $startDateArray = $NAVAMIDateArray;
                                } else if ($value->dayTypes == 'CHATURTHI') {

                                    $startDateArray = $CHATURTHIDateArray;
                                } else {

                                    $startDateArray = $CHATURDASHIDateArray;
                                }
                            }

                            if ($value->dayTypes == getWeekday($currentDate)) {
                                // echo "<br>".$value->refDataName."/22<br>";
                                $dayVisible = true;
                            } else if (getWeekdayOccurrence($currentDate) == $value->dayTypes) {
                                // echo "<br>".$value->refDataName."/33<br>";
                                $dayVisible = true;
                            } else {
                                // echo "<br>".$value->refDataName."/44<br>";
                                if (! empty($startDateArray)) {
                                    $dateToCheck = date('Y-m-d', strtotime($currentDate));

                                    $dayVisible = in_array($dateToCheck, $startDateArray) && (strtotime($currentDate) >= strtotime(date('Y-m-d'))) && in_array($value->dayTypes, $allowedTithis);
                                }
                            }
                        } else if (! isset($value->dayTypes) && empty($value->dayTypes)) {
                            $dayVisible = true;
                        } else if (strtotime($currentDate) <= strtotime($endDate) && strtotime($currentDate) >= strtotime($endDate)) {
                            $dayVisible = true;
                        }

                        if ($dayVisible) {

                            // Create daily event
                            $html .= ' {';
                            $html .= 'title:"' . trim($value->refDataName) . '",';
                            $html .= 'start: "' . $currentDate;

                            if (! empty($value->startTime)) {
                                $html .= 'T' . date('H:i:s', strtotime($value->startTime));
                            }
                            $html .= '",';

                            $html .= 'end: "' . $currentDate;
                            if (! empty($value->endTime)) {
                                $html .= 'T' . date('H:i:s', strtotime($value->endTime));
                            }
                            $html .= '",';

                            $html .= 'backgroundColor:"#b02f73f2",';

                            $html .= 'c_id:"' . @$value->_id . '",';
                            $html .= 'c_refDataName:"' . camelCase(@$value->refDataName) . '",';
                            $html .= 'c_serviceAmount:"' . camelCase(@$value->serviceAmount) . '",';
                            $html .= 'c_dayTypes:"' . camelCase(@$value->dayTypes) . '",';
                            $html .= 'c_eventDate:"' . @$currentDate . '",';
                            $html .= 'c_startTime:"' . @$value->startTime . '",';
                            $html .= 'c_endTime:"' . @$value->endTime . '",';
                            $html .= 'c_colour:"' . @$value->colour . '",';
                            $html .= 'c_moduleName:"' . @$value->moduleName . '",';
                            $html .= 'c_clientID:"' . @$value->clientID . '",';
                            $html .= 'c_productID:"' . @$value->productID . '",';
                            $html .= 'c_aspectType:"' . @$value->aspectType . '",';
                            $html .= 'c_recCreBy:"' . @$value->recCreBy . '",';
                            $html .= 'c_recCreDate:"' . @$value->recCreDate . '",';
                            $html .= 'c_recModBy:"' . @$value->recModBy . '",';
                            $html .= 'c_recModDate:"' . @$value->recModDate . '",';
                            $html .= 'c_serviceCategoryTypes:"' . @$value->serviceCategoryTypes . '",';
                            $html .= 'c_serviceTypes:"' . @$value->serviceTypes . '",';
                            $html .= 'c_serviceOccurrencesNo:"' . @$value->serviceOccurrencesNo . '",';
                            $html .= 'c_includeSankalpam:"' . @$includeSankalpam . '",';
                            $html .= 'c_Image:"' . @$src . '",';
                            $html .= 'c_bookingType:"' . @$bookingType . '",';
                            $html .= 'c_is_availibility_check:"' . @$is_availibility . '",';
                            $html .= "c_description:'" . str_replace("'", "\'", @$value->description) . "',";
                            $html .= 'c_is_date_required:"' . @$value->isDTVisible . '",';
                            $html .= 'c_isServicePaid:"' . @$isServicePaid . '",';
                            $html .= 'c_membershipDiscount:"' . @$value->membershipDiscount . '",';
                            $html .= 'c_membership_discount_amt:"' . @$value->membershipAmount . '",';
                            $html .= 'c_fullPackage:"' . @$fullPackage . '",';
                            $html .= 'c_service_desc:"",';
                            $html .= ' },';
                        }
                        $currentDate = date('Y-m-d', strtotime($currentDate . ' +1 day'));
                    }
                } else if (empty($startDate) && empty($endDate)) {

                    // Handle daily events when startDate and endDate are blank
                    $currentDate = date('Y-m-d');                         // Start from today
                    $endDate     = date('Y-m-d', strtotime('+365 days')); // Display for the next 30 days (or adjust as needed)

                    while (strtotime($currentDate) <= strtotime($endDate)) {
                        $dayVisible = false;
                        if (isset($value->dayTypes) && !empty($value->dayTypes)) {
                            if (@explode(" ", $value->dayTypes)[0] == "EVERY") {
                                $value->dayTypes = @explode(" ", $value->dayTypes)[1];
                            }
                        }
                        if (isset($value->dayTypes) && ! empty($value->dayTypes)) {

                            $dayVisible = false;

                            $startDateArray = [];
                            if (in_array($value->dayTypes, $allowedTithis)) {
                                if ($value->dayTypes == 'DWITIYA') {

                                    $startDateArray = $DWITIYADateArray;
                                } else if ($value->dayTypes == 'TRITIYA') {

                                    $startDateArray = $TRITIYADateArray;
                                } else if ($value->dayTypes == 'DWADASHI') {

                                    $startDateArray = $DWADASHIDateArray;
                                } else if ($value->dayTypes == 'SAPTAMI') {

                                    $startDateArray = $SAPTAMIDateArray;
                                } else if ($value->dayTypes == 'ASHTAMI') {

                                    $startDateArray = $ASHTAMIDateArray;
                                } else if ($value->dayTypes == 'PURNIMA') {

                                    $startDateArray = $PURNIMADateArray;
                                } else if ($value->dayTypes == 'PANCHAMI') {

                                    $startDateArray = $PANCHAMIDateArray;
                                } else if ($value->dayTypes == 'TRAYODASHI') {

                                    $startDateArray = $TRAYODASHIDateArray;
                                } else if ($value->dayTypes == 'PRATIPADA') {

                                    $startDateArray = $PRATIPADADateArray;
                                } else if ($value->dayTypes == 'AMAVASYA') {

                                    $startDateArray = $AMAVASYADateArray;
                                } else if ($value->dayTypes == 'SHASHDI') {

                                    $startDateArray = $SHASHDIDateArray;
                                } else if ($value->dayTypes == 'DASHAMI') {

                                    $startDateArray = $DASHAMIDateArray;
                                } else if ($value->dayTypes == 'EKADASHI') {

                                    $startDateArray = $EKADASHIDateArray;
                                } else if ($value->dayTypes == 'NAVAMI') {

                                    $startDateArray = $NAVAMIDateArray;
                                } else if ($value->dayTypes == 'CHATURTHI') {

                                    $startDateArray = $CHATURTHIDateArray;
                                } else {

                                    $startDateArray = $CHATURDASHIDateArray;
                                }
                            }
                            if ($value->dayTypes == getWeekday($currentDate)) {
                                // echo "<br>".$value->refDataName."/22<br>";
                                $dayVisible = true;
                            } else if (getWeekdayOccurrence($currentDate) == $value->dayTypes) {
                                // echo "<br>".$value->refDataName."/33<br>";
                                $dayVisible = true;
                            } else {
                                // echo "<br>".$value->refDataName."/44<br>";
                                if (! empty($startDateArray)) {
                                    $dateToCheck = date('Y-m-d', strtotime($currentDate));

                                    $dayVisible = in_array($dateToCheck, $startDateArray) && (strtotime($currentDate) >= strtotime(date('Y-m-d'))) && in_array($value->dayTypes, $allowedTithis);
                                }
                            }
                        } else if (! isset($value->dayTypes) && empty($value->dayTypes)) {
                            $dayVisible = true;
                        } else if (strtotime($currentDate) <= strtotime($endDate) && strtotime($currentDate) >= strtotime($endDate)) {
                            $dayVisible = true;
                        }

                        if ($dayVisible) {

                            $html .= ' {';
                            $html .= 'title:"' . trim($value->refDataName) . '",';
                            $html .= 'start: "' . $currentDate;

                            if (! empty($value->startTime)) {
                                $html .= 'T' . date('H:i:s', strtotime($value->startTime));
                            }
                            $html .= '",';

                            $html .= 'end: "' . $currentDate;
                            if (! empty($value->endTime)) {
                                $html .= 'T' . date('H:i:s', strtotime($value->endTime));
                            }
                            $html .= '",';

                            $html .= 'backgroundColor:"#b02f73f2",';

                            $html .= 'c_id:"' . @$value->_id . '",';
                            $html .= 'c_refDataName:"' . camelCase(@$value->refDataName) . '",';
                            $html .= 'c_serviceAmount:"' . camelCase(@$value->serviceAmount) . '",';
                            $html .= 'c_dayTypes:"' . camelCase(@$value->dayTypes) . '",';
                            $html .= 'c_eventDate:"' . @$currentDate . '",';
                            $html .= 'c_startTime:"' . @$value->startTime . '",';
                            $html .= 'c_endTime:"' . @$value->endTime . '",';
                            $html .= 'c_colour:"' . @$value->colour . '",';
                            $html .= 'c_moduleName:"' . @$value->moduleName . '",';
                            $html .= 'c_clientID:"' . @$value->clientID . '",';
                            $html .= 'c_productID:"' . @$value->productID . '",';
                            $html .= 'c_aspectType:"' . @$value->aspectType . '",';
                            $html .= 'c_recCreBy:"' . @$value->recCreBy . '",';
                            $html .= 'c_recCreDate:"' . @$value->recCreDate . '",';
                            $html .= 'c_recModBy:"' . @$value->recModBy . '",';
                            $html .= 'c_recModDate:"' . @$value->recModDate . '",';
                            $html .= 'c_serviceCategoryTypes:"' . @$value->serviceCategoryTypes . '",';
                            $html .= 'c_serviceTypes:"' . @$value->serviceTypes . '",';
                            $html .= 'c_serviceOccurrencesNo:"' . @$value->serviceOccurrencesNo . '",';
                            $html .= 'c_includeSankalpam:"' . @$includeSankalpam . '",';
                            $html .= 'c_Image:"' . @$src . '",';
                            $html .= 'c_bookingType:"' . @$bookingType . '",';
                            $html .= 'c_is_availibility_check:"' . @$is_availibility . '",';
                            $html .= "c_description:'" . str_replace("'", "\'", @$value->description) . "',";
                            $html .= 'c_is_date_required:"' . @$value->isDTVisible . '",';
                            $html .= 'c_isServicePaid:"' . @$isServicePaid . '",';
                            $html .= 'c_membershipDiscount:"' . @$value->membershipDiscount . '",';
                            $html .= 'c_membership_discount_amt:"' . @$value->membershipAmount . '",';
                            $html .= 'c_fullPackage:"' . @$fullPackage . '",';
                            $html .= 'c_service_desc:"",';
                            $html .= ' },';
                        }
                        $currentDate = date('Y-m-d', strtotime($currentDate . ' +1 day'));
                    }
                }
            }
        } else {
            $startDate = ! empty($value->startDate) ? date('Y-m-d', strtotime($value->startDate)) : null;
            $endDate   = ! empty($value->endDate) ? date('Y-m-d', strtotime($value->endDate)) : null;

            if ($startDate && $endDate) {
                $currentDate = date('Y-m-d');
                // $currentDate = $startDate;

                while (strtotime($currentDate) <= strtotime($endDate)) {
                    // echo (strtotime($currentDate) <= strtotime($endDate) && strtotime($currentDate) >= strtotime($endDate));
                    // echo "<br>".$value->refDataName.'//'.$currentDate.'//'.$endDate."//3434<br>";
                    $currentDay = date('w', strtotime($currentDate)); // Get day of the week (0 = Sunday, ..., 6 = Saturday)

                    $dayVisible = false;
                    if (isset($value->dayTypes) && !empty($value->dayTypes)) {
                            if (@explode(" ", $value->dayTypes)[0] == "EVERY") {
                                $value->dayTypes = @explode(" ", $value->dayTypes)[1];
                            }
                        }
                    if (isset($value->dayTypes) && ! empty($value->dayTypes)) {

                        $dayVisible = false;

                        $startDateArray = [];
                        if (in_array($value->dayTypes, $allowedTithis)) {
                            if ($value->dayTypes == 'DWITIYA') {

                                $startDateArray = $DWITIYADateArray;
                            } else if ($value->dayTypes == 'TRITIYA') {

                                $startDateArray = $TRITIYADateArray;
                            } else if ($value->dayTypes == 'DWADASHI') {

                                $startDateArray = $DWADASHIDateArray;
                            } else if ($value->dayTypes == 'SAPTAMI') {

                                $startDateArray = $SAPTAMIDateArray;
                            } else if ($value->dayTypes == 'ASHTAMI') {

                                $startDateArray = $ASHTAMIDateArray;
                            } else if ($value->dayTypes == 'PURNIMA') {

                                $startDateArray = $PURNIMADateArray;
                            } else if ($value->dayTypes == 'PANCHAMI') {

                                $startDateArray = $PANCHAMIDateArray;
                            } else if ($value->dayTypes == 'TRAYODASHI') {

                                $startDateArray = $TRAYODASHIDateArray;
                            } else if ($value->dayTypes == 'PRATIPADA') {

                                $startDateArray = $PRATIPADADateArray;
                            } else if ($value->dayTypes == 'AMAVASYA') {

                                $startDateArray = $AMAVASYADateArray;
                            } else if ($value->dayTypes == 'SHASHDI') {

                                $startDateArray = $SHASHDIDateArray;
                            } else if ($value->dayTypes == 'DASHAMI') {

                                $startDateArray = $DASHAMIDateArray;
                            } else if ($value->dayTypes == 'EKADASHI') {

                                $startDateArray = $EKADASHIDateArray;
                            } else if ($value->dayTypes == 'NAVAMI') {

                                $startDateArray = $NAVAMIDateArray;
                            } else if ($value->dayTypes == 'CHATURTHI') {

                                $startDateArray = $CHATURTHIDateArray;
                            } else {

                                $startDateArray = $CHATURDASHIDateArray;
                            }
                        }

                        if ($value->dayTypes == getWeekday($currentDate)) {
                            // echo "<br>".$value->refDataName."/22<br>";
                            $dayVisible = true;
                        } else if (getWeekdayOccurrence($currentDate) == $value->dayTypes) {
                            // echo "<br>".$value->refDataName."/33<br>";
                            $dayVisible = true;
                        } else {
                            // echo "<br>".$value->refDataName."/44<br>";
                            if (! empty($startDateArray)) {
                                $dateToCheck = date('Y-m-d', strtotime($currentDate));

                                $dayVisible = in_array($dateToCheck, $startDateArray) && (strtotime($currentDate) >= strtotime(date('Y-m-d'))) && in_array($value->dayTypes, $allowedTithis);
                            }
                        }
                    } else if (! isset($value->dayTypes) && empty($value->dayTypes)) {
                        $dayVisible = true;
                    } else if (strtotime($currentDate) <= strtotime($endDate) && strtotime($currentDate) >= strtotime($endDate)) {
                        $dayVisible = true;
                    }

                    if ($dayVisible) {

                        // Create the event for the valid date
                        $html .= ' {';
                        $html .= 'title:"' . trim($value->refDataName) . '",';
                        $html .= 'start: "' . $currentDate;

                        if (! empty($value->startTime)) {
                            $html .= 'T' . date('H:i:s', strtotime($value->startTime));
                        }
                        $html .= '",';

                        $html .= 'end: "' . $currentDate;
                        if (! empty($value->endTime)) {
                            $html .= 'T' . date('H:i:s', strtotime($value->endTime));
                        }
                        $html .= '",';

                        // if (!empty($value->colour)) {
                        $html .= 'backgroundColor:"#3d5644",';
                        // }

                        $html .= 'c_id:"' . @$value->_id . '",';
                        $html .= 'c_refDataName:"' . camelCase(@$value->refDataName) . '",';
                        $html .= 'c_serviceAmount:"' . camelCase(@$value->serviceAmount) . '",';
                        $html .= 'c_dayTypes:"' . camelCase(@$value->dayTypes) . '",';
                        $html .= 'c_eventDate:"' . @$currentDate . '",';
                        $html .= 'c_startTime:"' . @$value->startTime . '",';
                        $html .= 'c_endTime:"' . @$value->endTime . '",';
                        $html .= 'c_colour:"' . @$value->colour . '",';
                        $html .= 'c_moduleName:"' . @$value->moduleName . '",';
                        $html .= 'c_clientID:"' . @$value->clientID . '",';
                        $html .= 'c_productID:"' . @$value->productID . '",';
                        $html .= 'c_aspectType:"' . @$value->aspectType . '",';
                        $html .= 'c_recCreBy:"' . @$value->recCreBy . '",';
                        $html .= 'c_recCreDate:"' . @$value->recCreDate . '",';
                        $html .= 'c_recModBy:"' . @$value->recModBy . '",';
                        $html .= 'c_recModDate:"' . @$value->recModDate . '",';
                        $html .= 'c_serviceCategoryTypes:"' . @$value->serviceCategoryTypes . '",';
                        $html .= "c_description:'" . str_replace("'", "\'", @$value->description) . "',";
                        $html .= 'c_serviceTypes:"' . @$value->serviceTypes . '",';
                        $html .= 'c_serviceOccurrencesNo:"' . @$value->serviceOccurrencesNo . '",';
                        $html .= 'c_membershipDiscount:"' . @$value->membershipDiscount . '",';
                        $html .= 'c_membership_discount_amt:"' . @$value->membershipAmount . '",';
                        $html .= ' },';
                    }
                    $currentDate = date('Y-m-d', strtotime($currentDate . ' +1 day'));
                }
            } else if (empty($startDate) && empty($endDate) && isset($value->dayTypes) && ! empty($value->dayTypes)) {
                // Handle daily events when startDate and endDate are blank
                $currentDate = date('Y-m-d');                         // Start from today
                $endDate     = date('Y-m-d', strtotime('+365 days')); // Display for the next 30 days (or adjust as needed)

                while (strtotime($currentDate) <= strtotime($endDate)) {
                    $dayVisible = false;
                    $dayNames   = explode(',', $value->dayTypes); // Split the day names

                    $dayVisible = false;
                    if (isset($value->dayTypes) && !empty($value->dayTypes)) {
                            if (@explode(" ", $value->dayTypes)[0] == "EVERY") {
                                $value->dayTypes = @explode(" ", $value->dayTypes)[1];
                            }
                        }
                    if (isset($value->dayTypes) && ! empty($value->dayTypes)) {

                        $dayVisible = false;

                        $startDateArray = [];
                        if (in_array($value->dayTypes, $allowedTithis)) {
                            if ($value->dayTypes == 'DWITIYA') {

                                $startDateArray = $DWITIYADateArray;
                            } else if ($value->dayTypes == 'TRITIYA') {

                                $startDateArray = $TRITIYADateArray;
                            } else if ($value->dayTypes == 'DWADASHI') {

                                $startDateArray = $DWADASHIDateArray;
                            } else if ($value->dayTypes == 'SAPTAMI') {

                                $startDateArray = $SAPTAMIDateArray;
                            } else if ($value->dayTypes == 'ASHTAMI') {

                                $startDateArray = $ASHTAMIDateArray;
                            } else if ($value->dayTypes == 'PURNIMA') {

                                $startDateArray = $PURNIMADateArray;
                            } else if ($value->dayTypes == 'PANCHAMI') {

                                $startDateArray = $PANCHAMIDateArray;
                            } else if ($value->dayTypes == 'TRAYODASHI') {

                                $startDateArray = $TRAYODASHIDateArray;
                            } else if ($value->dayTypes == 'PRATIPADA') {

                                $startDateArray = $PRATIPADADateArray;
                            } else if ($value->dayTypes == 'AMAVASYA') {

                                $startDateArray = $AMAVASYADateArray;
                            } else if ($value->dayTypes == 'SHASHDI') {

                                $startDateArray = $SHASHDIDateArray;
                            } else if ($value->dayTypes == 'DASHAMI') {

                                $startDateArray = $DASHAMIDateArray;
                            } else if ($value->dayTypes == 'EKADASHI') {

                                $startDateArray = $EKADASHIDateArray;
                            } else if ($value->dayTypes == 'NAVAMI') {

                                $startDateArray = $NAVAMIDateArray;
                            } else if ($value->dayTypes == 'CHATURTHI') {

                                $startDateArray = $CHATURTHIDateArray;
                            } else {

                                $startDateArray = $CHATURDASHIDateArray;
                            }
                        }

                        if ($value->dayTypes == getWeekday($currentDate)) {
                            // echo "<br>".$value->refDataName."/22<br>";
                            $dayVisible = true;
                        } else if (getWeekdayOccurrence($currentDate) == $value->dayTypes) {
                            // echo "<br>".$value->refDataName."/33<br>";
                            $dayVisible = true;
                        } else {
                            // echo "<br>".$value->refDataName."/44<br>";
                            if (! empty($startDateArray)) {
                                $dateToCheck = date('Y-m-d', strtotime($currentDate));

                                $dayVisible = in_array($dateToCheck, $startDateArray) && (strtotime($currentDate) >= strtotime(date('Y-m-d'))) && in_array($value->dayTypes, $allowedTithis);
                            }
                        }
                    } else if (! isset($value->dayTypes) && empty($value->dayTypes)) {
                        $dayVisible = true;
                    } else if (strtotime($currentDate) <= strtotime($endDate) && strtotime($currentDate) >= strtotime($endDate)) {
                        $dayVisible = true;
                    }
                    if ($dayVisible) {
                        // Create daily event
                        $html .= ' {';
                        $html .= 'title:"' . trim($value->refDataName) . '",';
                        $html .= 'start: "' . $currentDate;

                        if (! empty($value->startTime)) {
                            $html .= 'T' . date('H:i:s', strtotime($value->startTime));
                        }
                        $html .= '",';

                        $html .= 'end: "' . $currentDate;
                        if (! empty($value->endTime)) {
                            $html .= 'T' . date('H:i:s', strtotime($value->endTime));
                        }
                        $html .= '",';

                        // if (!empty($value->colour)) {
                        $html .= 'backgroundColor:"#3d5644",';
                        // }

                        $html .= 'c_id:"' . @$value->_id . '",';
                        $html .= 'c_refDataName:"' . camelCase(@$value->refDataName) . '",';
                        $html .= 'c_serviceAmount:"' . camelCase(@$value->serviceAmount) . '",';
                        $html .= 'c_dayTypes:"' . camelCase(@$value->dayTypes) . '",';
                        $html .= 'c_eventDate:"' . @$currentDate . '",';
                        $html .= 'c_startTime:"' . @$value->startTime . '",';
                        $html .= 'c_endTime:"' . @$value->endTime . '",';
                        $html .= 'c_colour:"' . @$value->colour . '",';
                        $html .= 'c_moduleName:"' . @$value->moduleName . '",';
                        $html .= 'c_clientID:"' . @$value->clientID . '",';
                        $html .= 'c_productID:"' . @$value->productID . '",';
                        $html .= 'c_aspectType:"' . @$value->aspectType . '",';
                        $html .= 'c_recCreBy:"' . @$value->recCreBy . '",';
                        $html .= 'c_recCreDate:"' . @$value->recCreDate . '",';
                        $html .= 'c_recModBy:"' . @$value->recModBy . '",';
                        $html .= 'c_recModDate:"' . @$value->recModDate . '",';
                        $html .= 'c_serviceCategoryTypes:"' . @$value->serviceCategoryTypes . '",';
                        $html .= "c_description:'" . str_replace("'", "\'", @$value->description) . "',";
                        $html .= 'c_serviceTypes:"' . @$value->serviceTypes . '",';
                        $html .= 'c_serviceOccurrencesNo:"' . @$value->serviceOccurrencesNo . '",';
                        $html .= 'c_membershipDiscount:"' . @$value->membershipDiscount . '",';
                        $html .= 'c_membership_discount_amt:"' . @$value->membershipAmount . '",';
                        $html .= ' },';
                    }
                    $currentDate = date('Y-m-d', strtotime($currentDate . ' +1 day'));
                }
            } else if (empty($startDate) && empty($endDate)) {

                // Handle daily events when startDate and endDate are blank
                $currentDate = date('Y-m-d');                         // Start from today
                $endDate     = date('Y-m-d', strtotime('+365 days')); // Display for the next 30 days (or adjust as needed)

                while (strtotime($currentDate) <= strtotime($endDate)) {
                    $dayVisible = false;
                    $dayNames   = explode(',', $value->dayTypes); // Split the day names

                    $dayVisible = false;
                    if (isset($value->dayTypes) && !empty($value->dayTypes)) {
                            if (@explode(" ", $value->dayTypes)[0] == "EVERY") {
                                $value->dayTypes = @explode(" ", $value->dayTypes)[1];
                            }
                        }
                    if (isset($value->dayTypes) && ! empty($value->dayTypes)) {

                        $dayVisible = false;
                        $startDateArray = [];
                        if (in_array($value->dayTypes, $allowedTithis)) {
                            if ($value->dayTypes == 'DWITIYA') {

                                $startDateArray = $DWITIYADateArray;
                            } else if ($value->dayTypes == 'TRITIYA') {

                                $startDateArray = $TRITIYADateArray;
                            } else if ($value->dayTypes == 'DWADASHI') {

                                $startDateArray = $DWADASHIDateArray;
                            } else if ($value->dayTypes == 'SAPTAMI') {

                                $startDateArray = $SAPTAMIDateArray;
                            } else if ($value->dayTypes == 'ASHTAMI') {

                                $startDateArray = $ASHTAMIDateArray;
                            } else if ($value->dayTypes == 'PURNIMA') {

                                $startDateArray = $PURNIMADateArray;
                            } else if ($value->dayTypes == 'PANCHAMI') {

                                $startDateArray = $PANCHAMIDateArray;
                            } else if ($value->dayTypes == 'TRAYODASHI') {

                                $startDateArray = $TRAYODASHIDateArray;
                            } else if ($value->dayTypes == 'PRATIPADA') {

                                $startDateArray = $PRATIPADADateArray;
                            } else if ($value->dayTypes == 'AMAVASYA') {

                                $startDateArray = $AMAVASYADateArray;
                            } else if ($value->dayTypes == 'SHASHDI') {

                                $startDateArray = $SHASHDIDateArray;
                            } else if ($value->dayTypes == 'DASHAMI') {

                                $startDateArray = $DASHAMIDateArray;
                            } else if ($value->dayTypes == 'EKADASHI') {

                                $startDateArray = $EKADASHIDateArray;
                            } else if ($value->dayTypes == 'NAVAMI') {

                                $startDateArray = $NAVAMIDateArray;
                            } else if ($value->dayTypes == 'CHATURTHI') {

                                $startDateArray = $CHATURTHIDateArray;
                            } else {

                                $startDateArray = $CHATURDASHIDateArray;
                            }
                        }

                        if ($value->dayTypes == getWeekday($currentDate)) {
                            // echo "<br>".$value->refDataName."/22<br>";
                            $dayVisible = true;
                        } else if (getWeekdayOccurrence($currentDate) == $value->dayTypes) {
                            // echo "<br>".$value->refDataName."/33<br>";
                            $dayVisible = true;
                        } else {
                            // echo "<br>".$value->refDataName."/44<br>";
                            if (! empty($startDateArray)) {
                                $dateToCheck = date('Y-m-d', strtotime($currentDate));

                                $dayVisible = in_array($dateToCheck, $startDateArray) && (strtotime($currentDate) >= strtotime(date('Y-m-d'))) && in_array($value->dayTypes, $allowedTithis);
                            }
                        }
                    } else if (! isset($value->dayTypes) && empty($value->dayTypes)) {
                        $dayVisible = true;
                    } else if (strtotime($currentDate) <= strtotime($endDate) && strtotime($currentDate) >= strtotime($endDate)) {
                        $dayVisible = true;
                    }
                    if ($dayVisible) {
                        // Create daily event
                        $html .= ' {';
                        $html .= 'title:"' . trim($value->refDataName) . '",';
                        $html .= 'start: "' . $currentDate;

                        if (! empty($value->startTime)) {
                            $html .= 'T' . date('H:i:s', strtotime($value->startTime));
                        }
                        $html .= '",';

                        $html .= 'end: "' . $currentDate;
                        if (! empty($value->endTime)) {
                            $html .= 'T' . date('H:i:s', strtotime($value->endTime));
                        }
                        $html .= '",';

                        // if (!empty($value->colour)) {
                        $html .= 'backgroundColor:"#3d5644",';
                        // }

                        $html .= 'c_id:"' . @$value->_id . '",';
                        $html .= 'c_refDataName:"' . camelCase(@$value->refDataName) . '",';
                        $html .= 'c_serviceAmount:"' . camelCase(@$value->serviceAmount) . '",';
                        $html .= 'c_dayTypes:"' . camelCase(@$value->dayTypes) . '",';
                        $html .= 'c_eventDate:"' . @$currentDate . '",';
                        $html .= 'c_startTime:"' . @$value->startTime . '",';
                        $html .= 'c_endTime:"' . @$value->endTime . '",';
                        $html .= 'c_colour:"' . @$value->colour . '",';
                        $html .= 'c_moduleName:"' . @$value->moduleName . '",';
                        $html .= 'c_clientID:"' . @$value->clientID . '",';
                        $html .= 'c_productID:"' . @$value->productID . '",';
                        $html .= 'c_aspectType:"' . @$value->aspectType . '",';
                        $html .= 'c_recCreBy:"' . @$value->recCreBy . '",';
                        $html .= 'c_recCreDate:"' . @$value->recCreDate . '",';
                        $html .= 'c_recModBy:"' . @$value->recModBy . '",';
                        $html .= 'c_recModDate:"' . @$value->recModDate . '",';
                        $html .= 'c_serviceCategoryTypes:"' . @$value->serviceCategoryTypes . '",';
                        $html .= "c_description:'" . str_replace("'", "\'", @$value->description) . "',";
                        $html .= 'c_serviceTypes:"' . @$value->serviceTypes . '",';
                        $html .= 'c_serviceOccurrencesNo:"' . @$value->serviceOccurrencesNo . '",';
                        $html .= 'c_membershipDiscount:"' . @$value->membershipDiscount . '",';
                        $html .= 'c_membership_discount_amt:"' . @$value->membershipAmount . '",';
                        $html .= ' },';
                    }
                    $currentDate = date('Y-m-d', strtotime($currentDate . ' +1 day'));
                }
            }
        }
    }
}

?>



<?php

$html2 = '';
if (! empty($religious_data)) {
    foreach ($religious_data as $key => $value) {

        $html2 .= ' {';
        $html2 .= 'title:"' . trim($value['Location']) . '",';
        // $html2 .= 'c_colour:"' . @$value['colour'] . '",';
        if (! empty(@$value['colour'])) {
            $html2 .= 'backgroundColor:"' . @$value['colour'] . '",';
        } else {
            $html2 .= 'backgroundColor:"#fff",';
        }
        $html2 .= 'PurnimantaMonth:"' . trim($value['PurnimantaMonth']) . '",';
        $html2 .= 'MoonRise:"' . trim($value['MoonRise']) . '",';
        $html2 .= 'MoonSet:"' . trim($value['MoonSet']) . '",';

        $html2 .= 'SunRise:"' . trim($value['SunRise']) . '",';
        $html2 .= 'SunSet:"' . trim($value['SunSet']) . '",';
        $html2 .= 'Tithi:"' . trim($value['Tithi']) . '",';
        $html2 .= 'Paksha:"' . trim($value['Paksha']) . '",';

        $html2 .= 'ShakaSamvat:"' . trim(@$value['ShakaSamvat']) . '",';
        $html2 .= 'VikramSamvat:"' . trim(@$value['VikramSamvat']) . '",';
        $html2 .= 'GujaratiSamvat:"' . trim(@$value['GujaratiSamvat']) . '",';
        $html2 .= 'AmantaMonth:"' . trim(@$value['AmantaMonth']) . '",';

        $html2 .= 'PurnimantaMonth:"' . trim(@$value['PurnimantaMonth']) . '",';
        $html2 .= 'Weekday:"' . trim(@$value['Weekday']) . '",';
        $html2 .= 'Paksha:"' . trim(@$value['Paksha']) . '",';
        $html2 .= 'Tithi:"' . trim(@$value['Tithi']) . '",';

        $html2 .= 'Nakshatra:"' . trim(@$value['Nakshatra']) . '",';
        $html2 .= 'Yoga:"' . trim(@$value['Yoga']) . '",';
        $html2 .= 'Karana:"' . trim(@$value['Karana']) . '",';
        $html2 .= 'Karana2:"' . trim(@$value['Karana2']) . '",';

        $html2 .= 'Sunsign:"' . trim(@$value['Sunsign']) . '",';
        $html2 .= 'RahuKalam:"' . trim(@$value['RahuKalam']) . '",';
        $html2 .= 'GulikaiKalam:"' . trim(@$value['GulikaiKalam']) . '",';
        $html2 .= 'Yamaganda:"' . trim(@$value['Yamaganda']) . '",';

        $html2 .= 'DurMuhurtam:"' . trim(@$value['DurMuhurtam']) . '",';
        $html2 .= 'DurMuhurtam2:"' . trim(@$value['DurMuhurtam2']) . '",';
        $html2 .= 'AmritKalam:"' . trim(@$value['AmritKalam']) . '",';
        $html2 .= 'Varjyam:"' . trim(@$value['Varjyam']) . '",';
        $html2 .= 'Rithu:"' . trim(@$value['Rithu']) . '",';

        $html2 .= 'start: "' . (date('Y-m-d', strtotime(@$value['startDate']))) . '",';
        $html2 .= ' },';
    }
}

?>


<script>
    const q = '<?= @$_GET['q'] ?>';
    $(document).ready(function() {
        var loader = new ldLoader({
            root: ".ldld.full"
        });
        var tithis = ["PRATIPADA", "DWITIYA", "TRITIYA", "CHATURTHI", "PANCHAMI", "SHASHDI", "SAPTAMI", "ASHTAMI", "NAVAMI", "DASHAMI", "EKADASHI", "DWADASHI", "TRAYODASHI", "CHATURDASHI", "PURNIMA", "AMAVASYA"];

        function getNextOccurrences(date, dayType, occurrences) {
            console.log(dayType);
            var nextDates = [];
            var count = 0; // To count valid occurrences

            while (count < occurrences) {
                date.setDate(date.getDate() + 1); // Move to the next day

                if (dayType.length > 0) {
                    if ($.datepicker.formatDate('DD', date).toUpperCase() === dayType.toUpperCase()) {
                        nextDates.push($.datepicker.formatDate('mm/dd/yy', date)); // Format to mm/dd/yy
                        count++; // Increment valid occurrence count
                    } else if (tithis.includes(dayType.toUpperCase())) {

                        if ($("#datesArray").length === 0) {
                            console.error("Element with ID #datesArray not found.");
                            return [];
                        }

                        var tithiDates = $("#datesArray").val() || ""; // Default to empty string if undefined
                        console.log("tithiDates:", tithiDates);

                        if (!tithiDates) {
                            console.error("tithiDates is undefined or empty.");
                            return [];
                        }

                        var dateInMMDDYYFormat = $.datepicker.formatDate('yy-mm-dd', date);
                        var startDateArray = tithiDates.split(" ").pop().split(",");

                        if (startDateArray.includes(dateInMMDDYYFormat)) {
                            nextDates.push($.datepicker.formatDate('mm/dd/yy', date)); // Format to mm/dd/yy
                            count++;
                        }
                    }
                } else {
                    nextDates.push($.datepicker.formatDate('mm/dd/yy', date)); // Format to mm/dd/yy
                    count++;
                }
            }

            return nextDates;
        }


        // Get next occurrences based on the day type

        function formattedDateFunction(eventDate) {
            console.log("eventDate*********");
            console.log(eventDate);
            if (typeof eventDate === "string") {
                // Parse the date string (assuming format 'YYYY/MM/DD')
                eventDate = new Date(eventDate.replace(/-/g, '/')); // Replace dashes with slashes for compatibility
            }

            if (!(eventDate instanceof Date) || isNaN(eventDate)) {
                console.error("Invalid eventDate:", eventDate);
                return "Invalid Date"; // Handle invalid dates gracefully
            }
            let formattedDate = String(eventDate.getMonth() + 1).padStart(2, '0') + "/" + String(eventDate.getDate()).padStart(2, '0') + "/" + eventDate.getFullYear();
            return formattedDate;
        }



        var d = new Date();
        // var strDate = d.getFullYear() + "/" + (d.getMonth() + 1) + "/" + d.getDate();
        var strDate = String(d.getMonth() + 1).padStart(2, '0') + "/" + String(d.getDate()).padStart(2, '0') + "/" + d.getFullYear();

        // Initialize the main calendar
        $('#calendar').fullCalendar({
            //locale: 'zh-cn',
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,basicWeek,basicDay,list'
            },
            defaultDate: strDate,
            //defaultDate: '2022-11-12',
            navLinks: true, // can click day/week names to navigate views
            editable: false,
            eventLimit: true, // allow "more" link when too many events
            events: [
                <?php echo $html; ?>
            ],
            displayEventTime: true,
            eventRender: function(event, element, view) {

                element.find('.fc-time').remove();


                element.click(function() {

                    console.log("event.c_is_availibility_check1: " + event.start);

                    let Todaymill = new Date(event.start);

                    // Format the date as mm/dd/yyyy
                    let today = (Todaymill.getMonth() + 1).toString().padStart(2, '0') + '/' +
                        Todaymill.getDate().toString().padStart(2, '0') + '/' +
                        Todaymill.getFullYear();

                    console.log(today);
                    console.log("event.c_is_availibility_check: " + event.c_is_availibility_check);
                    console.log("strDate: " + strDate);
                    const eventDate = new Date(today);
                    console.log("eventDate: " + (eventDate.getMonth() + 1) + "/" + eventDate.getDate() + "/" + eventDate.getFullYear());
                    const serviceStartDate = eventDate.getFullYear() + "/" + (eventDate.getMonth() + 1) + "/" + eventDate.getDate();
                    console.log((eventDate.getMonth() + 1) + "/" + eventDate.getDate() + "/" + eventDate.getFullYear() < strDate);
                    // alert(event.c_serviceCategoryTypes);
                    console.log(eventDate);
                    var html = '';

                    let formattedDate = String(eventDate.getMonth() + 1).padStart(2, '0') + "/" + String(eventDate.getDate()).padStart(2, '0') + "/" + eventDate.getFullYear();
                    var formattedDates = formattedDate;
                    var showDate = '';
                    if (parseInt(event.c_serviceOccurrencesNo) > 0) {
                        var nextDates = getNextOccurrences(new Date(today), event.c_dayTypes, event.c_serviceOccurrencesNo - 1);
                        selectedDates = [today].concat(nextDates); // Resetting to only the new selection and its occurrences
                        formattedDates = selectedDates.join(", ")

                        showDate = formattedDateFunction(selectedDates[0]) + ' - ' + formattedDateFunction(selectedDates.at(-1));
                    } else {
                        showDate = formattedDate;
                    }
                    if (event.c_serviceCategoryTypes == 'IN-TEMPLE') {



                        html += '<div class="modal-header"><img src="<?php echo $header_data[0]['leftImage'] ? ApiBaseUrl()['url'] . $header_data[0]['leftImage'] : base_url('assets/img/logo-1.png') ?>" class="icon-box"><h4 class="modal-title w-100 btottomborder">Service Details</h4></div><div class="modal-body p-0"><table class="table table-responsive table-bordered mt-4" style="background: #ffffff3b;"><tbody>';

                        html += '<tr><th>Service Name</th><td> <span id="event_name">' + event.c_refDataName + '</span></td></tr>';

                        if (event.c_dayTypes) {
                            html += '<tr><th>Day</th><td> <span id="event_day">' + event.c_dayTypes + '</span></td></tr>';
                        }

                        if (event.c_eventDate) {
                            html += '<tr><th>Date</th><td> <span id="event_date">' + showDate + '</span>';
                            if (parseInt(event.c_serviceOccurrencesNo) > 0) {
                                html += '<br/><small>( ' + event.c_serviceOccurrencesNo + ' Bookings )';
                            }
                            html += '</td></tr>';
                        }

                        if (event.c_startTime) {
                            html += '<tr><th>Start&nbspTime</th><td> <span id="start_time">' + event.c_startTime + '</span></td></tr>';
                        }

                        if (event.c_endTime) {
                            html += '<tr><th>End&nbspTime</th><td> <span id="end_time">' + event.c_endTime + '</span></td></tr>';
                        }
                        if (event.c_serviceAmount) {
                            html += '<tr><th>Service Amount</th><td> <span id="end_time">$ ' + parseFloat(event.c_serviceAmount).toFixed(2) + '</span></td></tr>';
                        }

                        if (event.c_eventLink) {
                            html += '<tr><th>Event Link</th><td> <a href="' + event.c_eventLink + '" target="_blank" style="color: #9d0000;"><img src="<?php echo base_url('assets/img/click-here.gif'); ?>" height="50"></a></td></tr>';
                        }
                        if (event.c_description && event.c_description != "undefined" && event.c_description != "" && event.c_description != null) {
                            html += '<tr><th>Event Description</th><td> <a href="javaScript:void(0);" type="button" onclick="ShowHideDesc(\'' + event.c_id + '\')"><i class="fa fa-eye"></i></a><div style="display:none;" id="descDiv' + event.c_id + '">' + event.c_description + '</div></td></tr>';
                        }
                        html += '</tbody></table></div><div class="modal-footer p-0"><button type="button" class="mx-auto d-block btn btn-secondary" data-bs-dismiss="modal">Close</button>';
                        if (eventDate.getFullYear() + "/" + (eventDate.getMonth() + 1) + "/" + eventDate.getDate() < strDate || event.c_is_availibility_check != "true") {
                            html += '<button type="button" class="mx-auto d-block btn" style="background: #696969;">Add To Cart</button>';
                        } else {
                            // isServicePaids, is_membership_discounts, service_descs, serviceOccurrencesNos, fullPackages
                            html += `
									 <button class="mx-auto d-block btn btn-secondary" onclick="addToServiceCart('${event.c_serviceAmount}', '${event.c_refDataName}', '${event.c_id}', '${event.c_serviceCategoryTypes}', '${event.c_serviceTypes}', '${event.c_dayTypes}', '${formattedDates}', '${event.c_startTime}', '${event.c_description}', '${event.c_Image}', '${event.c_bookingType}', '${event.c_includeSankalpam}', '${event.c_is_date_required}', '${event.c_isServicePaid}', '${event.c_membershipDiscount}', '${event.c_service_desc}', '${event.c_serviceOccurrencesNo}', '${event.c_fullPackage}', '${event.c_membership_discount_amt}')">Add To Cart</button>`;

                        }



                        $("#modalcalenderserviceDetails").html(html);

                        $('#modalcalenderservice').modal('show');



                    } else if (event.c_serviceCategoryTypes == 'SPONSORSHIP') {



                        html += '<div class="modal-header"><img src="<?php echo $header_data[0]['leftImage'] ? ApiBaseUrl()['url'] . $header_data[0]['leftImage'] : base_url('assets/img/logo-1.png') ?>" class="icon-box"><h4 class="modal-title w-100 btottomborder">Sponsor Details</h4></div><div class="modal-body p-0"><table class="table table-responsive table-bordered mt-4" style="background: #ffffff3b;"><tbody>';

                        html += '<tr><th>Service Name</th><td> <span id="event_name">' + event.c_refDataName + '</span></td></tr>';

                        if (event.c_dayTypes) {
                            html += '<tr><th>Day</th><td> <span id="event_day">' + event.c_dayTypes + '</span></td></tr>';
                        }

                        if (event.c_eventDate) {
                            html += '<tr><th>Date</th><td> <span id="event_date">' + showDate + '</span>';
                            if (parseInt(event.c_serviceOccurrencesNo) > 0) {
                                html += '<br/><small>( ' + event.c_serviceOccurrencesNo + ' Bookings )';
                            }
                            html += '</td></tr>';
                        }

                        if (event.c_startTime) {
                            html += '<tr><th>Start&nbspTime</th><td> <span id="start_time">' + event.c_startTime + '</span></td></tr>';
                        }

                        if (event.c_endTime) {
                            html += '<tr><th>End&nbspTime</th><td> <span id="end_time">' + event.c_endTime + '</span></td></tr>';
                        }
                        if (event.c_serviceAmount) {
                            html += '<tr><th>Service Amount</th><td> <span id="end_time">$ ' + parseFloat(event.c_serviceAmount).toFixed(2) + '</span></td></tr>';
                        }

                        if (event.c_eventLink) {
                            html += '<tr><th>Event Link</th><td> <a href="' + event.c_eventLink + '" target="_blank" style="color: #9d0000;"><img src="<?php echo base_url('assets/img/click-here.gif'); ?>" height="50"></a></td></tr>';
                        }
                        if (event.c_description && event.c_description != "undefined" && event.c_description != "" && event.c_description != null) {
                            html += '<tr><th>Event Description</th><td> <a href="javaScript:void(0);" type="button" onclick="ShowHideDesc(\'' + event.c_id + '\')"><i class="fa fa-eye"></i></a><div style="display:none;" id="descDiv' + event.c_id + '">' + event.c_description + '</div></td></tr>';
                        }
                        html += '</tbody></table></div><div class="modal-footer p-0"><button type="button" class="mx-auto d-block btn btn-secondary" data-bs-dismiss="modal">Close</button>';
                        if (eventDate.getFullYear() + "/" + (eventDate.getMonth() + 1) + "/" + eventDate.getDate() < strDate || event.c_is_availibility_check != "true") {
                            html += '<button type="button" class="mx-auto d-block btn" style="background: #696969;">Add To Cart</button>';
                        } else {
                            // isServicePaids, is_membership_discounts, service_descs, serviceOccurrencesNos, fullPackages
                            html += `
			 <button class="mx-auto d-block btn btn-secondary" onclick="addToSponserCart('${event.c_serviceAmount}', '${event.c_refDataName}', '${event.c_id}', '${event.c_serviceCategoryTypes}', '${event.c_serviceTypes}', '${event.c_dayTypes}', '${formattedDates}', '${event.c_startTime}', '${event.c_description}', '${event.c_Image}', '${event.c_bookingType}', '${event.c_includeSankalpam}', '${event.c_is_date_required}', '${event.c_isServicePaid}', '${event.c_membershipDiscount}', '${event.c_service_desc}', '${event.c_serviceOccurrencesNo}', '${event.c_fullPackage}', '${event.c_membership_discount_amt}')">Add To Cart</button>`;

                        }



                        $("#modalcalenderersponserDetails").html(html);

                        $('#modalcalendersponser').modal('show');



                    } else if (event.c_serviceCategoryTypes == 'EVENTS') {
                        html += '<div class="modal-header"><img src="<?php echo $header_data[0]['leftImage'] ? ApiBaseUrl()['url'] . $header_data[0]['leftImage'] : base_url('assets/img/logo-1.png') ?>" class="icon-box"><h4 class="modal-title w-100 btottomborder">Event Details</h4></div><div class="modal-body p-0"><table class="table table-responsive table-bordered mt-4" style="background: #ffffff3b;"><tbody>';

                        html += '<tr><th>Event</th><td> <span id="event_name">' + event.c_refDataName + '</span></td></tr>';

                        if (event.c_dayTypes) {
                            html += '<tr><th>Day</th><td> <span id="event_day">' + event.c_dayTypes + '</span></td></tr>';
                        }

                        if (event.c_eventDate) {
                            html += '<tr><th>Date</th><td> <span id="event_date">' + formattedDate + '</span></td></tr>';
                        }

                        if (event.c_startTime) {
                            html += '<tr><th>Start&nbspTime</th><td> <span id="start_time">' + event.c_startTime + '</span></td></tr>';
                        }

                        if (event.c_endTime) {
                            html += '<tr><th>End&nbspTime</th><td> <span id="end_time">' + event.c_endTime + '</span></td></tr>';
                        }
                        if (event.c_serviceAmount) {
                            html += '<tr><th>Event Amount</th><td> <span id="end_time">$ ' + parseFloat(event.c_serviceAmount).toFixed(2) + '</span></td></tr>';
                        } else {
                            if (eventDate.getFullYear() + "/" + (eventDate.getMonth() + 1) + "/" + eventDate.getDate() < strDate) {} else {
                                html += '<tr><th>Event Amount</th><td> <div class="input-group pb-2" style="padding-right: 10px;padding-left: 10px;"><span class="input-group-text" style="border-radius: 0.375rem; padding-right: 5px;color: var(--main-color-new-theme);border:0;padding-right:10px;font-weight:bold">$</span><input id="anyAmtEvent' + event.c_id + '" service-id="' + event.c_id + '" type="number" class="anyamt form-control amount-input" placeholder="0.00" oninput="SetAmount(this.value,\'' + event.c_id + '\', \'' + event.c_refDataName + '\', \'' + event.c_id + '\', \'' + event.c_serviceCategoryTypes + '\', \'' + event.c_serviceTypes + '\', \'' + event.c_dayTypes + '\', \'' + serviceStartDate + '\', \'' + event.c_startTime + '\', \'' + event.c_membershipDiscount + '\', \'' + event.c_membership_discount_amt + '\')" minlength="1" pattern="[1-9]\\d*" style="background: transparent; color: var(--main-color-new-theme); font-size: 14px; font-weight: bold;" value=""></div></td></tr>';
                            }
                        }

                        if (event.c_eventLink) {
                            html += '<tr><th>Event Link</th><td> <a href="' + event.c_eventLink + '" target="_blank" style="color: #9d0000;"><img src="<?php echo base_url('assets/img/click-here.gif'); ?>" height="50"></a></td></tr>';
                        }
                        if (event.c_description && event.c_description != "undefined" && event.c_description != "" && event.c_description != null) {
                            html += '<tr><th>Event Description</th><td> <a href="javaScript:void(0);" type="button" onclick="ShowHideDesc(\'' + event.c_id + '\')"><i class="fa fa-eye"></i></a><div style="display:none;" id="descDiv' + event.c_id + '">' + event.c_description + '</div></td></tr>';
                        }
                        html += '</tbody></table></div><div class="modal-footer p-0"><button type="button" class="mx-auto d-block btn btn-secondary" data-bs-dismiss="modal">Close</button>';
                        if ((eventDate.getMonth() + 1) + "/" + eventDate.getDate() + "/" + eventDate.getFullYear() < strDate) {
                            html += '<button type="button" class="mx-auto d-block btn" style="background: #696969;">Add To Cart</button>';
                        } else {
                            html += `
									<button class="mx-auto d-block btn btn-secondary"  id="btn${event.c_id}" onclick="addSingleCart('${event.c_serviceAmount}', '${event.c_refDataName}', '${event.c_id}', '${event.c_serviceCategoryTypes}', '${event.c_serviceTypes}', '${event.c_dayTypes}', '${serviceStartDate}', '${event.c_startTime}', '${event.c_membershipDiscount}', '${event.c_membership_discount_amt}')">Add To Cart</button>`;

                        }
                        html += '</div>';
                        $("#modalcalendereventDetails").html(html);

                        $('#modalcalenderevent').modal('show');
                    } else {
                        html += '<tr><th>Event</th><td> <span id="event_name">' + event.c_refDataName + '</span></td></tr>';

                        if (event.c_dayTypes) {
                            html += '<tr><th>Day</th><td> <span id="event_day">' + event.c_dayTypes + '</span></td></tr>';
                        }

                        if (event.c_eventDate) {
                            html += '<tr><th>Date</th><td> <span id="event_date">' + event.c_eventDate + '</span></td></tr>';
                        }

                        if (event.c_startTime) {
                            html += '<tr><th>Start&nbspTime</th><td> <span id="start_time">' + event.c_startTime + '</span></td></tr>';
                        }

                        if (event.c_endTime) {
                            html += '<tr><th>End&nbspTime</th><td> <span id="end_time">' + event.c_endTime + '</span></td></tr>';
                        }

                        if (event.c_eventLink) {
                            html += '<tr><th>Event Link</th><td> <a href="' + event.c_eventLink + '" target="_blank" style="color: #9d0000;"><img src="<?php echo base_url('assets/img/click-here.gif'); ?>" height="50"></a></td></tr>';
                        }
                        if (event.c_description && event.c_description != "undefined" && event.c_description != "" && event.c_description != null) {
                            html += '<tr><th>Event Description</th><td> <a href="javaScript:void(0);" type="button" onclick="ShowHideDesc(\'' + event.c_id + '\')"><i class="fa fa-eye"></i></a><div style="display:none;" id="descDiv' + event.c_id + '">' + event.c_description + '</div></td></tr>';
                        }
                        $("#calendarEventDetails").html(html);

                        $('#modalevent').modal('show');
                    }


                    //alert(html);




                })
            }
        });

        // Hide the religious calendar initially
        if (q == 'panchangan') {
            $('#calendar').hide();
            $('#Religiouscalendar').show();
            if (!$('#Religiouscalendar').hasClass('initialized')) {
                var d1 = new Date();
                var strDate1 = d1.getFullYear() + "/" + (d1.getMonth() + 1) + "/" + d1.getDate();
                $('#Religiouscalendar').fullCalendar({
                    header: {
                        left: 'prev,next today',
                        center: 'title',
                        right: 'month,basicWeek,basicDay,list'
                    },
                    defaultDate: strDate1,
                    navLinks: true,
                    editable: false,
                    eventLimit: true,
                    events: [
                        <?php echo $html2; ?>
                    ],
                    displayEventTime: false,
                    eventRender: function(event, element) {
                        // var_dump(event);
                        element.find(".fc-title").html('<span class="location"><i style="color:orange;" class="fa fa-sun-o"></i>&nbsp;' + event.SunRise + '</span>&nbsp;<span class="location"><i style="color:orange;" class="fa fa-moon-o"></i>&nbsp;' + event.SunSet + '</span><br/><span class="tithi" style=""><i style="color:green;" class="fa fa-calendar-times-o"></i>&nbsp;' + event.Tithi + '</span><br/><span class="paksha" style="">' + event.Paksha + '</span>');
                        element.click(function() {
                            var html2 = '';
                            html2 += '<tr><th class="fw-bold">Location</th><td> <span id="event_name"> ' + event.title + '</span></td></tr>';
                            if (event.SunRise) {
                                html2 += '<tr><th class="fw-bold">Sun Rise</th><td> <span id="sun_rise">' + event.SunRise + '</span></td></tr>';
                            }

                            if (event.SunSet) {
                                html2 += '<tr><th class="fw-bold">Sun Set</th><td> <span id="sun_set">' + event.SunSet + '</span></td></tr>';
                            }

                            if (event.MoonRise) {
                                html2 += '<tr><th class="fw-bold">Moon Rise</th><td> <span id="moon_rise">' + event.MoonRise + '</span></td></tr>';
                            }


                            if (event.MoonSet) {
                                html2 += '<tr><th class="fw-bold">Moon Set</th><td> <span id="moon_set">' + event.MoonSet + '</span></td></tr>';
                            }

                            if (event.ShakaSamvat) {
                                html2 += '<tr><th class="fw-bold">Shaka Samvat</th><td> <span id="shaka_samvat">' + event.ShakaSamvat + '</span></td></tr>';
                            }

                            if (event.VikramSamvat) {
                                html2 += '<tr><th class="fw-bold">Vikram Samvat</th><td> <span id="vikram_samvat">' + event.VikramSamvat + '</span></td></tr>';
                            }

                            if (event.GujaratiSamvat) {
                                html2 += '<tr><th class="fw-bold">Gujarati Samvat</th><td> <span id="gujarati_samvat">' + event.GujaratiSamvat + '</span></td></tr>';
                            }

                            if (event.AmantaMonth) {
                                html2 += '<tr><th class="fw-bold">Amanta Month</th><td> <span id="amanta_month">' + event.AmantaMonth + '</span></td></tr>';
                            }

                            if (event.PurnimantaMonth) {
                                html2 += '<tr><th class="fw-bold">Purnimanta Month</th><td> <span id="purnimanta_month">' + event.PurnimantaMonth + '</span></td></tr>';
                            }

                            if (event.Weekday) {
                                html2 += '<tr><th class="fw-bold">Weekday</th><td> <span id="weekday">' + event.Weekday + '</span></td></tr>';
                            }

                            if (event.Paksha) {
                                html2 += '<tr><th class="fw-bold">Paksha</th><td> <span id="paksha">' + event.Paksha + '</span></td></tr>';
                            }

                            if (event.Tithi) {
                                html2 += '<tr><th class="fw-bold">Tithi</th><td> <span id="tithi">' + event.Tithi + '</span></td></tr>';
                            }

                            if (event.Nakshatra) {
                                html2 += '<tr><th class="fw-bold">Nakshatra</th><td> <span id="nakshatra">' + event.Nakshatra + '</span></td></tr>';
                            }

                            if (event.Yoga) {
                                html2 += '<tr><th class="fw-bold">Yoga</th><td> <span id="yoga">' + event.Yoga + '</span></td></tr>';
                            }

                            if (event.Karana) {
                                html2 += '<tr><th class="fw-bold">Karana</th><td> <span id="karana">' + event.Karana + '</span></td></tr>';
                            }

                            if (event.Karana2) {
                                html2 += '<tr><th class="fw-bold">Karana 2</th><td> <span id="karana2">' + event.Karana2 + '</span></td></tr>';
                            }

                            if (event.Sunsign) {
                                html2 += '<tr><th class="fw-bold">Sunsign</th><td> <span id="sunsign">' + event.Sunsign + '</span></td></tr>';
                            }

                            if (event.RahuKalam) {
                                html2 += '<tr><th class="fw-bold">Rahu Kalam</th><td> <span id="rahukalam">' + event.RahuKalam + '</span></td></tr>';
                            }

                            if (event.GulikaiKalam) {
                                html2 += '<tr><th class="fw-bold">Gulikai Kalam</th><td> <span id="gulikaikalam">' + event.GulikaiKalam + '</span></td></tr>';
                            }

                            if (event.Yamaganda) {
                                html2 += '<tr><th class="fw-bold">Yamaganda</th><td> <span id="yamaganda">' + event.Yamaganda + '</span></td></tr>';
                            }

                            if (event.DurMuhurtam) {
                                html2 += '<tr><th class="fw-bold">Dur Muhurtam</th><td> <span id="durmuhurtam">' + event.DurMuhurtam + '</span></td></tr>';
                            }

                            if (event.DurMuhurtam2) {
                                html2 += '<tr><th class="fw-bold">Dur Muhurtam 2</th><td> <span id="durmuhurtam2">' + event.DurMuhurtam2 + '</span></td></tr>';
                            }

                            if (event.AmritKalam) {
                                html2 += '<tr><th class="fw-bold">Amrit Kalam</th><td> <span id="amritkalam">' + event.AmritKalam + '</span></td></tr>';
                            }

                            if (event.Varjyam) {
                                html2 += '<tr><th class="fw-bold">Varjyam</th><td> <span id="varjyam">' + event.Varjyam + '</span></td></tr>';
                            }



                            $("#calendarPnachangamDetails").html(html2);
                            $('#modalpanchangam').modal('show');
                        });
                    }
                });
                $('#Religiouscalendar').addClass('initialized');
            }
        } else {
            $('#calendar').show();
            $('#Religiouscalendar').hide();
        }
        // Event handler for tab clicks
        $('.calendar-type').on('click', function() {
            var activeTabName = $(this).attr('tab-name');

            if (activeTabName === 'calendar') {
                $('#calendar').show();
                $('#Religiouscalendar').hide();
            } else {
                $('#calendar').hide();
                $('#Religiouscalendar').show();

                // Initialize the religious calendar if not already initialized
                if (!$('#Religiouscalendar').hasClass('initialized')) {
                    var d1 = new Date();
                    var strDate1 = d1.getFullYear() + "/" + (d1.getMonth() + 1) + "/" + d1.getDate();
                    $('#Religiouscalendar').fullCalendar({
                        header: {
                            left: 'prev,next today',
                            center: 'title',
                            right: 'month,basicWeek,basicDay,list'
                        },
                        defaultDate: strDate1,
                        navLinks: true,
                        editable: false,
                        eventLimit: true,
                        events: [
                            <?php echo $html2; ?>
                        ],
                        displayEventTime: false,
                        eventRender: function(event, element) {
                            // var_dump(event);
                            element.find(".fc-title").html('<span class="location"><i style="color:orange;" class="fa fa-sun-o"></i>&nbsp;' + event.SunRise + '</span>&nbsp;<span class="location"><i style="color:orange;" class="fa fa-moon-o"></i>&nbsp;' + event.SunSet + '</span><br/><span class="tithi" style=""><i style="color:green;" class="fa fa-calendar-times-o"></i>&nbsp;' + event.Tithi + '</span><br/><span class="paksha" style="">' + event.Paksha + '</span>');
                            element.click(function() {
                                var html2 = '';
                                html2 += '<tr><th class="fw-bold">Location</th><td> <span id="event_name"> ' + event.title + '</span></td></tr>';
                                if (event.SunRise) {
                                    html2 += '<tr><th class="fw-bold">Sun Rise</th><td> <span id="sun_rise">' + event.SunRise + '</span></td></tr>';
                                }

                                if (event.SunSet) {
                                    html2 += '<tr><th class="fw-bold">Sun Set</th><td> <span id="sun_set">' + event.SunSet + '</span></td></tr>';
                                }

                                if (event.MoonRise) {
                                    html2 += '<tr><th class="fw-bold">Moon Rise</th><td> <span id="moon_rise">' + event.MoonRise + '</span></td></tr>';
                                }


                                if (event.MoonSet) {
                                    html2 += '<tr><th class="fw-bold">Moon Set</th><td> <span id="moon_set">' + event.MoonSet + '</span></td></tr>';
                                }

                                if (event.ShakaSamvat) {
                                    html2 += '<tr><th class="fw-bold">Shaka Samvat</th><td> <span id="shaka_samvat">' + event.ShakaSamvat + '</span></td></tr>';
                                }

                                if (event.VikramSamvat) {
                                    html2 += '<tr><th class="fw-bold">Vikram Samvat</th><td> <span id="vikram_samvat">' + event.VikramSamvat + '</span></td></tr>';
                                }

                                if (event.GujaratiSamvat) {
                                    html2 += '<tr><th class="fw-bold">Gujarati Samvat</th><td> <span id="gujarati_samvat">' + event.GujaratiSamvat + '</span></td></tr>';
                                }

                                if (event.AmantaMonth) {
                                    html2 += '<tr><th class="fw-bold">Amanta Month</th><td> <span id="amanta_month">' + event.AmantaMonth + '</span></td></tr>';
                                }

                                if (event.PurnimantaMonth) {
                                    html2 += '<tr><th class="fw-bold">Purnimanta Month</th><td> <span id="purnimanta_month">' + event.PurnimantaMonth + '</span></td></tr>';
                                }

                                if (event.Weekday) {
                                    html2 += '<tr><th class="fw-bold">Weekday</th><td> <span id="weekday">' + event.Weekday + '</span></td></tr>';
                                }

                                if (event.Paksha) {
                                    html2 += '<tr><th class="fw-bold">Paksha</th><td> <span id="paksha">' + event.Paksha + '</span></td></tr>';
                                }

                                if (event.Tithi) {
                                    html2 += '<tr><th class="fw-bold">Tithi</th><td> <span id="tithi">' + event.Tithi + '</span></td></tr>';
                                }

                                if (event.Nakshatra) {
                                    html2 += '<tr><th class="fw-bold">Nakshatra</th><td> <span id="nakshatra">' + event.Nakshatra + '</span></td></tr>';
                                }

                                if (event.Yoga) {
                                    html2 += '<tr><th class="fw-bold">Yoga</th><td> <span id="yoga">' + event.Yoga + '</span></td></tr>';
                                }

                                if (event.Karana) {
                                    html2 += '<tr><th class="fw-bold">Karana</th><td> <span id="karana">' + event.Karana + '</span></td></tr>';
                                }

                                if (event.Karana2) {
                                    html2 += '<tr><th class="fw-bold">Karana 2</th><td> <span id="karana2">' + event.Karana2 + '</span></td></tr>';
                                }

                                if (event.Sunsign) {
                                    html2 += '<tr><th class="fw-bold">Sunsign</th><td> <span id="sunsign">' + event.Sunsign + '</span></td></tr>';
                                }

                                if (event.RahuKalam) {
                                    html2 += '<tr><th class="fw-bold">Rahu Kalam</th><td> <span id="rahukalam">' + event.RahuKalam + '</span></td></tr>';
                                }

                                if (event.GulikaiKalam) {
                                    html2 += '<tr><th class="fw-bold">Gulikai Kalam</th><td> <span id="gulikaikalam">' + event.GulikaiKalam + '</span></td></tr>';
                                }

                                if (event.Yamaganda) {
                                    html2 += '<tr><th class="fw-bold">Yamaganda</th><td> <span id="yamaganda">' + event.Yamaganda + '</span></td></tr>';
                                }

                                if (event.DurMuhurtam) {
                                    html2 += '<tr><th class="fw-bold">Dur Muhurtam</th><td> <span id="durmuhurtam">' + event.DurMuhurtam + '</span></td></tr>';
                                }

                                if (event.DurMuhurtam2) {
                                    html2 += '<tr><th class="fw-bold">Dur Muhurtam 2</th><td> <span id="durmuhurtam2">' + event.DurMuhurtam2 + '</span></td></tr>';
                                }

                                if (event.AmritKalam) {
                                    html2 += '<tr><th class="fw-bold">Amrit Kalam</th><td> <span id="amritkalam">' + event.AmritKalam + '</span></td></tr>';
                                }

                                if (event.Varjyam) {
                                    html2 += '<tr><th class="fw-bold">Varjyam</th><td> <span id="varjyam">' + event.Varjyam + '</span></td></tr>';
                                }



                                $("#calendarPnachangamDetails").html(html2);
                                $('#modalpanchangam').modal('show');
                            });
                        }
                    });
                    $('#Religiouscalendar').addClass('initialized');
                }
            }
        });
    });
</script>

<script type="text/javascript" src="<?php echo base_url('admin_assets/js/sweetalert2.all.min.js') ?>"></script>

<script type="text/javascript">
    $(document).ready(function() {
        window.scrollTo({
            top: 225,
            behavior: 'smooth'
        });
    });


    function addSingleCart(service_price, service_name, service_id, service_category, service_type, day_type, start_date, start_time, membership_discount, c_membership_discount_amt) {

        console.log(service_price + " :: " + service_name + " :: " + service_id + " :: " + service_category + " :: " + service_type + " :: " + day_type + " :: " + start_date + " :: " + start_time);


        loader.on();
        var totalPrice = service_price;
        var sankalpam_data = [];
        var cart_type = 'EVENTS';
        var ids = [];
        var qty = [];
        var ctg = [];
        var startTime = [];
        var startDate = [];
        var serviceTypes = [];
        var serviceName = [];
        var serviceAmount = [];
        var cart_ctg = [];
        var is_membership_discount = [];
        is_membership_discount.push(membership_discount);
        var membership_discount_amt = [];
        membership_discount_amt.push(c_membership_discount_amt);
        startTime.push(start_time);
        startDate.push(start_date);
        ctg.push(service_category);
        serviceTypes.push(service_type);
        serviceName.push(service_name);


        cart_ctg.push(cart_type);
        serviceAmount.push(service_price);
        ids.push(service_id);
        qty.push(1);


        $(".cart-count").text(ids.length);




        $.ajax({
            type: "POST",
            url: "<?php echo base_url('Events/addCart'); ?>",
            data: {
                ids: ids,
                totalPrice: totalPrice,
                qty: qty,
                ctg: ctg,
                startDate: startDate,
                serviceTypes: serviceTypes,
                serviceName: serviceName,
                serviceAmount: serviceAmount,
                cart_type: cart_type,
                cart_ctg: cart_ctg,
                is_membership_discount: is_membership_discount,
                membership_discount_amt: membership_discount_amt
            },
            success: function(result) {
                loader.off();
                var responseObject = JSON.parse(result);

                console.log(responseObject.status);
                var totalPrice = responseObject.totalPrice;

                if (responseObject.status == 1) {
                    updateCartCount();
                    Swal.fire({
                        title: 'Added into Cart!',
                        showDenyButton: false,
                        showCancelButton: false,
                        icon: 'success',
                        confirmButtonText: 'Proceed to Checkout',
                        allowOutsideClick: false,
                        // denyButtonText: `Cancel`,
                    }).then((result) => {

                        if (result.isConfirmed) {
                            $("#modalevent").modal("hide");
                            CartCheckLogin('events');

                        }
                    });

                } else {
                    Swal.fire('Something went wrong!', '', 'warning');
                }




                loader.off();
            }
        });


    }

    function CartCheckLogin(page) {

        loader.on();
        var page_name = page;
        event.preventDefault();
        $.ajax({
            url: "<?php echo base_url('check-login-status') ?>",
            type: "POST",
            dataType: "json",
            success: function(data) {
                loader.off();
                if (data == 0) {
                    openLoginModal(page_name);
                } else {
                    if (page_name == 'events') {
                        window.location.href = "<?php echo base_url('events/checkout') ?>";
                    } else if (page_name == 'services') {
                        window.location.href = "<?php echo base_url('checkout/service') ?>";
                    }
                }
            }
        });

    }



    function addToServiceCart(service_price, service_name, service_id, service_category, service_type, day_type, start_date, start_time, descriptions, images, bookingtypes, includeSankalpams, is_date_requireds, isServicePaids, is_membership_discounts, service_descs, serviceOccurrencesNos, fullPackages, c_membership_discount_amt) {

        var totalPrice = service_price;
        var serviceName = [];
        var ids = [];
        var ctg = [];
        var serviceTypes = [];
        var startDate = [];
        var startTime = [];
        var description = [];
        var serviceAmount = [];
        var image = [];
        var cart_ctg = [];
        var bookingtype = [];
        var includeSankalpam = [];
        var is_date_required = [];
        var isServicePaid = [];
        var is_membership_discount = [];
        var membership_discount_amt = [];
        var service_desc = [];
        var serviceOccurrencesNo = [];
        var fullPackage = [];
        var sankalpam_data = [];

        var cart_type = 'SERVICES';
        var qty = [];


        serviceName.push(service_name);
        ids.push(service_id);
        ctg.push(service_category);
        serviceTypes.push(service_type);
        startTime.push(start_time);
        startDate.push(start_date);
        description.push(descriptions);
        serviceAmount.push(service_price);

        image.push(images);
        cart_ctg.push('SERVICES');
        bookingtype.push(bookingtypes);
        includeSankalpam.push(includeSankalpams);
        is_date_required.push(is_date_requireds);
        isServicePaid.push(isServicePaids);
        is_membership_discount.push(is_membership_discounts);
        membership_discount_amt.push(c_membership_discount_amt);
        service_desc.push(service_descs);
        serviceOccurrencesNo.push(serviceOccurrencesNos);
        fullPackage.push(fullPackages);;
        qty.push(1);
        sankalpam_data.push('');

        var noDateSelected = 0;
        var addtoCartStatus = true;


        $.ajax({
            type: "POST",
            url: "<?php echo base_url('Services/addCart'); ?>",
            dataType: 'json',
            data: {
                ids: ids,
                totalPrice: totalPrice,
                qty: qty,
                ctg: ctg,
                serviceTypes: serviceTypes,
                serviceName: serviceName,
                startDate: startDate,
                startTime: startTime,
                serviceAmount: serviceAmount,
                cart_type: cart_type,
                image: image,
                description: description,
                cart_ctg: cart_ctg,
                bookingtype: bookingtype,
                includeSankalpam: includeSankalpam,
                is_date_required: is_date_required,
                is_membership_discount: is_membership_discount,
                service_desc: service_desc,
                serviceOccurrencesNo: serviceOccurrencesNo,
                fullPackage: fullPackage
            },
            success: function(result) {
                console.log(result);
                updateCartCount();
                Swal.fire({
                    title: 'Added into Cart!',
                    showDenyButton: false,
                    showCancelButton: false,
                    icon: 'success',
                    confirmButtonText: 'Proceed to Checkout',
                    allowOutsideClick: false,
                    // denyButtonText: `Cancel`,
                }).then((result) => {

                    if (result.isConfirmed) {
                        $("#modalcalenderservice").modal("hide");
                        CartCheckLogin('services');

                    }
                });
                loader.off();
            }
        });


    }

    function SetAmount(value, id, c_refDataName, c_serviceCategoryTypes, c_serviceTypes, c_dayTypes, serviceStartDate, c_startTime, c_membershipDiscount, c_membership_discount_amt) {
        console.log(value);
        console.log(id);
        console.log($("#btn" + id).attr('onclick'));

        // Get the button by its ID
        const button = document.getElementById(`btn${id}`);

        // Update the onclick attribute with the new service amount
        button.setAttribute('onclick', `addSingleCart('${value}', '${c_refDataName}', '${id}', '${c_serviceCategoryTypes}', '${c_serviceTypes}', '${c_dayTypes}', '${serviceStartDate}', '${c_startTime}', '${c_membershipDiscount}','${c_membership_discount_amt}')`);
    }

    function addToSponserCart(service_price, service_name, service_id, service_category, service_type, day_type, start_date, start_time, descriptions, images, bookingtypes, includeSankalpams, is_date_requireds, isServicePaids, is_membership_discounts, service_descs, serviceOccurrencesNos, fullPackages, membership_discount_amts) {

        var totalPrice = service_price;
        var serviceName = [];
        var ids = [];
        var ctg = [];
        var serviceTypes = [];
        var startDate = [];
        var startTime = [];
        var description = [];
        var serviceAmount = [];
        var image = [];
        var cart_ctg = [];
        var bookingtype = [];
        var includeSankalpam = [];
        var is_date_required = [];
        var isServicePaid = [];
        var is_membership_discount = [];
        var service_desc = [];
        var serviceOccurrencesNo = [];
        var fullPackage = [];
        var sankalpam_data = [];

        var membership_discount_amt = [];

        var cart_type = 'SPONSORSHIP';
        var qty = [];


        serviceName.push(service_name);
        ids.push(service_id);
        ctg.push(service_category);
        serviceTypes.push(service_type);
        startTime.push(start_time);
        startDate.push(start_date);
        description.push(descriptions);
        serviceAmount.push(service_price);

        image.push(images);
        cart_ctg.push('SPONSORSHIP');
        bookingtype.push(bookingtypes);
        includeSankalpam.push(includeSankalpams);
        is_date_required.push(is_date_requireds);
        isServicePaid.push(isServicePaids);
        is_membership_discount.push(is_membership_discounts);
        membership_discount_amt.push(membership_discount_amts);
        service_desc.push(service_descs);
        serviceOccurrencesNo.push(serviceOccurrencesNos);
        fullPackage.push(fullPackages);;
        qty.push(1);
        sankalpam_data.push('');

        var noDateSelected = 0;
        var addtoCartStatus = true;




        $.ajax({
            type: "POST",
            url: "<?php echo base_url('SponsorNow/addCart'); ?>",
            data: {
                ids: ids,
                totalPrice: totalPrice,
                qty: qty,
                ctg: ctg,
                serviceTypes: serviceTypes,
                serviceName: serviceName,
                startDate: startDate,
                startTime: startTime,
                serviceAmount: serviceAmount,
                cart_type: cart_type,
                image: image,
                description: description,
                cart_ctg: cart_ctg,
                is_date_required: is_date_required,
                service_desc: service_desc,
                serviceOccurrencesNo: serviceOccurrencesNo,
                is_membership_discount: is_membership_discount,
                membership_discount_amt: membership_discount_amt,
                fullPackage: fullPackage
            },
            success: function(result) {
                console.log(result);
                updateCartCount();
                Swal.fire({
                    title: 'Added into Cart!',
                    showDenyButton: false,
                    showCancelButton: false,
                    icon: 'success',
                    confirmButtonText: 'Proceed to Checkout',
                    allowOutsideClick: false,
                    // denyButtonText: `Cancel`,
                }).then((result) => {

                    if (result.isConfirmed) {
                        $("#modalcalendersponser").modal("hide");
                        CartCheckLogin('sponsorships');

                    }
                });
                loader.off();
            }
        });


    }


    function ShowHideDesc(id) {
        // $("#descDiv"+id).toggle();
        var display = $("#descDiv" + id).css("display");
        if (display != "none") {
            $("#descDiv" + id).attr("style", "display:none!important");
        } else {
            $("#descDiv" + id).attr("style", "display:block!important");
        }
    }
</script>

<script>
    function generatePDF() {
        const pdfUrl = "<?php echo base_url('assets/pdf/Calendar-2025.pdf'); ?>";

        window.open(pdfUrl, '_blank');

    }
</script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>





<?php $this->load->view('includes/footer.php') ?>
<?php $this->load->view('includes/script.php') ?>