Просмотр исходного кода

收款核销分摊计算逻辑调整

沈静伟 4 лет назад
Родитель
Сommit
701a3506f0
1 измененных файлов с 21 добавлено и 6 удалено
  1. 21 6
      src/apps/twriteoffbill/twriteoffbill.java

+ 21 - 6
src/apps/twriteoffbill/twriteoffbill.java

@@ -18,7 +18,7 @@ public class twriteoffbill extends PaoCust {
         super.init();
         if (!toBeAdded()) {
             if (!"新建".equals(getString("fstatus"))) {
-                setFieldFlag(new String[]{"ficashbillnum", "fdate", "fnotes","fagentnum", "fwriteoffamount"}, READONLY, true);
+                setFieldFlag(new String[]{"ficashbillnum", "fdate", "fnotes", "fagentnum", "fwriteoffamount"}, READONLY, true);
             }
             PaoSetRemote ficashbillSet = getPaoSet("ficashbill");
             if (!ficashbillSet.isEmpty()) {
@@ -50,7 +50,7 @@ public class twriteoffbill extends PaoCust {
     }
 
     public void caculate() throws P2Exception {
-        double funwriteoffamount = getDouble("funwriteoffamount");//凭证核销金额
+        double fwriteoffamount = getDouble("fwriteoffamount");//凭证核销金额
 
         PaoSetRemote twriteofforderSet = getPaoSet("twriteofforder");
         int i = 0;
@@ -62,19 +62,19 @@ public class twriteoffbill extends PaoCust {
         if (fwriteoffamount_detail <= 0) {
             throw new P2AppException("", "表体订单行无剩余可核销金额");
         }
-        if (fwriteoffamount_detail <= funwriteoffamount) {
+        if (fwriteoffamount_detail <= fwriteoffamount) {
             setValue("fwriteoffamount", fwriteoffamount_detail, 11L);
         } else {
-            //如果凭证剩余未核销金额小于所选订单表体金额,则进行分摊计算
+            //如果凭证核销金额小于所选订单表体金额,则进行分摊计算
             i = 0;
             while (twriteofforderSet.getPao(i) != null) {
                 double fwriteoffamount_old = twriteofforderSet.getPao(i).getDouble("fwriteoffamount");
-                double fwriteoffamount_new = funwriteoffamount * (fwriteoffamount_old / fwriteoffamount_detail);
+                double fwriteoffamount_new = fwriteoffamount * (fwriteoffamount_old / fwriteoffamount_detail);
                 twriteofforderSet.getPao(i).setValue("fwriteoffamount", fwriteoffamount_new, 11L);
                 i++;
             }
             //差额补齐计算
-            double chae = Math.sub(funwriteoffamount, twriteofforderSet.sum("fwriteoffamount"));
+            double chae = Math.sub(fwriteoffamount, twriteofforderSet.sum("fwriteoffamount"));
             if (chae != 0) {
                 twriteofforderSet.getPao(i - 1).setValue("fwriteoffamount", Math.add(twriteofforderSet.getPao(i - 1).getDouble("fwriteoffamount"), chae), 11L);
             }
@@ -176,6 +176,21 @@ public class twriteoffbill extends PaoCust {
     @Override
     public void fieldValidate(Object paoField, String fieldname) throws P2Exception {
         super.fieldValidate(paoField, fieldname);
+        if ("fwriteoffamount".equalsIgnoreCase(fieldname)) {
+            if (getDouble("fwriteoffamount") > getDouble("funwriteoffamount")) {
+                throw new P2AppException("", "本次核销金额不可大于凭证未核销金额");
+            }
+            double funwriteoffamount = 0;
+            PaoSetRemote twriteofforderSet = getPaoSet("twriteofforder");
+            int i = 0;
+            while (twriteofforderSet.getPao(i) != null) {
+                funwriteoffamount = Math.add(funwriteoffamount, twriteofforderSet.getPao(i).getDouble("funwriteoffamount"));
+                i++;
+            }
+            if (getDouble("fwriteoffamount") > funwriteoffamount) {
+                throw new P2AppException("", "本次核销金额不可大于订单未核销金额");
+            }
+        }
     }
 
     @Override