|
|
@@ -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];
|
|
|
}
|