<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">
                    <!-- <a type="button" href="<?php echo base_url(); ?>coachingsearch" class="btn btn-custom waves-effect waves-light" >Add New Enrollment <span class="m-l-5"><i class="fa fa-plus"></i></span></a>                     -->
                </div>
                <h4 class="page-title">Program Members (<?php echo $business[0]['business_name'];?>):</h4>
            </div>
        </div>
        
        <div class="row" id="divselection">
            <div class="col-sm-12">
                <div class="card-box ">
                    <h4 class="header-title m-t-0 m-b-30">Filters:</h4>
                    <form action="<?php echo base_url();?>coaching_members/5" method="post">
                        <input type="hidden" name="csrf_test_name" id="members_csrf" value=""/>
                    <div class="row">
                        <div class="col-lg-12">
                            <div class="row">
                                <div class="col-lg-2">
                                    <div class="row">
                                        <div class="col-lg-12"> <label class="control-label">Select Program Type:</label></div>
                                    </div>
                                    <div class="row">
                                        <div class="col-lg-12"> 
                                            <select  class="form-control" id="coaching_service" name="coaching_service">
                                                <option >All</option>
                                                <?php foreach ($coaching_services as $cs) { ?>
                                                    <option <?php if($coaching_service===$cs['id_business_services']){echo 'selected="selected"';}?> value="<?php echo $cs['id_business_services']; ?>"><?php echo $cs['service_name']; ?></option>
                                                <?php } ?>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                                
                                <div class="col-lg-2">
                                    <div class="row">
                                        <div class="col-lg-12"> <label class="control-label">View:</label></div>
                                    </div>
                                    <div class="row">
                                        <div class="col-lg-12"> 
                                            <select class="form-control" id="filter_veiw" name="filter_veiw">                                               
                                                <option <?php if(isset($status)){if($status=='Active'){echo 'selected="selected"';}} ?> value="Active">Active</option>
                                                <option <?php if(isset($status)){if($status=='Completed'){echo 'selected="selected"';}} ?> value="Completed">Completed</option>
                                                <option <?php if(isset($status)){if($status=='All'){echo 'selected="selected"';}} ?> value="All">All</option>                                                
                                            </select>
                                        </div>
                                    </div>
                                </div>
                               
                                <div class="col-lg-2">
                                    <div class="row">
                                        <div class="col-lg-12"> <label class="control-label">Get Members</label></div>
                                    </div>
                                    <div class="row">
                                        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6" > 
                                            <button onclick="$('#members_csrf').val($('#cook').val());"  type="submit" class="btn btn-pink btn-bordred waves-effect w-md waves-light m-b-5">Run</button>
                                        </div>
                                        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6"><i id="cog" class="fa fa-spin fa-cog" style="display:none; font-size:26px;width: auto;margin-right: 10px;"></i></div>
                                    </div>
                                </div>

                            </div>
                        </div>
                    </div>
                    </form>
                </div>
            </div>
        </div>
        
        <div class="row" >
            <div class="col-sm-12">
                <div class="card-box ">
                    <h4 class="header-title m-t-0 m-b-30"></h4>
                    <div class="row">
                        <div class="col-lg-12">
                            <table id="datatable-buttons" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
                                <thead>
                                    <tr>
                                        <th>Roll ID</th>
                                        <th>Member #</th>
                                        <th>Name</th>
                                        <th>Cell</th>
                                        <th>Emergency</th>                                        
                                        <th>Father's Name</th>                                        
                                        <th>Program</th>
                                        <th>Total Sessions</th>
                                        <th>Scheduled</th>
                                        <th>Price</th>
                                        <th>Enrolled On</th>
                                        <th>Valid Till</th>
                                        <th>Action</th>                                        
                                        <th>Service Provisioning</th>                                       
                                    </tr>
                                </thead>
                                <tbody> 
                                     <?php  
                                        //  echo "<pre>";
                                        // print_r($program_members); 
                                     ?>
                                    <?php foreach($program_members as $pm){ ?>
                                    <tr class="<?php if($pm['valid_until'] <= date('Y-m-d')){echo " danger ";} else if($pm['total_sessions']==$pm['scheduled']){echo " info ";}?>">
                                        <td>
                                            <?php echo $pm['id_program_enrollment'];?>
                                        </td>
                                        <td> 
                                            <?php 
                                                if($pm['program_group_id'] !="" && $pm['program_group_id'] !=null){

                                                 echo $pm['service_name']." - ".$pm['program_group_id']." - ".$pm['id_customers'];
                                                }else{ 
                                                    echo $pm['service_name']." - ".$pm['id_customers'];
                                                } 
                                             ?>
                                    
                                        </td>
                                        <td>
                                            <?php echo $pm['customer_name'];?>
                                        </td>
                                        <td>
                                            <?php echo $pm['customer_cell'];?>
                                        </td>
                                        
                                        <td>
                                            <?php echo $pm['emergency_contact_number'];?>
                                        </td>
                                        <td>
                                            <?php echo $pm['father_name'];?>
                                        </td>                                        
                                        <td>
                                            <?php echo $pm['service_name'];?>
                                        </td>                                        
                                        <td>
                                            <?php echo $pm['total_sessions'];?>
                                        </td>
                                        <td>
                                            <?php echo $pm['scheduled'];?>
                                        </td>
                                        <td>
                                            <?php echo $pm['per_session_rate'];?>
                                        </td>
                                        <td>
                                            <?php echo $pm['added_on'];?>
                                        </td>     
                                        <td>
                                            <?php echo $pm['valid_until'];?>
                                        </td>     
                                        <td class='noprint'> 
                                            
                                            <?php if(COACHING_MODE == 'session'){?>
                                            <a target="mframe" href="<?php echo base_url(); ?>print_coaching_enrollment/<?php echo $pm['id_program_enrollment']; ?>" class="btn btn-sm btn-icon waves-effect waves-light btn-success m-b-5"> <i class="fa fa-file"></i> Payments</a>  
                                            <?php } elseif(COACHING_MODE == 'service'){ ?>
                                            <a target="mframe" href="<?php echo base_url(); ?>open_receivable_invoices/<?php echo $pm['id_program_enrollment']; ?>" class="btn btn-sm btn-icon waves-effect waves-light btn-success m-b-5"> <i class="fa fa-file"></i> Add Payment</a>  
                                            <a target="mframe" href="<?php echo base_url(); ?>print_all_invoices/<?php echo $pm['id_program_enrollment']; ?>" class="btn btn-sm btn-icon waves-effect waves-light btn-info m-b-5"> <i class="fa fa-dollar"></i> Invoices</a>  
                                            <?php } ?>
                                            
                                           
                                        </td> 
                                        
                                        <td>
                                            <?php if($pm['valid_until'] > date('Y-m-d')){?>
                                            <!--<form method="post" action="<?php //echo base_url().'coaching_controller/coaching_service_provisioning';?>">-->
                                                <input type="hidden" name="id_program_enrollment" value="<?php echo $pm['id_program_enrollment']; ?>">
                                                <input type="hidden" name="id_program_enrolled_services" value="<?php echo $pm['id_program_enrolled_services']; ?>">
                                                <input type="hidden" name="service_id" value="<?php echo $pm['service_id']; ?>"> 

                                                <?php  
                                                  if( $pm['total_sessions'] > $pm['scheduled'] ){ 
                                                    ?> 
                                                     <a href="<?php echo base_url().'coaching_service_provisioning/'.$pm['id_program_enrollment'].'/'.$pm['id_program_enrolled_services'].'/'.$pm['service_id'].'/'."0";?>" class="btn btn-sm btn-icon waves-effect waves-light btn-pink m-b-5"> <i class="fa fa-calendar"></i> Schedule</a>  
                                                    <?php 

                                                 } ?> 

                                                 <?php  
                                                  if($pm['scheduled'] >= $pm['total_sessions'] ){ 
                                                     ?> 
                                                     <a target="_blank" href="<?php echo base_url().'program_completion_certificate/'.$pm['id_program_enrollment'].'/'.$pm['id_program_enrolled_services'].'/'.$pm['service_id'].'/'."0";?>" class="btn btn-sm btn-icon waves-effect waves-light btn-pink m-b-5"><i class="fa fa-download" aria-hidden="true"></i>  Certificate </a>  
                                                     <?php 
                                                  } ?>
                                               
                                            <!--</form>-->
                                            <?php } ?>
                                            
                                            <a href="<?php echo base_url(); ?>coaching_register_edit/<?php echo $pm['id_program_enrollment']; ?>" class="btn btn-sm btn-icon waves-effect waves-light btn-primary m-b-5"> <i class="fa fa-pencil"></i> Edit</a>                                             
                                            
                                            <!--<a href="<?php echo base_url().'coaching_invoice_list/'.$pm['id_program_enrollment'];?>" class="btn btn-sm btn-icon waves-effect waves-light btn-success m-b-5"> <i class="fa fa-dollar"></i> Invoices</a>-->  
                                        </td>
                                        
                                    </tr>
                                    <?php } ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script>
    
    $('document').ready(function(){
       
       
       
       $('#datatable-buttons').DataTable({
                "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
                "stateSave": true,
                "dom": "Bfrtlip",
                "buttons": [{extend: "copy", className: "btn-sm btn-custom btn-trans"}, {extend: "csv", className: "btn-sm btn-pink btn-trans"}, {
                        extend: "excel",
                        className: "btn-sm btn-warning btn-trans"
                    }, {extend: "pdf", className: "btn-sm btn-purple btn-trans"}],
                "responsive": !0,
		"order": [[ 1, 'asc' ]],
		"displayLength": 25
		
            });
            //changeview();
    });
    
    function changeview(){
        $('#datatable-buttons tr').each(function(row, tr) {
            //$(this).css('display','');
            console.log( $(tr).find('td:eq(7)').text().trim());
            console.log( $(tr).find('td:eq(8)').text().trim());
            if(row>0){
                var total = $(tr).find('td:eq(7)').text().trim();
                var booked = $(tr).find('td:eq(8)').text().trim();
                var status='';

                if(parseInt(total) <= parseInt(booked)){status = 'Completed';}
                else if(total > booked) {status = 'Active';}

                if($("#filter_veiw").val() != 'All'){ 
                    if(status != $("#filter_veiw").val()){
                        $(this).css('display','none');            
                    }else{
                        $(this).css('display','');
                    }
                }else{
                    $(this).css('display','');
                }
            }
        });
    }
    
</script>