code2

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

Popular posts from this blog

code1