| | |
| | | |
| | | |
| | | <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 |
| | | sl.sales_contract_no AS customerContractNo, |
| | | sl.customer_name, |
| | | sl.contract_amount AS contract_amount, |
| | | SUM( pl.contract_amount ) AS purchase_amount, |
| | | ( |
| | | sl.contract_amount - SUM( pl.contract_amount )) AS balance, |
| | | CONCAT( ROUND( ( sl.contract_amount - SUM( pl.contract_amount )) / sl.contract_amount * 100, 1 ), '%' ) AS balance_ratio |
| | | FROM |
| | | sales_ledger sl |
| | | INNER JOIN purchase_ledger pl ON sl.sales_contract_no = pl.sales_contract_no |
| | | <where> |
| | | <if test="c.customerName != null and c.customerName != ''"> |
| | | and sl.customer_name like concat('%',#{c.customerName},'%') |
| | | AND sl.customer_name LIKE CONCAT('%', #{c.customerName}, '%') |
| | | </if> |
| | | </where> |
| | | GROUP BY |
| | | sl.sales_contract_no, |
| | | sl.customer_name, |
| | | sl.contract_amount |
| | | ORDER BY |
| | | sl.sales_contract_no |
| | | </select> |
| | | <select id="listVat" resultType="com.ruoyi.purchase.dto.VatDto"> |
| | | select * |
| | |
| | | LEFT JOIN invoice_registration_product pr ON pr.id = il.invoice_registration_product_id |
| | | WHERE il.invoice_no IS NOT NULL |
| | | AND invoice_type = '增专票' |
| | | AND DATE_FORMAT(il.invoice_date, '%Y-%m') IS NOT NULL -- 新增:过滤month为NULL的情 |
| | | GROUP BY DATE_FORMAT(il.invoice_date, '%Y-%m') |
| | | ) a1 |
| | | LEFT JOIN ( |
| | |
| | | LEFT JOIN invoice_registration_product pr ON pr.id = il.invoice_registration_product_id |
| | | WHERE il.invoice_no IS NOT NULL |
| | | AND invoice_type = '增专票' |
| | | AND DATE_FORMAT(il.invoice_date, '%Y-%m') IS NOT NULL -- 新增:过滤month为NULL的情 |
| | | GROUP BY DATE_FORMAT(il.invoice_date, '%Y-%m') |
| | | ) a1 ON a1.month = a2.month |
| | | WHERE a1.month IS NULL |
| | | ORDER BY month |
| | | )as a |
| | | <where> |
| | | a.month is not null |
| | | <if test="month != null"> |
| | | and a.month = #{month} |
| | | </if> |
| | |
| | | # GROUP BY DATE_FORMAT(a.issue_date, '%Y-%m') |
| | | </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> |