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

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



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


$statement = $pdo->prepare("SELECT * FROM `tbl_product_variants` WHERE 1=1 and status=1 $condition");
    $statement->execute();
    $emp_data = $statement->fetchAll(PDO::FETCH_ASSOC);
    $totalData = $statement->rowCount();
    
    if($totalData>0){
        
?>

<div class="row porow" style="background: aquamarine; border-radius: 10px; padding: 10px 0px 10px 0px; 
    margin: 5px 0px 5px 0px; box-shadow: rgba(0, 0, 0, 0.02) 0px 1px 3px 0px, rgba(27, 31, 35, 0.15) 0px 0px 0px 1px; margin-top: 10px;">
                                        
                                    
                                        <input name="product_id[]" class="product_ids" value="<?=$emp_data[0]['id']?>" hidden>
                                        
                                        
                                        <div class="col-lg-3">
                                            <div class="form-group">
                                                <label for="product_name">Product Name <span style="color: red">*</span></label> 
                                                <input type="text" name="product_name[]" class="form-control" value="<?=$emp_data[0]['product_name']?>" id="product_name" placeholder="Product Name" required>
                                            </div>
                                        </div>
                                        
                                        <div class="col-lg-3">
                                            <div class="form-group" style="">
                                                <label for="category_name">Category</label> 
                                                <select name="category_name[]" id="category_name" class="form-control select22">
                                                    <option value="">Select Category</option>
                                                    <?php $statement = $pdo->prepare("SELECT * FROM `tbl_category` WHERE status=1");
                                                        $statement->execute();
                                                        $resultss = $statement->fetchAll(PDO::FETCH_ASSOC); 
                                                        foreach ($resultss as $ress) { ?>
                                                            <option value="<?=$ress['id']?>"><?=$ress['name']?></option>
                                                    <?php } ?>
                                                </select>
                                            </div>
                                        </div>
                                        
                    
                                        
                                        <div class="col-lg-3">
                                            <div class="form-group" style="">
                                                <label for="product_type">Product Type <span style="color: red">*</span></label>
                                                <select name="product_type[]" id="product_type" class="form-control select22">
                                                    <option value="1">Plain</option>
                                                    <option value="2">Stone</option>
                                                </select>
                                            </div>
                                        </div>
                                        
                                        <div class="col-lg-3">
                                            <div class="form-group" style="">
                                                <label for="unit">Unit <span style="color: red">*</span></label> 
                                                <select name="unit[]" id="unit" class="form-control select22" required>
                                                    <option value="">Select Units</option>
                                                    <?php $statement = $pdo->prepare("SELECT * FROM `tbl_units` WHERE status=1");
                                                        $statement->execute();
                                                        $resultss = $statement->fetchAll(PDO::FETCH_ASSOC); 
                                                        foreach ($resultss as $ress) { ?>
                                                            <option value="<?=$ress['id']?>"><?=$ress['name']?> (<?=$ress['short_name']?>)</option>
                                                    <?php } ?>
                                                </select>
                                            </div>
                                        </div>
                                        
                         
                                        <div class="col-lg-2">
                                            <div class="form-group">
                                                <label for="cross_weight">Cross Weight <span style="color: red">*</span></label>
                                                <input type="text" name="cross_weight[]" class="form-control" id="cross_weight" placeholder="Cross Weight">
                                            </div>
                                        </div>
                                        
                                        
                                        <div class="col-lg-2">
                                            <div class="form-group">
                                                <label for="stone_weight">Stone Weight <span style="color: red">*</span></label>
                                                <input type="text" name="stone_weight[]" class="form-control" id="stone_weight" placeholder="Stone Weight">
                                            </div>
                                        </div>
                                        
                                        
                                        <div class="col-lg-2">
                                            <div class="form-group">
                                                <label for="net_weight">Net Weight <span style="color: red;">*</span></label>
                                                <input type="text" name="net_weight[]" class="form-control" id="net_weight" placeholder="Net Weight">
                                            </div>
                                        </div>
                                        
                                        
                                        <div class="col-lg-2">
                                            <div class="form-group">
                                                <label for="stone_cost">Stone Cost <span style="color: red">*</span></label>
                                                <input type="text" name="stone_cost[]" class="form-control" id="stone_cost" placeholder="Stone Cost">
                                            </div>
                                        </div>
                                        
                                        
                                        
                                        
                                        
                                        
                                  
                                        
                                        <div class="col-lg-2">
                                            <div class="form-group">
                                                <label for="purity">Purity <span style="color: red">*</span></label> 
                                                <select name="purity[]" id="purity" class="form-control select22" required>
                                                    <option value="">Select Purity</option>
                                                    <?php $statement = $pdo->prepare("SELECT * FROM `tbl_ids_purity` WHERE status=1");
                                                        $statement->execute();
                                                        $resultss = $statement->fetchAll(PDO::FETCH_ASSOC); 
                                                        foreach ($resultss as $ress) { ?>
                                                            <option value="<?=$ress['value']?>"><?=$ress['name']?></option>
                                                    <?php } ?>
                                                </select>
                                            </div>
                                        </div>
                                        
                                        
                                        <div class="col-lg-1">
                                            <span class="btn btn-danger btn-sm remove_product" style="margin-top: 28px;"><i class="bi bi-trash3-fill"></i></span>
                                        </div>
                                        
                                        
                                        
                                    </div>
        
     
<?php } ?>


<script>
    $(document).on('click', '.remove_product', function() {
        $(this).closest('.porow').remove();
        grand_total();
    });
    
    
    $("body").on("keyup",".po_price",function(){
          var po_price=Number($(this).val());
          var po_qty=Number($(this).closest("tr").find(".po_qty").val());
          $(this).closest("tr").find(".total").val(po_price*po_qty);
          grand_total();
        });
        
        $("body").on("keyup",".po_qty",function(){
          var po_qty=Number($(this).val());
          var po_price=Number($(this).closest("tr").find(".po_price").val());
          $(this).closest("tr").find(".total").val(po_price*po_qty);
          grand_total();
        });      

</script>