Files
income_payments_management/db/统计视图.sql
T
2023-12-29 15:28:54 +08:00

972 lines
51 KiB
SQL

create view v_statistical as
select pp.id as projectId,
pp.superId,
pp.projectName,
principalName,
chargeCompanyId,
chargeCompanyTemporaryId,
chargeCompanyTemporaryName,
allMoney,
comeAllMoney,
chargeUse,
depart,
createTime,
if(pp.pack = 0, '否', '是') as packText,
year,
payStatue,
departId,
departCode,
principalNameId,
type,
if(billMoney is null, 0, billMoney) as billMoney,
confirmAmount,
invoiceNoTaxAmount,
paidNoTaxAmount,
confirmNoTaxAmount,
contactsName,
confirmDate,
pp.pack
from (SELECT pwgs.id,
pwg.id as superId,
pwg.working_group_project AS projectName,
pwg.principal_name_a as principalName,
pwgs.charge_company_id AS chargeCompanyId,
pwgs.charge_company_temporary_id as chargeCompanyTemporaryId,
pwgs.charge_company_temporary_name AS chargeCompanyTemporaryName,
pwgs.no_tax_amount as allMoney,
pwgs.paid_amount as comeAllMoney,
pwgs.charge_use as chargeUse,
sd.depart_name as depart,
pwgs.pack as pack,
pwg.year as year,
pwgs.in_account as payStatue,
sd.org_code as departCode,
sd.id as departId,
pwg.principal_id_a as principalNameId,
2 as type,
pwgs.invoice_amount AS billMoney,
confirm_amount as confirmAmount,
invoice_no_tax_amount as invoiceNoTaxAmount,
paid_no_tax_amount as paidNoTaxAmount,
confirm_no_tax_amount as confirmNoTaxAmount,
GROUP_CONCAT(DISTINCT pwgsc.contacts_temporary_name order by pwgsc.contacts_temporary_name) as contactsName,
GROUP_CONCAT(DISTINCT DATE_FORMAT(pcpr.payment_date,'%Y-%m')) as confirmDate,
pwgs.create_time as createTime
FROM pay_working_group pwg
right join pay_working_group_subitem pwgs on (pwg.id = pwgs.working_group_id)
left JOIN sys_user su on (pwg.principal_id_a = su.id)
left join sys_depart sd on (su.depart_ids = sd.id)
left JOIN pay_working_group_subitem_contacts pwgsc on pwgsc.working_group_sub_id = pwgs.id
left join pay_confirm_payment_record pcpr on pwgs.id = pcpr.project_id
group by pwgs.id
union all
SELECT pcp.id,
pcp.id as superId,
pcp.charge_project AS projectName,
pcp.principal_name as principalName,
pcp.charge_company_id AS chargeCompanyId,
pcp.charge_company_temporary_id as chargeCompanyTemporaryId,
pcp.charge_company_temporary_name AS chargeCompanyTemporaryName,
pcp.no_tax_amount as allMoney,
pcp.paid_amount as comeAllMoney,
pcp.charge_use as chargeUse,
sd.depart_name as depart,
pcp.pack as pack,
pcp.year as year,
pcp.in_account as payStatue,
sd.org_code as departCode,
sd.id as departId,
pcp.principal_id as principalNameId,
1 as type,
pcp.invoice_amount AS billMoney,
confirm_amount as confirmAmount,
invoice_no_tax_amount as invoiceNoTaxAmount,
paid_no_tax_amount as paidNoTaxAmount,
confirm_no_tax_amount as confirmNoTaxAmount,
contacts_temporary_name as contactsName,
GROUP_CONCAT(DATE_FORMAT(pcpr.payment_date,'%Y-%m')) as confirmDate,
pcp.create_time as createTime
FROM pay_common_project pcp
left JOIN sys_user su on (pcp.principal_id = su.id)
left join sys_depart sd on (su.depart_ids = sd.id)
left join pay_confirm_payment_record pcpr on pcp.id = pcpr.project_id
group by pcp.id
union all
SELECT pmps.id,
pmp.id as superId,
pmp.project_name AS projectName,
su.realname as principalName,
pmps.company_id AS chargeCompanyId,
pmps.company_id as chargeCompanyTemporaryId,
pmps.company_name AS chargeCompanyTemporaryName,
pmps.no_tax_amount as allMoney,
pmps.paid_amount as comeAllMoney,
pmps.charge_use as chargeUse,
sd.depart_name as depart,
pmps.pack as pack,
pmp.particular_year as year,
pmps.in_account as payStatue,
sd.org_code as departCode,
sd.id as departId,
pmp.director_id as principalNameId,
4 as type,
pmps.invoice_amount AS billMoney,
confirm_amount as confirmAmount,
invoice_no_tax_amount as invoiceNoTaxAmount,
paid_no_tax_amount as paidNoTaxAmount,
confirm_no_tax_amount as confirmNoTaxAmount,
company_contact_name as contactsName,
GROUP_CONCAT(DATE_FORMAT(pcpr.payment_date,'%Y-%m')) as confirmDate,
pmps.create_time as createTime
FROM pay_member_project pmp
right join pay_member_project_subitem pmps on (pmp.id = pmps.project_id)
left JOIN sys_user su on (pmp.director_id = su.id)
left join sys_depart sd on (su.depart_ids = sd.id)
left join pay_confirm_payment_record pcpr on pmps.id = pcpr.project_id
group by pmps.id
union all
SELECT pms.id,
pm.id as superId,
pm.meeting_name AS projectName,
su.realname as principalName,
pms.company_id AS chargeCompanyId,
pms.company_id as chargeCompanyTemporaryId,
pms.company_name AS chargeCompanyTemporaryName,
pms.no_tax_amount as allMoney,
pms.paid_amount as comeAllMoney,
pms.charge_use as chargeUse,
sd.depart_name as depart,
pms.pack as pack,
pm.particular_year as year,
pms.in_account as payStatue,
sd.org_code as departCode,
sd.id as departId,
pm.director_id as principalNameId,
3 as type,
pms.invoice_amount AS billMoney,
confirm_amount as confirmAmount,
invoice_no_tax_amount as invoiceNoTaxAmount,
paid_no_tax_amount as paidNoTaxAmount,
confirm_no_tax_amount as confirmNoTaxAmount,
company_contact_name as contactsName,
GROUP_CONCAT(DATE_FORMAT(pcpr.payment_date,'%Y-%m')) as confirmDate,
pms.create_time as createTime
FROM pay_meeting pm
right join pay_meeting_situation pms on (pm.id = pms.meeting_id)
left JOIN sys_user su on (pm.director_id = su.id)
left join sys_depart sd on (su.depart_ids = sd.id)
left join pay_confirm_payment_record pcpr on pms.id = pcpr.project_id
group by pms.id
union all
SELECT tmps.id,
tmp.id as superId,
tmp.project_name AS projectName,
su.realname as principalName,
tmps.company_id AS chargeCompanyId,
tmps.company_id as chargeCompanyTemporaryId,
tmps.company_name AS chargeCompanyTemporaryName,
tmps.no_tax_amount as allMoney,
tmps.paid_amount as comeAllMoney,
tmps.charge_use as chargeUse,
sd.depart_name as depart,
tmps.pack as pack,
tmp.year as year,
tmps.in_account as payStatue,
sd.org_code as departCode,
sd.id as departId,
tmp.director_id as principalNameId,
5 as type,
tmps.invoice_amount AS billMoney,
confirm_amount as confirmAmount,
invoice_no_tax_amount as invoiceNoTaxAmount,
paid_no_tax_amount as paidNoTaxAmount,
confirm_no_tax_amount as confirmNoTaxAmount,
liaison_man as contactsName,
GROUP_CONCAT(DATE_FORMAT(pcpr.payment_date,'%Y-%m')) as confirmDate,
tmps.create_time as createTime
FROM tb_member_project tmp
left join tb_member_project_subitem tmps on (tmp.id = tmps.project_id)
left JOIN sys_user su on (tmp.director_id = su.id)
left join sys_depart sd on (su.depart_ids = sd.id)
left join pay_confirm_payment_record pcpr on tmps.id = pcpr.project_id
group by tmps.id
union all
SELECT tcp.id,
tmp.id as superId,
tmp.project_name AS projectName,
su.realname as principalName,
tcp.company_id AS chargeCompanyId,
tcp.company_id as chargeCompanyTemporaryId,
tcp.company_name AS chargeCompanyTemporaryName,
tcp.no_tax_amount as allMoney,
tcp.paid_amount as comeAllMoney,
tcp.charge_use as chargeUse,
sd.depart_name as depart,
tcp.pack as pack,
tmp.year as year,
tcp.in_account as payStatue,
sd.org_code as departCode,
sd.id as departId,
tmp.director_id as principalNameId,
6 as type,
tcp.invoice_amount AS billMoney,
confirm_amount as confirmAmount,
invoice_no_tax_amount as invoiceNoTaxAmount,
paid_no_tax_amount as paidNoTaxAmount,
confirm_no_tax_amount as confirmNoTaxAmount,
liaison_man as contactsName,
GROUP_CONCAT(DATE_FORMAT(pcpr.payment_date,'%Y-%m')) as confirmDate,
tcp.create_time as createTime
FROM tb_member_project tmp
left join tb_certificate_payment tcp on (tmp.id = tcp.project_id)
left JOIN sys_user su on (tmp.director_id = su.id)
left join sys_depart sd on (su.depart_ids = sd.id)
left join pay_confirm_payment_record pcpr on tcp.id = pcpr.project_id
group by tcp.id
) pp
where pp.allMoney is not null
and pp.allMoney != 0
order by pp.createTime;
create table pay_confirm_payment_record
(
id varchar(36) not null comment 'id'
primary key,
create_by varchar(50) null comment '创建人',
create_time datetime null comment '创建日期',
update_by varchar(50) null comment '更新人',
update_time datetime null comment '更新日期',
project_id varchar(50) null comment '项目id',
project_type tinyint(1) null comment '项目类型',
amount_received decimal(12, 2) null comment '到账金额',
payment_date date null comment '到账日期',
remark varchar(200) null comment '备注'
) comment '确认来款记录表';
alter table pay_common_project
add column confirm_amount decimal(12, 2) default 0 null comment '确认金额';
alter table pay_working_group_subitem
add column confirm_amount decimal(12, 2) default 0 null comment '确认金额';
alter table pay_member_project_subitem
add column confirm_amount decimal(12, 2) default 0 null comment '确认金额';
alter table pay_meeting_situation
add column confirm_amount decimal(12, 2) default 0 null comment '确认金额';
alter table tb_member_project_subitem
add column confirm_amount decimal(12, 2) default 0 null comment '确认金额';
alter table tb_certificate_payment
add column confirm_amount decimal(12, 2) default 0 null comment '确认金额';
-- 新增税额和未税金额
alter table pay_payment_record
add column tax decimal(12, 2) default 0 comment '税额',
add column no_tax_amount decimal(12, 2) default 0 comment '未税金额';
alter table pay_mail_bill_project
add column tax decimal(12, 2) default 0 comment '税额',
add column no_tax_amount decimal(12, 2) default 0 comment '未税金额';
alter table pay_confirm_payment_record
add column tax decimal(12, 2) default 0 comment '税额',
add column no_tax_amount decimal(12, 2) default 0 comment '未税金额';
-- 项目增加确认收入状态,税额,未税金额
alter table pay_common_project
add column affirm_income tinyint(1) default 0 comment '确认收入',
add column confirm_no_tax_amount decimal(12, 2) default 0 comment '确认金额未税',
add column confirm_tax decimal(12, 2) default 0 comment '确认金额税额',
add column paid_no_tax_amount decimal(12, 2) default 0 comment '到账金额未税',
add column paid_tax decimal(12, 2) default 0 comment '到账金额税额',
add column invoice_no_tax_amount decimal(12, 2) default 0 comment '开票金额未税',
add column invoice_tax decimal(12, 2) default 0 comment '开票金额税额';
alter table pay_working_group_subitem
add column affirm_income tinyint(1) default 0 comment '确认收入',
add column confirm_no_tax_amount decimal(12, 2) default 0 comment '确认金额未税',
add column confirm_tax decimal(12, 2) default 0 comment '确认金额税额',
add column paid_no_tax_amount decimal(12, 2) default 0 comment '到账金额未税',
add column paid_tax decimal(12, 2) default 0 comment '到账金额税额',
add column invoice_no_tax_amount decimal(12, 2) default 0 comment '开票金额未税',
add column invoice_tax decimal(12, 2) default 0 comment '开票金额税额';
alter table pay_member_project_subitem
add column affirm_income tinyint(1) default 0 comment '确认收入',
add column confirm_no_tax_amount decimal(12, 2) default 0 comment '确认金额未税',
add column confirm_tax decimal(12, 2) default 0 comment '确认金额税额',
add column paid_no_tax_amount decimal(12, 2) default 0 comment '到账金额未税',
add column paid_tax decimal(12, 2) default 0 comment '到账金额税额',
add column invoice_no_tax_amount decimal(12, 2) default 0 comment '开票金额未税',
add column invoice_tax decimal(12, 2) default 0 comment '开票金额税额';
alter table pay_meeting_situation
add column affirm_income tinyint(1) default 0 comment '确认收入',
add column confirm_no_tax_amount decimal(12, 2) default 0 comment '确认金额未税',
add column confirm_tax decimal(12, 2) default 0 comment '确认金额税额',
add column paid_no_tax_amount decimal(12, 2) default 0 comment '到账金额未税',
add column paid_tax decimal(12, 2) default 0 comment '到账金额税额',
add column invoice_no_tax_amount decimal(12, 2) default 0 comment '开票金额未税',
add column invoice_tax decimal(12, 2) default 0 comment '开票金额税额';
alter table tb_member_project_subitem
add column affirm_income tinyint(1) default 0 comment '确认收入',
add column confirm_no_tax_amount decimal(12, 2) default 0 comment '确认金额未税',
add column confirm_tax decimal(12, 2) default 0 comment '确认金额税额',
add column paid_no_tax_amount decimal(12, 2) default 0 comment '到账金额未税',
add column paid_tax decimal(12, 2) default 0 comment '到账金额税额',
add column invoice_no_tax_amount decimal(12, 2) default 0 comment '开票金额未税',
add column invoice_tax decimal(12, 2) default 0 comment '开票金额税额';
alter table tb_certificate_payment
add column affirm_income tinyint(1) default 0 comment '确认收入',
add column confirm_no_tax_amount decimal(12, 2) default 0 comment '确认金额未税',
add column confirm_tax decimal(12, 2) default 0 comment '确认金额税额',
add column paid_no_tax_amount decimal(12, 2) default 0 comment '到账金额未税',
add column paid_tax decimal(12, 2) default 0 comment '到账金额税额',
add column invoice_no_tax_amount decimal(12, 2) default 0 comment '开票金额未税',
add column invoice_tax decimal(12, 2) default 0 comment '开票金额税额';
-- 处理历史数据
update pay_payment_record
set no_tax_amount = amount_received / 1.06,
tax = amount_received - no_tax_amount
where amount_received is not null;
update pay_mail_bill_project
set no_tax_amount = invoice_amount / 1.06,
tax = invoice_amount - no_tax_amount
where invoice_amount is not null;
update pay_confirm_payment_record
set no_tax_amount = amount_received / 1.06,
tax = amount_received - no_tax_amount
where amount_received is not null;
-- 六个项目处理历史数据
update pay_common_project
set confirm_no_tax_amount = confirm_amount / 1.06,
paid_no_tax_amount = paid_amount / 1.06,
invoice_no_tax_amount = invoice_amount / 1.06,
confirm_tax = confirm_amount - confirm_no_tax_amount,
paid_tax = paid_amount - paid_no_tax_amount,
invoice_tax = invoice_amount - invoice_no_tax_amount
where need_invoice != 0;
update pay_working_group_subitem
set confirm_no_tax_amount = confirm_amount / 1.06,
paid_no_tax_amount = paid_amount / 1.06,
invoice_no_tax_amount = invoice_amount / 1.06,
confirm_tax = confirm_amount - confirm_no_tax_amount,
paid_tax = paid_amount - paid_no_tax_amount,
invoice_tax = invoice_amount - invoice_no_tax_amount
where need_invoice != 0;
update pay_member_project_subitem
set confirm_no_tax_amount = confirm_amount / 1.06,
paid_no_tax_amount = paid_amount / 1.06,
invoice_no_tax_amount = invoice_amount / 1.06,
confirm_tax = confirm_amount - confirm_no_tax_amount,
paid_tax = paid_amount - paid_no_tax_amount,
invoice_tax = invoice_amount - invoice_no_tax_amount
where need_invoice != 0;
update pay_meeting_situation
set confirm_no_tax_amount = confirm_amount / 1.06,
paid_no_tax_amount = paid_amount / 1.06,
invoice_no_tax_amount = invoice_amount / 1.06,
confirm_tax = confirm_amount - confirm_no_tax_amount,
paid_tax = paid_amount - paid_no_tax_amount,
invoice_tax = invoice_amount - invoice_no_tax_amount
where need_invoice != 0;
update tb_member_project_subitem
set confirm_no_tax_amount = confirm_amount / 1.06,
paid_no_tax_amount = paid_amount / 1.06,
invoice_no_tax_amount = invoice_amount / 1.06,
confirm_tax = confirm_amount - confirm_no_tax_amount,
paid_tax = paid_amount - paid_no_tax_amount,
invoice_tax = invoice_amount - invoice_no_tax_amount
where invoice_requirements != 0;
update tb_certificate_payment
set confirm_no_tax_amount = confirm_amount / 1.06,
paid_no_tax_amount = paid_amount / 1.06,
invoice_no_tax_amount = invoice_amount / 1.06,
confirm_tax = confirm_amount - confirm_no_tax_amount,
paid_tax = paid_amount - paid_no_tax_amount,
invoice_tax = invoice_amount - invoice_no_tax_amount
where invoice_requirements != 0;
update pay_common_project
set confirm_no_tax_amount = confirm_amount ,
paid_no_tax_amount = paid_amount ,
invoice_no_tax_amount = invoice_amount
where need_invoice = 0;
update pay_working_group_subitem
set confirm_no_tax_amount = confirm_amount,
paid_no_tax_amount = paid_amount,
invoice_no_tax_amount = invoice_amount
where need_invoice = 0;
update pay_member_project_subitem
set confirm_no_tax_amount = confirm_amount ,
paid_no_tax_amount = paid_amount ,
invoice_no_tax_amount = invoice_amount
where need_invoice = 0;
update pay_meeting_situation
set confirm_no_tax_amount = confirm_amount ,
paid_no_tax_amount = paid_amount ,
invoice_no_tax_amount = invoice_amount
where need_invoice = 0;
update tb_member_project_subitem
set confirm_no_tax_amount = confirm_amount ,
paid_no_tax_amount = paid_amount ,
invoice_no_tax_amount = invoice_amount
where invoice_requirements = 0;
update tb_certificate_payment
set confirm_no_tax_amount = confirm_amount ,
paid_no_tax_amount = paid_amount ,
invoice_no_tax_amount = invoice_amount
where invoice_requirements = 0;
create view v_statistical_confirm as
select pp.id as projectId,
pp.superId,
pp.projectName,
principalName,
chargeCompanyId,
chargeCompanyTemporaryId,
chargeCompanyTemporaryName,
allMoney,
comeAllMoney,
chargeUse,
depart,
createTime,
if(pp.pack = 0, '否', '是') as packText,
year,
payStatue,
departId,
departCode,
principalNameId,
type,
if(billMoney is null, 0, billMoney) as billMoney,
confirmAmount,
invoiceNoTaxAmount,
paidNoTaxAmount,
confirmNoTaxAmount,
contactsName,
confirmDate,
pp.pack
from (SELECT pwgs.id,
pwg.id as superId,
pwg.working_group_project AS projectName,
pwg.principal_name_a as principalName,
pwgs.charge_company_id AS chargeCompanyId,
pwgs.charge_company_temporary_id as chargeCompanyTemporaryId,
pwgs.charge_company_temporary_name AS chargeCompanyTemporaryName,
pwgs.no_tax_amount as allMoney,
pwgs.paid_amount as comeAllMoney,
pwgs.charge_use as chargeUse,
sd.depart_name as depart,
pwgs.pack as pack,
pwg.year as year,
pwgs.in_account as payStatue,
sd.org_code as departCode,
sd.id as departId,
pwg.principal_id_a as principalNameId,
2 as type,
pwgs.invoice_amount AS billMoney,
confirm_amount as confirmAmount,
invoice_no_tax_amount as invoiceNoTaxAmount,
paid_no_tax_amount as paidNoTaxAmount,
pcpr.no_tax_amount as confirmNoTaxAmount,
(select GROUP_CONCAT(DISTINCT pwgsc.contacts_temporary_name order by pwgsc.contacts_temporary_name) from pay_working_group_subitem_contacts pwgsc where pwgsc.working_group_sub_id = pwgs.id) as contactsName,
DATE_FORMAT(pcpr.payment_date,'%Y-%m') as confirmDate,
pwgs.create_time as createTime
FROM pay_working_group pwg
right join pay_working_group_subitem pwgs on (pwg.id = pwgs.working_group_id)
left JOIN sys_user su on (pwg.principal_id_a = su.id)
left join sys_depart sd on (su.depart_ids = sd.id)
left JOIN pay_working_group_subitem_contacts pwgsc on pwgsc.working_group_sub_id = pwgs.id
left join pay_confirm_payment_record pcpr on pwgs.id = pcpr.project_id
group by pwgs.id,pcpr.id
union all
SELECT pcp.id,
pcp.id as superId,
pcp.charge_project AS projectName,
pcp.principal_name as principalName,
pcp.charge_company_id AS chargeCompanyId,
pcp.charge_company_temporary_id as chargeCompanyTemporaryId,
pcp.charge_company_temporary_name AS chargeCompanyTemporaryName,
pcp.no_tax_amount as allMoney,
pcp.paid_amount as comeAllMoney,
pcp.charge_use as chargeUse,
sd.depart_name as depart,
pcp.pack as pack,
pcp.year as year,
pcp.in_account as payStatue,
sd.org_code as departCode,
sd.id as departId,
pcp.principal_id as principalNameId,
1 as type,
pcp.invoice_amount AS billMoney,
confirm_amount as confirmAmount,
invoice_no_tax_amount as invoiceNoTaxAmount,
paid_no_tax_amount as paidNoTaxAmount,
pcpr.no_tax_amount as confirmNoTaxAmount,
contacts_temporary_name as contactsName,
DATE_FORMAT(pcpr.payment_date,'%Y-%m') as confirmDate,
pcp.create_time as createTime
FROM pay_common_project pcp
left JOIN sys_user su on (pcp.principal_id = su.id)
left join sys_depart sd on (su.depart_ids = sd.id)
left join pay_confirm_payment_record pcpr on pcp.id = pcpr.project_id
group by pcp.id,pcpr.id
union all
SELECT pmps.id,
pmp.id as superId,
pmp.project_name AS projectName,
su.realname as principalName,
pmps.company_id AS chargeCompanyId,
pmps.company_id as chargeCompanyTemporaryId,
pmps.company_name AS chargeCompanyTemporaryName,
pmps.no_tax_amount as allMoney,
pmps.paid_amount as comeAllMoney,
pmps.charge_use as chargeUse,
sd.depart_name as depart,
pmps.pack as pack,
pmp.particular_year as year,
pmps.in_account as payStatue,
sd.org_code as departCode,
sd.id as departId,
pmp.director_id as principalNameId,
4 as type,
pmps.invoice_amount AS billMoney,
confirm_amount as confirmAmount,
invoice_no_tax_amount as invoiceNoTaxAmount,
paid_no_tax_amount as paidNoTaxAmount,
pcpr.no_tax_amount as confirmNoTaxAmount,
company_contact_name as contactsName,
DATE_FORMAT(pcpr.payment_date,'%Y-%m') as confirmDate,
pmps.create_time as createTime
FROM pay_member_project pmp
right join pay_member_project_subitem pmps on (pmp.id = pmps.project_id)
left JOIN sys_user su on (pmp.director_id = su.id)
left join sys_depart sd on (su.depart_ids = sd.id)
left join pay_confirm_payment_record pcpr on pmps.id = pcpr.project_id
group by pmps.id,pcpr.id
union all
SELECT pms.id,
pm.id as superId,
pm.meeting_name AS projectName,
su.realname as principalName,
pms.company_id AS chargeCompanyId,
pms.company_id as chargeCompanyTemporaryId,
pms.company_name AS chargeCompanyTemporaryName,
pms.no_tax_amount as allMoney,
pms.paid_amount as comeAllMoney,
pms.charge_use as chargeUse,
sd.depart_name as depart,
pms.pack as pack,
pm.particular_year as year,
pms.in_account as payStatue,
sd.org_code as departCode,
sd.id as departId,
pm.director_id as principalNameId,
3 as type,
pms.invoice_amount AS billMoney,
confirm_amount as confirmAmount,
invoice_no_tax_amount as invoiceNoTaxAmount,
paid_no_tax_amount as paidNoTaxAmount,
pcpr.no_tax_amount as confirmNoTaxAmount,
company_contact_name as contactsName,
DATE_FORMAT(pcpr.payment_date,'%Y-%m') as confirmDate,
pms.create_time as createTime
FROM pay_meeting pm
right join pay_meeting_situation pms on (pm.id = pms.meeting_id)
left JOIN sys_user su on (pm.director_id = su.id)
left join sys_depart sd on (su.depart_ids = sd.id)
left join pay_confirm_payment_record pcpr on pms.id = pcpr.project_id
group by pms.id,pcpr.id
union all
SELECT tmps.id,
tmp.id as superId,
tmp.project_name AS projectName,
su.realname as principalName,
tmps.company_id AS chargeCompanyId,
tmps.company_id as chargeCompanyTemporaryId,
tmps.company_name AS chargeCompanyTemporaryName,
tmps.no_tax_amount as allMoney,
tmps.paid_amount as comeAllMoney,
tmps.charge_use as chargeUse,
sd.depart_name as depart,
tmps.pack as pack,
tmp.year as year,
tmps.in_account as payStatue,
sd.org_code as departCode,
sd.id as departId,
tmp.director_id as principalNameId,
5 as type,
tmps.invoice_amount AS billMoney,
confirm_amount as confirmAmount,
invoice_no_tax_amount as invoiceNoTaxAmount,
paid_no_tax_amount as paidNoTaxAmount,
pcpr.no_tax_amount as confirmNoTaxAmount,
liaison_man as contactsName,
DATE_FORMAT(pcpr.payment_date,'%Y-%m') as confirmDate,
tmps.create_time as createTime
FROM tb_member_project tmp
left join tb_member_project_subitem tmps on (tmp.id = tmps.project_id)
left JOIN sys_user su on (tmp.director_id = su.id)
left join sys_depart sd on (su.depart_ids = sd.id)
left join pay_confirm_payment_record pcpr on tmps.id = pcpr.project_id
group by tmps.id,pcpr.id
union all
SELECT tcp.id,
tmp.id as superId,
tmp.project_name AS projectName,
su.realname as principalName,
tcp.company_id AS chargeCompanyId,
tcp.company_id as chargeCompanyTemporaryId,
tcp.company_name AS chargeCompanyTemporaryName,
tcp.no_tax_amount as allMoney,
tcp.paid_amount as comeAllMoney,
tcp.charge_use as chargeUse,
sd.depart_name as depart,
tcp.pack as pack,
tmp.year as year,
tcp.in_account as payStatue,
sd.org_code as departCode,
sd.id as departId,
tmp.director_id as principalNameId,
6 as type,
tcp.invoice_amount AS billMoney,
confirm_amount as confirmAmount,
invoice_no_tax_amount as invoiceNoTaxAmount,
paid_no_tax_amount as paidNoTaxAmount,
pcpr.no_tax_amount as confirmNoTaxAmount,
liaison_man as contactsName,
DATE_FORMAT(pcpr.payment_date,'%Y-%m') as confirmDate,
tcp.create_time as createTime
FROM tb_member_project tmp
left join tb_certificate_payment tcp on (tmp.id = tcp.project_id)
left JOIN sys_user su on (tmp.director_id = su.id)
left join sys_depart sd on (su.depart_ids = sd.id)
left join pay_confirm_payment_record pcpr on tcp.id = pcpr.project_id
group by tcp.id,pcpr.id
) pp
where pp.allMoney is not null
and pp.allMoney != 0
order by pp.createTime;
-- 新增税率
alter table pay_payment_record
add column tax_rate varchar(10) null comment '税率' ;
alter table pay_mail_bill_project
add column tax_rate varchar(10) null comment '税率';
alter table pay_confirm_payment_record
add column tax_rate varchar(10) null comment '税率';
-- 处理历史数据
update pay_payment_record
set tax_rate = ROUND(tax / no_tax_amount, 2);
update pay_mail_bill_project
set tax_rate = ROUND(tax / no_tax_amount, 2);
update pay_confirm_payment_record
set tax_rate = ROUND(tax / no_tax_amount, 2);
-- 新增税率,税额,未税金额
alter table pay_common_project
add column tax_rate varchar(10) null comment '税率',
add column tax decimal(12, 2) default 0 comment '税额',
add column no_tax_amount decimal(12, 2) default 0 comment '未税金额';
alter table pay_working_group_subitem
add column tax_rate varchar(10) null comment '税率',
add column tax decimal(12, 2) default 0 comment '税额',
add column no_tax_amount decimal(12, 2) default 0 comment '未税金额';
alter table pay_member_project_subitem
add column tax_rate varchar(10) null comment '税率',
add column tax decimal(12, 2) default 0 comment '税额',
add column no_tax_amount decimal(12, 2) default 0 comment '未税金额';
alter table pay_meeting_situation
add column tax_rate varchar(10) null comment '税率',
add column tax decimal(12, 2) default 0 comment '税额',
add column no_tax_amount decimal(12, 2) default 0 comment '未税金额';
alter table tb_member_project_subitem
add column tax_rate varchar(10) null comment '税率',
add column tax decimal(12, 2) default 0 comment '税额',
add column no_tax_amount decimal(12, 2) default 0 comment '未税金额';
alter table tb_certificate_payment
add column tax_rate varchar(10) null comment '税率',
add column tax decimal(12, 2) default 0 comment '税额',
add column no_tax_amount decimal(12, 2) default 0 comment '未税金额';
-- 六个项目处理历史数据
update pay_common_project
set tax_rate = 0.06,
no_tax_amount = receivable_amount / 1.06,
tax = receivable_amount - no_tax_amount;
update pay_working_group_subitem
set tax_rate = 0.06,
no_tax_amount = receivable_amount / 1.06,
tax = receivable_amount - no_tax_amount;
update pay_member_project_subitem
set tax_rate = 0.06,
no_tax_amount = amount_receivable / 1.06,
tax = amount_receivable - no_tax_amount;
update pay_meeting_situation
set tax_rate = 0.06,
no_tax_amount = amount_receivable / 1.06,
tax = amount_receivable - no_tax_amount;
update tb_member_project_subitem
set tax_rate = 0.06,
no_tax_amount = amount_receivable / 1.06,
tax = amount_receivable - no_tax_amount;
update tb_certificate_payment
set tax_rate = 0.06,
no_tax_amount = amount_receivable / 1.06,
tax = amount_receivable - no_tax_amount;
INSERT INTO `sys_dict` (`id`, `dict_name`, `dict_code`, `description`, `del_flag`, `create_by`, `create_time`, `update_by`, `update_time`, `type`) VALUES ('1587319627974107138', '税率', 'rate', '', 0, 'LKGLZ', '2022-11-01 13:44:25', NULL, NULL, 0);
INSERT INTO `sys_dict_item` (`id`, `dict_id`, `item_text`, `item_value`, `description`, `sort_order`, `status`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES ('1587319749470511105', '1587319627974107138', '0%', '0.00', '', 1.00, 1, 'LKGLZ', '2022-11-01 13:44:54', 'LKGLZ', '2022-11-08 10:15:59');
INSERT INTO `sys_dict_item` (`id`, `dict_id`, `item_text`, `item_value`, `description`, `sort_order`, `status`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES ('1587319787034697729', '1587319627974107138', '1%', '0.01', '', 2.00, 1, 'LKGLZ', '2022-11-01 13:45:03', 'LKGLZ', '2022-11-01 13:53:35');
INSERT INTO `sys_dict_item` (`id`, `dict_id`, `item_text`, `item_value`, `description`, `sort_order`, `status`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES ('1587319809780408322', '1587319627974107138', '3%', '0.03', '', 3.00, 1, 'LKGLZ', '2022-11-01 13:45:08', NULL, NULL);
INSERT INTO `sys_dict_item` (`id`, `dict_id`, `item_text`, `item_value`, `description`, `sort_order`, `status`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES ('1587319860594401282', '1587319627974107138', '5%', '0.05', '', 4.00, 1, 'LKGLZ', '2022-11-01 13:45:20', 'LKGLZ', '2022-11-01 13:54:17');
INSERT INTO `sys_dict_item` (`id`, `dict_id`, `item_text`, `item_value`, `description`, `sort_order`, `status`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES ('1587319889472184321', '1587319627974107138', '6%', '0.06', '', 5.00, 1, 'LKGLZ', '2022-11-01 13:45:27', 'LKGLZ', '2022-11-01 13:54:11');
INSERT INTO `sys_dict_item` (`id`, `dict_id`, `item_text`, `item_value`, `description`, `sort_order`, `status`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES ('1587319930505060354', '1587319627974107138', '9%', '0.09', '', 6.00, 1, 'LKGLZ', '2022-11-01 13:45:37', 'LKGLZ', '2022-11-01 13:54:06');
INSERT INTO `sys_dict_item` (`id`, `dict_id`, `item_text`, `item_value`, `description`, `sort_order`, `status`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES ('1587319992635285506', '1587319627974107138', '13%', '0.13', '', 7.00, 1, 'LKGLZ', '2022-11-01 13:45:52', 'LKGLZ', '2022-11-01 13:54:02');
INSERT INTO `sys_dict_item` (`id`, `dict_id`, `item_text`, `item_value`, `description`, `sort_order`, `status`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES ('1587320050650898434', '1587319627974107138', '19%欧洲', '0.19', '', 8.00, 1, 'LKGLZ', '2022-11-01 13:46:06', 'LKGLZ', '2022-11-01 13:53:55');
create view v_statistical_all as
select pp.id as projectId,
pp.superId,
pp.projectName,
principalName,
chargeCompanyId,
chargeCompanyTemporaryId,
chargeCompanyTemporaryName,
allMoney,
comeAllMoney,
chargeUse,
depart,
createTime,
if(pp.pack = 0, '否', '是') as packText,
year,
payStatue,
departId,
departCode,
principalNameId,
type,
billMoney as invoiceAmount,
if(billMoney is null, 0, billMoney) as billMoney,
confirmAmount,
invoiceNoTaxAmount,
paidNoTaxAmount,
confirmNoTaxAmount,
contactsName,
confirmDate,
pp.pack
from (SELECT pwgs.id,
pwg.id as superId,
pwg.working_group_project AS projectName,
pwg.principal_name_a as principalName,
pwgs.charge_company_id AS chargeCompanyId,
pwgs.charge_company_temporary_id as chargeCompanyTemporaryId,
pwgs.charge_company_temporary_name AS chargeCompanyTemporaryName,
pwgs.no_tax_amount as allMoney,
pwgs.paid_amount as comeAllMoney,
pwgs.charge_use as chargeUse,
sd.depart_name as depart,
pwgs.pack as pack,
pwg.year as year,
pwgs.in_account as payStatue,
sd.org_code as departCode,
sd.id as departId,
pwg.principal_id_a as principalNameId,
2 as type,
pwgs.invoice_amount AS billMoney,
confirm_amount as confirmAmount,
invoice_no_tax_amount as invoiceNoTaxAmount,
paid_no_tax_amount as paidNoTaxAmount,
confirm_no_tax_amount as confirmNoTaxAmount,
GROUP_CONCAT(DISTINCT pwgsc.contacts_temporary_name order by pwgsc.contacts_temporary_name) as contactsName,
GROUP_CONCAT(DISTINCT DATE_FORMAT(pcpr.payment_date,'%Y-%m')) as confirmDate,
pwgs.create_time as createTime
FROM pay_working_group pwg
right join pay_working_group_subitem pwgs on (pwg.id = pwgs.working_group_id)
left JOIN sys_user su on (pwg.principal_id_a = su.id)
left join sys_depart sd on (su.depart_ids = sd.id)
left JOIN pay_working_group_subitem_contacts pwgsc on pwgsc.working_group_sub_id = pwgs.id
left join pay_confirm_payment_record pcpr on pwgs.id = pcpr.project_id
group by pwgs.id
union all
SELECT pcp.id,
pcp.id as superId,
pcp.charge_project AS projectName,
pcp.principal_name as principalName,
pcp.charge_company_id AS chargeCompanyId,
pcp.charge_company_temporary_id as chargeCompanyTemporaryId,
pcp.charge_company_temporary_name AS chargeCompanyTemporaryName,
pcp.no_tax_amount as allMoney,
pcp.paid_amount as comeAllMoney,
pcp.charge_use as chargeUse,
sd.depart_name as depart,
pcp.pack as pack,
pcp.year as year,
pcp.in_account as payStatue,
sd.org_code as departCode,
sd.id as departId,
pcp.principal_id as principalNameId,
1 as type,
pcp.invoice_amount AS billMoney,
confirm_amount as confirmAmount,
invoice_no_tax_amount as invoiceNoTaxAmount,
paid_no_tax_amount as paidNoTaxAmount,
confirm_no_tax_amount as confirmNoTaxAmount,
contacts_temporary_name as contactsName,
GROUP_CONCAT(DATE_FORMAT(pcpr.payment_date,'%Y-%m')) as confirmDate,
pcp.create_time as createTime
FROM pay_common_project pcp
left JOIN sys_user su on (pcp.principal_id = su.id)
left join sys_depart sd on (su.depart_ids = sd.id)
left join pay_confirm_payment_record pcpr on pcp.id = pcpr.project_id
group by pcp.id
union all
SELECT pmps.id,
pmp.id as superId,
pmp.project_name AS projectName,
su.realname as principalName,
pmps.company_id AS chargeCompanyId,
pmps.company_id as chargeCompanyTemporaryId,
pmps.company_name AS chargeCompanyTemporaryName,
pmps.no_tax_amount as allMoney,
pmps.paid_amount as comeAllMoney,
pmps.charge_use as chargeUse,
sd.depart_name as depart,
pmps.pack as pack,
pmp.particular_year as year,
pmps.in_account as payStatue,
sd.org_code as departCode,
sd.id as departId,
pmp.director_id as principalNameId,
4 as type,
pmps.invoice_amount AS billMoney,
confirm_amount as confirmAmount,
invoice_no_tax_amount as invoiceNoTaxAmount,
paid_no_tax_amount as paidNoTaxAmount,
confirm_no_tax_amount as confirmNoTaxAmount,
company_contact_name as contactsName,
GROUP_CONCAT(DATE_FORMAT(pcpr.payment_date,'%Y-%m')) as confirmDate,
pmps.create_time as createTime
FROM pay_member_project pmp
right join pay_member_project_subitem pmps on (pmp.id = pmps.project_id)
left JOIN sys_user su on (pmp.director_id = su.id)
left join sys_depart sd on (su.depart_ids = sd.id)
left join pay_confirm_payment_record pcpr on pmps.id = pcpr.project_id
group by pmps.id
union all
SELECT pms.id,
pm.id as superId,
pm.meeting_name AS projectName,
su.realname as principalName,
pms.company_id AS chargeCompanyId,
pms.company_id as chargeCompanyTemporaryId,
pms.company_name AS chargeCompanyTemporaryName,
pms.no_tax_amount as allMoney,
pms.paid_amount as comeAllMoney,
pms.charge_use as chargeUse,
sd.depart_name as depart,
pms.pack as pack,
pm.particular_year as year,
pms.in_account as payStatue,
sd.org_code as departCode,
sd.id as departId,
pm.director_id as principalNameId,
3 as type,
pms.invoice_amount AS billMoney,
confirm_amount as confirmAmount,
invoice_no_tax_amount as invoiceNoTaxAmount,
paid_no_tax_amount as paidNoTaxAmount,
confirm_no_tax_amount as confirmNoTaxAmount,
company_contact_name as contactsName,
GROUP_CONCAT(DATE_FORMAT(pcpr.payment_date,'%Y-%m')) as confirmDate,
pms.create_time as createTime
FROM pay_meeting pm
right join pay_meeting_situation pms on (pm.id = pms.meeting_id)
left JOIN sys_user su on (pm.director_id = su.id)
left join sys_depart sd on (su.depart_ids = sd.id)
left join pay_confirm_payment_record pcpr on pms.id = pcpr.project_id
group by pms.id
union all
SELECT tmps.id,
tmp.id as superId,
tmp.project_name AS projectName,
su.realname as principalName,
tmps.company_id AS chargeCompanyId,
tmps.company_id as chargeCompanyTemporaryId,
tmps.company_name AS chargeCompanyTemporaryName,
tmps.no_tax_amount as allMoney,
tmps.paid_amount as comeAllMoney,
tmps.charge_use as chargeUse,
sd.depart_name as depart,
tmps.pack as pack,
tmp.year as year,
tmps.in_account as payStatue,
sd.org_code as departCode,
sd.id as departId,
tmp.director_id as principalNameId,
5 as type,
tmps.invoice_amount AS billMoney,
confirm_amount as confirmAmount,
invoice_no_tax_amount as invoiceNoTaxAmount,
paid_no_tax_amount as paidNoTaxAmount,
confirm_no_tax_amount as confirmNoTaxAmount,
liaison_man as contactsName,
GROUP_CONCAT(DATE_FORMAT(pcpr.payment_date,'%Y-%m')) as confirmDate,
tmps.create_time as createTime
FROM tb_member_project tmp
left join tb_member_project_subitem tmps on (tmp.id = tmps.project_id)
left JOIN sys_user su on (tmp.director_id = su.id)
left join sys_depart sd on (su.depart_ids = sd.id)
left join pay_confirm_payment_record pcpr on tmps.id = pcpr.project_id
group by tmps.id
union all
SELECT tcp.id,
tmp.id as superId,
tmp.project_name AS projectName,
su.realname as principalName,
tcp.company_id AS chargeCompanyId,
tcp.company_id as chargeCompanyTemporaryId,
tcp.company_name AS chargeCompanyTemporaryName,
tcp.no_tax_amount as allMoney,
tcp.paid_amount as comeAllMoney,
tcp.charge_use as chargeUse,
sd.depart_name as depart,
tcp.pack as pack,
tmp.year as year,
tcp.in_account as payStatue,
sd.org_code as departCode,
sd.id as departId,
tmp.director_id as principalNameId,
6 as type,
tcp.invoice_amount AS billMoney,
confirm_amount as confirmAmount,
invoice_no_tax_amount as invoiceNoTaxAmount,
paid_no_tax_amount as paidNoTaxAmount,
confirm_no_tax_amount as confirmNoTaxAmount,
liaison_man as contactsName,
GROUP_CONCAT(DATE_FORMAT(pcpr.payment_date,'%Y-%m')) as confirmDate,
tcp.create_time as createTime
FROM tb_member_project tmp
left join tb_certificate_payment tcp on (tmp.id = tcp.project_id)
left JOIN sys_user su on (tmp.director_id = su.id)
left join sys_depart sd on (su.depart_ids = sd.id)
left join pay_confirm_payment_record pcpr on tcp.id = pcpr.project_id
group by tcp.id
) pp
order by pp.createTime;
create view v_confirm_payment_record as
select project_id,
sum(amount_received) as amount_received,
sum(no_tax_amount) as no_tax_amount,
GROUP_CONCAT(DATE_FORMAT(payment_date, '%Y-%m')) as payment_date
from pay_confirm_payment_record
group by project_id;
create view v_payment_record as
select project_id,
sum(amount_received) as amount_received,
sum(no_tax_amount) as no_tax_amount
from pay_payment_record
group by project_id;
create view v_mail_bill_project as
select project_id,
sum(invoice_amount) as invoice_amount,
sum(no_tax_amount) as no_tax_amount
from pay_mail_bill_project
group by project_id;