NewOtherOutStorageHomeVC.m 12 KB

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