<style type='text/css'>
#th1{
background-color:blue;    
color:white;
font-weight:bold;
padding:5px;
font-size:8px;
    
}   

#td1{
background-color:black;    
color:white;
font-weight:bold;
padding:5px;
}   
   
#td2{
color:black;
padding:5px;
}   

#td12{
color:white;
padding:5px;
background-color:blue;
}  

#tdh{
color:black;
font-weight:bold;
 
} 
</style>

<?php
 
include 'dbconfig.php';
 
// Create connection

$date1=$_GET['date1'];
$date2=$_GET['date2'];

//echo $notrans;
 
$conn = mysqli_connect($servername, $username, $password, $dbname);
 
// Check connection
 
if (!$conn) {
 
    die("Connection failed: " . mysqli_connect_error());
 
}
 
$sql3="select * from toko_profile";
$res3 = mysqli_query($conn, $sql3);
$row3 = mysqli_fetch_row($res3);
$dateok=date('d-m-Y',strtotime(tgl_rec));
 
$sql = "


SELECT 'A' as grp, date_format(tgl_rec,'%d-%m-%Y') ,notrans_link,item_code,item_desc,0,0,0 FROM Trans1sub where date(tgl_rec)>='".$date1."'"." and date(tgl_rec)<='".$date2."'  group by notrans_link,item_code,item_desc,harga_jual,harga_beli 
union all
SELECT 'B' as grp, date_format(tgl_rec,'%d-%m-%Y') ,notrans_link,item_code,item_desc,0,0,0 FROM Trans1sub where date(tgl_rec)>='".$date1."'"." and date(tgl_rec)<='".$date2."'  group by notrans_link,item_code,item_desc,harga_jual,harga_beli 
union all
SELECT  'C' as grp, date_format(tgl_rec,'%d-%m-%Y') ,notrans_link,item_code,item_desc,sum(qty),harga_jual,harga_beli FROM Trans1sub where date(tgl_rec)>='".$date1."'"." and date(tgl_rec)<='".$date2."'  group by notrans_link,item_code,item_desc,harga_jual,harga_beli order by notrans_link,item_code,item_desc,grp asc" ; 
/*
$sql2 = "SELECT sum(harga_jual*qty)-sum(disc_val) as totrp,sum(disc_val) as discount FROM Trans1sub  where date(tgl_rec)>='".$date1."'"." and date(tgl_rec)<='".$date2."'  order by idno desc" ;  

$res2 = mysqli_query($conn, $sql2);
$row2 = mysqli_fetch_row($res2);*/

$res = mysqli_query($conn, $sql);
echo "<table>";
echo "<tr><td id='tdh'>Omzet By Transaksi</td></tr>";
echo "<tr><td id='tdh'>Date : ".date('d-M-Y',strtotime($date1))." To ".date('d-M-Y',strtotime($date2))."</td></tr>";
echo "</table>";
echo "<br>";
echo "<table border='1'>";


if($res === false) {
  echo "error while executing mysql: " . mysqli_error($conn);
}
 
 while($row = mysqli_fetch_row($res))
 
 {
  
 if ($row[0]=='A')
 {
     
 echo "<tr><td id='td12' colspan='3'>Tanggal/No Transaksi :".$row[1]." / ".$row[2]."</td></tr>";  

 }elseif ($row[0]=='B'){
     
  echo "<tr><td id='td12' colspan='3'>".$row[3]." / ".$row[4]."</td></tr>";    
 }else

{ 
    echo "<th id='th1'>Qty</th><th id='th1'>Harga Jual</th><th id='th1'>Sub Total</th>";
echo "<tr><td align='right' id='td2'>".number_format($row[5],2)."</td><td align='right' id='td2'>".number_format($row[6],2)."</td><td align='right' id='td2'>".number_format($row[6]*$row[5],2)."</td></tr>"; 
 echo "<tr><td colspan='4'></td></tr>";
     
}
     
 }
 
 
   
   
 
 

 
mysqli_close($conn);
 
?>
