liuxiaolong
2019-05-09 0d1d88cdb668e75ea8609417ac18ae19947e9525
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC 
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
 
<hibernate-mapping>
    <sql-query name="IncomeStatementReportQuery">
        <![CDATA[
 
select a1.fisu_sn, a2.year_lei_ji,a3.month_lei_ji from 
fi_subject a1 left join 
(
        SELECT
            fisu_id,
         case when fisu_direction='借' then sum(fivd_debtor_money)
                    when fisu_direction='借' then sum(fivd_creditor_money)
                    else 0.0
            end as year_lei_ji, 0 as month_lei_ji
        FROM
            fi_voucher v
        LEFT JOIN fi_voucher_detail ON fivo_id = fivd_fivo_id
        left join fi_subject on fivd_subject_id=fisu_id
        where 1=1
        and fivo_is_cancle<>'Y'
        and fivo_type<>'初始化'
        and fisu_type='损益类'
        <<and fivo_date<=:endDate>>
        <<and fivo_fiac_id=:fiboId>>
        <<and v.factory_id=:factoryId>>
        group by fisu_id
) a2 on a1.fisu_id=a2.fisu_id
left join 
(
        SELECT
            fisu_id, 0 as year_lei_ji,
         case when fisu_direction='借' then sum(fivd_debtor_money)
                    when fisu_direction='借' then sum(fivd_creditor_money)
                    else 0.0
            end as month_lei_ji
        FROM
            fi_voucher v
        LEFT JOIN fi_voucher_detail ON fivo_id = fivd_fivo_id
        left join fi_subject on fivd_subject_id=fisu_id
        where 1=1
        and fivo_is_cancle<>'Y'
        and fivo_type<>'初始化'
        and fisu_type='损益类'
        <<and fivo_date<=:endDate>>
        <<and fivo_date>=:beginDate>>
        <<and fivo_fiac_id=:fiboId>>
        <<and v.factory_id=:factoryId>>
        group by fisu_id
) a3 on a1.fisu_id=a3.fisu_id
where 1=1
and (a2.year_lei_ji is not null or a3.month_lei_ji is not null)
 
        ]]>
    </sql-query>
</hibernate-mapping>