Using DMF creating Payment journal and mark the settle lines :
We need to extend CustomerPaymentJournalLineEntity - Data entity.
[ExtensionOf(tableStr(CustomerPaymentJournalLineEntity))]
Final class CustomerPaymentJournalLineEntity_CIT_Extension
{
[PostHandlerFor(tableStr(CustomerPaymentJournalLineEntity), tableMethodStr(CustomerPaymentJournalLineEntity, mapEntityToDataSource))]
public static void CustomerPaymentJournalLineEntity_Post_mapEntityToDataSource(XppPrePostArgs args)
{
CustTable custtable;
CustomerPaymentJournalLineEntity customerPaymentJournalLineEntity = args.getThis() as CustomerPaymentJournalLineEntity;
custtable = CustTable::find(customerPaymentJournalLineEntity.AccountDisplayValue);
DataEntityDataSourceRuntimeContext dataSourceCtx = args.getArg(identifierStr(_dataSourceCtx));
switch (dataSourceCtx.name())
{
case dataEntityDataSourceStr(CustomerPaymentJournalLineEntity, LedgerJournalTrans):
LedgerJournalTrans ledgerJournalTrans = dataSourceCtx.getBuffer();
ledgerJournalTrans.initFromCustTable(custtable);
/*if(!ledgerJournalTrans.MarkedInvoice)
{
ledgerJournalTrans.CITErrorLog = NoYes::Yes; // if any error occurs while importing record from file a field added to ledgerjournaltrans to notify it.
}*/
if ( LedgerJournalTrans.MarkedInvoice)
{
if(!CustTrans::findFromInvoice(ledgerJournalTrans.MarkedInvoice).RecId)
{
ledgerJournalTrans.CITErrorLog = NoYes::Yes;
}
}
break;
}
}
[DataEventHandler(tableStr(CustomerPaymentJournalLineEntity), DataEventType::PersistedEntity)]
public static void CustomerPaymentJournalLineEntity_onPersistedEntity(Common _sender, DataEventArgs _eventArgs)
{
CustomerPaymentJournalLineEntity customerPaymentJournalLineEntity = _sender;
LedgerJournalTrans ledgerJournalTrans;
while select ledgerJournalTrans where customerPaymentJournalLineEntity.JournalBatchNumber == ledgerJournalTrans.JournalNum
&& customerPaymentJournalLineEntity.LineNumber == ledgerJournalTrans.LineNum
{
CustomerPaymentJournalLineEntity::insertLinesForLineLevelSettlement(ledgerJournalTrans,customerPaymentJournalLineEntity.CITDiscountAmount);
}
}
private static void insertLinesForLineLevelSettlement(LedgerJournalTrans _ledgerJournalTrans, Amount _cashDisc)
{
CustTransOpen custTransOpen;
custTrans custTrans;
CustVendOpenTransManager manager;
CustTransCashDisc custTransCashDisc;
Select custTransOpen where custTransOpen.accountNum == _ledgerJournalTrans.accountDisplay()
Join custTrans where custTrans.Invoice == _ledgerJournalTrans.MarkedInvoice && custTrans.RecId == custTransOpen.RefrecId;
If (custTransOpen)
{
if (_cashDisc)
{
custTransCashDisc.CashDiscAmount = _cashDisc;
custTransCashDisc.CashDiscdate = systemdateget();
custTransCashDisc.RefRecId = custTransOpen.RecId;
custTransCashDisc.RefTableId = custTransOpen.TableId;
custTransCashDisc.insert();
}
/*
manager = CustVendOpenTransManager::construct(_ledgerJournalTrans);
manager.updateSettleAmount(custTransOpen,_ledgerJournalTrans.AmountCurCredit);
manager.updateTransMarked(custTransOpen,true);
*/
SpecTrans specTrans;
specTrans.SpecCompany = _ledgerJournalTrans.DataAreaId;
specTrans.SpecRecId = _ledgerJournalTrans.RecId;
specTrans.SpecTableId = _ledgerJournalTrans.TableId;
specTrans.RefCompany = custTransOpen.DataAreaId;
specTrans.RefRecId = custTransOpen.RecId;
specTrans.RefTableId = custTransOpen.TableId;
specTrans.code = _ledgerJournalTrans.CurrencyCode;
specTrans.Balance01 = _ledgerJournalTrans.AmountCurCredit;
specTrans.Payment = NoYes::No;
specTrans.SelectedDateUsedToCalcCashDisc = today();
specTrans.insert();
ttsBegin;
_ledgerJournalTrans.selectForUpdate(true);
_ledgerJournalTrans.SettleVoucher = SettlementType::SelectedTransact;
_ledgerJournalTrans.update();
ttsCommit;
}
}
}
=======================================================================
To Address discount while importing File:
Extend CustomerPaymentJournalLineEntity and add CITDiscountAmount.
If you want any of the fields to get populated from file values we need to add these fields if not exists
Ex: Document Number
We need to extend CustomerPaymentJournalLineEntity - Data entity.
[ExtensionOf(tableStr(CustomerPaymentJournalLineEntity))]
Final class CustomerPaymentJournalLineEntity_CIT_Extension
{
[PostHandlerFor(tableStr(CustomerPaymentJournalLineEntity), tableMethodStr(CustomerPaymentJournalLineEntity, mapEntityToDataSource))]
public static void CustomerPaymentJournalLineEntity_Post_mapEntityToDataSource(XppPrePostArgs args)
{
CustTable custtable;
CustomerPaymentJournalLineEntity customerPaymentJournalLineEntity = args.getThis() as CustomerPaymentJournalLineEntity;
custtable = CustTable::find(customerPaymentJournalLineEntity.AccountDisplayValue);
DataEntityDataSourceRuntimeContext dataSourceCtx = args.getArg(identifierStr(_dataSourceCtx));
switch (dataSourceCtx.name())
{
case dataEntityDataSourceStr(CustomerPaymentJournalLineEntity, LedgerJournalTrans):
LedgerJournalTrans ledgerJournalTrans = dataSourceCtx.getBuffer();
ledgerJournalTrans.initFromCustTable(custtable);
/*if(!ledgerJournalTrans.MarkedInvoice)
{
ledgerJournalTrans.CITErrorLog = NoYes::Yes; // if any error occurs while importing record from file a field added to ledgerjournaltrans to notify it.
}*/
if ( LedgerJournalTrans.MarkedInvoice)
{
if(!CustTrans::findFromInvoice(ledgerJournalTrans.MarkedInvoice).RecId)
{
ledgerJournalTrans.CITErrorLog = NoYes::Yes;
}
}
break;
}
}
[DataEventHandler(tableStr(CustomerPaymentJournalLineEntity), DataEventType::PersistedEntity)]
public static void CustomerPaymentJournalLineEntity_onPersistedEntity(Common _sender, DataEventArgs _eventArgs)
{
CustomerPaymentJournalLineEntity customerPaymentJournalLineEntity = _sender;
LedgerJournalTrans ledgerJournalTrans;
while select ledgerJournalTrans where customerPaymentJournalLineEntity.JournalBatchNumber == ledgerJournalTrans.JournalNum
&& customerPaymentJournalLineEntity.LineNumber == ledgerJournalTrans.LineNum
{
CustomerPaymentJournalLineEntity::insertLinesForLineLevelSettlement(ledgerJournalTrans,customerPaymentJournalLineEntity.CITDiscountAmount);
}
}
private static void insertLinesForLineLevelSettlement(LedgerJournalTrans _ledgerJournalTrans, Amount _cashDisc)
{
CustTransOpen custTransOpen;
custTrans custTrans;
CustVendOpenTransManager manager;
CustTransCashDisc custTransCashDisc;
Select custTransOpen where custTransOpen.accountNum == _ledgerJournalTrans.accountDisplay()
Join custTrans where custTrans.Invoice == _ledgerJournalTrans.MarkedInvoice && custTrans.RecId == custTransOpen.RefrecId;
If (custTransOpen)
{
if (_cashDisc)
{
custTransCashDisc.CashDiscAmount = _cashDisc;
custTransCashDisc.CashDiscdate = systemdateget();
custTransCashDisc.RefRecId = custTransOpen.RecId;
custTransCashDisc.RefTableId = custTransOpen.TableId;
custTransCashDisc.insert();
}
/*
manager = CustVendOpenTransManager::construct(_ledgerJournalTrans);
manager.updateSettleAmount(custTransOpen,_ledgerJournalTrans.AmountCurCredit);
manager.updateTransMarked(custTransOpen,true);
*/
SpecTrans specTrans;
specTrans.SpecCompany = _ledgerJournalTrans.DataAreaId;
specTrans.SpecRecId = _ledgerJournalTrans.RecId;
specTrans.SpecTableId = _ledgerJournalTrans.TableId;
specTrans.RefCompany = custTransOpen.DataAreaId;
specTrans.RefRecId = custTransOpen.RecId;
specTrans.RefTableId = custTransOpen.TableId;
specTrans.code = _ledgerJournalTrans.CurrencyCode;
specTrans.Balance01 = _ledgerJournalTrans.AmountCurCredit;
specTrans.Payment = NoYes::No;
specTrans.SelectedDateUsedToCalcCashDisc = today();
specTrans.insert();
ttsBegin;
_ledgerJournalTrans.selectForUpdate(true);
_ledgerJournalTrans.SettleVoucher = SettlementType::SelectedTransact;
_ledgerJournalTrans.update();
ttsCommit;
}
}
}
=======================================================================
To Address discount while importing File:
Extend CustomerPaymentJournalLineEntity and add CITDiscountAmount.
If you want any of the fields to get populated from file values we need to add these fields if not exists
Ex: Document Number
No comments:
Post a Comment