i am trying to create the new file , i have made some code changes to do so.
i have also did some changes to convert the text file using bin data but the session date i am getting wrong 1/1/1900 so my code is showing me error like cannot write to the file . i am posting my code below please suggest me if i need any changes to do
internal final class CustomerChequeDepositJob
{
public static void main(Args _args)
{
ISLCustPDCRegister pdcRegister;
LedgerJournalTable journalTable;
LedgerJournalTrans journalTrans;
BankAccountTable bankAccountTable;
#File
str filePath, fileName, cid, folderPath, baseFolder, folderName;
str Narration1, Narration2, fullNarration;
int lineCounter = 0;
AmountCur totalAmount = 0;
str dataLine, headerLine, content;
UtcDateTime now = DateTimeUtil::getSystemDateTime();
str timestamp;
date sessionDate;
AmountCur amount;
BinData binData = new BinData();
try
{
// Base and target folder
baseFolder = @"C:\Temp";
folderName = "Customer Cheque Deposit";
folderPath = baseFolder + "\\" + folderName;
// Create folder if it doesn't exist
//FileIOPermission permission = new FileIOPermission(folderPath, #io_write);
//permission.assert();
ARGlobal::CreateDirectory(folderPath);
// Prepare company info and file name
CompanyInfo companyInfo = CompanyInfo::find();
cid = companyInfo.ARCIDNo;
// Format timestamp: DDMMYYYYHHMMSS
timestamp = System.String::Format('{0:ddMMyyyyHHmmss}', DateTimeUtil::newDateTime(systemDateGet(), timeNow()));
fileName = strFmt("CCSS_%1_%2.txt", cid, timestamp);
filePath = folderPath + "\\" + fileName;
// Get session date in user's time zone
sessionDate = DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone());
// Add CSV Header
content = "S.No,CHQNAME_FRONT,CHQNAME_BACK,CHECKNUMBER,MICRNUMBER,BankRegNum,CompanyCID,BankAccount,MATURITYDATE,Amount,PaymentReference,Narration1,Narration2\r\n";
// Loop through records
while select ChqName_front,
ChqName_back,
CheckNumber,
MICRNumber,
MaturityDate,
PaymentReference,
BankAccount
from pdcRegister
join journalTable
where journalTable.JournalNum == pdcRegister.JournalNum
join Txt from journalTrans
where journalTrans.RecId == pdcRegister.LedgerJournalTrans
&& pdcRegister.PDCStatus == ISLPDCStatus::Received
&& pdcRegister.MaturityDate >= sessionDate
{
bankAccountTable = BankAccountTable::find(pdcRegister.BankAccount);
amount = pdcRegister.displayAmount();
lineCounter++;
totalAmount += amount;
fullNarration = journalTrans.Txt;
Narration1 = subStr(fullNarration, 1, 35);
Narration2 = subStr(fullNarration, 36, 35);
dataLine = strFmt('%1,%2,%3,%4,%5,%6,%7,%8,%9,%10,%11,%12,%13\r\n',
lineCounter,
pdcRegister.ChqName_front,
pdcRegister.ChqName_back,
pdcRegister.CheckNumber,
pdcRegister.MICRNumber,
bankAccountTable.RegistrationNum,
companyInfo.ARCIDNo,
bankAccountTable.AccountNum,
date2str(pdcRegister.MaturityDate, 123, 2, 1, 2, 1, 4),
amount,
pdcRegister.PaymentReference,
Narration1,
Narration2);
content += dataLine;
}
// Add summary line
headerLine = strFmt("\r\nTotal Records: %1, Total Amount: %2\r\n", lineCounter, totalAmount);
content += headerLine;
// Write to file
binData.setStrData(content);
binData.saveFile(filePath);
CodeAccessPermission::revertAssert();
info(strFmt("Export completed. %1 record(s) written to: %2", lineCounter, filePath));
}
catch (Exception::CLRError)
{
error("CLR error occurred.");
}
catch
{
error("Unhandled error occurred during export.");
}
}
}