<script>

$('#acc_from').on("change", function(e) {
  var acc_id = $('#acc_from :selected').val();
  $('#acc_to').html('');
  $('#acc_to').append("<option selected disabled>Select Account</option>");
  var account_type = {};
  account_type[0] = 32;
  account_type[1] = 36;
  $.post("<?php echo base_url() ?>accounts/select_heads_2",{account_type:account_type},function(data) {
    var obj = $.parseJSON(data);
    var length = obj.count;
    var i=0;
    if(length>0) {
      while (i < length) {
        if(obj.id[i]!=acc_id){
          $('#acc_to').append("<option value=" + obj.id[i] + ">" + obj.name[i] + "</option>");
        }
        i++;
      }
    }
    if(acc_id!=1){
      // $('#acc_to').append("<option value='1'>Cash Account</option>");
    }
  })
  $('#acc_to').trigger('change');
});

$("#paid_date,#paid_date_edit").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 } ?>
  })
  $("#payment_mode_add").select2({
    dropdownParent: $("#form_account_transfer_add"),
    placeholder: "Select Payment Mode"
  })
  $("#acc_from").select2({
    placeholder: "Select Account From",
    dropdownParent: $("#form_account_transfer_add")
  })
  $("#acc_to").select2({
    placeholder: "Select Account To",
    dropdownParent: $("#form_account_transfer_add")
  })

  $("#payment_mode_edit").select2({
    dropdownParent: $("#form_account_transfer_edit"),
    placeholder: "Select Payment Mode"
  })
  $("#acc_from_edit").select2({
    placeholder: "Select Account From",
    dropdownParent: $("#form_account_transfer_edit")
  })
  $("#acc_to_edit").select2({
    placeholder: "Select Account To",
    dropdownParent: $("#form_account_transfer_edit")
  })

</script>
<script>
$('body').on('click', '#acc_transfer_edit_btn', function() {
  var no = $(this).closest('tr').children('td');
  $('#to_id').val(no.eq(12).text());
  $('#acc_from_edit').val(no.eq(11).text()).trigger('change');
  // $('#acc_to_edit').val(no.eq(12).text()).trigger('change');
  $('#paid_amount_edit').val(no.eq(4).text());
  $('#paid_date_edit').datepicker("setDate",no.eq(5).text());
  $('#payment_mode_edit').val(no.eq(6).text()).trigger('change');
  $('#tr_remarks_edit').val(no.eq(7).text());
  $('#transaction_id_edit').val(no.eq(1).text());
});
$('#acc_from_edit').on("change", function(e) {
  var acc_id = $('#acc_from_edit :selected').val();
  $('#acc_to_edit').html('');
  $('#acc_to_edit').append("<option selected disabled>Select Account</option>");
  var account_type = {};
  account_type[0] = 32;
  account_type[1] = 36;
  $.post("<?php echo base_url() ?>accounts/select_heads_2",{account_type:account_type},function(data) {
    var obj = $.parseJSON(data);
    var length = obj.count;
    var i=0;
    var to_id2 = $('#to_id').val();
    if(length>0) {
      while (i < length) {
        if(obj.id[i]!=acc_id){
          $('#acc_to_edit').append("<option value=" + obj.id[i] + ">" + obj.name[i] + "</option>");
        }
        $('#acc_to_edit').val(to_id2).trigger('change');
        i++;
      }
    }
    if(acc_id!=1){
      // $('#acc_to_edit').append("<option value='1'>Cash Account</option>");
    }
  })
  // $('#acc_to_edit').trigger('change');
});
$('body').on('click', '#acc_transfer_delete_btn', function() {
  var no = $(this).closest('tr').children('td');
  $('#tr_id_delete').val(no.eq(1).text());
})



function GetSearchStatus(){
  return $('#table_filter_status').val();
}
<?php if($page_name=='data_entry_approval'){?>
  function GetStartDate(){
    return $('#table_filter_start_date').val();
  }
  function GetEndDate(){
    return $('#table_filter_end_date').val();
  }
  function GetSearchWork(){
    return $('#table_filter_work').val();
  }
  function GetSearchUser(){
    return $('#table_filter_user').val();
  }
  function GetSearchApprovalStatus(){
    return $('#table_filter_approval_status').val();
  }
  function GetSearchAccount() {
    return $('#table_filter_account').val();
  }
  <?php } ?>
  <?php
  $page_type='';
  if($page_name=='data_entry_approval'){
    $page_type='approval_entries';
  }
  ?>
  var acc_transfer_view_table = $('#acc_transfer_view_table').DataTable({
    "ajax":{
      url :"<?php echo base_url().'accounts/select_transfer/'.$page_type ?>", // json datasource
      type: "post", // type of method  , by default would be get
      data: function(d){
        <?php if($page_name=='data_entry_approval'){?>
          d.start_date = GetStartDate();
          d.end_date = GetEndDate();
          d.work = GetSearchWork();
          d.approval_status = GetSearchApprovalStatus();
          d.created_by = GetSearchUser();
          d.acc_head_id = GetSearchAccount();
          <?php } ?>
        }
      },
      "bProcessing": true,
      "deferRender": true,
      "bDeferRender": true,
      "scrollX" : true,
      buttons: [
        { extend: 'print', className: 'btn dark btn-outline',exportOptions: {columns: ':visible'},title: 'Account Transfer Report' },
        { 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>>",
      "lengthMenu": [
        [25, 50, 100, -1],
        [25, 50, 100, "All"] // change per page values here
      ],
      // set the initial value
      "pageLength": 25,
      "columnDefs": [
        {
          "targets": [<?php if($this->session->userdata('user_role')=='auditor'){ echo "10,"; } ?>11,12,13 ],
          className: "hidden"
        }
      ],
      'order': [1,'desc'],
      "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
        if(aData[13]=='0'){
          $('td', nRow).css('background-color', '#ffcccc');
        }else if(aData[13]=='2'){
          $('td', nRow).css('background-color', '#ffcccc');
        }
      }
    });
    $(".table_filter").on("change", function() {
      acc_transfer_view_table.ajax.reload();
    });
    $(".hide_column").hide();
  </script>
