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

$new_id = $Mainclass->real_escapes($_REQUEST['new_id']);
$g_weights = $_REQUEST['g_weights'];
$d_carats = $_REQUEST['d_carats'];
$s_carats = $_REQUEST['s_carats'];
$igi_nos = $_REQUEST['igi_nos'];
$hm_nos = $_REQUEST['hm_nos'];

for ($i = 0; $i < count($g_weights); $i++) {

    $g_weight = $Mainclass->real_escapes($g_weights[$i]);
    $d_carat = $Mainclass->real_escapes($d_carats[$i]);
	$s_carat = $Mainclass->real_escapes($s_carats[$i]);
    $igi_no = $Mainclass->real_escapes($igi_nos[$i]);
    $hm_no = $Mainclass->real_escapes($hm_nos[$i]);

$fetch_data = $Mainclass->Fetch_individual_data("gold_temp_product_master","*","SLN='".$new_id."'");
$data = $Mainclass->Fetch_individual_data("design_code_master","*","ParentId='".$fetch_data['ParentId']."'");

$count_check = $Mainclass->num_check("gold_products_master", "SLN", "ParentId='".$fetch_data['ParentId']."'");
$newcount = $count_check + 1;
$newcount_padded = str_pad($newcount, 3, '0', STR_PAD_LEFT);
$Productid = $fetch_data['ParentId']."-".$newcount_padded;



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


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


if($data['No_Stone']==0 && $data['No_Diamond']==0){

$inactive = "Yes";

$flag = 0;

}

else{

if($igi_no==""){

$inactive = "No";

$flag = 1;

}

}
	
	
$total_stone_price = $data['No_Stone']*$data['Stone_Value'];	
$total_diamond_price = $data['No_Diamond']*$data['Diamond_Value']*$d_carat;	
$total_sollitaire_price = $data['No_Solitaire']*$data['Solitaire_Value']*$s_carat;	
	
$Mainclass->Insert_Data("gold_products_master","ProductCategory	,Metal_Type	,ParentId	,ProductName	,Productid	,Barcode	,Vendor_Name	,VendorDesignCode	,HSNCode	,GoldPurity	,GoldWeight	,StoneName	,No_Stone	,StoneValue	,total_stone_price ,DiamondQuality	,DiamondColor	,DiamondType	,No_Diamond	,DiamondValue	,Diamond_Carat	,total_diamond_price ,SolitaireQuality	,SolitaireColor	,SolitaireType	,No_Solitaire	,Solitaire_Value	,sollitaire_Carat	,total_sollitaire_price,MakingChargesType	,MakingChargesValue	,WastedCost	,Remark	,IGINo	,HMNo	,Added_On	,Added_By ,IP,Active,is_igi_required,has_stone,has_diamond,has_solitaire,Stock"," '".$data['ProductCategory']."','".$data['Metal_Type']."','".$data['ParentId']."','".$data['ProductName']."','".$Productid."','".$barcode."','".$fetch_data['Vendor_Name']."','".$fetch_data['VendorDesignCode']."','".$data['HSNCode']."','".$data['GoldPurity']."','".$g_weight."','".$data['StoneName']."','".$data['No_Stone']."','".$data['Stone_Value']."','".$total_stone_price."','".$data['DiamondQuality']."','".$data['DiamondColor']."','".$data['DiamondType']."','".$data['No_Diamond']."','".$data['Diamond_Value']."','".$d_carat."','".$total_diamond_price."','".$data['SolitaireQuality']."','".$data['SolitaireColor']."','".$data['SolitaireType']."','".$data['No_Solitaire']."','".$data['Solitaire_Value']."','".$s_carat."','".$total_sollitaire_price."','".$data['MakingChargesType']."','".$data['MakingChargesValue']."','".$data['WastageCost']."','".$data['Remark']."','".$igi_no."','".$hm_no."','".$DateTime."','".$Added_By."','".$IP."','".$inactive."','".$flag."','".$data['has_stone']."','".$data['has_diamond']."','".$data['has_solitaire']."','1' ");

}

?>
