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


date_default_timezone_set("Asia/Manila"); 
	$date = date("Y-m-d");
?>
<!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">
    <script src="../dist/js/jquery.min.js"></script>
    <script language="JavaScript"><!--
javascript:window.history.forward(1);
//--></script>
    <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">QUOTE TODAYS LIST</li>
            </ol>
          </section>

          <!-- Main content -->
          <section class="content">
            <div class="row">
	          
			
            <div class="col-xs-12">
              <div class="box box-primary">
    
                <div class="box-header">
                  <h3 class="box-title">QUOTE TODAYS LISTS</h3>
                </div><!-- /.box-header -->
                <div class="box-body">
                  <table id="example1" class="table table-bordered table-striped">
                    <thead>
                      <tr>
            						<th>Sales Id #</th>
            						<th>Date and Time</th>
                        <th>Customer Last Name</th>
                        <th>Customer First Name</th>
                        <th>Address</th>
            						<th>Contact #</th>
            						<th>Total Amount</th>
                        <th>Status/Delivery</th>
<th>BRANCH</th>						
                        <th>Action</th>
						
                      </tr>
                    </thead>
                    <tbody>
<?php
		$branch=$_SESSION['branch'];
		$query=mysqli_query($con,"select * from sales where modeofpayment='quote' order by sales_id DESC ")or die(mysqli_error());
		$i=1;
		while($row=mysqli_fetch_array($query)){
		$cid=$row['cust_id'];
		$salesid=$row['sales_id'];
		$branch_id=$row['branch_id'];
		if($branch_id == 1){
			$branchko="GLASS";
		}else if($branch_id == 2){
			$branchko="ROOF";
		}else if($branch_id == 3){
			$branchko="STEEL";
		}
		$query1=mysqli_query($con,"select * from customer where cust_id='$cid'")or die(mysqli_error());
		$row1=mysqli_fetch_array($query1);
			$query2=mysqli_query($con,"select * from payment where sales_id='$salesid'")or die(mysqli_error());
		$row2=mysqli_fetch_array($query2);
		
?>
                      <tr>
					   <td style="width:100px;">SN#: <p style="color:maroon;font-size:16px;font-weight:bold;"><?php echo $row['sales_id'];?> </p></td>
						<td><?php echo $row['date_added'];?></td>
                          <td><p style="color:#191970;font-size:16px;font-weight:bold;"><?php echo $row1['cust_last'];?></p></td>
                        <td><p style="color:#191970;font-size:16px;font-weight:bold;"><?php echo $row1['cust_first'];?></p></td>
                        <td><?php echo $row1['cust_address'];?></td>
						<td><?php echo $row1['cust_contact'];?></td>
						<td><?php echo number_format($row['total'],2);?></td>
            <td><?php echo $row['delivery'];?></td>
			 <td><?php echo $branchko;?></td>
                        <td>
				<!-- <a href="><i class="glyphicon glyphicon-share-alt text-green"></i></a> 
				<a href="reprintko.php?sid=<?php echo $row['sales_id'];?>">GO<i class="glyphicon glyphicon-share-alt text-green"></i></a> -->
				<a href="#updateordinance<?php echo $row['sales_id'];?>" data-target="#updateordinance<?php echo $row['sales_id'];?>" data-toggle="modal" style="color:#fff;" class="small-box-footer"><i style="font-size:30px;"class="glyphicon glyphicon-check text-blue"></i></a>
						</td>
                      </tr>
					  
					<div id="updateordinance<?php echo $row['sales_id'];?>" class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
	<div class="modal-dialog">
	  <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">Update Product Details</h4>
              </div>
              <div class="modal-body">
			  <form method="post" name="autoSumForm" action="sales_addupdate.php">
				  <div class="row">
					 <div class="col-md-12">
						  
						  <?php 
						  $mys=$row['sales_id'];
						  
						  $myidpo=$_SESSION['id'];
						  $query1=mysqli_query($con,"select * from sales where sales_id='$mys'")or die(mysqli_error());
		                  $row1=mysqli_fetch_array($query1);
						  $custid=$row1['cust_id'];
						  $mytotal=$row1['total'];
						  $discount=$row1['discount'];
						   $custidlo=$row1['cust_id'];
						  $amount_due=$row1['amount_due'];
						   $cash_tendered=$row1['cash_tendered'];
						    $cash_change=$row1['cash_change'];
						   $query1=mysqli_query($con,"select * from customer where cust_id='$custid'")or die(mysqli_error());
		                  $row4=mysqli_fetch_array($query1);
						  $cust_first=$row4['cust_first'];
						   $cust_last=$row4['cust_last'];
						  
						  
						  ?>
						  
						  
						  <h2>Customer Name: <?php echo $cust_last;?>, &nbsp <?php echo $cust_first;?></h2>
						  <div class="form-group">
							<label for="date">Total</label>
								<input type="hidden" style="text-align:right" class="form-control" id="total" name="salesid" value="<?php echo $row['sales_id'];?>">
								<input type="hidden" style="text-align:right" class="form-control" id="total" name="myidcust" value="<?php echo $myidpo;?>">
								<input type="hidden" style="text-align:right" class="form-control" id="total" name="custid" value="<?php echo $custid;?>">
								<input type="text" style="text-align:right;font-size:24px;" class="form-control" id="total" name="total" placeholder="Total" 
								value="<?php echo $amount_due;?>" onFocus="startCalc();" onBlur="stopCalc();"  tabindex="5" readonly>
							
						  </div><!-- /.form group -->
						  <div class="form-group">
							<label for="date">Discount</label>
								<input type="text" style="text-align:right" class="form-control" id="amount_due" name="discount" placeholder="Amount Due" value="<?php echo number_format($discount,2);?>"  readonly>
						  </div><!-- /.form group -->
						  <div class="form-group">
							<label for="date">Amount Due</label>
								<input type="text" style="text-align:right;font-size:24px;" class="form-control" id="amount_due" name="amount_due" placeholder="Amount Due" value="<?php echo number_format($mytotal,2);?>"  readonly>
						  </div><!-- /.form group -->
						     <p style="color:blue;font-size:24px;" ><?php if($cash_tendered < 1 ){ ?> UNPAID <?php }else { ?> PARTIAL/PAID <?php  }?></p>
              <div class="form-group" id="tendered">
		<label for="date">Downpayment Cash Amount </label>  <br>
                <input type="text" class="form-control" style="text-align:right;font-size:30px;color:red;" onFocus="startCalc();" onBlur="stopCalc();"  id="cash" name="tendered" placeholder="Cash Tendered" value="<?php echo $cash_tendered;?>" readonly>
              </div><!-- /.form group -->
              <div class="form-group" id="change">
                <label for="date">Change/Balance if negative =balance / positive=change</label><br>
                <input type="text" style="text-align:right" class="form-control" id="changed" name="changeko" placeholder="Change" value="<?php  echo $cash_change; ?>" readonly>
              </div><!-- /.form group -->
					</div>
					
					

				</div>	
               
                  
                 
                     
				
					   <?php 
					    $myid=$_SESSION['id'];
						$query5=mysqli_query($con,"select * from user where user_id='$myid'")or die(mysqli_error());
			           $row5=mysqli_fetch_array($query5);
					   $mytype=$row5['type'];
					   
					   if($mytype == 1){
					   ?>
					  <br>
                      <button class="btn btn-lg btn-block btn-primary" id="daterange-btn" name="cash" type="submit"  tabindex="7">
                        Complete Sales
                      </button>
					   <?php }else {} ?>
					  
					  
					  <button class="btn btn-lg btn-block" id="daterange-btn" class="close" data-dismiss="modal" aria-label="Close"  tabindex="8">
                        <a href="cancel.php">Cancel Sale</a>
                      </button>
              
				</form>	
            </div>
			
        </div><!--end of modal-dialog-->
 </div>
 <!--end of modal-->   
					  
					  
					  
		           
<?php $i++;}?>					  
                    </tbody>
                    <tfoot>
                      <tr>
                       <th>Sales Id #</th>
            						<th>Branch</th>
                        <th>Customer Last Name</th>
                        <th>Customer First Name</th>
                        <th>Address</th>
            						<th>Contact #</th>
            						<th>Total Amount</th>
                        <th>Status/Delivery</th>	
						 <th>Date</th>	
                        <th>Action</th>
                      </tr>					  
                    </tfoot>
                  </table>
                </div><!-- /.box-body -->
 
            </div><!-- /.col -->
			
			
          </div><!-- /.row -->
	 
            
          </section><!-- /.content -->
        </div><!-- /.container -->
      </div><!-- /.content-wrapper -->
      <?php include('../dist/includes/footer.php');?>
    </div><!-- ./wrapper -->
	<script>
  
    
      $("#cash").click(function(){
          $("#tendered").show('slow');
          $("#change").show('slow');
      });

    $(function() {

      $(".btn_delete").click(function(){
      var element = $(this);
      var id = element.attr("id");
      var dataString = 'id=' + id;
      if(confirm("Sure you want to delete this item?"))
      {
	$.ajax({
	type: "GET",
	url: "temp_trans_del.php",
	data: dataString,
	success: function(){
		
	      }
	  });
	  
	  $(this).parents(".record").animate({ backgroundColor: "#fbc7c7" }, "fast")
	  .animate({ opacity: "hide" }, "slow");
      }
      return false;
      });

      });
    </script>
	
	<script type="text/javascript" src="autosum.js"></script>
    <!-- jQuery 2.1.4 -->
    <script src="../plugins/jQuery/jQuery-2.1.4.min.js"></script>
	<script src="../dist/js/jquery.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 () {
        $("#example2").DataTable();
        $('#example1').DataTable({
          "paging": true,
          "lengthChange": true,
          "searching": true,
          "ordering": false,
          "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>
