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

$p_cate=$Mainclass->real_escapes($_REQUEST['p_cate']);
$design_id=$Mainclass->real_escapes($_REQUEST['design_id']);
$m_type=$Mainclass->real_escapes($_REQUEST['m_type']);
$design_qty=$Mainclass->real_escapes($_REQUEST['design_qty']);
$vendor_name=$Mainclass->real_escapes($_REQUEST['vendor_name']);
$v_designcode=$Mainclass->real_escapes($_REQUEST['v_designcode']);
$v_billno=$Mainclass->real_escapes($_REQUEST['v_billno']);
$purchase_gold_rate=$Mainclass->real_escapes($_REQUEST['purchase_gold_rate']);
$invoice_date=date('Y-m-d',strtotime($_REQUEST['invoice_date']));

$fetch_last_id=$Mainclass->Fetch_individual_data("gold_temp_product_master","MAX(Temp_Id) as Temp","SLN>0");
	
	if($fetch_last_id['Temp']!="")
	{
		$explode_id=explode("/",$fetch_last_id['Temp']); 
		
		$new_id=$explode_id[1]+1;
		
		$temp_id="Temp/".str_pad($new_id, 4, '0', STR_PAD_LEFT); 
	}

	else
	{
		$temp_id="Temp/0001";
	}


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


for ($i=1; $i <=$design_qty; $i++) { 


$data = $Mainclass->Fetch_individual_data("design_code_master","*","ParentId='".$design_id."'");

$total_stone_value = $data['No_Stone']*$data['Stone_Value'];

$Mainclass->Insert_Data("gold_temp_product_master","Temp_Id,serial_no,ProductCategory,Metal_Type,ParentId,Quantity,Vendor_Name,VendorDesignCode,Added_On,Added_By,ProductName,HSNCode,GoldPurity,StoneName,No_Stone,Stone_Value,DiamondQuality,DiamondColor,DiamondType,No_Diamond,Diamond_Value,SolitaireQuality,SolitaireColor,SolitaireType,No_Solitaire,Solitaire_Value,MakingChargesType,MakingChargesValue,WastageCost,Remark,has_stone,has_diamond,has_solitaire,add_to_product,igi_updation,Diamond_Creation_Type,Solitaire_Creation_Type,Has_Size_Variation,confirm,total_stone_value,Color,VendorBillNo,MRP,purchase_gold_rate,invoice_date"," '".$temp_id."','".$i."','".$p_cate."','".$m_type."','".$design_id."','1','".$vendor_name."','".$v_designcode."','".$added_on."','".$User_Name."','".$data['ProductName']."','".$data['HSNCode']."','".$data['GoldPurity']."','".$data['StoneName']."','".$data['No_Stone']."','".$data['Stone_Value']."','".$data['DiamondQuality']."','".$data['DiamondColor']."','".$data['DiamondType']."','".$data['No_Diamond']."','".$data['Diamond_Value']."','".$data['SolitaireQuality']."','".$data['SolitaireColor']."','".$data['SolitaireType']."','".$data['No_Solitaire']."','".$data['Solitaire_Value']."','".$data['MakingChargesType']."','".$data['MakingChargesValue']."','".$data['WastageCost']."','".$data['Remark']."','".$data['has_stone']."','".$data['has_diamond']."','".$data['has_solitaire']."','No','No','".$data['Diamond_Creation_Type']."','".$data['Solitaire_Creation_Type']."','".$data['Has_Size_Variation']."','No','".$total_stone_value."','".$data['Color']."','".$v_billno."','".$data['MRP']."','".$purchase_gold_rate."','".$invoice_date."'");

}



echo $temp_id ;


?>