ScanOrderListViewController.m 111 KB

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