<?xml version="1.0" encoding="UTF-8"?>
<a:service xmlns:ns1="leaf.application.action" xmlns:p="uncertain.proc" xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script" trace="true">
    <a:init-procedure>
        <s:server-script import="app/app_login_check.js"><![CDATA[
            function prj_project_query() {
                var prj_project_list_details;
                var prj_lease_list_details;
                var prj_bp_list_details;
                var prj_item_list_details;
                try {
                    //申请首页维护
                    var prj_project_list_bm = $bm('app.chart.prj_information_mainten');
                    var prj_project_list_map = prj_project_list_bm.queryAsMap({
                        project_id: $ctx.parameter.project_id,
                        pagesize: $ctx.parameter.pagesize,
                        offsize: $ctx.parameter.offsize,
                        user_id: $ctx.parameter.user_id
                    });
                    prj_project_list_details = prj_project_list_map.getChildren();
                    if($ctx.parameter.project_id){
                    //车辆信息报价信息维护
                    var prj_lease_list_bm = $bm('app.prj_project.project_lease_item_query');
                    var prj_lease_list_map = prj_lease_list_bm.queryAsMap({
                        project_id: $ctx.parameter.project_id,
                        project_lease_item_id: $ctx.parameter.project_lease_item_id
                    });
                    prj_lease_list_details =prj_lease_list_map.getChildren();
                    //客户信息维护
                    var prj_bp_list_bm = $bm('app.prj_project.project_bp_query');
                    var prj_bp_list_map = prj_bp_list_bm.queryAsMap({
                        project_id: $ctx.parameter.project_id,
                        prj_bp_id: $ctx.parameter.prj_bp_id,
                        bp_id: $ctx.parameter.bp_id
                    });
                    prj_bp_list_details =prj_bp_list_map.getChildren();
                    //上传附件查询
                    var prj_item_list_bm = $bm('app.prj_project.get_list_item');
                    var prj_item_list_map = prj_item_list_bm.queryAsMap({
                        document_table:'PRJ_PROJECT',
                        document_id:$ctx.parameter.project_id,
                        cdd_list_id:$ctx.parameter.cdd_list_id
                    });
                    prj_item_list_details =prj_item_list_map.getChildren();
                    }
                    $ctx.parameter.return_status = 'S';
                    $ctx.parameter.return_message = '执行成功';
                } catch (e) {
                    $ctx.success = "true";
                    $ctx.parameter.return_status = 'E';
                    $ctx.parameter.return_message = String(e);
                }
                //返回结果
                var result = {
                    result: $ctx.parameter.return_status,
                    message: $ctx.parameter.return_message,
                    prj_project_list: [],
                    prj_lease_list:[],
                    prj_bp_list:[],
                    prj_item_list:[]
                };
                var prj_project_list = result.prj_project_list;
                if (prj_project_list_details) {
                    //println( bpMaster_list_details.length);
                    for (var i = 0;i < prj_project_list_details.length;i++) {
                        var prj_project_list_detail = prj_project_list_details[i];
                        prj_project_list.push({
                            "project_id": prj_project_list_detail.project_id,
                            "project_number": prj_project_list_detail.project_number,
                            "project_name": prj_project_list_detail.project_name,
                            "project_status": prj_project_list_detail.project_status,
                            "bp_class": prj_project_list_detail.bp_class,
                            "bp_class_n": prj_project_list_detail.bp_class_n,
                            "business_type": prj_project_list_detail.business_type,
                            "business_type_n": prj_project_list_detail.business_type_n,
                            "division": prj_project_list_detail.division,
                            "division_n": prj_project_list_detail.division_n,
                            "car_type": prj_project_list_detail.car_type,
                            "car_type_n": prj_project_list_detail.car_type_n,
                            "finance_amount": prj_project_list_detail.finance_amount,
                            "bp_name": prj_project_list_detail.bp_name,
                            "id_type_n": prj_project_list_detail.id_type_n,
                            "invoice_agent_id": prj_project_list_detail.invoice_agent_id,
                            "invoice_agent_id_n": prj_project_list_detail.invoice_agent_id_n,
                            "cdd_list_id": prj_project_list_detail.cdd_list_id,
                            "create_date": prj_project_list_detail.create_date
                            
                        });
                    }
                }
                
                var prj_lease_list = result.prj_lease_list;
                if (prj_lease_list_details) {
                    for (var i = 0;i < prj_lease_list_details.length;i++) {
                        var prj_lease_list_detail = prj_lease_list_details[i];
                        prj_lease_list.push({
                            "project_lease_item_id": prj_lease_list_detail.project_lease_item_id,
                            "brand_id": prj_lease_list_detail.brand_id,
                            "series_id": prj_lease_list_detail.series_id,
                            "model_id": prj_lease_list_detail.model_id,
                            "brand_id_n": prj_lease_list_detail.brand_id_n,
                            "series_id_n": prj_lease_list_detail.series_id_n,
                            "model_id_n": prj_lease_list_detail.model_id_n,
                            "guide_price": prj_lease_list_detail.guide_price,
                            "guide_price_n": prj_lease_list_detail.guide_price_n,
                            "objective_buy_car": prj_lease_list_detail.objective_buy_car,
                            "objective_buy_car_n": prj_lease_list_detail.objective_buy_car_n,
                            "invoice_price": prj_lease_list_detail.invoice_price,
                            "item_frame_number": prj_lease_list_detail.item_frame_number,
                            "lease_times": prj_lease_list_detail.lease_times,
                            "quotation_id": prj_lease_list_detail.quotation_id,
                            "project_id": prj_lease_list_detail.project_id,
                            "product_name_write": prj_lease_list_detail.product_name_write,
                            "first_amount": prj_lease_list_detail.first_amount,
                            "price_list": prj_lease_list_detail.price_list,
                            "price_list_n": prj_lease_list_detail.price_list_n,
                            "product_plan_id": prj_lease_list_detail.product_plan_id,
                            "product_type": prj_lease_list_detail.product_type,
                            "down_payment_ratio": prj_lease_list_detail.down_payment_ratio,
                            "deposit_ratio": prj_lease_list_detail.deposit_ratio,
                            "balloon_ratio": prj_lease_list_detail.balloon_ratio,
                            "int_rate_display": prj_lease_list_detail.int_rate_display,
                            "lease_charge_ratio": prj_lease_list_detail.lease_charge_ratio,
                            "annual_pay_times": prj_lease_list_detail.annual_pay_times,
                            "annual_pay_times_n": prj_lease_list_detail.annual_pay_times_n,
                            "insurance_price": prj_lease_list_detail.insurance_price,
                            "travel_tax": prj_lease_list_detail.travel_tax,
                            "purchase_tax": prj_lease_list_detail.purchase_tax,
                            "gps_amount": prj_lease_list_detail.gps_amount,
                            "mouth_rental": prj_lease_list_detail.mouth_rental,
                            "finance_amount": prj_lease_list_detail.finance_amount,
                            "down_payment": prj_lease_list_detail.down_payment,
                            "deposit": prj_lease_list_detail.deposit,
                            "lease_charge": prj_lease_list_detail.lease_charge,
                            "balloon": prj_lease_list_detail.balloon
                        });
                    }
                } 
                
                var prj_bp_list=result.prj_bp_list;
                if (prj_bp_list_details) {
                    for (var i = 0;i < prj_bp_list_details.length;i++) {
                        var prj_bp_list_detail = prj_bp_list_details[i];
                        prj_bp_list.push({
                            "prj_bp_id":prj_bp_list_detail.prj_bp_id,
                            "project_id":prj_bp_list_detail.project_id,
                            "bp_id":prj_bp_list_detail.bp_id,
                            "bp_class":prj_bp_list_detail.bp_class,
                            "id_type":prj_bp_list_detail.id_type,
                            "id_type_n":prj_bp_list_detail.id_type_n,
                            "id_card_no":prj_bp_list_detail.id_card_no,
                            "bp_name":prj_bp_list_detail.bp_name,
                            "cell_phone":prj_bp_list_detail.cell_phone,
                            "living_address":prj_bp_list_detail.living_address,
                            "ownship_of_house":prj_bp_list_detail.ownship_of_house,
                            "ownship_of_house_n":prj_bp_list_detail.ownship_of_house_n,
                            "house_loans_flag":prj_bp_list_detail.house_loans_flag,
                            "house_loans_flag_n":prj_bp_list_detail.house_loans_flag_n,
                            "address_on_resident_booklit":prj_bp_list_detail.address_on_resident_booklit,
                            "work_unit":prj_bp_list_detail.work_unit,
                            "work_unit_address":prj_bp_list_detail.work_unit_address,
                            "work_unit_phone":prj_bp_list_detail.work_unit_phone,
                            "position":prj_bp_list_detail.position,
                            "position_n":prj_bp_list_detail.position_n,
                            "card_type_sp":prj_bp_list_detail.card_type_sp,
                            "id_no_sp":prj_bp_list_detail.id_no_sp,
                            "id_no_sp_n":prj_bp_list_detail.id_no_sp_n,
                            "bp_name_sp":prj_bp_list_detail.bp_name_sp,
                            "cell_phone_sp":prj_bp_list_detail.cell_phone_sp,
                            "relationship_sp":prj_bp_list_detail.relationship_sp,
                            "relationship_sp_n":prj_bp_list_detail.relationship_sp_n,
                            "description_others":prj_bp_list_detail.description_others,
                            "description_others_n":prj_bp_list_detail.description_others_n,
                            "living_address_db":prj_bp_list_detail.living_address_db,
                            "resident_addres":prj_bp_list_detail.resident_addres,
                            "industry_sp":prj_bp_list_detail.industry_sp,
                            "work_unit_name_sp":prj_bp_list_detail.work_unit_name_sp,
                            "work_unit_address_sp":prj_bp_list_detail.work_unit_address_sp,
                            "position_sp_n":prj_bp_list_detail.position_sp_n,
                            "position_sp":prj_bp_list_detail.position_sp
                            
                         });
                    }
                }
                 var prj_item_list=result.prj_item_list;
                if (prj_item_list_details) {
                    for (var i = 0;i < prj_item_list_details.length;i++) {
                        var prj_item_list_detail = prj_item_list_details[i];
                        prj_item_list.push({
                            "cdd_item_desc":prj_item_list_detail.cdd_item_desc,
                            "check_id":prj_item_list_detail.check_id,
                            "cdd_item_id":prj_item_list_detail.cdd_item_id
                            });
                    }
                }
                $ctx.parameter.json = JSON.stringify(result);
            }
            if ($ctx.parameter.return_status != 'E' && $ctx.parameter.return_status != 'TIMEOUT') {
                prj_project_query();
            }
        ]]></s:server-script>
    </a:init-procedure>
    <a:service-output output="/parameter/@json"/>
</a:service>