567 lines
12 KiB
PL/PgSQL
Executable File
567 lines
12 KiB
PL/PgSQL
Executable File
drop function if exists staging2.fn_IHTBTD_BTD_TRX;
|
|
CREATE OR REPLACE FUNCTION staging2.fn_IHTBTD_BTD_TRX(p_client_id int,p_function_id int, p_file_mnemonic text,
|
|
p_file_sheet_mnemonic text, p_file_syspk int)
|
|
RETURNS void
|
|
LANGUAGE plpgsql
|
|
AS $function$
|
|
declare __test_instance_id int;
|
|
declare __client_id int :=p_client_id;
|
|
declare __function_id int :=p_function_id;
|
|
declare __file_mnemonic text :=p_file_mnemonic;
|
|
declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic;
|
|
declare __file_syspk int :=p_file_syspk;
|
|
declare __make text;
|
|
declare __model text;
|
|
declare err_state text;
|
|
declare err_msg text;
|
|
declare err_detail text;
|
|
declare err_hint text;
|
|
declare err_context text;
|
|
declare _error int;
|
|
declare __test_master_id int;
|
|
declare __test_instance_tractor_id int;
|
|
begin
|
|
__file_syspk := p_file_syspk;
|
|
|
|
|
|
/************************************************************
|
|
Function Name:fn_IHTBTD_BTD_TRX
|
|
Function Desc: This function populates data into ODS
|
|
File Format: IHT
|
|
Sheet Format: IHTBTD_BTD
|
|
Creation Date:
|
|
Updation Date:
|
|
Author: compegence team
|
|
Function Call: select staging2.fn_IHTBTD_BTD_TRX()
|
|
***************************************************************/
|
|
insert into transactional.test_instance
|
|
(
|
|
client_id,
|
|
function_id,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic,
|
|
tractor_make,
|
|
tractor_model,
|
|
job_order_no,
|
|
sample_receipt_date,
|
|
test_report_no,
|
|
generation,
|
|
customer_name,
|
|
test_engineer,
|
|
test_report_date,
|
|
no_of_sample,
|
|
test_start_date,
|
|
test_end_date,
|
|
tractor_sr_no,
|
|
test_standard_ref,
|
|
test_location_name,
|
|
test_operator,
|
|
project_group,
|
|
objective_of_test,
|
|
test_condition,
|
|
test_standard_desc,
|
|
test_standard_id,
|
|
acceptance_criteria,
|
|
remarks,
|
|
observations,
|
|
test_purpose
|
|
)
|
|
select
|
|
client_id,
|
|
function_id,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic,
|
|
make,model,
|
|
Test_Request_no,
|
|
sample_receipt_date::Date,
|
|
Test_report_No,
|
|
Generation,
|
|
Customer_Name,
|
|
Test_Engineer,
|
|
Test_Report_Date::Date,
|
|
No_of_Sample,
|
|
Test_Start_Date::Date,
|
|
Test_End_Date::Date,
|
|
Tractor_Sr_No,
|
|
Test_Standard_Refer,
|
|
test_location,
|
|
Operator_Name,
|
|
Project_Group,
|
|
Objective,
|
|
condition,
|
|
test_standard,
|
|
test_standard_id::numeric,
|
|
test_standard_ref
|
|
acceptance_criteria,
|
|
remarks,
|
|
observations,
|
|
test_purpose
|
|
from
|
|
staging2.IHTBTD_BTD_H1_block where trx_record =1;
|
|
|
|
update transactional.test_instance a
|
|
set
|
|
report_prepared_date=to_date(b.prepared_date,'DD-MM-YYYY'),
|
|
report_reviewed_date=to_date(b.reviewed_date,'DD-MM-YYYY'),
|
|
report_approved_date=to_date(b.approved_date,'DD-MM-YYYY'),
|
|
report_prepared_by=b.prepared_by,
|
|
report_reviewed_by=b.reviewed_by,
|
|
report_approved_by=b.approved_by,
|
|
report_template_replaces=b.replaces,
|
|
report_title=b.comments,
|
|
report_template_no=b.rev1,
|
|
report_template_rev_date=b.rev2,
|
|
report_template_rev_no= b.rev3
|
|
from staging2.IHTBTD_BTD_footer_block b
|
|
where a.file_sheet_mnemonic='IHTBTD_BTD' and trx_record =1;
|
|
|
|
|
|
|
|
insert into transactional.test_instance_tyre_info
|
|
(
|
|
client_id,
|
|
function_id,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic,
|
|
tractor_make,
|
|
tractor_model,
|
|
tyre_type,
|
|
tyre_make,
|
|
tyre_size,
|
|
tyre_ply_rating,
|
|
tyre_use_type,
|
|
tyre_pressure_kg_per_cm2
|
|
)
|
|
select
|
|
client_id,
|
|
function_id,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic,
|
|
make,model,
|
|
tyre_details,
|
|
tyre_make,
|
|
tyre_size,
|
|
ply_rating::numeric,
|
|
tyre_use_type,
|
|
pressure_kg_cm2::numeric
|
|
from staging2.IHTBTD_BTD_tyre_details_block where trx_record =1;
|
|
|
|
|
|
|
|
insert into transactional.test_instance_drawbar_info
|
|
(
|
|
client_id,
|
|
function_id,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic,
|
|
tractor_make,
|
|
tractor_model,
|
|
test_condition,
|
|
weight_front_kg,
|
|
weight_rear_kg,
|
|
weight_total_kg,
|
|
status
|
|
)
|
|
select
|
|
client_id,
|
|
function_id,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic,
|
|
make,model,
|
|
test_condition,
|
|
front::numeric ,
|
|
rear::numeric ,
|
|
total::numeric ,
|
|
status
|
|
from staging2.IHTBTD_BTD_weight_block where trx_record =1;
|
|
|
|
|
|
/*block */
|
|
|
|
insert into transactional.test_instance_tractor_info
|
|
(
|
|
client_id,
|
|
function_id,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic,
|
|
tractor_make,
|
|
tractor_model,
|
|
tractor_platform
|
|
)
|
|
select
|
|
client_id,
|
|
function_id,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic,
|
|
make,model,
|
|
platform
|
|
from staging2.IHTBTD_BTD_h1_block where trx_record =1;
|
|
|
|
update transactional.test_instance_tractor_info
|
|
set mahindra_model_yn = (
|
|
case when tractor_make like 'Mahindra%' then 'Y' else 'N' end
|
|
) where file_syspk =__file_syspk;
|
|
|
|
update transactional.test_instance_tractor_info a
|
|
set test_tractor_yn ='Y' where syspk in
|
|
(select min(syspk) from transactional.test_instance_tractor_info b
|
|
where b.file_syspk =a.file_syspk)
|
|
and a.file_syspk =__file_syspk;
|
|
|
|
update transactional.test_instance_tractor_info a
|
|
set
|
|
wheel_drive_type = b.Drive,
|
|
tractor_platform = b.Platform,
|
|
tractor_engine_hp= b.Tractor_power_hp::numeric,
|
|
generation= b.generation,
|
|
domestic_export= b.domestic_export,
|
|
tractor_sr_no = b.tractor_sr_no
|
|
from staging2.IHTBTD_BTD_H1_block b
|
|
where b.trx_record=1
|
|
and a.file_sheet_mnemonic ='IHTBTD_BTD'
|
|
and a.file_syspk =__file_syspk;
|
|
|
|
|
|
insert into transactional.iht_brake_perf_test_results
|
|
(
|
|
client_id,
|
|
function_id,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic,
|
|
tractor_make,
|
|
tractor_model,
|
|
test_condition,
|
|
srl_no,
|
|
trigger_speed_km_per_h,
|
|
brake_control_input_force_kg,
|
|
required_corrected_stopping_distance_m,
|
|
actual_stopping_distance_m,
|
|
deceleration_m_s2_v2_2s,
|
|
observation,
|
|
test_mode
|
|
)
|
|
select
|
|
client_id,
|
|
function_id,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic,
|
|
make,model,
|
|
column2,
|
|
column3::numeric,
|
|
column4::numeric,
|
|
column5::numeric,
|
|
column6::numeric,
|
|
column7::numeric,
|
|
column8::numeric,
|
|
column9,
|
|
column11
|
|
from staging2.IHTBTD_BTD_test_res_1_block where trx_record =1;
|
|
|
|
insert into transactional.iht_brake_perf_test_results
|
|
(
|
|
client_id,
|
|
function_id,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic,
|
|
tractor_make,
|
|
tractor_model,
|
|
test_condition,
|
|
srl_no,
|
|
trigger_speed_km_per_h,
|
|
brake_control_input_force_kg,
|
|
required_corrected_stopping_distance_m,
|
|
actual_stopping_distance_m,
|
|
deceleration_m_s2_v2_2s,
|
|
observation,
|
|
test_mode
|
|
)
|
|
select
|
|
client_id,
|
|
function_id,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic,
|
|
make,model,
|
|
column2,
|
|
column3::numeric,
|
|
column4::numeric,
|
|
column5::numeric,
|
|
column6::numeric,
|
|
column7::numeric,
|
|
column8::numeric,
|
|
column9,
|
|
column11
|
|
from staging2.IHTBTD_BTD_test_res_2_block where trx_record =1;
|
|
|
|
insert into transactional.iht_brake_perf_test_results
|
|
(
|
|
client_id,
|
|
function_id,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic,
|
|
tractor_make,
|
|
tractor_model,
|
|
test_condition,
|
|
srl_no,
|
|
trigger_speed_km_per_h,
|
|
brake_control_input_force_kg,
|
|
required_corrected_stopping_distance_m,
|
|
actual_stopping_distance_m,
|
|
deceleration_m_s2_v2_2s,
|
|
observation,
|
|
test_mode
|
|
)
|
|
select
|
|
client_id,
|
|
function_id,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic,
|
|
make,model,
|
|
column2,
|
|
column3::numeric,
|
|
column4::numeric,
|
|
column5::numeric,
|
|
column6::numeric,
|
|
column7::numeric,
|
|
column8::numeric,
|
|
column9,
|
|
column11
|
|
from staging2.IHTBTD_BTD_test_res_3_block where trx_record =1;
|
|
|
|
insert into transactional.iht_brake_perf_test_results
|
|
(
|
|
client_id,
|
|
function_id,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic,
|
|
tractor_make,
|
|
tractor_model,
|
|
test_condition,
|
|
srl_no,
|
|
trigger_speed_km_per_h,
|
|
brake_control_input_force_kg,
|
|
required_corrected_stopping_distance_m,
|
|
actual_stopping_distance_m,
|
|
deceleration_m_s2_v2_2s,
|
|
observation,
|
|
test_mode
|
|
)
|
|
select
|
|
client_id,
|
|
function_id,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic,
|
|
make,model,
|
|
column2,
|
|
column3::numeric,
|
|
column4::numeric,
|
|
column5::numeric,
|
|
column6::numeric,
|
|
column7::numeric,
|
|
column8::numeric,
|
|
column9,
|
|
column11
|
|
from staging2.IHTBTD_BTD_test_res_4_block where trx_record =1;
|
|
|
|
insert into transactional.iht_brake_perf_test_results
|
|
(
|
|
client_id,
|
|
function_id,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic,
|
|
tractor_make,
|
|
tractor_model,
|
|
test_condition,
|
|
srl_no,
|
|
trigger_speed_km_per_h,
|
|
brake_control_input_force_kg,
|
|
required_corrected_stopping_distance_m,
|
|
actual_stopping_distance_m,
|
|
deceleration_m_s2_v2_2s,
|
|
observation,
|
|
test_mode
|
|
)
|
|
select
|
|
client_id,
|
|
function_id,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic,
|
|
make,model,
|
|
column2,
|
|
column3::numeric,
|
|
column4::numeric,
|
|
column5::numeric,
|
|
column6::numeric,
|
|
column7::numeric,
|
|
column8::numeric,
|
|
column9,
|
|
column11
|
|
from staging2.IHTBTD_BTD_test_res_5_block where trx_record =1;
|
|
|
|
|
|
insert into transactional.iht_brake_perf_test_results
|
|
(
|
|
client_id,
|
|
function_id,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic,
|
|
tractor_make,
|
|
tractor_model,
|
|
test_condition,
|
|
srl_no,
|
|
trigger_speed_km_per_h,
|
|
brake_control_input_force_kg,
|
|
required_corrected_stopping_distance_m,
|
|
actual_stopping_distance_m,
|
|
deceleration_m_s2_v2_2s,
|
|
observation,
|
|
test_mode
|
|
)
|
|
select
|
|
client_id,
|
|
function_id,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic,
|
|
make,model,
|
|
column2,
|
|
column3::numeric,
|
|
column4::numeric,
|
|
column5::numeric,
|
|
column6::numeric,
|
|
column7::numeric,
|
|
column8::numeric,
|
|
column9,
|
|
column13
|
|
from staging2.IHTBTD_BTD_test_res_6_block where trx_record =1;
|
|
|
|
insert into transactional.iht_brake_perf_test_condition
|
|
(
|
|
client_id,
|
|
function_id,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic,
|
|
tractor_make,
|
|
tractor_model,
|
|
test_condition,
|
|
date_of_test,
|
|
time_of_test,
|
|
location_name,
|
|
test_mode,
|
|
wind_velocity_kmph,
|
|
ambient_temp_c,
|
|
humidity_rh_pct
|
|
)
|
|
select
|
|
client_id,
|
|
function_id,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic,
|
|
make,
|
|
model,
|
|
condition,
|
|
date::date,
|
|
time,
|
|
location,
|
|
mode,
|
|
wind_velocity_km_hr,
|
|
ambient_temperature_c::numeric ,
|
|
humidity_rh::numeric
|
|
from staging2.ihtbtd_btd_test_condition_block where trx_record =1;
|
|
|
|
update transactional.iht_brake_perf_test_results a
|
|
set brake_perf_test_condition_id=(select syspk
|
|
from transactional.iht_brake_perf_test_condition b
|
|
where a.test_mode =b.test_mode and a.test_condition=b.test_condition and a.file_syspk=b.file_syspk)
|
|
where a.file_syspk=__file_syspk;
|
|
|
|
|
|
|
|
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
|
|
select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk;
|
|
select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk;
|
|
select syspk from transactional.test_master into __test_master_id where test_type ='In House';
|
|
select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
|
|
|
|
|
|
update transactional.test_instance
|
|
set test_master_id =__test_master_id,
|
|
test_tractor_id =__test_instance_tractor_id
|
|
where file_syspk=__file_syspk;
|
|
|
|
|
|
update transactional.test_instance_tyre_info
|
|
set test_instance_id=__test_instance_id,
|
|
test_instance_tractor_id = __test_instance_tractor_id,
|
|
tractor_model =__model,
|
|
tractor_make=__make
|
|
where file_syspk=__file_syspk;
|
|
|
|
update transactional.test_instance_tractor_info
|
|
set test_instance_id=__test_instance_id,
|
|
tractor_model =__model,
|
|
tractor_make=__make
|
|
where file_syspk=__file_syspk;
|
|
|
|
update transactional.test_instance_drawbar_info
|
|
set test_instance_id=__test_instance_id,
|
|
test_instance_tractor_id = __test_instance_tractor_id,
|
|
tractor_model =__model,
|
|
tractor_make=__make
|
|
where file_syspk=__file_syspk;
|
|
|
|
update transactional.iht_brake_perf_test_condition
|
|
set test_instance_id=__test_instance_id,
|
|
test_instance_tractor_id = __test_instance_tractor_id,
|
|
tractor_model =__model,
|
|
tractor_make=__make
|
|
where file_syspk=__file_syspk;
|
|
|
|
update transactional.iht_brake_perf_test_results
|
|
set test_instance_id=__test_instance_id,
|
|
test_instance_tractor_id = __test_instance_tractor_id,
|
|
tractor_model =__model,
|
|
tractor_make=__make
|
|
where file_syspk=__file_syspk;
|
|
|
|
update transactional.test_instance
|
|
set test_file_name =(select a.file_name from staging1.staging_generic_table a where file_syspk = __file_syspk limit 1)
|
|
where file_syspk = __file_syspk;
|
|
|
|
|
|
update transactional.test_instance
|
|
set test_type = a.test_type,
|
|
test_name= a.test_name
|
|
from fw_core.test_file_sheet_format_master a
|
|
where transactional.test_instance.file_sheet_mnemonic = a.file_sheet_mnemonic
|
|
and transactional.test_instance.file_syspk=__file_syspk;
|
|
|
|
|
|
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_IHTBTD_BTD_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
|
|
|
end
|
|
$function$
|
|
;
|
|
|
|
|