Commit 6de087fe authored by Sandy's avatar Sandy

调整金额显示

parent a8d95938
......@@ -26,7 +26,7 @@ pod 'IQKeyboardManager', '~> 3.2.3'
#pod 'BaiduMapAPI', '~> 2.7.0'
#pod 'iVersion','~>1.11.4'
#pod 'Reveal-iOS-SDK', :configurations => ['Debug']
pod 'DZNEmptyDataSet'
pod 'CustomBadge', '~> 3.0.0'
#should be removed later
......
This diff is collapsed.
......@@ -38,4 +38,10 @@ typedef NS_ENUM(NSInteger, CalculateType) {
+ (NSDecimalNumber *)calculateNum1:(id)num1 num2:(id)num2 type:(CalculateType)type roundingType:(NSRoundingMode)roundingType cutLenth:(NSInteger)coutLenth;
/** 一百倍 */
+ (NSDecimalNumber *)oneHundredTimes:(id)num;
/** 计算百分比 */
+ (NSString *)getPercent:(id)num1 num:(id)num2;
/** 获取金额 */
+ (NSString *)getMoneyStringFrom:(id)num;
+ (NSString *)getMoneyStringFromString:(NSString *)originString;
@end
......@@ -51,8 +51,13 @@
break;
}
case CalculateTypeDiv: {
decimalResult = [decimalNum1 decimalNumberByDividingBy:decimalNum2 withBehavior:roundUp];
result = [decimalResult stringValue];
if ([decimalNum2 isEqualToNumber:@0]) {
decimalResult = [NSDecimalNumber decimalNumberWithString:@"0"];
}else{
decimalResult = [decimalNum1 decimalNumberByDividingBy:decimalNum2 withBehavior:roundUp];
result = [decimalResult stringValue];
}
break;
}
}
......@@ -61,6 +66,7 @@
return decimalResult;
}
//把传入的类型变成NSDecimalNumber
+ (NSDecimalNumber *)changeType:(id)num1 {
NSDecimalNumber *decimalNum1;
if ([num1 isKindOfClass:[NSDecimalNumber class]]) {
......@@ -78,4 +84,50 @@
+ (NSDecimalNumber *)oneHundredTimes:(id)num {
return [self calculateNum1:num num2:@100 type:CalculateTypeMul roundingType:NSRoundBankers cutLenth:10];
}
+ (NSString *)getPercent:(id)num1 num:(id)num2 {
[self calculateNum1:num1 num2:num1 type:CalculateTypeDiv roundingType:NSRoundBankers cutLenth:4];
NSDecimalNumber *result = [self oneHundredTimes:[self calculateNum1:num1 num2:num2 type:CalculateTypeDiv roundingType:NSRoundBankers cutLenth:4]];
return [NSString stringWithFormat:@"%@%%",[self getMoneyStringFromString:result.stringValue]];
}
+ (NSString *)getMoneyStringFrom:(id)num Lenth:(NSInteger)cutLenth {
NSDecimalNumberHandler *roundUp = [NSDecimalNumberHandler
decimalNumberHandlerWithRoundingMode:NSRoundBankers
scale:cutLenth ? cutLenth : 2
raiseOnExactness:NO
raiseOnOverflow:NO
raiseOnUnderflow:NO
raiseOnDivideByZero:YES];
NSDecimalNumber *decimal = [self changeType:num];
NSDecimalNumber *result = [decimal decimalNumberByAdding:[NSDecimalNumber decimalNumberWithString:@"0"] withBehavior:roundUp];
return [result stringValue];
}
+ (NSString *)getMoneyStringFrom:(id)num{
NSString *originString = [self getMoneyStringFrom:num Lenth:2];
return [self getMoneyStringFromString:originString];
}
+ (NSString *)getMoneyStringFromString:(NSString *)originString {
NSArray *array = [originString componentsSeparatedByString:@"."];
NSString *top = [array[0] stringByAppendingString:@"."];
NSString *result;
if (array.count == 1) {
result = [NSString stringWithFormat:@"%@00",top];
}else if(array.count == 2){
NSString *bottom = array[1];
if (bottom.length == 2) {
result = originString;
}
for (NSInteger i = bottom.length; i < 2; i++) {
result = [originString stringByAppendingString:@"0"];
}
}
return result;
}
@end
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "arrow_down_purple@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "arrow_down_purple@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "bill_no_image_default.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "checked_checkbox.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "unchecked_checkbox.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
......@@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.3.3</string>
<string>1.3.4</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
......
......@@ -32,7 +32,19 @@
#define GXF_DETAIL_COLOR HexColor(@"888888")
#define GXF_LEFTSIX_COLOR HexColor(@"666666")
/**
* colors
*/
#define kSysWhite [UIColor whiteColor]
//红 #ED1B23
#define kMainRedColor [UIColor colorWithRed:0.929 green:0.106 blue:0.137 alpha:1.000]
//蓝 #478FF1
#define kMainBlueColor [UIColor colorWithRed:0.278 green:0.561 blue:0.945 alpha:1.000]
//橙 #EA6402
#define kMainOrangeColor [UIColor colorWithRed:0.918 green:0.392 blue:0.008 alpha:1.000]
//紫 #5435AD
#define kMainPurpleColor [UIColor colorWithRed:0.329 green:0.208 blue:0.678 alpha:1.000]
//报表统一颜色
#define ReportColor GXF_NAVIGAYION_COLOR
#define ReportContentColor HexColor(@"f4422e")
......
......@@ -103,5 +103,7 @@
@property (nonatomic, copy) NSString *enterprise;
@property (nonatomic, copy) NSString *lastModify_id;
@property (nonatomic, strong) NSNumber *area;
@end
......@@ -9,6 +9,7 @@
#import "ReportBoardsViewController.h"
#import "ReportBoardTableViewCell.h"
#import "ReportViewController.h"
#import "VankeAppBoard_iPhone.h"
static NSString *const cellId = @"cellId";
@interface ReportBoardsViewController ()<UITableViewDelegate, UITableViewDataSource>
......@@ -47,8 +48,10 @@ ON_DID_APPEAR( signal )
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[VankeAppBoard_iPhone sharedInstance] showMenu];
}
......@@ -61,7 +64,7 @@ ON_DID_APPEAR( signal )
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
ReportViewController *reportVC = [[ReportViewController alloc] init];
reportVC.hidesBottomBarWhenPushed = YES;
switch (indexPath.row) {
case 0:
{
......
......@@ -16,6 +16,7 @@
//#import "SearchReportViewController.h"
#import "QueryOrder.h"
#import "CalculateHelper.h"
#import "VankeAppBoard_iPhone.h"
//#import "ReportDetailViewController.h"
@interface ReportViewController ()<UIScrollViewDelegate,CustomSegViewDelegate,FinishTimeViewDelegate>
{
......@@ -85,14 +86,14 @@ ON_CREATE_VIEWS( signal )
- (void)viewDidLoad {
[super viewDidLoad];
[[VankeAppBoard_iPhone sharedInstance] hideMenu];
//布局
#if 1
self.dataArr = [NSMutableArray array];
self.totalArr = [NSMutableArray array];
self.selectArr = [NSMutableArray array];
[self bulidLayout];
UIBarButtonItem *searchItem = [[UIBarButtonItem alloc]initWithTitle:@"切换日期" style:UIBarButtonItemStyleDone target:self action:@selector(customSegTwoClick:)];
UIBarButtonItem *searchItem = [[UIBarButtonItem alloc]initWithTitle:@"历史" style:UIBarButtonItemStyleDone target:self action:@selector(customSegTwoClick:)];
self.navigationItem.rightBarButtonItem = searchItem;
self.dayType = @"day";
......@@ -153,17 +154,6 @@ ON_CREATE_VIEWS( signal )
[arrAuthordCode addObject:org.code];
}
NSString *authorCodes = [arrAuthordCode componentsJoinedByString:@","];
NSDictionary *dict = @{
@"dataScopeType":self.dayType,
@"dataType":@"biz",
@"orgCodes":authorCodes,
@"dataScope":self.scopeType,
@"queryOrders":orderArr,
@"pageNumber":@0,
@"pageSize":@100
};
NSString *json = [dict JSONString];
NSDictionary *testParams = @{@"dataType" : self.reportType,
@"dataScopeType" : self.dayType,
@"dataScope" : self.scopeType,
......@@ -199,26 +189,23 @@ ON_CREATE_VIEWS( signal )
if (success == 1) {
NSDictionary *compassDict = data[ @"data" ][@"salesData"];
NSArray *arr = compassDict[@"records"];
// if (arr.count > 0) {
// for (NSDictionary *comDict in arr) {
// Compass *com = [[Compass alloc]init];
// [com setValuesForKeysWithDictionary:comDict];
// self.compass = com;
// }
// }
//计算顶部总的数据
Compass *com = nil;
for (NSDictionary *comDict in arr) {
if (!com) {
com = [[Compass alloc] init];
[com setValuesForKeysWithDictionary:comDict];
com.area = [CalculateHelper calculateNum1:com.sales num2:com.groundEffect type:CalculateTypeDiv roundingType:NSRoundBankers cutLenth:10];
}else{
Compass *obj = [[Compass alloc]init];
[obj setValuesForKeysWithDictionary:comDict];
com.sales = [CalculateHelper calculateNum1:com.sales num2:obj.sales type:CalculateTypeAdd roundingType:NSRoundBankers cutLenth:2];
com.salesChain = [CalculateHelper calculateNum1:com.salesChain num2:obj.salesChain type:CalculateTypeAdd roundingType:NSRoundBankers cutLenth:2];
com.salesYoY = [CalculateHelper calculateNum1:com.salesYoY num2:obj.salesYoY type:CalculateTypeAdd roundingType:NSRoundBankers cutLenth:2];
NSDecimalNumber *area = [CalculateHelper calculateNum1:obj.sales num2:obj.groundEffect type:CalculateTypeDiv roundingType:NSRoundBankers cutLenth:10];
com.area = [CalculateHelper calculateNum1:com.area num2:area type:CalculateTypeAdd roundingType:NSRoundBankers cutLenth:10];
}
}
......@@ -241,7 +228,7 @@ ON_CREATE_VIEWS( signal )
//获取底部详情数据
- (void)getBottomData:(NSIndexPath *)indexPath{
__weak typeof(self)weakSelf = self;
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
NSArray *arr = [[VankeCommonModel sharedInstance] getAuthOrgs];
NSMutableArray *arrAuthordCode = [NSMutableArray array];
for (AuthorizedOrg *org in arr) {
......@@ -251,7 +238,7 @@ ON_CREATE_VIEWS( signal )
NSDictionary *testParams = @{@"dataType" : self.reportType,
@"dataScopeType" : self.dayType,
@"dataScope" : self.scopeType,
@"orgCodes" : self.orgScope ? [NSNull null] : @"HSCQ,NTJY",
@"orgCodes" : self.orgScope ? [NSNull null] : authorCodes,
@"upperOrgCode" : self.orgScope ? self.orgScope : [NSNull null],
@"queryOrders" : @[@{@"field" : @"salesInfo.orgCode",
@"direction" : @"asc"}],
......@@ -264,9 +251,11 @@ ON_CREATE_VIEWS( signal )
//赋值
[IBTLoadingView hideHUDWithText:nil];
[strongSelf downLoadData:data indexPath:indexPath];
[hud hide:YES];
} failure:^(id data) {
[IBTLoadingView hideHUDWithText:nil];
[IBTLoadingView showTips:data];
[hud hide:YES];
}];
}
......
......@@ -166,14 +166,16 @@
}
self.dateLabel.text = compass.dataScope?[NSString stringWithFormat:@"%@%@累计销售额",compass.dataScope,weekday]:@"无";
//销售额
self.centerLabel.text = compass.sales?[IBTCommon countNumAndChangeformat:[IBTCommon stringDisposeWithFloat:[compass.sales floatValue]]]:@"---" ;
NSString *strSale = [IBTCommon countNumAndChangeformat:[IBTCommon stringDisposeWithFloat:[compass.sales floatValue]]];
self.centerLabel.text = compass.sales?[CalculateHelper getMoneyStringFromString:strSale] :@"---";
//销售环比变化率 比上周
NSDecimalNumber *saleDifference = [CalculateHelper calculateNum1:compass.sales num2:compass.salesChain type:CalculateTypeSub roundingType:NSRoundBankers cutLenth:4];
NSDecimalNumber *decimalSaleRate = [CalculateHelper calculateNum1:saleDifference num2:compass.salesChain type:CalculateTypeDiv roundingType:NSRoundBankers cutLenth:4];
decimalSaleRate = [CalculateHelper oneHundredTimes:decimalSaleRate];
NSString *salesChainRateStr = decimalSaleRate?[NSString stringWithFormat:@"%@%%", [decimalSaleRate stringValue]]:@"---";
NSString *salesChainRateStr = decimalSaleRate?[NSString stringWithFormat:@"%@%%", [CalculateHelper getMoneyStringFromString:[decimalSaleRate stringValue]]]:@"---";
if (![salesChainRateStr hasPrefix:@"-"] && ![salesChainRateStr isEqualToString:@"0"] && ![salesChainRateStr hasPrefix:@"--"]) {
[self.lastWeekLabel setImage:[UIImage imageNamed:ReportChainPlusImage] forState:UIControlStateNormal];
......@@ -181,6 +183,9 @@
}else if ([salesChainRateStr hasPrefix:@"-"] && ![salesChainRateStr isEqualToString:@"0"] && ![salesChainRateStr hasPrefix:@"--"]){
[self.lastWeekLabel setImage:[UIImage imageNamed:ReportChainMinusImage] forState:UIControlStateNormal];
[self.lastWeekLabel setTitleColor:GXF_SAVE_COLOR forState:UIControlStateNormal];
}else{
[self.lastWeekLabel setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
[self.lastWeekLabel setImage:nil forState:UIControlStateNormal];
}
[self.lastWeekLabel setTitle:salesChainRateStr forState:UIControlStateNormal];
......@@ -197,11 +202,16 @@
}else if ([salesYoStr hasPrefix:@"-"] && ![salesYoStr isEqualToString:@"0"] && ![salesYoStr hasPrefix:@"--"]){
[self.lastYearLabel setImage:[UIImage imageNamed:ReportChainMinusImage] forState:UIControlStateNormal];
[self.lastYearLabel setTitleColor:GXF_SAVE_COLOR forState:UIControlStateNormal];
}else{
[self.lastYearLabel setImage:nil forState:UIControlStateNormal];
[self.lastYearLabel setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
}
[self.lastYearLabel setTitle:salesYoStr forState:UIControlStateNormal];
//销售目标达成率
NSString *salesTargetStr = compass.salesTargetRate?[NSString stringWithFormat:@"%@%%",[IBTCommon stringDisposeWithFloat:[compass.salesTargetRate floatValue]]]:@"---";
//坪效
NSDecimalNumber *groundEffect = [CalculateHelper calculateNum1:compass.sales num2:compass.area type:CalculateTypeDiv roundingType:NSRoundBankers cutLenth:2];
NSString *salesTargetStr = compass.area?[NSString stringWithFormat:@"%@",[groundEffect stringValue]]:@"---";
self.rateLabel.text = salesTargetStr;
// //单店日均销售
// NSString *dailysalesPerStr = compass.dailysalesPerStore?[NSString stringWithFormat:@"%@",[IBTCommon stringDisposeWithFloat:[compass.dailysalesPerStore floatValue]]]:@"---";
......
......@@ -7,7 +7,7 @@
//
#import "SaleViewCell.h"
#import "CalculateHelper.h"
#define Sale_Cell_Height 50
#define Left_Width 120
#define Left_margin 5
......@@ -133,16 +133,16 @@
self.saleLabel.textColor = GXF_NAVIGAYION_COLOR;
}
//销售额
self.saleLabel.text = sale.sales?[IBTCommon countNumAndChangeformat:[IBTCommon stringDisposeWithFloat:[sale.sales floatValue]]] : @"0";
self.saleLabel.text = sale.sales?[CalculateHelper getMoneyStringFrom:sale.sales] : @"0";
NSString *salesYoStr = [NSString stringWithFormat:@"%@%%",[IBTCommon stringDisposeWithFloat:[sale.salesChainRate floatValue]]];
NSString *salesYoStr = [NSString stringWithFormat:@"%@%%",[CalculateHelper getMoneyStringFrom:sale.salesChainRate]];
[self.lastWeekLabel setTitle:salesYoStr forState:UIControlStateNormal];
//坪效
NSString *salesTargetRateStr = [NSString stringWithFormat:@"%@",[IBTCommon stringDisposeWithFloat:[sale.groundEffect floatValue]]];
NSString *salesTargetRateStr = [NSString stringWithFormat:@"%@",[CalculateHelper getMoneyStringFrom:sale.groundEffect]];
self.rateLabel.text = salesTargetRateStr;
//日均销售
self.dailySaleLabel.text = [NSString stringWithFormat:@"%@", [sale.dailysalesPerStore stringValue]];
self.dailySaleLabel.text = [NSString stringWithFormat:@"%@", [CalculateHelper getMoneyStringFrom:sale.dailysalesPerStore]];
[self setColorAndFont:sale.level];
......
......@@ -151,12 +151,11 @@
}else{
row = tap.view.tag;
}
picVC.title = self.arrRecords[row][@"salesDate"];
picVC.attachmentUuid = self.arrRecords[row][@"attachmentUuid"];
[self.navigationController pushViewController:picVC animated:YES];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
for (int i = 0; i < self.titles.count; i++) {
......@@ -260,7 +259,8 @@
if (self.shop == nil) {
}else{
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
WS(weakSelf)
NSDateFormatter *f = [[NSDateFormatter alloc] init];
[f setDateFormat:@"yyyy-MM-dd"];
......@@ -342,11 +342,22 @@
}
}
//添加附件那一行
NSMutableArray *arrAttachment = [NSMutableArray array];
for (int i = 0; i < [arrData[0] count]; i++) {
if (i == 0) {
[arrAttachment addObject:@"附件"];
}else{
[arrAttachment addObject:@"点击查看"];
}
}
[arrData addObject:arrAttachment];
[arrBottom addObject:@""];
[weakSelf setUpScrollViewWithDataArr:arrData bottomArr:arrBottom];
[hud hide:YES];
NSLog(@"d");
} failure:^(id data) {
[hud hide:YES];
}];
}
......
......@@ -24,6 +24,7 @@
#import "SaleInputPictureTableViewCell.h"
#import "TZImagePickerController.h"
#import "UIImage+Helper.h"
#import "NSDate+FormatterAdditions.h"
#define kCellCount 20
#define kCellID @"SalesInputTableViewCell.h"
#define kPicCellId @"SaleInputPictureTableViewCell.h"
......@@ -425,8 +426,9 @@ ON_WILL_APPEAR( signal )
}
- (void)httpPostAttachments {
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
ICRHTTPController *httpCtrl = [ICRHTTPController sharedController];
NSString *string = [NSString stringWithFormat:@"attachment/upload_by_file?entity_type=%@&entity_uuid=%@",@"salesInput",self.shop.uuid];
NSString *string = [NSString stringWithFormat:@"attachment/upload_by_file?entity_type=%@&entity_uuid=%@",@"salesInput",[NSString stringWithFormat:@"%@%@",self.shop.code, self.topView.textfieldDate.text]];
WS(weakSelf);
[self.arrPics removeLastObject];
[httpCtrl POST:string pictures:self.arrPics param:nil complete:^(id responseObject, NSError *error) {
......@@ -443,6 +445,7 @@ ON_WILL_APPEAR( signal )
WS(weakSelf)
[httpCtrl postUrl:utf8String params:params success:^(id data) {
weakSelf.arrPics = nil;
[hud hide:YES];
[weakSelf.selectedAssets removeAllObjects];
[weakSelf.cellDataDic removeAllObjects];
[weakSelf.tableView reloadData];
......
//
// Items.h
// StatementDetailItems.h
//
// Created by 杰 张 on 16/7/18
// Copyright (c) 2016 __MyCompanyName__. All rights reserved.
......@@ -9,14 +9,14 @@
@interface Items : NSObject <NSCoding, NSCopying>
@interface StatementDetailItems : NSObject <NSCoding, NSCopying>
@property (nonatomic, assign) double amount;
@property (nonatomic, strong) NSString *remark;
@property (nonatomic, assign) double endDate;
@property (nonatomic, assign) id remark;
@property (nonatomic, strong) NSString *endDate;
@property (nonatomic, assign) double unpaid;
@property (nonatomic, strong) NSString *subject;
@property (nonatomic, assign) double beginDate;
@property (nonatomic, strong) NSString *beginDate;
@property (nonatomic, assign) double direction;
@property (nonatomic, assign) double paid;
......
//
// Items.m
// StatementDetailItems.m
//
// Created by 杰 张 on 16/7/18
// Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//
#import "Items.h"
#import "StatementDetailItems.h"
NSString *const kItemsAmount = @"amount";
NSString *const kItemsRemark = @"remark";
NSString *const kItemsEndDate = @"endDate";
NSString *const kItemsUnpaid = @"unpaid";
NSString *const kItemsSubject = @"subject";
NSString *const kItemsBeginDate = @"beginDate";
NSString *const kItemsDirection = @"direction";
NSString *const kItemsPaid = @"paid";
NSString *const kStatementDetailItemsAmount = @"amount";
NSString *const kStatementDetailItemsRemark = @"remark";
NSString *const kStatementDetailItemsEndDate = @"endDate";
NSString *const kStatementDetailItemsUnpaid = @"unpaid";
NSString *const kStatementDetailItemsSubject = @"subject";
NSString *const kStatementDetailItemsBeginDate = @"beginDate";
NSString *const kStatementDetailItemsDirection = @"direction";
NSString *const kStatementDetailItemsPaid = @"paid";
@interface Items ()
@interface StatementDetailItems ()
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
@end
@implementation Items
@implementation StatementDetailItems
@synthesize amount = _amount;
@synthesize remark = _remark;
......@@ -48,14 +48,14 @@ NSString *const kItemsPaid = @"paid";
// This check serves to make sure that a non-NSDictionary object
// passed into the model class doesn't break the parsing.
if(self && [dict isKindOfClass:[NSDictionary class]]) {
self.amount = [[self objectOrNilForKey:kItemsAmount fromDictionary:dict] doubleValue];
self.remark = [self objectOrNilForKey:kItemsRemark fromDictionary:dict];
self.endDate = [[self objectOrNilForKey:kItemsEndDate fromDictionary:dict] doubleValue];
self.unpaid = [[self objectOrNilForKey:kItemsUnpaid fromDictionary:dict] doubleValue];
self.subject = [self objectOrNilForKey:kItemsSubject fromDictionary:dict];
self.beginDate = [[self objectOrNilForKey:kItemsBeginDate fromDictionary:dict] doubleValue];
self.direction = [[self objectOrNilForKey:kItemsDirection fromDictionary:dict] doubleValue];
self.paid = [[self objectOrNilForKey:kItemsPaid fromDictionary:dict] doubleValue];
self.amount = [[self objectOrNilForKey:kStatementDetailItemsAmount fromDictionary:dict] doubleValue];
self.remark = [self objectOrNilForKey:kStatementDetailItemsRemark fromDictionary:dict];
self.endDate = [self objectOrNilForKey:kStatementDetailItemsEndDate fromDictionary:dict];
self.unpaid = [[self objectOrNilForKey:kStatementDetailItemsUnpaid fromDictionary:dict] doubleValue];
self.subject = [self objectOrNilForKey:kStatementDetailItemsSubject fromDictionary:dict];
self.beginDate = [self objectOrNilForKey:kStatementDetailItemsBeginDate fromDictionary:dict];
self.direction = [[self objectOrNilForKey:kStatementDetailItemsDirection fromDictionary:dict] doubleValue];
self.paid = [[self objectOrNilForKey:kStatementDetailItemsPaid fromDictionary:dict] doubleValue];
}
......@@ -66,14 +66,14 @@ NSString *const kItemsPaid = @"paid";
- (NSDictionary *)dictionaryRepresentation
{
NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
[mutableDict setValue:[NSNumber numberWithDouble:self.amount] forKey:kItemsAmount];
[mutableDict setValue:self.remark forKey:kItemsRemark];
[mutableDict setValue:[NSNumber numberWithDouble:self.endDate] forKey:kItemsEndDate];
[mutableDict setValue:[NSNumber numberWithDouble:self.unpaid] forKey:kItemsUnpaid];
[mutableDict setValue:self.subject forKey:kItemsSubject];
[mutableDict setValue:[NSNumber numberWithDouble:self.beginDate] forKey:kItemsBeginDate];
[mutableDict setValue:[NSNumber numberWithDouble:self.direction] forKey:kItemsDirection];
[mutableDict setValue:[NSNumber numberWithDouble:self.paid] forKey:kItemsPaid];
[mutableDict setValue:[NSNumber numberWithDouble:self.amount] forKey:kStatementDetailItemsAmount];
[mutableDict setValue:self.remark forKey:kStatementDetailItemsRemark];
[mutableDict setValue:self.endDate forKey:kStatementDetailItemsEndDate];
[mutableDict setValue:[NSNumber numberWithDouble:self.unpaid] forKey:kStatementDetailItemsUnpaid];
[mutableDict setValue:self.subject forKey:kStatementDetailItemsSubject];
[mutableDict setValue:self.beginDate forKey:kStatementDetailItemsBeginDate];
[mutableDict setValue:[NSNumber numberWithDouble:self.direction] forKey:kStatementDetailItemsDirection];
[mutableDict setValue:[NSNumber numberWithDouble:self.paid] forKey:kStatementDetailItemsPaid];
return [NSDictionary dictionaryWithDictionary:mutableDict];
}
......@@ -97,42 +97,42 @@ NSString *const kItemsPaid = @"paid";
{
self = [super init];
self.amount = [aDecoder decodeDoubleForKey:kItemsAmount];
self.remark = [aDecoder decodeObjectForKey:kItemsRemark];
self.endDate = [aDecoder decodeDoubleForKey:kItemsEndDate];
self.unpaid = [aDecoder decodeDoubleForKey:kItemsUnpaid];
self.subject = [aDecoder decodeObjectForKey:kItemsSubject];
self.beginDate = [aDecoder decodeDoubleForKey:kItemsBeginDate];
self.direction = [aDecoder decodeDoubleForKey:kItemsDirection];
self.paid = [aDecoder decodeDoubleForKey:kItemsPaid];
self.amount = [aDecoder decodeDoubleForKey:kStatementDetailItemsAmount];
self.remark = [aDecoder decodeObjectForKey:kStatementDetailItemsRemark];
self.endDate = [aDecoder decodeObjectForKey:kStatementDetailItemsEndDate];
self.unpaid = [aDecoder decodeDoubleForKey:kStatementDetailItemsUnpaid];
self.subject = [aDecoder decodeObjectForKey:kStatementDetailItemsSubject];
self.beginDate = [aDecoder decodeObjectForKey:kStatementDetailItemsBeginDate];
self.direction = [aDecoder decodeDoubleForKey:kStatementDetailItemsDirection];
self.paid = [aDecoder decodeDoubleForKey:kStatementDetailItemsPaid];
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeDouble:_amount forKey:kItemsAmount];
[aCoder encodeObject:_remark forKey:kItemsRemark];
[aCoder encodeDouble:_endDate forKey:kItemsEndDate];
[aCoder encodeDouble:_unpaid forKey:kItemsUnpaid];
[aCoder encodeObject:_subject forKey:kItemsSubject];
[aCoder encodeDouble:_beginDate forKey:kItemsBeginDate];
[aCoder encodeDouble:_direction forKey:kItemsDirection];
[aCoder encodeDouble:_paid forKey:kItemsPaid];
[aCoder encodeDouble:_amount forKey:kStatementDetailItemsAmount];
[aCoder encodeObject:_remark forKey:kStatementDetailItemsRemark];
[aCoder encodeObject:_endDate forKey:kStatementDetailItemsEndDate];
[aCoder encodeDouble:_unpaid forKey:kStatementDetailItemsUnpaid];
[aCoder encodeObject:_subject forKey:kStatementDetailItemsSubject];
[aCoder encodeObject:_beginDate forKey:kStatementDetailItemsBeginDate];
[aCoder encodeDouble:_direction forKey:kStatementDetailItemsDirection];
[aCoder encodeDouble:_paid forKey:kStatementDetailItemsPaid];
}
- (id)copyWithZone:(NSZone *)zone
{
Items *copy = [[Items alloc] init];
StatementDetailItems *copy = [[StatementDetailItems alloc] init];
if (copy) {
copy.amount = self.amount;
copy.remark = [self.remark copyWithZone:zone];
copy.endDate = self.endDate;
copy.endDate = [self.endDate copyWithZone:zone];
copy.unpaid = self.unpaid;
copy.subject = [self.subject copyWithZone:zone];
copy.beginDate = self.beginDate;
copy.beginDate = [self.beginDate copyWithZone:zone];
copy.direction = self.direction;
copy.paid = self.paid;
}
......
//
// StatementDetailModel.h
//
// Created by 杰 张 on 16/7/18
// Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface StatementDetailModel : NSObject <NSCoding, NSCopying>
@property (nonatomic, assign) double amount;
@property (nonatomic, strong) NSString *settle;
@property (nonatomic, assign) double unpaid;
@property (nonatomic, assign) id picture;
@property (nonatomic, strong) NSString *contract;
@property (nonatomic, strong) NSString *shopName;
@property (nonatomic, strong) NSString *shopCode;
@property (nonatomic, assign) double paid;
@property (nonatomic, strong) NSString *state;
@property (nonatomic, strong) NSArray *items;
+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict;
- (instancetype)initWithDictionary:(NSDictionary *)dict;
- (NSDictionary *)dictionaryRepresentation;
@end
//
// StatementDetailModel.m
//
// Created by 杰 张 on 16/7/18
// Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//
#import "StatementDetailModel.h"
#import "StatementDetailItems.h"
NSString *const kStatementDetailModelAmount = @"amount";
NSString *const kStatementDetailModelSettle = @"settle";
NSString *const kStatementDetailModelUnpaid = @"unpaid";
NSString *const kStatementDetailModelPicture = @"picture";
NSString *const kStatementDetailModelContract = @"contract";
NSString *const kStatementDetailModelShopName = @"shopName";
NSString *const kStatementDetailModelShopCode = @"shopCode";
NSString *const kStatementDetailModelPaid = @"paid";
NSString *const kStatementDetailModelState = @"state";
NSString *const kStatementDetailModelItems = @"items";
@interface StatementDetailModel ()
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
@end
@implementation StatementDetailModel
@synthesize amount = _amount;
@synthesize settle = _settle;
@synthesize unpaid = _unpaid;
@synthesize picture = _picture;
@synthesize contract = _contract;
@synthesize shopName = _shopName;
@synthesize shopCode = _shopCode;
@synthesize paid = _paid;
@synthesize state = _state;
@synthesize items = _items;
+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
return [[self alloc] initWithDictionary:dict];
}
- (instancetype)initWithDictionary:(NSDictionary *)dict
{
self = [super init];
// This check serves to make sure that a non-NSDictionary object
// passed into the model class doesn't break the parsing.
if(self && [dict isKindOfClass:[NSDictionary class]]) {
self.amount = [[self objectOrNilForKey:kStatementDetailModelAmount fromDictionary:dict] doubleValue];
self.settle = [self objectOrNilForKey:kStatementDetailModelSettle fromDictionary:dict];
self.unpaid = [[self objectOrNilForKey:kStatementDetailModelUnpaid fromDictionary:dict] doubleValue];
self.picture = [self objectOrNilForKey:kStatementDetailModelPicture fromDictionary:dict];
self.contract = [self objectOrNilForKey:kStatementDetailModelContract fromDictionary:dict];
self.shopName = [self objectOrNilForKey:kStatementDetailModelShopName fromDictionary:dict];
self.shopCode = [self objectOrNilForKey:kStatementDetailModelShopCode fromDictionary:dict];
self.paid = [[self objectOrNilForKey:kStatementDetailModelPaid fromDictionary:dict] doubleValue];
self.state = [self objectOrNilForKey:kStatementDetailModelState fromDictionary:dict];
NSObject *receivedStatementDetailItems = [dict objectForKey:kStatementDetailModelItems];
NSMutableArray *parsedStatementDetailItems = [NSMutableArray array];
if ([receivedStatementDetailItems isKindOfClass:[NSArray class]]) {
for (NSDictionary *item in (NSArray *)receivedStatementDetailItems) {
if ([item isKindOfClass:[NSDictionary class]]) {
[parsedStatementDetailItems addObject:[StatementDetailItems modelObjectWithDictionary:item]];
}
}
} else if ([receivedStatementDetailItems isKindOfClass:[NSDictionary class]]) {
[parsedStatementDetailItems addObject:[StatementDetailItems modelObjectWithDictionary:(NSDictionary *)receivedStatementDetailItems]];
}
self.items = [NSArray arrayWithArray:parsedStatementDetailItems];
}
return self;
}
- (NSDictionary *)dictionaryRepresentation
{
NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
[mutableDict setValue:[NSNumber numberWithDouble:self.amount] forKey:kStatementDetailModelAmount];
[mutableDict setValue:self.settle forKey:kStatementDetailModelSettle];
[mutableDict setValue:[NSNumber numberWithDouble:self.unpaid] forKey:kStatementDetailModelUnpaid];
[mutableDict setValue:self.picture forKey:kStatementDetailModelPicture];
[mutableDict setValue:self.contract forKey:kStatementDetailModelContract];
[mutableDict setValue:self.shopName forKey:kStatementDetailModelShopName];
[mutableDict setValue:self.shopCode forKey:kStatementDetailModelShopCode];
[mutableDict setValue:[NSNumber numberWithDouble:self.paid] forKey:kStatementDetailModelPaid];
[mutableDict setValue:self.state forKey:kStatementDetailModelState];
NSMutableArray *tempArrayForItems = [NSMutableArray array];
for (NSObject *subArrayObject in self.items) {
if([subArrayObject respondsToSelector:@selector(dictionaryRepresentation)]) {
// This class is a model object
[tempArrayForItems addObject:[subArrayObject performSelector:@selector(dictionaryRepresentation)]];
} else {
// Generic object
[tempArrayForItems addObject:subArrayObject];
}
}
[mutableDict setValue:[NSArray arrayWithArray:tempArrayForItems] forKey:kStatementDetailModelItems];
return [NSDictionary dictionaryWithDictionary:mutableDict];
}
- (NSString *)description
{
return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}
#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
id object = [dict objectForKey:aKey];
return [object isEqual:[NSNull null]] ? nil : object;
}
#pragma mark - NSCoding Methods
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
self.amount = [aDecoder decodeDoubleForKey:kStatementDetailModelAmount];
self.settle = [aDecoder decodeObjectForKey:kStatementDetailModelSettle];
self.unpaid = [aDecoder decodeDoubleForKey:kStatementDetailModelUnpaid];
self.picture = [aDecoder decodeObjectForKey:kStatementDetailModelPicture];
self.contract = [aDecoder decodeObjectForKey:kStatementDetailModelContract];
self.shopName = [aDecoder decodeObjectForKey:kStatementDetailModelShopName];
self.shopCode = [aDecoder decodeObjectForKey:kStatementDetailModelShopCode];
self.paid = [aDecoder decodeDoubleForKey:kStatementDetailModelPaid];
self.state = [aDecoder decodeObjectForKey:kStatementDetailModelState];
self.items = [aDecoder decodeObjectForKey:kStatementDetailModelItems];
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeDouble:_amount forKey:kStatementDetailModelAmount];
[aCoder encodeObject:_settle forKey:kStatementDetailModelSettle];
[aCoder encodeDouble:_unpaid forKey:kStatementDetailModelUnpaid];
[aCoder encodeObject:_picture forKey:kStatementDetailModelPicture];
[aCoder encodeObject:_contract forKey:kStatementDetailModelContract];
[aCoder encodeObject:_shopName forKey:kStatementDetailModelShopName];
[aCoder encodeObject:_shopCode forKey:kStatementDetailModelShopCode];
[aCoder encodeDouble:_paid forKey:kStatementDetailModelPaid];
[aCoder encodeObject:_state forKey:kStatementDetailModelState];
[aCoder encodeObject:_items forKey:kStatementDetailModelItems];
}
- (id)copyWithZone:(NSZone *)zone
{
StatementDetailModel *copy = [[StatementDetailModel alloc] init];
if (copy) {
copy.amount = self.amount;
copy.settle = [self.settle copyWithZone:zone];
copy.unpaid = self.unpaid;
copy.picture = [self.picture copyWithZone:zone];
copy.contract = [self.contract copyWithZone:zone];
copy.shopName = [self.shopName copyWithZone:zone];
copy.shopCode = [self.shopCode copyWithZone:zone];
copy.paid = self.paid;
copy.state = [self.state copyWithZone:zone];
copy.items = [self.items copyWithZone:zone];
}
return copy;
}
@end
......@@ -6,21 +6,17 @@
//
#import <Foundation/Foundation.h>
#import "StatementRecords.h"
#import "StatementPaging.h"
@class StatementPaging;
@interface StatementModel : NSObject <NSCoding, NSCopying>
@property (nonatomic, strong) NSArray *records;
@property (nonatomic, assign) double amount;
@property (nonatomic, strong) NSString *settle;
@property (nonatomic, assign) double unpaid;
@property (nonatomic, strong) NSString *picture;
@property (nonatomic, strong) NSString *contract;
@property (nonatomic, strong) NSString *shopName;
@property (nonatomic, strong) NSString *shopCode;
@property (nonatomic, assign) double paid;
@property (nonatomic, strong) NSString *state;
@property (nonatomic, strong) NSArray *items;
@property (nonatomic, assign) double unpaidTotal;
@property (nonatomic, assign) double paidTotal;
@property (nonatomic, strong) StatementPaging *paging;
+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict;
- (instancetype)initWithDictionary:(NSDictionary *)dict;
......
......@@ -6,19 +6,15 @@
//
#import "StatementModel.h"
#import "Items.h"
#import "StatementRecords.h"
#import "StatementPaging.h"
NSString *const kStatementModelRecords = @"records";
NSString *const kStatementModelAmount = @"amount";
NSString *const kStatementModelSettle = @"settle";
NSString *const kStatementModelUnpaid = @"unpaid";
NSString *const kStatementModelPicture = @"picture";
NSString *const kStatementModelContract = @"contract";
NSString *const kStatementModelShopName = @"shopName";
NSString *const kStatementModelShopCode = @"shopCode";
NSString *const kStatementModelPaid = @"paid";
NSString *const kStatementModelState = @"state";
NSString *const kStatementModelItems = @"items";
NSString *const kStatementModelUnpaidTotal = @"unpaidTotal";
NSString *const kStatementModelPaidTotal = @"paidTotal";
NSString *const kStatementModelPaging = @"paging";
@interface StatementModel ()
......@@ -29,16 +25,11 @@ NSString *const kStatementModelItems = @"items";
@implementation StatementModel
@synthesize records = _records;
@synthesize amount = _amount;
@synthesize settle = _settle;
@synthesize unpaid = _unpaid;
@synthesize picture = _picture;
@synthesize contract = _contract;
@synthesize shopName = _shopName;
@synthesize shopCode = _shopCode;
@synthesize paid = _paid;
@synthesize state = _state;
@synthesize items = _items;
@synthesize unpaidTotal = _unpaidTotal;
@synthesize paidTotal = _paidTotal;
@synthesize paging = _paging;
+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
......@@ -53,28 +44,23 @@ NSString *const kStatementModelItems = @"items";
// This check serves to make sure that a non-NSDictionary object
// passed into the model class doesn't break the parsing.
if(self && [dict isKindOfClass:[NSDictionary class]]) {
self.amount = [[self objectOrNilForKey:kStatementModelAmount fromDictionary:dict] doubleValue];
self.settle = [self objectOrNilForKey:kStatementModelSettle fromDictionary:dict];
self.unpaid = [[self objectOrNilForKey:kStatementModelUnpaid fromDictionary:dict] doubleValue];
self.picture = [self objectOrNilForKey:kStatementModelPicture fromDictionary:dict];
self.contract = [self objectOrNilForKey:kStatementModelContract fromDictionary:dict];
self.shopName = [self objectOrNilForKey:kStatementModelShopName fromDictionary:dict];
self.shopCode = [self objectOrNilForKey:kStatementModelShopCode fromDictionary:dict];
self.paid = [[self objectOrNilForKey:kStatementModelPaid fromDictionary:dict] doubleValue];
self.state = [self objectOrNilForKey:kStatementModelState fromDictionary:dict];
NSObject *receivedItems = [dict objectForKey:kStatementModelItems];
NSMutableArray *parsedItems = [NSMutableArray array];
if ([receivedItems isKindOfClass:[NSArray class]]) {
for (NSDictionary *item in (NSArray *)receivedItems) {
NSObject *receivedStatementRecords = [dict objectForKey:kStatementModelRecords];
NSMutableArray *parsedStatementRecords = [NSMutableArray array];
if ([receivedStatementRecords isKindOfClass:[NSArray class]]) {
for (NSDictionary *item in (NSArray *)receivedStatementRecords) {
if ([item isKindOfClass:[NSDictionary class]]) {
[parsedItems addObject:[Items modelObjectWithDictionary:item]];
[parsedStatementRecords addObject:[StatementRecords modelObjectWithDictionary:item]];
}
}
} else if ([receivedItems isKindOfClass:[NSDictionary class]]) {
[parsedItems addObject:[Items modelObjectWithDictionary:(NSDictionary *)receivedItems]];
} else if ([receivedStatementRecords isKindOfClass:[NSDictionary class]]) {
[parsedStatementRecords addObject:[StatementRecords modelObjectWithDictionary:(NSDictionary *)receivedStatementRecords]];
}
self.items = [NSArray arrayWithArray:parsedItems];
self.records = [NSArray arrayWithArray:parsedStatementRecords];
self.amount = [[self objectOrNilForKey:kStatementModelAmount fromDictionary:dict] doubleValue];
self.unpaidTotal = [[self objectOrNilForKey:kStatementModelUnpaidTotal fromDictionary:dict] doubleValue];
self.paidTotal = [[self objectOrNilForKey:kStatementModelPaidTotal fromDictionary:dict] doubleValue];
self.paging = [StatementPaging modelObjectWithDictionary:[dict objectForKey:kStatementModelPaging]];
}
......@@ -85,26 +71,21 @@ NSString *const kStatementModelItems = @"items";
- (NSDictionary *)dictionaryRepresentation
{
NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
[mutableDict setValue:[NSNumber numberWithDouble:self.amount] forKey:kStatementModelAmount];
[mutableDict setValue:self.settle forKey:kStatementModelSettle];
[mutableDict setValue:[NSNumber numberWithDouble:self.unpaid] forKey:kStatementModelUnpaid];
[mutableDict setValue:self.picture forKey:kStatementModelPicture];
[mutableDict setValue:self.contract forKey:kStatementModelContract];
[mutableDict setValue:self.shopName forKey:kStatementModelShopName];
[mutableDict setValue:self.shopCode forKey:kStatementModelShopCode];
[mutableDict setValue:[NSNumber numberWithDouble:self.paid] forKey:kStatementModelPaid];
[mutableDict setValue:self.state forKey:kStatementModelState];
NSMutableArray *tempArrayForItems = [NSMutableArray array];
for (NSObject *subArrayObject in self.items) {
NSMutableArray *tempArrayForRecords = [NSMutableArray array];
for (NSObject *subArrayObject in self.records) {
if([subArrayObject respondsToSelector:@selector(dictionaryRepresentation)]) {
// This class is a model object
[tempArrayForItems addObject:[subArrayObject performSelector:@selector(dictionaryRepresentation)]];
[tempArrayForRecords addObject:[subArrayObject performSelector:@selector(dictionaryRepresentation)]];
} else {
// Generic object
[tempArrayForItems addObject:subArrayObject];
[tempArrayForRecords addObject:subArrayObject];
}
}
[mutableDict setValue:[NSArray arrayWithArray:tempArrayForItems] forKey:kStatementModelItems];
[mutableDict setValue:[NSArray arrayWithArray:tempArrayForRecords] forKey:kStatementModelRecords];
[mutableDict setValue:[NSNumber numberWithDouble:self.amount] forKey:kStatementModelAmount];
[mutableDict setValue:[NSNumber numberWithDouble:self.unpaidTotal] forKey:kStatementModelUnpaidTotal];
[mutableDict setValue:[NSNumber numberWithDouble:self.paidTotal] forKey:kStatementModelPaidTotal];
[mutableDict setValue:[self.paging dictionaryRepresentation] forKey:kStatementModelPaging];
return [NSDictionary dictionaryWithDictionary:mutableDict];
}
......@@ -128,32 +109,22 @@ NSString *const kStatementModelItems = @"items";
{
self = [super init];
self.records = [aDecoder decodeObjectForKey:kStatementModelRecords];
self.amount = [aDecoder decodeDoubleForKey:kStatementModelAmount];
self.settle = [aDecoder decodeObjectForKey:kStatementModelSettle];
self.unpaid = [aDecoder decodeDoubleForKey:kStatementModelUnpaid];
self.picture = [aDecoder decodeObjectForKey:kStatementModelPicture];
self.contract = [aDecoder decodeObjectForKey:kStatementModelContract];
self.shopName = [aDecoder decodeObjectForKey:kStatementModelShopName];
self.shopCode = [aDecoder decodeObjectForKey:kStatementModelShopCode];
self.paid = [aDecoder decodeDoubleForKey:kStatementModelPaid];
self.state = [aDecoder decodeObjectForKey:kStatementModelState];
self.items = [aDecoder decodeObjectForKey:kStatementModelItems];
self.unpaidTotal = [aDecoder decodeDoubleForKey:kStatementModelUnpaidTotal];
self.paidTotal = [aDecoder decodeDoubleForKey:kStatementModelPaidTotal];
self.paging = [aDecoder decodeObjectForKey:kStatementModelPaging];
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:_records forKey:kStatementModelRecords];
[aCoder encodeDouble:_amount forKey:kStatementModelAmount];
[aCoder encodeObject:_settle forKey:kStatementModelSettle];
[aCoder encodeDouble:_unpaid forKey:kStatementModelUnpaid];
[aCoder encodeObject:_picture forKey:kStatementModelPicture];
[aCoder encodeObject:_contract forKey:kStatementModelContract];
[aCoder encodeObject:_shopName forKey:kStatementModelShopName];
[aCoder encodeObject:_shopCode forKey:kStatementModelShopCode];
[aCoder encodeDouble:_paid forKey:kStatementModelPaid];
[aCoder encodeObject:_state forKey:kStatementModelState];
[aCoder encodeObject:_items forKey:kStatementModelItems];
[aCoder encodeDouble:_unpaidTotal forKey:kStatementModelUnpaidTotal];
[aCoder encodeDouble:_paidTotal forKey:kStatementModelPaidTotal];
[aCoder encodeObject:_paging forKey:kStatementModelPaging];
}
- (id)copyWithZone:(NSZone *)zone
......@@ -162,16 +133,11 @@ NSString *const kStatementModelItems = @"items";
if (copy) {
copy.records = [self.records copyWithZone:zone];
copy.amount = self.amount;
copy.settle = [self.settle copyWithZone:zone];
copy.unpaid = self.unpaid;
copy.picture = [self.picture copyWithZone:zone];
copy.contract = [self.contract copyWithZone:zone];
copy.shopName = [self.shopName copyWithZone:zone];
copy.shopCode = [self.shopCode copyWithZone:zone];
copy.paid = self.paid;
copy.state = [self.state copyWithZone:zone];
copy.items = [self.items copyWithZone:zone];
copy.unpaidTotal = self.unpaidTotal;
copy.paidTotal = self.paidTotal;
copy.paging = [self.paging copyWithZone:zone];
}
return copy;
......
//
// StatementPaging.h
//
// Created by 杰 张 on 16/7/18
// Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface StatementPaging : NSObject <NSCoding, NSCopying>
@property (nonatomic, assign) double pageCount;
@property (nonatomic, assign) double recordCount;
@property (nonatomic, assign) double pageSize;
@property (nonatomic, assign) double page;
+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict;
- (instancetype)initWithDictionary:(NSDictionary *)dict;
- (NSDictionary *)dictionaryRepresentation;
@end
//
// StatementPaging.m
//
// Created by 杰 张 on 16/7/18
// Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//
#import "StatementPaging.h"
NSString *const kStatementPagingPageCount = @"pageCount";
NSString *const kStatementPagingRecordCount = @"recordCount";
NSString *const kStatementPagingPageSize = @"pageSize";
NSString *const kStatementPagingPage = @"page";
@interface StatementPaging ()
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
@end
@implementation StatementPaging
@synthesize pageCount = _pageCount;
@synthesize recordCount = _recordCount;
@synthesize pageSize = _pageSize;
@synthesize page = _page;
+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
return [[self alloc] initWithDictionary:dict];
}
- (instancetype)initWithDictionary:(NSDictionary *)dict
{
self = [super init];
// This check serves to make sure that a non-NSDictionary object
// passed into the model class doesn't break the parsing.
if(self && [dict isKindOfClass:[NSDictionary class]]) {
self.pageCount = [[self objectOrNilForKey:kStatementPagingPageCount fromDictionary:dict] doubleValue];
self.recordCount = [[self objectOrNilForKey:kStatementPagingRecordCount fromDictionary:dict] doubleValue];
self.pageSize = [[self objectOrNilForKey:kStatementPagingPageSize fromDictionary:dict] doubleValue];
self.page = [[self objectOrNilForKey:kStatementPagingPage fromDictionary:dict] doubleValue];
}
return self;
}
- (NSDictionary *)dictionaryRepresentation
{
NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
[mutableDict setValue:[NSNumber numberWithDouble:self.pageCount] forKey:kStatementPagingPageCount];
[mutableDict setValue:[NSNumber numberWithDouble:self.recordCount] forKey:kStatementPagingRecordCount];
[mutableDict setValue:[NSNumber numberWithDouble:self.pageSize] forKey:kStatementPagingPageSize];
[mutableDict setValue:[NSNumber numberWithDouble:self.page] forKey:kStatementPagingPage];
return [NSDictionary dictionaryWithDictionary:mutableDict];
}
- (NSString *)description
{
return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}
#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
id object = [dict objectForKey:aKey];
return [object isEqual:[NSNull null]] ? nil : object;
}
#pragma mark - NSCoding Methods
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
self.pageCount = [aDecoder decodeDoubleForKey:kStatementPagingPageCount];
self.recordCount = [aDecoder decodeDoubleForKey:kStatementPagingRecordCount];
self.pageSize = [aDecoder decodeDoubleForKey:kStatementPagingPageSize];
self.page = [aDecoder decodeDoubleForKey:kStatementPagingPage];
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeDouble:_pageCount forKey:kStatementPagingPageCount];
[aCoder encodeDouble:_recordCount forKey:kStatementPagingRecordCount];
[aCoder encodeDouble:_pageSize forKey:kStatementPagingPageSize];
[aCoder encodeDouble:_page forKey:kStatementPagingPage];
}
- (id)copyWithZone:(NSZone *)zone
{
StatementPaging *copy = [[StatementPaging alloc] init];
if (copy) {
copy.pageCount = self.pageCount;
copy.recordCount = self.recordCount;
copy.pageSize = self.pageSize;
copy.page = self.page;
}
return copy;
}
@end
//
// StatementRecords.h
//
// Created by 杰 张 on 16/7/18
// Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface StatementRecords : NSObject <NSCoding, NSCopying>
@property (nonatomic, assign) double amount;
@property (nonatomic, strong) NSString *settle;
@property (nonatomic, assign) double unpaid;
@property (nonatomic, assign) id picture;
@property (nonatomic, strong) NSString *contract;
@property (nonatomic, strong) NSString *shopName;
@property (nonatomic, strong) NSString *shopCode;
@property (nonatomic, assign) double paid;
@property (nonatomic, strong) NSString *state;
@property (nonatomic, strong) NSArray *items;
+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict;
- (instancetype)initWithDictionary:(NSDictionary *)dict;
- (NSDictionary *)dictionaryRepresentation;
@end
//
// StatementRecords.m
//
// Created by 杰 张 on 16/7/18
// Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//
#import "StatementRecords.h"
NSString *const kStatementRecordsAmount = @"amount";
NSString *const kStatementRecordsSettle = @"settle";
NSString *const kStatementRecordsUnpaid = @"unpaid";
NSString *const kStatementRecordsPicture = @"picture";
NSString *const kStatementRecordsContract = @"contract";
NSString *const kStatementRecordsShopName = @"shopName";
NSString *const kStatementRecordsShopCode = @"shopCode";
NSString *const kStatementRecordsPaid = @"paid";
NSString *const kStatementRecordsState = @"state";
NSString *const kStatementRecordsItems = @"items";
@interface StatementRecords ()
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
@end
@implementation StatementRecords
@synthesize amount = _amount;
@synthesize settle = _settle;
@synthesize unpaid = _unpaid;
@synthesize picture = _picture;
@synthesize contract = _contract;
@synthesize shopName = _shopName;
@synthesize shopCode = _shopCode;
@synthesize paid = _paid;
@synthesize state = _state;
@synthesize items = _items;
+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
return [[self alloc] initWithDictionary:dict];
}
- (instancetype)initWithDictionary:(NSDictionary *)dict
{
self = [super init];
// This check serves to make sure that a non-NSDictionary object
// passed into the model class doesn't break the parsing.
if(self && [dict isKindOfClass:[NSDictionary class]]) {
self.amount = [[self objectOrNilForKey:kStatementRecordsAmount fromDictionary:dict] doubleValue];
self.settle = [self objectOrNilForKey:kStatementRecordsSettle fromDictionary:dict];
self.unpaid = [[self objectOrNilForKey:kStatementRecordsUnpaid fromDictionary:dict] doubleValue];
self.picture = [self objectOrNilForKey:kStatementRecordsPicture fromDictionary:dict];
self.contract = [self objectOrNilForKey:kStatementRecordsContract fromDictionary:dict];
self.shopName = [self objectOrNilForKey:kStatementRecordsShopName fromDictionary:dict];
self.shopCode = [self objectOrNilForKey:kStatementRecordsShopCode fromDictionary:dict];
self.paid = [[self objectOrNilForKey:kStatementRecordsPaid fromDictionary:dict] doubleValue];
self.state = [self objectOrNilForKey:kStatementRecordsState fromDictionary:dict];
self.items = [self objectOrNilForKey:kStatementRecordsItems fromDictionary:dict];
}
return self;
}
- (NSDictionary *)dictionaryRepresentation
{
NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
[mutableDict setValue:[NSNumber numberWithDouble:self.amount] forKey:kStatementRecordsAmount];
[mutableDict setValue:self.settle forKey:kStatementRecordsSettle];
[mutableDict setValue:[NSNumber numberWithDouble:self.unpaid] forKey:kStatementRecordsUnpaid];
[mutableDict setValue:self.picture forKey:kStatementRecordsPicture];
[mutableDict setValue:self.contract forKey:kStatementRecordsContract];
[mutableDict setValue:self.shopName forKey:kStatementRecordsShopName];
[mutableDict setValue:self.shopCode forKey:kStatementRecordsShopCode];
[mutableDict setValue:[NSNumber numberWithDouble:self.paid] forKey:kStatementRecordsPaid];
[mutableDict setValue:self.state forKey:kStatementRecordsState];
NSMutableArray *tempArrayForItems = [NSMutableArray array];
for (NSObject *subArrayObject in self.items) {
if([subArrayObject respondsToSelector:@selector(dictionaryRepresentation)]) {
// This class is a model object
[tempArrayForItems addObject:[subArrayObject performSelector:@selector(dictionaryRepresentation)]];
} else {
// Generic object
[tempArrayForItems addObject:subArrayObject];
}
}
[mutableDict setValue:[NSArray arrayWithArray:tempArrayForItems] forKey:kStatementRecordsItems];
return [NSDictionary dictionaryWithDictionary:mutableDict];
}
- (NSString *)description
{
return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}
#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
id object = [dict objectForKey:aKey];
return [object isEqual:[NSNull null]] ? nil : object;
}
#pragma mark - NSCoding Methods
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
self.amount = [aDecoder decodeDoubleForKey:kStatementRecordsAmount];
self.settle = [aDecoder decodeObjectForKey:kStatementRecordsSettle];
self.unpaid = [aDecoder decodeDoubleForKey:kStatementRecordsUnpaid];
self.picture = [aDecoder decodeObjectForKey:kStatementRecordsPicture];
self.contract = [aDecoder decodeObjectForKey:kStatementRecordsContract];
self.shopName = [aDecoder decodeObjectForKey:kStatementRecordsShopName];
self.shopCode = [aDecoder decodeObjectForKey:kStatementRecordsShopCode];
self.paid = [aDecoder decodeDoubleForKey:kStatementRecordsPaid];
self.state = [aDecoder decodeObjectForKey:kStatementRecordsState];
self.items = [aDecoder decodeObjectForKey:kStatementRecordsItems];
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeDouble:_amount forKey:kStatementRecordsAmount];
[aCoder encodeObject:_settle forKey:kStatementRecordsSettle];
[aCoder encodeDouble:_unpaid forKey:kStatementRecordsUnpaid];
[aCoder encodeObject:_picture forKey:kStatementRecordsPicture];
[aCoder encodeObject:_contract forKey:kStatementRecordsContract];
[aCoder encodeObject:_shopName forKey:kStatementRecordsShopName];
[aCoder encodeObject:_shopCode forKey:kStatementRecordsShopCode];
[aCoder encodeDouble:_paid forKey:kStatementRecordsPaid];
[aCoder encodeObject:_state forKey:kStatementRecordsState];
[aCoder encodeObject:_items forKey:kStatementRecordsItems];
}
- (id)copyWithZone:(NSZone *)zone
{
StatementRecords *copy = [[StatementRecords alloc] init];
if (copy) {
copy.amount = self.amount;
copy.settle = [self.settle copyWithZone:zone];
copy.unpaid = self.unpaid;
copy.picture = [self.picture copyWithZone:zone];
copy.contract = [self.contract copyWithZone:zone];
copy.shopName = [self.shopName copyWithZone:zone];
copy.shopCode = [self.shopCode copyWithZone:zone];
copy.paid = self.paid;
copy.state = [self.state copyWithZone:zone];
copy.items = [self.items copyWithZone:zone];
}
return copy;
}
@end
......@@ -7,7 +7,12 @@
//
#import "BaseViewController.h"
#import "StatementRecords.h"
@interface StatementDetailViewController : BaseViewController
@property (nonatomic, copy) NSString *startDate;
@property (nonatomic, copy) NSString *endDate;
@property (nonatomic, strong) StatementRecords *record;
@end
......@@ -8,8 +8,34 @@
#import "StatementDetailViewController.h"
#import "StatementDetailCell.h"
@interface StatementDetailViewController ()<UITableViewDelegate, UITableViewDataSource>
#import "StatementDetailModel.h"
#import "SRMonthPicker.h"
#import "UIScrollView+EmptyDataSet.h"
#import "CalculateHelper.h"
@interface StatementDetailViewController ()<UITableViewDelegate, UITableViewDataSource,SRMonthPickerDelegate, UITextFieldDelegate, DZNEmptyDataSetDelegate, DZNEmptyDataSetSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) StatementDetailModel *detailModel;
/** 应缴 */
@property (weak, nonatomic) IBOutlet UILabel *labelShoudPay;
/** 已缴 */
@property (weak, nonatomic) IBOutlet UILabel *labelPaid;
/** 未缴 */
@property (weak, nonatomic) IBOutlet UILabel *labelUnpaid;
/** year start */
@property (weak, nonatomic) IBOutlet UILabel *labelYearStart;
/** month start */
@property (weak, nonatomic) IBOutlet UILabel *labelMonthStart;
/** year start */
@property (weak, nonatomic) IBOutlet UILabel *labelYearEnd;
/** month end */
@property (weak, nonatomic) IBOutlet UILabel *labelMontEnd;
/** textfield start */
@property (weak, nonatomic) IBOutlet UITextField *textFieldStart;
/** textfield end */
@property (weak, nonatomic) IBOutlet UITextField *textFieldEnd;
/** 缴款率 */
@property (weak, nonatomic) IBOutlet UILabel *labelPaidRate;
@end
......@@ -17,6 +43,76 @@
- (void)viewDidLoad {
[super viewDidLoad];
NSDate *selectStart = [self getDateFromString:self.startDate];
NSDate *selectEnd = [self getDateFromString:self.endDate];
[self setStart:selectStart];
[self setEnd:selectEnd];
self.textFieldStart.delegate = self;
self.textFieldEnd.delegate = self;
[self setUpDatePicker];
[self setUpData];
}
/** 设置开始时间 */
- (void)setStart:(NSDate *)date {
self.labelYearStart.text = date.yearString;
self.labelMonthStart.text = date.monthString;
}
/** 设置结束时间 */
- (void)setEnd:(NSDate *)date {
self.labelYearEnd.text = date.yearString;
self.labelMontEnd.text = date.monthString;
}
- (void)setUpDatePicker {
SRMonthPicker *datePicker = [[SRMonthPicker alloc] initWithDate:[NSDate date]];
datePicker.monthPickerDelegate = self;
datePicker.yearFirst = YES;
self.textFieldStart.inputView = datePicker;
self.textFieldEnd.inputView = datePicker;
}
#pragma mark - SRMonthPickerDelegate
- (void)monthPickerDidChangeDate:(SRMonthPicker *)monthPicker {
NSString *strDate = [monthPicker.date stringWithFormatter:@"%Y%m"];
NSString *year = monthPicker.date.yearString;
NSString *month = monthPicker.date.monthString;
//判断是开始时间还是结束时间
if ([self.textFieldStart isFirstResponder]) {
self.startDate = strDate;
self.labelYearStart.text = year;
self.labelMonthStart.text = month;
}else{
self.endDate = strDate;
self.labelYearEnd.text = year;
self.labelMontEnd.text = month;
}
}
- (void)setUpData {
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
NSString *url = [NSString stringWithFormat:@"statement?contract=%@&beginSettle=%@&endSettle=%@",self.record.contract,self.startDate, self.endDate];
WS(weakSelf);
[[ICRHTTPController sharedController] getUrl:url params:nil success:^(id data) {
NSDictionary *dic = data;
weakSelf.detailModel = [StatementDetailModel modelObjectWithDictionary:dic[@"data"]];
weakSelf.title = weakSelf.detailModel.shopName;
weakSelf.labelShoudPay.text = [NSString stringWithFormat:@"应缴:%.2f", weakSelf.detailModel.amount];
weakSelf.labelPaid.text = [NSString stringWithFormat:@"已缴:%.2f",weakSelf.detailModel.paid];
weakSelf.labelUnpaid.text = [NSString stringWithFormat:@"未缴:%.2f",weakSelf.detailModel.unpaid];
//缴款率
NSString *paidRate = [CalculateHelper getPercent:[NSNumber numberWithDouble:weakSelf.detailModel.paid] num:[NSNumber numberWithDouble:weakSelf.detailModel.amount]];
weakSelf.labelPaidRate.text = paidRate;
[weakSelf.tableView reloadData];
[hud hide:YES];
CLog(@"%@", dic.JSONString);
} failure:^(id data) {
}];
}
......@@ -26,14 +122,45 @@
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 10;
return self.detailModel.items.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
StatementDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"StatementDetailCell" forIndexPath:indexPath];
[cell setUpCellWithModelArray:self.detailModel.items index:indexPath];
return cell;
}
- (NSDate *)getDateFromString:(NSString *)string {
NSDateFormatter *f = [[NSDateFormatter alloc] init];
[f setDateFormat:@"yyyyMM"];
return [f dateFromString:string];
}
#pragma mark - empty state
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
return [UIImage imageNamed:@"no_data"];
}
- (CAAnimation *)imageAnimationForEmptyDataSet:(UIScrollView *)scrollView {
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath: @"transform"];
animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_2, 0.0, 0.0, 1.0)];
animation.duration = 0.25;
animation.cumulative = YES;
animation.repeatCount = MAXFLOAT;
return animation;
}
#pragma mark - textfield delegate
- (void)textFieldDidEndEditing:(UITextField *)textField {
[self setUpData];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
......
......@@ -13,9 +13,14 @@
#import "StatementListParamModel.h"
#import "StatementModel.h"
#import "VankeAppBoard_iPhone.h"
@interface StatementViewController ()<UITableViewDelegate, UITableViewDataSource, SRMonthPickerDelegate, UISearchBarDelegate>
#import "CalculateHelper.h"
#import "StatementDetailViewController.h"
#import "UIScrollView+EmptyDataSet.h"
@interface StatementViewController ()<UITableViewDelegate, UITableViewDataSource, SRMonthPickerDelegate, UISearchBarDelegate, UITextFieldDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
/** 已缴百分比 */
@property (weak, nonatomic) IBOutlet UILabel *labelTotalPaidPercent;
/** 共?家商铺 */
@property (weak, nonatomic) IBOutlet UILabel *labelTotalShop;
/** 应缴合计 */
......@@ -37,6 +42,11 @@
/** 截止 月 */
@property (weak, nonatomic) IBOutlet UILabel *labelFinishMonth;
@property (weak, nonatomic) IBOutlet UISearchBar *searchBar;
@property (nonatomic, strong) NSArray *arrFilter;
@property (nonatomic, strong) NSMutableArray *arrClear;
@property (weak, nonatomic) IBOutlet UIButton *btnIsClear;
/** 当前选中的日期 */
@property (nonatomic, copy) NSString *startDate;
@property (nonatomic, copy) NSString *endDate;
......@@ -44,7 +54,7 @@
/** 网络请求参数 */
@property (nonatomic, strong) StatementListParamModel *paramModel;
@property (nonatomic, strong) NSMutableArray *arrData;
@property (nonatomic, strong) StatementModel *statementModel;
@end
@implementation StatementViewController
......@@ -56,7 +66,8 @@
[self setUpDatePicker];
self.paramModel = [[StatementListParamModel alloc] init];
self.title = @"商铺对账单";
// self.paramModel.authorizedOrgIn = [[UserInfo shareInstance].authorizedOrgs[0] uuid];
self.tableView.emptyDataSetSource = self;
self.tableView.emptyDataSetDelegate = self;
self.paramModel.pageSize = 999;
self.paramModel.pageNumber = 0;
[self setUpData];
......@@ -66,12 +77,12 @@
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// self.navigationController.navigationBar.barTintColor = kMainPurpleColor;
self.navigationController.navigationBar.backgroundImage = [UIImage imageWithColor:kMainPurpleColor];
}
- (void)setDefaults {
NSDate *currentDate = [NSDate date];
self.startDate = currentDate.yearMonthString;
self.startDate = [currentDate stringWithFormatter:@"%Y%m"];
self.endDate = [currentDate stringWithFormatter:@"%Y%m"];
self.labelYear.text = currentDate.yearString;
self.labelMonth.text = currentDate.monthString;
......@@ -90,11 +101,12 @@
/** 显示结清账户 */
- (IBAction)showSettleShop:(UIButton *)sender {
sender.selected = !sender.isSelected;
[self.tableView reloadData];
}
#pragma mark - SRMonthPickerDelegate
- (void)monthPickerDidChangeDate:(SRMonthPicker *)monthPicker {
NSString *strDate = monthPicker.date.yearMonthString;
NSString *strDate = [monthPicker.date stringWithFormatter:@"%Y%m"];
NSString *year = monthPicker.date.yearString;
NSString *month = monthPicker.date.monthString;
//判断是开始时间还是结束时间
......@@ -112,12 +124,20 @@
#pragma mark - UISearchBarDelegate
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
searchBar.showsCancelButton = YES;
[self.tableView reloadData];
return YES;
}
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
NSPredicate *pred = [NSPredicate predicateWithFormat:@"shopName contains [cd] %@ OR shopCode contains [cd] %@", searchText, searchText];
self.arrFilter = [self.statementModel.records filteredArrayUsingPredicate:pred];
[self.tableView reloadData];
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
searchBar.showsCancelButton = NO;
searchBar.text = nil;
[self.tableView reloadData];
HIDE_KEYBOARD;
}
......@@ -128,34 +148,55 @@
/** 网络请求 */
- (void)setUpData {
NSString *url = [NSString stringWithFormat:@"statement/query/%@~%@?authorizedOrgIn=%@&pageNumber=%@&pageSize=%@", @"201509", self.endDate, self.org.code, @0, @999];
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
NSString *url = [NSString stringWithFormat:@"statement/query/%@~%@?authorizedOrgIn=%@&pageNumber=%@&pageSize=%@", self.startDate, self.endDate, self.org.code, @0, @999];
WS(weakSelf);
[[ICRHTTPController sharedController] getUrl:url params:nil success:^(id data) {
NSDictionary *dict = data;
CLog(@"%@", dict.JSONString);
NSInteger count = dict[@"paging"][@"recordCount"];
weakSelf.labelTotalShop.text = [NSString stringWithFormat:@"%ld",(long)count];
for (NSDictionary *dic in data[@"data"][@"records"]) {
[self.arrData addObject:[StatementModel modelObjectWithDictionary:dic]];
weakSelf.statementModel = [StatementModel modelObjectWithDictionary:dict[@"data"]];
weakSelf.labelTotalShop.text = [NSString stringWithFormat:@"共%@家",[NSNumber numberWithDouble:weakSelf.statementModel.paging.recordCount]];
weakSelf.labelTotalShouldPay.text = [NSString stringWithFormat:@"应缴:%@",[CalculateHelper getMoneyStringFrom:[NSNumber numberWithDouble:weakSelf.statementModel.amount]]];
weakSelf.labelTotalPaidIn.text = [NSString stringWithFormat:@"已缴:%@",[CalculateHelper getMoneyStringFrom:[NSNumber numberWithDouble:weakSelf.statementModel.paidTotal]]];
weakSelf.labelTotalUnPaid.text = [NSString stringWithFormat:@"未缴:%@",[CalculateHelper getMoneyStringFrom:[NSNumber numberWithDouble:weakSelf.statementModel.unpaidTotal]]];
weakSelf.labelTotalPaidPercent.text = [CalculateHelper getPercent:[NSNumber numberWithDouble:weakSelf.statementModel.paidTotal] num:[NSNumber numberWithDouble:weakSelf.statementModel.amount]];
[weakSelf.tableView reloadData];
for (StatementRecords *records in weakSelf.statementModel.records) {
if (records.unpaid == 0) {
[weakSelf.arrClear addObject:records];
}
}
[self.tableView reloadData];
[hud hide:YES];
} failure:^(id data) {
[hud hide:YES];
}];
}
#pragma mark - tableView DataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.arrData.count;
if (self.searchBar.isFirstResponder) {
return self.arrFilter.count;
}else if(self.btnIsClear.isSelected){
return self.arrClear.count;
}else{
return self.statementModel.records.count;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
StatementTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"StatementCell" forIndexPath:indexPath];
[cell setUpCellWithArray:self.arrData index:indexPath];
if (self.searchBar.isFirstResponder) {
[cell setUpCellWithArray:self.arrFilter index:indexPath];
}else if(self.btnIsClear.isSelected){
[cell setUpCellWithArray:self.arrClear index:indexPath];
}else{
[cell setUpCellWithArray:self.statementModel.records index:indexPath];
}
return cell;
}
......@@ -164,16 +205,54 @@
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self PushToStoryBoardVCWithIdentifier:@"StatementDetailViewController" isHideTabbar:YES animate:YES];
StatementDetailViewController *detailVC = [self controllerWithIdentifier:@"StatementDetailViewController"];
detailVC.startDate = self.startDate;
detailVC.endDate = self.endDate;
if (self.searchBar.isFirstResponder) {
detailVC.record = self.arrFilter[indexPath.row];
}else if(self.btnIsClear.isSelected){
detailVC.record = self.arrClear[indexPath.row];
}else{
detailVC.record = self.statementModel.records[indexPath.row];
}
[self.navigationController pushViewController:detailVC animated:YES];
}
- (NSMutableArray *)arrData {
if (!_arrData) {
_arrData = [NSMutableArray array];
}
return _arrData;
- (void)textFieldDidEndEditing:(UITextField *)textField {
[self setUpData];
}
#pragma mark - empty state
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
return [UIImage imageNamed:@"no_data"];
}
- (CAAnimation *)imageAnimationForEmptyDataSet:(UIScrollView *)scrollView {
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath: @"transform"];
animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_2, 0.0, 0.0, 1.0)];
animation.duration = 0.25;
animation.cumulative = YES;
animation.repeatCount = MAXFLOAT;
return animation;
}
- (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView {
return [UIColor whiteColor];
}
#pragma mark - lazyloading
- (NSMutableArray *)arrClear {
if (!_arrClear) {
_arrClear = [NSMutableArray array];
}
return _arrClear;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
......
......@@ -10,4 +10,5 @@
@interface StatementDetailCell : UITableViewCell
- (void)setUpCellWithModelArray:(NSArray *)array index:(NSIndexPath *)indexPath;
@end
......@@ -7,7 +7,7 @@
//
#import "StatementDetailCell.h"
#import "StatementDetailItems.h"
@interface StatementDetailCell ()
/** 标题 */
@property (weak, nonatomic) IBOutlet UILabel *labelTitle;
......@@ -20,6 +20,7 @@
@property (weak, nonatomic) IBOutlet UILabel *labelPaidIn;
/** 未缴 */
@property (weak, nonatomic) IBOutlet UILabel *labelUnPaid;
@property (weak, nonatomic) IBOutlet UIImageView *img;
@end
@implementation StatementDetailCell
......@@ -28,6 +29,20 @@
// Initialization code
}
- (void)setUpCellWithModelArray:(NSArray *)array index:(NSIndexPath *)indexPath {
StatementDetailItems *item = array[indexPath.row];
self.labelTitle.text = item.subject;
self.labelDate.text = [NSString stringWithFormat:@"%@~%@",item.beginDate,item.endDate];
self.labelShouldPay.text = [NSString stringWithFormat:@"%.2f",item.amount];
self.labelPaidIn.text = [NSString stringWithFormat:@"[已缴]%.2f",item.paid];
self.labelUnPaid.text = [NSString stringWithFormat:@"[未缴]%.2f",item.unpaid];
if (item.direction < 0) {
self.img.image = [UIImage imageNamed:@"money_reduce"];
}else{
self.img.image = [UIImage imageNamed:@"money_add"];
}
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
......
......@@ -26,8 +26,8 @@
}
- (void)setUpCellWithArray:(NSArray *)array index:(NSIndexPath *)indexPath {
StatementModel *model = array[indexPath.row];
self.labelTitle.text = model.shopName;
StatementRecords *model = array[indexPath.row];
self.labelTitle.text = [NSString stringWithFormat:@"%@ %@",model.shopCode, model.shopName];
self.labelShouldPay.text = [NSString stringWithFormat:@"%.2f",model.amount];
self.labelPaidIn.text = [NSString stringWithFormat:@"[已缴]%.2f",model.paid];
self.labelUnPaid.text = [NSString stringWithFormat:@"[未缴]%.2f",model.unpaid];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment