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

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

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

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

// $date1=date('Y-m-d',strtotime($_GET['date1']));
// $date2=date('Y-m-d',strtotime($_GET['date2']));
$date1=$_GET['date1'];
$date2=$_GET['date2'];
$kodecab=$_GET['kodecab'];
// echo date('Y-m-d',strtotime($_GET['date1']))."<br>";
// echo date('Y-m-d',strtotime($_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 tgl_rec,notrans_link,tag_bayar,nohp,item_desc,harga_jual,custname,harga_beli,item_code,disc_val,harga_jual-disc_val as jualdisc from Trans1sub  where date(tgl_rec)>='".date('Y-m-d',strtotime($date1))."' and date(tgl_rec)<='".date('Y-m-d',strtotime($date2))."'  and typetrans='OT'   " ; 

$sql2 = "SELECT sum((a.harga_jual*a.qty)-a.disc_val) as omzet,sum((a.harga_jual*a.qty)-a.disc_val)-sum((a.harga_beli*a.qty)-a.disc_val) as laba,sum(b.qtyreturn) as qtyreturn FROM Trans1sub a left join (select idno_link,item_code,sum(qty*harga_jual) as qtyreturn from Trans1ret group by idno_link,item_code ) b on a.idno=b.idno_link and a.item_code=b.item_code   where date(a.tgl_rec)>='".date('Y-m-d',strtotime($date1))."' and date(a.tgl_rec)<='".date('Y-m-d',strtotime($date2))."' and a.kode_cabang='".$kodecab."' and a.kode_cabang='$kodecab' and a.typetrans='OT'  order by a.idno desc" ; 

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

$res = mysqli_query($conn, $sql);
$resx = mysqli_query($conn, $sql);
$resx2=mysqli_fetch_row($resx);
 

echo "<table>";
echo "<tr><td id='tdh'>Transaksi Detail By Date</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'>";
echo "<th id='th1'>Tanggal</th><th id='th1'>No.Nota</th><th id='th1'>Tipe Bayar</th><th id='th1'>No WA</th><th id='th1'>Nama Product</th><th id='th1'>Harga Jual</th><th id='th1'>Harga Jual after Disc.</th><th id='th1'>Disc Val</th>";

if($res === false) {
  echo "error while executing mysql: " . mysqli_error($conn);
}
 
 while($row = mysqli_fetch_row($res))
 
 {

echo "<tr><td id='td2'>".date('d-m-Y',strtotime($row[0]))."</td><td id='td2'>".$row[1]."</td><td id='td2'>".$row[2]."</td><td  id='td2'>".$row[3]."(".$row[6].")</td><td id='td2'>".$row[4]." (".$row[8].")</td><td id='td2' align='right'>".number_format($row[5],2)."</td><td id='td2' align='right'>".number_format($row[10],2)."</td><td id='td2' align='right'>".number_format($row[9],2)."</td></tr>";  
     
 }
 //echo "<tr><td>Total </td><td align='right' id='td1' >".number_format($row2[0],2)."</td><td align='right' id='td1'> ".number_format($row2[1],2)."</td><td align='right' id='td1'> ".number_format($row2[2],2)."</td></tr>";
 
   
   
 
 

 
mysqli_close($conn);
 
?>
