Hi guys ,
This is the most common requirement these days that the customer wants to create a payment journal automatically on triggering of certain events in D365 Fin Ops.
In the below example we are taking the values from a data entity and create payment journal accordingly for each record of this entity :-
#OCCRetryCount
int64 dim;
CustInvoiceTable custInvoiceTable_loc;
Counter progressCount,progressTotal;
Ledgerjournalname ledgerjournalname;
LedgerjournalTable LedgerjournalTable;
LedgerjournalTrans LedgerjournalTrans;
CustTable custtable_loc;
NumberSeq numberSeq;
CustParameters custParametersExt;
CustInvoiceTrans custInvoiceTrans;
CustInvoiceJour custInvoiceJour;
PaymentJournalDetailsEntity paymentjour , paymentjourupdate;
SalesTable salestbl;
DimensionAttribute dimBusinessUnitAttribute , dimProfitCenterAttribute ;
DimensionAttributeValue dimAttributeBusinessUnitValue, dimAttributeProfitCenterValue;
DimensionDefault defaultDimension;
DimensionAttributeValueSetItem dimensionAttributeValueSetItem;
DimensionDynamicAccount ledgerDim;
Currency currencydet;
DimensionAttributeValueSetStorage dimStorage = new DimensionAttributeValueSetStorage();
try
{
select * from custParametersExt;
if(custParametersExt.EnablePaymentJournalIntegration==NoYes::Yes)
{
while select paymentjour where paymentjour.UpdateFlag==0
{
custtable_loc = CustTable::find(paymentjour.CustomerAccount);
select currencydet where currencydet.CurrencyCode==paymentjour.Currency;
select dimensionAttributeValueSetItem where dimensionAttributeValueSetItem.DisplayValue==paymentjour.BusinessUnit;
select dimensionAttributeValueSetItem1 where dimensionAttributeValueSetItem1.DisplayValue==paymentjour.ProfitCenter;
if(custtable_loc)
{
if(currencydet)
{
if(dimensionAttributeValueSetItem)
{
ledgerDim = LedgerDynamicAccountHelper::getDynamicAccountFromAccountNumber
(paymentjour.CustomerAccount,LedgerJournalACType::Cust);
select custInvoiceTrans where custInvoiceTrans.InvoiceId==custInvoiceJour.InvoiceId;
select ledgerjournalname where ledgerjournalname.JournalName == custParametersExt.PaymentJournalName;
ttsBegin;
LedgerjournalTable.JournalName = custParametersExt.PaymentJournalName;
LedgerjournalTable.initFromLedgerJournalName();
LedgerjournalTable.JournalNum = JournalTableData::newTable(LedgerjournalTable).nextJournalId();
if(paymentjour.InvoiceId!="" && paymentjour.MethodofPayment!="")
{
LedgerjournalTable.Name = paymentjour.InvoiceId + " - " + paymentjour.MethodofPayment;
}
if(paymentjour.InvoiceId=="" && paymentjour.MethodofPayment=="")
{
LedgerjournalTable.Name = paymentjour.SalesID;
}
if(paymentjour.InvoiceId!="" && paymentjour.MethodofPayment=="")
{
LedgerjournalTable.Name = paymentjour.InvoiceId + " - " + paymentjour.SalesID;
}
if(paymentjour.InvoiceId=="" && paymentjour.MethodofPayment!="")
{
LedgerjournalTable.Name = paymentjour.SalesID + " - " + paymentjour.MethodofPayment;
}
LedgerjournalTable.insert();
if(ledgerjournalname)
{
numberSeq = NumberSeq::newGetVoucherFromId((
ledgerjournalname.NumberSequenceTable));
LedgerjournalTrans.Voucher = numberSeq.voucher();
LedgerjournalTrans.JournalNum = LedgerjournalTable.JournalNum;
LedgerjournalTrans.AccountType = LedgerJournalACType::Cust;
LedgerjournalTrans.Company = curext();
LedgerjournalTrans.parmAccount(custtable_loc.AccountNum,
LedgerjournalTrans.AccountType);
LedgerjournalTrans.CurrencyCode = paymentjour.Currency;
LedgerjournalTrans.TransDate = paymentjour.TransDate;
LedgerjournalTrans.Txt = LedgerjournalTable.Name;
LedgerjournalTrans.DefaultDimension = custtable_loc.DefaultDimension;
defaultDimension = LedgerjournalTrans.DefaultDimension;
dimStorage = DimensionAttributeValueSetStorage::find(defaultDimension);
dimBusinessUnitAttribute = DimensionAttribute::findByName('BusinessUnit');
dimProfitCenterAttribute = DimensionAttribute::findByName('CostCenter');
dimAttributeBusinessUnitValue= DimensionAttributeValue::findByDimensionAttributeAndValue
(dimBusinessUnitAttribute,paymentjour.BusinessUnit , true, true);
dimAttributeProfitCenterValue = DimensionAttributeValue::findByDimensionAttributeAndValue
(dimProfitCenterAttribute,paymentjour.ProfitCenter , true, true);
dimStorage.addItem(dimAttributeBusinessUnitValue);
dimStorage.addItem(dimAttributeProfitCenterValue);
LedgerjournalTrans.DefaultDimension = dimStorage.save();
LedgerjournalTrans.TransactionType = LedgerTransType::Payment;
LedgerjournalTrans.LedgerDimension = ledgerDim;
LedgerjournalTrans.AmountCurCredit = paymentjour.Amount;
LedgerjournalTrans.insert();
}
ttscommit;
if(LedgerjournalTable && LedgerjournalTrans)
{
ttsbegin;
select forupdate paymentjourupdate where paymentjourupdate.RecId==paymentjour.RecId;
paymentjourupdate.UpdateFlag=1;
paymentjourupdate.update();
ttscommit;
}
}
}
}
}
}
}
catch(Exception::Error)
{
throw error('Payment Journal Creation Failed');
}
catch(Exception::Deadlock)
{
retry;
}
catch(Exception::UpdateConflict)
{
if(appl.ttsLevel()==0)
{
if(xSession::currentRetryCount()>=#RetryNum)
{
throw exception::UpdateConflictNotRecovered;
}
else
{
retry;
}
}
else
{
throw exception::UpdateConflict;
}
}
This is the most common requirement these days that the customer wants to create a payment journal automatically on triggering of certain events in D365 Fin Ops.
In the below example we are taking the values from a data entity and create payment journal accordingly for each record of this entity :-
#OCCRetryCount
int64 dim;
CustInvoiceTable custInvoiceTable_loc;
Counter progressCount,progressTotal;
Ledgerjournalname ledgerjournalname;
LedgerjournalTable LedgerjournalTable;
LedgerjournalTrans LedgerjournalTrans;
CustTable custtable_loc;
NumberSeq numberSeq;
CustParameters custParametersExt;
CustInvoiceTrans custInvoiceTrans;
CustInvoiceJour custInvoiceJour;
PaymentJournalDetailsEntity paymentjour , paymentjourupdate;
SalesTable salestbl;
DimensionAttribute dimBusinessUnitAttribute , dimProfitCenterAttribute ;
DimensionAttributeValue dimAttributeBusinessUnitValue, dimAttributeProfitCenterValue;
DimensionDefault defaultDimension;
DimensionAttributeValueSetItem dimensionAttributeValueSetItem;
DimensionDynamicAccount ledgerDim;
Currency currencydet;
DimensionAttributeValueSetStorage dimStorage = new DimensionAttributeValueSetStorage();
try
{
select * from custParametersExt;
if(custParametersExt.EnablePaymentJournalIntegration==NoYes::Yes)
{
while select paymentjour where paymentjour.UpdateFlag==0
{
custtable_loc = CustTable::find(paymentjour.CustomerAccount);
select currencydet where currencydet.CurrencyCode==paymentjour.Currency;
select dimensionAttributeValueSetItem where dimensionAttributeValueSetItem.DisplayValue==paymentjour.BusinessUnit;
select dimensionAttributeValueSetItem1 where dimensionAttributeValueSetItem1.DisplayValue==paymentjour.ProfitCenter;
if(custtable_loc)
{
if(currencydet)
{
if(dimensionAttributeValueSetItem)
{
ledgerDim = LedgerDynamicAccountHelper::getDynamicAccountFromAccountNumber
(paymentjour.CustomerAccount,LedgerJournalACType::Cust);
select custInvoiceTrans where custInvoiceTrans.InvoiceId==custInvoiceJour.InvoiceId;
select ledgerjournalname where ledgerjournalname.JournalName == custParametersExt.PaymentJournalName;
ttsBegin;
LedgerjournalTable.JournalName = custParametersExt.PaymentJournalName;
LedgerjournalTable.initFromLedgerJournalName();
LedgerjournalTable.JournalNum = JournalTableData::newTable(LedgerjournalTable).nextJournalId();
if(paymentjour.InvoiceId!="" && paymentjour.MethodofPayment!="")
{
LedgerjournalTable.Name = paymentjour.InvoiceId + " - " + paymentjour.MethodofPayment;
}
if(paymentjour.InvoiceId=="" && paymentjour.MethodofPayment=="")
{
LedgerjournalTable.Name = paymentjour.SalesID;
}
if(paymentjour.InvoiceId!="" && paymentjour.MethodofPayment=="")
{
LedgerjournalTable.Name = paymentjour.InvoiceId + " - " + paymentjour.SalesID;
}
if(paymentjour.InvoiceId=="" && paymentjour.MethodofPayment!="")
{
LedgerjournalTable.Name = paymentjour.SalesID + " - " + paymentjour.MethodofPayment;
}
LedgerjournalTable.insert();
if(ledgerjournalname)
{
numberSeq = NumberSeq::newGetVoucherFromId((
ledgerjournalname.NumberSequenceTable));
LedgerjournalTrans.Voucher = numberSeq.voucher();
LedgerjournalTrans.JournalNum = LedgerjournalTable.JournalNum;
LedgerjournalTrans.AccountType = LedgerJournalACType::Cust;
LedgerjournalTrans.Company = curext();
LedgerjournalTrans.parmAccount(custtable_loc.AccountNum,
LedgerjournalTrans.AccountType);
LedgerjournalTrans.CurrencyCode = paymentjour.Currency;
LedgerjournalTrans.TransDate = paymentjour.TransDate;
LedgerjournalTrans.Txt = LedgerjournalTable.Name;
LedgerjournalTrans.DefaultDimension = custtable_loc.DefaultDimension;
defaultDimension = LedgerjournalTrans.DefaultDimension;
dimStorage = DimensionAttributeValueSetStorage::find(defaultDimension);
dimBusinessUnitAttribute = DimensionAttribute::findByName('BusinessUnit');
dimProfitCenterAttribute = DimensionAttribute::findByName('CostCenter');
dimAttributeBusinessUnitValue= DimensionAttributeValue::findByDimensionAttributeAndValue
(dimBusinessUnitAttribute,paymentjour.BusinessUnit , true, true);
dimAttributeProfitCenterValue = DimensionAttributeValue::findByDimensionAttributeAndValue
(dimProfitCenterAttribute,paymentjour.ProfitCenter , true, true);
dimStorage.addItem(dimAttributeBusinessUnitValue);
dimStorage.addItem(dimAttributeProfitCenterValue);
LedgerjournalTrans.DefaultDimension = dimStorage.save();
LedgerjournalTrans.TransactionType = LedgerTransType::Payment;
LedgerjournalTrans.LedgerDimension = ledgerDim;
LedgerjournalTrans.AmountCurCredit = paymentjour.Amount;
LedgerjournalTrans.insert();
}
ttscommit;
if(LedgerjournalTable && LedgerjournalTrans)
{
ttsbegin;
select forupdate paymentjourupdate where paymentjourupdate.RecId==paymentjour.RecId;
paymentjourupdate.UpdateFlag=1;
paymentjourupdate.update();
ttscommit;
}
}
}
}
}
}
}
catch(Exception::Error)
{
throw error('Payment Journal Creation Failed');
}
catch(Exception::Deadlock)
{
retry;
}
catch(Exception::UpdateConflict)
{
if(appl.ttsLevel()==0)
{
if(xSession::currentRetryCount()>=#RetryNum)
{
throw exception::UpdateConflictNotRecovered;
}
else
{
retry;
}
}
else
{
throw exception::UpdateConflict;
}
}
So with this 'twenty-twenty hindsight.' I have noticed I have subconsciously been sabotaging my life and my online business for many years. Billdu invoice generator online
ReplyDelete