|
|
@@ -3827,8 +3827,24 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
NSArray* arr_id=[RAUtils string2arr:product_id separator:@","];
|
|
|
NSArray *qty_arr = [RAUtils string2arr:qty separator:@","];
|
|
|
|
|
|
+ __block int number_of_outOfStock = 0;
|
|
|
+
|
|
|
for(int i=0;i<arr_id.count;i++)
|
|
|
{
|
|
|
+ __block BOOL needContinue = NO;
|
|
|
+ [iSalesDB jk_query:[NSString stringWithFormat:@"select availability from product where product_id = %@;",arr_id[i]] db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
|
|
|
+
|
|
|
+ int availability = sqlite3_column_int(stmt, 0);
|
|
|
+ if (availability <= 0) {
|
|
|
+ number_of_outOfStock++;
|
|
|
+ needContinue = YES;
|
|
|
+ }
|
|
|
+
|
|
|
+ }];
|
|
|
+
|
|
|
+ if (needContinue) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
int _id=[iSalesDB get_recordid:db table:@"offline_cart" where:[NSString stringWithFormat:@"so_no='%@' and product_id=%@",orderCode,arr_id[i]]];
|
|
|
int item_qty= count;
|
|
|
@@ -3897,6 +3913,11 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
ret[@"wish_count"]=[NSNumber numberWithInt:wish_count ];
|
|
|
ret[@"cart_count"]=[NSNumber numberWithInt:cart_count ];
|
|
|
ret[@"result"]=[NSNumber numberWithInt:RESULT_TRUE ];
|
|
|
+ if (number_of_outOfStock > 0) {
|
|
|
+ ret[@"result"]=[NSNumber numberWithInt:8];
|
|
|
+ ret[@"err_msg"] = [NSString stringWithFormat:@"%d item is out of stock",number_of_outOfStock];
|
|
|
+ }
|
|
|
+
|
|
|
[iSalesDB execSql:@"END TRANSACTION" db:db];
|
|
|
[iSalesDB close_db:db];
|
|
|
|
|
|
@@ -4181,7 +4202,7 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
|
|
|
|
|
|
|
|
|
- NSString *sqlQuery = [ NSString stringWithFormat:@"select c.product_id,c.price,c.discount,c.item_count,c.line_note,m.name,m.description,c.item_id,m.stockUom,c._id from (select _id,product_id,decrypt(str_price) as price,discount,item_count,line_note,item_id,modify_time from offline_cart where so_no='%@') c left join product m on c.product_id=m.product_id %@",orderCode,sort_str ];
|
|
|
+ NSString *sqlQuery = [ NSString stringWithFormat:@"select c.product_id,c.price,c.discount,c.item_count,c.line_note,m.name,m.description,c.item_id,m.stockUom,c._id,m.availability from (select _id,product_id,decrypt(str_price) as price,discount,item_count,line_note,item_id,modify_time from offline_cart where so_no='%@') c left join product m on c.product_id=m.product_id %@",orderCode,sort_str ];
|
|
|
|
|
|
|
|
|
// NSString *sqlQuery = [ NSString stringWithFormat:@"select c.product_id,decrypt(c.str_price),c.discount,c.item_count,c.line_note,m.name,m.description,c.item_id,m.stockUom,c._id from offline_cart c left join product m on c.product_id=m.product_id where c.so_no='%@'",orderCode ];
|
|
|
@@ -4206,7 +4227,7 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
|
|
|
while (sqlite3_step(statement) == SQLITE_ROW)
|
|
|
{
|
|
|
- NSDate *row_date = [NSDate date];
|
|
|
+// NSDate *row_date = [NSDate date];
|
|
|
|
|
|
|
|
|
NSMutableDictionary* itemjson = [[NSMutableDictionary alloc] init];
|
|
|
@@ -4264,7 +4285,8 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
|
|
|
int stockUom = sqlite3_column_int(statement, 8);
|
|
|
int _id = sqlite3_column_int(statement, 9);
|
|
|
-
|
|
|
+ int availability = sqlite3_column_int(statement, 10);
|
|
|
+
|
|
|
// NSDate *subtotal_date = [NSDate date];
|
|
|
NSDictionary* bsubtotaljson=[self model_subtotal:item_id count:item_count db:db compute_part:true];
|
|
|
// DebugLog(@"subtotal_date time interval");
|
|
|
@@ -4294,7 +4316,7 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
itemjson[@"description"]=[NSString stringWithFormat:@"%@\n%@",nsname,nsdescription ];
|
|
|
itemjson[@"stockUom"]=[NSNumber numberWithInt:stockUom];
|
|
|
itemjson[@"note"]=nsline_note;
|
|
|
-
|
|
|
+ itemjson[@"is_out_of_stock"] = [NSNumber numberWithBool:availability > 0 ? NO : YES];
|
|
|
// NSDate *date2 = [NSDate date];
|
|
|
itemjson[@"combine"]=[self model_bundle:item_id db:db compute_part:false contactID:appDelegate.contact_id];
|
|
|
// DebugLog(@"model_bundle time interval");
|
|
|
@@ -10540,10 +10562,54 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
return dic;
|
|
|
}
|
|
|
|
|
|
++ (BOOL)orderOutOfStock:(NSDictionary *)params db:(sqlite3 *)db{
|
|
|
+
|
|
|
+ // params
|
|
|
+ NSString *orderCode = [self valueInParams:params key:@"orderCode"];
|
|
|
+ orderCode = [self translateSingleQuote:orderCode];
|
|
|
+
|
|
|
+ // 缺货检查
|
|
|
+ NSString *out_of_stock_SQL = [NSString stringWithFormat:@"select p.availability from product as p left join offline_cart as c on p.product_id = c.product_id where c.so_no = '%@';",orderCode];
|
|
|
+
|
|
|
+ __block BOOL outOfStock = NO;
|
|
|
+ sqlite3 *database = db;
|
|
|
+ if (!db) {
|
|
|
+ database = [iSalesDB get_db];
|
|
|
+ }
|
|
|
+ [iSalesDB jk_query:out_of_stock_SQL db:database close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
|
|
|
+
|
|
|
+ int availability = sqlite3_column_int(stmt, 0);
|
|
|
+ outOfStock = outOfStock || (availability <= 0 ? YES : NO);
|
|
|
+
|
|
|
+ }];
|
|
|
+
|
|
|
+ if (!db) {
|
|
|
+ [iSalesDB close_db:database];
|
|
|
+ }
|
|
|
+
|
|
|
+ return outOfStock;
|
|
|
+}
|
|
|
+
|
|
|
+(NSData*) offline_placeorder :(NSMutableDictionary *) params
|
|
|
{
|
|
|
|
|
|
sqlite3 *db = [iSalesDB get_db];
|
|
|
+ // params
|
|
|
+ NSString *orderCode = [self valueInParams:params key:@"orderCode"];
|
|
|
+ orderCode = [self translateSingleQuote:orderCode];
|
|
|
+
|
|
|
+ // 缺货检查
|
|
|
+ BOOL out_of_stock = [self orderOutOfStock:params db:db];
|
|
|
+ if (out_of_stock) {
|
|
|
+ [iSalesDB close_db:db];
|
|
|
+
|
|
|
+ NSMutableDictionary *resultDic = [NSMutableDictionary dictionary];
|
|
|
+
|
|
|
+ [resultDic setObject:@"item is out of stock,after sync try again" forKey:@"err_msg"];
|
|
|
+ [resultDic setObject:[NSNumber numberWithInt:8] forKey:@"result"];
|
|
|
+
|
|
|
+ return [RAUtils dict2data:resultDic];
|
|
|
+ }
|
|
|
|
|
|
// UISetting
|
|
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
|
|
@@ -10561,9 +10627,7 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
|
|
|
int section_count = 0;
|
|
|
|
|
|
- // params
|
|
|
- NSString *orderCode = [self valueInParams:params key:@"orderCode"];
|
|
|
- orderCode = [self translateSingleQuote:orderCode];
|
|
|
+
|
|
|
|
|
|
// 0 Order Type 1 Shipping Method 2 Payment Information
|
|
|
__block NSMutableDictionary *ret = [self dictionaryFileName:@"placeOrderTemplate.json"];
|
|
|
@@ -11478,24 +11542,50 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
+ (NSData*)offline_movewish2cart:(NSMutableDictionary *)params {
|
|
|
|
|
|
NSString *collectId = params[@"collectId"];
|
|
|
- NSString *sql = [NSString stringWithFormat:@"select product_id,qty from wishlist where _id in (%@);",collectId];
|
|
|
+ NSString *sql = [NSString stringWithFormat:@"select w.product_id,w.qty,p.availability,w._id from wishlist as w left join product as p on w.product_id = p.product_id where w._id in (%@);",collectId];
|
|
|
|
|
|
__block NSString *product_id = @"";
|
|
|
__block NSString *qty = @"";
|
|
|
+ __block int number_of_outOfStock = 0;
|
|
|
+ __block NSMutableArray *delete_collectId = [NSMutableArray array];
|
|
|
[iSalesDB jk_query:sql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
|
|
|
|
|
|
int productId = sqlite3_column_int(stmt, 0);
|
|
|
|
|
|
int item_qty = sqlite3_column_int(stmt, 1);
|
|
|
|
|
|
- product_id = [product_id stringByAppendingString:[NSString stringWithFormat:@",%d",productId]];
|
|
|
+ int availability = sqlite3_column_int(stmt, 2);
|
|
|
+
|
|
|
+ int _id = sqlite3_column_int(stmt, 3);
|
|
|
|
|
|
- qty = [qty stringByAppendingString:[NSString stringWithFormat:@",%d",item_qty]];
|
|
|
+
|
|
|
+ if (availability > 0) {
|
|
|
+ product_id = [product_id stringByAppendingString:[NSString stringWithFormat:@",%d",productId]];
|
|
|
+
|
|
|
+ qty = [qty stringByAppendingString:[NSString stringWithFormat:@",%d",item_qty]];
|
|
|
+
|
|
|
+ [delete_collectId addObject:[NSString stringWithFormat:@"%d",_id]];
|
|
|
+
|
|
|
+ } else {
|
|
|
+ number_of_outOfStock++;
|
|
|
+ }
|
|
|
|
|
|
}];
|
|
|
|
|
|
- product_id = [product_id substringFromIndex:1];
|
|
|
- qty = [qty substringFromIndex:1];
|
|
|
+ NSMutableDictionary *retDic = nil;
|
|
|
+ if (delete_collectId.count == 0) {
|
|
|
+ retDic = [NSMutableDictionary dictionary];
|
|
|
+ retDic[@"result"] = [NSNumber numberWithInteger:8];
|
|
|
+ retDic[@"err_msg"] = [NSString stringWithFormat:@"%d item is out of stock",number_of_outOfStock];
|
|
|
+ return [RAUtils dict2data:retDic];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (product_id.length > 1) {
|
|
|
+ product_id = [product_id substringFromIndex:1];
|
|
|
+ }
|
|
|
+ if (qty.length > 1) {
|
|
|
+ qty = [qty substringFromIndex:1];
|
|
|
+ }
|
|
|
|
|
|
NSDictionary *newParams = @{
|
|
|
@"product_id" : product_id,
|
|
|
@@ -11504,19 +11594,21 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
};
|
|
|
|
|
|
NSData *data = [self offline_add2cart:newParams.mutableCopy];
|
|
|
- NSMutableDictionary *retDic = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil] mutableCopy];
|
|
|
+ retDic = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil] mutableCopy];
|
|
|
|
|
|
if ([retDic[@"result"] integerValue] == RESULT_TRUE) {
|
|
|
|
|
|
-// NSString *deleteSQL = [NSString stringWithFormat:@"delete from wishlist where _id in (%@);",collectId];
|
|
|
-//
|
|
|
-// int ret = [iSalesDB execSql:deleteSQL];
|
|
|
- int ret = [[[self offline_deletewishlist:@{@"collectId" : collectId}.mutableCopy] valueForKey:@"result"] integerValue];
|
|
|
+ int ret = [[[self offline_deletewishlist:@{@"collectId" : [delete_collectId componentsJoinedByString:@","]}.mutableCopy] valueForKey:@"result"] integerValue];
|
|
|
|
|
|
retDic[@"result"] = [NSNumber numberWithInteger:ret];
|
|
|
|
|
|
}
|
|
|
|
|
|
+ if (number_of_outOfStock > 0) {
|
|
|
+ retDic[@"result"] = [NSNumber numberWithInteger:8];
|
|
|
+ retDic[@"err_msg"] = [NSString stringWithFormat:@"%d item is out of stock",number_of_outOfStock];
|
|
|
+ }
|
|
|
+
|
|
|
return [RAUtils dict2data:retDic];
|
|
|
|
|
|
}
|