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


$GST=3;
$condition="Order_No='INO/00002'";
$Order_No='INO/00002';


$condition.=" order by SLN";

$Get_Dealers_Stock=$Mainclass->Fetch_multiple_data('gold_indent_details','*',$condition);
foreach($Get_Dealers_Stock as $stock)
{
		$ProductPrice=$stock['Price'];
		
		$Discount=$stock['Discount'];
		
		$GoldMarginValue=$stock['gold_discount'];
		$DiamondMarginValue=$stock['diamond_discount'];
		$MakingChargeMarginValue=$stock['making_charge_discount'];
		$StoneMarginValue=$stock['stone_discount'];
		$SolitaireMarginValue=$stock['solitaire_discount'];
		
		$Total_Product_Cost_Price=$ProductPrice-$Discount;
		
		$XR=($GST * $Total_Product_Cost_Price)/100; 

	    $GST_Amount= $XR;	
		
		$GST_Div=$GST_Amount/2;
		$CGST=$GST_Div;
		$SGST=$GST_Div;
		
		//echo $M=($GoldMarginValue+$DiamondMarginValue+$StoneMarginValue+$SolitaireMarginValue+$MakingChargeMarginValue);
		
		//$DMProductPrice=$ProductPrice-($GoldMarginValue+$DiamondMarginValue+$StoneMarginValue+$SolitaireMarginValue+$MakingChargeMarginValue);
		$DMProductPrice=$ProductPrice-($GoldMarginValue+$DiamondMarginValue+$StoneMarginValue+$SolitaireMarginValue+$MakingChargeMarginValue);
		$Net_Price= $Total_Product_Cost_Price+number_format((float)$CGST, 2, '.', '')+number_format((float)$SGST, 2, '.', '')+number_format((float)$IGST, 2, '.', ''); 
		
		$UpdateOrderDtl="update gold_indent_details set Total='".$DMProductPrice."',Order_Total='".$Net_Price."',GST='".$GST_Amount."',CGST='".$CGST."',SGST='".$SGST."',IGST='".$ROW['IGST']."' where SLN='".$stock['SLN']."'";
		mysqli_query($Mainclass->dbh,$UpdateOrderDtl);
}

           $Sql="select sum(Price) as TotalPrice,sum(Discount) as TotalDiscount, sum(Total) as Gross_Total,sum(Order_Total) as Net_Amt, sum(Order_Quantity) as Total_Qty,sum(GST) as GST,sum(CGST) as CGST,sum(SGST) as SGST,sum(IGST) as IGST,sum(Product_Weight) as Product_Weight from gold_indent_details where Order_No='".$Order_No."'";
           $RS=mysqli_query($Mainclass->dbh,$Sql);
           $ROW=mysqli_fetch_array($RS);
		  
		   $UpdateOrder="update gold_indent_master set Total='".$ROW['TotalPrice']."',Discount='".$ROW['TotalDiscount']."',Gross_Total='".$ROW['Gross_Total']."',Net_Total='".$ROW['Net_Amt']."',GST='".$ROW['GST']."',CGST='".$ROW['CGST']."',SGST='".$ROW['SGST']."',IGST='".$ROW['IGST']."' where Order_No='".$Order_No."'";
		   mysqli_query($Mainclass->dbh,$UpdateOrder);
		   
		   
		   echo "Updated";
?>