Răsfoiți Sursa

160818

fix offline_createorder func no orderCode
add offline_add2cart
Ray Zhang 9 ani în urmă
părinte
comite
79a6cb02d0

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

@@ -1292,11 +1292,16 @@
                 soId="";
             NSString *nssoId = [[NSString alloc]initWithUTF8String:soId];
             [ret setValue:nssoId forKey:@"soId"];
+            [ret setValue:nssoId forKey:@"orderCode"];
             
         }
         sqlite3_finalize(statement);
     }
     
+    [ret setValue:[NSNumber numberWithInt:0] forKey:@"orderStatus"];
+    [ret setValue:@"Regular Mode" forKey:@"mode"];
+
+    
     [iSalesDB close_db:db];
     
     return [RAUtils dict2data:ret];
@@ -1307,15 +1312,12 @@
 {
     
     
-    int count = [params[@"count"] intValue];
-    NSString* product_id=params[@"product_id"];
-    NSString* orderCode=params[@"orderCode"];
-   
     NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
     
     
+    NSString* orderCode = [params valueForKey:@"orderCode"];
+    
     
-
     
     sqlite3 *db = [iSalesDB get_db];
     
@@ -1329,20 +1331,55 @@
     [iSalesDB close_db:db];
     
     return [RAUtils dict2data:ret];
+
     
 }
 
 +(NSData*) offline_add2cart :(NSMutableDictionary *) params;
 {
+    NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
+     sqlite3 *db = [iSalesDB get_db];
     
-        NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-        
+    int count =0;
+    if(params[@"count"]!=nil)
+    {
+        count = [params[@"count"] intValue];
+    }
+
         
-        NSString* orderCode = [params valueForKey:@"orderCode"];
+    NSString* product_id=params[@"product_id"];
+    NSString* orderCode=params[@"orderCode"];
+
+    
+    NSArray* arr_id=[RAUtils string2arr:product_id separator:@","];
+
+    for(int i=0;i<arr_id.count;i++)
+    {
         
+        int _id=[iSalesDB get_recordid:db table:@"offline_cart" where:[NSString stringWithFormat:@"so_no='%@' and product_id=%@",orderCode,arr_id[i]]];
+        int item_qty= count;
+        if(item_qty==0)
+            item_qty=[self model_stockUom:[arr_id[i] intValue] db:db];
         
+        NSString* sql=nil;
+       
+        if(_id<0)
+        {
+             NSString* bundle_serialno= [self model_bundle:[arr_id[i] intValue] db:db];
+            sql=[NSString stringWithFormat:@"insert into offline_cart(product_id,so_no,item_count,bundle_item) values(%@,'%@',%d,'%@')",arr_id[i],orderCode,item_qty,bundle_serialno];
+            
+        }
+        else
+        {
+            sql=[NSString stringWithFormat:@"update offline_cart set item_count=item_count+%d where _id=%d",item_qty,_id];
+            
+        }
+        [iSalesDB execSql:sql db:db];
         
-        sqlite3 *db = [iSalesDB get_db];
+    }
+
+    
+   
         
         int cart_count=[iSalesDB get_recordcount:db table:@"offline_cart" where:[NSString stringWithFormat:@"so_no='%@'",orderCode]];
         
@@ -2205,6 +2242,60 @@
    // [iSalesDB close_db:db];
     
     return ret;
+}
++(NSString*) model_bundle:(int)product_id db:(sqlite3*)db
+{
+    NSString* ret = @"";
+    NSMutableArray* arr_bundle = [[NSMutableArray alloc]init];
+    
+    NSString *sqlQuery = [NSString stringWithFormat:@"select serial_no from bundle where product_id=%d;",product_id];
+    sqlite3_stmt * statement;
+    
+    
+    if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
+    {
+        
+        while (sqlite3_step(statement) == SQLITE_ROW)
+        {
+            char *serial_no = (char*)sqlite3_column_text(statement, 0);
+            if(serial_no==nil)
+                serial_no="";
+            NSString *nsserial_no = [[NSString alloc]initWithUTF8String:serial_no];
+            
+            [arr_bundle addObject:nsserial_no];
+        }
+        
+        ret=[RAUtils arr2string:arr_bundle separator:@";" trim:true];
+        
+        sqlite3_finalize(statement);
+    }
+    if(ret==nil)
+        ret=@"";
+    return ret;
+}
++(int) model_stockUom :(int)product_id db:(sqlite3*)db
+{
+    // get default sold qty, return -1 if model not found;
+    int ret = -1;
+    NSString *sqlQuery = [NSString stringWithFormat:@"select stockUom from model where product_id=%d;",product_id];
+    sqlite3_stmt * statement;
+    
+    
+    if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
+    {
+        
+        if (sqlite3_step(statement) == SQLITE_ROW)
+        {
+            ret = sqlite3_column_int(statement, 0);
+        }
+        
+        
+        sqlite3_finalize(statement);
+    }
+    
+    return ret;
+    
+    
 }
 +(NSDictionary*) model_img :(int)product_id db:(sqlite3*)db
 {

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

@@ -657,7 +657,7 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
     
     NSString* create_offline_login=@"CREATE TABLE IF NOT EXISTS offline_login ( _id INTEGER PRIMARY KEY, username VARCHAR(40),password VARCHAR(40), can_show_price integer ,can_see_price integer,contact_id VARCHAR(20),user_type integer,can_cancel_order integer,can_set_cart_price integer,can_create_portfolio integer, can_delete_order integer,can_submit_order integer,can_set_tearsheet_price integer,can_create_order integer, can_update_contact_info integer, mode VARCHAR(20), default_price text, price text, user_id integer,sales_code text);";
     
-    NSString* create_offline_order=@"CREATE TABLE IF NOT EXISTS offline_order ( _id INTEGER PRIMARY KEY,so_id text, order_id text ,status integer, general_notes TEXT ,internal_notes text,signature  text,user_type integer,contact_id text,sales_rep TEXT,create_by TEXT, total_price float, erpOrderStatus integer, logist text, lift_gate integer, logistic_note text, paymentType text, credit_card_first_name text, credit_card_last_name text, credit_card_address1 text, credit_card_address2 text, credit_card_zipcode text, credit_card_type text, credit_card_number text, credit_card_security_code text, credit_card_expiration text,credit_card_city text, credit_card_state text,customer_cid text,customer_contact text,customer_email text,customer_phone text,customer_fax text,receive_cid text,receive_name text,receive_ext text,receive_contact text, receive_phone text,receive_fax text,receive_email text,sender_cid text,sender_name text,sender_ext text,sender_contact text, sender_phone text,sender_fax text,sender_email text,shipping_billto_cid text,shipping_billto_name text,shipping_billto_ext text,shipping_billto_contact text, shipping_billto_phone text,shipping_billto_fax text,shipping_billto_email text,billing_cid text,billing_name text,billing_ext text,billing_contact text, billing_phone text,billing_fax text,billing_email text,returnto_cid text,returnto_name text,returnto_ext text,returnto_contact text, returnto_phone text,returnto_fax text,returnto_email text, must_call int,poNumber text,comments text,comments_ext text,paymentsAndCredits float,shipping float,lift_gate_value float,handling_fee_value float,totalPrice float,TotalCuft float,TotalWeight float,TotalCarton float,sign_picpath text,type integer,sync_data text,create_time TIMESTAMP default (datetime('now', 'localtime')));";
+    NSString* create_offline_order=@"CREATE TABLE IF NOT EXISTS offline_order ( _id INTEGER PRIMARY KEY,so_id text, order_id text ,status integer, general_notes TEXT ,internal_notes text,signature  text,user_type integer,contact_id text,sales_rep TEXT,create_by TEXT, total_price float, erpOrderStatus integer, logist text, lift_gate integer, logistic_note text, paymentType text, credit_card_first_name text, credit_card_last_name text, credit_card_address1 text, credit_card_address2 text, credit_card_zipcode text, credit_card_type text, credit_card_number text, credit_card_security_code text, credit_card_expiration text,credit_card_city text, credit_card_state text,customer_cid text,customer_contact text,customer_email text,customer_phone text,customer_fax text,receive_cid text,receive_name text,receive_ext text,receive_contact text, receive_phone text,receive_fax text,receive_email text,sender_cid text,sender_name text,sender_ext text,sender_contact text, sender_phone text,sender_fax text,sender_email text,shipping_billto_cid text,shipping_billto_name text,shipping_billto_ext text,shipping_billto_contact text, shipping_billto_phone text,shipping_billto_fax text,shipping_billto_email text,billing_cid text,billing_name text,billing_ext text,billing_contact text, billing_phone text,billing_fax text,billing_email text,returnto_cid text,returnto_name text,returnto_ext text,returnto_contact text, returnto_phone text,returnto_fax text,returnto_email text, must_call int,poNumber text,comments text,comments_ext text,paymentsAndCredits float,shipping float,lift_gate_value float,handling_fee_value float,TotalCuft float,TotalWeight float,TotalCarton float,sign_picpath text,type integer,sync_data text,create_time TIMESTAMP default (datetime('now', 'localtime')));";
     
     
     
@@ -881,7 +881,7 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
     sqlite3 *db = [self get_db];
     
     int ret = -1;
-    NSString *sqlQuery = [NSString stringWithFormat:@"select _id from %@ where %@ orderby %@",tablename,whereclause,orderby];
+    NSString *sqlQuery = [NSString stringWithFormat:@"select _id from %@ where %@ order by %@",tablename,whereclause,orderby];
     sqlite3_stmt * statement;
     
     if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
@@ -942,7 +942,7 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
 + (int) get_recordid:(sqlite3*)db table:(NSString*) tablename where:(NSString*) whereclause order:(NSString*) orderby
 {
     int ret = -1;
-    NSString *sqlQuery = [NSString stringWithFormat:@"select _id from %@ where %@ orderby %@",tablename,whereclause,orderby];
+    NSString *sqlQuery = [NSString stringWithFormat:@"select _id from %@ where %@ order by %@",tablename,whereclause,orderby];
     sqlite3_stmt * statement;
     
     if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)

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

@@ -1595,14 +1595,19 @@ repeat:
     {
         [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
     }
+    
+    NSData* json=nil;
     if(appDelegate.offline_mode)
     {
-        return [OLDataProvider offline_notimpl];
+        json=[OLDataProvider offline_add2cart:params];
     }
+    else
+    {
     if(![self IsNetworkAvailable])
         return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
     
-    NSData* json=[self get_json:URL_ADD_TO_CART parameters:params];
+    json=[self get_json:URL_ADD_TO_CART parameters:params];
+    }
     if(json==nil)
         return nil;
     NSError *error=nil;