// // CreateOrderViewController.m // RedAnt ERP Mobile // // Created by Ray on 8/24/15. // Copyright (c) 2015 United Software Applications, Inc. All rights reserved. // #import "CreateOrderViewController.h" #import "RANetwork.h" #import "MainViewController.h" #import "RASingleton.h" #import "config.h" //#import "CustomIOSAlertView.h" #import "AddressEditorViewController.h" #import "CreditCardEditorViewController.h" #import "JKTimerManager.h" #import "ZipArchive.h" #ifdef SCANNER_ORDER #import "StockViewController.h" #endif #define SUBMIT_CONFIRM 123 #define KEEP_TAIL 456 #define CLOSE_ACTION 567 @interface CreateOrderViewController () // static const char associatedkey; @property (nonatomic,assign) BOOL isResume;///<恢复 @property (nonatomic,assign) NSInteger userType;///<恢复使用 @end @implementation CreateOrderViewController - (void)onScanSwitchUserTypeClick:(id)sender { #ifdef SCANNER_ORDER AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; NSString *orderdir =[OLDataProvider getScanPath]; UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Select Customer type" message:@"" preferredStyle:UIAlertControllerStyleAlert]; //block代码块取代了delegate UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Existing Customer" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { NSMutableDictionary* dict = nil; NSString* ordertemplate = nil; if([RADataProvider getSiteHasERP]) ordertemplate =@"e_order.json"; else ordertemplate =@"e_order_noerp.json"; dict=[OLDataProvider loadScanTemplate:ordertemplate]; NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"]; [RAUtils dicttofile:orderPath dict:dict]; NSString *orderdir = [OLDataProvider getScanPath]; // NSMutableDictionary* dict= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"order.json"]] mutableCopy]; int section_count = [dict[@"section_count"] intValue]; for(int i=0;i discardDirty:<#(bool)#> // // NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"]; // // // // [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo]; // // [self scanPlaceOrder]; // }]; UIAlertAction *alert2 = [UIAlertAction actionWithTitle:@"New customer" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { NSMutableDictionary* dict = nil; dict=[OLDataProvider loadScanTemplate:@"n_order.json"]; NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"]; [RAUtils dicttofile:orderPath dict:dict]; NSString *orderdir = [OLDataProvider getScanPath]; // NSMutableDictionary* dict= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"order.json"]] mutableCopy]; int section_count = [dict[@"section_count"] intValue]; for(int i=0;i"];//判断字符串是否包含 // // //if (range.location ==NSNotFound)//不包含 // if (range.length >0)//包含 // { // // // // } // else//不包含 // { // // } // UIAlertView * alert = nil; UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Close" message:@"Choose your action" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *action_0 = [UIAlertAction actionWithTitle:@"Switch to cart" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { [((MainViewController*)appDelegate.main_vc) switchToCart]; [self.navigationController popViewControllerAnimated:true]; }]; UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Switch to order history" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { [self.navigationController popViewControllerAnimated:false]; AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; [((MainViewController*)appDelegate.main_vc) switchToOrder]; }]; NSString * a2Title=nil; if(appDelegate.order_status==0) a2Title=@"Close and cancel order"; else a2Title=@"Close and release order"; UIAlertAction *action_2 = [UIAlertAction actionWithTitle:a2Title style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order" completion:^{ PopWaitAlert* pop = [RAUtils waiting_pop:@"Release Order" completion:nil]; // //#ifdef SCANNER_ORDER //// if(RASingleton.sharedInstance.enable_OfflineOrder) // { // [pop hide]; //// [waitalert dismissViewControllerAnimated:YES completion:^{ // [OLDataProvider deleteScanOrder:appDelegate.order_code]; // [appDelegate closeOrder]; // // // // // // // [self prepareReturn:nil]; // // // // [self.navigationController popViewControllerAnimated:true]; // [((MainViewController*)appDelegate.main_vc) switchToOrder]; //// }]; // // return; // } //#endif [RANetwork request_release_order:appDelegate.order_code withScreen:nil completionHandler:^(NSMutableDictionary *result) { NSDictionary* order_json = result; // [waitalert dismissViewControllerAnimated:YES completion:^{ [pop hide]; if([[order_json valueForKey:@"result"] intValue]==2) { AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; // appDelegate.order_code = nil; [appDelegate closeOrder]; #ifdef RA_NOTIFICATION [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA]; #else [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false]; [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false]; #endif [((MainViewController*)appDelegate.main_vc) switchToHome]; if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout) { [((MainViewController*)appDelegate.main_vc) Loginout:false]; } [self prepareReturn:nil]; [self.navigationController popViewControllerAnimated:true]; // [self.navigationController dismissViewControllerAnimated:true completion:^{ // ; // }]; } else { [RAUtils message_box:@"Open Order" message:[order_json valueForKey:@"err_msg"] completion:nil] ; } // }]; }]; // }]; }]; UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [alertController addAction:action_0]; [alertController addAction:action_1]; [alertController addAction:action_2]; [alertController addAction:action_3]; [self presentViewController:alertController animated:YES completion:nil]; #endif } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #ifdef SCANNER_ORDER -(void) scanSave:(NSMutableDictionary*) upparams { AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; NSString *orderdir = [OLDataProvider getScanPath]; // NSString* userdir = [OLDataProvider getUserPath]; NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"]; [RAUtils dicttofile:orderPath dict:self.content_data_download]; int section_count = [self.content_data_download[@"section_count"] intValue]; for(int i=0;i1) // { // int dbg=1; // } continue; } else { newlist[[NSString stringWithFormat:@"item_%d",newcount]] = item; newcount++; } } newlist[@"count"] = @(newcount); [OLDataProvider saveScanOrderList:newlist]; // [RAUtils dicttofile:orderlistPath dict:newlist]; #ifdef RA_NOTIFICATION [ActiveViewController Notify:@"CartViewController,ScanOrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA]; #else AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false]; #endif } #endif -(void) newScanOrder { AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; if(appDelegate.order_code.length>0) { [OLDataProvider scanCloseOrder]; } // RASingleton.sharedInstance.enable_OfflineOrder = true; // __block MainViewController *brself= self; // NSString* order_code = RASingleton.sharedInstance.scan_temp_code; appDelegate.can_set_cart_price = true; appDelegate.can_see_price = true; RASingleton.sharedInstance.scan_cart = nil; RASingleton.sharedInstance.price_type = 1; { NSString *orderdir = [OLDataProvider getScanPath]; // [OLDataProvider moveScanTemp2Order]; NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"]; [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo]; } #ifdef RA_NOTIFICATION [ActiveViewController Notify:@"CartViewController,ScanOrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA]; #else MainViewController* main_vc=(MainViewController*)appDelegate.main_vc; [main_vc reloadCart:true immediately:false]; #endif MainViewController * mainvc = (MainViewController*)appDelegate.main_vc; [mainvc switchToCart]; } - (IBAction)onSaveClick:(id)sender { // id foo = nil; // [[NSMutableArray array] addObject:foo]; // add params check here. [self.lastedit endEditing:true]; [self.lasttextview endEditing:true]; NSMutableDictionary* upparams = [self check_cancommit:false]; // if(self.cancommit==false) // return; if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"]) upparams[@"shipping"] = nil; #ifdef SCANNER_ORDER // if(RASingleton.sharedInstance.enable_OfflineOrder) { // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); // NSString *documents = [paths objectAtIndex:0]; [self scanSave:upparams]; [RAUtils message_box:@"Message" message:@"Save Successfully" completion:^{ [self newScanOrder]; [self.navigationController popViewControllerAnimated:true]; }]; return; } #else // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving Order" completion:^{ PopWaitAlert* pop = [RAUtils waiting_pop:@"Saving Order" completion:nil]; [RANetwork request_save_order:upparams completionHandler:^(NSMutableDictionary *result) { NSDictionary* editor_json =result; // [waitalert dismissViewControllerAnimated:YES completion:^{ [pop hide]; if([[editor_json valueForKey:@"result"] intValue]==2) { AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table]; if(appDelegate.user_type ==USER_ROLE_EMPLOYEE) { appDelegate.customerInfo = customerInfo; appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"]; } NSString *msg = nil; if ([editor_json objectForKey:@"so#"]) { msg = [@"SO#:" stringByAppendingString:[editor_json objectForKey:@"so#"]]; } [RAUtils message_box:@"Order Saved" message:msg completion:nil]; if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.save_order_logout && appDelegate.user_type ==USER_ROLE_EMPLOYEE) { [((MainViewController*)appDelegate.main_vc) Loginout:false]; [self prepareReturn:nil]; [self.navigationController popViewControllerAnimated:true]; } else{ #ifdef RA_NOTIFICATION [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA]; #else AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false]; #endif } if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) { if (![RASingleton sharedInstance].currentOrderIsMerged) { [self releaseOrderAfterSave]; } } } else { [RAUtils message_box:@"Save Order" message:[editor_json valueForKey:@"err_msg"] completion:nil] ; } // }]; }]; // }]; #endif } - (void)textFieldDidEndEditing:(UITextField *)textField { [super textFieldDidEndEditing:textField]; UITableViewCell *cell = (UITableViewCell *) textField.superview.superview; NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell]; NSMutableDictionary* section_json=nil; // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row); NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy]; NSString* name = [item_json valueForKey:@"name"]; if([name isEqualToString:@"shipping"]|| [name isEqualToString:@"handling_fee_value"]||[name isEqualToString:@"lift_gate_value"]||[name isEqualToString:@"tax_percentage"]) { float shipping = [self getprice:@"shipping" section:indexPath.section]; float paymentsAndCredits = [self getprice:@"paymentsAndCredits" section:indexPath.section]; float handling_fee_value = [self getprice:@"handling_fee_value" section:indexPath.section]; float lift_gate =[self getprice:@"lift_gate_value" section:indexPath.section]; float tax = [self getprice:@"tax_percentage" section:indexPath.section]/100.0*paymentsAndCredits; float totalprice=shipping+paymentsAndCredits+handling_fee_value+lift_gate+tax; section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy]; int count=0; count=[[section_json valueForKey:@"count"] intValue]; int total_row_idx=-1; for(int i=0;i=0) { NSUInteger newIndex[] = {indexPath.section, total_row_idx}; NSIndexPath *newPath = [[NSIndexPath alloc] initWithIndexes:newIndex length:2]; // DebugLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize)); [self.editorTable reloadRowsAtIndexPaths:@[newPath]withRowAnimation:UITableViewRowAnimationMiddle]; // DebugLog(@"after refresh %@",NSStringFromCGSize(self.editorTable.contentSize)); // CGSize tablecontent =self.editorTable.contentSize; // tablecontent.height=tablecontent.height+self.keyboard_h; // self.editorTable.contentSize=tablecontent; // // // DebugLog(@"resize to %@",NSStringFromCGSize(self.editorTable.contentSize)); } // self.content_data = [editor_json mutableCopy]; // self.content_data = [self translate_json:editor_json]; // NSMutableDictionary* content_data1 = [self translate_json:self.content_data]; // [self.editorTable reloadData]; } // // [item_json setValue:@"true" forKey:@"dirty"]; // [item_json setValue:textField.text forKey:@"value"]; } -(float) getprice:(NSString*) name section :(long) index { NSMutableDictionary* section_json=nil; section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",index ]] mutableCopy]; int count=0; count=[[section_json valueForKey:@"count"] intValue]; for(int i=0;i0) [arraddr addObject:customer_address1]; if(customer_address2.length>0) [arraddr addObject:customer_address2]; if(customer_address3.length>0) [arraddr addObject:customer_address3]; if(customer_address4.length>0) [arraddr addObject:customer_address4]; NSString *addr_string = [arraddr componentsJoinedByString:@"\r\n"]; NSString* customer_city= [customerinfo valueForKey:@"customer_city"]; NSString* customer_country= [customerinfo valueForKey:@"customer_country"]; NSString* customer_zipcode= [customerinfo valueForKey:@"customer_zipcode"]; NSString* customer_state= [customerinfo valueForKey:@"customer_state"]; NSMutableArray* arrcty = [[NSMutableArray alloc] init]; if(customer_city.length>0) [arrcty addObject:customer_city]; if(customer_state.length>0) [arrcty addObject:customer_state]; if(customer_zipcode.length>0) [arrcty addObject:customer_zipcode]; if(customer_country.length>0) [arrcty addObject:customer_country]; NSString *cty_string = [arrcty componentsJoinedByString:@", "]; // NSString* customer_phone= [customerinfo valueForKey:@"customer_phone"]; // NSString* customer_fax= [customerinfo valueForKey:@"customer_fax"]; // // NSMutableArray* arrpho = [[NSMutableArray alloc] init]; // if(customer_phone.length>0) // { // customer_phone = [NSString stringWithFormat:@"TEL: %@",customer_phone]; // [arrpho addObject:customer_phone]; // } // if(customer_fax.length>0) // { // customer_fax = [NSString stringWithFormat:@"FAX: %@",customer_fax]; // [arrpho addObject:customer_fax]; // } // NSString *phone_string = [arrpho componentsJoinedByString:@", "]; // // // NSString* customer_contact= [customerinfo valueForKey:@"customer_contact"]; // if(customer_contact.length>0) // { // customer_contact = [NSString stringWithFormat:@"ATTN: %@",customer_contact]; // // } // NSString *contact_string = customer_contact; // // // NSString* customer_email= [customerinfo valueForKey:@"customer_email"]; // if(customer_email.length>0) // { // customer_email = [NSString stringWithFormat:@"Email: %@",customer_email]; // // } // NSString *email_string = customer_email; NSMutableArray* arrext = [[NSMutableArray alloc] init]; if(addr_string.length>0) [arrext addObject:addr_string]; if(cty_string.length>0) [arrext addObject:cty_string]; // if(phone_string.length>0) // [arrext addObject:phone_string]; // if(contact_string.length>0) // [arrext addObject:contact_string]; // if(email_string.length>0) // [arrext addObject:email_string]; ret = [arrext componentsJoinedByString:@"\r\n"]; // NSString *string = [array componentsJoinedByString:@" "]; // NSString* customer_name= [customerinfo valueForKey:@"customer_name"]; return ret; } -(NSMutableDictionary*)create_value_map:(NSDictionary*)key_map { NSMutableDictionary* ret= [[NSMutableDictionary alloc] init]; NSArray *keys= [key_map allKeys]; //遍历keys for(int i=0;i<[keys count];i++) { //得到当前key NSString *key=[keys objectAtIndex:i]; //如果key不是pic,说明value是字符类型,比如name:Boris NSString* valuefrom = [key_map valueForKey:key]; if(valuefrom.length==0) continue; NSString* value=[self getValue:valuefrom]; [ret setValue:value forKey:valuefrom]; } NSDictionary * customerinfo =[self create_cusromer_info_from_table]; [ret setValue:[self create_customer_ext:customerinfo] forKey:@"customer_contact_ext"]; [ret setValue:customerinfo[@"customer_first_name"] forKey:@"customer_first_name"]; [ret setValue:customerinfo[@"customer_last_name"] forKey:@"customer_last_name"]; return ret; } -(NSMutableDictionary*)create_cusromer_info_from_table { AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; NSMutableDictionary* ret= [appDelegate.customerInfo mutableCopy] ; [ret setValue:[self getValue:@"customer_country"] forKey:@"customer_country"]; [ret setValue:[self getValue:@"customer_phone"] forKey:@"customer_phone"]; [ret setValue:[self getValue:@"customer_email"] forKey:@"customer_email"]; [ret setValue:[self getValue:@"customer_name"] forKey:@"customer_name"]; [ret setValue:[self getValue:@"customer_address4"] forKey:@"customer_address4"]; [ret setValue:[self getValue:@"customer_address3"] forKey:@"customer_address3"]; [ret setValue:[self getValue:@"customer_address2"] forKey:@"customer_address2"]; [ret setValue:[self getValue:@"customer_address1"] forKey:@"customer_address1"]; [ret setValue:[self getValue:@"customer_zipcode"] forKey:@"customer_zipcode"]; [ret setValue:[self getValue:@"customer_city"] forKey:@"customer_city"]; [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"]; [ret setValue:[self getValue:@"customer_cid"] forKey:@"customer_cid"]; [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"]; [ret setValue:[self getValue:@"customer_contact"] forKey:@"customer_contact"]; [ret setValue:[self getValue:@"customer_fax"] forKey:@"customer_fax"]; NSString * firstname =nil; NSString* lastname = nil; NSString* contact_name = [self getValue:@"customer_contact"]; if(contact_name!=nil) { NSArray *_arr = [contact_name componentsSeparatedByString:NSLocalizedString(@" ", nil)]; if(_arr.count>=1) { firstname =_arr[0]; if(_arr.count>1) { lastname=[[_arr subarrayWithRange:NSMakeRange(1, _arr.count-1)] componentsJoinedByString:@" "]; } } } [ret setValue:firstname forKey:@"customer_first_name"]; [ret setValue:lastname forKey:@"customer_last_name"]; // [ret setValue:[self create_customer_ext:ret] forKey:@"customer_contact_ext"]; return ret; } #pragma mark - multi_action sub action clicked - (void)MActionClicked:(UIButton *)sender { UITableViewCell *cell = (UITableViewCell *) sender.superview.superview; NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell]; int refresh =0; NSMutableDictionary* section_json=nil; NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy]; NSString* subid=[item_json valueForKey:@"subid"]; NSString* refresh_trigger = [item_json valueForKey:@"name"]; NSDictionary* sub_action = [item_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)sender.tag]]; NSString* type = [sub_action valueForKey:@"type"]; bool discardDirty = [[sub_action valueForKey:@"discard_dirty"] boolValue]; if([type isEqualToString:@"pull"]) { [self.lastedit endEditing:true]; refresh = [[sub_action valueForKey:@"refresh"] intValue]; NSDictionary* keymap= [sub_action objectForKey:@"key_map"]; NSMutableDictionary* value=[self create_value_map:keymap]; if(subid==nil) { NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"]; section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy]; int icount=[[section_json valueForKey:@"count"] intValue]; for (int ic=0;ic0) [modify_item setValue:valuestr forKey:@"value"]; else [modify_item setValue:@"" forKey:@"value"]; [modify_item setValue:@"true" forKey:@"dirty"]; [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]]; } } } else { NSArray* idarr=[subid componentsSeparatedByString:@"_"]; int section = [(NSString*)idarr[0] intValue]; int item=[(NSString*)idarr[1] intValue]; NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"]; section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy]; NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy]; NSString* control_type = [olditem valueForKey:@"control"]; if([control_type isEqualToString:@"switch"]) olditem= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ]; else if([control_type isEqualToString:@"enum"]) { olditem= [self fill_enum_subitem:olditem subid:nil source:value mapping:jsonmap ]; } else { [RAUtils message_box:@"Sorry" message:@"not impl" completion:nil]; } [olditem setValue:@"true" forKey:@"dirty"]; [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]]; } [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]]; self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data]; if(refresh==1) { // if(restore_json!=nil) // { // int rc=[[restore_json valueForKey:@"count"] intValue]; // for(int ir=0;ir */ } else if([[itemjson valueForKey:@"control"] isEqualToString:@"action"]) { return nil; } else if([[itemjson valueForKey:@"control"] isEqualToString:@"signature"]) { NSString* valuestr = [itemjson valueForKey:@"value"]; if(valuestr.length==0) valuestr=@""; [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]]; return upparams; } else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"]) { NSString* valuestr = [itemjson valueForKey:@"value"]; [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]]; NSString* value = [itemjson valueForKey:@"value"]; // NSMutableDictionary* boolitem=nil; // NSMutableDictionary* subjson=nil; if([value isEqualToString:@"true"]) { // boolitem =[[itemjson objectForKey:@"true"] mutableCopy]; NSMutableDictionary* subitem = itemjson[@"sub_item"]; if(subitem!=nil) { int scount = [subitem[@"count"]intValue]; for(int si=0;si 0) { // // key // NSString *max_key = [itemjson objectForKey:@"max"]; // id max_obj = [self downloadValueForKey:max_key]; // if (max_obj) { // max_value = [max_obj floatValue]; // } // // } else { // // value // id max_obj = [itemjson objectForKey:@"max"]; // if (max_obj != nil) { // max_value = [max_obj floatValue]; // } // // } // // if (max_value < f_value) { // mfield =[NSString stringWithFormat:@"%ld. the value of %@ must be not larger than %.2f",fields.count+1,itemjson[@"aname"],max_value]; // } // } // // if (check_min) { // // if (min_type > 0) { // // key // NSString *min_key = [itemjson objectForKey:@"min"]; // id min_obj = [self downloadValueForKey:min_key]; // if (min_obj) { // min_value = [min_obj floatValue]; // } // } else { // // value // id min_obj = [itemjson objectForKey:@"min"]; // if (min_obj != nil) { // min_value = [min_obj floatValue]; // } // } // // if (min_value > f_value) { // mfield =[NSString stringWithFormat:@"%ld. the value of %@ must be not smaller than %.2f",fields.count+1,itemjson[@"aname"],min_value]; // } // } // // // if (check_min && check_max) { // if (f_value < min_value || f_value > max_value) { // mfield =[NSString stringWithFormat:@"%ld. the value of %@ must between %.2f and %.2f",fields.count+1,itemjson[@"aname"],min_value,max_value]; // } // } // // // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]]; // // // } else { // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]]; // } // // } return upparams; } else { NSString* value = [itemjson valueForKey:@"value"]; if(value.length==0) value=@""; [upparams setValue:value forKey:[itemjson valueForKey:@"name"]]; return upparams; } return upparams; } -(NSMutableDictionary*) convertScanOrder :(NSMutableDictionary*) dict { [[RAUtils keyWindow] endEditing:YES]; // [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder)]; [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil]; // self.first_miss_pos = nil; NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init]; // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"]; int section_count=(int)self.content_data_control.count;//[[self.content_data_download valueForKey:@"section_count"] intValue]; // NSString* aaa = [RAUtils dict2string:self.content_data_control]; for(int i=0;i0&&[fileManager fileExistsAtPath:[img_cache stringByAppendingPathComponent:img_url_0]]) { NSError* err; [fileManager copyItemAtURL:[NSURL fileURLWithPath:[img_cache stringByAppendingPathComponent:img_url_0]] toURL:[NSURL fileURLWithPath:[orderdir stringByAppendingPathComponent:img_url_0]] error:&err]; } if(img_url_1.length>0&&[fileManager fileExistsAtPath:[img_cache stringByAppendingPathComponent:img_url_1]]) { NSError* err; [fileManager copyItemAtURL:[NSURL fileURLWithPath:[img_cache stringByAppendingPathComponent:img_url_1]] toURL:[NSURL fileURLWithPath:[orderdir stringByAppendingPathComponent:img_url_1]] error:&err]; } if(img_url_2.length>0&&[fileManager fileExistsAtPath:[img_cache stringByAppendingPathComponent:img_url_2]]) { NSError* err; [fileManager copyItemAtURL:[NSURL fileURLWithPath:[img_cache stringByAppendingPathComponent:img_url_2]] toURL:[NSURL fileURLWithPath:[orderdir stringByAppendingPathComponent:img_url_2]] error:&err]; } } else if([item[@"control"] isEqualToString:@"signature"]) { // 复制图片到打包目录 NSString* img_url_0=item[@"value"]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); NSString *cachefolder = [paths objectAtIndex:0]; // NSString *offline_createimg = [cachefolder stringByAppendingPathComponent:@"offline_createimg"]; NSString *img_cache = [cachefolder stringByAppendingPathComponent:@"img_cache"]; NSFileManager* fileManager=[NSFileManager defaultManager]; if(img_url_0.length>0&&[fileManager fileExistsAtPath:[img_cache stringByAppendingPathComponent:img_url_0]]) { NSError* err; [fileManager copyItemAtURL:[NSURL fileURLWithPath:[img_cache stringByAppendingPathComponent:img_url_0]] toURL:[NSURL fileURLWithPath:[orderdir stringByAppendingPathComponent:img_url_0]] error:&err]; } } } } NSString * parampath= [orderdir stringByAppendingPathComponent:@"param.json"]; NSDictionary* param=[self convertScanOrder:self.content_data_download]; [RAUtils dicttofile:parampath dict:param]; NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"]; if(appDelegate.customerInfo==nil) appDelegate.customerInfo = [NSMutableDictionary new]; [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo]; NSString *cartpath = [orderdir stringByAppendingPathComponent:@"cart.json"]; RASingleton.sharedInstance.scan_cart[@"price_type"] = @(RASingleton.sharedInstance.price_type); NSMutableDictionary* savecart = [[NSMutableDictionary dictionaryWithDictionary:RASingleton.sharedInstance.scan_cart] mutableCopy]; if(newmodel) savecart[@"section_0"]=newmodel; // NSMutableDictionary* cart_section = [savecart[@"section_0"] mutableCopy]; for(int ci=0;ci<[cart_section[@"count"] intValue];ci++ ) { NSMutableDictionary* item = [cart_section[[NSString stringWithFormat:@"item_%d",ci]] mutableCopy]; if(RASingleton.sharedInstance.price_type==0) { item[@"pg_price_type"] =price_group[@"price_0"]; } else if([item[@"net_price"] boolValue]) { item[@"pg_price_type"] =price_group[@"price_3"]; } else if([item[@"special_price"] boolValue]) { item[@"pg_price_type"] =price_group[@"price_2"]; } else { item[@"pg_price_type"] =price_group[@"price_1"]; } cart_section[[NSString stringWithFormat:@"item_%d",ci]] = item; } savecart[@"section_0"]=cart_section; [RAUtils dicttofile:cartpath dict:savecart]; NSString * zippath= [orderdir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.zip",appDelegate.order_code]]; // NSError *error=nil; // // [str writeToFile:jsonpath atomically:true encoding:NSUTF8StringEncoding error:&error]; NSArray* arr_files=[RAUtils allFilesAtPath:orderdir]; ZipArchive* zip = [[ZipArchive alloc] init]; // if ([[NSFileManager defaultManager] fileExistsAtPath:zippath]) { // // // [[NSFileManager defaultManager] removeItemAtPath:zippath error:nil]; // // // } BOOL r = [zip CreateZipFile2:zippath Password:@"usai2010"]; for(int i=0;i0) { realuser = self.realuser; realpassword = self.realpassword; } else { realuser = appDelegate.user; realpassword = appDelegate.password; } NSDictionary* params = @{ // @"site_name":[RADataProvider getSiteName], @"user":realuser, @"_method":@"uploadOfflineOrder", @"password" : realpassword, @"md5":md5 }; // self.btnSubmitOrder.enabled = false; // NSLog(@"disable submit button"); // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission" completion:^{ PopWaitAlert* pop = [RAUtils waiting_pop:@"Order Submission" completion:nil]; [RANetwork request_fastupload:[params mutableCopy] filename:fileName data:file_data url:appDelegate.uploadurl completionHandler:^(NSMutableDictionary *result) { // [waitalert dismissViewControllerAnimated:false completion:^{ [pop hide]; int iresult = [result[@"result"] intValue]; if(iresult == RESULT_TRUE) { NSString* soid = result[@"so_id"]; if(soid.length==0) soid=@"N/A"; // upparams[@"soid"]=soid; // NSMutableDictionary* saveorder = [[NSMutableDictionary dictionaryWithDictionary:self.content_data_download] mutableCopy]; if(newmodel) { self.content_data_download[@"section_0"]=newmodel; } self.content_data_download[@"readonly"]=@1; [self scanSave:upparams]; NSString* company = upparams[@"customer_cid"]; if(company.length==0) company = upparams[@"customer_name"]; [OLDataProvider save2submitScanOrder:soid company:company]; // [OLDataProvider scanCloseOrder]; [appDelegate closeOrder]; RASingleton.sharedInstance.scan_cart = nil; #ifdef RA_NOTIFICATION [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA]; #else MainViewController* main_vc=(MainViewController*)appDelegate.main_vc; [main_vc reloadCart:true immediately:false]; #endif // [self prepareReturn:nil]; [self.navigationController popViewControllerAnimated:true]; [((MainViewController*)appDelegate.main_vc) switchToOrder]; // NSMutableDictionary* ret = [[NSMutableDictionary alloc] init]; // ret[@"result"]=@2; // ret[@"file"]=zippath; // result(ret); return; } else if(iresult==1) { self.fail_submit = true; self.realuser = nil; self.realpassword = nil; [RAUtils message_box:@"Submit Order" message:@"Can not submit the order, wrong password" completion:nil]; if ([[NSFileManager defaultManager] fileExistsAtPath:zippath]) { [[NSFileManager defaultManager] removeItemAtPath:zippath error:nil]; // [orderlist addObject:appDelegate.order_code]; // [RAUtils dicttofile:orderlistPath dict:orderlist]; } } else if([result[@"result"] intValue]==-4||[result[@"result"] intValue]==-3) { self.fail_submit = true; self.realuser = nil; self.realpassword = nil; [RAUtils message_box:@"Submit Order" message:@"Order submission failed. Please check your internet and try later." completion:nil]; // if ([[NSFileManager defaultManager] fileExistsAtPath:zippath]) { // // // [[NSFileManager defaultManager] removeItemAtPath:zippath error:nil]; // // // [orderlist addObject:appDelegate.order_code]; // // [RAUtils dicttofile:orderlistPath dict:orderlist]; // // } return; } else if(iresult==9) { self.fail_submit = true; self.realuser = nil; self.realpassword = nil; [RAUtils message_box:@"Submit Order" message:result[@"err_msg"] completion:nil]; } else { self.fail_submit = true; self.realuser = nil; self.realpassword = nil; [RAUtils message_box:@"Submit Order" message:@"Can not submit order, please contact administrator." completion:nil]; } // }]; // self.btnSubmitOrder.enabled = true; // NSLog(@"enable submit button"); }]; // }]; } return; } #endif - (void)empolyee_commit_order:(NSMutableDictionary *)upparams { #ifdef SCANNER_ORDER AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; NSString* realuser; NSString* realpassword; if(self.realuser.length>0) { realuser = self.realuser; realpassword = self.realpassword; } else { realuser = appDelegate.user; realpassword = appDelegate.password; } if((appDelegate.user_type==USER_ROLE_CUSTOMER && [upparams[@"customer_cid"] stringValue].length>0) || [upparams[@"customer_cid"] stringValue].length>0 ||[appDelegate.user.uppercaseString isEqualToString:@"GUEST"]) { NSMutableDictionary* param = [NSMutableDictionary new]; NSString* model = [self scan_stock]; param[@"models"]=model; param[@"customer_cid"]=upparams[@"customer_cid"]; param[@"user"]=realuser; param[@"password"]=realpassword; [RADataProvider request_scan_stock:param completionHandler:^(NSMutableDictionary *result) { if([result[@"result"] intValue]==2) { NSMutableArray* models = [result[@"models"] mutableCopy]; if(models.count==0) { //不可拆分,直接提交 [self scan_commit:upparams newmodel:nil]; } else { StockViewController * vc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"StockViewController"]; // // NSMutableArray* testmodels =[[RAConvertor string2dict:@"[{\"model\":\"1420-1*\",\"count\":1,\"is_back_order\":true,\"etd\":\"2022-06-23\"},{\"model\":\"1420-1*\",\"count\":1,\"is_back_order\":false,\"etd\":\"2022-06-23\"}]"] mutableCopy]; // NSMutableArray* testmodels =[[RAConvertor string2dict:@"[{\"model\":\"1420-1*\",\"count\":1,\"is_back_order\":false,\"etd\":\"2022-06-23\"}]"] mutableCopy]; // models = testmodels; models = [self scan_split_models:models]; vc.data =models; vc.returnValue = ^(NSMutableDictionary * _Nonnull models) { // model // int i=0; // RASingleton.sharedInstance.scan_cart[@"section_0"]=models; // self.content_data_download[@"section_0"]=models; [self scan_commit:upparams newmodel:models]; return; }; UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ; // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi]; // navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种 [self presentViewController:navi animated:YES completion:^{ // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320); DebugLog(@"StockViewController present........."); // self.btop = false; // <#code#> }]; } } else if([result[@"result"] intValue]==1) { self.fail_submit = true; self.realuser = nil; self.realpassword = nil; [RAUtils message_box:@"Submit Order" message:@"Can not submit the order, wrong password" completion:nil]; // if ([[NSFileManager defaultManager] fileExistsAtPath:zippath]) { // // // [[NSFileManager defaultManager] removeItemAtPath:zippath error:nil]; // // // [orderlist addObject:appDelegate.order_code]; // // [RAUtils dicttofile:orderlistPath dict:orderlist]; // // } return; } else if([result[@"result"] intValue]==-4||[result[@"result"] intValue]==-3) { self.fail_submit = true; self.realuser = nil; self.realpassword = nil; [RAUtils message_box:@"Submit Order" message:@"Order submission failed. Please check your internet and try later." completion:nil]; // if ([[NSFileManager defaultManager] fileExistsAtPath:zippath]) { // // // [[NSFileManager defaultManager] removeItemAtPath:zippath error:nil]; // // // [orderlist addObject:appDelegate.order_code]; // // [RAUtils dicttofile:orderlistPath dict:orderlist]; // // } return; } else { self.fail_submit = true; self.realuser = nil; self.realpassword = nil; [RAUtils message_box:@"Submit Order" message:@"Can not submit order, please contact administrator." completion:nil]; } }]; } else { //无contact 直接提交 [self scan_commit:upparams newmodel:nil]; } return; #else [upparams setValue:@"false" forKey:@"isHold"]; // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission" completion:^{ PopWaitAlert* pop = [RAUtils waiting_pop:@"Order Submission" completion:nil]; [RANetwork request_commit_order:upparams completionHandler:^(NSMutableDictionary *result) { NSDictionary* editor_json = result; // [waitalert dismissViewControllerAnimated:YES completion:^{ [pop hide]; if([[editor_json valueForKey:@"result"] intValue]==2) { // debug aaa AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; NSString* company= appDelegate.customerInfo[@"customer_name"]; NSString* send_to =appDelegate.customerInfo[@"customer_email"]; [appDelegate closeOrder]; #ifdef RA_NOTIFICATION [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA]; #else [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false]; #endif __block NSString* title=nil; __block NSString* msg=nil; #ifdef OFFLINE_MODE if(appDelegate.offline_mode) { title=TITLE_OFFLINE_SUBMIT; msg=MSG_OFFLINE_SUBMIT; } else #endif { title=@"Order submitted sucessfully"; msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]]; } NSString* pdf_url = [editor_json valueForKey:@"pdf_url"]; NSString* email_content =[editor_json valueForKey:@"email_content"]; NSString* soid=[editor_json valueForKey:@"so#"]; NSMutableDictionary *value = [NSMutableDictionary dictionary]; if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout) { //bbb [((MainViewController*)appDelegate.main_vc) Loginout:false]; value[@"commitorder_logout"]=@"true"; } [self prepareReturn:value]; // __block UIViewController* message_parent = self.navigationController.topViewController; [self.navigationController popToRootViewControllerAnimated:true]; if(pdf_url.length>0) { [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content]; // [appDelegate printPdf:pdf_url]; // }]; } else dispatch_async(dispatch_get_main_queue(), ^{ [RAUtils message_box:title message:msg completion:nil]; }); } else { [RAUtils message_box:@"Order Submission" message:[editor_json valueForKey:@"err_msg"] completion:nil]; } // }]; }]; // }]; #endif } @end