You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
4.2 KiB
PHP

<?php
include "../func_lib.php";
session_start();
if($_SESSION['validUser'] !== TRUE)
{
header("location: ./index.php");
exit();
}
echo "<style type='text/css'>";
echo "div#divprint{width:900px; border:1px solid #000; padding:20px 0; margin-bottom:25px;}";
echo "table.tbl {width:750px;border-width:0 0 1px 1px;border-spacing:0;border-collapse:collapse;font-size:9pt;text-align:center;}";
echo "table.tbl,table.tbl td {border-color:#000;border-style:solid;}";
echo "table.tbl td {margin:0;padding:2px;border-width:1px 1px 0 0;}";
echo "body {font-size:9pt;}";
echo "div.luar{text-align:left;margin-left:50px;}";
echo ".header{font-weight:bold;text-align:center;}";
echo ".isi{text-align:left;}";
echo "</style>";
$startDate = decTgl($_POST['startDate']);
$endDate = decTgl($_POST['endDate']);
if(bukaKoneksi()){
global $conn;
$query = "select p.kd_customer,p.nama,p.alamat,p.upline from pelanggan p where p.upline = '#'";
if($stmt = mysqli_prepare($conn,$query)){
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
$cek = mysqli_stmt_num_rows($stmt);
if($cek > 0){
mysqli_stmt_bind_result($stmt,$kdcust,$nama,$alamat,$upline);
$ttJumlah = array();
print("<center><div id=\"divprint\" >");
print("<h2>Laporan Rekap Saldo Bon Per Periode</h2><br/><br/>");
print("<div class=\"luar\">TOKO ".$_SESSION['namatoko']."<br/>");
print("Periode Bon Tanggal : ".encTgl($startDate)." s/d ".encTgl($endDate)."<br/>");
print("DICETAK TANGGAL : ".date('d-m-Y [H:i]')."<br/><br/>");
print("<table border=\"1\" class=\"tbl\">");
print("<tr class=\"header\"><td>Kode Plg</td><td>Nama</td><td>Alamat</td><td>Upline</td><td>Total Bon</td><td>Total Titip</td></tr>");
while(mysqli_stmt_fetch($stmt)){
$query2 = "select sum(m.jumlah_total)
from pelanggan p2 force index (primary,upline), m_bon m force index (kd_plg)
where p2.kd_customer = m.kode_plg and
(p2.upline = '$kdcust' or p2.kd_customer = '$kdcust')
and date(m.tgl_bon) BETWEEN '$startDate' and '$endDate'
group by p2.kd_customer";
if($stmt2 = mysqli_prepare($conn,$query2)){
mysqli_stmt_execute($stmt2);
mysqli_stmt_store_result($stmt2);
$cek2 = mysqli_stmt_num_rows($stmt2);
if($cek2 > 0){
mysqli_stmt_bind_result($stmt2,$total);
$ttJumlah['totalbon'] = 0;
while(mysqli_stmt_fetch($stmt2)){
$ttJumlah['totalbon'] += $total;
}
}else{
$ttJumlah['totalbon'] = 0;
}
}
$query3 = "select m.jumlah_total,t.bayar_bon
from pelanggan p force index (primary,upline),bayar_bon t left join m_bon m on (t.no_bon = m.no_bon)
where t.kd_plg = p.kd_customer
and (t.kd_plg = '$kdcust' or p.upline = '$kdcust')
and date(t.tgl_byr) between '$startDate' and '$endDate'";
if($stmt3 = mysqli_prepare($conn,$query3)){
mysqli_stmt_execute($stmt3);
mysqli_stmt_store_result($stmt3);
$cek3 = mysqli_stmt_num_rows($stmt3);
if($cek3 > 0){
mysqli_stmt_bind_result($stmt3,$totNota,$titip);
$ttJumlah['titip'] = 0;
while(mysqli_stmt_fetch($stmt3)){
$ttJumlah['titip'] += $titip;
}
}else{
$ttJumlah['titip'] = 0;
}
}
if ($ttJumlah['totalbon'] != 0){
print("<tr class=\"isi\"><td align=\"center\">$kdcust</td><td>$nama</td><td>$alamat</td><td align=\"center\">$upline</td><td align=\"right\">".number_format($ttJumlah['totalbon'], 0, ",", ".")."</td><td align=\"right\">".number_format($ttJumlah['titip'], 0, ",", ".")."</td></tr>");
}
}
print("</table><br/>");
print("</table></div></div></center>");
}else{
echo "Data tidak ditemukan!";
}
}
}
?>