<?php
include('db_connection.php');
$Mainclass=new DB_Controller();
$Order_Id=$_REQUEST['Order'];
$Product_SLN=$_REQUEST['Product_SLN'];
$Dealer_Id = $_COOKIE['O_Code'];

mysqli_query($Mainclass->dbh,"DELETE FROM `gold_billing_order_details` WHERE SLN='".$Product_SLN."'");



/*$condition_product="Order_No='".$Order_Id."'";
$Get_Billing_Details=$Mainclass->Fetch_multiple_data("gold_billing_order_details","Barcode",$condition_product);
foreach($Get_Billing_Details as $pro_det)
{
	
	$condition_discount="Dealer_Code like '%".$_COOKIE['O_Code']."%' and Product_Category like '%".$pro_det['Product_Catagory']."%' and Active='Yes' and '".date('Y-m-d')."' between From_Date And To_Date";
	$Check_Discount=$Mainclass->num_check("gold_discount_master","SLN",$condition_discount);
	if($Check_Discount>0)
	{
		$Discount_P=$Mainclass->Fetch_individual_data("gold_discount_master","Discount",$condition_discount);
		$Dis_percent=$Discount_P['Discount'];
	}
	else
	{
		$Dis_percent=0;
	}
	
$Stone_Value=$pro_det['stone_price'];
$Diamond_Value=$pro_det['diamond_price'];
$Solitaire_Value=$pro_det['solitaire_price'];
$Making_Charge_Type=$pro_det['making_charge_type'];
$Making_Charge=$pro_det['making_charge_val'];
$Wastage_Cost=$pro_det['wastage_cost'];
$Gold_Wt=$pro_det['gold_wt'];

$making_discount_percent=$pro_det['making_discount_percent'];
$stone_discount_percent=$pro_det['stone_discount_percent'];
$diamond_discount_percent=$pro_det['diamond_discount_percent'];
$solitaire_discount_percent=$pro_det['solitaire_discount_percent'];

	// $making_discount=$pro_det['making_discount_amt'];
	// $stone_discount=$pro_det['stone_discount_amt'];
	// $diamond_discount=$pro_det['diamond_discount_amt'];
	// $solitaire_discount=$pro_det['solitaire_discount_amt'];

$making_discount = $Making_Charge*($making_discount_percent/100);
$stone_discount = $Stone_Value*($stone_discount_percent/100);
$diamond_discount = $Diamond_Value*($diamond_discount_percent/100);
$solitaire_discount = $Solitaire_Value*($solitaire_discount_percent/100);


	$Today_Gold_Rate=$pro_det['gold_rate'];
	$Total_Gold_Value=$Gold_Wt*$Today_Gold_Rate;
	if($Making_Charge_Type=="Flat")
	{
		$Making_Charge_Val=$Making_Charge;
	}
	if($Making_Charge_Type=="Percentage")
	{
		$Making_Charge_Val=($Total_Gold_Value*$Making_Charge)/100;
	}
	if($Making_Charge_Type=="Rate per gram")
	{
		$Making_Charge_Val=$Making_Charge * $Gold_Wt;
	}
	

$making_discount = $Making_Charge_Val*($making_discount_percent/100);
$stone_discount = $Stone_Value*($stone_discount_percent/100);
$diamond_discount = $Diamond_Value*($diamond_discount_percent/100);
$solitaire_discount = $Solitaire_Value*($solitaire_discount_percent/100);
	
	$GST='3';
	$Stone=$Diamond_Value+$Stone_Value+$Solitaire_Value;
	
	$Discount_Value=($Making_Charge_Val*$Dis_percent)/100;

//=============Total Dealer Discount==============//

	$Total_Dealer_Disc=$making_discount+$stone_discount+$diamond_discount+$solitaire_discount;


	//====Taxable_Amount=====//
	$Amt_Bf_Tax=$Total_Gold_Value+$Making_Charge_Val+$Stone+$Wastage_Cost-$Discount_Value-$Total_Dealer_Disc;
	
	
	$Cgst=round(($GST/2 * $Amt_Bf_Tax)/100,2);
    $Sgst=round(($GST/2 * $Amt_Bf_Tax)/100,2);
    $XR=$Cgst+$Sgst;	
		
	//$GST_Amount=($Amt_Bf_Tax*$GST)/100;
	$GST_Amount=$XR;
	
	
	//$GST_Amount=($Amt_Bf_Tax*$GST)/100;
	
	$Net_Price=$Amt_Bf_Tax+$GST_Amount;

	
	$Condition_details="SLN='".$pro_det['SLN']."'";
	$Field_details="Total_Price='".$Net_Price."',GST='".$GST_Amount."',Discounted_Amount='".$Amt_Bf_Tax."',total_making_charge='".$Making_Charge_Val."',Product_Discount_Percent='".$Dis_percent."',Product_Discount='".$Discount_Value."',making_discount_percent='".$making_discount_percent."',making_discount_amt='".$making_discount."',stone_discount_percent='".$stone_discount_percent."',stone_discount_amt='".$stone_discount."',diamond_discount_percent='".$diamond_discount_percent."',diamond_discount_amt='".$diamond_discount."',solitaire_discount_percent='".$solitaire_discount_percent."',solitaire_discount_amt='".$solitaire_discount."',total_dealer_discount='".$Total_Dealer_Disc."'";
	$Upd_Details=$Mainclass->Update_Data('gold_billing_order_details',$Field_details,$Condition_details);
}





$condition=" Order_No='".$Order_Id."' and Product_Catagory!='Consumable'";
$Total_Quantity=$Mainclass->get_sum_field('gold_billing_order_details',"Quantity",$condition);
$condition1=" Order_No='".$Order_Id."' and Product_Catagory='Consumable'";
$Total_Consumable_Quantity=$Mainclass->get_sum_field('gold_billing_order_details',"Quantity",$condition1);
$condition_Bday=" Order_No='".$Order_Id."'";
$Total_Amount=$Mainclass->get_sum_field('gold_billing_order_details',"Price",$condition_Bday);
$Net_Amount=$Mainclass->get_sum_field('gold_billing_order_details',"Total_Price",$condition_Bday);
$Total_GST=$Mainclass->get_sum_field('gold_billing_order_details',"GST",$condition_Bday);
$Total_Making_Charge=$Mainclass->get_sum_field('gold_billing_order_details',"total_making_charge",$condition_Bday);

$Total_Discounted_Amt=$Mainclass->get_sum_field('gold_billing_order_details','Discounted_Amount',$condition_Bday);
$Total_Product_Discount=$Mainclass->get_sum_field('gold_billing_order_details',"Product_Discount",$condition_Bday);
$Total_Product_Value=$Mainclass->get_sum_field('gold_billing_order_details',"product_price",$condition_Bday);
$Total_Wastage_Value=$Mainclass->get_sum_field('gold_billing_order_details',"wastage_cost",$condition_Bday);
$Total_Dealer_Disc_Master=$Mainclass->get_sum_field('gold_billing_order_details',"total_dealer_discount",$condition_Bday);


$FieldValue="Quantity='".$Total_Quantity."',Total='".$Total_Amount."',Net_Total='".$Net_Amount."',GST='".$Total_GST."',Bill_Generated_By='".$_COOKIE['User_Name']."',Consumable_Quantity='".$Total_Consumable_Quantity."',Discounted_Amount='".$Total_Discounted_Amt."',total_making_charge='".$Total_Making_Charge."',Product_Discount='".$Total_Product_Discount."',total_product_price='".$Total_Product_Value."',making_discount_percent='".$making_discount_percent."',making_discount_amt='".$making_discount."',stone_discount_percent='".$stone_discount_percent."',stone_discount_amt='".$stone_discount."',diamond_discount_percent='".$diamond_discount_percent."',diamond_discount_amt='".$diamond_discount."',solitaire_discount_percent='".$solitaire_discount_percent."',solitaire_discount_amt='".$solitaire_discount."',total_dealer_discount='".$Total_Dealer_Disc_Master."'";

$Condition=" Order_No='".$Order_Id."'";

$Update_master=$Mainclass->Update_Data('gold_billing_order_master',$FieldValue,$Condition);*/

?>