Przeglądaj źródła

配件核销金额统计逻辑

hxh 4 miesięcy temu
rodzic
commit
45c73194b1

+ 4 - 0
src/custom/restcontroller/R.java

@@ -6988,6 +6988,10 @@ public class R {
         public static class v1 {
         }
     }
+    public static class ID2025122016411103 {
+        public static class v1 {
+        }
+    }
 
 }
 

+ 20 - 10
src/custom/restcontroller/webmanage/sale/tpartreimbursement/tpartreimbursement.java

@@ -23,6 +23,7 @@ import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Calendar;
+import java.util.HashMap;
 import java.util.List;
 
 import static beans.stockbill.bills.XSCK.getCashbillEntity;
@@ -435,12 +436,12 @@ public class tpartreimbursement extends Controller {
     @CACHEING
     public String queryReimbursableAmount() throws YosException {
         sys_enterpriseid = content.getLong("sys_enterpriseid");
-        Rows sumamountRows = dbConnect.runSqlQuery("select amount from st_stockbill t1 " +
+        Rows sumamountRows = dbConnect.runSqlQuery("select t1.payamount,t1.paydiscountamount from st_stockbill t1 " +
                 "inner join st_stockbill_items t2 on t1.st_stockbillid=t2.st_stockbillid and t1.siteid=t2.siteid  " +
                 "inner join sa_order t3 on t2.sa_orderid=t3.sa_orderid and t2.siteid=t3.siteid" +
-                " where t1.siteid='" + siteid + "' and t1.status='审核' and t1.type='销售出库' and t3.type='配件订单' and t3.sys_enterpriseid='" + sys_enterpriseid + "' and DATE_FORMAT( t1.checkdate, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )");
+                " where t1.siteid='" + siteid + "' and t1.status='审核' and t1.rb=1 and t1.type='销售出库' and t3.type='配件订单' and t3.sys_enterpriseid='" + sys_enterpriseid + "' and DATE_FORMAT( t1.checkdate, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )");
 
-        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "st_stockbill");
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "st_stockbill","payamount","paydiscountamount");
         querySQL.setTableAlias("t1");
         querySQL.addJoinTable(JOINTYPE.left, "st_stockbill_items", "t2", "t2.st_stockbillid = t1.st_stockbillid AND t2.siteid = t1.siteid","amount");
         querySQL.setSiteid(siteid);
@@ -448,8 +449,10 @@ public class tpartreimbursement extends Controller {
         querySQL.setWhere("t1.sourceobject='tpartreimbursement' and t1.status='审核' and t1.type='销售出库' and DATE_FORMAT(t1.checkdate, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )");
         Rows rows = querySQL.query();
 
-
-        return getSucReturnObject().setData(sumamountRows.sum("amount").subtract(rows.sum("amount"))).toString();
+        HashMap<String,BigDecimal> map =new HashMap<>();
+        map.put("amount",sumamountRows.sum("payamount").subtract(rows.sum("payamount")));
+        map.put("discountamount",sumamountRows.sum("paydiscountamount").subtract(rows.sum("paydiscountamount")));
+        return getSucReturnObject().setData(map).toString();
     }
 
     @API(title = "查询审核需核销金额", apiversion = R.ID2025081815213903.v1.class)
@@ -471,6 +474,8 @@ public class tpartreimbursement extends Controller {
     @CACHEING_CLEAN(apiClass = {tpartreimbursement.class, stockbill.class, Order.class, OrderItems.class})
     public String hexiao() throws YosException {
         ArrayList<String> sqllist = new ArrayList<>();
+        BigDecimal amount =content.getBigDecimal("amount");
+        BigDecimal discountamount =content.getBigDecimal("discountamount");
         long sys_enterpriseid = content.getLong("sys_enterpriseid");
         JSONArray sa_tpartreimbursementdetailids = content.getJSONArray("sa_tpartreimbursementdetailids");
         JSONArray iteminfos = content.getJSONArray("iteminfos");
@@ -618,9 +623,14 @@ public class tpartreimbursement extends Controller {
             Integer sa_tpartreimbursementdetailid = (Integer) object;
             sqllist.add("update sa_tpartreimbursementdetail set hongbillno='"+billno+"' where sa_tpartreimbursementdetailid="+sa_tpartreimbursementdetailid);
         }
+        if (discountamount.compareTo(totalamount) > 0) {
+            insertSQL.setValue("payamount", 0);
+            insertSQL.setValue("paydiscountamount", totalamount);
+        } else {
+            insertSQL.setValue("payamount", totalamount.subtract(discountamount));
+            insertSQL.setValue("paydiscountamount", discountamount);
+        }
 
-        insertSQL.setValue("payamount", totalamount);
-        insertSQL.setValue("paydiscountamount", 0);
 
         sqllist.add(insertSQL.getSQL());
         sqllist.add(DataContrlLog.createLog(this, "st_stockbill", st_stockbillid, "新增", "销售出库单新增成功,来源配件核销"+rows.toJsonArray("billno").toJSONString()).getSQL());
@@ -634,9 +644,9 @@ public class tpartreimbursement extends Controller {
             Stockbill.check(this, st_stockbillid, true);
         } catch (YosException e) {
             // Code to handle the exception
-           dbConnect.runSqlUpdate("delete from st_stockbill where st_stockbillid="+st_stockbillid);
-           dbConnect.runSqlUpdate("delete from st_stockbill_items where st_stockbillid="+st_stockbillid);
-           dbConnect.runSqlUpdate("delete from sys_contrllog where ownerid="+st_stockbillid+" and ownertable='st_stockbill'");
+            dbConnect.runSqlUpdate("delete from st_stockbill where st_stockbillid="+st_stockbillid);
+            dbConnect.runSqlUpdate("delete from st_stockbill_items where st_stockbillid="+st_stockbillid);
+            dbConnect.runSqlUpdate("delete from sys_contrllog where ownerid="+st_stockbillid+" and ownertable='st_stockbill'");
             for(Object object:sa_tpartreimbursementdetailids){
                 Integer sa_tpartreimbursementdetailid = (Integer) object;
                 dbConnect.runSqlUpdate("update sa_tpartreimbursementdetail set hongbillno='' where sa_tpartreimbursementdetailid="+sa_tpartreimbursementdetailid);

+ 22 - 5
src/custom/restcontroller/webmanage/sale/tpartreimbursement/tpartreimbursementdetail.java

@@ -21,6 +21,23 @@ public class tpartreimbursementdetail extends Controller {
         super(content);
     }
 
+    @API(title = "查询经销商", apiversion = R.ID2025122016411103.v1.class)
+    @CACHEING
+    public String queryAgents() throws YosException {
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_tpartreimbursement");
+        querySQL.setTableAlias("t1");
+        querySQL.addJoinTable(JOINTYPE.inner, "sa_agents", "t2", "t1.siteid = t2.siteid and t1.sys_enterpriseid = t2.sys_enterpriseid", "agentnum","signingstate","delivery");
+        querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t3", "t1.siteid = t3.siteid and t1.sys_enterpriseid = t3.sys_enterpriseid", "sys_enterpriseid",
+                "phonenumber", "contact", "enterprisename","abbreviation");
+        querySQL.setSiteid(siteid);
+        querySQL.setWhere("t2.status='1'");
+        querySQL.setWhere("t1.status='审核' and  exists(select * from sa_tpartreimbursementdetail where sa_tpartreimbursementid=t1.sa_tpartreimbursementid and isverified=0)");
+        querySQL.setPage(pageSize, pageNumber);
+        Rows rows = querySQL.query();
+
+        return getSucReturnObject().setData(rows).toString();
+    }
+
     @API(title = "配件申请单明细查询", apiversion = R.ID2025081915191103.v1.class)
     @CACHEING
     public String queryOrderItemList() throws YosException {
@@ -131,13 +148,13 @@ public class tpartreimbursementdetail extends Controller {
         Rows rows = orderitemsQuery.query();
         RowsMap rowsMap = rows.toRowsMap("sa_orderitemsid");
 //        if(!rowscount.get(0).getBoolean("createflag")){
-            for (int i = 0; i < iteminfos.size(); i++) {
-                if(rowsMap.containsKey(iteminfos.getJSONObject(i).getStringValue("sa_orderitemsid"))){
-                    if(rowsMap.get(iteminfos.getJSONObject(i).getStringValue("sa_orderitemsid")).get(0).getBigDecimal("qty").compareTo(iteminfos.getJSONObject(i).getBigDecimal("qty"))<0){
-                        //return getErrReturnObject().setErrMsg("该配件核销单数量不符合要求,请检查").toString();
-                    }
+        for (int i = 0; i < iteminfos.size(); i++) {
+            if(rowsMap.containsKey(iteminfos.getJSONObject(i).getStringValue("sa_orderitemsid"))){
+                if(rowsMap.get(iteminfos.getJSONObject(i).getStringValue("sa_orderitemsid")).get(0).getBigDecimal("qty").compareTo(iteminfos.getJSONObject(i).getBigDecimal("qty"))<0){
+                    //return getErrReturnObject().setErrMsg("该配件核销单数量不符合要求,请检查").toString();
                 }
             }
+        }
 //        }
 
         int i = 0;