<?php 
session_start();
ob_start(); 
include "header.php";
//$objIms->Semifinisheditem_alter();
?>

<?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"]);
}
?>
<!-- Page wrapper  -->
        <div class="page-wrapper">
           
            <!-- Container fluid  -->
            <div class="container-fluid">
                <!-- Start Page Content -->
                <div class="row">
                    <div class="col-12">
                        <div class="card">
                            <div class="card-body">
<script type="text/javascript">
		function showpay(str)
	{
		if(str=='Cheque')
		{
			document.getElementById("showdiv").style.display='block';
		}
		else
		{
			document.getElementById("showdiv").style.display='none';
		}
	}
	</script>
</script>							
							
<h4>Due Sales Details <span style="float:right"><button onclick="goBack()" class="btn btn-info btn-sm">Go Back</button><script>
function goBack() {
    window.history.back();
}
</script></span></h4>
						<hr />
</div>
<form id="form1" name="form1" method="post" action="">
<p>&nbsp;</p>
<table width="100%" cellpadding="4">
  <tr>
    <td height="38"  bgcolor="#FFFFFF" ><strong>Invoice No</strong></td>
    <td  bgcolor="#FFFFFF" ><strong>:</strong></td>
    <td  bgcolor="#FFFFFF" > <?=$sale_no?><br />     </td>
    <td  height="38" ><strong>Client Name<span style="color:#F00; font-weight:bold;">*</span> </strong></td>
    <td width="2%"><strong>:</strong></td>
    <td style="text-align:left"><?php echo $client_name;?></td>
    </tr>
  <tr>
    <td height="34"  bgcolor="#FFFFFF" ><strong>Invoice Date </strong></td>
    <td width="1%"  bgcolor="#FFFFFF" ><strong>:</strong></td>
    <td   bgcolor="#FFFFFF" >
       <?=$saledt?></td>
    <td >&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
</table>
<br />


     <div class="panel">
            <div class="panel-heading"><strong>Item List of Sales </strong></div>
            <p>&nbsp;</p>
            <table width="100%" class="table table-striped">
			<thead>
	    <?php
  $sql_viewtmp="select *  from view_sales_detail where salesmas_id=$salesmas_id and session_login_id = '".$_SESSION['login_id']."'";
				$res_viewtmp=mysql_query($sql_viewtmp);
				if(mysql_num_rows($res_viewtmp)>0)
				{ 
					$i=1;
					
  ?>
                     
                     <tr height="40" align="right">
            <th  >Si No</th>
            <th  >Name Of Product</th>          
            <th  >HSN/CODE </th>
            <th> UOM </th>
            <th  >Quantity</th>
            <th  >Rate </th>
            <th  >Amount</th>
            <th >Discount</th>
            <th  >CGST(%)</th>
           <!-- <th  >CGST </th>-->
            <th  >SGST(%)</th>
            <!--<th  >SGST</th>-->
            <th  >IGST(%)</th>
           <!-- <th  >IGST</th>-->
            <th  >Total Price</th>
            </tr>
			</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 ><?=$i++?></td>           
		    <td  ><?=$rows["item_name"]?></td>            
            <td  ><?=$rows["hsn_code"]?></td>
             <td><?=$rows["unit_name"]?></td>

            <td  ><?php echo $rows["qty"]; $totqty+=$rows["qty"];?></td>
            <td  ><?=$rows["unit_price"]?></td>
            <td  ><?php $totsum=($rows["unit_price"]*$rows["qty"]);echo number_format($totsum,2);$sumam+=$totsum;?></td>
            <td ><?php  $discount=$totsum*($rows["discount"]/100); echo number_format($discount,2);?></td>

            <td  ><?php  $cgst=$totsum*($rows["cgst"]/100); echo number_format($cgst,2);$sumtcg+=$cgst;?></td>
            <!--<td  ><?php  $cgst=$totprice*($rows["cgst"]/100); echo number_format($cgst,2);?></td>-->
            <td  ><?php  $sgst=$totsum*($rows["sgst"]/100); echo number_format($sgst,2);$sumtsg+=$sgst;?></td>
           <!-- <td  ><?php  $sgst=$totprice*($rows["sgst"]/100); echo number_format($sgst,2);?></td>-->
            <td  ><?php  $igst=$totsum*($rows["igst"]/100); echo number_format($igst,2);$sumtig+=$igst;?></td>
           <!-- <td  ><?php  $igst=$totprice*($rows["igst"]/100); echo number_format($igst,2);?></td>-->
            <td ><?php   $totamt=$totsum+$sumtcg+$sumtsg+$sumtig; echo number_format($totamt,2);$sums+=$totamt;?></td>
            </tr>  <?php $sums=$totamt;$i++;}} ?>   
            <tr height="32">
              <td >&nbsp;</td>
              <td colspan="10" ><div align="right"><strong>Sum Total : </strong></div></td>
              <td ><?php echo number_format($sums,2);?></td>
              </tr> 
            <?php ?>
			</tbody>
           </table>
		   
		   <?php
		  $sum_total=$sums;
  		
		 
        
		$nettot=@$sum_total+$freight_charge;?>
<table width="100%" class="table table-bordered">
		  
          <tr>
            <td><div align="right"><strong>Freight Charge(in Rs)</strong></div></td>
            <td><?=number_format($freight_charge,2)?></td>
          </tr>
          <tr>
            <td><div align="right">
              <div align="right"><strong>Grand Total(in Rs)</strong></div>
            </div></td>
            <td><?php echo number_format($nettot,2);?></td>
          </tr>
          <tr>
            <td width="85%"><div align="right"><strong>Round Off</strong></div></td>
            <td width="15%"> <?php echo number_format(round($nettot),2);?></td>
          </tr>
		          <tr>
            <td><div align="right"><strong>Payment Mode </strong></div></td>
            <td><select name="payment_mode" id="payment_mode"  class=" form-control" onchange="showpay(this.value)">
			<option value="Cash">Cash</option>
			<option value="Cheque">Cheque</option>
			</select></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
        </table>
          <table>     
          <tr>
            <!--<td height="35" ><input type="submit" id="Save" name="Save" value="Save" class="btn btn-primary" style="margin:inherit; width:100px"/></td>-->
			<td>
			
</td>
          </tr>
    </table>
		<div id="showdiv" style="display:none;">
		<table width="100%" class="table table-bordered">
  <tr>
    <td>Cheque No. </td>
    <td><strong>:</strong></td>
    <td><input type="text" name="cheque_no" id="cheque_no" /></td>
    <td>Cheque Date </td>
    <td><strong>:</strong></td>
    <td><input type="date" name="cheque_date" id="cheque_date" /></td>
  </tr>
  <tr>
    <td>Bank Name </td>
    <td><strong>:</strong></td>
    <td><input type="text" name="bank_name" id="bank_name" /></td>
    <td>Branch Name </td>
    <td><strong>:</strong></td>
    <td><input type="text" name="branch_name" id="branch_name" /></td>
  </tr>
       </table>
    </div>  
<p></p>
		<br />
        

</form></div>
                        </div>
                    </div>
                </div>
                <!-- End PAge Content -->
            </div>
            <!-- End Container fluid  -->


<?php include 'footer.php' ?>
 <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>
	<script>
