Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Made currency display in Payments consistent with rest of app #185

Closed
wants to merge 5 commits into from

4 participants

@invariant

Payment amounts were appearing weirdly in the Payments view, for
example 134.45£. With this update, it will appear as £134.45.
Added two new methods to CurrencyManager to give output in any
specified currency. Edited exiting methods to use those methods so as
not to repeat code.
Removed the separate number formatter in PaymentsViewController.

invariant and others added some commits
@invariant invariant Update PaymentsViewController to use the CurrencyManager to format am…
…ounts.

Payment amounts were appearing weirdly in the Payments view, for
example 134.45£. With this update, it will appear as £134.45.
Added two new methods to CurrencyManager to give output in any
specified currency. Edited exiting methods to use those methods so as
not to repeat code.
Removed the separate number formatter in PaymentsViewController.
ab2f6e7
@invariant invariant Merge https://github.com/omz/AppSales-Mobile bb3c4c3
@aporat aporat duplicate weekly reports fix c9bea94
@TheRealKerni TheRealKerni Fix fiscal calendar 7c005fa
@invariant

Thanks aporat. I pulled this into my repo.

ah, cool, maybe comment on the pull request, so @omz will merge it into the main repo :-) omz#198

@omz omz closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 29, 2011
  1. @invariant

    Update PaymentsViewController to use the CurrencyManager to format am…

    invariant authored
    …ounts.
    
    Payment amounts were appearing weirdly in the Payments view, for
    example 134.45£. With this update, it will appear as £134.45.
    Added two new methods to CurrencyManager to give output in any
    specified currency. Edited exiting methods to use those methods so as
    not to repeat code.
    Removed the separate number formatter in PaymentsViewController.
Commits on Feb 22, 2012
  1. @invariant
  2. @aporat @invariant

    duplicate weekly reports fix

    aporat authored invariant committed
  3. @TheRealKerni @invariant

    Fix fiscal calendar

    TheRealKerni authored invariant committed
Commits on Oct 9, 2012
  1. @invariant
This page is out of date. Refresh to see the latest.
View
3  Classes/AppleFiscalCalendar.m
@@ -34,7 +34,8 @@ - (id)init
//Covers the fiscal calendar from 2008 to 2016:
while (period < 100) {
//First month in a quarter covers 5 weeks, the others 4:
- NSDate *nextDate = [calendar dateByAddingComponents:((period % 3 == 0) ? components5Weeks : components4Weeks) toDate:currentDate options:0];
+ NSDate *nextDate = [calendar dateByAddingComponents:((period % 3 == 0) || (period % 50 == 0) ?
+ components5Weeks : components4Weeks) toDate:currentDate options:0];
[dates addObject:nextDate];
currentDate = nextDate;
period++;
View
2  Classes/CurrencyManager.h
@@ -55,6 +55,8 @@
+ (CurrencyManager *)sharedManager;
- (NSString *)baseCurrencyDescription;
- (NSString *)currencySymbolForCurrency:(NSString *)currencyCode;
+- (NSString *)descriptionForAmount:(NSString *)amount currency:(NSString *)currencyCode;
+- (NSString *)descriptionForAmount:(NSNumber *)amount currency:(NSString *)currencyCode withFraction:(BOOL)withFraction;
- (NSString *)baseCurrencyDescriptionForAmount:(NSString *)amount;
- (NSString *)baseCurrencyDescriptionForAmount:(NSNumber *)amount withFraction:(BOOL)withFraction;
- (void)forceRefresh;
View
21 Classes/CurrencyManager.m
@@ -159,8 +159,7 @@ - (void)setBaseCurrency:(NSString *)newBaseCurrency
- (NSString *)baseCurrencyDescription
{
- NSString *currencySymbol = [currencySymbols objectForKey:baseCurrency];
- return (currencySymbol != nil) ? currencySymbol : baseCurrency;
+ return [self currencySymbolForCurrency:[self baseCurrency]];
}
- (NSString *)currencySymbolForCurrency:(NSString *)currencyCode
@@ -169,16 +168,26 @@ - (NSString *)currencySymbolForCurrency:(NSString *)currencyCode
return (currencySymbol != nil) ? currencySymbol : currencyCode;
}
+- (NSString *)descriptionForAmount:(NSString *)amount currency:(NSString *)currencyCode
+{
+ return [NSString stringWithFormat:@"%@%@", [self currencySymbolForCurrency:currencyCode], amount];
+}
+
+- (NSString *)descriptionForAmount:(NSNumber *)amount currency:(NSString *)currencyCode withFraction:(BOOL)withFraction
+{
+ NSNumberFormatter *numberFormatter = (withFraction) ? (numberFormatterWithFraction) : (numberFormatterWithoutFraction);
+ NSString *formattedAmount = [numberFormatter stringFromNumber:amount];
+ return [self descriptionForAmount:formattedAmount currency:currencyCode];
+}
+
- (NSString *)baseCurrencyDescriptionForAmount:(NSString *)amount
{
- return [NSString stringWithFormat:@"%@%@", [self baseCurrencyDescription], amount];
+ return [self descriptionForAmount:amount currency:[self baseCurrency]];
}
- (NSString *)baseCurrencyDescriptionForAmount:(NSNumber *)amount withFraction:(BOOL)withFraction
{
- NSNumberFormatter *numberFormatter = (withFraction) ? (numberFormatterWithFraction) : (numberFormatterWithoutFraction);
- NSString *formattedAmount = [numberFormatter stringFromNumber:amount];
- return [self baseCurrencyDescriptionForAmount:formattedAmount];
+ return [self descriptionForAmount:amount currency:[self baseCurrency] withFraction:withFraction];
}
- (void)refreshIfNeeded
View
14 Classes/PaymentsViewController.m
@@ -60,11 +60,6 @@ - (void)reloadData
{
for (UIView *v in [NSArray arrayWithArray:self.scrollView.subviews]) [v removeFromSuperview];
- NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
- [numberFormatter setMaximumFractionDigits:2];
- [numberFormatter setGroupingSize:3];
- [numberFormatter setUsesGroupingSeparator:YES];
-
NSMutableDictionary *paymentsByYear = [NSMutableDictionary dictionary];
NSMutableDictionary *sumsByYear = [NSMutableDictionary dictionary];
NSSet *allPayments = account.payments;
@@ -95,7 +90,7 @@ - (void)reloadData
if ([payments count] > 0) {
NSNumber *sum = [payments valueForKeyPath:@"@sum.amount"];
NSString *currency = [[payments objectAtIndex:0] valueForKey:@"currency"];
- NSString *label = [NSString stringWithFormat:@"%@%@", [numberFormatter stringFromNumber:sum], [[CurrencyManager sharedManager] currencySymbolForCurrency:currency]];
+ NSString *label = [[CurrencyManager sharedManager] descriptionForAmount:sum currency:currency withFraction:YES];
NSMutableDictionary *labelsForYear = [labelsByYear objectForKey:year];
if (!labelsForYear) {
labelsForYear = [NSMutableDictionary dictionary];
@@ -122,9 +117,10 @@ - (void)reloadData
yearView.labelsByMonth = [labelsByYear objectForKey:year];
if ([allPayments count] > 0) {
//We assume that all payments have the same currency:
- yearView.footerText = [NSString stringWithFormat:@"\u2211 %@%@",
- [[CurrencyManager sharedManager] currencySymbolForCurrency:[[allPayments anyObject] valueForKey:@"currency"]],
- [numberFormatter stringFromNumber:[sumsByYear objectForKey:year]]];
+ yearView.footerText = [NSString stringWithFormat:@"\u2211 %@",
+ [[CurrencyManager sharedManager] descriptionForAmount:[sumsByYear objectForKey:year]
+ currency:[[allPayments anyObject] valueForKey:@"currency"]
+ withFraction:YES]];
}
yearView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
[scrollView addSubview:yearView];
View
41 Classes/Report.m
@@ -195,19 +195,36 @@ + (Report *)insertNewReportWithCSV:(NSString *)csv inAccount:(ASAccount *)accoun
if (platform) {
product.platform = platform;
}
-
+
if (!report) {
- if (isWeeklyReport) {
- report = [NSEntityDescription insertNewObjectForEntityForName:@"WeeklyReport" inManagedObjectContext:moc];
- [(WeeklyReport *)report setEndDate:endDate];
- [(WeeklyReport *)report setAccount:account];
- } else {
- report = [NSEntityDescription insertNewObjectForEntityForName:@"DailyReport" inManagedObjectContext:moc];
- [(DailyReport *)report setAccount:account];
- }
- report.startDate = beginDate;
- }
- [[report mutableSetValueForKey:@"transactions"] addObject:transaction];
+ NSFetchRequest *existingReportsFetchRequest = [[[NSFetchRequest alloc] init] autorelease];
+ if (isWeeklyReport) {
+ [existingReportsFetchRequest setEntity:[NSEntityDescription entityForName:@"WeeklyReport" inManagedObjectContext:moc]];
+ [existingReportsFetchRequest setPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND endDate == %@", account, endDate]];
+ } else {
+ [existingReportsFetchRequest setEntity:[NSEntityDescription entityForName:@"DailyReport" inManagedObjectContext:moc]];
+ [existingReportsFetchRequest setPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND startDate == %@", account, endDate]];
+ }
+
+ NSArray *existingReports = [moc executeFetchRequest:existingReportsFetchRequest error:NULL];
+
+ // in case there's already a report with the same date, skip this report
+ if ([existingReports count]!=0) {
+ return nil;
+ }
+
+ if (isWeeklyReport) {
+ report = [NSEntityDescription insertNewObjectForEntityForName:@"WeeklyReport" inManagedObjectContext:moc];
+ [(WeeklyReport *)report setEndDate:endDate];
+ [(WeeklyReport *)report setAccount:account];
+ } else {
+ report = [NSEntityDescription insertNewObjectForEntityForName:@"DailyReport" inManagedObjectContext:moc];
+ [(DailyReport *)report setAccount:account];
+ }
+ report.startDate = beginDate;
+ }
+ [[report mutableSetValueForKey:@"transactions"] addObject:transaction];
+
}
return report;
}
Something went wrong with that request. Please try again.