Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 62 additions & 38 deletions app/assets/javascripts/angular/controllers/reports.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,76 @@
$scope.rateDollar = $cookies.rateDollar || 0

$scope.load = (value) ->
$scope.data = {}
$scope.data.revenues = {}
$scope.data.costs = {}
$scope.data.translations = {}
$scope.data.loans = {}
$scope.months = $translate.instant('month_all').split(',')
curr_date = new Date()
$scope.funcPlan.show[curr_date.getMonth()] = false
$scope.CheckedYear = value
$scope.clickedMonths = [(curr_date.getMonth()+1) + '/' + $scope.CheckedYear]
$scope.currentMonth = $scope.months[curr_date.getMonth()]
$scope.loadDates()
$scope.loadDates($scope.clickedMonths, true)

$scope.loadDates = ->
mergeObjects = (result, object) ->
angular.forEach object, (value, key) ->
result = $.extend(true, [], result, value)
result

unmergeObjects = (month, object) ->
angular.forEach object, (value, key) ->
delete value[month]
$scope[key] = {}
$scope[key] = mergeObjects($scope[key], value)

$scope.loadDates = (month, clicked) ->
$cookies.rateDollar = String($scope.rateDollar).replace(',','.')
m = parseInt(String(month).split('/')[0])

Report.query
report_type: 'revenues'
, 'months[]': $scope.clickedMonths
, rate_currency: $scope.rateDollar
, (response) ->
$scope.revenues = response[0].articles
$scope.totalRevenue = response[0].total_values
$scope.totalRevenuePlan = response[0].total_values_plan

Report.query
report_type: 'costs'
, 'months[]': $scope.clickedMonths
, rate_currency: $scope.rateDollar
, (response) ->
$scope.costs = response[0].articles
$scope.totalCost = response[0].total_values
$scope.totalCostPlan = response[0].total_values_plan

Report.query
report_type: 'translations'
, 'months[]': $scope.clickedMonths
, rate_currency: $scope.rateDollar
, (response) ->
$scope.translations = response[0].articles
$scope.totalTranslation = response[0].total_values
$scope.totalTranslationPlan = response[0].total_values_plan

Report.query
report_type: 'loans'
, 'months[]': $scope.clickedMonths
, rate_currency: $scope.rateDollar
, (response) ->
$scope.loans = response[0].articles
$scope.totalLoan = response[0].total_values
$scope.totalLoanPlan = response[0].total_values_plan
if clicked
Report.query
report_type: 'revenues'
, 'months[]': month
, rate_currency: $scope.rateDollar
, (response) ->
$scope.data.revenues[m] = response[0].articles
$scope.revenues = mergeObjects($scope.revenues, $scope.data.revenues)
$scope.totalRevenue = $.extend(true, [], $scope.totalRevenue, response[0].total_values)
$scope.totalRevenuePlan = $.extend(true, [], $scope.totalRevenuePlan, response[0].total_values_plan)

Report.query
report_type: 'costs'
, 'months[]': month
, rate_currency: $scope.rateDollar
, (response) ->
$scope.data.costs[m] = response[0].articles
$scope.costs = mergeObjects($scope.costs, $scope.data.costs)
$scope.totalCost = $.extend(true, [], $scope.totalCost, response[0].total_values)
$scope.totalCostPlan = $.extend(true, [], $scope.totalCostPlan, response[0].total_values_plan)

Report.query
report_type: 'translations'
, 'months[]': month
, rate_currency: $scope.rateDollar
, (response) ->
$scope.data.translations[m] = response[0].articles
$scope.translations = mergeObjects($scope.translations, $scope.data.translations)
$scope.totalTranslation = $.extend(true, [], $scope.totalTranslation, response[0].total_values)
$scope.totalTranslationPlan = $.extend(true, [], $scope.totalTranslationPlan, response[0].total_values_plan)

Report.query
report_type: 'loans'
, 'months[]': month
, rate_currency: $scope.rateDollar
, (response) ->
$scope.data.loans[m] = response[0].articles
$scope.loans = mergeObjects($scope.loans, $scope.data.loans)
$scope.totalLoan = $.extend(true, [], $scope.totalLoan, response[0].total_values)
$scope.totalLoanPlan = $.extend(true, [], $scope.totalLoanPlan, response[0].total_values_plan)
else
unmergeObjects(m, $scope.data)

$scope.monthsChange = (month, clicked) ->
m = $scope.months.indexOf(month)+1
Expand All @@ -64,7 +88,7 @@
trashMonth = $scope.clickedMonths.indexOf(date)
$scope.clickedMonths.splice(trashMonth, 1)
delete $scope.funcPlan.show[m-1]
$scope.loadDates()
$scope.loadDates(date, clicked)

$scope.range = (start, end) ->
return [start..end]
Expand Down
48 changes: 16 additions & 32 deletions app/assets/templates/angular/reports/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,14 @@
span ng-show="!showCount" ▼
span ng-show="showCount" ▲
.value ng-class="{plan_show: funcPlan.show[$index]}" ng-repeat="month in range(1,12)" ng-show="isShow(month)"
span.pointer.plan ng-click="getRegisters(month, $event, 'revenues', revenue.article_id, true)" ng-show="funcPlan.show[$index]"
| {{revenue.valuesPlan[month]}}
span.pointer.fact ng-class="{add_background: funcPlan.show[$index]}" ng-click="getRegisters(month, $event, 'revenues', revenue.article_id, null)"
| {{revenue.values[month]}}
span.pointer.plan ng-click="getRegisters(month, $event, 'revenues', revenue.article_id, true)" ng-show="funcPlan.show[$index]" ng-bind="revenue.valuesPlan[month] || 0"
span.pointer.fact ng-class="{add_background: funcPlan.show[$index]}" ng-click="getRegisters(month, $event, 'revenues', revenue.article_id, null)" ng-bind="revenue.values[month] || 0"
.values class="{{revenue.article_type}}" ng-repeat="c in revenue.counterparties" ng-show="showCount && funcPlan.showRecord(c)"
.left.counterparty
| {{c.counterparty}}
.value ng-class="{plan_show: funcPlan.show[$index]}" ng-repeat="month in range(1,12)" ng-show="isShow(month)"
span.plan ng-show="funcPlan.show[$index]"
| {{c.valuesPlan[month]}}
span.fact ng-class="{add_background: funcPlan.show[$index]}"
| {{c.values[month]}}
span.plan ng-show="funcPlan.show[$index]" ng-bind="c.valuesPlan[month] || 0"
span.fact ng-class="{add_background: funcPlan.show[$index]}" ng-bind="c.values[month] || 0"
ng-include src='"#{asset_path('angular/shared/clearbord_reports.html')}"'
.values.bold.report-item
.left
Expand All @@ -79,18 +75,14 @@
span ng-show="!showCount" ▼
span ng-show="showCount" ▲
.value ng-class="{plan_show: funcPlan.show[$index]}" ng-repeat="month in range(1,12)" ng-show="isShow(month)"
span.pointer.plan ng-click="getRegisters(month, $event, 'costs', cost.article_id, true)" ng-show="funcPlan.show[$index]"
| {{cost.valuesPlan[month]}}
span.pointer.fact ng-class="{add_background: funcPlan.show[$index]}" ng-click="getRegisters(month, $event, 'costs', cost.article_id, null)"
| {{cost.values[month]}}
span.pointer.plan ng-click="getRegisters(month, $event, 'costs', cost.article_id, true)" ng-show="funcPlan.show[$index]" ng-bind="cost.valuesPlan[month] || 0"
span.pointer.fact ng-class="{add_background: funcPlan.show[$index]}" ng-click="getRegisters(month, $event, 'costs', cost.article_id, null)" ng-bind="cost.values[month] || 0"
.values class="{{cost.article_type}}" ng-repeat="c in cost.counterparties" ng-show="showCount && funcPlan.showRecord(c)"
.left.counterparty
| {{c.counterparty}}
.value ng-class="{plan_show: funcPlan.show[$index]}" ng-repeat="month in range(1,12)" ng-show="isShow(month)"
span.plan ng-show="funcPlan.show[$index]"
| {{c.valuesPlan[month]}}
span.fact ng-class="{add_background: funcPlan.show[$index]}"
| {{c.values[month]}}
span.plan ng-show="funcPlan.show[$index]" ng-bind="c.valuesPlan[month] || 0"
span.fact ng-class="{add_background: funcPlan.show[$index]}" ng-bind="c.values[month] || 0"
ng-include src='"#{asset_path('angular/shared/clearbord_reports.html')}"'
.values.bold
.left
Expand All @@ -117,18 +109,14 @@
span ng-show="!showCount" ▼
span ng-show="showCount" ▲
.value ng-class="{plan_show: funcPlan.show[$index]}" ng-repeat="month in range(1,12)" ng-show="isShow(month)"
span.pointer.plan ng-click="getRegisters(month, $event, 'translations', translation.article_id, true)" ng-show="funcPlan.show[$index]"
| {{translation.valuesPlan[month]}}
span.pointer.fact ng-class="{add_background: funcPlan.show[$index]}" ng-click="getRegisters(month, $event, 'translations', translation.article_id, null)"
| {{translation.values[month]}}
span.pointer.plan ng-click="getRegisters(month, $event, 'translations', translation.article_id, true)" ng-show="funcPlan.show[$index]" ng-bind="translation.valuesPlan[month] || 0"
span.pointer.fact ng-class="{add_background: funcPlan.show[$index]}" ng-click="getRegisters(month, $event, 'translations', translation.article_id, null)" ng-bind="translation.values[month] || 0"
.values class="{{translation.article_type}}" ng-repeat="c in translation.counterparties" ng-show="showCount && funcPlan.showRecord(c)"
.left.counterparty
| {{c.counterparty}}
.value ng-class="{plan_show: funcPlan.show[$index]}" ng-repeat="month in range(1,12)" ng-show="isShow(month)"
span.plan ng-show="funcPlan.show[$index]"
| {{c.valuesPlan[month]}}
span.fact ng-class="{add_background: funcPlan.show[$index]}"
| {{c.values[month]}}
span.plan ng-show="funcPlan.show[$index]" ng-bind="c.valuesPlan[month] || 0"
span.fact ng-class="{add_background: funcPlan.show[$index]}" ng-bind="c.values[month] || 0"
ng-include src='"#{asset_path('angular/shared/clearbord_reports.html')}"'
.values.bold.report-item
.left
Expand All @@ -146,15 +134,11 @@
span ng-show="!showCount" ▼
span ng-show="showCount" ▲
.value ng-class="{plan_show: funcPlan.show[$index]}" ng-repeat="month in range(1,12)" ng-show="isShow(month)"
span.pointer.plan ng-click="getRegisters(month, $event, 'loans', loan.article_id, true)" ng-show="funcPlan.show[$index]"
| {{loan.valuesPlan[month]}}
span.pointer.fact ng-class="{add_background: funcPlan.show[$index]}" ng-click="getRegisters(month, $event, 'loans', loan.article_id, null)"
| {{loan.values[month]}}
span.pointer.plan ng-click="getRegisters(month, $event, 'loans', loan.article_id, true)" ng-show="funcPlan.show[$index]" ng-bind="loan.valuesPlan[month] || 0"
span.pointer.fact ng-class="{add_background: funcPlan.show[$index]}" ng-click="getRegisters(month, $event, 'loans', loan.article_id, null)" ng-bind="loan.values[month] || 0"
.values class="{{loan.article_type}}" ng-repeat="c in loan.counterparties" ng-show="showCount && funcPlan.showRecord(c)"
.left.counterparty
| {{c.counterparty}}
.value ng-class="{plan_show: funcPlan.show[$index]}" ng-repeat="month in range(1,12)" ng-show="isShow(month)"
span.plan ng-show="funcPlan.show[$index]"
| {{c.valuesPlan[month]}}
span.fact ng-class="{add_background: funcPlan.show[$index]}"
| {{c.values[month]}}
span.plan ng-show="funcPlan.show[$index]" ng-bind="c.valuesPlan[month] || 0"
span.fact ng-class="{add_background: funcPlan.show[$index]}" ng-bind="c.values[month] || 0"