Sfoglia il codice sorgente

工时审批计算税额

zhangyao 3 mesi fa
parent
commit
86d7e81c6c

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+com.awspaas.user.apps.donenow_ctt/lib/com.awspaas.user.apps.donenow_ctt.jar
+com.awspaas.user.apps.donenow_ivt/lib/com.awspaas.user.apps.donenow_ivt.jar

BIN
com.awspaas.user.apps.donenow_ctt/lib/com.awspaas.user.apps.donenow_ctt.jar


+ 156 - 16
com.awspaas.user.apps.donenow_ctt/src/com/awspaas/user/apps/donenow_ctt/controller/contractApproveController.java

@@ -255,9 +255,8 @@ public class contractApproveController {
         return ResponseObject.newOkResponse();
     }
 
-
     /**
-     * 工时审批
+     * 批量审批人工
      * @param uc
      * @param approveDate
      * @param approveIds
@@ -272,14 +271,133 @@ public class contractApproveController {
         }
         sql = sql.substring(0, sql.length() - 1) + ")";
         List<RowMap> list = DBSql.getMaps(sql, Arrays.stream(IdArr).toArray());
+        String ORGID = uc.getCompanyModel().getId();
+        LocalDate thisDate = getLocalDate(approveDate);//审批时间
+        for (RowMap thisWorkEntry : list) {
+
+            for (String key : thisWorkEntry.keySet()) {
+                thisWorkEntry.put(key.toUpperCase(), thisWorkEntry.get(key) == null ? "" : thisWorkEntry.get(key));
+            }
+
+            BO oldEntry = SDK.getBOAPI().get("BO_EU_DNSDK_WORK_ENTRY", thisWorkEntry.getString("ID"));
+            String COST_CODE_ID = oldEntry.getString("COST_CODE_ID");//获取成本代码ID
+
+            System.out.println("COST_CODE_ID:" + COST_CODE_ID);
+
+            RowMap thisTaxCate = null;//税收种类
+            if (StringUtils.isNotBlank(COST_CODE_ID)) {
+                RowMap costCode = DBSql.getMap("SELECT * FROM BO_EU_DND_COST_CODE WHERE OID=? AND ORGID=?", new Object[]{COST_CODE_ID, ORGID});
+                if (costCode != null && StringUtils.isNotBlank(costCode.getString("TAX_CATEGORY_ID"))) {
+                    thisTaxCate = DBSql.getMap("SELECT * FROM BO_EU_DND_GENERAL WHERE OID=?  AND ORGID=?", new Object[]{costCode.getString("TAX_CATEGORY_ID"), ORGID});
+                }
+            }
+
+            System.out.println("TAX_CATEGORY_ID:" + thisTaxCate.getString("OID"));
+
+            Double tax_rate = 0.0;
+            RowMap thisTaxRegion = null;
+            RowMap thisAccount = DBSql.getMap("SELECT * FROM BO_EU_DNCRM_ACCOUNT WHERE ID=?", new Object[]{thisWorkEntry.getString("ACCOUNT_ID")});
+            // 获取税收信息
+            if (thisAccount != null && StringUtils.isNotBlank(thisAccount.getString("TAX_REGION_ID"))) {
+                thisTaxRegion = DBSql.getMap("SELECT * FROM BO_EU_DND_GENERAL WHERE OID=? AND ORGID=?", new Object[]{thisAccount.getString("TAX_REGION_ID"), ORGID});
+            }
+
+            System.out.println("TAX_REGION_ID:" + thisTaxRegion.getString("OID"));
+
+            if (thisTaxCate != null && thisTaxRegion != null) {
+
+                RowMap thisTax = DBSql.getMap("SELECT * FROM BO_EU_DND_TAX_REGION_CATE WHERE TAX_REGION_ID=? AND TAX_CATEGORY_ID=? AND ORGID=?", new Object[]{thisTaxRegion.getString("OID"), thisTaxCate.getString("OID"), ORGID});
+                if (thisTax != null) {
+                    tax_rate = thisTax.getDouble("TOTAL_EFFECTIVE_TAX_RATE");
+                }
+            }
+
+
+            Double block_hour_multiplier = 0.0;
+
+            RowMap thisConRole = DBSql.getMap("SELECT * FROM BO_EU_DNCTT_CONTRACT_RATE WHERE CONTRACT_ID=? AND ROLE_ID=?", new Object[]{thisWorkEntry.getString("CONTRACT_ID"), thisWorkEntry.getString("ROLE_ID")});
+
+            if (thisConRole != null) {
+                block_hour_multiplier = thisConRole.getDouble("BLOCK_HOUR_MULTIPLIER");//乘数
+            } else {
+                RowMap thisRole = DBSql.getMap("SELECT * FROM BO_EU_DNSYS_ROLE WHERE ID=?", new Object[]{thisWorkEntry.getString("ROLE_ID")});
+                if (thisRole != null) {
+                    block_hour_multiplier = thisRole.getDouble("HOURLY_FACTOR");//角色时间系数
+                }
+            }
+
+
+            BO thisDed = new BO();
+            thisDed.set("TYPE_ID", "1318");
+            thisDed.set("OBJECT_ID", thisWorkEntry.getString("ID"));
+            thisDed.set("POSTED_DATE", thisDate);
+            thisDed.set("TASK_ID", thisWorkEntry.getString("TASK_ID"));
+            thisDed.set("EXTENDED_PRICE", thisWorkEntry.getDouble("DOLLARS"));
+
+            thisDed.set("ACCOUNT_ID", thisWorkEntry.getString("ACCOUNT_ID"));
+            thisDed.set("CONTRACT_ID", thisWorkEntry.getString("CONTRACT_ID"));
+            thisDed.set("PURCHASE_ORDER_NO", thisWorkEntry.getString("PURCHASE_ORDER_NO"));
+            thisDed.set("BILL_ACCOUNT_ID", thisWorkEntry.getString("BILL_ACCOUNT_ID"));
+
+            thisDed.set("TAX_CATEGORY_NAME", thisTaxCate == null ? null : thisTaxCate.getString("NAME"));
+            thisDed.set("TAX_REGION_NAME", thisTaxRegion == null ? null : thisTaxRegion.getString("NAME"));
+
+            thisDed.set("EFFECTIVE_TAX_RATE", tax_rate);
+
+            thisDed.set("ROLE_ID", thisWorkEntry.getString("ROLE_ID"));
+            thisDed.set("QUANTITY", thisWorkEntry.get("QUANTITY"));
+            thisDed.set("RATE", thisWorkEntry.get("RATE"));
+            thisDed.set("BLOCK_HOUR_MULTIPLIER", block_hour_multiplier);
+            thisDed.set("EXTENDED_COST", thisWorkEntry.get("COST"));
+            if (thisTaxCate != null)
+                thisDed.set("TAX_CATEGORY_ID", thisTaxCate.getString("OID"));
+
 
+            thisDed.set("TAX_DOLLARS", thisWorkEntry.getDouble("DOLLARS") * (1 - 1 / (1 + tax_rate)));
+
+            if (StringUtils.isBlank(thisDed.getString("BILL_ACCOUNT_ID")) && StringUtils.isNotBlank(thisDed.getString("ACCOUNT_ID")))
+                thisDed.set("BILL_ACCOUNT_ID", thisDed.get("ACCOUNT_ID"));
+
+            dn.recordFormChanges.record(uc, thisDed, "审批提交工时");
+            SDK.getBOAPI().createDataBO("BO_EU_DNCRM_ACCOUNT_DEDUCTION", thisDed, uc);
+
+
+            oldEntry.set("APPROVE_AND_POST_DATE", thisDate);
+            oldEntry.set("APPROVE_AND_POST_USER_ID", uc.getUID());
+            dn.recordFormChanges.record(uc, oldEntry, "审批提交工时");
+            SDK.getBOAPI().update("BO_EU_DNSDK_WORK_ENTRY", oldEntry);
+
+
+        }
+
+
+        return ResponseObject.newOkResponse();
+    }
+
+    /**
+     * 工时审批
+     * @param uc
+     * @param approveDate
+     * @param approveIds
+     * @return
+     */
+    @Mapping("com.awspaas.user.apps.donenow_ctt.approve_labor2")
+    public ResponseObject laborApprove2(UserContext uc, String approveDate, String approveIds) {
+        String[] IdArr = approveIds.split(",");
+        String sql = "SELECT * FROM VIEW_EU_DNV_PENDING_LABOR WHERE ID IN(";
+        for (int i = 0; IdArr.length > i; i++) {
+            sql += "?,";
+        }
+        sql = sql.substring(0, sql.length() - 1) + ")";
+        List<RowMap> list = DBSql.getMaps(sql, Arrays.stream(IdArr).toArray());
+        String ORGID = uc.getCompanyModel().getId();
         for (RowMap rowMap : list) {
             String COST_CODE_ID = getString(rowMap, "COST_CODE_ID");//获取成本代码ID
             RowMap thisTaxCate = null;//税收种类
             if (StringUtils.isNotBlank(COST_CODE_ID)) {
-                RowMap costCode = DBSql.getMap("SELECT * FROM BO_EU_DND_COST_CODE WHERE ID=?", new Object[]{COST_CODE_ID});
+                RowMap costCode = DBSql.getMap("SELECT * FROM BO_EU_DND_COST_CODE WHERE OID=? AND ORGID=?", new Object[]{COST_CODE_ID, ORGID});
                 if (costCode != null && StringUtils.isNotBlank(costCode.getString("TAX_CATEGORY_ID"))) {
-                    thisTaxCate = DBSql.getMap("SELECT * FROM BO_EU_DND_GENERAL WHERE OID=?", new Object[]{costCode.getString("TAX_CATEGORY_ID")});
+                    thisTaxCate = DBSql.getMap("SELECT * FROM BO_EU_DND_GENERAL WHERE OID=?  AND ORGID=?", new Object[]{costCode.getString("TAX_CATEGORY_ID"), ORGID});
                 }
             }
 
@@ -295,36 +413,28 @@ public class contractApproveController {
                     thisAccount = thatAccount;
             }
 
-            RowMap thisProject = null;
 
             RowMap thisTaxRegion = null;
             Double tax_rate = 0.0;//税率
-
             String TASK_ID = rowMap.getString("TASK_ID");
             if (StringUtils.isNotBlank(TASK_ID)) {
-
-                thisProject = DBSql.getMap("SELECT * FROM BO_EU_DNPRO_PROJECT WHERE ID IN (SELECT PROJECT_ID FROM BO_EU_DNSDK_TASK WHERE ID=?)", new Object[]{TASK_ID});
-
                 RowMap thatAccount = DBSql.getMap("SELECT * FROM BO_EU_DNCRM_ACCOUNT WHERE ID IN (SELECT ACCOUNT_ID FROM BO_EU_DNSDK_TASK WHERE ID=?)", new Object[]{TASK_ID});
                 if (thatAccount != null)
                     thisAccount = thatAccount;
             }
 
-            //该员工的费率
-            // decimal? laborRate = sweDal.FindSignleBySql<decimal?>($"SELECT f_get_labor_rate({thisContractId},{oldEntry.cost_code_id},{oldEntry.role_id});");
-
             String thisContractId = thisContract == null ? "null" : thisContract.getString("ID");
             String ROLE_ID = rowMap.getString("ROLE_ID");
 
             Double laborRate = 0.0;
             //该员工的费率
             try {
-                laborRate = DBSql.getDouble("SELECT f_get_labor_rate(" + thisContractId + "," + COST_CODE_ID + "," + ROLE_ID + "," + uc.getCompanyModel().getId() + ") as laborRate", "laborRate");
+                laborRate = DBSql.getDouble("SELECT f_get_labor_rate(" + thisContractId + "," + COST_CODE_ID + "," + ROLE_ID + "," + ORGID + ") as laborRate", "laborRate");
             } catch (Exception e) {
                 System.out.println("获取费率异常" + e.getMessage());
             }
 
-            String ORGID = uc.getCompanyModel().getId();
+
             // 获取税收信息
             if (thisAccount != null && StringUtils.isNotBlank(thisAccount.getString("TAX_REGION_ID"))) {
                 thisTaxRegion = DBSql.getMap("SELECT * FROM BO_EU_DND_GENERAL WHERE OID=? AND ORGID=?", new Object[]{thisAccount.getString("TAX_REGION_ID"), ORGID});
@@ -400,6 +510,10 @@ public class contractApproveController {
                     thisBlockDed.set("EXTENDED_PRICE", 0);
                     thisBlockDed.set("BILL_ACCOUNT_ID", thisWorkEntry.get("BILL_ACCOUNT_ID"));
 
+
+                    if (StringUtils.isBlank(thisBlockDed.getString("BILL_ACCOUNT_ID")) && StringUtils.isNotBlank(thisBlockDed.getString("ACCOUNT_ID")))
+                        thisBlockDed.set("BILL_ACCOUNT_ID", thisBlockDed.get("ACCOUNT_ID"));
+
                     dn.recordFormChanges.record(uc, thisBlockDed, "审批提交工时");
                     SDK.getBOAPI().createDataBO("BO_EU_DNCRM_ACCOUNT_DEDUCTION", thisBlockDed, uc);
                 } else if (thisContract != null && thisContract.getString("TYPE_ID").equals("1203")) {
@@ -455,6 +569,11 @@ public class contractApproveController {
                                     }
                                     if (thisWorkEntry.getString("IS_BILLABLE").equals("0"))
                                         thisBlockDed.set("EXTENDED_PRICE", 0);
+
+
+                                    if (StringUtils.isBlank(thisBlockDed.getString("BILL_ACCOUNT_ID")) && StringUtils.isNotBlank(thisBlockDed.getString("ACCOUNT_ID")))
+                                        thisBlockDed.set("BILL_ACCOUNT_ID", thisBlockDed.get("ACCOUNT_ID"));
+
                                     dn.recordFormChanges.record(uc, thisBlockDed, "审批提交工时");
                                     SDK.getBOAPI().createDataBO("BO_EU_DNCRM_ACCOUNT_DEDUCTION", thisBlockDed, uc);
 
@@ -496,6 +615,11 @@ public class contractApproveController {
                                     thisBlockDed.set("extended_price", block.get(key) - (extend - totalMoney));
                                     if (thisWorkEntry.getString("IS_BILLABLE").equals("0"))
                                         thisBlockDed.set("EXTENDED_PRICE", 0);
+
+
+                                    if (StringUtils.isBlank(thisBlockDed.getString("BILL_ACCOUNT_ID")) && StringUtils.isNotBlank(thisBlockDed.getString("ACCOUNT_ID")))
+                                        thisBlockDed.set("BILL_ACCOUNT_ID", thisBlockDed.get("ACCOUNT_ID"));
+
                                     dn.recordFormChanges.record(uc, thisBlockDed, "审批提交工时");
                                     SDK.getBOAPI().createDataBO("BO_EU_DNCRM_ACCOUNT_DEDUCTION", thisBlockDed, uc);
                                     break;
@@ -524,6 +648,11 @@ public class contractApproveController {
                                 thisBlockDed.set("TAX_CATEGORY_ID", thisTaxCate.getString("ID"));
                             if (thisWorkEntry.getString("IS_BILLABLE").equals("0"))
                                 thisBlockDed.set("EXTENDED_PRICE", 0);
+
+
+                            if (StringUtils.isBlank(thisBlockDed.getString("BILL_ACCOUNT_ID")) && StringUtils.isNotBlank(thisBlockDed.getString("ACCOUNT_ID")))
+                                thisBlockDed.set("BILL_ACCOUNT_ID", thisBlockDed.get("ACCOUNT_ID"));
+
                             dn.recordFormChanges.record(uc, thisBlockDed, "审批提交工时");
                             SDK.getBOAPI().createDataBO("BO_EU_DNCRM_ACCOUNT_DEDUCTION", thisBlockDed, uc);
                         }
@@ -561,6 +690,9 @@ public class contractApproveController {
                                 if (thisAccount.getString("IS_TAX_EXEMPT").equals("1") == false)
                                     thisBlockDed.set("TAX_DOLLARS", thisWorkEntry.getDouble("HOURS_BILLED") * laborRate * (1 - 1 / (1 + tax_rate)));
 
+                                if (StringUtils.isBlank(thisBlockDed.getString("BILL_ACCOUNT_ID")) && StringUtils.isNotBlank(thisBlockDed.getString("ACCOUNT_ID")))
+                                    thisBlockDed.set("BILL_ACCOUNT_ID", thisBlockDed.get("ACCOUNT_ID"));
+
                                 dn.recordFormChanges.record(uc, thisBlockDed, "审批提交工时");
                                 SDK.getBOAPI().createDataBO("BO_EU_DNCRM_ACCOUNT_DEDUCTION", thisBlockDed, uc);
 
@@ -589,7 +721,7 @@ public class contractApproveController {
                             thisDed.set("EXTENDED_PRICE", thisWorkEntry.getDouble("HOURS_BILLED") * laborRate * block_hour_multiplier);
                             thisDed.set("ACCOUNT_ID", thisAccount.getString("ID"));
                             thisDed.set("CONTRACT_ID", thisWorkEntry.getString("CONTRACT_ID"));
-                            thisDed.set("QUANTITY", thisWorkEntry.getDouble("HOURS_BILLED"));
+                            //thisDed.set("QUANTITY", thisWorkEntry.getDouble("HOURS_BILLED"));
                             thisDed.set("PURCHASE_ORDER_NO", thisWorkEntry.getString("PURCHASE_ORDER_NO"));
                             thisDed.set("BILL_ACCOUNT_ID", thisWorkEntry.getString("BILL_ACCOUNT_ID"));
                             thisDed.set("TAX_CATEGORY_NAME", thisTaxCate == null ? null : thisTaxCate.getString("NAME"));
@@ -609,6 +741,9 @@ public class contractApproveController {
                             if (thisAccount.getString("IS_TAX_EXEMPT").equals("1") == false)
                                 thisDed.set("TAX_DOLLARS", thisWorkEntry.getDouble("HOURS_BILLED") * laborRate * (1 - 1 / (1 + tax_rate)));
 
+                            if (StringUtils.isBlank(thisDed.getString("BILL_ACCOUNT_ID")) && StringUtils.isNotBlank(thisDed.getString("ACCOUNT_ID")))
+                                thisDed.set("BILL_ACCOUNT_ID", thisDed.get("ACCOUNT_ID"));
+
                             dn.recordFormChanges.record(uc, thisDed, "审批提交工时");
                             SDK.getBOAPI().createDataBO("BO_EU_DNCRM_ACCOUNT_DEDUCTION", thisDed, uc);
                         }
@@ -625,7 +760,7 @@ public class contractApproveController {
                 thisDed.set("EXTENDED_PRICE", thisWorkEntry.getDouble("HOURS_BILLED") * laborRate * block_hour_multiplier);
                 thisDed.set("ACCOUNT_ID", thisAccount == null ? null : thisAccount.getString("ID"));
                 thisDed.set("CONTRACT_ID", thisWorkEntry.getString("CONTRACT_ID"));
-                thisDed.set("QUANTITY", thisWorkEntry.getDouble("HOURS_BILLED"));
+                //thisDed.set("QUANTITY", thisWorkEntry.getDouble("HOURS_BILLED"));
                 thisDed.set("PURCHASE_ORDER_NO", thisWorkEntry.getString("PURCHASE_ORDER_NO"));
                 thisDed.set("BILL_ACCOUNT_ID", thisWorkEntry.getString("BILL_ACCOUNT_ID"));
                 thisDed.set("TAX_CATEGORY_NAME", thisTaxCate == null ? null : thisTaxCate.getString("NAME"));
@@ -645,6 +780,9 @@ public class contractApproveController {
                 if (thisAccount.getString("IS_TAX_EXEMPT").equals("1") == false)
                     thisDed.set("TAX_DOLLARS", thisWorkEntry.getDouble("HOURS_BILLED") * laborRate * (1 - 1 / (1 + tax_rate)));
 
+                if (StringUtils.isBlank(thisDed.getString("BILL_ACCOUNT_ID")) && StringUtils.isNotBlank(thisDed.getString("ACCOUNT_ID")))
+                    thisDed.set("BILL_ACCOUNT_ID", thisDed.get("ACCOUNT_ID"));
+
                 dn.recordFormChanges.record(uc, thisDed, "审批提交工时");
                 SDK.getBOAPI().createDataBO("BO_EU_DNCRM_ACCOUNT_DEDUCTION", thisDed, uc);
             }
@@ -774,6 +912,8 @@ public class contractApproveController {
             if (thisTaxCate != null)
                 thisDed.set("TAX_CATEGORY_ID", thisTaxCate.getString("OID"));
 
+            if (StringUtils.isBlank(thisDed.getString("BILL_ACCOUNT_ID")) && StringUtils.isNotBlank(thisDed.getString("ACCOUNT_ID")))
+                thisDed.set("BILL_ACCOUNT_ID", thisDed.get("ACCOUNT_ID"));
 
             dn.recordFormChanges.record(uc, thisDed, "审批提交费用");
             SDK.getBOAPI().createDataBO("BO_EU_DNCRM_ACCOUNT_DEDUCTION", thisDed, uc);

+ 14 - 4
com.awspaas.user.apps.donenow_ctt/src/com/awspaas/user/apps/donenow_ctt/service/InvoiceService.java

@@ -54,11 +54,21 @@ public class InvoiceService {
 
         // 2. 初始化基础数据(3张核心表查询)
         List<RowMap> postedDataList = DBSql.getMaps(
-                "SELECT * FROM VIEW_EU_DNV_POSTED_ALL WHERE ID IN " + sqlWhere + " ORDER BY ACCOUNT_ID,BILL_ACCOUNT_ID",
+                "SELECT * FROM VIEW_EU_DNV_POSTED_ALL d WHERE d.ID IN " + sqlWhere + " AND (d.invoice_id is null OR d.invoice_id='' OR NOT EXISTS(SELECT 1 FROM bo_eu_dnctt_invoice i WHERE i.id=d.invoice_id AND IS_VOIDED=0))  AND  d.bill_account_id is NOT NULL AND d.ORGID='" + uc.getCompanyModel().getId() + "' ORDER BY ACCOUNT_ID,BILL_ACCOUNT_ID",
                 dedIdArr
         );
         // 统一Key为大写,避免字段名大小写不一致导致的NPE
-        postedDataList.forEach(row -> row.forEach((key, value) -> row.put(key.toUpperCase(), value)));
+        postedDataList.forEach(row -> row.forEach((key, value) -> {
+            if (key.toUpperCase().equals("BILL_ACCOUNT_ID")) {
+                if (value == null || StringUtils.isBlank(value.toString())) {
+                    row.put(key.toUpperCase(), row.get("ACCOUNT_ID"));
+                } else {
+                    row.put(key.toUpperCase(), value);
+                }
+            } else {
+                row.put(key.toUpperCase(), value);
+            }
+        }));
 
         List<RowMap> accountDedList = DBSql.getMaps(
                 "SELECT * FROM BO_EU_DNCRM_ACCOUNT_DEDUCTION WHERE ID IN " + sqlWhere + " ORDER BY ACCOUNT_ID,BILL_ACCOUNT_ID",
@@ -207,7 +217,7 @@ public class InvoiceService {
                 detail.setBindId(invoice.getBindId());
                 detail.set("INVOICE_ID", invoice.getId());
                 detail.set("ITEM_DATE", posted.get("ITEM_DATE"));
-                detail.set("ITEM_DESC", posted.get("ITEM_DESC"));
+                detail.set("ITEM_DESC", StringUtils.isBlank(posted.getString("ITEM_DESC")) ? posted.get("ITEM_NAME") : posted.get("ITEM_DESC"));
                 detail.set("RESOURCE_NAME", posted.get("RESOURCE_NAME"));
                 detail.set("QUANTITY", posted.get("QUANTITY"));
                 detail.set("RATE", posted.get("RATE"));
@@ -215,7 +225,7 @@ public class InvoiceService {
                 detail.set("HOURLY_RATE", posted.get("HOURLY_RATE"));
                 detail.set("ROLE_NAME", posted.get("ROLE_NAME"));
                 detail.set("WORK_TYPE", posted.get("WORK_TYPE"));
-                detail.set("TAX_INCLUSIVE", posted.get("DOLLARS"));
+                detail.set("TAX_DOLLARS", posted.get("TAX_DOLLARS"));
 
                 detail.set("BILL_ACCOUNT_ID", ded.getString("BILL_ACCOUNT_ID"));//计费客户
                 detail.set("ACCOUNT_ID", ded.getString("ACCOUNT_ID"));//客户

BIN
com.awspaas.user.apps.donenow_ivt/lib/com.awspaas.user.apps.donenow_ivt.jar