// // ScanOrderListViewController.m // iSales-USAI // // Created by Rui Zhang on 2/8/22. // Copyright © 2022 United Software Applications, Inc. All rights reserved. // #import "ScanOrderListViewController.h" #import "OrderListTableViewCell.h" #import "RANetwork.h" #import "OrderDetailViewController.h" #import "MainViewController.h" #import "ContactListViewController.h" #import "DefaultAppearance.h" #import "DefaultTableHeaderView.h" #import "SelectUploadOrderViewController.h" #import "NotificationNameCenter.h" #import "RASingleton.h" #import "ERPUtils.h" #import "UploadCell.h" #import "CustomerEditViewController.h" #import "CreateOrderViewController.h" #import "MainViewController.h" @interface ScanOrderListViewController () @property (nonatomic,strong) NSOperationQueue *dataOperationQueue; @property (nonatomic,strong) NSMutableArray *mergeList; @property (nonatomic,assign) NSInteger orderType;/// 1) { // [self.orderTypeSegmentControl setTitle:[NSString stringWithFormat:@"Purchase Order to %@",COMPANY_SHORT_NAME] forSegmentAtIndex:1]; // } // // // 显示Sales Order与否 // if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) { // if ([RASingleton sharedInstance].global_lock || ![RASingleton sharedInstance].customer_can_see_sales_Order) { // 是否解锁,是否有查看Sales Order权限 // if (self.orderTypeSegmentControl.numberOfSegments > 1) { // [self.orderTypeSegmentControl removeSegmentAtIndex:1 animated:YES]; // [self changeOrderType:0]; // } // } else { // // if (self.orderTypeSegmentControl.numberOfSegments == 1 && !self.table_order.isEditing) { // [self.orderTypeSegmentControl insertSegmentWithTitle:[NSString stringWithFormat:@"Purchase Order to %@",COMPANY_SHORT_NAME] atIndex:1 animated:YES]; // } // // } // } } -(void) newoloorder { AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; appDelegate.can_set_cart_price = true; appDelegate.can_see_price = true; RASingleton.sharedInstance.scan_cart = nil; RASingleton.sharedInstance.price_type = 1; // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); // NSString *documents = [paths objectAtIndex:0]; { NSString *orderdir = [OLDataProvider getScanPath]; NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"]; [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo]; } #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 // MainViewController * mainvc=(MainViewController * )appDelegate.main_vc; // mainvc.btnScan.enabled = true; // [appDelegate updateScanButton:true]; // AppDelegate* appDelegate = (AppDelegate*)UIApplication.sharedApplication.delegate; MainViewController * mainvc = (MainViewController*)appDelegate.main_vc; // [ActiveViewController Notify:@"ScanOrderListViewController" Message:@"NewOrder"]; [mainvc switchToCart]; } - (IBAction)onNewOrderClicked:(id)sender { AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; if(appDelegate.order_code.length>0) { // // 当前订单先关闭 [OLDataProvider scanCloseOrder]; } { [self newoloorder]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)manually_refresh { UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201]; if(self.isrefreshing) { [reF endRefreshing]; return; } reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"]; if ([self respondsToSelector:@selector(ReloadData)]) [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1]; } -(void)ReloadData { // [self.content_data removeAllObjects]; // [self.table_order reloadData]; // self.table_order.hidden = true; UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201]; [reF endRefreshing]; reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"]; self.keywords=nil; // self.offset = 0; self.reset_result=true; // [self.content_data removeAllObjects]; // [self.table_order reloadData]; [self loadpage]; // [self loadpage]; } - (void)operation_loadPage { if (self.dataOperationQueue.operationCount > 1) { // 队列后面还有操作 return; } // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); // NSString *documents = [paths objectAtIndex:0]; NSString *userdir = [OLDataProvider getUserPath]; NSMutableDictionary* orderlist = [OLDataProvider getScanOrderList]; // NSString *orderlistPath = [userdir stringByAppendingPathComponent:@"orderlist.json"]; // orderlist=[[RAUtils dictfromfile:orderlistPath] mutableCopy]; [self.content_data removeAllObjects]; int count = [orderlist[@"count"] intValue]; for(int i=0;iself.content_data.count) // { // int debug=true; // } // DebugLog(@"row %ld",(long)indexPath.row); // if(indexPath.row==self.content_data.count) // { // UITableViewCell *moreCell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"mores"]; // UILabel *moreDataLabel=[[UILabel alloc] init]; // // moreDataLabel.tag=200; // moreDataLabel.text=self.load_more_hint; // [moreDataLabel setFont:[UIFont systemFontOfSize:14.0f]]; // [moreDataLabel setTextAlignment:NSTextAlignmentCenter]; // moreDataLabel.frame=CGRectMake(0, 10, self.table_order.bounds.size.width, 20); // [moreDataLabel setBackgroundColor:[UIColor clearColor]]; // moreDataLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; // // [moreDataLabel addTarget:self action:@selector(changeCell) forControlEvents:UIControlEventValueChanged]; // // [moreCell.contentView addSubview:moreDataLabel]; // if([self.load_more_hint isEqualToString:@"Load more..."]) // [self performSelector:@selector(loadmore) withObject:nil afterDelay:1]; // // DebugLog(@"更多..."); // moreCell.backgroundColor = [UIColor whiteColor]; // return moreCell; // } // else { NSString *CellIdentifier = @"OrderListTableViewCell"; OrderListTableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; NSString* so= [self.content_data[indexPath.row] valueForKey:@"so#"]; NSString* price= [self.content_data[indexPath.row] valueForKey:@"price"]; // if(appDelegate.can_see_price&&appDelegate.price_hidden==false) // { // // } // else // { // price=nil; // } // // NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue]; NSString* purchase_time= [self.content_data[indexPath.row] valueForKey:@"purchase_time"]; NSString* status = [self.content_data[indexPath.row] valueForKey:@"order_status"] ; // if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) { // status = [ERPUtils orderStatus:statusCode]; // } NSString* customer_name = [self.content_data[indexPath.row] valueForKey:@"customer_name"]; NSString* model_count = [self.content_data[indexPath.row] valueForKey:@"model_count"]; NSString* sales = [self.content_data[indexPath.row] valueForKey:@"sales_rep"]; NSString* creator = [self.content_data[indexPath.row] valueForKey:@"create_by"]; NSString *po = [self.content_data[indexPath.row] valueForKey:@"po_id"]; CGRect price_frame = cell.labelprice.frame; if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && self.orderType == 1) { cell.label_po.hidden = NO; price_frame.origin.y = 5; cell.label_po.text = po; } else { cell.label_po.hidden = YES; price_frame.origin.y = 21; } cell.labelprice.frame = price_frame; cell.label_so.text=so; cell.labelprice.text=price;//price; cell.label_date.text=purchase_time; cell.label_contact.text=customer_name; cell.label_model.hidden = false; cell.label_model.text = model_count; cell.label_sales.text = sales; cell.label_creator.text = creator; cell.label_status.text=status; cell.backgroundColor = [UIColor whiteColor]; return cell; } } else if(tableView==self.table_submit) { AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; { NSString *CellIdentifier = @"OrderListTableViewCell"; OrderListTableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; NSString* so= [self.submit_content_data[indexPath.row] valueForKey:@"so#"]; NSString* price= [self.submit_content_data[indexPath.row] valueForKey:@"price"]; // if(appDelegate.can_see_price&&appDelegate.price_hidden==false) // { // // } // else // { // price=nil; // } // // NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue]; NSString* purchase_time= [self.submit_content_data[indexPath.row] valueForKey:@"purchase_time"]; NSString* status = [self.submit_content_data[indexPath.row] valueForKey:@"order_status"] ; // if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) { // status = [ERPUtils orderStatus:statusCode]; // } NSString* customer_name = [self.submit_content_data[indexPath.row] valueForKey:@"customer_name"]; NSString* model_count = [self.submit_content_data[indexPath.row] valueForKey:@"model_count"]; NSString* sales = [self.submit_content_data[indexPath.row] valueForKey:@"sales_rep"]; NSString* creator = [self.submit_content_data[indexPath.row] valueForKey:@"create_by"]; NSString *po = [self.submit_content_data[indexPath.row] valueForKey:@"po_id"]; CGRect price_frame = cell.labelprice.frame; if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && self.orderType == 1) { cell.label_po.hidden = NO; price_frame.origin.y = 5; cell.label_po.text = po; } else { cell.label_po.hidden = YES; price_frame.origin.y = 21; } cell.labelprice.frame = price_frame; cell.label_so.text=so; cell.labelprice.text=price;//[RAConvertor currencyNumber:(price.floatValue)];//price; cell.label_date.text=purchase_time; cell.label_contact.text=customer_name; cell.label_model.hidden = false; cell.label_model.text = model_count; cell.label_sales.text = sales; cell.label_creator.text = creator; cell.label_status.text=status; cell.backgroundColor = [UIColor whiteColor]; return cell; } } else { AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate; { NSString *CellIdentifier = @"UploadCell"; UploadCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; NSDictionary * item_json = Appdelegate.uploadManager.arr_queue[indexPath.row]; // // if (cell.operation) { // cell.operation.updateUI = nil; // } RAUploadOperation* op = item_json[@"operation"]; NSString* status =nil; switch ([item_json[@"status"] intValue]) { case TaskStatusStart: status=@"uploading"; break; case TaskStatusStop: status=@"stop"; break; case TaskStatusError: status=@"warning"; break; case TaskStatusWait: status=@"waiting"; break; case TaskStatusFinish: status=@"finish"; break; default: status=@"warning"; break; } double progress =[item_json[@"progress"] doubleValue]; cell.progress=progress; cell.name=item_json[@"file"]; cell.state= status; cell.errorMsg = item_json[@"msg"]; // __block RAUploadOperation* block_op = op; // __block UploadCell* block_cell = cell; // __block NSIndexPath* block_index = indexPath; // long idx = indexPath.row; // __weak typeof(self) weakself = self; op.updateUI=^(){ // blockDebugLog(@"updateUI @ row%ld %p \n operation %p",idx,block_cell,block_op); NSString* status =nil; switch ([item_json[@"status"] intValue]) { case TaskStatusStart: status=@"uploading"; break; case TaskStatusStop: status=@"stop"; break; case TaskStatusError: status=@"warning"; break; case TaskStatusWait: status=@"waiting"; break; case TaskStatusFinish: status=@"finish"; break; default: status=@"warning"; break; } double progress =[item_json[@"progress"] doubleValue]; cell.progress=progress; cell.name=item_json[@"file"]; cell.state= status; cell.errorMsg = item_json[@"msg"]; }; DebugLog(@"%@ set update ui",item_json[@"file"]); // cell.operation = op; // return cell; } } } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if(tableView==self.table_order) { // RASingleton.sharedInstance.enable_OfflineOrder = true; if (tableView.isEditing) { // 编辑模式下不响应 return; } // if(indexPath.row==self.content_data.count) return; { AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; // NSString *orderdir = [OLDataProvider getScanPath]; NSString *userdir = [OLDataProvider getUserPath]; NSMutableDictionary* orderitem =self.content_data[indexPath.row]; NSString* ordercode =orderitem[@"order_code"]; NSString *orderdir = [userdir stringByAppendingPathComponent:ordercode]; // NSMutableDictionary* order= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"order.json"]] mutableCopy]; NSMutableDictionary* cart= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"cart.json"]] mutableCopy]; if([appDelegate.available_price_group containsObject:cart[@"price_group"]] && [RADataProvider all_price_group][cart[@"price_group"]]!=nil) { appDelegate.order_code = ordercode; [appDelegate setUser:orderitem[@"create_by"]]; // appDelegate.user =; // appDelegate.custo orderitem[@"customer_name"] // appDelegate.user_type = USER_ROLE_EMPLOYEE; appDelegate.can_set_cart_price = true; appDelegate.can_see_price = true; NSMutableDictionary * params= [[NSMutableDictionary alloc] init]; // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); // NSString *documents = [paths objectAtIndex:0]; NSMutableDictionary* contact= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"contact.json"]] mutableCopy]; // NSMutableDictionary* app= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"app.json"]] mutableCopy]; [appDelegate setCustomerInfo: contact]; appDelegate.contact_id = contact[@"customer_cid"]; RASingleton.sharedInstance.scan_cart = cart; appDelegate.price_group = cart[@"price_group"]; RASingleton.sharedInstance.price_type = [cart[@"price_type"] intValue]; [appDelegate update_count_mark]; // [appDelegate updateScanButton:true]; [appDelegate SetMode:@""]; #ifdef RA_NOTIFICATION [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA]; #else [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false]; #endif // [self.navigationController pushViewController:orderinfoVC animated:true]; [((MainViewController*)appDelegate.main_vc) switchToCart]; return; } else { //价格组不存在 询问刷新 NSString * title =@"Price Has Changed"; NSString* message = @"Shopping cart items will show updated prices. "; UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert]; //block代码块取代了delegate // [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) { // textField.text = self.save_name; // // // }]; UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Continue" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { NSMutableDictionary* orderitem =self.content_data[indexPath.row]; NSString* ordercode =orderitem[@"order_code"]; appDelegate.order_code = ordercode; [appDelegate setUser:orderitem[@"create_by"]]; // appDelegate.user =; // appDelegate.custo orderitem[@"customer_name"] // appDelegate.user_type = USER_ROLE_EMPLOYEE; appDelegate.can_set_cart_price = true; appDelegate.can_see_price = true; NSMutableDictionary * params= [[NSMutableDictionary alloc] init]; // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); // NSString *documents = [paths objectAtIndex:0]; NSMutableDictionary* contact= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"contact.json"]] mutableCopy]; // NSMutableDictionary* app= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"app.json"]] mutableCopy]; [appDelegate setCustomerInfo: contact]; appDelegate.contact_id = contact[@"customer_cid"]; //用默认价格组替换订单之前保存的价格组 [RADataProvider default_price_group]; cart[@"price_group"]=appDelegate.price_group; RASingleton.sharedInstance.scan_cart = cart; // appDelegate.price_group = cart[@"price_group"]; RASingleton.sharedInstance.price_type = [cart[@"price_type"] intValue]; [appDelegate update_count_mark]; // [appDelegate updateScanButton:true]; [appDelegate SetMode:@""]; #ifdef RA_NOTIFICATION [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_CART_REFRESH]; #else [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false]; #endif // [self.navigationController pushViewController:orderinfoVC animated:true]; [((MainViewController*)appDelegate.main_vc) switchToCart]; return; }]; UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Close" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { DebugLog(@"Cancel"); return; }]; [alertControl addAction:actionOne]; [alertControl addAction:alertthree]; //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField) [self presentViewController:alertControl animated:YES completion:nil]; } } } else if(tableView==self.table_submit) { // RASingleton.sharedInstance.enable_OfflineOrder = true; if (tableView.isEditing) { // 编辑模式下不响应 return; } // // if(indexPath.row==self.content_data.count) // return; { // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; NSMutableDictionary* orderitem =self.submit_content_data[indexPath.row]; NSString* ordercode =orderitem[@"order_code"]; NSString *orderdir = [OLDataProvider getScanOrderPathByCode:ordercode]; // orderdir = [orderdir stringByAppendingPathComponent:ordercode]; NSMutableDictionary * params= [[NSMutableDictionary alloc] init]; CreateOrderViewController * orderinfoVC = [[CreateOrderViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil]; orderinfoVC.disable_dropdown_refresh=true; orderinfoVC.url_type = URL_FILE; orderinfoVC.request_url=[orderdir stringByAppendingPathComponent:@"order.json"]; orderinfoVC.params = params; orderinfoVC.title=@""; orderinfoVC.delegate=nil; [self.navigationController pushViewController:orderinfoVC animated:true]; // if(checked.count==count) // { // orderinfoVC.have_tail = true // } // appDelegate.order_code = ordercode; // // [appDelegate setUser:orderitem[@"create_by"]]; // // appDelegate.can_set_cart_price = true; // appDelegate.can_see_price = true; // // // NSMutableDictionary * params= [[NSMutableDictionary alloc] init]; // // // // // NSString *orderdir = [OLDataProvider getScanPath]; // NSMutableDictionary* cart= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"cart.json"]] mutableCopy]; // NSMutableDictionary* contact= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"contact.json"]] mutableCopy]; // // [appDelegate setCustomerInfo: contact]; // appDelegate.contact_id = contact[@"customer_cid"]; // RASingleton.sharedInstance.scan_cart = cart; // RASingleton.sharedInstance.price_type = [cart[@"price_type"] intValue]; // // // [appDelegate update_count_mark]; // [appDelegate SetMode:@""]; // // // //#ifdef RA_NOTIFICATION // [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA]; //#else // // // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false]; //#endif // //// [self.navigationController pushViewController:orderinfoVC animated:true]; // // [((MainViewController*)appDelegate.main_vc) switchToCart]; // return; } } } #pragma mark - searchBar delegate; - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { self.keywords=searchBar.text; // self.offset = 0; // [self.content_data removeAllObjects]; self.reset_result=true; [self loadpage]; } - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { if([searchText isEqualToString:@""] && !self.reset) { DebugLog(@"clear"); self.reset=true; self.keywords=nil; // self.offset = 0; // [self.content_data removeAllObjects]; self.reset_result=true; [self loadpage]; } else self.reset = false; } #pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮 //- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath { // 添加一个删除按钮 // self.indexPath=indexPath; if(tableView==self.table_order) { if(indexPath.row==self.content_data.count) // return @[]; return [UISwipeActionsConfiguration configurationWithActions:@[]]; AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; // NSString* so= [self.content_data[indexPath.row] valueForKey:@"so#"]; NSString* order_code= [self.content_data[indexPath.row] valueForKey:@"order_code"]; // NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"]; // NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue]; if(true/*appDelegate.user_type==USER_ROLE_EMPLOYEE || (appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeCustomer)*/) { // UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { UIContextualAction* deleteRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"Delete" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) { DebugLog(@"delete click"); NSString * title =@"Are you sure to delete order?"; UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert]; //block代码块取代了delegate // [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) { // textField.text = self.save_name; // // // }]; UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { [OLDataProvider deleteScanOrder:order_code]; if([appDelegate.order_code isEqualToString:order_code]) [appDelegate closeOrder]; // // [self prepareReturn:nil]; // [self.navigationController popViewControllerAnimated:true]; // [((MainViewController*)appDelegate.main_vc) switchToOrder]; return; }]; UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { DebugLog(@"Cancel"); }]; [alertControl addAction:actionOne]; [alertControl addAction:alertthree]; //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField) [self presentViewController:alertControl animated:YES completion:nil]; }]; deleteRowAction.backgroundColor = UIColor.redColor;//UIColorFromRGB(0x336699); // 添加一个编辑按钮 // // if(/*[order_status isEqualToString:@"Saved Order"]*/statusCode == 1&&appDelegate.can_cancel_order) // return @[cancelAction]; // // else // { { NSMutableArray* arr=[@[] mutableCopy]; if(appDelegate.can_delete_order) [arr addObject:deleteRowAction]; // if(appDelegate.can_cancel_order) // [arr addObject:cancelAction]; // return arr; return [UISwipeActionsConfiguration configurationWithActions:arr]; } // } } // return @[]; return [UISwipeActionsConfiguration configurationWithActions:@[]]; } else if(tableView==self.table_submit) { AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; // NSString* so= [self.content_data[indexPath.row] valueForKey:@"so#"]; NSString* order_code= [self.submit_content_data[indexPath.row] valueForKey:@"order_code"]; // NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"]; // NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue]; { // UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { UIContextualAction* deleteRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"Delete" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) { DebugLog(@"delete click"); NSString * title =@"Are you sure to delete the submitted record?"; UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert]; //block代码块取代了delegate UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { [OLDataProvider deleteSubmittedOrder:order_code]; return; }]; UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { DebugLog(@"Cancel"); }]; [alertControl addAction:actionOne]; [alertControl addAction:alertthree]; //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField) [self presentViewController:alertControl animated:YES completion:nil]; }]; deleteRowAction.backgroundColor = UIColorFromRGB(0x336699); // 添加一个编辑按钮 { NSMutableArray* arr=[@[] mutableCopy]; if(appDelegate.can_delete_order) [arr addObject:deleteRowAction]; // if(appDelegate.can_cancel_order) // [arr addObject:cancelAction]; // return arr; return [UISwipeActionsConfiguration configurationWithActions:arr]; } // } } } else { AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate; NSMutableDictionary * task = Appdelegate.uploadManager.arr_queue[indexPath.row]; __weak typeof(self) weakself = self; // UITableViewRowAction *startAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Restart"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { UIContextualAction* startAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"Restart" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) { if (Appdelegate.uploadManager.onlyWiFi && Appdelegate.uploadManager.reach.currentReachabilityStatus != ReachableViaWiFi) { [weakself.view makeToast:@"Current Network is not WiFi" duration:3.0 position:CSToastPositionCenter]; [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle]; return ; } DebugLog(@"Start click"); task[@"retry"]=[NSNumber numberWithInt:0]; [Appdelegate.uploadManager startTask:task]; [tableView reloadData]; }]; startAction.backgroundColor = UIColorFromRGB(0xff9933); // UITableViewRowAction *removeAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Remove" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { UIContextualAction* removeAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"Remove" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) { [Appdelegate.uploadManager removeTask:task]; // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle]; }]; removeAction.backgroundColor = UIColorFromRGB(0x9BBF5A); // UIColorFromRGB(0x336699); // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; switch ([task[@"status"] intValue]) { case TaskStatusFinish: // return @[removeAction]; return [UISwipeActionsConfiguration configurationWithActions:@[removeAction]]; case TaskStatusError: // return @[startAction,removeAction]; return [UISwipeActionsConfiguration configurationWithActions:@[startAction,removeAction]]; case TaskStatusStop: // return @[startAction]; return [UISwipeActionsConfiguration configurationWithActions:@[startAction]]; default: return nil; break; } } } - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { if(tableView==self.table_order) { if(indexPath.row==self.content_data.count) return NO; // // if(self.init_style==OL_OPEN) // // return NO; // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; // // NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"]; // NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue]; // // if(appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) { // // saved && ((type==0 && merge_permission) || type == 1 || can_cancel) // // BOOL isSavedOrder = /*[order_status isEqualToString:@"Saved Order"]*/statusCode == 1; // switch (self.orderType) { // case 0:{ // Shop Order // // if (!isSavedOrder) { // return NO; // } else { // if ([RASingleton sharedInstance].permissions_merge_order || appDelegate.can_cancel_order) { // return YES; // } else { // return NO; // } // } // // } // break; // case 1:{ // Sales Order // if (isSavedOrder && appDelegate.can_cancel_order) { // return YES; // } // return NO; // } // break; // // default: // break; // } // // } else { // return YES; // } return YES; } else if(tableView==self.table_submit) { return YES; } else { AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate; if(Appdelegate.uploadManager.arr_queue.count==0) return false; NSDictionary * item_json = Appdelegate.uploadManager.arr_queue[indexPath.row]; bool ret=false; switch ([item_json[@"status"] intValue]) { case TaskStatusStart: case TaskStatusWait: ret=false; break; case TaskStatusFinish: case TaskStatusStop: case TaskStatusError: ret = true; break; default: ret=false; break; } return ret; } } - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { if(tv==self.table_order) { if(indexPath.row==self.content_data.count) return UITableViewCellEditingStyleNone; bool offline_edit =[[self.content_data[indexPath.row] valueForKey:@"offline_edit"] boolValue]; // NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"]; NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue]; if(/*![order_status isEqualToString:@"Saved Order"]&&! [order_status isEqualToString:@"Quote Saved"]*/statusCode != 1 && statusCode != 0) return UITableViewCellEditingStyleNone; else { BOOL condition = offline_edit; #ifdef OFFLINE_MODE AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; condition = condition || appDelegate.offline_mode==false; #else condition = YES; #endif if (condition) return UITableViewCellEditingStyleDelete; else return UITableViewCellEditingStyleNone; } } else return UITableViewCellEditingStyleDelete; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ #pragma mark EnumSelectViewControllerDelegate -(void) EnumValueChanged:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath { self.status_cadedate = value; UIApplication * app = [UIApplication sharedApplication]; AppDelegate *appDelegate = (AppDelegate *)[app delegate]; appDelegate.OrderFilter = value; // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); // NSString *documents = [paths objectAtIndex:0]; // NSString *dist_path = [documents stringByAppendingPathComponent:@"status_filter_cadedate.json"]; // // // // if ([[NSFileManager defaultManager] fileExistsAtPath:dist_path]) { // // // // DebugLog(@"文件已经存在了"); // // // // } // // else // // { // // // // // // // // DebugLog(@"resourceSampleImagesFolderPath=%@",resourceFolderPath); // //NSData *data = [NSJSONSerialization dataWithJSONObject:self.status_cadedate options:kNilOptions error:nil]; // // // DebugLog(@"mainBundleFile==%@",mainBundleFile); // // [[NSFileManager defaultManager] createFileAtPath:dist_path // // contents:data // // attributes:nil]; // // } // self.keywords=searchBar.text; // self.offset = 0; // [self.content_data removeAllObjects]; self.reset_result=true; [self loadpage]; //[self.btnStatusFilter setTitle:setTitle:alert ]; } #pragma mark - button action - (NSIndexPath *)indexPathOfDeleteOrder:(NSString *)orderID { for (NSIndexPath *indexPath in self.table_order.indexPathsForSelectedRows) { NSString* orderid= [NSString stringWithFormat:@"%@",[self.content_data[indexPath.row] valueForKey:@"order_id"]]; if ([orderid isEqualToString:orderID]) { return indexPath; } } return nil; } - (void)handleSelectedOrders { [self.mergeList removeAllObjects]; if (!self.table_order.isEditing) { return; } for (NSIndexPath *indexPath in self.table_order.indexPathsForSelectedRows) { if(indexPath.row==self.content_data.count) continue; NSString* so= [self.content_data[indexPath.row] valueForKey:@"so#"]; NSString* orderid= [self.content_data[indexPath.row] valueForKey:@"order_id"]; NSString *create_by = [self.content_data[indexPath.row] valueForKey:@"create_by"]; NSString *create_time = [self.content_data[indexPath.row] valueForKey:@"purchase_time"]; NSString *orderCode = [NSString stringWithFormat:@"%@",[self.content_data[indexPath.row] valueForKey:@"order_code"]]; NSMutableDictionary *dic = [NSMutableDictionary dictionary]; [dic setValue:orderid forKey:@"order_id"]; [dic setValue:orderCode forKey:@"order_code"]; [dic setValue:so forKey:@"so_id"]; [dic setValue:create_by forKey:@"create_by"]; [dic setValue:create_time forKey:@"create_time"]; [dic setValue:[NSNumber numberWithInteger:0] forKey:@"check"]; // 合并到 [self.mergeList addObject:dic]; } } - (IBAction)editOrderListButtonClick:(UIBarButtonItem *)sender { } - (IBAction)onSegmentChanged:(UISegmentedControl *)sender { if(sender.selectedSegmentIndex==0) { self.table_order.hidden=false; self.table_upload.hidden = true; [self.table_order reloadData]; } else if(sender.selectedSegmentIndex==1) { // self.table_order.hidden=true; // self.table_upload.hidden = false; // [self.table_upload reloadData]; self.table_order.hidden=true; self.table_submit.hidden = false; [self.table_submit reloadData]; } // else // { // [self onNewOrderClicked:nil]; // } // } #pragma mark - notification action - (void)changePriceType:(id)notification { [self ReloadData]; } - (void)lockOrderListNotification:(NSNotification *)notification { if ([notification.name isEqual:Lock_Permission_Notification]) { if (self.orderType == 1) { self.orderTypeSegmentControl.selectedSegmentIndex = 0; // [self changeOrderType:0]; [self.orderTypeSegmentControl sendActionsForControlEvents:UIControlEventValueChanged]; } if(self.orderTypeSegmentControl.numberOfSegments > 1) { [self.orderTypeSegmentControl removeSegmentAtIndex:1 animated:YES]; // [self changeOrderType:0]; } } else { // 解锁 if ([RASingleton sharedInstance].customer_can_see_sales_Order) { // 有查看Sales order 权限 if (self.orderTypeSegmentControl.numberOfSegments == 1 && !self.table_order.isEditing) { [self.orderTypeSegmentControl insertSegmentWithTitle:[NSString stringWithFormat:@"Purchase Order to %@",COMPANY_SHORT_NAME] atIndex:1 animated:YES]; } } } } - (void)handleUserLogin:(NSNotification *)notification { AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; self.orderType = 0; if (self.table_order.isEditing) { [self.table_order setEditing:NO animated:YES]; self.editOrderListButton.image = [UIImage imageNamed:@"Combinegray"]; } if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) { self.orderTypeSegmentControl.selectedSegmentIndex = 0; [RASingleton sharedInstance].customer_order_type = 0; } } - (void)reRefreshView { [self.table_order reloadData]; } #pragma mark - RA_NOTIFICAITON -(void) refresh_ui { [self.table_order reloadData]; AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; if(appDelegate.can_create_order) { [self.btn_newOrder setImage:[UIImage imageNamed:@"neworder"]]; self.btn_newOrder.enabled = true; } else { [self.btn_newOrder setImage:nil]; self.btn_newOrder.enabled = false; } } -(void) reload_data { self.reset_result=true; self.norefresh=true; [self loadpage]; AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; if(appDelegate.can_create_order) { [self.btn_newOrder setImage:[UIImage imageNamed:@"neworder"]]; self.btn_newOrder.enabled = true; } else { [self.btn_newOrder setImage:nil]; self.btn_newOrder.enabled = false; } } -(void) refresh_price { [self refresh_ui]; } @end