Ray Zhang 9 лет назад
Родитель
Сommit
6f6970b623

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


+ 158 - 16
RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.m

@@ -121,6 +121,141 @@
     [iSalesDB close_db:db];
     
     
+    return ret;
+}
++(NSMutableDictionary*) preparecart:(NSString* ) orderCode db:(sqlite3*)db
+{
+    NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
+    UIApplication * app = [UIApplication sharedApplication];
+    AppDelegate *appDelegate = (AppDelegate *)[app delegate];
+    
+    
+    
+    
+    
+    
+    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);
+    sqlite3_stmt * statement;
+    
+    
+    [ret setValue:[NSNumber numberWithInt:AP_USER_NOT_AUTH ] forKey:@"result"];
+    
+    int count=0;
+    int dbresult=sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil);
+    if ( dbresult== SQLITE_OK)
+    {
+        
+        
+        while (sqlite3_step(statement) == SQLITE_ROW)
+        {
+            
+            
+            NSMutableDictionary* itemjson = [[NSMutableDictionary alloc] init];
+            
+            
+            
+            
+            int product_id = sqlite3_column_int(statement, 0);
+            
+            char *str_price = (char*)sqlite3_column_text(statement, 1);
+            
+            int item_id = sqlite3_column_int(statement, 7);
+            
+            NSString* Price=nil;
+            if(str_price==nil)
+            {
+                //                NSNumber* price= [self get_model_default_price:appDelegate.contact_id product_id:product_id db:db];
+                NSNumber* price = [self get_model_default_price:appDelegate.contact_id product_id:nil item_id:@(item_id) db:db];
+                if(price==nil)
+                    Price=@"No Price.";
+                else
+                    Price=[NSString stringWithFormat:@"%.2f",price.floatValue];
+            }
+            else
+            {
+                
+                Price=[NSString stringWithFormat:@"%.2f",[[[NSString alloc]initWithUTF8String:str_price] floatValue]];
+            }
+            
+            
+            double discount = sqlite3_column_double(statement, 2);
+            int item_count = sqlite3_column_int(statement, 3);
+            
+            char *line_note = (char*)sqlite3_column_text(statement, 4);
+            NSString *nsline_note=nil;
+            if(line_note!=nil)
+                nsline_note= [[NSString alloc]initWithUTF8String:line_note];
+            
+            
+            char *name = (char*)sqlite3_column_text(statement, 5);
+            NSString *nsname=nil;
+            if(name!=nil)
+                nsname= [[NSString alloc]initWithUTF8String:name];
+            
+            char *description = (char*)sqlite3_column_text(statement, 6);
+            NSString *nsdescription=nil;
+            if(description!=nil)
+                nsdescription= [[NSString alloc]initWithUTF8String:description];
+            
+            
+            
+//            int stockUom = sqlite3_column_int(statement, 8);
+//            int _id = sqlite3_column_int(statement, 9);
+//            
+//            
+//            NSDictionary* bsubtotaljson=[self model_subtotal:item_id count:item_count db:db compute_part:true];
+//            double cuft=[bsubtotaljson[@"cuft"] doubleValue];
+//            double weight=[bsubtotaljson[@"weight"] doubleValue];
+//            int carton=[bsubtotaljson[@"carton"] intValue];
+            
+            //            itemjson[@"img_url"]= [self model_category_img:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:item_id]] model_name:nil db:db];
+//            itemjson[@"img_url"] = [self item_image:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:item_id]] db:db];
+            itemjson[@"model"]=nsname;
+//            itemjson[@"cuft"]=[NSNumber numberWithDouble:cuft];
+//            itemjson[@"weight"]=[NSNumber numberWithDouble:weight];
+//            itemjson[@"carton"]=[NSNumber numberWithInt:carton];
+//            itemjson[@"cart_item_id"]=[NSNumber numberWithInt:_id].stringValue;
+//            itemjson[@"check"]=@"true";
+            itemjson[@"item_id"]=[NSNumber numberWithInt:item_id];
+            
+            itemjson[@"product_id"]=[NSNumber numberWithInt:product_id].stringValue;
+            itemjson[@"count"]=[NSNumber numberWithInt:item_count];
+            itemjson[@"unit_price"]=Price;
+            itemjson[@"discount"]=[NSNumber numberWithInt:discount];
+//            itemjson[@"description"]=[NSString stringWithFormat:@"%@\n%@",nsname,nsdescription ];
+//            itemjson[@"stockUom"]=[NSNumber numberWithInt:stockUom];
+            itemjson[@"note"]=nsline_note;
+            itemjson[@"combine"]=[self model_bundle:item_id db:db compute_part:false];
+            
+            ret[[NSString stringWithFormat:@"item_%d",count]]=itemjson;
+            count++;
+        }
+        
+        
+        ret[@"result"]=[NSNumber numberWithInt:RESULT_TRUE ];
+        sqlite3_finalize(statement);
+    }
+    
+    
+    
+    
+    
+    
+    int cart_count=[iSalesDB get_recordcount:db table:@"offline_cart" where:[NSString stringWithFormat:@"so_no='%@'",orderCode]];
+    
+    ret[@"count"]=[NSNumber numberWithInt:cart_count ];
+
+    
+
+    
     return ret;
 }
 +(NSMutableDictionary*) prepareOrder:(NSString* ) serial soid:(NSArray*) arr_soid
@@ -130,28 +265,20 @@
     for(int i=0;i<arr_soid.count;i++)
     {
         
+        NSMutableDictionary* itemjson = [[NSMutableDictionary alloc] init];
         
-        NSString *sqlQuery =[NSString stringWithFormat:@"select _id,sync_data from offline_order where so_id='%@'",arr_soid[i]];
+        NSString *sqlQuery =[NSString stringWithFormat:@"select _id,sync_data,sign_picpath,so_id from offline_order where so_id='%@'",arr_soid[i]];
         sqlite3_stmt * statement;
         
         
         [ret setValue:[NSNumber numberWithInt:AP_USER_NOT_AUTH ] forKey:@"result"];
         
-        int count=0;
+        //int count=0;
         int dbresult=sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil);
         if ( dbresult== SQLITE_OK)
         {
-            
-            
             if (sqlite3_step(statement) == SQLITE_ROW)
             {
-                
-                
-                NSMutableDictionary* itemjson = [[NSMutableDictionary alloc] init];
-                
-                
-                
-                
                 int _id = sqlite3_column_int(statement, 0);
                 
                 char *sync_data = (char*)sqlite3_column_text(statement, 1);
@@ -161,24 +288,39 @@
                     nssync_data= [[NSString alloc]initWithUTF8String:sync_data];
                     
                 }
+                char *img_1 = (char*)sqlite3_column_text(statement, 2);
+                NSString* nsimg_1=nil;
+                if(img_1!=nil)
+                {
+                    nsimg_1= [[NSString alloc]initWithUTF8String:img_1];
+                    [self copy_upImg:serial file:nsimg_1];
+                }
+                char *so_no = (char*)sqlite3_column_text(statement, 3);
+                NSString* nsso_no=nil;
+                if(so_no!=nil)
+                {
+                    nsso_no= [[NSString alloc]initWithUTF8String:so_no];
+                    
+                }
+                
                 
                 itemjson[@"_id"]=[NSNumber numberWithInt:_id];
                 itemjson[@"json_data"]= nssync_data;
                 
-                
-                ret[[NSString stringWithFormat:@"item_%d",count]]=itemjson;
-                count++;
+                itemjson[@"order_items"]=[self preparecart:nsso_no db:db];
             }
             
             
             ret[@"result"]=[NSNumber numberWithInt:RESULT_TRUE ];
-            sqlite3_finalize(statement);
+            
         }
         
-        ret[@"count"]=[NSNumber numberWithInt:count ];
+        sqlite3_finalize(statement);
+        ret[[NSString stringWithFormat:@"item_%d",i]]=itemjson;
         
         
     }
+    ret[@"count"]=[NSNumber numberWithInt:arr_soid.count ];
     [iSalesDB close_db:db];