<?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 project_build_query() {
                var company_list_details;
            
                try {
            
                    var bp_class_bm1 = $bm('app.workflow.wfl_basic_query');
                    var bp_class_list_map1 = bp_class_bm1.queryAsMap({
						user_id:$ctx.parameter.user_id,
						project_id: $ctx.parameter.project_id,
                        searchInput: $ctx.parameter.searchInput,
                        pagesize: $ctx.parameter.pagesize,
                        offsize: $ctx.parameter.offsize
                    });
                    company_list_details = bp_class_list_map1.getChildren();
                    
                     var bpMaster_list_bm9 = $bm('app.prj_quotation.quotation_result');
                    
                    var bpMaster_list_map9 = bpMaster_list_bm9.queryAsMap({
                        quotation_id: $ctx.parameter.quotation_id
                    });
                    var  quotation_query_details9 = bpMaster_list_map9.getChildren();
                    
                    
                    
                    //担保人
                     var bpMaster_list_bm = $bm('app.prj_lease_guar_save.prj_guar_query');
                   
                    var bpMaster_list_map = bpMaster_list_bm.queryAsMap({
                        project_id: $ctx.parameter.project_id
                    });
                   var bpMaster_list_details = bpMaster_list_map.getChildren();
                    //联系人查询
                    
                     var bpMaster_list_bm8 = $bm('app.order_request_create.prj_contact_info_query');
                   
                    var bpMaster_list_map8 = bpMaster_list_bm8.queryAsMap({
                        project_id: $ctx.parameter.project_id
                    });
                    var contact_person_details = bpMaster_list_map8.getChildren();
                      //股东信息查询
                    var bpMaster_list_bm11 = $bm('app.order_request_create.prj_project_share_query');
                   
                    var bpMaster_list_map11 = bpMaster_list_bm11.queryAsMap({
                        project_id: $ctx.parameter.project_id
                    });
                    
                   var share_info_details = bpMaster_list_map11.getChildren();
                   
                   
                    //租赁物
                     var bpMaster_list_bm1 = $bm('app.prj_lease_guar_save.prj_lease_query');
                   
                    var bpMaster_list_map1 = bpMaster_list_bm1.queryAsMap({
                        project_id: $ctx.parameter.project_id
                    });
                   var lease_guar_details = bpMaster_list_map1.getChildren();
                    //报价
                     var bpMaster_list_bm2 = $bm('app.prj_quotation.prj_quotation_query');
                    
                    var bpMaster_list_map2 = bpMaster_list_bm2.queryAsMap({
                        project_id: $ctx.parameter.project_id
                    });
                    var  quotation_query_details = bpMaster_list_map2.getChildren();
                    
                   //附件查詢
                   if($ctx.parameter.project_id){
                       var my_wfl_list_bm6 = $bm('app.order_request_create.prj_cdd_item_query1');
                       var my_wfl_list_map6 = my_wfl_list_bm6.queryAsMap({
                        user_id: $ctx.parameter.user_id,
                        project_id:$ctx.parameter.project_id               
                    });
                   var  my_wfl_list_details6 = my_wfl_list_map6.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_guar_query_list: [],
                    prj_lease_query_list: [],
                    prj_quotation_query_list: [],
                    prj_item_list: [],
                    quotation_result_list:[],
                    contact_person_list:[],
                    share_info_list:[]
                    
                };
                 var share_info_list = result.share_info_list;
                if (share_info_details) {
                    for (var i = 0;i < share_info_details.length;i++) {
                        var share_person_detail = share_info_details[i];
                        share_info_list.push({
                            "name": share_person_detail.name,
                            "share_info_id": share_person_detail.share_info_id,
                            "id_number": share_person_detail.id_number
                        });
                    }
                }
                
                
                   var contact_person_list = result.contact_person_list;
                if (contact_person_details) {
                    for (var i = 0;i < contact_person_details.length;i++) {
                        var contact_person_detail = contact_person_details[i];
                        contact_person_list.push({
                            "contact_person": contact_person_detail.contact_person,
                            "prj_contact_info_id": contact_person_detail.prj_contact_info_id,
                            "cell_phone": contact_person_detail.cell_phone
                        });
                    }
                }
            
                
                
                
                
                
                 if($ctx.parameter.quotation_id){
                    var quotation_result_list = result.quotation_result_list;
                if (quotation_query_details9) {
                    for (var i = 0;i < quotation_query_details9.length;i++) {
                        var my_wfl_list_detail9 = quotation_query_details9[i];
                         quotation_result_list.push({
                        "times": my_wfl_list_detail9.times,
                        "rental": my_wfl_list_detail9.rental,
                        "due_date": my_wfl_list_detail9.due_date,
                        
                        "outstanding_rental_tax_incld": my_wfl_list_detail9.outstanding_rental_tax_incld,
                        "principal": my_wfl_list_detail9.principal,
                        "interest": my_wfl_list_detail9.interest
                          
                    });
                    }
                }
                }
                 
                
                
                if($ctx.parameter.project_id){
                    var prj_item_list = result.prj_item_list;
                if (my_wfl_list_details6) {
                    for (var i = 0;i < my_wfl_list_details6.length;i++) {
                        var my_wfl_list_detail6 = my_wfl_list_details6[i];
                         prj_item_list.push({
                        "cdd_item_desc": my_wfl_list_detail6.cdd_item_desc,
                        "attachment": my_wfl_list_detail6.attach,
                        "check_id": my_wfl_list_detail6.check_id  
                    });
                    }
                }
                }
                 
              
               
                //报价
                 var prj_quotation_query_list = result.prj_quotation_query_list;
                 if(quotation_query_details){
                     for (var i = 0;i < quotation_query_details.length;i++) {
                         var bpmaster_list_deta = quotation_query_details[i];
                         if(bpmaster_list_deta.irr!='#Formula Error!'){
                             
                            prj_quotation_query_list.push({
                            "project_id": bpmaster_list_deta.project_id,
                            "price_list": bpmaster_list_deta.price_list,
                            "quotation_id": bpmaster_list_deta.quotation_id,
								  "price_list_n": bpmaster_list_deta.price_list_n,
								  "lease_times": Number(bpmaster_list_deta.lease_times),
								  "lease_times_n": bpmaster_list_deta.lease_times_n,
								  "annual_pay_times": bpmaster_list_deta.annual_pay_times,
								  "annual_pay_times_n": bpmaster_list_deta.annual_pay_times_n,
								  
								  "notarial_fee_payable": Number(bpmaster_list_deta.notarial_fee_payable),
								  "btb_interest_margin": Number(bpmaster_list_deta.btb_interest_margin),
								  "lease_item_price_agent": Number(bpmaster_list_deta.lease_item_price_agent),
								  "hd_user_col_n06": bpmaster_list_deta.hd_user_col_n06,
								  "btb_fee_after_tax": bpmaster_list_deta.btb_fee_after_tax,
								  "base_rate_type": bpmaster_list_deta.base_rate_type,
								  "base_rate": bpmaster_list_deta.base_rate,
								  
								   "btb_fee_after_tax_n": bpmaster_list_deta.btb_fee_after_tax_n,
								   "lease_start_date": bpmaster_list_deta.lease_start_date,
								    "deposit_deduction_n": bpmaster_list_deta.deposit_deduction_n,
								    "third_party_deposit": Number(bpmaster_list_deta.third_party_deposit),
								    "commission_receivable": Number(bpmaster_list_deta.commission_receivable),
								    "hd_user_col_n13": Number(bpmaster_list_deta.hd_user_col_n13),
								    
								    "financing_cost": bpmaster_list_deta.financing_cost,
								    "irr": Number(bpmaster_list_deta.irr),
								    "hd_user_col_v05": bpmaster_list_deta.hd_user_col_v05,
								    "hd_user_col_v05_n": bpmaster_list_deta.hd_user_col_v05_n,
								    "residual_value": bpmaster_list_deta.residual_value,
								    "promise_to_pay": Number(bpmaster_list_deta.promise_to_pay),
								    
								  
								  "lease_item_amount": Number(bpmaster_list_deta.lease_item_amount),
								  "margin_ratio": Number(bpmaster_list_deta.deposit_ratio),
								  "deposit": Number(bpmaster_list_deta.deposit),
								  "deposit_deduction": bpmaster_list_deta.deposit_deduction,
								  "hd_user_col_n14": Number(bpmaster_list_deta.hd_user_col_n14),
								  "insurance_fee": Number(bpmaster_list_deta.insurance_fee),
								  "hd_user_col_n05": Number(bpmaster_list_deta.hd_user_col_n05),
								  
								  "times_1": bpmaster_list_deta.times_1,
								  "principal_1": bpmaster_list_deta.principal_1,
								  "interest_1": bpmaster_list_deta.interest_1,
								  "discount_limit_1": bpmaster_list_deta.discount_limit_1,
								  "rental_1": bpmaster_list_deta.rental_1,
								  "product_id": bpmaster_list_deta.product_id,
								  "product_id_n": bpmaster_list_deta.product_id_n,
								  "down_payment": bpmaster_list_deta.down_payment,
								  
								  "hd_user_col_v01": bpmaster_list_deta.hd_user_col_v01,
								  "hd_user_col_v01_n": bpmaster_list_deta.hd_user_col_v01_n,
								  "down_payment_ratio": Number(bpmaster_list_deta.down_payment_ratio),
								  "other_fee": Number(bpmaster_list_deta.other_fee),
								  "other_fee3": Number(bpmaster_list_deta.other_fee3),
								  "lease_charge_ratio": Number(bpmaster_list_deta.lease_charge_ratio),
								  "lease_charge": bpmaster_list_deta.lease_charge,
								  "btb_int_rate_implicit": Number(bpmaster_list_deta.int_rate_display)
								                           
                        });  
                         }else{
                              prj_quotation_query_list.push({
                            "project_id": bpmaster_list_deta.project_id,
                            "price_list": bpmaster_list_deta.price_list,
                            "quotation_id": bpmaster_list_deta.quotation_id,
								  "price_list_n": bpmaster_list_deta.price_list_n,
								  "lease_times": Number(bpmaster_list_deta.lease_times),
								  "lease_times_n": bpmaster_list_deta.lease_times_n,
								  "annual_pay_times": bpmaster_list_deta.annual_pay_times,
								  "annual_pay_times_n": bpmaster_list_deta.annual_pay_times_n,
								  
								  "notarial_fee_payable": Number(bpmaster_list_deta.notarial_fee_payable),
								  "btb_interest_margin": Number(bpmaster_list_deta.btb_interest_margin),
								  "lease_item_price_agent": Number(bpmaster_list_deta.lease_item_price_agent),
								  "hd_user_col_n06": bpmaster_list_deta.hd_user_col_n06,
								  "btb_fee_after_tax": bpmaster_list_deta.btb_fee_after_tax,
								  "base_rate_type": bpmaster_list_deta.base_rate_type,
								  "base_rate": bpmaster_list_deta.base_rate,
								  
								   "btb_fee_after_tax_n": bpmaster_list_deta.btb_fee_after_tax_n,
								   "lease_start_date": bpmaster_list_deta.lease_start_date,
								    "deposit_deduction_n": bpmaster_list_deta.deposit_deduction_n,
								    "third_party_deposit": Number(bpmaster_list_deta.third_party_deposit),
								    "commission_receivable": Number(bpmaster_list_deta.commission_receivable),
								    "hd_user_col_n13": Number(bpmaster_list_deta.hd_user_col_n13),
								    
								    "financing_cost": bpmaster_list_deta.financing_cost,
								    "irr": bpmaster_list_deta.irr,
								    "hd_user_col_v05": bpmaster_list_deta.hd_user_col_v05,
								    "hd_user_col_v05_n": bpmaster_list_deta.hd_user_col_v05_n,
								    "residual_value": bpmaster_list_deta.residual_value,
								    "promise_to_pay": Number(bpmaster_list_deta.promise_to_pay),
								    
								  
								  "lease_item_amount": Number(bpmaster_list_deta.lease_item_amount),
								  "margin_ratio": Number(bpmaster_list_deta.deposit_ratio),
								  "deposit": Number(bpmaster_list_deta.deposit),
								  "deposit_deduction": bpmaster_list_deta.deposit_deduction,
								  "hd_user_col_n14": Number(bpmaster_list_deta.hd_user_col_n14),
								  "insurance_fee": Number(bpmaster_list_deta.insurance_fee),
								  "hd_user_col_n05": Number(bpmaster_list_deta.hd_user_col_n05),
								  
								  "times_1": bpmaster_list_deta.times_1,
								  "principal_1": bpmaster_list_deta.principal_1,
								  "interest_1": bpmaster_list_deta.interest_1,
								  "discount_limit_1": bpmaster_list_deta.discount_limit_1,
								  "rental_1": bpmaster_list_deta.rental_1,
								  "product_id": bpmaster_list_deta.product_id,
								  "product_id_n": bpmaster_list_deta.product_id_n,
								  "down_payment": bpmaster_list_deta.down_payment,
								  
								  "hd_user_col_v01": bpmaster_list_deta.hd_user_col_v01,
								  "hd_user_col_v01_n": bpmaster_list_deta.hd_user_col_v01_n,
								  "down_payment_ratio": Number(bpmaster_list_deta.down_payment_ratio),
								  "other_fee": Number(bpmaster_list_deta.other_fee),
								  "other_fee3": Number(bpmaster_list_deta.other_fee3),
								  "lease_charge_ratio": Number(bpmaster_list_deta.lease_charge_ratio),
								  "lease_charge": bpmaster_list_deta.lease_charge,
								  "btb_int_rate_implicit": Number(bpmaster_list_deta.int_rate_display)
								                           
                        });
                             
                             
                         }
                         
                       
                    }
                 }
                    
                
                //租赁物
                 var prj_lease_query_list = result.prj_lease_query_list;
                
              if (lease_guar_details) {
                    for (var i = 0;i < lease_guar_details.length;i++) {
                         var bpmaster_list_detai = lease_guar_details[i];
                        prj_lease_query_list.push({
                            
                            "guide_price": Number(bpmaster_list_detai.guide_price),
                            "insurance_price": Number(bpmaster_list_detai.insurance_price),
                            "gps_amount": Number(bpmaster_list_detai.gps_amount),
                            "purchase_tax":Number(bpmaster_list_detai.purchase_tax),
                            
        					"quantity": bpmaster_list_detai.quantity,
                            "project_id": bpmaster_list_detai.project_id,
                            "gps_flag": bpmaster_list_detai.gps_flag,
                           
                            "energy_type_n": bpmaster_list_detai.energy_type_n,
                            "bus_type_n": bpmaster_list_detai.bus_type_n,
    
        				    "model_id_n": bpmaster_list_detai.model_id_n,
                            "truck_class": bpmaster_list_detai.truck_class,
                            "truck_class_n": bpmaster_list_detai.truck_class_n,
                            "bus_type": bpmaster_list_detai.bus_type,
                            "color_of_apprearance": bpmaster_list_detai.color_of_apprearance,
						    "sit_number": bpmaster_list_detai.sit_number,
							"energy_type": bpmaster_list_detai.energy_type,
							"price": Number(bpmaster_list_detai.price),
        
                            "project_lease_item_id": bpmaster_list_detai.project_lease_item_id,
                            "model_id": bpmaster_list_detai.model_id,
                            "series_id_n": bpmaster_list_detai.series_id_n,
                            "series_id": bpmaster_list_detai.series_id,
						    "brand_id_n": bpmaster_list_detai.brand_id_n,
							"brand_id": bpmaster_list_detai.brand_id,
							"vehicle_class": bpmaster_list_detai.vehicle_class,
							"lease_item_seq": Number(bpmaster_list_detai.lease_item_seq)
                        });
                    }
            }
            
                
                 var prj_guar_query_list = result.prj_guar_query_list;
                
              if (bpMaster_list_details) {
                    for (var i = 0;i < bpMaster_list_details.length;i++) {
                         var bpmaster_list_detail = bpMaster_list_details[i];
                        prj_guar_query_list.push({
                            "business_license_num": bpmaster_list_detail.business_license_num,
                            
                            "guaranty_mode": bpmaster_list_detail.guaranty_mode,
                            "guaranty_mode_n": bpmaster_list_detail.guaranty_mode_n,
						    "other_mortgage": bpmaster_list_detail.other_mortgage,
							"other_mortgage_n": bpmaster_list_detail.other_mortgage_n,
							"other_guarantee": bpmaster_list_detail.other_guarantee,
							"bp_class": bpmaster_list_detail.bp_class,
                            
                            "prj_bp_id": String(bpmaster_list_detail.prj_bp_id),
                            "bp_id_n": bpmaster_list_detail.bp_name,
                            "bp_id": bpmaster_list_detail.bp_id,
                            "id_card_no": bpmaster_list_detail.id_card_no,
						    "work_unit": bpmaster_list_detail.work_unit,
							"founded_date": bpmaster_list_detail.founded_date,
							"project_id": bpmaster_list_detail.project_id,
								  "tax_registry_num": bpmaster_list_detail.tax_registry_num
                        });
                    }
            }
                
          
                var prj_project_list = result.prj_project_list;
                if (company_list_details) {
                    for (var i = 0;i < company_list_details.length;i++) {
                        var bp_class_list_detail1 = company_list_details[i];
                        prj_project_list.push({
                            "liv_city": bp_class_list_detail1.liv_city,
                            "liv_city_n": bp_class_list_detail1.liv_city_n,
                            "liv_district": bp_class_list_detail1.liv_district,
                            "liv_district_n": bp_class_list_detail1.liv_district_n,
                            "work_unit": bp_class_list_detail1.work_unit,
                            
                            "work_unit_phone": bp_class_list_detail1.work_unit_phone,
                            "gender": bp_class_list_detail1.gender,
                            "gender_n": bp_class_list_detail1.gender_n,
                            "id_type": bp_class_list_detail1.id_type,
                            "id_type_n": bp_class_list_detail1.id_type_n,
                            "id_card_no": bp_class_list_detail1.id_card_no,
                            "cell_phone": bp_class_list_detail1.cell_phone,
                            "liv_province": bp_class_list_detail1.liv_province,
                            "liv_province_n": bp_class_list_detail1.liv_province_n,
                            
                            "project_name": bp_class_list_detail1.project_name,
                            "employee_id": bp_class_list_detail1.employee_id,
                            "employee_id_n": bp_class_list_detail1.employee_id_n,
                            "province": bp_class_list_detail1.province,
                            "province_n": bp_class_list_detail1.province_n,
                            "city": bp_class_list_detail1.city,
                            "city_n": bp_class_list_detail1.city_n,
                            "district": bp_class_list_detail1.district,
                            "district_n": bp_class_list_detail1.district_n,
                            
                                 "manager_id": bp_class_list_detail1.manager_id,
                            "manager_id_n": bp_class_list_detail1.manager_id_n,
                            
                            "invoice_agent_id_n": bp_class_list_detail1.invoice_agent_id_n,
                            "invoice_agent_id": bp_class_list_detail1.invoice_agent_id,
                            "car_type_n": bp_class_list_detail1.car_type_n,
                            "car_type": bp_class_list_detail1.car_type,
                            "lease_channel_n": bp_class_list_detail1.lease_channel_n,
                            "lease_channel": bp_class_list_detail1.lease_channel,
                            "business_type_n": bp_class_list_detail1.business_type_n,
                            "business_type": bp_class_list_detail1.business_type,
            
                            
                            "bp_class_n": bp_class_list_detail1.bp_class_n,
                            "bp_class": bp_class_list_detail1.bp_class,
                            "document_type_n": bp_class_list_detail1.document_type_n,
                            "document_type": bp_class_list_detail1.document_type,
                            "project_number": bp_class_list_detail1.project_number,
                            "bp_id_n": bp_class_list_detail1.bp_id_n,
                            "bp_id": bp_class_list_detail1.bp_id,
                            "project_id": bp_class_list_detail1.project_id,
                            
                            "division_n": bp_class_list_detail1.division_n,
                            "create_date": bp_class_list_detail1.create_date,
                            "project_status": bp_class_list_detail1.project_status,
                            "project_status_n": bp_class_list_detail1.project_status_n,
                            "division": bp_class_list_detail1.division,
                            "other_mortgage": bp_class_list_detail1.other_mortgage,
                            "other_mortgage_n": bp_class_list_detail1.other_mortgage_n,
                            
                            "registered_capital": bp_class_list_detail1.registered_capital,
                            "founded_date": bp_class_list_detail1.founded_date,
                            "business_license_num": bp_class_list_detail1.business_license_num,
                            "guaranty_mode": bp_class_list_detail1.guaranty_mode,
                            "guaranty_mode_n": bp_class_list_detail1.guaranty_mode_n,
                            
                            "lease_organization": bp_class_list_detail1.lease_organization,
                            "lease_organization_n": bp_class_list_detail1.lease_organization_n,
                            "unit_id": bp_class_list_detail1.unit_id,
                            "unit_id_n": bp_class_list_detail1.unit_id_n,
                            "register_day": bp_class_list_detail1.register_day,
                            
                            "agent_type": bp_class_list_detail1.agent_type,
                            "agent_type_n": bp_class_list_detail1.agent_type_n,
                            "main_finance": bp_class_list_detail1.main_finance,
                            "contact_person": bp_class_list_detail1.contact_person,
                            
                            "prj_bp_id": bp_class_list_detail1.prj_bp_id,
                            "insurance_or_not": bp_class_list_detail1.insurance_or_not,
                            "insurance_or_not_n": bp_class_list_detail1.insurance_or_not_n,
                    
						    "other_mortgage": bp_class_list_detail1.other_mortgage,
							"other_mortgage_n": bp_class_list_detail1.other_mortgage_n,
							"other_guarantee": bp_class_list_detail1.other_guarantee
						
                            
                        });
                    }
                }
            
                $ctx.parameter.json = JSON.stringify(result);
            }
            if ($ctx.parameter.return_status != 'E' && $ctx.parameter.return_status != 'TIMEOUT') {
                project_build_query();
            }
        ]]></s:server-script>
    </a:init-procedure>
    <a:service-output output="/parameter/@json"/>
</a:service>