        <div class="wrapper">
            <div class="container">
                <!-- Page-Title -->
                <div class="row">
                    <div class="col-sm-12">
                        <div class="btn-group pull-right m-t-15">
                            <button id="btnPBooking" class="btn btn-primary waves-effect waves-light" onclick="open_PBooking();">
                                Add Booking
                            </button>
                        </div>
                        <h4 class="page-title">Bookings</h4>
                    </div>
                </div>
                
                 <div class="row">
                    <div class="col-sm-12">
                        <div class="card-box table-responsive">
                            <div class="row">
                                <form method="Post" action="">
                                <div class="col-md-2">
                                    <label class="form-label">Date</label>
                                    <input class="form-control"  name="myDate" id="myDate" value="<?php echo $myDate; ?>">
                                </div>
                                <div class="col-md-2">
                                    <label class="form-label">Action</label><br>
                                    <button type="submit" class="btn btn-primary ">Run</button>
                                </div>
                                </form>
                            </div>
                            <div class="row">
                                <h4 class="header-title m-t-0 m-b-30">&nbsp;</h4>

                                <table id="tblbookings" class="table  table-bordered dt-responsive nowrap" cellspacing="0" width="100%" style="color:#000 !important;">
                                    <thead>
                                        <tr>
                                            <th>Visit ID</th>
                                            <th>Visit Date</th>
                                            <th>Visit End</th>
                                            <th>Remarks</th>
                                            <th>Booking For</th>
                                            <th>Customer</th>
                                            <th>Customer Cell</th>
                                            <th>Type</th>
                                            <?php if($this->session->userdata('role')!=="Sh-Users"){?>
                                            <th>Rate</th>
                                             <th>Discount</th>  
                                            <th>Advance</th>
                                            <th>Payment Mode</th>

                                            <th>Remaining</th>
                                            <?php } ?>
                                            <th>Action</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php $lastid=0; foreach ($bookings as $booking){ $visitid=$booking['visit_id']; 
                                            if($lastid !== $visitid) {
                                        ?>
                                        <tr>
                                            <td style="background-color: <?php echo $booking['service_color']."90"; ?>;"><?php echo $booking['visit_id']; ?></td>
                                            <td style="background-color: <?php echo $booking['service_color']."90"; ?>;"><?php echo $booking['visit_date']; ?></td>
                                            <td style="background-color: <?php echo $booking['service_color']."90"; ?>;"><?php echo $booking['visit_date_end']; ?></td>
                                            <td style="background-color: <?php echo $booking['service_color']."90"; ?>;"><?php echo $booking['advance_comment']; ?></td>
                                            <td style="background-color: <?php echo $booking['service_color']."90"; ?>;"><?php echo $booking['service_type']; ?></td>
                                            <td style="background-color: <?php echo $booking['service_color']."90"; ?>;"><?php echo $booking['customer_name']; ?></td>
                                            <td style="background-color: <?php echo $booking['service_color']."90"; ?>;"><?php 
                                                    if( $this->session->userdata('hide_cell') && $this->session->userdata('hide_cell') == "No"){
                                                      echo  $booking['customer_cell'];
                                                    } 
                                                ?></td>
                                            <td style="background-color: <?php echo $booking['service_color']."90"; ?>;"><?php echo $booking['customer_email']; ?></td>
                                             <?php if($this->session->userdata('role')!=="Sh-Users"){?>
                                             <td style="background-color: <?php echo $booking['service_color']."90"; ?>;"><?php echo $booking['rate']; ?></td>
                                             <td style="background-color: <?php echo $booking['service_color']."90"; ?>;"><?php echo $booking['discount']; ?></td>
                                            <td style="background-color: <?php echo $booking['service_color']."90"; ?>;"><?php echo $booking['advance_amount']; ?></td>                                         
                                            <td style="background-color: <?php echo $booking['service_color']."90"; ?>;"><?php echo $booking['advance_mode']; ?></td>
                                            <td style="background-color: <?php echo $booking['service_color']."90"; ?>;"><?php echo $booking['rate']-($booking['discount']+$booking['advance_amount']); ?></td>

                                            <?php } ?>
                                            <td style="background-color: <?php echo $booking['service_color']."90"; ?>;">
                                                <a target="_blank" href="<?php echo base_url().'print_booking/'.$booking['visit_id']; ?>" class="btn btn-primary waves-effect waves-light m-b-5"> <i class="fa fa-print m-r-5"></i> <span>Open</span> </a>
                                                <button onclick="duplicate_booking(<?php echo $booking['booking_id']; ?>);" class="btn btn-pink waves-effect waves-light m-b-5"> <i class="fa fa-copy m-r-5"></i> Duplicate</button>
                                            </td>
                                        </tr>

                                        <?php $lastid=$visitid; }} ?>
                                    </tbody>
                                    <tfoot>
                                        <tr>
                                            <th></th>
                                            <th></th>
                                            <th></th>
                                            <th></th>
                                            <th></th>
                                            <th></th>
                                            <th></th>
                                             <?php if($this->session->userdata('role')!=="Sh-Users"){?>
                                            <th></th>
                                            <th></th>
                                            <th></th>
                                            <th></th>
                                            <th></th>
                                            <?php } ?>
                                            <th></th>

                                        </tr>
                                    </tfoot>
                                </table>
                             </div>
                        </div>
                    </div><!-- end col -->
                </div>
                <!-- end row -->
            </div>
    <div class="modal fade none-border" id="duplicatemodal" tabindex="-1" role="dialog" aria-labelledby="" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title"><strong>Make Copies of the Selected Booking:</strong></h4>
                </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="form-label">Number of Copies:</label>
                            <input id="numofcopies" class="form-control numeric" type="number" max=10 min=1 value="1">
                            <input id="duplicatebookingid" class="form-control" type="hidden">
                        </div>                        
                    </div>
                    <div class="col-md-6">
                        <p class="text-primary" style="font-size:14px;">
                            This Action will make the entered number of COPIES of all the services within the booking.<br>
                            These services will be assigned to the same STAFF and same DATETIME as the original service.<br>
                            <span class="text-pink" style="font-size:16px;"><strong>NOTE: </strong>  ADVANCES WILL NOT BE COPIED WITH THE SERVICES</span>
                        </p>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <div class="row">
                    <div class="">
                    <button onclick="create_duplicates();" class="pull-right btn btn-pink">Go</button>
                    </div>                    
                </div>
            </div>
      </div>
                
                
    <script type="text/javascript">
        $(document).ready(function() {

            $("#myDate").datepicker({
                autoclose: true,
                todayHighlight: true,
                format: 'yyyy-mm-dd'
            });



             $('#tblbookings').DataTable({
                lengthMenu: [[10, 25, 50, -1], [10, 25, 50, "All"]],
                stateSave: true,
                fixedHeader: {header: true},
                <?php if(DOWNLOAD == true || $this->session->userdata('role') == 'Admin' || $this->session->userdata('role')=='Super User'){ ?>
                    dom: "Bfrtlip",
                    buttons: [{extend: "copy", className: "btn-sm btn-custom btn-trans"}, {extend: "csv", className: "btn-sm btn-pink btn-trans", footer: true}, {
                            extend: "excel",
                            className: "btn-sm btn-warning btn-trans"
                        }, {extend: "pdf", className: "btn-sm btn-purple btn-trans", footer: true}
                    , {extend: "print", className: "btn-sm btn-primary btn-trans", footer: true}],
                <?php } else { ?>
                    dom: "frtlip",
                <?php } ?>
                    responsive: !0,
                    //"scrollX": true,
            });
            
        });
        function open_PBooking(){
             <?php if($this->session->userdata('role')=="Sh-Users"){?>
                window.location.assign('<?php echo base_url();?>sh_period_booking');     
             <?php } else { ?>
                window.location.assign('<?php echo base_url();?>period_booking');
             <?php } ?>
        }

        function duplicate_booking(bookingid){

            $("#duplicatebookingid").val(bookingid);
            $("#duplicatemodal").modal('show');
        }

        function create_duplicates(){
            var numofcopies = $("#numofcopies").val();
            var bookingid = $("#duplicatebookingid").val();
            if(numofcopies > 0){

                $.ajax({
                    type: 'POST',
                    url: '<?php echo base_url(); ?>bookings_controller/duplicate_booking',
                    data: { 'booking_id':bookingid, 'numofcopies':numofcopies },
                    dataType: "text",
                    cache: false,                    
                    success: function (data) {
                        location.reload();
                    }
                });

            }

        }
    </script>
