<?php 
class ControllerSoldToday extends Controller {  
	function index() { 
		$config   =& $this->locator->get('config');
		$currency =& $this->locator->get('currency');
		$database =& $this->locator->get('database');
		$language =& $this->locator->get('language');
		$image    =& $this->locator->get('image');
		$module   =& $this->locator->get('module');
		$request  =& $this->locator->get('request');
		$response =& $this->locator->get('response');
		$session  =& $this->locator->get('session');
		$tax      =& $this->locator->get('tax');
		$template =& $this->locator->get('template');
		$url      =& $this->locator->get('url');
		$image    =& $this->locator->get('image');
		$view = $this->locator->create('template');	
		$language->load('controller/sold_today.php');
		
	 //Recent Transactions    	
    	//$recent_order_data = array();
    	$get_time=date('Y-m-d:h:i:s',time()-86400*30); // 86400*30
    	$order_info=$database->getRows("select order_id from `order` where date_added>='".$get_time."'");    
    	foreach($order_info as $k=>$order){
    		$recent_order_id[$k]=$order['order_id'];
    	}   
    	$recent_order_results = $database->getRows("select distinct op.itemcode, op.name, op.price,op.total, op.quantity,i.filename from order_product op left join `product` p on op.itemcode=p.product_id left join image i on i.image_id=p.image_id where op.order_id in(" . implode(',',$recent_order_id) . ") group by op.itemcode");
  
    	foreach ($recent_order_results as $k=>$v){	
    				$recent_order_list[]=array(
    				    'itemcode'=>$v['itemcode'],
    				    'name'=>$v['name'],
    				    'price'=>$v['price'],
    				    'total'=>$v['total'],
    				    'quantity'=>$v['quantity'],
    				    'filename'=>$image->resize($v['filename'], 100, 100),
    				    'feedback'=>$database->getRow("select sum(rating) as sum,avg(rating) as avg,count(feedback_id) as total from `feedback` where product_id='".$v['itemcode']."'"),
    				);		
					//$recent_order_results[$k]['feedback']=$database->getRow("select sum(rating) as sum,avg(rating) as avg,count(feedback_id) as total from `feedback` where product_id='".$v['itemcode']."'");
		 }	

    	$view->set('recent_order_results', $recent_order_list);		
		$template->set('title', 'What Products Were Sold in 24 Hours?');
	    $template->set('content', $view->fetch('content/sold_today.tpl'));
		$template->set($module->fetchPublic());
    	$response->set($template->fetch('layout.tpl'));
	   
		 
  	}
	

}
?>
