Просмотр исходного кода

Copy Order检测当前打开订单时询问是否关闭订单后再Copy。

Pen Li 9 лет назад
Родитель
Сommit
a5648a2e73

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


+ 92 - 44
RedAnt ERP Mobile/common/Functions/order/OrderDetailViewController.m

@@ -505,8 +505,57 @@
 }
 - (void)onCopyOrderClick:(id)sender {
     
-    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Copy confirm", nil) message:NSLocalizedString(@"Are you sure to copy order?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
-    [alert show];
+     AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+    if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.order_code) {
+        
+        __weak typeof(self) weakself = self;
+        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:@"You must release current order,are you sure to release the order then copy a new order?" preferredStyle:UIAlertControllerStyleAlert];
+        
+        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
+            
+        }];
+        
+        UIAlertAction *yesAction = [UIAlertAction actionWithTitle:@"yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+            
+            UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Release Order"];
+            
+            dispatch_async(dispatch_get_global_queue(0, 0), ^{
+                
+                NSDictionary* order_json = [iSalesNetwork release_Order:appDelegate.order_code];
+                
+                dispatch_async(dispatch_get_main_queue(), ^{
+                    
+                    [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
+                    if([[order_json valueForKey:@"result"] intValue]==2)
+                    {
+                        [appDelegate closeOrder];
+                        
+                        [weakself copyOrder];
+                        
+                    } else {
+                        
+                       [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Release Order" controller:weakself] ;
+                    }
+                });
+                
+            });
+            
+        }];
+        
+        [alertVC addAction:cancelAction];
+        [alertVC addAction:yesAction];
+        
+        [self presentViewController:alertVC animated:YES completion:nil];
+        
+    } else {
+        
+        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Copy confirm", nil) message:NSLocalizedString(@"Are you sure to copy order?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
+        [alert show];
+        
+    }
+    
+    
+    
     
 }
 //- (void)onCommitOrderClick:(id)sender {
@@ -1822,52 +1871,51 @@
     
     if(buttonIndex!=alertView.cancelButtonIndex)
     {
-        UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Copy Order"];
-        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-            
-            NSDictionary* order_json = [iSalesNetwork copy_Order:self.order_code];
-            
-            dispatch_async(dispatch_get_main_queue(), ^{
-                [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-                if([[order_json valueForKey:@"result"] intValue]==2)
-                {
-               //     NSString* orderCode = [order_json valueForKey:@"orderCode"];
-                    
-                    //                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                    //                    if([appDelegate.order_code isEqualToString: self.order_code])
-                    //                    {
-                    //                        [appDelegate closeOrder];
-                    ////                        appDelegate.order_code= nil;
-                    //                        [appDelegate SetSo:nil];
-                    //
-                    //
-                    //                    }
-                    UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Copy successful." message:[NSString stringWithFormat:@"New order SO#: %@",[order_json valueForKey:@"so_id"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
-                    
-                    [alert show];
-                    
-                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                    [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
-                    [self.navigationController popViewControllerAnimated:false];
-                    
-                }
-                else
-                {
-                    [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Cpoy Order" controller:self] ;
-                }
+        [self copyOrder];
+    }
+}
+
+- (void)copyOrder {
+    
+    UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Copy Order"];
+    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+        
+        NSDictionary* order_json = [iSalesNetwork copy_Order:self.order_code];
+        
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
+            if([[order_json valueForKey:@"result"] intValue]==2)
+            {
+                //     NSString* orderCode = [order_json valueForKey:@"orderCode"];
                 
+                //                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                //                    if([appDelegate.order_code isEqualToString: self.order_code])
+                //                    {
+                //                        [appDelegate closeOrder];
+                ////                        appDelegate.order_code= nil;
+                //                        [appDelegate SetSo:nil];
+                //
+                //
+                //                    }
+                UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Copy successful." message:[NSString stringWithFormat:@"New order SO#: %@",[order_json valueForKey:@"so_id"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
                 
+                [alert show];
                 
-            });
+                AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
+                [self.navigationController popViewControllerAnimated:false];
+                
+            }
+            else
+            {
+                [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Cpoy Order" controller:self] ;
+            }
+            
+            
+            
         });
-        
-        
-        
-        
-        
-        
-        
-    }
+    });
+
 }