244 lines
9.8 KiB
PHP
244 lines
9.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['marital_status'] != '' &&
|
|
$data['email'] != '' &&
|
|
$data['address'] != '' &&
|
|
$data['state'] != '' &&
|
|
$data['country'] != '' &&
|
|
$data['disbursement_account'] != ''
|
|
) {
|
|
$sales_agent = $data['sales_agent'] ?? '-None-';
|
|
$udata = [
|
|
'customer_uid' => $data['customer_uid'],
|
|
'loan_amount' => $data['loan_amount'],
|
|
'payment_month' => $data['payment_month'],
|
|
'sales_agent' => $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);
|
|
|
|
log_message('error', "addedData Call UID ---=> ". $addedData["uid"] );
|
|
|
|
if ( isset($addedData["uid"])){
|
|
try {
|
|
$application_uid = $addedData["uid"];
|
|
$this->coreVerifyEmployerMessage($application_uid);
|
|
} catch (Exception $e) {
|
|
//echo 'Caught exception: ', $e->getMessage(), "\n";
|
|
log_message('error', "Application Call Error---=> ". $e->getMessage());
|
|
}
|
|
|
|
/*
|
|
* {
|
|
"id": "44",
|
|
"uid": "c8edebf8-16f6-45f9-98a0-2781199373e9",
|
|
"customer_uid": "47edd3f0-ab1b-4ede-86d7-e41388cdee62",
|
|
"loan_amount": "350000",
|
|
"payment_month": "12",
|
|
"sales_agent": "",
|
|
"gender": null,
|
|
"marital_status": "married",
|
|
"email": "ameye@chiefsoft.com",
|
|
"address": "4201 defoors farm trail",
|
|
"state": "akwa ibom",
|
|
"country": "NG",
|
|
"loan_detail": "{\"customer_uid\":\"47edd3f0-ab1b-4ede-86d7-e41388cdee62\",\"loan_amount\":\"350000\",\"payment_month\":\"12\",\"sales_agent\":\"\",\"gender\":\"female\",\"address\":\"4201 defoors farm trail\",\"marital_status\":\"married\",\"state\":\"akwa ibom\",\"email\":\"ameye@chiefsoft.com\",\"country\":\"NG\",\"employer_uid\":\"3a9ec95a-090c-4c98-bc01-e96d76b93952\",\"employment\":\"{\\\"job_title\\\":\\\"Main Developer\\\",\\\"name\\\":\\\"\\\",\\\"sector\\\":\\\"\\\",\\\"industry\\\":\\\"\\\",\\\"resumption_date\\\":\\\"2024-01-02\\\",\\\"email\\\":\\\"\\\",\\\"annual_income\\\":\\\"46464\\\",\\\"monthly_salary\\\":\\\"747477\\\",\\\"salary_payment_date\\\":\\\"2025-01-01\\\",\\\"employment_id\\\":\\\"75758559990\\\",\\\"highest_eductaion\\\":\\\"b.sc + professional qualification\\\",\\\"isChecked\\\":false}\",\"loan_reference\":\"[{\\\"fullname\\\":\\\"Olu Amey\\\",\\\"relationship\\\":\\\"Ma\\\",\\\"phone_number\\\":\\\"6784574356\\\",\\\"email\\\":\\\"ameye@chiefsoft.com\\\",\\\"bvn\\\":\\\"75758559991\\\"},{\\\"fullname\\\":\\\"Olu\\\",\\\"relationship\\\":\\\"Seld\\\",\\\"phone_number\\\":\\\"6784574399\\\",\\\"email\\\":\\\"works@chiefsoft.com\\\",\\\"bvn\\\":\\\"75758559990\\\"}]\",\"disbursement_account\":\"25252262666\",\"disbursement\":\"{\\\"account\\\":\\\"25252262666\\\"}\"}",
|
|
"status": "2",
|
|
"added": "2025-01-12 21:13:11.348383",
|
|
"updated": "2025-01-12 21:13:11.348383",
|
|
"employer_uid": "3a9ec95a-090c-4c98-bc01-e96d76b93952",
|
|
"disbursement_account": "25252262666",
|
|
"pc": "0"
|
|
}
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
}
|
|
return $this->respond($addedData, 200);
|
|
}
|
|
public function loanlist(){
|
|
|
|
return $this->respond([], 200);
|
|
}
|
|
|
|
public function loanOffer(){
|
|
$data = $this->request->getPost();
|
|
|
|
$mysql ="SELECT a.*, c.firstname FROM applications a LEFT JOIN customers c ON c.uid = a.customer_uid WHERE a.uid='". $data["application_uid"]."' ";
|
|
$query = $this->db->query($mysql);
|
|
$row = $query->getRowArray();
|
|
log_message('error', "Send Offer Application ". $data["application_uid"] );
|
|
|
|
$offerResult = $this->APIcall("POST", "http://10.10.10.48:6332/api/verify/offer", json_encode($row));
|
|
|
|
return $this->respond(["loan"=>$row, "result"=> $offerResult ], 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 [];
|
|
}
|
|
} |