Here my requirement is to create and post a journal using postman json format input file.
1. DTT_PostingProfile
internal final class DTT_RequestContractClass
{
str LegalEntity;
str Process;
date TransactionDate;
real Volume;
str AllocationAccount;
str WaterAuthority;
str SourceTradingZone;
str UseTradingZone;
str ApplicationId;
str TransactionText;
[DataMemberAttribute("LegalEntity")]
public str parmLegalEntity(str _legalEntity = LegalEntity)
{
LegalEntity = _legalEntity;
return LegalEntity;
}
[DataMemberAttribute("Process")]
public str parmProcess(str _Process = Process)
{
Process = _Process;
return Process;
}
[DataMemberAttribute("TransactionDate")]
public date parmTransactionDate(date _TransactionDate = TransactionDate)
{
TransactionDate = _TransactionDate;
return TransactionDate;
}
[DataMemberAttribute("Volume")]
public real parmVolume(real _Volume = Volume)
{
Volume = _Volume;
return Volume;
}
[DataMemberAttribute("AllocationAccount")]
public str parmAllocationAccount(str _AllocationAccount = AllocationAccount)
{
AllocationAccount = _AllocationAccount;
return AllocationAccount;
}
[DataMemberAttribute("WaterAuthority/WaterCorporation")]
public str parmWaterAuthority(str _WaterAuthority = WaterAuthority)
{
WaterAuthority = _WaterAuthority;
return WaterAuthority;
}
[DataMemberAttribute("SourceTradingZone")]
public str parmSourceTradingZone(str _SourceTradingZone = SourceTradingZone)
{
SourceTradingZone = _SourceTradingZone;
return SourceTradingZone;
}
[DataMemberAttribute("UseTradingZone")]
public str parmUseTradingZone(str _UseTradingZone = UseTradingZone)
{
UseTradingZone = _UseTradingZone;
return UseTradingZone;
}
[DataMemberAttribute("ApplicationId")]
public str parmApplicationId(str _ApplicationId = ApplicationId)
{
ApplicationId = _ApplicationId;
return ApplicationId;
}
[DataMemberAttribute("TransactionText")]
public str parmTransactionText(str _TransactionText = TransactionText)
{
TransactionText = _TransactionText;
return TransactionText;
}
}
2. Response class :
[DataContractAttribute]
internal final class DTT_ResponseContractClass
{
str Querystatus;
str JournalBatchNumber;
str ErrorType;
str ErrorDescription;
public static DTT_ResponseContractClass construct(str _Querystatus = "",
str _JournalBatchNumber = "",
str _ErrorType = "",
str _ErrorDescription = "")
{
DTT_ResponseContractClass contract = new DTT_ResponseContractClass();
contract.initialize(_Querystatus,_JournalBatchNumber,_ErrorType,_ErrorDescription);
return contract;
}
private void initialize(str _Querystatus,str _JournalBatchNumber,str _ErrorType,str _ErrorDescription)
{
this.parmQuerystatus(_Querystatus);
this.parmJournalBatchNumber(_JournalBatchNumber);
this.parmErrorType(_ErrorType);
this.parmErrorDescription(_ErrorDescription);
}
[DataMemberAttribute("Querystatus")]
public str parmQuerystatus(str _Querystatus = Querystatus)
{
Querystatus = _Querystatus;
return Querystatus;
}
[DataMemberAttribute("JournalBatchNumber")]
public str parmJournalBatchNumber(str _JournalBatchNumber = JournalBatchNumber)
{
JournalBatchNumber = _JournalBatchNumber;
return JournalBatchNumber;
}
[DataMemberAttribute("ErrorType")]
public str parmErrorType(str _ErrorType = ErrorType)
{
ErrorType = _ErrorType;
return ErrorType;
}
[DataMemberAttribute("ErrorDescription")]
public str parmErrorDescription(str _ErrorDescription = ErrorDescription)
{
ErrorDescription = _ErrorDescription;
return ErrorDescription;
}
public void setFailed(str _message)
{
this.parmErrorDescription(_message);
}
public void setFailedloc(str _message)
{
this.parmErrorType(_message);
}
}
3. Service Class :
internal final class DTT_ServiceClass
{
DTT_PostingProfile dTT_PostingProfile;
DTT_PostingProfileDetails dTT_PostingProfileDetails;
LedgerJournalTable ledgerJournaltable;
LedgerJournalTrans ledgerJournalTrans;
LedgerJournalName ledgerJournalname;
public DTT_ResponseContractClass exampleReturnJson(DTT_RequestContractClass _request)
{
DTT_ResponseContractClass contract = DTT_ResponseContractClass::construct();
DTT_Process dTT_Process;
container con;
LedgerJournalCheckPost jourPost;
NumberSeq numberSeq;
str process= _request.parmProcess();
dTT_Process = str2Enum(dTT_Process,process);
try
{
select crosscompany dTT_PostingProfile
where dTT_PostingProfile.DTT_Process == dTT_Process
&& dTT_PostingProfile.DataAreaId == _request.parmLegalEntity();
select crosscompany dTT_PostingProfileDetails
where dTT_PostingProfileDetails.DTT_Process == dTT_PostingProfile.DTT_Process;
select crosscompany ledgerJournaltable
where ledgerJournaltable.JournalName == dTT_PostingProfile.DTT_JournalName
&& ledgerJournaltable.DataAreaId == _request.parmLegalEntity();
changecompany(_request.parmLegalEntity())
{
ledgerJournalTable.clear();
ledgerJournalTable.initFromLedgerJournalName( dTT_PostingProfile.DTT_JournalName);
ledgerJournaltable.JournalNum = JournalTableData::newTable(ledgerJournalTable).nextJournalId();
if (ledgerJournalTable.validateWrite())
{
ledgerJournalTable.insert();
}
ledgerJournalTrans.clear();
ledgerJournalTrans.initValue();
ledgerjournalTrans.JournalNum = ledgerJournalTable.JournalNum;
ledgerjournalTrans.TransDate = _request.parmTransactionDate();
ledgerjournalTrans.Company = _request.parmLegalEntity();
ledgerjournalTrans.AccountType = LedgerJournalACType::Ledger;
con = DTT_ServiceClass::getLedgerDim(dTT_PostingProfileDetails);
ledgerJournalTrans.LedgerDimension = conPeek(con,1);
ledgerJournalTrans.OffsetLedgerDimension = conPeek(con,2);
ledgerjournalTrans.Txt = _request.parmTransactionText();
if(dTT_PostingProfileDetails.DTT_DebitCreaditProposal == DTT_DebitCreaditProposal::Debit)
{
ledgerjournalTrans.AmountCurDebit = _request.parmVolume();
}
else if(dTT_PostingProfileDetails.DTT_DebitCreaditProposal == DTT_DebitCreaditProposal::Credit)
{
ledgerjournalTrans.AmountCurCredit = _request.parmVolume();
}
ledgerjournalTrans.OffsetAccountType = LedgerJournalACType::Ledger;
ledgerjournalTrans.OffsetTxt = _request.parmTransactionText();
ledgerjournalTrans.Approved = NoYes::Yes;
ledgerjournalTrans.defaultRow(); // remove this line if u get continous error
if (ledgerJournalTrans.validateWrite())
{
ledgerjournalTrans.insert();
}
jourPost = LedgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTable, NoYes::Yes);
jourPost.runOperation();
}
if(_request.parmAllocationAccount() == null)
{
contract.setFailedloc("ApplicationAccount is empty");
contract.setFailed("ApplicationAccount cannot be blank");
}
else if(_request.parmVolume() ==0)
{
contract.setFailedloc("Volume is empty");
contract.setFailed("volume cannot be blank");
}
else if(_request.parmLegalEntity() ==null)
{
contract.setFailedloc("LegalEntity is empty");
contract.setFailed("LegalEntity cannot be blank");
}
else if(_request.parmProcess() == null)
{
contract.setFailedloc("Process is empty");
contract.setFailed("Process cannot be blank");
}
else if(_request.parmSourceTradingZone() == null)
{
contract.setFailedloc("SourceTradingZone is empty");
contract.setFailed("SourceTradingZone cannot be blank");
}
else if(_request.parmTransactionDate()== dateNull())
{
contract.setFailedloc("TransactionDate is empty");
contract.setFailed("TransactionDate cannot be blank");
}
else if(_request.parmTransactionText() == null)
{
contract.setFailedloc("TransactionText is empty");
contract.setFailed("TransactionText cannot be blank");
}
else if(_request.parmUseTradingZone() == null)
{
contract.setFailedloc("UseTradingZone is empty");
contract.setFailed("UseTradingZone cannot be blank");
}
else if(_request.parmWaterAuthority() == null)
{
contract.setFailedloc("WaterAuthority is empty");
contract.setFailed("WaterAuthority cannot be blank");
}
else
{
contract.parmQuerystatus("0");
contract.parmJournalBatchNumber(ledgerjournalTrans.Voucher);
contract.parmErrorType("Test");
contract.parmErrorDescription("Test");
}
return contract;
}
catch (Exception::Error)
{
contract.parmQuerystatus("1");
contract.parmJournalBatchNumber("Test");
contract.parmErrorType("Test");
contract.parmErrorDescription("Test");
}
return contract;
}
static container getLedgerDim(DTT_PostingProfileDetails dTT_PostingProfileDetails)
{
DimensionDynamicAccount ledgerDim;
LedgerRecId ledgerRecId;
MainAccountnum mainAccount,mainAccountloc;
DimensionAttributeValueCombination dimensionAttributeValueCombination;
DimensionStorage dimStorage;
container con,conloc;
int64 value,valueloc;
int i;
// mainAccount = MainAccount::findByMainAccountId("110115");
//mainAccountloc = MainAccount::findByMainAccountId("110130");
mainAccount = dTT_PostingProfileDetails.DTT_MainAccount;
mainAccountloc = dTT_PostingProfileDetails.DTT_OffsetAccount;
con = [mainAccount,mainAccountloc];
for (i = 1; i <= conLen(con); i++)
{
//value =any2Int64(conPeek(con,i));
DimensionServiceProvider DimensionServiceProvider = new DimensionServiceProvider();
LedgerAccountContract LedgerAccountContract = new LedgerAccountContract();
DimensionAttributeValueContract ValueContract;
List ListValueContract = new List(Types::Class);
LedgerAccountContract.parmMainAccount(conPeek(con,i));
LedgerAccountContract.parmValues(ListValueContract);
dimStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(LedgerAccountContract);
dimensionAttributeValueCombination = DimensionAttributeValueCombination::find(dimStorage.save());
if(dimensionAttributeValueCombination.RecId)
{
ledgerRecId = dimensionAttributeValueCombination.RecId;
}
conloc += ledgerRecId;
}
return conloc;
}
}
Json input file :