<style>
        .table1{}
        .table1 td{
            border-top: none !important;
            padding:1px 8px 1px 8px !important;
        }

/*         .datepicker-dropdown{position:absolute !important; top:-7px !important;}*/
</style>  
<div class="wrapper">
            <div class="container">
                <!-- Page-Title -->
                <div class="row">
                    <div class="col-sm-12">
                        <h4 class="page-title">Program Enrollment </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">
                    <div class="col-md-12">
                        <div class="panel panel-default">
                            <div class="panel-body">
                                <div class="row">
                                    <div class="pull-left">
                                        <h3 class="logo invoice-logo"><?php if(isset($business)){ if(isset($business[0]['business_logo1'])){echo "<img src='".base_url().'assets/images/business/'.$business[0]['business_logo1']."' alt='".$business[0]['business_name']."' class='img-responsive' />";}else{echo "<img src='".base_url().'assets/images/business/'.$business[0]['business_logo']."' alt='".$business[0]['business_name']."' class='img-responsive' />"; }} else {echo 'SkedWise';}?></h3>
                                    </div>
                                    <div class="pull-right">
                                        
                                        <table class="table table1" style="border:none !important;">
                                            <tr>
                                                <td style="border-right:1px solid #f7f7f7; color:#797979; text-align: right; vertical-align: bottom;">Date</td>
                                                <td style="color: #000; font: normal normal 16px/16px arial, serif; vertical-align: middle;"><?php echo date('d-m-Y'); ?></td>
                                            </tr>
                                            <tr>
                                                <td style="border-right:1px solid #f7f7f7; color:#797979; text-align: right">Member ID</td>
                                                <td style="color:#000;"><?php if(isset($program_enrollment)){ echo sprintf("%04s",$program_enrollment[0]['id_program_enrollment']);}else{echo '00001';} ?></td>
                                            </tr>
                                            <tr>
                                                <td style="border-right:1px solid #f7f7f7; color:#797979; text-align: right">Contact</td>
                                                <td style="color:#000;">Front Desk</td>
                                            </tr>
                                            <tr>
                                                <td style="border-right:1px solid #f7f7f7; color:#797979; text-align: right"></td>
                                                <td style="color:#000;"><?php if(isset($business)){ echo $business[0]['business_email'];}?></td>
                                            </tr>
                                            <tr>
                                                <td style="border-right:1px solid #f7f7f7; color:#797979; text-align: right"></td>
                                                <td style="color:#000;"><?php if(isset($business)){ echo $business[0]['business_phone2'];}?></td>
                                            </tr>
                                        </table>
                                    </div>
                                </div>
                                
                                
                                <div class="row">
                                    <div class="col-md-12 m-t-40">
                                        <div class="pull-left">

                                        </div>
                                        <div class="pull-right">
                                            <span style="color: #000; font: normal normal 16px/16px arial, serif;  text-transform: uppercase;"><?php echo $program_enrollment[0]['customer_name']; ?></span><br>
                                            <span style="color: #000; font: normal normal 16px/16px arial, serif;  text-transform: uppercase;"><?php echo $program_enrollment[0]['customer_address']; ?></span><br>
                                            <span style="color: #000; font: normal normal 16px/16px arial, serif;  text-transform: uppercase;"><?php echo $program_enrollment[0]['customer_cell']; ?></span><br>
                                            
                                            
                                            <br>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-12 m-t-10">
                                        <span style="font: normal bold 22px/40px arial, serif">ENROLLMENT DETAILS</span>
                                    </div>
                                </div>
                                <div class="row" style="color:#000 !important">
                                    
                                    <div class="col-md-4 col-sm-12">
                                        
                                        <input name="customerid" id="customerid" type="hidden" value="<?php echo $program_enrollment[0]['id_customers']; ?>">
                                        <input name="customername" id="customername" type="hidden" value="<?php echo $program_enrollment[0]['customer_name']; ?>">
                                        <input name="enrollment_id" id="enrollment_id" type="hidden" value="<?php echo  $program_enrollment[0]['id_program_enrollment'];?>">
                                        
                                        <table class="table table1 m-t-20">
                                            <tbody>
                                                <tr>
                                                    <td>Enrolled On</td>
                                                    <td><strong><?php if(isset($program_enrollment)){ echo $program_enrollment[0]['created_on'];} ?></strong></td>
                                                </tr>

                                                <tr>
                                                    <td>Age</td>
                                                    <td><strong><?php if(isset($program_enrollment)){ echo $program_enrollment[0]['age'];} ?></strong></td>
                                                </tr>


                                                <tr>
                                                    <td>Father's Name</td>
                                                    <td><strong><?php echo $program_enrollment[0]['father_name']; ?></strong></td>
                                                </tr>

                                                <tr>
                                                    <td>Mother's Name</td>
                                                    <td><strong><?php echo $program_enrollment[0]['mother_name']; ?></strong></td>
                                                </tr>

                                                <?php if(isset($program_enrollment) && isset($program_enrollment[0]['education'])){ ?>
                                                <tr>
                                                    <td>Last Level of Education</td>
                                                    <td><strong><?php if(isset($program_enrollment)){ echo $program_enrollment[0]['education'];} ?></strong></td>
                                                </tr>
                                                <?php } ?>
                                                <?php if(isset($program_enrollment) && isset($program_enrollment[0]['beuatyeducation'])){ ?>
                                                <tr>
                                                    <td>Beauty Eduction</td>
                                                    <td><strong><?php if(isset($program_enrollment)){ echo $program_enrollment[0]['beuatyeducation'];} ?></strong></td>
                                                </tr>
                                                <?php } ?>

                                        
                                                <tr>
                                                    <td>Spoken Languages:</td>
                                                    <td><?php echo $program_enrollment[0]['languages']; ?></td>
                                                   
                                                </tr>
                                                <tr>
                                                    <td>Previous Therapy:</td>
                                                    <td><?php echo $program_enrollment[0]['beautyexperience']; ?></td>
                                                    
                                                </tr>
                                                    
                                                
                                                <tr>
                                                    <td>
                                                        <strong>Goals:</strong>
                                                    </td>
                                                    <td>
                                                        <?php echo $program_enrollment[0]['goals']; ?>
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                    <div class="col-md-6 m-t-20">
                                        <p>Program Type    : <strong><?php echo $program_enrollment[0]['program_type']; ?></strong><br/>
                                           
                                        </p>
                                        
                                        <table class="table">
                                               <thead>
                                                   <tr>
                                                       <th>Service</th>
                                                       <th>Total Sessions</th>
                                                       <th class="text-right">Per Session Cost</th>
                                                       <th class="text-right" style="border-right:1px solid #c7c7c7;">Total Price</th>                                                       
                                                       <th class="text-right">Discount</th>
                                                       <th class="text-right">Invoiced</th>
                                                       <th class="text-right">Other Charges</th>
                                                       <th class="text-right">Taxes</th>
                                                       <th class="text-right">CC Fee</th>
                                                       <th class="text-right">Paid</th>
                                                       <th class="text-right">Balance</th>
                                                   </tr>
                                               </thead>
                                               <tbody>
                                            <?php $totalbalance=0; $totalprice=0; $totalpaid=0; $totalinvoiced=0; $totaltax=0; $totalothercharges=0; $totalcccharge=0;  if(null != $registration_fee){?>                                                
                                                   <tr>
                                                       <td colspan="3" ><strong><?php echo $registration_fee->program_invoice_remarks;?></strong></td>
                                                       <td class="text-right" style="border-right:1px solid #c7c7c7;"><?php echo $registration_fee->invoiced_amount; $totalprice=$totalprice+$registration_fee->invoiced_amount;?></td>
                                                       <td class="text-right" >0</td>                                                                                                          
                                                       <td  class="text-right"><?php echo $registration_fee->invoiced_amount; $totalinvoiced=$totalinvoiced+$registration_fee->invoiced_amount;?></td>
                                                       <td></td>    
                                                       <td  class="text-right"><?php echo $registration_fee->salestax; $totaltax=$totaltax+$registration_fee->salestax;?></td>
                                                       <td  class="text-right"><?php echo $registration_fee->cc_charge; $totalcccharge=$totalcccharge+$registration_fee->cc_charge;?></td>
                                                       <td  class="text-right"><?php echo $registration_fee->paid_amount;  $totalpaid=$totalpaid+$registration_fee->paid_amount;?></td>
                                                       <td  class="text-right"><?php echo ($registration_fee->invoiced_amount +$registration_fee->salestax + $registration_fee->cc_charge)  - $registration_fee->paid_amount; $totalbalance=$totalbalance+(($registration_fee->invoiced_amount + $registration_fee->salestax + $registration_fee->cc_charge) - $registration_fee->paid_amount);?></td>
                                                </tr>    
                                            <?php } ?>
                                                   
                                                   
                                            <?php foreach($program_enrollment as $services){?>
                                                <tr>
                                                    <td><?php echo '<b>'.$services['service_category'].'-'.$services['service_name'].'</b> '?></td>
                                                    <td><?php  echo $services['total_sessions'];?></td>
                                                    <td class="text-right"><?php echo $services['per_session_rate'];?></td>
                                                    <td class="text-right" style="border-right:1px solid #c7c7c7;"><?php echo number_format($services['total']); $totalprice=$totalprice+$services['total']; ?></td>
                                                    
                                                    <td class="text-right"><?php echo number_format($services['discount']);?></td>
                                                    <td class="text-right"><?php echo number_format($services['invoiced_amount']); $totalinvoiced=$totalinvoiced+$services['invoiced_amount'];?></td>
                                                    <td class="text-right"><?php echo number_format($services['other_charges']);?></td>
                                                    <td class="text-right"><?php echo number_format($services['salestax']); $totaltax=$totaltax+$services['salestax'];?></td>
                                                    <td class="text-right"><?php echo number_format($services['cc_charge']); $totalcccharge=$totalcccharge+$services['cc_charge'];?></td>
                                                    <td class="text-right"><?php echo number_format($services['paid']); $totalpaid=$totalpaid+$services['paid'];?></td>
                                                    <td class="text-right"><?php echo number_format(($services['invoiced_amount']+$services['salestax']+$services['other_charges']+$services['cc_charge'])-$services['paid']); $totalbalance=$totalbalance+(($services['invoiced_amount']+$services['salestax']+$services['other_charges']+$services['cc_charge'])-$services['paid']);?></td>
                                                </tr>
                                            <?php } ?>
                                               </tbody>
                                               <tfoot>
                                                   <tr>
                                                        <td colspan="3" class="border-right:1px solid #000;"></td>
                                                        <td class="text-right"><?php echo number_format($totalprice);?></td>
                                                        <td></td>
                                                        <td class="text-right"><?php echo number_format($totalinvoiced);?></td>
                                                        <td class="text-right"><?php echo number_format($totalothercharges);?></td>
                                                        <td class="text-right"><?php echo number_format($totaltax);?></td>
                                                        <td class="text-right"><?php echo number_format($totalcccharge);?></td>
                                                        <td class="text-right"><?php echo number_format($totalpaid);?></td>
                                                        <td class="text-right"><?php echo number_format($totalbalance);?></td>
                                                   </tr>
                                                   <?php if(isset($enrollment_advance)){ $totaladvance=0; foreach($enrollment_advance as $advance){?>
                                                   <tr>
                                                       <!--advances-->                                                       
                                                       <td></td>
                                                       <td></td>
                                                       <td>Advance</td>
                                                       <th colspan="3">Received on <?php echo $advance['advance_date'];?></th>
                                                       <th class="text-right"><?php echo number_format($advance['advance_amount']); $totaladvance=$totaladvance+$advance['advance_amount'];?></th>
                                                       <th><a target="_blank" class="btn btn-xs btn-info hidden-print" href="<?php echo base_url();?>print_advance_note/<?php echo $advance['id_program_advance_note'];?>"><i class="fa fa-icon fa-print"></i></a> </th>
                                                       <td><button class="btn btn-xs btn-danger hidden-print" onclick="remove_advance(<?php echo $advance['id_program_advance_note'];?>)"><i class="fa fa-icon fa-close"></i></button> </td>
                                                   </tr>
                                                   
                                                   <?php }} ?>
                                               </tfoot>
                                            </table>
                                        
                                    </div>
                                    <div class="col-md-2 col-xs-12 m-t-20" ></div>
                                </div>
                                <div class='row'>
                                    <div class="col-md-3 col-xs-12 m-t-20" ></div>
                                    <div class="col-md-6 col-xs-12 m-t-20" >                                        
                                        <div class="row m-t-20">
                                            <div class="col-md-6"></div>
                                            <div class="col-md-6">
                                                <table>
                                                    <tbody>
                                                        <tr>
                                                            <td style="padding: 0 20px 0 0"></td>
                                                            <td style="padding: 0 20px 0 0"><?php echo $program_enrollment[0]['created_by'];?></td>
                                                        </tr>
                                                        <tr>
                                                            <td style="padding: 0 20px 0 0"><span style = "text-decoration: overline"> Parent Signature</td>
                                                            <td style="padding: 0 20px 0 0"><span style = "text-decoration: overline"> Prepared by</td>
                                                        </tr>
                                                    </tbody>
                                                </table>
                                            </div>                              
                                    </div>
                                    <div class="col-md-3 col-xs-12 m-t-20" ></div>
                                </div>
                                <br>
                              
                                <hr>
                                <div class="hidden-print">
                                    <div class="pull-right">
                                        <button onclick="openadvancemodal(<?php echo $program_enrollment[0]['id_program_enrollment'] ;?>)" class="btn btn-primary waves-effect waves-light" id="btnpayment"><i class="fa fa-dollar"></i> Add Advance</button>
                                        <a type="submit" href="<?php echo base_url().'coaching_invoice_list/'.$program_enrollment[0]['id_program_enrollment'] ;?>" class="btn btn-success waves-effect waves-light" id="btnpayment"><i class="fa fa-calculator"></i> Invoicing</a>
                                        <a href="javascript:window.print()" class="btn btn-inverse waves-effect waves-light" id="btnprint"><i class="fa fa-print"></i></a>
                                       
                                    </div>
                                </div>
                            </div>
                        </div>

                    </div>

                </div>
                <!-- end row -->
<div id="advancemodal" class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="advancemodal" aria-hidden="true" style="display: none;">
    <div class="modal-dialog modal-md"  >
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="custom-width-modalLabel">Add Advance Payment</h4>
            </div>
            <div class="modal-body">
                <div class='row'>
                    <div class="col-md-12" id="advance_table">
                        <div>
                            <table id="adv_table" class="table table-stripped">
                                <tbody>
                                    <?php if(isset($enrollment_advance)){ ?>
                                    <thead>
                                        <tr>
                                            <td >ID</td>
                                            <td >Date</td>
                                            <td >Amount</td>
                                        </tr>
                                    </thead>
                                    <?php foreach($enrollment_advance as $advance){?>
                                    <tr>
                                        <td><?php echo $advance['id_program_advance_note'];?></td>
                                        <td><?php echo $advance['advance_date'];?></td>
                                        <td><?php echo $advance['advance_amount'];?></td>
                                    </tr>
                                    <?php }}?>
                                </tbody>
                                <tfoot>
                                </tfoot>
                            </table>
                            <hr>
                        </div>
                    </div>
                </div>
                <div class='row'>
                    <div class="col-md-6 " id="advance_block">
                        <div class="row">
                            <div class="form-group">
                                <div class="col-md-4">
                                    Advance Amount:
                                </div>
                                <div class="col-md-8">
                                    <div class="input-group">
                                        <span class="input-group-addon"><?php echo CURRENCY_CODE;?>. </span>
                                        <input class="form-control numeric" onchange="advanceamountchanged();" name="advance_amount" id="advance_amount" style="text-align: right;" />
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div id="advance_inst_div" style="display:none;" >
                            <div class="row">    
                                <div class="form-group">
                                    <div class="col-md-4">
                                        Inst. #:
                                    </div>
                                    <div class="col-md-8">
                                        <input class="form-control numeric" name="advance_inst" id="advance_inst" style="text-align: right; " />
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div id="advance_card_div" style="display:none;" >
                            <div class="row">
                                <div class="form-group">
                                    <div class="col-md-4">
                                        CC Fee %:
                                    </div>
                                    <div class="col-md-8">
                                        <input readonly="readonly" class="form-control numeric" name="cc_charge_setting" id="cc_charge_setting" style="text-align: right; " value="<?php echo $business[0]['cc_charge']; ?>" />
                                    </div>
                                </div>
                            </div>
                            <div class="row">    
                                <div class="form-group">
                                    <div class="col-md-4">
                                        Extra :
                                    </div>
                                    <div class="col-md-8">
                                        <input readonly="readonly" class="form-control" name="advance_cccharge" id="advance_cccharge" style="text-align: right; " value="0" />
                                    </div>
                                </div>    
                            
                            </div>
                        </div>
                        <div class="form-group">
                            <select class="form-control" onchange="showhideinst();" id="advance_mode" name = "advance_mode">
                                <option value="cash">Cash</option>
                                <option value="card">Credit Card</option>
                                <option value="card">Debit Card</option>
                                <option value="check">Bank</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <div class="col-md-4">
                                Advance Date:
                            </div>
                            <div class="col-md-8">
                                <input class="form-control date-picker" name="advance_date" id="advance_date" />
                            </div>
                        </div>
                    
                    </div>
                    <div class='col-md-6'>
                        <div>
                            Enter Advance Comment:
                        </div>
                        <div class="form-group">
                            <textarea class="form-control" name="advance_comment" id="advance_comment" ></textarea>
                        </div>
                    </div>
                </div>
                    
                    
            </div>
        
            <div class='modal-footer'>
                <button type="button" onclick="printadvance();"  class="btn btn-default waves-effect waves-light pull-right m-l-5"><i class="fa fa-print"></i></button>
                <button type="button" onclick="saveadvance();"  class="btn btn-custom waves-effect waves-light pull-right">Save</button>

            </div>
        </div>
    </div>
</div>
 

                
<script>
            
    $(document).ready(function(){
        
        $('#advance_date').datepicker({
                default: today,
                autoclose: true,
                todayHighlight: true,
                format: 'yyyy-mm-dd'
            }).datepicker('setDate', new Date());
        
    });
    
    
    function openadvancemodal(enrollmentid){
        
        $("#advancemodal").modal('show');
        
    }
    
    
    function showhideinst() {
       // console.log($("#advance_mode option:selected").val());
        if ($("#advance_mode option:selected").val() === "card" && $("#advance_mode option:selected").text() !== 'Debit Card') {
            $("#advance_inst_div").show();
            
            if(parseFloat($("#cc_charge_setting").val())>0){
                $("#advance_card_div").show();
                if($("#advance_amount").val() !==""){
                    $("#advance_cccharge").val((parseInt($("#advance_amount").val()) * parseFloat($("#cc_charge_setting").val())) / 100 );
                }
            }
        } else if ($("#advance_mode option:selected").val() === "check") {
            $("#advance_inst_div").show();
            $("#advance_card_div").hide();
        } else {
            $("#advance_card_div").hide();
        }
        
    }
    
    function advanceamountchanged(){
        if($("#advance_amount").val()!=='' && parseFloat($("#cc_charge_setting").val())>0 && $("#advance_mode option:selected").val() === "card"){
            $("#advance_cccharge").val((parseInt($("#advance_amount").val()) * parseInt($("#cc_charge_setting").val())) / 100 );

        }
    }

    function saveadvance() {

        if ($("#advance_amount").val() === '' || $("#advance_inst_div").is(":visible") && $("#advance_inst").val() == "") {
            if ($("#advance_amount").val() === '') {
                swal({
                    title: 'Please Enter Advance Amount!',
                    text: '',
                    type: 'error',
                    confirmButtonText: 'OK!'
                });
                $("#advance_amount").focus();
            } else if ($("#advance_inst_div").is(":visible") && $("#advance_inst").val() == "") {
                swal({
                    title: 'Please Enter Instrument Number!',
                    text: '',
                    type: 'error',
                    confirmButtonText: 'OK!'
                });
                $("#advance_inst").focus();
            }
            return false;
        } else {

            $.ajax({
                type: 'POST',
                //url: 'Scheduler_controller/active_staff_list',
                url: "<?php echo base_url() . 'coaching_controller/add_enrollment_advance'; ?>",
                data: {enrollment_id: $('#enrollment_id').val(),
                    advance_amount: $("#advance_amount").val(),
                    advance_mode: $("#advance_mode option:selected").val(),
                    advance_inst: $("#advance_inst").val(),
                    advance_cc_charge: $("#advance_cccharge").val(),
                    advance_comment: $("#advance_comment").val(),
                    advance_date: $("#advance_date").val()
                },                
                cache: false,
                async: true,
                success: function (data) {
                    toastr.success('Advance of <?php echo CURRENCY_CODE;?>' + $("#advance_amount").val() + ' Added for ' + $('#customername').val(), 'Done!');
                    console.log(data);
                    $("#advancemodal").modal('hide');
                   location.reload();
                }
            });
        }
    }
    
    
    function remove_advance(advid){
    
         $.ajax({
                type: 'POST',
                //url: 'Scheduler_controller/active_staff_list',
                url: "<?php echo base_url() . 'coaching_controller/remove_enrollment_advance'; ?>",
                data: {
                    enrollment_id: $('#enrollment_id').val(),
                    advance_note_id: advid
                },                
                cache: false,
                async: true,
                success: function (data) {
                    //toastr.success('Advance of <?php echo CURRENCY_CODE;?>' + $("#advance_amount").val() + ' Added for ' + $('#customername').val(), 'Done!');
                    //console.log(data);
                    if(data =='success'){
                        toastr.success('Advance Revmoved', 'Success');
                        location.reload();
                    } else{
                        toastr.error(data, 'Not Cancelled');
                        
                    }
                    
                }
            });
    
    }


</script>