<?php
if(basename($_SERVER['PHP_SELF']) == 'zreport.php') 
  $fn=" class='current'";
include'header.php';
include'connection.php';
$dato=$datos=$Date;
$custo=$conde='';
$k=$p=0;

// search for an item to be added to the chart
if(isset($_POST['search']))
		{
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			$custo=$_POST['custo'];
			$conde="AND `Date` BETWEEN '$dato' AND '$datos'";
			$p=1;

			if($custo)
				$condi="AND `Location`='$custo'";
		}
		
		
		
	if(isset($_POST['addo']))
		{
			$dati=$_POST['dati'];
			$dato=$datos=$dati;
			$sales=str_replace(',', '', $_POST['sales']);
			$vat=str_replace(',', '', $_POST['vat']);
			$sp=$_POST['sp'];
			$conde="AND `Date` BETWEEN '$dato' AND '$datos'";
			$p=1;
			
		$sso=mysqli_query($conn, "DELETE FROM `z-report` WHERE `Date`='$dati' AND `Location`='$sp'");
			
	$so=mysqli_query($conn, "INSERT INTO `z-report` (`Number`, `Date`, `User`, `Location`, `Sales`, `Vat`) VALUES (NULL, '$dati', '$loge', '$sp', '$sales', '$vat')");
		}
		
		
if(isset($_POST['delo']))
		{
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			$custo=$_POST['custo'];
			$rowid=$_POST['rowid'];
			$conde="AND `Date` BETWEEN '$dato' AND '$datos'";
			$p=$_POST['p'];
			
	$sso=mysqli_query($conn, "DELETE FROM `z-report` WHERE `Number`='$rowid'");

			if($custo)
				$condi="AND `Location`='$custo'";
		}
		
	if(isset($_POST['updo']))
		{
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			$custo=$_POST['custo'];
			$rowid=$_POST['rowid'];$dati=$_POST['dati'];
			$sales=str_replace(',', '', $_POST['sales']);
			$vat=str_replace(',', '', $_POST['vat']);
			$sp=$_POST['sp'];
			$conde="AND `Date` BETWEEN '$dato' AND '$datos'";
			$p=$_POST['p'];
			
	$sso=mysqli_query($conn, "UPDATE `z-report` SET `Date`='$dati', `Location`='$sp', `Sales`='$sales', `Vat`='$vat' WHERE `Number`='$rowid'");

			if($custo)
				$condi="AND `Location`='$custo'";
		}

		if($dato==$datos)
			$mpri="ON $dato";
		else
			$mpri="FROM $dato TO $datos";
?>


<script src="style/tableExport.js"></script>
<script type="text/javascript" src="style/jquery.base64.js"></script>
<script src="style/export.js"></script>


<div class="container-fluid main-content">
        <div class="page-title hidden-xs hidden-print">
          <h2 style='margin-top:-20px; margin-bottom: 5px; color:#ffcc33'>
         Finance
          </h2>
                 </div>
     
        <div class="row">
  <div class="col-lg-2 hidden-print">
   
   <ul class="list-group">  

    <li class="list-group-item">
	  <a href="salesrepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Sales Report
                </p>
              </a></li> 

    <li class="list-group-item">
	  <a href="purchase.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Purchase Orders
                </p>
              </a></li>   

    <li class="list-group-item">
	  <a href="trans.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Service Providers
                </p>
              </a></li> 

    <li class="list-group-item">
	  <a href="experepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Payout/Expenses
                </p>
              </a></li>  

    <li class="list-group-item active">
	  <a href="zreport.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Daily Z-Report
                </p>
              </a></li>   

    <li class="list-group-item">
	  <a href="taxrepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;VAT/TAX Report
                </p>
              </a></li>    

    <li class="list-group-item">
	  <a href="assets.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Assets Report
                </p>
              </a></li> 
                       
            </ul><br><br><br>
  </div>
                    
     <?php
        include'zmodal.php';
        ?>
       
        <form action="" method="post" class="form-horizontal "> 
        <div class="col-lg-10">
                  <div class="row">

                    <div class="col-lg-2" style="padding-left:40px;">
       <button class="btn  btn-warning btn-block" type="button" data-toggle='modal' data-target='#Modaldis' stle="font-size:13px;">Z-REPORT</button></div> 

				  <div class="col-lg-2"> </div>        

                         
                       <div class="col-lg-8 hidden-print">
                 <div class="col-lg-3">
			<select class="form-control" name="custo">
				<option value='' selected='selected'>SELECT POINT</option>
			 <?php
	$doi=mysqli_query($conn, "SELECT `Location` FROM `z-report` WHERE `Status`='0' AND `Location`!='' GROUP BY `Location` ORDER BY `Location` ASC");
			while($roi=mysqli_fetch_assoc($doi)){
				$desto=$roi['Location'];
				if($desto==$custo)
					$sle="selected='selected'";
				else
					$sle='';
			echo"<option value='$desto' $sle> $desto </option>";
			}
			?>    
                            </select>
					   </div>
            <div class="col-lg-3"> 
           <div class="input-group date" data-provide="datepicker">
      <input class="form-control form-center" id="from" name="dato" type="text" value="<?php echo $dato ?>" onkeypress='return isNumberKey(event)' required><span class="input-group-addon"><i class="lnr lnr-calendar-full"></i></span>
			</div></div>


		  <div class="col-lg-3"> 
           <div class="input-group date" data-provide="datepicker">	
      <input class="form-control form-center" id="to" name="datos" type="text" value="<?php echo $datos ?>" onkeypress='return isNumberKey(event)' required><span class="input-group-addon"><i class="lnr lnr-calendar-full"></i></span>
              </div></div>                      
                       
                       <div class="col-lg-2">
                        <button class="btn  btn-primary btn-block" type="submit" name="search"><i class="lnr lnr-magnifier"></i> Search</button>
                   
					  </div>
                         </div> 
                      
                     
                  
            </form> 

			</div>
<?php
			 if($p)
$do=mysqli_query($conn, "SELECT *FROM `z-report` WHERE `Status`='0' $conde $condi ORDER BY `Number` ASC");
	else
$do=mysqli_query($conn, "SELECT *FROM (SELECT *FROM `z-report` WHERE `Status`='0' ORDER BY `Date` DESC LIMIT 15) SUB ORDER BY `Date` ASC");
$fo=mysqli_num_rows($do);
?>


<div class="divFooter"><center><u><b>DAILY Z-REPORT <?php echo"$mpri"; ?></b></u></center></div>
             <div class="row">
            <div class="col-lg-12" style='margin-top:-20px;'>
             <span> &nbsp;&nbsp; Total Records Found : <b><?php echo" $fo " ?></b></span>
		<span class="pull-right">&nbsp;&nbsp;&nbsp;&nbsp;
		<a href="#" onclick="return window.print()" class="hidden-print" title='Click to print' data-toggle='tooltip' data-placement='top'><i class="lnr lnr-printer"></i></a></span> 
			 
			 <span class="pull-right hidden-print">
			 &nbsp;&nbsp;&nbsp;&nbsp;<button type="button" class="btn btn-default btn-xs dataExport" data-type="excel">Export <span class="caret"></span></button>
			 
			 &nbsp;&nbsp;&nbsp;&nbsp;
			 <a href="#" onclick="exportTableToExcel('tblData')" class="hidden-print" title='Export to excell' data-toggle='tooltip' data-placement='top'><i class="lnr lnr-line-spacing"></i></a></span>
		 
            <div class="widget-container fluid-height clearfix">
            <div class="widget-content padded clearfix">
               
    <table class="table table-striped table-hover" id="tblData">     
                    <thead>
                    <tr role="row"><th> No </th>
                        <th><div align='center'> DATE </th>
                        <th><div align='center'> SYSTEM&nbsp;USER </th>
                       <th><div align='center'> SALES&nbsp;POINT </th>
                       <th><div align='center'> SALES&nbsp;AMOUNT </th>
					   <th><div align='center'> VAT&nbsp;AMOUNT </th>
						 <th><div align='center'> VALUE </th>
				<th colspan='2'><div align='center'> OPTIONS </th>
                     </tr>
                    </thead>
                                        <tbody>
					<?php
					$n=1;				$tsa=$tva=$tvl=0;
						while($ro=mysqli_fetch_assoc($do)){
				$code=$ro['Number'];
				$dest=$ro['Location'];
				$dat=$ro['Date'];
			$sa=$ro['Sales'];
			$va=$ro['Vat'];
			$val=$sa-$va;
			$user=$ro['User'];

			$sao=number_format($sa,2);		
			$vao=number_format($va,2);			
			$valo=number_format($val,2);
			$stl="style='padding:1px;'";
		 
		print("<tr><td $stl><div align='right'>$n&nbsp;&nbsp;</td>
						<td class='text-center' $stl> $dat </td>
						<td $stl> $user </td><td $stl> $dest </td>
						<td $stl class='text-right'> $sao </td>
						<td $stl class='text-right'> $vao </td>
		<td class='text-right' style='padding:1px 10px 1px 1px;'> $valo &nbsp;&nbsp;");
		
		echo"<div class='modal fade text-left' id='exampleModal$n' tabindex='-1' role='dialog' aria-labelledby='exampleModalLabel' aria-hidden='true' 
		style='top:220px;'>
  <div class='modal-dialog' role='document'>
    <div class='modal-content text-left'>
      <div class='modal-header'>
        <h5 class='modal-title' id='exampleModalLabel'>DELETE CONFIRMATION 
<label class='text-right pull-right'> $dat &nbsp; $dest </h5>

      </div>
      <div class='modal-body' style='height:40px;'>
        <h5 style='color:#ff0033'>Do you want to delete this record?</h5>
      </div><br><form method='post' action=''><input type='hidden' name='rowid' value='$code'><input type='hidden' name='custo' value='$custo'>
      <input type='hidden' name='dato' value='$dato'><input type='hidden' name='datos' value='$datos'><input type='hidden' name='p' value='$p'>
      <div class='modal-footer' style='margin-top:-10px; height:50px; padding-top:5px; border:0px solid blue;'>
        <button type='button' class='btn btn-sm btn-success' data-dismiss='modal'>&nbsp;NO&nbsp;</button>
        <button type='submit' name='delo' class='btn btn-sm btn-danger'>YES</button>
      </div></form>
    </div>
  </div>
</div>";


 echo"<div class='modal fade' id='Modaldis$n' tabindex='-1' role='dialog' aria-labelledby='exampleModalLabel' aria-hidden='true'>
  <div class='modal-dialog' role='document'><div class='modal-content'><div class='modal-header text-left'>
        <h5 class='modal-title' id='exampleModalLabel'>Z-REPORT
        <button class='pull-right close' data-dismiss='modal' type='button'>&times;</button></h5>

      </div><form action='' method='post'>
      <div class='modal-body text-left'><div class='row'>
			 	
		 <div class='form-group'>	 
			  <div class='col-md-5' align='right'>
			  <label class='control-label' style='padding-top:10px;'>Sales Date</label></div>	

	 <div class='col-md-6'>
	    <div class='input-group date' data-provide='datepicker'>
          <input name='dati' class='form-control text-center' type='text' value='$dat' onkeypress='return isNumberKey(event)' required>
	  <span class='input-group-addon'><i class='lnr lnr-calendar-full'></i></span></div></div>
		</div><div class='row'> </div>
		
			<div class='form-group'>	 
	    <div class='col-md-5' align='right'>
	<label class='control-label'> &nbsp; </label></div>	

	 <div class='col-md-6'> &nbsp; </div>
		</div><div class='row'> </div>

        <div class='form-group'>
			<div class='col-md-5' align='right'> 
    <label class='control-label' style='padding-top:10px;'>Sales Point</label>
        </div>
            <div class='col-md-6'>
<select class='form-control' name='sp' style='font-size:16px; height:34px;' required><option value=''> </option>";
        
        
    $_SESSION['Base']="jblgroup_sales";
        include'sales.php';
    $sso=mysqli_query($cons, "SELECT `Branch` FROM `datatable` WHERE `Status`='0' ORDER BY `Number` ASC");
		while($rro=mysqli_fetch_assoc($sso)){
			$pla=$rro['Branch'];
			if($pla==$dest)
			    $s='selected';
			else
			    $s='';
		echo"<option value='$pla' $s> $pla </option>";
		}
		include'connection.php';
		echo"</select>
            </div></div>
		<div class='row'> </div>
		
			<div class='form-group'>	 
			  <div class='col-md-5' align='right'>
			  <label class='control-label'> &nbsp; </label></div>	

	 <div class='col-md-6'> &nbsp; </div>
		</div>
		<div class='row'> </div>
			 	
		 <div class='form-group'>	 
			  <div class='col-md-5' align='right'>
		<label class='control-label' style='padding-top:10px;'>Sales / Vat </label></div>	

	 <div class='col-md-3'>
          <input name='sales' class='form-control text-center' type='text' onkeyup='format(this);' onkeypress='return isNumberKey(event)' value='$sao' required>
            </div><div class='col-sm-3 col-xs-5' style='padding-left:0px; margin-left:0px;'>
	    
	    
          <input name='vat' class='form-control text-center' type='text' onkeyup='format(this);' onkeypress='return isNumberKey(event)' value='$vao' required></div>
		</div>

		
	</div></div>
	
	<div class='modal-header text-right' style='height:50px; padding-top:15px;'>	<input type='hidden' name='rowid' value='$code'><input type='hidden' name='custo' value='$custo'>
      <input type='hidden' name='dato' value='$dato'><input type='hidden' name='datos' value='$datos'><input type='hidden' name='p' value='$p'>
		<button type='button' class='btn btn-xs btn-danger' data-dismiss='modal' style='width:80px; height:26px;'> CANCEL </button>
        <button type='submit' name='updo' class='btn btn-xs btn-success' style='width:80px; height:26px;'> UPDATE </button></div>
      </form>
  </div></div>
</div>";
						
				print("</td><td class='hidden-xs hidden-print' align='right' style='width:30px; padding:0px;'><div title='Edit' data-toggle='tooltip' data-placement='top'>
                          <button type='button' class='btn btn-xs btn-warning hidden-print' style='height:20px; padding:0px; margin:2px;' data-placement='top'
						  data-toggle='modal' data-target='#Modaldis$n'>
						  &nbsp;&nbsp;<i class='lnr lnr-pencil'></i>&nbsp;&nbsp;</button></div></td></form>
						  
						  <form method=post action=''><td class='hidden-xs hidden-print' align='right' style='width:30px; padding:0px;'><div title='Delete' data-toggle='tooltip' data-placement='top'>
                          <button type='button' class='btn btn-xs btn-danger hidden-print' style='height:20px; padding:0px; margin:2px;' data-placement='top'
						  data-toggle='modal' data-target='#exampleModal$n'>
						  &nbsp;&nbsp;<i class='lnr lnr-trash'></i>&nbsp;&nbsp;</button></div></td></form></tr>");
							$n++;                  $tsa+=$sa;           
							$tva+=$va;              $tvl+=$val;
						}
						$tsa=number_format($tsa, 2);
						$tva=number_format($tva, 2);
						$tvl=number_format($tvl, 2);					
						?>
						
                    </tbody>
	<tr><th> </th><th colspan='3'>&nbsp;&nbsp;&nbsp;&nbsp; TOTAL VALUE </th>
					<th class='text-right'><?php echo $tsa ?></th>
					<th class='text-right'><?php echo $tva ?></th>
					<th class='text-right'><?php echo $tvl ?>&nbsp;&nbsp;</th>
					<th class='text-center' colspan='2'> -- </th></tr>
                  </table>
              </div></div>

                  </div>                     
                
              </div><span class="pull-right hidden-print">
			 &nbsp;&nbsp;&nbsp;&nbsp;<a href="#" onclick="return window.print()" class="hidden-print" title='Click to print' data-toggle='tooltip' data-placement='top'><i class="lnr lnr-printer"></i></a></span>
			 
			 <span class="pull-right hidden-print">
			 &nbsp;&nbsp;&nbsp;&nbsp;<a href="#" onclick="exportTableToExcel('tblData')" class="hidden-print" title='Export to excell' data-toggle='tooltip' data-placement='top'><i class="lnr lnr-line-spacing"></i></a></span>
			 
            </div></div>
                  </div>
        
   <?php
   include'footer.php';
   ?>
