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. //
  115. // return;
  116. // //如果两次点击的时间间隔小于1秒,则断定为双击事件
  117. //
  118. //// if(tableView.editing==false)
  119. //// return;
  120. //
  121. //// if(self.forNewResult)
  122. //// {
  123. //// if(indexPath.section==1&&[tableView numberOfRowsInSection:0]>=3)
  124. //// return;
  125. //// }
  126. //// else
  127. //// {
  128. //// if(indexPath.section==0&&[tableView numberOfRowsInSection:indexPath.section]<=1)
  129. //// return;
  130. //// }
  131. //// int between = 1;
  132. // NSUInteger curr = [[NSDate date] timeIntervalSince1970];
  133. //
  134. // if(indexPath.row==self.lasttap.row&&indexPath.section==self.lasttap.section)
  135. // {
  136. // if (curr-self.taptime<1) {
  137. // DebugLog(@"double click!");
  138. // self.lasttap =nil;
  139. //
  140. // NSMutableArray * from;
  141. // NSMutableArray * to ;
  142. // int section;
  143. // if(indexPath.section==0)
  144. // {
  145. // from = self.idata;
  146. // to = self.bdata;
  147. // section = 1;
  148. // }
  149. // else
  150. // {
  151. //
  152. // from = self.bdata;
  153. // to = self.idata;
  154. // section = 0;
  155. // }
  156. // NSIndexPath * toIndexPath = [NSIndexPath indexPathForRow:0 inSection:section];
  157. //// NSIndexPath * headerIndexPath = [NSIndexPath indexPathForRow:0 inSection:indexPath.section];
  158. //// NSIndexPath * headerIndexPath1 = toIndexPath;
  159. //
  160. // id content=from[indexPath.row];
  161. // [tableView beginUpdates];
  162. // [from removeObjectAtIndex:indexPath.row];
  163. // [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
  164. //
  165. // [to insertObject:content atIndex:0];
  166. // [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:toIndexPath] withRowAnimation:UITableViewRowAnimationFade];
  167. // [tableView endUpdates];
  168. //
  169. //// [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:headerIndexPath] withRowAnimation:UITableViewRowAnimationFade];
  170. //// [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:headerIndexPath1] withRowAnimation:UITableViewRowAnimationFade];
  171. // [tableView reloadData];
  172. //
  173. //
  174. // }
  175. // self.taptime = curr;
  176. //
  177. //
  178. // }
  179. // else
  180. // {
  181. // self.taptime = curr;
  182. // self.lasttap = indexPath;
  183. // }
  184. }
  185. //
  186. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  187. //{
  188. //// return [super tableview:tableView viewForHeaderInSection:section];
  189. // NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  190. // if(value==nil)
  191. // value=@"";
  192. // unsigned long color = strtoul([value UTF8String],0,16);
  193. //
  194. //
  195. // NSString* btntitle=nil ;
  196. // NSString*labeltitle = nil;
  197. //
  198. //
  199. // labeltitle= [self tableView:tableView titleForHeaderInSection:section];
  200. //
  201. //
  202. // DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  203. // // myView.backgroundColor = [UIColor whiteColor];//UIColorFromRGB(0x996633);;
  204. // myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  205. // myView.layer.shadowColor = [UIColor blackColor].CGColor;
  206. // myView.layer.shadowOffset = CGSizeMake(0, 0);
  207. // myView.layer.shadowOpacity = 0.5;
  208. // myView.layer.shadowRadius = 2.0;
  209. //
  210. // int linespace=0;
  211. // if(section==0)
  212. // linespace=11;
  213. //
  214. //
  215. //
  216. //
  217. // UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 5.5+linespace, 200, 20)];
  218. // titlelabel.textColor=UIColorFromRGB(color);//[UIColor whiteColor];
  219. // titlelabel.backgroundColor = [UIColor clearColor];
  220. // titlelabel.text=NSLocalizedString(labeltitle, nil);
  221. // titlelabel.font = [UIFont boldSystemFontOfSize:20];
  222. // [titlelabel sizeToFit];
  223. // [myView addSubview:titlelabel];
  224. // //
  225. // // UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(300, 0, 90, 22)];
  226. // // contactlabel.textColor=[UIColor whiteColor];
  227. // // contactlabel.backgroundColor = [UIColor clearColor];
  228. // // contactlabel.text=NSLocalizedString(@"Contact", nil);
  229. // // [contactlabel sizeToFit];
  230. // // [myView addSubview:contactlabel];
  231. // //
  232. // //
  233. // // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(400, 0, 90, 22)];
  234. // // modellabel.textColor=[UIColor whiteColor];
  235. // // modellabel.backgroundColor = [UIColor clearColor];
  236. // // modellabel.text=NSLocalizedString(@"Model", nil);
  237. // // [modellabel sizeToFit];
  238. // // [myView addSubview:modellabel];
  239. // //
  240. // // UILabel *pricelabel = [[UILabel alloc] initWithFrame:CGRectMake(500, 0, 90, 22)];
  241. // // pricelabel.textColor=[UIColor whiteColor];
  242. // // pricelabel.backgroundColor = [UIColor clearColor];
  243. // // pricelabel.text=NSLocalizedString(@"Price", nil);
  244. // // [pricelabel sizeToFit];
  245. // // [myView addSubview:pricelabel];
  246. // //
  247. // //
  248. // //
  249. // // UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(630, 0, 90, 22)];
  250. // // timelabel.textColor=[UIColor whiteColor];
  251. // // timelabel.backgroundColor = [UIColor clearColor];
  252. // // timelabel.text=NSLocalizedString(@"Create time", nil);
  253. // // [timelabel sizeToFit];
  254. // // [myView addSubview:timelabel];
  255. // //
  256. // //
  257. // //
  258. // // UILabel *statuslabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 60, 22)];
  259. // // statuslabel.textColor=[UIColor whiteColor];
  260. // // statuslabel.backgroundColor = [UIColor clearColor];
  261. // // statuslabel.text=NSLocalizedString(@"Status", nil);
  262. // // [statuslabel sizeToFit];
  263. // // [myView addSubview:statuslabel];
  264. // //
  265. // myView.backgroundColor = UIColor.lightGrayColor;
  266. //// UIColor * c=myView.backgroundColor;
  267. // return myView;
  268. //}
  269. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  270. if(section==0)
  271. return @"In Stock";
  272. else if(section==1)
  273. return @"Backorder";
  274. else
  275. return @"Backorder-Showroom";
  276. }
  277. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  278. return 3;
  279. }
  280. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  281. if(section==0)
  282. return _idata.count;
  283. else if(section==1)
  284. return _bdata.count;
  285. else return _sdata.count;
  286. }
  287. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  288. StockTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"StockTableViewCell"];
  289. if (!cell) {
  290. cell = [[StockTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"StockTableViewCell"];
  291. }
  292. NSArray* arr;
  293. if(indexPath.section==0)
  294. {
  295. arr = self.idata;
  296. cell.btnMove.hidden = false;
  297. }
  298. else if(indexPath.section==1)
  299. {
  300. arr = self.bdata;
  301. cell.btnMove.hidden = true;
  302. }
  303. else
  304. {
  305. arr = self.sdata;
  306. cell.btnMove.hidden = true;
  307. }
  308. cell.labelModel.text = arr[indexPath.row][@"model"];
  309. cell.labelETD.text = arr[indexPath.row][@"etd"];
  310. cell.labelQTY.text = [arr[indexPath.row][@"count"] stringValue];
  311. return cell;
  312. }
  313. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  314. //{
  315. // if(section==0)
  316. // return 44;
  317. // return 44;
  318. //}
  319. /*
  320. #pragma mark - Navigation
  321. // In a storyboard-based application, you will often want to do a little preparation before navigation
  322. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  323. // Get the new view controller using [segue destinationViewController].
  324. // Pass the selected object to the new view controller.
  325. }
  326. */
  327. @end