<?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>Customer Account | <?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>
      img.profile_pic {
    width: 152px;
    height: 125px;
    border: 5px solid #ccc;
}
    </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">
        
          <?php
          if(isset($_REQUEST['cid']))
            {
              $cid=$_REQUEST['cid'];
            }
            else
            {
            $cid=$_POST['cid'];
          }
          ?>
            <h1>
              <a class="btn btn-lg btn-warning" href="customer.php">Back</a>
              
            </h1>
            
          </section>

          <!-- Main content -->
          <section class="content">
            <div class="row">
	      <div class="col-md-3">
              <div class="box box-primary">
                <div class="box-body">
                  <!-- Date range -->
                  <form method="post" action="" enctype="multipart/form-data">
		  <?php
		    
		      $query=mysqli_query($con,"select * from customer where cust_id='$cid'")or die(mysqli_error());
			       $row=mysqli_fetch_array($query);
		  ?>	
		    <img class = "profile_pic" src = "../dist/uploads/<?php echo $row['cust_pic'];?>">
                  <div class="form-group">
                    <label for="date">Customer Name</label>
                    <div class="input-group col-md-12">
                      <h3><?php echo $row['cust_last'].", ".$row['cust_first'];?></h3>
                    </div><!-- /.input group -->
                  </div><!-- /.form group -->
		  
                  <div class="form-group">
                    <label for="date">Address</label>
                    <div class="input-group col-md-12">
                      <?php echo $row['cust_address'];?>
                    </div><!-- /.input group -->
                  </div><!-- /.form group -->
                  <div class="form-group">
                    <label for="date">Contact</label>
                    <div class="input-group col-md-12">
                      <?php echo $row['cust_contact'];?>
                    </div><!-- /.input group -->
                  </div><!-- /.form group -->
                  <div class="form-group">
                    <label for="date">Balance</label>
                    <div class="input-group col-md-12">
                      <h3><?php echo number_format($row['balance'],2);?></h3>
                    </div><!-- /.input group -->
                  </div><!-- /.form group -->
				  
				  <a href="#" data-target="#teacherreg" data-toggle="modal" class="btn btn-block btn-warning"><i class="glyphicon glyphicon-plus-sign text-blue"></i>Add Payment</a>
                  <a href="<?php if ($row['balance']<=0) echo "cash_transaction.php?cid=$cid&cat=1";?>" class="btn btn-block btn-primary">
                  <i class="glyphicon glyphicon-shopping-cart text-blue"></i>Add New Order</a>
                
				</form>	
                </div><!-- /.box-body -->
              </div><!-- /.box -->
            </div><!-- /.col (right) -->
            
            <div class="col-xs-9">
              <div class="nav-tabs-custom">
                <ul class="nav nav-tabs">
                  <li class=""><a href="#fa-icons" data-toggle="tab" aria-expanded="true">QUOTE HISTORY</a></li>
                  <li class=""><a href="#cash" data-toggle="tab">TRANSACTION History</a></li>
                  <li class=""><a href="#payments" data-toggle="tab" aria-expanded="false">PARTIAL/PAYMENT History</a></li>
                </ul>
                <div class="tab-content">
                  <!-- Font Awesome Icons -->
                  
                  <div class="tab-pane active" id="fa-icons">
                    <table id="" class="table table-bordered table-striped">
                  <thead>
                      <tr>
                        <th>Quote #</th>                      
                        <th>Qty</th>
                        <th>Product</th>
                        <th>Price</th>
                        <th>Term</th>
                        <th>Payable for</th>
                        <th>Amount Due</th>
                       
                        <th>Discount</th>
                        <th>Payment Status</th>
                        <th>View</th>
                      </tr>
                    </thead>
                    <tbody>
<?php
   // $cid=$_REQUEST['cid'];
    $query1=mysqli_query($con,"select * from sales where cust_id='$cid' and modeofpayment='quote' order by date_added desc")or die(mysqli_error($con));
    while($row1=mysqli_fetch_array($query1)){
		$mysalesid=$row1['sales_id'];
    $query33=mysqli_query($con,"select * from sales_details where sales_id='$mysalesid'")or die(mysqli_error($con));
    $row33=mysqli_fetch_array($query33);
	$myprodid=$row33['prod_id']?? null;
	$query44=mysqli_query($con,"select * from product where prod_id='$myprodid'")or die(mysqli_error($con));
    $row44=mysqli_fetch_array($query44);
?>
                      <tr>
                        <td><?php echo $row1['sales_id']?? null;?></td>
                        <td><?php echo $row33['qty']?? null;?></td>
                        <td><?php echo $row44['prod_name']?? null;?></td>
                        <td><?php echo $row44['prod_price']?? null;?></td>
                        <td><?php echo $row1['amount_due']?? null;?></td>
                        <td><?php echo $row1['status']?? null;?></td>
                        <td><?php echo $row1['discount']?? null;?></td>
                        <td><?php echo date("M d, Y",strtotime($row1['date_added']));?></td>
                  
                        <td><?php 
                        if ($row1['status']=='paid') 
                        echo "<span class='badge bg-green'>".$row1['status']."</span>";
                        else echo "<span class='badge bg-red'>For Quote</span>";
                        ?>

                      </td>
                      <td>
                        <a href="payment.php?cid=<?php echo $row['cust_id'];?>&sid=<?php echo $row1['sales_id'];?>"><i class="glyphicon glyphicon-share-alt"></i></a>
                        <a href="reprint.php?sid=<?php echo $row1['sales_id'];?>"><i class="glyphicon glyphicon-print"></i></a>
                        <a href="print.php?sid=<?php echo $row1['sales_id'];?>&cid=<?php echo $row['cust_id'];?>"><i class="glyphicon glyphicon-list"></i></a>
                      </td>  
                      </tr>
    <?php }?>       
                      </tbody>
                  
                  </table>
                  </div><!-- /#fa-icons -->

                  <div class="tab-pane" id="cash">
                    <table id="" class="table table-bordered table-striped">
                  <thead>
                      <tr>
                        <th>Transaction #</th>                      
                        <th>Product</th>
                        <th>Product Code</th>
                        <th>Price</th>
                        <th>Qty</th>
                        <th>Amount</th>
						<th>PAYMENT</th>
                        <th>Date Paid</th>
                        <th>Reprint</th>
                      </tr>
                    </thead>
                    <tbody>
<?php
   // $cid=$_REQUEST['cid'];
    $query1=mysqli_query($con,"select * from sales where cust_id='$cid' order by sales_id ASC")or die(mysqli_error($con));
    while($row1=mysqli_fetch_array($query1)){
    $mysalesid=$row1['sales_id'];
    $query33=mysqli_query($con,"select * from sales_details where sales_id='$mysalesid'")or die(mysqli_error($con));
    $row33=mysqli_fetch_array($query33);
	$myprodid=$row33['prod_id']?? null;
	$query44=mysqli_query($con,"select * from product where prod_id='$myprodid'")or die(mysqli_error($con));
    $row44=mysqli_fetch_array($query44);
?>
                      <tr>
                        <td><?php echo $row1['sales_id']?? null;?></td>
                        <td><?php echo $row44['prod_name']?? null;?></td>
                        <td><?php echo $row44['serial']?? null;?></td>
                        <td><?php echo $row33['price']?? null;?></td>
                        <td><?php echo $row33['qty']?? null;?></td>
                        <td><?php echo number_format($row1['total'],2);?></td>
						<td><?php echo number_format($row1['cash_tendered'],2);?></td>
                        <td><?php echo date("M d, Y",strtotime($row1['date_added']));?></td>
                        <td><a href="reprint_cash.php?sales_id=<?php echo $row1['sales_id'];?>"><i class="glyphicon glyphicon-print"></i></a>
                      </td>  
                      </tr>
    <?php }?>       
                      </tbody>
                  
                  </table>
                  </div><!-- /#fa-icons -->
                  <!-- glyphicons-->
				  
                  <div class="tab-pane" id="payments">
                    <table id="" class="table table-bordered table-striped">
                    <thead>
                      <tr>
                        <th>TR #</th>
						 <th>Grand total</th>
                        <th>Discount</th>
                        <th>Partial Amount Paid</th>
                        <th>Date</th>
                        <th>Balance</th>
						 <th>Action</th>
                      </tr>
                    </thead>
                    <tbody>
<?php
    $cid=$_REQUEST['cid'];
    $query3=mysqli_query($con,"select * from sales where cust_id='$cid' and modeofpayment='partial' order by sales_id DESC")or die(mysqli_error());
    while($row3=mysqli_fetch_array($query3)){
    $ggaga=$row3['total'];
	 $partial1=$row3['partial1'];
	  $partial2=$row3['partial2'];
	   $partial3=$row3['partial3'];
	   
	   $salesidpo=$row3['sales_id'];
	   $partotal=  $partial1 +  $partial2 +  $partial3;
	$dave=$ggaga - $partotal;
?>
                      <tr>
                        <td><?php echo $row3['sales_id'];?></td>
						  <td><?php echo $row3['amount_due'];?></td>
                        <td><?php echo $row3['discount'];?></td>
                        <td><?php echo $partotal;?></td>
                        <td><?php echo date("M d, Y",strtotime($row3['date_added']));?></td>
                        <td><?php if($dave < 1) { }else{ echo $dave; }?></td>
						<!-- <td><?php if($dave < 1) { }else{?> <a href="paymentpartial.php?cid=<?php echo $row3['cust_id'];?>&sid=<?php echo $row3['sales_id'];?>"><i class="glyphicon glyphicon-share-alt">REFUND</i></a> <?php }    ?> ?></td> -->
						<td>  <a href="#" data-target="#kill<?php echo $salesidpo;?>" data-toggle="modal" class="btn btn-block btn-warning"><i class="glyphicon glyphicon-plus-sign text-blue"></i>REFUND/UNDO PAYMENT</a></td>
						
						
    
                        
                      </tr>
					  
					  
					  	
<div id="kill<?php echo $salesidpo;?>" class="modal fade in primary" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
		<div class="modal-dialog">
		  <div class="modal-content">
                      <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h4 class="modal-title"><i class="glyphicon glyphicon-plus" style="font-size:30px;"></i>REFUND/UNDO PAYMENT</h4>
                      </div>
                      <div class="modal-body">
					  
					  <?php
   $cid=$_REQUEST['cid'];
   
    $query4=mysqli_query($con,"select * from term natural join sales where cust_id='$cid' order by term_id desc limit 0,1")or die(mysqli_error($con));
      $row1=mysqli_fetch_array($query4);    
?>    
			  <form class="form-horizontal" method="post" action="undopayment.php" enctype='multipart/form-data'>
                             <input type="hidden" class="form-control" id="tlast" name="cid" value="<?php echo $cid;?>">  
                               <input type="hidden" class="form-control" id="tlast" name="myssid" value="<?php echo $salesidpo;?>">  
                            
                             <div class="form-group">
                        				  <label class="control-label col-lg-3" for="tlast">ENTER ADMINISTRATOR VOID CODE!!</label>
                        				  <div class="col-lg-8">
										  <?php 
										  	$query1=mysqli_query($con,"select * from customer where cust_id='$cid'")or die(mysqli_error($con));
                                           $row1=mysqli_fetch_array($query1);	
										   $mypayment=$row1['balance']; 
										  ?>
                                    <input type="hidden" class="form-control" id="tlast" name="balance" value="<?php echo $row1['balance']; ?>">  
                                     <input type="password" class="form-control" id="tlast" name="void" placeholder="*******" required>  
				                           </div>
                             </div> 
                            
                      </div>       
                      <!--end of modal body-->
                      <div class="modal-footer">
			<button type="submit" name="save" class="btn btn-primary">Complete</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
                      </div>
               </div>
               
               <!--end of modal content-->
                </form>
           </div>
        </div>   	
		
					  
					  
    <?php }?>       
                    </tbody>
                  
                  </table>
                    
                  </div><!-- /#ion-icons -->
                </div><!-- /.tab-content -->
              </div><!-- /.nav-tabs-custom -->
            </div>
          </div><!-- /.row -->
	  
            
          </section><!-- /.content -->
        </div><!-- /.container -->
      </div><!-- /.content-wrapper -->
      <?php include('../dist/includes/footer.php');?>
    </div><!-- ./wrapper -->
<?php
   // $cid=$_REQUEST['cid'];
    $query4=mysqli_query($con,"select * from term natural join sales where cust_id='$cid' order by term_id desc limit 0,1")or die(mysqli_error($con));
      $row1=mysqli_fetch_array($query4);    
?>    






<div id="teacherreg" class="modal fade in primary" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
		<div class="modal-dialog">
		  <div class="modal-content">
                      <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h4 class="modal-title"><i class="glyphicon glyphicon-plus" style="font-size:30px;"></i>Add Payment for Balance Total of <?php echo $row1['balance'] ?? null;?></h4>
                      </div>
                      <div class="modal-body">
					  
					  <?php
   $cid=$_REQUEST['cid'];
    //$sid=$_REQUEST['sid'];
    $query4=mysqli_query($con,"select * from term natural join sales where cust_id='$cid' order by term_id desc limit 0,1")or die(mysqli_error($con));
      $row1=mysqli_fetch_array($query4);    
?>    
			  <form class="form-horizontal" method="post" action="payment_addbalance.php" enctype='multipart/form-data'>
                             <input type="hidden" class="form-control" id="tlast" name="cid" value="<?php echo $cid;?>">  
                               <!--<input type="hidden" class="form-control" id="tlast" name="sid" value="<?php echo $sid;?>">  -->
                            
                             <div class="form-group">
                        				  <label class="control-label col-lg-3" for="tlast">Balance Payment Amount</label>
                        				  <div class="col-lg-8">
										  
										  <?php 
										  	$query1=mysqli_query($con,"select * from customer where cust_id='$cid'")or die(mysqli_error($con));
                                           $row1=mysqli_fetch_array($query1);	
										   $mypayment=$row1['balance']; 
										  ?>
                                    <input type="hidden" class="form-control" id="tlast" name="balance" value="<?php echo $row1['balance']; ?>">  
                                     <input type="text" class="form-control" style="font-size:20px;height:30px;color:maroon;" id="tlast" name="amount" placeholder="Amount" required>  
				                           </div>
                             </div> 
                            
                      </div>       
                      <!--end of modal body-->
                      <div class="modal-footer">
			<button type="submit" name="save" class="btn btn-primary">Complete</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
                      </div>
               </div>
               
               <!--end of modal content-->
                </form>
           </div>
        </div>  
		
		
		

		
		
		
		
<!--end of teacherreg modal-->
    <!-- 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>
