StockViewController.m 11 KB

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