Im trying to generate a DataTable of the list of Payables from the database using PDO and JQuery AJAX But i keep encountering this error on my PHP File. Im not sure whats wrong with my code.
The error message says:
[28-Jun-2016 16:33:12 Asia/Manila] PHP Notice: Trying to get property of non-object in ** on line 121
Line 121 in pay_controller.php is:
if($allPayList->res == 0) { echo ""; }
This is the pay_controller.php
<?PHP
class PayController {
public function pay() {
if (empty($_GET['sid']))
return call('home', 'expire');
$getSessionData = SessionData::getData($_GET['sid']);
if($getSessionData->res = 0)
{
return call('home', 'expire');
}
date_default_timezone_set('Asia/Manila');
$dtnow = date('Y-m-d H:i:s');
$sexpire = date('Y-m-d H:i:s', strtotime($getSessionData->ssend));
if($sexpire < $dtnow)
{
return call('home', 'expire');
}
$getMenu = MENU::getMenu();
$menuid = 3;
require_once('views/pay.php');
}
public function currentpay() {
$curPayList = Payables::getCurrentPayable();
echo "
<div class='col-md-12'>
<table id='currentpay' class='display' cellspacing='0' width='100%'>
<thead>
<tr>
<th>Sequence</th>
<th>Date</th>
<th>Vendor</th>
<th>Reference No.</th>
<th class='text-right'>Amount</th>
<th>Action</th>
</tr>
</thead>
<tbody>
";
if($curPayList->res == 0) {
echo "";
}
elseif($curPayList->res == 1) {
echo "<tr>
<td>" . $curPayList->seq . "</td>
<td>" . $curPayList->pdate . "</td>
<td>" . $curPayList->vendor . "</td>
<td>" . $curPayList->refno . "</td>
<td class='text-right'>" . number_format($curPayList->amount,2) . "</td>
<td>
<a OnClick='showCurPayDetails(". $curPayList->seq .")' class='btn btn-sm btn-default'>
<span class='fa-stack fa-fw'>
<i class='fa fa-square-o fa-stack-2x'></i>
<i class='fa fa-eye fa-stack-1x'></i>
</span>
VIEW DETAILS
</a>
</td>
</tr>";
}
elseif($curPayList->res > 1) {
foreach($curPayList as $cPL) {
echo "<tr>
<td>" . $cPL->seq . "</td>
<td>" . $cPL->pdate . "</td>
<td>" . $cPL->vendor . "</td>
<td>" . $cPL->refno . "</td>
<td class='text-right'>" . number_format($cPL->amount,2) . "</td>
<td>
<a OnClick='showCurPayDetails(". $cPL->seq .")' class='btn btn-sm btn-default'>
<span class='fa-stack fa-fw'>
<i class='fa fa-square-o fa-stack-2x'></i>
<i class='fa fa-eye fa-stack-1x'></i>
</span>
VIEW DETAILS
</a>
</td>
</tr>";
}
}
echo "
</tbody>
</table>
</div>
";
}
public function allpay() {
$allPayListing = Payables::getAllPurchase();
echo "
<div class='col-md-12'>
<table id='allpay' class='display' cellspacing='0' width='100%'>
<thead>
<tr>
<th>Sequence</th>
<th>Date</th>
<th>Vendor</th>
<th>Reference No.</th>
<th class='text-right'>Amount</th>
<th>Action</th>
</tr>
</thead>
<tbody>
";
if($allPayListing->res == 0) {
echo "";
}
elseif($allPayListing->res == 1) {
echo "<tr>
<td>" . $allPayList->seq . "</td>
<td>" . $allPayList->pdate . "</td>
<td>" . $allPayList->vendor . "</td>
<td>" . $allPayList->refno . "</td>
<td class='text-right'>" . number_format($allPayList->amount,2) . "</td>
<td>
<a OnClick='showCurPayDetails(". $allPayList->seq .")' class='btn btn-sm btn-default'>
<span class='fa-stack fa-fw'>
<i class='fa fa-square-o fa-stack-2x'></i>
<i class='fa fa-eye fa-stack-1x'></i>
</span>
VIEW DETAILS
</a>
</td>
</tr>";
}
elseif($allPayListing->res > 1) {
foreach($allPayListing as $aPL) {
echo "<tr>
<td>" . $aPL->seq . "</td>
<td>" . $aPL->pdate . "</td>
<td>" . $aPL->vendor . "</td>
<td>" . $aPL->refno . "</td>
<td class='text-right'>" . number_format($aPL->amount,2) . "</td>
<td>
<a OnClick='showCurPayDetails(". $aPL->seq .")' class='btn btn-sm btn-default'>
<span class='fa-stack fa-fw'>
<i class='fa fa-square-o fa-stack-2x'></i>
<i class='fa fa-eye fa-stack-1x'></i>
</span>
VIEW DETAILS
</a>
</td>
</tr>";
}
}
echo "
</tbody>
</table>
</div>
";
}
public function error() {
require_once('404.php');
}
public function expire(){
require_once('expire.php');
}
}
?>
And this is the mod_pay.php
<?PHP
class Payables {
public $seq;
public $pdate;
public $vendor;
public $refno;
public $amount;
public $res;
public function __construct($seq, $pdate, $vendor, $refno, $amount, $res) {
$this ->seq = $seq;
$this ->pdate = $pdate;
$this ->vendor = $vendor;
$this ->refno = $refno;
$this ->amount = $amount;
$this ->res = $res;
}
public static function getCurrentPayable() {
$db = Db::getInstance();
$currentPay = $db->prepare('SELECT
payables.seq AS seq,
payables.purdate AS pdate,
companies.compname AS vendor,
payables.refno AS refno,
payables.balance AS amount
FROM
payables
LEFT JOIN
companies
ON
companies.seq = payables.vendor
WHERE
payables.paidstatus = 0
');
switch($currentPay->execute())
{
case True:
$currentPayResCount = $currentPay->rowCount();
if($currentPayResCount == 0) {
$currentPayList = new Payables(NULL,NULL,NULL,NULL,NULL,0);
}
elseif($currentPayResCount == 1) {
$currentPayRes = $currentPay->fetch();
$currentPayList = new Payables($currentPayRes['seq'], $currentPayRes['pdate'], $currentPayRes['vendor'], $currentPayRes['refno'], $currentPayRes['amount'], $currentPayResCount);
}
elseif($currentPayResCount > 1) {
$currentPayRes = $currentPay->fetchAll();
foreach($currentPayRes as $cPR) {
$currentPayList[] = new Payables($cPR['seq'], $cPR['pdate'], $cPR['vendor'], $cPR['refno'], $cPR['amount'], $currentPayResCount);
}
}
return $currentPayList;
break;
case False:
$currentPayList = new Payables(NULL,NULL,NULL,NULL,NULL,0);
return $currentPayList;
break;
}
}
public static function getAllPurchase() {
$db = Db::getInstance();
$allPayables = $db->prepare('SELECT
payables.seq AS seq,
payables.purdate AS pdate,
companies.compname AS vendor,
payables.refno AS refno,
payables.balance AS amount
FROM
payables
LEFT JOIN
companies
ON
companies.seq = payables.vendor
');
switch($allPayables->execute())
{
case True:
$allPayResCount = $allPayables->rowCount();
if($allPayResCount == 0) {
$allPayList = new Payables(NULL,NULL,NULL,NULL,NULL,0);
}
elseif($allPayResCount == 1) {
$allPayRes = $allPayables->fetch();
$allPayList = new Payables($allPayRes['seq'], $allPayRes['pdate'], $allPayRes['vendor'], $allPayRes['refno'], $allPayRes['amount'], $allPayResCount);
}
elseif($allPayResCount > 1) {
$allPayRes = $allPayables->fetchAll();
foreach($allPayRes as $aPR) {
$allPayList[] = new Payables($aPR['seq'], $aPR['pdate'], $aPR['vendor'], $aPR['refno'], $aPR['amount'], $allPayResCount);
}
}
return $allPayList;
break;
case False:
$allPayList = new Payables(NULL,NULL,NULL,NULL,NULL,0);
return $allPayList;
break;
}
}
}
?>
Note: I'm duplicating the getCurrentPayable()
function which does not return an error. It returns 1 result. getAllPurchase()
should return 2.
Edit: I included the entire file. Edit: I edited it to reflect the recent changes I've made and it still showing the same error.