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

收入凭证实现对冲功能

沈静伟 4 лет назад
Родитель
Сommit
0e9cbbce12

+ 69 - 6
src/apps/ficashbill/ficashbill.java

@@ -11,9 +11,8 @@ import p2.util.P2Exception;
 import saorder.saorder;
 import taccbal.taccbal;
 
-import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Date;
-import java.util.HashMap;
 
 /**
  * 收支凭证表主类
@@ -41,7 +40,7 @@ public class ficashbill extends PaoCust {
             /*
              * 非新建状态下或者该数据是其他单据生成的或者待审标记是true的情况下,将数据设为只读。
              */
-            if (!"新建".equals(getString("fstatus")) || getInt("FSOURCEID") > 0 || getBoolean("FWILLCHECK")) {
+            if (!"新建".equals(getString("fstatus")) || (getInt("FSOURCEID") > 0 && !getString("fsourceobject").equalsIgnoreCase(getName())) || getBoolean("FWILLCHECK")) {
                 setFieldFlag(new GetFieldsName(getName()).getFields(), READONLY, true);
                 if ("提交".equals(getString("fstatus"))) {
                     setFieldFlag("fconfirmamount", READONLY, false);
@@ -54,8 +53,10 @@ public class ficashbill extends PaoCust {
                 setFieldFlag("FWILLCHECK", READONLY, false);
             }
         }
-
-        setValue("FUNWRITEOFFAMOUNT", getDouble("FAMOUNT") - getDouble("FWRITEOFFAMOUNT"), 11l);
+        if (getDouble("famount") > 0) {
+            PaoSetRemote set = getPaoSet(Calendar.getInstance().getTimeInMillis() + getName(), getName(), "fstatus='审核' and ftype='" + getString("ftype") + "' and fsourceid='" + getUniqueIDValue() + "' and fsourceobject='" + getName() + "'");
+            setValue("FUNWRITEOFFAMOUNT", getDouble("FAMOUNT") + set.sum("famount") - getDouble("FWRITEOFFAMOUNT"), 11l);
+        }
     }
 
     @Override
@@ -103,7 +104,7 @@ public class ficashbill extends PaoCust {
             throw new P2AppException("", "非新建状态不可删除");
         }
 
-        if (getInt("fsourceid") > 0 && !"sendrepair".equalsIgnoreCase(getString("fsourceobject"))) {
+        if (getInt("fsourceid") > 0 && !("sendrepair".equalsIgnoreCase(getString("fsourceobject")) || (getName().equalsIgnoreCase(getString("fsourceobject"))))) {
             throw new P2AppException("", "该单为系统自动生成,不可删除");
         }
         if (getBoolean("fwillcheck")) {
@@ -217,6 +218,22 @@ public class ficashbill extends PaoCust {
                 }
             }
         }
+
+        if (getName().equalsIgnoreCase(getString("fsourceobject"))) {
+            if (famount >= 0) {
+                throw new P2AppException("", "对冲凭证必须为负数");
+            }
+            //原凭证
+            PaoSetRemote cashbillset = getPaoSet(Calendar.getInstance().getTimeInMillis() + getName(), getName(), "ficashbillid=" + getLong("fsourceid"));
+            if (cashbillset.isEmpty()) {
+                throw new P2AppException("", "原凭证不存在");
+            }
+            PaoRemote cashbill = cashbillset.getPao(0);
+            double funwriteoffamount = cashbill.getDouble("funwriteoffamount");//原凭证未核销金额
+            if (-famount > funwriteoffamount) {
+                throw new P2AppException("", "对冲金额绝对值必须小于原凭证未核销金额");
+            }
+        }
     }
 
 
@@ -478,6 +495,24 @@ public class ficashbill extends PaoCust {
                     throw new P2AppException("", "金额不可小于0");
                 }
             }
+            if (getDouble(fieldname) == 0) {
+                throw new P2AppException("", "金额不可等于0");
+            }
+            if (getName().equalsIgnoreCase(getString("fsourceobject"))) {
+                if (getDouble(fieldname) >= 0) {
+                    throw new P2AppException("", "对冲凭证必须为负数");
+                }
+                //原凭证
+                PaoSetRemote cashbillset = getPaoSet(Calendar.getInstance().getTimeInMillis() + getName(), getName(), "ficashbillid=" + getLong("fsourceid"));
+                if (cashbillset.isEmpty()) {
+                    throw new P2AppException("", "原凭证不存在");
+                }
+                PaoRemote cashbill = cashbillset.getPao(0);
+                double funwriteoffamount = cashbill.getDouble("famount");//原凭证未核销金额
+                if (-getDouble(fieldname) > funwriteoffamount) {
+                    throw new P2AppException("", "对冲金额绝对值必须小于原凭证未核销金额");
+                }
+            }
         }
     }
 
@@ -548,4 +583,32 @@ public class ficashbill extends PaoCust {
         pao.setValue("ficashbillnum", getString("fbillnum"));
         return pao.getUniqueIDValue();
     }
+
+    public long createredcashbill() throws P2Exception {
+        if (!"审核".equalsIgnoreCase(getString("fstatus"))) {
+            throw new P2AppException("", "非审核状态下不可进行对冲操作");
+        }
+        double famount = getDouble("famount");//凭证未核销金额
+        if (famount <= 0) {
+            throw new P2AppException("", "该凭证无法进行对冲操作");
+        }
+        double funwriteoffamount = getDouble("funwriteoffamount");//凭证未核销金额
+        if (funwriteoffamount <= 0) {
+            throw new P2AppException("", "当前凭证已无法进行对冲操作");
+        }
+        PaoSetRemote ficashbillSet = getPaoSet("$$ficashbill", "ficashbill");
+        ficashbillSet.setApp(getThisPaoSet().getApp().toUpperCase());
+        PaoRemote pao = ficashbillSet.addAtEnd();
+        pao.setValue("fsourceid", getUniqueIDValue());
+        pao.setValue("fsourceobject", "FICASHBILL");
+        pao.setValue("fagentnum", getString("fagentnum"));
+        pao.setValue("faccclsnum", getString("faccclsnum"));
+        pao.setValue("ftypemx", getString("ftypemx"), 11L);
+        pao.setValue("ftypemxdetail", getString("ftypemxdetail"), 11L);
+        pao.setValue("fnotes", "凭证对冲", 11L);
+        pao.setValue("fdate", getDate("fdate"));
+        pao.setValue("famount", -funwriteoffamount);
+        return pao.getUniqueIDValue();
+    }
+
 }

+ 15 - 0
src/apps/ficashbill/ficashbillAppBean.java

@@ -246,4 +246,19 @@ public class ficashbillAppBean extends AppBeanCust {
         byrefresh();
         return 1;
     }
+
+    /**
+     * Éú³É¶Ô³åƾ֤
+     *
+     * @return
+     */
+    public int CREATEREDCASHBILL() throws P2Exception {
+        ficashbill ficashbill = (ficashbill) getPao();
+        long id = ficashbill.createredcashbill();
+        this.save();
+        closeApp(getPaoSet().getApp().toUpperCase());
+        openApp(getPaoSet().getApp().toUpperCase(), id);
+        byrefresh();
+        return 1;
+    }
 }

+ 16 - 10
src/apps/twriteoffbill/twriteoffbill.java

@@ -98,9 +98,8 @@ public class twriteoffbill extends PaoCust {
             }
             PaoSetRemote ficashbillSet = getPaoSet("ficashbill");
             double fwriteoffamount = getDouble("fwriteoffamount");//本次核销金额
-            double fwriteoffamount_cashbill = ficashbillSet.getPao(0).getDouble("fwriteoffamount");//凭证已核销金额
-            double famount_cashbill = ficashbillSet.getPao(0).getDouble("famount");//凭证总金额
-            if (Math.sub(famount_cashbill, fwriteoffamount_cashbill) < fwriteoffamount) {
+            double funwriteoffamount_cashbill = ficashbillSet.getPao(0).getDouble("funwriteoffamount");//凭证未核销金额
+            if (funwriteoffamount_cashbill < fwriteoffamount) {
                 throw new P2AppException("", "收入凭证可核销金额不足");
             }
 
@@ -176,7 +175,7 @@ public class twriteoffbill extends PaoCust {
     @Override
     public void fieldValidate(Object paoField, String fieldname) throws P2Exception {
         super.fieldValidate(paoField, fieldname);
-        if ("fwriteoffamount".equalsIgnoreCase(fieldname)) {
+        if ("FWRITEOFFAMOUNT".equals(fieldname)) {
             if (getDouble("fwriteoffamount") > getDouble("funwriteoffamount")) {
                 throw new P2AppException("", "本次核销金额不可大于凭证未核销金额");
             }
@@ -197,17 +196,24 @@ public class twriteoffbill extends PaoCust {
     public void fieldAction(Object paoField, String fieldname) throws P2Exception {
         super.fieldAction(paoField, fieldname);
         if ("FICASHBILLNUM".equals(fieldname)) {
-            PaoSetRemote ficashbillSet = getPaoSet("ficashbill");
-            if (!ficashbillSet.isEmpty()) {
-                double famount = ficashbillSet.getPao(0).getDouble("famount");
-                double fwriteoffamount = ficashbillSet.getPao(0).getDouble("fwriteoffamount");
-                setValue("funwriteoffamount", Math.add(famount, -fwriteoffamount), 11L);
-                setValue("fwriteoffamount", Math.add(famount, -fwriteoffamount), 11L);
+//            PaoSetRemote ficashbillSet = getPaoSet("ficashbill");
+//            if (!ficashbillSet.isEmpty()) {
+//                double famount = ficashbillSet.getPao(0).getDouble("famount");
+//                double fwriteoffamount = ficashbillSet.getPao(0).getDouble("fwriteoffamount");
+//                setValue("funwriteoffamount", Math.add(famount, -fwriteoffamount), 11L);
+//                setValue("fwriteoffamount", Math.add(famount, -fwriteoffamount), 11L);
+//            }
+            if ("".equalsIgnoreCase(getString(fieldname))) {
+                setValue("funwriteoffamount", 0, 11L);
+                setValue("fwriteoffamount", 0, 11L);
+                setValue("faccclsnum", "", 11L);
             }
         } else if ("FAGENTNUM".equals(fieldname)) {
             setValue("ficashbillnum", "", 11L);
             setValue("fwriteoffamount", 0, 11L);
             setValue("faccclsnum", "", 11L);
+        } else if ("FUNWRITEOFFAMOUNT".equalsIgnoreCase(fieldname)) {
+            setValue("fwriteoffamount", getDouble(fieldname), 11L);
         }
     }