/** * Controller for the direct debit payment page * * @return void * * array('sort' => '938611', 'acct' => '07806039', 'assert' => 'true'), */ public function ddAction() { $pageForm = new TenantsInsuranceQuoteB_Form_DirectDebit(); $pageSession = new Zend_Session_Namespace('tenants_insurance_quote'); // Tell page NOT to use AJAX validation as we go $this->view->headScript()->appendScript('var ajaxValidate = true; var ajaxValidatePage = \'dd\';'); if ($this->getRequest()->isPost()) { $valid = $this->_formStepCommonValidate($pageForm, 'dd'); if ($valid && isset($_POST['dd_confirm'])) { // Form is valid and the user has confirmed the bank branch details $pageSession->completed['dd'] = true; // Mark page as valid, so user can progress // Save the direct debit details and redirect to confirmation page $formData = $pageForm->getValues(); $ddData = new Model_Core_Directdebit(); $ddData->refNo = $this->_customerReferenceNumber; $ddData->policyNumber = $this->_policyNumber; $ddData->accountName = $formData["subform_directdebit"]["dd_accountname"]; $ddData->accountNumber = $formData["subform_directdebit"]["bank_account_number"]; $ddData->sortCode = preg_replace('/-/', '', $formData["subform_directdebit"]["bank_sortcode_number"]); $quote = new Manager_Insurance_TenantsContentsPlus_Quote(null, null, $this->_policyNumber); $startDate = $quote->getStartDate(); $firstPayMonth = date("Y-m-d", strtotime("{$startDate} + 1 month")); $ddData->paymentDate = $firstPayMonth; $ddData->paymentFrequency = ucfirst(strtolower($quote->getPayBy())); // Create the Manage Object $ddPayment = new Manager_Core_Directdebit(); // Save the stuffs $ddPayment->save($ddData); $this->_formStepCommonNavigate('dd'); return; } elseif ($valid && !isset($_POST['dd_confirm'])) { // Form data is valid but they haven't confirmed their branch details $formData = $pageForm->getValues(); // Switch the form to the confirmation form (essentially the same but with hidden fields) $pageForm = new TenantsInsuranceQuoteB_Form_BankConfirmation(); // Populate the confirmation form with the data from the main DD form and also fill in the branch details // This is to show the bank branch details in the confirmation screen $bankManager = new Manager_Core_Bank(); $this->view->branchDetails = $bankManager->getBranchDetail($_POST['bank_sortcode_number']); $formData['subform_directdebit']['dd_confirm'] = "yes"; // The form data is in the wrong subform now because we want to use the confirmation form // so we have to switch the key over $formData['subform_bankconfirmation'] = $formData['subform_directdebit']; unset($formData['subform_directdebit']); $pageForm->populate($formData); } if (isset($_POST['back'])) { $this->_formStepCommonNavigate('dd'); return; } } // Load the element data from the database if we can if ($this->_formStepCommonPopulate($pageForm, 'dd')) { // Render the page unless we have been redirected $this->view->form = $pageForm; $this->render('step'); } }
/** * 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); }
/** * Controller for the direct debit payment page * * @return void */ public function ddAction() { $pageForm = new LandlordsInsuranceQuote_Form_BankConfirmation(); $pageSession = new Zend_Session_Namespace('landlords_insurance_quote'); // Tell page NOT to use AJAX validation as we go $this->view->headScript()->appendScript('var ajaxValidate = false; var ajaxValidatePage = \'dd\';'); // Look up bank details to show in view $bankManager = new Manager_Core_Bank(); $this->view->branchDetails = $bankManager->getBranchDetail($pageSession->paymentSelectionDetails['bank_sortcode_number']); // Drop the branch address lines into an array for accessing on the // front-end. $this->view->branchLines = array($this->view->branchDetails->bankNameFull, $this->view->branchDetails->addressLine1, $this->view->branchDetails->addressLine2, $this->view->branchDetails->addressLine3, $this->view->branchDetails->addressLine4, $this->view->branchDetails->town, $this->view->branchDetails->county, $this->view->branchDetails->postCode); if ($this->getRequest()->isPost()) { $valid = $this->_formStepCommonValidate($pageForm, 'dd'); if ($valid && isset($_POST['next'])) { // Form is valid and the user has confirmed the bank branch details $pageSession->completed['dd'] = true; // Mark page as valid, so user can progress $quoteManager = new Manager_Insurance_LandlordsPlus_Quote($this->_quoteID); // Save the direct debit details and redirect to confirmation page $ddData = new Model_Core_Directdebit(); $ddData->refNo = $this->_customerReferenceNumber; $ddData->policyNumber = $quoteManager->getPolicyNumber(); $ddData->accountName = $pageSession->paymentSelectionDetails['dd_accountname']; $ddData->accountNumber = $pageSession->paymentSelectionDetails['bank_account_number']; $ddData->sortCode = str_replace('-', '', $pageSession->paymentSelectionDetails['bank_sortcode_number']); $startDate = $quoteManager->getStartDate(); $firstPayMonth = date('Y-m-d', strtotime("{$startDate} + 1 month")); $ddData->paymentDate = $firstPayMonth; $ddData->paymentFrequency = ucfirst(strtolower($quoteManager->getPayBy())); // Instantiate a DD manager $ddPayment = new Manager_Core_Directdebit(); // Save the stuffs $ddPayment->save($ddData); $this->_formStepCommonNavigate('dd'); return; } if (isset($_POST['back'])) { $this->_formStepCommonNavigate('dd'); return; } } // Load the element data from the database if we can if ($this->_formStepCommonPopulate($pageForm, 'dd')) { // Render the page unless we have been redirected $this->view->form = $pageForm; $this->view->stepNum = 'dd'; $this->render('step'); } }