<?php



/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: 			*/



// +----------------------------------------------------------------------+



// | PHP version 4/5                                                      |



// +----------------------------------------------------------------------+



// | Copyright (c) 2004-2010 ARMIA INC                                    |



// +----------------------------------------------------------------------+



// | This source file is a part of iScripts VistaCart                     |



// +----------------------------------------------------------------------+



// | Authors: Jipson<jipson.thomas@armiasystems.com>             		  |



// +----------------------------------------------------------------------+



class Report extends AppModel



{



   	   var $name = 'Report';   	 



		function getReportDetails($qry='',$opt='',$start='',$limit='')



		{



			$Db = ConnectionManager::getDataSource($this->useDbConfig);				



		   	if($opt==0)



			{



			   $res=$this->query($qry);	



			   return count($res);



			}  



			else if($opt==1)



			{



			  $qry.=" LIMIT $start, $limit";			



			 // echo $qry;



			  $res=$this->query($qry);	



			  return $res;



		    }else if($opt==2){



				$res=$this->query($qry);	



			  	return $res;



			}	



		 } 



		 



		 function getTableName($tablename)



		 {



			$Db = ConnectionManager::getDataSource($this->useDbConfig);



			$tblnme = $Db->fullTableName($tablename);			



			return $tblnme;



		}



		



		 function getDates($opt='')



		 {



			$Db = ConnectionManager::getDataSource($this->useDbConfig);



			$ordtbl = $Db->fullTableName('orders');



			if($opt=='max')



			{



			 $maxdate	=	$this->query("SELECT DATE_ADD(max(date),INTERVAL 1 DAY) AS maxdate FROM $ordtbl");



			 $gdate= $maxdate[0][0]["maxdate"];			



			}



			else if($opt=='min')



			{



			 $mindate	=	$this->query("SELECT DATE_SUB(min(date),INTERVAL 1 DAY) AS mindate FROM $ordtbl");



			 $gdate= $mindate[0][0]["mindate"];			



			}



			return $gdate;



		}



		



		



		



				 



		 function getDates_reg($opt='')



		 {



			$Db = ConnectionManager::getDataSource($this->useDbConfig);



			$usrtbl = $Db->fullTableName('users');



			if($opt=='max')



			{



			 $maxdate	=	$this->query("SELECT DATE_ADD(max(reg_date),INTERVAL 1 DAY) AS maxdate FROM $usrtbl");



			 $gdate= $maxdate[0][0]["maxdate"];



			}



			else if($opt=='min')



			{



			 $mindate	=	$this->query("SELECT DATE_SUB(min(reg_date),INTERVAL 1 DAY) AS mindate FROM $usrtbl");



			 $gdate= $mindate[0][0]["mindate"];



			}



			return $gdate;



		}



		 function getDates_coupons($opt='')



		 {



			$Db = ConnectionManager::getDataSource($this->useDbConfig);



			$cpntbl = $Db->fullTableName('coupons');



			if($opt=='max')



			{



			 $maxdate	=	$this->query("SELECT  DATE_ADD(max(`to_date`),INTERVAL 1 DAY) AS maxdate FROM $cpntbl");



			 $gdate= $maxdate[0][0]["maxdate"];



			}



			else if($opt=='min')



			{



			 $mindate	=	$this->query("SELECT   DATE_SUB(min(`from_date`),INTERVAL 1 DAY) AS mindate FROM $cpntbl");



			 $gdate= $mindate[0][0]["mindate"];



			}



			return $gdate;



		}		 





//Function for populating user list.

		 function getUsersList()

		 {



			$Db = ConnectionManager::getDataSource($this->useDbConfig);

			$cpntbl = $Db->fullTableName('users');

			$userList	=	$this->query("SELECT uname,id FROM $cpntbl");

			if(count($userList)>0){

				for($j=0;$j < count($userList); $j++)

				{

						$userData[$userList[$j]['Vista_users']["id"]]= $userList[$j]['Vista_users']["uname"];

				}

			}else{

				$userData[]="No users found";

			}

			return $userData;

		}		 

		

// fetch of the order		

		 function fetchSUM($qry)

		 {

			$Db = ConnectionManager::getDataSource($this->useDbConfig);

			$cpntbl = $Db->fullTableName('users');

			$totAMT	=	$this->query($qry);

			return $totAMT[0][0]['totAmt'];

		}		 



		











}



?>