OrderListViewController.m 103 KB

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