<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Paychecks extends CI_Controller {
    function __construct()
 	{
	    parent::__construct();
		$this->load->helper('url');
		$this->load->helper('form');
        $this->load->model('common');
		$this->load->library('session');
		$this->load->database();
		$this->load->library(array('form_validation','template'));
	}

	public function index()   
	{
		$this->load->model('drivers_model');
		$data["drivers"] = $this->drivers_model->getall_drivers()["user"];
		if(isset($_POST['incomeexpensereport'])) {
			if (isset($_POST['driverId']) && $_POST['driverId'] != "" && !empty($_POST['driverId'])) {
				$triplist = $this->common->readdatafromcollectionbetweenwhere("Payouts", "completionTimeStamp" , ">", strtotime($this->input->post('incomeexpense_from'))*1000, "completionTimeStamp" , "<", (strtotime($this->input->post('incomeexpense_to'))+86500)*1000, "driverId" , "=", $_POST["driverId"]);
			} else {
				$triplist = $this->common->readdatafromcollectionbetweenwhere("Payouts", "completionTimeStamp" , ">", strtotime($this->input->post('incomeexpense_from'))*1000, "completionTimeStamp" , "<", strtotime($this->input->post('incomeexpense_to'))*1000);
			
			
			}
			if(empty($triplist)) {
				$this->session->set_flashdata('warningmessage', 'No Data found..');
				$data['paychecks'] ="";
				$data['driverId']=$_POST['driverId'];
			} else {
				$data['paychecks'] =$triplist;
				$data['driverId']=$_POST['driverId'];
			}
		}else{
			$data['driverId']="";
		}
		// if(!empty($this->input->get())){
		// 	echo "<pre>";
		// 	print_r($this->input->get());
		// 	echo $startDate=strtotime($this->input->get('startdate'));;		
		// 	echo $enddate=strtotime(date('Y-m-d', strtotime("+1 day", strtotime($this->input->get('enddate')))));




		// 	echo "</pre>";

		// 	$data['paychecks'] =$this->common->readdatafromcollectionwhereclause("Payouts");

		// }else{
		// 	$data['paychecks'] ="";
		// }
			


		



		$this->template->template_render('paychecks', $data); 
	}

	public function releasePaycheck($id)   
	{
		$data["status"] = "pending";
		$response =$this->common->updatedatamodel("Payouts", $id, $data);
		redirect('paychecks');
	}
	
	
}
