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

class CliQuo extends CI_Controller {
	
	const VERSION = '0.1.1';
	 
    public function __construct(){		
   		parent::__construct();
		$this->load->helper('completesql'); 
  		$this->load->model('Quotations');

	}

	public function index(){
		echo "Bienvenidos al modulo de cotizaciones\n\r";
		echo "la version ".self::VERSION." actual de este modulo\n\r";
		echo "====================================================== \n\r";
		echo "estas son algunas de las funciones principales\n\r";
		echo "====================================================\n\r";
		echo "getQuotations modo de ejecucion php index.php cliquo getQuotations [iduser]";
	}
	
	
	public function getQuotations($expression){
		list($command,$search) = explode(' ',$expression);
		if(ereg('^-u', $command))
			$where = array('user',$search);
		if(ereg('^-c',$command))
			$where = array('client',$search);
		
		$result = $this->Quotations->getQuotations($where);		
		if( !empty($result['total']) ):
			$tabla  =  "---------------------------------------------------------------------------------------\n\r";
			$tabla .=  "|	Cotizacion		|	Pedido	|	Fecha	        |	Cliente  	\n\r";
			$tabla .=  "---------------------------------------------------------------------------------------\n\r";
			$i = 0;
			foreach( $result['fetch'] as $row):
				(!empty($row->PEDIDO)) ? $i++ : $i;
				$tabla.= "|		".$row->COTIZACION."		|	".$row->PEDIDO."	|	".$row->HEDTE."	|	".$row->HNAME."\n\r"; 
			endforeach;
			echo $tabla;
		else:
			echo 'usuario inexistente';
		endif;
	}
	
}
