<script>
<?php if($page_name=='user_profile' || $page_name=='print_work_hour_report' || $page_name=='user_work_hour_report'){?>

  $("#table_filter_work_hour_start_date,#table_filter_work_hour_end_date").datepicker( {
    todayHighlight:!0, orientation:"bottom left", templates: {
      leftArrow: '<i class="la la-angle-left"></i>', rightArrow: '<i class="la la-angle-right"></i>'
    },format: "dd-mm-yyyy"
  })

  function GetSearchStartDate(){
    return $('#table_filter_work_hour_start_date').val();
  }
  function GetSearchEndDate(){
    return $('#table_filter_work_hour_end_date').val();
  }
  <?php } ?>
  function get_work_hour_report(){
    <?php if($page_name=='user_profile' || $page_name=='user_work_hour_report'){?>
    var start_date = GetSearchStartDate();
    var end_date = GetSearchEndDate();
    <?php }elseif($page_name=='print_work_hour_report'){?>
      var start_date = '<?php echo $start_date?>';
      var end_date = '<?php echo $end_date?>';
      <?php } ?>
    $.ajax({
      type: "POST",
      url: "<?php echo base_url() ?>user/select_work_hour_report",
      data: {
        <?php if($page_name=='user_profile' || $page_name=='print_work_hour_report' || $page_name=='user_work_hour_report'){?>
          start_date:start_date,
          end_date:end_date,
          user:"<?php echo $user_data->user_id?>"
          <?php } ?>
        },
        success: function(data)
        {
          var obj = $.parseJSON(data);
          $('#work_hour_report_view_table').html("");
          $('#work_hour_report_view_table').append(obj.table_data);
          $('#work_hour_report_view_table_caption').html('Work Hour Report of <strong><?php echo $user_data->user_alias."  ".$user_data->employee_code?></strong> - [<strong>'+start_date+' to '+end_date+'</strong>]');
        },
        complete: function (data) {
          <?php if($page_name=='print_work_hour_report'){?>
            // $.each('.bg_row',function(){
            //   var id = $(this).attr('id');
            //   var bg_color = $(this).data('bg-color');
            //   var css = "@media print { #"+id+" { background-color: "+bg_color+" !important;}}"
            //   $("#"+id).css(css);
            // })
            window.print();
            <?php } ?>
          }
        });
      }

      get_work_hour_report();
      $(".table_filter_work_hour").on("change", function() {
        get_work_hour_report();
      });
      $('#btn_print_work_hour_report').click(function(e){
        var user_id = "<?php echo $user_data->user_id?>";
        var start_date = $("#table_filter_work_hour_start_date").val();
        var end_date = $("#table_filter_work_hour_end_date").val();
        window.open('<?php echo base_url().'user/print_work_hour_report/'?>'+user_id+'?start_date='+start_date+'&end_date='+end_date,'newwindow','width=1200,height=700'); return false;
      });

      </script>
