<?php 
session_start();
ob_start(); ?>
<?php include "header.php"; ?>

<style type="text/css">
<!--
input{ border:#CCCCCC solid 1px; border-radius:5px; height:22px; width:200px; padding-left:5px;}
select{ border:#CCCCCC solid 1px; border-radius:5px; height:27px; width:200px;}
.table_bg{ border:#CCCCCC solid 1px; border-radius:5px; height:auto; width:auto; padding:20px; margin-bottom:10px;}
.text_style{ font-family:Arial, Helvetica, sans-serif; font-size:12px;}
.text_style1{ font-family:Arial, Helvetica, sans-serif; font-weight:bold; font-size:12px;}
.style14 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 18px;
	font-weight: bold;
}
.style16 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 24px;
	font-weight: bold;
}

-->
</style>


<?php
if(isset($_GET["uid"]))
{
$uid=$_GET["uid"];

			
			$whr1="md5(id)='$uid' and session_login_id = '".$_SESSION['login_id']."'";
$get=$objIms->getRows('view_purchasereturn_supplier',$whr1);
$purret_id=$get["id"];
$return_no=$get["return_no"];
$client_name=$get["supplier_name"];
$order_no=$get["order_no"];
$purchase_date=$objIms->IntToDate($get["purchase_date"]);
$client_address=$get["address"];
$client_tin=$get["gstin"];
$ret_date=$objIms->IntToDate($get["ret_date"]);

/*$whr="md5(id)='$uid'";
$getPatientInfo=$objIms->getRows('tbl_account',$whr);

			$invoice_no=$getPatientInfo["invoice_no"];
			$trans_date=$objIms->IntToDate($getPatientInfo["trans_date"]);
			$actual_amt=$getPatientInfo["actual_amt"];			
			
			$discount=$getPatientInfo["discount"];
$Paid_Amount=$objIms->getSumValue('tbl_account','Dr_Amt','mas_id="'.$salesmas_id.'" and sales_type="Sales"');*/

 $sqlitm="select * from tbl_supplier where id = '".$get['supplier_id']."' and session_login_id = '".$_SESSION['login_id']."'";
						
							$citm=mysql_query($sqlitm);
							
						$row_itm=mysql_fetch_array($citm);

$gstnum = $row_itm['gstin'];
$state_code =  substr($gstnum, 0, 2);

	$sqlst="select * from tbl_state where state_code = '".$state_code."'";
							
							$cst=mysql_query($sqlst);
							
						$row_st=mysql_fetch_array($cst);		
	}
?>

<script type="text/javascript">
 
function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;

     document.body.innerHTML = printContents;

     window.print();

     document.body.innerHTML = originalContents;
}

</script>
<script type="text/javascript">
$(function(){
    $('button').click(function(){
        var url='data:application/vnd.ms-excel,' + encodeURIComponent($('#tableWrap').html()) 
        location.href=url
        return false
    })
})
</script>
<!-- Page wrapper  -->
        <div class="page-wrapper">
            <!-- Bread crumb -->
            <div class="row page-titles">
                <div class="col-md-5 align-self-center">
                    <h3 class="text-primary"></h3> </div>
                <div class="col-md-7 align-self-center">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="javascript:void(0)">Home</a></li>
                        <li class="breadcrumb-item active">Debit Note</li>
                    </ol>
                </div>
            </div>
            <!-- End Bread crumb -->
            <!-- Container fluid  -->
            <div class="container-fluid">
                <!-- Start Page Content -->
                <div class="row">
                    <div class="col-12">
                        <div class="card">
                            <div class="card-body">
							<h3>Debit Note <a href="purchasereturn_list.php?cmd=Clear" class="btn btn-info btn-sm" style=" float:right">Go Back</a></span></h3><hr />
						<!--	
							<h3>Purchase return</h3>
	 -->
                              
                                <div class="table-responsive m-t-40">
<div id="printableArea">
<div style="width:260mm; height:297mm; margin:auto; text-align:center">
<div class="row">
	<div class="col-md-2">
	<img src="../uploads/<?php echo $_SESSION['org_logo'];?>" style="width:90px; height:80px;" />
	</div>
	<div class="col-md-10">
<p align="right" ><span class="style14" style="background:#666666; color:#FFFFFF; "><?php echo $_SESSION['org_name'];?></span><br />
        <span ><?php echo $_SESSION['address'];?>, <?php echo $_SESSION['city'];?> , <?php echo $_SESSION['state'];?> .</span><br />  
		<span>Contact No.:<?php echo $_SESSION['phone'];?>         </span><br />    
        <span>GSTIN:<?php echo $_SESSION['gstin'];?>       </span>
        
    </p>
	</div>
	</div>
	<hr style="width:100%;" />
	<h4>DEBIT NOTE</h4>
	<hr style="width:100%;" />
	<div class="row">
	<div class="col-md-8">
	<table class="table">
	 <tr>
          <td colspan="8"><div align="left">Deatils Of Receiver | Billed to: </div></td>
          <td colspan="8"><div align="left">Details of Consignee | Shipped to: </div></td>
          </tr>
        <tr>
          <td colspan="8">Name :<?=$client_name?><br />
Address : <?=$client_address?><br />
GSTIN :<?=$client_tin?><br />
State :-<?php echo $row_st['name'];?> <br /><span style="float:right">State Code:-<?php echo $state_code;?></span></td>
          <td colspan="8" style="text-align:left">Name :
              <?=$client_name?>
            <br />
            Address :
  <?=$client_address?>
  <br />
            GSTIN :
  <?=$client_tin?>
  <br />
            State :-<?php echo $row_st['name'];?> <br /><span style="float:right">State Code:-<?php echo $state_code;?></span> </td>
        </tr>
	</table>
	</div>
	<div class="col-md-4">
	<table class="table table-bordered" >
	<tr>
          <td bgcolor="#F0F0F0" >Document No :</td>
           <td> <?=$return_no?>
            </td>
			</tr>
			
			<tr>
			<td bgcolor="#F0F0F0">
Date Of Date :</td><td ><?=$ret_date?>
</td>
</tr>

<tr>
          <td bgcolor="#F0F0F0">Against Invoice / Bill of Supply No :  </td><td ><?=$order_no?></td>
		  </tr>
		  
		  <tr>
		  <td bgcolor="#F0F0F0">
          Date of Invoice / 
          Bill of Supply : </td><td ><?=$purchase_date?></td>
          </tr>
	</table>
	</div>
	</div>
	
	<br />
<table width="100%" border="0">
  <tr>
    <td align="center">
      <table class="table table-bordered" width="100%" >
       
        
		    <?php
  $sql_viewtmp="select *  from view_purchasereturn_det where purretmas_id=$purret_id and session_login_id = '".$_SESSION['login_id']."'";
				$res_viewtmp=mysql_query($sql_viewtmp);
				if(mysql_num_rows($res_viewtmp)>0)
				{ 
					$i=1;
					
  ?>
        <tr bgcolor="#CCCCCC" >
          <td rowspan="2"><strong># </strong></td>
          <td rowspan="2"><strong>Name of Product/Service </strong></td>
          <td rowspan="2"><strong>HSN ASC </strong></td>
          <td rowspan="2"><strong>UOM</strong></td>
          <td rowspan="2"><strong>Qty</strong></td>
          <td rowspan="2"><strong>Rate</strong></td>
          <!--<td rowspan="2"><strong>Amount</strong></td>-->
          <td rowspan="2"><strong>Less:Discount</strong></td>
          <td rowspan="2"><strong>Taxable Value </strong></td>
          <td colspan="2"><div align="center"><strong>CGST</strong></div></td>
          <td colspan="2"><div align="center"><strong>SGST</strong></div></td>
          <td colspan="2"><div align="center"><strong>IGST</strong></div></td>
          <td rowspan="2"><strong>Total</strong></td>
        </tr>
		
        <tr bgcolor="#CCCCCC">
          <td><strong>Rate</strong></td>
          <td><strong>Amount</strong></td>
          <td><strong>Rate</strong></td>
          <td><strong>Amount</strong></td>
          <td><strong>Rate</strong></td>
          <td><strong>Amount</strong></td>
          </tr>
		   <?php
		   $totqty=0;
		   $sumam=0;
		   $sumtav=0;
		   $sumtcg=0;
		   $sumtsg=0;
		   $sumtig=0;
		   $sums=0;
  while($rows=mysql_fetch_assoc($res_viewtmp))
					{
  ?>
        <tr>
          <td><?=$i++?></td>
          <td><?=$rows["item_name"]?></td>
          <td><?=$rows["hsn_code"]?></td>
          <td><?=$rows["unit_name"]?></td>
          <td><?php echo $rows["ret_qty"]; $totqty+=$rows["ret_qty"];?></td>
          <td><?=$rows["pur_price"]?></td>
          <?php $totsum=($rows["pur_price"]*$rows["ret_qty"]); number_format($totsum,2);$sumam+=$totsum;?>
          <td><?php  $discount=$totsum*($rows["discount"]/100); echo number_format($discount,2);?></td>
          <td><?php  $totprice=($totsum-$discount); echo number_format($totprice,2);$sumtav+=$totprice;?></td>
          <td><?php echo $rows["cgst"];?></td>
          <td><?php  $cgst=$totprice*($rows["cgst"]/100); echo number_format($cgst,2);$sumtcg+=$cgst;?></td>
          <td><?php echo $rows["sgst"];?></td>
          <td><?php  $sgst=$totprice*($rows["sgst"]/100); echo number_format($sgst,2);$sumtsg+=$sgst;?></td>
          <td><?php echo $rows["igst"];?></td>
          <td><?php  $igst=$totprice*($rows["igst"]/100); echo number_format($igst,2);$sumtig+=$igst;?></td>
          <td><?php   $totamt=$totprice+$cgst+$sgst+$igst; echo number_format($totamt,2);$sums+=$totamt;?></td>
        </tr>
		<?php }}?>
		<tr>
          <td colspan="15">&nbsp;</td>
          </tr>
        <tr>
          <td colspan="3"><div align="right">Total :  </div></td>
		   <td>&nbsp;</td>
          <td><?=number_format($totqty,2);?></td>
         
          <td><?php //number_format($sumam,2);?></td>
          <td>&nbsp;</td>
          <td><?=number_format($sumtav,2);?></td>
          
          <td><?=number_format($sumtcg,2);?></td>
          <td>&nbsp;</td>
          <td><?=number_format($sumtsg,2);?></td>
          <td>&nbsp;</td
          ><td><?=number_format($sumtig,2);?></td>
		  <td>&nbsp;</td>
          <td><?=number_format($sums,2);?></td>
        </tr>
        
		  </table>
		  <br />
		  <table class="table">
        <tr>
          <td colspan="8">Total Invoice Amount In Words:<br />
<h5><?php echo $objIms->Inwords($sums).' Only';?></h5> </td>
          <td colspan="8"><table width="100%" >
            <tr>
              <td><strong>Total Amount Before Tax: </strong></td>
              <td><strong>
                <?=number_format($sumtav,2);?>
              </strong></td>
            </tr>
            <tr>
              <td>Add : CGST </td>
              <td><?=number_format($sumtcg,2);?></td>
            </tr>
            <tr>
              <td>Add : SGST </td>
              <td><?=number_format($sumtsg,2);?>              </td>
            </tr>
            <tr>
              <td>Add : IGST </td>
              <td><?=number_format($sumtig,2);?></td>
            </tr>
            <tr>
              <td><strong>Tax Amount : GST </strong></td>
              <td><strong>
                <?php $totgst=$sumtcg+$sumtsg+$sumtig; echo number_format($totgst,2);?>
              </strong></td>
            </tr>
          </table></td>
          </tr>
        <tr>
          <td colspan="5"><div align="center">Bank Deatils: </div></td>
          <td colspan="3" rowspan="2">&nbsp;</td>
          <td colspan="8"><table width="100%" >
            <tr>
              <td width="81%"><strong>Total Amount After Tax : </strong></td>
              <td width="19%"><strong>
                <?=number_format($sums,2);?>
              </strong></td>
            </tr>
            <tr>
              <td><strong>Round Off Amount :</strong> </td>
              <td><strong>
              <?=number_format(round($sums),2);?>
              </strong></td>
            </tr>
            <tr>
              <td colspan="2">&nbsp;</td>
              </tr>
            <tr>
              <td>GST Payable on Reverse Charge : </td>
              <td>NA</td>
            </tr>
          </table></td>
          </tr>
        <tr>
          <td colspan="5">&nbsp;</td>
          <td colspan="8"><span style="vertical-align:text-top; text-align:center">Certified that the particulars given above are true and correct.</span> <br />
<span style="vertical-align:text-top; text-align:center"><strong>For <?php echo $_SESSION['org_name'];?></strong></span><br /><br />
<br />
<br />

<span style="vertical-align:text-bottom; text-align:center">Authorised Signatory</span></td>
          </tr>
      </table>      
     

</div>
</div>
</div>
<div align="center"><span class="btn btn-info" onClick="printDiv('printableArea')">Print</span>&nbsp;&nbsp;<button  id="btnExport" class="btn btn-success">Export to Excel</button></div>
</div>
  

</div>
                        </div>
                    </div>
                </div>
                <!-- End PAge Content -->
            </div>
            <!-- End Container fluid  -->
<?php include 'footer.php' ?>
<script>
  $(document).ready(function() {
  $("#btnExport").click(function(e) {
    e.preventDefault();

    //getting data from our table
    var data_type = 'data:application/vnd.ms-excel';
    var table_div = document.getElementById('printableArea');
    var table_html = table_div.outerHTML.replace(/ /g, '%20');

    var a = document.createElement('a');
    a.href = data_type + ', ' + table_html;
    
    a.click();
  });
});
</script>
 <script src="../js/lib/datatables/datatables.min.js"></script>
    <script src="../js/lib/datatables/cdn.datatables.net/buttons/1.2.2/js/dataTables.buttons.min.js"></script>
    <script src="../js/lib/datatables/cdn.datatables.net/buttons/1.2.2/js/buttons.flash.min.js"></script>
    <script src="../js/lib/datatables/cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
    <script src="../js/lib/datatables/cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/pdfmake.min.js"></script>
    <script src="../js/lib/datatables/cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/vfs_fonts.js"></script>
    <script src="../js/lib/datatables/cdn.datatables.net/buttons/1.2.2/js/buttons.html5.min.js"></script>
    <script src="../js/lib/datatables/cdn.datatables.net/buttons/1.2.2/js/buttons.print.min.js"></script>
    <script src="../js/lib/datatables/datatables-init.js"></script>		
