设备成本核算取数逻辑
This commit is contained in:
parent
28de0f7263
commit
6af8068791
|
|
@ -0,0 +1,150 @@
|
|||
package zcgj.zcdev.zcdev.pr.plugin.form;
|
||||
|
||||
import kd.bos.bill.AbstractBillPlugIn;
|
||||
import kd.bos.dataentity.OperateOption;
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||
import kd.bos.dataentity.entity.LocaleString;
|
||||
import kd.bos.dataentity.utils.StringUtils;
|
||||
import kd.bos.entity.operate.result.OperationResult;
|
||||
import kd.bos.form.ConfirmCallBackListener;
|
||||
import kd.bos.form.MessageBoxOptions;
|
||||
import kd.bos.form.control.Control;
|
||||
import kd.bos.form.control.events.BeforeClickEvent;
|
||||
import kd.bos.form.control.events.BeforeItemClickEvent;
|
||||
import kd.bos.orm.query.QCP;
|
||||
import kd.bos.orm.query.QFilter;
|
||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||
import kd.bos.servicehelper.operation.OperationServiceHelper;
|
||||
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||
import kd.bos.servicehelper.user.UserServiceHelper;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.YearMonth;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
import java.util.EventObject;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static kd.ai.gai.core.Constant.RepoInfo.number;
|
||||
|
||||
/**
|
||||
* 设备成本核算自动取数逻辑
|
||||
*/
|
||||
public class EquipmentCostAutoGetDataFormPlugin extends AbstractBillPlugIn {
|
||||
|
||||
@Override
|
||||
public void registerListener(EventObject e) {
|
||||
super.registerListener(e);
|
||||
//监听工具栏按钮点击事件
|
||||
this.addItemClickListeners("advcontoolbarap");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeItemClick(BeforeItemClickEvent evt) {
|
||||
//工具栏上的所有按钮的点击都会激活itemClick和beforeItemClick方法, 需 //要开发人员实现不同按钮的逻辑
|
||||
if (evt.getItemKey().equals("autosplit")) {
|
||||
Long currentUserId = UserServiceHelper.getCurrentUserId();
|
||||
|
||||
// this.getView().showMessage("自动取数 beforeItemClick");
|
||||
DynamicObject org = (DynamicObject)this.getModel().getValue("org");//所属组织
|
||||
DynamicObject project = (DynamicObject)this.getModel().getValue("project");//工程项目
|
||||
DynamicObject splitperiod = (DynamicObject)this.getModel().getValue("splitperiod");//期间
|
||||
|
||||
if(org!=null){
|
||||
long orgId = org.getLong("id");
|
||||
QFilter filterOrgId = new QFilter("zcgj_entryentity.zcgj_zjuseorg", QCP.equals,orgId);
|
||||
filterOrgId.and(new QFilter("billstatus", QCP.equals,"C"));
|
||||
DynamicObject[] equipinfoArray = BusinessDataServiceHelper.load("eceq_equipinfo",
|
||||
"creator,zcgj_entryentity.zcgj_assperiod,zcgj_entryentity.zcgj_headusedept,zcgj_entryentity.zcgj_entrybillno,zcgj_entryentity.zcgj_shareamount", new QFilter[]{filterOrgId});
|
||||
|
||||
DynamicObject[] loadsettle = BusinessDataServiceHelper.load("eceq_settle", "",
|
||||
new QFilter[]{new QFilter("org", "=", org.getLong("id"))
|
||||
, new QFilter("period", "=", splitperiod.getLong("id")),
|
||||
new QFilter("billstatus", "=", "C").or(new QFilter("billstatus", "=", "B"))});
|
||||
if(loadsettle.length == 0){
|
||||
//eceq_settle
|
||||
DynamicObject eceqsettle =BusinessDataServiceHelper.newDynamicObject("eceq_settle");//设备费用结算
|
||||
eceqsettle.set("org",org);
|
||||
eceqsettle.set("objecttype","1");
|
||||
eceqsettle.set("internalorg",org);
|
||||
eceqsettle.set("project",project);
|
||||
eceqsettle.set("period",splitperiod);
|
||||
String periodNumber = splitperiod.getString("number");
|
||||
Map<String, Date> monthStartAndEnd = getMonthStartAndEnd(periodNumber);
|
||||
eceqsettle.set("begindate",monthStartAndEnd.get("start"));
|
||||
eceqsettle.set("enddate",monthStartAndEnd.get("end"));
|
||||
eceqsettle.set("creator",currentUserId);
|
||||
eceqsettle.set("billname",org.getString("name")+"设备结算");
|
||||
eceqsettle.set("billstatus","A");
|
||||
int i=0;
|
||||
DynamicObjectCollection entryentity = eceqsettle.getDynamicObjectCollection("entryentity");//设备结算分录
|
||||
BigDecimal allAmount = BigDecimal.ZERO;
|
||||
for (DynamicObject equipinfo : equipinfoArray) {//设备详情
|
||||
DynamicObject eceqequipmentinfo = BusinessDataServiceHelper.loadSingle(equipinfo.getLong("id"), "eceq_equipment_info");
|
||||
DynamicObjectCollection dynamicObjectCollection = equipinfo.getDynamicObjectCollection("zcgj_entryentity");//设备详情折旧信息分录
|
||||
for (DynamicObject dynamicObject : dynamicObjectCollection) {
|
||||
DynamicObject zcgjAssperiod = dynamicObject.getDynamicObject("zcgj_assperiod");
|
||||
if(zcgjAssperiod!=null && zcgjAssperiod.getString("number").equals(periodNumber)){
|
||||
BigDecimal zcgjShareamount = dynamicObject.getBigDecimal("zcgj_shareamount");
|
||||
DynamicObject entryentityentity = entryentity.addNew();
|
||||
allAmount=allAmount.add(zcgjShareamount);
|
||||
entryentityentity.set("usestartdate",monthStartAndEnd.get("start"));//单价
|
||||
entryentityentity.set("useenddate",monthStartAndEnd.get("end"));//单价
|
||||
|
||||
entryentityentity.set("unitprice",zcgjShareamount);//单价
|
||||
entryentityentity.set("amount",zcgjShareamount);//金额
|
||||
entryentityentity.set("taxprice",zcgjShareamount);//含税单价
|
||||
entryentityentity.set("taxamount",zcgjShareamount);//含税金额
|
||||
entryentityentity.set("accountnum",1);//核算数量
|
||||
entryentityentity.set("equipment",eceqequipmentinfo);//设备名称
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
eceqsettle.set("curamount",allAmount);//本期结算金额
|
||||
eceqsettle.set("curoftaxamount",allAmount);//curoftaxamount
|
||||
|
||||
if(i>0){
|
||||
SaveServiceHelper.saveOperate("eceq_settle", new DynamicObject[]{eceqsettle}, null);//设备结算
|
||||
OperateOption option= OperateOption.create();
|
||||
OperationResult resultsubmit = OperationServiceHelper.executeOperate("submit", "eceq_settle", new DynamicObject[]{eceqsettle}, option);
|
||||
//OperationResult resultaudit = OperationServiceHelper.executeOperate("audit", "eceq_settle", new DynamicObject[]{eceqsettle}, option);
|
||||
|
||||
}else{
|
||||
//this.getView().showMessage("无设备结算生成!");
|
||||
}
|
||||
this.getView().showLoading(new LocaleString("拉取数据中,请稍后!"), 5000);
|
||||
// this.getView().showMessage("拉取数据中,请稍后!");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
super.beforeItemClick(evt);
|
||||
/*try {
|
||||
Thread.sleep(5000);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
public static Map<String, Date> getMonthStartAndEnd(String yearMonthStr) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMM");
|
||||
YearMonth yearMonth = YearMonth.parse(yearMonthStr, formatter);
|
||||
|
||||
// LocalDate 转换为 Date
|
||||
ZoneId zone = ZoneId.systemDefault();
|
||||
|
||||
Date start = Date.from(yearMonth.atDay(1).atStartOfDay(zone).toInstant());
|
||||
Date end = Date.from(yearMonth.atEndOfMonth().atTime(23, 59, 59).atZone(zone).toInstant());
|
||||
|
||||
Map<String, Date> result = new HashMap<>();
|
||||
result.put("start", start);
|
||||
result.put("end", end);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -343,7 +343,7 @@ public class NewEquipmentCardTaskPlugin extends AbstractTask {
|
|||
DynamicObject period = depresplitdetail.getDynamicObject("period");
|
||||
String periodnumber = safeGetString(period, "number");
|
||||
if (isEmpty(periodnumber)) continue;
|
||||
|
||||
//entrys.clear();
|
||||
if (existPeriodData.isEmpty() || !existPeriodData.contains(periodnumber)) {
|
||||
DynamicObject splitdept = depresplitdetail.getDynamicObject("splitdept");
|
||||
DynamicObjectCollection assentry = depresplitdetail.getDynamicObjectCollection("assentry");
|
||||
|
|
|
|||
Loading…
Reference in New Issue