<?php
include "../actions/dbPDO.php";
if(isset($_POST["mat_in_id"]))
{
	$idd = $_POST["mat_in_id"] ;
	$output = "";
	$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 mat_in_id = ?  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())
	{
		$net  = 0 ;
		$qty  = $row['qty'];
		$outt = $row['outt'] ;
		if(empty($outt)){$net = $qty ;}else{$net = $qty - $outt ; }
		 $output .= '	<tr>
							<td contenteditable ="true" class="out_qty">0</td>
							<td >' . $row['item_name'] . '</td>
							<td class="text-center">' . $net. '</td>
							<td >' . $row['kind'] . '</td>
							<td contenteditable ="true" class="text-center technician"></td>
							<td class="text-center out_unit_price">' . $row['unit_price'] . '</td>
							<td class="text-center">' . $row['mat_invoice_date'] . '</td>
							<td class="d-none out_line_id" >' . $row['line_id'] . '</td>
							<td class="d-none out_item_id" >' . $row['item_id'] . '</td>
							</tr>';
			}
	}
	else
	{
	$output .= '<tr><td colspan="7">لا يوجد سجلات ...</td></tr>';
	}
	echo $output;
}

?>
