OrderListViewController.m 91 KB

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