ScanOrderListViewController.m 87 KB

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