|
|
@@ -25,13 +25,58 @@
|
|
|
|
|
|
@implementation OLDataProvider
|
|
|
|
|
|
-+(NSString*) create_portfolio
|
|
|
+
|
|
|
+
|
|
|
++ (NSString *)portfolio_img:(NSString *)item_id db:(sqlite3 *)db
|
|
|
{
|
|
|
- // not impl
|
|
|
- return nil;
|
|
|
+
|
|
|
+ NSString* ret= nil;
|
|
|
+
|
|
|
+ NSString *sqlQuery = nil;
|
|
|
+
|
|
|
+ // sqlQuery = [NSString stringWithFormat:@"select i.url from product m LEFT join model_image i on m.product_id = i.product_id where m.item_id=%@ order by i.default_img desc, i._id asc limit 1;",item_id];// select i.url from model m
|
|
|
+ sqlQuery = [NSString stringWithFormat:@"select i.url from model_image as i where item_id = %@ and i.type<=1 order by i.default_img desc, i.type desc limit 1;",item_id];
|
|
|
+ sqlite3_stmt * statement;
|
|
|
+
|
|
|
+ // int count=0;
|
|
|
+ if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ if (sqlite3_step(statement) == SQLITE_ROW)
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ char *imgurl = (char*)sqlite3_column_text(statement, 0);
|
|
|
+ if(imgurl==nil)
|
|
|
+ imgurl="";
|
|
|
+ NSString *nsimgurl = [[NSString alloc]initWithUTF8String:imgurl];
|
|
|
+
|
|
|
+
|
|
|
+ ret=nsimgurl;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlite3_finalize(statement);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ [ret setValue:@"8" forKey:@"result"];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // [iSalesDB close_db:db];
|
|
|
+ // DebugLog(@"data string: %@",ret );
|
|
|
+
|
|
|
+
|
|
|
+ return ret;
|
|
|
+
|
|
|
}
|
|
|
+(NSMutableDictionary*) prepare_portfolio_data:(NSMutableDictionary*) params
|
|
|
{
|
|
|
+ //生成portfolio pdf需要的数据
|
|
|
NSMutableDictionary* data = [[NSMutableDictionary alloc]init];
|
|
|
data[@"npd_url"]=@"www.newpacificdirect.com";
|
|
|
NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
|
|
|
@@ -40,9 +85,112 @@
|
|
|
data[@"create_month"]=date;
|
|
|
data[@"company_name"]=@"New Pacific Direct,Inc.";
|
|
|
data[@"catalog_name"]=params[@"catalog_name"];
|
|
|
-// NSMutableDictionary* header = [[NSMutableDictionary alloc]init];
|
|
|
-// header[@"icon_small"]=@"portfolio_logo_s";
|
|
|
-// data[@"header"]=header;
|
|
|
+ data[@"PAGE_INDEX"]=@"Page $.{CURRENT_PAGE}.$ of $.{TOTAL_PAGE}.$";
|
|
|
+ data[@"TOTAL_PAGE"]=0;
|
|
|
+ data[@"CURRENT_PAGE"]=0;
|
|
|
+ NSMutableDictionary* grid = [[NSMutableDictionary alloc]init];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ NSString *sql = [NSString stringWithFormat:@"select a.product_id,a.name,a.description,a.price,a.sheet_discount,a.qty,a.percentage,a.item_id,a.fashion_id,a.line_note,a.percent,a._id from (select _id, product_id,name,description,ifnull(sheet_price,'null') as price,sheet_discount,ifnull(available_qty,'null') as qty,percentage,item_id,fashion_id,line_note,percent from offline_portfolio where product_id in(%@)) a left join (select * from product where product_id in(%@)) b on a.product_id=b.product_id",params[@"product_ids"],params[@"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];
|
|
|
+ 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 *line_note = [self textAtColumn:9 statement:stmt];
|
|
|
+ double percent = sqlite3_column_double(stmt, 10);
|
|
|
+ int portfolio_id = sqlite3_column_int(stmt, 11);
|
|
|
+ NSString* img_path = [self portfolio_img:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:item_id]] db:db];
|
|
|
+
|
|
|
+
|
|
|
+ NSString* set_price=@"";
|
|
|
+ NSString *price_null = [self textAtColumn:3 statement:stmt];
|
|
|
+ if ([price_null isEqualToString:@"null"]) {
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ set_price=[NSString stringWithFormat:@"%.2f",price*(1-discount)];
|
|
|
+ }
|
|
|
+ NSString* get_price=@"";
|
|
|
+ {
|
|
|
+ NSNumber* price = [self get_model_default_price:appDelegate.contact_id product_id:nil item_id:@(item_id) db:db];
|
|
|
+ // DebugLog(@"price time interval");
|
|
|
+ // [self printTimeIntervalBetween:price_date and:[NSDate date]];
|
|
|
+
|
|
|
+ if(price!=nil)
|
|
|
+ get_price=[NSString stringWithFormat:@"%.2f",price.floatValue];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ NSMutableDictionary *item = @{
|
|
|
+ @"linenotes": line_note,
|
|
|
+// @"product_id": product_id_string,
|
|
|
+// @"available_qty": @(qty),
|
|
|
+// @"available_percent" : @(percent),
|
|
|
+// @"description": [NSString stringWithFormat:@"%@\n%@",name,description],
|
|
|
+// @"item_id": [NSString stringWithFormat:@"%d",item_id],
|
|
|
+// @"fashion_id": [NSString stringWithFormat:@"%d",product_id],
|
|
|
+ @"img": img_path,
|
|
|
+ @"img_qr": img_path,
|
|
|
+ @"special_price": set_price,
|
|
|
+ @"price": get_price,
|
|
|
+ @"name": get_price,
|
|
|
+ @"description": get_price,
|
|
|
+ @"detail": get_price
|
|
|
+ }.mutableCopy;
|
|
|
+ if (percentage) {
|
|
|
+ [item removeObjectForKey:@"available_qty"];
|
|
|
+ } else {
|
|
|
+ [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"];
|
|
|
+
|
|
|
+ }];
|
|
|
+
|
|
|
+
|
|
|
+ [iSalesDB close_db:db];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// [dic setValue:[NSNumber numberWithBool:appDelegate.can_see_price] forKey:@"can_see_price"];
|
|
|
+// [dic setValue:@"" forKey:@"email_content"];
|
|
|
+// [dic setValue:[dic objectForKey:@"count"] forKey:@"total_count"];
|
|
|
+// [dic setValue:@"Regular Mode" forKey:@"mode"];
|
|
|
+//
|
|
|
+
|
|
|
+
|
|
|
+// NSMutableDictionary* cell = [[NSMutableDictionary alloc]init];
|
|
|
+// cell[@"count"]=[NSNumber numberWithInt:10];
|
|
|
+ grid[@"cell0"]=dic;
|
|
|
+ data[@"grid0"]=grid;
|
|
|
return data;
|
|
|
}
|
|
|
+(NSMutableDictionary*) get_pdftemplate:(NSString*) template
|
|
|
@@ -3698,6 +3846,7 @@
|
|
|
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+(NSDictionary*) model_img :(int)product_id db:(sqlite3*)db
|
|
|
{
|
|
|
NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
|