<?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 OrderDetail extends AppModel

{
	var $name 		= 'OrderDetail';

	//var $belongsTo 	= array('OrderDetail');
	
	
	
	 function getDates($opt='')
		 {
			$Db = ConnectionManager::getDataSource($this->useDbConfig);
			$ordtbl = $Db->fullTableName('orders');
			if($opt=='max')
			{
			 $maxdate	=	$this->query("SELECT DATE_FORMAT(DATE_ADD(max(date),INTERVAL 1 DAY),'%m-%d-%Y') AS maxdate FROM $ordtbl");
			 $gdate= $maxdate[0][0]["maxdate"];			
			}
			else if($opt=='min')
			{
			 $mindate	=	$this->query("SELECT DATE_FORMAT(DATE_SUB(min(date),INTERVAL 1 DAY),'%m-%d-%Y') AS mindate FROM $ordtbl");
			 $gdate= $mindate[0][0]["mindate"];			
			}
			return $gdate;
		}
		
		
    function getTableName($tablename)
	  {
		$Db = ConnectionManager::getDataSource($this->useDbConfig);
		$tblnme = $Db->fullTableName($tablename);		
		$tblnme=trim(str_replace('`','',$tblnme));		
		return $tblnme;
	  }
	  
	  
	  
	  //Overriding Pagination starts here...

	
      function paginate($conditions, $fields, $order, $limit, $page = 1, $recursive = null, $extra = array())

	  {										

					

					if(!isset($extra['passit']['sort']))

					{

						$extra['passit']['page']= 1;

						$extra['passit']['sort']='OrderDetail.id';

						$extra['passit']['direction'] ='DESC';

						$order = array($extra['passit']['sort'] => $extra['passit']['direction']);						

					}					

					else

					{

					  $order = array($extra['passit']['sort'] => $extra['passit']['direction']);		

					}						

					$group='';	$joins = '';

					if(isset($extra['group']))$group = $extra['group'];

					if(isset($extra['joins']))$joins = $extra['joins'];					

					$params = array(

					  'conditions' => $conditions,	

					  'fields' => $fields, 

					  'order' => $order,

					  'limit' => $limit,

					  'joins' => $joins,

					  'page' => $page,

					  'group' => $group,		  	 

					);		

					return $this->find('all', $params);		

         }



			function paginateCount($conditions = null, $recursive = 0, $extra = array()) 

			{

				    $group='';	$joins = '';

					if(isset($extra['group']))$group = $extra['group'];

					if(isset($extra['joins']))$joins = $extra['joins'];		

				    $params = array(

					  'conditions' => $conditions,	

					  'fields' => '',		

					  'joins' => $joins,					 

					  'group' => $group,		  	 

					);		

					return count($this->find('all', $params));	

			}


        //Overriding Pagination starts here...


}

?>