<?php

/* $Id: SelectCustomer.php 7133 2015-02-07 03:23:51Z daintree $*/

include('includes/session.inc');
$Title = _('Retail Counter Reports');
include('includes/header.inc');
include('includes/SQL_CommonFunctions.inc');
  

echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">';







	echo '<div class="col-sm-10">';// div class=?
	echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '<table class="table">';
echo '<div>';

echo '<tr>
			<td>' ._('From Date'). ':</td>
			<td><input  type="date" maxlength="10" size="15" required="required" name="fromdate" /></td>
		</tr>';

echo '</td>';
	echo '<tr>
			<td>' ._('To Date'). ':</td>
			<td><input  type="date" maxlength="10" size="15" required="required" name="todate" /></td>
		</tr>';

echo '</td>';
	
echo '<div><input type="submit"  name="quote" value="' ._('Show Sales Total For Date Range Below') . '" />
		</div>
		';



echo '</div>';

echo '</div>';
	echo '</table>';

//$jobno = $_POST['Job'];
$dateraw = $_POST['fromdate'] ;



$starttime = date("Y-m-d H:m:s", strtotime($dateraw));


$dateraw1 = $_POST['todate'] ;  
$endtime = date("Y-m-d H:m:s", strtotime($dateraw1));
	
$cashier = $_POST['cashier'];
	$counter =$_POST['counter'] ;
	

if (isset($_POST['quote']) ){  
		
	//echo ' <div class="row"> ';



		
		$sql4 =  "SELECT id,
	               sale_id,
				   sale_time,
				   counter,
				  username
			FROM sales_retailshops WHERE   sale_time between '" . $starttime. "' and '" . $endtime. "'
			Order by id ASC;
			
			";
	$ErrMsg = _('This customer could not be added because');
			$result4 = DB_query($sql4,$ErrMsg);
	
		
		
	
echo '<div class="table-responsive"><table id="projectreport" class="table">';
	echo '<thead> <tr class="info">
				
			<th >' . _('Total Sales Amount') . 
		'</th>
	
			</tr></thead>';
		$grandtotal = 0;
	
	while ($myrow4 = DB_fetch_array($result4)) {
		
		//getbudgeted totals
		
		 $query = "SELECT SUM(quantity_purchased*item_unit_price) as 'total'
						 
						 
				   			  
		          FROM salesitems_retailshops where id ='" . $myrow4['id']. "'";
		
		$result5 = DB_query($query);
		
		$myrow5 = DB_fetch_array($result5);
		//get actual cost
		
		$subtotal = $myrow5['total'];
		
		$valueInString = strval(round($subtotal,2));
if (strpos($valueInString, ".") == 0)
$valueInString = $valueInString.".00";
$valueArray = explode(".", $valueInString);
$substringValue = substr($valueArray[1], 1);

if ($substringValue >= 3 && $substringValue <= 7) {
$tempValue = str_replace(substr($valueArray[1], 1), 5, substr($valueArray[1], 1));
$tempValue = substr($valueArray[1],0,1).$tempValue;
$newvalue = floatval($valueArray[0].".".$tempValue);
} elseif ($substringValue == 1 ) {
$newvalue = $subtotal-0.01;
	} elseif ($substringValue == 2 ) {
	
	$newvalue = $subtotal-0.02;
	} elseif($substringValue == 0) {
$newvalue = floatval($subtotal);
} else {
$newFloat = floatval($valueArray[0].".".substr($valueArray[1],0,1));
$newvalue = ($newFloat+0.1);
}
		
			$total = $newvalue;
		
		$grandtotal += $total;
		
	}
echo '<tr>
					 <td>$' . $grandtotal . '</td>'
					;
	
echo '</div>';
echo '</div>';


	
}
 

	
	