| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151 |
- //
- // OrderListViewController.m
- // RedAnt ERP Mobile
- //
- // Created by Ray on 8/18/15.
- // Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
- //
- #import "OrderListViewController.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"
- @interface OrderListViewController ()
- @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 OrderListViewController
- - (NSOperationQueue *)dataOperationQueue {
- if (!_dataOperationQueue) {
- _dataOperationQueue = [[NSOperationQueue alloc] init];
- _dataOperationQueue.maxConcurrentOperationCount = 1;
- }
- return _dataOperationQueue;
- }
- - (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- - (NSMutableArray *)mergeList {
- if (!_mergeList) {
- _mergeList = [NSMutableArray array];
- }
- return _mergeList;
- }
- -(void) logout
- {
- [self.mergeList removeAllObjects];
- self.offset = 0;
- [self.content_data removeAllObjects];
- [self.table_order 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)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];
-
- 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];
- // 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 (appDelegate.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(appDelegate.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
- if (appDelegate.user_type != USER_ROLE_CUSTOMER || (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeCustomer))
- {
- self.orderTypeSegmentControl.hidden = YES;
-
-
-
- [self.view removeConstraint:self.tableTopConstraint];
- NSLayoutConstraint *myConstraint =[NSLayoutConstraint
- constraintWithItem:self.table_order //item1
- attribute:NSLayoutAttributeTop //约束属性
- relatedBy:NSLayoutRelationEqual //属性间的关系
- toItem:self.label_filter//item2
- attribute:NSLayoutAttributeBottom//约束属性
- multiplier:1
- constant:0.0];// 固定距离
- self.tableTopConstraint = myConstraint;
- [self.view addConstraint: myConstraint];//为button重新添加一个约束
-
- // NSArray *array =self.table_order.constraints;
- // CGRect scframe = CGRectMake(self.orderTypeSegmentControl.frame.origin.x, self.orderTypeSegmentControl.frame.origin.y, self.orderTypeSegmentControl.frame.size.width, 0);
- // self.orderTypeSegmentControl.frame = scframe;
- 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;
- frame.size.height += height;
- }
- self.table_order.frame = frame;
- } else {
- 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 (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];
- }
-
- }
- }
-
- }
- - (IBAction)onNewOrderClicked:(id)sender {
-
- NSString* msg=@"Do you want to create a new order?";
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- if(appDelegate.order_code.length==0)
- {
-
- if(appDelegate.contact_id.length>0)
- {
- msg = [msg stringByAppendingString:@"\n\nCustomer:"];
- msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
-
- }
- }
-
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
-
-
- UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- if(appDelegate.order_code && appDelegate.order_code.length>0)
- {
- // appDelegate.order_code= nil;
- // [appDelegate SetSo:nil];
-
- if (appDelegate.user_type == USER_ROLE_EMPLOYEE) {
- // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
- ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.showNavibar = true;
- cvc.contact_type = @"Sales_Order_Customer";
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- appDelegate.contact_id=[value valueForKey:@"customer_cid"];
- appDelegate.customerInfo = value;
-
- self.norefresh = true;
- [self neworder];
-
-
-
- // [main_vc checklogin:true];
- // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
-
- //
- // if(self.returnValue)
- // self.returnValue(value);
- };
-
- cvc.onCancel = ^(){
- self.norefresh = true;
- if(appDelegate.customerInfo==nil)
- {
- // [RAUtils message_box:@"" message:@"Cannot create order without customer infomation." completion:nil];
-
- [RAUtils message_box:@"" message:@"Cannot create order without customer infomation." completion:nil];
- }
- else
- {
- [self neworder];
- }
- // [main_vc checklogin:true];
- };
- cvc.onReset = ^(){
- // [main_vc checklogin:true];
- };
-
- [self.navigationController pushViewController:cvc animated:true];
- }
- else if (appDelegate.user_type == USER_ROLE_CUSTOMER){
- [self neworder];
- }
-
- }
- else
- {
- //create new;
-
- if(appDelegate.customerInfo==nil)// select contact if current contact not exist
- {
- MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
- ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.showNavibar = true;
- cvc.contact_type = @"Sales_Order_Customer";
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- appDelegate.contact_id=[value valueForKey:@"customer_cid"];
- appDelegate.customerInfo = value;
-
-
- if(appDelegate.order_code==nil)
- [self neworder];
-
- // [main_vc checklogin:true];
- // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
-
- //
- // if(self.returnValue)
- // self.returnValue(value);
- };
-
- cvc.onCancel = ^(){
-
- // [RAUtils message_box:@"" message:@"Cannot create order without customer infomation." completion:nil];
-
- [RAUtils message_box:@"" message:@"Cannot create order without customer infomation." completion:nil];
-
- };
- cvc.onReset = ^(){
- [main_vc checklogin:true];
- };
-
- [self.navigationController pushViewController:cvc animated:true];
- }
- else
- {
- [self neworder];
- }
- }
-
- }];
- UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
-
-
-
- }];
- [alertController addAction:action_2];
- [alertController addAction:action_3];
-
-
- [self presentViewController:alertController animated:YES completion:nil];
-
- // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Warning", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
- // [alert show];
-
-
- }
- - (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=self.searchbar.text;
- // 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;
- }
-
- // dispatch_async(self.loading_queue, ^{
-
- dispatch_sync(dispatch_get_main_queue(), ^{
- if(self.reset_result)
- {
- self.offset = 0;
- [self.content_data removeAllObjects];
- [self.table_order reloadData];
- }
-
- // NSMutableArray* arr_status = [[NSMutableArray alloc] init];
-
- NSMutableArray* arr_statusname = [[NSMutableArray alloc] init];
- int count = [[self.status_cadedate valueForKey:@"count"] intValue];
- for(int i=0;i<count;i++)
- {
- NSDictionary* val_json =[self.status_cadedate objectForKey:[NSString stringWithFormat:@"val_%d",i]];
- int check = [[val_json valueForKey:@"check"] intValue];
- if(check==1)
- {
- // [arr_status addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value_id"]]];
- [arr_statusname addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value"]]];
-
- // break;
- }
- }
-
- // NSString * str_status = [arr_status componentsJoinedByString:@","];
- NSString * str_statusname = [arr_statusname componentsJoinedByString:@","];
- if(str_statusname.length==0)
- str_statusname = @"All";
- self.label_filter.text = str_statusname;
- if(self.offset==0)
- {
- self.table_order.hidden = true;
-
- self.mum.center = self.view.center;
-
- self.mum.hidden = false;
- [self.mum startAnimating];
- }
- self.label_net_err.hidden=true;
-
- });
- // });
- // dispatch_async(self.loading_queue, ^{
- if(self.isrefreshing)
- return;
- self.isrefreshing=true;
-
-
-
-
-
-
-
-
-
- NSMutableArray* arr_status = [[NSMutableArray alloc] init];
-
- // NSMutableArray* arr_statusname = [[NSMutableArray alloc] init];
- int count = [[self.status_cadedate valueForKey:@"count"] intValue];
- for(int i=0;i<count;i++)
- {
- NSDictionary* val_json =[self.status_cadedate objectForKey:[NSString stringWithFormat:@"val_%d",i]];
- int check = [[val_json valueForKey:@"check"] intValue];
- if(check==1)
- {
- [arr_status addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value_id"]]];
- // [arr_statusname addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value"]]];
-
- // break;
- }
- }
-
- NSString * str_status = [arr_status componentsJoinedByString:@","];
-
-
-
-
-
- dispatch_sync(dispatch_get_main_queue(), ^{
- BOOL isMerged = NO;
- AppDelegate *appDelegate = nil;
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
- if (self.orderType == 0) {
- isMerged = NO;
- } else {
- isMerged = YES;
- }
- }
-
- [RANetwork request_orderlist:self.offset limit:self.limit keywords:self.keywords status:str_status customer:self.customer_id is_merged:isMerged completionHandler:^(NSMutableDictionary *result) {
- NSMutableDictionary* content=result;
-
-
-
-
-
-
- [self.mum stopAnimating];
- self.isrefreshing=false;
- if (self.dataOperationQueue.operationCount > 1) { // 队列后面还有操作
- return ;
- }
- int result_code=[[content valueForKey:@"result"] intValue];
-
- if(result_code==2||result_code==0)
- {
-
-
- int count = [[content valueForKey:@"count" ] intValue] ;
-
-
- self.time_zone = [content valueForKey:@"time_zone" ];
- self.offset += count;
- for(int i=0;i<count;i++)
- {
-
- NSDictionary* objmsg = [content objectForKey:[NSString stringWithFormat:@"item_%d",i]];
- [self.content_data addObject:[NSMutableDictionary dictionaryWithDictionary:objmsg]];
-
- }
- if(count<self.limit)
- {
-
- // 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];
- }
- else
- {
- self.load_more_hint=@"Load more...";
- // self.btnrefresh.enabled = true;
- // self.btnrefresh.titleLabel.text =NSLocalizedString(@"load_more",nil);
- // [self.btnrefresh setTitle:@"Load more" forState:UIControlStateNormal];
- }
-
-
- self.table_order.hidden = false;
- self.reset_result=false;
- [self.table_order reloadData ];
- }
- else if(result_code==RESULT_NET_ERROR &&self.offset==0)
- {
- self.label_net_err.hidden=false;
- self.table_order.hidden = true;
- }
- else
- {
-
- [RAUtils message_box:@"Loading Order List" message:[content valueForKey:@"err_msg"] completion:nil];
- }
-
-
-
-
-
-
- }];
-
- });
-
- }
- -(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;
- {
- return 66;
- }
- //- (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
- {
- 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, 2, 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, 2, 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(@"Contact", 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;
- }
- - (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
- {
- // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
- if( self.content_data.count==0)
- return 0;
- return self.content_data.count+1;
-
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- 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 (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;
- cell.label_date.text=purchase_time;
- cell.label_contact.text=customer_name;
- 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;
- }
- // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
- // NSDictionary * combine_json =[item_json objectForKey:@"combine"];
-
- // cell.bundle_item=combine_json;
- // NSString* img_url = [item_json valueForKey:@"img_url"];
- // NSString* description = [item_json valueForKey:@"description"];
- // // NSString* identifier = [item_json valueForKey:@"identifier"];
- // // NSString* attribute = [item_json valueForKey:@"attribute"];
- // NSString* currency = [item_json valueForKey:@"currency"];
- // int count =[[item_json valueForKey:@"count"] intValue];
- // double price =[[item_json valueForKey:@"price"] doubleValue];
- // // cell.labelAttribute.text = attribute;
- // cell.labelCurrency.text = currency;
- // cell.labelDescription.text = description;
- // // cell.labelIdentifier.text = identifier;
- // cell.labelPrice.text = [NSString stringWithFormat:@"%.2f",price];
- //
- //
- //
- // [cell set_Count:count];
-
- // NSString* file_name=[img_url lastPathComponent];
- // NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
- // if(img_data!=nil)
- // {
- //
- // UIImage * img =[UIImage imageWithData:img_data];
- // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
- // }
- // else
- // {
- //
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- //
- //
- // if(downloadimg_data!=nil)
- // {
- // [iSalesDB cache_img:downloadimg_data :file_name ];
- //
- // UIImage * img =[UIImage imageWithData:downloadimg_data];
- // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
- // }
- //
- // });
- // });
- //
- //
- // }
-
- // }
- // else
- // {
- // NSString *CellIdentifier = @"OrderInfoListItem";
- // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- // return cell;
- // }
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- if (tableView.isEditing) { // 编辑模式下不响应
- return;
- }
- //
- if(indexPath.row==self.content_data.count)
- return;
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- if(appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) { // Customer
- if ([RASingleton sharedInstance].global_lock) { // Order list 被锁
-
-
- [RAUtils message_box:@"Warning" message:@"Permission Needed.\nGoto Menu -> Unlock" completion:nil];
- return;
- }
- }
-
- NSString* orderid= [self.content_data[indexPath.row] valueForKey:@"order_id"];
- OrderDetailViewController* dvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderDetailViewController" ];
-
- // int i =[[self.content_data[indexPath.row] valueForKey:@"order_code"];
- dvc.selectOrder=^(NSMutableDictionary* order_detail){
-
- [self.navigationController popViewControllerAnimated:false];
- if(self.selectOrder)
- self.selectOrder(order_detail);
-
-
-
- };
- NSString* order_code =[self.content_data[indexPath.row] valueForKey:@"order_code"];
- NSString *erpSerialNo = [self.content_data[indexPath.row] valueForKey:@"erp_order_serial_no"];
-
- dvc.erpSerialNo = erpSerialNo;
- dvc.is_shoporder=(self.orderType == 0);
- dvc.order_code = order_code;
- dvc.order_status =[[self.content_data[indexPath.row] valueForKey:@"orderStatus"] intValue];
- // bool temp_order = false ;
- // NSString* order_status=[self.content_data[indexPath.row] valueForKey:@"order_status"];
- // if([order_status isEqualToString:@"Saved"]||[order_status isEqualToString:@"Quoted"])
- // temp_order=true;
- //
- // dvc.isTempOrder = temp_order;
-
- // dvc
-
- dvc.orderid=orderid;
- // dvc.category_id=nil;
- // dvc.ispush=true;
- // [dvc reload];
- [self.navigationController pushViewController:dvc animated:true];
-
-
- }
- #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(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* orderid= [self.content_data[indexPath.row] valueForKey:@"order_id"];
- // 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_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 =[NSString stringWithFormat:@"Are you sure to delete order SO#: %@",so];
-
- 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) {
-
- // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Delete Order" completion:^{
-
- PopWaitAlert* pop = [RAUtils waiting_pop:@"Delete Order" completion:nil];
- [RANetwork request_delete_order:orderid completionHandler:^(NSMutableDictionary *result) {
- NSDictionary* return_json = result;
- // [waitalert dismissViewControllerAnimated:YES completion:nil];
-
- [pop hide];
- // [waitalert dismissViewControllerAnimated:YES completion:^{
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
- if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
- {
- appDelegate.order_code= nil;
- [appDelegate SetSo:nil];
-
-
- appDelegate.cart_count=0;
- [appDelegate update_count_mark];
-
- // appDelegate.customerInfo = nil;
- // appDelegate.contact_id = nil;
- // appDelegate.order_customer_id = nil;
- }
-
-
-
- [RAUtils message_box:@"Order Delete" message:nil completion:nil];
- [self ReloadData];
- }
- else
- {
-
- [RAUtils message_box:@"Delete Order" message:[return_json valueForKey:@"err_msg"] completion:nil];
- }
- // }];
-
-
-
-
-
-
- }];
- // }];
-
-
-
- }];
-
- 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);
-
- // 添加一个编辑按钮
- //
- // UITableViewRowAction *cancelAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Cancel Order"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
-
-
- UIContextualAction* cancelAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"Cancel Order" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
-
- DebugLog(@"edit click");
-
-
-
- NSString * title =[NSString stringWithFormat:@"Are you sure to cancel order SO#: %@",so];
-
- UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
-
-
-
- UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
-
- // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Cancel Order" completion:^{
-
- PopWaitAlert* pop = [RAUtils waiting_pop:@"Cancel Order" completion:nil];
- [RANetwork request_cancel_order:orderid order_code:nil completionHandler:^(NSMutableDictionary *result) {
-
- NSDictionary* return_json = result;
- // [waitalert dismissViewControllerAnimated:YES completion:nil];
- // [waitalert dismissViewControllerAnimated:YES completion:^{
-
- [pop hide];
-
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
- if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
- {
- appDelegate.order_code= nil;
- //appDelegate.user_type = 0;
- appDelegate.customerInfo = nil;
- appDelegate.contact_id = nil;
- appDelegate.order_customer_id = nil;
- [appDelegate SetSo:nil];
- appDelegate.cart_count=0;
- [appDelegate update_count_mark];
-
-
- }
-
- [RAUtils message_box:@"Order Canceled" message:nil completion:nil];
- [self ReloadData];
- }
- else
- {
-
- [RAUtils message_box:@"Cancel Order" message:[return_json valueForKey:@"err_msg"] completion:nil];
- }
- // }];
-
-
-
-
-
-
-
- }];
- // }];
-
- }];
-
- 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];
-
-
-
- //
-
- }];
-
-
- cancelAction.backgroundColor = UIColorFromRGB(0xff9933);
-
-
-
-
-
-
-
-
-
- if(/*[order_status isEqualToString:@"Saved Order"]*/statusCode == 1&&appDelegate.can_cancel_order)
- // return @[cancelAction];
- return [UISwipeActionsConfiguration configurationWithActions:@[cancelAction]];
-
- else
- {
- if(/*[order_status isEqualToString:@"Quote Saved"]*/statusCode == 0)
- {
- 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 if (appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
-
- // // Cancel Order Action
- // UITableViewRowAction *cancelAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Cancel Order"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
- //
- UIContextualAction* cancelAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"Cancel Order" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
-
- DebugLog(@"edit click");
-
-
-
- NSString * title =[NSString stringWithFormat:@"Are you sure to cancel order SO#: %@",so];
-
- UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
-
-
-
- UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
-
- // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Cancel Order" completion:^{
-
- PopWaitAlert* pop = [RAUtils waiting_pop:@"Cancel Order" completion:nil];
- [RANetwork request_cancel_order:orderid order_code:nil completionHandler:^(NSMutableDictionary *result) {
- NSDictionary* return_json =result;
- // [waitalert dismissViewControllerAnimated:YES completion:nil];
- // [waitalert dismissViewControllerAnimated:YES completion:^{
-
- [pop hide];
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
- if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
- {
- appDelegate.order_code= nil;
- //appDelegate.user_type = 0;
- appDelegate.customerInfo = nil;
- appDelegate.contact_id = nil;
- appDelegate.order_customer_id = nil;
- [appDelegate SetSo:nil];
- appDelegate.cart_count=0;
- [appDelegate update_count_mark];
-
-
- }
-
- [RAUtils message_box:@"Order Canceled" message:nil completion:nil];
- [self ReloadData];
- }
- else
- {
- [RAUtils message_box:@"Cancel Order" message:[return_json valueForKey:@"err_msg"] completion:nil];
- }
- // }];
-
-
-
-
-
-
-
- }];
- // }];
-
-
- }];
-
- 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];
-
-
-
- //
-
- }];
-
-
- cancelAction.backgroundColor = UIColorFromRGB(0xff9933);
- NSMutableArray *actionArr = [NSMutableArray array];
- // 取消订单
- if(/*[order_status isEqualToString:@"Saved Order"]*/statusCode == 1&&appDelegate.can_cancel_order)
- [actionArr addObject:cancelAction];
-
- // return actionArr;
- return [UISwipeActionsConfiguration configurationWithActions:actionArr];
- }
-
- // return @[];
-
- return [UISwipeActionsConfiguration configurationWithActions:@[]];
-
- }
- - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
-
- 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;
- }
- - (void)tableView:(UITableView *)tableView
- commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
-
-
-
- }
- - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
-
-
- 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;
- }
- }
- /*
- #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;
- }
- - (IBAction)mergeListButtonClick:(UIBarButtonItem *)sender {
-
- if (!self.table_order.isEditing) {
-
-
-
- [RAUtils message_box:@"Warning" message:@"You have to click select firstly then select some saved order" completion:nil];
- return;
- }
-
- [self handleSelectedOrders];
-
- if (!self.mergeList.count) {
-
- return;
- }
-
- SelectUploadOrderViewController *mergeVC = [[UIStoryboard storyboardWithName:@"OLM" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SelectUploadOrderViewController"];
-
- UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:mergeVC];
-
- mergeVC.mergeList = self.mergeList;
-
- mergeVC.title = @"Combine List";
-
- __weak typeof(self) weakself = self;
-
- mergeVC.mergeBlock = ^(NSDictionary *ret) {
-
-
- if (weakself) {
-
- __strong typeof(weakself) strongself = weakself;
-
- if([[ret objectForKey:@"result"]integerValue] == RESULT_TRUE) {
-
- [weakself.mergeList removeAllObjects];
- [strongself.table_order endEditing:YES];
- [strongself ReloadData];
-
- if ([RASingleton sharedInstance].customer_can_see_sales_Order) {
-
- [strongself openOrder:ret];
-
- }
-
- } else {
-
- NSString *msg = [ret objectForKey:@"err_msg"];
-
-
- [RAUtils message_box:nil message:msg completion:nil];
- }
- }
-
- };
-
- mergeVC.deleteBlock = ^(NSString *orderID){
- NSIndexPath *indexPath = [weakself indexPathOfDeleteOrder:orderID];
- [weakself.table_order deselectRowAtIndexPath:indexPath animated:YES];
- };
-
- mergeVC.clearBlock = ^{
- for (NSDictionary *order in self.mergeList) {
-
- NSString *order_id = [NSString stringWithFormat:@"%@",[order objectForKey:@"order_id"]];
- NSIndexPath *indexPath = [weakself indexPathOfDeleteOrder:order_id];
- [weakself.table_order deselectRowAtIndexPath:indexPath animated:YES];
- }
- };
-
- nav.modalPresentationStyle = UIModalPresentationFormSheet;
-
- [self presentViewController:nav animated:YES completion: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 {
- if ([RASingleton sharedInstance].global_lock) { // Order list 被锁
-
-
- [RAUtils message_box:@"Warning" message:@"Permission Needed.\nGoto Menu -> Unlock" completion:nil];
- return;
- }
-
- UIImage *gray = [UIImage imageNamed:@"Combinegray"];
- UIImage *green = [[UIImage imageNamed:@"converttopo"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];//converttopo
-
- if (self.table_order.isEditing) {
- [self mergeListButtonClick:nil];
- // 结束选择时恢复
- if ([RASingleton sharedInstance].customer_can_see_sales_Order && ![RASingleton sharedInstance].global_lock) { // 有查看Sales order 权限,并且app没有锁
- if (self.orderTypeSegmentControl.numberOfSegments == 1) {
- [self.orderTypeSegmentControl insertSegmentWithTitle:[NSString stringWithFormat:@"Purchase Order to %@",COMPANY_SHORT_NAME] atIndex:1 animated:YES];
- }
- }
-
- self.status_cadedate = self.shop_order_filter;
- [self ReloadData];
-
- [self.table_order setEditing:NO animated:YES];
- // sender.title = @"Select";
- // [self.mergeList removeAllObjects];
- [sender setImage:gray];
-
- } else {
- // 选择时不能选择Sales Order
- if(self.orderTypeSegmentControl.numberOfSegments > 1) {
- [self.orderTypeSegmentControl removeSegmentAtIndex:1 animated:YES];
- [self changeOrderType:0];
- }
- // 切换filter
- 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];
- // 刷新,取Saved Order
- [self ReloadData];
-
- [self.table_order setEditing:YES animated:YES];
- // sender.title = @"Exit";
- [sender setImage:green];
- }
-
- }
- - (void)changeOrderType:(NSInteger)ordertype {
- self.orderType = ordertype;
- [RASingleton sharedInstance].customer_order_type = ordertype;
- if(self.init_style != OL_OPEN) {
- switch (ordertype) {
- case 0:{
- self.status_cadedate = self.shop_order_filter;
- }
- break;
- case 1:{
- self.status_cadedate = self.sales_order_filter;
- }
- break;
- default:
- break;
- }
-
- NSMutableArray *items = [self.toolbarView.items mutableCopy];
- if (ordertype == 1) {
- // 不能合并
- // if ([items containsObject:self.mergeListButton]) { // 显示button
- // [items removeObject:self.mergeListButton];
- // }
- if ([items containsObject:self.editOrderListButton]) { // 显示button
- [items removeObject:self.editOrderListButton];
- }
-
- self.toolbarView.items = items;
-
- } else {
-
- // 合并订单的权限
- if ([RASingleton sharedInstance].permissions_merge_order) { // 能够合并
-
- // 4 6 顺序不能换
- if (![items containsObject:self.editOrderListButton]) { // 没显示button
- [items insertObject:self.editOrderListButton atIndex:4];
- }
-
- // if (![items containsObject:self.mergeListButton]) { // 没显示button
- // [items insertObject:self.mergeListButton atIndex:6];
- // }
-
- self.toolbarView.items = items;
-
- } else { // 不能合并
- // if ([items containsObject:self.mergeListButton]) { // 显示button
- // [items removeObject:self.mergeListButton];
- // }
- if ([items containsObject:self.editOrderListButton]) { // 显示button
- [items removeObject:self.editOrderListButton];
- }
-
- self.toolbarView.items = items;
- }
-
- }
-
- } else {
-
- NSString *resource = @"status_filter_cadedate_open";
- if (ordertype == 1) {
- resource = @"status_filter_cadedate_po";
- }
-
- NSData *json=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:resource ofType:@"json" ]];
- NSError *error=nil;
- self.status_cadedate = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
-
- }
-
-
-
- [self ReloadData];
- }
- - (IBAction)orderTypeChanged:(UISegmentedControl *)sender {
- [self changeOrderType:sender.selectedSegmentIndex];
-
- }
- - (void)openOrder:(NSDictionary *)order {
-
- if (!order) {
- return;
- }
-
- NSString *orderCode = [order objectForKey:@"orderCode"];
- NSInteger orderStatus = [[order objectForKey:@"orderStatus"] integerValue];
- NSString *so = [order objectForKey:@"so#"];
-
- // __weak typeof(self) weakself = self;
-
- [RANetwork request_open_order:orderCode completionHandler:^(NSMutableDictionary *result) {
- NSDictionary* order_json = result ;
-
-
- if([[order_json valueForKey:@"result"] intValue]==2)
- {
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- appDelegate.order_code = orderCode;
- appDelegate.order_status = (int)orderStatus;
- [appDelegate SetSo:so];
-
- __weak MainViewController *mainVC = (MainViewController*)appDelegate.main_vc;
-
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"CartViewController,OrderListViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
-
-
- [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
- #endif
-
- [((MainViewController*)appDelegate.main_vc) switchToCart];
-
- mainVC.cartViewController.onFinishLoad=^{
- [mainVC.cartViewController placeOrder];
- mainVC.cartViewController.onFinishLoad=nil;
- };
-
- }
- else
- {
-
-
- [RAUtils message_box:@"Open Order" message:[order_json valueForKey:@"err_msg"] completion: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
|