?
Current Path : /home1/savoy/public_html/savoyglobal.net/drafthr/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/drafthr/system/application/models/reportmodel.php |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');?> <?php class reportmodel extends Model { function reportmodel() { parent::Model(); } function get_claimdetails($table,$id) { $data = array(); $sql = "select * from policynote inner join broking_slip on policynote.quotation_ref = broking_slip.quotation_ref and policynote.id = '$id'"; //echo $sql; $Q=$this->db->query($sql); $row=$Q->row(); return $row; } function generatereport($table,$selectsearch,$search,$fromdate,$todate,$cover_id) { // echo $table.'--'.$selectsearch.'--'.$search.'--'.$fromdate.'--'.$todate.'--'.$cover_id; $data = array(); $condition=""; if($selectsearch != "" && $fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $condition=" and claim.$selectsearch between '$fromdate' and '$todate'"; } if($cover_id != "cover_id") $condition=$condition." and placing_slip.cover_id = '$cover_id'"; $sql = " SELECT IFNULL(customer_corp_info.insured , customer_personal_ind.insured) as insured , staffpersonaldetails.name , covers.cover ,max(staffcustomer.entrydate) , customers.id , placing_slip.cover_id , policynote.policyno , claim.date , placing_slip_premiumdetails.brokerage , placing_slip_premiumdetails.premium, placing_slip_premiumdetails.policy_fees , insurance_company.company_name , customer_account.branch_id , customers.code , country.currencycode , placing_slip_premiumdetails.fromdate , placing_slip_premiumdetails.todate , IFNULL((SELECT sum(amount) from placing_slip_payamount where placing_slip_payamount.placing_slip_id=placing_slip.id ),0) as amount , IFNULL((SELECT sum(amount) from claimsettlement where claimsettlement.claimid=claim.id),0) as settlement 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 placing_slip ON (placing_slip.customer_id = customers.id) INNER JOIN covers ON (placing_slip.cover_id = covers.id) INNER JOIN country ON (placing_slip.currencytype = country.id) INNER JOIN policynote ON (placing_slip.quotation_ref = policynote.quotation_ref) INNER JOIN claim ON (claim.policyid = policynote.id) INNER JOIN claimsettlement ON (claimsettlement.claimid = claim.id) INNER JOIN placing_slip_premiumdetails ON (placing_slip_premiumdetails.placing_slip_id = placing_slip.id) LEFT JOIN placing_slip_payamount ON (placing_slip.id = placing_slip_payamount.placing_slip_id) INNER JOIN insurance_company ON (insurance_company.id = placing_slip_premiumdetails.insurance_company_id) INNER JOIN customer_account ON (customer_account.customer_id = customers.id) INNER JOIN staffcustomer ON (staffcustomer.customerid = customers.id) INNER JOIN staffpersonaldetails ON (staffcustomer.staffid = staffpersonaldetails.id) where customers.id = '".$search."' $condition GROUP BY staffcustomer.customerid order by placing_slip.cover_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 generateclaiminsureport($table,$fromdate,$todate,$search,$cover_id,$branch_id) { // echo $table.'--'.$selectsearch.'--'.$search.'--'.$fromdate.'--'.$todate.'--'.$cover_id; if($branch_id=='') $branch_id='branch_id'; $data = array(); $condition=""; if(($fromdate != "" && $todate != "")) { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $condition=" and claim.date between '$fromdate' and '$todate'"; } if($cover_id != "cover_id") $condition=$condition." and placing_slip.cover_id = '$cover_id'"; if($branch_id!='branch_id') { $condition=$condition." and customer_account.branch_id = '$branch_id'"; } $sql = " SELECT IFNULL(customer_corp_info.insured , customer_personal_ind.insured) as insured , staffpersonaldetails.name , covers.cover ,max(staffcustomer.entrydate) , customers.id , placing_slip.cover_id , policynote.policyno , claim.date , placing_slip_premiumdetails.brokerage , placing_slip_premiumdetails.premium, placing_slip_premiumdetails.policy_fees , insurance_company.company_name , customer_account.branch_id , customers.code , country.currencycode , placing_slip_premiumdetails.fromdate , placing_slip_premiumdetails.todate , IFNULL((SELECT sum(amount) from placing_slip_payamount where placing_slip_payamount.placing_slip_id=placing_slip.id ),0) as amount , IFNULL((SELECT sum(amount) from claimsettlement where claimsettlement.claimid=claim.id),0) as settlement 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 placing_slip ON (placing_slip.customer_id = customers.id) INNER JOIN covers ON (placing_slip.cover_id = covers.id) INNER JOIN country ON (placing_slip.currencytype = country.id) INNER JOIN policynote ON (placing_slip.quotation_ref = policynote.quotation_ref) INNER JOIN claim ON (claim.policyid = policynote.id) INNER JOIN claimsettlement ON (claimsettlement.claimid = claim.id) INNER JOIN placing_slip_premiumdetails ON (placing_slip_premiumdetails.placing_slip_id = placing_slip.id) LEFT JOIN placing_slip_payamount ON (placing_slip.id = placing_slip_payamount.placing_slip_id) INNER JOIN insurance_company ON (insurance_company.id = placing_slip_premiumdetails.insurance_company_id) INNER JOIN customer_account ON (customer_account.customer_id = customers.id) INNER JOIN staffcustomer ON (staffcustomer.customerid = customers.id) INNER JOIN staffpersonaldetails ON (staffcustomer.staffid = staffpersonaldetails.id) where placing_slip_premiumdetails.insurance_company_id = '".$search."' $condition GROUP BY staffcustomer.customerid order by placing_slip.cover_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 generatesalesclientreport($table,$search,$fromdate,$todate,$cover_id) { $data = array(); if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); } $sql="select * from placing_slip_refs pr group by type,pslip_id "; $res=$this->db->query($sql); $i=0; foreach ($res->result_array() as $restype) { $trtype=$restype['type']; $qid=$restype['pslip_id']; if($trtype=='issue') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,c.cover,p.premium,plc.customer_id,plc.cover_id,p.fromdate as qrefdate,p.todate as renewdate,p.insurance_company_id,pn.policyno as policy_no, p.brokerage,plc.id as plid,plc.cover_id,plc.quotation_ref as qref,plc.currencytype ,p.policy_fees,sc.staffid from placing_slip plc join placing_slip_premiumdetails p on p.placing_slip_id=plc.id left join policynote pn on pn.quotation_ref=plc.quotation_ref join covers c on c.id=plc.cover_id INNER JOIN staffcustomer sc ON plc.customer_id = sc.customerid INNER JOIN country ct ON plc.currencytype = ct.id "; } else if($trtype=='endorsement') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,plc.endrefno as qref,plc.endpolicyno as policy_no,p.fromdate as qrefdate,p.todate as renewdate,plc.premiumchange as premium,plc.policyfeeschange as policy_fees,covers.cover, p.insurance_company_id,pn.policyno,p.brokerage,pl.id as plid,pl.cover_id,pl.customer_id,pl.quotation_ref,pl.currencytype,sc.staffid from placing_slip pl left join placing_slip_premiumdetails p on p.placing_slip_id=pl.id left join policynote pn on pn.quotation_ref=pl.quotation_ref join endorsement plc on plc.policyid=pn.id left join covers on covers.id=pl.cover_id INNER JOIN staffcustomer sc ON pl.customer_id = sc.customerid INNER JOIN country ct ON pl.currencytype = ct.id "; } else if($trtype=='cancellation') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,plc.canpolicyno as policy_no,plc.canrefno as qref,p.fromdate as qrefdate,p.todate as renewdate,0-plc.premiumchange as premium,p.insurance_company_id,pn.policyno,covers.cover,'0' as policy_fees, p.brokerage,pl.id as plid,pl.cover_id,pl.customer_id,pl.quotation_ref,pl.currencytype,sc.staffid from placing_slip pl left join placing_slip_premiumdetails p on p.placing_slip_id=pl.id left join policynote pn on pn.quotation_ref=pl.quotation_ref join cancellation plc on plc.policyid=pn.id left join covers on covers.id=pl.cover_id INNER JOIN staffcustomer sc ON pl.customer_id = sc.customerid INNER JOIN country ct ON pl.currencytype = ct.id "; } else { $sql="SELECT IFNULL( (select sum(percentage) from declaration_stakeholders where declaration_stakeholders.declaration_id=p.declaration_id ),'0') as percentage,ct.currencycode,c.cover,p.premium,plc.customer_id,plc.cover_id,plc.certificate_refno as qref,p.todate as renewdate,plc.certificate_no as policy_no, p.fromdate as qrefdate,p.insurance_company_id,pn.policyno, p.brokerage,plc.id as plid,plc.cover_id,plc.quotation_ref,plc.currencytype,p.policy_fees,sc.staffid from declaration plc join declaration_premiumdetails p on p.declaration_id=plc.id left join policynote pn on pn.quotation_ref=plc.quotation_ref join covers c on c.id=plc.cover_id INNER JOIN staffcustomer sc ON plc.customer_id = sc.customerid INNER JOIN country ct ON plc.currencytype = ct.id "; } $sql=$sql."where plc.id='$qid' and customer_id='$search'"; if($fromdate != "" && $todate != "") { $sql=$sql." having qrefdate between '$fromdate' and '$todate' "; } if($cover_id!="cover_id") { $sql=$sql." and cover_id = '$cover_id'"; } //echo $sql.'<br><br><br>'; $res1=$this->db->query($sql); $result=$res1->row(); // foreach ($res1->result_array() as $row) // { // $resultset[] = $row; // } if(!isset($result->qref)) { continue; } $data[$i]['qtnref']=$result->qref; $data[$i]['qdate']=$result->qrefdate; $data[$i]['renewdate']=$result->renewdate; $data[$i]['plid']=$result->plid; $data[$i]['customerid']=$result->customer_id; $data[$i]['covertype']=$result->cover; $data[$i]['premium']=$result->premium; $data[$i]['brokerage']=$result->brokerage; $data[$i]['policy_no']=$result->policy_no; $data[$i]['staffid']=$result->staffid; $data[$i]['currencycode']=$result->currencycode; $data[$i]['cover_id']=$result->cover_id; $data[$i]['policy_fees']=$result->policy_fees; $data[$i]['insurance_company_id']=$result->insurance_company_id; $data[$i]['percentage']=$result->percentage; $i++; } // var_dump($data); return $data; } function generaterenewclientreport($table,$search,$fromdate,$todate,$cover_id) { // echo $table.'--'.$selectsearch.'--'.$search.'--'.$fromdate.'--'.$todate.'--'.$cover_id; $data = array(); if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); } $sql="select * from placing_slip_refs pr group by type,pslip_id "; $res=$this->db->query($sql); $i=0; foreach ($res->result_array() as $restype) { $trtype=$restype['type']; $qid=$restype['pslip_id']; if($trtype=='issue') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,c.cover,p.premium,plc.customer_id,plc.cover_id,p.todate as qrefdate,p.todate as renewdate,p.insurance_company_id,pn.policyno as policy_no, p.brokerage,plc.id as plid,plc.cover_id,plc.quotation_ref as qref,plc.currencytype ,p.policy_fees,sc.staffid from placing_slip plc join placing_slip_premiumdetails p on p.placing_slip_id=plc.id left join policynote pn on pn.quotation_ref=plc.quotation_ref join covers c on c.id=plc.cover_id INNER JOIN staffcustomer sc ON plc.customer_id = sc.customerid INNER JOIN country ct ON plc.currencytype = ct.id "; } else if($trtype=='endorsement') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,plc.endrefno as qref,plc.endpolicyno as policy_no,p.todate as qrefdate,p.todate as renewdate,plc.premiumchange as premium,plc.policyfeeschange as policy_fees,covers.cover, p.insurance_company_id,pn.policyno,p.brokerage,pl.id as plid,pl.cover_id,pl.customer_id,pl.quotation_ref,pl.currencytype,sc.staffid from placing_slip pl left join placing_slip_premiumdetails p on p.placing_slip_id=pl.id left join policynote pn on pn.quotation_ref=pl.quotation_ref join endorsement plc on plc.policyid=pn.id left join covers on covers.id=pl.cover_id INNER JOIN staffcustomer sc ON pl.customer_id = sc.customerid INNER JOIN country ct ON pl.currencytype = ct.id "; } else if($trtype=='cancellation') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,plc.canpolicyno as policy_no,plc.canrefno as qref,p.todate as qrefdate,p.todate as renewdate,0-plc.premiumchange as premium,p.insurance_company_id,pn.policyno,covers.cover,'0' as policy_fees, p.brokerage,pl.id as plid,pl.cover_id,pl.customer_id,pl.quotation_ref,pl.currencytype,sc.staffid from placing_slip pl left join placing_slip_premiumdetails p on p.placing_slip_id=pl.id left join policynote pn on pn.quotation_ref=pl.quotation_ref join cancellation plc on plc.policyid=pn.id left join covers on covers.id=pl.cover_id INNER JOIN staffcustomer sc ON pl.customer_id = sc.customerid INNER JOIN country ct ON pl.currencytype = ct.id "; } else { $sql="SELECT IFNULL( (select sum(percentage) from declaration_stakeholders where declaration_stakeholders.declaration_id=p.declaration_id ),'0') as percentage,ct.currencycode,c.cover,p.premium,plc.customer_id,plc.cover_id,plc.certificate_refno as qref,p.todate as renewdate,plc.certificate_no as policy_no, p.todate as qrefdate,p.insurance_company_id,pn.policyno, p.brokerage,plc.id as plid,plc.cover_id,plc.quotation_ref,plc.currencytype,p.policy_fees,sc.staffid from declaration plc join declaration_premiumdetails p on p.declaration_id=plc.id left join policynote pn on pn.quotation_ref=plc.quotation_ref join covers c on c.id=plc.cover_id INNER JOIN staffcustomer sc ON plc.customer_id = sc.customerid INNER JOIN country ct ON plc.currencytype = ct.id "; } $sql=$sql."where plc.id='$qid' and customer_id='$search'"; if($fromdate != "" && $todate != "") { $sql=$sql." having qrefdate between '$fromdate' and '$todate' "; } if($cover_id!="cover_id") { $sql=$sql." and cover_id = '$cover_id'"; } //echo $sql.'<br><br><br>'; $res1=$this->db->query($sql); $result=$res1->row(); // foreach ($res1->result_array() as $row) // { // $resultset[] = $row; // } if(!isset($result->qref)) { continue; } $data[$i]['qtnref']=$result->qref; $data[$i]['qdate']=$result->qrefdate; $data[$i]['renewdate']=$result->renewdate; $data[$i]['plid']=$result->plid; $data[$i]['customerid']=$result->customer_id; $data[$i]['covertype']=$result->cover; $data[$i]['premium']=$result->premium; $data[$i]['brokerage']=$result->brokerage; $data[$i]['policy_no']=$result->policy_no; $data[$i]['staffid']=$result->staffid; $data[$i]['currencycode']=$result->currencycode; $data[$i]['cover_id']=$result->cover_id; $data[$i]['policy_fees']=$result->policy_fees; $data[$i]['insurance_company_id']=$result->insurance_company_id; $data[$i]['percentage']=$result->percentage; $i++; } // var_dump($data); return $data; } function generatereportlossclient($table,$selectsearch,$search,$fromdate,$todate,$cover_id) { $data = array(); $sql = "select placing_slip.customer_id, placing_slip.quotation_ref,placing_slip.cover_id,placing_slip_premiumdetails.premium,policynote.policyno,claim.claimsref, sum(claimsettlement.amount) as totalamount from placing_slip inner join placing_slip_premiumdetails inner join policynote inner join claim inner join claimsettlement on placing_slip.id = placing_slip_premiumdetails.placing_slip_id and placing_slip.quotation_ref = policynote.quotation_ref and policynote.id = claim.policyid and claim.id = claimsettlement.claimid and placing_slip.customer_id = '$search'"; /*if($selectsearch != "" && $fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $sql=$sql." and claim.$selectsearch between '$fromdate' and '$todate'"; }*/ if($cover_id != "") $sql=$sql." and placing_slip.cover_id = '$cover_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 generatereportlossclaimcov($table,$cover_id) { $data = array(); $sql = "select placing_slip.customer_id, placing_slip.quotation_ref,placing_slip.cover_id,placing_slip_premiumdetails.premium,policynote.policyno,claim.claimsref, sum(claimsettlement.amount) as totalamount from placing_slip inner join placing_slip_premiumdetails inner join policynote inner join claim inner join claimsettlement on placing_slip.id = placing_slip_premiumdetails.placing_slip_id and placing_slip.quotation_ref = policynote.quotation_ref and policynote.id = claim.policyid and claim.id = claimsettlement.claimid and placing_slip.cover_id = '$cover_id'"; $Q=$this->db->query($sql); // echo $sql; if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function generatereportclaimcov($table,$selectsearch,$fromdate,$todate,$cover_id) { $data = array(); $condition=""; if($selectsearch != "" && $fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $condition=" and claim.$selectsearch between '$fromdate' and '$todate'"; } if($cover_id != "") $condition=$condition." and placing_slip.cover_id = '$cover_id'"; $sql = " SELECT IFNULL(customer_corp_info.insured , customer_personal_ind.insured) as insured , staffpersonaldetails.name , covers.cover ,max(staffcustomer.entrydate) , customers.id , customers.code , placing_slip.cover_id , policynote.policyno , claim.date , placing_slip_premiumdetails.brokerage , placing_slip_premiumdetails.premium, placing_slip_premiumdetails.policy_fees , insurance_company.company_name , customer_account.branch_id , placing_slip_premiumdetails.fromdate , placing_slip_premiumdetails.todate , country.currencycode , IFNULL((SELECT sum(amount) from placing_slip_payamount where placing_slip_payamount.placing_slip_id=placing_slip.id ),0) as amount , IFNULL((SELECT sum(amount) from claimsettlement where claimsettlement.claimid=claim.id),0) as settlement 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 placing_slip ON (placing_slip.customer_id = customers.id) INNER JOIN country ON (placing_slip.currencytype = country.id) INNER JOIN covers ON (placing_slip.cover_id = covers.id) INNER JOIN policynote ON (placing_slip.quotation_ref = policynote.quotation_ref) INNER JOIN claim ON (claim.policyid = policynote.id) INNER JOIN claimsettlement ON (claimsettlement.claimid = claim.id) INNER JOIN placing_slip_premiumdetails ON (placing_slip_premiumdetails.placing_slip_id = placing_slip.id) LEFT JOIN placing_slip_payamount ON (placing_slip.id = placing_slip_payamount.placing_slip_id) INNER JOIN insurance_company ON (insurance_company.id = placing_slip_premiumdetails.insurance_company_id) INNER JOIN customer_account ON (customer_account.customer_id = customers.id) INNER JOIN staffcustomer ON (staffcustomer.customerid = customers.id) INNER JOIN staffpersonaldetails ON (staffcustomer.staffid = staffpersonaldetails.id) where customers.id like '%' $condition group by placing_slip.id"; $Q=$this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function generatereportclaimbra($table,$selectsearch,$fromdate,$todate,$branch,$cover_id) { $data = array(); $condition=""; if($selectsearch != "" && $fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $condition=" and claim.$selectsearch between '$fromdate' and '$todate'"; } if($cover_id != "cover_id") $condition=$condition." and placing_slip.cover_id = '$cover_id'"; $sql = " SELECT IFNULL(customer_corp_info.insured , customer_personal_ind.insured) as insured , staffpersonaldetails.name , covers.cover ,max(staffcustomer.entrydate) , customers.id , customers.code , placing_slip.cover_id , policynote.policyno , claim.date , placing_slip_premiumdetails.brokerage , placing_slip_premiumdetails.premium, placing_slip_premiumdetails.policy_fees , placing_slip_premiumdetails.fromdate , placing_slip_premiumdetails.todate , insurance_company.company_name , country.currencycode , customer_account.branch_id , IFNULL((SELECT sum(amount) from placing_slip_payamount where placing_slip_payamount.placing_slip_id=placing_slip.id ),0) as amount , IFNULL((SELECT sum(amount) from claimsettlement where claimsettlement.claimid=claim.id),0) as settlement 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 placing_slip ON (placing_slip.customer_id = customers.id) INNER JOIN covers ON (placing_slip.cover_id = covers.id) INNER JOIN country ON (placing_slip.currencytype = country.id) INNER JOIN policynote ON (placing_slip.quotation_ref = policynote.quotation_ref) INNER JOIN claim ON (claim.policyid = policynote.id) INNER JOIN claimsettlement ON (claimsettlement.claimid = claim.id) INNER JOIN placing_slip_premiumdetails ON (placing_slip_premiumdetails.placing_slip_id = placing_slip.id) LEFT JOIN placing_slip_payamount ON (placing_slip.id = placing_slip_payamount.placing_slip_id) INNER JOIN insurance_company ON (insurance_company.id = placing_slip_premiumdetails.insurance_company_id) INNER JOIN customer_account ON (customer_account.customer_id = customers.id) INNER JOIN staffcustomer ON (staffcustomer.customerid = customers.id) INNER JOIN staffpersonaldetails ON (staffcustomer.staffid = staffpersonaldetails.id) INNER JOIN staffemployeedetails ON (staffcustomer.staffid = staffemployeedetails.staffid) where customer_account.branch_id = '$branch' $condition group by placing_slip.id order by placing_slip.cover_id"; $Q=$this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function generatereportbratarget($table,$fromdate,$todate,$branch,$cover_id) { $data = array(); $condition=""; if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $condition=" and (branchtarget.startdate >= '$fromdate' and branchtarget.startdate<='$todate') and (placing_slip_premiumdetails.fromdate >= '$fromdate' and placing_slip_premiumdetails.todate<='$todate')"; } if($cover_id != "cover_id") $condition=$condition." and placing_slip.cover_id = '$cover_id'"; $sql = " SELECT IFNULL(customer_corp_info.insured , customer_personal_ind.insured) as insured , staffpersonaldetails.name , covers.cover ,max(staffcustomer.entrydate) , customers.id , customers.code , placing_slip.cover_id , policynote.policyno , (branchtarget.target , branchtarget.curr_id as bt_currency , placing_slip_premiumdetails.brokerage , placing_slip_premiumdetails.premium, placing_slip_premiumdetails.policy_fees , placing_slip_premiumdetails.fromdate , placing_slip_premiumdetails.todate , insurance_company.company_name , country.currencycode , customer_account.branch_id , IFNULL((SELECT sum(amount) from placing_slip_payamount where placing_slip_payamount.placing_slip_id=placing_slip.id ),0) as amount 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 placing_slip ON (placing_slip.customer_id = customers.id) INNER JOIN covers ON (placing_slip.cover_id = covers.id) INNER JOIN country ON (placing_slip.currencytype = country.id) INNER 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 placing_slip_payamount ON (placing_slip.id = placing_slip_payamount.placing_slip_id) LEFT JOIN insurance_company ON (insurance_company.id = placing_slip_premiumdetails.insurance_company_id) INNER JOIN customer_account ON (customer_account.customer_id = customers.id) INNER JOIN staffcustomer ON (staffcustomer.customerid = customers.id) INNER JOIN staffpersonaldetails ON (staffcustomer.staffid = staffpersonaldetails.id) INNER JOIN staffemployeedetails ON (staffcustomer.staffid = staffemployeedetails.staffid) INNER JOIN branchtarget ON (branchtarget.branch = customer_account.branch_id) where customer_account.branch_id = '$branch' $condition group by placing_slip.id order by placing_slip.cover_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 generatereportsalesbra($table,$fromdate,$todate,$branch,$selectedcovers="") { $data = array(); if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); } $sql="select * from placing_slip_refs pr group by type,pslip_id "; $res=$this->db->query($sql); $i=0; foreach ($res->result_array() as $restype) { $trtype=$restype['type']; $qid=$restype['pslip_id']; if($trtype=='issue') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,c.cover,p.premium,plc.customer_id,plc.cover_id,p.fromdate as qrefdate,p.insurance_company_id,pn.policyno as policy_no,'null' as endmode, p.brokerage,plc.id as plid,plc.cover_id,plc.quotation_ref as qref,plc.currencytype ,p.policy_fees,sc.staffid from placing_slip plc join placing_slip_premiumdetails p on p.placing_slip_id=plc.id left join policynote pn on pn.quotation_ref=plc.quotation_ref join covers c on c.id=plc.cover_id INNER JOIN staffcustomer sc ON plc.customer_id = sc.customerid INNER JOIN country ct ON plc.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = plc.customer_id) "; } else if($trtype=='endorsement') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,plc.endrefno as qref,plc.endpolicyno as policy_no,p.fromdate as qrefdate,plc.premiumchange as premium,plc.policyfeeschange as policy_fees,covers.cover,plc.mode as endmode, p.insurance_company_id,pn.policyno,p.brokerage,pl.id as plid,pl.cover_id,pl.customer_id,pl.quotation_ref,pl.currencytype,sc.staffid from placing_slip pl left join placing_slip_premiumdetails p on p.placing_slip_id=pl.id left join policynote pn on pn.quotation_ref=pl.quotation_ref join endorsement plc on plc.policyid=pn.id left join covers on covers.id=pl.cover_id INNER JOIN staffcustomer sc ON pl.customer_id = sc.customerid INNER JOIN country ct ON pl.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = pl.customer_id) "; } else if($trtype=='cancellation') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,plc.canpolicyno as policy_no,plc.canrefno as qref,p.fromdate as qrefdate,0-plc.premiumchange as premium,p.insurance_company_id,pn.policyno,covers.cover,'0' as policy_fees,'null' as endmode, p.brokerage,pl.id as plid,pl.cover_id,pl.customer_id,pl.quotation_ref,pl.currencytype,sc.staffid from placing_slip pl left join placing_slip_premiumdetails p on p.placing_slip_id=pl.id left join policynote pn on pn.quotation_ref=pl.quotation_ref join cancellation plc on plc.policyid=pn.id left join covers on covers.id=pl.cover_id INNER JOIN staffcustomer sc ON pl.customer_id = sc.customerid INNER JOIN country ct ON pl.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = pl.customer_id) "; } else { $sql="SELECT IFNULL( (select sum(percentage) from declaration_stakeholders where declaration_stakeholders.declaration_id=p.declaration_id ),'0') as percentage,ct.currencycode,c.cover,p.premium,plc.customer_id,plc.cover_id,plc.certificate_refno as qref,plc.certificate_no as policy_no, p.fromdate as qrefdate,p.insurance_company_id,pn.policyno,'null' as endmode, p.brokerage,plc.id as plid,plc.cover_id,plc.quotation_ref,plc.currencytype,p.policy_fees,sc.staffid from declaration plc join declaration_premiumdetails p on p.declaration_id=plc.id left join policynote pn on pn.quotation_ref=plc.quotation_ref join covers c on c.id=plc.cover_id INNER JOIN staffcustomer sc ON plc.customer_id = sc.customerid INNER JOIN country ct ON plc.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = plc.customer_id) "; } if($selectedcovers!='') { $cvrs = str_replace('_', ',',$selectedcovers); $sql=$sql."where plc.id='$qid' and customer_account.branch_id = '$branch' and (cover_id IN ( $cvrs ))"; } else $sql=$sql."where plc.id='$qid' and customer_account.branch_id = '$branch'"; if($fromdate != "" && $todate != "") { $sql=$sql." having qrefdate between '$fromdate' and '$todate' "; } // echo $sql.'<br><br><br>'; $res1=$this->db->query($sql); $result=$res1->row(); if(!isset($result->qref)) { continue; } $data[$i]['qtnref']=$result->qref; $data[$i]['qdate']=$result->qrefdate; $data[$i]['plid']=$result->plid; $data[$i]['customerid']=$result->customer_id; $data[$i]['covertype']=$result->cover; $data[$i]['premium']=$result->premium; $data[$i]['brokerage']=$result->brokerage; $data[$i]['policy_no']=$result->policy_no; $data[$i]['staffid']=$result->staffid; $data[$i]['currencycode']=$result->currencycode; $data[$i]['cover_id']=$result->cover_id; $data[$i]['policy_fees']=$result->policy_fees; $data[$i]['insurance_company_id']=$result->insurance_company_id; $data[$i]['percentage']=$result->percentage; $data[$i]['endmode']=$result->endmode; $i++; } // var_dump($data); return $data; } function generatereportrenewbra($table,$fromdate,$todate,$branch) { $data = array(); if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); } $sql="select * from placing_slip_refs pr group by type,pslip_id "; $res=$this->db->query($sql); $i=0; foreach ($res->result_array() as $restype) { $trtype=$restype['type']; $qid=$restype['pslip_id']; if($trtype=='issue') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,c.cover,p.premium,plc.customer_id,plc.cover_id,p.todate as qrefdate,p.insurance_company_id,pn.policyno as policy_no, p.brokerage,plc.id as plid,plc.cover_id,plc.quotation_ref as qref,plc.currencytype ,p.policy_fees,sc.staffid from placing_slip plc join placing_slip_premiumdetails p on p.placing_slip_id=plc.id left join policynote pn on pn.quotation_ref=plc.quotation_ref join covers c on c.id=plc.cover_id INNER JOIN staffcustomer sc ON plc.customer_id = sc.customerid INNER JOIN country ct ON plc.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = plc.customer_id) "; } else if($trtype=='endorsement') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,plc.endrefno as qref,plc.endpolicyno as policy_no,p.todate as qrefdate,plc.premiumchange as premium,plc.policyfeeschange as policy_fees,covers.cover, p.insurance_company_id,pn.policyno,p.brokerage,pl.id as plid,pl.cover_id,pl.customer_id,pl.quotation_ref,pl.currencytype,sc.staffid from placing_slip pl left join placing_slip_premiumdetails p on p.placing_slip_id=pl.id left join policynote pn on pn.quotation_ref=pl.quotation_ref join endorsement plc on plc.policyid=pn.id left join covers on covers.id=pl.cover_id INNER JOIN staffcustomer sc ON pl.customer_id = sc.customerid INNER JOIN country ct ON pl.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = pl.customer_id) "; } else if($trtype=='cancellation') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,plc.canpolicyno as policy_no,plc.canrefno as qref,p.todate as qrefdate,0-plc.premiumchange as premium,p.insurance_company_id,pn.policyno,covers.cover,'0' as policy_fees, p.brokerage,pl.id as plid,pl.cover_id,pl.customer_id,pl.quotation_ref,pl.currencytype,sc.staffid from placing_slip pl left join placing_slip_premiumdetails p on p.placing_slip_id=pl.id left join policynote pn on pn.quotation_ref=pl.quotation_ref join cancellation plc on plc.policyid=pn.id left join covers on covers.id=pl.cover_id INNER JOIN staffcustomer sc ON pl.customer_id = sc.customerid INNER JOIN country ct ON pl.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = pl.customer_id) "; } else { $sql="SELECT IFNULL( (select sum(percentage) from declaration_stakeholders where declaration_stakeholders.declaration_id=p.declaration_id ),'0') as percentage,ct.currencycode,c.cover,p.premium,plc.customer_id,plc.cover_id,plc.certificate_refno as qref,plc.certificate_no as policy_no, p.todate as qrefdate,p.insurance_company_id,pn.policyno, p.brokerage,plc.id as plid,plc.cover_id,plc.quotation_ref,plc.currencytype,p.policy_fees,sc.staffid from declaration plc join declaration_premiumdetails p on p.declaration_id=plc.id left join policynote pn on pn.quotation_ref=plc.quotation_ref join covers c on c.id=plc.cover_id INNER JOIN staffcustomer sc ON plc.customer_id = sc.customerid INNER JOIN country ct ON plc.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = plc.customer_id) "; } $sql=$sql."where plc.id='$qid' and customer_account.branch_id = '$branch'"; if($fromdate != "" && $todate != "") { $sql=$sql." having qrefdate between '$fromdate' and '$todate' "; } // echo $sql.'<br><br><br>'; $res1=$this->db->query($sql); $result=$res1->row(); if(!isset($result->qref)) { continue; } $data[$i]['qtnref']=$result->qref; $data[$i]['qdate']=$result->qrefdate; $data[$i]['plid']=$result->plid; $data[$i]['customerid']=$result->customer_id; $data[$i]['covertype']=$result->cover; $data[$i]['premium']=$result->premium; $data[$i]['brokerage']=$result->brokerage; $data[$i]['policy_no']=$result->policy_no; $data[$i]['staffid']=$result->staffid; $data[$i]['currencycode']=$result->currencycode; $data[$i]['cover_id']=$result->cover_id; $data[$i]['policy_fees']=$result->policy_fees; $data[$i]['insurance_company_id']=$result->insurance_company_id; $data[$i]['percentage']=$result->percentage; $i++; } // var_dump($data); return $data; } function generatereportsalescover($table,$fromdate,$todate,$cover_id,$branch_id) { $data = array(); if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); } $sql="select * from placing_slip_refs pr group by type,pslip_id "; $res=$this->db->query($sql); $i=0; foreach ($res->result_array() as $restype) { $trtype=$restype['type']; $qid=$restype['pslip_id']; if($trtype=='issue') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,c.cover,p.premium,plc.customer_id,plc.cover_id,p.fromdate as qrefdate,p.insurance_company_id,pn.policyno as policy_no, p.brokerage,plc.id as plid,plc.cover_id,plc.quotation_ref as qref,plc.currencytype ,p.policy_fees,sc.staffid from placing_slip plc join placing_slip_premiumdetails p on p.placing_slip_id=plc.id left join policynote pn on pn.quotation_ref=plc.quotation_ref join covers c on c.id=plc.cover_id INNER JOIN staffcustomer sc ON plc.customer_id = sc.customerid INNER JOIN country ct ON plc.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = plc.customer_id) "; } else if($trtype=='endorsement') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,plc.endrefno as qref,plc.endpolicyno as policy_no,p.fromdate as qrefdate,plc.premiumchange as premium,plc.policyfeeschange as policy_fees,covers.cover, p.insurance_company_id,pn.policyno,p.brokerage,pl.id as plid,pl.cover_id,pl.customer_id,pl.quotation_ref,pl.currencytype,sc.staffid from placing_slip pl left join placing_slip_premiumdetails p on p.placing_slip_id=pl.id left join policynote pn on pn.quotation_ref=pl.quotation_ref join endorsement plc on plc.policyid=pn.id left join covers on covers.id=pl.cover_id INNER JOIN staffcustomer sc ON pl.customer_id = sc.customerid INNER JOIN country ct ON pl.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = pl.customer_id) "; } else if($trtype=='cancellation') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,plc.canpolicyno as policy_no,plc.canrefno as qref,p.fromdate as qrefdate,0-plc.premiumchange as premium,p.insurance_company_id,pn.policyno,covers.cover,'0' as policy_fees, p.brokerage,pl.id as plid,pl.cover_id,pl.customer_id,pl.quotation_ref,pl.currencytype,sc.staffid from placing_slip pl left join placing_slip_premiumdetails p on p.placing_slip_id=pl.id left join policynote pn on pn.quotation_ref=pl.quotation_ref join cancellation plc on plc.policyid=pn.id left join covers on covers.id=pl.cover_id INNER JOIN staffcustomer sc ON pl.customer_id = sc.customerid INNER JOIN country ct ON pl.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = pl.customer_id) "; } else { $sql="SELECT IFNULL( (select sum(percentage) from declaration_stakeholders where declaration_stakeholders.declaration_id=p.declaration_id ),'0') as percentage,ct.currencycode,c.cover,p.premium,plc.customer_id,plc.cover_id,plc.certificate_refno as qref,plc.certificate_no as policy_no, p.fromdate as qrefdate,p.insurance_company_id,pn.policyno, p.brokerage,plc.id as plid,plc.cover_id,plc.quotation_ref,plc.currencytype,p.policy_fees,sc.staffid from declaration plc join declaration_premiumdetails p on p.declaration_id=plc.id left join policynote pn on pn.quotation_ref=plc.quotation_ref join covers c on c.id=plc.cover_id INNER JOIN staffcustomer sc ON plc.customer_id = sc.customerid INNER JOIN country ct ON plc.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = plc.customer_id) "; } $sql=$sql."where plc.id='$qid' and cover_id='$cover_id'"; if($branch_id!='branch_id') { $sql=$sql." and customer_account.branch_id = '$branch_id'"; } if($fromdate != "" && $todate != "") { $sql=$sql." having qrefdate between '$fromdate' and '$todate' "; } // echo $sql.'<br><br><br>'; $res1=$this->db->query($sql); $result=$res1->row(); if(!isset($result->qref)) { continue; } $data[$i]['qtnref']=$result->qref; $data[$i]['qdate']=$result->qrefdate; $data[$i]['plid']=$result->plid; $data[$i]['customerid']=$result->customer_id; $data[$i]['covertype']=$result->cover; $data[$i]['premium']=$result->premium; $data[$i]['brokerage']=$result->brokerage; $data[$i]['policy_no']=$result->policy_no; $data[$i]['staffid']=$result->staffid; $data[$i]['currencycode']=$result->currencycode; $data[$i]['cover_id']=$result->cover_id; $data[$i]['policy_fees']=$result->policy_fees; $data[$i]['insurance_company_id']=$result->insurance_company_id; $data[$i]['percentage']=$result->percentage; $i++; } // var_dump($data); return $data; } function generatereportrenewcover($table,$fromdate,$todate,$cover_id,$branch_id) { $data = array(); if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); } $sql="select * from placing_slip_refs pr group by type,pslip_id "; $res=$this->db->query($sql); $i=0; foreach ($res->result_array() as $restype) { $trtype=$restype['type']; $qid=$restype['pslip_id']; if($trtype=='issue') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,c.cover,p.premium,plc.customer_id,plc.cover_id,p.todate as qrefdate,p.insurance_company_id,pn.policyno as policy_no, p.brokerage,plc.id as plid,plc.cover_id,plc.quotation_ref as qref,plc.currencytype ,p.policy_fees,sc.staffid from placing_slip plc join placing_slip_premiumdetails p on p.placing_slip_id=plc.id left join policynote pn on pn.quotation_ref=plc.quotation_ref join covers c on c.id=plc.cover_id INNER JOIN staffcustomer sc ON plc.customer_id = sc.customerid INNER JOIN country ct ON plc.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = plc.customer_id) "; } else if($trtype=='endorsement') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,plc.endrefno as qref,plc.endpolicyno as policy_no,p.todate as qrefdate,plc.premiumchange as premium,plc.policyfeeschange as policy_fees,covers.cover, p.insurance_company_id,pn.policyno,p.brokerage,pl.id as plid,pl.cover_id,pl.customer_id,pl.quotation_ref,pl.currencytype,sc.staffid from placing_slip pl left join placing_slip_premiumdetails p on p.placing_slip_id=pl.id left join policynote pn on pn.quotation_ref=pl.quotation_ref join endorsement plc on plc.policyid=pn.id left join covers on covers.id=pl.cover_id INNER JOIN staffcustomer sc ON pl.customer_id = sc.customerid INNER JOIN country ct ON pl.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = pl.customer_id) "; } else if($trtype=='cancellation') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,plc.canpolicyno as policy_no,plc.canrefno as qref,p.todate as qrefdate,0-plc.premiumchange as premium,p.insurance_company_id,pn.policyno,covers.cover,'0' as policy_fees, p.brokerage,pl.id as plid,pl.cover_id,pl.customer_id,pl.quotation_ref,pl.currencytype,sc.staffid from placing_slip pl left join placing_slip_premiumdetails p on p.placing_slip_id=pl.id left join policynote pn on pn.quotation_ref=pl.quotation_ref join cancellation plc on plc.policyid=pn.id left join covers on covers.id=pl.cover_id INNER JOIN staffcustomer sc ON pl.customer_id = sc.customerid INNER JOIN country ct ON pl.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = pl.customer_id) "; } else { $sql="SELECT IFNULL( (select sum(percentage) from declaration_stakeholders where declaration_stakeholders.declaration_id=p.declaration_id ),'0') as percentage,ct.currencycode,c.cover,p.premium,plc.customer_id,plc.cover_id,plc.certificate_refno as qref,plc.certificate_no as policy_no, p.todate as qrefdate,p.insurance_company_id,pn.policyno, p.brokerage,plc.id as plid,plc.cover_id,plc.quotation_ref,plc.currencytype,p.policy_fees,sc.staffid from declaration plc join declaration_premiumdetails p on p.declaration_id=plc.id left join policynote pn on pn.quotation_ref=plc.quotation_ref join covers c on c.id=plc.cover_id INNER JOIN staffcustomer sc ON plc.customer_id = sc.customerid INNER JOIN country ct ON plc.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = plc.customer_id) "; } $sql=$sql."where plc.id='$qid' and cover_id='$cover_id'"; if($branch_id!='branch_id') { $sql=$sql." and customer_account.branch_id = '$branch_id'"; } if($fromdate != "" && $todate != "") { $sql=$sql." having qrefdate between '$fromdate' and '$todate' "; } // echo $sql.'<br><br><br>'; $res1=$this->db->query($sql); $result=$res1->row(); if(!isset($result->qref)) { continue; } $data[$i]['qtnref']=$result->qref; $data[$i]['qdate']=$result->qrefdate; $data[$i]['plid']=$result->plid; $data[$i]['customerid']=$result->customer_id; $data[$i]['covertype']=$result->cover; $data[$i]['premium']=$result->premium; $data[$i]['brokerage']=$result->brokerage; $data[$i]['policy_no']=$result->policy_no; $data[$i]['staffid']=$result->staffid; $data[$i]['currencycode']=$result->currencycode; $data[$i]['cover_id']=$result->cover_id; $data[$i]['policy_fees']=$result->policy_fees; $data[$i]['insurance_company_id']=$result->insurance_company_id; $data[$i]['percentage']=$result->percentage; $i++; } // var_dump($data); return $data; } function generatereportsalesstf($table,$fromdate,$todate,$staffid,$cover_id,$branch_id,$selectedcovers="") { $data = array(); if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); } $sql="select * from placing_slip_refs pr group by type,pslip_id "; $res=$this->db->query($sql); $i=0; foreach ($res->result_array() as $restype) { $trtype=$restype['type']; $qid=$restype['pslip_id']; if($trtype=='issue') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,c.cover,p.premium,plc.customer_id,plc.cover_id,p.fromdate as qrefdate,p.insurance_company_id,pn.policyno as policy_no,'null' as endmode, p.brokerage,plc.id as plid,plc.cover_id,plc.quotation_ref as qref,plc.currencytype ,p.policy_fees,sc.staffid from placing_slip plc join placing_slip_premiumdetails p on p.placing_slip_id=plc.id left join policynote pn on pn.quotation_ref=plc.quotation_ref join covers c on c.id=plc.cover_id INNER JOIN staffcustomer sc ON plc.customer_id = sc.customerid INNER JOIN country ct ON plc.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = plc.customer_id) "; } else if($trtype=='endorsement') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,plc.endrefno as qref,plc.endpolicyno as policy_no,p.fromdate as qrefdate,plc.premiumchange as premium,plc.policyfeeschange as policy_fees,covers.cover,plc.mode as endmode, p.insurance_company_id,pn.policyno,p.brokerage,pl.id as plid,pl.cover_id,pl.customer_id,pl.quotation_ref,pl.currencytype,sc.staffid from placing_slip pl left join placing_slip_premiumdetails p on p.placing_slip_id=pl.id left join policynote pn on pn.quotation_ref=pl.quotation_ref join endorsement plc on plc.policyid=pn.id left join covers on covers.id=pl.cover_id INNER JOIN staffcustomer sc ON pl.customer_id = sc.customerid INNER JOIN country ct ON pl.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = pl.customer_id) "; } else if($trtype=='cancellation') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,plc.canpolicyno as policy_no,plc.canrefno as qref,p.fromdate as qrefdate,0-plc.premiumchange as premium,p.insurance_company_id,pn.policyno,covers.cover,'0' as policy_fees,'null' as endmode, p.brokerage,pl.id as plid,pl.cover_id,pl.customer_id,pl.quotation_ref,pl.currencytype,sc.staffid from placing_slip pl left join placing_slip_premiumdetails p on p.placing_slip_id=pl.id left join policynote pn on pn.quotation_ref=pl.quotation_ref join cancellation plc on plc.policyid=pn.id left join covers on covers.id=pl.cover_id INNER JOIN staffcustomer sc ON pl.customer_id = sc.customerid INNER JOIN country ct ON pl.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = pl.customer_id) "; } else { $sql="SELECT IFNULL( (select sum(percentage) from declaration_stakeholders where declaration_stakeholders.declaration_id=p.declaration_id ),'0') as percentage,ct.currencycode,c.cover,p.premium,plc.customer_id,plc.cover_id,plc.certificate_refno as qref,plc.certificate_no as policy_no, p.fromdate as qrefdate,p.insurance_company_id,pn.policyno,'null' as endmode, p.brokerage,plc.id as plid,plc.cover_id,plc.quotation_ref,plc.currencytype,p.policy_fees,sc.staffid from declaration plc join declaration_premiumdetails p on p.declaration_id=plc.id left join policynote pn on pn.quotation_ref=plc.quotation_ref join covers c on c.id=plc.cover_id INNER JOIN staffcustomer sc ON plc.customer_id = sc.customerid INNER JOIN country ct ON plc.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = plc.customer_id) "; } if($selectedcovers!='') { $cvrs = str_replace('_', ',',$selectedcovers); $sql=$sql."where plc.id='$qid' and staffid='$staffid' and (cover_id IN ( $cvrs ))"; } else $sql=$sql."where plc.id='$qid' and staffid='$staffid'"; if($cover_id!="cover_id") { $sql=$sql." and cover_id = '$cover_id'"; } if($branch_id!='branch_id') { $sql=$sql." and customer_account.branch_id = '$branch_id'"; } if($fromdate != "" && $todate != "") { $sql=$sql." having qrefdate between '$fromdate' and '$todate' "; } //echo $sql.'<br><br><br>'; $res1=$this->db->query($sql); $result=$res1->row(); if(!isset($result->qref)) { continue; } $data[$i]['qtnref']=$result->qref; $data[$i]['qdate']=$result->qrefdate; $data[$i]['plid']=$result->plid; $data[$i]['customerid']=$result->customer_id; $data[$i]['covertype']=$result->cover; $data[$i]['premium']=$result->premium; $data[$i]['brokerage']=$result->brokerage; $data[$i]['policy_no']=$result->policy_no; $data[$i]['staffid']=$result->staffid; $data[$i]['currencycode']=$result->currencycode; $data[$i]['cover_id']=$result->cover_id; $data[$i]['policy_fees']=$result->policy_fees; $data[$i]['insurance_company_id']=$result->insurance_company_id; $data[$i]['percentage']=$result->percentage; $data[$i]['endmode']=$result->endmode; $i++; } // var_dump($data); return $data; } function generatereportrenewstf($table,$fromdate,$todate,$staffid,$cover_id,$branch_id) { $data = array(); if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); } $sql="select * from placing_slip_refs pr group by type,pslip_id "; $res=$this->db->query($sql); $i=0; foreach ($res->result_array() as $restype) { $trtype=$restype['type']; $qid=$restype['pslip_id']; if($trtype=='issue') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,c.cover,p.premium,plc.customer_id,plc.cover_id,p.todate as qrefdate,p.insurance_company_id,pn.policyno as policy_no, p.brokerage,plc.id as plid,plc.cover_id,plc.quotation_ref as qref,plc.currencytype ,p.policy_fees,sc.staffid from placing_slip plc join placing_slip_premiumdetails p on p.placing_slip_id=plc.id left join policynote pn on pn.quotation_ref=plc.quotation_ref join covers c on c.id=plc.cover_id INNER JOIN staffcustomer sc ON plc.customer_id = sc.customerid INNER JOIN country ct ON plc.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = plc.customer_id) "; } else if($trtype=='endorsement') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,plc.endrefno as qref,plc.endpolicyno as policy_no,p.todate as qrefdate,plc.premiumchange as premium,plc.policyfeeschange as policy_fees,covers.cover, p.insurance_company_id,pn.policyno,p.brokerage,pl.id as plid,pl.cover_id,pl.customer_id,pl.quotation_ref,pl.currencytype,sc.staffid from placing_slip pl left join placing_slip_premiumdetails p on p.placing_slip_id=pl.id left join policynote pn on pn.quotation_ref=pl.quotation_ref join endorsement plc on plc.policyid=pn.id left join covers on covers.id=pl.cover_id INNER JOIN staffcustomer sc ON pl.customer_id = sc.customerid INNER JOIN country ct ON pl.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = pl.customer_id) "; } else if($trtype=='cancellation') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,plc.canpolicyno as policy_no,plc.canrefno as qref,p.todate as qrefdate,0-plc.premiumchange as premium,p.insurance_company_id,pn.policyno,covers.cover,'0' as policy_fees, p.brokerage,pl.id as plid,pl.cover_id,pl.customer_id,pl.quotation_ref,pl.currencytype,sc.staffid from placing_slip pl left join placing_slip_premiumdetails p on p.placing_slip_id=pl.id left join policynote pn on pn.quotation_ref=pl.quotation_ref join cancellation plc on plc.policyid=pn.id left join covers on covers.id=pl.cover_id INNER JOIN staffcustomer sc ON pl.customer_id = sc.customerid INNER JOIN country ct ON pl.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = pl.customer_id) "; } else { $sql="SELECT IFNULL( (select sum(percentage) from declaration_stakeholders where declaration_stakeholders.declaration_id=p.declaration_id ),'0') as percentage,ct.currencycode,c.cover,p.premium,plc.customer_id,plc.cover_id,plc.certificate_refno as qref,plc.certificate_no as policy_no, p.todate as qrefdate,p.insurance_company_id,pn.policyno, p.brokerage,plc.id as plid,plc.cover_id,plc.quotation_ref,plc.currencytype,p.policy_fees,sc.staffid from declaration plc join declaration_premiumdetails p on p.declaration_id=plc.id left join policynote pn on pn.quotation_ref=plc.quotation_ref join covers c on c.id=plc.cover_id INNER JOIN staffcustomer sc ON plc.customer_id = sc.customerid INNER JOIN country ct ON plc.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = plc.customer_id) "; } $sql=$sql."where plc.id='$qid' and staffid='$staffid'"; if($cover_id!="cover_id") { $sql=$sql." and cover_id = '$cover_id'"; } if($branch_id!='branch_id') { $sql=$sql." and customer_account.branch_id = '$branch_id'"; } if($fromdate != "" && $todate != "") { $sql=$sql." having qrefdate between '$fromdate' and '$todate' "; } // echo $sql.'<br><br><br>'; $res1=$this->db->query($sql); $result=$res1->row(); if(!isset($result->qref)) { continue; } $data[$i]['qtnref']=$result->qref; $data[$i]['qdate']=$result->qrefdate; $data[$i]['plid']=$result->plid; $data[$i]['customerid']=$result->customer_id; $data[$i]['covertype']=$result->cover; $data[$i]['premium']=$result->premium; $data[$i]['brokerage']=$result->brokerage; $data[$i]['policy_no']=$result->policy_no; $data[$i]['staffid']=$result->staffid; $data[$i]['currencycode']=$result->currencycode; $data[$i]['cover_id']=$result->cover_id; $data[$i]['policy_fees']=$result->policy_fees; $data[$i]['insurance_company_id']=$result->insurance_company_id; $data[$i]['percentage']=$result->percentage; $i++; } // var_dump($data); return $data; } function generatereportbrostf($table,$fromdate,$todate,$staffid) { $data = array(); $sql = "select distinct broking_slip.id as brid, broking_slip.customer_id,broking_slip.cover_id, broking_slip.quotation_ref,broking_slip.quotation_date,broking_slip.status, staffcustomer.staffid, staffcustomer.customerid from broking_slip inner join staffcustomer on broking_slip.customer_id = staffcustomer.customerid and staffcustomer.staffid = '$staffid'"; if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $sql=$sql." and broking_slip.quotation_date between '$fromdate' and '$todate'"; } $Q=$this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function generatereportplastf($table,$fromdate,$todate,$staffid) { $data = array(); $sql = "select placing_slip.id as plid, placing_slip.customer_id,placing_slip.cover_id, placing_slip.quotation_ref,placing_slip.quotation_date,placing_slip.status, staffcustomer.staffid, staffcustomer.customerid,placing_slip_premiumdetails.premium,placing_slip_premiumdetails.brokerage,placing_slip_premiumdetails.insurance_company_id,insurance_company.company_name from placing_slip inner join staffcustomer inner join placing_slip_premiumdetails inner join insurance_company on placing_slip_premiumdetails.placing_slip_id = placing_slip.id and placing_slip.customer_id = staffcustomer.customerid and insurance_company.id=placing_slip_premiumdetails.insurance_company_id and staffcustomer.staffid = '$staffid'"; if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $sql=$sql." and placing_slip.quotation_date between '$fromdate' and '$todate'"; } $Q=$this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function generatereportbroinscomp($table,$fromdate,$todate,$insurance_company_id) { $data = array(); $sql = "select distinct broking_slip.id, broking_slip.quotation_ref,broking_slip.cover_id,broking_slip.customer_id,broking_slip.quotation_date,broking_slip.status from broking_slip inner join broking_slip_status on broking_slip_status.broking_slip_id = broking_slip.id where broking_slip_status.companyid=$insurance_company_id"; if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $sql=$sql." and broking_slip.quotation_date between '$fromdate' and '$todate'"; } $Q=$this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function generatereportbrobranch($table,$fromdate,$todate,$branch_id) { $data = array(); $sql = "select distinct broking_slip.id, broking_slip.quotation_ref,broking_slip.cover_id,broking_slip.customer_id,broking_slip.quotation_date,broking_slip.status from broking_slip inner join customer_account on customer_account.customer_id = broking_slip.customer_id where customer_account.branch_id=$branch_id"; if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $sql=$sql." and broking_slip.quotation_date between '$fromdate' and '$todate'"; } $Q=$this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function generatereportplainscomp($table,$fromdate,$todate,$insurance_company_id) { $data = array(); $sql = "select placing_slip.id as plid, placing_slip.customer_id,placing_slip.cover_id, placing_slip.quotation_ref,placing_slip.quotation_date,placing_slip.status, staffcustomer.staffid, staffcustomer.customerid,placing_slip_premiumdetails.premium,placing_slip_premiumdetails.brokerage,placing_slip_premiumdetails.insurance_company_id,insurance_company.company_name from placing_slip inner join staffcustomer inner join placing_slip_premiumdetails inner join insurance_company on placing_slip_premiumdetails.placing_slip_id = placing_slip.id and placing_slip.customer_id = staffcustomer.customerid and insurance_company.id=placing_slip_premiumdetails.insurance_company_id and placing_slip_premiumdetails.insurance_company_id = '$insurance_company_id'"; if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $sql=$sql." and placing_slip.quotation_date between '$fromdate' and '$todate'"; } $Q=$this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function generatereportsalesinscomp($table,$fromdate,$todate,$inscompid,$cover_id,$branch_id) { $data = array(); if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); } $sql="select * from placing_slip_refs pr group by type,pslip_id "; $res=$this->db->query($sql); $i=0; foreach ($res->result_array() as $restype) { $trtype=$restype['type']; $qid=$restype['pslip_id']; if($trtype=='issue') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,c.cover,p.premium,plc.customer_id,plc.cover_id,p.fromdate as qrefdate,p.insurance_company_id,pn.policyno as policy_no, p.brokerage,plc.id as plid,plc.cover_id,plc.quotation_ref as qref,plc.currencytype ,p.policy_fees,sc.staffid from placing_slip plc join placing_slip_premiumdetails p on p.placing_slip_id=plc.id left join policynote pn on pn.quotation_ref=plc.quotation_ref join covers c on c.id=plc.cover_id INNER JOIN staffcustomer sc ON plc.customer_id = sc.customerid INNER JOIN country ct ON plc.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = plc.customer_id) "; } else if($trtype=='endorsement') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,plc.endrefno as qref,plc.endpolicyno as policy_no,p.fromdate as qrefdate,plc.premiumchange as premium,plc.policyfeeschange as policy_fees,covers.cover, p.insurance_company_id,pn.policyno,p.brokerage,pl.id as plid,pl.cover_id,pl.customer_id,pl.quotation_ref,pl.currencytype,sc.staffid from placing_slip pl left join placing_slip_premiumdetails p on p.placing_slip_id=pl.id left join policynote pn on pn.quotation_ref=pl.quotation_ref join endorsement plc on plc.policyid=pn.id left join covers on covers.id=pl.cover_id INNER JOIN staffcustomer sc ON pl.customer_id = sc.customerid INNER JOIN country ct ON pl.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = pl.customer_id) "; } else if($trtype=='cancellation') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,plc.canpolicyno as policy_no,plc.canrefno as qref,p.fromdate as qrefdate,0-plc.premiumchange as premium,p.insurance_company_id,pn.policyno,covers.cover,'0' as policy_fees, p.brokerage,pl.id as plid,pl.cover_id,pl.customer_id,pl.quotation_ref,pl.currencytype,sc.staffid from placing_slip pl left join placing_slip_premiumdetails p on p.placing_slip_id=pl.id left join policynote pn on pn.quotation_ref=pl.quotation_ref join cancellation plc on plc.policyid=pn.id left join covers on covers.id=pl.cover_id INNER JOIN staffcustomer sc ON pl.customer_id = sc.customerid INNER JOIN country ct ON pl.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = pl.customer_id) "; } else { $sql="SELECT IFNULL( (select sum(percentage) from declaration_stakeholders where declaration_stakeholders.declaration_id=p.declaration_id ),'0') as percentage,ct.currencycode,c.cover,p.premium,plc.customer_id,plc.cover_id,plc.certificate_refno as qref,plc.certificate_no as policy_no, p.fromdate as qrefdate,p.insurance_company_id,pn.policyno, p.brokerage,plc.id as plid,plc.cover_id,plc.quotation_ref,plc.currencytype,p.policy_fees,sc.staffid from declaration plc join declaration_premiumdetails p on p.declaration_id=plc.id left join policynote pn on pn.quotation_ref=plc.quotation_ref join covers c on c.id=plc.cover_id INNER JOIN staffcustomer sc ON plc.customer_id = sc.customerid INNER JOIN country ct ON plc.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = plc.customer_id) "; } $sql=$sql."where plc.id='$qid' and insurance_company_id='$inscompid'"; if($cover_id!="cover_id") { $sql=$sql." and cover_id = '$cover_id'"; } if($branch_id!='branch_id') { $sql=$sql." and customer_account.branch_id = '$branch_id'"; } if($fromdate != "" && $todate != "") { $sql=$sql." having qrefdate between '$fromdate' and '$todate' "; } // echo $sql.'<br><br><br>'; $res1=$this->db->query($sql); $result=$res1->row(); if(!isset($result->qref)) { continue; } $data[$i]['qtnref']=$result->qref; $data[$i]['qdate']=$result->qrefdate; $data[$i]['plid']=$result->plid; $data[$i]['customerid']=$result->customer_id; $data[$i]['covertype']=$result->cover; $data[$i]['premium']=$result->premium; $data[$i]['brokerage']=$result->brokerage; $data[$i]['policy_no']=$result->policy_no; $data[$i]['staffid']=$result->staffid; $data[$i]['currencycode']=$result->currencycode; $data[$i]['cover_id']=$result->cover_id; $data[$i]['policy_fees']=$result->policy_fees; $data[$i]['insurance_company_id']=$result->insurance_company_id; $data[$i]['percentage']=$result->percentage; $i++; } // var_dump($data); return $data; } function generatereportrenewinscomp($table,$fromdate,$todate,$inscompid,$cover_id,$branch_id) { $data = array(); if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); } $sql="select * from placing_slip_refs pr group by type,pslip_id "; $res=$this->db->query($sql); $i=0; foreach ($res->result_array() as $restype) { $trtype=$restype['type']; $qid=$restype['pslip_id']; if($trtype=='issue') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,c.cover,p.premium,plc.customer_id,plc.cover_id,p.todate as qrefdate,p.insurance_company_id,pn.policyno as policy_no, p.brokerage,plc.id as plid,plc.cover_id,plc.quotation_ref as qref,plc.currencytype ,p.policy_fees,sc.staffid from placing_slip plc join placing_slip_premiumdetails p on p.placing_slip_id=plc.id left join policynote pn on pn.quotation_ref=plc.quotation_ref join covers c on c.id=plc.cover_id INNER JOIN staffcustomer sc ON plc.customer_id = sc.customerid INNER JOIN country ct ON plc.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = plc.customer_id) "; } else if($trtype=='endorsement') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,plc.endrefno as qref,plc.endpolicyno as policy_no,p.todate as qrefdate,plc.premiumchange as premium,plc.policyfeeschange as policy_fees,covers.cover, p.insurance_company_id,pn.policyno,p.brokerage,pl.id as plid,pl.cover_id,pl.customer_id,pl.quotation_ref,pl.currencytype,sc.staffid from placing_slip pl left join placing_slip_premiumdetails p on p.placing_slip_id=pl.id left join policynote pn on pn.quotation_ref=pl.quotation_ref join endorsement plc on plc.policyid=pn.id left join covers on covers.id=pl.cover_id INNER JOIN staffcustomer sc ON pl.customer_id = sc.customerid INNER JOIN country ct ON pl.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = pl.customer_id) "; } else if($trtype=='cancellation') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,plc.canpolicyno as policy_no,plc.canrefno as qref,p.todate as qrefdate,0-plc.premiumchange as premium,p.insurance_company_id,pn.policyno,covers.cover,'0' as policy_fees, p.brokerage,pl.id as plid,pl.cover_id,pl.customer_id,pl.quotation_ref,pl.currencytype,sc.staffid from placing_slip pl left join placing_slip_premiumdetails p on p.placing_slip_id=pl.id left join policynote pn on pn.quotation_ref=pl.quotation_ref join cancellation plc on plc.policyid=pn.id left join covers on covers.id=pl.cover_id INNER JOIN staffcustomer sc ON pl.customer_id = sc.customerid INNER JOIN country ct ON pl.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = pl.customer_id) "; } else { $sql="SELECT IFNULL( (select sum(percentage) from declaration_stakeholders where declaration_stakeholders.declaration_id=p.declaration_id ),'0') as percentage,ct.currencycode,c.cover,p.premium,plc.customer_id,plc.cover_id,plc.certificate_refno as qref,plc.certificate_no as policy_no, p.todate as qrefdate,p.insurance_company_id,pn.policyno, p.brokerage,plc.id as plid,plc.cover_id,plc.quotation_ref,plc.currencytype,p.policy_fees,sc.staffid from declaration plc join declaration_premiumdetails p on p.declaration_id=plc.id left join policynote pn on pn.quotation_ref=plc.quotation_ref join covers c on c.id=plc.cover_id INNER JOIN staffcustomer sc ON plc.customer_id = sc.customerid INNER JOIN country ct ON plc.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = plc.customer_id) "; } $sql=$sql."where plc.id='$qid' and insurance_company_id='$inscompid'"; if($cover_id!="cover_id") { $sql=$sql." and cover_id = '$cover_id'"; } if($branch_id!='branch_id') { $sql=$sql." and customer_account.branch_id = '$branch_id'"; } if($fromdate != "" && $todate != "") { $sql=$sql." having qrefdate between '$fromdate' and '$todate' "; } // echo $sql.'<br><br><br>'; $res1=$this->db->query($sql); $result=$res1->row(); if(!isset($result->qref)) { continue; } $data[$i]['qtnref']=$result->qref; $data[$i]['qdate']=$result->qrefdate; $data[$i]['plid']=$result->plid; $data[$i]['customerid']=$result->customer_id; $data[$i]['covertype']=$result->cover; $data[$i]['premium']=$result->premium; $data[$i]['brokerage']=$result->brokerage; $data[$i]['policy_no']=$result->policy_no; $data[$i]['staffid']=$result->staffid; $data[$i]['currencycode']=$result->currencycode; $data[$i]['cover_id']=$result->cover_id; $data[$i]['policy_fees']=$result->policy_fees; $data[$i]['insurance_company_id']=$result->insurance_company_id; $data[$i]['percentage']=$result->percentage; $i++; } // var_dump($data); return $data; } function generatereportpaymentclient($search,$fromdate,$todate,$cover_id) { $data = array(); $sql = "select placing_slip.customer_id, placing_slip.quotation_ref, placing_slip.status,placing_slip.cover_id, placing_slip.quotation_date, placing_slip_payamount.amount, placing_slip_payamount.paydate from placing_slip inner join placing_slip_payamount where placing_slip.id = placing_slip_payamount.placing_slip_id and placing_slip.customer_id = '$search'"; if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $sql=$sql." and placing_slip_payamount.paydate between '$fromdate' and '$todate'"; } if($cover_id != "") $sql=$sql." and placing_slip.cover_id = '$cover_id'"; $Q=$this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function generatereportpaymentcover($search,$fromdate,$todate) { $data = array(); $sql = "select placing_slip.customer_id, placing_slip.quotation_ref, placing_slip.status,placing_slip.cover_id, placing_slip.quotation_date, placing_slip_payamount.amount, placing_slip_payamount.paydate from placing_slip inner join placing_slip_payamount where placing_slip.id = placing_slip_payamount.placing_slip_id and placing_slip.cover_id = '$search'"; if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $sql=$sql." and placing_slip_payamount.paydate between '$fromdate' and '$todate'"; } $Q=$this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function generatereportpaymentstf($search,$fromdate,$todate) { $data = array(); $sql = "select placing_slip.customer_id, placing_slip.quotation_ref, placing_slip.status,placing_slip.cover_id, placing_slip.quotation_date, placing_slip_payamount.amount, placing_slip_payamount.paydate from placing_slip inner join placing_slip_payamount inner join staffcustomer on placing_slip.id = placing_slip_payamount.placing_slip_id and placing_slip.customer_id = staffcustomer.customerid and staffcustomer.staffid = '$search'"; if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $sql=$sql." and placing_slip_payamount.paydate between '$fromdate' and '$todate'"; } $Q=$this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function generatereportpaymentinscomp($search,$fromdate,$todate) { $data = array(); $sql = "select placing_slip.customer_id, placing_slip.quotation_ref, placing_slip.status,placing_slip.cover_id, placing_slip.quotation_date, placing_slip_payamount.amount, placing_slip_payamount.paydate from placing_slip inner join placing_slip_payamount inner join placing_slip_premiumdetails on placing_slip.id = placing_slip_payamount.placing_slip_id and placing_slip.id = placing_slip_premiumdetails.placing_slip_id and placing_slip_premiumdetails.insurance_company_id = '$search'"; if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $sql=$sql." and placing_slip_payamount.paydate between '$fromdate' and '$todate'"; } //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 generatereportoutstandingclient($search,$fromdate,$todate,$cover_id) { $data = array(); $sql = "select placing_slip.customer_id, placing_slip.quotation_ref, placing_slip.status,placing_slip.cover_id, placing_slip.quotation_date, sum(placing_slip_payamount.amount) as totalamount, placing_slip_payamount.paydate, placing_slip_premiumdetails.premium from placing_slip inner join placing_slip_payamount inner join placing_slip_premiumdetails where placing_slip.id = placing_slip_payamount.placing_slip_id and placing_slip.id=placing_slip_premiumdetails.placing_slip_id and placing_slip.customer_id = '$search'"; if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $sql=$sql." and placing_slip_payamount.paydate between '$fromdate' and '$todate'"; } if($cover_id != "") $sql=$sql." and placing_slip.cover_id = '$cover_id'"; $Q=$this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function generatereportoutstandingcover($search,$fromdate,$todate) { $data = array(); $sql = "select placing_slip.customer_id, placing_slip.quotation_ref, placing_slip.status,placing_slip.cover_id, placing_slip.quotation_date, sum(placing_slip_payamount.amount) as totalamount, placing_slip_payamount.paydate, placing_slip_premiumdetails.premium from placing_slip inner join placing_slip_payamount inner join placing_slip_premiumdetails where placing_slip.id = placing_slip_payamount.placing_slip_id and placing_slip.id=placing_slip_premiumdetails.placing_slip_id and placing_slip.cover_id = '$search'"; if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $sql=$sql." and placing_slip_payamount.paydate between '$fromdate' and '$todate'"; } $Q=$this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function generatereportoutstandingstaff($search,$fromdate,$todate) { $data = array(); $sql = "select placing_slip.customer_id, placing_slip.quotation_ref, placing_slip.status,placing_slip.cover_id, placing_slip.quotation_date, sum(placing_slip_payamount.amount) as totalamount, placing_slip_payamount.paydate, placing_slip_premiumdetails.premium from placing_slip inner join placing_slip_payamount inner join placing_slip_premiumdetails inner join staffcustomer on placing_slip.id = placing_slip_payamount.placing_slip_id and placing_slip.id=placing_slip_premiumdetails.placing_slip_id and placing_slip.customer_id = staffcustomer.customerid and staffcustomer.staffid = '$search'"; if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $sql=$sql." and placing_slip_payamount.paydate between '$fromdate' and '$todate'"; } $Q=$this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function generatereportoutstandinginscomp($search,$fromdate,$todate) { $data = array(); $sql = "select placing_slip.customer_id, placing_slip.quotation_ref, placing_slip.status,placing_slip.cover_id, placing_slip.quotation_date, sum(placing_slip_payamount.amount) as totalamount, placing_slip_payamount.paydate, placing_slip_premiumdetails.premium from placing_slip inner join placing_slip_payamount inner join placing_slip_premiumdetails on placing_slip.id = placing_slip_payamount.placing_slip_id and placing_slip.id=placing_slip_premiumdetails.placing_slip_id and placing_slip_premiumdetails.insurance_company_id = '$search'"; if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $sql=$sql." and placing_slip_payamount.paydate between '$fromdate' and '$todate'"; } //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 generatereportleadsstf($table,$fromdate,$todate,$staffid,$cover_id,$branch_id) { $data = array(); $sql = "SELECT salesleads.leadname , salesleads.remarks , salesleads.rendate as date , staffpersonaldetails.name , covers.cover FROM salesleads INNER JOIN staffpersonaldetails ON (salesleads.staffid = staffpersonaldetails.id) INNER JOIN covers ON (salesleads.cover_id = covers.id) INNER JOIN staffemployeedetails ON (staffemployeedetails.staffid = staffpersonaldetails.id) WHERE staffpersonaldetails.id='$staffid'"; if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $sql=$sql." and salesleads.rendate between '$fromdate' and '$todate'"; } if($cover_id!="cover_id") { $sql=$sql."and covers.id = '$cover_id'"; } if($branch_id!='branch_id') { $sql=$sql." and branchid = '$branch_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 generatereportleadsbra($table,$fromdate,$todate,$branch_id) { $data = array(); $sql = "SELECT salesleads.leadname , salesleads.remarks , salesleads.rendate as date , staffpersonaldetails.name , covers.cover FROM salesleads INNER JOIN staffpersonaldetails ON (salesleads.staffid = staffpersonaldetails.id) INNER JOIN covers ON (salesleads.cover_id = covers.id) INNER JOIN staffemployeedetails ON (staffemployeedetails.staffid = staffpersonaldetails.id) WHERE branchid = '$branch_id'"; if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $sql=$sql." and salesleads.rendate between '$fromdate' and '$todate'"; } //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 generatereporttargetbra($table,$fromdate,$todate,$branch_id) { $data = array(); $sql = "SELECT * FROM branchtarget where branch = $branch_id "; if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $sql=$sql." and branchtarget.startdate between '$fromdate' and '$todate'"; } $Q=$this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function generatereporttargetempwise($table,$fromdate,$todate,$staffid) { $data = array(); $sql = "SELECT * FROM settarget INNER JOIN staffpersonaldetails ON (settarget.staffid = staffpersonaldetails.id) and settarget.staffid = $staffid "; if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $sql=$sql." and settarget.startdate between '$fromdate' and '$todate'"; } $Q=$this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function generatereportdailyactivity($table,$fromdate,$todate,$staffid,$branch_id) { $data = array(); $sql = " SELECT dailyactivitydetails.name as name, dailyactivitydetails.time as time, dailyactivitydetails.contact_person as contact_person,dailyactivitydetails.designation as designation,dailyactivitydetails.tel_no as tel_no, dailyactivitydetails.remarks as remarks, dailyactivity.date as date FROM dailyactivity INNER JOIN staffpersonaldetails ON (dailyactivity.staffid = staffpersonaldetails.id) INNER JOIN staffemployeedetails ON (staffemployeedetails.staffid = staffpersonaldetails.id) INNER JOIN dailyactivitydetails ON (dailyactivitydetails.activityid = dailyactivity.id) where staffpersonaldetails.id='$staffid'"; if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $sql=$sql." and dailyactivity.date between '$fromdate' and '$todate'"; } if($branch_id!='branch_id') { $sql=$sql." and branchid = '$branch_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 generatereportdailyactivitybranch($table,$fromdate,$todate,$branch_id) { $data = array(); $sql = " SELECT dailyactivitydetails.name as name, dailyactivitydetails.time as time,staffpersonaldetails.name as employee_name, dailyactivitydetails.contact_person as contact_person,dailyactivitydetails.designation as designation,dailyactivitydetails.tel_no as tel_no, dailyactivitydetails.remarks as remarks, dailyactivity.date as date FROM dailyactivity INNER JOIN staffpersonaldetails ON (dailyactivity.staffid = staffpersonaldetails.id) INNER JOIN staffemployeedetails ON (staffemployeedetails.staffid = staffpersonaldetails.id) INNER JOIN dailyactivitydetails ON (dailyactivitydetails.activityid = dailyactivity.id) "; if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $sql=$sql." and dailyactivity.date between '$fromdate' and '$todate'"; } if($branch_id!='branch_id') { $sql=$sql." and branchid = '$branch_id'"; } $Q=$this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function getfootervalue() { $sql="select footer from ourbranch join staffemployeedetails on staffemployeedetails.branchid = ourbranch.id join users on users.staff_id = staffemployeedetails.staffid where users.id= '".$_SESSION['userid']."'"; $data=$this->db->query($sql); $result = $data->row(); if($data->num_rows()>0) { return $result->footer; } else { $sql="select footer from ourbranch limit 1"; $data=$this->db->query($sql); $result = $data->row(); return $result->footer; } } function generatereporthrsalaryemp($fromdate,$todate,$staffid) { $data = array(); if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $dt="and salary_date between '$fromdate' and '$todate'"; } else { $dt=""; } $Q=$this->db->query("select es.salary_date,es.pay_date,es.basic_salary,es.allowance,es.deduction,es.netpayment,es.paidamount, es.commission, sp.employeeid,sp.name from emp_salary_slip es join staffpersonaldetails sp on sp.id=es.employee_id where employee_id='$staffid' and unpost='0' $dt "); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function generatereporthrsalarybranch($fromdate,$todate,$branchid) { $data = array(); if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $dt="and salary_date between '$fromdate' and '$todate'"; } else { $dt=""; } $Q=$this->db->query("select es.employee_id,es.salary_date,es.pay_date,es.basic_salary,es.allowance,es.deduction,es.netpayment,es.paidamount, es.commission, sp.employeeid,sp.name from emp_salary_slip es join staffpersonaldetails sp on sp.id=es.employee_id join staffemployeedetails se on se.staffid=es.employee_id where se.branchid='$branchid' and unpost='0' $dt "); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function generatereporthrleave($table,$fromdate,$todate,$staffid) { $data = array(); if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $dt="and fromdate >= '$fromdate' and todate <='$todate'"; } else { $dt=""; } $Q=$this->db->query("select a.fromdate,a.todate,a.leavestatus,a.remarks,l.leavename from assignleave a join leavetype l on l.id=a.type where staffid='$staffid' $dt "); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function generatereporthrleavebranch($table,$fromdate,$todate,$branchid) { $data = array(); if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $dt="and fromdate >= '$fromdate' and todate <='$todate'"; } else { $dt=""; } $Q=$this->db->query("select a.staffid, a.fromdate,a.todate,a.leavestatus,a.remarks,l.leavename from assignleave a join leavetype l on l.id=a.type join staffemployeedetails se on se.staffid=a.staffid where se.branchid='$branchid' $dt "); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function generarereporthrcommissionemp($fromdate,$todate,$staffid) { $data = array(); $comdet=array(); if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $dt="and salary_date between '$fromdate' and '$todate'"; } else { $dt=""; } $sql="select * from placing_slip_refs pr group by type,pslip_id "; $res=$this->db->query($sql); // $i=0; $data['premium']=0; $data['brokerage']=0; $data['percentage']=0; $commis=0; foreach ($res->result_array() as $restype) { $trtype=$restype['type']; $qid=$restype['pslip_id']; if($trtype=='issue') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,c.cover,p.premium,plc.customer_id,plc.cover_id,p.fromdate as qrefdate,p.insurance_company_id,pn.policyno as policy_no, p.brokerage,plc.id as plid,plc.cover_id,plc.quotation_ref as qref,plc.currencytype ,p.policy_fees,sc.staffid from placing_slip plc join placing_slip_premiumdetails p on p.placing_slip_id=plc.id left join policynote pn on pn.quotation_ref=plc.quotation_ref join covers c on c.id=plc.cover_id INNER JOIN staffcustomer sc ON plc.customer_id = sc.customerid INNER JOIN country ct ON plc.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = plc.customer_id) "; } else if($trtype=='endorsement') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,plc.endrefno as qref,plc.endpolicyno as policy_no,p.fromdate as qrefdate,plc.premiumchange as premium,plc.policyfeeschange as policy_fees,covers.cover, p.insurance_company_id,pn.policyno,p.brokerage,pl.id as plid,pl.cover_id,pl.customer_id,pl.quotation_ref,pl.currencytype,sc.staffid from placing_slip pl left join placing_slip_premiumdetails p on p.placing_slip_id=pl.id left join policynote pn on pn.quotation_ref=pl.quotation_ref join endorsement plc on plc.policyid=pn.id left join covers on covers.id=pl.cover_id INNER JOIN staffcustomer sc ON pl.customer_id = sc.customerid INNER JOIN country ct ON pl.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = pl.customer_id) "; } else if($trtype=='cancellation') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,plc.canpolicyno as policy_no,plc.canrefno as qref,p.fromdate as qrefdate,0-plc.premiumchange as premium,p.insurance_company_id,pn.policyno,covers.cover,'0' as policy_fees, p.brokerage,pl.id as plid,pl.cover_id,pl.customer_id,pl.quotation_ref,pl.currencytype,sc.staffid from placing_slip pl left join placing_slip_premiumdetails p on p.placing_slip_id=pl.id left join policynote pn on pn.quotation_ref=pl.quotation_ref join cancellation plc on plc.policyid=pn.id left join covers on covers.id=pl.cover_id INNER JOIN staffcustomer sc ON pl.customer_id = sc.customerid INNER JOIN country ct ON pl.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = pl.customer_id) "; } else { $sql="SELECT IFNULL( (select sum(percentage) from declaration_stakeholders where declaration_stakeholders.declaration_id=p.declaration_id ),'0') as percentage,ct.currencycode,c.cover,p.premium,plc.customer_id,plc.cover_id,plc.certificate_refno as qref,plc.certificate_no as policy_no, p.fromdate as qrefdate,p.insurance_company_id,pn.policyno, p.brokerage,plc.id as plid,plc.cover_id,plc.quotation_ref,plc.currencytype,p.policy_fees,sc.staffid from declaration plc join declaration_premiumdetails p on p.declaration_id=plc.id left join policynote pn on pn.quotation_ref=plc.quotation_ref join covers c on c.id=plc.cover_id INNER JOIN staffcustomer sc ON plc.customer_id = sc.customerid INNER JOIN country ct ON plc.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = plc.customer_id) "; } $sql=$sql."where plc.id='$qid' and staffid='$staffid'"; if($fromdate != "" && $todate != "") { $sql=$sql." having qrefdate between '$fromdate' and '$todate' "; } // echo $sql.'<br><br><br>'; $res1=$this->db->query($sql); $result=$res1->row(); if(!isset($result->qref)) { continue; } $data['premium']+=$result->premium; $data['brokerage']+=$result->brokerage; $data['percentage']+=$result->percentage; $commis+=($result->premium*$result->percentage)/100; // $i++; } // echo $data['premium'].'<br>'; // echo $data['percentage']; $comdet[0]['commissionamt']=$commis; $Q=$this->db->query("select sum(es.commission) as commpaid from emp_salary_slip es join staffpersonaldetails sp on sp.id=es.employee_id where employee_id='$staffid' and unpost='0' $dt "); $resl= $Q->row(); $comdet[0]['commissionpaid']=$resl->commpaid; return $comdet; } function generatereporthrcommissionbranch($fromdate,$todate,$branchid) { $data = array(); $comm=array(); if($fromdate != "" && $todate != "") { $fromdate = $this->mastermodel->convdatformat($fromdate); $todate = $this->mastermodel->convdatformat($todate); $dt="and salary_date between '$fromdate' and '$todate'"; } else { $dt=""; } $sql="select * from placing_slip_refs pr group by type,pslip_id "; $res=$this->db->query($sql); $i=0; // $data['premium']=0; // $data['brokerage']=0; // $data['percentage']=0; $commis=0; foreach ($res->result_array() as $restype) { $trtype=$restype['type']; $qid=$restype['pslip_id']; if($trtype=='issue') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,c.cover,p.premium,plc.customer_id,plc.cover_id,p.fromdate as qrefdate,p.insurance_company_id,pn.policyno as policy_no, p.brokerage,plc.id as plid,plc.cover_id,plc.quotation_ref as qref,plc.currencytype ,p.policy_fees,sc.staffid from placing_slip plc join placing_slip_premiumdetails p on p.placing_slip_id=plc.id left join policynote pn on pn.quotation_ref=plc.quotation_ref join covers c on c.id=plc.cover_id INNER JOIN staffcustomer sc ON plc.customer_id = sc.customerid INNER JOIN country ct ON plc.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = plc.customer_id) join staffemployeedetails se on se.staffid=sc.staffid "; } else if($trtype=='endorsement') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,plc.endrefno as qref,plc.endpolicyno as policy_no,p.fromdate as qrefdate,plc.premiumchange as premium,plc.policyfeeschange as policy_fees,covers.cover, p.insurance_company_id,pn.policyno,p.brokerage,pl.id as plid,pl.cover_id,pl.customer_id,pl.quotation_ref,pl.currencytype,sc.staffid from placing_slip pl left join placing_slip_premiumdetails p on p.placing_slip_id=pl.id left join policynote pn on pn.quotation_ref=pl.quotation_ref join endorsement plc on plc.policyid=pn.id left join covers on covers.id=pl.cover_id INNER JOIN staffcustomer sc ON pl.customer_id = sc.customerid INNER JOIN country ct ON pl.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = pl.customer_id) join staffemployeedetails se on se.staffid=sc.staffid "; } else if($trtype=='cancellation') { $sql="SELECT IFNULL( (select sum(percentage) from placing_slip_stakeholders where placing_slip_stakeholders.placing_slip_id=p.placing_slip_id ),'0') as percentage,ct.currencycode,plc.canpolicyno as policy_no,plc.canrefno as qref,p.fromdate as qrefdate,0-plc.premiumchange as premium,p.insurance_company_id,pn.policyno,covers.cover,'0' as policy_fees, p.brokerage,pl.id as plid,pl.cover_id,pl.customer_id,pl.quotation_ref,pl.currencytype,sc.staffid from placing_slip pl left join placing_slip_premiumdetails p on p.placing_slip_id=pl.id left join policynote pn on pn.quotation_ref=pl.quotation_ref join cancellation plc on plc.policyid=pn.id left join covers on covers.id=pl.cover_id INNER JOIN staffcustomer sc ON pl.customer_id = sc.customerid INNER JOIN country ct ON pl.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = pl.customer_id) join staffemployeedetails se on se.staffid=sc.staffid "; } else { $sql="SELECT IFNULL( (select sum(percentage) from declaration_stakeholders where declaration_stakeholders.declaration_id=p.declaration_id ),'0') as percentage,ct.currencycode,c.cover,p.premium,plc.customer_id,plc.cover_id,plc.certificate_refno as qref,plc.certificate_no as policy_no, p.fromdate as qrefdate,p.insurance_company_id,pn.policyno, p.brokerage,plc.id as plid,plc.cover_id,plc.quotation_ref,plc.currencytype,p.policy_fees,sc.staffid from declaration plc join declaration_premiumdetails p on p.declaration_id=plc.id left join policynote pn on pn.quotation_ref=plc.quotation_ref join covers c on c.id=plc.cover_id INNER JOIN staffcustomer sc ON plc.customer_id = sc.customerid INNER JOIN country ct ON plc.currencytype = ct.id LEFT JOIN customer_account ON (customer_account.customer_id = plc.customer_id) join staffemployeedetails se on se.staffid=sc.staffid "; } $sql=$sql."where plc.id='$qid' and se.branchid='$branchid' "; if($fromdate != "" && $todate != "") { $sql=$sql." having qrefdate between '$fromdate' and '$todate' "; } //echo $sql.'<br><br><br>'; $res1=$this->db->query($sql); $result=$res1->row(); if(!isset($result->qref)) { continue; } $data[$i]['premium']=$result->premium; $data[$i]['brokerage']=$result->brokerage; $data[$i]['percentage']=$result->percentage; $data[$i]['staffid']=$result->staffid; $i++; } $staffidsort=array(); foreach($data as $key => $row) { $staffidsort[$key]=$row['staffid']; } array_multisort($staffidsort, SORT_DESC, $data); $stid='unknown'; $k=-1; foreach($data as $updata) { if($updata['staffid']!=$stid) { $k++; $comm[$k]['premium']=0; $comm[$k]['brokerage']=0; $comm[$k]['commission']=0; $stid=$updata['staffid']; } $comm[$k]['staffid']=$updata['staffid']; $comm[$k]['premium']+=$updata['premium']; $comm[$k]['brokerage']+=$updata['brokerage']; $comm[$k]['commission']+=($updata['premium']*$updata['percentage'])/100; } // $commission=(($data['premium']*$data['percentage'])/100); // // $comdet[0]['commissionamt']=$commission; // $z=0; foreach($comm as $stf) { $empid=$stf['staffid']; $Q=$this->db->query("select sum(commission) as commpaid,name from emp_salary_slip es right join staffpersonaldetails sp on sp.id=es.employee_id where es.employee_id='$empid' and unpost='0' $dt "); $resl= $Q->row(); $comm[$z]['commissionpaid']=$resl->commpaid; $comm[$z]['name']=$resl->name; $z++; } return $comm; } } ?>