Search in sources :

Example 1 with AssetPaymentDocument

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;
}
Also used : CapitalAssetInformation(org.kuali.kfs.fp.businessobject.CapitalAssetInformation) AssetPaymentDocument(org.kuali.kfs.module.cam.document.AssetPaymentDocument) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) AssetPaymentAssetDetail(org.kuali.kfs.module.cam.businessobject.AssetPaymentAssetDetail) SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) NonTransactional(org.kuali.kfs.sys.service.NonTransactional)

Aggregations

CapitalAssetInformation (org.kuali.kfs.fp.businessobject.CapitalAssetInformation)1 AssetPaymentAssetDetail (org.kuali.kfs.module.cam.businessobject.AssetPaymentAssetDetail)1 AssetPaymentDocument (org.kuali.kfs.module.cam.document.AssetPaymentDocument)1 SourceAccountingLine (org.kuali.kfs.sys.businessobject.SourceAccountingLine)1 NonTransactional (org.kuali.kfs.sys.service.NonTransactional)1 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)1