浏览代码

新增NPD Mobile 设置价格类型接口,并替换调用。
修复ERP Mobile 部分线程调度错误问题。
新增NPD Mobile 读写店铺价格设置接口,并替换调用。
新增ERP Mobile 创建portfolio接口,并替换调用。
新增ERP Mobile portfolio预览接口,并替换调用。
去掉部分无用的接口函数。
新增ERP Mobile item search接口,并替换调用。
新增NPD Mobile 查询model数量接口,并替换调用。
新增ERP Mobile portfolio设置价格接口,并替换调用。

Ray Zhang 6 年之前
父节点
当前提交
bfc5d6f79b

+ 51 - 25
RedAnt ERP Mobile/common/Functions/portfolio/PortfolioEditQTYViewController.m

@@ -120,35 +120,61 @@
         return;
     self.buttonRefresh.enabled=false;
     self.labelQueryQTY.text = @"Querying current available QTY...";
-    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-        
-        NSDictionary* detail_json = [RANetwork request_model_qty:self.arr_fashion_ids[0]];
+    
+    [RANetwork request_modelqty:self.arr_fashion_ids[0] completionHandler:^(NSMutableDictionary *result) {
+        NSDictionary* detail_json = result;
+        self.buttonRefresh.enabled=true;
+        //            NSDictionary* imgsection = [detail_json objectForKey:@"img_section"];
+        //          AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
         
-        dispatch_async(dispatch_get_main_queue(), ^{
-            self.buttonRefresh.enabled=true;
-//            NSDictionary* imgsection = [detail_json objectForKey:@"img_section"];
-            //          AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+        if([[detail_json valueForKey:@"result"] intValue]==2)
+        {
             
-            if([[detail_json valueForKey:@"result"] intValue]==2)
-            {
-                
-                NSString* qty = [detail_json valueForKey:@"quantity_available"];
-                self.labelQueryQTY.text = [NSString stringWithFormat:@"Current Available QTY: %@",qty];
-               // self.detailTable.hidden = false;
-                
-                
-            }
-            else
-
-                {
-                    self.labelQueryQTY.text=@"Tap Refresh to query current QTY";
-                    [RAUtils message_alert:[detail_json valueForKey:@"err_msg"] title:@"Request Available QTY"/*@"Loading Model Detail Failed."*/ controller:self] ;
-                }
+            NSString* qty = [detail_json valueForKey:@"quantity_available"];
+            self.labelQueryQTY.text = [NSString stringWithFormat:@"Current Available QTY: %@",qty];
+            // self.detailTable.hidden = false;
             
-           
             
-        });
-    });
+        }
+        else
+            
+        {
+            self.labelQueryQTY.text=@"Tap Refresh to query current QTY";
+            [RAUtils message_alert:[detail_json valueForKey:@"err_msg"] title:@"Request Available QTY"/*@"Loading Model Detail Failed."*/ controller:self] ;
+        }
+        
+        
+        
+    }];
+//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+//
+//        NSDictionary* detail_json = [RANetwork request_model_qty:self.arr_fashion_ids[0]];
+//
+//        dispatch_async(dispatch_get_main_queue(), ^{
+//            self.buttonRefresh.enabled=true;
+////            NSDictionary* imgsection = [detail_json objectForKey:@"img_section"];
+//            //          AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+//
+//            if([[detail_json valueForKey:@"result"] intValue]==2)
+//            {
+//
+//                NSString* qty = [detail_json valueForKey:@"quantity_available"];
+//                self.labelQueryQTY.text = [NSString stringWithFormat:@"Current Available QTY: %@",qty];
+//               // self.detailTable.hidden = false;
+//
+//
+//            }
+//            else
+//
+//                {
+//                    self.labelQueryQTY.text=@"Tap Refresh to query current QTY";
+//                    [RAUtils message_alert:[detail_json valueForKey:@"err_msg"] title:@"Request Available QTY"/*@"Loading Model Detail Failed."*/ controller:self] ;
+//                }
+//
+//
+//
+//        });
+//    });
 }
 - (IBAction)QTYPercentageValueChanged:(id)sender {
     UISwitch * switchqty =(UISwitch*)sender;

+ 46 - 5
RedAnt ERP Mobile/common/Functions/portfolio/PortfolioListViewController.m

@@ -555,7 +555,7 @@
     if(self.content_data.count== indexPath.row)
         return;
     NSString* name=[self.content_data[indexPath.row] valueForKey:@"tear_name"];
-    NSString* url= [self.content_data[indexPath.row] valueForKey:@"pdf_path"];
+    __block NSString* url= [self.content_data[indexPath.row] valueForKey:@"pdf_path"];
     
     if(url==nil)
     {
@@ -564,10 +564,51 @@
         NSMutableDictionary* values = [[RAConvertor string2dict:[self.content_data[indexPath.row] valueForKey:@"model_info"]] mutableCopy];
         params[@"replaceValue"]=values;
         params[@"tearsheetsId"]=[self.content_data[indexPath.row] valueForKey:@"tearsheetsId"];
-        NSString* createpdf = [RANetwork create_portfolio:params];
-        if(createpdf!=nil)
-            url=createpdf;
-       // if()
+        
+        [RANetwork request_create_portfolio:params completionHandler:^(NSMutableDictionary *result) {
+            //            NSString* createpdf = result;
+            url=result[@"pdf_path"];
+            
+            BOOL isLocalFile= [[self.content_data[indexPath.row] valueForKey:@"isLocalFile"] boolValue];
+            
+            RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
+            ViewController.url = url;
+            ViewController.canSave = false;
+            ViewController.isLocalfile=isLocalFile;
+            NSString* subject;
+            
+            subject =name;//[NSString stringWithFormat:@"NPD Product List %@",cur_time];
+            
+            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];
+                
+            }
+            ViewController.mail_to = send_to;
+            
+            
+            NSString* lfilename = [TextUtils legalFilename:name];
+            
+            
+            ViewController.filename = [NSString stringWithFormat:@"%@.pdf",lfilename];
+            ViewController.mail_subject = subject;
+            
+            ViewController.hidenavi = false;
+            [self.navigationController pushViewController:ViewController animated:YES];
+            
+            
+        }];
+        return;
+        
+        //        NSString* createpdf = [RANetwork create_portfolio:params];
+        //        if(createpdf!=nil)
+        //            url=createpdf;
+        // if()
         
     }
 

+ 570 - 225
RedAnt ERP Mobile/common/Functions/portfolio/PortfolioViewController.m

@@ -624,127 +624,337 @@
     
     
     UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Processing"];
-    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+    [RANetwork request_portfoliopreview:params completionHandler:^(NSMutableDictionary *result) {
+        NSDictionary* editor_json = result;
+        [waitalert dismissViewControllerAnimated:YES completion:nil];
         
-        NSDictionary* editor_json = [RANetwork request_TearSheet:params];
         
-        dispatch_async(dispatch_get_main_queue(), ^{
-            [waitalert dismissViewControllerAnimated:YES completion:nil];
+        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;
             
-            if([[editor_json valueForKey:@"result"] intValue]==2)
+            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)
             {
                 
-                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"];
                 
+                NSString* del_ids = nil;
                 
-                NSMutableArray* send_to = [[NSMutableArray alloc]init];
-                if(customer_email.length>0)
+                UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving..."];
+#ifdef OFFLINE_MODE
+                if (appDelegate.offline_mode)
                 {
-                    send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
+                    [params setValue:url forKey:@"pdfPath"];
                 }
-                ViewController.mail_to = send_to;
-                
-                NSString* subject;
-
-                subject =catelog_name;
-
-                ViewController.mail_subject = subject;
-                
-                ViewController.onSavePDF=^(NSString* name,NSString* file)
+                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"];
+                
+                [RANetwork request_save_portfolio:params completionHandler:^(NSMutableDictionary *result) {
+                    NSDictionary* json =result;
+                    [waitalert dismissViewControllerAnimated:YES completion:nil];
                     
                     
-                    NSString* del_ids = nil;
-                    
-                    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving..."];
-                    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"];
-                        
+                    if([[json valueForKey:@"result"] intValue]==2)
+                    {
                         
+                        [RAUtils message_alert:@"Portfolio saved. You can find it from View Portfolios" title:@"Portfolio" controller:self];
                         
-                        NSDictionary* json = [RANetwork save_TearSheet:params];
+                        //                                [RAUtils alert_view:nil title:@"Portfolio saved. You can find it from View Portfolios" ] ;
                         
-                        dispatch_async(dispatch_get_main_queue(), ^{
-                            [waitalert dismissViewControllerAnimated:YES completion:nil];
+                        [self.navigationController dismissViewControllerAnimated:true 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];
+                            [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];
+                            [((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] ;
-                            }
-                            
-                        });
-                    });
-                    
-                    
+                        }];
+                    }
+                    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] ;
-            }
+                //                    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] ;
+        }
+        
+    }];
+    
+//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+//
+//        NSDictionary* editor_json = [RANetwork request_TearSheet:params];
+//
+//        dispatch_async(dispatch_get_main_queue(), ^{
+//            [waitalert dismissViewControllerAnimated:YES completion:nil];
+//
+//
+//            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
+//                                            {
+//                                                [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: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] ;
+//                        }
+//
+//                    }];
+//
+////                    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] ;
+//            }
+//
+//        });
+//    });
     
 }
 
@@ -915,76 +1125,141 @@
                 
                 UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Updating Quantity"];
                 
-                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-                    
-                    NSDictionary* cart_json = nil;
+                [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:nil];
                     
-                    cart_json= [RANetwork portfolio_setPrice:[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"item_id"] intValue]] price:price discount:discount QTY:qty  qty_p:qty_p notes:notes];
                     
-                    dispatch_async(dispatch_get_main_queue(), ^{
-                        [waitalert dismissViewControllerAnimated:YES completion:nil];
+                    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([[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];
+                        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"];
                         }
-                        else
-                        {
-                            [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Edit Portfolio" controller:self] ;
+                        
+                        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];
+                        
+                    }
+                    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;
+//
+//                    cart_json= [RANetwork portfolio_setPrice:[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"item_id"] intValue]] price:price discount:discount QTY:qty  qty_p:qty_p notes:notes];
+//
+//                    dispatch_async(dispatch_get_main_queue(), ^{
+//                        [waitalert dismissViewControllerAnimated:YES completion:nil];
+//
+//
+//                        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];
+//
+//                        }
+//                        else
+//                        {
+//                            [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Edit Portfolio" controller:self] ;
+//                        }
+//
+//
+//
+//
+//                    });
+//                });
                 //
                 //
                 //
@@ -1054,32 +1329,51 @@
             
             
             UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Updating Quantity"];
-            
-            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+            [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:nil];
                 
-                NSDictionary* cart_json = nil;
                 
-                cart_json= [RANetwork portfolio_setPrice:ids price:price discount:discount QTY:qty qty_p:qty_p notes:notes];
+                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_main_queue(), ^{
-                    [waitalert dismissViewControllerAnimated:YES completion:nil];
-                    
-                    
-                    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;
+//
+//                cart_json= [RANetwork portfolio_setPrice:ids price:price discount:discount QTY:qty qty_p:qty_p notes:notes];
+//
+//                dispatch_async(dispatch_get_main_queue(), ^{
+//                    [waitalert dismissViewControllerAnimated:YES completion:nil];
+//
+//
+//                    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] ;
+//                    }
+//
+//
+//
+//
+//                });
+//            });
             //
             //
             //
@@ -1673,61 +1967,112 @@
             
             UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Updating Quantity"];
             
-            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+            [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 = nil;
+                NSDictionary* cart_json = result;
+                [waitalert dismissViewControllerAnimated:YES completion:nil];
                 
-                cart_json= [RANetwork portfolio_setPrice:[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"item_id"] intValue]] price:price discount:discount QTY:qty  qty_p:qty_p notes:notes];
                 
-                dispatch_async(dispatch_get_main_queue(), ^{
-                    [waitalert dismissViewControllerAnimated:YES completion:nil];
-                    
+                if([[cart_json valueForKey:@"result"] intValue]==2)
+                {
+                    self.editedRow = indexPath.row;
                     
-                    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"];
-                            
-                            // 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];
-                        }
+                    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"];
                         
-                        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] ;
+                        // 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];
+                }
+                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;
+//
+//                cart_json= [RANetwork portfolio_setPrice:[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"item_id"] intValue]] price:price discount:discount QTY:qty  qty_p:qty_p notes:notes];
+//
+//                dispatch_async(dispatch_get_main_queue(), ^{
+//                    [waitalert dismissViewControllerAnimated:YES completion:nil];
+//
+//
+//                    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"];
+//
+//                            // 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];
+//                    }
+//                    else
+//                    {
+//                        [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Edit Portfolio" controller:self] ;
+//                    }
+//
+//
+//
+//
+//                });
+//            });
 //
 //            
 //            
@@ -2179,7 +2524,7 @@ commitEditingStyle:(UITableViewCellEditingStyle)editingStyle  forRowAtIndexPath:
         
         reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
         
-        [RANetwork request_portfolio:self.sortIndex completionHandler:^(NSMutableDictionary *result) {
+        [RANetwork request_portfoliolist:self.sortIndex completionHandler:^(NSMutableDictionary *result) {
             NSMutableDictionary* cart_json =result;
             [self.mum stopAnimating];
             

+ 492 - 178
RedAnt ERP Mobile/common/Functions/portfolio/TearSheetParamViewController.m

@@ -283,176 +283,444 @@
     
     
     UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Processing"];
-    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+    [RANetwork request_portfoliopreview:upparams completionHandler:^(NSMutableDictionary *result) {
+        NSDictionary* editor_json = result;
         
-        NSDictionary* editor_json = [RANetwork request_TearSheet:upparams];
+        //            [waitalert dismissViewControllerAnimated:YES completion:nil];
+        [waitalert dismissViewControllerAnimated:YES completion:nil];
         
-        dispatch_async(dispatch_get_main_queue(), ^{
-//            [waitalert dismissViewControllerAnimated:YES completion:nil];
-            [waitalert dismissViewControllerAnimated:YES completion:nil];
+        
+        
+        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;
             
-            if([[editor_json valueForKey:@"result"] intValue]==2)
+            
+            
+            //  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)
             {
-                //                    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;
                 
                 
+                NSString* del_ids = nil;
+                if(bremove)
+                    del_ids=[self.params valueForKey:@"item_ids"];
                 
-                //  AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-                NSString* customer_email=    [appDelegate.customerInfo valueForKey:@"customer_email"];
+                UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving..."];
                 
                 
-                NSMutableArray* send_to = [[NSMutableArray alloc]init];
-                if(customer_email.length>0)
+#ifdef OFFLINE_MODE
+                if (appDelegate.offline_mode)
                 {
-                    send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
-                    //                            customer_email compo
-                    //                            [send_to addObject:customer_email];
+                    [upparams setValue:url forKey:@"pdfPath"];
                 }
-                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)
+                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"];
+                
+                [RANetwork request_save_portfolio:upparams completionHandler:^(NSMutableDictionary *result) {
                     
+                    NSDictionary* json =result;
+                    [waitalert dismissViewControllerAnimated:YES completion:nil];
                     
-                    NSString* del_ids = nil;
-                    if(bremove)
-                        del_ids=[self.params valueForKey:@"item_ids"];
                     
-                    UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving..."];
-                    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];
+                    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: ] ;
                         
-                        dispatch_async(dispatch_get_main_queue(), ^{
-                            [waitalert dismissViewControllerAnimated:YES completion:nil];
+                        [self.navigationController dismissViewControllerAnimated:true 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];
+                            [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];
+                            [((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] ;
-                            }
-                            
-                        });
-                    });
-                    
-                  
+                            //                                            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];
                 
+                //                    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] ;
+                //                            }
+                //
+                //                        });
+                //                    });
                 
-                /*
-                 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] ;
-            }
+                
+            };
             
+            //    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];
+//
+//        dispatch_async(dispatch_get_main_queue(), ^{
+////            [waitalert dismissViewControllerAnimated:YES completion:nil];
+//            [waitalert dismissViewControllerAnimated:YES completion:nil];
+//
+//
+//
+//            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
+//                                            {
+//                                                [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) {
+//
+//                        NSDictionary* json =result;
+//                        [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] ;
+//                        }
+//
+//                    }];
+//
+//
+////                    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] ;
+//            }
+//
+//
+//
+//
+//        });
+//    });
     
     
     
@@ -638,7 +906,7 @@
         
         
 //        [pdf_url appendString:[valuefrom stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
-//        
+//
         [pdf_url appendString:[valuefrom stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet characterSetWithCharactersInString:@"`#%^{}\"[]|\\<> "]]];
         
         
@@ -685,57 +953,103 @@
             
             
             UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Processing"];
-            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+            [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:nil];
                 
                 
-                [upparams setValue:pdf_url forKey:@"pdfUrl"];
-                [upparams setValue:saveName forKey:@"pdfName"];
-                [upparams setValue:del_ids forKey:@"itemIds"];
-                [upparams setValue:saveNote forKey:@"pdfNote"];
-                
-                NSDictionary* editor_json = [RANetwork direct_save_TearSheet:upparams];
-                
-                dispatch_async(dispatch_get_main_queue(), ^{
-                    [waitalert dismissViewControllerAnimated:YES completion:nil];
+                if([[editor_json valueForKey:@"result"] intValue]==2)
+                {
                     
                     
-                    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:^{
                         
                         
                         
-                     //   [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];
+                        [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];
-
+                        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] ;
-                    }
-                    
+                        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), ^{
+//
+//
+//                [upparams setValue:pdf_url forKey:@"pdfUrl"];
+//                [upparams setValue:saveName forKey:@"pdfName"];
+//                [upparams setValue:del_ids forKey:@"itemIds"];
+//                [upparams setValue:saveNote forKey:@"pdfNote"];
+//
+//                NSDictionary* editor_json = [RANetwork direct_save_TearSheet:upparams];
+//
+//                dispatch_async(dispatch_get_main_queue(), ^{
+//                    [waitalert dismissViewControllerAnimated:YES completion:nil];
+//
+//
+//                    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] ;
+//                    }
+//
+//
+//
+//
+//                });
+//            });
 
         }
     }];

+ 175 - 87
RedAnt ERP Mobile/common/Functions/search+itemsearch/ItemSearchViewController.m

@@ -546,12 +546,9 @@
         self.mum.center = self.view.center;
         
         self.isrefreshing=true;
-    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
         
-    
-        NSDictionary* category_more=[RANetwork 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
-                                     ];
-        dispatch_async(dispatch_get_main_queue(), ^{
+        [RANetwork request_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 completionHandler:^(NSMutableDictionary *result) {
+            NSDictionary* category_more=result;
             [self.mum stopAnimating];
             self.isrefreshing=false;
             if (self.dataOperationQueue.operationCount > 1) {
@@ -599,47 +596,101 @@
             }
             
             
-        });
-        //        dispatch_async(dispatch_get_main_queue(), ^{
-        //            //  self.category_data = category_data;
-        //
-        //
-        //            if([[category_more valueForKey:@"result"] intValue]==2)
-        //            {
-        //                NSMutableDictionary* items_json= [[self.category_data objectForKey:@"items"] mutableCopy];
-        //
-        //                int count =[[category_more valueForKey:@"count"] intValue];
-        //                for(int i=0;i<count;i++)
-        //                {
-        //
-        //                    NSDictionary * item_json = [category_more objectForKey:[NSString stringWithFormat:@"item_%d",i]];
-        //                    [items_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",i+self.offset]];
-        //
-        //
-        //                }
-        //                long newcount=[[[self.category_data objectForKey:@"items"] valueForKey:@"count"] intValue]+count;
-        //                [items_json setValue: [NSString stringWithFormat:@"%ld",newcount] forKey:@"count"];
-        //                [self.category_data setObject:items_json forKey:@"items"];
-        //                self.offset+=count;
-        //                //            NSDictionary * item_json = [self.category_data objectForKey:@"items"];
-        //
-        //
-        //
-        //
-        //                DebugLog(@"%@",self.category_data);
-        //
-        //                [self.collectionview reloadData];
-        //            }
-        //            else
-        //            {
-        //                [RAUtils error_alert:[category_more valueForKey:@"err_msg"]] ;
-        //            }
-        //
-        //
-        //
-        //
-        //        });
-    });
+        }];
+//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+//
+//
+//        NSDictionary* category_more=[RANetwork 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
+//                                     ];
+//        dispatch_async(dispatch_get_main_queue(), ^{
+//            [self.mum stopAnimating];
+//            self.isrefreshing=false;
+//            if (self.dataOperationQueue.operationCount > 1) {
+//                return ;
+//            }
+//            NSDictionary* more_items=[category_more objectForKey:@"items"];
+//            if([[category_more valueForKey:@"result"] intValue]==2)
+//            {
+//                //  self.category_data = category_data;
+//                NSMutableDictionary* items_json= [[self.category_data objectForKey:@"items"] mutableCopy];
+//
+//                int count =[[more_items valueForKey:@"count"] intValue];
+//                for(int i=0;i<count;i++)
+//                {
+//
+//                    NSDictionary * item_json = [more_items objectForKey:[NSString stringWithFormat:@"item_%d",i]];
+//                    [items_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",i+self.offset]];
+//
+//
+//                }
+//                long newcount=[[[self.category_data objectForKey:@"items"] valueForKey:@"count"] intValue]+count;
+//                [items_json setValue: [NSString stringWithFormat:@"%ld",newcount] forKey:@"count"];
+//                [self.category_data setObject:items_json forKey:@"items"];
+//                self.offset+=count;
+//
+//                if(count<20)
+//                {
+//                    self.loadall=true;
+//
+//                }
+//
+//                //            NSDictionary * item_json = [self.category_data objectForKey:@"items"];
+//
+//
+//
+//
+//        //        DebugLog(@"%@",self.category_data);
+//
+//                [self.collectionview reloadData];
+//
+//            }
+//            else
+//            {
+//                [RAUtils message_alert:[category_more valueForKey:@"err_msg"] title:@"Search" controller:self] ;
+//            }
+//
+//
+//        });
+//        //        dispatch_async(dispatch_get_main_queue(), ^{
+//        //            //  self.category_data = category_data;
+//        //
+//        //
+//        //            if([[category_more valueForKey:@"result"] intValue]==2)
+//        //            {
+//        //                NSMutableDictionary* items_json= [[self.category_data objectForKey:@"items"] mutableCopy];
+//        //
+//        //                int count =[[category_more valueForKey:@"count"] intValue];
+//        //                for(int i=0;i<count;i++)
+//        //                {
+//        //
+//        //                    NSDictionary * item_json = [category_more objectForKey:[NSString stringWithFormat:@"item_%d",i]];
+//        //                    [items_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",i+self.offset]];
+//        //
+//        //
+//        //                }
+//        //                long newcount=[[[self.category_data objectForKey:@"items"] valueForKey:@"count"] intValue]+count;
+//        //                [items_json setValue: [NSString stringWithFormat:@"%ld",newcount] forKey:@"count"];
+//        //                [self.category_data setObject:items_json forKey:@"items"];
+//        //                self.offset+=count;
+//        //                //            NSDictionary * item_json = [self.category_data objectForKey:@"items"];
+//        //
+//        //
+//        //
+//        //
+//        //                DebugLog(@"%@",self.category_data);
+//        //
+//        //                [self.collectionview reloadData];
+//        //            }
+//        //            else
+//        //            {
+//        //                [RAUtils error_alert:[category_more valueForKey:@"err_msg"]] ;
+//        //            }
+//        //
+//        //
+//        //
+//        //
+//        //        });
+//    });
     });
 }
 
@@ -684,47 +735,84 @@
          self.mum.center = self.view.center;
          self.mum.hidden = false;
          [self.mum startAnimating];
-    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-        
-        NSDictionary* category_data=[RANetwork ItemSearch:0 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
-                                                             ];
-        
-        dispatch_async(dispatch_get_main_queue(), ^{
-            [self.mum stopAnimating];
-            self.isrefreshing=false;
-            if (self.dataOperationQueue.operationCount > 1) {
-                return ;
-            }
-            
-            self.category_data = [category_data mutableCopy];
-            [self.collectionview reloadData];
-            if([[category_data valueForKey:@"result"] intValue]==2)
-            {
-                self.collectionview.hidden = false;
-                NSDictionary * item_json = [self.category_data objectForKey:@"items"];
-                self.offset =[[item_json valueForKey:@"count"] intValue];
-                
-                int total = [[self.category_data valueForKey:@"item_total_count"]intValue];
-                
-                if(total<2)
-                    self.labelTotal.text = [NSString stringWithFormat:@"Total %d item",total];
-                else
-                    self.labelTotal.text = [NSString stringWithFormat:@"Total %d items",total];
-            }
-            else if([[category_data valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
-            {
-                self.label_net_err.hidden=false;
-                self.collectionview.hidden = true;
-            }
-            else
-            {
-                [RAUtils message_alert:[category_data valueForKey:@"err_msg"] title:@"Search" controller:self] ;
-            }
-            
-            
-            
-          });
-        });
+         
+         [RANetwork request_itemsearch:0 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 completionHandler:^(NSMutableDictionary *result) {
+             NSDictionary* category_data=result;
+           [self.mum stopAnimating];
+           self.isrefreshing=false;
+           if (self.dataOperationQueue.operationCount > 1) {
+               return ;
+           }
+           
+           self.category_data = [category_data mutableCopy];
+           [self.collectionview reloadData];
+           if([[category_data valueForKey:@"result"] intValue]==2)
+           {
+               self.collectionview.hidden = false;
+               NSDictionary * item_json = [self.category_data objectForKey:@"items"];
+               self.offset =[[item_json valueForKey:@"count"] intValue];
+               
+               int total = [[self.category_data valueForKey:@"item_total_count"]intValue];
+               
+               if(total<2)
+                   self.labelTotal.text = [NSString stringWithFormat:@"Total %d item",total];
+               else
+                   self.labelTotal.text = [NSString stringWithFormat:@"Total %d items",total];
+           }
+           else if([[category_data valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
+           {
+               self.label_net_err.hidden=false;
+               self.collectionview.hidden = true;
+           }
+           else
+           {
+               [RAUtils message_alert:[category_data valueForKey:@"err_msg"] title:@"Search" controller:self] ;
+           }
+           
+           
+           
+         }];
+//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+//
+//        NSDictionary* category_data=[RANetwork ItemSearch:0 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
+//                                                             ];
+//
+//        dispatch_async(dispatch_get_main_queue(), ^{
+//            [self.mum stopAnimating];
+//            self.isrefreshing=false;
+//            if (self.dataOperationQueue.operationCount > 1) {
+//                return ;
+//            }
+//
+//            self.category_data = [category_data mutableCopy];
+//            [self.collectionview reloadData];
+//            if([[category_data valueForKey:@"result"] intValue]==2)
+//            {
+//                self.collectionview.hidden = false;
+//                NSDictionary * item_json = [self.category_data objectForKey:@"items"];
+//                self.offset =[[item_json valueForKey:@"count"] intValue];
+//
+//                int total = [[self.category_data valueForKey:@"item_total_count"]intValue];
+//
+//                if(total<2)
+//                    self.labelTotal.text = [NSString stringWithFormat:@"Total %d item",total];
+//                else
+//                    self.labelTotal.text = [NSString stringWithFormat:@"Total %d items",total];
+//            }
+//            else if([[category_data valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
+//            {
+//                self.label_net_err.hidden=false;
+//                self.collectionview.hidden = true;
+//            }
+//            else
+//            {
+//                [RAUtils message_alert:[category_data valueForKey:@"err_msg"] title:@"Search" controller:self] ;
+//            }
+//
+//
+//
+//          });
+//        });
     });
 }
 

+ 90 - 39
RedAnt ERP Mobile/common/Price Setting/PriceSettingViewController.m

@@ -121,28 +121,53 @@
 
     UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Load Data"];
     
-    NSDictionary *dic = [RANetwork get_npd_shop_givenPrice];
+    [RANetwork request_npd_shop_givenprice:^(NSMutableDictionary *result) {
+            NSDictionary *dic = result;
 
-//    [waitalert dismissWithClickedButtonIndex:0 animated:YES];
-    [waitalert dismissViewControllerAnimated:YES completion:nil];
-    
-    
-    if ([[dic objectForKey:@"result"] integerValue] == 2) {
+        //    [waitalert dismissWithClickedButtonIndex:0 animated:YES];
+            [waitalert dismissViewControllerAnimated:YES completion:nil];
+            
+            
+            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];
+                
+            };
+    }];
     
-        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];
-        
-    }
+//    NSDictionary *dic = [RANetwork get_npd_shop_givenPrice];
+//
+////    [waitalert dismissWithClickedButtonIndex:0 animated:YES];
+//    [waitalert dismissViewControllerAnimated:YES completion:nil];
+//    
+//    
+//    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];
+//        
+//    }
 }
 
 - (NSString *)checkPriceType:(NSInteger)priceType {
@@ -213,31 +238,57 @@
     
     UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Set PriceType"];
     
-    NSDictionary *dic = [RANetwork set_npd_shop_price_type:self.priceType];
-    
-//    [waitalert dismissWithClickedButtonIndex:0 animated:YES];
-    [waitalert dismissViewControllerAnimated:YES completion:nil];
-    
-    // 成功
-    if ([[dic objectForKey:@"result"] integerValue] == 2) {
-        
-        [Singleton sharedInstance].npd_shop_price_type = self.priceType;
-    
-
+    [RANetwork request_update_npd_shop_price_type:self.priceType completionHandler:^(NSMutableDictionary *result) {
+        NSDictionary *dic=result;
+        [waitalert dismissViewControllerAnimated:YES completion:nil];
         
+        // 成功
+        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];
+            [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
 #else
-        // 刷新 Cart、Order List
-        [[NSNotificationCenter defaultCenter] postNotificationName:Change_Price_Type_Notification object:nil];
+            // 刷新 Cart、Order List
+            [[NSNotificationCenter defaultCenter] postNotificationName:Change_Price_Type_Notification object:nil];
 #endif
+            
+        } else { // 失败
+            
+            DebugLog(@"set price type failure");
+        }
         
-    } else { // 失败
-        
-        DebugLog(@"set price type failure");
-    }
+        [self dismissViewControllerAnimated:YES completion:nil];;
+    }];
     
-    [self dismissViewControllerAnimated:YES completion:nil];
+//    NSDictionary *dic = [RANetwork set_npd_shop_price_type:self.priceType];
+//
+////    [waitalert dismissWithClickedButtonIndex:0 animated:YES];
+//    [waitalert dismissViewControllerAnimated:YES completion:nil];
+//
+//    // 成功
+//    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];
 }
 
 @end

+ 33 - 13
RedAnt ERP Mobile/common/Price Setting/SetCategoryPriceController.m

@@ -224,24 +224,44 @@
     if (rightDiscount) {
         
         UIAlertController* waitalert = [RAUtils waiting_alert:self title:@"Set Price"];
-//        UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Set Price"];
+        //        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];
         
-        [waitalert dismissViewControllerAnimated:YES completion:nil];
-//        [waitalert dismissWithClickedButtonIndex:0 animated:YES];
-        
-        if ([[dic objectForKey:@"result"] integerValue] == 2) {
+        [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;
             
-            [self.categoryPrice setObject:[NSString stringWithFormat:@"%ld",self.priceType] forKey:@"base_price"];
-            [self.categoryPrice setObject:discount forKey:@"price_discount"];
+            [waitalert dismissViewControllerAnimated:YES completion:nil];
+            //        [waitalert dismissWithClickedButtonIndex:0 animated:YES];
             
-            // 将数据返回
-            if (self.returnBlock)
-                self.returnBlock(self.categoryPrice);
-        }
+            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);
+            }
+            
+            [self.navigationController popViewControllerAnimated:YES];
+        }];
         
-        [self.navigationController popViewControllerAnimated:YES];
+        //        NSDictionary *dic = [RANetwork set_npd_shop_givenPrice:@{@"base_price" : [NSString stringWithFormat:@"%ld",self.priceType],@"discount" : discount,@"category_id" : @(self.categoryID)}.mutableCopy];
+        //
+        //        [waitalert dismissViewControllerAnimated:YES completion:nil];
+        ////        [waitalert dismissWithClickedButtonIndex:0 animated:YES];
+        //
+        //        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);
+        //        }
+        //
+        //        [self.navigationController popViewControllerAnimated:YES];
         
     } else {
         

+ 21 - 12
RedAnt ERP Mobile/common/data_provider/RANetwork.h

@@ -66,7 +66,7 @@ extern NSString *const ScreenCodeOfflineSync;
 //+(NSDictionary*)load_HomePage: (int) price_template customid:(int) customid;
 +(NSDictionary*)retrieve_password: (NSString*) user email:(NSString*) email;
 
-+(NSDictionary*)request_model_qty: (NSString*) fashionId;
+//+(NSDictionary*)request_model_qty: (NSString*) fashionId;
 
 +(NSDictionary*)commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url;
 
@@ -98,7 +98,7 @@ extern NSString *const ScreenCodeOfflineSync;
 //+(NSDictionary*) add_toWatchList:(NSString* ) item_id withScreen:(NSString *)screenName;
 //+(NSDictionary*)request_Cart:(int)sort;
 //+(NSDictionary*)request_WatchList:(int)sort;
-+(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_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;
@@ -133,24 +133,23 @@ extern NSString *const ScreenCodeOfflineSync;
 
 
 //+(NSDictionary*)Search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull;
-+(NSDictionary*)ItemSearch:(long ) offset limit :(long)limit covertype:(NSString* ) covertype ctgid:(NSString*)ctgid modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller;
+//+(NSDictionary*)ItemSearch:(long ) offset limit :(long)limit covertype:(NSString* ) covertype ctgid:(NSString*)ctgid modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller;
 
 //+(NSDictionary*)request_Editor:(NSString*) request_url params:(NSMutableDictionary*)params;
 
-+(NSString*)DataTOjsonString:(id)object;
 
 
 //+(NSDictionary*)request_PDFList:(int ) offset limit:(int)limit keywords:(NSString* ) keywords ;
-+(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;
+//+(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;
 
 
 //+(NSDictionary*)Category_addall: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword  offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip orderCode:(NSString*) orderCode addTo:(NSString*) addTo;
 //+(NSDictionary*)category_addall2wish: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword  offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip;
 //+(NSDictionary*)category_addall2portfolio: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword  offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip;
 
-+(NSString*) create_portfolio:(NSMutableDictionary*)params ;
+//+(NSString*) create_portfolio:(NSMutableDictionary*)params ;
 
 //+(NSDictionary*)Search_addall:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull orderCode:(NSString*) orderCode  addTo:(NSString*) addTo;
 
@@ -167,11 +166,11 @@ extern NSString *const ScreenCodeOfflineSync;
 
 //+(NSString *)flattenHTML:(NSString *)html trimWhiteSpace:(BOOL)trim;
 
-+ (NSDictionary *)set_npd_shop_price_type:(NSInteger) priceType;
+//+ (NSDictionary *)set_npd_shop_price_type:(NSInteger) priceType;
 
-+ (NSDictionary *)get_npd_shop_givenPrice;
+//+ (NSDictionary *)get_npd_shop_givenPrice;
 
-+ (NSDictionary *)set_npd_shop_givenPrice:(NSMutableDictionary *)params;
+//+ (NSDictionary *)set_npd_shop_givenPrice:(NSMutableDictionary *)params;
 
 //+ (NSDictionary *)merge_order:(NSMutableDictionary *)params;
 
@@ -203,7 +202,7 @@ extern NSString *const ScreenCodeOfflineSync;
 
 +(void)request_editor:(NSString*) request_url params:(NSMutableDictionary*)params completionHandler:(resultHandler)result;
 +(void)request_wishlist:(int)sort completionHandler:(resultHandler)result;
-+(void)request_portfolio:(int)sort completionHandler:(resultHandler)result;
++(void)request_portfoliolist:(int)sort completionHandler:(resultHandler)result;
 +(void)request_portfoliopdf:(int ) offset limit:(int)limit keywords:(NSString* ) keywords completionHandler:(resultHandler)result;
 +(void)request_orderlist:(int ) offset limit :(int)limit keywords :(NSString* ) keywords status:(NSString*) status_code customer:(NSString*) customer is_merged:(BOOL) isMerged completionHandler:(resultHandler)result;
 +(void)request_logout:(resultHandler)result;
@@ -238,4 +237,14 @@ extern NSString *const ScreenCodeOfflineSync;
 +(void) request_update_cartqty:(NSString*) cart_id value:(int) value completionHandler:(resultHandler)result;
 +(void) request_update_cartgeneralnote:(NSString*) order_code notes:(NSString*) notes completionHandler:(resultHandler)result;
 +(void) request_update_cartitemnote:(NSString*) cart_id notes:(NSString*) notes completionHandler:(resultHandler)result;
++ (void)request_update_npd_shop_price_type:(NSInteger)priceType completionHandler:(resultHandler)result;
++ (void)request_npd_shop_givenprice:(resultHandler)result;
++ (void)request_update_npd_shop_givenprice:(NSMutableDictionary *)params completionHandler:(resultHandler)result;
++(void) request_create_portfolio:(NSMutableDictionary*)params completionHandler:(resultHandler)result;
++(void)request_save_portfoliodirectly:(NSMutableDictionary*)params completionHandler:(resultHandler)result;
++(void)request_save_portfolio:(NSMutableDictionary *)params completionHandler:(resultHandler)result;
++(void)request_portfoliopreview:(NSMutableDictionary*)params completionHandler:(resultHandler)result;
++(void)request_itemsearch:(long ) offset limit :(long)limit covertype:(NSString* ) covertype ctgid:(NSString*)ctgid modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller completionHandler:(resultHandler)result;
++(void)request_modelqty: (NSString*) fashionId completionHandler:(resultHandler)result;
++(void) request_update_portfolio_price:(NSString*) watchlist_id price:(float) price discount:(float) discount QTY:(int)qty qty_p:(float) qty_p notes:(NSString*)notes completionHandler:(resultHandler)result;
 @end

+ 736 - 42
RedAnt ERP Mobile/common/data_provider/RANetwork.m

@@ -571,20 +571,6 @@ NSString *const ScreenCodeOfflineSync = @"Offline Sync Screen";
 //}
 }
 
-+(NSString*)DataTOjsonString:(id)object
-{
-    NSString *jsonString = nil;
-    NSError *error;
-    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:object
-                                                       options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string
-                                                         error:&error];
-    if (! jsonData) {
-        DebugLog(@"Got an error: %@", error);
-    } else {
-        jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
-    }
-    return jsonString;
-}
 //+(NSDictionary*)request_Editor:(NSString*) sourceid editor:(NSString*)editor
 //{
 //
@@ -1910,31 +1896,31 @@ NSString *const ScreenCodeOfflineSync = @"Offline Sync Screen";
     return jsobj;
     
 }
-+(NSString*) create_portfolio:(NSMutableDictionary*)params
-{
-    __block AppDelegate *appDelegate = nil;
-    
-    dispatch_sync(dispatch_get_main_queue(), ^{
-        //some UI methods ej
-        appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
-    });
-        if(appDelegate.offline_mode)
-        {
-
-
-            NSData*json = [OLDataProvider offline_direct_save_TearSheet:params];
-            if(json==nil)
-                return nil;
-            NSError *error=nil;
-            NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
-            
-            return jsobj[@"pdf_path"];
-        }
-        else
-        {
-            return nil;
-        }
-}
+//+(NSString*) create_portfolio:(NSMutableDictionary*)params
+//{
+//    __block AppDelegate *appDelegate = nil;
+//
+//    dispatch_sync(dispatch_get_main_queue(), ^{
+//        //some UI methods ej
+//        appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
+//    });
+//        if(appDelegate.offline_mode)
+//        {
+//
+//
+//            NSData*json = [OLDataProvider offline_direct_save_TearSheet:params];
+//            if(json==nil)
+//                return nil;
+//            NSError *error=nil;
+//            NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+//
+//            return jsobj[@"pdf_path"];
+//        }
+//        else
+//        {
+//            return nil;
+//        }
+//}
 +(NSDictionary*)direct_save_TearSheet:(NSMutableDictionary*)params//(NSString*) request_url name:(NSString*)name delete:(NSString* )ids note:(NSString* )saveNote modelIds:(NSDictionary *)modelIds
 {
     NSMutableDictionary* off_params = [params mutableCopy];;
@@ -5892,7 +5878,7 @@ NSString *const ScreenCodeOfflineSync = @"Offline Sync Screen";
 //    }
 //    return jsobj;
 }
-+(void)request_portfolio:(int)sort completionHandler:(resultHandler)result
++(void)request_portfoliolist:(int)sort completionHandler:(resultHandler)result
 {
     
     
@@ -8645,7 +8631,7 @@ NSString *const ScreenCodeOfflineSync = @"Offline Sync Screen";
     [self request_interface:URL_CART_ITEM_NOTES parameters:params err_record_url:nil completionHandler:result retry:0];
     
     
-//    
+//
 //    NSData* json=nil;
 //    if(appDelegate.offline_mode)
 //    {
@@ -8655,7 +8641,7 @@ NSString *const ScreenCodeOfflineSync = @"Offline Sync Screen";
 //    {
 //    if(![self IsNetworkAvailable])
 //        return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
-//    
+//
 //    json=[self get_json:URL_CART_ITEM_NOTES parameters:params];
 //    }
 //    if(json==nil)
@@ -8664,4 +8650,712 @@ NSString *const ScreenCodeOfflineSync = @"Offline Sync Screen";
 //    NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
 //    return jsobj;
 }
++ (void)request_update_npd_shop_price_type:(NSInteger)priceType completionHandler:(resultHandler)result
+{
+    
+    NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
+     AppDelegate *appDelegate = nil;
+    
+    
+    appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
+
+    if(appDelegate.user!=nil)
+        [dic setValue:appDelegate.user forKey:@"user"];
+    
+    if(appDelegate.password!=nil)
+        [dic setValue:appDelegate.password forKey:@"password"];
+    
+    [dic setValue:[NSString stringWithFormat:@"%ld",priceType] forKey:@"price_type"];
+    [dic setObject:ScreenCodePriceSetting forKey:kScreenName];
+    
+    
+    if(appDelegate.offline_mode)
+    {
+        
+        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+            NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
+            dispatch_async(dispatch_get_main_queue(), ^{
+                result(json);
+            });
+        });
+        
+        return;
+    }
+    
+    
+    [self request_interface:URL_SET_PRICE_TYPE parameters:dic err_record_url:nil completionHandler:result retry:0];
+//    
+//    NSData* json=nil;
+//    if(appDelegate.offline_mode)
+//    {
+//        return [OLDataProvider offline_notimpl];
+//    }
+//    else
+//    {
+//        if(![self IsNetworkAvailable])
+//            return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+//        
+//        json = [RANetwork get_json:URL_SET_PRICE_TYPE parameters:dic];
+//    }
+//    if(json!=nil)
+//    {
+//        NSError *error=nil;
+//        NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+//        
+//        
+//        return jsobj;
+//    }
+//
+//    
+//    return nil;
+}
++ (void)request_npd_shop_givenprice:(resultHandler)result
+{
+    NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
+     AppDelegate *appDelegate = nil;
+    
+   
+    
+        appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
+
+    if(appDelegate.user!=nil)
+        [dic setValue:appDelegate.user forKey:@"user"];
+    
+    if(appDelegate.password!=nil)
+        [dic setValue:appDelegate.password forKey:@"password"];
+    
+    [dic setObject:ScreenCodeCategoryPrice forKey:kScreenName];
+        
+    
+    
+    if(appDelegate.offline_mode)
+    {
+        
+        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+            NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
+            dispatch_async(dispatch_get_main_queue(), ^{
+                result(json);
+            });
+        });
+        
+        return;
+    }
+    
+    
+    [self request_interface:URL_GET_CIVEN_PRICE parameters:dic err_record_url:nil completionHandler:result retry:0];
+//
+//    NSData* json=nil;
+//    if(appDelegate.offline_mode)
+//    {
+//        return [OLDataProvider offline_notimpl];
+//    }
+//    else
+//    {
+//        if(![self IsNetworkAvailable])
+//            return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+//
+//        json = [RANetwork get_json:URL_GET_CIVEN_PRICE parameters:dic];
+//    }
+//    if(json!=nil)
+//    {
+//        NSError *error=nil;
+//        NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+//
+//
+//        return jsobj;
+//    }
+//
+//
+//    return nil;
+
+}
+
++ (void)request_update_npd_shop_givenprice:(NSMutableDictionary *)params completionHandler:(resultHandler)result
+{
+    
+     AppDelegate *appDelegate = nil;
+    
+    
+    appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
+
+    if(appDelegate.user!=nil)
+        [params setValue:appDelegate.user forKey:@"user"];
+    
+    if(appDelegate.password!=nil)
+        [params setValue:appDelegate.password forKey:@"password"];
+    
+    [params setObject:ScreenCodeSetCatetoryPrice forKey:kScreenName];
+    
+    
+      if(appDelegate.offline_mode)
+      {
+          
+          dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+              NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
+              dispatch_async(dispatch_get_main_queue(), ^{
+                  result(json);
+              });
+          });
+          
+          return;
+      }
+      
+      
+      [self request_interface:URL_SET_GIVEN_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
+//
+//    NSData* json=nil;
+//    if(appDelegate.offline_mode)
+//    {
+//        return [OLDataProvider offline_notimpl];
+//    }
+//    else
+//    {
+//        if(![self IsNetworkAvailable])
+//            return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+//
+//        json = [RANetwork get_json:URL_SET_GIVEN_PRICE parameters:params];
+//    }
+//    if(json!=nil)
+//    {
+//        NSError *error=nil;
+//        NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+//
+//
+//        return jsobj;
+//    }
+//
+//
+//    return nil;
+}
+
++(void) request_create_portfolio:(NSMutableDictionary*)params completionHandler:(resultHandler)result
+{
+     AppDelegate *appDelegate = nil;
+    
+
+    appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
+    
+    
+    if(appDelegate.offline_mode)
+    {
+        
+        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+            NSMutableDictionary* json = [[OLDataProvider offline_direct_save_TearSheet:params] mutableCopy];
+            dispatch_async(dispatch_get_main_queue(), ^{
+                result(json);
+            });
+        });
+        
+        return;
+    }
+//
+//    if(appDelegate.offline_mode)
+//        {
+//
+//
+//            NSData*json = [OLDataProvider offline_direct_save_TearSheet:params];
+//            if(json==nil)
+//                return nil;
+//            NSError *error=nil;
+//            NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+//
+//            return jsobj[@"pdf_path"];
+//        }
+//        else
+//        {
+//            return nil;
+//        }
+}
++(void)request_save_portfoliodirectly:(NSMutableDictionary*)params completionHandler:(resultHandler)result
+{
+    NSMutableDictionary* off_params = [params mutableCopy];;
+    
+    params[@"off_params"]=[RAConvertor dict2string:off_params];;
+     AppDelegate *appDelegate = nil;
+    
+    
+    appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
+
+    if(appDelegate.user!=nil)
+        [params setValue:appDelegate.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"];
+    
+    [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
+    
+ 
+    if(appDelegate.offline_mode)
+    {
+        
+        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+            NSMutableDictionary* json = [[OLDataProvider offline_direct_save_TearSheet:params] mutableCopy];
+            dispatch_async(dispatch_get_main_queue(), ^{
+                result(json);
+            });
+        });
+        
+        return;
+    }
+    
+    
+        NSString * uuid= [[NSUUID UUID] UUIDString];
+        params[@"resultSerial"]=uuid;
+        __block bool bbreak = false;
+    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+        for(int i=0;i<150;i++)
+        {
+            //           NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
+            //            result_params[@"resultSerial"]=uuid;
+            if(bbreak)
+                break;
+            
+            dispatch_async(dispatch_get_main_queue(), ^{
+                [self request_interface:URL_REQUEST_DM parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
+                    
+                    
+                    if([resulti[@"result"] intValue]==2)
+                    {
+                        bbreak=true;
+                        result(resulti);
+                        
+                    }
+                    
+                    
+                } retry:0];
+                
+            });
+            
+            sleep(2);
+            
+            
+            
+        }
+    });
+    
+    
+//
+//
+//    NSData* json= nil;
+//
+//    if(appDelegate.offline_mode)
+//    {
+//        json = [OLDataProvider offline_direct_save_TearSheet:params];
+//    }
+//    else
+//    {
+//        if(![self IsNetworkAvailable])
+//            return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+//
+//        json=[self get_json:URL_REQUEST_DM parameters:params];
+//
+//        NSError *error=nil;
+//
+//        NSString * uuid= [[NSUUID UUID] UUIDString];
+//        params[@"resultSerial"]=uuid;
+//
+//        for(int i=0;i<150;i++)
+//        {
+//            //           NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
+//            //            result_params[@"resultSerial"]=uuid;
+//            json=[self get_json:URL_REQUEST_DM parameters:params];
+//            if(json!=nil)
+//            {
+//
+//                NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+//                if([jsobj[@"result"] intValue]==2)
+//                {
+//                    break;
+//                }
+//            }
+//            sleep(5);
+//        }
+//
+//    }
+//    if(json==nil)
+//        return nil;
+//    NSError *error=nil;
+//    NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+//    return jsobj;
+}
+
++(void)request_save_portfolio:(NSMutableDictionary *)params completionHandler:(resultHandler)result
+
+{
+    
+    
+    NSMutableDictionary* off_params = [params mutableCopy];;
+    
+    params[@"off_params"]=[RAConvertor dict2string:off_params];
+  //  NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+     AppDelegate *appDelegate = nil;
+    
+
+    
+        appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
+    
+    
+    if(appDelegate.user!=nil)
+        [params setValue:appDelegate.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"];
+    
+    [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
+    
+    if(appDelegate.offline_mode)
+    {
+        
+        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+            NSMutableDictionary* json = [[OLDataProvider offline_save_TearSheet:params] mutableCopy];
+            dispatch_async(dispatch_get_main_queue(), ^{
+                result(json);
+            });
+        });
+        
+        return;
+    }
+    
+    
+    [self request_interface:URL_SAVE_DM parameters:params err_record_url:nil completionHandler:result retry:0];
+    
+//
+//    NSData* json = nil;
+//    if(appDelegate.offline_mode)
+//    {
+//        json = [OLDataProvider offline_save_TearSheet:params];
+//    } else {
+//        if(![self IsNetworkAvailable])
+//            return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+//
+//        json=[self get_json:URL_SAVE_DM parameters:params];
+//    }
+//    if(json==nil)
+//        return nil;
+//    NSError *error=nil;
+//    NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+//    return jsobj;
+}
+
+
++(void)request_portfoliopreview:(NSMutableDictionary*)params completionHandler:(resultHandler)result
+{
+//    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+     AppDelegate *appDelegate = nil;
+    
+
+        appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
+
+    if(appDelegate.user!=nil)
+        [params setValue:appDelegate.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"];
+    
+     [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
+    
+//    [params setValue:request_url forKey:@"pdfUrl"];
+    
+    if(appDelegate.offline_mode)
+    {
+        
+        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+            NSMutableDictionary* json = [[OLDataProvider offline_request_tearsheet:params] mutableCopy];
+            dispatch_async(dispatch_get_main_queue(), ^{
+                result(json);
+            });
+        });
+        
+        return;
+    }
+    
+    
+        NSString * uuid= [[NSUUID UUID] UUIDString];
+        params[@"resultSerial"]=uuid;
+        __block bool bbreak = false;
+    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+        for(int i=0;i<150;i++)
+        {
+            //           NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
+            //            result_params[@"resultSerial"]=uuid;
+            if(bbreak)
+                break;
+            
+            dispatch_async(dispatch_get_main_queue(), ^{
+                [self request_interface:URL_REQUEST_DM parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
+                    
+                    
+                    if([resulti[@"result"] intValue]==2)
+                    {
+                        bbreak=true;
+                        result(resulti);
+                        
+                    }
+                    
+                    
+                } retry:0];
+                
+            });
+            
+            sleep(5);
+            
+            
+            
+        }
+    });
+    
+//
+//    NSData* json= nil;
+//    if(appDelegate.offline_mode)
+//    {
+//        json= [OLDataProvider offline_request_tearsheet:params];
+//    }
+//    else
+//    {
+//    if(![self IsNetworkAvailable])
+//        return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+//
+//        NSError *error=nil;
+//
+//        NSString * uuid= [[NSUUID UUID] UUIDString];
+//        params[@"resultSerial"]=uuid;
+//
+//        for(int i=0;i<150;i++)
+//        {
+//            //           NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
+//            //            result_params[@"resultSerial"]=uuid;
+//            json=[self get_json:URL_REQUEST_DM parameters:params];
+//            if(json!=nil)
+//            {
+//
+//                NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+//                if([jsobj[@"result"] intValue]==2)
+//                {
+//                    break;
+//                }
+//            }
+//            sleep(5);
+//        }
+//    }
+//    if(json==nil)
+//        return nil;
+//    NSError *error=nil;
+//    NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+//    return jsobj;
+}
+
++(void)request_itemsearch:(long ) offset limit :(long)limit covertype:(NSString* ) covertype ctgid:(NSString*)ctgid modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller completionHandler:(resultHandler)result
+{
+    
+    // for debug
+    //    return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
+    //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+    
+    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+     AppDelegate *appDelegate = nil;
+    
+    
+    
+        //some UI methods ej
+        appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
+    
+    
+    if(appDelegate.user!=nil)
+        [params setValue:appDelegate.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(appDelegate.order_code!=nil)
+        [params setValue:appDelegate.order_code forKey:@"orderCode"];
+    
+    
+    [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
+    if (alert && qty && available && price && bestseller) {
+        [params setObject:@"Filter" forKey:kAction];
+    }
+    if ([Singleton sharedInstance].homeItemClick) {
+        [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
+        [Singleton sharedInstance].homeItemClick = NO;
+        
+        NSDictionary *extra = @{@"CoverName" : [Singleton sharedInstance].homeClickedItemName};
+        [Singleton sharedInstance].homeClickedItemName = nil;
+        [params setObject:extra forKey:kExtra];
+    }
+    
+    
+    //    [params setValue:[NSString stringWithFormat:@"%d",price_template]  forKey:@"price_template"];
+    //    [params setValue:[NSString stringWithFormat:@"%d",customid]  forKey:@"custom_id"];
+    //    [params setValue:[NSString stringWithFormat:@"%@",category]  forKey:@"category"];
+    //    [params setValue:[NSString stringWithFormat:@"%d",sort_by]  forKey:@"sort_by"];
+    //    [params setValue:filter forKey:@"filter"];
+    [params setValue:covertype forKey:@"covertype"];
+    [params setValue:ctgid forKey:@"ctgId"];
+    [params setValue:modelname forKey:@"modelName"];
+    [params setValue:modeldescrip forKey:@"modelDescription"];
+    [params setValue:alert forKey:@"alert"];
+    [params setValue:qty forKey:@"sold_by_qty"];
+    [params setValue:available forKey:@"available"];
+    [params setValue:price forKey:@"price"];
+    [params setValue:bestseller forKey:@"bestseller"];
+    
+    [params setValue:[NSString stringWithFormat:@"%ld",limit]  forKey:@"limit"];
+    [params setValue:[NSString stringWithFormat:@"%ld",offset]  forKey:@"offset"];
+    
+    
+    if(appDelegate.offline_mode)
+       {
+                   dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+               NSMutableDictionary* json = [[OLDataProvider offline_itemsearch:params] mutableCopy];
+               dispatch_async(dispatch_get_main_queue(), ^{
+                   result(json);
+               });
+           });
+           
+           return;
+
+       }
+       [self request_interface:URL_ITEM_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
+    
+    
+//    if(appDelegate.offline_mode)
+//    {
+//        return [OLDataProvider offline_itemsearch:params];
+//    }
+//    if(![self IsNetworkAvailable])
+//        return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+//    NSData* json=[self get_json:URL_ITEM_SEARCH parameters:params];
+//    if(json==nil)
+//        return nil;
+//    NSError *error=nil;
+//    NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+//    return jsobj;
+}
+
++(void)request_modelqty: (NSString*) fashionId completionHandler:(resultHandler)result
+{
+    
+    
+    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+     AppDelegate *appDelegate = nil;
+    
+
+        appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
+
+    if(appDelegate.user!=nil)
+        [params setValue:appDelegate.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"];
+    [params setValue:fashionId  forKey:@"fashionId"];
+    
+    [params setObject:ScreenCodeEditPortfolio forKey:kScreenName];
+    
+    
+    if(appDelegate.offline_mode)
+       {
+                   dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+               NSMutableDictionary* json = [[OLDataProvider offline_model_qty:params] mutableCopy];
+               dispatch_async(dispatch_get_main_queue(), ^{
+                   result(json);
+               });
+           });
+           
+           return;
+
+       }
+       [self request_interface:URL_REQUEST_MODEL_QTY parameters:params err_record_url:nil completionHandler:result retry:0];
+    
+    
+//    NSData* json = nil;
+//    if(appDelegate.offline_mode)
+//    {
+//        json = [OLDataProvider offline_model_qty:params];
+//    } else {
+//        if(![self IsNetworkAvailable])
+//            return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+//
+//        json=[self get_json:URL_REQUEST_MODEL_QTY parameters:params];
+//    }
+//    if(json==nil)
+//        return nil;
+//    NSError *error=nil;
+//    NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+//    return jsobj;
+}
+
++(void) request_update_portfolio_price:(NSString*) watchlist_id price:(float) price discount:(float) discount QTY:(int)qty qty_p:(float) qty_p notes:(NSString*)notes completionHandler:(resultHandler)result
+{
+    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+     AppDelegate *appDelegate = nil;
+    
+
+    
+        appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
+
+    
+    if(appDelegate.user!=nil)
+        [params setValue:appDelegate.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"];
+    
+    [params setValue:watchlist_id forKey:@"item_id"];
+    
+//    if(notes.length>0)
+//        [params setValue:notes forKey:@"notes"];
+    if(notes)
+        [params setValue:notes forKey:@"notes"];
+    
+    if(price != -MAXFLOAT)
+        [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
+    
+    if (discount != -MAXFLOAT)
+        [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
+
+    if(qty_p != -MAXFLOAT)
+        [params setValue:[NSString stringWithFormat:@"%f",qty_p] forKey:@"available_percent"];
+    if(qty != -INT32_MAX)
+        [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
+    
+    [params setObject:ScreenCodePortfolio forKey:kScreenName];
+    
+    NSData* json = nil;
+    
+    
+    if(appDelegate.offline_mode)
+       {
+                   dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+               NSMutableDictionary* json = [[OLDataProvider offline_editPortfolio:params] mutableCopy];
+               dispatch_async(dispatch_get_main_queue(), ^{
+                   result(json);
+               });
+           });
+           
+           return;
+
+       }
+       [self request_interface:URL_PORTFOLIO_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
+    
+//
+//    if(appDelegate.offline_mode)
+//    {
+//        json = [OLDataProvider offline_editPortfolio:params];
+//    } else {
+//        if(![self IsNetworkAvailable])
+//            return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+//
+//        json = [self get_json:URL_PORTFOLIO_SET_PRICE parameters:params];
+//    }
+//    if(json==nil)
+//        return nil;
+//    NSError *error=nil;
+//    NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+//    return jsobj;
+}
 @end