Payment export file plan text file , download file X++
class CMCVendPaymentExportService
{
str fileContent;
LedgerJournalTrans journalTrans;
LedgerJournalTable journalTable;
SpecTrans specTrans;
GeneralJournalAccountEntry accEntry;
VendInvoiceJour vendInvoiceJour;
CMCRSTARVendorInterfaceParameters parameters;
real transAmt;
int batchNo,batchSeqNo;
str 3 agencyCode,transCode;
str 8 batchDate;
str 1 batchType;
str 3 batchNoStr;
str 5 batchSeqNoStr;
str 8 oprId;
str 2 fiscalYearStr;
TransDate effectiveDate;
VendTrans vendTrans;
public void processOperation( LedgerJournalFormTable ledgerJournalFormTable)
{
int fileCreatedTime = timenow();
Num fileDatestr = date2Str
(today(),
213,
DateDay::Digits2,
DateSeparator::None, // no separator
DateMonth::Digits2,
DateSeparator::None, // no separator
DateYear::Digits2
);
Description255 fileName = "P"+fileDatestr+
num2str0(fileCreatedTime div 3600 ,2,0,0,0) +
num2Str0(fileCreatedTime mod 3600 div 60,2,0,0,0) +
num2Str0(fileCreatedTime mod 3600 mod 60,2,0,0,0)+".txt";
//str fileName = "VendPaymentExp.txt";
this.runProcess(ledgerJournalFormTable);
try
{
File::SendStringAsFileToUser(fileContent, fileName);
this.endUpdate();
}
catch(Exception::Error)
{
throw error("Error occured while downloading file");
}
info(strFmt("CSV file %1 Sent to user",filename ));
}
public void createLine()
{
LedgerDimensionPreviewTmp ledgerDimensionPreviewTmpLocal;
MainAccount mainAcc;
LedgerFund ledgerFund;
VendTable vendTable;
LogisticsLocation logisticsLoc;
DirPartyLocation dirPartyLoc;
Amount transactionAmt;
Num fundValue,MainAccValue;
LedgerJournalTrans journalTransInvoice;
InvoiceDate invoiceDate;
TransDate transDate = vendInvoiceJour.InvoiceDate;
Description description = vendInvoiceJour.Description;
select firstonly journalTransInvoice
where journalTransInvoice.Voucher == vendInvoiceJour.LedgerVoucher
&& journalTransInvoice.Invoice == vendInvoiceJour.InvoiceId;
if(journalTransInvoice.RecId)
{
invoiceDate = journalTransInvoice.DocumentDate;
if(!description)
{
description = accEntry.Text;
}
}
else
{
invoiceDate = vendInvoiceJour.InvoiceDate;
}
batchSeqNoStr = this.wrapUpZeros(batchSeqNo,5);
vendTable = VendTable::find(journalTrans.accountDisplay());
transAmt += accEntry.TransactionCurrencyAmount;
transactionAmt = abs(accEntry.TransactionCurrencyAmount);
int dec = (roundDownDec(transactionAmt,2) - real2int(transactionAmt))*100;
if (accEntry.LedgerDimension)
{
// Build the preview data.
ledgerDimensionPreviewTmpLocal = LedgerDimensionPreviewTmp::buildLedgerDimensionPreviewTmp(accEntry.ledgerDimension);
select firstonly ledgerDimensionPreviewTmpLocal
where ledgerDimensionPreviewTmpLocal.Name == "Funds";
fundValue = ledgerDimensionPreviewTmpLocal.Value;
select firstonly ledgerDimensionPreviewTmpLocal
where ledgerDimensionPreviewTmpLocal.Name == "MainAccount";
MainAccValue = ledgerDimensionPreviewTmpLocal.Value;
select firstonly ledgerFund
where ledgerFund.FundNumber == fundValue;
agencyCode = this.wrapUpSpaces(ledgerFund.CMCFundAgencyCode,3) ;
select firstonly mainAcc
where mainAcc.MainAccountId == MainAccValue;
}
select firstonly logisticsLoc
where logisticsLoc.RecId == journalTrans.RemittanceLocation
exists join dirPartyLoc
where dirPartyLoc.Party == vendTable.Party
&& dirPartyLoc.Location == logisticsLoc.RecId ;
if(accEntry.IsCredit)
{
transCode = this.wrapUpZeros(str2Int(mainAcc.CMCCreditTransaction),3);
}
else
{
transCode = this.wrapUpZeros(str2Int(mainAcc.CMCDebitTransaction),3);
}
oprId = this.wrapUpSpaces(parameters.CMCVendPaymExpOprId,5) +agencyCode;
str 4 fiscalName = FiscalCalendarYear::findYearByCalendarDate(Ledger::findByLegalEntity(CompanyInfo::find().RecId).FiscalCalendar,systemDateGet()).Name ;
fiscalYearStr =subStr(fiscalName,3,2);
container line = [agencyCode,
batchDate,
batchType,
batchNoStr,
batchSeqNoStr,
oprId,
strRep(" ",4),
this.getDate2StrYMD(effectiveDate),
fiscalYearStr,
strRep(" ",2),
transCode,
strRep(" ",1),
strRep(" ",1),
agencyCode,
strRep(" ",20),
this.wrapUpZeros(str2Int(ledgerFund.CMCFundNumberState),5),
this.wrapUpZeros(str2Int(mainAcc.CMCRStar),4),
strRep(" ",42),
batchSeqNoStr,
strRep(" ",9),
this.wrapUpZeros(str2Int(journalTrans.BankChequeNum),6),
strRep(" ",8),
this.wrapUpSpaces(vendTable.CMCVendExpPrefix,1),
this.wrapUpSpaces(strAlpha(vendTable.Tax1099RegNum),9),
this.wrapUpSpaces(logisticsLoc.CMCVendAddrMailCode,3),
strRep(" ",1),
this.wrapUpSpaces(vendInvoiceJour.InvoiceId,14),
this.getDate2StrYMD(invoiceDate),
strRep(" ",8),
strRep(" ",8),
strRep("0",3),
strRep(" ",8),
strRep(" ",3),
this.getDate2StrYMD(vendInvoiceJour.DueDate),
this.getDate2StrYMD(invoiceDate),
strRep(" ",9),
this.wrapUpSpaces(vendTrans.CMCVendExpPaymDistrId,2),
strRep(" ",30),
this.wrapUpZeros(real2int(transactionAmt),11)+this.wrapUpZeros(dec,2),
strRep("0",13),
this.wrapUpSpaces(description,30),
strRep(" ",34),
strRep("0",5),
strRep("0",13),
strRep(" ",281),
agencyCode,
this.wrapUpSpaces(vendTable.CMCVendExpPrefix,1),
this.wrapUpSpaces(strAlpha(vendTable.Tax1099RegNum),9),
this.wrapUpSpaces(logisticsLoc.CMCVendAddrMailCode,3),
strRep(" ",71)
];
fileContent += con2Str(line,"");
}
public void runProcess(LedgerJournalFormTable ledgerJournalFormTable)
{
SubledgerVoucherGeneralJournalEntry subGjEntry ;
GeneralJournalEntry gjEntry;
boolean hasLines;
parameters = CMCRSTARVendorInterfaceParameters::find();
if(!parameters.BatchTrackingCount || parameters.BatchTrackingDate != today())
{
batchNo = 100;
}
else
{
batchNo = parameters.BatchTrackingCount;
}
for (journalTable = ledgerJournalFormTable.journalTable_DS().getFirst(true); journalTable; journalTable = ledgerJournalFormTable.journalTable_DS().getNext())
{
if (!journalTable.Posted)
{
batchNo += 1;
batchSeqNo = 0;
batchDate = this.getDate2StrYMD(systemDateGet());
batchType = this.wrapUpSpaces(parameters.CMCVendPaymExpBatchType,1);
batchNoStr = int2Str(batchNo);
while select journalTrans
where journalTrans.JournalNum == journalTable.JournalNum
&& journalTrans.PaymentStatus == CustVendPaymStatus::Sent
join specTrans
where specTrans.SpecTableId == journalTrans.TableId
&& specTrans.SpecRecId == journalTrans.RecId
{
vendTrans = specTrans.vendTrans();
vendInvoiceJour = vendTrans.vendInvoiceJour();
while select maxof(GeneralJournalEntry) from subGjEntry
where subGjEntry.AccountingDate == vendInvoiceJour.InvoiceDate
&& subGjEntry.Voucher == vendInvoiceJour.LedgerVoucher
join sum(TransactionCurrencyAmount),LedgerDimension,maxof(Text),maxof(IsCredit) from accEntry group by accEntry.LedgerDimension
where accEntry.GeneralJournalEntry == subGjEntry.GeneralJournalEntry
&& accEntry.PostingType != LedgerPostingType::VendBalance
&& accEntry.PostingType != LedgerPostingType::InterunitCredit
&& accEntry.PostingType != LedgerPostingType::InterunitDebit
{
effectiveDate = GeneralJournalEntry::find(subGjEntry.GeneralJournalEntry).AccountingDate;
if(fileContent)
{
fileContent += "\n";
}
hasLines = true;
batchSeqNo +=1;
this.createLine();
}
}
if(hasLines)
{
fileContent += "\n";
this.createTotalLine();
hasLines = false;
}
transAmt = 0;
}
}
}
public str wrapUpSpaces(str _text,int _no)
{
int txtLen = strLen(_text);
if(txtLen > _no)
{
_text = subStr(_text,0,_no);
}
else
{
_text = _text + strRep(" ",_no-txtLen);
}
return _text;
}
public str getDate2StrYMD(TransDate _transDate)
{
return int2Str(Year(_transDate))+this.wrapUpZeros(mthOfYr(_transDate),2) +this.wrapUpZeros( dayOfMth(_transDate),2);
}
public str wrapUpZeros(int _text,int _no)
{
return StrRFix(int2str(_text), _no, "0");
}
public Void createTotalLine()
{
int diffDays = today() - mkDate(01,01,Year(today()));
diffDays = diffDays+1;
str 5 batchJulianDate = fiscalYearStr+this.wrapUpZeros(diffDays,3);
int dec = (roundDownDec(transAmt,2) - real2int(transAmt))*100;
container line = [agencyCode,
batchDate,
batchType,
batchNoStr,
strRep("0",5),
oprId,
strRep(" ",34),
this.wrapUpSpaces(parameters.CMCVendPaymExpDisbMethod,1),
strRep(" ",2),
this.wrapUpSpaces(parameters.CMCVendPaymExpFastEntry,1),
strRep(" ",1),
this.wrapUpSpaces(parameters.CMCVendPaymExpBatchAmtCntInd,1),
this.wrapUpSpaces(parameters.CMCVendPaymExpBatchStatus,1),
this.wrapUpSpaces(parameters.CMCVendPaymExpBatchCntSw,1),
batchSeqNoStr,
batchJulianDate,
strRep("0",1),
strRep(" ",7),
batchSeqNoStr,
this.wrapUpZeros(real2int(transAmt),11)+this.wrapUpZeros(dec,2),
strRep(" ",5),
strRep("0",5),
strRep("0",13),
this.wrapUpSpaces(parameters.CMCVendPaymExpReqToPost,1)
];
fileContent += con2Str(line,"");
}
public static void main(Args args)
{
CMCVendPaymentExportService service;
service = new CMCVendPaymentExportService();
FormRun fr = args.caller();
//service.processOperation(fr.dataSource());
}
public void endUpdate()
{
ttsbegin;
CMCRSTARVendorInterfaceParameters parmLoc = CMCRSTARVendorInterfaceParameters::find(true);
parmLoc.BatchTrackingCount = batchNo;
parmLoc.BatchTrackingDate = today();
parmLoc.update();
ttscommit;
}
}
Comments
Post a Comment