package com.yem.wm.im.orderproreqbill.validator;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.ExtendedDataEntity;
import kd.bos.entity.validate.AbstractValidator;

public class OrderProReqBillSubmitValidator extends AbstractValidator {
    @Override
    public void validate() {
        ExtendedDataEntity[] dataEntities = this.getDataEntities();
        long inwhid = 0l;
        long outwhid = 0l;
        for (ExtendedDataEntity dataEntity : dataEntities) {
            //配件调拨计划，正常仓库
            //分录调入调出仓库分别一致
            DynamicObject obj = dataEntity.getDataEntity();
            String billtype = obj.getString("yem_billtype.number");
            String yem_isvmi = obj.getString("yem_isvmi");
            if ("yem_orderproreqbill_DB".equals(billtype) && "C".equals(yem_isvmi)) {
                DynamicObjectCollection maEntrys = obj.getDynamicObjectCollection("yem_es_materialinfo");
                for (DynamicObject maEntry : maEntrys) {
                    if (outwhid == 0l) {
                        outwhid = maEntry.getLong("yem_warehouse.id");
                    } else {
                        if(outwhid!=maEntry.getLong("yem_warehouse.id")){
                            this.addErrorMessage(dataEntity, "分录中调出仓库不一致，提交失败！");
                        }
                    }
                    if (inwhid == 0l) {
                        inwhid = maEntry.getLong("yem_outwhcode.id");
                    } else {
                        if(inwhid!=maEntry.getLong("yem_outwhcode.id")){
                            this.addErrorMessage(dataEntity, "分录中调入仓库不一致，提交失败！");
                        }
                    }
                }
            }
        }
    }
}
