<?php
include_once('dashboard_tapal.php');
 require_once('convert_marathi.php');
 #################################### Stamp Purchase Details Form ##########################################################
?>
<html>
<head>
<script type="text/javascript" src="js/adduser.js"></script> 

<script type="text/javascript">

	function doCalc() 	
	{
		var total=0;
		<?php 
		$q=mysql_query("SELECT stamp_nm,value from stamp_master");
		while($r=mysql_fetch_array($q))
		{
		?>	
			var x='<?php echo $r['value']; ?>';
			var y=document.getElementById(x).value;
			var ab=parseInt(y)*x;
			var total=total+ab;
			document.getElementById('total').value= total;
			if(document.getElementById('total').value < 0 )
			{
				alert(" Number of Ticket Can not Be Negative");
			}
		<?php
		}
		?>
	}	
</script>
</head>
<body>
    <div class="rightpanel">
        <ul class="breadcrumbs">
            <li><a href="dashboard_tapal.php"><i class="iconfa-home"></i></a> <span class="separator"></span></li>
            <li><a href="dashboard_tapal.php">Forms</a> <span class="separator"></span></li>
            <li>तिकीट खरेदीची माहिती लावा </li>
        </ul>
        <div class="pageheader">
            <div class="pageicon"><span class="iconfa-pencil"></span></div>
            <div class="pagetitle">
                <h5>Forms</h5>
                <h1>तिकीट खरेदीची माहिती लावा </h1>
            </div>
        </div><!--pageheader-->
        <div class="maincontent">
            <div class="maincontentinner">
				<div class="widget">
					<h4 class="widgettitle">तिकीट खरेदीची माहिती लावा </h4>
					<div class="widgetcontent">
						<?php			
							$purorno=$_POST['purorno'];
							$stampid=$_POST['stampid'];
							$prdt=$_POST['purchasedate'];
							$purdt = date('Y-m-d', strtotime($prdt));
							//$purchasedate=$_POST['purchasedate'];
							$supnm=$_POST['supnm'];
							$supcont=$_POST['supcont'];
							$qty=$_POST['qty'];
							$amt=$_POST['amt'];
							//qry
							$q=("INSERT INTO stamp_purchase_details(stamp_id, quantity, amount, purchase_dt, supplier_nm, supplier_contact,p_s_flag) VALUES('$stampid','$qty','$amt','$purdt','$supnm','$supcont','p')");
							mysql_query($q) or die("aaa".mysql_error());
							
							////// fetch stock from master table
							$q1=mysql_query("SELECT stock from stamp_master where stamp_id='$stampid' ");
							$r1=mysql_fetch_array($q1);
							$stock=$r1['stock'];
							
							////// add purchase to stock in master table
							$curstock=$stock+$qty;
							$q2=mysql_query("UPDATE stamp_master SET stock='$curstock' where stamp_id='$stampid'")or die("bbbb".mysql_error());
							
							/*$q3="select * from stamp_transaction,stamp_purchase_details where stamp_purchase_details.stamp_id=stamp_transaction.stamp_id";
							$rs=mysql_query($q3);
							while($r=mysql_fetch_array($rs))
							{
								$stock=$r['current_stock']+$qty;
								$stamp=$r['stamp_id'];
							}
							if($stamp==$stampid)
							{
								$q2=("UPDATE stamp_transaction SET stamp_transaction.current_stock='$stock' where stamp_id='$stampid'");
								mysql_query($q2) or die("cccc".mysql_error());
							}
							else
							{
								$q3=("INSERT INTO stamp_transaction(stamp_id,current_stock) VALUES('$stampid','$qty')");
								mysql_query($q3) or die("ddd".mysql_error());
							}	*/	
						?>
					<form class="stdform" action="stamp_purchase_details.php" method="post" name="stampdetails">
						<table width="50%">
							<tr>
							<td>
								<label>तिकिटाचे नाव टाका : </label></td>
							<td> 
							<span>
							<?php 
								convert_marathi();
								$query = "SELECT  * FROM stamp_master";   
								$result = mysql_query($query);
								echo "<select name='stampid'><option value=''>तिकीट निवडा </option>";
								while($row = mysql_fetch_array($result))
                                {
                                    echo "<option value=$row[stamp_id]>".$row['stamp_nm']."</option>"; 
								}
                               echo "</select>";
							?>                          
                            </span></td>
							</tr>
							<tr>
								<td> <label>नग : </label></td>
								<td><input type="text" name="qty" class="input-medium" placeholder="नग" onKeyup='doCalc();' /></td>
							</tr>
							<tr> 
								<td><label>रक्कम  : </label></td>
								<td><input type="text" name="amt" class="input-medium" placeholder="रक्कम"/></td>
							</tr>
							<tr>
								<td><label>खरेदी दिनांक  : </label></td>
								<td><input type="text" name="purchasedate" class="input-medium" placeholder="dd-mm-yyyy"/></td>
							</tr>
                          <!--  <tr>
								<td><label>पुरवठादाराचे नाव  : </label></td>
								<td><input type="text" name="supnm" class="input-medium unicode" lang="mr" placeholder="पुरवठादाराचे नाव "/></td>
							</tr>
							<tr>
								<td> <label style="width:130px;">पुरवठादाराचा संपर्क क्र : </label></td>
								<td><input type="text" name="supcont" class="input-medium" placeholder="मोबाईल क्र"/></td>
							</tr> -->
						</table>                 
                        <p class="stdformbutton">
                            <center> <button class="btn btn-primary" onclick="return stampPurchase()">जतन करा </button>
							<button type="reset" class="btn">रद्द करा</button></center>
                        </p>
                    </form>
                </div><!--widgetcontent-->
            </div><!--widget-->
            <?php
            include_once('footer.php');?>
            </div><!--maincontentinner-->
        </div><!--maincontent-->
    </div><!--rightpanel-->
</div><!--mainwrapper-->
</body>
</html>
