RSS

Create Payment Journal with X++

20 Jun

static server boolean processCheckPayment(CheckModule _checkModule)
{
LedgerJournalName ledgerJournalName;
LedgerJournalTable ledgerJournalTable;
LedgerJournalTrans ledgerJournalTrans;
LedgerJournalCheckPost ledgerJournalCheckPost;

Common common;
NumberSeq numberseq;
CustTrans custTrans;
CustTransOpen custTransOpen;
Specification specOffsetVoucher;

Parameters parameters = Parameters::find();
CustTable custTable = CustTable::find(_checkModule.CustAccount);
boolean result = false;
InvoiceId invoiceId;
;

while select custTransOpen
where custTransOpen.RefRecIdCheck == _checkModule.RecId &&
custTransOpen.UseRefRecId
{
custTrans = custTransOpen.custTrans();
invoiceId = custTrans.Invoice;

try
{
ttsbegin;

select firstonly ledgerJournalName
where ledgerJournalName.JournalName == parameters.LedgerJournalNameId &&
ledgerJournalName.JournalType == LedgerJournalType::CustPayment;

if(!ledgerJournalName.RecId)
throw error(“@CAM184”);

if(ledgerJournalName)
{
ledgerJournalTable.JournalName = ledgerJournalName.JournalName;
ledgerJournalTable.Name = ledgerJournalName.Name;
ledgerJournalTable.insert();

if(ledgerJournalTable)
{
numberseq = NumberSeq::NewGetVoucherFromCode(ledgerJournalName.VoucherSeries);
ledgerJournalTrans.JournalNum = ledgerJournalTable.JournalNum;
ledgerJournalTrans.Voucher = numberseq.voucher();
ledgerJournalTrans.TransDate = today();
ledgerJournalTrans.AccountType = LedgerJournalACType::Cust;
ledgerJournalTrans.Txt = CustTable::find(ledgerJournalTrans.AccountNum).Name;
ledgerJournalTrans.OffsetAccountType = ledgerJournalName.OffsetAccountType;
ledgerJournalTrans.OffsetAccount = ledgerJournalName.OffsetAccount;
ledgerJournalTrans.Dimension = ledgerJournalName.Dimension;
ledgerJournalTrans.CurrencyCode = ledgerJournalTable.CurrencyCode;
ledgerJournalTrans.ExchRate = ExchRates::find(ledgerJournalTable.CurrencyCode, datenull(), NoYes::No, NoYes::No).ExchRate;
ledgerJournalTrans.TransactionType = LedgerTransType::Payment;
ledgerJournalTrans.PaymMode = parameters.PaymMode;
ledgerJournalTrans.SettleVoucher = SettlementType::SelectedTransact;
ledgerJournalTrans.AccountNum = custTable.AccountNum;
ledgerJournalTrans.AmountCurCredit = custTransOpen.AmountCur;
ledgerJournalTrans.insert();

select custTransOpen
where custTransOpen.AccountNum == custTable.AccountNum &&
custTransOpen.RefRecId == CustTrans::findFromInvoice(invoiceId).RecId;

if(custTransOpen)
{
common = ledgerJournalTrans;
specOffsetVoucher = Specification_OffsetVoucher::newCommon(common, true);
if (!specOffsetVoucher.isMarked(custTransOpen.TableId, custTransOpen.RecId))
if (ledgerJournalTrans.RecId)
specOffsetVoucher.create(custTransOpen.TableId, custTransOpen.RecId, custTransOpen.AmountCur, ledgerJournalTable.CurrencyCode);
}

ledgerJournalCheckPost = LedgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTable, NoYes::Yes);
ledgerJournalCheckPost.run();
result = true;
}
}
ttscommit;
}
catch
{
ttsabort;
result = false;
}
}
return result;
}

 
Leave a comment

Posted by on June 20, 2012 in X++

 

Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
365 by Thijs

Blogging about Microsoft 365, Azure and Automation!

axhowto

Blog about ax with sample codes, tips and tricks.

GM Dynamics Blogs

Transform IT with Digital Trasformation and Social Innovation

Ms. Dynamic Millennial

Unboxing Microsoft Dynamics 365 for Finance and Operations

DynaD365Power

Exploring the new vision of the Power platform

Dynamics Vision 365

The FinOps pulse

Breaking Bong

I write when no one is watching

ErpCoder

Microsoft Dynamics 365 Business Management Solution Enthusiast

Dynamics 365 Finance

Dynamics 365 Finance & Much More.

Microsoft Dynamics AX

“ANYONE WHO STOPS LEARNING IS OLD, WHETHER AT TWENTY OR EIGHTY.” —HENRY FORD

Sumit Potbhare

Dynamics 365 for Commerce

iotsolution.se

This is your site about D365 (Finance and Supply Chain Management), IoT (Internet of Things) and HoloLens

Omni 365

Dynamics 365 Finance and Operations Blog

DIY D365

Power Platform Done Your Way

%d bloggers like this: