public void open(int _ban = 0)
{
ttsabort;
CIMMYTROCustomisationTable parameter = CIMMYTROCustomisationTable::find();
if (parameter.CIMMYT_RequireZimbabweEcoCashPaymentfile)
{
LedgerJournalTrans ledgerJournalTrans;
VendTable vendTable;
DimensionAttributeValueCombination dimComb;
DirPartyTable partyTable;
DirPerson dirPerson;
DirPersonName personName;
DirPartyLocation partyLocation;
LogisticsElectronicAddress address;
TaxRegistration taxReg;
str vendorMobile, firstName, lastName, nationalId, amountStr, line;
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
System.IO.StreamWriter writer = new System.IO.StreamWriter(memoryStream, System.Text.Encoding::UTF8);
// CSV header
writer.WriteLine("Phone Number,Amount,First Name,Last Name,National ID,Additional Field1,Additional Field2,Additional Field3");
while select ledgerJournalTrans
where ledgerJournalTrans.JournalNum == ledgerJournalId
&& ledgerJournalTrans.PaymentStatus == CustVendPaymStatus::Confirmed
&& ledgerJournalTrans.OffsetAccountType == LedgerJournalACType::Bank
&& ledgerJournalTrans.PaymMode == "TR-MOBILE"
{
vendorMobile = "";
firstName = "";
lastName = "";
nationalId = "";
// Vendor info
dimComb = DimensionAttributeValueCombination::find(ledgerJournalTrans.LedgerDimension);
VendAccount vendAccount = dimComb.DisplayValue;
vendTable = VendTable::find(vendAccount);
partyTable = DirPartyTable::findRec(vendTable.Party);
// 1. Find Primary Mobile Number (direct from LogisticsElectronicAddress)
select firstonly address
where address.Party == vendTable.Party
&& address.Type == LogisticsElectronicAddressMethodType::Phone
&& address.Locator != ""
&& address.IsPrimary == NoYes::Yes;
if (address.RecId)
{
vendorMobile = strKeep(address.Locator, '0123456789');
}
// 2. Find National ID (from TaxRegistration → DirPartyLocation)
select firstonly partyLocation
where partyLocation.Party == vendTable.Party
&& partyLocation.IsPrimary == NoYes::Yes;
if (partyLocation.RecId)
{
select firstonly taxReg
where taxReg.DirPartyLocation == partyLocation.RecId;
if (taxReg.RecId && taxReg.RegistrationNumber)
{
str allowedCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
nationalId = strKeep(taxReg.RegistrationNumber, allowedCharacters);
}
}
// 3. Get Vendor Name
dirPerson = DirPerson::find(partyTable.RecId);
if (dirPerson.RecId)
{
select firstonly personName
where personName.Person == dirPerson.RecId;
firstName = strKeep(personName.FirstName, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ');
lastName = strKeep(personName.LastName, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ');
}
// 4. Amount
real amount = ledgerJournalTrans.AmountCurDebit != 0 ? ledgerJournalTrans.AmountCurDebit : ledgerJournalTrans.AmountCurCredit;
amountStr = num2str(amount, -1, 2, 1, 0);
amountStr = strRem(amountStr, ",");
// 5. Build CSV line
line = strFmt("%1,%2,%3,%4,%5,,,",
vendorMobile,
amountStr,
firstName,
lastName,
nationalId);
writer.WriteLine(line);
}
writer.Flush();
memoryStream.Position = 0;
str exportFileName = strFmt("%1.csv", ledgerJournalId);
file::SendFileToUser(memoryStream, exportFileName);
}
}
in exel i am getting like this