<?php

session_start();

include('../includes/dbcon.php');



$userid=$_SESSION['hrm_id'];

 $user_name=$_SESSION['hrm_name'];

if (isset($_GET['docid'])) { 

  $docid= trim($_GET['docid']);

} 

if (isset($_POST['docid'])) { 

$docid= trim($_POST['docid']);

}

/////!!!!!!!!!!!!!!!!!!  Open inv_header   !!!!!!!!!!!!!!!!!!!!!!!!!!!!

$query=mysqli_query($con," SELECT * FROM `seheader`
LEFT JOIN customer_master ON seheader.party_id=customer_master.cus_id
LEFT JOIN employee_master ON employee_master.emp_id=seheader.empcode
  where seheader.docid='$docid'  ")or die(mysqli_error($con));

$count=mysqli_num_rows($query);

if ($count>0)

{

  while($rowsp=mysqli_fetch_array($query)){     

    //$grnd_no=$rowd['grnd_no'];  

    $docdate=$rowsp['docdate'];
    $emp_name=$rowsp['emp_name']; 
    $cus_name=$rowsp['cus_name'];
   // $note=$rowsp['type'];
     $edate1=$rowsp['edate'];
    $amount=$rowsp['amount'];
   // $chqno=$rowsp['chqno'];
   //  $chqdate=$rowsp['chqdate'];
     // $chqbank=$rowsp['chqbank'];
     //  $type=$rowsp['type'];
     // $cus_code=$rowsp['cus_code'];
    //  $note=$rowsp['note'];

  } ////  while($rowsp=mysqli_fetch_array($query)){ 


}


?>

<!DOCTYPE html>

<html>

<head>

<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<link rel="stylesheet" type="text/css" href="custom.css">

<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">

<style>

body{

background-color:#EFF8FF;

}

h1, p{

margin:0px;

}

.main-section{

background-color: #FFF;

border: 1px solid #8D43AC;

}

.header{

background-color: #8D43AC;

padding:10px 10px 5px 15px ;

color:#fff;

}

.content{

padding:20px 15px 20px 15px;

}

th{

background-color: #8D43AC;

color: #fff;

text-align: right;

}

.table td:nth-child(1),

.table th:nth-child(1){

text-align:left;

}

.lastSection{

padding: 20px 15px 30px 15px;

}



	</style>

</head>

<body>

  <div id="invoiceSection">

<div class="container">

<div class="row">

<div class="col-md-8 col-md-offset-2">

<div class="row main-section">

<div class="col-md-12 col-sm-12 header">

<div class="row">
<div class="col-md-6 col-sm-6 col-xs-6">
<h1> Debit Note</h1>
</div>
<div class="col-md-6 col-sm-6 col-xs-6 text-right">

<table  align="right">
  <tr>
   <td align="left">Debit Note No:</td>
    <td>&nbsp;:&nbsp;</td>
     <td align="left"><?php echo $docid;  ?></td> 
  </tr>
 <tr>
   <td align="left"> Date</td>
    <td>&nbsp;:&nbsp;</td>
     <td align="left"><?php echo date("Y-m-d",strtotime($docdate));  ?></td> 
  </tr>
 

  <tr>
   <td align="left">Rep</td>
    <td>&nbsp;:&nbsp;</td>
     <td align="left"><?php echo $emp_name;  ?></td> 
  </tr>
</table>
</div>
</div>





</div>

<div class="col-md-12 col-sm-12 content">






<div class="row">

<div class="col-md-6 col-sm-6 col-xs-6">
<p><?php echo $cus_name;  ?></p>
<p>Amount : <?php echo abs($amount);  ?></p>
</div>


<div class="col-md-6 col-sm-6 col-xs-6 text-right">

</div>



</div>

</div>

<div class="col-md-12 col-sm-12 text-right">

<table class="table">

<thead>

<tr>

  <th>#</th>

<th class="text-left">Document No</th>

<th class="text-left">Date</th>

<th class="text-left">Type</th>
<th class="text-left">Amount</th>
<th>Settled Amount</th>


</tr>

</thead>

<tbody>

<tr>

<?php



$sub_total=0;

          $inv_discount=0;

          $net_total=0;

          $tot_app=0;

          $ncount=0;





$queryd=mysqli_query($con," SELECT applyamount,refdocno,seheader.docdate AS invdate,
seheader.amount AS invamt,seheader.doctype AS invtype
FROM sedetail
LEFT JOIN `seheader` ON seheader.docid=sedetail.refdocno AND seheader.cancel <> 1

where sedetail.docid='$docid' ")or die(mysqli_error($con));

          while($row=mysqli_fetch_array($queryd)){               

              //$rcount = $rcount + 1;

              $app_docid=$row['refdocno'];
              $applyamount=$row['applyamount'];
              $docdate=$row['invdate'];
              $doctype=$row['invtype'];;
              $amount=$row['invamt'];
             
              $tot_app=$tot_app + $row['applyamount'];

              $ncount=$ncount+1;

?>



 <td class="text-left"><?php echo $ncount;  ?></td>

<td class="text-left"><?php  echo  $app_docid;   ?></td>

<td class="text-left"><?php  echo date("Y-m-d",strtotime($docdate));   ?></td>

<td class="text-left"><?php  echo  $doctype;   ?></td>

<td><?php echo number_format($amount,2);  ?></td>
<td><?php echo number_format(abs($applyamount),2);  ?></td>


</tr>



  <?php  }

 





   ?>

</tbody>

          <tr class="text-right">

                                      <td class="text-left"></td>

                                       <td class="text-left"></td>

                                      <td class="text-left">Total</td>                                

                                      <td class="text-left"></td>
                                      <td></td>                                 

                                      <td><span style="font-weight:bold"><u><?php echo number_format(abs($tot_app),2);  ?></u></span></td>



                </tr>

</table>

</div>

<div class="col-md-12 col-sm-12 lastSection">

<table width="80%" border="0">

                                  <tr><td width="30%" class="text-center">Checked By</td>

                                  	 

                                  	  
                                  </tr>



                                   <tr> <td width="30%" class="text-center"> <br><br>    </td>

                                       <td width="30%" class="text-center">      </td>

                                        <td width="30%" class="text-center">     </td>



                              

                                  <tr> <td width="30%" class="text-center">...................................</td>

                                      

                                           

                            

                                  </tr>

                                </table>

</div>

</div>

</div>

</div>

</div>

</div>

</body>

</html>