code1
public function applicationLabourLineLandRegistration($review_flag = false)
{
$this->db = $this->load->database('db2', TRUE);
$lmdata['district_all'] = $this->db->query("Select * from district_details")->result();
$this->LabourLineModel->dbSwitchSession();
$application_no = $this->input->get('app');
$application_no = $this->LabourLineModel->decryptJwtCase($application_no);
// $geo_date_query = $this->db->query("Select date_entry from supportive_document where applid='$application_no'")->row();
$this->db->select('date_entry');
$this->db->from('supportive_document');
$this->db->where('applid', $application_no);
$geo_date_query = $this->db->get()->row();
$geo_date = isset($geo_date_query->date_entry) ? $geo_date_query->date_entry : '.....';
$sql = "SELECT * FROM supportive_document WHERE id IN ( SELECT MAX(id) FROM supportive_document WHERE applid = ? AND dag_no IS NOT NULL AND file_name = ? GROUP BY applid, dag_no)";
$supportive_document_sql = $this->db->query($sql, array($application_no, GEO_TAG_PHOTO));
if ($supportive_document_sql->num_rows() > 0) {
$lmdata['geo_tag_doc'] = $supportive_document_sql->result();
} else {
$lmdata['geo_tag_doc_empty'] = "<span class='text-danger alert-danger'><b>Geo tag photo yet to be uploaded.</b></span>";
}
//********************case registration from API start ********* */
//********************check and insert if case not registered */
$recordExist = $this->LabourLineModel->checkExistDharitree($application_no);
if (!$recordExist) {
/// additional property for LM note
// $additional_property = $this->db->query("Select * from settlement_additional_property where applid='$application_no'");
$this->db->select('*');
$this->db->from('settlement_additional_property');
$this->db->where('applid', $application_no);
$additional_property = $this->db->get();
if ($additional_property->num_rows() > 0) {
$totallesaa = 0;
$totalganda = 0;
foreach ($additional_property->result() as $addprop) {
if (in_array($addprop->dist_code, json_decode(BARAK_VALLEY))) {
$total_g = $this->LabourLineModel->Total_ganda($addprop->bigha, $addprop->katha, $addprop->lessa, $addprop->ganda);
$totalganda = $totalganda + $total_g;
} else {
$total_l = $this->LabourLineModel->Total_Lessa($addprop->bigha, $addprop->katha, $addprop->lessa);
$totallesaa = $totallesaa + $total_l;
}
}
if (!empty($totallesaa)) {
$district['total_aditional_area'] = $this->LabourLineModel->Total_Bigha_Katha_Lessa($totallesaa);
}
if (!empty($totalganda)) {
$district['total_aditional_area_g'] = $this->LabourLineModel->Total_Bigha_Katha_Lessa2($totalganda);
}
$district['additional_property'] = $additional_property->result();
//var_dump($district['additional_property']); die;
}
$token = $this->LabourLineModel->createTokenJwt();
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, API_LINK_NC . "getAppDetails");
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, http_build_query(array(
'application_no' => $application_no,
'api_key' => API_KEY,
'token' => $token
)));
$output = curl_exec($curl_handle);
// var_dump($output);
// die;
if (isset(json_decode($output)->responseType)) {
if (json_decode($output)->responseType == 3) {
echo json_decode($output)->data . " - Unauthorized access!";
return false;
}
}
curl_close($curl_handle);
$backup = $output;
$output = json_decode($output);
//****************generate case number********************
$case_name = $this->LabourLineModel->genearteCaseName();
if (empty($case_name)) {
$data = array(
'error' => "Network Issue or Session Out. Please try Again"
);
echo json_encode($data);
die();
}
//*******generating petition_no and case_no */
$case_no['petition_no'] = $petition_no = $this->LabourLineModel->genearteSettlementPetitionNo();
$case_no['case_no'] = $case_name . $petition_no . "/" . LABOUR_LINE_LAND;
$district['geo_date'] = $geo_date;
$district['app'] = $output->application;
$district['pattaNo'] = $this->ncutility->getPattaTypeNo($district['app']->dist_code, $district['app']->subdiv_code, $district['app']->cir_code, $district['app']->mouza_code, $district['app']->lot_no, $district['app']->village_code, $district['app']->dag_no);
$district['applicants'] = $output->applicants;
$district['document'] = $output->documents;
$district['query'] = $output->query;
$district['property'] = $output->property;
$district['settlements'] = $output->settlements;
$district['encroachers'] = $output->encroachers;
$district['owners'] = $output->owners;
$district['riotee_noks'] = $output->riotee_noks;
$district['aadhar'] = $output->aadhar;
$district['nextKin'] = $output->nextKin;
// get khatian number
$d = $district['app']->dist_code;
$s = $district['app']->subdiv_code;
$c = $district['app']->cir_code;
$m = $district['app']->mouza_code;
$l = $district['app']->lot_no;
$v = $district['app']->village_code;
// $pno=$district['pattaNo']->patta_no;
// $pc=$district['pattaNo']->patta_type_code;
$dag = $district['app']->dag_no;
$district['co_name'] = $this->NcCommonModel->getCoName($d, $s, $c);
$district['s_area'] = $this->NcCommonModel->getPremiumArea();
$district['bhumi'] = $output->bhumi;
// for guardian relation
$query_for_guar_rel = "SELECT * from master_guard_rel WHERE id NOT IN ('5','6')";
$relation_executation = $this->db->query($query_for_guar_rel);
$row = $relation_executation->num_rows();
if ($row != 0) {
$district['guar_rel'] = $relation_executation->result();
}
if ($this->ncutility->checkUserAuthForCaseForLm($d, $s, $c, $m, $l) == false) {
$this->session->set_flashdata('message', "Unauthorized access for case no # " . $application_no);
redirect(base_url() . "index.php/home");
}
// fetch riotee noks -js- 05-09-2022
if ($output->riotee_noks == true) {
$district['riotee_nok'] = $output->riotee_noks;
}
// $district['selfDeclarationDetails'] = $output->selfDeclaration;
foreach ($output->selfDeclaration as $selfDec) {
$district['selfDeclarationDetails'] = json_decode($selfDec->dec_details);
}
$vlb_encc = [];
if ($output->encroachers == true) {
$district['riotee'] = $output->encroachers;
foreach ($output->encroachers as $encroacher) {
$vlb_encroacher = $this->NcServiceModel->getEncroacherDetails($d, $s, $c, $m, $l, $v, $encroacher->dag_no);
$district['vlb_enc'] = $vlb_encroacher;
if ($vlb_encroacher == true) {
// getting the encroacher details
$vlb_encroacher_in_dag = $this->NcServiceModel->getEncroacherInDag($vlb_encroacher->id);
$vlb_encc[] = $vlb_encroacher_in_dag;
} else {
$district['empty_err'] = "No Land Bank Details found!!";
}
}
$district['vlb_enc_details'] = $vlb_encc;
}
// aadhaar photo api
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, API_LINK_NC . "getApplicantPhoto");
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, http_build_query(array(
'application_no' => $application_no,
)));
$get_aadhaar_photo = curl_exec($curl_handle);
curl_close($curl_handle);
// if ($get_aadhaar_photo != 'n') {
// $district['aadhaar_b64_decoded'] = "<img src = data:" . $this->decodeBase64($get_aadhaar_photo) . ";base64," . $get_aadhaar_photo . " class='img-thumbnail' alt='Adhar Photo' width='170' height='200'>";
// }
$this->db->trans_begin();
// insertion in backup table (lm)
$backup_array = [
'applid' => $application_no,
'case_no' => $case_no['case_no'],
// 'from_office' => '',
// 'to_office' => '',
'status' => 'I',
// 'phase' => '',
'data' => $backup
];
$backup_insertion = $this->db->insert('settlement_backup_json', $backup_array);
if ($backup_insertion != 1) {
$this->db->trans_rollback();
log_message('error', '#BACKUP001: Insertion failed in settlement_backup_json RTPS Case No ' . $application_no);
$this->session->set_flashdata('message', "#BACKUP001: Registration of Settlement failed for case no : " . $application_no);
redirect(base_url() . "index.php/home");
return false;
}
///////// additional property starts here
$checkAdditionalProperty = $this->db->query("SELECT * FROM settlement_additional_property
WHERE applid=?", array($application_no));
if ($checkAdditionalProperty->num_rows() == 0) {
if (isset($output->property)) {
foreach ($output->property as $value) {
$add_property = array(
'case_no' => $case_no['case_no'],
'dist_code' => $value->dist_code,
'subdiv_code' => $value->subdiv_code,
'cir_code' => $value->cir_code,
'mouza_pargona_code' => $value->mouza_pargona_code,
'lot_no' => $value->lot_no,
'vill_townprt_code' => $value->vill_townprt_code,
'bigha' => $value->bigha,
'katha' => $value->katha,
'lessa' => $value->lessa,
'chatak' => $value->lessa,
'ganda' => $value->ganda,
'kranti' => $value->kranti,
'entry_date' => date('Y-m-d h:i:s'),
'is_rural' => $value->is_rural,
'dag_no' => $value->dag_no,
'patta_no' => $value->patta_no,
'service_id' => LABOUR_LINE_LAND_ID,
'applied_flag' => CITIZEN,
'dist_name' => trim($value->dist_name),
'cir_name' => trim($value->cir_name),
'vill_name' => trim($value->vill_name),
'applid' => $application_no,
);
$insAddProperty = $this->db->insert('settlement_additional_property', $add_property);
if ($insAddProperty != 1) {
$this->db->trans_rollback();
log_message('error', '#ERROR393: Insertion failed in settlement_additional_property RTPS Case No ' . $application_no);
$data = array(
'error' => "#ERROR393: Registration of Settlement failed for case no : " . $application_no
);
echo json_encode($data);
return false;
}
}
}
}
///////// additional property ends here
$pro_class = $this->input->post('protected_class');
$protected_class_vr = ($pro_class == null || $pro_class == '' || $pro_class == 0) ? 0 : $this->input->post('protected_class');
//****bhumiputra condition prepare for insertation */
if (!empty($output->bhumi['0'])) {
if ($output->bhumi['0']->bhumi_cert_available == 1) { //if bhumiputra available
$bhumiputra_confirmation = 'YES';
$bhumiputra_certificate_no = $output->bhumi['0']->bhumi_ack_no;
$bhumiputra_certificate_type = 'CERT';
} else if ($output->bhumi['0']->is_bhumi_applied == 1) { //if applied in bhumiputra
$bhumiputra_confirmation = 'YES';
$bhumiputra_certificate_no = $output->bhumi['0']->bhumi_ack_no;
$bhumiputra_certificate_type = 'ACK';
} else {
$bhumiputra_confirmation = '0';
$bhumiputra_certificate_no = '0';
$bhumiputra_certificate_type = '0';
}
} else {
$bhumiputra_confirmation = '0';
$bhumiputra_certificate_no = '0';
$bhumiputra_certificate_type = '0';
}
//********settlement_basic insertation */
$basic = array(
'dist_code' => $district['app']->dist_code,
'subdiv_code' => $district['app']->subdiv_code,
'cir_code' => $district['app']->cir_code,
'mouza_pargona_code' => $district['app']->mouza_code,
'lot_no' => $district['app']->lot_no,
'vill_townprt_code' => $district['app']->village_code,
'service_code' => $district['app']->service_code,
'ref_no' => $district['app']->ref_no,
'case_no' => $case_no['case_no'],
'trans_code' => 'F', /////////full
'petition_no' => $case_no['petition_no'],
'year_no' => date('Y'),
'date_entry' => date('Y-m-d G:i:s'),
'status' => 'Z',
'user_code' => $this->session->userdata('user_code'),
// 'lm_code' => $this->session->userdata('user_code'),
'submission_date' => date('Y-m-d G:i:s'),
'from_office' => 'API',
'pending_officer' => 'LM',
'pending_office' => 'CO',
'occupation_applicant' => $district['applicants'][0]->applicant_occupation,
'applid' => $district['app']->application_no,
'caste' => $district['applicants'][0]->caste_category,
'uuid' => $district['app']->uuid,
'protected_class' => $protected_class_vr,
'bhumiputra_confirmation' => $bhumiputra_confirmation,
'bhumiputra_certificate_no' => $bhumiputra_certificate_no,
'bhumiputra_certificate_type' => $bhumiputra_certificate_type,
// 'co_code' => $this->input->post('co_code')
'is_tribal' => ($district['app']->service_applied_for == 'SLLL') ? 0 : 1,
);
$insSetBasic = $this->db->insert('settlement_basic', $basic);
// echo $this->db->last_query(); die();
if ($insSetBasic != 1) {
$this->db->trans_rollback();
log_message('error', '#ERRSET00011: Insertion failed in settlement_basic RTPS Case No ' . $application_no);
$data = array(
'error' => "#ERRSET00011: Registration of Settlement failed for case no : " . $application_no
);
echo json_encode($data);
return false;
}
////settlement_dag_details insert start
if ($district['encroachers'] == false || empty($district['encroachers']) || $district['encroachers'] == '') {
// $api_dag={
// 'plot':'15'
// };
// $this->db->trans_rollback();
// log_message('error', '#ERRSET004545: Insertion failed settlement_dag details empty RTPS Case No ' . $application_no);
// log_message("error", "#ENCROACHER_DETAIL: " . $district['encroachers']);
// log_message('error', '#ENCROACHER_DETAIL: Insertion failed settlement_dag details ' . $this->db->last_query);
// log_message('error', '#ENCROACHER_DETAIL: Application_no ' . $application_no);
// log_message('error', '#ENCROACHER_DETAIL: API response ' . json_encode($output));
// $data = array(
// 'error' => "#ERRSET004545: Registration of Settlement failed for case no : " . $application_no
// );
// echo json_encode($data);
// return false;
} else {
foreach ($district['encroachers'] as $dags) {
$district['class'] = $this->ncutility->getPattaTypeNo($district['app']->dist_code, $district['app']->subdiv_code, $district['app']->cir_code, $district['app']->mouza_code, $district['app']->lot_no, $district['app']->village_code, $dags->dag_no);
// $enc_home_bigha = $dags->mbigha;
// $enc_home_katha = $dags->mkatha;
// $enc_home_lessa = $dags->mlessa;
// $enc_home_ganda = $dags->mganda;
// $enc_home_kranti = $dags->mkranti;
// $enc_agri_bigha = $dags->agri_bigha;
// $enc_agri_katha = $dags->agri_katha;
// $enc_agri_lessa = $dags->agri_lessa;
// $enc_agri_ganda = $dags->agri_ganda;
// $enc_agri_kranti = $dags->agri_kranti;
// $encroachment_area = [
// 'homestead' => [
// 'bigha' => $enc_home_bigha,
// 'katha' => $enc_home_katha,
// 'lessa' => $enc_home_lessa,
// 'ganda' => $enc_home_ganda,
// 'kranti' => $enc_home_kranti,
// ],
// 'agriculture' => [
// 'bigha' => $enc_agri_bigha,
// 'katha' => $enc_agri_katha,
// 'lessa' => $enc_agri_lessa,
// 'ganda' => $enc_agri_ganda,
// 'kranti' => $enc_agri_kranti,
// ],
// ];
$fmd = array(
'dist_code' => $district['app']->dist_code,
'subdiv_code' => $district['app']->subdiv_code,
'cir_code' => $district['app']->cir_code,
'mouza_pargona_code' => $district['app']->mouza_code,
'lot_no' => $district['app']->lot_no,
'vill_townprt_code' => $district['app']->village_code,
'user_code' => $this->session->userdata('user_code'),
'date_entry' => date('Y-m-d'),
'case_no' => $case_no['case_no'],
'petition_no' => $case_no['petition_no'],
'year_no' => date('Y'),
'new_land_class_code' => $district['class']->land_class_code,
'dag_no' => $dags->dag_no,
'patta_no' => $dags->patta_no,
'patta_type_code' => $dags->patta_code,
'is_urban' => $district['app']->is_urban,
'land_type' => $dags->land_type,
'revenue' => 0,
'operation' => 'E',
);
$fmd['dag_area_b'] = $dags->available_bigha;
$fmd['dag_area_k'] = $dags->available_katha;
$fmd['dag_area_lc'] = $dags->available_lessa;
$fmd['dag_area_g'] = $dags->available_ganda;
$fmd['dag_area_kr'] = $dags->available_kranti;
$insSetDag = $this->db->insert('settlement_dag_details', $fmd);
// log_message('error',$this->db->last_query());
if ($insSetDag != 1) {
$this->db->trans_rollback();
log_message('error', '#ERRSET0002_1: Insertion failed in settlement_dag_details RTPS Case No ' . $application_no);
log_message('error', "#ERRSET0002_2: Insertion failed in settlement_dag_details RTPS Case No $application_no == " . $this->db->last_query());
$data = array(
'error' => "#ERRSET0002: Registration of Settlement failed for case no : " . $application_no
);
echo json_encode($data);
return false;
}
//*******insertion in settlement_area_history**************
// if (in_array($district['app']->dist_code, json_decode(BARAK_VALLEY))) {
// //***********actual Encroachment area ***************
// $actual_encroachment_area_home_ganda = $this->LabourLineModel->Total_ganda($enc_home_bigha, $enc_home_katha, $enc_home_lessa, $enc_home_ganda);
// $actual_encroachment_area_agri_ganda = $this->LabourLineModel->Total_ganda($enc_agri_bigha, $enc_agri_katha, $enc_agri_lessa, $enc_agri_ganda);
// //***********total Actual Encroachment area*****************
// $total_actual_encroachment_area_ganda = (float)$actual_encroachment_area_home_ganda + (float)$actual_encroachment_area_agri_ganda;
// $totalEncroachmentAreaArr = $this->LabourLineModel->Total_Bigha_Katha_Lessa2($total_actual_encroachment_area_ganda);
// // **********************************************
// //***********Settlement area that applicant will get settlement on***********
// $total_settlement_ganda_home = $this->LabourLineModel->Total_ganda($fmd['home_b'], $fmd['home_k'], $fmd['home_lc'], $fmd['home_g']);
// $total_settlement_ganda_agri = $this->LabourLineModel->Total_ganda($fmd['agri_b'], $fmd['agri_k'], $fmd['agri_lc'], $fmd['agri_g']);
// //*****total Settlement area *************/
// $total_settlement_ganda = (float)$total_settlement_ganda_home + (float)$total_settlement_ganda_agri;
// $totalSettlementAreaArr = $this->LabourLineModel->Total_Bigha_Katha_Lessa2($total_settlement_ganda);
// //*************leftout area homestead**************
// $leftOutAreaHomeGanda = (float)$actual_encroachment_area_home_ganda - (float)$total_settlement_ganda_home;
// $leftOutAreaHomeArr = $this->LabourLineModel->Total_Bigha_Katha_Lessa2($leftOutAreaHomeGanda);
// //**********Ileftout area agriculture**************
// $leftOutAreaAgriGanda = (float)$actual_encroachment_area_agri_ganda - (float)$total_settlement_ganda_agri;
// $leftOutAreaAgriArr = $this->LabourLineModel->Total_Bigha_Katha_Lessa2($leftOutAreaAgriGanda);
// //**********Total left out area***************
// $totalLeftOutAreaGanda = (float)$total_actual_encroachment_area_ganda - (float)$total_settlement_ganda;
// $totalLeftOutAreaArr = $this->LabourLineModel->Total_Bigha_Katha_Lessa2($totalLeftOutAreaGanda);
// } else {
// //********actual Encroachment area**********
// $actual_encroachment_area_home_lessa = $this->LabourLineModel->Total_Lessa($enc_home_bigha, $enc_home_katha, $enc_home_lessa);
// $actual_encroachment_area_agri_lessa = $this->LabourLineModel->Total_Lessa($enc_agri_bigha, $enc_agri_katha, $enc_agri_lessa);
// //***********total Actual Encroachment area*****************
// $total_actual_encroachment_area_lessa = (float)$actual_encroachment_area_home_lessa + (float)$actual_encroachment_area_agri_lessa;
// $totalEncroachmentAreaArr = $this->LabourLineModel->Total_Bigha_Katha_Lessa($total_actual_encroachment_area_lessa);
// // **********************************************
// //*******Settlement area that applicant will get settlement on**********
// $total_settlement_lessa_home = $this->LabourLineModel->Total_Lessa($fmd['home_b'], $fmd['home_k'], $fmd['home_lc']);
// $total_settlement_lessa_agri = $this->LabourLineModel->Total_Lessa($fmd['agri_b'], $fmd['agri_k'], $fmd['agri_lc']);
// //*************Total settlement area */
// $total_settlement_lessa = (float)$total_settlement_lessa_home + (float)$total_settlement_lessa_agri;
// $totalSettlementAreaArr = $this->LabourLineModel->Total_Bigha_Katha_Lessa($total_settlement_lessa);
// //****************leftout area homestead**************
// $leftOutAreaHomeLessa = (float)$actual_encroachment_area_home_lessa - (float)$total_settlement_lessa_home;
// $leftOutAreaHomeArr = $this->LabourLineModel->Total_Bigha_Katha_Lessa($leftOutAreaHomeLessa);
// //*************leftout area agriculture*****************
// $leftOutAreaAgriLessa = (float)$actual_encroachment_area_agri_lessa - (float)$total_settlement_lessa_agri;
// $leftOutAreaAgriArr = $this->LabourLineModel->Total_Bigha_Katha_Lessa($leftOutAreaAgriLessa);
// //**********Total left out area***************
// $totalLeftOutArealessa = (float)$total_actual_encroachment_area_lessa - (float)$total_settlement_lessa;
// $totalLeftOutAreaArr = $this->LabourLineModel->Total_Bigha_Katha_Lessa($totalLeftOutArealessa);
// }
// $settlementAreaHistoryArr = [
// 'application_no' => $application_no,
// 'case_no' => $case_no['case_no'],
// 'dag_no' => $dags->dag_no,
// 'uuid' => $district['app']->uuid,
// 'created_at' => date('Y-m-d'),
// // 'applied_area_home_bigha' => $dags->mbigha,
// 'applied_area_home_katha' => $dags->mkatha,
// 'applied_area_home_lessa' => $dags->mlessa,
// 'applied_area_home_ganda' => $dags->mganda,
// 'applied_area_home_kranti' => $dags->mkranti,
// 'applied_area_agri_bigha' => $dags->agri_bigha,
// 'applied_area_agri_katha' => $dags->agri_katha,
// 'applied_area_agri_lessa' => $dags->agri_lessa,
// 'applied_area_agri_ganda' => $dags->agri_ganda,
// 'applied_area_agri_kranti' => $dags->agri_kranti,
// 'actual_encroachment_area_home_bigha' => $enc_home_bigha,
// 'actual_encroachment_area_home_katha' => $enc_home_katha,
// 'actual_encroachment_area_home_lessa' => $enc_home_lessa,
// 'actual_encroachment_area_home_ganda' => $enc_home_ganda,
// 'actual_encroachment_area_home_kranti' => $enc_home_kranti,
// 'actual_encroachment_area_agri_bigha' => $enc_agri_bigha,
// 'actual_encroachment_area_agri_katha' => $enc_agri_katha,
// 'actual_encroachment_area_agri_lessa' => $enc_agri_lessa,
// 'actual_encroachment_area_agri_ganda' => $enc_agri_ganda,
// 'actual_encroachment_area_agri_kranti' => $enc_agri_kranti,
// 'total_actual_encroachment_area_bigha' => $totalEncroachmentAreaArr[0],
// 'total_actual_encroachment_area_katha' => $totalEncroachmentAreaArr[1],
// 'total_actual_encroachment_area_lessa' => $totalEncroachmentAreaArr[2],
// 'total_actual_encroachment_area_ganda' => $totalEncroachmentAreaArr[3],
// 'total_actual_encroachment_area_kranti' => 0,
// 'settlement_area_home_bigha' => $fmd['home_b'],
// 'settlement_area_home_katha' => $fmd['home_k'],
// 'settlement_area_home_lessa' => $fmd['home_lc'],
// 'settlement_area_home_ganda' => $fmd['home_g'],
// 'settlement_area_home_kranti' => $fmd['home_kr'],
// 'settlement_area_agri_bigha' => $fmd['agri_b'],
// 'settlement_area_agri_katha' => $fmd['agri_k'],
// 'settlement_area_agri_lessa' => $fmd['agri_lc'],
// 'settlement_area_agri_ganda' => $fmd['agri_g'],
// 'settlement_area_agri_kranti' => $fmd['agri_kr'],
// 'total_settlement_area_bigha' => $totalSettlementAreaArr[0],
// 'total_settlement_area_katha' => $totalSettlementAreaArr[1],
// 'total_settlement_area_lessa' => $totalSettlementAreaArr[2],
// 'total_settlement_area_ganda' => $totalSettlementAreaArr[3],
// 'total_settlement_area_kranti' => 0,
// 'leftout_area_home_bigha' => $leftOutAreaHomeArr[0],
// 'leftout_area_home_katha' => $leftOutAreaHomeArr[1],
// 'leftout_area_home_lessa' => $leftOutAreaHomeArr[2],
// 'leftout_area_home_ganda' => $leftOutAreaHomeArr[3],
// 'leftout_area_home_kranti' => 0,
// 'leftout_area_agri_bigha' => $leftOutAreaAgriArr[0],
// 'leftout_area_agri_katha' => $leftOutAreaAgriArr[1],
// 'leftout_area_agri_lessa' => $leftOutAreaAgriArr[2],
// 'leftout_area_agri_ganda' => $leftOutAreaAgriArr[3],
// 'leftout_area_agri_kranti' => 0,
// 'total_leftout_area_bigha' => $totalLeftOutAreaArr[0],
// 'total_leftout_area_katha' => $totalLeftOutAreaArr[1],
// 'total_leftout_area_lessa' => $totalLeftOutAreaArr[2],
// 'total_leftout_area_ganda' => $totalLeftOutAreaArr[3],
// 'total_leftout_area_kranti' => 0,
// ];
// $insertSetlArea = $this->db->insert('settlement_area_history', $settlementAreaHistoryArr);
// if ($insertSetlArea != 1) {
// $this->db->trans_rollback();
// log_message('error', '#SETLARRHIS0001: Insertion failed in settlement_area_history RTPS Case No ' . $application_no);
// $data = array(
// 'error' => "#SETLARRHIS0001: Registration of Settlement failed for case no : " . $application_no
// );
// echo json_encode($data);
// return false;
// }
//**************end of settlement_area_history********************
}
}
//*******pdar_cron number generation */
$sql = "SELECT pdar_cron_no FROM settlement_applicant WHERE case_no = '" . $case_no['case_no'] . "'";
$result = $this->db->query($sql);
if ($result->num_rows() > 0) {
$cron_no = (int)$result->row()->pdar_cron_no + 1;
} else {
$cron_no = 1;
}
//*********settlement_applicant insertion */
foreach ($district['applicants'] as $setl) {
if ($get_aadhaar_photo != 'n' && $setl->is_applicant == '1') {
$timestamp = date('mdYhis', time()) . uniqid();
$identity_doc_unique_name = str_replace('/', "-", $application_no . '_' . $timestamp);
// creating and saving the base64 format payment notice to uploads/paymentNotice folder
$aadhar_path = AADHAAR_PHOTO . $identity_doc_unique_name . ".json";
$aadhaar_file_to_write_base64 = fopen($aadhar_path, "w") or die("Unable to open file!");
$aadhaar_encoded_file = $get_aadhaar_photo;
fwrite($aadhaar_file_to_write_base64, $aadhaar_encoded_file);
fclose($aadhaar_file_to_write_base64);
} else {
$aadhar_path = '';
}
if ($district['aadhar']->type == 'AADHAAR') {
$identity_ref_no = $district['aadhar']->aadhaar_no;
} else {
$identity_ref_no = $district['aadhar']->pan_no;
}
$applicant = array(
'dist_code' => $district['app']->dist_code,
'subdiv_code' => $district['app']->subdiv_code,
'cir_code' => $district['app']->cir_code,
'mouza_pargona_code' => $district['app']->mouza_code,
'lot_no' => $district['app']->lot_no,
'vill_townprt_code' => $district['app']->village_code,
'user_code' => $this->session->userdata('user_code'),
'case_no' => $case_no['case_no'],
'petition_no' => $case_no['petition_no'],
'operation' => 'E',
'dag_no' => 0,
'patta_no' => 0,
'patta_type_code' => 0,
'year_no' => date('Y'),
'date_entry' => date('Y-m-d'),
'pdar_id' => '-1',
'pdar_cron_no' => (int) $cron_no++,
'pdar_name' => $setl->name_ass,
'pdar_guardian' => $setl->gurdian_name_ass,
'eng_pdar_name' => $setl->name_eng,
'eng_pdar_guardian' => $setl->gurdian_name_eng,
'pdar_rel_guar' => $setl->gurdian_relation_id,
'pdar_gender' => $setl->gender,
'pdar_add1' => $setl->pre_add,
'pdar_add2' => $setl->per_add,
'pdar_mobile' => $setl->mobile,
'pdar_type' => $setl->pdar_type,
'is_applicant' => $setl->is_applicant,
'identity_ref_no' => $identity_ref_no,
'identity_type' => $district['aadhar']->type,
'identity_doc_link' => $aadhar_path,
'marital_status' => $setl->marital_status,
'dob' => $setl->dob,
);
$insSetApplicant = $this->db->insert('settlement_applicant', $applicant);
// echo $this->db->last_query(); die();
if ($insSetApplicant != 1) {
// var_dump($insSetApplicant);
// echo $this->db->last_query(); die();
$this->db->trans_rollback();
log_message('error', '#ERRSET0003: Insertion failed in settlement_applicant RTPS Case No ' . $application_no);
$data = array(
'error' => "#ERRSET0003: Registration of Settlement failed for case no : " . $application_no
);
echo json_encode($data);
return false;
}
}
//*********encroachers insert in applicant table */
if ($output->encroachers == true) {
foreach ($output->encroachers as $enc_applicant) {
$encroacher_app = array(
'dist_code' => $district['app']->dist_code,
'subdiv_code' => $district['app']->subdiv_code,
'cir_code' => $district['app']->cir_code,
'mouza_pargona_code' => $district['app']->mouza_code,
'lot_no' => $district['app']->lot_no,
'vill_townprt_code' => $district['app']->village_code,
'user_code' => $this->session->userdata('user_code'),
'case_no' => $case_no['case_no'],
'petition_no' => $case_no['petition_no'],
'operation' => 'E',
'dag_no' => $enc_applicant->dag_no,
'patta_no' => $enc_applicant->patta_no,
'patta_type_code' => $enc_applicant->patta_code,
'period_possession' => $enc_applicant->possession_date,
'year_no' => date('Y'),
'date_entry' => date('Y-m-d'),
'pdar_name' => 'NA', //$enc_applicant->name_ass,
'pdar_guardian' => 'NA', //$enc_applicant->gurdian_name_ass,
'pdar_rel_guar' => '0',
'pdar_cron_no' => (int) $cron_no++,
'pdar_id' => -1,
'pdar_type' => 'EN',
'enc_id' => $enc_applicant->encroacher_id,
);
$insSetEncroacher = $this->db->insert('settlement_applicant', $encroacher_app);
// echo $this->db->last_query();
// var_dump($insSetEncroacher); die;
if ($insSetEncroacher != 1) {
$this->db->trans_rollback();
log_message('error', '#ERRSET000309: Insertion failed in settlement_applicant RTPS Case No ' . $application_no);
$data = array(
'error' => "#ERRSET000309: Registration of Settlement failed for case no : " . $application_no
);
echo json_encode($data);
return false;
}
}
}
///// nominee add start /////
if ($output->nextKin == true) {
// foreach ($_POST['kin_name'] as $key =>$value) {
foreach ($output->nextKin as $nex_of_kin) {
$nominee_data = array(
'case_no' => $case_no['case_no'],
'nominee_name' => $nex_of_kin->next_of_kin_name,
'address' => $nex_of_kin->address,
'mobile_no' => $nex_of_kin->mobile_no,
'relation' => $nex_of_kin->relation_with_kin
);
$insNominee = $this->db->insert('settlement_nominee', $nominee_data);
// echo $this->db->last_query();
// var_dump($insSetEncroacher); die();
if ($insNominee != 1) {
$this->db->trans_rollback();
log_message('error', '#ERRSET00032: Insertion failed in settlement_nominee RTPS Case No ' . $application_no);
$data = array(
'error' => "#ERRSET00032: Registration of Settlement failed for case no : " . $application_no
);
echo json_encode($data);
return false;
}
}
}
///// nominee end //////
//********basundhar_application insertation */
$basundhara = array(
'dharitree' => $case_no['case_no'],
'basundhara' => $application_no,
'date_reg' => date('Y-m-d'),
'reg_by' => $this->session->userdata('user_code'),
'app_status' => 'M',
'pending_with' => 'LM'
);
$basundhar_app = $this->db->insert('basundhar_application', $basundhara);
if ($basundhar_app != 1) {
$this->db->trans_rollback();
log_message('error', '#ERRSET0003202: Insertion failed in basundhar_application RTPS Case No ' . $application_no);
$data = array(
'error' => "#ERRSET0003202: Registration of Settlement failed for case no : " . $application_no
);
echo json_encode($data);
return false;
} else {
//
//
//******commit if no errors */
$this->db->trans_commit();
}
}
// ********************case registration from API end********* */
// ************************************************************************************** */
//******* case data fetch from db for Lm start */
$startTime = microtime(true);
try {
$sql = $this->db->query('SELECT dharitree FROM basundhar_application WHERE basundhara = ?', array($application_no));
if ($sql->num_rows() > 0) {
$case_no = $sql->row()->dharitree;
} else {
$data = array(
'error' => 'Something went wrong! please contact administration!' . $application_no,
);
echo json_encode($data);
return false;
}
//*****LM view auth for this case */
// $this->ncutility->lmAuthBasic($case_no);
$this->ncutility->lmAuthFirstProceeding($case_no);
// row_array
$basic = $this->NcServiceModel->getSettlementBasic($case_no);
// result
$applicants_buyers = $this->NcServiceModel->getAllApplicantBuyers($case_no);
$applicants_owners = $this->NcServiceModel->getAllApplicantOwners($case_no);
$applicants_encroacher = $this->NcServiceModel->getAllApplicantEncroacher($case_no);
$applicants_riotee_nok = $this->NcServiceModel->getAllApplicantRioteeNok($case_no);
$dags = $this->NcServiceModel->getSettlementDag($case_no);
$lmnotes = $this->NcServiceModel->getSettlementTenantLmNote($case_no);
$proceedings = $this->NcServiceModel->getSettlementProceeding($case_no);
$dhardocuments = $this->NcServiceModel->getDocuments($case_no);
$nominee = $this->NcServiceModel->getAllNomineeDetail($case_no);
/// premium
$lmdata['s_area'] = $this->NcCommonModel->getPremiumArea();
// new premium addition
// $lmdata['area_category'] = $this->NcCommonModel->getPremiumCategory();
$premiumData = $this->db->query("Select * from settlement_premium where case_no='$case_no' and is_final=1")->row();
$lmdata['premiumData'] = $premiumData;
/// premium end
$lmdata['basic'] = $basic;
$lmdata['geo_date'] = $geo_date;
$lmdata['applicants_buyers'] = $applicants_buyers;
$lmdata['applicants_owners'] = $applicants_owners;
$lmdata['applicants_encroacher'] = $applicants_encroacher;
$lmdata['applicants_riotee_nok'] = $applicants_riotee_nok;
$lmdata['reservation'] = $this->NcServiceModel->getSettlementReservation($case_no);
$lmdata['dags'] = $dags;
$lmdata['long'] = '91.7120705';
$lmdata['lat'] = '26.3452088';
$lmdata['location_code'] = '070201010310001';
$geo_tag_dag = json_decode($this->getDatFromLonLat($lmdata['long'], $lmdata['lat'], $lmdata['location_code']), true);
// $geo_tag_dag = json_decode('{"data": [{"PlotNo": "57"}]}', true); //Temporary
$lmdata['geo_tag_dag'] = $geo_tag_dag['data'][0]['PlotNo'];
$lmdata['lmnotes'] = $lmnotes;
$lmdata['proceedings'] = $proceedings;
$lmdata['dhardocuments'] = $dhardocuments;
$lmdata['nominee'] = $nominee;
//for dag not eligible
$lmdata['dag_count'] = count($dags);
//for encroacher not eligible
$lmdata['dag_count'] = count($dags);
$d = $basic["dist_code"];
$s = $basic["subdiv_code"];
$c = $basic["cir_code"];
$m = $basic["mouza_pargona_code"];
$l = $basic["lot_no"];
$v = $basic["vill_townprt_code"];
//*******getting the deleted settlement_dag_details data from settlement_deleted_data table */
$deletedEnc = $this->NcCommonModel->getDeletedEncroacher($case_no);
$deletedEncArray = array();
foreach ($deletedEnc as $encroacherDeleted_data) {
$deletedEncArray[] = json_decode($encroacherDeleted_data->table_data);
}
$lmdata['deleted_encroacher'] = $deletedEncArray;
//***********getting the settlement_applicant occupiers data from settlement_deleted_data table */
$deletedDags = $this->NcCommonModel->getDeletedDags($case_no);
$deletedData = array();
foreach ($deletedDags as $deleteDag) {
$deletedData[] = json_decode($deleteDag->table_data);
}
$lmdata['deleted_dags'] = $deletedData;
if (isset($applicants_encroacher)):
foreach ($applicants_encroacher as $settl_vlb_add_check):
$sqlVlbEntryQuery = $this->db->query("SELECT * FROM settlement_land_bank_details WHERE application_no = ? AND dag_no = ? AND uuid = ?", array($application_no, $settl_vlb_add_check->dag_no, $lmdata['basic']['uuid']));
if ($sqlVlbEntryQuery->num_rows() > 0) {
$settlement_land_bank_details[] = $sqlVlbEntryQuery->row();
$vlb_encroacher_added_check[] = $sqlVlbEntryQuery->row()->dag_no;
$sql = $this->db->query("SELECT dag_no, status FROM land_bank_details WHERE id = ?", array($sqlVlbEntryQuery->row()->land_bank_details_id));
$land_bank_status[] = $sql->row();
} else {
$settlement_land_bank_details[] = false;
$vlb_encroacher_added_check[] = false;
$land_bank_status[] = false;
}
endforeach;
if (isset($vlb_encroacher_added_check)):
if ($vlb_encroacher_added_check):
$lmdata['settlement_vlb_encroacher_check'] = $vlb_encroacher_added_check;
endif;
endif;
if (isset($land_bank_status)):
$lmdata['land_bank_status'] = $land_bank_status;
endif;
if (isset($settlement_land_bank_details)):
$lmdata['settlement_land_bank_details'] = $settlement_land_bank_details;
endif;
endif;
foreach ($applicants_encroacher as $encroacher_prem) {
$revenue[] = $this->db->query("Select dag_revenue,dag_area_b,dag_area_k,dag_area_lc,dag_area_g,dag_area_kr,dag_no from chitha_basic where dist_code='$d' and "
. "subdiv_code='$s' and cir_code='$c' and mouza_pargona_code='$m' and lot_no='$l' and vill_townprt_code='$v' and dag_no='$encroacher_prem->dag_no'")->result();
$lmdata['revenue'] = $revenue;
}
// calling API for self declaration data
$sql = "Select basundhara from basundhar_application where dharitree='$case_no' ";
$basundhara = $this->db->query($sql)->row();
$token = $this->LabourLineModel->createTokenJwt();
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, API_LINK_NC . "getAppDetails");
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, http_build_query(array(
'application_no' => $basundhara->basundhara,
'api_key' => API_KEY,
'token' => $token
)));
$output = curl_exec($curl_handle);
if (isset(json_decode($output)->responseType)) {
if (json_decode($output)->responseType == 3) {
echo json_decode($output)->data . " - Unauthorized access!";
return false;
}
}
curl_close($curl_handle);
$output = json_decode($output);
$lmdata['document'] = $output->documents;
$lmdata['query'] = $output->query;
$lmdata['property'] = $output->property;
$lmdata['aadhar'] = $output->aadhar;
$lmdata['nextKin'] = $output->nextKin;
foreach ($output->selfDeclaration as $selfDec) {
$lmdata['selfDeclarationDetails'] = json_decode($selfDec->dec_details);
}
// var_dump($output);
// die;
// // This changed to run the application only on 12-11-2025 By Manashjyoti Deka Start**************
// foreach ($lmdata['applicants_buyers'] as $adhar_photo):
// if ($adhar_photo->is_applicant == 1):
// if (trim($adhar_photo->identity_type) == 'AADHAAR'):
// $adhar_photo_link = $adhar_photo->identity_doc_link;
// if (!file_exists($adhar_photo_link)) {
// $url = API_LINK_NC . "getApplicantPhoto";
// $arrayData = array(
// 'application_no' => $application_no,
// );
// //*****API call again for aadhar photo missing */
// $aadhaarPhotoReCall = $this->ncutility->curlPost($url, $arrayData);
// if ($aadhaarPhotoReCall == true) {
// $aadhar_path = $adhar_photo_link;
// $aadhaar_file_to_write_base64 = fopen($aadhar_path, "w") or die("Unable to open file!");
// $aadhaar_encoded_file = $aadhaarPhotoReCall;
// fwrite($aadhaar_file_to_write_base64, $aadhaar_encoded_file);
// fclose($aadhaar_file_to_write_base64);
// } else {
// echo json_encode(array('ERROR885784: API Response fail!'));
// return false;
// }
// }
// //**********reopening the updated file */
// $open_adhar_file = fopen($adhar_photo_link, "r") or die("Unable to open file!");
// $read_adhar_file = fread($open_adhar_file, filesize($adhar_photo_link));
// fclose($open_adhar_file);
// // decoding the base64 encoding file variable
// $lmdata['base64_decoded_adhar_file'] = "<img src = data:" . $this->decodeBase64($read_adhar_file) . ";base64," . $read_adhar_file . " class='img-thumbnail' alt='Adhar Photo' width='170' height='200'>";
// endif;
// endif;
// endforeach;
// // This changed to run the application only on 12-11-2025 By Manashjyoti Deka End****************
// for guardian relation
$query_for_guar_rel = "SELECT * from master_guard_rel WHERE id NOT IN ('5','6')";
$relation_executation = $this->db->query($query_for_guar_rel);
$row = $relation_executation->num_rows();
if ($row != 0) {
$lmdata['guar_rel'] = $relation_executation->result();
}
if (!empty($dags)) {
foreach ($dags as $vlb_dag) {
$sqlvlbcheck = $this->db->query("SELECT * FROM settlement_land_bank_details WHERE application_no = ? AND dag_no = ?", array($application_no, $vlb_dag->dag_no));
if ($sqlvlbcheck->num_rows() > 0) {
$vlb_newly_added[] = $sqlvlbcheck->row()->dag_no;
} else {
$vlb_newly_added[] = false;
}
}
$lmdata['vlb_newly_added'] = $vlb_newly_added;
}
/// additional property for LM note
$additional_property = $this->db->query("Select * from settlement_additional_property where applid='$application_no'");
if ($additional_property->num_rows() > 0) {
$totallesaa = 0;
$totalganda = 0;
foreach ($additional_property->result() as $addprop) {
if (in_array($addprop->dist_code, json_decode(BARAK_VALLEY))) {
$total_g = $this->LabourLineModel->Total_ganda($addprop->bigha, $addprop->katha, $addprop->lessa, $addprop->ganda);
$totalganda = $totalganda + $total_g;
} else {
$total_l = $this->LabourLineModel->Total_Lessa($addprop->bigha, $addprop->katha, $addprop->lessa);
$totallesaa = $totallesaa + $total_l;
}
}
if (!empty($totallesaa)) {
$lmdata['total_aditional_area'] = $this->LabourLineModel->Total_Bigha_Katha_Lessa($totallesaa);
}
if (!empty($totalganda)) {
$lmdata['total_aditional_area_g'] = $this->LabourLineModel->Total_Bigha_Katha_Lessa2($totalganda);
}
$lmdata['additional_property'] = $additional_property->result();
//var_dump($lmdata['additional_property']); die;
}
$lmdata['case_no'] = $case_no;
$rejected_data = $this->NcCommonModel->getRejectModal(NC_KHAS_LAND_ID);
if ($rejected_data == 'n') {
$lmdata['rejected_list'] = false;
} else {
$lmdata['rejected_list'] = $rejected_data;
}
} catch (Exception $e) {
log_message('ERROR#LM_DATA_FETCH', 'Lm application data fetch...####' . $e);
} finally {
$endTime = microtime(true);
$timeDiff = $endTime - $startTime;
if ($timeDiff > (float)2) {
log_message('EXECUTION_TIME', $this->router->fetch_class() . '->' . $this->router->fetch_method() . ' # The execution time is : ' . $timeDiff);
}
}
//****getting tribe cat and under tribal belt data from backup */
$getJsonBackup = $this->NcServiceModel->getJsonDataFromBackup($case_no);
if (isset($getJsonBackup)) {
if ($getJsonBackup) {
$json_settlement = json_decode($getJsonBackup->data);
foreach ($json_settlement->settlements as $jsonSettle) {
if ($jsonSettle->is_applicant == 1) {
$lmdata['backup_tribe_category'] = $jsonSettle->tribe_category;
$lmdata['backup_under_tribe_belts'] = $jsonSettle->under_tribe_belts;
}
}
}
}
//************check if SK is available*/
$lmdata['sk_name'] = $this->NcCommonModel->getSkName($basic['dist_code'], $basic['subdiv_code'], $basic['cir_code']);
if ($lmdata['sk_name'] == 'n') {
//************if SK is not available then load CO */
$lmdata['sk_availability'] = 'n';
$lmdata['co_name'] = $this->NcCommonModel->getCoName($basic['dist_code'], $basic['subdiv_code'], $basic['cir_code']);
} else {
$lmdata['sk_availability'] = 'y';
}
$lmdata['co_name'] = $this->NcCommonModel->getCoName($basic['dist_code'], $basic['subdiv_code'], $basic['cir_code']);
$lmdata['co_name_reject'] = $this->NcCommonModel->getCoName($basic['dist_code'], $basic['subdiv_code'], $basic['cir_code']);
if ($lmdata['rejected_list'] != false) {
$lmdata['dagFlagCheckChitha'] = $this->NcCommonModel->getChithaFlaggedRemarks($dags, $lmdata['rejected_list']);
} else {
$lmdata['dagFlagCheckChitha'] = false;
}
$applicantsEncroacherCount = $this->NcServiceModel->countAllApplicantEncroacher($case_no);
$setEncroacherStatus = 1;
if ($applicantsEncroacherCount == 0) {
$setEncroacherStatus = 1;
} else {
$setEncroacherStatus = 1;
}
$lmdata['setEncroacherStatus'] = $setEncroacherStatus;
// initial khasland view through API
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
// echo 'Line no:1418<pre>';var_dump($lmdata);die;
$lmdata['_view'] = 'LabourLineLand/LabourLandView';
$this->load->view('layouts/main', $lmdata);
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//*******update in settlement_basic */
$sk_code = null;
$co_code = null;
// if(trim($lmdata['sk_availability']) == 'y')
if ('1' == '2') {
$pending_officer = 'SK';
$sk_code = $this->input->post('co_code');
} else {
$pending_officer = 'CO';
$co_code = $this->input->post('co_code');
}
if ($validation_bypass == 1) {
$pending_officer = 'CO';
$co_code = $this->input->post('co_code_reject');
}
$basicData = [
'status' => 'W',
'lm_code' => $this->session->userdata('user_code'),
'submission_date' => date('Y-m-d G:i:s'),
'from_office' => 'LM',
'pending_officer' => $pending_officer,
'pending_office' => $pending_officer,
'sk_code' => $sk_code,
'co_code' => $co_code,
'approve_by' => $approved_by
];
$this->db->where('case_no', $case_no);
$this->db->update('settlement_basic', $basicData);
if ($this->db->affected_rows() <= 0) {
$this->db->trans_rollback();
log_message('error', '#ERROR0011: Updation failed in settlement_basic RTPS Case No ' . $application_no);
$data = array(
'error' => "#ERROR0011: Registration of Settlement failed for case no : " . $application_no
);
echo json_encode($data);
return false;
}
//update additional property
$additional_property_check = $this->db->query("Select * from settlement_additional_property where applid='$application_no'");
if ($additional_property_check->num_rows() > 0) {
$additionalPropertyUpdate = [
'case_no' => $case_no,
];
$this->db->where('applid', $application_no);
$this->db->update('settlement_additional_property', $additionalPropertyUpdate);
if ($this->db->affected_rows() <= 0) {
$this->db->trans_rollback();
log_message('error', '#ERROR1836: Updation failed in settlement_additional_property RTPS Case No ' . $application_no);
$data = array(
'error' => "#ERROR1836: Registration of Settlement failed for case no : " . $application_no
);
echo json_encode($data);
return false;
}
}
// insertion in backup table
$phase_count = $this->db->query("SELECT COUNT(*) as ct FROM settlement_backup_json WHERE applid = '$application_no' AND from_office = 'LM'")->row()->ct;
$phase_count = (int)$phase_count + 1;
$backup_array_lm = [
'applid' => $application_no,
'case_no' => $case_no,
'from_office' => 'LM',
'to_office' => $pending_officer,
'status' => 'W',
'phase' => 'LM_' . $phase_count,
'data' => json_encode($_POST)
];
$backup_insertion_lm = $this->db->insert('settlement_backup_json', $backup_array_lm);
if ($backup_insertion_lm != 1) {
$this->db->trans_rollback();
log_message('error', '#BACKUP002: Insertion failed in settlement_backup_json RTPS Case No ' . $application_no);
$this->session->set_flashdata('message', "#BACKUP002: Registration of Settlement failed for case no : " . $application_no);
redirect(base_url() . "index.php/home");
return false;
}
// UPDATING Geo Tag Photo case number in supportive document
if (isset($lmdata['geo_tag_doc'])) {
foreach ($lmdata['geo_tag_doc'] as $geo_tag_loop) {
$geo_tag_array = array(
'case_no' => $case_no
);
$this->db->where('applid', $geo_tag_loop->applid);
$this->db->where('dag_no', $geo_tag_loop->dag_no);
$this->db->where('file_name', GEO_TAG_PHOTO);
$this->db->update('supportive_document', $geo_tag_array);
if ($this->db->affected_rows() == 0) {
$this->db->trans_rollback();
log_message('error', '#SETUP0001S: Updation failed in supportive_document basundhara Case No ' . $geo_tag_loop->applid);
$data = array(
'error' => "#SETUP0001S: Registration of Settlement failed for case no : " . $geo_tag_loop->applid
);
echo json_encode($data);
return false;
}
}
}
//*****only insert if validation bypass is 0 */
if ($validation_bypass == 0) {
foreach ($lmdata['dags'] as $dagsland) {
$landmark_east = $this->input->post('landmark_east' . $dagsland->dag_no);
$landmark_west = $this->input->post('landmark_west' . $dagsland->dag_no);
$landmark_north = $this->input->post('landmark_north' . $dagsland->dag_no);
$landmark_south = $this->input->post('landmark_south' . $dagsland->dag_no);
$landmark = [
'east' => $landmark_east,
'west' => $landmark_west,
'north' => $landmark_north,
'south' => $landmark_south,
];
$fmddata = [
'date_entry' => date('Y-m-d'),
'landmark' => json_encode($landmark),
'nature_possession' => $this->input->post('nature_possession' . $dagsland->dag_no),
];
$this->db->where('case_no', $case_no);
$this->db->where('dag_no', $dagsland->dag_no);
$this->db->update('settlement_dag_details', $fmddata);
if ($this->db->affected_rows() <= 0) {
$this->db->trans_rollback();
log_message('error', '#ERROR0012: Updation failed in settlement_dag_details RTPS Case No ' . $application_no);
$data = array(
'error' => "#ERROR0012: Registration of Settlement failed for case no : " . $application_no
);
echo json_encode($data);
return false;
}
}
// upload additional file
if (isset($_FILES['fileUpload']['name'])) {
for ($i = 0; $i < $fileCount; $i++) {
$_FILES['file']['name'] = $_FILES['fileUpload']['name'][$i];
$_FILES['file']['type'] = $_FILES['fileUpload']['type'][$i];
$_FILES['file']['tmp_name'] = $_FILES['fileUpload']['tmp_name'][$i];
$_FILES['file']['error'] = $_FILES['fileUpload']['error'][$i];
$_FILES['file']['size'] = $_FILES['fileUpload']['size'][$i];
$mime = mime_content_type($_FILES['fileUpload']['tmp_name'][$i]);
$exp = explode("/", $mime);
$onlyExtension = $exp[1];
$fileRename = $this->UUID4() . '.' . $onlyExtension;
$config['upload_path'] = UPLOAD_DIR;
$config['allowed_types'] = UPLOAD_ALLOW_TYPE;
$config['max_size'] = UPLOAD_MAX_SIZE;;
$config['file_name'] = $fileRename;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ($this->upload->do_upload('file')) {
$document = array(
'case_no' => $case_no,
'file_name' => $_POST['fileText'][$i],
'user_code' => $this->session->userdata('user_code'),
// 'fetch_file_name' => $_FILES['file']['name'],
'fetch_file_name' => $_POST['fileText'][$i],
'file_type' => $_FILES['file']['type'],
'file_path' => UPLOAD_DIR . $fileRename,
'date_entry' => date('Y-m-d h:i:s'),
'mut_type' => LABOUR_LINE_LAND_ID,
);
// save data in attachment file
$addMoreDocQuery = $this->db->insert('supportive_document', $document);
if ($addMoreDocQuery != 1) {
$this->db->trans_rollback();
log_message('error', '#ERRADDDOC0001: Insertion failed in supportive document RTPS Case No ' . $application_no);
$this->session->set_flashdata('message', "#ERRADDDOC0001: Only PDF and Image files area allowed : " . $application_no);
redirect(base_url() . "index.php/home");
return false;
}
} else {
$this->db->trans_rollback();
// todo error show
// redirect to respected route with error mgs
log_message('error', '#ERRADDDOC0001: Insertion failed in supportive document RTPS Case No ' . $application_no);
$this->session->set_flashdata('message', "#ERRADDDOC00851: Only PDF and Image files area allowed : " . $application_no);
redirect(base_url() . "index.php/home");
return false;
}
}
}
//end of additional file upload
$field_report_file = $_FILES['field_report'];
// For uploading dag wise trace_map_copy
foreach ($lmdata['dags'] as $dags_doc) {
$timestamp = date('mdYhis', time()) . uniqid();
$trace_map_file = $_FILES['trace_map_copy' . $dags_doc->dag_no];
$trace_file_name = 'trace_map_copy' . $timestamp;
//upload trace map file by calling API
$trace_map_api_file = $this->SettlementCommonModel->uploadFileByApiBase($trace_map_file, $application_no, API_KEY, $trace_file_name);
$trace_json = json_decode($trace_map_api_file);
$trace_upload_path = UPLOAD_DIR . $timestamp . $trace_map_file['name'];
if ($trace_json->status == 4) // success
{
$document = array(
'case_no' => $case_no,
'file_name' => 'Trace Map Copy',
'user_code' => $this->session->userdata('user_code'),
'fetch_file_name' => $trace_map_file['name'],
'file_type' => $trace_map_file['type'],
'file_path' => $trace_upload_path,
'date_entry' => date('Y-m-d h:i:s'),
'mut_type' => $this->input->post('service_code'),
'dag_no' => $this->input->post('dag_no_doc' . $dags_doc->dag_no),
'api_doc_id' => $trace_json->docId,
);
$insert_supportive_doc = $this->db->insert('supportive_document', $document);
if ($insert_supportive_doc != 1) {
log_message('error', '#ERRORPPSSGG: Insertion failed in supportive_document for case no :' . $this->db->last_query());
$this->db->trans_rollback();
$json = [
'errorMessage' => "#ERRORPPSSGG: Failed to forward the case for Case No : " . $case_no
];
echo json_encode($json);
return false;
}
} else {
log_message('error', 'Unable to upload trace map file for case no ' . $case_no);
$this->db->trans_rollback();
$this->session->set_flashdata('message', "#ERRADDDOC077471: Only PDF and Image files area allowed : " . $application_no);
redirect(base_url() . "index.php/home");
}
if (FILE_UPLOAD_REQUIRE_IN_DHARITREE == 1) //
{
// Trace Map copy upload
$config['file_name'] = $trace_file_name;
$config['upload_path'] = UPLOAD_DIR;
$config['allowed_types'] = UPLOAD_ALLOW_TYPE;
$config['max_size'] = 2000;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if (!move_uploaded_file($trace_map_file['tmp_name'], $trace_upload_path)) {
log_message('error', 'Unable to move trace map file for case no ' . $case_no);
$this->db->trans_rollback();
$this->session->set_flashdata('message', "#ERRADDDOC00711001: Only PDF and Image files area allowed : " . $application_no);
redirect(base_url() . "index.php/home");
}
}
}
$timestamp = date('mdYhis', time()) . uniqid();
// For uploading field report
//upload field report file by calling API
$field_file_name = 'field_report' . $timestamp;
$field_report_api_file = $this->SettlementCommonModel->uploadFileByApiBase($field_report_file, $application_no, API_KEY, $field_file_name);
$field_report_json = json_decode($field_report_api_file);
$field_report_path = UPLOAD_DIR . $timestamp . $field_report_file['name'];
if ($field_report_json->status == 4) // success
{
$document = array(
'case_no' => $case_no,
'file_name' => 'Field Report',
'user_code' => $this->session->userdata('user_code'),
'fetch_file_name' => $field_report_file['name'],
'file_type' => $field_report_file['type'],
'file_path' => $field_report_path,
'date_entry' => date('Y-m-d h:i:s'),
'mut_type' => $this->input->post('service_code'),
'api_doc_id' => $field_report_json->docId,
);
$insert_supportive_doc = $this->db->insert('supportive_document', $document);
if ($insert_supportive_doc != 1) {
$this->db->trans_rollback();
log_message('error', '#ERRORPPSSGGP: Insertion failed in supportive_document for case no :' . $case_no);
$json = [
'errorMessage' => "#ERRORPPSSGGP: Failed to forward the case for Case No : " . $case_no
];
echo json_encode($json);
return false;
}
} else {
log_message('error', 'Unable to upload field report file for case no ' . $case_no);
$this->db->trans_rollback();
$this->session->set_flashdata('message', "#ERRADDDOC00998501: Only PDF and Image files area allowed : " . $application_no);
redirect(base_url() . "index.php/home");
}
if (FILE_UPLOAD_REQUIRE_IN_DHARITREE == 1) //
{
$config2['file_name'] = $field_file_name;
$config2['upload_path'] = UPLOAD_DIR;
$config2['allowed_types'] = UPLOAD_ALLOW_TYPE;
$config2['max_size'] = 2000;
$this->load->library('upload', $config2);
$this->upload->initialize($config2);
if (!move_uploaded_file($field_report_file['tmp_name'], $field_report_path)) {
log_message('error', 'Unable to move field report file for case no ' . $case_no);
$this->db->trans_rollback();
$this->session->set_flashdata('message', "#ERRADDDOC000331: Only PDF and Image files area allowed : " . $application_no);
redirect(base_url() . "index.php/home");
}
}
//*********if LM if case of case rejected the rejected remarks */
$responseMasterObj = $this->SettlementCommonModel->lmRejectedValidationBypassFalse(LABOUR_LINE_LAND_ID);
$comment = addslashes($this->input->post('lm_note'));
$pro_class_lm = $this->input->post('protected_class_lm');
$protected_class_lm = ($pro_class_lm == null || $pro_class_lm == '' || $pro_class_lm == 0) ? 0 : $this->input->post('protected_class_lm');
$lmnote = array(
'user_code' => $this->session->userdata('user_code'),
'chitha_verified' => $this->input->post('chitha_verified'),
'vlb_verified' => $this->input->post('vlb_verified'),
'is_tribal_belt' => $this->input->post('is_tribal_belt'),
'possession_verification' => $this->input->post('possession_verification'),
'period_possession' => date('Y-m-d'),
// 'nature_possession'=>$this->input->post('nature_possession'),
'is_landless' => $this->input->post('is_landless'),
'land_falls' => $this->input->post('land_falls'),
'falls_und_gmc' => $this->input->post('falls_und_gmc'),
'roadside_reservation' => $this->input->post('roadside_reservation'),
// 'zonal_valuation'=>$this->input->post('zonal_valuation'),
// 'trace_map_copy'=>$this->input->post('trace_map_copy'),
// 'chitha_copy'=>$this->input->post('chitha_copy'),
'trace_map_copy' => 'NA',
'chitha_copy' => 'NA',
'lm_note' => $comment,
'lm_remark_text' => $this->input->post('lm_remark_text'),
'date_entry' => date('Y-m-d h:i:s'),
'case_no' => $case_no,
'status' => 'W',
'total_bigha' => $this->input->post('total_bigha'),
'total_Katha' => $this->input->post('total_Katha'),
'total_lessa' => $this->input->post('total_lessa'),
'total_ganda' => $this->input->post('total_ganda'),
'total_kranti' => $this->input->post('total_kranti'),
// 'encroacher_exist_vlb' => $this->input->post('encroacher_exist_vlb'),
'landslide' => $this->input->post('landslide'),
'erosion' => $this->input->post('erosion'),
'protected_class_lm' => $protected_class_lm,
'bhumiputra_confirmation' => $this->input->post('bhumiputra_confirmation_lm'),
'lm_rejected_remarks' => json_encode($responseMasterObj->reject_remarks)
);
$insLmnote = $this->db->insert('settlement_ap_lmnote', $lmnote);
if ($insLmnote != 1) {
$this->db->trans_rollback();
log_message('error', '#ERRSET0005: Insertion failed in settlement_ap_lmnote RTPS Case No ' . $application_no);
$data = array(
'error' => "#ERRSET0005: Registration of Settlement failed for case no : " . $application_no
);
echo json_encode($data);
return false;
}
}
if ($validation_bypass == 1) {
$this->SettlementCommonModel->firstProceedingValidationBypassTrue(
LABOUR_LINE_LAND_ID,
$case_no,
$application_no,
$lmdata['rejected_list']
);
}
//******do if only validation_bypass 0 */
if ($validation_bypass == 0) {
///// road side reserve area start /////
if ($roadside_comment_check == 'YES') {
foreach ($lmdata['dags'] as $dags) {
$reservedarea = array(
'dist_code' => $this->input->post('dist_code'),
'subdiv_code' => $this->input->post('subdiv_code'),
'cir_code' => $this->input->post('cir_code'),
'mouza_pargona_code' => $this->input->post('mouza_pargona_code'),
'lot_no' => $this->input->post('lot_no'),
'vill_townprt_code' => $this->input->post('vill_townprt_code'),
'dag_no' => $this->input->post('reserved_dag_road' . $dags->dag_no),
'patta_no' => $this->input->post('reserved_patta_road' . $dags->dag_no),
'bigha' => $this->input->post('reserved_bigha' . $dags->dag_no),
'katha' => $this->input->post('reserved_katha' . $dags->dag_no),
'lessa' => $this->input->post('reserved_lessa' . $dags->dag_no),
'ganda' => $this->input->post('reserved_ganda' . $dags->dag_no),
'kranti' => $this->input->post('reserved_kranti' . $dags->dag_no),
'case_no' => $case_no,
'applid' => $this->input->post('applid'),
'lm_code' => $this->session->userdata('user_code'),
'date_entry' => date('Y-m-d h:i:s'),
'date_update' => date('Y-m-d h:i:s'),
'type' => 'R'
);
$reserveData = $this->db->insert('settlement_reservation', $reservedarea);
// echo $this->db->last_query(); die();
if ($reserveData != 1) {
$this->db->trans_rollback();
log_message('error', '#ERRSET00052: Insertion failed in settlement_reservation RTPS Case No ' . $application_no);
$data = array(
'error' => "#ERRSET00052: Registration of Settlement failed for case no : " . $application_no
);
echo json_encode($data);
return false;
}
}
}
if ($family_comment_check == 'YES') {
foreach ($lmdata['dags'] as $dags) {
$reservedarea = array(
'dist_code' => $this->input->post('dist_code'),
'subdiv_code' => $this->input->post('subdiv_code'),
'cir_code' => $this->input->post('cir_code'),
'mouza_pargona_code' => $this->input->post('mouza_pargona_code'),
'lot_no' => $this->input->post('lot_no'),
'vill_townprt_code' => $this->input->post('vill_townprt_code'),
'dag_no' => $this->input->post('reserved_dag_family' . $dags->dag_no),
'patta_no' => $this->input->post('reserved_patta_family' . $dags->dag_no),
'bigha' => $this->input->post('reserved_bigha_family' . $dags->dag_no),
'katha' => $this->input->post('reserved_katha_family' . $dags->dag_no),
'lessa' => $this->input->post('reserved_lessa_family' . $dags->dag_no),
'ganda' => $this->input->post('reserved_ganda_family' . $dags->dag_no),
'kranti' => $this->input->post('reserved_kranti_family' . $dags->dag_no),
'case_no' => $case_no,
'applid' => $this->input->post('applid'),
'lm_code' => $this->session->userdata('user_code'),
'date_entry' => date('Y-m-d h:i:s'),
'date_update' => date('Y-m-d h:i:s'),
'type' => 'F'
);
$reserveData = $this->db->insert('settlement_reservation', $reservedarea);
// echo $this->db->last_query(); die();
if ($reserveData != 1) {
$this->db->trans_rollback();
log_message('error', '#ERRSET00053: Insertion failed in settlement_reservation RTPS Case No ' . $application_no);
$data = array(
'error' => "#ERRSET00053: Registration of Settlement failed for case no : " . $application_no
);
echo json_encode($data);
return false;
}
}
}
///// family reserve area end //////
//////proceeding start//////
$proceeding_id = $this->db->query("Select max(proceeding_id)+1 as c from settlement_proceeding where case_no='$case_no' ")->row()->c;
if ($proceeding_id == null) {
$proceeding_id = 1;
}
$insPetProceed = [
'case_no' => $case_no,
'proceeding_id' => $proceeding_id,
'date_of_hearing' => date('Y-m-d h:i:s'),
'next_date_of_hearing' => date('Y-m-d h:i:s'),
'note_on_order' => $this->input->post('lm_remark_text'),
'status' => 'W',
'user_code' => $this->session->userdata('user_code'),
'date_entry' => date('Y-m-d h:i:s'),
'operation' => 'E',
'ip' => $this->utilityclass->get_client_ip(),
'office_from' => 'LM',
'office_to' => $pending_officer,
'task' => 'LM note submitted'
];
$insertProceeding = $this->db->insert('settlement_proceeding', $insPetProceed);
// echo $this->db->last_query(); die();
if ($insertProceeding != 1) {
$this->db->trans_rollback();
log_message('error', '#ERRORPP: Insertion failed in settlement_proceeding for case no :' . $case_no);
$json = [
'errorMessage' => "#ERRORPP: Failed to forward the case for Case No : " . $case_no
];
echo json_encode($json);
return false;
}
//////proceeding end//////
////settlement Khas LM Report insert end
if ($this->db->trans_status() == false) {
$this->db->trans_rollback();
$data = array(
'error' => "Error in submitting. Please try Again"
);
} else {
//////////////POST To basundhara/////////////////////
// $rmk = 'Forwarded to ' . $pending_officer;
// $status = 'M';
// $task = 'LM';
// $pen = 'CO';
// // $pen=$pending_officer;
// $case = $case_no;
// $rtps_status = $this->SettlementApiModel->postApiBasundhara($application_no, $case, $rmk, $status, $task, $pen);
// $rtps_status = json_decode($rtps_status);
// if (trim($rtps_status) != "y") {
// $this->db->trans_rollback();
// $this->session->set_flashdata('message', "Error #ERRAPP0011: Settlement Application not submitted case no # $case_no");
// redirect(base_url() . "index.php/home");
// } else {
//
}
$this->db->trans_commit();
$this->session->set_flashdata('message', "Application Successfully Forwarded to " . $pending_officer . " With Case No # " . $case_no);
redirect(base_url() . "index.php/home");
}
}
{
$this->db = $this->load->database('db2', TRUE);
$lmdata['district_all'] = $this->db->query("Select * from district_details")->result();
$this->LabourLineModel->dbSwitchSession();
$application_no = $this->input->get('app');
$application_no = $this->LabourLineModel->decryptJwtCase($application_no);
// $geo_date_query = $this->db->query("Select date_entry from supportive_document where applid='$application_no'")->row();
$this->db->select('date_entry');
$this->db->from('supportive_document');
$this->db->where('applid', $application_no);
$geo_date_query = $this->db->get()->row();
$geo_date = isset($geo_date_query->date_entry) ? $geo_date_query->date_entry : '.....';
$sql = "SELECT * FROM supportive_document WHERE id IN ( SELECT MAX(id) FROM supportive_document WHERE applid = ? AND dag_no IS NOT NULL AND file_name = ? GROUP BY applid, dag_no)";
$supportive_document_sql = $this->db->query($sql, array($application_no, GEO_TAG_PHOTO));
if ($supportive_document_sql->num_rows() > 0) {
$lmdata['geo_tag_doc'] = $supportive_document_sql->result();
} else {
$lmdata['geo_tag_doc_empty'] = "<span class='text-danger alert-danger'><b>Geo tag photo yet to be uploaded.</b></span>";
}
//********************case registration from API start ********* */
//********************check and insert if case not registered */
$recordExist = $this->LabourLineModel->checkExistDharitree($application_no);
if (!$recordExist) {
/// additional property for LM note
// $additional_property = $this->db->query("Select * from settlement_additional_property where applid='$application_no'");
$this->db->select('*');
$this->db->from('settlement_additional_property');
$this->db->where('applid', $application_no);
$additional_property = $this->db->get();
if ($additional_property->num_rows() > 0) {
$totallesaa = 0;
$totalganda = 0;
foreach ($additional_property->result() as $addprop) {
if (in_array($addprop->dist_code, json_decode(BARAK_VALLEY))) {
$total_g = $this->LabourLineModel->Total_ganda($addprop->bigha, $addprop->katha, $addprop->lessa, $addprop->ganda);
$totalganda = $totalganda + $total_g;
} else {
$total_l = $this->LabourLineModel->Total_Lessa($addprop->bigha, $addprop->katha, $addprop->lessa);
$totallesaa = $totallesaa + $total_l;
}
}
if (!empty($totallesaa)) {
$district['total_aditional_area'] = $this->LabourLineModel->Total_Bigha_Katha_Lessa($totallesaa);
}
if (!empty($totalganda)) {
$district['total_aditional_area_g'] = $this->LabourLineModel->Total_Bigha_Katha_Lessa2($totalganda);
}
$district['additional_property'] = $additional_property->result();
//var_dump($district['additional_property']); die;
}
$token = $this->LabourLineModel->createTokenJwt();
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, API_LINK_NC . "getAppDetails");
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, http_build_query(array(
'application_no' => $application_no,
'api_key' => API_KEY,
'token' => $token
)));
$output = curl_exec($curl_handle);
// var_dump($output);
// die;
if (isset(json_decode($output)->responseType)) {
if (json_decode($output)->responseType == 3) {
echo json_decode($output)->data . " - Unauthorized access!";
return false;
}
}
curl_close($curl_handle);
$backup = $output;
$output = json_decode($output);
//****************generate case number********************
$case_name = $this->LabourLineModel->genearteCaseName();
if (empty($case_name)) {
$data = array(
'error' => "Network Issue or Session Out. Please try Again"
);
echo json_encode($data);
die();
}
//*******generating petition_no and case_no */
$case_no['petition_no'] = $petition_no = $this->LabourLineModel->genearteSettlementPetitionNo();
$case_no['case_no'] = $case_name . $petition_no . "/" . LABOUR_LINE_LAND;
$district['geo_date'] = $geo_date;
$district['app'] = $output->application;
$district['pattaNo'] = $this->ncutility->getPattaTypeNo($district['app']->dist_code, $district['app']->subdiv_code, $district['app']->cir_code, $district['app']->mouza_code, $district['app']->lot_no, $district['app']->village_code, $district['app']->dag_no);
$district['applicants'] = $output->applicants;
$district['document'] = $output->documents;
$district['query'] = $output->query;
$district['property'] = $output->property;
$district['settlements'] = $output->settlements;
$district['encroachers'] = $output->encroachers;
$district['owners'] = $output->owners;
$district['riotee_noks'] = $output->riotee_noks;
$district['aadhar'] = $output->aadhar;
$district['nextKin'] = $output->nextKin;
// get khatian number
$d = $district['app']->dist_code;
$s = $district['app']->subdiv_code;
$c = $district['app']->cir_code;
$m = $district['app']->mouza_code;
$l = $district['app']->lot_no;
$v = $district['app']->village_code;
// $pno=$district['pattaNo']->patta_no;
// $pc=$district['pattaNo']->patta_type_code;
$dag = $district['app']->dag_no;
$district['co_name'] = $this->NcCommonModel->getCoName($d, $s, $c);
$district['s_area'] = $this->NcCommonModel->getPremiumArea();
$district['bhumi'] = $output->bhumi;
// for guardian relation
$query_for_guar_rel = "SELECT * from master_guard_rel WHERE id NOT IN ('5','6')";
$relation_executation = $this->db->query($query_for_guar_rel);
$row = $relation_executation->num_rows();
if ($row != 0) {
$district['guar_rel'] = $relation_executation->result();
}
if ($this->ncutility->checkUserAuthForCaseForLm($d, $s, $c, $m, $l) == false) {
$this->session->set_flashdata('message', "Unauthorized access for case no # " . $application_no);
redirect(base_url() . "index.php/home");
}
// fetch riotee noks -js- 05-09-2022
if ($output->riotee_noks == true) {
$district['riotee_nok'] = $output->riotee_noks;
}
// $district['selfDeclarationDetails'] = $output->selfDeclaration;
foreach ($output->selfDeclaration as $selfDec) {
$district['selfDeclarationDetails'] = json_decode($selfDec->dec_details);
}
$vlb_encc = [];
if ($output->encroachers == true) {
$district['riotee'] = $output->encroachers;
foreach ($output->encroachers as $encroacher) {
$vlb_encroacher = $this->NcServiceModel->getEncroacherDetails($d, $s, $c, $m, $l, $v, $encroacher->dag_no);
$district['vlb_enc'] = $vlb_encroacher;
if ($vlb_encroacher == true) {
// getting the encroacher details
$vlb_encroacher_in_dag = $this->NcServiceModel->getEncroacherInDag($vlb_encroacher->id);
$vlb_encc[] = $vlb_encroacher_in_dag;
} else {
$district['empty_err'] = "No Land Bank Details found!!";
}
}
$district['vlb_enc_details'] = $vlb_encc;
}
// aadhaar photo api
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, API_LINK_NC . "getApplicantPhoto");
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, http_build_query(array(
'application_no' => $application_no,
)));
$get_aadhaar_photo = curl_exec($curl_handle);
curl_close($curl_handle);
// if ($get_aadhaar_photo != 'n') {
// $district['aadhaar_b64_decoded'] = "<img src = data:" . $this->decodeBase64($get_aadhaar_photo) . ";base64," . $get_aadhaar_photo . " class='img-thumbnail' alt='Adhar Photo' width='170' height='200'>";
// }
$this->db->trans_begin();
// insertion in backup table (lm)
$backup_array = [
'applid' => $application_no,
'case_no' => $case_no['case_no'],
// 'from_office' => '',
// 'to_office' => '',
'status' => 'I',
// 'phase' => '',
'data' => $backup
];
$backup_insertion = $this->db->insert('settlement_backup_json', $backup_array);
if ($backup_insertion != 1) {
$this->db->trans_rollback();
log_message('error', '#BACKUP001: Insertion failed in settlement_backup_json RTPS Case No ' . $application_no);
$this->session->set_flashdata('message', "#BACKUP001: Registration of Settlement failed for case no : " . $application_no);
redirect(base_url() . "index.php/home");
return false;
}
///////// additional property starts here
$checkAdditionalProperty = $this->db->query("SELECT * FROM settlement_additional_property
WHERE applid=?", array($application_no));
if ($checkAdditionalProperty->num_rows() == 0) {
if (isset($output->property)) {
foreach ($output->property as $value) {
$add_property = array(
'case_no' => $case_no['case_no'],
'dist_code' => $value->dist_code,
'subdiv_code' => $value->subdiv_code,
'cir_code' => $value->cir_code,
'mouza_pargona_code' => $value->mouza_pargona_code,
'lot_no' => $value->lot_no,
'vill_townprt_code' => $value->vill_townprt_code,
'bigha' => $value->bigha,
'katha' => $value->katha,
'lessa' => $value->lessa,
'chatak' => $value->lessa,
'ganda' => $value->ganda,
'kranti' => $value->kranti,
'entry_date' => date('Y-m-d h:i:s'),
'is_rural' => $value->is_rural,
'dag_no' => $value->dag_no,
'patta_no' => $value->patta_no,
'service_id' => LABOUR_LINE_LAND_ID,
'applied_flag' => CITIZEN,
'dist_name' => trim($value->dist_name),
'cir_name' => trim($value->cir_name),
'vill_name' => trim($value->vill_name),
'applid' => $application_no,
);
$insAddProperty = $this->db->insert('settlement_additional_property', $add_property);
if ($insAddProperty != 1) {
$this->db->trans_rollback();
log_message('error', '#ERROR393: Insertion failed in settlement_additional_property RTPS Case No ' . $application_no);
$data = array(
'error' => "#ERROR393: Registration of Settlement failed for case no : " . $application_no
);
echo json_encode($data);
return false;
}
}
}
}
///////// additional property ends here
$pro_class = $this->input->post('protected_class');
$protected_class_vr = ($pro_class == null || $pro_class == '' || $pro_class == 0) ? 0 : $this->input->post('protected_class');
//****bhumiputra condition prepare for insertation */
if (!empty($output->bhumi['0'])) {
if ($output->bhumi['0']->bhumi_cert_available == 1) { //if bhumiputra available
$bhumiputra_confirmation = 'YES';
$bhumiputra_certificate_no = $output->bhumi['0']->bhumi_ack_no;
$bhumiputra_certificate_type = 'CERT';
} else if ($output->bhumi['0']->is_bhumi_applied == 1) { //if applied in bhumiputra
$bhumiputra_confirmation = 'YES';
$bhumiputra_certificate_no = $output->bhumi['0']->bhumi_ack_no;
$bhumiputra_certificate_type = 'ACK';
} else {
$bhumiputra_confirmation = '0';
$bhumiputra_certificate_no = '0';
$bhumiputra_certificate_type = '0';
}
} else {
$bhumiputra_confirmation = '0';
$bhumiputra_certificate_no = '0';
$bhumiputra_certificate_type = '0';
}
//********settlement_basic insertation */
$basic = array(
'dist_code' => $district['app']->dist_code,
'subdiv_code' => $district['app']->subdiv_code,
'cir_code' => $district['app']->cir_code,
'mouza_pargona_code' => $district['app']->mouza_code,
'lot_no' => $district['app']->lot_no,
'vill_townprt_code' => $district['app']->village_code,
'service_code' => $district['app']->service_code,
'ref_no' => $district['app']->ref_no,
'case_no' => $case_no['case_no'],
'trans_code' => 'F', /////////full
'petition_no' => $case_no['petition_no'],
'year_no' => date('Y'),
'date_entry' => date('Y-m-d G:i:s'),
'status' => 'Z',
'user_code' => $this->session->userdata('user_code'),
// 'lm_code' => $this->session->userdata('user_code'),
'submission_date' => date('Y-m-d G:i:s'),
'from_office' => 'API',
'pending_officer' => 'LM',
'pending_office' => 'CO',
'occupation_applicant' => $district['applicants'][0]->applicant_occupation,
'applid' => $district['app']->application_no,
'caste' => $district['applicants'][0]->caste_category,
'uuid' => $district['app']->uuid,
'protected_class' => $protected_class_vr,
'bhumiputra_confirmation' => $bhumiputra_confirmation,
'bhumiputra_certificate_no' => $bhumiputra_certificate_no,
'bhumiputra_certificate_type' => $bhumiputra_certificate_type,
// 'co_code' => $this->input->post('co_code')
'is_tribal' => ($district['app']->service_applied_for == 'SLLL') ? 0 : 1,
);
$insSetBasic = $this->db->insert('settlement_basic', $basic);
// echo $this->db->last_query(); die();
if ($insSetBasic != 1) {
$this->db->trans_rollback();
log_message('error', '#ERRSET00011: Insertion failed in settlement_basic RTPS Case No ' . $application_no);
$data = array(
'error' => "#ERRSET00011: Registration of Settlement failed for case no : " . $application_no
);
echo json_encode($data);
return false;
}
////settlement_dag_details insert start
if ($district['encroachers'] == false || empty($district['encroachers']) || $district['encroachers'] == '') {
// $api_dag={
// 'plot':'15'
// };
// $this->db->trans_rollback();
// log_message('error', '#ERRSET004545: Insertion failed settlement_dag details empty RTPS Case No ' . $application_no);
// log_message("error", "#ENCROACHER_DETAIL: " . $district['encroachers']);
// log_message('error', '#ENCROACHER_DETAIL: Insertion failed settlement_dag details ' . $this->db->last_query);
// log_message('error', '#ENCROACHER_DETAIL: Application_no ' . $application_no);
// log_message('error', '#ENCROACHER_DETAIL: API response ' . json_encode($output));
// $data = array(
// 'error' => "#ERRSET004545: Registration of Settlement failed for case no : " . $application_no
// );
// echo json_encode($data);
// return false;
} else {
foreach ($district['encroachers'] as $dags) {
$district['class'] = $this->ncutility->getPattaTypeNo($district['app']->dist_code, $district['app']->subdiv_code, $district['app']->cir_code, $district['app']->mouza_code, $district['app']->lot_no, $district['app']->village_code, $dags->dag_no);
// $enc_home_bigha = $dags->mbigha;
// $enc_home_katha = $dags->mkatha;
// $enc_home_lessa = $dags->mlessa;
// $enc_home_ganda = $dags->mganda;
// $enc_home_kranti = $dags->mkranti;
// $enc_agri_bigha = $dags->agri_bigha;
// $enc_agri_katha = $dags->agri_katha;
// $enc_agri_lessa = $dags->agri_lessa;
// $enc_agri_ganda = $dags->agri_ganda;
// $enc_agri_kranti = $dags->agri_kranti;
// $encroachment_area = [
// 'homestead' => [
// 'bigha' => $enc_home_bigha,
// 'katha' => $enc_home_katha,
// 'lessa' => $enc_home_lessa,
// 'ganda' => $enc_home_ganda,
// 'kranti' => $enc_home_kranti,
// ],
// 'agriculture' => [
// 'bigha' => $enc_agri_bigha,
// 'katha' => $enc_agri_katha,
// 'lessa' => $enc_agri_lessa,
// 'ganda' => $enc_agri_ganda,
// 'kranti' => $enc_agri_kranti,
// ],
// ];
$fmd = array(
'dist_code' => $district['app']->dist_code,
'subdiv_code' => $district['app']->subdiv_code,
'cir_code' => $district['app']->cir_code,
'mouza_pargona_code' => $district['app']->mouza_code,
'lot_no' => $district['app']->lot_no,
'vill_townprt_code' => $district['app']->village_code,
'user_code' => $this->session->userdata('user_code'),
'date_entry' => date('Y-m-d'),
'case_no' => $case_no['case_no'],
'petition_no' => $case_no['petition_no'],
'year_no' => date('Y'),
'new_land_class_code' => $district['class']->land_class_code,
'dag_no' => $dags->dag_no,
'patta_no' => $dags->patta_no,
'patta_type_code' => $dags->patta_code,
'is_urban' => $district['app']->is_urban,
'land_type' => $dags->land_type,
'revenue' => 0,
'operation' => 'E',
);
$fmd['dag_area_b'] = $dags->available_bigha;
$fmd['dag_area_k'] = $dags->available_katha;
$fmd['dag_area_lc'] = $dags->available_lessa;
$fmd['dag_area_g'] = $dags->available_ganda;
$fmd['dag_area_kr'] = $dags->available_kranti;
$insSetDag = $this->db->insert('settlement_dag_details', $fmd);
// log_message('error',$this->db->last_query());
if ($insSetDag != 1) {
$this->db->trans_rollback();
log_message('error', '#ERRSET0002_1: Insertion failed in settlement_dag_details RTPS Case No ' . $application_no);
log_message('error', "#ERRSET0002_2: Insertion failed in settlement_dag_details RTPS Case No $application_no == " . $this->db->last_query());
$data = array(
'error' => "#ERRSET0002: Registration of Settlement failed for case no : " . $application_no
);
echo json_encode($data);
return false;
}
//*******insertion in settlement_area_history**************
// if (in_array($district['app']->dist_code, json_decode(BARAK_VALLEY))) {
// //***********actual Encroachment area ***************
// $actual_encroachment_area_home_ganda = $this->LabourLineModel->Total_ganda($enc_home_bigha, $enc_home_katha, $enc_home_lessa, $enc_home_ganda);
// $actual_encroachment_area_agri_ganda = $this->LabourLineModel->Total_ganda($enc_agri_bigha, $enc_agri_katha, $enc_agri_lessa, $enc_agri_ganda);
// //***********total Actual Encroachment area*****************
// $total_actual_encroachment_area_ganda = (float)$actual_encroachment_area_home_ganda + (float)$actual_encroachment_area_agri_ganda;
// $totalEncroachmentAreaArr = $this->LabourLineModel->Total_Bigha_Katha_Lessa2($total_actual_encroachment_area_ganda);
// // **********************************************
// //***********Settlement area that applicant will get settlement on***********
// $total_settlement_ganda_home = $this->LabourLineModel->Total_ganda($fmd['home_b'], $fmd['home_k'], $fmd['home_lc'], $fmd['home_g']);
// $total_settlement_ganda_agri = $this->LabourLineModel->Total_ganda($fmd['agri_b'], $fmd['agri_k'], $fmd['agri_lc'], $fmd['agri_g']);
// //*****total Settlement area *************/
// $total_settlement_ganda = (float)$total_settlement_ganda_home + (float)$total_settlement_ganda_agri;
// $totalSettlementAreaArr = $this->LabourLineModel->Total_Bigha_Katha_Lessa2($total_settlement_ganda);
// //*************leftout area homestead**************
// $leftOutAreaHomeGanda = (float)$actual_encroachment_area_home_ganda - (float)$total_settlement_ganda_home;
// $leftOutAreaHomeArr = $this->LabourLineModel->Total_Bigha_Katha_Lessa2($leftOutAreaHomeGanda);
// //**********Ileftout area agriculture**************
// $leftOutAreaAgriGanda = (float)$actual_encroachment_area_agri_ganda - (float)$total_settlement_ganda_agri;
// $leftOutAreaAgriArr = $this->LabourLineModel->Total_Bigha_Katha_Lessa2($leftOutAreaAgriGanda);
// //**********Total left out area***************
// $totalLeftOutAreaGanda = (float)$total_actual_encroachment_area_ganda - (float)$total_settlement_ganda;
// $totalLeftOutAreaArr = $this->LabourLineModel->Total_Bigha_Katha_Lessa2($totalLeftOutAreaGanda);
// } else {
// //********actual Encroachment area**********
// $actual_encroachment_area_home_lessa = $this->LabourLineModel->Total_Lessa($enc_home_bigha, $enc_home_katha, $enc_home_lessa);
// $actual_encroachment_area_agri_lessa = $this->LabourLineModel->Total_Lessa($enc_agri_bigha, $enc_agri_katha, $enc_agri_lessa);
// //***********total Actual Encroachment area*****************
// $total_actual_encroachment_area_lessa = (float)$actual_encroachment_area_home_lessa + (float)$actual_encroachment_area_agri_lessa;
// $totalEncroachmentAreaArr = $this->LabourLineModel->Total_Bigha_Katha_Lessa($total_actual_encroachment_area_lessa);
// // **********************************************
// //*******Settlement area that applicant will get settlement on**********
// $total_settlement_lessa_home = $this->LabourLineModel->Total_Lessa($fmd['home_b'], $fmd['home_k'], $fmd['home_lc']);
// $total_settlement_lessa_agri = $this->LabourLineModel->Total_Lessa($fmd['agri_b'], $fmd['agri_k'], $fmd['agri_lc']);
// //*************Total settlement area */
// $total_settlement_lessa = (float)$total_settlement_lessa_home + (float)$total_settlement_lessa_agri;
// $totalSettlementAreaArr = $this->LabourLineModel->Total_Bigha_Katha_Lessa($total_settlement_lessa);
// //****************leftout area homestead**************
// $leftOutAreaHomeLessa = (float)$actual_encroachment_area_home_lessa - (float)$total_settlement_lessa_home;
// $leftOutAreaHomeArr = $this->LabourLineModel->Total_Bigha_Katha_Lessa($leftOutAreaHomeLessa);
// //*************leftout area agriculture*****************
// $leftOutAreaAgriLessa = (float)$actual_encroachment_area_agri_lessa - (float)$total_settlement_lessa_agri;
// $leftOutAreaAgriArr = $this->LabourLineModel->Total_Bigha_Katha_Lessa($leftOutAreaAgriLessa);
// //**********Total left out area***************
// $totalLeftOutArealessa = (float)$total_actual_encroachment_area_lessa - (float)$total_settlement_lessa;
// $totalLeftOutAreaArr = $this->LabourLineModel->Total_Bigha_Katha_Lessa($totalLeftOutArealessa);
// }
// $settlementAreaHistoryArr = [
// 'application_no' => $application_no,
// 'case_no' => $case_no['case_no'],
// 'dag_no' => $dags->dag_no,
// 'uuid' => $district['app']->uuid,
// 'created_at' => date('Y-m-d'),
// // 'applied_area_home_bigha' => $dags->mbigha,
// 'applied_area_home_katha' => $dags->mkatha,
// 'applied_area_home_lessa' => $dags->mlessa,
// 'applied_area_home_ganda' => $dags->mganda,
// 'applied_area_home_kranti' => $dags->mkranti,
// 'applied_area_agri_bigha' => $dags->agri_bigha,
// 'applied_area_agri_katha' => $dags->agri_katha,
// 'applied_area_agri_lessa' => $dags->agri_lessa,
// 'applied_area_agri_ganda' => $dags->agri_ganda,
// 'applied_area_agri_kranti' => $dags->agri_kranti,
// 'actual_encroachment_area_home_bigha' => $enc_home_bigha,
// 'actual_encroachment_area_home_katha' => $enc_home_katha,
// 'actual_encroachment_area_home_lessa' => $enc_home_lessa,
// 'actual_encroachment_area_home_ganda' => $enc_home_ganda,
// 'actual_encroachment_area_home_kranti' => $enc_home_kranti,
// 'actual_encroachment_area_agri_bigha' => $enc_agri_bigha,
// 'actual_encroachment_area_agri_katha' => $enc_agri_katha,
// 'actual_encroachment_area_agri_lessa' => $enc_agri_lessa,
// 'actual_encroachment_area_agri_ganda' => $enc_agri_ganda,
// 'actual_encroachment_area_agri_kranti' => $enc_agri_kranti,
// 'total_actual_encroachment_area_bigha' => $totalEncroachmentAreaArr[0],
// 'total_actual_encroachment_area_katha' => $totalEncroachmentAreaArr[1],
// 'total_actual_encroachment_area_lessa' => $totalEncroachmentAreaArr[2],
// 'total_actual_encroachment_area_ganda' => $totalEncroachmentAreaArr[3],
// 'total_actual_encroachment_area_kranti' => 0,
// 'settlement_area_home_bigha' => $fmd['home_b'],
// 'settlement_area_home_katha' => $fmd['home_k'],
// 'settlement_area_home_lessa' => $fmd['home_lc'],
// 'settlement_area_home_ganda' => $fmd['home_g'],
// 'settlement_area_home_kranti' => $fmd['home_kr'],
// 'settlement_area_agri_bigha' => $fmd['agri_b'],
// 'settlement_area_agri_katha' => $fmd['agri_k'],
// 'settlement_area_agri_lessa' => $fmd['agri_lc'],
// 'settlement_area_agri_ganda' => $fmd['agri_g'],
// 'settlement_area_agri_kranti' => $fmd['agri_kr'],
// 'total_settlement_area_bigha' => $totalSettlementAreaArr[0],
// 'total_settlement_area_katha' => $totalSettlementAreaArr[1],
// 'total_settlement_area_lessa' => $totalSettlementAreaArr[2],
// 'total_settlement_area_ganda' => $totalSettlementAreaArr[3],
// 'total_settlement_area_kranti' => 0,
// 'leftout_area_home_bigha' => $leftOutAreaHomeArr[0],
// 'leftout_area_home_katha' => $leftOutAreaHomeArr[1],
// 'leftout_area_home_lessa' => $leftOutAreaHomeArr[2],
// 'leftout_area_home_ganda' => $leftOutAreaHomeArr[3],
// 'leftout_area_home_kranti' => 0,
// 'leftout_area_agri_bigha' => $leftOutAreaAgriArr[0],
// 'leftout_area_agri_katha' => $leftOutAreaAgriArr[1],
// 'leftout_area_agri_lessa' => $leftOutAreaAgriArr[2],
// 'leftout_area_agri_ganda' => $leftOutAreaAgriArr[3],
// 'leftout_area_agri_kranti' => 0,
// 'total_leftout_area_bigha' => $totalLeftOutAreaArr[0],
// 'total_leftout_area_katha' => $totalLeftOutAreaArr[1],
// 'total_leftout_area_lessa' => $totalLeftOutAreaArr[2],
// 'total_leftout_area_ganda' => $totalLeftOutAreaArr[3],
// 'total_leftout_area_kranti' => 0,
// ];
// $insertSetlArea = $this->db->insert('settlement_area_history', $settlementAreaHistoryArr);
// if ($insertSetlArea != 1) {
// $this->db->trans_rollback();
// log_message('error', '#SETLARRHIS0001: Insertion failed in settlement_area_history RTPS Case No ' . $application_no);
// $data = array(
// 'error' => "#SETLARRHIS0001: Registration of Settlement failed for case no : " . $application_no
// );
// echo json_encode($data);
// return false;
// }
//**************end of settlement_area_history********************
}
}
//*******pdar_cron number generation */
$sql = "SELECT pdar_cron_no FROM settlement_applicant WHERE case_no = '" . $case_no['case_no'] . "'";
$result = $this->db->query($sql);
if ($result->num_rows() > 0) {
$cron_no = (int)$result->row()->pdar_cron_no + 1;
} else {
$cron_no = 1;
}
//*********settlement_applicant insertion */
foreach ($district['applicants'] as $setl) {
if ($get_aadhaar_photo != 'n' && $setl->is_applicant == '1') {
$timestamp = date('mdYhis', time()) . uniqid();
$identity_doc_unique_name = str_replace('/', "-", $application_no . '_' . $timestamp);
// creating and saving the base64 format payment notice to uploads/paymentNotice folder
$aadhar_path = AADHAAR_PHOTO . $identity_doc_unique_name . ".json";
$aadhaar_file_to_write_base64 = fopen($aadhar_path, "w") or die("Unable to open file!");
$aadhaar_encoded_file = $get_aadhaar_photo;
fwrite($aadhaar_file_to_write_base64, $aadhaar_encoded_file);
fclose($aadhaar_file_to_write_base64);
} else {
$aadhar_path = '';
}
if ($district['aadhar']->type == 'AADHAAR') {
$identity_ref_no = $district['aadhar']->aadhaar_no;
} else {
$identity_ref_no = $district['aadhar']->pan_no;
}
$applicant = array(
'dist_code' => $district['app']->dist_code,
'subdiv_code' => $district['app']->subdiv_code,
'cir_code' => $district['app']->cir_code,
'mouza_pargona_code' => $district['app']->mouza_code,
'lot_no' => $district['app']->lot_no,
'vill_townprt_code' => $district['app']->village_code,
'user_code' => $this->session->userdata('user_code'),
'case_no' => $case_no['case_no'],
'petition_no' => $case_no['petition_no'],
'operation' => 'E',
'dag_no' => 0,
'patta_no' => 0,
'patta_type_code' => 0,
'year_no' => date('Y'),
'date_entry' => date('Y-m-d'),
'pdar_id' => '-1',
'pdar_cron_no' => (int) $cron_no++,
'pdar_name' => $setl->name_ass,
'pdar_guardian' => $setl->gurdian_name_ass,
'eng_pdar_name' => $setl->name_eng,
'eng_pdar_guardian' => $setl->gurdian_name_eng,
'pdar_rel_guar' => $setl->gurdian_relation_id,
'pdar_gender' => $setl->gender,
'pdar_add1' => $setl->pre_add,
'pdar_add2' => $setl->per_add,
'pdar_mobile' => $setl->mobile,
'pdar_type' => $setl->pdar_type,
'is_applicant' => $setl->is_applicant,
'identity_ref_no' => $identity_ref_no,
'identity_type' => $district['aadhar']->type,
'identity_doc_link' => $aadhar_path,
'marital_status' => $setl->marital_status,
'dob' => $setl->dob,
);
$insSetApplicant = $this->db->insert('settlement_applicant', $applicant);
// echo $this->db->last_query(); die();
if ($insSetApplicant != 1) {
// var_dump($insSetApplicant);
// echo $this->db->last_query(); die();
$this->db->trans_rollback();
log_message('error', '#ERRSET0003: Insertion failed in settlement_applicant RTPS Case No ' . $application_no);
$data = array(
'error' => "#ERRSET0003: Registration of Settlement failed for case no : " . $application_no
);
echo json_encode($data);
return false;
}
}
//*********encroachers insert in applicant table */
if ($output->encroachers == true) {
foreach ($output->encroachers as $enc_applicant) {
$encroacher_app = array(
'dist_code' => $district['app']->dist_code,
'subdiv_code' => $district['app']->subdiv_code,
'cir_code' => $district['app']->cir_code,
'mouza_pargona_code' => $district['app']->mouza_code,
'lot_no' => $district['app']->lot_no,
'vill_townprt_code' => $district['app']->village_code,
'user_code' => $this->session->userdata('user_code'),
'case_no' => $case_no['case_no'],
'petition_no' => $case_no['petition_no'],
'operation' => 'E',
'dag_no' => $enc_applicant->dag_no,
'patta_no' => $enc_applicant->patta_no,
'patta_type_code' => $enc_applicant->patta_code,
'period_possession' => $enc_applicant->possession_date,
'year_no' => date('Y'),
'date_entry' => date('Y-m-d'),
'pdar_name' => 'NA', //$enc_applicant->name_ass,
'pdar_guardian' => 'NA', //$enc_applicant->gurdian_name_ass,
'pdar_rel_guar' => '0',
'pdar_cron_no' => (int) $cron_no++,
'pdar_id' => -1,
'pdar_type' => 'EN',
'enc_id' => $enc_applicant->encroacher_id,
);
$insSetEncroacher = $this->db->insert('settlement_applicant', $encroacher_app);
// echo $this->db->last_query();
// var_dump($insSetEncroacher); die;
if ($insSetEncroacher != 1) {
$this->db->trans_rollback();
log_message('error', '#ERRSET000309: Insertion failed in settlement_applicant RTPS Case No ' . $application_no);
$data = array(
'error' => "#ERRSET000309: Registration of Settlement failed for case no : " . $application_no
);
echo json_encode($data);
return false;
}
}
}
///// nominee add start /////
if ($output->nextKin == true) {
// foreach ($_POST['kin_name'] as $key =>$value) {
foreach ($output->nextKin as $nex_of_kin) {
$nominee_data = array(
'case_no' => $case_no['case_no'],
'nominee_name' => $nex_of_kin->next_of_kin_name,
'address' => $nex_of_kin->address,
'mobile_no' => $nex_of_kin->mobile_no,
'relation' => $nex_of_kin->relation_with_kin
);
$insNominee = $this->db->insert('settlement_nominee', $nominee_data);
// echo $this->db->last_query();
// var_dump($insSetEncroacher); die();
if ($insNominee != 1) {
$this->db->trans_rollback();
log_message('error', '#ERRSET00032: Insertion failed in settlement_nominee RTPS Case No ' . $application_no);
$data = array(
'error' => "#ERRSET00032: Registration of Settlement failed for case no : " . $application_no
);
echo json_encode($data);
return false;
}
}
}
///// nominee end //////
//********basundhar_application insertation */
$basundhara = array(
'dharitree' => $case_no['case_no'],
'basundhara' => $application_no,
'date_reg' => date('Y-m-d'),
'reg_by' => $this->session->userdata('user_code'),
'app_status' => 'M',
'pending_with' => 'LM'
);
$basundhar_app = $this->db->insert('basundhar_application', $basundhara);
if ($basundhar_app != 1) {
$this->db->trans_rollback();
log_message('error', '#ERRSET0003202: Insertion failed in basundhar_application RTPS Case No ' . $application_no);
$data = array(
'error' => "#ERRSET0003202: Registration of Settlement failed for case no : " . $application_no
);
echo json_encode($data);
return false;
} else {
//
//
//******commit if no errors */
$this->db->trans_commit();
}
}
// ********************case registration from API end********* */
// ************************************************************************************** */
//******* case data fetch from db for Lm start */
$startTime = microtime(true);
try {
$sql = $this->db->query('SELECT dharitree FROM basundhar_application WHERE basundhara = ?', array($application_no));
if ($sql->num_rows() > 0) {
$case_no = $sql->row()->dharitree;
} else {
$data = array(
'error' => 'Something went wrong! please contact administration!' . $application_no,
);
echo json_encode($data);
return false;
}
//*****LM view auth for this case */
// $this->ncutility->lmAuthBasic($case_no);
$this->ncutility->lmAuthFirstProceeding($case_no);
// row_array
$basic = $this->NcServiceModel->getSettlementBasic($case_no);
// result
$applicants_buyers = $this->NcServiceModel->getAllApplicantBuyers($case_no);
$applicants_owners = $this->NcServiceModel->getAllApplicantOwners($case_no);
$applicants_encroacher = $this->NcServiceModel->getAllApplicantEncroacher($case_no);
$applicants_riotee_nok = $this->NcServiceModel->getAllApplicantRioteeNok($case_no);
$dags = $this->NcServiceModel->getSettlementDag($case_no);
$lmnotes = $this->NcServiceModel->getSettlementTenantLmNote($case_no);
$proceedings = $this->NcServiceModel->getSettlementProceeding($case_no);
$dhardocuments = $this->NcServiceModel->getDocuments($case_no);
$nominee = $this->NcServiceModel->getAllNomineeDetail($case_no);
/// premium
$lmdata['s_area'] = $this->NcCommonModel->getPremiumArea();
// new premium addition
// $lmdata['area_category'] = $this->NcCommonModel->getPremiumCategory();
$premiumData = $this->db->query("Select * from settlement_premium where case_no='$case_no' and is_final=1")->row();
$lmdata['premiumData'] = $premiumData;
/// premium end
$lmdata['basic'] = $basic;
$lmdata['geo_date'] = $geo_date;
$lmdata['applicants_buyers'] = $applicants_buyers;
$lmdata['applicants_owners'] = $applicants_owners;
$lmdata['applicants_encroacher'] = $applicants_encroacher;
$lmdata['applicants_riotee_nok'] = $applicants_riotee_nok;
$lmdata['reservation'] = $this->NcServiceModel->getSettlementReservation($case_no);
$lmdata['dags'] = $dags;
$lmdata['long'] = '91.7120705';
$lmdata['lat'] = '26.3452088';
$lmdata['location_code'] = '070201010310001';
$geo_tag_dag = json_decode($this->getDatFromLonLat($lmdata['long'], $lmdata['lat'], $lmdata['location_code']), true);
// $geo_tag_dag = json_decode('{"data": [{"PlotNo": "57"}]}', true); //Temporary
$lmdata['geo_tag_dag'] = $geo_tag_dag['data'][0]['PlotNo'];
$lmdata['lmnotes'] = $lmnotes;
$lmdata['proceedings'] = $proceedings;
$lmdata['dhardocuments'] = $dhardocuments;
$lmdata['nominee'] = $nominee;
//for dag not eligible
$lmdata['dag_count'] = count($dags);
//for encroacher not eligible
$lmdata['dag_count'] = count($dags);
$d = $basic["dist_code"];
$s = $basic["subdiv_code"];
$c = $basic["cir_code"];
$m = $basic["mouza_pargona_code"];
$l = $basic["lot_no"];
$v = $basic["vill_townprt_code"];
//*******getting the deleted settlement_dag_details data from settlement_deleted_data table */
$deletedEnc = $this->NcCommonModel->getDeletedEncroacher($case_no);
$deletedEncArray = array();
foreach ($deletedEnc as $encroacherDeleted_data) {
$deletedEncArray[] = json_decode($encroacherDeleted_data->table_data);
}
$lmdata['deleted_encroacher'] = $deletedEncArray;
//***********getting the settlement_applicant occupiers data from settlement_deleted_data table */
$deletedDags = $this->NcCommonModel->getDeletedDags($case_no);
$deletedData = array();
foreach ($deletedDags as $deleteDag) {
$deletedData[] = json_decode($deleteDag->table_data);
}
$lmdata['deleted_dags'] = $deletedData;
if (isset($applicants_encroacher)):
foreach ($applicants_encroacher as $settl_vlb_add_check):
$sqlVlbEntryQuery = $this->db->query("SELECT * FROM settlement_land_bank_details WHERE application_no = ? AND dag_no = ? AND uuid = ?", array($application_no, $settl_vlb_add_check->dag_no, $lmdata['basic']['uuid']));
if ($sqlVlbEntryQuery->num_rows() > 0) {
$settlement_land_bank_details[] = $sqlVlbEntryQuery->row();
$vlb_encroacher_added_check[] = $sqlVlbEntryQuery->row()->dag_no;
$sql = $this->db->query("SELECT dag_no, status FROM land_bank_details WHERE id = ?", array($sqlVlbEntryQuery->row()->land_bank_details_id));
$land_bank_status[] = $sql->row();
} else {
$settlement_land_bank_details[] = false;
$vlb_encroacher_added_check[] = false;
$land_bank_status[] = false;
}
endforeach;
if (isset($vlb_encroacher_added_check)):
if ($vlb_encroacher_added_check):
$lmdata['settlement_vlb_encroacher_check'] = $vlb_encroacher_added_check;
endif;
endif;
if (isset($land_bank_status)):
$lmdata['land_bank_status'] = $land_bank_status;
endif;
if (isset($settlement_land_bank_details)):
$lmdata['settlement_land_bank_details'] = $settlement_land_bank_details;
endif;
endif;
foreach ($applicants_encroacher as $encroacher_prem) {
$revenue[] = $this->db->query("Select dag_revenue,dag_area_b,dag_area_k,dag_area_lc,dag_area_g,dag_area_kr,dag_no from chitha_basic where dist_code='$d' and "
. "subdiv_code='$s' and cir_code='$c' and mouza_pargona_code='$m' and lot_no='$l' and vill_townprt_code='$v' and dag_no='$encroacher_prem->dag_no'")->result();
$lmdata['revenue'] = $revenue;
}
// calling API for self declaration data
$sql = "Select basundhara from basundhar_application where dharitree='$case_no' ";
$basundhara = $this->db->query($sql)->row();
$token = $this->LabourLineModel->createTokenJwt();
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, API_LINK_NC . "getAppDetails");
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, http_build_query(array(
'application_no' => $basundhara->basundhara,
'api_key' => API_KEY,
'token' => $token
)));
$output = curl_exec($curl_handle);
if (isset(json_decode($output)->responseType)) {
if (json_decode($output)->responseType == 3) {
echo json_decode($output)->data . " - Unauthorized access!";
return false;
}
}
curl_close($curl_handle);
$output = json_decode($output);
$lmdata['document'] = $output->documents;
$lmdata['query'] = $output->query;
$lmdata['property'] = $output->property;
$lmdata['aadhar'] = $output->aadhar;
$lmdata['nextKin'] = $output->nextKin;
foreach ($output->selfDeclaration as $selfDec) {
$lmdata['selfDeclarationDetails'] = json_decode($selfDec->dec_details);
}
// var_dump($output);
// die;
// // This changed to run the application only on 12-11-2025 By Manashjyoti Deka Start**************
// foreach ($lmdata['applicants_buyers'] as $adhar_photo):
// if ($adhar_photo->is_applicant == 1):
// if (trim($adhar_photo->identity_type) == 'AADHAAR'):
// $adhar_photo_link = $adhar_photo->identity_doc_link;
// if (!file_exists($adhar_photo_link)) {
// $url = API_LINK_NC . "getApplicantPhoto";
// $arrayData = array(
// 'application_no' => $application_no,
// );
// //*****API call again for aadhar photo missing */
// $aadhaarPhotoReCall = $this->ncutility->curlPost($url, $arrayData);
// if ($aadhaarPhotoReCall == true) {
// $aadhar_path = $adhar_photo_link;
// $aadhaar_file_to_write_base64 = fopen($aadhar_path, "w") or die("Unable to open file!");
// $aadhaar_encoded_file = $aadhaarPhotoReCall;
// fwrite($aadhaar_file_to_write_base64, $aadhaar_encoded_file);
// fclose($aadhaar_file_to_write_base64);
// } else {
// echo json_encode(array('ERROR885784: API Response fail!'));
// return false;
// }
// }
// //**********reopening the updated file */
// $open_adhar_file = fopen($adhar_photo_link, "r") or die("Unable to open file!");
// $read_adhar_file = fread($open_adhar_file, filesize($adhar_photo_link));
// fclose($open_adhar_file);
// // decoding the base64 encoding file variable
// $lmdata['base64_decoded_adhar_file'] = "<img src = data:" . $this->decodeBase64($read_adhar_file) . ";base64," . $read_adhar_file . " class='img-thumbnail' alt='Adhar Photo' width='170' height='200'>";
// endif;
// endif;
// endforeach;
// // This changed to run the application only on 12-11-2025 By Manashjyoti Deka End****************
// for guardian relation
$query_for_guar_rel = "SELECT * from master_guard_rel WHERE id NOT IN ('5','6')";
$relation_executation = $this->db->query($query_for_guar_rel);
$row = $relation_executation->num_rows();
if ($row != 0) {
$lmdata['guar_rel'] = $relation_executation->result();
}
if (!empty($dags)) {
foreach ($dags as $vlb_dag) {
$sqlvlbcheck = $this->db->query("SELECT * FROM settlement_land_bank_details WHERE application_no = ? AND dag_no = ?", array($application_no, $vlb_dag->dag_no));
if ($sqlvlbcheck->num_rows() > 0) {
$vlb_newly_added[] = $sqlvlbcheck->row()->dag_no;
} else {
$vlb_newly_added[] = false;
}
}
$lmdata['vlb_newly_added'] = $vlb_newly_added;
}
/// additional property for LM note
$additional_property = $this->db->query("Select * from settlement_additional_property where applid='$application_no'");
if ($additional_property->num_rows() > 0) {
$totallesaa = 0;
$totalganda = 0;
foreach ($additional_property->result() as $addprop) {
if (in_array($addprop->dist_code, json_decode(BARAK_VALLEY))) {
$total_g = $this->LabourLineModel->Total_ganda($addprop->bigha, $addprop->katha, $addprop->lessa, $addprop->ganda);
$totalganda = $totalganda + $total_g;
} else {
$total_l = $this->LabourLineModel->Total_Lessa($addprop->bigha, $addprop->katha, $addprop->lessa);
$totallesaa = $totallesaa + $total_l;
}
}
if (!empty($totallesaa)) {
$lmdata['total_aditional_area'] = $this->LabourLineModel->Total_Bigha_Katha_Lessa($totallesaa);
}
if (!empty($totalganda)) {
$lmdata['total_aditional_area_g'] = $this->LabourLineModel->Total_Bigha_Katha_Lessa2($totalganda);
}
$lmdata['additional_property'] = $additional_property->result();
//var_dump($lmdata['additional_property']); die;
}
$lmdata['case_no'] = $case_no;
$rejected_data = $this->NcCommonModel->getRejectModal(NC_KHAS_LAND_ID);
if ($rejected_data == 'n') {
$lmdata['rejected_list'] = false;
} else {
$lmdata['rejected_list'] = $rejected_data;
}
} catch (Exception $e) {
log_message('ERROR#LM_DATA_FETCH', 'Lm application data fetch...####' . $e);
} finally {
$endTime = microtime(true);
$timeDiff = $endTime - $startTime;
if ($timeDiff > (float)2) {
log_message('EXECUTION_TIME', $this->router->fetch_class() . '->' . $this->router->fetch_method() . ' # The execution time is : ' . $timeDiff);
}
}
//****getting tribe cat and under tribal belt data from backup */
$getJsonBackup = $this->NcServiceModel->getJsonDataFromBackup($case_no);
if (isset($getJsonBackup)) {
if ($getJsonBackup) {
$json_settlement = json_decode($getJsonBackup->data);
foreach ($json_settlement->settlements as $jsonSettle) {
if ($jsonSettle->is_applicant == 1) {
$lmdata['backup_tribe_category'] = $jsonSettle->tribe_category;
$lmdata['backup_under_tribe_belts'] = $jsonSettle->under_tribe_belts;
}
}
}
}
//************check if SK is available*/
$lmdata['sk_name'] = $this->NcCommonModel->getSkName($basic['dist_code'], $basic['subdiv_code'], $basic['cir_code']);
if ($lmdata['sk_name'] == 'n') {
//************if SK is not available then load CO */
$lmdata['sk_availability'] = 'n';
$lmdata['co_name'] = $this->NcCommonModel->getCoName($basic['dist_code'], $basic['subdiv_code'], $basic['cir_code']);
} else {
$lmdata['sk_availability'] = 'y';
}
$lmdata['co_name'] = $this->NcCommonModel->getCoName($basic['dist_code'], $basic['subdiv_code'], $basic['cir_code']);
$lmdata['co_name_reject'] = $this->NcCommonModel->getCoName($basic['dist_code'], $basic['subdiv_code'], $basic['cir_code']);
if ($lmdata['rejected_list'] != false) {
$lmdata['dagFlagCheckChitha'] = $this->NcCommonModel->getChithaFlaggedRemarks($dags, $lmdata['rejected_list']);
} else {
$lmdata['dagFlagCheckChitha'] = false;
}
$applicantsEncroacherCount = $this->NcServiceModel->countAllApplicantEncroacher($case_no);
$setEncroacherStatus = 1;
if ($applicantsEncroacherCount == 0) {
$setEncroacherStatus = 1;
} else {
$setEncroacherStatus = 1;
}
$lmdata['setEncroacherStatus'] = $setEncroacherStatus;
// initial khasland view through API
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
// echo 'Line no:1418<pre>';var_dump($lmdata);die;
$lmdata['_view'] = 'LabourLineLand/LabourLandView';
$this->load->view('layouts/main', $lmdata);
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//*******update in settlement_basic */
$sk_code = null;
$co_code = null;
// if(trim($lmdata['sk_availability']) == 'y')
if ('1' == '2') {
$pending_officer = 'SK';
$sk_code = $this->input->post('co_code');
} else {
$pending_officer = 'CO';
$co_code = $this->input->post('co_code');
}
if ($validation_bypass == 1) {
$pending_officer = 'CO';
$co_code = $this->input->post('co_code_reject');
}
$basicData = [
'status' => 'W',
'lm_code' => $this->session->userdata('user_code'),
'submission_date' => date('Y-m-d G:i:s'),
'from_office' => 'LM',
'pending_officer' => $pending_officer,
'pending_office' => $pending_officer,
'sk_code' => $sk_code,
'co_code' => $co_code,
'approve_by' => $approved_by
];
$this->db->where('case_no', $case_no);
$this->db->update('settlement_basic', $basicData);
if ($this->db->affected_rows() <= 0) {
$this->db->trans_rollback();
log_message('error', '#ERROR0011: Updation failed in settlement_basic RTPS Case No ' . $application_no);
$data = array(
'error' => "#ERROR0011: Registration of Settlement failed for case no : " . $application_no
);
echo json_encode($data);
return false;
}
//update additional property
$additional_property_check = $this->db->query("Select * from settlement_additional_property where applid='$application_no'");
if ($additional_property_check->num_rows() > 0) {
$additionalPropertyUpdate = [
'case_no' => $case_no,
];
$this->db->where('applid', $application_no);
$this->db->update('settlement_additional_property', $additionalPropertyUpdate);
if ($this->db->affected_rows() <= 0) {
$this->db->trans_rollback();
log_message('error', '#ERROR1836: Updation failed in settlement_additional_property RTPS Case No ' . $application_no);
$data = array(
'error' => "#ERROR1836: Registration of Settlement failed for case no : " . $application_no
);
echo json_encode($data);
return false;
}
}
// insertion in backup table
$phase_count = $this->db->query("SELECT COUNT(*) as ct FROM settlement_backup_json WHERE applid = '$application_no' AND from_office = 'LM'")->row()->ct;
$phase_count = (int)$phase_count + 1;
$backup_array_lm = [
'applid' => $application_no,
'case_no' => $case_no,
'from_office' => 'LM',
'to_office' => $pending_officer,
'status' => 'W',
'phase' => 'LM_' . $phase_count,
'data' => json_encode($_POST)
];
$backup_insertion_lm = $this->db->insert('settlement_backup_json', $backup_array_lm);
if ($backup_insertion_lm != 1) {
$this->db->trans_rollback();
log_message('error', '#BACKUP002: Insertion failed in settlement_backup_json RTPS Case No ' . $application_no);
$this->session->set_flashdata('message', "#BACKUP002: Registration of Settlement failed for case no : " . $application_no);
redirect(base_url() . "index.php/home");
return false;
}
// UPDATING Geo Tag Photo case number in supportive document
if (isset($lmdata['geo_tag_doc'])) {
foreach ($lmdata['geo_tag_doc'] as $geo_tag_loop) {
$geo_tag_array = array(
'case_no' => $case_no
);
$this->db->where('applid', $geo_tag_loop->applid);
$this->db->where('dag_no', $geo_tag_loop->dag_no);
$this->db->where('file_name', GEO_TAG_PHOTO);
$this->db->update('supportive_document', $geo_tag_array);
if ($this->db->affected_rows() == 0) {
$this->db->trans_rollback();
log_message('error', '#SETUP0001S: Updation failed in supportive_document basundhara Case No ' . $geo_tag_loop->applid);
$data = array(
'error' => "#SETUP0001S: Registration of Settlement failed for case no : " . $geo_tag_loop->applid
);
echo json_encode($data);
return false;
}
}
}
//*****only insert if validation bypass is 0 */
if ($validation_bypass == 0) {
foreach ($lmdata['dags'] as $dagsland) {
$landmark_east = $this->input->post('landmark_east' . $dagsland->dag_no);
$landmark_west = $this->input->post('landmark_west' . $dagsland->dag_no);
$landmark_north = $this->input->post('landmark_north' . $dagsland->dag_no);
$landmark_south = $this->input->post('landmark_south' . $dagsland->dag_no);
$landmark = [
'east' => $landmark_east,
'west' => $landmark_west,
'north' => $landmark_north,
'south' => $landmark_south,
];
$fmddata = [
'date_entry' => date('Y-m-d'),
'landmark' => json_encode($landmark),
'nature_possession' => $this->input->post('nature_possession' . $dagsland->dag_no),
];
$this->db->where('case_no', $case_no);
$this->db->where('dag_no', $dagsland->dag_no);
$this->db->update('settlement_dag_details', $fmddata);
if ($this->db->affected_rows() <= 0) {
$this->db->trans_rollback();
log_message('error', '#ERROR0012: Updation failed in settlement_dag_details RTPS Case No ' . $application_no);
$data = array(
'error' => "#ERROR0012: Registration of Settlement failed for case no : " . $application_no
);
echo json_encode($data);
return false;
}
}
// upload additional file
if (isset($_FILES['fileUpload']['name'])) {
for ($i = 0; $i < $fileCount; $i++) {
$_FILES['file']['name'] = $_FILES['fileUpload']['name'][$i];
$_FILES['file']['type'] = $_FILES['fileUpload']['type'][$i];
$_FILES['file']['tmp_name'] = $_FILES['fileUpload']['tmp_name'][$i];
$_FILES['file']['error'] = $_FILES['fileUpload']['error'][$i];
$_FILES['file']['size'] = $_FILES['fileUpload']['size'][$i];
$mime = mime_content_type($_FILES['fileUpload']['tmp_name'][$i]);
$exp = explode("/", $mime);
$onlyExtension = $exp[1];
$fileRename = $this->UUID4() . '.' . $onlyExtension;
$config['upload_path'] = UPLOAD_DIR;
$config['allowed_types'] = UPLOAD_ALLOW_TYPE;
$config['max_size'] = UPLOAD_MAX_SIZE;;
$config['file_name'] = $fileRename;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ($this->upload->do_upload('file')) {
$document = array(
'case_no' => $case_no,
'file_name' => $_POST['fileText'][$i],
'user_code' => $this->session->userdata('user_code'),
// 'fetch_file_name' => $_FILES['file']['name'],
'fetch_file_name' => $_POST['fileText'][$i],
'file_type' => $_FILES['file']['type'],
'file_path' => UPLOAD_DIR . $fileRename,
'date_entry' => date('Y-m-d h:i:s'),
'mut_type' => LABOUR_LINE_LAND_ID,
);
// save data in attachment file
$addMoreDocQuery = $this->db->insert('supportive_document', $document);
if ($addMoreDocQuery != 1) {
$this->db->trans_rollback();
log_message('error', '#ERRADDDOC0001: Insertion failed in supportive document RTPS Case No ' . $application_no);
$this->session->set_flashdata('message', "#ERRADDDOC0001: Only PDF and Image files area allowed : " . $application_no);
redirect(base_url() . "index.php/home");
return false;
}
} else {
$this->db->trans_rollback();
// todo error show
// redirect to respected route with error mgs
log_message('error', '#ERRADDDOC0001: Insertion failed in supportive document RTPS Case No ' . $application_no);
$this->session->set_flashdata('message', "#ERRADDDOC00851: Only PDF and Image files area allowed : " . $application_no);
redirect(base_url() . "index.php/home");
return false;
}
}
}
//end of additional file upload
$field_report_file = $_FILES['field_report'];
// For uploading dag wise trace_map_copy
foreach ($lmdata['dags'] as $dags_doc) {
$timestamp = date('mdYhis', time()) . uniqid();
$trace_map_file = $_FILES['trace_map_copy' . $dags_doc->dag_no];
$trace_file_name = 'trace_map_copy' . $timestamp;
//upload trace map file by calling API
$trace_map_api_file = $this->SettlementCommonModel->uploadFileByApiBase($trace_map_file, $application_no, API_KEY, $trace_file_name);
$trace_json = json_decode($trace_map_api_file);
$trace_upload_path = UPLOAD_DIR . $timestamp . $trace_map_file['name'];
if ($trace_json->status == 4) // success
{
$document = array(
'case_no' => $case_no,
'file_name' => 'Trace Map Copy',
'user_code' => $this->session->userdata('user_code'),
'fetch_file_name' => $trace_map_file['name'],
'file_type' => $trace_map_file['type'],
'file_path' => $trace_upload_path,
'date_entry' => date('Y-m-d h:i:s'),
'mut_type' => $this->input->post('service_code'),
'dag_no' => $this->input->post('dag_no_doc' . $dags_doc->dag_no),
'api_doc_id' => $trace_json->docId,
);
$insert_supportive_doc = $this->db->insert('supportive_document', $document);
if ($insert_supportive_doc != 1) {
log_message('error', '#ERRORPPSSGG: Insertion failed in supportive_document for case no :' . $this->db->last_query());
$this->db->trans_rollback();
$json = [
'errorMessage' => "#ERRORPPSSGG: Failed to forward the case for Case No : " . $case_no
];
echo json_encode($json);
return false;
}
} else {
log_message('error', 'Unable to upload trace map file for case no ' . $case_no);
$this->db->trans_rollback();
$this->session->set_flashdata('message', "#ERRADDDOC077471: Only PDF and Image files area allowed : " . $application_no);
redirect(base_url() . "index.php/home");
}
if (FILE_UPLOAD_REQUIRE_IN_DHARITREE == 1) //
{
// Trace Map copy upload
$config['file_name'] = $trace_file_name;
$config['upload_path'] = UPLOAD_DIR;
$config['allowed_types'] = UPLOAD_ALLOW_TYPE;
$config['max_size'] = 2000;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if (!move_uploaded_file($trace_map_file['tmp_name'], $trace_upload_path)) {
log_message('error', 'Unable to move trace map file for case no ' . $case_no);
$this->db->trans_rollback();
$this->session->set_flashdata('message', "#ERRADDDOC00711001: Only PDF and Image files area allowed : " . $application_no);
redirect(base_url() . "index.php/home");
}
}
}
$timestamp = date('mdYhis', time()) . uniqid();
// For uploading field report
//upload field report file by calling API
$field_file_name = 'field_report' . $timestamp;
$field_report_api_file = $this->SettlementCommonModel->uploadFileByApiBase($field_report_file, $application_no, API_KEY, $field_file_name);
$field_report_json = json_decode($field_report_api_file);
$field_report_path = UPLOAD_DIR . $timestamp . $field_report_file['name'];
if ($field_report_json->status == 4) // success
{
$document = array(
'case_no' => $case_no,
'file_name' => 'Field Report',
'user_code' => $this->session->userdata('user_code'),
'fetch_file_name' => $field_report_file['name'],
'file_type' => $field_report_file['type'],
'file_path' => $field_report_path,
'date_entry' => date('Y-m-d h:i:s'),
'mut_type' => $this->input->post('service_code'),
'api_doc_id' => $field_report_json->docId,
);
$insert_supportive_doc = $this->db->insert('supportive_document', $document);
if ($insert_supportive_doc != 1) {
$this->db->trans_rollback();
log_message('error', '#ERRORPPSSGGP: Insertion failed in supportive_document for case no :' . $case_no);
$json = [
'errorMessage' => "#ERRORPPSSGGP: Failed to forward the case for Case No : " . $case_no
];
echo json_encode($json);
return false;
}
} else {
log_message('error', 'Unable to upload field report file for case no ' . $case_no);
$this->db->trans_rollback();
$this->session->set_flashdata('message', "#ERRADDDOC00998501: Only PDF and Image files area allowed : " . $application_no);
redirect(base_url() . "index.php/home");
}
if (FILE_UPLOAD_REQUIRE_IN_DHARITREE == 1) //
{
$config2['file_name'] = $field_file_name;
$config2['upload_path'] = UPLOAD_DIR;
$config2['allowed_types'] = UPLOAD_ALLOW_TYPE;
$config2['max_size'] = 2000;
$this->load->library('upload', $config2);
$this->upload->initialize($config2);
if (!move_uploaded_file($field_report_file['tmp_name'], $field_report_path)) {
log_message('error', 'Unable to move field report file for case no ' . $case_no);
$this->db->trans_rollback();
$this->session->set_flashdata('message', "#ERRADDDOC000331: Only PDF and Image files area allowed : " . $application_no);
redirect(base_url() . "index.php/home");
}
}
//*********if LM if case of case rejected the rejected remarks */
$responseMasterObj = $this->SettlementCommonModel->lmRejectedValidationBypassFalse(LABOUR_LINE_LAND_ID);
$comment = addslashes($this->input->post('lm_note'));
$pro_class_lm = $this->input->post('protected_class_lm');
$protected_class_lm = ($pro_class_lm == null || $pro_class_lm == '' || $pro_class_lm == 0) ? 0 : $this->input->post('protected_class_lm');
$lmnote = array(
'user_code' => $this->session->userdata('user_code'),
'chitha_verified' => $this->input->post('chitha_verified'),
'vlb_verified' => $this->input->post('vlb_verified'),
'is_tribal_belt' => $this->input->post('is_tribal_belt'),
'possession_verification' => $this->input->post('possession_verification'),
'period_possession' => date('Y-m-d'),
// 'nature_possession'=>$this->input->post('nature_possession'),
'is_landless' => $this->input->post('is_landless'),
'land_falls' => $this->input->post('land_falls'),
'falls_und_gmc' => $this->input->post('falls_und_gmc'),
'roadside_reservation' => $this->input->post('roadside_reservation'),
// 'zonal_valuation'=>$this->input->post('zonal_valuation'),
// 'trace_map_copy'=>$this->input->post('trace_map_copy'),
// 'chitha_copy'=>$this->input->post('chitha_copy'),
'trace_map_copy' => 'NA',
'chitha_copy' => 'NA',
'lm_note' => $comment,
'lm_remark_text' => $this->input->post('lm_remark_text'),
'date_entry' => date('Y-m-d h:i:s'),
'case_no' => $case_no,
'status' => 'W',
'total_bigha' => $this->input->post('total_bigha'),
'total_Katha' => $this->input->post('total_Katha'),
'total_lessa' => $this->input->post('total_lessa'),
'total_ganda' => $this->input->post('total_ganda'),
'total_kranti' => $this->input->post('total_kranti'),
// 'encroacher_exist_vlb' => $this->input->post('encroacher_exist_vlb'),
'landslide' => $this->input->post('landslide'),
'erosion' => $this->input->post('erosion'),
'protected_class_lm' => $protected_class_lm,
'bhumiputra_confirmation' => $this->input->post('bhumiputra_confirmation_lm'),
'lm_rejected_remarks' => json_encode($responseMasterObj->reject_remarks)
);
$insLmnote = $this->db->insert('settlement_ap_lmnote', $lmnote);
if ($insLmnote != 1) {
$this->db->trans_rollback();
log_message('error', '#ERRSET0005: Insertion failed in settlement_ap_lmnote RTPS Case No ' . $application_no);
$data = array(
'error' => "#ERRSET0005: Registration of Settlement failed for case no : " . $application_no
);
echo json_encode($data);
return false;
}
}
if ($validation_bypass == 1) {
$this->SettlementCommonModel->firstProceedingValidationBypassTrue(
LABOUR_LINE_LAND_ID,
$case_no,
$application_no,
$lmdata['rejected_list']
);
}
//******do if only validation_bypass 0 */
if ($validation_bypass == 0) {
///// road side reserve area start /////
if ($roadside_comment_check == 'YES') {
foreach ($lmdata['dags'] as $dags) {
$reservedarea = array(
'dist_code' => $this->input->post('dist_code'),
'subdiv_code' => $this->input->post('subdiv_code'),
'cir_code' => $this->input->post('cir_code'),
'mouza_pargona_code' => $this->input->post('mouza_pargona_code'),
'lot_no' => $this->input->post('lot_no'),
'vill_townprt_code' => $this->input->post('vill_townprt_code'),
'dag_no' => $this->input->post('reserved_dag_road' . $dags->dag_no),
'patta_no' => $this->input->post('reserved_patta_road' . $dags->dag_no),
'bigha' => $this->input->post('reserved_bigha' . $dags->dag_no),
'katha' => $this->input->post('reserved_katha' . $dags->dag_no),
'lessa' => $this->input->post('reserved_lessa' . $dags->dag_no),
'ganda' => $this->input->post('reserved_ganda' . $dags->dag_no),
'kranti' => $this->input->post('reserved_kranti' . $dags->dag_no),
'case_no' => $case_no,
'applid' => $this->input->post('applid'),
'lm_code' => $this->session->userdata('user_code'),
'date_entry' => date('Y-m-d h:i:s'),
'date_update' => date('Y-m-d h:i:s'),
'type' => 'R'
);
$reserveData = $this->db->insert('settlement_reservation', $reservedarea);
// echo $this->db->last_query(); die();
if ($reserveData != 1) {
$this->db->trans_rollback();
log_message('error', '#ERRSET00052: Insertion failed in settlement_reservation RTPS Case No ' . $application_no);
$data = array(
'error' => "#ERRSET00052: Registration of Settlement failed for case no : " . $application_no
);
echo json_encode($data);
return false;
}
}
}
if ($family_comment_check == 'YES') {
foreach ($lmdata['dags'] as $dags) {
$reservedarea = array(
'dist_code' => $this->input->post('dist_code'),
'subdiv_code' => $this->input->post('subdiv_code'),
'cir_code' => $this->input->post('cir_code'),
'mouza_pargona_code' => $this->input->post('mouza_pargona_code'),
'lot_no' => $this->input->post('lot_no'),
'vill_townprt_code' => $this->input->post('vill_townprt_code'),
'dag_no' => $this->input->post('reserved_dag_family' . $dags->dag_no),
'patta_no' => $this->input->post('reserved_patta_family' . $dags->dag_no),
'bigha' => $this->input->post('reserved_bigha_family' . $dags->dag_no),
'katha' => $this->input->post('reserved_katha_family' . $dags->dag_no),
'lessa' => $this->input->post('reserved_lessa_family' . $dags->dag_no),
'ganda' => $this->input->post('reserved_ganda_family' . $dags->dag_no),
'kranti' => $this->input->post('reserved_kranti_family' . $dags->dag_no),
'case_no' => $case_no,
'applid' => $this->input->post('applid'),
'lm_code' => $this->session->userdata('user_code'),
'date_entry' => date('Y-m-d h:i:s'),
'date_update' => date('Y-m-d h:i:s'),
'type' => 'F'
);
$reserveData = $this->db->insert('settlement_reservation', $reservedarea);
// echo $this->db->last_query(); die();
if ($reserveData != 1) {
$this->db->trans_rollback();
log_message('error', '#ERRSET00053: Insertion failed in settlement_reservation RTPS Case No ' . $application_no);
$data = array(
'error' => "#ERRSET00053: Registration of Settlement failed for case no : " . $application_no
);
echo json_encode($data);
return false;
}
}
}
///// family reserve area end //////
//////proceeding start//////
$proceeding_id = $this->db->query("Select max(proceeding_id)+1 as c from settlement_proceeding where case_no='$case_no' ")->row()->c;
if ($proceeding_id == null) {
$proceeding_id = 1;
}
$insPetProceed = [
'case_no' => $case_no,
'proceeding_id' => $proceeding_id,
'date_of_hearing' => date('Y-m-d h:i:s'),
'next_date_of_hearing' => date('Y-m-d h:i:s'),
'note_on_order' => $this->input->post('lm_remark_text'),
'status' => 'W',
'user_code' => $this->session->userdata('user_code'),
'date_entry' => date('Y-m-d h:i:s'),
'operation' => 'E',
'ip' => $this->utilityclass->get_client_ip(),
'office_from' => 'LM',
'office_to' => $pending_officer,
'task' => 'LM note submitted'
];
$insertProceeding = $this->db->insert('settlement_proceeding', $insPetProceed);
// echo $this->db->last_query(); die();
if ($insertProceeding != 1) {
$this->db->trans_rollback();
log_message('error', '#ERRORPP: Insertion failed in settlement_proceeding for case no :' . $case_no);
$json = [
'errorMessage' => "#ERRORPP: Failed to forward the case for Case No : " . $case_no
];
echo json_encode($json);
return false;
}
//////proceeding end//////
////settlement Khas LM Report insert end
if ($this->db->trans_status() == false) {
$this->db->trans_rollback();
$data = array(
'error' => "Error in submitting. Please try Again"
);
} else {
//////////////POST To basundhara/////////////////////
// $rmk = 'Forwarded to ' . $pending_officer;
// $status = 'M';
// $task = 'LM';
// $pen = 'CO';
// // $pen=$pending_officer;
// $case = $case_no;
// $rtps_status = $this->SettlementApiModel->postApiBasundhara($application_no, $case, $rmk, $status, $task, $pen);
// $rtps_status = json_decode($rtps_status);
// if (trim($rtps_status) != "y") {
// $this->db->trans_rollback();
// $this->session->set_flashdata('message', "Error #ERRAPP0011: Settlement Application not submitted case no # $case_no");
// redirect(base_url() . "index.php/home");
// } else {
//
}
$this->db->trans_commit();
$this->session->set_flashdata('message', "Application Successfully Forwarded to " . $pending_officer . " With Case No # " . $case_no);
redirect(base_url() . "index.php/home");
}
}
Comments
Post a Comment