<script type="text/javascript">
    $(function() {
        $("#theList tr:even").addClass("stripe1");
        $("#theList tr:odd").addClass("stripe2");

        $("#theList tr").hover(
            function() {
                $(this).toggleClass("highlight");
            },
            function() {
                $(this).toggleClass("highlight");
            }
        );
    });
</script>

<?php
include '../../inc/inc.koneksi.php';
include '../../inc/fungsi_tanggal.php';

$tglawal	= $_GET['tglawal'];
$tglakhir	= $_GET['tglakhir'];
$kodecab   	= $_GET['kodecab'];

echo "<table id='theList' width='100%'>
	<tr>
		<th>No.</th>
		<th>Tanggal</th>
		<th>Jumlah Tunai</th>
	    <th>Jumlah Kredit</th>	
		<th>Jumlah EDC</th>
		<th>Jumlah QRIS</th>
		<th>Jumlah GRAB</th>
		<th>Chg. EDC/QRIS</th>
		<th>Jumlah Omset</th>
		<th>Harga Pokok</th>
		<th>Laba Kotor</th>
	</tr>";
	if($kodecab=='')
	    $sql1 = mysql_query("SELECT tanggal FROM faktur_pj WHERE tanggal BETWEEN '$tglawal' AND '$tglakhir' AND batal='' AND posting='P' GROUP BY tanggal");
	else
	    $sql1 = mysql_query("SELECT tanggal FROM faktur_pj WHERE tanggal BETWEEN '$tglawal' AND '$tglakhir' AND kode_cab='$kodecab' AND batal='' AND posting='P' GROUP BY tanggal");

	$tjual 	= 0;
	$ttunai	= 0;
	$tkredit= 0;
	$tedc	= 0;
	$tqris  = 0;
	$tgrab  = 0;
	$tcharge= 0;
	$thpp   = 0;
	$tbiaya = 0;
	$no		= 1;
	
	while($r1=mysql_fetch_array($sql1)){
		$tanggal= $r1['tanggal'];
		
		if($kodecab=='')
		    $sql= mysql_query("SELECT kode_pj,tanggal,sum(jumlah) as jjual,sum(hpp) as jhpp,jenis_by,charge_edc as jcharge,sum(bayar) as jbayar FROM faktur_pj WHERE tanggal='$tanggal' AND batal='' AND posting='P' GROUP BY kode_pj");
	    else
	        $sql= mysql_query("SELECT kode_pj,tanggal,sum(jumlah) as jjual,sum(hpp) as jhpp,jenis_by,charge_edc as jcharge,sum(bayar) as jbayar FROM faktur_pj WHERE tanggal='$tanggal' AND kode_cab='$kodecab' AND batal='' AND posting='P' GROUP BY kode_pj");
	        
		$sjual 	= 0;
		$stunai	= 0;
		$skredit= 0;
		$sedc	= 0;
		$sqris  = 0;
		$sgrab  = 0;
		$scharge= 0;
		$shpp   = 0;

		while($r=mysql_fetch_array($sql)){
			$sjual	= $sjual+$r['jjual']+$r['jcharge'];
			$jenisby= $r['jenis_by'];
			$jual   = $r['jjual'];
			$bayar  = $r['jbayar'];
			$scharge= $scharge+$r['jcharge'];
			$shpp   = $shpp+$r['jhpp'];
			
			if($jenisby=='EDC'){
		        $sedc	= $sedc+$jual-$potong;
		        $scharge= $scharge+$charge;
	        }else{
	            if($jenisby=='QRIS'){
		            $sqris  = $sqris+$jual-$potong;
		            $scharge= $scharge+$charge;
	            }else{
	                if($jenisby=='GRAB') $sgrab= $sgrab+$jual-$potong;
	                else $stunai = $stunai+$jual-$potong;
	            }
	        }
			$snota++;
		}
		$laba  = $sjual-$shpp;
		
		echo "<tr>
			<td align='center'>$no</td>
			<td>".jin_date_str($tanggal)."</td>
			<td align='right'>".number_format($stunai,0)."</td>
			<td align='right'>".number_format($skredit,0)."</td>
			<td align='right'>".number_format($sedc,0)."</td>
			<td align='right'>".number_format($sqris,0)."</td>
		    <td align='right'>".number_format($sgrab,0)."</td>
	        <td align='right'>".number_format($scharge,0)."</td>
			<td align='right'>".number_format($sjual,0)."</td>
			<td align='right'>".number_format($shpp,0)."</td>
			<td align='right'>".number_format($laba,0)."</td>
		</tr>";
		$tjual	= $tjual+$sjual;
		$ttunai	= $ttunai+$stunai;
		$tkredit= $tkredit+$skredit;
		$tedc 	= $tedc+$sedc;
		$tqris	= $tqris+$sqris;
		$tgrab	= $tgrab+$sgrab;
		$tcharge= $tcharge+$scharge;
		$thpp   = $thpp+$shpp;
		$no++;
	}
    $tlaba= $tjual-$thpp;
	
echo "<tr></tr>
	<tr>
		<td></td>
		<td>Total</td>
		<td align='right'>".number_format($ttunai,0)."</td>
		<td align='right'>".number_format($tkredit,0)."</td>
		<td align='right'>".number_format($tedc,0)."</td>
		<td align='right'>".number_format($tqris,0)."</td>
		<td align='right'>".number_format($tgrab,0)."</td>
	    <td align='right'>".number_format($tcharge,0)."</td>
		<td align='right'>".number_format($tjual,0)."</td>
		<td align='right'>".number_format($thpp,0)."</td>
		<td align='right'>".number_format($tlaba,0)."</td>
	</tr>
</table>";
?>