mysql报表(1)--津贴报表

1. 根据行程的行数来统计津贴,一个行程对应一行津贴,津贴的天数取行程的天数,单价取差旅映射的报表,总价等于天数*单价

SELECT
	final.*,
	final.days * final.price AS allowanceTotal 
FROM
	(
SELECT
	temp.documentId,
	temp.documentNumber,
	temp.applicantDate,
	temp.employeeCode,
	temp.applicantName,
	temp.applicantCompany,
	temp.applicantDepartment,
	temp.t0,
	temp.t3,
	temp.t4,
	temp.t5,
	temp.t9,
	temp.lineCompanyName,
	temp.description,
	temp.fromWhere,
	temp.toWhere,
	temp.startDate,
	temp.endDate,
	temp.days,
	temp.id,
	temp.tr,
	temp.passTime,
	temp1.t_code AS travelType,
	temp1.price As price 
FROM
	(
SELECT
	h.id AS documentId,
	h.requisition_number AS documentNumber,
	h.requisition_date AS applicantDate,
	sct.employee_id AS employeeCode,
	sct.full_name AS applicantName,
	sc.NAME AS applicantCompany,
	sd.NAME AS applicantDepartment,
	(
SELECT
	d.T0code 
FROM
	fec_mdata.sys_department d,
	exp_report_line l 
WHERE
	d.id = l.department_id 
	AND l.exp_report_header_id = h.id 
	LIMIT 1 
	) t0,
	(
SELECT
	d.t3_code 
FROM
	fec_mdata.sys_department d,
	exp_report_line l 
WHERE
	d.id = l.department_id 
	AND l.exp_report_header_id = h.id 
	LIMIT 1 
	) t3,
	(
SELECT
CASE
	l.t4_code 
	WHEN "" THEN
	"*" ELSE l.t4_code 
END 
FROM
	exp_report_line l 
WHERE
	l.exp_report_header_id = h.id 
	LIMIT 1 
	) t4,
	(
SELECT
	e.t5_code 
FROM
	fec_expense.exp_budget_subject e,
	fec_expense.exp_report_oa_line ol,
	fec_expense.exp_report_oa_header oh 
WHERE
	e.budget_account_code = ol.bgt_item_name 
	AND ol.exp_report_oa_header_id = oh.id 
	AND oh.id = h.oa_header_id 
	) t5,
	(
SELECT
	s.t9_code 
FROM
	fec_mdata.sys_company s,
	exp_report_line l 
WHERE
	s.id = l.company_id 
	AND l.exp_report_header_id = h.id 
	LIMIT 1 
	) t9,
	(
SELECT
	scc.`name` 
FROM
	exp_report_line erl,
	fec_mdata.sys_company scc 
WHERE
	erl.exp_report_header_id = h.id 
	AND scc.id = erl.company_id 
	LIMIT 1 
	) lineCompanyName,
	l.description AS description,
	sldl.description AS fromWhere,
	sldl1.description AS toWhere,
	l.travel_date_from AS startDate,
	l.travel_date_to AS endDate,
	l.days AS days,
	l.id AS id,
	(
SELECT
	ol.trpoytvr_number 
FROM
	exp_report_oa_line ol,
	exp_report_line erl 
WHERE
	erl.oa_line_id = ol.id 
	AND erl.exp_report_header_id = h.id 
	AND ol.trpoytvr_number IS NOT NULL 
	LIMIT 1 
	) tr,
	DATE_FORMAT( h.completion_date, '%Y-%m-%d' ) AS passTime,
	oh.task_id
FROM
	exp_report_travel_appl l 
	join exp_report_header h on l.exp_report_header_id = h.id  	AND h.`status` IN ( '1004' ) 
	join exp_report_oa_header oh on h.oa_header_id=oh.id
	join fec_mdata.sys_company sc on  h.company_id = sc.id 
	join fec_mdata.sys_department sd on  sd.id = h.department_id
	join fec_mdata.sys_contact sct on h.applicant_id = sct.user_id
	join fec_mdata.sys_location sld on l.loction_to_id = sld.id 
	join fec_mdata.sys_location_detail sldl on sld.CODE = sldl.CODE
	join fec_mdata.sys_location sld1 on l.loction_to_id = sld1.id
	join fec_mdata.sys_location_detail sldl1 on  sld1.CODE = sldl1.CODE
WHERE
	 sldl.`language` = 'zh_cn'  
	AND sldl1.`language` = 'zh_cn' 
	AND sct.employee_id NOT IN ( '10001', '10000', '00008', '05215', '05246', '00393', '05260', '05296', '01607', '01267' ) 
	) temp 
	left JOIN 
(
SELECT
	al.task_id,
	em.price,
	em.t_code 
FROM
	 exp_oa_appl_header al 
	JOIN exp_travel_mapping em ON al.travel_type1 = em.travel_type1 
	AND IF (ISNULL(al.travel_type2) || LENGTH(trim(al.travel_type2))<1,"0",al.travel_type2) = IF (ISNULL(em.travel_type2) || LENGTH(trim(em.travel_type2))<1,"0",em.travel_type2)
	 AND IF (ISNULL(al.travel_type3) || LENGTH(trim(al.travel_type3))<1,"0",al.travel_type3) = IF (ISNULL(em.travel_type3) || LENGTH(trim(em.travel_type3))<1,"0",em.travel_type3)
	) temp1 ON temp1.task_id = temp.task_id
	) final
WHERE
 not EXISTS(select * from  exp_report_line rl where final.documentId=rl.exp_report_header_id AND  rl.expense_type_code  IN ( 'XL34010' ) )
 and	final.documentId IS NOT NULL

发布了53 篇原创文章 · 获赞 45 · 访问量 8853

猜你喜欢

转载自blog.csdn.net/qq_33036061/article/details/104049039