<?PHP 
include("header.php");
//session_start();
//error_reporting(0);

include "checksession.php";



include "include/db-connect.php";
if(isset($_REQUEST['submit']))
 {
	$start_date=$_REQUEST['from_date'];
			
	 $end_date=$_REQUEST['to_date']; 
	 
	 ?>
     <script>
	 window.location='view_sales_profit.php?sdate=<? echo $start_date ?>&&edate=<? echo $end_date ?>';
	 </script>
     <?
	 
	 //header("Location:view_sales_profit.php?sdate=$start_date&&edate=$end_date");
 }
 
 if(isset($_REQUEST['pid']))
 {
	 $product_id=$_REQUEST['product_id']; 
	 
	  ?>
     <script>
	 window.location='sales_profit_bypid.php?product_id=<? echo $product_id ?>';
	 </script>
     <?
	 
	 //header("Location:sales_profit_bypid.php?product_id=$product_id");
 }

?>
<!----------------Start Date Picker Code-------->
<script type="text/javascript" src="JavaScript/calendar.js">
</script>
<script type="text/javascript" src="JavaScript/calendar-en.js">
</script>
<script type="text/javascript" src="JavaScript/calendar-setup.js">
</script>
<link rel="stylesheet" type="text/css" media="all" href="JavaScript/calendar-win2k-cold-1.css" title="win2k-cold-1" />
<!----------------End Date Picker Code-------->


  <div id="content">
  <div class="breadcrumb">
       <!-- <a href="http://amarasudhan.com/admin/index.php?route=common/home&amp;token=b735cc089ec2d51abb9a8e1901f501fb">Home</a>-->
      </div>
              <div class="box">
    <div class="heading">
      <h1><img src="view/image/home.png" alt="" /> Total Sales</h1>
    </div>
    <div class="content">
      <div class="overview" style="width:100%; margin-left:0px;">
        <div class="dashboard-heading"> Total Sales</div>
        <div class="dashboard-content">
        
<!--Message Display-->	
<?php

if($_REQUEST['add'] == 'success') {echo $result= '<h4 class="alert_success">Category Added Success </h4>';}

if($_REQUEST['edit'] == 'sucess') {echo $result= '<h4 class="alert_success">Category Edited Success </h4>';}

if($_REQUEST['deactive'] == 'success') {echo $result= '<h4 class="alert_success">Deactivated Successfully </h4>';}

if($_REQUEST['delete'] == 'sucess') {echo $result= '<h4 class="alert_success">Category Deleted Success </h4>';}



?>		
  
 <?php 
		    $start_date=$_REQUEST['sdate'];
			
            $end_date=$_REQUEST['edate'];
			
			
			 
			  $dis1=("select count(*) as num  from purchase_tax where purchase_date Between '$start_date' and '$end_date'");		
		     $total_pages = mysql_fetch_array(mysql_query($dis1));
		

             $total_pages = $total_pages[num];
	        {
?>

<?php } ?>
 

  <table class="list" cellspacing="0" > 
			<thead> 
                 <tr>
                   
                    
                    <td class="left">S.No</td>
    				<td class="left">Date</td> 
                    <td class="left">Name</td>
                    <td class="left">Contact</td>
                    <td class="left">Address</td>                    
                    <td class="left">Amount</td>                   
                    <td class="left">Order ID</td>
                    <td class="left">Payment Type</td>  
                    <td class="left">Txn Id</td> 
                    <td class="left">Txn Amt</td>  
                    <td class="left">Despatch</td>  
                    <td class="left">Payment</td>  
                    <td class="left">AWB</td> 
					<td class="left">Delivery</td> 
                    <!--<td class="left">Transaction Details</td> -->
                    <td class="left">Product Details</td> 
              </tr>
              </thead>
			
			<tbody> 
           <?php 

		$dis1="select COUNT(*) as num  from ".$ORDER."";		

		$total_pages = mysql_fetch_array(mysql_query($dis1));
		$adjacents = 3;
        $total_pages = $total_pages[num];

$targetpage = ""; //your file name (the name of this file)

$limit = 10; //how many items to show per page

$page = $_GET['page'];

if($page)

$start = ($page - 1) * $limit; //first item to display on this page

else

$start = 0; //if no page var is given, set start to 0

if ($page == 0) $page = 1; //if no page var is given, default to 1.

$prev = $page - 1; //previous page is page - 1

$next = $page + 1; //next page is page + 1

$lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up.

$lpm1 = $lastpage - 1; //last page minus 1


$pagination = "";

if($lastpage > 1)

{

$pagination .= "<div class=\"pagination\">";

//previous button

if ($page > 1)

$pagination.= "<a href=\"$targetpage?page=$prev \"> Previous &nbsp;</a>";

else

$pagination.= "<span class=\"disabled\">Previous &nbsp;</span>";



//pages

if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up

{

for ($counter = 1; $counter <= $lastpage; $counter++)

{

if ($counter == $page)

$pagination.= "<span class=\"current\">$counter &nbsp;</span>";

else

$pagination.= "<a href=\"$targetpage?page=$counter \">$counter &nbsp;</a>";

}

}

elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some

{

//close to beginning; only hide later pages

if($page < 1 + ($adjacents * 2))

{

for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)

{

if ($counter == $page)

$pagination.= "<span class=\"current\">$counter &nbsp;</span>";

else

$pagination.= "<a href=\"$targetpage?page=$counter \">$counter &nbsp;s</a>";

}

$pagination.= "...";

$pagination.= "<a href=\"$targetpage?page=$lpm1 \">$lpm1 &nbsp;</a>";

$pagination.= "<a href=\"$targetpage?page=$lastpage \">$lastpage &nbsp;s</a>";

}

//in middle; hide some front and some back

elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))

{

$pagination.= "<a href=\"$targetpage?page=1 \">1 &nbsp;</a>";

$pagination.= "<a href=\"$targetpage?page=2 \">2 &nbsp;</a>";

$pagination.= "...";

for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)

{

if ($counter == $page)

$pagination.= "<span class=\"current\">$counter &nbsp;</span>";

else

$pagination.= "<a href=\"$targetpage?page=$counter \">$counter &nbsp;</a>";

}

$pagination.= "...";

$pagination.= "<a href=\"$targetpage?page=$lpm1 \">$lpm1 &nbsp;</a>";

$pagination.= "<a href=\"$targetpage?page=$lastpage \">$lastpage &nbsp;s</a>";

}

//close to end; only hide early pages

else

{

$pagination.= "<a href=\"$targetpage?page=1 \">1 &nbsp;</a>";

$pagination.= "<a href=\"$targetpage?page=2 \">2 &nbsp;</a>";

$pagination.= "...";

for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)

{

if ($counter == $page)

$pagination.= "<span class=\"current\">$counter &nbsp;</span>";

else

$pagination.= "<a href=\"$targetpage?page=$counter \">$counter &nbsp;</a>";

}

}

}



//next button

if ($page < $counter - 1)

$pagination.= "<a href=\"$targetpage?page=$next \">Next  &nbsp;</a>";

else

$pagination.= "<span class=\"disabled\">Next  &nbsp;</span>";

$pagination.= "</div>\n";

}

		$qur="SELECT * FROM ".$ORDER." order by serial desc  LIMIT $start, $limit"; 



		$result = mysql_query($qur)or die('Have an error in viewing data'.mysql_error());

		while ($row_section = mysql_fetch_array($result)) 

			{
			    $snum=$row_section['serial'];
				$date=$row_section['date'];
				$cust_id=$row_section['customer_id'];
				$name=$row_section['name'];
				$address=$row_section['address'];
				$product_name=$row_section['product_name'];
				$quantity=$row_section['quantity'];
				$tot_amount=$row_section['tot_amount'];
				$order_id=$row_section['order_id'];
				$awb_num=$row_section['awb_num'];
				$delivery=$row_section['delivery'];
				$payment=$row_section['payment'];
				
				$pay=$row_section['pay'];
				$txnid=$row_section['txnid'];
				$txnamount=$row_section['txnamount'];
				
				
				$setqqqqoooo=mysql_query("select * from invoice_no where order_id='$order_id'");
  				$fetqqqqoooo=mysql_fetch_array($setqqqqoooo);
  				$invno=$fetqqqqoooo['invno'];
			  ?>	    

			    <tr> 

   					<td class="left"><?php echo $snum;?></td> 

    				<td class="left"><?php  echo $date; ?></td>
                    

                     <td class="left"><?php echo $name; ?></td>
                     <td class="left"><?php echo $row_section['phone']; ?></td>
                      <td class="left"><?php echo $address; ?></td>
                     <td class="left"><?php echo $tot_amount; ?></td>                     
                     <td class="left"><?php echo $order_id; ?></td>
                     
                     <td class="left"><?php echo $pay; ?></td>
                     <td class="left"><?php echo $txnid; ?></td>
                     <td class="left"><?php echo $txnamount; ?></td>
                     <td align="center">
                     <?php
					 if($invno==NULL)
					 {
					 ?>
                     <a href="despatch.php?order_id=<?php echo $order_id; ?>" onClick="return confirm('The invoice will generate in this process. Do you want to continue??..')">
                     <img src="images/generate.jpg" width="40">
                     </a>
                     <?php } else {?>
                     <img src="images/check.jpg" width="20">
                     <?php } ?>
                     </td>
                     
                     <td class="left"><?php echo $payment; ?></td>
                    <td class="left"><?php echo $awb_num; ?></td>
                    <td class="left"><?php echo $delivery; ?></td>
                   <!-- <td class="left"><?php if($pay=='Paymentgateway'){ ?><a href="tran_det.php?order_id=<?php echo $order_id; ?>"><img src="images/icn_new_article.png" /></a><?php } ?></td>-->
                    
                    <td class="left"><a href="pro_det.php?order_id=<?php echo $order_id; ?>"><img src="images/icn_new_article.png" /></a></td>
				</tr> 	 

				 

<?php } ?> 

			</tbody> 

			</table>
            
   
        </div>
        <div align="right"><?php echo $pagination; ?> 	</div>	
      </div>
      
      
    <?php	
        $sql = "select sum(tot_amount) from orders where pay='COD' and payment='yes'";
		$q = mysql_query($sql);
		$row = mysql_fetch_array($q);
		
		
		$sqlasd = "select sum(tot_amount) from orders where pay='COD' and payment!='yes'";
		$qasd = mysql_query($sqlasd);
		$rowsad = mysql_fetch_array($qasd);
		
		
		$sqlww = "select sum(txnamount) from orders where pay='Paymentgateway'";
		$qww = mysql_query($sqlww);
		$rowww = mysql_fetch_array($qww);

?>
<font style="font-size:18px;"> Total Sales: <?php echo $row[0]+$rowsad[0]+$rowww[0]; ?>   </font> <br /><br />
<font style="font-size:18px;"> Paymentgateway: <?php echo $rowww[0]; ?> </font>  <br /> <br />  
<font style="font-size:18px;"> COD Payment Pending: <?php echo $rowsad[0]; ?> </font> <br /><br />
<font style="font-size:18px;"> COD Payment Completed: <?php echo $row[0]; ?> </font>   
      
      
      
      <!-- <div class="overview" style="width:80%; height:250px; margin-left:200px;">
        <div class="dashboard-heading"> Purchase Tax By Date</div>
        <div class="dashboard-content">
      
      
      
        <div><h3>total sales profit&nbsp;=&nbsp;Rs.<?php echo $row[0]; ?></h3></div>
<div style="margin-bottom:10px; margin-top:10px; margin-left:20px;"><!--<a href="javascript: history.go(-1)"><img src="images/bac.jpg"></a>--></div>
</article>

 <!--<form method="post" id="client" enctype="multipart/form-data" action="">
  		
  
           	    <div class="clear"></div>
				<article class="module width_3_quarter" style="margin-left:10px; width:1000px;">
				<header>
		  		<h3 class="tabs_involved" style="margin-left:5px; color:#033;">Sales Profit By Date</h3>
				</header>
				<div class="tab_container">
                
                <div class="mainrow">
                <div class="maintext">Start Date<font color="#FF0000"><b> *</b></font> </div>
                <div class="maintextbox">
                <input type="text" required class="TextBox" name="from_date" id="f_date_b1">
				<img src="images/cal.gif" id="f_trigger_b1" >
				<script type="text/javascript">
				Calendar.setup({inputField :"f_date_b1",ifFormat:"%Y-%m-%d",showsTime:true,button:"f_trigger_b1",singleClick:true});
				</script>
                </div>
                </div>
                
                <div class="mainrow">
                <div class="maintext">End Date<font color="#FF0000"><b> * </b></font> </div>
                <div class="maintextbox">
                <input type="text" required class="TextBox" name="to_date" id="f_date_b2">
				<img src="images/cal.gif" id="f_trigger_b2" >
				<script type="text/javascript">
				Calendar.setup({inputField :"f_date_b2",ifFormat:"%Y-%m-%d",showsTime:true,button:"f_trigger_b2",singleClick:true});
				</script>
                </div>                 
                </div>
                
                <div class="mainrow">
    			<div class="maintext"><font color="#FF0000"><b></b></font> </div>
                <div class="maintextbox"><input type="submit" name="submit"value="Submit" ></div>
                </div>
                </div>
                
 				</form>
                 <script type="text/javascript">
						function formCallback(result, form) 
						{
							window.status = "valiation callback for form '" + form.id + "': result = " + result;
						}
						
						var valid = new Validation('client', {immediate : true, onFormValidate : formCallback});
						Validation.addAllThese([
							['validate-password-confirm', 'Your confirmation password does not match your first password, please try again.', {
								equalToField : 'confirm_password'

							}]
						]);
					</script>
                  </div>
                </div>  
                  
                
                
                </div></div>
                
                
                
                 <div class="overview" style="width:80%; margin-left:200px;">
        <div class="dashboard-heading">  Purchase Tax By Date</div>
        <div class="dashboard-content">
                  
             <form method="post" id="profit_id" enctype="multipart/form-data" action="">
  			
  
  				<div class="clear"></div>
				<article class="module width_3_quarter" style="margin-left:-2px; width:1000px; height:150px;">
				<header>
		  		<h3 class="tabs_involved" style="margin-left:5px; color:#033;">Sales Profit by product id</h3>
				</header>
				<div class="tab_container">
                
                <div class="mainrow">
                <div class="maintext">Product ID<font color="#FF0000"><b> *</b></font> </div>
                <div class="maintextbox"> <select  name="product_id">
               
                            <option value="">Select Product ID</option>
                             <?php
               					 $select="select * from ".$PRODUCT."";
								 $result=mysql_query($select);
							 	 while ($row = mysql_fetch_array($result))
  									{ 
							?>
                            <option value="<?php echo $row['product_id']; ?>"><?php echo $row['product_id'];?> </option>
                            <?php } ?>
                            </select></div>
                </div>
                
                
                
                <div class="mainrow" style="margin-left:20px;">
    			<div class="maintext"><font color="#FF0000"><b></b></font> </div>
                <div class="maintextbox"><input type="submit" name="pid"value="Submit" ></div>
                </div>
                </div>
                
                </div>
                </div>
 				</form>
                 <script type="text/javascript">
						function formCallback(result, form) 
						{
							window.status = "valiation callback for form '" + form.id + "': result = " + result;
						}
						
						var valid = new Validation('profit_id', {immediate : true, onFormValidate : formCallback});
						Validation.addAllThese([
							['validate-password-confirm', 'Your confirmation password does not match your first password, please try again.', {
								equalToField : 'confirm_password'

							}]
						]);
					</script>


      </div></div></div>-->
      
      
      
      
      
      
      
      
      
      
      
      
      
    </div>
  </div>
</div>
<!--[if IE]>
<script type="text/javascript" src="view/javascript/jquery/flot/excanvas.js"></script>
<![endif]--> 
<script type="text/javascript" src="view/javascript/jquery/flot/jquery.flot.js"></script> 
<script type="text/javascript"><!--
function getSalesChart(range) {
	$.ajax({
		type: 'get',
		url: 'index.php?route=common/home/chart&token=b735cc089ec2d51abb9a8e1901f501fb&range=' + range,
		dataType: 'json',
		async: false,
		success: function(json) {
			var option = {	
				shadowSize: 0,
				lines: { 
					show: true,
					fill: true,
					lineWidth: 1
				},
				grid: {
					backgroundColor: '#FFFFFF'
				},	
				xaxis: {
            		ticks: json.xaxis
				}
			}

			$.plot($('#report'), [json.order, json.customer], option);
		}
	});
}

getSalesChart($('#range').val());
//--></script> 
</div>
<?php include("footer.php"); ?>