SELECT
	rd.id as id,
	rd.restoration_id as restoration_id,
	rd.restoration_sub_code as seq_number,
	ps.product_category_id as product_category_id,
	rd.product_set_id as product_set_id,
	rd.product_model_id as product_id,
	rd.lot_number as lot_number,
	'' as serial_number,
	rd.ubd_date as ubd,
	24 as validity_period,
	1 as unit_code,
	rd.restoration_quantity as quantity,
	rd.restoration_quantity as scheduled_quantity,
	IF(rd.restoration_type_id=2,2,1) as stock_type_code,
	restoration_detail_note as note,
	NOW() as created_at,
	NOW() as updated_at
FROM restoration_details as rd
LEFT JOIN master_app_production.product_sets as ps
	ON rd.product_set_id = ps.id
INTO OUTFILE "/tmp/restoration_details.csv" FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"';