173 lines
9.6 KiB
Java
173 lines
9.6 KiB
Java
|
package shkd.repc.repe.formplugin;
|
|||
|
|
|||
|
import kd.bos.dataentity.entity.DynamicObject;
|
|||
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|||
|
import kd.bos.dataentity.utils.StringUtils;
|
|||
|
import kd.bos.form.control.events.BeforeItemClickEvent;
|
|||
|
import kd.bos.form.plugin.AbstractFormPlugin;
|
|||
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|||
|
import kd.sdk.plugin.Plugin;
|
|||
|
|
|||
|
import java.math.BigDecimal;
|
|||
|
import java.math.RoundingMode;
|
|||
|
import java.util.EventObject;
|
|||
|
|
|||
|
/**
|
|||
|
* 动态表单插件
|
|||
|
*/
|
|||
|
public class SumEntryAmountPlugin extends AbstractFormPlugin implements Plugin {
|
|||
|
|
|||
|
@Override
|
|||
|
public void registerListener(EventObject e) {
|
|||
|
super.registerListener(e);
|
|||
|
//工具栏控件
|
|||
|
this.addItemClickListeners("tbmain");
|
|||
|
}
|
|||
|
|
|||
|
@Override
|
|||
|
public void beforeItemClick(BeforeItemClickEvent evt) {
|
|||
|
super.beforeItemClick(evt);
|
|||
|
if (StringUtils.equals("save", evt.getItemKey())||StringUtils.equals("submit", evt.getItemKey())) {
|
|||
|
boolean util = util(this.getModel().getDataEntity());
|
|||
|
if(!util){
|
|||
|
this.getView().showTipNotification("分录数量必填");
|
|||
|
evt.setCancel(true);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private boolean util(DynamicObject dynamicObject){
|
|||
|
DynamicObjectCollection qeug_orderformentry = dynamicObject.getDynamicObjectCollection("orderformentry");
|
|||
|
for (int i = 0; qeug_orderformentry!=null&&i < qeug_orderformentry.size(); i++) {
|
|||
|
DynamicObject dynamicObject1 = qeug_orderformentry.get(i);
|
|||
|
/**
|
|||
|
* 填写字段:数量,不含税,含税,税率,税额
|
|||
|
*/
|
|||
|
BigDecimal qty = dynamicObject1.getBigDecimal("ordercount");//数量
|
|||
|
BigDecimal qeug_exclusiveprice = dynamicObject1.getBigDecimal("totalprice");//不含税
|
|||
|
BigDecimal qeug_taxprice = dynamicObject1.getBigDecimal("taxprice");//含税
|
|||
|
BigDecimal qeug_taxrate = BigDecimal.ZERO;//税率
|
|||
|
BigDecimal qeug_taxamount = dynamicObject1.getBigDecimal("taxamount");//税额
|
|||
|
Object qeug_taxrate1 = dynamicObject1.get("taxrate");
|
|||
|
if(qeug_taxrate1!=null){
|
|||
|
qeug_taxrate = returnRate(dynamicObject1.getBigDecimal("taxrate.taxrate"));
|
|||
|
}
|
|||
|
boolean qty1 = returnComperZero(qty);//数量
|
|||
|
if(!qty1){
|
|||
|
return false;
|
|||
|
}
|
|||
|
boolean noTaxPrice = returnComperZero(qeug_exclusiveprice);//不含税
|
|||
|
boolean TaxPrice = returnComperZero(qeug_taxprice);//含税
|
|||
|
boolean taxRate = returnComperZero(qeug_taxrate);//税率
|
|||
|
boolean Tax = returnComperZero(qeug_taxamount);//税额
|
|||
|
/**
|
|||
|
* 计算字段:不含税,含税,不含税总价,含税总价,税额
|
|||
|
*/
|
|||
|
BigDecimal qeug_notaxtotalprice = BigDecimal.ZERO;//不含税总价
|
|||
|
BigDecimal qeug_taxtotalprice = BigDecimal.ZERO;//含税总价
|
|||
|
if(!noTaxPrice && !TaxPrice){
|
|||
|
qeug_notaxtotalprice = qty.multiply(qeug_exclusiveprice);
|
|||
|
dynamicObject1.set("notaxtotalprice", qeug_notaxtotalprice);
|
|||
|
qeug_taxtotalprice = qty.multiply(qeug_taxprice);
|
|||
|
dynamicObject1.set("taxtotalprice", qeug_taxtotalprice);
|
|||
|
}else if(!noTaxPrice && TaxPrice && !taxRate && !Tax){
|
|||
|
qeug_exclusiveprice = qeug_taxprice;
|
|||
|
dynamicObject1.set("totalprice",qeug_exclusiveprice);
|
|||
|
qeug_notaxtotalprice = qty.multiply(qeug_exclusiveprice);
|
|||
|
dynamicObject1.set("notaxtotalprice", qeug_notaxtotalprice);
|
|||
|
qeug_taxtotalprice = qty.multiply(qeug_taxprice);
|
|||
|
dynamicObject1.set("taxtotalprice", qeug_taxtotalprice);
|
|||
|
}else if(!noTaxPrice && TaxPrice && !taxRate && Tax){
|
|||
|
qeug_exclusiveprice = qeug_taxprice.subtract(qeug_taxamount.divide(qty, 2, RoundingMode.HALF_UP));
|
|||
|
dynamicObject1.set("totalprice",qeug_exclusiveprice);
|
|||
|
qeug_notaxtotalprice = qty.multiply(qeug_exclusiveprice);
|
|||
|
dynamicObject1.set("notaxtotalprice", qeug_notaxtotalprice);
|
|||
|
qeug_taxtotalprice = qty.multiply(qeug_taxprice);
|
|||
|
dynamicObject1.set("taxtotalprice", qeug_taxtotalprice);
|
|||
|
}else if(!noTaxPrice && TaxPrice && taxRate && !Tax){
|
|||
|
qeug_exclusiveprice = qeug_taxprice.divide(BigDecimal.ONE.add(qeug_taxrate), 2, RoundingMode.HALF_UP);
|
|||
|
dynamicObject1.set("totalprice",qeug_exclusiveprice);
|
|||
|
qeug_notaxtotalprice = qty.multiply(qeug_exclusiveprice);
|
|||
|
dynamicObject1.set("notaxtotalprice", qeug_notaxtotalprice);
|
|||
|
qeug_taxtotalprice = qty.multiply(qeug_taxprice);
|
|||
|
dynamicObject1.set("taxtotalprice", qeug_taxtotalprice);
|
|||
|
dynamicObject1.set("taxamount",qeug_taxtotalprice.subtract(qeug_notaxtotalprice));
|
|||
|
}else if(!noTaxPrice && TaxPrice && taxRate && Tax){
|
|||
|
qeug_exclusiveprice = qeug_taxprice.subtract(qeug_taxamount.divide(qty, 2, RoundingMode.HALF_UP));
|
|||
|
dynamicObject1.set("totalprice",qeug_exclusiveprice);
|
|||
|
qeug_notaxtotalprice = qty.multiply(qeug_exclusiveprice);
|
|||
|
dynamicObject1.set("notaxtotalprice", qeug_notaxtotalprice);
|
|||
|
qeug_taxtotalprice = qty.multiply(qeug_taxprice);
|
|||
|
dynamicObject1.set("taxtotalprice", qeug_taxtotalprice);
|
|||
|
}else if(noTaxPrice && !TaxPrice && !taxRate && !Tax){
|
|||
|
qeug_taxprice = qeug_exclusiveprice;
|
|||
|
dynamicObject1.set("taxprice",qeug_taxprice);
|
|||
|
qeug_notaxtotalprice = qty.multiply(qeug_exclusiveprice);
|
|||
|
dynamicObject1.set("notaxtotalprice", qeug_notaxtotalprice);
|
|||
|
qeug_taxtotalprice = qty.multiply(qeug_taxprice);
|
|||
|
dynamicObject1.set("taxtotalprice", qeug_taxtotalprice);
|
|||
|
}else if(noTaxPrice && !TaxPrice && !taxRate && Tax){
|
|||
|
qeug_taxprice = qeug_exclusiveprice.add(qeug_taxamount.divide(qty, 2, RoundingMode.HALF_UP));
|
|||
|
dynamicObject1.set("taxprice",qeug_taxprice);
|
|||
|
qeug_notaxtotalprice = qty.multiply(qeug_exclusiveprice);
|
|||
|
dynamicObject1.set("notaxtotalprice", qeug_notaxtotalprice);
|
|||
|
qeug_taxtotalprice = qty.multiply(qeug_taxprice);
|
|||
|
dynamicObject1.set("taxtotalprice", qeug_taxtotalprice);
|
|||
|
}else if(noTaxPrice && !TaxPrice && taxRate && !Tax){
|
|||
|
qeug_taxprice = qeug_exclusiveprice.multiply(BigDecimal.ONE.add(qeug_taxrate));
|
|||
|
dynamicObject1.set("taxprice",qeug_taxprice);
|
|||
|
qeug_notaxtotalprice = qty.multiply(qeug_exclusiveprice);
|
|||
|
dynamicObject1.set("notaxtotalprice", qeug_notaxtotalprice);
|
|||
|
qeug_taxtotalprice = qty.multiply(qeug_taxprice);
|
|||
|
dynamicObject1.set("taxtotalprice", qeug_taxtotalprice);
|
|||
|
dynamicObject1.set("taxamount",qeug_taxtotalprice.subtract(qeug_notaxtotalprice));
|
|||
|
}else if(noTaxPrice && !TaxPrice && taxRate && Tax){
|
|||
|
qeug_taxprice = qeug_exclusiveprice.add(qeug_taxamount.divide(qty, 2, RoundingMode.HALF_UP));
|
|||
|
dynamicObject1.set("taxprice",qeug_taxprice);
|
|||
|
qeug_notaxtotalprice = qty.multiply(qeug_exclusiveprice);
|
|||
|
dynamicObject1.set("notaxtotalprice", qeug_notaxtotalprice);
|
|||
|
qeug_taxtotalprice = qty.multiply(qeug_taxprice);
|
|||
|
dynamicObject1.set("taxtotalprice", qeug_taxtotalprice);
|
|||
|
}else if(noTaxPrice && TaxPrice && !taxRate && !Tax){
|
|||
|
qeug_notaxtotalprice = qty.multiply(qeug_exclusiveprice);
|
|||
|
dynamicObject1.set("notaxtotalprice", qeug_notaxtotalprice);
|
|||
|
qeug_taxtotalprice = qty.multiply(qeug_taxprice);
|
|||
|
dynamicObject1.set("taxtotalprice", qeug_taxtotalprice);
|
|||
|
dynamicObject1.set("taxamount",qeug_taxtotalprice.subtract(qeug_notaxtotalprice));
|
|||
|
}else if(noTaxPrice && TaxPrice && !taxRate && Tax){
|
|||
|
qeug_notaxtotalprice = qty.multiply(qeug_exclusiveprice);
|
|||
|
dynamicObject1.set("notaxtotalprice", qeug_notaxtotalprice);
|
|||
|
qeug_taxtotalprice = qty.multiply(qeug_taxprice);
|
|||
|
dynamicObject1.set("taxtotalprice", qeug_taxtotalprice);
|
|||
|
}else if(noTaxPrice && TaxPrice && taxRate && !Tax){
|
|||
|
qeug_notaxtotalprice = qty.multiply(qeug_exclusiveprice);
|
|||
|
dynamicObject1.set("notaxtotalprice", qeug_notaxtotalprice);
|
|||
|
qeug_taxtotalprice = qty.multiply(qeug_taxprice);
|
|||
|
dynamicObject1.set("taxtotalprice", qeug_taxtotalprice);
|
|||
|
dynamicObject1.set("taxamount",qeug_taxtotalprice.subtract(qeug_notaxtotalprice));
|
|||
|
}else if(noTaxPrice && TaxPrice && taxRate && Tax){
|
|||
|
qeug_notaxtotalprice = qty.multiply(qeug_exclusiveprice);
|
|||
|
dynamicObject1.set("notaxtotalprice", qeug_notaxtotalprice);
|
|||
|
qeug_taxtotalprice = qty.multiply(qeug_taxprice);
|
|||
|
dynamicObject1.set("taxtotalprice", qeug_taxtotalprice);
|
|||
|
}
|
|||
|
qeug_orderformentry.set(i, dynamicObject1);
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
private boolean returnComperZero(BigDecimal bigDecimal){
|
|||
|
return BigDecimal.ZERO.compareTo(bigDecimal) == -1;
|
|||
|
}
|
|||
|
|
|||
|
private BigDecimal returnRate(BigDecimal bigDecimal){
|
|||
|
if(bigDecimal==null){
|
|||
|
return BigDecimal.ZERO;
|
|||
|
}
|
|||
|
if(BigDecimal.ONE.compareTo(bigDecimal) <= 0){
|
|||
|
return bigDecimal.divide(new BigDecimal(100));
|
|||
|
}else{
|
|||
|
return bigDecimal;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|