getWizardDataFromSession('applicants'); $applicantIndex = Qs_Request::getRequestValue('applicantIndex'); $action = Qs_Request::getRequestValue('action'); $debug = Qs_Request::getRequestValue('debug'); if (isset($debug)) { $this->_saveDebugStatusToSession($debug); } if (isset($step) && $step != 1 && empty($applicants)) { Qs_Http::redirect($this->url()); } $languageMarker = $this->getLanguageMarkerFromSession(); $wizardLastStep = $this->getWizardLastStep(); if (($languageMarker && $this->_getCacheName() && !$action) || (isset($step) && $step == $wizardLastStep && isset($continueBtn) && !empty($applicants) && isset($applicantIndex) && (($applicantIndex == max(array_keys($applicants))) || ($this->isDebugMode() && $applicantIndex == 0))) ) { $this->_action = 'complete'; } elseif (isset($step) && $step == $wizardLastStep && empty($applicants)) { /* if something wrong, redirect to first page (start over) */ Qs_Http::redirect($this->url()); } elseif (isset($step)) { $this->_action = 'new'; $this->_unsetResultCacheName(); } if (!isset($action) && !isset($debug) && !$languageMarker) { /** unset Session data */ $this->unsetWizardDataFromSession(); $this->unsetCurrentFormFromSession(); $this->_unsetResultCacheName(); } return parent::exec(); } protected function _doNew() { $continueBtn = Qs_Request::getRequestValue('btnSubmit'); if (isset($continueBtn)) { $options = array( 'step' => Qs_Request::getRequestValue('step'), 'applicantIndex' => Qs_Request::getRequestValue('applicantIndex'), 'isValidationRender' => true ); $form = $this->_getNewForm($options); if ($form->validate()) { $this->_saveStepData(); $this->_addForm(); } else { $this->_addNotValidForm($form); } } else { if ($this->getLanguageMarkerFromSession()) { $this->_addCurrentForm(); } else { $this->_addForm(); } } $this->unsetLanguageMarkerFromSession(); return $this; } protected function _getNewForm(array $options = array()) { $form = $this->_getFormInstance('new', $options); return $form; } protected function _addNotValidForm($form) { $step = Qs_Request::getRequestValue('step'); $lastStep = $this->getConfig('wizardLastStep'); $step = ($step > $lastStep) ? $lastStep : $step; $stepTitle = $this->getConfig('stepTitle')->toArray()[$step]; $applicantIndex = Qs_Request::getRequestValue('applicantIndex'); $applicants = $this->getWizardDataFromSession('applicants'); $applicantName = (isset($applicantIndex) && $applicants && isset($applicants[$applicantIndex])) ? $applicants[$applicantIndex] : null; $this->_addItem(array( 'tpl' => $this->getTemplate('header.tpl'), 'stepTitle' => (isset($applicantName)) ? str_replace('%Name%', $applicantName, $this->translate($stepTitle)) : (($step == 1) ? $this->translate($stepTitle) : ''), )); $this->_addFormItem($form); return $this; } protected function _addCurrentForm() { $step = $this->getCurrentFormFromSession()['step']; $lastStep = $this->getConfig('wizardLastStep'); $step = ($step > $lastStep) ? $lastStep : $step; $stepTitle = $this->getConfig('stepTitle')->toArray()[$step]; $applicantIndex = $this->getCurrentFormFromSession()['applicantIndex']; $options = array( 'step' => $this->getCurrentFormFromSession()['step'], 'applicantIndex' => $applicantIndex, ); $defaults = $this->_prepareDefaultData($step, $applicantIndex); if ($step == 1) { $options['applicantsCount'] = $defaults['applicantsCount']; } $form = $this->_getNewForm($options); $form->setDefaults($defaults); $applicants = $this->getWizardDataFromSession('applicants'); $applicantName = (isset($applicantIndex) && $applicants && isset($applicants[$applicantIndex])) ? $applicants[$applicantIndex] : null; $this->_addItem(array( 'tpl' => $this->getTemplate('header.tpl'), 'stepTitle' => (isset($applicantName)) ? str_replace('%Name%', $applicantName, $this->translate($stepTitle)) : (($step == 1) ? $this->translate($stepTitle) : ''), )); $this->_addFormItem($form); if ($step == 2) { /* Resources for Advanced Income Calculator Popup*/ $this->_addPopupResources(); } return $this; } protected function _doNewAjax() { $this->_validateFormAjax(); } protected function _addForm() { $options = array(); $applicantIndex = 0; $lastStep = $this->getWizardLastStep(); $step = Qs_Request::getRequestValue('step'); $continueBtn = Qs_Request::getRequestValue('btnSubmit'); if ($step) { $nextStep = (isset($continueBtn)) ? $step + 1 : $step - 1; if ($nextStep < 1) { $nextStep = 1; } $options['step'] = $nextStep; if ($nextStep >= 1) { $applicantIndex = Qs_Request::getRequestValue('applicantIndex'); $applicants = $this->getWizardDataFromSession('applicants'); if (!isset($applicantIndex)) { $applicantIndex = 0; } else { if ($nextStep > $step) { //move forward if (isset($applicants[$applicantIndex + 1])) { //next applicant $applicantIndex = $applicantIndex + 1; $options['step'] = $step; } else { //next step $options['step'] = $nextStep; $applicantIndex = 0; } } else { //move backward if (isset($applicants[$applicantIndex - 1])) { //prev applicant $applicantIndex = $applicantIndex - 1; $options['step'] = $step; } else { //prev step $options['step'] = $nextStep; $applicantIndex = max(array_keys($applicants)); } } } if ($options['step'] == 3) { //step "Questionnaire for Immigration" $isUSCitizen = $this->_getStorageData(2, $applicantIndex)['isUSCitizen']; if ($isUSCitizen == 'y') { while (isset($applicants[$applicantIndex]) && $isUSCitizen == 'y') { $applicantIndex = ($nextStep > $step) ? $applicantIndex + 1 : $applicantIndex - 1; $isUSCitizen = $this->_getStorageData(2, $applicantIndex)['isUSCitizen']; } if (!isset($applicants[$applicantIndex])) { $options['step'] = ($nextStep > $step) ? 4 : 2; $applicantIndex = ($nextStep > $step) ? 0 : max(array_keys($applicants)); } } } if ($options['step'] == 6 && $this->isDebugMode()) { if ($nextStep > $options['step']) { $options['applicantIndex'] = max(array_keys($applicants)); } else { $options['applicantIndex'] = 0; } $options['step'] = $nextStep; } else { $options['applicantIndex'] = $applicantIndex; $options['applicantName'] = $applicants[$applicantIndex]; } } else { $options['step'] = $nextStep; } } else { $options['step'] = 1; } $step = ($options['step'] > $lastStep) ? $lastStep : $options['step']; $stepTitle = $this->getConfig('stepTitle')->toArray()[$step]; $this->_addItem(array( 'tpl' => $this->getTemplate('header.tpl'), 'stepTitle' => (isset($options['applicantName'])) ? str_replace('%Name%', $options['applicantName'], $this->translate($stepTitle)) : (($step == 1 || $step == 6) ? $this->translate($stepTitle) : ''), 'debugMode' => $this->isDebugMode() )); $defaults = $this->_prepareDefaultData($step, $applicantIndex); if ($step == 1) { $options['applicantsCount'] = $defaults['applicantsCount']; } $form = $this->_getNewForm($options); $form->setDefaults($defaults); $this->_addFormItem($form); if ($step == 2) { /* Resources for Advanced Income Calculator Popup*/ $this->_addPopupResources(); } $this->_saveCurrentFormToSession($options['step'], $options['applicantIndex']); return $this; } protected function _prepareDefaultData($step, $applicantIndex) { $configDefaults = $this->getConfig('defaults')->toArray()[$step]; $sessionData = $this->getWizardDataFromSession($step); if ($step == 1) { $defaults = array_merge($configDefaults, $sessionData); } else { if ($applicantIndex > 0) { $configDefaults = $this->_prepareSameForAllData($configDefaults, $sessionData, $step); } if ($step == 4 && $applicantIndex > 0) { /* autofill spouse info */ $configDefaults = $this->_prepareSpouseData($configDefaults, $sessionData, $applicantIndex); } $defaults = array_merge( $configDefaults, (isset($sessionData[$applicantIndex])) ? $sessionData[$applicantIndex] : [] ); } if ($step == 6) { // if Debug page $defaults['debugInfo'] = $this->_prepareDebugInfoContent(); } return $defaults; } protected function _prepareSameForAllData($defaultsData, $sessionData, $step) { /* key = step*/ $sameForAllElements = array( 2 => array('isUSCitizen', 'isMnResident', 'isAmericanIndian', 'isEligibleMedicare', 'zip'), 5 => array('insuranceSituation', 'monthlyPremium', 'isInsuranceOfferMin') ); if (isset($sameForAllElements[$step]) && $sameForAllElements[$step]) { $firstApplicantData = $sessionData[0]; foreach ($sameForAllElements[$step] as $sensitiveElement) { $sameValue = ($firstApplicantData[$sensitiveElement . App_Wizard_Form_New::SAME_FOR_ALL]); if ($sameValue == 'y') { $defaultsData[$sensitiveElement] = $firstApplicantData[$sensitiveElement]; } } } return $defaultsData; } protected function _prepareSpouseData($defaultsData, $sessionData, $applicantIndex) { foreach ($sessionData as $sessionApplicantIndex => $sessionApplicantData) { if ($sessionApplicantIndex == $applicantIndex) { break; } else { if (isset($sessionApplicantData['isMarried']) && $sessionApplicantData['isMarried'] == 'y' && $sessionApplicantData['spouseId'] == $applicantIndex ) { $defaultsData['isMarried'] = $sessionApplicantData['isMarried']; $defaultsData['spouseId'] = $sessionApplicantIndex; if ($sessionApplicantData['taxFilingStatus'] == 'filer') { $defaultsData['taxFilingStatus'] = $sessionApplicantData['taxFilingStatus']; $defaultsData['spouseFilingStatus'] = $sessionApplicantData['spouseFilingStatus']; $defaultsData['isLivingTogether'] = $sessionApplicantData['isLivingTogether']; } break; } } } return $defaultsData; } protected function _addPopupResources() { $this->_doc->addScript('js/fancybox/jquery.fancybox.js'); $this->_doc->addStylesheet('css/thirdpart/fancybox/jquery.fancybox.css'); return $this; } public function getWizardLastStep() { $wizardLastStep = $this->getConfig('wizardLastStep'); return ($this->isDebugMode()) ? $wizardLastStep + 1 : $wizardLastStep; } protected function _saveStepData() { $data = Qs_Request::getPost(); if (isset($data['step']) && $data['step'] != 6) { $this->_saveWizardDataToSession($this->_prepareFormData($data)); } /* if ($_SERVER["REMOTE_ADDR"] == '10.0.0.19') { vlive('Save Data', $this->getWizardDataFromSession()); vlive('Debug Status', $this->getDebugStatusFromSession()); } */ return $this; } /** * Prepare Form Data before save * * @param array $data * @return array */ protected function _prepareFormData($data) { if (2 == $data['step']) { $data['annualIncome'] = (!empty($data['annualIncome'])) ? $data['annualIncome'] : '0.00'; $data['monthlyIncome'] = (!empty($data['monthlyIncome'])) ? $data['monthlyIncome'] : '0.00'; } elseif (4 == $data['step']) { $data['additionalPersons'] = $this->_prepareNewPersonsData($data); } return $data; } protected function _prepareNewPersonsData($data) { $dependentElements = array( 'siblingsCount' => 'sibling', 'parentsCount' => 'parent', 'childrenCount' => 'child', 'dependentsCount' => 'dependent', 'filersCount' => 'filer', 'filersDependentsCount' => 'filersDependent' ); $newPersons = array(); foreach ($dependentElements as $elementCount => $elementName) { for($i = 0; $i < $data[$elementCount]; $i++) { $newPersons = array_merge($newPersons, $this->_getPersonInfo($data, $elementName, $i)); } } $newPersons = array_merge($newPersons, $this->_getPersonInfo($data, 'spouse')); return $newPersons; } protected function _getPersonInfo($data, $element, $countIndex = 0) { $info = array(); $elementSuffix = ($element != 'spouse') ? '_' . $countIndex : ''; $nameField = 'new' . ucfirst($element) . $elementSuffix; if (isset($data[$nameField])) { $newName = ucfirst(trim($data[$nameField])); if ($newName) { $annualIncome = $data[$element . 'AnnualIncome' . $elementSuffix]; $monthlyIncome = $data[$element . 'MonthlyIncome' . $elementSuffix]; $info[$newName]['applicantIndex'] = $data['applicantIndex']; $info[$newName]['type'] = $element; $info[$newName]['name'] = $newName; $info[$newName]['annualIncome'] = ($annualIncome) ? $annualIncome : '0.00'; $info[$newName]['monthlyIncome'] = ($monthlyIncome) ? $monthlyIncome : '0.00'; } } return $info; } /** * Return session object * * @param string $sessionName * @return Qs_Session_Namespace */ protected function _getSession($sessionName = null) { if ($sessionName === null) { $sessionName = get_class($this); } if ($this->_session && $this->_session->getNamespace() != $sessionName) { $this->_session = null; } if (null === $this->_session) { $this->_session = new Qs_Session_Namespace($sessionName, true); } return $this->_session; } protected function _saveDebugStatusToSession($status) { if (in_array($status, array(self::DEBUG_ON, self::DEBUG_OFF))) { $this->_getSession()->wizardDebug = $status; } return $this; } public function getDebugStatusFromSession() { return $this->_getSession()->wizardDebug; } protected function _saveCurrentFormToSession($step, $applicantIndex) { $this->_getSession()->wizardCurrentForm = array('step' => $step, 'applicantIndex' => $applicantIndex); return $this; } public function getCurrentFormFromSession() { return $this->_getSession()->wizardCurrentForm; } public function unsetCurrentFormFromSession() { return $this->_getSession()->wizardCurrentForm = null; } public function getLanguageMarkerFromSession() { return $this->_getSession()->wizardLanguageMarker; } protected function _saveLanguageMarkerToSession($value) { $this->_getSession()->wizardLanguageMarker = $value; return $this; } public function unsetLanguageMarkerFromSession() { return $this->_getSession()->wizardLanguageMarker = null; } public function isDebugMode() { return (self::DEBUG_ON == $this->getDebugStatusFromSession()); } /** * Save Wizard data to session * * @param array $data * @return App_Wizard_View */ protected function _saveWizardDataToSession($data) { if ($data) { foreach (array('__idItem', '_birth', 'action', 'btnCancel', 'btnSubmit') as $field) { if (array_key_exists($field, $data)) { unset($data[$field]); } } $saveData = array(); if ($data['step'] == 1) { if (!isset($data['applicants'])) { $data['applicants'] = array(); } $saveData['applicants'] = $data['applicants']; $this->unsetWizardDataFromSession('applicants'); $saveData[$data['step']] = $data; } elseif ($data['step'] == 4) { $sessionData = $this->getWizardDataFromSession(); $sessionPersons = (isset($sessionData['additionalPersons'])) ? $sessionData['additionalPersons'] : array(); $previousPersons = $this->_unsetAdditionalPersons($sessionPersons, $data['applicantIndex']); $saveData = array( 'additionalPersons' => array_merge((array)$previousPersons, $data['additionalPersons']), $data['step'] => $this->getWizardDataFromSession($data['step']) ); $this->unsetWizardDataFromSession('additionalPersons'); unset($data['additionalPersons']); $saveData[$data['step']][$data['applicantIndex']] = $data; } else { $saveData = array($data['step'] => $this->getWizardDataFromSession($data['step'])); $saveData[$data['step']][$data['applicantIndex']] = $data; } $this->unsetWizardDataFromSession($data['step']); $previousData = $this->getWizardDataFromSession(); $this->_getSession()->wizardData = (array)$previousData + $saveData; } return $this; } /** * Unset persons who has applicantIndex provided value * @param array $persons * @param int $applicantIndex * @return array */ protected function _unsetAdditionalPersons(array $persons, $applicantIndex) { foreach ($persons as $key => $person) { if ($person['applicantIndex'] == $applicantIndex) { unset($persons[$key]); } } return $persons; } /** * Return Wizard data from session * @param int|null $step * @return array */ public function getWizardDataFromSession($step = null) { $storageData = $this->_getSession()->wizardData; if ($step) { if (isset($storageData[$step]) && $storageData[$step]) { $storageData = (array)$storageData[$step]; } else { $storageData = []; } } return $storageData; } public function unsetWizardDataFromSession($step = null) { if ($step) { unset($this->_getSession()->wizardData[$step]); } else { $this->_getSession()->wizardData = null; } return $this; } protected function _doCompleteAjax() { $this->_validateFormAjax(); } protected function _doComplete() { /* Save last form data */ $this->_saveStepData(); $this->_addResultResources(); $this->unsetCurrentFormFromSession(); $this->_addItem(array( 'tpl' => $this->getTemplate('header.tpl'), 'stepTitle' => $this->translate($this->getConfig('stepTitle')->toArray()[$this->getConfig('wizardLastStep') + 2]), 'debugMode' => $this->isDebugMode() )); $data = $this->_processingWizardResult(); $this->_addItem(array( 'tpl' => $this->getTemplate('result.tpl'), 'result' => $data, 'resultPageContent' => App_Settings_Obj::get('resultPageContent'), 'total' => $this->_calculateTotalTaxCreditAmount($data) )); $this->unsetLanguageMarkerFromSession(); return $this; } protected function _getSecurityParams() { $secure = false; $httpOnly = false; /** @var $config Zend_Config */ $securityConfig = Zend_Registry::get('config')->security->toArray(); if ($securityConfig) { if (isset($securityConfig['session'])) { if (isset($securityConfig['session']['cookie_secure']) && $securityConfig['session']['cookie_secure'] && isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ) { $secure = true; } if (isset($securityConfig['session']['cookie_httponly']) && $securityConfig['session']['cookie_httponly'] ) { $httpOnly = true; } } } return ['secure' => $secure, 'httpOnly' => $httpOnly]; } protected function _generateCacheName() { return md5(time()); } protected function _unsetResultCacheName() { if (isset($_COOKIE['resultCacheName'])) { unset($_COOKIE['resultCacheName']); setcookie('resultCacheName', null, 1, '/'); } return $this; } protected function _setCacheName() { $cashName = $this->_generateCacheName(); $security = $this->_getSecurityParams(); //set the cookie to expire in 30 days setcookie( 'resultCacheName' , $cashName, time() + 86400 * 30, '/', null, $security['secure'], $security['httpOnly']); return $cashName; } protected function _getCacheName() { return \Qs_Array::get($_COOKIE, 'resultCacheName'); } protected function _saveResultDataToCache($data) { App_Wizard_Cache::set($this->_setCacheName(), $data); return $this; } protected function _getResultDataFromCache() { return App_Wizard_Cache::get($this->_getCacheName()); } protected function _addResultResources() { $this->_addPopupResources(); $this->_doc->addScript('js/app/gtm-event.js'); $this->_doc->addScript('js/app/wizard-form-tip.js', array(), 'wizard-form'); $this->_doc->addInitFunction('Form_Wizard_Tip.init', array()); $this->_doc->addScript('js/app/wizard-language.js'); $this->_doc->addInitFunction('Form_Wizard_Language.init', array()); $this->_doc->addScript('js/app/email-to.js'); $options = array('sendSuccessMsg' => $this->translate('Email was successfully sent to recipient.')); $this->_doc->addInitObject('app.EmailTo', array($options), 'emailToForm'); return $this; } protected function _getDebugInfo() { $data = $this->getWizardDataFromSession(); $processing = new App_Wizard_Processing($data); return $processing->getDebugData(); } protected function _prepareDebugInfoContent() { $debugInfo = $this->_getDebugInfo(); $smarty = $this->_doc->getSmarty(); $smarty->assign('result', $debugInfo['result']); $smarty->assign('calculating', $debugInfo['calculating']); return $smarty->fetch('Wizard/debug-info.tpl'); } protected function _processingWizardResult() { if (!$this->_getCacheName()) { $data = $this->getWizardDataFromSession(); $processing = new App_Wizard_Processing($data); $result = $processing->getResult(); $this->_saveResultDataToCache($result); } else { $result = $this->_getResultDataFromCache(); } if (is_array($result)) { $this->_assignResultText($result); } return $result; } /** * Filter result texts * @param array $resultTextIds * @return array */ protected function _filterResults($resultTextIds) { /* if results contain #21 and #9, unset #9 (issue HIST-49) */ if (in_array(21, $resultTextIds) && in_array(9, $resultTextIds)) { unset($resultTextIds[9]); } if (in_array(20, $resultTextIds) && in_array(9, $resultTextIds)) { unset($resultTextIds[20]); } return $resultTextIds; } protected function _assignResultText(&$result) { $resultTextObj = new App_ResultText_Obj(); foreach ($result as $key => $applicantResult) { $resultTextIds = $this->_filterResults($applicantResult['resultTextId']); $isAmericanIndian = $this->_getStorageData(2, $key)['isAmericanIndian']; if (isset($resultTextIds)) { if ($resultTexts = $resultTextObj->getResultTextById($resultTextIds)) { foreach($resultTexts as $resultTextId => $resultText){ if ($resultTextId == 5) { $resultText = str_replace('{premiumAmount}', $applicantResult['premiumAmount'], $resultText); } $result[$key]['resultText'][$resultTextId] = $resultText; } /* If $resultTextIds doesn't contain results 25, 26, 27, 28, 29*/ $aiResultsInResultList = array_intersect(array(25, 26, 27, 28, 29), $resultTextIds); if ('y' == $isAmericanIndian && empty($aiResultsInResultList)) { /* If none of the above is true, use the applicable results text but append the text from Results Text #30 to the result. */ $result[$key]['resultText'][30] = reset($resultTextObj->getResultTextById(array(30))); } /* add Note to results*/ if (isset($result[$key]['note'])) { if ($result[$key]['note'] == 'Student/Worker') { $result[$key]['resultText'][13] = reset($resultTextObj->getResultTextById(array(13))); } elseif ($result[$key]['note'] == 'OtherImmStatus') { $result[$key]['resultText'][12] = reset($resultTextObj->getResultTextById(array(12))); } } } } } return $this; } protected function _calculateTotalTaxCreditAmount($data) { $total = 0; if (is_array($data)) { foreach ($data as $applicantData) { if (isset($applicantData['aptcAmount']) && $applicantData['aptc']) { $total = $applicantData['aptcAmount']; } } } return $total; } protected function _validateFormAjax() { $continueBtn = Qs_Request::getRequestValue('btnSubmit'); if ($continueBtn) { $options = array( 'step' => Qs_Request::getRequestValue('step'), 'applicantIndex' => Qs_Request::getRequestValue('applicantIndex'), 'isValidationRender' => true ); $form = $this->_getNewForm($options); $this->_displayJson($form->validateAjax()); } else { $this->_displayJson(array('isValid' => true)); } } protected function _doChangeLanguage() { return $this->_do404(); } protected function _doChangeLanguageAjax() { if ($url = Qs_Request::getPostValue('url')) { $this->_saveLanguageMarkerToSession($url); } exit; } protected function _doGetFilersDependentsData() { return $this->_do404(); } protected function _doGetFilersDependentsDataAjax() { $data = array('result' => null); $applicantIndex = Qs_Request::getPostValue('applicantIndex'); $filers = Qs_Request::getPostValue('filers'); $filersCount = Qs_Request::getPostValue('filersCount'); /* get data from session for step 4 */ $sessionData = $this->getWizardDataFromSession(4); if (isset($sessionData[$applicantIndex]) && $sessionData[$applicantIndex]['filersDependentsCount'] > 0) { /* Якщо вже є засабмічені дані filersDependents для поточного юзера, то ніяких дій не робити */ $data['result'] = 'noAction'; } else { if ($filersCount == count($filers)) { for ($i = 0; $i < $applicantIndex; $i++) { $applicantData = $sessionData[$i]; if ($applicantData['taxFilingStatus'] == 'dependent') { if ($applicantData['filersCount'] == $filersCount) { $applicantFilers = $this->_getDependentElementValues( $applicantData, 'filerId', $filersCount); $diff = array_diff($applicantFilers, $filers); if (empty($diff)) { /* одинакові файлери*/ $data['result'] = $this->_getDependentElementValues( $applicantData, 'filersDependentId', $applicantData['filersDependentsCount']); break; } else { $data['result'] = array(); } } else { $data['result'] = array(); } } } } } $this->_displayJson($data); exit; } protected function _getDependentElementValues($data, $elementName, $count) { $result = array(); for ($i = 0; $i < $count; $i++) { $result[] = ('new' != ($value = $data[$elementName . '_' . $i])) ? $value : ''; } return $result; } protected function _doGetInsuranceOffer() { return $this->_do404(); } protected function _doGetInsuranceOfferAjax() { $data = array(); $ip = Qs_Request::getPostValue('ip'); $applicantIndex = Qs_Request::getPostValue('applicantIndex'); $annualIncome = (new App_Wizard_Processing($this->getWizardDataFromSession()))->getIncomeAPTC($applicantIndex); if (null != $ip && $annualIncome) { $data['result'] = (self::checkInsuranceOffer($ip, $annualIncome)) ? false : true; } $this->_displayJson($data); exit; } protected function _doGetApplicantIncome() { return $this->_do404(); } protected function _doGetApplicantIncomeAjax() { $data = array(); $applicantIndex = Qs_Request::getPostValue('applicantIndex'); $formData = $this->getWizardDataFromSession(); if ($personIndex = self::isAdditionalPersonIndex($applicantIndex)) { $annualIncome = $formData['additionalPersons'][$personIndex]['annualIncome']; $monthlyIncome = $formData['additionalPersons'][$personIndex]['monthlyIncome']; } else { $annualIncome = $formData[2][$applicantIndex]['annualIncome']; $monthlyIncome = $formData[2][$applicantIndex]['monthlyIncome']; } if (isset($monthlyIncome) && isset($annualIncome)) { $data['result'] = ['monthlyIncome' => $monthlyIncome, 'annualIncome' => $annualIncome]; /* issue HIST-40 p.5 $isIncomeAge = App_Wizard_View::checkApplicantAge( $formData[2][$applicantIndex]['birth'], App_Settings_Obj::get('minIncomeAge') ); $data['result']['show'] = $isIncomeAge; */ } $this->_displayJson($data); exit; } /** * if $applicantIndex is Additional Person Index return person index * @param int|string $applicantIndex * @return string|bool */ public static function isAdditionalPersonIndex($applicantIndex) { if (preg_match('/^' . App_Wizard_Form_Abstract::NEW_PERSON_PREFIX . '(.*)/', $applicantIndex, $matches)) { return $matches[1]; } else { return false; } } protected function _doGetApplicantAge() { return $this->_do404(); } protected function _doGetApplicantAgeAjax() { $data = array(); $birth = Qs_Request::getPostValue('birth'); if ($birth) { $data['result'] = self::getApplicantAge($birth); } $this->_displayJson($data); exit; } /** * Check (IP*12 > 0.0956*AINCOME) * @param float $ip * @param float $aincome * @return bool */ public static function checkInsuranceOffer($ip, $aincome) { $ip = self::currencyToFloat($ip); if ($ip && $aincome) { return ($ip * 12 > App_Settings_Obj::get('ESIConst') * $aincome) ? true : false; } return false; } public static function checkApplicantAge($birth, $minAge) { return (static::getApplicantAge($birth) >= $minAge); } public static function getApplicantAge($birth) { return date_diff(date_create($birth), date_create('today'))->y; } /** * convert currency string to float string * @param $currencyStr * @return mixed */ public static function currencyToFloat($currencyStr) { return preg_replace('/[^\d\.]/', '', $currencyStr); } protected function _getStorageData($step, $applicantIndex) { $configDefaults = $this->getConfig('defaults')->toArray()[$step]; $sessionData = $this->getWizardDataFromSession($step); return array_merge( $configDefaults, (isset($sessionData[$applicantIndex])) ? (array)$sessionData[$applicantIndex] : []); } protected function _doIncomeCalculatorPopup() { $this->_doc->display404(); } protected function _doIncomeCalculatorPopupAjax() { $this->_doc->clearInitFunctions(); $this->_doc->clearScripts(); $this->_doc->clearStylesheets(); $form = $this->_getFormInstance('incomeCalculator', array('defaults' => array())); $form->setAttrib('id', 'income-calculator-form'); $form->prependId(true); $form->setDefaults(); $smarty = $this->_doc->getSmarty(); $smarty->assign('FORM_HEADER', $this->translate('Advanced Income Calculator')); $smarty->assign('FORM_CONTENT', $form->render()); $formContent = $smarty->fetch('Wizard/popup-form.tpl'); $options = array( 'scripts' => $this->_doc->renderScripts(), 'initFunctions' => $this->_doc->renderInitFunctions(), 'form' => $formContent ); $this->_displayJson($options); } protected function _doRenderDependent() { exit; } /** * post param: int $lastIndex */ protected function _doRenderDependentAjax() { $lastIndex = Qs_Request::getPostValue('lastIndex'); $count = Qs_Request::getPostValue('count'); $applicantIndex = Qs_Request::getPostValue('applicantIndex'); $dependentElementName = Qs_Request::getPostValue('elName'); if (null === $lastIndex || null === $applicantIndex || null === $count || null === $dependentElementName) { $this->_displayJson(['isError' => 'true', 'message' => 'Wrong request']); exit; } $this->_doc ->clearInlineScripts() ->clearInitFunctions() ->clearScripts() ->clearStylesheets(); $formIndex = (int) $lastIndex + 1; $form = $this->_getNewForm([ 'step' => 4, 'applicantIndex' => $applicantIndex, 'renderMode' => App_Wizard_Form_New::RENDER_MODE_DEPENDENT, 'dependentElementName' => $dependentElementName, 'dependentElementLabel' => ($dependentElementName != 'filersDependent') ? ucfirst($dependentElementName) : 'Dependent', 'dependentIndex' => $formIndex, 'dependentCount' => $count ]); $form->removeElement('__idItem'); $form->removeElement('action'); $response = [ 'formHtml' => $form->render(), 'formIndex' => $formIndex, 'elementName' => $dependentElementName, 'evalData' => $this->_doc->getResources() ]; $this->_displayJson($response); exit; } protected function _doPrintPdf() { if (!$this->_getCacheName()) { Qs_Http::redirect($this->url()); } $this->_generatePDF(true); return $this; } protected function _doGetPdf() { if (!$this->_getCacheName()) { Qs_Http::redirect($this->url()); } $this->_generatePDF(); return $this; } protected function _preparePrintableResultContent($hasTitle = true, $hasIntro = true) { $data = $this->_processingWizardResult(); if ($hasIntro) { $this->_doc->getSmarty()->assign('pageIntro', App_Settings_Obj::get('introResultText')); } if ($hasTitle) { $pageHeader = $this->getConfig('stepTitle')->toArray()[$this->getConfig('wizardLastStep') + 2]; $this->_doc->getSmarty()->assign('pageHeader', $this->translate($pageHeader)); } $this->_doc->getSmarty()->assign('resultPageContent', App_Settings_Obj::get('resultPageContent')); $this->_doc->getSmarty()->assign('result', $data); $this->_doc->getSmarty()->assign('total', $this->_calculateTotalTaxCreditAmount($data)); $html = $this->_doc->fetchTemplate($this->getTemplate('pdf.tpl')); return $html; } /** * Generate wizard Result PDF * @param bool $print * @return $this * @throws Exception */ protected function _generatePDF($print = false) { /** @var Qs_Pdf_Renderer_TcPdf $pdf */ $pdf = Qs_Pdf::factory(null, ['orientation' => 'P']); $pdf->setHtml($this->_preparePrintableResultContent(null, true)); $estimate = $this->translate('Eligibility estimate') . ' ' . $this->translate(date('F')) . ' ' . date(' d, Y') . '.pdf'; if ($print) { // force print dialog $js = 'print(true);'; $pdf->IncludeJS($js); $pdf->inline($estimate); } else { $pdf->download($estimate); } return $this; } protected function _getEmailToForm() { $form = $this->_getFormInstance('emailTo', array('defaults' => array())); $form->setAttrib('id', 'email-to-form'); $form->setDefaults(); return $form; } protected function _doEmailPopup() { $this->_doc->display404(); } protected function _doEmailPopupAjax() { $this->_doc->clearInitFunctions(); $this->_doc->clearScripts(); $this->_doc->clearStylesheets(); $form = $this->_getEmailToForm(); $smarty = $this->_doc->getSmarty(); $smarty->assign('FORM_HEADER', $this->translate('Send healthcare eligibility estimate')); $smarty->assign('FORM_CONTENT', $form->render()); $formContent = $smarty->fetch('Wizard/popup-form.tpl'); $options = array( 'scripts' => $this->_doc->renderScripts(), 'initFunctions' => $this->_doc->renderInitFunctions(), 'form' => $formContent ); $this->_displayJson($options); } protected function _doEmailSend() { $this->_doc->display404(); } protected function _doEmailSendAjax() { $form = $this->_getEmailToForm(); $result = $form->validateAjax(); if ($result['isValid'] == true) { $this->_doSend($form->getValues()); } $this->_displayJson($result); return $this; } protected function _doSend($data) { $subject = $this->translate('Healthcare eligibility estimate'); $body = $this->_preparePrintableResultContent(null, true); $mail = new Qs_Mail(); $mail->setFrom(App_Settings_Obj::get('siteFrom')); $mail->setSubject($subject); Qs_Mail::cutImageBaseUrl($body, BASE_URL); $mail->setHtml($body, null, WWW_PATH); $mail->addTo($data['email']); $mail->send(); return $this; } public static function renderAbbr($abbr) { $list = Qs_Application::getConfig('Wizard')->toArray()['abbreviationTitle']; $abbrTitle = (isset($list[$abbr])) ? htmlspecialchars($list[$abbr]) : $abbr; return ($abbr) ? '' . $abbr . '' : null; } }