load->library('AWS_S3'); } public function listLessPDDetails($page,$limit,$sort,$pdofficerid,$datetype,$fdate,$tdate,$lenderid,$status,$lender_details,$pdagencyid,$vendor_pdofficer,$user_type,$createdby)// $page represents mysql offset { // echo $lenderid;die(); $this->db->SELECT('PDTRIGGER.pd_id,PDTRIGGER.imgc_fin_institute,PDTRIGGER.pd_sno,PDTRIGGER.fk_lender_id,PDTRIGGER.sub_entity_id,SUBENTITY.short_name as sub_entity_short_name,ENTITY.full_name as lender_full_name,ENTITY.short_name as lender_short_name,PDTRIGGER.fk_entity_billing_id,ENTITYBILLING.billing_name, PDTRIGGER.lender_applicant_id, DATE_FORMAT(PDTRIGGER.pd_date_of_initiation, "%d/%m/%Y") as pd_date_of_initiation, PDTRIGGER.fk_product_id,PRODUCTS.name as product_name,PRODUCTS.abbr as product_abbr, PRODUCTS.prod_catagory,PDTRIGGER.fk_subproduct_id,SUBPRODUCTS.name as subproduct_name,SUBPRODUCTS.abbr as subproduct_abbr, PDTRIGGER.fk_pd_type,PDTYPE.type_name as pd_type_name, PDTRIGGER.pd_status,PDTRIGGER.pd_specific_clarification, DATE_FORMAT(PDTRIGGER.createdon,"%d/%m/%Y %H:%i:%s") as createdon, PDTRIGGER.fk_createdby, DATE_FORMAT(PDTRIGGER.updatedon,"%d/%m/%Y %H:%i:%s") as master_updatedon, PDTRIGGER.fk_updatedby,concat(USERPROFILE.first_name," ",USERPROFILE.last_name) as createdby,concat(USERPROFILE1.first_name," ",USERPROFILE1.last_name) as updatedby, PDTRIGGER.fk_pd_allocation_type,,PDALLOCATIONTYPE.pd_allocation_type_name, PDTRIGGER.fk_pd_allocated_to,concat(USERPROFILE2.first_name," ",USERPROFILE2.last_name) as pd_allocated_to,PDTRIGGER.executive_id,concat(EXECUTIVE.first_name," ",EXECUTIVE.last_name) as executive_name,PDTRIGGER.central_pd_officer_id,concat(CENTRALOFFICER.first_name," ",CENTRALOFFICER.last_name) as centralofficer,PDTRIGGER.fk_pd_template_id,TEMPLATE.template_name, PDTRIGGER.fk_customer_segment,CUSTOMERSEGMENT.name as customer_segment_name,CUSTOMERSEGMENT.abbr as customer_segment_abbr, PDTRIGGER.pd_officier_final_judgement, PDTRIGGER.pd_agency_id,AGENCY.full_name as agency_name,AGENCY.short_name as agency_short_name,AGENCY.is_qc_enabled, PDTRIGGER.loan_amount,PDTRIGGER.addressline1,PDTRIGGER.addressline2,PDTRIGGER.addressline3,PDTRIGGER.fk_city,CITY.name as city_name,PDTRIGGER.fk_state,STATE.name as state_name,PINCODE.pincode,PDTRIGGER.pincode as pincode_id,PDTRIGGER.pd_contact_person,PDTRIGGER.pd_contact_mobileno,DATE_FORMAT(PDTRIGGER.scheduled_on,"%d/%m/%Y %h:%i %p") as scheduled_on,DATE_FORMAT(PDTRIGGER.completed_on,"%d/%m/%Y %h:%i:%s %p") as completed_on,PDTRIGGER.remarks,PDTRIGGER.is_original_report_created,PDTRIGGER.pd_report_latest_version,PDTRIGGER.pd_branch_id,ENTITYLENDERBRANCH.branch_name,PDTRIGGER.qc_feedback,PDTRIGGER.qc_rating,PDTRIGGER.qc_remarks,PDTRIGGER.lender_rating,PDTRIGGER.lender_feedback,PDTRIGGER.other_pincode,PDAPPLICANTSDETAILS.applicant_name,PDTRIGGER.is_otp_done,PDTRIGGER.is_child,PDTRIGGER.parent_pd_id,PDTRIGGER.fk_primary_address_id,PDTRIGGER.fk_address_id,PDTRIGGER.encrypted_url,PDTRIGGER.random_string,PDTRIGGER.pd_qc_note,ENTITY.is_sms_enabled,ENTITY.is_mail_enabled,ENTITY.is_app_notify_enabled,PDTRIGGER.is_notify_enabled,(SELECT DATE_FORMAT(createdon,"%d/%m/%Y") FROM h_common_masters where PDTRIGGER.pd_id = primary_key AND field_name = "pd_status" order by log_id DESC limit 1) as updatedon,ENTITYFININSTITUTION.institute_name as fin_institute_name,PDTRIGGER.is_video_merged,PDTRIGGER.vendor_status'); //$this->db->SELECT('pd_sno,fk_lender_id,pd_agency_id,pd_status,vendor_status'); $this->db->FROM(PDTRIGGER.' as PDTRIGGER'); $this->db->JOIN(ENTITY.' as ENTITY','PDTRIGGER.fk_lender_id = ENTITY.entity_id','LEFT'); $this->db->JOIN(ENTITY.' as SUBENTITY','PDTRIGGER.sub_entity_id = SUBENTITY.entity_id','LEFT'); $this->db->JOIN(ENTITYBILLING.' as ENTITYBILLING','PDTRIGGER.fk_entity_billing_id = ENTITYBILLING.entity_billing_id','LEFT'); $this->db->JOIN(PRODUCTS.' as PRODUCTS','PDTRIGGER.fk_product_id = PRODUCTS.product_id','LEFT'); $this->db->JOIN(SUBPRODUCTS.' as SUBPRODUCTS','PDTRIGGER.fk_subproduct_id = SUBPRODUCTS.subproduct_id','LEFT'); $this->db->JOIN(PDTYPE.' as PDTYPE','PDTRIGGER.fk_pd_type = PDTYPE.pd_type_id','LEFT'); $this->db->JOIN(PDSTATUS.' as PDSTATUS','PDTRIGGER.pd_status = PDSTATUS.pd_status_id','LEFT'); $this->db->JOIN(USERPROFILE.' as USERPROFILE','PDTRIGGER.fk_createdby = USERPROFILE.userid','LEFT'); $this->db->JOIN(USERPROFILE.' as USERPROFILE1','PDTRIGGER.fk_updatedby = USERPROFILE1.userid','LEFT'); $this->db->JOIN(PDALLOCATIONTYPE.' as PDALLOCATIONTYPE','PDTRIGGER.fk_pd_allocation_type = PDALLOCATIONTYPE.pd_allocation_type_id','LEFT'); $this->db->JOIN(USERPROFILE.' as USERPROFILE2','PDTRIGGER.fk_pd_allocated_to = USERPROFILE2.userid','LEFT'); $this->db->JOIN(USERPROFILE.' as EXECUTIVE','PDTRIGGER.executive_id = EXECUTIVE.userid','LEFT'); $this->db->JOIN(USERPROFILE.' as CENTRALOFFICER','PDTRIGGER.central_pd_officer_id = CENTRALOFFICER.userid','LEFT'); $this->db->JOIN(TEMPLATE.' as TEMPLATE','PDTRIGGER.fk_pd_template_id = TEMPLATE.template_id','LEFT'); $this->db->JOIN(CUSTOMERSEGMENT.' as CUSTOMERSEGMENT','PDTRIGGER.fk_customer_segment = CUSTOMERSEGMENT.customer_segment_id','LEFT'); $this->db->JOIN(ENTITY.' as AGENCY','PDTRIGGER.pd_agency_id = AGENCY.entity_id','LEFT'); $this->db->JOIN(STATE.' as STATE','PDTRIGGER.fk_state = STATE.state_id ','LEFT'); $this->db->JOIN(CITY.' as CITY','PDTRIGGER.fk_city = CITY.city_id','LEFT'); $this->db->JOIN(PINCODE.' as PINCODE','PDTRIGGER.pincode = PINCODE.pincode_id','LEFT'); $this->db->JOIN(ENTITYLENDERBRANCH.' as ENTITYLENDERBRANCH','PDTRIGGER.pd_branch_id = ENTITYLENDERBRANCH.entity_lender_branch_id','LEFT'); $this->db->JOIN(ENTITYFININSTITUTION.' as ENTITYFININSTITUTION','PDTRIGGER.imgc_fin_institute = ENTITYFININSTITUTION.entity_fin_institution_id','LEFT'); $this->db->JOIN(PDAPPLICANTSDETAILS.' as PDAPPLICANTSDETAILS','PDTRIGGER.pd_id = PDAPPLICANTSDETAILS.fk_pd_id AND PDAPPLICANTSDETAILS.applicant_type = 1','LEFT'); // $this->db->JOIN(COMMONMASTER.' as COMMONMASTER','PDTRIGGER.pd_id = COMMONMASTER.primary_key && COMMONMASTER.field_name = pd_status ','LEFT'); $this->db->WHERE('PDTRIGGER.pd_status !=',ARCHIVED); $this->db->WHERE('PDTRIGGER.pd_status !=',TRUNCATED); if($createdby != '') { $this->db->WHERE('PDTRIGGER.fk_createdby',$createdby); } if($pdofficerid != "" || $pdofficerid != null) { if($pdofficerid != 52 && $pdofficerid != 229 ) //support pd officer user id { $this->db->WHERE('PDTRIGGER.fk_pd_allocated_to',$pdofficerid); } } if($vendor_pdofficer != "" || $vendor_pdofficer != null) { $this->db->WHERE('PDTRIGGER.vendor_pdofficer',$vendor_pdofficer); } if($lenderid != "" || $lenderid != null) { $this->db->WHERE('PDTRIGGER.fk_lender_id',$lenderid); //print_r($lender_details);die(); // if(isset($lender_details['entity'])) // { // $this->db->WHERE('PDTRIGGER.fk_lender_id',$lender_details['entity']); // } // if(isset($lender_details['zone']) && count($lender_details['zone'])) // { // $this->db->WHERE_IN('PDTRIGGER.fk_city',$lender_details['zone']); // } // if(isset($lender_details['state'])) // { // $this->db->WHERE('PDTRIGGER.fk_state',$lender_details['state']); // } if(isset($lender_details['city'])) { $this->db->WHERE('PDTRIGGER.fk_city',$lender_details['city']); } // if(isset($lender_details['branch'])) // { // $this->db->WHERE('PDTRIGGER.fk_city',$lender_details['pd_branch_id']); // } // if(isset($lender_details['lender_credit_person'])) // { // $this->db->WHERE('PDTRIGGER.lender_credit_person',$lender_details['lender_credit_person']); // } } else { $this->db->WHERE('PDTRIGGER.fk_lender_id != ', (ENVIRONMENT == 'production' ? 7: 35) ); } if($pdagencyid != "" || $pdagencyid != null) { $this->db->WHERE('PDTRIGGER.pd_agency_id',$pdagencyid); $this->db->WHERE('PDTRIGGER.pd_status!=',FIA_REJECTED); //$this->db->WHERE('PDTRIGGER.vendor_status',TRIGGERED); //$this->db->WHERE("if(vendor_status = 'TRIGGERED', if( pd_status in ('ALLOCATED'),1,0),0)=0"); } if($status != "" || $status != null) { $this->db->WHERE('PDTRIGGER.pd_status',strtoupper($status)); } if($datetype != "" || $datetype != null) { if($datetype == 1) { if($fdate != "" || $fdate != null) { $this->db->WHERE('PDTRIGGER.pd_date_of_initiation >=',$fdate); } if($tdate != "" || $tdate != null) { $this->db->WHERE('PDTRIGGER.pd_date_of_initiation <=',$tdate); } } else if($datetype == 2) { if($fdate != "" || $fdate != null) { $this->db->WHERE('PDTRIGGER.scheduled_on >=',$fdate); } if($tdate != "" || $tdate != null) { $this->db->WHERE('PDTRIGGER.scheduled_on <=',$tdate); } } } if($user_type == 'SMC') { $current_smc_lender_id = ENVIRONMENT == 'production' ? 7 : 35; //pk id of SMC in live and demo $this->db->WHERE('PDTRIGGER.fk_lender_id',$current_smc_lender_id); } // FILTERING THE LAST 10 DAYS RECORDS $filter_rec='PDTRIGGER.pd_date_of_initiation BETWEEN DATE_SUB(NOW(), INTERVAL 60 DAY) AND NOW()'; $this->db->WHERE($filter_rec); // ----END OF FILTERING THE LAST 10 DAYS RECORDS--- $this->db->ORDER_BY('PDTRIGGER.pd_id',$sort); //$this->db->LIMIT($limit,$page); $result_array = $this->db->GET()->result_array(); // echo count($result_array); // print_r($this->db->last_query());die(); if(count($result_array) != 0) { foreach($result_array as $key => $result) { $this->db->SELECT('PDAPPLICANTSDETAILS.pd_co_applicant_id, PDAPPLICANTSDETAILS.fk_pd_id, PDAPPLICANTSDETAILS.applicant_name, PDAPPLICANTSDETAILS.applicant_type, PDAPPLICANTSDETAILS.mobile_no, PDAPPLICANTSDETAILS.email, PDAPPLICANTSDETAILS.addressline1, PDAPPLICANTSDETAILS.addressline2, PDAPPLICANTSDETAILS.addressline3, PDAPPLICANTSDETAILS.fk_city, PDAPPLICANTSDETAILS.fk_state, PDAPPLICANTSDETAILS.pincode,PDAPPLICANTSDETAILS.relation,RELATIONSHIPS.name as relation_name,PDAPPLICANTSDETAILS.landline,PDAPPLICANTSDETAILS.company_name,PDAPPLICANTSDETAILS.applicant_title_name,TITLES.name as title_name'); $this->db->FROM(PDAPPLICANTSDETAILS.' as PDAPPLICANTSDETAILS'); $this->db->JOIN(STATE.' as STATE','PDAPPLICANTSDETAILS.fk_state = STATE.state_id','LEFT'); $this->db->JOIN(CITY.' as CITY','PDAPPLICANTSDETAILS.fk_city = CITY.city_id','LEFT'); $this->db->JOIN(RELATIONSHIPS.' as RELATIONSHIPS','PDAPPLICANTSDETAILS.relation = RELATIONSHIPS.relationship_id','LEFT'); $this->db->JOIN(TITLES.' as TITLES','PDAPPLICANTSDETAILS.applicant_title_name = TITLES.title_id','LEFT'); $this->db->WHERE('PDAPPLICANTSDETAILS.fk_pd_id ',$result['pd_id']); $this->db->ORDER_BY('PDAPPLICANTSDETAILS.pd_co_applicant_id'); $result_child_array = $this->db->GET()->result_array(); if(count($result_child_array) != 0) { $result_array[$key]['applicat_details'] = $result_child_array; } } } if(count($result_array) > 0 ) { $result_data['data_status'] = true; $result_data['data'] = $result_array; return $result_data; } else { $result_data['data_status'] = false; $result_data['data'] = null; return $result_data; } } //PD List with Common Filters public function PDListwithGlobalFilters($pd_type,$pd_status,$pd_from_date,$pd_to_date,$pd_city,$pd_products,$pd_lender,$pd_applicant_name,$pd_applicant_lender_ref,$pd_officer_name,$include_archive,$pd_officer_id,$pd_agency_id,$vendor_pdofficer,$user_type,$createdby) { $limit = 1000; $this->db->SELECT('PDTRIGGER.pd_id, PDTRIGGER.pd_sno,PDTRIGGER.fk_lender_id,PDTRIGGER.sub_entity_id,SUBENTITY.short_name as sub_entity_short_name,PDTRIGGER.imgc_fin_institute,ENTITY.full_name as lender_full_name,ENTITY.short_name as lender_short_name,ENTITY.is_score_card_enabled,ENTITY.is_otp_enabled, PDTRIGGER.fk_entity_billing_id,ENTITYBILLING.billing_name,PDTRIGGER.lender_applicant_id, DATE_FORMAT(PDTRIGGER.pd_date_of_initiation, "%d/%m/%Y") as pd_date_of_initiation,PDTRIGGER.pd_date_of_initiation as pd_date_of_initiation_sqlformat, PDTRIGGER.fk_product_id,PRODUCTS.name as product_name,PRODUCTS.abbr as product_abbr, PRODUCTS.prod_catagory, PDTRIGGER.fk_subproduct_id,SUBPRODUCTS.name as subproduct_name,SUBPRODUCTS.abbr as subproduct_abbr, PDTRIGGER.fk_pd_type,PDTYPE.type_name as pd_type_name, PDTRIGGER.pd_status,PDTRIGGER.pd_specific_clarification, DATE_FORMAT(PDTRIGGER.createdon,"%d/%m/%Y %h:%i:%s %p") as createdon, PDTRIGGER.fk_createdby, DATE_FORMAT(PDTRIGGER.updatedon,"%d/%m/%Y %H:%i %p") as master_updatedon, PDTRIGGER.fk_updatedby,concat(USERPROFILE.first_name," ",USERPROFILE.last_name) as createdby,concat(USERPROFILE1.first_name," ",USERPROFILE1.last_name) as updatedby, PDTRIGGER.fk_pd_allocation_type,,PDALLOCATIONTYPE.pd_allocation_type_name, PDTRIGGER.fk_pd_allocated_to,concat(USERPROFILE2.first_name," ",USERPROFILE2.last_name) as pd_allocated_to,PDTRIGGER.executive_id,concat(EXECUTIVE.first_name," ",EXECUTIVE.last_name) as executive_name,PDTRIGGER.central_pd_officer_id,concat(CENTRALOFFICER.first_name," ",CENTRALOFFICER.last_name) as centralofficer,PDTRIGGER.fk_pd_template_id,TEMPLATE.template_name, PDTRIGGER.fk_customer_segment,CUSTOMERSEGMENT.name as customer_segment_name,CUSTOMERSEGMENT.abbr as customer_segment_abbr, PDTRIGGER.pd_officier_final_judgement, PDTRIGGER.pd_agency_id,AGENCY.full_name as agency_name,AGENCY.is_qc_enabled,AGENCY.short_name as agency_short_name, PDTRIGGER.loan_amount,PDTRIGGER.addressline1,PDTRIGGER.addressline2,PDTRIGGER.addressline3,PDTRIGGER.fk_city,CITY.name as city_name,PDTRIGGER.fk_state,STATE.name as state_name,PINCODE.pincode,PDTRIGGER.pincode as pincode_id,PDTRIGGER.lender_sales_person,concat(LENDERSALESPERSON.first_name," ",LENDERSALESPERSON.last_name) as lender_sales_person_name,LENDERSALESPERSON.mobile_no as lender_sales_contact_mobileno,LENDERSALESPERSON.email as lender_sales_person_email,PDTRIGGER.lender_credit_person,concat(LENDERCREDITPERSON.first_name," ",LENDERCREDITPERSON.last_name) as lender_credit_person_name,LENDERCREDITPERSON.mobile_no as lender_credit_person_contact_mobileno,LENDERCREDITPERSON.email as lender_credit_person_email,PDTRIGGER.pd_contact_person,PDTRIGGER.pd_contact_mobileno,DATE_FORMAT(PDTRIGGER.scheduled_on,"%d/%m/%Y %h:%i %p") as scheduled_on,PDTRIGGER.scheduled_on as scheduled_on_for_validation,DATE_FORMAT(PDTRIGGER.scheduled_on,"%dth %b %Y ") as scheduled_date_for_log,DATE_FORMAT(PDTRIGGER.scheduled_on,"%h:%i %p") as scheduled_time_for_log,DATE_FORMAT(PDTRIGGER.completed_on,"%d/%m/%Y %h:%i:%s %p") as completed_on,PDTRIGGER.remarks,PDTRIGGER.bounce_reason,PDTRIGGER.bounce_reason_others,BOUNCEMASTER.bounce_reason_name,PDTRIGGER.is_original_report_created,PDTRIGGER.pd_report_latest_version,PDAPPLICANTSDETAILS.applicant_name,PDAPPLICANTSDETAILS.applicant_name as main_applicant,PDTRIGGER.pd_branch_id,ENTITYLENDERBRANCH.branch_name,PDTRIGGER.qc_feedback,PDTRIGGER.qc_rating,PDTRIGGER.qc_remarks,PDTRIGGER.lender_rating,PDTRIGGER.lender_feedback,PDAPPLICANTSDETAILS.applicant_title_name,TITLES.name as title_name,PDTRIGGER.pd_contact_landline,PDTRIGGER.other_pincode,PDTRIGGER.is_otp_done,OTPREJECTION.rejection_reason,PDTRIGGER.otp_reject_other_reason,PDTRIGGER.encrypted_url,PDTRIGGER.is_child,PDTRIGGER.parent_pd_id,PDTRIGGER.fk_primary_address_id,PDTRIGGER.fk_address_id,PDTRIGGER.start_location,PDTRIGGER.satellite_image_base64_blob,DATE_FORMAT(PDTRIGGER.pd_report_generated_date,"%d/%m/%Y %h:%i:%s %p") as pd_report_generated_date,DATE_FORMAT(PDTRIGGER.pd_visit_date,"%d/%m/%Y %h:%i:%s %p") as pd_visit_date,PDTRIGGER.random_string,PDTRIGGER.pd_report_html_filename,PDTRIGGER.is_qc_edited,PDTRIGGER.is_zip_created,PDTRIGGER.pd_qc_note,PDTRIGGER.is_notify_enabled,(SELECT DATE_FORMAT(createdon,, "%d/%m/%Y") FROM h_common_masters where PDTRIGGER.pd_id = primary_key AND field_name = "pd_status" order by log_id DESC limit 1) as updatedon,ENTITYFININSTITUTION.institute_name as fin_institute_name,PDTRIGGER.vendor_status'); $this->db->FROM(PDTRIGGER.' as PDTRIGGER'); $this->db->JOIN(ENTITY.' as ENTITY','PDTRIGGER.fk_lender_id = ENTITY.entity_id ','LEFT'); $this->db->JOIN(ENTITY.' as SUBENTITY','PDTRIGGER.sub_entity_id = SUBENTITY.entity_id ','LEFT'); $this->db->JOIN(ENTITYBILLING.' as ENTITYBILLING','PDTRIGGER.fk_entity_billing_id = ENTITYBILLING.entity_billing_id','LEFT'); $this->db->JOIN(PRODUCTS.' as PRODUCTS','PDTRIGGER.fk_product_id = PRODUCTS.product_id','LEFT'); $this->db->JOIN(SUBPRODUCTS.' as SUBPRODUCTS','PDTRIGGER.fk_subproduct_id = SUBPRODUCTS.subproduct_id','LEFT'); $this->db->JOIN(PDTYPE.' as PDTYPE','PDTRIGGER.fk_pd_type = PDTYPE.pd_type_id','LEFT'); //$this->db->JOIN(PDSTATUS.' as PDSTATUS','PDTRIGGER.pd_status = PDSTATUS.pd_status_id','LEFT'); $this->db->JOIN(USERPROFILE.' as USERPROFILE','PDTRIGGER.fk_createdby = USERPROFILE.userid','LEFT'); $this->db->JOIN(USERPROFILE.' as USERPROFILE1','PDTRIGGER.fk_updatedby = USERPROFILE1.userid','LEFT'); $this->db->JOIN(PDALLOCATIONTYPE.' as PDALLOCATIONTYPE','PDTRIGGER.fk_pd_allocation_type = PDALLOCATIONTYPE.pd_allocation_type_id','LEFT'); $this->db->JOIN(USERPROFILE.' as USERPROFILE2','PDTRIGGER.fk_pd_allocated_to = USERPROFILE2.userid','LEFT'); $this->db->JOIN(USERPROFILE.' as USERPROFILE3','PDTRIGGER.executive_id = USERPROFILE3.userid','LEFT'); $this->db->JOIN(USERPROFILE.' as EXECUTIVE','PDTRIGGER.executive_id = EXECUTIVE.userid','LEFT'); $this->db->JOIN(USERPROFILE.' as CENTRALOFFICER','PDTRIGGER.central_pd_officer_id = CENTRALOFFICER.userid','LEFT'); $this->db->JOIN(USERPROFILE.' as LENDERSALESPERSON','PDTRIGGER.lender_sales_person = LENDERSALESPERSON.userid','LEFT'); $this->db->JOIN(USERPROFILE.' as LENDERCREDITPERSON','PDTRIGGER.lender_credit_person = LENDERCREDITPERSON.userid','LEFT'); $this->db->JOIN(TEMPLATE.' as TEMPLATE','PDTRIGGER.fk_pd_template_id = TEMPLATE.template_id','LEFT'); $this->db->JOIN(CUSTOMERSEGMENT.' as CUSTOMERSEGMENT','PDTRIGGER.fk_customer_segment = CUSTOMERSEGMENT.customer_segment_id','LEFT'); $this->db->JOIN(ENTITY.' as AGENCY','PDTRIGGER.pd_agency_id = AGENCY.entity_id','LEFT'); $this->db->JOIN(STATE.' as STATE','PDTRIGGER.fk_state = STATE.state_id ','LEFT'); $this->db->JOIN(CITY.' as CITY','PDTRIGGER.fk_city = CITY.city_id','LEFT'); $this->db->JOIN(PINCODE.' as PINCODE','PDTRIGGER.pincode = PINCODE.pincode_id','LEFT'); $this->db->JOIN(BOUNCEMASTER.' as BOUNCEMASTER','PDTRIGGER.bounce_reason = BOUNCEMASTER.bounce_id','LEFT'); $this->db->JOIN(PDAPPLICANTSDETAILS.' as PDAPPLICANTSDETAILS','PDTRIGGER.pd_id = PDAPPLICANTSDETAILS.fk_pd_id AND PDAPPLICANTSDETAILS.applicant_type = 1','LEFT'); $this->db->JOIN(ENTITYLENDERBRANCH.' as ENTITYLENDERBRANCH','PDTRIGGER.pd_branch_id = ENTITYLENDERBRANCH.entity_lender_branch_id','LEFT'); $this->db->JOIN(ENTITYFININSTITUTION.' as ENTITYFININSTITUTION','PDTRIGGER.imgc_fin_institute = ENTITYFININSTITUTION.entity_fin_institution_id','LEFT'); $this->db->JOIN(TITLES.' as TITLES','PDAPPLICANTSDETAILS.applicant_title_name = TITLES.title_id','LEFT'); $this->db->JOIN(OTPREJECTION.' as OTPREJECTION','PDTRIGGER.otp_reject_reason = OTPREJECTION.otp_rejection_id','LEFT'); //$this->db->WHERE('PDTRIGGER.pd_id',$pdid); $this->db->WHERE('PDTRIGGER.pd_status !=',TRUNCATED); if($include_archive == 1) { $this->db->OR_WHERE('PDTRIGGER.pd_status',ARCHIVED); } if(!empty($pd_type)) { $this->db->WHERE_IN('PDTRIGGER.fk_pd_type',$pd_type); } if(!empty($createdby)) { $this->db->WHERE('PDTRIGGER.fk_createdby',$createdby); } if(!empty($pd_status)) { $this->db->WHERE_IN('PDTRIGGER.pd_status',$pd_status); } if(($pd_from_date != "" || $pd_from_date != null) && ($pd_to_date != "" || $pd_to_date != null)) { $this->db->where('PDTRIGGER.pd_date_of_initiation BETWEEN ' ."'$pd_from_date'". ' AND ' ."'$pd_to_date'"); } if(!empty($pd_city)) { $this->db->WHERE_IN('PDTRIGGER.fk_city',$pd_city); } if(!empty($pd_products)) { $this->db->WHERE_IN('PDTRIGGER.fk_product_id',$pd_products); } if(!empty($pd_lender)) { $this->db->WHERE_IN('PDTRIGGER.fk_lender_id',$pd_lender); } if($pd_applicant_lender_ref != "" || $pd_applicant_lender_ref != null ) { $this->db->LIKE('PDTRIGGER.lender_applicant_id',"$pd_applicant_lender_ref"); } if($pd_applicant_name != "" || $pd_applicant_name != null ) { $this->db->LIKE('PDAPPLICANTSDETAILS.applicant_name',"$pd_applicant_name"); } if($pd_officer_name != "" || $pd_officer_name != null ) { $this->db->LIKE('concat(USERPROFILE2.first_name," ",USERPROFILE2.last_name)',$pd_officer_name); } if($pd_agency_id != "" || $pd_agency_id != null ) { $this->db->LIKE('PDTRIGGER.pd_agency_id',$pd_agency_id); $this->db->WHERE('PDTRIGGER.pd_status!=',FIA_REJECTED); //$this->db->WHERE("if(vendor_status = 'TRIGGERED', if( pd_status in ('ALLOCATED'),1,0),0)=0"); } if($pd_officer_id != "" || $pd_officer_id != null ) { $this->db->LIKE('PDTRIGGER.fk_pd_allocated_to',"$pd_officer_id"); $limit = 100; } if($vendor_pdofficer != "" || $vendor_pdofficer != null ) { $this->db->LIKE('PDTRIGGER.vendor_pdofficer',"$vendor_pdofficer"); $limit = 100; } if($user_type == 'SMC') { $current_smc_lender_id = ENVIRONMENT == 'production' ? 7 : 35; //pk id of SMC in live and demo $this->db->WHERE('PDTRIGGER.fk_lender_id',$current_smc_lender_id); } $this->db->ORDER_BY('PDTRIGGER.pd_id','DESC'); $this->db->LIMIT($limit,0); $result_array = $this->db->GET()->result_array(); //print_r($this->db->last_query());die(); return $result_array; } // get Lender Specific PDOfficers List And Currently Allocated PD Values form PDOFFICIERSDETAILS table public function getLenderSpecificPDOfficersListAndAllocatedValues($lender_specific_pdofficers_list) { $this->db->SELECT('fk_user_id,allocated'); $this->db->FROM(PDOFFICIERSDETAILS); $this->db->WHERE_IN('fk_user_id',$lender_specific_pdofficers_list); $result = $this->db->get()->result_array(); } public function updatePDofficersDetail($userid) { $sql = 'UPDATE '.PDOFFICIERSDETAILS.' SET total = total+1, allocated = allocated+1 WHERE fk_user_id ='.$userid; $modified = $this->db->query($sql); } /* *Get All PD Related Documents as signed and expired URL's from S3 Buckets */ public function getSignedPDDocsURL($pdid,$form_id = null,$company_id = null,$is_common_api = null,$rental_count_id = null,$api_client = '') { //echo $pdid,$form_id,$company_id;die(); $document_lists = array(); if($pdid != '' || $pdid != null) { // Get lenderid of this pd by using pid $lender_id = $this->selectCustomRecords(array('fk_lender_id'),array('pd_id' => $pdid),PDTRIGGER); if(count($lender_id)) { //Get PD Documenttitle and name from DB $where_condition_array = array('fk_pd_id' => $pdid); if($form_id != null){ $where_condition_array['fk_form_id'] = $form_id; } if($company_id != null){ $where_condition_array['company_id'] = $company_id ; } if($rental_count_id != null) { $where_condition_array['rental_count_id'] = $rental_count_id ; } if($is_common_api != null) { $where_condition_array['company_id'] = null ; $where_condition_array['fk_form_id'] = null ; } $time = '+2 day'; if($api_client == 'report' || $api_client == 'customer_app') { $time = '+5 day'; $where_condition_array['isactive'] = 1; } //print_r($where_condition_array);die(); $document_lists = $this->selectRecords(PDDOCUMENTS,$where_condition_array); // print_r($this->db->last_query());die(); if(count($document_lists)) { $bucket_name = LENDER_BUCKET_NAME_PREFIX.$lender_id[0]['fk_lender_id']; foreach($document_lists as $key => $value) { if($api_client == 'customer_app' && $value['img_type'] == 3) { //echo $value['pd_document_name']; unset($document_lists[$key]); continue; } $profilepics3path = 'pd'.$pdid.'/'.$value['pd_document_name']; $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$profilepics3path,$time); $document_lists[$key]['doc_url'] = $singed_uri; } } } } return $document_lists; } function getExistPDdetails($pdid) { $applicants_data = $this->getApplicantsDetails($pdid,$type = 1); //print_r($applicants_data);die(); if(count($applicants_data)) { $fields = array('pd_id','pd_sno','random_string'); $table = PDAPPLICANTSDETAILS.' as PDAPPLICANTSDETAILS'; $where_condition_array = array('mobile_no' => $applicants_data[0]['mobile_no'],'applicant_name' => $applicants_data[0]['applicant_name']); $joins = array( array('table'=>PDTRIGGER.' as PDTRIGGER','condition'=>"PDAPPLICANTSDETAILS.fk_pd_id = PDTRIGGER.pd_id AND PDTRIGGER.pd_id != $pdid",'jointype'=>'INNER JOIN'), ); return $this->getJoinRecords($fields,$table,$joins,$where_condition_array); } else { return array(); } } /* *Get all Applicants details by pdid */ public function getApplicantsDetails($pdid,$type = null) { $pdmaster_details = $this->getPDMasterDetails($pdid); $parent_pd_id = $pdmaster_details[0]['parent_pd_id']; //Get all AddtionalPD's ID $addtional_pd_ids = $parent_pd_id ? $this->getAddtionalPDIDs($parent_pd_id) : array(); //print_r($addtional_pd_ids); $addtional_pd_ids_string = array(); if(count($addtional_pd_ids)) { foreach($addtional_pd_ids as $addtional){ array_push($addtional_pd_ids_string,$addtional['pd_id']); } } //print_r($addtional_pd_ids_string);die(); $this->db->SELECT('PDAPPLICANTSDETAILS.pd_co_applicant_id, PDAPPLICANTSDETAILS.fk_pd_id, PDAPPLICANTSDETAILS.applicant_name, PDAPPLICANTSDETAILS.applicant_type, PDAPPLICANTSDETAILS.mobile_no, PDAPPLICANTSDETAILS.email, PDAPPLICANTSDETAILS.addressline1, PDAPPLICANTSDETAILS.addressline2, PDAPPLICANTSDETAILS.addressline3, PDAPPLICANTSDETAILS.fk_city, PDAPPLICANTSDETAILS.fk_state, PDAPPLICANTSDETAILS.pincode,PDAPPLICANTSDETAILS.relation,RELATIONSHIPS.name as relation_name,PDAPPLICANTSDETAILS.landline,PDAPPLICANTSDETAILS.company_name,PDAPPLICANTSDETAILS.applicant_title_name,TITLES.name as title_name,PDAPPLICANTSDETAILS.additional_pd_id,PDAPPLICANTSDETAILS.isactive'); $this->db->FROM(PDAPPLICANTSDETAILS.' as PDAPPLICANTSDETAILS'); $this->db->JOIN(STATE.' as STATE','PDAPPLICANTSDETAILS.fk_state = STATE.state_id','LEFT'); $this->db->JOIN(CITY.' as CITY','PDAPPLICANTSDETAILS.fk_city = CITY.city_id','LEFT'); $this->db->JOIN(RELATIONSHIPS.' as RELATIONSHIPS','PDAPPLICANTSDETAILS.relation = RELATIONSHIPS.relationship_id','LEFT'); $this->db->JOIN(TITLES.' as TITLES','PDAPPLICANTSDETAILS.applicant_title_name = TITLES.title_id','LEFT'); $this->db->WHERE('PDAPPLICANTSDETAILS.fk_pd_id ',$pdid); $this->db->WHERE('PDAPPLICANTSDETAILS.isactive',1); if($type) { //echo 'DOIDNO'; $this->db->WHERE('PDAPPLICANTSDETAILS.applicant_type',1); } if(count($addtional_pd_ids_string) && !$type) { $this->db->OR_WHERE_IN('PDAPPLICANTSDETAILS.fk_pd_id',$addtional_pd_ids_string); $this->db->WHERE('PDAPPLICANTSDETAILS.isactive',1); } $this->db->ORDER_BY('PDAPPLICANTSDETAILS.pd_co_applicant_id'); $result_child_array = $this->db->GET()->result_array(); //print_r($this->db->last_query());die(); if(count($result_child_array) != 0) { return $result_child_array; } else { return array(); } } public function getAddtionalPDIDs($pdid) { $data = $this->db->SELECT('pd_id')->FROM(PDTRIGGER)->WHERE('parent_pd_id',$pdid)->GET()->result_array(); //print_r($this->db->last_query()); return $data; // } public function getPDAddress($temp_pdid) { $pdid = $temp_pdid; $pd_master_detials = $this->getPDMasterDetails($pdid); $assigned_pd = null; if($pd_master_detials[0]['is_child'] == 1) { $assigned_pd = $pdid; $pdid = $pd_master_detials[0]['parent_pd_id']; } $this->db->SELECT('PDADDRESS.pd_address_id,PDADDRESS.fk_pd_id,PDADDRESS.assigned_pd, PDADDRESS.addressline1, PDADDRESS.fk_city, PDADDRESS.fk_state,PDADDRESS.pincode as pincode_id,PINCODE.pincode,PDADDRESS.other_pincode,PDADDRESS.isactive,PDADDRESS.createdon,PDADDRESS.updatedon,PDADDRESS.is_visited,CITY.name as city_name,STATE.name as state_name,PDADDRESS.is_primary'); $this->db->FROM(PDADDRESS.' as PDADDRESS'); $this->db->JOIN(STATE.' as STATE','PDADDRESS.fk_state = STATE.state_id','LEFT'); $this->db->JOIN(CITY.' as CITY','PDADDRESS.fk_city = CITY.city_id','LEFT'); $this->db->JOIN(PINCODE.' as PINCODE','PDADDRESS.pincode = PINCODE.pincode_id','LEFT'); $this->db->WHERE('PDADDRESS.fk_pd_id ',$pdid); if($assigned_pd != null) { $this->db->WHERE('PDADDRESS.assigned_pd ',$assigned_pd); } $this->db->ORDER_BY('PDADDRESS.pd_address_id'); $result_child_array = $this->db->GET()->result_array(); //print_r($this->db->last_query()); //print_r($result_child_array);die(); if(count($result_child_array) != 0) { foreach($result_child_array as $key => $single_address) { //$result_child_array[$key]['addtional_pd_data'] = array(); // if($single_address['is_primary'] != 0) // { $result_child_array[$key]['addtional_pd_data'] = $this->getAddtionalPDInformations($single_address['pd_address_id']); // } } return $result_child_array; } else { return array(); } } public function getPDCompany($pdid) { $this->db->SELECT('PDCOMPANY.pd_company_id, PDCOMPANY.company_name, PDCOMPANY.isactive,PDCOMPANY.createdon,PDCOMPANY.updatedon'); $this->db->FROM(PDCOMPANY.' as PDCOMPANY'); $this->db->WHERE('PDCOMPANY.fk_pd_id ',$pdid); $this->db->ORDER_BY('PDCOMPANY.pd_company_id'); $result_child_array = $this->db->GET()->result_array(); if(count($result_child_array) != 0) { return $result_child_array; } else { return array(); } } /* * GET PD Log Details by pdid */ public function getPDLogs($pdid) { //$pdid = 63; //get pd Master Details $pd_master_detials = $this->getPDMasterDetails($pdid); $arrayForText = array("fk_lender_id" => "Lender", "fk_entity_billing_id" => "Billing ID", "lender_applicant_id" => "Applicant Ref ID", "pd_date_of_initiation" => "PD Date of Initiation", "fk_product_id" => "Product", "fk_subproduct_id" => "Sub Product","fk_pd_type" => "PD Type", "pd_status" => "PD Status", "pd_specific_clarification"=> "PD Specific Clarification","fk_pd_allocation_type" => "Allocation Type", "fk_pd_allocated_to" => "Allocated Person", "fk_pd_template_id" => "PD Tempale", "fk_customer_segment" => "Customer Segment", "pd_officier_final_judgement" => "PD Officer Finale Judgement", "pd_agency_id" => "PD Agency", "loan_amount" => "Loan Amount", "addressline1" => "Addressline1", "addressline2" => "Addressline1", "addressline3" => "Addressline1", "fk_city" => "City", "fk_state" => "State", "pincode" => "Pincode", "bounce_reason" => "Bounce Reason", "executive_id" => "PD Executive","central_pd_officer_id"=>"Central PD Officer","pd_contact_person" => "Lender Contact Person", "pd_contact_mobileno" => "Lender Contact Mobile Number", "scheduled_on" => "Scheduled On", "completed_on" => "Completed On",'fk_address_id' => 'PD Address Map','fk_primary_address_id' => 'Primary Address',"vendor_status" => 'Vendor Status'); $this->db->SELECT('COMMONMASTER.log_id, COMMONMASTER.primary_key, COMMONMASTER.table_name, COMMONMASTER.field_name, COMMONMASTER.old_value, COMMONMASTER.new_value, COMMONMASTER.fk_createdby, DATE_FORMAT(COMMONMASTER.createdon,"%D %b %Y at %h:%i:%s %p") as createdon,COMMONMASTER.createdon raw_date_createdon,concat(USERPROFILE.first_name," ",USERPROFILE.last_name) as createdby,ENTITYBILLINGOLD.billing_name as old_billing_name,ENTITYBILLINGNEW.billing_name as new_billing_name,ENTITYOLD.full_name as old_entity_name,ENTITYNEW.full_name as new_entity_name,PRODUCTSOLD.abbr as old_product,PRODUCTSNEW.abbr as new_product,SUBPRODUCTSOLD.abbr as old_sub_product,SUBPRODUCTSNEW.abbr as new_sub_product,PDTYPEOLD.type_name as old_type_name,PDTYPENEW.type_name as new_type_name,concat(ALLOCATEDOLD.first_name," ",ALLOCATEDOLD.last_name) as old_allocated_to,concat(ALLOCATEDNEW.first_name," ",ALLOCATEDNEW.last_name) as new_allocated_to,TEMPLATEOLD.template_name as old_template_name,TEMPLATENEW.template_name as new_template_name,CUSTOMERSEGMENTOLD.name as old_cs_name,CUSTOMERSEGMENTNEW.name as new_cs_name,AGENCYOLD.full_name as old_agencyname,AGENCYNEW.full_name as new_agencyname,CITYOLD.name as old_city,CITYNEW.name as new_city,STATEOLD.name as old_state,STATENEW.name as new_state,concat(EXECUTIVEOLD.first_name," ",EXECUTIVEOLD.last_name) as old_executive,concat(EXECUTIVENEW.first_name," ",EXECUTIVENEW.last_name) as new_executive,concat(CENTRALPDOLD.first_name," ",CENTRALPDOLD.last_name) as old_central_pd_officer_id,concat(CENTRALPDNEW.first_name," ",CENTRALPDNEW.last_name) as new_central_pd_officer_id,ALLOCATIONOLD.pd_allocation_type_name as old_allocation_type,ALLOCATIONNEW.pd_allocation_type_name as new_allocation_type,BOUNCEMASTEROLD.bounce_reason_name as old_bounce_reason,BOUNCEMASTERNEW.bounce_reason_name as new_bounce_reason,PINCODEOLD.pincode as old_pincode,PINCODENEW.pincode as new_pincode,PDTRIGGER.other_pincode'); $this->db->FROM(COMMONMASTER.' as COMMONMASTER'); $this->db->JOIN(USERPROFILE.' as USERPROFILE','COMMONMASTER.fk_createdby = USERPROFILE.userid','LEFT'); $this->db->JOIN(ENTITYBILLING.' as ENTITYBILLINGOLD','COMMONMASTER.old_value = ENTITYBILLINGOLD.entity_billing_id','LEFT'); $this->db->JOIN(ENTITYBILLING.' as ENTITYBILLINGNEW','COMMONMASTER.new_value = ENTITYBILLINGNEW.entity_billing_id','LEFT'); $this->db->JOIN(ENTITY.' as ENTITYOLD','COMMONMASTER.old_value = ENTITYOLD.entity_id','LEFT'); $this->db->JOIN(ENTITY.' as ENTITYNEW','COMMONMASTER.new_value = ENTITYNEW.entity_id','LEFT'); $this->db->JOIN(PRODUCTS.' as PRODUCTSOLD','COMMONMASTER.old_value = PRODUCTSOLD.product_id','LEFT'); $this->db->JOIN(PRODUCTS.' as PRODUCTSNEW','COMMONMASTER.new_value = PRODUCTSNEW.product_id','LEFT'); $this->db->JOIN(SUBPRODUCTS.' as SUBPRODUCTSOLD','COMMONMASTER.old_value = SUBPRODUCTSOLD.subproduct_id','LEFT'); $this->db->JOIN(SUBPRODUCTS.' as SUBPRODUCTSNEW','COMMONMASTER.new_value = SUBPRODUCTSNEW.subproduct_id','LEFT'); $this->db->JOIN(PDTYPE.' as PDTYPEOLD','COMMONMASTER.old_value = PDTYPEOLD.pd_type_id','LEFT'); $this->db->JOIN(PDTYPE.' as PDTYPENEW','COMMONMASTER.new_value = PDTYPENEW.pd_type_id','LEFT'); $this->db->JOIN(USERPROFILE.' as ALLOCATEDOLD','COMMONMASTER.old_value = ALLOCATEDOLD.userid','LEFT'); $this->db->JOIN(USERPROFILE.' as ALLOCATEDNEW','COMMONMASTER.new_value = ALLOCATEDNEW.userid','LEFT'); $this->db->JOIN(TEMPLATE.' as TEMPLATEOLD','COMMONMASTER.old_value = TEMPLATEOLD.template_id','LEFT'); $this->db->JOIN(TEMPLATE.' as TEMPLATENEW','COMMONMASTER.new_value = TEMPLATENEW.template_id','LEFT'); $this->db->JOIN(CUSTOMERSEGMENT.' as CUSTOMERSEGMENTOLD','COMMONMASTER.old_value = CUSTOMERSEGMENTOLD.customer_segment_id','LEFT'); $this->db->JOIN(CUSTOMERSEGMENT.' as CUSTOMERSEGMENTNEW','COMMONMASTER.new_value = CUSTOMERSEGMENTNEW.customer_segment_id','LEFT'); $this->db->JOIN(ENTITY.' as AGENCYOLD','COMMONMASTER.old_value = AGENCYOLD.entity_id','LEFT'); $this->db->JOIN(ENTITY.' as AGENCYNEW','COMMONMASTER.new_value = AGENCYNEW.entity_id','LEFT'); $this->db->JOIN(CITY.' as CITYOLD','COMMONMASTER.old_value = CITYOLD.city_id','LEFT'); $this->db->JOIN(CITY.' as CITYNEW','COMMONMASTER.new_value = CITYNEW.city_id','LEFT'); $this->db->JOIN(STATE.' as STATEOLD','COMMONMASTER.old_value = STATEOLD.state_id','LEFT'); $this->db->JOIN(STATE.' as STATENEW','COMMONMASTER.new_value = STATENEW.state_id','LEFT'); $this->db->JOIN(USERPROFILE.' as EXECUTIVEOLD','COMMONMASTER.old_value = EXECUTIVEOLD.userid','LEFT'); $this->db->JOIN(USERPROFILE.' as EXECUTIVENEW','COMMONMASTER.new_value = EXECUTIVENEW.userid','LEFT'); $this->db->JOIN(USERPROFILE.' as CENTRALPDOLD','COMMONMASTER.old_value = CENTRALPDOLD.userid','LEFT'); $this->db->JOIN(USERPROFILE.' as CENTRALPDNEW','COMMONMASTER.new_value = CENTRALPDNEW.userid','LEFT'); $this->db->JOIN(PDALLOCATIONTYPE.' as ALLOCATIONOLD','COMMONMASTER.old_value = ALLOCATIONOLD.pd_allocation_type_id','LEFT'); $this->db->JOIN(PDALLOCATIONTYPE.' as ALLOCATIONNEW','COMMONMASTER.new_value = ALLOCATIONNEW.pd_allocation_type_id','LEFT'); $this->db->JOIN(BOUNCEMASTER.' as BOUNCEMASTEROLD','COMMONMASTER.old_value = BOUNCEMASTEROLD.bounce_id','LEFT'); $this->db->JOIN(BOUNCEMASTER.' as BOUNCEMASTERNEW','COMMONMASTER.new_value = BOUNCEMASTERNEW.bounce_id','LEFT'); $this->db->JOIN(PINCODE.' as PINCODEOLD','COMMONMASTER.old_value = PINCODEOLD.pincode_id','LEFT'); $this->db->JOIN(PINCODE.' as PINCODENEW','COMMONMASTER.new_value = PINCODENEW.pincode_id','LEFT'); $this->db->JOIN(PDTRIGGER.' as PDTRIGGER','COMMONMASTER.primary_key = PDTRIGGER.pd_id','LEFT'); $this->db->WHERE('COMMONMASTER.table_name="'.PDTRIGGER.'" AND COMMONMASTER.primary_key=',$pdid); $this->db->ORDER_BY('COMMONMASTER.log_id'); $logs = $this->db->GET()->result_array(); //print_r($logs);die(); //$sql = 'SELECT * FROM '.COMMONMASTER.' WHERE table_name = "'.PDTRIGGER.'" AND primary_key = '.$pdid; //$logs = $this->db->query($sql)->result_array(); $last_status_update_date = null; $actual_logs = array(); $revert_remark_iteration = 0; if(count($logs)) { foreach($logs as $log_key => $log) { if($log_key == (count($logs) - 1) && $log['field_name'] == 'pd_status') { $last_status_update_date = $log['raw_date_createdon']; //echo $last_status_update_date;die(); } if($log_key == 0 && $log['field_name'] == 'pd_status') { $log_string = 'PD Created with "'.$log['new_value'].'" status '; $user = $log['createdby']; $time = $log['createdon']; $actual_logs[$log_key]['log'] = $log_string; $actual_logs[$log_key]['user'] = $user; $actual_logs[$log_key]['time'] = $time; } else { $field_name = $log['field_name']; //print_r($field_name); switch($field_name){ case 'fk_entity_billing_id': $log_string = $arrayForText[$log['field_name']].' Changed From "'.$log['old_billing_name'].'" to "'.$log['new_billing_name'].'"'; $user = $log['createdby']; $time = $log['createdon']; $actual_logs[$log_key]['log'] = $log_string; $actual_logs[$log_key]['user'] = $user; $actual_logs[$log_key]['time'] = $time; break; case 'fk_lender_id': $log_string = $arrayForText[$log['field_name']].' Changed From "'.$log['old_entity_name'].'" to "'.$log['new_entity_name'].'"'; $user = $log['createdby']; $time = $log['createdon']; $actual_logs[$log_key]['log'] = $log_string; $actual_logs[$log_key]['user'] = $user; $actual_logs[$log_key]['time'] = $time; break; case 'fk_product_id': $log_string = $arrayForText[$log['field_name']].' Changed From "'.$log['old_product'].'" to "'.$log['new_product'].'"'; $user = $log['createdby']; $time = $log['createdon']; $actual_logs[$log_key]['log'] = $log_string; $actual_logs[$log_key]['user'] = $user; $actual_logs[$log_key]['time'] = $time; break; case 'fk_subproduct_id': $log_string = $arrayForText[$log['field_name']].' Changed From "'.$log['old_sub_product'].'" to "'.$log['new_sub_product'].'"'; $user = $log['createdby']; $time = $log['createdon']; $actual_logs[$log_key]['log'] = $log_string; $actual_logs[$log_key]['user'] = $user; $actual_logs[$log_key]['time'] = $time; break; case 'fk_pd_type': $log_string = $arrayForText[$log['field_name']].' Changed From "'.$log['old_type_name'].'" to "'.$log['new_type_name'].'"'; $actual_logs[] = $log_string; break; case 'fk_pd_allocated_to': if($log['old_allocated_to'] != null || $log['old_allocated_to'] != "" || $log['old_allocated_to'] != 0) { $log_string = $arrayForText[$log['field_name']].' Changed From "'.$log['old_allocated_to'].'" to "'.$log['new_allocated_to'].'"'; $user = $log['createdby']; $time = $log['createdon']; $actual_logs[$log_key]['log'] = $log_string; $actual_logs[$log_key]['user'] = $user; $actual_logs[$log_key]['time'] = $time; } // else // { // $log_string = ' PD Allocated to "'.$log['new_allocated_to'].'"'; // $user = $log['createdby']; // $time = $log['createdon']; // $actual_logs[$log_key]['log'] = $log_string; // $actual_logs[$log_key]['user'] = $user; // $actual_logs[$log_key]['time'] = $time; // } break; case 'fk_pd_template_id': $log_string = $arrayForText[$log['field_name']].' Changed From "'.$log['old_template_name'].'" to "'.$log['new_template_name'].'"'; //$actual_logs[] = $log_string; $user = $log['createdby']; $time = $log['createdon']; $actual_logs[$log_key]['log'] = $log_string; $actual_logs[$log_key]['user'] = $user; $actual_logs[$log_key]['time'] = $time; break; case 'fk_customer_segment': $log_string = $arrayForText[$log['field_name']].' Changed From "'.$log['old_cs_name'].'" to "'.$log['new_cs_name'].'"'; $user = $log['createdby']; $time = $log['createdon']; $actual_logs[$log_key]['log'] = $log_string; $actual_logs[$log_key]['user'] = $user; $actual_logs[$log_key]['time'] = $time; break; case 'pd_agency_id': $log_string = $arrayForText[$log['field_name']].' Changed From "'.$log['old_agencyname'].'" to "'.$log['new_agencyname'].'"'; $actual_logs[] = $log_string; break; case 'fk_city': $log_string = $arrayForText[$log['field_name']].' Changed From "'.$log['old_city'].'" to "'.$log['new_city'].'"'; $user = $log['createdby']; $time = $log['createdon']; $actual_logs[$log_key]['log'] = $log_string; $actual_logs[$log_key]['user'] = $user; $actual_logs[$log_key]['time'] = $time; break; case 'fk_state': $log_string = $arrayForText[$log['field_name']].' Changed From "'.$log['old_state'].'" to "'.$log['new_state'].'"'; $user = $log['createdby']; $time = $log['createdon']; $actual_logs[$log_key]['log'] = $log_string; $actual_logs[$log_key]['user'] = $user; $actual_logs[$log_key]['time'] = $time; break; case 'fk_pd_allocation_type': $log_string = $arrayForText[$log['field_name']].' Changed From "'.$log['old_state'].'" to "'.$log['new_state'].'"'; $user = $log['createdby']; $time = $log['createdon']; $actual_logs[$log_key]['log'] = $log_string; $actual_logs[$log_key]['user'] = $user; $actual_logs[$log_key]['time'] = $time; break; case 'pincode': //echo "pincode_ide"; if($log['old_pincode'] != null || $log['old_pincode'] != "") { if(is_numeric($log['new_pincode']) && is_numeric($log['old_pincode'])) { $log_string = $arrayForText[$log['field_name']].' Changed From "'.$log['old_pincode'].'" to "'.$log['new_pincode'].'"'; $user = $log['createdby']; $time = $log['createdon']; $actual_logs[$log_key]['log'] = $log_string; $actual_logs[$log_key]['user'] = $user; $actual_logs[$log_key]['time'] = $time; } else if(!is_numeric($log['new_pincode'])) { $log_string = $arrayForText[$log['field_name']].' Changed From "'.$log['old_pincode'].'" to "'.$log['other_pincode'].'"'; $user = $log['createdby']; $time = $log['createdon']; $actual_logs[$log_key]['log'] = $log_string; $actual_logs[$log_key]['user'] = $user; $actual_logs[$log_key]['time'] = $time; } else if(!is_numeric($log['old_pincode'])) { //echo "FOUND"; $log_string = $arrayForText[$log['field_name']].' Changed From "'.$log['other_pincode'].'" to "'.$log['new_pincode'].'"'; $user = $log['createdby']; $time = $log['createdon']; $actual_logs[$log_key]['log'] = $log_string; $actual_logs[$log_key]['user'] = $user; $actual_logs[$log_key]['time'] = $time; } } break; case 'executive_id': if($log['old_executive'] != null || $log['old_executive'] != "" || $log['old_executive'] != 0) { $log_string = $arrayForText[$log['field_name']].' Changed From "'.$log['old_executive'].'" to "'.$log['new_executive'].'"'; $user = $log['createdby']; $time = $log['createdon']; $actual_logs[$log_key]['log'] = $log_string; $actual_logs[$log_key]['user'] = $user; $actual_logs[$log_key]['time'] = $time; } // else // { // $log_string = 'PD assigned to Executive Officer "'.$log['new_executive'].'"'; // $user = $log['createdby']; // $time = $log['createdon']; // $actual_logs[$log_key]['log'] = $log_string; // $actual_logs[$log_key]['user'] = $user; // $actual_logs[$log_key]['time'] = $time; // } break; case 'central_pd_officer_id': if($log['old_central_pd_officer_id'] != null || $log['old_central_pd_officer_id'] != "" || $log['old_central_pd_officer_id'] != 0) { $log_string = $arrayForText[$log['field_name']].' Changed From "'.$log['old_central_pd_officer_id'].'" to "'.$log['new_central_pd_officer_id'].'"'; $user = $log['createdby']; $time = $log['createdon']; $actual_logs[$log_key]['log'] = $log_string; $actual_logs[$log_key]['user'] = $user; $actual_logs[$log_key]['time'] = $time; } // else // { // $log_string = 'PD assigned to Central PD Officer "'.$log['new_central_pd_officer_id'].'"'; // $user = $log['createdby']; // $time = $log['createdon']; // $actual_logs[$log_key]['log'] = $log_string; // $actual_logs[$log_key]['user'] = $user; // $actual_logs[$log_key]['time'] = $time; // } break; case 'vendor_status': $data_from_remarks = $this->selectCustomRecords(array('remark'),array('fk_pd_id' => $pdid,'is_revert_remark' => 1),PDREMARKS); $log_string = $arrayForText[$log['field_name']].' Changed From "'.$log['old_value'].'" to "'.$log['new_value'].'"'; $user = $log['createdby']; $time = $log['createdon']; $actual_logs[$log_key]['user'] = $user; $actual_logs[$log_key]['time'] = $time; $actual_logs[$log_key]['log'] = $log_string; if($log['new_value'] == ALLOCATED) { // if($pd_master_detials[0]['fk_pd_type'] == 1)//FULL PD // { // $actual_logs[$log_key]['meta_data'][] = array('display_name' => 'Allocated to PD Officer','display_value' => $pd_master_detials[0]['pd_allocated_to']); // } if(!$log['old_value'])//SMART PD { $actual_logs[$log_key]['log'] = 'PD Allocated to Vendor PD Officer'; // $actual_logs[$log_key]['meta_data'][] = array('display_name' => 'Allocated to Central PD Officer','display_value' => $pd_master_detials[0]['centralofficer']); // $actual_logs[$log_key]['meta_data'][] = array('display_name' => 'Allocated to Executive PD Officer','display_value' => $pd_master_detials[0]['executive_name']); $actual_logs[$log_key]['meta_data'][] = array('display_name' => 'Allocated to PD Officer','display_value' => $pd_master_detials[0]['pd_allocated_to']); } else { // $actual_logs[$log_key]['meta_data'][] = array('display_name' => 'Allocated to Central PD Officer','display_value' => $pd_master_detials[0]['centralofficer']); // $actual_logs[$log_key]['meta_data'][] = array('display_name' => 'Allocated to Executive PD Officer','display_value' => $pd_master_detials[0]['executive_name']); $actual_logs[$log_key]['meta_data'][] = array('display_name' => 'Allocated to PD Officer','display_value' => $pd_master_detials[0]['pd_allocated_to']); } // else //Tele PD // { // $actual_logs[$log_key]['meta_data']['Allocated to Central PD Officer'] = $pd_master_detials[0]['centralofficer']; // } } else if($log['new_value'] == SCHEDULED) { $actual_logs[$log_key]['meta_data'][] = array('display_name' => 'Scheduled Date','display_value' => $pd_master_detials[0]['scheduled_date_for_log']); $actual_logs[$log_key]['meta_data'][] = array('display_name' => 'Scheduled Time','display_value' => $pd_master_detials[0]['scheduled_time_for_log']); } else if($log['new_value'] == BOUNCED) { $actual_logs[$log_key]['meta_data'][] = array('display_name'=>'Rejected Reason','display_value' => $pd_master_detials[0]['bounce_reason_name']); if($pd_master_detials[0]['bounce_reason_others'] != "" || $pd_master_detials[0]['bounce_reason_others'] != null) { $actual_logs[$log_key]['meta_data'][] = array('display_name'=>'Rejected Reason Others','display_value'=> $pd_master_detials[0]['bounce_reason_others']); } } else if($log['new_value'] == COMPLETED)// && $log['old_value'] == QC_COMPLETED) { $actual_logs[$log_key]['meta_data'][] = array('display_name'=>'Remark of status change','display_value'=> $data_from_remarks[ $revert_remark_iteration ]['remark']); $revert_remark_iteration++; } break; case 'pd_status': $data_from_remarks = $this->selectCustomRecords(array('remark'),array('fk_pd_id' => $pdid,'is_revert_remark' => 1),PDREMARKS); $log_string = $arrayForText[$log['field_name']].' Changed From "'.$log['old_value'].'" to "'.$log['new_value'].'"'; $user = $log['createdby']; $time = $log['createdon']; $actual_logs[$log_key]['user'] = $user; $actual_logs[$log_key]['time'] = $time; $actual_logs[$log_key]['log'] = $log_string; if($log['new_value'] == ALLOCATED) { if($pd_master_detials[0]['fk_pd_type'] == 1)//FULL PD { $actual_logs[$log_key]['meta_data'][] = array('display_name' => 'Allocated to PD Officer','display_value' => $pd_master_detials[0]['pd_allocated_to']); } else if($pd_master_detials[0]['fk_pd_type'] == 2)//SMART PD { $actual_logs[$log_key]['meta_data'][] = array('display_name' => 'Allocated to Central PD Officer','display_value' => $pd_master_detials[0]['centralofficer']); $actual_logs[$log_key]['meta_data'][] = array('display_name' => 'Allocated to Executive PD Officer','display_value' => $pd_master_detials[0]['executive_name']); } else //Tele PD { $actual_logs[$log_key]['meta_data']['Allocated to Central PD Officer'] = $pd_master_detials[0]['centralofficer']; } } else if($log['new_value'] == SCHEDULED) { $actual_logs[$log_key]['meta_data'][] = array('display_name' => 'Scheduled Date','display_value' => $pd_master_detials[0]['scheduled_date_for_log']); $actual_logs[$log_key]['meta_data'][] = array('display_name' => 'Scheduled Time','display_value' => $pd_master_detials[0]['scheduled_time_for_log']); } else if($log['new_value'] == BOUNCED) { $actual_logs[$log_key]['meta_data'][] = array('display_name'=>'Rejected Reason','display_value' => $pd_master_detials[0]['bounce_reason_name']); if($pd_master_detials[0]['bounce_reason_others'] != "" || $pd_master_detials[0]['bounce_reason_others'] != null) { $actual_logs[$log_key]['meta_data'][] = array('display_name'=>'Rejected Reason Others','display_value'=> $pd_master_detials[0]['bounce_reason_others']); } } else if($log['new_value'] == COMPLETED && $log['old_value'] == QC_COMPLETED) { $actual_logs[$log_key]['meta_data'][] = array('display_name'=>'Remark of status change','display_value'=> $data_from_remarks[ $revert_remark_iteration ]['remark']); $revert_remark_iteration++; } else if($log['new_value'] == CANCELLED) { $actual_logs[$log_key]['meta_data'][] = array('display_name'=>'Remark of PD cancelleation','display_value'=> $pd_master_detials[0]['cancel_pd_remark']); } break; default: $log_string = $arrayForText[$log['field_name']].' Changed From "'.$log['old_value'].'" to "'.$log['new_value'].'"'; $user = $log['createdby']; $time = $log['createdon']; $actual_logs[$log_key]['log'] = $log_string; $actual_logs[$log_key]['user'] = $user; $actual_logs[$log_key]['time'] = $time; } } } } $result_data['child'] = array('testkey'=>'testvalue'); $result_data['master'] = $actual_logs; $result_data['last_status_update_date'] = $last_status_update_date ; //print_r($result_data['master']);die(); // Child History Start // $this->db->SELECT('PDAPPLICANTSDETAILS.pd_co_applicant_id, PDAPPLICANTSDETAILS.fk_pd_id, PDAPPLICANTSDETAILS.applicant_name, PDAPPLICANTSDETAILS.applicant_type, PDAPPLICANTSDETAILS.mobile_no, PDAPPLICANTSDETAILS.email, PDAPPLICANTSDETAILS.isactive, PDAPPLICANTSDETAILS.relation'); // $this->db->FROM(PDAPPLICANTSDETAILS.' as PDAPPLICANTSDETAILS'); // $this->db->JOIN(PDTRIGGER.' as PDTRIGGER'); // $this->db->WHERE('PDAPPLICANTSDETAILS.table_name="'.PDAPPLICANTSDETAILS.'" AND COMMONMASTER.primary_key=',$pd_co_applicant_id); // $this->db->GET('')->result_array(); return $result_data; } /* * GET PD Question Answers Details by pdid */ public function getPDQuestionAnswers($pdid) { return array(); } /* *Get PD Master Details. */ public function getPDMasterDetails($pdid,$random_string = null) { $this->db->SELECT('PDTRIGGER.pd_id, PDTRIGGER.pd_sno,PDTRIGGER.fk_lender_id,PDTRIGGER.sub_entity_id,SUBENTITY.short_name as sub_entity_short_name,PDTRIGGER.imgc_fin_institute,ENTITY.full_name as lender_full_name,ENTITY.short_name as lender_short_name,ENTITY.is_score_card_enabled,ENTITY.is_otp_enabled, PDTRIGGER.fk_entity_billing_id,ENTITYBILLING.billing_name,PDTRIGGER.lender_applicant_id, DATE_FORMAT(PDTRIGGER.pd_date_of_initiation, "%d/%m/%Y") as pd_date_of_initiation,PDTRIGGER.pd_date_of_initiation as pd_date_of_initiation_sqlformat, PDTRIGGER.fk_product_id,PRODUCTS.name as product_name,PRODUCTS.abbr as product_abbr, PRODUCTS.prod_catagory,PDTRIGGER.fk_subproduct_id,SUBPRODUCTS.name as subproduct_name,SUBPRODUCTS.abbr as subproduct_abbr, PDTRIGGER.fk_pd_type,PDTYPE.type_name as pd_type_name, PDTRIGGER.pd_status,PDTRIGGER.pd_specific_clarification, DATE_FORMAT(PDTRIGGER.createdon,"%d/%m/%Y %h:%i:%s %p") as createdon, PDTRIGGER.fk_createdby, DATE_FORMAT(PDTRIGGER.updatedon,"%d/%m/%Y %H:%i %p") as updatedon, PDTRIGGER.fk_updatedby,concat(USERPROFILE.first_name," ",USERPROFILE.last_name) as createdby,concat(USERPROFILE1.first_name," ",USERPROFILE1.last_name) as updatedby,DESIGNATION.designation as updatedby_designation,PDTRIGGER.fk_pd_allocation_type,,PDALLOCATIONTYPE.pd_allocation_type_name, PDTRIGGER.fk_pd_allocated_to,concat(USERPROFILE2.first_name," ",USERPROFILE2.last_name) as pd_allocated_to,PDTRIGGER.executive_id,concat(EXECUTIVE.first_name," ",EXECUTIVE.last_name) as executive_name,PDTRIGGER.central_pd_officer_id,concat(CENTRALOFFICER.first_name," ",CENTRALOFFICER.last_name) as centralofficer,PDTRIGGER.fk_pd_template_id,TEMPLATE.template_name, PDTRIGGER.fk_customer_segment,CUSTOMERSEGMENT.name as customer_segment_name,CUSTOMERSEGMENT.abbr as customer_segment_abbr, PDTRIGGER.pd_officier_final_judgement, PDTRIGGER.pd_agency_id,AGENCY.is_qc_enabled,AGENCY.full_name as agency_name,AGENCY.short_name as agency_short_name,PDTRIGGER.vendor_pdofficer,concat(VENDORPDOFFICER.first_name," ",VENDORPDOFFICER.last_name) as vendor_pdofficer_name,PDTRIGGER.loan_amount,PDTRIGGER.addressline1,PDTRIGGER.addressline2,PDTRIGGER.addressline3,PDTRIGGER.fk_city,CITY.name as city_name,PDTRIGGER.fk_state,STATE.name as state_name,PINCODE.pincode,PDTRIGGER.pincode as pincode_id,PDTRIGGER.lender_sales_person,concat(LENDERSALESPERSON.first_name," ",LENDERSALESPERSON.last_name) as lender_sales_person_name,LENDERSALESPERSON.mobile_no as lender_sales_contact_mobileno,LENDERSALESPERSON.email as lender_sales_person_email,PDTRIGGER.lender_credit_person,concat(LENDERCREDITPERSON.first_name," ",LENDERCREDITPERSON.last_name) as lender_credit_person_name,LENDERCREDITPERSON.mobile_no as lender_credit_person_contact_mobileno,LENDERCREDITPERSON.email as lender_credit_person_email,PDTRIGGER.pd_contact_person,PDTRIGGER.pd_contact_mobileno,DATE_FORMAT(PDTRIGGER.scheduled_on,"%d/%m/%Y %h:%i %p") as scheduled_on,PDTRIGGER.scheduled_on as scheduled_on_for_validation,DATE_FORMAT(PDTRIGGER.scheduled_on,"%dth %b %Y ") as scheduled_date_for_log,DATE_FORMAT(PDTRIGGER.scheduled_on,"%h:%i %p") as scheduled_time_for_log,DATE_FORMAT(PDTRIGGER.completed_on,"%d/%m/%Y %h:%i:%s %p") as completed_on,PDTRIGGER.remarks,PDTRIGGER.bounce_reason,PDTRIGGER.bounce_reason_others,BOUNCEMASTER.bounce_reason_name,PDTRIGGER.is_original_report_created,PDTRIGGER.pd_report_latest_version,PDAPPLICANTSDETAILS.applicant_name as main_applicant,PDTRIGGER.pd_branch_id,ENTITYLENDERBRANCH.branch_name,PDTRIGGER.qc_feedback,PDTRIGGER.qc_rating,PDTRIGGER.qc_remarks,PDTRIGGER.lender_rating,PDTRIGGER.lender_feedback,PDAPPLICANTSDETAILS.applicant_title_name,TITLES.name as title_name,PDTRIGGER.pd_contact_landline,PDTRIGGER.other_pincode,PDTRIGGER.is_otp_done,OTPREJECTION.rejection_reason,PDTRIGGER.otp_reject_other_reason,PDTRIGGER.encrypted_url,PDTRIGGER.is_child,PDTRIGGER.parent_pd_id,PDTRIGGER.fk_primary_address_id,PDTRIGGER.fk_address_id,PDTRIGGER.start_location,PDTRIGGER.satellite_image_base64_blob,DATE_FORMAT(PDTRIGGER.pd_report_generated_date,"%d/%m/%Y %h:%i:%s %p") as pd_report_generated_date,DATE_FORMAT(PDTRIGGER.pd_visit_date,"%d/%m/%Y %h:%i:%s %p") as pd_visit_date,PDTRIGGER.random_string,PDTRIGGER.pd_report_html_filename,PDTRIGGER.is_qc_edited,PDTRIGGER.is_zip_created,PDTRIGGER.pd_qc_note,ENTITY.is_sms_enabled,ENTITY.is_mail_enabled,ENTITY.is_app_notify_enabled,AGENCY.is_vendor_visit_disabled,PDTRIGGER.is_notify_enabled,ENTITYFININSTITUTION.institute_name as fin_institute_name,PDTRIGGER.is_img_pdf_created,PDTRIGGER.is_video_merged,PDTRIGGER.vendor_status,PDTRIGGER.vendor_scheduled_on as vendor_scheduled_on_validation,DATE_FORMAT(PDTRIGGER.vendor_scheduled_on,"%d/%m/%Y %h:%i %p") as vendor_scheduled_on,PDTRIGGER.complete_override_data,PDTRIGGER.excel_file_id,SMC_EXCEL_FILELIST.file_name,SMC_EXCEL_FILELIST.modified_fname,PDTRIGGER.mwise_sales_person,PDTRIGGER.is_field_visit_done,PDTRIGGER.cancel_pd_remark,if(SMC_EXCEL_FILELIST_RE_UPLOAD.fk_pd_id is not null,"1","0") as re_uploaded,SMC_EXCEL_FILELIST_RE_UPLOAD.modified_fname as re_uploaded_file_name,ROLES.role_id as pd_allocated_to_role_id'); $this->db->FROM(PDTRIGGER.' as PDTRIGGER'); $this->db->JOIN(ENTITY.' as ENTITY','PDTRIGGER.fk_lender_id = ENTITY.entity_id ','LEFT'); $this->db->JOIN(ENTITY.' as SUBENTITY','PDTRIGGER.sub_entity_id = SUBENTITY.entity_id ','LEFT'); $this->db->JOIN(ENTITYBILLING.' as ENTITYBILLING','PDTRIGGER.fk_entity_billing_id = ENTITYBILLING.entity_billing_id','LEFT'); $this->db->JOIN(PRODUCTS.' as PRODUCTS','PDTRIGGER.fk_product_id = PRODUCTS.product_id','LEFT'); $this->db->JOIN(SUBPRODUCTS.' as SUBPRODUCTS','PDTRIGGER.fk_subproduct_id = SUBPRODUCTS.subproduct_id','LEFT'); $this->db->JOIN(PDTYPE.' as PDTYPE','PDTRIGGER.fk_pd_type = PDTYPE.pd_type_id','LEFT'); //$this->db->JOIN(PDSTATUS.' as PDSTATUS','PDTRIGGER.pd_status = PDSTATUS.pd_status_id','LEFT'); $this->db->JOIN(USERPROFILE.' as USERPROFILE','PDTRIGGER.fk_createdby = USERPROFILE.userid','LEFT'); $this->db->JOIN(USERPROFILE.' as USERPROFILE1','PDTRIGGER.fk_updatedby = USERPROFILE1.userid','LEFT'); $this->db->JOIN(PDALLOCATIONTYPE.' as PDALLOCATIONTYPE','PDTRIGGER.fk_pd_allocation_type = PDALLOCATIONTYPE.pd_allocation_type_id','LEFT'); $this->db->JOIN(USERPROFILE.' as USERPROFILE2','PDTRIGGER.fk_pd_allocated_to = USERPROFILE2.userid','LEFT'); $this->db->JOIN(USERPROFILE.' as USERPROFILE3','PDTRIGGER.executive_id = USERPROFILE3.userid','LEFT'); $this->db->JOIN(USERPROFILE.' as EXECUTIVE','PDTRIGGER.executive_id = EXECUTIVE.userid','LEFT'); $this->db->JOIN(USERPROFILE.' as CENTRALOFFICER','PDTRIGGER.central_pd_officer_id = CENTRALOFFICER.userid','LEFT'); $this->db->JOIN(USERPROFILE.' as LENDERSALESPERSON','PDTRIGGER.lender_sales_person = LENDERSALESPERSON.userid','LEFT'); $this->db->JOIN(USERPROFILE.' as LENDERCREDITPERSON','PDTRIGGER.lender_credit_person = LENDERCREDITPERSON.userid','LEFT'); $this->db->JOIN(USERPROFILE.' as VENDORPDOFFICER','PDTRIGGER.vendor_pdofficer = VENDORPDOFFICER.userid','LEFT'); $this->db->JOIN(TEMPLATE.' as TEMPLATE','PDTRIGGER.fk_pd_template_id = TEMPLATE.template_id','LEFT'); $this->db->JOIN(CUSTOMERSEGMENT.' as CUSTOMERSEGMENT','PDTRIGGER.fk_customer_segment = CUSTOMERSEGMENT.customer_segment_id','LEFT'); $this->db->JOIN(ENTITY.' as AGENCY','PDTRIGGER.pd_agency_id = AGENCY.entity_id','LEFT'); $this->db->JOIN(STATE.' as STATE','PDTRIGGER.fk_state = STATE.state_id ','LEFT'); $this->db->JOIN(CITY.' as CITY','PDTRIGGER.fk_city = CITY.city_id','LEFT'); $this->db->JOIN(PINCODE.' as PINCODE','PDTRIGGER.pincode = PINCODE.pincode_id','LEFT'); $this->db->JOIN(BOUNCEMASTER.' as BOUNCEMASTER','PDTRIGGER.bounce_reason = BOUNCEMASTER.bounce_id','LEFT'); $this->db->JOIN(PDAPPLICANTSDETAILS.' as PDAPPLICANTSDETAILS','PDTRIGGER.pd_id = PDAPPLICANTSDETAILS.fk_pd_id AND PDAPPLICANTSDETAILS.applicant_type = 1','LEFT'); $this->db->JOIN(ENTITYLENDERBRANCH.' as ENTITYLENDERBRANCH','PDTRIGGER.pd_branch_id = ENTITYLENDERBRANCH.entity_lender_branch_id','LEFT'); $this->db->JOIN(ENTITYFININSTITUTION.' as ENTITYFININSTITUTION','PDTRIGGER.imgc_fin_institute = ENTITYFININSTITUTION.entity_fin_institution_id','LEFT'); $this->db->JOIN(TITLES.' as TITLES','PDAPPLICANTSDETAILS.applicant_title_name = TITLES.title_id','LEFT'); $this->db->JOIN(OTPREJECTION.' as OTPREJECTION','PDTRIGGER.otp_reject_reason = OTPREJECTION.otp_rejection_id','LEFT'); $this->db->JOIN(SMC_EXCEL_FILELIST.' as SMC_EXCEL_FILELIST','SMC_EXCEL_FILELIST.id = PDTRIGGER.excel_file_id','LEFT'); $this->db->JOIN(SMC_EXCEL_FILELIST.' as SMC_EXCEL_FILELIST_RE_UPLOAD','PDTRIGGER.pd_id = SMC_EXCEL_FILELIST_RE_UPLOAD.fk_pd_id AND SMC_EXCEL_FILELIST_RE_UPLOAD.isactive = 1','LEFT'); $this->db->JOIN(DESIGNATION.' as DESIGNATION','USERPROFILE1.designation = DESIGNATION.designation_id','LEFT'); $this->db->JOIN(USERPROFILEROLES.' as ALLOCATED_PERSION_ROLE','PDTRIGGER.fk_pd_allocated_to = ALLOCATED_PERSION_ROLE.fk_userid AND ALLOCATED_PERSION_ROLE.isactive = 1','LEFT'); $this->db->JOIN(ROLES.' as ROLES','ALLOCATED_PERSION_ROLE.user_role = ROLES.role_id','LEFT'); $this->db->WHERE('PDTRIGGER.pd_id',$pdid); if($random_string != null) { $this->db->WHERE('PDTRIGGER.random_string',$random_string); } // $this->db->ORDER_BY('PDTRIGGER.pd_id',$sort); // $this->db->LIMIT($limit,$page); $result_array = $this->db->GET()->result_array(); //print_r($result_array);die(); $mandatory_fields = array(); if(count($result_array)) { if($result_array[0]['fk_lender_id'] == "" || $result_array[0]['fk_lender_id'] == null){ $mandatory_fields[] = 'fk_lender_id'; } if($result_array[0]['pd_branch_id'] == "" || $result_array[0]['pd_branch_id'] == null){ $mandatory_fields[] = 'pd_branch_id'; } if($result_array[0]['lender_applicant_id'] == "" || $result_array[0]['lender_applicant_id'] == null){ $mandatory_fields[] = 'lender_applicant_id'; } if($result_array[0]['fk_product_id'] == "" || $result_array[0]['fk_product_id'] == null || $result_array[0]['fk_product_id'] == 0){ $mandatory_fields[] = 'fk_product_id'; } if(($result_array[0]['lender_short_name'] != 'CLIX') && ($result_array[0]['lender_short_name'] != 'MWISE' && $result_array[0]['prod_catagory'] != "BL")) { if($result_array[0]['fk_subproduct_id'] == "" || $result_array[0]['fk_subproduct_id'] == null || $result_array[0]['fk_subproduct_id'] == 0){ $mandatory_fields[] = 'fk_subproduct_id'; } } if($result_array[0]['fk_pd_type'] == "" || $result_array[0]['fk_pd_type'] == null || $result_array[0]['fk_pd_type'] == 0){ $mandatory_fields[] = 'fk_pd_type'; } if($result_array[0]['fk_customer_segment'] == "" || $result_array[0]['fk_customer_segment'] == null || $result_array[0]['fk_customer_segment'] == 0){ $mandatory_fields[] = 'fk_customer_segment'; } if($result_array[0]['loan_amount'] == "" || $result_array[0]['loan_amount'] == null){ $mandatory_fields[] = 'loan_amount'; } if($result_array[0]['addressline1'] == "" || $result_array[0]['addressline1'] == null){ $mandatory_fields[] = 'addressline1'; } // if($result_array[0]['fk_city'] == "" || $result_array[0]['fk_city'] == null){ $mandatory_fields[] = 'fk_city'; } if($result_array[0]['main_applicant'] == "" || $result_array[0]['main_applicant'] == null){ $mandatory_fields[] = 'main_applicant'; } if($result_array[0]['fk_state'] == "" || $result_array[0]['fk_state'] == null){ $mandatory_fields[] = 'fk_state'; } if($result_array[0]['pincode'] == "" || $result_array[0]['pincode'] == null){ $mandatory_fields[] = 'pincode'; } if($result_array[0]['lender_credit_person'] == "" || $result_array[0]['lender_credit_person'] == null) { $mandatory_fields[] = 'lender_credit_person'; } // if($result_array[0]['pd_contact_landline'] == "" || $result_array[0]['pd_contact_landline'] == null) // { // if($result_array[0]['pd_contact_mobileno'] == "" || $result_array[0]['pd_contact_mobileno'] == null) // { // $mandatory_fields[] = 'pd_contact_mobileno'; // } // } if($result_array[0]['fk_address_id'] == "" || $result_array[0]['fk_address_id'] == null) { $mandatory_fields[] = 'fk_address_id'; } if($result_array[0]['is_child'] == 0) { if($result_array[0]['fk_primary_address_id'] == "" || $result_array[0]['fk_primary_address_id'] == null) { $mandatory_fields[] = 'fk_primary_address_id'; } } } $result_array[]['mandatory_fields'] = $mandatory_fields; return $result_array; } public function getPDAdditionalRequirements($pdid) { $this->db->SELECT('add_req_id, add_requirement, isactive, fk_pd_id'); $this->db->FROM(PDADDTIONALREQUIREMENTS); $this->db->WHERE('isactive',1); $this->db->WHERE('fk_pd_id',$pdid); return $this->db->GET()->result_array(); } public function getDocsToBeCollected($pdid) { $this->db->SELECT('pd_doc_to_be_collect_id, doc_name, isactive, fk_pd_id'); $this->db->FROM(PDDOCSTOBECOLLECTED); $this->db->WHERE('isactive',1); $this->db->WHERE('fk_pd_id',$pdid); return $this->db->GET()->result_array(); } public function getVendorFormStatus($pdid,$pd_master_details = array()) { $res = $this->getVendorFormsWithStatus($pdid); if(count($res)) { //echo 'exist'; return $res; } else//18,5,13,11,19,20 { //echo 'insert'; if(count($pd_master_details)) { $f_arr = array(); if($pd_master_details[0]['customer_segment_abbr'] == 'SE-DI' || $pd_master_details[0]['customer_segment_abbr'] == 'SE-AI') { $f_arr = array(18,5,13,19,20,24,22,11); } else if($pd_master_details[0]['customer_segment_abbr'] == 'SAL') { $f_arr = array(18,5,20,24,12); } foreach ($f_arr as $key => $value) { $this->saveRecords(array('fk_pd_id' => $pdid,'fk_form_id' => $value),VENDORFORMSTATUS); } } return $this->getVendorFormsWithStatus($pdid); } } function getVendorFormsWithStatus($pdid) { $this->db->SELECT('fk_form_id, fk_pd_id, form_status'); $this->db->FROM(VENDORFORMSTATUS); $this->db->WHERE('fk_pd_id',$pdid); return $this->db->GET()->result_array(); } public function getTemplateForPD($pdid,$client,$random_string,$api = 'WEB') { $template_id = ""; //Get PD Master Details including Template id @param $pd_id $pd_master_detials = $this->getPDMasterDetails($pdid,$random_string); $pd_additional_requirements = $this->getPDAdditionalRequirements($pdid); $docs_to_be_collected = $this->getDocsToBeCollected($pdid); $over_all_photocount = $this->PD_Model->selectCustomRecords(array('*'),array('fk_pd_id' => $pdid,'isactive' => 1),PDDOCUMENTS); //echo count($docs_to_be_collected);die(); $pd_applicants_detials = $this->getApplicantsDetails($pdid); //print_r($pd_master_detials);die(); if(count($pd_master_detials)){ $template_id = $pd_master_detials[0]['fk_pd_template_id']; } $this->db->SELECT('TEMPLATEFORMS.form_id,PDFORMS.pd_form_order,PDFORMS.pd_form_level_order,PDFORMS.pd_form_name as form_name'); $this->db->FROM(TEMPLATEFORMS.' as TEMPLATEFORMS'); $this->db->JOIN(PDFORMS.' as PDFORMS','TEMPLATEFORMS.form_id = PDFORMS.pd_form_id'); $this->db->WHERE('TEMPLATEFORMS.fk_template_id',$template_id); $this->db->WHERE('TEMPLATEFORMS.isactive',1); // if( !(count($docs_to_be_collected) || count($pd_additional_requirements)) ) // { // $this->db->WHERE('TEMPLATEFORMS.form_id != ',24); //credit managers specific queries form // } if($pd_master_detials[0]['fk_pd_type'] == 3) { $this->db->WHERE('TEMPLATEFORMS.form_id != ',19); } $this->db->ORDER_BY('PDFORMS.pd_form_order'); $template_forms = $this->db->GET()->result_array(); // print_r($template_forms);die(); $level_one_status = 0; $level_one_total = 0; $level_two_status = 0; $level_two_total = 0; if($pd_master_detials[0]['is_child'] == 0) { //echo "parent"; foreach($template_forms as $template_key => $value) { $this->db->SELECT('count(*) as count'); $this->db->FROM(PDFORMDETAILSJSON.' as PDFORMDETAILSJSON'); $this->db->WHERE('PDFORMDETAILSJSON.fk_pd_id',$pdid); $this->db->WHERE('PDFORMDETAILSJSON.fk_form_id',$value['form_id']); $this->db->WHERE('PDFORMDETAILSJSON.isactive',1); $template_forms_count = 0; $template_forms_count = $this->db->GET()->result_array(); //if($value['form_id'] == 4){print_r($template_forms_count);} if(count($template_forms_count) && $template_forms_count[0]['count'] != 0) { $template_forms[$template_key]['isAnswered'] = true; if($value['pd_form_level_order'] == 1){$level_one_status++; $level_one_total++;} else if($value['pd_form_level_order'] == 2){$level_two_status++; $level_two_total++;} } else { $template_forms[$template_key]['isAnswered'] = false; if($value['pd_form_level_order'] == 1){ $level_one_total++;} else if($value['pd_form_level_order'] == 2){$level_two_total++;} } //make photo section always answerable true if($value['form_id'] == 26) { $template_forms[$template_key]['isAnswered'] = true; } if($value['pd_form_level_order'] == 1) { $template_forms[$template_key]['isAnswerable'] = true; } else if($value['pd_form_level_order'] == 2) { if($level_one_status != $level_one_total) { $template_forms[$template_key]['isAnswerable'] = false; } else { $template_forms[$template_key]['isAnswerable'] = true; } } else if($value['pd_form_level_order'] == 3) { if($level_two_status != $level_two_total) { $template_forms[$template_key]['isAnswerable'] = false; } else { $template_forms[$template_key]['isAnswerable'] = true; } } } } else // FOr addtional PD { //echo "child"; $parent_forms = $this->config->item('parent_forms'); foreach($template_forms as $template_key => $value) { $is_answered = 0; $this->db->SELECT('count(*) as count'); $this->db->FROM(PDFORMDETAILSJSON.' as PDFORMDETAILSJSON'); $this->db->WHERE('PDFORMDETAILSJSON.fk_pd_id',$pdid); $this->db->WHERE('PDFORMDETAILSJSON.fk_form_id',$value['form_id']); $this->db->WHERE('PDFORMDETAILSJSON.isactive',1); $template_forms_count = 0; $template_forms_count = $this->db->GET()->result_array(); //if($value['form_id'] == 19){ print_r($template_forms_count); }//die(); if(count($template_forms_count) && $template_forms_count[0]['count'] != 0) { //echo $value['form_id']; $is_answered = 1; $template_forms[$template_key]['isAnswered'] = true; if($value['pd_form_level_order'] == 1){ $level_one_status++; $level_one_total++;} else if($value['pd_form_level_order'] == 2){$level_two_status++; $level_two_total++;} } else { $template_forms[$template_key]['isAnswered'] = false; if($value['pd_form_level_order'] == 1){ $level_one_total++;} else if($value['pd_form_level_order'] == 2){$level_two_total++;} } if($value['pd_form_level_order'] == 1) { $template_forms[$template_key]['isAnswerable'] = true; } else if($value['pd_form_level_order'] == 2) { if($level_one_status != $level_one_total) { $template_forms[$template_key]['isAnswerable'] = false; } else { $template_forms[$template_key]['isAnswerable'] = true; } } else if($value['pd_form_level_order'] == 3) { if($level_two_status != $level_two_total) { $template_forms[$template_key]['isAnswerable'] = false; } else { $template_forms[$template_key]['isAnswerable'] = true; } } if( array_search($value['form_id'],$parent_forms) ) { $template_forms[$template_key]['isAnswered'] = true; $template_forms[$template_key]['isAnswerable'] = true; } else { if($is_answered == 0) { //echo $value['form_id']; $template_forms[$template_key]['isAnswered'] = false; $template_forms[$template_key]['isAnswerable'] = true; } else { //$template_forms[$template_key]['isAnswered'] = false; $template_forms[$template_key]['isAnswerable'] = true; } } } } //FOr smart PD Purpose Filter PD forms if($pd_master_detials[0]['fk_pd_type'] == 2 && $client == 1) { //$temp_array = array(3,5,10,13); foreach($template_forms as $key => $form) { if($form['form_id'] != 3 && $form['form_id'] != 5 && $form['form_id'] != 10 && $form['form_id'] != 13) { unset($template_forms[$key]) ; } } } //this one get sal case custom check - remove all forms except gen,add, employee $sal_check = $this->selectCustomRecords(array('*'),array('fk_pd_id' => $pdid),XTRA_CHECK); $result_data['salary_check'] = count($sal_check) ? $sal_check[0] : 1; $sal_flag = is_array($result_data['salary_check']) ? $result_data['salary_check']['flag'] : $result_data['salary_check']; //echo $pd_master_detials[0]['customer_segment_abbr'].$api.$sal_flag;die(); if($pd_master_detials[0]['customer_segment_abbr'] == 'SAL' && $api == 'MOB' && $sal_flag == 1) { foreach($template_forms as $key => $form) { if($form['form_id'] != 18 && $form['form_id'] != 5 && $form['form_id'] != 12) { unset($template_forms[$key]) ; } else { $template_forms[ $key ]['isAnswerable'] = true; } } } //change loan form name to facility form name if lender id cFPL // print_r($pd_master_detials);die(); if($pd_master_detials[0]['lender_short_name'] == 'CFPL') { foreach ($template_forms as $k => $val) { if($val['form_id'] == 10) { $template_forms[$k]['form_name'] = 'Facility & Anchor Details Section'; break; } } } // print_r($template_forms);die(); $result_data['question_answers'] = array();; $result_data['counts'] = array(); if(count($pd_master_detials)) { $result_data['pdmaster_details'] = $pd_master_detials[0]; } $result_data['pdapplicants_detials'] = $pd_applicants_detials; if($pd_master_detials[0]['fk_pd_type'] == 2 && !$pd_master_detials[0]['is_vendor_visit_disabled']) { $result_data['vendor_form_status'] = $this->getVendorFormStatus($pdid); } // $result_data['template_forms'] = json_decode(json_encode($template_forms), true);//$template_forms; $result_data['template_forms'] = array_values($template_forms); return $result_data; } public function getAnswersForPD($question_id,$pd_id,$template_id,$category_id) { $overalldata =array(); $pd_master_detials = $this->getPDMasterDetails($pd_id); $this->db->SELECT('QUESTIONANSWERS.question_answer_id,QUESTIONANSWERS.answer,PDANSWER.pd_answer,TEMPLATEANSWERWEIGHTAGE.template_answer_weightage,PDANSWER.pd_detail_answer_id,PDANSWER.isactive,PDANSWER.fk_pd_detail_id'); $this->db->FROM(TEMPLATEANSWERWEIGHTAGE.' as TEMPLATEANSWERWEIGHTAGE'); $this->db->JOIN(TEMPLATEQUESTION." as TEMPLATEQUESTION","TEMPLATEANSWERWEIGHTAGE.fk_template_question_id = TEMPLATEQUESTION.template_question_id AND TEMPLATEQUESTION.fk_template_question_category_id = $category_id AND TEMPLATEQUESTION.fk_template_id = $template_id AND TEMPLATEQUESTION.fk_question_id = $question_id"); $this->db->JOIN(QUESTIONANSWERS.' as QUESTIONANSWERS','TEMPLATEANSWERWEIGHTAGE.fk_question_answer_id = QUESTIONANSWERS.question_answer_id'); $this->db->JOIN(PDANSWER.' as PDANSWER',"QUESTIONANSWERS.question_answer_id = PDANSWER.pd_answer_id AND TEMPLATEANSWERWEIGHTAGE.fk_question_answer_id = PDANSWER.pd_answer_id AND PDANSWER.fk_pd_id = $pd_id AND PDANSWER.isactive = 1",'LEFT'); $this->db->ORDER_BY('QUESTIONANSWERS.question_answer_id'); // $this->db->WHERE('QUESTIONANSWERS.fk_question_id',$question['question_id']); // $this->db->WHERE('TEMPLATEANSWERWEIGHTAGE.fk_template_question_id',$question_id); //$this->db->WHERE('TEMPLATEANSWERWEIGHTAGE.fk_question_category_id',$category_id); //$this->db->WHERE('TEMPLATEANSWERWEIGHTAGE.fk_template_id',$template_id); // $this->db->WHERE('PDDETAIL.fk_pd_id',$pdid); $answers = $this->db->GET()->result_array(); $overalldata['answers'] = $answers; //Get PD Detail ID From PD DETAILS table using pd_id and question_id $fields = array('pd_detail_id','question_remark','fk_question_id as question_id','pd_question'); $where_condition_array = array('fk_pd_id'=>$pd_id,'fk_question_id'=>$question_id); $pd_detail = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDDETAIL); // print_r($pd_detail);die(); $overalldata['question_remark'] = ""; $overalldata['pd_detail_id'] = ""; $overalldata['question_id'] = ""; $overalldata['pd_question'] = ""; $overalldata['images'] = array();; if(count($pd_detail)) { $overalldata['question_remark'] = $pd_detail[0]['question_remark']; $overalldata['pd_detail_id'] = $pd_detail[0]['pd_detail_id']; $overalldata['question_id'] = $pd_detail[0]['question_id']; $overalldata['pd_question'] = $pd_detail[0]['pd_question']; $fields = array('pd_document_title', 'pd_document_name'); $where_condition_array = array('fk_pd_id'=>$pd_id,'fk_pd_detail_id'=> $pd_detail[0]['pd_detail_id']); $pd_docs = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDDOCUMENTS); // print_r($pd_docs);die(); if(count($pd_docs)) { $bucket_name = LENDER_BUCKET_NAME_PREFIX.$pd_master_detials[0]['fk_lender_id']; foreach($pd_docs as $doc_key => $doc) { if($doc['pd_document_name'] != "" || $doc['pd_document_name'] != null) { $profilepics3path = 'pd'.$pd_master_detials[0]['pd_id'].'/'.$doc['pd_document_name']; $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$profilepics3path,'+30 minutes'); $pd_docs[$doc_key]['pd_document_name'] = $singed_uri; } } } $overalldata['images'] = $pd_docs; } $overalldata['counts'] = $this->getOverallAnsweredCount($pd_id); return $overalldata; } /** * Check OTP PDTRIGGER TABLE * param OTP AND pd_id *sriram */ public function checkotp($pddata) { $this->db->select('OTP'); $this->db->where('pd_id',$pddata['pd_id']); $result = $this->db->get(PDTRIGGER.' as PDTRIGGER')->first_row(); //print_r($result);die; if($result !='') { if($result->OTP == $pddata['OTP']) { $fields = ('is_otp_done'); $where_condition_array = array('pd_id' => $pddata['pd_id']); $this->PD_Model->updateRecords($fields,PDTRIGGER,$where_condition_array); $result = true; }else { $result = false; } } return $result; } public function getOverallAnsweredCount($pdid) { $template_id = ""; $categories = ""; $overall_answered_count = 0; $overall_question_count = 0; $temp['overall_answered_count'] = 0; $temp['overall_question_count'] = 0; //Get PD Master Details including Template id @param $pd_id $pd_master_detials = $this->getPDMasterDetails($pdid); $pd_applicants_detials = $this->getApplicantsDetails($pdid); //sprint_r($pd_master_detials); $template_id = $pd_master_detials[0]['fk_pd_template_id']; if($template_id != "" || $template_id != null) { //Get Category, QUestions and Answers @param $template_id $this->db->SELECT('QUESTIONCATEGORY.category_name,TEMPLATECATEGORYWEIGHTAGE.template_category_weightage_id, TEMPLATECATEGORYWEIGHTAGE.fk_question_category_id, TEMPLATECATEGORYWEIGHTAGE.fk_template_id, TEMPLATECATEGORYWEIGHTAGE.weightage, DATE_FORMAT(TEMPLATECATEGORYWEIGHTAGE.createdon,"%d/%m/%Y") as createdon, TEMPLATECATEGORYWEIGHTAGE.fk_createdby, DATE_FORMAT(TEMPLATECATEGORYWEIGHTAGE.updatedon, "%d/%m/%Y") as updatedon, TEMPLATECATEGORYWEIGHTAGE.isactive, TEMPLATECATEGORYWEIGHTAGE.fk_updatedby'); $this->db->FROM(TEMPLATECATEGORYWEIGHTAGE .' as TEMPLATECATEGORYWEIGHTAGE'); $this->db->JOIN(QUESTIONCATEGORY.' as QUESTIONCATEGORY','TEMPLATECATEGORYWEIGHTAGE.fk_question_category_id = QUESTIONCATEGORY.question_category_id'); // $this->db->JOIN(USERPROFILE.' as USERPROFILE','TEMPLATECATEGORYWEIGHTAGE.fk_createdby = USERPROFILE.userid','LEFT'); // $this->db->JOIN(USERPROFILE.' as USERPROFILE1','TEMPLATECATEGORYWEIGHTAGE.fk_updatedby = USERPROFILE1.userid','LEFT'); $this->db->WHERE('TEMPLATECATEGORYWEIGHTAGE.fk_template_id',$template_id); $categories = $this->db->GET()->result_array(); //print_r( $categories); if(count($categories)) { /* DATE_FORMAT(TEMPLATEQUESTION.createdon,"%d/%m/%Y") as createdon, TEMPLATEQUESTION.fk_createdby, DATE_FORMAT(TEMPLATEQUESTION.updatedon,"%d/%m/%Y") as updatedon, TEMPLATEQUESTION.fk_updatedby,concat(USERPROFILE.first_name," ",USERPROFILE.last_name) as createdby,concat(USERPROFILE1.first_name," ",USERPROFILE1.last_name) as updatedby */ foreach($categories as $category_key => $category) { $this->db->SELECT('QUESTIONS.question_id,QUESTIONS.question,TEMPLATEQUESTION.template_question_id, TEMPLATEQUESTION.fk_template_id, TEMPLATEQUESTION.fk_question_id, TEMPLATEQUESTION.question_weightage, TEMPLATEQUESTION.question_answerable_by,TEMPLATEQUESTION.fk_template_question_category_id, TEMPLATEQUESTION.isactive,QUESTIONS.fk_question_answertype,QUESTIONANSWERTYPE.answer_type_name,PDDETAIL.pd_detail_id'); //$this->db->FROM(TEMPLATEQUESTION.' as TEMPLATEQUESTION'); $this->db->FROM(TEMPLATEQUESTION.' as TEMPLATEQUESTION'); $this->db->JOIN(QUESTIONS.' as QUESTIONS','TEMPLATEQUESTION.fk_question_id = QUESTIONS.question_id'); $this->db->JOIN(QUESTIONANSWERTYPE.' as QUESTIONANSWERTYPE','QUESTIONS.fk_question_answertype = QUESTIONANSWERTYPE.question_answer_type_id'); $this->db->JOIN(PDDETAIL.' as PDDETAIL',"QUESTIONS.question_id = PDDETAIL.fk_question_id AND PDDETAIL.fk_pd_id = $pdid",'LEFT'); // $this->db->JOIN(USERPROFILE.' as USERPROFILE','TEMPLATEQUESTION.fk_createdby = USERPROFILE.userid','LEFT'); // $this->db->JOIN(USERPROFILE.' as USERPROFILE1','TEMPLATEQUESTION.fk_updatedby = USERPROFILE1.userid','LEFT'); $this->db->WHERE('TEMPLATEQUESTION.fk_template_question_category_id',$category['fk_question_category_id']); $this->db->WHERE('TEMPLATEQUESTION.fk_template_id', $template_id); //$this->db->WHERE('TEMPLATEQUESTION.fk_template_id',$template_id); $questions = $this->db->GET()->result_array(); $answerd_count = 0; $pd_docs = array(); foreach($questions as $t_key => $question) { if($question['pd_detail_id'] != "" || $question['pd_detail_id'] != null){ $answerd_count++; // Get Alredy stored Images $fields = array('pd_document_title', 'pd_document_name'); $where_condition_array = array('fk_pd_id'=>$pdid,'fk_pd_detail_id'=> $question['pd_detail_id']); $pd_docs = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDDOCUMENTS); // print_r($pd_docs);die(); if(count($pd_docs)) { $bucket_name = LENDER_BUCKET_NAME_PREFIX.$pd_master_detials[0]['fk_lender_id']; foreach($pd_docs as $doc_key => $doc) { if($doc['pd_document_name'] != "" || $doc['pd_document_name'] != null) { $profilepics3path = 'pd'.$pd_master_detials[0]['pd_id'].'/'.$doc['pd_document_name']; $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$profilepics3path,'+30 minutes'); $pd_docs[$doc_key]['pd_document_name'] = $singed_uri; } } } $questions[$t_key]['images'] = $pd_docs; } } //print_r($questions);die(); //$categories[$category_key]['questions_count'] = count($questions); //$categories[$category_key]['answerd_count'] = $answerd_count; $temp['overall_answered_count'] += count($questions); $temp['overall_question_count'] += $answerd_count; } } } return $temp; // return $categories; } public function getPDFormDetails($pd_id,$pd_form_id = "") { $this->db->SELECT('PDFORMDETAILS.fk_pd_id,PDFORMDETAILS.fk_form_id,PDFORMDETAILS.iter_column_name,PDFORMDETAILS.iter_sub_column_name,PDFORMDETAILS.iteration, PDFORMDETAILS.column_name, PDFORMDETAILS.column_id, PDFORMDETAILS.column_value, PDFORMDETAILS.createdon, PDFORMDETAILS.fk_createdby,USERPROFILE.first_name,USERPROFILE.last_name'); $this->db->FROM(PDFORMDETAILS.' as PDFORMDETAILS'); $this->db->JOIN(USERPROFILE.' as USERPROFILE','PDFORMDETAILS.fk_createdby = USERPROFILE.userid','LEFT'); $this->db->WHERE('PDFORMDETAILS.fk_pd_id',$pd_id); if($pd_form_id != "") { $this->db->WHERE('PDFORMDETAILS.fk_form_id',$pd_form_id); } $this->db->WHERE('PDFORMDETAILS.isactive',1); $form_details = $this->db->GET()->result_array(); return $form_details; } public function getPDFormDetailsWithScoring($pd_id,$pd_form_id = "") { //PDFORMDETAILS.createdon, PDFORMDETAILS.fk_createdby,USERPROFILE.first_name,USERPROFILE.last_name // echo $pd_form_id; $pd_master_detials = $this->getPDMasterDetails($pd_id); $this->db->SELECT('PDFORMDETAILS.fk_pd_id,PDFORMDETAILS.fk_form_id,PDFORMDETAILS.iter_column_name,PDFORMDETAILS.iter_sub_column_name,PDFORMDETAILS.iteration, PDFORMDETAILS.column_name, PDFORMDETAILS.column_id, PDFORMDETAILS.column_value,TEMPLATECATEGORYWEIGHTAGE.weightage as category_weightage,TEMPLATECATEGORYWEIGHTAGE.fk_question_category_id,QUESTIONKEYMAPPING.fk_category_id,QUESTIONCATEGORY.category_name,SCORECARDQUESTIONS.score_question_id,SCORECARDQUESTIONS.weightage as question_weightage,SCORECARDQUESTIONS.calc_type,SCORECARDANSWERS.score'); $this->db->FROM(PDFORMDETAILS.' as PDFORMDETAILS'); $this->db->JOIN(TEMPLATECATEGORYWEIGHTAGE.' as TEMPLATECATEGORYWEIGHTAGE','TEMPLATECATEGORYWEIGHTAGE.fk_template_id ='.$pd_master_detials[0]['fk_pd_template_id']); $this->db->JOIN(QUESTIONKEYMAPPING.' as QUESTIONKEYMAPPING','TEMPLATECATEGORYWEIGHTAGE.fk_question_category_id = QUESTIONKEYMAPPING.fk_category_id AND QUESTIONKEYMAPPING.fk_form_id = PDFORMDETAILS.fk_form_id AND TEMPLATECATEGORYWEIGHTAGE.isactive = 1 AND QUESTIONKEYMAPPING.isactive = 1 AND QUESTIONKEYMAPPING.key = PDFORMDETAILS.column_name','LEFT'); $this->db->JOIN(QUESTIONCATEGORY.' as QUESTIONCATEGORY','QUESTIONKEYMAPPING.fk_category_id = QUESTIONCATEGORY.question_category_id AND TEMPLATECATEGORYWEIGHTAGE.fk_question_category_id = QUESTIONCATEGORY.question_category_id','LEFT'); $this->db->JOIN(SCORECARDQUESTIONS.' as SCORECARDQUESTIONS','PDFORMDETAILS.column_name = SCORECARDQUESTIONS.fk_key AND PDFORMDETAILS.fk_form_id = SCORECARDQUESTIONS.fk_form_id AND SCORECARDQUESTIONS.fk_template_id = '.$pd_master_detials[0]['fk_pd_template_id'].' AND SCORECARDQUESTIONS.isactive = 1','left'); $this->db->JOIN(SCORECARDANSWERS.' as SCORECARDANSWERS','PDFORMDETAILS.column_value = SCORECARDANSWERS.answer AND SCORECARDQUESTIONS.fk_template_id = '.$pd_master_detials[0]['fk_pd_template_id'].' AND SCORECARDQUESTIONS.score_question_id = SCORECARDANSWERS.fk_score_question_id AND SCORECARDQUESTIONS.isactive = 1 AND SCORECARDANSWERS.isactive = 1','left'); //$this->db->JOIN(USERPROFILE.' as USERPROFILE','PDFORMDETAILS.fk_createdby = USERPROFILE.userid','LEFT'); $this->db->WHERE('PDFORMDETAILS.fk_pd_id',$pd_id); if($pd_form_id != "") { $this->db->WHERE('PDFORMDETAILS.fk_form_id',$pd_form_id); } $this->db->WHERE('PDFORMDETAILS.isactive',1); $this->db->ORDER_BY('PDFORMDETAILS.pd_form_detail_id'); $form_details = $this->db->GET()->result_array(); if(count($form_details)) { foreach($form_details as $form_details_key => $form_detail) { // if($form_detail['score_question_id'] != null || $form_detail['score_question_id'] != '') // { $max_score = $this->db->SELECT('max(score) as max_score')->FROM(SCORECARDANSWERS)->WHERE('fk_score_question_id',$form_detail['score_question_id'])->GET()->result_array(); $form_details[$form_details_key]['max_score'] = $max_score[0]['max_score']; if($form_detail['category_weightage'] != "" && $form_detail['question_weightage'] != "" && $form_detail['score'] != "" && $max_score[0]['max_score'] != "") { $form_details[$form_details_key]['actual_score'] = (($form_detail['category_weightage']/100) * ($form_detail['question_weightage']/100) * $max_score[0]['max_score']); $form_details[$form_details_key]['exact_score'] = (($form_detail['category_weightage']/100) * ($form_detail['question_weightage']/100) * $form_detail['score']); } else { $form_details[$form_details_key]['actual_score'] = null; $form_details[$form_details_key]['exact_score'] = null; } // } } } return $form_details; } public function getAssessedIncome($pdid,$company_id = null) { /********************************* Assessd Income Sections *****************************************/ $assessed_income = array(); //echo "getAssessedIncome" ; //get sales_declared_by_customer details $fields = array('sdc_id','sales_declared_by_customer','margin_per','margin_value','comments'); $where_condition_array = array('fk_pd_id'=>$pdid,'isactive'=>1); $where_condition_array['company_id'] = $company_id ? $company_id : null; $sales_declared_by_customer = $this->selectCustomRecords($fields,$where_condition_array,SALESDECLAREDBYCUSTOMER); //get sales_purchased_by_customer details $fields = array('pdc_id','purchase_declared_by_customer','comments'); $where_condition_array = array('fk_pd_id'=>$pdid,'isactive'=>1); $where_condition_array['company_id'] = $company_id ? $company_id : null; $purchase_declared_by_customer = $this->selectCustomRecords($fields,$where_condition_array,PURCHASEDECLAREDBYCUSTOMER); //get Gross Profit calculatio Mode details $fields = array('calc_type_id','mode','margin','purchase_type','is_completed'); $where_condition_array = array('fk_pd_id'=>$pdid,'company_id'=>$company_id); $gross_profit_calculation_type = $this->selectCustomRecords($fields,$where_condition_array,PDASSESSEDINCOMEESTIMATIONOFGROSSPROFITTYPE); //print_r($gross_profit_calculation_type);die(); //get sales_calculated_by_itemwise details $fields = array('sci_id','sales_item','sales_qty','UOM.name as uom_name','fk_uom_id','FREQUENCY.name as frequency_name','rate_per_unit','fk_frequency_id','annual_sale_value','margin_final_value','margin_per','margin_per_uom','uom_other','comments','sales_type','other_sales_item'); $table = SALESCALCULATEDBYITEMWISE.' as SALESCALCULATEDBYITEMWISE'; $where_condition_array = array('fk_pd_id'=>$pdid,'SALESCALCULATEDBYITEMWISE.isactive'=>1); $where_condition_array['company_id'] = $company_id ? $company_id : null; //echo "where_condition_array"; //print_r($where_condition_array );die(); $joins = array( array('table'=>FREQUENCY.' as FREQUENCY','condition'=>'SALESCALCULATEDBYITEMWISE.fk_frequency_id = FREQUENCY.frequency_id','jointype'=>'LEFT'), array('table'=>UOM.' as UOM','condition'=>'SALESCALCULATEDBYITEMWISE.fk_uom_id = UOM.uom_id','jointype'=>'LEFT')); $sales_calculated_by_itemwise = $this->getJoinRecords($fields,$table,$joins,$where_condition_array); //print_r($sales_calculated_by_itemwise); if(count($sales_calculated_by_itemwise)) { foreach($sales_calculated_by_itemwise as $key => $item) { if($item['sales_type'] == 3) { //echo 'THREE'; $this->db->SELECT('month(sales_date) as month,year(sales_date) as year'); $this->db->FROM(SALESITEMMONTHWISECHILD.' as SALESITEMMONTHWISECHILD'); $this->db->WHERE('SALESITEMMONTHWISECHILD.fk_sci_id',$item['sci_id']); $this->db->WHERE('SALESITEMMONTHWISECHILD.isactive',1); $this->db->GROUP_BY('month(SALESITEMMONTHWISECHILD.sales_date)'); $sales_items_by_month = $this->db->GET()->result_array(); if(count($sales_items_by_month)) { $sales_items_by_months = array(); foreach($sales_items_by_month as $month_key => $month) { $this->db->SELECT('simc_id,sales_date,sales_value,fk_frequency_id,frequency_value,FREQUENCY.name as frequency_name,FREQUENCY.mutiple_factor'); $this->db->FROM(SALESITEMMONTHWISECHILD.' as SALESITEMMONTHWISECHILD'); $this->db->WHERE('SALESITEMMONTHWISECHILD.fk_sci_id',$item['sci_id']); $this->db->JOIN(FREQUENCY.' as FREQUENCY','SALESITEMMONTHWISECHILD.fk_frequency_id = FREQUENCY.frequency_id','LEFT'); $this->db->WHERE('month(SALESITEMMONTHWISECHILD.sales_date)',$month['month']); //$this->db->WHERE('year(SALESITEMMONTHWISECHILD.sales_date)',$month['year']); $this->db->WHERE('SALESITEMMONTHWISECHILD.isactive',1); //$this->db->GROUP_BY('month(SALESITEMMONTHWISECHILD.sales_date)'); $sales_items_by_month_child = $this->db->GET()->result_array(); //print_r($sales_items_by_month_child); if(count($sales_items_by_month_child)) { foreach($sales_items_by_month_child as $t_key => $child_item) { $sales_items_by_month_child[$t_key]['row_index'] = $t_key + 1; } } $sales_items_by_months[date("M-Y", strtotime($month['year'].'-'.$month['month']))] = $sales_items_by_month_child; } $sales_calculated_by_itemwise[$key]['items'] = $sales_items_by_months; } }//print_r($sales_items_by_months); } } // print_r($sales_calculated_by_itemwise); // die(); //print_r($this->db->last_query()); //get sales_items_by_monthwise details // $sales_items_by_months = array(); // $this->db->SELECT('sim_id,sales_item,margin_value,margin_per,comments,sales_type,other_sales_item'); // $this->db->FROM(SALESITEMMONTHWISE.' as SALESITEMMONTHWISE'); // $this->db->WHERE('SALESITEMMONTHWISE.fk_pd_id',$pdid); // $this->db->WHERE('SALESITEMMONTHWISE.isactive',1); // if($company_id != null) // { // $this->db->WHERE('SALESITEMMONTHWISE.company_id',$company_id); // } // $sales_items_by_monthwise = $this->db->GET()->result_array(); // //print_r($sales_items_by_monthwise); // if(count($sales_items_by_monthwise)) // { // foreach($sales_items_by_monthwise as $key => $item) // { // $this->db->SELECT('month(sales_date) as month,year(sales_date) as year'); // $this->db->FROM(SALESITEMMONTHWISECHILD.' as SALESITEMMONTHWISECHILD'); // $this->db->WHERE('SALESITEMMONTHWISECHILD.fk_sim_id',$item['sim_id']); // $this->db->WHERE('SALESITEMMONTHWISECHILD.isactive',1); // $this->db->GROUP_BY('month(SALESITEMMONTHWISECHILD.sales_date)'); // $sales_items_by_month = $this->db->GET()->result_array(); // //print_r($this->db->last_query()); // //print_r($sales_items_by_month); // if(count($sales_items_by_month)) // { // $sales_items_by_months = array(); // foreach($sales_items_by_month as $month_key => $month) // { // $this->db->SELECT('simc_id,sales_date,sales_value,fk_frequency_id,frequency_value,FREQUENCY.name as frequency_name,FREQUENCY.mutiple_factor'); // $this->db->FROM(SALESITEMMONTHWISECHILD.' as SALESITEMMONTHWISECHILD'); // $this->db->WHERE('SALESITEMMONTHWISECHILD.fk_sim_id',$item['sim_id']); // $this->db->JOIN(FREQUENCY.' as FREQUENCY','SALESITEMMONTHWISECHILD.fk_frequency_id = FREQUENCY.frequency_id','LEFT'); // $this->db->WHERE('month(SALESITEMMONTHWISECHILD.sales_date)',$month['month']); // //$this->db->WHERE('year(SALESITEMMONTHWISECHILD.sales_date)',$month['year']); // $this->db->WHERE('SALESITEMMONTHWISECHILD.isactive',1); // //$this->db->GROUP_BY('month(SALESITEMMONTHWISECHILD.sales_date)'); // $sales_items_by_month_child = $this->db->GET()->result_array(); // //print_r($sales_items_by_month_child); // if(count($sales_items_by_month_child)) // { // foreach($sales_items_by_month_child as $t_key => $child_item) // { // $sales_items_by_month_child[$t_key]['row_index'] = $t_key + 1; // } // } // $sales_items_by_months[date("M-Y", strtotime($month['year'].'-'.$month['month']))] = $sales_items_by_month_child; // } // $sales_items_by_monthwise[$key]['items'] = $sales_items_by_months; // } // //print_r($sales_items_by_months); // } // } //*************Get purchase_details $fields = array('purchase_id','purchase_item','purchase_qty','UOM.name as uom_name','fk_uom_id','FREQUENCY.name as frequency_name','rate_per_unit','fk_frequency_id','annual_purchase_value','uom_other','comments','purchase_type','other_purchase_item'); $table = PDPURCHASEDETAILS.' as PDPURCHASEDETAILS'; $where_condition_array = array('fk_pd_id'=>$pdid,'PDPURCHASEDETAILS.isactive'=>1); $where_condition_array['company_id'] = $company_id ? $company_id : null; $joins = array( array('table'=>FREQUENCY.' as FREQUENCY','condition'=>'PDPURCHASEDETAILS.fk_frequency_id = FREQUENCY.frequency_id','jointype'=>'LEFT'), array('table'=>UOM.' as UOM','condition'=>'PDPURCHASEDETAILS.fk_uom_id = UOM.uom_id','jointype'=>'LEFT')); $purchase_details = $this->getJoinRecords($fields,$table,$joins,$where_condition_array); if(count($purchase_details)) { foreach($purchase_details as $purchase_billwise_parent_key => $billwise) { $this->db->SELECT('month(purchase_date) as month,year(purchase_date) as year'); $this->db->FROM(PDPURCHASEBILLWISECHILD.' as PDPURCHASEBILLWISECHILD'); $this->db->WHERE('PDPURCHASEBILLWISECHILD.fk_purchase_id',$billwise['purchase_id']); $this->db->WHERE('PDPURCHASEBILLWISECHILD.isactive',1); $this->db->GROUP_BY('month(PDPURCHASEBILLWISECHILD.purchase_date)'); $purchase_billwise_child_group = $this->db->GET()->result_array(); //print_r($purchase_billwise_child_group); if(count($purchase_billwise_child_group)) { $purchase_billwise_data = array(); foreach($purchase_billwise_child_group as $billwise_child_key => $child) { $this->db->SELECT('pbwc_id,purchase_date,purchase_value,'); $this->db->FROM(PDPURCHASEBILLWISECHILD.' as PDPURCHASEBILLWISECHILD'); $this->db->WHERE('PDPURCHASEBILLWISECHILD.fk_purchase_id',$billwise['purchase_id']); $this->db->WHERE('month(PDPURCHASEBILLWISECHILD.purchase_date)',$child['month']); $this->db->WHERE('PDPURCHASEBILLWISECHILD.isactive',1); //$this->db->GROUP_BY('month(SALESITEMMONTHWISECHILD.sales_date)'); $purchase_billwise_child = $this->db->GET()->result_array(); if(count($purchase_billwise_child)) { foreach($purchase_billwise_child as $t_key => $child_item) { $purchase_billwise_child[$t_key]['row_index'] = $t_key + 1; } } $purchase_billwise_data[$billwise_child_key][date("M-Y", strtotime($child['year'].'-'.$child['month']))] = $purchase_billwise_child; } $purchase_details[$purchase_billwise_parent_key]['items'] = $purchase_billwise_data; } //print_r($sales_items_by_months); } } //get purchase bill details // $purchase_billwise_parent = array(); // $this->db->SELECT('pbw_id,purchase_item,annual_purchase_value,comments,other_purchase_item'); // $this->db->FROM(PDPURCHASEBILLWISE.' as PDPURCHASEBILLWISE'); // $this->db->WHERE('PDPURCHASEBILLWISE.fk_pd_id',$pdid); // $this->db->WHERE('PDPURCHASEBILLWISE.isactive',1); // if($company_id != null) // { // $this->db->WHERE('PDPURCHASEBILLWISE.company_id',$company_id); // } // $purchase_billwise_parent = $this->db->GET()->result_array(); // //print_r($purchase_billwise_parent); // if(count($purchase_billwise_parent)) // { // foreach($purchase_billwise_parent as $purchase_billwise_parent_key => $billwise) // { // $this->db->SELECT('month(purchase_date) as month,year(purchase_date) as year'); // $this->db->FROM(PDPURCHASEBILLWISECHILD.' as PDPURCHASEBILLWISECHILD'); // $this->db->WHERE('PDPURCHASEBILLWISECHILD.fk_pbw_id',$billwise['pbw_id']); // $this->db->WHERE('PDPURCHASEBILLWISECHILD.isactive',1); // $this->db->GROUP_BY('month(PDPURCHASEBILLWISECHILD.purchase_date)'); // $purchase_billwise_child_group = $this->db->GET()->result_array(); // //print_r($purchase_billwise_child_group); // if(count($purchase_billwise_child_group)) // { // $purchase_billwise_data = array(); // foreach($purchase_billwise_child_group as $billwise_child_key => $child) // { // $this->db->SELECT('pbwc_id,purchase_date,purchase_value,'); // $this->db->FROM(PDPURCHASEBILLWISECHILD.' as PDPURCHASEBILLWISECHILD'); // $this->db->WHERE('PDPURCHASEBILLWISECHILD.fk_pbw_id',$billwise['pbw_id']); // $this->db->WHERE('month(PDPURCHASEBILLWISECHILD.purchase_date)',$child['month']); // $this->db->WHERE('PDPURCHASEBILLWISECHILD.isactive',1); // //$this->db->GROUP_BY('month(SALESITEMMONTHWISECHILD.sales_date)'); // $purchase_billwise_child = $this->db->GET()->result_array(); // if(count($purchase_billwise_child)) // { // foreach($purchase_billwise_child as $t_key => $child_item) // { // $purchase_billwise_child[$t_key]['row_index'] = $t_key + 1; // } // } // $purchase_billwise_data[$billwise_child_key][date("M-Y", strtotime($child['year'].'-'.$child['month']))] = $purchase_billwise_child; // } // $purchase_billwise_parent[$purchase_billwise_parent_key]['items'] = $purchase_billwise_data; // } // //print_r($sales_items_by_months); // } // } //echo "*****************************************"; //print_r($purchase_billwise_parent);die(); //Get business_expenses $fields = array('pd_expense_id','PDBUSINESSEXPENSES.expense_item_id','BUSINESSEXPENSES.expense_item','FREQUENCY.name as frequency_name','fk_frequency_id','expense_value','annual_expenses_value','comments','other_expense_item'); $table = PDBUSINESSEXPENSES.' as PDBUSINESSEXPENSES'; $where_condition_array = array('fk_pd_id'=>$pdid,'PDBUSINESSEXPENSES.isactive'=>1); $where_condition_array['company_id'] = $company_id ? $company_id : null; $joins = array( array('table'=>FREQUENCY.' as FREQUENCY','condition'=>'PDBUSINESSEXPENSES.fk_frequency_id = FREQUENCY.frequency_id','jointype'=>'INNER JOIN'), array('table'=>BUSINESSEXPENSES.' as BUSINESSEXPENSES','condition'=>'PDBUSINESSEXPENSES.expense_item_id = BUSINESSEXPENSES.expense_item_id','jointype'=>'INNER JOIN')); $business_expenses = $this->getJoinRecords($fields,$table,$joins,$where_condition_array); //Get house_hold_expenses $fields = array('household_expense_id','expense_item','FREQUENCY.name as frequency_name','fk_frequency_id','expense_value','annual_expense_value','comments'); $table = PDHOUSEHOLDEXPENSES.' as PDHOUSEHOLDEXPENSES'; $where_condition_array = array('fk_pd_id'=>$pdid,'PDHOUSEHOLDEXPENSES.isactive'=>1); $where_condition_array['company_id'] = $company_id ? $company_id : null; $joins = array( array('table'=>FREQUENCY.' as FREQUENCY','condition'=>'PDHOUSEHOLDEXPENSES.fk_frequency_id = FREQUENCY.frequency_id','jointype'=>'INNER JOIN')); $house_hold_expenses = $this->getJoinRecords($fields,$table,$joins,$where_condition_array); //get Other Business Income details $fields = array('PDBUSINESSINCOME.pd_business_income_id', 'PDBUSINESSINCOME.fk_pd_id', 'PDBUSINESSINCOME.business_income_id', 'PDBUSINESSINCOME.income_value', 'PDBUSINESSINCOME.fk_frequency_id', 'PDBUSINESSINCOME.annual_income_value','PDBUSINESSINCOME.fk_createdby','PDBUSINESSINCOME.other_income_item','PDBUSINESSINCOME.other_frequncy_item','FREQUENCY.name as frequency_name','BUSINESSINCOME.business_income_item','comments'); $table = PDBUSINESSINCOME.' as PDBUSINESSINCOME'; $where_condition_array = array('fk_pd_id'=>$pdid,'PDBUSINESSINCOME.isactive'=>1); $where_condition_array['company_id'] = $company_id ? $company_id : null; $joins = array( array('table'=>FREQUENCY.' as FREQUENCY','condition'=>'PDBUSINESSINCOME.fk_frequency_id = FREQUENCY.frequency_id','jointype'=>'INNER JOIN'), array('table'=>BUSINESSINCOME.' as BUSINESSINCOME','condition'=>'PDBUSINESSINCOME.business_income_id = BUSINESSINCOME.business_income_id','jointype'=>'INNER JOIN')); $other_business_income = $this->getJoinRecords($fields,$table,$joins,$where_condition_array); /*********************************End of Assessd Income Sections *****************************************/ $assessed_income= array('sales_declared_by_customer'=>$sales_declared_by_customer,'sales_calculated_by_itemwise'=>$sales_calculated_by_itemwise,'purchase_details'=>$purchase_details,'purchase_declared_by_customer' => $purchase_declared_by_customer,'business_expenses'=>$business_expenses,'house_hold_expenses'=>$house_hold_expenses,'gross_profit_calculation_type' => $gross_profit_calculation_type,'othre_business_income' => $other_business_income); return $assessed_income; } public function getScorablePDFormDetailsJSON($pdid) { $array = array(1,2,4,5,11,13,18,19,20,21,22,10); $return_data = array(); foreach($array as $key => $value) { $this->db->SELECT('processed_json'); $this->db->FROM(PDFORMDETAILSJSON); $this->db->WHERE('isactive','1'); $this->db->WHERE('fk_pd_id',$pdid); $this->db->WHERE('fk_form_id',$value); $data = $this->db->GET()->result_array(); if(count($data)) { //echo $value; $return_data[$value] = $data; } } return $return_data; } function getScoreCardEnabledStatusByPDID($pdid) { $this->db->SELECT('ENTITY.is_score_card_enabled'); $this->db->FROM(ENTITY.' as ENTITY'); $this->db->JOIN(PDTRIGGER.' as PDTRIGGER','ENTITY.entity_id = PDTRIGGER.fk_lender_id'); $this->db->WHERE('PDTRIGGER.pd_id',$pdid); $res = $this->db->GET()->result_array(); return $res; } public function getScoreableQuestionToDispaly() { $this->db->SELECT('question,key'); $this->db->FROM(QUESTIONKEYMAPPING); $this->db->WHERE('fk_form_id is null'); $data = $this->db->GET()->result_array(); return $data; //$this->PD_Model->selectCustomRecords(array('question,key'),array('fk_form_id' =>'is null'),QUESTIONKEYMAPPING); } public function getAddtionalPDInformations($addressid) { $this->db->SELECT('PDTRIGGER.pd_id, PDTRIGGER.fk_lender_id,PDTRIGGER.sub_entity_id,SUBENTITY.short_name as sub_entity_short_name,ENTITY.full_name as lender_full_name,ENTITY.short_name as lender_short_name, PDTRIGGER.fk_entity_billing_id,ENTITYBILLING.billing_name,PDTRIGGER.lender_applicant_id, DATE_FORMAT(PDTRIGGER.pd_date_of_initiation, "%d/%m/%Y") as pd_date_of_initiation, PDTRIGGER.fk_product_id,PRODUCTS.name as product_name,PRODUCTS.abbr as product_abbr, PDTRIGGER.fk_subproduct_id,SUBPRODUCTS.name as subproduct_name,SUBPRODUCTS.abbr as subproduct_abbr, PDTRIGGER.fk_pd_type,PDTYPE.type_name as pd_type_name, PDTRIGGER.pd_status,PDTRIGGER.pd_specific_clarification, DATE_FORMAT(PDTRIGGER.createdon,"%d/%m/%Y %H:%i %p") as createdon, PDTRIGGER.fk_createdby, DATE_FORMAT(PDTRIGGER.updatedon,"%d/%m/%Y %H:%i %p") as updatedon, PDTRIGGER.fk_updatedby,concat(USERPROFILE.first_name," ",USERPROFILE.last_name) as createdby,concat(USERPROFILE1.first_name," ",USERPROFILE1.last_name) as updatedby, PDTRIGGER.fk_pd_allocation_type,,PDALLOCATIONTYPE.pd_allocation_type_name, PDTRIGGER.fk_pd_allocated_to,concat(USERPROFILE2.first_name," ",USERPROFILE2.last_name) as pd_allocated_to,PDTRIGGER.executive_id,concat(EXECUTIVE.first_name," ",EXECUTIVE.last_name) as executive_name,PDTRIGGER.central_pd_officer_id,concat(CENTRALOFFICER.first_name," ",CENTRALOFFICER.last_name) as centralofficer,PDTRIGGER.fk_pd_template_id,TEMPLATE.template_name, PDTRIGGER.fk_customer_segment,CUSTOMERSEGMENT.name as customer_segment_name,CUSTOMERSEGMENT.abbr as customer_segment_abbr, PDTRIGGER.pd_officier_final_judgement, PDTRIGGER.pd_agency_id,AGENCY.full_name as agency_name,AGENCY.is_qc_enabled,AGENCY.short_name as agency_short_name,PDTRIGGER.vendor_pdofficer,concat(VENDORPDOFFICER.first_name," ",VENDORPDOFFICER.last_name) as vendor_pdofficer_name,PDTRIGGER.loan_amount,PDTRIGGER.addressline1,PDTRIGGER.addressline2,PDTRIGGER.addressline3,PDTRIGGER.fk_city,CITY.name as city_name,PDTRIGGER.fk_state,STATE.name as state_name,PINCODE.pincode,PDTRIGGER.pincode as pincode_id,PDTRIGGER.pd_contact_person,PDTRIGGER.pd_contact_mobileno,DATE_FORMAT(PDTRIGGER.scheduled_on,"%d/%m/%Y %h:%i %p") as scheduled_on,PDTRIGGER.scheduled_on as scheduled_on_for_validation,DATE_FORMAT(PDTRIGGER.scheduled_on,"%dth %b %Y ") as scheduled_date_for_log,DATE_FORMAT(PDTRIGGER.scheduled_on,"%h:%i %p") as scheduled_time_for_log,DATE_FORMAT(PDTRIGGER.completed_on,"%d/%m/%Y %h:%i:%s %p") as completed_on,PDTRIGGER.remarks,PDTRIGGER.bounce_reason,PDTRIGGER.bounce_reason_others,BOUNCEMASTER.bounce_reason_name,PDTRIGGER.is_original_report_created,PDTRIGGER.pd_report_latest_version,PDTRIGGER.pd_branch_id,ENTITYLENDERBRANCH.branch_name,PDTRIGGER.qc_feedback,PDTRIGGER.qc_rating,PDTRIGGER.qc_remarks,PDTRIGGER.lender_rating,PDTRIGGER.lender_feedback,PDTRIGGER.pd_contact_landline,PDTRIGGER.other_pincode,PDTRIGGER.is_otp_done,OTPREJECTION.rejection_reason,PDTRIGGER.otp_reject_other_reason,PDTRIGGER.encrypted_url,PDTRIGGER.is_child,PDTRIGGER.parent_pd_id,PDTRIGGER.fk_primary_address_id,PDTRIGGER.fk_address_id,PDTRIGGER.random_string,PRODUCTS.prod_catagory,,PDTRIGGER.vendor_status,PDTRIGGER.vendor_scheduled_on as vendor_scheduled_on_validation,DATE_FORMAT(PDTRIGGER.vendor_scheduled_on,"%d/%m/%Y %h:%i %p") as vendor_scheduled_on'); $this->db->FROM(PDTRIGGER.' as PDTRIGGER'); $this->db->JOIN(ENTITY.' as ENTITY','PDTRIGGER.fk_lender_id = ENTITY.entity_id ','LEFT'); $this->db->JOIN(ENTITY.' as SUBENTITY','PDTRIGGER.sub_entity_id = SUBENTITY.entity_id ','LEFT'); $this->db->JOIN(ENTITYBILLING.' as ENTITYBILLING','PDTRIGGER.fk_entity_billing_id = ENTITYBILLING.entity_billing_id','LEFT'); $this->db->JOIN(PRODUCTS.' as PRODUCTS','PDTRIGGER.fk_product_id = PRODUCTS.product_id','LEFT'); $this->db->JOIN(SUBPRODUCTS.' as SUBPRODUCTS','PDTRIGGER.fk_subproduct_id = SUBPRODUCTS.subproduct_id','LEFT'); $this->db->JOIN(PDTYPE.' as PDTYPE','PDTRIGGER.fk_pd_type = PDTYPE.pd_type_id','LEFT'); //$this->db->JOIN(PDSTATUS.' as PDSTATUS','PDTRIGGER.pd_status = PDSTATUS.pd_status_id','LEFT'); $this->db->JOIN(USERPROFILE.' as USERPROFILE','PDTRIGGER.fk_createdby = USERPROFILE.userid','LEFT'); $this->db->JOIN(USERPROFILE.' as USERPROFILE1','PDTRIGGER.fk_updatedby = USERPROFILE1.userid','LEFT'); $this->db->JOIN(PDALLOCATIONTYPE.' as PDALLOCATIONTYPE','PDTRIGGER.fk_pd_allocation_type = PDALLOCATIONTYPE.pd_allocation_type_id','LEFT'); $this->db->JOIN(USERPROFILE.' as USERPROFILE2','PDTRIGGER.fk_pd_allocated_to = USERPROFILE2.userid','LEFT'); $this->db->JOIN(USERPROFILE.' as USERPROFILE3','PDTRIGGER.executive_id = USERPROFILE3.userid','LEFT'); $this->db->JOIN(USERPROFILE.' as EXECUTIVE','PDTRIGGER.executive_id = EXECUTIVE.userid','LEFT'); $this->db->JOIN(USERPROFILE.' as CENTRALOFFICER','PDTRIGGER.central_pd_officer_id = CENTRALOFFICER.userid','LEFT'); $this->db->JOIN(USERPROFILE.' as VENDORPDOFFICER','PDTRIGGER.vendor_pdofficer = VENDORPDOFFICER.userid','LEFT'); $this->db->JOIN(TEMPLATE.' as TEMPLATE','PDTRIGGER.fk_pd_template_id = TEMPLATE.template_id','LEFT'); $this->db->JOIN(CUSTOMERSEGMENT.' as CUSTOMERSEGMENT','PDTRIGGER.fk_customer_segment = CUSTOMERSEGMENT.customer_segment_id','LEFT'); $this->db->JOIN(ENTITY.' as AGENCY','PDTRIGGER.pd_agency_id = AGENCY.entity_id','LEFT'); $this->db->JOIN(STATE.' as STATE','PDTRIGGER.fk_state = STATE.state_id ','LEFT'); $this->db->JOIN(CITY.' as CITY','PDTRIGGER.fk_city = CITY.city_id','LEFT'); $this->db->JOIN(PINCODE.' as PINCODE','PDTRIGGER.pincode = PINCODE.pincode_id','LEFT'); $this->db->JOIN(OTPREJECTION.' as OTPREJECTION','PDTRIGGER.otp_reject_reason = OTPREJECTION.otp_rejection_id','LEFT'); $this->db->JOIN(BOUNCEMASTER.' as BOUNCEMASTER','PDTRIGGER.bounce_reason = BOUNCEMASTER.bounce_id','LEFT'); $this->db->JOIN(ENTITYLENDERBRANCH.' as ENTITYLENDERBRANCH','PDTRIGGER.pd_branch_id = ENTITYLENDERBRANCH.entity_lender_branch_id','LEFT'); $this->db->WHERE('PDTRIGGER.fk_address_id',$addressid); // $this->db->ORDER_BY('PDTRIGGER.pd_id',$sort); // $this->db->LIMIT($limit,$page); return $result_array = $this->db->GET()->result_array(); } function getLenderContactPersons($lender_id,$pd_branch_id) { // check CLIX group - this script for is lender is whether clix or clix housing, then have to bring both lender contact persons, otherwise pull contact persons belongs to single entity // $is_lenderid_clix_group = ENVIRONMENT == 'production' && ($lender_id == 5 || $lender_id == 9) ? true : (($lender_id == 16 || $lender_id == 38) ? true : false); // $clix = ENVIRONMENT == 'production' ? 5 : 16;$clixhousing = ENVIRONMENT == 'production' ? 9 : 38; // check CLIX group $this->db->select('USERPROFILE.userid, concat(USERPROFILE.first_name," ",USERPROFILE.last_name) as user_name,USERPROFILE.fk_entity_id,USERPROFILE.fk_city,USERPROFILEROLES.user_role,USERPROFILE.fk_entity_type_id,ROLES.role_name,if( POSITION("credit" IN ROLES.role_name),"CREDIT","SALES") as role_type'); $this->db->from(USERPROFILE.' as USERPROFILE'); //$this->db->join(ENTITYLENDERBRANCH.' as ENTITYLENDERBRANCH',"USERPROFILE.fk_entity_id = ENTITYLENDERBRANCH.fk_entity_id and ENTITYLENDERBRANCH.isactive = 1 and ENTITYLENDERBRANCH.fk_city_id = USERPROFILE.fk_city and ENTITYLENDERBRANCH.entity_lender_branch_id = $pd_branch_id"); //$this->db->join(STATE.' as STATE','USERPROFILE.fk_state = STATE.state_id and STATE.isactive = 1','LEFT'); //$this->db->join(CITY.' as CITY','USERPROFILE.fk_city = CITY.city_id and CITY.isactive = 1','LEFT'); // $this->db->join(CITY.' as CITY','USERPROFILE.fk_city = CITY.city_id and CITY.isactive = 1','LEFT'); $this->db->join(USERPROFILEROLES. ' as USERPROFILEROLES','USERPROFILEROLES.fk_userid = USERPROFILE.userid and USERPROFILEROLES.isactive =1'); $this->db->join(ROLES.' as ROLES','ROLES.role_id = USERPROFILEROLES.user_role'); //$this->db->where('USERPROFILE.fk_city',$pd_branch_id); // if(!$is_lenderid_clix_group) // { $this->db->where('USERPROFILE.fk_entity_id',$lender_id); // } // else // { // $this->db->where('USERPROFILE.fk_entity_id',$clix); // $this->db->or_where('USERPROFILE.fk_entity_id',$clixhousing); // } if($pd_branch_id) { //$this->db->where('USERPROFILE.fk_lender_branch_id',$pd_branch_id); } $this->db->where('USERPROFILE.isactive',1); $result = $this->db->get()->result_array(); // print_r($this->db->last_query()); return $result; } function getLenderHierarchyForPDListing($lender_user_id) { $this->db->select('USERPROFILE.userid, concat(USERPROFILE.first_name," ",USERPROFILE.last_name) as user_name,USERPROFILE.fk_entity_id,USERPROFILE.fk_city,USERPROFILE.fk_state,USERPROFILEROLES.user_role,USERPROFILE.fk_entity_type_id,ROLES.role_name,if( POSITION("credit" IN ROLES.role_name),"CREDIT","SALES") as role_type,ENTITYREGION.fk_region_id'); $this->db->from(USERPROFILE.' as USERPROFILE'); $this->db->join(USERPROFILEROLES. ' as USERPROFILEROLES','USERPROFILEROLES.fk_userid = USERPROFILE.userid and USERPROFILEROLES.isactive = 1'); $this->db->join(ROLES.' as ROLES','ROLES.role_id = USERPROFILEROLES.user_role'); $this->db->join(ENTITYREGION.' as ENTITYREGION','USERPROFILE.fk_city = ENTITYREGION.fk_city_id','LEFT'); //$this->db->join(ENTITYLENDERBRANCH.' as ENTITYLENDERBRANCH',"USERPROFILE.fk_entity_id = ENTITYLENDERBRANCH.fk_entity_id and ENTITYLENDERBRANCH.isactive = 1 and ENTITYLENDERBRANCH.fk_city_id = USERPROFILE.fk_city"); $this->db->where('USERPROFILE.isactive',1); $this->db->where('USERPROFILE.userid',$lender_user_id); $result = $this->db->get()->result_array(); //print_r($this->db->last_query());die(); return $result; } function checkExistPDDetails($params,$table,$client) { if(count($params) && $table) { if($table == PDTRIGGER) { $fields = array('pd_id','pd_sno'); $where_condition_array = array('lender_applicant_id' => $params['lender_applicant_id']); if($client) { $where_condition_array['fk_lender_id'] = $client; } return $this->selectCustomRecords($fields,$where_condition_array,$table); } else if($table == PDAPPLICANTSDETAILS) { $fields = array('pd_id','pd_sno','random_string'); $table = PDAPPLICANTSDETAILS.' as PDAPPLICANTSDETAILS'; $where_condition_array = array(); if(isset($params['mobile_no']) && $params['mobile_no']) { $where_condition_array['mobile_no'] = $params['mobile_no']; } if(isset($params['applicant_name']) && $params['applicant_name']) { $where_condition_array['lower(trim(applicant_name))'] = $params['applicant_name']; } $joins = array( array('table'=>PDTRIGGER.' as PDTRIGGER','condition'=>'PDAPPLICANTSDETAILS.fk_pd_id = PDTRIGGER.pd_id AND PDAPPLICANTSDETAILS.applicant_type = 1' ,'jointype'=>'INNER JOIN') ); if($client) { $joins = array( array('table'=>PDTRIGGER." as PDTRIGGER",'condition'=>"PDAPPLICANTSDETAILS.fk_pd_id = PDTRIGGER.pd_id AND PDAPPLICANTSDETAILS.applicant_type = 1 AND PDTRIGGER.fk_lender_id = $client" ,"jointype"=>"INNER JOIN") ); } return $this->getJoinRecords($fields,$table,$joins,$where_condition_array); print_r($this->db->last_query()); } } else { return array(); } } function getAllJSONFormData($pdid) { return $data = $this->db->select('fk_form_id, company_id, json, processed_json,rental_count_id')->from(PDFORMDETAILSJSON)->where('fk_pd_id',$pdid)->where('isactive',1)->get()->result_array(); } function getRCM($state) { // $fields = array('USERPROFILE.userid','USERPROFILE.first_name','USERPROFILE.last_name','USERPROFILEROLES.user_role'); // $table = USERPROFILE.' as USERPROFILE'; // $where_condition_array = array('USERPROFILE.fk_state' => $state); // $joins = array( // array('table'=>USERPROFILEROLES.' as USERPROFILEROLES','condition'=>'USERPROFILE.userid = USERPROFILEROLES.fk_userid and USERPROFILEROLES.user_role = 27 and USERPROFILEROLES.isactive = 1' ,'jointype'=>'INNER JOIN') // ); $fields = array('RCM_STATE_MAPPING.fk_user_id as userid','USERPROFILE.first_name','USERPROFILE.last_name','USERPROFILEROLES.user_role'); $table = RCM_STATE_MAPPING.' as RCM_STATE_MAPPING'; $where_condition_array = array('RCM_STATE_MAPPING.isactive '=>1,'RCM_STATE_MAPPING.fk_state_id' => $state); $joins = array( array('table'=>USERPROFILE." as USERPROFILE",'condition'=>"USERPROFILE.userid = RCM_STATE_MAPPING.fk_user_id " ,'jointype'=>'INNER JOIN'), array('table'=>USERPROFILEROLES.' as USERPROFILEROLES','condition'=>'RCM_STATE_MAPPING.fk_user_id = USERPROFILEROLES.fk_userid and USERPROFILEROLES.user_role = 27 and USERPROFILEROLES.isactive = 1' ,'jointype'=>'INNER JOIN') ); return $this->getJoinRecords($fields,$table,$joins,$where_condition_array); // print_r($this->db->last_query());exit(); } }