PurchaseDetailViewController.m 31.2 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
    SaveTag,    //收货状态:保存
    ReceiveTag,//收货状态:收货
n22's avatar
n22 committed
32 33
} BtnTag;

陈俊俊's avatar
陈俊俊 committed
34
@interface PurchaseDetailViewController ()<UIAlertViewDelegate>
陈俊俊's avatar
陈俊俊 committed
35 36 37
{
    UIScrollView *_scrollView;
    UIView *_purchaseView;
38 39
    //UIView *_bottomView;
    //ProductBillViewController *_pvc;
n22's avatar
n22 committed
40
    NSArray *_leftArr;
陈俊俊's avatar
陈俊俊 committed
41 42
    UIButton *_firstBtn;
    UIButton *_secondBtn;
43
    BottomPurchaseView *_aBottomView;
Sandy's avatar
Sandy committed
44 45 46
    UIView *_recieveBottomView;
    ReceiveProductViewController *_pvc;
    
陈俊俊's avatar
陈俊俊 committed
47 48 49 50 51 52
}
@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
53
@property (nonatomic,strong)UILabel *lastModifyNameLabel;
54
@property (nonatomic, strong) UILabel *purchaserLabel;
n22's avatar
n22 committed
55
@property (nonatomic,strong)UILabel *typeLabel;
陈俊俊's avatar
陈俊俊 committed
56
@property (nonatomic,strong)UILabel *vendorNameLabel;
n22's avatar
n22 committed
57 58 59
@property (nonatomic,strong)UILabel *vendorIsSureLabel;
@property (nonatomic,strong)UILabel *warehouseLabel;
@property (nonatomic,strong)UILabel *otherPriceLabel;
陈俊俊's avatar
陈俊俊 committed
60 61
@property (nonatomic,strong)UILabel *totalPriceLabel;
@property (nonatomic,strong)UILabel *noteLabel;
62 63 64
/**
 *  创建时间
 */
Sandy's avatar
Sandy committed
65
@property (strong, nonatomic) UILabel *labelCreateTime;
66 67 68
/**
 *  审核人
 */
Sandy's avatar
Sandy committed
69
@property (strong, nonatomic) UILabel *labelInspector;
70 71 72
/**
 *  审核时间
 */
Sandy's avatar
Sandy committed
73
@property (strong, nonatomic) UILabel *labelInspectTime;
74 75 76
/**
 *  收货人
 */
Sandy's avatar
Sandy committed
77
@property (strong, nonatomic) UILabel *labelReciever;
78 79 80
/**
 *  收货时间
 */
Sandy's avatar
Sandy committed
81
@property (strong, nonatomic) UILabel *labelRecieveTime;
82 83 84
/**
 *  有效期
 */
Sandy's avatar
Sandy committed
85
@property (strong, nonatomic) UILabel *labelExpiredDate;
86 87 88
/**
 *  外部单据号
 */
Sandy's avatar
Sandy committed
89
@property (strong, nonatomic) UILabel *labelOutSideNum;
陈俊俊's avatar
陈俊俊 committed
90 91

@property (nonatomic,strong)NSString *rejectCause;//拒接原因
陈俊俊's avatar
陈俊俊 committed
92 93 94 95 96 97
@end

@implementation PurchaseDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
Sandy's avatar
Sandy committed
98 99 100 101 102
    [self judgeType];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(editReceiveProduct:) name:KNOTIFICATION_EditReceiveProduct object:nil];
    [self bulidLayout];
    [self getDataFromServer];
}
Sandy's avatar
Sandy committed
103 104 105
- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
Sandy's avatar
Sandy committed
106
- (void)judgeType {
Sandy's avatar
Sandy committed
107 108 109
    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
110 111 112 113
        self.type = PurchaseTypeAfterVerify;
    }else{
        self.type = PurchaseTypeBeforeVerify;
    }
陈俊俊's avatar
陈俊俊 committed
114 115 116 117 118 119 120 121 122 123 124 125 126 127
}
- (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
128
                [weakSelf judgeType];
129
                [_aBottomView refreshCost:dictData[@"accountDetails"]];
陈俊俊's avatar
陈俊俊 committed
130 131 132 133 134 135 136 137 138 139 140 141 142
                [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
143
    [[ICRHTTPController sharedController] getPurchaseResultWithPurchaseUuid:self.bill.uuid success:succ failure:fail];
陈俊俊's avatar
陈俊俊 committed
144 145 146 147 148
}


#pragma mark - 视图初始化
- (void)bulidLayout{
Sandy's avatar
Sandy committed
149 150
    [_scrollView removeAllSubViews];
    
陈俊俊's avatar
陈俊俊 committed
151 152 153
    _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, ScreenSize.height - 64 - BottomHeight)];
    _scrollView.showsHorizontalScrollIndicator  = NO;
    _scrollView.showsVerticalScrollIndicator = NO;
陈俊俊's avatar
陈俊俊 committed
154
    _scrollView.backgroundColor = XXFBgColor;
陈俊俊's avatar
陈俊俊 committed
155
    [self.view addSubview:_scrollView];
Sandy's avatar
Sandy committed
156
    //    [self createBtn];
陈俊俊's avatar
陈俊俊 committed
157
    [self showBtnByPermissions];
n22's avatar
n22 committed
158
    [self createBottomView];
陈俊俊's avatar
陈俊俊 committed
159
    [self createPurchaseView];
陈俊俊's avatar
陈俊俊 committed
160
    
n22's avatar
n22 committed
161 162 163
}

- (void)createBtn{
陈俊俊's avatar
陈俊俊 committed
164
    _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
165
    [self.view addSubview:_firstBtn];
陈俊俊's avatar
陈俊俊 committed
166
    
陈俊俊's avatar
陈俊俊 committed
167 168 169 170
    _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
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185

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

- (void)hiddenTwoBtn{
    CGRect scrollViewFrame = _scrollView.frame;
    scrollViewFrame.size.height = ScreenSize.height - 64;
    _scrollView.frame = scrollViewFrame;
}
陈俊俊's avatar
陈俊俊 committed
269 270 271 272 273 274 275 276 277 278 279 280 281
//改变按钮的位置
- (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
282
    }
陈俊俊's avatar
陈俊俊 committed
283
    return YES;
陈俊俊's avatar
陈俊俊 committed
284
}
n22's avatar
n22 committed
285

陈俊俊's avatar
陈俊俊 committed
286
- (void)btnClick:(UIButton *)btn{
陈俊俊's avatar
陈俊俊 committed
287
    CLog(@"%ld",(long)btn.tag);
陈俊俊's avatar
陈俊俊 committed
288 289 290
    switch (btn.tag) {
        case CancleTag:
        {
陈俊俊's avatar
陈俊俊 committed
291
            CLog(@"作废");
陈俊俊's avatar
陈俊俊 committed
292 293 294 295
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请确认作废" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
            alertView.delegate = self;
            alertView.tag = CancleTag;
            [alertView show];
陈俊俊's avatar
陈俊俊 committed
296 297 298 299
        }
            break;
        case EndTag:
        {
陈俊俊's avatar
陈俊俊 committed
300
            CLog(@"结束");
陈俊俊's avatar
陈俊俊 committed
301 302 303 304
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请确认结束" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
            alertView.delegate = self;
            alertView.tag = EndTag;
            [alertView show];
陈俊俊's avatar
陈俊俊 committed
305 306 307 308
        }
            break;
        case RejectTag:
        {
陈俊俊's avatar
陈俊俊 committed
309
            CLog(@"拒绝");
陈俊俊's avatar
陈俊俊 committed
310 311 312 313
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请确认拒绝" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
            alertView.delegate = self;
            alertView.tag = RejectTag;
            [alertView show];
陈俊俊's avatar
陈俊俊 committed
314 315 316 317
        }
            break;
        case PassTag:
        {
陈俊俊's avatar
陈俊俊 committed
318
            CLog(@"审核通过");
陈俊俊's avatar
陈俊俊 committed
319 320 321 322
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请确认通过" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
            alertView.delegate = self;
            alertView.tag = PassTag;
            [alertView show];
陈俊俊's avatar
陈俊俊 committed
323 324 325 326
        }
            break;
        case SureTag:
        {
陈俊俊's avatar
陈俊俊 committed
327 328
            CLog(@"确认");
            [self dealByAction:PURCHASE_ACTION_VENDORCONFIRM];
Sandy's avatar
Sandy committed
329 330 331 332
        }
            break;
        case SaveTag:
        {
333 334 335
            if ([self checkReceive]) {
                [self httpSave];
            }
Sandy's avatar
Sandy committed
336 337 338 339 340 341 342 343 344
        }
            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];
            }
陈俊俊's avatar
陈俊俊 committed
345 346 347 348 349
        }
            break;
        default:
            break;
    }
n22's avatar
n22 committed
350
}
陈俊俊's avatar
陈俊俊 committed
351 352 353 354 355 356 357 358
- (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
359
                //是wms且非产品中心仓,审核时同时收货
Sandy's avatar
Sandy committed
360 361 362 363
//                if (self.isWms && self.isCenter == NO && [action isEqualToString:PURCHASE_ACTION_APPROVE]) {
//                    [self getDataFromServer];
//                }else{
                
Sandy's avatar
Sandy committed
364 365
                    [ICRUserUtil sharedInstance].needFresh = YES;
                    [self PopViewControllerAnimated:YES];
Sandy's avatar
Sandy committed
366
//                }
陈俊俊's avatar
陈俊俊 committed
367 368 369 370 371 372 373 374 375 376 377 378 379 380
            }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
381

Sandy's avatar
Sandy committed
382 383 384 385 386 387 388 389 390 391 392 393
- (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
394
    
Sandy's avatar
Sandy committed
395
    return YES;
n22's avatar
n22 committed
396 397
}

Sandy's avatar
Sandy committed
398
- (void)createBottomView{
Sandy's avatar
Sandy committed
399 400 401 402
    _aBottomView = [[BottomPurchaseView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_purchaseView.frame) + TopMargin, ScreenSize.width,300) withHidden:YES];
    _aBottomView.backgroundColor = [UIColor whiteColor];
    [_scrollView addSubview:_aBottomView];
    
Sandy's avatar
Sandy committed
403 404 405 406 407 408 409 410 411 412
    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;
        [_recieveBottomView addSubview:_pvc.view];
    }
Sandy's avatar
Sandy committed
413 414 415 416 417 418
    
    
    CGRect frame = _aBottomView.productVC.view.frame;
    _recieveBottomView.frame = frame;
    
    [_aBottomView.productVC.view addSubview:_recieveBottomView];
Sandy's avatar
Sandy committed
419
}
陈俊俊's avatar
陈俊俊 committed
420

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

- (void)fetchtPurchaseDetail{
    self.billNumberLabel.text = [IBTCommon checkString:self.bill.billNumber];
n22's avatar
n22 committed
488
    if ([self.bill.state isEqualToString:PURCHASE_STATE_INITIAL]) {
陈俊俊's avatar
陈俊俊 committed
489 490
        self.stateLabel.textColor = [UIColor redColor];
        self.stateLabel.text = @"未提交";
n22's avatar
n22 committed
491
    }else if ([self.bill.state isEqualToString:PURCHASE_STATE_SUBMITTED]) {
陈俊俊's avatar
陈俊俊 committed
492
        self.stateLabel.textColor = [UIColor greenColor];
陈俊俊's avatar
陈俊俊 committed
493
        self.stateLabel.text = @"未审批";
n22's avatar
n22 committed
494
    }else if ([self.bill.state isEqualToString:PURCHASE_STATE_REJECTED]) {
陈俊俊's avatar
陈俊俊 committed
495 496
        self.stateLabel.textColor = [UIColor grayColor];
        self.stateLabel.text = @"已拒绝";
n22's avatar
n22 committed
497
    }else if ([self.bill.state isEqualToString:PURCHASE_STATE_SHIPPING]) {
陈俊俊's avatar
陈俊俊 committed
498 499
        self.stateLabel.textColor = [UIColor grayColor];
        self.stateLabel.text = @"发运中";
陈俊俊's avatar
陈俊俊 committed
500
    }else if ([self.bill.state isEqualToString:PURCHASE_STATE_ABORTED]) {
501 502
        self.stateLabel.textColor = [UIColor grayColor];
        self.stateLabel.text = @"已作废";
n22's avatar
n22 committed
503
    }else if ([self.bill.state isEqualToString:PURCHASE_STATE_FINISHED]) {
陈俊俊's avatar
陈俊俊 committed
504 505
        self.stateLabel.textColor = [UIColor blackColor];
        self.stateLabel.text = @"已完成";
506
    }else if ([self.bill.state isEqualToString:PURCHASE_STATE_PROCESS]) {
陈俊俊's avatar
陈俊俊 committed
507
        self.stateLabel.textColor = [UIColor greenColor];
508 509 510 511
        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
512 513 514 515 516 517
    }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
518
    }
Sandy's avatar
Sandy committed
519 520
    
    _pvc.isHiddenEdit = ![self.bill.state isEqualToString:PURCHASE_STATE_WAITE_RECIEVE];
陈俊俊's avatar
陈俊俊 committed
521
    self.noticeNumberLabel.text = (self.bill.noticeNumber.length == 0) ? @"无":(self.bill.noticeNumber);
陈俊俊's avatar
陈俊俊 committed
522 523 524
    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
525
    self.totalPriceLabel.text = [IBTCommon checkString:[self.bill.total stringValue]];
陈俊俊's avatar
陈俊俊 committed
526
    self.noteLabel.text = [NSString stringWithFormat:@"%@",self.bill.remark?self.bill.remark:@"无"];
陈俊俊's avatar
陈俊俊 committed
527 528 529
    self.lastModifyNameLabel.text = [IBTCommon checkString:self.bill.lastModify_operName];
    NSString *type = [self.bill.type isEqualToString:GXF_Critical] ? @"紧急" : @"普通";
    self.typeLabel.text = type;
530
    self.purchaserLabel.text = [NSString stringWithFormat:@"%@[%@]",self.bill.purchaserName, self.bill.purchaserCode];
531
    self.vendorIsSureLabel.text = (self.bill.vendorConfirmTime.length > 0 && self.bill.vendorConfirmTime)? @"是":@"否";
陈俊俊's avatar
陈俊俊 committed
532 533
    self.warehouseLabel.text = [IBTCommon checkString:self.bill.receiveWrh_name];
    self.otherPriceLabel.text = [self.bill.charge stringValue];
Sandy's avatar
Sandy committed
534 535 536
    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
537 538
    self.labelExpiredDate.text = [IBTCommon checkString:self.bill.expiredDate];
    self.labelOutSideNum.text = [IBTCommon checkString:self.bill.outSideBillNumber];
Sandy's avatar
Sandy committed
539 540
    self.labelReciever.text = [IBTCommon checkString:self.bill.receive_operName];
    self.labelRecieveTime.text = [IBTCommon checkString:self.bill.receive_time];
陈俊俊's avatar
陈俊俊 committed
541
    NSMutableArray *productArr = [NSMutableArray array];
Sandy's avatar
Sandy committed
542 543 544 545 546 547 548 549
    
    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
550
            
Sandy's avatar
Sandy committed
551 552
            //待收货的时候才可以显示默认值
            if ([self.bill.state isEqualToString:PURCHASE_STATE_WAITE_RECIEVE]  && self.bill.receive_id == nil && billProbuct.rctQty.floatValue == 0) {
Sandy's avatar
Sandy committed
553 554 555 556 557
                
                if (self.isCenter) {
                    [billProbuct z_setRctQty:p.qty.floatValue];
                }else if (self.isWms){
                    [billProbuct z_setRctQty:0];
Sandy's avatar
Sandy committed
558 559 560 561
                }else{
                        billProbuct.rctQty = nil;
                        billProbuct.rctBaseQty = nil;
                        billProbuct.rctTotal = nil;
Sandy's avatar
Sandy committed
562
                }
Sandy's avatar
Sandy committed
563 564
            }else{
                [billProbuct z_setRctQty:billProbuct.rctQty.floatValue];
Sandy's avatar
Sandy committed
565
            }
Sandy's avatar
Sandy committed
566 567 568 569
            [productArr addObject:billProbuct];
        }
        _pvc.productArr = productArr;
        [_pvc.tableView reloadData];
Sandy's avatar
Sandy committed
570
        
Sandy's avatar
Sandy committed
571 572 573 574
//        //如果是wms,非中心仓,则审核完加载详情的时候自动收货
//        if (self.isWms && self.isCenter == NO && [self.bill.state isEqualToString:PURCHASE_STATE_WAITE_RECIEVE]) {
//            [self httpRecieve];
//        }
Sandy's avatar
Sandy committed
575
        
Sandy's avatar
Sandy committed
576 577 578 579 580 581 582 583
    }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
584
    }
Sandy's avatar
Sandy committed
585

Sandy's avatar
Sandy committed
586
    
陈俊俊's avatar
陈俊俊 committed
587 588 589 590 591 592 593 594 595 596 597
    [self setNoteHeight];
}

- (void)setNoteHeight
{
    CGFloat height =  [self.noteLabel calculateHeight];
    
    CGRect noteFrame = self.noteLabel.frame;
    noteFrame.size.height = height;
    self.noteLabel.frame = noteFrame;
    
598
    CGFloat totalHeight = height + LeftHeight*_leftArr.count + LeftMargin;
陈俊俊's avatar
陈俊俊 committed
599 600 601 602
    CGRect purchaseFrame = _purchaseView.frame;
    purchaseFrame.size.height = totalHeight;
    _purchaseView.frame = purchaseFrame;
    
Sandy's avatar
Sandy committed
603 604 605 606 607 608 609
//    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{
Sandy's avatar
Sandy committed
610 611 612 613
        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);
Sandy's avatar
Sandy committed
614
//    }
陈俊俊's avatar
陈俊俊 committed
615 616 617
    
}

陈俊俊's avatar
陈俊俊 committed
618 619 620
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (alertView.tag == CancleTag) {
        if (buttonIndex == 1) {
Sandy's avatar
Sandy committed
621 622 623 624
            if (self.isWms) {
                ShowMessage(@"wms仓不允许作废!");
                return;
            }
陈俊俊's avatar
陈俊俊 committed
625 626 627 628 629 630
            [self dealByAction:PURCHASE_ACTION_ABORT];//作废
        }
    }else if (alertView.tag == EndTag){
        if (buttonIndex == 1) {
            [self dealByAction:PURCHASE_ACTION_FINISH];//结束
        }
陈俊俊's avatar
陈俊俊 committed
631 632 633 634 635 636 637 638
    }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
639 640 641 642 643 644 645 646 647 648 649 650
    }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
651 652 653 654 655 656 657 658
    for (TransferPdtDetail *detail in _pvc.productArr) {
        if (detail.rctQty == nil) {
            ShowMessage(@"请选择商品实收数量后再提交!");
            return;
            
        }
    }
    
Sandy's avatar
Sandy committed
659 660 661 662
    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
663 664 665 666 667 668 669 670 671
    
    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
672
    [param setObject:arrProduct forKey:@"products"];
Sandy's avatar
Sandy committed
673 674 675 676 677
    
    
    
    [param setObject:self.bill.accountDetails forKey:@"accountDetails"];
    
Sandy's avatar
Sandy committed
678
    IBTLoadingView *hud = [IBTLoadingView showHUDAddedTo:self.view animated:YES];
Sandy's avatar
Sandy committed
679
    __weak UIViewController *weakSelf = self;
Sandy's avatar
Sandy committed
680 681
    [HTTP recievePurchase:param success:^(id succ) {
        [hud hide:YES];
Sandy's avatar
Sandy committed
682
        if ([succ[@"success"] boolValue]) {
Sandy's avatar
Sandy committed
683
            [ICRUserUtil sharedInstance].needFresh = YES;
Sandy's avatar
Sandy committed
684 685 686 687
            [IBTLoadingView showTips:@"   收货成功!   "];
            [weakSelf.navigationController popViewControllerAnimated:YES];
        }
    } failure:^(id fail) {
Sandy's avatar
Sandy committed
688
        [hud hide:YES];
Sandy's avatar
Sandy committed
689
        [IBTLoadingView showTips:fail];
Sandy's avatar
Sandy committed
690 691 692 693 694 695 696 697 698 699 700 701 702
    }];
    
}


- (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
703
    }
Sandy's avatar
Sandy committed
704 705 706 707 708 709 710 711
    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
712
}
Sandy's avatar
Sandy committed
713

714
- (void)httpSave {
Sandy's avatar
Sandy committed
715 716 717 718 719 720 721
    for (TransferPdtDetail *detail in _pvc.productArr) {
        if (detail.rctQty == nil) {
            ShowMessage(@"请选择商品实收数量后再保存!");
            return;
            
        }
    }
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760
    //保存
    void(^succ)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        if (data) {
            NSInteger success = [data[@"success"] integerValue];
            NSString *message = data[@"message"];
            if (success == 1) {
                //成功
                [IBTLoadingView showTips:@"   保存成功!   "];
                [self PopViewControllerAnimated:YES];
            }else{
                [IBTLoadingView showTips:message];
            }
        }
    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
    };
    
    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];
    }
    
    [param setObject:arrProduct forKey:@"products"];
    
    
    
    [param setObject:self.bill.accountDetails forKey:@"accountDetails"];
    
    
    [IBTLoadingView showProgressLabel:@"保存..."];
    [[ICRHTTPController sharedController] savePurchaseWithData:param success:succ failure:fail];
}

Sandy's avatar
Sandy committed
761

陈俊俊's avatar
陈俊俊 committed
762 763 764 765 766 767
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
Sandy's avatar
Sandy committed
768 769 770 771 772 773 774 775
 #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
776 777

@end