<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$producttotalrows = 1;
if($info4edit["info"]) $producttotalrows = count($info4edit["info"]);
?>

      <div class="main my-0">
        <div class="row mt-3 mx-0">
          <div class="col-md-6">
            <h3><?php echo $pgheading;?></h3>
          </div>
          <div class="col-md-5 text-right">
            &nbsp;
          </div>
        </div>
        
        <div class="container_fluid mt-2 px-3">
		<form name="frmgeneral" method="post" action="account/<?php echo $mgmtname;?>/managedata?<?php echo $_SERVER['QUERY_STRING'];?>" enctype="multipart/form-data"  onsubmit="return validateFrm();">
		<input type="hidden" name="rsrcid" value="<?php echo $rsrcid;?>">                
        <table class="webforms mt-0 table-responsive-sm">
		<tr>
          <td width="15%"><label>Vendor:</label></td>
          <td width="35%">
		  <select name="vendorid" id="vendorid" required>
		  <option value="">Select Vendor</option>
						<?php
						if(is_array($vendorlist) && count(array_filter($vendorlist))>0)
						{

							foreach($vendorlist as $vendorrow)
							{
								$sel_vendor ="";
								if($info4edit["main"]->fld_vendorid==$vendorrow->fld_id)
								{
									$sel_vendor = 'selected="selected"';
								}				
									?>
											<option value="<?php echo $vendorrow->fld_id;?>" <?php echo $sel_vendor;?>><?php echo $vendorrow->fld_name;?></option>
									<?php
								
							}
						}
						?> 
		  </select>
		  </td>
       
          <td width="15%"><label>Warehouse :</label></td>
          <td width="35%">
		  <select name="warehouseid" id="warehouseid" required>
		  <option value="">Select warehouse</option>
						<?php
						if(is_array($warehouselist) && count(array_filter($warehouselist))>0)
						{

							foreach($warehouselist as $warehouserow)
							{
								$sel_warehous ="";
								if($info4edit["main"]->fld_warehouseid==$warehouserow->fld_id)
								{
									$sel_warehous = 'selected="selected"';
								}				
									?>
											<option value="<?php echo $warehouserow->fld_id;?>" <?php echo $sel_warehous;?>><?php echo $warehouserow->fld_name;?></option>
									<?php
								
							}
						}
						?> 
		  </select>
		  </td>
         </tr> 		 
         <tr>
          <td width="15%"><label>Invoice Number:</label></td>
          <td width="35%"><input type="text" name="refno" id="refno" value="<?php if($info4edit["main"]) { echo $info4edit["main"]->fld_refno; }?>" required></td>
  
          <td width="15%"><label>Invoice Date:</label></td>
          <td width="35%"><input type="date" name="refdate" id="refdate" value="<?php if($info4edit["main"]) { echo $info4edit["main"]->fld_refdate; } else { echo date('Y-m-d'); } ?>" required></td>
         </tr> 
		 <tr>
             <td colspan="4" class="text-center">&nbsp;
			 <h5 id="frmerrormsg" class=""></h5>
			 </td>             
         </tr> 
		 <tr>
             <td colspan="4">
			 <table class="webforms mt-0 table-responsive-sm">
			 <tbody id="productrowbox">
			 <tr>
				<th width="30%">Product</th>
				<th width="10%">Qty. (Case)</th>
				<th width="10%">Qty. (Bottle)</th>
				<th width="10%">Price (Case)</th>
				<th width="10%">Price (Bottle)</th>
				<th width="10%">Sub Total</th>
				<th width="20%">&nbsp;</th>
			</tr>
			<?php
					if($info4edit["info"])
					{
						for($iix=0;$iix<count($info4edit["info"]);$iix++)
						{
							$rowidx = $iix+1;
							$rowinfo = $info4edit["info"][$iix];
							
				?>
					  
				<tr id="productrow_<?php echo $rowidx;?>">
				<td>
				<input type="hidden" name="transactioninfoids[]" id="transactioninfoids<?php echo $rowidx;?>" value="<?php echo $rowinfo->fld_id;?>"> 				
				<select  id="productid<?php echo $rowidx;?>" name="productid[]" required style="width:200px!important;" class="js-example-basic-single nxtinput">
                                                                <option value="">--Select Product Name--</option>
<?php
if(is_array($productlist) && count(array_filter($productlist))>0)
{
	
	foreach($productlist as $itemrow)
	{
		$sel_item ="";
		if($rowinfo->fld_productid==$itemrow->fld_id)
		{
			$sel_item = 'selected="selected"';
		}				
			?>
					<option value="<?php echo $itemrow->fld_id;?>" <?php echo $sel_item;?>><?php echo $itemrow->fld_name;?></option>
			<?php
		
	}
}
?>                                                            </select>
</td>
<td><input type="text" name="qty_case[]" id="qty_case<?php echo $rowidx;?>"  placeholder="Quanity" value="<?php echo $rowinfo->fld_qty_case;?>" required="required" data-validation-required-message="This field is required" aria-invalid="false" onchange="calcPurchaseAmt();" onkeypress='return event.charCode >= 48 && event.charCode <= 57 || event.charCode==46' style="width:100px!important;"><span id="qty_caseemsg1" class="" ></span></td>

<td><input type="text" name="qty_bottle[]" id="qty_bottle<?php echo $rowidx;?>"  placeholder="Quanity" value="<?php echo $rowinfo->fld_qty_bottle;?>" required="required" data-validation-required-message="This field is required" aria-invalid="false" onchange="calcPurchaseAmt();" onkeypress='return event.charCode >= 48 && event.charCode <= 57 || event.charCode==46'  style="width:100px!important;"><span id="qty_bottleemsg1" class=""></span></td>

<td><input type="text" step="any" name="price_case[]" id="price_case<?php echo $rowidx;?>"  placeholder="Price" value="<?php echo $rowinfo->fld_price_case;?>" required="required" data-validation-required-message="This field is required" aria-invalid="false" onchange="calcPurchaseAmt();" onkeypress='return event.charCode >= 48 && event.charCode <= 57 || event.charCode==46'  style="width:100px!important;"><span id="price_caseemsh<?php echo $rowidx;?>" class=""></span></td>

<td><input type="text" step="any" name="price_bottle[]" id="price_bottle<?php echo $rowidx;?>"  placeholder="Price" value="<?php echo $rowinfo->fld_price_bottle;?>" required="required" data-validation-required-message="This field is required" aria-invalid="false" onchange="calcPurchaseAmt();" onkeypress='return event.charCode >= 48 && event.charCode <= 57 || event.charCode==46'  style="width:100px!important;"><span id="price_bottleemsg<?php echo $rowidx;?>" class=""></span></td>

<td><input type="text" step="any" name="subtotal[]" id="subtotal<?php echo $rowidx;?>"  placeholder="Price" value="<?php echo $rowinfo->fld_subtotal;?>" required="required" data-validation-required-message="This field is required" aria-invalid="false"  onkeypress='return event.charCode >= 48 && event.charCode <= 57 || event.charCode==46' style="width:100px!important;" readonly><span id="subtotalemsg<?php echo $rowidx;?>" class="" ></span></td>

<td  id="rowid<?php echo $rowidx;?>">
	<?php
	if($iix==0)
	{
	?>
	&nbsp;
	<?php
	}
	else
	{
	?>
	<a class="btn btn-danger text-white" style="cursor:pointer" onclick="return removerow('<?php echo $rowidx;?>','product', 'edit', '<?php echo base_url();?>');">x</a>
	<?php
	}
	?>
</td>
			</tr>					  
				<?php
						}
				?>
				<?php
					}
					else
					{
				?>
			 <tr id="productrow_1">
				<td>
				<select  id="productid1" name="productid[]" required style="width:200px!important;" class="js-example-basic-single nxtinput">
                  <option value="">--Select Product Name--</option>
				<?php
				if(is_array($productlist) && count(array_filter($productlist))>0)
				{
					
					foreach($productlist as $itemrow)
					{
						$sel_item ="";
						if($results->fld_productid==$itemrow->fld_id)
						{
							$sel_item = 'selected="selected"';
						}				
							?>
									<option value="<?php echo $itemrow->fld_id;?>" <?php echo $sel_item;?>><?php echo $itemrow->fld_name;?></option>
							<?php
						
					}
				}
				?> 
				</select>
				</td>
				<td><input type="text" name="qty_case[]" id="qty_case1"  placeholder="Quanity" value="0" required="required" data-validation-required-message="This field is required" aria-invalid="false" onchange="calcPurchaseAmt();" onkeypress='return event.charCode >= 48 && event.charCode <= 57 || event.charCode==46' style="width:100px!important;"><span id="qty_caseemsg1" ></span></td>

				<td><input type="text" name="qty_bottle[]" id="qty_bottle1"  placeholder="Quanity" value="0" required="required" data-validation-required-message="This field is required" aria-invalid="false" onchange="calcPurchaseAmt();" onkeypress='return event.charCode >= 48 && event.charCode <= 57 || event.charCode==46' style="width:100px!important;"><span id="qty_bottleemsg1" ></span></td>

				<td><input type="text" step="any" name="price_case[]" id="price_case1"  placeholder="Price" value="0" required="required" data-validation-required-message="This field is required" aria-invalid="false" onchange="calcPurchaseAmt();" onkeypress='return event.charCode >= 48 && event.charCode <= 57 || event.charCode==46' style="width:100px!important;"><span id="price_caseemsg1" class="" style="width:100px!important;"></span></td>

				<td><input type="text" step="any" name="price_bottle[]" id="price_bottle1"  placeholder="Price" value="0" required="required" data-validation-required-message="This field is required" aria-invalid="false" onchange="calcPurchaseAmt();" onkeypress='return event.charCode >= 48 && event.charCode <= 57 || event.charCode==46' style="width:100px!important;"><span id="price_bottleemsg1" class="" style="width:100px!important;"></span></td>

				<td><input type="text" step="any" name="subtotal[]" id="subtotal1"  placeholder="Price" value="0" required="required" data-validation-required-message="This field is required" aria-invalid="false" onkeypress='return event.charCode >= 48 && event.charCode <= 57 || event.charCode==46' style="width:100px!important;" readonly><span id="subtotalemsg1" class="" style="width:100px!important;" ></span></td>
				<td>&nbsp;</td>
							</tr>
	
<?php
					}

			$subtotalamount = $info4edit["main"]->fld_amount-($info4edit["main"]->fld_vatamount+$info4edit["main"]->fld_tscamount)
		 ?>
		 

		</tbody> 
		</table> 

			 </td>
             
         </tr> 
		 
		 <tr>
             <td></td>
             <td colspan="3" class="text-right"><a class="btn btn-success text-white " style="cursor:pointer" onclick="return addrow('<?php echo base_url();?>');"><i class="fa fa-plus"></i> Row</a></td>
         </tr>
		 <tr>
					<td width="100%" colspan="4" class="text-right">
						<table style="width:30%!important" class="text-left"  align="right">
						<tr>	
							<td class="text-left" width="40%"> <strong>Sub Amount:<strong></td>
							<td class="text-right" width="60%" >
							<input type="hidden" name="producttotalrows" id="producttotalrows" value="<?php echo $producttotalrows;?>"  />
							<input type="text" class="form-control form-control-sm" readonly step="any" name="producttsubtotalamount" id="producttsubtotalamount"  placeholder="Total Amount" value="<?php if($subtotalamount) { echo $subtotalamount; } else { echo "0"; }?>" required="required" data-validation-required-message="This field is required" aria-invalid="false" style="width:150px!important;" >
							</td> 
						</tr>
						<tr>
							<td><strong> Vat Amount :</strong></td>
							<td  >
							<input type="text" class="form-control form-control-sm calcInvAmnt" name="vatamount"  id="vatamount" value="<?php if($info4edit["main"]) { echo $info4edit["main"]->fld_vatamount; }else { echo 0; }?>" placeholder="Vat Amount" onblur="calcPurchaseAmt();"style="width:150px!important;" />
							</td>
						</tr>
						<tr>
							<td ><strong> TSC Amount :</strong></td>
							<td  >
							<input type="text" class="form-control form-control-sm calcInvAmnt" name="tscamount"  id="tscamount" value="<?php if($info4edit["main"]) { echo $info4edit["main"]->fld_tscamount; }else { echo 0; }?>" placeholder="Discount" onblur="calcPurchaseAmt();" style="width:150px!important;"/>
							</td>
						</tr>						
							
						<tr>
							<td><strong> Discount :</strong></td>
							<td  >
							<input type="text" class="form-control form-control-sm calcInvAmnt" name="discount"  id="discount" value="<?php if($info4edit["main"]) { echo $info4edit["main"]->fld_discount; }else { echo 0; }?>" placeholder="Discount" onblur="calcPurchaseAmt();" style="width:150px!important;"/>
							</td>
						</tr>
						<tr>
							<td ><strong> Adjustment :</strong></td>
							<td>
							<input type="text" class="form-control form-control-sm calcInvAmnt" name="adjustment"  id="adjustment" value="<?php if($info4edit["main"]) { echo $info4edit["main"]->fld_adjustment; }else { echo 0; }?>" placeholder="Adjustment" onblur="calcPurchaseAmt();"style="width:150px!important;" />
							</td>
						</tr>
						<tr>
							<td ><strong>Net to Pay:</strong></td>
							<td  >
							<input type="text" class="form-control form-control-sm calcInvAmnt" name="productttotalamount"  id="productttotalamount" value="<?php if($info4edit["main"]) { echo $info4edit["main"]->fld_amount; }?>" placeholder="0"  readonly style="width:150px!important;"/>
							</td>
						</tr>

						<tr>
							<td >&nbsp;</td>
							<td >&nbsp;</td>
						</tr>
						<tr>
							
							<td colspan="2" class="text-right">
							<textarea name="remarks"  class="form-control form-control-sm " id="remarks" rows="2" cols="30" placeholder="Remarks" ><?php if($info4edit) { echo $info4edit["main"]->fld_remarks; }?></textarea>			  
							</td>
						</tr>							
						</table>
					</td>
					
				</tr>
		 
		 <tr>
             <td></td>
             <td colspan="3" class="text-right"><button class="btn btn-danger">Submit</button></td>
         </tr>
         </table>
         </form> 
	         <div class="clearfix"></div>          
        </div>
       </div>
<script type="text/javascript">

document.addEventListener('keyup', function(event) {
	var producttotalrows = $("#producttotalrows").val();
	 eidname =   event.target.name;	
	//alert(event.keyCode);
if (event.shiftKey==false)
{
	if (event.keyCode == 46)
	{
		eid =   event.target.id;
		if(eidname=='productid[]')
		{			
			var eidindex = eid.split("productid");			
		}
		else if(eidname=='qty_case[]')
		{			 
			var eidindex = eid.split("qty_case");			
		}
		else if(eidname=='qty_bottle[]')
		{			
			var eidindex = eid.split("qty_bottle");			
		}
		else if(eidname=='price_case[]')
		{			
			var eidindex = eid.split("price_case");			
		}	
		else if(eidname=='price_bottle[]')
		{			
			var eidindex = eid.split("price_bottle");			
		}
		else if(eidname=='subtotal[]')
		{			
			var eidindex = eid.split("subtotals");			
		}
		indexno  = eidindex[1];
		indexno = parseInt(indexno);		
		if(indexno>1)
		 {		
			transactioninfoids = $("#transactioninfoids"+indexno).val();
			transactioninfoids = parseInt(transactioninfoids);
			//alert(transactioninfoids);
			if(transactioninfoids>0)
			 {
				removerow(indexno,'product','edit','<?php echo base_url();?>');
			 }
			 else
			 {
				removerow(indexno,'product','add','<?php echo base_url();?>');
			 }
		 }
	 }	

	if (event.keyCode == 9 && eidname=="price_bottle[]") 
	{
		eid =   event.target.id;
		var eidindex = eid.split("price_bottle");
		indexno  = eidindex[1];
		indexno = parseInt(indexno);
		if(producttotalrows==indexno)
		{
		addrow('<?php echo base_url();?>');
		}
		indexno = indexno+1;
		indexno = parseInt(indexno);
		//$("#productid"+indexno).focus();
	} 
	else if (event.keyCode == 9 && eidname=="subtotal[]") 
	{
		eid =   event.target.id;
		var eidindex = eid.split("subtotal");
		indexno  = eidindex[1];
		indexno = parseInt(indexno);
		indexno = indexno+1;
		indexno = parseInt(indexno);
		$("#productid"+indexno).focus();
	}  
}
  
});


function addrow(base_url)
{
	var id = $("#producttotalrows").val();
	
	var productlist = $("#productid1").html();

	
	id = parseInt(id) + 1;
	$("#producttotalrows").val(id);	
		
	$("#productrowbox").append('<tr id="productrow_'+id+'"><td><select id="productid'+id+'" name="productid[]" style="width:200px!important;" class="js-example-basic-single nxtinput">'+productlist+'</select></td><td><input type="text" name="qty_case[]" id="qty_case'+id+'" value="0" onchange="calcPurchaseAmt();" onkeypress="return event.charCode >= 48 &amp;&amp; event.charCode <= 57 || event.charCode==46" style="width:100px!important;"><span id="qty_caseemsg'+id+'" class="" ></span></td><td><input type="text" name="qty_bottle[]" id="qty_bottle'+id+'" value="0" onchange="calcPurchaseAmt();" onkeypress="return event.charCode >= 48 &amp;&amp; event.charCode <= 57 || event.charCode==46" style="width:100px!important;"><span id="qty_bottleemsg'+id+'" class=""></span></td><td><input type="text" step="any" name="price_case[]" id="price_case'+id+'" placeholder="Price" value="0" onchange="calcPurchaseAmt();" onkeypress="return event.charCode >= 48 &amp;&amp; event.charCode <= 57 || event.charCode==46" style="width:100px!important;"><span id="price_caseemsg'+id+'" class=""></span></td><td><input type="text" step="any" name="price_bottle[]" id="price_bottle'+id+'" placeholder="Price" value="0" onchange="calcPurchaseAmt();" onkeypress="return event.charCode >= 48 &amp;&amp; event.charCode <= 57 || event.charCode==46" style="width:100px!important;"><span id="price_bottleemsg'+id+'" class=""></span></td><td><input type="text" step="any" name="subtotal[]" id="subtotal'+id+'" placeholder="Price" value="0" readonly onkeypress="return event.charCode >= 48 &amp;&amp; event.charCode <= 57 || event.charCode==46" style="width:100px!important;" readonly><span id="subtotalemsg'+id+'" class=""></span></td><td id="rowid'+id+'"><a class="btn btn-danger text-white" style="cursor:pointer" onclick="return removerow('+id+',\'product\',\'add\',\''+base_url+'\')">x</a></td></tr>');
	$('.js-example-basic-single').select2();

}
function removerow(rowId,actionFor,actionType,base_url)
{
	totalRowIdname = '#'+actionFor+'totalrows';
	removerowId= '#'+actionFor+'row_'+rowId;
	if(actionType == "add")
	{
			totalRow = $(totalRowIdname).val();
			//alert(totalRow);
			$(removerowId).remove();
			
			for(i=eval(rowId+1); i<=totalRow; i++)
			{
				if(actionFor=="product")
				{
					addremovelink = '<a class="btn btn-danger text-white" style="cursor:pointer" onclick="return removerow('+eval(i-1)+',\'product\',\'add\',\''+base_url+'\')">x</a>';
					$("#productrow_"+i).attr('id','productrow_'+eval(i-1));
					$("#productid"+i).attr('id','productid'+eval(i-1));
					$("#qty_case"+i).attr('id','qty_case'+eval(i-1));
					$("#qty_bottle"+i).attr('id','qty_bottle'+eval(i-1));
					$("#price_case"+i).attr('id','price_case'+eval(i-1));				
					$("#price_bottle"+i).attr('id','price_bottle'+eval(i-1));				
					$("#subtotal"+i).attr('id','subtotal'+eval(i-1));
					$("#rowid"+i).html(addremovelink);	
					$("#rowid"+i).attr('id','rowid'+eval(i-1));						
				}
						
			}
			
			var id = $(totalRowIdname).val();
			id = parseInt(id) - 1;
			$(totalRowIdname).val(id);
		
	}
	if(actionType == "edit")
	{
		if(!confirm('Action will delete the row!\nAre you sure?')) return false;			
				if(actionFor=="product")
				{
					delrowid = $("#transactioninfoids"+rowId).val();
				}				
			//alert(delrowid);
		$.ajax({
			url: base_url+"account/removecommonrow",
			data: {'task': actionFor, 'rowid': delrowid},
			type: "post",

			beforeSend: function() {
				//$("#row"+rowId).html('<img src="'+base_url+'assets/images/loader.gif" width="40" style="margin-left: 141px; margin-top: 11px;" />');
			},
			success: function(data){
				var msg = data.trim();
				//alert(msg);
				if(msg=="success")
				{					
					totalRow = $(totalRowIdname).val();
					
					for(i=eval(rowId+1); i<=totalRow; i++)
					{
						if(actionFor=="product")
						{	
							addremovelink = '<a class="btn btn-danger text-white" style="cursor:pointer" onclick="return removerow('+eval(i-1)+',\'product\',\'add\',\''+base_url+'\')">x</a>';
							$("#productrow_"+i).attr('id','productrow_'+eval(i-1));
							$("#productid"+i).attr('id','productid'+eval(i-1));
							$("#qty_case"+i).attr('id','qty_case'+eval(i-1));
							$("#qty_bottle"+i).attr('id','qty_bottle'+eval(i-1));
							$("#price_case"+i).attr('id','price_case'+eval(i-1));				
							$("#price_bottle"+i).attr('id','price_bottle'+eval(i-1));				
							$("#subtotal"+i).attr('id','subtotal'+eval(i-1));
							$("#rowid"+i).html(addremovelink);	
							$("#rowid"+i).attr('id','rowid'+eval(i-1));								
						}
					}					
					setTimeout(function(){ 
						$(removerowId).remove();
						var id = $(totalRowIdname).val();
						id = parseInt(id) - 1;
						$(totalRowIdname).val(id);
			
					}, 500);
					
				}
			}
		});
	}
	
	setTimeout(function(){ calcPurchaseAmt(); }, 1000);
}

function calcPurchaseAmt()
{
	
	
		totalproductamount = 0;
		rowamount=0;
		
		var producttotalrows = $("#producttotalrows").val();
		for(c=1; c<=producttotalrows; c++)
		{
			subtotal=0;
			qty_case 	= $("#qty_case"+c).val();
			qty_case = parseFloat(qty_case);
			price_case 	= $("#price_case"+c).val();
			price_case = parseFloat(price_case);

			if(qty_case>0 && price_case>0)
			{	
				
				subtotal_case = (price_case*qty_case);
				subtotal_case = parseFloat(subtotal_case);				
				subtotal = subtotal+subtotal_case;
			}
			qty_bottle 	= $("#qty_bottle"+c).val();
			qty_bottle = parseFloat(qty_bottle);
			price_bottle 	= $("#price_bottle"+c).val();
			price_bottle = parseFloat(price_bottle);

			if(qty_bottle>0 && price_bottle>0)
			{				
				subtotal_bottle = (price_bottle*qty_bottle);
				subtotal_bottle = parseFloat(subtotal_bottle);				
				subtotal = subtotal+subtotal_bottle;
				
			}
			
			subtotal = parseFloat(subtotal);
			$("#subtotal"+c).val(subtotal.toFixed(2));
			rowamount = rowamount+subtotal;
		}	
		subtotalamount = parseFloat(rowamount);
		$("#producttsubtotalamount").val(subtotalamount.toFixed(2));
		totalproductamount = subtotalamount;
		vatamount = $("#vatamount").val();
		vatamount = parseFloat(vatamount);
		if(vatamount>0)
		{
				totalproductamount = totalproductamount+vatamount;
		}
		tscamount = $("#tscamount").val();
		tscamount = parseFloat(tscamount);
		if(tscamount>0)
		{
				totalproductamount = totalproductamount+tscamount;
		}
		discount = $("#discount").val();
		discount = parseFloat(discount);
		if(discount!="")
		{
				totalproductamount = (totalproductamount-discount);
		}
		adjustment = $("#adjustment").val();
		adjustment = parseFloat(adjustment);
		if(adjustment!="")
		{
			if (adjustment >= 0)
			{
				totalproductamount = (totalproductamount+adjustment);
			}
			else
			{
				
				totalproductamount = (totalproductamount+(adjustment));
			}
				
		}



	
	totalproductamount = parseFloat(totalproductamount);

	$("#productttotalamount").val(totalproductamount.toFixed(2));
	
}

function validateFrm()
{
	
		erroralert = 0;
		errorvalmsg = "";
		var producttotalrows = $("#producttotalrows").val();
		for(c=1; c<=producttotalrows; c++)
		{
			
			var qty_case = $("#qty_case"+c).val();	
			qty_case = parseFloat(qty_case);
			
			var qty_bottle = $("#qty_bottle"+c).val();	
			qty_bottle = parseFloat(qty_bottle);
			
			var price_case = $("#price_case"+c).val();	
			price_case = parseFloat(price_case);
			var price_bottle = $("#price_bottle"+c).val();	
			price_bottle = parseFloat(price_bottle);
			qty_case_val = 1;
			price_case_val = 1;
			qty_bottle_val = 1;
			price_bottle_val = 1;
			if(qty_case<1)
			{			
				qty_case_val = 0;
							
			}
			if(price_case<1)
			{			
				price_case_val = 0;
							
			}
			if(qty_bottle<1)
			{			
				qty_bottle_val = 0;
						
			}
			if(price_bottle<1)
			{			
				price_bottle_val = 0;
							
			}
			
			if(qty_case_val<1 && qty_bottle_val<1)
			{
				if(qty_case_val==0)
				{
					erroralert = 1;
					errorvalmsg ='Please enter case qty greater then 0';	
				}
				else if(qty_bottle_val==0)
				{
					erroralert = 2;
					errorvalmsg ='Please enter bottle qty greater then 0';		
				}
				break;
			}
			else if(price_case_val<1 && price_bottle_val<1)
			{

				if(qty_case_val==1)
				{
					erroralert = 3;
					errorvalmsg ='Please enter case price greater then 0';	

				}
				else if(qty_bottle_val==1)
				{
					erroralert = 4;
					errorvalmsg ='Please enter bottle price greater then 0';	
				}
				
				break;
			}
			
		}
		
		if(erroralert==0)
		{
			vatamount 	= $("#vatamount").val();
			vatamount = parseInt(vatamount);
			
			tscamount 	= $("#tscamount").val();
			tscamount = parseInt(tscamount);

			discount 	= $("#discount").val();
			discount = parseInt(discount);

			nettopay 	= $("#productttotalamount").val();
			nettopay = parseInt(nettopay);
			if(vatamount>nettopay)
			{
				erroralert = 5;	
				errorvalmsg = " Please enter Vat Amount less then net price!";
			}
			else if(tscamount>nettopay)
			{
				erroralert = 6;		
				errorvalmsg = " Please enter TSC Amount less then net price!";
			}
			else if(discount>nettopay)
			{
				erroralert = 7;
				errorvalmsg = " Please enter discount less then net price!";
				
			}
		}
		//alert(erroralert);
		//alert(errorvalmsg);
		if(erroralert>0)
		{
			$("#frmerrormsg").html(errorvalmsg);
			$("#frmerrormsg").css('color', 'red');
			$("#frmerrormsg").css('border-color', 'red');
			setTimeout(function(){
			$("#frmerrormsg").html('');
			$("#frmerrormsg").css('color', '');
			$("#frmerrormsg").css('border-color', '');
			},4000);
			alert(errorvalmsg);		
			return false;
		}
	

}
</script>	
