<?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'];


$SqCheckIndent="select * from gold_indent_details where Order_No='".$_REQUEST['Order_No']."' and  Scan2 ='0'";
$RsCheckIndent=mysqli_query($Mainclass->dbh,$SqCheckIndent);
$PendingScan=mysqli_num_rows($RsCheckIndent);



?>
<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"><a href="pending-scantwo-fancy.php?Order_No=<?php echo $_REQUEST['Order_No']; ?>" class="various" data-fancybox-type="iframe" style="text-decoration:none;"><div class="btn btn-danger waves-effect waves-light" style="float:right; margin-left:10px;">Pending Final Scan : <?php echo $PendingScan; ?></div></a> <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>Prd Code</th>

<th>Order Qty</th>

<!--<th>W.H. 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 style="text-align:right;">Price</th>

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

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

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

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


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



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


<!--<th>Action</th>-->

</tr>

</thead>

<tbody>

<?php



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

	  $condition="  Order_No='".$_REQUEST['Order_No']."' and Scan2=1 order by Sequence 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_stock_master','*',$Condition);
	   
	   
	   $PMSDCondition=" Product_Code ='".$stock['Product_Code']."'"; 
	   $PMSD_QTY=$Mainclass->Fetch_individual_data('gold_product_master','*',$PMSDCondition);

?>

<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:80%; 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;"><span style="float:left; width:100%; height:auto"><?php echo $stock['Price'];?></span></td>


<td style="text-align:right;"><span style="float:left; width:100%; height:auto"><?php echo $stock['Discount'];?></span>


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

<td style="text-align:right;"><span style="float:left; width:100%; height:auto"><?php echo $stock['CGST'];?></span>
<td style="text-align:right;"><span style="float:left; width:100%; height:auto"><?php echo $stock['SGST'];?></span>
<td style="text-align:right;"><span style="float:left; width:100%; height:auto"><?php echo $stock['IGST'];?></span>


<td style="text-align:right;"><span style="float:left; width:100%; height:auto"><?php echo $stock['Order_Total'];?></span>





<span style="float:left; width:15%; height:auto; margin-left:5%; padding-top:4px; display:none;" id="show1_check<?php echo $i;?>"> 

<i class="feather icon-check" style="color:#009900; cursor:pointer; font-size:18px; font-weight:600; " onClick="update_category('<?php echo $stock['SLN'];?>','<?php echo $i;?>')"></i> 

<i class="feather icon-x" style="color:#FF0000; cursor:pointer; font-size:18px; font-weight:600; " onClick="close_edit()"></i>

</span>

</td>


<!--
<td>

<i class="feather icon-edit" style="font-size:20px; margin-right:10px; margin-left:20px; cursor:pointer;" rel="tooltip" title="Edit " onClick="edit_category('<?php echo $i;?>')"></i>

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

</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><span style="float:left; width:80%; height:auto"></span>



</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 style="text-align:right;"><span style="float:left; width:100%; height:auto">

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

</td>

<td style="text-align:right;"><span style="float:left; width:100%; height:auto">

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



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


<td style="text-align:right;"><span style="float:left; width:100%; height:auto">
<?php echo number_format($TotalCGST,2); ?>
</span></td>


<td style="text-align:right;"><span style="float:left; width:100%; height:auto">
<?php echo number_format($TotalSGST,2); ?>
</span></td>


<td style="text-align:right;"><span style="float:left; width:100%; height:auto">
<?php echo number_format($TotalIGST,2); ?>
</span>



</td>


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




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

</td>



</tr>
<?php

}

else

{

?>

    <tr><td colspan="14" 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['Scan1_Status']=='1' && $FchIndent['Scan2_Status']!='1')
{
?>
<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="Check_Scan2()">
</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['Scan1_Status']=='1' && $FchIndent['Scan2_Status']!='1')
{

?>

<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="Check_Scan2()">



<?php

}



?></div>