<?php session_start();
if(empty($_SESSION['id'])):
header('Location:../index.php');
endif;
if(empty($_SESSION['branch'])):
header('Location:../index.php');
endif;
?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Home | <?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>
 </head>
  <!-- ADD THE CLASS layout-top-nav TO REMOVE THE SIDEBAR. -->
  <body class="hold-transition skin-<?php echo $_SESSION['skin'];?> layout-top-nav" onload="myFunction()">
    <div class="wrapper">
      <?php include('../dist/includes/header.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">Product</li>
            </ol>
          </section>

          <!-- Main content -->
          <section class="content">
            <div class="row">
	      <div class="col-md-9">
              <div class="box box-primary">
                <div class="box-header">
                  <?php
				  
				   	include('../dist/includes/dbcon.php');
                  $branch=1;
                  $cid=$_REQUEST['cid'];
				  $cat=$_REQUEST['cat'];
				  if($cat == 1){
					  $catname="Walkin/REGULAR PRICE";
				  }else if($cat == 2){
					   $catname="Dealer Price/ Whole Sale Price";
				  }else if($cat == 3){
					   $catname="Freelance /Special Price";
					   
					   
					   
				  }
				  
				  
				  		  
$query23=mysqli_query($con,"select * from customer where cust_id='$cid'")or die(mysqli_error($con));
        $row23=mysqli_fetch_array($query23);
				  
				  
				  
				  ?>
                  <h2 class="box-title" style="font-weight:bold;"> Cust Name: <?php echo $row23['cust_last']; ?> &nbsp <?php echo $row23['cust_first']; ?> &nbsp &nbsp  <br> Roof Sales Transaction =  <span style="color:red;"> &nbsp <?php echo $catname; ?> </span></h2>
                </div>
                <div class="box-body">
                  <!-- Date range -->
                  <form method="post" action="transaction_add1.php">
				  <div class="row" style="min-height:400px">
					
					 <div class="col-md-4">
						  <div class="form-group">
							<label for="date">Product Name</label>
							 
								<select class="form-control select2" name="prod_name" tabindex="1" autofocus required>
								<?php
                  $branch=2;
                  $cid=$_REQUEST['cid'];
				  $cat=$_REQUEST['cat'];
								  include('../dist/includes/dbcon.php');
									 $query2=mysqli_query($con,"select * from product where branch_id='2' or branch_id='3' order by prod_name")or die(mysqli_error());
									    while($row=mysqli_fetch_array($query2)){
								?>
										<option value="<?php echo $row['prod_id'];?>"><?php echo $row['serial'];?>/<?php echo $row['prod_name']." Available(".$row['prod_qty'].")";?></option>
								  <?php }?>
								</select>
								<input type="hidden" class="form-control" name="cat" value="<?php echo $cat;?>" required>  	
						        <input type="hidden" class="form-control" name="cid" value="<?php echo $cid;?>" required>   
						  </div><!-- /.form group -->
					</div>
					<div class=" col-md-2">
						<div class="form-group">
							<label for="date">Quantity</label>
							<div class="input-group">
							  <input type="number" class="form-control pull-right" id="date" name="qty" placeholder="Quantity" tabindex="2" value="1"  required>
							<label for="date">LENGTH/METER</label>
							 <input type="floatval" class="form-control pull-right" id="date" name="meterko" placeholder="METER" tabindex="2" value="0"  required>
							</div><!-- /.input group -->
						</div><!-- /.form group -->
					 </div>
					<!--  <input type="text" class="form-control pull-right" id="date" name="hh" placeholder="METER" tabindex="2" value="1"  required> -->
				  	 <div class=" col-md-2">
						<div class="form-group">
							<label for="date">THICKNESS</label>
							<div class="input-group">
							 
							  
							<select type="text" class="form-control pull-right" id="variation" name="thick" >
							<option>--</option>
							<option>.6MM</option>
							 				<option>.5MM</option>
											 <option>.4MM</option>
											  <option>.3MM</option>
											  <option>2.55 MM</option>
											    <option>.2MM</option>
												  <option>.1MM</option>
										
							  </select> 
							</div>
						</div>
					 </div>  
					  <div class=" col-md-2">
						<div class="form-group">
							<label for="date">COLOR</label>
							<div class="input-group">
							   <select type="text" class="form-control pull-right" id="colorb" name="colorb" >
							<option value="" >COLOR</option>
							<option>CRIMSON RED</option>
							<option>AZURE BLUE</option>
							<option>BEIGE</option>
							<option>BAGUIO GREEN</option>
							<option>WHITE</option>
							<option>CHOCOLATE BROWN</option>
							<option>FOAM GREEN</option>
							<option>TERACOTA ORANGE</option>
							<option>IRON GRAY</option>
							<option>SUB POMELO</option>
							<option>EBONY</option>
							<option>RED OAK</option>
							<option>CLASSIC OAK</option>
							<option>JO2 BLACK</option>
							<option>JO5 COFFEE</option>
							<option>103 LIGHT COFFEE</option>
							<option>104 RED</option>
							<option>G00 YELLO WOOD</option>
							<option>MAPLE</option>
							<option>WOOD GRAIN PINE</option>
							<option>WOOD GRAIN CHERRY</option>
						    <option>WOOD GRAIN ANTIQUE OAK WOOD</option>
							<option>ETC</option>
							<option>OTHERS</option>
									   
							  </select>
							</div><!-- /.input group -->
						</div><!-- /.form group -->
					 </div>
					 
					 
					 
					 
					 
					 
					<div class="col-md-2">
						<div class="form-group">
							<label for="date"></label>
							<div class="input-group">
								<button class="btn btn-lg btn-primary" style="font-size:24px;" type="submit" tabindex="3" name="addtocart">+</button>
							</div>
						</div>
						
			
						
					</form>	
					</div>
					<div class="col-md-12">
<?php 
$queryb=mysqli_query($con,"select balance from customer where cust_id='$cid'")or die(mysqli_error());
     $rowb=mysqli_fetch_array($queryb);
        $balance=$rowb['balance']?? null;

        if ($balance>0) $disabled="disabled=true";else{$disabled="";}
?>
                  <table class="table table-bordered table-striped">
                    <thead>
                      <tr>
					   <th>Picture</th>
					   <th>Product Name</th>
                        <th>Qty</th>
						       
                        
						 
						    <th>Description/Thickness</th>
							 <th>Color</th>
						            <th>Unit Price</th>
						            <th>Total</th>
                        <th>Action</th>
                      </tr>
                    </thead>
                    <tbody>
<?php
		
		$query=mysqli_query($con,"select * from temp_trans natural join product where cust_id='$cid' ")or die(mysqli_error());
			$grand=0;
		while($row=mysqli_fetch_array($query)){
				$id=$row['temp_trans_id'];
				$hhko=$row['hh'];
				$total= $row['qty'] * $row['price'];
				$grand1=$hhko * $total;
				$grand=$grand + $total;
		
?>
                      <tr >
					  <td><img style="width:40px;height:30px" src="../dist/uploads/<?php echo $row['prod_pic'];?>"></td>
						
                        <td class="record"><?php echo $row['serial'];?>/<?php echo $row['prod_name'];?></td>
						<td><?php echo $row['qty'];?></td>
						<!-- <td><?php echo number_format($row['hh'],2);?></td> -->
						<td><?php echo $row['variation'];?>/<?php echo $row['ww'];?></td>
						<td><?php echo $row['color'];?></td>
						<td><?php echo number_format($row['price'],2);?></td>
						<td><?php echo number_format($total,2);?></td>
                        <td>
							
							<!-- <a href="#updateordinance<?php echo $row['temp_trans_id'];?>" data-target="#updateordinance<?php echo $row['temp_trans_id'];?>" data-toggle="modal" style="color:#fff;" class="small-box-footer"><i class="glyphicon glyphicon-edit text-blue"></i></a>
-->
              <a href="#delete<?php echo $row['temp_trans_id'];?>" data-target="#delete<?php echo $row['temp_trans_id'];?>" data-toggle="modal" style="color:#fff;" class="small-box-footer"><i class="glyphicon glyphicon-trash text-red"></i></a>
              
						</td>
                      </tr>
					  <div id="updateordinance<?php echo $row['temp_trans_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 Sales Details</h4>
              </div>
              <div class="modal-body">
			  <form class="form-horizontal" method="post" action="transaction_update.php" enctype='multipart/form-data'>
					<input type="hidden" class="form-control" name="cid" value="<?php echo $cid;?>" required>  
  <input type="hidden" class="form-control" name="cat" value="<?php echo $cat;?>" required> 					
					<input type="hidden" class="form-control" id="price" name="id" value="<?php echo $row['temp_trans_id'];?>" required>  
				<div class="form-group">
					<label class="control-label col-lg-3" for="price">Qty</label>
					<div class="col-lg-9">
					  <input type="text" class="form-control" id="price" name="qty" value="<?php echo $row['qty'];?>" required>  
					</div>
				</div>
				
              </div><br>
              <div class="modal-footer">
		            <button type="submit" class="btn btn-primary">Save changes</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
              </div>
			  </form>
            </div>
			
        </div><!--end of modal-dialog-->
 </div>
 <!--end of modal-->  
<div id="delete<?php echo $row['temp_trans_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">Delete Item</h4>
              </div>
              <div class="modal-body">
        <form class="form-horizontal" method="post" action="transaction_del1.php" enctype='multipart/form-data'>
          <input type="hidden" class="form-control" name="cid" value="<?php echo $cid;?>" required>   
		    <input type="hidden" class="form-control" name="cat" value="<?php echo $cat;?>" required> 
          <input type="hidden" class="form-control" id="price" name="id" value="<?php echo $row['temp_trans_id'];?>" required>  
        <p>Are you sure you want to remove <?php echo $row['prod_name'];?>?</p>
        
              </div><br>
              <div class="modal-footer">
                <button type="submit" class="btn btn-primary">Delete</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
              </div>
        </form>
            </div>
      
        </div><!--end of modal-dialog-->
 </div>
 <!--end of modal-->  
<?php }?>					  
                    </tbody>
                    
                  </table>
				  
		 
				  
				  
				  
				  
				  
				  
                </div><!-- /.box-body -->

				</div>	
               
                  
                  
				</form>	
                </div><!-- /.box-body -->
              </div><!-- /.box -->
            </div><!-- /.col (right) -->
            
            <div class="col-md-3">
              <div class="box box-primary">
               
                <div class="box-body">
                  <!-- Date range -->
          <form method="post" name="autoSumForm" action="sales_add1.php">
				  <div class="row">
					 <div class="col-md-12">
						  
						  <div class="form-group">
							<label for="date">Total</label>
							
								<input type="text" style="text-align:right" class="form-control" id="total" name="total" placeholder="Total" 
								value="<?php echo $grand;?>" onFocus="startCalc();" onBlur="stopCalc();"  tabindex="5" readonly>
							
						  </div><!-- /.form group -->
						  <div class="form-group">
							<label for="date">Discount</label>
							
								<input type="text" class="form-control text-right" id="discount" name="discount" value="0" tabindex="6" placeholder="Discount (Php)" onFocus="startCalc();" onBlur="stopCalc();">
								<label for="date">Enter Void Code for Discount %</label>
							<input type="password" class="form-control text-right" id="password" name="password" placeholder="*******" tabindex="6">
							<input type="hidden" class="form-control text-right" id="cid" name="cid" value="<?php echo $cid;?>">
						  </div><!-- /.form group -->
						  <div class="form-group">
							<label for="date">Amount Due</label>
							
								<input type="text" style="text-align:right" class="form-control" id="amount_due" name="amount_due" placeholder="Amount Due" value="<?php echo number_format($grand,2);?>" readonly>
							
						  </div><!-- /.form group -->
              
						 
              <div class="form-group" id="tendered">
                <label for="date">Cash Tendered</label><br>
                <input type="text" style="text-align:right" class="form-control" onFocus="startCalc();" onBlur="stopCalc();"  id="cash" name="tendered" placeholder="Cash Tendered" value="0">
              </div><!-- /.form group -->
              <div class="form-group" id="change">
                <label for="date">Change</label><br>
                <input type="text" style="text-align:right" class="form-control" id="changed" name="change" placeholder="Change">
              </div><!-- /.form group -->
					</div>
					
	




				</div>	
				
								
<div class="form-group">
							<label for="date">Select Type</label>
							
								<select class="form-control select2" name="typerko" tabindex="1" autofocus required>
								
								
								<option>Walkin</option>
								<?php
                  $branch=1;
                  $cid=$_REQUEST['cid'];
				  $cat=$_REQUEST['cat'];
								  include('../dist/includes/dbcon.php');
									 $query2=mysqli_query($con,"select * from ratedeliver ")or die(mysqli_error());
									    while($row=mysqli_fetch_array($query2)){
								?>
										<option value="<?php echo $row['id'];?>"><?php echo $row['truckname'];?><?php echo $row['qty'];?>/<?php echo $row['meter']." FEE(₱ ".$row['fee1'];?></option>
								  <?php }?>
								</select>
							
						  </div><!-- /.form group -->
				
				
				
				
               
                    <button class="btn btn-lg btn-block btn-primary" id="daterange-btn" name="quote" type="submit"  tabindex="7">
                        Roof Quote Transaction
                      </button>
                 <br>
				 
				  <?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">
                         Roof Complete Sales
                      </button>
					   <?php }else {} ?>
              
					  <button class="btn btn-lg btn-block" id="daterange-btn" type="reset"  tabindex="8">
                        <a href="cancel.php">Cancel Sale</a>
                      </button>
              
				</form>	
                </div><!-- /.box-body -->
              </div><!-- /.box -->
            </div><!-- /.col (right) -->
			
			
          </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 () {
        $("#example1").DataTable();
        $('#example2').DataTable({
          "paging": true,
          "lengthChange": false,
          "searching": false,
          "ordering": true,x`
          "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>
