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



<?php

if(isset($_GET["uid"]))
{
$uid=$_GET["uid"];
$rs=$objIms->getRows("view_purchase_supplier","md5(id)='$uid' and session_login_id = '".$_SESSION['login_id']."'");
$pur_id=$rs["id"];
$order_no=$rs["order_no"];
$purchase_date=$objIms->IntToDate($rs["purchase_date"]);
$supplier_name=$rs["supplier_name"];

$sql_acc="select *  from tbl_account where mas_id=$pur_id and sales_type='Purchase' and session_login_id = '".$_SESSION['login_id']."' order by id asc";
$res_acc=mysql_query($sql_acc);
$rsacc=mysql_fetch_array($res_acc);
$discount=$rsacc["discount"];
}

if(isset($_POST["Save"]))
{
$stampdate=$objIms->DateToInt(date('d-m-Y'));	
	$dueamt=$_POST["dueamt"];
	$payment_mode=$_POST["r3"];
	$invoice_no=$objIms->trasaction_no();	
$sql_ins="insert into tbl_account(invoice_no,mas_id,trans_date,Dr_Amt,sales_type,cash_type,payment_mode,session_login_id) values('$invoice_no','$pur_id','$stampdate','$dueamt','Purchase','Debit','$payment_mode','".$_SESSION['login_id']."')";
$res_ins=mysql_query($sql_ins);
$acount_id=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 ('$acount_id', '".$_POST['bank_name']."', '".$_POST['branch_name']."', '".$_POST['cheque_no']."', '".$cheque_date."', '".$_SESSION['login_id']."');";
					 $res_ck_dtl=mysql_query($sql_ck_dtl);
					}

header("location:purchase_list.php");
}
	
?>

<!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;}
.style2 {
	color: #00CC00;
	font-style: italic;
}
.style3 {color: #00CC00}


-->
</style>
</head>

<body>

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



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


<a href="purchase_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 Purchase Details
</div>
<form id="form1" name="form1" method="post" action="">
<p>&nbsp;</p>
<table width="100%" cellpadding="4">
  <tr>
    <td height="38" nowrap="nowrap" bgcolor="#FFFFFF" ><strong>Order   No</strong></td>
    <td nowrap="nowrap" bgcolor="#FFFFFF" ><strong>:</strong></td>
    <td nowrap="nowrap" bgcolor="#FFFFFF" ><?php echo $order_no;?></td>
    <td width="8%" height="38" nowrap="nowrap"><strong>Supplier Name</strong></td>
    <td width="2%"><strong>:</strong></td>
    <td width="31%"><?php echo $supplier_name;?></td>
    </tr>
  <tr>
    <td width="7%" height="34" nowrap="nowrap" bgcolor="#FFFFFF" ><strong>Order Date </strong></td>
    <td width="1%" nowrap="nowrap" bgcolor="#FFFFFF" ><strong>:</strong></td>
    <td width="28%" nowrap="nowrap" bgcolor="#FFFFFF" >
       <?php echo $purchase_date;?></td>
    <td nowrap="nowrap">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
</table>
<br />


     <div class="panel">
            <div class="panel-heading"><strong>Item List of Purchase </strong></div>
            <p>&nbsp;</p>
            <table width="100%" class="table table-striped">
              <?php 
				 $sql_viewtmp="select *  from view_purchase_det where purmas_id=$pur_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%">Order Qty</th>
                <th nowrap="nowrap" width="20%">Sell Price(Per) </th>
                <th nowrap="nowrap" width="20%">Pur 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">CGST </th>
                <th width="20%" nowrap="nowrap">SGST(%)</th>
                <th width="20%" nowrap="nowrap">SGST</th>
                <th width="20%" nowrap="nowrap">IGST(%)</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 nowrap="nowrap" width="40%"><?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["pur_qty"];?></td>
                <td nowrap="nowrap" width="20%"><?php echo $rows["sell_price"];?></td>
                <td nowrap="nowrap" width="20%"><?php echo $rows["pur_price"];?></td>
                <td nowrap="nowrap"><?php  $totsum=($rows["pur_qty"]*$rows["pur_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"];?></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 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="13" nowrap="nowrap"><div align="right"><strong>Sum Total : </strong></div></td>
                <td nowrap="nowrap"><?php echo number_format($sums,2);?></td>
              </tr>
              <?php }?>
            </table>
            <?php
		  $sum_total=$sums;
  		
		 
        
		$nettot=@$sum_total;?>
<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=@$nettot; echo number_format($nettot,2);?></td>
              </tr>
              <tr>
                <td><div align="right"><strong>Round Off</strong></div></td>
                <td><?php echo number_format(round($nettot),2);?></td>
              </tr>
			   <tr><td colspan="2"><b>PAYMENT MODE</b></td></tr>
		  <tr><td colspan="2">
               
                  <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>
       </table>
	   <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>
    </div>
     <?php 
				 $sql_viewd="select *  from tbl_account where session_login_id = '".$_SESSION['login_id']."' and mas_id=$pur_id and sales_type='Purchase' and cash_type='Debit'";
				$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="65%">Transaction Date </th>
           
            
            <th nowrap="nowrap" width="17%">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="65%"><?php echo $objIms->IntToDate($rowsd["trans_date"]);?></td>
            
           
            <td nowrap="nowrap" width="17%"><?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 }?>
<span style="float:right; margin-right:50px;"><strong>Due Amount :</strong><?php $tot=$nettot-$dr; $tot=round($tot); ?> <input type="text" name="dueamt" style="width:50px;" value="<?=$tot?>" /></span>
   <br /><br /><br />
<br />


<span style="float:right; margin-right:100px; "><input type="submit" name="Save" style="width:50px;" value="Save" /></span>
<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>
