EVOLUTION-NINJA
Edit File: Yaskawa_model.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class yaskawa_model extends CI_Model { public function admin_login($email,$password) { $this->db->select('*'); $this->db->from('users A'); $this->db->join('user_type B','B.user_type_id=A.user_type_id','left'); $this->db->where('A.email',$email); // $this->db->where('A.password',$password); $this->db->where('A.delete_status','ACTIVE'); $result = $this->db->get(); return $result->row(); } public function get_invoice_list(){ $this->db->select('*'); $this->db->from('invoice'); // $this->db->where($where); $query=$this->db->get(); return $query->result(); } public function get_converted_status_new($id){ $this->db->select('*'); $this->db->from('invoice'); $this->db->join('new_account','new_account.account_id=invoice.account_id'); $this->db->where('invoice.account_id',$id); $this->db->where('invoice.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function get_quotation_last_row($table,$where){ $this->db->select('*'); $this->db->from($table); $this->db->where($where); $this->db->order_by('quotation_id','DESC'); $query=$this->db->get(); return $query->row(); } public function get_row_by_desc($lead_id){ // $this->db->select('*'); $this->db->from('lead_attach_notes'); $this->db->where('lead_id',$lead_id); $this->db->order_by('notes_id','DESC'); $query=$this->db->get(); return $query->row(); } public function get_row_by_desc_new($lead_id){ // $this->db->select('*'); $this->db->from('potential_attach_notes'); $this->db->where('potential_id',$lead_id); $this->db->order_by('notes_id','DESC'); $query=$this->db->get(); return $query->row(); } public function add_leads($lead_details) { $result=$this->db->insert('leads',$lead_details); if($result){ return 1; }else{ return 0; } } public function get_single_row($table,$where){ $this->db->select('*'); $this->db->from($table); $this->db->where($where); $query=$this->db->get(); return $query->row(); } public function get_employee_row($emp_id){ $this->db->select('*'); $this->db->from('employees'); $this->db->join('designation','designation.designation_id=employees.designation_id','left'); $this->db->join('salary','salary.emp_id=employees.emp_id','left'); $this->db->join('department','department.department_id=employees.department_id','left'); $this->db->where('employees.emp_id',$emp_id); $query=$this->db->get(); return $query->row(); } public function update_single($where,$table,$data) { $this->db->where($where); return $this->db->update($table,$data); } public function get_customer_result($table,$where){ $this->db->select('*'); $this->db->from($table); $this->db->where($where); $query=$this->db->get(); return $query->result(); } public function delete_lead($lead_id,$data) { $this->db->where('lead_id',$lead_id); return $this->db->update('leads',$data); } public function delete_potential($lead_id,$data) { $this->db->where('potential_id',$lead_id); return $this->db->update('new_potential',$data); } public function update_status($lead_id,$data) { $this->db->where('task_id',$lead_id); $this->db->update('lead_new_tasks',$data); } public function acc_update_status($task_id,$dat) { $this->db->where('task_id',$task_id); $this->db->update('lead_new_tasks',$dat); } public function get_row($lead_id) { $this->db->select('*'); $this->db->from('lead_new_tasks'); $this->db->where('task_id',$lead_id); $query=$this->db->get(); return $query->row(); } public function customer_assets_details(){ $this->db->select('*'); $this->db->from('customer_assets a'); $this->db->join('service_type b','b.service_id = a.c_service'); $this->db->join('assets c','c.assets_id = a.c_domain_name'); $this->db->where('a.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } // edit leads under me 'dileep' ****************************************************************** public function get_lead_by_id($lead_id) { // Query to fetch lead data $this->db->where('lead_id', $lead_id); $query = $this->db->get('leads'); // Assuming 'leads' is your table name // Return the result as an array return $query->row_array(); // Fetch the lead as an associative array } // Method to update lead data public function update_lead($lead_id, $data) { // Update the lead information based on lead_id $this->db->where('lead_id', $lead_id); return $this->db->update('leads', $data); // Assuming 'leads' is your table name } // potential modal public function get_potential_by_id($potential_id) { $this->db->where('potential_id', $potential_id); $query = $this->db->get('new_potential'); // Replace 'potential_table' with your actual table name return $query->row_array(); // Return as an array } public function update_potential($potential_id, $data) { $this->db->where('potential_id', $potential_id); $this->db->update('new_potential', $data); // Replace 'potential_table' with your actual table name } // ACCOUNT // Method to get account details by ID // delete public function get_employee_designation($emp_id) { $this->db->where('emp_id', $emp_id); $this->db->where('delete_status', 'ACTIVE'); $query = $this->db->get('employees'); if ($query->num_rows() > 0) { return $query->row(); // Return a single row if found } else { return null; // Return null if no results found } } public function get_expense_by_id($expense_id) { $this->db->where('expense_id', $expense_id); $query = $this->db->get('expense'); return $query->row(); // Returns the row if it exists, otherwise null } public function update_invoice_payments($where, $data, $table) { // Log the query for debugging purposes $this->db->where($where); $this->db->update($table, $data); // Log the last executed query for debugging log_message('debug', 'Last query: ' . $this->db->last_query()); // Return true if any rows were updated return $this->db->affected_rows() > 0; } // ************************************************************************************************* // public function get_lead_by_id($lead_id) // { // $this->db->select('*'); // $this->db->from('leads'); // $this->db->where('leads.lead_id',$lead_id); // $this->db->where('leads.delete_status','ACTIVE'); // $query=$this->db->get(); // return $query->row(); // } // public function update_lead($lead_id,$lead_details) // { // $this->db->where('leads.lead_id',$lead_id); // $this->db->where('leads.delete_status','ACTIVE'); // $this->db->update('leads',$lead_details); // } public function insert($table,$data) { $this->db->insert($table,$data); return $this->db->insert_id(); } public function add_employee($employee_details) { $this->db->insert('employees',$employee_details); return $this->db->insert_id(); } public function get_all_employees() { $this->db->select('*,a.email_id as eid'); $this->db->from('employees a'); $this->db->join('department b','b.department_id = a.department_id','left'); $this->db->where('a.delete_status','ACTIVE'); $this->db->order_by('a.first_name','ASC'); $query=$this->db->get(); return $query->result(); } public function get_emp_id() { $this->db->select('*'); $this->db->from('employees'); $this->db->order_by('emp_id','DESC'); $this->db->limit(1); $query = $this->db->get(); return $query->row(); } public function get_emp_list($table,$where) { $this->db->select('*'); $this->db->from('employees'); $this->db->order_by('first_name','ASC'); $this->db->where($where); $query = $this->db->get(); return $query->result(); } public function delete_employee($emp_id,$data) { $this->db->where('employees.emp_id',$emp_id); $delete_emp=$this->db->update('employees',$data); $this->db->select('*'); $this->db->from('employees'); $this->db->where('employees.emp_id',$emp_id); $query=$this->db->get(); $result=$query->row(); $employee_id=$result->employee_id; $this->db->where('employee_education.employee_id',$employee_id); $delete_edu=$this->db->update('employee_education',$data); if($delete_emp||$delete_edu) { return 1; } else { return 0; } } public function add_department($department_details) { return $this->db->insert('department',$department_details); //return $this->db->insert(); } public function get_all_departments() { $this->db->select('*'); $this->db->from('department'); $this->db->where('department.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function delete_department($department_id,$data) { $this->db->where('department_id',$department_id); return $this->db->update('department',$data); } public function edit_department_details($department_id) { $this->db->select('*'); $this->db->from('department'); $this->db->where('department.department_id',$department_id); $this->db->where('department.delete_status','ACTIVE'); $query=$this->db->get(); return $query->row(); } public function update_department($department_id,$department_details) { //$this->db->select('*'); //$this->db->from('employees'); $this->db->where('department.department_id',$department_id); $this->db->where('department.delete_status','ACTIVE'); return $this->db->update('department',$department_details); } public function add_designation($designation_details) { return $this->db->insert('designation',$designation_details); //return $this->db->insert(); } public function get_all_designation() { $this->db->select('*'); $this->db->from('designation'); $this->db->where('designation.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function delete_designation($designation_id,$data) { $this->db->where('designation_id',$designation_id); return $this->db->update('designation',$data); } public function edit_designation_details($designation_id) { $this->db->select('*'); $this->db->from('designation'); $this->db->where('designation.designation_id',$designation_id); $this->db->where('designation.delete_status','ACTIVE'); $query=$this->db->get(); return $query->row(); } public function update_designation($designation_id,$designation_details) { //$this->db->select('*'); //$this->db->from('employees'); $this->db->where('designation.designation_id',$designation_id); $this->db->where('designation.delete_status','ACTIVE'); return $this->db->update('designation',$designation_details); } public function get_all_menu() { $this->db->select('*'); $this->db->from('menu'); $this->db->where('menu.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function get_menu_details($alt_name) { $this->db->select($alt_name); $this->db->from('leads'); $this->db->where('leads.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function single_lead_details($lead_id) { $this->db->select('*,a.last_name as lead_last_name , a.profile_pick as lead_pick,a.*'); $this->db->from('leads a'); $this->db->join('users b','b.user_id = a.lead_owner'); $this->db->where('a.lead_id',$lead_id); $this->db->where('a.delete_status','ACTIVE'); $query=$this->db->get(); return $query->row(); } public function single_lead_detail($lead_id) { $this->db->select('*,a.last_name as lead_last_name , a.profile_pick as lead_pick,a.*'); $this->db->from('leads a'); $this->db->join('users b','b.user_id = a.lead_owner'); $this->db->where('a.lead_id',$lead_id); // $this->db->where('a.delete_status','ACTIVE'); $query=$this->db->get(); return $query->row(); } public function single_lead_profile_details($lead_id) { $this->db->select('*,a.last_name as lead_last_name , a.profile_pick as lead_pick,a.*'); $this->db->from('leads a'); $this->db->join('users b','b.user_id = a.lead_owner'); $this->db->where('a.lead_id',$lead_id); //$this->db->where('a.delete_status','ACTIVE'); $query=$this->db->get(); return $query->row(); } public function update_menu_status($menu_id,$menu_status) { $this->db->where('menu.menu_id',$menu_id); $this->db->where('menu.delete_status','ACTIVE'); $this->db->update('menu',$menu_status); } public function get_users() { $this->db->select('*'); $this->db->from('employees'); $this->db->where('employees.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function get_alldata($table,$where) { $this->db->select('*'); $this->db->from($table); $this->db->where($where); $query=$this->db->get(); return $query->result(); } public function get_row_data($table,$where) { $this->db->select('*'); $this->db->from($table); $this->db->where($where); $query=$this->db->get(); return $query->row(); } public function get_menu() { $this->db->select('*'); $this->db->from('menu'); $this->db->where('menu.delete_status','ACTIVE'); $this->db->where('menu.status',1); $this->db->limit(6); $query=$this->db->get(); return $query->result(); $array = array(); foreach($query as $val) { $data['menu'] =$query; $this->db->select($val->alt_name); $this->db->from('leads'); $this->db->where('leads.delete_status','ACTIVE'); $query=$this->db->get(); $query= $query->result(); $data['menu_details']=$query; array_push($array,$data); } return $array; } public function import_lead_data($data) { return $this->db->insert('leads',$data); } //Sachin part public function get_all_leads($role_id) { $this->db->select('*, a.last_name as lead_last_name,a.created_at as c_date,a.description as desc,a.email as email'); $this->db->from('leads a'); $this->db->join('users b','b.user_id =a.lead_owner'); $this->db->join('roles c','c.role_id=a.role_id','left'); $this->db->where('a.lead_convert !=','CLOSED'); $this->db->where('a.delete_status','ACTIVE'); $this->db->order_by('a.created_at','DESC'); $this->db->order_by('a.lead_id','DESC'); $this->db->group_by(array('a.lead_id')); $query=$this->db->get(); return $query->result(); } public function feed_insert($feeds_details) { $result=$this->db->insert('feeds',$feeds_details); if($result){ return 1; } else { return 0; } } public function get_all_comments(){ $this->db->select('feeds_comment.*,a.user_name as sender_name,a.profile_pick as admin_pic,b.user_name as receiver_name,b.profile_pick as user_pic'); $this->db->from('feeds_comment','users a','users b'); $this->db->join('users a','feeds_comment.send_id=a.user_id'); $this->db->join('users b','feeds_comment.receive_id=b.user_id'); $result=$this->db->get(); return $result->result(); } public function feeds_records($days){ $this->db->select('feeds.*,a.user_name as sender_name,a.profile_pick as admin_pic,b.user_name as receiver_name,b.profile_pick as user_pic'); $this->db->from('feeds','users a','users b'); $this->db->join('users a','feeds.sender_id=a.user_id'); $this->db->join('users b','feeds.receiver_id=b.user_id'); // $this->db->join('feeds_comment','feeds_comment.feeds_id = feeds.feeds_id','left'); $this->db->order_by('feeds.send_date_time','DESC'); $this->db->limit(10); $this->db->where('feeds.date',$days); $query=$this->db->get(); return $query->result(); } public function feeds_records1($where,$table) { $this->db->select('feeds_comment.*,a.user_name as sender_name,a.profile_pick as admin_pic, b.user_name as receiver_name'); $this->db->from('feeds_comment'); $this->db->join('users a','feeds_comment.send_id=a.user_id'); $this->db->join('users b','feeds_comment.receive_id=b.user_id'); // $this->db->join('feeds_comment','feeds_comment.feeds_id = feeds.feeds_id','left'); $this->db->where('feeds_comment.feeds_id',$where); $this->db->limit(10); $query=$this->db->get(); return $query->result(); } public function feeds_lastweek__records(){ $this->db->select('feeds.*,a.user_name as sender_name,a.profile_pick as admin_pic,b.user_name as receiver_name,b.profile_pick as user_pic'); $this->db->from('feeds','users a','users b'); $this->db->join('users a','feeds.sender_id=a.user_id'); $this->db->join('users b','feeds.receiver_id=b.user_id'); // $this->db->join('feeds_comment','feeds_comment.feeds_id = feeds.feeds_id','left'); $this->db->order_by('feeds.send_date_time','DESC'); $this->db->limit(10); $this->db->where('feeds.date >= curdate() - INTERVAL DAYOFWEEK(curdate())+5 DAY'); $this->db->where('feeds.date < curdate() - INTERVAL DAYOFWEEK(curdate())-2 DAY'); $query=$this->db->get(); return $query->result(); } public function feeds_lastweek__records1($where,$table){ $this->db->select('feeds_comment.*,a.user_name as sender_name,a.profile_pick as admin_pic, b.user_name as receiver_name'); $this->db->from('feeds_comment'); $this->db->join('users a','feeds_comment.send_id=a.user_id'); $this->db->join('users b','feeds_comment.receive_id=b.user_id'); // $this->db->join('feeds_comment','feeds_comment.feeds_id = feeds.feeds_id','left'); $this->db->where('feeds_comment.feeds_id',$where); $this->db->limit(10); $this->db->where('feeds_comment.comm_date >= curdate() - INTERVAL DAYOFWEEK(curdate())+5 DAY'); $this->db->where('feeds_comment.comm_date < curdate() - INTERVAL DAYOFWEEK(curdate())-2 DAY'); $query=$this->db->get(); return $query->result(); } public function currentmonth_feeds_records($current_month){ $this->db->select('feeds.*,a.user_name as sender_name,a.profile_pick as admin_pic,b.user_name as receiver_name,b.profile_pick as user_pic'); $this->db->from('feeds','users a','users b'); $this->db->join('users a','feeds.sender_id=a.user_id'); $this->db->join('users b','feeds.receiver_id=b.user_id'); // $this->db->join('feeds_comment','feeds_comment.feeds_id = feeds.feeds_id','left'); $this->db->order_by('feeds.send_date_time','DESC'); $this->db->limit(10); $this->db->where('MONTH(date)',$current_month); $query=$this->db->get(); return $query->result(); } public function currentmonth_feeds_records1($where,$table,$current_month){ $this->db->select('feeds_comment.*,a.user_name as sender_name,a.profile_pick as admin_pic, b.user_name as receiver_name'); $this->db->from('feeds_comment'); $this->db->join('users a','feeds_comment.send_id=a.user_id'); $this->db->join('users b','feeds_comment.receive_id=b.user_id'); // $this->db->join('feeds_comment','feeds_comment.feeds_id = feeds.feeds_id','left'); $this->db->where('feeds_comment.feeds_id',$where); $this->db->limit(10); $this->db->where('MONTH(comm_date)',$current_month); $query=$this->db->get(); return $query->result(); } public function feeds_lastmonth__records($month){ $this->db->select('feeds.*,a.user_name as sender_name,a.profile_pick as admin_pic,b.user_name as receiver_name,b.profile_pick as user_pic'); $this->db->from('feeds','users a','users b'); $this->db->join('users a','feeds.sender_id=a.user_id'); $this->db->join('users b','feeds.receiver_id=b.user_id'); //$this->db->join('feeds_comment','feeds_comment.feeds_id = feeds.feeds_id','left'); $this->db->order_by('send_date_time','DESC'); $this->db->limit(10); $this->db->where('feeds.date',$month); $query=$this->db->get(); return $query->result(); } public function feeds_lastmonth__records1($where,$table,$month){ $this->db->select('feeds_comment.*,a.user_name as sender_name,a.profile_pick as admin_pic, b.user_name as receiver_name'); $this->db->from('feeds_comment'); $this->db->join('users a','feeds_comment.send_id=a.user_id'); $this->db->join('users b','feeds_comment.receive_id=b.user_id'); // $this->db->join('feeds_comment','feeds_comment.feeds_id = feeds.feeds_id','left'); $this->db->where('feeds_comment.feeds_id',$where); $this->db->limit(10); $this->db->where('feeds.date',$month); $query=$this->db->get(); return $query->result(); } //sachin part public function deleteleads($lead_ids) { if (!empty($lead_ids)) { $this->db->where_in('lead_id', $lead_ids); $this->db->delete('leads'); } } public function todays_sales() { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d'); $this->db->select('*,a.last_name as ln,a.created_at as created,a.email as mails'); $this->db->from('leads a'); $this->db->join('users b','b.user_id = a.lead_owner'); $this->db->where('a.created_at',$created_at); $this->db->where('a.annual_revenue >',0); $query=$this->db->get(); return $query->result(); } public function month_sale() { $date= new DateTime('now', new DateTimeZone('Asia/Kolkata')); $created_at = $date->format('m'); $this->db->select('*'); $this->db->from('leads'); $this->db->where('MONTH(created_at)',$created_at); $this->db->where('annual_revenue >',0); $query=$this->db->get(); return $query->result(); } public function sales_source() { $this->db->select('*,a.last_name as ln'); $this->db->from('leads a'); $this->db->join('users b','b.user_id = a.lead_owner'); //$this->db->where('MONTH(created_at)',$created_at); // $this->db->where('annual_revenue >',0); $query=$this->db->get(); return $query->result(); } public function lead_ownership_data(){ $this->db->select('*'); $this->db->from('leads'); $result=$this->db->get(); return $result->result(); } public function todays_leads_list() { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d'); $this->db->select('*,a.last_name as ln'); $this->db->from('leads a'); $this->db->join('users b','b.user_id = a.lead_owner'); $this->db->where('a.created_at',$created_at); $query=$this->db->get(); return $query->result(); } public function leads_by_industry() { $this->db->select('*'); $this->db->from('leads'); //$this->db->where('created_at',$created_at); $query=$this->db->get(); return $query->result(); } public function leads_by_status() { $this->db->select('*'); $this->db->from('leads a'); $this->db->join('users b','b.user_id = a.lead_owner'); //$this->db->where('created_at',$created_at); $this->db->group_by('a.lead_status'); $query=$this->db->get(); return $query->result(); } public function leads_by_source() { $this->db->select('*'); $this->db->from('leads'); //$this->db->where('created_at',$created_at); $this->db->group_by('lead_source'); $query=$this->db->get(); return $query->result(); } public function favorite_reports() { $this->db->select('*'); $this->db->from('report_menu'); $this->db->where('favorite_report','yes'); $query=$this->db->get(); return $query->result(); } public function ownership(){ $this->db->select('*'); $this->db->from('leads'); $this->db->group_by('lead_owner'); $result=$this->db->get(); return $result->result(); } public function sales_across_owner(){ $this->db->select("user_name,count('lead_id') as count"); $this->db->from('leads'); $this->db->join('users','users.user_id = leads.lead_owner'); $this->db->group_by('leads.lead_owner'); $result=$this->db->get(); return $result->result(); } public function sales_across_source(){ $this->db->select("lead_owner,count('lead_id') as count"); $this->db->from('leads'); $this->db->where('lead_source','Just Dial'); $this->db->group_by('lead_owner'); $result=$this->db->get(); return $result->result(); } public function Get_search($keyword) { $this->db->distinct(); $this->db->select('lead_owner'); //$this->db->order_by('customer_name', 'DESC'); $this->db->like("lead_owner", $keyword); $this->db->from('leads'); $query= $this->db->get(); return $query->result(); } public function update_favorite_reports($report_id,$data) { $this->db->where('report_menu.report_id',$report_id); $this->db->where('report_menu.report_status','ACTIVE'); $this->db->update('report_menu',$data); } public function delete_report($record_ids,$data) { if (!empty($record_ids)) { $this->db->where_in('report_id', $record_ids); $this->db->update('report_menu',$data); } } public function insert_new_users($insert){ $result=$this->db->insert('users',$insert); if($result){ return 1; } else { return 0; } } public function number_of_users(){ $this->db->select('*'); $this->db->from('users'); $this->db->where('users.delete_status','ACTIVE'); $this->db->where('users.role_id !=','68'); $result=$this->db->get(); return $result->result(); } public function user_details($user_id) { $this->db->select('*'); $this->db->from('users'); $this->db->where('users.user_id',$user_id); $this->db->where('users.delete_status','ACTIVE'); $query=$this->db->get(); return $query->row(); } public function login_person($user_id) { $this->db->select('*'); $this->db->from('users'); $this->db->where('users.user_id',$user_id); $this->db->where('users.delete_status','ACTIVE'); $query=$this->db->get(); return $query->row(); } public function user_details_update($uid,$update_data) { $this->db->where('users.user_id',$uid); $this->db->where('users.delete_status','ACTIVE'); $result=$this->db->update('users',$update_data); if($result){ return 1; } else { return 0; } } public function company_details($company_details) { $result=$this->db->insert('company_details',$company_details); if($result){ return 1; } else { return 0; } } public function add_new_roles($role_details) { $this->db->insert('roles', $role_details); $role_id = $this->db->insert_id(); return $role_id; } public function get_role_data($role_id) { $this->db->select('*'); $this->db->from('roles'); $this->db->where('roles.role_id',$role_id); $query=$this->db->get(); return $query->row(); } public function get_all_roles() { $this->db->select('*'); $this->db->from('roles'); $this->db->where('roles.delete_status','ACTIVE'); $this->db->limit(1); $query=$this->db->get(); return $query->row(); } public function get_all_role($table,$where) { $this->db->select('*'); $this->db->from($table); $this->db->where($where); $result=$this->db->get(); return $result->result(); } public function subrol_details($report_to) { $this->db->select('*'); $this->db->from('roles'); $this->db->where('roles.report_to',$report_to); $query=$this->db->get(); return $query->result(); } public function add_details($table,$role_details) { return $this->db->insert($table,$role_details); } public function add_employee_education($education_details) { return $this->db->insert('employee_education',$education_details); } public function update_roles($role_id,$role_details) { //$this->db->select('*'); //$this->db->from('employees'); $this->db->where('roles.role_id',$role_id); $this->db->where('roles.delete_status','ACTIVE'); return $this->db->update('roles',$role_details); } public function delete_role($role_id,$data) { $this->db->where('role_id',$role_id); return $this->db->update('roles',$data); } public function insert_email_settings($email_address_details) { return $this->db->insert('email_settings',$email_address_details); //return $this->db->insert(); } public function get_all_email_settings() { $this->db->select('*'); $this->db->from('email_settings'); $this->db->where('email_settings.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function get_users_list($username) { $this->db->select('*'); $this->db->from('users'); $this->db->where("user_name LIKE '%$username%'"); $query=$this->db->get(); return $query->result(); } public function sender_upload_files($feeds_id,$upload_file_details) { $this->db->where('feeds_id',$feeds_id); $result=$this->db->insert('feeds',$upload_file_details); if($result){ return 1; } else { return 0; } } public function get_pic_details($lead_id) { $this->db->select('*'); $this->db->from('leads'); $this->db->join('lead_profile_pic', 'leads.lead_id = lead_profile_pic.lead_id'); $this->db->where('leads.delete_status','ACTIVE'); $query=$this->db->get(); return $query->row(); } public function get_all_mail(){ $this->db->select('*'); $this->db->from('email_settings'); $this->db->where('email_settings.delete_status','ACTIVE'); $result=$this->db->get(); return $result->result(); } public function import_employee_data($data) { return $this->db->insert('employees',$data); } public function delete_email_organizing($email_settings_id,$data) { $this->db->where('email_settings_id',$email_settings_id); $this->db->update('email_settings',$data); } public function add_lead_notes($notes_details) { return $this->db->insert('account_attach_notes',$notes_details); } public function add_account_notes($notes_details) { return $this->db->insert('account_attach_notes',$notes_details); } public function add_contact_notes($notes_details) { return $this->db->insert('lead_attach_notes',$notes_details); } public function add_lead_attachments($attachment_details) { return $this->db->insert('lead_attachments',$attachment_details); } public function attach_linl_url($url_details) { return $this->db->insert('lead_link_url',$url_details); } public function add_new_task($task_details) { return $this->db->insert('lead_new_tasks',$task_details); } public function add_new_events($event_details) { // return $this->db->insert('lead_new_events',$event_details); } public function add_new_call($call_details) { return $this->db->insert('lead_new_calls',$call_details); } public function add_profile_pic($image_details) { return $this->db->insert('lead_profile_pic',$image_details); } public function get_event_call_details($lead_id) { $this->db->select('*'); $this->db->from('leads'); //$this->db->join('lead_new_calls','leads.lead_id=lead_new_calls.lead_id'); // $this->db->join('lead_new_events','leads.lead_id=lead_new_events.lead_id'); $this->db->join('lead_new_tasks','leads.lead_id=lead_new_tasks.lead_id'); $this->db->where('leads.lead_id',$lead_id); $this->db->where('lead_new_tasks.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function get_event_call_details_lead($lead_id) { $this->db->select('*'); $this->db->from('leads'); //$this->db->join('lead_new_calls','leads.lead_id=lead_new_calls.lead_id'); // $this->db->join('lead_new_events','leads.lead_id=lead_new_events.lead_id'); $this->db->join('lead_new_tasks','leads.lead_id=lead_new_tasks.lead_id'); $this->db->where('leads.lead_id',$lead_id); $this->db->where('lead_new_tasks.activity','OPEN'); $this->db->where('lead_new_tasks.details_from','Lead'); $this->db->where('lead_new_tasks.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function get_event_closed_details($lead_id) { $this->db->select('*'); $this->db->from('leads'); // $this->db->join('lead_new_calls','leads.lead_id=lead_new_calls.lead_id'); // $this->db->join('lead_new_events','leads.lead_id=lead_new_events.lead_id'); $this->db->join('lead_new_tasks','leads.lead_id=lead_new_tasks.lead_id'); $this->db->where('leads.lead_id',$lead_id); $this->db->where('lead_new_tasks.delete_status','INACTIVE'); $query=$this->db->get(); return $query->result(); } public function get_event_closed_details_lead($lead_id) { $this->db->select('*'); $this->db->from('leads'); // $this->db->join('lead_new_calls','leads.lead_id=lead_new_calls.lead_id'); // $this->db->join('lead_new_events','leads.lead_id=lead_new_events.lead_id'); $this->db->join('lead_new_tasks','leads.lead_id=lead_new_tasks.lead_id'); $this->db->where('leads.lead_id',$lead_id); $this->db->where('lead_new_tasks.activity','CLOSE'); $this->db->where('lead_new_tasks.details_from','Lead'); $this->db->where('lead_new_tasks.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function feeds_filter($feeds_date){ $this->db->select('*'); $this->db->from('feeds'); $this->db->join('users','feeds.receiver_id=users.user_id'); $this->db->join('leads','leads.lead_id=feeds.receiver_id'); $this->db->join('lead_profile_pic',' lead_profile_pic.lead_id=leads.lead_id'); $this->db->order_by('date','DESC'); $this->db->where('date',$feeds_date); $query=$this->db->get(); return $query->result(); } public function add_lead_account_attachment($attachment_details) { return $this->db->insert('lead_attachments',$attachment_details); } public function account_attach_linl_url($url_details) { return $this->db->insert('lead_account_linkurl',$url_details); } public function add_new_account_task($task_details) { return $this->db->insert('lead_new_tasks',$task_details); } public function add_new_account_events($event_details) { return $this->db->insert('account_events',$event_details); } public function add_new_account_call($call_details) { return $this->db->insert('account_calls',$call_details); } public function add_new_quotations($quotation_details) { return $this->db->insert('quotations',$quotation_details); } public function get_quotation_details($id) { $this->db->select('*'); $this->db->from('new_account'); $this->db->join('quotations','new_account.account_id=quotations.lead_id'); $this->db->where('new_account.account_id',$id); $this->db->where('new_account.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function get_quotation_details_potential($id) { $this->db->select('*'); $this->db->from('quotations'); $this->db->join('new_potential','new_potential.potential_id=quotations.potential_id'); $this->db->where('new_potential.potential_id',$id); $this->db->where('quotations.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function convert_status($quotation_id,$data) { $this->db->select('*'); $this->db->from('leads'); $this->db->join('quotations','leads.lead_id=quotations.lead_id'); $this->db->where('quotations.quotation_id',$quotation_id); $this->db->update('quotations',$data); } public function get_converted_status($id) { $this->db->select('*'); $this->db->from('new_account'); $this->db->join('quotations','new_account.account_id=quotations.lead_id'); $this->db->where('new_account.account_id',$id); $this->db->where('quotations.convert_status','CONVERTED'); $this->db->where('new_account.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function get_all_users() { $this->db->select('*'); $this->db->from('users'); $this->db->where('users.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function task($lead_id) { $this->db->select('*'); $this->db->from('leads'); $this->db->join('lead_new_tasks','leads.lead_id=lead_new_tasks.lead_id'); //$this->db->where('leads.lead_id',$lead_id); $this->db->where('leads.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function event($lead_id) { $this->db->select('*'); $this->db->from('leads'); $this->db->where('leads.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function call_status($lead_id) { $this->db->select('*'); $this->db->from('leads'); //$this->db->join('lead_new_events','leads.lead_id=lead_new_events.lead_id'); $this->db->join('lead_new_tasks','leads.lead_id=lead_new_tasks.lead_id'); $this->db->where('lead_new_tasks.type','Call'); $this->db->where('leads.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function get_notes_details($lead_id) { $this->db->select('*,account_attach_notes.created_at as c_date'); $this->db->from('account_attach_notes'); $this->db->join('leads','leads.lead_id=account_attach_notes.lead_id'); $this->db->join('users',' users.user_id=account_attach_notes.created_by','left'); $this->db->where('leads.lead_id',$lead_id); $this->db->where('account_attach_notes.notes_from','Lead'); $query=$this->db->get(); return $query->result(); } public function get_potentails_notes_details($lead_id) { $this->db->select('*,account_attach_notes.created_at as c_date'); $this->db->from('account_attach_notes'); $this->db->join('new_potential','new_potential.potential_id=account_attach_notes.lead_id'); $this->db->join('users',' users.user_id=account_attach_notes.created_by'); $this->db->where('new_potential.potential_id',$lead_id); $this->db->where('account_attach_notes.notes_from','Potential'); $query=$this->db->get(); return $query->result(); } public function get_attachment_details($lead_id) { $this->db->select('*'); $this->db->from('leads'); $this->db->join('lead_attachments','leads.lead_id=lead_attachments.lead_id'); $this->db->where('leads.lead_id',$lead_id); $query=$this->db->get(); return $query->result(); } public function single_employee_details($emp_id) { $this->db->select('*,a.email_id as eid'); $this->db->from('employees a'); $this->db->join('department b','b.department_id = a.department_id','left'); $this->db->join('designation c','c.designation_id = a.designation_id','left'); $this->db->where('a.emp_id',$emp_id); $this->db->where('a.delete_status','ACTIVE'); $query=$this->db->get(); return $query->row(); } public function employee_education_details($emp_id) { $this->db->select('*'); $this->db->from('employee_education a'); $this->db->where('a.employee_id',$emp_id); $this->db->where('a.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function update_employee_details($table,$where,$data) { $this->db->where($where); $result=$this->db->update($table,$data); return $result; } public function get_data($table,$where) { $this->db->select('*'); $this->db->from($table); $this->db->where($where); $query=$this->db->get(); return $query->result(); } public function get_data_new_invoice($table,$where) { $this->db->select('*'); $this->db->from('invoice'); $this->db->where($where); $this->db->order_by('invoice_date','desc'); $query=$this->db->get(); return $query->result(); } public function get_data_row($table,$where) { $this->db->select('*'); $this->db->from($table); $this->db->where($where); $query=$this->db->get(); return $query->row(); } public function lead_convert_status($lead_id,$data) { $this->db->where('lead_id',$lead_id); $this->db->update('leads',$data); } public function potential_convert_status($lead_id,$data) { $this->db->where('potential_id',$lead_id); $this->db->update('new_potential',$data); } public function feed_data($admin_id){ $this->db->select('feeds.*,a.user_name as sender_name,a.profile_pick,b.user_name as receiver_name,b.user_id as receiver_id'); $this->db->from('feeds','users a','users b'); $this->db->join('users a','feeds.sender_id=a.user_id'); $this->db->join('users b','feeds.receiver_id=b.user_id'); $this->db->order_by('send_date_time','DESC'); $this->db->limit(10); $this->db->where('feeds.delete_status','ACTIVE'); //$this->db->where('sender_id',$admin_id); $ijoin=$this->db->get(); return $ijoin->result(); } public function employee_list() { $this->db->select('*'); $this->db->from('employees'); $this->db->where('employees.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function get_account_notes_details($lead_id) { $this->db->select('*,account_attach_notes.created_at as c_date'); $this->db->from('new_account'); $this->db->join('account_attach_notes','new_account.account_id=account_attach_notes.lead_id'); $this->db->join('users','users.user_id=account_attach_notes.created_by','left'); $this->db->where('new_account.account_id',$lead_id); $this->db->where('account_attach_notes.notes_from','Account'); $this->db->where('new_account.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function get_contact_notes_details($id) { $this->db->select('*'); $this->db->from('account_attach_notes'); $this->db->join('new_contact','new_contact.contact_id=account_attach_notes.lead_id'); //$this->db->join('account_attach_notes','new_contact.contact_id=account_attach_notes.lead_id'); $this->db->where('account_attach_notes.notes_from','Contact'); $this->db->where('new_contact.contact_id',$id); $this->db->where('new_contact.delete_status','ACTIVE'); //$this->db->where('new_account.notes_from','Contact'); $query=$this->db->get(); return $query->result(); } public function get_account_task_details($account_id) { $this->db->select('lead_new_tasks.*'); $this->db->from('lead_new_tasks'); $this->db->join('new_account','new_account.account_id=lead_new_tasks.lead_id'); $this->db->where('lead_new_tasks.lead_id',$account_id); $this->db->where('lead_new_tasks.activity','OPEN'); $this->db->where('lead_new_tasks.details_from','Account'); $this->db->where('lead_new_tasks.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function get_acc_closed_details($lead_id) { $this->db->select('lead_new_tasks.*'); $this->db->from('lead_new_tasks'); //$this->db->join('lead_new_calls','leads.lead_id=lead_new_calls.lead_id'); // $this->db->join('lead_new_events','leads.lead_id=lead_new_events.lead_id'); $this->db->join('new_account','new_account.account_id=lead_new_tasks.lead_id'); $this->db->where('new_account.account_id',$lead_id); $this->db->where('lead_new_tasks.details_from','Account'); $this->db->where('lead_new_tasks.activity','CLOSE'); //$this->db->where('lead_new_tasks.delete_status','INACTIVE'); $query=$this->db->get(); return $query->result(); } public function get_acc_attachment_details($lead_id) { $this->db->select('*'); $this->db->from('new_account'); $this->db->join('lead_attachments','new_account.account_id=lead_attachments.lead_id'); $this->db->where('new_account.account_id',$lead_id); $query=$this->db->get(); return $query->result(); } public function edit_quotation($quotation_id) { $this->db->select('*'); $this->db->from('quotations'); $this->db->where('quotations.quotation_id',$quotation_id); $this->db->where('quotations.delete_status','ACTIVE'); $query=$this->db->get(); return $query->row(); } public function update_quotation($quotation_id,$lead_id,$quotation_details) { $this->db->select('*'); $this->db->from('leads'); $this->db->join('quotations','leads.lead_id=quotations.lead_id'); $this->db->where('quotations.quotation_id',$quotation_id); $this->db->where('quotations.delete_status','ACTIVE'); $this->db->update('quotations',$quotation_details); } public function replace_image($user_ids,$image_details){ $this->db->where('users.user_id',$user_ids); $result=$this->db->update('users',$image_details); if($result){ return 1; } else{ return 0; } } public function lead_replace_image($lead_ids,$image_details){ $this->db->where('leads.lead_id',$lead_ids); $result=$this->db->update('leads',$image_details); if($result){ return 1; } else{ return 0; } } public function company_details_update($ids,$company_details_update){ $this->db->where('company_details.company_id',$ids); $result=$this->db->update('company_details',$company_details_update); if($result){ return 1; } else { return 0; } } public function fetch_company_details(){ $this->db->select('*'); $this->db->from('company_details'); $result=$this->db->get(); return $result->row(); } public function company_logo($cmp_ids,$company_image){ $this->db->where('company_details.company_id',$cmp_ids); $result=$this->db->update('company_details',$company_image); if($result){ return 1; } else{ return 0; } } public function comment_feeds($comment_details) { $result=$this->db->insert('feeds_comment',$comment_details); if($result){ return 1; } else { return 0; } } public function edit_emp_details($emp_id) { $this->db->select('*'); $this->db->from('employees'); $this->db->where('employees.emp_id',$emp_id); $this->db->where('employees.delete_status','ACTIVE'); $query=$this->db->get(); return $query->row(); } public function delete_detail($where,$data,$table) { $this->db->where($where); $result=$this->db->update($table,$data); return $result; } public function update_employee($emp_id,$employee_details) { //$this->db->select('*'); //$this->db->from('employees'); $this->db->where('employees.emp_id',$emp_id); $this->db->where('employees.delete_status','ACTIVE'); $this->db->update('employees',$employee_details); } public function user_name_authentication($user_name){ $this->db->select('*'); $this->db->from('employees'); $this->db->where('employees.first_name',$user_name); $this->db->where('employees.delete_status','ACTIVE'); $result=$this->db->get(); return $result->row(); } public function update_emp_password($email,$data){ $this->db->where('email',$email); $this->db->update('users',$data); } public function single_quotation_update($quotation_id,$quotation_details) { $this->db->select('*'); $this->db->from('quotations'); //$this->db->join('quotations','leads.lead_id=quotations.lead_id'); $this->db->where('quotations.quotation_id',$quotation_id); $this->db->where('quotations.delete_status','ACTIVE'); $this->db->update('quotations',$quotation_details); } public function users_email_authentication($email_authentication){ $this->db->select('*'); $this->db->from('users'); $this->db->where('users.email',$email_authentication); $this->db->where('users.delete_status','ACTIVE'); $result=$this->db->get(); return $result->result(); } public function verify_email($email) { $this->db->select('*'); $this->db->from('users'); $this->db->where('users.email',$email); $this->db->where('users.delete_status','ACTIVE'); $result=$this->db->get(); $row=$result->row(); if($row) { $user_id = $row->user_id; return $user_id; }else{ return 0; } } public function update_password($user_id,$password_details) { $this->db->select('*'); $this->db->from('users'); $this->db->where('users.user_id',$user_id); $this->db->where('users.delete_status','ACTIVE'); $this->db->update('users',$password_details); } //////////////////////////////////////////// ACCESS CONTROLL //////////////////////////////////////////////////////////// public function get_all_menu_data() { $this->db->select('A.*'); $this->db->from('yaskawa_menu A'); $this->db->where('A.parent_id','0'); $this->db->where('A.delete_status','ACTIVE'); $result = $this->db->get(); $result = $result->result(); $array = array(); foreach($result as $val) { $data['menu_id'] = $val->menu_id; $data['menu_name'] = $val->menu_name; $data['parent_id'] = $val->parent_id; $this->db->select('B.*'); $this->db->from('yaskawa_menu B'); $this->db->where('B.delete_status','ACTIVE'); $this->db->where('B.parent_id !=','0'); $this->db->where('B.parent_id',$val->menu_id); $menu_result = $this->db->get(); $menu_result = $menu_result->result(); $arr = array(); foreach ($menu_result as $key => $value) { $sub_menu=$value->menu_name; $sub_menu_id=$value->menu_id; $this->db->select('c.*'); $this->db->from('yaskawa_menu c'); $this->db->where('c.delete_status','ACTIVE'); $this->db->where('c.parent_id !=','0'); $this->db->where('c.parent_id',$value->menu_id); $child = $this->db->get(); $child_result= $child->result(); if($child_result!=''){ $res['sub_menu']= $sub_menu; $res['sub_menu_id']= $sub_menu_id; $res['child']= $child_result; }else{ $res['sub_menu']= $sub_menu; $res['sub_menu_id']= $sub_menu_id; $res['child']= "null"; } array_push($arr,$res); } $data['sub']=$arr; array_push($array,$data); } return $array; } public function get_all_departments_data() { $this->db->select('*'); $this->db->from('roles'); $this->db->where('delete_status','ACTIVE'); $result = $this->db->get(); return $result->result(); } public function get_where_row($table,$where) { $this->db->select('*'); $this->db->from($table); $this->db->where($where); $query=$this->db->get(); return $query->row(); } public function get_where_result($table,$where) { $this->db->select('*'); $this->db->from($table); $this->db->where($where); $query=$this->db->get(); return $query->result(); } public function update_access($where,$table,$data) { $this->db->where($where); $this->db->update($table,$data); } public function insert_access($table,$data) { $this->db->insert($table,$data); return $this->db->insert_id(); } public function get_access_list() { $this->db->select('A.*,B.*'); $this->db->from('swansilk_access_controls A'); $this->db->join('swansilk_user_type B','B.user_type_id=A.department_id'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('B.delete_status','ACTIVE'); $result = $this->db->get(); $result = $result->result(); $array = array(); foreach($result as $val) { $data['department_id'] = $val->department_id; $data['department'] = $val->user_type; $this->db->select('C.menu_id'); $this->db->from('swansilk_access_controls C'); $this->db->where('C.department_id',$val->department_id); $this->db->where('C.delete_status','ACTIVE'); $menu = $this->db->get(); $menu = $menu->row(); if($menu) { $result=explode(",",$menu->menu_id); foreach($result as $res) { $sub_res[]=explode(",",$res); } $data['menu'] = $sub_res; } else { $data['menu'] = ''; } array_push($array,$data); } return $array; } public function get_all_staff() { $this->db->select('A.username,A.id,B.user_type'); $this->db->from('employee_details A'); $this->db->join('swansilk_user_type B','B.user_type_id=A.user_type_id'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('B.delete_status','ACTIVE'); $result = $this->db->get(); return $result->result(); } public function fetch_where_data($table,$where) { $this->db->select('*'); $this->db->from($table); $this->db->where($where); $result = $this->db->get(); return $result->result(); } public function verify_lead_email_id($email) { $this->db->select('*'); $this->db->from('leads'); $this->db->where('leads.email',$email); $this->db->where('leads.delete_status','ACTIVE'); $result=$this->db->get(); return $result->result(); } public function verify_employee_email_id($email) { $this->db->select('*'); $this->db->from('employees'); $this->db->where('employees.email_id',$email); $this->db->where('employees.delete_status','ACTIVE'); $result=$this->db->get(); return $result->result(); } public function add_new_roles1($report_to){ $this->db->select('*'); $this->db->from('roles'); $this->db->where('roles.role_name',$report_to); $result=$this->db->get(); return $result->row(); } public function add_new_roles2(){ $this->db->select('*'); $this->db->from('roles'); $this->db->group_by('role_name'); $result=$this->db->get(); return $result->result(); } public function tree_structure() { $this->db->select('*'); $this->db->from('roles'); $this->db->where('roles.report_to',0); $result=$this->db->get(); $result= $result->row(); $array=array();$member_array=array(); if( $result){ $data['id'] = $result->role_id; $data['parentId'] = null; $data['name'] = $result->role_name; array_push($array, $data); } $this->db->select('*'); $this->db->from('roles'); $this->db->where('roles.parent_id',$result->role_id); $result1=$this->db->get(); $result1= $result1->result(); foreach($result1 as $val){ $data1['id'] = $val->role_id; $data1['parentId'] = $val->report_to; $data1['name'] = $val->role_name; array_push($member_array,$data1); } $array_result = array_merge($array,$member_array); return $array_result; } public function add_new_roles_check($report_to){ $this->db->select('*'); $this->db->from('roles'); $this->db->where('roles.role_name',$report_to); $result=$this->db->get(); return $result->row(); } public function get_roles() { $this->db->select('*'); $this->db->from('roles'); $this->db->where('roles.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function update_company_details($id,$company_details) { $this->db->where('company_id',$id); $result=$this->db->update('company_details',$company_details); if($result){ return 1; } else { return 0; } } public function get_all_roles_admin() { $this->db->select('*'); $this->db->from('roles'); //$this->db->where('roles.role_id','asce'); $this->db->where('roles.delete_status','ACTIVE'); $this->db->group_by('role_name'); $query=$this->db->get(); return $query->result(); } public function get_all_roles_region() { $this->db->select('*'); $this->db->from('roles'); $this->db->where('roles.delete_status','ACTIVE'); $this->db->where('roles.zone!=',''); $this->db->group_by('role_name'); $query=$this->db->get(); return $query->result(); } public function Acc_contents($table,$where) { $this->db->select('*'); $this->db->from($table); $this->db->where($where); $query=$this->db->get(); return $query->result(); } public function Acc_favorite_reports() { $this->db->select('*'); $this->db->from('acc_report_menu'); $this->db->where('acc_favorite_report','yes'); $query=$this->db->get(); return $query->result(); } public function acc_get_alldata($table,$where) { $this->db->select('*'); $this->db->from($table); $this->db->where($where); $query=$this->db->get(); return $query->result(); } /*public function acc_todays_leads_list() { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d'); $this->db->select('*'); $this->db->from('leads'); $this->db->where('lead_status','CONVERTED'); //$this->db->where('created_at',$created_at); $query=$this->db->get(); return $query->result(); }*/ public function acc_leads_by_status() { $this->db->select('A.*,B.*'); $this->db->from('leads A'); $this->db->join('users B','A.lead_owner =B.user_id'); $this->db->where('lead_status','CONVERTED'); //$this->db->where('created_at',$created_at); $this->db->group_by('lead_status'); $query=$this->db->get(); return $query->result(); } public function acc_leads_by_industry() { $this->db->select('A.*,B.*'); $this->db->from('leads A'); $this->db->join('users B','B.user_id = A.lead_owner'); $this->db->where('lead_status','CONVERTED'); $query=$this->db->get(); return $query->result(); } public function acc_sales_source() { $this->db->select('A.*,B.*'); $this->db->from('leads A'); $this->db->join('users B','A.lead_owner = B.user_id'); $this->db->where('A.lead_status','CONVERTED'); $query=$this->db->get(); return $query->result(); } public function acc_sales_across_owner() { $this->db->select("B.*,lead_owner,count('lead_id') as count"); $this->db->from('leads A'); $this->db->join('users B','B.user_id = A.lead_owner'); $this->db->where('A.lead_status','CONVERTED'); $this->db->group_by('A.lead_owner'); $result=$this->db->get(); return $result->result(); } public function acc_converted_leads() { $this->db->select('*,a.last_name as ln,b.*'); $this->db->from('leads a'); //$this->db->where('MONTH(created_at)',$created_at); $this->db->join('users b','b.user_id = a.lead_owner'); $this->db->where('a.lead_status','CONVERTED'); $query=$this->db->get(); return $query->result(); } public function acc_todays_sales() { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d'); $this->db->select('A.*,B.*,A.created_at as created,A.email as mails'); $this->db->from('leads A'); $this->db->join('users B','A.lead_owner = B.user_id'); $this->db->where('A.lead_status','CONVERTED'); $this->db->where('A.converted_at',$created_at); $this->db->where('annual_revenue >',0); $query=$this->db->get(); return $query->result(); } public function acc_month_sale() { $date= new DateTime('now', new DateTimeZone('Asia/Kolkata')); $created_at = $date->format('m'); $this->db->select('*'); $this->db->from('leads'); $this->db->where('lead_status','CONVERTED'); //$this->db->where('MONTH(created_at)',$created_at); $this->db->where('annual_revenue >',0); $query=$this->db->get(); return $query->result(); } public function acc_task($lead_id) { $this->db->select('*'); $this->db->from('leads'); $this->db->join('lead_new_tasks','leads.lead_id=lead_new_tasks.lead_id'); $this->db->where('lead_status','CONVERTED'); $this->db->where('leads.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function acc_call_status($lead_id) { $this->db->select('*,A.last_name as ln '); $this->db->from('leads A'); //$this->db->join('lead_new_events','leads.lead_id=lead_new_events.lead_id'); $this->db->join('lead_new_tasks B','B.lead_id=A.lead_id'); $this->db->where('A.lead_status','CONVERTED'); $this->db->where('B.type','Call'); $this->db->where('A.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function acc_sales_across_source(){ $this->db->select("lead_owner,count('lead_id') as count"); $this->db->from('leads'); $this->db->where('lead_status','CONVERTED'); $this->db->where('lead_source','Just Dial'); $this->db->group_by('lead_owner'); $result=$this->db->get(); return $result->result(); } public function acc_update_favorite_reports($acc_report_id,$data) { $this->db->where('acc_report_menu.acc_report_id',$acc_report_id); $this->db->where('acc_report_menu.report_status','ACTIVE'); $this->db->update('acc_report_menu',$data); } public function feeds_update_status($feeds_id,$dat) { $this->db->where('feeds_id',$feeds_id); $this->db->update('feeds',$dat); } public function get_quotations() { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $today = $date->format('Y-m-d'); $this->db->select('A.*,B.*'); $this->db->from('quotations A'); $this->db->join('leads A','B.lead_id=A.lead_id'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('B.delete_status','ACTIVE'); $this->db->where('DATE(A.created_at)',$today); $this->db->order_by('A.quotation_id','DESC'); $result = $this->db->get(); return $result->result(); } public function get_todays_notifications() { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $today = $date->format('Y-m-d'); $this->db->select('A.*,B.*'); $this->db->from('leads A'); $this->db->join('users B ','B.user_id = A.lead_owner'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('A.lead_status !=','CONVERTED'); $this->db->where('DATE(A.created_at)',$today); $this->db->order_by('A.lead_id','DESC'); $result = $this->db->get(); return $result->result(); } public function get_alldays_notifications() { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $today = $date->format('Y-m-d'); $this->db->select('A.*,B.*'); $this->db->from('leads A'); $this->db->join('users B ','B.users_id = A.lead_owner'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('A.lead_status !=','CONVERTED'); $this->db->order_by('A.lead_id','DESC'); $result = $this->db->get(); return $result->result(); } public function get_thisweek_notifications($array) { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $today = $date->format('Y-m-d'); $this->db->select('A.*,B.*'); $this->db->from('leads A'); $this->db->join('users B','B.user_id = A.lead_owner'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('A.lead_status !=','CONVERTED'); $this->db->order_by('A.lead_id','DESC'); $this->db->where_in('DATE(A.created_at)',$array); $result = $this->db->get(); return $result->result(); } public function getacc_todays_notifications() { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $today = $date->format('Y-m-d'); $this->db->select('A.*'); $this->db->from('leads A'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('A.lead_status','CONVERTED'); $this->db->where('DATE(A.created_at)',$today); $this->db->order_by('A.lead_id','DESC'); $result = $this->db->get(); return $result->result(); } public function getacc_alldays_notifications() { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $today = $date->format('Y-m-d'); $this->db->select('A.*,B.*'); $this->db->from('leads A'); $this->db->join('users B','B.user_id = A.lead_owner'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('A.lead_status','CONVERTED'); $this->db->order_by('A.lead_id','DESC'); $result = $this->db->get(); return $result->result(); } public function getacc_thisweek_notifications($array) { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $today = $date->format('Y-m-d'); $this->db->select('A.*,B.*'); $this->db->from('leads A'); $this->db->join('users B','A.lead_owner = B.user_id'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('A.lead_status','CONVERTED'); $this->db->order_by('A.lead_id','DESC'); $this->db->where_in('DATE(A.created_at)',$array); $result = $this->db->get(); return $result->result(); } public function getquot_todays_notifications() { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $today = $date->format('Y-m-d'); $this->db->select('A.*,B.*'); $this->db->from('quotations A'); $this->db->join('leads B','B.lead_id=A.lead_id'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('A.convert_status !=','CONVERTED'); $this->db->where('B.delete_status','ACTIVE'); $this->db->where('DATE(A.created_at)',$today); $this->db->order_by('A.quotation_id','DESC'); $result = $this->db->get(); return $result->result(); } public function getquot_alldays_notifications() { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $today = $date->format('Y-m-d'); $this->db->select('A.*,B.*'); $this->db->from('quotations A'); $this->db->join('leads B','B.lead_id=A.lead_id'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('B.delete_status','ACTIVE'); $this->db->where('A.convert_status !=','CONVERTED'); //$this->db->where('DATE(A.created_at)',$today); $this->db->order_by('A.quotation_id','DESC'); $result = $this->db->get(); return $result->result(); } public function getquot_thisweek_notifications($array) { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $today = $date->format('Y-m-d'); $this->db->select('A.*,B.*'); $this->db->from('quotations A'); $this->db->join('leads B','B.lead_id=A.lead_id'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('A.convert_status !=','CONVERTED'); $this->db->where('B.delete_status','ACTIVE'); $this->db->where_in('DATE(A.created_at)',$array); $this->db->order_by('A.quotation_id','DESC'); $result = $this->db->get(); return $result->result(); } public function getinv_todays_notifications() { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $today = $date->format('Y-m-d'); $this->db->select('A.*,B.*'); $this->db->from('quotations A'); $this->db->join('leads B','B.lead_id=A.lead_id'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('A.convert_status','CONVERTED'); $this->db->where('B.delete_status','ACTIVE'); $this->db->where('DATE(A.created_at)',$today); $this->db->order_by('A.quotation_id','DESC'); $result = $this->db->get(); return $result->result(); } public function getinv_alldays_notifications() { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $today = $date->format('Y-m-d'); $this->db->select('A.*,B.*'); $this->db->from('quotations A'); $this->db->join('leads B','B.lead_id=A.lead_id'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('A.convert_status','CONVERTED'); $this->db->where('B.delete_status','ACTIVE'); $this->db->order_by('A.quotation_id','DESC'); $result = $this->db->get(); return $result->result(); } public function getinv_thisweek_notifications($array) { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $today = $date->format('Y-m-d'); $this->db->select('A.*,B.*'); $this->db->from('quotations A'); $this->db->join('leads B','B.lead_id=A.lead_id'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('A.convert_status','CONVERTED'); $this->db->where('B.delete_status','ACTIVE'); $this->db->where_in('DATE(A.created_at)',$array); $this->db->order_by('A.quotation_id','DESC'); $result = $this->db->get(); return $result->result(); } public function get_user_details() { $this->db->select('*'); $this->db->from('users'); $this->db->where('users.user_type_id!=','1'); $this->db->where('users.delete_status','ACTIVE'); $this->db->where('users.role_id !=','68'); $query=$this->db->get(); return $query->result(); } public function get_user_details1($id) { $this->db->select('*'); $this->db->from('users'); $this->db->join('new_contact','new_contact.contact_owner = users.user_id'); $this->db->where('new_contact.contact_id',$id); $this->db->where('users.user_type_id!=','1'); $this->db->where('users.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function get_user_details2($id) { $this->db->select('*'); $this->db->from('users'); $this->db->join('new_account','new_account.account_owner = users.user_id'); $this->db->where('new_account.account_id',$id); $this->db->where('users.user_type_id!=','1'); $this->db->where('users.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function get_user_details3($id) { $this->db->select('*'); $this->db->from('users'); $this->db->join('new_potential','new_potential.potential_owner = users.user_id'); $this->db->where('new_potential.potential_id',$id); $this->db->where('users.user_type_id!=','1'); $this->db->where('users.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function get_user_details4($id) { $this->db->select('*'); $this->db->from('users'); $this->db->join('leads','leads.lead_owner = users.user_id'); $this->db->where('leads.lead_id',$id); $this->db->where('users.user_type_id!=','1'); $this->db->where('users.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function get_lead_source_details() { $this->db->select('*'); $this->db->from('lead_source'); $this->db->where('lead_source.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function get_lead_status_details() { $this->db->select('*'); $this->db->from('lead_status'); $this->db->where('lead_status.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function get_lead_industry_details() { $this->db->select('*'); $this->db->from('masters'); $this->db->where('masters.master_type_id','12'); $this->db->where('masters.delete_status','ACTIVE'); $query=$this->db->get(); return $query->row(); } public function get_lead_ratings_details() { $this->db->select('*'); $this->db->from('masters'); $this->db->where('masters.delete_status','ACTIVE'); $this->db->where('masters.master_type_id','11'); $query=$this->db->get(); return $query->row(); } public function get_account_type() { $this->db->select('*'); $this->db->from('account_type'); $this->db->where('account_type.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function get_honorific(){ $this->db->select('*'); $this->db->from('honorific'); $this->db->where('honorific.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function get_customer_type(){ $this->db->select('*'); $this->db->from('customer_type'); $this->db->where('customer_type.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function get_lead_process(){ $this->db->select('*'); $this->db->from('lead_process'); $this->db->where('lead_process.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function smr_data_filter($created_at){ $this->db->select('*'); $this->db->from('leads'); $this->db->where('MONTH(created_at)',$created_at); $this->db->where('leads.lead_status','CONVERTED'); $result=$this->db->get(); return $result->result(); } public function today_leads(){ $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d'); $this->db->select('*'); $this->db->from('leads'); $this->db->where('leads.created_at',$created_at); $result=$this->db->get(); return $result->result(); } public function open_tasks(){ $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d'); $this->db->select('*'); $this->db->from('lead_new_tasks','leads'); $this->db->join('leads','leads.lead_id=lead_new_tasks.lead_id'); $this->db->where('lead_new_tasks.created_at',$created_at); $this->db->where('lead_new_tasks.delete_status','ACTIVE'); $result=$this->db->get(); return $result->result(); } public function social_media($ids,$social_media_update){ $this->db->where('users.user_id',$ids); $result=$this->db->update('users',$social_media_update); if($result){ return 1; } else { return 0; } } public function acc_todays_leads_list() { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $converted_at = $date->format('Y-m-d'); $this->db->select('*'); $this->db->from('leads'); $this->db->where('leads.lead_status','CONVERTED'); //$this->db->where('leads.converted_at',$converted_at); $query=$this->db->get(); return $query->result(); } public function acc_delete_report($acc_report_id,$data) { if (!empty($acc_report_id)) { $this->db->where_in('acc_report_id', $acc_report_id); $this->db->update('acc_report_menu',$data); } } public function home_accounts_list(){ // $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); // $created_at = $date->format('Y-m-d'); $this->db->select('*'); $this->db->from('new_account'); $this->db->join('users','users.user_id = new_account.account_owner '); $this->db->where('new_account.delete_status','ACTIVE'); //$this->db->where('leads.lead_status','CONVERTED'); //$this->db->order_by('created_at','DESC'); //$this->db->limit(10); $result=$this->db->get(); return $result->result(); } public function home_employee(){ $this->db->select('*,a.email_id as eid'); $this->db->from('employees a'); $this->db->join('department b','b.department_id = a.department_id '); $this->db->where('a.delete_status','Active'); $this->db->order_by('a.created_at','DESC'); $this->db->limit(5); $result=$this->db->get(); return $result->result(); } public function insert_lead_source1($data){ $result=$this->db->insert('lead_source',$data); if($result){ return 1; }else{ return 0; } } public function insert_industry1($data){ $result=$this->db->insert('lead_industry',$data); if($result){ return 1; }else{ return 0; } } public function insert_lead_status1($data){ $result=$this->db->insert('lead_status',$data); if($result){ return 1; }else{ return 0; } } public function insert_rating1($data){ $result=$this->db->insert('lead_ratings',$data); if($result){ return 1; }else{ return 0; } } public function insert_account_type1($data){ $result=$this->db->insert('account_type',$data); if($result){ return 1; }else{ return 0; } } public function insert_honorific($data){ $result=$this->db->insert('honorific',$data); if($result){ return 1; }else{ return 0; } } public function insert_customer_type($data){ $result=$this->db->insert('customer_type',$data); if($result){ return 1; }else{ return 0; } } public function insert_lead_process($data){ $result=$this->db->insert('lead_process',$data); if($result){ return 1; }else{ return 0; } } public function delete_lead_source($source_id,$data){ $this->db->where('source_id',$source_id); $result=$this->db->update('lead_source',$data); if($result){ return 1; }else{ return 0; } } public function delete_lead_industry($industry_id,$data){ $this->db->where('industry_id',$industry_id); $result=$this->db->update('lead_industry',$data); if($result){ return 1; }else{ return 0; } } public function delete_lead_status($status_id,$data){ $this->db->where('status_id',$status_id); $result=$this->db->update('lead_status',$data); if($result){ return 1; }else{ return 0; } } public function delete_rating($rating_id,$data){ $this->db->where('rating_id',$rating_id); $result=$this->db->update('lead_ratings',$data); if($result){ return 1; }else{ return 0; } } public function delete_account_type($account_id,$data){ $this->db->where('account_type_id',$account_id); $result=$this->db->update('account_type',$data); if($result){ return 1; }else{ return 0; } } public function leads_track_owners(){ $this->db->select('*'); $this->db->from('leads'); $this->db->where('leads.delete_status','ACTIVE'); $this->db->group_by('leads.lead_owner'); $result=$this->db->get(); return $result->result(); } public function lead_datas($lead_ids){ $this->db->select('*'); $this->db->from("leads"); $this->db->where('leads.lead_id',$lead_ids); $result=$this->db->get(); return $result->row(); } public function lead_details_update($lids,$lead_details_update){ $this->db->where('lead_id',$lids); $result=$this->db->update('leads',$lead_details_update); if($result){ return 1; }else{ return 0; } } public function edit_lead_source($source_id,$data){ $this->db->select('*'); $this->db->from("lead_source"); $this->db->where('lead_source.source_id',$source_id); $result=$this->db->get(); return $result->row(); } public function edit_lead_industry($industry_id,$data){ $this->db->select('*'); $this->db->from("lead_industry"); $this->db->where('lead_industry.industry_id',$industry_id); $result=$this->db->get(); return $result->row(); } public function edit_lead_status($status_id,$data){ $this->db->select('*'); $this->db->from("lead_status"); $this->db->where('lead_status.status_id',$status_id); $result=$this->db->get(); return $result->row(); } public function edit_rating($rating_id,$data){ $this->db->select('*'); $this->db->from("lead_ratings"); $this->db->where('lead_ratings.rating_id',$rating_id); $result=$this->db->get(); return $result->row(); } public function edit_account_type($account_id,$data){ $this->db->select('*'); $this->db->from("account_type"); $this->db->where('account_type.account_type_id',$account_id); $result=$this->db->get(); return $result->row(); } public function edit_honorific($honorific_id,$data){ $this->db->select('*'); $this->db->from("honorific"); $this->db->where('honorific.honorific_id',$honorific_id); $result=$this->db->get(); return $result->row(); } public function edit_customer_type($customer_type_id,$data){ $this->db->select('*'); $this->db->from("customer_type"); $this->db->where('customer_type.customer_type_id',$customer_type_id); $result=$this->db->get(); return $result->row(); } public function edit_lead_process($lead_process_id,$data){ $this->db->select('*'); $this->db->from("lead_process"); $this->db->where('lead_process.lead_process_id',$lead_process_id); $result=$this->db->get(); return $result->row(); } public function update_lead_source1($ids,$data){ $this->db->where('lead_source.source_id',$ids); $result=$this->db->update('lead_source',$data); if($result){ return 1; }else{ return 0; } } public function update_industry1($ids,$data){ $this->db->where('lead_industry.industry_id',$ids); $result=$this->db->update('lead_industry',$data); if($result){ return 1; }else{ return 0; } } public function update_lead_status1($ids,$data){ $this->db->where('lead_status.status_id',$ids); $result=$this->db->update('lead_status',$data); if($result){ return 1; }else{ return 0; } } public function update_rating1($ids,$data){ $this->db->where('lead_ratings.rating_id',$ids); $result=$this->db->update('lead_ratings',$data); if($result){ return 1; }else{ return 0; } } public function update_account_type1($ids,$data){ $this->db->where('account_type.account_type_id',$ids); $result=$this->db->update('account_type',$data); if($result){ return 1; }else{ return 0; } } public function update_honorific1($ids,$data){ $this->db->where('honorific.honorific_id',$ids); $result=$this->db->update('honorific',$data); if($result){ return 1; }else{ return 0; } } public function update_customer_type1($ids,$data){ $this->db->where('customer_type.customer_type_id',$ids); $result=$this->db->update('customer_type',$data); if($result){ return 1; }else{ return 0; } } public function update_lead_process1($ids,$data){ $this->db->where('lead_process.lead_process_id',$ids); $result=$this->db->update('lead_process',$data); if($result){ return 1; }else{ return 0; } } public function add_new_account($data){ $result=$this->db->insert('new_account',$data); $res=$this->db->insert_id(); if($result){ return $res; }else{ return 0; } } public function add_new_potential($data){ $result=$this->db->insert('new_potential',$data); return $this->db->insert_id(); } public function select_new_accounts($role_id){ $this->db->select('*,leads.company_name as acc_comp_name,leads.first_name as lead_contact_person'); $this->db->from('new_account'); $this->db->join('users','users.user_id =new_account.account_owner','left'); $this->db->join('roles','roles.role_id=new_account.role_id','left'); $this->db->join('leads','leads.lead_id=new_account.lead_id','left'); // $this->db->or_where('roles.role_id',$role_id); // $this->db->or_where('roles.parent_id',$role_id); // $this->db->or_where('roles.report_to',$role_id); $this->db->order_by('new_account.account_name','asc'); $result=$this->db->get(); return $result->result(); } public function select_new_accounts1(){ $this->db->select('*'); $this->db->from('new_account'); $this->db->join('users' ,'users.user_id = new_account.account_owner'); $this->db->join('quotations','new_account.account_id =quotations.lead_id'); $this->db->where('quotations.convert_status !=','CONVERTED'); $result=$this->db->get(); return $result->result(); } public function single_account_details($account_id) { $this->db->select('*'); $this->db->from('new_account'); $this->db->join('users','users.user_id = new_account.account_owner','left'); //$this->db->join('new_account','leads.lead_owner = new_account.account_owner'); $this->db->where('new_account.account_id',$account_id); $this->db->where('new_account.delete_status','ACTIVE'); $query=$this->db->get(); return $query->row(); } public function select_new_potential($role_id){ $this->db->select('np.*,users.*,new_account.*,np.description as desc,new_contact.*,np.potential_id as potential_id,np.city as p_city,np.address as p_address,new_account.account_name as acc_name,new_account.email_id as acc_email,np.email_id as potential_email'); $this->db->from('new_potential np'); $this->db->join('users','users.user_id = np.potential_owner'); $this->db->join('new_account','np.account_name = new_account.account_id','left'); $this->db->join('new_contact','new_contact.contact_id = np.contact_id','left'); // $this->db->join('roles','roles.role_id=new_potential.role_id','left'); // $this->db->or_where('roles.role_id',$role_id); // $this->db->or_where('roles.parent_id',$role_id); // $this->db->or_where('roles.report_to',$role_id); $this->db->where('np.delete_status','ACTIVE'); $result=$this->db->get(); return $result->result(); } /* public function potential_related($id ){ $this->db->select('*'); $this->db->from('new_account'); $this->db->join('new_potential','new_potential.account_name = new_account.account_id'); $this->db->where('new_account.account_id',$id); $result=$this->db->get(); return $result->result(); }*/ public function contact_related($id){ $this->db->select('*'); $this->db->from('new_account'); $this->db->join('new_contact','new_contact.account_name = new_account.account_id'); $this->db->where('new_account.account_id',$id); $result=$this->db->get(); return $result->result(); } public function accounts_details_update($acc_lids,$data){ $this->db->where('account_id',$acc_lids); $result=$this->db->update('new_account',$data); if($result){ return 1; }else{ return 0; } } public function add_new_contact($data){ $result=$this->db->insert('new_contact',$data); if($result){ return 1; }else{ return 0; } } public function contact_list($role_id){ $this->db->select('*'); $this->db->from('new_contact'); $this->db->join('users','users.user_id = new_contact.contact_owner'); $this->db->join('new_account',' new_account.account_name = new_contact.account_id'); // $this->db->join('new_account','new_account.account_id =new_contact.account_name'); $this->db->join('roles','roles.role_id=new_contact.role_id'); $this->db->or_where('roles.role_id',$role_id); $this->db->or_where('roles.parent_id',$role_id); $this->db->or_where('roles.report_to',$role_id); $result=$this->db->get(); return $result->result(); } public function contact_list1($id){ $this->db->select('*'); $this->db->from('new_potential'); $this->db->join('users','new_potential.potential_owner = users.user_id'); $this->db->join('new_contact','new_contact.contact_owner = new_potential.potential_owner '); $this->db->where('new_potential.potential_id',$id); $result=$this->db->get(); return $result->result(); } public function single_contact_details($contact_id) { $this->db->select('new_contact.*,new_contact.last_name as l_name,new_contact.name_type as n_type,new_contact.phone as c_phone,users.user_name,new_account.account_name'); $this->db->from('new_contact'); $this->db->where('new_contact.contact_id',$contact_id); $this->db->join('users','users.user_id = new_contact.contact_owner'); $this->db->join('new_account','new_account.account_id = new_contact.account_name','left'); $this->db->where('new_contact.delete_status','ACTIVE'); $query=$this->db->get(); return $query->row(); } public function contact_details_update($cont_lids,$data){ $this->db->where('contact_id',$cont_lids); $result=$this->db->update('new_contact',$data); if($result){ return 1; }else{ return 0; } } public function single_potential_details($potential_id) { $this->db->select('*,np.description as desc,np.type as business,np.email_id as email,np.website as p_website,np.annual_revenue as p_annual_revenue,np.fax as p_fax,np.address as p_address,np.street as p_street,np.city as p_city,np.state as p_state,np.zip_code as p_zip_code,np.country as p_country,np.service_name as s_name,np.service_date as s_date,np.service_amount as s_amount,np.account_name as acc_name,np.industry as indu'); $this->db->from('new_potential np'); $this->db->join('users','users.user_id = np.potential_owner'); $this->db->join('new_account','new_account.account_id = np.account_name','left outer'); $this->db->where('np.potential_id',$potential_id); $this->db->where('np.delete_status','ACTIVE'); $query=$this->db->get(); return $query->row(); } public function single_potential_details_potential($potential_id) { $this->db->select('*,np.description as desc,np.type as business,np.email_id as email,np.website as p_website,np.annual_revenue as p_annual_revenue,np.fax as p_fax,np.address as p_address,np.street as p_street,np.city as p_city,np.state as p_state,np.zip_code as p_zip_code,np.country as p_country,np.service_name as s_name,np.service_date as s_date,np.service_amount as s_amount,np.account_name as acc_name,np.industry as indu,np.designation as p_designation'); $this->db->from('new_potential np'); $this->db->join('users','users.user_id = np.potential_owner'); $this->db->join('new_account','new_account.account_id = np.account_name','left outer'); $this->db->where('np.potential_id',$potential_id); $this->db->where('np.delete_status','ACTIVE'); $query=$this->db->get(); return $query->row(); } public function potential_details_update($pot_lids,$data){ $this->db->where('potential_id',$pot_lids); $result=$this->db->update('new_potential',$data); if($result){ return 1; }else{ return 0; } } public function contact_attachments($data){ $result=$this->db->insert("contact_attachments",$data); if($result){ return 1; }else{ return 0; } } public function contact_attachments1($id){ $this->db->select("*"); $this->db->from('new_contact'); $this->db->join('contact_attachments','new_contact.contact_id = contact_attachments.contact_id'); $this->db->where('new_contact.contact_id',$id); $this->db->where('contact_attachments.delete_status','ACTIVE'); $result=$this->db->get(); return $result->result(); } public function contact_activities($data){ $result=$this->db->insert("contact_activities",$data); if($result){ return 1; }else{ return 0; } } public function contact_activities1($id){ $this->db->select("*"); $this->db->from('new_contact'); $this->db->join('contact_activities','new_contact.contact_id = contact_activities.contact_id'); $this->db->where('new_contact.contact_id',$id); $this->db->where('contact_activities.delete_status','ACTIVE'); $result=$this->db->get(); return $result->result(); } public function contact_closed($id,$data) { $this->db->where('cactivities_id',$id); $this->db->update('contact_activities',$data); } public function get_row1($id) { $this->db->select('*'); $this->db->from('contact_activities'); $this->db->where('cactivities_id',$id); $query=$this->db->get(); return $query->row(); } public function contact_closed_details($contact_id) { $this->db->select('*'); $this->db->from('new_contact'); $this->db->join('contact_activities','new_contact.contact_id=contact_activities.contact_id'); $this->db->where('new_contact.contact_id',$contact_id); $this->db->where('contact_activities.delete_status','CLOSE'); $query=$this->db->get(); return $query->result(); } public function potential_attachments($data){ $result=$this->db->insert("potential_attachments",$data); if($result){ return 1; }else{ return 0; } } public function potential_attachments1($id){ $this->db->select("*"); $this->db->from('new_potential'); $this->db->join('potential_attachments','new_potential.potential_id = potential_attachments.potential_id'); $this->db->where('new_potential.potential_id',$id); $this->db->where('new_potential.delete_status','ACTIVE'); $result=$this->db->get(); return $result->result(); } public function potential_activities($data){ $result=$this->db->insert("lead_new_tasks",$data); $datas= $this->db->insert_id(); if($result){ return $datas; }else{ return 0; } } public function potential_activities1($id){ $this->db->select("lead_new_tasks.*"); $this->db->from('lead_new_tasks'); $this->db->join('new_potential','new_potential.potential_id = lead_new_tasks.lead_id'); $this->db->where('new_potential.potential_id',$id); $this->db->where('lead_new_tasks.activity !=','CLOSE'); $this->db->where('lead_new_tasks.details_from','Potential'); $this->db->where('new_potential.delete_status','ACTIVE'); $result=$this->db->get(); return $result->result(); } public function potential_closed($id,$data) { $this->db->where('task_id',$id); $this->db->update('lead_new_tasks',$data); } public function update_user($id,$data) { $this->db->where('user_id',$id); return $this->db->update('users',$data); } public function get_row2($id) { $this->db->select('*'); $this->db->from('lead_new_tasks'); $this->db->where('lead_id',$id); $this->db->where('lead_new_tasks.activity','CLOSE'); $this->db->where('lead_new_tasks.delete_status','ACTIVE'); $query=$this->db->get(); return $query->row(); } public function potential_closed_details($potential_id) { $this->db->select('lead_new_tasks.*'); $this->db->from('lead_new_tasks'); $this->db->join('new_potential','new_potential.potential_id=lead_new_tasks.lead_id'); $this->db->where('new_potential.potential_id',$potential_id); $this->db->where('lead_new_tasks.activity','CLOSE'); $this->db->where('lead_new_tasks.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function potential_competitor($competitor){ $result=$this->db->insert('potential_competitor',$competitor); if($result){ return 1; }else{ return 0; } } public function potential_competitor1($id){ $this->db->select('*'); $this->db->from('new_potential'); $this->db->join('potential_competitor','new_potential.potential_id=potential_competitor.potential_id'); $this->db->where('new_potential.potential_id',$id); $this->db->where('new_potential.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function quick_contact1($id){ $this->db->select('*'); $this->db->from('new_potential'); $this->db->join('quick_contact','new_potential.potential_id=quick_contact.potential_id'); $this->db->where('quick_contact.potential_id',$id); $this->db->where("new_potential.delete_status","ACTIVE"); $result=$this->db->get(); return $result->result(); } public function quick_contact2($potential_id) { $this->db->select('*'); $this->db->from('new_potential'); $this->db->join('new_contact','new_contact.potential_id=new_potential.potential_id'); $this->db->join('new_account','new_account.account_id=new_potential.potential_id'); $this->db->where('new_potential.potential_id',$potential_id); $this->db->where("new_potential.delete_status","ACTIVE"); $result=$this->db->get(); return $result->result(); } public function contact_update($account_id,$data){ $this->db->where('new_account.account_id',$account_id); $result=$this->db->update('new_account',$data); if($result){ return 1; }else{ return 0; } } public function potential_search($search){ $this->db->select('*'); $this->db->from('new_account'); $this->db->or_like('new_account.account_name', $search); $this->db->or_like('new_account.phone', $search); $this->db->or_like('new_account.website', $search); $this->db->or_like('new_account.account_owner', $search); $this->db->where("new_account.delete_status","ACTIVE"); $result=$this->db->get(); return $result->result(); } public function update_edit_mapping($contactids,$contact_roles){ foreach($contactids as $contact=>$ids){ $this->db->where('account_id', $contactids[$contact]); $data=array('contact_roles'=>$contact_roles[$contact]); $result=$this->db->update('new_account',$data); } } public function account_name_search($keyword) { $this->db->distinct(); $this->db->select('account_name'); //$this->db->order_by('customer_name', 'DESC'); $this->db->like("account_name", $keyword); $this->db->from('new_account'); $query= $this->db->get(); return $query->result(); } public function stage_master_update($data){ $result=$this->db->insert('stage_master',$data); if($result){ return 1; }else{ return 0; } } public function stage_master_update1($id){ $this->db->select('*'); $this->db->from('new_potential'); $this->db->join('users','users.user_id = new_potential.potential_owner'); $this->db->join('stage_master','new_potential.potential_id=stage_master.potential_id'); $this->db->where('stage_master.potential_id',$id); $this->db->order_by('stage_master.modified_time','desc'); $this->db->where('new_potential.delete_status','ACTIVE'); $result= $this->db->get(); return $result->result(); } public function get_role_details($role){ $this->db->select(); $this->db->from('roles'); $this->db->where('roles.role_name',$role); $result=$this->db->get(); return $result->row(); } public function individual_sales($admin_id){ $this->db->select('*,SUM(quotations.sub_total) as amount'); $this->db->from('users'); $this->db->join('new_account','new_account.account_owner = users.user_id'); $this->db->join('quotations','quotations.lead_id = new_account.account_id'); $this->db->where('quotations.convert_status','CONVERTED'); $this->db->group_by('quotations.lead_id'); $result=$this->db->get(); return $result->result(); } public function industry_wise_sales($role_id){ $this->db->select('*,SUM(quotations.amount) as amount'); $this->db->from('users'); $this->db->join('new_account','new_account.account_owner = users.user_id'); $this->db->join('quotations','quotations.lead_id = new_account.account_id'); $this->db->where('quotations.convert_status','CONVERTED'); $this->db->group_by('quotations.lead_id'); $result=$this->db->get(); return $result->result(); } public function region_wise_sales($role_id){ $this->db->select('*,SUM(quotations.amount) as amount'); $this->db->from('users'); $this->db->join('new_account','new_account.account_owner = users.user_id'); $this->db->join('quotations','quotations.lead_id = new_account.account_id'); $this->db->where('quotations.convert_status','CONVERTED'); $this->db->group_by('quotations.lead_id'); $result=$this->db->get(); return $result->result(); } public function total_sales($where){ $this->db->select('invoice_amount'); $this->db->from('quotations'); $this->db->or_where('quotations.lead_id',$where); $result=$this->db->get(); return $result->result(); } public function industry_wise_filter($role_id,$indistry_name,$from_date,$to_date){ $this->db->select('*,SUM(quotations.invoice_amount) as amount'); $this->db->from('users'); $this->db->join('new_account','new_account.account_owner = users.user_id'); $this->db->join('quotations','quotations.lead_id = new_account.account_id'); $this->db->where('quotations.created_at >=',$from_date); $this->db->where('quotations.created_at <=',$to_date); $this->db->or_where('new_account.industry',$indistry_name); $this->db->where('quotations.convert_status','CONVERTED'); $this->db->group_by('quotations.lead_id'); // $this->db->where('new_account.role_id',$role_id); $result=$this->db->get(); return $result->result(); } public function region_wise_filter($region_wise,$from_date,$to_date){ $this->db->select('*,SUM(quotations.invoice_amount) as amount'); $this->db->from('quotations'); $this->db->where('quotations.created_at >=',$from_date); $this->db->where('quotations.created_at <=',$to_date); $this->db->or_where('new_account.role_id',$region_wise); $this->db->join('new_account','quotations.lead_id=new_account.account_id'); $this->db->where('quotations.convert_status','CONVERTED'); $this->db->group_by('quotations.lead_id'); // $this->db->where('new_account.role_id',$role_id); $result=$this->db->get(); return $result->result(); } public function individual_sales_filter($member,$from_date,$to_date){ $this->db->select('*,SUM(quotations.invoice_amount) as amount'); $this->db->from('users'); $this->db->join('new_account','new_account.account_owner = users.user_id'); $this->db->join('quotations','quotations.lead_id = new_account.account_id'); $this->db->where('quotations.invoice_date >=',$from_date); $this->db->where('quotations.invoice_date <=',$to_date); // $this->db->where('quotations.lead_id',$admin_id); $this->db->or_where('new_account.role_id',$member); $this->db->where('quotations.convert_status','CONVERTED'); $this->db->group_by('quotations.lead_id'); $result=$this->db->get(); return $result->result(); } public function update($where,$table,$data) { $this->db->where($where); $this->db->update($table,$data); return $this->db->affected_rows(); } public function account_details(){ $this->db->select('*'); $this->db->from('new_account'); $this->db->join('users','users.user_id = new_account.account_owner'); $this->db->where('new_account.delete_status','ACTIVE'); $this->db->order_by('new_account.account_name','ASC'); $result=$this->db->get(); return $result->result(); } public function lead_employees(){ $this->db->select('*'); $this->db->from('users'); $this->db->join('leads','leads.lead_owner = users.user_id'); $this->db->join('lead_new_tasks','lead_new_tasks.lead_id = leads.lead_id'); // $this->db->join('lead_attachments','lead_attachments.lead_id = lead_new_tasks.lead_id'); // $this->db->join('lead_attach_notes','lead_attach_notes.lead_id = lead_attachments.lead_id'); $this->db->where('users.delete_status','ACTIVE'); $result = $this->db->get(); return $result->result(); } public function account_employees(){ $this->db->select('*'); $this->db->from('users'); $this->db->join('new_account','new_account.account_owner = users.user_id'); $this->db->join('lead_new_tasks','lead_new_tasks.lead_id = new_account.account_id'); $this->db->where('users.delete_status','ACTIVE'); $result = $this->db->get(); return $result->result(); } public function potential_employees(){ $this->db->select('*'); $this->db->from('users'); $this->db->join('new_potential','new_potential.potential_owner = users.user_id'); $this->db->join('potential_activities','potential_activities.potential_id = new_potential.potential_id'); // $this->db->join('potential_attachments','potential_attachments.potential_id = potential_activities.potential_id','left outer'); $this->db->where('users.delete_status','ACTIVE'); $result = $this->db->get(); return $result->result(); } public function employee_lead_filter($employee_id){ $this->db->select('*'); $this->db->from('users'); $this->db->join('leads','leads.lead_owner = users.user_id'); $this->db->join('lead_new_tasks',' lead_new_tasks.lead_id = leads.lead_id'); $this->db->where('leads.lead_owner',$employee_id); $this->db->where('users.delete_status','ACTIVE'); $result = $this->db->get(); return $result->result(); } public function employee_account_filter($employee_id){ $this->db->select('*'); $this->db->from('users'); $this->db->join('new_account','new_account.account_owner = users.user_id'); $this->db->join('lead_new_tasks',' lead_new_tasks.lead_id = new_account.account_id'); $this->db->where('new_account.account_owner',$employee_id); $this->db->where('users.delete_status','ACTIVE'); $result = $this->db->get(); return $result->result(); } public function employee_potential_filter($employee_id){ $this->db->select('*'); $this->db->from('users'); $this->db->join('new_potential','new_potential.potential_owner = users.user_id'); $this->db->join('potential_activities',' potential_activities.potential_id = new_potential.potential_id'); $this->db->where('new_potential.potential_owner',$employee_id); $this->db->where('users.delete_status','ACTIVE'); $result = $this->db->get(); return $result->result(); } public function employee_activity_filter1($from_date,$to_date){ $this->db->select('*'); $this->db->from('users'); $this->db->join('leads','leads.lead_owner = users.user_id'); $this->db->join('lead_new_tasks','lead_new_tasks.lead_id = leads.lead_id'); $this->db->where('lead_new_tasks.created_at >=',$from_date); $this->db->where('lead_new_tasks.created_at <=',$to_date); $this->db->where('users.delete_status','ACTIVE'); $result = $this->db->get(); return $result->result(); } public function employee_activity_filter2($from_date,$to_date){ $this->db->select('*'); $this->db->from('users'); $this->db->join('new_account','new_account.account_owner = users.user_id'); $this->db->join('lead_new_tasks','lead_new_tasks.lead_id = new_account.account_id'); $this->db->where('lead_new_tasks.created_at >=',$from_date); $this->db->where('lead_new_tasks.created_at <=',$to_date); $this->db->where('users.delete_status','ACTIVE'); $result = $this->db->get(); return $result->result(); } public function employee_activity_filter3($from_date,$to_date){ $this->db->select('*'); $this->db->from('users'); $this->db->join('new_potential','new_potential.potential_owner = users.user_id'); $this->db->join('potential_activities',' potential_activities.potential_id = new_potential.potential_id'); $this->db->where('potential_activities.created_at >=',$from_date); $this->db->where('potential_activities.created_at <=',$to_date); $this->db->where('users.delete_status','ACTIVE'); $result = $this->db->get(); return $result->result(); } public function role_wise_filter($role_id){ $this->db->select('*'); $this->db->from('users'); $this->db->where('users.role_id',$role_id); $result = $this->db->get(); return $result->result(); } public function employee_wise_filter($userid){ $this->db->select('*,SUM(quotations.invoice_amount) as amount'); $this->db->from('users'); $this->db->join('new_account','new_account.account_owner = users.user_id'); $this->db->join('quotations','quotations.lead_id = new_account.account_id'); $this->db->where('new_account.account_owner',$userid); $this->db->where('quotations.convert_status','CONVERTED'); $this->db->group_by('quotations.lead_id'); $result=$this->db->get(); return $result->result(); } //------------------------autocomplete part---------------------- public function autocompletesearch($keyword){ $this->db->distinct(); $this->db->select('first_name'); $this->db->order_by('first_name', 'DESC'); $this->db->like("first_name", $keyword); $this->db->from('employees'); $query= $this->db->get(); return $query->result(); } public function contact_data_to_account($account_name,$data1){ $this->db->where('account_id',$account_name); $this->db->update('new_account',$data1); } public function potential_related($id ){ $this->db->select('*'); $this->db->from('new_potential'); $this->db->join('new_account','new_potential.account_id = new_account.account_id'); $this->db->where('new_potential.account_id',$id); $result=$this->db->get(); return $result->result(); } public function contacts_lists(){ $this->db->select('*,new_account.account_name as cname,new_contact.contact_id as c_contact_id'); $this->db->from('new_contact'); $this->db->join('users','users.user_id = new_contact.contact_owner'); $this->db->join('new_account',' new_account.account_id = new_contact.account_name','left'); $result=$this->db->get(); return $result->result(); } public function fetch_assets_details(){ $this->db->select('*'); $this->db->from('assets'); $this->db->where('delete_status','ACTIVE'); $result=$this->db->get(); return $result->result(); } public function add_assets($data){ $result=$this->db->insert('assets',$data); if($result){ return 1; }else{ return 0; } } public function delete_assets($lead_id,$data) { $this->db->where('assets_id',$lead_id); $result=$this->db->update('assets',$data); return $result; } public function delete($table,$where) { $this->db->where($where); return $this->db->delete($table); } public function get_all_masters_list() { $this->db->select('A.*,B.*'); $this->db->from('masters A'); $this->db->join('master_type B','B.master_type_id=A.master_type_id'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('B.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function get_where_orderby_row($table,$where,$order_by) { $this->db->select('*'); $this->db->from($table); $this->db->where($where); $this->db->order_by($order_by,"DESC"); $query=$this->db->get(); return $query->row(); } public function get_last_master_row($table,$where,$id){ $this->db->select('*'); $this->db->from($table); $this->db->where($where); $this->db->order_by($id,"DESC"); $query=$this->db->get(); return $query->row(); } public function get_quotation_result(){ $this->db->select('*,quotations.address as quote_add,quotations.description as quote_des,quotations.sub_total as subamount,quotations.amount as q_amount'); $this->db->from('quotations'); $this->db->join('new_account','new_account.account_id=quotations.account_id','left'); $this->db->join('leads','leads.lead_id=quotations.lead_id','left'); $this->db->join('new_potential','new_potential.potential_id=quotations.potential_id','left'); // $this->db->join('masters','masters.master_id=quotations.package_id','left'); $this->db->group_by(array('quotations.quotation_id')); $this->db->where('quotations.delete_status','ACTIVE'); $this->db->order_by('quotations.quo_date','DESC'); $this->db->order_by('quotations.quotation_number','DESC'); $result=$this->db->get(); return $result->result(); } public function search_lead($val){ /*$where = " where "; $select = "Select A.*"; $from = " from leads A"; $where .= "A.delete_status='ACTIVE' and "; $where .= "A.first_name LIKE '$val%'"; $doc_sql = $select.$from.$where; $doc_result = $this->db->query($doc_sql); $doc_result = $doc_result->result(); //print_r($doc_result);die(); return $doc_result; */ // Query #1 $this->db->select('first_name, email,lead_id,l_type as type,company_name'); $this->db->from('leads'); $this->db->where('delete_status','ACTIVE'); $this->db->like('first_name', $val); $this->db->or_like('company_name', $val); $query1 = $this->db->get()->result(); // Query #2 $this->db->select('potential_name as first_name, contact_name as email,potential_id as lead_id,p_type as type'); $this->db->from('new_potential'); $this->db->where('delete_status','ACTIVE'); $this->db->like('potential_name', $val); $query2 = $this->db->get()->result(); //Query3 $this->db->select('account_name as first_name, email_id as email,account_id as lead_id,type as type'); $this->db->from('new_account'); $this->db->where('delete_status','ACTIVE'); $this->db->like('account_name', $val); $query3 = $this->db->get()->result(); // Merge both query results $querys = array_merge($query1, $query2); $query = array_merge($querys, $query3); if(!empty($query)){ return $query; }else{ return 0; } } public function get_potentialnew_detail($id){ $this->db->select('*'); $this->db->from('new_potential'); $this->db->join('new_contact','new_contact.contact_id=new_potential.contact_id','left'); //$this->db->join('new_contact','new_contact.contact_id=new_potential.contact_id','left'); $this->db->where('new_potential.potential_id',$id); $this->db->where('new_potential.delete_status','ACTIVE'); $result=$this->db->get(); return $result->row(); } public function get_potentialaccount_detail($id){ $this->db->select('new_account.billing_street as mailing_street,new_account.billing_city as mailing_city,new_account.billing_state as mailing_state,new_account.billing_code as mailing_zip_code,new_account.email_id as email'); $this->db->from('new_potential'); $this->db->join('new_account','new_account.account_id=new_potential.account_id','left'); $this->db->where('new_potential.potential_id',$id); $this->db->where('new_potential.delete_status','ACTIVE'); $result=$this->db->get(); return $result->row(); } public function get_potential_detail($id){ $this->db->select('*'); $this->db->from('new_potential'); $this->db->where('new_potential.potential_id',$id); $this->db->where('new_potential.delete_status','ACTIVE'); $result=$this->db->get(); return $result->row(); } public function get_potentialnew_detail_new($id){ $this->db->select('new_contact.Email as email,new_contact.mailing_street,new_contact.mailing_city,new_contact.mailing_state,new_contact.mailing_zip_code'); $this->db->from('new_potential'); $this->db->join('new_contact','new_contact.contact_id=new_potential.contact_id','left'); $this->db->where('new_potential.potential_id',$id); $this->db->where('new_potential.delete_status','ACTIVE'); $result=$this->db->get(); return $result->row(); } public function get_quotation_details_new($id){ $this->db->select('*'); $this->db->from('quotations'); $this->db->join('masters','masters.master_id=quotations.package_id','left'); $this->db->where('quotations.delete_status','ACTIVE'); $this->db->where('quotations.quotation_id',$id); $result=$this->db->get(); return $result->row(); } public function get_domain_server() { $this->db->select('A.*'); $this->db->from('masters A'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('A.master_type_id','1'); $this->db->where('A.field_type','select'); $this->db->where('A.field_name','server'); $result = $this->db->get(); $result = $result->row(); $array = array(); if($result) { $json = json_decode($result->field_value); foreach($json as $val) { array_push($array, $val); } } return $array; } public function get_domain_service_provider() { $this->db->select('A.*'); $this->db->from('masters A'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('A.master_type_id','1'); $this->db->where('A.field_type','select'); $this->db->where('A.field_name','service_provider'); $result = $this->db->get(); $result = $result->row(); $array = array(); if($result) { $json = json_decode($result->field_value); foreach($json as $val) { array_push($array, $val); } } return $array; } public function get_hosting_service_provider() { $this->db->select('A.*'); $this->db->from('masters A'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('A.master_type_id','2'); $this->db->where('A.field_type','select'); $this->db->where('A.field_name','service_provider'); $result = $this->db->get(); $result = $result->row(); $array = array(); if($result) { $json = json_decode($result->field_value); foreach($json as $val) { array_push($array, $val); } } return $array; } public function pg_service_provider() { $this->db->select('A.*'); $this->db->from('masters A'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('A.master_type_id','3'); $this->db->where('A.field_type','select'); $this->db->where('A.field_name','service_provider'); $result = $this->db->get(); $result = $result->row(); $array = array(); if($result) { $json = json_decode($result->field_value); if($json!=''){ foreach($json as $val) { array_push($array, $val); } } } return $array; } public function get_sms_service_provider() { $this->db->select('A.*'); $this->db->from('masters A'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('A.master_type_id','4'); $this->db->where('A.field_type','select'); $this->db->where('A.field_name','service_provider'); $result = $this->db->get(); $result = $result->row(); $array = array(); if($result) { $json = json_decode($result->field_value); foreach($json as $val) { array_push($array, $val); } } return $array; } public function get_email_service_provider() { $this->db->select('A.*'); $this->db->from('masters A'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('A.master_type_id','5'); $this->db->where('A.field_type','select'); $this->db->where('A.field_name','service_provider'); $result = $this->db->get(); $result = $result->row(); $array = array(); if($result) { $json = json_decode($result->field_value); foreach($json as $val) { array_push($array, $val); } } return $array; } public function get_all_client_assets() { // $this->db->select('A.*'); // $this->db->from('client_assets A'); // $this->db->where('A.delete_status','ACTIVE'); // $result = $this->db->get(); // return $result->result(); $final_array = array(); $domain_array = array(); $hosting_array = array(); $pg_array = array(); $sms_array = array(); $email_array = array(); $this->db->select('A.*'); $this->db->from('client_assets A'); $this->db->where('A.delete_status','ACTIVE'); $domain_result = $this->db->get(); $domain_result = $domain_result->result(); foreach($domain_result as $val) { if($val->domain_asset_for != "") { $domain_data['asset_id'] = $val->asset_id; $domain_data['domain_asset_for'] = $val->domain_asset_for; $domain_data['master_type'] = 'Domain'; $domain_data['domain_username'] = $val->domain_username; $domain_data['domain_password'] = $val->domain_password; $domain_data['domain_service_provider'] = $val->domain_service_provider; $domain_data['domain_name'] = $val->domain_name; $domain_data['domain_server'] = $val->domain_server; $domain_data['domain_start_date'] = $val->domain_start_date; $domain_data['domain_expiry_date'] = $val->domain_expiry_date; $domain_data['domain_status'] = $val->domain_status; $domain_data['domain_space'] = $val->domain_space; $domain_data['no_of_sms'] = ''; $domain_data['pg_commission'] = ''; array_push($domain_array, $domain_data); } if($val->hosting_asset_for != "") { $hosting_data['asset_id'] = $val->asset_id; $hosting_data['domain_asset_for'] = $val->hosting_asset_for; $hosting_data['master_type'] = 'Hosting'; $hosting_data['domain_username'] = $val->hosting_username; $hosting_data['domain_password'] = $val->hosting_password; $hosting_data['domain_service_provider'] = $val->hosting_service_provider; $hosting_data['domain_name'] = ''; $hosting_data['domain_server'] = ''; $hosting_data['domain_start_date'] = ''; $hosting_data['domain_expiry_date'] = $val->hosting_expiry_date; $hosting_data['domain_status'] = ''; $hosting_data['domain_space'] = ''; $hosting_data['no_of_sms'] = ''; $hosting_data['pg_commission'] = ''; array_push($hosting_array, $hosting_data); } if($val->pg_asset_for != "") { $pg_data['asset_id'] = $val->asset_id; $pg_data['domain_asset_for'] = $val->pg_asset_for; $pg_data['master_type'] = 'Payment Gateway'; $pg_data['domain_username'] = $val->pg_username; $pg_data['domain_password'] = $val->pg_password; $pg_data['domain_service_provider'] = $val->pg_service_provider; $pg_data['domain_name'] = ''; $pg_data['domain_server'] = ''; $pg_data['domain_start_date'] = ''; $pg_data['domain_expiry_date'] = ''; $pg_data['domain_status'] = ''; $pg_data['domain_space'] = ''; $pg_data['no_of_sms'] = ''; $pg_data['pg_commission'] = $val->pg_commission; array_push($pg_array, $pg_data); } if($val->sms_asset_for != "") { $sms_data['asset_id'] = $val->asset_id; $sms_data['domain_asset_for'] = $val->sms_asset_for; $sms_data['master_type'] = 'SMS'; $sms_data['domain_username'] = $val->sms_username; $sms_data['domain_password'] = $val->sms_password; $sms_data['domain_service_provider'] = $val->sms_service_provider; $sms_data['domain_name'] = ''; $sms_data['domain_server'] = ''; $sms_data['domain_start_date'] = ''; $sms_data['domain_expiry_date'] = $val->sms_expiry_date; $sms_data['domain_status'] = ''; $sms_data['domain_space'] = ''; $sms_data['no_of_sms'] = $val->no_of_sms; $sms_data['pg_commission'] = ''; array_push($sms_array, $sms_data); } if($val->email_asset_for != "") { $email_data['asset_id'] = $val->asset_id; $email_data['domain_asset_for'] = $val->email_asset_for; $email_data['master_type'] = 'Email'; $email_data['domain_username'] = $val->email_username; $email_data['domain_password'] = $val->email_password; $email_data['domain_service_provider'] = $val->email_service_provider; $email_data['domain_name'] = ''; $email_data['domain_server'] = ''; $email_data['domain_start_date'] = ''; $email_data['domain_expiry_date'] = $val->email_expiry_date; $email_data['domain_status'] = ''; $email_data['domain_space'] = ''; $email_data['no_of_sms'] = $val->no_of_emails; $email_data['pg_commission'] = ''; array_push($email_array, $email_data); } } return array_merge($final_array,$domain_array,$hosting_array,$pg_array,$sms_array,$email_array); } public function get_invoice_id() { $this->db->select('*'); $this->db->from('invoice'); $this->db->where('delete_status','ACTIVE'); // $this->db->where('invoice_no !=','cash'); // $this->db->where('invoice_type !=','Profomo'); // $this->db->where('invoice_no !=','profomo'); $this->db->where('invoice_type','Normal'); $this->db->order_by('id','DESC'); $this->db->limit(1); $query = $this->db->get(); return $query->row(); } public function search_account($val){ $where = " where "; $select = "Select A.*"; $from = " from new_account A"; $where .= "A.delete_status='ACTIVE' and "; $where .= "A.account_name LIKE '$val%'"; $doc_sql = $select.$from.$where; $doc_result = $this->db->query($doc_sql); $doc_result = $doc_result->result(); return $doc_result; } public function add_invoice($invoce_data) { $result=$this->db->insert('invoice',$invoce_data); if($result) { return 1; } else { return 0; } } public function get_employee_designations($emp_id) { $this->db->select('*'); $this->db->from('employees'); $this->db->join('designation','employees.designation_id=designation.designation_id'); $this->db->where('employees.emp_id',$emp_id); $this->db->where('employees.delete_status','ACTIVE'); $query=$this->db->get(); return $query->row(); } public function get_potential_lead_id($to_name) { $exp=explode(":",$to_name); // print_r($exp); $this->db->select('A.potential_id as id,lead_source'); $this->db->from('new_potential A'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('A.potential_name',$exp[0]); $this->db->where('A.contact_name',$exp[1]); $results = $this->db->get(); $results = $results->row(); $this->db->select('B.lead_id as id,"lead_source"'); $this->db->from('leads B'); $this->db->where('B.delete_status','ACTIVE'); $this->db->where('B.first_name',$exp[0]); $this->db->where('B.email',$exp[1]); $result = $this->db->get(); $result = $result->row(); $this->db->select('C.lead_id as id,C.account_id as a_id ,C.type as lead_source'); $this->db->from('new_account C'); $this->db->where('C.delete_status','ACTIVE'); $this->db->where('C.account_name',$exp[0]); $this->db->where('C.email_id',$exp[1]); $resultg = $this->db->get(); $resultg = $resultg->row(); $datas=array(); if(!empty($results)) { return $results; }else if($result) { return $result; }else if($resultg) { return $resultg; } } //client requirement public function search_project($project_name) { $mdsa_sql = "select account_id,account_name from new_account where account_name LIKE '$project_name%' and delete_status='ACTIVE'"; $mdsa_result = $this->db->query($mdsa_sql); return $mdsa_result->result(); // $where = " where "; // $select = "Select A.*"; // $from = " from new_account A"; // $where .= "A.delete_status='ACTIVE' and "; // $where .= "A.account_name LIKE '$project_name%'"; // $doc_sql = $select.$from.$where; // $doc_result = $this->db->query($doc_sql); // $doc_result = $doc_result->result(); // //print_r($doc_result);die(); // return $doc_result; } //client requirement list public function all_client_requirements() { $this->db->select('A.*,B.*,C.*,A.created_at as req_created_on,D.user_name as data_updated_by,A.email as client_email'); $this->db->from('client_requirements A'); $this->db->join('new_account B','B.account_id=A.project_id','left'); $this->db->join('users C','C.user_id=A.entered_by'); $this->db->join('users D','D.user_id=A.updated_by','left'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('B.delete_status','ACTIVE'); $result=$this->db->get(); return $result->result(); } public function all_client_completed_requirements() { $this->db->select('A.*,B.*,C.*,A.created_at as req_created_on,D.user_name as data_updated_by,A.email as client_email'); $this->db->from('client_requirements A'); $this->db->join('new_account B','B.account_id=A.project_id'); $this->db->join('users C','C.user_id=A.entered_by'); $this->db->join('users D','D.user_id=A.updated_by','left'); $this->db->where('A.completion_status','YES'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('B.delete_status','ACTIVE'); $result=$this->db->get(); return $result->result(); } public function all_client_closed_requirements() { $this->db->select('A.*,B.*,C.*,A.created_at as req_created_on,D.user_name as data_updated_by,A.email as client_email'); $this->db->from('client_requirements A'); $this->db->join('new_account B','B.account_id=A.project_id'); $this->db->join('users C','C.user_id=A.entered_by'); $this->db->join('users D','D.user_id=A.updated_by','left'); $this->db->where('A.completion_status','CLOSED'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('B.delete_status','ACTIVE'); $result=$this->db->get(); return $result->result(); } public function all_client_ongoing_requirements() { $this->db->select('A.*,B.*,C.*,A.created_at as req_created_on,D.user_name as data_updated_by,A.email as client_email'); $this->db->from('client_requirements A'); $this->db->join('new_account B','B.account_id=A.project_id'); $this->db->join('users C','C.user_id=A.entered_by'); $this->db->join('users D','D.user_id=A.updated_by','left'); $this->db->where('A.completion_status','NO'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('B.delete_status','ACTIVE'); $result=$this->db->get(); return $result->result(); } public function single_client_requirement($client_requirement_id) { $this->db->select('*,A.email as client_email,C.user_name,A.created_at as c_date,D.user_name as uname,A.updated_at as u_date,A.website_live_date as live_date'); $this->db->from('client_requirements A'); $this->db->join('new_account B','B.account_id=A.project_id'); $this->db->join('users C','C.user_id=A.entered_by'); $this->db->join('users D','D.user_id=A.updated_by','left'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('B.delete_status','ACTIVE'); $this->db->where('A.client_requirement_id',$client_requirement_id); $result=$this->db->get(); return $result->row(); } public function add_data($table,$data) { $result=$this->db->insert($table,$data); if($result) { return 1; } else { return 0; } } //tickets module public function get_all_tickets() { $this->db->select('A.*,B.account_name as project,C.user_name'); $this->db->from('tickets A'); $this->db->join('new_account B','B.account_id=A.project_id'); $this->db->join('users C','C.user_id=A.created_by'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('B.delete_status','ACTIVE'); $result=$this->db->get(); return $result->result(); } public function get_single_ticket($ticket_id) { $this->db->select('A.*,B.account_name as project,C.user_name'); $this->db->from('tickets A'); $this->db->join('new_account B','B.account_id=A.project_id'); $this->db->join('users C','C.user_id=A.created_by'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('B.delete_status','ACTIVE'); $this->db->where('A.ticket_id',$ticket_id); $result=$this->db->get(); return $result->row(); } public function get_where_result_orderby($table,$where,$order_by) { $this->db->select('*'); $this->db->from($table); $this->db->where($where); $this->db->order_by($order_by,"DESC"); $query=$this->db->get(); return $query->result(); } public function get_assign_task_main_list($admin_id) { if($admin_id!=1){ $this->db->select('A.*,B.client_name,C.account_name,E.first_name'); $this->db->from('assign_task A'); $this->db->join('client_requirements B','B.client_requirement_id=A.client_requirement_id'); $this->db->join('new_account C','C.account_id=A.project_id'); $this->db->join('assigned_task_person_details D','D.task_id=A.id AND A.project_id=D.project_id'); $this->db->join('employees E','E.emp_id=D.emp_id'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('B.delete_status','ACTIVE'); $this->db->where('C.delete_status','ACTIVE'); $this->db->where('D.delete_status','ACTIVE'); $this->db->where('D.emp_id',$admin_id); //$this->db->group_by(array('A.id')); $result=$this->db->get(); $datas= $result->result(); $array=array(); foreach($datas as $val) { $data['client_name']=$val->client_name; $data['account_name']=$val->account_name; $data['title']=$val->title; $data['id']=$val->id; $data['client_requirement_id']=$val->client_requirement_id; $data['description']=$val->description; $data['attachment']=$val->attachment; $data['deadline']=$val->deadline; if($val->priority==1){ $preority='High'; }else { $preority='Low'; } $data['priority']=$preority; $data['link']=$val->link; $data['link_text']=$val->link_text; $data['project_id']=$val->project_id; $decode=json_decode($val->responsible_person); $responser=array(); foreach($decode as $key => $value) { $this->db->select('z.*'); $this->db->from('employees z'); $this->db->where('z.delete_status','ACTIVE'); $this->db->where('z.emp_id',$value); $result=$this->db->get(); $ret= $result->row(); array_push($responser,$ret->first_name); } $data['responsible_person']=$responser; array_push($array, $data); } return $array; } else { $this->db->select('A.*,B.client_name,C.account_name'); $this->db->from('assign_task A'); $this->db->join('client_requirements B','B.client_requirement_id=A.client_requirement_id'); $this->db->join('new_account C','C.account_id=A.project_id'); // $this->db->join('assigned_task_person_details D','D.task_id=A.id AND A.project_id=D.project_id'); //$this->db->join('employees E','E.emp_id=D.emp_id'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('B.delete_status','ACTIVE'); $this->db->where('C.delete_status','ACTIVE'); //$this->db->where('D.delete_status','ACTIVE'); $this->db->group_by(array('A.id')); $result=$this->db->get(); $datas= $result->result(); $array=array(); foreach($datas as $val) { $data['client_name']=$val->client_name; $data['account_name']=$val->account_name; //$data['first_name']=$val->first_name; $data['id']=$val->id; $data['client_requirement_id']=$val->client_requirement_id; $data['title']=$val->title; $data['description']=$val->description; $data['attachment']=$val->attachment; $data['deadline']=$val->deadline; if($val->priority==1){ $preority='High'; }else { $preority='Low'; } $data['priority']=$preority; $data['link']=$val->link; $data['link_text']=$val->link_text; $data['project_id']=$val->project_id; $decode=json_decode($val->responsible_person); $responser=array(); foreach($decode as $key => $value) { $this->db->select('z.*'); $this->db->from('employees z'); $this->db->where('z.delete_status','ACTIVE'); $this->db->where('z.emp_id',$value); $result=$this->db->get(); $ret= $result->row(); array_push($responser,$ret->first_name); } $data['responsible_person']=$responser; array_push($array, $data); } return $array; } } public function get_assign_task_sub_list($admin_id) { if($admin_id!=1){ $this->db->select('A.*,B.client_name,C.account_name,E.first_name'); $this->db->from('share_project_task A'); $this->db->join('client_requirements B','B.client_requirement_id=A.client_requirement_id'); $this->db->join('new_account C','C.account_id=A.project_id'); $this->db->join('task_shared_persons D','D.task_id=A.id AND A.project_id=D.project_id'); $this->db->join('employees E','E.emp_id=D.emp_id'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('B.delete_status','ACTIVE'); $this->db->where('C.delete_status','ACTIVE'); $this->db->where('D.delete_status','ACTIVE'); $this->db->where('D.emp_id',$admin_id); //$this->db->group_by(array('A.id')); $result=$this->db->get(); $datas= $result->result(); $array=array(); foreach($datas as $val) { $data['client_name']=$val->client_name; $data['account_name']=$val->account_name; $data['title']=$val->title; $data['id']=$val->id; $data['client_requirement_id']=$val->client_requirement_id; $data['description']=$val->description; $data['attachment']=$val->attachment; $data['deadline']=$val->deadline; if($val->priority==1){ $preority='High'; }else { $preority='Low'; } $data['priority']=$preority; $data['link']=$val->link; $data['link_text']=$val->link_text; $data['project_id']=$val->project_id; $decode=json_decode($val->responsible_person); $responser=array(); foreach($decode as $key => $value) { $this->db->select('z.*'); $this->db->from('employees z'); $this->db->where('z.delete_status','ACTIVE'); $this->db->where('z.emp_id',$value); $result=$this->db->get(); $ret= $result->row(); array_push($responser,$ret->first_name); } $data['responsible_person']=$responser; array_push($array, $data); } return $array; } else { $this->db->select('A.*,B.client_name,C.account_name'); $this->db->from('share_project_task A'); $this->db->join('client_requirements B','B.client_requirement_id=A.client_requirement_id'); $this->db->join('new_account C','C.account_id=A.project_id'); // $this->db->join('task_shared_persons D','D.task_id=A.id AND A.project_id=D.project_id'); //$this->db->join('employees E','E.emp_id=D.emp_id'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('B.delete_status','ACTIVE'); $this->db->where('C.delete_status','ACTIVE'); //$this->db->where('D.delete_status','ACTIVE'); $this->db->group_by(array('A.id')); $result=$this->db->get(); $datas= $result->result(); $array=array(); foreach($datas as $val) { $data['client_name']=$val->client_name; $data['account_name']=$val->account_name; //$data['first_name']=$val->first_name; $data['id']=$val->id; $data['client_requirement_id']=$val->client_requirement_id; $data['title']=$val->title; $data['description']=$val->description; $data['attachment']=$val->attachment; $data['deadline']=$val->deadline; if($val->priority==1){ $preority='High'; }else { $preority='Low'; } $data['priority']=$preority; $data['link']=$val->link; $data['link_text']=$val->link_text; $data['project_id']=$val->project_id; $decode=json_decode($val->responsible_person); $responser=array(); foreach($decode as $key => $value) { $this->db->select('z.*'); $this->db->from('employees z'); $this->db->where('z.delete_status','ACTIVE'); $this->db->where('z.emp_id',$value); $result=$this->db->get(); $ret= $result->row(); array_push($responser,$ret->first_name); } $data['responsible_person']=$responser; array_push($array, $data); } return $array; } } //assign ticket module public function get_raised_ticket($ticket_id) { $this->db->select('A.*,B.account_name as project,C.user_name'); $this->db->from('tickets A'); $this->db->join('new_account B','B.account_id=A.project_id'); $this->db->join('users C','C.user_id=A.created_by'); $this->db->where('A.delete_status','ACTIVE'); //$this->db->where('A.ticket_status','RAISED'); $this->db->where('B.delete_status','ACTIVE'); $this->db->where('A.ticket_id',$ticket_id); $result=$this->db->get(); return $result->row(); } public function search_role($val){ $this->db->from('role'); $this->db->like('role_name',$val); $result=$this->db->get(); return $result->row(); } public function delete_invoice_reports() { $this->db->where('delete_status','ACTIVE'); return $this->db->delete('invoice_reports'); } public function get_invoice_details($from_date,$to_date,$invoice_type) { $this->db->select('*'); $this->db->from('invoice'); $this->db->where('invoice.invoice_date>=',$from_date); $this->db->where('invoice.invoice_date<=',$to_date); $this->db->where('invoice.delete_status','ACTIVE'); if(!empty($invoice_type)){ $this->db->where('invoice.invoice_type',$invoice_type); } $result=$this->db->get(); return $result->result(); } public function get_resignation_data($emp_id) { $this->db->select('*'); $this->db->from('employees'); $this->db->join('roles','roles.role_id=employees.role_id','left'); $this->db->where('employees.delete_status','ACTIVE'); $this->db->where('employees.emp_id',$emp_id); $query=$this->db->get(); return $query->row(); } public function get_invoice_reports_details(){ $this->db->select('*'); $this->db->from('invoice_reports'); $this->db->where('invoice_reports.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function update_new($table,$where,$data){ $this->db->where($where); return $this->db->delete($table); } public function get_invoice_sum_value($where,$table){ $this->db->select('sum(amount) as amount,invoice_id'); $this->db->from('invoice_payments'); $this->db->where($where); $result=$this->db->get(); return $result->row(); } public function update_invoice_payment($where,$data,$table) { $this->db->where($where); $result=$this->db->update($table,$data); return $result; } public function get_renewal_list_data($table,$where){ $this->db->select('category,product_id as id,product_name,product_start_date,amc_date,notify_before_date,document_name,doc_renewal_date,agreement_name,agree_renewal_date'); $this->db->from('product_renewal'); $this->db->where($where); $result=$this->db->get(); return $result->result(); } public function get_emp_salary_list(){ $this->db->select('*'); $this->db->from('employees'); $this->db->join('salary','salary.emp_id=employees.emp_id'); $this->db->where('employees.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function delete_salary_emp($salary_id){ $this->db->where_in('salary_id', $salary_id); return $this->db->delete('salary'); } public function search_client($val){ // Query #1 $this->db->select('first_name, email,lead_id,l_type as type,mobile as phone'); $this->db->from('leads'); $this->db->where('delete_status','ACTIVE'); $this->db->like('first_name', $val); $query1 = $this->db->get()->result(); // Query #2 $this->db->select('first_name as first_name,phone,Email as email'); $this->db->from('new_contact'); //$this->db->join('new_contact','new_contact.contact_id=new_potential.contact_id','left'); $this->db->where('delete_status','ACTIVE'); $this->db->like('first_name', $val); $query2 = $this->db->get()->result(); // Merge both query results $this->db->select('account_name as first_name,phone,email_id as email'); $this->db->from('new_account'); $this->db->where('delete_status','ACTIVE'); $this->db->like('account_name', $val); $query3 = $this->db->get()->result(); $query = array_merge($query1, $query2,$query3); return $query; } public function get_quotation_status_data($status){ if($status!='ALL'){ $this->db->from('quotations'); $this->db->where('delete_status','ACTIVE'); $this->db->where('quotation_status', $status); $this->db->group_by(array('quotations.quotation_id')); $this->db->order_by('quo_date','DESC'); $query2 = $this->db->get()->result(); return $query2; } else{ $this->db->from('quotations'); $this->db->where('delete_status','ACTIVE'); $this->db->group_by(array('quotations.quotation_id')); $this->db->order_by('quo_date','DESC'); //$this->db->where('quotation_status', $status); $query2 = $this->db->get()->result(); return $query2; } } public function delete_master_new($table,$where) { $this->db->where($where); return $this->db->delete($table); } public function get_employee_status_data($status){ $this->db->select('employees.*,employees.email_id as email_id,department.department_name'); $this->db->from('employees'); $this->db->join('department','department.department_id=employees.department_id','left'); $this->db->where('employees.delete_status','Active'); $this->db->where('employees.employee_status', $status); $query2 = $this->db->get()->result(); return $query2; } public function get_account_phone_number(){ $this->db->select('phone,email_id as email'); $this->db->from('new_account'); $this->db->where('delete_status','ACTIVE'); $query3 = $this->db->get()->result(); return $query3; } public function get_leads_phone_number(){ $this->db->select('phone,email'); $this->db->from('leads'); $this->db->where('delete_status','ACTIVE'); $query3 = $this->db->get()->result(); return $query3; } public function get_contact_phone_number(){ $this->db->select('phone,Email as email'); $this->db->from('new_contact'); $this->db->where('delete_status','ACTIVE'); $query3 = $this->db->get()->result(); return $query3; } public function get_last_row_template(){ $this->db->from('email_template'); $this->db->order_by('e_template_id','DESC'); $this->db->limit(1); $query3 = $this->db->get()->row(); return $query3; } public function get_tickets_notifications(){ $this->db->from('tickets'); $query3 = $this->db->get()->result(); return $query3; } public function get_today_ticket_notification($date_format){ $this->db->from('tickets'); $this->db->join('new_account','new_account.account_id=tickets.project_id'); $this->db->where('DATE(tickets.created_at)',$date_format); $query3 = $this->db->get()->result(); return $query3; } public function get_week_ticket_notification($arr){ $this->db->from('tickets'); $this->db->join('new_account','new_account.account_id=tickets.project_id'); $this->db->where('DATE(tickets.created_at)',$arr); $query3 = $this->db->get()->result(); return $query3; } public function get_allday_ticket_notification(){ $this->db->from('tickets'); $this->db->join('new_account','new_account.account_id=tickets.project_id'); $query3 = $this->db->get()->result(); return $query3; } //Action access controls public function single_department_menu_access($access,$department_id) { $table = 'yaskawa_access_controls'; $where = array('delete_status' =>'ACTIVE','department_id' =>$department_id); $controls = $this->yaskawa_model->get_single_row($table,$where); if($controls) { $access = unserialize($controls->menu_id); if($access) { $multi_expresion = "'" .implode("','", $access ) . "'"; $sql = "select A.menu_id,A.menu_name,A.parent_id from yaskawa_menu A where A.menu_id IN ($multi_expresion) and A.delete_status='ACTIVE' and A.menu_type='LIST'"; $menu_result = $this->db->query($sql); $menu_result = $menu_result->result(); if($menu_result) { $data['count'] = count($menu_result)-1; } } } $this->db->select('A.*'); $this->db->from('yaskawa_menu A'); $this->db->where('A.parent_id','0'); $this->db->where('A.delete_status','ACTIVE'); $result = $this->db->get(); $result = $result->result(); $array = array(); foreach($result as $val) { $data['menu_id'] = $val->menu_id; $data['menu_name'] = $val->menu_name; $data['parent_id'] = $val->parent_id; $data['menu_type'] = $val->menu_type; $this->db->select('B.*'); $this->db->from('yaskawa_menu B'); $this->db->where('B.delete_status','ACTIVE'); $this->db->where('B.parent_id !=','0'); $this->db->where('B.parent_id',$val->menu_id); $menu_result = $this->db->get(); $menu_result = $menu_result->result(); if($menu_result) { $arr=array(); foreach ($menu_result as $key => $value) { $data1['menu_id']=$value->menu_id; $data1['menu_name']=$value->menu_name; $data1['menu_type']=$value->menu_type; $access_sql = "select * from access_action_rights A where A.menu_id ='$value->menu_id' and A.department_id='$department_id'"; $access_result = $this->db->query($access_sql); $access_result = $access_result->row(); if($access_result) { $data1['action_id'] = $access_result->action_id; $data1['department_id'] = $access_result->department_id; $data1['insert_id'] = $access_result->insert_id; $data1['edit_id'] = $access_result->edit_id; $data1['delete_id'] = $access_result->delete_id; } else { $data1['action_id'] = ''; $data1['department_id'] = ''; $data1['insert_id'] = '0'; $data1['edit_id'] = '0'; $data1['delete_id'] = '0'; } $this->db->select('c.*'); $this->db->from('yaskawa_menu c'); $this->db->where('c.delete_status','ACTIVE'); $this->db->where('c.parent_id !=','0'); $this->db->where('c.parent_id',$value->menu_id); $menu_result_new= $this->db->get(); $menu_result_new = $menu_result_new->result(); if($menu_result_new){ $arr1=array(); foreach ($menu_result_new as $key => $val1) { $data2['menu_id']=$val1->menu_id; $data2['menu_name']=$val1->menu_name; $data2['menu_type']=$val1->menu_type; $access_sql = "select * from access_action_rights A where A.menu_id ='$val1->menu_id' and A.department_id='$department_id'"; $access_result = $this->db->query($access_sql); $access_result = $access_result->row(); if($access_result) { $data2['action_id'] = $access_result->action_id; $data2['department_id'] = $access_result->department_id; $data2['insert_id'] = $access_result->insert_id; $data2['edit_id'] = $access_result->edit_id; $data2['delete_id'] = $access_result->delete_id; } else { $data2['action_id'] = ''; $data2['department_id'] = ''; $data2['insert_id'] = '0'; $data2['edit_id'] = '0'; $data2['delete_id'] = '0'; } array_push($arr1,$data2); } $data1['child']=$arr1; } else{ $data1['child']=""; } array_push($arr,$data1); } $data['sub_menu']=$arr; } else { $data['sub_menu'] = ""; } array_push($array,$data); } return $array; } public function search_contacts($val){ $this->db->select('first_name as first_name,phone,Email as email,new_contact.contact_id'); $this->db->from('new_contact'); $this->db->where('delete_status','ACTIVE'); $this->db->like('first_name', $val); $query2 = $this->db->get()->result(); return $query2; } public function generate_lead_report($from_date,$to_date){ $this->db->select('leads.*,leads.created_at as c_date,b.user_name,leads.delete_status as del_state'); $this->db->from('leads'); $this->db->join('users b','b.user_id =leads.lead_owner'); $this->db->where('leads.created_at >=',$from_date); $this->db->where('leads.created_at <=',$to_date); // $this->db->where('leads.delete_status','ACTIVE'); $this->db->order_by('leads.created_at','DESC'); $result=$this->db->get(); return $result->result(); } public function lead_status_data($status){ if($status=='CONTACTED'){ $this->db->select('leads.*,leads.created_at as c_date,b.user_name'); $this->db->from('leads'); $this->db->join('users b','b.user_id =leads.lead_owner'); $this->db->where('lead_status','Contacted'); $this->db->where('lead_convert !=','CLOSED'); $this->db->where('leads.delete_status','ACTIVE'); $this->db->order_by('leads.created_at','DESC'); $result=$this->db->get(); return $result->result(); }else if($status=='CONVERTED'){ $this->db->select('leads.*,leads.created_at as c_date,b.user_name'); $this->db->from('leads'); $this->db->join('users b','b.user_id =leads.lead_owner'); $this->db->where('converted_next_level','ACONVERT'); $this->db->or_where('converted_next_level','PCONVERT'); $this->db->or_where('lead_convert','PCONVERTED'); //$this->db->where('leads.delete_status','INACTIVE'); $this->db->order_by('leads.created_at','DESC'); $result=$this->db->get(); return $result->result(); }else if($status=='CLOSED'){ $this->db->select('leads.*,leads.created_at as c_date,b.user_name'); $this->db->from('leads'); $this->db->join('users b','b.user_id =leads.lead_owner'); $this->db->where('lead_convert','CLOSED'); $this->db->where('leads.delete_status','ACTIVE'); $this->db->order_by('leads.created_at','DESC'); $result=$this->db->get(); return $result->result(); }else { $this->db->select('leads.*,leads.created_at as c_date,b.user_name'); $this->db->from('leads'); $this->db->join('users b','b.user_id =leads.lead_owner'); //$this->db->where('lead_convert','CLOSED'); $this->db->where('leads.delete_status','ACTIVE'); $this->db->order_by('leads.created_at','DESC'); $result=$this->db->get(); return $result->result(); } } public function lead_status_sort_data($status,$from,$to){ if($status=='CONTACTED'){ $this->db->select('leads.*,leads.created_at as c_date,b.user_name,leads.delete_status as del_state'); $this->db->from('leads'); $this->db->join('users b','b.user_id =leads.lead_owner'); $this->db->where('leads.lead_convert !=','CLOSED'); $this->db->where('leads.lead_convert !=','PCONVERTED'); $this->db->where('leads.lead_convert !=','CONVERTED'); $this->db->where("(lead_status='Contacted' OR lead_status='')"); $this->db->where('leads.delete_status','ACTIVE'); $this->db->where('leads.created_at >=',$from); $this->db->where('leads.created_at <=',$to); $this->db->order_by('leads.created_at','DESC'); $result=$this->db->get(); return $result->result(); }else if($status=='CONVERTED'){ $this->db->select('leads.*,leads.created_at as c_date,b.user_name,leads.delete_status as del_state'); $this->db->from('leads'); $this->db->join('users b','b.user_id =leads.lead_owner'); //$this->db->where('leads.delete_status','ACTIVE'); $this->db->where('leads.created_at >=',$from); $this->db->where('leads.created_at <=',$to); $this->db->where("(lead_convert='CONVERTED' OR lead_convert='PCONVERTED' OR converted_next_level='ACONVERT' OR converted_next_level='PCONVERT')"); // $this->db->or_where('converted_next_level','ACONVERT'); // $this->db->or_where('converted_next_level','PCONVERT'); $this->db->order_by('leads.created_at','DESC'); $result=$this->db->get(); return $result->result(); }else if($status=='CLOSED'){ $this->db->select('leads.*,leads.created_at as c_date,b.user_name,leads.delete_status as del_state'); $this->db->from('leads'); $this->db->join('users b','b.user_id =leads.lead_owner'); $this->db->where('lead_convert','CLOSED'); $this->db->where('leads.delete_status','ACTIVE'); $this->db->where('leads.created_at >=',$from); $this->db->where('leads.created_at <=',$to); $this->db->order_by('leads.created_at','DESC'); $result=$this->db->get(); return $result->result(); }else { /* $this->db->select('leads.*,leads.created_at as c_date,b.user_name'); $this->db->from('leads'); $this->db->join('users b','b.user_id =leads.lead_owner'); //$this->db->where('lead_convert','CLOSED'); //$this->db->where('leads.delete_status','ACTIVE'); $this->db->where('leads.created_at >=',$from); $this->db->where('leads.created_at <=',$to); $this->db->order_by('leads.created_at','DESC'); $result=$this->db->get(); return $result->result();*/ $this->db->select('leads.*,leads.created_at as c_date,b.user_name,leads.delete_status as del_state'); $this->db->from('leads'); $this->db->join('users b','b.user_id =leads.lead_owner'); $this->db->where('leads.created_at >=',$from); $this->db->where('leads.created_at <=',$to); // $this->db->where('leads.delete_status','ACTIVE'); $this->db->order_by('leads.created_at','DESC'); $result=$this->db->get(); return $result->result(); } } public function get_open_ticket_list($date_format){ $this->db->select('A.*,B.account_name as project,A.created_at as c_date'); $this->db->from('tickets A'); $this->db->join('new_account B','B.account_id=A.project_id'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('B.delete_status','ACTIVE'); $this->db->where('DATE(A.created_at)',$date_format); $this->db->order_by('DATE(A.created_at)','DESC'); $result=$this->db->get(); return $result->result(); } public function get_expense_list($from,$to){ $this->db->from('expense A'); $this->db->where('A.expense_date >= ',$from); $this->db->where('A.expense_date <=',$to); $this->db->where('A.delete_status','ACTIVE'); $result=$this->db->get(); return $result->result(); } public function get_expense_data($id){ $this->db->from('expense'); $this->db->join('employees','employees.emp_id=expense.payment_by OR expense.payment_by=0'); $this->db->where('employees.delete_status','ACTIVE'); $this->db->where('expense.expense_id',$id); $query3 = $this->db->get()->row(); return $query3; } public function delete_row($where,$table){ $this->db->where($where); return $this->db->delete($table); } public function get_potential_data_status($status){ if($status=='CLOSED'){ $this->db->select('new_potential.*,users.*,new_account.*,new_potential.description as desc,new_contact.*,new_potential.potential_id as potential_id'); $this->db->from('new_potential'); $this->db->join('users','users.user_id = new_potential.potential_owner'); $this->db->join('new_account','new_potential.account_name = new_account.account_id','left'); $this->db->join('new_contact','new_contact.contact_id = new_potential.contact_id','left'); $this->db->where('new_potential.delete_status','ACTIVE'); $this->db->where('new_potential.stage','CLOSED'); $result=$this->db->get(); return $result->result(); }else{ $this->db->select('new_potential.*,users.*,new_account.*,new_potential.description as desc,new_contact.*,new_potential.potential_id as potential_id'); $this->db->from('new_potential'); $this->db->join('users','users.user_id = new_potential.potential_owner'); $this->db->join('new_account','new_potential.account_name = new_account.account_id','left'); $this->db->join('new_contact','new_contact.contact_id = new_potential.contact_id','left'); $this->db->where('new_potential.delete_status','ACTIVE'); $this->db->where('new_potential.stage !=','CLOSED'); $result=$this->db->get(); return $result->result(); } } public function get_agents_list(){ $this->db->select('employees.*,department.*,employees.email_id'); $this->db->from('employees'); $this->db->join('department','department.department_id = employees.department_id'); $this->db->where('employees.agents','AGENT'); $result=$this->db->get(); return $result->result(); } public function get_agents_list_where($status){ $this->db->select('employees.*,department.*,employees.email_id'); $this->db->from('employees'); $this->db->join('department','department.department_id = employees.department_id'); $this->db->where('employees.agents','AGENT'); $this->db->where('department.department_id',$status); $result=$this->db->get(); return $result->result(); } public function get_search_data($search_data) { $this->db->from('new_task A'); $this->db->where('A.delete_status','ACTIVE'); $where = "(A.id LIKE '%$search_data%' OR A. title LIKE '%$search_data%' OR A. description LIKE '%$search_data%' OR A. visibality_description LIKE '%$search_data%' OR A. assignee LIKE '%$search_data%' OR A. due_date LIKE '%$search_data%' OR A. due_time LIKE '%$search_data%'vOR A. created_at LIKE '%$search_data%'OR A. modified_at LIKE '%$search_data%')"; $this->db->where($where); $result=$this->db->get(); return $result->result(); } public function get_search_ticket_users($search_data) { $this->db->from('add_ticket_user A'); $this->db->where('A.delete_status','ACTIVE'); $where = "(A.id LIKE '%$search_data%' OR A. email LIKE '%$search_data%' OR A. name LIKE '%$search_data%' OR A. phone LIKE '%$search_data%' OR A. user_status LIKE '%$search_data%' OR A. register_status LIKE '%$search_data%' OR A. note LIKE '%$search_data%' OR A. created_at LIKE '%$search_data%'OR A. modified_at LIKE '%$search_data%')"; $this->db->where($where); $result=$this->db->get(); return $result->result(); } public function update_ticket_user_register_status($id) { $data=array('register_status'=>'Registered'); $this->db->where_in('id',$id); $this->db->update('add_ticket_user',$data); return $this->db->affected_rows(); } public function delete_ticket_user($id) { $data=array('delete_status'=>'INACTIVE'); $this->db->where_in('id',$id); $this->db->update('add_ticket_user',$data); return $this->db->affected_rows(); } public function update_locked_ticked_user($id) { $data=array('locked'=>'YES'); $this->db->where_in('id',$id); $this->db->update('add_ticket_user',$data); return $this->db->affected_rows(); } public function get_search_ticket_organization($search_data) { $this->db->from('add_ticket_organization A'); $this->db->where('A.delete_status','ACTIVE'); $where = "(A.id LIKE '%$search_data%' OR A. address LIKE '%$search_data%' OR A. name LIKE '%$search_data%' OR A. phone LIKE '%$search_data%' OR A. website LIKE '%$search_data%' OR A. note LIKE '%$search_data%' OR A. created_at LIKE '%$search_data%'OR A. modified_at LIKE '%$search_data%')"; $this->db->where($where); $result=$this->db->get(); return $result->result(); } public function delete_ticket_organization($id) { $data=array('delete_status'=>'INACTIVE'); $this->db->where_in('id',$id); $this->db->update('add_ticket_organization',$data); return $this->db->affected_rows(); } public function add_to_ticket_orgs($id) { $this->db->from('add_ticket_user A'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where_in('id',$id); $result=$this->db->get(); $dat= $result->result(); foreach($dat as $datas) $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $date_format = $date->format('Y-m-d'); $address=''; $name=$datas->name; $phone=$datas->phone; $website=''; $note=$datas->note; $data=array('address'=>$address,'name'=>$name,'phone'=>$phone,'website'=>$website,'note'=>$note,'delete_status'=>'ACTIVE','created_at'=>$date_format,'modified_at'=>$date_format); $table='add_ticket_organization'; $result=$this->yaskawa_model->insert($table,$data); return $result; } public function get_user_searched($search_data) { $this->db->from('add_ticket_user A'); $this->db->where('A.delete_status','ACTIVE'); $where = "( A. email LIKE '%$search_data%' OR A. name LIKE '%$search_data%' OR A. phone LIKE '%$search_data%')"; $this->db->where($where); $result=$this->db->get(); return $result->result(); } public function get_customer_new_result($table,$where,$date_new,$range){ if($range=='1'){ if($date_new!='1970-01-01'){ $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $date_format = $date->format('Y-m-d'); $this->db->select('*'); $this->db->from($table); $this->db->where($where); $this->db->where('DATE(created_at) >=',$date_new); $this->db->where('DATE(created_at) <=',$date_format); $query=$this->db->get(); return $query->result(); }else{ $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $date_format = $date->format('Y-m-d'); $this->db->select('*'); $this->db->from($table); $this->db->where($where); // $this->db->where('DATE(created_at) >=',$date_new); // $this->db->where('DATE(created_at) <=',$date_format); $query=$this->db->get(); return $query->result(); } } else if($range=='2'){ if($date_new!='1970-01-01'){ $datee = strtotime(date("Y-m-d", strtotime($date_new)) . " +1 week"); $this->db->select('*'); $this->db->from($table); $this->db->where($where); $this->db->where('DATE(created_at) >=',$date_new); $this->db->where('DATE(created_at) <=',$datee); $query=$this->db->get(); return $query->result(); }else{ $current_dayname = date("l"); // return sunday monday tuesday etc. $date = date("Y-m-d",strtotime('monday this week')); $t_date=date("Y-m-d",strtotime("$current_dayname this week")); $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $date_format = $date->format('Y-m-d'); $this->db->select('*'); $this->db->from($table); $this->db->where($where); $this->db->where('DATE(created_at) >=',$date_format); $this->db->where('DATE(created_at) <=',$t_date); $query=$this->db->get(); return $query->result(); } } else if($range=='3'){ if($date_new!='1970-01-01'){ $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $date_format = $date->format('Y-m-d'); $datee = strtotime(date("Y-m-d", strtotime($date_format)) . " +2 week"); $this->db->select('*'); $this->db->from($table); $this->db->where($where); $this->db->where('DATE(created_at) >=',$date_new); $this->db->where('DATE(created_at) <=',$datee); $query=$this->db->get(); return $query->result(); }else{ $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $date_format = $date->format('Y-m-d'); $datee = strtotime(date("Y-m-d", strtotime($date_format)) . " +2 week"); $this->db->select('*'); $this->db->from($table); $this->db->where($where); $this->db->where('DATE(created_at) >=',$date_format); $this->db->where('DATE(created_at) <=',$datee); $query=$this->db->get(); return $query->result(); } } else if($range=='4'){ if($date_new!='1970-01-01'){ $datee = strtotime(date("Y-m-d", strtotime($date_new)) . " +4 week"); $this->db->select('*'); $this->db->from($table); $this->db->where($where); $this->db->where('DATE(created_at) >=',$date_new); $this->db->where('DATE(created_at) <=',$datee); $query=$this->db->get(); return $query->result(); }else{ $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $date_format = $date->format('Y-m-d'); $datee = strtotime(date("Y-m-d", strtotime($date_format)) . " +4 week"); $this->db->select('*'); $this->db->from($table); $this->db->where($where); $this->db->where('DATE(created_at) >=',$date_new); $this->db->where('DATE(created_at) <=',$datee); $query=$this->db->get(); return $query->result(); } } else if($range=='5'){ if($date_new!='1970-01-01'){ $datee = strtotime(date("Y-m-d", strtotime($date_new)) . "+3 months"); $datee = date('Y-m-d', strtotime('+3 months')); $this->db->select('*'); $this->db->from($table); $this->db->where($where); $this->db->where('DATE(created_at) >=',$date_new); $this->db->where('DATE(created_at) <=',$datee); $query=$this->db->get(); return $query->result(); }else{ $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $date_format = $date->format('Y-m-d'); $datee = date('Y-m-d', strtotime('+3 months')); $this->db->select('*'); $this->db->from($table); $this->db->where($where); $this->db->where('DATE(created_at) >=',$date_format); $this->db->where('DATE(created_at) <=',$datee); $query=$this->db->get(); return $query->result(); } } } /* public function get_invoice_payment_details($name) { $this->db->select('*'); $this->db->from('invoice'); $this->db->where('delete_status', 'ACTIVE'); $this->db->where('name', $name); $query = $this->db->get(); $result = $query->result(); $i = 0; $res_array = array(); foreach($result as $val) { if($val->invoice_status == 'CLEARED' || $val->invoice_status == 'PARTIAL') { $this->db->select('A.total_amount, A.name,A.invoice_no, A.invoice_date, B.amount, C.amount as quotation_amount'); $this->db->from('invoice A'); $this->db->join('invoice_payments B','B.invoice_id = A.id'); $this->db->join('quotations C','A.name = C.client_name'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('B.delete_status','ACTIVE'); $this->db->where('C.delete_status','ACTIVE'); $this->db->where('A.id',$val->id); $this->db->where('A.name', $name); $query=$this->db->get(); $query= $query->row(); if($i == 0) { $data['balance_amount'] = $query->quotation_amount; $data['paid_amount'] = $query->amount; $originalDate = $query->invoice_date; $newDate = date("d-m-Y", strtotime($originalDate)); $data['date'] = $newDate; $data['invoice_no'] = $query->invoice_no; $data['name'] = $query->name; $pending_amonut = ($query->quotation_amount - $query->amount); $data['pending_amount'] = $pending_amonut; } else { $data['balance_amount'] = $pending_amonut; $data['paid_amount'] = $query->amount; $originalDate = $query->invoice_date; $newDate = date("d-m-Y", strtotime($originalDate)); $data['date'] = $newDate; $data['invoice_no'] = $query->invoice_no; $pending_amonut = ($data['balance_amount'] - $data['paid_amount']); $data['pending_amount'] = $pending_amonut; $data['name'] = $query->name; } array_push($res_array,$data); $i = $i + 1; } } return $res_array; } public function search_quotation($val){ $this->db->select('client_name, address, amount'); $this->db->from('quotations'); $this->db->where('delete_status','ACTIVE'); $this->db->like('client_name', $val); $query1 = $this->db->get()->result(); // Query #2 if(!empty($query1)){ return $query1; }else{ return 0; } }*/ /* public function get_invoice_payment_details($name,$quotation_id) { $this->db->select('*'); $this->db->from('invoice'); $this->db->where('delete_status', 'ACTIVE'); $this->db->where('quotation_id', $quotation_id); $query = $this->db->get(); $result = $query->result(); $i = 0; $res_array = array(); foreach($result as $val) { if($val->invoice_status == 'CLEARED' || $val->invoice_status == 'PARTIAL') { $this->db->select('A.total_amount, A.name,A.invoice_no, A.invoice_date, B.amount, C.amount as quotation_amount'); $this->db->from('invoice A'); $this->db->join('invoice_payments B','B.invoice_id = A.id'); $this->db->join('quotations C','A.quotation_id = C.quotation_id'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('B.delete_status','ACTIVE'); $this->db->where('C.delete_status','ACTIVE'); $this->db->where('C.quotation_id',$quotation_id); $this->db->where('A.quotation_id',$quotation_id); $this->db->where('B.invoice_id',$val->id); $this->db->where('A.id',$val->id); $this->db->where('A.name', $name); $query=$this->db->get(); $query= $query->row(); if($i == 0) { $data['balance_amount'] = $query->quotation_amount; $data['paid_amount'] = $query->amount; $originalDate = $query->invoice_date; $newDate = date("d-m-Y", strtotime($originalDate)); $data['date'] = $newDate; $data['invoice_no'] = $query->invoice_no; $data['name'] = $query->name; $pending_amonut = ($query->quotation_amount - $query->amount); $data['pending_amount'] = $pending_amonut; } else { $data['balance_amount'] = $pending_amonut; $data['paid_amount'] = $query->amount; $originalDate = $query->invoice_date; $newDate = date("d-m-Y", strtotime($originalDate)); $data['date'] = $newDate; $data['invoice_no'] = $query->invoice_no; $pending_amonut = ($data['balance_amount'] - $data['paid_amount']); $data['pending_amount'] = $pending_amonut; $data['name'] = $query->name; } array_push($res_array,$data); $i = $i + 1; } } return $res_array; } */ public function get_invoice_payment_details($name,$quotation_id,$from) { $this->db->select('*'); $this->db->from('invoice'); $this->db->where('delete_status', 'ACTIVE'); $this->db->where('name', $name); $query = $this->db->get(); $result = $query->result(); $i = 0; $res_array = array(); foreach($result as $val) { if($from == 'invoice') { $this->db->select('A.total_amount, A.name,A.invoice_no, A.invoice_date, A.grand_total as quotation_amount,B.amount'); $this->db->from('invoice A'); $this->db->join('invoice_payments B','B.invoice_id = A.id'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('B.delete_status','ACTIVE'); $this->db->where('B.invoice_id',$val->id); $this->db->where('A.id',$val->id); $this->db->where('A.name', $name); $query=$this->db->get(); $query= $query->row(); if(!empty($query)){ if($i == 0) { $data['balance_amount'] = $query->quotation_amount; $data['paid_amount'] = $query->amount; $originalDate = $query->invoice_date; $newDate = date("d-m-Y", strtotime($originalDate)); $data['date'] = $newDate; $data['invoice_no'] = $query->invoice_no; $data['name'] = $query->name; $pending_amonut = ($query->quotation_amount - $query->amount); $data['pending_amount'] = $pending_amonut; } else { $data['balance_amount'] = $query->quotation_amount; $data['paid_amount'] = $query->amount; $originalDate = $query->invoice_date; $newDate = date("d-m-Y", strtotime($originalDate)); $data['date'] = $newDate; $data['invoice_no'] = $query->invoice_no; $pending_amonut = ($data['balance_amount'] - $data['paid_amount']); $data['pending_amount'] = $pending_amonut; $data['name'] = $query->name; } array_push($res_array,$data); $i = $i + 1; } }else { $this->db->select('A.total_amount, A.name,A.invoice_no, A.invoice_date, B.amount, A.grand_total as quotation_amount'); $this->db->from('invoice A'); $this->db->join('invoice_payments B','B.invoice_id = A.id'); //$this->db->join('quotations C','A.quotation_id = C.quotation_id'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('B.delete_status','ACTIVE'); //$this->db->where('C.delete_status','ACTIVE'); //$this->db->where('C.quotation_id',$quotation_id); //$this->db->where('A.quotation_id',$quotation_id); $this->db->where('B.invoice_id',$val->id); $this->db->where('A.id',$val->id); $this->db->where('A.name', $name); $query=$this->db->get(); $query= $query->row(); if(!empty($query)){ if($i == 0) { $data['balance_amount'] = $query->quotation_amount; $data['paid_amount'] = $query->amount; $originalDate = $query->invoice_date; $newDate = date("d-m-Y", strtotime($originalDate)); $data['date'] = $newDate; $data['invoice_no'] = $query->invoice_no; $data['name'] = $query->name; $pending_amonut = ($query->quotation_amount - $query->amount); $data['pending_amount'] = $pending_amonut; } else { $data['balance_amount'] = $query->quotation_amount; $data['paid_amount'] = $query->amount; $originalDate = $query->invoice_date; $newDate = date("d-m-Y", strtotime($originalDate)); $data['date'] = $newDate; $data['invoice_no'] = $query->invoice_no; $pending_amonut = ($data['balance_amount'] - $data['paid_amount']); $data['pending_amount'] = $pending_amonut; $data['name'] = $query->name; } array_push($res_array,$data); $i = $i + 1; } } } return $res_array; } public function get_single_quotation_details($name,$quotation_id,$from) { $this->db->select('*'); $this->db->from('invoice A'); $this->db->join('quotations B','B.quotation_id=A.quotation_id'); $this->db->where('A.quotation_id',$quotation_id); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('B.delete_status','ACTIVE'); $result = $this->db->get(); $result = $result->row(); if($result) { $this->db->select('*'); $this->db->from('invoice_payments A'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('A.invoice_id',$result->id); $query = $this->db->get(); $query = $query->result(); $sum = 0; if($query) { foreach($query as $val) { $sum += $val->amount; } } $array = array(); $data['amount'] = $result->amount; $data['paid_amount'] = $sum; $data['pending'] = $result->amount - $sum; return $data; } } public function get_single_quotation_tax_details($name,$quotation_id,$from) { $this->db->select('*'); $this->db->from('quotations A'); $this->db->where('A.quotation_id',$quotation_id); $this->db->where('A.delete_status','ACTIVE'); $result = $this->db->get(); return $result->row(); } public function search_quotation($val){ $this->db->select('quotations.quotation_number,quotations.client_name,quotations.quotation_id,quotations.amount,quotations.address,quotations.client_name as account_name'); $this->db->from('quotations'); //$this->db->join('new_account', 'new_account.lead_id = quotations.lead_id','left'); $this->db->where('quotations.delete_status','ACTIVE'); //$this->db->where('new_account.delete_status','ACTIVE'); $this->db->like('quotations.client_name', $val); $this->db->group_by(array('quotations.quotation_id')); $query1 = $this->db->get()->result(); if(!empty($query1)){ return $query1; }else{ return 0; } } public function search_invoice_date($date,$status) { $date = new DateTime($date); $formattedDate = $date->format('d-m-Y'); $formattedDate2 = $date->format('Y-m-d'); if($status == 'PENDING') { $this->db->select('*'); $this->db->from('invoice'); $this->db->where('delete_status', 'ACTIVE'); $this->db->where('invoice_status', 'PENDING'); $this->db->order_by('invoice_date','desc'); $this->db->where('invoice_date',$formattedDate2); $query=$this->db->get(); return $query->result(); } else if($status == 'CLEARED') { $this->db->select('*'); $this->db->from('invoice'); $this->db->where('delete_status', 'ACTIVE'); $this->db->where('invoice_status', 'CLEARED'); $this->db->order_by('invoice_date','desc'); $this->db->where('invoice_date',$formattedDate2); $query=$this->db->get(); return $query->result(); } else if($status == 'PARTIAL') { $this->db->select('*'); $this->db->from('invoice'); $this->db->where('delete_status', 'ACTIVE'); $this->db->where('invoice_status', 'PARTIAL'); $this->db->order_by('invoice_date','desc'); $this->db->where('invoice_date',$formattedDate2); $query=$this->db->get(); return $query->result(); } else { // $this->db->select('*'); // $this->db->from('invoice'); // $this->db->join('invoice_payments', 'invoice_payments.invoice_id=invoice.id'); // $this->db->where('invoice.delete_status', 'ACTIVE'); // $this->db->where('invoice_payments.delete_status', 'ACTIVE'); // $this->db->like('invoice_payments.cheque_date',$formattedDate); // $this->db->or_like('invoice_payments.dd_date',$formattedDate); // $this->db->or_like('invoice_payments.online_date',$formattedDate); // $this->db->like('invoice.invoice_date',$formattedDate2); // $this->db->order_by('invoice_date','desc'); // $this->db->where('invoice.invoice_date',$formattedDate2); // $query1 = $this->db->get()->result(); // return $query1; $this->db->select('*'); $this->db->from('invoice'); $this->db->where('delete_status', 'ACTIVE'); $this->db->order_by('invoice_date','desc'); $this->db->where('invoice_date',$formattedDate2); $query=$this->db->get(); return $query->result(); } } /*public function view_invoice_search_payment($table,$id, $date) { $date = new DateTime($date); $formattedDate = $date->format('d-m-Y'); $this->db->select('*'); $this->db->from($table); $where = array('invoice_payments.delete_status' => 'ACTIVE', 'invoice_payments.invoice_id'=>$id); //$this->db->where('invoice_payments.delete_status', 'ACTIVE'); //$this->db->where('invoice_payments.invoice_id', $id); $this->db->where('invoice_payments.cheque_date',$formattedDate); $this->db->or_where('invoice_payments.dd_date',$formattedDate); $this->db->or_where('invoice_payments.online_date',$formattedDate); $query=$this->db->get(); return $query->result(); }*/ public function view_invoice_search_payment($table,$id, $date) { $date = new DateTime($date); $formattedDate = $date->format('d-m-Y'); $this->db->select('*'); $this->db->from($table); $this->db->where('invoice_payments.invoice_id', $id); $this->db->where('invoice_payments.delete_status', 'ACTIVE'); $query=$this->db->get(); $result = $query->result(); $result_array =array(); foreach($result as $val) { if($val->cheque_date == $formattedDate || $val->dd_date == $formattedDate || $val->online_date == $formattedDate) { $pay_result['payment_type']=$val->payment_type; $pay_result['payment_id']=$val->payment_id; $pay_result['favour_of']=$val->favour_of; $pay_result['cheque_no']=$val->cheque_no; $pay_result['cheque_date']=$val->cheque_date; $pay_result['dd_no']=$val->dd_no; $pay_result['dd_date']=$val->dd_date; $pay_result['utr_no']=$val->utr_no; $pay_result['online_date']=$val->online_date; $pay_result['bank_name']=$val->bank_name; $pay_result['branch_name']=$val->branch_name; $pay_result['collected_by']=$val->collected_by; $pay_result['amount']=$val->amount; $invoce_amount=number_format($val->amount); $pay_result['paid_amount']=$invoce_amount; array_push($result_array,$pay_result); } } return $result_array; // return $query->result(); // $query ="(SELECT * FROM invoice_payments WHERE invoice_payments.delete_status='ACTIVE' AND invoice_payments.invoice_id=$id AND (invoice_payments.cheque_date=$formattedDate OR invoice_payments.dd_date=$formattedDate OR invoice_payments.online_date=$formattedDate))"; // $result = $this->db->query($query); // $result = $result->result(); // return $result; } public function get_all_mail_from_user(){ $this->db->select('*'); $this->db->from('users'); $this->db->where('users.delete_status','ACTIVE'); $result=$this->db->get(); return $result->result(); } ////////////////////////leads//// shree//////////////////////// public function get_converted_status_new_leads($id){ $this->db->select('invoice.*,quotations.quotation_number,quotations.quo_date'); $this->db->from('invoice'); $this->db->join('new_account','new_account.account_id=invoice.account_id','left'); $this->db->join('quotations','quotations.quotation_id=invoice.quotation_id','left'); $this->db->join('leads','leads.lead_id=new_account.lead_id OR leads.lead_id=quotations.lead_id'); $this->db->where('leads.lead_id',$id); $this->db->where('invoice.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function get_quotation_details_lead($id) { $this->db->select('*'); $this->db->from('leads'); $this->db->join('quotations','leads.lead_id=quotations.lead_id'); $this->db->where('leads.lead_id',$id); $this->db->where('leads.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function get_proforma_id() { $this->db->select('*'); $this->db->from('invoice'); $this->db->where('delete_status','ACTIVE'); $this->db->where('invoice_type','Profomo'); $this->db->order_by('id','DESC'); $this->db->limit(1); $query = $this->db->get(); return $query->row(); } public function get_cash_id() { $this->db->select('*'); $this->db->from('invoice'); $this->db->where('delete_status','ACTIVE'); $this->db->where('invoice_type','Cash'); $this->db->order_by('id','DESC'); $this->db->limit(1); $query = $this->db->get(); return $query->row(); } public function get_cash_id_new() { $this->db->select('*'); $this->db->from('invoice_numbers'); $this->db->where('delete_status','ACTIVE'); $this->db->where('invoice_type','CASH'); $this->db->order_by('number_id','DESC'); $this->db->limit(1); $query = $this->db->get(); return $query->row(); } public function auto_complete_paymeny_by_name($keyword) { $this->db->distinct(); $this->db->select('first_name,last_name,emp_id'); //$this->db->order_by('first_name', 'DESC'); $this->db->like("first_name", $keyword); $this->db->or_like("last_name", $keyword); $this->db->from('employees'); $query= $this->db->get(); return $query->result(); } public function contact_list1_potentials($id){ $this->db->select('*'); $this->db->from('new_potential'); $this->db->join('new_contact','new_contact.contact_owner = new_potential.potential_owner'); $this->db->join('users','new_potential.potential_owner = users.user_id'); $this->db->where('new_potential.potential_id',$id); $this->db->group_by(array('new_potential.potential_id')); $result=$this->db->get(); return $result->result(); } public function amc_notification_count(){ // Current date $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $current_date = $date->format('Y-m-d'); // previous date $date = new \DateTime('+15 days'); // Alternatively, store the string in a variable $back_date_result = $date->format('Y-m-d'); // get in between dates datas $from = " from new_account A "; $where = " where "; $select = "select A.*,STR_TO_DATE(A.due_date, '%Y-%m-%d') as due_date"; $where .= " STR_TO_DATE (A.due_date,'%Y-%m-%d') >= STR_TO_DATE('$current_date','%Y-%m-%d') and "; $where .= " STR_TO_DATE (A.due_date,'%Y-%m-%d') <= STR_TO_DATE('$back_date_result','%Y-%m-%d') and"; $where .= " A.delete_status = 'ACTIVE' and "; $where .= " A.rating != 'INACTIVE' and "; $where .= " A.rating != 'Project Cancelled' and"; $where .= " A.view_status = '0'"; $sql = $select.$from.$where; $result = $this->db->query($sql); $result = $result->result(); return $result; } public function amc_notification(){ // Current date $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $current_date = $date->format('Y-m-d'); // previous date $date = new \DateTime('+15 days'); // Alternatively, store the string in a variable $back_date_result = $date->format('Y-m-d'); // get in between dates datas $from = " from new_account A "; $where = " where "; $select = "select A.*,STR_TO_DATE(A.due_date, '%Y-%m-%d') as due_date"; $where .= " STR_TO_DATE (A.due_date,'%Y-%m-%d') >= STR_TO_DATE('$current_date','%Y-%m-%d') and "; $where .= " STR_TO_DATE (A.due_date,'%Y-%m-%d') <= STR_TO_DATE('$back_date_result','%Y-%m-%d') and"; $where .= " A.delete_status = 'ACTIVE' and "; $where .= " A.rating != 'INACTIVE' and "; $where .= " A.rating != 'Project Cancelled'"; //$where .= " A.view_status = '0'"; $sql = $select.$from.$where; $result = $this->db->query($sql); $result = $result->result(); return $result; }public function get_user_details_new() { $this->db->select('*'); $this->db->from('users'); $this->db->where('users.user_type_id!=','1'); $this->db->where('users.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function get_quotation_details_account($id) { $this->db->select('quotations.*'); $this->db->from('quotations'); $this->db->join('new_account','new_account.account_id=quotations.account_id'); $this->db->where('new_account.account_id',$id); $this->db->where('quotations.quatetion_from','Account'); $this->db->where('new_account.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } /* public function get_quotation_details_account($id) { $this->db->select('*'); $this->db->from('new_account'); $this->db->join('quotations','new_account.account_id=quotations.account_id'); $this->db->where('new_account.account_id',$id); $this->db->where('new_account.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); }*/ ////////////////////////leads//////////////////////////// public function verify_potential_email_id($email) { $this->db->select('*'); $this->db->from('new_potential'); $this->db->where('new_potential.email_id',$email); $this->db->where('new_potential.delete_status','ACTIVE'); $result=$this->db->get(); return $result->result(); } public function get_quotation_result_old($id){ $this->db->select('*,quotations.address as quote_add,quotations.description as quote_des,quotations.sub_total as subamount,quotations.amount as q_amount'); $this->db->from('old_quotation_details quotations'); $this->db->join('new_account','new_account.account_id=quotations.account_id','left'); $this->db->join('leads','leads.lead_id=quotations.lead_id','left'); $this->db->join('new_potential','new_potential.potential_id=quotations.potential_id','left'); // $this->db->join('masters','masters.master_id=quotations.package_id','left'); $this->db->where('quotations.delete_status','ACTIVE'); $this->db->where('quotations.quotation_id',$id); $this->db->where('quotations.delete_status','ACTIVE'); $this->db->order_by('quo_date','DESC'); $result=$this->db->get(); return $result->result(); } public function search_quotation_id($qid){ $this->db->select('quotations.client_name,quotations.quotation_id,quotations.amount,quotations.address,quotations.client_name as account_name'); $this->db->from('quotations'); $this->db->join('new_account', 'new_account.lead_id = quotations.lead_id'); $this->db->where('quotations.delete_status','ACTIVE'); $this->db->where('new_account.delete_status','ACTIVE'); $this->db->like('quotations.quotation_id', $qid); $this->db->group_by(array('quotations.quotation_id')); $query1 = $this->db->get()->row(); if(!empty($query1)){ return $query1; }else{ return 0; } } public function search_quotation_id_to_invoice($qid){ $this->db->select('quotations.client_name,quotations.quotation_id,quotations.amount,quotations.address,quotations.client_name as account_name'); $this->db->from('quotations'); $this->db->join('new_account', 'new_account.lead_id = quotations.account_id','left'); $this->db->join('leads', 'leads.lead_id = quotations.lead_id','left'); $this->db->join('new_potential', 'new_potential.potential_id = quotations.potential_id','left'); //$this->db->where('leads.delete_status','ACTIVE'); //$this->db->where('new_potential.delete_status','ACTIVE'); //$this->db->where('quotations.delete_status','ACTIVE'); // $this->db->where('new_account.delete_status','ACTIVE'); $this->db->like('quotations.quotation_id', $qid); $this->db->group_by(array('quotations.quotation_id')); $query1 = $this->db->get()->row(); if(!empty($query1)){ return $query1; }else{ return 0; } } public function get_description_and_price($qid){ $this->db->select('quotations.*'); $this->db->from('quotations'); $this->db->where('quotations.delete_status','ACTIVE'); $this->db->like('quotations.quotation_id', $qid); $query1 = $this->db->get()->row(); if(!empty($query1)){ return $query1; }else{ return 0; } } //-------lead list------------------------------------------// public function fetch_contacted_leads() { $this->db->select('leads.*,leads.created_at as c_date,b.user_name'); $this->db->from('leads'); $this->db->join('users b','b.user_id =leads.lead_owner'); $this->db->where('lead_status','Contacted'); $this->db->where('lead_convert !=','CLOSED'); $this->db->where('leads.delete_status','ACTIVE'); $this->db->order_by('leads.created_at','DESC'); $result=$this->db->get(); return $result->result(); } public function fetch_closed_leads() { $this->db->select('leads.*,leads.created_at as c_date,b.user_name'); $this->db->from('leads'); $this->db->join('users b','b.user_id =leads.lead_owner'); $this->db->where('lead_convert','CLOSED'); $this->db->where('leads.delete_status','ACTIVE'); $this->db->order_by('leads.created_at','DESC'); $result=$this->db->get(); return $result->result(); } public function fetch_converted_leads() { $this->db->select('leads.*,leads.created_at as c_date,b.user_name'); $this->db->from('leads'); $this->db->join('users b','b.user_id =leads.lead_owner'); $this->db->where('converted_next_level','ACONVERT'); $this->db->or_where('converted_next_level','PCONVERT'); $this->db->or_where('lead_convert','PCONVERTED'); $this->db->order_by('leads.created_at','DESC'); $result=$this->db->get(); return $result->result(); } //---------------------------companies--------------------------------// public function search_company_account($val) { $this->db->select('*,leads.company_name as acc_comp_name'); $this->db->from('new_account'); $this->db->join('users','users.user_id =new_account.account_owner','left'); $this->db->join('roles','roles.role_id=new_account.role_id','left'); $this->db->join('leads','leads.lead_id=new_account.lead_id','left'); $this->db->like('new_account.account_name',$val); $this->db->order_by('new_account.account_name','asc'); $result=$this->db->get(); return $result->result(); } public function get_searched_company_details($company_name,$account_id) { $this->db->select('*,leads.company_name as acc_comp_name'); $this->db->from('new_account'); $this->db->join('users','users.user_id =new_account.account_owner','left'); $this->db->join('roles','roles.role_id=new_account.role_id','left'); $this->db->join('leads','leads.lead_id=new_account.lead_id','left'); $this->db->where('new_account.account_id',$account_id); $result=$this->db->get(); return $result->row(); } public function fetch_single_company_details($company_id) { $this->db->select('*'); $this->db->from('companies'); $this->db->where('company_id',$company_id); $result=$this->db->get(); return $result->row(); } //------------------------------------------------------------------------// public function get_single_invoice_payment_details($invoice_id) { $this->db->select('A.total_amount, A.name,A.invoice_no, A.invoice_date, A.grand_total as quotation_amount,B.amount,B.payment_type,B.created_at as added_date'); $this->db->from('invoice A'); $this->db->join('invoice_payments B','B.invoice_id = A.id'); $this->db->where('A.delete_status','ACTIVE'); $this->db->where('B.delete_status','ACTIVE'); $this->db->where('B.invoice_id',$invoice_id); $query=$this->db->get(); return $query->result(); } public function get_old_quotations($quotation_id) { $this->db->select('A.*,B.tax_state'); $this->db->from('old_quotation_details A'); $this->db->where('A.id',$quotation_id); $this->db->join('quotations B','B.quotation_id=A.quotation_id'); $result=$this->db->get(); return $result->row(); } public function get_quotation_amount_details_potential($id) { $this->db->select('*,quotations.amount as q_amount'); $this->db->from('quotations'); $this->db->join('new_potential','new_potential.potential_id=quotations.potential_id'); $this->db->where('new_potential.potential_id',$id); $this->db->where('quotations.delete_status','ACTIVE'); $query=$this->db->get(); return $query->result(); } public function source_details() { $this->db->select('*'); $this->db->from('lead_source'); $result = $this->db->get(); return $result->result(); // Returns an array of objects } public function get_employee_by_id($id) { return $this->db->where('emp_id', $id)->get('employees')->row(); } public function update_employee_documents($id, $documents) { $this->db->where('emp_id', $id); $this->db->set('documents', $documents); return $this->db->update('employees'); // Returns true on success, false on failure } }?>