|
|
@@ -2521,7 +2521,7 @@
|
|
|
NSString *ret = nil;
|
|
|
|
|
|
sqlite3 *db = [iSalesDB get_db];
|
|
|
- NSString *sqlQuery = [NSString stringWithFormat:@"select name from price where order_by = %@;",priceId];
|
|
|
+ NSString *sqlQuery = [NSString stringWithFormat:@"select name from price where type = %@;",priceId];
|
|
|
sqlite3_stmt * statement;
|
|
|
|
|
|
if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK) {
|
|
|
@@ -2609,7 +2609,7 @@
|
|
|
// "price_name" = 16;
|
|
|
// user = EvanK;
|
|
|
|
|
|
-
|
|
|
+ sqlite3 *db = [iSalesDB get_db];
|
|
|
|
|
|
NSString* contactType = [params valueForKey:@"contactType"]; // contactType = "Sales_Order_Customer";
|
|
|
if (contactType) {
|
|
|
@@ -2618,85 +2618,123 @@
|
|
|
contactType = @"1 = 1";
|
|
|
}
|
|
|
|
|
|
+ NSString* keyword = [params valueForKey:@"keyword"]; // search 时才有
|
|
|
+ DebugLog(@"offline contact list keyword: %@",keyword);
|
|
|
+
|
|
|
// advanced search
|
|
|
|
|
|
NSString* contact_name = [params valueForKey:@"contact_name"]; // "contact_name"
|
|
|
if (contact_name) {
|
|
|
- contact_name = [NSString stringWithFormat:@"contact_name = '%@'",contact_name];
|
|
|
+ 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 = [NSString stringWithFormat:@"and phone = '%@'",customer_phone];
|
|
|
+ customer_phone = [NSString stringWithFormat:@"and lower(phone) like '%%%@%%'",customer_phone.lowercaseString];
|
|
|
} else {
|
|
|
customer_phone = @"";
|
|
|
}
|
|
|
NSString* customer_fax = [params valueForKey:@"customer_fax"]; // "customer_fax"
|
|
|
if (customer_fax) {
|
|
|
- customer_fax = [NSString stringWithFormat:@"and fax = '%@'",customer_fax];
|
|
|
+ customer_fax = [NSString stringWithFormat:@"and lower(fax) like '%%%@%%'",customer_fax.lowercaseString];
|
|
|
} else {
|
|
|
customer_fax = @"";
|
|
|
}
|
|
|
|
|
|
NSString* customer_zipcode = [params valueForKey:@"customer_zipcode"]; // "customer_zipcode"
|
|
|
if (customer_zipcode) {
|
|
|
- customer_zipcode = [NSString stringWithFormat:@"and zipcode = '%@'",customer_zipcode];
|
|
|
+ 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_sales_rep = [NSString stringWithFormat:@"and sales_rep = '%@'",customer_sales_rep];
|
|
|
+ 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 = [NSString stringWithFormat:@"and state = '%@'",customer_state];
|
|
|
+ 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 = [NSString stringWithFormat:@"and decrypt(company_name) = '%@'",customer_name];
|
|
|
+ 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 = [NSString stringWithFormat:@"and country like '%%%@%%'",customer_country];
|
|
|
+ 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 = [NSString stringWithFormat:@"and contact_id = '%@'",customer_cid];
|
|
|
+ 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 = [NSString stringWithFormat:@"and city = '%@'",customer_city];
|
|
|
+ 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 = [NSString stringWithFormat:@"and decrypt(addr) = '%@'",customer_address];
|
|
|
+ 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 = [NSString stringWithFormat:@"and email = '%@'",customer_email];
|
|
|
+ customer_email = [NSString stringWithFormat:@"and lower(email) like '%%%@%%'",customer_email.lowercaseString];
|
|
|
} else {
|
|
|
customer_email = @"";
|
|
|
}
|
|
|
|
|
|
NSString *price_name = [params valueForKey:@"price_name"];
|
|
|
if (price_name) {
|
|
|
- price_name = [NSString stringWithFormat:@"and price_type in (SELECT name FROM price where type = %@ )",price_name];
|
|
|
+ if ([price_name containsString:@","]) {
|
|
|
+
|
|
|
+ // 首先从 price表中查处name
|
|
|
+ NSArray *pArray = [price_name componentsSeparatedByString:@","];
|
|
|
+
|
|
|
+ NSMutableString *mutablePStr = [NSMutableString stringWithFormat:@"SELECT name FROM price where type = %@ ",pArray[0]];
|
|
|
+
|
|
|
+ for (int i = 1;i < pArray.count;i++) {
|
|
|
+ NSString *p = pArray[i];
|
|
|
+ [mutablePStr appendFormat:@" or type = %@ ",p];
|
|
|
+ }
|
|
|
+ [mutablePStr appendString:@";"];
|
|
|
+
|
|
|
+ __block NSMutableArray *price_name_array = [NSMutableArray array];
|
|
|
+ [iSalesDB jk_query:mutablePStr db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
|
|
|
+ char *name = (char *)sqlite3_column_text(stmt, 0);
|
|
|
+ if (!name)
|
|
|
+ name = "";
|
|
|
+ [price_name_array addObject:[NSString stringWithUTF8String:name]];
|
|
|
+
|
|
|
+ }];
|
|
|
+
|
|
|
+ // 再根据name 拼sql
|
|
|
+ NSMutableString *mutable_price_name = [NSMutableString string];
|
|
|
+ [mutable_price_name appendFormat:@" and( price_type like '%%%@%%' ",price_name_array[0]];
|
|
|
+ for (int i = 1; i < price_name_array.count; i++) {
|
|
|
+ [mutable_price_name appendFormat:@" or price_type like '%%%@%%' ",price_name_array[i]];
|
|
|
+ }
|
|
|
+ [mutable_price_name appendString:@")"];
|
|
|
+
|
|
|
+ price_name = mutable_price_name;
|
|
|
+
|
|
|
+ } else {
|
|
|
+ price_name = [NSString stringWithFormat:@"and price_type in (SELECT name FROM price where type = %@ )",price_name];
|
|
|
+ }
|
|
|
+
|
|
|
} else {
|
|
|
price_name = @"";
|
|
|
}
|
|
|
@@ -2711,10 +2749,11 @@
|
|
|
|
|
|
NSString *where = [NSString stringWithFormat:@" %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ ",contactType,contact_name,customer_phone,customer_fax,customer_zipcode,customer_sales_rep,customer_state,customer_name,customer_country,customer_cid,customer_city,customer_address,customer_email,price_name];
|
|
|
|
|
|
+
|
|
|
NSString *sql = [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 %@ order by decrypt(company_name) limit %d offset %d",where,limit,offset];
|
|
|
|
|
|
|
|
|
- sqlite3 *db = [iSalesDB get_db];
|
|
|
+
|
|
|
|
|
|
int result= [iSalesDB AddExFunction:db];
|
|
|
|
|
|
@@ -2724,9 +2763,28 @@
|
|
|
|
|
|
NSString *sqlQuery = nil;
|
|
|
|
|
|
- sqlQuery = sql;
|
|
|
+ if(keyword.length==0)
|
|
|
+ {
|
|
|
+// 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 %@=1 order by decrypt(company_name) limit %d offset %d",contactType , limit, offset];
|
|
|
+// count=[iSalesDB get_recordcount:db table:@"offline_contact" where:[NSString stringWithFormat:@"%@='1",contactType]];
|
|
|
+
|
|
|
+ sqlQuery = sql;
|
|
|
+
|
|
|
+ count = [iSalesDB get_recordcount:db table:@"offline_contact" where:where];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // NSString* encrypt_keyword= [AESCrypt fastencrypt:keyword];
|
|
|
+
|
|
|
+ keyword = keyword.lowercaseString;
|
|
|
+
|
|
|
+
|
|
|
+ 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];
|
|
|
+
|
|
|
+ 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]];
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- count = [iSalesDB get_recordcount:db table:@"offline_contact" where:where];
|
|
|
|
|
|
DebugLog(@"offline_contactlist sql:%@",sqlQuery);
|
|
|
sqlite3_stmt * statement;
|
|
|
@@ -2765,10 +2823,10 @@
|
|
|
NSString *nscountry= [[NSString alloc]initWithUTF8String:country];
|
|
|
|
|
|
|
|
|
-// char *addr = (char*)sqlite3_column_text(statement, 3);
|
|
|
-// if(addr==nil)
|
|
|
-// addr="";
|
|
|
-// NSString *nsaddr= [[NSString alloc]initWithUTF8String:addr];
|
|
|
+ // char *addr = (char*)sqlite3_column_text(statement, 3);
|
|
|
+ // if(addr==nil)
|
|
|
+ // addr="";
|
|
|
+ // NSString *nsaddr= [[NSString alloc]initWithUTF8String:addr];
|
|
|
|
|
|
|
|
|
char *zipcode = (char*)sqlite3_column_text(statement, 4);
|
|
|
@@ -2787,12 +2845,12 @@
|
|
|
city="";
|
|
|
NSString *nscity= [[NSString alloc]initWithUTF8String:city];
|
|
|
|
|
|
-// char *contact_name = (char*)sqlite3_column_text(statement, 7);
|
|
|
-// NSString *nscontact_name = nil;
|
|
|
-// if(contact_name==nil)
|
|
|
-// nscontact_name=@"";
|
|
|
-// else
|
|
|
-// nscontact_name= [[NSString alloc]initWithUTF8String:contact_name];
|
|
|
+ // char *contact_name = (char*)sqlite3_column_text(statement, 7);
|
|
|
+ // NSString *nscontact_name = nil;
|
|
|
+ // if(contact_name==nil)
|
|
|
+ // nscontact_name=@"";
|
|
|
+ // else
|
|
|
+ // nscontact_name= [[NSString alloc]initWithUTF8String:contact_name];
|
|
|
|
|
|
char *phone = (char*)sqlite3_column_text(statement, 8);
|
|
|
NSString *nsphone = nil;
|
|
|
@@ -3031,6 +3089,9 @@
|
|
|
|
|
|
+ (NSData *)offline_saveContact:(NSDictionary *)params update:(BOOL)update {
|
|
|
|
|
|
+ NSString *addr = nil;
|
|
|
+ NSString *contact_name = nil;
|
|
|
+
|
|
|
NSString *companyName = [params objectForKey:@"company"];
|
|
|
if (companyName) {
|
|
|
companyName = [AESCrypt fastencrypt:companyName];
|
|
|
@@ -3040,6 +3101,20 @@
|
|
|
companyName = [self translateSingleQuote:companyName];
|
|
|
|
|
|
NSString *addr1 = [params objectForKey:@"address"];
|
|
|
+
|
|
|
+
|
|
|
+ NSString *addr2 = [params objectForKey:@"address2"];
|
|
|
+
|
|
|
+
|
|
|
+ NSString *addr3 = [params objectForKey:@"address_3"];
|
|
|
+
|
|
|
+
|
|
|
+ NSString *addr4 = [params objectForKey:@"address_4"];
|
|
|
+
|
|
|
+ addr = [RAUtils arr2string:@[addr1,addr2,addr3,addr4] separator:@" " trim:true];
|
|
|
+ addr = [AESCrypt fastencrypt:addr];
|
|
|
+ addr = [self translateSingleQuote:addr];
|
|
|
+
|
|
|
if (addr1) {
|
|
|
addr1 = [AESCrypt fastencrypt:addr1];
|
|
|
} else {
|
|
|
@@ -3047,24 +3122,22 @@
|
|
|
}
|
|
|
addr1 = [self translateSingleQuote:addr1];
|
|
|
|
|
|
- NSString *addr2 = [params objectForKey:@"address2"];
|
|
|
if (!addr2) {
|
|
|
addr2 = @"";
|
|
|
}
|
|
|
addr2 = [self translateSingleQuote:addr2];
|
|
|
|
|
|
- NSString *addr3 = [params objectForKey:@"address_3"];
|
|
|
if (!addr3) {
|
|
|
addr3 = @"";
|
|
|
}
|
|
|
addr3 = [self translateSingleQuote:addr3];
|
|
|
|
|
|
- NSString *addr4 = [params objectForKey:@"address_4"];
|
|
|
if (!addr4) {
|
|
|
addr4 = @"";
|
|
|
}
|
|
|
addr4 = [self translateSingleQuote:addr4];
|
|
|
|
|
|
+
|
|
|
NSString *country = [params objectForKey:@"country"];
|
|
|
if (country) {
|
|
|
country = [self countryNameByCountryCodeId:country];
|
|
|
@@ -3092,12 +3165,18 @@
|
|
|
zipcode = [self translateSingleQuote:zipcode];
|
|
|
|
|
|
NSString *fistName = [params objectForKey:@"firstname"];
|
|
|
+
|
|
|
+
|
|
|
+ NSString *lastName = [params objectForKey:@"lastname"];
|
|
|
+
|
|
|
+ contact_name = [RAUtils arr2string:@[fistName,lastName] separator:@" " trim:true];
|
|
|
+ contact_name = [self translateSingleQuote:contact_name];
|
|
|
+
|
|
|
if (!fistName) {
|
|
|
fistName = @"";
|
|
|
}
|
|
|
fistName = [self translateSingleQuote:fistName];
|
|
|
|
|
|
- NSString *lastName = [params objectForKey:@"lastname"];
|
|
|
if (!lastName) {
|
|
|
lastName = @"";
|
|
|
}
|
|
|
@@ -3184,7 +3263,7 @@
|
|
|
sync_data = [RAUtils dict2string:sync_dic];
|
|
|
sync_data = [self translateSingleQuote:sync_data];
|
|
|
|
|
|
- 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 = '%@',sync_data = '%@' 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,sync_data,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 = '%@',sync_data = '%@',contact_name = '%@',addr = '%@' 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,sync_data,contact_name,addr,contact_id];
|
|
|
} else {
|
|
|
|
|
|
contact_id = [self translateSingleQuote:contact_id];
|
|
|
@@ -3193,7 +3272,7 @@
|
|
|
sync_data = [RAUtils dict2string:sync_dic];
|
|
|
sync_data = [self translateSingleQuote:sync_data];
|
|
|
|
|
|
- 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,sync_data) 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,sync_data];
|
|
|
+ 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,sync_data,contact_name,addr) 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,sync_data,contact_name,addr];
|
|
|
}
|
|
|
|
|
|
int result = [iSalesDB execSql:sql];
|