应付配置增加附加费配置,应付账单新增核销、对账、凭证、审核功能

This commit is contained in:
liuminghui
2026-11-12 18:20:32 +08:00
parent 1ba431540d
commit 6675808dfc
55 changed files with 5898 additions and 185 deletions
@@ -5,8 +5,13 @@
<select id="selectPayBillList" resultType="com.bms.price.domain.PayBill">
select bill_id as billId, bill_no as billNo, supplier_id as supplierId, supplier_name as supplierName,
currency, source_type as sourceType, period_start as periodStart, period_end as periodEnd,
order_count as orderCount, total_amount as totalAmount, status, void_reason as voidReason,
void_by as voidBy, void_time as voidTime, create_by as createBy, create_time as createTime, remark
order_count as orderCount, total_amount as totalAmount, supplier_amount as supplierAmount,
diff_amount as diffAmount, paid_amount as paidAmount, due_date as dueDate, status,
bill_kind as billKind, original_bill_id as originalBillId, void_reason as voidReason,
void_by as voidBy, void_time as voidTime, confirm_by as confirmBy, confirm_time as confirmTime,
tax_rate as taxRate, amount_net as amountNet, tax_amount as taxAmount, exchange_rate as exchangeRate,
base_amount as baseAmount, rate_date as rateDate, term_days as termDays, submit_by as submitBy,
create_by as createBy, create_time as createTime, remark
from pay_bill
<where>
<if test="billNo != null and billNo != ''">and bill_no like concat('%', #{billNo}, '%')</if>
@@ -20,22 +25,30 @@
<select id="selectPayBillById" resultType="com.bms.price.domain.PayBill">
select bill_id as billId, bill_no as billNo, supplier_id as supplierId, supplier_name as supplierName,
currency, source_type as sourceType, period_start as periodStart, period_end as periodEnd,
order_count as orderCount, total_amount as totalAmount, status, void_reason as voidReason,
void_by as voidBy, void_time as voidTime, create_by as createBy, create_time as createTime, remark
order_count as orderCount, total_amount as totalAmount, supplier_amount as supplierAmount,
diff_amount as diffAmount, paid_amount as paidAmount, due_date as dueDate, status,
bill_kind as billKind, original_bill_id as originalBillId, void_reason as voidReason,
void_by as voidBy, void_time as voidTime, confirm_by as confirmBy, confirm_time as confirmTime,
tax_rate as taxRate, amount_net as amountNet, tax_amount as taxAmount, exchange_rate as exchangeRate,
base_amount as baseAmount, rate_date as rateDate, term_days as termDays, submit_by as submitBy,
create_by as createBy, create_time as createTime, remark
from pay_bill where bill_id = #{billId}
</select>
<select id="selectLines" resultType="com.bms.price.domain.PayBillLine">
select line_id as lineId, bill_id as billId, order_bill_id as orderBillId, order_no as orderNo,
lading_no as ladingNo, lading_fee_id as ladingFeeId, fee_name as feeName, amount, currency,
price_date as priceDate, version_no as versionNo, remote_flag as remoteFlag,
density_level as densityLevel, line_source as lineSource
select line_id as lineId, bill_id as billId, fee_id as feeId, order_bill_id as orderBillId, order_no as orderNo,
lading_no as ladingNo, lading_fee_id as ladingFeeId, fee_name as feeName, fee_source as feeSource,
fee_level as feeLevel, amount, supplier_amount as supplierAmount, diff_amount as diffAmount,
diff_status as diffStatus, currency, price_date as priceDate, version_no as versionNo,
remote_flag as remoteFlag, density_level as densityLevel, line_source as lineSource
from pay_bill_line where bill_id = #{billId} order by line_id
</select>
<select id="selectLogs" resultType="com.bms.price.domain.PayBillLog">
select log_id as logId, bill_id as billId, operation_type as operationType, from_status as fromStatus,
to_status as toStatus, operation_desc as operationDesc, operator_name as operatorName, create_time as createTime
select log_id as logId, bill_id as billId, biz_type as bizType, biz_id as bizId, line_id as lineId,
fee_id as feeId, operation_type as operationType, from_status as fromStatus, to_status as toStatus,
operation_desc as operationDesc, amount_before as amountBefore, amount_after as amountAfter,
operator_name as operatorName, create_time as createTime
from pay_bill_log where bill_id = #{billId} order by log_id
</select>
@@ -48,9 +61,21 @@
(select group_concat(concat(ifnull(nullif(trim(f.fee_name), ''), ifnull(f.fee_type, '费用')), ' ', format(f.amount, 2))
order by field(f.fee_type, 'BASIC_FREIGHT', 'REGISTRATION_FEE', 'SURCHARGE', 'REFUND'), f.fee_id separator ';')
from prc_pay_bill_fee f where f.bill_id = o.bill_id and f.is_deleted = '0') as feeText,
(select count(*) from prc_pay_bill_fee f
where f.bill_id = o.bill_id and ifnull(f.is_deleted, '0') = '0') as feeCount,
(select count(*) from prc_pay_bill_fee f
where f.bill_id = o.bill_id and ifnull(f.is_deleted, '0') = '0'
and f.statement_line_id is null
and not exists (
select 1 from pay_bill_line l
inner join pay_bill b on b.bill_id = l.bill_id
where l.order_bill_id = o.bill_id
and (l.fee_id is null or l.fee_id = '')
and b.status not in ('VOID', 'RED')
)) as unbilledCount,
(select b.bill_no from pay_bill_line l
inner join pay_bill b on b.bill_id = l.bill_id
where l.order_bill_id = o.bill_id and b.status &lt;&gt; 'VOID'
where l.order_bill_id = o.bill_id and b.status not in ('VOID', 'RED')
limit 1) as occupiedBillNo
from prc_order_bill o
left join prc_order_bill_ext e on e.bill_id = o.bill_id
@@ -81,8 +106,9 @@
</select>
<select id="selectOrderFees" resultType="com.bms.price.domain.PrcPayBillFee">
select fee_id as feeId, bill_id as billId, fee_name as feeName, amount, currency, fee_source as feeSource,
source_id as sourceId, is_deleted as isDeleted
select fee_id as feeId, bill_id as billId, pay_bill_id as payBillId, fee_type as feeType, fee_name as feeName,
sc_id as scId, fee_level as feeLevel, amount, currency, fee_source as feeSource, source_id as sourceId,
is_deleted as isDeleted
from prc_pay_bill_fee
where is_deleted = '0'
and bill_id in
@@ -93,10 +119,15 @@
<insert id="insertPayBill" useGeneratedKeys="true" keyProperty="billId">
insert into pay_bill (
bill_no, supplier_id, supplier_name, currency, source_type, period_start, period_end,
order_count, total_amount, status, create_by, create_time, remark
order_count, total_amount, supplier_amount, diff_amount, paid_amount, due_date, status, bill_kind,
original_bill_id, tax_rate, amount_net, tax_amount, exchange_rate, base_amount, rate_date, term_days,
create_by, create_time, remark
) values (
#{billNo}, #{supplierId}, #{supplierName}, #{currency}, #{sourceType}, #{periodStart}, #{periodEnd},
#{orderCount}, #{totalAmount}, 'DRAFT', #{createBy}, sysdate(), #{remark}
#{orderCount}, #{totalAmount}, #{supplierAmount}, #{diffAmount}, #{paidAmount}, #{dueDate}, 'DRAFT',
ifnull(#{billKind}, 'BLUE'), #{originalBillId}, ifnull(#{taxRate}, 0), ifnull(#{amountNet}, #{totalAmount}),
ifnull(#{taxAmount}, 0), ifnull(#{exchangeRate}, 1), ifnull(#{baseAmount}, #{totalAmount}), #{rateDate},
#{termDays}, #{createBy}, sysdate(), #{remark}
)
</insert>
@@ -113,18 +144,245 @@
<insert id="insertLines">
insert into pay_bill_line (
bill_id, order_bill_id, order_no, lading_no, lading_fee_id, fee_name, amount, currency,
price_date, version_no, remote_flag, density_level, line_source
bill_id, fee_id, order_bill_id, order_no, lading_no, lading_fee_id, fee_name, fee_source, fee_level,
amount, supplier_amount, diff_amount, diff_status, currency, price_date, version_no, remote_flag,
density_level, line_source
) values
<foreach collection="list" item="item" separator=",">
(#{item.billId}, #{item.orderBillId}, #{item.orderNo}, #{item.ladingNo}, #{item.ladingFeeId},
#{item.feeName}, #{item.amount}, #{item.currency}, #{item.priceDate}, #{item.versionNo},
#{item.remoteFlag}, #{item.densityLevel}, #{item.lineSource})
(#{item.billId}, #{item.feeId}, #{item.orderBillId}, #{item.orderNo}, #{item.ladingNo}, #{item.ladingFeeId},
#{item.feeName}, #{item.feeSource}, #{item.feeLevel}, #{item.amount}, #{item.supplierAmount},
#{item.diffAmount}, ifnull(#{item.diffStatus}, 'NONE'), #{item.currency}, #{item.priceDate},
#{item.versionNo}, #{item.remoteFlag}, #{item.densityLevel}, #{item.lineSource})
</foreach>
</insert>
<insert id="insertLine" useGeneratedKeys="true" keyProperty="lineId">
insert into pay_bill_line (
bill_id, fee_id, order_bill_id, order_no, lading_no, lading_fee_id, fee_name, fee_source, fee_level,
amount, supplier_amount, diff_amount, diff_status, currency, price_date, version_no, remote_flag,
density_level, line_source
) values (
#{billId}, #{feeId}, #{orderBillId}, #{orderNo}, #{ladingNo}, #{ladingFeeId}, #{feeName}, #{feeSource},
#{feeLevel}, #{amount}, #{supplierAmount}, #{diffAmount}, ifnull(#{diffStatus}, 'NONE'), #{currency},
#{priceDate}, #{versionNo}, #{remoteFlag}, #{densityLevel}, #{lineSource}
)
</insert>
<update id="bindFeeLine">
update prc_pay_bill_fee
set statement_line_id = #{lineId}
where fee_id = #{feeId}
and statement_line_id is null
and ifnull(is_deleted, '0') = '0'
</update>
<update id="clearFeeLine">
update prc_pay_bill_fee set statement_line_id = null where statement_line_id = #{lineId}
</update>
<update id="clearFeeLines">
update prc_pay_bill_fee f
inner join pay_bill_line l on l.line_id = f.statement_line_id
set f.statement_line_id = null
where l.bill_id = #{billId}
</update>
<update id="updatePayBillMoney">
update pay_bill
set total_amount = #{totalAmount},
supplier_amount = #{supplierAmount},
diff_amount = #{diffAmount},
paid_amount = #{paidAmount},
order_count = #{orderCount},
status = #{status},
confirm_by = #{confirmBy},
confirm_time = #{confirmTime},
tax_rate = ifnull(#{taxRate}, 0),
amount_net = ifnull(#{amountNet}, #{totalAmount}),
tax_amount = ifnull(#{taxAmount}, 0),
exchange_rate = ifnull(#{exchangeRate}, 1),
base_amount = ifnull(#{baseAmount}, #{totalAmount}),
rate_date = #{rateDate},
term_days = #{termDays},
update_by = #{updateBy},
update_time = sysdate()
where bill_id = #{billId}
</update>
<update id="updateLineAmount">
update pay_bill_line
set supplier_amount = #{supplierAmount},
diff_amount = #{diffAmount},
diff_status = #{diffStatus}
where line_id = #{lineId}
and bill_id = #{billId}
</update>
<delete id="deleteOpenDiff">
delete from pay_bill_diff where line_id = #{lineId} and handle_type = 'OPEN'
</delete>
<delete id="deleteLine">
delete from pay_bill_line where bill_id = #{billId} and line_id = #{lineId}
</delete>
<select id="selectFreeFees" resultType="com.bms.price.domain.PrcPayBillFee">
select f.fee_id as feeId, f.bill_id as billId, f.pay_bill_id as payBillId, f.fee_type as feeType,
f.fee_name as feeName, f.sc_id as scId, f.fee_level as feeLevel, f.amount, f.currency,
f.fee_source as feeSource, f.source_id as sourceId, f.settle_supplier_id as settleSupplierId,
f.settle_supplier_name as settleSupplierName
from prc_pay_bill_fee f
where ifnull(f.is_deleted, '0') = '0'
and f.statement_line_id is null
and f.bill_id in
<foreach collection="billIds" item="id" open="(" separator="," close=")">#{id}</foreach>
and not exists (
select 1 from pay_bill_line l
inner join pay_bill b on b.bill_id = l.bill_id
where l.order_bill_id = f.bill_id
and (l.fee_id is null or l.fee_id = '')
and b.status not in ('VOID', 'RED')
)
order by f.bill_id, f.fee_id
</select>
<select id="countCalcFees" resultType="int">
select count(*)
from prc_pay_bill_fee
where bill_id = #{billId}
and ifnull(is_deleted, '0') = '0'
and fee_source = 'CALC'
</select>
<select id="selectDiffs" resultType="com.bms.price.domain.PayBillDiff">
select diff_id as diffId, bill_id as billId, line_id as lineId, fee_id as feeId, our_amount as ourAmount,
supplier_amount as supplierAmount, diff_amount as diffAmount, reason, handle_type as handleType,
adjust_fee_id as adjustFeeId, create_by as createBy, create_time as createTime
from pay_bill_diff where bill_id = #{billId} order by diff_id
</select>
<select id="selectFiles" resultType="com.bms.price.domain.PayBillFile">
select file_id as fileId, bill_id as billId, file_type as fileType, invoice_no as invoiceNo,
invoice_date as invoiceDate, amount, tax_amount as taxAmount, amount_net as amountNet,
seller_name as sellerName, matched_amount as matchedAmount, currency, file_name as fileName,
file_url as fileUrl, deleted, create_by as createBy, create_time as createTime
from pay_bill_file
where bill_id = #{billId} and deleted = '0'
order by file_id
</select>
<select id="selectApprovals" resultType="com.bms.price.domain.PayBillApproval">
select approval_id as approvalId, bill_id as billId, action, opinion, operator_name as operatorName,
create_time as createTime
from pay_bill_approval where bill_id = #{billId} order by approval_id
</select>
<select id="selectLine" resultType="com.bms.price.domain.PayBillLine">
select line_id as lineId, bill_id as billId, fee_id as feeId, order_bill_id as orderBillId, order_no as orderNo,
lading_no as ladingNo, fee_name as feeName, fee_source as feeSource, fee_level as feeLevel, amount,
supplier_amount as supplierAmount, diff_amount as diffAmount, diff_status as diffStatus, currency,
line_source as lineSource
from pay_bill_line where line_id = #{lineId}
</select>
<select id="selectOpenDiff" resultType="com.bms.price.domain.PayBillDiff">
select diff_id as diffId, bill_id as billId, line_id as lineId, fee_id as feeId, our_amount as ourAmount,
supplier_amount as supplierAmount, diff_amount as diffAmount, reason, handle_type as handleType,
adjust_fee_id as adjustFeeId
from pay_bill_diff
where line_id = #{lineId} and handle_type = 'OPEN'
order by diff_id desc
limit 1
</select>
<insert id="insertDiff" useGeneratedKeys="true" keyProperty="diffId">
insert into pay_bill_diff (
bill_id, line_id, fee_id, our_amount, supplier_amount, diff_amount, reason, handle_type, adjust_fee_id,
create_by, create_time
) values (
#{billId}, #{lineId}, #{feeId}, #{ourAmount}, #{supplierAmount}, #{diffAmount}, #{reason}, #{handleType},
#{adjustFeeId}, #{createBy}, sysdate()
)
</insert>
<update id="updateDiff">
update pay_bill_diff
set our_amount = #{ourAmount},
supplier_amount = #{supplierAmount},
diff_amount = #{diffAmount},
reason = #{reason},
handle_type = #{handleType},
adjust_fee_id = #{adjustFeeId}
where diff_id = #{diffId}
</update>
<delete id="deleteDiffsByLine">
delete from pay_bill_diff where line_id = #{lineId}
</delete>
<insert id="insertFile" useGeneratedKeys="true" keyProperty="fileId">
insert into pay_bill_file (
bill_id, file_type, invoice_no, invoice_date, amount, tax_amount, amount_net, seller_name, matched_amount,
currency, file_name, file_url, deleted, create_by, create_time
) values (
#{billId}, #{fileType}, #{invoiceNo}, #{invoiceDate}, #{amount}, #{taxAmount}, #{amountNet}, #{sellerName},
ifnull(#{matchedAmount}, 0), #{currency}, #{fileName}, #{fileUrl}, '0', #{createBy}, sysdate()
)
</insert>
<select id="selectFile" resultType="com.bms.price.domain.PayBillFile">
select file_id as fileId, bill_id as billId, file_type as fileType, invoice_no as invoiceNo,
file_name as fileName, file_url as fileUrl, deleted
from pay_bill_file where file_id = #{fileId}
</select>
<update id="markFileDeleted">
update pay_bill_file set deleted = '1' where file_id = #{fileId}
</update>
<insert id="insertApproval">
insert into pay_bill_approval (bill_id, action, opinion, operator_name, create_time)
values (#{billId}, #{action}, #{opinion}, #{operatorName}, sysdate())
</insert>
<select id="selectFileList" resultType="com.bms.price.domain.PayBillFile">
select f.file_id as fileId, f.bill_id as billId, b.bill_no as billNo, b.supplier_name as supplierName,
f.file_type as fileType, f.invoice_no as invoiceNo, f.invoice_date as invoiceDate, f.amount,
f.tax_amount as taxAmount, f.file_name as fileName, f.file_url as fileUrl, f.create_by as createBy,
f.create_time as createTime
from pay_bill_file f
inner join pay_bill b on b.bill_id = f.bill_id
where f.deleted = '0'
<if test="billNo != null and billNo != ''">and b.bill_no like concat('%', #{billNo}, '%')</if>
<if test="supplierName != null and supplierName != ''">and b.supplier_name like concat('%', #{supplierName}, '%')</if>
<if test="invoiceNo != null and invoiceNo != ''">and f.invoice_no like concat('%', #{invoiceNo}, '%')</if>
<if test="fileType != null and fileType != ''">and f.file_type = #{fileType}</if>
order by f.file_id desc
</select>
<select id="countActiveFiles" resultType="int">
select count(*) from pay_bill_file where bill_id = #{billId} and deleted = '0'
</select>
<select id="selectOpenBills" resultType="com.bms.price.domain.PayPaymentAlloc">
select bill_id as billId, bill_no as billNo, currency, supplier_id as supplierId, supplier_name as supplierName,
(total_amount - ifnull(paid_amount, 0)) as openAmount
from pay_bill
where supplier_id = #{supplierId}
and currency = #{currency}
and status in ('CONFIRMED', 'PARTIAL')
and ifnull(bill_kind, 'BLUE') &lt;&gt; 'RED'
and total_amount - ifnull(paid_amount, 0) &gt; 0
order by bill_id
</select>
<insert id="insertLog">
insert into pay_bill_log (bill_id, operation_type, from_status, to_status, operation_desc, operator_name, create_time)
values (#{billId}, #{operationType}, #{fromStatus}, #{toStatus}, #{operationDesc}, #{operatorName}, sysdate())
insert into pay_bill_log (
bill_id, biz_type, biz_id, line_id, fee_id, operation_type, from_status, to_status, operation_desc,
amount_before, amount_after, operator_name, create_time
) values (
#{billId}, #{bizType}, #{bizId}, #{lineId}, #{feeId}, #{operationType}, #{fromStatus}, #{toStatus},
#{operationDesc}, #{amountBefore}, #{amountAfter}, #{operatorName}, sysdate()
)
</insert>
</mapper>