DailyReconciliationViewController.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. //
  2. // DailyReconciliationViewController.m
  3. // IBOSSmini
  4. //
  5. // Created by apple on 2017/5/4.
  6. // Copyright © 2017年 elongtian. All rights reserved.
  7. //
  8. #import "DailyReconciliationViewController.h"
  9. #import "DKWeeklyCalendarView.h"
  10. #import "DailyReconciDetailViewController.h"
  11. #import "DailyReconciliationCell.h"
  12. #import "DateFormat.h"
  13. @interface DailyReconciliationViewController ()<DKWeeklyCalendarViewDelegate,UITableViewDelegate,UITableViewDataSource>{
  14. //TableView对象
  15. UITableView *_vTableView;
  16. UIView *_headView;
  17. }
  18. /**
  19. 日期控件
  20. */
  21. @property (nonatomic, strong) DKWeeklyCalendarView* calendarView;
  22. /**
  23. 原始数据源
  24. */
  25. @property (strong, nonatomic) NSMutableArray *dataList;
  26. /**
  27. 转化成model数据源
  28. */
  29. @property (strong, nonatomic) NSMutableArray *dataNewList;
  30. /**
  31. 请求数据对象
  32. */
  33. @property(nonatomic,strong) ASIDownManager *mDownManager;
  34. @end
  35. static CGFloat CALENDER_VIEW_HEIGHT = 80.f;
  36. @implementation DailyReconciliationViewController
  37. #pragma mark - 公共函数
  38. /**
  39. viewDidLoad函数
  40. */
  41. - (void)viewDidLoad {
  42. [super viewDidLoad];
  43. [self showTitle:@""];
  44. [self initUI];
  45. }
  46. /**
  47. 修改:2017-9-26
  48. 适配机型
  49. 安全区视图发生变化
  50. */
  51. -(void)viewSafeAreaInsetsDidChange{
  52. _vTableView.frame = CGRectMake(0, CGRectGetMaxY(self.calendarView.frame)+10, SCREENWIDTH, self.view.safeAreaLayoutGuide.layoutFrame.size.height-CGRectGetMaxY(self.calendarView.frame)-10);
  53. [super viewSafeAreaInsetsDidChange];
  54. }
  55. /**
  56. didReceiveMemoryWarning函数
  57. */
  58. - (void)didReceiveMemoryWarning {
  59. [super didReceiveMemoryWarning];
  60. }
  61. #pragma mark - 数据源list属性
  62. /**
  63. 原始数据源
  64. @return <#return value description#>
  65. */
  66. - (NSMutableArray *)dataList{
  67. if(_dataList== nil){
  68. _dataList = [NSMutableArray new];
  69. }
  70. return _dataList;
  71. }
  72. /**
  73. 转化成model数据源
  74. @return <#return value description#>
  75. */
  76. - (NSMutableArray *)dataNewList{
  77. if(_dataNewList== nil){
  78. _dataNewList = [NSMutableArray new];
  79. }
  80. return _dataNewList;
  81. }
  82. /**
  83. 日期控件
  84. @return <#return value description#>
  85. */
  86. - (DKWeeklyCalendarView *)calendarView
  87. {
  88. if(!_calendarView){
  89. _calendarView = [[DKWeeklyCalendarView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, CALENDER_VIEW_HEIGHT)];
  90. _calendarView.delegate = self;
  91. }
  92. return _calendarView;
  93. }
  94. #pragma mark - 委托回调函数
  95. #pragma mark 委托接口回调函数
  96. /**
  97. 调用接口成功回调
  98. @param sender <#sender description#>
  99. */
  100. - (void)onLoadFinish:(ASIDownManager *)sender
  101. {
  102. // 服务器返回数据
  103. NSDictionary *dic = [sender.mWebStr JSONValue];
  104. [self Cancel];
  105. // 服务器返回数据是否正确
  106. if (dic && [dic isKindOfClass:[NSDictionary class]])
  107. {
  108. // 服务器返回数据状态值
  109. int iStatus = [[dic objectForKey:@"Status"] intValue];
  110. // 服务器返回数据消息
  111. NSString *message=[dic objectForKey:@"Message"];
  112. // 服务器返回数据状态值正确
  113. if (iStatus == 0)
  114. {
  115. // 返回值
  116. NSDictionary *dicResult =[dic objectForKey:@"Result"];
  117. NSArray * approvArr;
  118. NSArray * approvTotalArr;
  119. if(dicResult!=nil)
  120. {
  121. approvArr = [dicResult objectForKey:@"PivotDataTable"];
  122. approvTotalArr = [dicResult objectForKey:@"TotalTable"];
  123. }
  124. [self.dataList removeAllObjects];
  125. _vTableView.tableHeaderView = nil;
  126. _vTableView.backgroundView = nil;
  127. // 返回值数组
  128. if(approvArr!=nil)
  129. {
  130. [self.dataList addObjectsFromArray:approvArr];
  131. if(self.dataList.count==0){
  132. UIView *noDataView=[[UIView alloc]init];
  133. noDataView.frame=_vTableView.bounds;
  134. UIImageView *nodataImgView=[[UIImageView alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16,noDataView.frame.size.height/2-16,32,32)];
  135. [nodataImgView setImage:[UIImage imageNamed:@"icon_no_data"]];
  136. [noDataView addSubview:nodataImgView];
  137. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16-12,CGRectGetMaxY(nodataImgView.frame)+3,70, 25)];
  138. label.font=[UIFont systemFontOfSize:NoDataFontOfSize];
  139. label.text = @"无数据";
  140. label.numberOfLines = 2;
  141. label.textColor = [UIColor lightGrayColor];
  142. [noDataView addSubview:label];
  143. _vTableView.backgroundView =noDataView;
  144. [self showAlertViewText:@"未找到匹配结果"];
  145. }
  146. else
  147. {
  148. NSDictionary *dicTitle =approvTotalArr[0];
  149. _vTableView.tableHeaderView = _headView;
  150. self.lbTotalReceiptValue.text = @"¥0";
  151. self.lbTotalReceivableValue.text = @"¥0";
  152. if (dicTitle!=nil) {
  153. if([dicTitle objectForKey:@"ReceiptAmount"]){
  154. self.lbTotalReceiptValue.text=[NSString stringWithFormat:@"¥%@",[dicTitle objectForKey:@"ReceiptAmount"] ];
  155. }
  156. if([dicTitle objectForKey:@"ReceivableAmount"]){
  157. self.lbTotalReceivableValue.text=[NSString stringWithFormat:@"¥%@",[dicTitle objectForKey:@"ReceivableAmount"]];
  158. }
  159. }
  160. }
  161. [_vTableView reloadData];
  162. }
  163. }
  164. // 服务器返回数据状态值异常
  165. else if(iStatus==ActionResultStatusAuthError
  166. ||iStatus==ActionResultStatusNoLogin
  167. ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
  168. [self showReLoginDialog:message];
  169. }
  170. else {
  171. [_vTableView reloadData];
  172. [self showAlertViewText:message];
  173. }
  174. }
  175. }
  176. /**
  177. 调用接口失败回调
  178. @param sender <#sender description#>
  179. */
  180. - (void)onLoadFail:(ASIDownManager *)sender {
  181. [self Cancel];
  182. [_vTableView reloadData];
  183. [self showAlertViewText:@"加载失败"];
  184. }
  185. #pragma mark 委托tablview回调函数
  186. /**
  187. 行数
  188. @param tableView tableView description
  189. @param section section description
  190. @return return value description
  191. */
  192. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  193. {
  194. return [_dataList count];
  195. }
  196. /**
  197. Sections数
  198. @param tableView <#tableView description#>
  199. @return <#return value description#>
  200. */
  201. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  202. return 1;
  203. }
  204. /**
  205. 高度
  206. @param tableView <#tableView description#>
  207. @param indexPath <#indexPath description#>
  208. @return <#return value description#>
  209. */
  210. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  211. return 40;
  212. }
  213. /**
  214. 单元格
  215. @param tableView <#tableView description#>
  216. @param indexPath <#indexPath description#>
  217. @return <#return value description#>
  218. */
  219. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  220. {
  221. static NSString *CellIdentifier = @"DailyReconciliationCell";
  222. DailyReconciliationCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  223. if (cell == nil) {
  224. cell=[[DailyReconciliationCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  225. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  226. }
  227. // DailyReconciliationCell *cell = [[ DailyReconciliationCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
  228. NSDictionary *dic= _dataList[indexPath.row];
  229. if(dic!=nil)
  230. {
  231. cell.lblOrgNameView.text=[dic objectForKey:@"OrganizationName"];
  232. if([dic objectForKey:@"ReceiptAmount"]){
  233. cell.lblTotalReceiptView.text=[NSString stringWithFormat:@"¥%@",[dic objectForKey:@"ReceiptAmount"] ];
  234. }else{
  235. cell.lblTotalReceiptView.text=@"¥0";
  236. }
  237. if([dic objectForKey:@"ReceivableAmount"]){
  238. cell.lblTotalReceivableView.text=[NSString stringWithFormat:@"¥%@",[dic objectForKey:@"ReceivableAmount"]];
  239. }else{
  240. cell.lblTotalReceivableView.text=@"¥0";
  241. }
  242. }
  243. return cell;
  244. }
  245. /**
  246. 单元格选择事件
  247. @param tableView <#tableView description#>
  248. @param indexPath <#indexPath description#>
  249. */
  250. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  251. {
  252. NSDictionary *dic= _dataList[indexPath.row];
  253. if(dic!=nil)
  254. {
  255. NSString *orgID = [dic objectForKey:@"OrganizationID"];
  256. NSString *time = [dic objectForKey:@"AccountDate"];
  257. NSString *businessType = @"0";
  258. self.hidesBottomBarWhenPushed=YES;
  259. DailyReconciDetailViewController *detailVC =[[DailyReconciDetailViewController alloc]init];
  260. detailVC.organizationId = orgID;
  261. detailVC.accountDate = time;
  262. detailVC.businessType = businessType;
  263. [self.navigationController pushViewController:detailVC animated:YES];
  264. }
  265. }
  266. /**
  267. 日期控件属性
  268. @return <#return value description#>
  269. */
  270. - (NSDictionary *)CLCalendarBehaviorAttributes
  271. {
  272. return @{
  273. CLCalendarWeekStartDay : @1, //Start Day of the week, from 1-7 Mon-Sun -- default 1
  274. // CLCalendarDayTitleTextColor : [UIColor yellowColor],
  275. // CLCalendarSelectedDatePrintColor : [UIColor greenColor],
  276. };
  277. }
  278. /**
  279. 日期控件选择后的日期
  280. @param date <#date description#>
  281. */
  282. - (void)dailyCalendarViewDidSelect:(NSDate *)date
  283. {
  284. //用于格式化NSDate对象
  285. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  286. //设置格式
  287. [dateFormatter setDateFormat:@"yyyy-MM-dd"];
  288. //NSDate转NSString
  289. NSString *currentDateString = [dateFormatter stringFromDate: date];
  290. [self reloadData:currentDateString];
  291. }
  292. #pragma mark - 私有函数
  293. /**
  294. 初始化ui
  295. */
  296. - (void)initUI {
  297. self.navigationItem.title=@"日结对账表";
  298. self.view.backgroundColor = [UIColor whiteColor];
  299. [self.view addSubview:self.calendarView];
  300. //分割线
  301. UIView *viewBackgroud = [UIView new];
  302. viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(self.calendarView.frame), Screen_Width, 10);
  303. viewBackgroud.backgroundColor = LineBackgroundColor;
  304. [self.view addSubview:viewBackgroud];
  305. _vTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, self.view.frame.size.height - CGRectGetMaxY(viewBackgroud.frame))];
  306. _vTableView.rowHeight = UITableViewAutomaticDimension;
  307. _vTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  308. _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  309. _vTableView.backgroundColor = [UIColor whiteColor];
  310. _vTableView.delegate = self;
  311. _vTableView.dataSource=self;
  312. _vTableView.tableHeaderView = nil;
  313. [self.view addSubview:_vTableView];
  314. //头布局
  315. _headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, 40)];
  316. UIButton *btnHead=[UIButton buttonWithType:UIButtonTypeCustom];
  317. btnHead.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  318. CGFloat titleHeight = 50;
  319. CGFloat lblx = 20;
  320. CGFloat lblwidth = 130;
  321. CGFloat fontsize = 14;
  322. //CGFloat valuex = 125;
  323. CGFloat valuey = 10;
  324. CGFloat valuewidth = 200;
  325. CGFloat valueheight = 25;
  326. CGFloat heightLine =1;
  327. //总合计==================
  328. UIView *vtotal=[UIView new];
  329. vtotal.frame=CGRectMake(0, 0, Screen_Width, titleHeight);
  330. [_headView addSubview:vtotal];
  331. UILabel *lbtotal = [UILabel new];
  332. lbtotal.frame=CGRectMake(lblx, valuey, lblwidth, valueheight);
  333. lbtotal.font = [UIFont boldSystemFontOfSize:fontsize];
  334. lbtotal.text=@"总合计";
  335. [vtotal addSubview:lbtotal];
  336. //分割线
  337. viewBackgroud = [UIView new];
  338. viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vtotal.frame), Screen_Width, heightLine);
  339. viewBackgroud.backgroundColor = LineBackgroundColor;
  340. [_headView addSubview:viewBackgroud];
  341. //收款总额==================
  342. UIView *vtotalReceipt=[UIView new];
  343. vtotalReceipt.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight);
  344. [_headView addSubview:vtotalReceipt];
  345. UIImageView *imgview = [UIImageView new];
  346. imgview.frame=CGRectMake(lblx, valuey+5, 20, 20);
  347. [imgview setImage:[UIImage imageNamed:@"day_account_total_receivable"]];
  348. [vtotalReceipt addSubview:imgview];
  349. UILabel *lbtotalReceipt = [UILabel new];
  350. lbtotalReceipt.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+5, valuey+3, lblwidth, valueheight);
  351. lbtotalReceipt.font = [UIFont systemFontOfSize:fontsize];
  352. lbtotalReceipt.text=@"收款总额";
  353. [vtotalReceipt addSubview:lbtotalReceipt];
  354. self.lbTotalReceiptValue = [UILabel new];
  355. self.lbTotalReceiptValue.frame=CGRectMake(Screen_Width - valuewidth - lblx, valuey+3, valuewidth, valueheight);
  356. self.lbTotalReceiptValue.font = [UIFont boldSystemFontOfSize:fontsize];
  357. //self.lbtotalReceiptValue.text = @"¥0";
  358. self.lbTotalReceiptValue.textAlignment = NSTextAlignmentRight;
  359. [vtotalReceipt addSubview:self.lbTotalReceiptValue];
  360. viewBackgroud = [UIView new];
  361. viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vtotalReceipt.frame), Screen_Width, heightLine);
  362. viewBackgroud.backgroundColor = LineBackgroundColor;
  363. [_headView addSubview:viewBackgroud];
  364. //货款总额==================
  365. UIView *vtotalReceivable=[UIView new];
  366. vtotalReceivable.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight);
  367. [_headView addSubview:vtotalReceivable];
  368. UIImageView *imgviewReceivable = [UIImageView new];
  369. imgviewReceivable.frame=CGRectMake(lblx, valuey+6, 21, 16);
  370. [imgviewReceivable setImage:[UIImage imageNamed:@"day_account_total_receipt"]];
  371. [vtotalReceivable addSubview:imgviewReceivable];
  372. UILabel *lbtotalReceivable = [UILabel new];
  373. lbtotalReceivable.frame=CGRectMake(CGRectGetMaxX(imgviewReceivable.frame)+5, valuey+2, lblwidth, valueheight);
  374. lbtotalReceivable.font = [UIFont systemFontOfSize:fontsize];
  375. lbtotalReceivable.text=@"货款总额";
  376. [vtotalReceivable addSubview:lbtotalReceivable];
  377. self.lbTotalReceivableValue = [UILabel new];
  378. self.lbTotalReceivableValue.frame=CGRectMake(Screen_Width - valuewidth - lblx, valuey+2, valuewidth, valueheight);
  379. self.lbTotalReceivableValue.font = [UIFont boldSystemFontOfSize:fontsize];
  380. //self.lbtotalReceivableValue.text = @"¥0";
  381. self.lbTotalReceivableValue.textAlignment = NSTextAlignmentRight;
  382. [vtotalReceivable addSubview:self.lbTotalReceivableValue];
  383. viewBackgroud = [UIView new];
  384. viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vtotalReceivable.frame), Screen_Width, 40);
  385. viewBackgroud.backgroundColor = LineBackgroundColor;
  386. [_headView addSubview:viewBackgroud];
  387. CGFloat backY = 8;
  388. UILabel *lblTitleReceipt = [UILabel new];
  389. lblTitleReceipt.frame=CGRectMake(Screen_Width - 2*lblwidth - 10 - 2, backY, lblwidth, valueheight);
  390. lblTitleReceipt.font = [UIFont systemFontOfSize:fontsize];
  391. lblTitleReceipt.text=@"收款总额";
  392. lblTitleReceipt.textAlignment = NSTextAlignmentRight;
  393. [viewBackgroud addSubview:lblTitleReceipt];
  394. UILabel *lblTitleReceivable = [UILabel new];
  395. lblTitleReceivable.frame=CGRectMake(Screen_Width - lblwidth - 10, backY, lblwidth, valueheight);
  396. lblTitleReceivable.font = [UIFont systemFontOfSize:fontsize];
  397. lblTitleReceivable.text=@"货款总额";
  398. lblTitleReceivable.textAlignment = NSTextAlignmentRight;
  399. [viewBackgroud addSubview:lblTitleReceivable];
  400. UILabel *lblOrg = [UILabel new];
  401. lblOrg.frame=CGRectMake(lblx, backY, Screen_Width - CGRectGetMinX(lblTitleReceipt.frame) - lblx, valueheight);
  402. lblOrg.font = [UIFont systemFontOfSize:fontsize];
  403. lblOrg.text=@"部门";
  404. [viewBackgroud addSubview:lblOrg];
  405. _headView.frame = CGRectMake(0, 0, Screen_Width, CGRectGetMaxY(viewBackgroud.frame));
  406. _vTableView.tableHeaderView = _headView;
  407. }
  408. /**
  409. 进度条隐藏
  410. */
  411. - (void)Cancel {
  412. [self stopLoading];
  413. }
  414. /**
  415. 加载数据
  416. */
  417. -(void)reloadData:(NSString *)date
  418. {
  419. [self startLoading];
  420. NSString *urlStr = [NSString stringWithFormat:@"%@", ServerURL];
  421. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  422. [dict setObject:@"GetDailyReconciliationListIphone" forKey:@"Action"];
  423. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  424. [dict setObject:kkUserCode forKey:@"UserCode"];
  425. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  426. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  427. [dict setObject:@"" forKey:@"OrganizationCode"];
  428. [dict setObject:date forKey:@"AccountDateFrom"];
  429. [dict setObject:date forKey:@"AccountDateTo"];
  430. [dict setObject:@"0" forKey:@"BusinessType"];
  431. self.mDownManager = [[ASIDownManager alloc] init];
  432. _mDownManager.delegate = self;
  433. _mDownManager.OnImageDown = @selector(onLoadFinish:);
  434. _mDownManager.OnImageFail = @selector(onLoadFail:);
  435. [_mDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  436. }
  437. @end