Przeglądaj źródła

160822

modify model_subtotal func
modify model_bundle func
Ray Zhang 9 lat temu
rodzic
commit
1db6c1022a

+ 37 - 11
RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.m

@@ -1478,7 +1478,7 @@
     NSMutableDictionary* ret = [[NSMutableDictionary alloc]init];
     NSMutableDictionary* ret = [[NSMutableDictionary alloc]init];
     
     
     
     
-    NSString *sqlQuery = [NSString stringWithFormat:@"select item_id,qty,name,description,unit_price from bundle where product_item_id=%d;",item_id];
+    NSString *sqlQuery = [NSString stringWithFormat:@"select b.item_id,b.qty,c.name,c.description,b.unit_price,b.use_unitprice from (select item_id,qty,decrypt(unit_price) as unit_price,use_unitprice from bundle where product_item_id=%d) b left join catalog c on b.item_id=c.item_id;",item_id];
     sqlite3_stmt * statement;
     sqlite3_stmt * statement;
     
     
     int count=0;
     int count=0;
@@ -1503,6 +1503,11 @@
             NSString* nsdescription=[[NSString alloc]initWithUTF8String:description];
             NSString* nsdescription=[[NSString alloc]initWithUTF8String:description];
             
             
             double unit_price = sqlite3_column_double(statement, 4);
             double unit_price = sqlite3_column_double(statement, 4);
+             int use_unitprice = sqlite3_column_int(statement, 5);
+            if(use_unitprice!=1)
+            {
+                unit_price=0;
+            }
             
             
             itemjson[@"model"]=nsname;
             itemjson[@"model"]=nsname;
             itemjson[@"description"]=nsdescription;
             itemjson[@"description"]=nsdescription;
@@ -1518,7 +1523,10 @@
             sqlite3_finalize(statement);
             sqlite3_finalize(statement);
         }
         }
     }
     }
-    return ret;
+    if(count==0)
+        return nil;
+    else
+        return ret;
 }
 }
 +(NSDictionary*) model_subtotal:(int) item_id count:(int)count db:(sqlite3*)db compute_part:(bool)compute
 +(NSDictionary*) model_subtotal:(int) item_id count:(int)count db:(sqlite3*)db compute_part:(bool)compute
 {
 {
@@ -1530,7 +1538,7 @@
     int carton=0;
     int carton=0;
     
     
     
     
-    NSString *sqlQuery = [NSString stringWithFormat:@"select ulength ,uwidth ,uheight ,uweight  ,mlength ,mwidth ,mheight ,mweigth  ,ilength ,iwidth ,iheight , iweight ,pcs ,mpack ,ipack from catalog where item_id=%d;",item_id];
+    NSString *sqlQuery = [NSString stringWithFormat:@"select ulength ,uwidth ,uheight ,uweight  ,mlength ,mwidth ,mheight ,mweigth  ,ilength ,iwidth ,iheight , iweight ,pcs ,mpack ,ipack,ucbf,icbf,mcbf from catalog where item_id=%d;",item_id];
     sqlite3_stmt * statement;
     sqlite3_stmt * statement;
     
     
     
     
@@ -1554,6 +1562,9 @@
             int pcs = sqlite3_column_int(statement,12);
             int pcs = sqlite3_column_int(statement,12);
             int mpack = sqlite3_column_int(statement, 13);
             int mpack = sqlite3_column_int(statement, 13);
             int ipack = sqlite3_column_int(statement, 14);
             int ipack = sqlite3_column_int(statement, 14);
+            double ucbf = sqlite3_column_double(statement, 15);
+            double icbf = sqlite3_column_double(statement, 16);
+            double mcbf = sqlite3_column_double(statement, 17);
             
             
             if(ipack==0)
             if(ipack==0)
             {
             {
@@ -1606,7 +1617,10 @@
                 }
                 }
                 
                 
             }
             }
-            
+#ifdef BUILD_NPD
+            cuft=ucbf*count;
+            weight= uweight*count;
+#endif
             
             
         }
         }
         
         
@@ -1614,6 +1628,9 @@
         sqlite3_finalize(statement);
         sqlite3_finalize(statement);
     }
     }
     
     
+
+    
+    
     if(compute)
     if(compute)
     {
     {
         NSArray * arr_count=nil;
         NSArray * arr_count=nil;
@@ -1646,7 +1663,13 @@
     
     
     
     
     
     
-    NSString *sqlQuery =     [ NSString stringWithFormat:@"select c.product_id,c.str_price,c.discount,c.item_count,c.line_note,m.name,m.description,c.item_id,m.stockUom,c._id from (select _id,product_id,decrypt(str_price),discount,item_count,line_note,item_id from offline_count where so_no='%@') c left join product m on c.product_id=m.product_id",orderCode ];
+    NSString *sqlQuery =     [ NSString stringWithFormat:@"select c.product_id,c.price,c.discount,c.item_count,c.line_note,m.name,m.description,c.item_id,m.stockUom,c._id from (select _id,product_id,decrypt(str_price) as price,discount,item_count,line_note,item_id from offline_cart where so_no='%@') c left join product m on c.product_id=m.product_id",orderCode ];
+
+    
+//        NSString *sqlQuery =     [ NSString stringWithFormat:@"select c.product_id,decrypt(c.str_price),c.discount,c.item_count,c.line_note,m.name,m.description,c.item_id,m.stockUom,c._id from offline_cart c  left join product m on c.product_id=m.product_id where c.so_no='%@'",orderCode ];
+    
+    
+//   NSString *sqlQuery = @"select * from (select decrypt(str_price) from offline_cart) c";
     
     
     DebugLog(@"offline_login sql:%@",sqlQuery);
     DebugLog(@"offline_login sql:%@",sqlQuery);
     sqlite3_stmt * statement;
     sqlite3_stmt * statement;
@@ -1655,7 +1678,8 @@
     [ret setValue:[NSNumber numberWithInt:AP_USER_NOT_AUTH ] forKey:@"result"];
     [ret setValue:[NSNumber numberWithInt:AP_USER_NOT_AUTH ] forKey:@"result"];
     
     
     int count=0;
     int count=0;
-    if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
+    int dbresult=sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil);
+    if ( dbresult== SQLITE_OK)
     {
     {
         
         
         
         
@@ -1700,19 +1724,21 @@
                 nsline_note= [[NSString alloc]initWithUTF8String:line_note];
                 nsline_note= [[NSString alloc]initWithUTF8String:line_note];
             
             
             
             
-            char *name = (char*)sqlite3_column_text(statement, 6);
+            char *name = (char*)sqlite3_column_text(statement, 5);
             NSString *nsname=nil;
             NSString *nsname=nil;
             if(name!=nil)
             if(name!=nil)
                 nsname= [[NSString alloc]initWithUTF8String:name];
                 nsname= [[NSString alloc]initWithUTF8String:name];
             
             
-            char *description = (char*)sqlite3_column_text(statement, 7);
+            char *description = (char*)sqlite3_column_text(statement, 6);
             NSString *nsdescription=nil;
             NSString *nsdescription=nil;
             if(description!=nil)
             if(description!=nil)
                 nsdescription= [[NSString alloc]initWithUTF8String:description];
                 nsdescription= [[NSString alloc]initWithUTF8String:description];
             
             
+
             
             
             int stockUom = sqlite3_column_int(statement, 9);
             int stockUom = sqlite3_column_int(statement, 9);
             int _id = sqlite3_column_int(statement, 10);
             int _id = sqlite3_column_int(statement, 10);
+
             
             
             NSDictionary* bsubtotaljson=[self model_subtotal:item_id count:item_count db:db compute_part:true];
             NSDictionary* bsubtotaljson=[self model_subtotal:item_id count:item_count db:db compute_part:true];
             double cuft=[bsubtotaljson[@"cuft"] doubleValue];
             double cuft=[bsubtotaljson[@"cuft"] doubleValue];
@@ -1726,7 +1752,7 @@
             itemjson[@"carton"]=[NSNumber numberWithInt:carton];
             itemjson[@"carton"]=[NSNumber numberWithInt:carton];
             itemjson[@"cart_item_id"]=[NSNumber numberWithInt:_id];
             itemjson[@"cart_item_id"]=[NSNumber numberWithInt:_id];
             itemjson[@"check"]=@"true";
             itemjson[@"check"]=@"true";
-            itemjson[@"product_id"]=[NSNumber numberWithInt:product_id];
+            itemjson[@"product_id"]=[NSNumber numberWithInt:product_id].stringValue;
             itemjson[@"count"]=[NSNumber numberWithInt:item_count];
             itemjson[@"count"]=[NSNumber numberWithInt:item_count];
             itemjson[@"unit_price"]=Price;
             itemjson[@"unit_price"]=Price;
             itemjson[@"discount"]=[NSNumber numberWithInt:discount];
             itemjson[@"discount"]=[NSNumber numberWithInt:discount];
@@ -1739,7 +1765,7 @@
         }
         }
         
         
         
         
-        
+            ret[@"result"]=[NSNumber numberWithInt:RESULT_TRUE ];
         sqlite3_finalize(statement);
         sqlite3_finalize(statement);
     }
     }
     
     
@@ -1754,7 +1780,7 @@
     ret[@"wish_count"]=[NSNumber numberWithInt:wish_count ];
     ret[@"wish_count"]=[NSNumber numberWithInt:wish_count ];
     ret[@"cart_count"]=[NSNumber numberWithInt:cart_count ];
     ret[@"cart_count"]=[NSNumber numberWithInt:cart_count ];
     ret[@"count"]=[NSNumber numberWithInt:cart_count ];
     ret[@"count"]=[NSNumber numberWithInt:cart_count ];
-    ret[@"result"]=[NSNumber numberWithInt:RESULT_TRUE ];
+
     ret[@"mode"]=@"Regular Mode";
     ret[@"mode"]=@"Regular Mode";
     
     
     ret[@"general_note"]=@"GENERAL NOTE NOT IMPL";
     ret[@"general_note"]=@"GENERAL NOTE NOT IMPL";

+ 2 - 2
RedAnt ERP Mobile/common/data_provider/iSalesDB.m

@@ -637,7 +637,7 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
     
     
     NSString* create_product=@"CREATE TABLE IF NOT EXISTS product ( _id INTEGER PRIMARY KEY, name VARCHAR(20,0), description VARCHAR(20,0), product_id INTEGER, color VARCHAR(20,0), legcolor VARCHAR(20,0), availability INTEGER, incoming_stock INTEGER, ETA DATE, demension VARCHAR(20,0), seat_height VARCHAR(20,0), material VARCHAR(20,0), box_dim VARCHAR(20,0), volume VARCHAR(20,0), weight VARCHAR(20,0), model_set VARCHAR(20,0), load_ability VARCHAR(20,0), default_category VARCHAR(20,0), category VARCHAR(100,0), fabric_content VARCHAR(20,0), assembling VARCHAR(20,0), made_in VARCHAR(20,0), special_remarks VARCHAR(20,0), stockUom integer, fashion VARCHAR(20,0), isnew integer, property_field VARCHAR(20,0), property_display VARCHAR(20,0), selector_field VARCHAR(20,0), selector_display VARCHAR(20,0), product_group VARCHAR(20,0), packaging VARCHAR(20,0), closeout integer ,best_seller integer,alert VARCHAR(20,0),has_bundle integer,is_active integer,item_id integer);";
     NSString* create_product=@"CREATE TABLE IF NOT EXISTS product ( _id INTEGER PRIMARY KEY, name VARCHAR(20,0), description VARCHAR(20,0), product_id INTEGER, color VARCHAR(20,0), legcolor VARCHAR(20,0), availability INTEGER, incoming_stock INTEGER, ETA DATE, demension VARCHAR(20,0), seat_height VARCHAR(20,0), material VARCHAR(20,0), box_dim VARCHAR(20,0), volume VARCHAR(20,0), weight VARCHAR(20,0), model_set VARCHAR(20,0), load_ability VARCHAR(20,0), default_category VARCHAR(20,0), category VARCHAR(100,0), fabric_content VARCHAR(20,0), assembling VARCHAR(20,0), made_in VARCHAR(20,0), special_remarks VARCHAR(20,0), stockUom integer, fashion VARCHAR(20,0), isnew integer, property_field VARCHAR(20,0), property_display VARCHAR(20,0), selector_field VARCHAR(20,0), selector_display VARCHAR(20,0), product_group VARCHAR(20,0), packaging VARCHAR(20,0), closeout integer ,best_seller integer,alert VARCHAR(20,0),has_bundle integer,is_active integer,item_id integer);";
     
     
-    NSString* create_catalog=@"CREATE TABLE IF NOT EXISTS catalog ( _id INTEGER PRIMARY KEY, name VARCHAR(20,0), description VARCHAR(20,0), item_id INTEGER,is_active integer,ulength float,uwidth float,uheight float,uweight float,pcs integer,mpack integer,mlength float,mwidth float,mheight float,mweigth float,ipack integer,ilength float,iwidth float,iheight float, iweight float,is_single_model integer, is_master_model integer,is_rate integer,is_part integer);";
+    NSString* create_catalog=@"CREATE TABLE IF NOT EXISTS catalog ( _id INTEGER PRIMARY KEY, name VARCHAR(20,0), description VARCHAR(20,0), item_id INTEGER,is_active integer,ulength float,uwidth float,uheight float,uweight float,pcs integer,mpack integer,mlength float,mwidth float,mheight float,mweigth float,ipack integer,ilength float,iwidth float,iheight float, iweight float,ucbf float,icbf float, mcbf float,is_single_model integer, is_master_model integer,is_rate integer,is_part integer);";
     
     
     NSString* create_bundle=@"CREATE TABLE IF NOT EXISTS bundle ( _id INTEGER PRIMARY KEY, product_id integer,product_item_id integer,item_id integer,unit_price double,use_unitprice integer,qty integer);";
     NSString* create_bundle=@"CREATE TABLE IF NOT EXISTS bundle ( _id INTEGER PRIMARY KEY, product_id integer,product_item_id integer,item_id integer,unit_price double,use_unitprice integer,qty integer);";
     
     
@@ -648,7 +648,7 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
     
     
     NSString* create_image=@"CREATE TABLE IF NOT EXISTS model_image ( _id INTEGER PRIMARY KEY, name VARCHAR(20), url text, type integer, product_id INTEGER,item_id integer, default_img integer,picture_id integer);";
     NSString* create_image=@"CREATE TABLE IF NOT EXISTS model_image ( _id INTEGER PRIMARY KEY, name VARCHAR(20), url text, type integer, product_id INTEGER,item_id integer, default_img integer,picture_id integer);";
     
     
-    NSString* create_model_price=@"CREATE TABLE IF NOT EXISTS model_price ( _id INTEGER PRIMARY KEY, product_id INTEGER,item_id integer, price text , type integer, price_name text, expire_datetime datetime);";
+    NSString* create_model_price=@"CREATE TABLE IF NOT EXISTS model_price ( _id INTEGER PRIMARY KEY, item_id integer, price text , type integer, price_name text, expire_datetime datetime);";
     
     
     //NSString* create_model_ext=@"CREATE TABLE IF NOT EXISTS model_ext ( _id INTEGER PRIMARY KEY, product_id INTEGER,carton integer, cuft double, weight double;";
     //NSString* create_model_ext=@"CREATE TABLE IF NOT EXISTS model_ext ( _id INTEGER PRIMARY KEY, product_id INTEGER,carton integer, cuft double, weight double;";
     
     

+ 7 - 2
RedAnt ERP Mobile/common/data_provider/iSalesNetwork.m

@@ -2199,14 +2199,19 @@ repeat:
     
     
     if(appDelegate.order_code!=nil)
     if(appDelegate.order_code!=nil)
         [params setValue:appDelegate.order_code forKey:@"orderCode"];
         [params setValue:appDelegate.order_code forKey:@"orderCode"];
+    
+    NSData* json=nil;
     if(appDelegate.offline_mode)
     if(appDelegate.offline_mode)
     {
     {
-        return [OLDataProvider offline_notimpl];
+        json= [OLDataProvider offline_requestcart:params];
     }
     }
+    else
+    {
     if(![self IsNetworkAvailable])
     if(![self IsNetworkAvailable])
         return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
         return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
     
     
-    NSData* json=[self get_json:URL_CART parameters:params];
+    json=[self get_json:URL_CART parameters:params];
+    }
     if(json==nil)
     if(json==nil)
         return nil;
         return nil;
     NSError *error=nil;
     NSError *error=nil;