领料申请单去除系统插件中申请数量的赋值逻辑
This commit is contained in:
parent
430132a78a
commit
21c89b05a5
|
@ -0,0 +1,804 @@
|
|||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by FernFlower decompiler)
|
||||
//
|
||||
|
||||
package zcgj.zcdev.zcdev.pr.plugin.form;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.EventObject;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import kd.bos.context.RequestContext;
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||
import kd.bos.dataentity.entity.LocaleString;
|
||||
import kd.bos.dataentity.resource.ResManager;
|
||||
import kd.bos.dataentity.utils.StringUtils;
|
||||
import kd.bos.entity.datamodel.events.ChangeData;
|
||||
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
|
||||
import kd.bos.form.CloseCallBack;
|
||||
import kd.bos.form.FormShowParameter;
|
||||
import kd.bos.form.ShowType;
|
||||
import kd.bos.form.control.EntryGrid;
|
||||
import kd.bos.form.events.AfterDoOperationEventArgs;
|
||||
import kd.bos.form.events.ClosedCallBackEvent;
|
||||
import kd.bos.form.field.BasedataEdit;
|
||||
import kd.bos.form.field.ComboEdit;
|
||||
import kd.bos.form.field.ComboItem;
|
||||
import kd.bos.form.field.events.BeforeF7SelectEvent;
|
||||
import kd.bos.form.field.events.BeforeF7SelectListener;
|
||||
import kd.bos.list.ListShowParameter;
|
||||
import kd.bos.orm.query.QFilter;
|
||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||
import kd.ec.basedata.common.enums.LabourTeamEnum;
|
||||
import kd.ec.basedata.common.utils.ContractHelper;
|
||||
import kd.ec.basedata.common.utils.CurrencyHelper;
|
||||
import kd.ec.basedata.common.utils.OpenPageUtils;
|
||||
import kd.ec.contract.common.enums.PayDirectionEnum;
|
||||
import kd.ec.material.common.enums.PoundTransTypeEnum;
|
||||
import kd.ec.material.formplugin.AbstractEcmaBillPlugin;
|
||||
|
||||
public class MaterialApplyBillPluginExt extends AbstractEcmaBillPlugin implements BeforeF7SelectListener {
|
||||
private static final String PROJECT = "project";
|
||||
private static final String EC_PROJECT = "ec_project";
|
||||
|
||||
public MaterialApplyBillPluginExt() {
|
||||
}
|
||||
|
||||
public void registerListener(EventObject e) {
|
||||
super.registerListener(e);
|
||||
BasedataEdit basedataEdit = (BasedataEdit) this.getControl("labour");
|
||||
basedataEdit.addBeforeF7SelectListener(this);
|
||||
basedataEdit = (BasedataEdit) this.getControl("requestperson");
|
||||
basedataEdit.addBeforeF7SelectListener(this);
|
||||
basedataEdit = (BasedataEdit) this.getControl("warehouse");
|
||||
basedataEdit.addBeforeF7SelectListener(this);
|
||||
basedataEdit = (BasedataEdit) this.getControl("material");
|
||||
basedataEdit.addBeforeF7SelectListener(this);
|
||||
basedataEdit = (BasedataEdit) this.getControl("unitproject");
|
||||
basedataEdit.addBeforeF7SelectListener(this);
|
||||
basedataEdit = (BasedataEdit) this.getControl("contract");
|
||||
basedataEdit.addBeforeF7SelectListener(this);
|
||||
BasedataEdit transType = (BasedataEdit) this.getControl("transtype");
|
||||
if (transType != null) {
|
||||
transType.addBeforeF7SelectListener(this);
|
||||
}
|
||||
|
||||
BasedataEdit proj = (BasedataEdit) this.getView().getControl("project");
|
||||
if (proj != null) {
|
||||
proj.addBeforeF7ViewDetailListener((beforeF7ViewDetailEvent) -> {
|
||||
beforeF7ViewDetailEvent.setCancel(true);
|
||||
this.getView().showForm(OpenPageUtils.buildBillShowParam(beforeF7ViewDetailEvent.getPkId(), "ec_project"));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void afterCreateNewData(EventObject arg0) {
|
||||
super.afterCreateNewData(arg0);
|
||||
this.initPeriodAndBizDate();
|
||||
this.getModel().setValue("billsrc", "self");
|
||||
}
|
||||
|
||||
protected void initPeriodAndBizDate() {
|
||||
Calendar now = Calendar.getInstance();
|
||||
int year = now.get(1);
|
||||
int month = now.get(2) + 1;
|
||||
QFilter qFilter = new QFilter("periodyear", "=", year);
|
||||
qFilter.and(new QFilter("periodnumber", "=", month));
|
||||
DynamicObject[] periods = BusinessDataServiceHelper.load("bd_period", "periodyear,periodquarter", new QFilter[]{qFilter});
|
||||
if (periods != null && periods.length > 0) {
|
||||
this.getModel().setValue("period", periods[0].getPkValue());
|
||||
}
|
||||
|
||||
this.getModel().setValue("bizdate", new Date());
|
||||
}
|
||||
|
||||
public void afterBindData(EventObject e) {
|
||||
super.afterBindData(e);
|
||||
this.initRequestPersonControl();
|
||||
this.setUnitProjectFieldStatus();
|
||||
this.setEableAndVisableByCosttype((String) this.getModel().getValue("costtype"));
|
||||
}
|
||||
|
||||
protected void showRefuseBtn() {
|
||||
String billsrc = (String) this.getModel().getValue("billsrc");
|
||||
String supplierstatus = (String) this.getModel().getValue("supplierstatus");
|
||||
Boolean isSupplier = (Boolean) this.getModel().getValue("issupplier");
|
||||
String billstauts = (String) this.getModel().getValue("billstatus");
|
||||
long currUserId = RequestContext.get().getCurrUserId();
|
||||
DynamicObject user = BusinessDataServiceHelper.loadSingle(currUserId, "bos_user");
|
||||
DynamicObjectCollection userTypes = user.getDynamicObjectCollection("usertypes");
|
||||
List<String> userCategorys = (List) userTypes.stream().map((obj) -> {
|
||||
return obj.getDynamicObject("fbasedataid").getString("category");
|
||||
}).collect(Collectors.toList());
|
||||
if (StringUtils.equalsIgnoreCase(billsrc, "supplier") && StringUtils.equalsIgnoreCase(supplierstatus, "B") && isSupplier && StringUtils.equalsIgnoreCase(billstauts, "A") && userCategorys.contains("1")) {
|
||||
this.getView().setVisible(true, new String[]{"refusebtn"});
|
||||
} else {
|
||||
this.getView().setVisible(false, new String[]{"refusebtn"});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void setUnitProjectFieldStatus() {
|
||||
DynamicObject project = (DynamicObject) this.getModel().getValue("project");
|
||||
boolean flag = false;
|
||||
if (project != null && project.getBoolean("editonunit")) {
|
||||
flag = true;
|
||||
}
|
||||
|
||||
BasedataEdit unitProjectEdit = (BasedataEdit) this.getControl("unitproject");
|
||||
unitProjectEdit.setMustInput(flag);
|
||||
}
|
||||
|
||||
public void propertyChanged(PropertyChangedArgs e) {
|
||||
super.propertyChanged(e);
|
||||
String name = e.getProperty().getName();
|
||||
ChangeData changeData = e.getChangeSet()[0];
|
||||
if (StringUtils.equals("supplier", name)) {
|
||||
this.supplierChanged(changeData);
|
||||
} else if (StringUtils.equals("labour", name)) {
|
||||
this.labourChanged(changeData);
|
||||
} else if (StringUtils.equals("project", name)) {
|
||||
this.projectChanged(changeData);
|
||||
} else if (StringUtils.equals("warehouse", name)) {
|
||||
this.warehouseChanged(changeData);
|
||||
} else if (StringUtils.equals("measureunit", name)) {
|
||||
this.measureUnitChanged(changeData);
|
||||
} else if (StringUtils.equals("assmeasureunit", name)) {
|
||||
this.assMeasureUnitChanged(changeData);
|
||||
} else if (StringUtils.equals("qty", name)) {
|
||||
this.qtyChanged(changeData);
|
||||
} else if (StringUtils.equals("assqty", name)) {
|
||||
this.assQtyChanged(changeData);
|
||||
} else if (!StringUtils.equals("requestperson", name) && !StringUtils.equals("reqpersonname", name)) {
|
||||
if (StringUtils.equals("amount", name)) {
|
||||
this.sumAmountToHead();
|
||||
} else if (StringUtils.equals("currency", name)) {
|
||||
this.currencyChanged(changeData);
|
||||
} else if (StringUtils.equals("contract", name)) {
|
||||
this.onContractChanged(changeData);
|
||||
} else if (StringUtils.equals("unitproject", name)) {
|
||||
this.onUnitprojectChanged();
|
||||
} else if (StringUtils.equalsIgnoreCase("costtype", name)) {
|
||||
this.onCosttypeChanged(changeData);
|
||||
} else if (StringUtils.equals("material", name)) {
|
||||
this.onMaterilaChanged(changeData);
|
||||
} else if (StringUtils.equals("transtype", name)) {
|
||||
this.onTransTypeChange(changeData);
|
||||
}
|
||||
} else {
|
||||
this.setApplyPersonName();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void onTransTypeChange(ChangeData changeData) {
|
||||
this.clearEntryRowBoq();
|
||||
}
|
||||
|
||||
protected DynamicObject[] getBoqs(Object projectId, Object unitProjectId, Object resourceId) {
|
||||
QFilter filter = new QFilter("isleaf", "=", "1");
|
||||
if (projectId != null) {
|
||||
filter.and(new QFilter("project", "=", projectId));
|
||||
}
|
||||
|
||||
if (unitProjectId != null) {
|
||||
filter.and(new QFilter("unitproject", "=", unitProjectId));
|
||||
}
|
||||
|
||||
if (resourceId != null) {
|
||||
filter.and(new QFilter("resource", "=", resourceId));
|
||||
}
|
||||
|
||||
return BusinessDataServiceHelper.load("ec_ecbd_pro_boq", "id", new QFilter[]{filter});
|
||||
}
|
||||
|
||||
protected void onMaterilaChanged(ChangeData changeData) {
|
||||
DynamicObject project = (DynamicObject) this.getModel().getValue("project");
|
||||
if (project != null) {
|
||||
Object newValue = changeData.getNewValue();
|
||||
if (newValue != null) {
|
||||
DynamicObject mat = (DynamicObject) newValue;
|
||||
DynamicObject unitProject = (DynamicObject) this.getModel().getValue("unitproject");
|
||||
DynamicObject[] load = this.getBoqs(project.getPkValue(), unitProject == null ? null : unitProject.getPkValue(), mat.getPkValue());
|
||||
if (load.length > 0) {
|
||||
this.getModel().setValue("proboq", load[0].getPkValue());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void onCosttypeChanged(ChangeData changeData) {
|
||||
Object newValue = changeData.getNewValue();
|
||||
String costtype = (String) newValue;
|
||||
this.setEableAndVisableByCosttype(costtype);
|
||||
}
|
||||
|
||||
protected void setEableAndVisableByCosttype(String costtype) {
|
||||
if (!StringUtils.isEmpty(costtype)) {
|
||||
BasedataEdit contract = (BasedataEdit) this.getControl("contract");
|
||||
BasedataEdit labour = (BasedataEdit) this.getControl("labour");
|
||||
if (StringUtils.equals("a", costtype)) {
|
||||
this.getView().setVisible(false, new String[]{"supplier", "contract", "contractname", "labour"});
|
||||
contract.setMustInput(false);
|
||||
labour.setMustInput(false);
|
||||
this.getModel().beginInit();
|
||||
if (!(Boolean) this.getModel().getValue("issupplier")) {
|
||||
this.getModel().setValue("supplier", (Object) null);
|
||||
}
|
||||
|
||||
this.getModel().setValue("contract", (Object) null);
|
||||
this.getModel().setValue("labour", (Object) null);
|
||||
this.getModel().endInit();
|
||||
}
|
||||
|
||||
if (StringUtils.equals("b", costtype)) {
|
||||
this.getView().setVisible(true, new String[]{"supplier", "contract", "contractname", "labour"});
|
||||
contract.setMustInput(true);
|
||||
labour.setMustInput(true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected void onUnitprojectChanged() {
|
||||
int entryRowCount = this.getModel().getEntryRowCount("entryentity");
|
||||
|
||||
for (int i = 0; i < entryRowCount; ++i) {
|
||||
this.getModel().setValue("proboq", (Object) null, i);
|
||||
}
|
||||
|
||||
this.getModel().setValue("warehouse", (Object) null);
|
||||
this.getModel().setValue("labour", (Object) null);
|
||||
}
|
||||
|
||||
private void onContractChanged(ChangeData changeData) {
|
||||
Object newValue = changeData.getNewValue();
|
||||
if (newValue == null) {
|
||||
this.getModel().setValue("project", (Object) null);
|
||||
} else {
|
||||
DynamicObject contractF7 = (DynamicObject) newValue;
|
||||
DynamicObject project = contractF7.getDynamicObject("project");
|
||||
if (project != null) {
|
||||
this.getModel().setValue("project", project.getPkValue());
|
||||
}
|
||||
|
||||
DynamicObject newProject = (DynamicObject) this.getModel().getValue("project");
|
||||
this.setEnableUnitProjectByProjectEditOnUnit(newProject);
|
||||
this.getModel().deleteEntryData("entryentity");
|
||||
}
|
||||
}
|
||||
|
||||
protected void currencyChanged(ChangeData changeData) {
|
||||
DynamicObject targetCurrency = (DynamicObject) changeData.getNewValue();
|
||||
DynamicObject dynamicObject = this.getModel().getDataEntity();
|
||||
DynamicObject exrateTable = dynamicObject.getDynamicObject("exratetable");
|
||||
Date exchangeDate = dynamicObject.getDate("exchangedate");
|
||||
if (targetCurrency != null && exrateTable != null && exchangeDate != null) {
|
||||
int rowCount = this.getModel().getEntryRowCount("entryentity");
|
||||
|
||||
for (int i = 0; i < rowCount; ++i) {
|
||||
DynamicObject materialInventory = (DynamicObject) this.getModel().getValue("matinventory", i);
|
||||
String price = materialInventory.getString("price");
|
||||
BigDecimal priceNum = new BigDecimal(price);
|
||||
DynamicObject srcCurrency = materialInventory.getDynamicObject("currency");
|
||||
BigDecimal exchangeRate = BigDecimal.ONE;
|
||||
if (srcCurrency != null) {
|
||||
exchangeRate = CurrencyHelper.getExChangeRate(srcCurrency.getLong("id"), targetCurrency.getLong("id"), exrateTable.getLong("id"), new Date());
|
||||
}
|
||||
|
||||
exchangeRate = exchangeRate == null ? BigDecimal.ONE : exchangeRate;
|
||||
this.getModel().setValue("price", priceNum.multiply(exchangeRate), i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void sumAmountToHead() {
|
||||
EntryGrid grid = (EntryGrid) this.getControl("entryentity");
|
||||
this.getModel().setValue("totalapplyamount", grid.getSum("amount"));
|
||||
}
|
||||
|
||||
protected void setApplyPersonName() {
|
||||
DynamicObject labour = (DynamicObject) this.getModel().getValue("labour");
|
||||
if (labour != null && !StringUtils.equals(LabourTeamEnum.INTERNAL.getValue(), labour.getString("team"))) {
|
||||
this.getModel().setValue("applypersonname", this.getModel().getValue("reqpersonname"));
|
||||
} else {
|
||||
DynamicObject applyPerson = (DynamicObject) this.getModel().getValue("requestperson");
|
||||
this.getModel().setValue("applypersonname", applyPerson == null ? "" : applyPerson.getString("name"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void assQtyChanged(ChangeData changeData) {
|
||||
BigDecimal assQty = (BigDecimal) changeData.getNewValue();
|
||||
int rowIndex = changeData.getRowIndex();
|
||||
DynamicObject measureunit = (DynamicObject) this.getModel().getValue("measureunit", rowIndex);
|
||||
DynamicObject assMeasureunit = (DynamicObject) this.getModel().getValue("assmeasureunit", rowIndex);
|
||||
if (measureunit != null && assMeasureunit != null) {
|
||||
this.qtyAutoConvert(assQty, rowIndex, assMeasureunit, measureunit, "qty");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void qtyChanged(ChangeData changeData) {
|
||||
BigDecimal qty = (BigDecimal) changeData.getNewValue();
|
||||
int rowIndex = changeData.getRowIndex();
|
||||
DynamicObject measureunit = (DynamicObject) this.getModel().getValue("measureunit", rowIndex);
|
||||
DynamicObject assMeasureunit = (DynamicObject) this.getModel().getValue("assmeasureunit", rowIndex);
|
||||
if (measureunit != null && assMeasureunit != null) {
|
||||
this.qtyAutoConvert(qty, rowIndex, measureunit, assMeasureunit, "assqty");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void assMeasureUnitChanged(ChangeData changeData) {
|
||||
DynamicObject assMeasureunit = (DynamicObject) changeData.getNewValue();
|
||||
int rowIndex = changeData.getRowIndex();
|
||||
BigDecimal qty = (BigDecimal) this.getModel().getValue("qty", rowIndex);
|
||||
DynamicObject measureunit = (DynamicObject) this.getModel().getValue("measureunit", rowIndex);
|
||||
if (measureunit != null && assMeasureunit != null && qty != null && qty.compareTo(BigDecimal.ZERO) != 0) {
|
||||
this.qtyAutoConvert(qty, rowIndex, measureunit, assMeasureunit, "assqty");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void measureUnitChanged(ChangeData changeData) {
|
||||
DynamicObject measureUnit = (DynamicObject) changeData.getNewValue();
|
||||
int rowIndex = changeData.getRowIndex();
|
||||
BigDecimal assQty = (BigDecimal) this.getModel().getValue("assqty", rowIndex);
|
||||
DynamicObject assMeasureunit = (DynamicObject) this.getModel().getValue("assmeasureunit", rowIndex);
|
||||
if (measureUnit != null && assMeasureunit != null && assQty != null && assQty.compareTo(BigDecimal.ZERO) != 0) {
|
||||
this.qtyAutoConvert(assQty, rowIndex, assMeasureunit, measureUnit, "qty");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void qtyAutoConvert(BigDecimal srcQty, int rowIndex, DynamicObject srcMeasureunit, DynamicObject desMeasureunit, String qtyEntityId) {
|
||||
QFilter qFilter = new QFilter("srcmuid", "=", srcMeasureunit.getPkValue());
|
||||
qFilter.and(new QFilter("desmuid", "=", desMeasureunit.getPkValue()));
|
||||
DynamicObject[] measureunitConvs = BusinessDataServiceHelper.load("bd_measureunitconv", "srcmuid,desmuid,numerator,denominator", new QFilter[]{qFilter});
|
||||
srcQty = srcQty == null ? BigDecimal.ZERO : srcQty;
|
||||
BigDecimal assQty;
|
||||
if (measureunitConvs != null && measureunitConvs.length > 0) {
|
||||
BigDecimal numerator = measureunitConvs[0].getBigDecimal("numerator");
|
||||
numerator = numerator == null ? BigDecimal.ZERO : numerator;
|
||||
assQty = srcQty.multiply(numerator).setScale(desMeasureunit.getInt("precision"), RoundingMode.DOWN);
|
||||
} else {
|
||||
QFilter qFilter2 = new QFilter("srcmuid", "=", desMeasureunit.getPkValue());
|
||||
qFilter2.and(new QFilter("desmuid", "=", srcMeasureunit.getPkValue()));
|
||||
DynamicObject[] measureunitConvs2 = BusinessDataServiceHelper.load("bd_measureunitconv", "srcmuid,desmuid,numerator,denominator", new QFilter[]{qFilter2});
|
||||
if (measureunitConvs2 == null || measureunitConvs2.length <= 0) {
|
||||
this.getView().showTipNotification(ResManager.loadKDString("没有找到对应的换算率,无法换算,请确认或添加至换算表!", "MaterialApplyBillPlugin_0", "ec-ecma-formplugin", new Object[0]));
|
||||
return;
|
||||
}
|
||||
|
||||
BigDecimal numerator = measureunitConvs2[0].getBigDecimal("numerator");
|
||||
numerator = numerator == null ? BigDecimal.ZERO : numerator;
|
||||
assQty = numerator.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO : srcQty.divide(numerator, desMeasureunit.getInt("precision"), RoundingMode.DOWN);
|
||||
}
|
||||
|
||||
this.getModel().setValue(qtyEntityId, assQty, rowIndex);
|
||||
}
|
||||
|
||||
protected void warehouseChanged(ChangeData changeData) {
|
||||
this.getModel().deleteEntryData("entryentity");
|
||||
this.getModel().setValue("totalapplyamount", 0);
|
||||
DynamicObject newValue = (DynamicObject) changeData.getNewValue();
|
||||
if (newValue != null && this.getModel().getValue("project") == null) {
|
||||
DynamicObject depot = BusinessDataServiceHelper.loadSingle(newValue.getPkValue(), "ecma_depot");
|
||||
DynamicObject project = depot.getDynamicObject("project");
|
||||
DynamicObject unitproject = depot.getDynamicObject("unitproject");
|
||||
this.getModel().beginInit();
|
||||
if (project != null) {
|
||||
this.getModel().setValue("project", project.getPkValue());
|
||||
DynamicObject newProject = (DynamicObject) this.getModel().getValue("project");
|
||||
this.setEnableUnitProjectByProjectEditOnUnit(newProject);
|
||||
}
|
||||
|
||||
if (unitproject != null) {
|
||||
this.getModel().setValue("unitproject", unitproject.getPkValue());
|
||||
}
|
||||
|
||||
this.getModel().endInit();
|
||||
this.getView().updateView("project");
|
||||
this.getView().updateView("unitproject");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void projectChanged(ChangeData changeData) {
|
||||
Object newValue = changeData.getNewValue();
|
||||
this.setEnableUnitProjectByProjectEditOnUnit((DynamicObject) newValue);
|
||||
this.getModel().setValue("warehouse", (Object) null);
|
||||
this.getModel().setValue("labour", (Object) null);
|
||||
this.getModel().setValue("unitproject", (Object) null);
|
||||
this.setUnitProjectFieldStatus();
|
||||
}
|
||||
|
||||
protected void clearEntryRowBoq() {
|
||||
int entryentity = this.getModel().getEntryRowCount("entryentity");
|
||||
|
||||
for (int i = 0; i < entryentity; ++i) {
|
||||
this.getModel().setValue("proboq", (Object) null, i);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void labourChanged(ChangeData changeData) {
|
||||
this.initRequestPersonControl();
|
||||
DynamicObject newValue = (DynamicObject) changeData.getNewValue();
|
||||
if (newValue != null) {
|
||||
DynamicObject labour = BusinessDataServiceHelper.loadSingle(newValue.getPkValue(), "ecma_labour");
|
||||
if (labour.getDynamicObject("supplier") != null) {
|
||||
this.getModel().setValue("supplier", labour.getDynamicObject("supplier"));
|
||||
}
|
||||
|
||||
DynamicObjectCollection personEntryEntitys = labour.getDynamicObjectCollection("entryentity");
|
||||
DynamicObject unitproject;
|
||||
DynamicObject newProject;
|
||||
if (personEntryEntitys != null && !personEntryEntitys.isEmpty()) {
|
||||
String team = labour.getString("team");
|
||||
unitproject = (DynamicObject) personEntryEntitys.get(0);
|
||||
if (StringUtils.equals(team, LabourTeamEnum.INTERNAL.getValue())) {
|
||||
newProject = unitproject.getDynamicObject("pickmaterials");
|
||||
this.getModel().setValue("requestperson", newProject.getPkValue());
|
||||
} else if (StringUtils.equals(team, LabourTeamEnum.EXTERNAL.getValue())) {
|
||||
String requestPerson = unitproject.getString("pickmaterialsname");
|
||||
this.getModel().setValue("reqpersonname", requestPerson);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.getModel().getValue("project") == null) {
|
||||
DynamicObject project = labour.getDynamicObject("project");
|
||||
unitproject = labour.getDynamicObject("unitproject");
|
||||
this.getModel().beginInit();
|
||||
if (project != null) {
|
||||
this.getModel().setValue("project", project.getPkValue());
|
||||
newProject = (DynamicObject) this.getModel().getValue("project");
|
||||
this.setEnableUnitProjectByProjectEditOnUnit(newProject);
|
||||
}
|
||||
|
||||
if (unitproject != null) {
|
||||
this.getModel().setValue("unitproject", unitproject.getPkValue());
|
||||
}
|
||||
|
||||
this.getModel().endInit();
|
||||
this.getView().updateView("project");
|
||||
this.getView().updateView("unitproject");
|
||||
}
|
||||
} else {
|
||||
this.getModel().setValue("reqpersonname", "");
|
||||
this.getModel().setValue("requestperson", (Object) null);
|
||||
this.getModel().beginInit();
|
||||
if (!(Boolean) this.getModel().getValue("issupplier")) {
|
||||
this.getModel().setValue("supplier", (Object) null);
|
||||
}
|
||||
|
||||
this.getModel().setValue("project", (Object) null);
|
||||
this.getModel().setValue("supplier", (Object) null);
|
||||
this.getModel().endInit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void setEnableUnitProjectByProjectEditOnUnit(DynamicObject project) {
|
||||
if (project == null) {
|
||||
this.getView().setEnable(false, new String[]{"unitproject"});
|
||||
} else {
|
||||
Boolean editOnUnit = project.getBoolean("editonunit");
|
||||
if (editOnUnit) {
|
||||
this.getView().setEnable(true, new String[]{"unitproject"});
|
||||
} else {
|
||||
this.getView().setEnable(false, new String[]{"unitproject"});
|
||||
}
|
||||
}
|
||||
|
||||
this.getView().updateView("unitproject");
|
||||
}
|
||||
|
||||
protected void initRequestPersonControl() {
|
||||
DynamicObject labour = (DynamicObject) this.getModel().getValue("labour");
|
||||
BasedataEdit reqPersonF7;
|
||||
if (labour != null) {
|
||||
String team = labour.getString("team");
|
||||
if (StringUtils.equals(team, LabourTeamEnum.INTERNAL.getValue())) {
|
||||
ComboEdit reqPersonCombo = (ComboEdit) this.getControl("reqpersonname");
|
||||
this.getView().setVisible(false, new String[]{"reqpersonname"});
|
||||
reqPersonCombo.setMustInput(false);
|
||||
reqPersonF7 = (BasedataEdit) this.getControl("requestperson");
|
||||
this.getView().setVisible(true, new String[]{"requestperson"});
|
||||
reqPersonF7.setMustInput(true);
|
||||
} else if (StringUtils.equals(team, LabourTeamEnum.EXTERNAL.getValue())) {
|
||||
reqPersonF7 = (BasedataEdit) this.getControl("requestperson");
|
||||
this.getView().setVisible(false, new String[]{"requestperson"});
|
||||
reqPersonF7.setMustInput(false);
|
||||
ComboEdit reqPersonCombo = (ComboEdit) this.getControl("reqpersonname");
|
||||
this.getView().setVisible(true, new String[]{"reqpersonname"});
|
||||
reqPersonCombo.setMustInput(true);
|
||||
DynamicObjectCollection personEntryEntitys = labour.getDynamicObjectCollection("entryentity");
|
||||
if (personEntryEntitys != null && !personEntryEntitys.isEmpty()) {
|
||||
ArrayList<ComboItem> comboList = new ArrayList();
|
||||
Iterator var7 = personEntryEntitys.iterator();
|
||||
|
||||
while (var7.hasNext()) {
|
||||
DynamicObject person = (DynamicObject) var7.next();
|
||||
ComboItem comboItem = new ComboItem();
|
||||
LocaleString localeString = new LocaleString();
|
||||
String personName = person.getString("pickmaterialsname");
|
||||
localeString.setLocaleValue(personName);
|
||||
comboItem.setCaption(localeString);
|
||||
comboItem.setValue(personName);
|
||||
comboList.add(comboItem);
|
||||
}
|
||||
|
||||
reqPersonCombo.setComboItems(comboList);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ComboEdit reqPersonCombo = (ComboEdit) this.getControl("reqpersonname");
|
||||
this.getView().setVisible(false, new String[]{"reqpersonname"});
|
||||
reqPersonCombo.setMustInput(false);
|
||||
reqPersonF7 = (BasedataEdit) this.getControl("requestperson");
|
||||
this.getView().setVisible(true, new String[]{"requestperson"});
|
||||
reqPersonF7.setMustInput(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void supplierChanged(ChangeData changeData) {
|
||||
DynamicObject newValue = (DynamicObject) changeData.getNewValue();
|
||||
DynamicObject labour = (DynamicObject) this.getModel().getValue("labour");
|
||||
DynamicObject labourSupplier = labour == null ? null : labour.getDynamicObject("supplier");
|
||||
if (newValue == null || labourSupplier == null || !StringUtils.equals(newValue.getString("id"), labourSupplier.getString("id"))) {
|
||||
this.getModel().setValue("labour", (Object) null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void beforeF7Select(BeforeF7SelectEvent arg0) {
|
||||
String name = arg0.getProperty().getName();
|
||||
if (StringUtils.equals(name, "labour")) {
|
||||
this.beforeLabourSelect(arg0);
|
||||
} else if (StringUtils.equals(name, "requestperson")) {
|
||||
this.beforeRequestPersonSelect(arg0);
|
||||
} else if (StringUtils.equals(name, "warehouse")) {
|
||||
this.beforeWarehouseSelect(arg0);
|
||||
} else if (StringUtils.equals(name, "material")) {
|
||||
this.beforeMaterialSelect(arg0);
|
||||
} else if (StringUtils.equals(name, "contract")) {
|
||||
this.beforeContractSelect(arg0);
|
||||
} else if (StringUtils.equals(name, "transtype")) {
|
||||
this.beforeTransTypeSelect(arg0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void beforeTransTypeSelect(BeforeF7SelectEvent e) {
|
||||
ListShowParameter param = (ListShowParameter) e.getFormShowParameter();
|
||||
QFilter idFilter = new QFilter("id", "not in", Sets.newHashSet(new Long[]{PoundTransTypeEnum.POUND_IN.getDefaultId(), PoundTransTypeEnum.POUND_OUT.getDefaultId(), PoundTransTypeEnum.POUND_IN_THEN_OUT.getDefaultId()}));
|
||||
param.getListFilterParameter().getQFilters().add(idFilter);
|
||||
}
|
||||
|
||||
protected void beforeContractSelect(BeforeF7SelectEvent arg0) {
|
||||
ListShowParameter formShowParameter = (ListShowParameter) arg0.getFormShowParameter();
|
||||
ContractHelper.getContractByStatus("ecma_materialoutbill", formShowParameter, PayDirectionEnum.OUT.getValue());
|
||||
DynamicObject org = (DynamicObject) this.getModel().getValue("org");
|
||||
QFilter filter = new QFilter("org", "=", org.getPkValue());
|
||||
DynamicObject project = (DynamicObject) this.getModel().getValue("project");
|
||||
DynamicObject supplier = (DynamicObject) this.getModel().getValue("supplier");
|
||||
if (project != null) {
|
||||
filter.and(new QFilter("project", "=", project.getPkValue()));
|
||||
}
|
||||
|
||||
if (supplier != null) {
|
||||
filter.and(new QFilter("partb", "=", supplier.getPkValue()));
|
||||
}
|
||||
|
||||
formShowParameter.getListFilterParameter().getQFilters().add(filter);
|
||||
}
|
||||
|
||||
protected void beforeMaterialSelect(BeforeF7SelectEvent arg0) {
|
||||
arg0.setCancel(true);
|
||||
DynamicObject warehouse = (DynamicObject) this.getModel().getValue("warehouse");
|
||||
if (warehouse == null) {
|
||||
this.getView().showTipNotification(ResManager.loadKDString("请先选择仓库。", "MaterialApplyBillPlugin_1", "ec-ecma-formplugin", new Object[0]), 3000);
|
||||
} else {
|
||||
DynamicObject org = (DynamicObject) this.getModel().getValue("org");
|
||||
Map<String, Object> map = new HashMap();
|
||||
map.put("formId", "ecma_invmatf7");
|
||||
map.put("orgId", org == null ? null : org.getPkValue().toString());
|
||||
map.put("depotId", warehouse.getPkValue().toString());
|
||||
FormShowParameter showParameter = FormShowParameter.createFormShowParameter(map);
|
||||
List<Long> idList = new ArrayList();
|
||||
DynamicObjectCollection entryEntity = this.getModel().getEntryEntity("entryentity");
|
||||
Iterator var8 = entryEntity.iterator();
|
||||
|
||||
while (var8.hasNext()) {
|
||||
DynamicObject entry = (DynamicObject) var8.next();
|
||||
idList.add(entry.getLong("matinventory_id"));
|
||||
}
|
||||
|
||||
showParameter.setCustomParam("addfilter", new QFilter("id", "not in", idList));
|
||||
showParameter.getOpenStyle().setShowType(ShowType.Modal);
|
||||
showParameter.setCloseCallBack(new CloseCallBack(this, "inventorycallback"));
|
||||
this.getView().showForm(showParameter);
|
||||
}
|
||||
}
|
||||
|
||||
protected void beforeWarehouseSelect(BeforeF7SelectEvent arg0) {
|
||||
DynamicObject org = (DynamicObject) this.getModel().getValue("org");
|
||||
Long orgId = org == null ? 0L : (Long) org.getPkValue();
|
||||
arg0.getCustomQFilters().add(new QFilter("org", "=", orgId));
|
||||
DynamicObject project = (DynamicObject) this.getModel().getValue("project");
|
||||
if (project != null) {
|
||||
arg0.getCustomQFilters().add((new QFilter("project", "=", project.getPkValue())).or("project", "=", 0L));
|
||||
boolean editonunit = project.getBoolean("editonunit");
|
||||
if (editonunit) {
|
||||
DynamicObject unitproject = (DynamicObject) this.getModel().getValue("unitproject");
|
||||
if (unitproject == null) {
|
||||
this.getView().showTipNotification(ResManager.loadKDString("该项目按单位工程编制,请先选择单位工程。", "MaterialApplyBillPlugin_3", "ec-ecma-formplugin", new Object[0]), 3000);
|
||||
arg0.setCancel(true);
|
||||
return;
|
||||
}
|
||||
|
||||
arg0.getCustomQFilters().add((new QFilter("unitproject", "=", unitproject.getPkValue())).or(new QFilter("unitproject", "=", 0L)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void beforeRequestPersonSelect(BeforeF7SelectEvent arg0) {
|
||||
DynamicObject labour = (DynamicObject) this.getModel().getValue("labour");
|
||||
if (labour != null) {
|
||||
String team = labour.getString("team");
|
||||
if (StringUtils.equals(team, LabourTeamEnum.INTERNAL.getValue())) {
|
||||
DynamicObjectCollection personEntry = labour.getDynamicObjectCollection("entryentity");
|
||||
ArrayList<Object> pkList = new ArrayList();
|
||||
Iterator var6 = personEntry.iterator();
|
||||
|
||||
while (var6.hasNext()) {
|
||||
DynamicObject personEntryEntity = (DynamicObject) var6.next();
|
||||
DynamicObject requestPerson = personEntryEntity.getDynamicObject("pickmaterials");
|
||||
pkList.add(requestPerson.getPkValue());
|
||||
}
|
||||
|
||||
arg0.getCustomQFilters().add(new QFilter("id", "in", pkList));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void beforeLabourSelect(BeforeF7SelectEvent arg0) {
|
||||
DynamicObject project = (DynamicObject) this.getModel().getValue("project");
|
||||
if (project != null) {
|
||||
arg0.getCustomQFilters().add(new QFilter("project", "=", project.getPkValue()));
|
||||
boolean editonunit = project.getBoolean("editonunit");
|
||||
if (editonunit) {
|
||||
DynamicObject unitproject = (DynamicObject) this.getModel().getValue("unitproject");
|
||||
if (unitproject == null) {
|
||||
this.getView().showTipNotification(ResManager.loadKDString("该项目按单位工程编制,请先选择单位工程。", "MaterialApplyBillPlugin_3", "ec-ecma-formplugin", new Object[0]), 3000);
|
||||
arg0.setCancel(true);
|
||||
return;
|
||||
}
|
||||
|
||||
arg0.getCustomQFilters().add(new QFilter("unitproject", "=", unitproject.getPkValue()));
|
||||
}
|
||||
}
|
||||
|
||||
DynamicObject supplier = (DynamicObject) this.getModel().getValue("supplier");
|
||||
if (supplier != null) {
|
||||
arg0.getCustomQFilters().add(new QFilter("supplier", "=", supplier.getPkValue()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void closedCallBack(ClosedCallBackEvent closedCallBackEvent) {
|
||||
super.closedCallBack(closedCallBackEvent);
|
||||
String actionId = closedCallBackEvent.getActionId();
|
||||
Object returnData = closedCallBackEvent.getReturnData();
|
||||
if (StringUtils.equals(actionId, "inventorycallback")) {
|
||||
this.inventoryCloseCallBack(returnData);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void inventoryCloseCallBack(Object returnData) {
|
||||
String[] keys = (String[]) ((String[]) returnData);
|
||||
if (keys != null && keys.length > 0) {
|
||||
int rowCount = this.getModel().getEntryRowCount("entryentity");
|
||||
int rowIndex = this.getModel().getEntryCurrentRowIndex("entryentity");
|
||||
int newRowCount = keys.length - rowCount + rowIndex;
|
||||
if (newRowCount > 0) {
|
||||
this.getModel().batchCreateNewEntryRow("entryentity", newRowCount);
|
||||
}
|
||||
|
||||
this.getModel().updateCache();
|
||||
DynamicObject targetCurrency = (DynamicObject) this.getModel().getValue("currency");
|
||||
DynamicObject org = (DynamicObject) this.getModel().getValue("org");
|
||||
DynamicObject exRateTable = CurrencyHelper.getExRateTable(org == null ? 0L : org.getLong("id"));
|
||||
String[] var9 = keys;
|
||||
int var10 = keys.length;
|
||||
|
||||
for (int var11 = 0; var11 < var10; ++var11) {
|
||||
String key = var9[var11];
|
||||
DynamicObject materialInventory = BusinessDataServiceHelper.loadSingle(key, "ecma_matinventory");
|
||||
DynamicObject material = materialInventory.getDynamicObject("material");
|
||||
String modelnum = materialInventory.getString("modelnum");
|
||||
String lot = materialInventory.getString("lot");
|
||||
DynamicObject measureunit = materialInventory.getDynamicObject("measureunit");
|
||||
String price = materialInventory.getString("price");
|
||||
BigDecimal priceNum = new BigDecimal(price);
|
||||
DynamicObject srcCurrency = materialInventory.getDynamicObject("currency");
|
||||
BigDecimal exchangeRate = BigDecimal.ONE;
|
||||
if (targetCurrency != null && exRateTable != null && srcCurrency != null) {
|
||||
exchangeRate = CurrencyHelper.getExChangeRate(srcCurrency.getLong("id"), targetCurrency.getLong("id"), exRateTable.getLong("id"), new Date());
|
||||
}
|
||||
|
||||
exchangeRate = exchangeRate == null ? BigDecimal.ONE : exchangeRate;
|
||||
priceNum = priceNum.multiply(exchangeRate);
|
||||
BigDecimal qty = materialInventory.getBigDecimal("qty");
|
||||
QFilter filter = new QFilter("number", "=", lot);
|
||||
filter.and(new QFilter("material.id", "=", material.getPkValue()));
|
||||
filter.and(new QFilter("modelnum", "=", modelnum.trim()));
|
||||
DynamicObject[] lots = BusinessDataServiceHelper.load("ecma_material_lot", "number", new QFilter[]{filter});
|
||||
if (lots != null && lots.length > 0) {
|
||||
this.getModel().setValue("lotid", lots[0].getPkValue(), rowIndex);
|
||||
}
|
||||
|
||||
if (material != null) {
|
||||
this.getModel().setValue("material", material.getPkValue(), rowIndex);
|
||||
}
|
||||
|
||||
this.getModel().setValue("modelnum", modelnum, rowIndex);
|
||||
this.getModel().setValue("lot", lot, rowIndex);
|
||||
if (measureunit != null) {
|
||||
this.getModel().setValue("measureunit", measureunit.getPkValue(), rowIndex);
|
||||
} else {
|
||||
this.getModel().setValue("measureunit", (Object) null, rowIndex);
|
||||
}
|
||||
|
||||
this.getModel().setValue("price", priceNum, rowIndex);
|
||||
// this.getModel().setValue("qty", qty, rowIndex);
|
||||
this.getModel().setValue("matinventory", materialInventory.getPkValue(), rowIndex);
|
||||
++rowIndex;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) {
|
||||
super.afterDoOperation(afterDoOperationEventArgs);
|
||||
List<Object> successPkIds = afterDoOperationEventArgs.getOperationResult() != null ? afterDoOperationEventArgs.getOperationResult().getSuccessPkIds() : new ArrayList();
|
||||
if (((List) successPkIds).size() > 0) {
|
||||
String operateKey = afterDoOperationEventArgs.getOperateKey();
|
||||
if (StringUtils.equals(operateKey, "deleteentry")) {
|
||||
this.sumAmountToHead();
|
||||
}
|
||||
|
||||
if ("refuse".equals(operateKey)) {
|
||||
this.getModel().setValue("supplierstatus", "A");
|
||||
DynamicObject dataEntity = this.getModel().getDataEntity();
|
||||
SaveServiceHelper.save(new DynamicObject[]{dataEntity});
|
||||
this.getView().getParentView().invokeOperation("refresh");
|
||||
this.getView().close();
|
||||
this.getView().showMessage(ResManager.loadKDString("操作成功", "MaterialApplyBillPlugin_4", "ec-ecma-formplugin", new Object[0]));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue