<?php
session_start();
include "../config/config.php";
$id = $_GET['id'];
?>

<?php
    $statement = $pdo->prepare("SELECT * FROM tbl_customers  WHERE tbl_customers.id=".$id);
    $statement->execute();
    $emp_data = $statement->fetchAll(PDO::FETCH_ASSOC);
    $totalData = $statement->rowCount();
    if($totalData==1){
        foreach($emp_data as $data){
            
            
            if($data['dob']=="" || $data['dob']=="0000-00-00"){
                $dob = "";
            }else{
                $dob = date('d-m-Y', strtotime($data['dob']));
            }
            
            if($data['wedding_date']=="" || $data['wedding_date']=="0000-00-00"){
                $wedding_date = "";
            }else{
                $wedding_date = date('d-m-Y', strtotime($data['wedding_date']));
            }
            
            
        }
    }
?>

<div class="modal-dialog" role="document" style="width: 900px;">
    <div class="modal-content" id="printableArea">
      <div class="modal-header">
            <h4 class="modal-title" id="exampleModalLabel">
                <b>Customer Details (<?=$data['unique_id']?>)</b>
                
                <a class="btn btn-warning" style="margin-left: 100px;padding: 3px 10px 3px 10px;" href="pos.php?cus_id=<?=$id?>">Add Sales</a>
                <!--<span class="btn btn-danger" style="padding: 3px 10px 3px 10px;">Balance Amount: <b><?//=number_format($current_balance,2)?></b> </span>-->
            </h4>
            
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true"><i class="fa fa-times" style="margin-top: -23px; font-size: 28px;"></i></span>
            </button>
      </div>
      
           
           
      <div class="modal-body">
        <div class="row">
            
            
<div class="col-md-12" style="padding-top: 5px;">
 
<table class="table table-striped">
    <tr>
        <th style="width: 20%;">Customer Nmae</th>
        <td style="width: 30%;"><?=$data['customer_name']?></td>
        <th style="width: 20%;">Mobile Number</th>
        <td style="width: 30%;"><?=$data['mobile_no']?></td>
    </tr>
    <tr>
        
        <th>Customer ID</th>
        <td style="vertical-align: top;"><?=$data['unique_id']?></td>
        <th>Alter Mobile Number</th>
        <td style="vertical-align: top;"><?=$data['alter_mobile_no']?></td>
    </tr>
    <tr>
        
        <th>City/Town</th>
        <td style="vertical-align: top;"><?=$data['city']?></td>
        <th style="">Date of Birth</th>
        <td style="vertical-align: top !important;"><?=$dob?></td>
    </tr>
    <tr>
        <th>Gender</th>
        <td><?=$data['gender']?></td>
        <th>Religion</th>
        <td><?=$data['religion']?></td>
    </tr>
    <tr>
        <th>Address</th>
        <td><?=$data['address']?></td>
        <th style="">Wedding Date</th>
        <td style="vertical-align: top !important;"><?=$wedding_date?></td>
    </tr>
    <tr>
        <th>Pan No</th>
        <td><?=$data['pan_no']?></td>
        <th>Aadhaar No</th>
        <td><?=$data['aadhaar_no']?></td>
    </tr>
    <tr>
        <th>GST No</th>
        <td><?=$data['gst_no']?></td>
        <th></th>
        <td></td>
    </tr>
</table>

</div>



 
<div class="col-md-12" style="padding-top: 5px;"> 
 
 

<table class="table table-striped">
  <thead>
    <tr>
      <th scope="col">S.No</th>
      <th scope="col">Date</th>
      <th scope="col">Invoice No</th>
      <th scope="col">Grand Total</th>
      <th scope="col">Paid</th>
      <th scope="col">Balance</th>
    </tr>
  </thead>
  <tbody>
      
<?php
    $statement = $pdo->prepare("SELECT * FROM tbl_sales where customer_id=".$id);
    $statement->execute();
    $sales_items_data = $statement->fetchAll(PDO::FETCH_ASSOC);
    $totalData = $statement->rowCount();
    if($totalData>0){
        $i=1;
        foreach($sales_items_data as $data){
            
        $balance = $data['grand_total']-$data['paid'];
?>
            
            <tr>
              <td style="text-align: center;"><?=$i++?></td>
              <td style="text-align: center;"><?=date('d-m-Y', strtotime($data['date']))?></td>
              <td style="text-align: center;"><?=$data['invoice_no']?></td>
              <td style="text-align: right;padding-right: 35px;"><?=number_format($data['grand_total'],2)?></td>
              <td style="text-align: right;padding-right: 35px;"><?=number_format($data['paid'],2)?></td>
              <td style="text-align: right;padding-right: 35px;"><?=number_format($balance,2)?></td>
            </tr>
            
<?php   }
    }else{
        echo "<tr><td colspan='6' style='text-align: center;'>No Sales Records Found</td></tr>";
    }
?>
  </tbody>
</table>







      
           
            
        </div>
      </div>
      
      
      <div class="modal-footer">
        <button type="button" class="btn btn-danger pull-left" data-dismiss="modal"><i class="fa fa-times"></i> Close</button>
        <button type="button" class="btn btn-success pull-right" onclick="printDiv('printableArea')"><i class="bi bi-printer-fill"></i> Print</button>
      </div>

    </div>
</div>


<script>

    function printDiv(divName) {
        var printContents = document.getElementById(divName);
        var originalContents = document.body.innerHTML;
        
        var htmlToPrint = '' +
        '<style type="text/css">' +
        'table th, table td, table thead, table tbody {' +
        'border:1px solid #000 !important;' +
        'padding:0.5em;' +
        '}' +
        '</style>';
        
        htmlToPrint += printContents.outerHTML;
        
        document.body.innerHTML = printContents.outerHTML;
        
        window.print();
        
        document.body.innerHTML = originalContents;
    }
    
</script>
<style>
    thead{
        background: #dbcbcb;
    }
    table.table tbody tr:hover td {
        background-color: none !important;
        background: none !important;
    }
</style>

<script>
$(document).ready(function(){
});
</script>