|
|
@@ -2302,7 +2302,7 @@
|
|
|
}
|
|
|
|
|
|
+ (NSDictionary *)offline_getStateByCountryCode:(NSString *)countryCode checkedState:(NSString *)state_code{
|
|
|
-
|
|
|
+ countryCode = [self translateSingleQuote:countryCode];
|
|
|
NSString *sqlQuery = [NSString stringWithFormat:@"select _id,name,code,country_code from offline_state where country_code = '%@';",countryCode];
|
|
|
|
|
|
NSMutableDictionary *ret = [[iSalesDB jk_query:sqlQuery completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
|
|
|
@@ -2338,6 +2338,7 @@
|
|
|
|
|
|
+ (NSDictionary *)offline_getStateByCountryCodeId:(NSString *)codeId checkedState:(NSString *)stateCode {
|
|
|
|
|
|
+ codeId = [self translateSingleQuote:codeId];
|
|
|
NSString *sql = [NSString stringWithFormat:@"select name,code from offline_state where country_code = (select code as country_code FROM offline_country where countrycode_id = %@);",codeId];
|
|
|
|
|
|
NSMutableDictionary *ret = [[iSalesDB jk_query:sql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
|
|
|
@@ -2406,6 +2407,23 @@
|
|
|
|
|
|
+ (NSDictionary *)offline_getSalesRep {
|
|
|
|
|
|
+ // 首先从offline_login表中取出sales_code
|
|
|
+ AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
|
|
+ NSString *user = app.user;
|
|
|
+ user = [self translateSingleQuote:user];
|
|
|
+ NSString *loginSql = [NSString stringWithFormat:@"select sales_code from offline_login where username = '%@'",user];
|
|
|
+ __block NSString *user_code = @"";
|
|
|
+ [iSalesDB jk_query:loginSql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
|
|
|
+ char *code = (char *)sqlite3_column_text(stmt, 0);
|
|
|
+ if (code == NULL) {
|
|
|
+ code = "";
|
|
|
+ }
|
|
|
+
|
|
|
+ user_code = [NSString stringWithUTF8String:code];
|
|
|
+
|
|
|
+ }];
|
|
|
+
|
|
|
+ // 再取所有salesRep
|
|
|
NSString *sql = [NSString stringWithFormat:@"select _id,name,code,salesrep_id from offline_salesrep;"];
|
|
|
NSMutableDictionary *ret = [[iSalesDB jk_query:sql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
|
|
|
|
|
|
@@ -2420,11 +2438,16 @@
|
|
|
if (code == NULL) {
|
|
|
code = "";
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
NSMutableDictionary *repDic = [NSMutableDictionary dictionary];
|
|
|
[repDic setValue:[NSString stringWithFormat:@"%s - %s",code,name] forKey:@"value"];
|
|
|
[repDic setValue:[NSNumber numberWithInt:salesrep_id] forKey:@"value_id"];
|
|
|
+ // 比较code 相等则check
|
|
|
+ if ([[NSString stringWithUTF8String:code] isEqualToString:user_code]) {
|
|
|
+ [repDic setValue:[NSNumber numberWithInt:1] forKey:@"check"];
|
|
|
+ }
|
|
|
+
|
|
|
[container setValue:repDic forKey:[NSString stringWithFormat:@"val_%ld",(*count)++]];
|
|
|
|
|
|
}] mutableCopy];
|
|
|
@@ -2436,6 +2459,7 @@
|
|
|
|
|
|
+ (NSDictionary *)offline_dealZipCode:(NSString *)zipcode {
|
|
|
|
|
|
+ zipcode = [self translateSingleQuote:zipcode];
|
|
|
NSString *sql = [NSString stringWithFormat:@"select country,state,city,country_code,state_code from offline_zipcode where zipcode = '%@';",zipcode];
|
|
|
|
|
|
NSMutableDictionary *ret = [[iSalesDB jk_query:sql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
|
|
|
@@ -2487,7 +2511,7 @@
|
|
|
+ (NSString *)countryCodeByid:(NSString *)code_id {
|
|
|
|
|
|
NSString *ret = nil;
|
|
|
-
|
|
|
+ code_id = [self translateSingleQuote:code_id];
|
|
|
sqlite3 *db = [iSalesDB get_db];
|
|
|
NSString *sqlQuery = [NSString stringWithFormat:@"select code from offline_country where countrycode_id = %@",code_id];
|
|
|
sqlite3_stmt * statement;
|
|
|
@@ -2511,7 +2535,7 @@
|
|
|
|
|
|
+ (NSString *)countryCodeIdByCode:(NSString *)code {
|
|
|
NSString *ret = nil;
|
|
|
-
|
|
|
+ code = [self translateSingleQuote:code];
|
|
|
sqlite3 *db = [iSalesDB get_db];
|
|
|
NSString *sqlQuery = [NSString stringWithFormat:@"select countrycode_id from offline_country where code = '%@';",code];
|
|
|
sqlite3_stmt * statement;
|
|
|
@@ -2535,7 +2559,7 @@
|
|
|
+ (NSString *)countryNameByCountryCodeId:(NSString *)codeId {
|
|
|
|
|
|
NSString *name = nil;
|
|
|
-
|
|
|
+ codeId = [self translateSingleQuote:codeId];
|
|
|
sqlite3 *db = [iSalesDB get_db];
|
|
|
NSString *sqlQuery = [NSString stringWithFormat:@"select name from offline_country where countrycode_id = %@",codeId];
|
|
|
sqlite3_stmt * statement;
|
|
|
@@ -2559,7 +2583,7 @@
|
|
|
+ (NSString *)priceNameByPriceId:(NSString *)priceId {
|
|
|
|
|
|
NSString *ret = nil;
|
|
|
-
|
|
|
+ priceId = [self translateSingleQuote:priceId];
|
|
|
sqlite3 *db = [iSalesDB get_db];
|
|
|
NSString *sqlQuery = [NSString stringWithFormat:@"select name from price where type = %@;",priceId];
|
|
|
sqlite3_stmt * statement;
|
|
|
@@ -2583,7 +2607,7 @@
|
|
|
+ (NSString *)salesRepCodeById:(NSString *)_id {
|
|
|
|
|
|
NSString *ret = nil;
|
|
|
-
|
|
|
+ _id = [self translateSingleQuote:_id];
|
|
|
sqlite3 *db = [iSalesDB get_db];
|
|
|
NSString *sqlQuery = [NSString stringWithFormat:@"select code from offline_salesrep where salesrep_id = %@",_id];
|
|
|
sqlite3_stmt * statement;
|
|
|
@@ -2665,18 +2689,21 @@
|
|
|
|
|
|
NSString* contact_name = [params valueForKey:@"contact_name"]; // "contact_name"
|
|
|
if (contact_name) {
|
|
|
+ contact_name = [contact_name stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
|
|
|
contact_name = [NSString stringWithFormat:@"and lower(contact_name) like '%%%@%%'",contact_name.lowercaseString];
|
|
|
} else {
|
|
|
contact_name = @"";
|
|
|
}
|
|
|
NSString* customer_phone = [params valueForKey:@"customer_phone"]; // "customer_phone"
|
|
|
if (customer_phone) {
|
|
|
+ customer_phone = [customer_phone stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
|
|
|
customer_phone = [NSString stringWithFormat:@"and lower(decrypt(phone)) like '%%%@%%'",customer_phone.lowercaseString];
|
|
|
} else {
|
|
|
customer_phone = @"";
|
|
|
}
|
|
|
NSString* customer_fax = [params valueForKey:@"customer_fax"]; // "customer_fax"
|
|
|
if (customer_fax) {
|
|
|
+ customer_fax = [customer_fax stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
|
|
|
customer_fax = [NSString stringWithFormat:@"and lower(fax) like '%%%@%%'",customer_fax.lowercaseString];
|
|
|
} else {
|
|
|
customer_fax = @"";
|
|
|
@@ -2684,54 +2711,63 @@
|
|
|
|
|
|
NSString* customer_zipcode = [params valueForKey:@"customer_zipcode"]; // "customer_zipcode"
|
|
|
if (customer_zipcode) {
|
|
|
+ customer_zipcode = [customer_zipcode stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
|
|
|
customer_zipcode = [NSString stringWithFormat:@"and lower(zipcode) like '%%%@%%'",customer_zipcode.lowercaseString];
|
|
|
} else {
|
|
|
customer_zipcode = @"";
|
|
|
}
|
|
|
NSString* customer_sales_rep = [params valueForKey:@"customer_sales_rep"]; // "customer_sales_rep"
|
|
|
if (customer_sales_rep) {
|
|
|
+ customer_zipcode = [customer_zipcode stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
|
|
|
customer_sales_rep = [NSString stringWithFormat:@"and lower(sales_rep) like '%%%@%%'",customer_sales_rep.lowercaseString];
|
|
|
} else {
|
|
|
customer_sales_rep = @"";
|
|
|
}
|
|
|
NSString* customer_state = [params valueForKey:@"customer_state"]; // "customer_state"
|
|
|
if (customer_state) {
|
|
|
+ customer_state = [customer_state stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
|
|
|
customer_state = [NSString stringWithFormat:@"and lower(state) like '%%%@%%'",customer_state.lowercaseString];
|
|
|
} else {
|
|
|
customer_state = @"";
|
|
|
}
|
|
|
NSString* customer_name = [params valueForKey:@"customer_name"]; // "customer_name" 也就是company name
|
|
|
if (customer_name) {
|
|
|
+ customer_name = [customer_name stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
|
|
|
customer_name = [NSString stringWithFormat:@"and lower(decrypt(company_name)) like '%%%@%%'",customer_name.lowercaseString];
|
|
|
} else {
|
|
|
customer_name = @"";
|
|
|
}
|
|
|
NSString* customer_country = [params valueForKey:@"customer_country"]; // "customer_country"
|
|
|
if (customer_country) {
|
|
|
+ customer_country = [customer_country stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
|
|
|
customer_country = [NSString stringWithFormat:@"and lower(country) like '%%%@%%'",customer_country.lowercaseString];
|
|
|
} else {
|
|
|
customer_country = @"";
|
|
|
}
|
|
|
NSString* customer_cid = [params valueForKey:@"customer_cid"]; // "customer_cid"
|
|
|
if (customer_cid) {
|
|
|
+ customer_cid = [customer_cid stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
|
|
|
customer_cid = [NSString stringWithFormat:@"and lower(contact_id) like '%%%@%%'",customer_cid.lowercaseString];
|
|
|
} else {
|
|
|
customer_cid = @"";
|
|
|
}
|
|
|
NSString* customer_city = [params valueForKey:@"customer_city"]; // "customer_city"
|
|
|
if (customer_city) {
|
|
|
+ customer_city = [customer_city stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
|
|
|
customer_city = [NSString stringWithFormat:@"and lower(city) like '%%%@%%'",customer_city.lowercaseString];
|
|
|
} else {
|
|
|
customer_city = @"";
|
|
|
}
|
|
|
NSString* customer_address = [params valueForKey:@"customer_address"]; // "customer_address"
|
|
|
if (customer_address) {
|
|
|
+ customer_address = [customer_address stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
|
|
|
customer_address = [NSString stringWithFormat:@"and lower(decrypt(addr)) like '%%%@%%'",customer_address.lowercaseString];
|
|
|
} else {
|
|
|
customer_address = @"";
|
|
|
}
|
|
|
NSString* customer_email = [params valueForKey:@"customer_email"]; // "customer_email"
|
|
|
if (customer_email) {
|
|
|
+ customer_email = [customer_email stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
|
|
|
customer_email = [NSString stringWithFormat:@"and lower(email) like '%%%@%%'",customer_email.lowercaseString];
|
|
|
} else {
|
|
|
customer_email = @"";
|
|
|
@@ -2757,7 +2793,7 @@
|
|
|
char *name = (char *)sqlite3_column_text(stmt, 0);
|
|
|
if (!name)
|
|
|
name = "";
|
|
|
- [price_name_array addObject:[NSString stringWithUTF8String:name]];
|
|
|
+ [price_name_array addObject:[self translateSingleQuote:[NSString stringWithUTF8String:name]]];
|
|
|
|
|
|
}];
|
|
|
|
|
|
@@ -2778,7 +2814,7 @@
|
|
|
} else {
|
|
|
|
|
|
__block NSString *price;
|
|
|
-
|
|
|
+ price_name = [self translateSingleQuote:price_name];
|
|
|
[iSalesDB jk_query:[NSString stringWithFormat:@"SELECT name FROM price where type = %@ ;",price_name] db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
|
|
|
char *p = (char *)sqlite3_column_text(stmt, 0);
|
|
|
if (p == NULL) {
|
|
|
@@ -2790,6 +2826,7 @@
|
|
|
if ([price isEqualToString:@""]) {
|
|
|
price_name = @"";
|
|
|
} else {
|
|
|
+ price = [self translateSingleQuote:price];
|
|
|
price_name = [NSString stringWithFormat:@"and price_type like '%%%@%%'",price];
|
|
|
}
|
|
|
|
|
|
@@ -2839,9 +2876,9 @@
|
|
|
// NSString* encrypt_keyword= [AESCrypt fastencrypt:keyword];
|
|
|
|
|
|
keyword = keyword.lowercaseString;
|
|
|
+ keyword = [keyword stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
|
|
|
|
|
|
-
|
|
|
- sqlQuery=[NSString stringWithFormat:@"select editable,company_name,country,addr,zipcode,state,city,contact_name,phone,contact_id,addr_1,addr_2,addr_3,addr_4,first_name,last_name,fax,email from offline_contact where %@ and (lower(contact_id ) like'%%%@%%' or lower(decrypt(company_name)) like '%%%@%%') order by decrypt(company_name) limit %d offset %d",contactType , keyword,keyword,limit, offset];
|
|
|
+ sqlQuery=[NSString stringWithFormat:@"select editable,company_name,country,addr,zipcode,state,city,contact_name,phone,contact_id,addr_1,addr_2,addr_3,addr_4,first_name,last_name,fax,email from offline_contact where %@ and (lower(contact_id ) like'%%%@%%' or lower(decrypt(company_name)) like '%%%@%%' or lower(decrypt(phone)) like '%%%@%%' or lower(decrypt(addr)) like '%%%@%%') order by decrypt(company_name) limit %d offset %d",contactType , keyword,keyword,keyword,keyword,limit, offset];
|
|
|
|
|
|
count=[iSalesDB get_recordcount:db table:@"offline_contact" where:[NSString stringWithFormat:@"%@=1 and (lower(contact_id ) like'%@' or lower(company_name) like'%@')",contactType,keyword,keyword]];
|
|
|
}
|
|
|
@@ -3080,6 +3117,7 @@
|
|
|
|
|
|
+ (NSData *)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];
|
|
|
@@ -3397,6 +3435,7 @@
|
|
|
__block NSString *notes,*price_type,*sales_rep;
|
|
|
__block NSString *img_0,*img_1,*img_2;
|
|
|
|
|
|
+ contact_id = [self translateSingleQuote:contact_id];
|
|
|
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) {
|
|
|
@@ -3435,7 +3474,7 @@
|
|
|
phone = [AESCrypt fastdecrypt:phone];
|
|
|
}
|
|
|
|
|
|
- NSString *countrySql = [NSString stringWithFormat:@"select code from offline_country where name = '%@';",country];
|
|
|
+ NSString *countrySql = [NSString stringWithFormat:@"select code from offline_country where name = '%@';",[self translateSingleQuote:country]];
|
|
|
countryCode = [iSalesDB jk_queryText:countrySql];
|
|
|
|
|
|
stateCode = state;
|
|
|
@@ -3611,6 +3650,7 @@
|
|
|
if (!category || [category isEqualToString:@""]) {
|
|
|
category = @"%";
|
|
|
}
|
|
|
+ category = [self translateSingleQuote:category];
|
|
|
|
|
|
int limit = [[params valueForKey:@"limit"] intValue];
|
|
|
int offset = [[params valueForKey:@"offset"] intValue];
|
|
|
@@ -3655,6 +3695,7 @@
|
|
|
if ([alert isEqualToString:@"Display All"]) {
|
|
|
alert = [NSString stringWithFormat:@""];
|
|
|
} else {
|
|
|
+ alert = [self translateSingleQuote:alert];
|
|
|
alert = [NSString stringWithFormat:@"and alert = '%@'",alert];
|
|
|
}
|
|
|
|
|
|
@@ -3688,10 +3729,12 @@
|
|
|
NSArray *priceTypeArray = [self get_contact_default_price_type:nil db:db];
|
|
|
NSMutableString *priceName = [NSMutableString string];
|
|
|
for (int i = 0; i < priceTypeArray.count; i++) {
|
|
|
+ NSString *pricetype = priceTypeArray[i];
|
|
|
+ pricetype = [self translateSingleQuote:pricetype];
|
|
|
if (i == 0) {
|
|
|
- [priceName appendFormat:@"'%@'",priceTypeArray[i]];
|
|
|
+ [priceName appendFormat:@"'%@'",pricetype];
|
|
|
} else {
|
|
|
- [priceName appendFormat:@",'%@'",priceTypeArray[i]];
|
|
|
+ [priceName appendFormat:@",'%@'",pricetype];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -3717,10 +3760,12 @@
|
|
|
if ([qty isEqualToString:@"Display All"]) {
|
|
|
qty = @"";
|
|
|
} else {
|
|
|
+ qty = [self translateSingleQuote:qty];
|
|
|
qty = [NSString stringWithFormat:@"and model_set = 'Sold in quantities of %@'",qty];
|
|
|
}
|
|
|
|
|
|
// cate
|
|
|
+ category = [self translateSingleQuote:category];
|
|
|
NSString *cateWhere = [NSString stringWithFormat:@"category like'%%#%@#%%'",category];
|
|
|
|
|
|
// where bestseller > 0 order by bestseller desc
|
|
|
@@ -3883,6 +3928,7 @@
|
|
|
if ([alert isEqualToString:@"Display All"]) {
|
|
|
alert = [NSString stringWithFormat:@""];
|
|
|
} else {
|
|
|
+ alert = [self translateSingleQuote:alert];
|
|
|
alert = [NSString stringWithFormat:@"and alert = '%@'",alert];
|
|
|
}
|
|
|
|
|
|
@@ -3917,10 +3963,12 @@
|
|
|
NSArray *priceTypeArray = [self get_contact_default_price_type:nil db:db];
|
|
|
NSMutableString *priceName = [NSMutableString string];
|
|
|
for (int i = 0; i < priceTypeArray.count; i++) {
|
|
|
+ NSString *pricetype = priceTypeArray[i];
|
|
|
+ pricetype = [self translateSingleQuote:pricetype];
|
|
|
if (i == 0) {
|
|
|
- [priceName appendFormat:@"'%@'",priceTypeArray[i]];
|
|
|
+ [priceName appendFormat:@"'%@'",pricetype];
|
|
|
} else {
|
|
|
- [priceName appendFormat:@",'%@'",priceTypeArray[i]];
|
|
|
+ [priceName appendFormat:@",'%@'",pricetype];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -3946,6 +3994,7 @@
|
|
|
if ([qty isEqualToString:@"Display All"]) {
|
|
|
qty = @"";
|
|
|
} else {
|
|
|
+ qty = [self translateSingleQuote:qty];
|
|
|
qty = [NSString stringWithFormat:@"and model_set = 'Sold in quantities of %@'",qty];
|
|
|
}
|
|
|
|