HEX
Server: Apache/2.4.41 (Amazon) OpenSSL/1.0.2k-fips PHP/5.6.40
System: Linux ip-172-31-40-18 4.14.146-93.123.amzn1.x86_64 #1 SMP Tue Sep 24 00:45:23 UTC 2019 x86_64
User: apache (48)
PHP: 5.6.40
Disabled: NONE
Upload Files
File: /var/www/html/taxicamera/application/views/admin/payin/driver_settlement/driver_settlement_edit.php
<script>
  var page ='settlement_edit';

</script>
<script type="text/javascript"> base_url = "<?=base_url()?>"; </script>
<script src="<?=base_url('public/admin_assets/js/capture_settlement.js')?>"></script>
<script src="<?=base_url('public/admin_assets/js/capture_expense_settlement.js')?>"></script>
<!-- <script src="<?=base_url('public/admin_assets/js/capture_life_time_docs_settlement.js')?>"></script>
<script src="<?=base_url('public/admin_assets/js/shift_docs_settlement.js')?>"></script> -->
<style>
.chk_custom_box .checkmark {
  position: absolute;
  top: -10px;
  left: 12px;
  height: 18px;
  width: 18px;
  background-color: #dad7d7;
}

.recipt_img {
    width: 45%;
    height: auto;
    border-bottom: #ccc 1px solid;
    padding: 5px;
    -webkit-box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.3);
    -moz-box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.3);
    box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.3);
}
</style>
<style>
	#video,#video1,#video2,#video3 {
		border: 5px solid #28ce92;
    box-shadow: none;
    width: 100%;
    height: auto;
	}

	#photo,#photo1,#photo2,#photo3 {
		border: 5px solid #28ce92;
    box-shadow: none;
    width: 100%;
    height: 358px;
    float: right;
    position: relative;
    top: 0;
	}

	#canvas,#canvas1,#canvas2,#canvas3 {
	display:none;
	}

	.camera,.camera1,.camera2,.camera3 {
		width: 49%;
    display: inline-block;
	}

	.output,.output1,.output2,.output3 {
	width: 49%;
	display:inline-block;
	}

	/*#startbutton,#startbutton1 {
		display:block;
		position:relative;
		margin-left:auto;
		margin-right:auto;
		bottom:32px;
		background-color: rgba(0, 150, 0, 0.5);
		border: 1px solid rgba(255, 255, 255, 0.7);
		box-shadow: 0px 0px 1px 2px rgba(0, 0, 0, 0.2);
		font-size: 14px;
		font-family: "Lucida Grande", "Arial", sans-serif;
		color: rgba(255, 255, 255, 1.0);
	}*/

	.contentarea,.contentarea1,.contentarea2,.contentarea3 {
	font-size: 16px;
	font-family: "Lucida Grande", "Arial", sans-serif;
	width: 100%;
	}

	#payin_data_div hr{
		border-color: #ccc;
	}
</style>
<div class="main-content">
  <div class="content-wrapper">
    <div class="container-fluid">
      <!-- Basic form layout section start -->
      <section id="basic-form-layouts">
        <div class="row">
          <div class="col-md-12">
            <div class="card">
              <div class="card-header">
                <div class="page-title-wrap">
                  <h4 class="card-title">Driver Settlement Edit</h4>
                  <a class="title_btn t_btn_list" href="<?= (!empty($driver_settlement_data) && $driver_settlement_data['bulk_settlement_flag'] == 0)? base_url('admin/driver-settlement/list'): base_url('admin/DriverSettlement/bulk_settlement_list') ?>"><span><i class="fa fa-list-ul" aria-hidden="true"></i></span> Driver Settlement List</a> 
                </div>
                <!--<p class="mb-0">This is the most basic and cost estimation form is the default position.</p>-->
              </div>
              <div class="card-body">
              <?php if (!empty($driver_settlement_data)) : $dr_settlement_id = $driver_settlement_data['dr_settlement_id'];
                  else : $dr_settlement_id = "";
                  endif; ?>
              <form id="update_driver_settle_frm" class="form custom_form_style" action="<?php echo base_url() . 'admin/DriverSettlement/EditDriversettlement/' . $dr_settlement_id; ?>" method="post">
                <div class="px-3">
                  <input type="hidden" name="dr_settlement_id" id="dr_settlement_id" value="<?php echo $dr_settlement_id; ?>">
                    <div class="daily_stl_top_box">
                      <div class="filter_area">
                        <div class="row clearfix">
                          <div class="col-sm-6">
                            <div class="form-group" style="margin-bottom: 0;"></div>
                          </div>
                          <div class="col-sm-12">
                            <div id="drive_data_div" class="table_row repeat">
                              <?php $name = '';
                              if (!empty($driver_settlement_data) && $driver_settlement_data['first_name']) :
                                if ($driver_settlement_data['middle_name']) :
                                  $middle_name  = '';
                                  $middle_name . ' ';
                                else :
                                  $middle_name  = '';
                                endif;
                                $name = $driver_settlement_data['first_name'] . ' ' . $middle_name . $driver_settlement_data['last_name'];
                              endif; ?>
                              
                              <div class="list_filter_sett">
                              <ul>
                                      <li id="DC"><strong>DC </strong> <?php if(!empty($driver_settlement_data) && !empty($driver_settlement_data['dc_no'])): echo $driver_settlement_data['dc_no'];endif; ?></li>
                                      <li id="dr_dc_expiry"><strong>DC Exp. Date </strong><?php if(!empty($driver_settlement_data) && !empty($driver_settlement_data['dr_dc_expiry'])): echo date('d/m/Y',strtotime($driver_settlement_data['dr_dc_expiry'])); endif;?></li>
                                      <li id="dr_dl_expiry"><strong>DL Exp. Date </strong><?php if(!empty($driver_settlement_data) && !empty($driver_settlement_data['dr_licence_expiry'])): echo date('d/m/Y',strtotime($driver_settlement_data['dr_licence_expiry'])); endif;?></li>
                                      <li id="dr_rental_li"><strong>Rental </strong><?php if(!empty($driver_settlement_data) && !empty($driver_settlement_data['dr_rental'])): echo $driver_settlement_data['dr_rental']; else : echo 'N/A'; endif;?>
                                      <input type="hidden" id="rental_hidden" name="rental_hidden" value="<?php if(!empty($driver_settlement_data) && !empty($driver_settlement_data['dr_rental'])): echo $driver_settlement_data['dr_rental']; endif;?>">
                                    </li>
                                      <li>
                                      <?php if(!empty($driver_settlement_data['profile_photo'])): ?>
                                  <?php     $profile_photo  = $driver_settlement_data['profile_photo']; ?>
                                  <?php else: ?>
                                  <?php     $profile_photo  = 'no_image.jpg';?>
                                  <?php endif;?>
                                  <img src="<?php echo base_url().'public/upload_image/profile_photo/'.$profile_photo;?>" alt="" width="100px" height="100px"/>
                                  <li><strong><?php echo $name; ?></strong></li>  
                                      </li>
                                    </ul>
                              </div>
                            </div>
                            <div class="table_row repeat"> 
                                  
                                  <div class="row clearfix">
                                    <div class="col-md-6">
                              <h4>Shift Total Docs :</h4>
                              <?php if (!empty($driver_settlement_data['payin_reference_doc'])) : ?>
                                <?php $payin_reference_doc  = $driver_settlement_data['payin_reference_doc']; ?>
                              <?php else : ?>
                                <?php $payin_reference_doc  = 'No_Image_Available.jpg'; ?>
                              <?php endif; ?>
                              <div class="recipt_img">
                                <a href="<?php echo base_url() . 'public/upload_image/payin_images/' . $payin_reference_doc; ?>" data-fancybox data-caption="Payin Reference Docs">
                                  <img height="200" width="200" src="<?php echo base_url() . 'public/upload_image/payin_images/' . $payin_reference_doc; ?>" alt="" />
                                </a>
                              </div>
  
                            </div>
                            <div class="col-md-6">
                              <h4>Lifetime Total Docs :</h4>
                              <?php if (!empty($driver_settlement_data['payin_lifetime_total'])) : ?>
                                <?php $payin_lifetime_total  = $driver_settlement_data['payin_lifetime_total']; ?>
                              <?php else : ?>
                                <?php $payin_lifetime_total  = 'No_Image_Available.jpg'; ?>
                              <?php endif; ?>
                              <div class="recipt_img">
                                <a href="<?php echo base_url() . 'public/upload_image/payin_images/' . $payin_lifetime_total; ?>" data-fancybox data-caption="Payin Reference Docs">
                                  <img height="200" width="200" src="<?php echo base_url() . 'public/upload_image/payin_images/' . $payin_lifetime_total; ?>" alt="" />
                                </a>
                              </div>
  
                            </div>
                                  </div>
                                  </div>
                            
                            <div class="table_row repeat">
                              <!--<h4 class="cash_summary">Driver Settlement</h4>-->
                              <div class="table-responsive custom_table_area">
                                <table class="table table-striped table-bordered daily_stl_table">
                                  <thead>
                                    <tr>
                                      <th>Shift No.</th>
                                      <th>Car No.</th>
                                      <th>Shift Date</th>
                                      <th>Payout/Payin Amount</th>
                                      <th>Settlement Amount</th>
                                      <th>Due</th>
                                    </tr>
                                  </thead>
                                  <tbody>
                                    <?php if (!empty($driver_settlement_data)) : ?>
                                      <tr>
                                        <td><?php if (!empty($driver_settlement_data['shift_no'])) : echo $driver_settlement_data['shift_no'];
                                            endif; ?></td>
                                        <td><?php if (!empty($driver_settlement_data['car_no'])) : echo $driver_settlement_data['car_no'];
                                            endif; ?></td>
                                        <td><?php if (!empty($driver_settlement_data['shift_dt'])) : echo date('d/m/Y', strtotime($driver_settlement_data['shift_dt']));
                                            endif; ?></td>
                                        <td style="text-align: right;"><?php echo $driver_settlement_data['total_payin_payout']; ?></td>
                                        <td><?php echo $driver_settlement_data['settlement_amt']; ?></td>
                                        <td><?php echo $driver_settlement_data['final_due_amt']; ?></td>
                                      </tr>
                                    <?php endif; ?>
                                  </tbody>
                                </table>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>





                      <div class="row clearfix">
                        <div class="col-md-12 roster_left_main">
                          <div class="table_row repeat">
                            <h4 class="cash_summary">Driver Settlement</h4>
                            <div class="table-responsive custom_table_area">
                              <table class="table table-striped table-bordered daily_stl_table">
                                <thead>
                                  <tr>
                                    <th width="25%">Start Reading</th>
                                    <th width="25%">Name of Reading</th>
                                    <th width="25%">Finish Reading</th>
                                    <th width="25%">Action</th>
                                  </tr>
                                </thead>
                                <tbody>
                                  <tr class="total_extra_tr">
                                    <td>
                                      <div style="display:none;" id="total_extra_start_div" class="total_extra_div"><?php if (!empty($driver_settlement_data)) : echo $driver_settlement_data['total_extra_start'];
                                                                                                                    endif; ?></div>
                                      <input type="text" class="form-control decimal_validation_cls total_extra_input" id="total_extra_start" style="width:65%" value="<?php if (!empty($driver_settlement_data)) : echo $driver_settlement_data['total_extra_start'];
                                                                                                                                                                        endif; ?>">
                                    </td>
                                    <td>Total + Extra</td>
                                    <td>
                                      <div style="display:none;" id="total_extra_end_div" class="total_extra_div"><?php if (!empty($driver_settlement_data)) : echo $driver_settlement_data['total_extra_end'];
                                                                                                                  endif; ?></div>
                                      <input type="text" class="form-control decimal_validation_cls total_extra_input" style="width:65%" id="total_extra_end" value="<?php if (!empty($driver_settlement_data)) : echo $driver_settlement_data['total_extra_end'];
                                                                                                                                                                      endif; ?>">
                                    </td>
                                    <td class="text-center">
                                      <!-- <a class="btn_action edit_icon total_extra_edit"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></a> -->
                                      <label class="chk_custom_box">
                                        <input type="checkbox" rel="<?php echo $driver_settlement_data['payin_id']; ?>" class="total_extra_save">
                                        <span class="checkmark"></span>
                                      </label>

                                    </td>
                                  </tr>
                                  <tr class="paid_km_tr">
                                    <td>
                                      <div style="display:none;" id="paid_km_start_div" class="paid_km_div"><?php if (!empty($driver_settlement_data)) : echo $driver_settlement_data['paid_km_start'];
                                                                                                            endif; ?></div>
                                      <input type="text" class="form-control decimal_validation_cls paid_km_input" style="width:65%" id="paid_km_start" value="<?php if (!empty($driver_settlement_data)) : echo $driver_settlement_data['paid_km_start'];
                                                                                                                                                                endif; ?>">
                                    </td>
                                    <td>Paid KM</td>
                                    <td>
                                      <div style="display:none;" id="paid_km_end_div" class="paid_km_div"><?php if (!empty($driver_settlement_data)) : echo $driver_settlement_data['paid_km_end'];
                                                                                                          endif; ?></div>
                                      <input type="text" class="form-control decimal_validation_cls paid_km_input" style="width:65%" id="paid_km_end" value="<?php if (!empty($driver_settlement_data)) : echo $driver_settlement_data['paid_km_end'];
                                                                                                                                                              endif; ?>">
                                    </td>
                                    <td class="text-center">
                                      <!-- <a class="btn_action edit_icon paid_km_edit"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></a> -->

                                      <!-- <a href="javascript:void(0);" rel="<?php echo $driver_settlement_data['payin_id']; ?>" class="btn btn-primary btn-sm okbtn paid_km_save">OK</a> -->
                                      <label class="chk_custom_box">
                                        <input type="checkbox" rel="<?php echo $driver_settlement_data['payin_id']; ?>" class="paid_km_save">
                                        <span class="checkmark"></span>
                                      </label>

                                    </td>
                                  </tr>
                                  <tr class="total_km_tr">
                                    <td>
                                      <div style="display:none;" id="total_km_start_div" class="total_km_div"><?php if (!empty($driver_settlement_data)) : echo $driver_settlement_data['total_km_start'];
                                                                                                              endif; ?></div>
                                      <input type="text" class="form-control decimal_validation_cls total_km_input" style="width:65%" id="total_km_start" value="<?php if (!empty($driver_settlement_data)) : echo $driver_settlement_data['total_km_start'];
                                                                                                                                                                  endif; ?>">
                                    </td>
                                    <td>Total KM</td>
                                    <td>
                                      <div style="display:none;" id="total_km_end_div" class="total_km_div"><?php if (!empty($driver_settlement_data)) : echo $driver_settlement_data['total_km_end'];
                                                                                                            endif; ?></div>
                                      <input type="text" class="form-control decimal_validation_cls total_km_input" style="width:65%" id="total_km_end" value="<?php if (!empty($driver_settlement_data)) : echo $driver_settlement_data['total_km_end'];
                                                                                                                                                                endif; ?>">
                                    </td>
                                    <td class="text-center">
                                      <!-- <a class="btn_action edit_icon total_km_edit"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></a> -->
                                      <!-- <a href="javascript:void(0);" rel="<?php echo $driver_settlement_data['payin_id']; ?>" class="btn btn-primary btn-sm okbtn     total_km_save">OK</a> -->
                                      <label class="chk_custom_box">
                                        <input type="checkbox" rel="<?php echo $driver_settlement_data['payin_id']; ?>" class="total_km_save">
                                        <span class="checkmark"></span>
                                      </label>
                                    </td>
                                  </tr>
                                  <tr class="extra_tr">
                                    <td>
                                      <div style="display:none;" id="extra_start_div" class="extra_div"><?php if (!empty($driver_settlement_data)) : echo $driver_settlement_data['extra_start'];
                                                                                                        endif; ?></div>
                                      <input type="text" class="form-control decimal_validation_cls extra_input" style="width:65%" id="extra_start" value="<?php if (!empty($driver_settlement_data)) : echo $driver_settlement_data['extra_start'];
                                                                                                                                                            endif; ?>">
                                    </td>
                                    <td>Extra</td>
                                    <td>
                                      <div style="display:none;" id="extra_end_div" class="extra_div"><?php if (!empty($driver_settlement_data)) : echo $driver_settlement_data['extra_end'];
                                                                                                      endif; ?></div>
                                      <input type="text" class="form-control decimal_validation_cls extra_input" style="width:65%" id="extra_end" value="<?php if (!empty($driver_settlement_data)) : echo $driver_settlement_data['extra_end'];
                                                                                                                                                          endif; ?>">
                                    </td>
                                    <td class="text-center">
                                      <!-- <a class="btn_action edit_icon extra_edit"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></a>                           -->
                                      <!-- <a href="javascript:void(0);" rel="<?php echo $driver_settlement_data['payin_id']; ?>" class="btn btn-primary btn-sm okbtn extra_save">OK</a> -->
                                      <label class="chk_custom_box">
                                        <input type="checkbox" rel="<?php echo $driver_settlement_data['payin_id']; ?>" class="extra_save">
                                        <span class="checkmark"></span>
                                      </label>
                                    </td>
                                  </tr>
                                  <tr class="no_of_hiring_tr">
                                    <td>
                                      <div style="display:none;" id="no_of_hiring_start_div" class="no_of_hiring_div"><?php if (!empty($driver_settlement_data)) : echo $driver_settlement_data['no_of_hiring_start'];
                                                                                                                      endif; ?></div>
                                      <input type="text" class="form-control num_validation_cls no_of_hiring_input" style="width:65%" id="no_of_hiring_start" value="<?php if (!empty($driver_settlement_data)) : echo $driver_settlement_data['no_of_hiring_start'];
                                                                                                                                                                      endif; ?>">
                                    </td>
                                    <td>Number of Hiring</td>
                                    <td>
                                      <div style="display:none;" id="no_of_hiring_end_div" class="no_of_hiring_div"><?php if (!empty($driver_settlement_data)) : echo $driver_settlement_data['no_of_hiring_end'];
                                                                                                                    endif; ?></div>
                                      <input type="text" class="form-control num_validation_cls no_of_hiring_input" style="width:65%" id="no_of_hiring_end" value="<?php if (!empty($driver_settlement_data)) : echo $driver_settlement_data['no_of_hiring_end'];
                                                                                                                                                                    endif; ?>">
                                    </td>
                                    <td class="text-center">
                                      <!-- <a class="btn_action edit_icon no_of_hiring_edit"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></a>                           -->
                                      <label class="chk_custom_box">
                                        <input type="checkbox" rel="<?php echo $driver_settlement_data['payin_id']; ?>" class="no_of_hiring_save">
                                        <span class="checkmark"></span>
                                      </label>
                                      <!-- <a href="javascript:void(0);" rel="<?php echo $driver_settlement_data['payin_id']; ?>" class="btn btn-primary btn-sm okbtn no_of_hiring_save">OK</a> -->
                                    </td>
                                  </tr>
                                  <tr class="speedo_reading_tr">
                                    <td>
                                      <div style="display:none;" id="speedo_reading_start_div" class="speedo_reading_div"><?php if (!empty($driver_settlement_data)) : echo $driver_settlement_data['speedo_reading_start'];
                                                                                                                          endif; ?></div>
                                      <input type="text" class="form-control num_validation_cls speedo_reading_input" style="width:65%" id="speedo_reading_start" value="<?php if (!empty($driver_settlement_data)) : echo $driver_settlement_data['speedo_reading_start'];
                                                                                                                                                                          endif; ?>">
                                    </td>
                                    <td>Speedo Reading</td>
                                    <td>
                                      <div style="display:none;" id="speedo_reading_end_div" class="speedo_reading_div"><?php if (!empty($driver_settlement_data)) : echo $driver_settlement_data['speedo_reading_end'];
                                                                                                                        endif; ?></div>
                                      <input type="text" class="form-control num_validation_cls speedo_reading_input" style="width:65%" id="speedo_reading_end" value="<?php if (!empty($driver_settlement_data)) : echo $driver_settlement_data['speedo_reading_end'];
                                                                                                                                                                        endif; ?>">
                                    </td>
                                    <td class="text-center">
                                      <!-- <a class="btn_action edit_icon speedo_reading_edit"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></a>                         -->
                                      <!-- <a href="javascript:void(0);" rel="<?php echo $driver_settlement_data['payin_id']; ?>" class="btn btn-primary btn-sm okbtn speedo_reading_save">OK</a> -->
                                      <label class="chk_custom_box">
                                        <input type="checkbox" rel="<?php echo $driver_settlement_data['payin_id']; ?>" class="speedo_reading_save">
                                        <span class="checkmark"></span>
                                      </label>
                                    </td>
                                  </tr>
                                </tbody>
                              </table>
                            </div>
                          </div>
                          <div class="table_row repeat">
                            <h4 class="cash_summary">Dockets Details
                              <button type="button" id="add_more_docket" class="btn btn-success btn-sm" style="float:right;"><span><i class="fa fa-plus" aria-hidden="true"></i></span> Docket</button>
                            </h4>
                            <div class="table-responsive custom_table_area">
                              <table class="table table-striped table-bordered daily_stl_table">
                                <thead>
                                  <tr>
                                    <th width="25%">Dockets Name</th>
                                    <th width="25%">Photo</th>
                                    <th width="25%">Total</th>
                                    <th width="25%">Action</th>
                                  </tr>
                                </thead>
                                <tbody id="driver_docket_tbody">
                                  <?php if (!empty($settlement_dockets_data)) : ?>
                                    <?php foreach ($settlement_dockets_data as $docket_key => $dockets) : ?>
                                      <tr class="driver_docket_tr">
                                        <td><?php echo $dockets['docket_name']; ?></td>
                                        <td>
                                          <div class="ds_td_img">
                                            
                                          <select class="docket_upload_image_btn">
                                          <option value=""  data-id="<?=$docket_key + 1?>">Select</option>
                                          <option value="C" data-id="<?=$docket_key + 1?>">Camera</option>
                                          <option value="F" data-id="<?=$docket_key + 1?>">File</option>
                                        </select>
                            
                                        <input type="hidden" id="docket_image_<?=$docket_key + 1?>"  class="docket_image" value="<?=$dockets['docket_img']?>">
                                        <input type="file" id="docket_image_file_<?=$docket_key + 1?>" class="docket_image_file" style="display:none;">
                                        
                                        <a id="docket_uploaded_a_<?=$docket_key + 1?>" href="<?=!empty($dockets['docket_img'])?base_url('public/upload_image/payin_images/'.$dockets['docket_img']):base_url('public/upload_image/profile_photo/No_Image_Available.jpg')?>" data-fancybox data-caption="Dockets IMAGE">
                                          <img id="docket_uploaded_img_<?=$docket_key + 1?>" src="<?=!empty($dockets['docket_img'])?base_url('public/upload_image/payin_images/'.$dockets['docket_img']):base_url('public/upload_image/profile_photo/No_Image_Available.jpg')?>" alt="<?php echo $dockets['docket_name']; ?>" width="50px" height="50px"/>
                                        </a>
                                          
                                            <!--<input class="input_file" type="hidden" name="docket_img" style="width:100px">-->
                                          </div>
                                        </td>
                                        <td class="td_amount_right driver_docket_price">

                                          <div class="input-group">
                                            <div class="input-group-prepend docket_pr_input">
                                              <span class="input-group-text" id="basic-addon1">$</span>
                                            </div>
                                            <div style="display:none;" class="docket_price_div"><?php echo $dockets['docket_amount']; ?></div>
                                            <input type="hidden" name="docket_id[]" value="<?php echo $dockets['docket_id']; ?>">
                                            <input type="hidden" name="dr_settlement_docket_id[]" value="<?php echo $dockets['dr_settlement_docket_id']; ?>">
                                            <input type="hidden" class="docket_identification_id" value="payin_dockets_<?=$docket_key + 1?>">
                                            <input class="form-control docket_pr_input decimal_validation_cls docket_price_val" type="text" name="docket_price[]" value="<?php echo $dockets['docket_amount']; ?>" style="width:65%">
                                          </div>


                                        </td>
                                        <td class="text-center">
                                          <label class="chk_custom_box">
                                            <input type="checkbox" id="<?php echo $dockets['payin_dockets_id']; ?>" class="driver_docket_save">
                                            <span class="checkmark"></span>
                                          </label>
                                          <button type="button" data-payin_dockets_id="<?php echo $dockets['payin_dockets_id']; ?>" class="btn btn-danger btn-sm delete_btn"><span><i class="fa fa-trash" aria-hidden="true"></i></span></button>

                                        </td>

                                      </tr>
                                    <?php endforeach; ?>
                                  <?php else : ?>
                                    <tr>
                                      <td colspan="4">No data found</td>
                                    </tr>
                                  <?php endif; ?>
                                </tbody>
                              </table>
                            </div>
                            <div class="contentarea" style="display:none;">
															<div class="camera">
																<video id="video">Video stream not available.</video>
																
															</div>
															<canvas id="canvas"></canvas>
															<div class="output">
																<img id="photo" alt="The screen capture will appear in this box."> 
															</div>
															<hr>				
															<button id="startbutton" type="button" data-button_id="" class="btn btn-success btn-sm">Capture</button> 
														</div>       

                          </div>
                          <div class="table_row repeat">
                            <h4 class="cash_summary">Expense Details
                              <button type="button" id="add_more_expense" class="btn btn-success btn-sm" style="float:right;"><span><i class="fa fa-plus" aria-hidden="true"></i></span> Expense</button>
                            </h4>
                            <div class="table-responsive custom_table_area">
                              <table class="table table-striped table-bordered daily_stl_table">
                                <thead>
                                  <tr>
                                    <th>Expense Name</th>
                                    <th>Photo</th>
                                    <th>Amount</th>
                                    <th>Action</th>
                                  </tr>
                                </thead>
                                <tbody id="driver_expense_tbody">
                                  <?php if (!empty($settlement_expense_data)) : ?>
                                    <?php foreach ($settlement_expense_data as $expense_key => $expense) : ?>
                                      <tr class="driver_expenses_tr">
                                        <td><?php echo $expense['expense_name']; ?></td>
                                        <td>
                                          <div class="ds_td_img">
                                          <select class="expense_upload_image_btn">
                                          <option value="" data-id="<?=$expense_key +1?>">Select</option>
                                          <option value="C" data-id="<?=$expense_key +1?>">Camera</option>
                                          <option value="F" data-id="<?=$expense_key +1?>">File</option>
                                        </select>
                            
                                        <input type="hidden" id="expense_image_<?=$expense_key +1?>"  class="expense_image" value="<?=$expense['expense_img']?>">
                                        <input type="file" id="expense_image_file_<?=$expense_key +1?>" name="" class="expense_image_file" style="display:none;">

                                        <a id="expense_uploaded_a_<?=$expense_key + 1?>" href="<?=!empty($expense['expense_img'])?base_url('public/upload_image/payin_images/'.$expense['expense_img']):base_url('public/upload_image/profile_photo/No_Image_Available.jpg')?>" data-fancybox data-caption="Expense IMAGE">
                                          <img id="expense_uploaded_img_<?=$expense_key + 1?>" src="<?=!empty($expense['expense_img'])?base_url('public/upload_image/payin_images/'.$expense['expense_img']):base_url('public/upload_image/profile_photo/No_Image_Available.jpg')?>" alt="<?php echo $expense['expense_name']; ?>" width="50px" height="50px"/></a>
                                          </div>
                                        </td>
                                        <td class="td_amount_right expense_price_td">
                                          <div class="input-group">
                                            <div class="input-group-prepend expense_price_inp">
                                              <span class="input-group-text" id="basic-addon1">$</span>
                                            </div>
                                            <div style="display:none;" class="expense_price_div"><?php echo $expense['expense_amount']; ?></div>
                                            <input type="hidden" name="expense_id[]" value="<?php echo $expense['expense_id']; ?>">
                                            <input type="hidden" name="dr_settlement_expense_id[]" value="<?php echo $expense['dr_settlement_expense_id']; ?>">
                                            <input type="hidden" class="expense_identification_id" value="payin_expense_<?=$expense_key?>">
                                            <input type="text" class="form-control expense_price_inp decimal_validation_cls expense_price_val" name="expense_price[]" value="<?php echo $expense['expense_amount']; ?>" style="width:65%">
                                          </div>
                                        </td>
                                        <td class="text-center">

                                          <label class="chk_custom_box">
                                            <input type="checkbox" id="<?php echo $expense['payin_expense_id']; ?>" class="driver_expense_save">
                                            <span class="checkmark"></span>
                                            
                                          </label>
                                          <button type="button" data-payin_expense_id="<?php echo $expense['payin_expense_id']; ?>" class="btn btn-danger btn-sm delete_btn_expense"><span><i class="fa fa-trash" aria-hidden="true"></i></span></button>
                                          <!-- <a href="javascript:void(0);" class="btn_action edit_icon driver_expense_edit" ><i class="fa fa-pencil-square-o" aria-hidden="true"></i></a><a href="javascript:void(0);" id="<?php echo $expense['payin_expense_id']; ?>" class="btn btn-primary btn-sm okbtn driver_expense_save">OK</a> -->
                                        </td>
                                      </tr>
                                    <?php endforeach; ?>
                                  <?php else : ?>
                                    <tr>
                                      <td colspan="4">No data found</td>
                                    </tr>
                                  <?php endif; ?>
                                </tbody>
                              </table>
                            </div>
                            <div class="contentarea1" style="display:none;">
															<div class="camera1">
																<video id="video1">Video stream not available.</video>
																
															</div>
															<canvas id="canvas1"></canvas>
															<div class="output1">
																<img id="photo1" alt="The screen capture will appear in this box."> 
															</div>
															<hr>				
															<button id="startbutton1" type="button" data-button_id="" class="btn btn-success btn-sm">Capture</button> 
														</div>
                          </div>
                          <div class="table_row repeat">
                            <!--<h4 class="cash_summary">Fuel Details</h4>-->
                            <div class="table-responsive custom_table_area">
                              <table class="table table-striped table-bordered daily_stl_table">
                                <thead>
                                  <tr>
                                    <th>Title</th>
                                    <th>Commission Based</th>
                                    <th>Rental Based</th>
                                  </tr>
                                </thead>
                                <tbody>
                                  <tr>
                                    <td style="color: #000;font-weight: 500; width: 50%;">Docket Total</td>
                                    <td class="td_amount_right">
                                      <div class="input-group">
                                        <div class="input-group-prepend">
                                          <span class="input-group-text" id="basic-addon1">$</span>
                                        </div>
                                        <input type="text" class="form-control" id="total_dockets" aria-label="Username" aria-describedby="basic-addon1" value="<?php echo $total_settlement['total_dockets']; ?>" readonly>
                                      </div>
                                    </td>
                                    <td class="td_amount_right">
                                      <div class="input-group">
                                        <div class="input-group-prepend">
                                          <span class="input-group-text" id="basic-addon1">$</span>
                                        </div>
                                        <input type="text" class="form-control" id="total_dockets_rental" aria-label="Username" aria-describedby="basic-addon1" value="<?php echo $total_settlement['total_dockets']; ?>" readonly>
                                      </div>
                                    </td>
                                  </tr>
                                  <tr>
                                    <td style="color: #000;font-weight: 500; width: 50%;">Expense Total</td>
                                    <td class="td_amount_right">
                                      <div class="input-group">
                                        <div class="input-group-prepend">
                                          <span class="input-group-text" id="basic-addon1">$</span>
                                        </div>
                                        <input type="text" class="form-control" id="total_expense" aria-label="Username" aria-describedby="basic-addon1" value="<?php echo $total_settlement['total_expense']; ?>" readonly>
                                      </div>
                                    </td>
                                    <td class="td_amount_right">
                                      <div class="input-group">
                                        <div class="input-group-prepend">
                                          <span class="input-group-text" id="basic-addon1">$</span>
                                        </div>
                                        <input type="text" class="form-control" id="total_expense_rental" aria-label="Username" aria-describedby="basic-addon1" value="<?php echo $total_settlement['total_expense']; ?>" readonly>
                                      </div>
                                    </td>

                                  </tr>
                                  <tr>
                                    <td style="color: #000;font-weight: 500; width: 50%;">Shift Levy</td>
                                    <td class="td_amount_right">
                                      <div class="input-group">
                                        <div class="input-group-prepend">
                                          <span class="input-group-text" id="basic-addon1">$</span>
                                        </div>
                                        <input type="text" class="form-control" id="levy_total" aria-label="" aria-describedby="basic-addon1" value="<?php echo $total_settlement['levy_total']; ?>" readonly>
                                      </div>
                                    </td>
                                    <td class="td_amount_right">
                                      <div class="input-group">
                                        <div class="input-group-prepend">
                                          <span class="input-group-text" id="basic-addon1">$</span>
                                        </div>
                                        <input type="text" class="form-control" id="levy_total_rental" aria-label="" aria-describedby="basic-addon1" value="<?php echo $total_settlement['levy_total']; ?>" readonly>
                                      </div>
                                    </td>
                                  </tr>
                                  <tr>
                                    <td style="color: #000;font-weight: 500; width: 50%;">WHL</td>
                                    <td class="td_amount_right">
                                      <div class="input-group">
                                        <div class="input-group-prepend">
                                          <span class="input-group-text" id="basic-addon1">$</span>
                                        </div>
                                        <input type="text" class="form-control calculate_due_amt" id="no_of_whl" aria-label="" aria-describedby="basic-addon1" value="<?php echo $driver_settlement_data['no_of_whl']; ?>" data-rental_commission="commission">
                                      </div>
                                    </td>
                                    <td class="td_amount_right">
                                      <div class="input-group">
                                        <div class="input-group-prepend">
                                          <span class="input-group-text" id="basic-addon1">$</span>
                                        </div>
                                        <input type="text" class="form-control calculate_due_amt" id="no_of_whl_rental" aria-label="" aria-describedby="basic-addon1" value="<?php echo $driver_settlement_data['no_of_whl']; ?>" data-rental_commission="rental"readonly>
                                      </div>
                                    </td>
                                  </tr>

                                </tbody>
                              </table>
                            </div>
                          </div>
                          <div class="table_row repeat">
                            <!--<h4 class="cash_summary">Fuel Details</h4>-->
                            <div class="table-responsive custom_table_area">
                              <table class="table table-striped table-bordered daily_stl_table">
                                <thead>
                                  <tr>
                                    <th>Title</th>
                                    <th>Commission Based</th>
                                    <th>Rental Based</th>
                                  </tr>
                                </thead>
                                <tbody>
                                  <tr>
                                    <td style="color: #000;font-weight: 500; width: 50%;">Accident Installment</td>
                                    <td class="td_amount_right">
                                      <div class="input-group">
                                        <div class="input-group-prepend">
                                          <span class="input-group-text" id="basic-addon1">$</span>
                                        </div>
                                        <input type="text" class="form-control calculate_due_amt" id="accident_installment" data-rental_commission="commission" aria-label="Username" aria-describedby="basic-addon1" value="<?= number_format((!empty($driver_settlement_data['accident_installment']) ? $driver_settlement_data['accident_installment'] : 0), 2, '.', '') ?>">
                                      </div>

                                    </td>

                                    <td class="td_amount_right">
                                      <div class="input-group">
                                        <div class="input-group-prepend">
                                          <span class="input-group-text" id="basic-addon1">$</span>
                                        </div>
                                        <input type="text" class="form-control calculate_due_amt" data-rental_commission="rental" id="accident_installment_rental" aria-label="Username" aria-describedby="basic-addon1" value="<?= number_format((!empty($driver_settlement_data['accident_installment']) ? $driver_settlement_data['accident_installment'] : 0), 2, '.', '') ?>">
                                      </div>

                                    </td>
                                  </tr>
                                  <tr>
                                    <td style="color: #000;font-weight: 500; width: 50%;">Bond Installment</td>
                                    <td class="td_amount_right">
                                      <div class="input-group">
                                        <div class="input-group-prepend">
                                          <span class="input-group-text" id="basic-addon1">$</span>
                                        </div>
                                        <input type="text" class="form-control calculate_due_amt" id="bond_total" data-rental_commission="commission" aria-label="Username" aria-describedby="basic-addon1" value="<?= number_format((!empty($total_settlement['bond_total_com']) ? $total_settlement['bond_total_com'] : 0), 2, '.', '') ?>" readonly>
                                      </div>
                                    </td>

                                    <td class="td_amount_right">
                                      <div class="input-group">
                                        <div class="input-group-prepend">
                                          <span class="input-group-text" id="basic-addon1">$</span>
                                        </div>
                                        <input type="text" class="form-control calculate_due_amt" data-rental_commission="rental" id="bond_total_rental" aria-label="Username" aria-describedby="basic-addon1" value="<?= number_format((!empty($total_settlement['bond_total_rental']) ? $total_settlement['bond_total_rental'] : 0), 2, '.', '') ?>" readonly>
                                      </div>
                                    </td>
                                  </tr>
                                  <tr>
                                    <td style="color: #000;font-weight: 500; width: 50%;">Others</td>
                                    <td class="td_amount_right">
                                      <div class="input-group">
                                        <div class="input-group-prepend">
                                          <span class="input-group-text" id="basic-addon1">$</span>
                                        </div>
                                        <input type="text" class="form-control calculate_due_amt" id="other" data-rental_commission="commission" aria-label="" aria-describedby="basic-addon1" value="<?= number_format((!empty($total_settlement['other_com']) ? $total_settlement['other_com'] : 0), 2, '.', '') ?>">
                                      </div>
                                    </td>

                                    <td class="td_amount_right">
                                      <div class="input-group">
                                        <div class="input-group-prepend">
                                          <span class="input-group-text" id="basic-addon1">$</span>
                                        </div>
                                        <input type="text" class="form-control calculate_due_amt" id="other_rental" aria-label="" aria-describedby="basic-addon1" data-rental_commission="rental" value="<?= number_format((!empty($total_settlement['other_rental']) ? $total_settlement['other_rental'] : 0), 2, '.', '') ?>">
                                      </div>
                                    </td>
                                  </tr>

                                  <?php

                                  //echo '<pre>';print_r($driver_settlement_data);die;

                                  // $dr_rental = (!empty($driver_settlement_data) && !empty($driver_settlement_data['dr_rental']))? $driver_settlement_data['dr_rental']:0;
                                  // $total_dockets=isset($total_settlement['total_dockets'])?$total_settlement['total_dockets']:0;
                                  // $total_expense=isset($total_settlement['total_expense'])?$total_settlement['total_expense']:0;
                                  // $total_levy=isset($total_settlement['levy_total'])?$total_settlement['levy_total']:0;
                                  // $bond=!empty($driver_settlement_data['dr_rental'])?(isset($total_settlement['bond_total'])?$total_settlement['bond_total']:0):0;
                                  // $accident=isset($total_settlement['accident_installment'])?$total_settlement['accident_installment']:0;
                                  // $other=isset($total_settlement['other'])?$total_settlement['other']:0;
                                  // $amount_paid = 0;
                                  // $amount_paid=$driver_settlement_data['settlement_amt'] - $driver_settlement_data['final_due_amt'];

                                  // $rental_payout = !empty($driver_settlement_data['dr_rental'])? ($dr_rental - $total_dockets + $total_levy + $bond + $accident + $other - $amount_paid):'0.00';
                                  // $discount = !empty($driver_settlement_data['dr_rental'])?($total_settlement['amount_due'] - $rental_payout - $amount_paid):'0.00';
                                  //$driver_payout = $actual_payout - $discount;
                                  ?>
                                  <tr>
                                    <td style="color: #000;font-weight: 500;">Discount</td>
                                    <td class="td_amount_right">
                                      <div class="input-group">
                                        <div class="input-group-prepend">
                                          <span class="input-group-text" id="basic-addon1">$</span>
                                        </div>
                                        <input type="text" class="form-control calculate_due_amt" id="discount" data-rental_commission="commission" aria-label="" aria-describedby="basic-addon1" value="<?= !empty($total_settlement['discount_com']) ? number_format($total_settlement['discount_com'], 2, '.', '') : 0 ?>">
                                      </div>
                                    </td>
                                    <td class="td_amount_right">
                                      <div class="input-group">
                                        <div class="input-group-prepend">
                                          <span class="input-group-text" id="basic-addon1">$</span>
                                        </div>
                                        <input type="text" class="form-control calculate_due_amt" id="discount_rental" data-rental_commission="rental" aria-label="" aria-describedby="basic-addon1" value="<?= !empty($total_settlement['discount_rental']) ? number_format($total_settlement['discount_rental'], 2, '.', '') : 0 ?>">
                                      </div>
                                    </td>
                                  </tr>

                                  <tr>
                                    <td style="color: #000;font-weight: 500; width: 50%;"><Strong>Amount Paid</Strong></td>
                                    <td class="td_amount_right">
                                      <div class="input-group">
                                        <div class="input-group-prepend">
                                          <span class="input-group-text" id="basic-addon1">$</span>
                                        </div>

                                        <input type="text" class="form-control calculate_due_amt" id="amount_paid" data-rental_commission="commission" aria-label="" aria-describedby="basic-addon1" value="<?= !empty($total_settlement['amount_paid_com']) ? number_format($total_settlement['amount_paid_com'], 2, '.', '') : 0 ?>" readonly>

                                      </div>
                                    </td>
                                    <td class="td_amount_right">
                                      <div class="input-group">
                                        <div class="input-group-prepend">
                                          <span class="input-group-text" id="basic-addon1">$</span>
                                        </div>

                                        <input type="text" class="form-control calculate_due_amt" id="amount_paid_rental" data-rental_commission="rental" aria-label="" aria-describedby="basic-addon1" value="<?= !empty($total_settlement['amount_paid_rental']) ? number_format($total_settlement['amount_paid_rental'], 2, '.', '') : 0 ?>" readonly>

                                      </div>
                                    </td>
                                  </tr>


                                  <tr>
                                    <td style="color: #000;font-weight: 500; width: 50%;"><Strong>Amount Due</Strong></td>
                                    <td class="td_amount_right">
                                      <div class="input-group">
                                        <div class="input-group-prepend">
                                          <span class="input-group-text" id="basic-addon1">$</span>
                                        </div>

                                        <input type="text" class="form-control calculate_due_amt" id="amount_due" data-rental_commission="commission" aria-label="" aria-describedby="basic-addon1" value="<?= isset($total_settlement['amount_due_com']) ? number_format($total_settlement['amount_due_com'], 2, '.', '') : 0 ?>" readonly>
                                        <input type="hidden" id="total" class="form-control" aria-label="" data-rental_commission="commission" aria-describedby="basic-addon1" value="<?= isset($total_settlement['total_com']) ? $total_settlement['total_com'] : 0 ?>">
                                      </div>
                                    </td>
                                    <td class="td_amount_right">
                                      <div class="input-group">
                                        <div class="input-group-prepend">
                                          <span class="input-group-text" id="basic-addon1">$</span>
                                        </div>

                                        <input type="text" class="form-control calculate_due_amt" id="amount_due_rental" data-rental_commission="rental" aria-label="" aria-describedby="basic-addon1" value="<?= isset($total_settlement['amount_due_rental']) ? number_format($total_settlement['amount_due_rental'], 2, '.', '') : 0 ?>" readonly>
                                        <input type="hidden" id="total_rental" class="form-control" data-rental_commission="rental" aria-label="" aria-describedby="basic-addon1" value="<?= isset($total_settlement['amount_due_rental']) ? number_format($total_settlement['amount_due_rental'], 2, '.', '') : 0 ?>">
                                      </div>
                                    </td>
                                  </tr>
                                  <!-- <tr>
                        <td style="color: #000;font-weight: 800;"><Strong>Total</Strong></td>
                        <td class="td_amount_right">
                          <div class="input-group">
                              <div class="input-group-prepend">
                                  <span class="input-group-text" id="basic-addon1">$</span>
                              </div>
                              <input type="text" id="total" class="form-control" aria-label="" aria-describedby="basic-addon1" value="<?php echo $total_settlement['total']; ?>">
                          </div>
                        </td>
                    </tr> -->
                                </tbody>
                              </table>
                            </div>
                          </div>

                          <div class="table_row repeat">

                            <h4 class="cash_summary">
                              <strong><span id="payment_collection_div"> <?= ((!empty($driver_settlement_data['dr_rental']) ? $total_settlement['amount_due_rental'] : $total_settlement['amount_due_com']) < 0) ? 'Payment Mode' : 'Payment Collection Mode' ?></span></strong>
                              <strong style="float: right;">$<span style="float: right;" id="final_due_amount"><?= (!empty($driver_settlement_data['dr_rental']) ? $total_settlement['amount_due_rental'] : $total_settlement['amount_due_com']) ?></span></strong>
                            </h4>
                            <input type="hidden" id="final_due_amount_hid" name="final_due_amount_hid" value="<?= (!empty($driver_settlement_data['dr_rental']) ? $total_settlement['amount_due_rental'] : $total_settlement['amount_due_com']) ?>">
                            <?php if ($driver_settlement_data['bulk_settlement_flag'] == 0) { ?>
                            <div class="table-responsive custom_table_area">
                              <table class="table table-striped table-bordered daily_stl_table">
                                <tbody>
                                  <?php if (!empty($payment_options)) : ?>
                                    <?php foreach ($payment_options as $payopn) : ?>
                                      <tr>
                                        <td style="width: 50%;"><?php echo $payopn['payment_method'] ?></td>
                                        <td>
                                          <div class="input-group">
                                            <div class="input-group-prepend">
                                              <span class="input-group-text" id="basic-addon1">$</span>
                                            </div>
                                            <input type="text" id="<?php echo $payopn['payment_method_id'] ?>" class="form-control payment_opn decimal_positive_cls">
                                          </div>
                                        </td>
                                      </tr>
                                    <?php endforeach; ?>
                                  <?php endif; ?>
                                  <tr>
                                    <td style="width: 50%;color: #000;font-weight: 800;"><strong>Accumulate</strong></td>
                                    <td>
                                      <div class="input-group">
                                        <div class="input-group-prepend">
                                          <span class="input-group-text" id="basic-addon1">$</span>
                                        </div>
                                        <input type="text" id="admin_total_payment" name="admin_total_payment" class="form-control" value="" readonly>
                                      </div>
                                    </td>
                                  </tr>
                                </tbody>
                              </table>
                            </div>
                            <?php } ?>
                          </div>
                          <!--  Denomination -->
                          <!-- <div id="denomination_div" class="table_row repeat" style="display:none;">
                            <div class="daily_stl_top_box">
                              <h4 class="cash_summary">Denominations</h4>

                              <div class="table-responsive custom_table_area">
                                <table class="table table-striped table-bordered daily_stl_table">
                                  <thead>
                                    <tr>
                                    <th width="20%">Notes</th>
                                    <th width="30%">Qty</th>
                                    <th width="50%">Amount</th>
                                    </tr>
                                  </thead>
                                  <tbody>
                                  <tr style="display:none;">
                                    <td>1c Coins</td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt num_validation_cls" name="1c_coins_qty" id="1c_coins_qty" data-dollar_price=".01">
                                      <input type="hidden" id="1c_coins_amt" name="1c_coins_amt">
                                    </td>
                                    <td class="dollar_amount"></td>
                                </tr>
                                <tr>
                                    <td>5c Coins</td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt num_validation_cls" name="5c_coins_qty" id="5c_coins_qty" data-dollar_price=".05" data-balance_qty="<?=(isset($cash_in_data['5c_coins_qty']) || isset($cash_out_data['5c_coins_qty']))?($cash_in_data['5c_coins_qty'] - $cash_out_data['5c_coins_qty']) : 0?>">
                                      <input type="hidden" id="5c_coins_amt" name="5c_coins_amt">
                                    </td>
                                    <td class="dollar_amount"></td>
                                </tr>
                                <tr>
                                    <td>10c Coins</td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt num_validation_cls" name="10c_coins_qty" id="10c_coins_qty" data-dollar_price=".10" data-balance_qty="<?=(isset($cash_in_data['10c_coins_qty']) || isset($cash_out_data['10c_coins_qty']))?($cash_in_data['10c_coins_qty'] - $cash_out_data['10c_coins_qty']) : 0?>">
                                      <input type="hidden" id="10c_coins_amt" name="10c_coins_amt">
                                    </td>
                                    <td class="dollar_amount"></td>
                                </tr>
                                <tr>
                                    <td>20c Coins</td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt num_validation_cls" name="20c_coins_qty" id="20c_coins_qty" data-dollar_price=".20" data-balance_qty="<?=(isset($cash_in_data['20c_coins_qty']) || isset($cash_out_data['20c_coins_qty']))?($cash_in_data['20c_coins_qty'] - $cash_out_data['20c_coins_qty']) : 0?>">
                                      <input type="hidden" id="20c_coins_amt" name="20c_coins_amt">
                                    </td>
                                    <td class="dollar_amount"></td>
                                </tr>
                                <tr>
                                    <td>50c Coins</td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt num_validation_cls" name="50c_coins_qty" id="50c_coins_qty" data-dollar_price=".50" data-balance_qty="<?=(isset($cash_in_data['50c_coins_qty']) || isset($cash_out_data['50c_coins_qty']))?($cash_in_data['50c_coins_qty'] - $cash_out_data['50c_coins_qty']) : 0?>">
                                      <input type="hidden" id="50c_coins_amt" name="50c_coins_amt">
                                    </td>
                                    <td class="dollar_amount"></td>
                                </tr>
                                <tr>
                                    <td>1$ Coins</td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt num_validation_cls" name="1d_coins_qty" id="1d_coins_qty" data-dollar_price="1" data-balance_qty="<?=(isset($cash_in_data['1d_coins_qty']) || isset($cash_out_data['1d_coins_qty']))?($cash_in_data['1d_coins_qty'] - $cash_out_data['1d_coins_qty']) : 0?>">
                                      <input type="hidden" id="1d_coins_amt" name="1d_coins_amt">
                                    </td>
                                    <td class="dollar_amount"></td>
                                </tr>
                                <tr>
                                    <td>2$ Coins</td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt num_validation_cls" name="2d_coins_qty" id="2d_coins_qty" data-dollar_price="2" data-balance_qty="<?=(isset($cash_in_data['2d_coins_qty']) || isset($cash_out_data['2d_coins_qty']))?($cash_in_data['2d_coins_qty'] - $cash_out_data['2d_coins_qty']) : 0?>">
                                      <input type="hidden" id="2d_coins_amt" name="2d_coins_amt">
                                    </td>
                                    <td class="dollar_amount"></td>
                                </tr>
                                <tr>
                                    <td>5$ Notes</td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt num_validation_cls" name="5d_notes_qty" id="5d_notes_qty" data-dollar_price="5" data-balance_qty="<?=(isset($cash_in_data['5d_notes_qty']) || isset($cash_out_data['5d_notes_qty']))?($cash_in_data['5d_notes_qty'] - $cash_out_data['5d_notes_qty']) : 0?>">
                                      <input type="hidden" id="5d_notes_amt" name="5d_notes_amt">
                                    </td>
                                    <td class="dollar_amount"></td>
                                </tr>
                                <tr>
                                    <td>10$ Notes</td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt num_validation_cls" name="10d_notes_qty" id="10d_notes_qty" data-dollar_price="10" data-balance_qty="<?=(isset($cash_in_data['10d_notes_qty']) || isset($cash_out_data['10d_notes_qty']))?($cash_in_data['10d_notes_qty'] - $cash_out_data['10d_notes_qty']) : 0?>">
                                      <input type="hidden" id="10d_notes_amt" name="10d_notes_amt">
                                    </td>
                                    <td class="dollar_amount"></td>
                                </tr>
                                <tr>
                                    <td>20$ Notes</td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt num_validation_cls" name="20d_notes_qty" id="20d_notes_qty" data-dollar_price="20" data-balance_qty="<?=(isset($cash_in_data['20d_notes_qty']) || isset($cash_out_data['20d_notes_qty']))?($cash_in_data['20d_notes_qty'] - $cash_out_data['20d_notes_qty']) : 0?>">
                                      <input type="hidden" id="20d_notes_amt" name="20d_notes_amt">
                                    </td>
                                    <td class="dollar_amount"></td>
                                </tr>
                                <tr>
                                    <td>50$ Notes</td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt num_validation_cls" name="50d_notes_qty" id="50d_notes_qty" data-dollar_price="50" data-balance_qty="<?=(isset($cash_in_data['50d_notes_qty']) || isset($cash_out_data['50d_notes_qty']))?($cash_in_data['50d_notes_qty'] - $cash_out_data['50d_notes_qty']) : 0?>">
                                      <input type="hidden" id="50d_notes_amt" name="50d_notes_amt">
                                    </td>
                                    <td class="dollar_amount"></td>
                                </tr>
                                <tr>
                                    <td>100$ Notes</td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt num_validation_cls" name="100d_notes_qty" id="100d_notes_qty" data-dollar_price="100" data-balance_qty="<?=(isset($cash_in_data['100d_notes_qty']) || isset($cash_out_data['100d_notes_qty']))?($cash_in_data['100d_notes_qty'] - $cash_out_data['100d_notes_qty']) : 0?>">
                                      <input type="hidden" id="100d_notes_amt" name="100d_notes_amt">
                                    </td>
                                    <td class="dollar_amount"></td>
                                </tr>
                                  </tbody>
                                  <tfoot>
                                    <tr>
                                      <td colspan="2"><strong>TOTAL</strong></td>
                                      <td><strong class="total_amount"></strong></td>
                                      <input type="hidden" id="total_amount" name="total_amount">
                                    </tr>
                                  </tfoot>
                                </table>
                              </div>
                            </div>
                          </div> -->

                          <div id="denomination_div" class="table_row repeat" style="display:none;">
                        <div class="daily_stl_top_box">
                          <h4 class="cash_summary">Denominations</h4>

                          <div class="table-responsive custom_table_area">
                            <table class="table table-striped table-bordered daily_stl_table">
                              <thead>
                                <tr>
                                  <th width="10%">Notes</th>
                                  <th width="10%">Qty</th>
                                  <th width="20%">Amount</th>
                                  <th width="10%">Adjustment Qty</th>
                                  <th width="20%">Amount</th>
                                  <th width="30%">Final Amount</th>
                                  
                                </tr>
                              </thead>
                              <tbody>
                              <tr style="display:none;">
                                    <td>1c Coins</td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt num_validation_cls" name="1c_coins_qty" id="1c_coins_qty" data-dollar_price=".01">
                                      <input type="hidden" id="1c_coins_amt" name="1c_coins_amt">
                                    </td>
                                    <td class="dollar_amount"></td>
                                </tr>
                                <tr>
                                    <td>5c Coins</td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt num_validation_cls" name="5c_coins_qty" id="5c_coins_qty" data-dollar_price=".05" data-balance_qty="<?=(isset($cash_in_data['5c_coins_qty']) || isset($cash_out_data['5c_coins_qty']))?($cash_in_data['5c_coins_qty'] - $cash_out_data['5c_coins_qty']) : 0?>">
                                      <input type="hidden" id="5c_coins_amt" name="5c_coins_amt">
                                    </td>
                                    <td class="dollar_amount"></td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt_adjust num_validation_cls" name="5c_coins_qty_adjust" id="5c_coins_qty_adjust" data-dollar_price=".05" data-balance_qty="<?=(isset($cash_in_data['5c_coins_qty']) || isset($cash_out_data['5c_coins_qty']))?($cash_in_data['5c_coins_qty'] - $cash_out_data['5c_coins_qty']) : 0?>">
                                      <input type="hidden" id="5c_coins_amt_adjust" name="5c_coins_amt_adjust">
                                    </td>
                                    <td class="dollar_amount_adjust"></td>
                                    <td class="final_amount"></td>
                                </tr>
                                <tr>
                                    <td>10c Coins</td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt num_validation_cls" name="10c_coins_qty" id="10c_coins_qty" data-dollar_price=".10" data-balance_qty="<?=(isset($cash_in_data['10c_coins_qty']) || isset($cash_out_data['10c_coins_qty']))?($cash_in_data['10c_coins_qty'] - $cash_out_data['10c_coins_qty']) : 0?>">
                                      <input type="hidden" id="10c_coins_amt" name="10c_coins_amt">
                                    </td>
                                    <td class="dollar_amount"></td>
                                    <td>
                                    <input type="text" class="form-control calculate_amt_adjust num_validation_cls" name="10c_coins_qty_adjust" id="10c_coins_qty_adjust" data-dollar_price=".10" data-balance_qty="<?=(isset($cash_in_data['10c_coins_qty']) || isset($cash_out_data['10c_coins_qty']))?($cash_in_data['10c_coins_qty'] - $cash_out_data['10c_coins_qty']) : 0?>">
                                      <input type="hidden" id="10c_coins_amt_adjust" name="10c_coins_amt_adjust">
                                    </td>
                                    <td class="dollar_amount_adjust"></td>
                                    <td class="final_amount"></td>
                                </tr>
                                <tr>
                                    <td>20c Coins</td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt num_validation_cls" name="20c_coins_qty" id="20c_coins_qty" data-dollar_price=".20" data-balance_qty="<?=(isset($cash_in_data['20c_coins_qty']) || isset($cash_out_data['20c_coins_qty']))?($cash_in_data['20c_coins_qty'] - $cash_out_data['20c_coins_qty']) : 0?>">
                                      <input type="hidden" id="20c_coins_amt" name="20c_coins_amt">
                                    </td>
                                    <td class="dollar_amount"></td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt_adjust num_validation_cls" name="20c_coins_qty_adjust" id="20c_coins_qty_adjust" data-dollar_price=".20" data-balance_qty="<?=(isset($cash_in_data['20c_coins_qty']) || isset($cash_out_data['20c_coins_qty']))?($cash_in_data['20c_coins_qty'] - $cash_out_data['20c_coins_qty']) : 0?>">
                                      <input type="hidden" id="20c_coins_amt_adjust" name="20c_coins_amt_adjust">
                                    </td>
                                    <td class="dollar_amount_adjust"></td>
                                    <td class="final_amount"></td>
                                </tr>
                                <tr>
                                    <td>50c Coins</td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt num_validation_cls" name="50c_coins_qty" id="50c_coins_qty" data-dollar_price=".50" data-balance_qty="<?=(isset($cash_in_data['50c_coins_qty']) || isset($cash_out_data['50c_coins_qty']))?($cash_in_data['50c_coins_qty'] - $cash_out_data['50c_coins_qty']) : 0?>">
                                      <input type="hidden" id="50c_coins_amt" name="50c_coins_amt">
                                    </td>
                                    <td class="dollar_amount"></td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt_adjust num_validation_cls" name="50c_coins_qty_adjust" id="50c_coins_qty_adjust" data-dollar_price=".50" data-balance_qty="<?=(isset($cash_in_data['50c_coins_qty']) || isset($cash_out_data['50c_coins_qty']))?($cash_in_data['50c_coins_qty'] - $cash_out_data['50c_coins_qty']) : 0?>">
                                      <input type="hidden" id="50c_coins_amt_adjust" name="50c_coins_amt_adjust">
                                    </td>
                                    <td class="dollar_amount_adjust"></td>
                                    <td class="final_amount"></td>
                                </tr>
                                <tr>
                                    <td>1$ Coins</td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt num_validation_cls" name="1d_coins_qty" id="1d_coins_qty" data-dollar_price="1" data-balance_qty="<?=(isset($cash_in_data['1d_coins_qty']) || isset($cash_out_data['1d_coins_qty']))?($cash_in_data['1d_coins_qty'] - $cash_out_data['1d_coins_qty']) : 0?>">
                                      <input type="hidden" id="1d_coins_amt" name="1d_coins_amt">
                                    </td>
                                    <td class="dollar_amount"></td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt_adjust num_validation_cls" name="1d_coins_qty_adjust" id="1d_coins_qty_adjust" data-dollar_price="1" data-balance_qty="<?=(isset($cash_in_data['1d_coins_qty']) || isset($cash_out_data['1d_coins_qty']))?($cash_in_data['1d_coins_qty'] - $cash_out_data['1d_coins_qty']) : 0?>">
                                      <input type="hidden" id="1d_coins_amt_adjust" name="1d_coins_amt_adjust">
                                    </td>
                                    <td class="dollar_amount_adjust"></td>
                                    <td class="final_amount"></td>
                                </tr>
                                <tr>
                                    <td>2$ Coins</td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt num_validation_cls" name="2d_coins_qty" id="2d_coins_qty" data-dollar_price="2" data-balance_qty="<?=(isset($cash_in_data['2d_coins_qty']) || isset($cash_out_data['2d_coins_qty']))?($cash_in_data['2d_coins_qty'] - $cash_out_data['2d_coins_qty']) : 0?>">
                                      <input type="hidden" id="2d_coins_amt" name="2d_coins_amt">
                                    </td>
                                    <td class="dollar_amount"></td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt_adjust num_validation_cls" name="2d_coins_qty_adjust" id="2d_coins_qty_adjust" data-dollar_price="2" data-balance_qty="<?=(isset($cash_in_data['2d_coins_qty']) || isset($cash_out_data['2d_coins_qty']))?($cash_in_data['2d_coins_qty'] - $cash_out_data['2d_coins_qty']) : 0?>">
                                      <input type="hidden" id="2d_coins_amt_adjust" name="2d_coins_amt_adjust">
                                    </td>
                                    <td class="dollar_amount_adjust"></td>
                                    <td class="final_amount"></td>
                                </tr>
                                <tr>
                                    <td>5$ Notes</td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt num_validation_cls" name="5d_notes_qty" id="5d_notes_qty" data-dollar_price="5" data-balance_qty="<?=(isset($cash_in_data['5d_notes_qty']) || isset($cash_out_data['5d_notes_qty']))?($cash_in_data['5d_notes_qty'] - $cash_out_data['5d_notes_qty']) : 0?>">
                                      <input type="hidden" id="5d_notes_amt" name="5d_notes_amt">
                                    </td>
                                    <td class="dollar_amount"></td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt_adjust num_validation_cls" name="5d_notes_qty_adjust" id="5d_notes_qty_adjust" data-dollar_price="5" data-balance_qty="<?=(isset($cash_in_data['5d_notes_qty']) || isset($cash_out_data['5d_notes_qty']))?($cash_in_data['5d_notes_qty'] - $cash_out_data['5d_notes_qty']) : 0?>">
                                      <input type="hidden" id="5d_notes_amt_adjust" name="5d_notes_amt_adjust">
                                    </td>
                                    <td class="dollar_amount_adjust"></td>
                                    <td class="final_amount"></td>
                                </tr>
                                <tr>
                                    <td>10$ Notes</td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt num_validation_cls" name="10d_notes_qty" id="10d_notes_qty" data-dollar_price="10" data-balance_qty="<?=(isset($cash_in_data['10d_notes_qty']) || isset($cash_out_data['10d_notes_qty']))?($cash_in_data['10d_notes_qty'] - $cash_out_data['10d_notes_qty']) : 0?>">
                                      <input type="hidden" id="10d_notes_amt" name="10d_notes_amt">
                                    </td>
                                    <td class="dollar_amount"></td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt_adjust num_validation_cls" name="10d_notes_qty_adjust" id="10d_notes_qty_adjust" data-dollar_price="10" data-balance_qty="<?=(isset($cash_in_data['10d_notes_qty']) || isset($cash_out_data['10d_notes_qty']))?($cash_in_data['10d_notes_qty'] - $cash_out_data['10d_notes_qty']) : 0?>">
                                      <input type="hidden" id="10d_notes_amt_adjust" name="10d_notes_amt_adjust">
                                    </td>
                                    <td class="dollar_amount_adjust"></td>
                                    <td class="final_amount"></td>
                                </tr>
                                <tr>
                                    <td>20$ Notes</td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt num_validation_cls" name="20d_notes_qty" id="20d_notes_qty" data-dollar_price="20" data-balance_qty="<?=(isset($cash_in_data['20d_notes_qty']) || isset($cash_out_data['20d_notes_qty']))?($cash_in_data['20d_notes_qty'] - $cash_out_data['20d_notes_qty']) : 0?>">
                                      <input type="hidden" id="20d_notes_amt" name="20d_notes_amt">
                                    </td>
                                    <td class="dollar_amount"></td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt_adjust num_validation_cls" name="20d_notes_qty_adjust" id="20d_notes_qty_adjust" data-dollar_price="20" data-balance_qty="<?=(isset($cash_in_data['20d_notes_qty']) || isset($cash_out_data['20d_notes_qty']))?($cash_in_data['20d_notes_qty'] - $cash_out_data['20d_notes_qty']) : 0?>">
                                      <input type="hidden" id="20d_notes_amt_adjust" name="20d_notes_amt_adjust">
                                    </td>

                                    <td class="dollar_amount_adjust"></td>
                                    <td class="final_amount"></td>
                                </tr>
                                <tr>
                                    <td>50$ Notes</td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt num_validation_cls" name="50d_notes_qty" id="50d_notes_qty" data-dollar_price="50" data-balance_qty="<?=(isset($cash_in_data['50d_notes_qty']) || isset($cash_out_data['50d_notes_qty']))?($cash_in_data['50d_notes_qty'] - $cash_out_data['50d_notes_qty']) : 0?>">
                                      <input type="hidden" id="50d_notes_amt" name="50d_notes_amt">
                                    </td>
                                    <td class="dollar_amount"></td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt_adjust num_validation_cls" name="50d_notes_qty_adjust" id="50d_notes_qty_adjust" data-dollar_price="50" data-balance_qty="<?=(isset($cash_in_data['50d_notes_qty']) || isset($cash_out_data['50d_notes_qty']))?($cash_in_data['50d_notes_qty'] - $cash_out_data['50d_notes_qty']) : 0?>">
                                      <input type="hidden" id="50d_notes_amt_adjust" name="50d_notes_amt_adjust">
                                    </td>
                                    <td class="dollar_amount_adjust"></td>
                                    <td class="final_amount"></td>
                                </tr>
                                <tr>
                                    <td>100$ Notes</td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt num_validation_cls" name="100d_notes_qty" id="100d_notes_qty" data-dollar_price="100" data-balance_qty="<?=(isset($cash_in_data['100d_notes_qty']) || isset($cash_out_data['100d_notes_qty']))?($cash_in_data['100d_notes_qty'] - $cash_out_data['100d_notes_qty']) : 0?>">
                                      <input type="hidden" id="100d_notes_amt" name="100d_notes_amt">
                                    </td>
                                    <td class="dollar_amount"></td>
                                    <td>
                                      <input type="text" class="form-control calculate_amt_adjust num_validation_cls" name="100d_notes_qty_adjust" id="100d_notes_qty_adjust" data-dollar_price="100" data-balance_qty="<?=(isset($cash_in_data['100d_notes_qty']) || isset($cash_out_data['100d_notes_qty']))?($cash_in_data['100d_notes_qty'] - $cash_out_data['100d_notes_qty']) : 0?>">
                                      <input type="hidden" id="100d_notes_amt_adjust" name="100d_notes_amt_adjust">
                                    </td>
                                    <td class="dollar_amount_adjust"></td>
                                    <td class="final_amount"></td>
                                </tr>
                              </tbody>
                              <tfoot>
                                <tr>
                                  <td colspan="2" style="text-align:left;"><strong>TOTAL</strong></td>
                                  <td><strong class="total_amount"></strong></td>
                                  <td colspan="2"><strong class="total_amount_adjust"></strong></td>
                                  <td><strong class="total_final_amount"></strong></td>

                                  <input type="hidden" id="total_amount_cash" name="total_amount_cash">
                                  <input type="hidden" id="total_amount" name="total_amount">
                                  <input type="hidden" id="total_amount_adjust" name="total_amount_adjust">
                                </tr>
                              </tfoot>
                            </table>
                          </div>
                        </div>
                      </div>

                          <!--  END -->

                        </div>
                        


                      </div>
                    </div>
                </div>
                <div class="form-actions">
                  <input type="hidden" id="driver_id" value="<?php if (!empty($driver_settlement_data)) : echo $driver_settlement_data['driver_id'];
                                                              endif; ?>">
                  <input type="hidden" id="shift_id" value="<?php if (!empty($driver_settlement_data)) : echo $driver_settlement_data['shift_id'];
                                                            endif; ?>">
                  <input type="hidden" id="payin_id" value="<?php if (!empty($driver_settlement_data)) : echo $driver_settlement_data['payin_id'];
                                                            endif; ?>">
                  
                  <div class="form-actions" style="text-align:center;">
                  <a class="btn btn-danger mr-1" href="<?= (!empty($driver_settlement_data) && $driver_settlement_data['bulk_settlement_flag'] == 0)? base_url('admin/driver-settlement/list'): base_url('admin/DriverSettlement/bulk_settlement_list') ?>">
                    <i class="fa fa-times" aria-hidden="true"></i> Cancel
                  </a>
                 
                  <button type="button" id="submit_driver_settlement" class="btn btn-success">
                    <!-- style="display:none>-->
                    <i class="fa fa-floppy-o" aria-hidden="true"></i> Submit
                  </button>
                  
                      </div> 
                  
                  
                  
                </div>
                </form>
              </div>
            </div>
          </div>
        </div>
    </div>
    </section>
    <!-- // Basic form layout section end -->
  </div>
</div>
</div>

<script>
  
  $(document).ready(function() {
    $(".js-select2").select2();    
  })
  $(document).on('change','#driver_list',function(){

    var image_link = $(this).find(":selected").data('image_link');
    //alert(image_link);
      $(".ds_settelement_img").show();
      $("#driver_image_link_a").attr('href',image_link);
      $("#driver_image_link_img").attr('src',image_link);
      
      
      var driver_id   = $(this).val();
      $.ajax({
          type: "POST",
          url: '<?php echo base_url('admin/DriverSettlement/ajaxDriverShiftDetails')?>',
          data:{driver_id : driver_id},
          dataType:'JSON',
          success: function(response){
            //console.log(response);
            if(response['html'] !=''){
              $("#drive_data_div").html(response['html']);
            }
            if(response['html'] !='1'){
              $("#driver_settlement_div").html('');
            }          
          },
          error:function(response){          
              $.alert({
               type: 'red',
               title: 'Alert!',
               content: 'error',
            });
          }
      });
  });
  $(document).on('click','.driver_shift',function(){
      var shift_id   = $(this).attr('id');
      var driver_id  = $('#driver_list').val();
      var dr_settlement_id = $(this).data('dr_settlement_id');
      $.ajax({
          type: "POST",
          url: '<?php echo base_url('admin/DriverSettlement/ajaxDriverSettlement')?>',
          data:{shift_id : shift_id,driver_id:driver_id,dr_settlement_id:dr_settlement_id},
          dataType:'json',
          success: function(response){
          	//alert(response);
            if(response['html'] !=''){
              $("#driver_settlement_div").html(response['html']);
              $("#settlement_submit_btn").show();
            }                        
          },
          error:function(response){
              $.alert({
                 type: 'red',
                 title: 'Alert!',
                 content: 'error',
              });
          }
      });
  });

  
  $(document).on('click','.total_extra_save',function(){
    if($(this).is(':checked')){
      var payin_id        = $(this).attr('rel');
      var driver_id		  = $("#driver_id").val();
	    var shift_id		  = $("#shift_id").val();

      var rental_hidden_val = $("#rental_hidden").val();

      var other_rental                 = Number($("#other_rental").val());
      var bond_total_rental            = Number($("#bond_total_rental").val());
      var accident_installment_rental  = Number($("#accident_installment_rental").val());
      var discount_rental              = Number($("#discount_rental").val());
      var amount_paid_rental           = Number($("#amount_paid_rental").val());

      var other_com                 =  Number($("#other").val());
      var bond_total_com            =  Number($("#bond_total").val());
      var accident_installment_com  =  Number($("#accident_installment").val());
      var discount_com              =  Number($("#discount").val());
      var amount_paid_com           =  Number($("#amount_paid").val());
      
      other_com = isNaN(other_com)?0:other_com;
      bond_total_com = isNaN(bond_total_com)?0:bond_total_com;
      accident_installment_com = isNaN(accident_installment_com)?0:accident_installment_com;
      discount_com = isNaN(discount_com)?0:discount_com;
      amount_paid_com = isNaN(amount_paid_com)?0:amount_paid_com;

      other_rental = isNaN(other_rental)?0:other_rental;
      bond_total_rental = isNaN(bond_total_rental)?0:bond_total_rental;
      accident_installment_rental = isNaN(accident_installment_rental)?0:accident_installment_rental;
      discount_rental = isNaN(discount_rental)?0:discount_rental;
      amount_paid_rental = isNaN(amount_paid_rental)?0:amount_paid_rental;

      var no_of_whl_rental             = Number($("#no_of_whl_rental").val());
      var no_of_whl_com                 = Number($("#no_of_whl").val());
      no_of_whl_com = isNaN(no_of_whl_com)?0:no_of_whl_com;
      no_of_whl_rental = isNaN(no_of_whl_rental)?0:no_of_whl_rental;


      var total_ext_start = $('.total_extra_tr > td:nth-of-type(1) > input:nth-of-type(1)').val();      
      var total_ext_end   = $('.total_extra_tr > td:nth-of-type(3) > input:nth-of-type(1)').val();
      //alert(total_ext_start);
      if(parseFloat(total_ext_end) < parseFloat(total_ext_start)){       
          //$('.total_extra_tr > td:nth-of-type(3) > input:nth-of-type(1)').css('border-color', 'red');
          $.alert({
               type: 'red',
               title: 'Alert!',
               content: 'Total + Extra Finish Reading Should Be Greater Than Start Reading',
          });

          return false;       
      } else{
          
          $.ajax({
            type: "POST",
            url: '<?php echo base_url('admin/DriverSettlement/saveDriverSettlement')?>',
            data:{payin_id:payin_id,start_value:total_ext_start,end_value:total_ext_end,start_colmn:'total_extra_start',end_colmn:'total_extra_end',driver_id:driver_id,shift_id:shift_id,
            discount_com:discount_com,other_com:other_com,bond_total_com:bond_total_com,accident_installment_com:accident_installment_com,amount_paid_com:amount_paid_com,
            discount_rental:discount_rental,other_rental:other_rental,bond_total_rental:bond_total_rental,accident_installment_rental:accident_installment_rental,amount_paid_rental:amount_paid_rental,
            rental_commission:(rental_hidden_val > 0)?'R':'C',flag:1,rental_hidden_val:rental_hidden_val,no_of_whl_com:no_of_whl_com,no_of_whl_rental:no_of_whl_rental},
            dataType:'JSON',
            global: false,
            success: function(response){
              if(response['process'] =='success'){
                //alert("Successfully updated.");
                $("#total_extra_start_div").html(total_ext_start);
                $("#total_extra_end_div").html(total_ext_end); 
                $(".total_extra_div").show();
                $(".total_extra_input").hide();
              }else{               
                $.alert({
                   type: 'red',
                   title: 'Alert!',
                   content: 'Some problem occured.Please try again.',
                });
              }
              
        //--------------------------------Commission Based--------------------------//
        $("#total_dockets").val(response['total_settlement']['total_dockets']);
        $("#total_expense").val(response['total_settlement']['total_expense']);
        $("#levy_total").val(response['total_settlement']['levy_total']);
        $("#no_of_whl").val(response['total_settlement']['no_of_whl_com']);
        $("#accident_installment").val(response['total_settlement']['accident_installment_com']);
        $("#bond_total").val(response['total_settlement']['bond_total_com']);
        $("#other").val(response['total_settlement']['other_com']);
        $("#amount_due").val(response['total_settlement']['amount_due_com']);
        $("#discount").val(response['total_settlement']['discount_com']);
        $("#total").val(response['total_settlement']['total_com']);
        
        //--------------------------------Rental Based--------------------------//
        $("#total_dockets_rental").val(response['total_settlement']['total_dockets']);
        $("#total_expense_rental").val(response['total_settlement']['total_expense']);
        $("#levy_total_rental").val(response['total_settlement']['levy_total']);
        $("#no_of_whl_rental").val(response['total_settlement']['no_of_whl_rental']);
        $("#accident_installment_rental").val(response['total_settlement']['accident_installment_rental']);
        $("#bond_total_rental").val(response['total_settlement']['bond_total_rental']);
        $("#other_rental").val(response['total_settlement']['other_rental']);
        $("#amount_due_rental").val(response['total_settlement']['amount_due_rental']);
        $("#discount_rental").val(response['total_settlement']['discount_rental']);
        $("#total_rental").val(response['total_settlement']['total_rental']);
        
        if(!(Number($("#rental_hidden").val()))){
            $("#amount_due_rental").val('0.00');
        }
        if(!(Number($("#rental_hidden").val()))){
            $("#payment_collection_div").text(($("#amount_due").val() < 0)?'Payment Mode':'Payment Collection Mode');
            $("#final_due_amount").text($("#amount_due").val());
            $("#final_due_amount_hid").val($("#amount_due").val());
        }else{
            $("#payment_collection_div").text(($("#amount_due_rental").val() < 0)?'Payment Mode':'Payment Collection Mode');
            $("#final_due_amount").text($("#amount_due_rental").val());
            $("#final_due_amount_hid").val($("#amount_due_rental").val());
        }
              
            },
            error:function(response){
              $.alert({
                   type: 'red',
                   title: 'Alert!',
                   content: 'Error',
              });
            }
          });
      }
    } else{

      $(".total_extra_input").show();
      $(".total_extra_div").hide();
    }
  });
  $(document).on('click','.paid_km_save',function(){
    if($(this).is(':checked')){
      var payin_id      = $(this).attr('rel');
      var driver_id		= $("#driver_id").val();
	    var shift_id		= $("#shift_id").val();

      var rental_hidden_val = $("#rental_hidden").val();

      var other_rental                 = Number($("#other_rental").val());
      var bond_total_rental            = Number($("#bond_total_rental").val());
      var accident_installment_rental  = Number($("#accident_installment_rental").val());
      var discount_rental              = Number($("#discount_rental").val());
      var amount_paid_rental           = Number($("#amount_paid_rental").val());

      var other_com                 =  Number($("#other").val());
      var bond_total_com            =  Number($("#bond_total").val());
      var accident_installment_com  =  Number($("#accident_installment").val());
      var discount_com              =  Number($("#discount").val());
      var amount_paid_com           =  Number($("#amount_paid").val());
      
      other_com = isNaN(other_com)?0:other_com;
      bond_total_com = isNaN(bond_total_com)?0:bond_total_com;
      accident_installment_com = isNaN(accident_installment_com)?0:accident_installment_com;
      discount_com = isNaN(discount_com)?0:discount_com;
      amount_paid_com = isNaN(amount_paid_com)?0:amount_paid_com;

      other_rental = isNaN(other_rental)?0:other_rental;
      bond_total_rental = isNaN(bond_total_rental)?0:bond_total_rental;
      accident_installment_rental = isNaN(accident_installment_rental)?0:accident_installment_rental;
      discount_rental = isNaN(discount_rental)?0:discount_rental;
      amount_paid_rental = isNaN(amount_paid_rental)?0:amount_paid_rental;

      var no_of_whl_rental             = Number($("#no_of_whl_rental").val());
      var no_of_whl_com                 = Number($("#no_of_whl").val());

      no_of_whl_com = isNaN(no_of_whl_com)?0:no_of_whl_com;

      no_of_whl_rental = isNaN(no_of_whl_rental)?0:no_of_whl_rental;

      var paid_km_start = $('.paid_km_tr > td:nth-of-type(1) > input:nth-of-type(1)').val();      
      var paid_km_end   = $('.paid_km_tr > td:nth-of-type(3) > input:nth-of-type(1)').val();
      if(parseFloat(paid_km_end) < parseFloat(paid_km_start)){
          //$('.paid_km_tr > td:nth-of-type(3) > input:nth-of-type(1)').css('border-color', 'red');            
          $.alert({
             type: 'red',
             title: 'Alert!',
             content: 'Paid km Finish Reading Should Be Greater Than Start Reading',
          });
          return false;     
      }
      else{
          $.ajax({
            type: "POST",
            url: '<?php echo base_url('admin/DriverSettlement/saveDriverSettlement')?>',
            data:{payin_id:payin_id,start_value:paid_km_start,end_value:paid_km_end,start_colmn:'paid_km_start',end_colmn:'paid_km_end',driver_id:driver_id,shift_id:shift_id,
              discount_com:discount_com,other_com:other_com,bond_total_com:bond_total_com,accident_installment_com:accident_installment_com,amount_paid_com:amount_paid_com,
            discount_rental:discount_rental,other_rental:other_rental,bond_total_rental:bond_total_rental,accident_installment_rental:accident_installment_rental,amount_paid_rental:amount_paid_rental,
            rental_commission:(rental_hidden_val > 0)?'R':'C',flag:1,rental_hidden_val:rental_hidden_val,no_of_whl_com:no_of_whl_com,no_of_whl_rental:no_of_whl_rental
},
            dataType:'JSON',
            global: false,
            success: function(response){
              if(response['process'] =='success'){
                //alert("Successfully updated.");
                $("#paid_km_start_div").html(paid_km_start);
                $("#paid_km_end_div").html(paid_km_end); 
                $(".paid_km_div").show();
                $(".paid_km_input").hide(); 
                
              }
              else{
                $.alert({
                   type: 'red',
                   title: 'Alert!',
                   content: 'Some problem occure.Please try again.',
                });
              }
              
              
              
             
        //--------------------------------Commission Based--------------------------//
        $("#total_dockets").val(response['total_settlement']['total_dockets']);
        $("#total_expense").val(response['total_settlement']['total_expense']);
        $("#levy_total").val(response['total_settlement']['levy_total']);
        $("#no_of_whl").val(response['total_settlement']['no_of_whl_com']);
        $("#accident_installment").val(response['total_settlement']['accident_installment_com']);
        $("#bond_total").val(response['total_settlement']['bond_total_com']);
        $("#other").val(response['total_settlement']['other_com']);
        $("#amount_due").val(response['total_settlement']['amount_due_com']);
        $("#discount").val(response['total_settlement']['discount_com']);
        $("#total").val(response['total_settlement']['total_com']);
        
        //--------------------------------Rental Based--------------------------//
        $("#total_dockets_rental").val(response['total_settlement']['total_dockets']);
        $("#total_expense_rental").val(response['total_settlement']['total_expense']);
        $("#levy_total_rental").val(response['total_settlement']['levy_total']);
        $("#no_of_whl_rental").val(response['total_settlement']['no_of_whl_rental']);
        $("#accident_installment_rental").val(response['total_settlement']['accident_installment_rental']);
        $("#bond_total_rental").val(response['total_settlement']['bond_total_rental']);
        $("#other_rental").val(response['total_settlement']['other_rental']);
        $("#amount_due_rental").val(response['total_settlement']['amount_due_rental']);
        $("#discount_rental").val(response['total_settlement']['discount_rental']);
        $("#total_rental").val(response['total_settlement']['total_rental']);
        
        if(!(Number($("#rental_hidden").val()))){
            $("#amount_due_rental").val('0.00');
        }
        if(!(Number($("#rental_hidden").val()))){
            $("#payment_collection_div").text(($("#amount_due").val() < 0)?'Payment Mode':'Payment Collection Mode');
            $("#final_due_amount").text($("#amount_due").val());
            $("#final_due_amount_hid").val($("#amount_due").val());
        }else{
            $("#payment_collection_div").text(($("#amount_due_rental").val() < 0)?'Payment Mode':'Payment Collection Mode');
            $("#final_due_amount").text($("#amount_due_rental").val());
            $("#final_due_amount_hid").val($("#amount_due_rental").val());
        }
              
            },
            error:function(response){
               $.alert({
                   type: 'red',
                   title: 'Alert!',
                   content: 'Error',
                });
            }
          });
      }
    }else{

$(".paid_km_input").show();
$(".paid_km_div").hide();
}
  });
  $(document).on('click','.total_km_save',function(){
    if($(this).is(':checked')){
      var payin_id        = $(this).attr('rel');
      var driver_id		  = $("#driver_id").val();
	    var shift_id		  = $("#shift_id").val();

      var rental_hidden_val = $("#rental_hidden").val();

      var other_rental                 = Number($("#other_rental").val());
      var bond_total_rental            = Number($("#bond_total_rental").val());
      var accident_installment_rental  = Number($("#accident_installment_rental").val());
      var discount_rental              = Number($("#discount_rental").val());
      var amount_paid_rental           = Number($("#amount_paid_rental").val());

      var other_com                 =  Number($("#other").val());
      var bond_total_com            =  Number($("#bond_total").val());
      var accident_installment_com  =  Number($("#accident_installment").val());
      var discount_com              =  Number($("#discount").val());
      var amount_paid_com           =  Number($("#amount_paid").val());
      
      other_com = isNaN(other_com)?0:other_com;
      bond_total_com = isNaN(bond_total_com)?0:bond_total_com;
      accident_installment_com = isNaN(accident_installment_com)?0:accident_installment_com;
      discount_com = isNaN(discount_com)?0:discount_com;
      amount_paid_com = isNaN(amount_paid_com)?0:amount_paid_com;

      other_rental = isNaN(other_rental)?0:other_rental;
      bond_total_rental = isNaN(bond_total_rental)?0:bond_total_rental;
      accident_installment_rental = isNaN(accident_installment_rental)?0:accident_installment_rental;
      discount_rental = isNaN(discount_rental)?0:discount_rental;
      amount_paid_rental = isNaN(amount_paid_rental)?0:amount_paid_rental;

      var no_of_whl_rental             = Number($("#no_of_whl_rental").val());
      var no_of_whl_com                 = Number($("#no_of_whl").val());

      no_of_whl_com = isNaN(no_of_whl_com)?0:no_of_whl_com;

      no_of_whl_rental = isNaN(no_of_whl_rental)?0:no_of_whl_rental;


      var total_km_start  = $('.total_km_tr > td:nth-of-type(1) > input:nth-of-type(1)').val();      
      var total_km_end    = $('.total_km_tr > td:nth-of-type(3) > input:nth-of-type(1)').val();
      if(parseFloat(total_km_end) < parseFloat(total_km_start)){
          //$('.total_km_tr > td:nth-of-type(3) > input:nth-of-type(1)').css('border-color', 'red'); 
          $.alert({
             type: 'red',
             title: 'Alert!',
             content: 'Total km Finish Reading Should Be Greater Than Start Reading.',
          });
          return false;   
      }
      else{
          $.ajax({
            type: "POST",
            url: '<?php echo base_url('admin/DriverSettlement/saveDriverSettlement')?>',
            data:{payin_id:payin_id,start_value:total_km_start,end_value:total_km_end,start_colmn:'total_km_start',end_colmn:'total_km_end',driver_id:driver_id,shift_id:shift_id,discount_com:discount_com,other_com:other_com,bond_total_com:bond_total_com,accident_installment_com:accident_installment_com,amount_paid_com:amount_paid_com,
            discount_rental:discount_rental,other_rental:other_rental,bond_total_rental:bond_total_rental,accident_installment_rental:accident_installment_rental,amount_paid_rental:amount_paid_rental,rental_commission:(rental_hidden_val > 0)?'R':'C',flag:1,rental_hidden_val:rental_hidden_val,no_of_whl_com:no_of_whl_com,no_of_whl_rental:no_of_whl_rental
},
            dataType:'JSON',
            global: false,
            success: function(response){
              if(response['process'] =='success'){
                //alert("Successfully updated.");
                $("#total_km_start_div").html(total_km_start);
                $("#total_km_end_div").html(total_km_end); 
                $(".total_km_div").show();
                $(".total_km_input").hide();
                
              }
              else{
                $.alert({
                   type: 'red',
                   title: 'Alert!',
                   content: 'Some problem occure.Please try again.',
                });
              }
              
              
              
              //--------------------------------Commission Based--------------------------//
        $("#total_dockets").val(response['total_settlement']['total_dockets']);
        $("#total_expense").val(response['total_settlement']['total_expense']);
        $("#levy_total").val(response['total_settlement']['levy_total']);
        $("#no_of_whl").val(response['total_settlement']['no_of_whl_com']);
        $("#accident_installment").val(response['total_settlement']['accident_installment_com']);
        $("#bond_total").val(response['total_settlement']['bond_total_com']);
        $("#other").val(response['total_settlement']['other_com']);
        $("#amount_due").val(response['total_settlement']['amount_due_com']);
        $("#discount").val(response['total_settlement']['discount_com']);
        $("#total").val(response['total_settlement']['total_com']);
        
        //--------------------------------Rental Based--------------------------//
        $("#total_dockets_rental").val(response['total_settlement']['total_dockets']);
        $("#total_expense_rental").val(response['total_settlement']['total_expense']);
        $("#levy_total_rental").val(response['total_settlement']['levy_total']);
        $("#no_of_whl_rental").val(response['total_settlement']['no_of_whl_rental']);
        $("#accident_installment_rental").val(response['total_settlement']['accident_installment_rental']);
        $("#bond_total_rental").val(response['total_settlement']['bond_total_rental']);
        $("#other_rental").val(response['total_settlement']['other_rental']);
        $("#amount_due_rental").val(response['total_settlement']['amount_due_rental']);
        $("#discount_rental").val(response['total_settlement']['discount_rental']);
        $("#total_rental").val(response['total_settlement']['total_rental']);
        
        if(!(Number($("#rental_hidden").val()))){
            $("#amount_due_rental").val('0.00');
        }
        if(!(Number($("#rental_hidden").val()))){
            $("#payment_collection_div").text(($("#amount_due").val() < 0)?'Payment Mode':'Payment Collection Mode');
            $("#final_due_amount").text($("#amount_due").val());
            $("#final_due_amount_hid").val($("#amount_due").val());
        }else{
            $("#payment_collection_div").text(($("#amount_due_rental").val() < 0)?'Payment Mode':'Payment Collection Mode');
            $("#final_due_amount").text($("#amount_due_rental").val());
            $("#final_due_amount_hid").val($("#amount_due_rental").val());
        }
              
            },
            error:function(response){
               $.alert({
                   type: 'red',
                   title: 'Alert!',
                   content: 'Error',
                });
            }
          });
      }
      }else{

    $(".total_km_input").show();
    $(".total_km_div").hide();
    }
  });
  $(document).on('click','.extra_save',function(){
    if($(this).is(':checked')){
      var payin_id        = $(this).attr('rel');
      var driver_id		  = $("#driver_id").val();
	    var shift_id		  = $("#shift_id").val();

      var rental_hidden_val = $("#rental_hidden").val();

      var other_rental                 = Number($("#other_rental").val());
      var bond_total_rental            = Number($("#bond_total_rental").val());
      var accident_installment_rental  = Number($("#accident_installment_rental").val());
      var discount_rental              = Number($("#discount_rental").val());
      var amount_paid_rental           = Number($("#amount_paid_rental").val());

      var other_com                 =  Number($("#other").val());
      var bond_total_com            =  Number($("#bond_total").val());
      var accident_installment_com  =  Number($("#accident_installment").val());
      var discount_com              =  Number($("#discount").val());
      var amount_paid_com           =  Number($("#amount_paid").val());
      
      other_com = isNaN(other_com)?0:other_com;
      bond_total_com = isNaN(bond_total_com)?0:bond_total_com;
      accident_installment_com = isNaN(accident_installment_com)?0:accident_installment_com;
      discount_com = isNaN(discount_com)?0:discount_com;
      amount_paid_com = isNaN(amount_paid_com)?0:amount_paid_com;

      other_rental = isNaN(other_rental)?0:other_rental;
      bond_total_rental = isNaN(bond_total_rental)?0:bond_total_rental;
      accident_installment_rental = isNaN(accident_installment_rental)?0:accident_installment_rental;
      discount_rental = isNaN(discount_rental)?0:discount_rental;
      amount_paid_rental = isNaN(amount_paid_rental)?0:amount_paid_rental;

      var no_of_whl_rental             = Number($("#no_of_whl_rental").val());
      var no_of_whl_com                 = Number($("#no_of_whl").val());

      no_of_whl_com = isNaN(no_of_whl_com)?0:no_of_whl_com;

      no_of_whl_rental = isNaN(no_of_whl_rental)?0:no_of_whl_rental;


      var extra_start     = $('.extra_tr > td:nth-of-type(1) > input:nth-of-type(1)').val();      
      var extra_end       = $('.extra_tr > td:nth-of-type(3) > input:nth-of-type(1)').val();
      //alert(extra_start);alert(extra_end);
      if(parseFloat(extra_end) < parseFloat(extra_start)){
          //$('.extra_tr > td:nth-of-type(3) > input:nth-of-type(1)').css('border-color', 'red'); 
          $.alert({
             type: 'red',
             title: 'Alert!',
             content: 'Extra Finish Reading Should Be Greater Than Start Reading.',
          });
          return false;       
      }
      else{
          $.ajax({
            type: "POST",
            url: '<?php echo base_url('admin/DriverSettlement/saveDriverSettlement')?>',
            data:{payin_id:payin_id,start_value:extra_start,end_value:extra_end,start_colmn:'extra_start',end_colmn:'extra_end',driver_id:driver_id,shift_id:shift_id,discount_com:discount_com,other_com:other_com,bond_total_com:bond_total_com,accident_installment_com:accident_installment_com,amount_paid_com:amount_paid_com,
            discount_rental:discount_rental,other_rental:other_rental,bond_total_rental:bond_total_rental,accident_installment_rental:accident_installment_rental,amount_paid_rental:amount_paid_rental,rental_commission:(rental_hidden_val > 0)?'R':'C',flag:1,rental_hidden_val:rental_hidden_val,no_of_whl_com:no_of_whl_com,no_of_whl_rental:no_of_whl_rental},
            dataType:'JSON',
            global: false,
            success: function(response){
              if(response['process'] =='success'){
                //alert("Successfully updated.");
                $("#extra_start_div").html(extra_start);
                $("#extra_end_div").html(extra_end); 
                $(".extra_div").show();
                $(".extra_input").hide();
                
              }
              else{
                $.alert({
                   type: 'red',
                   title: 'Alert!',
                   content: 'Some problem occure.Please try again.',
                });
              }
              
              
              
              //--------------------------------Commission Based--------------------------//
        $("#total_dockets").val(response['total_settlement']['total_dockets']);
        $("#total_expense").val(response['total_settlement']['total_expense']);
        $("#levy_total").val(response['total_settlement']['levy_total']);
        $("#no_of_whl").val(response['total_settlement']['no_of_whl_com']);
        $("#accident_installment").val(response['total_settlement']['accident_installment_com']);
        $("#bond_total").val(response['total_settlement']['bond_total_com']);
        $("#other").val(response['total_settlement']['other_com']);
        $("#amount_due").val(response['total_settlement']['amount_due_com']);
        $("#discount").val(response['total_settlement']['discount_com']);
        $("#total").val(response['total_settlement']['total_com']);
        
        //--------------------------------Rental Based--------------------------//
        $("#total_dockets_rental").val(response['total_settlement']['total_dockets']);
        $("#total_expense_rental").val(response['total_settlement']['total_expense']);
        $("#levy_total_rental").val(response['total_settlement']['levy_total']);
        $("#no_of_whl_rental").val(response['total_settlement']['no_of_whl_rental']);
        $("#accident_installment_rental").val(response['total_settlement']['accident_installment_rental']);
        $("#bond_total_rental").val(response['total_settlement']['bond_total_rental']);
        $("#other_rental").val(response['total_settlement']['other_rental']);
        $("#amount_due_rental").val(response['total_settlement']['amount_due_rental']);
        $("#discount_rental").val(response['total_settlement']['discount_rental']);
        $("#total_rental").val(response['total_settlement']['total_rental']);
        
        if(!(Number($("#rental_hidden").val()))){
            $("#amount_due_rental").val('0.00');
        }
        if(!(Number($("#rental_hidden").val()))){
            $("#payment_collection_div").text(($("#amount_due").val() < 0)?'Payment Mode':'Payment Collection Mode');
            $("#final_due_amount").text($("#amount_due").val());
            $("#final_due_amount_hid").val($("#amount_due").val());
        }else{
            $("#payment_collection_div").text(($("#amount_due_rental").val() < 0)?'Payment Mode':'Payment Collection Mode');
            $("#final_due_amount").text($("#amount_due_rental").val());
            $("#final_due_amount_hid").val($("#amount_due_rental").val());
        }
              
            },
            error:function(response){
               $.alert({
                   type: 'red',
                   title: 'Alert!',
                   content: 'Error',
                });
            }
          });
      }
      }else{

        $(".extra_div").hide();
                $(".extra_input").show();
}
  });
  $(document).on('click','.no_of_hiring_save',function(){
    if($(this).is(':checked')){
      var payin_id                = $(this).attr('rel');
      var driver_id		  = $("#driver_id").val();
	    var shift_id		  = $("#shift_id").val();

      var rental_hidden_val = $("#rental_hidden").val();

      var other_rental                 = Number($("#other_rental").val());
      var bond_total_rental            = Number($("#bond_total_rental").val());
      var accident_installment_rental  = Number($("#accident_installment_rental").val());
      var discount_rental              = Number($("#discount_rental").val());
      var amount_paid_rental           = Number($("#amount_paid_rental").val());

      var other_com                 =  Number($("#other").val());
      var bond_total_com            =  Number($("#bond_total").val());
      var accident_installment_com  =  Number($("#accident_installment").val());
      var discount_com              =  Number($("#discount").val());
      var amount_paid_com           =  Number($("#amount_paid").val());
      
      other_com = isNaN(other_com)?0:other_com;
      bond_total_com = isNaN(bond_total_com)?0:bond_total_com;
      accident_installment_com = isNaN(accident_installment_com)?0:accident_installment_com;
      discount_com = isNaN(discount_com)?0:discount_com;
      amount_paid_com = isNaN(amount_paid_com)?0:amount_paid_com;

      other_rental = isNaN(other_rental)?0:other_rental;
      bond_total_rental = isNaN(bond_total_rental)?0:bond_total_rental;
      accident_installment_rental = isNaN(accident_installment_rental)?0:accident_installment_rental;
      discount_rental = isNaN(discount_rental)?0:discount_rental;
      amount_paid_rental = isNaN(amount_paid_rental)?0:amount_paid_rental;

      var no_of_whl_rental             = Number($("#no_of_whl_rental").val());
      var no_of_whl_com                 = Number($("#no_of_whl").val());

      no_of_whl_com = isNaN(no_of_whl_com)?0:no_of_whl_com;

      no_of_whl_rental = isNaN(no_of_whl_rental)?0:no_of_whl_rental;


      var no_of_hiring_start      = $('.no_of_hiring_tr > td:nth-of-type(1) > input:nth-of-type(1)').val();      
      var no_of_hiring_end        = $('.no_of_hiring_tr > td:nth-of-type(3) > input:nth-of-type(1)').val();
      if(parseFloat(no_of_hiring_end) < parseFloat(no_of_hiring_start)){
          //$('.no_of_hiring_tr > td:nth-of-type(3) > input:nth-of-type(1)').css('border-color', 'red');           
           $.alert({
               type: 'red',
               title: 'Alert!',
               content: 'No of Hiring Finish Reading Should Be Greater Than Start Reading.',
            });

          return false;   
      }
      else{
          $.ajax({
            type: "POST",
            url: '<?php echo base_url('admin/DriverSettlement/saveDriverSettlement')?>',
            data:{payin_id:payin_id,start_value:no_of_hiring_start,end_value:no_of_hiring_end,start_colmn:'no_of_hiring_start',end_colmn:'no_of_hiring_end',driver_id:driver_id,shift_id:shift_id,discount_com:discount_com,other_com:other_com,bond_total_com:bond_total_com,accident_installment_com:accident_installment_com,amount_paid_com:amount_paid_com,
            discount_rental:discount_rental,other_rental:other_rental,bond_total_rental:bond_total_rental,accident_installment_rental:accident_installment_rental,amount_paid_rental:amount_paid_rental,rental_commission:(rental_hidden_val > 0)?'R':'C',flag:1,rental_hidden_val:rental_hidden_val,no_of_whl_com:no_of_whl_com,no_of_whl_rental:no_of_whl_rental},
            dataType:'JSON',
            global: false,
            success: function(response){
				if(response['process'] =='success'){
					//alert("Successfully updated.");
					$("#no_of_hiring_start_div").html(no_of_hiring_start);
					$("#no_of_hiring_end_div").html(no_of_hiring_end); 
					$(".no_of_hiring_div").show();
					$(".no_of_hiring_input").hide();
				
				}
				else{
          $.alert({
               type: 'red',
               title: 'Alert!',
               content: 'Some problem occured.Please try again.',
            });
				}
        
              
              
        //--------------------------------Commission Based--------------------------//
        $("#total_dockets").val(response['total_settlement']['total_dockets']);
        $("#total_expense").val(response['total_settlement']['total_expense']);
        $("#levy_total").val(response['total_settlement']['levy_total']);
        $("#no_of_whl").val(response['total_settlement']['no_of_whl_com']);
        $("#accident_installment").val(response['total_settlement']['accident_installment_com']);
        $("#bond_total").val(response['total_settlement']['bond_total_com']);
        $("#other").val(response['total_settlement']['other_com']);
        $("#amount_due").val(response['total_settlement']['amount_due_com']);
        $("#discount").val(response['total_settlement']['discount_com']);
        $("#total").val(response['total_settlement']['total_com']);
        
        //--------------------------------Rental Based--------------------------//
        $("#total_dockets_rental").val(response['total_settlement']['total_dockets']);
        $("#total_expense_rental").val(response['total_settlement']['total_expense']);
        $("#levy_total_rental").val(response['total_settlement']['levy_total']);
        $("#no_of_whl_rental").val(response['total_settlement']['no_of_whl_rental']);
        $("#accident_installment_rental").val(response['total_settlement']['accident_installment_rental']);
        $("#bond_total_rental").val(response['total_settlement']['bond_total_rental']);
        $("#other_rental").val(response['total_settlement']['other_rental']);
        $("#amount_due_rental").val(response['total_settlement']['amount_due_rental']);
        $("#discount_rental").val(response['total_settlement']['discount_rental']);
        $("#total_rental").val(response['total_settlement']['total_rental']);
        
        if(!(Number($("#rental_hidden").val()))){
            $("#amount_due_rental").val('0.00');
        }
        if(!(Number($("#rental_hidden").val()))){
            $("#payment_collection_div").text(($("#amount_due").val() < 0)?'Payment Mode':'Payment Collection Mode');
            $("#final_due_amount").text($("#amount_due").val());
            $("#final_due_amount_hid").val($("#amount_due").val());
        }else{
            $("#payment_collection_div").text(($("#amount_due_rental").val() < 0)?'Payment Mode':'Payment Collection Mode');
            $("#final_due_amount").text($("#amount_due_rental").val());
            $("#final_due_amount_hid").val($("#amount_due_rental").val());
        }
              
            },
            error:function(response){
                $.alert({
                   type: 'red',
                   title: 'Alert!',
                   content: 'Error',
                });
            }
          });
      }
      }else{

        $(".no_of_hiring_div").hide();
					$(".no_of_hiring_input").show();
}
  });
  $(document).on('click','.speedo_reading_save',function(){
    if($(this).is(':checked')){
      var payin_id               = $(this).attr('rel');
      var driver_id		  		 = $("#driver_id").val();
	    var shift_id		  		 = $("#shift_id").val();
      
      var rental_hidden_val = $("#rental_hidden").val();

      var other_rental                 = Number($("#other_rental").val());
      var bond_total_rental            = Number($("#bond_total_rental").val());
      var accident_installment_rental  = Number($("#accident_installment_rental").val());
      var discount_rental              = Number($("#discount_rental").val());
      var amount_paid_rental           = Number($("#amount_paid_rental").val());

      var other_com                 =  Number($("#other").val());
      var bond_total_com            =  Number($("#bond_total").val());
      var accident_installment_com  =  Number($("#accident_installment").val()); 
      var discount_com              =  Number($("#discount").val());
      var amount_paid_com           =  Number($("#amount_paid").val());
      
      other_com = isNaN(other_com)?0:other_com;
      bond_total_com = isNaN(bond_total_com)?0:bond_total_com;
      accident_installment_com = isNaN(accident_installment_com)?0:accident_installment_com;
      discount_com = isNaN(discount_com)?0:discount_com;
      amount_paid_com = isNaN(amount_paid_com)?0:amount_paid_com;

      other_rental = isNaN(other_rental)?0:other_rental;
      bond_total_rental = isNaN(bond_total_rental)?0:bond_total_rental;
      accident_installment_rental = isNaN(accident_installment_rental)?0:accident_installment_rental;
      discount_rental = isNaN(discount_rental)?0:discount_rental;
      amount_paid_rental = isNaN(amount_paid_rental)?0:amount_paid_rental;

      var no_of_whl_rental             = Number($("#no_of_whl_rental").val());
      var no_of_whl_com                 = Number($("#no_of_whl").val());

      no_of_whl_com = isNaN(no_of_whl_com)?0:no_of_whl_com;

      no_of_whl_rental = isNaN(no_of_whl_rental)?0:no_of_whl_rental;
      
      var speedo_reading_start   = $('.speedo_reading_tr > td:nth-of-type(1) > input:nth-of-type(1)').val();      
      var speedo_reading_end     = $('.speedo_reading_tr > td:nth-of-type(3) > input:nth-of-type(1)').val();
      if(parseFloat(speedo_reading_end) < parseFloat(speedo_reading_start)){
          $('.speedo_reading_tr > td:nth-of-type(3) > input:nth-of-type(1)').css('border-color', 'red');
          $.alert({
                 type: 'red',
                 title: 'Alert!',
                 content: 'Speedo Finish Reading Should Be Greater Than Start Reading.',
              });   
          return false;    
      }
      else{
          $.ajax({
            type: "POST",
            url: '<?php echo base_url('admin/DriverSettlement/saveDriverSettlement')?>',
            data:{payin_id:payin_id,start_value:speedo_reading_start,end_value:speedo_reading_end,start_colmn:'speedo_reading_start',end_colmn:'speedo_reading_end',driver_id:driver_id,shift_id:shift_id,discount_com:discount_com,other_com:other_com,bond_total_com:bond_total_com,accident_installment_com:accident_installment_com,amount_paid_com:amount_paid_com,
            discount_rental:discount_rental,other_rental:other_rental,bond_total_rental:bond_total_rental,accident_installment_rental:accident_installment_rental,amount_paid_rental:amount_paid_rental,rental_commission:(rental_hidden_val > 0)?'R':'C',flag:1,rental_hidden_val:rental_hidden_val,no_of_whl_com:no_of_whl_com,no_of_whl_rental:no_of_whl_rental},
            dataType:'JSON',
            global: false,
            success: function(response){
              if(response['process'] =='success'){
                //alert("Successfully updated.");
                $("#speedo_reading_start_div").html(speedo_reading_start);
                $("#speedo_reading_end_div").html(speedo_reading_end); 
                $(".speedo_reading_div").show();
                $(".speedo_reading_input").hide();
                
                
              }
              else{
                $.alert({
                 type: 'red',
                 title: 'Alert!',
                 content: 'Some problem occure.Please try again.',
                });
              } 
              
              
              
              //--------------------------------Commission Based--------------------------//
        $("#total_dockets").val(response['total_settlement']['total_dockets']);
        $("#total_expense").val(response['total_settlement']['total_expense']);
        $("#levy_total").val(response['total_settlement']['levy_total']);
        $("#no_of_whl").val(response['total_settlement']['no_of_whl_com']);
        $("#accident_installment").val(response['total_settlement']['accident_installment_com']);
        $("#bond_total").val(response['total_settlement']['bond_total_com']);
        $("#other").val(response['total_settlement']['other_com']);
        $("#amount_due").val(response['total_settlement']['amount_due_com']);
        $("#discount").val(response['total_settlement']['discount_com']);
        $("#total").val(response['total_settlement']['total_com']);
        
        //--------------------------------Rental Based--------------------------//
        $("#total_dockets_rental").val(response['total_settlement']['total_dockets']);
        $("#total_expense_rental").val(response['total_settlement']['total_expense']);
        $("#levy_total_rental").val(response['total_settlement']['levy_total']);
        $("#no_of_whl_rental").val(response['total_settlement']['no_of_whl_rental']);
        $("#accident_installment_rental").val(response['total_settlement']['accident_installment_rental']);
        $("#bond_total_rental").val(response['total_settlement']['bond_total_rental']);
        $("#other_rental").val(response['total_settlement']['other_rental']);
        $("#amount_due_rental").val(response['total_settlement']['amount_due_rental']);
        $("#discount_rental").val(response['total_settlement']['discount_rental']);
        $("#total_rental").val(response['total_settlement']['total_rental']);
        
        if(!(Number($("#rental_hidden").val()))){
            $("#amount_due_rental").val('0.00');
        }
        if(!(Number($("#rental_hidden").val()))){
            $("#payment_collection_div").text(($("#amount_due").val() < 0)?'Payment Mode':'Payment Collection Mode');
            $("#final_due_amount").text($("#amount_due").val());
            $("#final_due_amount_hid").val($("#amount_due").val());
        }else{
            $("#payment_collection_div").text(($("#amount_due_rental").val() < 0)?'Payment Mode':'Payment Collection Mode');
            $("#final_due_amount").text($("#amount_due_rental").val());
            $("#final_due_amount_hid").val($("#amount_due_rental").val());
        }
              
            },
            error:function(response){
               $.alert({
                 type: 'red',
                 title: 'Alert!',
                 content: 'Error',
                });
            }
          });
      }
      }else{

        $(".speedo_reading_div").hide();
                $(".speedo_reading_input").show();
}
  });
// $(document).on('click','.driver_docket_edit',function(){
//     $(this).parents('.driver_docket_tr').find('input.docket_pr_input').attr('type','number');
//     $(this).parents('.driver_docket_tr').find('input.docket_pr_input').attr('min','1');
//     //$(this).parents('.driver_docket_tr').find('input.input_file').attr('type','file');
    
//     $(this).parents('tr').find('.docket_price_div').hide();    
// });
$(document).on('click','.driver_docket_save',function(){
  var currnt_obj        = $(this);
  if($(this).is(':checked')){
      var payin_dockets_id  = $(this).attr('id');
      var docket_identification_id = $(this).parents('tr').find('.docket_identification_id').val();
      var driver_docket_pr  = $(this).parents('tr').find('.docket_price_val').val();
      var driver_id		  = $("#driver_id").val();
      var shift_id		  = $("#shift_id").val();
      var payin_id 		  = $("#payin_id").val();
      var rental_hidden_val = $("#rental_hidden").val();
      var docket_id = $(this).parents('.driver_docket_tr').find('.docket_cls').val();

      var other_rental                    = Number($("#other_rental").val());
      var bond_total_rental             = Number($("#bond_total_rental").val());
      var accident_installment_rental   = Number($("#accident_installment_rental").val());
      var discount_rental               = Number($("#discount_rental").val());
      var amount_paid_rental            = Number($("#amount_paid_rental").val());
      var other_com                     =  Number($("#other").val());
      var bond_total_com                =  Number($("#bond_total").val());
      var accident_installment_com      =  Number($("#accident_installment").val());
      var discount_com                  =  Number($("#discount").val());
      var amount_paid_com               =  Number($("#amount_paid").val());
      
      other_com = isNaN(other_com)?0:other_com;
      bond_total_com = isNaN(bond_total_com)?0:bond_total_com;
      accident_installment_com = isNaN(accident_installment_com)?0:accident_installment_com;
      discount_com = isNaN(discount_com)?0:discount_com;
      amount_paid_com = isNaN(amount_paid_com)?0:amount_paid_com;

      other_rental = isNaN(other_rental)?0:other_rental;
      bond_total_rental = isNaN(bond_total_rental)?0:bond_total_rental;
      accident_installment_rental = isNaN(accident_installment_rental)?0:accident_installment_rental;
      discount_rental = isNaN(discount_rental)?0:discount_rental;
      amount_paid_rental = isNaN(amount_paid_rental)?0:amount_paid_rental;


      var no_of_whl_rental             = Number($("#no_of_whl_rental").val());
      var no_of_whl_com                 = Number($("#no_of_whl").val());

      no_of_whl_com = isNaN(no_of_whl_com)?0:no_of_whl_com;

      no_of_whl_rental = isNaN(no_of_whl_rental)?0:no_of_whl_rental;
    
    
    
    
    var formdata = new FormData();
    //console.log($(this).parents('driver_docket_tr').find('.docket_image'));
    if(!payin_dockets_id){

      if(!driver_docket_pr || !docket_id){
          $.alert({
             type: 'red',
             title: 'Alert!',
             content: 'Select Docket & amount Required',
          });
          return false;

    }

      
    
    }
    var docket_image_link = $(this).parents('.driver_docket_tr').find('.docket_image').val();
    var docket_image_type = $(this).parents('.driver_docket_tr').find('.docket_upload_image_btn').val();
    var data_id = $(this).parents('.driver_docket_tr').find('.docket_upload_image_btn option:selected').data('id');
    var docket_image_file = $(this).parents('.driver_docket_tr').find('.docket_image_file')[0].files[0];

    formdata.append('docket_image',docket_image_link);
    formdata.append('docket_image_file',docket_image_file);
    formdata.append('docket_image_type',docket_image_type);
    formdata.append('payin_dockets_id',payin_dockets_id);
    formdata.append('docket_id',docket_id);
    formdata.append('docket_identification_id',docket_identification_id);
    formdata.append('driver_docket_pr',driver_docket_pr);
    formdata.append('driver_id',driver_id);
    formdata.append('shift_id',shift_id);
    formdata.append('payin_id',payin_id);
    formdata.append('discount_com',discount_com);
    formdata.append('other_com',other_com);
    formdata.append('bond_total_com',bond_total_com);
    formdata.append('accident_installment_com',accident_installment_com);
    formdata.append('amount_paid_com',amount_paid_com);
    formdata.append('discount_rental',discount_rental);
    formdata.append('other_rental',other_rental);
    formdata.append('bond_total_rental',bond_total_rental);
    formdata.append('accident_installment_rental',accident_installment_rental);  
    formdata.append('amount_paid_rental',amount_paid_rental);
    formdata.append('rental_commission',(rental_hidden_val > 0)?'R':'C');
    formdata.append('flag',1);
    formdata.append('rental_hidden_val',rental_hidden_val);
    formdata.append('no_of_whl_com',no_of_whl_com);
    formdata.append('no_of_whl_rental',no_of_whl_rental);
  
  
  //alert(driver_id+"&&"+shift_id+"$$"+payin_id);
    $(".se-pre-con").show(); 
    $.ajax({
      type: "POST",
      url: '<?php echo base_url('admin/DriverSettlement/saveDriverDocket')?>',
      data:formdata,
      dataType:'JSON',
      contentType: false,
      processData: false,
      global: false,
      success: function(response){
      	//alert(response);
        if(response['process'] =='success'){
          //alert("Successfully updated.");          
          currnt_obj.parents('.driver_docket_tr').find('.docket_pr_input').hide();
          currnt_obj.parents('tr').find('.docket_price_div').show();  
          currnt_obj.parents('tr').find('.docket_price_div').html(driver_docket_pr); 
          currnt_obj.parents('tr').find('.docket_identification_id').val(response['docket_identification_id']);
          if(docket_image_type = 'F'){
            $('#docket_uploaded_a_'+data_id).attr('href',base_url+'public/upload_image/payin_images/'+response['image_link']); 
            $('#docket_uploaded_img_'+data_id).show();
            $('#docket_uploaded_img_'+data_id).attr('src',base_url+'public/upload_image/payin_images/'+response['image_link']);
            $('#docket_image_'+data_id).val(response['image_link']);
           }$(".se-pre-con").fadeOut("slow"); 
        }
        else{ 
          $(".se-pre-con").fadeOut("slow");   
          $.alert({
             type: 'red',
             title: 'Alert!',
             content: 'Some problem occure.Please try again.',
            });
        } 
        
        //--------------------------------Commission Based--------------------------//
        $("#total_dockets").val(response['total_settlement']['total_dockets']);
        $("#total_expense").val(response['total_settlement']['total_expense']);
        $("#levy_total").val(response['total_settlement']['levy_total']);
        $("#no_of_whl").val(response['total_settlement']['no_of_whl_com']);
        $("#accident_installment").val(response['total_settlement']['accident_installment_com']);
        $("#bond_total").val(response['total_settlement']['bond_total_com']);
        $("#other").val(response['total_settlement']['other_com']);
        $("#amount_due").val(response['total_settlement']['amount_due_com']);
        $("#discount").val(response['total_settlement']['discount_com']);
        $("#total").val(response['total_settlement']['total_com']);
        
        //--------------------------------Rental Based--------------------------//
        $("#total_dockets_rental").val(response['total_settlement']['total_dockets']);
        $("#total_expense_rental").val(response['total_settlement']['total_expense']);
        $("#levy_total_rental").val(response['total_settlement']['levy_total']);
        $("#no_of_whl_rental").val(response['total_settlement']['no_of_whl_rental']);
        $("#accident_installment_rental").val(response['total_settlement']['accident_installment_rental']);
        $("#bond_total_rental").val(response['total_settlement']['bond_total_rental']);
        $("#other_rental").val(response['total_settlement']['other_rental']);
        $("#amount_due_rental").val(response['total_settlement']['amount_due_rental']);
        $("#discount_rental").val(response['total_settlement']['discount_rental']);
        $("#total_rental").val(response['total_settlement']['total_rental']);
        
        if(!(Number($("#rental_hidden").val()))){
            $("#amount_due_rental").val('0.00');
        }
        if(!(Number($("#rental_hidden").val()))){
            $("#payment_collection_div").text(($("#amount_due").val() < 0)?'Payment Mode':'Payment Collection Mode');
            $("#final_due_amount").text($("#amount_due").val());
            $("#final_due_amount_hid").val($("#amount_due").val());
        }else{
            $("#payment_collection_div").text(($("#amount_due_rental").val() < 0)?'Payment Mode':'Payment Collection Mode');
            $("#final_due_amount").text($("#amount_due_rental").val());
            $("#final_due_amount_hid").val($("#amount_due_rental").val());
        }
        currnt_obj.parents('.driver_docket_tr').find('.delete_btn').remove();
           
            },
      error:function(response){
         $(".se-pre-con").fadeOut("slow"); 
         $.alert({
             type: 'red',
             title: 'Alert!',
             content: 'ERROR',
          });
      }
    });
  }else{
    currnt_obj.parents('.driver_docket_tr').find('.docket_pr_input').show();
    currnt_obj.parents('tr').find('.docket_price_div').hide();

  }
});
// $(document).on('click','.driver_expense_edit',function(){
//     $(this).parents('.driver_expenses_tr').find('input.expense_price_inp').attr('type','number');
//     $(this).parents('.driver_expenses_tr').find('input.expense_price_inp').attr('min','1');
//     //$(this).parents('.driver_docket_tr').find('input.input_file').attr('type','file');
    
//     $(this).parents('tr').find('.expense_price_div').hide();    
// });
$(document).on('click','.driver_expense_save',function(){
    
  var currnt_obj        = $(this);
  if($(this).is(':checked')){
    var payin_expense_id  = $(this).attr('id');
    var expense_identification_id = $(this).parents('tr').find('.expense_identification_id').val();
    var driver_expense_pr  = $(this).parents('tr').find('.expense_price_val').val();
    var driver_id		  = $("#driver_id").val();
	  var shift_id		  = $("#shift_id").val();
    var payin_id 		  = $("#payin_id").val();
    var rental_hidden_val = $("#rental_hidden").val();
    var expense_id = $(this).parents('.driver_expenses_tr').find('.expense_cls').val();

    var other_rental                 = Number($("#other_rental").val());
      var bond_total_rental            = Number($("#bond_total_rental").val());
      var accident_installment_rental  = Number($("#accident_installment_rental").val());
      var discount_rental              = Number($("#discount_rental").val());
      var amount_paid_rental           = Number($("#amount_paid_rental").val());

      var other_com                 =  Number($("#other").val());
      var bond_total_com            =  Number($("#bond_total").val());
      var accident_installment_com  =  Number($("#accident_installment").val());
      var discount_com              =  Number($("#discount").val());
      var amount_paid_com           =  Number($("#amount_paid").val());
      
      other_com = isNaN(other_com)?0:other_com;
      bond_total_com = isNaN(bond_total_com)?0:bond_total_com;
      accident_installment_com = isNaN(accident_installment_com)?0:accident_installment_com;
      discount_com = isNaN(discount_com)?0:discount_com;
      amount_paid_com = isNaN(amount_paid_com)?0:amount_paid_com;

      other_rental = isNaN(other_rental)?0:other_rental;
      bond_total_rental = isNaN(bond_total_rental)?0:bond_total_rental;
      accident_installment_rental = isNaN(accident_installment_rental)?0:accident_installment_rental;
      discount_rental = isNaN(discount_rental)?0:discount_rental;
      amount_paid_rental = isNaN(amount_paid_rental)?0:amount_paid_rental;
    
      var no_of_whl_rental             = Number($("#no_of_whl_rental").val());
      var no_of_whl_com                 = Number($("#no_of_whl").val());

      no_of_whl_com = isNaN(no_of_whl_com)?0:no_of_whl_com;

      no_of_whl_rental = isNaN(no_of_whl_rental)?0:no_of_whl_rental;
    
    
    var formdata = new FormData();
    //console.log($(this).parents('driver_docket_tr').find('.docket_image'));
    if(!payin_expense_id){

      if(!driver_expense_pr || !expense_id){
          $.alert({
             type: 'red',
             title: 'Alert!',
             content: 'Select Expense & amount Required',
          });
          return false;

    }

      
    
    }

    var expense_image_link = $(this).parents('.driver_expenses_tr').find('.expense_image').val();
    var expense_image_type = $(this).parents('.driver_expenses_tr').find('.expense_upload_image_btn').val();
    var data_id = $(this).parents('.driver_expenses_tr').find('.expense_upload_image_btn option:selected').data('id');
    var expense_image_file = $(this).parents('.driver_expenses_tr').find('.expense_image_file')[0].files[0];
    
    formdata.append('expense_image_file',expense_image_file);
    formdata.append('expense_image_type',expense_image_type);
    formdata.append('expense_image',expense_image_link);
    formdata.append('payin_expense_id',payin_expense_id);
    formdata.append('expense_identification_id',expense_identification_id);
    formdata.append('expense_id',expense_id);
    formdata.append('driver_expense_pr',driver_expense_pr);
    formdata.append('driver_id',driver_id);
    formdata.append('shift_id',shift_id);
    formdata.append('payin_id',payin_id);
    
    formdata.append('discount_com',discount_com);
    formdata.append('other_com',other_com);
    formdata.append('bond_total_com',bond_total_com);
    formdata.append('accident_installment_com',accident_installment_com);
    formdata.append('amount_paid_com',amount_paid_com);


    formdata.append('discount_rental',discount_rental);
    formdata.append('other_rental',other_rental);
    formdata.append('bond_total_rental',bond_total_rental);
    formdata.append('accident_installment_rental',accident_installment_rental);  
    formdata.append('amount_paid_rental',amount_paid_rental);
    
    formdata.append('rental_commission',(rental_hidden_val > 0)?'R':'C');
    formdata.append('flag',1);
    formdata.append('rental_hidden_val',rental_hidden_val);
    formdata.append('no_of_whl_com',no_of_whl_com);
    formdata.append('no_of_whl_rental',no_of_whl_rental);
  
  
  //alert(driver_id+"&&"+shift_id+"$$"+payin_id);
    $(".se-pre-con").show(); 
    $.ajax({
      type: "POST",
      url: '<?php echo base_url('admin/DriverSettlement/saveDriverExpense')?>',
      data:formdata,
      dataType:'JSON',
      contentType: false,
      processData: false,
      global: false,
      success: function(response){
      	//alert(response);
        if(response['process'] =='success'){
          //alert("Successfully updated.");          
          currnt_obj.parents('.driver_expenses_tr').find('.expense_price_inp').hide();
          currnt_obj.parents('tr').find('.expense_price_div').show();  
          currnt_obj.parents('tr').find('.expense_price_div').html(driver_expense_pr); 
          currnt_obj.parents('tr').find('.expense_identification_id').val(response['expense_identification_id']);
          if(expense_image_type = 'F'){
            $('#expense_uploaded_a_'+data_id).attr('href',base_url+'public/upload_image/payin_images/'+response['image_link']); 
            $('#expense_uploaded_img_'+data_id).show();
            $('#expense_uploaded_img_'+data_id).attr('src',base_url+'public/upload_image/payin_images/'+response['image_link']);
            $('#expense_image_'+data_id).val(response['image_link']);
          } $(".se-pre-con").fadeOut("slow"); 
        }
        else{
          $(".se-pre-con").fadeOut("slow");   
          $.alert({
             type: 'red',
             title: 'Alert!',
             content: 'Some problem occured.Please try again.',
            });
        } 
        
        //--------------------------------Commission Based--------------------------//
        $("#total_dockets").val(response['total_settlement']['total_dockets']);
        $("#total_expense").val(response['total_settlement']['total_expense']);
        $("#levy_total").val(response['total_settlement']['levy_total']);
        $("#no_of_whl").val(response['total_settlement']['no_of_whl_com']);
        $("#accident_installment").val(response['total_settlement']['accident_installment_com']);
        $("#bond_total").val(response['total_settlement']['bond_total_com']);
        $("#other").val(response['total_settlement']['other_com']);
        $("#amount_due").val(response['total_settlement']['amount_due_com']);
        $("#discount").val(response['total_settlement']['discount_com']);
        $("#total").val(response['total_settlement']['total_com']);
        
        //--------------------------------Rental Based--------------------------//
        $("#total_dockets_rental").val(response['total_settlement']['total_dockets']);
        $("#total_expense_rental").val(response['total_settlement']['total_expense']);
        $("#levy_total_rental").val(response['total_settlement']['levy_total']);
        $("#no_of_whl_rental").val(response['total_settlement']['no_of_whl_rental']);
        $("#accident_installment_rental").val(response['total_settlement']['accident_installment_rental']);
        $("#bond_total_rental").val(response['total_settlement']['bond_total_rental']);
        $("#other_rental").val(response['total_settlement']['other_rental']);
        $("#amount_due_rental").val(response['total_settlement']['amount_due_rental']);
        $("#discount_rental").val(response['total_settlement']['discount_rental']);
        $("#total_rental").val(response['total_settlement']['total_rental']);
        
        if(!(Number($("#rental_hidden").val()))){
            $("#amount_due_rental").val('0.00');
        }
        if(!(Number($("#rental_hidden").val()))){
            $("#payment_collection_div").text(($("#amount_due").val() < 0)?'Payment Mode':'Payment Collection Mode');
            $("#final_due_amount").text($("#amount_due").val());
            $("#final_due_amount_hid").val($("#amount_due").val());
        }else{
            $("#payment_collection_div").text(($("#amount_due_rental").val() < 0)?'Payment Mode':'Payment Collection Mode');
            $("#final_due_amount").text($("#amount_due_rental").val());
            $("#final_due_amount_hid").val($("#amount_due_rental").val());
        }
        currnt_obj.parents('.driver_expenses_tr').find('.delete_btn_expense').remove();
           
            },
      error:function(response){
         $(".se-pre-con").fadeOut("slow"); 
         $.alert({
             type: 'red',
             title: 'Alert!',
             content: 'ERROR',
          });
      }
    });
  }else{
    currnt_obj.parents('.driver_expenses_tr').find('.expense_price_inp').show();
    currnt_obj.parents('tr').find('.expense_price_div').hide();

  }
});

$(document).on('keyup chnage','.calculate_due_amt',function(event){
   calculate_TOTAL($(this).data('rental_commission'));
});


function calculate_TOTAL(rental_commission){
  event.preventDefault();
  
  var driver_id             = $("#driver_id").val();
  var shift_id              = $("#shift_id").val();
  var payin_id              = $("#payin_id").val();
  var rental_hidden_val     = $("#rental_hidden").val();
  
  
      var no_of_whl_rental             = Number($("#no_of_whl_rental").val());
      var other_rental                 = Number($("#other_rental").val());
      var bond_total_rental            = Number($("#bond_total_rental").val());
      var accident_installment_rental  = Number($("#accident_installment_rental").val());
      var discount_rental              = Number($("#discount_rental").val());
      var amount_paid_rental           = Number($("#amount_paid_rental").val());

      var no_of_whl_com                 = Number($("#no_of_whl").val());
      var other_com                 =  Number($("#other").val());
      var bond_total_com            =  Number($("#bond_total").val());
      var accident_installment_com  =  Number($("#accident_installment").val());
      var discount_com              =  Number($("#discount").val());
      var amount_paid_com           =  Number($("#amount_paid").val());
      
      no_of_whl_com = isNaN(no_of_whl_com)?0:no_of_whl_com;
      other_com = isNaN(other_com)?0:other_com;
      bond_total_com = isNaN(bond_total_com)?0:bond_total_com;
      accident_installment_com = isNaN(accident_installment_com)?0:accident_installment_com;
      discount_com = isNaN(discount_com)?0:discount_com;
      amount_paid_com = isNaN(amount_paid_com)?0:amount_paid_com;

      no_of_whl_rental = isNaN(no_of_whl_rental)?0:no_of_whl_rental;
      other_rental = isNaN(other_rental)?0:other_rental;
      bond_total_rental = isNaN(bond_total_rental)?0:bond_total_rental;
      accident_installment_rental = isNaN(accident_installment_rental)?0:accident_installment_rental;
      discount_rental = isNaN(discount_rental)?0:discount_rental;
      amount_paid_rental = isNaN(amount_paid_rental)?0:amount_paid_rental;
  
  $.ajax({
      type: "POST",
      url: '<?php echo base_url('admin/DriverSettlement/calculateDiscount')?>',
      data:{driver_id:driver_id,shift_id:shift_id,payin_id:payin_id,discount_com:discount_com,other_com:other_com,bond_total_com:bond_total_com,accident_installment_com:accident_installment_com,amount_paid_com:amount_paid_com,
            discount_rental:discount_rental,other_rental:other_rental,bond_total_rental:bond_total_rental,accident_installment_rental:accident_installment_rental,amount_paid_rental:amount_paid_rental,rental_commission:(rental_commission=='commission')?'C':'R',rental_hidden_val:rental_hidden_val,flag:1,no_of_whl_rental:no_of_whl_rental,no_of_whl_com:no_of_whl_com},
      dataType:'json',
      global: false,
      success: function(response){
        //alert(response);
        if(response){
          //alert("#total"+((rental_commission=='rental')?'_'+rental_commission:''));
          $("#total"+((rental_commission=='rental')?'_'+rental_commission:'')).val(response['total'+((rental_commission=='rental')?'_rental':'_com')]);
          $("#amount_due"+((rental_commission=='rental')?'_'+rental_commission:'')).val(response['amount_due'+((rental_commission=='rental')?'_rental':'_com')]);
            
            if(!(Number($("#rental_hidden").val()))){
              $("#amount_due_rental").val('0.00');
            }
            
            if(!(Number($("#rental_hidden").val()))){
            $("#payment_collection_div").text(($("#amount_due").val() < 0)?'Payment Mode':'Payment Collection Mode');
            $("#final_due_amount").text($("#amount_due").val());
            $("#final_due_amount_hid").val($("#amount_due").val());
        }else{
            $("#payment_collection_div").text(($("#amount_due_rental").val() < 0)?'Payment Mode':'Payment Collection Mode');
            $("#final_due_amount").text($("#amount_due_rental").val());
            $("#final_due_amount_hid").val($("#amount_due_rental").val());
        }
        }                  
      },
      error:function(response){
         $.alert({
             type: 'red',
             title: 'Alert!',
             content: 'ERROR',
          });
      }
    });
}
$(document).on('keyup','.payment_opn',function(){
	var accumulate_amount	= 0;
	var values = $("input.payment_opn");

    var payment_opn_arr = $.map(values, function(element) {
       return element.value;
    });
    $.each(payment_opn_arr,function(){accumulate_amount +=parseFloat(this) || 0;});
    $("#admin_total_payment").val(accumulate_amount.toFixed(2));
    var total 				= $("#total").val();

    if(this.id==3){
      var cash_amt=$(this).val();
      if(cash_amt > 0){
        $("#denomination_div").show();
      } else {
        $("#denomination_div").hide();
      }
    }
	
});


  // $(document).on('keyup','.calculate_amt',function(){
  //   var qty = $(this).val();
  //   var dollar_price = $(this).data('dollar_price');
  //   var balance_qty = $(this).data('balance_qty');
  //   var final_due_amount_hid = $("#final_due_amount_hid").val();
  //   // alert(Number(qty));
  //   // alert(Number(balance_qty));
  //   if((Number(final_due_amount_hid) < 0)  && (Number(qty) > Number(balance_qty))){

  //       $.alert({
  //           type: 'red',
  //           title: 'Denomination Not Available',
  //           content: 'Denomination not available in your cashbox.please add denomination in cash In',
  //       });
  //       $(this).val(0);
  //   } 
  //   qty = $(this).val();  
  //   var amount = parseFloat(Number(qty) * Number(dollar_price)).toFixed(2);
  //   var total_cash_amount=$("#3").val();
  //   var total_amount =0 * 1;
    
  //   $(this).next('input[type=hidden]').val(amount);
  //   $(this).parent().parent().children('.dollar_amount').html(amount);
    
    
  //     $('.dollar_amount').each(function(){
  //         total_amount +=Number($(this).text());
  //     })
      
  //     if(Math.abs(total_cash_amount) < Math.abs(total_amount)){
  //       $.alert({
  //         type: 'red',
  //         title: 'Alert!',
  //         content: 'Cash amount not matched with denominations total',
  //       });
  //       $(this).val('');
  //       $(this).next('input[type=hidden]').val('');
  //       $(this).parent().parent().children('.dollar_amount').html('');
  //     }else{
  //       $(".total_amount").text(parseFloat(total_amount).toFixed(2));
  //       $("#total_amount").val(total_amount);
  //     }

  // })   


  $(document).on('keyup','.calculate_amt',function(){
    var qty = $(this).val();
    var dollar_price = $(this).data('dollar_price');
    var balance_qty = $(this).data('balance_qty');
    var final_due_amount_hid = $("#final_due_amount_hid").val();
    // alert(Number(qty));
    // alert(Number(balance_qty));
    if((Number(final_due_amount_hid) < 0)  && (Number(qty) > Number(balance_qty))){

        $.alert({
            type: 'red',
            title: 'Denomination Not Available',
            content: 'Denomination not available in your cashbox.please add denomination in cash In',
        });
        $(this).val(0);
    } 
    qty = $(this).val();  
    var amount = parseFloat(Number(qty) * Number(dollar_price)).toFixed(2);
    var total_amount_adjust = parseFloat(Number($(this).parents('tr').find('.dollar_amount_adjust').text())).toFixed(2);
    var final_amount = parseFloat(amount - total_amount_adjust).toFixed(2);; 
    
    $(this).next('input[type=hidden]').val(amount);
    $(this).parents('tr').find('.dollar_amount').html(amount);
    $(this).parents('tr').find('.final_amount').html(final_amount);
    calculate_total_cash($(this));
    
  }) 

  $(document).on('keyup','.calculate_amt_adjust',function(){
    var qty = $(this).val();
    var dollar_price = $(this).data('dollar_price');
    var balance_qty = $(this).data('balance_qty');
    var final_due_amount_hid = $("#final_due_amount_hid").val();
    // alert(Number(qty));
    // alert(Number(balance_qty));
    if((Number(final_due_amount_hid) > 0)  && (Number(qty) > Number(balance_qty))){

        $.alert({
            type: 'red',
            title: 'Denomination Not Available',
            content: 'Denomination not available in your cashbox.please add denomination in cash In',
        });
        $(this).val(0);
    } 
    qty = $(this).val();  
    var amount = parseFloat(Number(qty) * Number(dollar_price)).toFixed(2);
    
    var total_amount = parseFloat(Number($(this).parents('tr').find('.dollar_amount').text())).toFixed(2);
    var final_amount = parseFloat(total_amount - amount).toFixed(2);; 

    $(this).next('input[type=hidden]').val(amount);
    $(this).parents('tr').find('.dollar_amount_adjust').html(amount);
    $(this).parents('tr').find('.final_amount').html(final_amount);
    calculate_total_cash($(this));
    
  })  


  function calculate_total_cash(this_obj){

    var total_cash_amount=$("#3").val();
    var total_amount =0 * 1;
    var total_amount_adjust =0 * 1;
    $('.dollar_amount').each(function(){
        total_amount +=Number($(this).text());
    })

    $('.dollar_amount_adjust').each(function(){
        total_amount_adjust +=Number($(this).text());
    })

    var final_amount = total_amount - total_amount_adjust;
    
    // if(Math.abs(total_cash_amount) < Math.abs(final_amount)){
    //   $.alert({
    //     type: 'red',
    //     title: 'Alert!',
    //     content: 'Cash amount not matched with denominations total',
    //   });
    //   this_obj.val('');
    //   this_obj.next('input[type=hidden]').val('');
    //   this_obj.parent().parent().children('.dollar_amount').html('');
    // }else{
      $(".total_amount").text(parseFloat(total_amount).toFixed(2));
      $(".total_amount_adjust").text(parseFloat(total_amount_adjust).toFixed(2));
      $(".total_final_amount").text(parseFloat(final_amount).toFixed(2));

      $("#total_amount").val(parseFloat(total_amount).toFixed(2));
      $("#total_amount_adjust").val(parseFloat(total_amount_adjust).toFixed(2));
      $("#total_amount_cash").val(parseFloat(final_amount).toFixed(2));
    //}

}

    
    
    
    // function calculate_total_amount(){
    //   var total_amount =0 * 1;
      
    //   $('.dollar_amount').each(function(){
    //       total_amount +=Number($(this).text());
    //   })
    //   $(".total_amount").text(parseFloat(total_amount).toFixed(2));
    //   $("#total_amount").val(total_amount);
    //   return total_amount;
    // } 

  $(document).on('click', '#submit_driver_settlement', function(event) {
      
     var checkbox_check = false;
    $('input[type=checkbox]').each(function () {
               if (!$(this).is(':checked')) {
                   
                   checkbox_check = false;
                   return false;
               } else {
                   
                   checkbox_check = true;
               }
    });
    event.preventDefault();
    var values = $("input.payment_opn");
      var payment_opn_arr = $.map(values, function(element) {
      	return element.value;
  	});
    var credit_card_amt       = 	payment_opn_arr[0];
  	var bank_transfer_amt     = 	payment_opn_arr[1];
  	var cash_amt 				      = 	payment_opn_arr[2];
    var admin_total_payment 	= 	$("#admin_total_payment").val();
    var final_due_amount      =   $("#final_due_amount_hid").val();
    var total                 = $("#final_due_amount_hid").val();
    var total_amount          = $("#total_amount_cash").val();
    //var cash_payment_total = $("#3").val();
    // alert(cash_payment_total);alert(total);return false;
    // alert(Math.abs(cash_amt));
    // alert(Math.abs(Number(total_amount)));
    // return false;
    if(!checkbox_check){
        $.alert({
                     type: 'red',
                     title: 'Alert!',
                     content: 'Please check all the checkbox before submit',
                    }); 
                    return false;
    }
  else if(admin_total_payment == ''){
    $.alert({
     type: 'red',
     title: 'Alert!',
     content: 'Please enter payment amount',
    });
    return false;

  }
  else if(Math.abs(Number(total)) < Math.abs(Number(admin_total_payment))){
    $.alert({
     type: 'red',
     title: 'Alert!',
     content: 'Accumulate amount should not greater than amount due',
    });
    return false;
  }
  else if(cash_amt > 0 && Math.abs(Number(cash_amt)) !=Math.abs(Number(total_amount))){
    $.alert({
     type: 'red',
     title: 'Alert!',
     content: 'Denomination total not matching with cash total',
    });
    return false;

  }
  else {

    var driver_id				= 	$("#driver_id").val();
  	var shift_id				= 	$("#shift_id").val();
    var rental_hidden   =   $("#rental_hidden").val();
    var dr_settlement_id  = $("#dr_settlement_id").val();
  	
    var total_dockets		=	$("#total_dockets").val();
  	var total_expense		=	$("#total_expense").val();
    var levy_total			=	$("#levy_total").val();
  
  	
    
    var no_of_whl                 = (!(Number(rental_hidden)))?Number($("#no_of_whl").val()):Number($("#no_of_whl_rental").val());
    var other                 = (!(Number(rental_hidden)))?Number($("#other").val()):Number($("#other_rental").val());
    var bond_total            = (!(Number(rental_hidden)))?Number($("#bond_total").val()):Number($("#bond_total_rental").val());
    var accident_installment  = (!(Number(rental_hidden)))?Number($("#accident_installment").val()):Number($("#accident_installment_rental").val());
    var discount              = (!(Number(rental_hidden)))?Number($("#discount").val()):Number($("#discount_rental").val());
    var amount_due            = (!(Number(rental_hidden)))?Number($("#amount_due").val()):Number($("#amount_due_rental").val());
    
    
    
    var c_1_coins_qty     = $("#1c_coins_qty").val();
    var c_1_coins_amt     = $("#1c_coins_amt").val();
    var c_5_coins_qty     = $("#5c_coins_qty").val();
    var c_5_coins_amt     = $("#5c_coins_amt").val();
    var c_10_coins_qty    = $("#10c_coins_qty").val();
    var c_10_coins_amt    = $("#10c_coins_amt").val();
    var c_20_coins_qty    = $("#20c_coins_qty").val();
    var c_20_coins_amt    = $("#20c_coins_amt").val();
    var c_50_coins_qty    = $("#50c_coins_qty").val();
    var c_50_coins_amt    = $("#50c_coins_amt").val();
    var d_1_coins_qty     = $("#1d_coins_qty").val();
    var d_1_coins_amt     = $("#1d_coins_amt").val();
    var d_2_coins_qty     = $("#2d_coins_qty").val();
    var d_2_coins_amt     = $("#2d_coins_amt").val();
    var d_5_notes_qty     = $("#5d_notes_qty").val();
    var d_5_notes_amt     = $("#5d_notes_amt").val();
    var d_10_notes_qty    = $("#10d_notes_qty").val();
    var d_10_notes_amt    = $("#10d_notes_amt").val();
    var d_20_notes_qty    = $("#20d_notes_qty").val();
    var d_20_notes_amt    = $("#20d_notes_amt").val();
    var d_50_notes_qty    = $("#50d_notes_qty").val();
    var d_50_notes_amt    = $("#50d_notes_amt").val();
    var d_100_notes_qty   = $("#100d_notes_qty").val();
    var d_100_notes_amt   = $("#100d_notes_amt").val(); 


    var c_1_coins_qty_adjust     = $("#1c_coins_qty_adjust").val();
    var c_1_coins_amt_adjust     = $("#1c_coins_amt_adjust").val();
    var c_5_coins_qty_adjust     = $("#5c_coins_qty_adjust").val();
    var c_5_coins_amt_adjust     = $("#5c_coins_amt_adjust").val();
    var c_10_coins_qty_adjust    = $("#10c_coins_qty_adjust").val();
    var c_10_coins_amt_adjust    = $("#10c_coins_amt_adjust").val();
    var c_20_coins_qty_adjust    = $("#20c_coins_qty_adjust").val();
    var c_20_coins_amt_adjust    = $("#20c_coins_amt_adjust").val();
    var c_50_coins_qty_adjust    = $("#50c_coins_qty_adjust").val();
    var c_50_coins_amt_adjust    = $("#50c_coins_amt_adjust").val();
    var d_1_coins_qty_adjust     = $("#1d_coins_qty_adjust").val();
    var d_1_coins_amt_adjust     = $("#1d_coins_amt_adjust").val();
    var d_2_coins_qty_adjust     = $("#2d_coins_qty_adjust").val();
    var d_2_coins_amt_adjust     = $("#2d_coins_amt_adjust").val();
    var d_5_notes_qty_adjust     = $("#5d_notes_qty_adjust").val();
    var d_5_notes_amt_adjust     = $("#5d_notes_amt_adjust").val();
    var d_10_notes_qty_adjust    = $("#10d_notes_qty_adjust").val();
    var d_10_notes_amt_adjust    = $("#10d_notes_amt_adjust").val();
    var d_20_notes_qty_adjust    = $("#20d_notes_qty_adjust").val();
    var d_20_notes_amt_adjust    = $("#20d_notes_amt_adjust").val();
    var d_50_notes_qty_adjust    = $("#50d_notes_qty_adjust").val();
    var d_50_notes_amt_adjust    = $("#50d_notes_amt_adjust").val();
    var d_100_notes_qty_adjust   = $("#100d_notes_qty_adjust").val();
    var d_100_notes_amt_adjust   = $("#100d_notes_amt_adjust").val();


    
    var total_amount_cash      = $("#total_amount_cash").val();
    var total_amount      = $("#total_amount").val();
    var total_amount_adjust      = $("#total_amount_adjust").val();

    
    var dr_settlement_id = $("#dr_settlement_id").val();

    var docket_price = $('input[name="docket_price[]"]').serializeArray();
    var expense_price = $('input[name="expense_price[]"]').serializeArray();
    var expense_id    = $('input[name="expense_id[]"],select[name="expense_id[]"]').serializeArray();
    var docket_id    = $('input[name="docket_id[]"],select[name="docket_id[]"]').serializeArray();
    var dr_settlement_docket_id = $('input[name="dr_settlement_docket_id[]"]').serializeArray();
    var dr_settlement_expense_id = $('input[name="dr_settlement_expense_id[]"]').serializeArray();

  	
    $.ajax({
        type: "POST",
        url: "<?php echo base_url('admin/DriverSettlement/EditDriversettlement/')?>"+dr_settlement_id,
        data:{driver_id:driver_id,shift_id:shift_id,total_dockets:total_dockets,total_expense:total_expense,accident_installment:accident_installment,bond_total:bond_total,other:other,levy_total:levy_total,no_of_whl:no_of_whl,amount_due:amount_due,discount:discount,credit_card_amt:credit_card_amt,bank_transfer_amt:bank_transfer_amt,cash_amt:cash_amt,admin_total_payment:admin_total_payment,
        "1c_coins_qty":c_1_coins_qty,"1c_coins_amt":c_1_coins_amt,
        "5c_coins_qty":c_5_coins_qty,"5c_coins_amt":c_5_coins_amt,"10c_coins_qty":c_10_coins_qty,"10c_coins_amt":c_10_coins_amt,"20c_coins_qty":c_20_coins_qty,"20c_coins_amt":c_20_coins_amt,"50c_coins_qty":c_50_coins_qty,"50c_coins_amt":c_50_coins_amt,"1d_coins_qty":d_1_coins_qty,"1d_coins_amt":d_1_coins_amt,"2d_coins_qty":d_2_coins_qty,"2d_coins_amt":d_2_coins_amt,"5d_notes_qty":d_5_notes_qty,"5d_notes_amt":d_5_notes_amt,"10d_notes_qty":d_10_notes_qty,"10d_notes_amt":d_10_notes_amt,"20d_notes_qty":d_20_notes_qty,"20d_notes_amt":d_20_notes_amt,"50d_notes_qty":d_50_notes_qty,"50d_notes_amt":d_50_notes_amt,"100d_notes_qty":d_100_notes_qty,"100d_notes_amt":d_100_notes_amt,
        "1c_coins_qty_adjust":c_1_coins_qty_adjust,"1c_coins_amt_adjust":c_1_coins_amt_adjust,
        "5c_coins_qty_adjust":c_5_coins_qty_adjust,"5c_coins_amt_adjust":c_5_coins_amt_adjust,"10c_coins_qty_adjust":c_10_coins_qty_adjust,"10c_coins_amt_adjust":c_10_coins_amt_adjust,"20c_coins_qty_adjust":c_20_coins_qty_adjust,"20c_coins_amt_adjust":c_20_coins_amt_adjust,"50c_coins_qty_adjust":c_50_coins_qty_adjust,"50c_coins_amt_adjust":c_50_coins_amt_adjust,"1d_coins_qty_adjust":d_1_coins_qty_adjust,"1d_coins_amt_adjust":d_1_coins_amt_adjust,"2d_coins_qty_adjust":d_2_coins_qty_adjust,"2d_coins_amt_adjust":d_2_coins_amt_adjust,"5d_notes_qty_adjust":d_5_notes_qty_adjust,"5d_notes_amt_adjust":d_5_notes_amt_adjust,"10d_notes_qty_adjust":d_10_notes_qty_adjust,"10d_notes_amt_adjust":d_10_notes_amt_adjust,"20d_notes_qty_adjust":d_20_notes_qty_adjust,"20d_notes_amt_adjust":d_20_notes_amt_adjust,"50d_notes_qty_adjust":d_50_notes_qty_adjust,"50d_notes_amt_adjust":d_50_notes_amt_adjust,"100d_notes_qty_adjust":d_100_notes_qty_adjust,"100d_notes_amt_adjust":d_100_notes_amt_adjust,
        "total_amount":total_amount,"total_amount_adjust":total_amount_adjust,
        "total_amount_cash":total_amount_cash,
        "final_due_amount":final_due_amount,"rental_hidden":rental_hidden,"dr_settlement_id":dr_settlement_id,"docket_price":docket_price,"expense_price":expense_price,"dr_settlement_docket_id":dr_settlement_docket_id,"dr_settlement_expense_id":dr_settlement_expense_id,"expense_id":expense_id,"docket_id":docket_id}, 
        dataType:'html',
        success: function(response){

          if(response =='success'){
            $.alert({
               type: 'green',
               title: 'Success',
               content: 'Successfully Driver payin settled.',
               buttons: {

                                          OK: {
                                            text: 'OK',
                                            btnClass: 'btn-green',
                                            action: function () {
                                                window.location.href="<?=base_url('admin/DriverSettlement/bulk_settlement_list')?>";
                                            } 
                                        },

                                        }
            });
          	
          }                  
        },
        error:function(response){           
          $.alert({
             type: 'red',
             title: 'Alert!',
             content: 'error',
          });
        }
      });
  }
  });
  var docket_key = "<?=isset($docket_key)?$docket_key + 1:0?>";
  $("#add_more_docket").click(function(){docket_key++;
         

          var resultHTML =`<tr class="driver_docket_tr">                                  
                          <td>
                            <select  class="docket_cls js-select2" name="docket_id[]" data-show-subtext="true" data-live-search="true">
                              <option value="">Select Docket</option>
                              <?php if(!empty($docket_list)): ?>
                              <?php   foreach($docket_list as $list): ?>
                                <option value="<?php echo $list['docket_id'];?>"><?php echo $list['docket_name'];?></option>
                              <?php   endforeach; ?>
                              <?php endif; ?>
                            </select>
                          </td>
                          <td>
                            
                          <select class="docket_upload_image_btn">
                              <option value="" data-id="`+docket_key+`">Select</option>
                              <option value="C" data-id="`+docket_key+`">Camera</option>
                              <option value="F" data-id="`+docket_key+`">File</option>
                            </select>
                            
                            <input type="hidden" id="docket_image_`+docket_key+`"  class="docket_image">
                            <input type="file" id="docket_image_file_`+docket_key+`" name="" class="docket_image_file" style="display:none;">

                            <a id="docket_uploaded_a_`+docket_key+`" data-fancybox data-caption="Dockets IMAGE">
                              <img id="docket_uploaded_img_`+docket_key+`" alt="The screen capture will appear in this box." height="50px" width="50px" style="display:none;"> 
                            </a>  
                              
                            
                          </td>
                          <td class="td_amount_right driver_docket_price">
                              
                          <div class="input-group">
                                  <div class="input-group-prepend docket_pr_input">
                                      <span class="input-group-text" id="basic-addon1">$</span>
                                  </div>
                              <div style="display:none;" class="docket_price_div"></div>
                              <input type="hidden" name="dr_settlement_docket_id[]" value="">
                              <input type="hidden" class="docket_identification_id" value="">
                              <input class="form-control docket_pr_input decimal_validation_cls docket_price_val" type="text" name="docket_price[]"  value="" style="width:65%">
                          </div>
                          

                          </td>
                          <td class="text-center">
                            <label class="chk_custom_box">
                              <input type="checkbox" id="" class="driver_docket_save">
                              <span class="checkmark"></span>
                            </label>
                            <button type="button" class="btn btn-danger btn-sm delete_btn"><span><i class="fa fa-trash" aria-hidden="true"></i></span></button>
                          </td>
                          
                      </tr>`; 

                      $("#driver_docket_tbody").append(resultHTML);
                      $(".js-select2").select2();

    
    })
    $(document).on('click','.delete_btn',function(){
      
      var payin_dockets_id  = $(this).data('payin_dockets_id');
      if(!payin_dockets_id){
        $(this).parents('.driver_docket_tr').remove();
      } else {
      
      var currnt_obj        = $(this);
      var docket_identification_id = $(this).parents('tr').find('.docket_identification_id').val();
      var driver_docket_pr  = $(this).parents('tr').find('.docket_price_val').val();
      var driver_id		  = $("#driver_id").val();
      var shift_id		  = $("#shift_id").val();
      var payin_id 		  = $("#payin_id").val();
      var rental_hidden_val = $("#rental_hidden").val();
      var docket_id = $(this).parents('.driver_docket_tr').find('.docket_cls').val();

      var other_rental                    = Number($("#other_rental").val());
      var bond_total_rental             = Number($("#bond_total_rental").val());
      var accident_installment_rental   = Number($("#accident_installment_rental").val());
      var discount_rental               = Number($("#discount_rental").val());
      var amount_paid_rental            = Number($("#amount_paid_rental").val());
      var other_com                     =  Number($("#other").val());
      var bond_total_com                =  Number($("#bond_total").val());
      var accident_installment_com      =  Number($("#accident_installment").val());
      var discount_com                  =  Number($("#discount").val());
      var amount_paid_com               =  Number($("#amount_paid").val());
      
      other_com = isNaN(other_com)?0:other_com;
      bond_total_com = isNaN(bond_total_com)?0:bond_total_com;
      accident_installment_com = isNaN(accident_installment_com)?0:accident_installment_com;
      discount_com = isNaN(discount_com)?0:discount_com;
      amount_paid_com = isNaN(amount_paid_com)?0:amount_paid_com;

      other_rental = isNaN(other_rental)?0:other_rental;
      bond_total_rental = isNaN(bond_total_rental)?0:bond_total_rental;
      accident_installment_rental = isNaN(accident_installment_rental)?0:accident_installment_rental;
      discount_rental = isNaN(discount_rental)?0:discount_rental;
      amount_paid_rental = isNaN(amount_paid_rental)?0:amount_paid_rental;


      var no_of_whl_rental             = Number($("#no_of_whl_rental").val());
      var no_of_whl_com                 = Number($("#no_of_whl").val());

      no_of_whl_com = isNaN(no_of_whl_com)?0:no_of_whl_com;

      no_of_whl_rental = isNaN(no_of_whl_rental)?0:no_of_whl_rental;
    
    
    
    
    var formdata = new FormData();
    
    
    var data_id = $(this).parents('.driver_docket_tr').find('.docket_upload_image_btn option:selected').data('id');
    

    
    formdata.append('payin_dockets_id',payin_dockets_id);
    formdata.append('docket_id',docket_id);
    formdata.append('docket_identification_id',docket_identification_id);
    formdata.append('driver_docket_pr',driver_docket_pr);
    formdata.append('driver_id',driver_id);
    formdata.append('shift_id',shift_id);
    formdata.append('payin_id',payin_id);
    formdata.append('discount_com',discount_com);
    formdata.append('other_com',other_com);
    formdata.append('bond_total_com',bond_total_com);
    formdata.append('accident_installment_com',accident_installment_com);
    formdata.append('amount_paid_com',amount_paid_com);
    formdata.append('discount_rental',discount_rental);
    formdata.append('other_rental',other_rental);
    formdata.append('bond_total_rental',bond_total_rental);
    formdata.append('accident_installment_rental',accident_installment_rental);  
    formdata.append('amount_paid_rental',amount_paid_rental);
    formdata.append('rental_commission',(rental_hidden_val > 0)?'R':'C');
    formdata.append('flag',1);
    formdata.append('rental_hidden_val',rental_hidden_val);
    formdata.append('no_of_whl_com',no_of_whl_com);
    formdata.append('no_of_whl_rental',no_of_whl_rental);
  
  
  //alert(driver_id+"&&"+shift_id+"$$"+payin_id);
    $.ajax({
      type: "POST",
      url: '<?php echo base_url('admin/DriverSettlement/deleteDriverDocket')?>',
      data:formdata,
      dataType:'JSON',
      contentType: false,
      processData: false,
      global: false,
      success: function(response){
      	//alert(response);
        if(response['process'] =='success'){
          //alert("Successfully updated.");          
          currnt_obj.parents('.driver_docket_tr').remove(); 
          $.alert({
             type: 'green',
             title: 'Deleted Successfully',
             content: 'Docket deleted successfully',
          });
         
        }
        else{          
          $.alert({
             type: 'red',
             title: 'Alert!',
             content: 'Some problem occure.Please try again.',
            });
        } 
        
        //--------------------------------Commission Based--------------------------//
        $("#total_dockets").val(response['total_settlement']['total_dockets']);
        $("#total_expense").val(response['total_settlement']['total_expense']);
        $("#levy_total").val(response['total_settlement']['levy_total']);
        $("#no_of_whl").val(response['total_settlement']['no_of_whl_com']);
        $("#accident_installment").val(response['total_settlement']['accident_installment_com']);
        $("#bond_total").val(response['total_settlement']['bond_total_com']);
        $("#other").val(response['total_settlement']['other_com']);
        $("#amount_due").val(response['total_settlement']['amount_due_com']);
        $("#discount").val(response['total_settlement']['discount_com']);
        $("#total").val(response['total_settlement']['total_com']);
        
        //--------------------------------Rental Based--------------------------//
        $("#total_dockets_rental").val(response['total_settlement']['total_dockets']);
        $("#total_expense_rental").val(response['total_settlement']['total_expense']);
        $("#levy_total_rental").val(response['total_settlement']['levy_total']);
        $("#no_of_whl_rental").val(response['total_settlement']['no_of_whl_rental']);
        $("#accident_installment_rental").val(response['total_settlement']['accident_installment_rental']);
        $("#bond_total_rental").val(response['total_settlement']['bond_total_rental']);
        $("#other_rental").val(response['total_settlement']['other_rental']);
        $("#amount_due_rental").val(response['total_settlement']['amount_due_rental']);
        $("#discount_rental").val(response['total_settlement']['discount_rental']);
        $("#total_rental").val(response['total_settlement']['total_rental']);
        
        if(!(Number($("#rental_hidden").val()))){
            $("#amount_due_rental").val('0.00');
        }
        if(!(Number($("#rental_hidden").val()))){
            $("#payment_collection_div").text(($("#amount_due").val() < 0)?'Payment Mode':'Payment Collection Mode');
            $("#final_due_amount").text($("#amount_due").val());
            $("#final_due_amount_hid").val($("#amount_due").val());
        }else{
            $("#payment_collection_div").text(($("#amount_due_rental").val() < 0)?'Payment Mode':'Payment Collection Mode');
            $("#final_due_amount").text($("#amount_due_rental").val());
            $("#final_due_amount_hid").val($("#amount_due_rental").val());
        }
        
           
            },
      error:function(response){6
         $.alert({
             type: 'red',
             title: 'Alert!',
             content: 'ERROR',
          });
      }
    });

  }
  

    })
    $(document).on('change','.docket_upload_image_btn',function(e){
		  var upload_option = $(this).val();
      var data_id = $('option:selected',this).data('id');
      //alert(data_id);
      if(upload_option == 'C'){
        $("#startbutton").attr("data-button_id",data_id);
        $('.contentarea').show();
        $("#docket_image_file_"+data_id).hide();
      } else if(upload_option == 'F'){
        $("#startbutton").attr("data-button_id","");
        $('.contentarea').hide();
        $("#docket_image_file_"+data_id).show();
      } else{
        $("#startbutton").attr("data-button_id","");
        $('.contentarea').hide();
        $("#docket_image_file_"+data_id).hide(); 
      }
      
		});
    $(document).on('click','#add_more_docket,.delete_btn',function(){
      $('.contentarea').hide();
    });
    
    var expense_key = "<?=isset($expense_key)?$expense_key + 1:0?>";
    $("#add_more_expense").click(function(){expense_key++;
         

         var resultHTML =`<tr class="driver_expenses_tr">                                  
                         <td>
                           <select  class="expense_cls js-select2" name="expense_id[]" data-show-subtext="true" data-live-search="true">
                             <option value="">Select Expense</option>
                             <?php if(!empty($expense_list)): ?>
                             <?php   foreach($expense_list as $list): ?>
                               <option value="<?php echo $list['expense_id'];?>"><?php echo $list['expense_name'];?></option>
                             <?php   endforeach; ?>
                             <?php endif; ?>
                           </select>
                         </td>
                         <td>
                           
                         <select class="expense_upload_image_btn">
                              <option value="" data-id="`+expense_key+`">Select</option>
                              <option value="C" data-id="`+expense_key+`">Camera</option>
                              <option value="F" data-id="`+expense_key+`">File</option>
                            </select>
                            
                            <input type="hidden" id="expense_image_`+expense_key+`"  class="expense_image">
                            <input type="file" id="expense_image_file_`+expense_key+`" name="" class="expense_image_file" style="display:none;">

                            <a id="expense_uploaded_a_`+expense_key+`" data-fancybox data-caption="Expense IMAGE">
                              <img id="expense_uploaded_img_`+expense_key+`" alt="The screen capture will appear in this box." height="50px" width="50px" style="display:none;"> 
                            </a> 
                             
                           
                         </td>
                         <td class="td_amount_right driver_expense_price">
                             
                         <div class="input-group">
                                 <div class="input-group-prepend expense_price_inp">
                                     <span class="input-group-text" id="basic-addon1">$</span>
                                 </div>
                             <div style="display:none;" class="expense_price_div"></div>
                             <input type="hidden" class="expense_identification_id" value="">
                             <input class="form-control expense_price_inp decimal_validation_cls expense_price_val" type="text" name="expense_price"  value="" style="width:65%">
                         </div>
                         

                         </td>
                         <td class="text-center">
                           <label class="chk_custom_box">
                             <input type="checkbox" id="" class="driver_expense_save">
                             <span class="checkmark"></span>
                           </label>
                           <button type="button" class="btn btn-danger btn-sm delete_btn_expense"><span><i class="fa fa-trash" aria-hidden="true"></i></span></button>
                         </td>
                         
                     </tr>`; 

                     $("#driver_expense_tbody").append(resultHTML);
                     $(".js-select2").select2();

   
   })
   $(document).on('click','.delete_btn_expense',function(){
     $(this).parents('.driver_expenses_tr').remove();
   })

   $(document).on('change','.expense_upload_image_btn',function(e){
		  var upload_option = $(this).val();
      var data_id = $('option:selected',this).data('id');
      //alert(data_id);
      if(upload_option == 'C'){
        $("#startbutton1").attr("data-button_id",data_id);
        $('.contentarea1').show();
        $("#expense_image_file_"+data_id).hide();
      } else if(upload_option == 'F'){
        $("#startbutton1").attr("data-button_id","");
        $('.contentarea1').hide();
        $("#expense_image_file_"+data_id).show();
      } else{
        $("#startbutton1").attr("data-button_id","");
        $('.contentarea1').hide();
        $("#expense_image_file_"+data_id).hide(); 
      }
      
		});
    $(document).on('click','#add_more_expense,.delete_btn_expense',function(){
      $('.contentarea1').hide();
    });


</script>