'use strict';angular.module('twoBookApp.uva',['ui.router','ui.bootstrap']).component('tboUva',{templateUrl:'vat/vat.template.html',controller:['SessionService','$http','$rootScope','RequestsErrorHandler','$timeout','$scope','$state',function UvaController(SessionService,$http,$rootScope,RequestsErrorHandler,$timeout,$scope,$state){var self=this;var _vatPeriods;var _vatType;var _total;var _editVatPayed;var _formDataVatPayed;var _vatEditOptions;var _focusPeriod;var _showErrorMessage=false;var _year;var _lea;var _dataLoaded=false;this._vatEditOptions={culture:"de-DE",format:"{0:n2}",decimals:2,round:false,restrictDecimals:true,spinners:false,} this.header={Period:"",KZ000:"Umsatz (Einnahmen)",KZ011:decodeHtml("abzügl. Exporte"),KZ017:decodeHtml("abzügl. iG-Lieferungen"),KZ020:decodeHtml("abzügl. unecht steuerfrei"),TaxableRevenue:"Steuerpfl. Umsatz",KZ022:"davon mit 20 %",KZ006:"davon mit 13 %",KZ029:"davon mit 10 %",VatSum:"Umsatzsteuer daher",KZ057:"Steuerschuld aus RC",KZ070:"BMG iG-Erwerbe",KZ072:"davon mit 20 %",KZ008:"davon mit 13 %",KZ073:"davon mit 10 %",KZ060:"Vorsteuer Inland",KZ065:"Vorsteuer aus iG-Erwerb",KZ066:"Vorsteuer aus RC",Vst:"Summe Vorsteuer",Vat:"USt Zahllast daher",DueDate:"fällig",VatPayed:"USt bezahlt"} this.kz={Period:"",KZ000:"KZ000",KZ011:"KZ011",KZ017:"KZ017",KZ020:"KZ020",TaxableRevenue:"",KZ022:"KZ022",KZ006:"KZ006",KZ029:"KZ029",VatSum:"",KZ057:"KZ057",KZ070:"KZ070",KZ072:"KZ072",KZ008:"KZ008",KZ073:"KZ073",KZ060:"KZ060",KZ065:"KZ065",KZ066:"KZ066",Vst:"",Vat:"",DueDate:"",VatPayed:""} this.loadVatPeriods=function(){SessionService.progressSymbol(true);RequestsErrorHandler.specificallyHandled(function(){SessionService.getCurrentBookKeeping().then(function(response){self._year=response.Year;self._lea=response.Lea;RequestsErrorHandler.specificallyHandled(function(){$http({method:'GET',url:SessionService.getApiUrl()+'/api/vatperiods',headers:{'Content-Type':'text/xml','lea':response.Lea,'year':response.Year}}).then(function(response){if(response.data&&!(response.data instanceof Array)){response.data=[response.data]} self.prepareVat(response.data);SessionService.progressSymbol(false);self._dataLoaded=true;self.checkVatPayed()},function(response){SessionService.progressSymbol(false);if(typeof(response.data)=="string"){self._errorMessage=response.status+" "+response.statusText+": "+response.data;}else if(typeof(response.data)=="object"&&response.data!=null&&response.data.hasOwnProperty('Message')){self._errorMessage=response.status+" "+response.statusText+": "+response.data.Message;}else{self._errorMessage=response.status+" "+response.statusText;} self.alert();});})},function(response){SessionService.progressSymbol(false);if(typeof(response.data)=="string"){self._errorMessage=response.status+" "+response.statusText+": "+response.data;}else if(typeof(response.data)=="object"&&response.data!=null&&response.data.hasOwnProperty('Message')){self._errorMessage=response.status+" "+response.statusText+": "+response.data.Message;}else{self._errorMessage=response.status+" "+response.statusText;} self.alert();})})};this.prepareVat=function(vatPeriods){if(vatPeriods===null){} if(vatPeriods[0].Uva=='m'){self._vatType='m';}else{self._vatType='q';} this._total={Period:"",PeriodName:"Total",KZ000:0.00,KZ011:0.00,KZ017:0.00,KZ020:0.00,TaxableRevenue:0.00,KZ022:0.00,KZ006:0.00,KZ029:0.00,VatSum:0.00,KZ057:0.00,KZ070:0.00,KZ072:0.00,KZ008:0.00,KZ073:0.00,KZ060:0.00,KZ065:0.00,KZ066:0.00,Vst:0.00,Vat:0.00,VatPayed:0.00} Object.keys(vatPeriods).forEach(function(key){var cur=vatPeriods[key] self._total.KZ000+=cur.KZ000;self._total.KZ011+=cur.KZ011;self._total.KZ017+=cur.KZ017;self._total.KZ020+=cur.KZ020;self._total.TaxableRevenue+=cur.TaxableRevenue;self._total.KZ022+=cur.KZ022;self._total.KZ006+=cur.KZ006;self._total.KZ029+=cur.KZ029;self._total.VatSum+=cur.VatSum;self._total.KZ057+=cur.KZ057;self._total.KZ070+=cur.KZ070;self._total.KZ072+=cur.KZ072;self._total.KZ008+=cur.KZ008;self._total.KZ073+=cur.KZ073;self._total.KZ060+=cur.KZ060;self._total.KZ065+=cur.KZ065;self._total.KZ066+=cur.KZ066;self._total.Vst+=cur.Vst;self._total.Vat+=cur.Vat;self._total.VatPayed+=cur.VatPayed;self._formDataVatPayed.push({Uva:cur.Uva,Period:cur.Period,VatPayed:cur.VatPayed,RowVersion:cur.RowVersion});delete vatPeriods[key].Uva;}) self._vatPeriods=vatPeriods;};this.alert=function(){self._showErrorMessage=true;tboAlert(self._errorMessage);};this.warning=function(msg){self._showErrorMessage=true;tboWarning(msg);};this.checkVatPayed=function(){var warning=false;var dueVat=0;var dueVatPayed=0;Object.keys(self._vatPeriods).forEach(function(key){if(new Date(self._vatPeriods[key].DueDate).getTime()<=new Date().getTime()&&self._vatPeriods[key].Vat>0&&self._vatPeriods[key].VatPayed==0){warning=true;}}) if(warning){self.warning("Für bereits fällige Perioden wurden keine Zahlungen erfasst.");} warning=false;Object.keys(self._vatPeriods).forEach(function(key){if(new Date(self._vatPeriods[key].DueDate).getTime()<=new Date().getTime()){dueVat+=self._vatPeriods[key].Vat;dueVatPayed+=self._vatPeriods[key].VatPayed;}}) if(dueVatPayed0){$timeout(function(){var inputs=$(element).find('input');if(inputs[0]!==undefined){inputs[Math.min(value-1,inputs.length-1)].focus();} scope.trigger=0;});}});}};}]);