瀏覽代碼

回款返利逻辑变更

hu 1 月之前
父節點
當前提交
1b6e4f1006

+ 198 - 0
src/custom/restcontroller/webmanage/sale/salestarget_cucu/SQL/回款明细_新.sql

@@ -0,0 +1,198 @@
+with cashbill as (select sys_enterpriseid,
+                         sa_accountclassid,
+                         substring(t1.period, 6, 2)                period,
+                         sum(if(type = 0, 0 - amount, 0 + amount)) amount
+                  from sa_cashbill t1
+                  where ((t1.type = 1 and t1.class in ('货款', '物流赔偿')) or
+                         (t1.type = 0 and t1.subclass = '拨款'))
+                    and t1.status = '审核'
+                    and t1.siteid = $siteid$
+                    and substring(t1.period, 1, 4) =$year$
+                  group by sys_enterpriseid, sa_accountclassid, substring(t1.period, 6, 2)),
+     cashbill1 as (select t1.sys_enterpriseid, sum(amount) amount, substring(t1.period, 6, 2) period
+                   from sa_cashbill t1
+                            left join sa_agents t2
+                                      on t1.siteid = t2.siteid and t1.sys_enterpriseid = t2.sys_enterpriseid
+                   where t1.type = 1
+                     and t1.status = '审核'
+                     and t1.siteid = $siteid$
+                     and IF(t2.agentnum in ('D1001', 'DY01', '2314', '2315', '2316', '2701'), 1 = 1, t1.sa_accountclassid != 96)
+                     and substring(t1.period, 1, 4) =$year$
+                     and t1.subclass in ('广告费', '上样补贴', '装修补贴','内购返点', '年终返利')
+                   group by sys_enterpriseid, substring(t1.period, 6, 2)),
+     orders as (select t.sys_enterpriseid, submitdate, sum(t.amount) amount
+                from (select t1.sys_enterpriseid, t2.amount, date_format(t1.checkdate, '%m') submitdate
+                      from sa_order t1
+                               inner join sa_orderitems t2
+                                          on t1.siteid = t2.siteid and t1.sa_orderid = t2.sa_orderid
+                               inner join plm_item t3
+                                          on t2.siteid = t3.siteid and t2.itemid = t3.itemid
+                               left join sa_agents t4
+                                         on t1.siteid = t4.siteid and t1.sys_enterpriseid = t4.sys_enterpriseid
+                      where t1.siteid = $siteid$
+                                and t1.status in ('审核', '关闭','手工关闭') and t3.financeclasstype='木制品'
+                                and year(t1.checkdate) =$year$
+
+union all
+select t1.sys_enterpriseid, 0 - (t2.undeliqty * t2.price) , date_format(t1.closedate, '%m')
+from sa_order t1
+         inner join sa_orderitems t2
+                    on t1.siteid = t2.siteid and t1.sa_orderid = t2.sa_orderid
+         inner join plm_item t3
+                    on t2.siteid = t3.siteid and t2.itemid = t3.itemid
+where t1.siteid = $siteid$
+          and t1.status = '手工关闭' and t3.financeclasstype='木制品'
+          and year(t1.closedate) =$year$
+
+union all
+select t1.sys_enterpriseid, -t2.amount, date_format(t1.recheckdate, '%m')
+from sa_aftersalesmag t1
+         inner join sa_aftersalesmag_items t2
+                    on t1.siteid = t2.siteid and t1.sa_aftersalesmagid = t2.sa_aftersalesmagid
+where t1.siteid = $siteid$
+          and t1.status = '复核' and t2.reason='木制品退货'
+          and year(t1.recheckdate) =$year$) t
+group by sys_enterpriseid, submitdate),
+    orders1 as (select t.sys_enterpriseid, submitdate, sum(t.amount) amount
+from (select t1.sys_enterpriseid, t2.amount, date_format(t1.checkdate, '%m') submitdate
+    from sa_order t1
+    inner join sa_orderitems t2
+    on t1.siteid = t2.siteid and t1.sa_orderid = t2.sa_orderid
+    inner join plm_item t3
+    on t2.siteid = t3.siteid and t2.itemid = t3.itemid
+    where t1.siteid = $siteid$
+    and t1.status in ('审核', '关闭','手工关闭') and t3.financeclasstype='木制品'
+    and year(t1.checkdate) =$year$
+
+    union all
+    select t1.sys_enterpriseid, 0 - (t2.undeliqty * t2.price) , date_format(t1.closedate, '%m')
+    from sa_order t1
+    inner join sa_orderitems t2
+    on t1.siteid = t2.siteid and t1.sa_orderid = t2.sa_orderid
+    inner join plm_item t3
+    on t2.siteid = t3.siteid and t2.itemid = t3.itemid
+    where t1.siteid = $siteid$
+    and t1.status = '手工关闭' and t3.financeclasstype='木制品'
+    and year(t1.closedate) =$year$
+
+    union all
+    select t1.sys_enterpriseid, -t2.amount, date_format(t1.recheckdate, '%m')
+    from sa_aftersalesmag t1
+    inner join sa_aftersalesmag_items t2
+    on t1.siteid = t2.siteid and t1.sa_aftersalesmagid = t2.sa_aftersalesmagid
+    where t1.siteid = $siteid$
+    and t1.status = '复核' and t2.reason='木制品退货'
+    and year(t1.recheckdate) =$year$) t
+group by sys_enterpriseid, submitdate)
+select distinct t1.enterprisename,
+                t1.siteid,
+                t1.province,
+                t2.agentnum,
+                t4.areaname2,
+                t4.areaname3,
+                cast(cast(t5.amount1 as float) as char)                                amount11,
+                cast(cast(t5.amount2 as float) as char)                                amount12,
+                cast(cast(t5.amount3 as float) as char)                                amount13,
+                cast(cast(t5.amount4 as float) as char)                                amount14,
+                cast(cast(t5.amount5 as float) as char)                                amount15,
+                cast(cast((t5.amount1 + t5.amount5 + t5.amount3) as float) as char)    sum1,
+                cast(cast(t17.amount1 as float) as char)                               count1,
+                cast(cast(t17.amount2 as float) as char)                               count2,
+                cast(cast(t17.amount3 as float) as char)                               count3,
+                cast(cast(t17.amount4 as float) as char)                               count4,
+                cast(cast(t17.amount5 as float) as char)                               count5,
+                cast(cast((t17.amount1 + t17.amount5 + t17.amount3) as float) as char) count6
+from sys_enterprise t1
+         left join sa_agents t2 on t1.siteid = t2.siteid and t1.sys_enterpriseid = t2.sys_enterpriseid
+         left join sys_enterprise_tradefield t3 on t1.sys_enterpriseid = t3.sys_enterpriseid and t1.siteid = t3.siteid
+         left join (select t1.sa_saleareaid, t3.areaname areaname1, t2.areaname areaname2, t1.areaname areaname3
+                    from sa_salearea t1
+                             inner join sa_salearea t2
+                                        on t1.siteid = t2.siteid and t1.parentid = t2.sa_saleareaid and t2.level = 3
+                             inner join sa_salearea t3
+                                        on t1.siteid = t2.siteid and t2.parentid = t3.sa_saleareaid and t3.level = 2
+                    where t1.siteid = $siteid$
+                    union all
+                    select t1.sa_saleareaid, t3.areaname areaname1, t2.areaname areaname2, t1.areaname areaname3
+                    from sa_salearea t1
+                             inner join sa_salearea t2
+                                        on t1.siteid = t2.siteid and t1.parentid = t2.sa_saleareaid and t2.level = 2
+                             inner join sa_salearea t3
+                                        on t1.siteid = t2.siteid and t2.parentid = t3.sa_saleareaid and t3.level = 1
+                    where t1.siteid = $siteid$
+                    union all
+                    select t1.sa_saleareaid, t2.areaname, t1.areaname, null
+                    from sa_salearea t1
+                             inner join sa_salearea t2
+                                        on t1.siteid = t2.siteid and t1.parentid = t2.sa_saleareaid and t2.level = 1
+                    where t1.siteid = $siteid$
+                    union all
+                    select t1.sa_saleareaid, t1.areaname, null, null
+                    from sa_salearea t1
+                    where t1.level = 1
+                      and t1.siteid = $siteid$) t4 on t3.sa_saleareaid = t4.sa_saleareaid
+         left join (select t5.sys_enterpriseid,
+                           ifnull(t1.amount, 0) amount1,
+                           ifnull(t2.amount, 0) amount2,
+                           ifnull(t3.amount, 0) amount3,
+                           ifnull(t4.amount, 0) amount4,
+                           ifnull(t6.amount, 0) amount5
+                    from sys_enterprise t5
+                             left join (select sys_enterpriseid, sum(amount) amount
+                                        from cashbill t1
+                                        where t1.sa_accountclassid = 67
+                                          and t1.period = $period$
+                                        group by sys_enterpriseid) t1 on t5.sys_enterpriseid = t1.sys_enterpriseid
+                             left join (select sys_enterpriseid, sum(amount) amount
+                                        from cashbill t1
+                                        where t1.sa_accountclassid = 69
+                                          and t1.period =$period$
+                                        group by sys_enterpriseid) t2 on t5.sys_enterpriseid = t2.sys_enterpriseid
+                             left join (select sys_enterpriseid, sum(amount) amount
+                                        from cashbill1 t1
+                                        where t1.period = $period$
+                                        group by sys_enterpriseid) t3 on t5.sys_enterpriseid = t3.sys_enterpriseid
+                             left join (select t.sys_enterpriseid, t.amount
+                                        from orders t
+                                        where t.submitdate = $period$) t4
+                                       on t5.sys_enterpriseid = t4.sys_enterpriseid
+                             left join (select sys_enterpriseid, sum(amount) amount
+                                        from cashbill t1
+                                        where t1.sa_accountclassid = 98
+                                          and t1.period = $period$
+                                        group by sys_enterpriseid) t6 on t5.sys_enterpriseid = t6.sys_enterpriseid
+                    where t5.siteid = $siteid$) t5
+                   on t1.sys_enterpriseid = t5.sys_enterpriseid
+         inner join (select t5.sys_enterpriseid,
+                            ifnull(t1.amount, 0) amount1,
+                            ifnull(t2.amount, 0) amount2,
+                            ifnull(t3.amount, 0) amount3,
+                            ifnull(t4.amount, 0) amount4,
+                            ifnull(t6.amount, 0) amount5
+                     from sys_enterprise t5
+                              left join (select sys_enterpriseid, sum(amount) amount
+                                         from cashbill t1
+                                         where t1.sa_accountclassid = 67
+                                         group by sys_enterpriseid) t1 on t5.sys_enterpriseid = t1.sys_enterpriseid
+                              left join (select sys_enterpriseid, sum(amount) amount
+                                         from cashbill t1
+                                         where t1.sa_accountclassid = 69
+                                         group by sys_enterpriseid) t2 on t5.sys_enterpriseid = t2.sys_enterpriseid
+                              left join (select sys_enterpriseid, sum(amount) amount
+                                         from cashbill1 t1
+                                         group by sys_enterpriseid) t3 on t5.sys_enterpriseid = t3.sys_enterpriseid
+                              left join (select t.sys_enterpriseid, sum(t.amount) amount
+                                         from orders1 t
+                                         group by t.sys_enterpriseid) t4
+                                        on t5.sys_enterpriseid = t4.sys_enterpriseid
+                              left join (select sys_enterpriseid, sum(amount) amount
+                                         from cashbill t1
+                                         where t1.sa_accountclassid = 98
+                                         group by sys_enterpriseid) t6 on t5.sys_enterpriseid = t6.sys_enterpriseid
+                     where t5.siteid = $siteid$
+                         and (t1.amount>=0 or t2.amount>= 0 or t3.amount>= 0 or
+                              t4.amount>= 0) or t6.amount>= 0) t17 on t1.sys_enterpriseid = t17.sys_enterpriseid
+where t1.siteid = $siteid$
+  and t1.sys_enterpriseid not in (9116, 9117)
+  and $where$ and t4.sa_saleareaid in $sa_saleareaids$ order by t4.areaname2,t4.areaname3
+

+ 3 - 3
src/custom/restcontroller/webmanage/sale/salestarget_cucu/SQL/账户回款统计.sql

@@ -1,4 +1,4 @@
-select t3.accountname,substring(t1.period, 6, 2) month,sum(if(t1.type = 0, 0 - amount, 0 + amount)) amount
+select t3.accountname,substring(t1.period, 6, 2) month,t2.sa_saleareaid,sum(if(t1.type = 0, 0 - amount, 0 + amount)) amount
 from sa_cashbill t1
          left join (select DISTINCT sys_enterpriseid,sa_saleareaid,siteid from sys_enterprise_tradefield) t2 on t1.sys_enterpriseid=t2.sys_enterpriseid and t1.siteid=t2.siteid
          left join sa_accountclass t3 on t3.sa_accountclassid=t1.sa_accountclassid and t3.siteid=t1.siteid
@@ -7,6 +7,6 @@ where ((t1.type = 1 and t1.class in ('货款', '物流赔偿')) or
   and t1.status = '审核'
   and t1.siteid = $siteid$
   and substring(t1.period, 1, 4) =  $year$
-  and t2.sa_saleareaid in $sa_saleareaids$
+  and ifnull(t2.sa_saleareaid,0)!=0
   and $where$
-group by t3.accountname, substring(t1.period, 6, 2)
+group by t3.accountname, substring(t1.period, 6, 2),t2.sa_saleareaid

+ 3 - 3
src/custom/restcontroller/webmanage/sale/salestarget_cucu/SQL/账户返利统计.sql

@@ -1,4 +1,4 @@
-select  sum(amount) amount, substring(t1.period, 6, 2) month
+select  sum(amount) amount,t3.sa_saleareaid, substring(t1.period, 6, 2) month
 from sa_cashbill t1
          left join sa_agents t2
                    on t1.siteid = t2.siteid and t1.sys_enterpriseid = t2.sys_enterpriseid
@@ -9,6 +9,6 @@ where t1.type = 1
   and IF(t2.agentnum in ('D1001', 'DY01', '2314', '2315', '2316', '2701'), 1 = 1, t1.sa_accountclassid != 96)
   and substring(t1.period, 1, 4) =  $year$
   and t1.subclass in ('广告费', '上样补贴', '装修补贴','内购返点', '年终返利')
-  and t3.sa_saleareaid in $sa_saleareaids$
+  and ifnull(t3.sa_saleareaid,0)!=0
   and $where$
-group by substring(t1.period, 6, 2)
+group by substring(t1.period, 6, 2),t3.sa_saleareaid

+ 386 - 254
src/custom/restcontroller/webmanage/sale/salestarget_cucu/performancetargetboard.java

@@ -89,11 +89,29 @@ public class performancetargetboard extends Controller {
     @API(title = "查询业务员月度指标", apiversion = R.ID2025103010192003.v1.class)
     public String queryperformancetarget_month() throws YosException {
         //long hrid= content.getLong("hrid");
-        long sa_saleareaid= content.getLong("sa_saleareaid");
+        //long sa_saleareaid= content.getLong("sa_saleareaid");
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_hr","name","hrid");
+        querySQL.setTableAlias("t1");
+        querySQL.addJoinTable(JOINTYPE.inner, "sa_salearea_hr", "t2", "t1.siteid = t2.siteid and t1.hrid = t2.hrid");
+        querySQL.addJoinTable(JOINTYPE.inner, "sa_salearea", "t3", " t3.siteid = t2.siteid and t3.sa_saleareaid = t2.sa_saleareaid", "sa_saleareaid","areaname");
+
+        querySQL.setWhere("t1.siteid", siteid);
+        querySQL.setWhere("t1.hrid", hrid);
+
+        Rows arearows = querySQL.query();
+        Rows arearows1=new Rows();
+
+        ArrayList<Long> saleareaidlist = new ArrayList<>();
+        for (Row row : arearows) {
+            saleareaidlist.add(row.getLong("sa_saleareaid"));
+        }
+        arearows1 =getSubSaleAreas(this,saleareaidlist);
+        arearows.addAll(arearows1);
+
+
         long year= content.getLong("year");
         long month= content.getLong("month");
         String monthstr = String.format("%02d", month);
-        JSONObject jsonObject =new JSONObject();
 
         BigDecimal gcproportion =BigDecimal.ZERO;
         BigDecimal zzproportion =BigDecimal.ZERO;
@@ -111,311 +129,422 @@ public class performancetargetboard extends Controller {
         }
         SQLFactory personnelsqlFactory = new SQLFactory(this, "人员-目标详情列表");
         personnelsqlFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
-        personnelsqlFactory.addParameter_SQL("where", " t.sa_saleareaid="+sa_saleareaid);
+        personnelsqlFactory.addParameter_SQL("where", " 1=1 ");
         personnelsqlFactory.addParameter("siteid", siteid);
         Rows salestargetrows = dbConnect.runSqlQuery(personnelsqlFactory.getSQL());
-        BigDecimal rw_month=BigDecimal.ZERO;
-        if(salestargetrows.isNotEmpty()){
-            //月度任务(万)
-            jsonObject.put("rw_month",salestargetrows.get(0).getBigDecimal("m"+month+"l"));
-            rw_month=salestargetrows.get(0).getBigDecimal("m"+month+"l");
-        }else{
-            jsonObject.put("rw_month",BigDecimal.ZERO);
-        }
+        RowsMap salestargetrowsMap = salestargetrows.toRowsMap("sa_saleareaid");
 
-        ArrayList<Long> list = new ArrayList<>();
-        list.add(sa_saleareaid);
-        list.addAll(getSubSaleAreaIds(this,list));
 
         SQLFactory paymentsqlFactory = new SQLFactory(this, "账户回款统计");
         paymentsqlFactory.addParameter("year", year);
-        paymentsqlFactory.addParameter_in("sa_saleareaids", list);
         paymentsqlFactory.addParameter_SQL("where"," 1=1 ");
         paymentsqlFactory.addParameter("siteid", siteid);
-        Rows paymentRows = dbConnect.runSqlQuery(paymentsqlFactory.getSQL());
-        RowsMap paymentRowsMap =paymentRows.toRowsMap("accountname");
+        Rows paymentRows_All = dbConnect.runSqlQuery(paymentsqlFactory.getSQL());
+        //RowsMap paymentRowsMap =paymentRows.toRowsMap("accountname");
 
         SQLFactory rebatesqlFactory = new SQLFactory(this, "账户返利统计");
         rebatesqlFactory.addParameter("year", year);
-        rebatesqlFactory.addParameter_in("sa_saleareaids", list);
         rebatesqlFactory.addParameter_SQL("where"," 1=1 ");
         rebatesqlFactory.addParameter("siteid", siteid);
-        Rows rebateRows = dbConnect.runSqlQuery(rebatesqlFactory.getSQL());
-        RowsMap rebateRowsMap =rebateRows.toRowsMap("month");
-        BigDecimal xainjin=paymentRowsMap.containsKey("现金账户")?paymentRowsMap.get("现金账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("现金账户").toRowsMap("month").get(monthstr).get(0).getBigDecimal("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
-        BigDecimal huodong=paymentRowsMap.containsKey("活动预存账户")?paymentRowsMap.get("活动预存账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("活动预存账户").toRowsMap("month").get(monthstr).get(0).getBigDecimal("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
-        BigDecimal fanli=rebateRowsMap.containsKey(monthstr)?rebateRowsMap.get(monthstr).get(0).getBigDecimal("amount"):BigDecimal.ZERO;
+        Rows rebateRows_All = dbConnect.runSqlQuery(rebatesqlFactory.getSQL());
+        //RowsMap rebateRowsMap =rebateRows.toRowsMap("month");
+
+        for(Row row :arearows){
+            BigDecimal rw_month=BigDecimal.ZERO;
+            if(salestargetrowsMap.containsKey(row.getString("sa_saleareaid"))){
+                //月度任务(万)
+                row.put("rw_month",salestargetrowsMap.get(row.getString("sa_saleareaid")).get(0).getBigDecimal("m"+month+"l"));
+                rw_month=salestargetrowsMap.get(row.getString("sa_saleareaid")).get(0).getBigDecimal("m"+month+"l");
+            }else{
+                row.put("rw_month",BigDecimal.ZERO);
+            }
+            ArrayList<Long> list = new ArrayList<>();
+            list.add(row.getLong("sa_saleareaid"));
+            list.addAll(getSubSaleAreaIds(this,list));
+            Rows paymentRows =new Rows();
+            Rows rebateRows =new Rows();
+            for(Row paymentRow :paymentRows_All){
+                if(list.contains(paymentRow.getLong("sa_saleareaid"))){
+                    paymentRows.add(paymentRow);
+                }
+            }
+            RowsMap paymentRowsMap =paymentRows.toRowsMap("accountname");
+            for(Row rebateRow :rebateRows_All){
+                if(list.contains(rebateRow.getLong("sa_saleareaid"))){
+                    rebateRows.add(rebateRow);
+                }
+            }
+            RowsMap rebateRowsMap =rebateRows.toRowsMap("month");
 
-        //回款完成额
-        jsonObject.put("completedamount",xainjin.add(huodong).add(fanli));
+            BigDecimal xainjin=paymentRowsMap.containsKey("现金账户")?paymentRowsMap.get("现金账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("现金账户").toRowsMap("month").get(monthstr).sum("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
+            BigDecimal huodong=paymentRowsMap.containsKey("活动预存账户")?paymentRowsMap.get("活动预存账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("活动预存账户").toRowsMap("month").get(monthstr).sum("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
+            BigDecimal fanli=rebateRowsMap.containsKey(monthstr)?rebateRowsMap.get(monthstr).sum("amount"):BigDecimal.ZERO;
 
-        BigDecimal previousexceed=BigDecimal.ZERO;
-        BigDecimal completedamountexceed100=BigDecimal.ZERO;
-        for(int i=1;i<=month;i++){
-            previousexceed=completedamountexceed100;
+            //回款完成额
+            row.put("completedamount",xainjin.add(huodong).add(fanli));
 
-            BigDecimal looprw_month=salestargetrows.isNotEmpty()?salestargetrows.get(0).getBigDecimal("m"+i+"l"):BigDecimal.ZERO;
-            BigDecimal loopxainjin=paymentRowsMap.containsKey("现金账户")?paymentRowsMap.get("现金账户").toRowsMap("month").containsKey(String.format("%02d", i))?paymentRowsMap.get("现金账户").toRowsMap("month").get(String.format("%02d", i)).get(0).getBigDecimal("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
-            BigDecimal loophuodong=paymentRowsMap.containsKey("活动预存账户")?paymentRowsMap.get("活动预存账户").toRowsMap("month").containsKey(String.format("%02d", i))?paymentRowsMap.get("活动预存账户").toRowsMap("month").get(String.format("%02d", i)).get(0).getBigDecimal("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
-            BigDecimal loopfanli=rebateRowsMap.containsKey(String.format("%02d", i))?rebateRowsMap.get(String.format("%02d", i)).get(0).getBigDecimal("amount"):BigDecimal.ZERO;
+            BigDecimal previousexceed=BigDecimal.ZERO;
+            BigDecimal completedamountexceed100=BigDecimal.ZERO;
+            for(int i=1;i<=month;i++){
+                previousexceed=completedamountexceed100;
+                BigDecimal looprw_month=salestargetrowsMap.get(row.getString("sa_saleareaid")).isNotEmpty()?salestargetrowsMap.get(row.getString("sa_saleareaid")).get(0).getBigDecimal("m"+i+"l"):BigDecimal.ZERO;
+                BigDecimal loopxainjin=paymentRowsMap.containsKey("现金账户")?paymentRowsMap.get("现金账户").toRowsMap("month").containsKey(String.format("%02d", i))?paymentRowsMap.get("现金账户").toRowsMap("month").get(String.format("%02d", i)).sum("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
+                BigDecimal loophuodong=paymentRowsMap.containsKey("活动预存账户")?paymentRowsMap.get("活动预存账户").toRowsMap("month").containsKey(String.format("%02d", i))?paymentRowsMap.get("活动预存账户").toRowsMap("month").get(String.format("%02d", i)).sum("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
+                BigDecimal loopfanli=rebateRowsMap.containsKey(String.format("%02d", i))?rebateRowsMap.get(String.format("%02d", i)).sum("amount"):BigDecimal.ZERO;
 
-            BigDecimal loopgcgc=paymentRowsMap.containsKey("GC工程现金账户")?paymentRowsMap.get("GC工程现金账户").toRowsMap("month").containsKey(String.format("%02d", i))?paymentRowsMap.get("GC工程现金账户").toRowsMap("month").get(String.format("%02d", i)).get(0).getBigDecimal("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
-            BigDecimal loopzzgc=paymentRowsMap.containsKey("整装工程现金账户")?paymentRowsMap.get("整装工程现金账户").toRowsMap("month").containsKey(String.format("%02d", i))?paymentRowsMap.get("整装工程现金账户").toRowsMap("month").get(String.format("%02d", i)).get(0).getBigDecimal("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
+                BigDecimal loopgcgc=paymentRowsMap.containsKey("GC工程现金账户")?paymentRowsMap.get("GC工程现金账户").toRowsMap("month").containsKey(String.format("%02d", i))?paymentRowsMap.get("GC工程现金账户").toRowsMap("month").get(String.format("%02d", i)).sum("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
+                BigDecimal loopzzgc=paymentRowsMap.containsKey("整装工程现金账户")?paymentRowsMap.get("整装工程现金账户").toRowsMap("month").containsKey(String.format("%02d", i))?paymentRowsMap.get("整装工程现金账户").toRowsMap("month").get(String.format("%02d", i)).sum("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
 
-            completedamountexceed100=loopxainjin.add(loophuodong).add(loopfanli).add(previousexceed)
-                    .add(loopgcgc.max(looprw_month.multiply(gcproportion).multiply(BigDecimal.valueOf(10000))))
-                    .add(loopzzgc.max(looprw_month.multiply(zzproportion).multiply(BigDecimal.valueOf(10000))))
-                    .subtract(looprw_month.multiply(BigDecimal.valueOf(10000)));
+                completedamountexceed100=loopxainjin.add(loophuodong).add(loopfanli).add(previousexceed)
+                        .add(loopgcgc.min(looprw_month.multiply(gcproportion).multiply(BigDecimal.valueOf(10000))))
+                        .add(loopzzgc.min(looprw_month.multiply(zzproportion).multiply(BigDecimal.valueOf(10000))))
+                        .subtract(looprw_month.multiply(BigDecimal.valueOf(10000)));
 
-        }
+            }
 
 
-        //上月完成额超出部分
-        jsonObject.put("previousexceed",previousexceed.compareTo(BigDecimal.ZERO)>0?previousexceed:0);
-
-        BigDecimal gcgc=paymentRowsMap.containsKey("GC工程现金账户")?paymentRowsMap.get("GC工程现金账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("GC工程现金账户").toRowsMap("month").get(monthstr).get(0).getBigDecimal("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
-        //GC工程完成额
-        jsonObject.put("gccompletedamount",gcgc.max(rw_month.multiply(gcproportion).multiply(BigDecimal.valueOf(10000))));
-        //GC工程超出部分
-        jsonObject.put("gccompletedamountexceed",gcgc.subtract(rw_month.multiply(gcproportion).multiply(BigDecimal.valueOf(10000))).compareTo(BigDecimal.ZERO)>0?gcgc.subtract(rw_month.multiply(gcproportion).multiply(BigDecimal.valueOf(10000))):0);
-
-        BigDecimal zzgc=paymentRowsMap.containsKey("整装工程现金账户")?paymentRowsMap.get("整装工程现金账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("整装工程现金账户").toRowsMap("month").get(monthstr).get(0).getBigDecimal("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
-        //整装工程完成额
-        jsonObject.put("zzcompletedamount",zzgc.max(rw_month.multiply(zzproportion).multiply(BigDecimal.valueOf(10000))));
-        //整装工程超出部分
-        jsonObject.put("zzcompletedamountexceed",zzgc.subtract(rw_month.multiply(zzproportion).multiply(BigDecimal.valueOf(10000))).compareTo(BigDecimal.ZERO)>0?zzgc.subtract(rw_month.multiply(zzproportion).multiply(BigDecimal.valueOf(10000))):0);
-
-        //完成额超出100%部分
-        jsonObject.put("completedamountexceed100",completedamountexceed100.compareTo(BigDecimal.ZERO)>0?completedamountexceed100:0);
-        //实际完成额
-        jsonObject.put("actualcompletedamount",jsonObject.getBigDecimal("completedamount").add(jsonObject.getBigDecimal("gccompletedamount")).add(jsonObject.getBigDecimal("zzcompletedamount")));
-        //实际完成百分比
-        if(rw_month.compareTo(BigDecimal.ZERO)==0){
-            jsonObject.put("actualcompletedpercentage",0);
-        }else{
-            jsonObject.put("actualcompletedpercentage", (jsonObject.getBigDecimal("completedamount").add(jsonObject.getBigDecimal("previousexceed")).add(jsonObject.getBigDecimal("gccompletedamount")).add(jsonObject.getBigDecimal("zzcompletedamount"))).divide((rw_month.multiply(BigDecimal.valueOf(10000))),4, RoundingMode.HALF_UP));
+            //上月完成额超出部分
+            row.put("previousexceed",previousexceed.compareTo(BigDecimal.ZERO)>0?previousexceed:0);
+
+            BigDecimal gcgc=paymentRowsMap.containsKey("GC工程现金账户")?paymentRowsMap.get("GC工程现金账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("GC工程现金账户").toRowsMap("month").get(monthstr).sum("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
+            //GC工程完成额
+            row.put("gccompletedamount",gcgc.min(rw_month.multiply(gcproportion).multiply(BigDecimal.valueOf(10000))));
+            //GC工程超出部分
+            row.put("gccompletedamountexceed",gcgc.subtract(rw_month.multiply(gcproportion).multiply(BigDecimal.valueOf(10000))).compareTo(BigDecimal.ZERO)>0?gcgc.subtract(rw_month.multiply(gcproportion).multiply(BigDecimal.valueOf(10000))):0);
+
+            BigDecimal zzgc=paymentRowsMap.containsKey("整装工程现金账户")?paymentRowsMap.get("整装工程现金账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("整装工程现金账户").toRowsMap("month").get(monthstr).sum("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
+            //整装工程完成额
+            row.put("zzcompletedamount",zzgc.min(rw_month.multiply(zzproportion).multiply(BigDecimal.valueOf(10000))));
+            //整装工程超出部分
+            row.put("zzcompletedamountexceed",zzgc.subtract(rw_month.multiply(zzproportion).multiply(BigDecimal.valueOf(10000))).compareTo(BigDecimal.ZERO)>0?zzgc.subtract(rw_month.multiply(zzproportion).multiply(BigDecimal.valueOf(10000))):0);
+
+            //完成额超出100%部分
+            row.put("completedamountexceed100",completedamountexceed100.compareTo(BigDecimal.ZERO)>0?completedamountexceed100:0);
+            //实际完成额
+            row.put("actualcompletedamount",row.getBigDecimal("completedamount").add(row.getBigDecimal("gccompletedamount")).add(row.getBigDecimal("zzcompletedamount")));
+            //实际完成百分比
+            if(rw_month.compareTo(BigDecimal.ZERO)==0){
+                row.put("actualcompletedpercentage",0);
+            }else{
+                row.put("actualcompletedpercentage", (row.getBigDecimal("completedamount").add(row.getBigDecimal("previousexceed")).add(row.getBigDecimal("gccompletedamount")).add(row.getBigDecimal("zzcompletedamount"))).divide((rw_month.multiply(BigDecimal.valueOf(10000))),4, RoundingMode.HALF_UP));
+            }
+        }
+        Rows arearows_quarter= queryperformancetarget_quarter(month,arearows,salestargetrowsMap,paymentRows_All,rebateRows_All);
+        System.err.println(arearows_quarter.get(0).getString("sa_saleareaid")+":"+arearows_quarter.get(0).getBigDecimal("completedamount"));
+        RowsMap arearowsMap_quarter=arearows_quarter.toRowsMap("sa_saleareaid");
+        Rows arearows_total= queryperformancetarget_total(month,arearows,salestargetrowsMap,paymentRows_All,rebateRows_All);
+        RowsMap arearowsMap_total=arearows_total.toRowsMap("sa_saleareaid");
+        for(Row row : arearows){
+            if(arearowsMap_quarter.containsKey(row.getString("sa_saleareaid"))){
+                row.put("rw_quarter",arearowsMap_quarter.get(row.getString("sa_saleareaid")).get(0).getBigDecimal("rw_quarter"));
+                row.put("actualcompletedamount_quarter",arearowsMap_quarter.get(row.getString("sa_saleareaid")).get(0).getBigDecimal("actualcompletedamount_quarter"));
+                row.put("zzcompletedamount_quarter",arearowsMap_quarter.get(row.getString("sa_saleareaid")).get(0).getBigDecimal("zzcompletedamount_quarter"));
+                row.put("gccompletedamount_quarter",arearowsMap_quarter.get(row.getString("sa_saleareaid")).get(0).getBigDecimal("gccompletedamount_quarter"));
+                row.put("actualcompletedpercentage_quarter",arearowsMap_quarter.get(row.getString("sa_saleareaid")).get(0).getBigDecimal("actualcompletedpercentage_quarter"));
+                System.err.println(row.getString("sa_saleareaid")+":"+arearowsMap_quarter.get(row.getString("sa_saleareaid")).get(0).getBigDecimal("completedamount_quarter"));
+                row.put("completedamount_quarter",arearowsMap_quarter.get(row.getString("sa_saleareaid")).get(0).getBigDecimal("completedamount_quarter"));
+                row.put("previousexceed_quarter",arearowsMap_quarter.get(row.getString("sa_saleareaid")).get(0).getBigDecimal("previousexceed_quarter"));
+            }else{
+                row.put("rw_quarter",0);
+                row.put("actualcompletedamount_quarter",0);
+                row.put("zzcompletedamount_quarter",0);
+                row.put("gccompletedamount_quarter",0);
+                row.put("actualcompletedpercentage_quarter",0);
+                row.put("completedamount_quarter",0);
+                row.put("previousexceed_quarter",0);
+            }
+            if(arearowsMap_total.containsKey(row.getString("sa_saleareaid"))){
+                row.put("rw_total",arearowsMap_total.get(row.getString("sa_saleareaid")).get(0).getBigDecimal("rw_total"));
+                row.put("actualcompletedamount_total",arearowsMap_total.get(row.getString("sa_saleareaid")).get(0).getBigDecimal("actualcompletedamount_total"));
+                row.put("zzcompletedamount_total",arearowsMap_total.get(row.getString("sa_saleareaid")).get(0).getBigDecimal("zzcompletedamount_total"));
+                row.put("gccompletedamount_total",arearowsMap_total.get(row.getString("sa_saleareaid")).get(0).getBigDecimal("gccompletedamount_total"));
+                row.put("actualcompletedpercentage_total",arearowsMap_total.get(row.getString("sa_saleareaid")).get(0).getBigDecimal("actualcompletedpercentage_total"));
+                row.put("differenceamount_total",arearowsMap_total.get(row.getString("sa_saleareaid")).get(0).getBigDecimal("differenceamount_total"));
+                row.put("completedamount_total",arearowsMap_total.get(row.getString("sa_saleareaid")).get(0).getBigDecimal("completedamount_total"));
+            }else{
+                row.put("rw_total",0);
+                row.put("actualcompletedamount_total",0);
+                row.put("zzcompletedamount_total",0);
+                row.put("gccompletedamount_total",0);
+                row.put("actualcompletedpercentage_total",0);
+                row.put("differenceamount_total",0);
+                row.put("completedamount_total",0);
+            }
         }
 
-
-        return getSucReturnObject().setData(jsonObject).toString();
+        return getSucReturnObject().setData(arearows).toString();
     }
 
-    @API(title = "查询业务员季度指标", apiversion = R.ID2025103010193903.v1.class)
-    public String queryperformancetarget_quarter() throws YosException {
+    /**
+     * 查询业务员季度指标
+     * @param selectmonth
+     * @param arearows
+     * @param salestargetrowsMap
+     * @param paymentRows_All
+     * @param rebateRows_All
+     * @return
+     * @throws YosException
+     */
+    public Rows queryperformancetarget_quarter(long selectmonth,Rows arearows,RowsMap salestargetrowsMap,Rows paymentRows_All,Rows rebateRows_All) throws YosException {
 //        long hrid= content.getLong("hrid");
-        long sa_saleareaid= content.getLong("sa_saleareaid");
-        long year= content.getLong("year");
-        int selectmonth= content.getIntValue("month");
-        JSONObject jsonObject =new JSONObject();
+        //long sa_saleareaid= content.getLong("sa_saleareaid");
 
-        Rows salestargetbillrows =dbConnect.runSqlQuery("select * from sa_salestargetbill where siteid='"+siteid+"' and year="+year+" and targettype='人员目标'");
-        long sa_salestargetbillid=0;
-        if(salestargetbillrows.isNotEmpty()){
-            sa_salestargetbillid=salestargetbillrows.get(0).getLong("sa_salestargetbillid");
-        }
-        SQLFactory personnelsqlFactory = new SQLFactory(this, "人员-目标详情列表");
-        personnelsqlFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
-        personnelsqlFactory.addParameter_SQL("where", " t.sa_saleareaid="+sa_saleareaid);
-        personnelsqlFactory.addParameter("siteid", siteid);
-        Rows salestargetrows = dbConnect.runSqlQuery(personnelsqlFactory.getSQL());
-        BigDecimal rw_quarter=BigDecimal.ZERO;
-        BigDecimal rw_previousquarter=BigDecimal.ZERO;
-        BigDecimal completedamount=BigDecimal.ZERO;
-        BigDecimal gcgccompletedamount=BigDecimal.ZERO;
-        BigDecimal zzgccompletedamount=BigDecimal.ZERO;
-        BigDecimal previouscompletedamount=BigDecimal.ZERO;
-        List<Integer> months = getCurrentQuarterMonths(selectmonth);
-        List<Integer> previousmonths =getPreviousQuarterMonthsCalendar(selectmonth);
-        if(salestargetrows.isNotEmpty()){
-            for(int month : months){
-                rw_quarter=rw_quarter.add(salestargetrows.get(0).getBigDecimal("m"+month+"l"));
+//        Rows salestargetbillrows =dbConnect.runSqlQuery("select * from sa_salestargetbill where siteid='"+siteid+"' and year="+year+" and targettype='人员目标'");
+//        long sa_salestargetbillid=0;
+//        if(salestargetbillrows.isNotEmpty()){
+//            sa_salestargetbillid=salestargetbillrows.get(0).getLong("sa_salestargetbillid");
+//        }
+//        SQLFactory personnelsqlFactory = new SQLFactory(this, "人员-目标详情列表");
+//        personnelsqlFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
+//        personnelsqlFactory.addParameter_SQL("where", " 1=1 ");
+//        personnelsqlFactory.addParameter("siteid", siteid);
+//        Rows salestargetrows = dbConnect.runSqlQuery(personnelsqlFactory.getSQL());
+//        RowsMap salestargetrowsMap = salestargetrows.toRowsMap("sa_saleareaid");
+
+
+        List<Integer> months = getCurrentQuarterMonths((int)selectmonth);
+        List<Integer> previousmonths =getPreviousQuarterMonthsCalendar((int)selectmonth);
+
+
+//        SQLFactory paymentsqlFactory = new SQLFactory(this, "账户回款统计");
+//        paymentsqlFactory.addParameter("year", year);
+//        paymentsqlFactory.addParameter_SQL("where"," 1=1 ");
+//        paymentsqlFactory.addParameter("siteid", siteid);
+//        Rows paymentRows_All = dbConnect.runSqlQuery(paymentsqlFactory.getSQL());
+//        RowsMap paymentRowsMap =paymentRows.toRowsMap("accountname");
+
+//        SQLFactory rebatesqlFactory = new SQLFactory(this, "账户返利统计");
+//        rebatesqlFactory.addParameter("year", year);
+//        rebatesqlFactory.addParameter_SQL("where"," 1=1 ");
+//        rebatesqlFactory.addParameter("siteid", siteid);
+//        Rows rebateRows_All = dbConnect.runSqlQuery(rebatesqlFactory.getSQL());
+//        RowsMap rebateRowsMap =rebateRows.toRowsMap("month");
+
+        Rows arearowsResult =new Rows();
+        for(Row row :arearows){
+            Row arearowResult =new Row();
+            arearowResult.put("sa_saleareaid",row.getLong("sa_saleareaid"));
+            BigDecimal rw_quarter=BigDecimal.ZERO;
+            BigDecimal rw_previousquarter=BigDecimal.ZERO;
+            BigDecimal completedamount=BigDecimal.ZERO;
+            BigDecimal gcgccompletedamount=BigDecimal.ZERO;
+            BigDecimal zzgccompletedamount=BigDecimal.ZERO;
+            if(salestargetrowsMap.containsKey(row.getString("sa_saleareaid"))){
+                for(int month : months){
+                    rw_quarter=rw_quarter.add(salestargetrowsMap.get(row.getString("sa_saleareaid")).get(0).getBigDecimal("m"+month+"l"));
+                }
+                for(int previousmonth : previousmonths){
+                    rw_previousquarter=rw_previousquarter.add(salestargetrowsMap.get(row.getString("sa_saleareaid")).get(0).getBigDecimal("m"+previousmonth+"l"));
+                }
             }
-            for(int previousmonth : previousmonths){
-                rw_previousquarter=rw_previousquarter.add(salestargetrows.get(0).getBigDecimal("m"+previousmonth+"l"));
+            //季度任务(万)
+            arearowResult.put("rw_quarter",rw_quarter);
+            ArrayList<Long> list = new ArrayList<>();
+            list.add(row.getLong("sa_saleareaid"));
+            list.addAll(getSubSaleAreaIds(this,list));
+
+            Rows paymentRows =new Rows();
+            Rows rebateRows =new Rows();
+            for(Row paymentRow :paymentRows_All){
+                if(list.contains(paymentRow.getLong("sa_saleareaid"))){
+                    paymentRows.add(paymentRow);
+                }
             }
-        }
-        ArrayList<Long> list = new ArrayList<>();
-        list.add(sa_saleareaid);
-        list.addAll(getSubSaleAreaIds(this,list));
-        //季度任务(万)
-        jsonObject.put("rw_quarter",rw_quarter);
-        SQLFactory paymentsqlFactory = new SQLFactory(this, "账户回款统计");
-        paymentsqlFactory.addParameter("year", year);
-        paymentsqlFactory.addParameter_in("sa_saleareaids",list);
-        paymentsqlFactory.addParameter_SQL("where"," 1=1 ");
-        paymentsqlFactory.addParameter("siteid", siteid);
-        Rows paymentRows = dbConnect.runSqlQuery(paymentsqlFactory.getSQL());
-        RowsMap paymentRowsMap =paymentRows.toRowsMap("accountname");
+            RowsMap paymentRowsMap =paymentRows.toRowsMap("accountname");
+            for(Row rebateRow :rebateRows_All){
+                if(list.contains(rebateRow.getLong("sa_saleareaid"))){
+                    rebateRows.add(rebateRow);
+                }
+            }
+            RowsMap rebateRowsMap =rebateRows.toRowsMap("month");
 
-        SQLFactory rebatesqlFactory = new SQLFactory(this, "账户返利统计");
-        rebatesqlFactory.addParameter("year", year);
-        rebatesqlFactory.addParameter_in("sa_saleareaids",list);
-        rebatesqlFactory.addParameter_SQL("where"," 1=1 ");
-        rebatesqlFactory.addParameter("siteid", siteid);
-        Rows rebateRows = dbConnect.runSqlQuery(rebatesqlFactory.getSQL());
-        RowsMap rebateRowsMap =rebateRows.toRowsMap("month");
-        for(int month : months){
-            String monthstr = String.format("%02d", month);
-            BigDecimal xainjin=paymentRowsMap.containsKey("现金账户")?paymentRowsMap.get("现金账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("现金账户").toRowsMap("month").get(monthstr).get(0).getBigDecimal("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
-            BigDecimal huodong=paymentRowsMap.containsKey("活动预存账户")?paymentRowsMap.get("活动预存账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("活动预存账户").toRowsMap("month").get(monthstr).get(0).getBigDecimal("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
-            BigDecimal fanli=rebateRowsMap.containsKey(monthstr)?rebateRowsMap.get(monthstr).get(0).getBigDecimal("amount"):BigDecimal.ZERO;
-            BigDecimal gcgc=paymentRowsMap.containsKey("GC工程现金账户")?paymentRowsMap.get("GC工程现金账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("GC工程现金账户").toRowsMap("month").get(monthstr).get(0).getBigDecimal("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
-            BigDecimal zzgc=paymentRowsMap.containsKey("整装工程现金账户")?paymentRowsMap.get("整装工程现金账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("整装工程现金账户").toRowsMap("month").get(monthstr).get(0).getBigDecimal("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
-            gcgccompletedamount=gcgccompletedamount.add(gcgc);
-            zzgccompletedamount=zzgccompletedamount.add(zzgc);
-            completedamount=completedamount.add(xainjin).add(huodong).add(fanli);
-        }
-        for(int previousmonth : previousmonths){
-            String previousmonthstr = String.format("%02d", previousmonth);
-            BigDecimal previousxainjin=paymentRowsMap.containsKey("现金账户")?paymentRowsMap.get("现金账户").toRowsMap("month").containsKey(previousmonthstr)?paymentRowsMap.get("现金账户").toRowsMap("month").get(previousmonthstr).get(0).getBigDecimal("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
-            BigDecimal previoushuodong=paymentRowsMap.containsKey("活动预存账户")?paymentRowsMap.get("活动预存账户").toRowsMap("month").containsKey(previousmonthstr)?paymentRowsMap.get("活动预存账户").toRowsMap("month").get(previousmonthstr).get(0).getBigDecimal("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
-            BigDecimal previousfanli=rebateRowsMap.containsKey(previousmonthstr)?rebateRowsMap.get(previousmonthstr).get(0).getBigDecimal("amount"):BigDecimal.ZERO;
-            previouscompletedamount=previouscompletedamount.add(previousxainjin).add(previoushuodong).add(previousfanli);
-        }
+            for(int month : months){
+                String monthstr = String.format("%02d", month);
+                BigDecimal xainjin=paymentRowsMap.containsKey("现金账户")?paymentRowsMap.get("现金账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("现金账户").toRowsMap("month").get(monthstr).sum("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
+                BigDecimal huodong=paymentRowsMap.containsKey("活动预存账户")?paymentRowsMap.get("活动预存账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("活动预存账户").toRowsMap("month").get(monthstr).sum("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
+                BigDecimal fanli=rebateRowsMap.containsKey(monthstr)?rebateRowsMap.get(monthstr).sum("amount"):BigDecimal.ZERO;
+                BigDecimal gcgc=paymentRowsMap.containsKey("GC工程现金账户")?paymentRowsMap.get("GC工程现金账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("GC工程现金账户").toRowsMap("month").get(monthstr).sum("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
+                BigDecimal zzgc=paymentRowsMap.containsKey("整装工程现金账户")?paymentRowsMap.get("整装工程现金账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("整装工程现金账户").toRowsMap("month").get(monthstr).sum("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
+                gcgccompletedamount=gcgccompletedamount.add(gcgc);
+                zzgccompletedamount=zzgccompletedamount.add(zzgc);
+                completedamount=completedamount.add(xainjin).add(huodong).add(fanli);
+            }
 
 
-        BigDecimal previousexceed=BigDecimal.ZERO;
-        BigDecimal completedamountexceed100=BigDecimal.ZERO;
-        int quarter = getQuarterByMonth(selectmonth);
-        for(int i=1;i<=quarter;i++){
-            previousexceed=completedamountexceed100;
-            List<Integer> loopmonths = getCurrentQuarterMonths(i*3-2);
-            BigDecimal looprw_quarter=BigDecimal.ZERO;
-            BigDecimal loopcompletedamount=BigDecimal.ZERO;
-            BigDecimal loopgcgccompletedamount=BigDecimal.ZERO;
-            BigDecimal loopzzgccompletedamount=BigDecimal.ZERO;
-            if(salestargetrows.isNotEmpty()){
+            BigDecimal previousexceed=BigDecimal.ZERO;
+            BigDecimal completedamountexceed100=BigDecimal.ZERO;
+            int quarter = getQuarterByMonth((int)selectmonth);
+            for(int i=1;i<=quarter;i++){
+                previousexceed=completedamountexceed100;
+                List<Integer> loopmonths = getCurrentQuarterMonths(i*3-2);
+                BigDecimal looprw_quarter=BigDecimal.ZERO;
+                BigDecimal loopcompletedamount=BigDecimal.ZERO;
+                BigDecimal loopgcgccompletedamount=BigDecimal.ZERO;
+                BigDecimal loopzzgccompletedamount=BigDecimal.ZERO;
+                if(salestargetrowsMap.get(row.getString("sa_saleareaid")).isNotEmpty()){
+                    for(int month : loopmonths){
+                        looprw_quarter=looprw_quarter.add(salestargetrowsMap.get(row.getString("sa_saleareaid")).get(0).getBigDecimal("m"+month+"l"));
+                    }
+                }
                 for(int month : loopmonths){
-                    looprw_quarter=looprw_quarter.add(salestargetrows.get(0).getBigDecimal("m"+month+"l"));
+                    String monthstr = String.format("%02d", month);
+                    BigDecimal loopxainjin=paymentRowsMap.containsKey("现金账户")?paymentRowsMap.get("现金账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("现金账户").toRowsMap("month").get(monthstr).sum("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
+                    BigDecimal loophuodong=paymentRowsMap.containsKey("活动预存账户")?paymentRowsMap.get("活动预存账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("活动预存账户").toRowsMap("month").get(monthstr).sum("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
+                    BigDecimal loopfanli=rebateRowsMap.containsKey(monthstr)?rebateRowsMap.get(monthstr).sum("amount"):BigDecimal.ZERO;
+                    BigDecimal loopgcgc=paymentRowsMap.containsKey("GC工程现金账户")?paymentRowsMap.get("GC工程现金账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("GC工程现金账户").toRowsMap("month").get(monthstr).sum("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
+                    BigDecimal loopzzgc=paymentRowsMap.containsKey("整装工程现金账户")?paymentRowsMap.get("整装工程现金账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("整装工程现金账户").toRowsMap("month").get(monthstr).sum("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
+                    loopgcgccompletedamount=loopgcgccompletedamount.add(loopgcgc);
+                    loopzzgccompletedamount=loopzzgccompletedamount.add(loopzzgc);
+                    loopcompletedamount=loopcompletedamount.add(loopxainjin).add(loophuodong).add(loopfanli);
                 }
-            }
-            for(int month : loopmonths){
-                String monthstr = String.format("%02d", month);
-                BigDecimal loopxainjin=paymentRowsMap.containsKey("现金账户")?paymentRowsMap.get("现金账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("现金账户").toRowsMap("month").get(monthstr).get(0).getBigDecimal("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
-                BigDecimal loophuodong=paymentRowsMap.containsKey("活动预存账户")?paymentRowsMap.get("活动预存账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("活动预存账户").toRowsMap("month").get(monthstr).get(0).getBigDecimal("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
-                BigDecimal loopfanli=rebateRowsMap.containsKey(monthstr)?rebateRowsMap.get(monthstr).get(0).getBigDecimal("amount"):BigDecimal.ZERO;
-                BigDecimal loopgcgc=paymentRowsMap.containsKey("GC工程现金账户")?paymentRowsMap.get("GC工程现金账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("GC工程现金账户").toRowsMap("month").get(monthstr).get(0).getBigDecimal("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
-                BigDecimal loopzzgc=paymentRowsMap.containsKey("整装工程现金账户")?paymentRowsMap.get("整装工程现金账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("整装工程现金账户").toRowsMap("month").get(monthstr).get(0).getBigDecimal("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
-                loopgcgccompletedamount=loopgcgccompletedamount.add(loopgcgc);
-                loopzzgccompletedamount=loopzzgccompletedamount.add(loopzzgc);
-                loopcompletedamount=loopcompletedamount.add(loopxainjin).add(loophuodong).add(loopfanli);
-            }
 
-            completedamountexceed100=loopcompletedamount.add(previousexceed).add(loopgcgccompletedamount)
-                    .add(loopzzgccompletedamount).subtract(looprw_quarter.multiply(BigDecimal.valueOf(10000)));
+                completedamountexceed100=loopcompletedamount.add(previousexceed).add(loopgcgccompletedamount)
+                        .add(loopzzgccompletedamount).subtract(looprw_quarter.multiply(BigDecimal.valueOf(10000)));
 
-        }
+            }
 
-        //回款完成额
-        jsonObject.put("completedamount",completedamount);
-        //上季完成额超出部分
-        jsonObject.put("previousexceed",previousexceed.compareTo(BigDecimal.ZERO)>0?previousexceed:0);
-        //GC工程完成额
-        jsonObject.put("gccompletedamount",gcgccompletedamount);
-        //整装工程完成额
-        jsonObject.put("zzcompletedamount",zzgccompletedamount);
-        //季度完成额
-        jsonObject.put("actualcompletedamount",jsonObject.getBigDecimal("completedamount").add(jsonObject.getBigDecimal("previousexceed")).add(jsonObject.getBigDecimal("gccompletedamount")).add(jsonObject.getBigDecimal("zzcompletedamount")));
-        //季度百分比
-        if(rw_quarter.compareTo(BigDecimal.ZERO)==0){
-            jsonObject.put("actualcompletedpercentage",0);
-        }else{
-            jsonObject.put("actualcompletedpercentage",jsonObject.getBigDecimal("actualcompletedamount").divide((rw_quarter.multiply(BigDecimal.valueOf(10000))),4, RoundingMode.HALF_UP));
+            //回款完成额
+            arearowResult.put("completedamount_quarter",completedamount);
+            //上季完成额超出部分
+            arearowResult.put("previousexceed_quarter",previousexceed.compareTo(BigDecimal.ZERO)>0?previousexceed:0);
+            //GC工程完成额
+            arearowResult.put("gccompletedamount_quarter",gcgccompletedamount);
+            //整装工程完成额
+            arearowResult.put("zzcompletedamount_quarter",zzgccompletedamount);
+            //季度完成额
+            arearowResult.put("actualcompletedamount_quarter",arearowResult.getBigDecimal("completedamount_quarter").add(arearowResult.getBigDecimal("previousexceed_quarter")).add(arearowResult.getBigDecimal("gccompletedamount_quarter")).add(arearowResult.getBigDecimal("zzcompletedamount_quarter")));
+            //季度百分比
+            if(rw_quarter.compareTo(BigDecimal.ZERO)==0){
+                arearowResult.put("actualcompletedpercentage_quarter",0);
+            }else{
+                arearowResult.put("actualcompletedpercentage_quarter",arearowResult.getBigDecimal("actualcompletedamount_quarter").divide((rw_quarter.multiply(BigDecimal.valueOf(10000))),4, RoundingMode.HALF_UP));
+            }
+            arearowsResult.add(arearowResult);
         }
-        return getSucReturnObject().setData(jsonObject).toString();
+        return arearowsResult;
 
     }
 
-    @API(title = "查询业务员总指标", apiversion = R.ID2025103010195403.v1.class)
-    public String queryperformancetarget_total() throws YosException {
-        //long hrid= content.getLong("hrid");
-        long sa_saleareaid= content.getLong("sa_saleareaid");
-        long year= content.getLong("year");
-        JSONArray months = content.getJSONArray("months");
-        JSONObject jsonObject =new JSONObject();
+    /**
+     * 查询业务员总指标
+     * @param selectmonth
+     * @param arearows
+     * @param salestargetrowsMap
+     * @param paymentRows_All
+     * @param rebateRows_All
+     * @return
+     * @throws YosException
+     */
+    public Rows queryperformancetarget_total(long selectmonth,Rows arearows,RowsMap salestargetrowsMap,Rows paymentRows_All,Rows rebateRows_All) throws YosException {
 
+        JSONArray months =new JSONArray();
         BigDecimal gcproportion =BigDecimal.ZERO.divide(BigDecimal.valueOf(100));
         BigDecimal zzproportion =BigDecimal.ZERO.divide(BigDecimal.valueOf(100));
-
-        Rows salestargetbillrows =dbConnect.runSqlQuery("select * from sa_salestargetbill where siteid='"+siteid+"' and year="+year+" and targettype='人员目标'");
+//        Rows salestargetbillrows =dbConnect.runSqlQuery("select * from sa_salestargetbill where siteid='"+siteid+"' and year="+year+" and targettype='人员目标'");
         Rows rows = dbConnect.runSqlQuery("select * from sys_site_parameter where siteid='" + siteid + "'");
         if(rows.isNotEmpty()){
             gcproportion=rows.get(0).getBigDecimal("gcproportion");
             zzproportion=rows.get(0).getBigDecimal("zzproportion");
-            if(months.isEmpty()){
-                months=rows.get(0).getJSONArray("statistics_months");
+            for(int i=1;i<=selectmonth;i++){
+                if(rows.get(0).getJSONArray("statistics_months").contains(i)){
+                    months.add(i);
+                }
             }
         }
-        long sa_salestargetbillid=0;
-        if(salestargetbillrows.isNotEmpty()){
-            sa_salestargetbillid=salestargetbillrows.get(0).getLong("sa_salestargetbillid");
-        }
-        SQLFactory personnelsqlFactory = new SQLFactory(this, "人员-目标详情列表");
-        personnelsqlFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
-        personnelsqlFactory.addParameter_SQL("where", " t.sa_saleareaid="+sa_saleareaid);
-        personnelsqlFactory.addParameter("siteid", siteid);
-        Rows salestargetrows = dbConnect.runSqlQuery(personnelsqlFactory.getSQL());
-        BigDecimal rw_all=BigDecimal.ZERO;
-        BigDecimal rw_year=BigDecimal.ZERO;
-        BigDecimal completedamount=BigDecimal.ZERO;
-        BigDecimal gcgccompletedamount=BigDecimal.ZERO;
-        BigDecimal zzgccompletedamount=BigDecimal.ZERO;
-        if(salestargetrows.isNotEmpty()){
-            for(Object month : months){
-                rw_all=rw_all.add(salestargetrows.get(0).getBigDecimal("m"+ (Integer)month+"l"));
+//        long sa_salestargetbillid=0;
+//        if(salestargetbillrows.isNotEmpty()){
+//            sa_salestargetbillid=salestargetbillrows.get(0).getLong("sa_salestargetbillid");
+//        }
+//        SQLFactory personnelsqlFactory = new SQLFactory(this, "人员-目标详情列表");
+//        personnelsqlFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
+//        personnelsqlFactory.addParameter_SQL("where", " 1=1 ");
+//        personnelsqlFactory.addParameter("siteid", siteid);
+//        Rows salestargetrows = dbConnect.runSqlQuery(personnelsqlFactory.getSQL());
+//        RowsMap salestargetrowsMap = salestargetrows.toRowsMap("sa_saleareaid");
+
+
+//        SQLFactory paymentsqlFactory = new SQLFactory(this, "账户回款统计");
+//        paymentsqlFactory.addParameter("year", year);
+//        paymentsqlFactory.addParameter_SQL("where"," 1=1 ");
+//        paymentsqlFactory.addParameter("siteid", siteid);
+//        Rows paymentRows_All = dbConnect.runSqlQuery(paymentsqlFactory.getSQL());
+//        RowsMap paymentRowsMap =paymentRows.toRowsMap("accountname");
+
+//        SQLFactory rebatesqlFactory = new SQLFactory(this, "账户返利统计");
+//        rebatesqlFactory.addParameter("year", year);
+//        rebatesqlFactory.addParameter_SQL("where"," 1=1 ");
+//        rebatesqlFactory.addParameter("siteid", siteid);
+//        Rows rebateRows_All = dbConnect.runSqlQuery(rebatesqlFactory.getSQL());
+//        RowsMap rebateRowsMap =rebateRows.toRowsMap("month");
+        Rows arearowsResult =new Rows();
+        for(Row row :arearows){
+            Row arearowResult =new Row();
+            arearowResult.put("sa_saleareaid",row.getLong("sa_saleareaid"));
+            BigDecimal rw_all=BigDecimal.ZERO;
+            BigDecimal rw_year=BigDecimal.ZERO;
+            BigDecimal completedamount=BigDecimal.ZERO;
+            BigDecimal gcgccompletedamount=BigDecimal.ZERO;
+            BigDecimal zzgccompletedamount=BigDecimal.ZERO;
+            if(salestargetrowsMap.get(row.getString("sa_saleareaid")).isNotEmpty()){
+                for(Object month : months){
+                    rw_all=rw_all.add(salestargetrowsMap.get(row.getString("sa_saleareaid")).get(0).getBigDecimal("m"+ (Integer)month+"l"));
+                }
+                rw_year=salestargetrowsMap.get(row.getString("sa_saleareaid")).get(0).getBigDecimal("y1l");
             }
-            rw_year=salestargetrows.get(0).getBigDecimal("y1l");
-        }
-        ArrayList<Long> list = new ArrayList<>();
-        list.add(sa_saleareaid);
-        list.addAll(getSubSaleAreaIds(this,list));
-        //总任务(万)
-        jsonObject.put("rw_all",rw_year);
-        SQLFactory paymentsqlFactory = new SQLFactory(this, "账户回款统计");
-        paymentsqlFactory.addParameter("year", year);
-        paymentsqlFactory.addParameter_in("sa_saleareaids", list);
-        paymentsqlFactory.addParameter_SQL("where"," 1=1 ");
-        paymentsqlFactory.addParameter("siteid", siteid);
-        Rows paymentRows = dbConnect.runSqlQuery(paymentsqlFactory.getSQL());
-        RowsMap paymentRowsMap =paymentRows.toRowsMap("accountname");
+            ArrayList<Long> list = new ArrayList<>();
+            list.add(row.getLong("sa_saleareaid"));
+            list.addAll(getSubSaleAreaIds(this,list));
 
-        SQLFactory rebatesqlFactory = new SQLFactory(this, "账户返利统计");
-        rebatesqlFactory.addParameter("year", year);
-        rebatesqlFactory.addParameter_in("sa_saleareaids", list);
-        rebatesqlFactory.addParameter_SQL("where"," 1=1 ");
-        rebatesqlFactory.addParameter("siteid", siteid);
-        Rows rebateRows = dbConnect.runSqlQuery(rebatesqlFactory.getSQL());
-        RowsMap rebateRowsMap =rebateRows.toRowsMap("month");
-        for(Object month : months){
-            String monthstr = String.format("%02d", (Integer)month);
-            BigDecimal xainjin=paymentRowsMap.containsKey("现金账户")?paymentRowsMap.get("现金账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("现金账户").toRowsMap("month").get(monthstr).get(0).getBigDecimal("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
-            BigDecimal huodong=paymentRowsMap.containsKey("活动预存账户")?paymentRowsMap.get("活动预存账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("活动预存账户").toRowsMap("month").get(monthstr).get(0).getBigDecimal("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
-            BigDecimal fanli=rebateRowsMap.containsKey(monthstr)?rebateRowsMap.get(monthstr).get(0).getBigDecimal("amount"):BigDecimal.ZERO;
-            BigDecimal gcgc=paymentRowsMap.containsKey("GC工程现金账户")?paymentRowsMap.get("GC工程现金账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("GC工程现金账户").toRowsMap("month").get(monthstr).get(0).getBigDecimal("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
-            BigDecimal zzgc=paymentRowsMap.containsKey("整装工程现金账户")?paymentRowsMap.get("整装工程现金账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("整装工程现金账户").toRowsMap("month").get(monthstr).get(0).getBigDecimal("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
-            gcgccompletedamount=gcgccompletedamount.add(gcgc);
-            zzgccompletedamount=zzgccompletedamount.add(zzgc);
-            completedamount=completedamount.add(xainjin).add(huodong).add(fanli);
-        }
-        //回款完成额
-        jsonObject.put("completedamount",completedamount);
-        //GC工程完成额
-        jsonObject.put("gccompletedamount",gcgccompletedamount.max(rw_all.multiply(gcproportion).multiply(BigDecimal.valueOf(10000))));
-        //整装工程完成额
-        jsonObject.put("zzcompletedamount",zzgccompletedamount.max(rw_all.multiply(zzproportion).multiply(BigDecimal.valueOf(10000))));
-        //总完成额
-        jsonObject.put("actualcompletedamount",jsonObject.getBigDecimal("completedamount").add(jsonObject.getBigDecimal("gccompletedamount")).add(jsonObject.getBigDecimal("zzcompletedamount")));
-        //百分比
-        if(rw_all.compareTo(BigDecimal.ZERO)==0){
-            jsonObject.put("actualcompletedpercentage",0);
-        }else{
-            jsonObject.put("actualcompletedpercentage",jsonObject.getBigDecimal("actualcompletedamount").divide((rw_all.multiply(BigDecimal.valueOf(10000))),4, RoundingMode.HALF_UP));
+            Rows paymentRows =new Rows();
+            Rows rebateRows =new Rows();
+            for(Row paymentRow :paymentRows_All){
+                if(list.contains(paymentRow.getLong("sa_saleareaid"))){
+                    paymentRows.add(paymentRow);
+                }
+            }
+            RowsMap paymentRowsMap =paymentRows.toRowsMap("accountname");
+            for(Row rebateRow :rebateRows_All){
+                if(list.contains(rebateRow.getLong("sa_saleareaid"))){
+                    rebateRows.add(rebateRow);
+                }
+            }
+            RowsMap rebateRowsMap =rebateRows.toRowsMap("month");
+
+            //总任务(万)
+            arearowResult.put("rw_total",rw_year);
+
+            for(Object month : months){
+                String monthstr = String.format("%02d", (Integer)month);
+                BigDecimal xainjin=paymentRowsMap.containsKey("现金账户")?paymentRowsMap.get("现金账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("现金账户").toRowsMap("month").get(monthstr).sum("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
+                BigDecimal huodong=paymentRowsMap.containsKey("活动预存账户")?paymentRowsMap.get("活动预存账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("活动预存账户").toRowsMap("month").get(monthstr).sum("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
+                BigDecimal fanli=rebateRowsMap.containsKey(monthstr)?rebateRowsMap.get(monthstr).sum("amount"):BigDecimal.ZERO;
+                BigDecimal gcgc=paymentRowsMap.containsKey("GC工程现金账户")?paymentRowsMap.get("GC工程现金账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("GC工程现金账户").toRowsMap("month").get(monthstr).sum("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
+                BigDecimal zzgc=paymentRowsMap.containsKey("整装工程现金账户")?paymentRowsMap.get("整装工程现金账户").toRowsMap("month").containsKey(monthstr)?paymentRowsMap.get("整装工程现金账户").toRowsMap("month").get(monthstr).sum("amount"):BigDecimal.ZERO:BigDecimal.ZERO;
+                gcgccompletedamount=gcgccompletedamount.add(gcgc);
+                zzgccompletedamount=zzgccompletedamount.add(zzgc);
+                completedamount=completedamount.add(xainjin).add(huodong).add(fanli);
+            }
+            //回款完成额
+            arearowResult.put("completedamount_total",completedamount);
+            //GC工程完成额
+            arearowResult.put("gccompletedamount_total",gcgccompletedamount.min(rw_all.multiply(gcproportion).multiply(BigDecimal.valueOf(10000))));
+            //整装工程完成额
+            arearowResult.put("zzcompletedamount_total",zzgccompletedamount.min(rw_all.multiply(zzproportion).multiply(BigDecimal.valueOf(10000))));
+            //总完成额
+            arearowResult.put("actualcompletedamount_total",arearowResult.getBigDecimal("completedamount_total").add(arearowResult.getBigDecimal("gccompletedamount_total")).add(arearowResult.getBigDecimal("zzcompletedamount_total")));
+            //百分比
+            if(rw_all.compareTo(BigDecimal.ZERO)==0){
+                arearowResult.put("actualcompletedpercentage_total",0);
+            }else{
+                arearowResult.put("actualcompletedpercentage_total",arearowResult.getBigDecimal("actualcompletedamount_total").divide((rw_all.multiply(BigDecimal.valueOf(10000))),4, RoundingMode.HALF_UP));
+            }
+            //和年度任务的差额
+            BigDecimal differenceamount=rw_all.multiply(BigDecimal.valueOf(7000)).subtract(arearowResult.getBigDecimal("actualcompletedamount_total"));
+            arearowResult.put("differenceamount_total",differenceamount.compareTo(BigDecimal.ZERO)>0?differenceamount:0);
+            arearowsResult.add(arearowResult);
         }
-        //和年度任务的差额
-        BigDecimal differenceamount=rw_all.multiply(BigDecimal.valueOf(7000)).subtract(jsonObject.getBigDecimal("actualcompletedamount"));
-        jsonObject.put("differenceamount",differenceamount.compareTo(BigDecimal.ZERO)>0?differenceamount:0);
 
-        return getSucReturnObject().setData(jsonObject).toString();
+        return arearowsResult;
 
     }
 
@@ -494,6 +623,8 @@ public class performancetargetboard extends Controller {
 
     @API(title = "回款明细", apiversion = R.ID2025103015304303.v1.class)
     public String querypaymentdetail() throws YosException {
+        long month =content.getLong("month");
+        String monthstr = String.format("%02d", month);
         QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_hr","name","hrid");
         querySQL.setTableAlias("t1");
         querySQL.addJoinTable(JOINTYPE.inner, "sa_salearea_hr", "t2", "t1.siteid = t2.siteid and t1.hrid = t2.hrid");
@@ -522,9 +653,10 @@ public class performancetargetboard extends Controller {
                 where.append(" and (t4.areaname3 ='").append(whereObject.getString("areaname3")).append("' or t4.areaname2 ='").append(whereObject.getString("areaname3")).append("' )");
             }
         }
-        SQLFactory sqlFactory = new SQLFactory(this, "回款明细");
+        SQLFactory sqlFactory = new SQLFactory(this, "回款明细_新");
         sqlFactory.addParameter("siteid", siteid);
         sqlFactory.addParameter("year", year);
+        sqlFactory.addParameter("period", monthstr);
         sqlFactory.addParameter_in("sa_saleareaids", list);
         sqlFactory.addParameter_SQL("where", where);
         Rows rows = dbConnect.runSqlQuery(sqlFactory);