|
@@ -207,8 +207,18 @@
|
|
|
NSMutableDictionary* template = [self get_pdftemplate:template_file];
|
|
NSMutableDictionary* template = [self get_pdftemplate:template_file];
|
|
|
|
|
|
|
|
NSString* file=[pdfCreator CreatePdf: template dataSource:data];
|
|
NSString* file=[pdfCreator CreatePdf: template dataSource:data];
|
|
|
- NSLog(file);
|
|
|
|
|
- return nil;
|
|
|
|
|
|
|
+ DebugLog(@"%@",file);
|
|
|
|
|
+
|
|
|
|
|
+ NSMutableDictionary *dic = [NSMutableDictionary dictionary];
|
|
|
|
|
+ [dic setObject:@"Regular Mode" forKey:@"mode"];
|
|
|
|
|
+ if (file) {
|
|
|
|
|
+ [dic setObject:[NSNumber numberWithInteger:RESULT_TRUE] forKey:@"result"];
|
|
|
|
|
+ [dic setObject:file forKey:@"pdf_path"];
|
|
|
|
|
+ return [RAUtils dict2data:dic];
|
|
|
|
|
+ }
|
|
|
|
|
+ [dic setObject:[NSNumber numberWithInteger:RESULT_FALSE] forKey:@"result"];
|
|
|
|
|
+
|
|
|
|
|
+ return [RAUtils dict2data:dic];
|
|
|
}
|
|
}
|
|
|
+(NSString*) get_offline_soid:(sqlite3*)db
|
|
+(NSString*) get_offline_soid:(sqlite3*)db
|
|
|
{
|
|
{
|
|
@@ -9934,8 +9944,7 @@
|
|
|
return [RAUtils dict2data:dic];
|
|
return [RAUtils dict2data:dic];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-+ (NSData *)offline_direct_save_TearSheet:(NSMutableDictionary *)params {
|
|
|
|
|
-
|
|
|
|
|
|
|
++ (NSData *)offline_savePDF:(NSMutableDictionary *)params direct:(BOOL)direct {
|
|
|
NSMutableDictionary *resultDictionary = [NSMutableDictionary dictionary];
|
|
NSMutableDictionary *resultDictionary = [NSMutableDictionary dictionary];
|
|
|
[resultDictionary setObject:@"Regular Mode" forKey:@"mode"];
|
|
[resultDictionary setObject:@"Regular Mode" forKey:@"mode"];
|
|
|
|
|
|
|
@@ -9943,17 +9952,29 @@
|
|
|
tear_name = [self translateSingleQuote:tear_name];
|
|
tear_name = [self translateSingleQuote:tear_name];
|
|
|
NSString *tear_note = [self valueInParams:params key:@"pdfNote"];
|
|
NSString *tear_note = [self valueInParams:params key:@"pdfNote"];
|
|
|
tear_note = [self translateSingleQuote:tear_note];
|
|
tear_note = [self translateSingleQuote:tear_note];
|
|
|
- NSString *pdf_path = [self valueInParams:params key:@"pdfUrl"];
|
|
|
|
|
|
|
+
|
|
|
|
|
+ NSString *configureParams = [self valueInParams:params key:@"configureParams"];
|
|
|
|
|
+
|
|
|
|
|
+ NSString *pdf_path = @"";
|
|
|
|
|
+ if (direct) {
|
|
|
|
|
+
|
|
|
|
|
+ configureParams = [self valueInParams:params key:@"pdfUrl"];
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+
|
|
|
|
|
+ pdf_path = [self valueInParams:params key:@"pdfPath"];
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
pdf_path = [self translateSingleQuote:pdf_path];
|
|
pdf_path = [self translateSingleQuote:pdf_path];
|
|
|
NSString *create_user = [self valueInParams:params key:@"user"];
|
|
NSString *create_user = [self valueInParams:params key:@"user"];
|
|
|
create_user = [self translateSingleQuote:create_user];
|
|
create_user = [self translateSingleQuote:create_user];
|
|
|
|
|
|
|
|
- NSString *product_ids = [Singleton sharedInstance].pdf_product_ids;
|
|
|
|
|
- NSString *item_ids = [Singleton sharedInstance].pdf_item_ids;
|
|
|
|
|
|
|
+ NSString *product_ids = [self valueInParams:params key:@"product_ids"];
|
|
|
|
|
+ NSString *item_ids = [self valueInParams:params key:@"item_ids"];
|
|
|
|
|
|
|
|
- [Singleton sharedInstance].pdf_product_ids = nil;
|
|
|
|
|
- [Singleton sharedInstance].pdf_item_ids = nil;
|
|
|
|
|
|
|
|
|
|
|
|
+ // model info
|
|
|
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];
|
|
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];
|
|
__block NSMutableDictionary *dic = [NSMutableDictionary dictionary];
|
|
@@ -10009,6 +10030,8 @@
|
|
|
|
|
|
|
|
}];
|
|
}];
|
|
|
|
|
|
|
|
|
|
+ [iSalesDB close_db:db];
|
|
|
|
|
+
|
|
|
if ([[resultDic objectForKey:@"result"] integerValue] != RESULT_TRUE) {
|
|
if ([[resultDic objectForKey:@"result"] integerValue] != RESULT_TRUE) {
|
|
|
|
|
|
|
|
[iSalesDB close_db:db];
|
|
[iSalesDB close_db:db];
|
|
@@ -10016,22 +10039,66 @@
|
|
|
|
|
|
|
|
return [RAUtils dict2data:resultDictionary];
|
|
return [RAUtils dict2data:resultDictionary];
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
NSString *model_info = [RAUtils dict2string:dic];
|
|
NSString *model_info = [RAUtils dict2string:dic];
|
|
|
model_info = [self translateSingleQuote:model_info];
|
|
model_info = [self translateSingleQuote:model_info];
|
|
|
|
|
|
|
|
- NSString *save_pdf_sql = [NSString stringWithFormat:@"insert into offline_pdf (tearsheets_id,pdf_path,create_user,tear_note,tear_name,model_info) values ((select ifnull(max(tearsheets_id),0) from offline_pdf) + 1,'%@','%@','%@','%@','%@');",pdf_path,create_user,tear_note,tear_name,model_info];
|
|
|
|
|
|
|
|
|
|
|
|
+ // 创建PDF
|
|
|
|
|
+
|
|
|
|
|
+ // 在preview情况下保存,则不需要新建了
|
|
|
|
|
+ if (direct) {
|
|
|
|
|
+ NSData *pdfData = [self offline_request_tearsheet:params]; // 新建PDF,获取本地路径
|
|
|
|
|
+
|
|
|
|
|
+ NSDictionary *pdfInfo = [NSJSONSerialization JSONObjectWithData:pdfData options:NSJSONReadingMutableContainers error:nil];
|
|
|
|
|
+ pdf_path = [pdfInfo objectForKey:@"pdf_path"];
|
|
|
|
|
+
|
|
|
|
|
+ if ([[pdfInfo objectForKey:@"result"] integerValue] == RESULT_TRUE) {
|
|
|
|
|
+
|
|
|
|
|
+ resultDictionary = pdfInfo.mutableCopy;
|
|
|
|
|
+
|
|
|
|
|
+ } else { // 创建PDF失败
|
|
|
|
|
+ return pdfData;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // pdf_path 就是本地路径
|
|
|
|
|
+ [resultDictionary setObject:pdf_path forKey:@"pdf_path"];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 将文件移动到PDF Cache文件夹
|
|
|
|
|
+ NSString *newPath = [pdf_path lastPathComponent];
|
|
|
|
|
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
|
|
|
|
+ NSString *cachefolder = [paths objectAtIndex:0];
|
|
|
|
|
+ NSString *pdfFolder = [cachefolder stringByAppendingPathComponent:@"pdf_cache"];
|
|
|
|
|
+ newPath = [pdfFolder stringByAppendingPathComponent:newPath];
|
|
|
|
|
+ NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
|
|
|
+ NSError *error = nil;
|
|
|
|
|
+ [fileManager moveItemAtPath:pdf_path toPath:newPath error:&error];
|
|
|
|
|
+ if (error) { // 移动文件失败
|
|
|
|
|
+ [resultDictionary setObject:[NSNumber numberWithInt:RESULT_FALSE] forKey:@"result"];
|
|
|
|
|
+ return [RAUtils dict2data:resultDictionary];
|
|
|
|
|
+ }
|
|
|
|
|
+ pdf_path = newPath;
|
|
|
|
|
|
|
|
|
|
+ // 保存信息
|
|
|
|
|
|
|
|
- int result = [iSalesDB execSql:save_pdf_sql db:db];
|
|
|
|
|
|
|
+ NSString *save_pdf_sql = [NSString stringWithFormat:@"insert into offline_pdf (tearsheets_id,pdf_path,create_user,tear_note,tear_name,model_info,configureParams) values ((select ifnull(max(tearsheets_id),0) from offline_pdf) + 1,'%@','%@','%@','%@','%@','%@');",pdf_path,create_user,tear_note,tear_name,model_info,configureParams];
|
|
|
|
|
|
|
|
- [iSalesDB close_db:db];
|
|
|
|
|
- [resultDictionary setObject:[NSNumber numberWithInt:result] forKey:@"result"];
|
|
|
|
|
|
|
+ int result = [iSalesDB execSql:save_pdf_sql];
|
|
|
|
|
|
|
|
|
|
+ [resultDictionary setObject:[NSNumber numberWithInt:result] forKey:@"result"];
|
|
|
return [RAUtils dict2data:resultDictionary];
|
|
return [RAUtils dict2data:resultDictionary];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
++ (NSData *)offline_direct_save_TearSheet:(NSMutableDictionary *)params {
|
|
|
|
|
+
|
|
|
|
|
+ return [self offline_savePDF:params direct:YES];
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
++ (NSData *)offline_save_TearSheet:(NSMutableDictionary *)params {
|
|
|
|
|
+ return [self offline_savePDF:params direct:NO];
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
+ (NSData *)offline_pdfList:(NSMutableDictionary *)params {
|
|
+ (NSData *)offline_pdfList:(NSMutableDictionary *)params {
|
|
|
|
|
|
|
|
int offset = [[params valueForKey:@"offset"] integerValue];
|
|
int offset = [[params valueForKey:@"offset"] integerValue];
|