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

$g_weight=$_REQUEST['g_weight'];

$diamond_type = $_REQUEST['diamond_type'];
$quality=$_REQUEST['quality'];
$color=$_REQUEST['color'];
$type=$_REQUEST['type'];
$no_diamonds=$_REQUEST['no_diamonds'];
$diamond_value=$_REQUEST['diamond_value'];
$d_carat=$_REQUEST['d_carat'];
//$total_diamond_price = $no_diamonds*$diamond_value*$d_carat;
$total_diamond_price = $diamond_value*$d_carat;
$sol_diamond_type = $_REQUEST['sol_diamond_type'];
$sol_quality=$_REQUEST['sol_quality'];
$sol_color=$_REQUEST['sol_color'];
$sol_type=$_REQUEST['sol_type'];
$sol_no_diamonds=$_REQUEST['sol_no_diamonds'];
$sol_diamond_value=$_REQUEST['sol_diamond_value'];
$s_carat=$_REQUEST['s_carat'];

//$total_sollitaire_price = $sol_no_diamonds*$sol_diamond_value*$s_carat;
$total_sollitaire_price = $sol_diamond_value*$s_carat;
$product_size=$_REQUEST['product_size'];


$temp_id=$_REQUEST['design_id'];
$serial_no=$_REQUEST['serial_no'];
$has_d=$_REQUEST['has_d'];
$has_s=$_REQUEST['has_s'];
$has_size=$_REQUEST['has_size'];

$item_no=$_REQUEST['item_no'];
$total_price=$_REQUEST['total_price'];

$Mainclass->Update_Data("gold_temp_product_master","GoldWeight='".$g_weight."',DiamondQuality='".$quality."',DiamondColor='".$color."',DiamondType='".$type."',No_Diamond='".$no_diamonds."',Diamond_Value='".$diamond_value."',Diamond_Carat='".$d_carat."',total_diamond_price='".$total_diamond_price."',SolitaireQuality='".$sol_quality."',SolitaireColor='".$sol_color."',SolitaireType='".$sol_type."',No_Solitaire='".$sol_no_diamonds."',Solitaire_Value='".$sol_diamond_value."',sollitaire_Carat='".$s_carat."',total_sollitaire_price='".$total_sollitaire_price."',Diamond_Creation_Type='".$diamond_type."',Solitaire_Creation_Type='".$sol_diamond_type."',Product_Size='".$product_size."',add_to_product='No',confirm='No',item_no='".$item_no."',total='".$total_price."'","Temp_Id='".$temp_id."' and serial_no='".$serial_no."'");


$temp_data = $Mainclass->Fetch_multiple_data("gold_temp_product_master","*","Temp_Id='".$temp_id."'");

foreach ($temp_data as $temp_data) {

$data = $Mainclass->Fetch_individual_data("gold_temp_product_master","Product_Id","ParentId='".$temp_data['ParentId']."' and Product_Id!='' order by SLN desc limit 1");
$last_product_id = $data['Product_Id'];
$last_product_id_array = explode("-",$last_product_id); 


$newcount = $last_product_id_array[1] + 1;
$newcount_padded = str_pad($newcount, 3, '0', STR_PAD_LEFT);
$Productid = $temp_data['ParentId']."-".$newcount_padded;

$Mainclass->Update_Data("gold_temp_product_master","confirm='Yes',Product_Id='".$Productid."'","SLN='".$temp_data['SLN']."'");	

if($temp_data['has_stone']=="No" && $temp_data['has_diamond']=="No" && $temp_data['has_solitaire']=="No"){

$m = date('m');
$y = date('y');
$barcode = $Productid . $m . $y;

$added_on = date('Y-m-d H:i:s');
$User_Name = $_COOKIE['User_Name'];
$IP = $_SERVER['REMOTE_ADDR'];

$Mainclass->Insert_Data("gold_products_master","Vendor_Name,VendorDesignCode,Metal_Type,ProductCategory,GoldWeight,ParentId,ProductName,Productid,Barcode,HSNCode,GoldPurity,Stock,StoneName,No_Stone,StoneValue,total_stone_price,Diamond_Creation_Type,DiamondQuality,DiamondColor,DiamondType,No_Diamond,DiamondValue,Diamond_Carat,total_diamond_price,Solitaire_Creation_Type,SolitaireQuality,SolitaireColor,SolitaireType,No_Solitaire,Solitaire_Value,sollitaire_Carat,total_sollitaire_price,Has_Size_Variation,Product_Size,MakingChargesType,MakingChargesValue,Remark,has_stone,has_diamond,has_solitaire,IGINo,Certifying_Organization,HMNo,Added_On,Added_By,IP,Active,Color,VendorBillNo,MRP,item_no,total","'".$temp_data['Vendor_Name']."','".$temp_data['VendorDesignCode']."','".$temp_data['Metal_Type']."','".$temp_data['ProductCategory']."','".$temp_data['GoldWeight']."','".$temp_data['ParentId']."','".$temp_data['ProductName']."','".$Productid."','".$barcode."','".$temp_data['HSNCode']."','".$temp_data['GoldPurity']."','1','".$temp_data['StoneName']."','".$temp_data['No_Stone']."','".$temp_data['Stone_Value']."','".$temp_data['total_stone_value']."','".$temp_data['Diamond_Creation_Type']."','".$temp_data['DiamondQuality']."','".$temp_data['DiamondColor']."','".$temp_data['DiamondType']."','".$temp_data['No_Diamond']."','".$temp_data['Diamond_Value']."','".$temp_data['Diamond_Carat']."','".$temp_data['total_diamond_price']."','".$temp_data['Solitaire_Creation_Type']."','".$temp_data['SolitaireQuality']."','".$temp_data['SolitaireColor']."','".$temp_data['SolitaireType']."','".$temp_data['No_Solitaire']."','".$temp_data['Solitaire_Value']."','".$temp_data['sollitaire_Carat']."','".$temp_data['total_sollitaire_price']."','".$temp_data['Has_Size_Variation']."','".$temp_data['Product_Size']."','".$temp_data['MakingChargesType']."','".$temp_data['MakingChargesValue']."','".$temp_data['Remark']."','".$temp_data['has_stone']."','".$temp_data['has_diamond']."','".$temp_data['has_solitaire']."','".$temp_data['IGINo']."','".$temp_data['Certifying_Organization']."','".$temp_data['HMNo']."','".$added_on."','".$User_Name."' ,'".$IP."' ,'Yes','".$temp_data['Color']."','".$temp_data['VendorBillNo']."','".$temp_data['MRP']."','".$temp_data['item_no']."','".$temp_data['total']."'");


$Mainclass->Update_Data("gold_temp_product_master","add_to_product='Yes',confirm='Yes'","SLN='".$temp_data['SLN']."'");	


}

	
}





?>