Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(function(){
- var deposits = new Backbone.Collection;
- var depositsFind = new Backbone.Collection;
- deposits.add(arrPrograms);
- var objFilter = Backbone.Model.extend({
- defaults: function() {
- return {
- 'sum': 0,
- 'currency': '',
- 'period': 0,
- 'period_day': 0,
- 'periodInterest': 0,
- 'sumExt': 0,
- 'isAddSum': false,
- 'isPartialDelivery': false,
- 'isMulti': false,
- 'isRetirees': false,
- 'isLifeInsurance': false
- };
- },
- validate: function(attrs) {
- var regExpNum = /^[0-9]+$/;
- var arrError = [];
- if (!this.has('sum') || !attrs.sum.length)
- arrError.push({ field: '#f_sum', error: 'Необходимо указать сумму вклада'});
- else if (this.has('sum') && attrs.sum.length > 0 && !regExpNum.test(attrs.sum))
- arrError.push({ field: '#f_sum', error: 'В сумме вклада можно указывать только цифры'});
- if (!(attrs.currency == 'rub' || attrs.currency == 'usd'))
- arrError.push({ field: '#f_currency', error: 'Необходимо указать валюту вклада'});
- if (!this.has('period') || !regExpNum.test(attrs.period))
- arrError.push({ field: '#f_period', error: 'Необходимо указать срок вклада'});
- if (this.has('period') && attrs.period == 99 && (!this.has('period_day') || !regExpNum.test(attrs.period_day)))
- arrError.push({ field: '#f_period_day', error: 'Необходимо указать срок вклада в днях'});
- if (!this.has('periodInterest') || attrs.periodInterest == 0 || !regExpNum.test(attrs.periodInterest))
- arrError.push({ field: '#f_period_interest', error: 'Необходимо указать выплату процентов'});
- if (attrs.isAddSum == true && this.has('sumExt') && attrs.sumExt.length > 0 && !regExpNum.test(attrs.sumExt))
- arrError.push({ field: '#f_sum_ext', error: 'В сумме дополнительных взносов можно указывать только цифры'});
- if (arrError.length > 0) return arrError;
- },
- clear: function() {
- this.set(this.defaults(), {silent: true});
- }
- });
- var TableView = Backbone.View.extend({
- el: $('#table tbody'),
- initialize: function() {
- this.$el.empty();
- },
- calc: function(dep){
- var objResult = {};
- var strCurr = App.model.get('currency');
- objResult.currency = strCurr;
- var intMonth = 0;
- var intCountMonth = parseInt(App.model.get('period'));
- var intOstatokDay = 0;
- if (intCountMonth == 999) {
- intCountMonth = parseInt(App.model.get('period_day'));
- }//\\ if
- _.each(dep.get('month'), function(numM, key){
- if (intCountMonth >= numM) intMonth = key;
- });
- var intRange = 0;
- _.each(dep.get('programm')[strCurr].range, function(numSum, key){
- if (parseInt(App.model.get('sum')) >= numSum) intRange = key;
- });
- objResult.precent = dep.get('programm')[strCurr].percent[intRange][intMonth];
- var intSlider = 0;
- var intBeginSumM1 = intBeginSumM2 = 0;
- if (dep.get('xid') == 'biznes_klass'){
- _.each(dep.get('programm')[strCurr].slider, function(numSum, key){
- if (parseInt(App.model.get('sum')) >= numSum) {
- intSlider = key;
- intBeginSumM1 = objResult.minSum = numSum;
- intBeginSumM2 = parseInt(App.model.get('sum')) - intBeginSumM1;
- }
- });
- objResult.precentExt = dep.get('programm')[strCurr].percent_ext[intSlider][intMonth];
- }//\\ if
- var intBeginSum = parseFloat(App.model.get('sum'));
- var intAddMoney = parseFloat(App.model.get('sumExt'));
- var intCountDayInMount = 1;
- objResult.income = 0;
- var intAddProcentFinal = 0;
- for (var intMonth = 1; intMonth <= intCountMonth; intMonth++) {
- arrT = {};
- arrT.begin_summ = intBeginSum;
- arrT.add_money = 0;
- arrT.add_procent = 0;
- if ((intMonth / 30) > 1 && (intMonth % 30 == 0) && intAddMoney > 0) {
- arrT.add_money = intAddMoney;
- }
- if (dep.get('xid') != 'biznes_klass'){
- arrT.add_procent = (intBeginSum / 100) * (objResult.precent / 365);
- } else {
- arrT.add_procent = (intBeginSumM1 / 100) * (objResult.precent / 365);
- arrT.add_procent += ((intBeginSumM2 + arrT.add_money) / 100) * (objResult.precentExt / 365);
- }//\\ if
- if (strCurr != 'rub' && objResult.precent > 9){
- // Получим процент при 9%
- var intTT = ((arrT.begin_summ + arrT.add_money) / 100) * (9 / 365);
- intTT = arrT.add_procent - intTT;
- if (intTT > 0) arrT.add_procent = arrT.add_procent - (intTT / 100 * 35);
- }//\\ if
- objResult.income += arrT.add_procent;
- if (dep.get('capitalization') == true) {
- intAddProcentFinal = intAddProcentFinal + arrT.add_money + arrT.add_procent;
- if (intMonth % (dep.get('capitalization_count_month')*30) == 0 || intMonth == intCountMonth) {
- intBeginSum = intBeginSum + intAddProcentFinal;
- intAddProcentFinal = 0;
- }//\\ if
- } else intBeginSum = intBeginSum + arrT.add_money;
- if (intMonth == intCountMonth && dep.get('capitalization') == false) intBeginSum += objResult.income;
- }//\\ for
- objResult.income = objResult.income.toFixed(2);
- return objResult;
- },
- render: function() {
- var html_table = '';
- var that = this;
- depositsFind.forEach(function(dep){
- var resultCalc = that.calc(dep);
- var strPaymentPercent = 'N/A';
- if (dep.get('payment_percent_end_of_month')) strPaymentPercent = 'В конце месяца';
- if (dep.get('payment_percent_end_of_deposit')) strPaymentPercent = 'В конце срока';
- if (!dep.get('payment_percent_end_of_month') && !dep.get('payment_percent_end_of_deposit') && dep.get('capitalization')) {
- if (dep.get('capitalization_count_month') == 1)
- strPaymentPercent = 'Капитализация каждые '+dep.get('capitalization_count_month')+' месяц';
- else if (dep.get('capitalization_count_month') > 1 && dep.get('capitalization_count_month') < 5)
- strPaymentPercent = 'Капитализация каждые '+dep.get('capitalization_count_month')+' месяца';
- else if (dep.get('capitalization_count_month') >= 5)
- strPaymentPercent = 'Капитализация каждые '+dep.get('capitalization_count_month')+' месяцев';
- }//\\ if
- var strCurr = strTitle = strPrecent = '';
- if (resultCalc.currency == 'rub') strCurr = 'руб.';
- else if (resultCalc.currency == 'usd') strCurr = 'USD';
- if (dep.get('xid') == 'biznes_klass') {
- strTitle = '<a href="'+dep.get('link')+'">"'+dep.get('title')+'"</a> Минимальная сумма вклада '+accounting.formatNumber(resultCalc.minSum, 0, ' ')+' '+strCurr+'<br />Более подробный расчет можно произвести в <a href="http://sobinbank.ru/ru/quotient_client/contributions/calculator/">калькуляторе</a>.';
- strPrecent = resultCalc.precent+'% на мин. сумму вклада; '+resultCalc.precentExt+'% на сумму сверх мин. суммы вклада';
- } else {
- strTitle = '<a href="'+dep.get('link')+'">"'+dep.get('title')+'"</a>';
- strPrecent = resultCalc.precent+'%';
- }
- html_table += '<tr>';
- html_table += '<td>'+strTitle+'</td>';
- html_table += '<td>'+strPrecent+'</td>';
- html_table += '<td>'+accounting.formatNumber(resultCalc.income, 2, ' ')+' '+strCurr+'</td>';
- html_table += '<td>'+strPaymentPercent+'</td>';
- html_table += '</tr>';
- });
- if (html_table.length == 0) html_table += '<tr><td colspan="4">Не найдено</td></tr>';
- this.$el.html(html_table);
- return this;
- }
- });
- var AppView = Backbone.View.extend({
- model: new objFilter,
- el: $('.csFilterDeposit'),
- events: {
- 'click .csSearchDeposit': 'onSearch',
- 'click .csClearForm': 'onClear',
- 'change #f_opt_add_sum': 'onAddSum',
- 'change #f_period': 'onShowPeriodDay'
- },
- resultTable: new TableView(),
- initialize: function() {
- this.model.on('error', function(m, error){
- $.each(error, function(index, er){
- App.showError(er.field, er.error);
- })
- });
- this.clearError();
- this.onShowPeriodDay();
- this.onAddSum();
- },
- render: function() {
- this.resultTable.render();
- return this;
- },
- onSearch: function() {
- this.clearError();
- this.model.clear();
- this.model.set({
- 'sum': this.$('#f_sum').val(),
- 'currency': this.$('#f_currency').val(),
- 'period': parseInt(this.$('#f_period').val()),
- 'period_day': parseInt(this.$('#f_period_day').val()),
- 'periodInterest': parseInt(this.$('#f_period_interest').val()),
- 'sumExt': this.$('#f_sum_ext').val(),
- 'isAddSum': this.$('#f_opt_add_sum').is(':checked'),
- 'isPartialDelivery': this.$('#f_opt_partial_delivery').is(':checked'),
- 'isMulti': this.$('#f_opt_multicurrency').is(':checked'),
- 'isRetirees': this.$('#f_opt_for_retirees').is(':checked'),
- 'isLifeInsurance': this.$('#f_opt_for_life_insurance').is(':checked')
- });
- if (this.model.isValid()) {
- depositsFind.reset();
- deposits.forEach(function(dep){
- var isFind = false;
- var indexCur = _.indexOf(dep.get('currency'), App.model.get('currency'));
- var intMinSum = 0;
- if (dep.get('min_sum') != null)
- intMinSum = dep.get('min_sum')[indexCur];
- var intCountMonth = parseInt(App.model.get('period'));
- if (intCountMonth == 999) {
- intCountMonth = App.model.get('period_day');
- }//\\ if
- if (parseInt(App.model.get('sum')) >= intMinSum) {
- if (
- (dep.get('case_only_month') == true && (_.indexOf(dep.get('month'), intCountMonth) != -1 || (intCountMonth == 272 && _.indexOf(dep.get('month'), 271) != -1) || (intCountMonth == 183 && _.indexOf(dep.get('month'), 182) != -1))) ||
- (dep.get('case_only_month') == false && dep.get('prolongation') == true && intCountMonth >= _.min(dep.get('month'))) ||
- (dep.get('case_only_month') == false && dep.get('prolongation') == false && intCountMonth >= _.min(dep.get('month')) && intCountMonth <= _.max(dep.get('month')))
- ) {
- if (
- (App.model.get('periodInterest') == 1 && dep.get('payment_percent_end_of_month') == true) ||
- (App.model.get('periodInterest') == 2 && dep.get('payment_percent_end_of_deposit') == true) ||
- (App.model.get('periodInterest') == 3 && dep.get('capitalization') == true) ||
- (App.model.get('periodInterest') == 4)
- ) {
- if ((App.model.get('sumExt') == '' || parseInt(App.model.get('sumExt')) == 0) || (
- parseInt(App.model.get('sumExt')) >= dep.get('min_add_cont')[indexCur]
- )) {
- isFind = true;
- if (App.model.get('isAddSum') == true && !(dep.get('min_add_cont')[indexCur] > 0)) isFind = false;
- if (App.model.get('isPartialDelivery') == true && dep.get('partial_delivery') == false) isFind = false;
- if (App.model.get('isMulti') == true && dep.get('xid') != 'multi') isFind = false;
- if (App.model.get('isRetirees') == true && (dep.get('xid') != 'pensionary' && dep.get('xid') != 'all2')) isFind = false;
- if (App.model.get('isLifeInsurance') == true && (dep.get('xid') != 'so_strahovkoi1' && dep.get('xid') != 'so_strahovkoi2' && dep.get('xid') != 'so_strahovkoi3')) isFind = false;
- }//\\ if
- }//\\ if
- }//\\ if
- }//\\ if
- if (isFind) depositsFind.add(dep);
- });
- } else {
- depositsFind.reset();
- this.model.clear();
- }
- this.render();
- },
- onClear: function() {
- this.model.clear();
- depositsFind.reset();
- this.clearError();
- this.$('#f_sum, #f_currency, #f_period, #f_period_interest, #f_sum_ext').val('');
- this.$('#f_opt_add_sum, #f_opt_partial_delivery, #f_opt_multicurrency, #f_opt_for_retirees').removeAttr('checked');
- this.onAddSum();
- this.onShowPeriodDay();
- this.render();
- },
- onAddSum: function() {
- if (this.$('#f_opt_add_sum').is(':checked')) this.$('#tr_add_sum').show();
- else {
- this.$('#f_sum_ext').val('');
- this.$('#tr_add_sum').hide();
- }//\\ if
- },
- onShowPeriodDay: function() {
- if (this.$('#f_period').val() == 999) this.$('#tr_period_day').show();
- else {
- this.$('#f_period_day').val('');
- this.$('#tr_period_day').hide();
- }//\\ if
- },
- showError: function(strEl, strTextError) {
- this.$(strEl).next().show().html(strTextError);
- },
- clearError: function() {
- $('.error_form').empty().hide();
- }
- });
- var App = new AppView();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement