package com.yem.wm.es.shippingdetails.op;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.args.EndOperationTransactionArgs;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;

/**
 * @author power
 * @ClassName
 * @description: 出运明细单 反审核
 * @date 2023/10/18
 */
public class ShippingDetailsUnAuditOp extends AbstractOperationServicePlugIn {
    @Override
    public void endOperationTransaction(EndOperationTransactionArgs e) {
        super.endOperationTransaction(e);
        DynamicObject[] dataEntities = e.getDataEntities();
        for(DynamicObject dataEntitie : dataEntities){
            dataEntitie = BusinessDataServiceHelper.loadSingle(dataEntitie.getPkValue(),dataEntitie.getDynamicObjectType().getName());
            uncollect(dataEntitie);
            removeArrearsAmt(dataEntitie);
            SaveServiceHelper.save(new DynamicObject[] {dataEntitie});
        }
    }


    /**
     * @description 审核时生成出运汇总分录
     * @author power
     * @time 2023/9/27
     */
    public void uncollect(DynamicObject dataEntitie) {
        DynamicObjectCollection collects = dataEntitie.getDynamicObjectCollection("yem_es_salesorder_total");
        int j = collects.size();
        if (collects!=null){
            for (int i = 0; i <j ; i++) {
                collects.remove(0);
            }

        }
    }


    public void removeArrearsAmt(DynamicObject dataEntitie){
        dataEntitie.set("yem_arrearsamt",null);
        dataEntitie.set("yem_arrearsamtapply",null);
    }
}
