<?
ob_start();
session_start();
if(isset($_SESSION['ses_name']))
{
$user=$_SESSION['ses_name'];
}else{
header("location:index.php");
}
$tyrenum_veh='';

include("include/config.php");
require_once "include/Database_functions.php";
$sqlObj=new sqlclass();

//$tablename='cf_client';
$todaydate = date('Y-m-d H:i:s');
		if(isset($_POST['purchasesubmit'])){
			
			if(isset($_POST['vendor_id'])){
			$vendorid=addslashes($_POST['vendor_id']);
			}
			
			if(isset($_POST['conver_oil_kg'])){
			$converoilkg=addslashes($_POST['conver_oil_kg']);
			}	
			
			if(isset($_POST['conver_oil'])){
			$converoil=addslashes($_POST['conver_oil']);
			}
			
			if(isset($_POST['conver_oil_per'])){
			$oil_per=addslashes($_POST['conver_oil_per']);
			}
				
			
			if(isset($_POST['conver_pinnakku'])){
			$converpinnakku=addslashes($_POST['conver_pinnakku']);
			}	
			
			if(isset($_POST['conver_pinnakku_per'])){
			$pinnakku_per=addslashes($_POST['conver_pinnakku_per']);
			}	
			
						
			if(isset($_POST['sack_no'])){
			$sackno=addslashes($_POST['sack_no']);
			}
			
			if(isset($_POST['sackgs'])){
			$sack_kgs=addslashes($_POST['sackgs']);
			}	
			
			if(isset($_POST['damaged_qty'])){
			$damagedqty=addslashes($_POST['damaged_qty']);
			}	
			
						
			$sql2 = mysql_query("insert into cf_kopra_purchase (kop_vendor_id,kopra_kg,conv_oil,oil_percentage,conv_pinnaku,pinnaku_percentage,sack_no,sack_kg,damaged_qty,add_date) values ('$vendorid','$converoilkg','$converoil','$oil_per','$converpinnakku','$pinnakku_per','$sackno','$sack_kgs','$damagedqty','$todaydate')");
						 
			$productid = mysql_insert_id();
			
			$sql3 = mysql_query("insert into cf_purchase (purchase_vendorid,purchase_prdid,purchase_total,purchase_pinna_total,purchase_type,purchase_addate) values ('$vendorid','$productid','$converoil','$converpinnakku','kopra','$todaydate')");	
			
		$sq_stock=mysql_query("select * from cf_stock");	
		if(mysql_num_rows($sq_stock) > 0)
		   {
		   		$rw = mysql_fetch_array($sq_stock);
				$stockoil = $rw['stock_coconutoil'] + $converoil;
				$stockpinnaku = $rw['stock_pinnaku'] + $converpinnakku;
		   		$sql4 = mysql_query("update cf_stock set stock_coconutoil = '$stockoil',stock_pinnaku='$stockpinnaku',add_date='$todaydate'");	
		   }
		   /*else
		   {	
		   		$sql5 = mysql_query("insert into cf_stock (stock_oil,stock_pinnaku,add_date) values ('$converoil','$converpinnakku','$todaydate')");	
		   }*/
			
			header("location:kopra_purchase_list.php");	
					
			}
			
				$kopvendorids = '';
				$koprakgs = '';
				$convoils = '';
				$convpinnakus = '';
				$sacknos = '';			
			    $damagedqty = '';
			
			if(isset($_REQUEST['pur_mainid'])){
			
				$id=$_REQUEST['pur_mainid'];
				$tablename='cf_kopra_purchase';
				$sqlObj->tablename="cf_kopra_purchase";
				$condition=" where kop_pur_id='$id'";
				$sqlObj->condition=$condition;
				$sqlObj->fieldvalue="*";
				$fieldvalue=$sqlObj->fieldvalue;
				$sql=$sqlObj->SelectTable();
				$kopvendorids = $sql['kop_vendor_id'];
				$koprakgs = $sql['kopra_kg'];
				$convoils = $sql['conv_oil'];
				$convpinnakus = $sql['conv_pinnaku'];
				$sacknos = $sql['sack_no'];
				$damagedqty = $sql['damaged_qty'];
				
				
			if(isset($_POST['vendor_id'])){
			$vendorid=addslashes($_POST['vendor_id']);
			}
			
			if(isset($_POST['conver_oil_kg'])){
			$converoilkg=addslashes($_POST['conver_oil_kg']);
			}	
			
			if(isset($_POST['conver_oil'])){
			$converoil=addslashes($_POST['conver_oil']);
			}	
			
			if(isset($_POST['conver_pinnakku'])){
			$converpinnakku=addslashes($_POST['conver_pinnakku']);
			}	
			
			if(isset($_POST['sack_no'])){
			$sackno=addslashes($_POST['sack_no']);
			}	
			
				
				/*$sqlObj->tablename=$tablename;
				if(isset($_POST['vendor_id']))
				{
				
				
				$sq_kopra=mysql_query("select * from cf_purchase where purchase_type = 'kopra' and purchase_vendorid = '$vendorid' and purchase_prdid = '$id'");
				$rw1=mysql_fetch_array($sq_kopra);	
				$purtot = $rw1['purchase_total'];
				$pinnatot = $rw1['purchase_pinna_total'];
				
				$sq_stock=mysql_query("select * from cf_stock");	
				if(mysql_num_rows($sq_stock) > 0)
				   {
						$rw = mysql_fetch_array($sq_stock);
						$stockoils = $rw['stock_oil'] - $purtot;
						$stockpinnakus = $rw['stock_pinnaku'] - $pinnatot;
						$sql4 = mysql_query("update cf_stock set stock_oil = '$stockoils',stock_pinnaku='$stockpinnakus'");	
				   }
				   
				mysql_query("delete from cf_purchase where purchase_vendorid = '$vendorid' and purchase_prdid = '$id'");
				
				$sql3 = mysql_query("insert into cf_purchase (purchase_vendorid,purchase_prdid,purchase_total,purchase_pinna_total,purchase_type,purchase_addate) values ('$vendorid','$productid','$converoil','$converpinnakku','kopra','$todaydate')");	
				
				
				$oilstock = stockoils + $converoil;
				$pinnakustock = stockpinnakus + $converpinnakku;
				$sql4 = mysql_query("update cf_stock set stock_oil = '$oilstock',stock_pinnaku='$pinnakustock',add_date='$todaydate'");	
				
				
				$sql2 = mysql_query("insert into cf_kopra_purchase (kop_vendor_id,kopra_kg,conv_oil,oil_percentage,conv_pinnaku,pinnaku_percentage,sack_no,sack_kg,damaged_qty,add_date) values ('$vendorid','$converoilkg','$converoil','$oil_per','$converpinnakku','$pinnakku_per','$sackno','$sack_kgs','$damagedqty','$todaydate')");
				
				$result=mysql_query("update cf_kopra_purchase set 
				kop_vendor_id = '$vendorid',
				kopra_kg ='$converoilkg',
				oil_percentage='$converoil',
				conv_oil ='$ffarequested',
				conv_pinnaku='$purchasetype',
				conv_pinnaku='$commodityval'
				where kop_pur_id = '$id'");
				
				header("location:kopra_purchase_list.php");
				}*/
					
			}

?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>OIL FILL</title>
<link href="css/styles.css" rel="stylesheet"  />
<link type="text/css" href="css_date/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
<!--<script src="js/driverdrop.js"></script>-->
<script src="js/addmoreclient.js"></script>
<script type="text/javascript" src="scripts_date/jquery.js"></script>
<script type="text/javascript" src="scripts_date/jquery-calendar-1.7.2.js"></script>
<script>$(document).ready(function(){
$('#tripdate').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'yy-mm-dd'
});
});

</script>

<script type="text/javascript">
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
function validation(){
if(document.clientform.clientname.value==''){
alert("Enter the Client Name");
document.clientform.clientname.focus();
return false;
}

var cnt = document.getElementById('totcntw').value;

for(i=1;i<=cnt;i++){

	if(document.getElementById('location'+i).value==''){
			alert("Select the town");
			return false;
	}
			
	if(document.getElementById('phoneno'+i).value==''){
		alert("Enter the Phone no");
		return false;
	}
			
	if(document.getElementById('consperson'+i).value==''){
		alert("Enter the Concerned Person");
		return false;
	}
		
		
}

}
</script>

<script>


function chk_kopra_pur(num)
	{
		var converoilkg = '';
		var converoilper = '';
		var converpinnakkuper = '';
		var sackgs='';
		var oilper ='';
		var pinnakkuper ='';
		var sackno ='';
		var damagedqty ='';
		if(document.getElementById('conver_oil_kg').value != '')
		{
			converoilkg = document.getElementById('conver_oil_kg').value;
		}
		else
		{
			document.getElementById('conver_oil_kg').value = ''; 
		}
		
		
		converoilper = document.getElementById('conver_oil_per').value;
		converpinnakkuper = document.getElementById('conver_pinnakku_per').value ;
		sackgs = document.getElementById('sackgs').value ;
		
		oilper = (converoilper*converoilkg)/100;
		pinnakkuper = (converpinnakkuper*converoilkg)/100;
		sackno = converoilkg/sackgs;
		damagedqty = (converoilkg*3)/100;
		document.getElementById('conver_oil').value = oilper;
		document.getElementById('conver_pinnakku').value = pinnakkuper;
		document.getElementById('sack_no').value = sackno;
		document.getElementById('damaged_qty').value = damagedqty;
		
	}







</script>

<style>
.lableentrytext{
font-size: 12px;
color: #505050;
clear: both;
margin-bottom: 5px;
text-transform: capitalize;
}

body {
	padding:0px;
	margin:0px;
	font-family:Arial, Helvetica, sans-serif;
	color:#000000;
}
.div01 {
	width:80%;
		margin:0 70px;
	padding-bottom:15px;
}
.ptForm {
	/*border:1px solid #000000;*/
	width:100%;
	margin:0 auto;
	padding:4px;
}
.ptText01 {
	font-size:20px;
	font-weight:bold;
}
.ptText02 {
	font-size:12px;
}
.ptText03 {
	font-size:16px;
	font-weight:bold;
}
.ptText04 {
	font-size:16px;
	font-weight:bold;
	border-left:solid 1px #000000;
	border-right:solid 1px #000000;
	border-top:solid 1px #000000;
}
.ptText05 {
	font-size:14px;
	font-weight:bold;
}
.field01 {
	border-bottom:#333333 dotted 1px;
	border-left:none;
	border-top:none;
	border-right:none;
	color:#000000;
	font-size:12px;
	font-weight:bold;
	background-color:#f1f1f1;
}
.field02 {
	border:none;
	color:#000000;
	font-size:12px;
	font-weight:bold;
	background-color:#f1f1f1;
}
.ptText06 {
	font-size:12px;
	font-weight:bold;
}
.rightTd {
	border-bottom:solid 1px #000000;
}
.leftTd {
	border-bottom:solid 1px #000000;
	border-right:solid 1px #000000;
	padding:4px;
}
.tdItem {
	border-bottom:solid 1px #000000;
	border-right:solid 1px #000000;
	padding:4px;
}
.rightTd {
	border-bottom:solid 1px #000000;
	padding:4px;
}
/*.rightTdBtm {
	border:none;
	padding:4px;
}
.leftTdBtm {
	border-right:solid 1px #000000;
	padding:4px;
}*/
.tdItemBtm {
	
	padding:4px;
}

#adv{

	display:none;
	
}

</style>



</head>

<body onLoad="">
<div class="wrapper">
  <div>
<?php 
	include("header.php");
?>
 
</div>
 
 
<div class="tabbedArea">
<?php
/*if(!empty($_REQUEST['tripid']))
{ 
	$tripid1 = $_REQUEST['tripid'];
	$arrtrip1=mysql_query("select * from cf_tripsheetsub where trip_id = '$tripid1'");
	$cnttrip1=mysql_num_rows($arrtrip1);
	if($cnttrip1>0){
		$div = $cnttrip1;
	}else{
		$div=1;
	}
}else{
		$div=1;
}*/
	$div=1;	
	?>
    <input type="hidden" id="divcnt" name="divcnt" value="<?=$div?>"/>
  <div class="tabBody">
  <?php 
		if(empty($_REQUEST['clientsubid']))
		{ ?>
		  <h1>Add Purchase Kopra</h1>
		  <?php } else { ?>
		  <h1>Edit Purchase Kopra</h1>
		<?php }
  ?>
   
   <div class="div01">
  <div class="ptForm">
  <form name="clientform" id="clientform" method="post" >
    <table width="100%" border="0" cellspacing="5" cellpadding="2"  style="border:1px solid #000000; padding:4px;">
           
      <input type="hidden" name="totcnt" id="totcntw" value="<?=$div?>">
     
        
        <!--<td class="ptText06" style="text-align:left;">No.
          <input name="" type="text" class="field02"  style="width:82%;" /></td>-->
         
         
      <tr>
        <td  colspan="5"  class="ptText02" style="width:70%;"><div id="list">
          <table width="100%"  cellspacing="0" cellpadding="0"   class="List" align="center" style="border-top:solid 1px #000000; border-bottom:none; border-left:solid 1px #000000; border-right:solid 1px #000000;" >
            <tr>
              <td width="25%" class="tdItem" style="font-weight:bold;">Vendor</td>
              <td width="75%" class="tdItem" style="font-weight:bold;">Kg</td>
            </tr>
            <tr>
              <td class="tdItem"><select class="input1" name="vendor_id" id="vendor_id" >
                  <option value="">Select Vendor</option>
                  <?php 
					$sq_vendor="select * from cf_reseller";
					$arrven=mysql_query($sq_vendor);
					while($resven=mysql_fetch_array($arrven))
					{
					?>
                  <option value="<?=$resven['reseller_id']?>" <? if($resven['reseller_id']==$kopvendorids) {?>selected<? }?>   >
                    <?=$resven['res_name']?>
                    </option>
                  <?php
					}
	 				?>
                </select>              </td>
              <td class="tdItem"><input type="text" name="conver_oil_kg" id="conver_oil_kg" class="input1" style="width:75px;" value="<?=$koprakgs?>" onKeyUp="chk_kopra_pur();" > 
                Kg Kopra</td>
            </tr>
            <?php 
            	$arrkopraconv1=mysql_query("select * from cf_kopra where kopra_conv_id = '1'");
				$rws1 = mysql_fetch_array($arrkopraconv1);
				$conoil = $rws1['kopra_conv_per'];
			?>	
 			<tr>
              <td class="tdItem">Conversion of Oil-<?=$conoil?>%</td>
              <td class="tdItem">
              <input type="hidden" name="conver_oil_per" id="conver_oil_per" class="input1" style="width:75px;" value="<?=$conoil?>" >
              <input type="text" name="conver_oil" id="conver_oil" class="input1" style="width:75px;" value="<?=$convoils?>" >
                Kg</td>
            </tr>
            <?php 
            	$arrkopraconv2=mysql_query("select * from cf_kopra where kopra_conv_id = '2'");
				$rws2 = mysql_fetch_array($arrkopraconv2);
				$conpinnaku = $rws2['kopra_conv_per'];
			?>
            <tr>
              <td class="tdItem">Conversion of Pinnakku-<?=$conpinnaku?>%</td>
              <td class="tdItem">
              <input type="hidden" name="conver_pinnakku_per" id="conver_pinnakku_per" class="input1" style="width:75px;" value="<?=$conpinnaku?>" >
              <input type="text" name="conver_pinnakku" id="conver_pinnakku" class="input1" style="width:75px;" value="<?=$convpinnakus?>" >
                Kg</td>
            </tr>
            <?php 
            	$arrkopraconv3=mysql_query("select * from cf_kopra where kopra_conv_id = '3'");
				$rws3 = mysql_fetch_array($arrkopraconv3);
				$sack_no = $rws3['kopra_conv_per'];
			?>
             <tr>
              <td class="tdItem">Sack-<?=$sack_no?> kg</td>
              <td class="tdItem">
              <input type="hidden" name="sackgs" id="sackgs" class="input1" style="width:75px;" value="<?=$sack_no?>" >
              <input type="text" name="sack_no" id="sack_no" class="input1" style="width:75px;" value="<?=$sacknos?>" >
              No</td>
            </tr>
            
            <tr>
              <td class="tdItem">Damaged 3%</td>
              <td class="tdItem">
              <input type="text" name="damaged_qty" id="damaged_qty" class="input1" style="width:75px;" value="<?=$damagedqty?>" >
              kg</td>
            </tr>
            	
          </table>
        </div></td>
      </tr>
        
            
            <tr>
            	<td width="825">
                <?php 
                 	if(empty($_REQUEST['pur_mainid']))
					{ ?>
					  <input type="submit" name="purchasesubmit" value="submit" class="submit-btn" onClick="return validation()"  >
                <?php } else { ?>
                	  <input type="submit" name="clientedit" value="edit" class="submit-btn" onClick="return validation()"  >
                <?php } ?>                </td>
            </tr>    
    </table>
    
    </form>
    
  </div>
  <div style="text-align:center;">
    
  </div>
</div>
   </div>
 </div>
 <div class="footer"><p>Powered by <a href="http://www.aadhocc.co.uk/" target="_blank">Aadhocc</a></p></div>
 
</div>
<div class="quicLInksCover">
  <?php 
	include("leftlink.php");
?>

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


		






