import java.io.File import java.io.FileWriter import java.io.BufferedWriter import java.text.SimpleDateFormat import java.util.Date import java.util.Random // Definisikan nama file dan path String fileName = 'Data Files/Data Upload/03 Switching/upload_switching_transaction.txt' File file = new File(fileName) // Cek apakah file sudah ada, jika ada hapus file tersebut if (file.exists()) { file.delete() println("File lama telah dihapus: " + fileName) } // Buat writer untuk menulis ke file BufferedWriter writer = new BufferedWriter(new FileWriter(file)) // Tulis header CSV dengan format baru writer.write("TransactionDate|TransactionType|SACode|InvestorFundUnitACNo|SwitchOutFundCode|SwitchOutAmount(Nominal)|SwitchOutAmount(Unit)|SwitchOutAmount(AllUnits)|SwitchingFeeChargeFund|Fee(Nominal)|Fee(Unit)|Fee|SwitchinFundCode|PaymentDate|TransferType|SAReferenceNo") writer.newLine() // Inisialisasi format tanggal dan generator nomor acak //SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd") //String currentDate = dateFormat.format(new Date()) // Menghasilkan tanggal saat ini // Inisialisasi format tanggal dengan format yyyyMMdd SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd") String currentDate = dateFormat.format(new Date()) // Menghasilkan tanggal saat ini dalam format yyyyMMdd // Data dummy yang ingin ditulis List> data = [ [transactionType: "3", saCode: "BPTPR", investorFundUnitACNo: "BPTPR0CZGMHF0129", switchOutFundCode: "BPTPRDTCPMPKON01", switchOutAmountNominal: "", switchOutAmountUnit: "10000", switchOutAmountAllUnits: "", switchingFeeChargeFund: "2", feeNominal: "", feeUnit: "1000", fee: "", switchinFundCode: "BPTPRDTSTPRSYR01", paymentDate: "", transferType: "2", saReferenceNo: "REF005"], [transactionType: "3", saCode: "BPTPR", investorFundUnitACNo: "BPTPR0CZGMHF0129", switchOutFundCode: "BPTPRDTCPMFKON01", switchOutAmountNominal: "", switchOutAmountUnit: "10000", switchOutAmountAllUnits: "", switchingFeeChargeFund: "2", feeNominal: "", feeUnit: "1000", fee: "", switchinFundCode: "BPTPRDFCBPTPRX01", paymentDate: "", transferType: "2", saReferenceNo: "REF006"] ] // Tulis data ke file CSV dengan menambahkan tanggal dan nomor acak untuk UnitBalanceComparison data.each { record -> writer.write("${currentDate}|${record.transactionType}|${record.saCode}|${record.investorFundUnitACNo}|${record.switchOutFundCode}|${record.switchOutAmountNominal}|${record.switchOutAmountUnit}|${record.switchOutAmountAllUnits}|${record.switchingFeeChargeFund}|${record.feeNominal}|${record.feeUnit}|${record.fee}|${record.switchinFundCode}|${record.paymentDate}|${record.transferType}|${record.saReferenceNo}") writer.newLine() } // Tutup writer writer.close() println("File CSV telah dibuat di: " + fileName)