예제 #1
0
 /**
  * Save a new schedule record,
  * This function needs various bit of information to create a schedule entry
  * @param String $refNo Policy reference number
  */
 public function save($refNo, $quote)
 {
     #$session = new Zend_Session_Namespace('tenants_insurance_quote');
     $scheduleObject = new Model_Insurance_Schedule();
     // Get the quote data
     # $quote = new Manager_Insurance_TenantsContentsPlus_Quote($refNo);
     // Get policy start date
     list($year, $month, $day) = explode("-", date("Y-m-d", strtotime($quote->getStartDate())));
     // This is the month the policy is incepted, there will be no payment on this day (0.00)
     $startMonth = date("F", strtotime("{$year}-{$month}-{$day}"));
     // This is the month that first payment is made, this will be 2x monthly value
     $firstPayMonth = date("F", mktime(0, 0, 0, $month++ > 12 ? 1 : $month, $day, $year));
     //Get the payment Refernce Number
     $scheduleObject->policyNumber = $quote->getPolicyNumber();
     if (strtolower($quote->getPayBy()) == "monthly") {
         /**
          * Direct Debit monthly set the current month to 0, next month is doubled remaining months to a single premium
          * ddfee set to Fees value
          * 
          **/
         // TENANTS FEES
         $feesObject = new Model_Insurance_Fee();
         $feesObject = $quote->getFees();
         $scheduleObject->ddFee = $feesObject->monthlyFeeSP;
         if ($quote->getPolicyName() == "landlordsp") {
             $quoteManager = new Manager_Insurance_LandlordsPlus_Quote($quote->getID());
             $landlordsFees = $quoteManager->getFees();
             $scheduleObject->ddFee = $landlordsFees['landlords_insurance_plus_monthly_admin'];
         }
         if (strtolower($quote->getPayMethod()) == "directdebit" || strtolower($quote->getPayMethod()) == "dd") {
             $ddPayment = new Manager_Core_Directdebit();
             // Get Payment data no from dd table
             $ddData = $ddPayment->getByRefNo($refNo);
             // Set Payment refno
             $scheduleObject->paymentRefNo = $ddData->paymentRefNo;
             // Set dd Fee
             // Iterate thru the months and apply the monthly payment
             while (key($scheduleObject->months)) {
                 $current = key($scheduleObject->months);
                 if ($current != strtolower($startMonth) && $current != strtolower($firstPayMonth)) {
                     $scheduleObject->months[$current] = round($quote->getPolicyQuote(), 2);
                 }
                 if ($current == strtolower($firstPayMonth)) {
                     $scheduleObject->months[$current] = round($quote->getPolicyQuote() * 2, 2);
                 }
                 next($scheduleObject->months);
             }
         } elseif (strtolower($quote->getPayMethod()) == "creditcard" || strtolower($quote->getPayMethod()) == "cc") {
             $ccPayment = new Manager_Core_CreditCard();
             // Get Payment data no from cc table
             $ccData = $ccPayment->getByRefNo($refNo);
             // Set Payment refno
             $scheduleObject->paymentRefNo = $ccData->paymentRefNo;
             // Set cc Fee
             $amount = $quote->getPolicyQuote();
             // This is the month the policy is incepted, there will be no payment on this day (0.00)
             // Iterate thru the months and apply the monthly payment
             while (key($scheduleObject->months)) {
                 $current = key($scheduleObject->months);
                 if ($current != strtolower($startMonth)) {
                     $scheduleObject->months[$current] = round($amount, 2);
                 }
                 next($scheduleObject->months);
             }
         }
     } else {
         /* Annual Stuff happens here */
         /**
          * Direct Debit annual set next month payment to full ammount
          **/
         if (strtolower($quote->getPayMethod()) == "directdebit" || strtolower($quote->getPayMethod()) == "dd") {
             $ddPayment = new Manager_Core_Directdebit();
             // Get Payment data no from dd table
             $ddData = $ddPayment->getByRefNo($refNo);
             // Set Payment refno
             $scheduleObject->paymentRefNo = $ddData->paymentRefNo;
             // Set Next month to full ammount
             $current = strtolower($firstPayMonth);
             $scheduleObject->months[$current] = round($quote->getPolicyQuote(), 2);
         } elseif (strtolower($quote->getPayMethod()) == "creditcard" || strtolower($quote->getPayMethod()) == "cc") {
             /**
              *  Credit Card annual sets all months to zero and Banked to full ammount
              **/
             $ccPayment = new Manager_Core_CreditCard();
             // Get Payment data no from cc table
             $ccData = $ccPayment->getByRefNo($refNo);
             // Set Payment refno
             $scheduleObject->paymentRefNo = $ccData->paymentRefNo;
             // Set firstPayment as banked
             $amount = $quote->getPolicyQuote();
         }
     }
     $schedule = new Datasource_Insurance_Schedules();
     $schedule->insertNew($scheduleObject);
 }
예제 #2
0
 /**
  * Saves the disbursement info to the relevant table 
  *
  * @param String policy, double $amount, int $months, String $paymethod, date $paymentdate, double $fee, int $csuID
  *
  * @return 
  *
  * 
  */
 public function processDisbursement($policynumber, $amount, $months, $paymethod, $paymentdate = null, $fee = null, $csuid = 0, $transactionType = 'payment')
 {
     if (is_null($paymentdate)) {
         $paymentdate = date("Y-m-d");
     }
     /**
      * prepair data to build transactions
      */
     $this->_policynumber = $policynumber;
     $this->_amount = $amount;
     $this->_months = $months;
     $policyDisb = new Datasource_Insurance_LegacyPolicies();
     $policy = $policyDisb->getByPolicyNumber($policynumber);
     $this->_policyname = $policy->policyName;
     $customerDisb = new Datasource_Core_LegacyCustomers();
     $customer = $customerDisb->getCustomer($policy->refNo);
     $scheduleDisb = new Datasource_Insurance_Schedules();
     $schedule = $scheduleDisb->retrieveByPolicyNumber($policynumber);
     $agentDisb = new Datasource_Core_Agents();
     $agentS = $agentDisb->getBySchemeNumber($policy->agentSchemeNumber);
     $agent = $agentDisb->fetchrow($agentS);
     $termDisb = new Datasource_Insurance_Policy_Term();
     $term = $termDisb->getPolicyTerm($policynumber, $policy->startDate);
     $this->_startdate = $policy->startDate;
     $transdata = array();
     $transdata['paymentrefno'] = $schedule->paymentRefNo;
     $transdata['policynumber'] = $policynumber;
     $transdata['paymentdate'] = $paymentdate;
     $transdata['amount'] = $amount;
     $transdata['handlingcharge'] = isset($fee) ? $fee : $schedule->ddFee;
     $transdata['csuid'] = $csuid;
     $transdata['months'] = $months;
     $transdata['paymethod'] = $paymethod;
     $transdata['whitelabelID'] = $agent['twolettercode'];
     $transdata['agentschemeno'] = $policy->agentSchemeNumber;
     $transdata['premier'] = ucfirst($agent['premier']);
     $transdata['salesman'] = $agent['salesman'];
     $transdata['riskarea'] = $policy->riskArea;
     $transdata['riskareab'] = $policy->riskAreaB;
     $transdata['isNewBusiness'] = $term['term'] == 1 ? 'yes' : 'no';
     $transdata['isPaidnet'] = $policy->paidNet;
     $transdata['policyTermID'] = $term['id'];
     $transdata['policyname'] = $policy->policyName;
     $transdata['type'] = $transactionType;
     $this->_transID = $this->_newtransaction->saveDetails($transdata);
     $transdata['trans_id'] = $this->_transID;
     $this->_termid = $transdata['policyTermID'];
     /*
      Create transaction record for MI
     */
     $transupportdata = array();
     $this->_transIDDW = $this->_transaction->saveDetails($transdata);
     $transupportdata['trans_id'] = $this->_transIDDW;
     $transupportdata['customerTitle'] = $customer->getTitle();
     $transupportdata['customerFirstName'] = $customer->getFirstName();
     $transupportdata['customerLastName'] = $customer->getLastName();
     $transupportdata['riskAddress1'] = $policy->propertyAddress1;
     $transupportdata['riskAddress2'] = $policy->propertyAddress2;
     $transupportdata['riskAddress3'] = $policy->propertyAddress3;
     $transupportdata['riskPostcode'] = $policy->propertyPostcode;
     $transupportdata['policytype'] = $policy->policyType;
     $transupportdata['payby'] = $policy->payBy;
     $transupportdata['policyLength'] = $policy->policyLength;
     $this->_transactionSupport->saveDetails($transupportdata);
     $this->_ptranID = $this->_paymentTransaction->saveDetails($transdata);
     $this->_getMult($policy);
     /*
      calculate for disbursement
     */
     $this->_calculateGrossprem($policy);
     $this->_calculateAgentComm($policy, $agent, $term['term']);
     $policyOptionsArray = explode("|", $policy->policyOptions);
     $es = array(4, 28, 29, 30);
     foreach ($policyOptionsArray as $key => $value) {
         $this->_initialise();
         $option = new Datasource_Insurance_Policy_Options($policy->policyType);
         $this->_optionID = $option->fetchOptionsByName($value);
         $this->_sumInsOption = $policyDisb->getPolicyOptionMatch($policy->policyOptions, $value, $policy->amountsCovered);
         if ($this->_sumInsOption > 0 || in_array($this->_optionID, $es)) {
             $this->_premOption = $policyDisb->getPolicyOptionMatch($policy->policyOptions, $value, $policy->optionPremiums) * $this->_mult;
             $this->_discOption = $policyDisb->getPolicyOptionMatch($policy->policyOptions, $value, $policy->optionDiscounts);
             $this->_calculateAgentCommOption();
             $this->_calculateTax();
             $this->_calculateNet($policy, $value);
             $this->_storeOptionDisbursement();
         }
         $this->_policynetprem += $this->_netOption;
         $this->_policyIPT += $this->_iptOption;
         if ($value == "contentstp") {
             $this->_disTcontents = $this->_netOption;
             $this->_iptTcontents = $this->_iptOption;
             $this->_premTcontents = $this->_premOption;
             $this->_sumTcontents = $this->_sumInsOption;
         } elseif ($value == "pedalcyclesp") {
             $this->_disTpedel = $this->_netOption;
             $this->_iptTpedel = $this->_iptOption;
             $this->_premTpedel = $this->_premOption;
             $this->_sumTpedel = $this->_sumInsOption;
         } elseif ($value == "possessionsp" || $value == "specpossessionsp") {
             $this->_disTposs += $this->_netOption;
             $this->_iptTposs += $this->_iptOption;
             $this->_premTposs += $this->_premOption;
             $this->_sumTposs += $this->_sumInsOption;
         } elseif ($value == "buildingsp" || $value == "buildingslflood") {
             $this->_disLbuilding += $this->_netOption;
             $this->_iptLbuilding += $this->_iptOption;
             $this->_premLbuilding += $this->_premOption;
             $this->_sumLbuilding = $this->_sumInsOption;
         } elseif ($value == "buildingsAccidentalDamagep") {
             $this->_disLBA = $this->_netOption;
             $this->_iptLBA = $this->_iptOption;
             $this->_premLBA = $this->_premOption;
             $this->_sumLBA = $this->_sumInsOption;
         } elseif ($value == "limitedcontentsp") {
             $this->_disLcontents = $this->_netOption;
             $this->_iptLcontents = $this->_iptOption;
             $this->_premLcontents = $this->_premOption;
             $this->_sumLcontents = $this->_sumInsOption;
         } elseif ($value == "contentslp" || $value == "contentslflood") {
             $this->_disLcontents += $this->_netOption;
             $this->_iptLcontents += $this->_iptOption;
             $this->_premLcontents += $this->_premOption;
             $this->_sumLcontents = $this->_sumInsOption;
         } elseif ($value == "contentslAccidentalDamagep") {
             $this->_disLCA = $this->_netOption;
             $this->_iptLCA = $this->_iptOption;
             $this->_premLCA = $this->_premOption;
             $this->_sumLCA = $this->_sumInsOption;
         } elseif ($value == "emergencyassistance" || $value == "emergencyassistancestandalone") {
             $this->_disES += $this->_netOption;
             $this->_iptES += $this->_iptOption;
             $this->_premES += $this->_premOption;
             $this->_sumES = $this->_sumInsOption;
         } elseif ($value == "emergencyassistancebahbuildings" || $value == "emergencyassistancebahstandalone") {
             $this->_disEB += $this->_netOption;
             $this->_iptEB += $this->_iptOption;
             $this->_premEB += $this->_premOption;
             $this->_sumEB = $this->_sumInsOption;
         }
         //Zend_Debug::dump($this);
     }
     $this->_grosspremium = round($this->_policypremium + $this->_policyIPT, 2);
     $this->_calCulateBalance();
     if ($this->_policyname == "tenantsp") {
         $this->_newtransaction->updateNewTranForTenant($this);
         $this->_transaction->updateTranForTenant($this);
     }
     if ($this->_policyname == "landlordsp") {
         $this->_newtransaction->updateTranForLandlord($this);
         $this->_transaction->updateTranForLandlord($this);
     }
     $this->_paymentTransaction->updatePaymentTransaction($this);
     /*
      * TODO reverse or refund disbursement
      */
     if ($amount < 0) {
     }
 }