eas之MrpUI
package com.kingdee.eas.custom.mrp.client;
import java.awt.Component;
import java.awt.event.*;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.swing.JLabel;
import org.apache.log4j.Logger;
import com.kingdee.bos.BOSException;
import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemInfo;
import com.kingdee.bos.metadata.query.util.CompareType;
import com.kingdee.bos.ui.face.CoreUIObject;
import com.kingdee.bos.appframework.syncUI.ThreadPool;
import com.kingdee.bos.ctrl.extendcontrols.KDBizPromptBox;
import com.kingdee.bos.ctrl.swing.event.SelectorEvent;
import com.kingdee.bos.ctrl.swing.event.SelectorListener;
import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.eas.base.permission.client.longtime.ILongTimeTask;
import com.kingdee.eas.base.permission.client.longtime.LongTimeDialog;
import com.kingdee.eas.base.permission.client.util.UITools;
import com.kingdee.eas.basedata.assistant.MeasureUnitInfo;
import com.kingdee.eas.basedata.master.material.MaterialInfo;
import com.kingdee.eas.basedata.master.material.MaterialProvideTypeEnum;
import com.kingdee.eas.basedata.org.AdminOrgUnitInfo;
import com.kingdee.eas.basedata.org.StorageOrgUnitInfo;
import com.kingdee.eas.basedata.scm.common.BillTypeInfo;
import com.kingdee.eas.basedata.scm.common.BizTypeInfo;
import com.kingdee.eas.basedata.scm.im.inv.WarehouseInfo;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.common.client.SysContext;
import com.kingdee.eas.custom.mrp.DemandPlanEntryCollection;
import com.kingdee.eas.custom.mrp.DemandPlanEntryInfo;
import com.kingdee.eas.custom.mrp.DemandPlanInfo;
import com.kingdee.eas.custom.mrp.DemandPlanState;
import com.kingdee.eas.custom.mrp.KCZYDEntryInfo;
import com.kingdee.eas.custom.mrp.KCZYDInfo;
import com.kingdee.eas.custom.mrp.MrpZylx;
import com.kingdee.eas.custom.mrp.PlannedWorkbenchEntry;
import com.kingdee.eas.custom.mrp.PlannedWorkbenchEntryDEntryInfo;
import com.kingdee.eas.custom.mrp.PlannedWorkbenchEntryInfo;
import com.kingdee.eas.custom.mrp.PlannedWorkbenchInfo;
import com.kingdee.eas.custom.mrp.SupplyRelationshipInfo;
import com.kingdee.eas.custom.mrp.WGJZYKCBSZBInfo;
import com.kingdee.eas.mm.basedata.BomEntryCollection;
import com.kingdee.eas.mm.basedata.BomEntryInfo;
import com.kingdee.eas.mm.basedata.BomInfo;
import com.kingdee.eas.mm.basedata.PlanVersionSetInfo;
import com.kingdee.eas.mm.common.MMBaseStatusEnum;
import com.kingdee.eas.mm.planning.PlannedOrderEntryInfo;
import com.kingdee.eas.mm.planning.PlannedOrderFactory;
import com.kingdee.eas.mm.planning.PlannedOrderInfo;
import com.kingdee.eas.mm.planning.PlannedOrderTypeEnum;
import com.kingdee.eas.mm.project.ProjectFactory;
import com.kingdee.eas.mm.project.ProjectInfo;
import com.kingdee.eas.scm.common.BillBaseStatusEnum;
import com.kingdee.eas.scm.im.inv.InventoryInfo;
import com.kingdee.eas.scm.im.inv.MatAttrChangeAfterEntryInfo;
import com.kingdee.eas.scm.im.inv.MatAttrChangeBeforeEntryInfo;
import com.kingdee.eas.scm.im.inv.MatAttrChangeBillFactory;
import com.kingdee.eas.scm.im.inv.MatAttrChangeBillInfo;
import com.kingdee.eas.scm.sm.pur.PurOrderEntryInfo;
import com.kingdee.eas.util.SysUtil;
import com.kingdee.eas.util.client.MsgBox;
import com.kingdee.jhf.util.BomUtil;
import com.kingdee.jhf.util.KingdeeUtils;
import com.kingdee.jhf.util.SupplyOrgUtil;
@SuppressWarnings("serial")
public class MrpUI extends AbstractMrpUI {
@SuppressWarnings("unused")
private static final Logger logger = CoreUIObject.getLogger(MrpUI.class);
//计划员工作台 -- 创建单据
private PlannedWorkbenchInfo plannedWorkbenchInfo = null;
//计划员工作台 -- 分录1
private PlannedWorkbenchEntryInfo plannedWorkbenchEntryInfo = null;
public MrpUI() throws Exception {
super();
}
public void storeFields() {
super.storeFields();
}
@Override
public void onLoad() throws Exception {
super.onLoad();
// 供应关系F7
this.kDBizPromptBox2.addSelectorListener(new SelectorListener() {
@Override
public void willShow(SelectorEvent e) {
KDBizPromptBox f7 = (KDBizPromptBox) e.getSource();
StorageOrgUnitInfo storageOrgUnitInfo = (StorageOrgUnitInfo) kDBizPromptBox1.getValue();
if (storageOrgUnitInfo != null) {
List<FilterItemInfo> list = new ArrayList<FilterItemInfo>();
list.add(new FilterItemInfo("state", "001", CompareType.EQUALS));
list.add(new FilterItemInfo("JHZZ.id", storageOrgUnitInfo.getId().toString(), CompareType.EQUALS));
f7init(f7, list);
} else {
MsgBox.showWarning("请先选择计划组织");
SysUtil.abort();
}
}
});
// 需求计划F7
List<FilterItemInfo> list = new ArrayList<FilterItemInfo>();
list.add(new FilterItemInfo("State", DemandPlanState.APPROVAL_VALUE, CompareType.EQUALS));
f7init(this.kDBizPromptBox3, list);
//计划组织
List<FilterItemInfo> list1 = new ArrayList<FilterItemInfo>();
list1.add(new FilterItemInfo("number", "01", CompareType.NOTEQUALS));
f7init(this.kDBizPromptBox1, list1);
this.kDBizPromptBox1.setValue(SysContext.getSysContext().getCurrentStorageUnit());
this.kDBizPromptBox2.setValue(this.getSupplyRelationship());
}
/**
* 获取默认的供应关系
* @return
*/
private SupplyRelationshipInfo getSupplyRelationship() {
StringBuilder sql = new StringBuilder();
sql.append(" select FID from CT_MRP_SupplyRelationship ");
sql.append(" where CFState = '001' ");
sql.append(" and CFJHZZID = '" + SysContext.getSysContext().getCurrentStorageUnit().getId() + "' ");
sql.append(" and CFDefaultNew = '001' ");
Object object = KingdeeUtils.returnOneData(sql.toString());
if (object != null) {
return (SupplyRelationshipInfo) KingdeeUtils.getInfo(object.toString());
} else {
return null;
}
}
/**
* 设置单据头F7
* @param F7
* @param list
*/
private void f7init(KDBizPromptBox F7, List<FilterItemInfo> list) {
// 过滤条件
FilterInfo filter = new FilterInfo();
// 条件
for (FilterItemInfo filterItemInfo : list) {
filter.getFilterItems().add(filterItemInfo);
}
// 绑定条件
EntityViewInfo view = new EntityViewInfo();
view.setFilter(filter);
// F7重新设定视图
F7.setEntityViewInfo(view);
F7.getQueryAgent().resetRuntimeEntityView();
F7.setRefresh(true);
}
/**
* 开始计算
*/
public void actionMRP_actionPerformed(ActionEvent e) throws Exception {
LongTimeDialog dialog = UITools.getDialog(this);
dialog.setLongTimeTask(new ILongTimeTask() {
public Object exec() throws Exception {
return strat();
}
public void afterExec(Object result) throws Exception {
MsgBox.showWarning(result.toString());
ThreadPool.destroyMonitor();
}
});
Component[] cps = dialog.getContentPane().getComponents();
for (Component cp : cps) {
if (cp instanceof JLabel) {
((JLabel) cp).setText("MRP运算中.......");
}
}
dialog.show();
}
private PlannedWorkbenchInfo setPlannedWorkbenchInfo(ProjectInfo projectInfo) {
PlannedWorkbenchInfo plannedWorkbenchInfo = new PlannedWorkbenchInfo();
//单据编号
Object object = KingdeeUtils.returnOneData("select MAX(TO_INT(SUBSTRING(FNumber,13,LEN(FNumber)))) from CT_MRP_PlannedWorkbench where FNumber like 'AUTO-SYSTEM-%'");
Integer index = Integer.parseInt(object == null ? "0" : object.toString()) + 1;
plannedWorkbenchInfo.setNumber("AUTO-SYSTEM-" + index);
//项目号
plannedWorkbenchInfo.setProject(projectInfo);
return plannedWorkbenchInfo;
}
private PlannedWorkbenchEntryInfo setPlannedWorkbenchEntryInfo(BomUtil bomUtil) {
PlannedWorkbenchEntryInfo plannedWorkbenchEntryInfo = new PlannedWorkbenchEntryInfo();
//物料
plannedWorkbenchEntryInfo.setMateriel(bomUtil.getMaterial());
//物料名称
plannedWorkbenchEntryInfo.setMaterielName(bomUtil.getMaterial().getName());
return plannedWorkbenchEntryInfo;
}
private void setPlannedWorkbenchEntryDEntryInfo(String field1, String field2, String field3, BigDecimal field4, BigDecimal field5) {
PlannedWorkbenchEntryDEntryInfo plannedWorkbenchEntryDEntryInfo = new PlannedWorkbenchEntryDEntryInfo();
//运算点
plannedWorkbenchEntryDEntryInfo.setField1(field1);
//库存组织
plannedWorkbenchEntryDEntryInfo.setField2(field2);
//仓库
plannedWorkbenchEntryDEntryInfo.setField3(field3);
//占用数量
plannedWorkbenchEntryDEntryInfo.setField4(field4);
//锁定数量
plannedWorkbenchEntryDEntryInfo.setField5(field5);
this.plannedWorkbenchEntryInfo.getDEntrys().add(plannedWorkbenchEntryDEntryInfo);
}
/**
* 开始计算-逻辑方法
*/
public String strat() {
//需求计划
DemandPlanInfo demandPlanInfo = (DemandPlanInfo) this.kDBizPromptBox3.getValue();
//供货定义
SupplyRelationshipInfo supplyRelationshipInfo = (SupplyRelationshipInfo) this.kDBizPromptBox2.getValue();
//计划组织
StorageOrgUnitInfo storageOrgUnitInfo = (StorageOrgUnitInfo) this.kDBizPromptBox1.getValue();
//判断为空
if (demandPlanInfo == null) {
return "需求计划不能为空";
}
if (supplyRelationshipInfo == null) {
return "供货关系不能为空";
}
if (storageOrgUnitInfo == null) {
return "计划组织不能为空";
}
//部门
AdminOrgUnitInfo adminOrgUnitInfo = demandPlanInfo.getDepartment();
//获取需求计划分录集合
DemandPlanEntryCollection collection = demandPlanInfo.getEntrys();
//遍历需求计划分录
for (int i = 0; i < collection.size(); i++) {
//需求计划分录info
DemandPlanEntryInfo EntryInfo = collection.get(i);
//项目号关闭直接退出运算
if (this.isProjectColse(EntryInfo)) {
return "项目号已关闭,退出运算";
}
//获取当前主物料的【BOM】
BomInfo bomInfo = this.getBomInfo(EntryInfo);
//获取不到BOM直接退出
if (bomInfo == null) {
return "无法获取订单BOM";
}
//根据【BOM】,获取主物料和子物料的毛需求
List<BomUtil> BomUtilList = this.getMaterialInfo(bomInfo, EntryInfo);
//无物料清单直接退出运算
if (BomUtilList == null) {
return "该物料无订单BOM";
}
//计划员工作台 -- 创建单据
this.plannedWorkbenchInfo = this.setPlannedWorkbenchInfo(EntryInfo.getProjectNumber());
//清除旧计划订单
this.del_PlannedOrder(EntryInfo.getProjectNumber(), storageOrgUnitInfo);
//遍历物料毛需求
for (BomUtil bomUtil : BomUtilList) {
//计划员工作台 -- 分录1
this.plannedWorkbenchEntryInfo = this.setPlannedWorkbenchEntryInfo(bomUtil);
//判断物料是否多发
if (!this.isMaterialMany(bomUtil, EntryInfo.getProjectNumber())) {
continue;
}
//是否满足需求
if (this.isCompare(bomUtil)) {
continue;
}
//计划订单使用
SupplyOrgUtil org = null;
//获取【供应关系定义】
List<SupplyOrgUtil> SupplyOrgList = this.getSupplyOrgs(supplyRelationshipInfo);
//删除类型为【MRP占用】的【库存占用单】
this.delKCZYD(EntryInfo.getProjectNumber(), bomUtil, SupplyOrgList);
//遍历【供应关系定义】中的【库存组织】
for (SupplyOrgUtil supplyOrgUtil : SupplyOrgList) {
//获取库存组织-计划订单用
if (supplyOrgUtil.getStorageOrgUnitInfo().getId().equals(storageOrgUnitInfo.getId())) {
org = supplyOrgUtil;
}
//根据库存组织获取【物料属性】
Integer materialProperties = this.isMaterialProperties(bomUtil, supplyOrgUtil);
if (materialProperties == null) {
return "无法获取【" + supplyOrgUtil.getStorageOrgUnitInfo().getName() + "】的计划资料";
} else {
bomUtil.setMaterialPropertie(materialProperties);
}
//查询【外购件占用库存比设置表】
WGJZYKCBSZBInfo wgjzykcbszbInfo = this.getWGJZYKCBSZBInfo(bomUtil.getMaterial(), supplyOrgUtil);
if (wgjzykcbszbInfo == null) {
/**无【外购件占用库存比设置表】*/
/*--------------运算库存--------------*/
this.MRP_Inventory(bomUtil, supplyOrgUtil, EntryInfo, adminOrgUnitInfo);
/*--------------运算采购在途-----------*/
if (!this.isCompare(bomUtil)) {
this.MRP_Purchase(bomUtil, supplyOrgUtil, EntryInfo);
}
} else {
/**有【外购件占用库存比设置表】*/
if (bomUtil.getDemandQty_1().compareTo(wgjzykcbszbInfo.getKCCGJS().multiply(wgjzykcbszbInfo.getBL().divide(new BigDecimal(100)))) <= 0) {
/**小于,等于*/
/*--------------运算库存--------------*/
this.MRP_Inventory(bomUtil, supplyOrgUtil, EntryInfo, adminOrgUnitInfo);
/*--------------运算采购在途-----------*/
if (!this.isCompare(bomUtil)) {
this.MRP_Purchase(bomUtil, supplyOrgUtil, EntryInfo);
}
} else {
/**大于*/
//查询库存占用单
this.isKczyd(bomUtil, EntryInfo.getProjectNumber());
//是否满足需求
if (!this.isCompare(bomUtil)) {
//判断物料属性,条件【库存组织】
if (bomUtil.getMaterialPropertie() == 10050) {
/**委外件*/
//查询委外在途
this.isSubContractOrderQty(bomUtil, EntryInfo.getProjectNumber(), supplyOrgUtil);
} else {
/**外购件*/
//查询采购在途
this.isPurOrderQty(bomUtil, EntryInfo.getProjectNumber(), supplyOrgUtil);
}
}
}
}
}
//是否满足需求
if (!this.isCompare(bomUtil)) {
/**不满足需求*/
//生成计划订单
this.AutoTO_PlannedOrder(bomUtil, org, EntryInfo, storageOrgUnitInfo, demandPlanInfo, bomInfo, adminOrgUnitInfo);
}
}
}
this.plannedWorkbenchInfo.getEntrys().add(this.plannedWorkbenchEntryInfo);
KingdeeUtils.addnew(this.plannedWorkbenchInfo.getBOSType(), this.plannedWorkbenchInfo);
return "运算结束!";
}
/**
* MRP运算-采购在途
* @param bomUtil
* @param supplyOrgUtil
* @param EntryInfo
*/
private void MRP_Purchase(BomUtil bomUtil, SupplyOrgUtil supplyOrgUtil, DemandPlanEntryInfo EntryInfo) {
//判断物料属性,条件【库存组织】
if (bomUtil.getMaterialPropertie() == 10050) {
/**委外件*/
this.isSubContractOrderQty(bomUtil, EntryInfo.getProjectNumber(), supplyOrgUtil);
} else {
/**外购件*/
if (bomUtil.isSpecialMaterial()) {
/**通用料*/
this.isPurOrderQty2(bomUtil, EntryInfo.getProjectNumber(), supplyOrgUtil);
if (!this.isCompare(bomUtil)) {
/**不满足需求*/
//采购拆分恢复
this.recoveryPurchase(supplyOrgUtil, EntryInfo.getProjectNumber(), bomUtil);
//查询通用料的采购在途
List<PurOrderEntryInfo> PurOrderEntryInfoList = this.isPurOrder(supplyOrgUtil, bomUtil, EntryInfo.getProjectNumber());
if (PurOrderEntryInfoList.size() != 0) {
/**有采购在途*/
//采购在途拆分
this.PurSplit(PurOrderEntryInfoList, bomUtil, EntryInfo.getProjectNumber());
}
}
} else {
/**专用料*/
//查询专用料的采购在途,并减少需求数量
this.isPurOrderQty(bomUtil, EntryInfo.getProjectNumber(), supplyOrgUtil);
}
}
}
/**
* MRP运算-库存
* @param bomUtil
* @param supplyOrgUtil
* @param EntryInfo
* @param adminOrgUnitInfo
*/
private void MRP_Inventory(BomUtil bomUtil, SupplyOrgUtil supplyOrgUtil, DemandPlanEntryInfo EntryInfo, AdminOrgUnitInfo adminOrgUnitInfo) {
//通用料、专用料判断
if (bomUtil.isSpecialMaterial()) {
/**通用料*/
List<Object[]> InventoryList = this.isInventory_Currency(bomUtil, supplyOrgUtil);
if (InventoryList.size() > 0) {
//填充库存占用
this.AutoTO_Kczyd(InventoryList, bomUtil, EntryInfo.getProjectNumber(), supplyOrgUtil);
}
} else {
/**专用料*/
List<InventoryInfo> InventoryList = this.isInventory_Special(bomUtil, supplyOrgUtil);
if (InventoryList.size() > 0) {
//生成形态转换单
this.AutoTO_MatAttrChangeBill(InventoryList, bomUtil, EntryInfo.getProjectNumber(), adminOrgUnitInfo);
}
//是否满足需求
if (!this.isCompare(bomUtil)) {
//查询当前项目号的库存,并减少需求数量,呆滞料除外
this.isInventoryQty(bomUtil, EntryInfo.getProjectNumber(), supplyOrgUtil);
}
}
}
/**
* 判断物料是否多发
* @param bomUtil
* @param projectInfo
* @return
*/
private boolean isMaterialMany(BomUtil bomUtil, ProjectInfo projectInfo) {
BigDecimal number = new BigDecimal(0);
StringBuilder sb = new StringBuilder();
sb.append(" select SUM(b.CFReleaseQty) from CT_MRP_KCZYD a ");
sb.append(" inner join CT_MRP_KCZYDEntry b on (b.FParentID = a.FID) ");
sb.append(" where b.CFMaterielID = '" + bomUtil.getMaterial().getId() + "' ");
sb.append(" and a.CFProjectID = '" + projectInfo.getId() + "' ");
Object object = KingdeeUtils.returnOneData(sb.toString());
if (object != null) {
number = new BigDecimal(object.toString());
}
this.setPlannedWorkbenchEntryDEntryInfo("库存占用单", null, null, number, number);
this.NumberReset(bomUtil, number, true);
if (bomUtil.getDemandQty_1().compareTo(number) < 0) {
return false;
} else {
return true;
}
}
/**
* 项目号关闭直接退出运算
* @param EntryInfo
* @return
*/
private boolean isProjectColse(DemandPlanEntryInfo EntryInfo) {
ProjectInfo projectInfo = (ProjectInfo) KingdeeUtils.getInfo(EntryInfo.getProjectNumber().getId().toString());
if (projectInfo.getBaseStatus().equals(MMBaseStatusEnum.CLOSED)) {
return true;
} else {
return false;
}
}
/**
* 查询委外在途,并减少需求数量
* @param bomUtil
* @param projectInfo
* @param supplyOrgUtil
*/
private void isSubContractOrderQty(BomUtil bomUtil, ProjectInfo projectInfo, SupplyOrgUtil supplyOrgUtil) {
BigDecimal number = new BigDecimal(0);
//委外订单
StringBuilder sql = new StringBuilder();
sql.append(" select sum(b.FQty - b.FTotalReceiptQty) from T_SM_SubContractOrderEntry b");
sql.append(" inner join T_SM_SubContractOrder a on (a.fid = b.fparentid) ");
sql.append(" where b.FReceiveOrgUnitID = '" + supplyOrgUtil.getStorageOrgUnitInfo().getId() + "' ");
sql.append(" and b.FProjectID = '" + projectInfo.getId() + "' ");
sql.append(" and b.FMaterialID = '" + bomUtil.getMaterial().getId() + "' ");
sql.append(" and a.FBaseStatus = 4 ");
sql.append(" and a.FBizTypeID = '1x7KMBq4mUmpj58T4jNPqiQHQ1w=' ");
Object object = KingdeeUtils.returnOneData(sql.toString());
if (object != null) {
BigDecimal count = new BigDecimal(object.toString());
number = count.add(number);
}
//运算过程
this.setPlannedWorkbenchEntryDEntryInfo("委外订单", null, null, number, number);
//委外申请单
sql = new StringBuilder();
sql.append(" select sum(b.FRequestQty - b.FOrderedQty) from T_SM_PurRequestEntry b ");
sql.append(" inner join T_SM_PurRequest a on(a.fid = b.fparentid) ");
sql.append(" where a.FDemandTypeID = 'KmuTezpYRpyN6uBe04rD6qvcMAg=' ");
sql.append(" and a.FBizTypeID = '1x7KMBq4mUmpj58T4jNPqiQHQ1w=' ");
sql.append(" and a.FBaseStatus = 4 ");
sql.append(" and b.FReceivedOrgUnitID = '" + supplyOrgUtil.getStorageOrgUnitInfo().getId() + "' ");
sql.append(" and b.FProjectID = '" + projectInfo.getId() + "' ");
sql.append(" and b.FMaterialID = '" + bomUtil.getMaterial().getId() + "' ");
object = KingdeeUtils.returnOneData(sql.toString());
if (object != null) {
BigDecimal count = new BigDecimal(object.toString());
number = count.add(number);
}
//重置物料需求数量
this.NumberReset(bomUtil, number, true);
//运算过程
this.setPlannedWorkbenchEntryDEntryInfo("委外申请单", null, null, number, number);
}
/**
* 查询专用料的采购在途,并减少需求数量
* @param bomUtil
* @param projectInfo
* @param supplyOrgUtil
*/
private void isPurOrderQty(BomUtil bomUtil, ProjectInfo projectInfo, SupplyOrgUtil supplyOrgUtil) {
BigDecimal number = new BigDecimal(0);
//采购订单
StringBuilder sb = new StringBuilder();
sb.append(" select sum(b.fqty - b.FTotalReceiptQty) from T_SM_PurOrderEntry b");
sb.append(" inner join T_SM_PurOrder a on (a.fid = b.fparentid) ");
sb.append(" where b.FStorageOrgUnitID = '" + supplyOrgUtil.getStorageOrgUnitInfo().getId() + "' ");
sb.append(" and b.FMaterialID = '" + bomUtil.getMaterial().getId() + "' ");
sb.append(" and a.FBaseStatus = 4 ");
sb.append(" and a.FBizTypeID = 'd8e80652-0106-1000-e000-04c5c0a812202407435C' ");
sb.append(" and b.FProjectID = '" + projectInfo.getId() + "' ");
Object object = KingdeeUtils.returnOneData(sb.toString());
if (object != null) {
BigDecimal count = new BigDecimal(object.toString());
number = count.add(number);
}
//运算过程
this.setPlannedWorkbenchEntryDEntryInfo("采购订单", supplyOrgUtil.getStorageOrgUnitInfo().getName(), null, number, number);
//采购申请单
sb = new StringBuilder();
sb.append(" select sum(b.FRequestQty - b.FOrderedQty) from T_SM_PurRequestEntry b ");
sb.append(" inner join T_SM_PurRequest a on(a.fid = b.fparentid) ");
sb.append(" where a.FDemandTypeID = 'hRIIQbTqTLaxKNAJnYwWbqvcMAg=' ");
sb.append(" and a.FBizTypeID = 'd8e80652-0106-1000-e000-04c5c0a812202407435C' ");
sb.append(" and a.FBaseStatus = 4 ");
sb.append(" and b.FReceivedOrgUnitID = '" + supplyOrgUtil.getStorageOrgUnitInfo().getId() + "' ");
sb.append(" and b.FMaterialID = '" + bomUtil.getMaterial().getId() + "' ");
sb.append(" and b.FProjectID = '" + projectInfo.getId() + "' ");
object = KingdeeUtils.returnOneData(sb.toString());
if (object != null) {
BigDecimal count = new BigDecimal(object.toString());
number = count.add(number);
}
//重置物料需求数量
this.NumberReset(bomUtil, number, true);
//运算过程
this.setPlannedWorkbenchEntryDEntryInfo("采购申请单", supplyOrgUtil.getStorageOrgUnitInfo().getName(), null, number, number);
}
/**
* 查询通用料的采购在途,并减少需求数量
* @param bomUtil
* @param projectInfo
* @param supplyOrgUtil
*/
private void isPurOrderQty2(BomUtil bomUtil, ProjectInfo projectInfo, SupplyOrgUtil supplyOrgUtil) {
BigDecimal number = new BigDecimal(0);
//采购申请单
StringBuilder sb = new StringBuilder();
sb.append(" select sum(b.FRequestQty - b.FOrderedQty) from T_SM_PurRequestEntry b ");
sb.append(" inner join T_SM_PurRequest a on(a.fid = b.fparentid) ");
sb.append(" where a.FDemandTypeID = 'hRIIQbTqTLaxKNAJnYwWbqvcMAg=' ");
sb.append(" and a.FBizTypeID = 'd8e80652-0106-1000-e000-04c5c0a812202407435C' ");
sb.append(" and a.FBaseStatus = 4 ");
sb.append(" and b.FReceivedOrgUnitID = '" + supplyOrgUtil.getStorageOrgUnitInfo().getId() + "' ");
sb.append(" and b.FMaterialID = '" + bomUtil.getMaterial().getId() + "' ");
sb.append(" and b.FRemark = '" + projectInfo.getId() + "' ");
Object object = KingdeeUtils.returnOneData(sb.toString());
if (object != null) {
BigDecimal count = new BigDecimal(object.toString());
number = count.add(number);
}
//重置物料需求数量
this.NumberReset(bomUtil, number, true);
//运算过程
this.setPlannedWorkbenchEntryDEntryInfo("采购申请单", supplyOrgUtil.getStorageOrgUnitInfo().getName(), null, number, number);
}
/**
* 查询库存,并减少需求数量,呆滞料除外
* @param bomUtil
* @param projectInfo
* @param supplyOrgUtil
*/
private void isInventoryQty(BomUtil bomUtil, ProjectInfo projectInfo, SupplyOrgUtil supplyOrgUtil) {
BigDecimal number = new BigDecimal(0);
StringBuilder sb = new StringBuilder();
sb.append(" select sum(FCurStoreQty) from T_IM_Inventory ");
sb.append(" where FStorageOrgUnitID = '" + supplyOrgUtil.getStorageOrgUnitInfo().getId() + "' ");
sb.append(" and FMaterialID = '" + bomUtil.getMaterial().getId() + "' ");
sb.append(" and FProjectID = '" + projectInfo.getId() + "' ");
sb.append(" and FCurStoreQty > 0 ");
sb.append(" and FStoreStatusID = '181875d5-0105-1000-e000-012ec0a812fd62A73FA5' ");
sb.append(" order by TO_INT(SUBSTRING(flot,LEN(flot)-2,LEN(flot))),CONVERT(DATETIME,SUBSTRING(flot,0,LEN(flot)-4)) ");
Object object = KingdeeUtils.returnOneData(sb.toString());
if (object != null) {
BigDecimal count = new BigDecimal(object.toString());
number = count.add(number);
}
if (number.compareTo(bomUtil.getDemandQty_2()) >= 0) {
number = bomUtil.getDemandQty_2();
}
//重置物料需求数量
this.NumberReset(bomUtil, number, true);
//运算过程
this.setPlannedWorkbenchEntryDEntryInfo("库存", supplyOrgUtil.getStorageOrgUnitInfo().getName(), null, number, number);
}
/**
* 查询库存占用单,并减少需求数量
* @param bomUtil
* @param projectInfo
*/
private void isKczyd(BomUtil bomUtil, ProjectInfo projectInfo) {
BigDecimal number = new BigDecimal(0);
StringBuilder sb = new StringBuilder();
sb.append(" select sum(cfzysl) from CT_MRP_KCZYD ");
sb.append(" where CFZYXMID = '" + projectInfo.getId() + "' ");
sb.append(" and CFWLID = '" + bomUtil.getMaterial().getId() + "' ");
sb.append(" and CFZYLX = '" + MrpZylx.B_VALUE + "'");
Object object = KingdeeUtils.returnOneData(sb.toString());
if (object != null) {
BigDecimal count = new BigDecimal(object.toString());
number = count.add(number);
}
bomUtil.setDemandQty_2(bomUtil.getDemandQty_2().subtract(number).compareTo(new BigDecimal(0)) > 0 ? bomUtil.getDemandQty_2().subtract(number) : new BigDecimal(0));
MaterialInfo materialInfo = (MaterialInfo) KingdeeUtils.getInfo(bomUtil.getMaterial().getId().toString());
MeasureUnitInfo measureUnitInfo = (MeasureUnitInfo) KingdeeUtils.getInfo(materialInfo.getBaseUnit().getId().toString());
bomUtil.setBasicDemandQty_2(bomUtil.getDemandQty_2().multiply(measureUnitInfo.getCoefficient()));
//运算过程
this.setPlannedWorkbenchEntryDEntryInfo("库存占用单", null, null, number, number);
}
/**
* 采购拆分恢复
* @param supplyOrgUtil
* @param projectInfo
* @param bomUtil
*/
private void recoveryPurchase(SupplyOrgUtil supplyOrgUtil, ProjectInfo projectInfo, BomUtil bomUtil) {
List<PurOrderEntryInfo> PurOrderEntryInfoList = new ArrayList<PurOrderEntryInfo>();
StringBuilder sb = new StringBuilder();
sb.append(" select b.fid from T_SM_PurOrderEntry b ");
sb.append(" inner join T_SM_PurOrder a on (a.fid = b.fparentid) ");
sb.append(" where b.FStorageOrgUnitID = '" + supplyOrgUtil.getStorageOrgUnitInfo().getId() + "' ");
sb.append(" and a.FBizTypeID = 'd8e80652-0106-1000-e000-04c5c0a812202407435C' ");
sb.append(" and b.FMaterialID = '" + bomUtil.getMaterial().getId() + "' ");
sb.append(" and b.FRemark like '" + projectInfo.getId() + "%' ");
sb.append(" and (b.FProjectID = '' or b.FProjectID is null) ");
sb.append(" and a.FBaseStatus = 4 ");
List<Object[]> values = KingdeeUtils.executeSQL(sb.toString());
for (Object[] objects : values) {
for (Object object : objects) {
if (object != null) {
PurOrderEntryInfoList.add((PurOrderEntryInfo) KingdeeUtils.getInfo(object.toString()));
}
}
}
for (PurOrderEntryInfo purOrderEntryInfo : PurOrderEntryInfoList) {
String[] id = purOrderEntryInfo.getRemark().split(",");
if (id.length == 2) {
PurOrderEntryInfo purOrderEntryInfo_Old = (PurOrderEntryInfo) KingdeeUtils.getInfo(id[1]);
//订货数量
purOrderEntryInfo_Old.setQty(purOrderEntryInfo.getQty().add(purOrderEntryInfo_Old.getQty()));
//基本订货数量
MeasureUnitInfo measureUnitInfo = (MeasureUnitInfo) KingdeeUtils.getInfo(purOrderEntryInfo_Old.getBaseUnit().getId().toString());
purOrderEntryInfo_Old.setBaseQty(purOrderEntryInfo_Old.getQty().multiply(measureUnitInfo.getCoefficient()));
//金额=订货数量*单价
purOrderEntryInfo_Old.setAmount(purOrderEntryInfo_Old.getQty().multiply(purOrderEntryInfo_Old.getPrice()));
//本位币金额=订货数量*单价
purOrderEntryInfo_Old.setLocalAmount(purOrderEntryInfo_Old.getQty().multiply(purOrderEntryInfo_Old.getPrice()));
//价税合计=订货数量*含税单价
purOrderEntryInfo_Old.setTaxAmount(purOrderEntryInfo_Old.getQty().multiply(purOrderEntryInfo_Old.getTaxPrice()).setScale(10, BigDecimal.ROUND_HALF_EVEN));
//本位币价税合计=订货数量*含税单价
purOrderEntryInfo_Old.setLocalTaxAmount(purOrderEntryInfo_Old.getQty().multiply(purOrderEntryInfo_Old.getTaxPrice()).setScale(10, BigDecimal.ROUND_HALF_EVEN));
//税额=价税合计-金额
purOrderEntryInfo_Old.setTax(purOrderEntryInfo_Old.getTaxAmount().subtract(purOrderEntryInfo_Old.getAmount()));
//本位币税额=价税合计-金额
purOrderEntryInfo_Old.setLocalTax(purOrderEntryInfo_Old.getTaxAmount().subtract(purOrderEntryInfo_Old.getAmount()));
//其他字段
purOrderEntryInfo_Old.setUnOrderedQty(purOrderEntryInfo_Old.getQty());
purOrderEntryInfo_Old.setTotalUnReceiveQty(purOrderEntryInfo_Old.getQty());
purOrderEntryInfo_Old.setCanInvMoveQty(purOrderEntryInfo_Old.getQty());
purOrderEntryInfo_Old.setAssociateQty(purOrderEntryInfo_Old.getQty());
purOrderEntryInfo_Old.setTotalUnReceiveBaseQty(purOrderEntryInfo_Old.getBaseQty());
purOrderEntryInfo_Old.setTotalUnReturnBaseQty(purOrderEntryInfo_Old.getBaseQty());
//保存源数据
KingdeeUtils.update(purOrderEntryInfo_Old.getId().toString(), purOrderEntryInfo_Old);
//删除子数据
KingdeeUtils.delete(purOrderEntryInfo.getId().toString());
} else {
purOrderEntryInfo.setRemark(null);
//保存源数据
KingdeeUtils.update(purOrderEntryInfo.getId().toString(), purOrderEntryInfo);
}
}
}
/**
* 生成形态转换单
* @param InventoryList
* @param bomUtil
* @param projectInfo
* @param adminOrgUnitInfo
*/
private void AutoTO_MatAttrChangeBill(List<InventoryInfo> InventoryList, BomUtil bomUtil, ProjectInfo projectInfo, AdminOrgUnitInfo adminOrgUnitInfo) {
try {
for (InventoryInfo inventoryInfo : InventoryList) {
//是否满足需求
if (!this.isCompare(bomUtil)) {
MatAttrChangeBillInfo matAttrChangeBillInfo = new MatAttrChangeBillInfo();
//业务类型
matAttrChangeBillInfo.setBizType((BizTypeInfo) KingdeeUtils.getInfo("kXeVPjHuchDgQKjAYj1RYCQHQ1w="));
//业务日期
matAttrChangeBillInfo.setBizDate(new Date());
//库存组织
matAttrChangeBillInfo.setStorageOrgUnit(inventoryInfo.getStorageOrgUnit());
//单据状态
matAttrChangeBillInfo.setBaseStatus(BillBaseStatusEnum.TEMPORARILYSAVED);
//创建人
matAttrChangeBillInfo.setCreator(SysContext.getSysContext().getCurrentUserInfo());
//创建时间
matAttrChangeBillInfo.setCreateTime(new Timestamp(System.currentTimeMillis()));
//转换前-部门
matAttrChangeBillInfo.setAdminOrgUnit(adminOrgUnitInfo);
/**转换前*/
MatAttrChangeBeforeEntryInfo beforeEntryInfo = new MatAttrChangeBeforeEntryInfo();
//转换前-物料
beforeEntryInfo.setMaterial(inventoryInfo.getMaterial());
//转换前-批次
beforeEntryInfo.setLot(inventoryInfo.getLot());
//转换前-项目号
beforeEntryInfo.setProject(inventoryInfo.getProject());
//转换前-计量单位
beforeEntryInfo.setUnit(inventoryInfo.getUnit());
//转换前-基本计量单位
beforeEntryInfo.setBaseUnit(inventoryInfo.getBaseUnit());
//转换前-单位实际成本
beforeEntryInfo.setUnitActualCost(new BigDecimal(0));
//转换前-实际成本
beforeEntryInfo.setActualCost(new BigDecimal(0));
//转换前-单位标准成本
beforeEntryInfo.setUnitStandardCost(new BigDecimal(0));
//转换前-标准成本
beforeEntryInfo.setStandardCost(new BigDecimal(0));
//转换前-财务组织
beforeEntryInfo.setCompanyOrgUnit(inventoryInfo.getCompanyOrgUnit());
//转换前-辅助计量单位换算系数
beforeEntryInfo.setAssCoefficient(new BigDecimal(0));
//转换前-辅助数量
beforeEntryInfo.setAssistQty(new BigDecimal(0));
//转换前-数量
int compare = inventoryInfo.getCurStoreQty().compareTo(bomUtil.getDemandQty_2());
if (compare > 0) {
beforeEntryInfo.setQty(bomUtil.getDemandQty_2());
} else {
beforeEntryInfo.setQty(inventoryInfo.getCurStoreQty());
}
//转换前-基本数量
MeasureUnitInfo measureUnitInfo = (MeasureUnitInfo) KingdeeUtils.getInfo(inventoryInfo.getBaseUnit().getId().toString());
BigDecimal count = beforeEntryInfo.getQty().multiply(measureUnitInfo.getCoefficient());
beforeEntryInfo.setBaseQty(count);
//转换前-仓库
beforeEntryInfo.setWarehouse(inventoryInfo.getWarehouse());
//转换前-库位
beforeEntryInfo.setLocation(inventoryInfo.getLocation());
//转换前-库存类型
beforeEntryInfo.setStoreType(inventoryInfo.getStoretype());
//转换前-库存状态
beforeEntryInfo.setStoreStatus(inventoryInfo.getStorestatus());
/**转换后*/
MatAttrChangeAfterEntryInfo afterEntryInfo = new MatAttrChangeAfterEntryInfo();
//转换后-物料
afterEntryInfo.setMaterial(beforeEntryInfo.getMaterial());
//转换后-批次
afterEntryInfo.setLot(beforeEntryInfo.getLot());
//转换后-项目号
afterEntryInfo.setProject(projectInfo);
//转换后-计量单位
afterEntryInfo.setUnit(beforeEntryInfo.getUnit());
//转换后-基本计量单位
afterEntryInfo.setBaseUnit(beforeEntryInfo.getBaseUnit());
//转换后-数量
afterEntryInfo.setQty(beforeEntryInfo.getQty());
//转换后-基本数量
afterEntryInfo.setBaseQty(beforeEntryInfo.getBaseQty());
//转换后-仓库
afterEntryInfo.setWarehouse(beforeEntryInfo.getWarehouse());
//转换后-库位
afterEntryInfo.setLocation(beforeEntryInfo.getLocation());
//转换后-库存类型
afterEntryInfo.setStoreType(beforeEntryInfo.getStoreType());
//转换后-库存状态
afterEntryInfo.setStoreStatus(beforeEntryInfo.getStoreStatus());
//转换后-单位实际成本
afterEntryInfo.setUnitActualCost(new BigDecimal(0));
//转换后-实际成本
afterEntryInfo.setActualCost(new BigDecimal(0));
//转换后-单位标准成本
afterEntryInfo.setUnitStandardCost(new BigDecimal(0));
//转换后-标准成本
afterEntryInfo.setStandardCost(new BigDecimal(0));
//转换后-财务组织
afterEntryInfo.setCompanyOrgUnit(beforeEntryInfo.getCompanyOrgUnit());
//转换后-辅助计量单位换算系数
afterEntryInfo.setAssCoefficient(new BigDecimal(0));
//转换后-辅助数量
afterEntryInfo.setAssistQty(new BigDecimal(0));
/**填充*/
beforeEntryInfo.getEntry1().add(afterEntryInfo);
matAttrChangeBillInfo.getEntry().add(beforeEntryInfo);
//提交
IObjectPK PK = MatAttrChangeBillFactory.getRemoteInstance().submit(matAttrChangeBillInfo);
//审核
MatAttrChangeBillFactory.getRemoteInstance().audit(PK);
} else {
break;
}
}
} catch (EASBizException e) {
e.printStackTrace();
} catch (BOSException e) {
e.printStackTrace();
}
}
/**
* //删除旧计划订单
* @param bomUtil
* @param projectInfo
*/
private void del_PlannedOrder(ProjectInfo projectInfo, StorageOrgUnitInfo storageOrgUnitInfo) {
try {
projectInfo = ProjectFactory.getRemoteInstance().getProjectInfo(new ObjectUuidPK(projectInfo.getId()));
FilterInfo filter = new FilterInfo();
filter.getFilterItems().add(new FilterItemInfo("storageOrgUnit.id", storageOrgUnitInfo.getId(), CompareType.EQUALS));
filter.getFilterItems().add(new FilterItemInfo("project.number", projectInfo.getNumber(), CompareType.EQUALS));
filter.getFilterItems().add(new FilterItemInfo("baseStatus", 1, CompareType.EQUALS));
filter.getFilterItems().add(new FilterItemInfo("baseStatus", 2, CompareType.EQUALS));
filter.getFilterItems().add(new FilterItemInfo("baseStatus", 4, CompareType.EQUALS));
filter.setMaskString("#0 and #1 and #2 or #3 or #4");
PlannedOrderFactory.getRemoteInstance().delete(filter);
} catch (EASBizException e) {
e.printStackTrace();
} catch (BOSException e) {
e.printStackTrace();
}
}
/**
* 生成计划订单
* @param bomUtil
* @param supplyOrgUtil
* @param projectInfo
* @param trackNumberInfo
* @param storageOrgUnitInfo
* @param demandPlanInfo
* @param bomInfo
* @param adminOrg
*/
@SuppressWarnings("unchecked")
private void AutoTO_PlannedOrder(BomUtil bomUtil, SupplyOrgUtil supplyOrgUtil, DemandPlanEntryInfo EntryInfo, StorageOrgUnitInfo storageOrgUnitInfo, DemandPlanInfo demandPlanInfo, BomInfo bomInfo, AdminOrgUnitInfo adminOrg) {
PlannedOrderInfo plannedOrderInfo = new PlannedOrderInfo();
Object object = KingdeeUtils.returnOneData("select MAX(TO_INT(SUBSTRING(FNumber,13,LEN(FNumber)))) from T_MM_PlannedOrder where FNumber like 'AUTO-SYSTEM-%'");
int index = Integer.parseInt(object == null ? "0" : object.toString()) + 1;
plannedOrderInfo.setNumber("AUTO-SYSTEM-" + index);
plannedOrderInfo.setStorageOrgUnit(storageOrgUnitInfo);
plannedOrderInfo.setBaseStatus(BillBaseStatusEnum.TEMPORARILYSAVED);
plannedOrderInfo.setMaterial(bomUtil.getMaterial());
plannedOrderInfo.setQty(bomUtil.getDemandQty_2());
plannedOrderInfo.setProductUnit(bomUtil.getMaterial().getBaseUnit());
plannedOrderInfo.setFinalProductsRate(new BigDecimal(100));
plannedOrderInfo.setProject(EntryInfo.getProjectNumber());
plannedOrderInfo.setAdminOrgUnit(adminOrg);
plannedOrderInfo.setPlanOrgUnit((AdminOrgUnitInfo) storageOrgUnitInfo.cast(AdminOrgUnitInfo.class));
plannedOrderInfo.setBaseQty(bomUtil.getBasicDemandQty_2());
plannedOrderInfo.setFinalProductsQty(bomUtil.getDemandQty_2());
plannedOrderInfo.setUnit(bomUtil.getMaterial().getBaseUnit());
plannedOrderInfo.setBillType((BillTypeInfo) KingdeeUtils.getInfo("9XXvbVGlRtym/0qtqeIXXrhE1B8="));
plannedOrderInfo.put("cplx", KingdeeUtils.getInfo(EntryInfo.getCplb().getId().toString()));
plannedOrderInfo.put("zrpa", KingdeeUtils.getInfo(demandPlanInfo.getZrpa().getId().toString()));
plannedOrderInfo.setProductionOrgUnit(storageOrgUnitInfo);
plannedOrderInfo.setStartDate(demandPlanInfo.getPlanStartTime());
plannedOrderInfo.setEndDate(demandPlanInfo.getPlanEndTime());
plannedOrderInfo.setAvilableDate(new Date());
plannedOrderInfo.setCreator(SysContext.getSysContext().getCurrentUserInfo());
plannedOrderInfo.setCreateTime(new Timestamp(System.currentTimeMillis()));
plannedOrderInfo.setBizDate(new Date());
plannedOrderInfo.setScheme(this.getPlanVersionSetInfo(storageOrgUnitInfo));
if (this.isMaterialProperties(bomUtil, supplyOrgUtil) == 10050) {
/**委外件*/
plannedOrderInfo.setOrderType(PlannedOrderTypeEnum.STOCKTRANSFER);
if (bomUtil.isMainMaterial()) {
plannedOrderInfo.setBom(bomInfo);
Iterator<BomEntryInfo> iterator = bomInfo.getEntrys().iterator();
while (iterator.hasNext()) {
BomEntryInfo bomEntryInfo = iterator.next();
PlannedOrderEntryInfo item = new PlannedOrderEntryInfo();
item.setMaterial(bomEntryInfo.getMaterial());
MaterialInfo materialInfo = (MaterialInfo) KingdeeUtils.getInfo(bomEntryInfo.getMaterial().getId().toString());
MeasureUnitInfo measureUnitInfo = (MeasureUnitInfo) KingdeeUtils.getInfo(materialInfo.getBaseUnit().getId().toString());
item.setUnit(measureUnitInfo);
item.setUnitQty(bomEntryInfo.getConsumeFixQty());
item.setStandardQty(bomUtil.getDemandQty_2().multiply(bomEntryInfo.getConsumeFixQty()));
item.setDemandQty(bomUtil.getDemandQty_2().multiply(bomEntryInfo.getConsumeFixQty()));
item.setBaseUnit(measureUnitInfo);
item.setBaseDemandQty(bomUtil.getDemandQty_2().multiply(bomEntryInfo.getConsumeFixQty()));
item.setScrapRate(bomEntryInfo.getScrapRatio());
item.setScrapQty(bomUtil.getDemandQty_2().multiply(bomEntryInfo.getConsumeFixQty()).multiply(bomEntryInfo.getScrapRatio().divide(new BigDecimal(100))));
item.setReqDate(new Date());
item.setProvideType(MaterialProvideTypeEnum.CURRENTORGPROVIDE);
item.setStorageOrgUnit(storageOrgUnitInfo);
plannedOrderInfo.getEntries().add(item);
}
}
} else {
/**外购件*/
plannedOrderInfo.setOrderType(PlannedOrderTypeEnum.PURCHASE);
}
KingdeeUtils.addnew(plannedOrderInfo.getBOSType(), plannedOrderInfo);
bomUtil.setDemandQty_2(new BigDecimal(0));
bomUtil.setBasicDemandQty_2(new BigDecimal(0));
}
/**
* 生成计划订单-获取计划方案
* @param storageOrgUnitInfo
* @return
*/
private PlanVersionSetInfo getPlanVersionSetInfo(StorageOrgUnitInfo storageOrgUnitInfo) {
StringBuilder sb = new StringBuilder();
sb.append(" select fid from T_MM_PlanVersionSet ");
sb.append(" where FStorageOrgUnitID = '" + storageOrgUnitInfo.getId() + "' ");
sb.append(" and fnumber = 900 ");
Object object = KingdeeUtils.returnOneData(sb.toString());
if (object != null) {
return (PlanVersionSetInfo) KingdeeUtils.getInfo(object.toString());
} else {
return null;
}
}
/**
* 生成库存占用
* @param InventoryList
* @param bomUtil
* @param projectInfo
* @param supplyOrgUtil
*/
private void AutoTO_Kczyd(List<Object[]> InventoryList, BomUtil bomUtil, ProjectInfo projectInfo, SupplyOrgUtil supplyOrgUtil) {
KCZYDInfo info = new KCZYDInfo();
//生成库存占用单
Object object = KingdeeUtils.returnOneData("select MAX(TO_INT(SUBSTRING(FNumber,13,LEN(FNumber)))) from CT_MRP_KCZYD where FNumber like 'AUTO-SYSTEM-%'");
Integer index = Integer.parseInt(object == null ? "0" : object.toString()) + 1;
info.setNumber("AUTO-SYSTEM-" + index);//单据编号
//业务日期
info.setBizDate(new Date());
//占用日期
info.setOccupancyDate(new Date());
//备注
info.setName("系统自动生成");
//占用类型
info.setOccupancyType(MrpZylx.A);
//占用项目号
info.setProject(projectInfo);
//创建人
info.setCreator(SysContext.getSysContext().getCurrentUserInfo());
//创建日期
info.setCreateTime(new Timestamp(System.currentTimeMillis()));
//库存组织
info.setInventoryOrg(supplyOrgUtil.getStorageOrgUnitInfo());
//遍历库存
for (Object[] objects : InventoryList) {
//是否满足需求
if (!this.isCompare(bomUtil)) {
BigDecimal number = new BigDecimal(objects[2].toString());
//查询是否有无被占有
StringBuilder sql = new StringBuilder();
sql.append(" select sum(b.CFOccupyQty-b.CFReleaseQty) from CT_MRP_KCZYD a ");
sql.append(" inner join CT_MRP_KCZYDEntry b on (b.FParentID = a.FID) ");
sql.append(" where b.CFMaterielID = '" + objects[0].toString() + "' ");
sql.append(" and b.CFWarehouseID = '" + objects[1].toString() + "' ");
sql.append(" and a.CFInventoryOrgID = '" + supplyOrgUtil.getStorageOrgUnitInfo().getId() + "' ");
object = KingdeeUtils.returnOneData(sql.toString());
BigDecimal count = object == null ? new BigDecimal(0) : new BigDecimal(object.toString());
number = number.subtract(count);
// 现有可用库存
int compare = number.compareTo(new BigDecimal(0));
if (compare > 0) {
KCZYDEntryInfo entryInfo = new KCZYDEntryInfo();
//物料INFO
MaterialInfo materialInfo = (MaterialInfo) KingdeeUtils.getInfo(objects[0].toString());
//物料编码
entryInfo.setMateriel(materialInfo);
//物料名称
entryInfo.setMaterielName(materialInfo.getName());
//仓库
entryInfo.setWarehouse((WarehouseInfo) KingdeeUtils.getInfo(objects[1].toString()));
//占用数量
compare = number.compareTo(bomUtil.getDemandQty_2());
if (compare >= 0) {
entryInfo.setOccupyQty(bomUtil.getDemandQty_2());
number = bomUtil.getDemandQty_2();
} else {
entryInfo.setOccupyQty(number);//占用数量
}
//释放数量
entryInfo.setReleaseQty(new BigDecimal(0));
//添加至对象
info.getEntrys().add(entryInfo);
//重置物料需求数量
this.NumberReset(bomUtil, number, true);
//运算过程
this.setPlannedWorkbenchEntryDEntryInfo("库存", info.getInventoryOrg().getName(), entryInfo.getWarehouse().getName(), number, number);
}
} else {
break;
}
}
KingdeeUtils.update(info.getId().toString(), info);
}
/**
* 采购在途拆分
* @param PurOrderEntryInfoList
* @param bomUtil
* @param projectInfo
*/
private void PurSplit(List<PurOrderEntryInfo> PurOrderEntryInfoList, BomUtil bomUtil, ProjectInfo projectInfo) {
BigDecimal number = new BigDecimal(0);
for (PurOrderEntryInfo OldEntryInfo : PurOrderEntryInfoList) {
if (OldEntryInfo.getMaterial().getId().equals(bomUtil.getMaterial().getId()) && OldEntryInfo.getRemark() == null) {
if (!this.isCompare(bomUtil)) {
//未入库数量
BigDecimal qty = OldEntryInfo.getQty().subtract(OldEntryInfo.getTotalInvoicedQty());
BigDecimal baseQty = OldEntryInfo.getBaseQty().subtract(OldEntryInfo.getTotalInvoicedBaseQty());
//比较
int compare = qty.compareTo(bomUtil.getDemandQty_2());
if (compare == 1) {
/**大于*/
PurOrderEntryInfo NewEntryInfo = OldEntryInfo;
/**旧数据重新计算*/
//旧数据-订货数量
OldEntryInfo.setQty(OldEntryInfo.getQty().subtract(bomUtil.getDemandQty_2()));
//旧数据-基本订货数量
OldEntryInfo.setBaseQty(OldEntryInfo.getBaseQty().subtract(bomUtil.getBasicDemandQty_2()));
//旧数据-金额=订货数量*单价
OldEntryInfo.setAmount(OldEntryInfo.getQty().multiply(OldEntryInfo.getPrice()));
//旧数据-本位币金额=订货数量*单价
OldEntryInfo.setLocalAmount(OldEntryInfo.getQty().multiply(OldEntryInfo.getPrice()));
//旧数据-价税合计=订货数量*含税单价
OldEntryInfo.setTaxAmount(OldEntryInfo.getQty().multiply(OldEntryInfo.getTaxPrice()).setScale(10, BigDecimal.ROUND_HALF_EVEN));
//旧数据-本位币价税合计=订货数量*含税单价
OldEntryInfo.setLocalTaxAmount(OldEntryInfo.getQty().multiply(OldEntryInfo.getTaxPrice()).setScale(10, BigDecimal.ROUND_HALF_EVEN));
//旧数据-税额=价税合计-金额
OldEntryInfo.setTax(OldEntryInfo.getTaxAmount().subtract(OldEntryInfo.getAmount()));
//旧数据-本位币税额=价税合计-金额
OldEntryInfo.setLocalTax(OldEntryInfo.getTaxAmount().subtract(OldEntryInfo.getAmount()));
//旧数据-其他字段
OldEntryInfo.setUnOrderedQty(OldEntryInfo.getUnOrderedQty().subtract(bomUtil.getDemandQty_2()));
OldEntryInfo.setTotalUnReceiveQty(OldEntryInfo.getTotalUnReceiveQty().subtract(bomUtil.getDemandQty_2()));
OldEntryInfo.setCanInvMoveQty(OldEntryInfo.getCanInvMoveQty().subtract(bomUtil.getDemandQty_2()));
OldEntryInfo.setAssociateQty(OldEntryInfo.getAssociateQty().subtract(bomUtil.getDemandQty_2()));
OldEntryInfo.setTotalUnReceiveBaseQty(OldEntryInfo.getTotalUnReceiveBaseQty().subtract(bomUtil.getBasicDemandQty_2()));
OldEntryInfo.setTotalUnReturnBaseQty(OldEntryInfo.getTotalUnReturnBaseQty().subtract(bomUtil.getBasicDemandQty_2()));
//旧数据-保存旧纪录
KingdeeUtils.update(OldEntryInfo.getId().toString(), OldEntryInfo);
/**新数据重新计算*/
//新数据-FID
NewEntryInfo.setId(null);
NewEntryInfo.setRemark(projectInfo.getId().toString() + "," + OldEntryInfo.getId().toString());
//新数据-订货数量
NewEntryInfo.setQty(bomUtil.getDemandQty_2());
//新数据-基本订货数量
NewEntryInfo.setBaseQty(bomUtil.getBasicDemandQty_2());
//新数据-金额=订货数量*单价
NewEntryInfo.setAmount(NewEntryInfo.getQty().multiply(NewEntryInfo.getPrice()));
//新数据-本位币金额=订货数量*单价
NewEntryInfo.setLocalAmount(NewEntryInfo.getQty().multiply(NewEntryInfo.getPrice()));
//新数据-价税合计=订货数量*含税单价
NewEntryInfo.setTaxAmount(NewEntryInfo.getQty().multiply(NewEntryInfo.getTaxPrice()).setScale(10, BigDecimal.ROUND_HALF_EVEN));
//新数据-本位币价税合计=订货数量*含税单价
NewEntryInfo.setLocalTaxAmount(NewEntryInfo.getQty().multiply(NewEntryInfo.getTaxPrice()).setScale(10, BigDecimal.ROUND_HALF_EVEN));
//新数据-税额=价税合计-金额
NewEntryInfo.setTax(NewEntryInfo.getTaxAmount().subtract(NewEntryInfo.getAmount()));
//新数据-本位币税额=价税合计-金额
NewEntryInfo.setLocalTax(NewEntryInfo.getTaxAmount().subtract(NewEntryInfo.getAmount()));
//新数据-其他字段
OldEntryInfo.setUnOrderedQty(bomUtil.getDemandQty_2());
OldEntryInfo.setTotalUnReceiveQty(bomUtil.getDemandQty_2());
OldEntryInfo.setCanInvMoveQty(bomUtil.getDemandQty_2());
OldEntryInfo.setAssociateQty(bomUtil.getDemandQty_2());
OldEntryInfo.setTotalUnReceiveBaseQty(bomUtil.getBasicDemandQty_2());
OldEntryInfo.setTotalUnReturnBaseQty(bomUtil.getBasicDemandQty_2());
//新数据-保存新纪录
KingdeeUtils.update(NewEntryInfo.getId().toString(), NewEntryInfo);
//重置物料需求数量
number = bomUtil.getDemandQty_2();
} else {
/**等于、小于*/
if (OldEntryInfo.getTotalInvoicedQty().compareTo(new BigDecimal(0)) == 0) {
//添加项目号
OldEntryInfo.setRemark(projectInfo.getId().toString());
KingdeeUtils.update(OldEntryInfo.getId().toString(), OldEntryInfo);
//重置物料需求数量
number = OldEntryInfo.getQty();
} else {
PurOrderEntryInfo NewEntryInfo = OldEntryInfo;
/**旧数据重新计算*/
//旧数据-订货数量
OldEntryInfo.setQty(OldEntryInfo.getTotalInvoicedQty());
//旧数据-基本订货数量
OldEntryInfo.setBaseQty(OldEntryInfo.getTotalInvoicedBaseQty());
//旧数据-金额=订货数量*单价
OldEntryInfo.setAmount(OldEntryInfo.getQty().multiply(OldEntryInfo.getPrice()));
//旧数据-本位币金额=订货数量*单价
OldEntryInfo.setLocalAmount(OldEntryInfo.getQty().multiply(OldEntryInfo.getPrice()));
//旧数据-价税合计=订货数量*含税单价
OldEntryInfo.setTaxAmount(OldEntryInfo.getQty().multiply(OldEntryInfo.getTaxPrice()).setScale(10, BigDecimal.ROUND_HALF_EVEN));
//旧数据-本位币价税合计=订货数量*含税单价
OldEntryInfo.setLocalTaxAmount(OldEntryInfo.getQty().multiply(OldEntryInfo.getTaxPrice()).setScale(10, BigDecimal.ROUND_HALF_EVEN));
//旧数据-税额=价税合计-金额
OldEntryInfo.setTax(OldEntryInfo.getTaxAmount().subtract(OldEntryInfo.getAmount()));
//旧数据-本位币税额=价税合计-金额
OldEntryInfo.setLocalTax(OldEntryInfo.getTaxAmount().subtract(OldEntryInfo.getAmount()));
//旧数据-其他字段
OldEntryInfo.setUnOrderedQty(OldEntryInfo.getUnOrderedQty().subtract(bomUtil.getDemandQty_2()));
OldEntryInfo.setTotalUnReceiveQty(OldEntryInfo.getTotalUnReceiveQty().subtract(bomUtil.getDemandQty_2()));
OldEntryInfo.setCanInvMoveQty(OldEntryInfo.getCanInvMoveQty().subtract(bomUtil.getDemandQty_2()));
OldEntryInfo.setAssociateQty(OldEntryInfo.getAssociateQty().subtract(bomUtil.getDemandQty_2()));
OldEntryInfo.setTotalUnReceiveBaseQty(OldEntryInfo.getTotalUnReceiveBaseQty().subtract(bomUtil.getBasicDemandQty_2()));
OldEntryInfo.setTotalUnReturnBaseQty(OldEntryInfo.getTotalUnReturnBaseQty().subtract(bomUtil.getBasicDemandQty_2()));
//旧数据-保存旧纪录
KingdeeUtils.update(OldEntryInfo.getId().toString(), OldEntryInfo);
/**新数据重新计算*/
//新数据-FID
NewEntryInfo.setId(null);
NewEntryInfo.setRemark(projectInfo.getId().toString() + "," + OldEntryInfo.getId().toString());
//新数据-订货数量
NewEntryInfo.setQty(qty);
//新数据-基本订货数量
NewEntryInfo.setBaseQty(baseQty);
//新数据-金额=订货数量*单价
NewEntryInfo.setAmount(NewEntryInfo.getQty().multiply(NewEntryInfo.getPrice()));
//新数据-本位币金额=订货数量*单价
NewEntryInfo.setLocalAmount(NewEntryInfo.getQty().multiply(NewEntryInfo.getPrice()));
//新数据-价税合计=订货数量*含税单价
NewEntryInfo.setTaxAmount(NewEntryInfo.getQty().multiply(NewEntryInfo.getTaxPrice()).setScale(10, BigDecimal.ROUND_HALF_EVEN));
//新数据-本位币价税合计=订货数量*含税单价
NewEntryInfo.setLocalTaxAmount(NewEntryInfo.getQty().multiply(NewEntryInfo.getTaxPrice()).setScale(10, BigDecimal.ROUND_HALF_EVEN));
//新数据-税额=价税合计-金额
NewEntryInfo.setTax(NewEntryInfo.getTaxAmount().subtract(NewEntryInfo.getAmount()));
//新数据-本位币税额=价税合计-金额
NewEntryInfo.setLocalTax(NewEntryInfo.getTaxAmount().subtract(NewEntryInfo.getAmount()));
//新数据-其他字段
OldEntryInfo.setUnOrderedQty(bomUtil.getDemandQty_2());
OldEntryInfo.setTotalUnReceiveQty(bomUtil.getDemandQty_2());
OldEntryInfo.setCanInvMoveQty(bomUtil.getDemandQty_2());
OldEntryInfo.setAssociateQty(bomUtil.getDemandQty_2());
OldEntryInfo.setTotalUnReceiveBaseQty(bomUtil.getBasicDemandQty_2());
OldEntryInfo.setTotalUnReturnBaseQty(bomUtil.getBasicDemandQty_2());
//重置物料需求数量
number = qty;
}
}
//重置物料需求数量
this.NumberReset(bomUtil, number, true);
//运算过程
this.setPlannedWorkbenchEntryDEntryInfo("采购在途占用", null, null, number, number);
} else {
break;
}
}
}
}
/**
* 查询通用料的采购在途
* @param supplyOrgUtil
* @param bomUtil
* @return
*/
private List<PurOrderEntryInfo> isPurOrder(SupplyOrgUtil supplyOrgUtil, BomUtil bomUtil, ProjectInfo projectInfo) {
List<PurOrderEntryInfo> list = new ArrayList<PurOrderEntryInfo>();
StringBuilder sb = new StringBuilder();
sb.append(" select b.fid from T_SM_PurOrderEntry b");
sb.append(" inner join T_SM_PurOrder a on (a.fid = b.fparentid) ");
sb.append(" where b.FStorageOrgUnitID = '" + supplyOrgUtil.getStorageOrgUnitInfo().getId() + "' ");
sb.append(" and b.FMaterialID = '" + bomUtil.getMaterial().getId() + "' ");
sb.append(" and (b.FRemark = '' or b.FRemark is null) ");
sb.append(" and a.FBizTypeID = 'd8e80652-0106-1000-e000-04c5c0a812202407435C' ");
sb.append(" and a.FBaseStatus = 4 ");
List<Object[]> values = KingdeeUtils.executeSQL(sb.toString());
for (Object[] objects : values) {
for (Object object : objects) {
if (object != null) {
list.add((PurOrderEntryInfo) KingdeeUtils.getInfo(object.toString()));
}
}
}
return list;
}
/**
* 查询是否有库存-专用料
* @param bomUtil
* @param supplyOrgUtil
* @return
*/
private List<InventoryInfo> isInventory_Special(BomUtil bomUtil, SupplyOrgUtil supplyOrgUtil) {
List<InventoryInfo> list = new ArrayList<InventoryInfo>();
StringBuilder sb = new StringBuilder();
sb.append(" select Fid from T_IM_Inventory ");
sb.append(" where FStorageOrgUnitID = '" + supplyOrgUtil.getStorageOrgUnitInfo().getId() + "' ");
sb.append(" and FMaterialID = '" + bomUtil.getMaterial().getId() + "' ");
sb.append(" and FCurStoreQty > 0 ");
sb.append(" and FStoreStatusID = '181875d5-0105-1000-e000-012ec0a812fd62A73FA5' ");
sb.append(" and FProjectID = (select FID from T_MM_Project where FNumber = 'PUB') ");
List<Object[]> values = KingdeeUtils.executeSQL(sb.toString());
for (Object[] objects : values) {
for (Object object : objects) {
if (object != null) {
list.add((InventoryInfo) KingdeeUtils.getInfo(object.toString()));
}
}
}
return list;
}
/**
* 查询是否有库存-通用料
* @param bomUtil
* @param supplyOrgUtil
* @return
*/
private List<Object[]> isInventory_Currency(BomUtil bomUtil, SupplyOrgUtil supplyOrgUtil) {
List<Object[]> values = new ArrayList<Object[]>();
StringBuilder sb = new StringBuilder();
sb.append(" select FMaterialID,FWarehouseID,SUM(FCurStoreQty) from T_IM_Inventory ");
sb.append(" where FStorageOrgUnitID = '" + supplyOrgUtil.getStorageOrgUnitInfo().getId() + "' ");
sb.append(" and FMaterialID = '" + bomUtil.getMaterial().getId() + "' ");
sb.append(" and FCurStoreQty > 0 ");
sb.append(" and FStoreStatusID = '181875d5-0105-1000-e000-012ec0a812fd62A73FA5' ");
for (WarehouseInfo warehouseInfo : supplyOrgUtil.getWarehouseInfoList()) {
StringBuilder sql = new StringBuilder(sb);
sql.append(" and FProjectID = 'EgkAAABc3Xza3gXu' ");
sql.append(" and FWarehouseID = '" + warehouseInfo.getId() + "' ");
sql.append(" group by FMaterialID,FWarehouseID ");
values.addAll(KingdeeUtils.executeSQL(sql.toString()));
}
return values;
}
/**
* 查询【外购件占用库存比设置表】
* @param materialInfo
* @param supplyOrgUtil
* @return
*/
private WGJZYKCBSZBInfo getWGJZYKCBSZBInfo(MaterialInfo materialInfo, SupplyOrgUtil supplyOrgUtil) {
StringBuilder sb = new StringBuilder();
sb.append(" select FID from CT_MRP_WGJZYKCBSZB ");
sb.append(" where CFWLBMID = '" + materialInfo.getId() + "' ");
sb.append(" and CFKCZZID = '" + supplyOrgUtil.getStorageOrgUnitInfo().getId() + "'");
Object object = KingdeeUtils.returnOneData(sb.toString());
if (object != null) {
return (WGJZYKCBSZBInfo) KingdeeUtils.getInfo(object.toString());
} else {
return null;
}
}
/**
* 获取物料属性
* @param bomUtil
* @param supplyOrgUtil
* @return
*/
private Integer isMaterialProperties(BomUtil bomUtil, SupplyOrgUtil supplyOrgUtil) {
StringBuilder sb = new StringBuilder();
sb.append(" select FMaterialAttr from T_BD_MaterialPlan ");
sb.append(" where FMaterialID = '" + bomUtil.getMaterial().getId() + "' ");
sb.append(" and FOrgUnit = '" + supplyOrgUtil.getStorageOrgUnitInfo().getId() + "' ");
sb.append(" and FStatus = 1 ");
Object object = KingdeeUtils.returnOneData(sb.toString());
if (object != null) {
return Integer.parseInt(object.toString());
} else {
return null;
}
}
/**
* 获取库存组织,根据优先级排序
* @param supplyRelationshipInfo
* @return
*/
public List<SupplyOrgUtil> getSupplyOrgs(SupplyRelationshipInfo supplyRelationshipInfo) {
List<SupplyOrgUtil> SupplyOrgUtilList = new ArrayList<SupplyOrgUtil>();
//供货组织
StringBuilder sql = new StringBuilder();
sql.append(" select CFSupplyOrgID from CT_MRP_SupplyRelationshipEntry ");
sql.append(" where FParentID = '" + supplyRelationshipInfo.getId() + "' ");
sql.append(" group by CFSupplyOrgID ");
sql.append(" order by max(CFPriority) desc ");
List<Object[]> values = KingdeeUtils.executeSQL(sql.toString());
for (Object[] objects : values) {
for (Object object : objects) {
//库存组织
StorageOrgUnitInfo storageOrgUnitInfo = (StorageOrgUnitInfo) KingdeeUtils.getInfo(object.toString());
//仓库
List<WarehouseInfo> warehouseInfoList = new ArrayList<WarehouseInfo>();
sql = new StringBuilder();
sql.append(" select CFWarehouseID from CT_MRP_SupplyRelationshipEntry ");
sql.append(" where FParentID = '" + supplyRelationshipInfo.getId() + "' ");
sql.append(" and CFSupplyOrgID = '" + storageOrgUnitInfo.getId() + "' ");
sql.append(" order by CFPriority desc ");
values = KingdeeUtils.executeSQL(sql.toString());
for (Object[] objects2 : values) {
for (Object object2 : objects2) {
if (object != null) {
warehouseInfoList.add((WarehouseInfo) KingdeeUtils.getInfo(object2.toString()));
}
}
}
SupplyOrgUtilList.add(new SupplyOrgUtil(storageOrgUnitInfo, warehouseInfoList));
}
}
return SupplyOrgUtilList;
}
/**
* 根据【BOM】,获取主物料和子物料的毛需求
* @param bomInfo
* @param EntryInfo
* @return
*/
@SuppressWarnings("unchecked")
private List<BomUtil> getMaterialInfo(BomInfo bomInfo, DemandPlanEntryInfo demandPlanEntryInfo) {
List<BomUtil> list = new ArrayList<BomUtil>();
if (bomInfo != null) {
//毛需求
BigDecimal qty = demandPlanEntryInfo.getDemandQuantity().compareTo(new BigDecimal(0)) == 0 ? new BigDecimal(0) : demandPlanEntryInfo.getDemandQuantity();
//获取物料
MaterialInfo materialInfo = (MaterialInfo) KingdeeUtils.getInfo(demandPlanEntryInfo.getMaterialCoding().getId().toString());
//获取基本计量单位
MeasureUnitInfo measureUnitInfo = (MeasureUnitInfo) KingdeeUtils.getInfo(materialInfo.getBaseUnit().getId().toString());
//实例化主物料对象
BomUtil bomUtil_A = new BomUtil();
//是否为主物料,true为主物料,false为子物料
bomUtil_A.setMainMaterial(true);
//是否为通用物料,true为通用物料,false为专用物料
Object object = KingdeeUtils.returnOneData("select CFYxwl from T_BD_Material where FID = '" + materialInfo.getId() + "'");
if (object != null) {
String value = object.toString();
if (value.equals("1")) {
bomUtil_A.setSpecialMaterial(true);
} else {
bomUtil_A.setSpecialMaterial(false);
}
} else {
bomUtil_A.setSpecialMaterial(false);
}
//主物料信息
bomUtil_A.setMaterial(materialInfo);
//主物料-毛需求数量
bomUtil_A.setDemandQty_1(qty);
//主物料-净需求数量
bomUtil_A.setDemandQty_2(qty);
//主物料-毛需求基本数量
bomUtil_A.setBasicDemandQty_1(qty.multiply(measureUnitInfo.getCoefficient()));
//主物料-净需求基本数量
bomUtil_A.setBasicDemandQty_2(qty.multiply(measureUnitInfo.getCoefficient()));
//添加到物料清单中
list.add(bomUtil_A);
//获取子项集合
Iterator<BomEntryInfo> iterator = bomInfo.getEntrys().iterator();
//遍历子项
while (iterator.hasNext()) {
BomEntryInfo bomEntryInfo = iterator.next();
//获取物料
materialInfo = (MaterialInfo) KingdeeUtils.getInfo(bomEntryInfo.getMaterial().getId().toString());
//获取基本计量单位
measureUnitInfo = (MeasureUnitInfo) KingdeeUtils.getInfo(materialInfo.getBaseUnit().getId().toString());
//实例子主物料对象
BomUtil bomUtil_B = new BomUtil();
//是否为主物料,true为主物料,false为子物料
bomUtil_B.setMainMaterial(false);
//是否为专用物料,true为专用物料,false为通用物料
object = KingdeeUtils.returnOneData("select CFYxwl from T_BD_Material where FID = '" + materialInfo.getId() + "'");
if (object != null) {
String value = object.toString();
if (value.equals("1")) {
bomUtil_B.setSpecialMaterial(true);
} else {
bomUtil_B.setSpecialMaterial(false);
}
} else {
bomUtil_B.setSpecialMaterial(false);
}
//子物料信息
bomUtil_B.setMaterial(materialInfo);
//子物料-毛需求数量
bomUtil_B.setDemandQty_1(qty.multiply(bomEntryInfo.getConsumeFixQty()));
//子物料-净需求数量
bomUtil_B.setDemandQty_2(qty.multiply(bomEntryInfo.getConsumeFixQty()));
//子物料-毛需求基本数量
bomUtil_B.setBasicDemandQty_1(qty.multiply(bomEntryInfo.getConsumeFixQty()).multiply(measureUnitInfo.getCoefficient()));
//子物料-净需求基本数量
bomUtil_B.setBasicDemandQty_2(qty.multiply(bomEntryInfo.getConsumeFixQty()).multiply(measureUnitInfo.getCoefficient()));
list.add(bomUtil_B);
}
}
return list;
}
/**
* 获取当前主物料的【BOM】
* @param info
* @return
*/
private BomInfo getBomInfo(DemandPlanEntryInfo info) {
BomInfo bomInfo = null;
StringBuilder sb = new StringBuilder();
sb.append(" select bom.fid from T_MM_Bom bom ");
sb.append(" inner join T_MM_OrderBOMPT bomPt on (bomPt.FOrderID = bom.FID) ");
sb.append(" where bom.FMaterialID = '" + info.getMaterialCoding().getId() + "' ");
sb.append(" and FStorageOrgUnitID = '" + info.getInventoryOrg().getId() + "' ");
sb.append(" and bomPt.FProjectID = '" + info.getProjectNumber().getId() + "' ");
sb.append(" and bom.FBaseStatus = 4");
Object object = KingdeeUtils.returnOneData(sb.toString());
if (object != null) {
//失效子项集合
List<BomEntryInfo> BomEntryInfoList = new ArrayList<BomEntryInfo>();
//获取BOM对象
bomInfo = (BomInfo) KingdeeUtils.getInfo(object.toString());
//获取子项集合
BomEntryCollection entryCollection = bomInfo.getEntrys();
//遍历子项集合,并获取失效子项
for (int i = 0; i < entryCollection.size(); i++) {
BomEntryInfo entryInfo = entryCollection.get(i);
long stratDate = entryInfo.getEffectiveDate().getTime();
long endDate = entryInfo.getDisableDate().getTime();
long Today = new Date().getTime();
if (!(Today >= stratDate && Today <= endDate)) {
BomEntryInfoList.add(entryInfo);
}
}
//删除子项
for (BomEntryInfo entryInfo : BomEntryInfoList) {
entryCollection.remove(entryInfo);
}
}
return bomInfo;
}
/**
* 删除类型为【MRP占用】的【库存占用单】
* @param projectInfo
* @param bomUtil
* @param SupplyOrgList
*/
private void delKCZYD(ProjectInfo projectInfo, BomUtil bomUtil, List<SupplyOrgUtil> SupplyOrgList) {
StringBuilder sb = new StringBuilder("");
for (SupplyOrgUtil supplyOrgUtil : SupplyOrgList) {
sb.append(String.format("'%s',", supplyOrgUtil.getStorageOrgUnitInfo().getId()));
}
StringBuilder sql = new StringBuilder();
sql.append(" select a.FID from CT_MRP_KCZYD a ");
sql.append(" inner join CT_MRP_KCZYDEntry b on (b.FParentID = a.FID) ");
sql.append(" where b.CFMaterielID = '" + bomUtil.getMaterial().getId() + "' ");
sql.append(" and a.CFInventoryOrgID in (" + sb.substring(0, sb.lastIndexOf(",")) + " )");
sql.append(" and a.CFProjectID = '" + projectInfo.getId() + "' ");
Object object = KingdeeUtils.returnOneData(sql.toString());
if (object != null) {
KingdeeUtils.delete(object.toString());
}
}
/**
* 通用方法--重置物料净需求数量和基本数量
* @param bomUtil
* @param number
* @param type
*/
private void NumberReset(BomUtil bomUtil, BigDecimal number, boolean type) {
//获取物料
MaterialInfo materialInfo = bomUtil.getMaterial();
//获取计量单位
MeasureUnitInfo measureUnitInfo = (MeasureUnitInfo) KingdeeUtils.getInfo(materialInfo.getBaseUnit().getId().toString());
if (type) {
//重置净需求数量
bomUtil.setDemandQty_2(bomUtil.getDemandQty_2().subtract(number));
} else {
//重置净需求数量
bomUtil.setDemandQty_2(bomUtil.getDemandQty_1().subtract(number));
}
//重置净需求基本单位
bomUtil.setBasicDemandQty_2(bomUtil.getDemandQty_2().multiply(measureUnitInfo.getCoefficient()));
}
/**
* 通用方法--是否满足需求
* @param bomUtil
* @return
*/
private boolean isCompare(BomUtil bomUtil) {
int compare = bomUtil.getDemandQty_2().compareTo(new BigDecimal(0));
if (compare > 0) {
/**不满足需求*/
return false;
} else {
/**满足需求*/
return true;
}
}
}