StockViewController.m 12 KB

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