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.

143 lines
6.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:950px; border:1px solid #000; padding:20px 0; margin-bottom:25px;}";
echo "table.tbl {width:800px;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:30px;}";
echo ".header{font-weight:bold;text-align:center;}";
echo ".isi{text-align:left;}";
echo "</style>";
$startDate = decTgl($_POST['jtTempo']);
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();
$ttJumlahTotalBon = 0;
$ttJumlahSaldoTitip = 0;
$ttJumlahNetSaldo = 0;
$ttJumlahBonLimit = 0;
print("<center><div id=\"divprint\" >");
print("<h2>Laporan Rekap Saldo Bon</h2><br/><br/>");
print("<div class=\"luar\">TOKO ".$_SESSION['namatoko']."<br/>");
print("Jatuh Tempo Tanggal : ".encTgl($startDate)."<br/>");
print("DICETAK TANGGAL : ".date('d-m-Y [H:i]')."<br/>");
print("<table border=\"1\" class=\"tbl\">");
print("<tr class=\"header\"><td>No.</td><td>Kode Plg</td><td>Nama</td><td>Alamat</td><td>Upline</td><td>Total Bon</td><td>Total Titip</td><td>Saldo Net Bon</td><td>Saldo Jth Tempo</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 m.status = 'B' and
(p2.upline = '$kdcust'
or p2.kd_customer = '$kdcust')
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')";
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;
$ttJumlah['nota'] = 0;
while(mysqli_stmt_fetch($stmt3)){
$ttJumlah['titip'] += $titip;
$ttJumlah['nota'] += $totNota;
$saldotitip = $ttJumlah['titip'] - $ttJumlah['nota'];
}
}else{
$saldotitip = 0;
}
}
$query4 = "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 m.status = 'B' and
(p2.upline = '$kdcust'
or p2.kd_customer = '$kdcust')
and date(m.tgl_bon) <= '$startDate'
group by p2.kd_customer";
if($stmt4 = mysqli_prepare($conn,$query4)){
mysqli_stmt_execute($stmt4);
mysqli_stmt_store_result($stmt4);
$cek4 = mysqli_stmt_num_rows($stmt4);
if($cek4 > 0){
mysqli_stmt_bind_result($stmt4,$total4);
$ttJumlah['bonlimit'] = 0;
while(mysqli_stmt_fetch($stmt4)){
$ttJumlah['bonlimit'] += $total4;
}
}else{
$ttJumlah['bonlimit'] = 0;
}
}
$netsaldo = $ttJumlah['totalbon']-$saldotitip;
if ($netsaldo != 0){
$urut ++;
print("<tr class=\"isi\"><td align=\"center\">$urut</td><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($saldotitip, 0, ",", ".")."</td>
<td align=\"right\">".number_format($netsaldo, 0, ",", ".")."</td>
<td align=\"right\">".number_format($ttJumlah['bonlimit'], 0, ",", ".")."</td></tr>");
$ttJumlahTotalBon += $ttJumlah['totalbon'];
$ttJumlahSaldoTitip += $saldotitip;
$ttJumlahNetSaldo += $netsaldo;
$ttJumlahBonLimit += $ttJumlah['bonlimit'];
}
}
print("<tr class=\"isi\"><td colspan=\"5\"></td>
<td align=\"right\">".number_format($ttJumlahTotalBon, 0, ",", ".")."</td>
<td align=\"right\">".number_format($ttJumlahSaldoTitip, 0, ",", ".")."</td>
<td align=\"right\">".number_format($ttJumlahNetSaldo, 0, ",", ".")."</td>
<td align=\"right\">".number_format($ttJumlahBonLimit, 0, ",", ".")."</td></tr>");
print("</table><br/>");
print("</table></div></div></center>");
}else{
echo "Data tidak ditemukan!";
}
}
}
?>