Explorar el Código

修复erp mobile 警告错误,runtime 错误,多处闪退和累积错误
修复ra image 底层接口修改后,无法编译的错误

Ray Zhang hace 6 años
padre
commit
14b8f98ecd
Se han modificado 67 ficheros con 8028 adiciones y 7136 borrados
  1. 19 19
      Apex Mobile/Apex Mobile/config.h
  2. 10 2
      RA Image/RA Image.xcodeproj/project.pbxproj
  3. 62 55
      RA Image/RA Image/BasicModeViewController.m
  4. 5 1
      RA Image/RA Image/LoginSettingViewController.m
  5. 38 29
      RA Image/RA Image/LoginViewController.m
  6. 36 28
      RA Image/RA Image/ModelModeViewController.m
  7. 29 21
      RA Image/RA Image/RootViewController.m
  8. 3 1
      RA Image/RA Image/UploadViewController.m
  9. 1 1
      RedAnt CRM/APEX CRM/APEX CRM/config/config.h
  10. 20 1
      RedAnt ERP Mobile/common/ActiveViewController.m
  11. 1 1
      RedAnt ERP Mobile/common/AppDelegateBase.h
  12. 158 89
      RedAnt ERP Mobile/common/AppDelegateBase.m
  13. 238 234
      RedAnt ERP Mobile/common/CartUtils.m
  14. 476 289
      RedAnt ERP Mobile/common/CommonEditor/CommonEditorViewController.m
  15. 16 18
      RedAnt ERP Mobile/common/ERP_Mobile_Contact.storyboard
  16. 3 2
      RedAnt ERP Mobile/common/ERP_Mobile_Order.storyboard
  17. 5 8
      RedAnt ERP Mobile/common/ERP_Mobile_Portfolio.storyboard
  18. 2 2
      RedAnt ERP Mobile/common/ERP_Mobile_Search.storyboard
  19. 94 86
      RedAnt ERP Mobile/common/Functions/MainViewController.m
  20. 26 24
      RedAnt ERP Mobile/common/Functions/address/AddressEditorViewController.m
  21. 38 36
      RedAnt ERP Mobile/common/Functions/camscan/ScannerViewController.m
  22. 33 31
      RedAnt ERP Mobile/common/Functions/cart/CartGeneralNotesViewController.m
  23. 473 451
      RedAnt ERP Mobile/common/Functions/cart/CartViewController.m
  24. 25 23
      RedAnt ERP Mobile/common/Functions/cart/ItemNotesViewController.m
  25. 5 2
      RedAnt ERP Mobile/common/Functions/category/CategorySearchFilterViewController.m
  26. 272 249
      RedAnt ERP Mobile/common/Functions/category/CategoryViewController.m
  27. 1 0
      RedAnt ERP Mobile/common/Functions/contact/ContactListViewController.h
  28. 76 69
      RedAnt ERP Mobile/common/Functions/contact/ContactListViewController.m
  29. 47 44
      RedAnt ERP Mobile/common/Functions/contact/CustomerEditViewController.m
  30. 60 86
      RedAnt ERP Mobile/common/Functions/contact/CustomerInfoViewController.m
  31. 60 58
      RedAnt ERP Mobile/common/Functions/modelDetail/DetailHeaderCell.m
  32. 153 147
      RedAnt ERP Mobile/common/Functions/modelDetail/DetailViewController.m
  33. 30 8
      RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.h
  34. 549 528
      RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.m
  35. 119 109
      RedAnt ERP Mobile/common/Functions/offline/OfflineSettingViewController.m
  36. 40 36
      RedAnt ERP Mobile/common/Functions/offline/SelectUploadOrderViewController.m
  37. 290 258
      RedAnt ERP Mobile/common/Functions/order/CreateOrderViewController.m
  38. 604 590
      RedAnt ERP Mobile/common/Functions/order/OrderDetailViewController.m
  39. 170 162
      RedAnt ERP Mobile/common/Functions/order/OrderListViewController.m
  40. 40 38
      RedAnt ERP Mobile/common/Functions/order/RAOrderEditorViewController.m
  41. 258 249
      RedAnt ERP Mobile/common/Functions/order/RAOrderPreviewController.m
  42. 24 22
      RedAnt ERP Mobile/common/Functions/portfolio/PortfolioListViewController.m
  43. 357 344
      RedAnt ERP Mobile/common/Functions/portfolio/PortfolioViewController.m
  44. 264 258
      RedAnt ERP Mobile/common/Functions/portfolio/TearSheetParamViewController.m
  45. 423 400
      RedAnt ERP Mobile/common/Functions/search+itemsearch/ItemSearchViewController.m
  46. 474 455
      RedAnt ERP Mobile/common/Functions/search+itemsearch/SearchViewController.m
  47. 31 29
      RedAnt ERP Mobile/common/Functions/sidemenu/CacheViewController.m
  48. 171 169
      RedAnt ERP Mobile/common/Functions/sidemenu/FunctionTestViewController.m
  49. 186 165
      RedAnt ERP Mobile/common/Functions/sidemenu/LoginViewController.m
  50. 214 212
      RedAnt ERP Mobile/common/Functions/sidemenu/UserListViewController.m
  51. 208 160
      RedAnt ERP Mobile/common/Functions/watchlist/WatchListViewController.m
  52. 3 3
      RedAnt ERP Mobile/common/ImageUtils.m
  53. 52 48
      RedAnt ERP Mobile/common/Price Setting/PriceSettingViewController.m
  54. 20 18
      RedAnt ERP Mobile/common/Price Setting/SetCategoryPriceController.m
  55. 7 2
      RedAnt ERP Mobile/common/RAUtils.h
  56. 44 7
      RedAnt ERP Mobile/common/RAUtils.m
  57. 2 2
      RedAnt ERP Mobile/common/customUI/ImageUploadViewController.m
  58. 2 2
      RedAnt ERP Mobile/common/data_provider/RANetwork.h
  59. 568 389
      RedAnt ERP Mobile/common/data_provider/RANetwork.m
  60. 4 1
      RedAnt ERP Mobile/common/data_provider/iSalesDB.h
  61. 22 11
      RedAnt ERP Mobile/common/data_provider/iSalesDB.m
  62. 5 11
      RedAnt ERP Mobile/iSales-NPD.xcodeproj/project.pbxproj
  63. 4 2
      RedAnt ERP Mobile/iSales-NPD/config.h
  64. 2 2
      RedAnt ERP Mobile/iSales-UNITED WAVER.xcodeproj/project.pbxproj
  65. 10 10
      common/InfinitePhoto/Controller/RAPhotoPreviewController.m
  66. 344 327
      common/WK PDF+Web/RAPDFViewController.m
  67. 2 2
      common/upload/RANetworkTaskDelegate.m

+ 19 - 19
Apex Mobile/Apex Mobile/config.h

@@ -13,7 +13,7 @@
 # ifdef DEBUG
 #define DEBUG_DB
 
-#define test_server
+//#define test_server
 //#define old_server
 
 # endif
@@ -41,7 +41,7 @@
     #define URL_SAVE_RESULT     @"http://192.168.50.15:8888/main_new_26.php"
     #define URL_SEARCH_RESULT     @"http://192.168.50.15:8888/main_new_26.php"
     //2020.01.09
-    #define URL_PRIVACY    @"https://ra.apexshipping.com/t/privacyPolicy.html"
+    #define URL_PRIVACY    @"https://ra.apexshipping.com/rc/t/privacyPolicy.html"
 
 #else
     #ifdef old_server
@@ -67,27 +67,27 @@
         #define URL_SEARCH_RESULT     @"http://192.168.50.15:8888/main_new.php"
     #else
 
-        #define URL_HOME                @"https://ra.apexshipping.com/main_new_26.php"
-        #define URL_HISTORY             @"https://ra.apexshipping.com/main_new_26.php"
-        #define URL_UPDATE_AUTH         @"https://ra.apexshipping.com/main_new_26.php"
-        #define URL_REQUEST_COUNT       @"https://ra.apexshipping.com/main_new_26.php"
-        #define URL_REQUEST_RECORDS     @"https://ra.apexshipping.com/main_new_26.php"
-        #define URL_RETRIEVE_PASS       @"https://ra.apexshipping.com/main_new_26.php"
-        #define URL_REQUEST_DETAIL      @"https://ra.apexshipping.com/main_new_26.php"
-        #define URL_ANNOUNCEMENTS       @"https://ra.apexshipping.com/mobile_news.php"
-        #define URL_NEWS                @"https://ra.apexshipping.com/mobile_news.php"
-        #define URL_LOCATIONS           @"https://ra.apexshipping.com/mobile_news26.php"
-        #define URL_PUSH                @"https://ra.apexshipping.com/main_new_26.php"
-        #define URL_KPI                 @"https://ra.apexshipping.com/main_new_26.php"
+        #define URL_HOME                @"https://ra.apexshipping.com/rc/main_new_26.php"
+        #define URL_HISTORY             @"https://ra.apexshipping.com/rc/main_new_26.php"
+        #define URL_UPDATE_AUTH         @"https://ra.apexshipping.com/rc/main_new_26.php"
+        #define URL_REQUEST_COUNT       @"https://ra.apexshipping.com/rc/main_new_26.php"
+        #define URL_REQUEST_RECORDS     @"https://ra.apexshipping.com/rc/main_new_26.php"
+        #define URL_RETRIEVE_PASS       @"https://ra.apexshipping.com/rc/main_new_26.php"
+        #define URL_REQUEST_DETAIL      @"https://ra.apexshipping.com/rc/main_new_26.php"
+        #define URL_ANNOUNCEMENTS       @"https://ra.apexshipping.com/rc/mobile_news.php"
+        #define URL_NEWS                @"https://ra.apexshipping.com/rc/mobile_news.php"
+        #define URL_LOCATIONS           @"https://ra.apexshipping.com/rc/mobile_news26.php"
+        #define URL_PUSH                @"https://ra.apexshipping.com/rc/main_new_26.php"
+        #define URL_KPI                 @"https://ra.apexshipping.com/rc/main_new_26.php"
         #define URL_ERR_LOG             @""
-        #define URL_SEND_COMM_EMAIL     @"https://ra.apexshipping.com/main_new_26.php"
+        #define URL_SEND_COMM_EMAIL     @"https://ra.apexshipping.com/rc/main_new_26.php"
 
         // 2019.1.4
-        #define URL_UPLOAD_SQL     @"https://ra.apexshipping.com/main_new_26.php"
-        #define URL_SAVE_RESULT     @"https://ra.apexshipping.com/main_new_26.php"
-        #define URL_SEARCH_RESULT    @"https://ra.apexshipping.com/main_new_26.php"
+        #define URL_UPLOAD_SQL     @"https://ra.apexshipping.com/rc/main_new_26.php"
+        #define URL_SAVE_RESULT     @"https://ra.apexshipping.com/rc/main_new_26.php"
+        #define URL_SEARCH_RESULT    @"https://ra.apexshipping.com/rc/main_new_26.php"
     //2020.01.09
-    #define URL_PRIVACY    @"https://ra.apexshipping.com/t/privacyPolicy.html"
+    #define URL_PRIVACY    @"https://ra.apexshipping.com/rc/t/privacyPolicy.html"
 
     #endif
 #endif

+ 10 - 2
RA Image/RA Image.xcodeproj/project.pbxproj

@@ -7,6 +7,7 @@
 	objects = {
 
 /* Begin PBXBuildFile section */
+		3C9CCF4A247E4B07006A49A5 /* UIImage+RedAnt.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C9CCF48247E4B07006A49A5 /* UIImage+RedAnt.m */; };
 		4203E5FD21BA5E88003E90BD /* QRCode.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4203E5F321BA5E88003E90BD /* QRCode.storyboard */; };
 		4203E5FE21BA5E88003E90BD /* RAQRCodeScannerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4203E5F521BA5E88003E90BD /* RAQRCodeScannerViewController.m */; };
 		4203E5FF21BA5E88003E90BD /* Camera.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4203E5F721BA5E88003E90BD /* Camera.storyboard */; };
@@ -91,6 +92,8 @@
 /* End PBXBuildFile section */
 
 /* Begin PBXFileReference section */
+		3C9CCF48247E4B07006A49A5 /* UIImage+RedAnt.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "UIImage+RedAnt.m"; path = "../../common/UIImage/UIImage+RedAnt.m"; sourceTree = "<group>"; };
+		3C9CCF49247E4B07006A49A5 /* UIImage+RedAnt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "UIImage+RedAnt.h"; path = "../../common/UIImage/UIImage+RedAnt.h"; sourceTree = "<group>"; };
 		4203E5F321BA5E88003E90BD /* QRCode.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = QRCode.storyboard; sourceTree = "<group>"; };
 		4203E5F421BA5E88003E90BD /* RAQRCodeScannerViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RAQRCodeScannerViewController.h; sourceTree = "<group>"; };
 		4203E5F521BA5E88003E90BD /* RAQRCodeScannerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RAQRCodeScannerViewController.m; sourceTree = "<group>"; };
@@ -445,6 +448,8 @@
 		42BC2D061EBAC74A0016B30D /* Common */ = {
 			isa = PBXGroup;
 			children = (
+				3C9CCF49247E4B07006A49A5 /* UIImage+RedAnt.h */,
+				3C9CCF48247E4B07006A49A5 /* UIImage+RedAnt.m */,
 				71749AFB1ECC199300018EEC /* UIImage+fixOrientation.h */,
 				71749AFC1ECC199300018EEC /* UIImage+fixOrientation.m */,
 				42BC2D071EBAC75F0016B30D /* TouchImageView.h */,
@@ -734,7 +739,7 @@
 		71DCDC2C1EAF234E00BA045A /* Project object */ = {
 			isa = PBXProject;
 			attributes = {
-				LastUpgradeCheck = 1010;
+				LastUpgradeCheck = 1150;
 				ORGANIZATIONNAME = USAI;
 				TargetAttributes = {
 					71DCDC331EAF234E00BA045A = {
@@ -746,7 +751,7 @@
 			};
 			buildConfigurationList = 71DCDC2F1EAF234E00BA045A /* Build configuration list for PBXProject "RA Image" */;
 			compatibilityVersion = "Xcode 3.2";
-			developmentRegion = English;
+			developmentRegion = en;
 			hasScannedForEncodings = 0;
 			knownRegions = (
 				en,
@@ -849,6 +854,7 @@
 				42BC2CFF1EBAC4050016B30D /* PhotoListViewController.m in Sources */,
 				71114ABC1EB1C73400D2200C /* ZipArchive.mm in Sources */,
 				42056E871EB9CF5D0010597A /* BasicModeViewController.m in Sources */,
+				3C9CCF4A247E4B07006A49A5 /* UIImage+RedAnt.m in Sources */,
 				42E1B0FE1EB1C8EE00EEF27C /* LoginTextFiledCell.m in Sources */,
 				71961CB01EC00DDD002C4096 /* RANetworkTaskDelegate.m in Sources */,
 				42A829D21EBC6D3300898B8A /* UploadCell.m in Sources */,
@@ -885,6 +891,7 @@
 			isa = XCBuildConfiguration;
 			buildSettings = {
 				ALWAYS_SEARCH_USER_PATHS = NO;
+				CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
 				CLANG_ANALYZER_NONNULL = YES;
 				CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
 				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
@@ -941,6 +948,7 @@
 			isa = XCBuildConfiguration;
 			buildSettings = {
 				ALWAYS_SEARCH_USER_PATHS = NO;
+				CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
 				CLANG_ANALYZER_NONNULL = YES;
 				CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
 				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";

+ 62 - 55
RA Image/RA Image/BasicModeViewController.m

@@ -684,67 +684,74 @@
 
 -(void) verify:(NSMutableDictionary*) params
 {
-     AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
+//     AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
 //    appDelegate.address = self.address;
     __weak typeof(self) weakself = self;
     NSString* title=[@"Verify " stringByAppendingString:self.barcodeTitle];
-    UIAlertView *alert = [RAUtils waiting_alert:@"Please wait" title:title];
-    dispatch_async(dispatch_get_global_queue(0, 0), ^{
-    //    if (weakself) {
-//            __strong typeof(weakself) strongself = weakself;
-            NSDictionary *result_json = [RANetwork Verify:params];
-            dispatch_async(dispatch_get_main_queue(), ^{
-                [alert dismissWithClickedButtonIndex:0 animated:YES];
-                int result = [[result_json objectForKey:@"result"] intValue];
-//                BOOL rememberLogin = [[strongself userDefaultsValue:kRememberLogin] boolValue];
-//                [self addTasks];
-//                return;
-                switch (result) {
-                    case 0:
-                    {
-                        //code not exist;
-                        
-                        [RAUtils message_alert:weakself.verify_msg0 title:@"Warring" controller:weakself];
-//                            [weakself.view makeToast:weakself.verify_msg0 duration:3.0 position:CSToastPositionCenter];
-                        break;
-                    }
-                    case 1:
-                    {
-                        
-                        [RAUtils message_alert:@"Model/Manufacturer does not match" title:@"Warring" controller:weakself];
-//                                                    [weakself.view makeToast:@"Model/Manufacturer does not match" duration:3.0 position:CSToastPositionCenter];
-                        break;
-                    }
-                    case 2:
-                    {
-                        //upload;
-                        [self addTasks];
-                        break;
-                    }
-                    case RESULT_NET_ERROR:
-                    {
-                        __weak typeof(self) weakSelf = self;
-                        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:@"Can not connect to server,still upload?" preferredStyle:UIAlertControllerStyleAlert];
-                        UIAlertAction *yesAction = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-                            [weakSelf addTasks];
-                        }];
-                        
-                        UIAlertAction *noAction = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
-                            
+    
+    __block UIAlertController* alertc = [RAUtils waiting_alert:self title:title completion:^{
+        dispatch_async(dispatch_get_global_queue(0, 0), ^{
+            //    if (weakself) {
+        //            __strong typeof(weakself) strongself = weakself;
+                    NSDictionary *result_json = [RANetwork Verify:params];
+                    dispatch_async(dispatch_get_main_queue(), ^{
+//                        [alert dismissWithClickedButtonIndex:0 animated:YES];
+                        [alertc dismissViewControllerAnimated:YES completion:^{
+                            int result = [[result_json objectForKey:@"result"] intValue];
+                            //                BOOL rememberLogin = [[strongself userDefaultsValue:kRememberLogin] boolValue];
+                            //                [self addTasks];
+                            //                return;
+                                            switch (result) {
+                                                case 0:
+                                                {
+                                                    //code not exist;
+                                                    
+                                                    [RAUtils message_alert:weakself.verify_msg0 title:@"Warring" controller:weakself];
+                            //                            [weakself.view makeToast:weakself.verify_msg0 duration:3.0 position:CSToastPositionCenter];
+                                                    break;
+                                                }
+                                                case 1:
+                                                {
+                                                    
+                                                    [RAUtils message_alert:@"Model/Manufacturer does not match" title:@"Warring" controller:weakself];
+                            //                                                    [weakself.view makeToast:@"Model/Manufacturer does not match" duration:3.0 position:CSToastPositionCenter];
+                                                    break;
+                                                }
+                                                case 2:
+                                                {
+                                                    //upload;
+                                                    [self addTasks];
+                                                    break;
+                                                }
+                                                case RESULT_NET_ERROR:
+                                                {
+                                                    __weak typeof(self) weakSelf = self;
+                                                    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:@"Can not connect to server,still upload?" preferredStyle:UIAlertControllerStyleAlert];
+                                                    UIAlertAction *yesAction = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+                                                        [weakSelf addTasks];
+                                                    }];
+                                                    
+                                                    UIAlertAction *noAction = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
+                                                        
+                                                    }];
+                                                    [alertVC addAction:yesAction];
+                                                    [alertVC addAction:noAction];
+                                                    [self presentViewController:alertVC animated:yesAction completion:nil];
+                                                    
+                                                }
+                                                default:
+                                                    break;
+                                            }
                         }];
-                        [alertVC addAction:yesAction];
-                        [alertVC addAction:noAction];
-                        [self presentViewController:alertVC animated:yesAction completion:nil];
                         
-                    }
-                    default:
-                        break;
-                }
-               
+                       
+                    });
+                    
+              //  }
             });
-            
-      //  }
-    });
+    }];
+//    UIAlertView *alert = [RAUtils waiting_alert:@"Please wait" title:title];
+    
 }
 
 @end

+ 5 - 1
RA Image/RA Image/LoginSettingViewController.m

@@ -199,7 +199,11 @@
             //                    strongself.externalTextField.text = externalAddr;
         }
         else {
-            [RAUtils alert_view:@"Wrong QR-CODE?" title:@"Can not setup server"];
+            
+            
+            [RAUtils message_alert:@"Wrong QR-CODE?" title:@"Can not setup server" controller:self];
+            
+//            [RAUtils alert_view:@"Wrong QR-CODE?" title:@"Can not setup server"];
             //                    strongself.nameTextField.text = nil;
             //                    strongself.internalTextField.text = [dataArr firstObject];
             //                    strongself.externalTextField.text = nil;

+ 38 - 29
RA Image/RA Image/LoginViewController.m

@@ -212,36 +212,45 @@ static NSString *kLoginUserInfo = @"UserInfo";
     AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
     appDelegate.address = self.address;
     __weak typeof(self) weakself = self;
-    UIAlertView *alert = [RAUtils waiting_alert:@"Please wait" title:@"Login"];
-    dispatch_async(dispatch_get_global_queue(0, 0), ^{
-        if (weakself) {
-            __strong typeof(weakself) strongself = weakself;
-            NSDictionary *loginDic = [RANetwork Login:strongself.user password:strongself.pwd];
-            dispatch_async(dispatch_get_main_queue(), ^{
-                [alert dismissWithClickedButtonIndex:0 animated:YES];
-                int result = [[loginDic objectForKey:@"result"] intValue];
-                BOOL rememberLogin = [[strongself userDefaultsValue:kRememberLogin] boolValue];
-                if (result == RESULT_TRUE) {
-                    if (!rememberLogin) {
-                        [self setUserDefaultsValue:nil forKey:kLoginUserInfo];
-                    } else {
-                        [strongself setUserDefaultsValue:@{@"address" : strongself.address,@"user" : strongself.user,@"pwd" : strongself.pwd} forKey:kLoginUserInfo];
-                    }
-                    appDelegate.bLogin = YES;
-                    appDelegate.user = strongself.user;
-                    appDelegate.password = strongself.pwd;
-                    appDelegate.companyName = [loginDic objectForKey:@"company_name"];
-                    [appDelegate loadCompanyIcon:[loginDic objectForKey:@"company_icon"]];
-                    appDelegate.modeList = [loginDic objectForKey:@"modellist"];
-                    [appDelegate showNormalRootVC];
-                } else {
-                    NSString *msg = [loginDic objectForKey:@"err_msg"];
-                    [RAUtils message_alert:msg title:@"Warning" controller:strongself];
-                }
-            });
+    
+//    UIAlertView *alert = [RAUtils waiting_alert:@"Please wait" title:@"Login"];
+   __block UIAlertController* alert = [RAUtils waiting_alert:self title:@"Login" completion:^{
+        dispatch_async(dispatch_get_global_queue(0, 0), ^{
+            if (weakself) {
+                __strong typeof(weakself) strongself = weakself;
+                NSDictionary *loginDic = [RANetwork Login:strongself.user password:strongself.pwd];
+                dispatch_async(dispatch_get_main_queue(), ^{
+//                    [alert dismissWithClickedButtonIndex:0 animated:YES];
+                    
+                    [alert dismissViewControllerAnimated:YES completion:^{
+                        int result = [[loginDic objectForKey:@"result"] intValue];
+                        BOOL rememberLogin = [[strongself userDefaultsValue:kRememberLogin] boolValue];
+                        if (result == RESULT_TRUE) {
+                            if (!rememberLogin) {
+                                [self setUserDefaultsValue:nil forKey:kLoginUserInfo];
+                            } else {
+                                [strongself setUserDefaultsValue:@{@"address" : strongself.address,@"user" : strongself.user,@"pwd" : strongself.pwd} forKey:kLoginUserInfo];
+                            }
+                            appDelegate.bLogin = YES;
+                            appDelegate.user = strongself.user;
+                            appDelegate.password = strongself.pwd;
+                            appDelegate.companyName = [loginDic objectForKey:@"company_name"];
+                            [appDelegate loadCompanyIcon:[loginDic objectForKey:@"company_icon"]];
+                            appDelegate.modeList = [loginDic objectForKey:@"modellist"];
+                            [appDelegate showNormalRootVC];
+                        } else {
+                            NSString *msg = [loginDic objectForKey:@"err_msg"];
+                            [RAUtils message_alert:msg title:@"Warning" controller:strongself];
+                        }
+                    }];
+                    
+                    
+                });
 
-        }
-    });
+            }
+        });
+    }];
+    
 }
 
 - (IBAction)settingBtnClick:(UIButton *)sender {

+ 36 - 28
RA Image/RA Image/ModelModeViewController.m

@@ -239,35 +239,43 @@
     
     // 从服务器取Manufacture
     if (barcode.length > 0) {
-        UIAlertView *alert = [RAUtils waiting_alert:@"Loading model's manufactures" title:@"Waiting"];
-        dispatch_async(dispatch_get_global_queue(0, 0), ^{
-            NSDictionary *modelManufacturs = [RANetwork getModelManufacture:barcode];
-            dispatch_async(dispatch_get_main_queue(), ^{
-                [alert dismissWithClickedButtonIndex:0 animated:YES];
-                int result = [[modelManufacturs objectForKey:@"result"] intValue];
-                if (result == 2) {
-                    NSArray *manufacturs = [modelManufacturs objectForKey:@"manufacturer"];
-                    if (manufacturs.count > 0) {
-                        self.manufacturerList = manufacturs;
-                        NSString *manufacter = nil;
-                        if (manufacturs.count == 1) {
-                            manufacter = [manufacturs objectAtIndex:0];
-                        } else {
-                            manufacter = nil;
-                        }
-                        self.manufacturer = manufacter;
-                    } else {
-                        self.manufacturerList = manufacturs;
-                        self.manufacturer = nil;
-                    }
-                } else {
-                    self.manufacturerList = self.oldManufacturerList;
-                    self.manufacturer = nil;
-                }
+        
+        __block UIAlertController* alertc=[RAUtils waiting_alert:self title:@"Loading model's manufactures" completion:^{
+            dispatch_async(dispatch_get_global_queue(0, 0), ^{
+                NSDictionary *modelManufacturs = [RANetwork getModelManufacture:barcode];
+                dispatch_async(dispatch_get_main_queue(), ^{
+//                    [alert dismissWithClickedButtonIndex:0 animated:YES];
+                    [alertc dismissViewControllerAnimated:YES completion:^{
+                        int result = [[modelManufacturs objectForKey:@"result"] intValue];
+                                           if (result == 2) {
+                                               NSArray *manufacturs = [modelManufacturs objectForKey:@"manufacturer"];
+                                               if (manufacturs.count > 0) {
+                                                   self.manufacturerList = manufacturs;
+                                                   NSString *manufacter = nil;
+                                                   if (manufacturs.count == 1) {
+                                                       manufacter = [manufacturs objectAtIndex:0];
+                                                   } else {
+                                                       manufacter = nil;
+                                                   }
+                                                   self.manufacturer = manufacter;
+                                               } else {
+                                                   self.manufacturerList = manufacturs;
+                                                   self.manufacturer = nil;
+                                               }
+                                           } else {
+                                               self.manufacturerList = self.oldManufacturerList;
+                                               self.manufacturer = nil;
+                                           }
+                    }];
+                   
+                });
+
+                
             });
-
-            
-        });
+        }];
+        
+      
+        
     }
 }
 

+ 29 - 21
RA Image/RA Image/RootViewController.m

@@ -198,27 +198,35 @@ static NSString *kLastMode = @"lastChooseMode";
     
 #ifndef PROJ_RAMOBILE
     //如果是Redant Mobile 集成的,就没有logout
-    UIAlertView *alert = [RAUtils waiting_alert:@"Please wait..." title:@"Logout"];
-    __weak typeof(self) weakself = self;
-    dispatch_async(dispatch_get_main_queue(), ^{
-        
-        NSDictionary *logoutDic = [RANetwork logout];
-        int result = [[logoutDic objectForKey:@"result"] intValue];
-        dispatch_async(dispatch_get_main_queue(), ^{
-            [alert dismissWithClickedButtonIndex:0 animated:YES];
-            AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
-            if (result == RESULT_TRUE) {
-                weakself.companyIcon = [UIImage imageNamed:@"AppIcon40x40"];
-                [appDelegate logout];
-            } else {
-                __strong typeof(weakself) strongself = weakself;
-                NSString *msg = [logoutDic objectForKey:@"err_msg"];
-                [RAUtils message_alert:msg title:@"Warning" controller:strongself];
-            }
-        });
-        
-        
-    });
+    
+
+    __block UIAlertController* alertcontroller= [RAUtils waiting_alert:self title:@"Logout" completion:^{
+        __weak typeof(self) weakself = self;
+           dispatch_async(dispatch_get_main_queue(), ^{
+               
+               NSDictionary *logoutDic = [RANetwork logout];
+               int result = [[logoutDic objectForKey:@"result"] intValue];
+               dispatch_async(dispatch_get_main_queue(), ^{
+//                   [alert dismissWithClickedButtonIndex:0 animated:YES];
+                   [alertcontroller dismissViewControllerAnimated:true completion:^{
+                       AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
+                       if (result == RESULT_TRUE) {
+                           weakself.companyIcon = [UIImage imageNamed:@"AppIcon40x40"];
+                           [appDelegate logout];
+                       } else {
+                           __strong typeof(weakself) strongself = weakself;
+                           NSString *msg = [logoutDic objectForKey:@"err_msg"];
+                           [RAUtils message_alert:msg title:@"Warning" controller:strongself];
+                       }
+                   }];
+
+               });
+               
+               
+           });
+    }];
+ //   UIAlertView *alert = [RAUtils waiting_alert:@"Please wait..." title:@"Logout"];
+   
     
 #endif
     

+ 3 - 1
RA Image/RA Image/UploadViewController.m

@@ -45,7 +45,9 @@
     AppDelegate* appdelegate = (AppDelegate* )[UIApplication sharedApplication].delegate;
     if(appdelegate.uploadManager.arr_queue.count==0)
     {
-        [RAUtils alert_view:nil title:@"Upload list is empty."];
+
+        [RAUtils message_alert:nil title:@"Upload list is empty." controller:self];
+//        [RAUtils alert_view:nil title:@"Upload list is empty."];
         return;
     }
     UIAlertController *alert = [UIAlertController alertControllerWithTitle:

+ 1 - 1
RedAnt CRM/APEX CRM/APEX CRM/config/config.h

@@ -12,7 +12,7 @@
 # ifdef DEBUG
 
 
-#define test_server
+//#define test_server
 
 
 # endif

+ 20 - 1
RedAnt ERP Mobile/common/ActiveViewController.m

@@ -130,7 +130,7 @@
         [appDelegate popFeedback:self];
         //        appDelegate.eventsFeedback = self;
     }
-    [super routerEvent:RA_NOTIFICATION_RELEASE_SCANNER Info:nil];
+//    [super routerEvent:RA_NOTIFICATION_RELEASE_SCANNER Info:nil];
 #endif
     [super viewDidDisappear:animated];
 }
@@ -286,6 +286,25 @@
 }
 
 #pragma mark - Notification
+//-(void)OnReleaseScanner:(NSNotification *)notification
+//{
+//    if(!self.support_scanner)
+//        return;
+//    else
+//        {
+//                    int a=0;
+//
+//                    UIApplication * app = [UIApplication sharedApplication];
+//                    AppDelegate *appDelegate = (AppDelegate *)[app delegate];
+//
+//                    if(self.support_scanner)
+//                    {
+//                        appDelegate.eventsFeedback = self;
+//                    }
+//
+//            }
+//    NSLog(@"release scanner !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+//}
 - (void)OnUpdatePrice: (NSNotification *)notification
 {
                     if(self.disable_refresh)

+ 1 - 1
RedAnt ERP Mobile/common/AppDelegateBase.h

@@ -146,7 +146,7 @@ typedef enum {
 -(void) update_count_mark;
 // downloader
 -(void) check_offline:(NSString*) ver useInternalAddress:(bool)buseinternaladdress parentvc:(UIViewController*) parent;
-@property bool disable_trigger;
+//@property bool disable_trigger;
 
 @property (nonatomic, strong) SyncControlPanelViewController *settingUI;
 @property (nonatomic, strong) NSFileHandle *fileHandle;

+ 158 - 89
RedAnt ERP Mobile/common/AppDelegateBase.m

@@ -140,7 +140,8 @@
     
 #ifdef RA_NOTIFICATION
     [ActiveViewController Notify:@"ContactListViewController" Message:RA_NOTIFICATION_REFRESH_UI];
-    [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+    //切换账号应该不需要刷新wishlist,此处如果刷新,会使wishlist新建订单自动添加出错。
+//    [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
     
 #else
     [((MainViewController*)self.main_vc) reloadContact:false immediately:false];
@@ -327,6 +328,10 @@
             
             
         }
+        
+        
+        
+        
     });
     
     
@@ -594,8 +599,12 @@ void UncaughtExceptionHandler(NSException *exception) {
     }
     [iSalesDB execSql:sql];
     
-    AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
-    [appDelegate writeUrgencyCache];
+    
+    dispatch_async(dispatch_get_main_queue(), ^{
+        AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
+        [appDelegate writeUrgencyCache];
+
+    });
 }
 
 - (void)handleErrorLog {
@@ -680,7 +689,7 @@ void UncaughtExceptionHandler(NSException *exception) {
         [self.urgencyDic removeAllObjects];
         [self.urgencyDic setObject:[NSNumber numberWithInt:0] forKey:@"count"];
         
-        MainViewController *mainVC = [self.window.rootViewController.childViewControllers lastObject];
+        
 //        UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
         
         NSString *user = [tmp_urgencyDic objectForKey:@"user"];
@@ -736,10 +745,11 @@ void UncaughtExceptionHandler(NSException *exception) {
                     
                     //            cuseditVC.delegate=self;
                     
-                    
+                              
+                    MainViewController *mainVC = [self.window.rootViewController.childViewControllers lastObject];
                     [[mainVC navigationController] setNavigationBarHidden:NO animated:NO];
                     [mainVC.navigationController pushViewController:cuseditVC animated:false];
-                    
+                              
                     
                     
                 } else if ([className isEqualToString:@"CreateOrderViewController"] || [className isEqualToString:@"RAOrderEditorViewController"]) {
@@ -782,6 +792,7 @@ void UncaughtExceptionHandler(NSException *exception) {
 #ifdef RA_NOTIFICATION
                             [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
 #else
+                            MainViewController *mainVC = [self.window.rootViewController.childViewControllers lastObject];
                             [mainVC reloadOrder:true immediately:false];
                             [mainVC reloadCart:true immediately:false];
 #endif
@@ -789,6 +800,7 @@ void UncaughtExceptionHandler(NSException *exception) {
                         }
                         else
                         {
+                            MainViewController *mainVC = [self.window.rootViewController.childViewControllers lastObject];
                             [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order" controller:mainVC] ;
                         }
                         
@@ -850,7 +862,7 @@ void UncaughtExceptionHandler(NSException *exception) {
                         orderinfoVC.params = params;
                         orderinfoVC.content_data_download = restored_data;
                         orderinfoVC.resumeOrder = YES;
-                        
+                        MainViewController *mainVC = [self.window.rootViewController.childViewControllers lastObject];
                         [mainVC.navigationController pushViewController:orderinfoVC animated:true];
                     }
 #ifdef BACKORDER_PROCESS
@@ -860,6 +872,7 @@ void UncaughtExceptionHandler(NSException *exception) {
                         
                         RAOrderEditorViewController *orderEditorVC = [[RAOrderEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
                         [orderEditorVC recoveryFromUrgencyDic:urgencyDic];
+                        MainViewController *mainVC = [self.window.rootViewController.childViewControllers lastObject];
                         [mainVC.navigationController pushViewController:orderEditorVC animated:YES];
                     }
 #endif
@@ -879,7 +892,7 @@ void UncaughtExceptionHandler(NSException *exception) {
                     addressVC.params = params;
                     addressVC.content_data_download = restored_data;
                     
-                    
+                    MainViewController *mainVC = [self.window.rootViewController.childViewControllers lastObject];
                     [mainVC.navigationController pushViewController:addressVC animated:true];
                     
                 }// class_name
@@ -1080,7 +1093,7 @@ void UncaughtExceptionHandler(NSException *exception) {
     
     // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
     // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
-#if defined(GOOGLE_ANALYTICS) || defined(BUILD_USAI)
+#if defined(GOOGLE_ANALYTICS) 
     NSTimeInterval timing = [[NSDate date] timeIntervalSinceDate:self.forgroundDate];
     self.forgroundDate = nil;
 
@@ -1228,30 +1241,34 @@ void UncaughtExceptionHandler(NSException *exception) {
         }
     });
 }
--(void) upload_offline:(NSString*) ver useInternalAddress:(bool)buseinternaladdress orderid:(NSArray*)arr_order
+-(void) upload_offline:(NSString*) ver useInternalAddress:(bool)buseinternaladdress orderid:(NSArray*)arr_order params:(NSMutableDictionary*) add_params
 {
+    
+    assert(add_params[@"user"]!=nil);
+    assert(add_params[@"password"]!=nil);
+//    assert(add_params[@"contact_id"]!=nil);
     [self add_downloadlog:@"Begin sync, please wait."];
     [self add_downloadlog:@"Prepare upload data."];
     //   NSArray* arr_order=[OLDataProvider enumOfflineOrder];
-    NSDictionary* upjson=[OLDataProvider prepareUpload:arr_order];
+    NSDictionary* upjson=[OLDataProvider prepareUpload:arr_order params:add_params];
     
     NSString* upfile=upjson[@"file"];
     
     {
         NSData* data = [NSData dataWithContentsOfFile: upfile];
-        UIApplication * app = [UIApplication sharedApplication];
-        AppDelegate *appDelegate = (AppDelegate *)[app delegate];
+//        UIApplication * app = [UIApplication sharedApplication];
+//        AppDelegate *appDelegate = (AppDelegate *)[app delegate];
         
         [ERPUtils googleAnalyticsSendRequestString:nil WithScreen:ScreenCodeOfflineSync Action:nil Extra:nil];
         
         NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
         
-        if(appDelegate.user!=nil)
-            [params setValue:appDelegate.user forKey:@"user"];
+        if(add_params[@"user"]!=nil)
+            [params setValue:add_params[@"user"] forKey:@"user"];
         //    if(appDelegate.contact_id!=nil)
         //        [params setValue:appDelegate.contact_id forKey:@"contactId"];
-        if(appDelegate.password!=nil)
-            [params setValue:appDelegate.password forKey:@"password"];
+        if(add_params[@"password"]!=nil)
+            [params setValue:add_params[@"password"] forKey:@"password"];
         
         
 #if TARGET_IPHONE_SIMULATOR//模拟器
@@ -1266,56 +1283,66 @@ 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];
-                }
-                
-                [weakSelf add_downloadlog:@"Upload successful."];
-                appDelegate.disable_trigger=true;
-                NSString* so_id=[RAConvertor arr2string:arr_order separator:@"," trim:true brackets:@"'"];
-                
-                [iSalesDB execSql:@"delete from offline_contact where not sync_data is null"];
-                [iSalesDB execSql:@"delete from wishlist"];
-                [iSalesDB execSql:[NSString stringWithFormat:@"delete from offline_order where so_id in(%@)",so_id]];
-                [iSalesDB execSql:[NSString stringWithFormat:@"delete from offline_cart where so_no in(%@)",so_id]];
-                [iSalesDB execSql:@"delete from offline_portfolio"];
-                [iSalesDB execSql:@"delete from offline_pdf"];
-                [OLDataProvider offline_clear_PDFCache];
-                
-                NSString* contactMap = json[@"contactMap"];
-                if(contactMap.length>0)
-                {
-                    NSDictionary* contactjson = [RAConvertor string2dict:contactMap];
-                    NSArray *keys= [contactjson allKeys];
-                    //遍历keys
-                    for(int i=0;i<[keys count];i++)
-                    {
-                        //得到当前key
-                        NSString *key=[keys objectAtIndex:i];
-                        //如果key不是pic,说明value是字符类型,比如name:Boris
-                        NSString* value = [contactjson valueForKey:key];
-                        
-                        [iSalesDB execSql:[NSString stringWithFormat:@"update offline_order set customer_cid='%@' where customer_cid='%@' and order_id is null",value,key]];
-                        [iSalesDB execSql:[NSString stringWithFormat:@"update offline_order set customer_cid='%@' where receive_cid='%@' and order_id is null",value,key]];
-                        [iSalesDB execSql:[NSString stringWithFormat:@"update offline_order set customer_cid='%@' where sender_cid='%@' and order_id is null",value,key]];
-                        [iSalesDB execSql:[NSString stringWithFormat:@"update offline_order set customer_cid='%@' where shipping_billto_cid='%@' and order_id is null",value,key]];
-                        [iSalesDB execSql:[NSString stringWithFormat:@"update offline_order set customer_cid='%@' where billing_cid='%@' and order_id is null",value,key]];
-                        [iSalesDB execSql:[NSString stringWithFormat:@"update offline_order set customer_cid='%@' where returnto_cid='%@' and order_id is null",value,key]];
-                        
-                    }
-                }
-                //                    NSDictionary* contactjson= upjson[@"contact"];
-                //                    NSDictionary* wishlistjson= upjson[@"wishlist"];
-                //                    NSDictionary* orderjson= upjson[@"order"];
-                
-                appDelegate.disable_trigger=false;
-                NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
-                [defaults removeObjectForKey:@"Forcedownload"];
-                [defaults setBool:true forKey:@"Forcedownload"];
-                [defaults synchronize];
+               
+                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+                    // 清理数据库要放入线程中执行
+                     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];
+                                    }
+                                    
+                                    [weakSelf add_downloadlog:@"Upload successful."];
+                    //                [iSalesDB disable_trigger]
+                                    [iSalesDB disable_trigger];
+                                    NSString* so_id=[RAConvertor arr2string:arr_order separator:@"," trim:true brackets:@"'"];
+                                    
+                                    [iSalesDB execSql:@"delete from offline_contact where not sync_data is null"];
+                                    [iSalesDB execSql:@"delete from wishlist"];
+                                    [iSalesDB execSql:[NSString stringWithFormat:@"delete from offline_order where so_id in(%@)",so_id]];
+                                    [iSalesDB execSql:[NSString stringWithFormat:@"delete from offline_cart where so_no in(%@)",so_id]];
+                                    [iSalesDB execSql:@"delete from offline_portfolio"];
+                                    [iSalesDB execSql:@"delete from offline_pdf"];
+                                    [OLDataProvider offline_clear_PDFCache];
+                                    
+                                    NSString* contactMap = json[@"contactMap"];
+                                    if(contactMap.length>0)
+                                    {
+                                        NSDictionary* contactjson = [RAConvertor string2dict:contactMap];
+                                        NSArray *keys= [contactjson allKeys];
+                                        //遍历keys
+                                        for(int i=0;i<[keys count];i++)
+                                        {
+                                            //得到当前key
+                                            NSString *key=[keys objectAtIndex:i];
+                                            //如果key不是pic,说明value是字符类型,比如name:Boris
+                                            NSString* value = [contactjson valueForKey:key];
+                                            
+                                            [iSalesDB execSql:[NSString stringWithFormat:@"update offline_order set customer_cid='%@' where customer_cid='%@' and order_id is null",value,key]];
+                                            [iSalesDB execSql:[NSString stringWithFormat:@"update offline_order set customer_cid='%@' where receive_cid='%@' and order_id is null",value,key]];
+                                            [iSalesDB execSql:[NSString stringWithFormat:@"update offline_order set customer_cid='%@' where sender_cid='%@' and order_id is null",value,key]];
+                                            [iSalesDB execSql:[NSString stringWithFormat:@"update offline_order set customer_cid='%@' where shipping_billto_cid='%@' and order_id is null",value,key]];
+                                            [iSalesDB execSql:[NSString stringWithFormat:@"update offline_order set customer_cid='%@' where billing_cid='%@' and order_id is null",value,key]];
+                                            [iSalesDB execSql:[NSString stringWithFormat:@"update offline_order set customer_cid='%@' where returnto_cid='%@' and order_id is null",value,key]];
+                                            
+                                        }
+                                    }
+                                    //                    NSDictionary* contactjson= upjson[@"contact"];
+                                    //                    NSDictionary* wishlistjson= upjson[@"wishlist"];
+                                    //                    NSDictionary* orderjson= upjson[@"order"];
+                                    
+                    //                [iSalesDB enable_trigger]
+                                    [iSalesDB enable_trigger];
+                                    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+                                    [defaults removeObjectForKey:@"Forcedownload"];
+                                    [defaults setBool:true forKey:@"Forcedownload"];
+                                    [defaults synchronize];
+                    
+                    dispatch_async(dispatch_get_main_queue(), ^{
+                        //下载函数要从主线程调用
+                       [weakSelf download_offline:ver useInternalAddress:buseinternaladdress];
+                    });
+                });
                 
-                [weakSelf download_offline:ver useInternalAddress:buseinternaladdress];
                 
             }
             else
@@ -1386,7 +1413,7 @@ void UncaughtExceptionHandler(NSException *exception) {
         //                    }
         //
         //                    [self add_downloadlog:@"Upload successful."];
-        //                    appDelegate.disable_trigger=true;
+        //                    [iSalesDB disable_trigger]
         //                    NSString* so_id=[RAUtils arr2string:arr_order separator:@"," trim:true brackets:@"'"];
         //
         //                    [iSalesDB execSql:@"delete from offline_contact where not sync_data is null"];
@@ -1423,7 +1450,7 @@ void UncaughtExceptionHandler(NSException *exception) {
         //                    //                    NSDictionary* wishlistjson= upjson[@"wishlist"];
         //                    //                    NSDictionary* orderjson= upjson[@"order"];
         //
-        //                    appDelegate.disable_trigger=false;
+        //                    [iSalesDB enable_trigger]
         //                    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
         //                    [defaults removeObjectForKey:@"Forcedownload"];
         //                    [defaults setBool:true forKey:@"Forcedownload"];
@@ -1534,6 +1561,27 @@ void UncaughtExceptionHandler(NSException *exception) {
             
             [RANetwork request_download_offline:downSerial completionHandler:^(NSMutableDictionary *result) {
                 download_json=result;
+                
+                if([download_json[@"result"] intValue]!=RESULT_TRUE)
+                {
+                    [self add_downloadlog:download_json[@"err_msg"]];
+                    dispatch_async(dispatch_get_main_queue(), ^{
+                        //                    self.downloadlog=nil;
+                        self.downloading=false;
+                        
+                        NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+                        
+                        [defaults removeObjectForKey:@"Forcedownload"];
+                        [defaults setBool:true forKey:@"Forcedownload"];
+                        //                                           NSString * downSerial = [defaults valueForKey:@"downSerial"];
+                        //                                           [defaults removeObjectForKey:@"downSerial"];
+                        //                                           [defaults removeObjectForKey:@"OFFLINE_DIRTY"];
+                        //                                           [defaults setBool:FALSE forKey:@"OFFLINE_DIRTY"];
+                        [defaults synchronize];
+                        [ [ UIApplication sharedApplication] setIdleTimerDisabled:NO ] ;
+                    });
+                    return;
+                }
                 //服务器准备数据完毕,进入处理数据逻辑。
                 if([download_json[@"request_count"] intValue]>=REQUEST_DOWNLOAD_RETRY_TIMES)
                 {
@@ -1558,10 +1606,21 @@ void UncaughtExceptionHandler(NSException *exception) {
                         dispatch_async(dispatch_get_main_queue(), ^{
                             //                    self.downloadlog=nil;
                             self.downloading=false;
-                        });
-                        dispatch_async(dispatch_get_main_queue(), ^{
+                            
+                            NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+                            
+                            [defaults removeObjectForKey:@"Forcedownload"];
+                            [defaults setBool:FALSE forKey:@"Forcedownload"];
+                            //                                           NSString * downSerial = [defaults valueForKey:@"downSerial"];
+                            //                                           [defaults removeObjectForKey:@"downSerial"];
+                            //                                           [defaults removeObjectForKey:@"OFFLINE_DIRTY"];
+                            //                                           [defaults setBool:FALSE forKey:@"OFFLINE_DIRTY"];
+                            [defaults synchronize];
                             [ [ UIApplication sharedApplication] setIdleTimerDisabled:NO ] ;
                         });
+//                        dispatch_async(dispatch_get_main_queue(), ^{
+//
+//                        });
                         [self.settingUI onSyncFinish];
                         return;
                     }
@@ -1769,22 +1828,28 @@ void UncaughtExceptionHandler(NSException *exception) {
         //
         //        }
         //        else
-        {
-            [self upload_offline:ver useInternalAddress:buseinternaladdress orderid:arr_order];
-            SyncControlPanelViewController * syncVC =[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"SyncControlPanelViewController"];
-            syncVC.action_string=@"Download";
-            UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:syncVC] ;
-            navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
-            [parent presentViewController:navi animated:YES completion:^{
-                
-                //        navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
-                
-                DebugLog(@"about present.........");
-                
-                //   self.btop = false;
-                //  <#code#>
-            }];
-        }
+        //        {
+        
+
+        NSMutableDictionary* add_params=[NSMutableDictionary new];
+        add_params[@"user"]=self.user;
+        add_params[@"password"]=self.password;
+        add_params[@"contact_id"]=self.contact_id;
+        [self upload_offline:ver useInternalAddress:buseinternaladdress orderid:arr_order params:add_params];
+        SyncControlPanelViewController * syncVC =[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"SyncControlPanelViewController"];
+        syncVC.action_string=@"Download";
+        UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:syncVC] ;
+        navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
+        [parent presentViewController:navi animated:YES completion:^{
+            
+            //        navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
+            
+            DebugLog(@"about present.........");
+            
+            //   self.btop = false;
+            //  <#code#>
+        }];
+        //        }
         
     }
     
@@ -2507,7 +2572,9 @@ void UncaughtExceptionHandler(NSException *exception) {
                 
                 @try {
                     char *errmsg=NULL;
-                    appDelegate.disable_trigger=true;
+//                    [iSalesDB disable_trigger]
+                    [iSalesDB disable_trigger];
+                    
                     if (sqlite3_exec(tdb, "begin", NULL, NULL, &errmsg)==SQLITE_OK)
                     {
                         
@@ -2594,7 +2661,8 @@ void UncaughtExceptionHandler(NSException *exception) {
                 }
                 @finally {
                     
-                    appDelegate.disable_trigger=false;
+//                    [iSalesDB enable_trigger]
+                    [iSalesDB enable_trigger];
                     sqlite3_close(tdb);
                     // [iSalesDB close_db:tdb];
                     //  [self SelectData];
@@ -2734,7 +2802,8 @@ void UncaughtExceptionHandler(NSException *exception) {
     self.window.backgroundColor = [UIColor whiteColor];
     
     //    [RAUtils expression_varable:nil regex:nil];
-    self.disable_trigger = false;
+//    self.disable_trigger = false;
+    [iSalesDB enable_trigger];
     [self initialExceptionHandler];
     [self becomeObserver];
 #ifdef GOOGLE_ANALYTICS

+ 238 - 234
RedAnt ERP Mobile/common/CartUtils.m

@@ -18,50 +18,52 @@
 +(void) neworder:(UIViewController*) vc selectorholder:(id)holder selector:(SEL)addtocart
 {
 
-    UIAlertController * waitalert = [RAUtils waiting_alert:vc title:@"Create Order"];
-    [RANetwork request_create_order:^(NSMutableDictionary *result) {
-        NSMutableDictionary* return_json = result;
-        
-        [waitalert dismissViewControllerAnimated:YES completion:^{
-            if([[return_json valueForKey:@"result"] intValue]==2)
-            {
-                int result=[[return_json valueForKey:@"result"] intValue];
-                if(result==2)
-                {
-                    //successed.
-                    
-                    NSString* order_code = [return_json valueForKey:@"orderCode"];
-                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                    appDelegate.order_code = order_code;
-                    appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
-                    
-                    IMP imp = [holder methodForSelector:addtocart];
-                    void (*func)(id, SEL) = (void *)imp;
-                    func(holder, addtocart);
-                    
-                    //                    [holder performSelector:addtocart];
-                    
-                    
-                    
-                    
-                }
-            }
-            else
-            {
-                [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Create Order" controller:vc] ;
-            }
-        }];
-//        [waitalert dismissViewControllerAnimated:YES completion:nil];
-        
-        
-
-        
-        
-        
-        
-        
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:vc title:@"Create Order" completion:^{
+        [RANetwork request_create_order:^(NSMutableDictionary *result) {
+                NSMutableDictionary* return_json = result;
+                
+                [waitalert dismissViewControllerAnimated:YES completion:^{
+                    if([[return_json valueForKey:@"result"] intValue]==2)
+                    {
+                        int result=[[return_json valueForKey:@"result"] intValue];
+                        if(result==2)
+                        {
+                            //successed.
+                            
+                            NSString* order_code = [return_json valueForKey:@"orderCode"];
+                            AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                            appDelegate.order_code = order_code;
+                            appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
+                            
+                            IMP imp = [holder methodForSelector:addtocart];
+                            void (*func)(id, SEL) = (void *)imp;
+                            func(holder, addtocart);
+                            
+                            //                    [holder performSelector:addtocart];
+                            
+                            
+                            
+                            
+                        }
+                    }
+                    else
+                    {
+                        [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Create Order" controller:vc] ;
+                    }
+                }];
+        //        [waitalert dismissViewControllerAnimated:YES completion:nil];
+                
+                
+
+                
+                
+                
+                
+                
+            }];
+
     }];
-//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+    //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //        NSDictionary* return_json = [RANetwork new_Order];
 //
@@ -402,144 +404,21 @@
             else
             {
 
-                UIAlertController * waitalert = [RAUtils waiting_alert:vc title:@"Checking Pending Order"];
-
-
-                [RANetwork request_pendingorder:appDelegate.contact_id completionHandler:^(NSMutableDictionary *result) {
-                    NSMutableDictionary* return_json =result;
-                    
-                    
-                    [waitalert dismissViewControllerAnimated:YES completion:^{
-                        if([[return_json valueForKey:@"result"] intValue]==2)
-                        {
-                            
-                            bool openPendingOrder= [[return_json valueForKey:@"hasPending"] boolValue];
-                            bool createNewOrder=appDelegate.can_create_order;
-                            
-                            if(openPendingOrder&&createNewOrder)
+                __block UIAlertController * waitalert = [RAUtils waiting_alert:vc title:@"Checking Pending Order" completion:^{
+                    [RANetwork request_pendingorder:appDelegate.contact_id completionHandler:^(NSMutableDictionary *result) {
+                        NSMutableDictionary* return_json =result;
+                        
+                        
+                        [waitalert dismissViewControllerAnimated:YES completion:^{
+                            if([[return_json valueForKey:@"result"] intValue]==2)
                             {
                                 
-                                NSString* msg =@"";
-                                if(appDelegate.contact_id.length>0)
-                                {
-                                    msg = [msg stringByAppendingString:@"Customer:"];
-                                    msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
-                                    
-                                }
-                                
-                                UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Add to cart" message:msg preferredStyle:UIAlertControllerStyleAlert];
-                                //block代码块取代了delegate
-                                
-                                
-                                
-                                UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Check for saved order" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-                                    
-                                    
-                                    //  vc.disable_refresh = true;
-                                    OrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderListViewController"];
-                                    ovc.showNavibar = true;
-                                    ovc.customer_id = appDelegate.contact_id;
-                                    ovc.selectOrder = ^(NSMutableDictionary* order_detail){
-                                        
-                                        IMP imp = [holder methodForSelector:addtocart];
-                                        void (*func)(id, SEL) = (void *)imp;
-                                        func(holder, addtocart);
-                                        //                                    [holder performSelector:addtocart];
-                                        
-                                        
-                                    };
-                                    ovc.init_style = OL_OPEN;
-                                    
-                                    ovc.onCancel = ^(){
-                                        
-                                        //  self.disable_refresh = false;
-                                        
-                                        
-                                        
-                                    };
-                                    
-                                    [vc.navigationController pushViewController:ovc animated:true];
-                                    
-                                    
-                                    
-                                    
-                                    
-                                }];
-                                
-                                UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Create new order" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-                                    
-                                    
-                                    {
-                                        //create new;
-                                        //    self.disable_refresh = true;
-                                        if(appDelegate.customerInfo==nil)// select contact if current contact not exist
-                                        {
-                                            ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
-                                            cvc.showNavibar = true;
-                                            cvc.contact_type = @"Sales_Order_Customer";
-                                            cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-                                                
-                                                appDelegate.contact_id=[value valueForKey:@"customer_cid"];
-                                                appDelegate.customerInfo = value;
-                                                
-                                                
-                                                if(appDelegate.order_code==nil)
-                                                    [self neworder:vc selectorholder:holder selector:addtocart];
-                                                //                                                            neworder();
-                                                
-                                                //    [main_vc checklogin:true];
-                                                //            [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
-                                                
-                                                //
-                                                //                if(self.returnValue)
-                                                //                    self.returnValue(value);
-                                            };
-                                            
-                                            cvc.onCancel = ^(){
-                                                
-                                                [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"New Order Error" controller:vc];
-                                                
-                                                // self.disable_refresh = false;
-                                                
-                                            };
-                                            cvc.onReset = ^(){
-                                                // [main_vc checklogin:true];
-                                            };
-                                            
-                                            [vc.navigationController pushViewController:cvc animated:true];
-                                        }
-                                        else
-                                        {
-                                            [self neworder:vc selectorholder:holder selector:addtocart];
-                                        }
-                                        
-                                    }
-                                    
-                                    
-                                    DebugLog(@"No");
-                                }];
-                                [alertControl addAction:actionOne];
-                                
-                                [alertControl addAction:alertthree];
-                                
-                                UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
-                                }];
-                                [alertControl addAction:alertcancel];
-                                //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
+                                bool openPendingOrder= [[return_json valueForKey:@"hasPending"] boolValue];
+                                bool createNewOrder=appDelegate.can_create_order;
                                 
-                                
-                                [vc presentViewController:alertControl animated:YES completion:nil];
-                                
-                                
-                                
-                                
-                                
-                                
-                            }
-                            else
-                            {
-                                if(openPendingOrder)
+                                if(openPendingOrder&&createNewOrder)
                                 {
+                                    
                                     NSString* msg =@"";
                                     if(appDelegate.contact_id.length>0)
                                     {
@@ -565,7 +444,7 @@
                                             IMP imp = [holder methodForSelector:addtocart];
                                             void (*func)(id, SEL) = (void *)imp;
                                             func(holder, addtocart);
-                                            //                                        [holder performSelector:addtocart];
+                                            //                                    [holder performSelector:addtocart];
                                             
                                             
                                         };
@@ -587,43 +466,6 @@
                                         
                                     }];
                                     
-                                    
-                                    [alertControl addAction:actionOne];
-                                    UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
-                                    }];
-                                    [alertControl addAction:alertcancel];
-                                    
-                                    //   [alertControl addAction:alertthree];
-                                    
-                                    //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
-                                    
-                                    
-                                    [vc presentViewController:alertControl animated:YES completion:nil];
-                                    
-                                    
-                                    
-                                    
-                                    
-                                    
-                                    
-                                }
-                                else if(createNewOrder)
-                                {
-                                    NSString* msg =@"";
-                                    if(appDelegate.contact_id.length>0)
-                                    {
-                                        msg = [msg stringByAppendingString:@"Customer:"];
-                                        msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
-                                        
-                                    }
-                                    
-                                    UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Add to cart" message:msg preferredStyle:UIAlertControllerStyleAlert];
-                                    //block代码块取代了delegate
-                                    
-                                    
-                                    
-                                    
-                                    
                                     UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Create new order" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                                         
                                         
@@ -676,14 +518,13 @@
                                         
                                         DebugLog(@"No");
                                     }];
-                                    //                                        [alertControl addAction:actionOne];
+                                    [alertControl addAction:actionOne];
                                     
                                     [alertControl addAction:alertthree];
                                     
                                     UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                                     }];
                                     [alertControl addAction:alertcancel];
-                                    
                                     //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
                                     
                                     
@@ -693,32 +534,195 @@
                                     
                                     
                                     
+                                    
                                 }
                                 else
                                 {
-                                    [RAUtils message_alert:[return_json valueForKey:@"You donot have permission to access order"] title:@"Add To Cart" controller:vc];
+                                    if(openPendingOrder)
+                                    {
+                                        NSString* msg =@"";
+                                        if(appDelegate.contact_id.length>0)
+                                        {
+                                            msg = [msg stringByAppendingString:@"Customer:"];
+                                            msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
+                                            
+                                        }
+                                        
+                                        UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Add to cart" message:msg preferredStyle:UIAlertControllerStyleAlert];
+                                        //block代码块取代了delegate
+                                        
+                                        
+                                        
+                                        UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Check for saved order" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
+                                            
+                                            
+                                            //  vc.disable_refresh = true;
+                                            OrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderListViewController"];
+                                            ovc.showNavibar = true;
+                                            ovc.customer_id = appDelegate.contact_id;
+                                            ovc.selectOrder = ^(NSMutableDictionary* order_detail){
+                                                
+                                                IMP imp = [holder methodForSelector:addtocart];
+                                                void (*func)(id, SEL) = (void *)imp;
+                                                func(holder, addtocart);
+                                                //                                        [holder performSelector:addtocart];
+                                                
+                                                
+                                            };
+                                            ovc.init_style = OL_OPEN;
+                                            
+                                            ovc.onCancel = ^(){
+                                                
+                                                //  self.disable_refresh = false;
+                                                
+                                                
+                                                
+                                            };
+                                            
+                                            [vc.navigationController pushViewController:ovc animated:true];
+                                            
+                                            
+                                            
+                                            
+                                            
+                                        }];
+                                        
+                                        
+                                        [alertControl addAction:actionOne];
+                                        UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
+                                        }];
+                                        [alertControl addAction:alertcancel];
+                                        
+                                        //   [alertControl addAction:alertthree];
+                                        
+                                        //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
+                                        
+                                        
+                                        [vc presentViewController:alertControl animated:YES completion:nil];
+                                        
+                                        
+                                        
+                                        
+                                        
+                                        
+                                        
+                                    }
+                                    else if(createNewOrder)
+                                    {
+                                        NSString* msg =@"";
+                                        if(appDelegate.contact_id.length>0)
+                                        {
+                                            msg = [msg stringByAppendingString:@"Customer:"];
+                                            msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
+                                            
+                                        }
+                                        
+                                        UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Add to cart" message:msg preferredStyle:UIAlertControllerStyleAlert];
+                                        //block代码块取代了delegate
+                                        
+                                        
+                                        
+                                        
+                                        
+                                        UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Create new order" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
+                                            
+                                            
+                                            {
+                                                //create new;
+                                                //    self.disable_refresh = true;
+                                                if(appDelegate.customerInfo==nil)// select contact if current contact not exist
+                                                {
+                                                    ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
+                                                    cvc.showNavibar = true;
+                                                    cvc.contact_type = @"Sales_Order_Customer";
+                                                    cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
+                                                        
+                                                        appDelegate.contact_id=[value valueForKey:@"customer_cid"];
+                                                        appDelegate.customerInfo = value;
+                                                        
+                                                        
+                                                        if(appDelegate.order_code==nil)
+                                                            [self neworder:vc selectorholder:holder selector:addtocart];
+                                                        //                                                            neworder();
+                                                        
+                                                        //    [main_vc checklogin:true];
+                                                        //            [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
+                                                        
+                                                        //
+                                                        //                if(self.returnValue)
+                                                        //                    self.returnValue(value);
+                                                    };
+                                                    
+                                                    cvc.onCancel = ^(){
+                                                        
+                                                        [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"New Order Error" controller:vc];
+                                                        
+                                                        // self.disable_refresh = false;
+                                                        
+                                                    };
+                                                    cvc.onReset = ^(){
+                                                        // [main_vc checklogin:true];
+                                                    };
+                                                    
+                                                    [vc.navigationController pushViewController:cvc animated:true];
+                                                }
+                                                else
+                                                {
+                                                    [self neworder:vc selectorholder:holder selector:addtocart];
+                                                }
+                                                
+                                            }
+                                            
+                                            
+                                            DebugLog(@"No");
+                                        }];
+                                        //                                        [alertControl addAction:actionOne];
+                                        
+                                        [alertControl addAction:alertthree];
+                                        
+                                        UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
+                                        }];
+                                        [alertControl addAction:alertcancel];
+                                        
+                                        //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
+                                        
+                                        
+                                        [vc presentViewController:alertControl animated:YES completion:nil];
+                                        
+                                        
+                                        
+                                        
+                                        
+                                    }
+                                    else
+                                    {
+                                        [RAUtils message_alert:[return_json valueForKey:@"You donot have permission to access order"] title:@"Add To Cart" controller:vc];
+                                    }
+                                    
                                 }
                                 
+                                
                             }
-                            
-                            
-                        }
-                        else
-                        {
-                            
-                            [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Check Pending Order" controller:vc] ;
-                        }
+                            else
+                            {
+                                
+                                [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Check Pending Order" controller:vc] ;
+                            }
+                        }];
+                        
+                        
+
+                        
+                        
+                        
+                        
+                        
                     }];
-                    
-                    
-
-                    
-                    
-                    
-                    
-                    
+
                 }];
 
+
+                
 //                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //                    NSDictionary* return_json = [RANetwork request_PendingOrder:appDelegate.contact_id];

+ 476 - 289
RedAnt ERP Mobile/common/CommonEditor/CommonEditorViewController.m

@@ -252,16 +252,18 @@
 {
     [super viewWillAppear:animated];
     
-    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
-    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
+//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
+//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
     
     // 键盘高度变化通知,ios5.0新增的
-#ifdef __IPHONE_5_0
-    float version = [[[UIDevice currentDevice] systemVersion] floatValue];
-    if (version >= 5.0) {
+//#ifdef __IPHONE_5_0
+//    float version = [[[UIDevice currentDevice] systemVersion] floatValue];
+//    if (version >= 5.0) {
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
-    }
-#endif
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidChangeFrame:) name:UIKeyboardDidChangeFrameNotification object:nil];
+
+//    }
+//#endif
     
 }
 -(void) viewWillDisappear:(BOOL)animated
@@ -402,50 +404,52 @@
     if(self.url_type==URL_REMOTE)
     {
         
-        UIAlertController * waitalert = [RAUtils waiting_alert:self message:self.loading_msg title:self.loading_title];
-        
-        [RANetwork request_editor:self.request_url params:self.params completionHandler:^(NSMutableDictionary *result) {
-            NSMutableDictionary* editor_json = result;
-            DebugLog(@"data string: %@",[RAConvertor dict2string:editor_json] );
-            
-            
+        __block UIAlertController * waitalert = [RAUtils waiting_alert:self message:self.loading_msg title:self.loading_title completion:^{
+            [RANetwork request_editor:self.request_url params:self.params completionHandler:^(NSMutableDictionary *result) {
+                NSMutableDictionary* editor_json = result;
+                DebugLog(@"data string: %@",[RAConvertor dict2string:editor_json] );
+                
                 
-            [waitalert dismissViewControllerAnimated:YES completion:^{
-                if([[editor_json valueForKey:@"result"] intValue]==2)
-                {
-                    
-                    weakself.content_data_download = [editor_json mutableCopy];
-                    
-                    weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed: weakself.changed_data];
-                    
-                    //                self.content_data = [editor_json mutableCopy];
-                    //                    self.content_data = [self translate_json:editor_json];
-                    
-                    //                  NSMutableDictionary* content_data1 = [self translate_json:self.content_data];
                     
-                    [weakself download_success];
+                [waitalert dismissViewControllerAnimated:YES completion:^{
+                    if([[editor_json valueForKey:@"result"] intValue]==2)
+                    {
+                        
+                        weakself.content_data_download = [editor_json mutableCopy];
+                        
+                        weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed: weakself.changed_data];
+                        
+                        //                self.content_data = [editor_json mutableCopy];
+                        //                    self.content_data = [self translate_json:editor_json];
+                        
+                        //                  NSMutableDictionary* content_data1 = [self translate_json:self.content_data];
+                        
+                        [weakself download_success];
+                        
+                        [weakself.editorTable reloadData];
+                        
+                        //                NSString * ttt=[self.content_data valueForKey:@"title"] ;
+                        
+                        weakself.navigationItem.title =  [weakself.content_data_download valueForKey:@"title"] ;
+                    }
+                    else
+                    {
+                        [weakself download_failed];
+                        [weakself alertMessage:[editor_json valueForKey:@"err_msg"]];
+                        
+                    }
+                }];
                     
-                    [weakself.editorTable reloadData];
                     
-                    //                NSString * ttt=[self.content_data valueForKey:@"title"] ;
+
                     
-                    weakself.navigationItem.title =  [weakself.content_data_download valueForKey:@"title"] ;
-                }
-                else
-                {
-                    [weakself download_failed];
-                    [weakself alertMessage:[editor_json valueForKey:@"err_msg"]];
                     
-                }
-            }];
-                
                 
+            }];
 
-                
-                
-            
         }];
         
+                
 //        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //            NSDictionary* editor_json = [weakself request_Editor:weakself.request_url params:weakself.params];
@@ -1365,56 +1369,58 @@
     {
         
         
-        
-        UIAlertController * waitalert = [RAUtils waiting_alert:self message:self.loading_msg title:self.loading_title];
-        
         self.params[@"refresh_trigger"]=trigger;
-        __weak typeof(self) weakself = self;
-        
-        
-        NSDictionary* refresh_params=[self get_refresh_param];
-        
-        NSArray* changed_key=[refresh_params allKeys];
-        for(int i=0;i<changed_key.count;i++)
-        {
-            NSString* obj_str=[NSString stringWithFormat:@"%@",[refresh_params valueForKey:(NSString*)changed_key[i]]];
-            [self.params setObject:obj_str forKey:(NSString*)changed_key[i]];
-        }
-        
-        [RANetwork request_editor:self.request_url params:self.params completionHandler:^(NSMutableDictionary *result) {
-            NSMutableDictionary* editor_json = result;
-            DebugLog(@"data string: %@",[RAConvertor dict2string:editor_json] );
-            
-            [waitalert dismissViewControllerAnimated:YES completion:^{
-                if([[editor_json valueForKey:@"result"] intValue]==2)
-                {
+               __weak typeof(self) weakself = self;
+               
+               
+               NSDictionary* refresh_params=[self get_refresh_param];
+               
+               NSArray* changed_key=[refresh_params allKeys];
+               for(int i=0;i<changed_key.count;i++)
+               {
+                   NSString* obj_str=[NSString stringWithFormat:@"%@",[refresh_params valueForKey:(NSString*)changed_key[i]]];
+                   [self.params setObject:obj_str forKey:(NSString*)changed_key[i]];
+               }
+        __block UIAlertController * waitalert = [RAUtils waiting_alert:self message:self.loading_msg title:self.loading_title completion:^{
+            [RANetwork request_editor:self.request_url params:self.params completionHandler:^(NSMutableDictionary *result) {
+                NSMutableDictionary* editor_json = result;
+                DebugLog(@"data string: %@",[RAConvertor dict2string:editor_json] );
+                
+                [waitalert dismissViewControllerAnimated:YES completion:^{
+                    if([[editor_json valueForKey:@"result"] intValue]==2)
+                    {
+                        
+                        weakself.content_data_download = [weakself CopyDirty:weakself.content_data_download to:[editor_json mutableCopy]];//[editor_json mutableCopy];
+                        
+                        weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed: weakself.changed_data];
+                        
+                        
+                        [weakself download_success];
+                        [weakself.editorTable reloadData];
+                        
+                    }
+                    else
+                    {
+                        [weakself download_failed];
+                        [weakself alertMessage:[editor_json valueForKey:@"err_msg"]];
+                    }
+                }];
                     
-                    weakself.content_data_download = [weakself CopyDirty:weakself.content_data_download to:[editor_json mutableCopy]];//[editor_json mutableCopy];
                     
-                    weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed: weakself.changed_data];
+
+                    
                     
                     
-                    [weakself download_success];
-                    [weakself.editorTable reloadData];
                     
-                }
-                else
-                {
-                    [weakself download_failed];
-                    [weakself alertMessage:[editor_json valueForKey:@"err_msg"]];
-                }
-            }];
-                
-                
-
-                
-                
-                
                 
+            }];
             
+
         }];
         
-//        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+       
+        
+        //        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //
 //
@@ -2617,40 +2623,42 @@
             
             [params setValue:val forKey:name];
             
-            
-            UIAlertController * waitalert = [RAUtils waiting_alert:self message:self.loading_msg title:self.loading_title];
             __weak typeof(self) weakself = self;
-            
-            [RANetwork request_commoneditor_partialrefresh:params url:url completionHandler:^(NSMutableDictionary *result) {
-                NSDictionary* editor_json =result;
-                [waitalert dismissViewControllerAnimated:YES completion:^{
-                    if([[editor_json valueForKey:@"result"] intValue]==2)
-                    {
-                        
-                        int prcount = [[editor_json valueForKey:@"count"] intValue];
-                        for(int ipr=0;ipr<prcount;ipr++)
+            __block UIAlertController * waitalert = [RAUtils waiting_alert:self message:self.loading_msg title:self.loading_title completion:^{
+                [RANetwork request_commoneditor_partialrefresh:params url:url completionHandler:^(NSMutableDictionary *result) {
+                    NSDictionary* editor_json =result;
+                    [waitalert dismissViewControllerAnimated:YES completion:^{
+                        if([[editor_json valueForKey:@"result"] intValue]==2)
                         {
-                            NSDictionary* pr_item = [editor_json objectForKey:[NSString stringWithFormat:@"item_%d",ipr]];
-                            NSString* name = [pr_item valueForKey:@"name"];
-                            NSString* value = [pr_item valueForKey:@"value"];
                             
-                            [weakself setValue:name value:value];
+                            int prcount = [[editor_json valueForKey:@"count"] intValue];
+                            for(int ipr=0;ipr<prcount;ipr++)
+                            {
+                                NSDictionary* pr_item = [editor_json objectForKey:[NSString stringWithFormat:@"item_%d",ipr]];
+                                NSString* name = [pr_item valueForKey:@"name"];
+                                NSString* value = [pr_item valueForKey:@"value"];
+                                
+                                [weakself setValue:name value:value];
+                            }
+                            
+                            
+                        }
+                        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] ;
-                    }
+                    }];
+                    
+                    
+
                     
                 }];
-                
-                
 
-                
             }];
-//            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+            
+            
+            //            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //                NSDictionary* editor_json = [RANetwork commoneditor_partialrefresh:params url:url];
 //
@@ -2767,39 +2775,42 @@
             
             [params setValue:val forKey:name];
             
-            
-            UIAlertController * waitalert = [RAUtils waiting_alert:self message:self.loading_msg title:self.loading_title];
             __weak typeof(self) weakself = self;
             
-            [RANetwork request_commoneditor_partialrefresh:params url:url completionHandler:^(NSMutableDictionary *result) {
-                NSDictionary* editor_json = result;
-                [waitalert dismissViewControllerAnimated:YES completion:^{
-                    if([[editor_json valueForKey:@"result"] intValue]==2)
-                    {
-                        
-                        int prcount = [[editor_json valueForKey:@"count"] intValue];
-                        for(int ipr=0;ipr<prcount;ipr++)
+            __block UIAlertController * waitalert = [RAUtils waiting_alert:self message:self.loading_msg title:self.loading_title completion:^{
+                [RANetwork request_commoneditor_partialrefresh:params url:url completionHandler:^(NSMutableDictionary *result) {
+                    NSDictionary* editor_json = result;
+                    [waitalert dismissViewControllerAnimated:YES completion:^{
+                        if([[editor_json valueForKey:@"result"] intValue]==2)
                         {
-                            NSDictionary* pr_item = [editor_json objectForKey:[NSString stringWithFormat:@"item_%d",ipr]];
-                            NSString* name = [pr_item valueForKey:@"name"];
-                            NSString* value = [pr_item valueForKey:@"value"];
                             
-                            [weakself setValue:name value:value];
+                            int prcount = [[editor_json valueForKey:@"count"] intValue];
+                            for(int ipr=0;ipr<prcount;ipr++)
+                            {
+                                NSDictionary* pr_item = [editor_json objectForKey:[NSString stringWithFormat:@"item_%d",ipr]];
+                                NSString* name = [pr_item valueForKey:@"name"];
+                                NSString* value = [pr_item valueForKey:@"value"];
+                                
+                                [weakself setValue:name value:value];
+                            }
+                            
                         }
-                        
-                    }
-                    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] ;
+                        }
+                    }];
+                    
+                    
+
+                    
+                    
                 }];
-                
-                
 
-                
-                
             }];
-//            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+            
+            
+            //            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //                NSDictionary* editor_json = [RANetwork commoneditor_partialrefresh:params url:url];
 //
@@ -3276,6 +3287,7 @@
         NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
         NSString* value =[item_json valueForKey:@"value"];
         NSString* align =[item_json valueForKey:@"align"];
+        
         if([align isEqualToString:@"right"])
             cell.textview.textAlignment= kCTTextAlignmentRight;
         else
@@ -4957,48 +4969,50 @@
                 if(password!=nil)
                     [params setValue:password forKey:@"password"];
                 
-                UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Upload Signature"];
-                
-                [NetworkUtils upload:imageData FileName:@"test.jpg" Params:params ToHost:URL_UPLOAD_IMG Result:^(NSMutableDictionary *json) {
-                    
-                    dispatch_async(dispatch_get_main_queue(), ^{
-                        [waitalert dismissViewControllerAnimated:YES completion:^{
-                            if([[json valueForKey:@"result"] intValue]==2)
-                            {
-                                NSString* img_url_down = json[@"img_url_aname"];
-
-                                NSString* img_url_up = json[@"img_url"];
-                                
-                                NSMutableDictionary* item_json =((NSMutableArray*)weakself.content_data_control[indexPath.section])[indexPath.row];
-                                
-                                [item_json setValue:img_url_down forKey:@"avalue"];
-                                [item_json setValue:img_url_up forKey:@"value"];
-                                [item_json setValue:@"true" forKey:@"dirty"];
-                                NSMutableDictionary* section_json = [[weakself.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
-                                [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
-                                
-                                [weakself.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
-                                weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed:weakself.changed_data];
-                                
-                                
-                                CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [weakself.editorTable cellForRowAtIndexPath:indexPath];
-                                
-                                cell.imageviewSignature.image = signimg;
-                                
-                                
-                            }
-                            else
-                            {
-                                [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Image" controller:weakself] ;
-                            }
-                        }];
+                __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Upload Signature" completion:^{
+                    [NetworkUtils upload:imageData FileName:@"test.jpg" Params:params ToHost:URL_UPLOAD_IMG Result:^(NSMutableDictionary *json) {
                         
+//                        dispatch_async(dispatch_get_main_queue(), ^{
+                            [waitalert dismissViewControllerAnimated:YES completion:^{
+                                if([[json valueForKey:@"result"] intValue]==2)
+                                {
+                                    NSString* img_url_down = json[@"img_url_aname"];
 
+                                    NSString* img_url_up = json[@"img_url"];
+                                    
+                                    NSMutableDictionary* item_json =((NSMutableArray*)weakself.content_data_control[indexPath.section])[indexPath.row];
+                                    
+                                    [item_json setValue:img_url_down forKey:@"avalue"];
+                                    [item_json setValue:img_url_up forKey:@"value"];
+                                    [item_json setValue:@"true" forKey:@"dirty"];
+                                    NSMutableDictionary* section_json = [[weakself.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
+                                    [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
+                                    
+                                    [weakself.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
+                                    weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed:weakself.changed_data];
+                                    
+                                    
+                                    CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [weakself.editorTable cellForRowAtIndexPath:indexPath];
+                                    
+                                    cell.imageviewSignature.image = signimg;
+                                    
+                                    
+                                }
+                                else
+                                {
+                                    [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Image" controller:weakself] ;
+                                }
+                            }];
+                            
+
+                            
+//                        });
                         
-                    });
-                    
-                } Progress:nil DecryptHandler:nil];
+                    } Progress:nil DecryptHandler:nil];
+
+                }];
                 
+                                
                 
                 
 //                AFHTTPRequestSerializer* serializer=[AFHTTPRequestSerializer serializer] ;
@@ -5992,7 +6006,7 @@
 
 - (void)textFieldDidBeginEditing:(UITextField *)textField
 {
-    DebugLog(@"textField shouldChangeCharactersInRange");
+    DebugLog(@"textField textFieldDidBeginEditing");
     
     self.lastedit = textField;
     UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
@@ -6405,10 +6419,47 @@
 //{
 //    return [RANetwork request_Editor:request_url params:params];
 //}
+//
+//- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
+//{
+//
+//    NSLog(@"willDisplayCell");
+//    NSString *cellclass;
+//    const char *class_name_ch = object_getClassName([cell class]);
+//    cellclass = [NSString stringWithUTF8String:class_name_ch];
+//
+//    CommonEditorCellTextView * tvcell=nil;
+//    if([cellclass isEqualToString:@"CommonEditorCellTextView"])
+//    {
+//        tvcell=(CommonEditorCellTextView*)self.editingcell;
+//        tvcell.textview.scrollEnabled=true;
+//
+//
+//    }
+//}
+//- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath
+//{
+//
+//    NSLog(@"didEndDisplayingCell");
+//    NSString *cellclass;
+//    const char *class_name_ch = object_getClassName([cell class]);
+//    cellclass = [NSString stringWithUTF8String:class_name_ch];
+//
+//    CommonEditorCellTextView * tvcell=nil;
+//    if([cellclass isEqualToString:@"CommonEditorCellTextView"])
+//    {
+//        tvcell=(CommonEditorCellTextView*)self.editingcell;
+//        tvcell.textview.scrollEnabled=false;
+//
+//
+//    }
+//
+//}
 #pragma mark - Responding to keyboard events
 
 
 - (void)keyboardWillChangeFrame:(NSNotification *)notification {
+//    return;
     DebugLog(@"keyboardWillChangeFrame");
     
 
@@ -6432,17 +6483,42 @@
         
         // table -> top > offset: table.y = -offset
         // 事实上top:topLayoutGuide
+//        self.additionalSafeAreaInsets
+        
         float y0=self.view.safeAreaLayoutGuide.topAnchor.accessibilityActivationPoint.y;
-        CGFloat topAvailableHeight = (CGRectGetMinY(table_origin_screen_frame) - self.topLayoutGuide.length);
+        CGFloat topAvailableHeight = (CGRectGetMinY(table_origin_screen_frame) - y0);
         if (topAvailableHeight > 0) {
             if (topAvailableHeight > offset) {
                 table_frame.origin.y = -offset;
             } else {
                 // 向上移动到topLayoutGuide,不足部分通过缩减高度到达keyboard顶部
-                table_frame.origin.y = -topAvailableHeight;
+//                table_frame.origin.y = -topAvailableHeight;
+                
+                
+//                table_frame.size.height = (end_y - self.topLayoutGuide.length);
+                
+                
+                for (NSLayoutConstraint *constraint in self.tableContainer.constraints) {
+                    if (constraint.firstAttribute == NSLayoutAttributeBottom) {
+//                        int a=0;
+                        
+                        [self.tableContainer removeConstraint:constraint];
+                        NSLayoutConstraint *bottom_constraint = [NSLayoutConstraint constraintWithItem:self.editorTable
+                                                                                             attribute:NSLayoutAttributeBottom
+                                                                                             relatedBy:NSLayoutRelationEqual
+                                                                                                toItem:self.tableContainer
+                                                                                             attribute:NSLayoutAttributeBottom
+                                                                                            multiplier:1
+                                                                                              constant:-end.size.height];
+                        self.tb_bottom_constraint = bottom_constraint;
+                        [self.tableContainer addConstraint:bottom_constraint];
+                        break;
+                        //
+                    }
+                }
+
                 
                 
-                table_frame.size.height = (end_y - self.topLayoutGuide.length);
             }
         } else {
             // contentInset = (top = 64, left = 0, bottom = 0, right = 0),topAvailableHeight = -64
@@ -6452,15 +6528,66 @@
 //        table_frame.size.height = CGRectGetHeight(table_origin_screen_frame) - (CGRectGetMaxY(table_origin_screen_frame) - end_y);
     } else {
 //        table_frame.size.height = CGRectGetHeight(table_origin_screen_frame);
-        table_frame = self.tableContainer.bounds;
+//        table_frame = self.tableContainer.bounds;
+        for (NSLayoutConstraint *constraint in self.tableContainer.constraints) {
+            if (constraint.firstAttribute == NSLayoutAttributeBottom) {
+                //                        int a=0;
+                
+                [self.tableContainer removeConstraint:constraint];
+                NSLayoutConstraint *bottom_constraint = [NSLayoutConstraint constraintWithItem:self.editorTable
+                                                                                     attribute:NSLayoutAttributeBottom
+                                                                                     relatedBy:NSLayoutRelationEqual
+                                                                                        toItem:self.tableContainer
+                                                                                     attribute:NSLayoutAttributeBottom
+                                                                                    multiplier:1
+                                                                                      constant:0];
+                self.tb_bottom_constraint = bottom_constraint;
+                [self.tableContainer addConstraint:bottom_constraint];
+                break;
+                //
+            }
+        }
     }
 
     self.editorTable.frame = table_frame;
     
     CGRect cell_screen_frame = [self.editingcell convertRect:self.editingcell.bounds toView:self.view.window];
-    if (CGRectGetMaxY(cell_screen_frame) > end_y) {
+    int cover =CGRectGetMaxY(cell_screen_frame) - end_y;
+    if (cover>0) {
         // Cell 被键盘遮挡后才滚动
-        [self.editorTable scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionNone animated:NO];
+        NSLog(@"scrollToRowAtIndexPath");
+        NSString *cellclass;
+        const char *class_name_ch = object_getClassName([self.editingcell class]);
+        cellclass = [NSString stringWithUTF8String:class_name_ch];
+        
+        CommonEditorCellTextView * tvcell=nil;
+//        if([cellclass isEqualToString:@"CommonEditorCellTextView"])
+        {
+//            tvcell=(CommonEditorCellTextView*)self.editingcell;
+//            tvcell.textview.scrollEnabled=false;
+
+               CGPoint current_offset=self.editorTable.contentOffset;
+               
+               NSLog(@"OFFSET %f",current_offset.y);
+               CGPoint moveto= CGPointMake(self.editingcell.frame.origin.x,current_offset.y+cover);
+               [self.editorTable setContentOffset:moveto];
+        }
+        
+        
+        ;
+        
+//        self.editorTable cell
+//        self.editorTable scrollto
+//        self.editorTable scrollToNearestSelectedRowAtScrollPosition:(UITableViewScrollPosition) animated:<#(BOOL)#>
+        
+//        CGPoint current_offset=self.editorTable.contentOffset;
+//
+//        NSLog(@"OFFSET %f",current_offset.y);
+//        CGPoint moveto= CGPointMake(self.editingcell.frame.origin.x,current_offset.y+cover);
+     //   [self.editorTable setContentOffset:self.editingcell.frame.origin];
+//        [self.editorTable scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionNone animated:NO];
+
+//
     }
 
     // ===============================================
@@ -6472,127 +6599,187 @@
     
 }
 
-//static float table_origin_h = 0;
-
-- (void)keyboardWillShow:(NSNotification *)notification {
-    DebugLog(@"keyboardWillShow");
-//
-//    if(self.keyboard_show)
-//        return;
-//
-//    self.keyboard_show=true;
-//    /*
-//     Reduce the size of the text view so that it's not obscured by the keyboard.
-//     Animate the resize so that it's in sync with the appearance of the keyboard.
-//     */
-//
-//    NSDictionary *userInfo = [notification userInfo];
-//
-//    // Get the origin of the keyboard when it's displayed.
-//    NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
-//
-//    // Get the top of the keyboard as the y coordinate of its origin in self's view's coordinate system. The bottom of the text view's frame should align with the top of the keyboard's final position.
-//    //    CGRect keyboardRect = [aValue CGRectValue];
-//    CGSize keyboardSize = [aValue CGRectValue].size;
-//    DebugLog(@"keyboard height:%f",keyboardSize.height);
-//    // Get the duration of the animation.
-//    NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
-//    NSTimeInterval animationDuration;
-//    [animationDurationValue getValue:&animationDuration];
-//
-//
-//    //    if(self.keyboard_h==0)
-//    //   {
-//    self.keyboard_h =keyboardSize.height;
-//    CGRect cellrect_screen = [RAUtils relativeFrameForScreenWithView:self.editingcell];
-//    CGRect rect_screen = [ UIScreen mainScreen ].bounds;
-//
-//    //    int vpos =self.view.frame.origin.y+self.view.frame.size.height;
-//    //    int loginpos = self.editingcell.frame.origin.y+self.editingcell.frame.size.height;
-//    //
-//    int cellpos = cellrect_screen.origin.y+cellrect_screen.size.height;
-//    //    screen.size.height-keyboardSize.height-(cellpos_screen.origin.x+cellpos_screen.size.height);
-//    self.ioffset = cellpos-(rect_screen.size.height-keyboardSize.height);//rect_screen.size.height-keyboardSize.height-(rect_screen.origin.y+rect_screen.size.height);//keyboardSize.height -(self.view.frame.size.height-loginpos);
-//    if(self.ioffset>0)
+- (void)keyboardDidChangeFrame:(NSNotification *)notification {
+        NSLog(@"keyboardDidChangeFrame");
+//    NSString *cellclass;
+//    const char *class_name_ch = object_getClassName([self.editingcell class]);
+//    cellclass = [NSString stringWithUTF8String:class_name_ch];
+//
+//    CommonEditorCellTextView * tvcell=nil;
+//    if([cellclass isEqualToString:@"CommonEditorCellTextView"])
 //    {
-//        //  self.resize = true;
-//
-//
-//        CGPoint contentOffsetPoint = self.editorTable.contentOffset;
-//
 //
-//        contentOffsetPoint.y+=self.ioffset;
+//        tvcell=(CommonEditorCellTextView*)self.editingcell;
+//        tvcell.textview.scrollEnabled=true;
 //
-//        self.editorTable.contentOffset=contentOffsetPoint;
 //
-//
-//        //       NSTimeInterval animationDuration = 0.30f;
-//        //        CGRect frame = self.view.frame;
-//        //        frame.origin.y -=self.ioffset;//view的Y轴上移
-//        //        frame.size.height +=self.ioffset; //View的高度增加
-//        //        self.view.frame = frame;
-//        //        [UIView beginAnimations:@"ResizeView" context:nil];
-//        //        [UIView setAnimationDuration:animationDuration];
-//        //        self.view.frame = frame;
-//        //        [UIView commitAnimations];//设置调整界面的动画效果
 //    }
-//
-//    table_origin_h = self.editorTable.frame.size.height;
-//    self.editorTable.frame = CGRectMake(0, 0, self.editorTable.frame.size.width, self.editorTable.frame.size.height-self.keyboard_h);
-//
-//    //    CGSize tablecontent =self.editorTable.contentSize;
-//    //    tablecontent.height=tablecontent.height+self.keyboard_h;
-//    //    self.editorTable.contentSize=tablecontent;
-//    //    }
-//    // Animate the resize of the text view's frame in sync with the keyboard's appearance.
-//    //  [self moveInputBarWithKeyboardHeight:keyboardRect.size.height withDuration:animationDuration];
+    return;
+
+
+
+    // 使用tableContainer计算frame 保证屏幕旋转后table height正确
+    //    CGRect table_origin_screen_frame = [self.tableContainer convertRect:self.tableContainer.bounds toView:self.view.window];
+
+    CGRect screen_rect = [RAUtils relativeFrameForScreenWithView:self.editorTable];
+    //
+    //    //    NSTimeInterval duration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
+    //    //    duration *= 0.0;
+    CGRect end = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
+//    CGRect begin = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
+    float kbheight = end.size.height;
+    CGFloat keyboard_top = end.origin.y;
+    NSLog(@"keyboard rect: %@",NSStringFromCGRect(end));
+
+    NSLog(@"view rect: %@",NSStringFromCGRect(self.view.frame));
+    NSLog(@"view screen rect: %@",NSStringFromCGRect(screen_rect));
+
+    //    self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
+
+    float dark = screen_rect.origin.y+screen_rect.size.height-keyboard_top;
+
+    if(dark>0)
+    {
+//        self.editorTable.scrollEnabled = true;
+//        self.editorTable.contentSize = CGSizeMake(self.editorTable.frame.size.width, self.editorTable.frame.size.height+dark);
+        
+        self.editorTable.contentSize=CGSizeMake(self.editorTable.contentSize.width, self.editorTable.contentSize.height+kbheight);
+       
+    }
+    else
+    {
+//        self.editorTable.scrollEnabled = false;
+//        self.editorTable.contentSize = self.editorTable.frame.size;
+                self.editorTable.contentSize=CGSizeMake(self.editorTable.contentSize.width, self.editorTable.contentSize.height-kbheight);
+      
+    }
+
+
+
 }
-- (void)keyboardWillHide:(NSNotification *)notification {
-    DebugLog(@"keyboardWillHide");
-
-//    self.keyboard_show=false;
-//    NSDictionary* userInfo = [notification userInfo];
-//
-//    /*
-//     Restore the size of the text view (fill self's view).
-//     Animate the resize so that it's in sync with the disappearance of the keyboard.
-//     */
-//    NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
-//    NSTimeInterval animationDuration;
-//    [animationDurationValue getValue:&animationDuration];
-//    CGSize tablecontent =self.editorTable.contentSize;
-//    tablecontent.height=tablecontent.height-self.keyboard_h;
-//    //    self.editorTable.contentSize=tablecontent;
-//
-//    self.editorTable.frame = CGRectMake(0, 0, self.editorTable.frame.size.width, table_origin_h);
-//
-//    self.keyboard_h= 0;
-//    DebugLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
-//
-//
-//    //    if(self.resize)
-//    //    {
-//    //        NSTimeInterval animationDuration = 0.30f;
-//    //        CGRect frame = self.view.frame;
-//    //        //    if(prewTag == textField.tag) //当结束编辑的View的TAG是上次的就移动
-//    //        //    {   //还原界面
-//    //        //        moveY =  prewMoveY;
-//    //        frame.origin.y +=self.ioffset;
-//    //        frame.size. height -=self.ioffset;
-//    //        self.view.frame = frame;
-//    //        //    }
-//    //        //self.view移回原位置
-//    //        [UIView beginAnimations:@"ResizeView" context:nil];
-//    //        [UIView setAnimationDuration:animationDuration];
-//    //        self.view.frame = frame;
-//    //        [UIView commitAnimations];
-//    //        //[textField resignFirstResponder];
-//    //        self.ioffset=0;
-//    //    }
+
+
+//static float table_origin_h = 0;
 //
+//- (void)keyboardWillShow:(NSNotification *)notification {
+//    DebugLog(@"keyboardWillShow");
+////
+////    if(self.keyboard_show)
+////        return;
+////
+////    self.keyboard_show=true;
+////    /*
+////     Reduce the size of the text view so that it's not obscured by the keyboard.
+////     Animate the resize so that it's in sync with the appearance of the keyboard.
+////     */
+////
+////    NSDictionary *userInfo = [notification userInfo];
+////
+////    // Get the origin of the keyboard when it's displayed.
+////    NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
+////
+////    // Get the top of the keyboard as the y coordinate of its origin in self's view's coordinate system. The bottom of the text view's frame should align with the top of the keyboard's final position.
+////    //    CGRect keyboardRect = [aValue CGRectValue];
+////    CGSize keyboardSize = [aValue CGRectValue].size;
+////    DebugLog(@"keyboard height:%f",keyboardSize.height);
+////    // Get the duration of the animation.
+////    NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
+////    NSTimeInterval animationDuration;
+////    [animationDurationValue getValue:&animationDuration];
+////
+////
+////    //    if(self.keyboard_h==0)
+////    //   {
+////    self.keyboard_h =keyboardSize.height;
+////    CGRect cellrect_screen = [RAUtils relativeFrameForScreenWithView:self.editingcell];
+////    CGRect rect_screen = [ UIScreen mainScreen ].bounds;
+////
+////    //    int vpos =self.view.frame.origin.y+self.view.frame.size.height;
+////    //    int loginpos = self.editingcell.frame.origin.y+self.editingcell.frame.size.height;
+////    //
+////    int cellpos = cellrect_screen.origin.y+cellrect_screen.size.height;
+////    //    screen.size.height-keyboardSize.height-(cellpos_screen.origin.x+cellpos_screen.size.height);
+////    self.ioffset = cellpos-(rect_screen.size.height-keyboardSize.height);//rect_screen.size.height-keyboardSize.height-(rect_screen.origin.y+rect_screen.size.height);//keyboardSize.height -(self.view.frame.size.height-loginpos);
+////    if(self.ioffset>0)
+////    {
+////        //  self.resize = true;
+////
+////
+////        CGPoint contentOffsetPoint = self.editorTable.contentOffset;
+////
+////
+////        contentOffsetPoint.y+=self.ioffset;
+////
+////        self.editorTable.contentOffset=contentOffsetPoint;
+////
+////
+////        //       NSTimeInterval animationDuration = 0.30f;
+////        //        CGRect frame = self.view.frame;
+////        //        frame.origin.y -=self.ioffset;//view的Y轴上移
+////        //        frame.size.height +=self.ioffset; //View的高度增加
+////        //        self.view.frame = frame;
+////        //        [UIView beginAnimations:@"ResizeView" context:nil];
+////        //        [UIView setAnimationDuration:animationDuration];
+////        //        self.view.frame = frame;
+////        //        [UIView commitAnimations];//设置调整界面的动画效果
+////    }
+////
+////    table_origin_h = self.editorTable.frame.size.height;
+////    self.editorTable.frame = CGRectMake(0, 0, self.editorTable.frame.size.width, self.editorTable.frame.size.height-self.keyboard_h);
+////
+////    //    CGSize tablecontent =self.editorTable.contentSize;
+////    //    tablecontent.height=tablecontent.height+self.keyboard_h;
+////    //    self.editorTable.contentSize=tablecontent;
+////    //    }
+////    // Animate the resize of the text view's frame in sync with the keyboard's appearance.
+////    //  [self moveInputBarWithKeyboardHeight:keyboardRect.size.height withDuration:animationDuration];
+//}
+//- (void)keyboardWillHide:(NSNotification *)notification {
+//    DebugLog(@"keyboardWillHide");
 //
-//    //  [self moveInputBarWithKeyboardHeight:0.0 withDuration:animationDuration];
-}
+////    self.keyboard_show=false;
+////    NSDictionary* userInfo = [notification userInfo];
+////
+////    /*
+////     Restore the size of the text view (fill self's view).
+////     Animate the resize so that it's in sync with the disappearance of the keyboard.
+////     */
+////    NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
+////    NSTimeInterval animationDuration;
+////    [animationDurationValue getValue:&animationDuration];
+////    CGSize tablecontent =self.editorTable.contentSize;
+////    tablecontent.height=tablecontent.height-self.keyboard_h;
+////    //    self.editorTable.contentSize=tablecontent;
+////
+////    self.editorTable.frame = CGRectMake(0, 0, self.editorTable.frame.size.width, table_origin_h);
+////
+////    self.keyboard_h= 0;
+////    DebugLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
+////
+////
+////    //    if(self.resize)
+////    //    {
+////    //        NSTimeInterval animationDuration = 0.30f;
+////    //        CGRect frame = self.view.frame;
+////    //        //    if(prewTag == textField.tag) //当结束编辑的View的TAG是上次的就移动
+////    //        //    {   //还原界面
+////    //        //        moveY =  prewMoveY;
+////    //        frame.origin.y +=self.ioffset;
+////    //        frame.size. height -=self.ioffset;
+////    //        self.view.frame = frame;
+////    //        //    }
+////    //        //self.view移回原位置
+////    //        [UIView beginAnimations:@"ResizeView" context:nil];
+////    //        [UIView setAnimationDuration:animationDuration];
+////    //        self.view.frame = frame;
+////    //        [UIView commitAnimations];
+////    //        //[textField resignFirstResponder];
+////    //        self.ioffset=0;
+////    //    }
+////
+////
+////    //  [self moveInputBarWithKeyboardHeight:0.0 withDuration:animationDuration];
+//}
 
 #pragma mark - RageCell Delegate
 

+ 16 - 18
RedAnt ERP Mobile/common/ERP_Mobile_Contact.storyboard

@@ -3,7 +3,7 @@
     <device id="ipad9_7" orientation="portrait" layout="fullscreen" appearance="light"/>
     <dependencies>
         <deployment identifier="iOS"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16086"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
         <capability name="Safe area layout guides" minToolsVersion="9.0"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
@@ -12,10 +12,6 @@
         <scene sceneID="hHO-Dm-MSy">
             <objects>
                 <viewController storyboardIdentifier="ContactListViewController" title="Contact List" useStoryboardIdentifierAsRestorationIdentifier="YES" id="nYA-mr-Jr1" customClass="ContactListViewController" sceneMemberID="viewController">
-                    <layoutGuides>
-                        <viewControllerLayoutGuide type="top" id="ded-ER-OA1"/>
-                        <viewControllerLayoutGuide type="bottom" id="0I8-iZ-xjq"/>
-                    </layoutGuides>
                     <view key="view" contentMode="scaleToFill" id="kOx-jb-UtN">
                         <rect key="frame" x="0.0" y="0.0" width="768" height="1024"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
@@ -33,7 +29,7 @@
                                     <barButtonItem style="plain" systemItem="flexibleSpace" id="Kh1-HL-uSg"/>
                                     <barButtonItem style="plain" id="3JX-S8-pQQ">
                                         <searchBar key="customView" contentMode="redraw" searchBarStyle="minimal" placeholder="Name, Address, Phone etc" id="LlH-OI-NKM">
-                                            <rect key="frame" x="308" y="3" width="361" height="44"/>
+                                            <rect key="frame" x="300" y="3" width="361" height="44"/>
                                             <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
                                             <textInputTraits key="textInputTraits"/>
                                             <connections>
@@ -41,11 +37,12 @@
                                             </connections>
                                         </searchBar>
                                     </barButtonItem>
-                                    <barButtonItem width="42" style="plain" systemItem="fixedSpace" id="VDA-fn-Xil"/>
+                                    <barButtonItem width="42" style="plain" systemItem="fixedSpace" id="Tff-3j-POA"/>
+                                    <barButtonItem enabled="NO" id="6yA-4j-4Jw"/>
                                     <barButtonItem image="newcustomer" id="0ZI-ZH-e6C">
                                         <color key="tintColor" red="0.59999999999999998" green="0.40000000000000002" blue="0.20000000000000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                                         <connections>
-                                            <action selector="onNewCustomerClick:" destination="nYA-mr-Jr1" id="QnL-H7-01J"/>
+                                            <action selector="onNewCustomerClick:" destination="nYA-mr-Jr1" id="Otk-ul-0n9"/>
                                         </connections>
                                     </barButtonItem>
                                 </items>
@@ -109,25 +106,26 @@
                         </subviews>
                         <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                         <constraints>
-                            <constraint firstItem="0I8-iZ-xjq" firstAttribute="top" secondItem="OI6-ri-aSh" secondAttribute="bottom" id="3oX-iM-Ks6"/>
-                            <constraint firstItem="2zZ-CD-G37" firstAttribute="centerX" secondItem="kOx-jb-UtN" secondAttribute="centerX" id="AY5-ce-YHc"/>
-                            <constraint firstItem="OI6-ri-aSh" firstAttribute="leading" secondItem="U3k-01-o7I" secondAttribute="leading" id="FCf-Vc-4wr"/>
-                            <constraint firstItem="Or5-ax-ZZ1" firstAttribute="leading" secondItem="U3k-01-o7I" secondAttribute="leading" id="IAa-LV-nV4"/>
+                            <constraint firstItem="PMy-fH-koM" firstAttribute="bottom" secondItem="OI6-ri-aSh" secondAttribute="bottom" id="3oX-iM-Ks6"/>
+                            <constraint firstItem="2zZ-CD-G37" firstAttribute="centerX" secondItem="PMy-fH-koM" secondAttribute="centerX" id="AY5-ce-YHc"/>
+                            <constraint firstItem="OI6-ri-aSh" firstAttribute="leading" secondItem="PMy-fH-koM" secondAttribute="leading" id="FCf-Vc-4wr"/>
+                            <constraint firstItem="Or5-ax-ZZ1" firstAttribute="leading" secondItem="PMy-fH-koM" secondAttribute="leading" id="IAa-LV-nV4"/>
                             <constraint firstItem="2zZ-CD-G37" firstAttribute="centerY" secondItem="kOx-jb-UtN" secondAttribute="centerY" id="SPc-JR-0z9"/>
-                            <constraint firstItem="Or5-ax-ZZ1" firstAttribute="trailing" secondItem="U3k-01-o7I" secondAttribute="trailing" id="aF0-GZ-ysg"/>
-                            <constraint firstItem="Or5-ax-ZZ1" firstAttribute="top" secondItem="ded-ER-OA1" secondAttribute="bottom" id="fWM-on-hS3"/>
-                            <constraint firstItem="R2e-04-QIL" firstAttribute="centerX" secondItem="kOx-jb-UtN" secondAttribute="centerX" id="gyd-fk-gRV"/>
-                            <constraint firstItem="OI6-ri-aSh" firstAttribute="trailing" secondItem="U3k-01-o7I" secondAttribute="trailing" id="ko6-Or-s5k"/>
+                            <constraint firstItem="Or5-ax-ZZ1" firstAttribute="trailing" secondItem="PMy-fH-koM" secondAttribute="trailing" id="aF0-GZ-ysg"/>
+                            <constraint firstItem="Or5-ax-ZZ1" firstAttribute="top" secondItem="PMy-fH-koM" secondAttribute="top" id="fWM-on-hS3"/>
+                            <constraint firstItem="R2e-04-QIL" firstAttribute="centerX" secondItem="PMy-fH-koM" secondAttribute="centerX" id="gyd-fk-gRV"/>
+                            <constraint firstItem="OI6-ri-aSh" firstAttribute="trailing" secondItem="PMy-fH-koM" secondAttribute="trailing" id="ko6-Or-s5k"/>
                             <constraint firstItem="OI6-ri-aSh" firstAttribute="top" secondItem="Or5-ax-ZZ1" secondAttribute="bottom" symbolic="YES" id="p3c-j4-dSa"/>
                             <constraint firstItem="R2e-04-QIL" firstAttribute="centerY" secondItem="kOx-jb-UtN" secondAttribute="centerY" id="xgD-hS-EhU"/>
                         </constraints>
-                        <viewLayoutGuide key="safeArea" id="U3k-01-o7I"/>
+                        <viewLayoutGuide key="safeArea" id="PMy-fH-koM"/>
                     </view>
                     <connections>
                         <outlet property="label_net_err" destination="R2e-04-QIL" id="F6l-LI-Mui"/>
                         <outlet property="mum" destination="2zZ-CD-G37" id="qCb-6v-E7n"/>
                         <outlet property="searchBar" destination="LlH-OI-NKM" id="lK3-g1-giU"/>
                         <outlet property="table" destination="OI6-ri-aSh" id="P60-cj-7pE"/>
+                        <outlet property="toolbar" destination="Or5-ax-ZZ1" id="VY0-Xa-Q8P"/>
                     </connections>
                 </viewController>
                 <placeholder placeholderIdentifier="IBFirstResponder" id="UUC-KF-pFb" userLabel="First Responder" sceneMemberID="firstResponder"/>
@@ -137,6 +135,6 @@
     </scenes>
     <resources>
         <image name="assign" width="40" height="40"/>
-        <image name="newcustomer" width="32" height="32"/>
+        <image name="newcustomer" width="40" height="40"/>
     </resources>
 </document>

+ 3 - 2
RedAnt ERP Mobile/common/ERP_Mobile_Order.storyboard

@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16096" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
     <device id="ipad9_7" orientation="portrait" layout="fullscreen" appearance="light"/>
     <dependencies>
         <deployment identifier="iOS"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15510"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
         <capability name="Safe area layout guides" minToolsVersion="9.0"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
@@ -536,6 +536,7 @@
                                         </searchBar>
                                     </barButtonItem>
                                     <barButtonItem style="plain" systemItem="flexibleSpace" id="QSC-SH-uLY"/>
+                                    <barButtonItem enabled="NO" id="gC0-8y-KuJ"/>
                                     <barButtonItem image="Combinegray" id="1DF-ll-7D8">
                                         <connections>
                                             <action selector="editOrderListButtonClick:" destination="Q3R-QB-OJA" id="aUm-1f-TOV"/>

+ 5 - 8
RedAnt ERP Mobile/common/ERP_Mobile_Portfolio.storyboard

@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16097" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
     <device id="ipad9_7" orientation="portrait" layout="fullscreen" appearance="light"/>
     <dependencies>
         <deployment identifier="iOS"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15509"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
         <capability name="Safe area layout guides" minToolsVersion="9.0"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
@@ -24,7 +24,7 @@
                                 <rect key="frame" x="0.0" y="0.0" width="768" height="974"/>
                                 <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                                 <prototypes>
-                                    <tableViewCell contentMode="scaleToFill" fixedFrame="YES" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="WatchListItemCell" rowHeight="120" translatesAutoresizingMaskIntoConstraints="NO" id="6GU-0i-6NT" customClass="ModelItemCell">
+                                    <tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="WatchListItemCell" rowHeight="120" translatesAutoresizingMaskIntoConstraints="NO" id="6GU-0i-6NT" customClass="ModelItemCell">
                                         <rect key="frame" x="0.0" y="28" width="768" height="120"/>
                                         <autoresizingMask key="autoresizingMask"/>
                                         <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="6GU-0i-6NT" id="1hj-1W-Fag">
@@ -145,14 +145,12 @@
                                 <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                                 <items>
                                     <barButtonItem title="Select all" id="rkp-fD-jUp">
-                                        <color key="tintColor" red="0.59999999999999998" green="0.40000000000000002" blue="0.20000000000000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                                         <connections>
                                             <action selector="onSelectClick:" destination="yR0-uM-vSf" id="BmK-8X-xGy"/>
                                         </connections>
                                     </barButtonItem>
                                     <barButtonItem width="42" style="plain" systemItem="fixedSpace" id="dhP-c4-vbs"/>
                                     <barButtonItem title="Delete" id="Dik-9B-lll">
-                                        <color key="tintColor" red="0.59999999999999998" green="0.40000000000000002" blue="0.20000000000000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                                         <connections>
                                             <action selector="onDeleteClick:" destination="yR0-uM-vSf" id="dVy-J7-pJV"/>
                                         </connections>
@@ -165,7 +163,6 @@
                                     </barButtonItem>
                                     <barButtonItem width="42" style="plain" systemItem="fixedSpace" id="Nuy-yl-mxD"/>
                                     <barButtonItem title="Create Portfolio" id="4qg-qC-65n">
-                                        <color key="tintColor" red="0.59999999999999998" green="0.40000000000000002" blue="0.20000000000000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                                         <connections>
                                             <action selector="onCreateTearSheet:" destination="yR0-uM-vSf" id="Mxj-DH-tMX"/>
                                         </connections>
@@ -552,7 +549,7 @@
                                 </items>
                             </navigationBar>
                             <activityIndicatorView opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" hidesWhenStopped="YES" animating="YES" style="whiteLarge" translatesAutoresizingMaskIntoConstraints="NO" id="MG5-Qo-QiV">
-                                <rect key="frame" x="366" y="494" width="37" height="37"/>
+                                <rect key="frame" x="365.5" y="493.5" width="37" height="37"/>
                                 <color key="color" red="0.59999999999999998" green="0.40000000000000002" blue="0.20000000000000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                             </activityIndicatorView>
                             <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="GUB-XJ-Xjd">
@@ -602,7 +599,7 @@
                                 </connections>
                             </tableView>
                             <label hidden="YES" opaque="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Cannot get data from server.
Tap to try again." textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dP6-eo-w8h">
-                                <rect key="frame" x="262" y="489" width="244" height="46"/>
+                                <rect key="frame" x="262" y="489.5" width="244" height="45.5"/>
                                 <fontDescription key="fontDescription" type="system" pointSize="19"/>
                                 <color key="textColor" red="0.33333333329999998" green="0.33333333329999998" blue="0.33333333329999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                                 <nil key="highlightedColor"/>

+ 2 - 2
RedAnt ERP Mobile/common/ERP_Mobile_Search.storyboard

@@ -3,7 +3,7 @@
     <device id="ipad9_7" orientation="portrait" layout="fullscreen" appearance="light"/>
     <dependencies>
         <deployment identifier="iOS"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16086"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
         <capability name="Safe area layout guides" minToolsVersion="9.0"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
@@ -2230,7 +2230,7 @@
         <image name="btn_search" width="102" height="30"/>
         <image name="check_0_24" width="24" height="24"/>
         <image name="check_1_24" width="24" height="24"/>
-        <image name="close" width="32" height="32"/>
+        <image name="close" width="40" height="40"/>
         <image name="filter" width="32" height="32"/>
         <image name="layout_list" width="40" height="40"/>
         <image name="layout_small" width="40" height="40"/>

+ 94 - 86
RedAnt ERP Mobile/common/Functions/MainViewController.m

@@ -269,7 +269,11 @@
         [self.btnLogin setTitle:@"Sign out" forState:UIControlStateNormal];
     else
         [self.btnLogin setTitle:@"Sign in" forState:UIControlStateNormal];
-    [RANetwork LoadImage:appDelegate.user_icon into:self.user_head ];
+    
+    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+        [RANetwork LoadImage:appDelegate.user_icon into:self.user_head ];
+    });
+    
     
     if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE*/true)
         self.btnContact.hidden = NO;
@@ -660,57 +664,59 @@
     
     if(appDelegate.bLogin)
     {
-        UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Sign out"];
-        
-        [RANetwork request_logout:^(NSMutableDictionary *result) {
-            NSMutableDictionary* return_json =result;
-            
-            [waitalert dismissViewControllerAnimated:YES completion:^{
-                if([[return_json valueForKey:@"result"] intValue]==2)
-                {
-                    //                    [self hideMenu];
-                    //                    [self switchToHome:nil];
-                    [appDelegate Logout];
-                    [self checklogin :false];
-                    if(showlogin)
+        __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Sign out" completion:^{
+            [RANetwork request_logout:^(NSMutableDictionary *result) {
+                NSMutableDictionary* return_json =result;
+                
+                [waitalert dismissViewControllerAnimated:YES completion:^{
+                    if([[return_json valueForKey:@"result"] intValue]==2)
                     {
-                        LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
-                        loginvc.returnValue = ^(bool blogin){
-                            
-                            [self checklogin :true];
-                            
-                        };
-                        
-                        UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
-                        
-                        
-                        
-                        
-                        
-                        
-                        navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
-                        [self presentViewController:navi animated:YES completion:^{
-                            
-                            DebugLog(@"login present.........");
+                        //                    [self hideMenu];
+                        //                    [self switchToHome:nil];
+                        [appDelegate Logout];
+                        [self checklogin :false];
+                        if(showlogin)
+                        {
+                            LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
+                            loginvc.returnValue = ^(bool blogin){
+                                
+                                [self checklogin :true];
+                                
+                            };
                             
-                        }];
-                    }
-                }
-                else
-                {
-                    [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
-                }
-            }];
+                            UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
                             
                             
                             
                             
                             
                             
+                            navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
+                            [self presentViewController:navi animated:YES completion:^{
+                                
+                                DebugLog(@"login present.........");
+                                
+                            }];
+                        }
+                    }
+                    else
+                    {
+                        [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
+                    }
+                }];
+                                
+                                
+                                
+                                
+                                
+                                
+                                
                             
-                        
+            }];
+
         }];
         
+                
 //        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //            
 //            NSDictionary* return_json = [RANetwork logout];
@@ -3083,52 +3089,54 @@
 -(void) neworderforCart
 {
     
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order"];
-    [RANetwork request_create_order:^(NSMutableDictionary *result) {
-        NSMutableDictionary* return_json = result;
-        
-        [waitalert dismissViewControllerAnimated:YES completion:^{
-            if([[return_json valueForKey:@"result"] intValue]==2)
-            {
-                int result=[[return_json valueForKey:@"result"] intValue];
-                if(result==2)
-                {
-                    //successed.
-                    
-                    NSString* order_code = [return_json valueForKey:@"orderCode"];
-                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                    appDelegate.order_code = order_code;
-                    appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
-                    
-                    self.previous_VC = self.current_VC;
-                    [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
-                    
-                    
-#ifdef RA_NOTIFICATION
-                    [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-#else
-                    [self reloadCart:true immediately:false];
-                    [self reloadOrder:true immediately:false];
-#endif
-                    
-                    
-                }
-            }
-            else
-            {
-                [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
-            }
-        }];
-        
-        
-        
-        
-        
-        
-        
-        
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order" completion:^{
+        [RANetwork request_create_order:^(NSMutableDictionary *result) {
+                NSMutableDictionary* return_json = result;
+                
+                [waitalert dismissViewControllerAnimated:YES completion:^{
+                    if([[return_json valueForKey:@"result"] intValue]==2)
+                    {
+                        int result=[[return_json valueForKey:@"result"] intValue];
+                        if(result==2)
+                        {
+                            //successed.
+                            
+                            NSString* order_code = [return_json valueForKey:@"orderCode"];
+                            AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                            appDelegate.order_code = order_code;
+                            appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
+                            
+                            self.previous_VC = self.current_VC;
+                            [self flipFromViewController:self.current_VC toViewController:self.cartViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
+                            
+                            
+        #ifdef RA_NOTIFICATION
+                            [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+        #else
+                            [self reloadCart:true immediately:false];
+                            [self reloadOrder:true immediately:false];
+        #endif
+                            
+                            
+                        }
+                    }
+                    else
+                    {
+                        [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
+                    }
+                }];
+                
+                
+                
+                
+                
+                
+                
+                
+            }];
+
     }];
-//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+    //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //        
 //        NSDictionary* return_json = [RANetwork new_Order];
 //        

+ 26 - 24
RedAnt ERP Mobile/common/Functions/address/AddressEditorViewController.m

@@ -149,38 +149,40 @@
     if(self.cancommit==false)
         return;
     
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Save Address"];
-    
-    [RANetwork request_add_address:upparams completionHandler:^(NSMutableDictionary *result) {
-        
-        [waitalert dismissViewControllerAnimated:YES completion:^{
-            NSDictionary* editor_json = result;
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Save Address" completion:^{
+        [RANetwork request_add_address:upparams completionHandler:^(NSMutableDictionary *result) {
             
-            if([[editor_json valueForKey:@"result"] intValue]==2)
-            {
-                
-                //                int result = [[editor_json valueForKey:@"result"] intValue];
+            [waitalert dismissViewControllerAnimated:YES completion:^{
+                NSDictionary* editor_json = result;
                 
-                //                if(result==2)
+                if([[editor_json valueForKey:@"result"] intValue]==2)
                 {
                     
-                    [self.navigationController popViewControllerAnimated:true];
-                    [self prepareReturn: nil];
+                    //                int result = [[editor_json valueForKey:@"result"] intValue];
+                    
+                    //                if(result==2)
+                    {
+                        
+                        [self.navigationController popViewControllerAnimated:true];
+                        [self prepareReturn: nil];
+                    }
+                    
+                    
                 }
-                
-                
-            }
-            else
-            {
-                [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Address" controller:self] ;
-            }
+                else
+                {
+                    [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Address" controller:self] ;
+                }
+            }];
+            
+            
+            
+            
         }];
-        
-        
-        
-        
+
     }];
     
+        
 //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //        NSDictionary* editor_json = [RANetwork create_Address:upparams];

+ 38 - 36
RedAnt ERP Mobile/common/Functions/camscan/ScannerViewController.m

@@ -674,48 +674,50 @@
 -(void) neworder
 {
     
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order"];
-    [RANetwork request_create_order:^(NSMutableDictionary *result) {
-        NSMutableDictionary* return_json = result;
-        
-        [waitalert dismissViewControllerAnimated:YES completion:^{
-            
-            //        [waitalert dismissViewControllerAnimated:YES completion:nil];
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order" completion:^{
+        [RANetwork request_create_order:^(NSMutableDictionary *result) {
+            NSMutableDictionary* return_json = result;
             
-            
-            if([[return_json valueForKey:@"result"] intValue]==2)
-            {
-                int result=[[return_json valueForKey:@"result"] intValue];
-                if(result==2)
+            [waitalert dismissViewControllerAnimated:YES completion:^{
+                
+                //        [waitalert dismissViewControllerAnimated:YES completion:nil];
+                
+                
+                if([[return_json valueForKey:@"result"] intValue]==2)
+                {
+                    int result=[[return_json valueForKey:@"result"] intValue];
+                    if(result==2)
+                    {
+                        //successed.
+                        
+                        NSString* order_code = [return_json valueForKey:@"orderCode"];
+                        AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                        appDelegate.order_code = order_code;
+                        appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
+                        
+                        
+                        [self addtocart];
+                        
+                        
+                        
+                    }
+                }
+                else
                 {
-                    //successed.
-                    
-                    NSString* order_code = [return_json valueForKey:@"orderCode"];
-                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                    appDelegate.order_code = order_code;
-                    appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
-                    
-                    
-                    [self addtocart];
-                    
-                    
                     
+                    [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
                 }
-            }
-            else
-            {
-                
-                [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
-            }
+            }];
+            
+            
+            
+            
+            
+            
         }];
-        
-        
-        
-        
-        
-        
+
     }];
-//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+    //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //        NSDictionary* return_json = [RANetwork new_Order];
 //

+ 33 - 31
RedAnt ERP Mobile/common/Functions/cart/CartGeneralNotesViewController.m

@@ -53,41 +53,43 @@
     
     // [self.tv_notes endEditing:true];
     self.notes = self.tv_notes.text;
-    
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Update General Notes"];
-    
     NSString* notes=self.tv_notes.text;
-    UIApplication * app = [UIApplication sharedApplication];
-     AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-    
-    
-    [RANetwork request_update_cartgeneralnote:appDelegate.order_code notes:notes completionHandler:^(NSMutableDictionary *result) {
-        NSDictionary* cart_json = result;
-        
-        [waitalert dismissViewControllerAnimated:YES completion:^{
-            //            [waitalert dismissViewControllerAnimated:YES completion:nil];
-            if([[cart_json valueForKey:@"result"] intValue]==2)
-            {
-                [self dismissViewControllerAnimated:NO
-                                         completion:^{
-                    
-                    if(self.onSetValue)
-                        self.onSetValue(self.notes);
-                    
-                }];
-            }
-            else
-            {
-                [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Update General Notes" controller:self] ;
-            }
+       UIApplication * app = [UIApplication sharedApplication];
+        AppDelegate *appDelegate = (AppDelegate *)[app delegate];
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Update General Notes" completion:^{
+        [RANetwork request_update_cartgeneralnote:appDelegate.order_code notes:notes completionHandler:^(NSMutableDictionary *result) {
+            NSDictionary* cart_json = result;
+            
+            [waitalert dismissViewControllerAnimated:YES completion:^{
+                //            [waitalert dismissViewControllerAnimated:YES completion:nil];
+                if([[cart_json valueForKey:@"result"] intValue]==2)
+                {
+                    [self dismissViewControllerAnimated:NO
+                                             completion:^{
+                        
+                        if(self.onSetValue)
+                            self.onSetValue(self.notes);
+                        
+                    }];
+                }
+                else
+                {
+                    [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Update General Notes" controller:self] ;
+                }
+            }];
+
+            
+            
+            
+            
         }];
 
-        
-        
-        
-        
     }];
-//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+    
+   
+    
+    
+    //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //        NSDictionary* cart_json = nil;
 //

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 473 - 451
RedAnt ERP Mobile/common/Functions/cart/CartViewController.m


+ 25 - 23
RedAnt ERP Mobile/common/Functions/cart/ItemNotesViewController.m

@@ -60,34 +60,36 @@
     
     self.notes = self.tv_notes.text;
     
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Update Item Notes"];
-    
-    [RANetwork request_update_cartitemnote:self.cart_id notes:self.tv_notes.text completionHandler:^(NSMutableDictionary *result) {
-        
-        NSDictionary* cart_json = result;
-        [waitalert dismissViewControllerAnimated:YES completion:^{
-            if([[cart_json valueForKey:@"result"] intValue]==2)
-            {
-                [self dismissViewControllerAnimated:NO
-                                         completion:^{
-                    if(self.onSaveNote)
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Update Item Notes" completion:^{
+        [RANetwork request_update_cartitemnote:self.cart_id notes:self.tv_notes.text completionHandler:^(NSMutableDictionary *result) {
+            
+            NSDictionary* cart_json = result;
+            [waitalert dismissViewControllerAnimated:YES completion:^{
+                if([[cart_json valueForKey:@"result"] intValue]==2)
+                {
+                    [self dismissViewControllerAnimated:NO
+                                             completion:^{
+                        if(self.onSaveNote)
+                            
+                            self.onSaveNote(self.notes);
                         
-                        self.onSaveNote(self.notes);
-                    
-                }];
-            }
-            else
-            {
-                [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Update Item Notes" controller:self] ;
-            }
+                    }];
+                }
+                else
+                {
+                    [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Update Item Notes" controller:self] ;
+                }
+            }];
+
+            
+            
+            
+            
         }];
 
-        
-        
-        
-        
     }];
     
+        
 //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //        NSDictionary* cart_json = nil;

+ 5 - 2
RedAnt ERP Mobile/common/Functions/category/CategorySearchFilterViewController.m

@@ -515,8 +515,11 @@
 }
 - (IBAction)onSearchClick:(id)sender {
     
-
-    NSString *ids = [[self get_checkedIDs:self.categoryMenu] componentsJoinedByString:@","];
+    
+    NSArray* arrids =[self get_checkedIDs:self.categoryMenu];
+    NSString *ids=nil;
+    if(arrids.count>0)
+     ids= [arrids componentsJoinedByString:@","];
     
     NSString* modelname = self.textModelName.text;
     if(modelname.length==0)

+ 272 - 249
RedAnt ERP Mobile/common/Functions/category/CategoryViewController.m

@@ -117,6 +117,19 @@
             }
             
         }
+        else
+        {
+            switch (type) {
+                case 3:
+                    item[@"wish_exists"]=@"true";
+                    break;
+                case 4:
+                    item[@"cart_exists"]=@"true";
+                    break;
+                default:
+                    break;
+            }
+        }
         [item setValue:@"false" forKey:@"checked"];
         
         
@@ -549,40 +562,42 @@
 -(void) neworder
 {
     
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order"];
-    [RANetwork request_create_order:^(NSMutableDictionary *result) {
-        NSMutableDictionary* return_json = result;
-        
-        [waitalert dismissViewControllerAnimated:YES completion:^{
-            if([[return_json valueForKey:@"result"] intValue]==2)
-            {
-                int result=[[return_json valueForKey:@"result"] intValue];
-                if(result==2)
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order" completion:^{
+        [RANetwork request_create_order:^(NSMutableDictionary *result) {
+            NSMutableDictionary* return_json = result;
+            
+            [waitalert dismissViewControllerAnimated:YES completion:^{
+                if([[return_json valueForKey:@"result"] intValue]==2)
                 {
-                    //successed.
-                    
-                    NSString* order_code = [return_json valueForKey:@"orderCode"];
-                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                    appDelegate.order_code = order_code;
-                    [self addtocart];
+                    int result=[[return_json valueForKey:@"result"] intValue];
+                    if(result==2)
+                    {
+                        //successed.
+                        
+                        NSString* order_code = [return_json valueForKey:@"orderCode"];
+                        AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                        appDelegate.order_code = order_code;
+                        [self addtocart];
 
+                    }
                 }
-            }
-            else
-            {
-                [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
-            }
+                else
+                {
+                    [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
+                }
+            }];
+            
+            
+
+            
+            
+            
+            
+            
         }];
-        
-        
 
-        
-        
-        
-        
-        
     }];
-//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+    //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //        NSDictionary* return_json = [RANetwork new_Order];
 //
@@ -761,7 +776,9 @@
     
     
     
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Add Models To Cart"];
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Add Models To Cart" completion:^{
+        
+    }];
     
     
     if (self.addAll) {
@@ -817,7 +834,7 @@
                         }
                         [RAUtils message_alert:nil title:msg controller:self] ;
                         
-                        [self end_select:2];
+                        [self end_select:4];
                         
                         
                         
@@ -836,7 +853,7 @@
                     [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
 #endif
                     
-                    [self end_select:2];
+                    [self end_select:4];
                     [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
                 }
                 else
@@ -1084,134 +1101,136 @@
     self.addPortfolioBtn.enabled =false;
     
     
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Add Models To Portfolio"];
-    
-    
-            if (self.addAll) {
-    //            AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
-                [RANetwork request_addall_category:self.categoryid customid:0 price_template:0 sort:0 filter:nil keyword:nil offset:self.offset limit:20 alert:self.p_alert qty:self.p_QTY available:self.p_available price:self.p_price bestseller:self.p_bestseller modelname:self.modelname modeldescrip:self.modeldescrip orderCode:nil  addTo:@"portfolio" completionHandler:^(NSMutableDictionary *result) {
-                    
-                    NSDictionary* return_json = result;
-                    [waitalert dismissViewControllerAnimated:YES completion:^{
-                        self.addPortfolioBtn.enabled =true;
-                        
-                        if([[return_json valueForKey:@"result"] intValue]==2)
-                        {
-                            //                int result=[[return_json valueForKey:@"result"] intValue];
-                            //                if(result==2)
-                            //                {
-                            //                    //successed.
-                            
-                            
-                            
-                            
-#ifdef RA_NOTIFICATION
-                            [ActiveViewController Notify:@"PortfolioViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-#else
-                            AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                            [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
-#endif
-                            
-                            NSString * msg = nil;
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Add Models To Portfolio" completion:^{
+                    if (self.addAll) {
+            //            AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
+                        [RANetwork request_addall_category:self.categoryid customid:0 price_template:0 sort:0 filter:nil keyword:nil offset:self.offset limit:20 alert:self.p_alert qty:self.p_QTY available:self.p_available price:self.p_price bestseller:self.p_bestseller modelname:self.modelname modeldescrip:self.modeldescrip orderCode:nil  addTo:@"portfolio" completionHandler:^(NSMutableDictionary *result) {
                             
-                            if (self.addAll) {
+                            NSDictionary* return_json = result;
+                            [waitalert dismissViewControllerAnimated:YES completion:^{
+                                self.addPortfolioBtn.enabled =true;
                                 
-                                unsigned long checkedCount = [return_json[@"count"] integerValue];
-                                
-                                msg=[NSString stringWithFormat:@"%lu items added to Portfolio",checkedCount];
-                            } else {
-                                
-                                if(checked.count==1)
+                                if([[return_json valueForKey:@"result"] intValue]==2)
                                 {
-                                    msg=@"1 item added to Portfolio";
+                                    //                int result=[[return_json valueForKey:@"result"] intValue];
+                                    //                if(result==2)
+                                    //                {
+                                    //                    //successed.
+                                    
+                                    
+                                    
+                                    
+        #ifdef RA_NOTIFICATION
+                                    [ActiveViewController Notify:@"PortfolioViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+        #else
+                                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                                    [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
+        #endif
+                                    
+                                    NSString * msg = nil;
+                                    
+                                    if (self.addAll) {
+                                        
+                                        unsigned long checkedCount = [return_json[@"count"] integerValue];
+                                        
+                                        msg=[NSString stringWithFormat:@"%lu items added to Portfolio",checkedCount];
+                                    } else {
+                                        
+                                        if(checked.count==1)
+                                        {
+                                            msg=@"1 item added to Portfolio";
+                                        }
+                                        else
+                                        {
+                                            msg=[NSString stringWithFormat:@"%lu items added to Portfolio",(unsigned long)checked.count];
+                                        }
+                                    }
+                                    
+                                    [RAUtils message_alert:nil title:msg controller:self] ;
+                                    
+                                    
+                                    [self end_select:3 ];
+                                    
                                 }
                                 else
                                 {
-                                    msg=[NSString stringWithFormat:@"%lu items added to Portfolio",(unsigned long)checked.count];
+                                    [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Portfolio" controller:self] ;
                                 }
-                            }
+                            }];
                             
-                            [RAUtils message_alert:nil title:msg controller:self] ;
                             
                             
-                            [self end_select:3 ];
-                            
-                        }
-                        else
-                        {
-                            [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Portfolio" controller:self] ;
-                        }
-                    }];
-                    
-                    
-                    
-                    
-                    
-                }];
-                
-                
-            } else {
-                [RANetwork request_addto_portfolio:ids withScreen:ScreenCodeCategory completionHandler:^(NSMutableDictionary *result) {
-                    
-                    NSDictionary* return_json = result;
-                    [waitalert dismissViewControllerAnimated:YES completion:^{
-                        self.addPortfolioBtn.enabled =true;
-                        
-                        if([[return_json valueForKey:@"result"] intValue]==2)
-                        {
-                            //                int result=[[return_json valueForKey:@"result"] intValue];
-                            //                if(result==2)
-                            //                {
-                            //                    //successed.
                             
                             
+                        }];
+                        
+                        
+                    } else {
+                        [RANetwork request_addto_portfolio:ids withScreen:ScreenCodeCategory completionHandler:^(NSMutableDictionary *result) {
                             
-                            
-#ifdef RA_NOTIFICATION
-                            [ActiveViewController Notify:@"PortfolioViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-#else
-                            AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                            [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
-#endif
-                            
-                            NSString * msg = nil;
-                            
-                            if (self.addAll) {
-                                
-                                unsigned long checkedCount = [return_json[@"count"] integerValue];
+                            NSDictionary* return_json = result;
+                            [waitalert dismissViewControllerAnimated:YES completion:^{
+                                self.addPortfolioBtn.enabled =true;
                                 
-                                msg=[NSString stringWithFormat:@"%lu items added to Portfolio",checkedCount];
-                            } else {
-                                
-                                if(checked.count==1)
+                                if([[return_json valueForKey:@"result"] intValue]==2)
                                 {
-                                    msg=@"1 item added to Portfolio";
+                                    //                int result=[[return_json valueForKey:@"result"] intValue];
+                                    //                if(result==2)
+                                    //                {
+                                    //                    //successed.
+                                    
+                                    
+                                    
+                                    
+        #ifdef RA_NOTIFICATION
+                                    [ActiveViewController Notify:@"PortfolioViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+        #else
+                                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                                    [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
+        #endif
+                                    
+                                    NSString * msg = nil;
+                                    
+                                    if (self.addAll) {
+                                        
+                                        unsigned long checkedCount = [return_json[@"count"] integerValue];
+                                        
+                                        msg=[NSString stringWithFormat:@"%lu items added to Portfolio",checkedCount];
+                                    } else {
+                                        
+                                        if(checked.count==1)
+                                        {
+                                            msg=@"1 item added to Portfolio";
+                                        }
+                                        else
+                                        {
+                                            msg=[NSString stringWithFormat:@"%lu items added to Portfolio",(unsigned long)checked.count];
+                                        }
+                                    }
+                                    
+                                    [RAUtils message_alert:nil title:msg controller:self] ;
+                                    
+                                    
+                                    [self end_select:3 ];
+                                    
                                 }
                                 else
                                 {
-                                    msg=[NSString stringWithFormat:@"%lu items added to Portfolio",(unsigned long)checked.count];
+                                    [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Portfolio" controller:self] ;
                                 }
-                            }
+                            }];
                             
-                            [RAUtils message_alert:nil title:msg controller:self] ;
                             
                             
-                            [self end_select:3 ];
                             
-                        }
-                        else
-                        {
-                            [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Portfolio" controller:self] ;
-                        }
-                    }];
-                    
-                    
-                    
-                    
-                    
-                }];
-               
-            }
+                            
+                        }];
+                       
+                    }
+    }];
+    
+    
+
 
 //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
@@ -1313,134 +1332,136 @@
     NSString * ids = [checked componentsJoinedByString:@","];
     self.addWishBtn.enabled =false;
     
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Add Models To Wish List"];
-    
-    if (self.addAll) {
-        
-        [RANetwork request_addall_category:self.categoryid customid:0 price_template:0 sort:0 filter:nil keyword:nil offset:self.offset limit:20 alert:self.p_alert qty:self.p_QTY available:self.p_available price:self.p_price bestseller:self.p_bestseller modelname:self.modelname modeldescrip:self.modeldescrip orderCode:nil  addTo:@"wishlist" completionHandler:^(NSMutableDictionary *result) {
-            NSDictionary* return_json = result;
-            [waitalert dismissViewControllerAnimated:YES completion:^{
-                self.addWishBtn.enabled =true;
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Add Models To Wish List" completion:^{
+        if (self.addAll) {
                 
-                if([[return_json valueForKey:@"result"] intValue]==2)
-                {
-                    
-                    //successed.
-                    
-                    //                    NSString* order_code = [return_json valueForKey:@"order_code"];
-                    
-                    
-#ifdef RA_NOTIFICATION
-                    [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-#else
-                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                    
-                    [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
-#endif
-                    
-                    NSString * msg = nil;
-                    
-                    if (self.addAll) {
-                        
-                        unsigned long checkedCount = [return_json[@"count"] integerValue];
-                        
-                        msg=[NSString stringWithFormat:@"%lu items added to \nWish List",checkedCount];
-                    } else {
+                [RANetwork request_addall_category:self.categoryid customid:0 price_template:0 sort:0 filter:nil keyword:nil offset:self.offset limit:20 alert:self.p_alert qty:self.p_QTY available:self.p_available price:self.p_price bestseller:self.p_bestseller modelname:self.modelname modeldescrip:self.modeldescrip orderCode:nil  addTo:@"wishlist" completionHandler:^(NSMutableDictionary *result) {
+                    NSDictionary* return_json = result;
+                    [waitalert dismissViewControllerAnimated:YES completion:^{
+                        self.addWishBtn.enabled =true;
                         
-                        if(checked.count==1)
+                        if([[return_json valueForKey:@"result"] intValue]==2)
                         {
-                            msg=@"1 item added to \nWish List";
+                            
+                            //successed.
+                            
+                            //                    NSString* order_code = [return_json valueForKey:@"order_code"];
+                            
+                            
+        #ifdef RA_NOTIFICATION
+                            [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+        #else
+                            AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                            
+                            [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
+        #endif
+                            
+                            NSString * msg = nil;
+                            
+                            if (self.addAll) {
+                                
+                                unsigned long checkedCount = [return_json[@"count"] integerValue];
+                                
+                                msg=[NSString stringWithFormat:@"%lu items added to \nWish List",checkedCount];
+                            } else {
+                                
+                                if(checked.count==1)
+                                {
+                                    msg=@"1 item added to \nWish List";
+                                }
+                                else
+                                {
+                                    msg=[NSString stringWithFormat:@"%lu items added to \nWish List",(unsigned long)checked.count];
+                                }
+                            }
+                            
+                            [RAUtils message_alert:nil title:msg controller:self] ;
+                            
+                            
+                            
+                            [self end_select:3];
+                            
                         }
                         else
                         {
-                            msg=[NSString stringWithFormat:@"%lu items added to \nWish List",(unsigned long)checked.count];
+                            [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Wish List" controller:self] ;
                         }
-                    }
+                    }];
                     
-                    [RAUtils message_alert:nil title:msg controller:self] ;
                     
                     
                     
-                    [self end_select:1];
                     
-                }
-                else
-                {
-                    [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Wish List" controller:self] ;
-                }
-            }];
-            
-            
-            
-            
-            
-        }];
-        
-        
-        
-    } else {
-        
-        [RANetwork request_addto_wishlist:ids withScreen:ScreenCodeCategory completionHandler:^(NSMutableDictionary *result) {
-            NSDictionary* return_json = result;
-            [waitalert dismissViewControllerAnimated:YES completion:^{
-                self.addWishBtn.enabled =true;
+                }];
                 
-                if([[return_json valueForKey:@"result"] intValue]==2)
-                {
-                    
-                    //successed.
-                    
-                    //                    NSString* order_code = [return_json valueForKey:@"order_code"];
-                    
-                    
-#ifdef RA_NOTIFICATION
-                    [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-#else
-                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                    
-                    [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
-#endif
-                    
-                    NSString * msg = nil;
-                    
-                    if (self.addAll) {
-                        
-                        unsigned long checkedCount = [return_json[@"count"] integerValue];
-                        
-                        msg=[NSString stringWithFormat:@"%lu items added to \nWish List",checkedCount];
-                    } else {
+                
+                
+            } else {
+                
+                [RANetwork request_addto_wishlist:ids withScreen:ScreenCodeCategory completionHandler:^(NSMutableDictionary *result) {
+                    NSDictionary* return_json = result;
+                    [waitalert dismissViewControllerAnimated:YES completion:^{
+                        self.addWishBtn.enabled =true;
                         
-                        if(checked.count==1)
+                        if([[return_json valueForKey:@"result"] intValue]==2)
                         {
-                            msg=@"1 item added to \nWish List";
+                            
+                            //successed.
+                            
+                            //                    NSString* order_code = [return_json valueForKey:@"order_code"];
+                            
+                            
+        #ifdef RA_NOTIFICATION
+                            [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+        #else
+                            AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                            
+                            [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
+        #endif
+                            
+                            NSString * msg = nil;
+                            
+                            if (self.addAll) {
+                                
+                                unsigned long checkedCount = [return_json[@"count"] integerValue];
+                                
+                                msg=[NSString stringWithFormat:@"%lu items added to \nWish List",checkedCount];
+                            } else {
+                                
+                                if(checked.count==1)
+                                {
+                                    msg=@"1 item added to \nWish List";
+                                }
+                                else
+                                {
+                                    msg=[NSString stringWithFormat:@"%lu items added to \nWish List",(unsigned long)checked.count];
+                                }
+                            }
+                            
+                            [RAUtils message_alert:nil title:msg controller:self] ;
+                            
+                            
+                            
+                            [self end_select:1];
+                            
                         }
                         else
                         {
-                            msg=[NSString stringWithFormat:@"%lu items added to \nWish List",(unsigned long)checked.count];
+                            [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Wish List" controller:self] ;
                         }
-                    }
-                    
-                    [RAUtils message_alert:nil title:msg controller:self] ;
-                    
+                        
+                        
+                    }];
                     
                     
-                    [self end_select:1];
                     
-                }
-                else
-                {
-                    [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Wish List" controller:self] ;
-                }
+                }];
                 
                 
-            }];
-            
-            
-            
-        }];
-        
-        
-    }
+            }
+    }];
+    
+    
     
 //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
@@ -2136,7 +2157,8 @@
     //    ref.hidden = true;
     [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
     [self.collectionview addSubview:ref];
-    
+    self.collectionview.alwaysBounceVertical = YES;
+//    self.collectionview.scrollEnabled = true;
 
     
 }
@@ -2470,20 +2492,20 @@
         }
         else
         {
-            BOOL offline = NO;
-#ifdef OFFLINE_MODE
-            AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
-            offline = appDelegate.offline_mode;
-#endif
+//            BOOL offline = NO;
+//#ifdef OFFLINE_MODE
+//            AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
+//            offline = appDelegate.offline_mode;
+//#endif
             dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                 
                 NSData*  downloadimg_data = nil;
                 
                 
-                
-                if (!offline) {
+                //离线模式不会主动下载图片,避免同名图片覆盖离线图片。
+//                if (!offline) {
                     downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
-                }
+//                }
                 
                 dispatch_async(dispatch_get_main_queue(), ^{
                     
@@ -3168,6 +3190,7 @@
 #pragma mark - RA_NOTIFICAITON
 -(void) refresh_ui
 {
+     [self.tableview reloadData];
     [self.collectionview reloadData];
 }
 -(void) reload_data

+ 1 - 0
RedAnt ERP Mobile/common/Functions/contact/ContactListViewController.h

@@ -38,5 +38,6 @@
 @property bool assig_icon;
 @property bool reset_icon;
 @property int ui_type;
+@property (weak, nonatomic) IBOutlet UIToolbar *toolbar;
 
 @end

+ 76 - 69
RedAnt ERP Mobile/common/Functions/contact/ContactListViewController.m

@@ -53,6 +53,7 @@
 }
 - (void)viewDidLoad {
     [super viewDidLoad];
+//    self.toolbar.hidden=true;
     self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
     self.label_net_err.layer.borderWidth = 2.0;
     self.label_net_err.layer.cornerRadius=15;
@@ -228,6 +229,7 @@
     //    [self loadpage];
     
     [[self navigationController] setNavigationBarHidden:!self.showNavibar animated:NO];
+    ;
 }
 #ifndef RA_NOTIFICATION
 -(void) reload_container_getdata:(bool) update_data
@@ -455,7 +457,7 @@
 }
 - (IBAction)onASearch:(UIBarButtonItem *)sender {
     
-    
+
     
     ContactAdvanceSearchViewController * vc = [[ContactAdvanceSearchViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
     
@@ -498,6 +500,7 @@
 }
 - (IBAction)onNewCustomerClick:(id)sender {
     
+    NSLog(@"new click");
     
     NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
     
@@ -591,84 +594,86 @@
     
     
     
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Getting Contact information"];
-    
-    [RANetwork request_contactinfo:contactid completionHandler:^(NSMutableDictionary *result) {
-        NSMutableDictionary* editor_json = result;
-        
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Getting Contact information" completion:^{
+        [RANetwork request_contactinfo:contactid completionHandler:^(NSMutableDictionary *result) {
+            NSMutableDictionary* editor_json = result;
             
-        [waitalert dismissViewControllerAnimated:YES completion:^{
-            if([[editor_json valueForKey:@"result"] intValue]==2)
-            {
-                __block NSMutableDictionary* data_init = [[editor_json objectForKey:@"customerInfo" ] mutableCopy];
-                
-                //---------------- construct customer_contact----------------------
-                NSString* customer_first_name = [data_init valueForKey:@"customer_first_name"];
-                if(customer_first_name==nil)
-                    customer_first_name=@"";
                 
-                NSString* customer_last_name= [data_init valueForKey:@"customer_last_name"];
-                if(customer_last_name==nil)
-                    customer_last_name=@"";
-                NSString* customer_contact = [NSString stringWithFormat:@"%@ %@",customer_first_name,customer_last_name];
-                customer_contact=[customer_contact stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
-                [data_init setValue:customer_contact forKey:@"customer_contact"];
-                
-                data_init[@"is_subaction"]=self.is_subaction;
-                data_init[@"subaction_tag"]= self.subaction_tag;
-                [self.navigationController popToRootViewControllerAnimated:false];
+            [waitalert dismissViewControllerAnimated:YES completion:^{
+                if([[editor_json valueForKey:@"result"] intValue]==2)
+                {
+                    __block NSMutableDictionary* data_init = [[editor_json objectForKey:@"customerInfo" ] mutableCopy];
+                    
+                    //---------------- construct customer_contact----------------------
+                    NSString* customer_first_name = [data_init valueForKey:@"customer_first_name"];
+                    if(customer_first_name==nil)
+                        customer_first_name=@"";
+                    
+                    NSString* customer_last_name= [data_init valueForKey:@"customer_last_name"];
+                    if(customer_last_name==nil)
+                        customer_last_name=@"";
+                    NSString* customer_contact = [NSString stringWithFormat:@"%@ %@",customer_first_name,customer_last_name];
+                    customer_contact=[customer_contact stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+                    [data_init setValue:customer_contact forKey:@"customer_contact"];
+                    
+                    data_init[@"is_subaction"]=self.is_subaction;
+                    data_init[@"subaction_tag"]= self.subaction_tag;
+                    [self.navigationController popToRootViewControllerAnimated:false];
+                    
+                    
+                    [self.table reloadData];
+                    NSLog(@"%s reloadData",__FUNCTION__);
+                    if(self.returnValue)
+                        self.returnValue(data_init,self.from);
+                    
+                    //                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+                    //                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                    //                    NSDictionary* editor_json = [iSalesNetwork update_OrderCustomer:appDelegate.order_code customerinfo:data_init];
+                    //
+                    //                    dispatch_async(dispatch_get_main_queue(), ^{
+                    //
+                    //
+                    //                        if([[editor_json valueForKey:@"result"] intValue]==2)
+                    //                        {
+                    //
+                    ////                            [self.navigationController popViewControllerAnimated:false];
+                    ////                            if(self.returnValue)
+                    ////                            {
+                    ////
+                    ////                                self.returnValue(data_init);
+                    ////                            }
+                    //
+                    //
+                    //
+                    //                        }
+                    //                        else
+                    //                        {
+                    //                            [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Update Order Customer Infomation" controller:self] ;
+                    //                        }
+                    //
+                    //
+                    //
+                    //                    });
+                    //                });
+                    
+                }
+                else
+                {
+                    [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Loading Contact Information" controller:self] ;
+                    //                self.btn_assign.enabled=false;
+                }
+            }];
                 
                 
-                [self.table reloadData];
-                NSLog(@"%s reloadData",__FUNCTION__);
-                if(self.returnValue)
-                    self.returnValue(data_init,self.from);
                 
-                //                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-                //                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                //                    NSDictionary* editor_json = [iSalesNetwork update_OrderCustomer:appDelegate.order_code customerinfo:data_init];
-                //
-                //                    dispatch_async(dispatch_get_main_queue(), ^{
-                //
-                //
-                //                        if([[editor_json valueForKey:@"result"] intValue]==2)
-                //                        {
-                //
-                ////                            [self.navigationController popViewControllerAnimated:false];
-                ////                            if(self.returnValue)
-                ////                            {
-                ////
-                ////                                self.returnValue(data_init);
-                ////                            }
-                //
-                //
-                //
-                //                        }
-                //                        else
-                //                        {
-                //                            [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Update Order Customer Infomation" controller:self] ;
-                //                        }
-                //
-                //
-                //
-                //                    });
-                //                });
                 
-            }
-            else
-            {
-                [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Loading Contact Information" controller:self] ;
-                //                self.btn_assign.enabled=false;
-            }
-        }];
-            
-            
-            
             
+        }];
         
+
     }];
     
-    return ;
+        return ;
     
 //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
@@ -931,6 +936,8 @@
 }
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
+    
+    
     if (indexPath.row>self.content_data.count-1) {
         return;
     }

+ 47 - 44
RedAnt ERP Mobile/common/Functions/contact/CustomerEditViewController.m

@@ -258,59 +258,62 @@
     NSMutableDictionary* upparams = [self check_cancommit:true];
     if(self.cancommit==false)
         return;
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving Contact"];
     __weak typeof(self) weakself = self;
-    
-    resultHandler handler =^(NSMutableDictionary *result) {
-        NSDictionary* editor_json = result;
-        [waitalert dismissViewControllerAnimated:YES completion:^{
-            if([[editor_json valueForKey:@"result"] intValue]==2)
-            {
-                //                NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
-                //
-                //
-                //                AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                //                appDelegate.customerInfo = customerInfo;
-                //                appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
-                //    //     self.labelContact.text=appDelegate.contact_name;
-                //
-                //    NSDictionary * customerinfo = appDelegate.customerInfo;
-                [weakself prepareReturn:nil];
-                if(weakself.bnewcustomer  )
-                    [weakself.navigationController popViewControllerAnimated:false];
-                else
-                    [weakself.navigationController popToRootViewControllerAnimated:false];
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving Contact" completion:^{
+        resultHandler handler =^(NSMutableDictionary *result) {
+                NSDictionary* editor_json = result;
+                [waitalert dismissViewControllerAnimated:YES completion:^{
+                    if([[editor_json valueForKey:@"result"] intValue]==2)
+                    {
+                        //                NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
+                        //
+                        //
+                        //                AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                        //                appDelegate.customerInfo = customerInfo;
+                        //                appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
+                        //    //     self.labelContact.text=appDelegate.contact_name;
+                        //
+                        //    NSDictionary * customerinfo = appDelegate.customerInfo;
+                        [weakself prepareReturn:nil];
+                        if(weakself.bnewcustomer  )
+                            [weakself.navigationController popViewControllerAnimated:false];
+                        else
+                            [weakself.navigationController popToRootViewControllerAnimated:false];
+                        
+                        
+                        
+                        
+        #ifdef RA_NOTIFICATION
+                        
+                        [ActiveViewController Notify:@"ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+        #else
+                        AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                        [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
+        #endif
+                        
+                    }
+                    else
+                    {
+                        [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Save Order" controller:weakself] ;
+                    }
+                }];
                 
                 
+
                 
                 
-#ifdef RA_NOTIFICATION
                 
-                [ActiveViewController Notify:@"ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-#else
-                AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
-#endif
                 
-            }
+            } ;
+            
+            if(self.bnewcustomer )
+                [RANetwork request_add_customer:upparams completionHandler:handler];
             else
-            {
-                [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Save Order" controller:weakself] ;
-            }
-        }];
-        
-        
-
-        
-        
-        
-        
-    } ;
+                [RANetwork request_update_customer:upparams completionHandler:handler];
+    }];
+    
+    
     
-    if(self.bnewcustomer )
-        [RANetwork request_add_customer:upparams completionHandler:handler];
-    else
-        [RANetwork request_update_customer:upparams completionHandler:handler];
     
     
 //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

+ 60 - 86
RedAnt ERP Mobile/common/Functions/contact/CustomerInfoViewController.m

@@ -182,44 +182,46 @@
         
         
         UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
-            UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order"];
-            
-            [RANetwork request_release_order:appDelegate.order_code withScreen:ScreenCodeCustomerInfo  completionHandler:^(NSMutableDictionary *result) {
-                NSDictionary* order_json = result;
-                [waitalert dismissViewControllerAnimated:YES completion:^{
-                    if([[order_json valueForKey:@"result"] intValue]==2)
-                    {
-                        AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                        //                    appDelegate.order_code = nil;
-                        [appDelegate closeOrder];
-                        
-                        
-                        
-#ifdef RA_NOTIFICATION
-                        [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-                        [ActiveViewController Notify:@"ContactListViewController" Message:RA_NOTIFICATION_REFRESH_UI];
-#else
-                        [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
-                        [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
-                        [((MainViewController*)appDelegate.main_vc) reloadContact:false immediately:false];
-#endif
-                        
-                        [self.navigationController popToRootViewControllerAnimated:false];
-                        
-                        
-                        
-                    }
-                    else
-                    {
-                        [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Release Order" controller:self] ;
-                    }
-                }];
+            __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order" completion:^{
+                [RANetwork request_release_order:appDelegate.order_code withScreen:ScreenCodeCustomerInfo  completionHandler:^(NSMutableDictionary *result) {
+                                NSDictionary* order_json = result;
+                                [waitalert dismissViewControllerAnimated:YES completion:^{
+                                    if([[order_json valueForKey:@"result"] intValue]==2)
+                                    {
+                                        AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                                        //                    appDelegate.order_code = nil;
+                                        [appDelegate closeOrder];
+                                        
+                                        
+                                        
+                #ifdef RA_NOTIFICATION
+                                        [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+                                        [ActiveViewController Notify:@"ContactListViewController" Message:RA_NOTIFICATION_REFRESH_UI];
+                #else
+                                        [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
+                                        [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
+                                        [((MainViewController*)appDelegate.main_vc) reloadContact:false immediately:false];
+                #endif
+                                        
+                                        [self.navigationController popToRootViewControllerAnimated:false];
+                                        
+                                        
+                                        
+                                    }
+                                    else
+                                    {
+                                        [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Release Order" controller:self] ;
+                                    }
+                                }];
+
+                                
+                                
+                                
+                            }];
 
-                
-                
-                
             }];
-//            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+            
+            //            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //                NSDictionary* order_json = [RANetwork release_Order:appDelegate.order_code withScreen:ScreenCodeCustomerInfo];
 //
@@ -445,60 +447,32 @@
 }
 -(void) request_fill
 {
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Loading Contact information"];
-    
-    
-    [RANetwork request_contactinfo:self.contactId completionHandler:^(NSMutableDictionary *result) {
-        NSMutableDictionary* editor_json = result;
-        
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Loading Contact information" completion:^{
+        [RANetwork request_contactinfo:self.contactId completionHandler:^(NSMutableDictionary *result) {
+            NSMutableDictionary* editor_json = result;
             
-        [waitalert dismissViewControllerAnimated:YES completion:^{
-            if([[editor_json valueForKey:@"result"] intValue]==2)
-            {
-                self.data_init = [[editor_json objectForKey:@"customerInfo" ] mutableCopy];
-                
-                [self fillData];
-                self.btn_assign.enabled=true;
                 
-            }
-            else
-            {
-                [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Loading Contact Information" controller:self] ;
-                self.btn_assign.enabled=false;
-            }
+            [waitalert dismissViewControllerAnimated:YES completion:^{
+                if([[editor_json valueForKey:@"result"] intValue]==2)
+                {
+                    self.data_init = [[editor_json objectForKey:@"customerInfo" ] mutableCopy];
+                    
+                    [self fillData];
+                    self.btn_assign.enabled=true;
+                    
+                }
+                else
+                {
+                    [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Loading Contact Information" controller:self] ;
+                    self.btn_assign.enabled=false;
+                }
+            }];
+ 
         }];
-            
-
-            
-            
-        
+        return;
     }];
-    return;
-//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-//        
-//        NSDictionary* editor_json = [RANetwork request_CustomerInfo:self.contactId];
-//        
-//        dispatch_async(dispatch_get_main_queue(), ^{
-//            
-//            [waitalert dismissViewControllerAnimated:YES completion:nil];
-//            
-//            if([[editor_json valueForKey:@"result"] intValue]==2)
-//            {
-//                self.data_init = [[editor_json objectForKey:@"customerInfo" ] mutableCopy];
-//                
-//                [self fillData];
-//                self.btn_assign.enabled=true;
-//                
-//            }
-//            else
-//            {
-//                [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Loading Contact Information" controller:self] ;
-//                self.btn_assign.enabled=false;
-//            }
-//            
-//            
-//        });
-//    });
+    
+
 }
 - (void) fillData
 {

+ 60 - 58
RedAnt ERP Mobile/common/Functions/modelDetail/DetailHeaderCell.m

@@ -1742,69 +1742,71 @@
 -(void) neworder
 {
     
-    UIAlertController * waitalert = [RAUtils waiting_alert:[RAUtils getViewController:self] title:@"Create Order"];
-    [RANetwork request_create_order:^(NSMutableDictionary *result) {
-        NSMutableDictionary* return_json = result;
-        
-        [waitalert dismissViewControllerAnimated:YES completion:^{
-            if([[return_json valueForKey:@"result"] intValue]==2)
-            {
-                int result=[[return_json valueForKey:@"result"] intValue];
-                if(result==2)
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:[RAUtils getViewController:self] title:@"Create Order" completion:^{
+        [RANetwork request_create_order:^(NSMutableDictionary *result) {
+            NSMutableDictionary* return_json = result;
+            
+            [waitalert dismissViewControllerAnimated:YES completion:^{
+                if([[return_json valueForKey:@"result"] intValue]==2)
                 {
-                    //successed.
-                    
-                    NSString* order_code = [return_json valueForKey:@"orderCode"];
-                    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
-                    appDelegate.order_code = order_code;
-                    
-                    int count=[self.quantity_text.text intValue];
-                    [self addtocart:count];
-                    
-                    
-                    //    [self ReloadData];
-                    
-                    
-                    //                    if(self.shopCartBlock!=nil)
-                    //                    {
-                    //                        UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
-                    //
-                    //
-                    //                        CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
-                    //                        UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
-                    //                        iv.image = img;
-                    //                        //                        [self.contentView addSubview:iv];
-                    //                        self.shopCartBlock(iv);
-                    //
-                    //                    }
-                    
+                    int result=[[return_json valueForKey:@"result"] intValue];
+                    if(result==2)
+                    {
+                        //successed.
+                        
+                        NSString* order_code = [return_json valueForKey:@"orderCode"];
+                        AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
+                        appDelegate.order_code = order_code;
+                        
+                        int count=[self.quantity_text.text intValue];
+                        [self addtocart:count];
+                        
+                        
+                        //    [self ReloadData];
+                        
+                        
+                        //                    if(self.shopCartBlock!=nil)
+                        //                    {
+                        //                        UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
+                        //
+                        //
+                        //                        CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
+                        //                        UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
+                        //                        iv.image = img;
+                        //                        //                        [self.contentView addSubview:iv];
+                        //                        self.shopCartBlock(iv);
+                        //
+                        //                    }
+                        
+                    }
                 }
-            }
-            else
-            {
-                UIViewController *vc= [RAUtils getViewController:self];
-                NSString *msg = [return_json valueForKey:@"err_msg"];
-                NSString *title = @"Add To Cart";
-                if ([msg hasPrefix:@"Out of Stock.\n"]) {
-                    title = @"Add To Cart: Out of Stock";
-                    msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
-                    self.btnNotifyMe.enabled = YES;
-                    self.btnaddCart.enabled = NO;
+                else
+                {
+                    UIViewController *vc= [RAUtils getViewController:self];
+                    NSString *msg = [return_json valueForKey:@"err_msg"];
+                    NSString *title = @"Add To Cart";
+                    if ([msg hasPrefix:@"Out of Stock.\n"]) {
+                        title = @"Add To Cart: Out of Stock";
+                        msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
+                        self.btnNotifyMe.enabled = YES;
+                        self.btnaddCart.enabled = NO;
+                    }
+                    
+                    [RAUtils message_alert:msg title:title controller:vc] ;
                 }
-                
-                [RAUtils message_alert:msg title:title controller:vc] ;
-            }
+            }];
+            
+            
+            
+            
+            
+            
+            
+            
         }];
-        
-        
-        
-        
-        
-        
-        
-        
+
     }];
-//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+    //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //        NSDictionary* return_json = [RANetwork new_Order];
 //

+ 153 - 147
RedAnt ERP Mobile/common/Functions/modelDetail/DetailViewController.m

@@ -640,64 +640,66 @@ dispatch_async(dispatch_get_main_queue(), ^{
     
     NSString *catelog_name = [NSString stringWithFormat:@"%@ Hang Tag",vc.groupName];
     
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Processing"];
-    
-    [RANetwork request_hangtag:vc.groupName completionHandler:^(NSMutableDictionary *result) {
-        NSMutableDictionary* editor_json =result;
-        
-        [waitalert dismissViewControllerAnimated:YES completion:^{
-            if([[editor_json valueForKey:@"result"] intValue]==2)
-            {
-                
-                AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                
-                NSString* url = [editor_json valueForKey:@"pdf_path"];
-                bool isLocalFile = [[editor_json valueForKey:@"isLocalFile"] boolValue];
-                RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
-                ViewController.url = url;
-                ViewController.canSave = false;
-                ViewController.isLocalfile=isLocalFile;
-                
-                ViewController.filename = [NSString stringWithFormat:@"%@.pdf",[TextUtils legalFilename:catelog_name]];
-                
-                
-                NSString* company=    [appDelegate.customerInfo valueForKey:@"customer_name"];
-                
-                if(company==nil)
-                    company=@"";
-                
-                NSString* customer_email=    [appDelegate.customerInfo valueForKey:@"customer_email"];
-                
-                
-                NSMutableArray* send_to = [[NSMutableArray alloc]init];
-                if(customer_email.length>0)
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Processing" completion:^{
+        [RANetwork request_hangtag:vc.groupName completionHandler:^(NSMutableDictionary *result) {
+            NSMutableDictionary* editor_json =result;
+            
+            [waitalert dismissViewControllerAnimated:YES completion:^{
+                if([[editor_json valueForKey:@"result"] intValue]==2)
+                {
+                    
+                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                    
+                    NSString* url = [editor_json valueForKey:@"pdf_path"];
+                    bool isLocalFile = [[editor_json valueForKey:@"isLocalFile"] boolValue];
+                    RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
+                    ViewController.url = url;
+                    ViewController.canSave = false;
+                    ViewController.isLocalfile=isLocalFile;
+                    
+                    ViewController.filename = [NSString stringWithFormat:@"%@.pdf",[TextUtils legalFilename:catelog_name]];
+                    
+                    
+                    NSString* company=    [appDelegate.customerInfo valueForKey:@"customer_name"];
+                    
+                    if(company==nil)
+                        company=@"";
+                    
+                    NSString* customer_email=    [appDelegate.customerInfo valueForKey:@"customer_email"];
+                    
+                    
+                    NSMutableArray* send_to = [[NSMutableArray alloc]init];
+                    if(customer_email.length>0)
+                    {
+                        send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
+                    }
+                    ViewController.mail_to = send_to;
+                    
+                    NSString* subject;
+                    
+                    subject =catelog_name;
+                    
+                    ViewController.mail_subject = subject;
+                    
+                    ViewController.hidenavi = false;
+                    [vc.navigationController pushViewController:ViewController animated:YES];
+                    
+                }
+                else
                 {
-                    send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
+                    [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Hang Tag" controller:vc];
                 }
-                ViewController.mail_to = send_to;
-                
-                NSString* subject;
+            }];
                 
-                subject =catelog_name;
                 
-                ViewController.mail_subject = subject;
                 
-                ViewController.hidenavi = false;
-                [vc.navigationController pushViewController:ViewController animated:YES];
                 
-            }
-            else
-            {
-                [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Hang Tag" controller:vc];
-            }
-        }];
-            
             
-            
-            
-        
+        }];
+
     }];
-    return;
+    
+        return;
 //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //        NSDictionary* editor_json = [RANetwork request_hangTag:vc.groupName];
@@ -1392,48 +1394,50 @@ dispatch_async(dispatch_get_main_queue(), ^{
             __weak typeof(self) weakself = self;
             cell.notifyMeBlock = ^{
                 
-                UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email"];
-                
-                [RANetwork request_notifymodel:self.product_id emailAddr:nil withScreen:ScreenCodeModelInfo completionHandler:^(NSMutableDictionary *result) {
-                    NSMutableDictionary *dic =result;
-                    
-                    
-                    [waitting_alert dismissViewControllerAnimated:YES completion:^{
-                        int result_code = [[dic valueForKey:@"result"] intValue];
-                        
-                        if (result_code != RESULT_TRUE && result_code != RESULT_NO_EMAIL_ADDRESS) {
-                            
-                            NSString *msg = [NSString stringWithFormat:@"The email send failed"];
-                            
-                            if ([dic valueForKey:@"err_msg"]) {
-                                msg = [dic valueForKey:@"err_msg"];
-                            }
-                            
-                            
-                            UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
-                            UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-                                
-                            }];
-                            
-                            [errorAlertVC addAction:action];
-                            [weakself presentViewController:errorAlertVC animated:YES completion:nil];
-                            
-                        } else if (result_code == RESULT_TRUE){
-                            
-                            [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
-                            
-                        } else if (result_code == RESULT_NO_EMAIL_ADDRESS) {
-                            
-                            [self showEmailAddrBox];
-                            
-                        }
-                    }];
-//                    [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
-                    
-                   
-                    
+                __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
+                    [RANetwork request_notifymodel:self.product_id emailAddr:nil withScreen:ScreenCodeModelInfo completionHandler:^(NSMutableDictionary *result) {
+                                        NSMutableDictionary *dic =result;
+                                        
+                                        
+                                        [waitting_alert dismissViewControllerAnimated:YES completion:^{
+                                            int result_code = [[dic valueForKey:@"result"] intValue];
+                                            
+                                            if (result_code != RESULT_TRUE && result_code != RESULT_NO_EMAIL_ADDRESS) {
+                                                
+                                                NSString *msg = [NSString stringWithFormat:@"The email send failed"];
+                                                
+                                                if ([dic valueForKey:@"err_msg"]) {
+                                                    msg = [dic valueForKey:@"err_msg"];
+                                                }
+                                                
+                                                
+                                                UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
+                                                UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+                                                    
+                                                }];
+                                                
+                                                [errorAlertVC addAction:action];
+                                                [weakself presentViewController:errorAlertVC animated:YES completion:nil];
+                                                
+                                            } else if (result_code == RESULT_TRUE){
+                                                
+                                                [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
+                                                
+                                            } else if (result_code == RESULT_NO_EMAIL_ADDRESS) {
+                                                
+                                                [self showEmailAddrBox];
+                                                
+                                            }
+                                        }];
+                    //                    [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
+                                        
+                                       
+                                        
+                                    }];
+
                 }];
                 
+                                
                 //                dispatch_async(dispatch_get_global_queue(0,0), ^{
                 //
                 //                    NSDictionary *dic = [RANetwork notifyModel:self.product_id emailAddr:nil withScreen:ScreenCodeModelInfo];
@@ -1968,13 +1972,13 @@ dispatch_async(dispatch_get_main_queue(), ^{
                     else
                     {
                         NSData*  downloadimg_data = nil;
-                        BOOL offline = NO;
-#ifdef OFFLINE_MODE
-                        offline = appDelegate.offline_mode;
-#endif
-                        if (!offline) {
+//                        BOOL offline = NO;
+//#ifdef OFFLINE_MODE
+//                        offline = appDelegate.offline_mode;
+//#endif
+//                        if (!offline) {
                             downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
-                        }
+//                        }
                         dispatch_async(dispatch_get_main_queue(), ^{
                             
                             
@@ -2087,13 +2091,13 @@ dispatch_async(dispatch_get_main_queue(), ^{
                     {
                         NSData*  downloadimg_data = nil;
                         
-                        BOOL offline = NO;
-#ifdef OFFLINE_MODE
-                        offline = appDelegate.offline_mode;
-#endif
-                        if (!offline) {
+//                        BOOL offline = NO;
+//#ifdef OFFLINE_MODE
+//                        offline = appDelegate.offline_mode;
+//#endif
+//                        if (!offline) {
                             downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
-                        }
+//                        }
                         dispatch_async(dispatch_get_main_queue(), ^{
                             
                             
@@ -2381,13 +2385,13 @@ dispatch_async(dispatch_get_main_queue(), ^{
                     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                         
                         NSData*  downloadimg_data = nil;
-                        BOOL offline = NO;
-#ifdef OFFLINE_MODE
-                        offline = appDelegate.offline_mode;
-#endif
-                        if (!offline) {
+//                        BOOL offline = NO;
+//#ifdef OFFLINE_MODE
+//                        offline = appDelegate.offline_mode;
+//#endif
+//                        if (!offline) {
                             downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
-                        }
+//                        }
                         dispatch_async(dispatch_get_main_queue(), ^{
                             
                             
@@ -2714,46 +2718,48 @@ dispatch_async(dispatch_get_main_queue(), ^{
             // 验证是邮件地址,发送邮件
             [weakVC dismissViewControllerAnimated:YES completion:^{
                 
-                UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email"];
-                [RANetwork request_notifymodel:weakself.product_id emailAddr:text withScreen:ScreenCodeModelInfo completionHandler:^(NSMutableDictionary *result) {
-                    DebugLog(@"email cart result: %@",result);
-                    
-                    
-                    [waitting_alert dismissViewControllerAnimated:YES completion:^{
-                        int resultStatus = [[result objectForKey:@"result"] intValue];
-                        if (resultStatus != RESULT_TRUE && resultStatus != RESULT_NO_EMAIL_ADDRESS) {
-                            
-                            NSString *msg = [NSString stringWithFormat:@"The email send failed"];
-                            if ([result valueForKey:@"err_msg"]) {
-                                msg = [result valueForKey:@"err_msg"];
-                            }
-                            
-                            
-                            UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
-                            UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-                                
-                            }];
-                            
-                            [errorAlertVC addAction:action];
-                            [weakself presentViewController:errorAlertVC animated:YES completion:nil];
-                            
-                        }else if(resultStatus == RESULT_TRUE){
-                            
-                            [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
-                            
-                        } else if (resultStatus == RESULT_NO_EMAIL_ADDRESS) {
-                            
-                            [weakself showEmailAddrBox];
-                            
-                        }
-                    }];
-//                    [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
-                    
-                    
-                    
-                    
+                __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
+                    [RANetwork request_notifymodel:weakself.product_id emailAddr:text withScreen:ScreenCodeModelInfo completionHandler:^(NSMutableDictionary *result) {
+                                        DebugLog(@"email cart result: %@",result);
+                                        
+                                        
+                                        [waitting_alert dismissViewControllerAnimated:YES completion:^{
+                                            int resultStatus = [[result objectForKey:@"result"] intValue];
+                                            if (resultStatus != RESULT_TRUE && resultStatus != RESULT_NO_EMAIL_ADDRESS) {
+                                                
+                                                NSString *msg = [NSString stringWithFormat:@"The email send failed"];
+                                                if ([result valueForKey:@"err_msg"]) {
+                                                    msg = [result valueForKey:@"err_msg"];
+                                                }
+                                                
+                                                
+                                                UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
+                                                UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+                                                    
+                                                }];
+                                                
+                                                [errorAlertVC addAction:action];
+                                                [weakself presentViewController:errorAlertVC animated:YES completion:nil];
+                                                
+                                            }else if(resultStatus == RESULT_TRUE){
+                                                
+                                                [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
+                                                
+                                            } else if (resultStatus == RESULT_NO_EMAIL_ADDRESS) {
+                                                
+                                                [weakself showEmailAddrBox];
+                                                
+                                            }
+                                        }];
+                    //                    [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
+                                        
+                                        
+                                        
+                                        
+                                    }];
+
                 }];
-                
+                                
 //                dispatch_async(dispatch_get_global_queue(0, 0), ^{
 //
 //                    NSDictionary *result = [RANetwork notifyModel:weakself.product_id emailAddr:text withScreen:ScreenCodeModelInfo];

+ 30 - 8
RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.h

@@ -21,7 +21,7 @@
 +(NSData*) offline_searchaddall :(NSMutableDictionary *) params;
 +(NSData*) offline_itemsearchaddall :(NSMutableDictionary *) params;
 
-+(NSDictionary*) offline_model :(NSMutableDictionary *) params;
+//+(NSDictionary*) offline_model :(NSMutableDictionary *) params;
 
 
 /**
@@ -38,23 +38,23 @@
 +(NSData *) offline_editContact:(NSMutableDictionary *) params;
 +(NSData *) offline_saveNewContact:(NSMutableDictionary *) params;
 +(NSData *) offline_saveContact:(NSMutableDictionary *) params;
-+(NSDictionary*) offline_contactlist :(NSMutableDictionary *) params;
+//+(NSDictionary*) offline_contactlist :(NSMutableDictionary *) params;
 +(NSDictionary*) offline_contactinfo :(NSMutableDictionary *) params;
 +(NSData *) offline_saveBusinesscard:(NSData *) image;
 +(NSData*) offline_saveaddr :(NSMutableDictionary *) params;
 
 
-+(NSDictionary*) offline_commoneditor_partialrefresh :(NSMutableDictionary *) params;
-+(NSDictionary*) offline_wishlist :(NSMutableDictionary *) params;
+//+(NSDictionary*) offline_commoneditor_partialrefresh :(NSMutableDictionary *) params;
+//+(NSDictionary*) offline_wishlist :(NSMutableDictionary *) params;
 +(NSDictionary*) offline_add2wishlist :(NSMutableDictionary *) params;
 +(NSDictionary*) offline_deletewishlist :(NSMutableDictionary *) params;
 
 
 +(NSData*) offline_login :(NSMutableDictionary *) params;
-+(NSDictionary*) offline_logout :(NSMutableDictionary *) params;
+//+(NSDictionary*) offline_logout :(NSMutableDictionary *) params;
 
 
-+(NSData*) offline_createorder :(NSMutableDictionary *) params;
+//+(NSData*) offline_createorder :(NSMutableDictionary *) params;
 +(NSData*) offline_orderlist :(NSMutableDictionary *) params;
 +(NSData*) offline_orderdetail :(NSMutableDictionary *) params;
 +(NSData*) offline_editorder :(NSMutableDictionary *) params;
@@ -68,7 +68,7 @@
 + (NSData*)offline_movewish2cart:(NSMutableDictionary *)params;
 +(NSData*) offline_add2cart :(NSMutableDictionary *) params;
 +(NSData*) offline_add2cartbyname :(NSMutableDictionary *) params;
-+(NSData*) offline_requestcart :(NSMutableDictionary *) params;
+//+(NSData*) offline_requestcart :(NSMutableDictionary *) params;
 +(NSData*) offline_updategnotes :(NSMutableDictionary *) params;
 +(NSData*) offline_movecart2wish :(NSMutableDictionary *) params;
 +(NSData*) offline_cartremove :(NSMutableDictionary *) params;
@@ -91,7 +91,7 @@
 
 // sync
 +(NSArray*) enumOfflineOrder;
-+(NSDictionary*) prepareUpload:(NSArray*) arr_order;
++(NSDictionary *) prepareUpload:(NSArray*) arr_order params:(NSMutableDictionary*)add_params;
 //+(void) uploadFile:(NSString*) file;
 //  category filter, contact advanced search, item search, search,wishlist,
 
@@ -126,4 +126,26 @@
 
 + (void) offline_removePDFWithName:(NSString *)name;
 
+
+#pragma mark new interface 2020
+typedef void(^resultHandler)(NSMutableDictionary *result);
+
++(void) offline_contactlist :(NSMutableDictionary *) params completionHandler:(resultHandler)result;
+//+(void) offline_contactinfo :(NSMutableDictionary *) params completionHandler:(resultHandler)result;
+//+(void) offline_category :(NSMutableDictionary *) params completionHandler:(resultHandler)result;
+//+(void) offline_search:(NSMutableDictionary *) params completionHandler:(resultHandler)result;
+//+(void) offline_itemsearch :(NSMutableDictionary *) params completionHandler:(resultHandler)result;
++(void) offline_commoneditor_partialrefresh :(NSMutableDictionary *) params completionHandler:(resultHandler)result;
++(void) offline_wishlist :(NSMutableDictionary *) params completionHandler:(resultHandler)result;
+//+(void) offline_add2wishlist :(NSMutableDictionary *) params completionHandler:(resultHandler)result;
++(void) offline_model :(NSMutableDictionary *) params completionHandler:(resultHandler)result;
+//+(void) offline_deletewishlist :(NSMutableDictionary *) params completionHandler:(resultHandler)result;
++(void) offline_logout :(NSMutableDictionary *) params completionHandler:(resultHandler)result;
++(void) offline_createorder :(NSMutableDictionary *) params completionHandler:(resultHandler)result;
++(void) offline_requestcart :(NSMutableDictionary *) params completionHandler:(resultHandler)result;
+
+//+(void) offline_add2cart :(NSMutableDictionary *) params completionHandler:(resultHandler)result;
+//+(void) offline_add2cartbyname :(NSMutableDictionary *) params completionHandler:(resultHandler)result;
+//+(void) offline_movewish2cart:(NSMutableDictionary *)params completionHandler:(resultHandler)result;
+//+(void) addAll:(NSMutableDictionary *) params from:(int)from completionHandler:(resultHandler)result;
 @end

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 549 - 528
RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.m


+ 119 - 109
RedAnt ERP Mobile/common/Functions/offline/OfflineSettingViewController.m

@@ -442,64 +442,68 @@
         
         if(appDelegate.bLogin)
         {
-            UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Sign out"];
-            
-            [RANetwork request_logout:^(NSMutableDictionary *result) {
-                NSMutableDictionary* return_json=result ;
-                
-                [waitalert dismissViewControllerAnimated:YES completion:^{
-                    if([[return_json valueForKey:@"result"] intValue]==2)
-                    {
-                        
-                        [appDelegate Logout];
-                        NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
-                        [defaults removeObjectForKey:@"EnableOfflineMode"];
-                        [defaults setBool:self.switch_offline.isOn forKey:@"EnableOfflineMode"];
-                        
-                        [defaults synchronize];
-#ifdef OFFLINE_MODE
-                        appDelegate.offline_mode =self.switch_offline.isOn;
-#endif
-                        
-#ifdef RA_NOTIFICATION
-                        
-                        [ActiveViewController Notify:@"PortfolioViewController,WatchListViewController,CategoryViewController,PDFListViewController,CartViewController,OrderListViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-#else
-                        [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
-                        [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
-                        
-                        [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
-                        [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
-                        [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
-                        
-                        //                        [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
-                        
-                        [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
-                        [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
-                        //                        [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
-                        
-                        
-#endif
-                        
-                        
-                        
-                        [((MainViewController*)appDelegate.main_vc) switchToHome];
-                    }
-                    else
-                    {
-                        // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
-                    }
-                }];
-                
-                
-                
-                
-                
-                
-                
-                
+            __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Sign out" completion:^{
+                [RANetwork request_logout:^(NSMutableDictionary *result) {
+                                NSMutableDictionary* return_json=result ;
+                                
+                                [waitalert dismissViewControllerAnimated:YES completion:^{
+                                    if([[return_json valueForKey:@"result"] intValue]==2)
+                                    {
+                                        
+                                        [appDelegate Logout];
+                                        NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+                                        [defaults removeObjectForKey:@"EnableOfflineMode"];
+                                        [defaults setBool:self.switch_offline.isOn forKey:@"EnableOfflineMode"];
+                                        
+                                        [defaults synchronize];
+                #ifdef OFFLINE_MODE
+                                        appDelegate.offline_mode =self.switch_offline.isOn;
+                #endif
+                                        
+                #ifdef RA_NOTIFICATION
+                                        
+                                        [ActiveViewController Notify:@"PortfolioViewController,WatchListViewController,CategoryViewController,PDFListViewController,CartViewController,OrderListViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+                #else
+                                        [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
+                                        [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
+                                        
+                                        [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
+                                        [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
+                                        [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
+                                        
+                                        //                        [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
+                                        
+                                        [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
+                                        [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
+                                        //                        [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
+                                        
+                                        
+                #endif
+                                        
+                                        
+                                        
+                                         [self dismissViewControllerAnimated:true completion:^{
+                                                                                           [((MainViewController*)appDelegate.main_vc) switchToHome];
+                                                                                       }];
+                                    }
+                                    else
+                                    {
+                                        // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
+                                    }
+                                }];
+                                
+                                
+                                
+                                
+                                
+                                
+                                
+                                
+                            }];
+
             }];
             
+                        
             
 //            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
@@ -585,7 +589,9 @@
 
             
             
-            [((MainViewController*)appDelegate.main_vc) switchToHome];
+             [self dismissViewControllerAnimated:true completion:^{
+                                                               [((MainViewController*)appDelegate.main_vc) switchToHome];
+                                                           }];
         }
     }
     else
@@ -596,59 +602,63 @@
             // have offline data
             if(appDelegate.bLogin)
             {
-                UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Sign out"];
-                [RANetwork request_logout:^(NSMutableDictionary *result) {
-                    NSMutableDictionary* return_json = result;
-                    
-                    [waitalert dismissViewControllerAnimated:YES completion:^{
-                        if([[return_json valueForKey:@"result"] intValue]==2)
-                        {
-                            
-                            [appDelegate Logout];
-                            
-                            NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
-                            [defaults removeObjectForKey:@"EnableOfflineMode"];
-                            [defaults setBool:self.switch_offline.isOn forKey:@"EnableOfflineMode"];
-                            
-                            [defaults synchronize];
-#ifdef OFFLINE_MODE
-                            appDelegate.offline_mode =self.switch_offline.isOn;
-#endif
-                            
-#ifdef RA_NOTIFICATION
-                            [ActiveViewController Notify:@"PortfolioViewController,WatchListViewController,CategoryViewController,PDFListViewController,CartViewController,OrderListViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-#else
-                            [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
-                            [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
-                            [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
-                            [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
-                            [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
-                            //                            [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
-                            [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
-                            [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
-                            //                            [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
-#endif
-                            
-                            
-                            
-                            
-                            [((MainViewController*)appDelegate.main_vc) switchToHome];
-                        }
-                        else
-                        {
-                            // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
-                        }
-                    }];
-                    
-                    
-                    
-                    
-                    
-                    
-                    
-                    
+                __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Sign out" completion:^{
+                    [RANetwork request_logout:^(NSMutableDictionary *result) {
+                                        NSMutableDictionary* return_json = result;
+                                        
+                                        [waitalert dismissViewControllerAnimated:YES completion:^{
+                                            if([[return_json valueForKey:@"result"] intValue]==2)
+                                            {
+                                                
+                                                [appDelegate Logout];
+                                                
+                                                NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+                                                [defaults removeObjectForKey:@"EnableOfflineMode"];
+                                                [defaults setBool:self.switch_offline.isOn forKey:@"EnableOfflineMode"];
+                                                
+                                                [defaults synchronize];
+                    #ifdef OFFLINE_MODE
+                                                appDelegate.offline_mode =self.switch_offline.isOn;
+                    #endif
+                                                
+                    #ifdef RA_NOTIFICATION
+                                                [ActiveViewController Notify:@"PortfolioViewController,WatchListViewController,CategoryViewController,PDFListViewController,CartViewController,OrderListViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+                    #else
+                                                [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
+                                                [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
+                                                [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
+                                                [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
+                                                [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
+                                                //                            [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
+                                                [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
+                                                [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
+                                                //                            [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
+                    #endif
+                                                
+                                                
+                                                [self dismissViewControllerAnimated:true completion:^{
+                                                    [((MainViewController*)appDelegate.main_vc) switchToHome];
+                                                }];
+                                                
+                                                
+                                            }
+                                            else
+                                            {
+                                                // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
+                                            }
+                                        }];
+                                        
+                                        
+                                        
+                                        
+                                        
+                                        
+                                        
+                                        
+                                    }];
+
                 }];
-                
+                                
 //                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //                    NSDictionary* return_json = [RANetwork logout];

+ 40 - 36
RedAnt ERP Mobile/common/Functions/offline/SelectUploadOrderViewController.m

@@ -163,31 +163,33 @@
                 
                 [alertVC dismissViewControllerAnimated:YES completion:^{
                     // 关闭订单
-                    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order"];
-                    
-                    [RANetwork request_release_order:order_code withScreen:ScreenCodeOfflineSetting completionHandler:^(NSMutableDictionary *result) {
-                        NSDictionary* order_json =result;
-                        
-                        [waitalert dismissViewControllerAnimated:YES completion:^{
-                            //                    [waitalert dismissViewControllerAnimated:YES completion:nil];
-                            if([[order_json valueForKey:@"result"] intValue]==2)
-                            {
-                                AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                                
-                                [appDelegate closeOrder];
-                                closeOrder = YES;
-                                
-                                [weakself uploadButtonClicked:weakself.uploadButton];
-                                
-                            } else {
-                                // 释放失败
-                                closeOrder = NO;
-                                [RAUtils message_alert:@"Release Order Failed!" title:@"Warning" controller:weakself];
-                            }
+                    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order" completion:^{
+                        [RANetwork request_release_order:order_code withScreen:ScreenCodeOfflineSetting completionHandler:^(NSMutableDictionary *result) {
+                            NSDictionary* order_json =result;
+                            
+                            [waitalert dismissViewControllerAnimated:YES completion:^{
+                                //                    [waitalert dismissViewControllerAnimated:YES completion:nil];
+                                if([[order_json valueForKey:@"result"] intValue]==2)
+                                {
+                                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                                    
+                                    [appDelegate closeOrder];
+                                    closeOrder = YES;
+                                    
+                                    [weakself uploadButtonClicked:weakself.uploadButton];
+                                    
+                                } else {
+                                    // 释放失败
+                                    closeOrder = NO;
+                                    [RAUtils message_alert:@"Release Order Failed!" title:@"Warning" controller:weakself];
+                                }
+                            }];
+                            
                         }];
-                        
+
                     }];
-                }];
+                    
+                                    }];
                
                 
 //                NSDictionary* order_json = [RANetwork release_Order:order_code withScreen:ScreenCodeOfflineSetting];
@@ -230,25 +232,27 @@
         [params setObject:checked_id forKey:@"targetOrderId"];
         [params setObject:[Singleton sharedInstance].customerInfo forKey:@"customerInfo"];
         
-        UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Merge Order"];
-        
-        
-        [RANetwork request_mergeorder:params completionHandler:^(NSMutableDictionary *result) {
-            NSDictionary *ret = result;
-            //            [waitalert dismissWithClickedButtonIndex:0 animated:YES];
-            [waitalert dismissViewControllerAnimated:YES completion:^{
-                [self.navigationController dismissViewControllerAnimated:YES completion:^{
-                    
-                    if (weakself.mergeBlock) {
-                        weakself.mergeBlock(ret);
-                    }
+        __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Merge Order" completion:^{
+            [RANetwork request_mergeorder:params completionHandler:^(NSMutableDictionary *result) {
+                NSDictionary *ret = result;
+                //            [waitalert dismissWithClickedButtonIndex:0 animated:YES];
+                [waitalert dismissViewControllerAnimated:YES completion:^{
+                    [self.navigationController dismissViewControllerAnimated:YES completion:^{
+                        
+                        if (weakself.mergeBlock) {
+                            weakself.mergeBlock(ret);
+                        }
+                        
+                    }];
                     
                 }];
                 
             }];
-            
+
         }];
         
+        
+                
 //        NSDictionary *ret = [RANetwork merge_order:params];
 //
 //        [waitalert dismissWithClickedButtonIndex:0 animated:YES];

+ 290 - 258
RedAnt ERP Mobile/common/Functions/order/CreateOrderViewController.m

@@ -1745,54 +1745,56 @@
             a2Title=@"Close and release order";
         UIAlertAction *action_2 = [UIAlertAction actionWithTitle:a2Title style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
             AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-            UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order"];
-            
-            [RANetwork request_release_order:appDelegate.order_code withScreen:nil completionHandler:^(NSMutableDictionary *result) {
-                NSDictionary* order_json = result;
-                
-                [waitalert dismissViewControllerAnimated:YES completion:^{
-                    if([[order_json valueForKey:@"result"] intValue]==2)
-                    {
-                        AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                        //                        appDelegate.order_code = nil;
-                        
-                        [appDelegate closeOrder];
-                        
-                        
-#ifdef RA_NOTIFICATION
-                        [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-#else
-                        [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
-                        [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
-#endif
-                        
-                        [((MainViewController*)appDelegate.main_vc) switchToHome];
-                        
-                        if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
-                        {
-                            [((MainViewController*)appDelegate.main_vc) Loginout:false];
-                        }
-                        
-                        [self prepareReturn:nil];
-                        
-                        
-                        [self.navigationController popViewControllerAnimated:true];
-                        //                        [self.navigationController dismissViewControllerAnimated:true completion:^{
-                        //                            ;
-                        //                        }];
-                        
-                    }
-                    else
-                    {
-                        [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
-                    }
-                }];
-                
-                
-                
-                
+            __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order" completion:^{
+                [RANetwork request_release_order:appDelegate.order_code withScreen:nil completionHandler:^(NSMutableDictionary *result) {
+                                NSDictionary* order_json = result;
+                                
+                                [waitalert dismissViewControllerAnimated:YES completion:^{
+                                    if([[order_json valueForKey:@"result"] intValue]==2)
+                                    {
+                                        AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                                        //                        appDelegate.order_code = nil;
+                                        
+                                        [appDelegate closeOrder];
+                                        
+                                        
+                #ifdef RA_NOTIFICATION
+                                        [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+                #else
+                                        [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
+                                        [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
+                #endif
+                                        
+                                        [((MainViewController*)appDelegate.main_vc) switchToHome];
+                                        
+                                        if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
+                                        {
+                                            [((MainViewController*)appDelegate.main_vc) Loginout:false];
+                                        }
+                                        
+                                        [self prepareReturn:nil];
+                                        
+                                        
+                                        [self.navigationController popViewControllerAnimated:true];
+                                        //                        [self.navigationController dismissViewControllerAnimated:true completion:^{
+                                        //                            ;
+                                        //                        }];
+                                        
+                                    }
+                                    else
+                                    {
+                                        [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
+                                    }
+                                }];
+                                
+                                
+                                
+                                
+                            }];
+
             }];
-//            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+            
+            //            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //                NSDictionary* order_json = [RANetwork release_Order:appDelegate.order_code withScreen:nil];
 //
@@ -1932,90 +1934,92 @@
         upparams[@"shipping"] = nil;
     
     
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving Order"];
-    [RANetwork request_save_order:upparams completionHandler:^(NSMutableDictionary *result) {
-        NSDictionary* editor_json =result;
-        
-        [waitalert dismissViewControllerAnimated:YES completion:^{
-            if([[editor_json valueForKey:@"result"] intValue]==2)
-            {
-                
-                AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving Order" completion:^{
+        [RANetwork request_save_order:upparams completionHandler:^(NSMutableDictionary *result) {
+                NSDictionary* editor_json =result;
                 
+                [waitalert dismissViewControllerAnimated:YES completion:^{
+                    if([[editor_json valueForKey:@"result"] intValue]==2)
+                    {
+                        
+                        AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                        
+                        
+                        
+                        NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
+                        
+                        
+                        if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
+                        {
+                            appDelegate.customerInfo = customerInfo;
+                            appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
+                        }
+                        NSString *msg = nil;
+                        if ([editor_json objectForKey:@"so#"]) {
+                            msg = [@"SO#:" stringByAppendingString:[editor_json objectForKey:@"so#"]];
+                        }
+                        [RAUtils message_alert:msg title:@"Order Saved" controller:self] ;
+                        
+                        if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.save_order_logout && appDelegate.user_type ==USER_ROLE_EMPLOYEE)
+                        {
+                            [((MainViewController*)appDelegate.main_vc) Loginout:false];
+                            [self prepareReturn:nil];
+                            [self.navigationController popViewControllerAnimated:true];
+                        }
+                        else{
+                            
+                            
+        #ifdef RA_NOTIFICATION
+                            [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+        #else
+                            
+                            AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                            [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
+        #endif
+                        }
+                        
+                        if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
+                            
+                            if (![Singleton sharedInstance].currentOrderIsMerged) {
+                                [self releaseOrderAfterSave];
+                            }
+                            
+                            
+                        }
+                        
+                        
+                        //                if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
+                        //                    appDelegate.order_code = nil;
+                        //
+                        //                }
+                        //    //     self.labelContact.text=appDelegate.contact_name;
+                        //
+                        //    NSDictionary * customerinfo = appDelegate.customerInfo;
+                        // [self prepareReturn:nil];
+                        //                [self.navigationController dismissViewControllerAnimated:true completion:^{
+                        //
+                        //
+                        //                    ;
+                        //                }];
+                        
+                    }
+                    else
+                    {
+                        [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Save Order" controller:self] ;
+                    }
+                }];
                 
-                NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
                 
                 
-                if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
-                {
-                    appDelegate.customerInfo = customerInfo;
-                    appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
-                }
-                NSString *msg = nil;
-                if ([editor_json objectForKey:@"so#"]) {
-                    msg = [@"SO#:" stringByAppendingString:[editor_json objectForKey:@"so#"]];
-                }
-                [RAUtils message_alert:msg title:@"Order Saved" controller:self] ;
                 
-                if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.save_order_logout && appDelegate.user_type ==USER_ROLE_EMPLOYEE)
-                {
-                    [((MainViewController*)appDelegate.main_vc) Loginout:false];
-                    [self prepareReturn:nil];
-                    [self.navigationController popViewControllerAnimated:true];
-                }
-                else{
-                    
-                    
-#ifdef RA_NOTIFICATION
-                    [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-#else
-                    
-                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                    [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
-#endif
-                }
                 
-                if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
-                    
-                    if (![Singleton sharedInstance].currentOrderIsMerged) {
-                        [self releaseOrderAfterSave];
-                    }
-                    
-                    
-                }
                 
                 
-                //                if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
-                //                    appDelegate.order_code = nil;
-                //
-                //                }
-                //    //     self.labelContact.text=appDelegate.contact_name;
-                //
-                //    NSDictionary * customerinfo = appDelegate.customerInfo;
-                // [self prepareReturn:nil];
-                //                [self.navigationController dismissViewControllerAnimated:true completion:^{
-                //
-                //
-                //                    ;
-                //                }];
                 
-            }
-            else
-            {
-                [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Save Order" controller:self] ;
-            }
-        }];
-        
-        
-        
-        
-        
-        
-        
-        
+            }];
+
     }];
-//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+    //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //        NSDictionary* editor_json = [RANetwork save_Order:upparams];
 //
@@ -3161,6 +3165,10 @@
 #ifdef OFFLINE_MODE
     [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
 #endif
+    
+    MainViewController *mainVC = (MainViewController *)appDelegate.main_vc;
+    __block NSString *so = [mainVC.labelSo.text substringFromIndex:5];
+    
     [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:1 queue:nil repeats:YES action:^{
         
         NSMutableDictionary *urgencyDic = [NSMutableDictionary dictionary];
@@ -3178,17 +3186,18 @@
             
             
             [urgencyDic setValue:appDelegate.order_code forKey:@"order_code"];
-            MainViewController *mainVC = (MainViewController *)appDelegate.main_vc;
-            NSString *so = [mainVC.labelSo.text substringFromIndex:5];
+
             [urgencyDic setValue:so forKey:@"order_so"];
             [urgencyDic setValue:[NSNumber numberWithInt:appDelegate.order_status ] forKey:@"order_status"];
             
             [urgencyDic setValue:appDelegate.order_customer_id forKey:@"order_customer_id"];
             
         }
-        
-        [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
-        [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
+            [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
+
+        });
         
     }];
 }
@@ -3202,62 +3211,64 @@
 
 - (void)customer_commit_order:(NSMutableDictionary *)upparams {
     
-    
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission"];
-    
     [upparams setValue:@"true" forKey:@"isHold"];
-    [RANetwork request_commit_order:upparams completionHandler:^(NSMutableDictionary *result) {
-        NSDictionary* editor_json =result;
-        [waitalert dismissViewControllerAnimated:YES completion:^{
-            if([[editor_json valueForKey:@"result"] intValue]==2)
-            {
-                
-                AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                // appDelegate.customerInfo = customerInfo;
-                
-                [appDelegate closeOrder];
-                
-                
-#ifdef RA_NOTIFICATION
-                [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-#else
-                [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
-#endif
-                
-                NSString* title=nil;
-                NSString* msg=nil;
-#ifdef OFFLINE_MODE
-                if(appDelegate.offline_mode)
-                {
-                    title=TITLE_OFFLINE_SUBMIT;
-                    msg=MSG_OFFLINE_SUBMIT;
-                }
-                else
-#endif
-                {
-                    title=@"Order submitted sucessfully";
-                    msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
-                }
-                
-                [RAUtils message_alert:msg title:title controller:self];
-                //                UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
-                
-                //                [alert show];
-                
-                [self prepareReturn:nil];
-                [self.navigationController popToRootViewControllerAnimated:true];
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission" completion:^{
+        [RANetwork request_commit_order:upparams completionHandler:^(NSMutableDictionary *result) {
+                NSDictionary* editor_json =result;
+                [waitalert dismissViewControllerAnimated:YES completion:^{
+                    if([[editor_json valueForKey:@"result"] intValue]==2)
+                    {
+                        
+                        AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                        // appDelegate.customerInfo = customerInfo;
+                        
+                        [appDelegate closeOrder];
+                        
+                        
+        #ifdef RA_NOTIFICATION
+                        [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+        #else
+                        [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
+        #endif
+                        
+                        NSString* title=nil;
+                        NSString* msg=nil;
+        #ifdef OFFLINE_MODE
+                        if(appDelegate.offline_mode)
+                        {
+                            title=TITLE_OFFLINE_SUBMIT;
+                            msg=MSG_OFFLINE_SUBMIT;
+                        }
+                        else
+        #endif
+                        {
+                            title=@"Order submitted sucessfully";
+                            msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
+                        }
+                        
+                        [RAUtils message_alert:msg title:title controller:self];
+                        //                UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
+                        
+                        //                [alert show];
+                        
+                        [self prepareReturn:nil];
+                        [self.navigationController popToRootViewControllerAnimated:true];
+                        
+                        
+                    }
+                    else
+                    {
+                        [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
+                    }
+                }];
                 
                 
-            }
-            else
-            {
-                [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
-            }
-        }];
-        
-        
+            }];
+
     }];
-//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+    
+    
+    //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //        NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
 //
@@ -3314,91 +3325,112 @@
 }
 
 - (void)empolyee_commit_order:(NSMutableDictionary *)upparams {
-    
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission"];
     [upparams setValue:@"false" forKey:@"isHold"];
-    [RANetwork request_commit_order:upparams completionHandler:^(NSMutableDictionary *result) {
-        NSDictionary* editor_json = result;
-        [waitalert dismissViewControllerAnimated:YES completion:^{
-            if([[editor_json valueForKey:@"result"] intValue]==2)
-            {
-                
-                // debug aaa
-                AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                NSString* company= appDelegate.customerInfo[@"customer_name"];
-                NSString* send_to =appDelegate.customerInfo[@"customer_email"];
-                
-                [appDelegate closeOrder];
-                
-                
-#ifdef RA_NOTIFICATION
-                [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-#else
-                
-                [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
-#endif
-                
-                NSString* title=nil;
-                NSString* msg=nil;
-#ifdef OFFLINE_MODE
-                if(appDelegate.offline_mode)
-                {
-                    title=TITLE_OFFLINE_SUBMIT;
-                    msg=MSG_OFFLINE_SUBMIT;
-                }
-                else
-#endif
-                {
-                    title=@"Order submitted sucessfully";
-                    msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
-                }
-                
-                UIAlertController* message_alert=[RAUtils message_alert:msg title:title controller:self];
-                
-                //                UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
-                //
-                //                [alert show];
-                //
-                NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
-                NSString* email_content =[editor_json valueForKey:@"email_content"];
-                NSString* soid=[editor_json valueForKey:@"so#"];
-                
-                NSMutableDictionary *value = [NSMutableDictionary dictionary];
-                if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
-                {
-                    //bbb
-                    [((MainViewController*)appDelegate.main_vc) Loginout:false];
-                    value[@"commitorder_logout"]=@"true";
-                }
-                [self prepareReturn:value];
-                
-                [self.navigationController popToRootViewControllerAnimated:true];
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission" completion:^{
+        [RANetwork request_commit_order:upparams completionHandler:^(NSMutableDictionary *result) {
+                NSDictionary* editor_json = result;
+                [waitalert dismissViewControllerAnimated:YES completion:^{
+                    if([[editor_json valueForKey:@"result"] intValue]==2)
+                    {
+                        
+                        // debug aaa
+                        AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                        NSString* company= appDelegate.customerInfo[@"customer_name"];
+                        NSString* send_to =appDelegate.customerInfo[@"customer_email"];
+                        
+                        [appDelegate closeOrder];
+                        
+                        
+        #ifdef RA_NOTIFICATION
+                        [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+        #else
+                        
+                        [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
+        #endif
+                        
+                        __block NSString* title=nil;
+                        __block NSString* msg=nil;
+        #ifdef OFFLINE_MODE
+                        if(appDelegate.offline_mode)
+                        {
+                            title=TITLE_OFFLINE_SUBMIT;
+                            msg=MSG_OFFLINE_SUBMIT;
+                        }
+                        else
+        #endif
+                        {
+                            title=@"Order submitted sucessfully";
+                            msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
+                        }
+                        
+                        NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
+                        NSString* email_content =[editor_json valueForKey:@"email_content"];
+                        NSString* soid=[editor_json valueForKey:@"so#"];
+                        
+                        NSMutableDictionary *value = [NSMutableDictionary dictionary];
+                        if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
+                        {
+                            //bbb
+                            [((MainViewController*)appDelegate.main_vc) Loginout:false];
+                            value[@"commitorder_logout"]=@"true";
+                        }
+                        [self prepareReturn:value];
+                        
+                        __block UIViewController* message_parent = self.navigationController.topViewController;
+                        [self.navigationController popToRootViewControllerAnimated:true];
+                        if(pdf_url.length>0)
+                        {
+                            
+                            
+//                            [message_alert dismissViewControllerAnimated:YES completion:^{
+                                //                        [alert dismissWithClickedButtonIndex:0 animated:FALSE];
+//                                [self.navigationController popToRootViewControllerAnimated:true];
+                                [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
+                                
+                                //  [appDelegate printPdf:pdf_url];
+//                            }];
+                            
+                            
+                        }
+                        else
+                            dispatch_async(dispatch_get_main_queue(), ^{
+//                            UIAlertController* message_alert=
+                                
+                                [RAUtils message_alert:msg title:title controller:message_parent];
+                        });
+//                        __block UIAlertController* message_alert=[RAUtils message_alert:msg title:title controller:self.parentViewController action_handler:^(UIAlertAction * _Nonnull action) {
+//
+//
+//
+//
+////                            [self.navigationController popToRootViewControllerAnimated:true];
+//
+//
+//                        } completion:^{
+//
+//                        }];
+                        
+                        //                UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
+                        //
+                        //                [alert show];
+                        //
+                       
+                        
+                        
+                    }
+                    else
+                    {
+                        [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
+                    }
+                }];
                 
-                if(pdf_url.length>0)
-                {
-                    
-                    
-                    [message_alert dismissViewControllerAnimated:YES completion:^{
-                        //                        [alert dismissWithClickedButtonIndex:0 animated:FALSE];
-                        [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
-                        //  [appDelegate printPdf:pdf_url];
-                    }];
- 
-                    
-                }
                 
                 
-            }
-            else
-            {
-                [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
-            }
-        }];
-        
-        
-        
+            }];
+
     }];
-//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+    
+    //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //        NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
 //

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 604 - 590
RedAnt ERP Mobile/common/Functions/order/OrderDetailViewController.m


+ 170 - 162
RedAnt ERP Mobile/common/Functions/order/OrderListViewController.m

@@ -855,69 +855,71 @@
 -(void) neworder
 {
     
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order"];
-    [RANetwork request_create_order:^(NSMutableDictionary *result) {
-        NSMutableDictionary* return_json =result;
-        
-        [waitalert dismissViewControllerAnimated:YES completion:^{
-            if([[return_json valueForKey:@"result"] intValue]==2)
-            {
-                int result=[[return_json valueForKey:@"result"] intValue];
-                if(result==2)
-                {
-                    //successed.
-                    
-                    NSString* order_code = [return_json valueForKey:@"orderCode"];
-                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                    appDelegate.order_code = order_code;
-                    appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
-                    
-                    
-#ifdef RA_NOTIFICATION
-                    [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-#else
-                    MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
-                    [main_vc reloadCart:true immediately:false];
-#endif
-                    
-                    [self ReloadData];
-                    
-                    
-                    //     [self performSelector:@selector(loadpage) withObject:nil afterDelay:1];
-                    //    [self loadpage];
-                    
-                    
-                    //                    if(self.shopCartBlock!=nil)
-                    //                    {
-                    //                        UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
-                    //
-                    //
-                    //                        CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
-                    //                        UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
-                    //                        iv.image = img;
-                    //                        //                        [self.contentView addSubview:iv];
-                    //                        self.shopCartBlock(iv);
-                    //
-                    //                    }
-                    
-                }
-            }
-            else
-            {
-                [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Create Order" controller:self] ;
-            }
-        }];
-//        [waitalert dismissViewControllerAnimated:YES completion:nil];
-        
-        
-        
-        
-        
-        
-        
-        
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order" completion:^{
+        [RANetwork request_create_order:^(NSMutableDictionary *result) {
+                NSMutableDictionary* return_json =result;
+                
+                [waitalert dismissViewControllerAnimated:YES completion:^{
+                    if([[return_json valueForKey:@"result"] intValue]==2)
+                    {
+                        int result=[[return_json valueForKey:@"result"] intValue];
+                        if(result==2)
+                        {
+                            //successed.
+                            
+                            NSString* order_code = [return_json valueForKey:@"orderCode"];
+                            AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                            appDelegate.order_code = order_code;
+                            appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
+                            
+                            
+        #ifdef RA_NOTIFICATION
+                            [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+        #else
+                            MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
+                            [main_vc reloadCart:true immediately:false];
+        #endif
+                            
+                            [self ReloadData];
+                            
+                            
+                            //     [self performSelector:@selector(loadpage) withObject:nil afterDelay:1];
+                            //    [self loadpage];
+                            
+                            
+                            //                    if(self.shopCartBlock!=nil)
+                            //                    {
+                            //                        UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
+                            //
+                            //
+                            //                        CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
+                            //                        UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
+                            //                        iv.image = img;
+                            //                        //                        [self.contentView addSubview:iv];
+                            //                        self.shopCartBlock(iv);
+                            //
+                            //                    }
+                            
+                        }
+                    }
+                    else
+                    {
+                        [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Create Order" controller:self] ;
+                    }
+                }];
+        //        [waitalert dismissViewControllerAnimated:YES completion:nil];
+                
+                
+                
+                
+                
+                
+                
+                
+            }];
+
     }];
-    
+        
 //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //        NSDictionary* return_json = [RANetwork new_Order];
@@ -1534,44 +1536,46 @@
             
             UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
                 
-                UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Delete Order"];
-                [RANetwork request_delete_order:orderid completionHandler:^(NSMutableDictionary *result) {
-                    NSDictionary* return_json = result;
-                    //                        [waitalert dismissViewControllerAnimated:YES completion:nil];
-                    [waitalert dismissViewControllerAnimated:YES completion:^{
-                        if([[return_json valueForKey:@"result"] intValue]==2)
-                        {
-                            if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
+                __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Delete Order" completion:^{
+                    [RANetwork request_delete_order:orderid completionHandler:^(NSMutableDictionary *result) {
+                        NSDictionary* return_json = result;
+                        //                        [waitalert dismissViewControllerAnimated:YES completion:nil];
+                        [waitalert dismissViewControllerAnimated:YES completion:^{
+                            if([[return_json valueForKey:@"result"] intValue]==2)
                             {
-                                appDelegate.order_code= nil;
-                                [appDelegate SetSo:nil];
-                                
-                                
-                                appDelegate.cart_count=0;
-                                [appDelegate update_count_mark];
+                                if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
+                                {
+                                    appDelegate.order_code= nil;
+                                    [appDelegate SetSo:nil];
+                                    
+                                    
+                                    appDelegate.cart_count=0;
+                                    [appDelegate update_count_mark];
+                                    
+                                    //                                appDelegate.customerInfo = nil;
+                                    //                                appDelegate.contact_id = nil;
+                                    //                                appDelegate.order_customer_id = nil;
+                                }
                                 
-                                //                                appDelegate.customerInfo = nil;
-                                //                                appDelegate.contact_id = nil;
-                                //                                appDelegate.order_customer_id = nil;
+                                [RAUtils message_alert:nil title:@"Order Delete" controller:self] ;
+                                [self ReloadData];
                             }
-                            
-                            [RAUtils message_alert:nil title:@"Order Delete" controller:self] ;
-                            [self ReloadData];
-                        }
-                        else
-                        {
-                            [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Delete Order" controller:self] ;
-                        }
+                            else
+                            {
+                                [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Delete Order" controller:self] ;
+                            }
+                        }];
+                        
+                        
+
+                        
+                        
+                        
+                        
                     }];
-                    
-                    
 
-                    
-                    
-                    
-                    
                 }];
-                
+                                
                 
 //                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
@@ -1652,45 +1656,47 @@
             
             UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
                 
-                UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Cancel Order"];
-                [RANetwork request_cancel_order:orderid order_code:nil completionHandler:^(NSMutableDictionary *result) {
-                    
-                    NSDictionary* return_json = result;
-                    //                        [waitalert dismissViewControllerAnimated:YES completion:nil];
-                    [waitalert dismissViewControllerAnimated:YES completion:^{
+                __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Cancel Order" completion:^{
+                    [RANetwork request_cancel_order:orderid order_code:nil completionHandler:^(NSMutableDictionary *result) {
                         
-                        if([[return_json valueForKey:@"result"] intValue]==2)
-                        {
-                            if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
+                        NSDictionary* return_json = result;
+                        //                        [waitalert dismissViewControllerAnimated:YES completion:nil];
+                        [waitalert dismissViewControllerAnimated:YES completion:^{
+                            
+                            if([[return_json valueForKey:@"result"] intValue]==2)
                             {
-                                appDelegate.order_code= nil;
-                                //appDelegate.user_type = 0;
-                                appDelegate.customerInfo = nil;
-                                appDelegate.contact_id = nil;
-                                appDelegate.order_customer_id = nil;
-                                [appDelegate SetSo:nil];
-                                appDelegate.cart_count=0;
-                                [appDelegate update_count_mark];
-                                
-                                
+                                if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
+                                {
+                                    appDelegate.order_code= nil;
+                                    //appDelegate.user_type = 0;
+                                    appDelegate.customerInfo = nil;
+                                    appDelegate.contact_id = nil;
+                                    appDelegate.order_customer_id = nil;
+                                    [appDelegate SetSo:nil];
+                                    appDelegate.cart_count=0;
+                                    [appDelegate update_count_mark];
+                                    
+                                    
+                                }
+                                [RAUtils message_alert:nil title:@"Order Canceled" controller:self] ;
+                                [self ReloadData];
                             }
-                            [RAUtils message_alert:nil title:@"Order Canceled" controller:self] ;
-                            [self ReloadData];
-                        }
-                        else
-                        {
-                            [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Cancel Order" controller:self] ;
-                        }
+                            else
+                            {
+                                [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Cancel Order" controller:self] ;
+                            }
+                        }];
+                        
+                        
+                        
+                        
+                        
+                        
+                        
                     }];
-                    
-                    
-                    
-                    
-                    
-                    
-                    
+
                 }];
-//                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+                //                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //                    NSDictionary* return_json = [RANetwork cancel_Order:orderid order_code:nil];
 //
@@ -1928,44 +1934,46 @@
             
             UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
                 
-                UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Cancel Order"];
-                
-                [RANetwork request_cancel_order:orderid order_code:nil completionHandler:^(NSMutableDictionary *result) {
-                    NSDictionary* return_json =result;
-                    //                        [waitalert dismissViewControllerAnimated:YES completion:nil];
-                    [waitalert dismissViewControllerAnimated:YES completion:^{
-                        if([[return_json valueForKey:@"result"] intValue]==2)
-                        {
-                            if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
+                __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Cancel Order" completion:^{
+                    [RANetwork request_cancel_order:orderid order_code:nil completionHandler:^(NSMutableDictionary *result) {
+                        NSDictionary* return_json =result;
+                        //                        [waitalert dismissViewControllerAnimated:YES completion:nil];
+                        [waitalert dismissViewControllerAnimated:YES completion:^{
+                            if([[return_json valueForKey:@"result"] intValue]==2)
                             {
-                                appDelegate.order_code= nil;
-                                //appDelegate.user_type = 0;
-                                appDelegate.customerInfo = nil;
-                                appDelegate.contact_id = nil;
-                                appDelegate.order_customer_id = nil;
-                                [appDelegate SetSo:nil];
-                                appDelegate.cart_count=0;
-                                [appDelegate update_count_mark];
-                                
-                                
+                                if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
+                                {
+                                    appDelegate.order_code= nil;
+                                    //appDelegate.user_type = 0;
+                                    appDelegate.customerInfo = nil;
+                                    appDelegate.contact_id = nil;
+                                    appDelegate.order_customer_id = nil;
+                                    [appDelegate SetSo:nil];
+                                    appDelegate.cart_count=0;
+                                    [appDelegate update_count_mark];
+                                    
+                                    
+                                }
+                                [RAUtils message_alert:nil title:@"Order Canceled" controller:self] ;
+                                [self ReloadData];
                             }
-                            [RAUtils message_alert:nil title:@"Order Canceled" controller:self] ;
-                            [self ReloadData];
-                        }
-                        else
-                        {
-                            [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Cancel Order" controller:self] ;
-                        }
+                            else
+                            {
+                                [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Cancel Order" controller:self] ;
+                            }
+                        }];
+                        
+                        
+                        
+                        
+                        
+                        
+                        
                     }];
-                    
-                    
-                    
-                    
-                    
-                    
-                    
+
                 }];
-//                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+                
+                //                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //                    NSDictionary* return_json = [RANetwork cancel_Order:orderid order_code:nil];
 //

+ 40 - 38
RedAnt ERP Mobile/common/Functions/order/RAOrderEditorViewController.m

@@ -196,49 +196,51 @@ static const int totalPage = 3;
                      // close order;
                      
                      AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                     UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order"];
-             [RANetwork request_release_order:appDelegate.order_code withScreen:nil completionHandler:^(NSMutableDictionary *result) {
-                 NSDictionary* order_json = result;
-             //                    [waitalert dismissViewControllerAnimated:YES completion:nil];
-                 [waitalert dismissViewControllerAnimated:YES completion:^{
-                     if([[order_json valueForKey:@"result"] intValue]==2)
-                     {
-                         AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                         
-                         [appDelegate closeOrder];
-                         
-                         
-                         //#ifdef RA_NOTIFICATION
-                         //                        [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-                         //#else
-                         //                        [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
-                         //#endif
-                         [((MainViewController*)appDelegate.main_vc) switchToHome];
-                         
-                         if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
+             __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order" completion:^{
+                 [RANetwork request_release_order:appDelegate.order_code withScreen:nil completionHandler:^(NSMutableDictionary *result) {
+                     NSDictionary* order_json = result;
+                 //                    [waitalert dismissViewControllerAnimated:YES completion:nil];
+                     [waitalert dismissViewControllerAnimated:YES completion:^{
+                         if([[order_json valueForKey:@"result"] intValue]==2)
                          {
-                             [((MainViewController*)appDelegate.main_vc) Loginout:false];
+                             AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                             
+                             [appDelegate closeOrder];
+                             
+                             
+                             //#ifdef RA_NOTIFICATION
+                             //                        [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+                             //#else
+                             //                        [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
+                             //#endif
+                             [((MainViewController*)appDelegate.main_vc) switchToHome];
+                             
+                             if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
+                             {
+                                 [((MainViewController*)appDelegate.main_vc) Loginout:false];
+                             }
+                             
+                             [self prepareReturn:nil];
+                             
+                             
+                             [self.navigationController popViewControllerAnimated:true];
+                             
+                             
                          }
-                         
-                         [self prepareReturn:nil];
-                         
-                         
-                         [self.navigationController popViewControllerAnimated:true];
-                         
-                         
-                     }
-                     else
-                     {
-                         [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
-                     }
+                         else
+                         {
+                             [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
+                         }
+                     }];
+                                     
+
+                                     
+                                     
+                                     
                  }];
-                                 
 
-                                 
-                                 
-                                 
              }];
-//                     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+             //                     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //                         NSDictionary* order_json = [RANetwork release_Order:appDelegate.order_code withScreen:nil];
 //

+ 258 - 249
RedAnt ERP Mobile/common/Functions/order/RAOrderPreviewController.m

@@ -1754,49 +1754,51 @@
                  
                  
                  AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                 UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order"];
-         [RANetwork request_release_order:appDelegate.order_code withScreen:nil completionHandler:^(NSMutableDictionary *result) {
-             NSDictionary* order_json = result;
-             [waitalert dismissViewControllerAnimated:YES completion:^{
-                 if([[order_json valueForKey:@"result"] intValue]==2)
-                 {
-                     AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                     //                        appDelegate.order_code = nil;
-                     
-                     [appDelegate closeOrder];
-                     
-                     
-#ifdef RA_NOTIFICATION
-                     [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-#else
-                     [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
-#endif
-                     [((MainViewController*)appDelegate.main_vc) switchToHome];
-                     
-                     if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
-                     {
-                         [((MainViewController*)appDelegate.main_vc) Loginout:false];
-                     }
-                     
-                     [self prepareReturn:nil];
-                     
-                     
-                     [self.navigationController popToRootViewControllerAnimated:true];
-                     //                        [self.navigationController dismissViewControllerAnimated:true completion:^{
-                     //                            ;
-                     //                        }];
-                     
-                 }
-                 else
-                 {
-                     [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
-                 }
-             }];
-             
-             
-             
-             
+         __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order" completion:^{
+             [RANetwork request_release_order:appDelegate.order_code withScreen:nil completionHandler:^(NSMutableDictionary *result) {
+                          NSDictionary* order_json = result;
+                          [waitalert dismissViewControllerAnimated:YES completion:^{
+                              if([[order_json valueForKey:@"result"] intValue]==2)
+                              {
+                                  AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                                  //                        appDelegate.order_code = nil;
+                                  
+                                  [appDelegate closeOrder];
+                                  
+                                  
+             #ifdef RA_NOTIFICATION
+                                  [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+             #else
+                                  [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
+             #endif
+                                  [((MainViewController*)appDelegate.main_vc) switchToHome];
+                                  
+                                  if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
+                                  {
+                                      [((MainViewController*)appDelegate.main_vc) Loginout:false];
+                                  }
+                                  
+                                  [self prepareReturn:nil];
+                                  
+                                  
+                                  [self.navigationController popToRootViewControllerAnimated:true];
+                                  //                        [self.navigationController dismissViewControllerAnimated:true completion:^{
+                                  //                            ;
+                                  //                        }];
+                                  
+                              }
+                              else
+                              {
+                                  [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
+                              }
+                          }];
+                          
+                          
+                          
+                          
+                      }];
          }];
+         
 //                 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //                     NSDictionary* order_json = [RANetwork release_Order:appDelegate.order_code withScreen:nil];
@@ -1909,92 +1911,94 @@
         upparams[@"shipping"] = nil;
     
     
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving Order"];
-    
-    [RANetwork request_save_order:upparams completionHandler:^(NSMutableDictionary *result) {
-        NSDictionary* editor_json =result;
-        
-        [waitalert dismissViewControllerAnimated:YES completion:^{
-            if([[editor_json valueForKey:@"result"] intValue]==2)
-            {
-                
-                AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving Order" completion:^{
+        [RANetwork request_save_order:upparams completionHandler:^(NSMutableDictionary *result) {
+                NSDictionary* editor_json =result;
                 
+                [waitalert dismissViewControllerAnimated:YES completion:^{
+                    if([[editor_json valueForKey:@"result"] intValue]==2)
+                    {
+                        
+                        AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                        
+                        
+                        
+                        NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
+                        
+                        
+                        if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
+                        {
+                            appDelegate.customerInfo = customerInfo;
+                            appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
+                        }
+                        NSString *msg = nil;
+                        if ([editor_json objectForKey:@"so#"]) {
+                            msg = [@"SO#:" stringByAppendingString:[editor_json objectForKey:@"so#"]];
+                        }
+                        [RAUtils message_alert:msg title:@"Order Saved" controller:self] ;
+                        
+                        if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.save_order_logout && appDelegate.user_type ==USER_ROLE_EMPLOYEE)
+                        {
+                            [((MainViewController*)appDelegate.main_vc) Loginout:false];
+                            [self prepareReturn:nil];
+                            [self.navigationController popToRootViewControllerAnimated:true];
+                        }
+                        else{
+                            
+                            
+        #ifdef RA_NOTIFICATION
+                            [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+        #else
+                            
+                            AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                            [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
+        #endif
+                        }
+                        
+                        if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
+                            
+                            if (![Singleton sharedInstance].currentOrderIsMerged) {
+                                [self releaseOrderAfterSave];
+                            }
+                            
+                            
+                        }
+                        
+                        
+                        //                if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
+                        //                    appDelegate.order_code = nil;
+                        //
+                        //                }
+                        //    //     self.labelContact.text=appDelegate.contact_name;
+                        //
+                        //    NSDictionary * customerinfo = appDelegate.customerInfo;
+                        // [self prepareReturn:nil];
+                        //                [self.navigationController dismissViewControllerAnimated:true completion:^{
+                        //
+                        //
+                        //                    ;
+                        //                }];
+                        
+                    }
+                    else
+                    {
+                        [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Save Order" controller:self] ;
+                    }
+                }];
+                //            [waitalert dismissViewControllerAnimated:YES completion:nil];
                 
                 
-                NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
                 
                 
-                if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
-                {
-                    appDelegate.customerInfo = customerInfo;
-                    appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
-                }
-                NSString *msg = nil;
-                if ([editor_json objectForKey:@"so#"]) {
-                    msg = [@"SO#:" stringByAppendingString:[editor_json objectForKey:@"so#"]];
-                }
-                [RAUtils message_alert:msg title:@"Order Saved" controller:self] ;
                 
-                if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.save_order_logout && appDelegate.user_type ==USER_ROLE_EMPLOYEE)
-                {
-                    [((MainViewController*)appDelegate.main_vc) Loginout:false];
-                    [self prepareReturn:nil];
-                    [self.navigationController popToRootViewControllerAnimated:true];
-                }
-                else{
-                    
-                    
-#ifdef RA_NOTIFICATION
-                    [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-#else
-                    
-                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                    [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
-#endif
-                }
                 
-                if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
-                    
-                    if (![Singleton sharedInstance].currentOrderIsMerged) {
-                        [self releaseOrderAfterSave];
-                    }
-                    
-                    
-                }
                 
                 
-                //                if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
-                //                    appDelegate.order_code = nil;
-                //
-                //                }
-                //    //     self.labelContact.text=appDelegate.contact_name;
-                //
-                //    NSDictionary * customerinfo = appDelegate.customerInfo;
-                // [self prepareReturn:nil];
-                //                [self.navigationController dismissViewControllerAnimated:true completion:^{
-                //
-                //
-                //                    ;
-                //                }];
-                
-            }
-            else
-            {
-                [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Save Order" controller:self] ;
-            }
-        }];
-        //            [waitalert dismissViewControllerAnimated:YES completion:nil];
-        
-        
-        
-        
-        
-        
-        
-        
+            }];
+
     }];
-//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+    
+    //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //        NSDictionary* editor_json = [RANetwork save_Order:upparams];
 //
@@ -2927,69 +2931,71 @@
 
 
 - (void)customer_commit_order:(NSMutableDictionary *)upparams {
-    
-
-        UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission"];
-    
         if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
             upparams[@"shipping"] = nil;
     
         [upparams setValue:@"true" forKey:@"isHold"];
-    
-    [RANetwork request_commit_order:upparams completionHandler:^(NSMutableDictionary *result) {
-        NSDictionary* editor_json =result;
-        [waitalert dismissViewControllerAnimated:YES completion:^{
-            if([[editor_json valueForKey:@"result"] intValue]==2)
-            {
-                
-                AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                // appDelegate.customerInfo = customerInfo;
-                
-                [appDelegate closeOrder];
-                
-#ifdef RA_NOTIFICATION
-                [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-                
-#else
-                [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
-#endif
-                
-                
-                
-                NSString* title=nil;
-                NSString* msg=nil;
-#ifdef OFFLINE_MODE
-                if(appDelegate.offline_mode)
-                {
-                    title=TITLE_OFFLINE_SUBMIT;
-                    msg=MSG_OFFLINE_SUBMIT;
-                }
-                else
-#endif
-                {
-                    title=@"Order submitted sucessfully";
-                    msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
-                }
-                
-                //                    UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
-                //
-                //                    [alert show];
-                [self back_order_submit_alert:editor_json];
-                
-                [self prepareReturn:nil];
-                [self.navigationController popToRootViewControllerAnimated:true];
-                
-                
-            }
-            else
-            {
-                [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
-            }
-        }];
-                    
-                    
+
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission" completion:^{
+        [RANetwork request_commit_order:upparams completionHandler:^(NSMutableDictionary *result) {
+                NSDictionary* editor_json =result;
+                [waitalert dismissViewControllerAnimated:YES completion:^{
+                    if([[editor_json valueForKey:@"result"] intValue]==2)
+                    {
+                        
+                        AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                        // appDelegate.customerInfo = customerInfo;
+                        
+                        [appDelegate closeOrder];
+                        
+        #ifdef RA_NOTIFICATION
+                        [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+                        
+        #else
+                        [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
+        #endif
+                        
+                        
+                        
+                        NSString* title=nil;
+                        NSString* msg=nil;
+        #ifdef OFFLINE_MODE
+                        if(appDelegate.offline_mode)
+                        {
+                            title=TITLE_OFFLINE_SUBMIT;
+                            msg=MSG_OFFLINE_SUBMIT;
+                        }
+                        else
+        #endif
+                        {
+                            title=@"Order submitted sucessfully";
+                            msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
+                        }
+                        
+                        //                    UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
+                        //
+                        //                    [alert show];
+                        [self back_order_submit_alert:editor_json];
+                        
+                        [self prepareReturn:nil];
+                        [self.navigationController popToRootViewControllerAnimated:true];
+                        
+                        
+                    }
+                    else
+                    {
+                        [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
+                    }
                 }];
-//        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+                            
+                            
+                        }];
+
+    }];
+    
+
+    
+    //        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //            NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
 //
@@ -3049,86 +3055,89 @@
 
 - (void)empolyee_commit_order:(NSMutableDictionary *)upparams {
     
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission"];
     [upparams setValue:@"false" forKey:@"isHold"];
-    [RANetwork request_commit_order:upparams completionHandler:^(NSMutableDictionary *result) {
-        NSDictionary* editor_json = result;
-        [waitalert dismissViewControllerAnimated:YES completion:^{
-            if([[editor_json valueForKey:@"result"] intValue]==2)
-            {
-                
-                // debug aaa
-                AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                NSString* company= appDelegate.customerInfo[@"customer_name"];
-                NSString* send_to =appDelegate.customerInfo[@"customer_email"];
-                
-                [appDelegate closeOrder];
-                
-#ifdef RA_NOTIFICATION
-                [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-                
-#else
-                [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
-#endif
-                
-                NSString* title=nil;
-                NSString* msg=nil;
-#ifdef OFFLINE_MODE
-                if(appDelegate.offline_mode)
-                {
-                    title=TITLE_OFFLINE_SUBMIT;
-                    msg=MSG_OFFLINE_SUBMIT;
-                }
-                else
-#endif
-                {
-                    title=@"Order submitted sucessfully";
-                    msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
-                }
-                
-                //                UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
-                //
-                //                [alert show];
-                UIViewController *alert = [self back_order_submit_alert:editor_json];
-                
-                NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
-                NSString* email_content =[editor_json valueForKey:@"email_content"];
-                //                NSString* soid=[editor_json valueForKey:@"so#"];
-                {
-                    NSMutableDictionary *value = [NSMutableDictionary dictionary];
-                    if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
-                    {
-                        //bbb
-                        [((MainViewController*)appDelegate.main_vc) Loginout:false];
-                        value[@"commitorder_logout"]=@"true";
-                    }
-                    [self prepareReturn:value];
-                    
-                    [self.navigationController popToRootViewControllerAnimated:true];
-                    
-                    if(pdf_url.length>0)
+   __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission" completion:^{
+        [RANetwork request_commit_order:upparams completionHandler:^(NSMutableDictionary *result) {
+                NSDictionary* editor_json = result;
+                [waitalert dismissViewControllerAnimated:YES completion:^{
+                    if([[editor_json valueForKey:@"result"] intValue]==2)
                     {
                         
-                        //                        [alert dismissWithClickedButtonIndex:0 animated:FALSE];
-                        [alert dismissViewControllerAnimated:YES completion:^{
-                            NSString *pdf_title = [editor_json objectForKey:@"title"];
-                            [appDelegate printPdf:pdf_url company:company send_to:send_to soid:pdf_title content:email_content];
-                        }];
+                        // debug aaa
+                        AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                        NSString* company= appDelegate.customerInfo[@"customer_name"];
+                        NSString* send_to =appDelegate.customerInfo[@"customer_email"];
+                        
+                        [appDelegate closeOrder];
+                        
+        #ifdef RA_NOTIFICATION
+                        [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+                        
+        #else
+                        [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
+        #endif
+                        
+                        NSString* title=nil;
+                        NSString* msg=nil;
+        #ifdef OFFLINE_MODE
+                        if(appDelegate.offline_mode)
+                        {
+                            title=TITLE_OFFLINE_SUBMIT;
+                            msg=MSG_OFFLINE_SUBMIT;
+                        }
+                        else
+        #endif
+                        {
+                            title=@"Order submitted sucessfully";
+                            msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
+                        }
+                        
+                        //                UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
+                        //
+                        //                [alert show];
+                        UIViewController *alert = [self back_order_submit_alert:editor_json];
+                        
+                        NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
+                        NSString* email_content =[editor_json valueForKey:@"email_content"];
+                        //                NSString* soid=[editor_json valueForKey:@"so#"];
+                        {
+                            NSMutableDictionary *value = [NSMutableDictionary dictionary];
+                            if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
+                            {
+                                //bbb
+                                [((MainViewController*)appDelegate.main_vc) Loginout:false];
+                                value[@"commitorder_logout"]=@"true";
+                            }
+                            [self prepareReturn:value];
+                            
+                            [self.navigationController popToRootViewControllerAnimated:true];
+                            
+                            if(pdf_url.length>0)
+                            {
+                                
+                                //                        [alert dismissWithClickedButtonIndex:0 animated:FALSE];
+                                [alert dismissViewControllerAnimated:YES completion:^{
+                                    NSString *pdf_title = [editor_json objectForKey:@"title"];
+                                    [appDelegate printPdf:pdf_url company:company send_to:send_to soid:pdf_title content:email_content];
+                                }];
 
+                            }
+                        }
+                        
                     }
-                }
+                    else
+                    {
+                        [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
+                    }
+                }];
                 
-            }
-            else
-            {
-                [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
-            }
-        }];
-        
-        
-        
+                
+                
+            }];
+
     }];
-//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+    
+    //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //        NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
 //

+ 24 - 22
RedAnt ERP Mobile/common/Functions/portfolio/PortfolioListViewController.m

@@ -708,30 +708,32 @@
             
             
             UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
-                UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Remove Portfilio"];
-                
-                [RANetwork request_removeportfoliopdf:listid completionHandler:^(NSMutableDictionary *result) {
-                    NSMutableDictionary* cart_json = result;
-                    
-                    
-                    [waitalert dismissViewControllerAnimated:YES completion:nil];
-//                    [waitalert dismissViewControllerAnimated:YES completion:nil];
-                    
-                    if([[cart_json valueForKey:@"result"] intValue]==2)
-                    {
-                        
-                        [self ReloadData];
-                    }
-                    else
-                    {
-                        [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Portfolio" controller:self] ;
-                    }
-                    
-                    
-                    
-                    
+                __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Remove Portfilio" completion:^{
+                    [RANetwork request_removeportfoliopdf:listid completionHandler:^(NSMutableDictionary *result) {
+                                        NSMutableDictionary* cart_json = result;
+                                        
+                                        
+                                        [waitalert dismissViewControllerAnimated:YES completion:nil];
+                    //                    [waitalert dismissViewControllerAnimated:YES completion:nil];
+                                        
+                                        if([[cart_json valueForKey:@"result"] intValue]==2)
+                                        {
+                                            
+                                            [self ReloadData];
+                                        }
+                                        else
+                                        {
+                                            [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Portfolio" controller:self] ;
+                                        }
+                                        
+                                        
+                                        
+                                        
+                                    }];
+
                 }];
                 
+                                
 //                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //                    
 //                    NSMutableDictionary* cart_json =[RANetwork delete_portfoliolist:listid];

+ 357 - 344
RedAnt ERP Mobile/common/Functions/portfolio/PortfolioViewController.m

@@ -346,60 +346,62 @@
 -(void) neworder
 {
     
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order"];
-    [RANetwork request_create_order:^(NSMutableDictionary *result) {
-        NSMutableDictionary* return_json = result;
-        
-//        [waitalert dismissViewControllerAnimated:YES completion:nil];
-        [waitalert dismissViewControllerAnimated:YES completion:^{
-            
-            if([[return_json valueForKey:@"result"] intValue]==2)
-            {
-                int result=[[return_json valueForKey:@"result"] intValue];
-                if(result==2)
-                {
-                    //successed.
-                    
-                    NSString* order_code = [return_json valueForKey:@"orderCode"];
-                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                    appDelegate.order_code = order_code;
-                    
-                    
-                    [self addtocart];
-                    
-                    
-                    //    [self ReloadData];
-                    
-                    
-                    //                    if(self.shopCartBlock!=nil)
-                    //                    {
-                    //                        UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
-                    //
-                    //
-                    //                        CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
-                    //                        UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
-                    //                        iv.image = img;
-                    //                        //                        [self.contentView addSubview:iv];
-                    //                        self.shopCartBlock(iv);
-                    //
-                    //                    }
+   __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order" completion:^{
+        [RANetwork request_create_order:^(NSMutableDictionary *result) {
+                NSMutableDictionary* return_json = result;
+                
+        //        [waitalert dismissViewControllerAnimated:YES completion:nil];
+                [waitalert dismissViewControllerAnimated:YES completion:^{
                     
-                }
-            }
-            else
-            {
-                [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
-            }
-        }];
-        
-        
-        
-        
-        
-        
-        
+                    if([[return_json valueForKey:@"result"] intValue]==2)
+                    {
+                        int result=[[return_json valueForKey:@"result"] intValue];
+                        if(result==2)
+                        {
+                            //successed.
+                            
+                            NSString* order_code = [return_json valueForKey:@"orderCode"];
+                            AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                            appDelegate.order_code = order_code;
+                            
+                            
+                            [self addtocart];
+                            
+                            
+                            //    [self ReloadData];
+                            
+                            
+                            //                    if(self.shopCartBlock!=nil)
+                            //                    {
+                            //                        UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
+                            //
+                            //
+                            //                        CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
+                            //                        UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
+                            //                        iv.image = img;
+                            //                        //                        [self.contentView addSubview:iv];
+                            //                        self.shopCartBlock(iv);
+                            //
+                            //                    }
+                            
+                        }
+                    }
+                    else
+                    {
+                        [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
+                    }
+                }];
+                
+                
+                
+                
+                
+                
+                
+            }];
+
     }];
-//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+    //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //        NSDictionary* return_json = [RANetwork new_Order];
 //
@@ -668,176 +670,181 @@
     [params setObject:pdf_url forKey:@"pdfUrl"];
     
     
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Processing"];
-    [RANetwork request_portfoliopreview:params completionHandler:^(NSMutableDictionary *result) {
-        NSDictionary* editor_json = result;
-        [waitalert dismissViewControllerAnimated:YES completion:^{
-            if([[editor_json valueForKey:@"result"] intValue]==2)
-            {
-                
-                AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                
-                NSString* url = [editor_json valueForKey:@"pdf_path"];
-                NSString* path = [editor_json valueForKey:@"pdf_real_path"];
-                bool isLocalFile = [[editor_json valueForKey:@"isLocalFile"] boolValue];
-                RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
-                ViewController.url = url;
-                ViewController.canSave = true;
-                ViewController.isLocalfile=isLocalFile;
-                
-                ViewController.filename = [NSString stringWithFormat:@"%@.pdf",[TextUtils legalFilename:catelog_name]];
-                ViewController.save_name =catelog_name;
-                ViewController.save_note =internal_note;
-                
-                NSString* company=    [appDelegate.customerInfo valueForKey:@"customer_name"];
-                
-                if(company==nil)
-                    company=@"";
-                
-                NSString* customer_email=    [appDelegate.customerInfo valueForKey:@"customer_email"];
-                
-                
-                NSMutableArray* send_to = [[NSMutableArray alloc]init];
-                if(customer_email.length>0)
-                {
-                    send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
-                }
-                ViewController.mail_to = send_to;
-                
-                NSString* subject;
-                
-                subject =catelog_name;
-                
-                ViewController.mail_subject = subject;
-                
-                ViewController.onSavePDF=^(NSString* name,NSString* file)
-                {
-                    
-                    
-                    NSString* del_ids = nil;
-                    
-                    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving..."];
-#ifdef OFFLINE_MODE
-                    if (appDelegate.offline_mode)
-                    {
-                        [params setValue:url forKey:@"pdfPath"];
-                    }
-                    else
-#endif
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Processing" completion:^{
+        [RANetwork request_portfoliopreview:params completionHandler:^(NSMutableDictionary *result) {
+                NSDictionary* editor_json = result;
+                [waitalert dismissViewControllerAnimated:YES completion:^{
+                    if([[editor_json valueForKey:@"result"] intValue]==2)
                     {
-                        [params setValue:path forKey:@"pdfPath"];
-                    }
-                    [params setValue:name forKey:@"pdfName"];
-                    [params setValue:internal_note forKey:@"pdfNote"];
-                    [params setValue:del_ids forKey:@"itemIds"];
-                    [params setValue:pdf_url forKey:@"configureParams"];
-                    
-                    [RANetwork request_save_portfolio:params completionHandler:^(NSMutableDictionary *result) {
-                        NSDictionary* json =result;
-                        [waitalert dismissViewControllerAnimated:YES completion:^{
-                            if([[json valueForKey:@"result"] intValue]==2)
-                            {
-                                
-                                [RAUtils message_alert:@"Portfolio saved. You can find it from View Portfolios" title:@"Portfolio" controller:self];
-                                
-                                //                                [RAUtils alert_view:nil title:@"Portfolio saved. You can find it from View Portfolios" ] ;
-                                
-                                [self.navigationController dismissViewControllerAnimated:true completion:^{
-                                    
-                                    
-                                    
-#ifdef RA_NOTIFICATION
-                                    [ActiveViewController Notify:@"PortfolioViewController,PDFListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-#else
-                                    [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
-                                    [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
-#endif
-                                }];
-                            }
-                            else
-                            {
-                                [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Save Portfolio" controller:self] ;
-                            }
-                        }];
                         
+                        AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
                         
+                        NSString* url = [editor_json valueForKey:@"pdf_path"];
+                        NSString* path = [editor_json valueForKey:@"pdf_real_path"];
+                        bool isLocalFile = [[editor_json valueForKey:@"isLocalFile"] boolValue];
+                        RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
+                        ViewController.url = url;
+                        ViewController.canSave = true;
+                        ViewController.isLocalfile=isLocalFile;
                         
+                        ViewController.filename = [NSString stringWithFormat:@"%@.pdf",[TextUtils legalFilename:catelog_name]];
+                        ViewController.save_name =catelog_name;
+                        ViewController.save_note =internal_note;
                         
-                    }];
-                    
-                    //                    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-                    //
-                    //
-                    //#ifdef OFFLINE_MODE
-                    //                        if (appDelegate.offline_mode)
-                    //                        {
-                    //                            [params setValue:url forKey:@"pdfPath"];
-                    //                        }
-                    //                        else
-                    //#endif
-                    //                        {
-                    //                            [params setValue:path forKey:@"pdfPath"];
-                    //                        }
-                    //                        [params setValue:name forKey:@"pdfName"];
-                    //                        [params setValue:internal_note forKey:@"pdfNote"];
-                    //                        [params setValue:del_ids forKey:@"itemIds"];
-                    //                        [params setValue:pdf_url forKey:@"configureParams"];
-                    //
-                    //
-                    //
-                    //                        NSDictionary* json = [RANetwork save_TearSheet:params];
-                    //
-                    //                        dispatch_async(dispatch_get_main_queue(), ^{
-                    //                            [waitalert dismissViewControllerAnimated:YES completion:nil];
-                    //
-                    //
-                    //                            if([[json valueForKey:@"result"] intValue]==2)
-                    //                            {
-                    //
-                    //                                [RAUtils message_alert:@"Portfolio saved. You can find it from View Portfolios" title:@"Portfolio" controller:self];
-                    //
-                    ////                                [RAUtils alert_view:nil title:@"Portfolio saved. You can find it from View Portfolios" ] ;
-                    //
-                    //                                [self.navigationController dismissViewControllerAnimated:true completion:^{
-                    //
-                    //
-                    //
-                    //#ifdef RA_NOTIFICATION
-                    //                                    [ActiveViewController Notify:@"PortfolioViewController,PDFListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-                    //#else
-                    //                                    [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
-                    //                                    [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
-                    //#endif
-                    //                                }];
-                    //                            }
-                    //                            else
-                    //                            {
-                    //                                [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Save Portfolio" controller:self] ;
-                    //                            }
-                    //
-                    //                        });
-                    //                    });
-                    
-                    
-                    
-                };
+                        NSString* company=    [appDelegate.customerInfo valueForKey:@"customer_name"];
+                        
+                        if(company==nil)
+                            company=@"";
+                        
+                        NSString* customer_email=    [appDelegate.customerInfo valueForKey:@"customer_email"];
+                        
+                        
+                        NSMutableArray* send_to = [[NSMutableArray alloc]init];
+                        if(customer_email.length>0)
+                        {
+                            send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
+                        }
+                        ViewController.mail_to = send_to;
+                        
+                        NSString* subject;
+                        
+                        subject =catelog_name;
+                        
+                        ViewController.mail_subject = subject;
+                        
+                        ViewController.onSavePDF=^(NSString* name,NSString* file)
+                        {
+                            
+                            
+                            NSString* del_ids = nil;
+                            #ifdef OFFLINE_MODE
+                                                if (appDelegate.offline_mode)
+                                                {
+                                                    [params setValue:url forKey:@"pdfPath"];
+                                                }
+                                                else
+                            #endif
+                                                {
+                                                    [params setValue:path forKey:@"pdfPath"];
+                                                }
+                                                [params setValue:name forKey:@"pdfName"];
+                                                [params setValue:internal_note forKey:@"pdfNote"];
+                                                [params setValue:del_ids forKey:@"itemIds"];
+                                                [params setValue:pdf_url forKey:@"configureParams"];
+                            __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving..." completion:^{
+                                [RANetwork request_save_portfolio:params completionHandler:^(NSMutableDictionary *result) {
+                                                        NSDictionary* json =result;
+                                                        [waitalert dismissViewControllerAnimated:YES completion:^{
+                                                            if([[json valueForKey:@"result"] intValue]==2)
+                                                            {
+                                                                
+                                                                [RAUtils message_alert:@"Portfolio saved. You can find it from View Portfolios" title:@"Portfolio" controller:self];
+                                                                
+                                                                //                                [RAUtils alert_view:nil title:@"Portfolio saved. You can find it from View Portfolios" ] ;
+                                                                
+                                                                [self.navigationController dismissViewControllerAnimated:true completion:^{
+                                                                    
+                                                                    
+                                                                    
+                                #ifdef RA_NOTIFICATION
+                                                                    [ActiveViewController Notify:@"PortfolioViewController,PDFListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+                                #else
+                                                                    [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
+                                                                    [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
+                                #endif
+                                                                }];
+                                                            }
+                                                            else
+                                                            {
+                                                                [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Save Portfolio" controller:self] ;
+                                                            }
+                                                        }];
+                                                        
+                                                        
+                                                        
+                                                        
+                                                    }];
+
+                            }];
+                            
+
+                            
+                                                        
+                            //                    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+                            //
+                            //
+                            //#ifdef OFFLINE_MODE
+                            //                        if (appDelegate.offline_mode)
+                            //                        {
+                            //                            [params setValue:url forKey:@"pdfPath"];
+                            //                        }
+                            //                        else
+                            //#endif
+                            //                        {
+                            //                            [params setValue:path forKey:@"pdfPath"];
+                            //                        }
+                            //                        [params setValue:name forKey:@"pdfName"];
+                            //                        [params setValue:internal_note forKey:@"pdfNote"];
+                            //                        [params setValue:del_ids forKey:@"itemIds"];
+                            //                        [params setValue:pdf_url forKey:@"configureParams"];
+                            //
+                            //
+                            //
+                            //                        NSDictionary* json = [RANetwork save_TearSheet:params];
+                            //
+                            //                        dispatch_async(dispatch_get_main_queue(), ^{
+                            //                            [waitalert dismissViewControllerAnimated:YES completion:nil];
+                            //
+                            //
+                            //                            if([[json valueForKey:@"result"] intValue]==2)
+                            //                            {
+                            //
+                            //                                [RAUtils message_alert:@"Portfolio saved. You can find it from View Portfolios" title:@"Portfolio" controller:self];
+                            //
+                            ////                                [RAUtils alert_view:nil title:@"Portfolio saved. You can find it from View Portfolios" ] ;
+                            //
+                            //                                [self.navigationController dismissViewControllerAnimated:true completion:^{
+                            //
+                            //
+                            //
+                            //#ifdef RA_NOTIFICATION
+                            //                                    [ActiveViewController Notify:@"PortfolioViewController,PDFListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+                            //#else
+                            //                                    [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
+                            //                                    [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
+                            //#endif
+                            //                                }];
+                            //                            }
+                            //                            else
+                            //                            {
+                            //                                [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Save Portfolio" controller:self] ;
+                            //                            }
+                            //
+                            //                        });
+                            //                    });
+                            
+                            
+                            
+                        };
+                        
+                        ViewController.hidenavi = false;
+                        [self.navigationController pushViewController:ViewController animated:YES];
+                        
+                    }
+                    else
+                    {
+                        [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Portfolio" controller:self] ;
+                    }
+                }];
                 
-                ViewController.hidenavi = false;
-                [self.navigationController pushViewController:ViewController animated:YES];
                 
-            }
-            else
-            {
-                [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Portfolio" controller:self] ;
-            }
-        }];
-        
-        
 
 
-        
+                
+            }];
+
     }];
-    
+        
 //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //        NSDictionary* editor_json = [RANetwork request_TearSheet:params];
@@ -1173,76 +1180,78 @@
             vc.onSetValue = ^(int qty,double qty_p, double price, double discount , NSString* notes){
                 
                 
-                UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Updating Quantity"];
-                
-                [RANetwork request_update_portfolio_price:[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"item_id"] intValue]] price:price discount:discount QTY:qty  qty_p:qty_p notes:notes completionHandler:^(NSMutableDictionary *result) {
-                    NSDictionary* cart_json = result;
-                    [waitalert dismissViewControllerAnimated:YES completion:^{
-                        if([[cart_json valueForKey:@"result"] intValue]==2)
-                        {
-                            //                            if(qty>=0)
-                            //                                item_json[@"available_qty"]=[NSNumber numberWithInt:qty];
-                            //                            else
-                            //                                [item_json removeObjectForKey:@"available_qty"];
-                            //                            if(qty_p>=0)
-                            //                                item_json[@"available_percent"]=[NSNumber numberWithInt:qty_p];
-                            //                            else
-                            //                                [item_json removeObjectForKey:@"available_percent"];
-                            //                            item_json[@"linenotes"]=notes;
-                            //                            item_json[@"tear_sheet_discount"]=[NSString stringWithFormat:@"%.2f",discount];
-                            //                            item_json[@"tear_sheet_price"]=[NSString stringWithFormat:@"%.2f",price];
-                            //                            self.content_data[[NSString stringWithFormat:@"item_%d",single_idx]]=item_json;
-                            //                            // item_json[@"available_qty"]=[NSNumber numberWithInt:qty];
-                            //                            [self.itemListTable reloadData];
-                            
-                            
-                            if (!(qty == -INT32_MAX && qty_p == -MAXFLOAT)) {
-                                // qty
-                                if (qty != -INT32_MAX)
-                                    item_json[@"available_qty"]=[NSNumber numberWithInt:qty];
-                                else
-                                    [item_json removeObjectForKey:@"available_qty"];
+               __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Updating Quantity" completion:^{
+                    [RANetwork request_update_portfolio_price:[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"item_id"] intValue]] price:price discount:discount QTY:qty  qty_p:qty_p notes:notes completionHandler:^(NSMutableDictionary *result) {
+                        NSDictionary* cart_json = result;
+                        [waitalert dismissViewControllerAnimated:YES completion:^{
+                            if([[cart_json valueForKey:@"result"] intValue]==2)
+                            {
+                                //                            if(qty>=0)
+                                //                                item_json[@"available_qty"]=[NSNumber numberWithInt:qty];
+                                //                            else
+                                //                                [item_json removeObjectForKey:@"available_qty"];
+                                //                            if(qty_p>=0)
+                                //                                item_json[@"available_percent"]=[NSNumber numberWithInt:qty_p];
+                                //                            else
+                                //                                [item_json removeObjectForKey:@"available_percent"];
+                                //                            item_json[@"linenotes"]=notes;
+                                //                            item_json[@"tear_sheet_discount"]=[NSString stringWithFormat:@"%.2f",discount];
+                                //                            item_json[@"tear_sheet_price"]=[NSString stringWithFormat:@"%.2f",price];
+                                //                            self.content_data[[NSString stringWithFormat:@"item_%d",single_idx]]=item_json;
+                                //                            // item_json[@"available_qty"]=[NSNumber numberWithInt:qty];
+                                //                            [self.itemListTable reloadData];
+                                
+                                
+                                if (!(qty == -INT32_MAX && qty_p == -MAXFLOAT)) {
+                                    // qty
+                                    if (qty != -INT32_MAX)
+                                        item_json[@"available_qty"]=[NSNumber numberWithInt:qty];
+                                    else
+                                        [item_json removeObjectForKey:@"available_qty"];
+                                    
+                                    // qty_p
+                                    if (qty_p != -MAXFLOAT)
+                                        item_json[@"available_percent"]=[NSNumber numberWithInt:qty_p];
+                                    else
+                                        [item_json removeObjectForKey:@"available_percent"];
+                                }
+                                
+                                if (notes) {
+                                    item_json[@"linenotes"]=notes;
+                                }
+                                
+                                if (discount != -MAXFLOAT) {
+                                    item_json[@"tear_sheet_discount"]=[NSString stringWithFormat:@"%.2f",discount];
+                                }
+                                
+                                if (price != -MAXFLOAT) {
+                                    item_json[@"tear_sheet_price"]=[NSString stringWithFormat:@"%.2f",price];
+                                }
+                                
+                                self.content_data[[NSString stringWithFormat:@"item_%d",single_idx]]=item_json;
+                                // item_json[@"available_qty"]=[NSNumber numberWithInt:qty];
+                                
+                                [self.itemListTable reloadData];
                                 
-                                // qty_p
-                                if (qty_p != -MAXFLOAT)
-                                    item_json[@"available_percent"]=[NSNumber numberWithInt:qty_p];
-                                else
-                                    [item_json removeObjectForKey:@"available_percent"];
-                            }
-                            
-                            if (notes) {
-                                item_json[@"linenotes"]=notes;
-                            }
-                            
-                            if (discount != -MAXFLOAT) {
-                                item_json[@"tear_sheet_discount"]=[NSString stringWithFormat:@"%.2f",discount];
                             }
-                            
-                            if (price != -MAXFLOAT) {
-                                item_json[@"tear_sheet_price"]=[NSString stringWithFormat:@"%.2f",price];
+                            else
+                            {
+                                [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Edit Portfolio" controller:self] ;
                             }
-                            
-                            self.content_data[[NSString stringWithFormat:@"item_%d",single_idx]]=item_json;
-                            // item_json[@"available_qty"]=[NSNumber numberWithInt:qty];
-                            
-                            [self.itemListTable reloadData];
-                            
-                        }
-                        else
-                        {
-                            [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Edit Portfolio" controller:self] ;
-                        }
+                        }];
+                        
+                        
+                        
+
+                        
+                        
+                        
+                        
                     }];
-                    
-                    
-                    
 
-                    
-                    
-                    
-                    
                 }];
                 
+                                
 //                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //                    NSDictionary* cart_json = nil;
@@ -1381,29 +1390,31 @@
         vc.onSetValue = ^(int qty,double qty_p,double price, double discount , NSString* notes){
             
             
-            UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Updating Quantity"];
-            [RANetwork request_update_portfolio_price:ids price:price discount:discount QTY:qty qty_p:qty_p notes:notes completionHandler:^(NSMutableDictionary *result) {
-                NSDictionary* cart_json = result;
-                [waitalert dismissViewControllerAnimated:YES completion:^{
-                    if([[cart_json valueForKey:@"result"] intValue]==2)
-                    {
-                        [RAUtils message_alert:[NSString stringWithFormat:@"%ld items saved.",checked.count] title:@"Edit Portfolio" controller:self] ;
-                        [self reload_data];
-                    }
-                    else
-                    {
-                        [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Edit Portfolio" controller:self] ;
-                    }
+            __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Updating Quantity" completion:^{
+                [RANetwork request_update_portfolio_price:ids price:price discount:discount QTY:qty qty_p:qty_p notes:notes completionHandler:^(NSMutableDictionary *result) {
+                    NSDictionary* cart_json = result;
+                    [waitalert dismissViewControllerAnimated:YES completion:^{
+                        if([[cart_json valueForKey:@"result"] intValue]==2)
+                        {
+                            [RAUtils message_alert:[NSString stringWithFormat:@"%ld items saved.",checked.count] title:@"Edit Portfolio" controller:self] ;
+                            [self reload_data];
+                        }
+                        else
+                        {
+                            [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Edit Portfolio" controller:self] ;
+                        }
+                    }];
+                    
+                    
+
+                    
+                    
+                    
+                    
                 }];
-                
-                
 
-                
-                
-                
-                
             }];
-            
+                        
 //            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //                NSDictionary* cart_json = nil;
@@ -2020,62 +2031,64 @@
         vc.onSetValue = ^(int qty,double qty_p, double price, double discount , NSString* notes){
             
             
-            UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Updating Quantity"];
-            
-            [RANetwork request_update_portfolio_price:[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"item_id"] intValue]] price:price discount:discount QTY:qty  qty_p:qty_p notes:notes completionHandler:^(NSMutableDictionary *result) {
-                
-                NSDictionary* cart_json = result;
-                [waitalert dismissViewControllerAnimated:YES completion:^{
-                    if([[cart_json valueForKey:@"result"] intValue]==2)
-                    {
-                        self.editedRow = indexPath.row;
-                        
-                        if (!(qty == -INT32_MAX && qty_p == -MAXFLOAT)) {
-                            // qty
-                            if (qty != -INT32_MAX)
-                                item_json[@"available_qty"]=[NSNumber numberWithInt:qty];
-                            else
-                                [item_json removeObjectForKey:@"available_qty"];
+            __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Updating Quantity" completion:^{
+                [RANetwork request_update_portfolio_price:[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"item_id"] intValue]] price:price discount:discount QTY:qty  qty_p:qty_p notes:notes completionHandler:^(NSMutableDictionary *result) {
+                    
+                    NSDictionary* cart_json = result;
+                    [waitalert dismissViewControllerAnimated:YES completion:^{
+                        if([[cart_json valueForKey:@"result"] intValue]==2)
+                        {
+                            self.editedRow = indexPath.row;
                             
-                            // qty_p
-                            if (qty_p != -MAXFLOAT)
-                                item_json[@"available_percent"]=[NSNumber numberWithInt:qty_p];
-                            else
-                                [item_json removeObjectForKey:@"available_percent"];
-                        }
-                        
-                        if (notes) {
-                            item_json[@"linenotes"]=notes;
-                        }
-                        
-                        if (discount != -MAXFLOAT) {
-                            item_json[@"tear_sheet_discount"]=[NSString stringWithFormat:@"%.2f",discount];
+                            if (!(qty == -INT32_MAX && qty_p == -MAXFLOAT)) {
+                                // qty
+                                if (qty != -INT32_MAX)
+                                    item_json[@"available_qty"]=[NSNumber numberWithInt:qty];
+                                else
+                                    [item_json removeObjectForKey:@"available_qty"];
+                                
+                                // qty_p
+                                if (qty_p != -MAXFLOAT)
+                                    item_json[@"available_percent"]=[NSNumber numberWithInt:qty_p];
+                                else
+                                    [item_json removeObjectForKey:@"available_percent"];
+                            }
+                            
+                            if (notes) {
+                                item_json[@"linenotes"]=notes;
+                            }
+                            
+                            if (discount != -MAXFLOAT) {
+                                item_json[@"tear_sheet_discount"]=[NSString stringWithFormat:@"%.2f",discount];
+                            }
+                            
+                            if (price != -MAXFLOAT) {
+                                item_json[@"tear_sheet_price"]=[NSString stringWithFormat:@"%.2f",price];
+                            }
+                            
+                            self.content_data[[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]]=item_json;
+                            // item_json[@"available_qty"]=[NSNumber numberWithInt:qty];
+                            self.indexPath=indexPath;
+                            [self.itemListTable reloadData];
                         }
-                        
-                        if (price != -MAXFLOAT) {
-                            item_json[@"tear_sheet_price"]=[NSString stringWithFormat:@"%.2f",price];
+                        else
+                        {
+                            [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Edit Portfolio" controller:self] ;
                         }
-                        
-                        self.content_data[[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]]=item_json;
-                        // item_json[@"available_qty"]=[NSNumber numberWithInt:qty];
-                        self.indexPath=indexPath;
-                        [self.itemListTable reloadData];
-                    }
-                    else
-                    {
-                        [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Edit Portfolio" controller:self] ;
-                    }
+                    }];
+                    
+                    
+                    
+
+                    
+                    
+                    
+                    
                 }];
-                
-                
-                
 
-                
-                
-                
-                
             }];
             
+                        
 //            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //                NSDictionary* cart_json = nil;

+ 264 - 258
RedAnt ERP Mobile/common/Functions/portfolio/TearSheetParamViewController.m

@@ -284,230 +284,234 @@
     
     
     
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Processing"];
-    [RANetwork request_portfoliopreview:upparams completionHandler:^(NSMutableDictionary *result) {
-        NSDictionary* editor_json = result;
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Processing" completion:^{
+        [RANetwork request_portfoliopreview:upparams completionHandler:^(NSMutableDictionary *result) {
+                NSDictionary* editor_json = result;
 
-        //            [waitalert dismissViewControllerAnimated:YES completion:nil];
-        [waitalert dismissViewControllerAnimated:YES completion:^{
-            if([[editor_json valueForKey:@"result"] intValue]==2)
-            {
-                //                    NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
-                
-                AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                
-                NSString* url = [editor_json valueForKey:@"pdf_path"];
-                NSString* path = [editor_json valueForKey:@"pdf_real_path"];
-                bool isLocalFile = [[editor_json valueForKey:@"isLocalFile"] boolValue];
-                RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
-                ViewController.url = url;
-                ViewController.canSave = true;
-                ViewController.isLocalfile=isLocalFile;
-                //                    ViewController.mail_content = [self.content_data valueForKey:@"email_content"];
-                ViewController.filename = [NSString stringWithFormat:@"%@.pdf",[TextUtils legalFilename:catelog_name]];
-                ViewController.save_name =catelog_name;
-                ViewController.save_note =internal_note;
-                //ViewController.filename = catelog_name;
-                NSString* company=    [appDelegate.customerInfo valueForKey:@"customer_name"];
-                
-                if(company==nil)
-                    company=@"";
-                //                    NSString* customer_email=    [appDelegate.customerInfo valueForKey:@"customer_email"];
-                
-                
-                //                    NSMutableArray* send_to = [[NSMutableArray alloc]init];
-                //                    if(customer_email.length>0)
-                //                        [send_to addObject:customer_email];
-                //                    ViewController.mail_to = send_to;
-                
-                
-                
-                //  AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                NSString* customer_email=    [appDelegate.customerInfo valueForKey:@"customer_email"];
-                
-                
-                NSMutableArray* send_to = [[NSMutableArray alloc]init];
-                if(customer_email.length>0)
-                {
-                    send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
-                    //                            customer_email compo
-                    //                            [send_to addObject:customer_email];
-                }
-                ViewController.mail_to = send_to;
-                
-                NSString* subject;
-                //                    if (company.length==0) {
-                
-                //         NSString* cur_time =[RAUtils current_date];
-                subject =catelog_name;//[NSString stringWithFormat:@"NPD Product List %@",cur_time];
-                
-                
-                
-                //                    }
-                //                    else
-                //                    {
-                //                        subject = [NSString stringWithFormat:@"Tear sheet for %@",company ];
-                //                    }
-                //                ViewController.attachment_name = [NSString stringWithFormat:@"%@.pdf",catelog_name];//[NSString stringWithFormat:@"NPD_Product_List %@.pdf",cur_time];
-                ViewController.mail_subject = subject;
-                
-                //                    ViewController.onLoadSuccess =^(NSString* url)
-                //                    {
-                //
-                //                    };
-                
-                
-                ViewController.onSavePDF=^(NSString* name,NSString* file)
-                {
-                    
-                    
-                    NSString* del_ids = nil;
-                    if(bremove)
-                        del_ids=[self.params valueForKey:@"item_ids"];
-                    
-                    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving..."];
-                    
-                    
-#ifdef OFFLINE_MODE
-                    if (appDelegate.offline_mode)
-                    {
-                        [upparams setValue:url forKey:@"pdfPath"];
-                    }
-                    else
-#endif
+                //            [waitalert dismissViewControllerAnimated:YES completion:nil];
+                [waitalert dismissViewControllerAnimated:YES completion:^{
+                    if([[editor_json valueForKey:@"result"] intValue]==2)
                     {
-                        [upparams setValue:path forKey:@"pdfPath"];
-                    }
-                    [upparams setValue:name forKey:@"pdfName"];
-                    [upparams setValue:internal_note forKey:@"pdfNote"];
-                    [upparams setValue:del_ids forKey:@"itemIds"];
-                    [upparams setValue:pdf_url forKey:@"configureParams"];
-                    
-                    [RANetwork request_save_portfolio:upparams completionHandler:^(NSMutableDictionary *result) {
+                        //                    NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
                         
-                        NSDictionary* json =result;
-                        [waitalert dismissViewControllerAnimated:YES completion:^{
-                            if([[json valueForKey:@"result"] intValue]==2)
-                            {
-                                [RAUtils message_alert:@"Portfolio saved. You can find it from View Portfolios" title:@"Portfolio" controller:self];
-                                //                                [RAUtils alert_view:nil title: ] ;
-                                
-                                [self.navigationController dismissViewControllerAnimated:true completion:^{
-                                    
-                                    
-                                    
-#ifdef RA_NOTIFICATION
-                                    [ActiveViewController Notify:@"PortfolioViewController,PDFListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-#else
-                                    [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
-                                    [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
-#endif
-                                    //                                            if(self.onDismiss)
-                                    //                                                self.onDismiss(catelog_name);
-                                }];
-                            }
-                            else
-                            {
-                                [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Save Portfolio" controller:self] ;
-                            }
-                        }];
+                        AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
                         
+                        NSString* url = [editor_json valueForKey:@"pdf_path"];
+                        NSString* path = [editor_json valueForKey:@"pdf_real_path"];
+                        bool isLocalFile = [[editor_json valueForKey:@"isLocalFile"] boolValue];
+                        RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
+                        ViewController.url = url;
+                        ViewController.canSave = true;
+                        ViewController.isLocalfile=isLocalFile;
+                        //                    ViewController.mail_content = [self.content_data valueForKey:@"email_content"];
+                        ViewController.filename = [NSString stringWithFormat:@"%@.pdf",[TextUtils legalFilename:catelog_name]];
+                        ViewController.save_name =catelog_name;
+                        ViewController.save_note =internal_note;
+                        //ViewController.filename = catelog_name;
+                        NSString* company=    [appDelegate.customerInfo valueForKey:@"customer_name"];
                         
+                        if(company==nil)
+                            company=@"";
+                        //                    NSString* customer_email=    [appDelegate.customerInfo valueForKey:@"customer_email"];
                         
                         
-                    }];
-                    
-                    
-                    //                    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-                    //
-                    //
-                    //#ifdef OFFLINE_MODE
-                    //                        if (appDelegate.offline_mode)
-                    //                        {
-                    //                            [upparams setValue:url forKey:@"pdfPath"];
-                    //                        }
-                    //                        else
-                    //#endif
-                    //                        {
-                    //                            [upparams setValue:path forKey:@"pdfPath"];
-                    //                        }
-                    //                        [upparams setValue:name forKey:@"pdfName"];
-                    //                        [upparams setValue:internal_note forKey:@"pdfNote"];
-                    //                        [upparams setValue:del_ids forKey:@"itemIds"];
-                    //                        [upparams setValue:pdf_url forKey:@"configureParams"];
-                    //
-                    //
-                    //
-                    //                        NSDictionary* json = [RANetwork save_TearSheet:upparams];
-                    //
-                    //                        dispatch_async(dispatch_get_main_queue(), ^{
-                    //                            [waitalert dismissViewControllerAnimated:YES completion:nil];
-                    //
-                    //
-                    //                            if([[json valueForKey:@"result"] intValue]==2)
-                    //                            {
-                    //                                [RAUtils message_alert:@"Portfolio saved. You can find it from View Portfolios" title:@"Portfolio" controller:self];
-                    ////                                [RAUtils alert_view:nil title: ] ;
-                    //
-                    //                                [self.navigationController dismissViewControllerAnimated:true completion:^{
-                    //
-                    //
-                    //
-                    //#ifdef RA_NOTIFICATION
-                    //                                    [ActiveViewController Notify:@"PortfolioViewController,PDFListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-                    //#else
-                    //                                    [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
-                    //                                     [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
-                    //#endif
-                    //                                    //                                            if(self.onDismiss)
-                    //                                    //                                                self.onDismiss(catelog_name);
-                    //                                }];
-                    //                            }
-                    //                            else
-                    //                            {
-                    //                                [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Save Portfolio" controller:self] ;
-                    //                            }
-                    //
-                    //                        });
-                    //                    });
-                    
-                    
-                    
-                };
-                
-                //    ViewController. = self.function_name;
-                //    ViewController.behavior =BEHAVIOR_SEARCH;
-                ViewController.hidenavi = false;
-                [self.navigationController pushViewController:ViewController animated:YES];
-                //  [[self navigationController] setNavigationBarHidden:NO animated:NO];
-                
-                
-                /*
-                 if(self.return_url)
-                 self.return_url(url,path,bremove);
-                 [self.navigationController dismissViewControllerAnimated:true completion:^{
-                 if(self.onDismiss)
-                 self.onDismiss(catelog_name);
-                 }];
-                 */
-                
-            }
-            else
-            {
-                [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Portfolio" controller:self] ;
-            }
-        }];
+                        //                    NSMutableArray* send_to = [[NSMutableArray alloc]init];
+                        //                    if(customer_email.length>0)
+                        //                        [send_to addObject:customer_email];
+                        //                    ViewController.mail_to = send_to;
+                        
+                        
+                        
+                        //  AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                        NSString* customer_email=    [appDelegate.customerInfo valueForKey:@"customer_email"];
+                        
+                        
+                        NSMutableArray* send_to = [[NSMutableArray alloc]init];
+                        if(customer_email.length>0)
+                        {
+                            send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
+                            //                            customer_email compo
+                            //                            [send_to addObject:customer_email];
+                        }
+                        ViewController.mail_to = send_to;
+                        
+                        NSString* subject;
+                        //                    if (company.length==0) {
+                        
+                        //         NSString* cur_time =[RAUtils current_date];
+                        subject =catelog_name;//[NSString stringWithFormat:@"NPD Product List %@",cur_time];
+                        
+                        
+                        
+                        //                    }
+                        //                    else
+                        //                    {
+                        //                        subject = [NSString stringWithFormat:@"Tear sheet for %@",company ];
+                        //                    }
+                        //                ViewController.attachment_name = [NSString stringWithFormat:@"%@.pdf",catelog_name];//[NSString stringWithFormat:@"NPD_Product_List %@.pdf",cur_time];
+                        ViewController.mail_subject = subject;
+                        
+                        //                    ViewController.onLoadSuccess =^(NSString* url)
+                        //                    {
+                        //
+                        //                    };
+                        
+                        
+                        ViewController.onSavePDF=^(NSString* name,NSString* file)
+                        {
+                            
+                            
+                            NSString* del_ids = nil;
+                            if(bremove)
+                                del_ids=[self.params valueForKey:@"item_ids"];
+                                        
+                            #ifdef OFFLINE_MODE
+                                                if (appDelegate.offline_mode)
+                                                {
+                                                    [upparams setValue:url forKey:@"pdfPath"];
+                                                }
+                                                else
+                            #endif
+                                                {
+                                                    [upparams setValue:path forKey:@"pdfPath"];
+                                                }
+                                                [upparams setValue:name forKey:@"pdfName"];
+                                                [upparams setValue:internal_note forKey:@"pdfNote"];
+                                                [upparams setValue:del_ids forKey:@"itemIds"];
+                                                [upparams setValue:pdf_url forKey:@"configureParams"];
+                            __block UIAlertController * waitalert_save = [RAUtils waiting_alert:self title:@"Saving..." completion:^{
+                                [RANetwork request_save_portfolio:upparams completionHandler:^(NSMutableDictionary *result) {
+                                                        
+                                                        NSDictionary* json =result;
+                                                        [waitalert_save dismissViewControllerAnimated:YES completion:^{
+                                                            if([[json valueForKey:@"result"] intValue]==2)
+                                                            {
+                                                                [RAUtils message_alert:@"Portfolio saved. You can find it from View Portfolios" title:@"Portfolio" controller:self];
+                                                                //                                [RAUtils alert_view:nil title: ] ;
+                                                                
+                                                                [self.navigationController dismissViewControllerAnimated:true completion:^{
+                                                                    
+                                                                    
+                                                                    
+                                #ifdef RA_NOTIFICATION
+                                                                    [ActiveViewController Notify:@"PortfolioViewController,PDFListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+                                #else
+                                                                    [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
+                                                                    [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
+                                #endif
+                                                                    //                                            if(self.onDismiss)
+                                                                    //                                                self.onDismiss(catelog_name);
+                                                                }];
+                                                            }
+                                                            else
+                                                            {
+                                                                [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Save Portfolio" controller:self] ;
+                                                            }
+                                                        }];
+                                                        
+                                                        
+                                                        
+                                                        
+                                                    }];
+
+                            }];
+                            
+        
+                            
+                                                        
+                            
+                            //                    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+                            //
+                            //
+                            //#ifdef OFFLINE_MODE
+                            //                        if (appDelegate.offline_mode)
+                            //                        {
+                            //                            [upparams setValue:url forKey:@"pdfPath"];
+                            //                        }
+                            //                        else
+                            //#endif
+                            //                        {
+                            //                            [upparams setValue:path forKey:@"pdfPath"];
+                            //                        }
+                            //                        [upparams setValue:name forKey:@"pdfName"];
+                            //                        [upparams setValue:internal_note forKey:@"pdfNote"];
+                            //                        [upparams setValue:del_ids forKey:@"itemIds"];
+                            //                        [upparams setValue:pdf_url forKey:@"configureParams"];
+                            //
+                            //
+                            //
+                            //                        NSDictionary* json = [RANetwork save_TearSheet:upparams];
+                            //
+                            //                        dispatch_async(dispatch_get_main_queue(), ^{
+                            //                            [waitalert dismissViewControllerAnimated:YES completion:nil];
+                            //
+                            //
+                            //                            if([[json valueForKey:@"result"] intValue]==2)
+                            //                            {
+                            //                                [RAUtils message_alert:@"Portfolio saved. You can find it from View Portfolios" title:@"Portfolio" controller:self];
+                            ////                                [RAUtils alert_view:nil title: ] ;
+                            //
+                            //                                [self.navigationController dismissViewControllerAnimated:true completion:^{
+                            //
+                            //
+                            //
+                            //#ifdef RA_NOTIFICATION
+                            //                                    [ActiveViewController Notify:@"PortfolioViewController,PDFListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+                            //#else
+                            //                                    [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
+                            //                                     [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
+                            //#endif
+                            //                                    //                                            if(self.onDismiss)
+                            //                                    //                                                self.onDismiss(catelog_name);
+                            //                                }];
+                            //                            }
+                            //                            else
+                            //                            {
+                            //                                [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Save Portfolio" controller:self] ;
+                            //                            }
+                            //
+                            //                        });
+                            //                    });
+                            
+                            
+                            
+                        };
+                        
+                        //    ViewController. = self.function_name;
+                        //    ViewController.behavior =BEHAVIOR_SEARCH;
+                        ViewController.hidenavi = false;
+                        [self.navigationController pushViewController:ViewController animated:YES];
+                        //  [[self navigationController] setNavigationBarHidden:NO animated:NO];
+                        
+                        
+                        /*
+                         if(self.return_url)
+                         self.return_url(url,path,bremove);
+                         [self.navigationController dismissViewControllerAnimated:true completion:^{
+                         if(self.onDismiss)
+                         self.onDismiss(catelog_name);
+                         }];
+                         */
+                        
+                    }
+                    else
+                    {
+                        [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Portfolio" controller:self] ;
+                    }
+                }];
 
 
 
-        
- 
+                
+         
 
 
 
 
+            }];
+
     }];
-    
+        
 //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //        NSDictionary* editor_json = [RANetwork request_TearSheet:upparams];
@@ -957,57 +961,59 @@
         {
             saveName = name.text;
             self.savebtn.enabled =false;
-            
-            
-            UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Processing"];
             [upparams setValue:pdf_url forKey:@"pdfUrl"];
-            [upparams setValue:saveName forKey:@"pdfName"];
-            [upparams setValue:del_ids forKey:@"itemIds"];
-            [upparams setValue:saveNote forKey:@"pdfNote"];
-            [RANetwork request_save_portfoliodirectly:upparams completionHandler:^(NSMutableDictionary *result) {
-                NSDictionary* editor_json =result;
-                [waitalert dismissViewControllerAnimated:YES completion:^{
-                    if([[editor_json valueForKey:@"result"] intValue]==2)
-                    {
-                        
-                        
-                        
-                        
-                        //   [RAUtils alert_view:nil title:@"Portfolio saved. You can find it from View Portfolios" ] ;
-                        NSString* url = [editor_json valueForKey:@"pdf_path"];
-                        bool isLocalFile = [editor_json valueForKey:@"isLocalFile"];
-                        [self.navigationController dismissViewControllerAnimated:true completion:^{
-                            
-                            
-                            
-#ifdef RA_NOTIFICATION
-                            [ActiveViewController Notify:@"PortfolioViewController,PDFListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-#else
-                            AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                            [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
-                            [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
-                            
-#endif
-                            
-                            if(self.onSaved)
-                                self.onSaved(url,saveName,isLocalFile);
-                        }];
-                        
-                    }
-                    else
-                    {
-                        [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Portfolio" controller:self] ;
-                    }
-                }];
-                
-                
-                
-                
-                
-                
-                
-            }];
+                       [upparams setValue:saveName forKey:@"pdfName"];
+                       [upparams setValue:del_ids forKey:@"itemIds"];
+                       [upparams setValue:saveNote forKey:@"pdfNote"];
             
+            __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Processing" completion:^{
+                [RANetwork request_save_portfoliodirectly:upparams completionHandler:^(NSMutableDictionary *result) {
+                                NSDictionary* editor_json =result;
+                                [waitalert dismissViewControllerAnimated:YES completion:^{
+                                    if([[editor_json valueForKey:@"result"] intValue]==2)
+                                    {
+                                        
+                                        
+                                        
+                                        
+                                        //   [RAUtils alert_view:nil title:@"Portfolio saved. You can find it from View Portfolios" ] ;
+                                        NSString* url = [editor_json valueForKey:@"pdf_path"];
+                                        bool isLocalFile = [editor_json valueForKey:@"isLocalFile"];
+                                        [self.navigationController dismissViewControllerAnimated:true completion:^{
+                                            
+                                            
+                                            
+                #ifdef RA_NOTIFICATION
+                                            [ActiveViewController Notify:@"PortfolioViewController,PDFListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+                #else
+                                            AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                                            [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
+                                            [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
+                                            
+                #endif
+                                            
+                                            if(self.onSaved)
+                                                self.onSaved(url,saveName,isLocalFile);
+                                        }];
+                                        
+                                    }
+                                    else
+                                    {
+                                        [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Portfolio" controller:self] ;
+                                    }
+                                }];
+                                
+                                
+                                
+                                
+                                
+                                
+                                
+                            }];
+
+            }];
+           
+                        
 //            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //

+ 423 - 400
RedAnt ERP Mobile/common/Functions/search+itemsearch/ItemSearchViewController.m

@@ -126,6 +126,19 @@
             }
             
         }
+        else
+        {
+            switch (type) {
+                case 3:
+                    item[@"wish_exists"]=@"true";
+                    break;
+                case 4:
+                    item[@"cart_exists"]=@"true";
+                    break;
+                default:
+                    break;
+            }
+        }
         [item setValue:@"false" forKey:@"checked"];
         
         
@@ -317,6 +330,8 @@
     //    ref.hidden = true;
     [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
     [self.collectionview addSubview:ref];
+    
+    self.collectionview.alwaysBounceVertical = YES;
 }
 -(void)manually_refresh
 {
@@ -1045,59 +1060,61 @@
 -(void) neworder
 {
     
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order"];
-    [RANetwork request_create_order:^(NSMutableDictionary *result) {
-        NSMutableDictionary* return_json = result;
-        
-        [waitalert dismissViewControllerAnimated:YES completion:^{
-            if([[return_json valueForKey:@"result"] intValue]==2)
-            {
-                int result=[[return_json valueForKey:@"result"] intValue];
-                if(result==2)
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order" completion:^{
+        [RANetwork request_create_order:^(NSMutableDictionary *result) {
+            NSMutableDictionary* return_json = result;
+            
+            [waitalert dismissViewControllerAnimated:YES completion:^{
+                if([[return_json valueForKey:@"result"] intValue]==2)
                 {
-                    //successed.
-                    
-                    NSString* order_code = [return_json valueForKey:@"orderCode"];
-                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                    appDelegate.order_code = order_code;
-                    
-                    
-                    [self addtocart];
-                    
-                    
-                    //    [self ReloadData];
-                    
-                    
-                    //                    if(self.shopCartBlock!=nil)
-                    //                    {
-                    //                        UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
-                    //
-                    //
-                    //                        CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
-                    //                        UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
-                    //                        iv.image = img;
-                    //                        //                        [self.contentView addSubview:iv];
-                    //                        self.shopCartBlock(iv);
-                    //
-                    //                    }
-                    
+                    int result=[[return_json valueForKey:@"result"] intValue];
+                    if(result==2)
+                    {
+                        //successed.
+                        
+                        NSString* order_code = [return_json valueForKey:@"orderCode"];
+                        AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                        appDelegate.order_code = order_code;
+                        
+                        
+                        [self addtocart];
+                        
+                        
+                        //    [self ReloadData];
+                        
+                        
+                        //                    if(self.shopCartBlock!=nil)
+                        //                    {
+                        //                        UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
+                        //
+                        //
+                        //                        CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
+                        //                        UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
+                        //                        iv.image = img;
+                        //                        //                        [self.contentView addSubview:iv];
+                        //                        self.shopCartBlock(iv);
+                        //
+                        //                    }
+                        
+                    }
                 }
-            }
-            else
-            {
-                [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
-            }
+                else
+                {
+                    [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
+                }
+            }];
+            
+            
+            
+            
+            
+            
+            
+            
         }];
-        
-        
-        
-        
-        
-        
-        
-        
+
     }];
-//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+    //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //        NSDictionary* return_json = [RANetwork new_Order];
 //
@@ -1284,182 +1301,184 @@
     
     NSString * ids = [checked componentsJoinedByString:@","];
     self.addCartBtn.enabled = false;
-     UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Add Models To Cart"];
-
-    if (self.addAll) {
-        AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
-        
-        [RANetwork request_addall_itemsearch:self.offset limit:20 covertype:self.covertype ctgid:self.ctgid modelname:self.modelname modeldescrip:self.modeldescrip alert:self.alert qty:self.p_QTY available:self.p_available price:self.p_price bestseller:self.p_bestseller orderCode:appDelegate.order_code addTo:@"cart" completionHandler:^(NSMutableDictionary *result) {
-                    NSDictionary* return_json =result;
-            [waitalert dismissViewControllerAnimated:YES completion:^{
-                self.addCartBtn.enabled = true;
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Add Models To Cart" completion:^{
+            if (self.addAll) {
+                AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
                 
-                if([[return_json valueForKey:@"result"] intValue]==2)
-                {
-                    //                int result=[[return_json valueForKey:@"result"] intValue];
-                    //                if(result==2)
-                    //                {
-                    //                    //successed.
-                    
-                    //             NSString* order_code = [return_json valueForKey:@"order_code"];
-                    
-                    //                    appDelegate.order_code = order_code;
-                    //                AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                    //                appDelegate.order_code = order_code;
-                    
-                    
-#ifdef RA_NOTIFICATION
-                    [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-#else
-                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                    [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
-#endif
-                    
-                    
-                    NSString * msg = nil;
-                    
-                    if (self.addAll) {
-                        
-                        unsigned long checkedCount = [return_json[@"count"] integerValue];
-                        
-                        msg=[NSString stringWithFormat:@"%lu items added to Cart",checkedCount];
-                    } else {
-                        
+                [RANetwork request_addall_itemsearch:self.offset limit:20 covertype:self.covertype ctgid:self.ctgid modelname:self.modelname modeldescrip:self.modeldescrip alert:self.alert qty:self.p_QTY available:self.p_available price:self.p_price bestseller:self.p_bestseller orderCode:appDelegate.order_code addTo:@"cart" completionHandler:^(NSMutableDictionary *result) {
+                            NSDictionary* return_json =result;
+                    [waitalert dismissViewControllerAnimated:YES completion:^{
+                        self.addCartBtn.enabled = true;
                         
-                        if(checked.count==1)
+                        if([[return_json valueForKey:@"result"] intValue]==2)
+                        {
+                            //                int result=[[return_json valueForKey:@"result"] intValue];
+                            //                if(result==2)
+                            //                {
+                            //                    //successed.
+                            
+                            //             NSString* order_code = [return_json valueForKey:@"order_code"];
+                            
+                            //                    appDelegate.order_code = order_code;
+                            //                AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                            //                appDelegate.order_code = order_code;
+                            
+                            
+        #ifdef RA_NOTIFICATION
+                            [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+        #else
+                            AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                            [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
+        #endif
+                            
+                            
+                            NSString * msg = nil;
+                            
+                            if (self.addAll) {
+                                
+                                unsigned long checkedCount = [return_json[@"count"] integerValue];
+                                
+                                msg=[NSString stringWithFormat:@"%lu items added to Cart",checkedCount];
+                            } else {
+                                
+                                
+                                if(checked.count==1)
+                                {
+                                    msg=@"1 item added to Cart";
+                                }
+                                else
+                                {
+                                    msg=[NSString stringWithFormat:@"%lu items added to Cart",(unsigned long)checked.count];
+                                }
+                            }
+                            
+                            
+                            [RAUtils message_alert:nil title:msg controller:self] ;
+                            
+                            [self end_select:4];
+                            
+                            
+                            
+                            //                }
+                        }
+                        else  if([[return_json valueForKey:@"result"] intValue]==8)
                         {
-                            msg=@"1 item added to Cart";
+                            
+                            
+        #ifdef RA_NOTIFICATION
+                            [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+        #else
+                            AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                            [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
+                            [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
+        #endif
+                            
+                            [self end_select:4];
+                            [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
                         }
                         else
                         {
-                            msg=[NSString stringWithFormat:@"%lu items added to Cart",(unsigned long)checked.count];
+                            [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
                         }
-                    }
-                    
-                    
-                    [RAUtils message_alert:nil title:msg controller:self] ;
-                    
-                    [self end_select:2];
-                    
-                    
-                    
-                    //                }
-                }
-                else  if([[return_json valueForKey:@"result"] intValue]==8)
-                {
-                    
-                    
-#ifdef RA_NOTIFICATION
-                    [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-#else
-                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                    [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
-                    [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
-#endif
-                    
-                    [self end_select:2];
-                    [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
-                }
-                else
-                {
-                    [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
-                }
-            }];
-                    
-                    
-                    
-                    
-                    
-                    
-                }];
+                    }];
+                            
+                            
+                            
+                            
+                            
+                            
+                        }];
 
-    } else {
-        [RANetwork request_addto_cart_byname:ids withScreen:ScreenCodeParticularCategory completionHandler:^(NSMutableDictionary *result) {
-            NSDictionary* return_json =result;
-            [waitalert dismissViewControllerAnimated:YES completion:^{
-                self.addCartBtn.enabled = true;
-                
-                if([[return_json valueForKey:@"result"] intValue]==2)
-                {
-                    //                int result=[[return_json valueForKey:@"result"] intValue];
-                    //                if(result==2)
-                    //                {
-                    //                    //successed.
-                    
-                    //             NSString* order_code = [return_json valueForKey:@"order_code"];
-                    
-                    //                    appDelegate.order_code = order_code;
-                    //                AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                    //                appDelegate.order_code = order_code;
-                    
-                    
-#ifdef RA_NOTIFICATION
-                    [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-#else
-                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                    [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
-#endif
-                    
-                    
-                    NSString * msg = nil;
-                    
-                    if (self.addAll) {
-                        
-                        unsigned long checkedCount = [return_json[@"count"] integerValue];
-                        
-                        msg=[NSString stringWithFormat:@"%lu items added to Cart",checkedCount];
-                    } else {
-                        
+            } else {
+                [RANetwork request_addto_cart_byname:ids withScreen:ScreenCodeParticularCategory completionHandler:^(NSMutableDictionary *result) {
+                    NSDictionary* return_json =result;
+                    [waitalert dismissViewControllerAnimated:YES completion:^{
+                        self.addCartBtn.enabled = true;
                         
-                        if(checked.count==1)
+                        if([[return_json valueForKey:@"result"] intValue]==2)
+                        {
+                            //                int result=[[return_json valueForKey:@"result"] intValue];
+                            //                if(result==2)
+                            //                {
+                            //                    //successed.
+                            
+                            //             NSString* order_code = [return_json valueForKey:@"order_code"];
+                            
+                            //                    appDelegate.order_code = order_code;
+                            //                AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                            //                appDelegate.order_code = order_code;
+                            
+                            
+        #ifdef RA_NOTIFICATION
+                            [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+        #else
+                            AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                            [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
+        #endif
+                            
+                            
+                            NSString * msg = nil;
+                            
+                            if (self.addAll) {
+                                
+                                unsigned long checkedCount = [return_json[@"count"] integerValue];
+                                
+                                msg=[NSString stringWithFormat:@"%lu items added to Cart",checkedCount];
+                            } else {
+                                
+                                
+                                if(checked.count==1)
+                                {
+                                    msg=@"1 item added to Cart";
+                                }
+                                else
+                                {
+                                    msg=[NSString stringWithFormat:@"%lu items added to Cart",(unsigned long)checked.count];
+                                }
+                            }
+                            
+                            
+                            [RAUtils message_alert:nil title:msg controller:self] ;
+                            
+                            [self end_select:2];
+                            
+                            
+                            
+                            //                }
+                        }
+                        else  if([[return_json valueForKey:@"result"] intValue]==8)
                         {
-                            msg=@"1 item added to Cart";
+                            
+                            
+        #ifdef RA_NOTIFICATION
+                            [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+        #else
+                            AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                            [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
+                            [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
+        #endif
+                            
+                            [self end_select:2];
+                            [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
                         }
                         else
                         {
-                            msg=[NSString stringWithFormat:@"%lu items added to Cart",(unsigned long)checked.count];
+                            [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
                         }
-                    }
-                    
-                    
-                    [RAUtils message_alert:nil title:msg controller:self] ;
+                    }];
                     
-                    [self end_select:2];
                     
                     
                     
-                    //                }
-                }
-                else  if([[return_json valueForKey:@"result"] intValue]==8)
-                {
                     
                     
-#ifdef RA_NOTIFICATION
-                    [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-#else
-                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                    [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
-                    [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
-#endif
-                    
-                    [self end_select:2];
-                    [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
-                }
-                else
-                {
-                    [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
-                }
-            }];
-            
-            
-            
-            
-            
-            
-        }];
-        
-        
-    }
+                }];
+                
+                
+            }
+    }];
+
+
     
 //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
@@ -1598,122 +1617,124 @@
     NSString * ids = [checked componentsJoinedByString:@","];
     self.addPortfolioBtn.enabled =false;
     
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Add Models To Portfolio"];
-    
-            if (self.addAll) {
-                [RANetwork request_addall_itemsearch:self.offset limit:20 covertype:self.covertype ctgid:self.ctgid modelname:self.modelname modeldescrip:self.modeldescrip alert:self.alert qty:self.p_QTY available:self.p_available price:self.p_price bestseller:self.p_bestseller orderCode:nil addTo:@"portfolio" completionHandler:^(NSMutableDictionary *result) {
-                    NSDictionary* return_json = result;
-                    [waitalert dismissViewControllerAnimated:YES completion:^{
-                        self.addPortfolioBtn.enabled =true;
-                        
-                        if([[return_json valueForKey:@"result"] intValue]==2)
-                        {
-                            
-                            
-                            
-                            
-#ifdef RA_NOTIFICATION
-                            [ActiveViewController Notify:@"PortfolioViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-#else
-                            AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                            [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
-#endif
-                            
-                            NSString * msg = nil;
-                            
-                            if (self.addAll) {
-                                
-                                unsigned long checkedCount = [return_json[@"count"] integerValue];
-                                
-                                msg=[NSString stringWithFormat:@"%lu items added to Portfolio",checkedCount];
-                            } else {
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Add Models To Portfolio" completion:^{
+                    if (self.addAll) {
+                        [RANetwork request_addall_itemsearch:self.offset limit:20 covertype:self.covertype ctgid:self.ctgid modelname:self.modelname modeldescrip:self.modeldescrip alert:self.alert qty:self.p_QTY available:self.p_available price:self.p_price bestseller:self.p_bestseller orderCode:nil addTo:@"portfolio" completionHandler:^(NSMutableDictionary *result) {
+                            NSDictionary* return_json = result;
+                            [waitalert dismissViewControllerAnimated:YES completion:^{
+                                self.addPortfolioBtn.enabled =true;
                                 
-                                if(checked.count==1)
+                                if([[return_json valueForKey:@"result"] intValue]==2)
                                 {
-                                    msg=@"1 item added to Portfolio";
+                                    
+                                    
+                                    
+                                    
+        #ifdef RA_NOTIFICATION
+                                    [ActiveViewController Notify:@"PortfolioViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+        #else
+                                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                                    [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
+        #endif
+                                    
+                                    NSString * msg = nil;
+                                    
+                                    if (self.addAll) {
+                                        
+                                        unsigned long checkedCount = [return_json[@"count"] integerValue];
+                                        
+                                        msg=[NSString stringWithFormat:@"%lu items added to Portfolio",checkedCount];
+                                    } else {
+                                        
+                                        if(checked.count==1)
+                                        {
+                                            msg=@"1 item added to Portfolio";
+                                        }
+                                        else
+                                        {
+                                            msg=[NSString stringWithFormat:@"%lu items added to Portfolio",(unsigned long)checked.count];
+                                        }
+                                    }
+                                    
+                                    [RAUtils message_alert:nil title:msg controller:self] ;
+                                    
+                                    
+                                    [self end_select:3];
+                                    
                                 }
                                 else
                                 {
-                                    msg=[NSString stringWithFormat:@"%lu items added to Portfolio",(unsigned long)checked.count];
+                                    [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Portfolio" controller:self] ;
                                 }
-                            }
+                            }];
                             
-                            [RAUtils message_alert:nil title:msg controller:self] ;
                             
                             
-                            [self end_select:3];
-                            
-                        }
-                        else
-                        {
-                            [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Portfolio" controller:self] ;
-                        }
-                    }];
-                    
-                    
-                    
-                    
-                    
-                    
-                }];
-            } else {
-                [RANetwork request_addto_portfolio:ids withScreen:ScreenCodeParticularCategory completionHandler:^(NSMutableDictionary *result) {
-                    NSDictionary* return_json = result;
-                    [waitalert dismissViewControllerAnimated:YES completion:^{
-                        self.addPortfolioBtn.enabled =true;
-                        
-                        if([[return_json valueForKey:@"result"] intValue]==2)
-                        {
                             
                             
                             
-                            
-#ifdef RA_NOTIFICATION
-                            [ActiveViewController Notify:@"PortfolioViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-#else
-                            AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                            [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
-#endif
-                            
-                            NSString * msg = nil;
-                            
-                            if (self.addAll) {
-                                
-                                unsigned long checkedCount = [return_json[@"count"] integerValue];
-                                
-                                msg=[NSString stringWithFormat:@"%lu items added to Portfolio",checkedCount];
-                            } else {
+                        }];
+                    } else {
+                        [RANetwork request_addto_portfolio:ids withScreen:ScreenCodeParticularCategory completionHandler:^(NSMutableDictionary *result) {
+                            NSDictionary* return_json = result;
+                            [waitalert dismissViewControllerAnimated:YES completion:^{
+                                self.addPortfolioBtn.enabled =true;
                                 
-                                if(checked.count==1)
+                                if([[return_json valueForKey:@"result"] intValue]==2)
                                 {
-                                    msg=@"1 item added to Portfolio";
+                                    
+                                    
+                                    
+                                    
+        #ifdef RA_NOTIFICATION
+                                    [ActiveViewController Notify:@"PortfolioViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+        #else
+                                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                                    [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
+        #endif
+                                    
+                                    NSString * msg = nil;
+                                    
+                                    if (self.addAll) {
+                                        
+                                        unsigned long checkedCount = [return_json[@"count"] integerValue];
+                                        
+                                        msg=[NSString stringWithFormat:@"%lu items added to Portfolio",checkedCount];
+                                    } else {
+                                        
+                                        if(checked.count==1)
+                                        {
+                                            msg=@"1 item added to Portfolio";
+                                        }
+                                        else
+                                        {
+                                            msg=[NSString stringWithFormat:@"%lu items added to Portfolio",(unsigned long)checked.count];
+                                        }
+                                    }
+                                    
+                                    [RAUtils message_alert:nil title:msg controller:self] ;
+                                    
+                                    
+                                    [self end_select:3];
+                                    
                                 }
                                 else
                                 {
-                                    msg=[NSString stringWithFormat:@"%lu items added to Portfolio",(unsigned long)checked.count];
+                                    [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Portfolio" controller:self] ;
                                 }
-                            }
+                            }];
                             
-                            [RAUtils message_alert:nil title:msg controller:self] ;
                             
                             
-                            [self end_select:3];
                             
-                        }
-                        else
-                        {
-                            [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Portfolio" controller:self] ;
-                        }
-                    }];
-                    
-                    
-                    
-                    
-                    
-                    
-                }];
-                
-            }
+                            
+                            
+                        }];
+                        
+                    }
+    }];
+    
+
     
     
 //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
@@ -1815,128 +1836,130 @@
     self.addWishBtn.enabled =false;
     
     
-     UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Add Models To Wish List"];
-    
-            if (self.addAll) {
-    
-                [RANetwork request_addall_itemsearch:self.offset limit:20 covertype:self.covertype ctgid:self.ctgid modelname:self.modelname modeldescrip:self.modeldescrip alert:self.alert qty:self.p_QTY available:self.p_available price:self.p_price bestseller:self.p_bestseller orderCode:nil addTo:@"wishlist" completionHandler:^(NSMutableDictionary *result) {
-                    NSDictionary* return_json = result;
-                    [waitalert dismissViewControllerAnimated:YES completion:^{
-                        self.addWishBtn.enabled =true;
-                        
-                        if([[return_json valueForKey:@"result"] intValue]==2)
-                        {
-                            
-                            
-                            
-                            
-                            
-#ifdef RA_NOTIFICATION
-                            [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-#else
-                            AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                            
-                            [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
-#endif
-                            NSString * msg = nil;
-                            
-                            if (self.addAll) {
-                                
-                                unsigned long checkedCount = [return_json[@"count"] integerValue];
-                                
-                                msg=[NSString stringWithFormat:@"%lu items added to \nWish List",checkedCount];
-                            } else {
-                                
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Add Models To Wish List" completion:^{
+        if (self.addAll) {
+            
+                        [RANetwork request_addall_itemsearch:self.offset limit:20 covertype:self.covertype ctgid:self.ctgid modelname:self.modelname modeldescrip:self.modeldescrip alert:self.alert qty:self.p_QTY available:self.p_available price:self.p_price bestseller:self.p_bestseller orderCode:nil addTo:@"wishlist" completionHandler:^(NSMutableDictionary *result) {
+                            NSDictionary* return_json = result;
+                            [waitalert dismissViewControllerAnimated:YES completion:^{
+                                self.addWishBtn.enabled =true;
                                 
-                                if(checked.count==1)
+                                if([[return_json valueForKey:@"result"] intValue]==2)
                                 {
-                                    msg=@"1 item added to \nWish List";
+                                    
+                                    
+                                    
+                                    
+                                    
+        #ifdef RA_NOTIFICATION
+                                    [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+        #else
+                                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                                    
+                                    [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
+        #endif
+                                    NSString * msg = nil;
+                                    
+                                    if (self.addAll) {
+                                        
+                                        unsigned long checkedCount = [return_json[@"count"] integerValue];
+                                        
+                                        msg=[NSString stringWithFormat:@"%lu items added to \nWish List",checkedCount];
+                                    } else {
+                                        
+                                        
+                                        if(checked.count==1)
+                                        {
+                                            msg=@"1 item added to \nWish List";
+                                        }
+                                        else
+                                        {
+                                            msg=[NSString stringWithFormat:@"%lu items added to \nWish List",(unsigned long)checked.count];
+                                        }
+                                    }
+                                    
+                                    [RAUtils message_alert:nil title:msg controller:self] ;
+                                    
+                                    
+                                    [self end_select:3];
+                                    
                                 }
                                 else
                                 {
-                                    msg=[NSString stringWithFormat:@"%lu items added to \nWish List",(unsigned long)checked.count];
+                                    [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Wish List" controller:self] ;
                                 }
-                            }
+                            }];
                             
-                            [RAUtils message_alert:nil title:msg controller:self] ;
                             
                             
-                            [self end_select:1];
                             
-                        }
-                        else
-                        {
-                            [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Wish List" controller:self] ;
-                        }
-                    }];
-                    
-                    
-                    
-                    
-                    
-                }];
+                            
+                        }];
 
-                
-            } else {
-                
-                [RANetwork request_addto_wishlist:ids withScreen:ScreenCodeParticularCategory completionHandler:^(NSMutableDictionary *result) {
-                    NSDictionary* return_json = result;
-                    [waitalert dismissViewControllerAnimated:YES completion:^{
-                        self.addWishBtn.enabled =true;
                         
-                        if([[return_json valueForKey:@"result"] intValue]==2)
-                        {
-                            
-                            
-                            
-                            
-                            
-#ifdef RA_NOTIFICATION
-                            [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-#else
-                            AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                            
-                            [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
-#endif
-                            NSString * msg = nil;
-                            
-                            if (self.addAll) {
-                                
-                                unsigned long checkedCount = [return_json[@"count"] integerValue];
-                                
-                                msg=[NSString stringWithFormat:@"%lu items added to \nWish List",checkedCount];
-                            } else {
-                                
+                    } else {
+                        
+                        [RANetwork request_addto_wishlist:ids withScreen:ScreenCodeParticularCategory completionHandler:^(NSMutableDictionary *result) {
+                            NSDictionary* return_json = result;
+                            [waitalert dismissViewControllerAnimated:YES completion:^{
+                                self.addWishBtn.enabled =true;
                                 
-                                if(checked.count==1)
+                                if([[return_json valueForKey:@"result"] intValue]==2)
                                 {
-                                    msg=@"1 item added to \nWish List";
+                                    
+                                    
+                                    
+                                    
+                                    
+        #ifdef RA_NOTIFICATION
+                                    [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+        #else
+                                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                                    
+                                    [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
+        #endif
+                                    NSString * msg = nil;
+                                    
+                                    if (self.addAll) {
+                                        
+                                        unsigned long checkedCount = [return_json[@"count"] integerValue];
+                                        
+                                        msg=[NSString stringWithFormat:@"%lu items added to \nWish List",checkedCount];
+                                    } else {
+                                        
+                                        
+                                        if(checked.count==1)
+                                        {
+                                            msg=@"1 item added to \nWish List";
+                                        }
+                                        else
+                                        {
+                                            msg=[NSString stringWithFormat:@"%lu items added to \nWish List",(unsigned long)checked.count];
+                                        }
+                                    }
+                                    
+                                    [RAUtils message_alert:nil title:msg controller:self] ;
+                                    
+                                    
+                                    [self end_select:1];
+                                    
                                 }
                                 else
                                 {
-                                    msg=[NSString stringWithFormat:@"%lu items added to \nWish List",(unsigned long)checked.count];
+                                    [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Wish List" controller:self] ;
                                 }
-                            }
+                            }];
                             
-                            [RAUtils message_alert:nil title:msg controller:self] ;
                             
                             
-                            [self end_select:1];
                             
-                        }
-                        else
-                        {
-                            [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Wish List" controller:self] ;
-                        }
-                    }];
-                    
-                    
-                    
-                    
-                    
-                }];
-                
-            }
+                            
+                        }];
+                        
+                    }
+    }];
+    
+            
     
     
 //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
@@ -2611,7 +2634,7 @@
             
             currentSelecteCell.checkImageView.hidden = true;
             if(self.categoryViewType != CATEGORY_VIEWTYPE_LIST)
-                [currentSelecteCell setBackgroundColor: UIColorFromRGB(0x996633)];
+                [currentSelecteCell setBackgroundColor: [UIColor whiteColor]];
             else
                 [currentSelecteCell setBackgroundColor:  [UIColor whiteColor]];
         }

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 474 - 455
RedAnt ERP Mobile/common/Functions/search+itemsearch/SearchViewController.m


+ 31 - 29
RedAnt ERP Mobile/common/Functions/sidemenu/CacheViewController.m

@@ -100,7 +100,36 @@
     
     
     
-    UIAlertController * alert = [RAUtils waiting_alert:self message:@"Deleting..." title:nil];
+    __block UIAlertController * alert = [RAUtils waiting_alert:self message:@"Deleting..." title:nil completion:^{
+         NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
+            NSString *cachefolder = [paths objectAtIndex:0];
+                NSString *img_cache = [cachefolder stringByAppendingPathComponent:@"img_cache"];
+            
+            
+            [RAUtils deletefiles:img_cache];
+            [RAUtils deletefiles: cachefolder];
+            //    DebugLog(@"%@",cachefolder);
+            //     DebugLog(@"%@",img_cache);
+        //    float size=[RAUtils fileSizeForDir:cachefolder];
+        //    // float size1=[RAUtils fileSizeForDir:img_cache];
+        //
+        //    self.sizeLabel.text = [NSString stringWithFormat:@"Cache size: %.2f MB",size];
+        //
+        //    [self.mum stopAnimating];
+            
+            
+            [alert dismissViewControllerAnimated:YES completion:^{
+                //     [alert dismissWithClickedButtonIndex:0 animated:FALSE];
+                
+                [self.mum startAnimating];
+                float size=[RAUtils fileSizeForDir:cachefolder];
+                // float size1=[RAUtils fileSizeForDir:img_cache];
+                
+                self.sizeLabel.text = [NSString stringWithFormat:@"Cache size: %.2f MB",size];
+                
+                [self.mum stopAnimating];
+            }];
+    }];
     
 //    UIAlertView * alert=[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Deleting", nil) message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
     
@@ -114,34 +143,7 @@
 
 
     
-    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
-    NSString *cachefolder = [paths objectAtIndex:0];
-        NSString *img_cache = [cachefolder stringByAppendingPathComponent:@"img_cache"];
-    
-    
-    [RAUtils deletefiles:img_cache];
-    [RAUtils deletefiles: cachefolder];
-    //    DebugLog(@"%@",cachefolder);
-    //     DebugLog(@"%@",img_cache);
-//    float size=[RAUtils fileSizeForDir:cachefolder];
-//    // float size1=[RAUtils fileSizeForDir:img_cache];
-//    
-//    self.sizeLabel.text = [NSString stringWithFormat:@"Cache size: %.2f MB",size];
-//    
-//    [self.mum stopAnimating];
-    
-    
-    [alert dismissViewControllerAnimated:YES completion:^{
-        //     [alert dismissWithClickedButtonIndex:0 animated:FALSE];
-        
-        [self.mum startAnimating];
-        float size=[RAUtils fileSizeForDir:cachefolder];
-        // float size1=[RAUtils fileSizeForDir:img_cache];
-        
-        self.sizeLabel.text = [NSString stringWithFormat:@"Cache size: %.2f MB",size];
-        
-        [self.mum stopAnimating];
-    }];
+   
 
     
 }

+ 171 - 169
RedAnt ERP Mobile/common/Functions/sidemenu/FunctionTestViewController.m

@@ -94,191 +94,193 @@ self.airPrinterController = [UIPrintInteractionController sharedPrintController]
 {
     
     
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"preparing print..."];
-    
-    UIPrintInteractionController* airPrinterController=[UIPrintInteractionController sharedPrintController];
-    UIPrintInfo *printInfo = [UIPrintInfo printInfo];
-    printInfo.outputType = UIPrintInfoOutputGeneral;
-    printInfo.orientation = UIPrintInfoOrientationPortrait;
-    printInfo.jobName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];
-    if(self.filename.length>0)
-        printInfo.jobName = self.filename;
-    airPrinterController.printInfo = printInfo;
-    airPrinterController.printingItem = data;
-    airPrinterController.delegate = self;
-    
-    
-    airPrinterController.showsNumberOfCopies=true;
-    //10.0开始始终显示
-//    airPrinterController.showsPageRange = true;
-    airPrinterController.showsPaperSelectionForLoadedPapers=true;
-    
-    void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
-        if(completed && error)
-        {
-//                        DebugLog(@"Printing failed due to error in domain %@ with error code %lu. Localized description: %@, and failure reason: %@", error.domain, (long)error.code, error.localizedDescription, error.localizedFailureReason);
-        }
-
-    };
-    
-    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-    
-    
-    if(appDelegate.printerURL==nil)
-    {
-        [waitalert dismissViewControllerAnimated:YES completion:nil];
-        if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
-        {
-            UIPrinterPickerController *printPicker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil];
-            //   [printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:yes completionHandler:
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"preparing print..." completion:^{
+            UIPrintInteractionController* airPrinterController=[UIPrintInteractionController sharedPrintController];
+            UIPrintInfo *printInfo = [UIPrintInfo printInfo];
+            printInfo.outputType = UIPrintInfoOutputGeneral;
+            printInfo.orientation = UIPrintInfoOrientationPortrait;
+            printInfo.jobName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];
+            if(self.filename.length>0)
+                printInfo.jobName = self.filename;
+            airPrinterController.printInfo = printInfo;
+            airPrinterController.printingItem = data;
+            airPrinterController.delegate = self;
             
             
+            airPrinterController.showsNumberOfCopies=true;
+            //10.0开始始终显示
+        //    airPrinterController.showsPageRange = true;
+            airPrinterController.showsPaperSelectionForLoadedPapers=true;
             
-            //                 [ printPicker presentFromBarButtonItem:self.btnshare animated:YES completionHandler:
+            void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
+                if(completed && error)
+                {
+        //                        DebugLog(@"Printing failed due to error in domain %@ with error code %lu. Localized description: %@, and failure reason: %@", error.domain, (long)error.code, error.localizedDescription, error.localizedFailureReason);
+                }
+
+            };
             
+            AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
             
             
-            [printPicker presentFromRect:CGRectMake(100, 100, 300, 500) inView:self.view animated:YES completionHandler:
-             
-             
-             
-             //        [printPicker presentAnimated:YES completionHandler:
-             ^(UIPrinterPickerController *printerPicker, BOOL userDidSelect, NSError *error)
-             {
-                 if (userDidSelect)
-                 {
-                     //User selected the item in the UIPrinterPickerController and got the printer details.
-                     
-                     [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printerPicker.selectedPrinter];
-                     
-                     //Here you will get the printer and printer details.ie,
-                     // printerPicker.selectedPrinter, printerPicker.selectedPrinter.displayName, printerPicker.selectedPrinter.URL etc. So you can display the printer name in your label text or button title.
-                     
-                     
-                     
-                     
-                     appDelegate.printerURL =printerPicker.selectedPrinter.URL.absoluteString;
-                     
-                     [self startAirPrintWithData1:data];
-                     
-                 }
-                 else
-                 {
+            if(appDelegate.printerURL==nil)
+            {
+                [waitalert dismissViewControllerAnimated:YES completion:nil];
+                if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
+                {
+                    UIPrinterPickerController *printPicker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil];
+                    //   [printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:yes completionHandler:
+                    
+                    
+                    
+                    //                 [ printPicker presentFromBarButtonItem:self.btnshare animated:YES completionHandler:
+                    
+                    
+                    
+                    [printPicker presentFromRect:CGRectMake(100, 100, 300, 500) inView:self.view animated:YES completionHandler:
                      
                      
-                     //                          AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                     //                          if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
-                     //                          {
-                     //
-                     //                              [((MainViewController*)appDelegate.main_vc) Loginout:false];
-                     //                          }
-                     //                          [self prepareReturn:nil];
                      
-                     //[self.navigationController popViewControllerAnimated:true];
-                 }
-             }];
-        }
-    }
-    else
-    {
-        UIPrinter *airPrinter = [UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL] ];///*self.printer;*/
-        [airPrinter contactPrinter:^(BOOL available)
-         {
-             [waitalert dismissViewControllerAnimated:YES completion:nil];
-             
-             if (available&& appDelegate.printerURL.length>0)
-             {
-                 
-                 
-                 [airPrinterController printToPrinter:airPrinter completionHandler:completionHandler];
-                 DebugLog(@"AIRPRINTER AVAILABLE");
-             }
-             else
-             {
-                 appDelegate.printerURL = nil;
-                 
-                 //             [airPrinterController presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler:
-                 //
-                 //
-                 //
-                 //              //        [printPicker presentAnimated:YES completionHandler:
-                 //              ^(UIPrintInteractionController *printerController, BOOL userDidSelect, NSError *error)
-                 //              {
-                 //                  if (userDidSelect)
-                 //                  {
-                 //                      NSString* sid= printerController.printInfo.printerID;
-                 //                      UIPrintPaper*paper=  printerController.printPaper;
-                 //
-                 //                  }
-                 //              }];
-                 
-                 
-                 DebugLog(@"AIRPRINTER NOT AVAILABLE");
-                 
-                 
-                 
-                 if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
+                     //        [printPicker presentAnimated:YES completionHandler:
+                     ^(UIPrinterPickerController *printerPicker, BOOL userDidSelect, NSError *error)
+                     {
+                         if (userDidSelect)
+                         {
+                             //User selected the item in the UIPrinterPickerController and got the printer details.
+                             
+                             [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printerPicker.selectedPrinter];
+                             
+                             //Here you will get the printer and printer details.ie,
+                             // printerPicker.selectedPrinter, printerPicker.selectedPrinter.displayName, printerPicker.selectedPrinter.URL etc. So you can display the printer name in your label text or button title.
+                             
+                             
+                             
+                             
+                             appDelegate.printerURL =printerPicker.selectedPrinter.URL.absoluteString;
+                             
+                             [self startAirPrintWithData1:data];
+                             
+                         }
+                         else
+                         {
+                             
+                             
+                             //                          AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                             //                          if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
+                             //                          {
+                             //
+                             //                              [((MainViewController*)appDelegate.main_vc) Loginout:false];
+                             //                          }
+                             //                          [self prepareReturn:nil];
+                             
+                             //[self.navigationController popViewControllerAnimated:true];
+                         }
+                     }];
+                }
+            }
+            else
+            {
+                UIPrinter *airPrinter = [UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL] ];///*self.printer;*/
+                [airPrinter contactPrinter:^(BOOL available)
                  {
-                     UIPrinterPickerController *printPicker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil];
-                     //   [printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:yes completionHandler:
-                     
-                     
+                     [waitalert dismissViewControllerAnimated:YES completion:nil];
                      
-                     //                 [ printPicker presentFromBarButtonItem:self.btnshare animated:YES completionHandler:
-                     
-                     
-                     
-                     [printPicker presentFromRect:CGRectMake(100, 100, 300, 500) inView:self.view animated:YES completionHandler:
-                      
-                      
-                      
-                      //        [printPicker presentAnimated:YES completionHandler:
-                      ^(UIPrinterPickerController *printerPicker, BOOL userDidSelect, NSError *error)
-                      {
-                          if (userDidSelect)
-                          {
-                              //User selected the item in the UIPrinterPickerController and got the printer details.
-                              
-                              [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printerPicker.selectedPrinter];
-                              
-                              //Here you will get the printer and printer details.ie,
-                              // printerPicker.selectedPrinter, printerPicker.selectedPrinter.displayName, printerPicker.selectedPrinter.URL etc. So you can display the printer name in your label text or button title.
-                              
-                              
-                              
-                              
-                              appDelegate.printerURL =printerPicker.selectedPrinter.URL.absoluteString;
+                     if (available&& appDelegate.printerURL.length>0)
+                     {
+                         
+                         
+                         [airPrinterController printToPrinter:airPrinter completionHandler:completionHandler];
+                         DebugLog(@"AIRPRINTER AVAILABLE");
+                     }
+                     else
+                     {
+                         appDelegate.printerURL = nil;
+                         
+                         //             [airPrinterController presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler:
+                         //
+                         //
+                         //
+                         //              //        [printPicker presentAnimated:YES completionHandler:
+                         //              ^(UIPrintInteractionController *printerController, BOOL userDidSelect, NSError *error)
+                         //              {
+                         //                  if (userDidSelect)
+                         //                  {
+                         //                      NSString* sid= printerController.printInfo.printerID;
+                         //                      UIPrintPaper*paper=  printerController.printPaper;
+                         //
+                         //                  }
+                         //              }];
+                         
+                         
+                         DebugLog(@"AIRPRINTER NOT AVAILABLE");
+                         
+                         
+                         
+                         if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
+                         {
+                             UIPrinterPickerController *printPicker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil];
+                             //   [printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:yes completionHandler:
+                             
+                             
+                             
+                             //                 [ printPicker presentFromBarButtonItem:self.btnshare animated:YES completionHandler:
+                             
+                             
+                             
+                             [printPicker presentFromRect:CGRectMake(100, 100, 300, 500) inView:self.view animated:YES completionHandler:
                               
-                              [self startAirPrintWithData:data];
                               
-                          }
-                          else
-                          {
-                              appDelegate.printerURL = nil;
                               
-                              //                          AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                              //                          if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
-                              //                          {
-                              //
-                              //                              [((MainViewController*)appDelegate.main_vc) Loginout:false];
-                              //                          }
-                              //                          [self prepareReturn:nil];
-                              
-                              //[self.navigationController popViewControllerAnimated:true];
-                          }
-                      }];
-                 }
-             }
-         }];
-    }
-    
-    
-    
-    
-    
-    
+                              //        [printPicker presentAnimated:YES completionHandler:
+                              ^(UIPrinterPickerController *printerPicker, BOOL userDidSelect, NSError *error)
+                              {
+                                  if (userDidSelect)
+                                  {
+                                      //User selected the item in the UIPrinterPickerController and got the printer details.
+                                      
+                                      [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printerPicker.selectedPrinter];
+                                      
+                                      //Here you will get the printer and printer details.ie,
+                                      // printerPicker.selectedPrinter, printerPicker.selectedPrinter.displayName, printerPicker.selectedPrinter.URL etc. So you can display the printer name in your label text or button title.
+                                      
+                                      
+                                      
+                                      
+                                      appDelegate.printerURL =printerPicker.selectedPrinter.URL.absoluteString;
+                                      
+                                      [self startAirPrintWithData:data];
+                                      
+                                  }
+                                  else
+                                  {
+                                      appDelegate.printerURL = nil;
+                                      
+                                      //                          AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                                      //                          if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
+                                      //                          {
+                                      //
+                                      //                              [((MainViewController*)appDelegate.main_vc) Loginout:false];
+                                      //                          }
+                                      //                          [self prepareReturn:nil];
+                                      
+                                      //[self.navigationController popViewControllerAnimated:true];
+                                  }
+                              }];
+                         }
+                     }
+                 }];
+            }
+            
+            
+            
+            
+            
+            
 
+            
+    }];
     
+
     
     
 }

+ 186 - 165
RedAnt ERP Mobile/common/Functions/sidemenu/LoginViewController.m

@@ -136,6 +136,14 @@
                     
                     [RAUtils message_alert:@"Detected incomplete sync, please finish sync first." title:@"Incomplete sync" controller:self];
 
+                    [defaults removeObjectForKey:@"EnableOfflineMode"];
+                    [defaults setBool:false forKey:@"EnableOfflineMode"];
+                    
+                    [defaults synchronize];
+                    
+                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                    appDelegate.offline_mode = false;
+                    
 //                    [RAUtils alert_view:@"Detected incomplete sync, please finish sync first." title:@"Incomplete sync"];
                 }
                 else
@@ -229,6 +237,16 @@
         
         [RAUtils message_alert:@"Detected incomplete sync, please finish sync first." title:@"Incomplete sync" controller:self];
         
+        [RAUtils message_alert:@"Detected incomplete sync, please finish sync first." title:@"Incomplete sync" controller:self];
+
+        [defaults removeObjectForKey:@"EnableOfflineMode"];
+        [defaults setBool:false forKey:@"EnableOfflineMode"];
+        
+        [defaults synchronize];
+        
+        AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+        appDelegate.offline_mode = false;
+        
 //        [RAUtils alert_view:@"Detected incomplete sync, please finish sync first." title:@"Incomplete sync"];
         return;
     }
@@ -255,213 +273,216 @@
 //    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Sign in"];
     
   
-    UIAlertController* waitalert= [RAUtils waiting_alert:self title:@"Sign in"];
-//        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Sign in" message:@"Please wait..." preferredStyle:UIAlertControllerStyleAlert];
-//        [self presentViewController:alertController animated:YES completion:nil];
-    
-    
-    [RANetwork request_login:user password:password completionHandler:^(NSMutableDictionary *result) {
-        
-        
-        [waitalert dismissViewControllerAnimated:true completion:^{
-            int ret=[result[@"result"] intValue];
-            self.btnLogin.enabled = true;
-            
-            if(ret==RESULT_TRUE)
-                
-            {
+    __block UIAlertController* waitalert= [RAUtils waiting_alert:self title:@"Sign in" completion:^{
+        [RANetwork request_login:user password:password completionHandler:^(NSMutableDictionary *result) {
                 
-                //
-                //                NSString* contactid=[self.content_data[indexPath.row] valueForKey:@"contact_id"] ;
-                AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                //                appDelegate.contact_id=contactid;
-                //                appDelegate.contact_name =[self.content_data[indexPath.row] valueForKey:@"name"];
                 
-                NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
-                [defaults removeObjectForKey:@"user"];
-                [defaults removeObjectForKey:@"password"];
-                NSString* encryptu=[AESCrypt encrypt:appDelegate.user password:@"usai"];
-                NSString* encryptp=[AESCrypt encrypt:self.editpass.text password:@"usai"] ;
-                if(self.checkSavePassword.selected)
-                {
+                [waitalert dismissViewControllerAnimated:true completion:^{
+                    int ret=[result[@"result"] intValue];
+                    self.btnLogin.enabled = true;
                     
-                    [defaults setValue:encryptu forKey:@"user"];
-                    [defaults setValue:encryptp forKey:@"password"];
-                    sqlite3 *db = [iSalesDB get_db];
-                    
-                    int count =[iSalesDB get_recordcount:db table:@"login_info" where:[NSString stringWithFormat:@"name='%@'",encryptu]];
-                    
-                    if(count==0)
-                    {
+                    if(ret==RESULT_TRUE)
                         
-                        NSString * savelogin=[NSString stringWithFormat:@"insert into login_info(name,pwd) values('%@','%@')",encryptu,encryptp];
-                        [iSalesDB execSql:savelogin db:db];
-                    }
-                    else
-                    {
-                        NSString * savelogin=[NSString stringWithFormat:@"update login_info set pwd='%@' where name='%@'",encryptp,encryptu];
-                        [iSalesDB execSql:savelogin db:db];
-                    }
-                    
-                    [iSalesDB close_db:db];
-                    
-                    //                    [defaults setBool:TRUE forKey:@"autologin"];
-                }
-                else
-                {
-                    NSString* sql=[NSString stringWithFormat:@"delete from login_info where name='%@'",encryptu];
-                    [iSalesDB execSql:sql];
-                }
-                [defaults synchronize];
-                
-                [self dismissViewControllerAnimated:YES completion:^{
-                    
-                    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
-                    
-                    bool offline_dirty=[defaults boolForKey:@"OFFLINE_DIRTY"];
-                    sqlite3* db = [iSalesDB get_db];
-                    int offline_user_exist=[iSalesDB get_recordcount:db table:@"offline_login" where:[NSString stringWithFormat:@"username='%@'",appDelegate.user ]];
-                    
-                    [iSalesDB close_db:db];
-                    
-                    
-                    BOOL condition = offline_dirty && offline_user_exist>0;
-                    
-#ifdef OFFLINE_MODE
-                    condition = condition && !appDelegate.offline_mode;
-#endif
-                    if(condition)
                     {
                         
-                        UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Detected new offline data" message:@"Do you want to sync with server?" preferredStyle:UIAlertControllerStyleAlert];
-                        //block代码块取代了delegate
+                        //
+                        //                NSString* contactid=[self.content_data[indexPath.row] valueForKey:@"contact_id"] ;
+                        AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                        //                appDelegate.contact_id=contactid;
+                        //                appDelegate.contact_name =[self.content_data[indexPath.row] valueForKey:@"name"];
                         
-                        
-                        UIAlertAction *actionTwo = [UIAlertAction actionWithTitle:@"Yes(Recommended)" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
+                        NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+                        [defaults removeObjectForKey:@"user"];
+                        [defaults removeObjectForKey:@"password"];
+                        NSString* encryptu=[AESCrypt encrypt:appDelegate.user password:@"usai"];
+                        NSString* encryptp=[AESCrypt encrypt:self.editpass.text password:@"usai"] ;
+                        if(self.checkSavePassword.selected)
+                        {
+                            
+                            [defaults setValue:encryptu forKey:@"user"];
+                            [defaults setValue:encryptp forKey:@"password"];
+                            sqlite3 *db = [iSalesDB get_db];
                             
+                            int count =[iSalesDB get_recordcount:db table:@"login_info" where:[NSString stringWithFormat:@"name='%@'",encryptu]];
                             
+                            if(count==0)
+                            {
+                                
+                                NSString * savelogin=[NSString stringWithFormat:@"insert into login_info(name,pwd) values('%@','%@')",encryptu,encryptp];
+                                [iSalesDB execSql:savelogin db:db];
+                            }
+                            else
+                            {
+                                NSString * savelogin=[NSString stringWithFormat:@"update login_info set pwd='%@' where name='%@'",encryptp,encryptu];
+                                [iSalesDB execSql:savelogin db:db];
+                            }
                             
+                            [iSalesDB close_db:db];
                             
-                            UIApplication * app = [UIApplication sharedApplication];
-                            AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-                            //UIViewController* active_vc = appDelegate.active_controller;
-                            OfflineSettingViewController * offlineVC =[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"OfflineSettingViewController"];
-                            //    loginvc.delegate = self;
-                            //    loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
-                            //       appDelegate.active_controller = gunVC;
-                            //        gunVC.onDismissVC = ^(){
-                            //            appDelegate.active_controller = active_vc;
-                            //        };
-                            UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:offlineVC] ;
+                            //                    [defaults setBool:TRUE forKey:@"autologin"];
+                        }
+                        else
+                        {
+                            NSString* sql=[NSString stringWithFormat:@"delete from login_info where name='%@'",encryptu];
+                            [iSalesDB execSql:sql];
+                        }
+                        [defaults synchronize];
+                        
+                        [self dismissViewControllerAnimated:YES completion:^{
                             
+                            NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
                             
+                            bool offline_dirty=[defaults boolForKey:@"OFFLINE_DIRTY"];
+                            sqlite3* db = [iSalesDB get_db];
+                            int offline_user_exist=[iSalesDB get_recordcount:db table:@"offline_login" where:[NSString stringWithFormat:@"username='%@'",appDelegate.user ]];
                             
+                            [iSalesDB close_db:db];
                             
                             
-                            //    [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
+                            BOOL condition = offline_dirty && offline_user_exist>0;
                             
-                            navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
-                            [appDelegate.main_vc presentViewController:navi animated:YES completion:^{
+        #ifdef OFFLINE_MODE
+                            condition = condition && !appDelegate.offline_mode;
+        #endif
+                            if(condition)
+                            {
                                 
+                                UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Detected new offline data" message:@"Do you want to sync with server?" preferredStyle:UIAlertControllerStyleAlert];
+                                //block代码块取代了delegate
                                 
-                                MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
                                 
-                                [main_vc checklogin:true];
-                                //        navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
+                                UIAlertAction *actionTwo = [UIAlertAction actionWithTitle:@"Yes(Recommended)" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
+                                    
+                                    
+                                    
+                                    
+                                    UIApplication * app = [UIApplication sharedApplication];
+                                    AppDelegate *appDelegate = (AppDelegate *)[app delegate];
+                                    //UIViewController* active_vc = appDelegate.active_controller;
+                                    OfflineSettingViewController * offlineVC =[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"OfflineSettingViewController"];
+                                    //    loginvc.delegate = self;
+                                    //    loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
+                                    //       appDelegate.active_controller = gunVC;
+                                    //        gunVC.onDismissVC = ^(){
+                                    //            appDelegate.active_controller = active_vc;
+                                    //        };
+                                    UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:offlineVC] ;
+                                    
+                                    
+                                    
+                                    
+                                    
+                                    //    [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
+                                    
+                                    navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
+                                    [appDelegate.main_vc presentViewController:navi animated:YES completion:^{
+                                        
+                                        
+                                        MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
+                                        
+                                        [main_vc checklogin:true];
+                                        //        navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
+                                        
+                                        DebugLog(@"about present.........");
+                                        
+                                        //   self.btop = false;
+                                        //  <#code#>
+                                    }];
+                                    
+                                    
+                                    
+                                    
+                                }];
                                 
-                                DebugLog(@"about present.........");
+                                UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
+                                    
+                                    if(self.returnValue)
+                                        self.returnValue(true);
+                                    [[NSNotificationCenter defaultCenter] postNotificationName:LoginOK_HandleUrgencyFile_Notification object:nil];
+                                    
+                                }];
                                 
-                                //   self.btop = false;
-                                //  <#code#>
-                            }];
-                            
-                            
-                            
-                            
-                        }];
-                        
-                        UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
-                            
-                            if(self.returnValue)
-                                self.returnValue(true);
-                            [[NSNotificationCenter defaultCenter] postNotificationName:LoginOK_HandleUrgencyFile_Notification object:nil];
-                            
+                                [alertControl addAction:actionTwo];
+                                [alertControl addAction:alertthree];
+                                
+                                
+                                
+                                [appDelegate.main_vc presentViewController:alertControl animated:YES completion:nil];
+                                
+                                
+                                
+                                
+                            }
+                            else
+                            {
+                                if(self.returnValue)
+                                    self.returnValue(true);
+                                [[NSNotificationCenter defaultCenter] postNotificationName:LoginOK_HandleUrgencyFile_Notification object:nil];
+                            }
                         }];
                         
-                        [alertControl addAction:actionTwo];
-                        [alertControl addAction:alertthree];
-                        
-                        
-                        
-                        [appDelegate.main_vc presentViewController:alertControl animated:YES completion:nil];
-                        
                         
                         
+                        //                if (self.delegate && [self.delegate respondsToSelector:@selector(LoginViewControllerDidLogin:)]) {
+                        //                    [self.delegate LoginViewControllerDidLogin:self];
+                        //                }
                         
+                        [[NSNotificationCenter defaultCenter] postNotificationName:User_LoginOK_Notification object:nil];
                     }
                     else
                     {
-                        if(self.returnValue)
-                            self.returnValue(true);
-                        [[NSNotificationCenter defaultCenter] postNotificationName:LoginOK_HandleUrgencyFile_Notification object:nil];
-                    }
-                }];
-                
-                
-                
-                //                if (self.delegate && [self.delegate respondsToSelector:@selector(LoginViewControllerDidLogin:)]) {
-                //                    [self.delegate LoginViewControllerDidLogin:self];
-                //                }
-                
-                [[NSNotificationCenter defaultCenter] postNotificationName:User_LoginOK_Notification object:nil];
-            }
-            else
-            {
-                NSString* msg=nil;
-                
-                switch (ret) {
-                        
-                    case RESULT_NET_NOTAVAILABLE:
-                        msg = MSG_NET_NOTAVAILABLE;
-                        break;
-                        
+                        NSString* msg=nil;
                         
-                    case RESULT_NET_ERROR:
-                        msg = MSG_NET_ERROR;
-                        break;
+                        switch (ret) {
+                                
+                            case RESULT_NET_NOTAVAILABLE:
+                                msg = MSG_NET_NOTAVAILABLE;
+                                break;
+                                
+                                
+                            case RESULT_NET_ERROR:
+                                msg = MSG_NET_ERROR;
+                                break;
+                                
+                                
+                            case RESULT_FALSE:
+                                msg = MSG_USERAUTH_ERROR;
+                                break;
+                                
+                            case RESULT_VER_LOW:
+                                msg = MSG_VER_LOW;
+                                break;
+                                
+                            case RESULT_LOGIN_DEVICE:
+                                msg= MSG_LOGIN_DEVICE;
+                                break;
+                            default:
+                                break;
+                        }
                         
+                        [RAUtils message_alert:msg title:@"Cannot sign-in" controller:self];
+                        //            [RAUtils alert_view:msg title:@"Cannot sign-in"];
                         
-                    case RESULT_FALSE:
-                        msg = MSG_USERAUTH_ERROR;
-                        break;
                         
-                    case RESULT_VER_LOW:
-                        msg = MSG_VER_LOW;
-                        break;
                         
-                    case RESULT_LOGIN_DEVICE:
-                        msg= MSG_LOGIN_DEVICE;
-                        break;
-                    default:
-                        break;
-                }
+                    }
+                }];
                 
-                [RAUtils message_alert:msg title:@"Cannot sign-in" controller:self];
-                //            [RAUtils alert_view:msg title:@"Cannot sign-in"];
+        //        [waitalert dismissViewControllerAnimated:YES completion:nil];
+
                 
                 
                 
-            }
-        }];
-        
-//        [waitalert dismissViewControllerAnimated:YES completion:nil];
+            }];
+            
 
-        
-        
-        
     }];
     return;
-//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+//        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Sign in" message:@"Please wait..." preferredStyle:UIAlertControllerStyleAlert];
+//        [self presentViewController:alertController animated:YES completion:nil];
+    
+    
+    //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //        
 //        
 //        int ret=[RANetwork  Authorize:user password:password];

+ 214 - 212
RedAnt ERP Mobile/common/Functions/sidemenu/UserListViewController.m

@@ -110,235 +110,237 @@
             return;
         }
         
-        UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Switch user"];
-        
-        [RANetwork request_logout:^(NSMutableDictionary *result) {
-            
-            
-            
-            appDelegate.cart_count = 0;
-            appDelegate.wish_count =0;
-            appDelegate.port_count =0;
-            
-            [appDelegate update_count_mark];
-            
-            
-            appDelegate.can_show_price =false;
-            appDelegate.can_see_price =false;
-            appDelegate.can_create_portfolio =false;
-            appDelegate.can_create_order =false;
-            
-            
-            appDelegate.can_cancel_order =false;
-            appDelegate.can_set_cart_price =false;
-            appDelegate.can_delete_order =false;
-            appDelegate.can_submit_order =false;
-            appDelegate.can_set_tearsheet_price =false;
-            appDelegate.can_update_contact_info = false;
-            
-            appDelegate.save_order_logout = false;
-            appDelegate.submit_order_logout = false;
-            appDelegate.alert_sold_in_quantities = false;
-            
-            appDelegate.ipad_perm =nil ;
-            appDelegate.user_type = USER_ROLE_UNKNOWN;
-            appDelegate.OrderFilter= nil;
-            [appDelegate SetSo:nil];
-            [appDelegate set_main_button_panel];
-            
-            [appDelegate Logout];
-            [appDelegate checkLogin:NO];
-            
-            //                [waitalert dismissViewControllerAnimated:YES completion:nil];
-            
-            [RANetwork request_login:user password:password completionHandler:^(NSMutableDictionary *result) {
-                int ret=[result[@"result"]intValue];
-                
-                
-                [waitalert dismissViewControllerAnimated:YES completion:^{
-                    if(ret==RESULT_TRUE)
-                    {
-                        AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+        __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Switch user" completion:^{
+            [RANetwork request_logout:^(NSMutableDictionary *result) {
                         
-                        NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
-                        [defaults removeObjectForKey:@"user"];
-                        [defaults removeObjectForKey:@"password"];
-                        if(true)
-                        {
-                            NSString* encryptu=[AESCrypt encrypt:appDelegate.user password:@"usai"];
-                            NSString* encryptp=[AESCrypt encrypt:appDelegate.password password:@"usai"] ;
-                            
-                            [defaults setValue:encryptu forKey:@"user"];
-                            [defaults setValue:encryptp forKey:@"password"];
-                            
-                        }
-                        [defaults synchronize];
                         
-                        MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
-                        if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
-                        {
-                            [main_vc checklogin:false];
-                        }
-                        else
-                        {
-                            [main_vc checklogin:false];
-                        }
                         
-                        [self dismissViewControllerAnimated:true completion:^{
-                            if(self.returnValue)
-                                self.returnValue(true);
-                        }];
+                        appDelegate.cart_count = 0;
+                        appDelegate.wish_count =0;
+                        appDelegate.port_count =0;
+                        
+                        [appDelegate update_count_mark];
+                        
+                        
+                        appDelegate.can_show_price =false;
+                        appDelegate.can_see_price =false;
+                        appDelegate.can_create_portfolio =false;
+                        appDelegate.can_create_order =false;
+                        
+                        
+                        appDelegate.can_cancel_order =false;
+                        appDelegate.can_set_cart_price =false;
+                        appDelegate.can_delete_order =false;
+                        appDelegate.can_submit_order =false;
+                        appDelegate.can_set_tearsheet_price =false;
+                        appDelegate.can_update_contact_info = false;
                         
-                    } // 登陆成功
-                    else
-                    {
-                        NSString* msg=nil;
+                        appDelegate.save_order_logout = false;
+                        appDelegate.submit_order_logout = false;
+                        appDelegate.alert_sold_in_quantities = false;
                         
-                        switch (ret) {
-                                
-                            case RESULT_NET_NOTAVAILABLE:
-                                msg = MSG_NET_NOTAVAILABLE;
-                                break;
-                                
-                                
-                            case RESULT_NET_ERROR:
-                                msg = MSG_NET_ERROR;
-                                break;
-                                
-                                
-                            case RESULT_FALSE:
-                                msg = MSG_USERAUTH_ERROR;
-                                break;
-                                
-                            case RESULT_VER_LOW:
-                                msg = MSG_VER_LOW;
-                                break;
-                            default:
-                                break;
-                        }
+                        appDelegate.ipad_perm =nil ;
+                        appDelegate.user_type = USER_ROLE_UNKNOWN;
+                        appDelegate.OrderFilter= nil;
+                        [appDelegate SetSo:nil];
+                        [appDelegate set_main_button_panel];
                         
+                        [appDelegate Logout];
+                        [appDelegate checkLogin:NO];
                         
-                        UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Switch User" message:msg preferredStyle:UIAlertControllerStyleAlert];
-                        //block代码块取代了delegate
-                        UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
+                        //                [waitalert dismissViewControllerAnimated:YES completion:nil];
+                        
+                        [RANetwork request_login:user password:password completionHandler:^(NSMutableDictionary *result) {
+                            int ret=[result[@"result"]intValue];
+                            
                             
-                            [self dismissViewControllerAnimated:true completion:^{
-                                if(self.returnValue)
-                                    self.returnValue(false);
+                            [waitalert dismissViewControllerAnimated:YES completion:^{
+                                if(ret==RESULT_TRUE)
+                                {
+                                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                                    
+                                    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+                                    [defaults removeObjectForKey:@"user"];
+                                    [defaults removeObjectForKey:@"password"];
+                                    if(true)
+                                    {
+                                        NSString* encryptu=[AESCrypt encrypt:appDelegate.user password:@"usai"];
+                                        NSString* encryptp=[AESCrypt encrypt:appDelegate.password password:@"usai"] ;
+                                        
+                                        [defaults setValue:encryptu forKey:@"user"];
+                                        [defaults setValue:encryptp forKey:@"password"];
+                                        
+                                    }
+                                    [defaults synchronize];
+                                    
+                                    MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
+                                    if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
+                                    {
+                                        [main_vc checklogin:false];
+                                    }
+                                    else
+                                    {
+                                        [main_vc checklogin:false];
+                                    }
+                                    
+                                    [self dismissViewControllerAnimated:true completion:^{
+                                        if(self.returnValue)
+                                            self.returnValue(true);
+                                    }];
+                                    
+                                } // 登陆成功
+                                else
+                                {
+                                    NSString* msg=nil;
+                                    
+                                    switch (ret) {
+                                            
+                                        case RESULT_NET_NOTAVAILABLE:
+                                            msg = MSG_NET_NOTAVAILABLE;
+                                            break;
+                                            
+                                            
+                                        case RESULT_NET_ERROR:
+                                            msg = MSG_NET_ERROR;
+                                            break;
+                                            
+                                            
+                                        case RESULT_FALSE:
+                                            msg = MSG_USERAUTH_ERROR;
+                                            break;
+                                            
+                                        case RESULT_VER_LOW:
+                                            msg = MSG_VER_LOW;
+                                            break;
+                                        default:
+                                            break;
+                                    }
+                                    
+                                    
+                                    UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Switch User" message:msg preferredStyle:UIAlertControllerStyleAlert];
+                                    //block代码块取代了delegate
+                                    UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
+                                        
+                                        [self dismissViewControllerAnimated:true completion:^{
+                                            if(self.returnValue)
+                                                self.returnValue(false);
+                                        }];
+                                        
+                                    }];
+                                    
+                                    
+                                    [alertControl addAction:actionOne];
+                                    
+                                    [self presentViewController:alertControl animated:YES completion:nil];
+                                    
+                                } // 登陆失败
                             }];
+            //                [waitalert dismissViewControllerAnimated:YES completion:nil];
+                            
+                            
+                            
                             
                         }];
                         
                         
-                        [alertControl addAction:actionOne];
+                        //                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+                        //
+                        //                    int ret=[RANetwork  Authorize:user password:password];
+                        //
+                        //                    dispatch_async(dispatch_get_main_queue(), ^{
+                        //
+                        //                        [waitalert dismissViewControllerAnimated:YES completion:nil];
+                        //
+                        //                        if(ret==RESULT_TRUE)
+                        //                        {
+                        //                            AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                        //
+                        //                            NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+                        //                            [defaults removeObjectForKey:@"user"];
+                        //                            [defaults removeObjectForKey:@"password"];
+                        //                            if(true)
+                        //                            {
+                        //                                NSString* encryptu=[AESCrypt encrypt:appDelegate.user password:@"usai"];
+                        //                                NSString* encryptp=[AESCrypt encrypt:appDelegate.password password:@"usai"] ;
+                        //
+                        //                                [defaults setValue:encryptu forKey:@"user"];
+                        //                                [defaults setValue:encryptp forKey:@"password"];
+                        //
+                        //                            }
+                        //                            [defaults synchronize];
+                        //
+                        //                            MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
+                        //                            if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
+                        //                            {
+                        //                                [main_vc checklogin:false];
+                        //                            }
+                        //                            else
+                        //                            {
+                        //                                [main_vc checklogin:false];
+                        //                            }
+                        //
+                        //                            [self dismissViewControllerAnimated:true completion:^{
+                        //                                if(self.returnValue)
+                        //                                    self.returnValue(true);
+                        //                            }];
+                        //
+                        //                        } // 登陆成功
+                        //                        else
+                        //                        {
+                        //                            NSString* msg=nil;
+                        //
+                        //                            switch (ret) {
+                        //
+                        //                                case RESULT_NET_NOTAVAILABLE:
+                        //                                    msg = MSG_NET_NOTAVAILABLE;
+                        //                                    break;
+                        //
+                        //
+                        //                                case RESULT_NET_ERROR:
+                        //                                    msg = MSG_NET_ERROR;
+                        //                                    break;
+                        //
+                        //
+                        //                                case RESULT_FALSE:
+                        //                                    msg = MSG_USERAUTH_ERROR;
+                        //                                    break;
+                        //
+                        //                                case RESULT_VER_LOW:
+                        //                                    msg = MSG_VER_LOW;
+                        //                                    break;
+                        //                                default:
+                        //                                    break;
+                        //                            }
+                        //
+                        //
+                        //                            UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Switch User" message:msg preferredStyle:UIAlertControllerStyleAlert];
+                        //                            //block代码块取代了delegate
+                        //                            UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
+                        //
+                        //                                [self dismissViewControllerAnimated:true completion:^{
+                        //                                    if(self.returnValue)
+                        //                                        self.returnValue(false);
+                        //                                }];
+                        //
+                        //                            }];
+                        //
+                        //
+                        //                            [alertControl addAction:actionOne];
+                        //
+                        //                            [self presentViewController:alertControl animated:YES completion:nil];
+                        //
+                        //                        } // 登陆失败
+                        //
+                        //                    }); // update login ui
+                        //
+                        //                }); // attemp login
                         
-                        [self presentViewController:alertControl animated:YES completion:nil];
                         
-                    } // 登陆失败
-                }];
-//                [waitalert dismissViewControllerAnimated:YES completion:nil];
-                
-                
-                
-                
-            }];
-            
-            
-            //                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-            //
-            //                    int ret=[RANetwork  Authorize:user password:password];
-            //
-            //                    dispatch_async(dispatch_get_main_queue(), ^{
-            //
-            //                        [waitalert dismissViewControllerAnimated:YES completion:nil];
-            //
-            //                        if(ret==RESULT_TRUE)
-            //                        {
-            //                            AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-            //
-            //                            NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
-            //                            [defaults removeObjectForKey:@"user"];
-            //                            [defaults removeObjectForKey:@"password"];
-            //                            if(true)
-            //                            {
-            //                                NSString* encryptu=[AESCrypt encrypt:appDelegate.user password:@"usai"];
-            //                                NSString* encryptp=[AESCrypt encrypt:appDelegate.password password:@"usai"] ;
-            //
-            //                                [defaults setValue:encryptu forKey:@"user"];
-            //                                [defaults setValue:encryptp forKey:@"password"];
-            //
-            //                            }
-            //                            [defaults synchronize];
-            //
-            //                            MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
-            //                            if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
-            //                            {
-            //                                [main_vc checklogin:false];
-            //                            }
-            //                            else
-            //                            {
-            //                                [main_vc checklogin:false];
-            //                            }
-            //
-            //                            [self dismissViewControllerAnimated:true completion:^{
-            //                                if(self.returnValue)
-            //                                    self.returnValue(true);
-            //                            }];
-            //
-            //                        } // 登陆成功
-            //                        else
-            //                        {
-            //                            NSString* msg=nil;
-            //
-            //                            switch (ret) {
-            //
-            //                                case RESULT_NET_NOTAVAILABLE:
-            //                                    msg = MSG_NET_NOTAVAILABLE;
-            //                                    break;
-            //
-            //
-            //                                case RESULT_NET_ERROR:
-            //                                    msg = MSG_NET_ERROR;
-            //                                    break;
-            //
-            //
-            //                                case RESULT_FALSE:
-            //                                    msg = MSG_USERAUTH_ERROR;
-            //                                    break;
-            //
-            //                                case RESULT_VER_LOW:
-            //                                    msg = MSG_VER_LOW;
-            //                                    break;
-            //                                default:
-            //                                    break;
-            //                            }
-            //
-            //
-            //                            UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Switch User" message:msg preferredStyle:UIAlertControllerStyleAlert];
-            //                            //block代码块取代了delegate
-            //                            UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-            //
-            //                                [self dismissViewControllerAnimated:true completion:^{
-            //                                    if(self.returnValue)
-            //                                        self.returnValue(false);
-            //                                }];
-            //
-            //                            }];
-            //
-            //
-            //                            [alertControl addAction:actionOne];
-            //
-            //                            [self presentViewController:alertControl animated:YES completion:nil];
-            //
-            //                        } // 登陆失败
-            //
-            //                    }); // update login ui
-            //
-            //                }); // attemp login
-            
-            
+                    }];
+
         }];
         
+                
 //        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //            [RANetwork logout];

+ 208 - 160
RedAnt ERP Mobile/common/Functions/watchlist/WatchListViewController.m

@@ -39,6 +39,12 @@
 @property (nonatomic,strong) NSOperationQueue *dataOperationQueue;
 @property (nonatomic,copy) NSString *print_url;
 
+//仅用于加购物车的临时变量,避免wishlist刷新后check 丢失。
+@property (nonatomic,strong) NSMutableArray* checked_cart;
+@property (nonatomic,strong) NSMutableArray* checked_iid_cart;
+
+
+
 @end
 
 @implementation WatchListViewController
@@ -78,6 +84,34 @@
 }
 #endif
 - (IBAction)onAddtoCart:(id)sender {
+    
+    self.checked_cart = [[NSMutableArray alloc] init];
+       
+    self.checked_iid_cart= [[NSMutableArray alloc] init];
+       
+       int count = [[self.content_data valueForKey:@"count"] intValue];
+       for(int i=0;i<count;i++)
+       {
+           NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
+           bool check = [[item_json valueForKey:@"check"] boolValue];
+           if(check)
+           {
+               /*
+               if ([[item_json valueForKey:@"available"] isEqualToString:@"In Production"] || [[item_json valueForKey:@"available"] integerValue] == 0) {
+                   
+                   [RAUtils message_alert:@"There ars some products is not available" title:@"Warning" controller:self];
+                   return;
+                   
+               }
+                */
+               [self.checked_cart addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"product_id"] intValue]]];
+               [self.checked_iid_cart addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"item_id"] intValue]]];
+           }
+       }
+
+    
+    
+    
     [CartUtils add_to_cart:self selectorholder:self selector:@selector(addtocart)];
     return;
 //
@@ -205,32 +239,38 @@
 //
 }
 -(void) addtocart
+{
+    [self addtocart:self.checked_cart checked_iid:self.checked_iid_cart];
+    self.checked_cart=nil;
+    self.checked_iid_cart=nil;
+}
+-(void) addtocart:(NSMutableArray*) checked checked_iid:(NSMutableArray*)checked_iid
 {
     
-    
-    NSMutableArray* checked = [[NSMutableArray alloc] init];
-    
-    NSMutableArray* checked_iid = [[NSMutableArray alloc] init];
-    
-    int count = [[self.content_data valueForKey:@"count"] intValue];
-    for(int i=0;i<count;i++)
-    {
-        NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
-        bool check = [[item_json valueForKey:@"check"] boolValue];
-        if(check)
-        {
-            /*
-            if ([[item_json valueForKey:@"available"] isEqualToString:@"In Production"] || [[item_json valueForKey:@"available"] integerValue] == 0) {
-                
-                [RAUtils message_alert:@"There ars some products is not available" title:@"Warning" controller:self];
-                return;
-                
-            }
-             */
-            [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"product_id"] intValue]]];
-            [checked_iid addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"item_id"] intValue]]];
-        }
-    }
+//
+//    NSMutableArray* checked = [[NSMutableArray alloc] init];
+//
+//    NSMutableArray* checked_iid = [[NSMutableArray alloc] init];
+//
+//    int count = [[self.content_data valueForKey:@"count"] intValue];
+//    for(int i=0;i<count;i++)
+//    {
+//        NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
+//        bool check = [[item_json valueForKey:@"check"] boolValue];
+//        if(check)
+//        {
+//            /*
+//            if ([[item_json valueForKey:@"available"] isEqualToString:@"In Production"] || [[item_json valueForKey:@"available"] integerValue] == 0) {
+//
+//                [RAUtils message_alert:@"There ars some products is not available" title:@"Warning" controller:self];
+//                return;
+//
+//            }
+//             */
+//            [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"product_id"] intValue]]];
+//            [checked_iid addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"item_id"] intValue]]];
+//        }
+//    }
 
     if(checked.count==0)
     {
@@ -328,101 +368,103 @@
 //        });
 //    });
 }
--(void) neworder
-{
-    
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order"];
-    
-    [RANetwork request_create_order:^(NSMutableDictionary *result) {
-        NSMutableDictionary* return_json =result;
-        
-        [waitalert dismissViewControllerAnimated:YES completion:^{
-            //        [waitalert dismissViewControllerAnimated:YES completion:nil];
-            
-            
-            if([[return_json valueForKey:@"result"] intValue]==2)
-            {
-                int result=[[return_json valueForKey:@"result"] intValue];
-                if(result==2)
-                {
-                    //successed.
-                    
-                    NSString* order_code = [return_json valueForKey:@"orderCode"];
-                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                    appDelegate.order_code = order_code;
-                    appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
-                    
-                    [self addtocart];
-                    
-
-                    
-                }
-            }
-            else
-            {
-                [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
-            }
-        }];
-        
-
-        
-        
-        
-        
-        
-    }];
-//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+//-(void) neworder
+//{
 //
-//        NSDictionary* return_json = [RANetwork new_Order];
+//    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order" completion:^{
+//        [RANetwork request_create_order:^(NSMutableDictionary *result) {
+//            NSMutableDictionary* return_json =result;
 //
-//        dispatch_async(dispatch_get_main_queue(), ^{
-//            [waitalert dismissViewControllerAnimated:YES completion:nil];
+//            [waitalert dismissViewControllerAnimated:YES completion:^{
+//                //        [waitalert dismissViewControllerAnimated:YES completion:nil];
 //
 //
-//            if([[return_json valueForKey:@"result"] intValue]==2)
-//            {
-//                int result=[[return_json valueForKey:@"result"] intValue];
-//                if(result==2)
+//                if([[return_json valueForKey:@"result"] intValue]==2)
 //                {
-//                    //successed.
+//                    int result=[[return_json valueForKey:@"result"] intValue];
+//                    if(result==2)
+//                    {
+//                        //successed.
 //
-//                    NSString* order_code = [return_json valueForKey:@"orderCode"];
-//                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-//                    appDelegate.order_code = order_code;
-//                    appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
+//                        NSString* order_code = [return_json valueForKey:@"orderCode"];
+//                        AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+//                        appDelegate.order_code = order_code;
+//                        appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
 //
-//                    [self addtocart];
+//                        [self addtocart];
 //
 //
-//                    //    [self ReloadData];
 //
+//                    }
+//                }
+//                else
+//                {
+//                    [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
+//                }
+//            }];
 //
-//                    //                    if(self.shopCartBlock!=nil)
-//                    //                    {
-//                    //                        UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
-//                    //
-//                    //
-//                    //                        CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
-//                    //                        UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
-//                    //                        iv.image = img;
-//                    //                        //                        [self.contentView addSubview:iv];
-//                    //                        self.shopCartBlock(iv);
-//                    //
-//                    //                    }
 //
-//                }
-//            }
-//            else
-//            {
-//                [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
-//            }
 //
 //
 //
 //
-//        });
-//    });
-}
+//
+//        }];
+//
+//    }];
+//
+//    //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+////
+////        NSDictionary* return_json = [RANetwork new_Order];
+////
+////        dispatch_async(dispatch_get_main_queue(), ^{
+////            [waitalert dismissViewControllerAnimated:YES completion:nil];
+////
+////
+////            if([[return_json valueForKey:@"result"] intValue]==2)
+////            {
+////                int result=[[return_json valueForKey:@"result"] intValue];
+////                if(result==2)
+////                {
+////                    //successed.
+////
+////                    NSString* order_code = [return_json valueForKey:@"orderCode"];
+////                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+////                    appDelegate.order_code = order_code;
+////                    appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
+////
+////                    [self addtocart];
+////
+////
+////                    //    [self ReloadData];
+////
+////
+////                    //                    if(self.shopCartBlock!=nil)
+////                    //                    {
+////                    //                        UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
+////                    //
+////                    //
+////                    //                        CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
+////                    //                        UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
+////                    //                        iv.image = img;
+////                    //                        //                        [self.contentView addSubview:iv];
+////                    //                        self.shopCartBlock(iv);
+////                    //
+////                    //                    }
+////
+////                }
+////            }
+////            else
+////            {
+////                [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
+////            }
+////
+////
+////
+////
+////        });
+////    });
+//}
 
 
 - (void)viewDidLoad
@@ -540,24 +582,26 @@
     
     //    NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
     NSString * string = [checked componentsJoinedByString:@","];
-    UIAlertController* wait_alert = [RAUtils waiting_alert:self title:@"Remove Models From Wishlist"];
-    [RANetwork request_remove_wishlist:string completionHandler:^(NSMutableDictionary *result) {
-        NSMutableDictionary* cart_json = result;
-        [wait_alert dismissViewControllerAnimated:YES completion:^{
-            if([[cart_json valueForKey:@"result"] intValue]==2)
-            {
-                [self reload_data];
-                [self.btnselect setTitle:@"Select all"];
-            }
-            else
-            {
-                [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Remove Model From Wish List" controller:self] ;
-            }
+    __block UIAlertController* wait_alert = [RAUtils waiting_alert:self title:@"Remove Models From Wishlist" completion:^{
+        [RANetwork request_remove_wishlist:string completionHandler:^(NSMutableDictionary *result) {
+            NSMutableDictionary* cart_json = result;
+            [wait_alert dismissViewControllerAnimated:YES completion:^{
+                if([[cart_json valueForKey:@"result"] intValue]==2)
+                {
+                    [self reload_data];
+                    [self.btnselect setTitle:@"Select all"];
+                }
+                else
+                {
+                    [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Remove Model From Wish List" controller:self] ;
+                }
+            }];
+
+            
         }];
 
-        
     }];
-//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+    //    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 //
 //        NSDictionary* cart_json = [RANetwork watchlist_remove:string];
 //
@@ -1012,27 +1056,29 @@
                      NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)self.indexPath.row]] mutableCopy];
                      
                      NSString *ids=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"item_id"] intValue]];
-                     UIAlertController* wait_alert = [RAUtils waiting_alert:self title:@"Remove Model"];
-                     [RANetwork request_remove_wishlist:ids completionHandler:^(NSMutableDictionary *result) {
-                         NSMutableDictionary* cart_json = result;
-                         
-                         
-                         [wait_alert dismissViewControllerAnimated:YES completion:^{
-                             if([[cart_json valueForKey:@"result"] intValue]==2)
-                             {
-                                 [self reload_data];
-                             }
-                             else
-                             {
-                                 [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
-                             }
-                         }];
-                         
-
-                         
-                         
+             __block UIAlertController* wait_alert = [RAUtils waiting_alert:self title:@"Remove Model" completion:^{
+                 [RANetwork request_remove_wishlist:ids completionHandler:^(NSMutableDictionary *result) {
+                     NSMutableDictionary* cart_json = result;
+                     
+                     
+                     [wait_alert dismissViewControllerAnimated:YES completion:^{
+                         if([[cart_json valueForKey:@"result"] intValue]==2)
+                         {
+                             [self reload_data];
+                         }
+                         else
+                         {
+                             [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
+                         }
                      }];
- 
+                     
+
+                     
+                     
+                 }];
+
+             }];
+                      
              
                      
                  }];
@@ -1446,36 +1492,38 @@ commitEditingStyle:(UITableViewCellEditingStyle)editingStyle  forRowAtIndexPath:
             // 验证是邮件地址,发送邮件
             [weakVC dismissViewControllerAnimated:YES completion:^{
                 
-                UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email"];
-                
-                [RANetwork request_emailwishlist:text completionHandler:^(NSMutableDictionary *result) {
-                    DebugLog(@"email wishlist result: %@",result);
-                    
+                __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
+                    [RANetwork request_emailwishlist:text completionHandler:^(NSMutableDictionary *result) {
+                        DebugLog(@"email wishlist result: %@",result);
                         
-                    [waitting_alert dismissViewControllerAnimated:YES completion:^{
-                        //                        [waitting_alert dismissWithClickedButtonIndex:0 animated:YES];
-                        
-                        if ([[result objectForKey:@"result"] integerValue] != RESULT_TRUE) {
                             
-                            UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"The email send to %@ failed",text] preferredStyle:UIAlertControllerStyleAlert];
-                            UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-                                
-                            }];
+                        [waitting_alert dismissViewControllerAnimated:YES completion:^{
+                            //                        [waitting_alert dismissWithClickedButtonIndex:0 animated:YES];
                             
-                            [errorAlertVC addAction:action];
-                            [weakself presentViewController:errorAlertVC animated:YES completion:nil];
-                            
-                        }else {
-                            
-                            [RAUtils message_alert:nil title:@"Email was sent successfully" controller:weakself];
+                            if ([[result objectForKey:@"result"] integerValue] != RESULT_TRUE) {
+                                
+                                UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"The email send to %@ failed",text] preferredStyle:UIAlertControllerStyleAlert];
+                                UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+                                    
+                                }];
+                                
+                                [errorAlertVC addAction:action];
+                                [weakself presentViewController:errorAlertVC animated:YES completion:nil];
+                                
+                            }else {
+                                
+                                [RAUtils message_alert:nil title:@"Email was sent successfully" controller:weakself];
+                                
+                            }
+                        }];
+
                             
-                        }
+                        
                     }];
 
-                        
-                    
                 }];
                 
+                                
                 
 //                dispatch_async(dispatch_get_global_queue(0, 0), ^{
 //

+ 3 - 3
RedAnt ERP Mobile/common/ImageUtils.m

@@ -64,10 +64,10 @@
     path=[path stringByReplacingOccurrencesOfString:@"http://" withString:@""];
     //    path=[path stringByReplacingOccurrencesOfString:filename withString:@""];
     
-    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+//    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
     
-    if(appDelegate.bEnable_Cache==false)
-        return nil;
+//    if(appDelegate.bEnable_Cache==false)
+//        return nil;
     
     
     NSData* data = nil;

+ 52 - 48
RedAnt ERP Mobile/common/Price Setting/PriceSettingViewController.m

@@ -119,35 +119,37 @@
 
 - (IBAction)calculatePriceButtonClick:(UIButton *)sender {
 
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Load Data"];
-    
-    [RANetwork request_npd_shop_givenprice:^(NSMutableDictionary *result) {
-            NSDictionary *dic = result;
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Load Data" completion:^{
+        [RANetwork request_npd_shop_givenprice:^(NSMutableDictionary *result) {
+                NSDictionary *dic = result;
 
-        //    [waitalert dismissWithClickedButtonIndex:0 animated:YES];
-        [waitalert dismissViewControllerAnimated:YES completion:^{
-            if ([[dic objectForKey:@"result"] integerValue] == 2) {
-                
-                CategoryPriceViewController *categoryPriceVC =[ [UIStoryboard storyboardWithName:@"CUL" bundle:nil] instantiateViewControllerWithIdentifier:@"CategoryPriceViewController"];
-                
-                categoryPriceVC.categoryGivenPrice = dic.mutableCopy;
+            //    [waitalert dismissWithClickedButtonIndex:0 animated:YES];
+            [waitalert dismissViewControllerAnimated:YES completion:^{
+                if ([[dic objectForKey:@"result"] integerValue] == 2) {
+                    
+                    CategoryPriceViewController *categoryPriceVC =[ [UIStoryboard storyboardWithName:@"CUL" bundle:nil] instantiateViewControllerWithIdentifier:@"CategoryPriceViewController"];
+                    
+                    categoryPriceVC.categoryGivenPrice = dic.mutableCopy;
+                    
+                    [self.navigationController pushViewController:categoryPriceVC animated:YES];
+                } else {
+                    
+                    NSString *msg = [dic objectForKey:@"msg"];
+                    if (!msg) {
+                        msg = @"Some Error Occured,Please Try Again";
+                    }
+                    [RAUtils message_alert:msg title:@"Set Store Price" controller:self];
+                    
+                };
+            }];
                 
-                [self.navigationController pushViewController:categoryPriceVC animated:YES];
-            } else {
                 
-                NSString *msg = [dic objectForKey:@"msg"];
-                if (!msg) {
-                    msg = @"Some Error Occured,Please Try Again";
-                }
-                [RAUtils message_alert:msg title:@"Set Store Price" controller:self];
-                
-            };
+
         }];
-            
-            
 
     }];
     
+        
 //    NSDictionary *dic = [RANetwork get_npd_shop_givenPrice];
 //
 ////    [waitalert dismissWithClickedButtonIndex:0 animated:YES];
@@ -238,37 +240,39 @@
 
 - (IBAction)saveButtonClick:(UIButton *)sender {
     
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Set PriceType"];
-    
-    [RANetwork request_update_npd_shop_price_type:self.priceType completionHandler:^(NSMutableDictionary *result) {
-        NSDictionary *dic=result;
-        [waitalert dismissViewControllerAnimated:YES completion:^{
-            // 成功
-            if ([[dic objectForKey:@"result"] integerValue] == 2) {
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Set PriceType" completion:^{
+        [RANetwork request_update_npd_shop_price_type:self.priceType completionHandler:^(NSMutableDictionary *result) {
+                NSDictionary *dic=result;
+                [waitalert dismissViewControllerAnimated:YES completion:^{
+                    // 成功
+                    if ([[dic objectForKey:@"result"] integerValue] == 2) {
+                        
+                        [Singleton sharedInstance].npd_shop_price_type = self.priceType;
+                        
+                        
+                        
+        #ifdef RA_NOTIFICATION
+                        [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+        #else
+                        // 刷新 Cart、Order List
+                        [[NSNotificationCenter defaultCenter] postNotificationName:Change_Price_Type_Notification object:nil];
+        #endif
+                        
+                    } else { // 失败
+                        
+                        DebugLog(@"set price type failure");
+                    }
+                    
+                    [self dismissViewControllerAnimated:YES completion:nil];;
+                }];
                 
-                [Singleton sharedInstance].npd_shop_price_type = self.priceType;
-                
-                
-                
-#ifdef RA_NOTIFICATION
-                [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-#else
-                // 刷新 Cart、Order List
-                [[NSNotificationCenter defaultCenter] postNotificationName:Change_Price_Type_Notification object:nil];
-#endif
-                
-            } else { // 失败
-                
-                DebugLog(@"set price type failure");
-            }
+
+            }];
             
-            [self dismissViewControllerAnimated:YES completion:nil];;
-        }];
-        
 
     }];
     
-//    NSDictionary *dic = [RANetwork set_npd_shop_price_type:self.priceType];
+    //    NSDictionary *dic = [RANetwork set_npd_shop_price_type:self.priceType];
 //
 ////    [waitalert dismissWithClickedButtonIndex:0 animated:YES];
 //    [waitalert dismissViewControllerAnimated:YES completion:nil];

+ 20 - 18
RedAnt ERP Mobile/common/Price Setting/SetCategoryPriceController.m

@@ -223,30 +223,32 @@
     
     if (rightDiscount) {
         
-        UIAlertController* waitalert = [RAUtils waiting_alert:self title:@"Set Price"];
-        //        UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Set Price"];
-        
-        
-        [RANetwork request_update_npd_shop_givenprice:@{@"base_price" : [NSString stringWithFormat:@"%ld",self.priceType],@"discount" : discount,@"category_id" : @(self.categoryID)}.mutableCopy completionHandler:^(NSMutableDictionary *result) {
-            NSDictionary *dic = result;
-            
-            [waitalert dismissViewControllerAnimated:YES completion:^{
-                //        [waitalert dismissWithClickedButtonIndex:0 animated:YES];
+        __block UIAlertController* waitalert = [RAUtils waiting_alert:self title:@"Set Price" completion:^{
+            [RANetwork request_update_npd_shop_givenprice:@{@"base_price" : [NSString stringWithFormat:@"%ld",self.priceType],@"discount" : discount,@"category_id" : @(self.categoryID)}.mutableCopy completionHandler:^(NSMutableDictionary *result) {
+                NSDictionary *dic = result;
                 
-                if ([[dic objectForKey:@"result"] integerValue] == 2) {
+                [waitalert dismissViewControllerAnimated:YES completion:^{
+                    //        [waitalert dismissWithClickedButtonIndex:0 animated:YES];
                     
-                    [self.categoryPrice setObject:[NSString stringWithFormat:@"%ld",self.priceType] forKey:@"base_price"];
-                    [self.categoryPrice setObject:discount forKey:@"price_discount"];
+                    if ([[dic objectForKey:@"result"] integerValue] == 2) {
+                        
+                        [self.categoryPrice setObject:[NSString stringWithFormat:@"%ld",self.priceType] forKey:@"base_price"];
+                        [self.categoryPrice setObject:discount forKey:@"price_discount"];
+                        
+                        // 将数据返回
+                        if (self.returnBlock)
+                            self.returnBlock(self.categoryPrice);
+                    }
                     
-                    // 将数据返回
-                    if (self.returnBlock)
-                        self.returnBlock(self.categoryPrice);
-                }
+                    [self.navigationController popViewControllerAnimated:YES];
+                }];
                 
-                [self.navigationController popViewControllerAnimated:YES];
             }];
-            
         }];
+        //        UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Set Price"];
+        
+        
+
         
         //        NSDictionary *dic = [RANetwork set_npd_shop_givenPrice:@{@"base_price" : [NSString stringWithFormat:@"%ld",self.priceType],@"discount" : discount,@"category_id" : @(self.categoryID)}.mutableCopy];
         //

+ 7 - 2
RedAnt ERP Mobile/common/RAUtils.h

@@ -30,10 +30,15 @@ NS_ASSUME_NONNULL_BEGIN
 + (CGRect)relativeFrameForScreenWithView:(UIView *)v;
 +(NSDictionary*) error_json :(int)code err_msg:(NSString* _Nullable)msg;
 +(UIAlertController*) message_alert :(NSString* _Nullable) msg title:(NSString*_Nullable) title controller:(UIViewController*) vc;
+
++(UIAlertController*) message_alert :(NSString*) msg title:(NSString*) title controller:(UIViewController*) vc action_handler:(void (^ __nullable)(UIAlertAction *action))action_handler completion:(void (^ __nullable)(void))completion;
 //+(void) alert_view :(NSString*) msg title:(NSString*) title ;
 //+(UIAlertView * ) waiting_alert :(NSString*) msg title:(NSString*) title;
-+(UIAlertController*) waiting_alert:(UIViewController*)parent title:(NSString*_Nullable) title;
-+(UIAlertController*) waiting_alert:(UIViewController*)parent message:(NSString*_Nullable)msg title:(NSString*_Nullable) title;
+//+(UIAlertController*) waiting_alert:(UIViewController*)parent title:(NSString*_Nullable) title;
++(UIAlertController*) waiting_alert:(UIViewController*)parent title:(NSString*) title completion:(void (^ __nullable)(void))completion;
+
+//+(UIAlertController*) waiting_alert:(UIViewController*)parent message:(NSString*_Nullable)msg title:(NSString*_Nullable) title;
++(UIAlertController*) waiting_alert:(UIViewController*)parent message:(NSString*)msg title:(NSString*) title completion:(void (^ __nullable)(void))completion;
 + (float)fileSizeForDir:(NSString*)path;//计算文件夹下文件的总大小;
 +(void) deletefiles :(NSString*) path;
 +(UIColor*) strColor:(NSString*) color;

+ 44 - 7
RedAnt ERP Mobile/common/RAUtils.m

@@ -558,18 +558,36 @@
     return freespace/1024/1024;
 }
 
-+(UIAlertController*) waiting_alert:(UIViewController*)parent title:(NSString*) title
+//+(UIAlertController*) waiting_alert:(UIViewController*)parent title:(NSString*) title
+//{
+//    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:@"Please wait..." preferredStyle:UIAlertControllerStyleAlert];
+//
+////    [parent presentModalViewController:alertController animated:YES];
+//    [parent presentViewController:alertController animated:YES completion:nil];
+//    return alertController;
+//
+//}
++(UIAlertController*) waiting_alert:(UIViewController*)parent title:(NSString*) title completion:(void (^ __nullable)(void))completion
 {
-    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:@"Please wait..." preferredStyle:UIAlertControllerStyleAlert];
-    [parent presentViewController:alertController animated:YES completion:nil];
-    return alertController;
+    
+    return [self waiting_alert:parent message:@"Please wait..." title:title completion:completion];
+//    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:@"Please wait..." preferredStyle:UIAlertControllerStyleAlert];
+//    
+//    [parent presentViewController:alertController animated:YES completion:completion];
+//    return alertController;
 
 }
-
-+(UIAlertController*) waiting_alert:(UIViewController*)parent message:(NSString*)msg title:(NSString*) title
+//+(UIAlertController*) waiting_alert:(UIViewController*)parent message:(NSString*)msg title:(NSString*) title
+//{
+//    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert];
+//    [parent presentViewController:alertController animated:YES completion:nil];
+//    return alertController;
+//
+//}
++(UIAlertController*) waiting_alert:(UIViewController*)parent message:(NSString*)msg title:(NSString*) title completion:(void (^ __nullable)(void))completion
 {
     UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert];
-    [parent presentViewController:alertController animated:YES completion:nil];
+    [parent presentViewController:alertController animated:YES completion:completion];
     return alertController;
 
 }
@@ -591,6 +609,25 @@
     [vc presentViewController:alertController animated:YES completion:nil];
     return alertController;
 
+}
+
++(UIAlertController*) message_alert :(NSString*) msg title:(NSString*) title controller:(UIViewController*) vc action_handler:(void (^ __nullable)(UIAlertAction *action))action_handler completion:(void (^ __nullable)(void))completion
+{
+    if(title==nil)
+        title = @"Message";
+    if ([title isEqualToString:@"Add To Cart"]) {
+        if ([msg hasPrefix:@"Out of Stock.\n"]) {
+            title = @"Add To Cart: Out of Stock";
+            msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
+        }
+    }
+    
+    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert];
+    UIAlertAction *action_0 = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:action_handler];
+    [alertController addAction:action_0];
+    [vc presentViewController:alertController animated:YES completion:completion];
+    return alertController;
+
 }
 //+(UIAlertView * ) waiting_alert :(NSString*) msg title:(NSString*) title
 //{

+ 2 - 2
RedAnt ERP Mobile/common/customUI/ImageUploadViewController.m

@@ -368,7 +368,7 @@
         __weak typeof(self) weakSelf = self;
         
         [NetworkUtils upload:imageData FileName:@"test.jpg" Params:params ToHost:URL_UPLOAD_IMG Result:^(NSMutableDictionary *result) {
-            dispatch_async(dispatch_get_main_queue(), ^{
+            
                 if([[result valueForKey:@"result"] intValue]==2)
                 {
                     NSString* img_url_down = result[@"img_url_aname"];
@@ -384,7 +384,7 @@
                 {
                     [RAUtils message_alert:[result valueForKey:@"err_msg"] title:@"Upload Image" controller:weakSelf] ;
                 }
-            });
+           
         } Progress:^(NSURLSessionTask *task, double progress) {
             dispatch_async(dispatch_get_main_queue(), ^{
                 [weakSelf.uploadProgress setProgress:progress animated:YES];

+ 2 - 2
RedAnt ERP Mobile/common/data_provider/RANetwork.h

@@ -102,7 +102,7 @@ extern NSString *const ScreenCodeOfflineSync;
 //+(NSDictionary*) portfolio_setPrice:(NSString*) watchlist_id price:(float) price discount:(float) discount QTY:(int)qty qty_p:(float) qty_p notes:(NSString*)notes;
 //+(NSDictionary*) portfolio_setQTY:(NSString*) watchlist_id QTY:(int)qty;
 
-+(NSDictionary*) cart_remove:(NSString* ) item_ids;
+//+(NSDictionary*) cart_remove:(NSString* ) item_ids;
 //+(NSDictionary*) cart_check:(NSString* ) item_ids;
 //+(NSDictionary*) watchlist_remove:(NSString* ) item_ids;
 
@@ -141,7 +141,7 @@ extern NSString *const ScreenCodeOfflineSync;
 
 
 //+(NSDictionary*)request_PDFList:(int ) offset limit:(int)limit keywords:(NSString* ) keywords ;
-+(NSDictionary*)request_TearSheet:(NSMutableDictionary*)params;
+//+(NSDictionary*)request_TearSheet:(NSMutableDictionary*)params;
 //+(NSDictionary*)save_TearSheet:(NSMutableDictionary *)params;
 //+(NSDictionary*)direct_save_TearSheet:(NSMutableDictionary*)params;//(NSString*) request_url name:(NSString*)name delete:(NSString* )ids note:(NSString* )saveNote modelIds:(NSDictionary *)modelIds;
 

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 568 - 389
RedAnt ERP Mobile/common/data_provider/RANetwork.m


+ 4 - 1
RedAnt ERP Mobile/common/data_provider/iSalesDB.h

@@ -13,10 +13,13 @@
 
 typedef void(^queryBlock)(sqlite3_stmt *stmt,NSMutableDictionary *container,long *count);
 typedef void(^failureBlock)(NSMutableDictionary *container,NSString *err_msg);
-
+static bool btrigger = true;
 @interface iSalesDB : NSObject
 
 
++(void) disable_trigger;
++(void) enable_trigger;
+
 //+(void)testdata;
 + (int) initializeDb;
 +(int)execSql:(NSString *)sql db:(sqlite3 *)db;

+ 22 - 11
RedAnt ERP Mobile/common/data_provider/iSalesDB.m

@@ -8,7 +8,7 @@
 
 #import "iSalesDB.h"
 #import "AESCrypt.h"
-#import "AppDelegate.h"
+//#import "AppDelegate.h"
 #import "Singleton.h"
 
 NSLock *dblock ;
@@ -41,8 +41,8 @@ int count_dbconn;
 }
 
 void offline_dirty(sqlite3_context *context, int argc, sqlite3_value **argv) {
-    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-    if(!appDelegate.disable_trigger)
+//    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+    if(btrigger)
     {
     NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
     [defaults removeObjectForKey:@"OFFLINE_DIRTY"];
@@ -453,10 +453,10 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
 }
 + (void) save_pdf: (NSString*) temp_path filename:(NSString*) filename
 {
-    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-    
-    if(appDelegate.bEnable_Cache==false)
-        return ;
+//    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+//
+//    if(appDelegate.bEnable_Cache==false)
+//        return ;
     if(temp_path==nil)
         return;
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
@@ -523,10 +523,10 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
     if(path.length==0)
         path=@"";
     
-    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-    
-    if(appDelegate.bEnable_Cache==false)
-        return ;
+//    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+//
+//    if(appDelegate.bEnable_Cache==false)
+//        return ;
     if(imgData==nil)
         return;
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
@@ -1009,6 +1009,7 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
         sqlite3_finalize(statement);
     }
     //   [iSalesDB close_db:db];
+    assert(ret>=0);
     return ret;
 }
 + (int) get_recordid:(NSString*) tablename where:(NSString*) whereclause order:(NSString*) orderby
@@ -1244,4 +1245,14 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
     return ret;
 }
 
+
+#pragma mark trigger control
++(void) disable_trigger
+{
+    btrigger = false;
+}
++(void) enable_trigger
+{
+    btrigger = true;
+}
 @end

+ 5 - 11
RedAnt ERP Mobile/iSales-NPD.xcodeproj/project.pbxproj

@@ -69,7 +69,6 @@
 		42BEAB381FA1D23B0024D647 /* EnumSelectAndSortViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 42BEAB341FA1D23A0024D647 /* EnumSelectAndSortViewController.m */; };
 		42BEF34F1E89FE1100632AB6 /* FirebaseAnalytics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 42BEF3241E89FE1100632AB6 /* FirebaseAnalytics.framework */; };
 		42BEF3501E89FE1100632AB6 /* FirebaseCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 42BEF3271E89FE1100632AB6 /* FirebaseCore.framework */; };
-		42BEF3511E89FE1200632AB6 /* CHANGELOG.md in Sources */ = {isa = PBXBuildFile; fileRef = 42BEF3291E89FE1100632AB6 /* CHANGELOG.md */; };
 		42BEF3521E89FE1200632AB6 /* FirebaseInstanceID.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 42BEF32B1E89FE1100632AB6 /* FirebaseInstanceID.framework */; };
 		42BEF3541E89FE1200632AB6 /* GGLAnalytics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 42BEF32F1E89FE1100632AB6 /* GGLAnalytics.framework */; };
 		42BEF3551E89FE1200632AB6 /* GGLCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 42BEF3301E89FE1100632AB6 /* GGLCore.framework */; };
@@ -86,7 +85,6 @@
 		42D3A4A21EFA6D36007A54C1 /* PhotoList.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 42D3A49D1EFA6D36007A54C1 /* PhotoList.storyboard */; };
 		42D3A4A31EFA6D36007A54C1 /* PhotoPreviewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 42D3A4A01EFA6D36007A54C1 /* PhotoPreviewCell.m */; };
 		42D3A4A61EFA7346007A54C1 /* VideoPreviewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 42D3A4A51EFA7346007A54C1 /* VideoPreviewCell.m */; };
-		42D9A0231EB02DA6008AF7AF /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 42D9A0221EB02DA6008AF7AF /* AdSupport.framework */; };
 		42D9A0251EB03994008AF7AF /* libAdIdAccess.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 42D9A0241EB03994008AF7AF /* libAdIdAccess.a */; };
 		42DC12F11F0CD98E00A4C011 /* OrderDetailPickInfoCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 42DC12F01F0CD98E00A4C011 /* OrderDetailPickInfoCell.m */; };
 		42DC31131D546FBE00BCD1C6 /* category.json in Resources */ = {isa = PBXBuildFile; fileRef = 42DC31121D546FBE00BCD1C6 /* category.json */; };
@@ -128,11 +126,11 @@
 		7141DD4E1C57459B00F7DF59 /* bitstream.c in Sources */ = {isa = PBXBuildFile; fileRef = 7141DD3E1C57459B00F7DF59 /* bitstream.c */; };
 		7141DD4F1C57459B00F7DF59 /* mask.c in Sources */ = {isa = PBXBuildFile; fileRef = 7141DD401C57459B00F7DF59 /* mask.c */; };
 		7141DD501C57459B00F7DF59 /* QRCodeGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 7141DD431C57459B00F7DF59 /* QRCodeGenerator.m */; };
-		7141DD511C57459B00F7DF59 /* qrencode.c in Sources */ = {isa = PBXBuildFile; fileRef = 7141DD441C57459B00F7DF59 /* qrencode.c */; };
+		7141DD511C57459B00F7DF59 /* qrencode.c in Sources */ = {isa = PBXBuildFile; fileRef = 7141DD441C57459B00F7DF59 /* qrencode.c */; settings = {COMPILER_FLAGS = "-Wno-shorten-64-to-32"; }; };
 		7141DD521C57459B00F7DF59 /* qrinput.c in Sources */ = {isa = PBXBuildFile; fileRef = 7141DD461C57459B00F7DF59 /* qrinput.c */; };
 		7141DD531C57459B00F7DF59 /* qrspec.c in Sources */ = {isa = PBXBuildFile; fileRef = 7141DD481C57459B00F7DF59 /* qrspec.c */; };
 		7141DD541C57459B00F7DF59 /* rscode.c in Sources */ = {isa = PBXBuildFile; fileRef = 7141DD4A1C57459B00F7DF59 /* rscode.c */; };
-		7141DD551C57459B00F7DF59 /* split.c in Sources */ = {isa = PBXBuildFile; fileRef = 7141DD4C1C57459B00F7DF59 /* split.c */; };
+		7141DD551C57459B00F7DF59 /* split.c in Sources */ = {isa = PBXBuildFile; fileRef = 7141DD4C1C57459B00F7DF59 /* split.c */; settings = {COMPILER_FLAGS = "-Wno-shorten-64-to-32"; }; };
 		7141DD5F1C5747CE00F7DF59 /* AESCrypt.m in Sources */ = {isa = PBXBuildFile; fileRef = 7141DD571C5747CE00F7DF59 /* AESCrypt.m */; };
 		7141DD611C5747CE00F7DF59 /* NSData+Base64.m in Sources */ = {isa = PBXBuildFile; fileRef = 7141DD5A1C5747CE00F7DF59 /* NSData+Base64.m */; };
 		7141DD621C5747CE00F7DF59 /* NSData+CommonCrypto.m in Sources */ = {isa = PBXBuildFile; fileRef = 7141DD5C1C5747CE00F7DF59 /* NSData+CommonCrypto.m */; };
@@ -242,7 +240,7 @@
 		71BBA2291CEAC17E00C91DED /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 71BBA2281CEAC17E00C91DED /* libz.tbd */; };
 		71BBA2401CEAEF0700C91DED /* ioapi.c in Sources */ = {isa = PBXBuildFile; fileRef = 71BBA2381CEAEF0700C91DED /* ioapi.c */; };
 		71BBA2411CEAEF0700C91DED /* mztools.c in Sources */ = {isa = PBXBuildFile; fileRef = 71BBA23A1CEAEF0700C91DED /* mztools.c */; };
-		71BBA2421CEAEF0700C91DED /* unzip.c in Sources */ = {isa = PBXBuildFile; fileRef = 71BBA23C1CEAEF0700C91DED /* unzip.c */; };
+		71BBA2421CEAEF0700C91DED /* unzip.c in Sources */ = {isa = PBXBuildFile; fileRef = 71BBA23C1CEAEF0700C91DED /* unzip.c */; settings = {COMPILER_FLAGS = "-Wno-dangling-else"; }; };
 		71BBA2431CEAEF0700C91DED /* zip.c in Sources */ = {isa = PBXBuildFile; fileRef = 71BBA23E1CEAEF0700C91DED /* zip.c */; };
 		71BF06FB1D2F3CAC00981938 /* OLDataProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 71BF06FA1D2F3CAC00981938 /* OLDataProvider.m */; };
 		71BF06FE1D2F3CBA00981938 /* OfflineSettingViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 71BF06FD1D2F3CBA00981938 /* OfflineSettingViewController.m */; };
@@ -441,7 +439,6 @@
 		42D3A4A01EFA6D36007A54C1 /* PhotoPreviewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PhotoPreviewCell.m; sourceTree = "<group>"; };
 		42D3A4A41EFA7346007A54C1 /* VideoPreviewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VideoPreviewCell.h; sourceTree = "<group>"; };
 		42D3A4A51EFA7346007A54C1 /* VideoPreviewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VideoPreviewCell.m; sourceTree = "<group>"; };
-		42D9A0221EB02DA6008AF7AF /* AdSupport.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AdSupport.framework; path = System/Library/Frameworks/AdSupport.framework; sourceTree = SDKROOT; };
 		42D9A0241EB03994008AF7AF /* libAdIdAccess.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libAdIdAccess.a; sourceTree = "<group>"; };
 		42DC12EF1F0CD98E00A4C011 /* OrderDetailPickInfoCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OrderDetailPickInfoCell.h; path = common/Functions/order/OrderDetailPickInfoCell.h; sourceTree = SOURCE_ROOT; };
 		42DC12F01F0CD98E00A4C011 /* OrderDetailPickInfoCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OrderDetailPickInfoCell.m; path = common/Functions/order/OrderDetailPickInfoCell.m; sourceTree = SOURCE_ROOT; };
@@ -847,7 +844,6 @@
 			buildActionMask = 2147483647;
 			files = (
 				42D9A0251EB03994008AF7AF /* libAdIdAccess.a in Frameworks */,
-				42D9A0231EB02DA6008AF7AF /* AdSupport.framework in Frameworks */,
 				42BEF35F1E89FEE300632AB6 /* CoreData.framework in Frameworks */,
 				42BEF35D1E89FECD00632AB6 /* SystemConfiguration.framework in Frameworks */,
 				71BBA2291CEAC17E00C91DED /* libz.tbd in Frameworks */,
@@ -1136,7 +1132,6 @@
 		42BEF35B1E89FECC00632AB6 /* Frameworks */ = {
 			isa = PBXGroup;
 			children = (
-				42D9A0221EB02DA6008AF7AF /* AdSupport.framework */,
 				42BEF35E1E89FEE300632AB6 /* CoreData.framework */,
 				42BEF35C1E89FECD00632AB6 /* SystemConfiguration.framework */,
 			);
@@ -2290,7 +2285,6 @@
 				7162A5471C58719D00AB630E /* RATreeView+Private.m in Sources */,
 				428980041E2490C1005F1BD8 /* NotificationNameCenter.m in Sources */,
 				4289802C1E2492D2005F1BD8 /* CategoryPriceViewController.m in Sources */,
-				42BEF3511E89FE1200632AB6 /* CHANGELOG.md in Sources */,
 				71DF748D1C57608F00F2789C /* TouchLabel.m in Sources */,
 				428980171E24924D005F1BD8 /* SortItemViewController.m in Sources */,
 				42D3A4A11EFA6D36007A54C1 /* ContentPreviewController.m in Sources */,
@@ -2484,7 +2478,7 @@
 				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
 				CODE_SIGN_IDENTITY = "iPhone Developer";
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
-				CURRENT_PROJECT_VERSION = 200211;
+				CURRENT_PROJECT_VERSION = 200515;
 				DEVELOPMENT_TEAM = HXWLAA5YN5;
 				FRAMEWORK_SEARCH_PATHS = (
 					"$(inherited)",
@@ -2528,7 +2522,7 @@
 				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
 				CODE_SIGN_IDENTITY = "iPhone Developer";
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
-				CURRENT_PROJECT_VERSION = 200211;
+				CURRENT_PROJECT_VERSION = 200515;
 				DEVELOPMENT_TEAM = HXWLAA5YN5;
 				FRAMEWORK_SEARCH_PATHS = (
 					"$(inherited)",

+ 4 - 2
RedAnt ERP Mobile/iSales-NPD/config.h

@@ -9,7 +9,9 @@
 #ifndef RedAnt_ERP_Mobile_config_h
 #define RedAnt_ERP_Mobile_config_h
 #define BUILD_NPD
-#define GOOGLE_ANALYTICS
+
+#define RA_NOTIFICATION
+//#define GOOGLE_ANALYTICS
 #define BACKORDER_PROCESS // 允许backorder process
 
 # ifdef DEBUG
@@ -27,7 +29,7 @@
 
 
 #define OFFLINE_MODE
-#define GOOGLE_ANALYTICS
+
 #define PDF_DEBUG false
 
 //#define ENCRYPT_OFF

+ 2 - 2
RedAnt ERP Mobile/iSales-UNITED WAVER.xcodeproj/project.pbxproj

@@ -2483,7 +2483,7 @@
 				CODE_SIGN_IDENTITY = "iPhone Developer";
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
 				CODE_SIGN_STYLE = Automatic;
-				CURRENT_PROJECT_VERSION = 200107;
+				CURRENT_PROJECT_VERSION = 200502;
 				DEVELOPMENT_TEAM = HXWLAA5YN5;
 				FRAMEWORK_SEARCH_PATHS = (
 					"$(inherited)",
@@ -2529,7 +2529,7 @@
 				CODE_SIGN_IDENTITY = "iPhone Developer";
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
 				CODE_SIGN_STYLE = Automatic;
-				CURRENT_PROJECT_VERSION = 200107;
+				CURRENT_PROJECT_VERSION = 200502;
 				DEVELOPMENT_TEAM = HXWLAA5YN5;
 				FRAMEWORK_SEARCH_PATHS = (
 					"$(inherited)",

+ 10 - 10
common/InfinitePhoto/Controller/RAPhotoPreviewController.m

@@ -167,20 +167,20 @@
 #pragma mark - CollectionView Delegate
 
 - (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
-
-    if (self.initialized) {
-        
-        NSUInteger idx = [self contentOffsetForIndexPath:indexPath];
-        PhotoPreviewCell *preCell = (PhotoPreviewCell *)cell;
-        id<RAPhotoItemDelegate> model = [self.photos objectAtIndex:idx];
-//        preCell.model = model;
-    }
+//
+//    if (self.initialized) {
+//
+//        NSUInteger idx = [self contentOffsetForIndexPath:indexPath];
+//        PhotoPreviewCell *preCell = (PhotoPreviewCell *)cell;
+//        id<RAPhotoItemDelegate> model = [self.photos objectAtIndex:idx];
+////        preCell.model = model;
+//    }
 }
 
 - (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
     
-    PhotoPreviewCell *preCell = (PhotoPreviewCell *)cell;
-//    [preCell reset];
+//    PhotoPreviewCell *preCell = (PhotoPreviewCell *)cell;
+////    [preCell reset];
 }
 
 #pragma mark - CollectionView DataSource

+ 344 - 327
common/WK PDF+Web/RAPDFViewController.m

@@ -210,214 +210,216 @@
 
 -(void) loadcontent
 {
-    
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Loading..."];
     self.mum.hidden=false;
-    
-    if(self.isLocalfile)
-    {
-        /*
-        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
-        NSString *cachefolder = [paths objectAtIndex:0];
-        NSString *pdfFolder = [cachefolder stringByAppendingPathComponent:@"pdf_cache"];
-        self.url = [pdfFolder stringByAppendingPathComponent:self.url];
-        */
-        
-        self.content= [NSData dataWithContentsOfFile:self.url];
-        
-        [waitalert dismissViewControllerAnimated:YES completion:nil];
-        
-//        [waitalert dismissViewControllerAnimated:YES completion:nil];
-        
-        if (self.filename.length <= 0) {
-            self.filename=[self.url lastPathComponent];
-        } else {
-            [self copyTmpLocalFile:self.url];
-        }
-        
-        self.btnshare.enabled =true;
-        
-        
-        self.btnemail.enabled =true;
-        self.btnsave.enabled =true;
-        
-//        if(self.onLoadSuccess)
-//        self.onLoadSuccess(self.url);
-//        
-//        if(self.autoPrint)
-//        [self startAirPrintWithData:self.content];
-        
-//        NSLog(@"put file to webview");
-//        [self.webView loadData:self.content MIMEType:@"application/pdf" textEncodingName:nil baseURL:nil];
-        
-        NSURL *url = [NSURL fileURLWithPath:self.url];
-        NSURLRequest *request = [NSURLRequest requestWithURL:url];
-        [self.wkWebview loadRequest:request];
-        
-    }
-    else
-    {
-        
-        [RANetwork request_fastdownload:nil url:self.url completionHandler:^(NSMutableDictionary *result) {
-            self.content= result[@"data"];
-            if(self.filename.length<=0)
-                self.filename = result[@"suggestedFilename"];
-            
-            
-            [waitalert dismissViewControllerAnimated:YES completion:^{
-                [[self navigationController] setNavigationBarHidden:self.hidenavi animated:NO];
-                self.navigationItem.title = self.save_name;
-                UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
-                //  self.content=nil;
-                if(self.content!=nil&&self.content.length>0)
-                {
-                    [reF removeFromSuperview];
-                    
-                    
-                    // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
-                    NSString *path = NSTemporaryDirectory();
-                    NSString *filePath = [path stringByAppendingPathComponent:self.filename];
-                    //    NSError *error = nil;
-                    //    BOOL bo = [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
-                    //    NSAssert(bo,@"创建目录失败");
-                    if (self.cachePath.length) {
-                        filePath = self.cachePath;
-                    }
-                    
-                    [self.content writeToFile:filePath atomically:YES];
-                    
-                    self.url = filePath;
-                    self.isLocalfile = true;
-                    
-                    
-                    self.btnshare.enabled =true;
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Loading..." completion:^{
+        if(self.isLocalfile)
+            {
+                /*
+                NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
+                NSString *cachefolder = [paths objectAtIndex:0];
+                NSString *pdfFolder = [cachefolder stringByAppendingPathComponent:@"pdf_cache"];
+                self.url = [pdfFolder stringByAppendingPathComponent:self.url];
+                */
+                
+                self.content= [NSData dataWithContentsOfFile:self.url];
+                
+                [waitalert dismissViewControllerAnimated:YES completion:nil];
+                
+        //        [waitalert dismissViewControllerAnimated:YES completion:nil];
+                
+                if (self.filename.length <= 0) {
+                    self.filename=[self.url lastPathComponent];
+                } else {
+                    [self copyTmpLocalFile:self.url];
+                }
+                
+                self.btnshare.enabled =true;
+                
+                
+                self.btnemail.enabled =true;
+                self.btnsave.enabled =true;
+                
+        //        if(self.onLoadSuccess)
+        //        self.onLoadSuccess(self.url);
+        //
+        //        if(self.autoPrint)
+        //        [self startAirPrintWithData:self.content];
+                
+        //        NSLog(@"put file to webview");
+        //        [self.webView loadData:self.content MIMEType:@"application/pdf" textEncodingName:nil baseURL:nil];
+                
+                NSURL *url = [NSURL fileURLWithPath:self.url];
+                NSURLRequest *request = [NSURLRequest requestWithURL:url];
+                [self.wkWebview loadRequest:request];
+                
+            }
+            else
+            {
+                
+                [RANetwork request_fastdownload:nil url:self.url completionHandler:^(NSMutableDictionary *result) {
+                    self.content= result[@"data"];
+                    if(self.filename.length<=0)
+                        self.filename = result[@"suggestedFilename"];
                     
                     
-                    self.btnemail.enabled =true;
-                    self.btnsave.enabled =true;
+                    [waitalert dismissViewControllerAnimated:YES completion:^{
+                        [[self navigationController] setNavigationBarHidden:self.hidenavi animated:NO];
+                        self.navigationItem.title = self.save_name;
+                        UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
+                        //  self.content=nil;
+                        if(self.content!=nil&&self.content.length>0)
+                        {
+                            [reF removeFromSuperview];
+                            
+                            
+                            // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+                            NSString *path = NSTemporaryDirectory();
+                            NSString *filePath = [path stringByAppendingPathComponent:self.filename];
+                            //    NSError *error = nil;
+                            //    BOOL bo = [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
+                            //    NSAssert(bo,@"创建目录失败");
+                            if (self.cachePath.length) {
+                                filePath = self.cachePath;
+                            }
+                            
+                            [self.content writeToFile:filePath atomically:YES];
+                            
+                            self.url = filePath;
+                            self.isLocalfile = true;
+                            
+                            
+                            self.btnshare.enabled =true;
+                            
+                            
+                            self.btnemail.enabled =true;
+                            self.btnsave.enabled =true;
+                            
+                            
+                            
+                            NSURL *url = [NSURL fileURLWithPath:filePath];
+                            NSURLRequest *request = [NSURLRequest requestWithURL:url];
+                            [self.wkWebview loadRequest:request];
+                            
+                            
+                        }
+                        else
+                        {
+                            [RAUtils message_alert:nil  title:@"Open PDF Failed" controller:self];
+                            
+                            if(self.autoPrint)
+                                [self.navigationController popViewControllerAnimated:true];
+                        }
+                    }];
                     
                     
                     
-                    NSURL *url = [NSURL fileURLWithPath:filePath];
-                    NSURLRequest *request = [NSURLRequest requestWithURL:url];
-                    [self.wkWebview loadRequest:request];
                     
                     
-                }
-                else
-                {
-                    [RAUtils message_alert:nil  title:@"Open PDF Failed" controller:self];
                     
-                    if(self.autoPrint)
-                        [self.navigationController popViewControllerAnimated:true];
-                }
-            }];
-            
-            
-            
-            
-            
-            
-        }];
+                }];
 
-        
-        
-        
-//        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-//
-//                NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:self.url]        cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60*5];
-//
-//                //设置请求方式为get
-//
-//                [request setHTTPMethod:@"GET"];
-//
-//                //添加用户会话id
-//
-//                [request addValue:@"text/html" forHTTPHeaderField:@"Content-Type"];
-//
-//                //连接发送请求
-//
-//
-//                NSHTTPURLResponse* urlResponse = nil;
-//
-//                NSError *error = nil;
-//
-//                self.content= [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
-//
-//                if(self.filename.length<=0)
-//                    self.filename = [urlResponse suggestedFilename];
-//
-//
-//                dispatch_async(dispatch_get_main_queue(), ^{
-//                    [waitalert dismissViewControllerAnimated:YES completion:nil];
-//
-//                    [[self navigationController] setNavigationBarHidden:self.hidenavi animated:NO];
-//                    self.navigationItem.title = self.save_name;
-//                    UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
-//                  //  self.content=nil;
-//                    if(self.content!=nil&&self.content.length>0)
-//                    {
-//                        [reF removeFromSuperview];
-//
-//
-//                       // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
-//                        NSString *path = NSTemporaryDirectory();
-//                        NSString *filePath = [path stringByAppendingPathComponent:self.filename];
-//                        //    NSError *error = nil;
-//                        //    BOOL bo = [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
-//                        //    NSAssert(bo,@"创建目录失败");
-//                        if (self.cachePath.length) {
-//                            filePath = self.cachePath;
-//                        }
-//
-//                        [self.content writeToFile:filePath atomically:YES];
-//
-//                        self.url = filePath;
-//                        self.isLocalfile = true;
-//
-//
-//                        self.btnshare.enabled =true;
-//
-//
-//                        self.btnemail.enabled =true;
-//                        self.btnsave.enabled =true;
-//
-//
-//
-//                        NSURL *url = [NSURL fileURLWithPath:filePath];
-//                        NSURLRequest *request = [NSURLRequest requestWithURL:url];
-//                        [self.wkWebview loadRequest:request];
-//
-//
-//
-//
-//
-//
-//         //               int a=0;
-//                    }
-//                    else
-//                    {
-//                        [RAUtils message_alert:nil  title:@"Open PDF Failed" controller:self];
-//
-//                        if(self.autoPrint)
-//                            [self.navigationController popViewControllerAnimated:true];
-//        //                self.content = [self.url dataUsingEncoding:NSUTF8StringEncoding];
-//                    }
-//
-//                    ;
-//        //            DebugLog(@"%@",[[NSString alloc] initWithData:self.content encoding:NSASCIIStringEncoding]);
-//                    //
-//
-//        //            DebugLog(urlResponse.MIMEType);
-//
-//        //            [self.webView loadData:self.content MIMEType:urlResponse.MIMEType textEncodingName:nil baseURL:nil];
-//
-//
-//
-//
-//                });
-//        });
-    }
+                
+                
+                
+        //        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+        //
+        //                NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:self.url]        cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60*5];
+        //
+        //                //设置请求方式为get
+        //
+        //                [request setHTTPMethod:@"GET"];
+        //
+        //                //添加用户会话id
+        //
+        //                [request addValue:@"text/html" forHTTPHeaderField:@"Content-Type"];
+        //
+        //                //连接发送请求
+        //
+        //
+        //                NSHTTPURLResponse* urlResponse = nil;
+        //
+        //                NSError *error = nil;
+        //
+        //                self.content= [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
+        //
+        //                if(self.filename.length<=0)
+        //                    self.filename = [urlResponse suggestedFilename];
+        //
+        //
+        //                dispatch_async(dispatch_get_main_queue(), ^{
+        //                    [waitalert dismissViewControllerAnimated:YES completion:nil];
+        //
+        //                    [[self navigationController] setNavigationBarHidden:self.hidenavi animated:NO];
+        //                    self.navigationItem.title = self.save_name;
+        //                    UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
+        //                  //  self.content=nil;
+        //                    if(self.content!=nil&&self.content.length>0)
+        //                    {
+        //                        [reF removeFromSuperview];
+        //
+        //
+        //                       // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+        //                        NSString *path = NSTemporaryDirectory();
+        //                        NSString *filePath = [path stringByAppendingPathComponent:self.filename];
+        //                        //    NSError *error = nil;
+        //                        //    BOOL bo = [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
+        //                        //    NSAssert(bo,@"创建目录失败");
+        //                        if (self.cachePath.length) {
+        //                            filePath = self.cachePath;
+        //                        }
+        //
+        //                        [self.content writeToFile:filePath atomically:YES];
+        //
+        //                        self.url = filePath;
+        //                        self.isLocalfile = true;
+        //
+        //
+        //                        self.btnshare.enabled =true;
+        //
+        //
+        //                        self.btnemail.enabled =true;
+        //                        self.btnsave.enabled =true;
+        //
+        //
+        //
+        //                        NSURL *url = [NSURL fileURLWithPath:filePath];
+        //                        NSURLRequest *request = [NSURLRequest requestWithURL:url];
+        //                        [self.wkWebview loadRequest:request];
+        //
+        //
+        //
+        //
+        //
+        //
+        //         //               int a=0;
+        //                    }
+        //                    else
+        //                    {
+        //                        [RAUtils message_alert:nil  title:@"Open PDF Failed" controller:self];
+        //
+        //                        if(self.autoPrint)
+        //                            [self.navigationController popViewControllerAnimated:true];
+        //        //                self.content = [self.url dataUsingEncoding:NSUTF8StringEncoding];
+        //                    }
+        //
+        //                    ;
+        //        //            DebugLog(@"%@",[[NSString alloc] initWithData:self.content encoding:NSASCIIStringEncoding]);
+        //                    //
+        //
+        //        //            DebugLog(urlResponse.MIMEType);
+        //
+        //        //            [self.webView loadData:self.content MIMEType:urlResponse.MIMEType textEncodingName:nil baseURL:nil];
+        //
+        //
+        //
+        //
+        //                });
+        //        });
+            }
+    }];
+    
+    
+    
     
     
     
@@ -956,131 +958,39 @@
 {
     
     
-    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"preparing print..."];
-    
-    UIPrintInteractionController* airPrinterController=[UIPrintInteractionController sharedPrintController];
-    UIPrintInfo *printInfo = [UIPrintInfo printInfo];
-    printInfo.outputType = UIPrintInfoOutputGeneral;
-    printInfo.orientation = UIPrintInfoOrientationPortrait;
-    printInfo.jobName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];
-    if(self.filename.length>0)
-        printInfo.jobName = self.filename;
-    airPrinterController.printInfo = printInfo;
-    airPrinterController.printingItem = data;
-    airPrinterController.delegate = self;
-    
-    
-    airPrinterController.showsNumberOfCopies=true;
-//    airPrinterController.showsPageRange = true;
-    airPrinterController.showsPaperSelectionForLoadedPapers=true;
-    
-    void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
-        if(completed && error)
-        {
-            //                        DebugLog(@"Printing failed due to error in domain %@ with error code %lu. Localized description: %@, and failure reason: %@", error.domain, (long)error.code, error.localizedDescription, error.localizedFailureReason);
-        }
-        
-    };
-    
-    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-    
-    
-    if(appDelegate.printerURL==nil)
-    {
-        [waitalert dismissViewControllerAnimated:YES completion:^{
-            if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
-            {
-                UIPrinterPickerController *printPicker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil];
-                //   [printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:yes completionHandler:
-                
-                
-                
-                //                 [ printPicker presentFromBarButtonItem:self.btnshare animated:YES completionHandler:
-                
-                
-                
-                [printPicker presentFromRect:CGRectMake(100, 100, 300, 500) inView:self.view animated:YES completionHandler:
-                 
-                 
-                 
-                 //        [printPicker presentAnimated:YES completionHandler:
-                 ^(UIPrinterPickerController *printerPicker, BOOL userDidSelect, NSError *error)
-                 {
-                     if (userDidSelect)
-                     {
-                         //User selected the item in the UIPrinterPickerController and got the printer details.
-                         
-                         [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printerPicker.selectedPrinter];
-                         
-                         //Here you will get the printer and printer details.ie,
-                         // printerPicker.selectedPrinter, printerPicker.selectedPrinter.displayName, printerPicker.selectedPrinter.URL etc. So you can display the printer name in your label text or button title.
-                         
-                         
-                         
-                         
-                         appDelegate.printerURL =printerPicker.selectedPrinter.URL.absoluteString;
-                         
-                         [self startAirPrintWithData:data];
-                         
-                     }
-                     else
-                     {
-                         
-                         
-                         //                          AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                         //                          if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
-                         //                          {
-                         //
-                         //                              [((MainViewController*)appDelegate.main_vc) Loginout:false];
-                         //                          }
-                         //                          [self prepareReturn:nil];
-                         
-                         //[self.navigationController popViewControllerAnimated:true];
-                     }
-                 }];
-            }
-        }];
-//        [waitalert dismissViewControllerAnimated:YES completion:nil];
+    __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"preparing print..." completion:^{
 
-    }
-    else
-    {
-        UIPrinter *airPrinter = [UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL] ];///*self.printer;*/
-        [airPrinter contactPrinter:^(BOOL available)
-         {
             
-            [waitalert dismissViewControllerAnimated:YES completion:^{
-                if (available&& appDelegate.printerURL.length>0)
+            UIPrintInteractionController* airPrinterController=[UIPrintInteractionController sharedPrintController];
+            UIPrintInfo *printInfo = [UIPrintInfo printInfo];
+            printInfo.outputType = UIPrintInfoOutputGeneral;
+            printInfo.orientation = UIPrintInfoOrientationPortrait;
+            printInfo.jobName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];
+            if(self.filename.length>0)
+                printInfo.jobName = self.filename;
+            airPrinterController.printInfo = printInfo;
+            airPrinterController.printingItem = data;
+            airPrinterController.delegate = self;
+            
+            
+            airPrinterController.showsNumberOfCopies=true;
+        //    airPrinterController.showsPageRange = true;
+            airPrinterController.showsPaperSelectionForLoadedPapers=true;
+            
+            void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
+                if(completed && error)
                 {
-                    
-                    
-                    [airPrinterController printToPrinter:airPrinter completionHandler:completionHandler];
-                    DebugLog(@"AIRPRINTER AVAILABLE");
+                    //                        DebugLog(@"Printing failed due to error in domain %@ with error code %lu. Localized description: %@, and failure reason: %@", error.domain, (long)error.code, error.localizedDescription, error.localizedFailureReason);
                 }
-                else
-                {
-                    appDelegate.printerURL = nil;
-                    
-                    //             [airPrinterController presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler:
-                    //
-                    //
-                    //
-                    //              //        [printPicker presentAnimated:YES completionHandler:
-                    //              ^(UIPrintInteractionController *printerController, BOOL userDidSelect, NSError *error)
-                    //              {
-                    //                  if (userDidSelect)
-                    //                  {
-                    //                      NSString* sid= printerController.printInfo.printerID;
-                    //                      UIPrintPaper*paper=  printerController.printPaper;
-                    //
-                    //                  }
-                    //              }];
-                    
-                    
-                    DebugLog(@"AIRPRINTER NOT AVAILABLE");
-                    
-                    
-                    
+                
+            };
+            
+            AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+            
+            
+            if(appDelegate.printerURL==nil)
+            {
+                [waitalert dismissViewControllerAnimated:YES completion:^{
                     if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
                     {
                         UIPrinterPickerController *printPicker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil];
@@ -1118,7 +1028,7 @@
                              }
                              else
                              {
-                                 appDelegate.printerURL = nil;
+                                 
                                  
                                  //                          AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
                                  //                          if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
@@ -1132,14 +1042,121 @@
                              }
                          }];
                     }
-                }
-            }];
-            
-//             [waitalert dismissViewControllerAnimated:YES completion:nil];
-             
+                }];
+        //        [waitalert dismissViewControllerAnimated:YES completion:nil];
 
-         }];
-    }
+            }
+            else
+            {
+                UIPrinter *airPrinter = [UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL] ];///*self.printer;*/
+                [airPrinter contactPrinter:^(BOOL available)
+                 {
+                    
+                    [waitalert dismissViewControllerAnimated:YES completion:^{
+                        if (available&& appDelegate.printerURL.length>0)
+                        {
+                            
+                            
+                            [airPrinterController printToPrinter:airPrinter completionHandler:completionHandler];
+                            DebugLog(@"AIRPRINTER AVAILABLE");
+                        }
+                        else
+                        {
+                            appDelegate.printerURL = nil;
+                            
+                            //             [airPrinterController presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler:
+                            //
+                            //
+                            //
+                            //              //        [printPicker presentAnimated:YES completionHandler:
+                            //              ^(UIPrintInteractionController *printerController, BOOL userDidSelect, NSError *error)
+                            //              {
+                            //                  if (userDidSelect)
+                            //                  {
+                            //                      NSString* sid= printerController.printInfo.printerID;
+                            //                      UIPrintPaper*paper=  printerController.printPaper;
+                            //
+                            //                  }
+                            //              }];
+                            
+                            
+                            DebugLog(@"AIRPRINTER NOT AVAILABLE");
+                            
+                            
+                            
+                            if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
+                            {
+                                UIPrinterPickerController *printPicker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil];
+                                //   [printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:yes completionHandler:
+                                
+                                
+                                
+                                //                 [ printPicker presentFromBarButtonItem:self.btnshare animated:YES completionHandler:
+                                
+                                
+                                
+                                [printPicker presentFromRect:CGRectMake(100, 100, 300, 500) inView:self.view animated:YES completionHandler:
+                                 
+                                 
+                                 
+                                 //        [printPicker presentAnimated:YES completionHandler:
+                                 ^(UIPrinterPickerController *printerPicker, BOOL userDidSelect, NSError *error)
+                                 {
+                                     if (userDidSelect)
+                                     {
+                                         //User selected the item in the UIPrinterPickerController and got the printer details.
+                                         
+                                         [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printerPicker.selectedPrinter];
+                                         
+                                         //Here you will get the printer and printer details.ie,
+                                         // printerPicker.selectedPrinter, printerPicker.selectedPrinter.displayName, printerPicker.selectedPrinter.URL etc. So you can display the printer name in your label text or button title.
+                                         
+                                         
+                                         
+                                         
+                                         appDelegate.printerURL =printerPicker.selectedPrinter.URL.absoluteString;
+                                         
+                                         [self startAirPrintWithData:data];
+                                         
+                                     }
+                                     else
+                                     {
+                                         appDelegate.printerURL = nil;
+                                         
+                                         //                          AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                                         //                          if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
+                                         //                          {
+                                         //
+                                         //                              [((MainViewController*)appDelegate.main_vc) Loginout:false];
+                                         //                          }
+                                         //                          [self prepareReturn:nil];
+                                         
+                                         //[self.navigationController popViewControllerAnimated:true];
+                                     }
+                                 }];
+                            }
+                        }
+                    }];
+                    
+        //             [waitalert dismissViewControllerAnimated:YES completion:nil];
+                     
+
+                 }];
+            }
+            
+            
+            
+            
+            
+            
+            
+            
+            
+            
+        
+    }];
+    
+   
     
     
     

+ 2 - 2
common/upload/RANetworkTaskDelegate.m

@@ -195,9 +195,9 @@
                 
                 
             }
-            
+            dispatch_async(dispatch_get_main_queue(), ^{
             self.r([jsobj mutableCopy]);
-            
+             });
         }
     }
 

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio