Преглед изворни кода

实现获取Product数量的离线接口。

Pen Li пре 9 година
родитељ
комит
21ddaea88d

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


+ 4 - 0
RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.h

@@ -106,4 +106,8 @@
 
 + (NSData *)offline_add2Portfolio:(NSMutableDictionary *)params;
 
++ (NSData *)offline_model_qty:(NSMutableDictionary *)params;
+
++ (NSData *)offline_editPortfolio:(NSMutableDictionary *)params;
+
 @end

+ 48 - 4
RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.m

@@ -9659,7 +9659,7 @@
     }
     
     
-    NSString *sql = [NSString stringWithFormat:@"select product_id,name,description,ifnull(sheet_price,'null'),sheet_discount,available_qty,percentage,item_id,fashion_id,img,line_note,percent from offline_portfolio order by %@ limit %d offset %d;",orderBy,limit,offset];
+    NSString *sql = [NSString stringWithFormat:@"select product_id,name,description,ifnull(sheet_price,'null'),sheet_discount,ifnull(available_qty,'null'),percentage,item_id,fashion_id,img,line_note,percent from offline_portfolio order by %@ limit %d offset %d;",orderBy,limit,offset];
     
     __block NSMutableDictionary *dic = [NSMutableDictionary dictionary];
     
@@ -9679,7 +9679,7 @@
         int qty = sqlite3_column_int(stmt, 5);
         int percentage = sqlite3_column_int(stmt, 6);
         int item_id = sqlite3_column_int(stmt, 7);
-        int fashion_id = sqlite3_column_int(stmt, 8);
+//        int fashion_id = sqlite3_column_int(stmt, 8);
         NSString *img_path = [self textAtColumn:9 statement:stmt];
         NSString *line_note = [self textAtColumn:10 statement:stmt];
         double percent = sqlite3_column_double(stmt, 11);
@@ -9689,6 +9689,8 @@
             price = [[self get_model_default_price:appDelegate.contact_id product_id:nil item_id:@(item_id) db:db] doubleValue];
         }
         
+        
+        
         NSMutableDictionary *item = @{
                                       @"linenotes": line_note,
                                       @"check": @(1),
@@ -9697,7 +9699,7 @@
                                       @"available_percent" : @(percent),
                                       @"description": [NSString stringWithFormat:@"%@\n%@",name,description],
                                       @"item_id": [NSString stringWithFormat:@"%d",item_id],
-                                      @"fashion_id": [NSString stringWithFormat:@"%d",fashion_id],
+                                      @"fashion_id": [NSString stringWithFormat:@"%d",product_id],
                                       @"img": img_path,
                                       @"tear_sheet_discount": [NSString stringWithFormat:@"%f",discount],
                                       @"tear_sheet_price": [NSString stringWithFormat:@"%f",price]
@@ -9708,6 +9710,11 @@
             [item removeObjectForKey:@"available_percent"];
         }
         
+        NSString *qty_null = [self textAtColumn:5 statement:stmt];
+        if ([qty_null isEqualToString:@"null"]) {
+            [item removeObjectForKey:@"available_qty"];
+        }
+        
         
         [dic setObject:item forKey:[NSString stringWithFormat:@"item_%ld",*count]];
         [dic setValue:[NSNumber numberWithLong:++(*count)] forKey:@"count"];
@@ -9744,8 +9751,10 @@
     NSString *keyword = [params valueForKey:@"keyWord"];
     
     NSString *where = @"";
+    
     if (keyword.length) {
-        
+        keyword = [self translateSingleQuote:keyword];
+        where = [NSString stringWithFormat:@"where lower(create_user) like '%%%@%%' or lower(tear_note) like '%%%@%%'  or lower(tear_name) like '%%%@%%'",keyword.lowercaseString,keyword.lowercaseString,keyword.lowercaseString];
     }
     
     NSString *sql = [NSString stringWithFormat:@"select tear_name,tear_note,createtime,create_user,pdf_path,tearsheets_id from offline_pdf %@ order by createtime desc limit %d offset %d;",where,limit,offset];
@@ -9825,4 +9834,39 @@
     return [RAUtils dict2data:dic];
 }
 
++ (NSData *)offline_model_qty:(NSMutableDictionary *)params {
+    
+    NSString *product_id = [params objectForKey:@"fashionId"];
+    NSString *sql = [NSString stringWithFormat:@"select availability from product where product_id = %@;",product_id];
+    
+    __block int result = RESULT_TRUE;
+    __block int qty = 0;
+    [iSalesDB jk_query:sql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
+        
+        qty = sqlite3_column_int(stmt, 0);
+        
+    } failure:^(NSMutableDictionary *container, NSString *err_msg) {
+        result = RESULT_FALSE;
+    }];
+    
+    NSMutableDictionary *dic = @{
+                                 @"err_msg" : result == RESULT_FALSE ? @"Failed." : @"Success.",
+                                 @"mode" : @"Regular Mode",
+                                 @"quantity_available" : @(qty),
+                                 @"result" : @(result),
+                                }.mutableCopy;
+
+    
+    return [RAUtils dict2data:dic];
+    
+    
+}
+
++ (NSData *)offline_editPortfolio:(NSMutableDictionary *)params {
+    
+    NSMutableDictionary *dic = nil;
+    
+    return [RAUtils dict2data:dic];
+}
+
 @end

+ 1 - 1
RedAnt ERP Mobile/common/Functions/portfolio/PDFListViewController.m

@@ -190,7 +190,7 @@
                     
                     NSDictionary* objmsg = [content objectForKey:[NSString stringWithFormat:@"item_%d",i]];
                     [self.content_data addObject:[NSMutableDictionary dictionaryWithDictionary:objmsg]];
-                    
+                    DebugLog(@"content_data: %@",self.content_data);
                 }
                 if(count<self.limit)
                 {

+ 14 - 10
RedAnt ERP Mobile/common/data_provider/iSalesNetwork.m

@@ -2105,15 +2105,17 @@ repeat:
     if(qty != -INT32_MAX)
         [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
     
+    NSData* json = nil;
     
     if(appDelegate.offline_mode)
     {
-        return [OLDataProvider offline_notimpl];
+        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(![self IsNetworkAvailable])
-        return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
-    
-    NSData* json=[self get_json:URL_PORTFOLIO_SET_PRICE parameters:params];
     if(json==nil)
         return nil;
     NSError *error=nil;
@@ -3148,14 +3150,16 @@ repeat:
     if(appDelegate.password!=nil)
         [params setValue:appDelegate.password forKey:@"password"];
     [params setValue:fashionId  forKey:@"fashionId"];
+    NSData* json = nil;
     if(appDelegate.offline_mode)
     {
-        return [OLDataProvider offline_notimpl];
-    }
-    if(![self IsNetworkAvailable])
-        return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+        json = [OLDataProvider offline_model_qty:params];
+    } else {
+        if(![self IsNetworkAvailable])
+            return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
     
-    NSData* json=[self get_json:URL_REQUEST_MODEL_QTY parameters:params];
+        json=[self get_json:URL_REQUEST_MODEL_QTY parameters:params];
+    }
     if(json==nil)
         return nil;
     NSError *error=nil;