feat: plugin-rental, support calc tax ,filter by category (#909)

视图更新. 上线后需要线上执行视图sql

Reviewed-on: daoyoucloud/tachybase#909
Reviewed-by: sealday <zhanglin@daoyoucloud.com>
Co-authored-by: bai.zixv <bai.zixv@foxmail.com>
Co-committed-by: bai.zixv <bai.zixv@foxmail.com>
This commit is contained in:
bai.zixv 2024-05-06 18:52:43 +08:00 committed by sealday
parent d64d092dbd
commit e95ce7186c
2 changed files with 15 additions and 6 deletions

View File

@ -0,0 +1,5 @@
---
"@hera/plugin-rental": patch
---
tax, category

View File

@ -1,14 +1,15 @@
-- 增值税计算 -- 增值税计算
CREATE OR REPLACE VIEW CREATE OR REPLACE VIEW
public.view_invoice_tax AS public.view_invoice_tax AS
-- 发票进项表和完税凭证表: 1. 筛选所需字段并统一命名,2. 将发票进项表和完税凭证表, 两个表的数据合并
WITH RECURSIVE WITH RECURSIVE
-- 发票进项表和完税凭证表: 转化数据, 并将发票进项表和完税凭证表, 两个表的数据合并
A_INPUT AS ( A_INPUT AS (
SELECT SELECT
purchaser_id AS company_id, -- 发票进项取购买方公司id,作为本公司id标识 purchaser_id AS company_id, -- 发票进项取购买方公司id,作为本公司id标识
authentication_date AT TIME ZONE 'Asia/Shanghai' AS "date", -- 发票进项取认证日期,作为计算月份的来源 authentication_date AT TIME ZONE 'Asia/Shanghai' AS "date", -- 发票进项取认证日期,作为计算月份的来源
tax_amount, tax_amount,
"state" "state",
category
FROM FROM
invoice_input invoice_input
UNION ALL UNION ALL
@ -16,7 +17,8 @@ WITH RECURSIVE
purchaser_id AS company_id, -- 完税凭证,同发票进项字段 purchaser_id AS company_id, -- 完税凭证,同发票进项字段
authentication_date AT TIME ZONE 'Asia/Shanghai' AS "date", -- 完税凭证,同发票进项字段 authentication_date AT TIME ZONE 'Asia/Shanghai' AS "date", -- 完税凭证,同发票进项字段
tax_amount, tax_amount,
"state" "state",
category
FROM FROM
invoice_receipt invoice_receipt
), ),
@ -26,11 +28,12 @@ WITH RECURSIVE
seller_id AS company_id, -- 发票销项取销售方id,作为本公司id标识 seller_id AS company_id, -- 发票销项取销售方id,作为本公司id标识
"Invoicing_date" AT TIME ZONE 'Asia/Shanghai' AS "date", -- 发票销项取开票日期,作为计算月份的来源 "Invoicing_date" AT TIME ZONE 'Asia/Shanghai' AS "date", -- 发票销项取开票日期,作为计算月份的来源
tax_amount, tax_amount,
"state" "state",
category
FROM FROM
invoice_output invoice_output
), ),
-- 聚合A_INPUT: 1. 按照 company_id 和 date 聚合计算后的月份 "MONTH" 2. 获取对应月份的进项税额 input_tax_amount -- 筛选和聚合A_INPUT: 1. 按照 company_id 和 date 聚合计算后的月份 "MONTH" 2. 获取对应月份的进项税额 input_tax_amount
B_INPUT AS ( B_INPUT AS (
SELECT SELECT
company_id, company_id,
@ -41,11 +44,12 @@ WITH RECURSIVE
WHERE WHERE
"date" >= '2022-01-01' -- 筛选出日期在'2022-01-01'之后的数据 "date" >= '2022-01-01' -- 筛选出日期在'2022-01-01'之后的数据
AND "state" = '1' -- 筛选出所有状态为正常的记录, 正常-1,作废-2 AND "state" = '1' -- 筛选出所有状态为正常的记录, 正常-1,作废-2
AND "category" = '0' -- 筛选出进项发票种类为 0-专用发票; 0-专用发票,1-普通发票;只有专用发票计入增值税计算
GROUP BY GROUP BY
company_id, company_id,
"MONTH" "MONTH"
), ),
-- 聚合B_OUTPUT: 1. 按照 company_id 和 date 聚合计算后的月份 "MONTH" 2. 获取对应月份的销项税额 output_tax_amount -- 筛选和聚合B_OUTPUT: 1. 按照 company_id 和 date 聚合计算后的月份 "MONTH" 2. 获取对应月份的销项税额 output_tax_amount
B_OUTPUT AS ( B_OUTPUT AS (
SELECT SELECT
company_id, company_id,