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

class History extends CI_Controller {

	public function __construct(){
        parent::__construct();
		$this->load->model('token_model');
		
    }


	public function index()
    {
	
		## METHODE ACCEPTE
		$this->token_model->valideMethod('GET');
		
		## AUTHENTIFICATION 
		$this->token_model->valideToken();

		## RECUPERATION DES DONNEES 
        $size = 100;
		if(!empty($_GET['date_begin'])) $debut = $_GET['date_begin'];
		if(!empty($_GET['date_end'])) $fin = $_GET['date_end'];
        $vdebut = strtotime($debut);
        $vfin = strtotime($fin);
        if(empty($vfin)) $fin = date('Y-m-d');
        if(empty($vdebut)) $debut = date('Y-m-d',time()-(3600*24*30*3)); //trois mois avant
        
		$debut = $debut." 00:00:00";
        $fin = $fin." 23:59:59";
		
		

		//REQUETE DE RECUPERATION
		success:
		$query = "select transaction_id,reference_id,order_id, date_created,date_payment,status as status, amount,fees,taxes,amount_total,ip_address as ip_from,recipient_number from transactions where agent_id = '".$this->token_model->user_id."' and (date_created>='$debut' and date_created<='$fin') limit $size";// and   transaction_id='".$this->token_model->Data['transactionid']."'";
        
		$reponse = $this->db->query($query)->result_array();
		
		
		$result['data']=$reponse;
		local_json($result);

		## METHODE ACCEPTE
		$this->token_model->valideMethod('POST');

		## AUTHENTIFICATION 
		$this->token_model->valideToken();

		## RECUPERATION DES DONNEES 
		$this->token_model->getData('JSON');
       
        $json = $this->token_model->Data;
        
    }
	

}