<?php
/* $Id: index.php 6941 2014-10-26 23:18:08Z daintree $*/
error_reporting(E_ALL & ~E_NOTICE);
$PageSecurity=0;

include('includes/session.inc');
$Title=_('ERP Home');
include('includes/newheader.php');
$userid = $_SESSION['UserID'];

?>
	
		
		
		<?
			//echo ' <div class="row"> ';

	
?>


 
   
<script>
	

$(document).on('blur', '#100qty', function(){
         $100qty = $("#100qty").val();
		 
		 $total = $100qty * 100;
		 
	$("#100total").val($total);
calculateTotal();
		
    });								
										
	$(document).on('blur', '#50qty', function(){
         $100qty = $("#50qty").val();
		 
		 $total = $100qty * 50;
		 
	$("#50total").val($total);
		calculateTotal();
		  
	 });	
	
		$(document).on('blur', '#20qty', function(){
         $100qty = $("#20qty").val();
		 
		 $total = $100qty * 20;
		 
	$("#20total").val($total);
			calculateTotal();
		
		 	    
	 
        });
	
		$(document).on('blur', '#10qty', function(){
         $100qty = $("#10qty").val();
		 
		 $total = $100qty * 10;
		 
	$("#10total").val($total);
		
		 	    calculateTotal();
		 
	  
		 
        });
	
		$(document).on('blur', '#5qty', function(){
         $100qty = $("#5qty").val();
		 
		 $total = $100qty * 5;
		 
	$("#5total").val($total);
		
		 	   calculateTotal(); 
		 
	  
		 
        });
	
		$(document).on('blur', '#2qty', function(){
         $100qty = $("#2qty").val();
		 
		 $total = $100qty * 2;
		 
	$("#2total").val($total);
		
		 	  calculateTotal();
		 
	  
		 
        });
		$(document).on('blur', '#1qty', function(){
         $100qty = $("#1qty").val();
		 
		 $total = $100qty * 1;
		 
	$("#1total").val($total);
		
		 	  
		   calculateTotal();
	  
		 
        });
	
		$(document).on('blur', '#fiftyqty', function(){
         $100qty = $("#fiftyqty").val();
		 
		 $total = $100qty * 0.5;
		 
	$("#fiftytotal").val($total);
		
		 	  
		   calculateTotal();
	  
		 
        });
	
		$(document).on('blur', '#twentyqty', function(){
         $100qty = $("#twentyqty").val();
		 
		 $total = $100qty * 0.20;
		 
	$("#twentytotal").val($total);
		
		 	  $total = parseFloat($total).toFixed(2)
		   
	  calculateTotal();
		 
        });
	
		$(document).on('blur', '#tenqty', function(){
         $100qty = $("#tenqty").val();
		 
		 $total = $100qty * 0.10;
		 $total = parseFloat($total).toFixed(2)
	$("#tentotal").val($total);
		
		 	  
		   calculateTotal();
	  
		 
        });
	
		$(document).on('blur', '#fiveqty', function(){
         $100qty = $("#fiveqty").val();
		 
		 $total = $100qty * 0.05;
		$total = parseFloat($total).toFixed(2)
	$("#fivetotal").val($total);
		
		 	  
calculateTotal();
	  
		 
        });
		

	
	function calculateTotal(){
		
		 var grand_total = 0;
   	
	var hundred = $('#100total').val();
	var	fifty = $('#50total').val();
	var	twenty = $('#20total').val();
	var	ten = $('#10total').val();
	var five= $('#5total').val();
	var	two= $('#2total').val();
	var	one= $('#1total').val();
	var	fiftycents= $('#fiftytotal').val();
	var	twentycents= $('#twentytotal').val();
	var	tencents= $('#tentotal').val();
	var	fivecents= $('#fivetotal').val();
            
	var grand_total =  parseFloat(hundred) + parseFloat(fifty)+ parseFloat(twenty) + parseFloat(ten)+parseFloat(five)+parseFloat(two) + parseFloat(one)+ parseFloat(fiftycents) + parseFloat(twentycents) + parseFloat(tencents) + parseFloat(fivecents);
		
$('#totalamount').val(grand_total);
		
	}


</script>

									<?php

if (isset($_POST['cash'])){

	
	
	
	?>


				<h3>Cash in And Out Form</h3>
		<div class="col-sm-4">
		
		<?
	echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') .'" method="post">';
echo '<div>';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
	?>
				
						<label for="name">Amount(+ for cashin and - for cashout) </label>
						<input type="number"  step=".01" name="amount" class="form-control">
					
						<label for="location">Location</label>
		
		<?
	
	echo '<select name="loccode">';



$SQL = "SELECT loccode, locationname
	FROM locations
	";
$ErrMsg = _('The stock locations could not be retrieved');
$DbgMsg = _('SQL used to retrieve the stock locations was') . ':';
$StkLocsResult = DB_query($SQL, $ErrMsg, $DbgMsg);
// COMMENT: What if there is no authorized locations available for this user?
while($myrow=DB_fetch_array($StkLocsResult)) {
	echo '<option value="' . $myrow['loccode'] . '">' . $myrow['locationname']  . '</option>';
}
echo '</select> <br>';
			
					?>
						
							
											
						<label for="terminal">Terminal</label>
						<select name="terminal" class="form-control">
  <option value="Counter 1">Counter 1</option>
  <option value="Counter 2">Counter 2</option>
  <option value="Counter 3">Counter 3</option>

</select>
				
					
						<label for="message">Message</label>
						<textarea name="message" class="form-control"></textarea>
									
					
					<input type="submit" class="btn btn-success" id="submit" name = "processcash">
				
			</form>
</div>

<?
	
	
	
	
}
elseif (isset($_POST['processcash']) ){
		
		$sql17 ="SELECT typeno from systypes where typeid = 71";
			
		$Result = DB_query($sql17);
	
	$myrow17 = DB_fetch_array($Result) ;
			
			$AdjustmentNumber = $myrow17['typeno']+1;
	
	$sqldate = date("Y-m-d");
	$userid = $_SESSION['UserID'];
	
$SQLdebtor = "INSERT INTO possales (
									transno,
									
									type,
									trandate,
									loccode,
									terminal,
								    
									cash_movement_amount,
								    invtext,
									
								    entered_by)
				VALUES (
				
					'CM-" . $AdjustmentNumber. "',
				
				    '71',
					'" . $sqldate . "',
					
					'" . $_POST['loccode'] . "',
					'" . $_POST['terminal'] . "',
					
					
					'" . $_POST['amount']. "',
					
					'" . $_POST['message'] . "',
					
					'" . $userid . "'
				
					)";
		
	//	$result = DB_query($connect,$SQLdebtor);
			
$results = DB_query($SQLdebtor);
	
	
		$sql188 ="UPDATE systypes   SET	typeno ='" . $AdjustmentNumber . "' WHERE typeid = 71";
			
		$Result888 = DB_query($sql188);
	
	
	
		 $message = "Processed";
	echo "<script type='text/javascript'>alert('$message');</script>";
		echo "<script type='text/javascript'>javascript:history.go(-2)</script>";
	// header('Location: POSTrans.php');
	exit();
		
	}

elseif(isset($_POST['closing'])){
	
	
		echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') .'" method="post">';
echo '<div>';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
	
	?>
<div id="dayendreport">

				<h3>End of Day Processing</h3>
				
	
			
			<div class="row">
    <div class="col-sm-2" style="background-color:lavender; font-weight: 800">Notes</div>
     <div class="col-sm-1" style="background-color:lavender; font-weight: 800"> X </div>
    <div class="col-sm-2" style="background-color:lavenderblush;font-weight: 800">Qty</div>
     <div class="col-sm-1" style="background-color:lavender; font-weight: 800"> = </div>
    <div class="col-sm-2" style="background-color:lavender;font-weight: 800">Total</div>
    
  </div>
  		<div class="row">
    <div class="col-sm-2" style="background-color:lightgoldenrodyellow;">$100 Bill</div>
    <div class="col-sm-1" style="background-color:lavender; font-weight: 800"> X </div>
    <div class="col-sm-2" style="background-color:lightgoldenrodyellow;"><input type="number"  step=".01" name="100qty" id ="100qty" class="form-control "></div>
    <div class="col-sm-1" style="background-color:lavender; font-weight: 800"> = </div>
    <div class="col-sm-2" style="background-color:lightgoldenrodyellow;"><input type="number"  step=".01" name="100total" id ="100total" class="form-control 100qty"></div>
    
  </div>
			<div class="row">
    <div class="col-sm-2" style="background-color:orange;">$50 Bill</div>
    <div class="col-sm-1" style="background-color:lavender; font-weight: 800"> X </div>
    <div class="col-sm-2" style="background-color:orange;"><input type="number"  step=".01" name="50qty" id ="50qty" class="form-control"></div>
    <div class="col-sm-1" style="background-color:lavender; font-weight: 800"> = </div>
    <div class="col-sm-2" style="background-color:orange;"><input type="number"  step=".01" name="50total" id ="50total" class="form-control 50 qty"></div>
    
  </div>
					<div class="row">
    <div class="col-sm-2" style="background-color:dodgerblue;">$20 Bill</div>
    <div class="col-sm-1" style="background-color:lavender; font-weight: 800"> X </div>
    <div class="col-sm-2" style="background-color:lavenderblush;"><input type="number"  step=".01" name="20qty" id ="20qty" class="form-control"></div>
    <div class="col-sm-1" style="background-color:lavender; font-weight: 800"> = </div>
    <div class="col-sm-2" style="background-color:lavender;"><input type="number"  step=".01" name="20total" id ="20total" class="form-control"></div>
    
  </div>
					<div class="row">
    <div class="col-sm-2" style="background-color:mediumpurple;">$10 Bill</div>
    <div class="col-sm-1" style="background-color:lavender; font-weight: 800"> X </div>
    <div class="col-sm-2" style="background-color:lavenderblush;"><input type="number"  step=".01" name="10qty" id ="10qty" class="form-control"></div>
    <div class="col-sm-1" style="background-color:lavender; font-weight: 800"> = </div>
    <div class="col-sm-2" style="background-color:lavender;"><input type="number"  step=".01" name="10total" id ="10total" class="form-control"></div>
    
  </div>
					<div class="row">
    <div class="col-sm-2" style="background-color:darkseagreen;">$5 Bill</div>
    <div class="col-sm-1" style="background-color:lavender; font-weight: 800"> X </div>
    <div class="col-sm-2" style="background-color:lavenderblush;"><input type="number"  step=".01" name="5qty" id ="5qty" class="form-control"></div>
    <div class="col-sm-1" style="background-color:lavender; font-weight: 800"> = </div>
    <div class="col-sm-2" style="background-color:lavender;"><input type="number"  step=".01" name="5total" id ="5total" class="form-control"></div>
    
  </div>
					<div class="row">
    <div class="col-sm-2" style="background-color:goldenrod;">$2 Coin </div>
    <div class="col-sm-1" style="background-color:lavender; font-weight: 800"> X </div>
    <div class="col-sm-2" style="background-color:lavenderblush;"><input type="number"  step=".01" name="2qty" id ="2qty" class="form-control"></div>
    <div class="col-sm-1" style="background-color:lavender; font-weight: 800"> = </div>
    <div class="col-sm-2" style="background-color:lavender;"><input type="number"  step=".01" name="2total" id ="2total" class="form-control"></div>
    
  </div>
					<div class="row">
    <div class="col-sm-2" style="background-color:goldenrod;">$1 Coin </div>
    <div class="col-sm-1" style="background-color:lavender; font-weight: 800"> X </div>
    <div class="col-sm-2" style="background-color:lavenderblush;"><input type="number"  step=".01" name="1qty" id ="1qty" class="form-control"></div>
    <div class="col-sm-1" style="background-color:lavender; font-weight: 800"> = </div>
    <div class="col-sm-2" style="background-color:lavender;"><input type="number"  step=".01" name="1total" id ="1total" class="form-control"></div>
    
  </div>
					<div class="row">
    <div class="col-sm-2" style="background-color:silver;">50 Cents Coin </div>
    <div class="col-sm-1" style="background-color:lavender; font-weight: 800"> X </div>
    <div class="col-sm-2" style="background-color:lavenderblush;"><input type="number"  step=".01" name="fiftyqty" id ="fiftyqty" class="form-control"></div>
    <div class="col-sm-1" style="background-color:lavender; font-weight: 800"> = </div>
    <div class="col-sm-2" style="background-color:lavender;"><input type="number"  step=".01" name="fiftytotal" id ="fiftytotal" class="form-control"></div>
    
  </div>
					<div class="row">
    <div class="col-sm-2" style="background-color:silver;">20 Cents Coin</div>
    <div class="col-sm-1" style="background-color:lavender; font-weight: 800"> X </div>
    <div class="col-sm-2" style="background-color:lavenderblush;"><input type="number"  step=".01" name="twentyqty" id ="twentyqty" class="form-control"></div>
    <div class="col-sm-1" style="background-color:lavender; font-weight: 800"> = </div>
    <div class="col-sm-2" style="background-color:lavender;"><input type="number"  step=".01" name="twentytotal" id ="twentytotal" class="form-control"></div>
    
  </div>
					<div class="row">
    <div class="col-sm-2" style="background-color:silver;">10 Cents Coin</div>
    <div class="col-sm-1" style="background-color:lavender; font-weight: 800"> X </div>
    <div class="col-sm-2" style="background-color:lavenderblush;"><input type="number"  step=".01" name="tenqty" id ="tenqty" class="form-control"></div>
    <div class="col-sm-1" style="background-color:lavender; font-weight: 800"> = </div>
    <div class="col-sm-2" style="background-color:lavender;"><input type="number"  step=".01" name="tentotal" id ="tentotal" class="form-control"></div>
    
  </div>
					<div class="row">
    <div class="col-sm-2" style="background-color:lavender;">5 Cents Coin</div>
    <div class="col-sm-1" style="background-color:lavender; font-weight: 800"> X </div>
    <div class="col-sm-2" style="background-color:lavenderblush;"><input type="number"  step=".01" name="fiveqty" id ="fiveqty" class="form-control"></div>
    <div class="col-sm-1" style="background-color:lavender; font-weight: 800"> = </div>
    <div class="col-sm-2" style="background-color:lavender;"><input type="number"  step=".01" name="fivetotal" id ="fivetotal" class="form-control"></div>
    
  </div>
					<div class="row">
    <div class="col-sm-2" style="background-color:lavender;font-weight: 800">Total</div>
     <div class="col-sm-1" style="background-color:lavender; font-weight: 800">  </div>
    <div class="col-sm-2" style="background-color:lavenderblush;"></div>
     <div class="col-sm-1" style="background-color:lavender; font-weight: 800"> </div>
    <div class="col-sm-2" style="background-color:lavender;font-weight: 800""><input type="number"  step=".01" name="totalamount" id ="totalamount" class="form-control" ></div>
    
  </div>	
					
					
					
					
									
			
		
		<?

	?>
				
					<div class="row">
		<div class="col-sm-2">
						<label for="location">Location</label>
		                                        
		<?
	
	echo '<select name="loccode1">';



$SQL = "SELECT loccode, locationname
	FROM locations
	";
$ErrMsg = _('The stock locations could not be retrieved');
$DbgMsg = _('SQL used to retrieve the stock locations was') . ':';
$StkLocsResult = DB_query($SQL, $ErrMsg, $DbgMsg);
// COMMENT: What if there is no authorized locations available for this user?
while($myrow=DB_fetch_array($StkLocsResult)) {
	echo '<option value="' . $myrow['loccode'] . '">' . $myrow['locationname']  . '</option>';
}
echo '</select>';
			
					?>
					
					</div>
						
							
						<div class="col-sm-2">					
						<label for="terminal">Terminal</label>
						<select name="terminal1" class="form-control">
  <option value="Counter 1">Counter 1</option>
  <option value="Counter 2">Counter 2</option>
  <option value="Counter 3">Counter 3</option>

</select>
	</div>
		<div class="col-sm-4">	
				</div>
		
			</div>	
				
											
			
		<div class="col-sm-1">	
					<input type="submit" class="btn btn-success" id="dayend1" name = "dayend">
					
					
			</div>	
			
		
			
			</form>

</div>
</div>




<?
	

	
	
}
elseif (isset($_POST['dayend']) ){
		
		$sql171 ="SELECT typeno from systypes where typeid = 73";
			
		$Result1 = DB_query($sql171);
	
	$myrow171 = DB_fetch_array($Result1) ;
			
			$AdjustmentNumber = $myrow171['typeno']+1;
	
	$sqldate = date("Y-m-d");
	$sqldate1 = date("d-m-Y");
	$userid = $_SESSION['UserID'];
	
$SQLdebtor = "INSERT INTO possales (
									transno,
									
									type,
									trandate,
									loccode,
									terminal,
								    
									day_end_count_total,
								    
									
								    entered_by)
				VALUES (
				
					'DE-" . $AdjustmentNumber. "',
				
				    '73',
					'" . $sqldate . "',
					
					'" . $_POST['loccode1'] . "',
					'" . $_POST['terminal1'] . "',
					
					
					'" .  $_POST['totalamount']. "',
					
					
					'" . $userid . "'
				
					)";
		
	//	$result = DB_query($connect,$SQLdebtor);
			
$results = DB_query($SQLdebtor);
	
	
		$sql188 ="UPDATE systypes   SET	typeno ='" . $AdjustmentNumber . "' WHERE typeid = 73";
			
		$Result888 = DB_query($sql188);
	
	//insert in cash float database
		
	
$SQLcash = "INSERT INTO cashtilcounts (
									date,
									shop,
									terminal,

									100note,
									
									50note,
									20note,
									10note,
									5note,
								    2coin,
								    1coin,
									50cent_coin,
									20cent_coin,
									10cent_coin,
									5cent_coin,
									total_amount,
								    entered_by
									)
				VALUES (
				 '" . $sqldate . "',
				   '" . $_POST['loccode1']. "',
				   '" . $_POST['terminal1']. "',
					'" . $_POST['100qty']. "',
					'" . $_POST['50qty']. "',
					'" . $_POST['20qty']. "',
					'" . $_POST['10qty']. "',
					'" . $_POST['5qty']. "',
					'" . $_POST['2qty']. "',
					'" . $_POST['1qty']. "',
					'" . $_POST['fiftyqty']. "',
					'" . $_POST['twentyqty']. "',
					'" . $_POST['tenqty']. "',
					'" . $_POST['fiveqty']. "',
					'" . $_POST['totalamount']. "',
					
					
					'" . $userid . "'
				
					)";
		
	//	$result = DB_query($connect,$SQLdebtor);
			
$results = DB_query($SQLcash);
	
	//sessions
	$_SESSION['date']	=	$sqldate1;
			$_SESSION['loccode1']	=	$_POST['loccode1'];
	
			$_SESSION['terminal1'] =  $_POST['terminal1'];
			$_SESSION['100qty'] =$_POST['100qty'];
			$_SESSION['50qty']=$_POST['50qty'];
			$_SESSION['20qty'] =$_POST['20qty'];
			$_SESSION['10qty']=$_POST['10qty'];
			$_SESSION['5qty']=$_POST['5qty'];
			$_SESSION['2qty'] =$_POST['2qty'];
			$_SESSION['1qty']=$_POST['1qty'];
	        $_SESSION['fiftyqty']=$_POST['fiftyqty'];
			$_SESSION['twentyqty']=$_POST['twentyqty'];
			$_SESSION['tenqty'] =$_POST['tenqty'];
			$_SESSION['fiveqty']=$_POST['fiveqty'];
	        $_SESSION['totalamount']=$_POST['totalamount'];
	

			$date = $_SESSION['date'];
            $location = $_SESSION['loccode1'];
			$terminal = $_SESSION['terminal1'] ;
			$hundredqty = $_SESSION['100qty'];
			$fiftyqty = $_SESSION['50qty'];
			$twentyqty = $_SESSION['20qty'];
			$tenqty = $_SESSION['10qty'];
			$fiveqty = $_SESSION['5qty'];
			$twoqty = $_SESSION['2qty'];
			$oneqty = $_SESSION['1qty'];
	        $fiftycents = $_SESSION['fiftyqty'];
			$twentycents = $_SESSION['twentyqty'];
			$tencents = $_SESSION['tenqty'];
			$fivecents = $_SESSION['fiveqty'];
	        $totalamount = $_SESSION['totalamount'];


	$sql1711 ="SELECT locationname from locations where loccode ='" . $_POST['loccode1']. "'";
			
		$Result11 = DB_query($sql1711);
	
	$myrow1711 = DB_fetch_array($Result11) ;
	
	$location = $myrow1711['locationname'];
	
	
	
		$sql4 =  "SELECT 
	               possales.trandate,
				   locations.locationname,
				   possales.terminal,
				   
				    DAY(possales.trandate) as dayname,
				   			 MONTH(possales.trandate) as monname,  
							  YEAR(possales.trandate) as yearname,
				     SUM(possales.totalamount) as sales,
					  SUM(possales.rounded_amount) as roundedsales,
					   SUM(possales.day_end_count_total) as dayendcount,
					      SUM(possales.cash_movement_amount) as cashmovement
						 
			FROM possales INNER JOIN locations
						ON possales.loccode = locations.loccode 
			WHERE possales.trandate = '" . $sqldate . "'
			Group by YEAR(possales.trandate),MONTH(possales.trandate),DAY(possales.trandate),possales.loccode,possales.terminal
			Order by possales.trandate DESC
			";
	$ErrMsg = _('This customer could not be added because');
			$result4 = DB_query($sql4,$ErrMsg);
	
	$myrow4 = DB_fetch_array($result4);
	
		$variance =($myrow4['dayendcount'] - ($myrow4['roundedsales'] + $myrow4['cashmovement']));
			$sysbalance =($myrow4['roundedsales'] + $myrow4['cashmovement']);
			$status = "Balanced";
			
			if ($variance < 0){
				
				$status = "DEFICIT";
			}
			if ($variance > 0){
				
				$status = "SURPLUS";
			}
//use this above data in html version of invoice
echo '<div class="container">
            <div class="row">
                <div class="col-lg-9 col-xs-12 col-centered">
				
             ';
	
	
	//echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
	
echo "<div id='printarea' style='text-align: center'>
<div id='printdata'  style='font-size:18px'>
<img src='https://ebusinescloudservers.com/demo/smalllogo1.jpg' width='280px' height='100px'>
<div style='font-weight: 800' >Cash Til Count </div>
<div id='date'style='font-weight: 800' >Date: $date</div>
<div id='loccode'style='font-weight: 800' >$location</div>
<div id='terminal'style='font-weight: 800' >$terminal</div>";

?>
	
    <div style="background-color:lavender; font-weight: 800">Notes &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Qty&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Total </div>
    <div>--------------------------------------------------</div>
   <div style='font-weight: 50'> $100 Bill   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <? echo $hundredqty ; ?>  &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <? $hundredtotal = $hundredqty * 100 ; echo $hundredtotal; ?> 
    </div>
    <div style='font-weight: 50'> $150 Bill   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <? echo $fiftyqty ; ?>  &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <? $fiftytotal = $fiftyqty * 50 ; echo $fiftytotal;?> 
    </div>
    <div style='font-weight: 50'> $120 Bill   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <? echo $twentyqty ; ?>  &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <? $twentytotal = $twentyqty * 20 ; echo $twentytotal; ?> 
    </div>
    <div style='font-weight: 50'> $10 Bill  &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <? echo $tenqty ; ?>  &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <? $tentotal = $tenqty * 10 ; echo $tentotal;?> 
    </div>
    <div style='font-weight: 50'> $5 Bill &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <? echo $fiveqty ; ?>  &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <? $fivetotal = $fiveqty * 5; echo $fivetotal;?> 
    </div>
    <div style='font-weight: 50'> $2coin  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <? echo $twoqty ; ?>  &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <? $twototal = $twoqty * 2 ; echo $twototal;?> 
    </div>
    <div style='font-weight: 50'> $1coin &nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <? echo $oneqty ; ?>  &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <? $onetotal = $oneqty * 1 ; echo $onetotal;?> 
    </div>
    <div style='font-weight: 50'> 50cents &nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <? echo $fiftycents; ?>  &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <? $fiftycentstotal = $fiftycents * 0.5 ; echo $fiftycentstotal;?> 
    </div>
    <div style='font-weight: 50'> 20cents  &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <? echo $twentycents ; ?>  &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <? $twentycentstotal = $twentycents * 0.2 ; echo $twentycentstotal ;?> 
    </div>
    <div style='font-weight: 50'> 10cents &nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <? echo $tencents ; ?>  &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <? $tencentstotal = $tencents * 0.1 ; echo $tencentstotal;?> 
    </div>
    <div style='font-weight: 50'> 5cents  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <? echo $fivecents ; ?>  &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <? $fivecentstotal = $fivecents * 0.05 ; echo $fivecentstotal;?> 
    </div>
  
 
			
	<div>--------------------------------------------------</div>
	
	 <div style='font-weight: 50'> Total Count   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <? echo $totalamount;?> 
    </div>
  <div>--------------------------------------------------</div>
  <div style='font-weight: 50'> POS Sys Balance: &nbsp;&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <? echo $sysbalance;?> 
    </div>
       <div>--------------------------------------------------</div>
  <div style='font-weight: 50'> Cash Movement: &nbsp;&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <? echo $myrow4['cashmovement'];?> 
    </div>
      <div>--------------------------------------------------</div>
  <div style='font-weight: 50'> Variance: &nbsp;&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <? echo $variance;?> 
    </div>
    
      <div>--------------------------------------------------</div>
  <div style='font-weight: 50'> Status: &nbsp;&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <? echo $status;?> 
    </div>
    <div>--------------------------------------------------</div>
    <div>--------------------------------------------------</div>
	<?


echo "<div id='copyright'style='font-size:14px'>---------Powered by E-Business ERP 2.0----------</div>
</div>";

// Replace ... with your PHP Object
	
echo " <br>";


;


echo "<a href='CashTillManagement.php'>  <button type='button' id ='cash' name='cash' class='btn btn-success'>Go to Cash Til Management</button></a><a href='https://ebusinescloudservers.com/demo/erp-vms/POSTrans.php'>  <button type='button' id ='postrans' name='postrans' class='btn btn-info'>Go to POS Trans</button></a> <input type='button' id='btn' value='RePrint' onclick='printData();'></div></div></div></div>";


echo "<script>

$('#btn').trigger('click');

function printData()
{
   var divToPrint=document.getElementById('printdata');
   newWin= window.open('');
   newWin.document.write(divToPrint.innerHTML);
   newWin.print();
   newWin.close();
}


	
	
	
	

	
</script>
";

				
	

	
	
	}

else{
//this is where you paste. Below paste it:
	
	
  $month = date("M"); $currentyear = date("Y"); echo "Showing Current Month Realtime Tallys! for: - ".$month.'-'.$currentyear; ?>
 				

<div class="m-portlet  m-portlet--unair">
							<div class="m-portlet__body  m-portlet__body--no-padding">
								<div class="row m-row--no-padding m-row--col-separator-xl">
										<div class="col-md-12 col-lg-6 col-xl-3">

										<!--begin::New Users-->
										<div class="m-widget24">
											<div class="m-widget24__item">
												<h4 class="m-widget24__title">
													Total Overall Sales
												</h4><br>
												<span class="m-widget24__desc">
														Total Value
												</span>
												<span class="m-widget24__stats m--font-success">
													<?php 
													$monthTotal = date("M");
													$currentmonth = date("m");
													$currentyear = date("Y");
													$currentdate = $currentyear.'-'.$currentmonth.'-1';
														$currentdate2 = $currentyear.'-'.$currentmonth.'-31';
													$SQL =  "select sum(totalamount) as total from possales where type =69 AND trandate between '" . $currentdate. "' AND '" . $currentdate2. "'";
												 		
			$result = DB_query($SQL);  
	
			$myrowuser = DB_fetch_array($result) ;
		$totalTotal= $myrowuser['total'];
													$invoiceTotal= number_format($totalTotal,2,".",",");
													echo "$".$invoiceTotal;
													
													
													
													?>
												</span>
											
											</div>
										</div>

										<!--end::New Users-->
									</div>
										
										
									
								<div class="col-md-12 col-lg-6 col-xl-3">

										<!--begin::New Feedbacks-->
										<div class="m-widget24">
											<div class="m-widget24__item">
												<h4 class="m-widget24__title">
													Refunds
												</h4><br>
												<span class="m-widget24__desc">
													Total Value
												</span>
												<span class="m-widget24__stats m--font-danger">
													<?php 
													
													$SQL1 =  "select sum(totalamount) as total from possales WHERE type =70 AND trandate between '" . $currentdate. "' AND '" . $currentdate2. "' ";
														
														
			$result1 = DB_query($SQL1);
	
			$myrowuser1 = DB_fetch_array($result1) ;
		$total1Total= $myrowuser1['total'];
													$quote1Total = number_format($total1Total,2,".",",");
													echo "$".$quote1Total;
													
													
													
													?>
												</span>
											
											</div>
										</div>

										<!--end::New Feedbacks-->
									</div>
								<div class="col-md-12 col-lg-6 col-xl-3">

										<!--begin::New Feedbacks-->
										<div class="m-widget24">
											<div class="m-widget24__item">
												<h4 class="m-widget24__title">
													Actual Sales:
												</h4><br>
												<span class="m-widget24__desc">
													Total Value
												</span>
												<span class="m-widget24__stats m--font-info">
													<?php 
													$balanceTotal = $totalTotal-$total1Total;
													echo "$".$balanceTotal;
													
													
													
													?>
												</span>
											
											</div>
										</div>

										<!--end::New Feedbacks-->
									</div>
							
								</div>
							</div>
						</div>
     
     
		

   								<div class="row">
									
<div class="col-sm-4">
     
     
     
   
   
									</div></div>
  
 									<?php
	
$userid = $_SESSION['UserID'];

	
    include('xcrud/xcrud.php');
   $invoices= Xcrud::get_instance();
   $invoices->table('possales');
//$xcrud->where('department', 'Fire-Suva');
  //  $quotation->default_tab('Project info');
	
	
   //$invoices = $xcrud->nested_table('Invoice','projectid','debtortrans','projectid'); // 3rd level

//$invoices->or_where('type =', 70);
//$invoices->column_pattern('orderno', '<a href="#" class="xcrud-action" data-task="view" data-primary="{orderno}">{value}</a>');
$invoices->unset_add();
		 $invoices->unset_edit();
			    $invoices->unset_remove();
$invoices->order_by('id','desc');

$invoices->label('transno','Invoice no:');

$invoices->label('trandate','Dated:');
$invoices->label('loccode','Location');

	$invoices->label('totalamount','Total(incl Taxes)');
		

$invoices->label('ovgst','Vat');
$invoices->label('plastic','Plastic Bag Levy');
$invoices->table_name('POS Transactions');
$invoices->button('RePrintReceipt.php?invoicenumber={sdc_invoice_no}&transno={transno}', 'Re-Print Receipt','glyphicon glyphicon-download-alt','westpac');
//$invoices->button('JCEmailInvoice.php?orderno={order_}&transno={transno}', 'Email Invoice','glyphicon glyphicon-envelope','payslipemail');
$invoices->button('RefundReceipt.php?invoicenumber={sdc_invoice_no}&transno={transno}', 'Refund','glyphicon glyphicon-retweet','creditnote');
//$invoices->button('CreditInvoice.php?orderno={order_}&transno={transno}', 'Credit Note','glyphicon glyphicon-cog','payslip');

	  $invoices->relation('debtorno','debtorsmaster','debtorno','name');
	 $invoices->relation('department','department','departmentid','departmentname'); 
$invoices->relation('loccode','locations','loccode','locationname');
 $invoices->relation('type','systypes','typeid','typename');

$invoices->sum('totalamount,rounded_amount,ovgst,stt,ecal,plastic');
$invoices->change_type('totalamount', 'price', '0', array('prefix'=>'$','decimals'=>'2'));
//$invoices->column_pattern('transno', '<a href="#" class="xcrud-action" data-task="view" data-primary="{transno}">{value}</a>');


$salesorderdetails = $invoices->nested_table('Item Line Details','id','possales_details','orderno');
			  $salesorderdetails->unset_add();
			   $salesorderdetails->unset_edit();
			   $salesorderdetails->unset_remove();
$salesorderdetails->table_name('Line item Details');
 
$salesorderdetails->subselect('total','{unitprice}*{quantity}');
$salesorderdetails->sum('total');

$salesorderdetails->change_type('total,unitprice', 'price', '0', array('prefix'=>'$','decimals'=>'2'));
  $salesorderdetails->relation('stkcode','stockmaster','stockid','description');


    echo $invoices->render();
	
$IP = $_SERVER['REMOTE_ADDR']; 
  
// $IP stores the ip address of client 
echo "Your internet global IP address is: $IP <br>";
						 
						 // PHP code to get the MAC address of Client 
$MAC = exec('getmac'); 
  
// Storing 'getmac' value in $MAC 
$MAC = strtok($MAC, ' '); 
  
// Updating $MAC value using strtok function,  
// strtok is used to split the string into tokens 
// split character of strtok is defined as a space 
// because getmac returns transport name after 
// MAC address    
echo "MAC address of client is: $MAC";
						 
						 
echo '</div>';
echo '</div>';






			  
 	echo '</div >';
											  


	echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') .'" method="post">';
echo '<div>';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';

	
	echo '<input type="submit" name="cash" id="cash" class="btn btn-info" value="CASH IN/CASH OUT"  /> <input type="submit" name="closing" id="closing" class="btn btn-info" value="DAY END CLOSING"/>    </form>';


}
	?>


		
		</div>
				</div>
			</div>
					
					

						<!--end:: Widgets/Stats-->

						<!--Begin::Section-->
						

		<!-- end::Quick Sidebar -->

		<!-- begin::Scroll Top -->
		<div id="m_scroll_top" class="m-scroll-top">
			<i class="la la-arrow-up"></i>
		</div>

		<!-- end::Scroll Top -->

		<!-- begin::Quick Nav -->
		

		<!-- begin::Quick Nav -->
<script src="includes/vendors/owl.carousel/dist/owl.carousel.js" type="text/javascript"></script>

		<!--end::Page Scripts -->
	</body>

	<!-- end::Body -->
</html>
 
      
<?php



/*The module link codes are hard coded in a switch statement below to determine the options to show for each tab */
include('includes/MainMenuLinksArray.php');

if (isset($SupplierLogin) AND $SupplierLogin==1){
	echo '<table class="table_index">
			<tr>
			<td class="menu_group_item">
				<p>&bull; <a href="' . $RootPath . '/SupplierTenders.php?TenderType=1">' . _('View or Amend outstanding offers') . '</a></p>
			</td>
			</tr>
			<tr>
			<td class="menu_group_item">
				<p>&bull; <a href="' . $RootPath . '/SupplierTenders.php?TenderType=2">' . _('Create a new offer') . '</a></p>
			</td>
			</tr>
			<tr>
			<td class="menu_group_item">
				<p>&bull; <a href="' . $RootPath . '/SupplierTenders.php?TenderType=3">' . _('View any open tenders without an offer') . '</a></p>
			</td>
			</tr>
		</table>';
	include('includes/footer.inc');
	exit;
} elseif (isset($CustomerLogin) AND $CustomerLogin==1){
	echo '<table class="table_index">
			<tr>
			<td class="menu_group_item">
				<p>&bull; <a href="' . $RootPath . '/CustomerInquiry.php?CustomerID=' . $_SESSION['CustomerID'] . '">' . _('Account Status') . '</a></p>
			</td>
			</tr>
			<tr>
			<td class="menu_group_item">
				<p>&bull; <a href="' . $RootPath . '/SelectOrderItems.php?NewOrder=Yes">' . _('Place An Order') . '</a></p>
			</td>
			</tr>
			<tr>
			<td class="menu_group_item">
				<p>&bull; <a href="' . $RootPath . '/SelectCompletedOrder.php?SelectedCustomer=' . $_SESSION['CustomerID'] . '">' . _('Order Status') . '</a></p>
			</td>
			</tr>
		</table>';

	include('includes/footer.inc');
	exit;
}

if (isset($_GET['Application'])){ /*This is sent by this page (to itself) when the user clicks on a tab */
	$_SESSION['Module'] = $_GET['Application'];
}








//include('includes/footer.inc');

function GetRptLinks($GroupID) {
/*
This function retrieves the reports given a certain group id as defined in /reports/admin/defaults.php
in the acssociative array $ReportGroups[]. It will fetch the reports belonging solely to the group
specified to create a list of links for insertion into a table to choose a report. Two table sections will
be generated, one for standard reports and the other for custom reports.
*/
	global $db, $RootPath, $ReportList;
	require_once('reportwriter/languages/en_US/reports.php');
	require_once('reportwriter/admin/defaults.php');
	$GroupID=$ReportList[$GroupID];
	$Title= array(_('Custom Reports'), _('Standard Reports and Forms'));

	$sql= "SELECT id,
				reporttype,
				defaultreport,
				groupname,
				reportname
			FROM reports
			ORDER BY groupname,
					reportname";
	$Result=DB_query($sql,'','',false,true);
	$ReportList = '';
	while ($Temp = DB_fetch_array($Result)) $ReportList[] = $Temp;

	$RptLinks = '';
	for ($Def=1; $Def>=0; $Def--) {
        $RptLinks .= '<li class="menu_group_headers">';
        $RptLinks .= '<b>' .  $Title[$Def] . '</b>';
        $RptLinks .= '</li>';
		$NoEntries = true;
		if ($ReportList) { // then there are reports to show, show by grouping
			foreach ($ReportList as $Report) {
				if ($Report['groupname']==$GroupID AND $Report['defaultreport']==$Def) {
                    $RptLinks .= '<li class="menu_group_item">';
					$RptLinks .= '<p>&bull; <a href="' . $RootPath . '/reportwriter/ReportMaker.php?action=go&amp;reportid=' . $Report['id'] . '">' . _($Report['reportname']) . '</a></p>';
					$RptLinks .= '</li>';
					$NoEntries = false;
				}
			}
			// now fetch the form groups that are a part of this group (List after reports)
			$NoForms = true;
			foreach ($ReportList as $Report) {
				$Group=explode(':',$Report['groupname']); // break into main group and form group array
				if ($NoForms AND $Group[0]==$GroupID AND $Report['reporttype']=='frm' AND $Report['defaultreport']==$Def) {
                    $RptLinks .= '<li class="menu_group_item">';
					$RptLinks .= '<img src="' . $RootPath . '/css/' . $_SESSION['Theme'] . '/images/folders.gif" width="16" height="13" alt="" />&nbsp;';
					$RptLinks .= '<p>&bull; <a href="' . $RootPath . '/reportwriter/FormMaker.php?id=' . $Report['groupname'] . '"></p>';
					$RptLinks .= $FormGroups[$Report['groupname']] . '</a>';
					$RptLinks .= '</li>';
					$NoForms = false;
					$NoEntries = false;
				}
			}
		}
		if ($NoEntries) $RptLinks .= '<li class="menu_group_item">' . _('There are no reports to show!') . '</li>';
	}
	return $RptLinks;
}
	
?>




