Преглед изворни кода

修改orderDetail,增加models、计算payments、total

Pen Li пре 9 година
родитељ
комит
474b6258a2

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


+ 16 - 0
RedAnt ERP Mobile/RedAnt ERP Mobile.xcworkspace/xcuserdata/macmini1.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -13,5 +13,21 @@
             stopOnStyle = "0">
          </BreakpointContent>
       </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            shouldBeEnabled = "Yes"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "common/Functions/offline/OLDataProvider.m"
+            timestampString = "493624961.355323"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "1422"
+            endingLineNumber = "1422"
+            landmarkName = "+offline_add2cart:"
+            landmarkType = "5">
+         </BreakpointContent>
+      </BreakpointProxy>
    </Breakpoints>
 </Bucket>

+ 164 - 52
RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.m

@@ -1766,6 +1766,7 @@
             itemjson[@"combine"]=[self model_bundle:item_id db:db compute_part:false];
             
             ret[[NSString stringWithFormat:@"item_%d",count]]=itemjson;
+            count++;
         }
         
         
@@ -4792,7 +4793,14 @@
     
     
     NSString *customerID = nil; // 在查询结果中还需要调用offline_contactinfo,需要使用,其中要打开db 就会lock,故而将其置于外面,在close db后在调用
-    
+    NSString *nssoid = nil;
+    NSString* orderinfo = nil;
+    NSString *moreInfo = nil;
+    double handlingFee = 0;
+    double payments_and_credist = 0;
+    double totalPrice = 0;
+    double shippingFee = 0;
+    double lift_gate = 0;
     if (sqlite3_prepare_v2(db, [sql UTF8String], -1, &statement, nil) == SQLITE_OK)
     {
         
@@ -4800,17 +4808,13 @@
         if (sqlite3_step(statement) == SQLITE_ROW)
         {
             
-            
-            
-            //            NSMutableDictionary* item=[[NSMutableDictionary alloc]init];
-            
             int order_id = sqlite3_column_int(statement, 0);
             
             
             char *soid = (char*)sqlite3_column_text(statement, 1);
             if(soid==nil)
                 soid= "";
-            NSString *nssoid= [[NSString alloc]initWithUTF8String:soid];
+            nssoid= [[NSString alloc]initWithUTF8String:soid];
             // so#
             ret[@"so#"] = nssoid;
             
@@ -4840,9 +4844,6 @@
             ret[@"orderStatus"] = [NSNumber numberWithInteger:status];
             ret[@"order_status"] = nsstatus;
             
-            double TotalCuft = 0;
-            double TotalWeight = 0;
-            double TotalCarton = 0;
             
             char *company_name = (char*)sqlite3_column_text(statement, 5);
             if(company_name==nil)
@@ -4895,12 +4896,14 @@
             NSString *shipping = [NSString stringWithFormat:@"$%.2f",sqlite3_column_double(statement, 12)];
             if ([[self textAtColumn:48 statement:statement] isEqualToString:@"ship_null"]) {
                 shipping = @"Shipping To Be Quoted";
+            } else {
+                shippingFee = sqlite3_column_double(statement, 12);
             }
             
             // Shipping
             ret[@"Shipping"] = shipping;
             
-            double lift_gate = sqlite3_column_double(statement, 13);
+            lift_gate = sqlite3_column_double(statement, 13);
             // Liftgate Fee(No loading dock)
             ret[@"Liftgate Fee(No loading dock)"] = [NSString stringWithFormat:@"$%.2f",lift_gate];
             
@@ -4922,16 +4925,14 @@
             int have_lift_gate = sqlite3_column_int(statement, 17);
             
             // order info
-            NSString* orderinfo = [self textFileName:@"order_info.html"];
+            orderinfo = [self textFileName:@"order_info.html"];
             
             
             orderinfo = [self replaceHtml:orderinfo String:@"SO_or_nbsp" withString:nssoid];
             orderinfo = [self replaceHtml:orderinfo String:@"PO_or_nbsp" withString:nspoNumber];
             orderinfo = [self replaceHtml:orderinfo String:@"OrderDate_or_nbsp" withString:nscreate_time];
             orderinfo = [self replaceHtml:orderinfo String:@"OrderStatus_or_nbsp" withString:nsstatus];
-            orderinfo = [self replaceHtml:orderinfo String:@"TotalCuft_or_nbsp" withString:[NSString stringWithFormat:@"%.2f",TotalCuft]];
-            orderinfo = [self replaceHtml:orderinfo String:@"TotalWeight_or_nbsp" withString:[NSString stringWithFormat:@"%.2f",TotalWeight]];
-            orderinfo = [self replaceHtml:orderinfo String:@"TotalCarton_or_nbsp" withString:[NSString stringWithFormat:@"%.2f",TotalCarton]];
+            
             orderinfo = [self replaceHtml:orderinfo String:@"CustomerInfo_or_nbsp" withString:nscompany_name];
             orderinfo = [self replaceHtml:orderinfo String:@"CustomerName_or_nbsp" withString:nscustomer_contact];
             orderinfo = [self replaceHtml:orderinfo String:@"CustomerAddress_or_nbsp" withString:customer_address];
@@ -4994,11 +4995,11 @@
                 payment = [self replaceHtml:payment String:@"PAYMENTTYPE_PLACEHOLDER" withString:nspayment_type];
             }
             orderinfo=[self replaceHtml:orderinfo String:@"Payment_info_or_nbsp" withString:payment];
-            ret[@"order_info"]= orderinfo;
+            
             ret[@"result"]= [NSNumber numberWithInt:2];
             
             // more info
-            NSString *moreInfo = [self textFileName:@"more_info.html"];
+           moreInfo = [self textFileName:@"more_info.html"];
             
             /*****ship to******/
             // ShipToCompany_or_&nbsp
@@ -5045,25 +5046,16 @@
             NSString *returnToAddr = [self textAtColumn:32 statement:statement];
             moreInfo = [self replaceHtml:moreInfo String:@"ReturnToAddress_or_" withString:returnToAddr];
             //
-            ret[@"more_order_info"] = moreInfo;
+            
             DebugLog(@"more info : %@",moreInfo);
             
             // handling fee
-            double handlingFee = sqlite3_column_double(statement, 33);
+            handlingFee = sqlite3_column_double(statement, 33);
             ret[@"Handling Fee"] = [NSString stringWithFormat:@"$%.2f",handlingFee];
             
-            // payments/Credits
-            double payments_and_credist = sqlite3_column_double(statement, 34);
-            ret[@"Payments/Credits"] = [NSString stringWithFormat:@"$%.2f",payments_and_credist];
-            
-            // total
-            double totalPrice = sqlite3_column_double(statement, 35);
-            ret[@"Total"] = [NSString stringWithFormat:@"$%.2f",totalPrice];
-            
             // customer info
             customerID = [self textAtColumn:36 statement:statement];
             
-            
             // mode
             ret[@"mode"] = appDelegate.mode;
             
@@ -5086,33 +5078,153 @@
     [iSalesDB close_db:db];
     
     NSDictionary *contactInfo = [self offline_contactinfo:[@{@"contactId":customerID} mutableCopy]];
-    //            NSMutableDictionary *customerInfo = [NSMutableDictionary dictionary];
-    
-    //            customerInfo[@"business_card_0"] = contactInfo[@"business_card_0"];
-    //            customerInfo[@"business_card_1"] = contactInfo[@"business_card_1"];
-    //            customerInfo[@"business_card_2"] = contactInfo[@"business_card_2"];
-    //            customerInfo[@"customer_address1"] = contactInfo[@"customer_address1"];
-    //            customerInfo[@"customer_address2"] = contactInfo[@"customer_address2"];
-    //            customerInfo[@"customer_address3"] = contactInfo[@"customer_address3"];
-    //            customerInfo[@"customer_address4"] = contactInfo[@"customer_address4"];
-    //            customerInfo[@"customer_cid"] = contactInfo[@"customer_cid"];
-    //            customerInfo[@"customer_city"] = contactInfo[@"customer_city"];
-    //            customerInfo[@"customer_contact"] = contactInfo[@"customer_contact"];
-    //            customerInfo[@"customer_contact_notes"] = contactInfo[@"customer_contact_notes"];
-    //            customerInfo[@"customer_country"] = contactInfo[@"customer_country"];
-    //            customerInfo[@"customer_email"] = contactInfo[@"customer_email"];
-    //            customerInfo[@"customer_fax"] = contactInfo[@"customer_fax"];
-    //            customerInfo[@"customer_first_name"] = contactInfo[@"customer_first_name"];
-    //            customerInfo[@"customer_last_name"] = contactInfo[@"customer_last_name"];
-    //            customerInfo[@"customer_name"] = contactInfo[@"customer_name"];
-    //            customerInfo[@"customer_phone"] = contactInfo[@"customer_phone"];
-    //            customerInfo[@"customer_price_type"] = contactInfo[@"customer_price_type"];
-    //            customerInfo[@"customer_sales_rep"] = contactInfo[@"customer_sales_rep"];
-    //            customerInfo[@"customer_state"] = contactInfo[@"customer_state"];
-    //            customerInfo[@"customer_zipcode"] = contactInfo[@"customer_zipcode"];
-    
     ret[@"customerInfo"] = contactInfo;
     
+    // models
+    if (nssoid) {
+        
+        __block double TotalCuft = 0;
+        __block double TotalWeight = 0;
+        __block int TotalCarton = 0;
+
+        __block double allItemPrice = 0;
+        
+         NSString *modelSql = [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",nssoid];
+        sqlite3 *db1 = [iSalesDB get_db];
+        [iSalesDB jk_query:modelSql db:db1 close:YES completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
+            
+            NSMutableDictionary* itemjson = [[NSMutableDictionary alloc] init];
+            
+            
+            
+            
+            int product_id = sqlite3_column_int(stmt, 0);
+            
+            char *str_price = (char*)sqlite3_column_text(stmt, 1);
+            
+            int item_id = sqlite3_column_int(stmt, 7);
+            
+            NSString* Price=nil;
+            if(str_price==nil)
+            {
+                NSNumber* price = [self get_model_default_price:appDelegate.contact_id product_id:nil item_id:@(item_id) db:db1];
+                if(price==nil)
+                    Price=@"No Price.";
+                else
+                    Price=[NSString stringWithFormat:@"%.2f",price.floatValue];
+            }
+            else
+            {
+                
+                Price=[NSString stringWithFormat:@"%.2f",[[[NSString alloc]initWithUTF8String:str_price] floatValue]];
+            }
+            
+            
+            int discount = sqlite3_column_int(stmt, 2);
+            int item_count = sqlite3_column_int(stmt, 3);
+            
+            char *line_note = (char*)sqlite3_column_text(stmt, 4);
+            NSString *nsline_note=nil;
+            if(line_note!=nil)
+                nsline_note= [[NSString alloc]initWithUTF8String:line_note];
+            
+            
+            char *name = (char*)sqlite3_column_text(stmt, 5);
+            NSString *nsname=nil;
+            if(name!=nil)
+                nsname= [[NSString alloc]initWithUTF8String:name];
+            
+            char *description = (char*)sqlite3_column_text(stmt, 6);
+            NSString *nsdescription=nil;
+            if(description!=nil)
+                nsdescription= [[NSString alloc]initWithUTF8String:description];
+            
+            
+            
+//            int stockUom = sqlite3_column_int(stmt, 8);
+//            int _id = sqlite3_column_int(stmt, 9);
+            
+            
+            NSDictionary* bsubtotaljson=[self model_subtotal:item_id count:item_count db:db1 compute_part:true];
+            double cuft=[bsubtotaljson[@"cuft"] doubleValue];
+            double weight=[bsubtotaljson[@"weight"] doubleValue];
+            int carton=[bsubtotaljson[@"carton"] intValue];
+            
+            TotalCuft += cuft;
+            TotalWeight += weight;
+            TotalCarton += carton;
+            
+            itemjson[@"combine"]=[self model_bundle:item_id db:db1 compute_part:false];
+            
+            itemjson[@"img"]= [self model_category_img:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:item_id]] model_name:nil db:db1];
+            
+            itemjson[@"Item Number"]=[NSString stringWithFormat:@"%@\n%@",nsname,nsdescription ];
+            itemjson[@"note"]=nsline_note;
+            itemjson[@"The unit price"]=Price;
+            
+            itemjson[@"order_item_status"] = @""; // 暂时不处理
+            itemjson[@"product_id"] = [NSString stringWithFormat:@"%d",product_id];
+            itemjson[@"QTY"] = [NSString stringWithFormat:@"%d",item_count];
+            
+            double subTotal = item_count * [Price doubleValue] * (1.0 - discount / 100.0);
+            if(itemjson[@"combine"] != nil)
+            {
+                //  int citem=0;
+                
+                int bcount=[[itemjson[@"combine"] valueForKey:@"count"] intValue];
+                for(int bc=0;bc<bcount;bc++)
+                {
+                    NSDictionary * bitem = [itemjson[@"combine"] objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
+                    int modulus= [[bitem valueForKey:@"modulus"] intValue];
+                    double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
+                    subTotal += uprice * modulus * item_count;
+                }
+            }
+
+            
+            itemjson[@"Subtotal"] = [NSString stringWithFormat:@"%.2f",item_count * [Price doubleValue]];
+           
+            
+            ret[[NSString stringWithFormat:@"item_%ld",(*count)++]]=itemjson;
+            ret[@"model_count"] = [NSNumber numberWithInteger:*count];
+            
+            allItemPrice += subTotal;
+            
+        }];
+        
+        orderinfo = [self replaceHtml:orderinfo String:@"TotalCuft_or_nbsp" withString:[NSString stringWithFormat:@"%.2f ft³",TotalCuft]];
+        orderinfo = [self replaceHtml:orderinfo String:@"TotalWeight_or_nbsp" withString:[NSString stringWithFormat:@"%.2f lbs",TotalWeight]];
+        orderinfo = [self replaceHtml:orderinfo String:@"TotalCarton_or_nbsp" withString:[NSString stringWithFormat:@"%d",TotalCarton]];
+        
+        // payments/Credits
+//        payments_and_credist = sqlite3_column_double(statement, 34);
+        payments_and_credist = allItemPrice;
+        ret[@"Payments/Credits"] = [NSString stringWithFormat:@"$%.2f",payments_and_credist];
+        
+//        // total
+//        totalPrice = sqlite3_column_double(statement, 35);
+//        ret[@"Total"] = [NSString stringWithFormat:@"$%.2f",totalPrice];
+
+        
+        
+    } else {
+        orderinfo = [self replaceHtml:orderinfo String:@"TotalCuft_or_nbsp" withString:@""];
+        orderinfo = [self replaceHtml:orderinfo String:@"TotalWeight_or_nbsp" withString:@""];
+        orderinfo = [self replaceHtml:orderinfo String:@"TotalCarton_or_nbsp" withString:@""];
+        
+        // payments/Credits
+        payments_and_credist = 0;
+        ret[@"Payments/Credits"] = [NSString stringWithFormat:@"$%.2f",payments_and_credist];
+
+
+    }
+    // total
+    totalPrice = payments_and_credist + lift_gate + handlingFee + shippingFee;
+    ret[@"Total"] = [NSString stringWithFormat:@"$%.2f",totalPrice];
+    
+    ret[@"order_info"]= orderinfo;
+    ret[@"more_order_info"] = moreInfo;
+    
     
     return [RAUtils dict2data:ret];