Bladeren bron

建表portfoli和pdf。
实现离线方法pdflist和portfolio list

Pen Li 9 jaren geleden
bovenliggende
commit
344fcbfd33

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


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

@@ -94,5 +94,12 @@
 //+(NSDictionary*) model_img :(int)product_id;
 //+(NSDictionary*) model_property :(int)product_id field:(NSString*) value ;
 
+#pragma mark - portlio
+
++ (NSData *)offline_portfolioList:(NSMutableDictionary *)params;
+
++ (NSData *)offline_direct_save_TearSheet:(NSMutableDictionary *)params;
+
++ (NSData *)offline_pdfList:(NSMutableDictionary *)params;
 
 @end

+ 184 - 0
RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.m

@@ -14,6 +14,7 @@
 #import "ZipArchive.h"
 #import "UIProgressView+AFNetworking.h"
 #import "AFHTTPSessionManager.h"
+#import "AppDelegate.h"
 
 @interface OLDataProvider ()
 
@@ -9622,4 +9623,187 @@
     
 }
 
+#pragma mark - portfolio
+
++ (NSData *)offline_portfolioList:(NSMutableDictionary *)params {
+    
+//    {
+//        "result": 2,
+//        "min_ver": "160514",
+//        "count": 1,
+//        "can_see_price": true,
+//        "item_0": {
+//            "linenotes": "恢复肌肤就不会就附近",
+//            "check": 1,
+//            "product_id": "3732",
+//            "available_qty": 787,
+//            "description": "108237-SH-B\nCharlotte Fabric Chair Black Legs, Shark",
+//            "item_id": "13405",
+//            "fashion_id": "4858",
+//            "img": "http://192.168.0.112:8080/site//u/NPD/20151211/108237-SH-B_2916_s.jpg",
+//            "tear_sheet_discount": "20.00",
+//            "tear_sheet_price": "3109.00"
+//        },
+//        "email_content": "",
+//        "total_count": 1,
+//        "mode": "Regular Mode"
+//    }
+    
+    int sort = [[params valueForKey:@"sort"] integerValue];
+    int offset = [[params valueForKey:@"offset"] integerValue];
+    int limit = [[params valueForKey:@"limit"] integerValue];
+    
+    NSString *orderBy = @"";
+    switch (sort) {
+        case 0:{
+            orderBy = @"modifytime desc";
+        }
+            break;
+        case 1:{
+            orderBy = @"modifytime asc";
+        }
+            break;
+        case 2:{
+            orderBy = @"name asc";
+        }
+            break;
+        case 3:{
+            orderBy = @"name desc";
+        }
+            break;
+        case 4:{
+            orderBy = @"description asc";
+        }
+            break;
+            
+        default:
+            break;
+    }
+    
+    NSString *sql = [NSString stringWithFormat:@"select product_id,name,description,sheet_price,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];
+    
+    __block NSMutableDictionary *dic = [NSMutableDictionary dictionary];
+    
+    [iSalesDB jk_query:sql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
+        
+        [dic setValue:[NSNumber numberWithInteger:RESULT_TRUE] forKey:@"result"];
+        
+        int product_id = sqlite3_column_int(stmt, 0);
+        NSString *product_id_string = [NSString stringWithFormat:@"%d",product_id];
+        NSString *name = [self textAtColumn:1 statement:stmt];
+        NSString *description = [self textAtColumn:2 statement:stmt];
+        double price = sqlite3_column_double(stmt, 3);
+        double discount = sqlite3_column_double(stmt,4);
+        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);
+        NSString *img_path = [self textAtColumn:9 statement:stmt];
+        NSString *line_note = [self textAtColumn:10 statement:stmt];
+        double percent = sqlite3_column_double(stmt, 11);
+        
+        NSMutableDictionary *item = @{
+                                @"linenotes": line_note,
+                                @"check": @(1),
+                                @"product_id": product_id_string,
+                                @"available_qty": @(qty),
+                                @"available_percent" : @(percent),
+                                @"description": description,
+                                @"item_id": [NSString stringWithFormat:@"%d",item_id],
+                                @"fashion_id": [NSString stringWithFormat:@"%d",fashion_id],
+                                @"img": img_path,
+                                @"tear_sheet_discount": [NSString stringWithFormat:@"%f",discount],
+                                @"tear_sheet_price": [NSString stringWithFormat:@"%f",price]
+                                }.mutableCopy;
+        if (percentage) {
+            [item removeObjectForKey:@"available_qty"];
+        } else {
+            [item removeObjectForKey:@"available_percent"];
+        }
+        
+        
+        [dic setObject:item forKey:[NSString stringWithFormat:@"item_%ld",*count]];
+        [dic setValue:[NSNumber numberWithLong:++(*count)] forKey:@"count"];
+        
+    } failure:^(NSMutableDictionary *container, NSString *err_msg) {
+        
+        [dic setValue:[NSNumber numberWithInteger:RESULT_FALSE] forKey:@"result"];
+        
+        [dic setValue:[NSNumber numberWithInteger:0] forKey:@"count"];
+    }];
+    
+    AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
+    
+    [dic setValue:[NSNumber numberWithBool:appDelegate.can_see_price] forKey:@"can_see_price"];
+    [dic setValue:@"" forKey:@"emial_content"];
+    [dic setValue:[dic objectForKey:@"count"] forKey:@"total_count"];
+    [dic setValue:@"Regular Mode" forKey:@"mode"];
+    
+    return [RAUtils dict2data:dic];
+}
+
++ (NSData *)offline_direct_save_TearSheet:(NSMutableDictionary *)params {
+    
+    
+    
+    
+    
+    
+    
+    return nil;
+}
+
++ (NSData *)offline_pdfList:(NSMutableDictionary *)params {
+    
+    int offset = [[params valueForKey:@"offset"] integerValue];
+    int limit = [[params valueForKey:@"limit"] integerValue];
+    NSString *keyword = [params valueForKey:@"keyWord"];
+    
+    NSString *where = @"";
+    if (keyword.length) {
+        
+    }
+    
+    NSString *sql = [NSString stringWithFormat:@"select tear_name,tear_note,createtime,create_user,pdf_path,tearsheets_id from offline_pdf %@ order by createtime desc;",where];
+    
+    __block NSMutableDictionary *dic = [NSMutableDictionary dictionary];
+    
+    [iSalesDB jk_query:sql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
+        
+        NSString *name = [self textAtColumn:0 statement:stmt];
+        NSString *note = [self textAtColumn:1 statement:stmt];
+        NSString *time = [self textAtColumn:2 statement:stmt];
+        NSString *user = [self textAtColumn:3 statement:stmt];
+        NSString *patch = [self textAtColumn:4 statement:stmt];
+        
+        time = [self changeDateTimeFormate:time];
+        time = [time stringByAppendingString:@" PST"];
+        
+        
+        int sheet_id = sqlite3_column_int(stmt, 0);
+        
+        
+        NSMutableDictionary *item = @{
+                                      @"tearsheetsId": @(sheet_id),
+                                      @"pdf_path": patch,
+                                      @"create_time": time,
+                                      @"create_user": user,
+                                      @"tear_note": note,
+                                      @"tear_name": name
+                                      }.mutableCopy;
+        
+        [dic setObject:item forKey:[NSString stringWithFormat:@"item_%ld",*count]];
+        [dic setValue:[NSNumber numberWithLong:++(*count)] forKey:@"count"];
+        
+    } failure:^(NSMutableDictionary *container, NSString *err_msg) {
+        [dic setValue:[NSNumber numberWithInteger:RESULT_FALSE] forKey:@"result"];
+        
+        [dic setValue:[NSNumber numberWithInteger:0] forKey:@"count"];
+    }];
+    
+    [dic setValue:@"Regular Mode" forKey:@"mode"];
+    
+    return [RAUtils dict2data:dic];
+}
+
 @end

+ 13 - 0
RedAnt ERP Mobile/common/data_provider/iSalesDB.m

@@ -721,6 +721,12 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
     
     NSString* create_offline_salesrep=@"CREATE TABLE IF NOT EXISTS offline_salesrep ( _id INTEGER PRIMARY KEY, name text, code text,salesrep_id integer);";
     
+    
+    NSString *create_offline_portfolio = @"create table if not exists offline_portfolio (_id integer primary key,product_id integer,name text,description tex,item_id integer,fashion_id integer,available_qty integer,percentage integer,percent double,sheet_price double,sheet_discount double,img text,line_note text,createtime timestamp default(datetime('now','localtime')),modifytime timestamp default(datetime('now','localtime')));";
+    
+    NSString *create_offline_pdf = @"create table if not exists offline_pdf (_id integer primary key,tearsheets_id integer,pdf_path text,create_user text,tear_note text,tear_name text,createtime timestamp default(datetime('now','localtime')));";
+    
+    
     NSString* create_order_trigger=@"CREATE TRIGGER  if not exists offline_order_insert after insert on offline_order BEGIN select offline_dirty();  UPDATE offline_order SET modify_time= datetime('now', 'localtime') WHERE _id=new._id;END;CREATE TRIGGER  if not exists offline_order_update after update on offline_order BEGIN select offline_dirty();  UPDATE offline_order SET modify_time= datetime('now', 'localtime') WHERE _id=new._id;END;CREATE TRIGGER  if not exists offline_order_delete after delete on offline_order BEGIN select offline_dirty();  END;";
  
     
@@ -732,6 +738,10 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
     //drop trigger if exists wishlist_insert;drop trigger if exists wishlist_update;drop trigger if exists wishlist_delete;
     
     NSString* create_wishlist_trigger=@"CREATE TRIGGER  if not exists wishlist_insert after insert on wishlist BEGIN select offline_dirty();  UPDATE wishlist SET modify_time= datetime('now', 'localtime') WHERE _id=new._id;END;CREATE TRIGGER  if not exists wishlist_update after update on wishlist BEGIN select offline_dirty();  UPDATE wishlist SET modify_time= datetime('now', 'localtime'), is_dirty = 1 WHERE _id=new._id; END;CREATE TRIGGER if not exists wishlist_delete after DELETE ON wishlist BEGIN select offline_dirty(); END;";
+    
+    
+    
+    
     AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
     
     //if(appDelegate.offline_mode)
@@ -769,6 +779,9 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
         [self execSql:create_bundle db:db];
         [self execSql:create_catalog db:db];
         [self execSql:create_errlog db:db];
+        
+        [self execSql:create_offline_portfolio db:db];
+        [self execSql:create_offline_pdf db:db];
 
         
         

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

@@ -1446,14 +1446,16 @@ repeat:
     [params setValue:[NSString stringWithFormat:@"%d",limit]  forKey:@"limit"];
     [params setValue:[NSString stringWithFormat:@"%d",offset]  forKey:@"offset"];
 
+    NSData* json = nil;
     if(appDelegate.offline_mode)
     {
-        return [OLDataProvider offline_notimpl];
+        json = [OLDataProvider offline_pdfList:params];
+    } else {
+        if(![self IsNetworkAvailable])
+            return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+        
+        json=[self get_json:URL_DM_LIST parameters:params];
     }
-    if(![self IsNetworkAvailable])
-        return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
-    
-    NSData* json=[self get_json:URL_DM_LIST parameters:params];
     if(json==nil)
         return nil;
     NSError *error=nil;
@@ -1480,7 +1482,7 @@ repeat:
     
     if(appDelegate.offline_mode)
     {
-        return [OLDataProvider offline_notimpl];
+        json = [OLDataProvider offline_direct_save_TearSheet:params];
     }
     else
     {
@@ -2481,14 +2483,18 @@ repeat:
     [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
     [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
     
+    NSData* json = nil;
     if(appDelegate.offline_mode)
     {
-        return [OLDataProvider offline_notimpl];
+        json = [OLDataProvider offline_portfolioList:params];
+    } else {
+        if(![self IsNetworkAvailable])
+            return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+        
+        json = [self get_json:URL_PORTFOLIO parameters:params];
     }
-    if(![self IsNetworkAvailable])
-        return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
     
-    NSData* json=[self get_json:URL_PORTFOLIO parameters:params];
+    
     if(json==nil)
         return nil;
     NSError *error=nil;