Selaa lähdekoodia

实现离线保存pdf创建信息。

Pen Li 9 vuotta sitten
vanhempi
commit
bee8bf105a

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


+ 96 - 1
RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.m

@@ -16,6 +16,7 @@
 #import "AFHTTPSessionManager.h"
 #import "AppDelegate.h"
 #import "pdfCreator.h"
+#import "Singleton.h"
 
 
 @interface OLDataProvider ()
@@ -9775,7 +9776,99 @@
 
 + (NSData *)offline_direct_save_TearSheet:(NSMutableDictionary *)params {
     
-    return nil;
+    NSMutableDictionary *resultDictionary = [NSMutableDictionary dictionary];
+    [resultDictionary setObject:@"Regular Mode" forKey:@"mode"];
+    
+    NSString *tear_name = [params objectForKey:@"pdfName"];
+    tear_name = [self translateSingleQuote:tear_name];
+    NSString *tear_note = [params objectForKey:@"pdfNote"];
+    tear_note = [self translateSingleQuote:tear_note];
+    NSString *pdf_path = [params objectForKey:@"pdfUrl"];
+    pdf_path = [self translateSingleQuote:pdf_path];
+    NSString *create_user = [params objectForKey:@"user"];
+    create_user = [self translateSingleQuote:create_user];
+    
+    NSString *product_ids = [Singleton sharedInstance].pdf_product_ids;
+    NSString *item_ids = [Singleton sharedInstance].pdf_item_ids;
+    
+    [Singleton sharedInstance].pdf_product_ids = nil;
+    [Singleton sharedInstance].pdf_item_ids = nil;
+    
+    NSString *sql = [NSString stringWithFormat:@"select product_id,ifnull(sheet_price,'null'),sheet_discount,ifnull(available_qty,'null'),percentage,item_id,line_note,percent from offline_portfolio where product_id in (%@);",product_ids];
+    
+    __block NSMutableDictionary *dic = [NSMutableDictionary dictionary];
+    
+    AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
+    
+    sqlite3 *db = [iSalesDB get_db];
+    
+    NSDictionary *resultDic = [iSalesDB jk_query:sql db:db close:NO 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];
+        double price = sqlite3_column_double(stmt, 1);
+        double discount = sqlite3_column_double(stmt,2);
+        int qty = sqlite3_column_int(stmt, 3);
+        int percentage = sqlite3_column_int(stmt, 4);
+        int item_id = sqlite3_column_int(stmt, 5);
+        NSString *line_note = [self textAtColumn:6 statement:stmt];
+        double percent = sqlite3_column_double(stmt, 7);
+        
+        NSString *price_null = [self textAtColumn:3 statement:stmt];
+        if ([price_null isEqualToString:@"null"]) {
+            price = [[self get_model_default_price:appDelegate.contact_id product_id:nil item_id:@(item_id) db:db] doubleValue];
+        }
+        
+        
+        
+        NSMutableDictionary *item = @{
+                                      @"linenotes": line_note,
+                                      @"product_id": product_id_string,
+                                      @"available_qty": @(qty),
+                                      @"available_percent" : @(percent),
+                                      @"item_id": [NSString stringWithFormat:@"%d",item_id],
+                                      @"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"];
+        }
+        
+        NSString *qty_null = [self textAtColumn:3 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"];
+        
+    }];
+    
+    if ([[resultDic objectForKey:@"result"] integerValue] != RESULT_TRUE) {
+        
+        [resultDictionary setObject:[resultDic objectForKey:@"result"] forKey:@"result"];
+        
+        return [RAUtils dict2data:resultDictionary];
+    }
+
+    NSString *model_info = [RAUtils dict2string:dic];
+    model_info = [self translateSingleQuote:model_info];
+    
+    NSString *save_pdf_sql = [NSString stringWithFormat:@"insert into offline_pdf (pdf_path,create_user,tear_note,tear_name,model_info) values ('%@','%@','%@','%@','%@');",pdf_path,create_user,tear_note,tear_name,model_info];
+    
+    
+    
+    int result = [iSalesDB execSql:save_pdf_sql db:db];
+    
+    [resultDictionary setObject:[NSNumber numberWithInt:result] forKey:@"result"];
+    
+    
+    return [RAUtils dict2data:resultDictionary];
 }
 
 + (NSData *)offline_pdfList:(NSMutableDictionary *)params {
@@ -9864,6 +9957,8 @@
 //    }
     
     NSMutableDictionary *dic = [self dictionaryFileName:@"TearSheet.json"];
+    [dic setObject:[params objectForKey:@"product_ids"] forKey:@"product_ids"];
+    [dic setObject:[params objectForKey:@"item_ids"] forKey:@"item_ids"];
     
     return [RAUtils dict2data:dic];
 }

+ 8 - 0
RedAnt ERP Mobile/common/Functions/portfolio/TearSheetParamViewController.m

@@ -10,6 +10,8 @@
 #import "iSalesNetwork.h"
 #import "PDFViewController.h"
 #import "MainViewController.h"
+#import "Singleton.h"
+
 @interface TearSheetParamViewController ()
 
 @end
@@ -424,6 +426,12 @@
 }
 - (void)onSaveClick:(UIButton *)sender {
     
+    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+    if (appDelegate.offline_mode) {
+        [Singleton sharedInstance].pdf_item_ids = [self.content_data_download objectForKey:@"item_ids"];
+        [Singleton sharedInstance].pdf_product_ids = [self.content_data_download objectForKey:@"product_ids"];
+    }
+    
     
     // add params check here.
     [self.lastedit endEditing:true];

+ 1 - 1
RedAnt ERP Mobile/common/data_provider/iSalesDB.m

@@ -724,7 +724,7 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
     
     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,is_delete integer,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_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,model_info 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;";

+ 1 - 1
RedAnt ERP Mobile/common/data_provider/iSalesNetwork.m

@@ -1490,7 +1490,7 @@ repeat:
     
     if(appDelegate.offline_mode)
     {
-        return [OLDataProvider offline_notimpl];
+        json = [OLDataProvider offline_direct_save_TearSheet:params];
     }
     else
     {

+ 4 - 0
RedAnt ERP Mobile/iSales-NPD/Singleton.h

@@ -12,6 +12,10 @@
 
 @property (nonatomic,assign) NSInteger npd_shop_price_type;
 
+@property (nonatomic,copy) NSString *pdf_item_ids; ///<临时数据,用于create PDF
+
+@property (nonatomic,copy) NSString *pdf_product_ids; ///<临时数据,用于create PDF
+
 + (instancetype)sharedInstance;
 
 @end