angular.module('twoBookApp.chart-top',['ui.router','kendo.directives']).component('tboChartTop',{templateUrl:'chart-top/chart-top.template.html',bindings:{tboHeight:'=',tboCategory:'@',tboDashboard:'=',},controller:['Upload','$http','$timeout','RequestsErrorHandler','SessionService','$filter','$scope','$rootScope','$injector','$state','ErrorDialogEmbedded',function(Upload,$http,$timeout,RequestsErrorHandler,SessionService,$filter,$scope,$rootScope,$injector,$state,ErrorDialogEmbedded){var self=this;var _chartOtions;var _top;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:["#cc0000","#cc6600","#cccc00","#66cc00","#00cc33","#00cccc","#0066cc","#3300cc","#cc00cc","#cc0066"],tooltip:{visible:true,template:"
#= category #
"+"
#= kendo.format('{0:C0}',value) #
"+"#if (dataItem.Diff != null) {#"+"
VJ: #= tboNumberRelation(dataItem.Diff) #
"+"#}#"},series:[{field:'Amount',categoryField:'Title',padding:50,labels:{template:"#= category #",position:"outsideEnd",align:"column",font:"14px Arial,Helvetica,sans-serif",visible:true},border:{width:1,color:"black",opacity:0.1}}],legend:{visible:false,},title:{text:"",color:"#000000",font:"18px Arial,Helvetica,sans-serif",}} this.updateTitle=function(){var chart=$("#tboChartTopCustomers").getKendoChart();chart.setOptions({title:{text:"Total: "+tboNumberKPI(self._coverage),}});} this._top=new kendo.data.DataSource({transport:{read:function(e){RequestsErrorHandler.specificallyHandled(function(){SessionService.getCurrentBookKeeping().then(function(response){self._lea=response.Lea;self._year=response.Year;$http({method:'GET',url:SessionService.getApiUrl()+'/api/charts',headers:{'Content-Type':'text/xml','lea':response.Lea,'year':response.Year,'type':self.tboCategory}}).then(function(response){if(response.data[0].Data.length==0){self._noData=true;}else{self._noData=false;} self._coverage=response.data[0].Coverage;self.updateTitle();e.success(response.data)},function(response){self._errorMessage=response.statusText;e.error("XHR response",response.error,response.statusText);});})})}},schema:{data:function(response){return response[0].Data;},},});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_"+$state.current.data.pageTitle.split(" ").join("_")+"_"+self._year+".pdf",});}) var chart=$("#tboChartTopCustomers").getKendoChart();chart.exportPDF({}).done(function(data){kendo.saveAs({dataURI:data,fileName:"2book_Top_Kunden.pdf"});});$('#tboFocus').focus();} this._bkListener=$rootScope.$on('tboCurrentBookKeeping',function(event,data){DEBUG&&console.log("char TopCustomers received book keeping change");var chart=$("#tboChartTopCustomers").getKendoChart();chart.dataSource.read();});$scope.$on('$destroy',self._bkListener);}]});