<?php
include "../actions/dbPDO.php";
if(isset($_POST["brand"]))
{
	$idd = $_POST["brand"] ;
	$output = "";
	if($idd == "all"){
		$sql = $db->prepare("SELECT item_name ,qty , outt , unit_price , mat_name , store_name ,mat_invoice_date ,
			 line_id , item_id , kind
			  FROM `supp_mat_v` WHERE  qty > outt OR outt IS NULL order by mat_invoice_date ");
	}else{
		$brand = "%".$idd."%" ;
		$sql = $db->prepare("SELECT item_name ,qty , outt , unit_price , mat_name , store_name ,mat_invoice_date ,
			 line_id , item_id , kind
			  FROM `supp_mat_v` WHERE kind in('جميع السيارات' , ?)  AND (qty > outt OR outt IS NULL) order by mat_invoice_date ");
		$sql->bindParam(1,$idd);
	}
	$sql->execute();
	if($sql->rowCount()>0){
	while($row = $sql->fetch())
	{
		$nett =  $row['qty'] -  $row['outt'] ;
		 $output .= '
					<tr>
							<td contenteditable="true" class="s_qty">0</td>
							<td class="text-center">' . $row['item_name'] . '</td>
							<td class="text-center">' . $nett . '</td>
							<td class="text-center">' . $row['kind'] . '</td>
							<td contenteditable="true" class="text-center s_technician "></td>
							<td class="text-center s_unit_price">' . $row['unit_price'] . '</td>
							<td class="text-center">' . $row['mat_name'] . '</td>
							<td class="text-center">' . $row['mat_invoice_date'] . '</td>
							<td class="d-none s_line_id" >' . $row['line_id'] . '</td>
							<td class="d-none s_item_id" >' . $row['item_id'] . '</td>
							</tr>';	}}
	else
	{
	$output .= '<tr><td colspan="8">لا يوجد سجلات ...</td></tr>';
	}
	echo $output;
}

?>
