PurchaseDetailViewController.m 28.9 KB
Newer Older
陈俊俊's avatar
陈俊俊 committed
1 2 3 4 5 6 7 8 9
//
//  PurchaseDetailViewController.m
//  XFFruit
//
//  Created by 陈俊俊 on 15/8/23.
//  Copyright (c) 2015年 Xummer. All rights reserved.
//

#import "PurchaseDetailViewController.h"
陈俊俊's avatar
陈俊俊 committed
10 11
#import "ProductBillViewController.h"
#import "PurchaseBillProduct.h"
12
#import "BottomPurchaseView.h"
Sandy's avatar
Sandy committed
13 14 15
#import "ReceiveProductViewController.h"
#import "TransferPdtDetail.h"
#import "NewReceiveProductViewController.h"
陈俊俊's avatar
陈俊俊 committed
16
//#import "RejectView.h"
陈俊俊's avatar
陈俊俊 committed
17 18 19 20 21 22 23
#define BottomHeight                                50
#define LeftMargin                                  15
#define LeftWidth                                   100
#define LeftHeight                                  30
#define TopMargin                                   15
#define OneWidth                                    (ScreenSize.width - LeftMargin * 2)
#define TwoWidth                                    ((ScreenSize.width - LeftMargin*3)/2)
n22's avatar
n22 committed
24
typedef enum : NSUInteger {
陈俊俊's avatar
陈俊俊 committed
25 26 27 28 29
    CancleTag = 3500,//作废
    EndTag,          //结束
    RejectTag,       //拒绝
    PassTag,         //审核
    SureTag,         //确定
Sandy's avatar
Sandy committed
30 31 32
    SaveTag,    //收货状态:保存
    ReceiveTag,//收货状态:收货
    AbortTag//收货状态:作废
n22's avatar
n22 committed
33 34
} BtnTag;

陈俊俊's avatar
陈俊俊 committed
35
@interface PurchaseDetailViewController ()<UIAlertViewDelegate>
陈俊俊's avatar
陈俊俊 committed
36 37 38
{
    UIScrollView *_scrollView;
    UIView *_purchaseView;
39 40
    //UIView *_bottomView;
    //ProductBillViewController *_pvc;
n22's avatar
n22 committed
41
    NSArray *_leftArr;
陈俊俊's avatar
陈俊俊 committed
42 43
    UIButton *_firstBtn;
    UIButton *_secondBtn;
44
    BottomPurchaseView *_aBottomView;
Sandy's avatar
Sandy committed
45 46 47
    UIView *_recieveBottomView;
    ReceiveProductViewController *_pvc;
    
陈俊俊's avatar
陈俊俊 committed
48 49 50 51 52 53
}
@property (nonatomic,strong)UILabel *billNumberLabel;
@property (nonatomic,strong)UILabel *noticeNumberLabel;
@property (nonatomic,strong)UILabel *createOperNameLabel;
@property (nonatomic,strong)UILabel *checkNameLabel;
@property (nonatomic,strong)UILabel *stateLabel;
n22's avatar
n22 committed
54
@property (nonatomic,strong)UILabel *lastModifyNameLabel;
55
@property (nonatomic, strong) UILabel *purchaserLabel;
n22's avatar
n22 committed
56
@property (nonatomic,strong)UILabel *typeLabel;
陈俊俊's avatar
陈俊俊 committed
57
@property (nonatomic,strong)UILabel *vendorNameLabel;
n22's avatar
n22 committed
58 59 60
@property (nonatomic,strong)UILabel *vendorIsSureLabel;
@property (nonatomic,strong)UILabel *warehouseLabel;
@property (nonatomic,strong)UILabel *otherPriceLabel;
陈俊俊's avatar
陈俊俊 committed
61 62
@property (nonatomic,strong)UILabel *totalPriceLabel;
@property (nonatomic,strong)UILabel *noteLabel;
n22's avatar
n22 committed
63

Sandy's avatar
Sandy committed
64 65 66 67 68
@property (strong, nonatomic) UILabel *labelCreateTime;
@property (strong, nonatomic) UILabel *labelInspector;
@property (strong, nonatomic) UILabel *labelInspectTime;
@property (strong, nonatomic) UILabel *labelReciever;
@property (strong, nonatomic) UILabel *labelRecieveTime;
Sandy's avatar
Sandy committed
69 70
@property (strong, nonatomic) UILabel *labelExpiredDate;
@property (strong, nonatomic) UILabel *labelOutSideNum;
Sandy's avatar
Sandy committed
71
@property (nonatomic,assign)BOOL isNotShowEdit;
陈俊俊's avatar
陈俊俊 committed
72
//@property (nonatomic,strong)RejectView *rejectView;
陈俊俊's avatar
陈俊俊 committed
73 74

@property (nonatomic,strong)NSString *rejectCause;//拒接原因
陈俊俊's avatar
陈俊俊 committed
75 76 77 78 79 80
@end

@implementation PurchaseDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
Sandy's avatar
Sandy committed
81 82 83 84 85 86 87
    [self judgeType];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(editReceiveProduct:) name:KNOTIFICATION_EditReceiveProduct object:nil];
    [self bulidLayout];
    [self getDataFromServer];
}

- (void)judgeType {
Sandy's avatar
Sandy committed
88 89 90
    if ([self.bill.state isEqualToString:PURCHASE_STATE_WAITE_RECIEVE] ||
        [self.bill.state isEqualToString:PURCHASE_STATE_RECEIVED] ||
        self.bill.receive_id != nil) {
Sandy's avatar
Sandy committed
91 92 93 94
        self.type = PurchaseTypeAfterVerify;
    }else{
        self.type = PurchaseTypeBeforeVerify;
    }
陈俊俊's avatar
陈俊俊 committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108
}
- (void)getDataFromServer{
    __weak typeof(self)weakSelf = self;
    void(^succ)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        if (data) {
            NSInteger success = [data[@"success"] integerValue];
            NSString *message  = data[@"message"] ;
            if (success == 1) {
                NSDictionary *dictData = data[@"data"];
                PurchaseBill *bill = [[PurchaseBill alloc]init];
                [bill setValuesForKeysWithDictionary:dictData];
                self.bill = bill;
Sandy's avatar
Sandy committed
109
                [weakSelf judgeType];
110
                [_aBottomView refreshCost:dictData[@"accountDetails"]];
陈俊俊's avatar
陈俊俊 committed
111 112 113 114 115 116 117 118 119 120 121 122 123
                [strongSelf fetchtPurchaseDetail];
            }else{
                [IBTLoadingView showTips:message];
            }
        }else{
            [IBTLoadingView showTips:@"     无记录     "];
        }
    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
    };
    [IBTLoadingView showProgressLabel:@"正在加载..."];
陈俊俊's avatar
陈俊俊 committed
124
    [[ICRHTTPController sharedController] getPurchaseResultWithPurchaseUuid:self.bill.uuid success:succ failure:fail];
陈俊俊's avatar
陈俊俊 committed
125 126 127 128 129
}


#pragma mark - 视图初始化
- (void)bulidLayout{
Sandy's avatar
Sandy committed
130 131
    [_scrollView removeAllSubViews];
    
陈俊俊's avatar
陈俊俊 committed
132 133 134
    _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, ScreenSize.height - 64 - BottomHeight)];
    _scrollView.showsHorizontalScrollIndicator  = NO;
    _scrollView.showsVerticalScrollIndicator = NO;
陈俊俊's avatar
陈俊俊 committed
135
    _scrollView.backgroundColor = XXFBgColor;
陈俊俊's avatar
陈俊俊 committed
136
    [self.view addSubview:_scrollView];
Sandy's avatar
Sandy committed
137
    //    [self createBtn];
陈俊俊's avatar
陈俊俊 committed
138
    [self showBtnByPermissions];
n22's avatar
n22 committed
139
    [self createBottomView];
陈俊俊's avatar
陈俊俊 committed
140
    [self createPurchaseView];
陈俊俊's avatar
陈俊俊 committed
141
    
n22's avatar
n22 committed
142 143 144
}

- (void)createBtn{
陈俊俊's avatar
陈俊俊 committed
145
    _firstBtn = [IBTCustomButtom creatButtonWithFrame:CGRectMake(LeftMargin, ScreenSize.height  - 64 - BottomHeight +5, (ScreenSize.width - LeftMargin*3)/2, 40) target:self sel:@selector(btnClick:) tag:0 image:nil title:@"" titleColor: [UIColor whiteColor] isCorner:YES corner:5 bgColor:GXF_SAVE_COLOR];
陈俊俊's avatar
陈俊俊 committed
146
    [self.view addSubview:_firstBtn];
陈俊俊's avatar
陈俊俊 committed
147
    
陈俊俊's avatar
陈俊俊 committed
148 149 150 151
    _secondBtn = [IBTCustomButtom creatButtonWithFrame:CGRectMake(CGRectGetMaxX(_firstBtn.frame)+ LeftMargin, ScreenSize.height  - 64 - BottomHeight +5, (ScreenSize.width - LeftMargin*3)/2, 40) target:self sel:@selector(btnClick:) tag:0 image:nil title:@"" titleColor:[UIColor whiteColor] isCorner:YES corner:5 bgColor:GXF_COMMIT_COLOR];
    [self.view addSubview:_secondBtn];
    [self showBtnByPermissions];
}
陈俊俊's avatar
陈俊俊 committed
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166

- (void)createBtnWithArr:(NSArray *)arr{
    CGFloat btnWidth = (ScreenSize.width - LeftMargin * (arr.count+1))/arr.count;
    for (NSInteger i = 0; i < arr.count; i++) {
        NSInteger btnTag = 0;
        if ([arr[i] isEqualToString:@"拒绝"]) {
            btnTag = RejectTag;
        }else if ([arr[i] isEqualToString:@"审核通过"]) {
            btnTag = PassTag;
        }else if ([arr[i] isEqualToString:@"确认"]) {
            btnTag = SureTag;
        }else if ([arr[i] isEqualToString:@"结束"]) {
            btnTag = EndTag;
        }else if ([arr[i] isEqualToString:@"作废"]) {
            btnTag = CancleTag;
Sandy's avatar
Sandy committed
167 168 169 170
        }else if ([arr[i] isEqualToString:@"保存"]) {
            btnTag = SaveTag;
        }else if ([arr[i] isEqualToString:@"收货"]) {
            btnTag = ReceiveTag;
陈俊俊's avatar
陈俊俊 committed
171 172 173 174 175 176 177
        }
        CGRect btnFrame = CGRectMake(LeftMargin + (LeftMargin + btnWidth)*i,  ScreenSize.height  - 64 - BottomHeight +5, btnWidth, 40);
        UIButton *perBtn = [IBTCustomButtom creatButtonWithFrame:btnFrame target:self sel:@selector(btnClick:) tag:btnTag image:nil title:arr[i] titleColor:[UIColor whiteColor] isCorner:YES corner:5 bgColor:GXF_COMMIT_COLOR];
        [self.view addSubview:perBtn];
    }
}

陈俊俊's avatar
陈俊俊 committed
178 179 180
//根据权限判断按钮显示
- (void)showBtnByPermissions{
    //逻辑判断按钮显示不显示
陈俊俊's avatar
陈俊俊 committed
181 182
    if ([self.bill.state isEqualToString:PURCHASE_STATE_SUBMITTED]) {//状态已提交 未审批
        if([self checkIsPermission:PURCHASE_PERMISSIONS_MANAGEAPPROVE]){
陈俊俊's avatar
陈俊俊 committed
183
            //显示拒绝和审批
陈俊俊's avatar
陈俊俊 committed
184 185 186
            NSArray *arr = @[@"拒绝",@"审核通过"];
            [self createBtnWithArr:arr];
            
陈俊俊's avatar
陈俊俊 committed
187
        }
188
    }else if([self.bill.state isEqualToString:PURCHASE_STATE_SHIPPING]){//状态是发运中即已审批
陈俊俊's avatar
陈俊俊 committed
189
        NSMutableArray *arr = [NSMutableArray array];
190
        if([self checkIsPermission:PURCHASE_PERMISSIONS_VENDORAPPROVE] && (!self.bill.vendorConfirmTime || self.bill.vendorConfirmTime.length < 1)){//供应商审批权
陈俊俊's avatar
陈俊俊 committed
191
            //显示确认按钮
陈俊俊's avatar
陈俊俊 committed
192 193 194
            [arr addObject:@"确认"];
        }
        if ([self checkIsPermission:PURCHASE_PERMISSIONS_FINISH]){//结束权
Sandy's avatar
Sandy committed
195
            //显示结束按钮
陈俊俊's avatar
陈俊俊 committed
196 197 198
            [arr addObject:@"结束"];
        }
        if([self checkIsPermission:PURCHASE_PERMISSIONS_ABORT]){//作废权
Sandy's avatar
Sandy committed
199
            //显示作废按钮
陈俊俊's avatar
陈俊俊 committed
200 201 202 203 204
            [arr addObject:@"作废"];
        }
        [self createBtnWithArr:arr];
        if (arr.count == 0) {
            [self hiddenTwoBtn];
陈俊俊's avatar
陈俊俊 committed
205 206 207 208
        }
    }else if([self.bill.state isEqualToString:PURCHASE_STATE_FINISHED]){//完成
        if ([self checkIsPermission:PURCHASE_PERMISSIONS_ABORT]) {//有作废权的
            //显示作废按钮
陈俊俊's avatar
陈俊俊 committed
209 210
            NSArray *arr = @[@"作废"];
            [self createBtnWithArr:arr];
Sandy's avatar
Sandy committed
211
            
212 213 214 215 216 217 218 219 220
        }else{
            [self hiddenTwoBtn];
        }
    }else if([self.bill.state isEqualToString:PURCHASE_STATE_PROCESSFAIL]){//系统处理失败的
        if ([self checkIsPermission:PURCHASE_PERMISSIONS_ABORT]) {//有作废权的
            //显示作废按钮
            NSArray *arr = @[@"作废"];
            [self createBtnWithArr:arr];
            
陈俊俊's avatar
陈俊俊 committed
221 222
        }else{
            [self hiddenTwoBtn];
陈俊俊's avatar
陈俊俊 committed
223
        }
Sandy's avatar
Sandy committed
224
    }else if ([self.bill.state isEqualToString:PURCHASE_STATE_WAITE_RECIEVE]){
Sandy's avatar
Sandy committed
225 226 227 228 229
        if ([IBTCommon checkIsPermission:RECEIVE_ACTION_RECEIVE]) {
            [self createBtnWithArr:@[@"作废",@"收货"]];
        }else{
            [self hiddenTwoBtn];
        }
Sandy's avatar
Sandy committed
230
    }else if([self.bill.state isEqualToString:PURCHASE_STATE_ABORTED]){//已作废
陈俊俊's avatar
陈俊俊 committed
231
        [self hiddenTwoBtn];
Sandy's avatar
Sandy committed
232 233 234 235 236 237 238 239
    }else if ([self.bill.state isEqualToString:PURCHASE_STATE_RECEIVED]){
        if([self checkIsPermission:PURCHASE_PERMISSIONS_ABORT]){//供应商审批权
            //显示确认按钮
            NSArray *arr = @[@"作废"];
            [self createBtnWithArr:arr];
        }else{
            [self hiddenTwoBtn];
        }
240
    }else{
Sandy's avatar
Sandy committed
241
        [self hiddenTwoBtn];
陈俊俊's avatar
陈俊俊 committed
242 243
    }
}
陈俊俊's avatar
陈俊俊 committed
244 245 246 247 248 249

- (void)hiddenTwoBtn{
    CGRect scrollViewFrame = _scrollView.frame;
    scrollViewFrame.size.height = ScreenSize.height - 64;
    _scrollView.frame = scrollViewFrame;
}
陈俊俊's avatar
陈俊俊 committed
250 251 252 253 254 255 256 257 258 259 260 261 262
//改变按钮的位置
- (void)changeBtnFrame:(UIButton *)btn title:(NSString *)title originX:(CGFloat)originX width:(CGFloat)width{
    CGRect btnFrame = btn.frame;
    btnFrame.origin.x = originX;
    btnFrame.size.width = width;
    btn.frame = btnFrame;
    [btn setTitle:title forState:UIControlStateNormal];
}
- (BOOL)checkIsPermission:(NSString *)permission{
    for (NSString *per in [ICRUserUtil sharedInstance].permissions) {
        if ([per isEqualToString:permission]) {
            return YES;
        }
n22's avatar
n22 committed
263
    }
陈俊俊's avatar
陈俊俊 committed
264
    return YES;
陈俊俊's avatar
陈俊俊 committed
265
}
n22's avatar
n22 committed
266

陈俊俊's avatar
陈俊俊 committed
267
- (void)btnClick:(UIButton *)btn{
陈俊俊's avatar
陈俊俊 committed
268
    CLog(@"%ld",(long)btn.tag);
陈俊俊's avatar
陈俊俊 committed
269 270 271
    switch (btn.tag) {
        case CancleTag:
        {
陈俊俊's avatar
陈俊俊 committed
272
            CLog(@"作废");
陈俊俊's avatar
陈俊俊 committed
273 274 275 276
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请确认作废" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
            alertView.delegate = self;
            alertView.tag = CancleTag;
            [alertView show];
陈俊俊's avatar
陈俊俊 committed
277 278 279 280
        }
            break;
        case EndTag:
        {
陈俊俊's avatar
陈俊俊 committed
281
            CLog(@"结束");
陈俊俊's avatar
陈俊俊 committed
282 283 284 285
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请确认结束" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
            alertView.delegate = self;
            alertView.tag = EndTag;
            [alertView show];
陈俊俊's avatar
陈俊俊 committed
286 287 288 289
        }
            break;
        case RejectTag:
        {
陈俊俊's avatar
陈俊俊 committed
290
            CLog(@"拒绝");
陈俊俊's avatar
陈俊俊 committed
291 292 293 294
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请确认拒绝" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
            alertView.delegate = self;
            alertView.tag = RejectTag;
            [alertView show];
陈俊俊's avatar
陈俊俊 committed
295 296 297 298
        }
            break;
        case PassTag:
        {
陈俊俊's avatar
陈俊俊 committed
299
            CLog(@"审核通过");
陈俊俊's avatar
陈俊俊 committed
300 301 302 303
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请确认通过" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
            alertView.delegate = self;
            alertView.tag = PassTag;
            [alertView show];
陈俊俊's avatar
陈俊俊 committed
304 305 306 307
        }
            break;
        case SureTag:
        {
陈俊俊's avatar
陈俊俊 committed
308 309
            CLog(@"确认");
            [self dealByAction:PURCHASE_ACTION_VENDORCONFIRM];
Sandy's avatar
Sandy committed
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
        }
            break;
        case SaveTag:
        {
//            if ([self checkReceive]) {
//                self.state = RECEIVE_STATE_SAVE;
//                [self getDataFromServer:RECEIVE_STATE_SAVE msg:@"正在保存..."];
//            }
        }
            break;
        case ReceiveTag:{
            if ([self checkReceive]) {
                UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"收货后不能重复收货,请确认是否要收货?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
                alertView.delegate = self;
                alertView.tag = ReceiveTag;
                [alertView show];
            }
        }
            break;
        case AbortTag:
        {
//            CLog(@"作废");
//            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请确认作废" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
//            alertView.delegate = self;
//            alertView.tag = AbortTag;
//            [alertView show];
陈俊俊's avatar
陈俊俊 committed
336 337 338 339 340
        }
            break;
        default:
            break;
    }
n22's avatar
n22 committed
341
}
陈俊俊's avatar
陈俊俊 committed
342 343 344 345 346 347 348 349
- (void)dealByAction:(NSString *)action{
    //保存
    void(^succ)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        if (data) {
            NSInteger success = [data[@"success"] integerValue];
            NSString *message = data[@"message"];
            if (success == 1) {
Sandy's avatar
Sandy committed
350 351 352 353 354 355 356 357
                //是wms且非产品中心仓,审核时同时收货
                if (self.isWms && self.isCenter == NO && [action isEqualToString:PURCHASE_ACTION_APPROVE]) {
                    [self getDataFromServer];
                }else{
                    
                    [ICRUserUtil sharedInstance].needFresh = YES;
                    [self PopViewControllerAnimated:YES];
                }
陈俊俊's avatar
陈俊俊 committed
358 359 360 361 362 363 364 365 366 367 368 369 370 371
            }else{
                [IBTLoadingView showTips:message];
            }
        }else{
            [IBTLoadingView showTips:@"操作异常"];
        }
    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
    };
    [IBTLoadingView showProgressLabel:@"正在加载..."];
    [[ICRHTTPController sharedController]dealByActionWithPurchaseUuid:self.bill.uuid action:action remark:[IBTCommon checkString:self.rejectCause] version:self.bill.version success:succ failure:fail];
}
n22's avatar
n22 committed
372

Sandy's avatar
Sandy committed
373 374 375 376 377 378 379 380 381 382 383 384
- (BOOL)checkReceive{
    for (NSString *isEdit in _pvc.defaultState) {
        if ([isEdit isEqualToString:@"NO"]) {
            ShowMessage(@"有商品行没有编辑过收货数量,请先编辑再收货");
            return NO;
        }
    }
    
    if (_pvc.productArr.count == 0) {
        ShowMessage(@"商品不能为空");
        return NO;
    }
陈俊俊's avatar
陈俊俊 committed
385
    
Sandy's avatar
Sandy committed
386
    return YES;
n22's avatar
n22 committed
387 388
}

Sandy's avatar
Sandy committed
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
- (void)createBottomView{
    if (self.type == PurchaseTypeAfterVerify) {
        _recieveBottomView= [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_purchaseView.frame) + TopMargin, ScreenSize.width,300)];
        _recieveBottomView.backgroundColor = [UIColor redColor];
        [_scrollView addSubview:_recieveBottomView];
        
        _pvc = [[ReceiveProductViewController alloc]init];
        _pvc.viewFrame = _recieveBottomView.bounds;
        _pvc.isHiddenAdd = YES;
        _pvc.isHiddenEdit = self.isNotShowEdit;
        [_recieveBottomView addSubview:_pvc.view];
    }else{
        _aBottomView = [[BottomPurchaseView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_purchaseView.frame) + TopMargin, ScreenSize.width,300) withHidden:YES];
        _aBottomView.backgroundColor = [UIColor whiteColor];
        [_scrollView addSubview:_aBottomView];
    }
}
陈俊俊's avatar
陈俊俊 committed
406

Sandy's avatar
Sandy committed
407
- (void)createPurchaseView{
Sandy's avatar
Sandy committed
408
    _leftArr = @[@"单号:",@"采购通知单:",@"创建人:",@"创建时间:",@"审核人:",@"审核时间:",@"收货人:",@"收货时间:",@"有效期:",@"采购员:",@"状态:",@"类型:",@"供应商:",@"供应商确认:",@"收货仓库:",@"其他费用:",@"总金额:",@"外部单据号:",@"备注:"];
Sandy's avatar
Sandy committed
409
    
n22's avatar
n22 committed
410
    _purchaseView= [[UIView alloc]initWithFrame:CGRectMake(0, TopMargin, ScreenSize.width, LeftHeight*_leftArr.count +LeftMargin)];
陈俊俊's avatar
陈俊俊 committed
411 412 413
    _purchaseView.backgroundColor = [UIColor whiteColor];
    [_scrollView addSubview:_purchaseView];
    
Sandy's avatar
Sandy committed
414 415
    for (NSString *title in _leftArr) {
        NSInteger i = [_leftArr indexOfObject:title];
陈俊俊's avatar
陈俊俊 committed
416
        UILabel *leftLabel = [[UILabel alloc]initWithFrame:CGRectMake(LeftMargin, 10 + LeftHeight *i, LeftWidth, LeftHeight)];
陈俊俊's avatar
陈俊俊 committed
417
        leftLabel.font = GXF_SEVENTEENTH_SIZE;
n22's avatar
n22 committed
418
        leftLabel.text = _leftArr[i];
陈俊俊's avatar
陈俊俊 committed
419
        leftLabel.textColor = GXF_DETAIL_COLOR;
陈俊俊's avatar
陈俊俊 committed
420 421 422
        [_purchaseView addSubview:leftLabel];
        
        UILabel *rightLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(leftLabel.frame), 10 + LeftHeight *i, _purchaseView.frame.size.width - LeftMargin - LeftWidth, LeftHeight)];
陈俊俊's avatar
陈俊俊 committed
423 424
        rightLabel.font = GXF_SEVENTEENTH_SIZE;
        rightLabel.textColor = GXF_DETAIL_COLOR;
Sandy's avatar
Sandy committed
425
        if ([title isEqualToString:@"单号:"]) {
陈俊俊's avatar
陈俊俊 committed
426
            self.billNumberLabel = rightLabel;
Sandy's avatar
Sandy committed
427
        }else if ([title isEqualToString:@"采购通知单:"]){
陈俊俊's avatar
陈俊俊 committed
428
            self.noticeNumberLabel = rightLabel;
Sandy's avatar
Sandy committed
429
        }else if ([title isEqualToString:@"创建人:"]){
陈俊俊's avatar
陈俊俊 committed
430
            self.createOperNameLabel = rightLabel;
Sandy's avatar
Sandy committed
431
        }else if ([title isEqualToString:@"最后修改人:"]){
432
            self.lastModifyNameLabel = rightLabel;
Sandy's avatar
Sandy committed
433
        }else if ([title isEqualToString:@"采购员:"]){
434
            self.purchaserLabel = rightLabel;
Sandy's avatar
Sandy committed
435
        }else if ([title isEqualToString:@"状态:"]){
436
            self.stateLabel = rightLabel;
Sandy's avatar
Sandy committed
437
        }else if ([title isEqualToString:@"类型:"]){
438
            self.typeLabel = rightLabel;
Sandy's avatar
Sandy committed
439
        }else if ([title isEqualToString:@"供应商:"]){
440
            self.vendorNameLabel = rightLabel;
Sandy's avatar
Sandy committed
441
        }else if ([title isEqualToString:@"供应商确认:"]){
442
            self.vendorIsSureLabel = rightLabel;
Sandy's avatar
Sandy committed
443
        }else if ([title isEqualToString:@"收货仓库:"]){
陈俊俊's avatar
陈俊俊 committed
444
            self.warehouseLabel = rightLabel;
Sandy's avatar
Sandy committed
445
        }else if ([title isEqualToString:@"其他费用:"]){
n22's avatar
n22 committed
446
            self.otherPriceLabel = rightLabel;
Sandy's avatar
Sandy committed
447
        }else if ([title isEqualToString:@"总金额:"]){
陈俊俊's avatar
陈俊俊 committed
448
            self.totalPriceLabel = rightLabel;
Sandy's avatar
Sandy committed
449
        }else if ([title isEqualToString:@"备注:"]){
陈俊俊's avatar
陈俊俊 committed
450 451
            rightLabel.numberOfLines = 0;
            self.noteLabel = rightLabel;
Sandy's avatar
Sandy committed
452 453 454 455 456 457 458 459 460 461
        }else if ([title isEqualToString:@"创建时间:"]){
            self.labelCreateTime = rightLabel;
        }else if ([title isEqualToString:@"审核人:"]){
            self.labelInspector = rightLabel;
        }else if ([title isEqualToString:@"审核时间:"]){
            self.labelInspectTime = rightLabel;
        }else if ([title isEqualToString:@"收货人:"]){
            self.labelReciever = rightLabel;
        }else if ([title isEqualToString:@"收货时间:"]){
            self.labelRecieveTime = rightLabel;
Sandy's avatar
Sandy committed
462 463 464 465
        }else if ([title isEqualToString:@"有效期:"]){
            self.labelExpiredDate = rightLabel;
        }else if ([title isEqualToString:@"外部单据号:"]){
            self.labelOutSideNum = rightLabel;
陈俊俊's avatar
陈俊俊 committed
466
        }
Sandy's avatar
Sandy committed
467
        
陈俊俊's avatar
陈俊俊 committed
468 469 470 471 472 473
        [_purchaseView addSubview:rightLabel];
    }
}

- (void)fetchtPurchaseDetail{
    self.billNumberLabel.text = [IBTCommon checkString:self.bill.billNumber];
n22's avatar
n22 committed
474
    if ([self.bill.state isEqualToString:PURCHASE_STATE_INITIAL]) {
陈俊俊's avatar
陈俊俊 committed
475 476
        self.stateLabel.textColor = [UIColor redColor];
        self.stateLabel.text = @"未提交";
n22's avatar
n22 committed
477
    }else if ([self.bill.state isEqualToString:PURCHASE_STATE_SUBMITTED]) {
陈俊俊's avatar
陈俊俊 committed
478
        self.stateLabel.textColor = [UIColor greenColor];
陈俊俊's avatar
陈俊俊 committed
479
        self.stateLabel.text = @"未审批";
n22's avatar
n22 committed
480
    }else if ([self.bill.state isEqualToString:PURCHASE_STATE_REJECTED]) {
陈俊俊's avatar
陈俊俊 committed
481 482
        self.stateLabel.textColor = [UIColor grayColor];
        self.stateLabel.text = @"已拒绝";
n22's avatar
n22 committed
483
    }else if ([self.bill.state isEqualToString:PURCHASE_STATE_SHIPPING]) {
陈俊俊's avatar
陈俊俊 committed
484 485
        self.stateLabel.textColor = [UIColor grayColor];
        self.stateLabel.text = @"发运中";
陈俊俊's avatar
陈俊俊 committed
486
    }else if ([self.bill.state isEqualToString:PURCHASE_STATE_ABORTED]) {
487 488
        self.stateLabel.textColor = [UIColor grayColor];
        self.stateLabel.text = @"已作废";
n22's avatar
n22 committed
489
    }else if ([self.bill.state isEqualToString:PURCHASE_STATE_FINISHED]) {
陈俊俊's avatar
陈俊俊 committed
490 491
        self.stateLabel.textColor = [UIColor blackColor];
        self.stateLabel.text = @"已完成";
492
    }else if ([self.bill.state isEqualToString:PURCHASE_STATE_PROCESS]) {
陈俊俊's avatar
陈俊俊 committed
493
        self.stateLabel.textColor = [UIColor greenColor];
494 495 496 497
        self.stateLabel.text = @"提交系统处理";
    }else if ([self.bill.state isEqualToString:PURCHASE_STATE_PROCESSFAIL]) {
        self.stateLabel.textColor = [UIColor blackColor];
        self.stateLabel.text = @"系统处理失败";
Sandy's avatar
Sandy committed
498 499 500 501 502 503
    }else if ([self.bill.state isEqualToString:PURCHASE_STATE_WAITE_RECIEVE]) {
        self.stateLabel.textColor = [UIColor blackColor];
        self.stateLabel.text = @"待收货";
    }else if ([self.bill.state isEqualToString:PURCHASE_STATE_RECEIVED]) {
        self.stateLabel.textColor = [UIColor blackColor];
        self.stateLabel.text = @"已收货";
陈俊俊's avatar
陈俊俊 committed
504
    }
Sandy's avatar
Sandy committed
505 506
    
    _pvc.isHiddenEdit = ![self.bill.state isEqualToString:PURCHASE_STATE_WAITE_RECIEVE];
陈俊俊's avatar
陈俊俊 committed
507
    self.noticeNumberLabel.text = (self.bill.noticeNumber.length == 0) ? @"无":(self.bill.noticeNumber);
陈俊俊's avatar
陈俊俊 committed
508 509 510
    self.createOperNameLabel.text = [IBTCommon checkString:self.bill.create_operName];
    self.checkNameLabel.text = [IBTCommon checkString:self.bill.vendor_name];
    self.vendorNameLabel.text = [IBTCommon checkString:self.bill.vendor_name];
n22's avatar
n22 committed
511
    self.totalPriceLabel.text = [IBTCommon checkString:[self.bill.total stringValue]];
陈俊俊's avatar
陈俊俊 committed
512
    self.noteLabel.text = [NSString stringWithFormat:@"%@",self.bill.remark?self.bill.remark:@"无"];
陈俊俊's avatar
陈俊俊 committed
513 514 515
    self.lastModifyNameLabel.text = [IBTCommon checkString:self.bill.lastModify_operName];
    NSString *type = [self.bill.type isEqualToString:GXF_Critical] ? @"紧急" : @"普通";
    self.typeLabel.text = type;
516
    self.purchaserLabel.text = [NSString stringWithFormat:@"%@[%@]",self.bill.purchaserName, self.bill.purchaserCode];
517
    self.vendorIsSureLabel.text = (self.bill.vendorConfirmTime.length > 0 && self.bill.vendorConfirmTime)? @"是":@"否";
陈俊俊's avatar
陈俊俊 committed
518 519
    self.warehouseLabel.text = [IBTCommon checkString:self.bill.receiveWrh_name];
    self.otherPriceLabel.text = [self.bill.charge stringValue];
Sandy's avatar
Sandy committed
520 521 522
    self.labelCreateTime.text = [IBTCommon checkString:self.bill.create_time];
    self.labelInspector.text = [IBTCommon checkString:self.bill.approv_operName];
    self.labelInspectTime.text = [IBTCommon checkString:self.bill.approv_time];
Sandy's avatar
Sandy committed
523 524
    self.labelExpiredDate.text = [IBTCommon checkString:self.bill.expiredDate];
    self.labelOutSideNum.text = [IBTCommon checkString:self.bill.outSideBillNumber];
陈俊俊's avatar
陈俊俊 committed
525
    NSMutableArray *productArr = [NSMutableArray array];
Sandy's avatar
Sandy committed
526 527 528 529 530 531 532 533
    
    if (self.type == PurchaseTypeAfterVerify) {
        for (NSDictionary *billDict in self.bill.products) {
            TransferPdtDetail *billProbuct = [TransferPdtDetail new];
            [billProbuct setValuesForKeysWithDictionary:billDict];
            PurchaseBillProduct *p = [PurchaseBillProduct new];
            [p setValuesForKeysWithDictionary:billDict];
            billProbuct.purchasePdt = p;
Sandy's avatar
Sandy committed
534 535 536 537 538 539
            
             if (self.isCenter) {
                [billProbuct z_setRctQty:p.qty.floatValue];
            }else if (self.isWms){
                [billProbuct z_setRctQty:0];
            }
Sandy's avatar
Sandy committed
540 541 542 543
            [productArr addObject:billProbuct];
        }
        _pvc.productArr = productArr;
        [_pvc.tableView reloadData];
Sandy's avatar
Sandy committed
544 545 546 547 548
        
        if (self.isWms && self.isCenter == NO) {
            [self httpRecieve];
        }
        
Sandy's avatar
Sandy committed
549 550 551 552 553 554 555 556 557
    }else{
        
        for (NSDictionary *billDict in self.bill.products) {
            PurchaseBillProduct *billProbuct = [PurchaseBillProduct new];
            [billProbuct setValuesForKeysWithDictionary:billDict];
            [productArr addObject:billProbuct];
        }
        _aBottomView.productVC.productArr = productArr;
        [_aBottomView.productVC.tableView reloadData];
陈俊俊's avatar
陈俊俊 committed
558
    }
n22's avatar
n22 committed
559
    
Sandy's avatar
Sandy committed
560 561 562
    
    
    
陈俊俊's avatar
陈俊俊 committed
563 564 565 566 567 568 569 570 571 572 573
    [self setNoteHeight];
}

- (void)setNoteHeight
{
    CGFloat height =  [self.noteLabel calculateHeight];
    
    CGRect noteFrame = self.noteLabel.frame;
    noteFrame.size.height = height;
    self.noteLabel.frame = noteFrame;
    
574
    CGFloat totalHeight = height + LeftHeight*_leftArr.count + LeftMargin;
陈俊俊's avatar
陈俊俊 committed
575 576 577 578
    CGRect purchaseFrame = _purchaseView.frame;
    purchaseFrame.size.height = totalHeight;
    _purchaseView.frame = purchaseFrame;
    
Sandy's avatar
Sandy committed
579 580 581 582 583 584 585 586 587 588 589 590
    if (self.type == PurchaseTypeAfterVerify) {
        CGRect bottomFrame = _recieveBottomView.frame;
        bottomFrame.origin.y = CGRectGetMaxY(_purchaseView.frame) + TopMargin;
        _recieveBottomView.backgroundColor = [UIColor redColor];
        _recieveBottomView.frame = bottomFrame;
        _scrollView.contentSize = CGSizeMake(ScreenSize.width, totalHeight + CGRectGetHeight(_recieveBottomView.frame) + TopMargin*2 + 100);
    }else{
        CGRect bottomFrame = _aBottomView.frame;
        bottomFrame.origin.y = CGRectGetMaxY(_purchaseView.frame) + TopMargin;
        _aBottomView.frame = bottomFrame;
        _scrollView.contentSize = CGSizeMake(ScreenSize.width, totalHeight + CGRectGetHeight(_aBottomView.frame) + TopMargin*2);
    }
陈俊俊's avatar
陈俊俊 committed
591 592 593
    
}

陈俊俊's avatar
陈俊俊 committed
594 595 596 597 598 599 600 601 602
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (alertView.tag == CancleTag) {
        if (buttonIndex == 1) {
            [self dealByAction:PURCHASE_ACTION_ABORT];//作废
        }
    }else if (alertView.tag == EndTag){
        if (buttonIndex == 1) {
            [self dealByAction:PURCHASE_ACTION_FINISH];//结束
        }
陈俊俊's avatar
陈俊俊 committed
603 604 605 606 607 608 609 610
    }else if(alertView.tag == RejectTag){
        if (buttonIndex == 1) {
            [self dealByAction:PURCHASE_ACTION_REJECT];
        }
    }else if(alertView.tag == PassTag){
        if (buttonIndex == 1) {
            [self dealByAction:PURCHASE_ACTION_APPROVE];
        }
Sandy's avatar
Sandy committed
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
    }else if (alertView.tag == AbortTag) {
        if (buttonIndex == 1) {
            [self dealByAction:TRANSFER_STATE_ABORTED];//作废
        }
    }else if(alertView.tag == ReceiveTag){
        if (buttonIndex == 1) {
//            //提交
//            self.state = RECEIVE_STATE_RECEIVE;
//            [self getDataFromServer:RECEIVE_STATE_RECEIVE msg:@"收货中..."];
            [self httpRecieve];
        }
    }
}


- (void)httpRecieve{
Sandy's avatar
Sandy committed
627 628 629 630
    NSString *receiveTime = [[NSDate date] httpParameterString];
    self.bill.receive_time = receiveTime;
    self.bill.receive_id = [ICRUserUtil sharedInstance].userId;
    self.bill.receive_operName = [ICRUserUtil sharedInstance].userName;
Sandy's avatar
Sandy committed
631 632 633 634 635 636 637 638 639
    
    NSMutableDictionary *param = [self.bill dictForCommit].mutableCopy;
    NSMutableArray *arrProduct = [NSMutableArray array];
    for (TransferPdtDetail *pdt in _pvc.productArr) {
        PurchaseBillProduct *pPdt = [pdt changeToPurchasePdt];
        NSDictionary *dict = [pPdt dictForCommit];
        [arrProduct addObject:dict];
    }
    
Sandy's avatar
Sandy committed
640
    [param setObject:arrProduct forKey:@"products"];
Sandy's avatar
Sandy committed
641 642 643 644 645
    
    
    
    [param setObject:self.bill.accountDetails forKey:@"accountDetails"];
    
Sandy's avatar
Sandy committed
646
    IBTLoadingView *hud = [IBTLoadingView showHUDAddedTo:self.view animated:YES];
Sandy's avatar
Sandy committed
647
    __weak UIViewController *weakSelf = self;
Sandy's avatar
Sandy committed
648 649
    [HTTP recievePurchase:param success:^(id succ) {
        [hud hide:YES];
Sandy's avatar
Sandy committed
650
        if ([succ[@"success"] boolValue]) {
Sandy's avatar
Sandy committed
651
            [ICRUserUtil sharedInstance].needFresh = YES;
Sandy's avatar
Sandy committed
652 653 654 655
            [IBTLoadingView showTips:@"   收货成功!   "];
            [weakSelf.navigationController popViewControllerAnimated:YES];
        }
    } failure:^(id fail) {
Sandy's avatar
Sandy committed
656
        [IBTLoadingView showTips:fail];
Sandy's avatar
Sandy committed
657 658 659 660 661 662 663 664 665 666 667 668 669
    }];
    
}


- (void)editReceiveProduct:(NSNotification *)fination{
    NewReceiveProductViewController *nvc = [NewReceiveProductViewController new];
    NSInteger indexTag = [[[fination userInfo] objectForKey:@"indexPath"] integerValue];
    TransferPdtDetail *transferPdtDetail = [[fination userInfo] objectForKey:@"transferPdtDetail"];
    if (transferPdtDetail) {
        nvc.navTitle = @"商品明细";
        nvc.indexTag = indexTag;
        nvc.noticeProduct = transferPdtDetail;
陈俊俊's avatar
陈俊俊 committed
670
    }
Sandy's avatar
Sandy committed
671 672 673 674 675 676 677 678
    nvc.editReceiveProduct = ^(TransferPdtDetail *transferPdtDetail,NSInteger indexTag){
        if (transferPdtDetail) {
            [_pvc.productArr replaceObjectAtIndex:indexTag withObject:transferPdtDetail];
            [_pvc.defaultState replaceObjectAtIndex:indexTag withObject:@"YES"];
            [_pvc.tableView reloadData];
        }
    };
    [self PushViewController:nvc animated:YES];
陈俊俊's avatar
陈俊俊 committed
679
}
Sandy's avatar
Sandy committed
680 681


陈俊俊's avatar
陈俊俊 committed
682 683 684 685 686 687
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
Sandy's avatar
Sandy committed
688 689 690 691 692 693 694 695
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */
陈俊俊's avatar
陈俊俊 committed
696 697

@end