<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: weiwuzhen  
    $Date: 2016-6-21 下午3:16:56  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[select t1.document_id,
       to_char( sum(to_number(t1.principal)),'FM999,999,999,990.00') sum_principal,
      to_char( sum(to_number(t1.interest)),'FM999,999,999,990.00') sum_interest,
      decode( sum(to_number(t1.lease_charge)),0,'0.00',to_char( sum(to_number(t1.lease_charge)),'FM999,999,990,999.00')) sum_lease_charge,
      to_char( sum(to_number(t1.sum_row_amount)),'FM999,999,999,99.00') sum_sum_row_amount
  from (select pq.document_id, --合同ID
               ln.times, --期数
               ln.due_date, --租金支付日
               ln.principal, --租赁成本
               ln.interest, --租赁利息
               ln.lease_charge, --手续费
               to_number(nvl(ln.principal, 0)) +
               to_number(nvl(ln.interest, 0)) +
               to_number(nvl(ln.lease_charge, 0)) sum_row_amount --行合计
          from prj_quotation pq, hls_fin_calculator_ln ln
         where pq.document_category = 'PROJECT'
           and pq.quotation_type = 'MAJOR'
           and pq.main_contract_flag = 'Y'
           and pq.calc_session_id = ln.calc_session_id
           and pq.document_id=${/parameter/@project_id} ) t1
 group by t1.document_id
 ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
