| | |
| | | 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 * 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(IF(type = 'purchase', tax_price, 0)) AS xTaxAmount, |
| | | SUM(IF(type = 'sales', tax_price, 0)) AS jTaxAmount |
| | | SUM(jTaxAmount) AS jTaxAmount, |
| | | SUM(xTaxAmount) AS xTaxAmount, |
| | | SUM(jTaxAmount) - SUM(xTaxAmount) AS taxAmount |
| | | FROM ( |
| | | SELECT |
| | | DATE_FORMAT(issue_date, '%Y-%m') AS month, |
| | | tax_price, |
| | | 'sales' AS type |
| | | SUM(tax_price) AS jTaxAmount, |
| | | 0 AS xTaxAmount |
| | | FROM account_sales_invoice |
| | | WHERE status != 1 |
| | | 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, |
| | | tax_price, |
| | | 'purchase' AS type |
| | | 0 AS jTaxAmount, |
| | | SUM(tax_price) AS xTaxAmount |
| | | FROM account_purchase_invoice |
| | | WHERE status != 1 |
| | | ) AS all_data |
| | | GROUP BY month |
| | | ) AS TT |
| | | <where> |
| | | <if test="month != null"> |
| | | and TT.month = #{month} |
| | | WHERE (status IS NULL OR status = 0) |
| | | <if test="year != null and year != ''"> |
| | | AND YEAR(issue_date) = #{year} |
| | | </if> |
| | | </where> |
| | | ORDER BY TT.month |
| | | 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> |