
<style type="text/css">
  
.button { padding: 10px;    margin-right: 10px; background-color: #008CBA;} /* Blue */


</style>

<?php 
session_start();
if(isset($_SESSION['login'])){
include "header.php"; 
include "top.php";
include 'main.php';
echo $invoice = $_GET['invoice'];
 $sql="SELECT * from `invoice` where invoice='$invoice'";
$result = $conn->query($sql);
while($row=$result->fetch_assoc()) { 
?>
        <!-- END MENU SIDEBAR-->



        <!-- PAGE CONTAINER-->
       

 <div class="page-container main-content ">
<div class="section__content section__content--p30" style="margin-top: 10%;" >
<div class="row" style="float: right;">
<button ><?php echo "<a class='button btn btn-success btn-md' href='enterpayment1.php?invoice=".$row["invoice"]."'> Pay </a>" ;?></button>
<button><?php echo "<a class='button btn btn-primary btn-md' href='invoicereturn.php?invoice=".$row["invoice"]."'> Return </a>" ;?></button>
<button>
<?php echo "<a class='button btn btn-danger btn-md' href='invoicecancel.php?invoice=".$row["invoice"]."'> Invoice Cancel </a>" ;?></button>
</div>
 </div>
            <!-- MAIN CONTENT-->
            <div class="main-content">
                <div class="section__content section__content--p30">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-11">
                             <div class="card-title" style="padding-left: 6%    ;">
                         <h3 class="text-center title-2">Invoice Details</h3>
                                        </div>  </div>
                           
                            <div class="col-lg-6">
                                <div class="card">
                
                                    <div class="card-body">
                                         <div class="form-group">
                                               INVOICE CODE : <?php echo $row['invoice']; ?>
                                                
                                            </div>
                                            <div class="form-group">
                                               DATE : <?php echo date('d-m-Y',strtotime($row['actualdate'])); ?>
                                                
                                            </div>
                                            <div class="form-group">
                                               DUE DATE : <?php echo date('d-m-Y',strtotime($row['due_date'])); ?>
                                                
                                            </div>
                                            <div class="form-group">
                                              DAYS CREDITS :<?php
$date= $row['actualdate'];
$date2 =new DateTime($date); 
$today = date("Y/m/d");
$today1=new DateTime($today); 
$diff = $today1   ->diff($date2)->format("%a");
                                               echo $diff; ?>


                                                
                                    </div>
                                    </div>
                                </div>
                            </div> 

                            <div class="col-lg-6">
                                <div class="card">
                
                                    <div class="card-body">
                                         <div class="form-group">
                                               PARTY : <?php echo $row['party']; ?>
                                                
                                            </div> 
                                            <div class="form-group">
                                               AMOUNT : <?php echo $row['amount']; ?>
                                                
                                            </div> 
                                            <div class="form-group">
                                               BALANCE : <?php echo $row['balance']; ?>
                                                
                                            </div>
                                            <div class="form-group">
                                               STATUS : <?php echo $row['status']; ?>
                                                
                                            </div>                                   
<?php } ?>
                                    </div>
                                </div> </div></div></div>
<?php 
$sql4="SELECT * from `invoice` where
      invoice='$invoice'";
$result4 = $conn->query($sql4);
while($row4=$result4->fetch_assoc()) { 

  $status=$row4['status']; 
 
 }

/*$status="Cancel";*/
if($status=="Cancel"){

$sql5="SELECT * from `cancelinvoice` where
      invoiceid='$invoice'";
$result5 = $conn->query($sql5);
while($row5=$result5->fetch_assoc()) { 

 

?>
<div class="card-title" style="padding-left: 3%    ;">
                         <h3 class="text-center title-2">Invoice Canceled</h3>
                                        </div>

Cancel Date: <input type="text" name="date" value="<?php echo date('d-m-Y',strtotime($row5['canceldate']));?>" readonly><br><br>
Remark:  <textarea id="form7" name="remark" class="md-textarea form-control" rows="10" required="" readonly ><?php echo $row5['remark'];?></textarea>



<?php 

}

}
if($status!="Cancel")
 {

?>


       <?php $sql1="SELECT * from `payment` WHERE invoice='$invoice'";
        $result1 = $conn->query($sql1);



?>

         
         <div class="col-lg-12">
         <div class="card-title">
                           <h3 class="text-center title-2">Payment Details</h3>  </div> <div class="table-responsive table--no-card m-b-30">
                                    <table class="table table-borderless table-striped table-earning">
                                        <thead>
                                            <tr>
                                                <th>Invoice</th>
                                                <th>Payment Date</th>
                                                <th>Mode</th>                
                                                <th >Amount</th>
                                                 <th>Remarks</th></tr>
                                        </thead>
                                        <tbody>
                                            
<?php while($row1=$result1->fetch_assoc()) { ?><tr>
<td><?php echo $invoice=$row1['invoice']; ?></td>
<td><?php echo date('d-m-Y',strtotime($row1['payment_date'])); ?></td>
<td><?php echo $row1['mode']; ?></td>
<td><?php echo $row1['amount']; ?></td>
<td><?php echo $row1['remark']; ?></td>

</tr>  
<?php } ?>

                                     
                               </tbody>
                               </table>    
                                </div></div>


  <?php 
  $sql2="SELECT * from `returninvoice` WHERE invoiceid='$invoice'";
$result2 = $conn->query($sql2);
?>
  <div class="col-lg-12">
                              <div class="card-title">
                           <h3 class="text-center title-2">Transaction History</h3>  </div> <div class="table-responsive table--no-card m-b-30">
                                    <table class="table table-borderless table-striped table-earning">
                                        <thead>
                                            <tr>
                                                <th>Invoice</th>
                                                <th>Return Date</th>
                                                <th>Quantity</th>                
                                                <th >Return Amount</th>
                                                 <th>Remarks</th></tr>
                                        </thead>
                                        <tbody>
                                            
<?php while($row2=$result2->fetch_assoc()) { ?><tr>
<td><?php echo $invoice=$row2['invoiceid']; ?></td>
<td><?php echo date('d-m-Y',strtotime($row2['returndate'])); ?></td>
<td><?php echo $row2['quantity']; ?></td>
<td><?php echo $row2['returnamount']; ?></td>
<td><?php echo $row2['remark']; ?></td>

</tr>  
<?php } ?>

                                     
                               </tbody>
                               </table>
                                 
                                </div>

</div>
<?php } ?>
</div></div>

                           
                          

    <!-- Jquery JS-->
  <script src="vendor/jquery-3.2.1.min.js"></script>
 <script src="vendor/animsition/animsition.min.js"></script>
    
    <script src="js/main.js"></script>
  <style>
  .pay {
  background-color: #f5f5f5; /* Green */
  border: none;
  color: white;
  padding: 5px 5px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
}
</style>
</body>

</html>
<!-- end document-->
<?php
}
else
{
    header ('location:index.php');
}
?>