load->model('Entity_Management_Model'); $this->load->library('AWS_S3'); } public function listAllEntites_get() { $page = 0;$limit = 0;$sort = 'ASC';$entity_type_id = '';$entity_id = ''; if($this->get('page')) { $page = $this->get('page'); } if($this->get('limit')){ $limit = $this->get('limit'); } if($this->get('sort')) { $sort = $this->get('sort'); } if($this->get('etid')) { $entity_type_id = $this->get('etid'); } $result = $this->Entity_Management_Model->listAllEntities($page,$limit,$sort,$entity_type_id,$entity_id); if($result['data_status']) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $result['data']; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $this->response($data,REST_Controller::HTTP_OK); } } public function saveNewEntity_post() { $records = ""; $entity_id = ""; $bucket_status = ""; $cors_status = ""; if($this->post('records')){ $records = $this->post('records'); } if(!isset($records['entity_id'])) { $entity_id = $this->Entity_Management_Model->saveRecords($records,ENTITY);//insert user records and get entity_id if($entity_id != '' || $entity_id != null) { $CUSTOM_DEBUG_INFO = 'CUSTOM_DEBUG_INFO :- Entity Created Successfully! '. $entity_id; log_message('ERROR',$CUSTOM_DEBUG_INFO); // If New Entity is Lender(2) type, then create a S3 bucket for corresponding lender. if($records['fk_entity_type_id'] == 2) { //echo "LENDER TYPE"; $bucket_name = LENDER_BUCKET_NAME_PREFIX.$entity_id; $bucket_status = $this->aws_s3->createNewBucket($bucket_name); if($bucket_status['Location']) { $CUSTOM_DEBUG_INFO = 'CUSTOM_DEBUG_INFO :- Bucket Created Successfully! '. $entity_id; log_message('ERROR',$CUSTOM_DEBUG_INFO); $cors_status = $this->aws_s3->setCors($bucket_name); } } } if($entity_id != '' || $entity_id != null) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['record'] = $entity_id; $data['bucket_info'] = $bucket_status; $data['cors_info'] = $cors_status; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NOT_MODIFIED; $this->response($data,REST_Controller::HTTP_OK); } } else { $where_condition_array = array('entity_id' => $records['entity_id']); $entity_id = $this->Entity_Management_Model->updateRecords($records,ENTITY,$where_condition_array); if($entity_id != '' || $entity_id != null) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['record'] = true; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NOT_MODIFIED; $this->response($data,REST_Controller::HTTP_OK); } } } /* * Get Location Hierarchy as Region,state,city, and branch - wrapped as one array */ public function getLocationHierarchy_get() { $fields = array('region_id','name as region_name'); $where_condition_array = array('isactive' => 1); $region_data = $this->Entity_Management_Model->selectCustomRecords($fields,$where_condition_array,REGIONS); if(count($region_data)) { foreach($region_data as $region_key => $region) { $fields = array('state_id','name as state_name','code'); $where_condition_array = array('isactive' => 1,'fk_region_id'=>$region['region_id']); $state_data = $this->Entity_Management_Model->selectCustomRecords($fields,$where_condition_array,STATE); if(count($state_data)) { foreach($state_data as $state_key => $state) { $fields = array('city_id','name as city_name'); $where_condition_array = array('isactive' => 1,'fk_state_id' => $state['state_id']); $city_data = $this->Entity_Management_Model->selectCustomRecords($fields,$where_condition_array,CITY); if(count($city_data)) { foreach($city_data as $city_key => $city) { $fields = array('branch_id','name as branch_name'); $where_condition_array = array('isactive' => 1,'fk_city_id' => $city['city_id']); $branch_data = $this->Entity_Management_Model->selectCustomRecords($fields,$where_condition_array,BRANCH); $city_data[$city_key]['branch_data'] = $branch_data; } $state_data[$state_key]['city_data'] = $city_data; } } $region_data[$region_key]['state_data'] = $state_data; } } } if(count($region_data)) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $region_data; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NOT_MODIFIED; $data['msg'] = 'Records Not Found'; $this->response($data,REST_Controller::HTTP_OK); } } /****** Get All Entity Billing Info and it's contact info @param entity id******/ public function getEntityBillingInfo_get() { $entity_id = ""; if($this->get('eid')) { $entity_id = $this->get('eid'); } if( $entity_id != "" || $entity_id != null) { $result = $this->Entity_Management_Model->getEntityBillingInfo($entity_id); if(count($result)) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $result; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $this->response($data,REST_Controller::HTTP_OK); } } } public function getEntityMasterInfo_get() { $entity_id = ""; if($this->get('eid')) { $entity_id = $this->get('eid'); } if( $entity_id != "" || $entity_id != null) { // $columns = array('ENTITY.entity_id, ENTITY.full_name, ENTITY.short_name'); // $table = array(''); // $joins = array(); // $where_condition_array = array(); $result = $this->Entity_Management_Model->listAllEntities(0,0,0,0,$entity_id); if(count($result)) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $result; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $this->response($data,REST_Controller::HTTP_OK); } } } //entity_billing_id, fk_entity_id, billing_name, addressline1, addressline2, addressline3, pincode, email, mobileno, gstno, pan, gststatecode, isactive public function saveEntityBillingInfo_post() { $records = ""; $child_records = ""; $count = ""; if($this->post('records')){ $records = $this->post('records'); } //print_r($records); if($records != "" || $records != null) { if($records['entity_billing_id'] != "" || $records['entity_billing_id'] != null) { //UPDATE if(isset($records['contacts'])) { $child_records = $records['contacts']; unset($records['contacts']); } $where_condition_array = array('entity_billing_id' => $records['entity_billing_id']); $entity_billing_id = $this->Entity_Management_Model->updateRecords($records,ENTITYBILLING,$where_condition_array); if($entity_billing_id != "" || $entity_billing_id != null) { if($child_records != "" || $child_records != null) { foreach($child_records as $key => $child) { //print_r($child['entity_billing_contact_id']); if($child['entity_billing_contact_id'] != "" ||$child['entity_billing_contact_id'] != null) { //echo "UPDATE"; $where_condition_array = array('entity_billing_contact_id' => $child['entity_billing_contact_id']); $entity_billing_contact_id = $this->Entity_Management_Model->updateRecords($child,ENTITYBILLINGCONTACTINFO,$where_condition_array); if($entity_billing_contact_id != "" || $entity_billing_contact_id != null){$count++;} } else { //echo "INSERT"; $child['fk_entity_billing_id'] = $records['entity_billing_id']; $entity_billing_contact_id = $this->Entity_Management_Model->saveRecords($child,ENTITYBILLINGCONTACTINFO); if($entity_billing_contact_id != "" || $entity_billing_contact_id != null){$count++;} } } } } if(($entity_billing_id != "" || $entity_billing_id != null) && $count == count($child_records)) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = true; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = "Some Thing Went Wrong! Try Later"; $this->response($data,REST_Controller::HTTP_OK); } } else { //INSERT if(isset($records['contacts'])) { $child_records = $records['contacts']; unset($records['contacts']); } $entity_billing_id = $this->Entity_Management_Model->saveRecords($records,ENTITYBILLING); if($entity_billing_id != "" || $entity_billing_id != null) { if($child_records != "" || $child_records != null) { foreach($child_records as $key => $child) { $child['fk_entity_billing_id'] = $entity_billing_id; $entity_billing_contact_id = $this->Entity_Management_Model->saveRecords($child,ENTITYBILLINGCONTACTINFO); if($entity_billing_contact_id != "" || $entity_billing_contact_id != null){$count++;} } } } if(($entity_billing_id != "" || $entity_billing_id != null) && $count == count($child_records)) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $entity_billing_id; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = "Some Thing Went Wrong! Try Later"; $this->response($data,REST_Controller::HTTP_OK); } } } } /* * Get Location Hierarchy as city and state - wrapped as one array for Lender Regions Mapping */ public function getCityHierarchy_get() { $cities = $this->Entity_Management_Model->getCityHierarchy(); if(count($cities)) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $cities; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NOT_MODIFIED; $data['msg'] = 'Records Not Found'; $this->response($data,REST_Controller::HTTP_OK); } } /* * Save Entity Regions Mapping */ public function saveEntityRegionMapping_post() { $count = 0; $records = $this->post('records'); foreach($records as $key => $record) { if($record['entity_region_map_id'] != null || $record['entity_region_map_id'] != "") { $where_condition_array = array('entity_region_map_id' => $record['entity_region_map_id']); $entity_region_map_id = $this->Entity_Management_Model->updateRecords($record,ENTITYREGION,$where_condition_array); if($entity_region_map_id != "" || $entity_region_map_id != null){ $count++; } } else { $entity_region_map_id = $this->Entity_Management_Model->saveRecords($record,ENTITYREGION); if($entity_region_map_id != "" || $entity_region_map_id != null){ $count++; } } } if(count($records) == $count) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = true; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NOT_MODIFIED; $data['msg'] = 'Records Not Found'; $this->response($data,REST_Controller::HTTP_OK); } } /*Get Exist Mapped Region and City For Entity Edit Page*/ public function getEntityRegionCityMap_get() { $entity_id = $this->get('entityid'); $fields = array('fk_region_id','fk_city_id','fk_entity_id','entity_region_map_id','isactive'); $where_condition_array = array('fk_entity_id' => $entity_id); $records = $this->Entity_Management_Model->selectCustomRecords($fields,$where_condition_array,ENTITYREGION); if($records != null || $records != "") { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $records; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NOT_MODIFIED; $data['msg'] = 'Records Not Found'; $this->response($data,REST_Controller::HTTP_OK); } } /* * Save Vendor City Mapping */ public function saveVendorCityMapping_post() { $count = 0; $records = $this->post('records'); // foreach($records as $key => $record) // { if($records['vendor_city_map_id'] != null || $records['vendor_city_map_id'] != "") { $where_condition_array = array('vendor_city_map_id' => $records['vendor_city_map_id']); $vendor_city_map_id = $this->Entity_Management_Model->updateRecords($records,VENDORCITYMAP,$where_condition_array); if($vendor_city_map_id != "" || $vendor_city_map_id != null){ $count++; } } else { $vendor_city_map_id = $this->Entity_Management_Model->saveRecords($records,VENDORCITYMAP); if($vendor_city_map_id != "" || $vendor_city_map_id != null){ $count++; } } // } if($vendor_city_map_id != "" || $vendor_city_map_id != null) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $vendor_city_map_id; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NOT_MODIFIED; $data['msg'] = 'Records Not Found'; $this->response($data,REST_Controller::HTTP_OK); } } /*Get Exist Mapped Vendor and City For Entity Edit Page*/ public function getVendorCityMap_get() { $entity_id = $this->get('entityid'); $fields = array('vendor_city_map_id', 'fk_vendor_id', 'fk_city_id', 'isactive'); $where_condition_array = array('fk_vendor_id' => $entity_id); $records = $this->Entity_Management_Model->selectCustomRecords($fields,$where_condition_array,VENDORCITYMAP); if($records != null || $records != "") { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $records; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NOT_MODIFIED; $data['msg'] = 'Records Not Found'; $this->response($data,REST_Controller::HTTP_OK); } } //Save Branches Againest Lender - these branches used while PD Initation Screen public function saveLenderBranches_post() { //entity_lender_branch_id, branch_name, isactive, createdon, updatedon, fk_createdby, fk_updatedby $records = $this->post('records'); $count = 0; //print_r($records); foreach($records as $key => $record) { if($record['entity_lender_branch_id'] != null || $record['entity_lender_branch_id'] != "") { $where_condition_array = array('entity_lender_branch_id' => $record['entity_lender_branch_id']); $id = $this->Entity_Management_Model->updateRecords($record,ENTITYLENDERBRANCH,$where_condition_array); if($id != null || $id != ""){ $count++; } } else { $id = $this->Entity_Management_Model->saveRecords($record,ENTITYLENDERBRANCH); if($id != null || $id != ""){ $count++; } } } if($count != 0 && (count($records) == $count)) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = true; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NOT_MODIFIED; $data['msg'] = "Something Went Wrong!Try Later"; $this->response($data,REST_Controller::HTTP_OK); } } public function listLenderBranches_get() { $entity_id = $this->get('entityid'); //Get Mapped Cities $fields = array('fk_city_id', 'branch_name','isactive','fk_createdby','fk_entity_id','fk_updatedby','fk_city_id'); $where_condition_array = array('fk_entity_id' => $entity_id,'isactive'=>1); $records = $this->Entity_Management_Model->selectCustomRecords($fields,$where_condition_array,ENTITYLENDERBRANCH); $columns = array('ENTITYREGION.fk_city_id','CITY.name'); $table = ENTITYREGION.' as ENTITYREGION'; $joins = array(array('table' => CITY. ' as CITY', 'condition' =>'ENTITYREGION.fk_city_id = CITY.city_id', 'jointype' => 'INNER')); $where_condition_array = array('ENTITYREGION.isactive' => 1,'ENTITYREGION.fk_entity_id' => $entity_id); $entity_city_details = $this->Entity_Management_Model->getJoinRecords($columns,$table,$joins,$where_condition_array); //print_r($entity_city_details); $fields = array('entity_lender_branch_id', 'branch_name','isactive','fk_createdby','fk_entity_id','fk_updatedby','fk_city_id'); $where_condition_array = array('fk_entity_id' => $entity_id,'isactive'=>1); $records = $this->Entity_Management_Model->selectCustomRecords($fields,$where_condition_array,ENTITYLENDERBRANCH); if(count($entity_city_details)) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = array('branch_details' => $records,'city_master' =>$entity_city_details); $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = "No Data Available"; $this->response($data,REST_Controller::HTTP_OK); } } public function getFullTATInfo_post() { //echo "dssd"; $records = $this->post('records'); $entity_id = $records['fk_entity_id']; //$entity_tat_master_id = $records['entity_tat_master_id']; //print_r($this->post('records')); $fields = array('entity_tat_master_id', 'fk_entity_id', 'tat1', 'tat2'); $where_condition_array = array('fk_entity_id' => $entity_id,'isactive'=>1); $tat_master_records = $this->Entity_Management_Model->selectCustomRecords($fields,$where_condition_array,ENTITYTAT); if(count($tat_master_records)) { foreach($tat_master_records as $tat_key => $tat) { $columns = array('entity_tat_child_id', 'fk_city_id','CITY.name as city_name','fk_pd_type_id','PDTYPE.type_name as pd_type_name','fk_product_id','PRODUCTS.name as prodcut_name' , 'fk_tat_master_id'); $table = ENTITYTATCHILD.' as ENTITYTATCHILD'; $joins = array( array('table' => CITY. ' as CITY', 'condition' =>'ENTITYTATCHILD.fk_city_id = CITY.city_id', 'jointype' => 'INNER'), array('table' => PRODUCTS. ' as PRODUCTS', 'condition' =>'ENTITYTATCHILD.fk_product_id = PRODUCTS.product_id', 'jointype' => 'INNER'), array('table' => PDTYPE. ' as PDTYPE', 'condition' =>'ENTITYTATCHILD.fk_pd_type_id = PDTYPE.pd_type_id', 'jointype' => 'INNER') ); $where_condition_array = array('ENTITYTATCHILD.isactive' => 1,'ENTITYTATCHILD.fk_tat_master_id' => $tat['entity_tat_master_id']); $entity_tat_child = $this->Entity_Management_Model->getJoinRecords($columns,$table,$joins,$where_condition_array); $final_child = array(); foreach($entity_tat_child as $child_key => $child) { $temp = array(); $temp['entity_tat_child_id'] = $child['entity_tat_child_id']; $temp['city'] = array('id' => $child['fk_city_id'],'name' => $child['city_name']); $temp['product'] = array('id' => $child['fk_product_id'],'name' => $child['prodcut_name']); $temp['pd_type'] = array('id' => $child['fk_pd_type_id'],'name' => $child['pd_type_name']); $final_child[] = $temp; } $tat_master_records[$tat_key]['child'] = $final_child; } $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $tat_master_records; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = "No Data Available"; $this->response($data,REST_Controller::HTTP_OK); } } public function saveTATInfo_post() { $records = $this->post('records'); $count = 0; if($records['entity_tat_master_id'] == "" || $records['entity_tat_master_id'] == null) { $temp = array('fk_entity_id'=>$records['fk_entity_id'],'tat1'=>$records['tat1'],'tat2'=>$records['tat2'],'fk_createdby'=>$records['fk_createdby']); $id = $this->Entity_Management_Model->saveRecords($temp,ENTITYTAT); if($id != null || $id != "") { foreach($records['child'] as $key => $child) { $temp = array('fk_city_id'=>substr($child,0,1),'fk_product_id'=>substr($child,1,1),'fk_pd_type_id'=>substr($child,2,1),'fk_tat_master_id'=>$id); $cid = $this->Entity_Management_Model->saveRecords($temp,ENTITYTATCHILD); if($cid != "" || $cid != null) { $count++; } } } if($count != 0 && ($count == count($records['child']))) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $count; $this->response($data,REST_Controller::HTTP_OK); } } else { $temp = array('fk_entity_id'=>$records['fk_entity_id'],'tat1'=>$records['tat1'],'tat2'=>$records['tat2'],'fk_updatedby'=>$records['fk_updatedby']); $where_condition_array = array('entity_tat_master_id' => $records['entity_tat_master_id']); $id = $this->Entity_Management_Model->updateRecords($temp,ENTITYTAT,$where_condition_array); if($id != null || $id != "") { foreach($records['child'] as $key => $child) { $temp = array('fk_city_id'=>substr($child,0,1),'fk_product_id'=>substr($child,1,1),'fk_pd_type_id'=>substr($child,2,1),'fk_tat_master_id'=>$records['entity_tat_master_id']); $cid = $this->Entity_Management_Model->saveRecords($temp,ENTITYTATCHILD); if($cid != "" || $cid != null) { $count++; } } } if($count != 0 && ($count == count($records['child']))) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $count; $this->response($data,REST_Controller::HTTP_OK); } } } public function deleteTATCombimaion_post() { $records = $this->post('records'); $entity_tat_master_id = $records['entity_tat_master_id']; $fk_entity_id = $records['fk_entity_id']; $entity_tat_child_id_details = $records['entity_tat_child_id_details']; $this->db->SET('isactive',0); //$this->db->SET('fk_updatedby',$records['fk_updatedby']); $this->db->where('fk_tat_master_id',$entity_tat_master_id); //$this->db->where('fk_entity_id',$fk_entity_id); $this->db->where_in('entity_tat_child_id',$entity_tat_child_id_details); $this->db->update(ENTITYTATCHILD); //print_r($this->db->last_query()); $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = true; $this->response($data,REST_Controller::HTTP_OK); } public function saveEntityPricingInfo_post() { $records = $this->post('records'); $count = 0; foreach($records as $key => $record) { if($record['pricing_info_id'] != "" || $record['pricing_info_id'] != null) { $where_condition_array = array('pricing_info_id' => $record['pricing_info_id']); $id = $this->Entity_Management_Model->updateRecords($temp,PRICINGINFO,$where_condition_array); if($id != null || $id != "") { $count++; } } else { $id = $this->Entity_Management_Model->saveRecords($record,PRICINGINFO); if($id != null || $id != "") { $count++; } } } if($count != 0 && count($records) == $count) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $count; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NOT_MODIFIED; $data['msg'] = 'Something Went Wrong! Try Later...'; $this->response($data,REST_Controller::HTTP_OK); } } public function listEntityPricingInfo_post() { $records = $this->post('records'); echo 'called'; $logger = MYLOG::logFunction(); $logger->info("CUSTOM SPECIFIC TEMPLATE ",array('PDID' => "sdfkhs")); die(); $columns = array('ENTITY.short_name as lender_name', 'pricing_info_id', 'fk_lender_id', 'slab_name', 'from', 'to', 'full_pd_di', 'full_pd_ai', 'smart_pd', 'tele_pd', 'PRICINGINFO.isactive', 'PRICINGINFO.createdon', 'PRICINGINFO.updateon', 'PRICINGINFO.fk_createdby',' PRICINGINFO.fk_updatedby'); $table = PRICINGINFO.' as PRICINGINFO'; $joins = array(array('table' => ENTITY. ' as ENTITY', 'condition' =>'PRICINGINFO.fk_lender_id = ENTITY.entity_id', 'jointype' => 'INNER')); $where_condition_array = array('PRICINGINFO.isactive' => 1,'PRICINGINFO.fk_lender_id' => $records['entity_id']); $pricing_details = $this->Entity_Management_Model->getJoinRecords($columns,$table,$joins,$where_condition_array); // print_r($this->db->last_query()); if(count($pricing_details)) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $pricing_details; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = 'No Records Found'; $this->response($data,REST_Controller::HTTP_OK); } } public function saveEntityDisclaimer_post() { $records = $this->post('records'); $id = null; if($records['entity_disclaimer_id']) { $id = $this->Entity_Management_Model->updateRecords($records,ENTITYDISCLAIMER,array('entity_disclaimer_id' => $records['entity_disclaimer_id'])); } else { $id = $this->Entity_Management_Model->saveRecords($records,ENTITYDISCLAIMER); } if($id != null) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $id; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = 'Something Went Wrong! Try Later'; $this->response($data,REST_Controller::HTTP_OK); } } public function getEntityDisclaimer_get() { $entity_id = $this->get('eid'); $res = $this->Entity_Management_Model->selectCUstomRecords(array('*'),ENTITYDISCLAIMER,array('fk_entity_id' => $entity_id,'type' => 1)); if(count($res)) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $res[0]; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = 'No Records Found'; $this->response($data,REST_Controller::HTTP_OK); } } public function saveEntityFinInstitutions_post() { // ENTITYFININSTITUTION $records = $this->post('records'); $count = 0; foreach($records as $key => $value) { if($value['entity_fin_institution_id'] != "" || $value['entity_fin_institution_id'] != null) { $id = $this->Entity_Management_Model->updateRecords($value,ENTITYFININSTITUTION,array('entity_fin_institution_id' => $value['entity_fin_institution_id'])); if($id != '') { $count++; } } else { $id = $this->Entity_Management_Model->saveRecords($value,ENTITYFININSTITUTION); if($id != '') { $count++; } } } if($count == count($records)) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $count; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = 'Something Went Wrong! Try Later'; $this->response($data,REST_Controller::HTTP_OK); } } public function getEntityFinInstitutions_get() { $entity_id = $this->uri->segment(2); if($entity_id) { $institutions = $this->Entity_Management_Model->selectCustomRecords(array('*'),array('fk_entity_id' => $entity_id),ENTITYFININSTITUTION); if(count($institutions)) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $institutions; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = 'No Records Found!'; $this->response($data,REST_Controller::HTTP_OK); } } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_BAD_REQUEST; $this->response($data,REST_Controller::HTTP_OK); } } public function getEntityOtherPreferences_get() { $entity_id = $this->uri->segment(2); $products = array(); $customer_segments = array(); $pd_types = array(); $fk_createdby = ''; if($entity_id) { $preferences = $this->Entity_Management_Model->selectCustomRecords(array('*'),array('fk_entity_id' => $entity_id),ENTITYPREFERENCE); //print_r($preferences); foreach($preferences as $preference_key => $preference_value) { if($preference_value['preference_type'] == 1) { $products = explode(",",$preference_value['values']); } if($preference_value['preference_type'] == 2) { $customer_segments = explode(",",$preference_value['values']); } if($preference_value['preference_type'] == 3) { $pd_types = explode(",",$preference_value['values']); } $fk_createdby = $preference_value['fk_createdby']; } $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = array('products' => $products,'customer_segments' => $customer_segments,'pd_types' => $pd_types,'fk_createdby' => $fk_createdby); $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_BAD_REQUEST; $this->response($data,REST_Controller::HTTP_OK); } } public function saveEntityOtherPreferences_post() { $records = $this->post('records'); $over_all_count = 0; if(count($records['products'])) { $products = ''; foreach($records['products'] as $p_key => $p_value) { $products .= $p_value.','; } if($products != '') { $products = substr_replace($products,'',-1,1); $data = array('fk_entity_id' => $records['fk_entity_id'], 'preference_type' => 1, 'values' => $products,'fk_createdby' => $records['fk_createdby'],'fk_updatedby' => isset($records['fk_updatedby']) ? $records['fk_updatedby'] : null); $existing_data = $this->Entity_Management_Model->selectCustomRecords(array('*'),array('fk_entity_id' => $records['fk_entity_id'],'preference_type' => 1),ENTITYPREFERENCE); $id = null; if(count($existing_data)) { $existing_data_id = 0; if(isset($existing_data[0]['preference_type']) && $existing_data[0]['preference_type'] == 1) { $existing_data_id = $existing_data[0]['entity_preference_id']; } $id = $this->Entity_Management_Model->updateRecords($data,ENTITYPREFERENCE,array('entity_preference_id' => $existing_data_id)); } else { $id = $this->Entity_Management_Model->saveRecords($data,ENTITYPREFERENCE); } if($id != null) { $over_all_count++; } } } if(count($records['customer_segments'])) { $customer_segments = ''; foreach($records['customer_segments'] as $cs_key => $cs_value) { $customer_segments .= $cs_value.','; } if($customer_segments != '') { $customer_segments = substr_replace($customer_segments,'',-1,1); $data = array('fk_entity_id' => $records['fk_entity_id'], 'preference_type' => 2, 'values' => $customer_segments,'fk_createdby' => $records['fk_createdby'],'fk_updatedby' => isset($records['fk_updatedby']) ? $records['fk_updatedby'] : null); $existing_data = $this->Entity_Management_Model->selectCustomRecords(array('*'),array('fk_entity_id' => $records['fk_entity_id'],'preference_type' => 2),ENTITYPREFERENCE); $id = null; if(count($existing_data)) { $existing_data_id = 0; if(isset($existing_data[0]['preference_type']) && $existing_data[0]['preference_type'] == 2) { $existing_data_id = $existing_data[0]['entity_preference_id']; } $id = $this->Entity_Management_Model->updateRecords($data,ENTITYPREFERENCE,array('entity_preference_id' => $existing_data_id)); } else { $id = $this->Entity_Management_Model->saveRecords($data,ENTITYPREFERENCE); } if($id != null) { $over_all_count++; } } } if(count($records['pd_types'])) { $pd_types = ''; foreach($records['pd_types'] as $pt_key => $pt_value) { $pd_types .= $pt_value.','; } if($pd_types != '') { $pd_types = substr_replace($pd_types,'',-1,1); $data = array('fk_entity_id' => $records['fk_entity_id'], 'preference_type' => 3, 'values' => $pd_types,'fk_createdby' => $records['fk_createdby'],'fk_updatedby' => isset($records['fk_updatedby']) ? $records['fk_updatedby'] : null); $existing_data = $this->Entity_Management_Model->selectCustomRecords(array('*'),array('fk_entity_id' => $records['fk_entity_id'],'preference_type' => 3),ENTITYPREFERENCE); $id = null; if(count($existing_data)) { $existing_data_id = 0; if(isset($existing_data[0]['preference_type']) && $existing_data[0]['preference_type'] == 3) { $existing_data_id = $existing_data[0]['entity_preference_id']; } $id = $this->Entity_Management_Model->updateRecords($data,ENTITYPREFERENCE,array('entity_preference_id' => $existing_data_id)); } else { $id = $this->Entity_Management_Model->saveRecords($data,ENTITYPREFERENCE); } if($id != null) { $over_all_count++; } } } if($over_all_count != 0) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $over_all_count; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = 'Somethings went wrong. Try Later!'; $this->response($data,REST_Controller::HTTP_OK); } } public function getEntityPreferences_get() { $entity_id = $this->uri->segment(2); $products = array(); $salespd_products = array(); $customer_segments = array(); $pd_types = array(); $financial_institutions = array(); //echo $entity_id; $existing_preferences = $this->Entity_Management_Model->selectCustomRecords(array('*'),array('fk_entity_id' => $entity_id),ENTITYPREFERENCE); $financial_institutions = $this->Entity_Management_Model->selectCustomRecords(array('*'),array('fk_entity_id' => $entity_id,'isactive' => 1),ENTITYFININSTITUTION); // if(count($existing_financial_institutions)) // { // $financial_institutions = $this->Entity_Management_Model->selectCustomRecords(array('*'),array('fk_entity_id' => $entity_id,'isactive' => 1),ENTITYFININSTITUTION); // } if(count($existing_preferences)) { foreach($existing_preferences as $preference_key => $preference_value) { if($preference_value['preference_type'] == 1) { $products = explode(",",$preference_value['values']); //$products = '(' . $preference_value['values'] . ')'; } if($preference_value['preference_type'] == 2) { $customer_segments = explode(",",$preference_value['values']); } if($preference_value['preference_type'] == 3) { $pd_types = explode(",",$preference_value['values']); } if($preference_value['preference_type'] == 4) { $salespd_products = explode(",",$preference_value['values']); } } } //GET PRODUCT AND SUB PRODUCT $this->db->SELECT('product_id,name as product_name,abbr as product_abbr,prod_catagory')->FROM(PRODUCTS); if(count($products)) { $this->db->WHERE_IN('product_id ',$products); } $this->db->WHERE('isactive',1); $products = $this->db->GET()->result_array(); //print_r($products);die(); foreach($products as $key => $value) { $fields = array('subproduct_id','name as subproduct_name','abbr as subproduct_abbr','is_others'); $where_condition_array = array('isactive' => 1,'fk_product_id' => $value['product_id']); $subproducts = $this->Entity_Management_Model->selectCustomRecords($fields,$where_condition_array,SUBPRODUCTS); //array_push($result_data[$key],$subproducts); $products[$key]['subproducts'] = $subproducts; } //GET SALESPS PRODUCT AND SUB PRODUCT $this->db->SELECT('product_id,name as product_name,abbr as product_abbr')->FROM(PRODUCTS); if(count($salespd_products)) { $this->db->WHERE_IN('product_id ',$salespd_products); } $this->db->WHERE('isactive',1); $salespd_products = $this->db->GET()->result_array(); //print_r($products);die(); foreach($salespd_products as $key => $value) { $fields = array('subproduct_id','name as subproduct_name','abbr as subproduct_abbr','is_others'); $where_condition_array = array('isactive' => 1,'fk_product_id' => $value['product_id']); $subproducts = $this->Entity_Management_Model->selectCustomRecords($fields,$where_condition_array,SUBPRODUCTS); //array_push($result_data[$key],$subproducts); $salespd_products[$key]['subproducts'] = $subproducts; } //GET CUSTOMER SEGMENTS $this->db->SELECT('customer_segment_id,name as customer_segment,abbr')->FROM(CUSTOMERSEGMENT); if(count($customer_segments)) { $this->db->WHERE_IN('customer_segment_id ',$customer_segments); } $this->db->WHERE('isactive',1); $customer_segments = $this->db->GET()->result_array(); //GET PDTYPES $this->db->SELECT('*')->FROM(PDTYPE); if(count($pd_types)) { $this->db->WHERE_IN('pd_type_id ',$pd_types); } $this->db->WHERE('isactive',1); $pd_types = $this->db->GET()->result_array(); $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = array('products' =>$products,'customer_segments' => $customer_segments, 'pd_types' => $pd_types,'financial_institutions' => $financial_institutions,'salespd_products' => $salespd_products); $this->response($data,REST_Controller::HTTP_OK); } }