SalesSlipReceivablesVC.m 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. //
  2. // SalesSlipReceivablesVCViewController.m
  3. // IBOSSmini
  4. //
  5. // Created by guan hong hou on 2018/4/8.
  6. // Copyright © 2018年 elongtian. All rights reserved.
  7. //
  8. #import "SalesSlipReceivablesVC.h"
  9. @interface SalesSlipReceivablesVC ()
  10. @end
  11. @implementation SalesSlipReceivablesVC
  12. #pragma mark - 公共函数
  13. /**
  14. 视图加载完成
  15. */
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. [self loadNavStyle];
  19. [self initUI];
  20. if([_salesSlipModel.finalReceivableAmount doubleValue]>0){
  21. [self loadEarnestDataSource];
  22. }
  23. else if([_salesSlipModel.finalReceivables doubleValue]<0){
  24. _lblAvailablePredeposit.text=@"0.0000";
  25. _lblSubtractionPredeposit.userInteractionEnabled=NO;
  26. [self loadSettlementMethodDataSource];
  27. }
  28. }
  29. /**
  30. 修改:2017-9-25
  31. 适配机型
  32. 安全区视图发生变化
  33. */
  34. -(void)viewSafeAreaInsetsDidChange{
  35. self.view.backgroundColor = [UIColor whiteColor];
  36. _scrollView.frame=CGRectMake(0,0, Screen_Width, self.view.safeAreaLayoutGuide.layoutFrame.size.height-50);
  37. _btnSave.frame=CGRectMake(20,self.view.safeAreaLayoutGuide.layoutFrame.size.height-50, Screen_Width-40,50) ;
  38. [super viewSafeAreaInsetsDidChange];
  39. }
  40. #pragma mark - 委托函数
  41. /**
  42. 结算方式回调函数
  43. @param collectAmountModel <#collectAmountModel description#>
  44. */
  45. -(void)callbackSettlementMethod:(CollecteAmountModel *) collectAmountModel{
  46. _settlementTypeId=collectAmountModel.settlementTypeID;
  47. _lblSettlementMethod.text=collectAmountModel.settlementTypeName;
  48. }
  49. /**
  50. 冲减预存回调
  51. @param arry <#arry description#>
  52. */
  53. -(void)callbackUseStorageAmount:(NSMutableArray *)arry{
  54. double sum = 0;
  55. _useStorageCheckedList = arry;
  56. for(UseStorageModel *model in _useStorageCheckedList){
  57. NSString *earnestSum = model.earnestSum;
  58. double earnestSumValue = [earnestSum doubleValue];
  59. if(earnestSumValue > 0){
  60. sum+=earnestSumValue;
  61. }
  62. }
  63. NSString *sumStr=[NSString stringWithFormat:@"%.4f",sum];
  64. _lblSubtractionPredeposit.text = sumStr;
  65. }
  66. /**
  67. 冲减预存加载完成
  68. @param sender <#sender description#>
  69. */
  70. -(void)onEarnestLoadFinish:(ASIDownManager *)sender{
  71. NSDictionary *dic = [sender.mWebStr JSONValue];
  72. [self stopLoading];
  73. // 服务器返回数据是否正确
  74. if (dic && [dic isKindOfClass:[NSDictionary class]]) {
  75. // 服务器返回数据状态值
  76. int iStatus = [[dic objectForKey:@"Status"] intValue];
  77. // 服务器返回数据消息
  78. NSString *message=[dic objectForKey:@"Message"];
  79. // 服务器返回数据状态值正确
  80. if (iStatus == 0) {
  81. NSArray * infoArr=[dic objectForKey:@"Result"];
  82. if(infoArr!=nil&& infoArr.count>0)
  83. {
  84. _useStorageList=[[NSMutableArray alloc]init];
  85. for (int i = 0; i < infoArr.count; i++) {
  86. NSDictionary *dic=infoArr[i];
  87. UseStorageModel *model = [[UseStorageModel alloc] init];
  88. model.waitAuditSum = [NSString stringWithFormat:@"%.4f",[[dic objectForKey: @"WaitAuditSum"] doubleValue]];
  89. model.settlementType = [dic objectForKey: @"SettlementType"];
  90. model.settlementTypeName = [dic objectForKey: @"SettlementTypeName"];
  91. model.waitSetPrestore =[NSString stringWithFormat:@"%.4f",[[dic objectForKey: @"WaitSetPrestore"] doubleValue]] ;
  92. model.prestoreSum = [NSString stringWithFormat:@"%.4f",[[dic objectForKey: @"PrestoreSum"] doubleValue]];
  93. model.freezeSum = [NSString stringWithFormat:@"%.4f",[[dic objectForKey: @"FreezeSum"] doubleValue]];
  94. model.unusedEarnest = [NSString stringWithFormat:@"%.4f",[[dic objectForKey: @"UnusedEarnest"] doubleValue]];
  95. model.earnestSum = [NSString stringWithFormat:@"%.4f",[[dic objectForKey: @"EarnestSum"] doubleValue]];
  96. model.organizationID = [NSString stringWithFormat:@"%@",[dic objectForKey: @"OrganizationID"]];
  97. model.objectType = [dic objectForKey: @"ObjectType"];
  98. model.objectID = [NSString stringWithFormat:@"%@",[dic objectForKey: @"ObjectID"]];
  99. [_useStorageList addObject:model];
  100. }
  101. double sum=0;
  102. for(UseStorageModel *model in _useStorageList){
  103. NSString *unusedEarnestSum = model.unusedEarnest;
  104. double unusedEarnestSumValue = [unusedEarnestSum doubleValue];
  105. sum+=unusedEarnestSumValue;
  106. }
  107. NSString *sumStr=[NSString stringWithFormat:@"%.4f",sum];
  108. _lblAvailablePredeposit.text = sumStr;
  109. }
  110. else{
  111. _lblAvailablePredeposit.text=@"0.0000";
  112. }
  113. }
  114. else if(iStatus==ActionResultStatusAuthError
  115. ||iStatus==ActionResultStatusNoLogin
  116. ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
  117. [self showReLoginDialog:message];
  118. }
  119. else{
  120. [self showAlertViewText:message];
  121. }
  122. [self loadSettlementMethodDataSource];
  123. }
  124. }
  125. /**
  126. 冲减预存加载失败
  127. @param sender <#sender description#>
  128. */
  129. -(void)onEarnestLoadFail:(ASIDownManager *)sender{
  130. [self stopLoading];
  131. [self showAlertViewText:@"加载失败"];
  132. }
  133. /**
  134. 保存成功加载完成
  135. @param sender <#sender description#>
  136. */
  137. -(void)onLoadFinish:(ASIDownManager *)sender{
  138. NSDictionary *dic = [sender.mWebStr JSONValue];
  139. [self stopLoading];
  140. // 服务器返回数据是否正确
  141. if (dic && [dic isKindOfClass:[NSDictionary class]]) {
  142. // 服务器返回数据状态值
  143. int iStatus = [[dic objectForKey:@"Status"] intValue];
  144. // 服务器返回数据消息
  145. NSString *message=[dic objectForKey:@"Message"];
  146. // 服务器返回数据状态值正确
  147. if (iStatus == 0) {
  148. //初始化->
  149. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示"
  150. message:@"保存成功!" preferredStyle:
  151. UIAlertControllerStyleAlert ];
  152. // addAction->
  153. [alert addAction:[UIAlertAction actionWithTitle:@"确定"
  154. style:UIAlertActionStyleDefault
  155. handler:^(UIAlertAction *action)
  156. {
  157. if([self.refreshDelegate respondsToSelector:@selector(refreshData)])
  158. {
  159. [self.refreshDelegate refreshData];
  160. }
  161. [self.navigationController popViewControllerAnimated:YES];
  162. }]];
  163. //展示->
  164. [self presentViewController:alert animated:YES completion:nil];
  165. }
  166. else if(iStatus==ActionResultStatusAuthError
  167. ||iStatus==ActionResultStatusNoLogin
  168. ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
  169. [self showReLoginDialog:message];
  170. }
  171. else{
  172. [self showAlertViewText:message];
  173. }
  174. }
  175. }
  176. /**
  177. 保存加载失败
  178. @param sender <#sender description#>
  179. */
  180. -(void)onLoadFail:(ASIDownManager *)sender{
  181. [self stopLoading];
  182. [self showAlertViewText:@"加载失败"];
  183. }
  184. -(void)onSettlementMethodLoadFinish:(ASIDownManager *)sender{
  185. NSDictionary *dic = [sender.mWebStr JSONValue];
  186. [self stopLoading];
  187. // 服务器返回数据是否正确
  188. if (dic && [dic isKindOfClass:[NSDictionary class]]) {
  189. // 服务器返回数据状态值
  190. int iStatus = [[dic objectForKey:@"Status"] intValue];
  191. // 服务器返回数据消息
  192. NSString *message=[dic objectForKey:@"Message"];
  193. // 服务器返回数据状态值正确
  194. if (iStatus == 0) {
  195. NSArray * infoArr=[dic objectForKey:@"Result"];
  196. if(infoArr!=nil&& infoArr.count>0)
  197. {
  198. _settlementMethodList=[[NSMutableArray alloc]init];
  199. for (int i = 0; i < infoArr.count; i++) {
  200. NSDictionary *dic=infoArr[i];
  201. CollecteAmountModel *model = [[CollecteAmountModel alloc] init];
  202. model.settlementTypeName = [dic objectForKey:@"SettlementTypeName"];
  203. model.settlementTypeID = [NSString stringWithFormat:@"%@",[dic objectForKey:@"SettlementType"]];
  204. [_settlementMethodList addObject:model];
  205. }
  206. CollecteAmountModel *collectModel=[_settlementMethodList objectAtIndex:0];
  207. _lblSettlementMethod.text=collectModel.settlementTypeName;
  208. _settlementTypeId=collectModel.settlementTypeID;
  209. }
  210. }
  211. else if(iStatus==ActionResultStatusAuthError
  212. ||iStatus==ActionResultStatusNoLogin
  213. ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
  214. [self showReLoginDialog:message];
  215. }
  216. else{
  217. [self showAlertViewText:message];
  218. }
  219. }
  220. }
  221. -(void)onSettlementMethodLoadFail:(ASIDownManager *)sender{
  222. [self stopLoading];
  223. [self showAlertViewText:@"加载失败"];
  224. }
  225. #pragma mark - 私有函数
  226. /**
  227. 导航按钮样式
  228. */
  229. -(void)loadNavStyle
  230. {
  231. self.navigationItem.title=@"新建应收款";
  232. //返回
  233. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  234. [button setBackgroundImage:[UIImage imageNamed:@"icon_back"]
  235. forState:UIControlStateNormal];
  236. [button addTarget:self action:@selector(goBack)
  237. forControlEvents:UIControlEventTouchUpInside];
  238. button.frame = CGRectMake(0, 0, 15, 18);
  239. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  240. self.navigationItem.leftBarButtonItem = menuButton;
  241. }
  242. /**
  243. 返回
  244. */
  245. - (void)goBack
  246. {
  247. [self.navigationController popViewControllerAnimated:YES];
  248. }
  249. /**
  250. 初始化UI
  251. */
  252. -(void)initUI{
  253. [self.view setBackgroundColor:[UIColor whiteColor]];
  254. _scrollView=[UIScrollView new];
  255. _scrollView.frame=CGRectZero;
  256. [self.view addSubview:_scrollView];
  257. _vBody=[UIView new];
  258. _vBody.frame=CGRectZero;
  259. [_scrollView addSubview:_vBody];
  260. _scrollView.delegate=self;
  261. UITapGestureRecognizer* gesture=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKey)];
  262. [self.view addGestureRecognizer:gesture];
  263. UILabel *lblTitleBasicInfo=[[UILabel alloc]init];
  264. lblTitleBasicInfo.frame=CGRectMake(15,16, 100, 25);
  265. lblTitleBasicInfo.text = @"基础信息";
  266. lblTitleBasicInfo.textColor=[UIColor redColor];
  267. lblTitleBasicInfo.font= [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  268. [_vBody addSubview:lblTitleBasicInfo];
  269. UIView *separator1 = [UIView new];
  270. separator1.backgroundColor=LineBackgroundColor;
  271. separator1.frame=CGRectMake(0,CGRectGetMaxY(lblTitleBasicInfo.frame)+3,Screen_Width, 1);
  272. [_vBody addSubview:separator1];
  273. _vBody.frame=CGRectMake(0,0,Screen_Width, CGRectGetMaxY(separator1.frame));
  274. UIView *vSalesNo=[UIView new];
  275. vSalesNo.frame=CGRectMake(0, CGRectGetMaxY(separator1.frame),Screen_Width, 51);
  276. [_vBody addSubview:vSalesNo];
  277. _lblSalesNo=[self getUILabel:vSalesNo labelText:@"销售单号" hintText:@"" labelColor:[UIColor blackColor] isHaveRightArrow:NO tag:1000];
  278. _lblSalesNo.text=_salesSlipModel.SalesNo;
  279. UIView *vCustomerCode=[UIView new];
  280. vCustomerCode.frame=CGRectMake(0, CGRectGetMaxY(vSalesNo.frame),Screen_Width, 51);
  281. [_vBody addSubview:vCustomerCode];
  282. _lblCustomerCode=[self getUILabel:vCustomerCode labelText:@"客户编码" hintText:@"" labelColor:[UIColor blackColor] isHaveRightArrow:NO tag:1001];
  283. _lblCustomerCode.text=_salesSlipModel.customerCode;
  284. _customerId=_salesSlipModel.customerId;
  285. UIView *vDepartment=[UIView new];
  286. vDepartment.frame=CGRectMake(0, CGRectGetMaxY(vCustomerCode.frame),Screen_Width, 51);
  287. [_vBody addSubview:vDepartment];
  288. _lblDepartment=[self getUILabel:vDepartment labelText:@"业务部门" hintText:@"" labelColor:[UIColor blackColor] isHaveRightArrow:NO tag:1002];
  289. _lblDepartment.text=_salesSlipModel.organizationName;
  290. _organizationId=_salesSlipModel.organizationId;
  291. _salesId=_salesSlipModel.salesId;
  292. UIView *vBusinessType=[UIView new];
  293. vBusinessType.frame=CGRectMake(0, CGRectGetMaxY(vDepartment.frame),Screen_Width, 51);
  294. [_vBody addSubview:vBusinessType];
  295. _lblBusinessType=[self getUILabel:vBusinessType labelText:@"业务类型" hintText:@"" labelColor:[UIColor blackColor] isHaveRightArrow:NO tag:1003];
  296. _lblBusinessType.text=_salesSlipModel.salesTypeName;
  297. UIView *vCustomerName=[UIView new];
  298. vCustomerName.frame=CGRectMake(0, CGRectGetMaxY(vBusinessType.frame),Screen_Width, 51);
  299. [_vBody addSubview:vCustomerName];
  300. _lblCustomerName=[self getUILabel:vCustomerName labelText:@"客户名称" hintText:@"" labelColor:[UIColor blackColor] isHaveRightArrow:NO tag:1004];
  301. _lblCustomerName.text=_salesSlipModel.customerName;
  302. UIView *vSalesMan=[UIView new];
  303. vSalesMan.frame=CGRectMake(0, CGRectGetMaxY(vCustomerName.frame),Screen_Width, 51);
  304. [_vBody addSubview:vSalesMan];
  305. _lblSalesMan=[self getUILabel:vSalesMan labelText:@"业 务 员" hintText:@"" labelColor:[UIColor blackColor] isHaveRightArrow:NO tag:1005];
  306. _lblSalesMan.text=_salesSlipModel.staffName;
  307. _salesmanId=_salesSlipModel.staffId;
  308. // UIView *vRemarks=[UIView new];
  309. // vRemarks.frame=CGRectMake(0, CGRectGetMaxY(vSalesMan.frame),Screen_Width, 51);
  310. // [_vBody addSubview:vRemarks];
  311. // _txtRemarks=[self getTextField:vRemarks labelText:@"备 注" hintText:@"请输入备注" labelColor:[UIColor blackColor] tag:1006];
  312. // _txtRemarks.enabled=NO;
  313. UILabel *lblTitleAmountInfo=[[UILabel alloc]init];
  314. lblTitleAmountInfo.frame=CGRectMake(15,CGRectGetMaxY(vSalesMan.frame)+16, 100, 25);
  315. lblTitleAmountInfo.text = @"金额信息";
  316. lblTitleAmountInfo.textColor=[UIColor redColor];
  317. lblTitleAmountInfo.font= [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  318. [_vBody addSubview:lblTitleAmountInfo];
  319. UIView *separator2 = [UIView new];
  320. separator2.backgroundColor=LineBackgroundColor;
  321. separator2.frame=CGRectMake(0,CGRectGetMaxY(lblTitleAmountInfo.frame)+3,Screen_Width, 1);
  322. [_vBody addSubview:separator2];
  323. UIView *vAmountCollected=[UIView new];
  324. vAmountCollected.frame=CGRectMake(0, CGRectGetMaxY(separator2.frame),Screen_Width, 51);
  325. [_vBody addSubview:vAmountCollected];
  326. _txtAmountCollected=[self getTextField:vAmountCollected labelText:@"收款金额" hintText:@"请输入收款金额" labelColor:[UIColor redColor] tag:1007];
  327. _txtAmountCollected.keyboardType=UIKeyboardTypeDecimalPad;
  328. _txtAmountCollected.text=_salesSlipModel.finalReceivableAmount;
  329. UIView *vSettlementMethod=[UIView new];
  330. vSettlementMethod.frame=CGRectMake(0, CGRectGetMaxY(vAmountCollected.frame),Screen_Width, 51);
  331. [_vBody addSubview:vSettlementMethod];
  332. _lblSettlementMethod=[self getUILabel:vSettlementMethod labelText:@"结算方式" hintText:@"请选择结算方式" labelColor:[UIColor redColor] isHaveRightArrow:YES tag:1009];
  333. UITapGestureRecognizer *tapGesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(goSettlementMethod:)];
  334. [_lblSettlementMethod addGestureRecognizer:tapGesture];
  335. [tapGesture setNumberOfTapsRequired:1];
  336. UIView *vSubtractionPredeposit=[UIView new];
  337. vSubtractionPredeposit.frame=CGRectMake(0, CGRectGetMaxY(vSettlementMethod.frame),Screen_Width, 51);
  338. [_vBody addSubview:vSubtractionPredeposit];
  339. _lblSubtractionPredeposit=[self getUILabel:vSubtractionPredeposit labelText:@"冲减预存" hintText:@"请选择冲减预存" labelColor:[UIColor blackColor] isHaveRightArrow:YES tag:1010];
  340. UITapGestureRecognizer *tapGesture1=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(goSubtractionPredeposit:)];
  341. [_lblSubtractionPredeposit addGestureRecognizer:tapGesture1];
  342. [tapGesture1 setNumberOfTapsRequired:1];
  343. UIView *vAmountReceivable=[UIView new];
  344. vAmountReceivable.frame=CGRectMake(0, CGRectGetMaxY(vSubtractionPredeposit.frame),Screen_Width, 51);
  345. [_vBody addSubview:vAmountReceivable];
  346. _lblAmountReceivable=[self getUILabel:vAmountReceivable labelText:@"应收金额" hintText:@"" labelColor:[UIColor blackColor] isHaveRightArrow:NO tag:1008];
  347. _lblAmountReceivable.text=_salesSlipModel.accountReceivableAmount;
  348. UIView *vAmountReceived=[UIView new];
  349. vAmountReceived.frame=CGRectMake(0, CGRectGetMaxY(vAmountReceivable.frame),Screen_Width, 51);
  350. [_vBody addSubview:vAmountReceived];
  351. _lblAmountReceived=[self getUILabel:vAmountReceived labelText:@"已收金额" hintText:@"" labelColor:[UIColor blackColor] isHaveRightArrow:NO tag:1011];
  352. _lblAmountReceived.text=_salesSlipModel.receivablePayAmount;
  353. UIView *vCancellationAmount=[UIView new];
  354. vCancellationAmount.frame=CGRectMake(0, CGRectGetMaxY(vAmountReceived.frame),Screen_Width, 51);
  355. [_vBody addSubview:vCancellationAmount];
  356. _lblCancellationAmount=[self getUILabel:vCancellationAmount labelText:@"核销金额" hintText:@"" labelColor:[UIColor blackColor] isHaveRightArrow:NO tag:1012];
  357. _lblCancellationAmount.text=_salesSlipModel.verificationSum;
  358. UIView *vRemainderReceivables=[UIView new];
  359. vRemainderReceivables.frame=CGRectMake(0, CGRectGetMaxY(vCancellationAmount.frame),Screen_Width, 51);
  360. [_vBody addSubview:vRemainderReceivables];
  361. _lblRemainderReceivables=[self getUILabel:vRemainderReceivables labelText:@"剩余应收" hintText:@"" labelColor:[UIColor blackColor] isHaveRightArrow:NO tag:1013];
  362. _lblRemainderReceivables.text=_salesSlipModel.finalReceivableAmount;
  363. UIView *vAvailablePredeposit=[UIView new];
  364. vAvailablePredeposit.frame=CGRectMake(0, CGRectGetMaxY(vRemainderReceivables.frame),Screen_Width, 51);
  365. [_vBody addSubview:vAvailablePredeposit];
  366. _lblAvailablePredeposit=[self getUILabel:vAvailablePredeposit labelText:@"可用预存" hintText:@"" labelColor:[UIColor blackColor] isHaveRightArrow:NO tag:1014];
  367. UIImage *pic=[UIImage imageNamed:@"bt_datasave"];
  368. CGFloat h = (Screen_Width-40)*pic.size.height/pic.size.width;
  369. _vBody.frame=CGRectMake(0,0,Screen_Width, CGRectGetMaxY(vAvailablePredeposit.frame));
  370. _scrollView.contentSize = CGSizeMake(self.view.frame.size.width, CGRectGetMaxY(_vBody.frame)+rectStatusHeight+rectNavHeight+20);
  371. _scrollView.frame=CGRectMake(0,0, Screen_Width, Screen_Height-50);
  372. //保存按钮
  373. _btnSave=[UIButton buttonWithType:UIButtonTypeCustom];
  374. _btnSave.frame=CGRectMake(20, Screen_Height- h - 5 - rectStatusHeight-rectNavHeight, Screen_Width-40,h) ;
  375. [_btnSave setBackgroundImage:pic forState:UIControlStateNormal];
  376. [_btnSave addTarget:self action:@selector(dataSave) forControlEvents:UIControlEventTouchUpInside];
  377. [self.view addSubview:_btnSave];
  378. }
  379. /**
  380. 保存函数
  381. */
  382. -(void)dataSave{
  383. NSString *businessTypeName= _lblBusinessType.text;
  384. NSString *remainderReceivable=_lblRemainderReceivables.text;
  385. NSString *amountReceivable=_lblAmountReceivable.text;
  386. NSString *amountReceived=_lblAmountReceived.text;
  387. NSString *verificationAmount=_lblCancellationAmount.text;
  388. if(remainderReceivable==nil||[remainderReceivable isEqualToString:@""]){
  389. [self showAlertViewText:@"剩余应收不能为空"];
  390. return;
  391. }
  392. NSString *amountCollected=_txtAmountCollected.text;
  393. if(amountCollected==nil||[amountCollected isEqualToString:@""]){
  394. [self showAlertViewText:@"收款金额不能为空"];
  395. return;
  396. }
  397. if(![RegularExpression isLegalAmount:amountCollected]){
  398. [self showAlertViewText:@"收款金额格式不正确"];
  399. return;
  400. }
  401. NSString *settlementMethod= _lblSettlementMethod.text;
  402. if(settlementMethod==nil||[settlementMethod isEqualToString:@""]){
  403. [self showAlertViewText:@"请选择结算方式"];
  404. return;
  405. }
  406. else if([settlementMethod isEqualToString:@"请选择结算方式"]){
  407. [self showAlertViewText:@"请选择结算方式"];
  408. return;
  409. }
  410. if([remainderReceivable doubleValue]<0){
  411. double remainderReceivableValue=[remainderReceivable doubleValue];
  412. double amountCollectedValue=[amountCollected doubleValue];
  413. if(amountCollectedValue>0){
  414. [self showAlertViewText:@"收款金额只能为负数"];
  415. return;
  416. }
  417. else{
  418. remainderReceivableValue=fabs([remainderReceivable doubleValue]);
  419. amountCollectedValue=fabs([amountCollected doubleValue]);
  420. if(amountCollectedValue>remainderReceivableValue){
  421. [self showAlertViewText:@"收款金额不能大于剩余应收"];
  422. return;
  423. }
  424. }
  425. }
  426. else{
  427. double remainderReceivableValue=[remainderReceivable doubleValue];
  428. double amountCollectedValue=[amountCollected doubleValue];
  429. if(amountCollectedValue>remainderReceivableValue){
  430. [self showAlertViewText:@"收款金额不能大于剩余应收"];
  431. return;
  432. }
  433. }
  434. NSString *useDeposit=_lblSubtractionPredeposit.text;
  435. if(useDeposit==nil||[useDeposit isEqualToString:@""]){
  436. useDeposit=@"0";
  437. }
  438. else if([useDeposit isEqualToString:@"请选择冲减预存"]){
  439. useDeposit=@"0";
  440. }
  441. [self startLoading];
  442. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  443. [dict setObject:@"SaveReceivablesPayIphone" forKey:@"Action"];
  444. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  445. [dict setObject:kkUserCode forKey:@"UserCode"];
  446. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  447. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  448. [dict setObject:businessTypeName forKey:@"SalesTypeName"];
  449. [dict setObject:_organizationId forKey:@"BusinessOrganization"];
  450. [dict setObject:_salesId forKey:@"InvoiceID"];
  451. [dict setObject:_customerId forKey:@"ObjectID"];
  452. [dict setObject:remainderReceivable forKey:@"LeftReceivable"];
  453. [dict setObject:_settlementTypeId forKey:@"SettlementType"];
  454. [dict setObject:amountCollected forKey:@"TotalPaySum"];
  455. [dict setObject:useDeposit forKey:@"UseDepositAmount"];
  456. NSMutableArray *useStorageArray=[[NSMutableArray alloc]init];
  457. NSString *useStorageValue=@"";
  458. if(_useStorageCheckedList != nil && _useStorageCheckedList.count > 0){
  459. for (UseStorageModel *model in _useStorageCheckedList) {
  460. if([model.earnestSum doubleValue]>0){
  461. NSDictionary *dic=[NSDictionary new];
  462. dic = @{@"SettlementType":model.settlementType,
  463. @"EarnestSum":model.earnestSum,
  464. @"Remarks":model.remarks==nil?@"":model.remarks,
  465. };
  466. [useStorageArray addObject: dic];
  467. }
  468. }
  469. SBJsonWriter *write =[[SBJsonWriter alloc] init];
  470. useStorageValue = [write stringWithObject:useStorageArray];
  471. [dict setObject:useStorageValue forKeyedSubscript:@"UseDepositDetail"];
  472. }
  473. NSMutableArray *receivablesPayDetailArray=[[NSMutableArray alloc]init];
  474. NSDictionary *receivablesPayDetailDic=[NSDictionary new];
  475. receivablesPayDetailDic = @{@"AccountDetailType":@"7",@"InvoiceID":_salesId,@"SalesMan":_salesmanId,@"AccountReceivableAmount":amountReceivable,@"ReceivablePayAmount":amountCollected,@"ReceivablePayedAmount":amountReceived,@"VerificationSum":verificationAmount,@"UseDeposit":useDeposit,@"Remarks":@""};
  476. [receivablesPayDetailArray addObject:receivablesPayDetailDic];
  477. SBJsonWriter *write =[[SBJsonWriter alloc] init];
  478. NSString *receivablesPayDetail = [write stringWithObject:receivablesPayDetailArray];
  479. [dict setObject:receivablesPayDetail forKeyedSubscript:@"ReceivablesPayDetail"];
  480. _downManager = [[ASIDownManager alloc] init];
  481. _downManager.delegate = self;
  482. _downManager.OnImageDown = @selector(onLoadFinish:);
  483. _downManager.OnImageFail = @selector(onLoadFail:);
  484. [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
  485. }
  486. /**
  487. 跳转到冲减预存
  488. @param gesture <#gesture description#>
  489. */
  490. -(void)goSubtractionPredeposit:(UITapGestureRecognizer *)gesture{
  491. if(_useStorageList==nil||_useStorageList.count==0){
  492. return;
  493. }
  494. if(_useStorageCheckedList==nil||_useStorageCheckedList.count==0){
  495. _useStorageCheckedList=_useStorageList;
  496. }
  497. UseStorageVC *vc = [[UseStorageVC alloc] init];
  498. vc.organizationID = _organizationId;
  499. vc.customerID = _customerId;
  500. vc.earnestList = _useStorageCheckedList;
  501. vc.useEarnestAmountDelegate = self;
  502. [self.navigationController pushViewController:vc animated:YES];
  503. }
  504. /**
  505. 使用定金
  506. */
  507. -(void)loadEarnestDataSource{
  508. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  509. [dict setObject:@"GetAccountPrestoreDataIphone" forKey:@"Action"];
  510. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  511. [dict setObject:kkUserCode forKey:@"UserCode"];
  512. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  513. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  514. [dict setObject:_organizationId==nil?@"":_organizationId forKey:@"OrganizationID"];
  515. [dict setObject:_customerId==nil?@"":_customerId forKey:@"CustomerID"];
  516. [dict setObject:@"" forKey:@"SalesID"];
  517. _downManager = [[ASIDownManager alloc] init];
  518. _downManager.delegate = self;
  519. _downManager.OnImageDown = @selector(onEarnestLoadFinish:);
  520. _downManager.OnImageFail = @selector(onEarnestLoadFail:);
  521. [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
  522. }
  523. /**
  524. 收款方式
  525. */
  526. -(void)loadSettlementMethodDataSource{
  527. [self startLoading];
  528. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  529. [dict setObject:@"GetReceivableWayIphone" forKey:@"Action"];
  530. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  531. [dict setObject:kkUserCode forKey:@"UserCode"];
  532. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  533. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  534. _downManager = [[ASIDownManager alloc] init];
  535. _downManager.delegate = self;
  536. _downManager.OnImageDown = @selector(onSettlementMethodLoadFinish:);
  537. _downManager.OnImageFail = @selector(onSettlementMethodLoadFail:);
  538. [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
  539. }
  540. /**
  541. 跳转到结算方式
  542. @param gesture <#gesture description#>
  543. */
  544. - (void)goSettlementMethod:(UITapGestureRecognizer *)gesture {
  545. if(_settlementMethodList==nil||_settlementMethodList.count==0){
  546. return;
  547. }
  548. SettlementMethodVC *vc = [[SettlementMethodVC alloc]init];
  549. vc.settlementMethodArray=_settlementMethodList;
  550. vc.settlementDelegate=self;
  551. [self.navigationController pushViewController:vc animated:YES];
  552. }
  553. /**
  554. 创建 UITextField
  555. */
  556. -(UITextField *)getTextField:(UIView*)v labelText:(NSString*)labelTitle hintText:(NSString*)hint labelColor:(UIColor*) color tag:(NSInteger) tag {
  557. UILabel *lblCustomer = [UILabel new];
  558. lblCustomer.frame=CGRectMake(15,16, 100, 25);
  559. lblCustomer.text = labelTitle;
  560. lblCustomer.textColor=color;
  561. lblCustomer.font= [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  562. [v addSubview:lblCustomer];
  563. UITextField *txtCustomer = [UITextField new];
  564. txtCustomer.frame=CGRectMake(CGRectGetMaxX(lblCustomer.frame)+10,16, SCREENWIDTH-CGRectGetMaxX(lblCustomer.frame)-30, 25);
  565. txtCustomer.tag=tag;
  566. txtCustomer.delegate = self;
  567. txtCustomer.font=[UIFont systemFontOfSize: LabelAndTextFontOfSize];
  568. txtCustomer.placeholder = hint;
  569. [v addSubview:txtCustomer];
  570. UIView *separator = [UIView new];
  571. separator.backgroundColor=LineBackgroundColor;
  572. separator.frame=CGRectMake(CGRectGetMaxX(lblCustomer.frame)+10,CGRectGetMaxY(txtCustomer.frame)+10,Screen_Width-CGRectGetMaxX(lblCustomer.frame)+10, 1);
  573. [v addSubview:separator];
  574. return txtCustomer;
  575. }
  576. /**
  577. 创建UILabel
  578. */
  579. -(UILabel *)getUILabel:(UIView*)v labelText:(NSString*)labelTitle hintText:(NSString*)hint labelColor:(UIColor*) color isHaveRightArrow:(Boolean)rightArrowFlag tag:(NSInteger) tag{
  580. UILabel *lblTitleCustomer = [UILabel new];
  581. lblTitleCustomer.frame=CGRectMake(15,16, 100, 25);
  582. lblTitleCustomer.text = labelTitle;
  583. lblTitleCustomer.textColor=color;
  584. lblTitleCustomer.font= [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  585. [v addSubview:lblTitleCustomer];
  586. UILabel *lblCustomer = [UILabel new];
  587. lblCustomer.frame=CGRectMake(CGRectGetMaxX(lblTitleCustomer.frame)+10,16, SCREENWIDTH-CGRectGetMaxX(lblTitleCustomer.frame)-30, 25);
  588. lblCustomer.font=[UIFont systemFontOfSize: LabelAndTextFontOfSize];
  589. lblCustomer.userInteractionEnabled=YES;
  590. lblCustomer.text=hint;
  591. lblCustomer.tag=tag;
  592. [v addSubview:lblCustomer];
  593. UIView *separator = [UIView new];
  594. separator.backgroundColor=LineBackgroundColor;
  595. separator.frame=CGRectMake(CGRectGetMaxX(lblTitleCustomer.frame)+10,CGRectGetMaxY(lblCustomer.frame)+10,Screen_Width-CGRectGetMaxX(lblTitleCustomer.frame)+10, 1);
  596. [v addSubview:separator];
  597. if(rightArrowFlag){
  598. UIButton *btnRightArrow = [UIButton buttonWithType:UIButtonTypeCustom];
  599. btnRightArrow.frame=CGRectMake(Screen_Width-50,10,32,30);
  600. UIImageView *rightArrowImg = [[UIImageView alloc]initWithFrame:CGRectMake(25,9,7, 12)];
  601. [rightArrowImg setImage:[UIImage imageNamed:@"rightarrow"]];
  602. [ btnRightArrow addSubview:rightArrowImg];
  603. rightArrowImg.userInteractionEnabled=NO;
  604. [v addSubview:btnRightArrow];
  605. }
  606. return lblCustomer;
  607. }
  608. /**
  609. 隐藏键盘
  610. */
  611. - (void)hideKey{
  612. [self.view endEditing:YES];
  613. }
  614. @end