ScanOrderListViewController.m 112 KB

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