SELECT
	id,
	NULL as accept_order_id,
	order_id,
	NULL as purchase_id,
	NULL as arriving_id,
	1 as rev_number,
	input_date,
	purchase_date as target_date,
	35 as user_id,
	19 as section_id,
	4 as purchase_trigger_code,
	CASE purchase_type_id WHEN 1 THEN 2 WHEN 2 THEN 2 WHEN 7 THEN 2 WHEN 3 THEN 5 WHEN 4 THEN 5 WHEN 5 THEN 5 WHEN 6 THEN 5 END as purchase_type_code,
	supplier_id + 1 as supplier_id,
	supplier_id + 1 as payto_supplier_id,
	supplier_id + 1 as payto_supplier_group_id,
	invoice_number,
	hospital_id as warehouse_id,
	hospital_id as own_warehouse_id,
	NULL as user_position_id,
	NULL as sales_user_id,
	NULL as sales_area_id,
	NULL as sales_section_id,
	NULL as customer_id,
	IF(supplier_id=1,2,1) as currency_type_code,
	83.5 as exchange_rate,
	total_price,
	total_tax as total_duty,
	IF(supplier_id=3,1,0) as duty_type_code,
	IF(supplier_id=3,5,0) as duty_rate,
	0 as price_duty_type_code,
	1 as duty_calc_type_code,
	1 as frac_digit_code,
	1 as fraction_method_code,
	IF(total_quantity<0,0,1) as sign_type_code,
	cutoff_date as cutoff_date_code,
	purchase_timing_id as charge_timing_code,
	0 as state_code,
	purchase_note as note,
	0 as invalid_flag_code,
	print_sheet as print_check_date,
	lot_print_sheet as print_lot_date,
	NULL as deleted_at,
	NOW() as created_at,
	NOW() as updated_at
FROM purchases WHERE id > 1653
INTO OUTFILE "/tmp/purchases.csv" FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"';