123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- package fi.fa.opplugin;
- import com.alibaba.druid.util.StringUtils;
- import fi.fa.opplugin.utils.ChangeDataUtils;
- import kd.bos.dataentity.OperateOption;
- import kd.bos.dataentity.entity.DynamicObject;
- import kd.bos.dataentity.entity.DynamicObjectCollection;
- import kd.bos.entity.datamodel.ListSelectedRowCollection;
- import kd.bos.entity.operate.result.OperationResult;
- import kd.bos.form.control.events.ItemClickEvent;
- import kd.bos.list.BillList;
- import kd.bos.list.plugin.AbstractListPlugin;
- 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 java.math.BigDecimal;
- import java.util.EventObject;
- import java.util.List;
- //资产变更单中间表下推资产变更单
- public class FaChangeMidOpPlugin extends AbstractListPlugin {
- public void registerListener(EventObject e) {
- super.registerListener(e);
- this.addItemClickListeners(new String[]{"toolbarap"});
- }
- @Override
- public void itemClick(ItemClickEvent evt) {
- String itemKey = evt.getItemKey();
- if ("nckd_push".equals(itemKey)) {
- StringBuilder errMsg = new StringBuilder();
- BillList billList = (BillList)this.getControl("billlistap");
- ListSelectedRowCollection list = billList.getSelectedRows();
- Object[] primaryKeyValues = list.getPrimaryKeyValues();
- if (primaryKeyValues.length > 0) {
- for (Object pk : primaryKeyValues) {
- DynamicObject info = BusinessDataServiceHelper.loadSingle(pk, "nckd_e_change_mid");
- String nckd_flag = info.getString("nckd_flag");
- String direction = info.getString("nckd_direction");
- if ("1".equals(nckd_flag)) {
- errMsg.append("单据号: ").append(info.getString("number")).append("已经下推生成了业务处理单,不允许重复下推!");
- errMsg.append("\r\n");
- continue;
- }
- String error = ChangeDataUtils.check(info);
- if (!StringUtils.isEmpty(error)) {
- errMsg.append(error);
- errMsg.append("\r\n");
- continue;
- }
- DynamicObject busProcess = BusinessDataServiceHelper.newDynamicObject("nckd_ywcld");
- busProcess.set("nckd_bizdate", info.getDate("nckd_date_out"));//业务日期
- busProcess.set("nckd_orgfield3", ChangeDataUtils.getOrg(info.getString("nckd_dept_in")));//调入使用部门
- busProcess.set("nckd_userfield", ChangeDataUtils.getUser(info.getString("nckd_used_user")));//调入使用人
- busProcess.set("nckd_textfield1", info.getString("nckd_reason"));//调拨原因
- busProcess.set("billstatus", "A");//暂存
- busProcess.set("nckd_detailtype", "E");//业务类型(E:资产调拨)
- busProcess.set("nckd_combofield2", "2");//调拨类型(2:组织内)
- //调出方向
- if("0".equals(direction)){
- busProcess.set("creator", ChangeDataUtils.getUser(info.getString("nckd_user_out")));//创建人
- busProcess.set("nckd_applierv", ChangeDataUtils.getUser(info.getString("nckd_user_out")));//调拨申请人
- }//调入方向
- else if ("1".equals(direction)) {
- busProcess.set("creator", ChangeDataUtils.getUser(info.getString("nckd_user_in")));//创建人
- busProcess.set("nckd_applierv", ChangeDataUtils.getUser(info.getString("nckd_user_in")));//调拨申请人
- }
- List<String> codeList =ChangeDataUtils.getCardNumber(info);
- QFilter filter = new QFilter("number", QCP.in,codeList);
- filter.and("isbak", QCP.equals, "0");
- DynamicObject[] card = BusinessDataServiceHelper.load("fa_card_real","id",new QFilter[] {filter});
- for (int c = 0; c < card.length; c++) {
- DynamicObject cardInfo = BusinessDataServiceHelper.loadSingle(card[c].getPkValue(), card[c].getDynamicObjectType().getName());
- DynamicObject fin = ChangeDataUtils.queryFinCard(cardInfo.getLong("id"));
- BigDecimal originalval = BigDecimal.ZERO;
- BigDecimal accumdepre = BigDecimal.ZERO;
- BigDecimal decval = BigDecimal.ZERO;
- BigDecimal preresidualval = BigDecimal.ZERO;
- BigDecimal nckd_amountfield23 = BigDecimal.ZERO;
- BigDecimal nckd_amountfield24 = BigDecimal.ZERO;
- if (fin != null) {
- originalval = fin.getBigDecimal("originalval");//资产原值(nckd_amountfield19)
- accumdepre = fin.getBigDecimal("accumdepre");//累计折旧(nckd_amountfield20)
- decval = fin.getBigDecimal("decval");//减值准备(nckd_amountfield21)
- preresidualval = fin.getBigDecimal("preresidualval");//预计净残值(nckd_amountfield22)
- nckd_amountfield23 = originalval.subtract(accumdepre);//预计清理净值(nckd_amountfield23 = nckd_amountfield19 - nckd_amountfield20)
- nckd_amountfield24 = nckd_amountfield23.subtract(decval);//预计净残值(nckd_amountfield24 = nckd_amountfield19 - nckd_amountfield20 - nckd_amountfield21)
- }
- //创建资产调拨分录
- DynamicObjectCollection entryEntity = busProcess.getDynamicObjectCollection("nckd_entryentity216");
- DynamicObject entry1 = entryEntity.addNew();
- entry1.set("nckd_basedatafield5", cardInfo);//资产编码
- entry1.set("nckd_amountfield19", originalval);//预计清理原值
- entry1.set("nckd_amountfield20", accumdepre);//预计清理累计折旧
- entry1.set("nckd_amountfield21", decval);//预计清理减值准备
- entry1.set("nckd_amountfield22", preresidualval);//预计清理残值
- entry1.set("nckd_amountfield23", nckd_amountfield23);//预计清理净值
- entry1.set("nckd_amountfield24", nckd_amountfield24);//预计清理净额
- }
- //执行保存-提交-审核
- OperationResult saveResult = SaveServiceHelper.saveOperate("nckd_ywcld", new DynamicObject[]{busProcess}, OperateOption.create());
- if (saveResult.isSuccess()){
- info.set("nckd_flag", "1");
- SaveServiceHelper.save(new DynamicObject[]{info});
- errMsg.append("单据号: ").append(info.getString("number")).append("下推生成业务处理单成功!");
- errMsg.append("\r\n");
- OperationResult submitResult = OperationServiceHelper.executeOperate("submit", "nckd_ywcld",saveResult.getSuccessPkIds().toArray(),OperateOption.create());
- OperationResult auditResult = OperationServiceHelper.executeOperate("audit", "nckd_ywcld",submitResult.getSuccessPkIds().toArray(),OperateOption.create());
- }else {
- errMsg.append(saveResult.getMessage());
- errMsg.append("\r\n");
- }
- }
- }else {
- this.getView().showMessage("请至少选择一条数据");
- }
- }
- }
- }
|