<?php 
session_start();
ob_start(); ?>

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

      
$whr1="md5(id)='$uid' and session_login_id = '".$_SESSION['login_id']."'";
$get=$objIms->getRows('view_sales_master',$whr1);
$salesmas_id=$get["id"];
$sale_no=$get["sale_no"];
$sales_type=$get["sales_type"];
$client_name=$get["client_name"];
$client_address=$get["client_address"];
$client_tin=$get["tin_no"];
$saledt=$objIms->IntToDate($get["stampdate"]);

/*$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"');*/
	}?>
<script type="text/javascript">
function original()
{
document.getElementById("original").style.display="block";
document.getElementById("duplicate").style.display="none";
document.getElementById("triplicate").style.display="none";
}

function duplicate()
{
document.getElementById("original").style.display="none";
document.getElementById("duplicate").style.display="block";
document.getElementById("triplicate").style.display="none";
}


function triplicate()
{
document.getElementById("original").style.display="none";
document.getElementById("duplicate").style.display="none";
document.getElementById("triplicate").style.display="block";
}

</script>

<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>
<style type="text/css">
   
    p{
      font-size: 15px;
      margin: 5px;
      text-align: left;

    }
    td{
      width: 5px;
      height: 5px;
      margin: -2px;
    }
    tr{
      margin: -5px;
    }
    span{
      margin: 5px;

    }


    @media print {
 .p{
  text-align: left !important;
 }
}
  </style>


<!-- 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">Sale Reciept</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">

  <div class="panel-heading"><strong>Sale Reciept </strong><span style="float:right"> <a class="btn btn-info" href="sales_list.php?cmd=Clear" style="color:#333333; text-decoration:none">Go Back</a> </span> </div>
    <div class="panel" style="text-align:center">
  <span class="btn btn-info" onclick="original()"> Original For Receipient </span>
   <span class="btn btn-primary" onclick="duplicate()"> Duplicate for Supplier/Transporter </span>
    <span class="btn btn-success" onclick="triplicate()"> Triplicate for Supplier </span>
  
  </div>
  
  <!--   <div id="tableWrap">
  <div id="printableArea"> -->
  <style media="print">

  [background-color] {
        z-index: 0; background:#FFFFFF;
        position: relative;
        -webkit-print-color-adjust: exact !important;
    }

  </style>
<div class="container" id="printableArea">
<br>
<table class="table" style="width: 100%"; border="1px" >
  <thead><th colspan="3" style="text-align: center;">M/S TIRUPATI BALAJI TEXTILE <br>
  Original For Receipient</th></thead>
  <tbody>
  <tr>
  <td>
<table class="table" style=" width: 100%;">
  <tbody>
  
    <tr>
      <td style="text-align: left">
      <div style="font-weight: bold;">PRASAD MARKET</div>
      <div >LOHAR TOLA ROAD,NEAR ASHOKA HOTEL</div>
      <div >RAMGARH CANTT (Jharkhand)</div>
      <div >Contact No.:7033875044,9905517315  </div>
       <?php if($sales_type=="Tax Invoice"){?>
        <div>GSTIN:20GVRPS5606G1ZB         </div>
        <?php }?>
      </td>
      
    </tr>
    <tr>
      <td style="text-align: left">
        <p style="font-weight: bold; margin-top: 0px;margin-bottom: 0px;">Details of Receiver | Billed to : </p>
        <p style="font-weight: bold; margin-top: 0px;margin-bottom: 0px;">Name &nbsp;&nbsp;<strong>:</strong>&nbsp;&nbsp;<?=$client_name?></p>
        <p style=" margin-top: 0px;margin-bottom: 0px;">Address&nbsp;&nbsp;<strong>:</strong>&nbsp;&nbsp;<?=$client_address?></p>
        <p style=" margin-top: 0px;margin-bottom: 0px;">GSTIN<strong>:</strong>&nbsp;&nbsp;<?=$client_tin?></p>
        <p style=" margin-top: 0px;margin-bottom: 0px;">State &nbsp;&nbsp;<strong>:</strong>&nbsp;&nbsp;Jharkhand</p>
        <p style=" margin-top: 0px;margin-bottom: 0px;">State Code &nbsp;&nbsp;<strong>:</strong>&nbsp;&nbsp;20</p>      
        <p style="font-weight: bold;margin-top: 0px;margin-bottom: 0px;">Details of Consignee | Shipped to : </p>
        <p style="font-weight: bold;margin-top: 0px;margin-bottom: 0px;">Name &nbsp;&nbsp;<strong>:</strong>&nbsp;&nbsp;<?=$client_name?></p>
        <p style=" margin-top: 0px;margin-bottom: 0px;">Address&nbsp;&nbsp;<strong>:</strong>&nbsp;&nbsp;<?=$client_address?></p>
        <p style=" margin-top: 0px;margin-bottom: 0px;">GSTIN<strong>:</strong>&nbsp;&nbsp;<?=$client_tin?></p>
        <p style=" margin-top: 0px;margin-bottom: 0px;">State &nbsp;&nbsp;<strong>:</strong>&nbsp;&nbsp;Jharkhand</p>
        <p style=" margin-top: 0px;margin-bottom: 0px;">State Code &nbsp;&nbsp;<strong>:</strong>&nbsp;&nbsp;20</p>      
      </td> 
    </tr>
  </tbody>
</table>
</td>
<td>
<table class="table" style="width: 100%;border-left: 0px; border-top: 0px; border-right: 0px; border-bottom: 0px" border="1"; >
  <tbody>
  <tr>
      
      <td>
        <p style="font-weight: bold;">Invoice No. </p>
        <p><?=$sale_no?></p>
      </td>
      <td>
        <p>Transportation Mode</p>
        <p></p>
      </td>
      
  </tr>
  <tr>
    
      <td>
        <p>TAX Invoice Date </p>
        <p><?=$saledt?></p>
      </td>
    
    
      <td>
          <p>Date of Supply  </p>
      </td>
    </tr>
    <tr>
      <td>
        <p>State</p>
        <p>Jharkhand</p>
      </td>
      <td>
        <p>Place of Supply</p>
        <p>Jharkhand</p>
      </td>
    </tr>
    <tr>
      <td>
        <p>State Code </p>
        <p>20</p>
      </td>
      <td>
        <p>State Code </p>
        <p>20</p>
      </td>
    </tr>
    <tr>
      <td colspan="2" rowspan="1">
        
        <textarea id="mess" placeholder="Terms Of Delivery" style="width: 98%; height: 130px; border: 0px"></textarea>

      </td>
      
    </tr>
    
  </tbody>
</table>
</td>
</tr>
</tbody>
</table>



<table class="table" style=" width: 100%" border="1px " >
  <thead>
   <?php
        $sql_viewtmp="select * from view_sales_detail where session_login_id = '".$_SESSION['login_id']."' and  salesmas_id=$salesmas_id";
        $res_viewtmp=mysql_query($sql_viewtmp);
        if(mysql_num_rows($res_viewtmp)>0)
        { 
          $i=1;
          
  ?>
    <th><p style="font-weight: bold;">Sr No. </p></th>
    <th><p style="font-weight: bold;">Name of Product / Service </p></th>
    <th><p>HSN ACS </p></th>
    <th><p>UOM</p></th>
    <th><p>Qty</p></th>
    <th><p>Rate</p></th>
    <th><p>Trade Disc</p></th>
    <th><p>Amount</p></th>
  </thead>
  <tbody>
  <?php
       $totqty=0;
       $sumam=0;
       $sumtav=0;
       $sumtcg=0;
       $sumtsg=0;
       $sumtig=0;
       $sums=0;
  while($rows=mysql_fetch_assoc($res_viewtmp))
          {
  ?>
    <tr>
      <td>
        <p><?=$i++;?></p>
      </td>
      <td>
        <p style="font-weight: bold"><?=$rows["item_name"]?></p>
      </td>
      <td>
        <p><?=$rows["hsn_code"];?><?=$rows["hsn_code"]?></p>
      </td>
      <td>
        <p><?=$rows["unit_name"]?></p>
      </td>
      <td>
        <p style="font-weight: bold"><?php echo $rows["qty"]; $totqty+=$rows["qty"];?></p>
      </td>
      <td>
        <p><?=$rows["unit_price"]?></p>
      </td>
      <td>
        <p><?php  $discount=$totsum*($rows["discount"]/100); echo number_format($discount,2);?></p>
      </td>
      <td>
        <p><?php $totsum=(($rows["unit_price"]*$rows["qty"])-$discount); echo number_format($totsum,2); ?></p><?php
        $sumam+= $totsum;
        }
       } ?>

       
      </td>
    </tr>
  </tbody>
</table>
<div style="border: 1px solid black">
  <div style="float: left">Amount Chargeable (in words)</div>
  <div style="float: right;">E, & O.E</div>
  <p style="font-weight: bold"><?php echo $objIms->Inwords(round($sumam))?></p>
</div>
<table class="table" border="1px" style="width: 100%">
    <tbody>
    <tr>

      <td colspan="4" rowspan="2" >
      Taxable Value
    </td>

    <td colspan="4" style="text-align: center;">
      CGST
    </td>

    <td colspan="4" style="text-align: center;">
      SGST
    </td>
    <td colspan="4" style="text-align: center;">
      IGST
    </td>
    <td colspan="4" rowspan="2" style="text-align: center;">
      Total
    </td>

    <tr>
    
    
    <td colspan="2">Rate</td>
    <td colspan="2">Amount</td>

    <td colspan="2">Rate</td>
    <td colspan="2">Amount</td>

    <td colspan="2">Rate</td>
    <td colspan="2">Amount</td>
    </tr>
    </tr>
      <?php
  $sql_viewtmp="select * from view_sales_detail where session_login_id = '".$_SESSION['login_id']."' and  salesmas_id= $salesmas_id group by hsn_code order by hsn_code";

        $res_viewtmp=mysql_query($sql_viewtmp);
         if(mysql_num_rows($res_viewtmp)>0)
        { 
          $i=1;
            while($rows=mysql_fetch_assoc($res_viewtmp))
          {
        $hsn_c1 = $rows["hsn_code"];
  ?>
  
   <?php 
   $sql_tp = "select *,sum(((qty*unit_price)-((qty*unit_price)*discount/100))*1) as tot_2, sum(((qty*unit_price)-((qty*unit_price)*discount/100))*cgst/100)as cgstamt,  sum(((qty*unit_price)-((qty*unit_price)*discount/100))*sgst/100) as sgstamt, sum(((qty*unit_price)-((qty*unit_price)*discount/100))*igst/100) as igstamt from view_sales_detail where session_login_id = '".$_SESSION['login_id']."' and salesmas_id= '$salesmas_id' and hsn_code = '$hsn_c1' group by hsn_code";
   $res_tp = mysql_query($sql_tp);
 
 while($abc = mysql_fetch_assoc($res_tp)){


   ?> <tr>
      <td colspan="4">
        <p><?php echo  $abc['hsn_code'] ; ?></p>
      </td>
      <td colspan="2">
        <p><?php echo $rows["cgst"];?></p>
      </td>
      <td colspan="2">
        <p><?php  $cgst=$totprice*($rows["cgst"]/100);  number_format($cgst,2);$sumtcg+=$cgst; echo number_format( $abc['cgstamt'] ,2);?><?php $cgst1 = $abc['cgstamt']; ?></p>
      </td>
      <td colspan="2">
        <p><?php echo $rows["sgst"];?></p>
      </td>
      <td colspan="2">
        <p><?php  $sgst=$totprice*($rows["sgst"]/100);  number_format($sgst,2);$sumtsg+=$sgst; echo number_format($abc['sgstamt'] ,2);?><?php $sgst1 = $abc['sgstamt']; ?></p>
      </td>
      <td colspan="2">
        <p><?php echo $rows["igst"];?></p>
      </td>
      <td colspan="2">
        <p><?php  $igst=$totprice*($rows["igst"]/100);  number_format($igst,2);$sumtig+=$igst; echo number_format($abc['igstamt'] ,2);?><?php $igst1 = $abc['igstamt']; ?></p>
      </td>
        <?php 
    $item_total=$cgst1+$sgst1+$igst1;
    $grand_total=$grand_total+$item_total;
    ?>
      <td colspan="4"><?php $abc['tot_2']; $tot_amt_ret = $abc['tot_2']; ?>
      <?php $tot_amt_rtr = $tot_amt_ret + $cgst1+$cgst1 + $igst1; ?>
        <p><?php   $totamt=$sumam+$item_total; number_format($totamt,2);$sums+=$totamt; echo $tot_amt_rtr; $sum_amt+=$tot_amt_rtr;?></p>
      </td>
    </tr>
     <?php }}}?>
  
 
  </tbody>
</table>

<div  style="width: 100%; height: 25px;border: 1px solid black">
    <p style="font-weight: bold"><?php echo $objIms->Inwords(round($sum_amt)).' ';?> Rupees Only.&nbsp;&nbsp;</p>
  </div>
  
    <div  style="width: 100%; height: 180px; border: 1px solid black">
      <div style="float: left; width: 45%; height: 50%; margin-top: 90px;">
        <p>GST Payable on Reverse Charge</p>
        <br>
        <p>Certified that the perticulars given above are true and correct. </p>
      </div>
      <div style="float: right; width: 55%; height: 50%;">
        <p style=" margin-left: 8px; margin-bottom: 2px;">Company's Bank Details</p>
        <p style=" margin-left: 8px margin-bottom: 2px;">Bank Account Number</p>
        <p style=" margin-left: 8px margin-bottom: 2px;">3704511441</p>
        <p style=" margin-left: 8px margin-bottom: 2px;">Bank Branch IFSC : :SBIN0012815 </p>
        <div style="width: 98%; height: 50px; border: 1px solid black; margin-left: 7px;margin-top: 2px;">
          <p style="text-align: right;">For, M/S TIRUPATI BALAJI TEXTILE</p>
        
          <p style="text-align: right;margin-top: 7px">Authorised signature</p>
        </div>
      </div>  
    

<!-- 
</div>-->

</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>
<?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>