checkRTGuser(); // is RTG User or not $this->setUserType(); /*if ($_SESSION['userType'] == CRM_USER_INDICATOR && $_SESSION['Auth']['User']['type'] == 1) { $isAllclients = $this->isAccessAllClients(); if ($isAllclients) { $employee_id = $this->Auth->user('user_id'); $client_id = $this->request->params['pass'][0]; if (!empty($client_id) && !empty($employee_id)) { if (!$this->isValidEmployee($employee_id, $client_id) && $this->request->params['action'] != "index") { return $this->redirect(['action' => 'index']); } } } }*/ $isPermitted = Permission::isPermitted(SECURE_PORTAL_CONTROLLER_ID); if($isPermitted){ $this->Auth->allow(['index']); } } /** * Index method * * @return \Cake\Http\Response|void */ public function index() { $this->clientList(); } private function clientList() { $member_id = $this->Auth->user('id'); $userTypeName = $this->getCurrentUserType(); $this->loadModel('Clients'); $affiliate_type = 0; if ($this->request->is('ajax')) { $inputData = $this->request->getData(); $this->loadModel('ClientAssignments'); $member_id = $this->Auth->user('id'); if ($inputData['action'] == 'CLIENT_STATUS_UPDATE') { $message = "Status has not been updated."; $response = $this->Clients->statusUpdateById($inputData['client_id'], $inputData['status']); if ($response) { $message = "Status has been updated successfully."; } } else if($inputData['action'] == 'CLIENT_SHIFT'){ $check_type = $inputData['check_type']; $employee_id = 0; $affiliate_id = 0; $employee_list = $inputData['employee_list']; $employee_affiliate_list = $inputData['employee_affiliate_list']; $affiliateList = $inputData['affiliateList']; if(!empty($employee_list)){ $employee_list = json_decode($employee_list,true); } if(!empty($employee_affiliate_list)){ $employee_affiliate_list = json_decode($employee_affiliate_list,true); } if(!empty($affiliateList)){ $affiliateList = json_decode($affiliateList,true); } $organizedData = $this->organizeClientShifting($inputData); extract($organizedData); $client_name = $inputData['client_name']; $message = 'The Client "' . $client_name . '" has not been moved succesfully.'; $final_assoc = $inputData['final_assoc']; //pr($final_assoc);exit; $crmuser_id = $inputData['crmuser_id']; $client_id = $inputData['client_id']; $this->loadModel('ReminderNotification'); if($check_type == "unchecked"){ if($crmuser_id > 0){ $response = $this->ClientAssignments->deleteRelation($client_id,$crmuser_id); $crmuserRefferenceIds = $this->Crmusers->getCrmUsersByIdsWithRefference([$crmuser_id]); if(!empty($crmuserRefferenceIds)){ $updateData = current($crmuserRefferenceIds); $updateData['client_id'] = $client_id; $this->ReminderNotification->reminderNotificationStatusUpdate($updateData,0); // 0 = in active reminder } }else{ $response = $this->ClientAssignments->deleteMemberRelation($client_id,$member_id); } }else if($check_type == "checked"){ if($crmuser_id > 0){ $this->loadModel('Crmusers'); $crmuserRefferenceIds = $this->Crmusers->getCrmUsersByIdsWithRefference([$crmuser_id]); if(!empty($crmuserRefferenceIds)){ $updateData = current($crmuserRefferenceIds); $updateData['client_id'] = $client_id; $this->ReminderNotification->reminderNotificationStatusUpdate($updateData,1); // 1 = active reminder } }else{ $crmuserRefferenceIds[] = ['refference_id'=>$member_id,'refference_type'=>1]; // 1 = member type } $this->loadModel('Clients'); $this->Clients->moveClient($inputData['client_id'],0); // 0 = move to main client list $response = $this->ClientAssignments->updateClientRelation($inputData['client_id'],$crmuserRefferenceIds); } //$response = $this->Clients->assignAffiliateOrEmployee($inputData['client_id'],$employee_id,$affiliate_id); if($response){ if(!empty($client_name)){ $message = 'The Client "' . $client_name . '" has been moved succesfully.'; }else{ $message = 'Client has been moved succesfully.'; } } }else if($inputData['action'] == 'EMPLOYEE_AFFILIATE_LIST'){ $commonLogic = new commonLogic(); $message = $commonLogic->clientsFilteringByMemberOREmployees($inputData); }else if($inputData['action'] == 'GET_AGREEMENT_LIST'){ $message = $this->getAgrementListByClientId($inputData); }else if($inputData['action'] == "ASSIN_AGREEMENT"){ $message = $this->assignAgreementByClientId($inputData); }elseif ($inputData['action'] == "DELETE_AGREEMENT_FORMAT") { $message = $this->deleteAgreementFormatById($inputData); }else if($inputData['action'] == "AGREEMENT_REASSIGNED"){ $inputData['member_id'] = $member_id; $message = $this->reassignedAgreement($inputData); $message['html'] = $this->getAgrementListByClientId($inputData); }else if($inputData['action'] == "REVOKE_AGREEMENT_REASSIGNED"){ $this->loadModel('AgreementAssignments'); $status = 1; $inputData['member_id'] = $member_id; $res = $this->AgreementAssignments->makeReAssignedAgreement($inputData,$status); $message['status'] = false; $message['message'] = "Revoked is not succesfull."; if($res){ $message['status'] = true; $message['message'] = "Successfully revoked re-assigned."; $message['html'] = $this->getAgrementListByClientId($inputData); // Everything Insertion (2 = crmuser, 1 = member, 3 = contact user, 4 = staff user) $everything = new \App\Utility\Everythings(); $everythinData['action_on_id'] = SAME_AS_BY; $everythinData['action_on_name'] = SAME_AS_BY; $everythinData['event_name'] = "agreement_revoked_reassign"; $everythinData['action_on_usertype'] = CMS_USER_INDICATOR; $everything->everythingWrapper($this->Auth->user(), $everythinData); // Everything Insertion } }else if ($inputData['action'] == 'GET_CLIENT_EMAIL') { // pr($inputData);exit; $client_id = $inputData['client_id']; $client_info = $this->Contacts->getPrimaryClientInfoByClientId($client_id); $message['client_info'] = $client_info; }else if ($inputData['action'] == 'SEND_CLIENT_EMAIL') { $this->loadModel('SendEmailToClients'); $user_type = $this->getCurrentUserType(); $client_id = $inputData['client_id']; $email_subject = $inputData['client_email_subject']; $to_email = trim($inputData['client_email']); $email_body = nl2br($inputData['client_email_body']); $member_contact_name= $this->Auth->user('contact_name'); $member_contact_company= $this->Auth->user('company_name'); if($user_type == 'MEMBER'){ $inputData['sender_id'] = $this->Auth->User('id'); $inputData['sender_type'] = 1; }else if($user_type == 'EMPLOYEE'){ $inputData['sender_id'] = $this->Auth->User('user_id'); $inputData['sender_type'] = 2; } $client_send_email = $this->SendEmailToClients->insertClientSendEmail($inputData); // pr($inputData);exit; if((!empty($member_contact_name) && !empty($member_contact_company))){ $client_regards = "Regards,
".$member_contact_name.','.$member_contact_company; }elseif (!empty($member_contact_name)){ $client_regards = "Regards,
".$member_contact_name; }elseif (!empty($member_contact_company)){ $client_regards = "Regards,
".$member_contact_company; }else{ $client_regards = "Regards
"; } $commonlogic = new commonLogic; $personalize = $commonlogic->personalizeInfo(); $templateContent = [ 'regards' => $client_regards, 'email_body' => $email_body ]; if(!empty($personalize['email_signature'])){ $templateContent['email_signature'] = $personalize['email_signature']; } $this->sendEmail('send_email_to_client', $templateContent, $to_email, $email_subject, "", $personalize['personalize']); $message['status'] = true; }else if ($inputData['action'] == 'SEND_CLIENT_LOGIN_CREDENTIAL') { $password = $inputData['password']; $c_password = $inputData['c_password']; $contact_id = $inputData['contact_id']; $message = ""; if($password == $c_password){ $this->loadModel('Contacts'); $contact_data['password'] = md5($password); $contact_data['raw_password'] = $password; if($this->Contacts->updateContactById($contact_id,$contact_data)){ $contact = $this->Contacts->getContactsById($contact_id); $email = $contact->email; if(!empty($email)) { $message = 'Client login credential sent successfully.'; $member_contact_name = $this->Auth->user('contact_name'); $member_contact_company = $this->Auth->user('company_name'); if ((!empty($member_contact_name) && !empty($member_contact_company))) { $client_regards = "Regards,
" . $member_contact_name . ',' . $member_contact_company; } elseif (!empty($member_contact_name)) { $client_regards = "Regards,
" . $member_contact_name; } elseif (!empty($member_contact_company)) { $client_regards = "Regards,
" . $member_contact_company; } else { $client_regards = "Regards,
"; } $commonlogic = new commonLogic; $personalize = $commonlogic->personalizeInfo(); $loginurl = $personalize['login_url']; $templateContent = [ 'firstname' => $contact->first_name . " " . $contact->last_name, 'loginurl' => $loginurl, 'user_email' => $email, 'password' => $contact->raw_password, 'member_name' => $this->Auth->user('email'), 'regards' => $client_regards ]; if (!empty($personalize['email_signature'])) { $templateContent['email_signature'] = $personalize['email_signature']; } $this->sendEmail(MANDRILL_TEMPLATE_USER_CREATION, $templateContent, $email, "Client Portal Credential", "", $personalize['personalize']); } } } } echo json_encode($message); exit; } if ($this->request->is('post')){ $request = $this->request->getData(); if(isset($request['client_action_types']) && $request['client_action_types'] > 0){ $selected_client_ids = []; if(!empty($request['selected_content'])){ $selected_client_ids = explode(',', $request['selected_content']); } if( $request['client_action_types'] == 1){ // For Delete All $result = $this->Clients->deleteClientRelatedInfoByClientId($member_id,$selected_client_ids); if($result){ $this->Flash->success(__('The selected clients has been deleted.')); } else { $this->Flash->error(__('The action could not be executed. Please, try again.')); } }else if( $request['client_action_types'] == 2){//For Make All Active $status = 1; $result = $this->Clients->updateStatusByIdList($selected_client_ids,$status); if($result){ $this->Flash->success(__('The selected clients has been made active.')); } else { $this->Flash->error(__('The action could not be executed. Please, try again.')); } }else if( $request['client_action_types'] == 3){//For Make All InActive $status = 2; $result = $this->Clients->updateStatusByIdList($selected_client_ids,$status); // print_r($result);exit; if($result){ $this->Flash->success(__('The selected clients has been made Inactive.')); } else { $this->Flash->error(__('The action could not be executed. Please, try again.')); } }else if( $request['client_action_types'] == 4){//For Make All Graduated/Completed $status = 3; $result = $this->Clients->updateStatusByIdList($selected_client_ids,$status); // print_r($result);exit; if($result){ $this->Flash->success(__('The selected clients has been made Inactive.')); } else { $this->Flash->error(__('The action could not be executed. Please, try again.')); } }else if( $request['client_action_types'] == 5){//For Export All if(!empty($selected_client_ids) && is_array($selected_client_ids)){ $export_condition = "Clients.id in (".implode(",",$selected_client_ids).")"; $this->query_to_csv($export_condition, $member_id); } } }else if(isset($request['selected_reference_ids']) && !empty($request['selected_reference_ids'])){ $selected_reference_ids = json_decode($request['selected_reference_ids'],true); $selected_client_ids = []; $final_assoc = []; if(!empty($request['selected_content'])){ $selected_client_ids = explode(',', $request['selected_content']); } if(!empty($selected_client_ids)){ $this->loadModel('ClientAssignments'); foreach($selected_client_ids as $c_id){ if(!empty($selected_reference_ids)){ foreach($selected_reference_ids as $r_id => $r_type){ if($r_type == 1 && $r_id == 0){ $r_id = $member_id; } $final_assoc[] = [ 'client_id'=>$c_id, 'refference_id'=>$r_id, 'refference_type'=>$r_type ]; $this->ClientAssignments->deleteMemberRelation($c_id, $r_id, $r_type); } } } } if(!empty($final_assoc)){ if($this->ClientAssignments->insertClientAssignMents($final_assoc)){ $this->Flash->success(__('The selected clients has been assigned.')); } } //pr($final_assoc);exit; } } $clientId = ""; if ($_SESSION['userType'] == CONTACT_USER_INDICATOR) { $client_id = $_SESSION['global_client_id']; $clientId = 'id =' . $client_id; return $this->redirect('/client/view/' . $client_id); } $page_limit = 10; $selected_status = 1; // for ui select active $status = "Clients.status = ".$selected_status; // default active client $client_type = 1; $affiliate_client_id = 0; $employee_id = 0; $affiliate_client_list = []; $emlpoyee_list = []; $affiliate_condition = ""; if(isset($this->request->query['show_client_checkbox'])){ $this->set('show_client_checkbox',1); } $is_show_all_clients = $this->Auth->user('is_show_all_clients'); if (isset($this->request->query['page_limit'])) { $page_limit = $this->request->query('page_limit'); } if (isset($this->request->query['client_type'])) { $client_type = $this->request->query('client_type'); } if (isset($this->request->query['affiliate_client_id'])) { $affiliate_client_id = $this->request->query('affiliate_client_id'); } if (isset($this->request->query['employee_id'])) { $employee_id = $this->request->query('employee_id'); } if (isset($this->request->query['status']) && !empty($this->request->query['status'])) { $status = "Clients.status = " . $this->request->query('status'); $selected_status = $this->request->query('status'); if($selected_status == "all"){ $status = ""; } } $this->paginate = [ 'limit' => $page_limit, 'order' => [ 'Clients.id' => 'desc', 'Contacts.id' => 'desc' ], 'maxLimit'=>500 ]; $cmsuser_id = $this->Auth->user('id'); $search = ''; if (false) { // is affiliate user check $affiliate_client_id = $this->Auth->user('user_id'); $affiliate_type = 2; if($this->Auth->user('is_employee_affiliate')){ $affiliate_type = 4; } } else { $is_employee = false; if ($_SESSION['userType'] == CRM_USER_INDICATOR && $_SESSION['Auth']['User']['type'] == 1) { $is_employee = true; } list($affiliate_client_list,$emlpoyee_list,$employee_affiliate_list) = $this->generateAffiliateList($employee_id,$is_employee); } $is_source = 0; if ($this->request->params['action'] == 'clientonboarding') { $is_source = 1; } if($userTypeName != "AFFILIATE"){ if (!empty($affiliate_condition)) { $affiliate_condition .= " AND Clients.is_source = " . $is_source; } else { $affiliate_condition = "Clients.is_source = " . $is_source; } } if($is_show_all_clients == 2){ $auth_employee_id = $this->Auth->user('user_id'); } // echo $affiliate_condition;exit; if (isset($this->request->query['search']) && !empty($this->request->query['search'])) { $search = $this->request->query('search'); $condition = ' ( Clients.name LIKE ' . "'%" . $search . "%' OR Clients.phone LIKE '%" . $search . "%' OR Clients.website LIKE '%" . $search . "%'" . "OR Contacts.first_name LIKE '%" . $search . "%' OR Contacts.last_name LIKE '%" . $search ."%'" ." OR CONCAT(Contacts.first_name, ' ' , Contacts.last_name) LIKE '%" . $search ."%'" ." OR Contacts.email LIKE '%" . $search ."%'" . ") "; } if($_SESSION['userType'] == CMS_USER_INDICATOR || ($_SESSION['userType'] == STAF_USER_INDICATOR && $this->Auth->user('is_employee_to_member')) || ($_SESSION['userType']== CRM_USER_INDICATOR)){ $clients = $this->Contacts->find('all') ->contain(['Clients']); $is_filtering = true; /* For All Employee $employee_id = -1 For A single employee $employee_id > 0 For All Affiliate $affiliate_client_id = -1 For A single Affiliate $affiliate_client_id > 0 */ $reference_type_array = []; $reference_id_array = []; if($userTypeName == "EMPLOYEE"){ if($this->Auth->user('is_show_all_clients') == 1){ $is_filtering = false; }else{ $reference_type_array[] = 3; $reference_id_array[] = $this->Auth->user('user_id'); } } if($employee_id == -1){ $reference_type_array[] = 3; }else if($employee_id > 0){ $reference_type_array[] = 3; $reference_id_array[] = $employee_id; } if ($affiliate_client_id == -1 || $affiliate_client_id == -2) { $reference_type_array[] = 2; $reference_type_array[] = 4; } else if ($affiliate_client_id > 0) { if($affiliate_type == 0){ $this->loadModel('Crmusers'); $crmusers = $this->Crmusers->find()->where(['Crmusers.id' => $affiliate_client_id])->first(); $affiliate_type = 2; if($crmusers->employee_id > 0){ $affiliate_type = 4; } } if($affiliate_type > 0){ $reference_id_array[] = $affiliate_client_id; $reference_type_array[] = $affiliate_type; }else{ $reference_type_array[] = 2; $reference_type_array[] = 4; } } $new_dynamic_condition = ""; if(!empty($reference_type_array)){ $reference_type_array = array_unique($reference_type_array); $new_dynamic_condition = 'CAT.refference_type in('.implode(",",$reference_type_array).")"; } if(!empty($reference_id_array)){ $reference_id_array = array_unique($reference_id_array); $current_condition = 'CAT.refference_id in('.implode(",",$reference_id_array).")"; if(!empty($new_dynamic_condition)){ $new_dynamic_condition .= " AND ".$current_condition; }else{ $new_dynamic_condition = $current_condition; } } if($is_filtering && !empty($new_dynamic_condition)){ $clients = $clients->join([ 'table' => 'client_assignments', 'alias' => 'CAT', 'type' => 'INNER', 'conditions' => [ 'Contacts.client_id = CAT.client_id', $new_dynamic_condition ] ]); } $clients = $clients ->where([$condition,$affiliate_condition,'Contacts.is_primary_contact' => 1, 'Clients.cmsuser_id' => $cmsuser_id, $clientId, $status]) ->distinct('Contacts.client_id'); }else if($_SESSION['userType']== CRM_USER_INDICATOR){ $this->loadModel('ClientAssignments'); $CRM_AUTH_ID = $this->Auth->user('user_id'); $u_type = "refference_type = 1"; if($_SESSION['Auth']['User']['type'] == 1){ $u_type = "refference_type = 3"; }else if($_SESSION['Auth']['User']['type'] == 2){ $u_type = "refference_type = 2 OR refference_type = 4"; if($this->Auth->user('is_employee_affiliate')){ $u_type = "refference_type = 4"; } } if(!empty($u_type)){ $emp_client_ids = $this->ClientAssignments->getClientsByUserTypeIdAndCondition($CRM_AUTH_ID,$u_type); } $clients = []; if(!empty($emp_client_ids)){ $clients = $this->Contacts->find('all')->contain(['Clients']) ->where(['Clients.id IN'=>$emp_client_ids, 'Clients.cmsuser_id' => $cmsuser_id, $clientId, $status]); } } //} $user_permissions = $this->request->session()->read('user_permissions'); $this->loadModel('Sertg'); $paginated_clients = $clients; $paginated_clients = $this->paginate($paginated_clients); $client_ids = []; $client_employee_relations = []; $client_letter_set_assoc = []; if(!empty($client_ids)){ $this->loadModel('ClientAssignments'); $user_type = 0; if ($_SESSION['userType']== CRM_USER_INDICATOR && $_SESSION['Auth']['User']['type'] == 1) { $user_type = 4; } $client_employee_relationsData = $this->ClientAssignments->getClientsRealtionsByClientIds($client_ids, $user_type); $client_employee_relations = $client_employee_relationsData['employees']; } // pr($client_employee_relationsData); // pr($client_employee_relations);exit; if($_SESSION['hasEpicVelocity'] || $_SESSION['hasVelocity']){ $isVelocityUser = true; } $this->loadModel('Notes'); $noteList = $this->Notes->getNotesByMemberIdWithNoteList($cmsuser_id); $this->set('noteList', $noteList); $this->set('client_type', $client_type); $this->set('affliliate_client_id', $affiliate_client_id); $this->set('affiliate_client_list', $affiliate_client_list); $this->set('employee_affiliate_list', $employee_affiliate_list); $this->set('employee_list', $emlpoyee_list); $this->set('employee_id', $employee_id); $this->set('status', $selected_status); $this->set('user_permission', $user_permissions); $this->set('bulk_actions', [BULK_ACTION_DELETE => "Move to trash"]); $this->set('clients', $paginated_clients); //$this->paginate($clients)); $this->set('searchText', $search); $this->set('current_module', $this->getModules()); $this->set('page_list', $this->getPages()); $this->set('module_pages', $this->getPages()); $nav_arr[0] = array('action' => 'add', 'page_id' => '3046', 'icon' => '', 'label' => 'Add'); $this->set('nav_arr', $nav_arr); $this->set('page_limit', $page_limit); $this->set('isVelocityUser', $isVelocityUser); $this->set("is_source", $is_source); $this->set("client_employee_relations", $client_employee_relations); $this->set("client_employee_relationsData", $client_employee_relationsData); $this->set("client_letter_set_assoc", $client_letter_set_assoc); //$this->viewBuilder()->layout("custom_layout"); } /** * View method * * @param string|null $idClient Secure Portal Login id. * @return \Cake\Http\Response|void * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ public function view($id = null) { $clientSecurePortalLogin = $this->ClientSecurePortalLogin->get($id, [ 'contain' => [] ]); $this->set('clientSecurePortalLogin', $clientSecurePortalLogin); } /** * Add method * * @return \Cake\Http\Response|null Redirects on successful add, renders view otherwise. */ public function add() { $clientSecurePortalLogin = $this->ClientSecurePortalLogin->newEntity(); if ($this->request->is('post')) { $clientSecurePortalLogin = $this->ClientSecurePortalLogin->patchEntity($clientSecurePortalLogin, $this->request->getData()); if ($this->ClientSecurePortalLogin->save($clientSecurePortalLogin)) { $this->Flash->success(__('Theclient secure portal login has been saved.')); return $this->redirect(['action' => 'index']); } $this->Flash->error(__('Theclient secure portal login could not be saved. Please, try again.')); } $this->set(compact('clientSecurePortalLogin')); } /** * Edit method * * @param string|null $idClient Secure Portal Login id. * @return \Cake\Http\Response|null Redirects on successful edit, renders view otherwise. * @throws \Cake\Network\Exception\NotFoundException When record not found. */ public function edit($id = null) { $clientSecurePortalLogin = $this->ClientSecurePortalLogin->get($id, [ 'contain' => [] ]); if ($this->request->is(['patch', 'post', 'put'])) { $clientSecurePortalLogin = $this->ClientSecurePortalLogin->patchEntity($clientSecurePortalLogin, $this->request->getData()); if ($this->ClientSecurePortalLogin->save($clientSecurePortalLogin)) { $this->Flash->success(__('Theclient secure portal login has been saved.')); return $this->redirect(['action' => 'index']); } $this->Flash->error(__('Theclient secure portal login could not be saved. Please, try again.')); } $this->set(compact('clientSecurePortalLogin')); } /** * Delete method * * @param string|null $idClient Secure Portal Login id. * @return \Cake\Http\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ public function delete($id = null) { $this->request->allowMethod(['post', 'delete']); $clientSecurePortalLogin = $this->ClientSecurePortalLogin->get($id); if ($this->ClientSecurePortalLogin->delete($clientSecurePortalLogin)) { $this->Flash->success(__('Theclient secure portal login has been deleted.')); } else { $this->Flash->error(__('Theclient secure portal login could not be deleted. Please, try again.')); } return $this->redirect(['action' => 'index']); } }