StockViewController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. //
  2. // StockViewController.m
  3. // HMLG Scan Order
  4. //
  5. // Created by Rui Zhang on 6/21/22.
  6. // Copyright © 2022 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "StockViewController.h"
  9. #import "StockTableViewCell.h"
  10. #import "DefaultTableHeaderView.h"
  11. #import "DefaultAppearance.h"
  12. #import "const.h"
  13. #import "RAUtils.h"
  14. @interface StockViewController ()
  15. @end
  16. @implementation StockViewController
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. // Do any additional setup after loading the view.
  20. }
  21. - (IBAction)onSubmit:(id)sender {
  22. NSMutableDictionary* models = [NSMutableDictionary new];
  23. models[@"count"] = @(self.idata.count+self.bdata.count+self.sdata.count);
  24. models[@"title"] =@"Model Information";
  25. int count=0;
  26. for(int i=0;i<self.idata.count;i++)
  27. {
  28. models[[NSString stringWithFormat:@"item_%d",count]]=self.idata[i];
  29. count++;
  30. }
  31. for(int j=0;j<self.bdata.count;j++)
  32. {
  33. models[[NSString stringWithFormat:@"item_%d",count]]=self.bdata[j];
  34. count++;
  35. }
  36. for(int k=0;k<self.sdata.count;k++)
  37. {
  38. models[[NSString stringWithFormat:@"item_%d",count]]=self.sdata[k];
  39. count++;
  40. }
  41. [self dismissViewControllerAnimated:true completion:^{
  42. if(self.returnValue)
  43. self.returnValue(models);
  44. }];
  45. }
  46. - (IBAction)onCancel:(id)sender {
  47. [self dismissViewControllerAnimated:true completion:nil];
  48. }
  49. - (IBAction)onMovebackorder:(id)sender {
  50. UITableViewCell* cell = (UITableViewCell*)((UIButton*)sender).superview.superview;
  51. NSIndexPath * indexPath = [self.table indexPathForCell:cell];
  52. UITableView* tableView = self.table;
  53. NSMutableArray * from;
  54. NSMutableArray * to ;
  55. // int section;
  56. // if(indexPath.section==0)
  57. // {
  58. from = self.idata;
  59. to = self.bdata;
  60. // [tableView beginUpdates];
  61. NSMutableDictionary* content=from[indexPath.row];
  62. content[@"is_back_order"] =@"true";
  63. [from removeObjectAtIndex:indexPath.row];
  64. // [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
  65. for(int i=0;i<to.count;i++)
  66. {
  67. if([to[i][@"model"] isEqualToString:content[@"model"]])
  68. {
  69. to[i][@"count"]=@([to[i][@"count"] intValue]+[content[@"count"] intValue]);
  70. to[i][@"cuft"]=@([to[i][@"count"] intValue] * [to[i][@"unit_cuft"] doubleValue]);
  71. // NSString * mpack=newitem[@"stockUom"];
  72. to[i][@"subtotal_price"] = @([to[i][@"count"] intValue]* [to[i][@"unit_price"] doubleValue]*(1-[to[i][@"discount"] doubleValue]/100.0));
  73. content=nil;
  74. break;
  75. }
  76. }
  77. if(content!=nil)
  78. {
  79. [to insertObject:content atIndex:0];
  80. // NSIndexPath * toIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
  81. // [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:toIndexPath] withRowAnimation:UITableViewRowAnimationFade];
  82. }
  83. // [tableView endUpdates];
  84. // [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:headerIndexPath] withRowAnimation:UITableViewRowAnimationFade];
  85. // [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:headerIndexPath1] withRowAnimation:UITableViewRowAnimationFade];
  86. [tableView reloadData];
  87. }
  88. - (void)setData:(NSMutableArray *)data
  89. {
  90. _data = data;
  91. self.idata = [NSMutableArray new];
  92. self.bdata = [NSMutableArray new];
  93. self.sdata = [NSMutableArray new];
  94. for(int i=0;i<data.count;i++)
  95. {
  96. if( [ data[i][@"is_showroom_order"] boolValue])
  97. {
  98. [_sdata addObject:data[i]];
  99. }
  100. else
  101. {
  102. if( [ data[i][@"is_back_order"] boolValue])
  103. {
  104. [_bdata addObject:data[i]];
  105. }
  106. else{
  107. [_idata addObject:data[i]];
  108. }
  109. }
  110. }
  111. }
  112. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  113. {
  114. return;
  115. //如果两次点击的时间间隔小于1秒,则断定为双击事件
  116. // if(tableView.editing==false)
  117. // return;
  118. // if(self.forNewResult)
  119. // {
  120. // if(indexPath.section==1&&[tableView numberOfRowsInSection:0]>=3)
  121. // return;
  122. // }
  123. // else
  124. // {
  125. // if(indexPath.section==0&&[tableView numberOfRowsInSection:indexPath.section]<=1)
  126. // return;
  127. // }
  128. // int between = 1;
  129. NSUInteger curr = [[NSDate date] timeIntervalSince1970];
  130. if(indexPath.row==self.lasttap.row&&indexPath.section==self.lasttap.section)
  131. {
  132. if (curr-self.taptime<1) {
  133. DebugLog(@"double click!");
  134. self.lasttap =nil;
  135. NSMutableArray * from;
  136. NSMutableArray * to ;
  137. int section;
  138. if(indexPath.section==0)
  139. {
  140. from = self.idata;
  141. to = self.bdata;
  142. section = 1;
  143. }
  144. else
  145. {
  146. from = self.bdata;
  147. to = self.idata;
  148. section = 0;
  149. }
  150. NSIndexPath * toIndexPath = [NSIndexPath indexPathForRow:0 inSection:section];
  151. // NSIndexPath * headerIndexPath = [NSIndexPath indexPathForRow:0 inSection:indexPath.section];
  152. // NSIndexPath * headerIndexPath1 = toIndexPath;
  153. id content=from[indexPath.row];
  154. [tableView beginUpdates];
  155. [from removeObjectAtIndex:indexPath.row];
  156. [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
  157. [to insertObject:content atIndex:0];
  158. [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:toIndexPath] withRowAnimation:UITableViewRowAnimationFade];
  159. [tableView endUpdates];
  160. // [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:headerIndexPath] withRowAnimation:UITableViewRowAnimationFade];
  161. // [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:headerIndexPath1] withRowAnimation:UITableViewRowAnimationFade];
  162. [tableView reloadData];
  163. }
  164. self.taptime = curr;
  165. }
  166. else
  167. {
  168. self.taptime = curr;
  169. self.lasttap = indexPath;
  170. }
  171. }
  172. //
  173. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  174. //{
  175. //// return [super tableview:tableView viewForHeaderInSection:section];
  176. // NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  177. // if(value==nil)
  178. // value=@"";
  179. // unsigned long color = strtoul([value UTF8String],0,16);
  180. //
  181. //
  182. // NSString* btntitle=nil ;
  183. // NSString*labeltitle = nil;
  184. //
  185. //
  186. // labeltitle= [self tableView:tableView titleForHeaderInSection:section];
  187. //
  188. //
  189. // DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  190. // // myView.backgroundColor = [UIColor whiteColor];//UIColorFromRGB(0x996633);;
  191. // myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  192. // myView.layer.shadowColor = [UIColor blackColor].CGColor;
  193. // myView.layer.shadowOffset = CGSizeMake(0, 0);
  194. // myView.layer.shadowOpacity = 0.5;
  195. // myView.layer.shadowRadius = 2.0;
  196. //
  197. // int linespace=0;
  198. // if(section==0)
  199. // linespace=11;
  200. //
  201. //
  202. //
  203. //
  204. // UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 5.5+linespace, 200, 20)];
  205. // titlelabel.textColor=UIColorFromRGB(color);//[UIColor whiteColor];
  206. // titlelabel.backgroundColor = [UIColor clearColor];
  207. // titlelabel.text=NSLocalizedString(labeltitle, nil);
  208. // titlelabel.font = [UIFont boldSystemFontOfSize:20];
  209. // [titlelabel sizeToFit];
  210. // [myView addSubview:titlelabel];
  211. // //
  212. // // UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(300, 0, 90, 22)];
  213. // // contactlabel.textColor=[UIColor whiteColor];
  214. // // contactlabel.backgroundColor = [UIColor clearColor];
  215. // // contactlabel.text=NSLocalizedString(@"Contact", nil);
  216. // // [contactlabel sizeToFit];
  217. // // [myView addSubview:contactlabel];
  218. // //
  219. // //
  220. // // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(400, 0, 90, 22)];
  221. // // modellabel.textColor=[UIColor whiteColor];
  222. // // modellabel.backgroundColor = [UIColor clearColor];
  223. // // modellabel.text=NSLocalizedString(@"Model", nil);
  224. // // [modellabel sizeToFit];
  225. // // [myView addSubview:modellabel];
  226. // //
  227. // // UILabel *pricelabel = [[UILabel alloc] initWithFrame:CGRectMake(500, 0, 90, 22)];
  228. // // pricelabel.textColor=[UIColor whiteColor];
  229. // // pricelabel.backgroundColor = [UIColor clearColor];
  230. // // pricelabel.text=NSLocalizedString(@"Price", nil);
  231. // // [pricelabel sizeToFit];
  232. // // [myView addSubview:pricelabel];
  233. // //
  234. // //
  235. // //
  236. // // UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(630, 0, 90, 22)];
  237. // // timelabel.textColor=[UIColor whiteColor];
  238. // // timelabel.backgroundColor = [UIColor clearColor];
  239. // // timelabel.text=NSLocalizedString(@"Create time", nil);
  240. // // [timelabel sizeToFit];
  241. // // [myView addSubview:timelabel];
  242. // //
  243. // //
  244. // //
  245. // // UILabel *statuslabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 60, 22)];
  246. // // statuslabel.textColor=[UIColor whiteColor];
  247. // // statuslabel.backgroundColor = [UIColor clearColor];
  248. // // statuslabel.text=NSLocalizedString(@"Status", nil);
  249. // // [statuslabel sizeToFit];
  250. // // [myView addSubview:statuslabel];
  251. // //
  252. // myView.backgroundColor = UIColor.lightGrayColor;
  253. //// UIColor * c=myView.backgroundColor;
  254. // return myView;
  255. //}
  256. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  257. if(section==0)
  258. return @"In Stock";
  259. else if(section==1)
  260. return @"Backorder";
  261. else
  262. return @"Backorder-Showroom";
  263. }
  264. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  265. return 3;
  266. }
  267. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  268. if(section==0)
  269. return _idata.count;
  270. else if(section==1)
  271. return _bdata.count;
  272. else return _sdata.count;
  273. }
  274. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  275. StockTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"StockTableViewCell"];
  276. if (!cell) {
  277. cell = [[StockTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"StockTableViewCell"];
  278. }
  279. NSArray* arr;
  280. if(indexPath.section==0)
  281. {
  282. arr = self.idata;
  283. cell.btnMove.hidden = false;
  284. }
  285. else if(indexPath.section==1)
  286. {
  287. arr = self.bdata;
  288. cell.btnMove.hidden = true;
  289. }
  290. else
  291. {
  292. arr = self.sdata;
  293. cell.btnMove.hidden = true;
  294. }
  295. cell.labelModel.text = arr[indexPath.row][@"model"];
  296. cell.labelETD.text = arr[indexPath.row][@"etd"];
  297. cell.labelQTY.text = [arr[indexPath.row][@"count"] stringValue];
  298. return cell;
  299. }
  300. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  301. //{
  302. // if(section==0)
  303. // return 44;
  304. // return 44;
  305. //}
  306. /*
  307. #pragma mark - Navigation
  308. // In a storyboard-based application, you will often want to do a little preparation before navigation
  309. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  310. // Get the new view controller using [segue destinationViewController].
  311. // Pass the selected object to the new view controller.
  312. }
  313. */
  314. @end