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

#import "NewPurchaseViewController.h"
陈俊俊's avatar
陈俊俊 committed
10
#import "SeePurchaseNoticeViewController.h"
n22's avatar
n22 committed
11
#import "TopPurchaseView.h"
陈俊俊's avatar
陈俊俊 committed
12
#import "ProductBillViewController.h"
n22's avatar
n22 committed
13
#import "PurchaseBillProduct.h"
陈俊俊's avatar
陈俊俊 committed
14
#import "PurchaseViewController.h"
陈俊俊's avatar
陈俊俊 committed
15 16
#import "ShopDetaileViewController.h"
#import "PurchaseBillProduct.h"
17
#import "GXFPopView.h"
陈俊俊's avatar
陈俊俊 committed
18
#import "NoticeProduct.h"
19 20
#import "BottomPurchaseView.h"
#import "NewCostViewController.h"
21
#import "FeeAcountDetail.h"
Sandy's avatar
Sandy committed
22
#import "CalculateHelper.h"
n22's avatar
n22 committed
23
#define TopHeight 328
n22's avatar
n22 committed
24 25 26 27 28 29 30 31
#define BottomHeight 300
#define SpaceHeight 20
#define BottomViewHeight 60
typedef enum : NSUInteger {
    SaveTag = 8000,
    CommitTag,
} BtnTag;

陈俊俊's avatar
陈俊俊 committed
32
@interface NewPurchaseViewController ()<TopPurchaseViewDelegate,UIAlertViewDelegate>
n22's avatar
n22 committed
33 34 35 36
{
    UIScrollView *_scrollView;
    TopPurchaseView *_purchaseView;
    UIView *_bottomView;
陈俊俊's avatar
陈俊俊 committed
37
    ProductBillViewController *_pvc ;
38
    BottomPurchaseView *_aBottomView;
陈俊俊's avatar
陈俊俊 committed
39 40 41
    id uuidObject;
    id billNumberObject;
    NSNumber *versionObject;
n22's avatar
n22 committed
42
}
n22's avatar
n22 committed
43
@property (nonatomic,strong)NSString *state;
44
@property (nonatomic,strong)GXFPopView *popView;
n22's avatar
n22 committed
45

陈俊俊's avatar
陈俊俊 committed
46 47 48 49




n22's avatar
n22 committed
50 51 52 53
@end

@implementation NewPurchaseViewController

n22's avatar
n22 committed
54 55 56 57 58
- (instancetype)init{
    self = [super init];
    if (self) {
        //监听值的改变
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setProductTotalPrice:) name:SetProductTotalPrice object:nil];
陈俊俊's avatar
陈俊俊 committed
59
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addPurchaseProduct:) name:KNOTIFICATION_AddPurchaseProduct object:nil];
60
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addTransportCost:) name:KNOTIFICATION_AddTransportCost object:nil];
n22's avatar
n22 committed
61 62 63 64
    }
    return self;
}

Sandy's avatar
Sandy committed
65 66 67 68 69 70 71 72 73 74 75 76 77
- (void)viewWillAppear:(BOOL)animated {
    
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    if(self.purchaseBill && [self.state isEqualToString:PURCHASE_STATE_INITIAL]){
        [ICRUserUtil sharedInstance].needFresh = YES;
    }

    
}

n22's avatar
n22 committed
78 79 80 81
- (void)viewDidLoad {
    [super viewDidLoad];
    //布局
    [self bulidLayout];
陈俊俊's avatar
陈俊俊 committed
82 83 84 85
    //数据默认值
    uuidObject = [NSNull null];
    billNumberObject = [NSNull null];
    versionObject = [NSNumber numberWithInteger:0];
陈俊俊's avatar
陈俊俊 committed
86 87 88
    if (self.purchaseBill) {
        [self getDataFromServer];
    }
陈俊俊's avatar
陈俊俊 committed
89 90 91 92 93
    if (self.purchaseNotice) {
        _purchaseView.noticeUuid = self.purchaseNotice.uuid;
        _purchaseView.noticeNumber = self.purchaseNotice.billnumber;
        //转换
        NSMutableArray *arr = [self coverPurchaseBillProduct:self.purchaseNotice.products];
94
        _aBottomView.productVC.productArr = arr;
陈俊俊's avatar
陈俊俊 committed
95
    }
陈俊俊's avatar
陈俊俊 committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
}
- (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.purchaseBill = bill;
                [strongSelf prepareDataInCell];
            }else{
                [IBTLoadingView showTips:message];
            }
        }else{
            [IBTLoadingView showTips:@"     无记录     "];
        }
    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
Sandy's avatar
Sandy committed
120 121
        ShowMessage(((NSError *)data).localizedDescription);
//        [IBTLoadingView showTips:data];
陈俊俊's avatar
陈俊俊 committed
122 123
    };
    [IBTLoadingView showProgressLabel:@"正在加载..."];
陈俊俊's avatar
陈俊俊 committed
124
    [[ICRHTTPController sharedController] getPurchaseResultWithPurchaseUuid:self.purchaseBill.uuid success:succ failure:fail];
陈俊俊's avatar
陈俊俊 committed
125 126 127 128
}
//赋值
- (void)prepareDataInCell{
    _purchaseView.bill = self.purchaseBill;
陈俊俊's avatar
陈俊俊 committed
129
    
陈俊俊's avatar
陈俊俊 committed
130 131 132 133 134 135
    NSMutableArray *arr = [NSMutableArray array];
    for (NSDictionary *productDict in self.purchaseBill.products) {
        PurchaseBillProduct *billProduct = [[PurchaseBillProduct alloc]init];
        [billProduct setValuesForKeysWithDictionary:productDict];
        [arr addObject:billProduct];
    }
136
    _aBottomView.productVC.productArr = arr;
Sandy's avatar
Sandy committed
137
    [_aBottomView.productVC.tableView reloadData];
138 139 140 141 142 143 144 145 146 147 148
    
    
    NSMutableArray *arrCost = [NSMutableArray array];
    for (NSDictionary *dic in _purchaseBill.accountDetails) {
        FeeAcountDetail *cost = [[FeeAcountDetail alloc] init];
        [cost setValuesForKeysWithDictionary:dic];
        [arrCost addObject:cost];
    }
    
    _aBottomView.costVC.costArr = arrCost;
    [_aBottomView.costVC.tableView reloadData];
n22's avatar
n22 committed
149 150
}

151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
- (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) {
            [_aBottomView refreshCost:fee indexPath:indexPath];
        }
    };
    nvc.deleteTransportCost = ^(FeeAcountDetail *fee,NSIndexPath *indexPath){
        if (fee) {
            [_aBottomView refreshDelCost:fee indexPath:indexPath];
        }
    };
    [self PushViewController:nvc animated:YES];
    
}


n22's avatar
n22 committed
179 180 181 182 183 184 185 186 187 188 189 190
#pragma mark - 布局
- (void)bulidLayout
{
    self.view.backgroundColor  = XXFBgColor;
    _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0,0, ScreenSize.width, ScreenSize.height- 64 - BottomViewHeight )];
    _scrollView.showsHorizontalScrollIndicator  = NO;
    _scrollView.showsVerticalScrollIndicator = NO;
    _scrollView.contentSize = CGSizeMake(ScreenSize.width, TopHeight+ BottomHeight + SpaceHeight*2);
    [self.view addSubview:_scrollView];
    
    
    UIView *footView = [[UIView alloc]initWithFrame:CGRectMake(0, ScreenSize.height - BottomViewHeight - 64, ScreenSize.width, BottomViewHeight)];
陈俊俊's avatar
陈俊俊 committed
191
    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];
n22's avatar
n22 committed
192 193
    [footView addSubview:saveBtn];
    
陈俊俊's avatar
陈俊俊 committed
194
    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];
n22's avatar
n22 committed
195 196 197
    [footView addSubview:commitBtn];
    
    [self.view addSubview:footView];
Sandy's avatar
Sandy committed
198
    
n22's avatar
n22 committed
199 200 201 202
    _purchaseView = [[TopPurchaseView alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, TopHeight)];
    _purchaseView.delegate = self;
    [_scrollView addSubview:_purchaseView];
    
Sandy's avatar
Sandy committed
203 204 205 206 207 208 209
    //    _bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_purchaseView.frame) + 20, ScreenSize.width,BottomHeight)];
    //    _bottomView.backgroundColor = [UIColor whiteColor];
    //    [_scrollView addSubview:_bottomView];
    //
    //    _pvc = [[ProductBillViewController alloc]init];
    //    _pvc.viewFrame = _bottomView.bounds;
    //    [_bottomView addSubview:_pvc.view];
210 211 212
    _aBottomView = [[BottomPurchaseView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_purchaseView.frame) + 20, ScreenSize.width,BottomHeight) withHidden:NO];
    _aBottomView.backgroundColor = [UIColor whiteColor];
    [_scrollView addSubview:_aBottomView];
n22's avatar
n22 committed
213 214 215
    
}

216
//添加商品明细,更新上部显示的费用
n22's avatar
n22 committed
217 218
- (void)setProductTotalPrice:(NSNotification *)fication{
    //计算总金额
Sandy's avatar
Sandy committed
219
    NSDecimalNumber *otherPrice = [NSDecimalNumber decimalNumberWithString:@"0"];
Sandy's avatar
Sandy committed
220 221 222 223 224 225 226 227
    //    if (_aBottomView.costVC.costArr.count == 0) {
    //        otherPrice = [_purchaseView.otherPriceFiled.text floatValue];
    //    }else{
    for (FeeAcountDetail *cost in _aBottomView.costVC.costArr) {
        otherPrice = [CalculateHelper calculateNum1:otherPrice num2:cost.leftmoney type:CalculateTypeAdd roundingType:NSRoundBankers cutLenth:10];
    }
    _purchaseView.otherPriceFiled.text = [NSString stringWithFormat:@"%@", otherPrice];
    //    }
228
    
n22's avatar
n22 committed
229
    //其他费用 + 商品总金额
230
    
231
    NSMutableArray *purchaseProduct = _aBottomView.productVC.productArr;
Sandy's avatar
Sandy committed
232
    NSDecimalNumber *totalPrice = [NSDecimalNumber decimalNumberWithString:@"0"];
n22's avatar
n22 committed
233
    for (PurchaseBillProduct *billProduct in purchaseProduct) {
Sandy's avatar
Sandy committed
234
        totalPrice = [CalculateHelper calculateNum1:totalPrice num2:billProduct.total type:CalculateTypeAdd roundingType:NSRoundBankers cutLenth:10];
n22's avatar
n22 committed
235
    }
Sandy's avatar
Sandy committed
236 237 238 239
    NSDecimalNumber *all = [CalculateHelper calculateNum1:totalPrice num2:otherPrice type:CalculateTypeAdd roundingType:NSRoundBankers cutLenth:2];
    _purchaseView.purchasePriceLabel.text = [NSString stringWithFormat:@"%@",[all stringValue]];
    _purchaseView.total = all;
    _purchaseView.chargePurchase = otherPrice;
240 241
    
    
Sandy's avatar
Sandy committed
242
    
243 244 245
    
    
    
n22's avatar
n22 committed
246
}
陈俊俊's avatar
陈俊俊 committed
247
- (void)addPurchaseProduct:(NSNotification *)fication{
248
    
陈俊俊's avatar
陈俊俊 committed
249 250 251
    PurchaseBillProduct *billProduct = [[fication userInfo] objectForKey:@"purchaseBillProduct"];
    NSInteger indexTag = [[[fication userInfo] objectForKey:@"indexTag"] integerValue];
    
陈俊俊's avatar
陈俊俊 committed
252
    ShopDetaileViewController *svc = [[ShopDetaileViewController alloc] init];
Sandy's avatar
Sandy committed
253
    svc.intertype = ShopDetailInterTypePurchase;
陈俊俊's avatar
陈俊俊 committed
254
    if (billProduct) {
陈俊俊's avatar
陈俊俊 committed
255
        svc.navTitle = @"编辑商品";
陈俊俊's avatar
陈俊俊 committed
256 257 258 259
        ShopDetail *shopDetail=[self coverShopDetail:billProduct];
        shopDetail.IsXiuGai=YES;
        svc.choseShopDetail = ^(ShopDetail *Detail){
            if (Detail.IsDeleted) {
260
                [_aBottomView.productVC.productArr removeObjectAtIndex:indexTag];
陈俊俊's avatar
陈俊俊 committed
261 262
            }else{
                PurchaseBillProduct *billProduct = [self coverPurchaseProduct:Detail];
263
                [_aBottomView.productVC.productArr replaceObjectAtIndex:indexTag withObject:billProduct];
陈俊俊's avatar
陈俊俊 committed
264
            }
265
            [_aBottomView.productVC.tableView reloadData];
陈俊俊's avatar
陈俊俊 committed
266 267 268 269 270
            [[NSNotificationCenter defaultCenter] postNotificationName:SetProductTotalPrice object:nil];
        };
        svc.shopDetail=shopDetail;
    }else{
        // 回调
陈俊俊's avatar
陈俊俊 committed
271
        svc.navTitle = @"添加商品";
陈俊俊's avatar
陈俊俊 committed
272 273
        svc.choseShopDetail = ^(ShopDetail *shopDetail){
            PurchaseBillProduct *billProduct = [self coverPurchaseProduct:shopDetail];
274 275
            [_aBottomView.productVC.productArr addObject:billProduct];
            [_aBottomView.productVC.tableView reloadData];
陈俊俊's avatar
陈俊俊 committed
276 277 278
            [[NSNotificationCenter defaultCenter] postNotificationName:SetProductTotalPrice object:nil];
        };
    }
Sandy's avatar
Sandy committed
279
    
陈俊俊's avatar
陈俊俊 committed
280 281 282
    svc.title = [IBTCommon localizableString:@"AddShopDetail"];
    [self PushViewController:svc animated:YES];
}
陈俊俊's avatar
陈俊俊 committed
283 284


n22's avatar
n22 committed
285
- (void)btnClick:(UIButton *)btn{
n22's avatar
n22 committed
286 287 288 289
    switch (btn.tag) {
        case SaveTag:
        {
            if ([self checkPurchase]) {
陈俊俊's avatar
陈俊俊 committed
290
                [self getDataFromServer:PURCHASE_STATE_INITIAL msg:@"正在保存..."];
n22's avatar
n22 committed
291 292 293 294
            }
        }
            break;
        case CommitTag:{
陈俊俊's avatar
陈俊俊 committed
295
            if ([self checkPurchase]) {
陈俊俊's avatar
陈俊俊 committed
296 297 298
                UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请确认提交" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
                alertView.delegate = self;
                [alertView show];
陈俊俊's avatar
陈俊俊 committed
299
            }
n22's avatar
n22 committed
300 301 302 303 304 305 306
        }
            break;
        default:
            break;
    }
}

陈俊俊's avatar
陈俊俊 committed
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
- (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
325 326 327
                    if (self.purchaseNotice) {
                        [self PopViewControllerAnimated:YES];
                    }else{
Sandy's avatar
Sandy committed
328 329 330 331
                        [[NSNotificationCenter defaultCenter] removeObserver:self name:SetProductTotalPrice object:nil];
                        [[NSNotificationCenter defaultCenter] removeObserver:self name:KNOTIFICATION_AddPurchaseProduct object:nil];
                        [[NSNotificationCenter defaultCenter] removeObserver:self name:KNOTIFICATION_AddTransportCost object:nil];
                        
陈俊俊's avatar
陈俊俊 committed
332 333 334
                        PurchaseViewController *svc = [PurchaseViewController new];
                        svc.title = @"查看采购单";
                        [self PushViewController:svc animated:YES];
Sandy's avatar
Sandy committed
335 336
                        
                        
陈俊俊's avatar
陈俊俊 committed
337
                    }
陈俊俊's avatar
陈俊俊 committed
338 339
                }
            }else{
Sandy's avatar
Sandy committed
340 341
                ShowMessage(message);
//                [IBTLoadingView showTips:message];
陈俊俊's avatar
陈俊俊 committed
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
            }
        }
    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
    };
    
    if(self.purchaseBill.uuid.length > 0 && uuidObject == [NSNull null]){
        uuidObject = self.purchaseBill.uuid;
    }
    if (self.purchaseBill.billNumber > 0 && billNumberObject == [NSNull null]) {
        billNumberObject = self.purchaseBill.billNumber;
    }
    if (self.purchaseBill && [versionObject integerValue] == 0) {
        versionObject = self.purchaseBill.version;
    }
陈俊俊's avatar
陈俊俊 committed
359 360 361 362 363 364
    if (_purchaseView.noticeUuid.length ==0 || _purchaseView.noticeNumber.length == 0) {
        if (self.purchaseBill && self.purchaseBill.noticeNumber && self.purchaseBill.noticeUuid) {
            _purchaseView.noticeUuid = self.purchaseBill.noticeUuid;
            _purchaseView.noticeNumber = self.purchaseBill.noticeNumber;
        }
    }
陈俊俊's avatar
陈俊俊 committed
365
    NSMutableArray *billProducts = [NSMutableArray array];
366
    for (PurchaseBillProduct *billProduct in _aBottomView.productVC.productArr) {        [billProducts  addObject:[billProduct dictForCommit]];
陈俊俊's avatar
陈俊俊 committed
367
    }
陈俊俊's avatar
陈俊俊 committed
368
    self.state = state;
369 370 371 372 373
    
    NSMutableArray *costs = [NSMutableArray array];
    for (FeeAcountDetail *fee in _aBottomView.costVC.costArr) {
        [costs  addObject:[fee dictForCommit]];
    }
Sandy's avatar
Sandy committed
374 375 376 377 378 379 380 381 382
    
    //获取到期时间
    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
383 384 385 386
    NSDictionary *dict = @{@"uuid":uuidObject,
                           @"version":versionObject,
                           @"billnumber":billNumberObject,
                           @"state":state,
Sandy's avatar
Sandy committed
387
                           @"expiredDate":expiredTime,
陈俊俊's avatar
陈俊俊 committed
388 389 390 391 392 393 394 395 396
                           @"type":[IBTCommon checkString:_purchaseView.type],
                           @"noticeUuid":[IBTCommon checkString:_purchaseView.noticeUuid],
                           @"noticeNumber":[IBTCommon checkString:_purchaseView.noticeNumber],
                           @"vendor_uuid":[IBTCommon checkString:_purchaseView.vendor_uuid],
                           @"vendor_code":[IBTCommon checkString:_purchaseView.vendor_code],
                           @"vendor_name":[IBTCommon checkString:_purchaseView.vendor_name],
                           @"receiveWrh_uuid":[IBTCommon checkString:_purchaseView.receiveWrh_uuid],
                           @"receiveWrh_code":[IBTCommon checkString:_purchaseView.receiveWrh_code],
                           @"receiveWrh_name":[IBTCommon checkString:_purchaseView.receiveWrh_name],
397 398 399
                           @"purchaserUuid":_purchaseView.selectPerson.userUuid,
                           @"purchaserCode":_purchaseView.selectPerson.userCode,
                           @"purchaserName":_purchaseView.selectPerson.userName,
陈俊俊's avatar
陈俊俊 committed
400 401
                           @"total":_purchaseView.total,
                           @"charge":_purchaseView.chargePurchase,
陈俊俊's avatar
陈俊俊 committed
402
                           @"remark":[IBTCommon checkString:_purchaseView.remark],
Sandy's avatar
Sandy committed
403
                           @"outSideBillNumber":[IBTCommon checkString:_purchaseView.purchaseExternal.text],
404
                           @"products":billProducts,
405
                           @"accountDetails":costs};
陈俊俊's avatar
陈俊俊 committed
406 407 408
    [IBTLoadingView showProgressLabel:msg];
    [[ICRHTTPController sharedController] savePurchaseWithData:dict success:succ failure:fail];
}
n22's avatar
n22 committed
409 410
#pragma mark - checkNull
- (BOOL)checkPurchase{
陈俊俊's avatar
陈俊俊 committed
411
    _purchaseView.remark = _purchaseView.remarkTextView.text;
412 413 414 415
    if (_purchaseView.selectPerson == nil) {
        ShowMessage(@"采购员不能为空");
        return NO;
    }
陈俊俊's avatar
陈俊俊 committed
416 417 418 419 420 421 422 423 424 425 426 427
    if (_purchaseView.type.length == 0 ) {
        ShowMessage(@"采购类型不能为空");
        return NO;
    }
    if (_purchaseView.vendor_uuid.length == 0 ) {
        ShowMessage(@"供应商不能为空");
        return NO;
    }
    if (_purchaseView.receiveWrh_uuid.length == 0 ) {
        ShowMessage(@"收货仓库不能为空");
        return NO;
    }
Sandy's avatar
Sandy committed
428
    if (_purchaseView.purchaseExternal.text.length == 0) {
Sandy's avatar
Sandy committed
429 430 431
        ShowMessage(@"外部单据号不能为空");
        return NO;
    }
432
    if (_aBottomView.productVC.productArr.count == 0) {
陈俊俊's avatar
陈俊俊 committed
433 434 435 436 437
        ShowMessage(@"采购商品不能为空");
        return NO;
    }
    if ([_purchaseView.total floatValue] < 0 || !_purchaseView.total) {
        ShowMessage(@"金额不能为空");
n22's avatar
n22 committed
438 439
        return NO;
    }
Sandy's avatar
Sandy committed
440 441 442 443 444
    
    if (_aBottomView.costVC.costArr.count == 0) {
        ShowMessage(@"请添加费用明细");
        return NO;
    }
445
    for (PurchaseBillProduct *billProduct in _aBottomView.productVC.productArr) {
陈俊俊's avatar
陈俊俊 committed
446
        if ([billProduct.qty floatValue] <= 0 || [billProduct.baseQty floatValue] <= 0) {
陈俊俊's avatar
陈俊俊 committed
447 448 449
            ShowMessage(@"有数量等于0的商品明细,请编辑后保存");
            return NO;
        }
Sandy's avatar
Sandy committed
450 451 452 453
        //        if ([billProduct.price floatValue] <=0 || [billProduct.basePrice floatValue] <= 0) {
        //            ShowMessage(@"有价格未填写的商品明细,请编辑后保存");
        //            return NO;
        //        }
陈俊俊's avatar
陈俊俊 committed
454
    }
Sandy's avatar
Sandy committed
455
    
n22's avatar
n22 committed
456
    return YES;
陈俊俊's avatar
陈俊俊 committed
457
}
n22's avatar
n22 committed
458 459


n22's avatar
n22 committed
460 461
#pragma mark - TopPurchaseViewDelegate

陈俊俊's avatar
陈俊俊 committed
462 463
- (void)pushNextViewController:(id)vc{
    [self PushViewController:vc animated:YES];
n22's avatar
n22 committed
464
}
陈俊俊's avatar
陈俊俊 committed
465 466 467
//两个类之间的转换
- (PurchaseBillProduct *)coverPurchaseProduct:(ShopDetail *)shopDetail{
    PurchaseBillProduct *billProduct = [[PurchaseBillProduct alloc]init];
陈俊俊's avatar
陈俊俊 committed
468
    billProduct.uuid = shopDetail.uuid;
陈俊俊's avatar
陈俊俊 committed
469 470 471
    billProduct.product_uuid = shopDetail.product_uuid;
    billProduct.product_code = shopDetail.product_code;
    billProduct.product_name = shopDetail.merchandise;
Sandy's avatar
Sandy committed
472
    billProduct.qpc = [NSDecimalNumber decimalNumberWithString:shopDetail.packageSpecification];
陈俊俊's avatar
陈俊俊 committed
473
    billProduct.unit = shopDetail.packageUnit;
Sandy's avatar
Sandy committed
474 475 476 477 478
    billProduct.qty = [NSDecimalNumber decimalNumberWithString:shopDetail.packageQuantity];
    billProduct.price = shopDetail.packageUnitPrice;
    billProduct.baseQty = [NSDecimalNumber decimalNumberWithString:shopDetail.foundationQuantity];
    billProduct.basePrice = shopDetail.foundationUnitPrice;
    billProduct.total = shopDetail.totalMoney;
陈俊俊's avatar
陈俊俊 committed
479
    billProduct.remark = shopDetail.remark;
陈俊俊's avatar
陈俊俊 committed
480
    billProduct.qpcStr = shopDetail.packageQpcStr ? shopDetail.packageQpcStr : @"无";
陈俊俊's avatar
陈俊俊 committed
481
    billProduct.baseUnit = shopDetail.packageQpcUnit;
Sandy's avatar
Sandy committed
482
    billProduct.vnum = shopDetail.vnum;
陈俊俊's avatar
陈俊俊 committed
483 484 485 486 487 488 489 490
    return billProduct;
}
- (ShopDetail *)coverShopDetail:(PurchaseBillProduct *)billProduct{
    ShopDetail *shopDetail = [[ShopDetail alloc]init];
    shopDetail.uuid = billProduct.uuid;
    shopDetail.product_uuid = billProduct.product_uuid;
    shopDetail.product_code = billProduct.product_code;
    shopDetail.merchandise  = billProduct.product_name;
Sandy's avatar
Sandy committed
491
    shopDetail.packageSpecification  =  [CalculateHelper getMoneyStringFrom:billProduct.qpc Lenth:0];
陈俊俊's avatar
陈俊俊 committed
492
    shopDetail.packageUnit = billProduct.unit;
Sandy's avatar
Sandy committed
493
    shopDetail.packageQuantity = [CalculateHelper getMoneyStringFrom:billProduct.qty Lenth:0];
陈俊俊's avatar
陈俊俊 committed
494
    shopDetail.packageUnitPrice  = billProduct.price;
Sandy's avatar
Sandy committed
495
    shopDetail.foundationQuantity= [CalculateHelper getMoneyStringFrom:billProduct.baseQty Lenth:0];
陈俊俊's avatar
陈俊俊 committed
496 497
    shopDetail.foundationUnitPrice= billProduct.basePrice;
    shopDetail.totalMoney= billProduct.total;
陈俊俊's avatar
陈俊俊 committed
498
    shopDetail.remark  = billProduct.remark;
陈俊俊's avatar
陈俊俊 committed
499
    shopDetail.packageQpcStr = billProduct.qpcStr;
陈俊俊's avatar
陈俊俊 committed
500
    shopDetail.packageQpcUnit = billProduct.baseUnit;
Sandy's avatar
Sandy committed
501
    shopDetail.vnum = billProduct.vnum;
陈俊俊's avatar
陈俊俊 committed
502 503
    return shopDetail;
}
陈俊俊's avatar
陈俊俊 committed
504 505 506 507
- (NSMutableArray *)coverPurchaseBillProduct:(NSArray *)arr{
    NSMutableArray *billArr = [NSMutableArray array];
    for (NoticeProduct *product in arr) {
        PurchaseBillProduct *billProduct = [PurchaseBillProduct new];
Sandy's avatar
Sandy committed
508
        //        billProduct.uuid = product.uuid;
陈俊俊's avatar
陈俊俊 committed
509 510 511
        billProduct.product_name = product.productName;
        billProduct.product_uuid  = product.productUuid;
        billProduct.product_code = product.productCode;
陈俊俊's avatar
陈俊俊 committed
512
        billProduct.baseUnit = product.baseUnit;
陈俊俊's avatar
陈俊俊 committed
513 514 515 516 517 518 519
        billProduct.qpc = product.qpc;
        billProduct.unit = product.packUnit;
        billProduct.qty = [NSNumber numberWithFloat:0];
        billProduct.price = [NSNumber numberWithFloat:0];
        billProduct.baseQty = [NSNumber numberWithFloat:0];
        billProduct.basePrice = [NSNumber numberWithFloat:0];
        billProduct.total = [NSNumber numberWithFloat:0];
陈俊俊's avatar
陈俊俊 committed
520
        billProduct.remark = @"";
陈俊俊's avatar
陈俊俊 committed
521
        billProduct.qpcStr = [NSString stringWithFormat:@"1*%@",product.qpc];
陈俊俊's avatar
陈俊俊 committed
522 523 524 525
        [billArr addObject:billProduct];
    }
    return billArr;
}
n22's avatar
n22 committed
526

n22's avatar
n22 committed
527 528 529 530 531
#pragma mark - 协议方法
- (void)hiddenKeyBoard{
    [self keyboardHidden];
}
- (void)keyboardHidden{
n22's avatar
n22 committed
532
    [_purchaseView.otherPriceFiled resignFirstResponder];
n22's avatar
n22 committed
533 534
    [_purchaseView.remarkTextView resignFirstResponder];
}
陈俊俊's avatar
陈俊俊 committed
535

陈俊俊's avatar
陈俊俊 committed
536 537 538 539 540 541
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 1) {
        [self getDataFromServer:PURCHASE_STATE_SUBMITTED msg:@"正在提交..."];//提交
    }
}

n22's avatar
n22 committed
542 543 544 545 546 547
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
Sandy's avatar
Sandy committed
548 549 550 551 552 553 554 555
 #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.
 }
 */
n22's avatar
n22 committed
556 557

@end