<?php session_start();
require_once __DIR__."/allfunctions.php";


	$con = mysqli_connect(get_dbserver(),get_dbuser(),get_dbpassword(),get_dbname());




	if(isset($_SESSION["proditemarrayinventory"]))
	{
	    $itemarrayprod = $_SESSION["proditemarrayinventory"];
		$itemarrayquantity = $_SESSION["proditemqty"];
	}
	else
	{
	 $itemarrayprod = array();
	 $itemarrayquantity = array();
	}


				$itemid=$_GET["inv"];
				$itemqty=$_GET["itemqty"];

				$checkifdoble=1;
				for($a=0;$a<count($itemarrayprod);$a++)
				{
					if($itemarrayprod[$a]==$itemid && $itemarrayprod[$a]!=0)
					{
						//$itemarrayquantity += $itemqty;
						$itemarrayquantity[$a]=($itemarrayquantity[$a]*1)+($itemqty*1);
						$checkifdoble=2;
					}
				}

				if($checkifdoble==1)
				{
					if($itemid!="")
					{

						array_push($itemarrayprod,$itemid);
						array_push($itemarrayquantity,$itemqty);


					}
				}
				else if($checkifdoble==2)
				{
					if($itemid!="")
					{




					}
				}





																	$_SESSION["proditemarrayinventory"]=$itemarrayprod;
																	$_SESSION["proditemqty"]=$itemarrayquantity;

?>

															<table class="table table-bordered jomaterialtable" id="datatable" width="100%" cellspacing="0">
																		<thead>
																			<th>ID</th>
																			<th>Product Name</th>
																			<th>Quantity</th>
																			<th></th>
																		</thead>
																	<tbody>
																	<?php

																	foreach ($itemarrayprod as $key=>$value)
																	{
																		$MaterialListDetails = MaterialListDetails($itemarrayprod[$key]);


																		if($MaterialListDetails["id"]!="")
																		{
																			//echo $_SESSION["joborderitemqty"];
																			echo '<tr>';
																			echo '<td>' . $itemarrayprod[$key] . '</td>';
																			echo '<td>' . strtoupper($MaterialListDetails["name"]) . '</td>';
																			echo '<td>' . $itemarrayquantity[$key] . '</td>';
																			echo '<td> <a href="#"  class="btn btn-sm btn-primary shadow-sm" onclick="deleteMaterialprod('. $key . ');
																			return false"><i class="far fa-trash-alt"></i></a></td>';
																			echo '</tr>';


																		}
																	}

																	?>

																	</tbody>



																</table>
