OrderListViewController.m 103 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634
  1. //
  2. // OrderListViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 8/18/15.
  6. // Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "OrderListViewController.h"
  9. #import "OrderListTableViewCell.h"
  10. #import "RANetwork.h"
  11. #import "OrderDetailViewController.h"
  12. #import "MainViewController.h"
  13. #import "ContactListViewController.h"
  14. #import "DefaultAppearance.h"
  15. #import "DefaultTableHeaderView.h"
  16. #import "SelectUploadOrderViewController.h"
  17. #import "NotificationNameCenter.h"
  18. #import "RASingleton.h"
  19. #import "ERPUtils.h"
  20. @interface OrderListViewController ()
  21. @property (nonatomic,strong) NSOperationQueue *dataOperationQueue;
  22. @property (nonatomic,strong) NSMutableArray *mergeList;
  23. @property (nonatomic,assign) NSInteger orderType;///<sales order/shop order
  24. @property (nonatomic,strong) NSMutableDictionary *sales_order_filter;
  25. @property (nonatomic,strong) NSMutableDictionary *shop_order_filter;
  26. @property (strong, nonatomic) IBOutlet UIBarButtonItem *mergeListButton;
  27. @property (strong, nonatomic) IBOutlet UIBarButtonItem *editOrderListButton;
  28. @property (strong, nonatomic) IBOutlet UISegmentedControl *orderTypeSegmentControl;
  29. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *tableTopConstraint;
  30. @end
  31. @implementation OrderListViewController
  32. - (NSOperationQueue *)dataOperationQueue {
  33. if (!_dataOperationQueue) {
  34. _dataOperationQueue = [[NSOperationQueue alloc] init];
  35. _dataOperationQueue.maxConcurrentOperationCount = 1;
  36. }
  37. return _dataOperationQueue;
  38. }
  39. - (void)dealloc {
  40. [[NSNotificationCenter defaultCenter] removeObserver:self];
  41. }
  42. - (NSMutableArray *)mergeList {
  43. if (!_mergeList) {
  44. _mergeList = [NSMutableArray array];
  45. }
  46. return _mergeList;
  47. }
  48. -(void) logout
  49. {
  50. [self.mergeList removeAllObjects];
  51. self.offset = 0;
  52. [self.content_data removeAllObjects];
  53. [self.table_order reloadData];
  54. self.status_cadedate = nil;
  55. }
  56. #ifndef RA_NOTIFICATION
  57. -(void) reload_container_getdata:(bool) update_data
  58. {
  59. [super reload_container_getdata:update_data];
  60. if(update_data)
  61. {
  62. // self.offset = 0;
  63. // [self.content_data removeAllObjects];
  64. self.reset_result=true;
  65. self.norefresh=true;
  66. [self reload_data];
  67. }
  68. else
  69. {
  70. [self.table_order reloadData];
  71. }
  72. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  73. if(appDelegate.can_create_order)
  74. {
  75. [self.btn_newOrder setImage:[UIImage imageNamed:@"neworder"]];
  76. self.btn_newOrder.enabled = true;
  77. }
  78. else
  79. {
  80. [self.btn_newOrder setImage:nil];
  81. self.btn_newOrder.enabled = false;
  82. }
  83. }
  84. #endif
  85. -(void) showHidePrice
  86. {
  87. #ifndef RA_NOTIFICATION
  88. [self reload_container_getdata:false];
  89. #endif
  90. }
  91. - (void)viewDidLoad {
  92. [super viewDidLoad];
  93. self.edgesForExtendedLayout = UIRectEdgeNone;
  94. self.loading_queue = dispatch_queue_create("orderlist_loading", NULL);
  95. self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
  96. self.label_net_err.layer.borderWidth = 2.0;
  97. self.label_net_err.layer.cornerRadius=15;
  98. self.label_net_err.layer.masksToBounds=true;
  99. #ifndef RA_NOTIFICATION
  100. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changePriceType:) name:Change_Price_Type_Notification object:nil];
  101. #endif
  102. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(lockOrderListNotification:) name:Lock_Permission_Notification object:nil];
  103. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(lockOrderListNotification:) name:unLock_Permission_Notification object:nil];
  104. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleUserLogin:) name:User_LoginOK_Notification object:nil];
  105. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
  106. // tap.minimumPressDuration = 0.8; //定义按的时间
  107. [self.label_net_err addGestureRecognizer:tap];
  108. // Do any additional setup after loading the view.
  109. self.offset = 0;
  110. self.limit = 25;
  111. self.content_data = [[NSMutableArray alloc]init];
  112. // Customer Order Type 0 Shop Order/ 1 Sales Order
  113. self.orderType = self.orderTypeSegmentControl.selectedSegmentIndex;
  114. [RASingleton sharedInstance].customer_order_type = self.orderType;
  115. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  116. ref.tag = 201 ;
  117. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  118. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  119. // ref.hidden = true;
  120. [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
  121. [self.table_order addSubview:ref];
  122. self.table_order.allowsMultipleSelectionDuringEditing = YES;
  123. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  124. // NSString *documents = [paths objectAtIndex:0];
  125. // NSString *dist_path = [documents stringByAppendingPathComponent:@"status_filter_cadedate.json"];
  126. // if ([[NSFileManager defaultManager] fileExistsAtPath:dist_path]) {
  127. //
  128. // DebugLog(@"文件已经存在了");
  129. //
  130. // }
  131. // else
  132. // {
  133. //
  134. //
  135. //
  136. // // DebugLog(@"resourceSampleImagesFolderPath=%@",resourceFolderPath);
  137. //
  138. // NSData *mainBundleFile = [NSData dataWithContentsOfFile:order_filter_source_path];
  139. //
  140. // // DebugLog(@"mainBundleFile==%@",mainBundleFile);
  141. //
  142. // [[NSFileManager defaultManager] createFileAtPath:dist_path
  143. //
  144. // contents:mainBundleFile
  145. //
  146. // attributes:nil];
  147. //
  148. // }
  149. [self loadfilter];
  150. }
  151. -(void) loadfilter
  152. {
  153. if(self.status_cadedate!=nil)
  154. return;
  155. UIApplication * app = [UIApplication sharedApplication];
  156. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  157. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  158. self.shop_order_filter = [RASingleton sharedInstance].shop_order_status_filter;
  159. self.sales_order_filter = [RASingleton sharedInstance].sales_order_status_filter;
  160. if(self.init_style==OL_OPEN)
  161. {
  162. NSData *data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"status_filter_cadedate_open" ofType:@"json" ]];
  163. NSError *error=nil;
  164. self.status_cadedate = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  165. } else if (self.orderTypeSegmentControl.selectedSegmentIndex == 0) {
  166. self.status_cadedate = self.shop_order_filter;
  167. } else {
  168. self.status_cadedate = self.sales_order_filter;
  169. }
  170. return;
  171. }
  172. NSData* json =nil;
  173. if(self.init_style==OL_OPEN)
  174. {
  175. json=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"status_filter_cadedate_open" ofType:@"json" ]];
  176. NSError *error=nil;
  177. self.status_cadedate = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  178. }
  179. else
  180. {
  181. // json=//[NSData dataWithContentsOfFile:dist_path];
  182. // NSError *error=nil;
  183. self.status_cadedate = appDelegate.OrderFilter;//[[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  184. }
  185. }
  186. - (IBAction)onCancel:(id)sender {
  187. if(self.onCancel)
  188. self.onCancel();
  189. [self.navigationController popViewControllerAnimated:false];
  190. }
  191. - (IBAction)onStatusFilterClick:(id)sender {
  192. if (self.table_order.isEditing || self.init_style == OL_OPEN) {
  193. return;
  194. }
  195. EnumSelectViewController* enumvc =[[UIStoryboard storyboardWithName:@"CommonEditor" bundle:nil] instantiateViewControllerWithIdentifier:@"EnumSelectorViewController"];
  196. enumvc.delegate = self;
  197. enumvc.max_select = 0;
  198. //enumvc.updatePosition = indexPath;
  199. // if([[required lowercaseString] isEqualToString:@"true"])
  200. // enumvc.canbeEmpty = false;
  201. // else
  202. // enumvc.canbeEmpty =true;
  203. enumvc.cadedate = self.status_cadedate ;
  204. enumvc.title = @"Order Status Selection";
  205. // enumvc.value = [value_json mutableCopy];
  206. enumvc.single_select =false;
  207. [self.navigationController pushViewController:enumvc animated:true];
  208. }
  209. - (void)viewWillAppear:(BOOL)animated
  210. {
  211. [super viewWillAppear:animated];
  212. [self loadfilter];
  213. [[self navigationController] setNavigationBarHidden:!self.showNavibar animated:NO];
  214. // 检查权限
  215. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  216. NSMutableArray *items = [self.toolbarView.items mutableCopy];
  217. if(appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  218. // Check for Saved Order中Type和History Type不一致导致Status不正确
  219. [RASingleton sharedInstance].customer_order_type = self.orderType;
  220. // if (!self.table_order.isEditing) { // 在编辑状态下不能change Type否则显示混乱
  221. // [self changeOrderType:self.orderType];
  222. // }
  223. // 合并订单的权限
  224. if ([RASingleton sharedInstance].permissions_merge_order) { // 能够合并
  225. // 4 6 顺序不能换
  226. if (![items containsObject:self.editOrderListButton]) { // 没显示button
  227. [items insertObject:self.editOrderListButton atIndex:4];
  228. }
  229. self.toolbarView.items = items;
  230. } else { // 不能合并
  231. if ([items containsObject:self.editOrderListButton]) { // 显示button
  232. [items removeObject:self.editOrderListButton];
  233. }
  234. self.toolbarView.items = items;
  235. }
  236. // Check For Saved Order 不能合并
  237. if(self.init_style==OL_OPEN || self.orderType == 1) {
  238. if ([items containsObject:self.editOrderListButton]) { // 显示button
  239. [items removeObject:self.editOrderListButton];
  240. }
  241. self.toolbarView.items = items;
  242. }
  243. } else {
  244. if ([items containsObject:self.editOrderListButton]) { // 显示button
  245. [items removeObject:self.editOrderListButton];
  246. }
  247. self.toolbarView.items = items;
  248. }
  249. // 非Customer用户不用区分Sales Order 和 Shop Order
  250. if (appDelegate.user_type != USER_ROLE_CUSTOMER || (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeCustomer)) {
  251. self.orderTypeSegmentControl.hidden = YES;
  252. [self.view removeConstraint:self.tableTopConstraint];
  253. NSLayoutConstraint *myConstraint =[NSLayoutConstraint
  254. constraintWithItem:self.table_order //item1
  255. attribute:NSLayoutAttributeTop //约束属性
  256. relatedBy:NSLayoutRelationEqual //属性间的关系
  257. toItem:self.label_filter//item2
  258. attribute:NSLayoutAttributeBottom//约束属性
  259. multiplier:1
  260. constant:0.0];// 固定距离
  261. self.tableTopConstraint = myConstraint;
  262. [self.view addConstraint: myConstraint];//为button重新添加一个约束
  263. // NSArray *array =self.table_order.constraints;
  264. // CGRect scframe = CGRectMake(self.orderTypeSegmentControl.frame.origin.x, self.orderTypeSegmentControl.frame.origin.y, self.orderTypeSegmentControl.frame.size.width, 0);
  265. // self.orderTypeSegmentControl.frame = scframe;
  266. CGFloat y = CGRectGetMinY(self.orderTypeSegmentControl.frame);
  267. CGFloat height = CGRectGetHeight(self.orderTypeSegmentControl.frame);
  268. CGRect frame = self.table_order.frame;
  269. if (frame.origin.y != y) {
  270. frame.origin.y = y;
  271. frame.size.height += height;
  272. }
  273. self.table_order.frame = frame;
  274. } else {
  275. self.orderTypeSegmentControl.hidden = NO;
  276. [self.view removeConstraint:self.tableTopConstraint];
  277. NSLayoutConstraint *myConstraint =[NSLayoutConstraint
  278. constraintWithItem:self.table_order //item1
  279. attribute:NSLayoutAttributeTop //约束属性
  280. relatedBy:NSLayoutRelationEqual //属性间的关系
  281. toItem:self.orderTypeSegmentControl//item2
  282. attribute:NSLayoutAttributeBottom//约束属性
  283. multiplier:1
  284. constant:0.0];// 固定距离
  285. self.tableTopConstraint = myConstraint;
  286. [self.view addConstraint: myConstraint];//为button重新添加一个约束
  287. CGFloat y = CGRectGetMinY(self.orderTypeSegmentControl.frame);
  288. CGFloat height = CGRectGetHeight(self.orderTypeSegmentControl.frame);
  289. CGRect frame = self.table_order.frame;
  290. if (frame.origin.y == y) {
  291. frame.origin.y = y + height;
  292. frame.size.height -= height;
  293. }
  294. self.table_order.frame = frame;
  295. }
  296. // 修复Homer显示NPD
  297. if (self.orderTypeSegmentControl.numberOfSegments > 1) {
  298. [self.orderTypeSegmentControl setTitle:[NSString stringWithFormat:@"Purchase Order to %@",COMPANY_SHORT_NAME] forSegmentAtIndex:1];
  299. }
  300. // 显示Sales Order与否
  301. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  302. if ([RASingleton sharedInstance].global_lock || ![RASingleton sharedInstance].customer_can_see_sales_Order) { // 是否解锁,是否有查看Sales Order权限
  303. if (self.orderTypeSegmentControl.numberOfSegments > 1) {
  304. [self.orderTypeSegmentControl removeSegmentAtIndex:1 animated:YES];
  305. [self changeOrderType:0];
  306. }
  307. } else {
  308. if (self.orderTypeSegmentControl.numberOfSegments == 1 && !self.table_order.isEditing) {
  309. [self.orderTypeSegmentControl insertSegmentWithTitle:[NSString stringWithFormat:@"Purchase Order to %@",COMPANY_SHORT_NAME] atIndex:1 animated:YES];
  310. }
  311. }
  312. }
  313. }
  314. - (IBAction)onNewOrderClicked:(id)sender {
  315. NSString* msg=@"Do you want to create a new order?";
  316. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  317. if(appDelegate.order_code.length==0)
  318. {
  319. if(appDelegate.contact_id.length>0)
  320. {
  321. msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  322. msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  323. }
  324. }
  325. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  326. UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  327. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  328. if(appDelegate.order_code && appDelegate.order_code.length>0)
  329. {
  330. // appDelegate.order_code= nil;
  331. // [appDelegate SetSo:nil];
  332. if (appDelegate.user_type == USER_ROLE_EMPLOYEE) {
  333. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  334. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  335. cvc.showNavibar = true;
  336. cvc.contact_type = @"Sales_Order_Customer";
  337. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  338. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  339. appDelegate.customerInfo = value;
  340. self.norefresh = true;
  341. [self neworder];
  342. // [main_vc checklogin:true];
  343. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  344. //
  345. // if(self.returnValue)
  346. // self.returnValue(value);
  347. };
  348. cvc.onCancel = ^(){
  349. self.norefresh = true;
  350. if(appDelegate.customerInfo==nil)
  351. {
  352. [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self];
  353. }
  354. else
  355. {
  356. [self neworder];
  357. }
  358. // [main_vc checklogin:true];
  359. };
  360. cvc.onReset = ^(){
  361. // [main_vc checklogin:true];
  362. };
  363. [self.navigationController pushViewController:cvc animated:true];
  364. }
  365. else if (appDelegate.user_type == USER_ROLE_CUSTOMER){
  366. [self neworder];
  367. }
  368. }
  369. else
  370. {
  371. //create new;
  372. if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  373. {
  374. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  375. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  376. cvc.showNavibar = true;
  377. cvc.contact_type = @"Sales_Order_Customer";
  378. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  379. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  380. appDelegate.customerInfo = value;
  381. if(appDelegate.order_code==nil)
  382. [self neworder];
  383. // [main_vc checklogin:true];
  384. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  385. //
  386. // if(self.returnValue)
  387. // self.returnValue(value);
  388. };
  389. cvc.onCancel = ^(){
  390. [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self];
  391. };
  392. cvc.onReset = ^(){
  393. [main_vc checklogin:true];
  394. };
  395. [self.navigationController pushViewController:cvc animated:true];
  396. }
  397. else
  398. {
  399. [self neworder];
  400. }
  401. }
  402. }];
  403. UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  404. }];
  405. [alertController addAction:action_2];
  406. [alertController addAction:action_3];
  407. [self presentViewController:alertController animated:YES completion:nil];
  408. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Warning", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  409. // [alert show];
  410. }
  411. - (void)didReceiveMemoryWarning {
  412. [super didReceiveMemoryWarning];
  413. // Dispose of any resources that can be recreated.
  414. }
  415. -(void)manually_refresh
  416. {
  417. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201];
  418. if(self.isrefreshing)
  419. {
  420. [reF endRefreshing];
  421. return;
  422. }
  423. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  424. if ([self respondsToSelector:@selector(ReloadData)])
  425. [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
  426. }
  427. -(void)ReloadData
  428. {
  429. // [self.content_data removeAllObjects];
  430. // [self.table_order reloadData];
  431. // self.table_order.hidden = true;
  432. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201];
  433. [reF endRefreshing];
  434. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  435. self.keywords=self.searchbar.text;
  436. // self.offset = 0;
  437. self.reset_result=true;
  438. // [self.content_data removeAllObjects];
  439. // [self.table_order reloadData];
  440. [self loadpage];
  441. // [self loadpage];
  442. }
  443. - (void)operation_loadPage {
  444. if (self.dataOperationQueue.operationCount > 1) { // 队列后面还有操作
  445. return;
  446. }
  447. // dispatch_async(self.loading_queue, ^{
  448. dispatch_sync(dispatch_get_main_queue(), ^{
  449. if(self.reset_result)
  450. {
  451. self.offset = 0;
  452. [self.content_data removeAllObjects];
  453. [self.table_order reloadData];
  454. }
  455. // NSMutableArray* arr_status = [[NSMutableArray alloc] init];
  456. NSMutableArray* arr_statusname = [[NSMutableArray alloc] init];
  457. int count = [[self.status_cadedate valueForKey:@"count"] intValue];
  458. for(int i=0;i<count;i++)
  459. {
  460. NSDictionary* val_json =[self.status_cadedate objectForKey:[NSString stringWithFormat:@"val_%d",i]];
  461. int check = [[val_json valueForKey:@"check"] intValue];
  462. if(check==1)
  463. {
  464. // [arr_status addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value_id"]]];
  465. [arr_statusname addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value"]]];
  466. // break;
  467. }
  468. }
  469. // NSString * str_status = [arr_status componentsJoinedByString:@","];
  470. NSString * str_statusname = [arr_statusname componentsJoinedByString:@","];
  471. if(str_statusname.length==0)
  472. str_statusname = @"All";
  473. self.label_filter.text = str_statusname;
  474. if(self.offset==0)
  475. {
  476. self.table_order.hidden = true;
  477. self.mum.center = self.view.center;
  478. self.mum.hidden = false;
  479. [self.mum startAnimating];
  480. }
  481. self.label_net_err.hidden=true;
  482. });
  483. // });
  484. // dispatch_async(self.loading_queue, ^{
  485. if(self.isrefreshing)
  486. return;
  487. self.isrefreshing=true;
  488. NSMutableArray* arr_status = [[NSMutableArray alloc] init];
  489. // NSMutableArray* arr_statusname = [[NSMutableArray alloc] init];
  490. int count = [[self.status_cadedate valueForKey:@"count"] intValue];
  491. for(int i=0;i<count;i++)
  492. {
  493. NSDictionary* val_json =[self.status_cadedate objectForKey:[NSString stringWithFormat:@"val_%d",i]];
  494. int check = [[val_json valueForKey:@"check"] intValue];
  495. if(check==1)
  496. {
  497. [arr_status addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value_id"]]];
  498. // [arr_statusname addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value"]]];
  499. // break;
  500. }
  501. }
  502. NSString * str_status = [arr_status componentsJoinedByString:@","];
  503. dispatch_sync(dispatch_get_main_queue(), ^{
  504. BOOL isMerged = NO;
  505. AppDelegate *appDelegate = nil;
  506. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  507. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  508. if (self.orderType == 0) {
  509. isMerged = NO;
  510. } else {
  511. isMerged = YES;
  512. }
  513. }
  514. [RANetwork request_orderlist:self.offset limit:self.limit keywords:self.keywords status:str_status customer:self.customer_id is_merged:isMerged completionHandler:^(NSMutableDictionary *result) {
  515. NSMutableDictionary* content=result;
  516. [self.mum stopAnimating];
  517. self.isrefreshing=false;
  518. if (self.dataOperationQueue.operationCount > 1) { // 队列后面还有操作
  519. return ;
  520. }
  521. int result_code=[[content valueForKey:@"result"] intValue];
  522. if(result_code==2||result_code==0)
  523. {
  524. int count = [[content valueForKey:@"count" ] intValue] ;
  525. self.time_zone = [content valueForKey:@"time_zone" ];
  526. self.offset += count;
  527. for(int i=0;i<count;i++)
  528. {
  529. NSDictionary* objmsg = [content objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  530. [self.content_data addObject:[NSMutableDictionary dictionaryWithDictionary:objmsg]];
  531. }
  532. if(count<self.limit)
  533. {
  534. // int i =self.btnrefresh.state;
  535. self.load_more_hint=@"All loaded";
  536. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"no_more", nil);
  537. // [self.btnrefresh setTitle:@"No more" forState:UIControlStateNormal];
  538. }
  539. else
  540. {
  541. self.load_more_hint=@"Load more...";
  542. // self.btnrefresh.enabled = true;
  543. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"load_more",nil);
  544. // [self.btnrefresh setTitle:@"Load more" forState:UIControlStateNormal];
  545. }
  546. self.table_order.hidden = false;
  547. self.reset_result=false;
  548. [self.table_order reloadData ];
  549. }
  550. else if(result_code==RESULT_NET_ERROR &&self.offset==0)
  551. {
  552. self.label_net_err.hidden=false;
  553. self.table_order.hidden = true;
  554. }
  555. else
  556. {
  557. [RAUtils message_alert:[content valueForKey:@"err_msg"] title:@"Loading Order List" controller:self] ;
  558. }
  559. }];
  560. });
  561. //
  562. // NSMutableDictionary* content=nil;
  563. // content=[[RANetwork request_OrderList:self.offset limit : self.limit keywords:self.keywords status:str_status customer:self.customer_id is_merged:isMerged] mutableCopy];
  564. //
  565. //
  566. // dispatch_sync(dispatch_get_main_queue(), ^{
  567. //
  568. //
  569. //
  570. //
  571. //
  572. // [self.mum stopAnimating];
  573. // self.isrefreshing=false;
  574. // if (self.dataOperationQueue.operationCount > 1) { // 队列后面还有操作
  575. // return ;
  576. // }
  577. // int result=[[content valueForKey:@"result"] intValue];
  578. //
  579. // if(result==2||result==0)
  580. // {
  581. //
  582. //
  583. // int count = [[content valueForKey:@"count" ] intValue] ;
  584. //
  585. //
  586. // self.time_zone = [content valueForKey:@"time_zone" ];
  587. // self.offset += count;
  588. // for(int i=0;i<count;i++)
  589. // {
  590. //
  591. // NSDictionary* objmsg = [content objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  592. // [self.content_data addObject:[NSMutableDictionary dictionaryWithDictionary:objmsg]];
  593. //
  594. // }
  595. // if(count<self.limit)
  596. // {
  597. //
  598. // // int i =self.btnrefresh.state;
  599. // self.load_more_hint=@"All loaded";
  600. // // self.btnrefresh.titleLabel.text =NSLocalizedString(@"no_more", nil);
  601. // // [self.btnrefresh setTitle:@"No more" forState:UIControlStateNormal];
  602. // }
  603. // else
  604. // {
  605. // self.load_more_hint=@"Load more...";
  606. // // self.btnrefresh.enabled = true;
  607. // // self.btnrefresh.titleLabel.text =NSLocalizedString(@"load_more",nil);
  608. // // [self.btnrefresh setTitle:@"Load more" forState:UIControlStateNormal];
  609. // }
  610. //
  611. //
  612. // self.table_order.hidden = false;
  613. // self.reset_result=false;
  614. // [self.table_order reloadData ];
  615. // }
  616. // else if(result==RESULT_NET_ERROR &&self.offset==0)
  617. // {
  618. // self.label_net_err.hidden=false;
  619. // self.table_order.hidden = true;
  620. // }
  621. // else
  622. // {
  623. // [RAUtils message_alert:[content valueForKey:@"err_msg"] title:@"Loading Order List" controller:self] ;
  624. // }
  625. //
  626. //
  627. //
  628. //
  629. // });
  630. //
  631. // });
  632. }
  633. -(void) loadpage
  634. {
  635. __weak typeof(self) weakself = self;
  636. NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
  637. if (weakself) {
  638. __strong typeof(weakself) strongself = weakself;
  639. [strongself operation_loadPage];
  640. }
  641. }];
  642. [self.dataOperationQueue addOperation:operation];
  643. }
  644. - (void)loadmore
  645. {
  646. // self.btnrefresh.enabled = NO;
  647. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"loading",nil);
  648. // [self.btnrefresh setTitle:@"Loading..." forState:UIControlStateNormal];
  649. [self loadpage];
  650. }
  651. //-(void)changeCell
  652. //{
  653. //// UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  654. //// reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"refreshing"];
  655. // [self performSelector:@selector(loadmore) withObject:nil afterDelay:1];
  656. // DebugLog(@"refresh!!!!!!!!");
  657. //
  658. //}
  659. -(void) neworder
  660. {
  661. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order" completion:^{
  662. [RANetwork request_create_order:^(NSMutableDictionary *result) {
  663. NSMutableDictionary* return_json =result;
  664. [waitalert dismissViewControllerAnimated:YES completion:^{
  665. if([[return_json valueForKey:@"result"] intValue]==2)
  666. {
  667. int result=[[return_json valueForKey:@"result"] intValue];
  668. if(result==2)
  669. {
  670. //successed.
  671. NSString* order_code = [return_json valueForKey:@"orderCode"];
  672. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  673. appDelegate.order_code = order_code;
  674. appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  675. #ifdef RA_NOTIFICATION
  676. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  677. #else
  678. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  679. [main_vc reloadCart:true immediately:false];
  680. #endif
  681. [self ReloadData];
  682. // [self performSelector:@selector(loadpage) withObject:nil afterDelay:1];
  683. // [self loadpage];
  684. // if(self.shopCartBlock!=nil)
  685. // {
  686. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  687. //
  688. //
  689. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  690. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  691. // iv.image = img;
  692. // // [self.contentView addSubview:iv];
  693. // self.shopCartBlock(iv);
  694. //
  695. // }
  696. }
  697. }
  698. else
  699. {
  700. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Create Order" controller:self] ;
  701. }
  702. }];
  703. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  704. }];
  705. }];
  706. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  707. //
  708. // NSDictionary* return_json = [RANetwork new_Order];
  709. //
  710. // dispatch_async(dispatch_get_main_queue(), ^{
  711. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  712. //
  713. //
  714. // if([[return_json valueForKey:@"result"] intValue]==2)
  715. // {
  716. // int result=[[return_json valueForKey:@"result"] intValue];
  717. // if(result==2)
  718. // {
  719. // //successed.
  720. //
  721. // NSString* order_code = [return_json valueForKey:@"orderCode"];
  722. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  723. // appDelegate.order_code = order_code;
  724. // appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  725. //
  726. //
  727. //#ifdef RA_NOTIFICATION
  728. // [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  729. //#else
  730. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  731. // [main_vc reloadCart:true immediately:false];
  732. //#endif
  733. //
  734. // [self ReloadData];
  735. //
  736. //
  737. // // [self performSelector:@selector(loadpage) withObject:nil afterDelay:1];
  738. // // [self loadpage];
  739. //
  740. //
  741. // // if(self.shopCartBlock!=nil)
  742. // // {
  743. // // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  744. // //
  745. // //
  746. // // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  747. // // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  748. // // iv.image = img;
  749. // // // [self.contentView addSubview:iv];
  750. // // self.shopCartBlock(iv);
  751. // //
  752. // // }
  753. //
  754. // }
  755. // }
  756. // else
  757. // {
  758. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Create Order" controller:self] ;
  759. // }
  760. //
  761. //
  762. //
  763. //
  764. // });
  765. // });
  766. }
  767. //#pragma mark - UIAlertViewDelegate
  768. //// Called when a button is clicked. The view will be automatically dismissed after this call returns
  769. //- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  770. //{
  771. // if(buttonIndex!=alertView.cancelButtonIndex)
  772. // {
  773. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  774. //
  775. // if(appDelegate.order_code && appDelegate.order_code.length>0)
  776. // {
  777. //// appDelegate.order_code= nil;
  778. //// [appDelegate SetSo:nil];
  779. //
  780. // if (appDelegate.user_type == USER_ROLE_EMPLOYEE) {
  781. // // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  782. // ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  783. // cvc.showNavibar = true;
  784. // cvc.contact_type = @"Sales_Order_Customer";
  785. // cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  786. //
  787. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  788. // appDelegate.customerInfo = value;
  789. //
  790. // self.norefresh = true;
  791. // [self neworder];
  792. //
  793. //
  794. //
  795. // // [main_vc checklogin:true];
  796. // // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  797. //
  798. // //
  799. // // if(self.returnValue)
  800. // // self.returnValue(value);
  801. // };
  802. //
  803. // cvc.onCancel = ^(){
  804. // self.norefresh = true;
  805. // if(appDelegate.customerInfo==nil)
  806. // {
  807. // [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self];
  808. // }
  809. // else
  810. // {
  811. // [self neworder];
  812. // }
  813. // // [main_vc checklogin:true];
  814. // };
  815. // cvc.onReset = ^(){
  816. // // [main_vc checklogin:true];
  817. // };
  818. //
  819. // [self.navigationController pushViewController:cvc animated:true];
  820. // }
  821. // else if (appDelegate.user_type == USER_ROLE_CUSTOMER){
  822. // [self neworder];
  823. // }
  824. //
  825. // }
  826. // else
  827. // {
  828. // //create new;
  829. //
  830. // if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  831. // {
  832. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  833. // ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  834. // cvc.showNavibar = true;
  835. // cvc.contact_type = @"Sales_Order_Customer";
  836. // cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  837. //
  838. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  839. // appDelegate.customerInfo = value;
  840. //
  841. //
  842. // if(appDelegate.order_code==nil)
  843. // [self neworder];
  844. //
  845. // // [main_vc checklogin:true];
  846. // // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  847. //
  848. // //
  849. // // if(self.returnValue)
  850. // // self.returnValue(value);
  851. // };
  852. //
  853. // cvc.onCancel = ^(){
  854. //
  855. // [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self];
  856. //
  857. //
  858. //
  859. // };
  860. // cvc.onReset = ^(){
  861. // [main_vc checklogin:true];
  862. // };
  863. //
  864. // [self.navigationController pushViewController:cvc animated:true];
  865. // }
  866. // else
  867. // {
  868. // [self neworder];
  869. // }
  870. // }
  871. //
  872. // }
  873. //}
  874. #pragma mark - Table view data source
  875. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  876. {
  877. return 66;
  878. }
  879. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  880. //{
  881. // return 0;
  882. //}
  883. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  884. //{
  885. // return 0;
  886. //}
  887. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  888. //{
  889. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  890. // return myView;
  891. //
  892. //}
  893. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  894. {
  895. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  896. if(value==nil)
  897. value=@"";
  898. unsigned long color = strtoul([value UTF8String],0,16);
  899. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  900. // myView.backgroundColor = UIColorFromRGB(0x996633);
  901. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  902. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  903. myView.layer.shadowOffset = CGSizeMake(0, 0);
  904. myView.layer.shadowOpacity = 0.5;
  905. myView.layer.shadowRadius = 2.0;
  906. UILabel *statuslabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 2, 130, 22)];
  907. statuslabel.textColor=UIColorFromRGB(color);
  908. statuslabel.backgroundColor = [UIColor clearColor];
  909. statuslabel.text=NSLocalizedString(@"Status", nil);
  910. [statuslabel sizeToFit];
  911. [myView addSubview:statuslabel];
  912. UILabel *solabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 21, 130, 22)];
  913. solabel.textColor=UIColorFromRGB(color);
  914. solabel.backgroundColor = [UIColor clearColor];
  915. solabel.text=NSLocalizedString(@"SO#", nil);
  916. [solabel sizeToFit];
  917. [myView addSubview:solabel];
  918. UILabel *userlabel = [[UILabel alloc] initWithFrame:CGRectMake(165, 21, 125, 22)];
  919. userlabel.textColor=UIColorFromRGB(color);
  920. userlabel.backgroundColor = [UIColor clearColor];
  921. userlabel.text=NSLocalizedString(@"Sales rep", nil);
  922. [userlabel sizeToFit];
  923. [myView addSubview:userlabel];
  924. UILabel *creatorlabel = [[UILabel alloc] initWithFrame:CGRectMake(165, 2, 125, 22)];
  925. creatorlabel.textColor=UIColorFromRGB(color);
  926. creatorlabel.backgroundColor = [UIColor clearColor];
  927. creatorlabel.text=NSLocalizedString(@"Create by", nil);
  928. [creatorlabel sizeToFit];
  929. [myView addSubview:creatorlabel];
  930. UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(296, 11, 150, 22)];
  931. contactlabel.textColor=UIColorFromRGB(color);
  932. contactlabel.backgroundColor = [UIColor clearColor];
  933. contactlabel.text=NSLocalizedString(@"Contact", nil);
  934. [contactlabel sizeToFit];
  935. [myView addSubview:contactlabel];
  936. //
  937. // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(424, 11, 52, 22)];
  938. // modellabel.textColor=[UIColor whiteColor];
  939. // modellabel.backgroundColor = [UIColor clearColor];
  940. // modellabel.text=NSLocalizedString(@"Model", nil);
  941. // [modellabel sizeToFit];
  942. // [myView addSubview:modellabel];
  943. // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(self.table_order.frame.size.width-276, 2, 100, 22)];
  944. // modellabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  945. // modellabel.textColor=[UIColor whiteColor];
  946. // modellabel.backgroundColor = [UIColor clearColor];
  947. // modellabel.text=NSLocalizedString(@"Items/QTY", nil);
  948. // [modellabel sizeToFit];
  949. // [myView addSubview:modellabel];
  950. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  951. UILabel *pricelabel = nil;
  952. if(appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && self.orderType==1)
  953. pricelabel=[[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.table_order.frame.size.width-276, 2, 100, 22)];
  954. else
  955. pricelabel=[[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.table_order.frame.size.width-276, 11, 100, 22)];
  956. pricelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  957. pricelabel.textColor=UIColorFromRGB(color);
  958. pricelabel.backgroundColor = [UIColor clearColor];
  959. pricelabel.text=NSLocalizedString(@"Order Total", nil);
  960. [pricelabel sizeToFit];
  961. [myView addSubview:pricelabel];
  962. if(appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && self.orderType==1)
  963. {
  964. UILabel *polabel = nil;
  965. polabel=[[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.table_order.frame.size.width-276, 21, 100, 22)];
  966. polabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  967. polabel.textColor=UIColorFromRGB(color);
  968. polabel.backgroundColor = [UIColor clearColor];
  969. polabel.text=NSLocalizedString(@"PO#", nil);
  970. [polabel sizeToFit];
  971. [myView addSubview:polabel];
  972. }
  973. UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(self.table_order.frame.size.width-163/*605*/,11, 148, 22)];
  974. timelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  975. timelabel.textColor=UIColorFromRGB(color);
  976. timelabel.backgroundColor = [UIColor clearColor];
  977. if(self.time_zone==nil)
  978. timelabel.text=@"Create time";
  979. else
  980. timelabel.text=[NSString stringWithFormat:@"Create time (%@)",self.time_zone];
  981. [timelabel sizeToFit];
  982. [myView addSubview:timelabel];
  983. myView.autoresizesSubviews=true;
  984. // [myView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin];
  985. // modellabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  986. // pricelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  987. // timelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  988. myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  989. //
  990. return myView;
  991. }
  992. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  993. {
  994. return 44;
  995. }
  996. //
  997. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  998. // if(section==0)
  999. // return nil;
  1000. // else
  1001. // return @"detail section";
  1002. //}
  1003. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  1004. {
  1005. return 1;
  1006. }
  1007. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  1008. {
  1009. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  1010. if( self.content_data.count==0)
  1011. return 0;
  1012. return self.content_data.count+1;
  1013. }
  1014. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  1015. {
  1016. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1017. // if(tableView==self.itemListTable)
  1018. // {
  1019. // if(indexPath.row>self.content_data.count)
  1020. // {
  1021. // int debug=true;
  1022. // }
  1023. // DebugLog(@"row %ld",(long)indexPath.row);
  1024. if(indexPath.row==self.content_data.count)
  1025. {
  1026. UITableViewCell *moreCell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"mores"];
  1027. UILabel *moreDataLabel=[[UILabel alloc] init];
  1028. moreDataLabel.tag=200;
  1029. moreDataLabel.text=self.load_more_hint;
  1030. [moreDataLabel setFont:[UIFont systemFontOfSize:14.0f]];
  1031. [moreDataLabel setTextAlignment:NSTextAlignmentCenter];
  1032. moreDataLabel.frame=CGRectMake(0, 10, self.table_order.bounds.size.width, 20);
  1033. [moreDataLabel setBackgroundColor:[UIColor clearColor]];
  1034. moreDataLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
  1035. // [moreDataLabel addTarget:self action:@selector(changeCell) forControlEvents:UIControlEventValueChanged];
  1036. [moreCell.contentView addSubview:moreDataLabel];
  1037. if([self.load_more_hint isEqualToString:@"Load more..."])
  1038. [self performSelector:@selector(loadmore) withObject:nil afterDelay:1];
  1039. // DebugLog(@"更多...");
  1040. moreCell.backgroundColor = [UIColor whiteColor];
  1041. return moreCell;
  1042. }
  1043. else
  1044. {
  1045. NSString *CellIdentifier = @"OrderListTableViewCell";
  1046. OrderListTableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1047. NSString* so= [self.content_data[indexPath.row] valueForKey:@"so#"];
  1048. NSString* price= [self.content_data[indexPath.row] valueForKey:@"price"];
  1049. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  1050. {
  1051. }
  1052. else
  1053. {
  1054. price=nil;
  1055. }
  1056. NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue];
  1057. NSString* purchase_time= [self.content_data[indexPath.row] valueForKey:@"purchase_time"];
  1058. NSString* status = [self.content_data[indexPath.row] valueForKey:@"order_status"] ;
  1059. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1060. status = [ERPUtils orderStatus:statusCode];
  1061. }
  1062. NSString* customer_name = [self.content_data[indexPath.row] valueForKey:@"customer_name"];
  1063. NSString* model_count = [self.content_data[indexPath.row] valueForKey:@"model_count"];
  1064. NSString* sales = [self.content_data[indexPath.row] valueForKey:@"sales_rep"];
  1065. NSString* creator = [self.content_data[indexPath.row] valueForKey:@"create_by"];
  1066. NSString *po = [self.content_data[indexPath.row] valueForKey:@"po_id"];
  1067. CGRect price_frame = cell.labelprice.frame;
  1068. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && self.orderType == 1) {
  1069. cell.label_po.hidden = NO;
  1070. price_frame.origin.y = 5;
  1071. cell.label_po.text = po;
  1072. } else {
  1073. cell.label_po.hidden = YES;
  1074. price_frame.origin.y = 21;
  1075. }
  1076. cell.labelprice.frame = price_frame;
  1077. cell.label_so.text=so;
  1078. cell.labelprice.text=price;
  1079. cell.label_date.text=purchase_time;
  1080. cell.label_contact.text=customer_name;
  1081. cell.label_model.text = model_count;
  1082. cell.label_sales.text = sales;
  1083. cell.label_creator.text = creator;
  1084. cell.label_status.text=status;
  1085. cell.backgroundColor = [UIColor whiteColor];
  1086. return cell;
  1087. }
  1088. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1089. // NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  1090. // cell.bundle_item=combine_json;
  1091. // NSString* img_url = [item_json valueForKey:@"img_url"];
  1092. // NSString* description = [item_json valueForKey:@"description"];
  1093. // // NSString* identifier = [item_json valueForKey:@"identifier"];
  1094. // // NSString* attribute = [item_json valueForKey:@"attribute"];
  1095. // NSString* currency = [item_json valueForKey:@"currency"];
  1096. // int count =[[item_json valueForKey:@"count"] intValue];
  1097. // double price =[[item_json valueForKey:@"price"] doubleValue];
  1098. // // cell.labelAttribute.text = attribute;
  1099. // cell.labelCurrency.text = currency;
  1100. // cell.labelDescription.text = description;
  1101. // // cell.labelIdentifier.text = identifier;
  1102. // cell.labelPrice.text = [NSString stringWithFormat:@"%.2f",price];
  1103. //
  1104. //
  1105. //
  1106. // [cell set_Count:count];
  1107. // NSString* file_name=[img_url lastPathComponent];
  1108. // NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  1109. // if(img_data!=nil)
  1110. // {
  1111. //
  1112. // UIImage * img =[UIImage imageWithData:img_data];
  1113. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  1114. // }
  1115. // else
  1116. // {
  1117. //
  1118. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1119. //
  1120. // NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1121. //
  1122. // dispatch_async(dispatch_get_main_queue(), ^{
  1123. //
  1124. //
  1125. //
  1126. // if(downloadimg_data!=nil)
  1127. // {
  1128. // [iSalesDB cache_img:downloadimg_data :file_name ];
  1129. //
  1130. // UIImage * img =[UIImage imageWithData:downloadimg_data];
  1131. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  1132. // }
  1133. //
  1134. // });
  1135. // });
  1136. //
  1137. //
  1138. // }
  1139. // }
  1140. // else
  1141. // {
  1142. // NSString *CellIdentifier = @"OrderInfoListItem";
  1143. // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1144. // return cell;
  1145. // }
  1146. }
  1147. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  1148. {
  1149. if (tableView.isEditing) { // 编辑模式下不响应
  1150. return;
  1151. }
  1152. //
  1153. if(indexPath.row==self.content_data.count)
  1154. return;
  1155. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1156. if(appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) { // Customer
  1157. if ([RASingleton sharedInstance].global_lock) { // Order list 被锁
  1158. [RAUtils message_alert:@"Permission Needed.\nGoto Menu -> Unlock" title:@"Warning" controller:self];
  1159. return;
  1160. }
  1161. }
  1162. NSString* orderid= [self.content_data[indexPath.row] valueForKey:@"order_id"];
  1163. OrderDetailViewController* dvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderDetailViewController" ];
  1164. // int i =[[self.content_data[indexPath.row] valueForKey:@"order_code"];
  1165. dvc.selectOrder=^(NSMutableDictionary* order_detail){
  1166. [self.navigationController popViewControllerAnimated:false];
  1167. if(self.selectOrder)
  1168. self.selectOrder(order_detail);
  1169. };
  1170. NSString* order_code =[self.content_data[indexPath.row] valueForKey:@"order_code"];
  1171. NSString *erpSerialNo = [self.content_data[indexPath.row] valueForKey:@"erp_order_serial_no"];
  1172. dvc.erpSerialNo = erpSerialNo;
  1173. dvc.is_shoporder=(self.orderType == 0);
  1174. dvc.order_code = order_code;
  1175. dvc.order_status =[[self.content_data[indexPath.row] valueForKey:@"orderStatus"] intValue];
  1176. // bool temp_order = false ;
  1177. // NSString* order_status=[self.content_data[indexPath.row] valueForKey:@"order_status"];
  1178. // if([order_status isEqualToString:@"Saved"]||[order_status isEqualToString:@"Quoted"])
  1179. // temp_order=true;
  1180. //
  1181. // dvc.isTempOrder = temp_order;
  1182. // dvc
  1183. dvc.orderid=orderid;
  1184. // dvc.category_id=nil;
  1185. // dvc.ispush=true;
  1186. // [dvc reload];
  1187. [self.navigationController pushViewController:dvc animated:true];
  1188. }
  1189. #pragma mark - searchBar delegate;
  1190. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
  1191. {
  1192. self.keywords=searchBar.text;
  1193. // self.offset = 0;
  1194. // [self.content_data removeAllObjects];
  1195. self.reset_result=true;
  1196. [self loadpage];
  1197. }
  1198. - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
  1199. {
  1200. if([searchText isEqualToString:@""] && !self.reset)
  1201. {
  1202. DebugLog(@"clear");
  1203. self.reset=true;
  1204. self.keywords=nil;
  1205. // self.offset = 0;
  1206. // [self.content_data removeAllObjects];
  1207. self.reset_result=true;
  1208. [self loadpage];
  1209. }
  1210. else
  1211. self.reset = false;
  1212. }
  1213. #pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮
  1214. - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
  1215. {
  1216. // 添加一个删除按钮
  1217. // self.indexPath=indexPath;
  1218. if(indexPath.row==self.content_data.count)
  1219. return @[];
  1220. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1221. NSString* so= [self.content_data[indexPath.row] valueForKey:@"so#"];
  1222. NSString* orderid= [self.content_data[indexPath.row] valueForKey:@"order_id"];
  1223. // NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"];
  1224. NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue];
  1225. if(appDelegate.user_type==USER_ROLE_EMPLOYEE || (appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeCustomer)) {
  1226. UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1227. DebugLog(@"delete click");
  1228. NSString * title =[NSString stringWithFormat:@"Are you sure to delete order SO#: %@",so];
  1229. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
  1230. //block代码块取代了delegate
  1231. // [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  1232. // textField.text = self.save_name;
  1233. //
  1234. //
  1235. // }];
  1236. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1237. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Delete Order" completion:^{
  1238. [RANetwork request_delete_order:orderid completionHandler:^(NSMutableDictionary *result) {
  1239. NSDictionary* return_json = result;
  1240. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1241. [waitalert dismissViewControllerAnimated:YES completion:^{
  1242. if([[return_json valueForKey:@"result"] intValue]==2)
  1243. {
  1244. if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
  1245. {
  1246. appDelegate.order_code= nil;
  1247. [appDelegate SetSo:nil];
  1248. appDelegate.cart_count=0;
  1249. [appDelegate update_count_mark];
  1250. // appDelegate.customerInfo = nil;
  1251. // appDelegate.contact_id = nil;
  1252. // appDelegate.order_customer_id = nil;
  1253. }
  1254. [RAUtils message_alert:nil title:@"Order Delete" controller:self] ;
  1255. [self ReloadData];
  1256. }
  1257. else
  1258. {
  1259. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Delete Order" controller:self] ;
  1260. }
  1261. }];
  1262. }];
  1263. }];
  1264. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1265. //
  1266. // NSDictionary* return_json = [RANetwork delete_Order:orderid];
  1267. //
  1268. // dispatch_async(dispatch_get_main_queue(), ^{
  1269. //// [waitalert dismissViewControllerAnimated:YES completion:nil];
  1270. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1271. //
  1272. //
  1273. // if([[return_json valueForKey:@"result"] intValue]==2)
  1274. // {
  1275. // if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
  1276. // {
  1277. // appDelegate.order_code= nil;
  1278. // [appDelegate SetSo:nil];
  1279. //
  1280. //
  1281. // appDelegate.cart_count=0;
  1282. // [appDelegate update_count_mark];
  1283. //
  1284. //// appDelegate.customerInfo = nil;
  1285. //// appDelegate.contact_id = nil;
  1286. //// appDelegate.order_customer_id = nil;
  1287. // }
  1288. //
  1289. // [RAUtils message_alert:nil title:@"Order Delete" controller:self] ;
  1290. // [self ReloadData];
  1291. // }
  1292. // else
  1293. // {
  1294. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Delete Order" controller:self] ;
  1295. // }
  1296. //
  1297. //
  1298. //
  1299. //
  1300. // });
  1301. // });
  1302. }];
  1303. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1304. DebugLog(@"Cancel");
  1305. }];
  1306. [alertControl addAction:actionOne];
  1307. [alertControl addAction:alertthree];
  1308. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1309. [self presentViewController:alertControl animated:YES completion:nil];
  1310. }];
  1311. deleteRowAction.backgroundColor = UIColorFromRGB(0x336699);
  1312. // 添加一个编辑按钮
  1313. UITableViewRowAction *cancelAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Cancel Order"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1314. DebugLog(@"edit click");
  1315. NSString * title =[NSString stringWithFormat:@"Are you sure to cancel order SO#: %@",so];
  1316. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
  1317. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1318. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Cancel Order" completion:^{
  1319. [RANetwork request_cancel_order:orderid order_code:nil completionHandler:^(NSMutableDictionary *result) {
  1320. NSDictionary* return_json = result;
  1321. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1322. [waitalert dismissViewControllerAnimated:YES completion:^{
  1323. if([[return_json valueForKey:@"result"] intValue]==2)
  1324. {
  1325. if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
  1326. {
  1327. appDelegate.order_code= nil;
  1328. //appDelegate.user_type = 0;
  1329. appDelegate.customerInfo = nil;
  1330. appDelegate.contact_id = nil;
  1331. appDelegate.order_customer_id = nil;
  1332. [appDelegate SetSo:nil];
  1333. appDelegate.cart_count=0;
  1334. [appDelegate update_count_mark];
  1335. }
  1336. [RAUtils message_alert:nil title:@"Order Canceled" controller:self] ;
  1337. [self ReloadData];
  1338. }
  1339. else
  1340. {
  1341. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Cancel Order" controller:self] ;
  1342. }
  1343. }];
  1344. }];
  1345. }];
  1346. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1347. //
  1348. // NSDictionary* return_json = [RANetwork cancel_Order:orderid order_code:nil];
  1349. //
  1350. // dispatch_async(dispatch_get_main_queue(), ^{
  1351. //// [waitalert dismissViewControllerAnimated:YES completion:nil];
  1352. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1353. //
  1354. //
  1355. //
  1356. // if([[return_json valueForKey:@"result"] intValue]==2)
  1357. // {
  1358. // if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
  1359. // {
  1360. // appDelegate.order_code= nil;
  1361. // //appDelegate.user_type = 0;
  1362. // appDelegate.customerInfo = nil;
  1363. // appDelegate.contact_id = nil;
  1364. // appDelegate.order_customer_id = nil;
  1365. // [appDelegate SetSo:nil];
  1366. // appDelegate.cart_count=0;
  1367. // [appDelegate update_count_mark];
  1368. //
  1369. //
  1370. // }
  1371. // [RAUtils message_alert:nil title:@"Order Canceled" controller:self] ;
  1372. // [self ReloadData];
  1373. // }
  1374. // else
  1375. // {
  1376. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Cancel Order" controller:self] ;
  1377. // }
  1378. //
  1379. //
  1380. //
  1381. //
  1382. // });
  1383. // });
  1384. }];
  1385. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1386. DebugLog(@"Cancel");
  1387. }];
  1388. [alertControl addAction:actionOne];
  1389. [alertControl addAction:alertthree];
  1390. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1391. [self presentViewController:alertControl animated:YES completion:nil];
  1392. //
  1393. }];
  1394. cancelAction.backgroundColor = UIColorFromRGB(0xff9933);
  1395. if(/*[order_status isEqualToString:@"Saved Order"]*/statusCode == 1&&appDelegate.can_cancel_order)
  1396. return @[cancelAction];
  1397. else
  1398. {
  1399. if(/*[order_status isEqualToString:@"Quote Saved"]*/statusCode == 0)
  1400. {
  1401. NSMutableArray* arr=[@[] mutableCopy];
  1402. if(appDelegate.can_delete_order)
  1403. [arr addObject:deleteRowAction];
  1404. if(appDelegate.can_cancel_order)
  1405. [arr addObject:cancelAction];
  1406. return arr;
  1407. }
  1408. }
  1409. } else if (appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1410. // UITableViewRowAction *add2MergeListAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Add To Combine List" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  1411. //
  1412. // NSString *orderCode = [NSString stringWithFormat:@"%@",[self.content_data[indexPath.row] valueForKey:@"order_code"]];
  1413. //
  1414. //
  1415. // NSString *create_by = [self.content_data[indexPath.row] valueForKey:@"create_by"];
  1416. // NSString *create_time = [self.content_data[indexPath.row] valueForKey:@"purchase_time"];
  1417. //
  1418. // __block BOOL contain = NO;
  1419. // [self.mergeList enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  1420. //
  1421. // NSString *so_id = [(NSDictionary *)obj objectForKey:@"so_id"];
  1422. // if ([so_id isEqualToString:so]) {
  1423. //
  1424. // contain = YES;
  1425. //
  1426. // *stop = YES;
  1427. // }
  1428. //
  1429. // }]; // 避免重复添加
  1430. //
  1431. //
  1432. // if (!contain) {
  1433. //
  1434. // __block BOOL closeOrder = NO;
  1435. // // 检查是否被自己打开
  1436. // if ([orderCode isEqualToString:appDelegate.order_code]) {
  1437. //
  1438. // UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:@"can not add to combine list because current order is opened. Do you want to close order and add to combine list?" preferredStyle:UIAlertControllerStyleAlert];
  1439. //
  1440. // UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1441. //
  1442. // closeOrder = NO;
  1443. // [alertVC dismissViewControllerAnimated:YES completion:nil];
  1444. //
  1445. // }];
  1446. //
  1447. // UIAlertAction *closeOrderAction = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1448. //
  1449. //
  1450. // [alertVC dismissViewControllerAnimated:YES completion:nil];
  1451. // // 关闭订单
  1452. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order"];
  1453. // NSDictionary* order_json = [iSalesNetwork release_Order:orderCode];
  1454. //
  1455. // dispatch_async(dispatch_get_main_queue(), ^{
  1456. //
  1457. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1458. // if([[order_json valueForKey:@"result"] intValue]==2)
  1459. // {
  1460. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1461. //
  1462. // [appDelegate closeOrder];
  1463. // closeOrder = YES;
  1464. //
  1465. // // 锁订单/检查是否被别人锁定
  1466. // NSDictionary *lock_dic = [iSalesNetwork lock_order:orderCode]; // 和open一样,只不过不用更新car count
  1467. //
  1468. //
  1469. // if ([[lock_dic objectForKey:@"result"] integerValue] == RESULT_TRUE) {
  1470. //
  1471. // NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  1472. //
  1473. // [dic setValue:orderid forKey:@"order_id"];
  1474. // [dic setValue:so forKey:@"so_id"];
  1475. // [dic setValue:create_by forKey:@"create_by"];
  1476. // [dic setValue:create_time forKey:@"create_time"];
  1477. // [dic setValue:[NSNumber numberWithInteger:0] forKey:@"check"]; // 合并到
  1478. //
  1479. // [self.mergeList addObject:dic];
  1480. //
  1481. // } else {
  1482. //
  1483. // [RAUtils message_alert:[lock_dic objectForKey:@"err_msg"] title:@"Warning" controller:self];
  1484. //
  1485. // }
  1486. //
  1487. //
  1488. // }
  1489. // else
  1490. // {
  1491. // closeOrder = NO;
  1492. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Release Order" controller:self] ;
  1493. // }
  1494. //
  1495. //
  1496. //
  1497. // });
  1498. //
  1499. //
  1500. //
  1501. // }];
  1502. //
  1503. // [alertVC addAction:cancelAction];
  1504. // [alertVC addAction:closeOrderAction];
  1505. //
  1506. // [self presentViewController:alertVC animated:YES completion:nil];
  1507. //
  1508. // } else {
  1509. //
  1510. // closeOrder = YES;
  1511. // // 锁订单/检查是否被别人锁定
  1512. // NSDictionary *lock_dic = [iSalesNetwork lock_order:orderCode]; // 和open一样,只不过不用更新car count
  1513. //
  1514. // if ([[lock_dic objectForKey:@"result"] integerValue] == RESULT_TRUE) {
  1515. //
  1516. // NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  1517. //
  1518. // [dic setValue:orderid forKey:@"order_id"];
  1519. // [dic setValue:so forKey:@"so_id"];
  1520. // [dic setValue:create_by forKey:@"create_by"];
  1521. // [dic setValue:create_time forKey:@"create_time"];
  1522. // [dic setValue:[NSNumber numberWithInteger:0] forKey:@"check"]; // 合并到
  1523. //
  1524. // [self.mergeList addObject:dic];
  1525. //
  1526. // } else {
  1527. //
  1528. // [RAUtils message_alert:[lock_dic objectForKey:@"err_msg"] title:@"Warning" controller:self];
  1529. //
  1530. // }
  1531. // }
  1532. //
  1533. // }
  1534. //
  1535. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationFade];
  1536. //
  1537. // DebugLog(@"%@",self.mergeList);
  1538. //
  1539. // }];
  1540. // add2MergeListAction.backgroundColor = UIColorFromRGB(0x336699);
  1541. // Cancel Order Action
  1542. UITableViewRowAction *cancelAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Cancel Order"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1543. DebugLog(@"edit click");
  1544. NSString * title =[NSString stringWithFormat:@"Are you sure to cancel order SO#: %@",so];
  1545. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
  1546. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1547. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Cancel Order" completion:^{
  1548. [RANetwork request_cancel_order:orderid order_code:nil completionHandler:^(NSMutableDictionary *result) {
  1549. NSDictionary* return_json =result;
  1550. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1551. [waitalert dismissViewControllerAnimated:YES completion:^{
  1552. if([[return_json valueForKey:@"result"] intValue]==2)
  1553. {
  1554. if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
  1555. {
  1556. appDelegate.order_code= nil;
  1557. //appDelegate.user_type = 0;
  1558. appDelegate.customerInfo = nil;
  1559. appDelegate.contact_id = nil;
  1560. appDelegate.order_customer_id = nil;
  1561. [appDelegate SetSo:nil];
  1562. appDelegate.cart_count=0;
  1563. [appDelegate update_count_mark];
  1564. }
  1565. [RAUtils message_alert:nil title:@"Order Canceled" controller:self] ;
  1566. [self ReloadData];
  1567. }
  1568. else
  1569. {
  1570. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Cancel Order" controller:self] ;
  1571. }
  1572. }];
  1573. }];
  1574. }];
  1575. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1576. //
  1577. // NSDictionary* return_json = [RANetwork cancel_Order:orderid order_code:nil];
  1578. //
  1579. // dispatch_async(dispatch_get_main_queue(), ^{
  1580. //// [waitalert dismissViewControllerAnimated:YES completion:nil];
  1581. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1582. //
  1583. //
  1584. // if([[return_json valueForKey:@"result"] intValue]==2)
  1585. // {
  1586. // if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
  1587. // {
  1588. // appDelegate.order_code= nil;
  1589. // //appDelegate.user_type = 0;
  1590. // appDelegate.customerInfo = nil;
  1591. // appDelegate.contact_id = nil;
  1592. // appDelegate.order_customer_id = nil;
  1593. // [appDelegate SetSo:nil];
  1594. // appDelegate.cart_count=0;
  1595. // [appDelegate update_count_mark];
  1596. //
  1597. //
  1598. // }
  1599. // [RAUtils message_alert:nil title:@"Order Canceled" controller:self] ;
  1600. // [self ReloadData];
  1601. // }
  1602. // else
  1603. // {
  1604. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Cancel Order" controller:self] ;
  1605. // }
  1606. //
  1607. //
  1608. //
  1609. //
  1610. // });
  1611. // });
  1612. }];
  1613. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1614. DebugLog(@"Cancel");
  1615. }];
  1616. [alertControl addAction:actionOne];
  1617. [alertControl addAction:alertthree];
  1618. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1619. [self presentViewController:alertControl animated:YES completion:nil];
  1620. //
  1621. }];
  1622. cancelAction.backgroundColor = UIColorFromRGB(0xff9933);
  1623. NSMutableArray *actionArr = [NSMutableArray array];
  1624. // 取消订单
  1625. if(/*[order_status isEqualToString:@"Saved Order"]*/statusCode == 1&&appDelegate.can_cancel_order)
  1626. [actionArr addObject:cancelAction];
  1627. return actionArr;
  1628. }
  1629. return @[];
  1630. }
  1631. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
  1632. if(indexPath.row==self.content_data.count)
  1633. return NO;
  1634. if(self.init_style==OL_OPEN)
  1635. return NO;
  1636. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1637. // NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"];
  1638. NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue];
  1639. if(appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1640. // saved && ((type==0 && merge_permission) || type == 1 || can_cancel)
  1641. BOOL isSavedOrder = /*[order_status isEqualToString:@"Saved Order"]*/statusCode == 1;
  1642. switch (self.orderType) {
  1643. case 0:{ // Shop Order
  1644. if (!isSavedOrder) {
  1645. return NO;
  1646. } else {
  1647. if ([RASingleton sharedInstance].permissions_merge_order || appDelegate.can_cancel_order) {
  1648. return YES;
  1649. } else {
  1650. return NO;
  1651. }
  1652. }
  1653. }
  1654. break;
  1655. case 1:{ // Sales Order
  1656. if (isSavedOrder && appDelegate.can_cancel_order) {
  1657. return YES;
  1658. }
  1659. return NO;
  1660. }
  1661. break;
  1662. default:
  1663. break;
  1664. }
  1665. } else {
  1666. return YES;
  1667. }
  1668. return YES;
  1669. }
  1670. - (void)tableView:(UITableView *)tableView
  1671. commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  1672. }
  1673. - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  1674. if(indexPath.row==self.content_data.count)
  1675. return UITableViewCellEditingStyleNone;
  1676. bool offline_edit =[[self.content_data[indexPath.row] valueForKey:@"offline_edit"] boolValue];
  1677. // NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"];
  1678. NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue];
  1679. if(/*![order_status isEqualToString:@"Saved Order"]&&! [order_status isEqualToString:@"Quote Saved"]*/statusCode != 1 && statusCode != 0)
  1680. return UITableViewCellEditingStyleNone;
  1681. else
  1682. {
  1683. BOOL condition = offline_edit;
  1684. #ifdef OFFLINE_MODE
  1685. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1686. condition = condition || appDelegate.offline_mode==false;
  1687. #else
  1688. condition = YES;
  1689. #endif
  1690. if (condition)
  1691. return UITableViewCellEditingStyleDelete;
  1692. else
  1693. return UITableViewCellEditingStyleNone;
  1694. }
  1695. }
  1696. /*
  1697. #pragma mark - Navigation
  1698. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1699. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1700. // Get the new view controller using [segue destinationViewController].
  1701. // Pass the selected object to the new view controller.
  1702. }
  1703. */
  1704. #pragma mark EnumSelectViewControllerDelegate
  1705. -(void) EnumValueChanged:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
  1706. {
  1707. self.status_cadedate = value;
  1708. UIApplication * app = [UIApplication sharedApplication];
  1709. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1710. appDelegate.OrderFilter = value;
  1711. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  1712. // NSString *documents = [paths objectAtIndex:0];
  1713. // NSString *dist_path = [documents stringByAppendingPathComponent:@"status_filter_cadedate.json"];
  1714. //
  1715. //
  1716. // // if ([[NSFileManager defaultManager] fileExistsAtPath:dist_path]) {
  1717. // //
  1718. // // DebugLog(@"文件已经存在了");
  1719. // //
  1720. // // }
  1721. // // else
  1722. // // {
  1723. // //
  1724. // //
  1725. // //
  1726. // // DebugLog(@"resourceSampleImagesFolderPath=%@",resourceFolderPath);
  1727. //
  1728. //NSData *data = [NSJSONSerialization dataWithJSONObject:self.status_cadedate options:kNilOptions error:nil];
  1729. //
  1730. // // DebugLog(@"mainBundleFile==%@",mainBundleFile);
  1731. //
  1732. // [[NSFileManager defaultManager] createFileAtPath:dist_path
  1733. //
  1734. // contents:data
  1735. //
  1736. // attributes:nil];
  1737. //
  1738. // }
  1739. // self.keywords=searchBar.text;
  1740. // self.offset = 0;
  1741. // [self.content_data removeAllObjects];
  1742. self.reset_result=true;
  1743. [self loadpage];
  1744. //[self.btnStatusFilter setTitle:setTitle:alert ];
  1745. }
  1746. #pragma mark - button action
  1747. - (NSIndexPath *)indexPathOfDeleteOrder:(NSString *)orderID {
  1748. for (NSIndexPath *indexPath in self.table_order.indexPathsForSelectedRows) {
  1749. NSString* orderid= [NSString stringWithFormat:@"%@",[self.content_data[indexPath.row] valueForKey:@"order_id"]];
  1750. if ([orderid isEqualToString:orderID]) {
  1751. return indexPath;
  1752. }
  1753. }
  1754. return nil;
  1755. }
  1756. - (IBAction)mergeListButtonClick:(UIBarButtonItem *)sender {
  1757. if (!self.table_order.isEditing) {
  1758. [RAUtils message_alert:@"You have to click select firstly then select some saved order" title:@"Warning" controller:self];
  1759. return;
  1760. }
  1761. [self handleSelectedOrders];
  1762. if (!self.mergeList.count) {
  1763. // [RAUtils message_alert:@"Combine List is Empty" title:@"Warning" controller:self];
  1764. return;
  1765. }
  1766. SelectUploadOrderViewController *mergeVC = [[UIStoryboard storyboardWithName:@"OLM" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SelectUploadOrderViewController"];
  1767. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:mergeVC];
  1768. mergeVC.mergeList = self.mergeList;
  1769. mergeVC.title = @"Combine List";
  1770. __weak typeof(self) weakself = self;
  1771. mergeVC.mergeBlock = ^(NSDictionary *ret) {
  1772. if (weakself) {
  1773. __strong typeof(weakself) strongself = weakself;
  1774. if([[ret objectForKey:@"result"]integerValue] == RESULT_TRUE) {
  1775. [weakself.mergeList removeAllObjects];
  1776. [strongself.table_order endEditing:YES];
  1777. [strongself ReloadData];
  1778. if ([RASingleton sharedInstance].customer_can_see_sales_Order) {
  1779. [strongself openOrder:ret];
  1780. }
  1781. } else {
  1782. NSString *msg = [ret objectForKey:@"err_msg"];
  1783. [RAUtils message_alert:msg title:nil controller:strongself];
  1784. }
  1785. }
  1786. };
  1787. mergeVC.deleteBlock = ^(NSString *orderID){
  1788. NSIndexPath *indexPath = [weakself indexPathOfDeleteOrder:orderID];
  1789. [weakself.table_order deselectRowAtIndexPath:indexPath animated:YES];
  1790. };
  1791. mergeVC.clearBlock = ^{
  1792. for (NSDictionary *order in self.mergeList) {
  1793. NSString *order_id = [NSString stringWithFormat:@"%@",[order objectForKey:@"order_id"]];
  1794. NSIndexPath *indexPath = [weakself indexPathOfDeleteOrder:order_id];
  1795. [weakself.table_order deselectRowAtIndexPath:indexPath animated:YES];
  1796. }
  1797. };
  1798. nav.modalPresentationStyle = UIModalPresentationFormSheet;
  1799. [self presentViewController:nav animated:YES completion:nil];
  1800. }
  1801. - (void)handleSelectedOrders {
  1802. [self.mergeList removeAllObjects];
  1803. if (!self.table_order.isEditing) {
  1804. return;
  1805. }
  1806. for (NSIndexPath *indexPath in self.table_order.indexPathsForSelectedRows) {
  1807. if(indexPath.row==self.content_data.count)
  1808. continue;
  1809. NSString* so= [self.content_data[indexPath.row] valueForKey:@"so#"];
  1810. NSString* orderid= [self.content_data[indexPath.row] valueForKey:@"order_id"];
  1811. NSString *create_by = [self.content_data[indexPath.row] valueForKey:@"create_by"];
  1812. NSString *create_time = [self.content_data[indexPath.row] valueForKey:@"purchase_time"];
  1813. NSString *orderCode = [NSString stringWithFormat:@"%@",[self.content_data[indexPath.row] valueForKey:@"order_code"]];
  1814. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  1815. [dic setValue:orderid forKey:@"order_id"];
  1816. [dic setValue:orderCode forKey:@"order_code"];
  1817. [dic setValue:so forKey:@"so_id"];
  1818. [dic setValue:create_by forKey:@"create_by"];
  1819. [dic setValue:create_time forKey:@"create_time"];
  1820. [dic setValue:[NSNumber numberWithInteger:0] forKey:@"check"]; // 合并到
  1821. [self.mergeList addObject:dic];
  1822. }
  1823. }
  1824. - (IBAction)editOrderListButtonClick:(UIBarButtonItem *)sender {
  1825. if ([RASingleton sharedInstance].global_lock) { // Order list 被锁
  1826. [RAUtils message_alert:@"Permission Needed.\nGoto Menu -> Unlock" title:@"Warning" controller:self];
  1827. return;
  1828. }
  1829. UIImage *gray = [UIImage imageNamed:@"Combinegray"];
  1830. UIImage *green = [[UIImage imageNamed:@"converttopo"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];//converttopo
  1831. if (self.table_order.isEditing) {
  1832. [self mergeListButtonClick:nil];
  1833. // 结束选择时恢复
  1834. if ([RASingleton sharedInstance].customer_can_see_sales_Order && ![RASingleton sharedInstance].global_lock) { // 有查看Sales order 权限,并且app没有锁
  1835. if (self.orderTypeSegmentControl.numberOfSegments == 1) {
  1836. [self.orderTypeSegmentControl insertSegmentWithTitle:[NSString stringWithFormat:@"Purchase Order to %@",COMPANY_SHORT_NAME] atIndex:1 animated:YES];
  1837. }
  1838. }
  1839. self.status_cadedate = self.shop_order_filter;
  1840. [self ReloadData];
  1841. [self.table_order setEditing:NO animated:YES];
  1842. // sender.title = @"Select";
  1843. // [self.mergeList removeAllObjects];
  1844. [sender setImage:gray];
  1845. } else {
  1846. // 选择时不能选择Sales Order
  1847. if(self.orderTypeSegmentControl.numberOfSegments > 1) {
  1848. [self.orderTypeSegmentControl removeSegmentAtIndex:1 animated:YES];
  1849. [self changeOrderType:0];
  1850. }
  1851. // 切换filter
  1852. NSData *data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"status_filter_cadedate_open" ofType:@"json" ]];
  1853. NSError *error=nil;
  1854. self.status_cadedate = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  1855. // 刷新,取Saved Order
  1856. [self ReloadData];
  1857. [self.table_order setEditing:YES animated:YES];
  1858. // sender.title = @"Exit";
  1859. [sender setImage:green];
  1860. }
  1861. }
  1862. - (void)changeOrderType:(NSInteger)ordertype {
  1863. self.orderType = ordertype;
  1864. [RASingleton sharedInstance].customer_order_type = ordertype;
  1865. if(self.init_style != OL_OPEN) {
  1866. switch (ordertype) {
  1867. case 0:{
  1868. self.status_cadedate = self.shop_order_filter;
  1869. }
  1870. break;
  1871. case 1:{
  1872. self.status_cadedate = self.sales_order_filter;
  1873. }
  1874. break;
  1875. default:
  1876. break;
  1877. }
  1878. NSMutableArray *items = [self.toolbarView.items mutableCopy];
  1879. if (ordertype == 1) {
  1880. // 不能合并
  1881. // if ([items containsObject:self.mergeListButton]) { // 显示button
  1882. // [items removeObject:self.mergeListButton];
  1883. // }
  1884. if ([items containsObject:self.editOrderListButton]) { // 显示button
  1885. [items removeObject:self.editOrderListButton];
  1886. }
  1887. self.toolbarView.items = items;
  1888. } else {
  1889. // 合并订单的权限
  1890. if ([RASingleton sharedInstance].permissions_merge_order) { // 能够合并
  1891. // 4 6 顺序不能换
  1892. if (![items containsObject:self.editOrderListButton]) { // 没显示button
  1893. [items insertObject:self.editOrderListButton atIndex:4];
  1894. }
  1895. // if (![items containsObject:self.mergeListButton]) { // 没显示button
  1896. // [items insertObject:self.mergeListButton atIndex:6];
  1897. // }
  1898. self.toolbarView.items = items;
  1899. } else { // 不能合并
  1900. // if ([items containsObject:self.mergeListButton]) { // 显示button
  1901. // [items removeObject:self.mergeListButton];
  1902. // }
  1903. if ([items containsObject:self.editOrderListButton]) { // 显示button
  1904. [items removeObject:self.editOrderListButton];
  1905. }
  1906. self.toolbarView.items = items;
  1907. }
  1908. }
  1909. } else {
  1910. NSString *resource = @"status_filter_cadedate_open";
  1911. if (ordertype == 1) {
  1912. resource = @"status_filter_cadedate_po";
  1913. }
  1914. NSData *json=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:resource ofType:@"json" ]];
  1915. NSError *error=nil;
  1916. self.status_cadedate = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  1917. }
  1918. [self ReloadData];
  1919. }
  1920. - (IBAction)orderTypeChanged:(UISegmentedControl *)sender {
  1921. [self changeOrderType:sender.selectedSegmentIndex];
  1922. }
  1923. - (void)openOrder:(NSDictionary *)order {
  1924. if (!order) {
  1925. return;
  1926. }
  1927. NSString *orderCode = [order objectForKey:@"orderCode"];
  1928. NSInteger orderStatus = [[order objectForKey:@"orderStatus"] integerValue];
  1929. NSString *so = [order objectForKey:@"so#"];
  1930. __weak typeof(self) weakself = self;
  1931. [RANetwork request_open_order:orderCode completionHandler:^(NSMutableDictionary *result) {
  1932. NSDictionary* order_json = result ;
  1933. if([[order_json valueForKey:@"result"] intValue]==2)
  1934. {
  1935. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1936. appDelegate.order_code = orderCode;
  1937. appDelegate.order_status = (int)orderStatus;
  1938. [appDelegate SetSo:so];
  1939. __weak MainViewController *mainVC = (MainViewController*)appDelegate.main_vc;
  1940. #ifdef RA_NOTIFICATION
  1941. [ActiveViewController Notify:@"CartViewController,OrderListViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1942. #else
  1943. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1944. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1945. [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
  1946. #endif
  1947. [((MainViewController*)appDelegate.main_vc) switchToCart];
  1948. mainVC.cartViewController.onFinishLoad=^{
  1949. [mainVC.cartViewController placeOrder];
  1950. mainVC.cartViewController.onFinishLoad=nil;
  1951. };
  1952. }
  1953. else
  1954. {
  1955. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order" controller:weakself] ;
  1956. }
  1957. }];
  1958. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1959. //
  1960. // NSDictionary* order_json = [RANetwork open_Order:orderCode];
  1961. //
  1962. // dispatch_async(dispatch_get_main_queue(), ^{
  1963. //
  1964. // if([[order_json valueForKey:@"result"] intValue]==2)
  1965. // {
  1966. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1967. // appDelegate.order_code = orderCode;
  1968. // appDelegate.order_status = orderStatus;
  1969. // [appDelegate SetSo:so];
  1970. //
  1971. // __weak MainViewController *mainVC = (MainViewController*)appDelegate.main_vc;
  1972. //
  1973. //#ifdef RA_NOTIFICATION
  1974. // [ActiveViewController Notify:@"CartViewController,OrderListViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1975. //#else
  1976. //
  1977. //
  1978. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1979. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1980. // [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
  1981. //#endif
  1982. //
  1983. // [((MainViewController*)appDelegate.main_vc) switchToCart];
  1984. //
  1985. // mainVC.cartViewController.onFinishLoad=^{
  1986. // [mainVC.cartViewController placeOrder];
  1987. // mainVC.cartViewController.onFinishLoad=nil;
  1988. // };
  1989. //
  1990. // }
  1991. // else
  1992. // {
  1993. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order" controller:weakself] ;
  1994. // }
  1995. //
  1996. //
  1997. //
  1998. // });
  1999. // });
  2000. }
  2001. #pragma mark - notification action
  2002. - (void)changePriceType:(id)notification {
  2003. [self ReloadData];
  2004. }
  2005. - (void)lockOrderListNotification:(NSNotification *)notification {
  2006. if ([notification.name isEqual:Lock_Permission_Notification]) {
  2007. if (self.orderType == 1) {
  2008. self.orderTypeSegmentControl.selectedSegmentIndex = 0;
  2009. // [self changeOrderType:0];
  2010. [self.orderTypeSegmentControl sendActionsForControlEvents:UIControlEventValueChanged];
  2011. }
  2012. if(self.orderTypeSegmentControl.numberOfSegments > 1) {
  2013. [self.orderTypeSegmentControl removeSegmentAtIndex:1 animated:YES];
  2014. // [self changeOrderType:0];
  2015. }
  2016. } else { // 解锁
  2017. if ([RASingleton sharedInstance].customer_can_see_sales_Order) { // 有查看Sales order 权限
  2018. if (self.orderTypeSegmentControl.numberOfSegments == 1 && !self.table_order.isEditing) {
  2019. [self.orderTypeSegmentControl insertSegmentWithTitle:[NSString stringWithFormat:@"Purchase Order to %@",COMPANY_SHORT_NAME] atIndex:1 animated:YES];
  2020. }
  2021. }
  2022. }
  2023. }
  2024. - (void)handleUserLogin:(NSNotification *)notification {
  2025. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2026. self.orderType = 0;
  2027. if (self.table_order.isEditing) {
  2028. [self.table_order setEditing:NO animated:YES];
  2029. self.editOrderListButton.image = [UIImage imageNamed:@"Combinegray"];
  2030. }
  2031. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  2032. self.orderTypeSegmentControl.selectedSegmentIndex = 0;
  2033. [RASingleton sharedInstance].customer_order_type = 0;
  2034. }
  2035. }
  2036. - (void)reRefreshView {
  2037. [self.table_order reloadData];
  2038. }
  2039. #pragma mark - RA_NOTIFICAITON
  2040. -(void) refresh_ui
  2041. {
  2042. [self.table_order reloadData];
  2043. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2044. if(appDelegate.can_create_order)
  2045. {
  2046. [self.btn_newOrder setImage:[UIImage imageNamed:@"neworder"]];
  2047. self.btn_newOrder.enabled = true;
  2048. }
  2049. else
  2050. {
  2051. [self.btn_newOrder setImage:nil];
  2052. self.btn_newOrder.enabled = false;
  2053. }
  2054. }
  2055. -(void) reload_data
  2056. {
  2057. self.reset_result=true;
  2058. self.norefresh=true;
  2059. [self loadpage];
  2060. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2061. if(appDelegate.can_create_order)
  2062. {
  2063. [self.btn_newOrder setImage:[UIImage imageNamed:@"neworder"]];
  2064. self.btn_newOrder.enabled = true;
  2065. }
  2066. else
  2067. {
  2068. [self.btn_newOrder setImage:nil];
  2069. self.btn_newOrder.enabled = false;
  2070. }
  2071. }
  2072. -(void) refresh_price
  2073. {
  2074. [self refresh_ui];
  2075. }
  2076. @end