|
|
@@ -3834,7 +3834,7 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
count = [params[@"count"] intValue];
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
|
|
NSString* product_id=params[@"product_id"];
|
|
|
NSString* orderCode=params[@"orderCode"];
|
|
|
NSString *qty = params[@"qty"];
|
|
|
@@ -3855,20 +3855,22 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
item_qty=[self model_stockUom:[arr_id[i] intValue] db:db];
|
|
|
|
|
|
// 检查新加Model数量是否大于库存
|
|
|
- __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 < item_qty || availability <= 0) {
|
|
|
- number_of_outOfStock++;
|
|
|
- needContinue = YES;
|
|
|
- }
|
|
|
+ if (!appDelegate.can_create_backorder) {
|
|
|
+ __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 < item_qty || availability <= 0) {
|
|
|
+ number_of_outOfStock++;
|
|
|
+ needContinue = YES;
|
|
|
+ }
|
|
|
+
|
|
|
+ }];
|
|
|
|
|
|
- }];
|
|
|
-
|
|
|
- if (needContinue) {
|
|
|
- continue;
|
|
|
+ if (needContinue) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
int _id=[iSalesDB get_recordid:db table:@"offline_cart" where:[NSString stringWithFormat:@"so_no='%@' and product_id=%@",orderCode,arr_id[i]]];
|
|
|
@@ -3906,17 +3908,19 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
|
|
|
sql = [NSString stringWithFormat:@"select c.item_count + %ld,p.availability from product as p left join offline_cart as c on c.item_id = p.item_id where c._id = %d;",item_qty,_id];
|
|
|
__block BOOL update = YES;
|
|
|
- [iSalesDB jk_query:sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
|
|
|
-
|
|
|
- int newQTY = sqlite3_column_int(stmt, 0);
|
|
|
- int availability = sqlite3_column_int(stmt, 1);
|
|
|
-
|
|
|
- if (newQTY > availability) { // 库存不够
|
|
|
- update = NO;
|
|
|
- number_of_outOfStock++;
|
|
|
- }
|
|
|
-
|
|
|
- }];
|
|
|
+ if (!appDelegate.can_create_backorder) {
|
|
|
+ [iSalesDB jk_query:sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
|
|
|
+
|
|
|
+ int newQTY = sqlite3_column_int(stmt, 0);
|
|
|
+ int availability = sqlite3_column_int(stmt, 1);
|
|
|
+
|
|
|
+ if (newQTY > availability) { // 库存不够
|
|
|
+ update = NO;
|
|
|
+ number_of_outOfStock++;
|
|
|
+ }
|
|
|
+
|
|
|
+ }];
|
|
|
+ }
|
|
|
|
|
|
if (update) {
|
|
|
|
|
|
@@ -3957,10 +3961,12 @@ 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"] = @"Out of Stock.\nNo more quantity available.\nPlease try again after sync.";
|
|
|
- /*[NSString stringWithFormat:@"%d item is out of stock",number_of_outOfStock]*/
|
|
|
+ if (!appDelegate.can_create_backorder) {
|
|
|
+ if (number_of_outOfStock > 0) {
|
|
|
+ ret[@"result"]=[NSNumber numberWithInt:8];
|
|
|
+ ret[@"err_msg"] = @"Out of Stock.\nNo more quantity available.\nPlease try again after sync.";
|
|
|
+ /*[NSString stringWithFormat:@"%d item is out of stock",number_of_outOfStock]*/
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
[iSalesDB execSql:@"END TRANSACTION" db:db];
|
|
|
@@ -4496,6 +4502,7 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
[header setValue:[NSNumber numberWithBool:can_submit_order] forKey:@"can_submit_order"];
|
|
|
[header setValue:[NSNumber numberWithBool:can_set_tearsheet_price] forKey:@"can_set_tearsheet_price"];
|
|
|
[header setValue:[NSNumber numberWithBool:can_create_order] forKey:@"can_create_order"];
|
|
|
+ [header setObject:@(YES) forKey:@"can_create_backorder"];
|
|
|
|
|
|
[header setValue:[NSNumber numberWithBool:can_update_contact_info] forKey:@"can_update_contact_info"];
|
|
|
|
|
|
@@ -9000,25 +9007,29 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
|
|
|
|
|
|
NSString *_id = [self valueInParams:params key:@"cartitem_id"];
|
|
|
- int item_count = [params[@"inputInt"] integerValue];
|
|
|
+ int item_count = [params[@"inputInt"] intValue];
|
|
|
|
|
|
// 购买检查数量大于库存
|
|
|
- NSString *checkSql = [NSString stringWithFormat:@"select p.availability from product as p left join offline_cart as c on c.item_id = p.item_id where c._id = %@;",_id];
|
|
|
- __block BOOL out_of_stock = NO;
|
|
|
- [iSalesDB jk_query:checkSql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
|
|
|
-
|
|
|
- int availability = sqlite3_column_int(stmt, 0);
|
|
|
+ AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
|
|
+ if (!appDelegate.can_create_backorder) {
|
|
|
+ NSString *checkSql = [NSString stringWithFormat:@"select p.availability from product as p left join offline_cart as c on c.item_id = p.item_id where c._id = %@;",_id];
|
|
|
+ __block BOOL out_of_stock = NO;
|
|
|
+ [iSalesDB jk_query:checkSql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
|
|
|
+
|
|
|
+ int availability = sqlite3_column_int(stmt, 0);
|
|
|
+
|
|
|
+ if (availability < item_count) {
|
|
|
+ out_of_stock = YES;
|
|
|
+ }
|
|
|
+
|
|
|
+ }];
|
|
|
|
|
|
- if (availability < item_count) {
|
|
|
- out_of_stock = YES;
|
|
|
+ if (out_of_stock) { // 缺货
|
|
|
+ [dic setValue:[NSNumber numberWithInteger:8] forKey:@"result"];
|
|
|
+ [dic setObject:@"Item is out of stock" forKey:@"err_msg"];
|
|
|
+ return [RAUtils dict2data:dic];
|
|
|
}
|
|
|
-
|
|
|
- }];
|
|
|
-
|
|
|
- if (out_of_stock) { // 缺货
|
|
|
- [dic setValue:[NSNumber numberWithInteger:8] forKey:@"result"];
|
|
|
- [dic setObject:@"Item is out of stock" forKey:@"err_msg"];
|
|
|
- return [RAUtils dict2data:dic];
|
|
|
+
|
|
|
}
|
|
|
|
|
|
NSString *sql = [NSString stringWithFormat:@"update offline_cart set item_count = %d where _id = %@;",item_count,_id];
|
|
|
@@ -10769,18 +10780,21 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
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:@"some item(s) are out of stock,please remove them from cart before placing order with NPD or try again after sync" forKey:@"err_msg"];
|
|
|
- [resultDic setObject:[NSNumber numberWithInt:8] forKey:@"result"];
|
|
|
-
|
|
|
- return [RAUtils dict2data:resultDic];
|
|
|
+ AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
|
|
+ if (!appDelegate.can_create_backorder) {
|
|
|
+ BOOL out_of_stock = [self orderOutOfStock:params db:db];
|
|
|
+ if (out_of_stock) {
|
|
|
+ [iSalesDB close_db:db];
|
|
|
+
|
|
|
+ NSMutableDictionary *resultDic = [NSMutableDictionary dictionary];
|
|
|
+
|
|
|
+ [resultDic setObject:@"some item(s) are out of stock,please remove them from cart before placing order with NPD or try again after sync" forKey:@"err_msg"];
|
|
|
+ [resultDic setObject:[NSNumber numberWithInt:8] forKey:@"result"];
|
|
|
+
|
|
|
+ return [RAUtils dict2data:resultDic];
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
// UISetting
|
|
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
|
|
NSString *cachefolder = [paths objectAtIndex:0];
|
|
|
@@ -11711,7 +11725,7 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
|
|
|
+ (NSData*)offline_movewish2cart:(NSMutableDictionary *)params {
|
|
|
// cart中存在的Model在wish list move to cart之后,cart中Model数量为1
|
|
|
-
|
|
|
+ AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
|
|
NSString *collectId = params[@"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];
|
|
|
|
|
|
@@ -11729,28 +11743,39 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
|
|
|
int _id = sqlite3_column_int(stmt, 3);
|
|
|
|
|
|
- // 库存小于购买量为缺货
|
|
|
- if (availability >= item_qty) {
|
|
|
+ if (!appDelegate.can_create_backorder) {
|
|
|
+ // 库存小于购买量为缺货
|
|
|
+ if (availability >= item_qty) {
|
|
|
+ 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++;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
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++;
|
|
|
}
|
|
|
|
|
|
}];
|
|
|
|
|
|
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 (!appDelegate.can_create_backorder) {
|
|
|
+ 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];
|
|
|
}
|
|
|
@@ -11775,11 +11800,14 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
|
|
|
}
|
|
|
|
|
|
- if (number_of_outOfStock > 0) {
|
|
|
- retDic[@"result"] = [NSNumber numberWithInteger:8];
|
|
|
- retDic[@"err_msg"] = [NSString stringWithFormat:@"%d item is out of stock",number_of_outOfStock];
|
|
|
+ if (!appDelegate.can_create_backorder) {
|
|
|
+ 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];
|
|
|
|
|
|
}
|
|
|
@@ -11788,9 +11816,9 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
|
|
|
+ (NSData *)offline_portfolioList:(NSMutableDictionary *)params {
|
|
|
|
|
|
- int sort = [[params valueForKey:@"sort"] integerValue];
|
|
|
- int offset = [[params valueForKey:@"offset"] integerValue];
|
|
|
- int limit = [[params valueForKey:@"limit"] integerValue];
|
|
|
+ int sort = [[params valueForKey:@"sort"] intValue];
|
|
|
+ int offset = [[params valueForKey:@"offset"] intValue];
|
|
|
+ int limit = [[params valueForKey:@"limit"] intValue];
|
|
|
|
|
|
NSString *orderBy = @"";
|
|
|
switch (sort) {
|