'use strict';angular.module('twoBookApp.chart-performance-cum',['ui.router']).component('chartPerformanceCum',{templateUrl:'chart-performance-cum/chart-performance-cum.template.html',bindings:{tboHeight:'=',tboDashboard:'='},controller:['$http','$timeout','RequestsErrorHandler','SessionService','$filter','$scope','$rootScope','$injector','ErrorDialogEmbedded',function($http,$timeout,RequestsErrorHandler,SessionService,$filter,$scope,$rootScope,$injector,ErrorDialogEmbedded){var self=this;var _chartOtions;var _performance;var _chartHeight;var _updateChart;var _lea;this._chartHeight=this.tboHeight;this._updateChart=false;this._lea=0;this._noData=false;this.setHeight=function(height){$timeout(function(){self.tboHeight=height;});}
this._chartOptions={culture:"de-DE",transitions:true,seriesColors:["lightgray","darkgray","gray","dimgray","darkgreen"],series:[{field:'Win4',name:'',type:"line",width:1,visible:true,tooltip:{visible:true,template:"
#= dataItem.Year4 #
"+"#= kendo.format('{0:C0}',value) #
"+"#if (dataItem.WinDiff4 != null) {#"+"VJ: #= tboNumberRelation(dataItem.WinDiff4)#
"+"#}#"},markers:{size:7,},},{field:'Win3',name:'',type:"line",width:2,tooltip:{visible:true,template:"#= dataItem.Year3 #
"+"#= kendo.format('{0:C0}',value) #
"+"#if (dataItem.WinDiff3 != null) {#"+"VJ: #= tboNumberRelation(dataItem.WinDiff3)#
"+"#}#"},markers:{size:8,},},{field:'Win2',name:'',type:"line",width:4,tooltip:{visible:true,template:"#= dataItem.Year2 #
"+"#= kendo.format('{0:C0}',value) #
"+"#if (dataItem.WinDiff2 != null) {#"+"VJ: #= tboNumberRelation(dataItem.WinDiff2)#
"+"#}#"},markers:{size:10,},},{field:'Win1',name:'',type:"line",width:6,tooltip:{visible:true,template:"#= dataItem.Year1 #
"+"#= kendo.format('{0:C0}',value) #
"+"#if (dataItem.WinDiff1 != null) {#"+"VJ: #= tboNumberRelation(dataItem.WinDiff1)#
"+"#}#"},markers:{size:12,}},{field:'Win',name:'',type:"line",width:8,tooltip:{visible:true,template:"#= dataItem.Year #
"+"#= kendo.format('{0:C0}',value) #
"+"#if (dataItem.WinDiff != null) {#"+"VJ: #= tboNumberRelation(dataItem.WinDiff)#
"+"#}#"},markers:{size:14,}},],axisDefaults:{majorGridLines:{visible:false,}},valueAxes:[{title:{text:"Gewinn [Eur]"},labels:{format:"{0:n0}"},line:{visible:true},axisCrossingValue:0,}],categoryAxis:{field:'Month',line:{visible:true},labels:{template:"#= decodeHtml(monthNamesShort[value-1]) #",},},legend:{position:"bottom"}}
this._performance=new kendo.data.DataSource({transport:{read:function(e){RequestsErrorHandler.specificallyHandled(function(){SessionService.getCurrentBookKeeping().then(function(response){self._lea=response.Lea;$http({method:'GET',url:SessionService.getApiUrl()+'/api/charts',headers:{'Content-Type':'text/xml','lea':response.Lea,'year':response.Year,'type':'performanceCum'}}).then(function(response){if(response.data.length==0){self._noData=true;}else{self._noData=false;var opt=$('#tboChartPerformanceCum').data("kendoChart").options;opt.series[0].name=response.data[0].Year4;opt.series[1].name=response.data[0].Year3;opt.series[2].name=response.data[0].Year2;opt.series[3].name=response.data[0].Year1;opt.series[4].name=response.data[0].Year;for(var i=0;i<5;i++){if(i>response.data[0].Years-1){opt.series[4-i].visible=false;opt.series[4-i].visibleInLegend=false;}else{opt.series[4-i].visible=true;opt.series[4-i].visibleInLegend=true;}}
$('#tboChartPerformanceCum').data("kendoChart").redraw();}
e.success(response.data)},function(response){self._errorMessage=response.statusText;e.error("XHR response",response.error,response.statusText);});})})}},sort:[{field:"Month",dir:"asc"}]});this.onSeriesHover=function(e){if(e.series.width==10){return;}
var width=8;for(var i=this.options.series.length-1;i>=0;i--){this.options.series[i].width=width;this.options.series[i].markers.size=width+6;width=width<=2?1:width-2;}
e.series.width=10;e.series.markers.size=16;this.options.transitions=false;this.refresh();this.options.transitions=true;}
this.pdf=function(){kendo.drawing.drawDOM($(".k-content"),{}).then(function(group){var PAGE_RECT=new kendo.geometry.Rect([0,0],[mm(297-20),mm(210-20)]);var content=new kendo.drawing.Group();content.append(group);kendo.drawing.fit(content,PAGE_RECT)
return kendo.drawing.exportPDF(content,{paperSize:"A4",margin:"1cm",landscape:true,});}).done(function(data){kendo.saveAs({dataURI:data,fileName:"2book_Gewinnentwicklung.pdf",});});$('#tboFocus').focus();}
this._bkListener=$rootScope.$on('tboCurrentBookKeeping',function(event,data){DEBUG&&console.log("chart performance received book keeping change");var chart=$("#tboChartPerformanceCum").getKendoChart();if(self._lea!=data.Lea){chart.dataSource.read();}});$scope.$on('$destroy',self._bkListener);}]});