<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: 			*/
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 2004-2008 ARMIA INC                                    |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts EasyCart                      |
// +----------------------------------------------------------------------+
// | Authors: Jipson<jipson.thomas@armiasystems.com>             		  |
// +----------------------------------------------------------------------+
?>
<?php echo $javascript->link('jquery.js');?>
<?php echo $javascript->link('hint.js'); ?> 
<?php echo $javascript->link('ui.datepicker.js'); ?>
<script>
	//Code for the project	
	$(document).ready(function()	
	{	
	$('#sales_fdate').datepick({minDate: '<?php echo $dflt_mindate;?>' , maxDate:'<?php echo $dflt_maxdate;?>', 
	dateFormat: 'mm-dd-yy',closeAtTop: false, showStatus: true,  showOn: 'both', buttonImageOnly: true,
	 buttonImage: '<?php echo $cnfg["sitebasefolder"]."/img/calendar.gif";?>' });	
	 
	 $('#sales_tdate').datepick({minDate: '<?php echo $dflt_mindate;?>' , maxDate:'<?php echo $dflt_maxdate;?>', 
	dateFormat: 'mm-dd-yy',closeAtTop: false, showStatus: true,  showOn: 'both', buttonImageOnly: true,
	 buttonImage: '<?php echo $cnfg["sitebasefolder"]."/img/calendar.gif";?>' });	
	 
	});
</script>
<script>
function submitForm(thisform)
{
 // 
  var fromdate=$('#from_date').val();
  var todate=$('#to_date').val();
   $('#fdate').val(fromdate);
   $('#tdate').val(todate);
   thisform.submit();
  }
  </script>

<div align="center" class="subheading">
  <div align="left">SALES REPORT</div>
            </div>
            <br />
			<div align="left" id="item_details_admin">
							<div>
							<form name="report" action="<?php echo $cnfg["sitebasefolder"];?>/<?php echo $this->params["controller"];?>/<?php echo $this->params["action"];?>" method="post">
							From <input type="text"  name="sales_fdate"  id="sales_fdate" size="15" readonly="readonly" value="<?php echo $mindate;?>" onclick="return false;"/>
							&nbsp;&nbsp;&nbsp;
							To <input type="text"  name="sales_tdate"  id="sales_tdate" size="15" readonly="readonly" value="<?php echo $maxdate;?>" onclick="return false;"
							/>
							<input type="button" value="view"  onclick="return submitForm(document.report);"/>			
							</form>
							</div> 
							 <br />	 <br />		
							 <?php if(count($reportdet) > 0) { ?>
							 <label  class="btn_style-org"><strong><?php echo $html->link('Export to csv','/orders/salescsv');?> >></strong></label>
							 <label   class="btn_style-org"><strong><?php echo $html->link('Export to xls','/orders/salesxls');?> >></strong></label>
							 <?php } ?>
							 <div class="clear"></div>
							 <br />	 <br />		
			
			 <?php 
      if($mindate <> '' &&  $maxdate <> ''){
       $paginator->options(array('url'=>array_merge(array('frmdate'=>$mindate,
	   'todate'=>$maxdate),$this->passedArgs))); } 
	   
	     $pval='';
			if(isset($this->passedArgs['page']))
			$pval=$this->passedArgs['page'];
			 ?>
				<!--items display area start -->
				  <div align="center" id="items_display_area_admin">
						   <div id="list_admin_top">
											   <div class="list9"><strong>#</strong></div>
											    <div class="list11"><strong><?php echo $paginator->sort('Order Number', 'Order.id'); ?></strong></div>
												<div class="list14"><strong><?php echo $paginator->sort('Date', 'Order.date'); ?></strong></div>
												<div class="list14">
												<strong><?php				
													echo $html->link(__('Username', true), array(
													'controller' => 'orders',
													'action' => 'reports',
													'page' => $pval,
													'frmdate'=> $mindate,
													'todate'=> $maxdate,
													'sort' => 'USR.uname',
													'direction' => (empty($this->passedArgs['direction']) || $this->passedArgs['direction'] == 'asc')?'desc' : 'asc',
													'limit' => $this->passedArgs['limit']						
													
												));
												?></strong>	
												</div>
												<div class="list14">
												<strong><?php				
													echo $html->link(__('Order Status', true), array(
													'controller' => 'orders',
													'action' => 'reports',
													'page' => $pval,
													'frmdate'=> $mindate,
													'todate'=> $maxdate,
													'sort' => 'Order.order_status_id',
													'direction' => (empty($this->passedArgs['direction']) || $this->passedArgs['direction'] == 'asc')?'desc' : 'asc',
													'limit' => $this->passedArgs['limit']						
													
												));
												?></strong>	
												</div>
												<div class="list14">
												<strong><?php				
													echo $html->link(__('Coupon code', true), array(
													'controller' => 'orders',
													'action' => 'reports',
													'page' => $pval,
													'frmdate'=> $mindate,
													'todate'=> $maxdate,
													'sort' => 'CPN.code',
													'direction' => (empty($this->passedArgs['direction']) || $this->passedArgs['direction'] == 'asc')?'desc' : 'asc',
													'limit' => $this->passedArgs['limit']						
													
												));
												?></strong>	
												</div>
												<div class="list14">
												<strong><?php				
													echo $html->link(__('Discount', true), array(
													'controller' => 'orders',
													'action' => 'reports',
													'page' => $pval,
													'frmdate'=> $mindate,
													'todate'=> $maxdate,
													'sort' => 'Order.discount',
													'direction' => (empty($this->passedArgs['direction']) || $this->passedArgs['direction'] == 'asc')?'desc' : 'asc',
													'limit' => $this->passedArgs['limit']						
													
												));
												?></strong>	
												</div>		
												<div class="list12">
												<strong><?php				
													echo $html->link(__('Total', true), array(
													'controller' => 'orders',
													'action' => 'reports',
													'page' => $pval,
													'frmdate'=> $mindate,
													'todate'=> $maxdate,
													'sort' => 'Order.total_price',
													'direction' => (empty($this->passedArgs['direction']) || $this->passedArgs['direction'] == 'asc')?'desc' : 'asc',
													'limit' => $this->passedArgs['limit']						
													
												));
												?></strong>	
												</div>																
												<div align="left" class="float_clear"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
							</div>
		
								<?php
							if(!empty($passedarg) && !isset($passedarg["page"]))								
									$cnt=1;
									else if(!empty($passedarg) && $passedarg["page"]==1)
									$cnt=1;
									else
									$cnt=((($passedarg["page"]-1)*($passedarg["limit"]))+1);	
										if(!empty($reportdet))
										 {
											foreach($reportdet as $det)
												{ ?>
								<div id="list_admin">
												<div class="list9"><?php echo $cnt++;?></div>
												<div class="list11">
												<?php echo $html->link($det['Order']['id'],"/orders/details/".$det['Order']['id']); ?>
												</div>
												<div class="list14"><?php
												 $ord_dt = strtotime($det["Order"]["date"]);											          
												 echo date("m-d-Y",$ord_dt);?></div>
												<div class="list14"><?php echo Sanitize::html($det["USR"]["uname"]);?></div>										
												<div class="list14"><?php echo Sanitize::html($det["ORS"]["name"]);?></div>
												<div class="list14"><?php if($det["CPN"]["code"]<>'') echo Sanitize::html($det["CPN"]["code"]); else echo "-";?></div>		
												<div class="list14"><?php echo $curlogo.$det["Order"]["discount"];?></div>				
												<div class="list12"><?php echo $curlogo.$det["Order"]["total_price"];?></div>		
												<div align="left" class="float_clear"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>									
												
								</div>
					 <?php  	}  ?>
					 
									 <div id="admin_bottom">		
												<div>&nbsp;</div>
												<div> 
												<?php echo $paginator->numbers(); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $paginator->counter(); ?>	</div>
												<div>&nbsp;</div>	
												<div align="left" class="float_clear"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
										  </div>			
					 
					 <?php } else { ?>
							  <div id="admin_bottom">									
												
												<div>&nbsp;</div>
												<div><strong>Sorry no reports found !</strong></div>
												<div>&nbsp;</div>	
												<div>&nbsp;</div>	
												<div>&nbsp;</div>										
												<div align="left" class="float_clear"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
								</div>			     
					 <?php } ?>
					 				 <div align="left" class="float_clear1"></div>
            </div>
            <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif');?></div>