
<div class="col-lg-12">
    <section class="panel">
        <header class="panel-heading" style="min-height:120px">
            <div class="col-lg-3"> <span>Ref No : <?php echo $idl_data['idl_ref_no'];?></span> </div>
            <div class="col-lg-6">
                <h4 class="text-center"><i class="fa fa-truck truck_icon"></i><br/> <b>ETC Cargo Limited(ICD018) - Port Tariff Entry - ICD Officer </b></h4></div>
            <div class="col-lg-3"><span>Date : <?php echo $idl_data['idl_date'];?></span></div>
        </header>
        <div class="clear"></div>
        <div class="panel-body">
            <form class="form-horizontal" method="post" action="<?php echo base_url();?>icd/pteo_ctrl/update_icd_details/<?php echo $idl_data['idl_id'];?>">
                <div class="col-lg-12">
                    <div class="form-group col-md-6">
                        <label class="col-lg-4 col-sm-4">Vessel Name </label>
                        <div class="col-lg-8">

							<input type="text" class="form-control" value="<?php echo $idl_data['idl_vessel_name'];?>" readonly required>

                        </div>
                    </div>

                    <div class="form-group col-md-6">
                        <label class="col-lg-4 col-sm-4">Time In </label>
                        <div class="col-lg-8">

							<input type="text" class="form-control" name="idl_time_in" value="<?php date_default_timezone_set('Asia/Kolkata'); echo $date = date('h:i a', time());;?>" readonly required>

                        </div>
                    </div>
                    <div class="form-group col-md-6">
                        <label class="col-lg-4 col-sm-4">Bill Of Lading </label>
                        <div class="col-lg-8">
                            <input type="text" class="form-control" value="<?php echo $idl_data['idl_bill_of_loading'];?>" readonly required>

                        </div>
                    </div>

					<div class="form-group col-md-6">
                        <label class="col-lg-4 col-sm-4">Container Status </label>
                        <div class="col-lg-8">
							<!-- <input type="text" class="form-control" value="<?php echo $idl_data['csl_name'];?>" readonly required> -->

                            <select class="form-control container_status_cls" name="idl_csl_id" required>
                                <option value="">--Select--</option>
								<?php
									foreach($csl_list as $csl_row){
								?>
                                		<option value="<?php echo $csl_row['csl_id']; ?>" <?php if(isset($idl_data['idl_csl_id']) && $idl_data['idl_csl_id']==$csl_row['csl_id']){ echo "selected=selected";}?>><?php echo $csl_row['csl_name']; ?></option>
										
								<?php
									}
								?>
                            </select>

                        </div>
                    </div>
                    <div class="form-group col-md-6">
                        <label class="col-lg-4 col-sm-4">Shipping Line </label>
                        <div class="col-lg-8">
							<input type="text" class="form-control" value="<?php echo $idl_data['idl_shipping_line'];?>" readonly required>
                        </div>
                    </div>

                     <div class="form-group col-md-6">
                        <label class="col-lg-4 col-sm-4 ">Type Of Cargo </label>
                        <div class="col-lg-8">
                            <input type="text" class="form-control" value="<?php echo $idl_data['ctl_name'];?>" readonly required>

                        </div>
                    </div>
                    <div class="form-group col-md-6">
                        <label class="col-lg-4 col-sm-4">Payment Agency </label>
                        <div class="col-lg-8">
                            <input type="text" class="form-control" value="<?php echo $idl_data['pal_name'];?>" readonly required>

                        </div>
                    </div>

                    <div class="form-group col-md-6">
                        <label class="col-lg-4 col-sm-4"> VAT Applicable </label>
                        <div class="col-lg-8">
                            <input type="text" class="form-control vat_a_cls" name="idl_vat" value="<?php echo $idl_data['idl_vat'];?>" >
                            
                            
                            <!-- <select class="form-control " name="idl_vat" required  >
                                <option value="">--Select--</option>
                                <option value="Yes" <?php if($idl_data['idl_vat']=='Yes'){ echo "selected=selected";}?>  >Yes</option>
                                <option value="No" <?php if($idl_data['idl_vat']=='No'){ echo "selected=selected";}?>  >No</option> 
                            </select> -->

                        </div>
                    </div>
                    <div class="form-group col-md-6">
                        <label class="col-lg-4 col-sm-4"> Proforma Invoice  </label>
                        <div class="col-lg-8">
                            <input type="text" class="form-control" name="idl_proforma_invoice" value="<?php echo $idl_data['idl_proforma_invoice'];?>" required>

                        </div>
                    </div>
                    <div class="form-group col-md-6">
                        <label class="col-lg-4 col-sm-4"> Destination </label>
                        <div class="col-lg-8">
                            <input type="text" class="form-control" name="idl_destination" value="<?php echo $idl_data['idl_destination'];?>" required>

                        </div>
                    </div>


                     <div class="form-group col-md-6">
                        <label class="col-lg-4 col-sm-4">Billing Reference </label>
                        <div class="col-lg-8">
                            <input type="text" class="form-control" name="idl_bill_refer" value="<?php echo $idl_data['idl_bill_refer'];?>" required>

                        </div>
                    </div>
                    
                   
                </div>
				<header class="panel-heading">
                    <h4 class="text-center"> 
                        <b> Container Details </b>                    
                    </h4>
                </header>

                <div class="panel-body">
                    <section id="unseen">
                        <table class="table table-bordered table-striped table-condensed col-md-12">
                            <thead>
                                <tr>
                                    <th class="" width="100">C.No </th>
                                    <th class="numeric" width="100"> Size </th>
                                    <th class="" width="100">  Type </th>
                                    <th class="" width="100">  Status </th>
                                    <th class="" width="100">   Seal <br>S.NO1 </th>
                                    <th class="" width="100">   Seal <br>S.NO2  </th>
                                    <th class="" width="100">Service </th>
                                    <th class="" width="100">Cur </th>
                                    <th class="" width="100">H .<br> Charges </th>
                                    <th class="" width="100">Levy </th> 
                                    <th class="" width="100">Sub <br> Total </th>
                                    <th class="" width="100">VAT <br>(%)</th>
                                    <th class="" width="100">Total </th>
                                    <th class="" width="100">Remarks </th>

                                </tr>
                            </thead>
                            <tbody id="tbody_id">   
                            <?php
                                foreach($icdl_list as $icdl_key=>$icdl_row){
                            ?>  
                                    <tr> 
                                        <td> 
                                            <input type="hidden" name="icdl_id[]" value="<?php echo $icdl_row['icdl_id'];?>" required> 

                                            <input type="text" class="form-control" value="<?php echo $icdl_row['icdl_c_no'];?>" readonly>  
                                        </td>
                                        <td> 
                                            <input type="text" class="form-control" value="<?php echo $icdl_row['icdl_c_size'];?>" readonly>  
                                        </td>
                                        <td> 
                                            <input type="text" class="form-control" value="<?php echo $icdl_row['icdl_c_type'];?>" readonly>  
                                        </td>
                                        <td> 
                                            <input type="text" class="form-control" name="icdl_c_status[]" value="<?php echo $icdl_row['icdl_c_status'];?>" required>  
                                        </td>
                                        <td> 
                                            <input type="text" class="form-control" value="<?php echo $icdl_row['icdl_c_seal_s_no1'];?>" readonly>  
                                        </td>
                                        <td> 
                                            <input type="text" class="form-control" value="<?php echo $icdl_row['icdl_c_seal_s_no2'];?>" readonly>  
                                        </td>
                                        <td> 
                                            <select class="form-control" name="icdl_isl_id[]" required>
                                                <option value="">--Select--</option>
                                                <?php
                                                    foreach($isl_list as $isl_row){
                                                ?>
                                                        <option value="<?php echo $isl_row['isl_id']; ?>" <?php if(isset($icdl_row['icdl_isl_id']) && $icdl_row['icdl_isl_id']==$isl_row['isl_id']){ echo "selected=selected";}?>><?php echo $isl_row['isl_name']; ?></option>
                                                        
                                                <?php
                                                    }
                                                ?>
                                            </select>  
                                        </td>
                                        <td> 
                                            <select class="form-control" name="icdl_cul_id[]" required>
                                                <option value="">--Select--</option>
                                                <?php
                                                    foreach($cul_list as $cul_row){
                                                ?>
                                                        <option value="<?php echo $cul_row['cul_id']; ?>" <?php if(isset($icdl_row['icdl_cul_id']) && $icdl_row['icdl_cul_id']==$cul_row['cul_id']){ echo "selected=selected";}?>><?php echo $cul_row['cul_name']; ?></option>
                                                        
                                                <?php
                                                    }
                                                ?>
                                            </select>  
                                        </td>
                                        <td> 
                                            <input type="number" class="form-control handling_cls" id="hand_t_id_<?php echo $icdl_key;?>" data-const_h_val="<?php echo $icdl_key;?>" name="icdl_handling_charges[]" value="<?php echo $icdl_row['icdl_handling_charges'];?>" required>  
                                        </td>
                                        <td> 
                                            <input type="number" class="form-control levy_input_cls" id="levy_t_id_<?php echo $icdl_key;?>" data-const_l_val="<?php echo $icdl_key;?>" name="icdl_levy[]" value="<?php echo $icdl_row['icdl_levy'];?>" required>  
                                        </td>

                                        <td> 
                                            <input type="number" class="form-control sub_total_cls" id="sub_t_id_<?php echo $icdl_key;?>" data-const_s_val="<?php echo $icdl_key;?>" name="icdl_sub_total[]" value="<?php echo $icdl_row['icdl_sub_total'];?>" readonly required>  
                                        </td>
                                        <td> 
                                            <input type="number" class="form-control val_cls" id="vat_id_<?php echo $icdl_key;?>" data-const_v_val="<?php echo $icdl_key;?>" name="icdl_vat[]" value="<?php echo $icdl_row['icdl_vat'];?>" readonly required>  
                                        </td>
                                        <td  style="width:9% !important;"> 
                                            <input type="number" class="form-control total_input_cls" id="total_val_<?php echo $icdl_key;?>" name="icdl_total[]" value="<?php echo $icdl_row['icdl_total'];?>" required readonly>  
                                        </td>
                                        <td> 
                                            <input type="text" class="form-control" name="icdl_remarks[]" value="<?php echo $icdl_row['icdl_remarks'];?>" required>  
                                        </td>
                                    </tr>
                            <?php
                                }
                            ?>
                                <tr>  
                                    <td COLSPAN="8" style="text-align:right"><b>Total</b></td>

                                    <td> <b id="han_td_id"></b> </td>
                                    <td> <b id="lev_td_id"></b> </td>
                                    <td> <b id="sub_td_id">0</b> </td>
                                    <td> <b id="vat_td_id">0</b> </td>
                                    <td> <b id="tot_td_id">0</b> </td>
                                    <td> </td>
                                </tr>
                            </tbody>
                        </table>

                        <div class=" col-lg-offset-5">
                            <div class="col-lg-2">
                                <button type="submit" class="btn btn-success"> <i class="fa fa-thumbs-up"></i>&nbsp; Save</button>
                            </div>

                        </div>

                    </section>
                </div>
                <!---->

            </form>
        </div>
    </section>

</div>

<?php
    if($idl_data['csl_name']=="Transit"){
?>
        <script type='text/javascript'> 
            $(document).ready(function(){
                $('.vat_a_cls').prop('readonly', true);          
                $('.val_cls').prop('readonly', true);
                // $('.vat_a_cls').val('No');
                $('.val_cls').val('0');
            });
        </script> 
<?php
    }
?>
<script type='text/javascript'> 
    $(document).ready(function(){
        $('.val_cls').val('0');
    });
    $('.container_status_cls').change(function(){
        this_val = $(this).val();
        if(this_val=='2'){
            $('.vat_a_cls').prop('readonly', true);          
            $('.val_cls').prop('readonly', true);
            $('.vat_a_cls').val('No');
            $('.val_cls').val('0');
            
        }else{
            $('.vat_a_cls').prop('readonly', false);    
            $('.val_cls').prop('readonly', false);
            // $('.vat_a_cls').val('Yes');            
            $('.val_cls').val('');
        } 
    });

     $('.handling_cls').on('keypress keyup keypress', function() {
        this_id     = $(this).attr('id');
        const_val   = $('#'+this_id).data('const_h_val'); 
        this_h_val  = $('#'+this_id).val();                        
        this_l_val  = $('#levy_t_id_'+const_val).val();         
        // this_v_val  = $('#vat_id_'+const_val).val(); 
        amt_t_val = 0; 
        vat_val = 0;
        if(this_h_val!=''){
            amt_t_val = parseFloat(amt_t_val)+parseFloat(this_h_val);
            amt_t_val = parseFloat(amt_t_val).toFixed(2); 
            $('#sub_t_id_'+const_val).val(amt_t_val);
        }       
        if(this_l_val!=''){
            amt_t_val = parseFloat(this_l_val)+parseFloat(amt_t_val);
            amt_t_val = parseFloat(amt_t_val).toFixed(2); 
            $('#sub_t_id_'+const_val).val(amt_t_val);
        }
            
        v_val = amt_t_val*(18/100);
        v_val = parseFloat(v_val).toFixed(2);
        $('#vat_id_'+const_val).val(v_val); 
        amt_t_val = parseFloat(amt_t_val)+parseFloat(v_val);
        amt_t_val = parseFloat(amt_t_val).toFixed(2); 
        $('#total_val_'+const_val).val(amt_t_val);
        
        var h_sum = 0;
        $('.handling_cls').each(function(){
            if(this.value!=''){
                this_val = parseFloat(this.value).toFixed(2);
                h_sum += parseFloat(this_val);
            }
        });
        
        var l_sum = 0;
        $('.levy_input_cls').each(function(){
            if(this.value!=''){
                this_val = parseFloat(this.value).toFixed(2);
                l_sum += parseFloat(this_val);
            }
        });

        var s_sum = 0;
        $('.sub_total_cls').each(function(){
            if(this.value!=''){
                this_val = parseFloat(this.value).toFixed(2);
                s_sum += parseFloat(this_val);
            }
        });

        var v_sum = 0;
        $('.val_cls').each(function(){
            this_val = parseFloat(this.value).toFixed(2);
            v_sum += parseFloat(this_val);
        });

        var t_sum = 0;
        $('.total_input_cls').each(function(){
            if(this.value!=''){
                this_val = parseFloat(this.value).toFixed(2);
                t_sum += parseFloat(this_val);
            }
        });


        $('#han_td_id,#lev_td_id,#sub_td_id,#vat_td_id,#tot_td_id').html('');
        $('#han_td_id').html(h_sum);
        $('#lev_td_id').html(l_sum);
        $('#sub_td_id').html(s_sum);
        $('#vat_td_id').html(v_sum);
        $('#tot_td_id').html(t_sum);
    });
    $('.levy_input_cls').on('keypress keyup keypress', function() {
        this_id     = $(this).attr('id');
        const_val   = $('#'+this_id).data('const_l_val'); 
        this_h_val  = $('#hand_t_id_'+const_val).val();                       
        this_l_val  = $('#'+this_id).val(); 
        // this_v_val  = $('#vat_id_'+const_val).val(); 
        amt_t_val = 0; 
        if(this_h_val!=''){
            amt_t_val = parseFloat(amt_t_val)+parseFloat(this_h_val);
            amt_t_val = parseFloat(amt_t_val).toFixed(2);             
            $('#sub_t_id_'+const_val).val(amt_t_val);
        }       
        if(this_l_val!=''){
            amt_t_val = parseFloat(this_l_val)+parseFloat(amt_t_val);
            amt_t_val = parseFloat(amt_t_val).toFixed(2);             
            $('#sub_t_id_'+const_val).val(amt_t_val);
        }
       
            

        v_val = amt_t_val*(18/100);
        v_val = parseFloat(v_val).toFixed(2);
        $('#vat_id_'+const_val).val(v_val); 
        amt_t_val = parseFloat(amt_t_val)+parseFloat(v_val);  
        amt_t_val = parseFloat(amt_t_val).toFixed(2);               
        $('#total_val_'+const_val).val(amt_t_val);
        

        var h_sum = 0;
        $('.handling_cls').each(function(){
            if(this.value!=''){
                this_val = parseFloat(this.value).toFixed(2);
                h_sum += parseFloat(this_val);
            }
        });
        
        var l_sum = 0;
        $('.levy_input_cls').each(function(){
            if(this.value!=''){
                this_val = parseFloat(this.value).toFixed(2);
                l_sum += parseFloat(this_val);
            }
        });


        var s_sum = 0;
        $('.sub_total_cls').each(function(){
            if(this.value!=''){
                this_val = parseFloat(this.value).toFixed(2);                
                s_sum += parseFloat(this_val);
            }
        });

        var v_sum = 0;
        $('.val_cls').each(function(){
            this_val = parseFloat(this.value).toFixed(2);            
            v_sum += parseFloat(this_val);
        });

        var t_sum = 0;
        $('.total_input_cls').each(function(){
            if(this.value!=''){
                this_val = parseFloat(this.value).toFixed(2);                
                t_sum += parseFloat(this_val);
            }
        });


        $('#han_td_id,#lev_td_id,#sub_td_id,#vat_td_id,#tot_td_id').html('');
        $('#han_td_id').html(h_sum);
        $('#lev_td_id').html(l_sum);
        $('#sub_td_id').html(s_sum);
        $('#vat_td_id').html(v_sum);
        $('#tot_td_id').html(t_sum);
    });

    
</script>