<script>
<?php if($page_name=='expense_bills'){?>
  $("#table_filter_work").select2({
    placeholder: "Select  Work",
    templateResult: format_project_dropdown
  })
  <?php } ?>
  $("#table_filter_expense_type").select2({
    placeholder: "Select  Expense Head"
  })
  $("#table_filter_expense_head").select2({
    placeholder: "Select  Expense Head"
  })


  $("#expense_bill_paid_date_add,#expense_bill_paid_date_edit,#expense_bill_reference_date_add,#expense_bill_date_add").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 } ?>
    })
    $('body').on('change', '#expense_bill_payment_mode_add', function() {
      var payment_mode=$('#expense_bill_payment_mode_add :selected').val();
      if(payment_mode=='POST DATED CHEQUE'){
        $('#expense_bill_paid_date_add').datepicker('destroy');
        $("#expense_bill_paid_date_add").datepicker( {
          todayHighlight:!0, orientation:"bottom left", templates: {
            leftArrow: '<i class="la la-angle-left"></i>', rightArrow: '<i class="la la-angle-right"></i>'
          },
          <?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 } ?>
          })
        }else{
          $('#expense_bill_paid_date_add').datepicker('destroy');
          $("#expense_bill_paid_date_add").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 select_expense_head(select_id,type=''){
          $('#'+select_id).html('');
          if(type=='filter'){
            $("#"+select_id).append("<option value='all' selected >All Expense Heads</option>");
          }else{
            $("#"+select_id).append("<option disabled selected >Select Expense Head</option>");
          }
          $.post("<?php echo base_url() ?>accounts/select_heads_2",{account_type:11},function(data) {
            var obj = $.parseJSON(data);
            var i=0;
            if(obj.count>0) {
              while (i < obj.id.length) {
                $("#"+select_id).append("<option value=" + obj.id[i] + ">" + obj.name[i] + "</option>");
                i++;
              }
            }
          })
        }

        select_expense_head("table_filter_expense_head",'filter');
        select_expense_head("expense_head_add");
        select_expense_head("expense_head_edit");
        select_expense_head("expense_head_add_2");

        $("#expense_head_add").select2({
          placeholder: "Select Expense Head",
          dropdownParent: $("#form_expense_bill_add")
        })
        $("#expense_head_add_2").select2({
          placeholder: "Select Expense Head",
          dropdownParent: $("#form_local_material_purchase_bill_add")
        })
        $("#expense_bill_tax_percent_add").select2({
          placeholder: "Select Tax %",
          dropdownParent: $("#form_expense_bill_add")
        })
        $("#expense_bill_debit_acc_add").select2({
          placeholder: "Select Debit Account",
          dropdownParent: $("#form_expense_bill_add")
        })
        $("#expense_bill_payment_mode_add").select2({
          placeholder: "Select Debit Account",
          dropdownParent: $("#form_expense_bill_add")
        })
        $("#expense_bill_work_add").select2({
          placeholder: "Select Work",
          dropdownParent: $("#form_expense_bill_add"),
          templateResult: format_project_dropdown
        })

        $("#expense_bill_work_edit").select2({
          placeholder: "Select Work",
          dropdownParent: $("#form_expense_bill_edit"),
          templateResult: format_project_dropdown
        })
        $("#expense_bill_tax_percent_edit").select2({
          placeholder: "Select Tax %",
          dropdownParent: $("#form_expense_bill_edit")
        })
        $("#expense_bill_debit_acc_edit").select2({
          placeholder: "Select Debit Account",
          dropdownParent: $("#form_expense_bill_edit")
        })
        $("#expense_head_edit").select2({
          placeholder: "Select Expense Head",
          dropdownParent: $("#form_expense_bill_edit")
        })

        <?php if($page_name=='work_profile'){?>
          var work_id = "<?php echo $work_data->work_id ?>";
          $("#expense_bill_work_add").val(work_id).trigger('change');
          $("#expense_bill_work_div_add").show();
          $("#expense_bill_work_add").attr('required',true);

          $("#expense_bill_work_edit").val(work_id).trigger('change');
          $("#expense_bill_work_div_edit").show();
          $("#expense_bill_work_edit").attr('required',true);
          <?php } ?>
          $('input[type=radio][name=expense_type]').change(function() {
            if (this.value == 'work') {
              $("#expense_bill_work_div_add").show();
              $("#expense_bill_work_add").attr('required',true);
            }else{
              $("#expense_bill_work_div_add").hide();
              $("#expense_bill_work_add").removeAttr('required',true);
            }
          });
          $('input[type=radio][name=expense_type_edit]').change(function() {
            if (this.value == 'work') {
              $("#expense_bill_work_div_edit").show();
              $("#expense_bill_work_edit").attr('required',true);
            }else{
              $("#expense_bill_work_div_edit").hide();
              $("#expense_bill_work_edit").removeAttr('required',true);
            }
          });
          function calculate_expense_bill_balance(form_type='',field=''){
            if(form_type=='edit'){
              var tax_percent = parseFloat($('#expense_bill_tax_percent_edit :selected').data('tax-percent'));
              var bill_amount = parseFloat(($("#expense_bill_amount_edit").val()=='') ? 0 : parseFloat($("#expense_bill_amount_edit").val()));
              var tax_amount = bill_amount*tax_percent/100;
              $("#expense_bill_tax_amount_edit").val(tax_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
              var payable_amount = parseFloat(bill_amount+tax_amount);
              $("#expense_bill_payable_amount_edit").val(payable_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
              var paid_amount = ($("#expense_bill_total_paid_edit").val()=='') ? 0 : parseFloat($("#expense_bill_total_paid_edit").val());
              $("#expense_bill_balance_edit").val((payable_amount-paid_amount).toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
            }else{
              var tax_percent = parseFloat($('#expense_bill_tax_percent_add :selected').data('tax-percent'));
              var bill_amount = parseFloat(($("#expense_bill_amount_add").val()=='') ? 0 : parseFloat($("#expense_bill_amount_add").val()));
              var tax_amount = bill_amount*tax_percent/100;
              $("#expense_bill_tax_amount_add").val(tax_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
              var payable_amount = parseFloat(bill_amount+tax_amount);
              $("#expense_bill_payable_amount_add").val(payable_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
              if(field!='expense_bill_paid_amount_add'){
                $("#expense_bill_paid_amount_add").val($('#expense_bill_payable_amount_add').val());
              }
              $("#expense_bill_paid_amount_add").attr('max',$('#expense_bill_payable_amount_add').val());
              if($("#expense_bill_paid_amount_add").val()>0){
                $(".expense_bill_paid_amount_req_fields").attr('required',true);
              }else{
                $(".expense_bill_paid_amount_req_fields").removeAttr('required',true);
              }
              var paid_amount = ($("#expense_bill_paid_amount_add").val()=='') ? 0 : parseFloat($("#expense_bill_paid_amount_add").val());
              $("#expense_bill_balance_amount_add").val((payable_amount-paid_amount).toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
            }
          }
          $('body').on('change keyup', '#expense_bill_paid_amount_add', function() {
            var value = $(this).val();
            // if(value=="" || value==null){
            //   $(this).val(0)
            // }
            if($(this).val()>0){
              $(".expense_bill_paid_amount_req_fields").attr('required',true);
            }else{
              $(".expense_bill_paid_amount_req_fields").removeAttr('required',true);
            }
            calculate_expense_bill_balance('add','expense_bill_paid_amount_add');
          })
          $('body').on('change keyup', '.expense_bill_amount_fields_add', function() {
            var value = $(this).val();
            // if(value=="" || value==null){
            //   $(this).val(0);
            // }

            calculate_expense_bill_balance('add');
          })
          $('body').on('change keyup', '#expense_bill_date_add', function() {
            $("#expense_bill_paid_date_add").datepicker("setDate",$(this).val());
          })

          $('body').on('change keyup', '.expense_bill_amount_fields_edit', function() {
            var value = $(this).val();
            // if(value=="" || value==null){
            //   $(this).val(0)
            // }
            calculate_expense_bill_balance('edit');
          })
          $('body').on('click', '#expense_bill_edit_btn', function() {
            $("#expense_bill_attachment_delete_status").val(0);
            var no = $(this).closest('tr').children('td');
            $('#expense_bill_id_edit').val(no.eq(29).text());
            $('#expense_bill_date_edit').datepicker("setDate", no.eq(2).text());
            var expense_type=no.eq(3).text();
            if(expense_type=="Office Expense"){
              expense_type = "office";
              $("#expense_bill_work_div_edit").hide();
              $("#expense_bill_work_edit").removeAttr('required',true);
            }else{
              expense_type = "work";
              $('#expense_bill_work_edit').val(no.eq(28).text()).trigger('change');
              $("#expense_bill_work_div_edit").show();
              $("#expense_bill_work_edit").attr('required',true);
            }
            $("input[name=expense_type_edit][value=" + expense_type + "]").prop('checked', true);
            $('#expense_bill_no_edit').val(no.eq(5).text());
            $('#expense_bill_consignee_edit').val(no.eq(6).text());
            $("#expense_bill_tax_no_edit").val(no.eq(7).text());
            $('#expense_bill_payable_amount_edit').val(no.eq(16).text());
            $('#expense_bill_description_edit').val(no.eq(20).text());
            $('#expense_bill_remarks_edit').val(no.eq(21).text());
            $('#expense_head_edit').val(no.eq(27).text()).trigger('change');
            $('#expense_bill_total_paid_edit').val(no.eq(17).text());
            $('#expense_bill_balance_edit').val(no.eq(18).text());
            $('#expense_bill_tax_percent_edit').val(no.eq(31).text()).trigger('change');
            var tax_amount=parseFloat(no.eq(32).text());
            var payable_amount=parseFloat(no.eq(16).text());
            var bill_amount = parseFloat(payable_amount-tax_amount);
            $('#expense_bill_amount_edit').val(bill_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
            var file = no.eq(30).text();
            if(file!=''){
              var file_data='<tr>'+
              '<td><a style="word-break: break-all" target="_blank" href="'+file+'" style="margin-left: 5px;margin-right: 5px" >'+file+'</a></td>'+
              '<td><a style="margin-left: 5px;margin-right: 5px" id="expense_bill_attachment_item_delete_btn" href="javascript:;" class="btn btn-sm btn-danger m-btn m-btn--icon  m-btn--pill m-btn--air"><i class="la la-trash"></i> Change</a></td>'+
              '</tr>';
              $("#expense_bill_edit_file_table_body").html(file_data);
              $("#expense_bill_edit_file_table").show();
              $("#expense_bill_edit_file_upload").hide();
            }else{
              $("#expense_bill_edit_file_table").hide();
              $("#expense_bill_edit_file_upload").show();
            }
            calculate_expense_bill_balance('edit');
          })
          $('body').on('click', '#expense_bill_attachment_item_delete_btn', function() {
            $("#expense_bill_edit_file_table").hide();
            $("#expense_bill_edit_file_upload").show();
            $("#expense_bill_attachment_delete_status").val(1);
          })


          function GetSearchexpensehead(){
            return $('#table_filter_expense_head').val();
          }
          <?php if ($page_name == 'work_summary') { ?>
            function GetStartDate() {
              return $('#table_filter_start_date').val();
            }
            function GetEndDate() {
              return $('#table_filter_end_date').val();
            }
            <?php } ?>
            <?php if($page_name=='expense_bills'){?>
              function GetSearchexpensetype(){
                return $('#table_filter_expense_type').val();
              }
              function GetSearchStatus(){
                return $('#table_filter_status').val();
              }
              function GetSearchDate(){
                return $('#table_filter_date_range').val();
              }
              function GetSearchWork(){
                return $('#table_filter_work').val();
              }
              <?php } ?>
              <?php if($page_name=='user_profile'){?>
                function GetStartDate(){
                  return $('#table_filter_start_date').val();
                }
                function GetEndDate(){
                  return $('#table_filter_end_date').val();
                }
                <?php } ?>
                <?php if($page_name=='data_entry_approval' || $page_name=='data_entry_approval_2_level'){?>
                  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';
                  }elseif($page_name=='data_entry_approval_2_level'){
                    $page_type='approval_entries_2_level';
                  }
                  ?>
                  var expense_bills_view_table = $('#expense_bills_view_table').DataTable({
                    "ajax":{
                      url :"<?php echo base_url().'expense/select_expense_bills/'.$page_type ?>", // json datasource
                      type: "post", // type of method  , by default would be get
                      data: function(d){
                        <?php if($page_name=='expense_bills'){?>
                          d.date = GetSearchDate();
                          d.expense_head = GetSearchexpensehead();
                          d.expense_type = GetSearchexpensetype();
                          d.work = GetSearchWork();
                          <?php } ?>
                          <?php if($page_name=='data_entry_approval' || $page_name=='data_entry_approval_2_level'){?>
                            d.start_date = GetStartDate();
                            d.end_date = GetEndDate();
                            d.work = GetSearchWork();
                            d.approval_status = GetSearchApprovalStatus();
                            d.created_by = GetSearchUser();
                            <?php } ?>
                            <?php if($page_name=='work_profile' || $page_name=='work_summary'){?>
                              d.work = "<?php echo $work_data->work_id?>";
                              d.expense_head = GetSearchexpensehead();
                              <?php } ?>
                              <?php if($page_name=='work_profile_master' || $page_name=='work_summary_master'){?>
                                d.work_ids = "<?php echo implode(',',$sub_project_ids)?>";
                                <?php } ?>
                              <?php if($page_name=='supplier_profile'){?>
                                d.bill_supplier_id = "<?php echo $supplier_data->supplier_id?>";
                                <?php } ?>
                                <?php if($page_name=='work_summary'){?>
                                  d.start_date = GetStartDate();
                                  d.end_date = GetEndDate();
                                  <?php } ?>
                                  <?php if($page_name=='reports_activity'){?>
                                    d.date = GetSearchDate();
                                    d.work = GetSearchWork();
                                    <?php } ?>
                                    <?php if($page_name=='user_profile'){?>
                                      d.user_id = "<?php echo $user_data->user_id?>";
                                      d.start_date = GetStartDate();
                                      d.end_date = GetEndDate();
                                      <?php } ?>
                                      <?php if($page_name=='stage_profile' || $page_name=='stage_summary'){?>
                                        d.stage_id = "<?php echo $stage_data->stage_id?>";
                                        <?php } ?>
                                      }
                                    },
                                    "bProcessing": true,
                                    "deferRender": true,
                                    "bDeferRender": true,
                                    <?php if($page_name=='work_summary'){?>
                                      "scrollX": false,
                                      bFilter: false,
                                      "bLengthChange": false,
                                      "bPaginate": false,
                                      "bInfo": false,
                                      buttons: [
                                        { extend: 'colvis', className: 'btn dark btn-outline', text: 'Columns'}
                                      ],
                                      "dom": "<'row' <'col-md-12'B>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>", // horizobtal scrollable datatable
                                      <?php }else{?>
                                        "scrollX" : true,
                                        buttons: [
                                          { extend: 'print', className: 'btn dark btn-outline',exportOptions: {columns: ':visible'},title: 'Expense Bills' },
                                          { 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
                                        ],
                                        <?php } ?>
                                        'order': false,
                                        "columnDefs": [
                                          {
                                            "targets": [ 27,28,29,30,31,32,33,34,35<?php if($this->config->item('Tax_tax_splitting')==0){ echo ",10,11,12,13,14,15";}?><?php if($page_name=='work_profile'){ echo ",3"; }?><?php if($page_name=='work_summary'){ echo ",3,19,21,22,23,26"; }?><?php if($page_name=='reports_activity'){ echo ",26"; }?> <?php if($this->session->userdata('user_role')=='auditor' && $this->session->userdata('user_data_permission')['adding']!=1) { echo ",26"; } ?>],
                                            className: "hidden"
                                          }
                                        ],

                                        "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
                                          if(aData[34]=='0'){
                                            $('td', nRow).css('background-color', '#ffcccc');
                                          }else if(aData[34]=='2'){
                                            $('td', nRow).css('background-color', '#ffcccc');
                                          }
                                          if(aData[34]=='1'){
                                            if(aData[35]=='0'){
                                              $('td', nRow).css('background-color', '#F0FAB3');
                                            }else if(aData[35]=='2'){
                                              $('td', nRow).css('background-color', '#ffcccc');
                                            }
                                          }
                                        }
                                      });
                                      var expense_bill_payments_view_table = $('#expense_bill_payments_view_table').DataTable({
                                        "ajax":{
                                          url :"<?php echo base_url().'accounts/select_account_transactions/expense_bill/'.$page_type ?>", // json datasource
                                          type: "post", // type of method  , by default would be get
                                          data: function(d){

                                            <?php if($page_name=='expense_bills'){?>
                                              d.date = GetSearchDate();
                                              d.expense_head = GetSearchexpensehead();
                                              d.expense_type = GetSearchexpensetype();
                                              d.work = GetSearchWork();
                                              <?php } ?>
                                              <?php if($page_name=='data_entry_approval' || $page_name=='data_entry_approval_2_level'){?>
                                                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 } ?>
                                                <?php if($page_name=='work_profile' || $page_name=='work_summary'){?>
                                                  d.work = "<?php echo $work_data->work_id?>";
                                                  d.expense_head = GetSearchexpensehead();
                                                  <?php } ?>
                                                  <?php if($page_name=='work_profile_master' || $page_name=='work_summary_master'){?>
                                                    d.work_ids = "<?php echo implode(',',$sub_project_ids)?>";
                                                    <?php } ?>
                                                  <?php if($page_name=='supplier_profile'){?>
                                                    d.bill_supplier_id = "<?php echo $supplier_data->supplier_id?>";
                                                    <?php } ?>
                                                    <?php if($page_name=='work_summary'){?>
                                                      d.start_date = GetStartDate();
                                                      d.end_date = GetEndDate();
                                                      <?php } ?>
                                                      <?php if($page_name=='reports_activity'){?>
                                                        d.date = GetSearchDate();
                                                        d.work = GetSearchWork();
                                                        <?php } ?>
                                                        <?php if($page_name=='user_profile'){?>
                                                          d.acc_user_id = "<?php echo $user_data->user_id?>";
                                                          d.start_date = GetStartDate();
                                                          d.end_date = GetEndDate();
                                                          <?php } ?>
                                                          <?php if($page_name=='stage_profile' || $page_name=='stage_summary'){?>
                                                            d.stage_id = "<?php echo $stage_data->stage_id?>";
                                                            <?php } ?>
                                                          }
                                                        },
                                                        "bProcessing": true,
                                                        "deferRender": true,
                                                        "bDeferRender": true,
                                                        <?php if($page_name=='work_summary'){?>
                                                          "scrollX": false,
                                                          bFilter: false,
                                                          "bLengthChange": false,
                                                          "bPaginate": false,
                                                          "bInfo": false,
                                                          buttons: [
                                                            { extend: 'colvis', className: 'btn dark btn-outline', text: 'Columns'}
                                                          ],
                                                          "dom": "<'row' <'col-md-12'B>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>", // horizobtal scrollable datatable
                                                          <?php }else{?>
                                                            "scrollX" : true,
                                                            buttons: [
                                                              { extend: 'print', className: 'btn dark btn-outline',exportOptions: {columns: ':visible'},title: 'Expense Bill Transactions' },
                                                              { 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
                                                            ],
                                                            <?php } ?>
                                                            'order': [],
                                                            "columnDefs": [
                                                              {
                                                                "targets": [ 6,7,19,20,21,22,23,24<?php if($page_name=='work_profile'){ echo ",4"; }?><?php if($page_name=='work_summary'){ echo ",1,4,8,9,13,14,15,18"; }?>],
                                                                className: "hidden"
                                                              }
                                                            ],
                                                            "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
                                                              if(aData[23]=='0'){
                                                                $('td', nRow).css('background-color', '#ffcccc');
                                                              }else if(aData[23]=='2'){
                                                                $('td', nRow).css('background-color', '#ffcccc');
                                                              }
                                                              if(aData[23]=='1'){
                                                                if(aData[24]=='0'){
                                                                  $('td', nRow).css('background-color', '#F0FAB3');
                                                                }else if(aData[24]=='2'){
                                                                  $('td', nRow).css('background-color', '#ffcccc');
                                                                }
                                                              }
                                                            }
                                                          });
                                                          var expense_bills_heads_view_table = $('#expense_bills_heads_view_table').DataTable({
                                                            "ajax":{
                                                              url :"<?php echo base_url().'expense/select_expense_bill_heads/' ?>", // json datasource
                                                              type: "post", // type of method  , by default would be get
                                                              data: function(d){
                                                                <?php if($page_name=='expense_bills'){?>
                                                                  d.date = GetSearchDate();
                                                                  d.expense_head = GetSearchexpensehead();
                                                                  d.expense_type = GetSearchexpensetype();
                                                                  d.work = GetSearchWork();
                                                                  <?php } ?>
                                                                  <?php if($page_name=='work_profile' || $page_name=='work_summary'){?>
                                                                    d.work = "<?php echo $work_data->work_id?>";
                                                                    <?php } ?>
                                                                    <?php if($page_name=='work_profile_master' || $page_name=='work_summary_master'){?>
                                                                      d.work_ids = "<?php echo implode(',',$sub_project_ids)?>";
                                                                      <?php } ?>
                                                                    <?php if($page_name=='work_summary'){?>
                                                                      d.start_date = GetStartDate();
                                                                      d.end_date = GetEndDate();
                                                                      <?php } ?>
                                                                    }
                                                                  },
                                                                  "bProcessing": true,
                                                                  "deferRender": true,
                                                                  "bDeferRender": true,
                                                                  <?php if($page_name=='work_summary'){?>
                                                                    "scrollX": false,
                                                                    bFilter: false,
                                                                    "bLengthChange": false,
                                                                    "bPaginate": false,
                                                                    "bInfo": false,
                                                                    buttons: [
                                                                      { extend: 'colvis', className: 'btn dark btn-outline', text: 'Columns'}
                                                                    ],
                                                                    "dom": "<'row' <'col-md-12'B>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>", // horizobtal scrollable datatable
                                                                    <?php }else{?>
                                                                      "scrollX" : true,
                                                                      buttons: [
                                                                        { extend: 'print', className: 'btn dark btn-outline',exportOptions: {columns: ':visible'},title: 'Expense Bill Summary' },
                                                                        { 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
                                                                      ],
                                                                      <?php } ?>
                                                                      'order': false,
                                                                      "columnDefs": [
                                                                        {
                                                                          "targets": [ ],
                                                                          className: "hidden"
                                                                        }
                                                                      ]
                                                                    });
                                                                    $(".table_filter").on("change", function() {
                                                                      expense_bills_view_table.ajax.reload();
                                                                      expense_bill_payments_view_table.ajax.reload();
                                                                      expense_bills_heads_view_table.ajax.reload();
                                                                    });
                                                                    $(".hide_column").hide();

                                                                    <?php if($page_name=='expense_bills'){?>
                                                                      // Date Range Picker
                                                                      var start = moment();
                                                                      var end = moment();

                                                                      function cb(start, end) {
                                                                        $('#table_filter_date_range').val(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
                                                                        expense_bills_view_table.ajax.reload();
                                                                        expense_bill_payments_view_table.ajax.reload();
                                                                        expense_bills_heads_view_table.ajax.reload();
                                                                      }

                                                                      $('#table_filter_date_range').daterangepicker({
                                                                        buttonClasses: "m-btn btn",
                                                                        applyClass: "btn-primary",
                                                                        cancelClass: "btn-secondary",
                                                                        startDate: start,
                                                                        endDate: end,
                                                                        locale: {
                                                                          format: 'MMMM D, YYYY'
                                                                        },
                                                                        ranges: {
                                                                          'Today': [moment(), moment()],
                                                                          'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                                                                          'Last 7 Days': [moment().subtract(6, 'days'), moment()],
                                                                          'Last 30 Days': [moment().subtract(29, 'days'), moment()],
                                                                          'This Month': [moment().startOf('month'), moment().endOf('month')],
                                                                          'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')],
                                                                          'All time': [moment('1970-01-01'), moment().add(9999, 'days')],
                                                                        }
                                                                      }, cb);

                                                                      cb(start, end);


                                                                      $(".form_submit_btn").click(function (e) {
                                                                        e.preventDefault();
                                                                        var a = $(this),
                                                                        l = $(this).closest("form"),
                                                                        action = l.attr('action');
                                                                        var form_id = l.attr('id');
                                                                        l.validate({
                                                                          rules: {
                                                                            paid_amount: {
                                                                              number: !0,
                                                                              required: !0
                                                                            },
                                                                            bill_amount: {
                                                                              number: !0,
                                                                              required: !0
                                                                            }
                                                                          }, invalidHandler: function (e, r) {
                                                                            var i = $("#" + form_id + "_msg");
                                                                            i.removeClass("m--hide").show(), mUtil.scrollTo(i, -200)
                                                                          }, submitHandler: function (e) {
                                                                          }
                                                                        }),
                                                                        // $(".numeric_fields").each(function () {
                                                                        //   $("#"+$(this).attr("id")).rules('add', {
                                                                        //     number: !0
                                                                        //   });
                                                                        // }),
                                                                        l.valid() && (a.addClass("m-loader m-loader--right m-loader--light").attr("disabled", !0),
                                                                        l.ajaxSubmit({
                                                                          url: action,
                                                                          success: function (e, t, r, s) {
                                                                            var modal_id = l.attr('data-modal-id');
                                                                            var form_type = l.attr('data-form-type');
                                                                            $("#" + form_id + "_msg").addClass("m--hide");
                                                                            // Block UI
                                                                            mApp.blockPage({
                                                                              overlayColor: "#000000",
                                                                              type: "loader",
                                                                              state: "success",
                                                                              message: "Please wait..."
                                                                            }), setTimeout(function () {
                                                                              mApp.unblockPage()
                                                                            }, 2e3);
                                                                            var obj = $.parseJSON(e);
                                                                            if (obj.status == 1) {
                                                                              a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
                                                                              toastr[obj.flashdata_type](obj.flashdata_msg, obj.flashdata_title);
                                                                              $("#"+modal_id).modal('toggle');
                                                                              $("."+form_id+"_fields").val('');
                                                                              $("."+form_id+"_select").val('').trigger("change");
                                                                              // $("#"+form_id).trigger("reset");
                                                                              // $("#"+form_id)[0].reset();
                                                                              // $("#"+form_id).get(0).reset();
                                                                              $(".custom-file-label").text("Choose file");
                                                                              $('input[type=radio]').prop('checked', false);
                                                                              $("#expense_bill_work_div_add").hide();
                                                                              $("#expense_bill_work_add").removeAttr('required',true);
                                                                              if(form_id=="form_expense_head_add"){
                                                                                select_expense_head("expense_head_add");
                                                                                select_expense_head("expense_head_edit");
                                                                                select_expense_head("table_filter_expense_head",'filter');
                                                                              }else{
                                                                                expense_bills_view_table.ajax.reload();
                                                                                expense_bill_payments_view_table.ajax.reload();
                                                                                expense_bills_heads_view_table.ajax.reload();
                                                                              }
                                                                              $('#table_body_local_purchase_items').html('');
                                                                              $('#current_row_count_local_purchase_items').val(0);
                                                                            } else {
                                                                              a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
                                                                              toastr[obj.flashdata_type](obj.flashdata_msg, obj.flashdata_title);
                                                                            }
                                                                            if (obj == null) {
                                                                              setTimeout(function () {
                                                                                a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
                                                                                toastr["warning"]("Your Attempt is Timed Out. Please Try Again.", "Timed Out");
                                                                              }, 2e4)
                                                                            }
                                                                          },error: function() {
                                                                            a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
                                                                            toastr["error"]("Sorry. There Has Been Some Error Occurred. Please Try Again.", "Error");
                                                                          }
                                                                        })
                                                                      )
                                                                    });
                                                                    <?php } ?>
                                                                    </script>
                                                                    <?php if($this->config->item('Expense_local_material_purchase')==1){?>
                                                                      <?php $this->view("modules/include_scripts/local_material_purchase_scripts");?>
                                                                    <?php } ?>
