<?xml version="1.0" encoding="UTF-8"?>
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
<mapper namespace="com.ruoyi.account.mapper.AccountStatementMapper">
|
|
<select id="listPageAccountStatement" resultType="com.ruoyi.account.bean.vo.StatementAccountVo">
|
SELECT lj.*,
|
<choose>
|
<when test="req.accountType == 1">
|
c.customer_name as customerName
|
</when>
|
<when test="req.accountType == 2">
|
s.supplier_name as customerName
|
</when>
|
<otherwise>
|
'' as customerName
|
</otherwise>
|
</choose>
|
FROM account_statement AS lj
|
<!-- 动态 LEFT JOIN -->
|
<choose>
|
<when test="req.accountType == 1">
|
LEFT JOIN customer AS c
|
ON lj.customer_id = c.id
|
</when>
|
<when test="req.accountType == 2">
|
LEFT JOIN supplier_manage AS s
|
ON lj.customer_id = s.id
|
</when>
|
</choose>
|
WHERE 1=1
|
<if test="req.accountType != null">
|
AND lj.account_type = #{req.accountType}
|
</if>
|
<if test="req.customerId != null">
|
AND lj.customer_id = #{req.customerId}
|
</if>
|
<if test="req.startDate != null and req.endDate != null">
|
AND DATE_FORMAT(CONCAT(lj.statement_month, '-01'), '%Y-%m-%d')
|
BETWEEN #{req.startDate} AND #{req.endDate}
|
</if>
|
ORDER BY lj.statement_month DESC
|
</select>
|
<select id="selectVatDtoPage" resultType="com.ruoyi.purchase.dto.VatDto">
|
SELECT * FROM (
|
SELECT
|
asi.id,
|
asi.invoice_number AS invoiceNumber,
|
asi.issue_date AS issueDate,
|
'sales' AS type,
|
asi.invoice_type AS invoiceType,
|
asi.tax_price AS taxAmount,
|
asi.tax_inclusive_price AS totalAmount,
|
c.customer_name AS customerName,
|
NULL AS supplierName,
|
DATE_FORMAT(asi.issue_date, '%Y-%m') AS month
|
FROM account_sales_invoice asi
|
LEFT JOIN customer c ON c.id = asi.customer_id
|
WHERE (asi.status IS NULL OR asi.status = 0)
|
UNION ALL
|
SELECT
|
api.id,
|
api.invoice_number AS invoiceNumber,
|
api.issue_date AS issueDate,
|
'purchase' AS type,
|
api.invoice_type AS invoiceType,
|
api.tax_price AS taxAmount,
|
api.tax_inclusive_price AS totalAmount,
|
NULL AS customerName,
|
s.supplier_name AS supplierName,
|
DATE_FORMAT(api.issue_date, '%Y-%m') AS month
|
FROM account_purchase_invoice api
|
LEFT JOIN supplier_manage s ON s.id = api.supplier_id
|
WHERE (api.status IS NULL OR api.status = 0)
|
) AS invoice_detail
|
<where>
|
<if test="month != null and month != ''">
|
AND month = #{month}
|
</if>
|
<if test="type != null and type != ''">
|
AND type = #{type}
|
</if>
|
</where>
|
ORDER BY issueDate DESC, type
|
</select>
|
|
<select id="selectVatSummary" resultType="com.ruoyi.purchase.dto.VatSummaryDto">
|
SELECT
|
month,
|
SUM(jTaxAmount) AS jTaxAmount,
|
SUM(xTaxAmount) AS xTaxAmount,
|
SUM(jTaxAmount) - SUM(xTaxAmount) AS taxAmount
|
FROM (
|
SELECT
|
DATE_FORMAT(issue_date, '%Y-%m') AS month,
|
SUM(tax_price) AS jTaxAmount,
|
0 AS xTaxAmount
|
FROM account_sales_invoice
|
WHERE (status IS NULL OR status = 0)
|
<if test="year != null and year != ''">
|
AND YEAR(issue_date) = #{year}
|
</if>
|
GROUP BY DATE_FORMAT(issue_date, '%Y-%m')
|
UNION ALL
|
SELECT
|
DATE_FORMAT(issue_date, '%Y-%m') AS month,
|
0 AS jTaxAmount,
|
SUM(tax_price) AS xTaxAmount
|
FROM account_purchase_invoice
|
WHERE (status IS NULL OR status = 0)
|
<if test="year != null and year != ''">
|
AND YEAR(issue_date) = #{year}
|
</if>
|
GROUP BY DATE_FORMAT(issue_date, '%Y-%m')
|
) t
|
GROUP BY month
|
ORDER BY month
|
</select>
|
|
<select id="listVatDetail" resultType="com.ruoyi.purchase.dto.VatDto">
|
SELECT *
|
FROM (
|
-- 进项税明细(采购订单)
|
SELECT
|
pl.purchase_contract_number AS invoiceNo,
|
pl.sales_contract_no AS salesContractNo,
|
pl.supplier_name AS supplierName,
|
NULL AS customerName,
|
'进项' AS orderType,
|
pl.entry_date AS invoiceDate,
|
slp.tax_rate AS taxRate,
|
ROUND(SUM(slp.tax_inclusive_total_price - slp.tax_exclusive_total_price), 2) AS jTaxAmount,
|
0 AS xTaxAmount,
|
ROUND(SUM(slp.tax_inclusive_total_price - slp.tax_exclusive_total_price), 2) AS taxAmount
|
FROM sales_ledger_product slp
|
LEFT JOIN purchase_ledger pl ON pl.id = slp.sales_ledger_id
|
WHERE slp.type = 2
|
AND slp.tax_rate IS NOT NULL
|
AND slp.tax_rate > 0
|
GROUP BY pl.id
|
|
UNION ALL
|
|
-- 销项税明细(销售订单)
|
SELECT
|
sl.sales_contract_no AS invoiceNo,
|
sl.sales_contract_no AS salesContractNo,
|
NULL AS supplierName,
|
sl.customer_name AS customerName,
|
'销项' AS orderType,
|
sl.entry_date AS invoiceDate,
|
slp.tax_rate AS taxRate,
|
0 AS jTaxAmount,
|
ROUND(SUM(slp.tax_inclusive_total_price - slp.tax_exclusive_total_price), 2) AS xTaxAmount,
|
ROUND(SUM(slp.tax_inclusive_total_price - slp.tax_exclusive_total_price), 2) AS taxAmount
|
FROM sales_ledger_product slp
|
LEFT JOIN sales_ledger sl ON sl.id = slp.sales_ledger_id
|
WHERE slp.type = 1
|
AND slp.tax_rate IS NOT NULL
|
AND slp.tax_rate > 0
|
GROUP BY sl.id
|
) a
|
<where>
|
<if test="month != null and month != ''">
|
AND DATE_FORMAT(a.invoiceDate, '%Y-%m') = #{month}
|
</if>
|
</where>
|
ORDER BY a.invoiceDate DESC
|
</select>
|
</mapper>
|