This commit is contained in:
parent
d1ec049a68
commit
a058faf70b
|
@ -0,0 +1,770 @@
|
|||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by FernFlower decompiler)
|
||||
//
|
||||
|
||||
package zcgj.zcdev.zcdev.pr.plugin.form;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.EventObject;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import kd.bos.context.RequestContext;
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||
import kd.bos.dataentity.resource.ResManager;
|
||||
import kd.bos.dataentity.utils.StringUtils;
|
||||
import kd.bos.entity.EntityMetadataCache;
|
||||
import kd.bos.entity.datamodel.ListSelectedRowCollection;
|
||||
import kd.bos.entity.datamodel.events.ChangeData;
|
||||
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
|
||||
import kd.bos.entity.report.CellStyle;
|
||||
import kd.bos.form.CloseCallBack;
|
||||
import kd.bos.form.ConfirmCallBackListener;
|
||||
import kd.bos.form.MessageBoxOptions;
|
||||
import kd.bos.form.MessageBoxResult;
|
||||
import kd.bos.form.ShowFormHelper;
|
||||
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.events.MessageBoxClosedEvent;
|
||||
import kd.bos.form.field.BasedataEdit;
|
||||
import kd.bos.form.field.DateEdit;
|
||||
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.org.OrgUnitServiceHelper;
|
||||
import kd.ec.basedata.common.enums.BillStatusEnum;
|
||||
import kd.ec.basedata.common.enums.ResourceTypeEnum;
|
||||
import kd.ec.basedata.common.utils.MetaDataUtil;
|
||||
import kd.ec.contract.common.utils.CurrencyHelper;
|
||||
import kd.ec.material.formplugin.AbstractEcmaBillPlugin;
|
||||
|
||||
public class PurchaseApplyEditPluginExt extends AbstractEcmaBillPlugin implements BeforeF7SelectListener {
|
||||
public static final String OLD_PROJECT_VALUE = "oldProjectValue";
|
||||
public static final String CANCEL_PROJECT_CHANGED = "cancelProjectChanged";
|
||||
public static final String IS_PRICE_CHANGED = "isPriceChanged";
|
||||
public static final String IS_OF_TAX_PRICE_CHANGED = "isOfTaxPriceChanged";
|
||||
public static final String TOTAL_REQUIRE_QTY_MAP = "totalRequireQtyMap";
|
||||
public static final String TOTAL_APPLY_QTY_MAP = "totalApplyQtyMap";
|
||||
public static final String SELECTTOTALREQUIRE = "selecttotalrequire";
|
||||
public static final String INVENTORYQUERY = "inventoryquery";
|
||||
|
||||
public PurchaseApplyEditPluginExt() {
|
||||
}
|
||||
|
||||
public void registerListener(EventObject e) {
|
||||
super.registerListener(e);
|
||||
BasedataEdit unitProject = (BasedataEdit)this.getControl("unitproject");
|
||||
unitProject.addBeforeF7SelectListener(this);
|
||||
BasedataEdit labour = (BasedataEdit)this.getControl("labour");
|
||||
labour.addBeforeF7SelectListener(this);
|
||||
BasedataEdit material = (BasedataEdit)this.getControl("material");
|
||||
material.addBeforeF7SelectListener(this);
|
||||
}
|
||||
|
||||
public void afterCreateNewData(EventObject e) {
|
||||
super.afterCreateNewData(e);
|
||||
Long userId = RequestContext.get().getCurrUserId();
|
||||
this.getModel().setValue("applyer", userId);
|
||||
this.setFiOrgByOrg();
|
||||
}
|
||||
|
||||
private void setFiOrgByOrg() {
|
||||
DynamicObject org = (DynamicObject)this.getModel().getValue("org");
|
||||
if (org != null) {
|
||||
Map<String, Object> bizOrg = OrgUnitServiceHelper.getCompanyByOrg(Long.valueOf(org.getPkValue().toString()), Boolean.FALSE, Boolean.TRUE);
|
||||
this.getModel().setValue("fiaccountorg", bizOrg.get("id"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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 afterBindData(EventObject e) {
|
||||
super.afterBindData(e);
|
||||
DateEdit date = (DateEdit)this.getControl("requestdate");
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(11, 0);
|
||||
calendar.set(12, 0);
|
||||
calendar.set(13, 0);
|
||||
calendar.set(14, 0);
|
||||
date.setMinDate(calendar.getTime());
|
||||
this.initTotalPurchaseQtyColor();
|
||||
this.setUnitProjectFieldStatus();
|
||||
}
|
||||
|
||||
protected void initTotalPurchaseQtyColor() {
|
||||
EntryGrid grid = (EntryGrid)this.getControl("purchaseentry");
|
||||
List<CellStyle> cellStyles = new ArrayList(10);
|
||||
int rowCount = this.getModel().getEntryRowCount("purchaseentry");
|
||||
|
||||
for(int i = 0; i < rowCount; ++i) {
|
||||
cellStyles.add(this.generateTotalPurchaseQtyCellStyle(i));
|
||||
}
|
||||
|
||||
grid.setCellStyle(cellStyles);
|
||||
}
|
||||
|
||||
public void propertyChanged(PropertyChangedArgs e) {
|
||||
String name = e.getProperty().getName();
|
||||
if (StringUtils.equals(name, "project")) {
|
||||
this.projectChanged(e);
|
||||
} else if (!StringUtils.equals(name, "notaxamount") && !StringUtils.equals(name, "taxamount") && !StringUtils.equals(name, "oftaxamount")) {
|
||||
if (StringUtils.equals(name, "oftaxprice")) {
|
||||
this.ofTaxPriceChanged(e.getChangeSet()[0]);
|
||||
} else if (StringUtils.equals(name, "price")) {
|
||||
this.priceChanged(e.getChangeSet()[0]);
|
||||
} else if (StringUtils.equals(name, "entrytaxrate")) {
|
||||
this.entryTaxRateChanged(e.getChangeSet()[0]);
|
||||
} else if (StringUtils.equals(name, "material")) {
|
||||
this.materialChanged(e.getChangeSet()[0]);
|
||||
} else if (StringUtils.equals(name, "totalpurchaseqty")) {
|
||||
this.totalPurchaseQtyChanged(e.getChangeSet()[0]);
|
||||
} else if (StringUtils.equals(name, "unitproject")) {
|
||||
this.updateEntryQtyData();
|
||||
this.getPageCache().remove("totalRequireQtyMap");
|
||||
this.getPageCache().remove("totalApplyQtyMap");
|
||||
} else if (StringUtils.equals(name, "fiaccountorg")) {
|
||||
this.fiAccountOrgChaged(e.getChangeSet()[0]);
|
||||
}
|
||||
} else {
|
||||
this.sumAmountToHead();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void entryTaxRateChanged(ChangeData changeData) {
|
||||
BigDecimal price = (BigDecimal)this.getModel().getValue("price", changeData.getRowIndex());
|
||||
price = price == null ? BigDecimal.ZERO : price;
|
||||
BigDecimal newOfTaxPrice = price;
|
||||
DynamicObject entryTaxRate = (DynamicObject)changeData.getNewValue();
|
||||
BigDecimal oldOfTaxPrice;
|
||||
if (entryTaxRate != null) {
|
||||
oldOfTaxPrice = entryTaxRate.getBigDecimal("taxrate");
|
||||
oldOfTaxPrice = oldOfTaxPrice == null ? BigDecimal.ZERO : oldOfTaxPrice;
|
||||
newOfTaxPrice = price.multiply(oldOfTaxPrice.divide(new BigDecimal(100), 10, RoundingMode.HALF_UP).add(BigDecimal.ONE));
|
||||
}
|
||||
|
||||
oldOfTaxPrice = (BigDecimal)this.getModel().getValue("oftaxprice", changeData.getRowIndex());
|
||||
if (newOfTaxPrice.compareTo(oldOfTaxPrice) != 0) {
|
||||
this.getPageCache().put("isPriceChanged", "1");
|
||||
this.getModel().setValue("oftaxprice", newOfTaxPrice, changeData.getRowIndex());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void totalPurchaseQtyChanged(ChangeData changeData) {
|
||||
EntryGrid grid = (EntryGrid)this.getControl("purchaseentry");
|
||||
List<CellStyle> cellStyles = new ArrayList(10);
|
||||
int index = changeData.getRowIndex();
|
||||
cellStyles.add(this.generateTotalPurchaseQtyCellStyle(index));
|
||||
grid.setCellStyle(cellStyles);
|
||||
}
|
||||
|
||||
protected CellStyle generateTotalPurchaseQtyCellStyle(int index) {
|
||||
BigDecimal totalPurchaseQty = (BigDecimal)this.getModel().getValue("totalpurchaseqty", index);
|
||||
BigDecimal totalRequireQty = (BigDecimal)this.getModel().getValue("totalrequireqty", index);
|
||||
String color = "#545454";
|
||||
if (totalPurchaseQty != null && (totalRequireQty == null || totalPurchaseQty.compareTo(totalRequireQty) > 0)) {
|
||||
color = "#DC143C";
|
||||
}
|
||||
|
||||
CellStyle cellStyle = new CellStyle();
|
||||
cellStyle.setRow(index);
|
||||
cellStyle.setFieldKey("totalpurchaseqty");
|
||||
cellStyle.setForeColor(color);
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
protected void materialChanged(ChangeData changeData) {
|
||||
DynamicObject material = (DynamicObject)changeData.getNewValue();
|
||||
DynamicObject unit = (DynamicObject)this.getModel().getValue("unit", changeData.getRowIndex());
|
||||
BigDecimal requireQty = BigDecimal.ZERO;
|
||||
BigDecimal applyQty = BigDecimal.ZERO;
|
||||
if (material != null) {
|
||||
DynamicObject taxRate = (DynamicObject)this.getModel().getValue("taxrate");
|
||||
if (this.getModel().getValue("entrytaxrate", changeData.getRowIndex()) == null && taxRate != null) {
|
||||
this.getModel().setValue("entrytaxrate", taxRate.getPkValue(), changeData.getRowIndex());
|
||||
}
|
||||
|
||||
Map<String, BigDecimal> totalRequireQtyMap = this.getTotalRequireQtyMap();
|
||||
if (totalRequireQtyMap != null) {
|
||||
requireQty = (BigDecimal)totalRequireQtyMap.getOrDefault(this.concatKeyByMaterialAndUnit(material, unit), BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
Map<String, BigDecimal> totalApplyQtyMap = this.getTotalApplyQtyMap();
|
||||
if (totalApplyQtyMap != null) {
|
||||
applyQty = (BigDecimal)totalApplyQtyMap.getOrDefault(this.concatKeyByMaterialAndUnit(material, unit), BigDecimal.ZERO);
|
||||
}
|
||||
}
|
||||
|
||||
this.getModel().setValue("totalrequireqty", requireQty, changeData.getRowIndex());
|
||||
this.getModel().setValue("hispurchaseqty", applyQty, changeData.getRowIndex());
|
||||
}
|
||||
|
||||
protected Map<String, BigDecimal> getTotalApplyQtyMap() {
|
||||
DynamicObject project = (DynamicObject)this.getModel().getValue("project");
|
||||
if (project != null) {
|
||||
String mapString = this.getPageCache().get("totalApplyQtyMap");
|
||||
if (mapString != null) {
|
||||
try {
|
||||
return this.parseJsonToMap(mapString);
|
||||
} catch (Exception var4) {
|
||||
return this.queryTotalApplyData(project);
|
||||
}
|
||||
} else {
|
||||
return this.queryTotalApplyData(project);
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected Map<String, BigDecimal> queryTotalApplyData(DynamicObject project) {
|
||||
QFilter filter = new QFilter("project", "=", project.getPkValue());
|
||||
filter.and("billstatus", "=", BillStatusEnum.AUDIT.getValue());
|
||||
DynamicObject unitProject = this.getModel().getDataEntity().getDynamicObject("unitproject");
|
||||
QFilter unitProFilter;
|
||||
if (unitProject != null) {
|
||||
unitProFilter = new QFilter("unitproject", "=", unitProject.getPkValue());
|
||||
filter.and(unitProFilter);
|
||||
} else {
|
||||
unitProFilter = new QFilter("unitproject", "=", 0L);
|
||||
filter.and(unitProFilter);
|
||||
}
|
||||
|
||||
DynamicObject[] applyBills = BusinessDataServiceHelper.load("ecma_purchaseapply", "purchaseentry,purchaseentry.material,purchaseentry.unit,purchaseentry.purchaseqty", new QFilter[]{filter});
|
||||
if (applyBills != null && applyBills.length > 0) {
|
||||
Map<String, BigDecimal> qtyMap = new HashMap(16);
|
||||
DynamicObject[] var6 = applyBills;
|
||||
int var7 = applyBills.length;
|
||||
|
||||
for(int var8 = 0; var8 < var7; ++var8) {
|
||||
DynamicObject applyBill = var6[var8];
|
||||
DynamicObjectCollection entries = applyBill.getDynamicObjectCollection("purchaseentry");
|
||||
if (entries != null && !entries.isEmpty()) {
|
||||
Iterator var11 = entries.iterator();
|
||||
|
||||
while(var11.hasNext()) {
|
||||
DynamicObject entry = (DynamicObject)var11.next();
|
||||
DynamicObject material = entry.getDynamicObject("material");
|
||||
DynamicObject unit = entry.getDynamicObject("unit");
|
||||
BigDecimal qty = entry.getBigDecimal("purchaseqty");
|
||||
this.summaryQtyToMap(qtyMap, material, unit, qty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.getPageCache().put("totalApplyQtyMap", JSONObject.toJSONString(qtyMap));
|
||||
return qtyMap;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected void summaryQtyToMap(Map<String, BigDecimal> qtyMap, DynamicObject material, DynamicObject unit, BigDecimal qty) {
|
||||
if (material != null) {
|
||||
String key = this.concatKeyByMaterialAndUnit(material, unit);
|
||||
BigDecimal totalQty = (BigDecimal)qtyMap.getOrDefault(key, BigDecimal.ZERO);
|
||||
totalQty = totalQty.add(qty);
|
||||
if (totalQty.compareTo(BigDecimal.ZERO) != 0) {
|
||||
qtyMap.put(key, totalQty);
|
||||
} else {
|
||||
qtyMap.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected Map<String, BigDecimal> parseJsonToMap(String mapString) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(mapString);
|
||||
Set<Map.Entry<String, Object>> entries = jsonObject.entrySet();
|
||||
Map<String, BigDecimal> qtyMap = new HashMap(16);
|
||||
Iterator var5 = entries.iterator();
|
||||
|
||||
while(var5.hasNext()) {
|
||||
Map.Entry<String, Object> entry = (Map.Entry)var5.next();
|
||||
qtyMap.put(entry.getKey(), (BigDecimal)entry.getValue());
|
||||
}
|
||||
|
||||
return qtyMap;
|
||||
}
|
||||
|
||||
protected Map<String, BigDecimal> getTotalRequireQtyMap() {
|
||||
DynamicObject project = (DynamicObject)this.getModel().getValue("project");
|
||||
if (project != null) {
|
||||
String mapString = this.getPageCache().get("totalRequireQtyMap");
|
||||
if (mapString != null) {
|
||||
try {
|
||||
return this.parseJsonToMap(mapString);
|
||||
} catch (Exception var4) {
|
||||
return this.queryTotalRequireData(project);
|
||||
}
|
||||
} else {
|
||||
return this.queryTotalRequireData(project);
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected Map<String, BigDecimal> queryTotalRequireData(DynamicObject project) {
|
||||
QFilter filter = new QFilter("project", "=", project.getPkValue());
|
||||
filter.and("billstatus", "=", BillStatusEnum.AUDIT.getValue());
|
||||
filter.and("isvalid", "=", "1");
|
||||
DynamicObject unitProject = this.getModel().getDataEntity().getDynamicObject("unitproject");
|
||||
QFilter unitProFilter;
|
||||
if (unitProject != null) {
|
||||
unitProFilter = new QFilter("unitproject", "=", unitProject.getPkValue());
|
||||
filter.and(unitProFilter);
|
||||
} else {
|
||||
unitProFilter = new QFilter("unitproject", "=", 0L);
|
||||
filter.and(unitProFilter);
|
||||
}
|
||||
|
||||
DynamicObject[] totalRequireBills = BusinessDataServiceHelper.load("ecma_totalrequireplan", "entryentity,entryentity.materiel,entryentity.unit,entryentity.qty", new QFilter[]{filter});
|
||||
if (totalRequireBills != null && totalRequireBills.length > 0) {
|
||||
DynamicObjectCollection entries = totalRequireBills[0].getDynamicObjectCollection("entryentity");
|
||||
if (entries != null && !entries.isEmpty()) {
|
||||
Map<String, BigDecimal> qtyMap = new HashMap(16);
|
||||
Iterator var7 = entries.iterator();
|
||||
|
||||
while(var7.hasNext()) {
|
||||
DynamicObject entry = (DynamicObject)var7.next();
|
||||
DynamicObject material = entry.getDynamicObject("materiel");
|
||||
DynamicObject unit = entry.getDynamicObject("unit");
|
||||
BigDecimal qty = entry.getBigDecimal("qty");
|
||||
this.summaryQtyToMap(qtyMap, material, unit, qty);
|
||||
}
|
||||
|
||||
this.getPageCache().put("totalRequireQtyMap", JSONObject.toJSONString(qtyMap));
|
||||
return qtyMap;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String concatKeyByMaterialAndUnit(DynamicObject material, DynamicObject unit) {
|
||||
return (material == null ? "0" : material.getString("id")) + "&" + (unit == null ? "0" : unit.getString("id"));
|
||||
}
|
||||
|
||||
protected void priceChanged(ChangeData changeData) {
|
||||
if (this.getPageCache().get("isOfTaxPriceChanged") != null) {
|
||||
this.getPageCache().remove("isOfTaxPriceChanged");
|
||||
} else {
|
||||
BigDecimal newPrice = (BigDecimal)changeData.getNewValue();
|
||||
newPrice = newPrice == null ? BigDecimal.ZERO : newPrice;
|
||||
BigDecimal newOfTaxPrice = newPrice;
|
||||
DynamicObject entryTaxRate = (DynamicObject)this.getModel().getValue("entrytaxrate", changeData.getRowIndex());
|
||||
if (entryTaxRate != null) {
|
||||
BigDecimal taxRate = entryTaxRate.getBigDecimal("taxrate");
|
||||
taxRate = taxRate == null ? BigDecimal.ZERO : taxRate;
|
||||
newOfTaxPrice = newPrice.multiply(taxRate.divide(new BigDecimal(100), 10, RoundingMode.HALF_UP).add(BigDecimal.ONE));
|
||||
}
|
||||
|
||||
this.getPageCache().put("isPriceChanged", "1");
|
||||
this.getModel().setValue("oftaxprice", newOfTaxPrice, changeData.getRowIndex());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void ofTaxPriceChanged(ChangeData changeData) {
|
||||
if (this.getPageCache().get("isPriceChanged") != null) {
|
||||
this.getPageCache().remove("isPriceChanged");
|
||||
} else {
|
||||
BigDecimal newOfTaxPrice = (BigDecimal)changeData.getNewValue();
|
||||
newOfTaxPrice = newOfTaxPrice == null ? BigDecimal.ZERO : newOfTaxPrice;
|
||||
BigDecimal newPrice = newOfTaxPrice;
|
||||
DynamicObject entryTaxRate = (DynamicObject)this.getModel().getValue("entrytaxrate", changeData.getRowIndex());
|
||||
if (entryTaxRate != null) {
|
||||
BigDecimal taxRate = entryTaxRate.getBigDecimal("taxrate");
|
||||
taxRate = taxRate == null ? BigDecimal.ZERO : taxRate;
|
||||
newPrice = newOfTaxPrice.divide(taxRate.divide(new BigDecimal(100), 10, RoundingMode.HALF_UP).add(BigDecimal.ONE), 10, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
this.getPageCache().put("isOfTaxPriceChanged", "1");
|
||||
this.getModel().setValue("price", newPrice, changeData.getRowIndex());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void projectChanged(PropertyChangedArgs e) {
|
||||
if (this.getPageCache().get("cancelProjectChanged") != null) {
|
||||
this.getPageCache().remove("cancelProjectChanged");
|
||||
} else {
|
||||
ChangeData[] changeSet = e.getChangeSet();
|
||||
DynamicObject newProject = changeSet[0].getNewValue() == null ? null : (DynamicObject)changeSet[0].getNewValue();
|
||||
if (newProject == null) {
|
||||
this.getModel().setValue("fiaccountorg", (Object)null);
|
||||
} else {
|
||||
this.getModel().setValue("fiaccountorg", newProject.getDynamicObject("fiaccountorg"));
|
||||
}
|
||||
|
||||
DynamicObjectCollection entries = this.getModel().getEntryEntity("purchaseentry");
|
||||
if (entries != null && !entries.isEmpty()) {
|
||||
Iterator var5 = entries.iterator();
|
||||
|
||||
while(var5.hasNext()) {
|
||||
DynamicObject entry = (DynamicObject)var5.next();
|
||||
if (entry.getDynamicObject("labour") != null) {
|
||||
DynamicObject oldValue = (DynamicObject)changeSet[0].getOldValue();
|
||||
if (oldValue != null) {
|
||||
this.getPageCache().put("oldProjectValue", oldValue.getPkValue().toString());
|
||||
}
|
||||
|
||||
this.getView().showConfirm(ResManager.loadKDString("切换项目将清空分录中劳务班组字段,请确认。", "PurchaseApplyEditPlugin_0", "ec-ecma-formplugin", new Object[0]), MessageBoxOptions.OKCancel, new ConfirmCallBackListener("project"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.updateEntryQtyData();
|
||||
this.getModel().setValue("unitproject", (Object)null);
|
||||
this.getPageCache().remove("totalRequireQtyMap");
|
||||
this.getPageCache().remove("totalApplyQtyMap");
|
||||
this.setUnitProjectFieldStatus();
|
||||
}
|
||||
}
|
||||
|
||||
private void fiAccountOrgChaged(ChangeData changeData) {
|
||||
DynamicObject fiAccountOrg = changeData.getNewValue() == null ? null : (DynamicObject)changeData.getNewValue();
|
||||
DynamicObject currency;
|
||||
if (fiAccountOrg != null) {
|
||||
currency = CurrencyHelper.getCurrency((Long)fiAccountOrg.getPkValue());
|
||||
if (currency != null) {
|
||||
boolean isMutiCurrency = this.getModel().getDataEntity().getBoolean("ismulticurrency");
|
||||
if (isMutiCurrency) {
|
||||
this.getModel().setValue("stdcurrency", currency);
|
||||
} else {
|
||||
this.getModel().setValue("stdcurrency", currency);
|
||||
this.getModel().setValue("currency", currency);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
currency = this.getModel().getDataEntity().getDynamicObject("org");
|
||||
if (currency != null) {
|
||||
// DynamicObject currency = CurrencyHelper.getCurrency((Long)currency.getPkValue());//源码
|
||||
currency = CurrencyHelper.getCurrency((Long) currency.getPkValue());//二开修改
|
||||
if (currency != null) {
|
||||
boolean isMutiCurrency = this.getModel().getDataEntity().getBoolean("ismulticurrency");
|
||||
if (isMutiCurrency) {
|
||||
this.getModel().setValue("stdcurrency", currency);
|
||||
} else {
|
||||
this.getModel().setValue("stdcurrency", currency);
|
||||
this.getModel().setValue("currency", currency);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void updateEntryQtyData() {
|
||||
Map<String, BigDecimal> totalApplyQtyMap = this.getTotalApplyQtyMap();
|
||||
Map<String, BigDecimal> totalRequireQtyMap = this.getTotalRequireQtyMap();
|
||||
int rowCount = this.getModel().getEntryRowCount("purchaseentry");
|
||||
|
||||
for(int i = 0; i < rowCount; ++i) {
|
||||
DynamicObject material = (DynamicObject)this.getModel().getValue("material", i);
|
||||
DynamicObject unit = (DynamicObject)this.getModel().getValue("unit", i);
|
||||
BigDecimal totalApplyQty = totalApplyQtyMap == null ? BigDecimal.ZERO : (BigDecimal)totalApplyQtyMap.getOrDefault(this.concatKeyByMaterialAndUnit(material, unit), BigDecimal.ZERO);
|
||||
BigDecimal totalRequireQty = totalRequireQtyMap == null ? BigDecimal.ZERO : (BigDecimal)totalRequireQtyMap.getOrDefault(this.concatKeyByMaterialAndUnit(material, unit), BigDecimal.ZERO);
|
||||
this.getModel().setValue("hispurchaseqty", totalApplyQty, i);
|
||||
this.getModel().setValue("totalrequireqty", totalRequireQty, i);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) {
|
||||
super.afterDoOperation(afterDoOperationEventArgs);
|
||||
String operateKey = afterDoOperationEventArgs.getOperateKey();
|
||||
if (StringUtils.equals(operateKey, "deleteentry")) {
|
||||
this.sumAmountToHead();
|
||||
} else if (StringUtils.equals(operateKey, "newentry")) {
|
||||
this.afterNewEntry();
|
||||
} else if (StringUtils.equals(operateKey, "selecttotalrequire")) {
|
||||
this.doSelectTotalRequire();
|
||||
} else if (StringUtils.equals(operateKey, "inventoryquery")) {
|
||||
this.doInventoryQuery();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void doSelectTotalRequire() {
|
||||
DynamicObject project = (DynamicObject)this.getModel().getValue("project");
|
||||
if (project == null) {
|
||||
this.getView().showTipNotification(ResManager.loadKDString("请先填写“项目”。", "PurchaseApplyEditPlugin_1", "ec-ecma-formplugin", new Object[0]));
|
||||
} else {
|
||||
QFilter filter = new QFilter("project", "=", project.getPkValue());
|
||||
filter.and("billstatus", "=", BillStatusEnum.AUDIT.getValue());
|
||||
filter.and("isvalid", "=", "1");
|
||||
DynamicObject unitProject = this.getModel().getDataEntity().getDynamicObject("unitproject");
|
||||
Boolean isUnitProject = project.getBoolean("editonunit");
|
||||
if (Boolean.TRUE.equals(isUnitProject) && unitProject == null) {
|
||||
this.getView().showTipNotification(ResManager.loadKDString("请先填写单位工程。", "PurchaseApplyEditPlugin_3", "ec-ecma-formplugin", new Object[0]));
|
||||
} else {
|
||||
if (unitProject != null) {
|
||||
QFilter unitProFilter = new QFilter("unitproject", "=", unitProject.getPkValue());
|
||||
filter.and(unitProFilter);
|
||||
}
|
||||
|
||||
DynamicObject[] totalRequireBills = BusinessDataServiceHelper.load("ecma_totalrequireplan", "entryentity,entryentity.materiel", new QFilter[]{filter});
|
||||
if (totalRequireBills != null && totalRequireBills.length > 0) {
|
||||
DynamicObjectCollection entries = totalRequireBills[0].getDynamicObjectCollection("entryentity");
|
||||
List<Object> entryIds = new ArrayList();
|
||||
if (entries != null && !entries.isEmpty()) {
|
||||
Set<Object> materialIdSet = this.getMaterialIdSet();
|
||||
Iterator var9 = entries.iterator();
|
||||
|
||||
while(var9.hasNext()) {
|
||||
DynamicObject entry = (DynamicObject)var9.next();
|
||||
if (entry.getDynamicObject("materiel") != null && !materialIdSet.contains(entry.getDynamicObject("materiel").getPkValue())) {
|
||||
entryIds.add(entry.getPkValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (entryIds.size() > 0) {
|
||||
ListShowParameter parameter = ShowFormHelper.createShowListForm("ecma_totalrequireentryf7", true);
|
||||
parameter.getListFilterParameter().getQFilters().add(new QFilter("id", "in", entryIds));
|
||||
parameter.getListFilterParameter().getQFilters().add(new QFilter("materiel.resourcetype", "!=", "06"));
|
||||
parameter.setFormId("ecbd_listf7");
|
||||
CloseCallBack callBack = new CloseCallBack(this, "selecttotalrequire");
|
||||
parameter.setCloseCallBack(callBack);
|
||||
this.getView().showForm(parameter);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.getView().showTipNotification(String.format(ResManager.loadKDString("当前项目不存在有效的%s。", "PurchaseApplyEditPlugin_2", "ec-ecma-formplugin", new Object[0]), MetaDataUtil.getDisplayName("ecma_totalrequireplan")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void doInventoryQuery() {
|
||||
EntryGrid purchaseEntryGrid = (EntryGrid)this.getControl("purchaseentry");
|
||||
int[] selectRows = purchaseEntryGrid.getSelectRows();
|
||||
if (selectRows.length == 0) {
|
||||
this.getView().showTipNotification(ResManager.loadKDString("请先勾选具体的资源", "PurchaseApplyEditPlugin_4", "ec-ecma-formplugin", new Object[0]));
|
||||
} else if (selectRows.length > 1) {
|
||||
this.getView().showTipNotification(ResManager.loadKDString("请选择一行数据进行即时库存查询", "PurchaseApplyEditPlugin_9", "ec-ecma-formplugin", new Object[0]));
|
||||
} else {
|
||||
DynamicObject entryRowEntity = this.getModel().getEntryRowEntity("purchaseentry", selectRows[0]);
|
||||
DynamicObject material = null;
|
||||
if (entryRowEntity != null) {
|
||||
material = entryRowEntity.getDynamicObject("material");
|
||||
}
|
||||
|
||||
if (material != null) {
|
||||
Set<String> resourceTypeSet = new HashSet(3);
|
||||
resourceTypeSet.add(ResourceTypeEnum.MATERIAL.getValue());
|
||||
resourceTypeSet.add(ResourceTypeEnum.TURNOVER.getValue());
|
||||
resourceTypeSet.add(ResourceTypeEnum.COMPOSITE.getValue());
|
||||
if (!resourceTypeSet.contains(material.getString("resourcetype"))) {
|
||||
this.getView().showTipNotification(ResManager.loadKDString("仅支持资源性质为物资清单、复合料清单、周材清单的库存查询", "PurchaseApplyEditPlugin_6", "ec-ecma-formplugin", new Object[0]));
|
||||
} else {
|
||||
ListShowParameter listShowParameter = ShowFormHelper.createShowListForm("ecma_matinventory", false, 2);
|
||||
listShowParameter.getOpenStyle().setShowType(ShowType.Modal);
|
||||
listShowParameter.getListFilterParameter().getQFilters().add(new QFilter("material", "=", material.getPkValue()));
|
||||
DynamicObject org = (DynamicObject)this.getModel().getValue("org");
|
||||
if (org != null) {
|
||||
listShowParameter.getListFilterParameter().getQFilters().add(new QFilter("org", "=", org.getPkValue()));
|
||||
}
|
||||
|
||||
DynamicObject project = (DynamicObject)this.getModel().getValue("project");
|
||||
if (project != null) {
|
||||
listShowParameter.getListFilterParameter().getQFilters().add(new QFilter("project", "=", project.getPkValue()));
|
||||
}
|
||||
|
||||
DynamicObject unitproject = (DynamicObject)this.getModel().getValue("unitproject");
|
||||
if (unitproject != null) {
|
||||
listShowParameter.getListFilterParameter().getQFilters().add(new QFilter("warehouse.unitproject", "=", unitproject.getPkValue()));
|
||||
}
|
||||
|
||||
this.getView().showForm(listShowParameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void afterNewEntry() {
|
||||
DynamicObject taxRate = (DynamicObject)this.getModel().getValue("taxrate");
|
||||
if (taxRate != null) {
|
||||
int index = this.getModel().getEntryCurrentRowIndex("purchaseentry");
|
||||
this.getModel().setValue("entrytaxrate", taxRate.getPkValue(), index);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void sumAmountToHead() {
|
||||
EntryGrid grid = (EntryGrid)this.getControl("purchaseentry");
|
||||
this.getModel().setValue("amount", grid.getSum("notaxamount"));
|
||||
this.getModel().setValue("oftax", grid.getSum("oftaxamount"));
|
||||
this.getModel().setValue("tax", grid.getSum("taxamount"));
|
||||
}
|
||||
|
||||
public void beforeF7Select(BeforeF7SelectEvent beforeF7SelectEvent) {
|
||||
String name = beforeF7SelectEvent.getProperty().getName();
|
||||
if (StringUtils.equals(name, "unitproject")) {
|
||||
this.beforeUnitProjectSelect(beforeF7SelectEvent);
|
||||
} else if (StringUtils.equals(name, "labour")) {
|
||||
this.beforeLabourSelect(beforeF7SelectEvent);
|
||||
} else if (StringUtils.equals(name, "material")) {
|
||||
this.beforeMaterialSelect(beforeF7SelectEvent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void beforeMaterialSelect(BeforeF7SelectEvent beforeF7SelectEvent) {
|
||||
Set<Object> materialIds = this.getMaterialIdSet();
|
||||
beforeF7SelectEvent.addCustomQFilter(new QFilter("id", "not in", materialIds));
|
||||
}
|
||||
|
||||
protected Set<Object> getMaterialIdSet() {
|
||||
int rowCount = this.getModel().getEntryRowCount("purchaseentry");
|
||||
Set<Object> materialIds = new HashSet(rowCount);
|
||||
if (rowCount > 0) {
|
||||
for(int i = 0; i < rowCount; ++i) {
|
||||
DynamicObject material = (DynamicObject)this.getModel().getValue("material", i);
|
||||
if (material != null) {
|
||||
materialIds.add(material.getPkValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return materialIds;
|
||||
}
|
||||
|
||||
protected void beforeLabourSelect(BeforeF7SelectEvent beforeF7SelectEvent) {
|
||||
DynamicObject project = (DynamicObject)this.getModel().getValue("project");
|
||||
if (project == null) {
|
||||
this.getView().showTipNotification(ResManager.loadKDString("请先填写“项目”。", "PurchaseApplyEditPlugin_1", "ec-ecma-formplugin", new Object[0]));
|
||||
beforeF7SelectEvent.setCancel(true);
|
||||
} else {
|
||||
QFilter filter = new QFilter("project", "=", project.getPkValue());
|
||||
beforeF7SelectEvent.addCustomQFilter(filter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void beforeUnitProjectSelect(BeforeF7SelectEvent beforeF7SelectEvent) {
|
||||
DynamicObject project = (DynamicObject)this.getModel().getValue("project");
|
||||
QFilter filter = new QFilter("parent", "=", project != null ? project.getPkValue() : 0L);
|
||||
beforeF7SelectEvent.addCustomQFilter(filter);
|
||||
}
|
||||
|
||||
public void closedCallBack(ClosedCallBackEvent closedCallBackEvent) {
|
||||
super.closedCallBack(closedCallBackEvent);
|
||||
String actionId = closedCallBackEvent.getActionId();
|
||||
if (StringUtils.equals(actionId, "selecttotalrequire")) {
|
||||
this.totalRequireCallBack(closedCallBackEvent.getReturnData());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void totalRequireCallBack(Object returnData) {
|
||||
ListSelectedRowCollection rows = (ListSelectedRowCollection)returnData;
|
||||
if (rows != null && !rows.isEmpty()) {
|
||||
DynamicObject[] requireEntries = BusinessDataServiceHelper.load(rows.getPrimaryKeyValues(), EntityMetadataCache.getDataEntityType("ecma_totalrequireentryf7"));
|
||||
if (requireEntries != null && requireEntries.length > 0) {
|
||||
int[] indexArr = this.getModel().batchCreateNewEntryRow("purchaseentry", requireEntries.length);
|
||||
this.getModel().updateCache();
|
||||
|
||||
for(int i = 0; i < requireEntries.length; ++i) {
|
||||
DynamicObject requireEntry = requireEntries[i];
|
||||
int index = indexArr[i];
|
||||
this.getPageCache().put("isPriceChanged", "1");
|
||||
this.getPageCache().put("isOfTaxPriceChanged", "1");
|
||||
DynamicObject material = requireEntry.getDynamicObject("materiel");
|
||||
if (material != null) {
|
||||
this.getModel().setValue("material", material.getPkValue(), index);
|
||||
}
|
||||
|
||||
DynamicObject unit = requireEntry.getDynamicObject("unit");
|
||||
if (unit != null) {
|
||||
this.getModel().setValue("unit", unit.getPkValue(), index);
|
||||
}
|
||||
|
||||
this.getModel().setValue("purchaseqty", requireEntry.getBigDecimal("qty"), index);
|
||||
DynamicObject taxRateObj = requireEntry.getDynamicObject("entrytaxrate");
|
||||
if (taxRateObj != null) {
|
||||
this.getModel().setValue("entrytaxrate", taxRateObj.getPkValue(), index);
|
||||
this.getModel().setValue("price", requireEntry.getBigDecimal("oftaxprice"), index);
|
||||
this.getModel().setValue("oftaxprice", requireEntry.getBigDecimal("price"), index);
|
||||
} else {
|
||||
taxRateObj = (DynamicObject)this.getModel().getValue("entrytaxrate", index);
|
||||
BigDecimal taxRate = taxRateObj == null ? BigDecimal.ONE : taxRateObj.getBigDecimal("taxrate");
|
||||
this.getModel().setValue("price", requireEntry.getBigDecimal("oftaxprice"), index);
|
||||
this.getModel().setValue("oftaxprice", requireEntry.getBigDecimal("oftaxprice").multiply(BigDecimal.ONE.add(taxRate.divide(new BigDecimal("100"), 4))), index);
|
||||
}
|
||||
|
||||
this.getPageCache().remove("isPriceChanged");
|
||||
this.getPageCache().remove("isOfTaxPriceChanged");
|
||||
DynamicObject labour = requireEntry.getDynamicObject("labour");
|
||||
if (labour != null) {
|
||||
this.getModel().setValue("labour", labour.getPkValue(), index);
|
||||
}
|
||||
|
||||
this.getModel().setValue("totalrequireqty", requireEntry.getBigDecimal("qty"), index);
|
||||
this.getModel().setValue("qualityrequirement", requireEntry.getString("qualityrequire"), index);
|
||||
this.getModel().setValue("purchasemethod", requireEntry.getString("suppliermode"), index);
|
||||
this.getModel().setValue("remarks", requireEntry.getString("remark"), index);
|
||||
}
|
||||
|
||||
this.initTotalPurchaseQtyColor();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void confirmCallBack(MessageBoxClosedEvent messageBoxClosedEvent) {
|
||||
super.confirmCallBack(messageBoxClosedEvent);
|
||||
String callBackId = messageBoxClosedEvent.getCallBackId();
|
||||
if (StringUtils.equals(callBackId, "project")) {
|
||||
this.projectConfirmCallBack(messageBoxClosedEvent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void projectConfirmCallBack(MessageBoxClosedEvent messageBoxClosedEvent) {
|
||||
if (MessageBoxResult.Yes.equals(messageBoxClosedEvent.getResult())) {
|
||||
int rowCount = this.getModel().getEntryRowCount("purchaseentry");
|
||||
|
||||
for(int i = 0; i < rowCount; ++i) {
|
||||
this.getModel().setValue("labour", (Object)null, i);
|
||||
}
|
||||
|
||||
this.updateEntryQtyData();
|
||||
this.getModel().setValue("unitproject", (Object)null);
|
||||
this.getPageCache().remove("totalRequireQtyMap");
|
||||
this.getPageCache().remove("totalApplyQtyMap");
|
||||
} else {
|
||||
this.getPageCache().put("cancelProjectChanged", "1");
|
||||
this.getModel().setValue("project", this.getPageCache().get("oldProjectValue"));
|
||||
this.getPageCache().remove("oldProjectValue");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue