?
Current Path : /home1/savoy/public_html/savoyglobal.net/rms/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/rms/application/models/customermodel.php |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Customermodel extends CI_Model { function __construct() { // Call the Model constructor parent::__construct(); } /*functions for profile */ function insertmasterdata($branch_id='') { $time= date("Y-m-d H:i:s"); $tblValues=array('menu_id'=>$_SESSION['current_mode'], 'creator_id'=> $_SESSION['user_id'], 'owner_id'=> $_SESSION['user_id'], 'created_time'=> $time, 'login_type_id'=>$_SESSION['login_type'], 'ip_address'=> $_SERVER['REMOTE_ADDR']); $this->db->insert('master', $tblValues); return mysql_insert_id(); } function get_customer_no($customer_type) { $num=$this->mastermodel->get_num_rows('customer','customer_type',$customer_type); $num++; do { if($customer_type == "Corporate") { $code="CRP"; } else { $code="IDL"; } $customer_no = $code.str_pad($num, 4, "0", STR_PAD_LEFT); $num_rows_customer = $this->mastermodel->number_rows('customer','customer_no',$customer_no); $num++; }while($num_rows_customer!=0); return $customer_no; } /* functions for customer */ function search_customer($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('customer'); $this->db->join('location','location_id=customer_location_id','left'); $this->db->join('master','master_id=customer_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('customer_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_customer($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $customer_type=$postdata['customer_type']; $tblValues=array( 'customer_id'=>$masterid, 'customer_type'=>$customer_type, 'customer_no'=>$postdata['customer_no'], 'customer_name'=>$postdata['customer_name'], 'customer_contact_no'=>$postdata['customer_contact_no'], 'customer_address'=>$postdata['customer_address'], 'customer_pobox'=>$postdata['customer_pobox'], 'customer_location_id'=>$postdata['customer_location_id'], 'customer_country'=>$postdata['customer_country'], 'customer_fax'=>$postdata['customer_fax'], 'customer_email'=>$postdata['customer_email'], 'customer_status'=>$postdata['customer_status'] ); $this->db->insert('customer', $tblValues); if($customer_type=='Corporate') { $tblValues=array( 'customer_id'=>$masterid, 'customer_group_name'=>$postdata['customer_group_name'], 'customer_business_activity'=>$postdata['customer_business_activity'], 'customer_website'=>$postdata['customer_website'] ); $this->db->insert('customer_corporate',$tblValues); $i=1; while(isset($postdata['contact_name'.$i])) { if($postdata['contact_name'.$i]!='') { $tblValues=array( 'customer_id'=>$masterid, 'contact_name'=>$postdata['contact_name'.$i], 'contact_mobile'=>$postdata['contact_mobile'.$i], 'contact_email'=>$postdata['contact_email'.$i], 'contact_phone'=>$postdata['contact_phone'.$i], 'contact_designation'=>$postdata['contact_designation'.$i] ); $this->db->insert('customer_corporate_contacts',$tblValues); } $i++; } } else { $tblValues=array( 'customer_id'=>$masterid, 'customer_dob'=>$this->mastermodel->convertdateformat($postdata['customer_dob']), 'customer_gender'=>$postdata['customer_gender'], 'customer_profession'=>$postdata['customer_profession'], 'customer_marital_status'=>$postdata['customer_marital_status'] ); $this->db->insert('customer_personal',$tblValues); } $parent= $this->mastermodel->get_account_settings('customer','finance_sub_account_settings'); if($parent) { $chart_type_id=$this->mastermodel->get_single_field_value('finance_chart_master','chart_type_id','chart_master_id',$parent); if($this->mastermodel->get_num_rows('finance_chart_master','chart_account_code',$postdata['customer_no'])==0) { $tblValues=array('chart_account_code'=>$postdata['customer_no'], 'chart_account_name'=>$postdata['customer_name'], 'chart_type_id'=>$chart_type_id, 'parent'=>$parent, 'inactive'=>0); $this->db->insert('finance_chart_master', $tblValues); } else { $tblValues=array('chart_account_name'=>$postdata['customer_name'], 'chart_type_id'=>$chart_type_id, 'parent'=>$parent, 'inactive'=>0); $this->db->where('chart_account_code', $postdata['customer_no']); $this->db->update('finance_chart_master', $tblValues); } } $data['resfunction']='search_customer'; 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_customer($postdata) { $data=array(); $this->db->trans_begin(); $customer_type=$postdata['customer_type']; $tblValues=array( 'customer_name'=>$postdata['customer_name'], 'customer_contact_no'=>$postdata['customer_contact_no'], 'customer_address'=>$postdata['customer_address'], 'customer_pobox'=>$postdata['customer_pobox'], 'customer_location_id'=>$postdata['customer_location_id'], 'customer_country'=>$postdata['customer_country'], 'customer_fax'=>$postdata['customer_fax'], 'customer_email'=>$postdata['customer_email'], 'customer_status'=>$postdata['customer_status'] ); $this->db->where('customer_id',$postdata['customer_id']); $this->db->update('customer', $tblValues); $parent= $this->mastermodel->get_account_settings('customer','finance_sub_account_settings'); if($parent) { $chart_type_id=$this->mastermodel->get_single_field_value('finance_chart_master','chart_type_id','chart_master_id',$parent); if($this->mastermodel->get_num_rows('finance_chart_master','chart_account_code',$postdata['customer_no'])==0) { $tblValues=array('chart_account_code'=>$postdata['customer_no'], 'chart_account_name'=>$postdata['customer_name'], 'chart_type_id'=>$chart_type_id, 'parent'=>$parent, 'inactive'=>0); $this->db->insert('finance_chart_master', $tblValues); } else { $tblValues=array('chart_account_name'=>$postdata['customer_name'], 'chart_type_id'=>$chart_type_id, 'parent'=>$parent, 'inactive'=>0); $this->db->where('chart_account_code', $postdata['customer_no']); $this->db->update('finance_chart_master', $tblValues); } } // $tblValues=array('chart_account_name'=>$postdata['customer_name']); // $this->db->where('chart_account_code', $postdata['customer_no']); // $this->db->update('finance_chart_master', $tblValues); if($customer_type=='Corporate') { $tblValues=array( 'customer_group_name'=>$postdata['customer_group_name'], 'customer_business_activity'=>$postdata['customer_business_activity'], 'customer_website'=>$postdata['customer_website'] ); $this->db->where('customer_id',$postdata['customer_id']); $this->db->update('customer_corporate',$tblValues); $this->db->where('customer_id',$postdata['customer_id']); $this->db->delete('customer_corporate_contacts'); $i=1; while(isset($postdata['contact_name'.$i])) { if($postdata['contact_name'.$i]!='') { $tblValues=array( 'customer_id'=>$postdata['customer_id'], 'contact_name'=>$postdata['contact_name'.$i], 'contact_mobile'=>$postdata['contact_mobile'.$i], 'contact_email'=>$postdata['contact_email'.$i], 'contact_phone'=>$postdata['contact_phone'.$i], 'contact_designation'=>$postdata['contact_designation'.$i] ); $this->db->insert('customer_corporate_contacts',$tblValues); } $i++; } } else { $tblValues=array( 'customer_id'=>$postdata['customer_id'], 'customer_dob'=>$this->mastermodel->convertdateformat($postdata['customer_dob']), 'customer_gender'=>$postdata['customer_gender'], 'customer_profession'=>$postdata['customer_profession'], 'customer_marital_status'=>$postdata['customer_marital_status'] ); $this->db->where('customer_id',$postdata['customer_id']); $this->db->update('customer_personal',$tblValues); } $data['resfunction']='search_customer'; 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']='Customer details updated Successfully'; return $data; } } }