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

#import "NewTransportViewController.h"
#import "TopTransportView.h"
#import "BottomTransportView.h"
#import "TransportPurchaseViewController.h"
陈俊俊's avatar
陈俊俊 committed
13 14
#import "NewCostViewController.h"
#import "TransportPdtDetail.h"
陈俊俊's avatar
陈俊俊 committed
15
#import "FeeAcountDetail.h"
陈俊俊's avatar
陈俊俊 committed
16 17
#import "TransportViewController.h"
#import "ShopDetaileViewController.h"
18
#import "PurchaseBill.h"
19
#import "ProductStockModel.h"
20
#import "CalculateHelper.h"
21
NSInteger purchaseAddStockCheckNumber = 0;
陈俊俊's avatar
陈俊俊 committed
22 23 24 25 26
typedef enum : NSUInteger {
    SaveTag = 7000,
    CommitTag,
} BtnTag;

陈俊俊's avatar
陈俊俊 committed
27
#define TopHeight 328
Sandy's avatar
Sandy committed
28
#define BottomHeight 290
陈俊俊's avatar
陈俊俊 committed
29 30
#define SpaceHeight 20
#define BottomViewHeight 60
陈俊俊's avatar
陈俊俊 committed
31
@interface NewTransportViewController ()<TopTransportViewDelegate,UIScrollViewDelegate,UIAlertViewDelegate>
陈俊俊's avatar
陈俊俊 committed
32 33 34 35 36 37 38
{
    UIScrollView *_scrollView;
    TopTransportView *_sheetView;
    BottomTransportView *_bottomView;
    id uuidObject;
    id billNumberObject;
    NSNumber *versionObject;
陈俊俊's avatar
陈俊俊 committed
39
    id stateObject;
陈俊俊's avatar
陈俊俊 committed
40
    
陈俊俊's avatar
陈俊俊 committed
41
}
陈俊俊's avatar
陈俊俊 committed
42
@property (nonatomic,strong)NSString *state;
43 44 45 46
/**
 *  用户选择的第一个商品的采购单
 */
@property (strong, nonatomic) PurchaseBill *firstBill;
Sandy's avatar
Sandy committed
47 48 49 50
/**
 *  缓存的选择的采购单数据
 */
@property (strong, nonatomic) NSMutableDictionary *dicProduct;
陈俊俊's avatar
陈俊俊 committed
51 52 53
@end

@implementation NewTransportViewController
陈俊俊's avatar
陈俊俊 committed
54 55 56
- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
陈俊俊's avatar
陈俊俊 committed
57 58 59
- (instancetype)init{
    self = [super init];
    if (self) {
陈俊俊's avatar
陈俊俊 committed
60 61 62
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(choseTransportPurchase) name:KNOTIFICATION_ChoseTransportPurchase object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addTransportCost:) name:KNOTIFICATION_AddTransportCost object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addPurchaseProduct:) name:KNOTIFICATION_AddPurchaseProduct object:nil];
Sandy's avatar
Sandy committed
63
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deleteInPurchase:) name:KNOTIFICATION_DeleteTransportPdtInPurchase object:nil];
陈俊俊's avatar
陈俊俊 committed
64 65 66 67 68 69 70 71 72 73 74
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    //布局
    [self bulidLayout];
    uuidObject = [NSNull null];
    billNumberObject = [NSNull null];
    versionObject = [NSNumber numberWithInteger:0];
陈俊俊's avatar
陈俊俊 committed
75
    stateObject = [NSNull null];
陈俊俊's avatar
陈俊俊 committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
    if (self.transport) {
        [self getDataFromServer];
    }
}

- (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"];
                Transport *transport = [[Transport alloc]init];
                [transport setValuesForKeysWithDictionary:dictData];
                self.transport = transport;
                [strongSelf fetchtTransportDetail];
            }else{
                [IBTLoadingView showTips:message];
            }
        }else{
            [IBTLoadingView showTips:@"     无记录     "];
        }
    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
    };
    [IBTLoadingView showProgressLabel:@"正在加载..."];
    [[ICRHTTPController sharedController] getTransportResultWithTransportUuid:self.transport.uuid success:succ failure:fail];
陈俊俊's avatar
陈俊俊 committed
108
}
陈俊俊's avatar
陈俊俊 committed
109 110 111 112 113 114

- (void)fetchtTransportDetail
{
    _sheetView.transport = self.transport;
    [_bottomView refreshCost:self.transport.accountDetails];
    [_bottomView refreshTranProduct:self.transport.pdtDetails];
115 116
    
    //清空缓存,重新
117 118
    [self resetCache];

陈俊俊's avatar
陈俊俊 committed
119 120
}

Sandy's avatar
Sandy committed
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
- (void)deleteInPurchase:(NSNotification *)noti {
    NSString *bill = noti.object;
    [self deletePdtUnderPurchaseBillNumber:bill];
}

- (void)deletePdtUnderPurchaseBillNumber:(NSString *)billNumber {
    NSMutableArray *arrInBill = [NSMutableArray array];
    for (TransportPdtDetail *pdt in _bottomView.productVC.transportProductArr) {
        if ([pdt.purchasebillnumber isEqualToString:billNumber]) {
            [arrInBill addObject:pdt];
        }
    }
    NSMutableArray *orign = _bottomView.productVC.transportProductArr.mutableCopy;
    [orign removeObjectsInArray:arrInBill];
    
//    if (self.transport) {
//        self.transport.pdtDetails = orign;
//        [self fetchtTransportDetail];
//        
//    }else{
        _bottomView.productVC.transportProductArr = orign;
        [_bottomView.productVC refresh];
143
    [self resetCache];
Sandy's avatar
Sandy committed
144 145 146
//    }
}

147 148 149 150 151 152 153 154 155 156 157 158 159 160
- (void)resetCache {
    //清空缓存,重新
    [self.dicProduct removeAllObjects];
    for (TransportPdtDetail *pdtDetail in _bottomView.productVC.transportProductArr) {
        NSMutableArray *arrProduct = [self.dicProduct objectForKey:pdtDetail.purchasebillnumber];
        if (!arrProduct) {
            arrProduct = [NSMutableArray array];
            [self.dicProduct setObject:arrProduct forKey:pdtDetail.purchasebillnumber];
        }
        
        [arrProduct addObject:pdtDetail];
    }
}

陈俊俊's avatar
陈俊俊 committed
161 162
- (void)bulidLayout{
    self.view.backgroundColor  = XXFBgColor;
Sandy's avatar
Sandy committed
163
    _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0,0, ScreenSize.width, ScreenHeight- 64 - BottomViewHeight )];
陈俊俊's avatar
陈俊俊 committed
164 165 166 167 168 169
    _scrollView.showsHorizontalScrollIndicator  = NO;
    _scrollView.showsVerticalScrollIndicator = NO;
    _scrollView.contentSize = CGSizeMake(ScreenSize.width, TopHeight+ BottomHeight + SpaceHeight*2);
    [self.view addSubview:_scrollView];
    
    
Sandy's avatar
Sandy committed
170
    UIView *footView = [[UIView alloc]initWithFrame:CGRectMake(0, ScreenHeight - BottomViewHeight - 64, ScreenSize.width, BottomViewHeight)];
陈俊俊's avatar
陈俊俊 committed
171 172 173 174 175 176 177 178 179 180 181 182
    UIButton *saveBtn =  [IBTCustomButtom creatButtonWithFrame:CGRectMake(15, 8, (ScreenSize.width - 15*3)/2, 44) target:self sel:@selector(btnClick:) tag:SaveTag image:nil title:@"保存" titleColor: [UIColor whiteColor] isCorner:YES corner:5 bgColor:GXF_SAVE_COLOR];
    [footView addSubview:saveBtn];
    
    UIButton *commitBtn = [IBTCustomButtom creatButtonWithFrame:CGRectMake(CGRectGetMaxX(saveBtn.frame) + 15, 8, (ScreenSize.width - 15*3)/2, 44) target:self sel:@selector(btnClick:) tag:CommitTag image:nil title:@"提交" titleColor: [UIColor whiteColor] isCorner:YES corner:5 bgColor:GXF_COMMIT_COLOR];
    [footView addSubview:commitBtn];
    
    [self.view addSubview:footView];
    
    _sheetView = [[TopTransportView alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, TopHeight)];
    _sheetView.delegate = self;
    [_scrollView addSubview:_sheetView];
    
陈俊俊's avatar
陈俊俊 committed
183
    _bottomView = [[BottomTransportView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_sheetView.frame) + 20, ScreenSize.width,BottomHeight) withHidden:NO];
陈俊俊's avatar
陈俊俊 committed
184 185 186 187 188 189 190 191
    _bottomView.backgroundColor = [UIColor whiteColor];
    [_scrollView addSubview:_bottomView];
}
- (void)btnClick:(UIButton *)btn{
    switch (btn.tag) {
        case SaveTag:
        {
            if ([self checkTransport]) {
陈俊俊's avatar
陈俊俊 committed
192
                self.state = TRANSFER_STATE_INITIAL;
陈俊俊's avatar
陈俊俊 committed
193
                [self getDataFromServer:TRANSPORT_STATE_INITIAL msg:@"正在保存..."];
陈俊俊's avatar
陈俊俊 committed
194 195 196 197 198
            }
        }
            break;
        case CommitTag:{
            if ([self checkTransport]) {
199 200
                
                
201
                NSArray *array = self.dicProduct.allKeys;
Sandy's avatar
Sandy committed
202
                WS(weakSelf);
203 204
                //判断数量问题
                [IBTLoadingView showProgressLabel:@""];
205
                [self resetCache];
206 207 208 209 210 211 212
                [self stockValidWithDic:self.dicProduct billNumbers:array complete:^{
                    [IBTLoadingView hideHUDWithText:@""];
                    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请确认提交" delegate:weakSelf cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
                    alertView.delegate = weakSelf;
                    [alertView show];
                    
                }];
陈俊俊's avatar
陈俊俊 committed
213 214 215 216 217 218 219
            }
        }
            break;
        default:
            break;
    }
}
220

Sandy's avatar
Sandy committed
221 222 223 224 225 226 227
/**
 *  查库存接口
 *
 *  @param dic         存放已选择单据
 *  @param billNumbers 单号
 *  @param complete    回调
 */
228
- (void)stockValidWithDic:(NSMutableDictionary *)dic billNumbers:(NSArray *)billNumbers complete:(void (^)(void))complete {
229
    //如果billNumbers数量为0,说明没有去选择
230 231 232 233 234 235 236
    
    NSString *billNum = billNumbers[purchaseAddStockCheckNumber];
    NSMutableArray *arrProducts = [dic objectForKey:billNum];
    __weak NewTransportViewController *weakSelf = self;
    [HTTP purchaseStockWithPurchaseUuid:billNum success:^(id succ) {
        if (![succ[@"data"] isKindOfClass:[NSArray class]]) {
                                [IBTLoadingView hideHUDWithText:@""];
237
            NSString *msg = [NSString stringWithFormat:@"采购单<%@>在总部系统的库存不足!", billNum];
238 239 240 241 242 243 244 245 246 247
            ShowMessage(msg);
            return ;
        }
        
        for (NSDictionary *dict in succ[@"data"]) {
            ProductStockModel *model = [ProductStockModel new];
            [model setValuesForKeysWithDictionary:dict];
            for (TransportPdtDetail *detail in arrProducts) {
                if ([detail.productCode isEqualToString:model.productCode]) {
                    
Sandy's avatar
Sandy committed
248
                    if ([detail.baseQty compare:decimalNumberWithDouble(model.qty)] == NSOrderedDescending) {
249
                        CLog(@"库存不足");
Sandy's avatar
Sandy committed
250
                        [IBTLoadingView hideHUDWithText:@""];
251
                        purchaseAddStockCheckNumber = 0;
252
                        NSString *msg = [NSString stringWithFormat:@"采购单<%@>的商品%@在总部系统的库存不足!", billNum, detail.productName];
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
                        ShowMessage(msg);
                        return ;
                    }
                }
            }
        }
        
        purchaseAddStockCheckNumber += 1;
        if (purchaseAddStockCheckNumber == billNumbers.count) {
            purchaseAddStockCheckNumber = 0;
            complete();
        }else{
            [weakSelf stockValidWithDic:dic billNumbers:billNumbers complete:complete];
        }
        
    } failure:^(id fail) {
                            [IBTLoadingView hideHUDWithText:@""];
        purchaseAddStockCheckNumber = 0;
    }];
}


陈俊俊's avatar
陈俊俊 committed
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
- (void)getDataFromServer:(NSString *)state msg:(NSString *)msg{
    //保存
    void(^succ)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        if (data) {
            NSInteger success = [data[@"success"] integerValue];
            NSString *message = data[@"message"];
            if (success == 1) {
                //成功
                if ([state isEqualToString:PURCHASE_STATE_INITIAL]) {//保存成功
                    NSString *uuidS = data[@"data"][@"uuid"];
                    NSString *billNumberS = data[@"data"][@"billNumber"];
                    NSNumber *versionN = data[@"data"][@"version"];
                    uuidObject = uuidS;
                    billNumberObject = billNumberS;
                    versionObject = versionN;
                    [IBTLoadingView showTips:[NSString stringWithFormat:@"当前单据%@已保存成功",billNumberS]];
                }else{//提交成功
陈俊俊's avatar
陈俊俊 committed
293
                    TransportViewController *svc = [TransportViewController new];
陈俊俊's avatar
陈俊俊 committed
294
                    svc.title = @"发运单列表";
陈俊俊's avatar
陈俊俊 committed
295
                    [self PushViewController:svc animated:YES];
陈俊俊's avatar
陈俊俊 committed
296 297
                }
            }else{
298
                ShowMessage(message);
陈俊俊's avatar
陈俊俊 committed
299 300 301 302 303 304 305 306 307 308 309 310 311 312
            }
        }
    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
    };
    
    if(self.transport.uuid.length > 0 && uuidObject == [NSNull null]){
        uuidObject = self.transport.uuid;
    }
    if (self.transport.billnumber > 0 && billNumberObject == [NSNull null]) {
        billNumberObject = self.transport.billnumber;
    }
陈俊俊's avatar
陈俊俊 committed
313 314 315 316 317
    if (self.transport.state > 0 && stateObject == [NSNull null]) {
        stateObject = self.transport.state;
    }else{
        stateObject = state;
    }
陈俊俊's avatar
陈俊俊 committed
318 319 320
    if (self.transport && [versionObject integerValue] == 0) {
        versionObject = self.transport.version;
    }
陈俊俊's avatar
陈俊俊 committed
321
    NSMutableArray *billProducts = [NSMutableArray array];
陈俊俊's avatar
陈俊俊 committed
322
    for (TransportPdtDetail *pdtDetail in _bottomView.productVC.transportProductArr) {
Sandy's avatar
Sandy committed
323 324 325 326 327 328
        TransportPdtDetail *pdtCopy = [[TransportPdtDetail alloc] init];
        [pdtCopy setValuesForKeysWithDictionary:pdtDetail.dictForCommit];
        pdtCopy.shippedFlag = nil;
        pdtCopy.shippedQty = nil;
        pdtCopy.receivedQty = nil;
        [billProducts  addObject:[pdtCopy dictForCommit]];
陈俊俊's avatar
陈俊俊 committed
329 330 331 332 333
    }
    NSMutableArray *costs = [NSMutableArray array];
    for (FeeAcountDetail *fee in _bottomView.costVC.costArr) {
        [costs  addObject:[fee dictForCommit]];
    }
陈俊俊's avatar
陈俊俊 committed
334
    
Sandy's avatar
Sandy committed
335 336 337 338 339 340 341 342
    //获取到期时间
    NSString *dateString = [[NSDate date] httpParameterString];
    NSDateFormatter *f = [NSDateFormatter new];
    [f setDateFormat:@"yyy-MM-dd HH:ss:mm"];
    NSDate *date = [f dateFromString:dateString];
    NSDate *new = [NSDate dateWithTimeInterval:60 * 60 * 24 * 5 sinceDate:date];
    NSString *expiredTime = [f stringFromDate:new];
    
陈俊俊's avatar
陈俊俊 committed
343
    NSDictionary *dict = @{@"uuid":uuidObject,
陈俊俊's avatar
陈俊俊 committed
344
                           @"version":versionObject,
陈俊俊's avatar
陈俊俊 committed
345
                           @"billnumber":billNumberObject,
陈俊俊's avatar
陈俊俊 committed
346
                           @"enterprise":[ICRUserUtil sharedInstance].orgId,
陈俊俊's avatar
陈俊俊 committed
347
                           @"state":stateObject,
Sandy's avatar
Sandy committed
348
                           @"expiredDate":expiredTime,
陈俊俊's avatar
陈俊俊 committed
349 350 351 352 353 354 355 356 357
                           @"warehouseUuid":[IBTCommon checkString:_sheetView.warehouseUuid],
                           @"warehouseCode":[IBTCommon checkString:_sheetView.warehouseCode],
                           @"warehouseName":[IBTCommon checkString:_sheetView.warehouseName],
                           @"rwarehouseUuid":[IBTCommon checkString:_sheetView.rwarehouseUuid],
                           @"rwarehouseCode":[IBTCommon checkString:_sheetView.rwarehouseCode],
                           @"rwarehouseName":[IBTCommon checkString:_sheetView.rwarehouseName],
                           @"carnumber":[IBTCommon checkString:_sheetView.carnumber],
                           @"type":[IBTCommon checkString:_sheetView.type],
                           @"carphone":[IBTCommon checkString:_sheetView.carphone],
陈俊俊's avatar
陈俊俊 committed
358
                           @"arriveDate":[IBTCommon checkString:_sheetView.arriveDate],
陈俊俊's avatar
陈俊俊 committed
359
                           @"note":[IBTCommon checkString:_sheetView.note],
陈俊俊's avatar
陈俊俊 committed
360 361 362
                           @"pdtDetails":billProducts,
                           @"accountDetails":costs};
    [IBTLoadingView showProgressLabel:msg];
陈俊俊's avatar
陈俊俊 committed
363 364 365 366 367 368
    if ([state isEqualToString:TRANSFER_STATE_INITIAL]) {
         [[ICRHTTPController sharedController] saveTransportWithData:dict success:succ failure:fail];
    }else{
         [[ICRHTTPController sharedController] saveAndSubmitTransportWithData:dict success:succ failure:fail];
    }
   
陈俊俊's avatar
陈俊俊 committed
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
}



- (BOOL)checkTransport{
    _sheetView.note = _sheetView.remarkTextView.text;
    _sheetView.carnumber = _sheetView.carTextFiled.text;
    _sheetView.carphone = _sheetView.phoneTextFiled.text;

    if (_sheetView.warehouseName.length == 0 ) {
        ShowMessage(@"发货仓库不能为空");
        return NO;
    }
    if (_sheetView.rwarehouseUuid.length == 0 ) {
        ShowMessage(@"收货仓库不能为空");
        return NO;
    }
    
    if (_sheetView.type.length == 0 ) {
        ShowMessage(@"运输类型不能为空");
        return NO;
    }
    if (_sheetView.carnumber.length == 0) {
        ShowMessage(@"车牌号不能为空");
        return NO;
    }
    if (_sheetView.carphone.length == 0) {
        ShowMessage(@"司机电话不能为空");
        return NO;
    }
399 400 401 402
    if (_sheetView.arriveDate.length  == 0) {
        ShowMessage(@"预计到货时间不能为空");
        return NO;
    }
陈俊俊's avatar
陈俊俊 committed
403
    
陈俊俊's avatar
陈俊俊 committed
404
    if (_bottomView.productVC.transportProductArr.count == 0) {
陈俊俊's avatar
陈俊俊 committed
405 406 407 408 409 410 411
        ShowMessage(@"商品不能为空");
        return NO;
    }
    if (_bottomView.costVC.costArr.count == 0) {
        ShowMessage(@"费用不能为空");
        return NO;
    }
陈俊俊's avatar
陈俊俊 committed
412

陈俊俊's avatar
陈俊俊 committed
413
    for (TransportPdtDetail *billProduct in _bottomView.productVC.transportProductArr) {
陈俊俊's avatar
陈俊俊 committed
414
        if ([billProduct.qty floatValue] <= 0 || [billProduct.baseQty floatValue] <= 0) {
陈俊俊's avatar
陈俊俊 committed
415 416 417
            ShowMessage(@"有数量等于0的商品明细,请编辑后保存");
            return NO;
        }
Sandy's avatar
Sandy committed
418 419 420 421
//        if ([billProduct.price floatValue] <=0 || [billProduct.packprice floatValue] <= 0) {
//            ShowMessage(@"有价格未填写的商品明细,请编辑后保存");
//            return NO;
//        }
陈俊俊's avatar
陈俊俊 committed
422
    }
陈俊俊's avatar
陈俊俊 committed
423 424 425 426 427
    // 校验手机号码
    if (![RegexUtil isValidatePhone:_sheetView.carphone] || ![RegexUtil isValidatePhoneNew:_sheetView.carphone]){
        ShowMessage(@"手机号格式不正确");
        return NO;
    }
陈俊俊's avatar
陈俊俊 committed
428

陈俊俊's avatar
陈俊俊 committed
429 430 431
    return YES;
}

432 433 434 435 436 437 438 439 440 441 442 443 444 445
- (void)setFirstBill:(PurchaseBill *)firstBill {
    _firstBill = firstBill;
    /**
     *  @property (nonatomic,strong)NSString *receiveWrh_uuid;//收货uuid
     @property (nonatomic,strong)NSString *receiveWrh_code;//收货代码
     @property (nonatomic,strong)NSString *receiveWrh_name;//收货姓名
     *
     */
    _sheetView.warehouseCode = firstBill.receiveWrh_code;
    _sheetView.warehouseName = firstBill.receiveWrh_name;
    _sheetView.warehouseUuid = firstBill.receiveWrh_uuid;
    _sheetView.warehouseLabel.text = [NSString stringWithFormat:@"%@[%@]",_sheetView.warehouseName,_sheetView.warehouseCode];
    _sheetView.warehouseLabel.textColor = GXF_CONTENT_COLOR;
}
陈俊俊's avatar
陈俊俊 committed
446 447 448


- (void)choseTransportPurchase{
449
    __weak NewTransportViewController *weakSelf = self;
陈俊俊's avatar
陈俊俊 committed
450
    TransportPurchaseViewController *tpv = [TransportPurchaseViewController new];
Sandy's avatar
Sandy committed
451
    tpv.isTransportIn = YES;
陈俊俊's avatar
陈俊俊 committed
452
    tpv.getProchaseProduct = ^(NSArray *products){
陈俊俊's avatar
陈俊俊 committed
453 454 455
        if (products.count > 0) {
            [_bottomView reProduct:products];
        }
陈俊俊's avatar
陈俊俊 committed
456
    };
457 458 459 460 461 462 463
    
    tpv.blockFirstWarehouse = ^(NSArray *bills){
        if (bills.count > 0) {
            weakSelf.firstBill = bills[0];
        }
    };
    
Sandy's avatar
Sandy committed
464 465
    tpv.dicProduct = self.dicProduct;
    
陈俊俊's avatar
陈俊俊 committed
466 467
    [self PushViewController:tpv animated:YES];
}
Sandy's avatar
Sandy committed
468 469


陈俊俊's avatar
陈俊俊 committed
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
- (void)addTransportCost:(NSNotification *)fination{
    
    NewCostViewController *nvc = [NewCostViewController new];
    NSIndexPath *indexPath = [[fination userInfo] objectForKey:@"indexPath"];
    FeeAcountDetail *fee = [[fination userInfo] objectForKey:@"feeAccountDetail"];

    if (indexPath) {
        nvc.navTitle = @"编辑费用";
        nvc.indexPath = indexPath;
        nvc.accountDetail = fee;
    }else{
        nvc.navTitle = @"添加费用";
    }
    nvc.getTransportCost = ^(FeeAcountDetail *fee,NSIndexPath *indexPath){
        if (fee) {
            [_bottomView refreshCost:fee indexPath:indexPath];
        }
    };
    nvc.deleteTransportCost = ^(FeeAcountDetail *fee,NSIndexPath *indexPath){
        if (fee) {
            [_bottomView refreshDelCost:fee indexPath:indexPath];
        }
    };
    [self PushViewController:nvc animated:YES];

}
- (void)addPurchaseProduct:(NSNotification *)fication{
陈俊俊's avatar
陈俊俊 committed
497
    TransportPdtDetail *billProduct = [[fication userInfo] objectForKey:@"transportPdtDetail"];
498
    NSInteger indexTag = [[[fication userInfo] objectForKey:@"indexPath"] integerValue];
陈俊俊's avatar
陈俊俊 committed
499
    
陈俊俊's avatar
陈俊俊 committed
500
    ShopDetaileViewController *svc = [[ShopDetaileViewController alloc] init];
陈俊俊's avatar
陈俊俊 committed
501
    if (billProduct) {
Sandy's avatar
Sandy committed
502
        svc.intertype = ShopDetailInterTypeTransport;
陈俊俊's avatar
陈俊俊 committed
503
        svc.navTitle = @"编辑商品";
陈俊俊's avatar
陈俊俊 committed
504 505 506 507 508 509
        ShopDetail *shopDetail=[self coverShopDetail:billProduct];
        shopDetail.IsXiuGai=YES;
        svc.choseShopDetail = ^(ShopDetail *Detail){
            TransportPdtDetail *tdetail = [self coverTransportPdtDetail:Detail];
            if (Detail.IsDeleted) {
                [_bottomView refreshDelProduct:tdetail tag:indexTag];
510
                //清空缓存,重新
511 512
                [self resetCache];
                
陈俊俊's avatar
陈俊俊 committed
513 514 515 516 517 518
            }else{
                [_bottomView refreshEditProduct:tdetail tag:indexTag];
            }
        };
        svc.shopDetail=shopDetail;
    }else{
陈俊俊's avatar
陈俊俊 committed
519
        svc.navTitle = @"添加商品";
陈俊俊's avatar
陈俊俊 committed
520 521 522 523 524 525
        // 回调
        svc.choseShopDetail = ^(ShopDetail *shopDetail){
            TransportPdtDetail *tdetail = [self coverTransportPdtDetail:shopDetail];
            [_bottomView refreshProduct:tdetail];
        };
    }
陈俊俊's avatar
陈俊俊 committed
526 527
    [self PushViewController:svc animated:YES];
}
陈俊俊's avatar
陈俊俊 committed
528

陈俊俊's avatar
陈俊俊 committed
529 530 531 532 533 534 535

- (TransportPdtDetail *)coverTransportPdtDetail:(ShopDetail *)shopDetail{
    TransportPdtDetail *billProduct = [[TransportPdtDetail alloc]init];
    billProduct.uuid = shopDetail.uuid;
    billProduct.productUuid = shopDetail.product_uuid;
    billProduct.productCode = shopDetail.product_code;
    billProduct.productName = shopDetail.merchandise;
Sandy's avatar
Sandy committed
536
    billProduct.qpc = [NSDecimalNumber decimalNumberWithString:shopDetail.packageSpecification];
陈俊俊's avatar
陈俊俊 committed
537
    billProduct.unit = shopDetail.packageUnit;
Sandy's avatar
Sandy committed
538 539 540 541
    billProduct.qty = [NSDecimalNumber decimalNumberWithString:shopDetail.packageQuantity];
    billProduct.packprice = shopDetail.packageUnitPrice;
    billProduct.price = shopDetail.foundationUnitPrice;
    billProduct.baseQty = [NSDecimalNumber decimalNumberWithString:shopDetail.foundationQuantity];
542
    billProduct.total = shopDetail.totalMoney;
陈俊俊's avatar
陈俊俊 committed
543
    billProduct.note = shopDetail.remark;
陈俊俊's avatar
陈俊俊 committed
544
    billProduct.qpcStr = shopDetail.packageQpcStr ? shopDetail.packageQpcStr : @"无" ;
陈俊俊's avatar
陈俊俊 committed
545
    billProduct.baseUnit = shopDetail.packageQpcUnit;
陈俊俊's avatar
陈俊俊 committed
546 547
    billProduct.purchasebillnumber = shopDetail.sourceBillNumber;
    billProduct.purchasePdtDetail = shopDetail.sourceDetail;
Sandy's avatar
Sandy committed
548 549
    billProduct.receivedQty = shopDetail.receivedQty;
    billProduct.shippedQty = shopDetail.shippedQty;
550 551
    billProduct.checkTotal = shopDetail.checkTotal;
    billProduct.checkPrice = shopDetail.checkPrice;
陈俊俊's avatar
陈俊俊 committed
552 553 554 555
    return billProduct;
}
- (ShopDetail *)coverShopDetail:(TransportPdtDetail *)billProduct{
    ShopDetail *shopDetail = [[ShopDetail alloc]init];
Sandy's avatar
Sandy committed
556
    [shopDetail setValuesForKeysWithDictionary:billProduct.dictForCommit];
陈俊俊's avatar
陈俊俊 committed
557 558 559 560 561 562 563
    shopDetail.uuid = billProduct.uuid;
    shopDetail.product_uuid = billProduct.productUuid;
    shopDetail.product_code = billProduct.productCode;
    shopDetail.merchandise  = billProduct.productName;
    shopDetail.packageSpecification  =  [billProduct.qpc stringValue];
    shopDetail.packageUnit = billProduct.unit;
    shopDetail.packageQuantity = [billProduct.qty stringValue];
陈俊俊's avatar
陈俊俊 committed
564 565
    shopDetail.packageUnitPrice  = billProduct.packprice;
    shopDetail.foundationUnitPrice= billProduct.price;
陈俊俊's avatar
陈俊俊 committed
566
    shopDetail.foundationQuantity= [billProduct.baseQty  stringValue];
陈俊俊's avatar
陈俊俊 committed
567
    shopDetail.totalMoney= billProduct.total;
Sandy's avatar
Sandy committed
568
    shopDetail.total = billProduct.total;
陈俊俊's avatar
陈俊俊 committed
569
    shopDetail.remark  = billProduct.note;
陈俊俊's avatar
陈俊俊 committed
570 571
    shopDetail.sourceDetail = billProduct.purchasePdtDetail;
    shopDetail.sourceBillNumber = billProduct.purchasebillnumber;
Sandy's avatar
Sandy committed
572 573
    shopDetail.receivedQty = billProduct.receivedQty;
    shopDetail.shippedQty = billProduct.shippedQty;
574 575
    shopDetail.checkPrice = billProduct.checkPrice;
    shopDetail.checkTotal = billProduct.checkTotal;
陈俊俊's avatar
陈俊俊 committed
576 577 578
    return shopDetail;
    
}
陈俊俊's avatar
陈俊俊 committed
579 580 581
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 1) {
        //提交
陈俊俊's avatar
陈俊俊 committed
582 583
        self.state = TRANSPORT_STATE_RECEIVED;
        [self getDataFromServer:TRANSPORT_STATE_RECEIVED msg:@"正在提交..."];
陈俊俊's avatar
陈俊俊 committed
584 585
    }
}
陈俊俊's avatar
陈俊俊 committed
586

陈俊俊's avatar
陈俊俊 committed
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
#pragma mark - TopPurchaseViewDelegate

- (void)pushNextViewController:(id)vc{
    [self PushViewController:vc animated:YES];
}
#pragma mark - 协议方法
- (void)hiddenKeyBoard{
    [self keyboardHidden];
}
- (void)keyboardHidden{
    [_sheetView.phoneTextFiled resignFirstResponder];
    [_sheetView.carTextFiled resignFirstResponder];
    [_sheetView.remarkTextView resignFirstResponder];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
陈俊俊's avatar
陈俊俊 committed
604 605 606 607 608
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    if(self.transport && [self.state isEqualToString:TRANSPORT_STATE_INITIAL]){
        [ICRUserUtil sharedInstance].needFresh = YES;
    }
陈俊俊's avatar
陈俊俊 committed
609 610 611 612
    if (_sheetView.startTimeView) {
        [_sheetView.startTimeView removeFromSuperview];
        _sheetView.startTimeView = nil;
    }
陈俊俊's avatar
陈俊俊 committed
613
}
陈俊俊's avatar
陈俊俊 committed
614

Sandy's avatar
Sandy committed
615 616 617 618 619 620 621
- (NSMutableDictionary *)dicProduct {
    if (!_dicProduct) {
        _dicProduct = [NSMutableDictionary dictionary];
    }
    return _dicProduct;
}

陈俊俊's avatar
陈俊俊 committed
622 623 624 625 626 627 628 629 630 631 632
/*
#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.
}
*/

@end