<script type="text/javascript">

  $('body').on('click', '#project_stages_edit_btn', function() {
    var no = $(this).closest('tr').children('td');
    $('#stage_id_edit').val(no.eq(0).text());
    $('#stage_name_edit').val(no.eq(2).text());
    $('#stage_no_edit').val(no.eq(1).text());
    $('#stage_start_date_edit').val(no.eq(4).text());
    $('#stage_end_date_edit').val(no.eq(5).text());
    $('#stage_budget_amount_edit').val(no.eq(3).text());
    $('#stage_description_edit').html(no.eq(11).text());
    var status = no.eq(10).text();
    if(status==1){
      status_val = true;
    }
    else{
      status_val = false;
    }
    $("#active_status_edit").bootstrapSwitch('state', status_val);

  });

 //  function GetSearchwork(){
 //   return $('#table_filter_work2').val();
 // }
 // function GetSearchDate(){
 //   return $('#table_filter_date_range2').val();
 // }

 var project_stages_view_table = $('#project_stages_view_table').DataTable({
  "ajax":{
        url :"<?php echo base_url().'work/select_project_stages' ?>", // json datasource
        type: "post", // type of method  , by default would be get
        data: function(d){
          d.project = '<?= $work_data->work_id?>';
        }
      },
      "bProcessing": true,
      "deferRender": true,
      "bDeferRender": true,

      "scrollX" : true,
      buttons: [
      { extend: 'print', className: 'btn dark btn-outline',title: 'Project Stages' },
      { 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"]
      ],

      'order': false,
      "columnDefs": [
      {
        "targets": [0,10,11],
        className: "hidden"
      }
      ]
    });


	  // Date Range Picker
	  var start = moment();
	  var end = moment();

	  function cb(start, end) {
	  	$('#table_filter_date_range2').val(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
	  	// invoices_view_table.ajax.reload();
	  	project_stages_view_table.ajax.reload();
	  }

	  $('#table_filter_date_range2').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);

   $(".table_filter").on("change", function() {
		// invoices_view_table.ajax.reload();
		project_stages_view_table.ajax.reload();

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




 </script>
