<script>
<?php if ($page_name == '') { ?>

  <?php } ?>

  function get_branch_id() {
    return $('#company_branch :selected').val();
  }
  <?php if ($page_name == 'work_summary') { ?>
    function GetStartDate() {
      return $('#table_filter_start_date').val();
    }
    function GetEndDate() {
      return $('#table_filter_end_date').val();
    }
    <?php } ?>
    var creditors_view_table = $('#creditors_view_table').DataTable({
      "ajax": {
        url: "<?php echo base_url() . 'accounts/select_creditors_list' ?>", // json datasource
        type: "post", // type of method  , by default would be get
        data: function(d) {
          <?php if (!empty($this->config->item('company_branches'))) { ?>
            d.branch_id = get_branch_id();
            <?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 } ?>
            }
          },
          "bProcessing": true,
          "deferRender": true,
          "bDeferRender": true,
          "scrollX": true,
          buttons: [{
            extend: 'print',
            className: 'btn dark btn-outline',
            exportOptions: {
              columns: ':visible'
            },
            title: 'Creditors List'
          },
          {
            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 (empty($this->config->item('company_branches'))) { echo ",1"; }?> ],
          className: "hidden"
        }],
        'order': []
      });
      $(".table_filter").on("change", function() {
        creditors_view_table.ajax.reload();
      });
    </script>
