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

$count = $_POST['count'];
$product_ids = $_POST['product_ids'];
?>

<div class="row porow" style="background: aquamarine; border-radius: 10px; padding: 10px 0px 10px 0px; margin: 5px 0px 15px 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: 25px;">
                                        
                                        <input class="count" value="<?=$count?>" hidden>
                                        <input name="product_id[]" class="product_ids" value="0" hidden>
                                        <input name="purchase_order_items_id[]" class="" value="0" hidden>
                                        
                                        <div class="col-lg-2">
                                            <div class="form-group">
                                                <label for="product" class="required">Products</label> 
                                                <select name="product[]" id="product_<?=$count?>" onchange="productKarat(<?=$count?>)" class="form-control select22" required>
                                                    <?php $statement = $pdo->prepare("SELECT * FROM `tbl_ids_products` WHERE status=1 and id=?");
                                                        $statement->execute(array($product_ids));
                                                        $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">
                                                <label for="product_name" class="required">Product Name</label> 
                                                <select name="product_name[]" id="product_name_<?=$count?>" class="form-control select22" required>
                                                    <option value="">Select Product Name</option>
                                                    <?php $statement = $pdo->prepare("SELECT * FROM `tbl_products_name` WHERE status=1 and type=2 and product_ids=?");
                                                        $statement->execute(array($product_ids));
                                                        $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="category_name" class="required">Category</label> 
                                                <select name="category_name[]" id="category_name" class="form-control select22" required>
                                                    <option value="">Select Category</option>
                                                    <?php $statement = $pdo->prepare("SELECT * FROM `tbl_category` WHERE status=1 and product_ids=?");
                                                        $statement->execute(array($product_ids));
                                                        $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_<?=$count?>" onchange="productType(<?=$count?>)" class="form-control select22">
                                                    <option value="1">Plain</option>
                                                    <option value="2">Stone</option>
                                                </select>
                                            </div>
                                        </div>
                                        
                                        <div class="col-lg-3" hidden>
                                            <div class="form-group" style="">
                                                <label for="unit">Unit <span style="color: red">*</span></label> 
                                                <select name="unit[]" id="unit_<?=$count?>" class="form-control select22" onchange="UnitChange(<?=$count?>)" required data-count="<?=$count?>">
                                                    <?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 id="plain_section_<?=$count?>"></div>
                            
                                        <div id="stone_section_<?=$count?>"></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_<?=$count?>" class="form-control select22" onchange="purityChange(<?=$count?>)" required>
                                                    <option value="">Select Purity</option>
                                                    <?php $statement = $pdo->prepare("SELECT * FROM `tbl_ids_purity` WHERE status=1 and product_ids=?");
                                                        $statement->execute(array($product_ids));
                                                        $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-2">
                                            <div class="form-group">
                                                <label class="required" for="touch">Touch</label>
                                                <input type="text" name="touch[]" class="form-control touch" value="" id="touch_<?=$count?>" placeholder="Touch">
                                            </div>
                                        </div>
                                        
                                        <div class="col-lg-2">
                                            <div class="form-group">
                                                <label class="required" for="today_gram_amount">Per Gram Amount</label>
                                                <input type="text" name="today_gram_amount[]" class="form-control" id="today_gram_amount_<?=$count?>" oninput="ProductTotal(<?=$count?>); GrandTotal();" placeholder="Today Gram Amount">
                                            </div>
                                        </div>
                                        
                                        <div class="col-lg-2">
                                            <div class="form-group">
                                                <label class="required" for="making_charges">Making Charges</label>
                                                <input type="text" name="making_charges[]" class="form-control" id="making_charges_<?=$count?>" oninput="ProductTotal(<?=$count?>); GrandTotal();" placeholder="Making Charges">
                                            </div>
                                        </div>
                                        
                                        
                                        <div class="col-lg-2">
                                            <div class="form-group">
                                                <label class="required" for="total_pro_amount">Total Amount</label>
                                                <input type="text" name="total_pro_amount[]" class="form-control total_product_amount" value="0.00" id="total_amount_<?=$count?>" placeholder="Total Amount" readonly>
                                            </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>