| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215 |
- //
- // 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;///<sales order/shop order
- @property (nonatomic,strong) NSMutableDictionary *sales_order_filter;
- @property (nonatomic,strong) NSMutableDictionary *shop_order_filter;
- @property (strong, nonatomic) IBOutlet UIBarButtonItem *mergeListButton;
- @property (strong, nonatomic) IBOutlet UIBarButtonItem *editOrderListButton;
- @property (strong, nonatomic) IBOutlet UISegmentedControl *orderTypeSegmentControl;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *tableTopConstraint;
- @end
- @implementation ScanOrderListViewController
- - (NSOperationQueue *)dataOperationQueue {
- if (!_dataOperationQueue) {
- _dataOperationQueue = [[NSOperationQueue alloc] init];
- _dataOperationQueue.maxConcurrentOperationCount = 1;
- }
- return _dataOperationQueue;
- }
- - (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- AppDelegate* appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
- [appdelegate.uploadManager removeObserver:self forKeyPath:@"arr_queue"];
- }
- - (NSMutableArray *)mergeList {
- if (!_mergeList) {
- _mergeList = [NSMutableArray array];
- }
- return _mergeList;
- }
- -(void) logout
- {
- [self.mergeList removeAllObjects];
- self.offset = 0;
- [self.content_data removeAllObjects];
- [self.submit_content_data removeAllObjects];
- [self.table_order reloadData];
- [self.table_submit reloadData];
- self.status_cadedate = nil;
- }
- #ifndef RA_NOTIFICATION
- -(void) reload_container_getdata:(bool) update_data
- {
- [super reload_container_getdata:update_data];
- if(update_data)
- {
- // self.offset = 0;
- // [self.content_data removeAllObjects];
- self.reset_result=true;
- self.norefresh=true;
- [self reload_data];
- }
- else
- {
- [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;
- }
- }
- #endif
- -(void) showHidePrice
- {
- #ifndef RA_NOTIFICATION
- [self reload_container_getdata:false];
- #endif
- }
- - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
- {
-
- if([keyPath isEqualToString:@"arr_queue"])
- {
- // NSArray* arr1 = [change objectForKey:NSKeyValueChangeOldKey];
- // NSArray* arr2 = [change objectForKey:NSKeyValueChangeNewKey];
- // if(arr1.count!=arr2.count)
-
- __weak typeof(self) weakself = self;
- dispatch_async(dispatch_get_main_queue(), ^{
- blockDebugLog(@"arr_queue changed reload tableview");
- [self.table_upload reloadData];
- });
-
- }
- // if(context)
- // NSLog(@"old: %@", [change objectForKey:NSKeyValueChangeOldKey]);
- // NSLog(@"old: %@", [change objectForKey:NSKeyValueChangeNewKey]);
- // NSLog(@"context: %@", context);
- }
- - (void)onNewOrder: (NSNotification *)notification
- {
- [self onNewOrderClicked:nil];
-
- }
- - (void)onShowList: (NSNotification *)notification
- {
-
- if([notification.name isEqualToString:@"ShowUnSubmit"])
- {
- [self.orderTypeSegmentControl setSelectedSegmentIndex:0];
-
- self.table_order.hidden=false;
- self.table_submit.hidden = true;
- // [self.table_upload reloadData];
- [self.table_order reloadData];
- [self.table_submit reloadData];
-
- // onSegmentChanged
- }
- else
- {
-
- [self.orderTypeSegmentControl setSelectedSegmentIndex:1];
-
- self.table_order.hidden=true;
- self.table_submit.hidden = false;
- // [self.table_order reloadData];
- [self.table_order reloadData];
- [self.table_submit reloadData];
- }
-
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // self.edgesForExtendedLayout = UIRectEdgeNone;
-
- self.loading_queue = dispatch_queue_create("orderlist_loading", NULL);
-
- self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
- self.label_net_err.layer.borderWidth = 2.0;
- self.label_net_err.layer.cornerRadius=15;
- self.label_net_err.layer.masksToBounds=true;
- #ifndef RA_NOTIFICATION
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changePriceType:) name:Change_Price_Type_Notification object:nil];
- #endif
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(lockOrderListNotification:) name:Lock_Permission_Notification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(lockOrderListNotification:) name:unLock_Permission_Notification object:nil];
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleUserLogin:) name:User_LoginOK_Notification object:nil];
-
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onNewOrder:) name:@"NewOrder" object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onShowList:) name:@"ShowSubmit" object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onShowList:) name:@"ShowUnSubmit" object:nil];
-
-
- AppDelegate* appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
-
-
- [appdelegate.uploadManager addObserver:self
- forKeyPath:@"arr_queue"
- options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld)
- context:@"arr_queue changed"];
-
-
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
- // tap.minimumPressDuration = 0.8; //定义按的时间
- [self.label_net_err addGestureRecognizer:tap];
- // Do any additional setup after loading the view.
- self.offset = 0;
- self.limit = 25;
- self.content_data = [[NSMutableArray alloc]init];
- self.submit_content_data = [[NSMutableArray alloc]init];
- // Customer Order Type 0 Shop Order/ 1 Sales Order
- // self.orderType = self.orderTypeSegmentControl.selectedSegmentIndex;
- [RASingleton sharedInstance].customer_order_type = self.orderType;
-
-
- UIRefreshControl *ref = [[UIRefreshControl alloc]init];
- ref.tag = 201 ;
- ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
- ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
- // ref.hidden = true;
- [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
- [self.table_order addSubview:ref];
- self.table_order.allowsMultipleSelectionDuringEditing = YES;
-
- // 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 *mainBundleFile = [NSData dataWithContentsOfFile:order_filter_source_path];
- //
- // // DebugLog(@"mainBundleFile==%@",mainBundleFile);
- //
- // [[NSFileManager defaultManager] createFileAtPath:dist_path
- //
- // contents:mainBundleFile
- //
- // attributes:nil];
- //
- // }
-
- [self loadfilter];
-
-
- }
- -(void) loadfilter
- {
- //
- // if(self.status_cadedate!=nil)
- // return;
- //
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- //
- // if (RASingleton.sharedInstance.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
- // self.shop_order_filter = [RASingleton sharedInstance].shop_order_status_filter;
- // self.sales_order_filter = [RASingleton sharedInstance].sales_order_status_filter;
- // if(self.init_style==OL_OPEN)
- // {
- // NSData *data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"status_filter_cadedate_open" ofType:@"json" ]];
- // NSError *error=nil;
- // self.status_cadedate = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
- //
- // }
- //// else if (self.orderTypeSegmentControl.selectedSegmentIndex == 0) {
- //// self.status_cadedate = self.shop_order_filter;
- //// } else {
- //// self.status_cadedate = self.sales_order_filter;
- //// }
- // return;
- // }
- //
- // NSData* json =nil;
- // if(self.init_style==OL_OPEN)
- // {
- // json=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"status_filter_cadedate_open" ofType:@"json" ]];
- // NSError *error=nil;
- // self.status_cadedate = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
- //
- // }
- // else
- // {
- // // json=//[NSData dataWithContentsOfFile:dist_path];
- // // NSError *error=nil;
- // self.status_cadedate = appDelegate.OrderFilter;//[[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
- // }
- }
- - (IBAction)onCancel:(id)sender {
- if(self.onCancel)
- self.onCancel();
- [self.navigationController popViewControllerAnimated:false];
- }
- - (IBAction)onStatusFilterClick:(id)sender {
- // if (self.table_order.isEditing || self.init_style == OL_OPEN) {
- // return;
- // }
- // EnumSelectViewController* enumvc =[[UIStoryboard storyboardWithName:@"CommonEditor" bundle:nil] instantiateViewControllerWithIdentifier:@"EnumSelectorViewController"];
- // enumvc.delegate = self;
- // enumvc.max_select = 0;
- // //enumvc.updatePosition = indexPath;
- // // if([[required lowercaseString] isEqualToString:@"true"])
- // // enumvc.canbeEmpty = false;
- // // else
- // // enumvc.canbeEmpty =true;
- // enumvc.cadedate = self.status_cadedate ;
- // enumvc.title = @"Order Status Selection";
- // // enumvc.value = [value_json mutableCopy];
- // enumvc.single_select =false;
- //
- // [self.navigationController pushViewController:enumvc animated:true];
- }
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- [self loadfilter];
-
- [[self navigationController] setNavigationBarHidden:!self.showNavibar animated:NO];
-
- // 检查权限
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- NSMutableArray *items = [self.toolbarView.items mutableCopy];
-
- if(RASingleton.sharedInstance.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
-
- // Check for Saved Order中Type和History Type不一致导致Status不正确
- [RASingleton sharedInstance].customer_order_type = self.orderType;
- // if (!self.table_order.isEditing) { // 在编辑状态下不能change Type否则显示混乱
- // [self changeOrderType:self.orderType];
- // }
-
- // 合并订单的权限
- if ([RASingleton sharedInstance].permissions_merge_order) { // 能够合并
-
- // 4 6 顺序不能换
- if (![items containsObject:self.editOrderListButton]) { // 没显示button
- [items insertObject:self.editOrderListButton atIndex:4];
- }
-
- self.toolbarView.items = items;
-
- } else { // 不能合并
-
- if ([items containsObject:self.editOrderListButton]) { // 显示button
- [items removeObject:self.editOrderListButton];
- }
-
- self.toolbarView.items = items;
- }
-
- // // Check For Saved Order 不能合并
- // if(self.init_style==OL_OPEN || self.orderType == 1) {
- //
- // if ([items containsObject:self.editOrderListButton]) { // 显示button
- // [items removeObject:self.editOrderListButton];
- // }
- //
- // self.toolbarView.items = items;
- //
- // }
-
- } else {
-
-
- if ([items containsObject:self.editOrderListButton]) { // 显示button
- [items removeObject:self.editOrderListButton];
- }
-
- self.toolbarView.items = items;
- }
-
- // 非Customer用户不用区分Sales Order 和 Shop Order
- {
- self.orderTypeSegmentControl.hidden = NO;
-
- // [self.view removeConstraint:self.tableTopConstraint];
- //
- //
- // NSLayoutConstraint *myConstraint =[NSLayoutConstraint
- // constraintWithItem:self.table_order //item1
- // attribute:NSLayoutAttributeTop //约束属性
- // relatedBy:NSLayoutRelationEqual //属性间的关系
- // toItem:self.orderTypeSegmentControl//item2
- // attribute:NSLayoutAttributeBottom//约束属性
- // multiplier:1
- // constant:0.0];// 固定距离
- // self.tableTopConstraint = myConstraint;
- // [self.view addConstraint: myConstraint];//为button重新添加一个约束
- //
- //
- //
- // CGFloat y = CGRectGetMinY(self.orderTypeSegmentControl.frame);
- // CGFloat height = CGRectGetHeight(self.orderTypeSegmentControl.frame);
- // CGRect frame = self.table_order.frame;
- // if (frame.origin.y == y) {
- // frame.origin.y = y + height;
- // frame.size.height -= height;
- // }
- // self.table_order.frame = frame;
- }
-
- // 修复Homer显示NPD
- // if (self.orderTypeSegmentControl.numberOfSegments > 1) {
- // [self.orderTypeSegmentControl setTitle:[NSString stringWithFormat:@"Purchase Order to %@",COMPANY_SHORT_NAME] forSegmentAtIndex:1];
- // }
- //
- // // 显示Sales Order与否
- // if (RASingleton.sharedInstance.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;i<count;i++)
- {
-
- NSDictionary* objmsg = [orderlist objectForKey:[NSString stringWithFormat:@"item_%d",i]];
- [self.content_data addObject:[NSMutableDictionary dictionaryWithDictionary:objmsg]];
-
- }
-
-
-
- NSMutableDictionary* submitlist = [OLDataProvider getScanSubmitList];
- // NSString *submitlistPath = [userdir stringByAppendingPathComponent:@"submitlist.json"];
- // submitlist=[[RAUtils dictfromfile:submitlistPath] mutableCopy];
- [self.submit_content_data removeAllObjects];
- int scount = [submitlist[@"count"] intValue];
- for(int i=0;i<scount;i++)
- {
-
- NSDictionary* objmsg = [submitlist objectForKey:[NSString stringWithFormat:@"item_%d",i]];
- [self.submit_content_data addObject:[NSMutableDictionary dictionaryWithDictionary:objmsg]];
-
- }
-
-
- // int i =self.btnrefresh.state;
- self.load_more_hint=@"All loaded";
- // self.btnrefresh.titleLabel.text =NSLocalizedString(@"no_more", nil);
- // [self.btnrefresh setTitle:@"No more" forState:UIControlStateNormal];
-
-
-
- dispatch_sync(dispatch_get_main_queue(), ^{
- // self.table_order.hidden = false;
- // self.table_submit.hidden = false;
- self.reset_result=false;
- [self.table_order reloadData ];
- [self.table_submit reloadData ];
- });
- return;
- }
- -(void) loadpage
- {
- __weak typeof(self) weakself = self;
- NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
-
- if (weakself) {
- __strong typeof(weakself) strongself = weakself;
- [strongself operation_loadPage];
- }
-
- }];
-
- [self.dataOperationQueue addOperation:operation];
-
- }
- - (void)loadmore
- {
- // self.btnrefresh.enabled = NO;
- // self.btnrefresh.titleLabel.text =NSLocalizedString(@"loading",nil);
-
- // [self.btnrefresh setTitle:@"Loading..." forState:UIControlStateNormal];
- [self loadpage];
- }
- //-(void)changeCell
- //{
- //// UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
- //// reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"refreshing"];
- // [self performSelector:@selector(loadmore) withObject:nil afterDelay:1];
- // DebugLog(@"refresh!!!!!!!!");
- //
- //}
- -(void) neworder
- {
-
- // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order" completion:^{
-
- PopWaitAlert* pop = [RAUtils waiting_pop:@"Create Order" completion:nil];
- [RANetwork request_create_order:^(NSMutableDictionary *result) {
- NSMutableDictionary* return_json =result;
-
- // [waitalert dismissViewControllerAnimated:YES completion:^{
- [pop hide];
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
- int result=[[return_json valueForKey:@"result"] intValue];
- if(result==2)
- {
- //successed.
-
- NSString* order_code = [return_json valueForKey:@"orderCode"];
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- appDelegate.order_code = order_code;
- appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
-
-
- #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 ReloadData];
-
-
- }
- }
- else
- {
- [RAUtils message_box:@"Create Order" message:[return_json valueForKey:@"err_msg"] completion:nil];
- }
- // }];
- // [waitalert dismissViewControllerAnimated:YES completion:nil];
-
-
-
-
-
-
-
-
- }];
-
- }
- #pragma mark - Table view data source
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- {
- if(tableView==self.table_order||tableView==self.table_submit)
- return 66;
- else
- return 100;
-
- }
- //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- //{
- // return 0;
- //}
- //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- //{
- // return 0;
- //}
- //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
- //{
- // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
- // return myView;
- //
- //}
- - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- {
- if(tableView==self.table_order)
- {
- NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
-
- if(value==nil)
- value=@"";
- unsigned long color = strtoul([value UTF8String],0,16);
-
- DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
- // myView.backgroundColor = UIColorFromRGB(0x996633);
- myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
- myView.layer.shadowColor = [UIColor blackColor].CGColor;
- myView.layer.shadowOffset = CGSizeMake(0, 0);
- myView.layer.shadowOpacity = 0.5;
- myView.layer.shadowRadius = 2.0;
-
-
- UILabel *statuslabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 11, 130, 22)];
- statuslabel.textColor=UIColorFromRGB(color);
- statuslabel.backgroundColor = [UIColor clearColor];
- statuslabel.text=NSLocalizedString(@"Status", nil);
- [statuslabel sizeToFit];
- [myView addSubview:statuslabel];
-
- // UILabel *solabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 21, 130, 22)];
- // solabel.textColor=UIColorFromRGB(color);
- // solabel.backgroundColor = [UIColor clearColor];
- // solabel.text=NSLocalizedString(@"SO#", nil);
- // [solabel sizeToFit];
- // [myView addSubview:solabel];
-
- // UILabel *userlabel = [[UILabel alloc] initWithFrame:CGRectMake(165, 21, 125, 22)];
- // userlabel.textColor=UIColorFromRGB(color);
- // userlabel.backgroundColor = [UIColor clearColor];
- // userlabel.text=NSLocalizedString(@"Sales rep", nil);
- // [userlabel sizeToFit];
- // [myView addSubview:userlabel];
-
- UILabel *creatorlabel = [[UILabel alloc] initWithFrame:CGRectMake(165, 11, 125, 22)];
- creatorlabel.textColor=UIColorFromRGB(color);
- creatorlabel.backgroundColor = [UIColor clearColor];
- creatorlabel.text=NSLocalizedString(@"Create by", nil);
- [creatorlabel sizeToFit];
- [myView addSubview:creatorlabel];
-
- UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(296, 11, 150, 22)];
-
- contactlabel.textColor=UIColorFromRGB(color);
- contactlabel.backgroundColor = [UIColor clearColor];
- contactlabel.text=NSLocalizedString(@"Company / Contact ID", nil);
- [contactlabel sizeToFit];
- [myView addSubview:contactlabel];
-
-
-
- //
- // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(424, 11, 52, 22)];
- // modellabel.textColor=[UIColor whiteColor];
- // modellabel.backgroundColor = [UIColor clearColor];
- // modellabel.text=NSLocalizedString(@"Model", nil);
- // [modellabel sizeToFit];
- // [myView addSubview:modellabel];
-
- // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(self.table_order.frame.size.width-276, 2, 100, 22)];
- // modellabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
- // modellabel.textColor=[UIColor whiteColor];
- // modellabel.backgroundColor = [UIColor clearColor];
- // modellabel.text=NSLocalizedString(@"Items/QTY", nil);
- // [modellabel sizeToFit];
- // [myView addSubview:modellabel];
-
-
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- UILabel *pricelabel = nil;
- if(appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && self.orderType==1)
- pricelabel=[[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.table_order.frame.size.width-276, 2, 100, 22)];
- else
- pricelabel=[[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.table_order.frame.size.width-276, 11, 100, 22)];
- pricelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
- pricelabel.textColor=UIColorFromRGB(color);
- pricelabel.backgroundColor = [UIColor clearColor];
- pricelabel.text=NSLocalizedString(@"Order Total", nil);
- [pricelabel sizeToFit];
- [myView addSubview:pricelabel];
-
-
- if(appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && self.orderType==1)
- {
- UILabel *polabel = nil;
- polabel=[[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.table_order.frame.size.width-276, 21, 100, 22)];
- polabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
- polabel.textColor=UIColorFromRGB(color);
- polabel.backgroundColor = [UIColor clearColor];
- polabel.text=NSLocalizedString(@"PO#", nil);
- [polabel sizeToFit];
- [myView addSubview:polabel];
- }
-
-
- UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(self.table_order.frame.size.width-163/*605*/,11, 148, 22)];
- timelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
- timelabel.textColor=UIColorFromRGB(color);
- timelabel.backgroundColor = [UIColor clearColor];
- if(self.time_zone==nil)
- timelabel.text=@"Create time";
- else
- timelabel.text=[NSString stringWithFormat:@"Create time (%@)",self.time_zone];
- [timelabel sizeToFit];
- [myView addSubview:timelabel];
-
- myView.autoresizesSubviews=true;
- // [myView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin];
-
-
-
-
- // modellabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
- // pricelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
- // timelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
- myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
- //
- return myView;
- }
- else
- if(tableView==self.table_submit)
- {
- NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
-
- if(value==nil)
- value=@"";
- unsigned long color = strtoul([value UTF8String],0,16);
-
- DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
- // myView.backgroundColor = UIColorFromRGB(0x996633);
- myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
- myView.layer.shadowColor = [UIColor blackColor].CGColor;
- myView.layer.shadowOffset = CGSizeMake(0, 0);
- myView.layer.shadowOpacity = 0.5;
- myView.layer.shadowRadius = 2.0;
-
-
- UILabel *statuslabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 11, 130, 22)];
- statuslabel.textColor=UIColorFromRGB(color);
- statuslabel.backgroundColor = [UIColor clearColor];
- statuslabel.text=NSLocalizedString(@"SO#", nil);
- [statuslabel sizeToFit];
- [myView addSubview:statuslabel];
-
- // UILabel *solabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 21, 130, 22)];
- // solabel.textColor=UIColorFromRGB(color);
- // solabel.backgroundColor = [UIColor clearColor];
- // solabel.text=NSLocalizedString(@"SO#", nil);
- // [solabel sizeToFit];
- // [myView addSubview:solabel];
-
- // UILabel *userlabel = [[UILabel alloc] initWithFrame:CGRectMake(165, 21, 125, 22)];
- // userlabel.textColor=UIColorFromRGB(color);
- // userlabel.backgroundColor = [UIColor clearColor];
- // userlabel.text=NSLocalizedString(@"Sales rep", nil);
- // [userlabel sizeToFit];
- // [myView addSubview:userlabel];
-
- UILabel *creatorlabel = [[UILabel alloc] initWithFrame:CGRectMake(165, 11, 125, 22)];
- creatorlabel.textColor=UIColorFromRGB(color);
- creatorlabel.backgroundColor = [UIColor clearColor];
- creatorlabel.text=NSLocalizedString(@"Create by", nil);
- [creatorlabel sizeToFit];
- [myView addSubview:creatorlabel];
-
- UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(296, 11, 150, 22)];
-
- contactlabel.textColor=UIColorFromRGB(color);
- contactlabel.backgroundColor = [UIColor clearColor];
- contactlabel.text=NSLocalizedString(@"Company / Customer ID", nil);
- [contactlabel sizeToFit];
- [myView addSubview:contactlabel];
-
-
-
- //
- // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(424, 11, 52, 22)];
- // modellabel.textColor=[UIColor whiteColor];
- // modellabel.backgroundColor = [UIColor clearColor];
- // modellabel.text=NSLocalizedString(@"Model", nil);
- // [modellabel sizeToFit];
- // [myView addSubview:modellabel];
-
- // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(self.table_order.frame.size.width-276, 2, 100, 22)];
- // modellabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
- // modellabel.textColor=[UIColor whiteColor];
- // modellabel.backgroundColor = [UIColor clearColor];
- // modellabel.text=NSLocalizedString(@"Items/QTY", nil);
- // [modellabel sizeToFit];
- // [myView addSubview:modellabel];
-
-
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- UILabel *pricelabel = nil;
- if(appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && self.orderType==1)
- pricelabel=[[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.table_order.frame.size.width-276, 2, 100, 22)];
- else
- pricelabel=[[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.table_order.frame.size.width-276, 11, 100, 22)];
- pricelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
- pricelabel.textColor=UIColorFromRGB(color);
- pricelabel.backgroundColor = [UIColor clearColor];
- pricelabel.text=NSLocalizedString(@"Order Total", nil);
- [pricelabel sizeToFit];
- [myView addSubview:pricelabel];
-
-
- if(appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && self.orderType==1)
- {
- UILabel *polabel = nil;
- polabel=[[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.table_order.frame.size.width-276, 21, 100, 22)];
- polabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
- polabel.textColor=UIColorFromRGB(color);
- polabel.backgroundColor = [UIColor clearColor];
- polabel.text=NSLocalizedString(@"PO#", nil);
- [polabel sizeToFit];
- [myView addSubview:polabel];
- }
-
-
- UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(self.table_order.frame.size.width-163/*605*/,11, 148, 22)];
- timelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
- timelabel.textColor=UIColorFromRGB(color);
- timelabel.backgroundColor = [UIColor clearColor];
- if(self.time_zone==nil)
- timelabel.text=@"Create time";
- else
- timelabel.text=[NSString stringWithFormat:@"Create time (%@)",self.time_zone];
- [timelabel sizeToFit];
- [myView addSubview:timelabel];
-
- myView.autoresizesSubviews=true;
- // [myView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin];
-
-
-
-
- // modellabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
- // pricelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
- // timelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
- myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
- //
- return myView;
- }
- else return nil;
-
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- return 44;
- }
- //
- //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
- // if(section==0)
- // return nil;
- // else
- // return @"detail section";
- //}
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- if(tableView==self.table_order)
- {
- return self.content_data.count;
- // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
- // if( self.content_data.count==0)
- // return 0;
- // return self.content_data.count+1;
- }
- if(tableView==self.table_submit)
- {
- return self.submit_content_data.count;
- // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
- // if( self.content_data.count==0)
- // return 0;
- // return self.content_data.count+1;
- }
- else
- {
- AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
- return Appdelegate.uploadManager.arr_queue.count;
- }
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if(tableView==self.table_order)
- {
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- // if(tableView==self.itemListTable)
- // {
-
- // if(indexPath.row>self.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 (RASingleton.sharedInstance.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 (RASingleton.sharedInstance.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"]];
- // RASingleton.sharedInstance.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"]];
- // RASingleton.sharedInstance.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
|