autologin Fixes : ps

This commit is contained in:
VE10-Sanjeev 2023-07-11 20:11:21 +05:30
parent aaa9450ccd
commit 6f649f1231

View File

@ -1821,229 +1821,227 @@ public function filterSalesPDList_post() {
}
}
public function toMakeCetNewSalesPd($array){
public function toMakeCetNewSalesPd($array)
{
// print_r($array['type']);die;
// header("Location: https://demo.pdgenie.com/salespdpwa/#/sales-pd-list/list-pd");
log_message('ERROR','## C) Inside toMakeCetNewSalesPd Fns');
log_message('ERROR', '## C) Inside toMakeCetNewSalesPd Fns');
$sales_pd_type = $array['type'];
$productname = $array['product'];
$productname = $array['product'];
$applicantname = $array['applicantname'];
$applicantid = $array['applicantid'];
$applicantid = $array['applicantid'];
$usersemailid = $array['userid'];
$loanamount = $array['loanamount'];
$createdby = null;
$salepdid = null;
$current_date = date("d/m/Y H:i:s");
// $reponse_arr = json_decode(,true);
// print_r(APPPATH."controller/newSalesPD.json");die();
$lenderid = (ENVIRONMENT == 'production' ? 7 : 35);
if($applicantid != null && (!empty($applicantid))){
$where_condition = array("applicant_id"=>$applicantid);
$is_exist_applicant_id = $this->Sales_PD_Model->selectCustomRecords(array('sales_pd_sno'),$where_condition,SALES_PD_DATA);
if(count($is_exist_applicant_id)){
if ((!empty($sales_pd_type)) && (!empty($productname)) && (!empty($applicantname)) && (!empty($applicantid)) && (!empty($usersemailid)) && (!empty($loanamount))) {
/************lender id,shortname******************/
$lender_short_name = $this->Sales_PD_Model->selectCustomRecords(array('short_name'), array('entity_id' => $lenderid), ENTITY);
/************product id,name,abbr******************/
if ($productname) {
$product_short_name = preg_replace('/[^A-Za-z0-9\-]/', '', strtoupper($productname));
$product_where_condition = array('isactive' => 1);
if ($usersemailid) {
$product_where_condition['abbr like'] = '%' . $product_short_name . '%';
}
$product_id = $this->Sales_PD_Model->selectCustomRecords(array('product_id'), $product_where_condition, PRODUCTS);
$product_id = $product_id[0]['product_id'];
}
/************user id******************/
$columns = array('USERPROFILE.userid', 'ROLES.role_id', 'USERPROFILEROLES.user_role', 'ROLES.role_name');
$table = USERPROFILE . ' as USERPROFILE';
$joins = array(
array(
'table' => USERPROFILEROLES . ' as USERPROFILEROLES',
'condition' => 'USERPROFILEROLES.fk_userid = USERPROFILE.userid and USERPROFILEROLES.isactive =1',
'jointype' => 'INNER'
),
array(
'table' => ROLES . ' as ROLES',
'condition' => 'ROLES.role_id = USERPROFILEROLES.user_role',
'jointype' => 'INNER'
)
);
$order_by = 'USERPROFILE.userid';
if ($usersemailid) {
$user_where_condition['email like'] = '%' . $usersemailid . '%';
}
$user_details = $this->Sales_PD_Model->getJoinRecords($columns, $table, $joins, $user_where_condition, $order_by, 'DESC', '', $or_where);
$user_id = $user_details[0]['userid'];
$role_id = $user_details[0]['role_id'];
$createdby = $user_id;
if($applicantid != null && (!empty($applicantid))){
$where_condition = array("applicant_id"=>$applicantid);
$is_exist_applicant_id = $this->Sales_PD_Model->selectCustomRecords(array('sales_pd_sno'),$where_condition,SALES_PD_DATA);
}
if(!empty($is_exist_applicant_id) && count($is_exist_applicant_id)){
$is_exist_sales_pd_sno = $is_exist_applicant_id[0]['sales_pd_sno'];
log_message('ERROR','## InVaild : Applicant_id Already Exist with '.$is_exist_sales_pd_sno.' PD');
log_message('ERROR','## InVaild : Applicant_id Already Exist with ``'.$is_exist_sales_pd_sno.'`` PD');
$salepdid = 0;
}else{
}
else{
log_message('ERROR','## Vaild : Applicant_id = '.$applicantid);
if ((!empty($sales_pd_type)) && (!empty($productname)) && (!empty($applicantname)) && (!empty($applicantid)) && (!empty($usersemailid)) && (!empty($loanamount))) {
/************lender id,shortname******************/
$lender_short_name = $this->Sales_PD_Model->selectCustomRecords(array('short_name'),array('entity_id' => $lenderid),ENTITY);
/************product id,name,abbr******************/
if($productname){
$product_short_name = preg_replace('/[^A-Za-z0-9\-]/', '', strtoupper($productname));
$product_where_condition = array('isactive' => 1);
if ($usersemailid) {
$product_where_condition['abbr like'] = '%'.$product_short_name.'%';
}
/************random URL******************/
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < 16; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
$product_id = $this->Sales_PD_Model->selectCustomRecords(array('product_id'),$product_where_condition,PRODUCTS);
$product_id = $product_id[0]['product_id'];
}
/************user id******************/
$columns = array('USERPROFILE.userid','ROLES.role_id','USERPROFILEROLES.user_role','ROLES.role_name');
$table = USERPROFILE.' as USERPROFILE';
$joins = array(array('table' => USERPROFILEROLES. ' as USERPROFILEROLES',
'condition' =>'USERPROFILEROLES.fk_userid = USERPROFILE.userid and USERPROFILEROLES.isactive =1',
'jointype' => 'INNER'),
array('table' => ROLES.' as ROLES',
'condition' =>'ROLES.role_id = USERPROFILEROLES.user_role',
'jointype' => 'INNER'));
$order_by = 'USERPROFILE.userid';
if ($usersemailid) {
$user_where_condition['email like'] = '%'.$usersemailid.'%';
}
$user_details = $this->Sales_PD_Model->getJoinRecords($columns,$table,$joins,$user_where_condition,$order_by,'DESC','',$or_where);
$user_id = $user_details[0]['userid'];
$role_id = $user_details[0]['role_id'];
$createdby = $user_id;
/************Random URL******************/
$count = $this->Sales_PD_Model->selectCustomRecords(array('count(*) as count'), array('lender_id' => $lenderid, 'product_id' => $product_id, 'isactive' => 1), SALES_PD_DATA);
/************random URL******************/
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < 16; $i++)
{
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
/************Random URL******************/
$count = $this->Sales_PD_Model->selectCustomRecords(array('count(*) as count'),array('lender_id' => $lenderid,'product_id' => $product_id,'isactive' => 1),SALES_PD_DATA);
$salepd_serial_no = count($lender_short_name)? $lender_short_name[0]['short_name']:'UNKNOWN';
$salepd_serial_no .= $product_id? '-'.$product_short_name:'-UNKNOWN';
$salepd_serial_no .= '-'.(++$count[0]['count']);
log_message('ERROR','## 1) random string : '.$randomString.' serial No : '.$salepd_serial_no);
/*************Inserting Here ******************/
$records = array("sales_pd_sno"=> $salepd_serial_no,"rand_string"=>$randomString,"lender_id"=>$lenderid, "product_id"=>$product_id, "sales_pd_type"=>$sales_pd_type, "applicant_id"=>$applicantid, "applicant_name"=>$applicantname, "createdby"=>$createdby, "isactive"=>1);
$id = $this->Sales_PD_Model->saveRecords($records,SALES_PD_DATA);
$salepdid = $id;
// $id = 775; // 772,773,777,778
log_message('ERROR','## 2) available sales pdid : '.$id);
if (!empty($id)) {
$msg = "Inserted, Sales PD : ".$salepd_serial_no."/".$id;
$template = $this->Sales_PD_Model->selectCustomRecords(array('*'),array('lender_id' => $lenderid,'product_id' => $product_id,'pd_type' => 1,'sales_pd_type' => $sales_pd_type,'isactive' => 1),SALESPDTEMPLATE);
log_message('ERROR',"## 3) sales_pd_template_id : ".$template[0]["sales_pd_template_id"]." name : ".$template[0]["name"]." lender_id : ".$template[0]["lender_id"]." product_id : ".$template[0]["product_id"]." pd_type : ".$template[0]["pd_type"]." sales_pd_type : ".$template[0]["sales_pd_type"]);
log_message('ERROR','## 4) '.$msg);
$template = json_decode($template[0]['template'],true);
$section_data=array();
foreach ($template['sections'] as $key => $value){
$section_id = $template['sections'][$key]['section_id'];
$section_name = $template['sections'][$key]['section_name'];
switch($section_id)
{
case 1:
if($value['questions'])
{
foreach($value['questions'] as $form_key => $form_value)
{
$fieldtype = isset($form_value['type']) ? $form_value['type'] : "";
// echo $fieldtype;
if($form_value['question_key'] == 'application_id'){
$value['questions'][$form_key]['answer_value'] = $applicantid;
}else if($form_value['question_key'] == 'main_loan_applicant'){
$value['questions'][$form_key]['answer_value'] = $applicantname;
}
// else if($form_value['question_key'] == 'company_name'){
// $value['questions'][$form_key]['answer_value'] = "PVT LIMIT";
// }
// else if($form_value['question_key'] == 'person_met_during_visit'){
// $value['questions'][$form_key]['answer_value'] = "shree 4";
// }
// else if($form_value['question_key'] == 'address_visited'){
// $value['questions'][$form_key]['answer_value'] = "Perambalur - 7";
// }
else if($form_value['question_key'] === 'state'){
$value['questions'][$form_key]['answer_value'] = 0;
$value['questions'][$form_key]['answers'] = $this->Sales_PD_Model->selectCustomRecords(array('state_id as answer_id','name as answer'),array('isactive' => 1),STATE);
}
else if($form_value['question_key'] === 'person_met_designation'){
$value['questions'][$form_key]['answer_value'] = 0;
$value['questions'][$form_key]['answers'] = $this->Sales_PD_Model->selectCustomRecords(array('company_relationship_id as answer_id','name as answer'),array('isactive' => 1),COMPANYRELATIONSHIPS);
}
else if(!empty($form_value['question_key'])){
$value['questions'][$form_key]['answer_value'] = ($fieldtype == 8 || $fieldtype == 4 || $fieldtype == 3 || $fieldtype == 2) ? 0 : null;
}
$salepd_serial_no = count($lender_short_name) ? $lender_short_name[0]['short_name'] : 'UNKNOWN';
$salepd_serial_no .= $product_id ? '-' . $product_short_name : '-UNKNOWN';
$salepd_serial_no .= '-' . (++$count[0]['count']);
log_message('ERROR', '## 1) random string : ' . $randomString . ' serial No : ' . $salepd_serial_no);
/*************Inserting Here ******************/
$records = array("sales_pd_sno" => $salepd_serial_no, "rand_string" => $randomString, "lender_id" => $lenderid, "product_id" => $product_id, "sales_pd_type" => $sales_pd_type, "applicant_id" => $applicantid, "applicant_name" => $applicantname, "createdby" => $createdby, "isactive" => 1);
$id = $this->Sales_PD_Model->saveRecords($records, SALES_PD_DATA);
$salepdid = $id;
// $id = 775; // 772,773,777,778
log_message('ERROR', '## 2) available sales pdid : ' . $id);
if (!empty($id)) {
$msg = "Inserted, Sales PD : " . $salepd_serial_no . "/" . $id;
$template = $this->Sales_PD_Model->selectCustomRecords(array('*'), array('lender_id' => $lenderid, 'product_id' => $product_id, 'pd_type' => 1, 'sales_pd_type' => $sales_pd_type, 'isactive' => 1), SALESPDTEMPLATE);
log_message('ERROR', "## 3) sales_pd_template_id : " . $template[0]["sales_pd_template_id"] . " name : " . $template[0]["name"] . " lender_id : " . $template[0]["lender_id"] . " product_id : " . $template[0]["product_id"] . " pd_type : " . $template[0]["pd_type"] . " sales_pd_type : " . $template[0]["sales_pd_type"]);
log_message('ERROR', '## 4) ' . $msg);
$template = json_decode($template[0]['template'], true);
$section_data = array();
foreach ($template['sections'] as $key => $value) {
$section_id = $template['sections'][$key]['section_id'];
$section_name = $template['sections'][$key]['section_name'];
switch ($section_id) {
case 1:
if ($value['questions']) {
foreach ($value['questions'] as $form_key => $form_value) {
$fieldtype = isset($form_value['type']) ? $form_value['type'] : "";
// echo $fieldtype;
if ($form_value['question_key'] == 'application_id') {
$value['questions'][$form_key]['answer_value'] = $applicantid;
} else if ($form_value['question_key'] == 'main_loan_applicant') {
$value['questions'][$form_key]['answer_value'] = $applicantname;
}
// else if($form_value['question_key'] == 'company_name'){
// $value['questions'][$form_key]['answer_value'] = "PVT LIMIT";
// }
// else if($form_value['question_key'] == 'person_met_during_visit'){
// $value['questions'][$form_key]['answer_value'] = "shree 4";
// }
// else if($form_value['question_key'] == 'address_visited'){
// $value['questions'][$form_key]['answer_value'] = "Perambalur - 7";
// }
else if ($form_value['question_key'] === 'state') {
$value['questions'][$form_key]['answer_value'] = 0;
$value['questions'][$form_key]['answers'] = $this->Sales_PD_Model->selectCustomRecords(array('state_id as answer_id', 'name as answer'), array('isactive' => 1), STATE);
} else if ($form_value['question_key'] === 'person_met_designation') {
$value['questions'][$form_key]['answer_value'] = 0;
$value['questions'][$form_key]['answers'] = $this->Sales_PD_Model->selectCustomRecords(array('company_relationship_id as answer_id', 'name as answer'), array('isactive' => 1), COMPANYRELATIONSHIPS);
} else if (!empty($form_value['question_key'])) {
$value['questions'][$form_key]['answer_value'] = ($fieldtype == 8 || $fieldtype == 4 || $fieldtype == 3 || $fieldtype == 2) ? 0 : null;
}
$general = array("section_id"=>$section_id,"section_name"=>$section_name,"onsubmit"=>null,"questions"=>$value['questions'],"order_id"=>1,"is_complete"=>1,"fk_createdby"=>$createdby,"sales_pd_id"=>$id);
array_push($section_data, $general);
}
break;
case 2:
if($value['questions'] && $loanamount)
{
foreach($value['questions'] as $form_key => $form_value)
{
$fieldtype = isset($form_value['type']) ? $form_value['type'] : "";
if($form_value['question_key'] == 'loan_amount_applied'){
$value['questions'][$form_key]['answer_value'] = $loanamount;
}
else if(!empty($form_value['question_key'])){
$value['questions'][$form_key]['answer_value'] = ($fieldtype == 8 || $fieldtype == 4 || $fieldtype == 3 || $fieldtype == 2) ? 0 : null;
}
}
$fund = array("section_id"=>$section_id,"section_name"=>$section_name,"onsubmit"=>null,"questions"=>$value['questions'],"order_id"=>1,"is_complete"=>1,"fk_createdby"=>$createdby,"sales_pd_id"=>$id);
array_push($section_data, $fund);
}
break;
default: "No Sections";
}
}
if(!empty($section_data)){
foreach ($section_data as $key => $data_value){
$check=$this->Sales_PD_Model->selectCustomRecords(array('*'),array('sales_pd_id' =>$id,'section_id' => $data_value['section_id'],'isactive' => 1 ),SALESPD_SECTION_DATA);
if(count($check)>0){
$this->Sales_PD_Model->updateRecords(array('isactive' => 0),SALESPD_SECTION_DATA,array('sales_pd_id' =>$id,'section_id' => $data_value['section_id'] ));
$general = array("section_id" => $section_id, "section_name" => $section_name, "onsubmit" => null, "questions" => $value['questions'], "order_id" => 1, "is_complete" => 1, "fk_createdby" => $createdby, "sales_pd_id" => $id);
array_push($section_data, $general);
}
//insert new record
$section_data_arr = json_encode($data_value);
$fields = array('sales_pd_id' => $id, 'section_id' => $data_value['section_id'], 'status' =>1,'section_data' => $section_data_arr,'createdby' => $createdby);
$reponse = $this->Sales_PD_Model->saveRecords($fields,SALESPD_SECTION_DATA);
// $reponse = 1;
$msg = $msg." ( ".$data_value['section_name']." ID : ".$reponse. " )";
log_message('ERROR','## 5) Confirmation : '.$msg);
}
break;
case 2:
if ($value['questions'] && $loanamount) {
foreach ($value['questions'] as $form_key => $form_value) {
$fieldtype = isset($form_value['type']) ? $form_value['type'] : "";
if ($form_value['question_key'] == 'loan_amount_applied') {
$value['questions'][$form_key]['answer_value'] = $loanamount;
} else if (!empty($form_value['question_key'])) {
$value['questions'][$form_key]['answer_value'] = ($fieldtype == 8 || $fieldtype == 4 || $fieldtype == 3 || $fieldtype == 2) ? 0 : null;
}
}
$fund = array("section_id" => $section_id, "section_name" => $section_name, "onsubmit" => null, "questions" => $value['questions'], "order_id" => 1, "is_complete" => 1, "fk_createdby" => $createdby, "sales_pd_id" => $id);
array_push($section_data, $fund);
}
break;
default:
"No Sections";
}
}
if (!empty($section_data)) {
foreach ($section_data as $key => $data_value) {
$check = $this->Sales_PD_Model->selectCustomRecords(array('*'), array('sales_pd_id' => $id, 'section_id' => $data_value['section_id'], 'isactive' => 1), SALESPD_SECTION_DATA);
if (count($check) > 0) {
$this->Sales_PD_Model->updateRecords(array('isactive' => 0), SALESPD_SECTION_DATA, array('sales_pd_id' => $id, 'section_id' => $data_value['section_id']));
}
//insert new record
$section_data_arr = json_encode($data_value);
$fields = array('sales_pd_id' => $id, 'section_id' => $data_value['section_id'], 'status' => 1, 'section_data' => $section_data_arr, 'createdby' => $createdby);
$reponse = $this->Sales_PD_Model->saveRecords($fields, SALESPD_SECTION_DATA);
// $reponse = 1;
$msg = $msg . " ( " . $data_value['section_name'] . " ID : " . $reponse . " )";
log_message('ERROR', '## 5) Confirmation : ' . $msg);
}
}
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['msg'] = "Sales PD : ".$salepd_serial_no;
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Data Not Found,Try again';
}
log_message('ERROR','## 6) Finally, '.$data['msg']);
date_default_timezone_set("Asia/Kolkata");
$current_date = date("d/m/Y H:i:s");
$smcauthtoken = smcfinance::SmcFinanceAuthUrl();
if($smcauthtoken != null){
log_message('ERROR','## 7) I Got SMC Finance Auth Token');
smcfinance::SmcFinanceApiUrl($applicantid,$salepdid,$salepd_serial_no,1,$smcauthtoken);
}else{
log_message('ERROR','## 7) SMC Finance Auth Token Not Founded, '.$smcauthtoken);
}
}else{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['msg'] = "Sales PD : " . $salepd_serial_no;
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Param (or) Value Not Missing,Please Check again';
$data['msg'] = 'Data Not Found,Try again';
}
}
log_message('ERROR', '## 6) Finally, ' . $data['msg']);
date_default_timezone_set("Asia/Kolkata");
$smcauthtoken = smcfinance::SmcFinanceAuthUrl();
if ($smcauthtoken != null) {
log_message('ERROR', '## 7) I Got SMC Finance Auth Token');
smcfinance::SmcFinanceApiUrl($applicantid, $salepdid, $salepd_serial_no, 1, $smcauthtoken);
} else {
log_message('ERROR', '## 7) SMC Finance Auth Token Not Founded, ' . $smcauthtoken);
}
}
} else {
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NOT_FOUND;
$data['msg'] = 'Param (or) Value Not Missing,Please Check again';
}
if(ENVIRONMENT == 'production'){
if (ENVIRONMENT == 'production') {
$auth_user_id = "MwiseSales@yahoo.com";
$auth_password = "sine1234";
$token = base64_encode($auth_user_id."#".$auth_password."#".$user_id."#".$role_id."#".$current_date."#".$usersemailid."#".$salepdid);
$token = base64_encode($auth_user_id . "#" . $auth_password . "#" . $user_id . "#" . $role_id . "#" . $current_date . "#" . $usersemailid . "#" . $salepdid);
// echo $token;
// log_message('ERROR','## 7) Finally, '.$data['msg']);
$redirect_uri = "https://pdgenie.com/sales/#/auto?token=".$token; // For Production
}else{
$redirect_uri = "https://pdgenie.com/sales/#/auto?token=" . $token; // For Production
} else {
$auth_user_id = "MwiseSales@yahoo.com";
$auth_password = "sine1234";
$token = base64_encode($auth_user_id."#".$auth_password."#".$user_id."#".$role_id."#".$current_date."#".$usersemailid."#".$salepdid);
$token = base64_encode($auth_user_id . "#" . $auth_password . "#" . $user_id . "#" . $role_id . "#" . $current_date . "#" . $usersemailid . "#" . $salepdid);
// echo $token;
// $token = base64_encode('mwisesales1@sine.com#test1234'."#".$user_id."#".$role_id);
// $redirect_uri = "http://localhost:4200/#/auto?token=".$token; // For Localhost
$redirect_uri ="https://demo.pdgenie.com/salespdpwa/#/auto?token=".$token; // For Testing
$redirect_uri = "https://demo.pdgenie.com/salespdpwa/#/auto?token=" . $token; // For Testing
}
// echo $auth_user_id."#".$auth_password."#".$user_id."#".$role_id."#".$current_date."#".$usersemailid."#".$salepdid;
log_message('ERROR', '## 8) Redirect B4 '.$auth_user_id."#".$auth_password."#".$user_id."#".$role_id."#".$current_date."#".$usersemailid."#".$salepdid);
// MwiseSales@yahoo.com#sine1234#293#19#06/07/2023 16:02:57#mwisesales1@sine.com#904
// https://demo.pdgenie.com/salespdpwa/#/auto?token=TXdpc2VTYWxlc0B5YWhvby5jb20jc2luZTEyMzQjMjkzIzE5IzA2LzA3LzIwMjMgMTY6MDI6NTcjbXdpc2VzYWxlczFAc2luZS5jb20jOTA0
// echo $redirect_uri;
// die();
header("Location: ".$redirect_uri);
log_message('ERROR', '## 9) Redirect Aftr `' . $redirect_uri . '`');
header("Location: " . $redirect_uri);
// $this->response($data,REST_Controller::HTTP_OK);
//if($data['dataStatus']){ header("Location: https://sidharthindustries.com/SIA/"); }
}
function uploadSalesImages_get(){