|
@@ -3072,14 +3072,7 @@
|
|
|
|
|
|
|
|
return ret;
|
|
return ret;
|
|
|
}
|
|
}
|
|
|
-+(NSData *) offline_saveContact:(NSMutableDictionary *) params
|
|
|
|
|
-{
|
|
|
|
|
- return nil;
|
|
|
|
|
-}
|
|
|
|
|
-+(NSData *) offline_editContact:(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];
|
|
@@ -3089,7 +3082,6 @@
|
|
|
NSMutableDictionary *section_0 = [[ret objectForKey:@"section_0"] mutableCopy];
|
|
NSMutableDictionary *section_0 = [[ret objectForKey:@"section_0"] mutableCopy];
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
NSString *countryCode = nil;
|
|
NSString *countryCode = nil;
|
|
|
NSString *countryCode_id = nil;
|
|
NSString *countryCode_id = nil;
|
|
|
NSString *stateCode = nil;
|
|
NSString *stateCode = nil;
|
|
@@ -3161,6 +3153,85 @@
|
|
|
return [RAUtils dict2data:ret];
|
|
return [RAUtils dict2data:ret];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+#pragma mark save
|
|
|
|
|
+
|
|
|
|
|
++ (NSData *)offline_saveContact:(NSDictionary *)params update:(BOOL)update {
|
|
|
|
|
+
|
|
|
|
|
+ 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 = nil;
|
|
|
|
|
+ if (update){
|
|
|
|
|
+ contact_id = [params objectForKey:@"contact_id"];
|
|
|
|
|
+ sql = [NSString stringWithFormat:@"update offline_contact set 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 = '%@' where contact_id = '%@';",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];
|
|
|
|
|
+ } else
|
|
|
|
|
+ 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,Sales_Order_Customer,Sales_Order_Freight_Bill_To,Sales_Order_Ship_From,Sales_Order_Merchandise_Bill_To,Contact_Return_To,Sales_Order_Ship_To) values ('%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@',1,'%@',1,1,0,1,0,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 execSql:sql];
|
|
|
|
|
+
|
|
|
|
|
+ NSString *retStr = [NSString stringWithFormat:@"{\"result\":%d,\"min_ver\":\"160409\",\"mode\":\"Regular Mode\"}",result];
|
|
|
|
|
+
|
|
|
|
|
+ return [retStr dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
#pragma mark save new contact
|
|
#pragma mark save new contact
|
|
|
|
|
|
|
|
+ (NSString *)countryNameByCountryCodeId:(NSString *)codeId {
|
|
+ (NSString *)countryNameByCountryCodeId:(NSString *)codeId {
|
|
@@ -3230,75 +3301,301 @@
|
|
|
+(NSData *) offline_saveNewContact:(NSMutableDictionary *) params
|
|
+(NSData *) offline_saveNewContact:(NSMutableDictionary *) params
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
- 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];
|
|
|
|
|
|
|
+// NSLog(@"%@",params);
|
|
|
|
|
+// NSString *companyName = [params objectForKey:@"company"];
|
|
|
|
|
+// if (companyName) {
|
|
|
|
|
+// companyName = [AESCrypt fastencrypt:companyName];
|
|
|
// }
|
|
// }
|
|
|
- NSString *addr3 = [params objectForKey:@"address_3"];
|
|
|
|
|
-// if (addr3) {
|
|
|
|
|
-// addr3 = [AESCrypt fastencrypt:addr3];
|
|
|
|
|
|
|
+//
|
|
|
|
|
+// NSString *addr1 = [params objectForKey:@"address"];
|
|
|
|
|
+// if (addr1) {
|
|
|
|
|
+// addr1 = [AESCrypt fastencrypt:addr1];
|
|
|
// }
|
|
// }
|
|
|
- NSString *addr4 = [params objectForKey:@"address_4"];
|
|
|
|
|
-// if (addr4) {
|
|
|
|
|
-// addr4 = [AESCrypt fastencrypt:addr4];
|
|
|
|
|
|
|
+// 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,Sales_Order_Customer,Sales_Order_Freight_Bill_To,Sales_Order_Ship_From,Sales_Order_Merchandise_Bill_To,Contact_Return_To,Sales_Order_Ship_To) values ('%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@',1,'%@',1,1,0,1,0,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];
|
|
|
|
|
+// int result = [iSalesDB execSql:sql];
|
|
|
|
|
+//
|
|
|
|
|
+// NSString *retStr = [NSString stringWithFormat:@"{\"result\":%d,\"min_ver\":\"160409\",\"mode\":\"Regular Mode\"}",result];
|
|
|
|
|
+//
|
|
|
|
|
+// return [retStr dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
|
|
|
|
- NSString *country = [params objectForKey:@"country"];
|
|
|
|
|
- if (country) {
|
|
|
|
|
- country = [self countryNameByCountryCodeId:country];
|
|
|
|
|
|
|
+ return [self offline_saveContact:params update:NO];
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+#pragma mark edit contact
|
|
|
|
|
+
|
|
|
|
|
++ (NSString *)textAtColumn:(int)col statement:(sqlite3_stmt *)stmt{
|
|
|
|
|
+ NSString *text = [NSString stringWithFormat:@"%s",(char *)sqlite3_column_text(stmt, col)];
|
|
|
|
|
+ if (!text) {
|
|
|
|
|
+ text = @"";
|
|
|
}
|
|
}
|
|
|
- NSString *state = [params objectForKey:@"state"];
|
|
|
|
|
- NSString *city = [params objectForKey:@"city"];
|
|
|
|
|
- NSString *zipcode = [params objectForKey:@"zipcode"];
|
|
|
|
|
|
|
+ return text;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
++(NSData *) offline_editContact:(NSMutableDictionary *) params
|
|
|
|
|
+{
|
|
|
|
|
+// {
|
|
|
|
|
+// "contact_id" = "CE0D2445-3C1F-40EC-B94C-A39A6900FBDA";
|
|
|
|
|
+// password = 123456;
|
|
|
|
|
+// user = EvanK;
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
- NSString *fistName = [params objectForKey:@"firstname"];
|
|
|
|
|
- NSString *lastName = [params objectForKey:@"lastname"];
|
|
|
|
|
|
|
+ NSString *path = [[NSBundle mainBundle] pathForResource:@"editContact.json" ofType:nil];
|
|
|
|
|
+ NSData *data = [NSData dataWithContentsOfFile:path];
|
|
|
|
|
+ NSMutableDictionary *ret = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil] mutableCopy];
|
|
|
|
|
|
|
|
- NSString *phone = [params objectForKey:@"phone"];
|
|
|
|
|
|
|
+ NSMutableDictionary *section_0 = [[ret objectForKey:@"section_0"] mutableCopy];
|
|
|
|
|
+
|
|
|
|
|
+ NSString *countryCode = nil;
|
|
|
|
|
+ NSString *countryCode_id = nil;
|
|
|
|
|
+ NSString *stateCode = nil;
|
|
|
|
|
+
|
|
|
|
|
+ /*------contact infor------*/
|
|
|
|
|
+ __block NSString *country = nil;
|
|
|
|
|
+ __block NSString *company_name = nil;
|
|
|
|
|
+ __block NSString *contact_id = params[@"contact_id"];
|
|
|
|
|
+
|
|
|
|
|
+ __block NSString *addr_1,*addr_2,*addr_3,*addr_4;
|
|
|
|
|
+ __block NSString *zipcode = nil;
|
|
|
|
|
+ __block NSString *state = nil; // state_code
|
|
|
|
|
+ __block NSString *city = nil; //
|
|
|
|
|
+ __block NSString *firt_name,*last_name;
|
|
|
|
|
+ __block NSString *phone,*fax,*email;
|
|
|
|
|
+ __block NSString *notes,*price_type,*sales_rep;
|
|
|
|
|
+ __block NSString *img_0,*img_1,*img_2;
|
|
|
|
|
+
|
|
|
|
|
+ NSString *sql = [NSString stringWithFormat:@"select country,company_name,addr_1,addr_2,addr_3,addr_4,zipcode,state,city,first_name,last_name,phone,fax,email,notes,price_type,sales_rep,img_0,img_1,img_2 from offline_contact where contact_id = '%@';",contact_id];
|
|
|
|
|
+
|
|
|
|
|
+ [iSalesDB jk_query:sql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
|
|
|
|
|
+
|
|
|
|
|
+ country = [self textAtColumn:0 statement:stmt]; // country name
|
|
|
|
|
+ company_name = [self textAtColumn:1 statement:stmt];
|
|
|
|
|
+ addr_1 = [self textAtColumn:2 statement:stmt];
|
|
|
|
|
+ addr_2 = [self textAtColumn:3 statement:stmt];
|
|
|
|
|
+ addr_3 = [self textAtColumn:4 statement:stmt];
|
|
|
|
|
+ addr_4 = [self textAtColumn:5 statement:stmt];
|
|
|
|
|
+ zipcode = [self textAtColumn:6 statement:stmt];
|
|
|
|
|
+ state = [self textAtColumn:7 statement:stmt]; // state code
|
|
|
|
|
+ city = [self textAtColumn:8 statement:stmt];
|
|
|
|
|
+ firt_name = [self textAtColumn:9 statement:stmt];
|
|
|
|
|
+ last_name = [self textAtColumn:10 statement:stmt];
|
|
|
|
|
+ phone = [self textAtColumn:11 statement:stmt];
|
|
|
|
|
+ fax = [self textAtColumn:12 statement:stmt];
|
|
|
|
|
+ email = [self textAtColumn:13 statement:stmt];
|
|
|
|
|
+ notes = [self textAtColumn:14 statement:stmt];
|
|
|
|
|
+ price_type = [self textAtColumn:15 statement:stmt]; // name
|
|
|
|
|
+ sales_rep = [self textAtColumn:16 statement:stmt]; // code
|
|
|
|
|
+ img_0 = [self textAtColumn:17 statement:stmt];
|
|
|
|
|
+ img_1 = [self textAtColumn:18 statement:stmt];
|
|
|
|
|
+ img_2 = [self textAtColumn:19 statement:stmt];
|
|
|
|
|
+
|
|
|
|
|
+ }];
|
|
|
|
|
+
|
|
|
|
|
+ // decrypt
|
|
|
|
|
+ if (company_name) {
|
|
|
|
|
+ company_name = [AESCrypt fastdecrypt:company_name];
|
|
|
|
|
+ }
|
|
|
|
|
+ if (addr_1) {
|
|
|
|
|
+ addr_1 = [AESCrypt fastdecrypt:addr_1];
|
|
|
|
|
+ }
|
|
|
if (phone) {
|
|
if (phone) {
|
|
|
- phone = [AESCrypt fastencrypt:phone];
|
|
|
|
|
|
|
+ phone = [AESCrypt fastdecrypt:phone];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- NSString *fax = [params objectForKey:@"fax"];
|
|
|
|
|
- NSString *email = [params objectForKey:@"email"];
|
|
|
|
|
|
|
+ NSString *countrySql = [NSString stringWithFormat:@"select code from offline_country where name = '%@';",country];
|
|
|
|
|
+ countryCode = [iSalesDB jk_queryText:countrySql];
|
|
|
|
|
|
|
|
- NSString *notes = [params objectForKey:@"contact_notes"];
|
|
|
|
|
|
|
+ stateCode = state;
|
|
|
|
|
|
|
|
- NSString *price = [params objectForKey:@"price_name"];
|
|
|
|
|
- if (price) {
|
|
|
|
|
- price = [self priceNameByPriceId:price];
|
|
|
|
|
- }
|
|
|
|
|
- NSString *salesRep = [params objectForKey:@"sales_rep"];
|
|
|
|
|
- if (salesRep) {
|
|
|
|
|
- salesRep = [self salesRepCodeById:salesRep];
|
|
|
|
|
|
|
+ if ([params.allKeys containsObject:@"refresh_trigger"]) {
|
|
|
|
|
+
|
|
|
|
|
+ if ([params[@"refresh_trigger"] isEqualToString:@"country"]) {
|
|
|
|
|
+
|
|
|
|
|
+ NSString *code_id = params[@"country"];
|
|
|
|
|
+ countryCode_id = code_id;
|
|
|
|
|
+ countryCode = [self countryCodeByid:code_id];
|
|
|
|
|
+
|
|
|
|
|
+ } else if ([params[@"refresh_trigger"] isEqualToString:@"zipcode"]) {
|
|
|
|
|
+
|
|
|
|
|
+ NSString *zip_code = params[@"zipcode"];
|
|
|
|
|
+ zipcode = zip_code;
|
|
|
|
|
+
|
|
|
|
|
+ countryCode_id = params[@"country"];
|
|
|
|
|
+
|
|
|
|
|
+ NSDictionary *dic = [self offline_dealZipCode:zip_code];
|
|
|
|
|
+
|
|
|
|
|
+ countryCode = [dic valueForKey:@"country_code"];
|
|
|
|
|
+
|
|
|
|
|
+ stateCode = [dic valueForKey:@"state_code"];
|
|
|
|
|
+
|
|
|
|
|
+ city = [dic valueForKey:@"city"];
|
|
|
|
|
+
|
|
|
|
|
+ // zip code
|
|
|
|
|
+ NSMutableDictionary *zipDic = [[section_0 valueForKey:@"item_8"] mutableCopy];
|
|
|
|
|
+ [zipDic setValue:zipcode forKey:@"value"];
|
|
|
|
|
+ [section_0 setValue:zipDic forKey:@"item_8"];
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- 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];
|
|
|
|
|
|
|
+// 0 Country
|
|
|
|
|
+// 1 Company Name
|
|
|
|
|
+// 2 Contact ID
|
|
|
|
|
+// 3 Picture
|
|
|
|
|
+// 4 Address 1
|
|
|
|
|
+// 5 Address 2
|
|
|
|
|
+// 6 Address 3
|
|
|
|
|
+// 7 Address 4
|
|
|
|
|
+// 8 Zip Code
|
|
|
|
|
+// 9 State/Province
|
|
|
|
|
+// 10 City
|
|
|
|
|
+// 11 Contact First Name
|
|
|
|
|
+// 12 Contact Last Name
|
|
|
|
|
+// 13 Phone
|
|
|
|
|
+// 14 Fax
|
|
|
|
|
+// 15 Email
|
|
|
|
|
+// 16 Contact Notes
|
|
|
|
|
+// 17 Price Type
|
|
|
|
|
+// 18 Sales Rep
|
|
|
|
|
+
|
|
|
|
|
+ // country
|
|
|
|
|
+ NSDictionary *allCountry = [self offline_getAllCountryDefault:countryCode];
|
|
|
|
|
+ [self setValue:allCountry forItemKey:@"item_0" valueKey:@"cadedate" inDictionary:section_0];
|
|
|
|
|
|
|
|
- NSString *contact_id = [NSUUID UUID].UUIDString;
|
|
|
|
|
|
|
+ // company
|
|
|
|
|
+ [self setValue:company_name forItemKey:@"item_1" valueKey:@"value" inDictionary:section_0];
|
|
|
|
|
|
|
|
- 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,Sales_Order_Customer,Sales_Order_Freight_Bill_To,Sales_Order_Ship_From,Sales_Order_Merchandise_Bill_To,Contact_Return_To,Sales_Order_Ship_To) values ('%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@',1,'%@',1,1,0,1,0,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];
|
|
|
|
|
|
|
+ // contact_id
|
|
|
|
|
+ [self setValue:contact_id forItemKey:@"item_2" valueKey:@"value" inDictionary:section_0];
|
|
|
|
|
|
|
|
-// int result = [iSalesDB jk_execSql:sql withDatabase:YES];
|
|
|
|
|
- int result = [iSalesDB execSql:sql];
|
|
|
|
|
|
|
+ // picture
|
|
|
|
|
+ NSString *img_avalue = [NSString stringWithFormat:@"%@,%@,%@",img_0,img_1,img_2];
|
|
|
|
|
+ [self setValue:img_avalue forItemKey:@"item_3" valueKey:@"avalue" inDictionary:section_0];
|
|
|
|
|
+ [self setValue:img_0 forItemKey:@"item_3" valueKey:@"img_url_aname_0" inDictionary:section_0];
|
|
|
|
|
+ [self setValue:img_1 forItemKey:@"item_3" valueKey:@"img_url_aname_1" inDictionary:section_0];
|
|
|
|
|
+ [self setValue:img_2 forItemKey:@"item_3" valueKey:@"img_url_aname_2" inDictionary:section_0];
|
|
|
|
|
|
|
|
- NSString *retStr = [NSString stringWithFormat:@"{\"result\":%d,\"min_ver\":\"160409\",\"mode\":\"Regular Mode\"}",result];
|
|
|
|
|
|
|
+ // addr 1 2 3 4
|
|
|
|
|
+ [self setValue:addr_1 forItemKey:@"item_4" valueKey:@"value" inDictionary:section_0];
|
|
|
|
|
+ [self setValue:addr_2 forItemKey:@"item_5" valueKey:@"value" inDictionary:section_0];
|
|
|
|
|
+ [self setValue:addr_3 forItemKey:@"item_6" valueKey:@"value" inDictionary:section_0];
|
|
|
|
|
+ [self setValue:addr_4 forItemKey:@"item_7" valueKey:@"value" inDictionary:section_0];
|
|
|
|
|
|
|
|
- return [retStr dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
|
|
|
+ // zip code
|
|
|
|
|
+ [self setValue:zipcode forItemKey:@"item_8" valueKey:@"value" inDictionary:section_0];
|
|
|
|
|
+
|
|
|
|
|
+ // state
|
|
|
|
|
+ NSDictionary *allState = [self offline_getStateByCountryCode:countryCode checkedState:stateCode];
|
|
|
|
|
+ [self setValue:allState forItemKey:@"item_9" valueKey:@"cadedate" inDictionary:section_0];
|
|
|
|
|
+
|
|
|
|
|
+ // city
|
|
|
|
|
+ [self setValue:city forItemKey:@"item_10" valueKey:@"value" inDictionary:section_0];
|
|
|
|
|
+
|
|
|
|
|
+ // first last
|
|
|
|
|
+ [self setValue:firt_name forItemKey:@"item_11" valueKey:@"value" inDictionary:section_0];
|
|
|
|
|
+ [self setValue:last_name forItemKey:@"item_12" valueKey:@"value" inDictionary:section_0];
|
|
|
|
|
+
|
|
|
|
|
+ // phone fax email
|
|
|
|
|
+ [self setValue:phone forItemKey:@"item_13" valueKey:@"value" inDictionary:section_0];
|
|
|
|
|
+ [self setValue:fax forItemKey:@"item_14" valueKey:@"value" inDictionary:section_0];
|
|
|
|
|
+ [self setValue:email forItemKey:@"item_15" valueKey:@"value" inDictionary:section_0];
|
|
|
|
|
+
|
|
|
|
|
+ // notes
|
|
|
|
|
+ [self setValue:notes forItemKey:@"item_16" valueKey:@"value" inDictionary:section_0];
|
|
|
|
|
+
|
|
|
|
|
+ // price
|
|
|
|
|
+ NSMutableDictionary *priceDic = [[self offline_getPrice] mutableCopy];
|
|
|
|
|
+ for (NSString *key in priceDic.allKeys) {
|
|
|
|
|
+
|
|
|
|
|
+ if ([key containsString:@"val_"]) {
|
|
|
|
|
+ NSMutableDictionary *dic = [priceDic[key] mutableCopy];
|
|
|
|
|
+ if ([dic[@"value"] isEqualToString:price_type]) {
|
|
|
|
|
+ [dic setValue:[NSNumber numberWithInteger:1] forKey:@"check"];
|
|
|
|
|
+ [priceDic setValue:dic forKey:key];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ [self setValue:priceDic forItemKey:@"item_17" valueKey:@"cadedate" inDictionary:section_0];
|
|
|
|
|
+
|
|
|
|
|
+ // Sales Rep
|
|
|
|
|
+ NSMutableDictionary *repDic = [[self offline_getSalesRep] mutableCopy];
|
|
|
|
|
+ for (NSString *key in repDic.allKeys) {
|
|
|
|
|
+ if ([key containsString:@"val_"]) {
|
|
|
|
|
+ NSMutableDictionary *dic = [repDic[key] mutableCopy];
|
|
|
|
|
+ NSString *value = dic[@"value"];
|
|
|
|
|
+ NSString *code = [[[value componentsSeparatedByString:@"-"] firstObject] stringByReplacingOccurrencesOfString:@" " withString:@""];
|
|
|
|
|
+ if (code && [code isEqualToString:sales_rep]) {
|
|
|
|
|
+ [dic setValue:[NSNumber numberWithInteger:1] forKey:@"check"];
|
|
|
|
|
+ [repDic setValue:dic forKey:key];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ [self setValue:repDic forItemKey:@"item_18" valueKey:@"cadedate" inDictionary:section_0];
|
|
|
|
|
+
|
|
|
|
|
+ [ret setValue:section_0 forKey:@"section_0"];
|
|
|
|
|
+
|
|
|
|
|
+ return [RAUtils dict2data:ret];
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+#pragma mark - save contact
|
|
|
|
|
+
|
|
|
|
|
++(NSData *) offline_saveContact:(NSMutableDictionary *) params
|
|
|
|
|
+{
|
|
|
|
|
+ return [self offline_saveContact:params update:YES];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|