<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: hty
    $Date: 2018/5/18 13:06
    $Revision: 1.0 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT
                  to_char(o.write_off_date, 'MM') write_off_month,
                  sum(o.write_off_due_amount)     write_off_due_amount,
                  sum(o.write_off_principal)      write_off_principal,
                  sum(o.write_off_interest)       write_off_interest,
                  'PAYMENT'                       write_off_type
                FROM csh_write_off o
                WHERE o.write_off_type IN ('PAYMENT_DEBT', 'PAYMENT_PREPAYMENT')
                      AND o.reversed_flag = 'N'
                      AND to_char(o.write_off_date, 'yyyy') = to_char(sysdate, 'yyyy')
                GROUP BY to_char(o.write_off_date, 'MM')
                UNION (SELECT
                         to_char(o.write_off_date, 'MM') write_off_month,
                         sum(o.write_off_due_amount)     write_off_due_amount,
                         sum(o.write_off_principal)      write_off_principal,
                         sum(o.write_off_interest)       write_off_interest,
                         'RECEIPT'                       write_off_type
                       FROM csh_write_off o
                       WHERE o.write_off_type IN
                             ('RECEIPT_CREDIT',
                              'RECEIPT_ADVANCE_RECEIPT',
                              'RECEIPT_DEPOSIT',
                              'RECEIPT_DEPOSIT_POOL')
                             AND o.reversed_flag = 'N'
                             AND TO_CHAR(o.write_off_date, 'yyyy') = to_char(sysdate, 'yyyy')
                       GROUP BY to_char(o.write_off_date, 'MM'))
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="write_off_month" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="write_off_due_amount" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="write_off_principal" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="write_off_interest" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="write_off_type" databaseType="VARCHAR2" datatype="java.lang.String"/>
    </bm:fields>
</bm:model>
