Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Unanswered

Vendor bankoutput file creation in AX 2009 process

Posted on by 419
class PHIVendPaymRecord_Text_PH_New extends VendOutPaymRecord
{
}
public int getCountLines(LedgerJournalId _journalNum)
{
LedgerJournalTrans ledgerJournalTrans;
    int recordCount;
    select count(RecId) from ledgerJournalTrans
    where ledgerJournalTrans.JournalNum == _journalNum;
    recordCount = ledgerJournalTrans.RecId;
    return recordCount;
}
public int getCountVoucher(LedgerJournalId _journalNum)
{
    LedgerJournalTrans ledgerJournalTrans;
    int voucherLineCount;
    Voucher vouchercount;
    ;
   while select count(voucher) from ledgerJournalTrans
        group by Voucher
        where ledgerJournalTrans.JournalNum == _journalNum
        {
         voucherLineCount +=1;
        }

    return voucherLineCount;
}
public int getLastFileNo(LedgerJournalId _journalNum)
{
ledgerJournalTrans ledgerJournalTransrec;
;
     select * from ledgerJournalTransrec
                    order by ledgerJournalTransrec.JournalNum desc
                 where ledgerJournalTransrec.JournalNum ==_journalNum;
                return ledgerJournalTransrec.PaymentSequenceNum;
}
public recid getLastRecId(LedgerJournalId _journalNum)
{
ledgerJournalTrans ledgerJournalTransrec;
;
     select * from ledgerJournalTransrec
                    order by ledgerJournalTransrec.JournalNum desc
                 where ledgerJournalTransrec.JournalNum ==_journalNum;
                return ledgerJournalTransrec.recid;
}
void output()
{
    container                           line;
    container                           lastLineRecords;
    LedgerJournalTrans                  ledgerJournalTrans,localLedgerJournalTrans,ledgerJournalTransrec;
    BankAccountTable                    bankAccountTable;
    VendTable                           vendTable;
    VendBankAccount                     vendBankAccount;
    Address                             Address;
    DirPartyTable                       DirPartyTable;
    DirPartyAddressRelationship         dirPartyAddressRelationship;
    DirPartyAddressRelationshipMapping  dirPartyAddressRelationshipMapping;
    Amount                              totalAmt;
     str                                strformat8,strformat9;
     str                                transactionTypeDRCR;
     AmountCurDebit                     curDebit,curCredit;
     int                                linesNoCount, counter,noLines,CountVoucher,LastFileNo;
     RecId                              lastRecId;

    ;
    ledgerJournalTransrec = custVendPaym.ledgerJournalTrans();
    ledgerJournalTrans  = custVendPaym.ledgerJournalTrans();
    bankAccountTable    = custVendPaym.bankAccountTable();
    vendTable           = custVendPaym.custVendTable();
    select firstonly vendBankAccount
    where vendBankAccount.VendAccount == vendTable.AccountNum
       && vendBankAccount.PHIBankFile == NoYes::Yes;
    select * from DirPartyTable where DirPartyTable.PartyId== vendTable.PartyId
    outer join dirPartyAddressRelationship where dirPartyAddressRelationship.PartyId == DirPartyTable.PartyId
    join dirPartyAddressRelationshipMapping where dirPartyAddressRelationshipMapping.PartyAddressRelationshipRecId == dirPartyAddressRelationship.RecId
    join Address where Address.RecId== dirPartyAddressRelationshipMapping.AddressRecId &&
       Address.type== AddressType::Payment;
    select sum(AmountCurDebit),sum(amountCurCredit) from localLedgerJournalTrans  where localLedgerJournalTrans.JournalNum==ledgerJournalTrans.JournalNum;
    totalAmt = abs(localLedgerJournalTrans.AmountCurCredit - localLedgerJournalTrans.AmountCurDebit);
    counter =1;
    if(ledgerJournalTrans.AmountCurDebit>0)
    {
    curDebit = ledgerJournalTrans.AmountCurDebit;
     transactionTypeDRCR = '02';
    }
    else
    {
     curDebit = ledgerJournalTrans.AmountCurCredit;
     transactionTypeDRCR = '01';
    }
        bankAccountTable = BankAccountTable::find(ledgerJournalTrans.OffsetAccount);
   /* line= ['TR',ledgerJournalTrans.Voucher,bankAccountTable.AccountNum,Date2str(ledgerJournalTrans.TransDate,213,2,4,2,4,4),num2str(totalAmt,1,2,1,0),ledgerJournalTrans.PHIDeliveryMethod,
          enum2str(ledgerJournalTrans.PHIReleaseMode),VendTable.PHIBankLocationCode,vendTable.Name,vendBankAccount.AccountNum,ledgerJournalTrans.Txt,' ',Address.Street,Address.City,Address.State,Address.ZipCode];
    file.writeExp(line);*/ //commted by pankaj
      strformat8 = date2str(ledgerJournalTrans.TransDate,321,DateDay::Digits2,DateSeparator::None,DateMonth::Digits2,DateSeparator::None,DateYear::Digits4);
      //linesNoCount=0;
      linesNoCount = ledgerjournaltable::find(ledgerJournalTrans.JournalNum).numOfLines();
     /* select firstfast * from ledgerJournalTransrec
                order by ledgerJournalTransrec.JournalNum desc
                where ledgerJournalTransrec.JournalNum == ledgerJournalTrans.JournalNum ;*/
                lastRecId = this.getLastRecId(ledgerJournalTrans.JournalNum);
                noLines = this.getCountLines(ledgerJournalTrans.JournalNum);
   /* if(linesNo >= 1)
    {
    this.Output_Invoice();
    }
    else
    {*/
    line= ['TR',ledgerJournalTrans.Voucher,strformat8,vendTable.CountryRegionId,vendBankAccount.AccountID,vendBankAccount.AccountNum,
    curDebit,ledgerJournalTrans.currencyCode,
          ledgerJournalTrans.PaymMode,transactionTypeDRCR,'01',bankAccountTable.AccountNum,bankAccountTable.Name,ledgerJournalTrans.Txt,' ',Address.Street,Address.City,Address.State,Address.ZipCode];
     counter++;
    file.writeExp(line);
   // }
    /*
    if(ledgerJournalTrans.SettleVoucher==SettlementType::SelectedTransact)
    {
        this.Output_Invoice();
    }*/
    ///
    //linesNoCount =linesNoCount+ 1;
    linesNoCount =linesNoCount;
     counter = conLen(line);
    // if(ledgerJournalTrans.LineNum >=linesNoCount)
   // if(LedgerJournalTrans::lastLineNum(ledgerJournalTrans.JournalNum) >= counter )
  // if( counter >= 2)
  if(ledgerJournalTrans.RecId == lastRecId )
    {
    CountVoucher = this.getCountVoucher(ledgerJournalTrans.JournalNum);
    lastLineRecords = conNull();
    lastLineRecords= ['FT',noLines,CountVoucher,totalAmt];
     file.writeExp(lastLineRecords);
     //line = conNull();
     //break;
    }
   /* info(Strfmt('%1',LedgerJournalTrans::lastLineNum(ledgerJournalTrans.JournalNum)));
     info(Strfmt('%1',linesNoCount));
      info(Strfmt('%1',lastRecId));
      counter = conLen(line);
info(strFmt("Number of records: %1", counter));*/
       //
}
void output_header()
{
    container line;
    ledgerJOurnalTrans  ledgerJournalTrans,localLedgerJournalTrans;
    Amount  totalAmt;
    str strformat8,strformat9;
    int LastFileNo;
    ;
    ledgerJournalTrans  = custVendPaym.ledgerJournalTrans();
    LastFileNo = this.getLastFileNo(ledgerJournalTrans.JournalNum);
    select sum(AmountCurDebit),sum(amountCurCredit) from localLedgerJournalTrans  where localLedgerJournalTrans.JournalNum==ledgerJournalTrans.JournalNum;
    totalAmt = localLedgerJournalTrans.AmountCurCredit + localLedgerJournalTrans.AmountCurDebit;
   // line=['FH','TestPH',Date2str(systemdateGet(),213,2,4,2,4,4),num2str(totalAmt,1,2,1,0)];
   if(!LedgerJournalTrans.FileCreated)
   {
  strformat8 = date2str(today(),321,DateDay::Digits2,DateSeparator::None,DateMonth::Digits2,DateSeparator::None,DateYear::Digits4);
  }
  else
  {
  strformat8 = date2str(LedgerJournalTrans.FileCreated,321,DateDay::Digits2,DateSeparator::None,DateMonth::Digits2,DateSeparator::None,DateYear::Digits4);
  }
  strformat9 = strFmt(time2str(timeNow(), TimeSeparator::Space,  TimeFormat::Hour24));
  strformat9 = strAlpha(strformat9);
 // line=['FH',ledgerJournalTrans.AccountNum,strformat8,strformat9,'01100'];//num2str(totalAmt,1,2,1,0)];//stralpha function to remove space
 line=['FH',ledgerJournalTrans.AccountNum,strformat8,strformat9,LastFileNo+1];
   file.writeExp(line);
}
void Output_Invoice()
{
    container line;
    ledgerJournalTrans          ledgerJournalTrans,ledgerJournalTransLine,localLedgerJournalTrans;
    bankAccountTable            bankAccountTable;
    vendTable                   vendTable;
    VendTrans                   VendTrans;
    VendTransOpen               VendTransOpen;
    specTrans                   specTrans;
    Amount                      LocalAmount;
    CustVendOpenTransManager    manager;

    VendBankAccount                     vendBankAccount;
    Address                             Address;
    DirPartyTable                       DirPartyTable;
    DirPartyAddressRelationship         dirPartyAddressRelationship;
    DirPartyAddressRelationshipMapping  dirPartyAddressRelationshipMapping;
    Amount                              totalAmt;
    str                                strformat8,strformat9;
     AmountCurDebit                     curDebit,curCredit;
     int                                linesNo;
      str                                transactionTypeDRCR;
    ;
    ledgerJournalTrans  = custVendPaym.ledgerJournalTrans();
    bankAccountTable    = custVendPaym.bankAccountTable();
    vendTable           = custVendPaym.custVendTable();
   /* manager = CustVendOpenTransManager::construct(ledgerJournalTrans);
    while select VendTransOpen where vendTransOpen.AccountNum==VendTable.AccountNum
        exists join specTrans where specTrans.RefCompany==VendTransOpen.dataAreaId
        && specTrans.RefTableId==VendTransOpen.TableId
        && SpecTrans.RefRecId==VendTransOpen.RecId
    {
        if(manager.getTransMarked(VendTransOpen))
        {
            select VendTrans where vendTrans.AccountNum==VendTable.AccountNum && vendtrans.RecId==VendTransOpen.RefRecId;
            localAmount=abs(vendTransOpen.AmountCur);
            line=['ITR',ledgerJournalTrans.Voucher,VendTrans.Invoice,num2str(localAmount,1,2,0,0),'0',num2str(localAmount,1,2,0,0),vendTrans.Txt];
            file.writeExp(line);
        }
    }*/ // commeted by pankaj
    select firstonly vendBankAccount
    where vendBankAccount.VendAccount == vendTable.AccountNum
       && vendBankAccount.PHIBankFile == NoYes::Yes;
    select * from DirPartyTable where DirPartyTable.PartyId== vendTable.PartyId
    outer join dirPartyAddressRelationship where dirPartyAddressRelationship.PartyId == DirPartyTable.PartyId
    join dirPartyAddressRelationshipMapping where dirPartyAddressRelationshipMapping.PartyAddressRelationshipRecId == dirPartyAddressRelationship.RecId
    join Address where Address.RecId== dirPartyAddressRelationshipMapping.AddressRecId &&
       Address.type== AddressType::Payment;
    select sum(AmountCurDebit),sum(amountCurCredit) from localLedgerJournalTrans  where localLedgerJournalTrans.JournalNum==ledgerJournalTrans.JournalNum;
    totalAmt = abs(LedgerJournalTrans.AmountCurCredit - LedgerJournalTrans.AmountCurDebit);

      strformat8 = date2str(ledgerJournalTrans.TransDate,321,DateDay::Digits2,DateSeparator::None,DateMonth::Digits2,DateSeparator::None,DateYear::Digits4);

    while select ledgerJournalTransLine where ledgerJournalTransLine.JournalNum == ledgerJournalTrans.JournalNum
    {
     bankAccountTable = BankAccountTable::find(ledgerJournalTrans.OffsetAccount);
     if(ledgerJournalTrans.AmountCurDebit>0)
    {
    curDebit=0;
    curDebit = ledgerJournalTrans.AmountCurDebit;
    transactionTypeDRCR = '02';
    }
    else
    {
     curDebit=0;
     curDebit = ledgerJournalTrans.AmountCurCredit;
     transactionTypeDRCR = '01';
    }
    line= ['TR',ledgerJournalTrans.Voucher,strformat8,Address.CountryRegionId,vendBankAccount.AccountID,vendBankAccount.AccountNum,
    curDebit,ledgerJournalTrans.currencyCode,
          ledgerJournalTrans.PaymMode,transactionTypeDRCR,'01',bankAccountTable.AccountID,bankAccountTable.Name,ledgerJournalTrans.Txt,' ',Address.Street,Address.City,Address.State,Address.ZipCode];
    file.writeExp(line);
    }
}
str removeCommaInAddress(str _address)
{
    int                     lenAdd,remComma1,rem;
    str                     printAdd,y;
    ;
    lenAdd =  strlen(_address);
    y = _address;
    printAdd = _address;
    for(rem = 1; rem <=lenAdd; rem++)
    {
        remComma1 = strfind(y,' ',rem,1);
        if(remComma1 >0)
        {
            printAdd = strdel(y,remComma1,1);
            printAdd = strins(printAdd,' ',remComma1);
            y = printAdd;
            remComma1 = 0;
        }
    }
    printAdd = strRTrim(printAdd);
    return printAdd;
}
-------------------------------------------------------------------------------------------------------
class PHIVendOutPaym_Text_PH_New extends VendOutPaym
{
}
public void close()
{
    ;// super();
}
public classId custVendOutPaymRecordRootClassId()
{
    return classnum(PHIVendPaymRecord_Text_PH_New);
}
protected Object dialog(DialogRunbase _dialog,
                        boolean _forceOnClient)
{
    DialogRunbase dialog;
    ;
    return dialog;
}
public PaymInterfaceName interfaceName()
{
    return 'Payment text format-PH - New';
}
void open()
{
    filepath        filepath;
    PhiBankFileSeries   PhiBankFileSeries;
    #LocalCodePage
    ;
    filepath= WinAPI::browseForFolderDialog("@PHI4626","@PHI4627",true);
    phiBankFileSeries=phiBankFileSeries::find();
    PhiBankFileSeries.write();
    filename=filepath+ '\\'+'PHP'+date2str(systemdateget(),123,2,0,2,0,2)+int2str(PhiBankFileSeries::find().PHISerialNumber)+'.txt';
    file = CustVendOutPaym::newFile(filename, #cp_1252);
    if (!file || file.status() != IO_Status::Ok)
    {
        throw error(
        strfmt("@SYS19312", filename));
    }
    file.outFieldDelimiter(',');
    file.outRecordDelimiter('\r\n');
}
boolean validate()
{
    return true;
}
  • Martin Dráb Profile Picture
    Martin Dráb 228,501 Most Valuable Professional on at
    Vendor bankoutput file creation in AX 2009 process
    What is the thing you want to discuss in this forum? You've just posted some code without any explanation.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,532 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,501 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans