?
Current Path : /home1/savoy/public_html/savoyglobal.net/sgms/application/models/ |
Linux gator3171.hostgator.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64 |
Current File : /home1/savoy/public_html/savoyglobal.net/sgms/application/models/salesmodel.php |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Salesmodel extends CI_Model { function __construct() { // Call the Model constructor parent::__construct(); } function add($postdata) { $data=array(); $data['resfunction']=$postdata['resfunction']; $table = $postdata['tab_name']; unset ($postdata['tab_name']); unset ($postdata['resfunction']); $res=$this->db->insert($table,$postdata); $cnt=$this->db->insert_id(); if($res>0) { $data['res']=1; $data['msg']='Record Added Successfully'; } else { $data['res']=0; $data['msg']='Error On Adding Record'; } return $data; } /*Search function starts here*/ function search_employeecustomer($pagenum) { $data=array(); if($this->mastermodel->check_private()) { $flag=1; } else { $flag=0; } $this->db->from('employeecustomer'); $this->db->join('employee','employee.employee_id=employeecustomer.employee_id'); $this->db->join('customer','customer.customer_id=employeecustomer.customer_id'); $postdata=$_SESSION['searchdata']; if(!empty($postdata)) { $searchtext=$postdata['searchtext']; $searchfield=$postdata['searchopt']; $this->db->like($searchfield, $searchtext); } $count= $this->db->count_all_results(); $arr=$this->fpaginate->paginate($pagenum,$count); $data['startpage']=$arr[0]; $data['endpage']=$arr[1]; $start=$arr[2]; $perpage=$arr[3]; $data['count']=$count; if(!empty($postdata)) { $searchtext=$postdata['searchtext']; $searchfield=$postdata['searchopt']; $this->db->like($searchfield, $searchtext); } $this->db->select('*'); $this->db->from('employeecustomer'); $this->db->join('employee','employee.employee_id=employeecustomer.employee_id'); $this->db->join('customer','customer.customer_id=employeecustomer.customer_id'); if($flag==1) { $this->db->join('master','master.masterid=employeecustomer.employeecustomer_id'); $this->db->where('`master`.`owner_id` IN ('.$_SESSION['employees'].')', NULL, FALSE); } $this->db->limit($perpage, $start); $this->db->order_by('employeecustomer_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_employeecustomer($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata($postdata['employee_id']); $customer_allocation_date = $this->mastermodel->convertdateformat($postdata['customer_allocation_date']); $tblValues=array('employeecustomer_id'=>$masterid, 'customer_allocation_date'=>$customer_allocation_date, 'customer_id'=>$postdata['customer_id'], 'description'=>$postdata['description'], 'employee_id'=>$postdata['employee_id']); $this->db->insert('employeecustomer', $tblValues); $this->mastermodel->updatemasterdata($postdata['customer_id'],$postdata['employee_id']); $data['resfunction']='search_employeecustomer'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_employeecustomer($postdata) { $data=array(); $this->db->trans_begin(); $this->mastermodel->updatemasterdata($postdata['employeecustomer_id']); $customer_allocation_date = $this->mastermodel->convertdateformat($postdata['customer_allocation_date']); $tblValues=array('description'=>$postdata['description'], 'customer_allocation_date'=>$customer_allocation_date); $this->db->where('employeecustomer_id', $postdata['employeecustomer_id']); $this->db->update('employeecustomer', $tblValues); $data['resfunction']='search_employeecustomer'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } function search_sales_lead($pagenum) { $data=array(); if($this->mastermodel->check_private()) { $flag=1; } else { $flag=0; } $this->db->from('sales_lead'); $this->db->join('employee','employee.employee_id=sales_lead.employee_id'); $this->db->join('activity','activity.activity_id=sales_lead.activity_id'); $postdata=$_SESSION['searchdata']; if(!empty($postdata)) { $searchtext=$postdata['searchtext']; $searchfield=$postdata['searchopt']; $this->db->like($searchfield, $searchtext); } $count= $this->db->count_all_results(); $arr=$this->fpaginate->paginate($pagenum,$count); $data['startpage']=$arr[0]; $data['endpage']=$arr[1]; $start=$arr[2]; $perpage=$arr[3]; $data['count']=$count; if(!empty($postdata)) { $searchtext=$postdata['searchtext']; $searchfield=$postdata['searchopt']; $this->db->like($searchfield, $searchtext); } $this->db->select('*'); $this->db->from('sales_lead'); $this->db->join('employee','employee.employee_id=sales_lead.employee_id'); $this->db->join('activity','activity.activity_id=sales_lead.activity_id'); if($flag==1) { $this->db->join('master','master.masterid=sales_lead.sales_lead_id'); $this->db->where('`master`.`owner_id` IN ('.$_SESSION['employees'].')', NULL, FALSE); } $this->db->limit($perpage, $start); $this->db->order_by('sales_lead_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_sales_lead($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata($postdata['employee_id']); $date = $this->mastermodel->convertdateformat($postdata['date']); $tblValues=array('sales_lead_id'=>$masterid, 'date'=>$date, 'lead_name'=>$postdata['lead_name'], 'email'=>$postdata['email'], 'contact_no'=>$postdata['contact_no'], 'remarks'=>$postdata['remarks'], 'status'=>$postdata['status'], 'activity_id'=>$postdata['activity_id'], 'employee_id'=>$postdata['employee_id']); $this->db->insert('sales_lead', $tblValues); $data['resfunction']='search_sales_lead'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_sales_lead($postdata) { $data=array(); $this->db->trans_begin(); $this->mastermodel->updatemasterdata($postdata['sales_lead_id']); $date = $this->mastermodel->convertdateformat($postdata['date']); $tblValues=array( 'date'=>$date, 'lead_name'=>$postdata['lead_name'], 'email'=>$postdata['email'], 'contact_no'=>$postdata['contact_no'], 'remarks'=>$postdata['remarks'], 'status'=>$postdata['status'], 'activity_id'=>$postdata['activity_id']); $this->db->where('sales_lead_id', $postdata['sales_lead_id']); $this->db->update('sales_lead', $tblValues); $data['resfunction']='search_sales_lead'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function search_employee_target($pagenum) { $data=array(); if($this->mastermodel->check_private()) { $flag=1; } else { $flag=0; } $this->db->from('employee_target'); $this->db->join('employee','employee.employee_id=employee_target.employee_id'); $postdata=$_SESSION['searchdata']; if(!empty($postdata)) { $searchtext=$postdata['searchtext']; $searchfield=$postdata['searchopt']; $this->db->like($searchfield, $searchtext); } $count= $this->db->count_all_results(); $arr=$this->fpaginate->paginate($pagenum,$count); $data['startpage']=$arr[0]; $data['endpage']=$arr[1]; $start=$arr[2]; $perpage=$arr[3]; $data['count']=$count; if(!empty($postdata)) { $searchtext=$postdata['searchtext']; $searchfield=$postdata['searchopt']; $this->db->like($searchfield, $searchtext); } $this->db->select('*'); $this->db->from('employee_target'); $this->db->join('employee','employee.employee_id=employee_target.employee_id'); if($flag==1) { $this->db->join('master','master.masterid=employee_target.employee_target_id'); $this->db->where('`master`.`owner_id` IN ('.$_SESSION['employees'].')', NULL, FALSE); } $this->db->limit($perpage, $start); $this->db->order_by('employee_target_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_employee_target($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata($postdata['employee_id']); $start_date = $this->mastermodel->convertdateformat($postdata['start_date']); $end_date = $this->mastermodel->convertdateformat($postdata['end_date']); $tblValues=array('employee_target_id'=>$masterid, 'start_date'=>$start_date, 'end_date'=>$end_date, 'currency_id'=>$postdata['currency_id'], 'employee_id'=>$postdata['employee_id'], 'target'=>$postdata['target'], 'remarks'=>$postdata['remarks'], 'target_type'=>$postdata['target_type']); $this->db->insert('employee_target', $tblValues); $data['resfunction']='search_employee_target'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_employee_target($postdata) { $data=array(); $this->db->trans_begin(); $this->mastermodel->updatemasterdata($postdata['employee_target_id']); $start_date = $this->mastermodel->convertdateformat($postdata['start_date']); $end_date = $this->mastermodel->convertdateformat($postdata['end_date']); $tblValues=array('start_date'=>$start_date, 'end_date'=>$end_date, 'remarks'=>$postdata['remarks'], 'target'=>$postdata['target']); $this->db->where('employee_target_id', $postdata['employee_target_id']); $this->db->update('employee_target', $tblValues); $data['resfunction']='search_employee_target'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } function search_branch_target($pagenum) { $data=array(); $this->db->from('branch_target'); $this->db->join('branch','branch.branch_id=branch_target.branch_id'); $postdata=$_SESSION['searchdata']; if(!empty($postdata)) { $searchtext=$postdata['searchtext']; $searchfield=$postdata['searchopt']; $this->db->like($searchfield, $searchtext); } $count= $this->db->count_all_results(); $arr=$this->fpaginate->paginate($pagenum,$count); $data['startpage']=$arr[0]; $data['endpage']=$arr[1]; $start=$arr[2]; $perpage=$arr[3]; $data['count']=$count; if(!empty($postdata)) { $searchtext=$postdata['searchtext']; $searchfield=$postdata['searchopt']; $this->db->like($searchfield, $searchtext); } $this->db->select('*'); $this->db->from('branch_target'); $this->db->join('branch','branch.branch_id=branch_target.branch_id'); $this->db->limit($perpage, $start); $this->db->order_by('branch_target_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_branch_target($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $start_date = $this->mastermodel->convertdateformat($postdata['start_date']); $end_date = $this->mastermodel->convertdateformat($postdata['end_date']); $tblValues=array('branch_target_id'=>$masterid, 'start_date'=>$start_date, 'end_date'=>$end_date, 'currency_id'=>$postdata['currency_id'], 'branch_id'=>$postdata['branch_id'], 'target'=>$postdata['target'], 'remarks'=>$postdata['remarks'], 'target_type'=>$postdata['target_type']); $this->db->insert('branch_target', $tblValues); $data['resfunction']='search_branch_target'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_branch_target($postdata) { $data=array(); $this->db->trans_begin(); $this->mastermodel->updatemasterdata($postdata['branch_target_id']); $start_date = $this->mastermodel->convertdateformat($postdata['start_date']); $end_date = $this->mastermodel->convertdateformat($postdata['end_date']); $tblValues=array( 'start_date'=>$start_date, 'end_date'=>$end_date, 'remarks'=>$postdata['remarks'], 'target'=>$postdata['target']); $this->db->where('branch_target_id', $postdata['branch_target_id']); $this->db->update('branch_target', $tblValues); $data['resfunction']='search_branch_target'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } function search_daily_activity($pagenum) { $data=array(); if($this->mastermodel->check_private()) { $flag=1; } else { $flag=0; } $this->db->from('daily_activity'); $this->db->join('employee','employee.employee_id=daily_activity.employee_id'); $postdata=$_SESSION['searchdata']; if(!empty($postdata)) { $searchtext=$postdata['searchtext']; $searchfield=$postdata['searchopt']; $this->db->like($searchfield, $searchtext); } $count= $this->db->count_all_results(); $arr=$this->fpaginate->paginate($pagenum,$count); $data['startpage']=$arr[0]; $data['endpage']=$arr[1]; $start=$arr[2]; $perpage=$arr[3]; $data['count']=$count; if(!empty($postdata)) { $searchtext=$postdata['searchtext']; $searchfield=$postdata['searchopt']; $this->db->like($searchfield, $searchtext); } $this->db->select('*'); $this->db->from('daily_activity'); $this->db->join('employee','employee.employee_id=daily_activity.employee_id'); if($flag==1) { $this->db->join('master','master.masterid=daily_activity.daily_activity_id'); $this->db->where('`master`.`owner_id` IN ('.$_SESSION['employees'].')', NULL, FALSE); } $this->db->limit($perpage, $start); $this->db->order_by('daily_activity_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_daily_activity($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata($postdata['employee_id']); $activity_date = $this->mastermodel->convertdateformat($postdata['activity_date']); $tblValues=array('daily_activity_id'=>$masterid, 'employee_id'=>$postdata['employee_id'], 'activity_date'=>$activity_date, 'remarks'=>$postdata['remarks']); $this->db->insert('daily_activity', $tblValues); $i=1; while(isset($postdata['customer_name'.$i])) { $tblValues=array( 'daily_activity_id'=>$masterid, 'customer_name'=>$postdata['customer_name'.$i], 'contact_person_name'=>$postdata['contact_person_name'.$i], 'time'=>$postdata['time'.$i], 'contact_no'=>$postdata['contact_no'.$i], 'remarks'=>$postdata['remarks'.$i]); $this->db->insert('daily_activity_details', $tblValues); $i++; } $data['resfunction']='search_daily_activity'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_daily_activity($postdata) { $data=array(); $this->db->trans_begin(); $this->mastermodel->updatemasterdata($postdata['daily_activity_id']); $activity_date = $this->mastermodel->convertdateformat($postdata['activity_date']); $tblValues=array( 'activity_date'=>$activity_date, 'remarks'=>$postdata['remarks']); $this->db->where('daily_activity_id', $postdata['daily_activity_id']); $this->db->update('daily_activity', $tblValues); $this->db->where('daily_activity_id',$postdata['daily_activity_id']); $this->db->delete('daily_activity_details'); $i=1; while(isset ($postdata['customer_name'.$i])) { $tblValues=array( 'daily_activity_id'=>$postdata['daily_activity_id'], 'customer_name'=>$postdata['customer_name'.$i], 'contact_person_name'=>$postdata['contact_person_name'.$i], 'time'=>$postdata['time'.$i], 'contact_no'=>$postdata['contact_no'.$i], 'remarks'=>$postdata['remarks'.$i]); $this->db->insert('daily_activity_details', $tblValues); $i++; } $data['resfunction']='search_daily_activity'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } }