| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- //
- // NewSalesOutStorageHomeVC.m
- // IBOSSmini
- //
- // Created by guan hong hou on 2018/4/12.
- // Copyright © 2018年 elongtian. All rights reserved.
- //
- #import "NewSalesOutStorageHomeVC.h"
- @interface NewSalesOutStorageHomeVC (){
- NewSalesOutStorageListVC *newSalesOutStorageListVc;
- NewSalesOutStorageGoodsDetailVC *newSalesOutStorageGoodsDetailVc;
- }
- @end
- @implementation NewSalesOutStorageHomeVC
- #pragma mark 公共函数
- /**
- 视图加载完成函数
- */
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self loadNavStyle];
- [self initUI];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
-
- }
- #pragma mark 委托函数
- /**
- 保存数据成功回调
-
- @param sender <#sender description#>
- */
- - (void)onSaveDataLoadFinish:(ASIDownManager *)sender {
- NSDictionary *dic = [sender.mWebStr JSONValue];
- [self stopLoading];
- // 服务器返回数据是否正确
- if (dic && [dic isKindOfClass:[NSDictionary class]]) {
- // 服务器返回数据状态值
- int iStatus = [[dic objectForKey:@"Status"] intValue];
- // 服务器返回数据消息
- NSString *message=[dic objectForKey:@"Message"];
- // 服务器返回数据状态值正确
- if (iStatus == 0) {
-
- __weak typeof (self)weakself = self;
- //初始化->
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示"
- message:@"保存成功!" preferredStyle:
- UIAlertControllerStyleAlert ];
- // addAction->
- [alert addAction:[UIAlertAction actionWithTitle:@"确定"
- style:UIAlertActionStyleDefault
- handler:^(UIAlertAction *action)
- {
-
- [weakself.navigationController popViewControllerAnimated:YES];
- //关闭当前页面 刷新一览主界面
- if([self.refreshDelegate respondsToSelector:@selector(refreshData)]){
- [self.refreshDelegate refreshData];
- }
-
-
-
- }]];
- //展示->
- [self presentViewController:alert animated:YES completion:nil];
- }
-
- else if(iStatus==ActionResultStatusAuthError
- ||iStatus==ActionResultStatusNoLogin
- ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
-
- [self showReLoginDialog:message];
- }
- else{
- [self showAlertViewText:message];
- }
-
- }
- }
- /**
- 保存数据失败回调
- @param sender <#sender description#>
- */
- - (void)onSaveDataLoadFail:(ASIDownManager *)sender {
- [self stopLoading];
- [self showAlertViewText:@"加载失败"];
- }
- #pragma mark 私有函数
- /**
- 导航按钮样式
- */
- -(void)loadNavStyle
- {
- self.navigationItem.title=@"新建销售出库";
- //返回
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- [button setBackgroundImage:[UIImage imageNamed:@"icon_back"]
- forState:UIControlStateNormal];
- [button addTarget:self action:@selector(goBack)
- forControlEvents:UIControlEventTouchUpInside];
- button.frame = CGRectMake(0, 0, 15, 18);
-
- UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
- self.navigationItem.leftBarButtonItem = menuButton;
- }
- /**
- 初始化UI
- */
- -(void)initUI{
-
- [self.view setBackgroundColor:[UIColor whiteColor]];
- self.page = [[PageSwitchView alloc] init];
- [self.view addSubview:self.page];
- newSalesOutStorageListVc = [[NewSalesOutStorageListVC alloc] init];
- newSalesOutStorageListVc.listNavVc=self.navigationController;
-
- newSalesOutStorageGoodsDetailVc = [[NewSalesOutStorageGoodsDetailVC alloc] init];
- newSalesOutStorageGoodsDetailVc.salesSlipListVc=newSalesOutStorageListVc;
- newSalesOutStorageGoodsDetailVc.nav=self.navigationController;
- newSalesOutStorageListVc.goodsDetailVc=newSalesOutStorageGoodsDetailVc;
- NSMutableArray *arr=[[NSMutableArray alloc]init];
-
- PageSwitchModel *model = [[PageSwitchModel alloc] init];
- model.title = @"销售出库";
- model.controller = newSalesOutStorageListVc;
- [arr addObject:model];
- model = [[PageSwitchModel alloc] init];
- model.title = @"商品明细";
- model.controller = newSalesOutStorageGoodsDetailVc;
- [arr addObject:model];
-
- self.page.datas = arr;
- UIView *bottomView= [UIView new];
- [self.view addSubview:bottomView];
- bottomView.translatesAutoresizingMaskIntoConstraints=NO;
- UIView *bottomSeparatorView = [UIView new];
- bottomSeparatorView.frame=CGRectMake(0, 0, Screen_Width, 1);
- bottomSeparatorView.backgroundColor = LineBackgroundColor;
- [bottomView addSubview:bottomSeparatorView];
- //提交结算
- _btnSave=[UIButton buttonWithType:UIButtonTypeCustom];
- [_btnSave setTitle:@"保存" forState:UIControlStateNormal];
- [_btnSave setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- _btnSave.frame=CGRectMake(20,7, Screen_Width-40,40);
- [_btnSave setBackgroundColor:[UIColor colorWithRed:189.0/255.0 green:0 blue:7.0/255.0 alpha:1]];
- [_btnSave addTarget:self action:@selector(saveOutStorage) forControlEvents:UIControlEventTouchUpInside];
- [bottomView addSubview:_btnSave];
- [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_page]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_page)]];
-
- [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[bottomView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(bottomView)]];
- NSArray *arr1 = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_page][bottomView(55)]-marg-|" options:0 metrics:@{@"marg":@(SCREENHEIGHT >= 812 ? 34 : 0)} views:NSDictionaryOfVariableBindings(_page,bottomView)];
-
- [self.view addConstraints:arr1];
- }
- /**
- 保存销售出库
- */
- -(void)saveOutStorage{
- [self.view endEditing:YES];
- if(newSalesOutStorageGoodsDetailVc.goodsList==nil||newSalesOutStorageGoodsDetailVc.goodsList.count==0){
- [self showAlertViewText:@"商品明细不能为空"];
- return;
- }
-
- for(SalesOutStorageSalesSlipGoodsListModel *goodsListModel in newSalesOutStorageGoodsDetailVc.goodsList){
-
- if(goodsListModel.outGoingQuantity==nil||[goodsListModel.outGoingQuantity isEqualToString:@""]){
- [self showAlertViewText:@"出库数量不能为空"];
- return;
- }
- if(goodsListModel.goodsCode==nil||[goodsListModel.goodsCode isEqualToString:@""]){
- [self showAlertViewText:@"商品编码不能为空"];
- return;
- }
- if(goodsListModel.onlyCode==nil||[goodsListModel.onlyCode isEqualToString:@""]){
- [self showAlertViewText:@"唯一编码不能为空"];
- return;
- }
-
- if([goodsListModel.outGoingQuantity doubleValue]<=0){
- [self showAlertViewText:@"出库数量必须大于零"];
- return;
- }
-
- if([goodsListModel.outGoingQuantity doubleValue]>[goodsListModel.salesQuantity doubleValue]-[goodsListModel.outQuantity doubleValue]){
- [self showAlertViewText:@"出库数量不能大于销售未出库数量"];
- return;
- }
- }
-
-
- newSalesOutStorageListVc.remarks = newSalesOutStorageListVc.txtRemarks.text;
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- [dict setObject:@"SaveSalesInventoryDataIphone" forKey:@"Action"];
- [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
- [dict setObject:kkUserCode forKey:@"UserCode"];
- [dict setObject:kkUserPwd forKey:@"UserPassword"];
- [dict setObject:kkSessionKey forKey:@"SessionKey"];
- [dict setObject:[NSString stringWithFormat:@"%d",newSalesOutStorageListVc.salesSlipListModel.status] forKey:@"Status"];
-
- [dict setObject:@"1" forKey:@"IDevicesType"];
- [dict setObject:newSalesOutStorageListVc.dockerId==nil?@"":newSalesOutStorageListVc.dockerId forKey:@"Docker"];
- [dict setObject:newSalesOutStorageListVc.driverId==nil?@"":newSalesOutStorageListVc.driverId forKey:@"Driver"];
- [dict setObject:newSalesOutStorageListVc.remarks==nil?@"":newSalesOutStorageListVc.remarks forKey:@"Remarks"];
- [dict setObject:newSalesOutStorageListVc.salesSlipListModel.customerId==nil?@"":newSalesOutStorageListVc.salesSlipListModel.customerId forKey:@"CustomerID"];
- [dict setObject:newSalesOutStorageListVc.salesSlipListModel.customerCode==nil?@"":newSalesOutStorageListVc.salesSlipListModel.customerCode forKey:@"CustomerCode"];
- [dict setObject:newSalesOutStorageListVc.salesSlipListModel.customerName==nil?@"":newSalesOutStorageListVc.salesSlipListModel.customerName forKey:@"CustomerName"];
- [dict setObject:newSalesOutStorageListVc.salesSlipListModel.telephone==nil ?@"" :newSalesOutStorageListVc.salesSlipListModel.telephone forKey:@"Telephone"];
- [dict setObject:newSalesOutStorageListVc.salesSlipListModel.contacts==nil?@"":newSalesOutStorageListVc.salesSlipListModel.contacts forKey:@"Contacts"];
-
- [dict setObject:newSalesOutStorageListVc.salesSlipListModel.customerAddress==nil?@"":newSalesOutStorageListVc.salesSlipListModel.customerAddress forKey:@"Address"];
- [dict setObject:newSalesOutStorageListVc.salesSlipListModel.staffId==nil?@"":newSalesOutStorageListVc.salesSlipListModel.staffId forKey:@"StaffID"];
- [dict setObject:newSalesOutStorageListVc.salesSlipListModel.staffName==nil?@"":newSalesOutStorageListVc.salesSlipListModel.staffName forKey:@"StaffName"];
-
- [dict setObject:newSalesOutStorageListVc.salesSlipListModel.departmentId==nil?@"":newSalesOutStorageListVc.salesSlipListModel.departmentId forKey:@"BusinessOrganizationID"];
- [dict setObject:newSalesOutStorageListVc.salesSlipListModel.departmentCode==nil?@"":newSalesOutStorageListVc.salesSlipListModel.departmentCode forKey:@"OrganizationCode"];
-
- [dict setObject:newSalesOutStorageListVc.salesSlipListModel.departmentName==nil?@"":newSalesOutStorageListVc.salesSlipListModel.departmentName forKey:@"OrganizationName"];
-
-
- NSMutableArray *goodsListArray=[[NSMutableArray alloc]init];
-
- if(newSalesOutStorageGoodsDetailVc.goodsList!=nil&&newSalesOutStorageGoodsDetailVc.goodsList.count>0){
-
- for(SalesOutStorageSalesSlipGoodsListModel *goodsListModel in newSalesOutStorageGoodsDetailVc.goodsList){
- NSDictionary *dic=[NSDictionary new];
- dic=@{@"InventoryID":goodsListModel.inventoryId,@"CodeID":goodsListModel.codeId,@"DeliveryQuantity":goodsListModel.outGoingQuantity,@"OnlyCode":goodsListModel.onlyCode,@"Specification":goodsListModel.goodsSpecification==nil?@"":goodsListModel.goodsSpecification,@"ColorNumber":goodsListModel.colorNumber,@"GradeName":goodsListModel.gradeName,@"WarehouseID":goodsListModel.warehouseId,@"WarehouseName":goodsListModel.warehouseName,@"SourceDetailID":goodsListModel.detailId,@"PriorColorNumber":goodsListModel.priorColorNumber,@"PriorWarehouseID":goodsListModel.priorWareHouseId,@"PriorPositionNumber":goodsListModel.priorPositionNumber,@"PositionNumber":goodsListModel.positionNumber,@"PriorInventoryID":goodsListModel.priorInventoryId,@"OutQuantity":goodsListModel.outQuantity,@"Remarks":goodsListModel.remark==nil?@"":goodsListModel.remark,@"SalesQuantity":goodsListModel.salesQuantity};
- [goodsListArray addObject:dic];
- }
-
- SBJsonWriter *write = [[SBJsonWriter alloc] init];
- NSString *value = [write stringWithObject:goodsListArray];
- [dict setObject:value forKeyedSubscript:@"DeliveryDetailData"];
- }
-
- [self startLoading];
- _downManager = [[ASIDownManager alloc] init];
- _downManager.delegate = self;
- _downManager.OnImageDown = @selector(onSaveDataLoadFinish:);
- _downManager.OnImageFail = @selector(onSaveDataLoadFail:);
- [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
- }
- @end
|