?
Current Path : /home1/savoy/public_html/savoyglobal.net/sibsmoved/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 |
Current File : /home1/savoy/public_html/savoyglobal.net/sibsmoved/system/application/models/documentsmodel.php |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');?> <?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ class documentsmodel extends Model { function documentsmodel() { parent::Model(); } function viewtemplate($c_id,$t_id) { // $limtvalue= ($PageNo-1) * $pageSize ."," . $pageSize; $data['results']= $this->db->query("select * from template where cover_id='$c_id' and template_type='$t_id'"); return $data['results']; } function addbrokingslip() { $input=0; $area=0; $combo=0; if(isset($_POST['labelname'])&& isset($_POST['fieldtype'])) { $fieldtype = $_POST['fieldtype']; $cover_id=$_POST['coverid']; $cyear=date('Y'); $labelname=$_POST['labelname']; if (!isset($_POST['currencytype'])) { $ctype=$this->mastermodel->getdatas('default_currency'); $_POST['currencytype']=$ctype[0]['currency_id']; } if(!isset($_POST['desctitle'])&& !isset($_POST['suminsuredtitle'])) { $_POST['desctitle']="Description"; $_POST['suminsuredtitle']="Sum Insured"; } if(!isset($_POST['totalsumtitle'])&& !isset($_POST['total_sumtitle_amount'])) { $_POST['totalsumtitle']=""; $_POST['total_sumtitle_amount']=0; } $this->db->trans_begin();//MANUAL TRANSACTION BEGIN HERE $created_date= date("Y-m-d H:i:s"); $maxval=$this->db->query("SELECT quotation_ref from broking_slip where id in (select max(id) from broking_slip where cover_id='$cover_id')"); $result= $maxval->row(); $code=$result->quotation_ref; $arr=explode('/', $code); $cid=(int)$arr[3]; $maxid=$cid+1; $compquotref=$this->gertquotationreference(); $quotation_ref="$compquotref/$cover_id/$cyear/$maxid"; $qtndate=$this->mastermodel->convdatformat($_POST['quotationdate']); $tblValues=array('customer_id'=>$_POST['cust_id'], 'quotation_ref'=>$quotation_ref, 'cover_id'=>$_POST['coverid'], 'template_header'=>$_POST['template_header'], 'quotation_date'=>$qtndate, 'created_date'=>$created_date, 'currencytype'=>$_POST['currencytype'], 'suminsured_desctitle'=>$_POST['desctitle'], 'suminsured_sumtitle'=>$_POST['suminsuredtitle'], 'total_sumtitle'=>$_POST['totalsumtitle'], 'total_sumtitle_amount'=>$_POST['total_sumtitle_amount']); $this->db->insert('broking_slip', $tblValues); $brokingslip_id=mysql_insert_id(); $query=$this->db->query("insert into quotation values('','$brokingslip_id','$qtndate')") ; for($i=0;$i<sizeof($fieldtype);$i++) { $value=""; switch($fieldtype[$i]) { case 'text': $textOrder=$_POST['textorder']; $value=$_POST['myInputs'. $textOrder[$input]]; $input++; break; case 'textarea': $areaOrder=$_POST['areaorder']; $value=$_POST['myTextAreas'.$areaOrder[$area]]; $area++; break; case 'combobox': $comboOrder=$_POST['comboorder']; if(isset($_POST['myComboBox'.$comboOrder[$combo]])) { $comboval=$_POST['myComboBox'.$comboOrder[$combo]]; if(is_array($comboval)) { $value=implode('~',$comboval); } } $combo++; break; case 'periodofinsurance': $value=$_POST['periodofinsurance']; break; case 'brokerage': $value=$_POST['brokerage']; break; case 'policyfees': $value=$_POST['policyfees']; break; case 'premium': $value=$_POST['premium']; break; default : $value=""; break; } $tblValues=array('broking_slip_id'=>$brokingslip_id, 'labelname'=>$labelname[$i], 'value'=>$value, 'fieldtype'=>$fieldtype[$i]); $this->db->insert('broking_slip_form', $tblValues); } if(isset($_POST['section']) && isset($_POST['section_title'])) { $section=$_POST['section']; $section_title=$_POST['section_title']; $secorder=0; $k=0; for($j=0;$j<sizeof($_POST['section']);$j++) { if(!isset($_POST["totamt".$j])) { $_POST["totamt".$j]=0; } $tblValues=array('broking_slip_id'=>$brokingslip_id, 'section'=>$section[$j], 'section_title'=>$section_title[$j], 'total_suminsured'=>$_POST["totamt".$j]); $this->db->insert('broking_slip_section', $tblValues); $section_id=mysql_insert_id(); if(isset($_POST['desc']) && isset($_POST['sumamt'])) { $amt=$_POST['sumamt']; $desc=$_POST['desc']; $f=0; while($f<= $_POST['seccount'.$secorder]) { $tblValues=array('broking_slip_id'=>$brokingslip_id, 'description'=>$desc[$k], 'amount'=>$amt[$k], 'section_id'=>$section_id); $this->db->insert('broking_slip_sum_insured', $tblValues); $k++; $f++; } $secorder++; } } } if(isset($_POST['ratesection']) && isset($_POST['rate'])) { $ratesection=$_POST['ratesection']; $rate=$_POST['rate']; for($n=0;$n<sizeof($_POST['ratesection']);$n++) { $tblValues=array('broking_slip_id'=>$brokingslip_id, 'ratesection'=>$ratesection[$n], 'rate'=>$rate[$n]); $this->db->insert('broking_slip_rate', $tblValues); } } } if($_POST['isnewadded']=='added') { $inputnew=0; $areanew=0; $combonew=0; $fieldtypenew = $_POST['fieldtypenew']; $labelnamenew = $_POST['labelnamenew']; for($z=0;$z<sizeof($fieldtypenew);$z++) { switch($fieldtypenew[$z]) { case 'text': $textOrdernew=$_POST['textordernew']; $valuenew=$_POST['myInputsnew'. $textOrdernew[$inputnew]]; $inputnew++; break; case 'textarea': $areaOrdernew=$_POST['areaordernew']; $valuenew=$_POST['myTextAreasnew'.$areaOrdernew[$areanew]]; $areanew++; break; case 'combobox' : $comboOrdernew=$_POST['comboordernew']; $valuenew=$_POST['combotextnew'.$comboOrdernew[$combonew]]; //$valuenew=implode('~', $combovalnew); $combonew++; break; default: $value=""; break; } $tblValues=array('broking_slip_id'=>$brokingslip_id, 'labelname'=>$labelnamenew[$z], 'value'=>$valuenew, 'fieldtype'=>$fieldtypenew[$z]); $this->db->insert('broking_slip_form', $tblValues); } } if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); return 0; } else { $this->db->trans_commit(); return 1; } } function getlist($curentpage,$maxpage) { return $this->fpaginate->paginate($curentpage,$maxpage,6); } function search_placingslip($searchopt,$count,$staffids,$searchtext="",$page="",$per_page="") { $data = array(); if ($page) $start = ($page-1)*$per_page; else $start=0; $seropt=explode('~', $searchopt); $staffids=implode(',', $staffids); if ($this->mastermodel->ret_private()) { $condition=' join staffcustomer s on b.customer_id=s.customerid where s.staffid in ('.$staffids.')'; $condition1='join staffcustomer sc on b.customer_id=sc.customerid where sc.staffid in ('.$staffids.') and'; } else { $condition=""; $condition1="where"; } if ($seropt[1]=='placing_slip') { if ($count=='true') { $data['results']= $this->db->query("select distinct b.id from $seropt[1] " . "b $condition1 $seropt[0] like '$searchtext%'"); return $data['results']->num_rows(); } else { $data['results']= $this->db->query("select distinct b.id,b.quotation_date, " . "placing_slip_premiumdetails.premium, insurance_company.company_name, " . "b.quotation_ref,b.template_header,b.customer_id,cover_id, b.remarks " . "from $seropt[1] b join placing_slip_premiumdetails " . "on placing_slip_premiumdetails.placing_slip_id" . " = b.id join insurance_company on insurance_company.id = " . "placing_slip_premiumdetails.insurance_company_id $condition1 $seropt[0] like '%$searchtext%' " . "order by b.id desc limit $start,$per_page"); return $data['results']; } } else if ($seropt[1]=='customers') { if($count=='true') { $sql="select distinct b.id,b.quotation_date,b.customer_id,b.quotation_ref, " . "placing_slip_premiumdetails.premium, insurance_company.company_name," . "b.cover_id,b.template_header,b.quotation_date,b.created_date," . "cp.insured,cc.insured, b.remarks from placing_slip b join placing_slip_premiumdetails " . "on placing_slip_premiumdetails.placing_slip_id" . " = b.id join insurance_company on insurance_company.id = " . "placing_slip_premiumdetails.insurance_company_id left join customer_corp_info " . "cc on b.customer_id =cc.customer_id left join customer_personal_ind " . "cp on b.customer_id =cp.customer_id $condition1 (cc.insured " . "like '$searchtext%' or cp.insured like '%$searchtext%')"; $data['results']=$this->db->query($sql); return $data['results']->num_rows(); } else { $data['results']=$this->db->query("select distinct b.id,b.quotation_date, " . "placing_slip_premiumdetails.premium, insurance_company.company_name," . "b.customer_id,b.quotation_ref,b.cover_id,b.template_header," . "b.quotation_date,b.created_date,cp.insured,cc.insured, b.remarks from " . "placing_slip b join placing_slip_premiumdetails on placing_slip_premiumdetails.placing_slip_id" . " = b.id join insurance_company on insurance_company.id = " . "placing_slip_premiumdetails.insurance_company_id left join " . "customer_corp_info cc on b.customer_id " . "= cc.customer_id left join customer_personal_ind cp on b.customer_id " . "=cp.customer_id $condition1 (cc.insured like '%$searchtext%' " . "or cp.insured like '$searchtext%') order by b.id desc limit $start,$per_page"); return $data['results']; } } else { if ($count=='true') { $data['results']=$this->db->query("select * from placing_slip b join " . "placing_slip_premiumdetails on placing_slip_premiumdetails.placing_slip_id" . " = b.id join insurance_company on insurance_company.id = " . "placing_slip_premiumdetails.insurance_company_id $condition1 " . "$seropt[2] in (select $seropt[3] from $seropt[1] " . "where $seropt[0] like '%$searchtext%')"); return $data['results']->num_rows(); } else { $data['results']=$this->db->query("select distinct b.id,b.quotation_date, " . "placing_slip_premiumdetails.premium, insurance_company.company_name," . "b.quotation_ref,b.template_header,b.customer_id, b.remarks,cover_id " . "from placing_slip b join placing_slip_premiumdetails on placing_slip_premiumdetails.placing_slip_id" . " = b.id join insurance_company on insurance_company.id = " . "placing_slip_premiumdetails.insurance_company_id $condition1 $seropt[2] in (select $seropt[3] " . "from $seropt[1] where $seropt[0] like '%$searchtext%') order " . "by b.id desc limit $start,$per_page"); return $data['results']; } } } function search_brokingslip($searchopt,$count,$staffids,$searchtext="",$page=1,$per_page="") { $data = array(); if($page) $start = ($page-1)*$per_page; else $start=0; $seropt=explode('~', $searchopt); $staffids=implode(',', $staffids); if ($this->mastermodel->ret_private()) { $condition='b join staffcustomer s on b.customer_id=s.customerid where s.staffid in ('.$staffids.')'; $condition1=' join staffcustomer sc on b.customer_id=sc.customerid where sc.staffid in ('.$staffids.') and'; } else { $condition=""; $condition1="where"; } if($seropt[1]=='broking_slip') { if($seropt[0]=='quotation_date') { $searchtext=$this->mastermodel->convdatformat($searchtext); } if($count=='true') { $this->db->like($seropt[0],$searchtext); $results=$this->db->query("select distinct b.id from $seropt[1] b $condition1 $seropt[0] like '%$searchtext%'"); return $results->num_rows(); } else { // $this->db->like($seropt[0],$searchtext); //$this->db->limit($start,$per_page); // echo "select distinct b.id, b.quotation_ref,b.template_header,b.quotation_date,b.customer_id,cover_id from $seropt[1] b $condition1 $seropt[0] like '%$searchtext%'"; $data['results']=$this->db->query("select distinct b.id, b.quotation_ref,b.template_header,b.quotation_date,b.customer_id,cover_id from $seropt[1] b $condition1 $seropt[0] like '%$searchtext%' order by b.id desc limit $start,$per_page "); return $data['results']; } } else if($seropt[1]=='customers') { if($count=='true') { $data['results']=$this->db->query("select distinct b.id,b.quotation_date,b.customer_id,b.quotation_ref,b.cover_id,b.template_header,b.quotation_date,b.created_date,cp.insured,cc.insured from broking_slip b left join customer_corp_info cc on b.customer_id =cc.customer_id left join customer_personal_ind cp on b.customer_id =cp.customer_id $condition1 (cc.insured like '%$searchtext%' or cp.insured like '%$searchtext%')"); return $data['results']->num_rows(); } else { $data['results']=$this->db->query("select distinct b.id,b.customer_id,b.quotation_date,b.quotation_ref,b.cover_id,b.template_header,b.quotation_date,b.created_date,cp.insured,cc.insured from broking_slip b left join customer_corp_info cc on b.customer_id =cc.customer_id left join customer_personal_ind cp on b.customer_id =cp.customer_id $condition1 (cc.insured like '%$searchtext%' or cp.insured like '%$searchtext%') order by b.id desc limit $start,$per_page "); return $data['results']; } } else { if($count=='true') { $data['results']=$this->db->query("select distinct b.id,b.quotation_date, b.quotation_ref,b.template_header,b.customer_id,cover_id from broking_slip b $condition1 $seropt[2] in (select $seropt[3] from $seropt[1] where $seropt[0] like '%$searchtext%') "); return $data['results']->num_rows(); } else { $data['results']=$this->db->query("select distinct b.id,b.quotation_date, b.quotation_ref,b.template_header,b.customer_id,cover_id from broking_slip b $condition1 $seropt[2] in (select $seropt[3] from $seropt[1] where $seropt[0] like '%$searchtext%') order by b.id desc limit $start,$per_page"); return $data['results']; } } } function updatebrokingslip() { $input=0; $area=0; $combo=0; if(isset($_POST['labelname'])&& isset($_POST['fieldtype'])) { $fieldtype = $_POST['fieldtype']; $cover_id=$_POST['coverid']; $brokingslip_id=$_POST['brokingslipid']; $labelname=$_POST['labelname']; $quotation_ref=$_POST['quotation_ref']; if (!isset($_POST['currencytype'])) { $ctype=$this->mastermodel->getdatas('default_currency'); $_POST['currencytype']=$ctype[0]['currency_id']; } if(!isset($_POST['desctitle'])&& !isset($_POST['suminsuredtitle'])) { $_POST['desctitle']="Description"; $_POST['suminsuredtitle']="Sum Insured"; } if(!isset($_POST['totalsumtitle'])&& !isset($_POST['total_sumtitle_amount'])) { $_POST['totalsumtitle']=""; $_POST['total_sumtitle_amount']=0; } $this->db->trans_begin();//MANUAL TRANSACTION BEGIN HERE $qtndate=$this->mastermodel->convdatformat($_POST['quotationdate']); $tblValues=array('customer_id'=>$_POST['cust_id'], 'template_header'=>$_POST['template_header'], 'quotation_date'=>$qtndate, 'currencytype'=>$_POST['currencytype'], 'suminsured_desctitle'=>$_POST['desctitle'], 'suminsured_sumtitle'=>$_POST['suminsuredtitle'], 'total_sumtitle'=>$_POST['totalsumtitle'], 'total_sumtitle_amount'=>$_POST['total_sumtitle_amount']); $this->db->where('id', $brokingslip_id); $this->db->update('broking_slip', $tblValues); $this->db->where('broking_slip_id', $brokingslip_id); $this->db->delete('broking_slip_form'); for($i=0;$i<sizeof($fieldtype);$i++) { $value=""; switch($fieldtype[$i]) { case 'text': $textOrder=$_POST['textorder']; $value=$_POST['myInputs'. $textOrder[$input]]; $input++; break; case 'textarea': $areaOrder=$_POST['areaorder']; $value=$_POST['myTextAreas'.$areaOrder[$area]]; $area++; break; case 'combobox': $comboOrder=$_POST['comboorder']; if(isset($_POST['myComboBox'.$comboOrder[$combo]])) { $comboval=$_POST['myComboBox'.$comboOrder[$combo]]; if(is_array($comboval)) { $value=implode('~',$comboval); } } $combo++; break; case 'periodofinsurance': $value=$_POST['periodofinsurance']; break; case 'brokerage': $value=$_POST['brokerage']; break; case 'policyfees': $value=$_POST['policyfees']; break; case 'premium': $value=$_POST['premium']; break; default : $value=""; break; } $tblValues=array('broking_slip_id'=>$brokingslip_id, 'labelname'=>$labelname[$i], 'value'=>$value, 'fieldtype'=>$fieldtype[$i]); $this->db->insert('broking_slip_form', $tblValues); } if(isset($_POST['section']) && isset($_POST['section_title'])) { $section=$_POST['section']; $section_title=$_POST['section_title']; $secorder=0; $k=0; $this->db->where('broking_slip_id', $brokingslip_id); $this->db->delete('broking_slip_section'); $this->db->where('broking_slip_id', $brokingslip_id); $this->db->delete('broking_slip_sum_insured'); for($j=0;$j<sizeof($_POST['section']);$j++) { if(!isset($_POST["totamt".$j])) { $_POST["totamt".$j]=0; } $tblValues=array('broking_slip_id'=>$brokingslip_id, 'section'=>$section[$j], 'section_title'=>$section_title[$j], 'total_suminsured'=>$_POST["totamt".$j]); $this->db->insert('broking_slip_section', $tblValues); $section_id=mysql_insert_id(); if(isset($_POST['desc']) && isset($_POST['sumamt'])) { $amt=$_POST['sumamt']; $desc=$_POST['desc']; $f=0; while($f<= $_POST['seccount'.$secorder]) { $tblValues=array('broking_slip_id'=>$brokingslip_id, 'description'=>$desc[$k], 'amount'=>$amt[$k], 'section_id'=>$section_id); $this->db->insert('broking_slip_sum_insured', $tblValues); $k++; $f++; } $secorder++; } } } $this->db->where('broking_slip_id', $brokingslip_id); $this->db->delete('broking_slip_rate'); $count=0; if(isset($_POST['ratesection']) && isset($_POST['rate'])) { $ratesection=$_POST['ratesection']; $rate=$_POST['rate']; for($n=0;$n<sizeof($_POST['ratesection']);$n++) { $tblValues=array('broking_slip_id'=>$brokingslip_id, 'ratesection'=>$ratesection[$n], 'rate'=>$rate[$n]); $this->db->insert('broking_slip_rate', $tblValues); } } } if($_POST['isnewadded']=='added') { $inputnew=0; $areanew=0; $combonew=0; $fieldtypenew = $_POST['fieldtypenew']; $labelnamenew = $_POST['labelnamenew']; for($z=0;$z<sizeof($fieldtypenew);$z++) { switch($fieldtypenew[$z]) { case 'text': $textOrdernew=$_POST['textordernew']; $valuenew=$_POST['myInputsnew'. $textOrdernew[$inputnew]]; $inputnew++; break; case 'textarea': $areaOrdernew=$_POST['areaordernew']; $valuenew=$_POST['myTextAreasnew'.$areaOrdernew[$areanew]]; $areanew++; break; case 'combobox' : $comboOrdernew=$_POST['comboordernew']; $valuenew=$_POST['combotextnew'.$comboOrdernew[$combonew]]; //$valuenew=implode('~', $combovalnew); $combonew++; break; default: $value=""; break; } $tblValues=array('broking_slip_id'=>$brokingslip_id, 'labelname'=>$labelnamenew[$z], 'value'=>$valuenew, 'fieldtype'=>$fieldtypenew[$z]); $this->db->insert('broking_slip_form', $tblValues); } } if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); return 0; } else { $this->db->trans_commit(); return 1; } } function updateplacingslip() { $input=0; $area=0; $combo=0; if(isset($_POST['labelname'])&& isset($_POST['fieldtype'])) { $cover_id=$_POST['coverid']; $placingslip_id=$_POST['placingslipid']; $labelname=$_POST['labelname']; $fieldtype=$_POST['fieldtype']; $typeofpolicy=$_POST['policytype']; if (!isset($_POST['currencytype'])) { $ctype=$this->mastermodel->getdatas('default_currency'); $_POST['currencytype']=$ctype[0]['currency_id']; } if(!isset($_POST['desctitle'])&& !isset($_POST['suminsuredtitle'])) { $_POST['desctitle']="Description"; $_POST['suminsuredtitle']="Sum Insured"; } if(!isset($_POST['totalsumtitle'])&& !isset($_POST['total_sumtitle_amount'])) { $_POST['totalsumtitle']=""; $_POST['total_sumtitle_amount']=0; } if (!isset($_POST['premium'])) { $_POST['premium']=0; } if (!isset($_POST['frmdate'])) { $_POST['frmdate']=""; } if (!isset($_POST['todate'])) { $_POST['todate']=""; } if (!isset($_POST['brokerage'])) { $_POST['brokerage']=0; } if(!isset($_POST['policyfees'])) { $_POST['policyfees']=0; } $this->db->trans_begin();//MANUAL TRANSACTION BEGIN HERE $customer_id=$_POST['cust_id']; $template_header=$_POST['template_header']; $quotation_ref=$_POST['quotation_ref']; $tblValues=array('customer_id'=>$_POST['cust_id'], 'template_header'=>$_POST['template_header'], 'typeof_policy'=>$typeofpolicy, 'currencytype'=>$_POST['currencytype'], 'suminsured_desctitle'=>$_POST['desctitle'], 'suminsured_sumtitle'=>$_POST['suminsuredtitle'], 'total_sumtitle'=>$_POST['totalsumtitle'], 'remarks'=>$_POST['description'], 'quotation_date'=>$this->mastermodel->convdatformat($_POST['quotationdate']), 'total_sumtitle_amount'=>$_POST['total_sumtitle_amount']); $this->db->where('id', $placingslip_id); $this->db->update('placing_slip', $tblValues); $tblValues=array( 'premium'=>$_POST['premium'], 'fromdate'=>$this->mastermodel->convdatformat($_POST['frmdate']), 'todate'=>$this->mastermodel->convdatformat($_POST['todate']), 'brokerage'=>$_POST['brokerage'], 'ispercentage'=>$_POST['ispercentage'], 'policy_fees'=>$_POST['policyfees']); $this->db->where('placing_slip_id', $placingslip_id); $this->db->update('placing_slip_premiumdetails', $tblValues); $this->db->where('placing_slip_id', $placingslip_id); $this->db->delete('placing_slip_form'); for($i=0;$i<sizeof($fieldtype);$i++) { $value=""; switch($fieldtype[$i]) { case 'text': $textOrder=$_POST['textorder']; $value=$_POST['myInputs'. $textOrder[$input]]; $input++; break; case 'textarea': $areaOrder=$_POST['areaorder']; $value=$_POST['myTextAreas'.$areaOrder[$area]]; $area++; break; case 'combobox': $comboOrder=$_POST['comboorder']; if(isset($_POST['myComboBox'.$comboOrder[$combo]])) { $comboval=$_POST['myComboBox'.$comboOrder[$combo]]; if(is_array($comboval)) { $value=implode('~',$comboval); } } $combo++; break; default : $value=""; break; } $tblValues=array('placing_slip_id'=>$placingslip_id, 'labelname'=>$labelname[$i], 'value'=>$value, 'fieldtype'=>$fieldtype[$i]); $this->db->insert('placing_slip_form', $tblValues); } if(isset($_POST['section']) && isset($_POST['section_title'])) { $section=$_POST['section']; $section_title=$_POST['section_title']; $secorder=0; $k=0; $this->db->where('placing_slip_id', $placingslip_id); $this->db->delete('placing_slip_section'); $this->db->where('placing_slip_id', $placingslip_id); $this->db->delete('placing_slip_sum_insured'); for($j=0;$j<sizeof($_POST['section']);$j++) { if(!isset($_POST["totamt".$j])) { $_POST["totamt".$j]=0; } $tblValues=array('placing_slip_id'=>$placingslip_id, 'section'=>$section[$j], 'section_title'=>$section_title[$j], 'total_suminsured'=>$_POST["totamt".$j]); $this->db->insert('placing_slip_section', $tblValues); $section_id=mysql_insert_id(); if(isset($_POST['desc']) && isset($_POST['sumamt'])) { $amt=$_POST['sumamt']; $desc=$_POST['desc']; $f=0; while($f<= $_POST['seccount'.$secorder]) { $tblValues=array('placing_slip_id'=>$placingslip_id, 'description'=>$desc[$k], 'amount'=>$amt[$k], 'section_id'=>$section_id); $this->db->insert('placing_slip_sum_insured', $tblValues); $k++; $f++; } $secorder++; } } } $this->db->where('placing_slip_id', $placingslip_id); $this->db->delete('placing_slip_rate'); if(isset($_POST['ratesection']) && isset($_POST['rate'])) { $ratesection=$_POST['ratesection']; $rate=$_POST['rate']; for($n=0;$n<sizeof($_POST['ratesection']);$n++) { $tblValues=array('placing_slip_id'=>$placingslip_id, 'ratesection'=>$ratesection[$n], 'rate'=>$rate[$n]); $this->db->insert('placing_slip_rate', $tblValues); } } } if($_POST['isnewadded']=='added') { $inputnew=0; $areanew=0; $combonew=0; $fieldtypenew = $_POST['fieldtypenew']; $labelnamenew = $_POST['labelnamenew']; for($z=0;$z<sizeof($fieldtypenew);$z++) { switch($fieldtypenew[$z]) { case 'text': $textOrdernew=$_POST['textordernew']; $valuenew=$_POST['myInputsnew'. $textOrdernew[$inputnew]]; $inputnew++; break; case 'textarea': $areaOrdernew=$_POST['areaordernew']; $valuenew=$_POST['myTextAreasnew'.$areaOrdernew[$areanew]]; $areanew++; break; case 'combobox' : $comboOrdernew=$_POST['comboordernew']; $valuenew=$_POST['combotextnew'.$comboOrdernew[$combonew]]; //$valuenew=implode('~', $combovalnew); $combonew++; break; default: $value=""; break; } $tblValues=array('placing_slip_id'=>$placingslip_id, 'labelname'=>$labelnamenew[$z], 'value'=>$valuenew, 'fieldtype'=>$fieldtypenew[$z]); $this->db->insert('placing_slip_form', $tblValues); } } if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); return 0; } else { $this->db->trans_commit(); return $placingslip_id; } } function addplacingslip() { $input=0; $area=0; $combo=0; if(isset($_POST['labelname'])&& isset($_POST['fieldtype'])) { $fieldtype = $_POST['fieldtype']; $cover_id=$_POST['coverid']; $cyear=date('Y'); $labelname=$_POST['labelname']; if (!isset($_POST['currencytype'])) { $ctype=$this->mastermodel->getdatas('default_currency'); $_POST['currencytype']=$ctype[0]['currency_id']; } if(!isset($_POST['desctitle'])&& !isset($_POST['suminsuredtitle'])) { $_POST['desctitle']="Description"; $_POST['suminsuredtitle']="Sum Insured"; } if(!isset($_POST['totalsumtitle'])&& !isset($_POST['total_sumtitle_amount'])) { $_POST['totalsumtitle']=""; $_POST['total_sumtitle_amount']=0; } if (!isset($_POST['premium'])) { $_POST['premium']=0; } if (!isset($_POST['frmdate'])) { $_POST['frmdate']=""; } if (!isset($_POST['todate'])) { $_POST['todate']=""; } if (!isset($_POST['brokerage'])) { $_POST['brokerage']=0; } if(!isset($_POST['policyfees'])) { $_POST['policyfees']=0; } $this->db->trans_begin();//MANUAL TRANSACTION BEGIN HERE $customer_id=$_POST['cust_id']; $template_header=$_POST['template_header']; $typeofpolicy=$_POST['policytype']; $created_date= date("Y-m-d H:i:s"); $quotation_ref=$_POST['quotation_ref']; $quotationdate=$this->mastermodel->convdatformat($_POST['quotationdate']); $tblValues=array('customer_id'=>$_POST['cust_id'], 'quotation_ref'=>$quotation_ref, 'cover_id'=>$_POST['coverid'], 'template_header'=>$_POST['template_header'], 'typeof_policy'=>$typeofpolicy, 'quotation_date'=>$quotationdate, 'created_date'=>$created_date, 'currencytype'=>$_POST['currencytype'], 'suminsured_desctitle'=>$_POST['desctitle'], 'suminsured_sumtitle'=>$_POST['suminsuredtitle'], 'total_sumtitle'=>$_POST['totalsumtitle'], 'remarks'=>$_POST['description'], 'total_sumtitle_amount'=>$_POST['total_sumtitle_amount']); $this->db->insert('placing_slip', $tblValues); $placingslip_id=mysql_insert_id(); $tblValues=array('status'=>'Converted'); $this->db->where('quotation_ref',$quotation_ref); $this->db->update('broking_slip', $tblValues); $tblValues=array('placing_slip_id'=>$placingslip_id, 'premium'=>$_POST['premium'], 'fromdate'=>$this->mastermodel->convdatformat($_POST['frmdate']), 'todate'=>$this->mastermodel->convdatformat($_POST['todate']), 'brokerage'=>$_POST['brokerage'], 'ispercentage'=>$_POST['ispercentage'], 'policy_fees'=>$_POST['policyfees']); $this->db->insert('placing_slip_premiumdetails', $tblValues); for($i=0;$i<sizeof($fieldtype);$i++) { $value=""; switch($fieldtype[$i]) { case 'text': $textOrder=$_POST['textorder']; $value=$_POST['myInputs'. $textOrder[$input]]; $input++; break; case 'textarea': $areaOrder=$_POST['areaorder']; $value=$_POST['myTextAreas'.$areaOrder[$area]]; $area++; break; case 'combobox': $comboOrder=$_POST['comboorder']; if(isset($_POST['myComboBox'.$comboOrder[$combo]])) { $comboval=$_POST['myComboBox'.$comboOrder[$combo]]; if(is_array($comboval)) { $value=implode('~',$comboval); } } $combo++; break; default : $value=""; break; } $tblValues=array('placing_slip_id'=>$placingslip_id, 'labelname'=>$labelname[$i], 'value'=>$value, 'fieldtype'=>$fieldtype[$i]); $this->db->insert('placing_slip_form', $tblValues); } if(isset($_POST['section']) && isset($_POST['section_title'])) { $section=$_POST['section']; $section_title=$_POST['section_title']; $secorder=0; $k=0; for($j=0;$j<sizeof($_POST['section']);$j++) { if(!isset($_POST["totamt".$j])) { $_POST["totamt".$j]=0; } $tblValues=array('placing_slip_id'=>$placingslip_id, 'section'=>$section[$j], 'section_title'=>$section_title[$j], 'total_suminsured'=>$_POST["totamt".$j]); $this->db->insert('placing_slip_section', $tblValues); $section_id=mysql_insert_id(); if(isset($_POST['desc']) && isset($_POST['sumamt'])) { $amt=$_POST['sumamt']; $desc=$_POST['desc']; $f=0; while($f<= $_POST['seccount'.$secorder]) { $tblValues=array( 'placing_slip_id'=>$placingslip_id, 'description'=>$desc[$k], 'amount'=>$amt[$k], 'section_id'=>$section_id); $this->db->insert('placing_slip_sum_insured', $tblValues); $k++; $f++; } $secorder++; } } } if(isset($_POST['ratesection']) && isset($_POST['rate'])) { $ratesection=$_POST['ratesection']; $rate=$_POST['rate']; for($n=0;$n<sizeof($_POST['ratesection']);$n++) { $tblValues=array('placing_slip_id'=>$placingslip_id, 'ratesection'=>$ratesection[$n], 'rate'=>$rate[$n]); $this->db->insert('placing_slip_rate', $tblValues); } } } if($_POST['isnewadded']=='added') { $inputnew=0; $areanew=0; $combonew=0; $fieldtypenew = $_POST['fieldtypenew']; $labelnamenew = $_POST['labelnamenew']; for($z=0;$z<sizeof($fieldtypenew);$z++) { switch($fieldtypenew[$z]) { case 'text': $textOrdernew=$_POST['textordernew']; $valuenew=$_POST['myInputsnew'. $textOrdernew[$inputnew]]; $inputnew++; break; case 'textarea': $areaOrdernew=$_POST['areaordernew']; $valuenew=$_POST['myTextAreasnew'.$areaOrdernew[$areanew]]; $areanew++; break; case 'combobox' : $comboOrdernew=$_POST['comboordernew']; $valuenew=$_POST['combotextnew'.$comboOrdernew[$combonew]]; //$valuenew=implode('~', $combovalnew); $combonew++; break; default: $value=""; break; } $tblValues=array('placing_slip_id'=>$placingslip_id, 'labelname'=>$labelnamenew[$z], 'value'=>$valuenew, 'fieldtype'=>$fieldtypenew[$z]); $this->db->insert('placing_slip_form', $tblValues); } } if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); return 0; } else { $this->db->trans_commit(); return $placingslip_id; } } function insertplacingslippayment() { $pay_mode=$_POST['paymethod']; $this->db->trans_begin(); $premiumdata = array( 'insurance_company_id' => $_POST['insurance_company_id'], 'payment_method' => $pay_mode, 'sum_insured' => $_POST['sum_insured'], ); $this->db->where('placing_slip_id', $_POST['placing_slip_id']); $this->db->update('placing_slip_premiumdetails', $premiumdata); $payslip=$_POST['placing_slip_id']; $this->db->where('placing_slip_id', $_POST['placing_slip_id']); $this->db->delete('placing_slip_stakeholders'); //$reff_id=$this->customermodel->getSingleFieldValue('placing_slip_refs','id','pslip_id',$_POST['placing_slip_id']); $reff_id=$this->getplacingslip_refs($payslip); $oldcrereferenceno= $this->getplacingslip_referenceno($payslip,5); $olddebreferenceno= $this->getplacingslip_referenceno($payslip,6); if(count($reff_id)!=0) { foreach($reff_id as $refval) { $a=$refval['id']; $trans_date = $this->mastermodel->getSingleFieldValue('gl_trans', 'tran_date', 'type_no', $a); $this->db->query('delete from gl_trans where type_no ='.$a); $this->db->query('delete from audit_trail where trans_no ='.$a); $this->db->query('delete from refs where id ='.$a); } $this->db->where('pid', $payslip); $this->db->delete('customer_trans'); $this->db->where('pid', $payslip); $this->db->delete('agent_trans'); $this->db->where('pid', $payslip); $this->db->delete('company_trans'); $this->db->query("delete from placing_slip_refs where pslip_id='$payslip' and type='issue'" ); } /*********************** Add Agent and their commission percentage*****************************/ $tot_brokerage=$_POST['brokerage']; $tot_brokerage_cover=$tot_brokerage; $trans_date=$acctype_val= $this->customermodel->getSingleFieldValue('placing_slip','quotation_date','id',$_POST['placing_slip_id']); if (isset($trans_date) && !empty($trans_date)) { $tdate = $trans_date; } else { $tdate=date('Y-m-d'); } $ispercentage=$_POST['ispercentage']; if (isset($_POST['staffid']) && isset($_POST['brockamt'])) { $refc=$this->accountingsmodel->get_reference_code(5); /************ Insert into refs table and take inserted id **************/ if($oldcrereferenceno) $refc=$oldcrereferenceno; $refdatae=array( 'type'=>'5', 'reference'=>$refc ); $this->db->insert('refs', $refdatae); $refid=$this->db->insert_id() ; /************ Insert into placing slip refs table **************/ $refpdata=array( 'id'=>$refid, 'pslip_id'=>$_POST['placing_slip_id'], 'type'=>'issue' ); $this->db->insert('placing_slip_refs', $refpdata); $fyear=$this->accountingsmodel->fiscalyear(); $insValuesA=array( 'trans_no'=>$refid, 'user'=>$_SESSION['userid'], 'date_trans'=>$tdate, 'fiscal_year'=>$fyear, 'gl_date'=>$tdate ); $this->db->insert('audit_trail', $insValuesA); $staffid=$_POST['staffid']; $pecentageamt=$_POST['brockamt']; $comm_pay_amt=0; for($sff=0;$sff<sizeof($staffid);$sff++) { $preamt1=$_POST['preamt']; $stakedata=array( 'placing_slip_id'=>$_POST['placing_slip_id'], 'staffid'=>$staffid[$sff], 'percentage'=>$pecentageamt[$sff] ); $this->db->insert('placing_slip_stakeholders', $stakedata); if($ispercentage) $agentamt= $preamt1 *($pecentageamt[$sff]/100); else $agentamt= $pecentageamt[$sff]; if($agentamt!=0) { $agent_acc=$_POST['agent_acc'][$sff]; $trans_date=$acctype_val= $this->customermodel->getSingleFieldValue('placing_slip','quotation_date','id',$_POST['placing_slip_id']); $insValuesS=array( 'type_no'=>$refid, 'tran_date'=>$tdate, 'account'=>$agent_acc, 'memo'=>'', 'amount'=>-number_format($agentamt,2, '.', '') ); $insValuesAt=array( 'type_no'=>$refid, 'tran_date'=>$tdate, 'account'=>$agent_acc, 'memo'=>'', 'amount'=>-number_format($agentamt,2, '.', ''), 'pid'=>$_POST['placing_slip_id'] ); $this->db->insert('gl_trans', $insValuesS); $this->db->insert('agent_trans', $insValuesAt); } $tot_brokerage=$tot_brokerage-$pecentageamt[$sff]; $comm_pay_amt+=$agentamt; } $commission_acc=$this->get_commission_pay_acc(); if($comm_pay_amt!=0) { $insValuesCP=array( 'type_no'=>$refid, 'tran_date'=>$tdate, 'account'=>$commission_acc, 'memo'=>'', 'amount'=>number_format($comm_pay_amt,2, '.', '') ); $this->db->insert('gl_trans', $insValuesCP); } } // if payment is to Savoy if ($pay_mode == 'credit') { /********************************insert total premium as customer debit into gl trans************************************/ $preamt=$_POST['preamt']+$_POST['policyfees']; if ($ispercentage==0) { $preamt+=$_POST['brokerage']; } $cust_acc=$_POST['cust_acc']; $refd=$this->accountingsmodel->get_reference_code(6); /************ Insert into refs table and take inserted id **************/ if($olddebreferenceno) $refd=$olddebreferenceno; $refdata=array( 'type'=>'6', 'reference'=>$refd ); $this->db->insert('refs', $refdata); $refid1=$this->db->insert_id() ; /************ Insert into placing slip refs table **************/ $refpdata=array( 'id'=>$refid1, 'pslip_id'=>$_POST['placing_slip_id'], 'type'=>'issue' ); $this->db->insert('placing_slip_refs', $refpdata); $fyear=$this->accountingsmodel->fiscalyear(); $insValuesA1=array( 'trans_no'=>$refid1, 'user'=>$_SESSION['userid'], 'date_trans'=>$tdate, 'fiscal_year'=>$fyear, 'gl_date'=>$tdate ); $this->db->insert('audit_trail', $insValuesA1); $trans_date=$acctype_val= $this->customermodel->getSingleFieldValue('placing_slip','quotation_date','id',$_POST['placing_slip_id']); $insValues=array( 'type_no'=>$refid1, 'tran_date'=>$tdate, 'account'=>$cust_acc, 'memo'=>'', 'amount'=>number_format($preamt,2, '.', '') ); $this->db->insert('gl_trans', $insValues); /********************************insert into customer transaction table*************************************************/ $insValue=array( 'type_no'=>$refid1, 'tran_date'=>$tdate, 'account'=>$cust_acc, 'memo'=>'', 'amount'=>number_format($preamt,2, '.', ''), 'alloc'=>0, 'pid'=>$_POST['placing_slip_id'] ); $this->db->insert('customer_trans', $insValue); /*******************************insert brokerage amount into cover acc in gl trans*************************************/ $brokamount=$_POST['brokerage']; if($ispercentage) $totbrotamt= $_POST['preamt'] *($brokamount/100); else $totbrotamt= $brokamount; $covr_acc=$_POST['covr_acc']; $trans_date=$acctype_val= $this->customermodel->getSingleFieldValue('placing_slip','quotation_date','id',$_POST['placing_slip_id']); $insValues1=array( 'type_no'=>$refid1, 'tran_date'=>$tdate, 'account'=>$covr_acc, 'memo'=>'', 'amount'=>-number_format($totbrotamt,2, '.', '') ); $this->db->insert('gl_trans', $insValues1); /****************************************insert insurer amount into credit as company acc*********************************************/ $compamt=$_POST['comp_amt']; $comp_acc=$this->accountingsmodel->get_acc_id('insurance_company','company_code',$_POST['insurance_company_id']); $insValuesC=array( 'type_no'=>$refid1, 'tran_date'=>$tdate, 'account'=>$comp_acc, 'memo'=>'', 'amount'=>-number_format($compamt,2, '.', '') ); $insValuesC1=array( 'type_no'=>$refid1, 'tran_date'=>$tdate, 'account'=>$comp_acc, 'memo'=>'', 'amount'=>-number_format($compamt,2, '.', ''), 'pid'=>$_POST['placing_slip_id'] ); $this->db->insert('gl_trans', $insValuesC); $this->db->insert('company_trans', $insValuesC1); } // if payment is to insurance company else { $brokamount=$_POST['brokerage']; if($ispercentage) $totbrotamt= $_POST['preamt'] *($brokamount/100); else $totbrotamt= $brokamount; $comp_acc=$this->accountingsmodel->get_acc_id('insurance_company','company_code',$_POST['insurance_company_id']); $refd=$this->accountingsmodel->get_reference_code(6); /************ Insert into refs table and take inserted id **************/ if($olddebreferenceno) $refd=$olddebreferenceno; $refdata=array( 'type'=>'6', 'reference'=>$refd ); $this->db->insert('refs', $refdata); $refid1=$this->db->insert_id() ; /************ Insert into placing slip refs table **************/ $refpdata=array( 'id'=>$refid1, 'pslip_id'=>$_POST['placing_slip_id'], 'type'=>'issue' ); $this->db->insert('placing_slip_refs', $refpdata); $fyear=$this->accountingsmodel->fiscalyear(); $insValuesA1=array( 'trans_no'=>$refid1, 'user'=>$_SESSION['userid'], 'date_trans'=>$tdate, 'fiscal_year'=>$fyear, 'gl_date'=>$tdate ); $this->db->insert('audit_trail', $insValuesA1); $trans_date=$acctype_val= $this->customermodel->getSingleFieldValue('placing_slip','quotation_date','id',$_POST['placing_slip_id']); $insValues=array( 'type_no'=>$refid1, 'tran_date'=>$tdate, 'account'=>$comp_acc, 'memo'=>'', 'amount'=>number_format($totbrotamt,2, '.', '') ); $this->db->insert('gl_trans', $insValues); /********************************insert into ins company transaction table*************************************************/ $insValue=array( 'type_no'=>$refid1, 'tran_date'=>$tdate, 'account'=>$comp_acc, 'memo'=>'', 'amount'=>number_format($totbrotamt,2, '.', ''), 'alloc'=>'', 'pid'=>$_POST['placing_slip_id'] ); $this->db->insert('company_trans', $insValue); /*******************************insert brokerage amount into cover acc in gl trans*************************************/ $covr_acc=$_POST['covr_acc']; $insValues1=array( 'type_no'=>$refid1, 'tran_date'=>$tdate, 'account'=>$covr_acc, 'memo'=>'', 'amount'=>-number_format($totbrotamt,2, '.', '') ); $this->db->insert('gl_trans', $insValues1); } if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); } else { $this->db->trans_commit(); return true; } } function GetPaySlipPayment($id) { $result=$this->db->query("select * from placing_slip_payamount where placing_slip_id='". $id . "'"); return $result; } function placingslippaymentModel() { $pay_mode=$this->input->post('paymethod'); $payslip=$this->input->post('pslipamount'); $tblValues=array('placing_slip_id '=>$this->input->post('pslipamount'),'amount'=>$this->input->post('payamount'),'paydate'=>$this->input->post('paydate'),'paymethod'=>$this->input->post('paymethod')); $this->db->insert('placing_slip_payamount', $tblValues); $payid=mysql_insert_id(); if($pay_mode=='netbank') { $bankname=$_POST['bank_name']; $deposit_no=$_POST['cheque_no']; $acc_no=$_POST['acc_no']; $holder=$_POST['acc_holder']; // echo $bankname.'--'.$deposit_no.'--'.$acc_no.'--'.$holder; $paymentdata=array( 'payment_id'=>$payid, 'deposit_no'=>$deposit_no, 'bank_name'=>$bankname, 'account_number'=>$acc_no, 'account_holder'=>$holder ); $this->db->insert('placing_slip_netbankdetails', $paymentdata); } elseif($pay_mode=='bank') { $bankname=$_POST['bank_name']; $cheque_no=$_POST['cheque_no']; $paymentdata=array( 'payment_id'=>$payid, 'dd_cheque_no'=>$cheque_no, 'bank_name'=>$bankname, ); $this->db->insert('placing_slip_bank', $paymentdata); } } function insertbrokstatus() { $statusdate=$this->mastermodel->convdatformat($this->input->post('statusdate')); $statusdata=array('broking_slip_id'=>$this->input->post('brokingslipid'), 'statusdate'=>$statusdate, 'statusmode'=>$this->input->post('documentmode'), 'address'=>$this->input->post('documentaddress'), 'companyid'=>$this->input->post('companyid'), 'statusresponse'=>$this->input->post('docresponse'), 'statusremarks'=>$this->input->post('docremarks') ); $this->db->insert('broking_slip_status',$statusdata); } function updatebrokstatus() { $data = array('status'=>$this->input->post('brokstatus')); $this->db->where('id', $this->input->post('brokingslipid')); $res=$this->db->update('broking_slip',$data); if($res==1) { echo $this->input->post('brokstatus'); } } function updatebrokingslipstatus() { $statusdate=$this->mastermodel->convdatformat($this->input->post('statusdate')); $statusdata=array('broking_slip_id'=>$this->input->post('brokingslipid'), 'statusdate'=>$statusdate, 'statusmode'=>$this->input->post('documentmode'), 'address'=>$this->input->post('documentaddress'), 'companyid'=>$this->input->post('companyid'), 'statusresponse'=>$this->input->post('docresponse'), 'statusremarks'=>$this->input->post('docremarks') ); $this->db->where('id',$this->input->post('brokingslipstatusid')); $this->db->update('broking_slip_status',$statusdata); } function insertplacstatus() { $statusdata=array('placing_slip_id'=>$this->input->post('placingslipid'), 'statusdate'=>$this->input->post('statusdate'), 'statusmode'=>$this->input->post('documentmode'), 'address'=>$this->input->post('documentaddress'), 'statusresponse'=>$this->input->post('docresponse'), 'statusremarks'=>$this->input->post('docremarks') ); $this->db->insert('placing_slip_status',$statusdata); } function updateplacstatus() { $data = array('status'=>$this->input->post('placstatus')); $this->db->where('id', $this->input->post('placingslipid')); $res=$this->db->update('placing_slip',$data); if($res==1) { echo $this->input->post('placstatus'); } } function updateplacingslipstatus() { $statusdata=array('placing_slip_id'=>$this->input->post('placingslipid'), 'statusdate'=>$this->input->post('statusdate'), 'statusmode'=>$this->input->post('documentmode'), 'address'=>$this->input->post('documentaddress'), 'statusresponse'=>$this->input->post('docresponse'), 'statusremarks'=>$this->input->post('docremarks') ); $this->db->where('id',$this->input->post('placingslipstatusid')); $this->db->update('placing_slip_status',$statusdata); } function count_alls($table,$field,$value="") { $res=$this->db->query("select * from ".$table." where ". $field . " like '". $value . "%'" ); return $res->num_rows(); } function editdata_pslip($table) { $id=$this->input->post('id'); $amount=$this->input->post('editamount'); $date=$this->input->post('editdate'); $paymethod=$this->input->post('paymethod'); if($amount!="" && $date!="") { $tblValues=array('paydate'=>$date,'amount'=>$amount,'paymethod'=>$paymethod); $this->db->where('id',$id); $this->db->update($table, $tblValues); echo "Updated Sucessfully"; } $bname=$this->input->post('bname'); $ch_no=$this->input->post('ch_no'); $accno=$this->input->post('accno'); $acchol=$this->input->post('acchol'); if($paymethod!="cash" && $paymethod!='') { if($paymethod=='netbank') { $fields=array('deposit_no'=>$ch_no,'bank_name'=>$bname,'account_number'=>$accno,'account_holder'=>$acchol); $this->db->where('payment_id',$id); $this->db->update('placing_slip_netbankdetails', $fields); } else { $fields=array('dd_cheque_no'=>$ch_no,'bank_name'=>$bname); $this->db->where('payment_id',$id); $this->db->update('placing_slip_bank', $fields); } } } function count_allds($table,$field,$value="") { $staffids=$this->mastermodel->tracestaff(); $staffids=implode(',', $staffids); $condition="where"; $where=" $field like '$value%' "; $qry="SELECT distinct datasheet.id,datasheet.coverid,covers.cover , segment_insurances.segment FROM datasheet INNER JOIN covers ON (datasheet.coverid = covers.id) INNER JOIN segment_insurances ON (covers.segment_id = segment_insurances.id) ".$condition. $where; $res=$this->db->query($qry); return $res->num_rows(); } function deletepsliptabledata($table,$id) { $res=$this->db->delete($table,array('payment_id'=> $id)); if($res>0) { return 1; } else { return 0; } } function get_data_srow($table,$id,$field,$sortfield="") { $data = array(); $this->db->where($field,$id); if(!empty($sortfield)) { $this->db->order_by($sortfield,'asc'); } $Q= $this->db->get($table); //$row=$Q->row(); foreach ($Q->result_array() as $row) { $data[] = $row; } return $data; } function Getquotation($pageno,$field,$value="") { $staffids=$this->mastermodel->tracestaff(); $staffids=implode(',', $staffids); if ($this->mastermodel->ret_private()) { $condition=' join staffcustomer s on customers.id=s.customerid where s.staffid in ('.$staffids.') and'; } else { $condition="where"; } if($field=="insured") { $where=" (customer_corp_info.insured like '$value%' or customer_personal_ind.insured like '$value%')"; } else { $where=" $field like '$value%' "; } $limit=(($pageno-1) * 10); $data=array(); $qry="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) ".$condition. $where. " order by quotation.id desc limit " . $limit .",10 " ; $res=$this->db->query($qry); return $res->result_array(); } function count_allquotation($table,$field,$value="") { $staffids=$this->mastermodel->tracestaff(); $staffids=implode(',', $staffids); if ($this->mastermodel->ret_private()) { $condition=' join staffcustomer s on customers.id=s.customerid where s.staffid in ('.$staffids.') and'; } else { $condition="where"; } if($field=="insured") { $where=" (customer_corp_info.insured like '$value%' or customer_personal_ind.insured like '$value%')"; } else { $where=" $field like '$value%' "; } $res=$this->db->query("SELECT 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) ".$condition. $where ); return $res->num_rows(); } function addquotation() { $query=$this->db->query("insert into quotation values('','$_POST[broid]','$_POST[issueDate]')") ; $quoteid=mysql_insert_id(); if($query>0) { return 1; } else { return 0; } } function updatequotation($table) { $this->db->query("update $table set brokingslip='$_POST[broid]',date='$_POST[issueDate]' where id='$_POST[qid]'"); // echo $query; } function adddatasheet() { $query=$this->db->query("insert into datasheet values('','$_POST[cover_id]')") ; $dsid=mysql_insert_id(); if($query>0) { return 1; } else { return 0; } } function Getdatasheet($pageno,$field,$value="") { $limit=(($pageno-1) * 10); $data=array(); $staffids=$this->mastermodel->tracestaff(); $staffids=implode(',', $staffids); $condition="where"; $where=" $field like '$value%' "; $qry="SELECT distinct datasheet.id,datasheet.coverid , covers.cover , segment_insurances.segment FROM datasheet INNER JOIN covers ON (datasheet.coverid = covers.id) INNER JOIN segment_insurances ON (covers.segment_id = segment_insurances.id) ".$condition. $where. " limit " . $limit .",10"; $res=$this->db->query($qry); return $res->result_array(); } function updatedatasheet($table) { $this->db->query("update $table set coverid='$_POST[cover_id]' where id='$_POST[dsid]'"); } function get_datasheet_data($id) { $qry="SELECT datasheet.id,datasheet.coverid, covers.cover , segment_insurances.segment as segmentname FROM datasheet INNER JOIN covers ON (datasheet.coverid = covers.id) INNER JOIN segment_insurances ON (covers.segment_id = segment_insurances.id) where datasheet.id= " . $id ; $res=$this->db->query($qry); return $res->result_array(); } function get_debitdata($id) { $sql = " SELECT IFNULL(customer_corp_info.insured , customer_personal_ind.insured) as insured , covers.cover , customers.id , placing_slip.cover_id , placing_slip.remarks , placing_slip.quotation_date as qtndate , policynote.policyno , country.currencycode , country.currencyname , placing_slip_premiumdetails.brokerage,placing_slip_premiumdetails.ispercentage , placing_slip_premiumdetails.premium , placing_slip_premiumdetails.policy_fees , insurance_company.company_name , insurance_company.po_box , insurance_company.address as ins_address , insurance_company.country_id , insurance_company.city_id , customer_account.branch_id , customers.code , customer_contact.address , customer_contact.country , customer_contact.city , customer_contact.postbox , customer_contact.phone_office , customer_contact.email , customer_contact.mobile , customer_contact.fax , placing_slip_premiumdetails.fromdate , placing_slip_premiumdetails.todate , NULL as ecpolicyno FROM customers LEFT JOIN customer_personal_ind ON (customers.id = customer_personal_ind.customer_id) LEFT JOIN customer_corp_info ON (customers.id = customer_corp_info.customer_id) INNER JOIN customer_contact ON (customers.id = customer_contact.customer_id) INNER JOIN placing_slip ON (placing_slip.customer_id = customers.id) INNER JOIN covers ON (placing_slip.cover_id = covers.id) LEFT JOIN policynote ON (placing_slip.quotation_ref = policynote.quotation_ref) INNER JOIN placing_slip_premiumdetails ON (placing_slip_premiumdetails.placing_slip_id = placing_slip.id) LEFT JOIN insurance_company ON (placing_slip_premiumdetails.insurance_company_id=insurance_company.id ) INNER JOIN customer_account ON (customer_account.customer_id = customers.id) INNER JOIN country ON (placing_slip.currencytype=country.id) where placing_slip.id = '".$id."' "; // echo $sql; $Q=$this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function getendorsementdebitcredit($endid,$plid) { $sql = " SELECT IFNULL(customer_corp_info.insured , customer_personal_ind.insured) as insured , covers.cover , customers.id , placing_slip.cover_id , placing_slip.remarks , policynote.policyno , country.currencycode , country.currencyname , e.brokerage,e.ispercentage , e.enddate as qtndate , e.endrefno,e.endpolicyno as ecpolicyno,e.enddate,e.mode,e.premiumchange as premium ,e.policyfeeschange as policy_fees,e.paymentoptions , insurance_company.company_name , insurance_company.po_box , insurance_company.country_id , insurance_company.city_id , customer_account.branch_id , insurance_company.address as ins_address , customers.code , customer_contact.address , customer_contact.country , customer_contact.city , customer_contact.postbox , customer_contact.phone_office , customer_contact.email , customer_contact.mobile , customer_contact.fax , placing_slip_premiumdetails.fromdate , placing_slip_premiumdetails.todate FROM customers LEFT JOIN customer_personal_ind ON (customers.id = customer_personal_ind.customer_id) LEFT JOIN customer_corp_info ON (customers.id = customer_corp_info.customer_id) INNER JOIN customer_contact ON (customers.id = customer_contact.customer_id) INNER JOIN placing_slip ON (placing_slip.customer_id = customers.id) INNER JOIN covers ON (placing_slip.cover_id = covers.id) LEFT JOIN policynote ON (placing_slip.quotation_ref = policynote.quotation_ref) inner join endorsement e on e.policyid=policynote.id INNER JOIN placing_slip_premiumdetails ON (placing_slip_premiumdetails.placing_slip_id = placing_slip.id) LEFT JOIN insurance_company ON (placing_slip_premiumdetails.insurance_company_id=insurance_company.id ) INNER JOIN customer_account ON (customer_account.customer_id = customers.id) INNER JOIN country ON (placing_slip.currencytype=country.id) where e.id='$endid' and placing_slip.id='$plid' "; $Q=$this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function getcancellationdebitcredit($endid,$plid) { $sql = " SELECT IFNULL(customer_corp_info.insured , customer_personal_ind.insured) as insured , covers.cover , customers.id , placing_slip.cover_id , placing_slip.remarks , policynote.policyno , country.currencycode , country.currencyname , placing_slip_premiumdetails.brokerage,placing_slip_premiumdetails.ispercentage , c.date as qtndate , c.canpolicyno as ecpolicyno,c.canrefno,c.date as cancdate,c.premiumchange as premium ,0 as policy_fees , insurance_company.company_name , insurance_company.po_box , insurance_company.country_id , insurance_company.city_id , customer_account.branch_id , customers.code , customer_contact.address , customer_contact.country , customer_contact.city , customer_contact.postbox , customer_contact.phone_office , customer_contact.email , customer_contact.mobile , customer_contact.fax , placing_slip_premiumdetails.fromdate , placing_slip_premiumdetails.todate FROM customers LEFT JOIN customer_personal_ind ON (customers.id = customer_personal_ind.customer_id) LEFT JOIN customer_corp_info ON (customers.id = customer_corp_info.customer_id) INNER JOIN customer_contact ON (customers.id = customer_contact.customer_id) INNER JOIN placing_slip ON (placing_slip.customer_id = customers.id) INNER JOIN covers ON (placing_slip.cover_id = covers.id) LEFT JOIN policynote ON (placing_slip.quotation_ref = policynote.quotation_ref) inner join cancellation c on c.policyid=policynote.id INNER JOIN placing_slip_premiumdetails ON (placing_slip_premiumdetails.placing_slip_id = placing_slip.id) LEFT JOIN insurance_company ON (placing_slip_premiumdetails.insurance_company_id=insurance_company.id ) INNER JOIN customer_account ON (customer_account.customer_id = customers.id) INNER JOIN country ON (placing_slip.currencytype=country.id) where c.id='$endid' and placing_slip.id='$plid' "; // echo $sql; $Q=$this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function credit_stakeholder($pid) { $sql="select * from placing_slip_stakeholders pssh INNER JOIN staffpersonaldetails spd ON spd.id=pssh.staffid LEFT JOIN staffpermaddress spa ON spa.staffid=spd.id where placing_slip_id=$pid"; $Q=$this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } else { $data=0; } $Q->free_result(); return $data; } function count_credit_stakeholder($pid) { $sql="select * from placing_slip_stakeholders pssh INNER JOIN staffpersonaldetails spd ON spd.id=pssh.staffid LEFT JOIN staffpermaddress spa ON spa.staffid=spd.id where placing_slip_id=$pid"; //echo $sql; $Q=$this->db->query($sql); $res=$Q->num_rows(); return $res; } function broke_exist($bid) { $qref=$this->customermodel->getSingleFieldValue('broking_slip','quotation_ref','id',$bid); $query=$this->db->query("select * from placing_slip where quotation_ref='$qref'"); echo $query->num_rows(); } function get_commission_pay_acc() { $data=array(); $qry="SELECT cm.account_code as code FROM mainacc_setting mas join chart_master cm ON cm.id=mas.commission_pay_acc "; $res=$this->db->query($qry); $data=$res->row()->code ; return $data; } function getpolicyfeesname($pid) { $qry="select labelname from placing_slip_form where placing_slip_id='$pid' and fieldtype='policyfees'"; $res=$this->db->query($qry); if(isset($res->row()->labelname)) { $data=$res->row()->labelname ; } else { $data="Policy Fees"; } return $data; } function search_debitnote($count,$searchopt,$searchtext="",$page="",$per_page="") { $data = array(); if($page) $start = ($page-1)*$per_page; else $start=0; if(!empty ($searchopt)) { $condition="and $searchopt like '%$searchtext%'"; } else { $condition=""; } if($count=='true') { $results=$this->db->query("SELECT `reference`,refs.id as refid,ps.pslip_id as qid,ps.type FROM `refs` left join placing_slip_refs ps on ps.id=refs.id where refs.type='6' and ps.pslip_id!=0 $condition order by refid desc"); return $results->num_rows(); } else { $Q=$this->db->query("SELECT `reference`,refs.id as refid,ps.pslip_id as qid,ps.type FROM `refs` left join placing_slip_refs ps on ps.id=refs.id where refs.type='6' and ps.pslip_id!=0 $condition order by refid desc limit $start,$per_page"); foreach ($Q->result_array() as $row) { $data[] = $row; } return $data; } } function search_creditnote($count,$searchopt,$searchtext="",$page="",$per_page="") { $data=array(); if($page) $start = ($page-1)*$per_page; else $start=0; if(!empty ($searchopt)) { $condition="and $searchopt like '%$searchtext%'"; } else { $condition=""; } if($count=='true') { $results=$this->db->query("SELECT distinct `reference`,refs.id as refid,ps.pslip_id as qid,ps.type FROM `refs` join placing_slip_refs ps on ps.id=refs.id left join placing_slip p on p.id=ps.pslip_id left join placing_slip_stakeholders psh on psh.placing_slip_id=p.id where refs.type='5' $condition order by refid desc"); return $results->num_rows(); } else { $Q=$this->db->query("SELECT distinct `reference`,refs.id as refid,ps.pslip_id as qid,ps.type FROM `refs` join placing_slip_refs ps on ps.id=refs.id left join placing_slip p on p.id=ps.pslip_id left join placing_slip_stakeholders psh on psh.placing_slip_id=p.id where refs.type='5' $condition order by refid desc limit $start,$per_page"); foreach ($Q->result_array() as $row) { $data[] = $row; } return $data; } } function getplacingslip_refs($plid) { $data = array(); $Q=$this->db->query("select * from placing_slip_refs where pslip_id ='$plid' and type='issue'"); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function getplacingslip_referenceno($plid,$reftype,$doctype="issue") { $reference = 0; $Q=$this->db->query("select reference from refs r join placing_slip_refs ps on ps.id=r.id where ps.pslip_id ='$plid' and ps.type='$doctype' and r.type='$reftype'"); $data=$Q->row(); if (!empty($data)) { $reference = $data->reference; } return $reference; } function getendorsement_refs($plid) { $data = array(); $Q=$this->db->query("select * from placing_slip_refs where pslip_id ='$plid' and type='endorsement'"); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function getendorsement_referenceno($plid,$reftype) { $Q=$this->db->query("select reference from refs r join placing_slip_refs ps on ps.id=r.id where ps.pslip_id ='$plid' and ps.type='endorsement' and r.type='$reftype'"); $data=$Q->row()->reference ; return $data; } function getcancellation_refs($plid) { $data = array(); $Q=$this->db->query("select * from placing_slip_refs where pslip_id ='$plid' and type='cancellation'"); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function getcancellation_referenceno($plid,$reftype) { $Q=$this->db->query("select reference from refs r join placing_slip_refs ps on ps.id=r.id where ps.pslip_id ='$plid' and ps.type='cancellation' and r.type='$reftype'"); $data=$Q->row()->reference ; return $data; } function get_declarationdebit($id) { $sql = " SELECT IFNULL(customer_corp_info.insured , customer_personal_ind.insured) as insured , covers.cover , customers.id , declaration.cover_id , placing_slip.remarks , declaration.declarationdate as qtndate , policynote.policyno , country.currencycode , country.currencyname , declaration_premiumdetails.brokerage,declaration_premiumdetails.ispercentage , declaration_premiumdetails.premium , declaration_premiumdetails.policy_fees , insurance_company.company_name , insurance_company.po_box , insurance_company.country_id , insurance_company.city_id , customer_account.branch_id , customers.code , customer_contact.address , customer_contact.country , customer_contact.city , customer_contact.postbox , customer_contact.phone_office , customer_contact.email , customer_contact.mobile , customer_contact.fax , declaration_project_period.fromdate , declaration_project_period.todate , NULL as ecpolicyno FROM customers LEFT JOIN customer_personal_ind ON (customers.id = customer_personal_ind.customer_id) LEFT JOIN customer_corp_info ON (customers.id = customer_corp_info.customer_id) INNER JOIN customer_contact ON (customers.id = customer_contact.customer_id) INNER JOIN declaration ON (declaration.customer_id = customers.id) INNER JOIN covers ON (declaration.cover_id = covers.id) LEFT JOIN policynote ON (declaration.quotation_ref = policynote.quotation_ref) INNER JOIN declaration_premiumdetails ON (declaration_premiumdetails.declaration_id = declaration.id) LEFT JOIN insurance_company ON (declaration_premiumdetails.insurance_company_id=insurance_company.id ) LEFT JOIN declaration_project_period ON (declaration_project_period.declaration_id=declaration.id ) INNER JOIN customer_account ON (customer_account.customer_id = customers.id) INNER JOIN country ON (declaration.currencytype=country.id) where declaration.id = '".$id."' "; // echo $sql; $Q=$this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function sumamountgl($refid) { $res=$this->db->query("select sum(abs(amount)) as amount from gl_trans where type_no='$refid'"); $result=$res->row(); if(!isset($result->amount)) $amount=0; else $amount=$result->amount; return $amount; } function checktemplateexist($coverid) { $res=$this->db->query("select count(*) as count from template where cover_id='$coverid' and template_type='1'"); $result=$res->row(); if(!isset($result->count)) $count=0; else $count=$result->count; return $count; } function findcustomerbycode($code) { $res=$this->db->query("SELECT IFNULL(customer_corp_info.insured,customer_personal_ind.insured) as insured, customers.code as code ,customers.id,customers.type as type 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) where customers.code='$code'"); $result=$res->row(); if($res->num_rows() > 0) { $insured= $result->insured; $id=$result->id; $type=$result->type; if($type=='Individual') { $business='NIL'; } else { $business=$this->customermodel->getSingleFieldValue('customer_corp_info','business_activity','customer_id',$id); } $resultset=$insured.'~'.$business.'~'.$id; } else { $resultset=""; } return $resultset; } function checkbrokingslipexist($code) { $codenew=str_replace("~","/",$code); $res=$this->db->query("select id from broking_slip where quotation_ref='$codenew' "); $result=$res->row(); if(!isset($result->id)) $count=0; else $count=$result->id; return $count; } function gertquotationreference() { $res=$this->db->query("select qref from quotation_reference "); $result=$res->row(); return $result->qref; } function getreferencebyplacingslip($plid,$type,$rtype) { $res=$this->db->query("SELECT p.id as refid FROM `placing_slip_refs` p join refs on refs.id=p.id where p.pslip_id='$plid' and p.type='$rtype' and refs.type='$type' "); $result=$res->row(); if(!isset($result->refid)) $count=""; else $count=$result->refid; return $count; } }