388 lines
9.8 KiB
PL/PgSQL
Executable File
388 lines
9.8 KiB
PL/PgSQL
Executable File
drop function if exists staging2.fn_FTDRY_TRS_TRX ;
|
|
CREATE OR REPLACE FUNCTION staging2.fn_FTDRY_TRS_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_tractor_id int;
|
|
begin
|
|
|
|
__file_syspk := p_file_syspk;
|
|
/************************************************************
|
|
Function Name:fn_FTDRY_TRS_TRX
|
|
Function Desc: This function populates data into ODS
|
|
File Format: FTDRY
|
|
Sheet Format: FTDRY_TRS
|
|
Creation Date:
|
|
Updation Date:
|
|
Author: compegence team
|
|
Function Call: select staging2.fn_FTDRY_TRS_TRX()
|
|
--***************************************************************/
|
|
--
|
|
--delete from transactional.test_instance where file_syspk =836;
|
|
--
|
|
--delete from transactional.test_instance_engine_info where file_syspk =836;
|
|
--
|
|
--delete from transactional.test_instance_implement_info where file_syspk =836;
|
|
--
|
|
--delete from transactional.test_instance_tractor_info where file_syspk =836;
|
|
--
|
|
--
|
|
--delete from transactional.test_instance_trailer_info where file_syspk =836;
|
|
--
|
|
--delete from transactional.test_instance_tyre_info where file_syspk =836;
|
|
|
|
insert into transactional.test_instance
|
|
(
|
|
client_id,
|
|
function_id,
|
|
test_report_no,
|
|
objective_of_test,
|
|
background_of_test,
|
|
job_order_no,
|
|
test_location_name,
|
|
soil_moisture_content_pct,
|
|
soil_bulk_density_g_per_cc,
|
|
test_engineer,
|
|
test_operator,
|
|
date_of_test,
|
|
test_report_date,
|
|
season,
|
|
type_of_soil,
|
|
soil_cone_index,
|
|
field_condition,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic
|
|
)
|
|
select
|
|
client_id,
|
|
function_id,
|
|
report_reference_no test_report_no,
|
|
objective_of_test,
|
|
background_of_test,
|
|
job_order_no,
|
|
test_location test_location_name,
|
|
soil_moisture_content_::text soil_moisture_content_pct ,
|
|
soil_bulk_density_g_cc::int soil_bulk_density_g_per_cc,
|
|
test_engineer,
|
|
test_operator,
|
|
date_of_test::date,
|
|
report_date::date test_report_date,
|
|
season,
|
|
type_of_soil,
|
|
trim(' Kpa' from soil_cone_index_kpa)::int soil_cone_index,
|
|
field_condition,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic
|
|
from staging2.ftdry_trs_h1_block where trx_record=1;
|
|
|
|
insert into transactional.test_instance_tractor_info
|
|
(
|
|
client_id,
|
|
function_id,
|
|
tractor_model,
|
|
tractor_make,
|
|
tractor_sr_no,
|
|
tractor_engine_hp,
|
|
fip_type,
|
|
hour_Meter_Reading,
|
|
Steering_Type,
|
|
Transmission_Type,
|
|
wheel_drive_type,
|
|
egr_yn,
|
|
Brake_Type,
|
|
PTO_Type,
|
|
Standard_PTO_Speed_RPM,
|
|
EPTO_Speed_RPM,
|
|
tractor_weight_front_kg,
|
|
tractor_weight_rear_kg,
|
|
tractor_weight_total_kg,
|
|
Ballasted_Tractor_Accessories,
|
|
Mechanical_Ballast_Rear,
|
|
mechanical_ballast_rear_in_kg,
|
|
water_ballast_rear_75_pct ,
|
|
Mechanical_Ballast_Front,
|
|
mechanical_ballast_front_kg ,
|
|
Total_Ballast_Weight,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic
|
|
)
|
|
select
|
|
client_id,
|
|
function_id,
|
|
Tractor_Model,
|
|
Tractor_Make,
|
|
Tractor_Sr_No,
|
|
Tractor_Engine_HP::float,
|
|
FIP_Type,
|
|
hour_Meter_Reading::numeric,
|
|
Steering_Type,
|
|
Transmission_Type,
|
|
Wheel_Drive_Type_WD wheel_drive_type ,
|
|
EGR_Yes_No egr_yn,
|
|
Brake_Type ,
|
|
PTO_Type ,
|
|
Standard_PTO_Speed_RPM::numeric,
|
|
EPTO_Speed_RPM,
|
|
Tractor_Weight_kg_Front::numeric tractor_weight_front_kg ,
|
|
Tractor_Weight_kg_Rear::numeric tractor_weight_rear_kg ,
|
|
Tractor_Weight_kg_Total::numeric tractor_weight_total_kg ,
|
|
Ballasted_Tractor_Accessories,
|
|
Mechanical_Ballast_Rear,
|
|
Mechanical_Ballast_Rear_in_KG::numeric mechanical_ballast_rear_in_kg ,
|
|
Water_Ballast_Rear water_ballast_rear_75_pct ,
|
|
Mechanical_Ballast_Front,
|
|
Mechanical_Ballast_Front_in_Kg::numeric mechanical_ballast_front_kg ,
|
|
Total_Ballast_Weight::numeric,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic
|
|
from staging2.ftdry_trs_spec_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
|
|
set test_tractor_yn ='N'
|
|
where test_tractor_yn is null and file_syspk =__file_syspk;
|
|
|
|
|
|
insert into transactional.test_instance_tyre_info
|
|
(
|
|
client_id,
|
|
function_id,
|
|
tractor_make,
|
|
tractor_model,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic,
|
|
tractor_sr_no,
|
|
tyre_type,
|
|
tyre_make,
|
|
tyre_size,
|
|
tyre_pressure_psi
|
|
)
|
|
select
|
|
client_id,
|
|
function_id,
|
|
tractor_make,
|
|
tractor_model,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic,
|
|
tractor_sr_no,
|
|
'front',
|
|
front_tyre_make tyre_make,
|
|
front_tyre_size tyre_size,
|
|
front_tyre_pressure_psi::numeric tyre_pressure_psi
|
|
from staging2.ftdry_trs_spec_block where trx_record=1;
|
|
|
|
update transactional.test_instance_tyre_info a
|
|
set test_instance_tractor_id =(select syspk
|
|
from transactional.test_instance_tractor_info b
|
|
where a.file_syspk=b.file_syspk and
|
|
a.tractor_model=b.tractor_model and a.tractor_sr_no=b.tractor_sr_no)
|
|
where a.tyre_type ='front' and a.file_syspk =__file_syspk;
|
|
|
|
|
|
insert into transactional.test_instance_tyre_info
|
|
(
|
|
client_id,
|
|
function_id,
|
|
tractor_make,
|
|
tractor_model,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic,
|
|
tractor_sr_no,
|
|
tyre_type,
|
|
tyre_make,
|
|
tyre_size,
|
|
tyre_pressure_psi
|
|
)
|
|
select
|
|
client_id,
|
|
function_id,
|
|
tractor_make,
|
|
tractor_model,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic,
|
|
tractor_sr_no,
|
|
'rear',
|
|
rear_tyre_make tyre_make,
|
|
rear_tyre_size tyre_size,
|
|
rear_tyre_pressure_psi::numeric tyre_pressure_psi
|
|
from staging2.ftdry_trs_spec_block where trx_record=1;
|
|
|
|
update transactional.test_instance_tyre_info a
|
|
set test_instance_tractor_id =(select syspk
|
|
from transactional.test_instance_tractor_info b
|
|
where a.file_syspk=b.file_syspk and
|
|
a.tractor_model=b.tractor_model and a.tractor_sr_no=b.tractor_sr_no)
|
|
where a.tyre_type ='rear' and a.file_syspk = __file_syspk;
|
|
|
|
insert into transactional.test_instance_engine_info
|
|
(
|
|
client_id,
|
|
function_id,
|
|
low_idle_observed ,
|
|
high_idle_observed ,
|
|
rated_rpm ,
|
|
engine_to_pto_ratio_540_pto,
|
|
engine_to_pto_ratio_540e_pto,
|
|
tractor_model,
|
|
tractor_make,
|
|
tractor_sr_no,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic
|
|
)
|
|
select
|
|
client_id,
|
|
function_id,
|
|
low_idle::numeric low_idle_observed ,
|
|
high_idle::numeric high_idle_observed ,
|
|
rated_rpm::numeric,
|
|
engine_to_pto_ratio_540_pto,
|
|
engine_to_pto_ratio_540e_pto,
|
|
tractor_model,
|
|
tractor_make,
|
|
tractor_sr_no,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic
|
|
from staging2.ftdry_trs_engine_rpm_block
|
|
where trx_record=1;
|
|
|
|
update transactional.test_instance_engine_info a
|
|
set test_instance_tractor_id =(select syspk
|
|
from transactional.test_instance_tractor_info b
|
|
where a.file_syspk=b.file_syspk and
|
|
a.tractor_model=b.tractor_model and a.tractor_sr_no=b.tractor_sr_no)
|
|
where a.file_syspk = __file_syspk;
|
|
|
|
insert into transactional.test_instance_implement_info
|
|
(
|
|
client_id,
|
|
function_id,
|
|
name_of_implement,
|
|
type_of_implement,
|
|
make_of_implement,
|
|
no_of_disc_blades_bottoms,
|
|
cutting_width_m,
|
|
implement_weight_kg,
|
|
hitch_category,
|
|
span_for_mounted_implement_mm ,
|
|
mast_height_for_mounted_implement_mm,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic
|
|
)
|
|
select
|
|
client_id,
|
|
function_id,
|
|
name_of_implement,
|
|
type_of_implement,
|
|
make_of_implement,
|
|
no_of_bottoms_tyne_disc_blade no_of_disc_blades_bottoms,
|
|
cutting_width_m,
|
|
trim('kg' from implement_weight_kg)::numeric,
|
|
hitch_category,
|
|
span_cm_for_mounted_implement::numeric span_for_mounted_implement_cm ,
|
|
mast_height_cm_for_mounted_implement::numeric mast_height_for_mounted_implement_cm,
|
|
file_syspk,
|
|
file_mnemonic,
|
|
file_sheet_mnemonic
|
|
from staging2.ftdry_trs_implement_block where trx_record=1;
|
|
|
|
update transactional.test_instance a
|
|
set report_template_no=b.report_template_no,
|
|
report_template_rev_no=b.report_template_rev_no,
|
|
report_template_rev_date =b.report_template_rev_date
|
|
from staging2.ftdry_trs_implement_block b where trx_record=1
|
|
and a.file_syspk=b.file_syspk;
|
|
|
|
|
|
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
|
|
select syspk from transactional.test_master into __test_master_id where test_type ='Field';
|
|
select syspk from transactional.test_instance_tractor_info into __test_tractor_id
|
|
where file_syspk =__file_syspk and test_tractor_yn ='Y';
|
|
|
|
|
|
update transactional.test_instance
|
|
set test_master_id =__test_master_id,
|
|
test_tractor_id =__test_tractor_id
|
|
where file_syspk=__file_syspk;
|
|
|
|
|
|
update transactional.test_instance_engine_info
|
|
set test_instance_id=__test_instance_id
|
|
where file_syspk=__file_syspk;
|
|
|
|
|
|
update transactional.test_instance_tractor_info
|
|
set test_instance_id=__test_instance_id
|
|
where file_syspk=__file_syspk;
|
|
|
|
|
|
update transactional.test_instance_tyre_info
|
|
set test_instance_id=__test_instance_id
|
|
where file_syspk=__file_syspk;
|
|
|
|
update transactional.test_instance_implement_info
|
|
set test_instance_id=__test_instance_id
|
|
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_FTDRY_TRS_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
|
|
|
end
|
|
$function$
|
|
;
|
|
|
|
|
|
|
|
|
|
|