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

  function GetSearchDate() {
    return $('#table_filter_date_range').val();
  }

  function GetSearchWork() {
    return $('#table_filter_work').val();
  }

  function GetSearchWorktype() {
    return $('#table_filter_work_type').val();
  }
  function GetSearchContractor() {
    return $('#table_filter_contractor').val();
  }
  function get_branch_id() {
    return $('#company_branch :selected').val();
  }

  <?php } ?>
  <?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();
    }
    <?php } ?>
    <?php
    $page_type = '';
    if ($page_name == 'data_entry_approval') {
      $page_type = 'approval_entries';
    }
    ?>
    var bill_labour_wage_view_table = $('#bill_labour_wage_view_table').DataTable({
      "ajax": {
        url: "<?php echo base_url() . 'subcontracts/select_subcontract_bill_labours/' . $page_type ?>", // json datasource
        type: "post", // type of method  , by default would be get
        data: function(d) {
          <?php if ($page_name == 'subcontract_profile') { ?>
            d.contract_id = "<?php echo $subcontract_data->contract_id ?>";
            <?php } ?>
            <?php if ($page_name == 'subcontract_payments') { ?>
              d.date = GetSearchDate();
              d.work = GetSearchWork();
              d.contractor = GetSearchContractor();
              d.work_type = GetSearchWorktype();
              <?php if (!empty($this->config->item('company_branches'))) { ?>
                d.branch_id = get_branch_id();
                <?php } ?>
                <?php } ?>
                <?php if ($page_name == 'data_entry_approval') { ?>
                  d.start_date = GetStartDate();
                  d.end_date = GetEndDate();
                  d.work = GetSearchWork();
                  d.approval_status = GetSearchApprovalStatus();
                  d.user_id = GetSearchUser();
                  <?php } ?>
                }
              },
              "bProcessing": true,
              "deferRender": true,
              "bDeferRender": true,
              "scrollX": true,
              buttons: [{
                extend: 'print',
                className: 'btn dark btn-outline',
                exportOptions: {
                  columns: ':visible'
                },
                title: 'Subcontract Bill Labour Report',
                <?php if($this->config->item('company_letter_head')!=''){ ?>
                  customize: function ( win ) {
                    $(win.document.body).prepend(
                      '<img src="<?php echo base_url().'uploads/company/'.$this->config->item('company_letter_head')?>" style="top:0; left:0;width:100%;" />'
                    );
                  }
                  <?php } ?>
                },
                {
                  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
              ],
              "columnDefs": [{
                "targets": [],
              className: "hidden"
            }],
            'order': false,

          });

        </script>
