<?php 
ob_start();
session_start();
include "../config/config.php";

$condition='';
$get_pro_id = $_POST['pro_id'];



if($get_pro_id!=""){
	$condition.=" and tbl_product_variants.id=".$get_pro_id;
}


$statement = $pdo->prepare("SELECT tbl_product_variants.*,tbl_units.name as unit_name, tbl_units.short_name,
tbl_wastage.percentage
FROM `tbl_product_variants` 
LEFT JOIN tbl_units ON tbl_units.id=tbl_product_variants.unit
LEFT JOIN tbl_wastage ON tbl_wastage.id=tbl_product_variants.wastage
WHERE 1=1 and tbl_product_variants.status=1 $condition");
    $statement->execute();
    $emp_data = $statement->fetchAll(PDO::FETCH_ASSOC);
    $totalData = $statement->rowCount();
    
    if($totalData>0){
    
    
    // Rate Calculation Starts Here
    $statement_price = $pdo->prepare("SELECT * FROM `tbl_prices` WHERE product_id=? and purity_id=?");
    $statement_price->execute(array($emp_data[0]['pro_ids'], $emp_data[0]['purity']));
    $price_data = $statement_price->fetchAll(PDO::FETCH_ASSOC);
    $price_totalData = $statement_price->rowCount(); 
        
    $price_amount = $price_data[0]['amount'];
    // Rate Calculation Endss Here
    
    
    
    $stone_weight = $emp_data[0]['stone_weight'];
    $stone_cost = $emp_data[0]['stone_cost'];
    $net_weight = $emp_data[0]['net_weight'];
    
    if($emp_data[0]['unit']==1){
        $stone_amount = $stone_weight*$stone_cost;
        $product_amount = $net_weight*$price_amount;
    }else if($emp_data[0]['unit']==2){
        $stone_amount = $stone_weight*$stone_cost;
        $product_amount = $net_weight*$price_amount;
    } 
    
    
        
?>


<tr class="porow">
    
    
    
    
    
    
    <td>
        <input name="product_id[]" class="product_ids" value="<?=$emp_data[0]['id']?>" hidden>
        <input name="product_name[]" value="<?=$emp_data[0]['product_name']?>" hidden>
        <input name="weight_details[]" value="<?=$emp_data[0]['cross_weight']?>-<?=$emp_data[0]['stone_weight']?>-<?=$emp_data[0]['net_weight']?>" hidden>
        <input name="stone_cost[]" value="<?=$stone_cost?>" hidden>
    
    
        <b><?=$emp_data[0]['product_name']?></b></td>
    <td>
        <input name="hsn_code[]" value="<?=$emp_data[0]['hsn_code']?>" hidden>
        <b><?=$emp_data[0]['hsn_code']?></b>
    </td>
    <td><b><?=$emp_data[0]['unit_name']?> (<?=$emp_data[0]['short_name']?>)</b></td>
    <td><input type="text" name="lable_quantity[]" class="form-control" value="1"  placeholder="Qty" required></td>
    <td>
        <b><?=$emp_data[0]['cross_weight']?> - <?=$emp_data[0]['stone_weight']?> - <?=$emp_data[0]['net_weight']?></b>
    </td>
    <td>
        
        <b><span id="price_<?=$emp_data[0]['id']?>"><?=$stone_cost?></span></b>
    </td>
    <td>
        <b><span id="price_total_<?=$emp_data[0]['id']?>"><?=$emp_data[0]['percentage']?> %</span></b>
    </td>
    <td><span class="btn btn-danger btn-sm remove_product" style=""><i class="bi bi-trash3-fill"></i></span></td>
</tr>

<?php } ?>

