<?php
include("db_connection.php");
$Mainclass=new DB_Controller();

$barcode=$_REQUEST['scan_barcode'];


$fetch_sql = $Mainclass->dbh->prepare("SELECT * FROM gold_products_master WHERE Barcode=? ");
$fetch_sql->bind_param('s',$barcode);
$fetch_sql->execute();
$fetch_qry=$fetch_sql->get_result();
$fetch_data = $fetch_qry->fetch_assoc();


$category = $Mainclass->Fetch_individual_data("gold_product_category_master",'*',"SLN='".$fetch_data['ProductCategory']."'");

if($fetch_data['StoneName']==""){

$stone_name ="NA";
  
}

else{

  $stone_name = $fetch_data['StoneName'];
}

?>



<div class="row mb-3"> 
 <div class="col-sm-12">
     
  <h5 class="mb-2 text-uppercase">Product Details</h5>   
 <table class="table">
  
  <tbody>
    <tr>
      <th class="text-start">Product Code</th>
     
      <td class="text-end"><?php echo $fetch_data['Productid']?></td>
    </tr>


    <tr>
      <th class="text-start">Product Category</th>
     
      <td class="text-end"><?php echo $category['Category']?></td>
    </tr>
  

    <tr>
      <th class="text-start">Product Name</th>
     
      <td class="text-end"><?php echo $fetch_data['ProductName']?></td>
    </tr>

        <tr>
      <th class="text-start">HSN Code</th>
     
      <td class="text-end"><?php echo $fetch_data['HSNCode']?></td>
    </tr>

    <tr>
      <th class="text-start">Gold Purity</th>
     
      <td class="text-end"><?php echo $fetch_data['GoldPurity']?></td>
    </tr>


        <tr>
      <th class="text-start">Gold Weight</th>
     
      <td class="text-end"><?php echo $fetch_data['GoldWeight']?> Gm.</td>
    </tr>

        <tr>
      <th class="text-start">Stone</th>
     
      <td class="text-end"><?php echo $stone_name?></td>
    </tr>


            <tr>
      <th class="text-start">IGI No</th>
     
      <td class="text-end"><?php echo $fetch_data['IGINo']?></td>
    </tr>


    </tbody>
    </table>
     
     
     
     
     
 </div>   
    
</div>

<?php 

if($fetch_data['has_diamond']=="Yes"){

?>

<div class="row">
    
    <div class="col-sm-6">
        
    <section class="faq">    
        
      <div class="wrapper_child">
                            <div class="question__faqs bg2 body_font lh-sm fw-normal border-bottom">
                                <div class="row m-0 p-0">
                                <div class="col-sm-12 p-0"><h5 class="mb-2 text-uppercase w-100"> Diamond DETAILS</h5></div> 
                                <div class="col-sm-12 p-0"><h6 class="w-100 fs-6">Total Weight : <?php echo $fetch_data['Diamond_Carat']?> Ct | Total No. Of Diamonds : <?php echo $fetch_data['No_Diamond']?></h6></div>
                                
                                </div>
                            
                            
                            </div>
                            <div class="answercont" style="max-height: 0px;">
        
                           
                                        
 <table class="table">
  
  <tbody>
    <tr>
      <th class="text-start">Diamond Type</th>
     
      <td class="text-end"><?php echo $fetch_data['Diamond_Creation_Type']?></td>
    </tr>


    <tr>
      <th class="text-start">Diamond Quality</th>
     
      <td class="text-end"><?php echo $fetch_data['DiamondQuality']?></td>
    </tr>
  

    <tr>
      <th class="text-start">Diamond Color</th>
     
      <td class="text-end"><?php echo $fetch_data['DiamondColor']?></td>
    </tr>

        <tr>
      <th class="text-start">Diamond Size</th>
     
      <td class="text-end"><?php echo $fetch_data['DiamondType']?></td>
    </tr>


    </tbody>
    </table>
             
                                        
                                        
                                        
                                        
                                        
                                        
                                    </p>
                                </div>
                            </div>
                        </div>  
        </div> 
        
<?php } ?>



<?php 

if($fetch_data['has_solitaire']=="Yes"){

?>

<div class="row">
    
    <div class="col-sm-6">
        
    <section class="faq">    
        
      <div class="wrapper_child">
                            <div class="question__faqs bg2 body_font lh-sm fw-normal border-bottom">
                                <div class="row m-0 p-0">
                                <div class="col-sm-12 p-0"><h5 class="mb-2 text-uppercase w-100"> Solitaire DETAILS</h5></div> 
                                <div class="col-sm-12 p-0"><h6 class="w-100 fs-6">Total Weight : <?php echo $fetch_data['sollitaire_Carat']?> Ct | Total No. Of Solitaires : <?php echo $fetch_data['No_Solitaire']?></h6></div>
                                
                                </div>
                            
                            
                            </div>
                            <div class="answercont" style="max-height: 0px;">
        
                           
                                        
 <table class="table">
  
  <tbody>
    <tr>
      <th class="text-start">Solitaire Type</th>
     
      <td class="text-end"><?php echo $fetch_data['Solitaire_Creation_Type']?></td>
    </tr>


    <tr>
      <th class="text-start">Solitaire Quality</th>
     
      <td class="text-end"><?php echo $fetch_data['SolitaireQuality']?></td>
    </tr>
  

    <tr>
      <th class="text-start">Solitaire Color</th>
     
      <td class="text-end"><?php echo $fetch_data['SolitaireColor']?></td>
    </tr>

        <tr>
      <th class="text-start">Solitaire Size</th>
     
      <td class="text-end"><?php echo $fetch_data['SolitaireType']?></td>
    </tr>


    </tbody>
    </table>
             
                                        
                                        
                                        
                                        
                                        
                                        
                                    </p>
                                </div>
                            </div>
                        </div>  
        </div> 
        
<?php } ?>



<div class="row">
    
    <div class="col-sm-6">
        
    <section class="faq">    
        
      <div class="wrapper_child">
                            <div class="question__faqs bg2 body_font lh-sm fw-normal border-bottom active">
                                <div class="row m-0 p-0">
                                <div class="col-sm-12 p-0"><h5 class="mb-2 text-uppercase w-100"> Price Breakup</h5></div> 
                                
                                
                                </div>
                            
                            
                            </div>
                            <div class="answercont" style="max-height: 235px;">
        
                   
                            
<?php 

$today = date('Y-m-d');
$fetch_gold_rate = $Mainclass->Fetch_individual_data("gold_rate_master",'Selling_Rate',"DATE(Entry_Date)='".$today."' and Karat='".$fetch_data['GoldPurity']."' order by SLN desc limit 1");
$gold_rate = $fetch_gold_rate['Selling_Rate']; 

$gold_value = $fetch_data['GoldWeight']*$gold_rate;

$stone_price=$fetch_data['total_stone_price'];

$diamond_value = $fetch_data['Diamond_Carat']*$fetch_data['DiamondValue'];
$solitaire_value = $fetch_data['sollitaire_Carat']*$fetch_data['Solitaire_Value'];

$making_type="";

if($fetch_data['MakingChargesType']=="Flat"){

$making_type="";

}

if($fetch_data['MakingChargesType']=="Percentage"){

$making_type=$fetch_data['MakingChargesValue']." % of ".$gold_value ;

}

if($fetch_data['MakingChargesType']=="Rate per gram"){

$making_type=$fetch_data['MakingChargesValue']."/gram";

}

$making_charge_val=$fetch_data['current_making_charge'];

$price_before_gst = $gold_value+$stone_price+$diamond_value+$solitaire_value+$making_charge_val;
$gst = number_format($price_before_gst*(3/100),2);

$total_value = $price_before_gst+$gst;

?>

                                        
 <table class="table">
  
  <tbody>
    <tr>
      <th class="text-start">Gold Value</th>
     
      <td class="text-end" style="text-align:right"> <i class="fa-solid fa-indian-rupee-sign"></i> <?php echo number_format($gold_value,2);?></td>
    </tr>


    <tr>
      <th class="text-start">Stone Value</th>
     
      <td class="text-end" style="text-align:right"><i class="fa-solid fa-indian-rupee-sign"></i> <?php echo $stone_price?></td>
    </tr>
  

    <tr>
      <th class="text-start">Diamond Value</th>
     
      <td class="text-end" style="text-align:right"> <i class="fa-solid fa-indian-rupee-sign"></i> <?php echo number_format($diamond_value,2)?></td>
    </tr>

        <tr>
      <th class="text-start">Solitaire Value</th>
     
      <td class="text-end" style="text-align:right"> <i class="fa-solid fa-indian-rupee-sign"></i> <?php echo number_format($solitaire_value,2)?></td>
    </tr>


        <tr>
      <th class="text-start">Making Charge Value (<?php echo $making_type?>)</th>
     
      <td class="text-end" style="text-align:right"> <i class="fa-solid fa-indian-rupee-sign"></i> <?php echo number_format($making_charge_val,2);?></td>
    </tr>


        <tr>
      <th class="text-start">GST</th>
     
      <td class="text-end" style="text-align:right"> <i class="fa-solid fa-indian-rupee-sign"></i> <?php echo $gst;?></td>
    </tr>

        <tr>
      <th class="text-start">Total</th>
     
      <td class="text-end" style="text-align:right"> <i class="fa-solid fa-indian-rupee-sign"></i> <?php echo number_format($total_value,2)?></td>
    </tr>

    </tbody>
    </table>
             
                                        
                                        
                                        
                                        
                                        
                                        
                                    </p>
                                </div>
                            </div>
                        </div>  
        </div> 

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js" ></script>
<script>

document.addEventListener('DOMContentLoaded', function () {
    var tooltipTriggerList = [].slice.call(document.querySelectorAll('.tooltip-trigger'));
    tooltipTriggerList.forEach(function (tooltipTriggerEl) {
        new bootstrap.Tooltip(tooltipTriggerEl, {
            html: true
        });
    });
});
</script>


<script>
        let question__faqs = document.querySelectorAll(".question__faqs");

        question__faqs.forEach(question => {
            question.addEventListener("click", () => {
                const active = document.querySelector(".question__faqs.active");
                if (active && active !== question) {
                    active.classList.remove("active");
                    active.nextElementSibling.style.maxHeight = 0;
                }

                question.classList.toggle("active");
                const answer = question.nextElementSibling;

                if (question.classList.contains("active")) {
                    // Temporarily set maxHeight to none to get correct scrollHeight
                    answer.style.maxHeight = 'none';
                    const height = answer.scrollHeight + "px";
                    answer.style.maxHeight = 0; // Reset first
                    setTimeout(() => {
                        answer.style.maxHeight = height;
                    }, 10); // Delay required for transition
                } else {
                    answer.style.maxHeight = 0;
                }
            });
        });
        
    
        
    </script>  
