<?php

	include 'Header.php';
    include 'Navbar.php';
	include 'Sidebar.php';
	include 'includes/admin_API_Config.php';

	$obj = new API_Config;
	$data = array();
	$data['admin_username'] = $_SESSION['admin_username'];
	$response = json_decode($obj->call_API("API_Product_List.php", $data));
	$storeList  = json_decode($obj->call_API("API_Store_List.php", $data));
	//var_dump($response);
	error_reporting(0);

?>




<!-- BEGIN CONTENT -->
	<div class="page-content-wrapper">
		<div class="page-content">
			<!-- BEGIN SAMPLE PORTLET CONFIGURATION MODAL FORM-->
			<div class="modal fade" id="portlet-config" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-dialog">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
							<h4 class="modal-title">Modal title</h4>
						</div>
						<div class="modal-body">
							 Widget settings form goes here
						</div>
						<div class="modal-footer">
							<button type="button" class="btn blue">Save changes</button>
							<button type="button" class="btn default" data-dismiss="modal">Close</button>
						</div>
					</div>
					<!-- /.modal-content -->
				</div>
				<!-- /.modal-dialog -->
			</div>
			<!-- /.modal -->
			<!-- END SAMPLE PORTLET CONFIGURATION MODAL FORM-->
			<!-- BEGIN PAGE HEADER-->
			<!-- BEGIN PAGE BREADCRUMB -->
			<ul class="page-breadcrumb breadcrumb">
				<li>
					<a href="#">Dashboard</a>
					<i class="fa fa-circle"></i>
				</li>
				<li>
					<a href="#">Purchase</a>
					<i class="fa fa-circle"></i>
				</li>
				<li>
					<a href="#">Add Purchase</a>
				</li>
			</ul>
			<!-- END PAGE BREADCRUMB -->
			<!-- END PAGE HEADER-->
			<!-- BEGIN PAGE CONTENT-->


			<!-- BEGIN SAMPLE FORM PORTLET-->
					<div class="portlet box blue">
						<div class="portlet-title">
							<div class="caption">
								<i class="icon-settings"></i>
								<span class="caption-subject bold uppercase">Purchase</span>
							</div>
						</div>
						
						<div class="portlet-body form">
							<form action="#" method="POST" action="#" class="horizontal-form" name="frmPurchase" id="frmPurchase">
												<div class="form-body">
													<div class="row">
														<div class="col-md-3">
															<div class="form-group form-md-line-input form-md-label">
                                                                <input type="text" class="form-control" name="memberID" id="memberID" maxlength="9">
                                                                <label for="MemberID">Member ID:</label>
                                                                <span class="help-block"></span>
										                        </div>
										
														</div>
														<!--/span-->
														<div class="col-md-3">
															<div class="form-group form-md-line-input form-md-label">
																<input type="text" class="form-control" name="memberName" id="memberName">
																<label for="memberName">Member Name:</label>
																<span class="help-block"></span>
															</div>
														</div>
														<div class="col-md-3">
															<div class="form-group form-md-line-input form-md-label">
                                                                <input type="text" class="form-control" name="customerID" id="customerID">
                                                                <label for="customerID">Customer ID:</label>
                                                                <span class="help-block"></span>
										                    </div>
														</div>
														<!--/span-->
													
													</div>
													<!--/row-->
													
													<!--/row-->
													<p>&nbsp;</p>
													<div class="row" id="storeRow">
														<div class="col-md-4">
															<div class="form-group form-md-line-input form-md has-info">
																<select class="form-control input-large" id="store">
																	<?php
																		foreach($storeList->eCommerceStores as $row)
																		{
																			echo "<option value='" . $row->id . "' price='" . $row->price . "'  pv='" . $row->pricevalue . "'>" . ucwords($row->name) . "</option>";
																		}
																	?>
																</select>
																<label for="store">Select Store:</label>
															</div>
														</div>
														<div class="col-md-4">
															<div class="form-group form-md-line-input form-md-label">
																<textarea class="form-control valid" rows="3" name="address" id="address" aria-invalid="false"></textarea>
																<label for="address">Customer Address:</label>
                                                                <span class="help-block"></span>
															</div>															
														</div>
														<div class="col-md-3">
															<div class="form-group form-md-line-input form-md-label">
                                                                <input type="text" class="form-control" name="pincode" id="pincode" maxlength="6" value="">
                                                                <label for="pincode">Pincode:</label>
                                                                <span class="help-block"></span>
										                    </div>
														</div>
													</div>

													<div class="row">
													   <div class="col-md-6">
															<div class="form-group form-md-line-input form-md-label">
																<textarea class="form-control valid" rows="3" name="otherInfo" id="otherInfo" aria-invalid="false"></textarea>
																<label for="otherInfo">Any Other Info:</label>
                                                                <span class="help-block"></span>
															</div>
														</div>
                                                        <input type="text" class="form-control" name="productIDValue" id="productIDValue" />
														<div class="col-md-6" id="productIDRow">
														</div>
													</div>
												</div>
									
									
									 <div class="table-responsive">
                                        <table class="table table-bordered">
                                            <tbody>
												<tr style="background:#ECF0F5;">
													<th style="width:40%; text-align:center;border:1px solid #E1E1E1;">PRODUCT</th>
													<th style="width:10%; text-align:center;border:1px solid #E1E1E1;">QTY</th>
													<th style="width:10%; text-align:center;border:1px solid #E1E1E1;">PV</th>
													<th style="width:10%; text-align:center;border:1px solid #E1E1E1;">Total PV</th>
													<th style="width:10%; text-align:center;border:1px solid #E1E1E1;">RATE</th>
													<th style="width:10%; text-align:center;border:1px solid #E1E1E1;">TOTAL</th>
													<th style="width:5%;border:1px solid #E1E1E1;"></th>
												</tr>
												<tr>
													<td style="text-align:center; width:20%; " class="responsive_col">
														<select class="form-control select2 select2-hidden-accessible" name="productList" id="productList" data-rel="chosen" tabindex="-1" aria-hidden="true">
															<option value="0.0" pv="0.0"> Select Product</option>
															<?php
																foreach($response->productList as $row)
																{
																	echo "<option value='" . $row->id . "' price='" . $row->price . "'  pv='" . $row->pricevalue . "'>" . ucwords($row->name) . "</option>";
																}
															?>                                                            
														  </select>
													</td>
													<td class="responsive_col"> 
														<center>
															<input type="text" class="form-control" name="qty" id="qty" style="width:100%;" value="0" maxlength="2"/>
														</center>
													</td>
													<td class="responsive_col">
														<center>
															<input type="text" class="form-control" name="pv" id="pv" style="width:100%;" value="0.0" />
														</center>
													</td>
													<td class="responsive_col">
														<center>
															<input type="text" class="form-control" name="totalPV" id="totalPV" style="width:100%;" value="0.0" />
														</center>
													</td>
													<td class="responsive_col">
														<center>
															<input type="text" class="form-control" name="rate" id="rate" style="width:100%;" value="0.0" />
														</center>
													</td>
													<td class="responsive_col">
														<center>
															<input type="text" class="form-control" name="total" id="total" style="width:100%;" value="0.0" readonly="readonly">
														</center>
													</td>
													<td class="responsive_col">
														<center>
															<button type="button" class="btn btn-block btn-default btn-flat" name="addProduct" id="addProduct" style="background:#0080C0; color:#fff;">ADD</button>
														</center>
													</td>
												</tr>
										    </tbody>
										</table>
									</div>

                                    <div class="table-responsive">
                                    <table class="table table-bordered"> 
									   <tbody name='products' id='products'>
											<tr style="background:#ECF0F5;width:100%">
												 <th style="width:5%;text-align:center;border:1px solid #E1E1E1;">SR.NO</th>
												 <th style="width:40%; text-align:center;border:1px solid #E1E1E1;">PRODUCT</th>
												 <th style="width:5%; text-align:center;border:1px solid #E1E1E1;">QTY</th>
												 <th style="width:10%; text-align:center;border:1px solid #E1E1E1;">Total PV</th>
 												 <th style="width:10%; text-align:center;border:1px solid #E1E1E1;">Total PV</th>
												 <th style="width:10%; text-align:center;border:1px solid #E1E1E1;">RATE</th>
												 <th style="width:10%; text-align:center;border:1px solid #E1E1E1;">TOTAL</th>
												 <th style="width:5%; text-align:center;border:1px solid #E1E1E1;">ACTIONS</th>
											</tr>
										</tbody>
									</table>
									<button type="submit" class="btn btn-default btn-flat col-md-offset-10 col-md-2" name="btnPurchase" id="btnPurchase" style="background:#0080C0; color:#fff;">SUBMIT</button>
                                  </div>
								  </form>
                                      
						</div>
					</div>
					<!-- END SAMPLE FORM PORTLET-->
					
				</div>
			</div>


<?php

	include 'footer.php';
?>



<script type="text/javascript">

	var productList = 0;
	var arrayElement = new Array();
	var request = 0;

	$("#productList").change(function(){

		var quantity       = 1;
		var productIDValue = parseFloat($(this).find('option:selected').attr('value'));
		var rate           = parseFloat($(this).find('option:selected').attr('price'));
		var pv             = parseFloat($("#productList").find('option:selected').attr('pv'));
		var totalPV        = quantity * pv;
		var total          = quantity * rate;

		$("#productIDValue").val(productIDValue);
		$("#qty").val(quantity);
		$("#rate").val(rate);
		$("#total").val(total);
		$("#pv").val(pv);
		$("#totalPV").val(totalPV);

	
	});


   $("#qty").on("keypress keyup blur paste change",function (event){

		$(this).val($(this).val().replace(/[^\d].+/, ""));
        if ((event.which < 48 || event.which > 57)) {
                event.preventDefault();
        }
		  
		if($("#qty").val() == '')
			$("#qty").val(1);

		var quantity = parseInt($("#qty").val());
		var rate     = parseFloat($("#productList").find('option:selected').attr('price'));
		var pv       = parseFloat($("#productList").find('option:selected').attr('pv'));

		var total    = parseFloat(quantity * rate);
		var totalPV  = parseFloat(quantity * pv);
		$("#rate").val(rate);
		$("#total").val(total);
		$("#pv").val(parseFloat(pv));
		$("#totalPV").val(parseFloat(totalPV));
		


	});

	

	
	$("#addProduct").click(function(){

		var selectedIndex = $("#productList option:selected").index();
		//alert("hi");

		
		if (selectedIndex == 0)
		{
			return false;
		}
		
		
		else
		{
			if(productList==0)
			{

				var productID    = parseInt($("#productIDValue").val());
				var quantity	 = parseInt($("#qty").val());
				var rate		 = parseFloat($("#rate").val());
				var total		 = parseFloat($("#total").val());
				var pv           = parseFloat($("#pv").val());
				var totalPV      = parseFloat($("#totalPV").val());
				var productName  = $("#productList").find('option:selected').text();
				addRow(productList, productID, productName,  quantity, pv, totalPV, rate, total);
				productList++;
			}

			else
			{
				for(i=0; i<arrayElement.length; i++)
				{
					if(arrayElement[i][1] == parseInt($("#productIDValue").val()))
					{
						var quantity	 = parseInt($("#qty").val());
						var rate		 = parseFloat($("#rate").val());
						var pv           = parseFloat($("#pv").val());
						arrayElement[i][3] += quantity;
						arrayElement[i][5] *= arrayElement[i][3];
						arrayElement[i][7] *= arrayElement[i][3];
						updateRow();
						alert("hi");

					}

					else
					{
						if(i==arrayElement.length-1)
						{
							var productID    = parseInt($("#productIDValue").val());
							var quantity	 = parseInt($("#qty").val());
							var rate		 = parseFloat($("#rate").val());
							var total		 = parseFloat($("#total").val());
							var pv           = parseFloat($("#pv").val());
							var totalPV      = parseFloat($("#totalPV").val());
							var productName  = $("#productList").find('option:selected').text();
							addRow(productList, productID, productName,  quantity, pv, totalPV, rate, total);
							productList++;
						}

					}
				
				}
				

			}

		}
	});



 	$("#rate").on("keypress keyup blur paste change",function (event) {

	   $(this).val($(this).val().replace(/[^\d].+/, ""));
            if ((event.which < 48 || event.which > 57)) {
                event.preventDefault();
        }

		var rate  = parseFloat($("#rate").val());
		var qty   = parseInt($("#qty").val());
		var total = rate * qty;
        $("#total").val(total);
		
	});


	$("#memberID").on("keypress keyup blur paste change",function (event) {

	   
           $(this).val($(this).val().replace(/[^\d].+/, ""));
            if ((event.which < 48 || event.which > 57)) {
                event.preventDefault();
            }
			else
			{
				if($("#memberID").val().length==9)
				{
					 request++;
					 if(request>1)
						 return false;

					  $.post("../API/API_check_refer_idV3.php",
					  {
						refer_id: $("#memberID").val(),
						//ajax : 1,

					  },

					  function(data, status){
						if(status)
						{
						  request = 0;
						  if(data.status==1)
						  {
							 $("#memberName").val(data.user_info.name + "  " + data.user_info.last_name);
							 $("#customerID").val(data.user_info.customer_id);
							 var address = data.user_info.address1 + ", " + data.user_info.address2 + ", " + data.user_info.city + " - " + " "  + data.user_info.state + "."; 
							 $("#address").text(address);
							 $("#pincode").val(data.user_info.zip_code);

						  }
						  else
						  {
							 $("#memberName").val("Invalid Member ID!");
 							 $("#memberName").val("Invalid Member ID!");
						  }

						}

						else
						  {
							alert("Cannot get a response from the server. Please try later!");
							$('#finish').attr('disabled', true);

						  }
						
						});
				   }

				
			  }
    });


	function addRow(countSerialNo, productID, productName, quantity, pv, totalPV, rate, total)
	{
			var totalItems   = 0;
			var totalOrderPV = 0;
			var totalRate    = 0;
			var grandTotal   = 0;
		    var tableRow = "<tr style='background:#ECF0F5;'><th style='width:5%;text-align:center;border:1px solid #E1E1E1;'>SR.NO</th><th style='width:40%; text-align:center;border:1px solid #E1E1E1;'>Product</th><th style='width:5%; text-align:center;border:1px solid #E1E1E1;'>QTY</th><th style='width:10%; text-align:center;border:1px solid #E1E1E1;'>PV</th><th style='width:10%; text-align:center;border:1px solid #E1E1E1;'>Total PV</th><th style='width:10%; text-align:center;border:1px solid #E1E1E1;'>RATE</th><th style='width:10%;text-align:center;border:1px solid #E1E1E1;'>TOTAL</th><th style='width:5%; text-align:center;border:1px solid #E1E1E1;'>ACTIONS</th</tr>";
    		
			window.arrayElement[countSerialNo] = [countSerialNo, productID, productName, quantity, pv, totalPV, rate, total];

			var productIDRow += "<input type='text' name='pv[]' value='" + (window.arrayElement[i][4])  + "' readonly style='width:100%;border: transparent;text-align:center;'/>";

			for(i=0; i<window.arrayElement.length; i++)
			{
				tableRow += "<tr><td style='width:5%;text-align:center;'><input type='text' name='srNo[]' value='" + (i+1)  + "' readonly style='width:100%;border: transparent;text-align:center;'/></td>";
				productIDRow += "<input type='text' name='productID[]' value='" + (window.arrayElement[i][1])  + "' readonly style='width:100%;border: transparent;text-align:center;'/>";		
				tableRow += "<td style='width:40%;'><input type='textarea' name='productName[]' value='" + (window.arrayElement[i][2])  + "' readonly style='width:100%;border: transparent;'/></td>";
				tableRow += "<td style='width:5%;text-align:center;'><input type='text' name='productQTY[]' value='" + (window.arrayElement[i][3])  + "' readonly style='width:100%;border: transparent;text-align:center;'/></td>";
				tableRow += "<td style='width:10%;text-align:center;'><input type='text' name='pv[]' value='" + (window.arrayElement[i][4])  + "' readonly style='width:100%;border: transparent;text-align:center;'/></td>";
				tableRow += "<td style='width:10%;text-align:center;'><input type='text' name='totalPV[]' value='" + (window.arrayElement[i][5])  + "' readonly style='width:100%;border: transparent;text-align:center;'/></td>";
				tableRow += "<td style='width:10%;text-align:center;'><input type='text' name='productRate[]' value='" + (window.arrayElement[i][6])  + "' readonly style='width:100%;border: transparent;text-align:center;'/></td>";
				tableRow += "<td style='width:10%;text-align:center;'><input type='text' name='productTotal[]' value='" + (window.arrayElement[i][7])  + "' readonly style='width:100%;border: transparent;text-align:center;'/></td>";
				tableRow += "<td style='width:5%;text-align:center;'><a href='javascript:removeItem(" +  window.arrayElement[i][0]  + ")' class='btn default btn-sm'><span class='md-click-circle md-click-animate'></span><i class='fa fa-times'></i> Remove </a></td></tr>";
				totalItems	  += parseFloat(window.arrayElement[i][3]);
				totalOrderPV  += parseFloat(window.arrayElement[i][5]);			
			    grandTotal	  += parseFloat(window.arrayElement[i][7]);

			}

			tableRow += "<tr><td style='width:5%;text-align:center;>'></td>";
			tableRow += "<td style='width:40%;'><strong>TOTAL ITEMS</strong></td>";
			tableRow += "<td style='width:5%;text-align:center;>'><input type='text' name='totalItems' value='" + totalItems  + "' readonly style='width:100%;border: transparent;text-align:center;'/></td>";
			tableRow += "<td style='width:5%;'></td>";
			tableRow += "<td style='width:15%;text-align:center;>'><input type='text' name='grandTotal' value='" + totalOrderPV  + "' readonly style='border: transparent;text-align:center;'/></td>";
			tableRow += "<td style='width:15%;text-align:center;>'><strong></strong></td>";
			tableRow += "<td style='width:15%;text-align:center;>'><input type='text' name='grandTotal' value='" + grandTotal  + "' readonly style='border: transparent;text-align:center;'/></td>";
			tableRow += "<td style='width:5%;text-align:center;>'><strong></strong></td></tr>";

			$("#products").html(tableRow);
			$("#productList").prop('selectedIndex', 0);
			$("#productID").val('');
			$("#qty").val(0);
			$("#pv").val(0.0);
			$("#totalPV").val(0.0);
			$("#rate").val(0.0);
			$("#total").val(0.0);


	}



	function updateRow()
	{
			var totalItems   = 0;
			var totalOrderPV = 0;
			var totalRate    = 0;
			var grandTotal   = 0;
		    var tableRow = "<tr style='background:#ECF0F5;'><th style='width:5%;text-align:center;border:1px solid #E1E1E1;'>SR.NO</th><th style='width:40%; text-align:center;border:1px solid #E1E1E1;'>Product</th><th style='width:5%; text-align:center;border:1px solid #E1E1E1;'>QTY</th><th style='width:10%; text-align:center;border:1px solid #E1E1E1;'>PV</th><th style='width:10%; text-align:center;border:1px solid #E1E1E1;'>Total PV</th><th style='width:10%; text-align:center;border:1px solid #E1E1E1;'>RATE</th><th style='width:10%;text-align:center;border:1px solid #E1E1E1;'>TOTAL</th><th style='width:5%; text-align:center;border:1px solid #E1E1E1;'>ACTIONS</th</tr>";

			for(i=0; i<window.arrayElement.length; i++)
			{

				tableRow += "<tr><td style='width:5%;text-align:center;'><input type='text' name='srNo[]' value='" + (i+1)  + "' readonly style='width:100%;border: transparent;text-align:center;'/></td>";
				tableRow += "<td style='width:40%;'><input type='textarea' name='productName[]' value='" + (window.arrayElement[i][2])  + "' readonly style='width:100%;border: transparent;'/></td>";
				tableRow += "<td style='width:5%;text-align:center;'><input type='text' name='productQTY[]' value='" + (window.arrayElement[i][3])  + "' readonly style='width:100%;border: transparent;text-align:center;'/></td>";
				tableRow += "<td style='width:10%;text-align:center;'><input type='text' name='pv[]' value='" + (window.arrayElement[i][4])  + "' readonly style='width:100%;border: transparent;text-align:center;'/></td>";
				tableRow += "<td style='width:10%;text-align:center;'><input type='text' name='totalPV[]' value='" + (window.arrayElement[i][5])  + "' readonly style='width:100%;border: transparent;text-align:center;'/></td>";
				tableRow += "<td style='width:10%;text-align:center;'><input type='text' name='productRate[]' value='" + (window.arrayElement[i][6])  + "' readonly style='width:100%;border: transparent;text-align:center;'/></td>";
				tableRow += "<td style='width:10%;text-align:center;'><input type='text' name='productTotal[]' value='" + (window.arrayElement[i][7])  + "' readonly style='width:100%;border: transparent;text-align:center;'/></td>";
				tableRow += "<td style='width:5%;text-align:center;'><a href='javascript:removeItem(" +  window.arrayElement[i][0]  + ")' class='btn default btn-sm'><span class='md-click-circle md-click-animate'></span><i class='fa fa-times'></i> Remove </a></td></tr>";
				totalItems	  += parseFloat(window.arrayElement[i][3]);
				totalOrderPV  += parseFloat(window.arrayElement[i][5]);			
			    grandTotal	  += parseFloat(window.arrayElement[i][7]);

			}

			tableRow += "<tr><td style='width:5%;text-align:center;>'></td>";
			tableRow += "<td style='width:40%;'><strong>TOTAL ITEMS</strong></td>";
			tableRow += "<td style='width:5%;text-align:center;>'><input type='text' name='totalItems' value='" + totalItems  + "' readonly style='width:100%;border: transparent;text-align:center;'/></td>";
			tableRow += "<td style='width:5%;'></td>";
			tableRow += "<td style='width:15%;text-align:center;>'><input type='text' name='grandTotal' value='" + totalOrderPV  + "' readonly style='border: transparent;text-align:center;'/></td>";
			tableRow += "<td style='width:15%;text-align:center;>'><strong></strong></td>";
			tableRow += "<td style='width:15%;text-align:center;>'><input type='text' name='grandTotal' value='" + grandTotal  + "' readonly style='border: transparent;text-align:center;'/></td>";
			tableRow += "<td style='width:5%;text-align:center;>'><strong></strong></td></tr>";

			$("#products").html('');
			$("#products").html(tableRow);
			$("#productList").prop('selectedIndex', 0);
			$("#productID").val('');
			$("#qty").val(0);
			$("#pv").val(0.0);
			$("#totalPV").val(0.0);
			$("#rate").val(0.0);
			$("#total").val(0.0);


	}




	

	
	function removeItem(itemIndex)
	{
		window.arrayElement.splice(itemIndex, 1);
		//alert(window.arrayElement.length);
		window.productList -= 1;


		if(window.arrayElement.length == 0)
		{
			$("#products").html("<tr style='background:#ECF0F5;'><th style='width:5%;text-align:center;border:1px solid #E1E1E1;'>SR.NO</th><th style='width:40%; text-align:center;border:1px solid #E1E1E1;'>Product</th><th style='width:5%; text-align:center;border:1px solid #E1E1E1;'>QTY</th><th style='width:10%; text-align:center;border:1px solid #E1E1E1;'>PV</th><th style='width:10%; text-align:center;border:1px solid #E1E1E1;'>Total PV</th><th style='width:10%; text-align:center;border:1px solid #E1E1E1;'>RATE</th><th style='width:10%;text-align:center;border:1px solid #E1E1E1;'>TOTAL</th><th style='width:5%; text-align:center;border:1px solid #E1E1E1;'>ACTIONS</th</tr>");
		}

		else
		{
				var totalItems   = 0;
				var totalOrderPV = 0;
				var totalRate    = 0;
				var grandTotal   = 0;
				var tableRow = "<tr style='background:#ECF0F5;'><th style='width:5%;text-align:center;border:1px solid #E1E1E1;'>SR.NO</th><th style='width:40%; text-align:center;border:1px solid #E1E1E1;'>Product</th><th style='width:5%; text-align:center;border:1px solid #E1E1E1;'>QTY</th><th style='width:10%; text-align:center;border:1px solid #E1E1E1;'>PV</th><th style='width:10%; text-align:center;border:1px solid #E1E1E1;'>Total PV</th><th style='width:10%; text-align:center;border:1px solid #E1E1E1;'>RATE</th><th style='width:10%;text-align:center;border:1px solid #E1E1E1;'>TOTAL</th><th style='width:5%; text-align:center;border:1px solid #E1E1E1;'>ACTIONS</th</tr>";

				for(i=0; i<window.arrayElement.length; i++)
				{
					
					tableRow += "<tr><td style='width:5%;text-align:center;'><input type='text' name='srNo[]' value='" + (i+1)  + "' readonly style='width:100%;border: transparent;text-align:center;'/></td>";
					tableRow += "<td style='width:40%;'><input type='textarea' name='productName[]' value='" + (arrayElement[i][2])  + "' readonly style='width:100%;border: transparent;'/></td>";
					tableRow += "<td style='width:5%;text-align:center;'><input type='text' name='productQTY[]' value='" + (arrayElement[i][3])  + "' readonly style='width:100%;border: transparent;text-align:center;'/></td>";
					tableRow += "<td style='width:10%;text-align:center;'><input type='text' name='pv[]' value='" + (arrayElement[i][4])  + "' readonly style='width:100%;border: transparent;text-align:center;'/></td>";
					tableRow += "<td style='width:10%;text-align:center;'><input type='text' name='totalPV[]' value='" + (arrayElement[i][5])  + "' readonly style='width:100%;border: transparent;text-align:center;'/></td>";
					tableRow += "<td style='width:10%;text-align:center;'><input type='text' name='productRate[]' value='" + (arrayElement[i][6])  + "' readonly style='width:100%;border: transparent;text-align:center;'/></td>";
					tableRow += "<td style='width:10%;text-align:center;'><input type='text' name='productTotal[]' value='" + (arrayElement[i][7])  + "' readonly style='width:100%;border: transparent;text-align:center;'/></td>";
					tableRow += "<td style='width:5%;text-align:center;'><a href='javascript:removeItem(" +  i  + ")' class='btn default btn-sm'><span class='md-click-circle md-click-animate'></span><i class='fa fa-times'></i> Remove </a></td></tr>";
					totalItems	  += parseFloat(arrayElement[i][3]);
					totalOrderPV  += parseFloat(arrayElement[i][5]);			
					grandTotal	  += parseFloat(arrayElement[i][7]);

				}

				tableRow += "<tr><td style='width:5%;text-align:center;>'></td>";
				tableRow += "<td style='width:40%;'><strong>TOTAL ITEMS</strong></td>";
				tableRow += "<td style='width:5%;text-align:center;>'><input type='text' name='totalItems' value='" + totalItems  + "' readonly style='width:100%;border: transparent;text-align:center;'/></td>";
				tableRow += "<td style='width:5%;'></td>";
				tableRow += "<td style='width:15%;text-align:center;>'><input type='text' name='grandTotal' value='" + totalOrderPV  + "' readonly style='border: transparent;text-align:center;'/></td>";
				tableRow += "<td style='width:15%;text-align:center;>'><strong></strong></td>";
				tableRow += "<td style='width:15%;text-align:center;>'><input type='text' name='grandTotal' value='" + grandTotal  + "' readonly style='border: transparent;text-align:center;'/></td>";
				tableRow += "<td style='width:5%;text-align:center;>'><strong></strong></td></tr>";

				//$("#productArray").val(arrayElement.toString());
				$("#products").html(tableRow);
				$("#products").html(tableRow);
				$("#productList").prop('selectedIndex', 0);
				$("#productIDValue").val('');
				$("#qty").val(0);
				$("#pv").val(0.0);
				$("#totalPV").val(0.0);
				$("#rate").val(0.0);
				$("#total").val(0.0);

		}

		
				
	}


		

</script>
</body>
</html>