<?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"]);
	}
	
	if(isset($_POST["Save"]))
	{
	$tothavepaid=$_POST["tothavepaid"];
	$due=$_POST["due"];
	$payment_mode=$_POST["r3"];
	$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 , payment_mode , session_login_id )values('$invoice_no','$salesmas_id','$stampdate','$actual_amt','$due','Sales','Debit','$payment_mode', '".$_SESSION['login_id']."')";
	
				
				$res_ins=mysql_query($sql_ins);
				$accid=mysql_insert_id();
				if($payment_mode=='Cheque')
					{
					$cheque_date = $_POST['cheque_date'];
					$cheque_date = date('Y-m-d', strtotime($cheque_date));
					 $sql_ck_dtl="INSERT INTO `tbl_cheque_detail` (`account_id`, `bank_name`, `branch_name`, `checque_no`, `checque_date`, , `session_login_id`) VALUES ('$accid', '".$_POST['bank_name']."', '".$_POST['branch_name']."', '".$_POST['cheque_no']."', '".$cheque_date."', '".$_SESSION['login_id']."');";
					 $res_ck_dtl=mysql_query($sql_ck_dtl);
					}
				?>
       <script type="text/javascript">
         alert('Success');
       </script> 
				<?php
				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 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;
					$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 session_login_id = '".$_SESSION['login_id']."' and 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 colspan="27"><b>PAYMENT MODE</b></td></tr>
		  <tr><td colspan="3">
               
                  <input type="radio" id="r3" name="r3" value="Cash" class="flat-red" checked>
				  Cash
               
               
                  <input type="radio" id="r3" name="r3" style="margin-left:20px" value="Cheque" class="flat-red">
                  Cheque
               
        	
		
	</td></tr>
	<tr>
	<td colspan="27">
	<hr style="border:6px solid #CCCC00;display:none;" id="cheq_hide_header" />
<div id="cheq_hide" style="display:none; margin:1px;">
 	<table width="100%" class="table table-bordered">
	<tr><td>Bank Name</td>
		<td>
			<input type="text" id="bank_name" name="bank_name" class="w100 form-control" />
		</td>
		<td>Branch Name</td>
		<td>
			<input type="text" id="branch_name" name="branch_name" class="w100 form-control"/>
		</td>
		</tr>
		<tr>
		<td>Cheque Number</td>
		<td>
			<input type="text" id="cheque_no" name="cheque_no" class="w100 form-control"/>
		</td>
		<td>Cheque Date</td>
		<td>
		 <input name="check_date" type="text" id="cheque_date"  style="width:185px; background-color:#FFF"  value="<?=$dt?>" class="tcal" readonly=""/>	</div>
			</td>
			</tr>
		</table>
			</div>
		</div>
	
	</td>
	</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>
<script>
$("input[name='r3']").click(function() {
    var status = $(this).val();
    if (status == 'Cheque') {
        $("#cheq_hide_header").show('slow');
		$("#cheq_hide").show('slow');
    } else {
		$("#cheq_hide").hide();
		$("#cheq_hide_header").hide('slow');
    }
});
</script>
</body>
</html>
