From f0a84af02546dfc490441db9a8ca3517b0d7fc8e Mon Sep 17 00:00:00 2001 From: VE10-Sanjeev Date: Wed, 8 Feb 2023 15:47:24 +0530 Subject: [PATCH] New Sales PD Section Data : ps --- .../controllers/Sales_PD_Controller.php | 84 ++++++++++++++----- 1 file changed, 61 insertions(+), 23 deletions(-) diff --git a/api/application/controllers/Sales_PD_Controller.php b/api/application/controllers/Sales_PD_Controller.php index 8748afb1..1f8ff460 100644 --- a/api/application/controllers/Sales_PD_Controller.php +++ b/api/application/controllers/Sales_PD_Controller.php @@ -968,6 +968,26 @@ class Sales_PD_Controller extends REST_Controller { public function saveSalesPDsection_post() { $records = $this->post('records'); + $is_entry_created = $this->salesPDsection($records); + if($is_entry_created) + { + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['records'] = $is_entry_created; + $this->response($data,REST_Controller::HTTP_OK); + } + else + { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NO_CONTENT; + $data['msg'] = 'Something went wrong! Try Later'; + $this->response($data,REST_Controller::HTTP_OK); + + } + } + public function salesPDsection($records) + { + $sales_pd_id = $records['sales_pd_id']; $section_id = $records['section_id']; $fk_createdby = $records['fk_createdby']; @@ -1078,23 +1098,7 @@ class Sales_PD_Controller extends REST_Controller { //insert new record $fields = array('sales_pd_id' => $sales_pd_id, 'section_id' => $section_id, 'status' =>$status ,'section_data' => $section_data,'createdby' => $fk_createdby); $is_entry_created = $this->Sales_PD_Model->saveRecords($fields,SALESPD_SECTION_DATA); - if($is_entry_created) - { - $data['dataStatus'] = true; - $data['status'] = REST_Controller::HTTP_OK; - $data['records'] = $is_entry_created; - $this->response($data,REST_Controller::HTTP_OK); - } - else - { - $data['dataStatus'] = false; - $data['status'] = REST_Controller::HTTP_NO_CONTENT; - $data['msg'] = 'Something went wrong! Try Later'; - $this->response($data,REST_Controller::HTTP_OK); - - } - - + return $is_entry_created; } public function getSalesPDSectionData_post() @@ -1611,14 +1615,14 @@ public function filterSalesPDList_post() { ****** ******/ public function cetNewSalesPd_get(){ // - $pdtype = $this->get('type'); + $sales_pd_type = $this->get('type'); $productname = $this->get('prod'); $applicantname = $this->get('apcntname'); $applicantid = $this->get('apcntid'); $userid = $this->get('uid'); $createdby = null; $lenderid = (ENVIRONMENT == 'production' ? 7 : 35); - if ((!empty($pdtype)) && (!empty($productname)) && (!empty($applicantname)) && (!empty($applicantid)) && (!empty($userid))) { + if ((!empty($sales_pd_type)) && (!empty($productname)) && (!empty($applicantname)) && (!empty($applicantid)) && (!empty($userid))) { /************lender id,shortname******************/ $lender_short_name = $this->Sales_PD_Model->selectCustomRecords(array('short_name'),array('entity_id' => $lenderid),ENTITY); @@ -1664,14 +1668,48 @@ public function filterSalesPDList_post() { $salepd_serial_no .= '-'.(++$count[0]['count']); /*************Inserting Here ******************/ - $records = array("sales_pd_sno"=> $salepd_serial_no,"rand_string"=>$randomString,"lender_id"=>$lenderid, "product_id"=>$product_id, "sales_pd_type"=>$pdtype, "applicant_id"=>$applicantid, "applicant_name"=>$applicantname, "createdby"=>$createdby, "isactive"=>1); - + $records = array("sales_pd_sno"=> $salepd_serial_no,"rand_string"=>$randomString,"lender_id"=>$lenderid, "product_id"=>$product_id, "sales_pd_type"=>$sales_pd_type, "applicant_id"=>$applicantid, "applicant_name"=>$applicantname, "createdby"=>$createdby, "isactive"=>1); $id = $this->Sales_PD_Model->saveRecords($records,SALES_PD_DATA); - + // $id = 772; if (!empty($id)) { + $msg = "Inserted, Sales PD : ".$salepd_serial_no."/".$id; + $template = $this->Sales_PD_Model->selectCustomRecords(array('*'),array('lender_id' => $lenderid,'product_id' => $product_id,'pd_type' => 1,'sales_pd_type' => $sales_pd_type,'isactive' => 1),SALESPDTEMPLATE); + $template = json_decode($template[0]['template'],true); + $section_data=array(); + foreach ($template['sections'] as $key => $value){ + $section_id = $template['sections'][$key]['section_id']; + $section_name = $template['sections'][$key]['section_name']; + switch($section_id) + { + case 1: + if($value['questions']) + { + foreach($value['questions'] as $form_key => $form_value) + { + if($form_value['question_key'] == 'application_id'){ + $value['questions'][$form_key]['answer_value'] = $applicantid; + }else if($form_value['question_key'] == 'main_loan_applicant'){ + $value['questions'][$form_key]['answer_value'] = $applicantname; + }else if(!empty($form_value['question_key'])){ + $value['questions'][$form_key]['answer_value'] = null; + } + } + $general = array("section_id"=>$section_id,"section_name"=>$section_name,"onsubmit"=>null,"questions"=>$value['questions'],"order_id"=>1,"is_complete"=>1,"fk_createdby"=>$createdby,"sales_pd_id"=>$id); + array_push($section_data, $general); + } + break; + default: "No Sections"; + } + } + if(!empty($section_data)){ + foreach ($section_data as $key => $data_value){ + $reponse = $this->salesPDsection($data_value); + $msg = $msg." ( ".$data_value['section_name']." ID : ".$reponse. " )"; + } + } $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; - $data['records'] = "Inserted ID : ".$salepd_serial_no."/".$id; + $data['records'] = $msg; } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NOT_FOUND;