Przeglądaj źródła

修改Model Detail、离线Add To Cart、 Wish List Move To Cart以及Cart Set QTY,检查购买数量大于库存不能购买。
修改离线Palce Order检查缺货。
修改离线Model Detail,增加Model QTY In Cart。
修改Place Order,增加刷新时错误返回Cart。

Pen Li 9 lat temu
rodzic
commit
4d8ec0a23a

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


+ 33 - 26
RedAnt ERP Mobile/common/CommonEditor/CommonEditorViewController.m

@@ -226,6 +226,36 @@
     [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
 }
 
+- (void)alertMessage:(NSString *)msg {
+    
+    if (notifyMe_switch) {
+        
+        if ([self.class_name isEqualToString:@"CreateOrderViewController"]) {
+            
+            NSString *err_msg = msg;
+            UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:err_msg preferredStyle:UIAlertControllerStyleAlert];
+            __weak typeof(self) weakself = self;
+            UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+                
+                [weakself.navigationController popViewControllerAnimated:YES];
+                
+            }];
+            [alertVC addAction:action];
+            
+            [self presentViewController:alertVC animated:YES completion:nil];
+            
+        } else {
+            
+            [RAUtils message_alert:msg title:nil controller:self] ;
+        }
+        
+    } else {
+        
+        [RAUtils message_alert:msg title:nil controller:self] ;
+    }
+    
+}
+
 - (void)viewDidLoad
 {
     [super viewDidLoad];
@@ -299,31 +329,8 @@
                 }
                 else
                 {
-                    if (notifyMe_switch) {
-                        
-                        if ([self.class_name isEqualToString:@"CreateOrderViewController"]) {
-                            
-                            NSString *err_msg = [editor_json valueForKey:@"err_msg"];
-                            UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:err_msg preferredStyle:UIAlertControllerStyleAlert];
-                            __weak typeof(self) weakself = self;
-                            UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-                                
-                                [weakself.navigationController popViewControllerAnimated:YES];
-                                
-                            }];
-                            [alertVC addAction:action];
-                            
-                            [self presentViewController:alertVC animated:YES completion:nil];
-                            
-                        } else {
-                            
-                            [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:weakself] ;
-                        }
-                        
-                    } else {
-                        
-                        [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:weakself] ;
-                    }
+                    
+                    [weakself alertMessage:[editor_json valueForKey:@"err_msg"]];
                     
                 }
                 
@@ -1025,7 +1032,7 @@
                 }
                 else
                 {
-                    [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:weakself] ;
+                    [weakself alertMessage:[editor_json valueForKey:@"err_msg"]];
                 }
                 
                 

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

@@ -8,9 +8,12 @@
 
 #import <UIKit/UIKit.h>
 //#import "CommonGridViewController.h"
-#import "ModelItemCell.h"
+
 #import "CommonEditorViewController.h"
 #import "ActiveViewController.h"
+
+@class ModelItemCell;
+
 @interface CartViewController : ActiveViewController <UITableViewDataSource,UITableViewDelegate,CommonEditorViewControllerDelegate/*,CommonGridViewControllerDelegate,ModelItemCellDelegate*/,UIAlertViewDelegate>
 @property (strong, nonatomic) IBOutlet UITableView *itemListTable;
 @property (strong, nonatomic) IBOutlet UIView *cartItemView;

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

@@ -1619,6 +1619,11 @@
         
 //        if(count==qty)
 //            return;
+        
+        if ([[ext valueForKey:@"result"] integerValue] == 8) {
+            return ;
+        }
+        
         [item_json setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"count"];
         [item_json setValue:[ext valueForKey:@"cuft"] forKey:@"cuft"];
                 [item_json setValue:[ext valueForKey:@"carton"] forKey:@"carton"];

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

@@ -11,7 +11,7 @@
 #import "EditModelPriceViewController.h"
 #import "RAUtils.h"
 #import "BundleModelViewController.h"
-
+#import "CartViewController.h"
 
 #define NUMBERS @"0123456789\n"
 @implementation ModelItemCell
@@ -183,6 +183,7 @@
                     else
                     {
                         UIViewController* vc=[RAUtils getViewController :self];
+                        [((CartViewController *)vc).itemListTable reloadData];
                         [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Change Model Count" controller:vc] ;
                     }
                     
@@ -399,6 +400,7 @@
                         else
                         {
                             UIViewController* vc=[RAUtils getViewController :self];
+                            [((CartViewController *)vc).itemListTable reloadData];
                             [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Change Model Count" controller:vc] ;
                         }
                         
@@ -449,6 +451,7 @@
                     else
                     {
                         UIViewController* vc=[RAUtils getViewController :self];
+                        [((CartViewController *)vc).itemListTable reloadData];
                         [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Change Model Count" controller:vc] ;
                     }
                     

+ 25 - 4
RedAnt ERP Mobile/common/Functions/modelDetail/DetailHeaderCell.m

@@ -523,6 +523,7 @@
     NSString* ct=[self.count_Label.text stringByReplacingOccurrencesOfString:@"\n" withString:@""];
     
     AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
+    /*
     if (c <= 0 && appDelegate.user_type == USER_ROLE_CUSTOMER && [Singleton sharedInstance].currentOrderIsMerged) {
         
         self.btnaddCart.enabled = NO;
@@ -531,19 +532,37 @@
         [RAUtils message_alert:@"Model is out of stock" title:@"Warning" controller:[RAUtils getViewController:self]];
         return;
     }
+    */
     
     if(c<count)
     {
         
-
+        NSString *msg = nil;
+        BOOL continueAdd = YES;
+        if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
+            
+            if ([Singleton sharedInstance].currentOrderIsMerged) { // Purchase Order不允许购买数量大于库存
+                msg = @"Item is OUT OF STOCK and not available to order from NPD.";
+                continueAdd = NO;
+            } else { // Shop Order购买数量大于库存需要确认
+                msg = @"Item is OUT OF STOCK and not available to order from NPD.\nAdd to cart anyway?";
+                continueAdd = YES;
+            }
+        }
         
+        if (appDelegate.user_type == USER_ROLE_EMPLOYEE) { // Employee不允许购买数量大于库存
+            msg = @"Item is OUT OF STOCK and not available to order.";
+            continueAdd = NO;
+        }
         
         
         
-        UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Availability %@",ct ] message:@"Item is OUT OF STOCK and not available to order from NPD.\nAdd to cart anyway?" preferredStyle:UIAlertControllerStyleAlert];
+        UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Availability %@",ct ] message:msg preferredStyle:UIAlertControllerStyleAlert];
         
         UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
-            [self addtocart:count];
+            if (continueAdd) {
+                [self addtocart:count];
+            }
         }];
 
         
@@ -552,7 +571,9 @@
         
         UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
         }];
-        [alertControl addAction:alertcancel];
+        if (continueAdd) {
+            [alertControl addAction:alertcancel];
+        }
 
         UIViewController *vc= [RAUtils getViewController:self];
         

+ 101 - 29
RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.m

@@ -3299,6 +3299,21 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
             [img_section setValue:nsname forKey:@"model_name"];
             [img_section setValue:nsdescription forKey:@"model_descrition"];
             
+            if (appDelegate.order_code) { // 离线order code即so#
+                
+                NSString *cartQtySql = [NSString stringWithFormat:@"select c.item_count from offline_cart as c left join offline_order as o on c.so_no = o.so_id where o.so_id = '%@' and c.item_id = %d;",appDelegate.order_code,item_id];
+                __block int cartQTY = 0;
+                [iSalesDB jk_query:cartQtySql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
+                    
+                    cartQTY = sqlite3_column_int(stmt, 0);
+                    
+                }];
+                
+                if (cartQTY > 0) {
+                    [img_section setObject:[NSNumber numberWithInt:cartQTY] forKey:@"Model QTY in cart"];
+                }
+            }
+            
             [ret setObject:img_section forKey:@"img_section"];
             
             NSMutableDictionary* detail0_section = [[NSMutableDictionary alloc] init];
@@ -3831,11 +3846,21 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
     
     for(int i=0;i<arr_id.count;i++)
     {
+        
+        int item_qty= count;
+        if (qty) {
+            item_qty = [qty_arr[i] integerValue];
+        }
+        if(item_qty==0)
+            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 <= 0) {
+            // 库存小于购买量为缺货
+            if (availability < item_qty || availability <= 0) {
                 number_of_outOfStock++;
                 needContinue = YES;
             }
@@ -3847,16 +3872,12 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
         }
         
         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;
-        if (qty) {
-            item_qty = [qty_arr[i] integerValue];
-        }
-        if(item_qty==0)
-            item_qty=[self model_stockUom:[arr_id[i] intValue] db:db];
+        
         
         NSString* sql=nil;
         
-        sqlite3_stmt *stmt;
+        sqlite3_stmt *stmt = nil;
+        BOOL shouldStep = NO;
 
         if(_id<0)
         {
@@ -3871,35 +3892,58 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
             sqlite3_bind_text(stmt,2,[orderCode UTF8String],[orderCode length],NULL);
             sqlite3_bind_text(stmt,3,[[NSString stringWithFormat:@"%d",item_qty] UTF8String],[[NSString stringWithFormat:@"%d",item_qty] length],NULL);
             sqlite3_bind_text(stmt,4,[[NSString stringWithFormat:@"%d",item_id] UTF8String],[[NSString stringWithFormat:@"%d",item_id] length],NULL);
-            
+            shouldStep = YES;
         }
         else
         {
-            if (qty) {
+            if (qty) { // wish list move to cart
                  sql=[NSString stringWithFormat:@"update offline_cart set item_count=1,modify_time = datetime('now', 'localtime') where _id=?"];
                 
                 sqlite3_prepare_v2(db, [sql UTF8String], -1, &stmt, nil);
                 sqlite3_bind_int(stmt, 1, _id);
-                
+                shouldStep = YES;
             } else {
-                sql=[NSString stringWithFormat:@"update offline_cart set item_count=item_count+?,create_time = datetime('now', 'localtime') where _id=?"];
                 
-                sqlite3_prepare_v2(db, [sql UTF8String], -1, &stmt, nil);
-                sqlite3_bind_text(stmt,1,[[NSString stringWithFormat:@"%d",item_qty] UTF8String],[[NSString stringWithFormat:@"%d",item_qty] length],NULL);
-                sqlite3_bind_text(stmt,2,[[NSString stringWithFormat:@"%d",_id] UTF8String],[[NSString stringWithFormat:@"%d",_id] length],NULL);
+                sql = [NSString stringWithFormat:@"select c.item_count + %d,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 (update) {
+                    
+                    sql=[NSString stringWithFormat:@"update offline_cart set item_count=item_count+?,create_time = datetime('now', 'localtime') where _id=?"];
+                    
+                    sqlite3_prepare_v2(db, [sql UTF8String], -1, &stmt, nil);
+                    sqlite3_bind_text(stmt,1,[[NSString stringWithFormat:@"%d",item_qty] UTF8String],[[NSString stringWithFormat:@"%d",item_qty] length],NULL);
+                    sqlite3_bind_text(stmt,2,[[NSString stringWithFormat:@"%d",_id] UTF8String],[[NSString stringWithFormat:@"%d",_id] length],NULL);
+                    shouldStep = YES;
+                }
             }
 
             
             
         }
         
-        if (sqlite3_step(stmt) == SQLITE_ERROR) {
-            [iSalesDB execSql:@"ROLLBACK" db:db];
-            ret[@"result"]=[NSNumber numberWithInt:RESULT_ERROR ];
+        
+        if (shouldStep) {
             
-            [iSalesDB close_db:db];
-            DebugLog(@"add to cart error");
-            return [RAUtils dict2data:ret];
+            if (sqlite3_step(stmt) == SQLITE_ERROR) {
+                [iSalesDB execSql:@"ROLLBACK" db:db];
+                ret[@"result"]=[NSNumber numberWithInt:RESULT_ERROR ];
+                
+                [iSalesDB close_db:db];
+                DebugLog(@"add to cart error");
+                return [RAUtils dict2data:ret];
+            }
         }
         
     }
@@ -4316,7 +4360,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];
+            itemjson[@"is_out_of_stock"] = [NSNumber numberWithBool:availability >= item_count ? 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");
@@ -8725,8 +8769,12 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
     }];
     [iSalesDB close_db:db];
     // 去除第一个,
-    product_id = [product_id substringFromIndex:1];
-    item_count_str = [item_count_str substringFromIndex:1];
+    if (product_id.length > 1) {
+        product_id = [product_id substringFromIndex:1];
+    }
+    if (item_count_str.length > 1) {
+         item_count_str = [item_count_str substringFromIndex:1];
+    }
     
     NSMutableDictionary *dic = [NSMutableDictionary dictionary];
     
@@ -8851,9 +8899,30 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
 
 +(NSData*) offline_cartsetqty :(NSMutableDictionary *) params
 {
+    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
+    
     NSString *_id = [self valueInParams:params key:@"cartitem_id"];
     int item_count = [params[@"inputInt"] integerValue];
     
+    // 购买检查数量大于库存
+    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 (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];
     
     int ret = [iSalesDB execSql:sql];
@@ -8870,7 +8939,7 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
 
     [iSalesDB close_db:db];
     
-    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
+    
     [dic setValue:[NSNumber numberWithInteger:ret] forKey:@"result"];
     [dic setValue:@"Regular Mode" forKey:@"mode"];
 //    [dic setValue:@"160409" forKey:@"min_ver"];
@@ -10569,7 +10638,7 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
     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];
+    NSString *out_of_stock_SQL = [NSString stringWithFormat:@"select p.availability,c.item_count 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;
@@ -10579,7 +10648,9 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
     [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);
+        int item_qty = sqlite3_column_int(stmt, 1);
+        
+        outOfStock = outOfStock || (availability < item_qty ? YES : NO);
         
     }];
     
@@ -11540,6 +11611,7 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
 #pragma mark move wish list to cart
 
 + (NSData*)offline_movewish2cart:(NSMutableDictionary *)params {
+    // cart中存在的Model在wish list move to cart之后,cart中Model数量为1
     
     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];
@@ -11558,8 +11630,8 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
         
         int _id = sqlite3_column_int(stmt, 3);
         
-        
-        if (availability > 0) {
+        // 库存小于购买量为缺货
+        if (availability >= item_qty) {
             product_id = [product_id stringByAppendingString:[NSString stringWithFormat:@",%d",productId]];
             
             qty = [qty stringByAppendingString:[NSString stringWithFormat:@",%d",item_qty]];