NewSalesOutStorageHomeVC.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. //
  2. // NewSalesOutStorageHomeVC.m
  3. // IBOSSmini
  4. //
  5. // Created by guan hong hou on 2018/4/12.
  6. // Copyright © 2018年 elongtian. All rights reserved.
  7. //
  8. #import "NewSalesOutStorageHomeVC.h"
  9. @interface NewSalesOutStorageHomeVC (){
  10. NewSalesOutStorageListVC *newSalesOutStorageListVc;
  11. NewSalesOutStorageGoodsDetailVC *newSalesOutStorageGoodsDetailVc;
  12. }
  13. @end
  14. @implementation NewSalesOutStorageHomeVC
  15. #pragma mark 公共函数
  16. /**
  17. 视图加载完成函数
  18. */
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. [self loadNavStyle];
  22. [self initUI];
  23. }
  24. - (void)didReceiveMemoryWarning {
  25. [super didReceiveMemoryWarning];
  26. }
  27. #pragma mark 委托函数
  28. /**
  29. 保存数据成功回调
  30. @param sender <#sender description#>
  31. */
  32. - (void)onSaveDataLoadFinish:(ASIDownManager *)sender {
  33. NSDictionary *dic = [sender.mWebStr JSONValue];
  34. [self stopLoading];
  35. // 服务器返回数据是否正确
  36. if (dic && [dic isKindOfClass:[NSDictionary class]]) {
  37. // 服务器返回数据状态值
  38. int iStatus = [[dic objectForKey:@"Status"] intValue];
  39. // 服务器返回数据消息
  40. NSString *message=[dic objectForKey:@"Message"];
  41. // 服务器返回数据状态值正确
  42. if (iStatus == 0) {
  43. __weak typeof (self)weakself = self;
  44. //初始化->
  45. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示"
  46. message:@"保存成功!" preferredStyle:
  47. UIAlertControllerStyleAlert ];
  48. // addAction->
  49. [alert addAction:[UIAlertAction actionWithTitle:@"确定"
  50. style:UIAlertActionStyleDefault
  51. handler:^(UIAlertAction *action)
  52. {
  53. [weakself.navigationController popViewControllerAnimated:YES];
  54. //关闭当前页面 刷新一览主界面
  55. if([self.refreshDelegate respondsToSelector:@selector(refreshData)]){
  56. [self.refreshDelegate refreshData];
  57. }
  58. }]];
  59. //展示->
  60. [self presentViewController:alert animated:YES completion:nil];
  61. }
  62. else if(iStatus==ActionResultStatusAuthError
  63. ||iStatus==ActionResultStatusNoLogin
  64. ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
  65. [self showReLoginDialog:message];
  66. }
  67. else{
  68. [self showAlertViewText:message];
  69. }
  70. }
  71. }
  72. /**
  73. 保存数据失败回调
  74. @param sender <#sender description#>
  75. */
  76. - (void)onSaveDataLoadFail:(ASIDownManager *)sender {
  77. [self stopLoading];
  78. [self showAlertViewText:@"加载失败"];
  79. }
  80. #pragma mark 私有函数
  81. /**
  82. 导航按钮样式
  83. */
  84. -(void)loadNavStyle
  85. {
  86. self.navigationItem.title=@"新建销售出库";
  87. //返回
  88. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  89. [button setBackgroundImage:[UIImage imageNamed:@"icon_back"]
  90. forState:UIControlStateNormal];
  91. [button addTarget:self action:@selector(goBack)
  92. forControlEvents:UIControlEventTouchUpInside];
  93. button.frame = CGRectMake(0, 0, 15, 18);
  94. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  95. self.navigationItem.leftBarButtonItem = menuButton;
  96. }
  97. /**
  98. 初始化UI
  99. */
  100. -(void)initUI{
  101. [self.view setBackgroundColor:[UIColor whiteColor]];
  102. self.page = [[PageSwitchView alloc] init];
  103. [self.view addSubview:self.page];
  104. newSalesOutStorageListVc = [[NewSalesOutStorageListVC alloc] init];
  105. newSalesOutStorageListVc.listNavVc=self.navigationController;
  106. newSalesOutStorageGoodsDetailVc = [[NewSalesOutStorageGoodsDetailVC alloc] init];
  107. newSalesOutStorageGoodsDetailVc.salesSlipListVc=newSalesOutStorageListVc;
  108. newSalesOutStorageGoodsDetailVc.nav=self.navigationController;
  109. newSalesOutStorageListVc.goodsDetailVc=newSalesOutStorageGoodsDetailVc;
  110. NSMutableArray *arr=[[NSMutableArray alloc]init];
  111. PageSwitchModel *model = [[PageSwitchModel alloc] init];
  112. model.title = @"销售出库";
  113. model.controller = newSalesOutStorageListVc;
  114. [arr addObject:model];
  115. model = [[PageSwitchModel alloc] init];
  116. model.title = @"商品明细";
  117. model.controller = newSalesOutStorageGoodsDetailVc;
  118. [arr addObject:model];
  119. self.page.datas = arr;
  120. UIView *bottomView= [UIView new];
  121. [self.view addSubview:bottomView];
  122. bottomView.translatesAutoresizingMaskIntoConstraints=NO;
  123. UIView *bottomSeparatorView = [UIView new];
  124. bottomSeparatorView.frame=CGRectMake(0, 0, Screen_Width, 1);
  125. bottomSeparatorView.backgroundColor = LineBackgroundColor;
  126. [bottomView addSubview:bottomSeparatorView];
  127. //提交结算
  128. _btnSave=[UIButton buttonWithType:UIButtonTypeCustom];
  129. [_btnSave setTitle:@"保存" forState:UIControlStateNormal];
  130. [_btnSave setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  131. _btnSave.frame=CGRectMake(20,7, Screen_Width-40,40);
  132. [_btnSave setBackgroundColor:[UIColor colorWithRed:189.0/255.0 green:0 blue:7.0/255.0 alpha:1]];
  133. [_btnSave addTarget:self action:@selector(saveOutStorage) forControlEvents:UIControlEventTouchUpInside];
  134. [bottomView addSubview:_btnSave];
  135. [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_page]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_page)]];
  136. [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[bottomView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(bottomView)]];
  137. NSArray *arr1 = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_page][bottomView(55)]-marg-|" options:0 metrics:@{@"marg":@(SCREENHEIGHT >= 812 ? 34 : 0)} views:NSDictionaryOfVariableBindings(_page,bottomView)];
  138. [self.view addConstraints:arr1];
  139. }
  140. /**
  141. 保存销售出库
  142. */
  143. -(void)saveOutStorage{
  144. [self.view endEditing:YES];
  145. if(newSalesOutStorageGoodsDetailVc.goodsList==nil||newSalesOutStorageGoodsDetailVc.goodsList.count==0){
  146. [self showAlertViewText:@"商品明细不能为空"];
  147. return;
  148. }
  149. for(SalesOutStorageSalesSlipGoodsListModel *goodsListModel in newSalesOutStorageGoodsDetailVc.goodsList){
  150. if(goodsListModel.outGoingQuantity==nil||[goodsListModel.outGoingQuantity isEqualToString:@""]){
  151. [self showAlertViewText:@"出库数量不能为空"];
  152. return;
  153. }
  154. if(goodsListModel.goodsCode==nil||[goodsListModel.goodsCode isEqualToString:@""]){
  155. [self showAlertViewText:@"商品编码不能为空"];
  156. return;
  157. }
  158. if(goodsListModel.onlyCode==nil||[goodsListModel.onlyCode isEqualToString:@""]){
  159. [self showAlertViewText:@"唯一编码不能为空"];
  160. return;
  161. }
  162. if([goodsListModel.outGoingQuantity doubleValue]<=0){
  163. [self showAlertViewText:@"出库数量必须大于零"];
  164. return;
  165. }
  166. if([goodsListModel.outGoingQuantity doubleValue]>[goodsListModel.salesQuantity doubleValue]-[goodsListModel.outQuantity doubleValue]){
  167. [self showAlertViewText:@"出库数量不能大于销售未出库数量"];
  168. return;
  169. }
  170. }
  171. newSalesOutStorageListVc.remarks = newSalesOutStorageListVc.txtRemarks.text;
  172. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  173. [dict setObject:@"SaveSalesInventoryDataIphone" forKey:@"Action"];
  174. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  175. [dict setObject:kkUserCode forKey:@"UserCode"];
  176. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  177. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  178. [dict setObject:[NSString stringWithFormat:@"%d",newSalesOutStorageListVc.salesSlipListModel.status] forKey:@"Status"];
  179. [dict setObject:@"1" forKey:@"IDevicesType"];
  180. [dict setObject:newSalesOutStorageListVc.dockerId==nil?@"":newSalesOutStorageListVc.dockerId forKey:@"Docker"];
  181. [dict setObject:newSalesOutStorageListVc.driverId==nil?@"":newSalesOutStorageListVc.driverId forKey:@"Driver"];
  182. [dict setObject:newSalesOutStorageListVc.remarks==nil?@"":newSalesOutStorageListVc.remarks forKey:@"Remarks"];
  183. [dict setObject:newSalesOutStorageListVc.salesSlipListModel.customerId==nil?@"":newSalesOutStorageListVc.salesSlipListModel.customerId forKey:@"CustomerID"];
  184. [dict setObject:newSalesOutStorageListVc.salesSlipListModel.customerCode==nil?@"":newSalesOutStorageListVc.salesSlipListModel.customerCode forKey:@"CustomerCode"];
  185. [dict setObject:newSalesOutStorageListVc.salesSlipListModel.customerName==nil?@"":newSalesOutStorageListVc.salesSlipListModel.customerName forKey:@"CustomerName"];
  186. [dict setObject:newSalesOutStorageListVc.salesSlipListModel.telephone==nil ?@"" :newSalesOutStorageListVc.salesSlipListModel.telephone forKey:@"Telephone"];
  187. [dict setObject:newSalesOutStorageListVc.salesSlipListModel.contacts==nil?@"":newSalesOutStorageListVc.salesSlipListModel.contacts forKey:@"Contacts"];
  188. [dict setObject:newSalesOutStorageListVc.salesSlipListModel.customerAddress==nil?@"":newSalesOutStorageListVc.salesSlipListModel.customerAddress forKey:@"Address"];
  189. [dict setObject:newSalesOutStorageListVc.salesSlipListModel.staffId==nil?@"":newSalesOutStorageListVc.salesSlipListModel.staffId forKey:@"StaffID"];
  190. [dict setObject:newSalesOutStorageListVc.salesSlipListModel.staffName==nil?@"":newSalesOutStorageListVc.salesSlipListModel.staffName forKey:@"StaffName"];
  191. [dict setObject:newSalesOutStorageListVc.salesSlipListModel.departmentId==nil?@"":newSalesOutStorageListVc.salesSlipListModel.departmentId forKey:@"BusinessOrganizationID"];
  192. [dict setObject:newSalesOutStorageListVc.salesSlipListModel.departmentCode==nil?@"":newSalesOutStorageListVc.salesSlipListModel.departmentCode forKey:@"OrganizationCode"];
  193. [dict setObject:newSalesOutStorageListVc.salesSlipListModel.departmentName==nil?@"":newSalesOutStorageListVc.salesSlipListModel.departmentName forKey:@"OrganizationName"];
  194. NSMutableArray *goodsListArray=[[NSMutableArray alloc]init];
  195. if(newSalesOutStorageGoodsDetailVc.goodsList!=nil&&newSalesOutStorageGoodsDetailVc.goodsList.count>0){
  196. for(SalesOutStorageSalesSlipGoodsListModel *goodsListModel in newSalesOutStorageGoodsDetailVc.goodsList){
  197. NSDictionary *dic=[NSDictionary new];
  198. 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};
  199. [goodsListArray addObject:dic];
  200. }
  201. SBJsonWriter *write = [[SBJsonWriter alloc] init];
  202. NSString *value = [write stringWithObject:goodsListArray];
  203. [dict setObject:value forKeyedSubscript:@"DeliveryDetailData"];
  204. }
  205. [self startLoading];
  206. _downManager = [[ASIDownManager alloc] init];
  207. _downManager.delegate = self;
  208. _downManager.OnImageDown = @selector(onSaveDataLoadFinish:);
  209. _downManager.OnImageFail = @selector(onSaveDataLoadFail:);
  210. [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
  211. }
  212. @end