<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Headers: Content-Type');
require_once('../lib/dbclass.php');




$name = $_REQUEST['name'];


$where = 'tbl_transaction.id>0 and tbl_transaction.donation=1 and tbl_transaction.Received>0 ';




if ($name != '') {
    $where .= " and (tbl_customer.name like '%$name%' or tbl_customer.Mobile like '%$name%') ";
}











$data = findQuery("SELECT tbl_transaction.customerid,tbl_transaction.hideidendity,tbl_transaction.id,DATE_FORMAT(tbl_transaction.dateadded,'%H:%i:%s')orderedtime,tbl_customer.name,tbl_ward.ward_name,tbl_panchayat.panchayat_name,tbl_assembly.name assembly,tbl_panchayat.id panchayatid,
    tbl_district.district_name,tbl_transaction.Received,MONTHNAME(tbl_transaction.dateadded) month,day(tbl_transaction.dateadded) day
     from tbl_transaction
     inner join tbl_customer on tbl_customer.id=tbl_transaction.customerid inner join tbl_ward on tbl_ward.id=tbl_customer.Ward inner join tbl_panchayat on tbl_panchayat.id=tbl_customer.Panchayat
    inner join tbl_assembly on tbl_assembly.id=tbl_customer.Assembly 
    inner join tbl_district on tbl_district.id=tbl_customer.District where  $where order by tbl_transaction.id desc 
    
    
    
    
    
    
    
    
    
   ");

if ($data) {
    $message = 'true';
    for ($i = 0;$i < count($data);$i++) {
        $fullypaid = 0;

        if ($data[$i]['Received'] > 0) {
            $fullypaid = 1;
        }

        if ($data[$i]['hideidendity'] == 1) {
            $data[$i]['name'] = 'xxxxxxxxxx';
        }

        $data2[] = [


'customerid'    => $data[$i]['customerid'],
'name'          => $data[$i]['name'],
'ward'          => $data[$i]['ward_name'],
'panchayat'     => $data[$i]['panchayat_name'],
'assembly'      => $data[$i]['assembly'],
'district'      => $data[$i]['district_name'],
'amount'        => $data[$i]['Received'],
'month'         => $data[$i]['month'],
'day'           => $data[$i]['day'],
'time'          => $data[$i]['orderedtime'],
'id'            => $data[$i]['id'],
'fullypaid'     => $fullypaid,
'canchangeward' => 1,
'panchayatid'   => $data[$i]['panchayatid'],
'receiptname'   => $data[$i]['name'],
];
    }
} else {
    $message = 'false';
    $data2[] = ['error' => 'Not Found'];
}



echo json_encode(['Status' => $message, 'data' => $data2]);

return;

?>

