

<?php session_start();
if(empty($_SESSION['id'])):
header('Location:../index.php');
endif;
if(empty($_SESSION['branch'])):
header('Location:../index.php');
endif;

date_default_timezone_set("Asia/Manila"); 
	$date = date("Y-m-d");
	include('../dist/includes/dbcon.php');
	
$id=$_SESSION['id']; 
$query8=mysqli_query($con,"select SUM(amount) as gogo1 from expenses where date='$date' and user_id='$id'")or die(mysqli_error($con));
$row8=mysqli_fetch_array($query8);	
$myexpe=$row8['gogo1']?? null; 
//echo $myexpe;

$query11=mysqli_query($con,"select SUM(amount) as remit from remit where date='$date' and user_id='$id'")or die(mysqli_error($con));
        $row11=mysqli_fetch_array($query11);	
		$muyremit=$row11['remit']?? null;
	
?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>QUOTE SALES | <?php include('../dist/includes/title.php');?></title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="../plugins/datatables/dataTables.bootstrap.css">
    <link rel="stylesheet" href="../dist/css/AdminLTE.min.css">
    <link rel="stylesheet" href="../plugins/select2/select2.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="../dist/css/skins/_all-skins.min.css">
    <style>
      
    </style>
 </head>
  <!-- ADD THE CLASS layout-top-nav TO REMOVE THE SIDEBAR. -->
  <body class="hold-transition skin-<?php echo $_SESSION['skin'];?> layout-top-nav">
    <div class="wrapper">
      <?php include('../dist/includes/header.php');
      include('../dist/includes/dbcon.php');
      ?>
      <!-- Full Width Column -->
      <div class="content-wrapper">
        <div class="container">
          <!-- Content Header (Page header) -->
          <section class="content-header">
            <h1>
              <a class="btn btn-lg btn-warning" href="home.php">Back</a>
              
            </h1>
            <ol class="breadcrumb">
              <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
              <li class="active">TODAYS SALES</li>
            </ol>
          </section>

          <!-- Main content -->
          <section class="content" style="margin-left:-200px;width:1500px;">
            <div class="row" >
	          
			
            <div class="col-xs-16">
              <div class="box box-primary">
    
                <div class="box-header">
						<?php
include('../dist/includes/dbcon.php');

$branch=$_SESSION['branch'];
    $query=mysqli_query($con,"select * from branch where branch_id='$branch'")or die(mysqli_error());
  
        $row=mysqli_fetch_array($query);
        
?>  <center>
                  <h5><b>GLASS and ROOFING DEPARTMENT</b> </h5>  
                  <h6>Address: <?php echo $row['branch_address'];?></h6>
                  <h6>Contact #: <?php echo $row['branch_contact'];?></h6> </center>
                  
				<center>  <h3><b>Cash Sales Report as of <?php echo date("M d, Y",strtotime($date));?></b></h3> </center>
                  
				  <a class = "btn btn-success btn-print" href = "" onclick = "window.print()"><i class ="glyphicon glyphicon-print"></i> Print</a>
							<a class = "btn btn-primary btn-print" href = "home.php"><i class ="glyphicon glyphicon-arrow-left"></i> Back to Homepage</a>   
							 <a href="#updateordinance" data-target="#updateordinance" data-toggle="modal" style="color:black;" class = "btn btn-warning btn-print" ><i class ="glyphicon glyphicon-trash"></i> Cancel Trans</a> 
								
                </div><!-- /.box-header -->
                <div class="box-body" class="col-xs-16">
                	<table id="example1" class="table table-bordered table-striped">
                    <thead>
					<h4>PARTIAL/CASH PAYMENT TODAY</h4>
                      <tr>
					    <th>Branch</th>
                        <th>TR #</th>
                        <th>Customer Name</th>
                        <th>Product</th>
                        
                        <th>Qty</th>
						<th>Price</th>
						<th>Total</th>
                        <th>Discount</th>
                        <th>Partial/CASH Paid</th>
                        <th>Date Paid</th>
						  <th>UNPAID</th>
                      </tr>
                    </thead>
                    <tbody>
<?php

$query=mysqli_query($con,"select * from sales where mydate='$date' and status!='quote'")or die(mysqli_error($con));
		$qty=0;$grand=0;$discount=0;
				while($row=mysqli_fetch_array($query)){
				$sales_id=$row['sales_id'];
				$cust_id=$row['cust_id'];
				
                $total=$row['amount_due'];
				$grand=$grand+$total;
                $discount=$discount+$row['discount'];
				$mybranch=$row['branch_id'];
				if($mybranch == 1){
					$branch="GLASS";
				}else if($mybranch == 2){
					$branch="ROOF";
				}

$query1=mysqli_query($con,"select * from customer where cust_id='$cust_id'")or die(mysqli_error($con));
        $row1=mysqli_fetch_array($query1);	
				
				
		$query2=mysqli_query($con,"select * from sales_details where sales_id='$sales_id'")or die(mysqli_error($con));
        $row2=mysqli_fetch_array($query2);
		$prod_id=$row2['prod_id'] ?? null;
		$query3=mysqli_query($con,"select * from product where prod_id='$prod_id'")or die(mysqli_error($con));
        $row3=mysqli_fetch_array($query3);	

		
			$query9=mysqli_query($con,"select SUM(total) as cashgo from sales where mydate='$date' and modeofpayment='cash'")or die(mysqli_error($con));
        $row9=mysqli_fetch_array($query9);	
		$mycashtotal=$row9['cashgo'];	
			

$query10=mysqli_query($con,"select SUM(discount) as discoko from sales where mydate='$date' and modeofpayment='cash'")or die(mysqli_error($con));
        $row10=mysqli_fetch_array($query10);	
		$mydisc11=$row10['discoko']?? null;		


	$query=mysqli_query($con,"select * from sales where mydate='$date' and modeofpayment!='quote' ")or die(mysqli_error($con));
		$qty=0;$grand=0;$discount=0;
				while($row=mysqli_fetch_array($query)){
				$sales_id=$row['sales_id'];
				$cust_id=$row['cust_id'];
				
                $total=$row['amount_due'];
				
                $discount=$row['discount'];
				$mybranch=$row['branch_id'];
				if($mybranch == 1){
					$branch="GLASS";
				}else if($mybranch == 2){
					$branch="ROOF";
				}else if($mybranch == 3){
					$branch="HARDWARE";
				}
				
				
		
				
			$query1=mysqli_query($con,"select * from customer where cust_id='$cust_id'")or die(mysqli_error($con));
        $row1=mysqli_fetch_array($query1);	
		$query7=mysqli_query($con,"select SUM(partial1) as gogo from sales where mydate='$date' and modeofpayment='partial'")or die(mysqli_error($con));
        $row7=mysqli_fetch_array($query7);	
		$mytotal=$row7['gogo']?? null;
				
		$query2=mysqli_query($con,"select * from sales_details where sales_id='$sales_id'")or die(mysqli_error($con));
        $row2=mysqli_fetch_array($query2);
				$prod_id=$row2['prod_id']?? null;
		$query3=mysqli_query($con,"select * from product where prod_id='$prod_id'")or die(mysqli_error($con));
        $row3=mysqli_fetch_array($query3);	

$query12=mysqli_query($con,"select SUM(discount) as discokofff from sales where mydate='$date' and modeofpayment='partial'")or die(mysqli_error($con));
        $row12=mysqli_fetch_array($query12);	
		$mydisc12=$row12['discokofff']?? null;	

		
				
				
?>
            <tr style=" border: 1px solid black;">
			<td style=" border: 1px solid black;"><?php echo $branch;?></td>
            <td style=" border: 1px solid black;"><?php echo $row['sales_id'];?></td>
            <td style=" border: 1px solid black;"><?php echo $row1['cust_last'].", ".$row1['cust_first'];?></td>
            <td style=" border: 1px solid black;"><?php echo $row3['prod_name']?? null;?></td>
           
            <td style=" border: 1px solid black;"><?php echo $row2['qty']?? null;?></td>
			<td style=" border: 1px solid black;"><?php echo $row2['price']?? null;?></td>
			 <td style=" border: 1px solid black;"><?php echo $row['amount_due']?? null;?></td>
            <td style=" border: 1px solid black;"><?php echo $row['discount']?? null;?></td>
            <td style="text-align:right;border: 1px solid black;"><?php echo number_format($row['partial1'],2);
								?></td>
            <td style=" border: 1px solid black;"><?php echo date("M d, Y h:i a",strtotime($row['mydate']));?></td> 
<?php $javako=number_format($row['amount_due'] - $row['partial1'],2);?>			
			  <td style="text-align:right;border: 1px solid black"><?php if($javako < 0 ) { echo "CHARGE"; }else { echo $javako; }?></td>
		
 <?php } ?>                       
                      </tr>
		
                    </tbody>		
                    <tfoot>
          <tr>
            <th style=" border: 1px solid black;" colspan="2">TOTAL</th>
            <th style=" border: 1px solid black;" style="text-align:right;"><h4><b><?php echo  $grand + $mytotal + $mycashtotal;?></b></h4></th>
			 <th style=" border: 1px solid black;" colspan="2">START UP CASH</th>
			 <?php 
		$queryfund=mysqli_query($con,"select * from pettycash where note='begin' and date='$date'")or die(mysqli_error($con));
        $rowfund=mysqli_fetch_array($queryfund);
		
		$tara9=$rowfund['ii']?? null * 1;
		$timetara=$tara9;
			 ?>
            <th style=" border: 1px solid black;" style="text-align:right;"><h4><b><?php echo $timetara; ?></b></h4></th>
          </tr>             
					<tr>
            <th style=" border: 1px solid black;" colspan="2">LESS:TOTAL DISCOUNT</th>
            <th style=" border: 1px solid black;" style="text-align:right;"><h4><b><?php echo  number_format($mydisc11 + $mydisc12,2);?></b></h4></th>
			<th style=" border: 1px solid black;" colspan="2">TODAYS PAID</th>
			<?php 
		$querypaid=mysqli_query($con,"select SUM(partial1) as gogola from sales where mydate='$date' and modeofpayment='partial' ")or die(mysqli_error($con));
        $rowpaid=mysqli_fetch_array($querypaid);
		?>
            <th style=" border: 1px solid black;" style="text-align:right;"><h4><b><?php echo  $rowpaid['gogola']; ?></b></h4></th>
          </tr>   
		   <tr>
            <th style=" border: 1px solid black;" colspan="2">TOTAL EXPENSES</th>
            <th style=" border: 1px solid black;" style="text-align:right;"><h4><b><?php echo $myexpe;?></b></h4></th>
			<th style=" border: 1px solid black;" colspan="2">CHARGE SALES</th>
            <th style=" border: 1px solid black;" style="text-align:right;"><h4><b><?php echo $rowpaid['gogola'];  ?></b></h4></th>
		</tr> 
		  <?php 
	$totaldiscountpo=$mydisc12; 
	 $gama=$grand + $mytotal + $mycashtotal - $myexpe;  $gamapo=$gama - $muyremit;
		  ?>

          <tr>
            <th style=" border: 1px solid black;" colspan="2">TOTAL CASH SALES</th>
            <th style=" border: 1px solid black;" style="text-align:right;"><h4><b><?php echo $gama?></b></h4></th>
			<th style=" border: 1px solid black;" colspan="2">TODAYS UNPAID</th>
			<?php 
		$queryunpaid=mysqli_query($con,"select SUM(partial3) as hahasi from sales where mydate='$date' ")or die(mysqli_error($con));
        $rowunpaid=mysqli_fetch_array($queryunpaid);
		?>
            <th style=" border: 1px solid black;" style="text-align:right;"><h4><b><?php echo $rowunpaid['hahasi'];?></b></h4></th>
			    </tr>		
		            <tr>
            <th style=" border: 1px solid black;" colspan="2">TOTAL REMITTANCES</th>
            <th style=" border: 1px solid black;" style="text-align:right;"><h4><b><?php echo $muyremit;?></b></h4></th>
			<th style=" border: 1px solid black;" colspan="2">TOTAL PAYABLES</th>
			<?php 
		$querybalance=mysqli_query($con,"select SUM(balance) as loloya from customer where balance > 0 ")or die(mysqli_error($con));
        $rowbalance=mysqli_fetch_array($querybalance);
		?>
            <th style=" border: 1px solid black;" style="text-align:right;"><h4><b><?php echo $rowbalance['loloya']; ?></b></h4></th>
			    </tr>		
		   <tr>
            <th colspan="2" style=" border: 1px solid black;" >REMAINING CASH TO REMIT</th>
            <th style=" border: 1px solid black;" style="text-align:right;"><h4><b><?php $gama=$grand + $mytotal + $mycashtotal + $timetara - $myexpe; echo $gamapo=$gama - $muyremit;?></b></h4></th>
			<th style=" border: 1px solid black;" colspan="2">TOTAL TODAYS CUSTOMERS</th>
			<?php
		$querytimeko=mysqli_query($con,"select DISTINCT(cust_id) from sales where mydate='$date'")or die(mysqli_error($con));
        $rowtimeko=mysqli_num_rows($querytimeko);
		?>
            <th style=" border: 1px solid black;" style="text-align:right;"><h4><b><?php echo  $rowtimeko; ?></b></h4></th>
			    </tr>		
          <tr>
		  
            <th colspan="2" style=" border: 1px solid black;" ></th>
            <th style=" border: 1px solid black;" style="text-align:right;"></th>
			<th style=" border: 1px solid black;color:maroon;font-size:20px;" colspan="2"> TODAYS REMITTABLES</th>
			
            <th style="border: 1px solid black;"> <p style="text-align:right;color:maroon;font-size:20px;"> ₱ <b><?php $gama=$grand + $mytotal + $mycashtotal + $timetara - $myexpe;  echo $gamapo=number_format($gama - $muyremit,2);?> </b></p></th>
                      </tr> 
                      <tr>
                        <th>Prepared by:</th>
                        <th></th>
                        <th></th>
                        <th></th>
                      </tr> 
<?php
    $id=$_SESSION['id'];
    $query=mysqli_query($con,"select * from user where user_id='$id'")or die(mysqli_error($con));
    $row=mysqli_fetch_array($query);
 
?>                      
                      <tr>
                        <th><?php echo $row['name'];?></th>
                        <th></th>
                        <th></th>
                        <th></th>
                      </tr>  			  
        </tfoot>
       </table>
	   
	   
	   
	
	   <?php
	  // $datenewko = date('Y-m-d', strtotime("+1 day"));
	   //mysqli_query($con,"update pettycash set ii='$gamapo', note='begin' where date='$datenewko'")or die(mysqli_error($con));
	   
	   ?>
	  <center> <h3>QUOTE HISTORY TODAY</h3> </center>
	   <table id="example1" class="table table-bordered table-striped">
                    <thead>
                      <tr>
					    <th>Branch</th>
                        <th>TR #</th>
                        <th>Customer Name</th>
                        <th>Product</th>
                        <th>Product Code</th>
                        <th>Qty</th>
						<th>Price</th>
                        <th>Discount</th>
                        <th>Payable </th>
                        <th>Date Paid</th>
                      </tr>
                    </thead>
                    <tbody>
<?php
	$query=mysqli_query($con,"select * from sales natural join sales_details natural join product natural join customer where mydate='$date' and modeofpayment='quote' ")or die(mysqli_error($con));
		$qty=0;$grand=0;$discount=0;
								while($row=mysqli_fetch_array($query)){
                $total=$row['qty']*$row['price'];
				$grand=$grand+$total-$row['discount'];
                $discount=$discount+$row['discount'];
				$mybranch=$row['branch_id'];
				if($mybranch == 1){
					$branch="GLASS";
				}else if($mybranch == 2){
					$branch="ROOF";
				}
				
				
?>
            <tr>
			<td><?php echo $branch;?></td>
            <td><?php echo $row['sales_id'];;?></td>
            <td><?php echo $row['cust_last'].", ".$row['cust_first'];?></td>
            <td><?php echo $row['prod_name'];?></td>
            <td><?php echo $row['serial'];?></td>
            <td><?php echo $row['qty'];?></td>
						<td><?php echo $row['price'];?></td>
            <td><?php echo $row['discount'];?></td>
            <td style="text-align:right"><?php echo number_format($row['total'],2);
								?></td>
            <td><?php echo date("M d, Y h:i a",strtotime($row['mydate']));?></td>    
			
		
				<?php } } ?>                       
                      </tr>
		
                    </tbody>
                   </table>
				   <?php
				   	$queryfund1=mysqli_query($con,"select * from pettycash where note='begin' and date='$date'")or die(mysqli_error($con));
        $rowfund1=mysqli_fetch_array($queryfund1);
		?>
	      <h3>CASH BEGIN:<?php echo $rowfund1['ii'];?></h3>
                </div><!-- /.box-body -->
 
            </div><!-- /.col -->
			
			
          </div><!-- /.row -->
	 
            
			
<div id="updateordinance" class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
	<div class="modal-dialog" style="width:200px;height:auto">
	  <div class="modal-content" style="height:auto">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">×</span></button>
                <h4 class="modal-title">CANCEL TRANSACTION </h4>
              </div>
              <div class="modal-body">
			  <form action="canceltrans.php" method="POST">
			  <label>Enter Trans No: SN0__</label>
				<div class="form-group">
					<input name="transsn" style="font-size:24px;width:150px;" type="number" />
	<label>Enter Void Passcode</label>
				<div class="form-group">
					<input name="adminpasscode" style="font-size:24px;width:150px;" type="password" />
<input name="remitid" type="hidden" value="<?php echo $row['id'];?>"/>
 <button class="btn btn-primary" id="daterange-btn" name="submitko">
							Submit
						  </button>
              </div><hr>
			  </form>
              <div class="modal-footer">
	<h5 style="text-align:center;">Please enter the TR# and void code of administrator </h5>
              </div>
		
            </div>
			
        </div><!--end of modal-dialog-->
 </div>
 <!--end of modal-->  
			
			
			
			
			
			
			
			
          </section><!-- /.content -->
        </div><!-- /.container -->
      </div><!-- /.content-wrapper -->
      <?php include('../dist/includes/footer.php');?>
    </div><!-- ./wrapper -->

    <!-- jQuery 2.1.4 -->
    <script src="../plugins/jQuery/jQuery-2.1.4.min.js"></script>
    <!-- Bootstrap 3.3.5 -->
    <script src="../bootstrap/js/bootstrap.min.js"></script>
    <script src="../plugins/select2/select2.full.min.js"></script>
    <!-- SlimScroll -->
    <script src="../plugins/slimScroll/jquery.slimscroll.min.js"></script>
    <!-- FastClick -->
    <script src="../plugins/fastclick/fastclick.min.js"></script>
    <!-- AdminLTE App -->
    <script src="../dist/js/app.min.js"></script>
    <!-- AdminLTE for demo purposes -->
    <script src="../dist/js/demo.js"></script>
    <script src="../plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="../plugins/datatables/dataTables.bootstrap.min.js"></script>
    
    <script>
      $(function () {
        $("#example1").DataTable();
        $('#example2').DataTable({
          "paging": true,
          "lengthChange": false,
          "searching": false,
          "ordering": true,
          "info": true,
          "autoWidth": false
        });
      });
    </script>
     <script>
      $(function () {
        //Initialize Select2 Elements
        $(".select2").select2();

        //Datemask dd/mm/yyyy
        $("#datemask").inputmask("dd/mm/yyyy", {"placeholder": "dd/mm/yyyy"});
        //Datemask2 mm/dd/yyyy
        $("#datemask2").inputmask("mm/dd/yyyy", {"placeholder": "mm/dd/yyyy"});
        //Money Euro
        $("[data-mask]").inputmask();

        //Date range picker
        $('#reservation').daterangepicker();
        //Date range picker with time picker
        $('#reservationtime').daterangepicker({timePicker: true, timePickerIncrement: 30, format: 'MM/DD/YYYY h:mm A'});
        //Date range as a button
        $('#daterange-btn').daterangepicker(
            {
              ranges: {
                'Today': [moment(), moment()],
                'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                'Last 7 Days': [moment().subtract(6, 'days'), moment()],
                'Last 30 Days': [moment().subtract(29, 'days'), moment()],
                'This Month': [moment().startOf('month'), moment().endOf('month')],
                'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
              },
              startDate: moment().subtract(29, 'days'),
              endDate: moment()
            },
        function (start, end) {
          $('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
        }
        );

        //iCheck for checkbox and radio inputs
        $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
          checkboxClass: 'icheckbox_minimal-blue',
          radioClass: 'iradio_minimal-blue'
        });
        //Red color scheme for iCheck
        $('input[type="checkbox"].minimal-red, input[type="radio"].minimal-red').iCheck({
          checkboxClass: 'icheckbox_minimal-red',
          radioClass: 'iradio_minimal-red'
        });
        //Flat red color scheme for iCheck
        $('input[type="checkbox"].flat-red, input[type="radio"].flat-red').iCheck({
          checkboxClass: 'icheckbox_flat-green',
          radioClass: 'iradio_flat-green'
        });

        //Colorpicker
        $(".my-colorpicker1").colorpicker();
        //color picker with addon
        $(".my-colorpicker2").colorpicker();

        //Timepicker
        $(".timepicker").timepicker({
          showInputs: false
        });
      });
    </script>
  </body>
</html>
