Pārlūkot izejas kodu

新建Contact Type表。
新建contact、保存Contact、Contact Info和编辑Contact 增加Contact Type,修改新建Address(新建Contact增加Contact Type后修改CreateContact.json文件,导致顺序不对)

Pen Li 9 gadi atpakaļ
vecāks
revīzija
4f676d5fc6

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


+ 72 - 28
RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.m

@@ -3928,7 +3928,7 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
     
     
     {
-        sqlQuery=[NSString stringWithFormat:@"select editable,company_name,country,addr,zipcode,state,city,contact_name,phone,contact_id,addr_1,addr_2,addr_3,addr_4,first_name,last_name,fax,email,img_0,img_1,img_2,price_type,notes,sales_rep from offline_contact where contact_id='%@'",contactId];
+        sqlQuery=[NSString stringWithFormat:@"select editable,company_name,country,addr,zipcode,state,city,contact_name,phone,contact_id,addr_1,addr_2,addr_3,addr_4,first_name,last_name,fax,email,img_0,img_1,img_2,price_type,notes,sales_rep,type from offline_contact where contact_id='%@'",contactId];
         
     }
     
@@ -4108,6 +4108,8 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
             else
                 nssalesrep= [[NSString alloc]initWithUTF8String:salesrep];
             
+            NSString *contact_type = [self textAtColumn:24 statement:statement];
+            
             
             {
                 // decrypt
@@ -4174,7 +4176,7 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
             [item setValue:nscontact_name   forKey:@"customer_contact"];
             [item setValue:nsfax   forKey:@"customer_fax"];
             [item setValue:nsemail   forKey:@"customer_email"];
-            
+            [item setValue:contact_type   forKey:@"customer_contact_type"];
             
             
             [ret setObject:item forKey:@"customerInfo"];
@@ -5131,6 +5133,32 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
     return ret;
 }
 
++ (NSDictionary *)offline_getContactTypeChecked:(NSString *)type {
+    NSString *sql = @"select _id,type_name from contact_type";
+    __block NSMutableDictionary *ret = [NSMutableDictionary dictionary];
+    [ret setValue:[NSNumber numberWithInt:0] forKey:@"count"];
+    
+    [iSalesDB jk_query:sql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
+        
+        int _id = sqlite3_column_int(stmt, 0);
+        NSString *name = [self textAtColumn:1 statement:stmt];
+        
+        NSDictionary *typeDic = @{
+                                  @"value_id" : name,
+                                  @"value" : name,
+                                  @"check" : type && [type isEqualToString:name] ? @(1) : !type && *count == 0 ? @(1) : @(0)
+                                  };
+        
+        [ret setValue:typeDic forKey:[NSString stringWithFormat:@"val_%ld",*count]];
+        [ret setValue:[NSNumber numberWithInt:++(*count)] forKey:@"count"];
+        
+    } failure:^(NSMutableDictionary *container, NSString *err_msg) {
+        
+    }];
+    
+    return  ret;
+}
+
 + (NSDictionary *)offline_getSalesRep {
     
     // 首先从offline_login表中取出sales_code
@@ -5973,9 +6001,9 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
                 city = [dic valueForKey:@"city"];
                 
                 // zip code
-                NSMutableDictionary *zipDic = [[section_0 valueForKey:@"item_10"] mutableCopy];
+                NSMutableDictionary *zipDic = [[section_0 valueForKey:@"item_11"] mutableCopy];
                 [zipDic setValue:zipCode forKey:@"value"];
-                [section_0 setValue:zipDic forKey:@"item_10"];
+                [section_0 setValue:zipDic forKey:@"item_11"];
             }
         }
         
@@ -5987,28 +6015,32 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
     
     // country
     NSDictionary *allCountry = [self offline_getAllCountryDefault:countryCode];
-    [self setValue:allCountry forItemKey:@"item_5" valueKey:@"cadedate" inDictionary:section_0];
+    [self setValue:allCountry forItemKey:@"item_6" valueKey:@"cadedate" inDictionary:section_0];
     
     // state
     NSDictionary *allState = [self offline_getStateByCountryCode:countryCode checkedState:stateCode];
     //     NSDictionary *allState = [self offline_getStateByCountryCodeId:countryCode_id checkedState:stateCode];
-    [self setValue:allState forItemKey:@"item_11" valueKey:@"cadedate" inDictionary:section_0];
+    [self setValue:allState forItemKey:@"item_12" valueKey:@"cadedate" inDictionary:section_0];
     
     // city
     if (city) {
-        NSMutableDictionary *cityDic = [[section_0 valueForKey:@"item_12"] mutableCopy];
+        NSMutableDictionary *cityDic = [[section_0 valueForKey:@"item_13"] mutableCopy];
         [cityDic setValue:city forKey:@"value"];
         
-        [section_0 setValue:cityDic forKey:@"item_12"];
+        [section_0 setValue:cityDic forKey:@"item_13"];
     }
     
     // price type
     NSDictionary *priceDic = [self offline_getPrice];
     [self setValue:priceDic forItemKey:@"item_2" valueKey:@"cadedate" inDictionary:section_0];
     
+    // contact type
+    NSDictionary *contactTypeDic = [self offline_getContactTypeChecked:nil];
+    [self setValue:contactTypeDic forItemKey:@"item_3" valueKey:@"cadedate" inDictionary:section_0];
+    
     // Sales Rep
     NSDictionary *repDic = [self offline_getSalesRep];
-    [self setValue:repDic forItemKey:@"item_17" valueKey:@"cadedate" inDictionary:section_0];
+    [self setValue:repDic forItemKey:@"item_18" valueKey:@"cadedate" inDictionary:section_0];
     
     [ret setValue:section_0 forKey:@"section_0"];
     
@@ -6186,6 +6218,12 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
     
     NSString *contact_id = [NSUUID UUID].UUIDString;
     
+    NSString *contact_type = [params objectForKey:@"type_name"];
+    if (!contact_type) {
+        contact_type = @"";
+    }
+    contact_type = [self translateSingleQuote:contact_type];
+    
     // 判断更新时是否为customer
     if (update) {
         contact_id = [params objectForKey:@"contact_id"];
@@ -6223,7 +6261,7 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
         sync_data = [RAUtils dict2string:sync_dic];
         sync_data = [self translateSingleQuote:sync_data];
         
-        sql = [NSString stringWithFormat:@"update offline_contact set company_name = '%@',addr_1 = '%@',addr_2 = '%@',addr_3 = '%@',addr_4 = '%@',country = '%@',state = '%@',city = '%@',zipcode = '%@',first_name = '%@',last_name = '%@',phone = '%@',fax = '%@',email = '%@',notes = '%@',price_type = '%@',sales_rep = '%@',img_0 = '%@',img_1 = '%@',img_2 = '%@',sync_data = '%@',contact_name = '%@',addr = '%@' where contact_id = '%@';",companyName,addr1,addr2,addr3,addr4,country,state,city,zipcode,fistName,lastName,phone,fax,email,notes,price,salesRep,img_0,img_1,img_2,sync_data,contact_name,addr,contact_id];
+        sql = [NSString stringWithFormat:@"update offline_contact set company_name = '%@',addr_1 = '%@',addr_2 = '%@',addr_3 = '%@',addr_4 = '%@',country = '%@',state = '%@',city = '%@',zipcode = '%@',first_name = '%@',last_name = '%@',phone = '%@',fax = '%@',email = '%@',notes = '%@',price_type = '%@',sales_rep = '%@',img_0 = '%@',img_1 = '%@',img_2 = '%@',sync_data = '%@',contact_name = '%@',addr = '%@',type = '%@' where contact_id = '%@';",companyName,addr1,addr2,addr3,addr4,country,state,city,zipcode,fistName,lastName,phone,fax,email,notes,price,salesRep,img_0,img_1,img_2,sync_data,contact_name,addr,contact_type,contact_id];
     } else {
         
         contact_id = [self translateSingleQuote:contact_id];
@@ -6233,7 +6271,7 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
         sync_data = [RAUtils dict2string:sync_dic];
         sync_data = [self translateSingleQuote:sync_data];
         
-        sql = [NSString stringWithFormat:@"insert into offline_contact (is_active,company_name,addr_1,addr_2,addr_3,addr_4,country,state,city,zipcode,first_name,last_name,phone,fax,email,notes,price_type,sales_rep,img_0,img_1,img_2,editable,contact_id,Sales_Order_Customer,Sales_Order_Freight_Bill_To,Sales_Order_Ship_From,Sales_Order_Merchandise_Bill_To,Contact_Return_To,Sales_Order_Ship_To,sync_data,contact_name,addr) values (1,'%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@',1,'%@',%d,%d,0,%d,0,1,'%@','%@','%@')",companyName,addr1,addr2,addr3,addr4,country,state,city,zipcode,fistName,lastName,phone,fax,email,notes,price,salesRep,img_0,img_1,img_2,contact_id,isCustomer ? 1 : 0,isCustomer ? 1 : 0,isCustomer ? 1 : 0,sync_data,contact_name,addr];
+        sql = [NSString stringWithFormat:@"insert into offline_contact (is_active,company_name,addr_1,addr_2,addr_3,addr_4,country,state,city,zipcode,first_name,last_name,phone,fax,email,notes,price_type,sales_rep,img_0,img_1,img_2,editable,contact_id,Sales_Order_Customer,Sales_Order_Freight_Bill_To,Sales_Order_Ship_From,Sales_Order_Merchandise_Bill_To,Contact_Return_To,Sales_Order_Ship_To,sync_data,contact_name,addr,type) values (1,'%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@',1,'%@',%d,%d,0,%d,0,1,'%@','%@','%@','%@')",companyName,addr1,addr2,addr3,addr4,country,state,city,zipcode,fistName,lastName,phone,fax,email,notes,price,salesRep,img_0,img_1,img_2,contact_id,isCustomer ? 1 : 0,isCustomer ? 1 : 0,isCustomer ? 1 : 0,sync_data,contact_name,addr,contact_type];
     }
     
     int result = [iSalesDB execSql:sql];
@@ -6285,9 +6323,10 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
     __block NSString *phone,*fax,*email;
     __block NSString *notes,*price_type,*sales_rep;
     __block NSString *img_0,*img_1,*img_2;
+    __block NSString *contact_type;
     
     contact_id = [self translateSingleQuote:contact_id];
-    NSString *sql = [NSString stringWithFormat:@"select country,company_name,addr_1,addr_2,addr_3,addr_4,zipcode,state,city,first_name,last_name,phone,fax,email,notes,price_type,sales_rep,img_0,img_1,img_2 from offline_contact where contact_id = '%@';",contact_id];
+    NSString *sql = [NSString stringWithFormat:@"select country,company_name,addr_1,addr_2,addr_3,addr_4,zipcode,state,city,first_name,last_name,phone,fax,email,notes,price_type,sales_rep,img_0,img_1,img_2,type from offline_contact where contact_id = '%@';",contact_id];
     
     [iSalesDB jk_query:sql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
         
@@ -6311,7 +6350,7 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
         img_0 = [self textAtColumn:17 statement:stmt];
         img_1 = [self textAtColumn:18 statement:stmt];
         img_2 = [self textAtColumn:19 statement:stmt];
-        
+        contact_type = [self textAtColumn:20 statement:stmt];
     }];
     
     // decrypt
@@ -6394,7 +6433,8 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
     //    15	Email
     //    16	Contact Notes
     //    17	Price Type
-    //    18	Sales Rep
+    //    18    Contact Type
+    //    19	Sales Rep
     
     // country
     NSDictionary *allCountry = [self offline_getAllCountryDefault:countryCode];
@@ -6459,6 +6499,10 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
     }
     [self setValue:priceDic forItemKey:@"item_17" valueKey:@"cadedate" inDictionary:section_0];
     
+    // Contact Rep
+    NSDictionary *contactTypeDic = [self offline_getContactTypeChecked:contact_type];
+    [self setValue:contactTypeDic forItemKey:@"item_18" valueKey:@"cadedate" inDictionary:section_0];
+    
     // Sales Rep
     NSMutableDictionary *repDic = [[self offline_getSalesRep] mutableCopy];
     for (NSString *key in repDic.allKeys) {
@@ -6472,7 +6516,7 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
             }
         }
     }
-    [self setValue:repDic forItemKey:@"item_18" valueKey:@"cadedate" inDictionary:section_0];
+    [self setValue:repDic forItemKey:@"item_19" valueKey:@"cadedate" inDictionary:section_0];
     
     [ret setValue:section_0 forKey:@"section_0"];
     
@@ -10010,29 +10054,29 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
     
     [new_section_0 setObject:[NSNumber numberWithInteger:14] forKey:@"count"];
     
-    NSMutableDictionary *country_dic = [section_0[@"item_5"] mutableCopy];
+    NSMutableDictionary *country_dic = [section_0[@"item_6"] 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
+    [new_section_0 setObject:[self anameDealWithStarAtItem:section_0[@"item_7"] add:YES] forKey:@"item_2"]; // Address 1*
+    [new_section_0 setObject:section_0[@"item_8"] forKey:@"item_3"]; // Address 2
+    [new_section_0 setObject:section_0[@"item_9"] forKey:@"item_4"]; // Address 3
+    [new_section_0 setObject:section_0[@"item_10"] forKey:@"item_5"]; // Address 4
     
-    NSMutableDictionary *zip_code_dic = [self anameDealWithStarAtItem:section_0[@"item_10"] add:YES];
+    NSMutableDictionary *zip_code_dic = [self anameDealWithStarAtItem:section_0[@"item_11"] 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:[self anameDealWithStarAtItem:section_0[@"item_12"] add:YES] forKey:@"item_7"]; // State/Province*
+    [new_section_0 setObject:[self anameDealWithStarAtItem:section_0[@"item_13"] add:YES] forKey:@"item_8"]; // City*
+    [new_section_0 setObject:section_0[@"item_14"] forKey:@"item_9"]; // Contact First Name
+    [new_section_0 setObject:section_0[@"item_15"] forKey:@"item_10"]; // Contact Last Name
+    [new_section_0 setObject:section_0[@"item_5"] forKey:@"item_11"]; // Phone*
+    [new_section_0 setObject:section_0[@"item_16"] forKey:@"item_12"]; // Fax
+    [new_section_0 setObject:[self anameDealWithStarAtItem:section_0[@"item_4"] add:NO] forKey:@"item_13"]; // Email
     [new_section_0 setObject:section_0[@"title"] forKey:@"title"];
     
     

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

@@ -730,6 +730,8 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
     
     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,configureParams text,is_delete integer,is_dirty integer,is_local integer,off_params text,createtime timestamp default(datetime('now','localtime')),modify_time timestamp DEFAULT(datetime('now','localtime')));";
     
+    NSString *create_contact_type = @"create table if not exists contact_type (_id integer primary key,type_name text);";
+    
     
     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;";
  
@@ -787,7 +789,7 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
         [self execSql:create_offline_portfolio db:db];
         [self execSql:create_offline_pdf db:db];
 
-        
+        [self execSql:create_contact_type db:db];
         
         
     }

+ 25 - 17
RedAnt ERP Mobile/iSales-NPD/createContact.json

@@ -2,7 +2,7 @@
   "mode" : "Regular Mode",
   "result" : 2,
   "section_0" : {
-    "count" : 18,
+    "count" : 19,
     "item_0" : {
       "aname" : "Company Name",
       "control" : "edit",
@@ -20,7 +20,7 @@
       "name" : "business_card",
       "value" : ""
     },
-    "item_10" : {
+    "item_11" : {
       "aname" : "Zip Code",
       "control" : "edit",
       "keyboard" : "text",
@@ -34,7 +34,7 @@
       },
       "value" : ""
     },
-    "item_11" : {
+    "item_12" : {
       "aname" : "State/Province",
       "cadedate" : "",
       "control" : "enum",
@@ -42,14 +42,14 @@
       "required" : "true",
       "single_select" : "true"
     },
-    "item_12" : {
+    "item_13" : {
       "aname" : "City",
       "control" : "edit",
       "keyboard" : "text",
       "name" : "city",
       "value" : ""
     },
-    "item_13" : {
+    "item_14" : {
       "aname" : "Contact First Name",
       "capital" : "1",
       "control" : "edit",
@@ -57,7 +57,7 @@
       "name" : "firstname",
       "value" : ""
     },
-    "item_14" : {
+    "item_15" : {
       "aname" : "Contact Last Name",
       "capital" : "1",
       "control" : "edit",
@@ -65,20 +65,20 @@
       "name" : "lastname",
       "value" : ""
     },
-    "item_15" : {
+    "item_16" : {
       "aname" : "Fax",
       "control" : "edit",
       "keyboard" : "text",
       "name" : "fax",
       "value" : ""
     },
-    "item_16" : {
+    "item_17" : {
       "aname" : "Contact Notes",
       "control" : "text_view",
       "name" : "contact_notes",
       "value" : ""
     },
-    "item_17" : {
+    "item_18" : {
       "aname" : "Sales Rep",
       "cadedate" : "",
       "control" : "enum",
@@ -94,7 +94,15 @@
       "required" : "true",
       "single_select" : "true"
     },
-    "item_3" : {
+  "item_3" : {
+      "aname" : "Contact Type",
+      "cadedate" : "",
+      "control" : "enum",
+      "name" : "type_name",
+      "required" : "true",
+      "single_select" : "true"
+  },
+    "item_4" : {
       "aname" : "Email",
       "control" : "edit",
       "keyboard" : "text",
@@ -102,7 +110,7 @@
       "required" : "true",
       "value" : ""
     },
-    "item_4" : {
+    "item_5" : {
       "aname" : "Phone",
       "control" : "edit",
       "keyboard" : "text",
@@ -110,7 +118,7 @@
       "required" : "true",
       "value" : ""
     },
-    "item_5" : {
+    "item_6" : {
       "aname" : "Country",
       "cadedate" : "",
       "control" : "enum",
@@ -124,28 +132,28 @@
       },
       "single_select" : "true"
     },
-    "item_6" : {
+    "item_7" : {
       "aname" : "Address 1",
       "control" : "edit",
       "keyboard" : "text",
       "name" : "address",
       "value" : ""
     },
-    "item_7" : {
+    "item_8" : {
       "aname" : "Address 2",
       "control" : "edit",
       "keyboard" : "text",
       "name" : "address2",
       "value" : ""
     },
-    "item_8" : {
+    "item_9" : {
       "aname" : "Address 3",
       "control" : "edit",
       "keyboard" : "text",
       "name" : "address_3",
       "value" : ""
     },
-    "item_9" : {
+    "item_10" : {
       "aname" : "Address 4",
       "control" : "edit",
       "keyboard" : "text",
@@ -161,4 +169,4 @@
     "val_0" : "zipcode",
     "val_1" : "country"
   }
-}
+}

+ 11 - 4
RedAnt ERP Mobile/iSales-NPD/editContact.json

@@ -2,7 +2,7 @@
   "mode" : "Regular Mode",
   "result" : 2,
   "section_0" : {
-    "count" : 19,
+    "count" : 20,
     "item_0" : {
       "aname" : "Country",
       "cadedate" : "",
@@ -81,9 +81,16 @@
       "cadedate" : "",
       "control" : "enum",
       "name" : "price_name",
-      "single_select" : "false"
+      "single_select" : "true"
     },
-    "item_18" : {
+  "item_18" : {
+      "aname" : "Contact Type",
+      "cadedate" : "",
+      "control" : "enum",
+      "name" : "type_name",
+      "single_select" : "true"
+  },
+    "item_19" : {
       "aname" : "Sales Rep",
       "cadedate" : "",
       "control" : "enum",
@@ -168,4 +175,4 @@
     "val_0" : "zipcode",
     "val_1" : "country"
   }
-}
+}