|
@@ -10,6 +10,7 @@ import com.actionsoft.sdk.local.SDK;
|
|
|
import com.actionsoft.sdk.local.api.Logger;
|
|
import com.actionsoft.sdk.local.api.Logger;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.joda.time.LocalDate;
|
|
import org.joda.time.LocalDate;
|
|
|
|
|
+import org.joda.time.format.DateTimeFormat;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
@@ -50,8 +51,7 @@ public class InvoiceService {
|
|
|
logger.info("日期范围:" + param.getDateRangeFrom() + "--" + param.getDateRangeTo());
|
|
logger.info("日期范围:" + param.getDateRangeFrom() + "--" + param.getDateRangeTo());
|
|
|
|
|
|
|
|
// 1. 基础校验:空值过滤
|
|
// 1. 基础校验:空值过滤
|
|
|
- if (StringUtils.isBlank(accDeduIds))
|
|
|
|
|
- return "参数错误";
|
|
|
|
|
|
|
+ if (StringUtils.isBlank(accDeduIds)) return "参数错误";
|
|
|
|
|
|
|
|
String[] dedIdArr = accDeduIds.split(",");
|
|
String[] dedIdArr = accDeduIds.split(",");
|
|
|
|
|
|
|
@@ -85,19 +85,22 @@ public class InvoiceService {
|
|
|
//ITEM_DATE i) 弹出窗口输入账单起止日期,保存时需要校验所选条目是否在账单起止日期内
|
|
//ITEM_DATE i) 弹出窗口输入账单起止日期,保存时需要校验所选条目是否在账单起止日期内
|
|
|
// ii) 批量选择条目:计费客户相同、状态必须为----未生成生成账单
|
|
// ii) 批量选择条目:计费客户相同、状态必须为----未生成生成账单
|
|
|
|
|
|
|
|
|
|
+ org.joda.time.format.DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd");
|
|
|
|
|
+
|
|
|
String BILL_ACCOUNT_ID = null;
|
|
String BILL_ACCOUNT_ID = null;
|
|
|
for (RowMap row : postedDataList) {
|
|
for (RowMap row : postedDataList) {
|
|
|
String ITEM_DATE = row.getString("ITEM_DATE");
|
|
String ITEM_DATE = row.getString("ITEM_DATE");
|
|
|
if (StringUtils.isNotBlank(ITEM_DATE)) {
|
|
if (StringUtils.isNotBlank(ITEM_DATE)) {
|
|
|
- LocalDate itemDate = TypeUtil.convert(ITEM_DATE, LocalDate.class);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ LocalDate itemDate = LocalDate.parse(ITEM_DATE, formatter);
|
|
|
|
|
+
|
|
|
//i) 弹出窗口输入账单起止日期,保存时需要校验所选条目是否在账单起止日期内
|
|
//i) 弹出窗口输入账单起止日期,保存时需要校验所选条目是否在账单起止日期内
|
|
|
if (itemDate.isBefore(param.getDateRangeFrom()) || itemDate.isAfter(param.getDateRangeTo())) {
|
|
if (itemDate.isBefore(param.getDateRangeFrom()) || itemDate.isAfter(param.getDateRangeTo())) {
|
|
|
return "所选条目有账单起止日期不符合要求";
|
|
return "所选条目有账单起止日期不符合要求";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// ii) 批量选择条目:计费客户相同、状态必须为----未生成生成账单
|
|
// ii) 批量选择条目:计费客户相同、状态必须为----未生成生成账单
|
|
|
- if (StringUtils.isBlank(BILL_ACCOUNT_ID))
|
|
|
|
|
- BILL_ACCOUNT_ID = row.getString("BILL_ACCOUNT_ID");
|
|
|
|
|
|
|
+ if (StringUtils.isBlank(BILL_ACCOUNT_ID)) BILL_ACCOUNT_ID = row.getString("BILL_ACCOUNT_ID");
|
|
|
else {
|
|
else {
|
|
|
if (!BILL_ACCOUNT_ID.equals(row.getString("BILL_ACCOUNT_ID"))) {
|
|
if (!BILL_ACCOUNT_ID.equals(row.getString("BILL_ACCOUNT_ID"))) {
|
|
|
return "所选条目有账单客户必须相同";
|
|
return "所选条目有账单客户必须相同";
|
|
@@ -106,8 +109,7 @@ public class InvoiceService {
|
|
|
|
|
|
|
|
//RECEIVE_STATUS 4661 未生成生成账单
|
|
//RECEIVE_STATUS 4661 未生成生成账单
|
|
|
String RECEIVE_STATUS = row.getString("RECEIVE_STATUS");
|
|
String RECEIVE_STATUS = row.getString("RECEIVE_STATUS");
|
|
|
- if (RECEIVE_STATUS.equals("4661") == false)
|
|
|
|
|
- return "所选条目有账单状态必须为未生成生成账单";
|
|
|
|
|
|
|
+ if (RECEIVE_STATUS.equals("4661") == false) return "所选条目有账单状态必须为未生成生成账单";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -128,7 +130,12 @@ public class InvoiceService {
|
|
|
List<RowMap> customerDedList = entry.getValue();
|
|
List<RowMap> customerDedList = entry.getValue();
|
|
|
|
|
|
|
|
// 4.1 客户信息校验:必须有客户顾问(否则跳过)
|
|
// 4.1 客户信息校验:必须有客户顾问(否则跳过)
|
|
|
|
|
+
|
|
|
RowMap customer = DBSql.getMap("SELECT * FROM BO_EU_DNCRM_ACCOUNT WHERE ID = ?", ACCOUNT_ID);
|
|
RowMap customer = DBSql.getMap("SELECT * FROM BO_EU_DNCRM_ACCOUNT WHERE ID = ?", ACCOUNT_ID);
|
|
|
|
|
+
|
|
|
|
|
+ logger.info("处理客户ID:" + ACCOUNT_ID);
|
|
|
|
|
+ logger.info("RESOURCE_ID--" + customer.getString("RESOURCE_ID"));
|
|
|
|
|
+
|
|
|
if (customer == null || StringUtils.isBlank(customer.getString("RESOURCE_ID"))) {
|
|
if (customer == null || StringUtils.isBlank(customer.getString("RESOURCE_ID"))) {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
@@ -137,6 +144,7 @@ public class InvoiceService {
|
|
|
List<RowMap> noPoDedList = customerDedList.stream().filter(ded -> StringUtils.isBlank(ded.getString("PURCHASE_ORDER_NO"))).collect(Collectors.toList());
|
|
List<RowMap> noPoDedList = customerDedList.stream().filter(ded -> StringUtils.isBlank(ded.getString("PURCHASE_ORDER_NO"))).collect(Collectors.toList());
|
|
|
if (!noPoDedList.isEmpty()) {
|
|
if (!noPoDedList.isEmpty()) {
|
|
|
List<RowMap> noPoPostedList = postedDataList.stream().filter(p -> StringUtils.isBlank(p.getString("PURCHASE_ORDER_NO"))).filter(p -> ACCOUNT_ID.equals(p.get("ACCOUNT_ID")) || ACCOUNT_ID.equals(p.get("BILL_ACCOUNT_ID"))).collect(Collectors.toList());
|
|
List<RowMap> noPoPostedList = postedDataList.stream().filter(p -> StringUtils.isBlank(p.getString("PURCHASE_ORDER_NO"))).filter(p -> ACCOUNT_ID.equals(p.get("ACCOUNT_ID")) || ACCOUNT_ID.equals(p.get("BILL_ACCOUNT_ID"))).collect(Collectors.toList());
|
|
|
|
|
+ logger.info("无PO账单数量:" + noPoPostedList.size());
|
|
|
String noPoInvoiceId = createInvoiceAndDetails(uc, customer, noPoPostedList, noPoDedList, itemTypeDict, param, isDeal, "");
|
|
String noPoInvoiceId = createInvoiceAndDetails(uc, customer, noPoPostedList, noPoDedList, itemTypeDict, param, isDeal, "");
|
|
|
if (StringUtils.isNotBlank(noPoInvoiceId)) {
|
|
if (StringUtils.isNotBlank(noPoInvoiceId)) {
|
|
|
invoiceIds.add(noPoInvoiceId);
|
|
invoiceIds.add(noPoInvoiceId);
|
|
@@ -149,6 +157,8 @@ public class InvoiceService {
|
|
|
String poNo = poEntry.getKey();
|
|
String poNo = poEntry.getKey();
|
|
|
List<RowMap> poDedList = poEntry.getValue();
|
|
List<RowMap> poDedList = poEntry.getValue();
|
|
|
List<RowMap> poPostedList = postedDataList.stream().filter(p -> poNo.equals(p.getString("PURCHASE_ORDER_NO"))).filter(p -> ACCOUNT_ID.equals(p.get("ACCOUNT_ID")) || ACCOUNT_ID.equals(p.get("BILL_ACCOUNT_ID"))).collect(Collectors.toList());
|
|
List<RowMap> poPostedList = postedDataList.stream().filter(p -> poNo.equals(p.getString("PURCHASE_ORDER_NO"))).filter(p -> ACCOUNT_ID.equals(p.get("ACCOUNT_ID")) || ACCOUNT_ID.equals(p.get("BILL_ACCOUNT_ID"))).collect(Collectors.toList());
|
|
|
|
|
+ logger.info("处理采购订单:" + poNo);
|
|
|
|
|
+
|
|
|
String poInvoiceId = createInvoiceAndDetails(uc, customer, poPostedList, poDedList, itemTypeDict, param, isDeal, poNo);
|
|
String poInvoiceId = createInvoiceAndDetails(uc, customer, poPostedList, poDedList, itemTypeDict, param, isDeal, poNo);
|
|
|
if (StringUtils.isNotBlank(poInvoiceId)) {
|
|
if (StringUtils.isNotBlank(poInvoiceId)) {
|
|
|
invoiceIds.add(poInvoiceId);
|
|
invoiceIds.add(poInvoiceId);
|
|
@@ -179,40 +189,38 @@ public class InvoiceService {
|
|
|
try {
|
|
try {
|
|
|
// 1. 计算汇总数据
|
|
// 1. 计算汇总数据
|
|
|
InvoiceSummary summary = calculateSummary(postedList);
|
|
InvoiceSummary summary = calculateSummary(postedList);
|
|
|
-
|
|
|
|
|
// 2. 生成发票编号+创建流程实例
|
|
// 2. 生成发票编号+创建流程实例
|
|
|
String invoiceNo = SDK.getRuleAPI().executeAtScript("B@left(@date,4)@mid(@date,6,2).@mid(@sequenceMonth(@companyId_invoice,4,0,1),7)", uc);
|
|
String invoiceNo = SDK.getRuleAPI().executeAtScript("B@left(@date,4)@mid(@date,6,2).@mid(@sequenceMonth(@companyId_invoice,4,0,1),7)", uc);
|
|
|
ProcessInstance pi = SDK.getProcessAPI().createProcessInstance("obj_a7d46a9dd4df40b899ddcf02113fe0d2", uc.getUID(), "新增账单" + invoiceNo);
|
|
ProcessInstance pi = SDK.getProcessAPI().createProcessInstance("obj_a7d46a9dd4df40b899ddcf02113fe0d2", uc.getUID(), "新增账单" + invoiceNo);
|
|
|
-
|
|
|
|
|
// 3. 构建并保存发票头
|
|
// 3. 构建并保存发票头
|
|
|
BO invoice = new BO();
|
|
BO invoice = new BO();
|
|
|
invoice.set("INVOICE_NO", invoiceNo);
|
|
invoice.set("INVOICE_NO", invoiceNo);
|
|
|
invoice.set("ACCOUNT_ID", customer.getString("ID"));
|
|
invoice.set("ACCOUNT_ID", customer.getString("ID"));
|
|
|
invoice.set("ACCOUNT_NAME", customer.getString("NAME"));
|
|
invoice.set("ACCOUNT_NAME", customer.getString("NAME"));
|
|
|
invoice.set("OWNER_RESOURCE_NAME", DBSql.getString("SELECT USERNAME FROM orguser WHERE USERID=?", new Object[]{customer.getString("RESOURCE_ID")}));
|
|
invoice.set("OWNER_RESOURCE_NAME", DBSql.getString("SELECT USERNAME FROM orguser WHERE USERID=?", new Object[]{customer.getString("RESOURCE_ID")}));
|
|
|
- invoice.set("INVOICE_DATE", param.getInvoiceDate());
|
|
|
|
|
|
|
+
|
|
|
|
|
+ invoice.set("INVOICE_DATE", param.getInvoiceDate().toString());
|
|
|
|
|
+ invoice.set("DATE_RANGE_FROM", param.getDateRangeFrom().toString());
|
|
|
|
|
+ invoice.set("DATE_RANGE_TO", param.getDateRangeTo().toString());
|
|
|
|
|
+
|
|
|
invoice.set("TOTAL", summary.totalMoney);
|
|
invoice.set("TOTAL", summary.totalMoney);
|
|
|
invoice.set("TAX_VALUE", summary.totalTax);
|
|
invoice.set("TAX_VALUE", summary.totalTax);
|
|
|
invoice.set("TOTAL_PRICE", summary.totalPrice);
|
|
invoice.set("TOTAL_PRICE", summary.totalPrice);
|
|
|
invoice.set("NOBILL_HOURS", summary.noBillHours);
|
|
invoice.set("NOBILL_HOURS", summary.noBillHours);
|
|
|
invoice.set("BILL_HOURS", summary.billHours);
|
|
invoice.set("BILL_HOURS", summary.billHours);
|
|
|
invoice.set("PREPAID_HOURS", summary.prepaidHours);
|
|
invoice.set("PREPAID_HOURS", summary.prepaidHours);
|
|
|
- invoice.set("DATE_RANGE_FROM", param.getDateRangeFrom());
|
|
|
|
|
- invoice.set("DATE_RANGE_TO", param.getDateRangeTo());
|
|
|
|
|
invoice.set("PAYMENT_TERM_ID", param.getPaymentTermId());
|
|
invoice.set("PAYMENT_TERM_ID", param.getPaymentTermId());
|
|
|
invoice.set("PURCHASE_ORDER_NO", poNo); // 有PO则赋值,无PO为空
|
|
invoice.set("PURCHASE_ORDER_NO", poNo); // 有PO则赋值,无PO为空
|
|
|
invoice.set("NOTES", param.getNotes());
|
|
invoice.set("NOTES", param.getNotes());
|
|
|
// 税区名称查询
|
|
// 税区名称查询
|
|
|
- String taxRegionName = StringUtils.isBlank(customer.getString("TAX_REGION_ID")) ? "" : DBSql.getString("SELECT NAME FROM BO_EU_DND_GENERAL WHERE OID = ?", new Object[]{customer.getString("TAX_REGION_ID")});
|
|
|
|
|
|
|
+ String taxRegionName = StringUtils.isBlank(customer.getString("TAX_REGION_ID")) || customer.getString("TAX_REGION_ID").equals("0") ? "" : DBSql.getString("SELECT NAME FROM BO_EU_DND_GENERAL WHERE OID = ?", new Object[]{customer.getString("TAX_REGION_ID")});
|
|
|
|
|
+
|
|
|
invoice.set("TAX_REGION_NAME", taxRegionName);
|
|
invoice.set("TAX_REGION_NAME", taxRegionName);
|
|
|
invoice.setBindId(pi.getId());
|
|
invoice.setBindId(pi.getId());
|
|
|
|
|
|
|
|
// 记录变更+保存发票BO
|
|
// 记录变更+保存发票BO
|
|
|
-
|
|
|
|
|
SDK.getBOAPI().create("BO_EU_DNCTT_INVOICE", invoice, pi, uc);
|
|
SDK.getBOAPI().create("BO_EU_DNCTT_INVOICE", invoice, pi, uc);
|
|
|
-
|
|
|
|
|
dn.recordFormChanges.record(uc, invoice, "保存发票:" + invoiceNo);
|
|
dn.recordFormChanges.record(uc, invoice, "保存发票:" + invoiceNo);
|
|
|
-
|
|
|
|
|
// 4. 构建并保存发票明细(批量处理)
|
|
// 4. 构建并保存发票明细(批量处理)
|
|
|
Map<String, RowMap> dedIdMap = dedList.stream().collect(Collectors.toMap(ded -> ded.getString("ID"), ded -> ded));
|
|
Map<String, RowMap> dedIdMap = dedList.stream().collect(Collectors.toMap(ded -> ded.getString("ID"), ded -> ded));
|
|
|
int lineNo = 1;
|
|
int lineNo = 1;
|
|
@@ -232,7 +240,7 @@ public class InvoiceService {
|
|
|
detail.set("DOLLARS", posted.get("DOLLARS"));//含税总价
|
|
detail.set("DOLLARS", posted.get("DOLLARS"));//含税总价
|
|
|
detail.set("TAX_DOLLARS", posted.get("TAX_DOLLARS"));//税额
|
|
detail.set("TAX_DOLLARS", posted.get("TAX_DOLLARS"));//税额
|
|
|
|
|
|
|
|
- BigDecimal DOLLARS_NOTAX =(posted.get("DOLLARS")==null?BigDecimal.ZERO: TypeUtil.convert(posted.get("DOLLARS"), BigDecimal.class)).subtract((posted.get("TAX_DOLLARS")==null?BigDecimal.ZERO: TypeUtil.convert(posted.get("TAX_DOLLARS"), BigDecimal.class)));
|
|
|
|
|
|
|
+ BigDecimal DOLLARS_NOTAX = (posted.get("DOLLARS") == null ? BigDecimal.ZERO : TypeUtil.convert(posted.get("DOLLARS"), BigDecimal.class)).subtract((posted.get("TAX_DOLLARS") == null ? BigDecimal.ZERO : TypeUtil.convert(posted.get("TAX_DOLLARS"), BigDecimal.class)));
|
|
|
|
|
|
|
|
detail.set("DOLLARS_NOTAX", DOLLARS_NOTAX);//不含税总价
|
|
detail.set("DOLLARS_NOTAX", DOLLARS_NOTAX);//不含税总价
|
|
|
|
|
|
|
@@ -283,6 +291,8 @@ public class InvoiceService {
|
|
|
|
|
|
|
|
return invoice.getId(); // 返回生成的发票ID
|
|
return invoice.getId(); // 返回生成的发票ID
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
|
|
+ logger.info("错误---" + e.getMessage());
|
|
|
|
|
+ logger.error("错误--111-", e);
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|