diff --git a/DUREX Vendor Control/Base.lproj/Localizable.strings b/DUREX Vendor Control/Base.lproj/Localizable.strings
index f635f11..d77af42 100644
--- a/DUREX Vendor Control/Base.lproj/Localizable.strings
+++ b/DUREX Vendor Control/Base.lproj/Localizable.strings
@@ -78,6 +78,7 @@
"Discounted Price" = "Discounted Price";
"1€ Change" = "1€ Change";
"50c Change" = "50c Change";
+"Money Paid" = "Money Paid";
"Update Date & Time" = "Update Date & Time";
"Update product price" = "Update product price";
"Update product name" = "Update product name";
\ No newline at end of file
diff --git a/DUREX Vendor Control/CommunicationProtocol.h b/DUREX Vendor Control/CommunicationProtocol.h
index acfe69a..772dd8a 100644
--- a/DUREX Vendor Control/CommunicationProtocol.h
+++ b/DUREX Vendor Control/CommunicationProtocol.h
@@ -17,7 +17,7 @@
#define MONEY_OUT_NUM_UNITS ((int)3)
#define CHANGE_NUM_UNITS ((int)2)
#define MAX_PRODUCTS ((int)16)
-
+#define SALE_STRING_LENGTH ((int)36)
@interface CommunicationProtocol : NSObject
@@ -30,7 +30,7 @@
-(Boolean) updatePrice: (uint8_t) channel : (uint8_t) product : (uint8_t) eur : (uint8_t) cents;
-(Boolean) updateProductName: (uint8_t) channel : (uint8_t) product : (NSString*) name;
-(NSString*) readSensorData;
--(NSString*) readSalesLog: (NSDate*) start : (NSDate*) end;
+-(NSString*) readSalesLog: (NSDateComponents*) start : (NSDateComponents*) end;
+(id) sharedProtocol;
@end
diff --git a/DUREX Vendor Control/CommunicationProtocol.m b/DUREX Vendor Control/CommunicationProtocol.m
index bd2c827..e80b91a 100644
--- a/DUREX Vendor Control/CommunicationProtocol.m
+++ b/DUREX Vendor Control/CommunicationProtocol.m
@@ -311,12 +311,6 @@
-(Boolean) updateTime: (NSDateComponents*) date
{
- if(date == nil)
- {
- NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
- NSCalendarUnit units = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
- date = [calendar components:units fromDate:[NSDate date]];
- }
NSMutableString *command = [NSMutableString stringWithFormat: @"A5"];
NSInteger year = [date year];
year = year - (year/100)*100;
@@ -363,9 +357,9 @@
{
NSString *command = @"A4";
[self writeMessage:command];
- NSString *answer = [self readMessage];
+ //NSString *answer = [self readMessage];
- /*NSMutableString *answer = [[NSMutableString alloc]initWithString:@"P400255002550025510"];
+ NSMutableString *answer = [[NSMutableString alloc]initWithString:@"P400255002550025510"];
for(int i = 0; i < 15; i++)
{
[answer appendString:@"0"];
@@ -379,19 +373,19 @@
[answer appendString:@"2"];
}
[answer appendString:@"1"];
- [answer appendString:@"1"];*/
-
- if([[answer substringToIndex:2]isEqualToString:@"P4"])
+ [answer appendString:@"1"];
+
+ if([answer length] > 1 && [[answer substringToIndex:2]isEqualToString:@"P4"])
{
return answer;
}
return nil;
}
--(NSString*) readSalesLog : (NSDate*) start : (NSDate*) end
+-(NSString*) readSalesLog : (NSDateComponents*) start : (NSDateComponents*) end
{
- NSMutableString *startDate = [[NSMutableString alloc] init];
- NSMutableString *endDate = [[NSMutableString alloc] init];
+ NSMutableString *startDate = [NSMutableString stringWithString:@""];
+ NSMutableString *endDate = [NSMutableString stringWithString:@""];
NSMutableString *command = [NSMutableString stringWithString:@"A2"];
if(start == nil)
{
@@ -399,7 +393,10 @@
}
else
{
-
+ NSInteger year = [start year];
+ year = year - (year/100)*100;
+ [startDate appendString:[NSString stringWithFormat:@"%02ld",(long)year]];
+ [startDate appendString:[NSString stringWithFormat:@"%02ld%02ld%02ld%02ld",(long)[start month],(long)[start day],(long)[start hour],(long)[start minute]]];
}
if(end == nil)
{
@@ -407,7 +404,10 @@
}
else
{
-
+ NSInteger year = [end year];
+ year = year - (year/100)*100;
+ [endDate appendString:[NSString stringWithFormat:@"%02ld",(long)year]];
+ [endDate appendString:[NSString stringWithFormat:@"%02ld%02ld%02ld%02ld",(long)[end month],(long)[end day],(long)[end hour],(long)[end minute]]];
}
[command appendString:startDate];
[command appendString:@"-"];
@@ -417,7 +417,7 @@
NSMutableString *answer = [[NSMutableString alloc]initWithString:@"P21405141651102416090662045001500512P21406141651102416090662045001500512P2P2"];
- if([[answer substringToIndex:2]isEqualToString:@"P2"])
+ if([answer length] > 1 && [[answer substringToIndex:2]isEqualToString:@"P2"])
{
return answer;
}
diff --git a/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.xcworkspace/xcuserdata/imanol.xcuserdatad/UserInterfaceState.xcuserstate b/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.xcworkspace/xcuserdata/imanol.xcuserdatad/UserInterfaceState.xcuserstate
index 63ef1aa..0afb628 100644
--- a/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.xcworkspace/xcuserdata/imanol.xcuserdatad/UserInterfaceState.xcuserstate
+++ b/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.xcworkspace/xcuserdata/imanol.xcuserdatad/UserInterfaceState.xcuserstate
diff --git a/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/xcuserdata/imanol.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/xcuserdata/imanol.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
index fe2b454..cf1192b 100644
--- a/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/xcuserdata/imanol.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
+++ b/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/xcuserdata/imanol.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
@@ -2,4 +2,230 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/DUREX Vendor Control/FirstAppExample/Base.lproj/MainStoryboard.storyboard b/DUREX Vendor Control/FirstAppExample/Base.lproj/MainStoryboard.storyboard
index 3efc01b..1bc2341 100644
--- a/DUREX Vendor Control/FirstAppExample/Base.lproj/MainStoryboard.storyboard
+++ b/DUREX Vendor Control/FirstAppExample/Base.lproj/MainStoryboard.storyboard
@@ -119,7 +119,7 @@
-
+
diff --git a/DUREX Vendor Control/FirstAppExample/main.m b/DUREX Vendor Control/FirstAppExample/main.m
index 68b8059..12cf982 100644
--- a/DUREX Vendor Control/FirstAppExample/main.m
+++ b/DUREX Vendor Control/FirstAppExample/main.m
@@ -1,4 +1,4 @@
- //
+//
// main.m
// TestAppExample
//
diff --git a/DUREX Vendor Control/MenuTableViewController.h b/DUREX Vendor Control/MenuTableViewController.h
index a47ba40..91fe92f 100644
--- a/DUREX Vendor Control/MenuTableViewController.h
+++ b/DUREX Vendor Control/MenuTableViewController.h
@@ -33,20 +33,22 @@
#define MAINTENANCE_CELLS_PER_SECTION num(9),num(3)
#define MAINTENANCE_HEADERS NSLocalizedString(@"Sensors", nil),NSLocalizedString(@"Commands", nil)
-#define SALES_ELEMENTS @"10€ Notes",@"5€ Notes",@"2€ Coins",@"1€ Coins",@"50c Coins",@"Channel",@"Product Code",@"Normal Price",@"Discounted Price",@"1€ Change",@"50c Change"
-#define SALES_CELLS_PER_SECTION num(11)
-#define SALES_HEADERS @"14/06/2014"
+#define SALE_ELEMENTS @"[3000]Money Paid",@"[3001]Channel",@"[3002]Product Code",@"[3003]Normal Price",@"[3004]Discounted Price",@"[3005]Money Returned"
+#define SALE_MONEY_PAID @"10€ Notes",@"5€ Notes",@"2€ Coins",@"1€ Coins",@"50c Coins"
+#define SALE_MONEY_RETURNED @"1€ Change",@"50c Change"
+#define SALE_HEADERS nil
-#define CONFIGURATION_ELEMENTS @"[3000]Update Date & Time",@"[3001]Update product price",@"[3002]Update product name"
+#define CONFIGURATION_ELEMENTS @"[4000]Update Date & Time",@"[4001]Update product price",@"[4002]Update product name"
#define CONFIGURATION_CELLS_PER_SECTION num(3)
#define CONFIGURATION_HEADERS nil
-#define CELL_IDENTIFIERS @"MenuCell",@"MaintenanceCell",@"SalesCell",@"ConfigCell",@"ReportCell"
+#define CELL_IDENTIFIERS @"MenuCell",@"MaintenanceCell",@"SaleListCell",@"SaleCell",@"ConfigCell",@"ReportCell"
enum {
MENU = 0,
MAINTENANCE,
- SALES,
+ SALE_LIST,
+ SALE,
BASIC_CONFIGURATION,
REPORT,
} navigationLevel;
diff --git a/DUREX Vendor Control/MenuTableViewController.m b/DUREX Vendor Control/MenuTableViewController.m
index 091f383..8fefc0f 100644
--- a/DUREX Vendor Control/MenuTableViewController.m
+++ b/DUREX Vendor Control/MenuTableViewController.m
@@ -21,9 +21,9 @@
@property (nonatomic,strong) const NSMutableArray *maintenanceStructure;
@property (nonatomic,strong) const NSMutableArray *maintenanceHeaders;
-@property (nonatomic,strong) const NSMutableArray *salesElements;
-@property (nonatomic,strong) const NSMutableArray *salesStructure;
-@property (nonatomic,strong) const NSMutableArray *salesHeaders;
+@property (nonatomic,strong) const NSMutableArray *saleListElements;
+@property (nonatomic,strong) const NSMutableArray *saleListStructure;
+@property (nonatomic,strong) const NSMutableArray *saleListHeaders;
@property (nonatomic,strong) const NSMutableArray *configElements;
@property (nonatomic,strong) const NSMutableArray *configStructure;
@@ -101,7 +101,7 @@
return TRUE;
}
-- (Boolean) generateSalesNavLevel
+- (Boolean) generateSaleListNavLevel
{
//LAUNCH DATE RANGE SELECTOR
NSString *salesData = [_protocol readSalesLog: nil : nil];
@@ -111,16 +111,9 @@
return FALSE;
}
[[self salesLog] setResponseValue:salesData];
- [self setSalesElements:[[NSMutableArray alloc] initWithObjects:SALES_ELEMENTS, nil]];
- [self setSalesStructure:[[NSMutableArray alloc] initWithObjects:SALES_CELLS_PER_SECTION, nil]];
- if([[self salesStructure] count] > 1)
- {
- [self setSalesHeaders:[[NSMutableArray alloc] initWithObjects:SALES_HEADERS, nil]];
- }
- else
- {
- [self setSalesHeaders:nil];
- }
+ [self setSaleListElements:[[NSMutableArray alloc] initWithObjects:nil, nil]];
+ [self setSaleListStructure:[[NSMutableArray alloc] initWithObjects:nil, nil]];
+ [self setSaleListHeaders:nil];
return TRUE;
}
@@ -147,12 +140,12 @@
[self setCurrentStructure:[self maintenanceStructure]];
[self setCurrentHeaders:[self maintenanceHeaders]];
}
- else if([self currentNavLevel] == SALES)
+ else if([self currentNavLevel] == SALE_LIST)
{
[[self navigationItem] setTitle:NSLocalizedString(@"Sales log", nil)];
- [self setCurrentElements:[self salesElements]];
- [self setCurrentStructure:[self salesStructure]];
- [self setCurrentHeaders:[self salesHeaders]];
+ [self setCurrentElements:[self saleListElements]];
+ [self setCurrentStructure:[self saleListStructure]];
+ [self setCurrentHeaders:[self saleListHeaders]];
}
else if([self currentNavLevel] == BASIC_CONFIGURATION)
{
@@ -237,6 +230,9 @@
//Initialize sensor status
[self setSensorStatus:[[Sensors alloc]init]];
+
+ //Initialize sales log
+ [self setSalesLog:[[SalesLog alloc]init]];
}
-(void)viewDidAppear:(BOOL)animated
@@ -458,14 +454,14 @@
}
else if([cellName isEqualToString:NSLocalizedString(@"Sales log", nil)])
{
- NSLog(@"[MenuTableViewController.m]: Changing to navLevel: SALES");
- if([self generateSalesNavLevel])
+ NSLog(@"[MenuTableViewController.m]: Changing to navLevel: SALE_LIST");
+ if([self generateSaleListNavLevel])
{
- [self changeNavLevel:SALES:TRUE];
+ [self changeNavLevel:SALE_LIST:TRUE];
}
else
{
- NSLog(@"[MenuTableViewController.m]: Error while changing to navLevel: SALES");
+ NSLog(@"[MenuTableViewController.m]: Error while changing to navLevel: SALE_LIST");
}
}
}
@@ -649,9 +645,9 @@
}
}
}
- else if([[NSRegularExpression regularExpressionWithPattern:@"Channel (\\d+)" options:0 error:NULL] numberOfMatchesInString:[[cell textLabel] text] options:0 range:(NSMakeRange(0,[[[cell textLabel] text] length]))] != 0)
+ else if([[NSRegularExpression regularExpressionWithPattern:[NSString stringWithFormat:@"%@ (\\d+)",NSLocalizedString(@"Channel",nil)] options:0 error:NULL] numberOfMatchesInString:[[cell textLabel] text] options:0 range:(NSMakeRange(0,[[[cell textLabel] text] length]))] != 0)
{
- NSUInteger index = [[[[cell textLabel] text] substringFromIndex:8] intValue] - 1;
+ NSUInteger index = [[[[cell textLabel] text] substringFromIndex:([NSLocalizedString(@"Channel",nil) length] + 1)] intValue] - 1;
if([cell tag] == 2001) // Products Present in Channel tag
{
if([[[[self sensorStatus] channelProductAvailability] objectAtIndex:index] intValue] == 1)
@@ -729,9 +725,9 @@
}
[[cell detailTextLabel] setText:[NSString stringWithFormat:@"%d",numSold]];
}
- else if([[NSRegularExpression regularExpressionWithPattern:@"Product (\\d+)" options:0 error:NULL] numberOfMatchesInString:[[cell textLabel] text] options:0 range:(NSMakeRange(0,[[[cell textLabel] text] length]))] != 0)
+ else if([[NSRegularExpression regularExpressionWithPattern:[NSString stringWithFormat:@"%@ (\\d+)",NSLocalizedString(@"Product",nil)] options:0 error:NULL] numberOfMatchesInString:[[cell textLabel] text] options:0 range:(NSMakeRange(0,[[[cell textLabel] text] length]))] != 0)
{
- NSUInteger index = [[[[cell textLabel] text] substringFromIndex:8] intValue] - 1;
+ NSUInteger index = [[[[cell textLabel] text] substringFromIndex:([NSLocalizedString(@"Product",nil) length] + 1)] intValue] - 1;
if([cell tag] == 2007)
{
[[cell detailTextLabel] setText:[[[[self sensorStatus] productsSold] objectAtIndex:index] stringValue]];
diff --git a/DUREX Vendor Control/Sale.h b/DUREX Vendor Control/Sale.h
index 0c15b80..dacc79c 100644
--- a/DUREX Vendor Control/Sale.h
+++ b/DUREX Vendor Control/Sale.h
@@ -16,6 +16,7 @@
@property NSString *productCode;
@property NSString *normalPrice;
@property NSString *discountedPrice;
+@property NSString *channel;
@property NSDate *saleTime;
- (id) init;
diff --git a/DUREX Vendor Control/SalesLog.h b/DUREX Vendor Control/SalesLog.h
index 88c2df6..ebb6785 100644
--- a/DUREX Vendor Control/SalesLog.h
+++ b/DUREX Vendor Control/SalesLog.h
@@ -7,6 +7,8 @@
//
#import
+#import "CommunicationProtocol.h"
+#import "Sale.h"
@interface SalesLog : NSObject
diff --git a/DUREX Vendor Control/SalesLog.m b/DUREX Vendor Control/SalesLog.m
index fbff0a8..f054923 100644
--- a/DUREX Vendor Control/SalesLog.m
+++ b/DUREX Vendor Control/SalesLog.m
@@ -24,7 +24,43 @@
- (void) parseResponse
{
-
+ NSInteger currentSale = 0;
+ NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
+ NSCalendarUnit units = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit;
+ NSDateComponents *saleDate = [[NSDateComponents alloc] init];
+ NSInteger currentYear = [[calendar components:units fromDate:[NSDate date]] year];
+ currentYear = (currentYear/100)*100;
+ while(![[[self response] substringWithRange:NSMakeRange((currentSale*SALE_STRING_LENGTH), 4)] isEqualToString:@"P2P2"])
+ {
+ Sale *sale = [[Sale alloc] init];
+ [saleDate setYear:(currentYear + [[[self response] substringWithRange:NSMakeRange(2 + currentSale*SALE_STRING_LENGTH, 2)] intValue])];
+ [saleDate setMonth:[[[self response] substringWithRange:NSMakeRange(4 + currentSale*SALE_STRING_LENGTH, 2)] intValue]];
+ [saleDate setDay:[[[self response] substringWithRange:NSMakeRange(6 + currentSale*SALE_STRING_LENGTH, 2)] intValue]];
+ [saleDate setHour:[[[self response] substringWithRange:NSMakeRange(8 + currentSale*SALE_STRING_LENGTH, 2)] intValue]];
+ [saleDate setMinute:[[[self response] substringWithRange:NSMakeRange(10 + currentSale*SALE_STRING_LENGTH, 2)] intValue]];
+ [sale setSaleTime:[saleDate date]];
+ NSLog(@"date: %@",saleDate);
+ [[sale moneyPaid] insertObject:[NSNumber numberWithInt:[[[self response] substringWithRange:NSMakeRange(12 + currentSale*SALE_STRING_LENGTH, 2)] intValue]] atIndex:0];
+ [[sale moneyPaid] insertObject:[NSNumber numberWithInt:[[[self response] substringWithRange:NSMakeRange(14 + currentSale*SALE_STRING_LENGTH, 2)] intValue]] atIndex:1];
+ [[sale moneyPaid] insertObject:[NSNumber numberWithInt:[[[self response] substringWithRange:NSMakeRange(16 + currentSale*SALE_STRING_LENGTH, 2)] intValue]] atIndex:2];
+ [[sale moneyPaid] insertObject:[NSNumber numberWithInt:[[[self response] substringWithRange:NSMakeRange(18 + currentSale*SALE_STRING_LENGTH, 2)] intValue]] atIndex:3];
+ [[sale moneyPaid] insertObject:[NSNumber numberWithInt:[[[self response] substringWithRange:NSMakeRange(20 + currentSale*SALE_STRING_LENGTH, 2)] intValue]] atIndex:4];
+ NSLog(@"moneyPaid: %@",[sale moneyPaid]);
+ [sale setChannel:[[self response] substringWithRange:NSMakeRange(22 + currentSale*SALE_STRING_LENGTH, 1)]];
+ NSLog(@"channel: %@",[sale channel]);
+ [sale setProductCode:[[self response] substringWithRange:NSMakeRange(23 + currentSale*SALE_STRING_LENGTH, 1)]];
+ NSLog(@"productCode: %@",[sale productCode]);
+ [sale setNormalPrice: [NSString stringWithFormat:@"%d,%02d",[[[self response] substringWithRange:NSMakeRange(24 + currentSale*SALE_STRING_LENGTH, 2)] intValue],[[[self response] substringWithRange:NSMakeRange(26 + currentSale*SALE_STRING_LENGTH, 2)] intValue]]];
+ NSLog(@"normalPrice: %@",[sale normalPrice]);
+ [sale setDiscountedPrice: [NSString stringWithFormat:@"%d,%02d",[[[self response] substringWithRange:NSMakeRange(28 + currentSale*SALE_STRING_LENGTH, 2)] intValue],[[[self response] substringWithRange:NSMakeRange(30 + currentSale*SALE_STRING_LENGTH, 2)] intValue]]];
+ NSLog(@"discountedPrice: %@",[sale discountedPrice]);
+ [[sale moneyReturned] insertObject:[NSNumber numberWithInt:[[[self response] substringWithRange:NSMakeRange(32 + currentSale*SALE_STRING_LENGTH, 2)] intValue]] atIndex:0];
+ [[sale moneyReturned] insertObject:[NSNumber numberWithInt:[[[self response] substringWithRange:NSMakeRange(34 + currentSale*SALE_STRING_LENGTH , 2)] intValue]] atIndex:1];
+ NSLog(@"moneyReturned: %@",[sale moneyReturned]);
+ [[self sales] insertObject:sale atIndex:currentSale];
+ currentSale++;
+ }
+ NSLog(@"%@",[self sales]);
}
@end
diff --git a/DUREX Vendor Control/en.lproj/Localizable.strings b/DUREX Vendor Control/en.lproj/Localizable.strings
index f635f11..0fbeb31 100644
--- a/DUREX Vendor Control/en.lproj/Localizable.strings
+++ b/DUREX Vendor Control/en.lproj/Localizable.strings
@@ -76,6 +76,7 @@
"Product Code" = "Product Code";
"Normal Price" = "Normal Price";
"Discounted Price" = "Discounted Price";
+"Money Paid" = "Money Paid";
"1€ Change" = "1€ Change";
"50c Change" = "50c Change";
"Update Date & Time" = "Update Date & Time";
diff --git a/DUREX Vendor Control/es.lproj/Localizable.strings b/DUREX Vendor Control/es.lproj/Localizable.strings
index cf09c07..1024332 100644
--- a/DUREX Vendor Control/es.lproj/Localizable.strings
+++ b/DUREX Vendor Control/es.lproj/Localizable.strings
@@ -76,6 +76,7 @@
"Product Code" = "Código del producto";
"Normal Price" = "Precio Normal";
"Discounted Price" = "Precio con descuento";
+"Money Paid" = "Efectivo Pagado";
"1€ Change" = "Cambio de 1€";
"50c Change" = "Cambio de 50c";
"Update Date & Time" = "Actualizar fecha y hora";
diff --git a/TODO b/TODO
index c6a04fd..77b1d47 100644
--- a/TODO
+++ b/TODO
@@ -3,12 +3,13 @@ BUGS:
- On date change, response is overwritten by previous query, trimming needed according to numBytes
- Sanitize input on name/price change
- Seemingly random crashes
+- Month headers on sale list
TODO:
-- A2 command
-- Sale parser
-- Generate view
+- Populate sale list with dates
+- On select any date, generate navlevel with index in salesLog
+- Generate sale navLevel
- Implement sensor status logging and sending to remote server
- Lewis infrastructure for data viewing (SQL, Webpage, CSV parser)