<style>
table {
    border-collapse: collapse;}
th {
    background-color: #808080;
    color: white;}
th, td {
    text-align: left;
    padding: 2px;
    #width:1250px;
    font:normal 11px/2.0em Sans-Serif;}

tr:nth-child(even){background-color:#eee}
tr:hover {background-color: #f5f5f5}
pragra{color:#959595;font:normal 12px/2.0em Sans-Serif;}
</style>

<?php
//Pending Invoices - against prices//
//$con=mysqli_connect("localhost","primarysales","S5L7lF01EQZvQrGK","primarysales_dianaold");
//$result=mysqli_query($con,"select distinct(item_names) as ittm,dates,invoice_number,agent_names,invoice_types,item_ranges,sub_ranges,executive_names,regions,regions,territory_names,agent_types,sum(box_qty)as qty,sum(box_qty*packets_per_box*packet_weights/1000000)as tones,sum(box_qty*box_price)as grand_val,invoice_types,itemcodes from rc_invoices where dates between '2023-12-01' and '2023-12-31' group by invoice_number,box_price,item_ranges,item_names,regions,agent_names,territory_names,dates order by dates");

//Incentive-RD
//$con=mysqli_connect("localhost","primarysales","S5L7lF01EQZvQrGK","primarysales_dianaold");

//$result=mysqli_query($con,"select distinct(item_names) as ittm,agent_names,invoice_types,item_ranges,sub_ranges,executive_names,regions,regions,territory_names,agent_types,sum(pcs_qty)as qty,sum(free_qtys) as free,sum(pcs_qty*packet_weights/1000000) as tones,sum(pcs_qty*pcs_price)as grand_val,pcs_price as pricee,invoice_types,dates from rd_saleinv where dates between '2024-01-01' and '2024-01-31' group by item_ranges,item_names,regions,agent_names,territory_names order by dates");

//DB-RD-DATA ANALYSIS
//$con=mysqli_connect("localhost","primarysales","S5L7lF01EQZvQrGK","primarysales_dianaold");

//$result=mysqli_query($con,"select distinct(item_names) as ittm,dates,agent_names,item_ranges,sub_ranges,executive_names,regions,territory_names,sum(pcs_qty)as qty,sum(pcs_qty*packet_weights/1000) as tones,sum(pcs_qty*pcs_price)as grand_val from rd_saleinv where dates between '2021-12-01' and '2021-12-31' group by dates,item_ranges,item_names,regions,agent_names order by dates");

//Incentive-Target
$con=mysqli_connect("localhost","primarysales","S5L7lF01EQZvQrGK","primarysales_dianaold");
$result=mysqli_query($con,"select distinct(item_names) as ittm,agent_names,invoice_types,item_ranges,sub_ranges,executive_names,regions,regions,territory_names,agent_types,sum(box_qty)as qty,sum(box_qty*packets_per_box*packet_weights/1000000) as tones,sum(box_qty*box_price)as grand_val,invoice_types,invoice_types from rc_targets where dates between '2024-02-01' and '2024-02-31' group by item_ranges,item_names,regions,agent_names,territory_names order by dates");

//Incentive-Primary ASM
//$con=mysqli_connect("localhost","primarysales","S5L7lF01EQZvQrGK","primarysales_dianaold");
//
//$result=mysqli_query($con,"select distinct(item_names) as ittm,agent_names,invoice_types,item_ranges,sub_ranges,executive_names,regions,regions,territory_names,agent_types,sum(box_qty)as qty,sum(box_qty*packets_per_box*packet_weights/1000000) as tones,sum(box_qty*box_price)as grand_val,invoice_types,invoice_types from rc_invoices where dates between '2024-01-01' and '2024-01-31' group by item_ranges,item_names,regions,agent_names,territory_names order by dates");


//$result=mysqli_query($con,"select distinct(item_names) as ittm,dates,invoice_number,agent_names,itemcodes,item_ranges,sub_ranges,executive_names,box_price,regions,box_mrp,agent_types,sum(box_qty)as qty,sum(box_qty*packets_per_box*packet_weights/1000000) as tones,sum(box_qty*box_price)as grand_val,invoice_types,invoice_types from rc_invoices where dates between '2022-06-01' and '2022-07-31' group by invoice_number,item_ranges,itemcodes,regions,agent_names,dates order by dates");

//$con=mysqli_connect("localhost","primarysales","S5L7lF01EQZvQrGK","primarysales_dianaold");
//$result=mysqli_query($con,"select distinct(item_names) as ittm,agent_names,agent_names,agent_names,invoice_types,item_ranges,sub_ranges,executive_names,regions,regions,territory_names,agent_types,sum(pcs_qty)as qty,sum(pcs_qty) as tones,sum(box_qty*box_price)as grand_val,invoice_types,invoice_types from rc_invoices where dates between '2021-03-01' and '2021-03-31' group by item_ranges,item_names,regions,agent_names,territory_names order by dates");

print"<br>";
echo "<table >
<tr>
<!--<th>Date</th>
<th>Invoice</th>
<th>Voucher</th>-->
<th>Invoice</th>
<th>Agent</th>
<th>Status</th>
<th>Type</th>
<th>Range</th>
<th>Sub Range</th>
<th>Territory</th>
<th>Chanell</th>
<th>Region</th>
<th>Executive</th>
<th>Item</th>
<!--<th>Target Qty</th>-->
<!--<th>Primary Qty</th>-->
<!--<th>Rd Qty</th>-->
<!--<th>Target Value</th>-->
<th>Units</th>
<th>free</th>
<th>tot-rd</th>
<th>Price</th>
<th>M-Tons</th>
<th>Primary Value</th>
<!--<th>Rd Value</th>-->
<!--<th>Stock Units</th>-->
</tr>";

while($row = mysqli_fetch_array($result)) {

##$id=$row['agent_names']; 
//echo "<td>" . $row['dates'] . "</td>";
echo "<td>" . $row['invoice_number'] . "</td>";
//echo "<td>" . $row['dates'] . "</td>";
echo "<td>" . $row['agent_names'] . "</td>";
echo "<td>" . $row['itemcodes'] . "</td>";
echo "<td>" . $row['agent_types'] . "</td>";
echo"<td>" .$row['item_ranges']."</td>";
echo"<td>" .$row['sub_ranges']."</td>";
echo "<td>" . $row['box_mrp'] . "</td>";
echo "<td>" . $row['box_price'] . "</td>";
echo "<td>" . $row['regions'] . "</td>";
echo "<td>"  . $row['executive_names'] . "</td>";
echo "<td>" . $row['ittm'] . "</td>";
##echo "<td>" . $row['mitems'] . "</td>";
##echo "<td>" . $row['tgvl'] . "</td>";
echo "<td>" . number_format($row['qty'],4, '.', ',') . "</td>";
echo "<td>" . number_format($row['free'],4, '.', ',') . "</td>";
echo "<td>" . number_format($row['qty']+$row['free'],4, '.', ',') . "</td>";
echo "<td>" . number_format($row['pricee'],4, '.', ',') . "</td>";
echo "<td>" . number_format($row['tones'],4, '.', ',') . "</td>";
##echo "<td>" . number_format($row['tgwt'],2, '.', ',') . "</td>";
##echo "<td>" . number_format($row['acwt'],2, '.', ',') . "</td>";
##echo "<td>" . number_format($row['rdvl'],2, '.', ',') . "</td>";
##echo "<td>" . number_format($row['volum'],2, '.', ',') . "</td>";
##echo "<td>" . number_format($row['tgwt'],2, '.', ',') . "</td>";
echo "<td>" . number_format($row['grand_val'],2, '.', ',') . "</td>";

##echo "<td>"  . number_format(($row['tgvl'] + $row['acvl']-$row['rdqt']),0, '.', ',') ."</td>";
echo "</tr>";
}
echo "</table>";

mysqli_close($con);
?>

