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



<?php
if(isset($_GET["uid"]))
{
$uid=$_GET["uid"];
	$whr1="md5(id)='$uid'";
$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"]);
	}
	
	if(isset($_POST["Save"]))
	{
	$tothavepaid=$_POST["tothavepaid"];
	$due=$_POST["due"];
	$stampdate=$objIms->DateToInt(date('d-m-Y'));
	$invoice_no=$objIms->trasaction_no();
	if($tothavepaid>=$due)
	{
	$sql_ins="insert into tbl_account(invoice_no,mas_id,trans_date,actual_amt,Dr_Amt,sales_type,cash_type)values('$invoice_no','$salesmas_id','$stampdate','$actual_amt','$due','Sales','Debit')";
	
				
				$res_ins=mysql_query($sql_ins);
				$accid=mysql_insert_id();
				header("location:sales_duereciept.php?uid=".md5($accid));
	}
	else
	{
	$msg="Please Fill Correct Amount";
	}
	}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>

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

<body>

<div class="span11" style=" width:83%;">



<div class="12" style=" margin-left:0px; ">


<a href="<?php echo $objIms->pageCaption($varFileName)?>_list.php?page=1&cmd=Clear" style="float:right">
<span class="btn" style="margin:20px 0px 20px 0px; font-weight:bold">Go Back</span></a>
<br />
<br />
<br />

<div class="12" style=" margin-left:0px;">
<div class="panel" style="border:<?php echo THEMECOLOR?> solid 1px; border-radius:0px;">
<div class="panel-heading" style="margin-bottom:15px; background:<?php echo THEMECOLOR?>; color:<?php echo THEMEFONRCOLOR?>; font-weight:bold; border-radius:0px;">
View Client
</div>
<form id="form1" name="form1" method="post" action="">
<p>&nbsp;</p>
<table width="100%" class="table table-bordered" cellpadding="4">
  <tr>
    <td height="38" 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="38" 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="34" 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 $saledt;?></td>
    <td nowrap="nowrap"><span class="text_style1">Client Address </span></td>
    <td><strong>:</strong></td>
    <td><?=$client_address?></td>
    </tr>
</table>
<br />


     <div class="panel">
            <div class="panel-heading"><strong>Item List of Sale </strong></div>
            <p>&nbsp;</p>
            <table width="100%" class="table table-striped">
		
            <?php
  $sql_viewtmp="select *  from view_sales_detail where salesmas_id=$salesmas_id";
				$res_viewtmp=mysql_query($sql_viewtmp);
				if(mysql_num_rows($res_viewtmp)>0)
				{ 
					$i=1;
					$sum=0;
  ?>
  <tr>
    <td width="6%" height="28"><span class="text_style1">Si No</span></td>
    <td width="29%"><span class="text_style1">Item Name</span></td>
    <td width="18%"><span class="text_style1">Unit Name</span></td>
    <td width="13%"><span class="text_style1">Order Qty</span></td>
    <td width="17%"><span class="text_style1">Price(Pc)</span></td>
    <td width="17%"><strong>Total</strong></td>
    <td width="17%"><strong>Discount</strong></td>
    <th width="20%" align="left" nowrap="nowrap">CGST(%)</th>
    <th width="20%" align="left" nowrap="nowrap">CGST </th>
    <th width="20%" align="left" nowrap="nowrap">SGST(%)</th>
    <th width="20%" align="left" nowrap="nowrap">SGST</th>
    <th width="20%" align="left" nowrap="nowrap">IGST(%)</th>
    <th width="20%" align="left" nowrap="nowrap">IGST</th>
    <td width="17%"><span class="text_style1">Total Price</span></td>
  </tr>
  <?php
  $sum=0;
  while($rows=mysql_fetch_assoc($res_viewtmp))
					{
  ?>
  <tr>
    <td height="27"><span class="text_style"><?=$i++?></span></td>
    <td><span class="text_style"><?=$rows["item_name"]?></span></td>
    <td><span class="text_style"><?=$rows["unit_name"]?></span></td>
    <td><span class="text_style"><?=$rows["qty"]?></span></td>
    <td><span class="text_style">
      <?=$rows["unit_price"]?>
    </span></td>
    <td><?php echo $totsum=($rows["unit_price"]*$rows["qty"]);?></td>
    <td><?php echo $discount=$totsum*($rows["discount"]/100); $totprice=($totsum-$discount);?></td>
    <td width="20%" nowrap="nowrap"><?php echo $rows["cgst"];?></td>
    <td width="20%" nowrap="nowrap"><?php  $cgst=$totprice*($rows["cgst"]/100); echo number_format($cgst,2);?></td>
    <td width="20%" nowrap="nowrap"><?php echo $rows["sgst"];?></td>
    <td width="20%" nowrap="nowrap"><?php  $sgst=$totprice*($rows["sgst"]/100); echo number_format($sgst,2);?></td>
    <td width="20%" nowrap="nowrap"><?php echo $rows["igst"];?></td>
    <td width="20%" nowrap="nowrap"><?php  $igst=$totprice*($rows["igst"]/100); echo number_format($igst,2);?></td>
    <td class="text_style1"><?php echo $totamt=$totprice+$cgst+$sgst+$igst;?></td>
  </tr>
  <?php $sum=$sum+$totamt;}}?>
  <tr>
    <td height="27" colspan="13" align="right" class="text_style1">Sum Total : </td>
    <td class="text_style1"><?php echo number_format($sum,2);?></td>
  </tr>
  
    <tr>
      <td height="27" colspan="13" align="right" class="text_style1">Grand Total: </td>
      <td class="text_style1"><?php  $gtol=$sum; echo number_format($gtol,2);$gtol=round($gtol);?></td>
    </tr>
	<tr>
      <td height="27" colspan="13" align="right" class="text_style1">Round Off:</td>
      <td class="text_style1"><?php  echo $gtol=round($gtol);?></td>
    </tr>
  <tr>
    <td height="27" colspan="13" align="right" class="text_style1">Paid Amt: </td>
	<?php $sqlpaid="select sum(Dr_Amt) as paid_amt from tbl_account where mas_id='$salesmas_id' and sales_type='Sales'";
	$exepaid=mysql_query($sqlpaid);
	$rspaid=mysql_fetch_array($exepaid);
	$tolpaidamt=$rspaid["paid_amt"];
	?>
    <td class="text_style1"><?=$rspaid["paid_amt"]?><input type="hidden" name="tothavepaid" value="<?=$gtol-$rspaid["paid_amt"];?>" /></td>
  </tr>
  <tr>
    <td height="27" colspan="13" align="right" class="text_style1">Due:</td>
    <td class="text_style1"><?php $pt=$gtol-$tolpaidamt; ?><input type="text" name="due" style="width:100px;" value="<?php echo $pt;?>" /></td>
  </tr>
  <?php echo '<span style="color:#FF0000">'.$msg.'</span>';?>
  <tr>
    <td height="27" colspan="13" align="right" class="text_style1">&nbsp;</td>
    <td class="text_style1">&nbsp;</td>
  </tr>
  <tr>
    <td height="27" colspan="13"  class="text_style1"><input type="submit" id="Save" name="Save" value="Save" class="btn btn-info" style="margin:inherit; width:100px"/></td>
    <td class="text_style1">&nbsp;</td>
  </tr>
           </table>
    </div>
	
		

   
<p></p>
		<br />
        

</form></div>
</body>
</html>
