Ver Fonte

修改Model Detail,使Employee也能使用Notify Me功能,Customer在打开Shop Order情况下才能添加缺货Model。
修改离线Cart、Place Order、Select Add To Cart以及Wish List Move To Cart,增加缺货检查。
修改同步上传,提示Out Of Stock Order。

Pen Li há 9 anos atrás
pai
commit
3fbf74b439

BIN
RedAnt ERP Mobile/RedAnt ERP Mobile.xcworkspace/xcuserdata/macmini1.xcuserdatad/UserInterfaceState.xcuserstate


+ 4 - 4
RedAnt ERP Mobile/common/Functions/cart/CartViewController.m

@@ -1554,15 +1554,15 @@
     else
         cell.labelNoSuchModel.hidden=true;
     
-    if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
+    //if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
         if (!is_out_of_stock) {
             cell.labelOutOfStock.hidden = YES;
         } else {
             cell.labelOutOfStock.hidden = NO;
         }
-    } else {
-        cell.labelOutOfStock.hidden = YES;
-    }
+//    } else {
+//        cell.labelOutOfStock.hidden = YES;
+//    }
     
     //    discount = 5.0;
     cell.discount = discount;

+ 28 - 20
RedAnt ERP Mobile/common/Functions/modelDetail/DetailViewController.m

@@ -959,23 +959,22 @@ self.isrefreshing=false;
             
             cell.btnaddPortfolio.hidden = YES;
             cell.btnNotifyMe.hidden = YES;
-//            CGRect wishListFrame = cell.btnaddWish.frame;
-//            CGRect cartFrame = cell.btnaddCart.frame;
-//            cartFrame.origin.x = wishListFrame.origin.x;
-//            cell.btnaddCart.frame = cartFrame;
             
         } else {
             
+            NSString *qtyStr = [section_json valueForKey:@"Availability"];
+            cell.btnNotifyMe.layer.borderColor = [UIColor blackColor].CGColor;
+            cell.btnNotifyMe.layer.borderWidth = 1.0f;
+            cell.btnNotifyMe.layer.cornerRadius = 3.0f;
+            cell.btnNotifyMe.layer.masksToBounds = YES;
+            
             if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
+                
                 cell.btnaddPortfolio.hidden = YES;
                 
                 if (!notifyMe_switch) {
                     
                     cell.btnNotifyMe.hidden = YES;
-//                    CGRect wishListFrame = cell.btnaddWish.frame;
-//                    CGRect cartFrame = cell.btnaddCart.frame;
-//                    cartFrame.origin.x = wishListFrame.origin.x;
-//                    cell.btnaddCart.frame = cartFrame;
                     
                 } else {
                     
@@ -993,7 +992,7 @@ self.isrefreshing=false;
                                 
                                 [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
                                 
-                                int result = [[dic valueForKey:@"result"] integerValue];
+                                NSInteger result = [[dic valueForKey:@"result"] integerValue];
                                 
                                 if (result != RESULT_TRUE && result != RESULT_NO_EMAIL_ADDRESS) {
                                     
@@ -1029,19 +1028,11 @@ self.isrefreshing=false;
                         
                     };
                     
-                    cell.btnNotifyMe.layer.borderColor = [UIColor blackColor].CGColor;
-                    cell.btnNotifyMe.layer.borderWidth = 1.0f;
-                    cell.btnNotifyMe.layer.cornerRadius = 3.0f;
-                    cell.btnNotifyMe.layer.masksToBounds = YES;
-                    NSString *qtyStr = [section_json valueForKey:@"Availability"];
-                    
-                    //
-                    
                     if (!appDelegate.order_code) { // 未打开订单状态
                         
                         if (!qtyStr || !qtyStr.length || [qtyStr isEqualToString:@"In Production"] || [qtyStr isEqualToString:@"0"] || [qtyStr isEqualToString:@"Sold Out"]) {
                             
-                            cell.btnaddCart.enabled = YES;
+                            cell.btnaddCart.enabled = NO;
                             cell.btnNotifyMe.alpha = 1.0;
                             cell.btnNotifyMe.enabled = YES;
                             
@@ -1088,9 +1079,26 @@ self.isrefreshing=false;
                     
                 }
                 
-            } else {
+            } else { // employee
+                
                 cell.btnaddPortfolio.hidden = NO;
-                cell.btnNotifyMe.hidden = YES;
+                cell.btnNotifyMe.hidden = NO;
+                
+                if (!qtyStr || !qtyStr.length || [qtyStr isEqualToString:@"In Production"] || [qtyStr isEqualToString:@"0"] || [qtyStr isEqualToString:@"Sold Out"]) { // 缺货
+                    cell.btnaddCart.enabled = NO;
+                    cell.btnNotifyMe.alpha = 1.0;
+                    cell.btnNotifyMe.enabled = YES;
+                } else { // 未缺货
+                    cell.btnNotifyMe.enabled = NO;
+                    cell.btnNotifyMe.alpha = 0.4;
+                    cell.btnaddCart.enabled = YES;
+                }
+                
+                if (appDelegate.offline_mode) {
+                    
+                    cell.btnNotifyMe.hidden = YES;
+                }
+                
             }
 
             

+ 109 - 17
RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.m

@@ -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];
     
 }

+ 5 - 0
RedAnt ERP Mobile/iSales-NPD/AppDelegate.m

@@ -1242,6 +1242,11 @@ void UncaughtExceptionHandler(NSException *exception) {
                 
                 if([[json valueForKey:@"result"] intValue]==2)
                 {
+                    NSString *out_of_stock_ids = [json valueForKey:@"stock_out_so_id"];
+                    if (out_of_stock_ids) {
+                        [RAUtils message_alert:[NSString stringWithFormat:@"Below orders were not submitted because some models were out of stock. You can check from order history under online mode.\n %@",out_of_stock_ids] title:@"Warning" controller:self.main_vc];
+                    }
+                    
                     [self add_downloadlog:@"Upload successful."];
                     appDelegate.disable_trigger=true;
                     NSString* so_id=[RAUtils arr2string:arr_order separator:@"," trim:true brackets:@"'"];