use of org.kuali.kfs.module.cam.document.AssetPaymentDocument in project cu-kfs by CU-CommunityApps.
the class GlLineServiceImpl method createAssetPaymentDocument.
/**
* @see GlLineService#createAssetPaymentDocument(GeneralLedgerEntry, Integer)
*/
@Override
@NonTransactional
public Document createAssetPaymentDocument(GeneralLedgerEntry primaryGlEntry, Integer capitalAssetLineNumber) throws WorkflowException {
// Find out the GL Entry
// initiate a new document
AssetPaymentDocument document = (AssetPaymentDocument) documentService.getNewDocument(DocumentTypeName.ASSET_PAYMENT);
document.setCapitalAssetBuilderOriginIndicator(true);
// populate the capital asset line distribution amount code to the payment document.
CapitalAssetInformation capitalAssetInformation = findCapitalAssetInformation(primaryGlEntry.getDocumentNumber(), capitalAssetLineNumber);
if (ObjectUtils.isNotNull(capitalAssetInformation)) {
// setup asset allocation info accordingly so it can be changed on Asset Payment Document
if (ObjectUtils.isNull(capitalAssetInformation.getDistributionAmountCode())) {
document.setAssetPaymentAllocationTypeCode(KFSConstants.CapitalAssets.DISTRIBUTE_COST_EQUALLY_CODE);
document.setAllocationFromFPDocuments(false);
} else {
document.setAssetPaymentAllocationTypeCode(capitalAssetInformation.getDistributionAmountCode());
document.setAllocationFromFPDocuments(true);
}
}
document.getDocumentHeader().setDocumentDescription(CAB_DESC_PREFIX + primaryGlEntry.getDocumentNumber());
updatePreTagInformation(primaryGlEntry, document, capitalAssetLineNumber);
// Asset Payment Detail - sourceAccountingLines on the document....
document.getSourceAccountingLines().addAll(createAssetPaymentDetails(primaryGlEntry, document, 0, capitalAssetLineNumber));
KualiDecimal assetAmount = KualiDecimal.ZERO;
List<SourceAccountingLine> sourceAccountingLines = document.getSourceAccountingLines();
for (SourceAccountingLine sourceAccountingLine : sourceAccountingLines) {
assetAmount = assetAmount.add(sourceAccountingLine.getAmount());
}
List<AssetPaymentAssetDetail> assetPaymentDetails = document.getAssetPaymentAssetDetail();
for (AssetPaymentAssetDetail assetPaymentDetail : assetPaymentDetails) {
assetPaymentDetail.setAllocatedAmount(assetAmount);
}
// Asset payment asset detail
// save the document
documentService.saveDocument(document);
markCapitalAssetProcessed(primaryGlEntry, capitalAssetLineNumber);
deactivateGLEntries(primaryGlEntry, document, capitalAssetLineNumber);
return document;
}
Aggregations