业务场景:一张付款单通过BOTP生成两张凭证,点击一次“生成凭证按钮”,自动根据两个规则生成两张凭证。
解决方法:预先设定两个规则的编码,如果存在动态会计规则存在这个两个编码,就根据这两个规则生成两张凭证,不存在的话就按原来的方法执行。
具体代码:
@Override
public void actionVoucher_actionPerformed(ActionEvent e) throws Exception{
//获取付款单序时簿上选中的单据的ID,getSelectedListId自己实现
List<String> idList = getSelectedListId();
if (idList != null && idList.size() > 0) {
String ids = "";
for(int i=0; i<idList.size(); i++){
ids += "'"+idList.get(i)+"',";
}
if(ids.length()>0){
ids = ids.substring(0,ids.length()-1);
//获取付款单集合
String oql = "select * where id in ('', "+ids+")";
CoreBillBaseCollection paymentCollection = PaymentFactory.getRemoteInstance().getCoreBillBaseCollection(oql);
//生成凭证,如果业务逻辑是要选中的单据合并生成凭证的话,
//generateVoucherInfo传入的参数是paymentCollection
for(int k=0; k<paymentCollection.size(); k++){
generateVoucherInfo(paymentCollection.get(k), e);
}
}
} else{
MsgBox.showInfo("请先选择单据");
}
this.refresh(e);
}
public void generateVoucherInfo(CoreBillBaseInfo srcInfo, ActionEvent e) throws Exception {
//对一张单据生成两张凭证
CoreBillBaseCollection coll = new CoreBillBaseCollection();
coll.add(srcInfo);
IBOTMapping botMapping = BOTMappingFactory.getRemoteInstance();
//获取付款单的所有动态会计规则
BOTMappingCollection botMappingCollection = botMapping.getMappingCollectionForSelect(coll, (new VoucherInfo()).getBOSType().toString(), DefineSysEnum.DAP);
if(botMappingCollection!=null){
boolean bool= false;
for(int i=0; i<botMappingCollection.size(); i++){
BOTMappingInfo botMappingInfo = botMappingCollection.get(i);
//如果付款单的BOTP规则中有编码规则是"MyPay10001"、"MyPay10002",就根据这两个规则生成两张凭证
if(botMappingInfo.getName().equals("MyPay10001") || botMappingInfo.getName().equals("MyPay10002")){
bool = true;
IObjectPK ruleId = new ObjectUuidPK(botMappingInfo.getId().toString());
IDAPTransformer idapTransformer = DAPTransformerFactory.getRemoteInstance();
//单据转换,具体的转换方法用法可以参考DAPTransformer.facade
DAPTransformResult result = idapTransformer.transformForBotp(coll, DAPVoucherTypeEnum.FIVoucher, ruleId);
//保存转换结果
idapTransformer.save(coll, result);
//如果不使用DAPTransformer.facade转换的话可以使用BTPManager.facade
//不过我在使用这个的过程中出现了比较多的问题,如调用业务方法异常:会计期间为空;FSOURCETYPE 不能为空等。
//IBTPManager ibtpManager = BTPManagerFactory.getRemoteInstance();
//BTPTransformResult result = ibtpManager.transformForBotp(coll, (new VoucherInfo()).getBOSType().toString(), ruleId);
//IObjectCollection collection = result.getBills();
//for(int j=0; j<collection.size(); j++){
// VoucherInfo voucherInfo = (VoucherInfo) collection.getObject(j);
// ibtpManager.saveRelations(voucherInfo, result.getBOTRelationCollection());
//}
}
}
//如果没有预先设定的编码规则,就按原来的方法执行
if(!bool){
super.actionVoucher_actionPerformed(e);
}
}
解决方法:预先设定两个规则的编码,如果存在动态会计规则存在这个两个编码,就根据这两个规则生成两张凭证,不存在的话就按原来的方法执行。
具体代码:
@Override
public void actionVoucher_actionPerformed(ActionEvent e) throws Exception{
//获取付款单序时簿上选中的单据的ID,getSelectedListId自己实现
List<String> idList = getSelectedListId();
if (idList != null && idList.size() > 0) {
String ids = "";
for(int i=0; i<idList.size(); i++){
ids += "'"+idList.get(i)+"',";
}
if(ids.length()>0){
ids = ids.substring(0,ids.length()-1);
//获取付款单集合
String oql = "select * where id in ('', "+ids+")";
CoreBillBaseCollection paymentCollection = PaymentFactory.getRemoteInstance().getCoreBillBaseCollection(oql);
//生成凭证,如果业务逻辑是要选中的单据合并生成凭证的话,
//generateVoucherInfo传入的参数是paymentCollection
for(int k=0; k<paymentCollection.size(); k++){
generateVoucherInfo(paymentCollection.get(k), e);
}
}
} else{
MsgBox.showInfo("请先选择单据");
}
this.refresh(e);
}
public void generateVoucherInfo(CoreBillBaseInfo srcInfo, ActionEvent e) throws Exception {
//对一张单据生成两张凭证
CoreBillBaseCollection coll = new CoreBillBaseCollection();
coll.add(srcInfo);
IBOTMapping botMapping = BOTMappingFactory.getRemoteInstance();
//获取付款单的所有动态会计规则
BOTMappingCollection botMappingCollection = botMapping.getMappingCollectionForSelect(coll, (new VoucherInfo()).getBOSType().toString(), DefineSysEnum.DAP);
if(botMappingCollection!=null){
boolean bool= false;
for(int i=0; i<botMappingCollection.size(); i++){
BOTMappingInfo botMappingInfo = botMappingCollection.get(i);
//如果付款单的BOTP规则中有编码规则是"MyPay10001"、"MyPay10002",就根据这两个规则生成两张凭证
if(botMappingInfo.getName().equals("MyPay10001") || botMappingInfo.getName().equals("MyPay10002")){
bool = true;
IObjectPK ruleId = new ObjectUuidPK(botMappingInfo.getId().toString());
IDAPTransformer idapTransformer = DAPTransformerFactory.getRemoteInstance();
//单据转换,具体的转换方法用法可以参考DAPTransformer.facade
DAPTransformResult result = idapTransformer.transformForBotp(coll, DAPVoucherTypeEnum.FIVoucher, ruleId);
//保存转换结果
idapTransformer.save(coll, result);
//如果不使用DAPTransformer.facade转换的话可以使用BTPManager.facade
//不过我在使用这个的过程中出现了比较多的问题,如调用业务方法异常:会计期间为空;FSOURCETYPE 不能为空等。
//IBTPManager ibtpManager = BTPManagerFactory.getRemoteInstance();
//BTPTransformResult result = ibtpManager.transformForBotp(coll, (new VoucherInfo()).getBOSType().toString(), ruleId);
//IObjectCollection collection = result.getBills();
//for(int j=0; j<collection.size(); j++){
// VoucherInfo voucherInfo = (VoucherInfo) collection.getObject(j);
// ibtpManager.saveRelations(voucherInfo, result.getBOTRelationCollection());
//}
}
}
//如果没有预先设定的编码规则,就按原来的方法执行
if(!bool){
super.actionVoucher_actionPerformed(e);
}
}
}
//单据规则转换 (先在规则配置中配置好,启用规则)
/**
* 后台做单据转换
* TestBizInfo 转换为 TestBiz2Info
* @param info TestBizInfo(源单)
*/
@Override
protected boolean _botpTest(Context ctx, IObjectValue info)
throws BOSException, EASBizException {
CoreBillBaseCollection coll = new CoreBillBaseCollection();
coll.add((TestBizInfo)info);
IBOTMapping botMapping = BOTMappingFactory.getLocalInstance(ctx);
//获取TestBiz的所有单据转换规则
BOTMappingCollection botMappingCollection = botMapping
.getMappingCollectionForSelect(coll, (new TestBiz2Info())
.getBOSType().toString(), DefineSysEnum.BTP);//BTP指
if(botMappingCollection!=null){
boolean bool= false;
for(int i=0; i<botMappingCollection.size(); i++){
BOTMappingInfo botMappingInfo = botMappingCollection.get(i);
if (botMappingInfo.getName().equals("test001")) {//test001是规则编码
bool = true;
IObjectPK ruleId = new ObjectUuidPK(botMappingInfo.getId()
.toString());
// IDAPTransformer idapTransformer =
// DAPTransformerFactory.getRemoteInstance();
// //单据转换,具体的转换方法用法可以参考DAPTransformer.facade
// DAPTransformResult result =
// idapTransformer.transformForBotp(coll,
// DAPVoucherTypeEnum.FIVoucher, ruleId);
// //保存转换结果
// idapTransformer.save(coll, result);
IBTPManager ibtpManager = BTPManagerFactory.getLocalInstance(ctx);
BTPTransformResult result = ibtpManager.transformForBotp(coll, (new TestBiz2Info()).getBOSType().toString(),
ruleId);
IObjectCollection collection = result.getBills();
//保存转换关系
for (int j = 0; j < collection.size(); j++) {
TestBiz2Info voucherInfo = (TestBiz2Info) collection.getObject(j);
ibtpManager.saveRelations(voucherInfo, result.getBOTRelationCollection());
}
}
}
}
return super._botpTest(ctx, info);
}