OrderListViewController.m 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151
  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 (RASingleton.sharedInstance.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(RASingleton.sharedInstance.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 (RASingleton.sharedInstance.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_box:@"" message:@"Cannot create order without customer infomation." completion:nil];
  354. [RAUtils message_box:@"" message:@"Cannot create order without customer infomation." completion:nil];
  355. }
  356. else
  357. {
  358. [self neworder];
  359. }
  360. // [main_vc checklogin:true];
  361. };
  362. cvc.onReset = ^(){
  363. // [main_vc checklogin:true];
  364. };
  365. [self.navigationController pushViewController:cvc animated:true];
  366. }
  367. else if (appDelegate.user_type == USER_ROLE_CUSTOMER){
  368. [self neworder];
  369. }
  370. }
  371. else
  372. {
  373. //create new;
  374. if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  375. {
  376. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  377. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  378. cvc.showNavibar = true;
  379. cvc.contact_type = @"Sales_Order_Customer";
  380. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  381. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  382. appDelegate.customerInfo = value;
  383. if(appDelegate.order_code==nil)
  384. [self neworder];
  385. // [main_vc checklogin:true];
  386. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  387. //
  388. // if(self.returnValue)
  389. // self.returnValue(value);
  390. };
  391. cvc.onCancel = ^(){
  392. // [RAUtils message_box:@"" message:@"Cannot create order without customer infomation." completion:nil];
  393. [RAUtils message_box:@"" message:@"Cannot create order without customer infomation." completion:nil];
  394. };
  395. cvc.onReset = ^(){
  396. [main_vc checklogin:true];
  397. };
  398. [self.navigationController pushViewController:cvc animated:true];
  399. }
  400. else
  401. {
  402. [self neworder];
  403. }
  404. }
  405. }];
  406. UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  407. }];
  408. [alertController addAction:action_2];
  409. [alertController addAction:action_3];
  410. [self presentViewController:alertController animated:YES completion:nil];
  411. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Warning", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  412. // [alert show];
  413. }
  414. - (void)didReceiveMemoryWarning {
  415. [super didReceiveMemoryWarning];
  416. // Dispose of any resources that can be recreated.
  417. }
  418. -(void)manually_refresh
  419. {
  420. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201];
  421. if(self.isrefreshing)
  422. {
  423. [reF endRefreshing];
  424. return;
  425. }
  426. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  427. if ([self respondsToSelector:@selector(ReloadData)])
  428. [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
  429. }
  430. -(void)ReloadData
  431. {
  432. // [self.content_data removeAllObjects];
  433. // [self.table_order reloadData];
  434. // self.table_order.hidden = true;
  435. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201];
  436. [reF endRefreshing];
  437. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  438. self.keywords=self.searchbar.text;
  439. // self.offset = 0;
  440. self.reset_result=true;
  441. // [self.content_data removeAllObjects];
  442. // [self.table_order reloadData];
  443. [self loadpage];
  444. // [self loadpage];
  445. }
  446. - (void)operation_loadPage {
  447. if (self.dataOperationQueue.operationCount > 1) { // 队列后面还有操作
  448. return;
  449. }
  450. // dispatch_async(self.loading_queue, ^{
  451. dispatch_sync(dispatch_get_main_queue(), ^{
  452. if(self.reset_result)
  453. {
  454. self.offset = 0;
  455. [self.content_data removeAllObjects];
  456. [self.table_order reloadData];
  457. }
  458. // NSMutableArray* arr_status = [[NSMutableArray alloc] init];
  459. NSMutableArray* arr_statusname = [[NSMutableArray alloc] init];
  460. int count = [[self.status_cadedate valueForKey:@"count"] intValue];
  461. for(int i=0;i<count;i++)
  462. {
  463. NSDictionary* val_json =[self.status_cadedate objectForKey:[NSString stringWithFormat:@"val_%d",i]];
  464. int check = [[val_json valueForKey:@"check"] intValue];
  465. if(check==1)
  466. {
  467. // [arr_status addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value_id"]]];
  468. [arr_statusname addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value"]]];
  469. // break;
  470. }
  471. }
  472. // NSString * str_status = [arr_status componentsJoinedByString:@","];
  473. NSString * str_statusname = [arr_statusname componentsJoinedByString:@","];
  474. if(str_statusname.length==0)
  475. str_statusname = @"All";
  476. self.label_filter.text = str_statusname;
  477. if(self.offset==0)
  478. {
  479. self.table_order.hidden = true;
  480. self.mum.center = self.view.center;
  481. self.mum.hidden = false;
  482. [self.mum startAnimating];
  483. }
  484. self.label_net_err.hidden=true;
  485. });
  486. // });
  487. // dispatch_async(self.loading_queue, ^{
  488. if(self.isrefreshing)
  489. return;
  490. self.isrefreshing=true;
  491. NSMutableArray* arr_status = [[NSMutableArray alloc] init];
  492. // NSMutableArray* arr_statusname = [[NSMutableArray alloc] init];
  493. int count = [[self.status_cadedate valueForKey:@"count"] intValue];
  494. for(int i=0;i<count;i++)
  495. {
  496. NSDictionary* val_json =[self.status_cadedate objectForKey:[NSString stringWithFormat:@"val_%d",i]];
  497. int check = [[val_json valueForKey:@"check"] intValue];
  498. if(check==1)
  499. {
  500. [arr_status addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value_id"]]];
  501. // [arr_statusname addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value"]]];
  502. // break;
  503. }
  504. }
  505. NSString * str_status = [arr_status componentsJoinedByString:@","];
  506. dispatch_sync(dispatch_get_main_queue(), ^{
  507. BOOL isMerged = NO;
  508. AppDelegate *appDelegate = nil;
  509. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  510. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  511. if (self.orderType == 0) {
  512. isMerged = NO;
  513. } else {
  514. isMerged = YES;
  515. }
  516. }
  517. [RANetwork request_orderlist:self.offset limit:self.limit keywords:self.keywords status:str_status customer:self.customer_id is_merged:isMerged completionHandler:^(NSMutableDictionary *result) {
  518. NSMutableDictionary* content=result;
  519. [self.mum stopAnimating];
  520. self.isrefreshing=false;
  521. if (self.dataOperationQueue.operationCount > 1) { // 队列后面还有操作
  522. return ;
  523. }
  524. int result_code=[[content valueForKey:@"result"] intValue];
  525. if(result_code==2||result_code==0)
  526. {
  527. int count = [[content valueForKey:@"count" ] intValue] ;
  528. self.time_zone = [content valueForKey:@"time_zone" ];
  529. self.offset += count;
  530. for(int i=0;i<count;i++)
  531. {
  532. NSDictionary* objmsg = [content objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  533. [self.content_data addObject:[NSMutableDictionary dictionaryWithDictionary:objmsg]];
  534. }
  535. if(count<self.limit)
  536. {
  537. // int i =self.btnrefresh.state;
  538. self.load_more_hint=@"All loaded";
  539. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"no_more", nil);
  540. // [self.btnrefresh setTitle:@"No more" forState:UIControlStateNormal];
  541. }
  542. else
  543. {
  544. self.load_more_hint=@"Load more...";
  545. // self.btnrefresh.enabled = true;
  546. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"load_more",nil);
  547. // [self.btnrefresh setTitle:@"Load more" forState:UIControlStateNormal];
  548. }
  549. self.table_order.hidden = false;
  550. self.reset_result=false;
  551. [self.table_order reloadData ];
  552. }
  553. else if(result_code==RESULT_NET_ERROR &&self.offset==0)
  554. {
  555. self.label_net_err.hidden=false;
  556. self.table_order.hidden = true;
  557. }
  558. else
  559. {
  560. [RAUtils message_box:@"Loading Order List" message:[content valueForKey:@"err_msg"] completion:nil];
  561. }
  562. }];
  563. });
  564. }
  565. -(void) loadpage
  566. {
  567. __weak typeof(self) weakself = self;
  568. NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
  569. if (weakself) {
  570. __strong typeof(weakself) strongself = weakself;
  571. [strongself operation_loadPage];
  572. }
  573. }];
  574. [self.dataOperationQueue addOperation:operation];
  575. }
  576. - (void)loadmore
  577. {
  578. // self.btnrefresh.enabled = NO;
  579. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"loading",nil);
  580. // [self.btnrefresh setTitle:@"Loading..." forState:UIControlStateNormal];
  581. [self loadpage];
  582. }
  583. //-(void)changeCell
  584. //{
  585. //// UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  586. //// reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"refreshing"];
  587. // [self performSelector:@selector(loadmore) withObject:nil afterDelay:1];
  588. // DebugLog(@"refresh!!!!!!!!");
  589. //
  590. //}
  591. -(void) neworder
  592. {
  593. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order" completion:^{
  594. PopWaitAlert* pop = [RAUtils waiting_pop:@"Create Order" completion:nil];
  595. [RANetwork request_create_order:^(NSMutableDictionary *result) {
  596. NSMutableDictionary* return_json =result;
  597. // [waitalert dismissViewControllerAnimated:YES completion:^{
  598. [pop hide];
  599. if([[return_json valueForKey:@"result"] intValue]==2)
  600. {
  601. int result=[[return_json valueForKey:@"result"] intValue];
  602. if(result==2)
  603. {
  604. //successed.
  605. NSString* order_code = [return_json valueForKey:@"orderCode"];
  606. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  607. appDelegate.order_code = order_code;
  608. appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  609. #ifdef RA_NOTIFICATION
  610. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  611. #else
  612. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  613. [main_vc reloadCart:true immediately:false];
  614. #endif
  615. [self ReloadData];
  616. }
  617. }
  618. else
  619. {
  620. [RAUtils message_box:@"Create Order" message:[return_json valueForKey:@"err_msg"] completion:nil];
  621. }
  622. // }];
  623. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  624. }];
  625. // }];
  626. }
  627. #pragma mark - Table view data source
  628. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  629. {
  630. return 66;
  631. }
  632. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  633. //{
  634. // return 0;
  635. //}
  636. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  637. //{
  638. // return 0;
  639. //}
  640. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  641. //{
  642. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  643. // return myView;
  644. //
  645. //}
  646. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  647. {
  648. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  649. if(value==nil)
  650. value=@"";
  651. unsigned long color = strtoul([value UTF8String],0,16);
  652. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  653. // myView.backgroundColor = UIColorFromRGB(0x996633);
  654. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  655. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  656. myView.layer.shadowOffset = CGSizeMake(0, 0);
  657. myView.layer.shadowOpacity = 0.5;
  658. myView.layer.shadowRadius = 2.0;
  659. UILabel *statuslabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 2, 130, 22)];
  660. statuslabel.textColor=UIColorFromRGB(color);
  661. statuslabel.backgroundColor = [UIColor clearColor];
  662. statuslabel.text=NSLocalizedString(@"Status", nil);
  663. [statuslabel sizeToFit];
  664. [myView addSubview:statuslabel];
  665. UILabel *solabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 21, 130, 22)];
  666. solabel.textColor=UIColorFromRGB(color);
  667. solabel.backgroundColor = [UIColor clearColor];
  668. solabel.text=NSLocalizedString(@"SO#", nil);
  669. [solabel sizeToFit];
  670. [myView addSubview:solabel];
  671. UILabel *userlabel = [[UILabel alloc] initWithFrame:CGRectMake(165, 21, 125, 22)];
  672. userlabel.textColor=UIColorFromRGB(color);
  673. userlabel.backgroundColor = [UIColor clearColor];
  674. userlabel.text=NSLocalizedString(@"Sales rep", nil);
  675. [userlabel sizeToFit];
  676. [myView addSubview:userlabel];
  677. UILabel *creatorlabel = [[UILabel alloc] initWithFrame:CGRectMake(165, 2, 125, 22)];
  678. creatorlabel.textColor=UIColorFromRGB(color);
  679. creatorlabel.backgroundColor = [UIColor clearColor];
  680. creatorlabel.text=NSLocalizedString(@"Create by", nil);
  681. [creatorlabel sizeToFit];
  682. [myView addSubview:creatorlabel];
  683. UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(296, 11, 150, 22)];
  684. contactlabel.textColor=UIColorFromRGB(color);
  685. contactlabel.backgroundColor = [UIColor clearColor];
  686. contactlabel.text=NSLocalizedString(@"Contact", nil);
  687. [contactlabel sizeToFit];
  688. [myView addSubview:contactlabel];
  689. //
  690. // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(424, 11, 52, 22)];
  691. // modellabel.textColor=[UIColor whiteColor];
  692. // modellabel.backgroundColor = [UIColor clearColor];
  693. // modellabel.text=NSLocalizedString(@"Model", nil);
  694. // [modellabel sizeToFit];
  695. // [myView addSubview:modellabel];
  696. // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(self.table_order.frame.size.width-276, 2, 100, 22)];
  697. // modellabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  698. // modellabel.textColor=[UIColor whiteColor];
  699. // modellabel.backgroundColor = [UIColor clearColor];
  700. // modellabel.text=NSLocalizedString(@"Items/QTY", nil);
  701. // [modellabel sizeToFit];
  702. // [myView addSubview:modellabel];
  703. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  704. UILabel *pricelabel = nil;
  705. if(appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && self.orderType==1)
  706. pricelabel=[[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.table_order.frame.size.width-276, 2, 100, 22)];
  707. else
  708. pricelabel=[[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.table_order.frame.size.width-276, 11, 100, 22)];
  709. pricelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  710. pricelabel.textColor=UIColorFromRGB(color);
  711. pricelabel.backgroundColor = [UIColor clearColor];
  712. pricelabel.text=NSLocalizedString(@"Order Total", nil);
  713. [pricelabel sizeToFit];
  714. [myView addSubview:pricelabel];
  715. if(appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && self.orderType==1)
  716. {
  717. UILabel *polabel = nil;
  718. polabel=[[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.table_order.frame.size.width-276, 21, 100, 22)];
  719. polabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  720. polabel.textColor=UIColorFromRGB(color);
  721. polabel.backgroundColor = [UIColor clearColor];
  722. polabel.text=NSLocalizedString(@"PO#", nil);
  723. [polabel sizeToFit];
  724. [myView addSubview:polabel];
  725. }
  726. UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(self.table_order.frame.size.width-163/*605*/,11, 148, 22)];
  727. timelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  728. timelabel.textColor=UIColorFromRGB(color);
  729. timelabel.backgroundColor = [UIColor clearColor];
  730. if(self.time_zone==nil)
  731. timelabel.text=@"Create time";
  732. else
  733. timelabel.text=[NSString stringWithFormat:@"Create time (%@)",self.time_zone];
  734. [timelabel sizeToFit];
  735. [myView addSubview:timelabel];
  736. myView.autoresizesSubviews=true;
  737. // [myView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin];
  738. // modellabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  739. // pricelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  740. // timelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  741. myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  742. //
  743. return myView;
  744. }
  745. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  746. {
  747. return 44;
  748. }
  749. //
  750. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  751. // if(section==0)
  752. // return nil;
  753. // else
  754. // return @"detail section";
  755. //}
  756. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  757. {
  758. return 1;
  759. }
  760. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  761. {
  762. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  763. if( self.content_data.count==0)
  764. return 0;
  765. return self.content_data.count+1;
  766. }
  767. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  768. {
  769. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  770. // if(tableView==self.itemListTable)
  771. // {
  772. // if(indexPath.row>self.content_data.count)
  773. // {
  774. // int debug=true;
  775. // }
  776. // DebugLog(@"row %ld",(long)indexPath.row);
  777. if(indexPath.row==self.content_data.count)
  778. {
  779. UITableViewCell *moreCell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"mores"];
  780. UILabel *moreDataLabel=[[UILabel alloc] init];
  781. moreDataLabel.tag=200;
  782. moreDataLabel.text=self.load_more_hint;
  783. [moreDataLabel setFont:[UIFont systemFontOfSize:14.0f]];
  784. [moreDataLabel setTextAlignment:NSTextAlignmentCenter];
  785. moreDataLabel.frame=CGRectMake(0, 10, self.table_order.bounds.size.width, 20);
  786. [moreDataLabel setBackgroundColor:[UIColor clearColor]];
  787. moreDataLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
  788. // [moreDataLabel addTarget:self action:@selector(changeCell) forControlEvents:UIControlEventValueChanged];
  789. [moreCell.contentView addSubview:moreDataLabel];
  790. if([self.load_more_hint isEqualToString:@"Load more..."])
  791. [self performSelector:@selector(loadmore) withObject:nil afterDelay:1];
  792. // DebugLog(@"更多...");
  793. moreCell.backgroundColor = [UIColor whiteColor];
  794. return moreCell;
  795. }
  796. else
  797. {
  798. NSString *CellIdentifier = @"OrderListTableViewCell";
  799. OrderListTableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  800. NSString* so= [self.content_data[indexPath.row] valueForKey:@"so#"];
  801. NSString* price= [self.content_data[indexPath.row] valueForKey:@"price"];
  802. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  803. {
  804. }
  805. else
  806. {
  807. price=nil;
  808. }
  809. NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue];
  810. NSString* purchase_time= [self.content_data[indexPath.row] valueForKey:@"purchase_time"];
  811. NSString* status = [self.content_data[indexPath.row] valueForKey:@"order_status"] ;
  812. if (RASingleton.sharedInstance.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  813. status = [ERPUtils orderStatus:statusCode];
  814. }
  815. NSString* customer_name = [self.content_data[indexPath.row] valueForKey:@"customer_name"];
  816. NSString* model_count = [self.content_data[indexPath.row] valueForKey:@"model_count"];
  817. NSString* sales = [self.content_data[indexPath.row] valueForKey:@"sales_rep"];
  818. NSString* creator = [self.content_data[indexPath.row] valueForKey:@"create_by"];
  819. NSString *po = [self.content_data[indexPath.row] valueForKey:@"po_id"];
  820. CGRect price_frame = cell.labelprice.frame;
  821. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && self.orderType == 1) {
  822. cell.label_po.hidden = NO;
  823. price_frame.origin.y = 5;
  824. cell.label_po.text = po;
  825. } else {
  826. cell.label_po.hidden = YES;
  827. price_frame.origin.y = 21;
  828. }
  829. cell.labelprice.frame = price_frame;
  830. cell.label_so.text=so;
  831. cell.labelprice.text=price;
  832. cell.label_date.text=purchase_time;
  833. cell.label_contact.text=customer_name;
  834. cell.label_model.text = model_count;
  835. cell.label_sales.text = sales;
  836. cell.label_creator.text = creator;
  837. cell.label_status.text=status;
  838. cell.backgroundColor = [UIColor whiteColor];
  839. return cell;
  840. }
  841. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  842. // NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  843. // cell.bundle_item=combine_json;
  844. // NSString* img_url = [item_json valueForKey:@"img_url"];
  845. // NSString* description = [item_json valueForKey:@"description"];
  846. // // NSString* identifier = [item_json valueForKey:@"identifier"];
  847. // // NSString* attribute = [item_json valueForKey:@"attribute"];
  848. // NSString* currency = [item_json valueForKey:@"currency"];
  849. // int count =[[item_json valueForKey:@"count"] intValue];
  850. // double price =[[item_json valueForKey:@"price"] doubleValue];
  851. // // cell.labelAttribute.text = attribute;
  852. // cell.labelCurrency.text = currency;
  853. // cell.labelDescription.text = description;
  854. // // cell.labelIdentifier.text = identifier;
  855. // cell.labelPrice.text = [NSString stringWithFormat:@"%.2f",price];
  856. //
  857. //
  858. //
  859. // [cell set_Count:count];
  860. // NSString* file_name=[img_url lastPathComponent];
  861. // NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  862. // if(img_data!=nil)
  863. // {
  864. //
  865. // UIImage * img =[UIImage imageWithData:img_data];
  866. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  867. // }
  868. // else
  869. // {
  870. //
  871. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  872. //
  873. // NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  874. //
  875. // dispatch_async(dispatch_get_main_queue(), ^{
  876. //
  877. //
  878. //
  879. // if(downloadimg_data!=nil)
  880. // {
  881. // [iSalesDB cache_img:downloadimg_data :file_name ];
  882. //
  883. // UIImage * img =[UIImage imageWithData:downloadimg_data];
  884. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  885. // }
  886. //
  887. // });
  888. // });
  889. //
  890. //
  891. // }
  892. // }
  893. // else
  894. // {
  895. // NSString *CellIdentifier = @"OrderInfoListItem";
  896. // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  897. // return cell;
  898. // }
  899. }
  900. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  901. {
  902. if (tableView.isEditing) { // 编辑模式下不响应
  903. return;
  904. }
  905. //
  906. if(indexPath.row==self.content_data.count)
  907. return;
  908. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  909. if(appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) { // Customer
  910. if ([RASingleton sharedInstance].global_lock) { // Order list 被锁
  911. [RAUtils message_box:@"Warning" message:@"Permission Needed.\nGoto Menu -> Unlock" completion:nil];
  912. return;
  913. }
  914. }
  915. NSString* orderid= [self.content_data[indexPath.row] valueForKey:@"order_id"];
  916. OrderDetailViewController* dvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderDetailViewController" ];
  917. // int i =[[self.content_data[indexPath.row] valueForKey:@"order_code"];
  918. dvc.selectOrder=^(NSMutableDictionary* order_detail){
  919. [self.navigationController popViewControllerAnimated:false];
  920. if(self.selectOrder)
  921. self.selectOrder(order_detail);
  922. };
  923. NSString* order_code =[self.content_data[indexPath.row] valueForKey:@"order_code"];
  924. NSString *erpSerialNo = [self.content_data[indexPath.row] valueForKey:@"erp_order_serial_no"];
  925. dvc.erpSerialNo = erpSerialNo;
  926. dvc.is_shoporder=(self.orderType == 0);
  927. dvc.order_code = order_code;
  928. dvc.order_status =[[self.content_data[indexPath.row] valueForKey:@"orderStatus"] intValue];
  929. // bool temp_order = false ;
  930. // NSString* order_status=[self.content_data[indexPath.row] valueForKey:@"order_status"];
  931. // if([order_status isEqualToString:@"Saved"]||[order_status isEqualToString:@"Quoted"])
  932. // temp_order=true;
  933. //
  934. // dvc.isTempOrder = temp_order;
  935. // dvc
  936. dvc.orderid=orderid;
  937. // dvc.category_id=nil;
  938. // dvc.ispush=true;
  939. // [dvc reload];
  940. [self.navigationController pushViewController:dvc animated:true];
  941. }
  942. #pragma mark - searchBar delegate;
  943. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
  944. {
  945. self.keywords=searchBar.text;
  946. // self.offset = 0;
  947. // [self.content_data removeAllObjects];
  948. self.reset_result=true;
  949. [self loadpage];
  950. }
  951. - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
  952. {
  953. if([searchText isEqualToString:@""] && !self.reset)
  954. {
  955. DebugLog(@"clear");
  956. self.reset=true;
  957. self.keywords=nil;
  958. // self.offset = 0;
  959. // [self.content_data removeAllObjects];
  960. self.reset_result=true;
  961. [self loadpage];
  962. }
  963. else
  964. self.reset = false;
  965. }
  966. #pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮
  967. //- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
  968. - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath
  969. {
  970. // 添加一个删除按钮
  971. // self.indexPath=indexPath;
  972. if(indexPath.row==self.content_data.count)
  973. // return @[];
  974. return [UISwipeActionsConfiguration configurationWithActions:@[]];
  975. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  976. NSString* so= [self.content_data[indexPath.row] valueForKey:@"so#"];
  977. NSString* orderid= [self.content_data[indexPath.row] valueForKey:@"order_id"];
  978. // NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"];
  979. NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue];
  980. if(appDelegate.user_type==USER_ROLE_EMPLOYEE || (appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeCustomer)) {
  981. // UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  982. UIContextualAction* deleteRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"Delete" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  983. DebugLog(@"delete click");
  984. NSString * title =[NSString stringWithFormat:@"Are you sure to delete order SO#: %@",so];
  985. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
  986. //block代码块取代了delegate
  987. // [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  988. // textField.text = self.save_name;
  989. //
  990. //
  991. // }];
  992. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  993. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Delete Order" completion:^{
  994. PopWaitAlert* pop = [RAUtils waiting_pop:@"Delete Order" completion:nil];
  995. [RANetwork request_delete_order:orderid completionHandler:^(NSMutableDictionary *result) {
  996. NSDictionary* return_json = result;
  997. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  998. [pop hide];
  999. // [waitalert dismissViewControllerAnimated:YES completion:^{
  1000. if([[return_json valueForKey:@"result"] intValue]==2)
  1001. {
  1002. if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
  1003. {
  1004. appDelegate.order_code= nil;
  1005. [appDelegate SetSo:nil];
  1006. appDelegate.cart_count=0;
  1007. [appDelegate update_count_mark];
  1008. // appDelegate.customerInfo = nil;
  1009. // appDelegate.contact_id = nil;
  1010. // appDelegate.order_customer_id = nil;
  1011. }
  1012. [RAUtils message_box:@"Order Delete" message:nil completion:nil];
  1013. [self ReloadData];
  1014. }
  1015. else
  1016. {
  1017. [RAUtils message_box:@"Delete Order" message:[return_json valueForKey:@"err_msg"] completion:nil];
  1018. }
  1019. // }];
  1020. }];
  1021. // }];
  1022. }];
  1023. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1024. DebugLog(@"Cancel");
  1025. }];
  1026. [alertControl addAction:actionOne];
  1027. [alertControl addAction:alertthree];
  1028. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1029. [self presentViewController:alertControl animated:YES completion:nil];
  1030. }];
  1031. deleteRowAction.backgroundColor = UIColorFromRGB(0x336699);
  1032. // 添加一个编辑按钮
  1033. //
  1034. // UITableViewRowAction *cancelAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Cancel Order"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1035. UIContextualAction* cancelAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"Cancel Order" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  1036. DebugLog(@"edit click");
  1037. NSString * title =[NSString stringWithFormat:@"Are you sure to cancel order SO#: %@",so];
  1038. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
  1039. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1040. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Cancel Order" completion:^{
  1041. PopWaitAlert* pop = [RAUtils waiting_pop:@"Cancel Order" completion:nil];
  1042. [RANetwork request_cancel_order:orderid order_code:nil completionHandler:^(NSMutableDictionary *result) {
  1043. NSDictionary* return_json = result;
  1044. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1045. // [waitalert dismissViewControllerAnimated:YES completion:^{
  1046. [pop hide];
  1047. if([[return_json valueForKey:@"result"] intValue]==2)
  1048. {
  1049. if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
  1050. {
  1051. appDelegate.order_code= nil;
  1052. //appDelegate.user_type = 0;
  1053. appDelegate.customerInfo = nil;
  1054. appDelegate.contact_id = nil;
  1055. appDelegate.order_customer_id = nil;
  1056. [appDelegate SetSo:nil];
  1057. appDelegate.cart_count=0;
  1058. [appDelegate update_count_mark];
  1059. }
  1060. [RAUtils message_box:@"Order Canceled" message:nil completion:nil];
  1061. [self ReloadData];
  1062. }
  1063. else
  1064. {
  1065. [RAUtils message_box:@"Cancel Order" message:[return_json valueForKey:@"err_msg"] completion:nil];
  1066. }
  1067. // }];
  1068. }];
  1069. // }];
  1070. }];
  1071. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1072. DebugLog(@"Cancel");
  1073. }];
  1074. [alertControl addAction:actionOne];
  1075. [alertControl addAction:alertthree];
  1076. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1077. [self presentViewController:alertControl animated:YES completion:nil];
  1078. //
  1079. }];
  1080. cancelAction.backgroundColor = UIColorFromRGB(0xff9933);
  1081. if(/*[order_status isEqualToString:@"Saved Order"]*/statusCode == 1&&appDelegate.can_cancel_order)
  1082. // return @[cancelAction];
  1083. return [UISwipeActionsConfiguration configurationWithActions:@[cancelAction]];
  1084. else
  1085. {
  1086. if(/*[order_status isEqualToString:@"Quote Saved"]*/statusCode == 0)
  1087. {
  1088. NSMutableArray* arr=[@[] mutableCopy];
  1089. if(appDelegate.can_delete_order)
  1090. [arr addObject:deleteRowAction];
  1091. if(appDelegate.can_cancel_order)
  1092. [arr addObject:cancelAction];
  1093. // return arr;
  1094. return [UISwipeActionsConfiguration configurationWithActions:arr];
  1095. }
  1096. }
  1097. } else if (appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1098. // // Cancel Order Action
  1099. // UITableViewRowAction *cancelAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Cancel Order"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1100. //
  1101. UIContextualAction* cancelAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"Cancel Order" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  1102. DebugLog(@"edit click");
  1103. NSString * title =[NSString stringWithFormat:@"Are you sure to cancel order SO#: %@",so];
  1104. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
  1105. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1106. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Cancel Order" completion:^{
  1107. PopWaitAlert* pop = [RAUtils waiting_pop:@"Cancel Order" completion:nil];
  1108. [RANetwork request_cancel_order:orderid order_code:nil completionHandler:^(NSMutableDictionary *result) {
  1109. NSDictionary* return_json =result;
  1110. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1111. // [waitalert dismissViewControllerAnimated:YES completion:^{
  1112. [pop hide];
  1113. if([[return_json valueForKey:@"result"] intValue]==2)
  1114. {
  1115. if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
  1116. {
  1117. appDelegate.order_code= nil;
  1118. //appDelegate.user_type = 0;
  1119. appDelegate.customerInfo = nil;
  1120. appDelegate.contact_id = nil;
  1121. appDelegate.order_customer_id = nil;
  1122. [appDelegate SetSo:nil];
  1123. appDelegate.cart_count=0;
  1124. [appDelegate update_count_mark];
  1125. }
  1126. [RAUtils message_box:@"Order Canceled" message:nil completion:nil];
  1127. [self ReloadData];
  1128. }
  1129. else
  1130. {
  1131. [RAUtils message_box:@"Cancel Order" message:[return_json valueForKey:@"err_msg"] completion:nil];
  1132. }
  1133. // }];
  1134. }];
  1135. // }];
  1136. }];
  1137. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1138. DebugLog(@"Cancel");
  1139. }];
  1140. [alertControl addAction:actionOne];
  1141. [alertControl addAction:alertthree];
  1142. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1143. [self presentViewController:alertControl animated:YES completion:nil];
  1144. //
  1145. }];
  1146. cancelAction.backgroundColor = UIColorFromRGB(0xff9933);
  1147. NSMutableArray *actionArr = [NSMutableArray array];
  1148. // 取消订单
  1149. if(/*[order_status isEqualToString:@"Saved Order"]*/statusCode == 1&&appDelegate.can_cancel_order)
  1150. [actionArr addObject:cancelAction];
  1151. // return actionArr;
  1152. return [UISwipeActionsConfiguration configurationWithActions:actionArr];
  1153. }
  1154. // return @[];
  1155. return [UISwipeActionsConfiguration configurationWithActions:@[]];
  1156. }
  1157. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
  1158. if(indexPath.row==self.content_data.count)
  1159. return NO;
  1160. if(self.init_style==OL_OPEN)
  1161. return NO;
  1162. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1163. // NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"];
  1164. NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue];
  1165. if(appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1166. // saved && ((type==0 && merge_permission) || type == 1 || can_cancel)
  1167. BOOL isSavedOrder = /*[order_status isEqualToString:@"Saved Order"]*/statusCode == 1;
  1168. switch (self.orderType) {
  1169. case 0:{ // Shop Order
  1170. if (!isSavedOrder) {
  1171. return NO;
  1172. } else {
  1173. if ([RASingleton sharedInstance].permissions_merge_order || appDelegate.can_cancel_order) {
  1174. return YES;
  1175. } else {
  1176. return NO;
  1177. }
  1178. }
  1179. }
  1180. break;
  1181. case 1:{ // Sales Order
  1182. if (isSavedOrder && appDelegate.can_cancel_order) {
  1183. return YES;
  1184. }
  1185. return NO;
  1186. }
  1187. break;
  1188. default:
  1189. break;
  1190. }
  1191. } else {
  1192. return YES;
  1193. }
  1194. return YES;
  1195. }
  1196. - (void)tableView:(UITableView *)tableView
  1197. commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  1198. }
  1199. - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  1200. if(indexPath.row==self.content_data.count)
  1201. return UITableViewCellEditingStyleNone;
  1202. bool offline_edit =[[self.content_data[indexPath.row] valueForKey:@"offline_edit"] boolValue];
  1203. // NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"];
  1204. NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue];
  1205. if(/*![order_status isEqualToString:@"Saved Order"]&&! [order_status isEqualToString:@"Quote Saved"]*/statusCode != 1 && statusCode != 0)
  1206. return UITableViewCellEditingStyleNone;
  1207. else
  1208. {
  1209. BOOL condition = offline_edit;
  1210. #ifdef OFFLINE_MODE
  1211. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1212. condition = condition || appDelegate.offline_mode==false;
  1213. #else
  1214. condition = YES;
  1215. #endif
  1216. if (condition)
  1217. return UITableViewCellEditingStyleDelete;
  1218. else
  1219. return UITableViewCellEditingStyleNone;
  1220. }
  1221. }
  1222. /*
  1223. #pragma mark - Navigation
  1224. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1225. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1226. // Get the new view controller using [segue destinationViewController].
  1227. // Pass the selected object to the new view controller.
  1228. }
  1229. */
  1230. #pragma mark EnumSelectViewControllerDelegate
  1231. -(void) EnumValueChanged:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
  1232. {
  1233. self.status_cadedate = value;
  1234. UIApplication * app = [UIApplication sharedApplication];
  1235. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1236. appDelegate.OrderFilter = value;
  1237. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  1238. // NSString *documents = [paths objectAtIndex:0];
  1239. // NSString *dist_path = [documents stringByAppendingPathComponent:@"status_filter_cadedate.json"];
  1240. //
  1241. //
  1242. // // if ([[NSFileManager defaultManager] fileExistsAtPath:dist_path]) {
  1243. // //
  1244. // // DebugLog(@"文件已经存在了");
  1245. // //
  1246. // // }
  1247. // // else
  1248. // // {
  1249. // //
  1250. // //
  1251. // //
  1252. // // DebugLog(@"resourceSampleImagesFolderPath=%@",resourceFolderPath);
  1253. //
  1254. //NSData *data = [NSJSONSerialization dataWithJSONObject:self.status_cadedate options:kNilOptions error:nil];
  1255. //
  1256. // // DebugLog(@"mainBundleFile==%@",mainBundleFile);
  1257. //
  1258. // [[NSFileManager defaultManager] createFileAtPath:dist_path
  1259. //
  1260. // contents:data
  1261. //
  1262. // attributes:nil];
  1263. //
  1264. // }
  1265. // self.keywords=searchBar.text;
  1266. // self.offset = 0;
  1267. // [self.content_data removeAllObjects];
  1268. self.reset_result=true;
  1269. [self loadpage];
  1270. //[self.btnStatusFilter setTitle:setTitle:alert ];
  1271. }
  1272. #pragma mark - button action
  1273. - (NSIndexPath *)indexPathOfDeleteOrder:(NSString *)orderID {
  1274. for (NSIndexPath *indexPath in self.table_order.indexPathsForSelectedRows) {
  1275. NSString* orderid= [NSString stringWithFormat:@"%@",[self.content_data[indexPath.row] valueForKey:@"order_id"]];
  1276. if ([orderid isEqualToString:orderID]) {
  1277. return indexPath;
  1278. }
  1279. }
  1280. return nil;
  1281. }
  1282. - (IBAction)mergeListButtonClick:(UIBarButtonItem *)sender {
  1283. if (!self.table_order.isEditing) {
  1284. [RAUtils message_box:@"Warning" message:@"You have to click select firstly then select some saved order" completion:nil];
  1285. return;
  1286. }
  1287. [self handleSelectedOrders];
  1288. if (!self.mergeList.count) {
  1289. return;
  1290. }
  1291. SelectUploadOrderViewController *mergeVC = [[UIStoryboard storyboardWithName:@"OLM" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SelectUploadOrderViewController"];
  1292. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:mergeVC];
  1293. mergeVC.mergeList = self.mergeList;
  1294. mergeVC.title = @"Combine List";
  1295. __weak typeof(self) weakself = self;
  1296. mergeVC.mergeBlock = ^(NSDictionary *ret) {
  1297. if (weakself) {
  1298. __strong typeof(weakself) strongself = weakself;
  1299. if([[ret objectForKey:@"result"]integerValue] == RESULT_TRUE) {
  1300. [weakself.mergeList removeAllObjects];
  1301. [strongself.table_order endEditing:YES];
  1302. [strongself ReloadData];
  1303. if ([RASingleton sharedInstance].customer_can_see_sales_Order) {
  1304. [strongself openOrder:ret];
  1305. }
  1306. } else {
  1307. NSString *msg = [ret objectForKey:@"err_msg"];
  1308. [RAUtils message_box:nil message:msg completion:nil];
  1309. }
  1310. }
  1311. };
  1312. mergeVC.deleteBlock = ^(NSString *orderID){
  1313. NSIndexPath *indexPath = [weakself indexPathOfDeleteOrder:orderID];
  1314. [weakself.table_order deselectRowAtIndexPath:indexPath animated:YES];
  1315. };
  1316. mergeVC.clearBlock = ^{
  1317. for (NSDictionary *order in self.mergeList) {
  1318. NSString *order_id = [NSString stringWithFormat:@"%@",[order objectForKey:@"order_id"]];
  1319. NSIndexPath *indexPath = [weakself indexPathOfDeleteOrder:order_id];
  1320. [weakself.table_order deselectRowAtIndexPath:indexPath animated:YES];
  1321. }
  1322. };
  1323. nav.modalPresentationStyle = UIModalPresentationFormSheet;
  1324. [self presentViewController:nav animated:YES completion:nil];
  1325. }
  1326. - (void)handleSelectedOrders {
  1327. [self.mergeList removeAllObjects];
  1328. if (!self.table_order.isEditing) {
  1329. return;
  1330. }
  1331. for (NSIndexPath *indexPath in self.table_order.indexPathsForSelectedRows) {
  1332. if(indexPath.row==self.content_data.count)
  1333. continue;
  1334. NSString* so= [self.content_data[indexPath.row] valueForKey:@"so#"];
  1335. NSString* orderid= [self.content_data[indexPath.row] valueForKey:@"order_id"];
  1336. NSString *create_by = [self.content_data[indexPath.row] valueForKey:@"create_by"];
  1337. NSString *create_time = [self.content_data[indexPath.row] valueForKey:@"purchase_time"];
  1338. NSString *orderCode = [NSString stringWithFormat:@"%@",[self.content_data[indexPath.row] valueForKey:@"order_code"]];
  1339. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  1340. [dic setValue:orderid forKey:@"order_id"];
  1341. [dic setValue:orderCode forKey:@"order_code"];
  1342. [dic setValue:so forKey:@"so_id"];
  1343. [dic setValue:create_by forKey:@"create_by"];
  1344. [dic setValue:create_time forKey:@"create_time"];
  1345. [dic setValue:[NSNumber numberWithInteger:0] forKey:@"check"]; // 合并到
  1346. [self.mergeList addObject:dic];
  1347. }
  1348. }
  1349. - (IBAction)editOrderListButtonClick:(UIBarButtonItem *)sender {
  1350. if ([RASingleton sharedInstance].global_lock) { // Order list 被锁
  1351. [RAUtils message_box:@"Warning" message:@"Permission Needed.\nGoto Menu -> Unlock" completion:nil];
  1352. return;
  1353. }
  1354. UIImage *gray = [UIImage imageNamed:@"Combinegray"];
  1355. UIImage *green = [[UIImage imageNamed:@"converttopo"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];//converttopo
  1356. if (self.table_order.isEditing) {
  1357. [self mergeListButtonClick:nil];
  1358. // 结束选择时恢复
  1359. if ([RASingleton sharedInstance].customer_can_see_sales_Order && ![RASingleton sharedInstance].global_lock) { // 有查看Sales order 权限,并且app没有锁
  1360. if (self.orderTypeSegmentControl.numberOfSegments == 1) {
  1361. [self.orderTypeSegmentControl insertSegmentWithTitle:[NSString stringWithFormat:@"Purchase Order to %@",COMPANY_SHORT_NAME] atIndex:1 animated:YES];
  1362. }
  1363. }
  1364. self.status_cadedate = self.shop_order_filter;
  1365. [self ReloadData];
  1366. [self.table_order setEditing:NO animated:YES];
  1367. // sender.title = @"Select";
  1368. // [self.mergeList removeAllObjects];
  1369. [sender setImage:gray];
  1370. } else {
  1371. // 选择时不能选择Sales Order
  1372. if(self.orderTypeSegmentControl.numberOfSegments > 1) {
  1373. [self.orderTypeSegmentControl removeSegmentAtIndex:1 animated:YES];
  1374. [self changeOrderType:0];
  1375. }
  1376. // 切换filter
  1377. NSData *data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"status_filter_cadedate_open" ofType:@"json" ]];
  1378. NSError *error=nil;
  1379. self.status_cadedate = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  1380. // 刷新,取Saved Order
  1381. [self ReloadData];
  1382. [self.table_order setEditing:YES animated:YES];
  1383. // sender.title = @"Exit";
  1384. [sender setImage:green];
  1385. }
  1386. }
  1387. - (void)changeOrderType:(NSInteger)ordertype {
  1388. self.orderType = ordertype;
  1389. [RASingleton sharedInstance].customer_order_type = ordertype;
  1390. if(self.init_style != OL_OPEN) {
  1391. switch (ordertype) {
  1392. case 0:{
  1393. self.status_cadedate = self.shop_order_filter;
  1394. }
  1395. break;
  1396. case 1:{
  1397. self.status_cadedate = self.sales_order_filter;
  1398. }
  1399. break;
  1400. default:
  1401. break;
  1402. }
  1403. NSMutableArray *items = [self.toolbarView.items mutableCopy];
  1404. if (ordertype == 1) {
  1405. // 不能合并
  1406. // if ([items containsObject:self.mergeListButton]) { // 显示button
  1407. // [items removeObject:self.mergeListButton];
  1408. // }
  1409. if ([items containsObject:self.editOrderListButton]) { // 显示button
  1410. [items removeObject:self.editOrderListButton];
  1411. }
  1412. self.toolbarView.items = items;
  1413. } else {
  1414. // 合并订单的权限
  1415. if ([RASingleton sharedInstance].permissions_merge_order) { // 能够合并
  1416. // 4 6 顺序不能换
  1417. if (![items containsObject:self.editOrderListButton]) { // 没显示button
  1418. [items insertObject:self.editOrderListButton atIndex:4];
  1419. }
  1420. // if (![items containsObject:self.mergeListButton]) { // 没显示button
  1421. // [items insertObject:self.mergeListButton atIndex:6];
  1422. // }
  1423. self.toolbarView.items = items;
  1424. } else { // 不能合并
  1425. // if ([items containsObject:self.mergeListButton]) { // 显示button
  1426. // [items removeObject:self.mergeListButton];
  1427. // }
  1428. if ([items containsObject:self.editOrderListButton]) { // 显示button
  1429. [items removeObject:self.editOrderListButton];
  1430. }
  1431. self.toolbarView.items = items;
  1432. }
  1433. }
  1434. } else {
  1435. NSString *resource = @"status_filter_cadedate_open";
  1436. if (ordertype == 1) {
  1437. resource = @"status_filter_cadedate_po";
  1438. }
  1439. NSData *json=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:resource ofType:@"json" ]];
  1440. NSError *error=nil;
  1441. self.status_cadedate = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  1442. }
  1443. [self ReloadData];
  1444. }
  1445. - (IBAction)orderTypeChanged:(UISegmentedControl *)sender {
  1446. [self changeOrderType:sender.selectedSegmentIndex];
  1447. }
  1448. - (void)openOrder:(NSDictionary *)order {
  1449. if (!order) {
  1450. return;
  1451. }
  1452. NSString *orderCode = [order objectForKey:@"orderCode"];
  1453. NSInteger orderStatus = [[order objectForKey:@"orderStatus"] integerValue];
  1454. NSString *so = [order objectForKey:@"so#"];
  1455. // __weak typeof(self) weakself = self;
  1456. [RANetwork request_open_order:orderCode completionHandler:^(NSMutableDictionary *result) {
  1457. NSDictionary* order_json = result ;
  1458. if([[order_json valueForKey:@"result"] intValue]==2)
  1459. {
  1460. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1461. appDelegate.order_code = orderCode;
  1462. appDelegate.order_status = (int)orderStatus;
  1463. [appDelegate SetSo:so];
  1464. __weak MainViewController *mainVC = (MainViewController*)appDelegate.main_vc;
  1465. #ifdef RA_NOTIFICATION
  1466. [ActiveViewController Notify:@"CartViewController,OrderListViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1467. #else
  1468. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1469. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1470. [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
  1471. #endif
  1472. [((MainViewController*)appDelegate.main_vc) switchToCart];
  1473. mainVC.cartViewController.onFinishLoad=^{
  1474. [mainVC.cartViewController placeOrder];
  1475. mainVC.cartViewController.onFinishLoad=nil;
  1476. };
  1477. }
  1478. else
  1479. {
  1480. [RAUtils message_box:@"Open Order" message:[order_json valueForKey:@"err_msg"] completion:nil];
  1481. }
  1482. }];
  1483. }
  1484. #pragma mark - notification action
  1485. - (void)changePriceType:(id)notification {
  1486. [self ReloadData];
  1487. }
  1488. - (void)lockOrderListNotification:(NSNotification *)notification {
  1489. if ([notification.name isEqual:Lock_Permission_Notification]) {
  1490. if (self.orderType == 1) {
  1491. self.orderTypeSegmentControl.selectedSegmentIndex = 0;
  1492. // [self changeOrderType:0];
  1493. [self.orderTypeSegmentControl sendActionsForControlEvents:UIControlEventValueChanged];
  1494. }
  1495. if(self.orderTypeSegmentControl.numberOfSegments > 1) {
  1496. [self.orderTypeSegmentControl removeSegmentAtIndex:1 animated:YES];
  1497. // [self changeOrderType:0];
  1498. }
  1499. } else { // 解锁
  1500. if ([RASingleton sharedInstance].customer_can_see_sales_Order) { // 有查看Sales order 权限
  1501. if (self.orderTypeSegmentControl.numberOfSegments == 1 && !self.table_order.isEditing) {
  1502. [self.orderTypeSegmentControl insertSegmentWithTitle:[NSString stringWithFormat:@"Purchase Order to %@",COMPANY_SHORT_NAME] atIndex:1 animated:YES];
  1503. }
  1504. }
  1505. }
  1506. }
  1507. - (void)handleUserLogin:(NSNotification *)notification {
  1508. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1509. self.orderType = 0;
  1510. if (self.table_order.isEditing) {
  1511. [self.table_order setEditing:NO animated:YES];
  1512. self.editOrderListButton.image = [UIImage imageNamed:@"Combinegray"];
  1513. }
  1514. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1515. self.orderTypeSegmentControl.selectedSegmentIndex = 0;
  1516. [RASingleton sharedInstance].customer_order_type = 0;
  1517. }
  1518. }
  1519. - (void)reRefreshView {
  1520. [self.table_order reloadData];
  1521. }
  1522. #pragma mark - RA_NOTIFICAITON
  1523. -(void) refresh_ui
  1524. {
  1525. [self.table_order reloadData];
  1526. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1527. if(appDelegate.can_create_order)
  1528. {
  1529. [self.btn_newOrder setImage:[UIImage imageNamed:@"neworder"]];
  1530. self.btn_newOrder.enabled = true;
  1531. }
  1532. else
  1533. {
  1534. [self.btn_newOrder setImage:nil];
  1535. self.btn_newOrder.enabled = false;
  1536. }
  1537. }
  1538. -(void) reload_data
  1539. {
  1540. self.reset_result=true;
  1541. self.norefresh=true;
  1542. [self loadpage];
  1543. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1544. if(appDelegate.can_create_order)
  1545. {
  1546. [self.btn_newOrder setImage:[UIImage imageNamed:@"neworder"]];
  1547. self.btn_newOrder.enabled = true;
  1548. }
  1549. else
  1550. {
  1551. [self.btn_newOrder setImage:nil];
  1552. self.btn_newOrder.enabled = false;
  1553. }
  1554. }
  1555. -(void) refresh_price
  1556. {
  1557. [self refresh_ui];
  1558. }
  1559. @end