| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- //
- // StockViewController.m
- // HMLG Scan Order
- //
- // Created by Rui Zhang on 6/21/22.
- // Copyright © 2022 United Software Applications, Inc. All rights reserved.
- //
- #import "StockViewController.h"
- #import "StockTableViewCell.h"
- #import "DefaultTableHeaderView.h"
- #import "DefaultAppearance.h"
- #import "const.h"
- @interface StockViewController ()
- @end
- @implementation StockViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- }
- - (IBAction)onSubmit:(id)sender {
- NSMutableDictionary* models = [NSMutableDictionary new];
- models[@"count"] = @(self.idata.count+self.bdata.count+self.sdata.count);
- models[@"title"] =@"Model Information";
- int count=0;
- for(int i=0;i<self.idata.count;i++)
- {
- models[[NSString stringWithFormat:@"item_%d",count]]=self.idata[i];
- count++;
- }
- for(int j=0;j<self.bdata.count;j++)
- {
- models[[NSString stringWithFormat:@"item_%d",count]]=self.bdata[j];
- count++;
- }
- for(int k=0;k<self.sdata.count;k++)
- {
- models[[NSString stringWithFormat:@"item_%d",count]]=self.sdata[k];
- count++;
- }
-
- [self dismissViewControllerAnimated:true completion:^{
- if(self.returnValue)
- self.returnValue(models);
- }];
-
- }
- - (IBAction)onCancel:(id)sender {
- [self dismissViewControllerAnimated:true completion:nil];
- }
- - (IBAction)onMovebackorder:(id)sender {
-
- UITableViewCell* cell = (UITableViewCell*)((UIButton*)sender).superview.superview;
- NSIndexPath * indexPath = [self.table indexPathForCell:cell];
- UITableView* tableView = self.table;
-
- NSMutableArray * from;
- NSMutableArray * to ;
- // int section;
- // if(indexPath.section==0)
- // {
- from = self.idata;
- to = self.bdata;
-
-
-
-
- // [tableView beginUpdates];
- NSMutableDictionary* content=from[indexPath.row];
- content[@"is_back_order"] =@"true";
- [from removeObjectAtIndex:indexPath.row];
- // [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
- for(int i=0;i<to.count;i++)
- {
- if([to[i][@"model"] isEqualToString:content[@"model"]])
- {
- to[i][@"count"]=@([to[i][@"count"] intValue]+[content[@"count"] intValue]);
- to[i][@"cuft"]=@([to[i][@"count"] intValue] * [to[i][@"unit_cuft"] doubleValue]);
- // NSString * mpack=newitem[@"stockUom"];
-
- to[i][@"subtotal_price"] = @([to[i][@"count"] intValue]* [to[i][@"unit_price"] doubleValue]*(1-[to[i][@"discount"] doubleValue]/100.0));
- content=nil;
- break;
- }
- }
- if(content!=nil)
- {
- [to insertObject:content atIndex:0];
- // NSIndexPath * toIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
- // [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:toIndexPath] withRowAnimation:UITableViewRowAnimationFade];
- }
-
-
- // [tableView endUpdates];
-
- // [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:headerIndexPath] withRowAnimation:UITableViewRowAnimationFade];
- // [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:headerIndexPath1] withRowAnimation:UITableViewRowAnimationFade];
- [tableView reloadData];
-
- }
- - (void)setData:(NSMutableArray *)data
- {
- _data = data;
-
- self.idata = [NSMutableArray new];
- self.bdata = [NSMutableArray new];
- self.sdata = [NSMutableArray new];
- for(int i=0;i<data.count;i++)
- {
- if( [ data[i][@"is_showroom_order"] boolValue])
- {
- [_sdata addObject:data[i]];
- }
- else
- {
- if( [ data[i][@"is_back_order"] boolValue])
- {
- [_bdata addObject:data[i]];
- }
- else{
- [_idata addObject:data[i]];
- }
- }
-
- }
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- return;
- //如果两次点击的时间间隔小于1秒,则断定为双击事件
-
- // if(tableView.editing==false)
- // return;
-
- // if(self.forNewResult)
- // {
- // if(indexPath.section==1&&[tableView numberOfRowsInSection:0]>=3)
- // return;
- // }
- // else
- // {
- // if(indexPath.section==0&&[tableView numberOfRowsInSection:indexPath.section]<=1)
- // return;
- // }
- // int between = 1;
- NSUInteger curr = [[NSDate date] timeIntervalSince1970];
-
- if(indexPath.row==self.lasttap.row&&indexPath.section==self.lasttap.section)
- {
- if (curr-self.taptime<1) {
- DebugLog(@"double click!");
- self.lasttap =nil;
-
- NSMutableArray * from;
- NSMutableArray * to ;
- int section;
- if(indexPath.section==0)
- {
- from = self.idata;
- to = self.bdata;
- section = 1;
- }
- else
- {
-
- from = self.bdata;
- to = self.idata;
- section = 0;
- }
- NSIndexPath * toIndexPath = [NSIndexPath indexPathForRow:0 inSection:section];
- // NSIndexPath * headerIndexPath = [NSIndexPath indexPathForRow:0 inSection:indexPath.section];
- // NSIndexPath * headerIndexPath1 = toIndexPath;
-
- id content=from[indexPath.row];
- [tableView beginUpdates];
- [from removeObjectAtIndex:indexPath.row];
- [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
- [to insertObject:content atIndex:0];
- [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:toIndexPath] withRowAnimation:UITableViewRowAnimationFade];
- [tableView endUpdates];
-
- // [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:headerIndexPath] withRowAnimation:UITableViewRowAnimationFade];
- // [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:headerIndexPath1] withRowAnimation:UITableViewRowAnimationFade];
- [tableView reloadData];
-
- }
- self.taptime = curr;
-
-
- }
- else
- {
- self.taptime = curr;
- self.lasttap = indexPath;
- }
- }
- //
- //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- //{
- //// return [super tableview:tableView viewForHeaderInSection:section];
- // NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
- // if(value==nil)
- // value=@"";
- // unsigned long color = strtoul([value UTF8String],0,16);
- //
- //
- // NSString* btntitle=nil ;
- // NSString*labeltitle = nil;
- //
- //
- // labeltitle= [self tableView:tableView titleForHeaderInSection:section];
- //
- //
- // DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
- // // myView.backgroundColor = [UIColor whiteColor];//UIColorFromRGB(0x996633);;
- // myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
- // myView.layer.shadowColor = [UIColor blackColor].CGColor;
- // myView.layer.shadowOffset = CGSizeMake(0, 0);
- // myView.layer.shadowOpacity = 0.5;
- // myView.layer.shadowRadius = 2.0;
- //
- // int linespace=0;
- // if(section==0)
- // linespace=11;
- //
- //
- //
- //
- // UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 5.5+linespace, 200, 20)];
- // titlelabel.textColor=UIColorFromRGB(color);//[UIColor whiteColor];
- // titlelabel.backgroundColor = [UIColor clearColor];
- // titlelabel.text=NSLocalizedString(labeltitle, nil);
- // titlelabel.font = [UIFont boldSystemFontOfSize:20];
- // [titlelabel sizeToFit];
- // [myView addSubview:titlelabel];
- // //
- // // UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(300, 0, 90, 22)];
- // // contactlabel.textColor=[UIColor whiteColor];
- // // contactlabel.backgroundColor = [UIColor clearColor];
- // // contactlabel.text=NSLocalizedString(@"Contact", nil);
- // // [contactlabel sizeToFit];
- // // [myView addSubview:contactlabel];
- // //
- // //
- // // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(400, 0, 90, 22)];
- // // modellabel.textColor=[UIColor whiteColor];
- // // modellabel.backgroundColor = [UIColor clearColor];
- // // modellabel.text=NSLocalizedString(@"Model", nil);
- // // [modellabel sizeToFit];
- // // [myView addSubview:modellabel];
- // //
- // // UILabel *pricelabel = [[UILabel alloc] initWithFrame:CGRectMake(500, 0, 90, 22)];
- // // pricelabel.textColor=[UIColor whiteColor];
- // // pricelabel.backgroundColor = [UIColor clearColor];
- // // pricelabel.text=NSLocalizedString(@"Price", nil);
- // // [pricelabel sizeToFit];
- // // [myView addSubview:pricelabel];
- // //
- // //
- // //
- // // UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(630, 0, 90, 22)];
- // // timelabel.textColor=[UIColor whiteColor];
- // // timelabel.backgroundColor = [UIColor clearColor];
- // // timelabel.text=NSLocalizedString(@"Create time", nil);
- // // [timelabel sizeToFit];
- // // [myView addSubview:timelabel];
- // //
- // //
- // //
- // // UILabel *statuslabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 60, 22)];
- // // statuslabel.textColor=[UIColor whiteColor];
- // // statuslabel.backgroundColor = [UIColor clearColor];
- // // statuslabel.text=NSLocalizedString(@"Status", nil);
- // // [statuslabel sizeToFit];
- // // [myView addSubview:statuslabel];
- // //
- // myView.backgroundColor = UIColor.lightGrayColor;
- //// UIColor * c=myView.backgroundColor;
- // return myView;
- //}
- - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
-
- if(section==0)
- return @"In Stock";
- else if(section==1)
- return @"Backorder";
- else
- return @"Backorder-Showroom";
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 3;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- if(section==0)
- return _idata.count;
- else if(section==1)
- return _bdata.count;
- else return _sdata.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- StockTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"StockTableViewCell"];
- if (!cell) {
- cell = [[StockTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"StockTableViewCell"];
- }
- NSArray* arr;
- if(indexPath.section==0)
- {
- arr = self.idata;
- cell.btnMove.hidden = false;
- }
- else if(indexPath.section==1)
- {
- arr = self.bdata;
- cell.btnMove.hidden = true;
- }
- else
- {
- arr = self.sdata;
- cell.btnMove.hidden = true;
- }
- cell.labelModel.text = arr[indexPath.row][@"model"];
- cell.labelETD.text = arr[indexPath.row][@"etd"];
- cell.labelQTY.text = [arr[indexPath.row][@"count"] stringValue];
-
- return cell;
- }
- //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- //{
- // if(section==0)
- // return 44;
- // return 44;
- //}
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|