Files
digifi-mware/app/Controllers/Loan.php
T
CHIEFSOFT\ameye 176edc74d5 loan data
2024-09-03 17:40:12 -04:00

194 lines
6.8 KiB
PHP

<?php
namespace App\Controllers;
use CodeIgniter\API\ResponseTrait;
use PHPUnit\Util\Json;
class Loan extends BaseController
{
use ResponseTrait;
var $request;
function __construct()
{
$this->request = \Config\Services::request();
}
public function addPaymentCard(){
$result =[];
return $this->respond($result, 200);
}
public function loanProcess(){
// $get_param = $_GET ?? null;
$uriSegments = explode("/", parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
$segLen = count($uriSegments);
$application_uid = $uriSegments[$segLen -1];
// $this->$segLen
$employerQr = "SELECT * FROM applications WHERE uid::text = '".$application_uid."' ";
log_message('error', "employerQr -->" . $employerQr);
$query = $this->db->query( $employerQr);
$application = $query->getResult('array');
$sqlV = "SELECT * FROM employer_checks WHERE application_uid::text ='".$application_uid."' ORDER BY id DESC LIMIT 1";
log_message('error', "employerQr -->" . $employerQr);
$query = $this->db->query( $sqlV);
$verification = $query->getResult('array');
$result =[
"application_uid" => $application_uid,
"application" => $application,
"verification" => $verification
];
return $this->respond($result, 200);
}
public function loanApply(){
/*
uid uuid,
loan_amount INT DEFAULT 0,
payment_month INT DEFAULT 0,
sales_agent VARCHAR(50),
gender VARCHAR(20),
marital_status VARCHAR(20),
email VARCHAR(100),
address VARCHAR(150),
state VARCHAR(50),
country VARCHAR(3),
loan_detail TEXT,
*/
// header('Access-Control-Allow-Origin: "*" ');
//header("Access-Control-Allow-Headers: Origin, X-API-KEY, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method, Access-Control-Allow-Headers, Authorization, observe, enctype, Content-Length, X-Csrf-Token");
// log_message('critical', "0003");
// header("Access-Control-Allow-Methods: GET, PUT, POST, DELETE, PATCH, OPTIONS");
// header("Access-Control-Allow-Credentials: true");
// header("Access-Control-Max-Age: 3600");
// header('content-type: application/json; charset=utf-8');
$data = $this->request->getPost();
try {
$json_data =json_encode($data);
$serialize_data=serialize($data);
/*
*employment
loan_reference
disbursement
*/
// $data2 =json_decode($data);
//log_message('error', "JSON -->" . $json_data);
log_message('error', "BEFORE THE LOG -->");
log_message('error', "UID2---=>" . $data["customer_uid"]);
log_message('error', "UID2-employment--=>" . serialize( $data["employment"]));
log_message('error', "UID2-loan_reference--=>" . serialize( $data["loan_reference"]));
log_message('error', "UID2-disbursement--=>" . serialize( $data["disbursement"]));
log_message('error', "UID3-employment--=>" . serialize( $data->employment));
log_message('error', "UID3-loan_reference--=>" . serialize( $data->loan_reference));
log_message('error', "UID3-disbursement--=>" . serialize( $data->disbursement));
// log_message('error', "UID3---=>" . $data2->customer_uid);
// log_message('error', "UID4---=>" . $data2["customer_uid"]);
log_message('error', "---------------------------------------------------------------->");
log_message('error', "SERIALIZE -->" . $serialize_data);
log_message('error', "---------------------------------------------------------------->");
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
//employer_uid
$verified_employer = false;
if ( $data['employer_uid'] != '') {
$employerQr = "SELECT * FROM employers WHERE uid ='".$data['employer_uid']."'";
log_message('error', "employerQr -->" . $employerQr);
$query = $this->db->query( $employerQr);
$row = $query->getResult('array');
if (isset($row))
{
$verified_employer = true;
}
}
$addedData =[];
if (
$data['customer_uid'] != '' &&
$data['loan_amount'] != '' &&
$data['payment_month'] != '' &&
$data['sales_agent'] != '' &&
$data['marital_status'] != '' &&
$data['email'] != '' &&
$data['address'] != '' &&
$data['state'] != '' &&
$data['country'] != '' &&
$data['disbursement_account'] != ''
) {
$udata = [
'customer_uid' => $data['customer_uid'],
'loan_amount' => $data['loan_amount'],
'payment_month' => $data['payment_month'],
'sales_agent' => $data['sales_agent'],
'marital_status' => $data['marital_status'],
'email' => $data['email'],
'address' => $data['address'],
'state' => $data['state'],
'country' => $data['country'],
'employer_uid' => $data['employer_uid'],
'disbursement_account' => $data['disbursement_account'],
'loan_detail' => json_encode($data)
];
if( $verified_employer == true ){
$udata['status'] = 2;
}
$addedData = $this->insert_db('applications', $udata);
}
return $this->respond($addedData, 200);
}
public function loanlist(){
return $this->respond([], 200);
}
public function loanDetail(){
$in = $this->request->getGet();
$data = [];
$mysql ="SELECT * FROM applications WHERE customer_uid = '". $in["uid"]."' AND uid='". $in["application_uid"]."' ";
$query = $this->db->query($mysql);
$row = $query->getRowArray();
$row["loan_detail"] = json_decode( $row["loan_detail"] ); // "ameye";
//$row["loan_detail"]["employment"] = json_decode( $row["loan_detail"]["employment"] );
$employment_line = json_decode( $row["loan_detail"]->employment ); //["employment"] ;
$row["employment"] = $employment_line ; // json_decode( $row["loan_detail"]["employment"] );
$loan_reference_line = json_decode( $row["loan_detail"]->loan_reference );
$row["loan_reference"] = $loan_reference_line ;
$disbursement_line = json_decode( $row["loan_detail"]->disbursement );
$row["disbursement"] = $disbursement_line ;
return $this->respond(["loan"=>$row], 200);
}
public function startProcessing(){
return [];
}
}