package com.byyy.scmc.im.print; /** * @Author 李杰 * @Description 打印模板的控制 * @Date 2023/10/31 */ import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObjectCollection; import kd.bos.dataentity.utils.StringUtils; import kd.bos.orm.query.QFilter; import kd.bos.print.core.data.DataRowSet; import kd.bos.print.core.data.field.Field; import kd.bos.print.core.plugin.AbstractPrintPlugin; import kd.bos.print.core.plugin.event.AfterLoadDataEvent; import kd.bos.servicehelper.BusinessDataServiceHelper; import kd.bos.servicehelper.QueryServiceHelper; import java.util.*; public class ImSaloutBillPrintPlugIn extends AbstractPrintPlugin { @Override public void afterLoadData(AfterLoadDataEvent evt) { super.afterLoadData(evt); List rowSets = evt.getDataRowSets(); for (DataRowSet dataRowSet : rowSets) { // List entryRowsNew = new ArrayList<>(); // List entryRows = dataRowSet.getCollectionField(KEY_ENTRYENTITY).getValue(); Field id = dataRowSet.getField("id"); //获取采购入库单 DynamicObject loadBill = null; // loadBill = BusinessDataServiceHelper.loadSingle("im_purinbill", "supplier", new QFilter[]{ // new QFilter("id", "=",id.toString()) // }); loadBill = QueryServiceHelper.queryOne("im_purinbill", "supplier.id", new QFilter[]{ new QFilter("id", "=",id.toString()) }); if (loadBill == null){ return; } //获取供货供应商编码 String supplierId = loadBill.getString("supplier.id"); //查询供应商 DynamicObject supplierBill = BusinessDataServiceHelper.loadSingle("bd_supplier", "rm_supplier_cert.rm_certificate_no,rm_supplier_cert.rm_certificate_type", new QFilter[]{ new QFilter("id", "=", supplierId) }); if (supplierBill == null){ return; } //获取证照信息 DynamicObjectCollection entities = supplierBill.getDynamicObjectCollection("rm_supplier_cert"); for (DynamicObject entity : entities) { if ("1002".equals(entity.getString("rm_certificate_type.number"))){ String rmCertificateNo = entity.getString("rm_certificate_no"); if (StringUtils.isEmpty(rmCertificateNo)){ return; } //为模板赋值经营许可证号---医疗器械经营许可证号 Field byyyBusinesslicense = dataRowSet.getField("byyy_businesslicense"); byyyBusinesslicense.setValue(rmCertificateNo); dataRowSet.put("byyy_businesslicense",byyyBusinesslicense); } if ("1010".equals(entity.getString("rm_certificate_type.number"))){ String rmCertificateNo = entity.getString("rm_certificate_no"); if (StringUtils.isEmpty(rmCertificateNo)){ return; } //备案凭证编号取第二类医疗器械经营备案凭证 Field byyyRecordvoucher = dataRowSet.getField("byyy_recordvoucher"); byyyRecordvoucher.setValue(rmCertificateNo); dataRowSet.put("byyy_recordvoucher",byyyRecordvoucher); } } // for (DataRowSet entryRow : entryRows) { // entryRowsNew.add(entryRow); // //深拷贝新行,每行分录新增一行,如果不需要展示单据头和单据体字段,则可不用深拷贝 // DataRowSet copy = entryRow.deepCopy(); // //rm_fix_discount 固定折扣额 // BigDecimal discount = (BigDecimal) copy.getField("rm_fix_discount").getValue(); // if(discount.compareTo(BigDecimal.ZERO)!=0){ // // //qty 数量 // BigDecimal qty = (BigDecimal) copy.getField("qty").getValue(); // //taxrate 税率% // BigDecimal taxrate = (BigDecimal) copy.getField("taxrateid.taxrate").getValue(); // //priceandtax 含税单价 // BigDecimal bigDecimal = qty.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO : discount.divide(qty, 6, BigDecimal.ROUND_HALF_UP); // copy.getField("priceandtax").setValue(bigDecimal.multiply(BigDecimal.valueOf(-1))); // //price 单价 // BigDecimal decimal = bigDecimal.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO : bigDecimal.multiply(BigDecimal.valueOf(100)).divide(BigDecimal.valueOf(100).add(taxrate), 6, BigDecimal.ROUND_HALF_UP); // copy.getField("price").setValue(decimal.multiply(BigDecimal.valueOf(-1))); // //清空无用数据 // //amount 金额 // copy.getField("amount").setValue(BigDecimal.ZERO); // //taxamount 税额 // copy.getField("taxamount").setValue(BigDecimal.ZERO); // //amountandtax 价税合计 // copy.getField("amountandtax").setValue(BigDecimal.ZERO); // entryRowsNew.add(copy); // // } } // dataRowSet.getCollectionField(KEY_ENTRYENTITY).setValue(entryRowsNew); } }