ScanOrderListViewController.m 111 KB

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