<?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');




$uniquedid = $_REQUEST['uniquedid'];

if ($uniquedid == '') {
    $uniquedid = '0';
}


$where = "tbl_transaction.id>0  and tbl_transaction.uniquedid='$uniquedid'   and tbl_transaction.Received>0 ";
















$data = findQuery("SELECT tbl_transaction.customerid,tbl_transaction.Transid,tbl_transaction.id,tbl_transaction.dateadded orderedtime,tbl_customer.name,tbl_ward.ward_name,tbl_panchayat.panchayat_name,tbl_assembly.name assembly,tbl_panchayat.id panchayatid,tbl_transaction.donation,tbl_transaction.sponsorship,
    tbl_district.district_name,tbl_transaction.Received,MONTHNAME(tbl_transaction.dateadded) month,day(tbl_transaction.dateadded) day,tbl_transaction.volunteer,tbl_ward.id wardid,tbl_transaction.clubid
     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++) {
        $status = 'Paid';

        if ($data[$i]['wardid'] == 0) {
            $clubid                = $data[$i]['clubid'];
            $club                  = findQuery("SELECT * from tbl_club where id=$clubid");
            $data[$i]['ward_name'] = $club[0]['club_name'];
        }

        $data2[] = [



'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'],
'date'          => $data[$i]['orderedtime'],
'status'        => $status,
'donation'      => $data[$i]['donation'],
'sponsorship'   => $data[$i]['sponsorship'],
'Transactionid' => $data[$i]['Transid'] ? $data[$i]['Transid'] : 'NA',
];
    }
} else {
    $message = 'false';
    $data2[] = ['error' => 'Not Found'];
}



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

return;

?>

