public function formDepositCompare() { $depositsIds = Tree::getDepositsCompared(); $html = ''; if ($depositsIds) { $deposits = Tree::whereIn('id', $depositsIds)->active()->get(); $depositsEntities = Deposit::whereIn('id_tb_tree', $depositsIds)->get(); $depositsCompared = Deposit::prepareData($depositsEntities); $html = View::make('partials.popups.deposits_compare_inner', compact('depositsCompared', 'deposits'))->render(); } return Response::json(array('status' => true, 'html' => $html)); }
public function doDepositCalculation() { App::setLocale(Cookie::get('locale', 'ru')); $isMain = intval(Input::get('is_main')); $depositAmount = intval(trim(Input::get('deposit_amount'))); $term = intval(trim(Input::get('term'))); $monthlyInstallment = intval(trim(Input::get('monthly_installment'))); $currency = trim(Input::get('currency')); $interestPaymentType = trim(Input::get('interest_payment_type')); $interestPaymentPercent = trim(Input::get('interest_payment_percent')); if (!$depositAmount || !$term || !$currency) { return Response::json(array('status' => false)); } $calculator = new DepositCalculator(); $calculator->setDepositAmount($depositAmount); $calculator->setTerm($term); $calculator->setMonthlyInstallment($monthlyInstallment); $calculator->setCurrency($currency); $viewTemplate = 'partials.calculators.partials.deposit_table_main'; $sliderHtml = ''; if (!$isMain) { $calculator->setInterestPaymentType($interestPaymentType); $calculator->setInterestPaymentPercent($interestPaymentPercent); $calculator->setIsMain(false); $viewTemplate = 'partials.calculators.partials.deposit_table'; } $calculations = $calculator->calculate(); if (!$isMain) { $depositsIds = Tree::getDepositsCompared(); $depositsCatalog = Cache::tags('j_tree')->rememberForever('deposits_catalog_' . App::getLocale(), function () { return Tree::find(Collector::get('idDepositsCatalog')); }); $deposits = Cache::tags('j_tree')->rememberForever('deposits_products_' . App::getLocale(), function () use($depositsCatalog) { return $depositsCatalog->children()->get(); }); $deposits = Tree::filterDepositsByIds($deposits, $depositsIds); $allDeposits = Cache::tags('deposits')->rememberForever('deposits_' . App::getLocale(), function () { return Deposit::all(); }); $depositOptionsGroups = Deposit::prepareData($allDeposits); $sliderHtml = View::make('private-persons.deposits.partials.deposits_slider', compact('deposits', 'depositOptionsGroups', 'calculations'))->render(); } $html = View::make($viewTemplate, compact('result', 'currency', 'calculations'))->render(); $firstDepositData = array(); if ($calculations) { $firstDepositData = array_values($calculations)[0]; } return Response::json(array('status' => true, 'html' => $html, 'slider_html' => $sliderHtml, 'currency' => isset($calculations['currency']) ? $calculations['currency'] : '', 'result' => isset($calculations['sum']) ? $calculations['sum'] : '', 'sum' => $firstDepositData['sum'])); }