<script>

      <?php
      $page_type = '';
      if ($page_name == 'data_entry_approval') {
        $page_type = 'approval_entries';
      }
      ?>
      var proforma_invoices_view_table = $('#proforma_invoices_view_table').DataTable({
        "ajax": {
          url: "<?php echo base_url() . 'invoices/select_invoices/view/' . $page_type ?>", // json datasource
          type: "post", // type of method  , by default would be get
          data: function(d) {
            d.invoice_type = "proforma";
            <?php if ($page_name == 'work_profile' || $page_name == 'projects_profile' || $page_name == 'work_summary') { ?>
                  d.project = "<?php echo $work_data->work_id ?>";
                  <?php }elseif($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',
                          title: 'Client Invoices'
                        },
                        {
                          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": [2,23,24,25,26 <?php if ($page_name == 'work_summary') {
                          echo ",1,4,5,22";
                        } ?><?php if ($this->config->item('Tax_tax_splitting') == 0) {
                          echo ",10,11,12,13,14,15";
                        } ?><?php if ($this->session->userdata('user_role') == 'auditor' && $this->session->userdata('user_data_permission')['adding'] != 1) {
                          echo ",22";
                        } ?><?php if (empty($this->config->item('company_branches'))) { echo ",1"; }?><?php if (isset($invoice_type) && $invoice_type=='other_income') { echo ",5"; }?>
                      <?php if($this->config->item('Client_Payment_client_payment_invoice_template')==3 || $this->config->item('Client_Payment_client_payment_invoice_template')==5 || $this->config->item('Client_Payment_client_payment_invoice_template')==6  || $this->config->item('Client_Payment_client_payment_invoice_template')==7){ echo ",8,10,11,12,13,14,15";}?>],
                        className: "hidden"
                      }],
                      'order': false,
                      "fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
                        if (aData[24] == '0') {
                          $('td', nRow).css('background-color', '#ffcccc');
                        } else if (aData[24] == '2') {
                          $('td', nRow).css('background-color', '#ffcccc');
                        }
                      }
                    });

                    $(".hide_column").hide();

                    $("[data-switch=true]").bootstrapSwitch()

                    $(".table_filter").on("change", function() {
                      proforma_invoices_view_table.ajax.reload();
                    });
                    $(".hide_column").hide();
                    </script>
