|
|
@@ -14,10 +14,17 @@ import com.awspaas.user.apps.donenow_ctt.service.contractService;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
import java.sql.SQLException;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
+import static com.awspaas.user.apps.donenow_ctt.service.contractService.GetEntryCost;
|
|
|
+import static com.awspaas.user.apps.donenow_ctt.service.contractService.getLocalDate;
|
|
|
+
|
|
|
@Controller
|
|
|
public class contractApproveController {
|
|
|
private static final Logger contractLogger = SDK.getLogAPI().getLogger(contractApproveController.class);//记录日志
|
|
|
@@ -247,4 +254,533 @@ public class contractApproveController {
|
|
|
return ResponseObject.newOkResponse();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 工时审批
|
|
|
+ * @param uc
|
|
|
+ * @param approveDate
|
|
|
+ * @param approveIds
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Mapping("com.awspaas.user.apps.donenow_ctt.approve_labor")
|
|
|
+ public ResponseObject laborApprove(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());
|
|
|
+
|
|
|
+ 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});
|
|
|
+ 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")});
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ RowMap thisContract = null;//合同
|
|
|
+ RowMap thisAccount = null;
|
|
|
+ String CONTRRACT_ID = getString(rowMap, "CONTRACT_ID");
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(CONTRRACT_ID)) {
|
|
|
+ thisContract = DBSql.getMap("SELECT * FROM BO_EU_DNCTT_CONTRACT WHERE ID=?", new Object[]{CONTRRACT_ID});
|
|
|
+
|
|
|
+ RowMap thatAccount = DBSql.getMap("SELECT * FROM BO_EU_DNCRM_ACCOUNT WHERE ID IN (SELECT ACCOUNT_ID FROM BO_EU_DNCTT_CONTRACT WHERE ID=?)", new Object[]{CONTRRACT_ID});
|
|
|
+ if (thatAccount != null)
|
|
|
+ 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");
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("获取费率异常" + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取税收信息
|
|
|
+ if (thisAccount != null && StringUtils.isNotBlank(thisAccount.getString("TAX_REGION_ID"))) {
|
|
|
+ thisTaxRegion = DBSql.getMap("SELECT * FROM BO_EU_DND_GENERAL WHERE OID=?", new Object[]{thisAccount.getString("TAX_REGION_ID")});
|
|
|
+ }
|
|
|
+ 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=?", new Object[]{thisTaxRegion.getString("ID"), thisTaxCate.getString("ID")});
|
|
|
+ if (thisTax != null) {
|
|
|
+ tax_rate = thisTax.getDouble("TOTAL_EFFECTIVE_TAX_RATE");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ LocalDate thisDate = getLocalDate(approveDate);//审批时间
|
|
|
+ Double block_hour_multiplier = 0.0;
|
|
|
+ if (thisContract != null && StringUtils.isNotBlank(ROLE_ID)) {
|
|
|
+ //var thisConRole = new ctt_contract_rate_dal(_connect).GetSinRate(thisContract.id, (long)oldEntry.role_id);
|
|
|
+ //return FindSignleBySql<ctt_contract_rate>($"SELECT * from ctt_contract_rate where delete_time = 0 and contract_id = {contract_id} and //role_id ={role_id}");
|
|
|
+ RowMap thisConRole = DBSql.getMap("SELECT * FROM BO_EU_DNCTT_CONTRACT_RATE WHERE CONTRACT_ID=? AND ROLE_ID=?", new Object[]{thisContract.getString("ID"), 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[]{ROLE_ID});
|
|
|
+ if (thisRole != null) {
|
|
|
+ block_hour_multiplier = thisRole.getDouble("HOURLY_FACTOR");//角色时间系数
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Double> block = new HashMap<>();//存储预付id,和总价
|
|
|
+ Map<String, Double> blockRate = new HashMap<>();//存储预付id,和总价
|
|
|
+
|
|
|
+ RowMap thisWorkEntry = DBSql.getMap("select * from BO_EU_DNSDK_WORK_ENTRY where ID=?", new Object[]{getString(rowMap, "ID")});
|
|
|
+ LocalDate thisEntryDate = getLocalDate(getString(thisWorkEntry, "START_TIME"));
|
|
|
+ LocalDate thisEntryEndDate = StringUtils.isBlank(getString(thisWorkEntry, "START_TIME")) ? thisEntryDate : getLocalDate(getString(thisWorkEntry, "END_TIME"));
|
|
|
+
|
|
|
+ LocalDate thisContractStartDate = thisContract == null ? null : thisContract.getDate("START_DATE").toInstant()
|
|
|
+ .atZone(ZoneId.systemDefault())
|
|
|
+ .toLocalDate();
|
|
|
+ LocalDate thisContractEndDate = thisContract == null ? null : thisContract.getDate("END_DATE").toInstant()
|
|
|
+ .atZone(ZoneId.systemDefault())
|
|
|
+ .toLocalDate();
|
|
|
+
|
|
|
+ Double totalHours = StringUtils.isBlank(thisWorkEntry.getString("HOURS_BILLED_DEDUCTION")) ? thisWorkEntry.getDouble("HOURS_BILLED") : thisWorkEntry.getDouble("HOURS_BILLED_DEDUCTION");
|
|
|
+ if (thisContract != null && thisEntryDate != null && thisContractStartDate.compareTo(thisEntryDate) <= 0 && thisContractEndDate.compareTo(thisEntryEndDate) >= 0) {
|
|
|
+
|
|
|
+ String endDate = thisEntryDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+
|
|
|
+ // 这个工时的总额
|
|
|
+ Double totalMoney = StringUtils.isBlank(thisWorkEntry.getString("HOURS_BILLED_DEDUCTION")) ? thisWorkEntry.getDouble("HOURS_BILLED") : thisWorkEntry.getDouble("HOURS_BILLED_DEDUCTION");
|
|
|
+ totalMoney = totalMoney * (StringUtils.isBlank(thisWorkEntry.getString("HOURS_RATE_DEDUCTION")) ? laborRate : thisWorkEntry.getDouble("HOURS_RATE_DEDUCTION"));
|
|
|
+
|
|
|
+ //不计费的工时
|
|
|
+ if (laborRate == null || laborRate <= 0) {
|
|
|
+ BO thisBlockDed = new BO();
|
|
|
+ thisBlockDed.set("TYPE_ID", "1318");//工时
|
|
|
+ thisBlockDed.set("OBJECT_ID", thisWorkEntry.getString("ID"));
|
|
|
+ thisBlockDed.set("POSTED_DATE", thisDate);
|
|
|
+ thisBlockDed.set("TASK_ID", thisWorkEntry.getString("TASK_ID"));
|
|
|
+ thisBlockDed.set("ACCOUNT_ID", thisAccount.getString("ID"));
|
|
|
+ thisBlockDed.set("QUANTITY", totalHours);
|
|
|
+ thisBlockDed.set("BILL_CREATE_USER_ID", thisWorkEntry.getString("CREATEUSER"));
|
|
|
+ thisBlockDed.set("PURCHASE_ORDER_NO", thisWorkEntry.getString("PURCHASE_ORDER_NO"));
|
|
|
+ thisBlockDed.set("TAX_CATEGORY_NAME", thisTaxCate == null ? null : thisTaxCate.getString("NAME"));
|
|
|
+ thisBlockDed.set("TAX_REGION_NAME", thisTaxRegion == null ? null : thisTaxRegion.getString("NAME"));
|
|
|
+ thisBlockDed.set("EFFECTIVE_TAX_RATE", tax_rate);
|
|
|
+ thisBlockDed.set("ROLE_ID", thisWorkEntry.getString("ROLE_ID"));
|
|
|
+ thisBlockDed.set("EXTENDED_COST", GetEntryCost(thisWorkEntry.getString("ID")));
|
|
|
+ thisBlockDed.set("CONTRACT_ID", thisWorkEntry.getString("CONTRACT_ID"));
|
|
|
+ if (thisTaxCate != null)
|
|
|
+ thisBlockDed.set("TAX_CATEGORY_ID", thisTaxCate.getString("ID"));
|
|
|
+
|
|
|
+ thisBlockDed.set("EXTENDED_PRICE", 0);
|
|
|
+ thisBlockDed.set("BILL_ACCOUNT_ID", thisWorkEntry.get("BILL_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")) {
|
|
|
+ //预付费合同
|
|
|
+
|
|
|
+ //获取工时
|
|
|
+ Double extended_price = DBSql.getDouble("SELECT sum(round(b.rate/" + laborRate + " - ifnull((SELECT sum(extended_price)FROM bo_eu_dncrm_account_deduction WHERE contract_block_id = b.id ),0),2)) AS RATE FROM bo_eu_dnctt_contract_block b WHERE b.contract_id='" + thisContract.getString("ID") + "' and b.status_id=1 and b.start_date <='" + thisEntryDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + "' and b.end_date >='" + endDate + "'", "RATE");
|
|
|
+ extended_price = extended_price * laborRate;
|
|
|
+
|
|
|
+ // Double thisEntryRate = GetRateByCodeAndRole(COST_CODE_ID, ROLE_ID);
|
|
|
+
|
|
|
+ List<RowMap> block_hours = DBSql.getMaps("SELECT b.ID,(round(b.rate/" + laborRate + " - ifnull((SELECT sum(extended_price)FROM bo_eu_dncrm_account_deduction WHERE contract_block_id = b.id ),0),2)) AS RATE FROM bo_eu_dnctt_contract_block b WHERE b.contract_id='" + thisContract.getString("ID") + "' and b.status_id=1 and b.start_date <='" + thisEntryDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + "' and b.end_date >='" + endDate + "'");
|
|
|
+
|
|
|
+ for (RowMap block_hour : block_hours) {
|
|
|
+ if (block_hour.get("RATE") != null && block_hour.getDouble("RATE") > 0) {
|
|
|
+ block.put(block_hour.getString("ID"), block_hour.getDouble("RATE"));
|
|
|
+ }
|
|
|
+ blockRate.put(block_hour.getString("ID"), block_hour.getDouble("RATE"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (totalMoney == null || totalMoney <= extended_price) {
|
|
|
+ if (totalMoney != null) {
|
|
|
+ Double extend = 0.0;
|
|
|
+ for (String key : block.keySet()) {
|
|
|
+ extend += block.get(key);
|
|
|
+ if (extend <= totalMoney) {
|
|
|
+ BO thisBlockDed = new BO();
|
|
|
+ thisBlockDed.set("TYPE_ID", "1318");
|
|
|
+ thisBlockDed.set("OBJECT_ID", thisWorkEntry.getString("ID"));
|
|
|
+ thisBlockDed.set("POSTED_DATE", thisDate);
|
|
|
+ thisBlockDed.set("TASK_ID", thisWorkEntry.getString("TASK_ID"));
|
|
|
+ thisBlockDed.set("EXTENDED_PRICE", block.get(key));
|
|
|
+ thisBlockDed.set("ACCOUNT_ID", thisWorkEntry.getString("ACCOUNT_ID"));
|
|
|
+ thisBlockDed.set("CONTRACT_ID", thisWorkEntry.getString("CONTRACT_ID"));
|
|
|
+ thisBlockDed.set("BILL_CREATE_USER_ID", thisWorkEntry.getString("CREATEUSER"));
|
|
|
+ thisBlockDed.set("PURCHASE_ORDER_NO", thisWorkEntry.getString("PURCHASE_ORDER_NO"));
|
|
|
+ thisBlockDed.set("TAX_CATEGORY_NAME", thisTaxCate == null ? null : thisTaxCate.getString("NAME"));
|
|
|
+ thisBlockDed.set("TAX_REGION_NAME", thisTaxRegion == null ? null : thisTaxRegion.getString("NAME"));
|
|
|
+ thisBlockDed.set("EFFECTIVE_TAX_RATE", tax_rate);
|
|
|
+ thisBlockDed.set("ROLE_ID", thisWorkEntry.getString("ROLE_ID"));
|
|
|
+ thisBlockDed.set("QUANTITY", totalHours);
|
|
|
+ thisBlockDed.set("RATE", blockRate.get(key));
|
|
|
+ thisBlockDed.set("CONTRACT_BLOCK_ID", key);
|
|
|
+ thisBlockDed.set("BLOCK_HOUR_MULTIPLIER", block_hour_multiplier);
|
|
|
+ thisBlockDed.set("EXTENDED_COST", GetEntryCost(thisWorkEntry.getString("ID")));
|
|
|
+
|
|
|
+ if (thisTaxCate != null)
|
|
|
+ thisBlockDed.set("TAX_CATEGORY_ID", thisTaxCate.getString("ID"));
|
|
|
+
|
|
|
+
|
|
|
+ if (thisAccount.getString("IS_TAX_EXEMPT").equals("1") == false) {
|
|
|
+ thisBlockDed.set("TAX_DOLLARS", thisWorkEntry.getDouble("HOURS_BILLED") * laborRate * (1 - 1 / (1 + tax_rate)));
|
|
|
+ }
|
|
|
+ if (thisWorkEntry.getString("IS_BILLABLE").equals("0"))
|
|
|
+ thisBlockDed.set("EXTENDED_PRICE", 0);
|
|
|
+ dn.recordFormChanges.record(uc, thisBlockDed, "审批提交工时");
|
|
|
+ SDK.getBOAPI().createDataBO("BO_EU_DNCRM_ACCOUNT_DEDUCTION", thisBlockDed, uc);
|
|
|
+
|
|
|
+ //修改相应的预付费信息
|
|
|
+ BO thisBlock = SDK.getBOAPI().get("BO_EU_DNCTT_CONTRACT_BLOCK", key);
|
|
|
+ if (thisBlock != null) {
|
|
|
+ thisBlock.set("STATUS_ID", 0);
|
|
|
+ dn.recordFormChanges.record(uc, thisBlock, "修改预付费信息");
|
|
|
+ SDK.getBOAPI().update("BO_EU_DNCTT_CONTRACT_BLOCK", thisBlock);
|
|
|
+ }
|
|
|
+ if (extend == totalMoney) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ } else {
|
|
|
+ BO thisBlockDed = new BO();
|
|
|
+ thisBlockDed.set("TYPE_ID", "1318");
|
|
|
+ thisBlockDed.set("OBJECT_ID", thisWorkEntry.getString("ID"));
|
|
|
+ thisBlockDed.set("POSTED_DATE", thisDate);
|
|
|
+ thisBlockDed.set("TASK_ID", thisWorkEntry.getString("TASK_ID"));
|
|
|
+ thisBlockDed.set("EXTENDED_PRICE", block.get(key));
|
|
|
+ thisBlockDed.set("ACCOUNT_ID", thisWorkEntry.getString("ACCOUNT_ID"));
|
|
|
+ thisBlockDed.set("CONTRACT_ID", thisWorkEntry.getString("CONTRACT_ID"));
|
|
|
+ thisBlockDed.set("BILL_CREATE_USER_ID", thisWorkEntry.getString("CREATEUSER"));
|
|
|
+ thisBlockDed.set("PURCHASE_ORDER_NO", thisWorkEntry.getString("PURCHASE_ORDER_NO"));
|
|
|
+ thisBlockDed.set("TAX_CATEGORY_NAME", thisTaxCate == null ? null : thisTaxCate.getString("NAME"));
|
|
|
+ thisBlockDed.set("TAX_REGION_NAME", thisTaxRegion == null ? null : thisTaxRegion.getString("NAME"));
|
|
|
+ thisBlockDed.set("EFFECTIVE_TAX_RATE", tax_rate);
|
|
|
+ thisBlockDed.set("ROLE_ID", thisWorkEntry.getString("ROLE_ID"));
|
|
|
+ thisBlockDed.set("QUANTITY", totalHours);
|
|
|
+ thisBlockDed.set("RATE", blockRate.get(key));
|
|
|
+ thisBlockDed.set("CONTRACT_BLOCK_ID", key);
|
|
|
+ thisBlockDed.set("BLOCK_HOUR_MULTIPLIER", block_hour_multiplier);
|
|
|
+ thisBlockDed.set("EXTENDED_COST", GetEntryCost(thisWorkEntry.getString("ID")));
|
|
|
+ if (thisTaxCate != null)
|
|
|
+ thisBlockDed.set("TAX_CATEGORY_ID", thisTaxCate.getString("ID"));
|
|
|
+
|
|
|
+ thisBlockDed.set("extended_price", block.get(key) - (extend - totalMoney));
|
|
|
+ if (thisWorkEntry.getString("IS_BILLABLE").equals("0"))
|
|
|
+ thisBlockDed.set("EXTENDED_PRICE", 0);
|
|
|
+ dn.recordFormChanges.record(uc, thisBlockDed, "审批提交工时");
|
|
|
+ SDK.getBOAPI().createDataBO("BO_EU_DNCRM_ACCOUNT_DEDUCTION", thisBlockDed, uc);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ BO thisBlockDed = new BO();
|
|
|
+ thisBlockDed.set("TYPE_ID", "1318");
|
|
|
+ thisBlockDed.set("OBJECT_ID", thisWorkEntry.getString("ID"));
|
|
|
+ thisBlockDed.set("POSTED_DATE", thisDate);
|
|
|
+ thisBlockDed.set("TASK_ID", thisWorkEntry.getString("TASK_ID"));
|
|
|
+ thisBlockDed.set("ACCOUNT_ID", thisWorkEntry.getString("ACCOUNT_ID"));
|
|
|
+ thisBlockDed.set("CONTRACT_ID", thisWorkEntry.getString("CONTRACT_ID"));
|
|
|
+ thisBlockDed.set("BILL_CREATE_USER_ID", thisWorkEntry.getString("CREATEUSER"));
|
|
|
+ thisBlockDed.set("PURCHASE_ORDER_NO", thisWorkEntry.getString("PURCHASE_ORDER_NO"));
|
|
|
+ thisBlockDed.set("TAX_CATEGORY_NAME", thisTaxCate == null ? null : thisTaxCate.getString("NAME"));
|
|
|
+ thisBlockDed.set("TAX_REGION_NAME", thisTaxRegion == null ? null : thisTaxRegion.getString("NAME"));
|
|
|
+ thisBlockDed.set("EFFECTIVE_TAX_RATE", tax_rate);
|
|
|
+ thisBlockDed.set("ROLE_ID", thisWorkEntry.getString("ROLE_ID"));
|
|
|
+ thisBlockDed.set("QUANTITY", totalHours);
|
|
|
+ thisBlockDed.set("RATE", thisWorkEntry.get("HOURS_RATE_DEDUCTION") != null ? thisWorkEntry.get("HOURS_RATE_DEDUCTION") : laborRate);
|
|
|
+ thisBlockDed.set("BLOCK_HOUR_MULTIPLIER", block_hour_multiplier);
|
|
|
+ thisBlockDed.set("EXTENDED_COST", GetEntryCost(thisWorkEntry.getString("ID")));
|
|
|
+ if (thisTaxCate != null)
|
|
|
+ thisBlockDed.set("TAX_CATEGORY_ID", thisTaxCate.getString("ID"));
|
|
|
+ if (thisWorkEntry.getString("IS_BILLABLE").equals("0"))
|
|
|
+ thisBlockDed.set("EXTENDED_PRICE", 0);
|
|
|
+ dn.recordFormChanges.record(uc, thisBlockDed, "审批提交工时");
|
|
|
+ SDK.getBOAPI().createDataBO("BO_EU_DNCRM_ACCOUNT_DEDUCTION", thisBlockDed, uc);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ RowMap ccnr = DBSql.getMap("select * from BO_EU_DNCTT_CONTRACT_NOTIFY_RULE where contract_id=?", new Object[]{thisContractId});
|
|
|
+ if (ccnr != null && ccnr.get("RATE") != null && ccnr.getDouble("RATE") > 0) {
|
|
|
+ Double extend = 0.0;
|
|
|
+ for (String key : block.keySet()) {
|
|
|
+ extend = extend + block.get(key);
|
|
|
+ BO thisBlockDed = new BO();
|
|
|
+ thisBlockDed.set("TYPE_ID", "1318");
|
|
|
+ thisBlockDed.set("OBJECT_ID", thisWorkEntry.getString("ID"));
|
|
|
+ thisBlockDed.set("POSTED_DATE", thisDate);
|
|
|
+ thisBlockDed.set("TASK_ID", thisWorkEntry.getString("TASK_ID"));
|
|
|
+ thisBlockDed.set("EXTENDED_PRICE", block.get(key));
|
|
|
+ thisBlockDed.set("ACCOUNT_ID", thisWorkEntry.getString("ACCOUNT_ID"));
|
|
|
+ thisBlockDed.set("CONTRACT_ID", thisWorkEntry.getString("CONTRACT_ID"));
|
|
|
+ thisBlockDed.set("BILL_CREATE_USER_ID", thisWorkEntry.getString("CREATEUSER"));
|
|
|
+ thisBlockDed.set("PURCHASE_ORDER_NO", thisWorkEntry.getString("PURCHASE_ORDER_NO"));
|
|
|
+ thisBlockDed.set("TAX_CATEGORY_NAME", thisTaxCate == null ? null : thisTaxCate.getString("NAME"));
|
|
|
+ thisBlockDed.set("TAX_REGION_NAME", thisTaxRegion == null ? null : thisTaxRegion.getString("NAME"));
|
|
|
+ thisBlockDed.set("EFFECTIVE_TAX_RATE", tax_rate);
|
|
|
+ thisBlockDed.set("ROLE_ID", thisWorkEntry.getString("ROLE_ID"));
|
|
|
+ thisBlockDed.set("QUANTITY", totalHours);
|
|
|
+ thisBlockDed.set("RATE", blockRate.get(key));
|
|
|
+ thisBlockDed.set("CONTRACT_BLOCK_ID", key);
|
|
|
+ thisBlockDed.set("BLOCK_HOUR_MULTIPLIER", block_hour_multiplier);
|
|
|
+ thisBlockDed.set("EXTENDED_COST", GetEntryCost(thisWorkEntry.getString("ID")));
|
|
|
+ if (thisTaxCate != null)
|
|
|
+ thisBlockDed.set("TAX_CATEGORY_ID", thisTaxCate.getString("ID"));
|
|
|
+
|
|
|
+ if (thisWorkEntry.getString("IS_BILLABLE").equals("0"))
|
|
|
+ thisBlockDed.set("EXTENDED_PRICE", 0);
|
|
|
+
|
|
|
+ if (thisAccount.getString("IS_TAX_EXEMPT").equals("1") == false)
|
|
|
+ thisBlockDed.set("TAX_DOLLARS", thisWorkEntry.getDouble("HOURS_BILLED") * laborRate * (1 - 1 / (1 + tax_rate)));
|
|
|
+
|
|
|
+ dn.recordFormChanges.record(uc, thisBlockDed, "审批提交工时");
|
|
|
+ SDK.getBOAPI().createDataBO("BO_EU_DNCRM_ACCOUNT_DEDUCTION", thisBlockDed, uc);
|
|
|
+
|
|
|
+ //修改相应的预付费信息
|
|
|
+ BO thisBlock = SDK.getBOAPI().get("BO_EU_DNCTT_CONTRACT_BLOCK", key);
|
|
|
+ if (thisBlock != null) {
|
|
|
+ thisBlock.set("STATUS_ID", 0);
|
|
|
+ dn.recordFormChanges.record(uc, thisBlock, "修改合同成本预付时间或费用");
|
|
|
+ SDK.getBOAPI().update("BO_EU_DNCTT_CONTRACT_BLOCK", thisBlock);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (extend - totalMoney <= 0) {
|
|
|
+ //??? 什么逻辑
|
|
|
+ System.out.println("合同金额不足");
|
|
|
+ System.out.println("后面怎么处理。。。。。。。。");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ } else {
|
|
|
+ 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("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("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", totalHours);
|
|
|
+ thisDed.set("RATE", thisWorkEntry.get("HOURS_RATE_DEDUCTION") != null ? thisWorkEntry.get("HOURS_RATE_DEDUCTION") : laborRate);
|
|
|
+ thisDed.set("BLOCK_HOUR_MULTIPLIER", block_hour_multiplier);
|
|
|
+ thisDed.set("EXTENDED_COST", GetEntryCost(thisWorkEntry.getString("ID")));
|
|
|
+ if (thisTaxCate != null)
|
|
|
+ thisDed.set("TAX_CATEGORY_ID", thisTaxCate.getString("ID"));
|
|
|
+
|
|
|
+ if (thisWorkEntry.getString("IS_BILLABLE").equals("0"))
|
|
|
+ thisDed.set("EXTENDED_PRICE", 0);
|
|
|
+
|
|
|
+ if (thisAccount.getString("IS_TAX_EXEMPT").equals("1") == false)
|
|
|
+ thisDed.set("TAX_DOLLARS", thisWorkEntry.getDouble("HOURS_BILLED") * laborRate * (1 - 1 / (1 + tax_rate)));
|
|
|
+
|
|
|
+ dn.recordFormChanges.record(uc, thisDed, "审批提交工时");
|
|
|
+ SDK.getBOAPI().createDataBO("BO_EU_DNCRM_ACCOUNT_DEDUCTION", thisDed, uc);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (thisContract == null || (thisContract.getString("type_id").equals("1203") == false && thisContract.getString("TYPE_ID").equals("1202") == false) || thisContractStartDate.compareTo(thisEntryDate) > 0 || thisContractEndDate.compareTo(thisEntryEndDate) < 0) {
|
|
|
+ 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("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("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", totalHours);
|
|
|
+ thisDed.set("RATE", thisWorkEntry.get("HOURS_RATE_DEDUCTION") != null ? thisWorkEntry.get("HOURS_RATE_DEDUCTION") : laborRate);
|
|
|
+ thisDed.set("BLOCK_HOUR_MULTIPLIER", block_hour_multiplier);
|
|
|
+ thisDed.set("EXTENDED_COST", GetEntryCost(thisWorkEntry.getString("ID")));
|
|
|
+ if (thisTaxCate != null)
|
|
|
+ thisDed.set("TAX_CATEGORY_ID", thisTaxCate.getString("ID"));
|
|
|
+
|
|
|
+ if (thisWorkEntry.getString("IS_BILLABLE").equals("0"))
|
|
|
+ thisDed.set("EXTENDED_PRICE", 0);
|
|
|
+
|
|
|
+ if (thisAccount.getString("IS_TAX_EXEMPT").equals("1") == false)
|
|
|
+ thisDed.set("TAX_DOLLARS", thisWorkEntry.getDouble("HOURS_BILLED") * laborRate * (1 - 1 / (1 + tax_rate)));
|
|
|
+
|
|
|
+ dn.recordFormChanges.record(uc, thisDed, "审批提交工时");
|
|
|
+ SDK.getBOAPI().createDataBO("BO_EU_DNCRM_ACCOUNT_DEDUCTION", thisDed, uc);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ BO oldEntry = SDK.getBOAPI().get("BO_EU_DNSDK_WORK_ENTRY", thisWorkEntry.getString("ID"));
|
|
|
+ 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 rowMap
|
|
|
+ * @param key
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getString(RowMap rowMap, String key) {
|
|
|
+ if (rowMap.containsKey(key))
|
|
|
+ return rowMap.getString(key);
|
|
|
+ else if (rowMap.containsKey(key.toUpperCase()))
|
|
|
+ return rowMap.getString(rowMap.getString(key.toUpperCase()));
|
|
|
+ else if (rowMap.containsKey(key.toLowerCase()))
|
|
|
+ return rowMap.getString(rowMap.getString(key.toLowerCase()));
|
|
|
+
|
|
|
+ key = key.toUpperCase();
|
|
|
+ for (String s : rowMap.keySet()) {
|
|
|
+ if (s.toUpperCase().equals(key))
|
|
|
+ return rowMap.getString(s);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 费用审批
|
|
|
+ * @param uc
|
|
|
+ * @param approveDate
|
|
|
+ * @param approveIds
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Mapping("com.awspaas.user.apps.donenow_ctt.approve_expense")
|
|
|
+ public ResponseObject expenseApprove(UserContext uc, String approveDate, String approveIds) {
|
|
|
+ String[] IdArr = approveIds.split(",");
|
|
|
+ String sql = "SELECT * FROM VIEW_EU_DNV_PENDING_EXPENSE 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());
|
|
|
+ for (RowMap rowMap : list) {
|
|
|
+ String expenseId = getString(rowMap, "ID");
|
|
|
+ RowMap oldExp = DBSql.getMap("SELECT * FROM BO_EU_DNSDK_EXPENSE WHERE ID=?", expenseId);
|
|
|
+ RowMap thisTaxCate = null;//税收种类
|
|
|
+ RowMap thisTaxRegion = null;//税区
|
|
|
+ Double tax_rate = 0.0;//税率
|
|
|
+ String contract_id = null;
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank("COST_CODE_ID")) {
|
|
|
+ RowMap thisCost = DBSql.getMap("SELECT * FROM BO_EU_DND_COST_CODE WHERE ID=?", getString(rowMap, "COST_CODE_ID"));
|
|
|
+ if (thisCost != null && StringUtils.isNotBlank(thisCost.getString("TAX_CATEGORY_ID"))) {
|
|
|
+ thisTaxCate = DBSql.getMap("SELECT * FROM BO_EU_DND_GENERAL WHERE OID=?", thisCost.getString("TAX_CATEGORY_ID"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ RowMap thisAccount = DBSql.getMap("SELECT * FROM BO_EU_DNCRM_ACCOUNT WHERE ID=?", getString(rowMap, "ACCOUNT_ID"));
|
|
|
+ if (thisAccount != null && StringUtils.isNotBlank(thisAccount.getString("TAX_REGION_ID"))) {
|
|
|
+ thisTaxRegion = DBSql.getMap("SELECT * FROM BO_EU_DND_GENERAL WHERE OID=?", thisAccount.getString("TAX_REGION_ID"));
|
|
|
+ }
|
|
|
+ if (thisTaxRegion != null && thisTaxCate != null) {
|
|
|
+ tax_rate = DBSql.getDouble("SELECT TOTAL_EFFECTIVE_TAX_RATE FROM BO_EU_DND_TAX_REGION_CATE WHERE tax_region_id='" + thisTaxRegion.getString("ID") + "' and tax_cate_id='" + thisTaxCate.getString("ID") + "' ", "TOTAL_EFFECTIVE_TAX_RATE");
|
|
|
+ }
|
|
|
+ LocalDate thisDate = getLocalDate(approveDate);//审批时间
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(oldExp.getString("PROJECT_ID"))) {
|
|
|
+ String projectRateContractId = DBSql.getString("SELECT CONTRACT_ID FROM BO_EU_DNPRO_PROJECT WHERE ID=?", new Object[]{oldExp.getString("PROJECT_ID")});
|
|
|
+ if (StringUtils.isNotBlank(projectRateContractId)) {
|
|
|
+ contract_id = projectRateContractId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(oldExp.getString("TASK_ID"))) {
|
|
|
+ String taskRateContractId = DBSql.getString("SELECT CONTRACT_ID FROM BO_EU_DNSDK_TASK WHERE ID=?", new Object[]{oldExp.getString("TASK_ID")});
|
|
|
+ if (StringUtils.isNotBlank(taskRateContractId)) {
|
|
|
+ contract_id = taskRateContractId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Double extended_price = 0.0;
|
|
|
+ if (oldExp.getString("IS_BILLABLE").equals("1")) {
|
|
|
+ if (oldExp.get("AMOUNT_DEDUCTION") != null && oldExp.getDouble("AMOUNT_DEDUCTION") > 0) {
|
|
|
+ extended_price = oldExp.getDouble("AMOUNT_DEDUCTION");
|
|
|
+ } else if (oldExp.get("AMOUNT") != null && oldExp.getDouble("AMOUNT") > 0) {
|
|
|
+ extended_price = oldExp.getDouble("AMOUNT");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ BO thisDed = new BO();
|
|
|
+ thisDed.set("CONTRACT_ID", contract_id);
|
|
|
+ thisDed.set("OBJECT_ID", oldExp.getString("ID"));
|
|
|
+ thisDed.set("TYPE_ID", "1322");
|
|
|
+ thisDed.set("POSTED_DATE", thisDate);
|
|
|
+ thisDed.set("TASK_ID", oldExp.getString("TASK_ID"));
|
|
|
+ thisDed.set("EXTENDED_PRICE", extended_price);
|
|
|
+ thisDed.set("EXTENDED_COST", extended_price);
|
|
|
+ thisDed.set("ACCOUNT_ID", oldExp.getString("ACCOUNT_ID"));
|
|
|
+ thisDed.set("QUANTITY", 1);
|
|
|
+ thisDed.set("BILL_CREATE_USER_ID", oldExp.getString("CREATEUSER"));
|
|
|
+ thisDed.set("PURCHASE_ORDER_NO", oldExp.getString("PURCHASE_ORDER_NO"));
|
|
|
+ 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("TAX_DOLLARS", extended_price * (1 - 1 / (1 + tax_rate)));
|
|
|
+ if (thisTaxCate != null)
|
|
|
+ thisDed.set("TAX_CATEGORY_ID", thisTaxCate.getString("ID"));
|
|
|
+
|
|
|
+ dn.recordFormChanges.record(uc, thisDed, "审批提交费用");
|
|
|
+ SDK.getBOAPI().createDataBO("BO_EU_DNCRM_ACCOUNT_DEDUCTION", thisDed, uc);
|
|
|
+
|
|
|
+ BO oldExpense = SDK.getBOAPI().get("BO_EU_DNSDK_EXPENSE", oldExp.getString("ID"));
|
|
|
+ oldExpense.set("APPROVE_AND_POST_DATE", thisDate);
|
|
|
+ oldExpense.set("APPROVE_AND_POST_USER_ID", uc.getUID());
|
|
|
+ dn.recordFormChanges.record(uc, oldExpense, "审批提交费用");
|
|
|
+ SDK.getBOAPI().update("BO_EU_DNSDK_EXPENSE", oldExpense);
|
|
|
+
|
|
|
+
|
|
|
+ //通知
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return ResponseObject.newOkResponse();
|
|
|
+ }
|
|
|
}
|