Showing posts with label Vendor Payment Journal. Show all posts
Showing posts with label Vendor Payment Journal. Show all posts

Wednesday, May 7, 2025

Code to get the settled invoices for a payment journal in d365fo x++

 [ExtensionOf(classStr(LedgerJournalCheckPost))]

internal final class LedgerJournalCheckpost_Extension

{

    protected void runInternal()

    {

        PROZIPPaymentJournalStaging     ZIPPaymentJournalStaging;

        VendTrans                       vendTrans,vendTransloc;

        VendSettlement                  vendSettlement;

        LedgerJournalTrans              ledgerJournalTrans;

        LedgerJournalTable              ledgerJOurnalTableloc;

 

        next runInternal();

 

        if(ledgerJournalTable.Posted == NoYes::Yes && ledgerJournalTable.JournalType == LedgerJournalType::Payment)

        {

            while select ledgerJournalTrans

                where ledgerJournalTrans.JournalNum == ledgerJournalTable.JournalNum

            {

                select vendTrans

                    where vendTrans.RecId == ledgerJournalTrans.VendTransId;

 

                while select vendSettlement

                    where vendSettlement.TransCompany == vendTrans.DataAreaId

                    && vendSettlement.TransRecId == vendTrans.RecId

                    && vendSettlement.AccountNum == vendTrans.AccountNum

                {

                    select vendTransloc

                        where vendTransloc.RecId == vendSettlement.OffsetRecid;

 

                    select ledgerJOurnalTableloc 

                        where ledgerJOurnalTableloc.JournalNum == vendTransloc.JournalNum;

 

                        ZIPPaymentJournalStaging.PROProcessingStatus    = PROProcessingStatus::Unprocessed;

                        ZIPPaymentJournalStaging.InvoiceVoucher         = vendTransloc.Voucher;

                        ZIPPaymentJournalStaging.Invoice                = vendTransloc.Invoice;

                        ZIPPaymentJournalStaging.insert();

                    }

                }

            }

        }

    }

 

}

Sunday, January 7, 2024

Generate Payment Advice Report for selected record in D365F&O X++

 Accounts Payable>Vendor Payment Journal>Lines>Print>Payment Advice

The standard report is generating for all the line records automatically, Our requirement is to generate the report for only selected record.

[ExtensionOf(classStr(BankPaymAdvicePaymentQueryGenerator))]

internal final class DaxBankPaymAdvicePaymentQueryGenerator_Extension

{

   public QueryRun getPaymentLineQueryRun(BankPaymAdviceContract _bankPaymAdviceContract)

   {

       Query query ;

       QueryRun    queryRun;

       queryRun = next getPaymentLineQueryRun(_bankPaymAdviceContract);

       query = queryRun.query();

       query.dataSourceTable(tableNum(LedgerJournalTrans)).addRange(fieldNum(LedgerJournalTrans, RecId)).value(queryValue(_bankPaymAdviceContract.parmLedgerJournalTransRecId()));

       return queryRun;

   }

}

.............................

[ExtensionOf(classStr(BankPaymAdviceUIBuilder))]

internal final class DaxBankPaymAdviceUIBuilder_Extension

{

   private DialogField dialogRecid;

   public void postRun()

   {

       next postRun();

 

       LedgerJournalTrans ledgerJournalTrans;

       BankPaymAdviceContract contract = this.dataContractObject();

       if (this.controller().parmArgs() && this.controller().parmArgs().record())

       {

           ledgerJournalTrans = this.controller().parmArgs().record() as LedgerJournalTrans;

       }

       contract.parmLedgerJournalTransRecId(ledgerJournalTrans.RecId);

   }

}

.................................

Output :






Wednesday, August 23, 2023

Code to change the Electronic payment format of vendor payment journal in D365 F&O

 My requirement is to change the exported format(NACHA) of vendor payment journal.

Standard Format (Existing):

AP>Vendor payment journal>lines>generate payements.



Code to modify the existing format :


[ExtensionOf(classStr(VendOutPaym_NACHA))]

internal final class DaxvendOutPaym_NACHA_Extension

{

   public LedgerJournalTrans  ledgerJournalTrans;

   protected container createACH_HeaderRecord()

   {

       LogisticsPostalAddress  logisticsPotalAddress;

       container   headerACH,con;

       str         value = "HD";

       str         value2,dateValue,value3,datevalue2,effectivedateloc,journalnum,amountcurdebit,accountid,vendorid;

                 

       #define.spc(' ')

       str 50      aditonalname            =   strRep(#spc, 50); //to get spaces of length 50

       value3      = "PYCHK";

       dateValue   = date2str( systemDateGet(),

                       321,

                       DateDay::Digits2,

                       DateSeparator::Hyphen,

                       DateMonth::Digits2,

                       DateSeparator::Hyphen,

                       DateYear::Digits4,

                       DateFlags::FormatAll);

       effectivedateloc = date2str( effectiveEntDate,

                       321,

                       DateDay::Digits2,

                       DateSeparator::Hyphen,

                       DateMonth::Digits2,

                       DateSeparator::Hyphen,

                       DateYear::Digits4,

                       DateFlags::FormatAll);

 

       headerACH = next createACH_HeaderRecord();

       CompanyInfo     companyInfo = CompanyInfo::find();

       //while

       select ledgerJournalTrans where ledgerJournalTrans.JournalNum == ledgerJournalId;

       vendorid = LedgerDimensionFacade::getDisplayValueForLedgerDimension(ledgerJournalTrans.LedgerDimension);

       if(ledgerJournalTrans.PaymentStatus == CustVendPaymStatus::None)

       {

           select logisticsPotalAddress

           where logisticsPotalAddress.Location == ledgerJournalTrans.RemittanceLocation;

           //{

           value2 = ledgerJournalTrans.PaymReference;

           if(ledgerJournalTrans.AmountCurCredit)

           {

               value3 = value3 + "C";

           }

           if(ledgerJournalTrans.AmountCurDebit)

           {

               value3 = value3 + "D";

           }

           datevalue2 = date2str( ledgerJournalTrans.TransDate,

                       321,

                       DateDay::Digits2,

                       DateSeparator::Hyphen,

                       DateMonth::Digits2,

                       DateSeparator::Hyphen,

                       DateYear::Digits4,

                       DateFlags::FormatAll);

           amountcurdebit = strRFix(any2Str(ledgerJournalTrans.AmountCurDebit),16,'0');

           // }

           value2 = strRFix(value2,15,'0');

           journalnum = strLFix(ledgerJournalId,30,' ');

           accountid = strLFix(bankAccountTable.AccountID,35,' ');

 

           headerACH = conNull();

           con = conIns(headerACH,1,value + value2 + dateValue + "\n" + value3 + journalnum

                   + datevalue2 + effectivedateloc + effectivedateloc + amountcurdebit + "." + any2Str(ledgerJournalTrans.AmountCurDebit));

           return con;

       }

       else

       {

           return headerACH;

       }   

   }

   protected container createBatchHeaderRecord()

   {

       container   headerBatch;

       headerBatch =  next createBatchHeaderRecord();

       if(ledgerJournalTrans.PaymentStatus == CustVendPaymStatus::None)

       {

           headerBatch = conNull();

           return headerBatch;

       }

       else

       {

           return headerBatch;

       }

   }

   protected container createBatchControlRecord()

   {

       container   headerBatch;

       headerBatch = next createBatchControlRecord();

       if(ledgerJournalTrans.PaymentStatus == CustVendPaymStatus::None)

       {

           headerBatch = conNull();

           return headerBatch;

       }

       else

       {

           return headerBatch;

       }

   }

 

   protected container createACH_ControlRecord()

   {

       container   headerBatch;

       container  contai;

       str  con = "lohith";

       headerBatch = next createACH_ControlRecord();

       if(ledgerJournalTrans.PaymentStatus == CustVendPaymStatus::None)

       {

           headerBatch = conNull();

           return headerBatch;

       }

       else

       {

           return headerBatch;

       }

   }

}

..............................

[ExtensionOf(classstr(VendOutPaymRecord_NACHA_CCD))]

internal final class DaxVendOutpaymRecord_NACHA_CCD_Extension

{

   protected void initRecord()

   {

       next initRecord();

       outputRecord = "";

   }

}


OutPut :








Wednesday, July 26, 2023

Export of vendor payment journal info message to JSON format in D365 X++

 My requirement is to export the vendor payment journal to JSON format through custom button.

And to generate the response in JSON file based on validations occured.

Custom button clicked Event Handler :

internal final class DaxLedgerJournalTable_EventHandler

{

   /// </summary>

   /// <param name="sender"></param>

   /// <param name="e"></param>

   [FormControlEventHandler(formControlStr(LedgerJournalTable, Json), FormControlEventType::Clicked)]

   public static void Json_OnClicked(FormControl sender, FormControlEventArgs e)

   {

       MenuFunction                    menuFunction;

       FormRun formRun                 = sender.formRun();

       FormDataSource                  LedgerJournalTable_ds = formRun.dataSource(1);

       LedgerJournalCheckpost          _ledgerJournalCheckpost;

       str                             message,msg,info,setvalue;

       container                       con;

       Set                             setOne;

       SetEnumerator                   enumerator;

       setOne                          = new Set(types::String);

       LedgerJournalTable              ledgerJournalTable;

       ledgerJournalTable              = LedgerJournalTable_ds.cursor();

       LedgerJournalTrans              ledgerJournalTrans;

       System.IO.StringWriter          stringWriter;

       Newtonsoft.Json.JsonTextWriter  jsonWriter;

       stringWriter                    = new System.IO.StringWriter();

//validation

       ledgerJournalTable              = LedgerJournalTable::find(ledgerjournaltable.JournalNum);

       _LedgerJournalCheckPost         = LedgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTable,NoYes::No);

       _LedgerJournalCheckPost.run();

       message                         = _LedgerJournalCheckPost.parmErrorMsg();

       if(message)

       {

           msg             = Global::parmSysInfologStr();

       }

       info                = Global::parminfo();

       if(info != "Journal is OK.")

       {

           con = str2con(info);

       }

       setOne.add(message);

       setOne.add(msg);

       enumerator = setOne.getEnumerator();

       while (enumerator.moveNext())

       {

           setvalue += enumerator.current();

       }

       con = conIns(con,1,setvalue);

       jsonWriter                      = new Newtonsoft.Json.JsonTextWriter(stringWriter);

       jsonWriter.WriteStartObject();// add '{'

       jsonWriter.WritePropertyName("Journal Num");

       jsonWriter.WriteValue(ledgerJournalTable.JournalNum);

       jsonWriter.WritePropertyName("Journal Name");

       jsonWriter.WriteValue(ledgerJournalTable.JournalName);

       jsonWriter.WritePropertyName("Lines");

       jsonWriter.WriteStartArray();

       while select ledgerJournalTrans

           where ledgerJournalTrans.JournalNum == ledgerjournaltable.JournalNum

       {

           jsonWriter.WriteStartObject();// add '{'

           jsonWriter.WritePropertyName("Voucher");

           jsonWriter.WriteValue(ledgerJournalTrans.Voucher);

           jsonWriter.WritePropertyName("Vendor Name");

           jsonWriter.WriteValue(ledgerJournalTrans.LedgerDimensionName);

           jsonWriter.WriteEndObject(); // add '}'

       }

       jsonWriter.WriteEndArray(); //add ']'

       jsonWriter.WriteEndObject(); //add '}'

       if(info == "Journal is OK." && !msg && !message)

       {

           jsonWriter.WriteStartObject();

           jsonWriter.WritePropertyName("Response");

           jsonWriter.WriteStartArray();

           jsonWriter.WriteStartObject();// add '{'

           jsonWriter.WritePropertyName("Status");

           jsonWriter.WriteValue("Success");

           jsonWriter.WritePropertyName("Remark");

           jsonWriter.WriteValue(info);

       }

       else

       {

           jsonWriter.WriteStartObject();

           jsonWriter.WritePropertyName("Response");

           jsonWriter.WriteStartArray();

           jsonWriter.WriteStartObject();// add '{'

           jsonWriter.WritePropertyName("Status");

           jsonWriter.WriteValue("Failed");

           jsonWriter.WritePropertyName("Remark");

           jsonWriter.WriteValue(con2Str(con));

       }

       jsonWriter.WriteEndObject();

       jsonWriter.WriteEndArray();

       jsonWriter.WriteEndObject();

       info(strFmt("%1,",stringWriter.ToString()));

       //info(strFmt("my message %1", message)); //Warnings

       //info(strFmt("my msg %1", msg)); //warnings

       //info(strFmt("my info %1", info)); // info's

   }

}

Code to get warnings and info messages :

[ExtensionOf(classStr(Global))]

static final class DaxGlobal_Extension

{

   public static SysInfologStr  message;

   public static SysInfologStr  info;

   static boolean checkFailed(SysInfoLogStr txt, URL helpURL, SysInfoAction _sysInfoAction)

   {

       boolean     ret;

       ret = next checkFailed(txt,helpURL,_sysInfoAction);

       Global::parmSysInfologStr(txt);

       return ret;

   }

   static SysInfologStr parmSysInfologStr(SysInfologStr  _message = message)

   {

       message = getPrefix()+_message;

       return message;

   }

   static SysInfologStr parminfo(SysInfologStr  _info = info)

   {

       info = getPrefix()+_info;

       return info;

   }

   static Exception info(SysInfoLogStr txt, URL helpUrl, SysInfoAction _sysInfoAction)

   {

       boolean     ret;

       ret =next info(txt,helpUrl,_sysInfoAction);

       Global::parminfo(txt);

       return ret;

   }

}

Code to get the current record validation message :

[ExtensionOf(classStr(LedgerPostingMessageLog))]

internal final class DaxLedgerPostingMessageLog_Extension

{

   public SysInfologStr message;

   public boolean logCheckFailed(SysInfologStr _message, URL _helpURL)

   {

       boolean ret;

       ret= next logCheckFailed(_message,_helpURL);

       this.parmSysInfologStr(_message);

       return ret;

   }

   public SysInfologStr parmSysInfologStr(SysInfologStr  _message = message)

   {

       message = _message;

       return message;

   } 

}

Code to get the above class message in ledgerjournalcheckpost for use in custom button :

[ExtensionOf(classstr(LedgerJournalCheckPost))]

internal final class Dax_LedgerJournalCheckpost_Extension

{

   public SysInfologStr message;

   protected boolean checkJournalStatus()

   {

       boolean ret;

       ret = next checkJournalStatus();

       message = getPrefix() + ledgerPostingMessageCollection.parmSysInfologStr();

       return ret;

   }

   public SysInfologStr parmErrorMsg()

   {

       return message;

   }

}


Output :





Other Simplest way to get Info Message is :

Validation(info message)  is saved in Log field of Ledger Journal Table.