Переглянути джерело

iSalesDB 增加方法 + (NSDictionary *)jk_query:(NSString *)sql completion:(queryBlock)block failure:(failureBlock)failure
getState 方法中查询state 为空时 增加 Other 选项
addreditor 方法中 state第一个选项增加为 Other

Pen Li 9 роки тому
батько
коміт
02b1108e0d

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


+ 132 - 9
RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.m

@@ -2839,6 +2839,7 @@
             code = "";
         }
         
+        
         NSMutableDictionary *stateDic = [NSMutableDictionary dictionaryWithCapacity:2];
         [stateDic setValue:[NSString stringWithUTF8String:name] forKey:@"value"];
         [stateDic setValue:[NSString stringWithUTF8String:code] forKey:@"value_id"];
@@ -2851,8 +2852,39 @@
         NSString *key = [NSString stringWithFormat:@"val_%ld",(*count)++];
         [container setValue:stateDic forKey:key];
         
+    } failure:^(NSMutableDictionary *container,NSString *err_msg){
+        
+        DebugLog(@"query all state error: %@",err_msg);
+        
+//        NSMutableDictionary *stateDic = [NSMutableDictionary dictionaryWithCapacity:2];
+//        [stateDic setValue:@"Other" forKey:@"value"];
+//        [stateDic setValue:@"" forKey:@"value_id"];
+//        [stateDic setValue:[NSNumber numberWithInt:0] forKey:@"check"];
+//        
+//        if (state_code && [@"" isEqualToString:state_code]) {
+//            [stateDic setValue:[NSNumber numberWithInt:1] forKey:@"check"];
+//        }
+//
+//        NSString *key = [NSString stringWithFormat:@"val_0"];
+//        [container setValue:stateDic forKey:key];
+        
     }] mutableCopy];
     
+    // failure 可以不用了,一样的
+    if (ret.allKeys.count == 0) {
+        NSMutableDictionary *stateDic = [NSMutableDictionary dictionaryWithCapacity:2];
+        [stateDic setValue:@"Other" forKey:@"value"];
+        [stateDic setValue:@"" forKey:@"value_id"];
+        [stateDic setValue:[NSNumber numberWithInt:0] forKey:@"check"];
+        
+        if (state_code && [@"" isEqualToString:state_code]) {
+            [stateDic setValue:[NSNumber numberWithInt:1] forKey:@"check"];
+        }
+        
+        NSString *key = [NSString stringWithFormat:@"val_0"];
+        [ret setValue:stateDic forKey:key];
+    }
+    
     [ret setValue:[NSNumber numberWithInt:ret.allKeys.count] forKey:@"count"];
     
     return ret;
@@ -6692,7 +6724,8 @@
     double totalWeight = [[total valueForKey:@"totalWeight"] doubleValue];
     int totalCarton = [[total valueForKey:@"totalCarton"] doubleValue];
     double payments = [[total valueForKey:@"payments"] doubleValue];
-    double totalPrice = payments + lift_gate_value + shipping + handling_fee;
+//    double totalPrice = payments + lift_gate_value + shipping + handling_fee;
+    double totalPrice = payments;
     
     [dic setValue:@"Order Total" forKey:@"title"];
     
@@ -6713,7 +6746,7 @@
                                        @"name" : @"handling_fee_value",
                                        @"required" : @"true",
                                        @"type" : @"price",
-                                       @"value" : [NSString stringWithFormat:@"%.2f",handling_fee]
+                                       @"value" : @"Shipping To Be Quoted"/*[NSString stringWithFormat:@"%.2f",handling_fee]*/
                                        };
    
     
@@ -6724,7 +6757,7 @@
                                    @"name" : @"shipping",
                                    @"required" : @"true",
                                    @"type" : @"price",
-                                   @"value" : [NSString stringWithFormat:@"%.2f",shipping]
+                                   @"value" : @"Shipping To Be Quoted"/*[NSString stringWithFormat:@"%.2f",shipping]*/
                                    };
    
     
@@ -6735,7 +6768,7 @@
                                    @"name" : @"lift_gate_value",
                                    @"required" : @"true",
                                    @"type" : @"price",
-                                   @"value" : [NSString stringWithFormat:@"%.2f",lift_gate_value]
+                                   @"value" : @"Shipping To Be Quoted"/*[NSString stringWithFormat:@"%.2f",lift_gate_value]*/
                                    };
     
     int item_count = 1;
@@ -6832,11 +6865,7 @@
     
     return dic;
 }
-+(NSData*) offline_addreditor :(NSMutableDictionary *) params
-{
-    NSMutableDictionary * ret = [self offline_notimpl];
-    return [RAUtils dict2data:ret];
-}
+
 + (NSDictionary *)shippingMethodDic:(NSDictionary *)params db:(sqlite3 *)db {
     NSMutableDictionary *dic = [NSMutableDictionary dictionary];
     
@@ -7018,6 +7047,100 @@
 //    return nil;
 }
 
+#pragma mark addr editor
+
++ (NSMutableDictionary *)anameDealWithStarAtItem:(NSDictionary *)item add:(BOOL)add {
+    NSMutableDictionary *new_item = [item mutableCopy];
+    
+    [new_item setValue:add ? @"true" : @"false" forKey:@"required"];
+    
+    return new_item;
+}
+
++(NSData*) offline_addreditor :(NSMutableDictionary *) params
+{
+    //    "is_subaction" = true;
+    //    orderCode = MOB1608240002;
+    //    password = 123456;
+    //    "subaction_tag" = 1;
+    //    user = EvanK;
+    
+    //    {
+    //        "is_subaction" = true;
+    //        orderCode = MOB1608240002;
+    //        password = 123456;
+    //        "refresh_trigger" = zipcode;
+    //        "subaction_tag" = 1;
+    //        user = EvanK;
+    //    }
+    
+    NSMutableDictionary * ret = [self dictionaryFileName:@"createContact.json"];
+    [ret removeObjectForKey:@"up_params"];
+    [ret setObject:@"New Address" forKey:@"title"];
+    
+    NSDictionary * section_0 = [ret objectForKey:@"section_0"];
+    NSMutableDictionary *new_section_0 = [NSMutableDictionary dictionary];
+    
+    [new_section_0 setObject:[NSNumber numberWithInteger:14] forKey:@"count"];
+    
+    NSMutableDictionary *country_dic = [section_0[@"item_5"] mutableCopy];
+    [country_dic removeObjectForKey:@"refresh"];
+    [country_dic removeObjectForKey:@"restore"];
+    [new_section_0 setObject:country_dic forKey:@"item_0"]; // Country
+    
+    
+    [new_section_0 setObject:section_0[@"item_0"] forKey:@"item_1"]; // company name*
+    [new_section_0 setObject:[self anameDealWithStarAtItem:section_0[@"item_6"] add:YES] forKey:@"item_2"]; // Address 1*
+    [new_section_0 setObject:section_0[@"item_7"] forKey:@"item_3"]; // Address 2
+    [new_section_0 setObject:section_0[@"item_8"] forKey:@"item_4"]; // Address 3
+    [new_section_0 setObject:section_0[@"item_9"] forKey:@"item_5"]; // Address 4
+    
+    NSMutableDictionary *zip_code_dic = [self anameDealWithStarAtItem:section_0[@"item_10"] add:YES];
+    [zip_code_dic removeObjectForKey:@"refresh"];
+    [new_section_0 setObject:zip_code_dic forKey:@"item_6"]; // Zip Code*
+    
+    [new_section_0 setObject:[self anameDealWithStarAtItem:section_0[@"item_11"] add:YES] forKey:@"item_7"]; // State/Province*
+    [new_section_0 setObject:[self anameDealWithStarAtItem:section_0[@"item_12"] add:YES] forKey:@"item_8"]; // City*
+    [new_section_0 setObject:section_0[@"item_13"] forKey:@"item_9"]; // Contact First Name
+    [new_section_0 setObject:section_0[@"item_14"] forKey:@"item_10"]; // Contact Last Name
+    [new_section_0 setObject:section_0[@"item_4"] forKey:@"item_11"]; // Phone*
+    [new_section_0 setObject:section_0[@"item_15"] forKey:@"item_12"]; // Fax
+    [new_section_0 setObject:[self anameDealWithStarAtItem:section_0[@"item_3"] add:NO] forKey:@"item_13"]; // Email
+    [new_section_0 setObject:section_0[@"title"] forKey:@"title"];
+    
+    
+    // country
+    NSString *countryCode = @"US";
+    NSDictionary *allCountry = [self offline_getAllCountryDefault:countryCode];
+    [self setValue:allCountry forItemKey:@"item_0" valueKey:@"cadedate" inDictionary:new_section_0];
+    
+    
+    // state
+    NSMutableDictionary *allState = [[self offline_getStateByCountryCode:countryCode checkedState:nil] mutableCopy];
+    
+    NSDictionary *tmpDic = @{
+                             @"value" : @"Other",
+                             @"value_id" : @"",
+                             @"check" : [NSNumber numberWithInteger:0]
+                             };
+    
+    for (int i = 0; i < allState.allKeys.count; i++) {
+        NSString *key = [NSString stringWithFormat:@"val_%d",i];
+        
+        NSDictionary *tmp = allState[key];
+        [allState setValue:tmpDic forKey:key];
+        tmpDic = tmp;
+    }
+    [allState setValue:[NSNumber numberWithInteger:allState.allKeys.count - 1] forKey:@"count"];
+    
+    [self setValue:allState forItemKey:@"item_7" valueKey:@"cadedate" inDictionary:new_section_0];
+    
+    [ret setValue:new_section_0 forKey:@"section_0"];
+    
+    return [RAUtils dict2data:ret];
+}
+
+
 #pragma mark cancel order
 
 

+ 3 - 1
RedAnt ERP Mobile/common/data_provider/iSalesDB.h

@@ -12,7 +12,7 @@
 #import "config.h"
 
 typedef void(^queryBlock)(sqlite3_stmt *stmt,NSMutableDictionary *container,long *count);
-
+typedef void(^failureBlock)(NSMutableDictionary *container,NSString *err_msg);
 
 @interface iSalesDB : NSObject
 
@@ -54,6 +54,8 @@ typedef void(^queryBlock)(sqlite3_stmt *stmt,NSMutableDictionary *container,long
 
 + (NSDictionary *)jk_query:(NSString *)sql db:(sqlite3 *)db close:(BOOL)close completion:(queryBlock)block;
 
++ (NSDictionary *)jk_query:(NSString *)sql completion:(queryBlock)block failure:(failureBlock)failure;
+
 + (NSString *)jk_queryText:(NSString *)sql;
 
 @end

+ 21 - 3
RedAnt ERP Mobile/common/data_provider/iSalesDB.m

@@ -972,6 +972,14 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
 
 + (NSDictionary *)jk_query:(NSString *)sql completion:(queryBlock)block {
     
+    return [self jk_query:sql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
+        if (block) {
+            block(stmt,container,count);
+        }
+    } failure:nil];
+}
+
++ (NSDictionary *)jk_query:(NSString *)sql completion:(queryBlock)block failure:(failureBlock)failure {
     __block NSMutableDictionary *dic = [NSMutableDictionary dictionary];
     
     sqlite3 *db = [iSalesDB get_db];
@@ -980,11 +988,21 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
     
     if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK) {
         long count = 0;
-        while (sqlite3_step(statement) == SQLITE_ROW) {
-            block(statement,dic,&count);
+        if (block) {
+            while (sqlite3_step(statement) == SQLITE_ROW) {
+                block(statement,dic,&count);
+            }
+
         }
-        
         sqlite3_finalize(statement);
+    } else {
+        if (failure) {
+            const char *err = sqlite3_errmsg(db);
+            if (err == NULL) {
+                err = "";
+            }
+             failure(dic,[NSString stringWithUTF8String:err]);
+        }
     }
     [iSalesDB close_db:db];