';self.bookentriesGrid.setOptions({navigatable:false});$timeout(function(){self.bookentriesGrid.saveAsPDF({}).done(function(data){self._pdfInProgress=false;self.bookentriesGrid.setOptions({navigatable:true});$scope.$apply();}).fail(function(data){self._pdfInProgress=false;self.bookentriesGrid.setOptions({navigatable:true});});});$('#tboFocus').focus();});}
self.downloadFile=function(lea,year,attachmentId){if(self._isInEditMode)return;RequestsErrorHandler.specificallyHandled(function(){$http({method:'GET',url:SessionService.getApiUrl()+'/api/file',headers:{'lea':lea,'year':year,'id':attachmentId},responseType:'arraybuffer'}).then(function(response){var fileName=response.headers('Content-Disposition').split(';')[1].trim().split('=')[1];fileName=fileName.replace(/"/g,'');var file=new Blob([response.data],{type:'application/pdf'});var fileURL=URL.createObjectURL(file);if(navigator.appVersion.toString().indexOf('.NET')>0)
window.navigator.msSaveOrOpenBlob(file,fileName);else
window.open(fileURL);},function(response){var decodedString=String.fromCharCode.apply(null,new Uint8Array(response.data));self.errorMessage=response.statusText+': '+decodedString;self.alert();})});}
self.deleteFile=function(lea,year,entryId,attachmentId){if(self._isInEditMode)return;self._isUploaded=true;dataItem=self.gridDataSource.get(entryId);var tr=self.bookentriesGrid.tbody.find("tr[data-uid='"+dataItem.uid+"']");tr.addClass('tbo-state-selected-to-delete');ErrorDialogEmbedded.show('Willst Du den Anhang zu der rot markierten Eingabe wirklich löschen?',btnOk|btnCancel,iconUser,"AlertMessageWrapper").then(function(){tr.removeClass('tbo-state-selected-to-delete');SessionService.progressSymbol(true);RequestsErrorHandler.specificallyHandled(function(){$http({method:'DELETE',url:SessionService.getApiUrl()+'/api/file/'+attachmentId,headers:{'lea':lea,'year':year,'id':entryId}}).then(function(response){dataItem=self.gridDataSource.get(entryId);for(var key in response.data){if(response.data.hasOwnProperty(key)){dataItem.set(key,response.data[key]);}}
SessionService.progressSymbol(false);},function(response){var x=typeof(response.data)==='object'?response.data.Message:response.data;self.errorMessage=response.statusText+': '+(typeof(response.data)==='object'?response.data.Message:response.data);self.alert();SessionService.progressSymbol(false);});});},function(){tr.removeClass('tbo-state-selected-to-delete');});self.bookentriesGrid.element.find(".k-grid-content").animate({scrollTop:tr.offset().top-self.bookentriesGrid.content.offset().top+self.bookentriesGrid.content.scrollTop()-(tr.offset().top-self.bookentriesGrid.content.offset().top)/2},400);}
self.uploadFiles=function(file,errFiles,lea,year,entryId,attachmentId){self._isUploaded=true;dataItem=self.gridDataSource.get(entryId);if(attachmentId!==null&&attachmentId!=0){var tr=self.bookentriesGrid.tbody.find("tr[data-uid='"+dataItem.uid+"']");tr.addClass('tbo-state-selected-to-delete');ErrorDialogEmbedded.show('Willst Du den Anhang zu der rot markierten Eingabe wirklich überschreiben?',btnOk|btnCancel,iconUser,"AlertMessageWrapper").then(function(){tr.removeClass('tbo-state-selected-to-delete');self.uploadFiles(file,errFiles,lea,year,entryId,0);},function(){tr.removeClass('tbo-state-selected-to-delete');});self.bookentriesGrid.element.find(".k-grid-content").animate({scrollTop:tr.offset().top-self.bookentriesGrid.content.offset().top+self.bookentriesGrid.content.scrollTop()-(tr.offset().top-self.bookentriesGrid.content.offset().top)/2},400);return;}
if(errFiles.length>0){switch(errFiles[0].$error){case'maxFiles':self.errorMessage=decodeHtml("Es kann nur ein PDF-Dokument je Eingabe angefügt werden. Maximale Größe 1,5 MB.");self.alert();break;case'pattern':self.errorMessage=decodeHtml("Es kann nur ein PDF-Dokument angefügt werden.");self.alert();break;case'maxSize':self.errorMessage=decodeHtml("Das Dokument überschreitet die maximale Größe von 1,5 MB.");self.alert();break;default:self.errorMessage=decodeHtml("Unbekannter Fehler beim Upload: "+errFiles[0].$error);self.alert();break;}
return;}
self.f=file;self.fileProgress=0;self.fileProgressId=entryId;if(file){SessionService.progressSymbol(true);RequestsErrorHandler.specificallyHandled(function(){file.upload=Upload.upload({url:SessionService.getApiUrl()+'/api/file',headers:{'lea':lea,'year':year,'id':entryId},data:{file:file}});});file.upload.then(function(response){dataItem=self.gridDataSource.get(entryId);for(var key in response.data){if(response.data.hasOwnProperty(key)){dataItem.set(key,response.data[key]);}}
self.fileProgress=0;self.fileProgressId=0;SessionService.progressSymbol(false);},function(response){self.errorMessage=response.statusText+': '+(typeof(response.data)==='object'?response.data.Message:response.data);self.alert();SessionService.progressSymbol(false);self.fileProgress=0;self.fileProgressId=0;},function(evt){self.fileProgressId=entryId;self.fileProgress=Math.min(100,parseInt(100.0*evt.loaded/evt.total));});}}
this.initCheckboxFilter=function initCheckboxFilter(e){var popup=e.container.data("kendoPopup");var dataSource=this.dataSource;var field=e.field;var checkboxesDataSource=new kendo.data.DataSource({data:self.uniqueForField(dataSource,field),});var displayField=""
switch(field){case'CategoryId':displayField='CategoryDesc';e.container.data("kendoPopup").bind("open",function(){self.updateCheckboxFilter(e,field);});break;case'IncomeExpenseId':displayField='IEDesc';e.container.data("kendoPopup").bind("open",function(){self.updateCheckboxFilter(e,field);});break;case'TypeId':displayField='TypeDesc';e.container.data("kendoPopup").bind("open",function(){self.updateCheckboxFilter(e,field);});break;default:displayField=field;}
var helpTextElement=e.container.children(":first").children(":first");helpTextElement.nextUntil(":has(.k-button)").remove();var element=$("").insertAfter(helpTextElement).kendoListView({dataSource:checkboxesDataSource,pageable:true,template:"
',filterable:false},]};}
this.getIncomeExpensesWithCategories=function getIncomeExpensesWithCategories(){console.log('getIncomeExpensesWithCategories');SessionService.progressSymbol(true);RequestsErrorHandler.specificallyHandled(function(){$http({method:'get',url:SessionService.getApiUrl()+'/api/incomeexpenses',headers:{'content-type':'text/xml'}}).then(function(response){SessionService.progressSymbol(false);self.incomeExpensesWithCategories=response.data;self.setKendoGridOptions();},function(response){SessionService.progressSymbol(false);self.errorMessage=response.statustext;self.alert();});})};this.getSettings=function getSettings(){DEBUG&&console.log('getSettings');SessionService.progressSymbol(true);SessionService.getSettings().then(function(response){self.Settings=response;self.showColumns();SessionService.progressSymbol(false);},function(response){SessionService.progressSymbol(false);self.errorMessage=response.statusText+': '+(typeof(response.data)==='object'?response.data.Message:response.data);self.alert();});};this.getIncomeExpensesWithCategories();this.getSettings();this.sumFooter=function(field){var allData=self.gridDataSource.data();var query=new kendo.data.Query(allData);var data;if(self.gridDataSource.filter()){data=query.filter(self.gridDataSource.filter()).data;}else{data=query.data;}
var item,sum=0;for(var idx=0;idx0?0:addToFirstColumn;addToFirstColumn=self.setColumnWidth("Note",0)>0?0:addToFirstColumn;addToFirstColumn=self.setColumnWidth("Info1",0)>0?0:addToFirstColumn;addToFirstColumn=self.setColumnWidth("Info2",0)>0?0:addToFirstColumn;self.bookentriesGrid.autoFitColumn("EntryNumber");self.bookentriesGrid.autoFitColumn("InvoiceDate");self.bookentriesGrid.autoFitColumn("TypeId");self.bookentriesGrid.autoFitColumn("IncomeExpenseId");self.bookentriesGrid.autoFitColumn("CategoryId");self.bookentriesGrid.autoFitColumn("Amount");self.bookentriesGrid.autoFitColumn("Vat");self.bookentriesGrid.autoFitColumn("IsOK");self.bookentriesGrid.autoFitColumn("Net");self.bookentriesGrid.autoFitColumn("Tax");self.bookentriesGrid.autoFitColumn("Attachment");self.bookentriesGrid.autoFitColumn("Command");var tableWidth=grid.wrapper.find("div.k-grid-content")[0].clientWidth;var autoFitColumnsWidth=0;var countNoneAutoFitColumns=0;for(i=0;i0){var autoFitColumnWidth=Math.floor((tableWidth-autoFitColumnsWidth)/countNoneAutoFitColumns);var addToFirstColumn=(tableWidth-autoFitColumnsWidth)%countNoneAutoFitColumns;if(autoFitColumnWidth0?0:addToFirstColumn;addToFirstColumn=self.setColumnWidth("Note",autoFitColumnWidth+addToFirstColumn)>0?0:addToFirstColumn;addToFirstColumn=self.setColumnWidth("Info1",autoFitColumnWidth+addToFirstColumn)>0?0:addToFirstColumn;addToFirstColumn=self.setColumnWidth("Info2",autoFitColumnWidth+addToFirstColumn)>0?0:addToFirstColumn;}};this.setColumnWidth=function(field,width){opt=self.bookentriesGrid.getOptions();j=0;for(i=0;iRechnungsdatumangegeben werden.");return false;}
return true;},invoiceDateValidation:function(input){DEBUG&&console.log("entered invoiceDataValidation");if(input.is("[name='InvoiceDate']")&&input.val()!=""){DEBUG&&console.log("invoceDateValidation input:",input.val());var dateValid=tboCheckDate(input.val());DEBUG&&console.log("currentDate:"+input.val());if(!dateValid){input.attr("data-invoicedatevalidation-msg","Das Datum ist nicht gültig.");return false;}
dateValid=input.data("kendoDatePicker").value();if(!dateValid){input.attr("data-invoicedatevalidation-msg","Das Datum ist nicht gültig.");return false;}
dateValid=tboCheckDate(input.val(),self.currentBookKeeping.Year);if(!dateValid){input.attr("data-invoicedatevalidation-msg","Das Datum mussim Jahr "+self.currentBookKeeping.Year+" liegen.");return false;}}
return true;}}},TypeId:{nullable:false,validation:{typeIdRequired:function(input){if(input.is("[name='TypeId']")&&input.val()==""){input.attr("data-typeIdRequired-msg","Es muss eineBuchungstypangegeben werden.");return false;}
return true;}}},CustomerSupplier:{nullable:false,validation:{customerSupplierRequired:function(input){if(input.is("[name='CustomerSupplier']")&&input.val()==""){input.attr("data-customerSupplierRequired-msg","Es muss einKunde/Lieferantangegeben werden.");return false;}
return true;}}},Note:{nullable:false},Info1:{nullable:false},Info2:{nullable:false},IncomeExpenseId:{nullable:false,validation:{incomeExpenseIdRequired:function(input){DEBUG&&console.log("entered incomeExpenseIdRequired");if(input.is("[name='IncomeExpenseId']")&&input.val()==""){input.attr("data-incomeExpenseIdRequired-msg","Es muss eineEinnahmen-/Ausgabenartangegeben werden.");return false;}
if(input.is("[name='IncomeExpenseId']")&&input.val()!=""){validator=$("#BookentriesGrid").kendoValidator().data("kendoValidator");validator.validateInput($("input[name=CategoryId]"));validator.validateInput($("input[name=Vat]"));}
return true;}}},CategoryId:{nullable:false,validation:{categoryIdRequired:function(input){if(input.is("[name='CategoryId']")&&input.val()==""){input.attr("data-categoryIdRequired-msg","Es muss eineEinnahmen-/Ausgabenkategorieangegeben werden.");return false;}
return true;},categoryIdValidation:function(input){if(input.is("[name='CategoryId']")||input.is("[name='IncomeExpenseId']")){var row=input.closest("tr");var grid=row.closest("[data-role=grid]").data("kendoGrid");var dataItem=grid.dataItem(row);var curCategoryId="",curIncomeExpenseId="";input.is("[name='CategoryId']")?curCategoryId=input.val():curCategoryId=dataItem.CategoryId;input.is("[name='IncomeExpenseId']")?curIncomeExpenseId=input.val():curIncomeExpenseId=dataItem.IncomeExpenseId;if(curCategoryId=="SVA"&&curIncomeExpenseId=="A-AUST"){self.categoryHint=decodeHtml("SVA in Kombination mit einer Ausgabe im Ausland ist nur in den seltensten F\ällen korrekt!");$timeout(0);return true;}
self.categoryHint="";$timeout(0);return true;}
return true;}}},Amount:{type:"number",validation:{amountValidation:function(input){DEBUG&&console.log("entered amountValidation");if(input.is("[name='Amount']")){var row=input.closest("tr");var grid=row.closest("[data-role=grid]").data("kendoGrid");var dataItem=grid.dataItem(row);var curAmount=null,curCategoryId="";input.is("[name='Amount']")?curAmount=input.val():curAmount=dataItem.Vat;input.is("[name='CategoryId']")?curCategoryId=input.val():curCategoryId=dataItem.CategoryId;if(curAmount>400&&curCategoryId=="GWG"&&self.currentBookKeeping.Year<2020){self.amountHint=decodeHtml("Ein Betrag über 400 Euro bei einem geringfügigen Wirtschaftsgut ist in der Regel nicht korrekt.");$timeout(0);return true;}
if(curAmount>800&&curCategoryId=="GWG"&&self.currentBookKeeping.Year>=2020){self.amountHint=decodeHtml("Ein Betrag über 800 Euro bei einem geringfügigen Wirtschaftsgut ist in der Regel nicht korrekt.");$timeout(0);return true;}
self.amountHint="";$timeout(0);return true;}
return true;}}},SignedAmount:{type:"number",editable:false},Vat:{nullable:true,type:"number",validation:{vatValidation:function(input){DEBUG&&console.log("entered vatValidation");DEBUG&&console.log("field:"+input[0].name);if(input.is("[name='Vat']")){if(self.currentBookKeeping.IsGross=="true"){return true;}
var row=input.closest("tr");var grid=row.closest("[data-role=grid]").data("kendoGrid");var dataItem=grid.dataItem(row);var curVat=null,curIncomeExpenseId="",curUstCode="";input.is("[name='Vat']")?curVat=input.val():curVat=dataItem.Vat;input.is("[name='IncomeExpenseId']")?curIncomeExpenseId=input.val():curIncomeExpenseId=dataItem.IncomeExpenseId;if(curIncomeExpenseId!=""){curUstCode=($filter('filter')(self.incomeExpensesWithCategories,curIncomeExpenseId,true,'value'))[0].UstCode;}
if(curVat!=null&&(curVat<0||curVat>100)){input.attr("data-vatValidation-msg","Der Steuersatz muss einen Wert von 0 bis 100 annehmen.");return false;}
if((curUstCode=="A-AUSL"||curUstCode=="E-OUB"||curUstCode=="E-RC"||curUstCode=="E-NSTB")&&(curVat!=null&&curVat!="")){input.attr("data-vatValidation-msg","Bei dieser E/A-Art darf kein Steuersatz angegeben sein.");return false;}else if(curUstCode=="A-O"||curUstCode=="A-RC"||curUstCode=="A-IGE"||curUstCode=="E-O"){if(curVat==null||curVat==""){input.attr("data-vatValidation-msg","Der Wert muss aufgrund der E/A-Art 0%, 10%, 13% oder 20% sein.");return false;}
else if(curVat!=0&&curVat!=10&&curVat!=13&&curVat!=20){input.attr("data-vatValidation-msg","Bei dieser E/A-Art sind nur 0%, 10%, 13% oder 20% erlaubt.");return false;}
if(curVat==0&&curUstCode=="E-O"){self.vatHint=decodeHtml("0% USt bei einer Einnahme in Österreich ist nur in den seltensten F\ällen korrekt.");$timeout(0);return true;}}else if((curUstCode=="A-WDL"||curUstCode=="E-IGL"||curUstCode=="E-EX")&&(curVat!=0||curVat==""||curVat==null)){input.attr("data-vatValidation-msg","Der Steuersatz muss 0% sein.");return false;}else{if(curVat==null){self.vatHint=decodeHtml("Es wurde kein Steuersatz angegeben.");$timeout(0);return true;}}
self.vatHint="";$timeout(0);return true;}
return true;}}},IsOK:{type:"boolean",defaultValue:true},Net:{type:"number",editable:false},SignedNet:{type:"number",editable:false},Tax:{type:"number",editable:false},SignedTax:{type:"number",editable:false},Attachment:{editable:false}}}},aggregate:[{field:"Amount",aggregate:"sum"},{field:"SignedAmount",aggregate:"sum"},{field:"Tax",aggregate:"sum"},{field:"SignedTax",aggregate:"sum"},{field:"Net",aggregate:"sum"},{field:"SignedNet",aggregate:"sum"},],requestStart:function(e){if(self._isInEditMode){e.preventDefault();}}});var dropDownElementTemplate='