<script>

$("#labour_add_insurance_fd_payment").select2({
  placeholder: "Select Labour",
  dropdownParent: $("#form_insurance_fd_payment_add")
})
$("#debit_acc_add_insurance_fd_payment").select2({
  placeholder: "Select TR Account",
  dropdownParent: $("#form_insurance_fd_payment_add")
})
$("#payment_mode_add_insurance_fd_payment").select2({
  placeholder: "Select TR Mode",
  dropdownParent: $("#form_insurance_fd_payment_add")
})

$("#paid_date_add_insurance_fd_payment,#reference_date_add_insurance_fd_payment,#paid_date_edit_insurance_fd_payment,#reference_date_edit_insurance_fd_payment,#received_date_add_receive_payment").datepicker( {
  todayHighlight:!0, orientation:"bottom left", templates: {
    leftArrow: '<i class="la la-angle-left"></i>', rightArrow: '<i class="la la-angle-right"></i>'
  },
  endDate: '+0d',
  <?php if($this->session->userdata('user_role')!='admin' && $this->config->item('User_calendar_date_restriction_enabled')==1){ ?>
    startDate: '<?php echo $this->config->item('User_calendar_date_restriction_start_days');?>d'
    <?php } ?>
  })

  function get_labour_details(){
    <?php if($page_name=='labour_profile'){ ?>
    var labour_id="<?php echo $labour_data->labour_id?>";
    <?php }else{ ?>
      var labour_id=$('#labour_add_insurance_fd_payment :selected').val();
      <?php } ?>
    var labour_payment_type = $("input[type=radio][name=labour_payment_type]:checked").val();
    $('#reference_id_add_insurance_fd_payment').val(labour_id);
    if(labour_payment_type!='' && labour_payment_type!=null){
      $.post("<?php echo base_url() ?>labours/select_details",{labour_id:labour_id,labour_payment_type:labour_payment_type},function(data) {
        var obj = $.parseJSON(data);
        var i=0;
        if(obj.count==1) {
          if(labour_payment_type=='insurance'){
            $("#labour_insurance_fd_balance_add").val(obj.total_insurance_balance);
          }else{
            $("#labour_insurance_fd_balance_add").val(obj.total_fd_balance);
          }
        }
      })
    }

  }
  $('body').on('change', '#labour_add_insurance_fd_payment', function() {
    get_labour_details();
  })
  $('input[type=radio][name=labour_payment_type]').change(function() {
      get_labour_details();
  })

  var labour_insurance_fd_payments_view_table = $('#labour_insurance_fd_payments_view_table').DataTable({
    "ajax":{
      url :"<?php echo base_url().'accounts/select_account_transactions/labour_insurance_fd/'?>", // json datasource
      type: "post", // type of method  , by default would be get
      data: function(d){
        <?php if($page_name=='labour_profile'){?>
          d.labour = "<?php echo $labour_data->labour_id?>";
          <?php } ?>
        }
      },
      "bProcessing": true,
      "deferRender": true,
      "bDeferRender": true,
      "scrollX" : true,
      buttons: [
        { extend: 'print', className: 'btn dark btn-outline',exportOptions: {columns: ':visible'},title: 'Labour Insurance, FD Payments' },
        { extend: 'csv', className: 'btn purple btn-outline ' },
        { extend: 'colvis', className: 'btn dark btn-outline', text: 'Columns'}
      ],
      dom:"<'row'<'col-sm-6 text-left'B><'col-sm-6 text-right'f>>\n\t\t\t<'row'<'col-sm-12'tr>>\n\t\t\t<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7 dataTables_pager'lp>>", // horizobtal scrollable datatable
      "lengthMenu": [
        [25, 50, 100, -1],
        [25, 50, 100, "All"] // change per page values here
      ],
      // set the initial value
      "pageLength": 25,
      "columnDefs": [
        {
          "targets": [ 3,6,7,8,19,20,21,22,23],
          className: "hidden"
        }
      ],
      'ordering': false
    });
  </script>
