<style>
     tr.strikethrough > td {text-decoration:line-through !important; color:red;} 
</style>

<div class="wrapper">
    <div class="container">
        <!-- Page-Title -->
        <div class="row">
            <div class="col-sm-12">
                <h4 class="page-title">Edit Enrollment In Coaching Program: <?php if(isset( $program_enrollment)){ echo  $program_enrollment->customer_name;}?></h4>
            </div>
        </div>
        <?php if ($this->session->flashdata('Success') && $this->session->flashdata('Success') != "") { ?>
            <div class="row">
                <div class="col-sm-12">
                    <div class="alert alert-success">
                        <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
                        <strong>Success!</strong> <?php echo $this->session->flashdata('Success'); ?>
                    </div>
                </div>
            </div>
        <?php } ?>
        <?php if ($this->session->flashdata('Error') && $this->session->flashdata('Error') != "") { ?>
            <div class="row">
                <div class="col-sm-12">
                    <div class="alert alert-danger">
                        <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
                        <strong>Error!</strong> <?php echo $this->session->flashdata('Error'); ?>
                    </div>
                </div>
            </div>
        <?php } ?>
        <div class="row" id="divselection">
            <div class="col-sm-12">                
                <div class="card-box ">
                    
                            <div class="row m-t-20 m-b-20">
                                <div class="col-lg-12">
                                   <h4 class="title txt-primary" ><strong style='border-bottom: #808080 solid 1px '>Program Enrollment:</strong></h4>
                                </div>
                            </div>
                            
                            <div class="row m-t-20 m-b-20">
                                <?php if($program_enrollment->valid_until <= date('Y-m-d')){ ?>
                                <div class="col-md-6">
                                    <span style="font-size:13px;" class="control-label text-danger">
                                        This Enrollment Has Expired!
                                    </span>
                                </div>
                                <div class="col-md-6">
        <!--                                    <form id="extendvalidityform" method="post" action="<?php// echo base_url();?>coaching_controller/extend2days">
                                    <input name='eid' type='hidden' value='<?php //echo $program_enrollment->id_program_enrollment; ?>'>    
                                    <span style="font-size:13px; font-weight: bold;"  class="control-label text-info">
                                        Do you want to extend the Validity for 2 more days?
                                        <button type="submit" class="btn btn-sm btn-pink">Yes</button>                                               
                                    </span>
                                    </form>-->
                                </div>
                                 <?php } else { ?>
                                <div class="col-md-6">
                                    <span style="font-size:13px;" class="control-label text-default">
                                        <strong>This Enrollment is Valid Till : <?php echo date_format(date_create($program_enrollment->valid_until), 'd-m-Y');?></strong>
                                </div>
                                <div class="col-md-6">
                                </div>
                    
                                <?php } ?>
                            </div>
                           
                            <div class="row">
                                <input type="hidden" name="programenrollmentid" id="programenrollmentid" value="<?php echo $program_enrollment->id_program_enrollment; ?>"/>
                                <input type="hidden" name="program_type" id="program_type" value="<?php if(isset($enrolled_services[0]['service_category'])){echo $enrolled_services[0]['service_category'];} ?>"/>
                                <div class="col-lg-2">
                                    <label for="txtprograms" class="control-label">Program</label>                                    
                                    <select tabindex="27" id="txtprograms" name="txtprograms" class="form-control" onchange="fillservicedetail(),get_group_by_program()" required="required">
                                        <option></option>
                                        <?php foreach($services as $service){ ?>
                                        <option rate="<?php echo $service['service_rate']; ?>" value="<?php echo $service['id_business_services']; ?>"><?php echo $service['service_name']; ?></option>
                                        <?php } ?>
                                    </select>                                    
                                </div> 
                                <div class="col-lg-2" <?php  if($flag_for_individual_or_group  == "individual_client"){ ?> style="display:none" <?php  }else{ ?> style="display:block" <?php }  ?>> 
                                    <label for="txtprograms" class="control-label">Program Groups</label>                                    
                                    <select tabindex="27" id="txtprogramsgroup" name="txtprogramsgroup" class="form-control"   onchange="getting_group_sessions_and_set_in_total_session();">
                    
                                    </select>                                    
                                </div>
                                <div class="col-lg-2">
                                    <label for="txtpsessionprice" class="control-label">Price Per Session</label>
                                    <input tabindex="28" type="text" class="form-control numeric" placeholder="Session price" id="txtpsessionprice" name="txtpsessionprice" required="required" min="0" value="0">
                                </div> 
                                <div class="col-lg-2">
                                    <label for="txttotalsessions" class="control-label">Total Session</label>
                                    <input tabindex="29"  type="text" class="form-control numeric" placeholder="Total Sessions" id="txttotalsessions" name="txttotalsessions" required="required" min="1" value="1" oninput="calculate_total_program_price_with_session()" <?php  if($flag_for_individual_or_group  == "individual_client"){ ?>  <?php  }else{ ?> readonly <?php }  ?>>
                                </div> 
                                <div class="col-lg-1">
                                    <label for="txttotalsessions" class="control-label">Discount</label>
                                    <input tabindex="29" type="text" class="form-control numeric" placeholder="Total Sessions" id="program_discount_perc" name="program_discount" required="required" min="1" value="0" oninput="calculate_total_program_price_with_session()"> 
                                </div> 
                                <div class="col-lg-2">
                                    <label for="txttotalsessions" class="control-label">Other Charges</label>
                                    <input tabindex="29" type="text" class="form-control numeric"  id="othercharges" name="othercharges" required="required" min="1" value="0" oninput="calculate_total_program_price_with_session()"> 
                                    <h4 class="text-pink text-right" id="price_with_session"></h4>
                                </div>
                                <div class="col-lg-1">                                   
                                    <button tabindex="30" type="button" onclick="addnewservice();" class='btn btn-sm btn-primary m-t-20'><i class="fa fa-arrow-down"></i> Add</button>                                    
                                </div>
                                
                            </div>
                            <div class="row">
                                <div class="col-md-12">
                                    <table id="tblservices" name="tblservices" class="table">
                                        <thead>
                                            <th class="hidden">service_id</th>
                                            <th>Program</th>
                                            <th>Per Session Rate</th>
                                            <th>Total Session</th>
                                            <th>Discount</th>
                                            <th>Other Charges</th>
                                            <th>Status</th>
                                            <th></th>
                                            <th></th>
                                        </thead>
                                        <tbody>  
                        
                                            <?php foreach($enrolled_services as $service){?>
                                            <?php if($service['service_status']=='InActive'){$class='strikethrough';}else{$class='';} ?>
                                            <tr class="<?php echo $class; ?>">                                            
                                                <td class="hidden"><?php echo $service['service_id']; ?></td>
                                                <td><?php echo $service['service_name']; ?></td>
                                                <td>
                                                    <input name="registered_rate" id="registered_rate_<?php echo $service['service_id'];?>" style="border:none" type="number" value="<?php echo $service['per_session_rate']; ?>">
                                                </td>
                                                <td><input onchange="if($(this).val() < <?php echo $service['total_sessions'];?>){$(this).val(<?php echo $service['total_sessions'];?>)}" name="registered_sessions" id="registered_sessions_<?php echo $service['service_id'];?>" style="border:none" type="number" min="<?php echo $service['total_sessions']; ?>" max="50" value="<?php echo $service['total_sessions']; ?>"></td> 
                                                <td><?php  echo $service['invoice_discount']; ?></td>
                                                <td><?php  echo $service['invoice_other_charges']; ?></td>
                                                <td><?php echo $service['service_status']; ?></td>
                                                <td><a target="_blank" href="<?php echo base_url(); ?>print_all_invoices/<?php echo $program_enrollment->id_program_enrollment;?>" class="btn btn-xs btn-default"><i class="fa fa-icon fa-print"></i> Print</a></td>
                                                <!-- <td><button onclick="update_sessions(<?php echo $service['service_id']; ?>,<?php echo $program_enrollment->id_program_enrollment; ?>)" class="btn btn-xs btn-success"><i class="fa fa-icon fa-plus"></i> Update</button></td> --> 
                                                <?php 
                                                  if($service['paid_amount'] <=0){ 
                                                     ?>
                                                    <td><button onclick="remove_service(<?php echo $service['service_id']; ?>,<?php echo $program_enrollment->id_program_enrollment; ?>,<?php echo $service['id_program_enrolled_services']; ?>);" class="btn btn-xs btn-danger"><i class="fa fa-icon fa-trash"></i></button></td>                                            
                                                    <?php 
                                                  }
                                                ?>
                                            </tr>
                                            <?php } ?>
                                        </tbody>
                                        <tfoot></tfoot>
                                    </table>
                                </div>
                            </div>
                    <hr>
                    
                    
                    
                    <h4 class="header-title m-t-0 m-b-30"></h4>
                    <form id="detailsform" method="post" action="<?php echo base_url(); ?>coaching_controller/edit_enrollment">
                        <input type="hidden" name="csrf_test_name" id="training_customer_csrf" value=""/>
                        <input type="hidden" name="txtprogramenrollmentid" id="txtprogramenrollmentid" value="<?php echo $program_enrollment->id_program_enrollment; ?>"/>
                        
                        <div class="form-group">
                             <div class="divider"></div>
                             <div class="row">
                                <div class="col-lg-12">
                                    <h3 class="title text-primary"><strong>Customer Details:</strong></h3>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-lg-3">
                                    <div class="form-group">
                                        <label for="txtcustomername" class="control-label"><span class='text-pink'>*</span> Name</label>
                                        <input type="hidden" class="form-control" placeholder="Customer ID" id="txtcustomerid" name="txtcustomerid" value="<?php if(isset($program_enrollment)){ echo $program_enrollment->id_customers;}?>">
                                        <input tabindex="1" type="text" class="form-control" placeholder="Customer Name" id="txtcustomername" name="txtcustomername" value="<?php if(isset( $program_enrollment)){ echo  $program_enrollment->customer_name;}?>" required="required">
                                    </div>
                                </div>
                                <div class="col-lg-3">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="txtcustomercell" class="control-label"><span class='text-pink'>*</span> Cell</label>
                                            <input tabindex="2" type="text" class="form-control numeric" placeholder="Customer Cell" id="txtcustomercell" name="txtcustomercell" value="<?php if(isset($program_enrollment)){ echo  $program_enrollment->customer_cell;}?>" requried='required'>
                                        </div> 
                                    </div> 
                                </div>
                                <div class="col-lg-3">
                                    <div class="form-group">
                                        <label for="txtcustomerphone1" class="control-label">Phone 1</label>
                                        <input tabindex="3" type="text" class="form-control numeric" placeholder="Customer Phone 1" id="txtcustomerphone1" name="txtcustomerphone1" value="<?php if(isset($program_enrollment)){ echo $program_enrollment->customer_phone1;}?>">
                                    </div>                                    
                                </div>
                                <div class="col-lg-3">
                                    <div class="form-group">
                                        <label for="txtcustomerphone2" class="control-label">Phone 2</label>
                                        <input tabindex="4" type="text" class="form-control numeric" placeholder="Customer Phone 2" id="txtcustomerphone2" name="txtcustomerphone2" value="<?php if(isset($program_enrollment)){ echo $program_enrollment->customer_phone2;}?>">
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label for="txtcustomergender" class="control-label">Gender</label>
                                        <select tabindex="2" type="text" class="form-control numeric" placeholder="Gender" id="txtcustomergender" name="txtcustomergender" >
                                            <option value="F" <?php if(isset($program_enrollment) && $program_enrollment->customer_gender==="F"){ echo "selected";}?>>Female</option>
                                            <option value="M" <?php if(isset($program_enrollment) && $program_enrollment->customer_gender==="M"){ echo "selected";}?>>Male</option>
                                        </select>
                                    </div> 
                                </div>
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label for="txtcustomertype" class="control-label">Type</label>
                                        <select tabindex="5" name="txtcustomertype" id="txtcustomertype" class="form-control">
                                           
                                            <option value=""></option>
                                            <option value="orange" <?php if(isset($program_enrollment) && $program_enrollment->customer_type=="orange"){echo "selected='selected'";}?>><i style="color:orange" class="ti ti-star"></i> (Orange) High Priority Customer</option>
                                            <option value="green" <?php if(isset($program_enrollment) && $program_enrollment->customer_type=="green"){echo "selected='selected'";}?>><i class="ti ti-face-smile"></i> (Green) General Customer</option>
                                            <option value="red" <?php if(isset($program_enrollment) && $program_enrollment->customer_type=="red"){echo "selected='selected'";}?>><i class="ti ti-hand-stop"></i> (Red) Flagged Customer</option>
                                                    
                                        </select>
                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label for="txtcustomercard" class="control-label">Card #</label>
                                        <input tabindex="4" type="text" class="form-control numeric" placeholder="Customer Card#" id="txtcustomercard" name="txtcustomercard" value="<?php if(isset($program_enrollment)){ echo $program_enrollment->customer_card;}?>">
                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label for="txtcustomerprofession" class="control-label">Profession</label>
                                        <input tabindex="6" type="text" class="form-control" placeholder="Customer Profession" id="txtcustomerprofession" name="txtcustomerprofession" value="<?php if(isset($program_enrollment)){ echo $program_enrollment->profession;}?>">
                                    </div> 
                                </div>
                            </div>
                            
                            <div class="row">
                                <div class="col-lg-3">
                                    <div class="form-group">
                                        <label for="txtcustomeremail" class="control-label">Email</label>
                                        <input tabindex="7" type="email" class="form-control " placeholder="Customer Email" id="txtcustomeremail" name="txtcustomeremail" value="<?php if(isset($program_enrollment)){ echo $program_enrollment->customer_email;}?>">
                                    </div>
                                </div>
                                
                                <div class="col-lg-6">
                                    <div class="form-group">
                                        <label for="txtcustomeraddress" class="control-label">Address</label>
                                        <input tabindex="8" type="text" class="form-control " placeholder="Customer Address" id="txtcustomeraddress" name="txtcustomeraddress" value="<?php if(isset($program_enrollment)){ echo $program_enrollment->customer_address;}?>">
                                    </div>
                                </div>
                                <div class="col-lg-3">
                                    <div class="form-group">
                                        <div class="col-sm-12">
                                            <label for="txtcustomeranniversary" class="control-label">Wedding Anniversary</label>
                                        </div>
                                        <div class="col-sm-12">
                                            <div class="input-group">
                                                <input tabindex="9" type="text" class="form-control" placeholder="yyyy/mm/dd" id="txtcustomeranniversary" name="txtcustomeranniversary" value="<?php if(isset($program_enrollment)){ echo $program_enrollment->customer_anniversary;}?>">
                                                <span class="input-group-addon bg-info b-0 text-white"><i class="ti ti-calendar"></i></span>
                                            </div><!-- input-group -->
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="row">
                                <div class="col-lg-3">
                                     <div class="form-group">
                                        <div class="col-lg-12">
                                            <label for="txtcustomerbirthday" class="control-label">Birthday</label>
                                        </div>
                                        <div class="col-lg-4">
                                            <select tabindex="10" id="txtcustomerbirthday" name="txtcustomerbirthday" class="form-control">
                                                <option value=""></option>
                                                <?php $x=1; while($x <= 31) {?>
                                                    <option value='<?php echo $x;?>' <?php if(isset($program_enrollment) && $program_enrollment->customer_birthday==$x){echo "selected='selected'";}?>><?php echo $x;?></option>                                                    
                                                <?php $x++; } ?>
                                            </select>
                                        </div>
                                        <div class="col-lg-8">
                                            <select tabindex="11" id="txtcustomerbirthmonth" name="txtcustomerbirthmonth" class="form-control">
                                                <option value=""></option>
                                                <option value="January" <?php if(isset($program_enrollment) && $program_enrollment->customer_birthmonth=="January"){echo "selected='selected'";}?>>January</option>
                                                <option value="February" <?php if(isset($program_enrollment) && $program_enrollment->customer_birthmonth=="February"){echo "selected='selected'";}?>>February</option>
                                                <option value="March" <?php if(isset($program_enrollment) && $program_enrollment->customer_birthmonth=="March"){echo "selected='selected'";}?>>March</option>
                                                <option value="April" <?php if(isset($program_enrollment) && $program_enrollment->customer_birthmonth=="April"){echo "selected='selected'";}?>>April</option>
                                                <option value="May" <?php if(isset($program_enrollment) && $program_enrollment->customer_birthmonth=="May"){echo "selected='selected'";}?>>May</option>
                                                <option value="June" <?php if(isset($program_enrollment) && $program_enrollment->customer_birthmonth=="June"){echo "selected='selected'";}?>>June</option>
                                                <option value="July" <?php if(isset($program_enrollment) && $program_enrollment->customer_birthmonth=="July"){echo "selected='selected'";}?>>July</option>
                                                <option value="August" <?php if(isset($program_enrollment) && $program_enrollment->customer_birthmonth=="August"){echo "selected='selected'";}?>>August</option>
                                                <option value="September" <?php if(isset($program_enrollment) && $program_enrollment->customer_birthmonth=="September"){echo "selected='selected'";}?>>September</option>
                                                <option value="October" <?php if(isset($program_enrollment) && $program_enrollment->customer_birthmonth=="October"){echo "selected='selected'";}?>>October</option>
                                                <option value="November" <?php if(isset($program_enrollment) && $program_enrollment->customer_birthmonth=="November"){echo "selected='selected'";}?>>November</option>
                                                <option value="December" <?php if(isset($program_enrollment) && $program_enrollment->customer_birthmonth=="December"){echo "selected='selected'";}?>>December</option>
                                            </select>
                                        </div>

                                    </div>
                                </div>
                                <div class="col-lg-3">
                                    <div class="form-group">
                                        <label for="txtcustomerallergies" class="control-label text-danger">Allergies Alert</label>
                                        <input tabindex="12" type="text" class="form-control " placeholder="Note down any allergies the customer may have" id="txtcustomerallergies" name="txtcustomerallergies" value="<?php if(isset($program_enrollment)){ echo $program_enrollment->customer_allergies;}?>">
                                    </div> 
                                </div>
                                <div class="col-lg-3">
                                    <div class="form-group">
                                        <label for="txtcustomeralert" class="control-label text-warning">Customer Alert</label>
                                        <input tabindex="13" type="text" class="form-control " placeholder="Note down any other alerts you want to get when the customer visits . . ." id="txtcustomeralert" name="txtcustomeralert" value="<?php if(isset($program_enrollment)){ echo $program_enrollment->customer_alert;}?>">
                                    </div>
                                </div>
                                <div class="col-lg-3">
                                    
                                </div>
                            </div>
                            <!----Training Items--->
                             <div class="divider"></div>
                             <div class="row">
                                <div class="col-lg-12">
                                    <h3 class="title text-primary"><strong>Training Related Info:</strong></h3>
                                </div>
                            </div>
                            <div class="row m-t-20 m-b-20">
                                <div class="col-lg-12">
                                   <h4 class="title txt-primary" ><strong style='border-bottom: #808080 solid 1px '>Basic Info:</strong></h4>
                                </div>
                            </div>
                            
                            <div class="row ">
                                <div class="col-md-6 form-horizontal">
                                    <div class="form-group">
                                        <label for="txtemergencyperson" class="col-md-4 control-label "><span class="text-pink">*</span> Emergency Contact Person</label>
                                        <div class="col-md-8">
                                            <input tabindex="14" type="text" class="form-control" placeholder="Emergency Contact Person" id="txtemergencynumber" name="txtemergencyperson" required="required" value="<?php if(isset($program_enrollment)){ echo $program_enrollment->emergency_contact_person;}?>">
                                        </div>
                                    </div>
                                    
                                    <div class="form-group">
                                        <label for="txtemergencynumber" class="col-md-4 control-label "><span class="text-pink">*</span> Emergency Contact Number</label>
                                        <div class="col-md-8">
                                            <input tabindex="15" type="text" class="form-control numeric" placeholder="Emergency Contact Number" id="txtemergencynumber" name="txtemergencynumber" required="required" value="<?php if(isset($program_enrollment)){ echo $program_enrollment->emergency_contact_number;}?>">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="txtage" class="col-md-4 control-label">Age</label>
                                        <div class="col-md-8">
                                            <input tabindex="16" type="text" class="form-control numeric" placeholder="Age" id="txtage" name="txtage" value="<?php if(isset($program_enrollment)){ echo $program_enrollment->age;}?>">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="txtgoals" class="col-md-4 control-label">Learning Goals</label>
                                        <div class="col-md-8">
                                            <textarea tabindex="17" type="text" class="form-control" placeholder="Goals" id="txtgoals" name="txtgoals" value="<?php if(isset($program_enrollment) && isset($program_enrollment->goals)){ echo $program_enrollment->goals;}?>"></textarea>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-lg-6 form-horizontal">
                                    
                                    <div class="form-group">
                                        <label for="txteducation" class="col-md-4 control-label ">Last Level of Education Completed</label>
                                        <div class="col-md-8">
                                            <input tabindex="18" type="text" class="form-control" placeholder="Education" id="txteducation" name="txteducation" value="<?php if(isset($program_enrollment)&& isset($program_enrollment->education)){ echo $program_enrollment->education;}?>">
                                        </div>
                                    </div>
                                    
                                   
                                     <div class="form-group">
                                        <label for="txtbeautyeducation" class="col-md-4 control-label">Previous Beauty Education</label>
                                        <div class="col-md-8">
                                            <input tabindex="20" type="text" class="form-control" placeholder="Beauty Related Education" id="txtbeautyeducation" name="txtbeautyeducation" value="<?php if(isset($program_enrollment) ){ echo $program_enrollment->beautyeducation;}?>">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="txtexperience" class="col-md-4 control-label">Previous Beauty Experience</label>
                                        <div class="col-md-8">
                                            <input tabindex="21" type="text" class="form-control" placeholder="Experience" id="txtexperience" name="txtexperience" value="<?php if(isset($program_enrollment) && isset($program_enrollment->experience)){ echo $program_enrollment->experience;}?>">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <hr/>
                                
                             <div class="row m-t-20">
                                <div class="col-md-6">
                                    <div class="btn-group pull-right m-t-15">
                                        
                                        <button type="button" onclick="$('#training_customer_csrf').val($('#cook').val()); submit_form();" class="btn waves-effect waves-light btn-pink m-t-20">Save</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>    
    </div>
</div>

<script>
    $(document).ready(function () {

        $("#txtprograms").select2();
        $("#txtprogramsgroup").select2();  

        $(document).on('click', '#othercharges,#program_discount_perc', function() {
            this.select();
        });
        $(document).on('input', '#program_discount_perc', function() { 
             var program_discount = parseFloat($(this).val()) || 0; 
                if(program_discount >0 ) {
                  $("#othercharges").val(0);
                } 
             calculate_total_program_price_with_session();
        });
        $(document).on('input', '#othercharges', function() { 
            var othercharges = parseFloat($(this).val()) || 0; 
            if(othercharges >0){
             $("#program_discount_perc").val(0);
            } 
            calculate_total_program_price_with_session();
        });

        toastr.options = {
            "closeButton": true,
            "debug": true,
            "newestOnTop": true,
            "progressBar": true,
            "positionClass": "toast-bottom-center",
            "preventDuplicates": true,
            "onclick": null,
            "showDuration": "300",
            "hideDuration": "1000",
            "timeOut": "5000",
            "extendedTimeOut": "1000",
            "showEasing": "swing",
            "hideEasing": "linear",
            "showMethod": "fadeIn",
            "hideMethod": "fadeOut"
        }

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

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

        $(".numeric").keypress(function (e) {
            //if the letter is not digit then display error and don't type anything
            if (e.which != 13 && e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
                return false;
            }
        });
        $(".decimal").keypress(function(e) {
            //if the letter is not digit then display error and don't type anything
            if (e.which != 13 && e.which != 8 && e.which != 0  && e.which != 46 && (e.which < 48 || e.which > 57) ) {
                
                return false;
            }
        });
    });

    function getprogramsessions(){
         $("#txtprogramsessions").html('<option></option>');
         
         $.ajax({
            type: 'POST',
            url: "<?php echo base_url() . 'programs_controller/get_active_sessions'; ?>",
            data: {programid: $("#txtprograms option:selected").val()},
            dataType: "json",
            cache: false,
            async: true,
            success: function(data) {
               
                var mhtml = '';
                for (x = 0; x < data.length; x++) {
                    mhtml='<option value="'+ data[x]['id_program_sessions'] +'">'+ data[x]['start'] +' - ' + data[x]['end'] + '</option>'
                }
                
                $("#txtprogramsessions").append(mhtml);
            }
        });
    }


    function addnewservice(){ 

        if($("#txtprogramsgroup").val() == ''){ 
             swal({
                title: 'Please Select Group First.',
                text: "",
                type: 'info',
                showCancelButton: false,
                confirmButtonColor: '#ff5b5b',
                confirmButtonText: 'Ok'
             }); 
            return false;   
         } 
        $.ajax({
           type: 'POST',
            url: "<?php echo base_url() . 'coaching_controller/add_service_to_enrollment'; ?>",
            data: {
                    customer_id: <?php echo  $program_enrollment->customer_id;?>,
                    customer_name: '<?php echo  $program_enrollment->customer_name;?>',
                    service_id: $("#txtprograms option:selected").val(), 
                    enrollment_id: $("#programenrollmentid").val(), 
                    service_name: $("#txtprograms option:selected").text(),
                    per_session_rate: $("#txtpsessionprice").val(),
                    program_discount: $("#program_discount_perc").val(),
                    program_group_id: $("#txtprogramsgroup").val(),
                    total_sessions: $("#txttotalsessions").val(),
                    other_charges: $("#othercharges").val()
                },
            cache: false,
            async: true,
            success: function(data) {  
                var r = data.split(","); 
                // Check if the first part of the split string is "Warning_of_validation"
                if (r[0].trim() === "Warning_of_validation") { 
                    swal({
                        title: 'One of the groups you have selected already has a student in it.',
                        text: "",
                        type: 'info',
                        showCancelButton: false,
                        confirmButtonColor: '#ff5b5b',
                        confirmButtonText: 'Ok'
                    }); 
                    return false; 
                } else { 
                    toastr.success('New Service Added!');
                    location.reload(); 
                }
           }
        });

    }
    
    function fillservicedetail(){ 

        $("#txtpsessionprice").val($("#txtprograms option:selected").attr('rate')) ; 
        calculate_total_program_price_with_session();
    
    }
    
    function remove_service(serviceid, enrollmentid,id_program_enrolled_services){
        $.ajax({
           type: 'POST',
            url: "<?php echo base_url() . 'coaching_controller/remove_service_from_enrollment'; ?>",
            data: {service_id: serviceid, 
                    enrollment_id: enrollmentid ,
                    program_enrolled_services_id:id_program_enrolled_services
                },
            dataType: "json",
            cache: false,
            async: true,
            success: function(data) { 
                // console.log(data,"data");
                toastr.success('Service Removed!');
                location.reload();
           }
        });
    }
    
    function update_sessions(serviceid, enrollmentid){
        var elem = "#registered_sessions_"+serviceid;
        var elem1 = "#registered_rate_"+serviceid;
        var total_sessions = $(elem).val();    
        var session_rate = $(elem1).val();   
        
        $.ajax({
           type: 'POST',
            url: "<?php echo base_url() . 'coaching_controller/update_service_enrollment_sessions'; ?>",
            data: {service_id: serviceid, 
                    enrollment_id: enrollmentid,
                    total_sessions: total_sessions,
                    session_rate: session_rate
                },
            dataType: "json",
            cache: false,
            async: true,
            success: function(data) {
                toastr.success('Service Removed!');
                location.reload();
           }
        });
    } 


    function calculate_total_program_price_with_session(){ 
        var price =  parseFloat($("#txtpsessionprice").val()) || 0; 
        var total_session =  parseFloat($("#txttotalsessions").val()) || 0;  
        var discount  =  parseFloat($("#program_discount_perc").val()) || 0;   
        var othercharges = parseFloat($("#othercharges").val()) || 0;  

        var price_with_sessions =  (price*total_session)-discount;  
        if(othercharges > 0){
            price_with_sessions =(price*total_session)+othercharges;
        } 
        if(discount > (price*total_session)){

                       swal({
                            title: 'We cannot offer a discount greater than the total price.',
                            text: "",
                            type: 'info',
                            showCancelButton: false,
                            confirmButtonColor: '#ff5b5b',
                            confirmButtonText: 'Ok'
                        }); 
           return false;             
        }
        $("#price_with_session").text("Final Price : "+ parseFloat(price_with_sessions).toFixed(1));
    }  


    function get_group_by_program(){
      var  program_id = parseFloat($("#txtprograms").val());  
        $.ajax({
                type: 'POST',
                //url: 'customer_controller/searchid',
                url: "<?php echo base_url() . 'coaching_controller/getting_groups_by_program'; ?>",
                data: {id_program: program_id},
                cache: false,
                async: true,
                success: function(data) {
                    var data = JSON.parse(data);
                    var options = '';   
                    if(data.groups.length > 0) { 
                        if ("<?php echo $flag_for_individual_or_group; ?>" === "individual_client") {
                            options += '<option tsession="1" value="0" selected>None</option>'; 
                        } 
                        $.each(data.groups, function(index, group) { 
                            options += '<option tsession="'+group.total_group_session+'" value="' + group.id_program_groups + '">' + group.program_group + '</option>';
                        }); 
                        $("#txtprogramsgroup").html(options); 
                        $("#txtprogramsgroup").select2();
                        getting_group_sessions_and_set_in_total_session();
                    } else {  
                        var options = ''; 
                        if ("<?php echo $flag_for_individual_or_group; ?>" === "individual_client") {  
                          options+='<option tsession="1" value="0" selected>None</option>'; 
                          $("#txtprogramsgroup").html(options); 
                          $("#txtprogramsgroup").select2();
                        }else{ 
                            options+='<option tsession="1" value="" selected>Not Available</option>'; 
                          $("#txtprogramsgroup").html(options);  
                          $("#txtprogramsgroup").select2();
                        }
                        getting_group_sessions_and_set_in_total_session();
                    }
                }
            });
    } 

    function getting_group_sessions_and_set_in_total_session(){
        $("#txttotalsessions").val($("#txtprogramsgroup option:selected").attr('tsession'));  
        calculate_total_program_price_with_session();
    }
    
    function submit_form(){
        
        $("#detailsform").submit();
    
    }
</script>