<?php
include('db_connection.php');

$Mainclass=new DB_Controller();


$SqCheckIndent="select * from gold_indent_master where Order_No='".$_REQUEST['Order_No']."'";
$RsCheckIndent=mysqli_query($Mainclass->dbh,$SqCheckIndent);
$FchIndent=mysqli_fetch_array($RsCheckIndent);


$FetchDealerCon=" Order_Code= '".$FchIndent['Dealer_Code']."'";
$Field_Needed="State,Dealer_Credit_Limit,Dealer_Type";
$DeaerDtl=$Mainclass->Fetch_individual_data('dealer_master',$Field_Needed,$FetchDealerCon);


$AvailableCr=$DeaerDtl['Dealer_Credit_Limit'];
$RemainingBl=$AvailableCr-$FchIndent['Net_Total'];

?>
<input type="hidden" class="form-control" name="Indent_Net_Amt" id="Indent_Net_Amt" value="<?php echo $FchIndent['Net_Total']; ?>" >
<div class="row" style="margin-bottom:20px;"><div class="col-sm-12"><div class="btn btn-danger waves-effect waves-light" style="float:right; margin-left:10px;">Remaining Credit Limit : <?php echo number_format($RemainingBl,2); ?></div><div class="btn btn-success waves-effect waves-light" style="float:right;">Available Credit Limit : <?php echo number_format($AvailableCr,2); ?></div></div></div>
<table id="multi-colum-dt" class="table table-striped table-bordered nowrap">

<thead>

<tr>

<th>SLN </th>

<th>Product Code</th>

<th>Qty</th>

<!--<th>Warehouse Stock</th>-->
<th>Gold Dtl</th>
<th>Stone Dtl</th>'
<th>Dmd Dtl</th>
<th>Sol Dtl</th>
<th>Making Charge</th>



<!--<th>Dealer Stock</th>-->

<th>MRN</th>

<th>Price</th>

<th>Discount</th>

<!--<th>GST</th>-->

<th>CGST</th>

<th>SGST</th>


<th>IGST</th>



<th>Total</th>


<th>Action</th>

</tr>

</thead>

<tbody>

<?php



//$_REQUEST['Indent_No']='IND001';

	  $condition.="  Order_No='".$_REQUEST['Order_No']."' order by SLN desc";

  

//$condition.="  group by Category";

$Get_Dealers_Stock=$Mainclass->Fetch_multiple_data('gold_indent_details','*',$condition);

if($Get_Dealers_Stock>0)

{	

$i=1;

   $ToatlIndQty=0;
   $ToatlIndAmt=0;
   $ToatlIndPrice=0;
   $TotalGst=0;
   $TotalDiscount=0;
   
   
    $TotalCGST=0;
	$TotalSGST=0;
	$TotalIGST=0;

    foreach($Get_Dealers_Stock as $stock)

	{

	   $Condition=" Product_Code ='".$stock['Product_Code']."' and Dealer_Code='".$FchIndent['Dealer_Code']."'"; 
       $Get_Quantity=$Mainclass->Fetch_individual_data('dealer_gold_stock_master','*',$Condition);
	   
	   
	   $PMSDCondition=" Productid ='".$stock['Product_Code']."'"; 
	   $PMSD_QTY=$Mainclass->Fetch_individual_data('gold_products_master','*',$PMSDCondition);
	   
	   
	   $MRN_Date_Limit=date('Y-m-d', strtotime("-183 days"));
	   
	   $MRNCondition=" Product_Code ='".$stock['Product_Code']."' and Dealer_Code='".$FchIndent['Dealer_Code']."' and Return_Status='Yes' and MRN_Date >=".$MRN_Date_Limit;
	   
	   $MRN=$Mainclass->get_sum_field('damage_return_details','Quantity',$MRNCondition);
	   
	  if($MRN=="")
	   {
		   $MRN=0;
		   
	   }
	   else{
		   $MRN=$MRN;
	   }

?>

<tr>

<th scope="row"><?php echo $i;?></th>



<td><span style="float:left; width:80%; height:auto"><?php echo $stock['Product_Code'];?></span>



</td>

<td><span style="float:left; width:30%; height:auto"><?php echo $stock['Order_Quantity'];?></span>





</td>

<!--<td><span style="float:left; width:80%; height:auto">
<?php echo $PMSD_QTY['Stock'];?>
</span>

</td>-->


<td>
<b>GR</b> : <?php echo $stock['gold_rate'];?><br>
<b>CT</b> : <?php echo $stock['gold_purity'];?><br>
<b>Wt</b> : <?php echo $stock['gold_wt'];?><br>
<b>Total</b> : <?php echo $stock['gold_value'];?><br>
<b>Dis</b> : <?php echo $stock['gold_discount'];?><br>
<b>Net Value</b> : <?php echo $stock['total_gold_value'];?><br>
</td>
<td>
<b>SR</b> : <?php echo $stock['stone_price'];?><br>
<b>Qty</b> : <?php echo $stock['no_stone'];?><br>
<b>Total</b> : <?php echo $stock['stone_value'];?><br>
<b>Dis</b> : <?php echo $stock['stone_discount'];?><br>
<b>Net Value</b> : <?php echo $stock['total_stone_value'];?><br>
</td>
<td>
<b>DR</b> : <?php echo $stock['diamond_rate'];?><br>
<b>CT</b> : <?php echo $stock['diamond_carat'];?><br>
<b>Qty</b> : <?php echo $stock['no_diamond'];?><br>
<b>Total</b> : <?php echo $stock['diamond_value'];?><br>
<b>Dis</b> : <?php echo $stock['diamond_discount'];?><br>
<b>Net Value</b> : <?php echo $stock['total_diamond_value'];?><br>
</td>
<td>
<b>SLR</b> : <?php echo $stock['solitaire_price'];?><br>
<b>CT</b> : <?php echo $stock['sollitaire_carat'];?><br>
<b>Qty</b> : <?php echo $stock['no_solitaire'];?><br>
<b>Total</b> : <?php echo $stock['sollitaire_value'];?><br>
<b>Dis</b> : <?php echo $stock['solitaire_discount'];?><br>
<b>Net Value</b> : <?php echo $stock['total_sollitaire_value'];?><br>
</td>

<td>
<b>MC</b> : <?php echo $stock['making_charge'];?><br>
<b>MC Type</b> : <?php echo $stock['making_charge_type'];?><br>
<b>Dis</b> : <?php echo $stock['making_charge_discount'];?><br>
<b>Net Value</b> : <?php echo $stock['total_making_charge'];?><br>
</td>


<!--
<td><span style="float:left; width:80%; height:auto">
<?php echo $Get_Quantity['Quantity'];?>
</span>

</td>-->


<td style="text-align:right;"><?php echo $MRN; ?></td>

<td style="text-align:right;"><?php echo $stock['Price'];?></td>


<td style="text-align:right;"><?php echo $stock['Discount'];?></td>


<!--<td><span style="float:left; width:80%; height:auto"><?php echo $stock['GST'];?></span>-->

<td style="text-align:right;"><?php echo $stock['CGST'];?></td>
<td  style="text-align:right;"><?php echo $stock['SGST'];?></td>
<td  style="text-align:right;"><?php echo $stock['IGST'];?></td>


<td  style="text-align:right;"><?php echo $stock['Order_Total'];?></td>







<td>



<?php
if($FchIndent['Scan1_Status']!='1')
{
?>

<i class="fas fa-trash" style="font-size:20px; color:#FF0000; cursor:pointer;" rel="tooltip" title="Delete " onClick="delete_Category('<?php echo $stock['SLN'];?>')"></i>
<?php

}
?>

</td>

</tr>

<?php

$i++;

$ToatlIndQty=$ToatlIndQty+$stock['Order_Quantity'];
$ToatlIndAmt=$ToatlIndAmt+$stock['Order_Total'];

$ToatlIndPrice=$ToatlIndPrice+$stock['Price'];

$TotalGst=$TotalGst+$stock['GST'];

$TotalDiscount=$TotalDiscount+$stock['Discount'];

$TotalCGST=$TotalCGST+$stock['CGST'];
$TotalSGST=$TotalSGST+$stock['SGST'];
$TotalIGST=$TotalIGST+$stock['IGST'];
}

?>

<tr>

<th scope="row">Total</th>



<td></td>





<td><span style="float:left; width:80%; height:auto"><?php echo $ToatlIndQty;?></span>





</td>


<td><span style="float:left; width:80%; height:auto">

</span>

</td>

<td><span style="float:left; width:80%; height:auto">

</span>

</td>
<td><span style="float:left; width:80%; height:auto">

</span>

</td>
<td><span style="float:left; width:80%; height:auto">

</span>

</td>

<td><span style="float:left; width:80%; height:auto">

</span>

</td>
<td><span style="float:left; width:80%; height:auto">

</span>

</td>
<td  style="text-align:right;">

<?php echo number_format($ToatlIndPrice,2); ?>


</td>

<td  style="text-align:right;">

<?php echo number_format($TotalDiscount,2); ?>




</td>

<!--
<td><span style="float:left; width:60%; height:auto">
<?php echo number_format($TotalGst,2); ?>
</span></td>--->


<td  style="text-align:right;">
<?php echo number_format($TotalCGST,2); ?>
</td>


<td  style="text-align:right;">
<?php echo number_format($TotalSGST,2); ?>
</td>


<td  style="text-align:right;">
<?php echo number_format($TotalIGST,2); ?>




</td>


<td  style="text-align:right;">




<?php echo number_format($ToatlIndAmt,2); ?>

</td>

<td>



</td>

</tr>
<?php

}

else

{

?>

    <tr><td colspan="17" style="text-align:center; font-weight:bold; color:#FF0000;"> No Data Found!</td></tr>

<?php

}

?>

</tbody>

</table>

<div class="col-sm-12" ><div class="form-group row">
<label class="col-sm-12 col-form-label">&nbsp;</label>
<?php
/*
if($Get_Dealers_Stock>0 && $FchIndent['Indent_Status']!='Completed')
{
?>
<div class="col-sm-12">
<input name="save_submit" type="button" class="btn btn-primary m-b-0" value="COMPLETE" style="float:right; padding: 3px 14px; font-size:13px;" onClick="Complete_Indent()">
</div>
<?php
}*/
?>
</div></div>


<div class="footer-copyright-area">Total Scan Qty : <?php echo $ToatlIndQty; ?> | Total Amount : <?php echo number_format($ToatlIndAmt,2); ?> | Available Credit Limit : <?php echo $AvailableCr; ?> | Remaining Credit Limit : <span id="show_remain"><?php echo $RemainingBl; ?></span>

<?php





if($Get_Dealers_Stock>0 && $FchIndent['Indent_Status']!='Completed')
{



?>



<input name="save_submit" type="button" class="btn btn-primary m-b-0" value="COMPLETE" style="float:right; padding: 3px 14px; font-size:13px; margin-left:10px;" onClick="Complete_Indent()">







<?php



}











?></div>