maven
6 天以前 897acda0bb8c0bcd9511d62fad24060609669d35
src/main/resources/mapper/purchase/InvoicePurchaseMapper.xml
@@ -6,26 +6,48 @@
    <select id="selectPurchaseReport" resultType="com.ruoyi.purchase.dto.InvoicePurchaseReportDto">
        select sl.customer_contract_no,
               sl.customer_name,
               sl.project_name,
               sl.contract_amount,
               pl.contract_amount as purchase_amount,
               sum(slp.tax_exclusive_total_price) as sale_tax_exclusive_total_price,
               sum(pr.tax_exclusive_total_price) as tax_exclusive_total_price,
               (sl.contract_amount-pl.contract_amount) as balance,
        CONCAT(FORMAT((sl.contract_amount - pl.contract_amount) / sl.contract_amount * 100, 2), '%') AS balance_ratio,
               sl.contract_amount-sum(slp.tax_exclusive_total_price)-(pl.contract_amount-sum(pr.tax_exclusive_total_price)) as balance_amount
        from purchase_ledger pl
                 left join sales_ledger sl on pl.sales_ledger_id = sl.id
                 left join product_record pr on pr.purchase_ledger_id = pl.id
                 left join sales_ledger_product slp on slp.sales_ledger_id = sl.id
        group by sl.customer_contract_no, sl.customer_name, sl.project_name, sl.contract_amount, pl.contract_amount
        having sl.customer_contract_no is not null
        SELECT
        A.*,
        FORMAT(A.sales_tax_amount - A.purchase_tax_amount, 2) AS balance_amount
        FROM (
        SELECT
        sl.customer_contract_no,
        sl.id,
        pl.id AS pl_id,
        sl.customer_name,
        sl.project_name,
        slp.tax_inclusive_total_price - slp.tax_exclusive_total_price AS contract_amount,
        SUM(slp1.tax_inclusive_total_price - slp1.tax_exclusive_total_price) AS purchase_amount,
        (slp.tax_exclusive_total_price) / COUNT(slp.id) AS sale_tax_exclusive_total_price,
        SUM(slp1.tax_exclusive_total_price) AS tax_exclusive_total_price,
        (slp.tax_inclusive_total_price - slp.tax_exclusive_total_price) -
        SUM(slp1.tax_inclusive_total_price - slp1.tax_exclusive_total_price) AS balance,
        CONCAT(
        FORMAT(
        ((slp.tax_inclusive_total_price - slp.tax_exclusive_total_price) -
        SUM(slp1.tax_inclusive_total_price - slp1.tax_exclusive_total_price)) /
        (slp.tax_inclusive_total_price - slp.tax_exclusive_total_price) * 100,
        2),
        '%'
        ) AS balance_ratio,
        (slp.tax_inclusive_total_price - slp.tax_exclusive_total_price) AS sales_tax_amount,
        SUM(slp1.tax_inclusive_total_price - slp1.tax_exclusive_total_price) AS purchase_tax_amount
        FROM
        purchase_ledger pl
        LEFT JOIN
        sales_ledger sl ON pl.sales_ledger_id = sl.id
        LEFT JOIN
        sales_ledger_product slp ON slp.sales_ledger_id = sl.id AND slp.type = 1
        LEFT JOIN
        sales_ledger_product slp1 ON slp1.sales_ledger_id = pl.id AND slp1.type = 2
        GROUP BY
        sl.customer_contract_no, sl.customer_name, sl.project_name, sl.id, pl.id
        HAVING
        sl.customer_contract_no IS NOT NULL
        ) A
        <where>
            <if test="c.customerName != null and c.customerName != ''">
                and sl.customer_name like concat('%',#{c.customerName},'%')
                AND A.customer_name LIKE CONCAT('%', #{c.customerName}, '%')
            </if>
        </where>
    </select>
@@ -109,7 +131,7 @@
             )as a
        <where>
            <if test="month != null">
                and a.month = date_format(#{month})
                and a.month = #{month}
            </if>
        </where>
@@ -140,4 +162,4 @@
#         GROUP BY DATE_FORMAT(a.issue_date, '%Y-%m')
    </select>
</mapper>
</mapper>