<?php 
include_once("../../lib/authentication.php"); 
$MySQLi= new MySQLi($server, $user_apma, $pass_apma, $db_apma); 
$query="SELECT SUM(IF(DETAIL.stsAktif=1, DETAIL.iPembayaran, 0)) AS iTotal, 
               KASBANKGIRO.iDebit, 
               HUTANGPIUTANG.strKode, 
               HUTANGPIUTANG.dtTransaksi, 
               USER.strNama 
        FROM a_transaksi_hutangpiutang AS HUTANGPIUTANG 
        LEFT JOIN a_transaksi_hutangpiutang_detail AS DETAIL 
        ON HUTANGPIUTANG.ID = DETAIL.transaksi_hutangpiutang_ID 
        INNER JOIN a_muser AS USER 
        ON HUTANGPIUTANG.muser_id = USER.ID 
        INNER JOIN a_transaksi_kasbankgiro AS KASBANKGIRO 
        ON HUTANGPIUTANG.transaksi_kasbankgiro_ID =KASBANKGIRO.ID 
        WHERE HUTANGPIUTANG.stsAktif=1 AND 
              HUTANGPIUTANG.strKode like 'PYM%'
        GROUP BY HUTANGPIUTANG.strKode";
$result=$MySQLi->query($query);
$errorCount=0; 
$stringBuffer="";
while($row=$result->fetch_array())
{ 
    $iTotalKasBankGiro=$row['iDebit']; 
    $iTotal=$row['iTotal']; 
    $iSisa=$iTotalKasBankGiro-$iTotal; 
    if(number_format($iSisa,2)>0)
    {
        $errorCount=$errorCount+1;
        $stringBuffer=$stringBuffer.$row['strKode']."<br>";
	}
}
echo $errorCount;
echo $stringBuffer;
?>
