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



<?php

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

$rsr=$objIms->getRows("tbl_sales_return_mstr","md5(id)='$uid' and session_login_id = '".$_SESSION['login_id']."'");
$purretmas_id=$rsr["id"];
$salesmas_id=$rsr["salesmas_id"];
$return_no=$rsr["salereturn_no"];
$return_date=$objIms->IntToDate($rsr["return_date"]);

/*$sql_acc="select *  from tbl_account where mas_id=$salesmas_id and sales_type='Sales Return' order by id asc";
$res_acc=mysql_query($sql_acc);
$rsacc=mysql_fetch_array($res_acc);
$discount=$rsacc["discount"];*/
			
			$whr1="id='$salesmas_id' and session_login_id = '".$_SESSION['login_id']."'";
$get=$objIms->getRows('view_sales_master',$whr1);
$sale_no=$get["sale_no"];
$sale_date=$objIms->IntToDate($get["stampdate"]);
$client_name=$get["client_name"];
$client_address=$get["client_address"];
$client_tin=$get["tin_no"];
	}


	
?>


		
	
		 <style>
			select.error { background-color:#ffa8a8; border: 1px dotted red;  }
			input.error{ background-color:#ffa8a8;   }
			textarea.error{ background-color:#ffa8a8; border: 1px dotted red;  }
         </style>
		 
        


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


-->
</style>
<!-- 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">
							
							<h3>View Sale Return<span style="float:right"><button onclick="goBack()" class="btn btn-info btn-sm">Go Back</button><script>
function goBack() {
    window.history.back();
}
</script></span></h3>
                              
                                <div class="table-responsive m-t-40">
<form id="form1" name="form1" method="post" action="">
<table width="100%" cellpadding="4" class="table table-bordered">
  <tr>
    <td height="29" nowrap="nowrap" bgcolor="#FFFFFF" ><strong>Return No. </strong></td>
    <td nowrap="nowrap" bgcolor="#FFFFFF" ><strong>:</strong></td>
    <td nowrap="nowrap" bgcolor="#FFFFFF" ><?=$return_no?></td>
    <td height="29" nowrap="nowrap"><strong>Return Date </strong></td>
    <td><strong>:</strong></td>
    <td><?=$return_date?></td>
  </tr>
  <tr>
    <td height="27" nowrap="nowrap" bgcolor="#FFFFFF" ><strong>Sale   No</strong></td>
    <td nowrap="nowrap" bgcolor="#FFFFFF" ><strong>:</strong></td>
    <td nowrap="nowrap" bgcolor="#FFFFFF" ><?php echo $sale_no;?></td>
    <td width="8%" height="27" nowrap="nowrap"><strong>Client Name<span style="color:#F00; font-weight:bold;">*</span> </strong></td>
    <td width="2%"><strong>:</strong></td>
    <td width="31%"><?php echo $client_name;?></td>
  </tr>
  <tr>
    <td width="7%" height="27" nowrap="nowrap" bgcolor="#FFFFFF" ><strong>Sales Date </strong></td>
    <td width="1%" nowrap="nowrap" bgcolor="#FFFFFF" ><strong>:</strong></td>
    <td width="28%" nowrap="nowrap" bgcolor="#FFFFFF" ><?php echo $sale_date;?></td>
    <td nowrap="nowrap"><span class="text_style1">Client Address </span></td>
    <td><strong>:</strong></td>
    <td><?=$client_address?></td>
  </tr>
</table>


     <div class="panel">
            <div class="panel-heading"><strong>Item List of Sales </strong></div>
          
            <table width="100%" class="table table-striped">
		
            <?php 
				 $sql_viewtmp="select *  from view_salesreturn_det where purretmas_id=$purretmas_id and session_login_id = '".$_SESSION['login_id']."'";
				$res_viewtmp=mysql_query($sql_viewtmp);
				if(mysql_num_rows($res_viewtmp)>0)
				{ 
					$i=1;
					$sums=0;
					?>
                     
                     <tr height="32" align="left">
            <th nowrap="nowrap" width="7%">Si No</th>
            <th nowrap="nowrap" width="40%">Item Name</th>
           
            <th nowrap="nowrap" width="20%">Unit Name </th>
            <th nowrap="nowrap" width="20%">Return Qty</th>
            <th nowrap="nowrap" width="20%">Sell Price(Per) </th>
            <th nowrap="nowrap">Total</th>
            <th nowrap="nowrap">Discount</th>
            <th width="20%" nowrap="nowrap">CGST(%)</th>
            
            <th width="20%" nowrap="nowrap">SGST(%)</th>
            
            <th width="20%" nowrap="nowrap">IGST(%)</th>
           
            <th nowrap="nowrap" width="20%">Total Price</th>
            </tr>
            <?php
				while($rows=mysql_fetch_assoc($res_viewtmp))
					{
						
						
						
						
							
							
			?>
           
            <tr height="32">
            <td nowrap="nowrap" width="7%"><?php echo $i;?></td>
           
		    <td ><?php echo $rows["item_name"];?></td>
            
            <td nowrap="nowrap" width="20%"><?php echo $rows["unit_name"];?></td>
            <td nowrap="nowrap" width="20%"><?php echo $rows["ret_qty"];?></td>
            <td nowrap="nowrap" width="20%"><?php echo $rows["sell_price"];?></td>
            <td nowrap="nowrap"><?php  $totsum=($rows["ret_qty"]*$rows["sell_price"]); echo number_format($totsum,2);?></td>
            <td nowrap="nowrap"><?php  $discount=$totsum*($rows["discount"]/100); echo number_format($discount,2);$totprice=($totsum-$discount);?></td>
            <td width="20%" nowrap="nowrap"><?php echo $rows["cgst"];?><?php  $cgst=$totprice*($rows["cgst"]/100);  number_format($cgst,2);?></td>
           
            <td width="20%" nowrap="nowrap"><?php echo $rows["sgst"];?><?php  $sgst=$totprice*($rows["sgst"]/100);  number_format($sgst,2);?></td>
           
            <td width="20%" nowrap="nowrap"><?php echo $rows["igst"];?><?php  $igst=$totprice*($rows["igst"]/100);  number_format($igst,2);?></td>
           
            <td nowrap="nowrap"><?php  $totamt=$totprice+$cgst+$sgst+$igst; echo number_format($totamt,2);?></td>
            </tr>  <?php $sums=$sums+($totamt);$i++;} ?>   
            <tr height="32">
              <td nowrap="nowrap">&nbsp;</td>
              <td colspan="9" nowrap="nowrap"><div align="right"><strong>Sum Total : </strong></div></td>
              <td nowrap="nowrap"><?php echo number_format($sums,2);?></td>
              </tr> 
            <?php }?>
           </table>
		   
		          
        
      
        
        <table width="100%" class="table table-bordered">
          <tr>
            <td width="85%"><div align="right"><strong>Grand Total</strong></div></td>
            <td width="15%"><?php  $nettot=@$sums; echo number_format($sums,2);?></td>
          </tr>
		  
          <tr>
            <td><div align="right"><strong>Round Off</strong></div></td>
            <td> <?php echo number_format(round($sums),2);?></td>
          </tr>
        </table>
    </div>
	 <?php 
				$sql_viewd="select *  from tbl_account where session_login_id = '".$_SESSION['login_id']."' and  mas_id=$purretmas_id and sales_type='Sales Return' and clear=1";
				$res_viewd=mysql_query($sql_viewd);
				if(mysql_num_rows($res_viewd)>0)
				{ 
					$u=1;
					
					?>
                     <table width="100%" class="table table-striped">
                     <tr height="32" align="left">
            <th nowrap="nowrap" width="18%">Si No</th>
            <th nowrap="nowrap" width="66%">Transaction Date </th>
           
            
            <th nowrap="nowrap" width="16%">Given Amount </th>
            </tr>
            <?php
			$dr=0;
				while($rowsd=mysql_fetch_assoc($res_viewd))
					{
						
						
						
						
							
							
			?>
           
            <tr height="32">
            <td nowrap="nowrap" width="18%"><?php echo $u;?></td>
           
		    <td nowrap="nowrap" width="66%"><?php echo $objIms->IntToDate($rowsd["trans_date"]);?></td>
            
           
            <td nowrap="nowrap" width="16%"><?php echo $Dr_Amt=($rowsd["Dr_Amt"]);?></td>
            </tr>  <?php $dr=$dr+($Dr_Amt);$u++;} ?>   
            <tr height="32">
              <td nowrap="nowrap">&nbsp;</td>
              <td nowrap="nowrap"><div align="right"><strong>Total Paid: </strong></div></td>
              <td nowrap="nowrap"><?php echo $dr;?>	</td>
              </tr> 
           </table>
    <?php }?>
		


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