| | |
| | | |
| | | |
| | | <select id="selectPurchaseReport" resultType="com.ruoyi.purchase.dto.InvoicePurchaseReportDto"> |
| | | select A.*, |
| | | FORMAT(A.contract_amount-A.sale_tax_exclusive_total_price-A.purchase_amount+A.tax_exclusive_total_price,2) as balance_amount |
| | | from (select sl.customer_contract_no, |
| | | 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, |
| | | pl.id AS pl_id, |
| | | sl.customer_name, |
| | | sl.project_name, |
| | | sl.contract_amount, |
| | | pl.contract_amount as purchase_amount, |
| | | sum(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, |
| | | (sl.contract_amount - pl.contract_amount) as balance, |
| | | CONCAT(FORMAT((sl.contract_amount - pl.contract_amount) / sl.contract_amount * 100, 2), |
| | | '%') AS balance_ratio |
| | | 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.contract_amount, pl.contract_amount,sl.id,pl.id |
| | | having sl.customer_contract_no is not null) A |
| | | 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> |