ScanOrderListViewController.m 83 KB

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