gongchunyi
6 天以前 b3712bb9c618d3cb74b6a200fd83c2ba0577ac3d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?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
        month,
        jTaxAmount,
        xTaxAmount,
        (jTaxAmount - xTaxAmount) AS taxAmount
    FROM (
        SELECT
            month,
            SUM(IF(type = 'purchase', tax_price, 0)) AS xTaxAmount,
            SUM(IF(type = 'sales', tax_price, 0)) AS jTaxAmount
        FROM (
            SELECT
                DATE_FORMAT(issue_date, '%Y-%m') AS month,
                tax_price,
                'sales' AS type
            FROM account_sales_invoice
            WHERE status != 1
            UNION ALL
            SELECT
                DATE_FORMAT(issue_date, '%Y-%m') AS month,
                tax_price,
                'purchase' AS type
            FROM account_purchase_invoice
            WHERE status != 1
        ) AS all_data
    GROUP BY month
    ) AS TT
     <where>
            <if test="month != null">
                and TT.month = #{month}
            </if>
     </where>
    ORDER BY TT.month
    </select>
</mapper>