-1

Suppose:

1bhk flat 200rupee maintainance

2bhk flat 400rupee maintainance charges

Suppose 1 bhk user pays the amount in a given date.

But if user does not pay the amount in the given date then automatically add 20% extra charge on to the basic amount.

Is it possible to implement this in Objective C?

NSNoob
  • 5,548
  • 6
  • 41
  • 54

2 Answers2

0

It's very simple bro. Following code will work for 1BHK user.

float oneBHKCharge=200;

float finalDue=0;

NSString *strDueDate = @"10-02-2017";
NSString *strPaidDate = @"10-02-2017";

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd-MM-yyyy"];
NSDate *dueDate = [dateFormatter dateFromString:strDueDate];
NSDate *paidDate = [dateFormatter dateFromString:strPaidDate];


NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *components = [gregorianCalendar components:NSCalendarUnitDay
                                                    fromDate:dueDate
                                                      toDate:paidDate
                                                     options:0];


if (components.day > 0)
{
    finalDue = oneBHKCharge + oneBHKCharge*0.2;
}
else
{
    finalDue = oneBHKCharge;
}

NSLog(@"%f",finalDue);
MD.
  • 1,157
  • 11
  • 18
0

Here the code I solved this topic. I stored in the NSUserdefaults the days that count as overdue. An did here the check

- (NSNumber *)invoiceOverDue
{
   NSNumber *result;
   NSInteger dueDays = [[NSUserDefaults standardUserDefaults] integerForKey:VPPayDue];
  if ([[self dueTime] intValue] > dueDays) 
  {
    result = [NSNumber numberWithBool:YES];
  }

  else {
    result = [NSNumber numberWithBool:NO];
  }
  return result;
}

And here the part in witch I calculate the overdue time.

// DueTime calculation
-(NSNumber *)dueTime
{
// NSTimeInterval secondsPerDay = 24 * 60 * 60;
if ([[self invoiceStatus] intValue] > 1)
{
    return [NSNumber numberWithInt:0];
}

else {
    NSTimeInterval calculateTime = [[* Insert here the date of your invoice*] timeIntervalSinceNow];
    //DLog(@"dueTime bevor / 86400 :%f", calculateTime);
    calculateTime /= -86400;
    //DLog(@"dueTime :%f", calculateTime);
    int returnInt = [ConverterHelper numberRoundUp:calculateTime];

    return [NSNumber numberWithInt:returnInt];
}

}

voltae
  • 582
  • 4
  • 11