|
@@ -11,6 +11,7 @@
|
|
|
#import "RAUtils.h"
|
|
#import "RAUtils.h"
|
|
|
#import "AESCrypt.h"
|
|
#import "AESCrypt.h"
|
|
|
#import "AppDelegate.h"
|
|
#import "AppDelegate.h"
|
|
|
|
|
+#import "iSalesDB+JKDB.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
@interface OLDataProvider ()
|
|
@interface OLDataProvider ()
|
|
@@ -2701,6 +2702,28 @@
|
|
|
sqlite3_close(db);
|
|
sqlite3_close(db);
|
|
|
[dic setValue:[NSNumber numberWithInt:dic.allKeys.count] forKey:@"count"];
|
|
[dic setValue:[NSNumber numberWithInt:dic.allKeys.count] forKey:@"count"];
|
|
|
return dic;
|
|
return dic;
|
|
|
|
|
+
|
|
|
|
|
+// NSDictionary *ret = [iSalesDB jk_query:@"select _id,name,code,countrycode_id from offline_country;" completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container,long *count) {
|
|
|
|
|
+// char *name = (char *) sqlite3_column_text(stmt, 1); // 全称
|
|
|
|
|
+// char *code = (char *) sqlite3_column_text(stmt, 2); // 缩写
|
|
|
|
|
+// int code_id = sqlite3_column_int(stmt, 3); // id
|
|
|
|
|
+//
|
|
|
|
|
+// NSMutableDictionary *countryDic = [NSMutableDictionary dictionaryWithCapacity:2];
|
|
|
|
|
+// [countryDic setValue:[NSString stringWithFormat:@"%s",name] forKey:@"value"];
|
|
|
|
|
+// [countryDic setValue:[NSString stringWithFormat:@"%d",code_id] forKey:@"value_id"];
|
|
|
|
|
+// [countryDic setValue:[NSNumber numberWithInt:0] forKey:@"check"];
|
|
|
|
|
+//
|
|
|
|
|
+// if ([countryCode isEqualToString:[NSString stringWithUTF8String:code]]) {
|
|
|
|
|
+// [countryDic setValue:[NSNumber numberWithInt:1] forKey:@"check"];
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// long n = *count;
|
|
|
|
|
+// *count = n + 1;
|
|
|
|
|
+// NSString *key = [NSString stringWithFormat:@"val_%ld",n];
|
|
|
|
|
+// [container setValue:countryDic forKey:key];
|
|
|
|
|
+// }];
|
|
|
|
|
+//
|
|
|
|
|
+// return [ret copy];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ (NSDictionary *)offline_getStateByCountryCode:(NSString *)countryCode checkedState:(NSString *)state_code{
|
|
+ (NSDictionary *)offline_getStateByCountryCode:(NSString *)countryCode checkedState:(NSString *)state_code{
|
|
@@ -2935,10 +2958,7 @@
|
|
|
{
|
|
{
|
|
|
return nil;
|
|
return nil;
|
|
|
}
|
|
}
|
|
|
-+(NSData *) offline_saveNewContact:(NSMutableDictionary *) params
|
|
|
|
|
-{
|
|
|
|
|
- return nil;
|
|
|
|
|
-}
|
|
|
|
|
|
|
+
|
|
|
+ (NSData *)offline_createContact:(NSMutableDictionary *)params {
|
|
+ (NSData *)offline_createContact:(NSMutableDictionary *)params {
|
|
|
|
|
|
|
|
NSString *path = [[NSBundle mainBundle] pathForResource:@"createContact.json" ofType:nil];
|
|
NSString *path = [[NSBundle mainBundle] pathForResource:@"createContact.json" ofType:nil];
|
|
@@ -3020,5 +3040,151 @@
|
|
|
return [RAUtils dict2data:ret];
|
|
return [RAUtils dict2data:ret];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+#pragma mark save new contact
|
|
|
|
|
+
|
|
|
|
|
++ (NSString *)countryNameByCountryCodeId:(NSString *)codeId {
|
|
|
|
|
+
|
|
|
|
|
+ NSString *name = nil;
|
|
|
|
|
+
|
|
|
|
|
+ sqlite3 *db = [iSalesDB get_db];
|
|
|
|
|
+ NSString *sqlQuery = [NSString stringWithFormat:@"select name from offline_country where countrycode_id = %@",codeId];
|
|
|
|
|
+ sqlite3_stmt * statement;
|
|
|
|
|
+
|
|
|
|
|
+ if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK) {
|
|
|
|
|
+ while (sqlite3_step(statement) == SQLITE_ROW) {
|
|
|
|
|
+ char *value = (char *)sqlite3_column_text(statement, 0);
|
|
|
|
|
+ name = [NSString stringWithUTF8String:value];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ sqlite3_finalize(statement);
|
|
|
|
|
+ }
|
|
|
|
|
+ sqlite3_close(db);
|
|
|
|
|
+
|
|
|
|
|
+ return name;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
++ (NSString *)priceNameByPriceId:(NSString *)priceId {
|
|
|
|
|
+
|
|
|
|
|
+ NSString *ret = nil;
|
|
|
|
|
+
|
|
|
|
|
+ sqlite3 *db = [iSalesDB get_db];
|
|
|
|
|
+ NSString *sqlQuery = [NSString stringWithFormat:@"select name from price where order_by = %@;",priceId];
|
|
|
|
|
+ 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, 0);
|
|
|
|
|
+ ret = [NSString stringWithUTF8String:name];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ sqlite3_finalize(statement);
|
|
|
|
|
+ }
|
|
|
|
|
+ sqlite3_close(db);
|
|
|
|
|
+
|
|
|
|
|
+ return ret;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
++ (NSString *)salesRepCodeById:(NSString *)_id {
|
|
|
|
|
+
|
|
|
|
|
+ NSString *ret = nil;
|
|
|
|
|
+
|
|
|
|
|
+ sqlite3 *db = [iSalesDB get_db];
|
|
|
|
|
+ NSString *sqlQuery = [NSString stringWithFormat:@"select code from offline_salesrep where salesrep_id = %@",_id];
|
|
|
|
|
+ sqlite3_stmt * statement;
|
|
|
|
|
+
|
|
|
|
|
+ if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK) {
|
|
|
|
|
+ while (sqlite3_step(statement) == SQLITE_ROW) {
|
|
|
|
|
+ char *rep = (char *)sqlite3_column_text(statement, 0);
|
|
|
|
|
+ ret = [NSString stringWithUTF8String:rep];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ sqlite3_finalize(statement);
|
|
|
|
|
+ }
|
|
|
|
|
+ sqlite3_close(db);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ return ret;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
++(NSData *) offline_saveNewContact:(NSMutableDictionary *) params
|
|
|
|
|
+{
|
|
|
|
|
+// {
|
|
|
|
|
+//
|
|
|
|
|
+// password = 123456;
|
|
|
|
|
+// "price_name" = 0;
|
|
|
|
|
+// "sales_rep" = 121;
|
|
|
|
|
+
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
|
|
+ NSLog(@"%@",params);
|
|
|
|
|
+ NSString *companyName = [params objectForKey:@"company"];
|
|
|
|
|
+ if (companyName) {
|
|
|
|
|
+ companyName = [AESCrypt fastencrypt:companyName];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ NSString *addr1 = [params objectForKey:@"address"];
|
|
|
|
|
+ if (addr1) {
|
|
|
|
|
+ addr1 = [AESCrypt fastencrypt:addr1];
|
|
|
|
|
+ }
|
|
|
|
|
+ NSString *addr2 = [params objectForKey:@"address2"];
|
|
|
|
|
+ if (addr2) {
|
|
|
|
|
+ addr2 = [AESCrypt fastencrypt:addr2];
|
|
|
|
|
+ }
|
|
|
|
|
+ NSString *addr3 = [params objectForKey:@"address_3"];
|
|
|
|
|
+ if (addr3) {
|
|
|
|
|
+ addr3 = [AESCrypt fastencrypt:addr3];
|
|
|
|
|
+ }
|
|
|
|
|
+ NSString *addr4 = [params objectForKey:@"address_4"];
|
|
|
|
|
+ if (addr4) {
|
|
|
|
|
+ addr4 = [AESCrypt fastencrypt:addr4];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ NSString *country = [params objectForKey:@"country"];
|
|
|
|
|
+ if (country) {
|
|
|
|
|
+ country = [self countryNameByCountryCodeId:country];
|
|
|
|
|
+ }
|
|
|
|
|
+ NSString *state = [params objectForKey:@"state"];
|
|
|
|
|
+ NSString *city = [params objectForKey:@"city"];
|
|
|
|
|
+ NSString *zipcode = [params objectForKey:@"zipcode"];
|
|
|
|
|
+
|
|
|
|
|
+ NSString *fistName = [params objectForKey:@"firstname"];
|
|
|
|
|
+ NSString *lastName = [params objectForKey:@"lastname"];
|
|
|
|
|
+
|
|
|
|
|
+ NSString *phone = [params objectForKey:@"phone"];
|
|
|
|
|
+ if (phone) {
|
|
|
|
|
+ phone = [AESCrypt fastencrypt:phone];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ NSString *fax = [params objectForKey:@"fax"];
|
|
|
|
|
+ NSString *email = [params objectForKey:@"email"];
|
|
|
|
|
+
|
|
|
|
|
+ NSString *notes = [params objectForKey:@"contact_notes"];
|
|
|
|
|
+
|
|
|
|
|
+ NSString *price = [params objectForKey:@"price_name"];
|
|
|
|
|
+ if (price) {
|
|
|
|
|
+ price = [self priceNameByPriceId:price];
|
|
|
|
|
+ }
|
|
|
|
|
+ NSString *salesRep = [params objectForKey:@"sales_rep"];
|
|
|
|
|
+ if (salesRep) {
|
|
|
|
|
+ salesRep = [self salesRepCodeById:salesRep];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ NSString *img = [params objectForKey:@"business_card"];
|
|
|
|
|
+ NSArray *array = [img componentsSeparatedByString:@","];
|
|
|
|
|
+ NSString *img_0 = array[0];
|
|
|
|
|
+ NSString *img_1 = array[1];
|
|
|
|
|
+ NSString *img_2 = array[2];
|
|
|
|
|
+
|
|
|
|
|
+ NSString *contact_id = [NSUUID UUID].UUIDString;
|
|
|
|
|
+
|
|
|
|
|
+ NSString *sql = [NSString stringWithFormat:@"insert into offline_contact (company_name,addr_1,addr_2,addr_3,addr_4,country,state,city,zipcode,first_name,last_name,phone,fax,email,notes,price_type,sales_rep,img_0,img_1,img_2,editable,contact_id) values ('%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@',1,'%@')",companyName,addr1,addr2,addr3,addr4,country,state,city,zipcode,fistName,lastName,phone,fax,email,notes,price,salesRep,img_0,img_1,img_2,contact_id];
|
|
|
|
|
+
|
|
|
|
|
+ int result = [iSalesDB jk_execSql:sql withDatabase:YES];
|
|
|
|
|
+
|
|
|
|
|
+ NSString *retStr = [NSString stringWithFormat:@"{\"result\":%d,\"min_ver\":\"160409\",\"mode\":\"Regular Mode\"}",result];
|
|
|
|
|
+
|
|
|
|
|
+ return [retStr dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
|
|
|
@end
|
|
@end
|