Skip to content

Instantly share code, notes, and snippets.

@toco
Last active December 19, 2015 03:48
Show Gist options
  • Save toco/5892319 to your computer and use it in GitHub Desktop.
Save toco/5892319 to your computer and use it in GitHub Desktop.
Category for https://github.com/toco/DTAUS to create http://www.bezahlcode.de URLs using the BezahlCode library.
- (BOOL)application:(NSApplication *)sender openFile:(NSString *)filename {
NSData *fileData = [NSData dataWithContentsOfFile:filename];
DTAData *aDTAData = [DTAParser parseData:fileData];
for (NSURL *aUrl in [aDTAData bezahlCodeURLs]) {
[[NSWorkspace sharedWorkspace] openURL:aUrl];
}
BOOL success = aDTAData!=nil;
if (!success) {
// handle error
}
return success;
}
//
// DTAData+bezahlCode.h
//
// Created by Tobias Conradi on 06.01.13.
//
// Copyright (c) 2013 Tobias Conradi
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#import "DTAData.h"
#import "DTABuchung.h"
#import "BezahlCodeLinkCreator.h"
@interface DTAData (bezahlCode)
/*!
* @return Returns an array of bezahlCode URLs containing all DTABuchung instances in DTAData.
*/
- (NSArray*) bezahlCodeURLs;
@end
@interface DTABuchung (bezahlCode)
/*!
* Returns a bezahlCode URL representation of itself by using BezahlCodeLinkCreator
*
* @param executionDate date of execution
* @param isPayment YES for payment, NO for debit
*/
- (NSURL *)bezahlCodeWithExecutionDate:(NSDate*)executionDate payment:(BOOL) isPayment;
@end
//
// DTAData+bezahlCode.m
//
// Created by Tobias Conradi on 06.01.13.
//
// Copyright (c) 2013 Tobias Conradi
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#import "DTAData+bezahlCode.h"
@implementation DTAData (bezahlCode)
- (NSArray *)bezahlCodeURLs {
NSMutableArray *bezahlCodes = [NSMutableArray arrayWithCapacity:[self.buchungen count]];
NSDate *executionDate = nil; // TODO: self.ausfuerungsDatum convert to date
if ([[self.ausfuerungsDatum stringByReplacingOccurrencesOfString:@" " withString:@""] length]) {
NSDateFormatter *formatter = [NSDateFormatter new];
[formatter setDateFormat:@"ddMMyy"];
executionDate = [formatter dateFromString:self.ausfuerungsDatum];
} else {
executionDate = [NSDate date];
}
BOOL isPayment = ![[[self art] substringToIndex:1] isEqualToString:@"L"];
for (DTABuchung *aBuchung in self.buchungen) {
[bezahlCodes addObject:[aBuchung bezahlCodeWithExecutionDate:executionDate payment:isPayment]];
}
return [bezahlCodes copy];
}
@end
@implementation DTABuchung (bezahlCode)
- (NSURL *)bezahlCodeWithExecutionDate:(NSDate*)executionDate payment:(BOOL) isPayment{
NSParameterAssert(executionDate);
NSString *betrag = [self.betrag stringByReplacingCharactersInRange:NSMakeRange([self.betrag length]-2, 0) withString:@","];
NSString *currencyCode = @"DM";
if ([self.waehrung isEqualToString:@"1"]) {
currencyCode = @"EUR";
}
BezahlCodeLinkCreatorLinkTypes paymentType = isPayment ? EBezahlCodeLinkCreatorLinkType_SinglePayment : EBezahlCodeLinkCreatorLinkType_SingleDirectDebit;
NSString *bezahlCode = [BezahlCodeLinkCreator CreateBezahlCodeForType:paymentType
withName:self.kundenName
withAccountNumber:self.kundenKontonummer
withBNC:self.kundenBankleitzahl
withReasonsArray:self.verwendungszweck
withAmount:betrag
withCurrencyCode:currencyCode
withPostingKey:self.buchungsSchluessel
withPostingKeyExtension:self.buchungsSchluesselErgaenzung
withExecutionDate:executionDate
withPeriodicTimeUnit:nil
withPeriodicTimeUnitRotation:0
withPeriodicFirstExecutionDate:nil
withPeriodicFirstExecutionDay:0
withPeriodicLastExecutionDate:nil
];
return [NSURL URLWithString:bezahlCode];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment