|
|
@@ -2584,4 +2584,136 @@
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
+#pragma mark - Jack
|
|
|
+
|
|
|
+#pragma mark create new contact
|
|
|
++ (NSDictionary *)offline_getAllCountry {
|
|
|
+// "val_227" : {
|
|
|
+// "check" : 1,
|
|
|
+// "value" : "US United States",
|
|
|
+// "value_id" : "228"
|
|
|
+// },
|
|
|
+
|
|
|
+ NSMutableDictionary *dic = [NSMutableDictionary dictionary];
|
|
|
+ sqlite3 *db = [iSalesDB get_db];
|
|
|
+
|
|
|
+ const char *sqlQuery = "select * from offline_country;";
|
|
|
+ sqlite3_stmt * statement;
|
|
|
+
|
|
|
+ if (sqlite3_prepare_v2(db, sqlQuery, -1, &statement, nil) == SQLITE_OK) {
|
|
|
+
|
|
|
+ while (sqlite3_step(statement) == SQLITE_ROW) {
|
|
|
+ char *name = (char *) sqlite3_column_text(statement, 1);
|
|
|
+ char *code = (char *) sqlite3_column_text(statement, 2);
|
|
|
+
|
|
|
+ NSMutableDictionary *countryDic = [NSMutableDictionary dictionaryWithCapacity:2];
|
|
|
+ [countryDic setValue:[NSString stringWithUTF8String:name] forKey:@"value"];
|
|
|
+ [countryDic setValue:[NSString stringWithUTF8String:code] forKey:@"value_id"];
|
|
|
+ [countryDic setValue:[NSNumber numberWithInt:0] forKey:@"check"];
|
|
|
+
|
|
|
+ NSString *key = [NSString stringWithFormat:@"val_%d",[[NSString stringWithUTF8String:code] integerValue] - 1];
|
|
|
+ [dic setValue:countryDic forKey:key];
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlite3_finalize(statement);
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlite3_close(db);
|
|
|
+ return dic;
|
|
|
+}
|
|
|
+
|
|
|
++ (NSDictionary *)offline_getStateByCountryCode:(NSString *)countryCode {
|
|
|
+
|
|
|
+ NSMutableDictionary *dic = [NSMutableDictionary dictionary];
|
|
|
+
|
|
|
+ sqlite3 *db = [iSalesDB get_db];
|
|
|
+
|
|
|
+ NSString *sqlQuery = [NSString stringWithFormat:@"select * from offline_state where country_code = %@;",countryCode];
|
|
|
+ sqlite3_stmt * statement;
|
|
|
+
|
|
|
+ if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK) {
|
|
|
+ int i = 0;
|
|
|
+ while (sqlite3_step(statement) == SQLITE_ROW) {
|
|
|
+ char *name = (char *) sqlite3_column_text(statement, 1); // value
|
|
|
+ char *code = (char *) sqlite3_column_text(statement, 2); // value_id
|
|
|
+
|
|
|
+ NSMutableDictionary *stateDic = [NSMutableDictionary dictionaryWithCapacity:2];
|
|
|
+ [stateDic setValue:[NSString stringWithUTF8String:name] forKey:@"value"];
|
|
|
+ [stateDic setValue:[NSString stringWithUTF8String:code] forKey:@"value_id"];
|
|
|
+ [stateDic setValue:[NSNumber numberWithInt:0] forKey:@"check"];
|
|
|
+
|
|
|
+ NSString *key = [NSString stringWithFormat:@"val_%d",i++];
|
|
|
+ [dic setValue:stateDic forKey:key];
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlite3_finalize(statement);
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlite3_close(db);
|
|
|
+ return dic;
|
|
|
+}
|
|
|
+
|
|
|
++ (NSDictionary *)offline_getPrice {
|
|
|
+ NSMutableDictionary *priceDic = [NSMutableDictionary dictionary];
|
|
|
+
|
|
|
+ sqlite3 *db = [iSalesDB get_db];
|
|
|
+ NSString *sqlQuery = [NSString stringWithFormat:@"select * from price;"];
|
|
|
+ sqlite3_stmt * statement;
|
|
|
+
|
|
|
+ if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK) {
|
|
|
+ while (sqlite3_step(statement) == SQLITE_ROW) {
|
|
|
+ char *name = (char *) sqlite3_column_text(statement, 1);
|
|
|
+ int type = sqlite3_column_int(statement, 2);
|
|
|
+ int orderBy = sqlite3_column_int(statement, 3);
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlite3_finalize(statement);
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlite3_close(db);
|
|
|
+ return priceDic;
|
|
|
+}
|
|
|
+
|
|
|
++ (NSDictionary *)offline_createContact:(NSMutableDictionary *)params {
|
|
|
+
|
|
|
+ NSString *path = [[NSBundle mainBundle] pathForResource:@"createContact.json" ofType:nil];
|
|
|
+ NSData *data = [NSData dataWithContentsOfFile:path];
|
|
|
+ NSMutableDictionary *ret = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil] mutableCopy];
|
|
|
+
|
|
|
+ // country
|
|
|
+ NSDictionary *allCountry = [self offline_getAllCountry];
|
|
|
+
|
|
|
+ NSString *key = nil;
|
|
|
+ NSString *countryCode = nil;
|
|
|
+ if ([params.allKeys containsObject:@"refresh_trigger"]) {
|
|
|
+ if([params[@"refresh_trigger"] isEqualToString:@"country"]) { // choose country
|
|
|
+ countryCode = params[@"country"];
|
|
|
+ key = [NSString stringWithFormat:@"val_%d",[countryCode integerValue] - 1];
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // default: US United States
|
|
|
+ key = @"val_227";
|
|
|
+ countryCode = @"228";
|
|
|
+ }
|
|
|
+
|
|
|
+ NSMutableDictionary *country = [allCountry objectForKey:key];
|
|
|
+ [country setValue:[NSNumber numberWithInt:1] forKey:@"check"];
|
|
|
+
|
|
|
+ NSDictionary *section_0 = [ret objectForKey:@"section_0"];
|
|
|
+ NSDictionary *item_country = [section_0 objectForKey:@"item_5"];
|
|
|
+ [item_country setValue:allCountry forKey:@"cadedate"];
|
|
|
+
|
|
|
+ // state
|
|
|
+ NSDictionary *allState = [self offline_getStateByCountryCode:countryCode];
|
|
|
+ NSMutableDictionary *item_state = [section_0 objectForKey:@"item_11"];
|
|
|
+ [item_state setValue:allState forKey:@"cadedate"];
|
|
|
+
|
|
|
+ // price type
|
|
|
+
|
|
|
+
|
|
|
+ // Sales Rep
|
|
|
+
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
@end
|