1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.kuali.kfs.module.ld.batch.service.impl;
20
21 import java.util.Date;
22
23 import org.kuali.kfs.gl.batch.service.PostTransaction;
24 import org.kuali.kfs.gl.businessobject.Transaction;
25 import org.kuali.kfs.module.ld.LaborConstants;
26 import org.kuali.kfs.module.ld.batch.service.LaborAccountingCycleCachingService;
27 import org.kuali.kfs.module.ld.businessobject.LaborTransaction;
28 import org.kuali.kfs.module.ld.businessobject.LedgerBalance;
29 import org.kuali.kfs.sys.KFSConstants;
30 import org.kuali.kfs.sys.service.ReportWriterService;
31 import org.kuali.rice.core.api.util.type.KualiDecimal;
32 import org.kuali.rice.krad.util.ObjectUtils;
33 import org.springframework.transaction.annotation.Transactional;
34
35
36
37
38 @Transactional
39 public class LaborLedgerBalancePoster implements PostTransaction {
40 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LaborLedgerBalancePoster.class);
41
42 private LaborAccountingCycleCachingService laborAccountingCycleCachingService;
43
44
45
46 public String post(Transaction transaction, int mode, Date postDate, ReportWriterService posterReportWriterService) {
47 String operationType = KFSConstants.OperationType.INSERT;
48 LedgerBalance ledgerBalance = new LedgerBalance((LaborTransaction) transaction);
49
50
51 LedgerBalance tempLedgerBalance = laborAccountingCycleCachingService.getLedgerBalance(ledgerBalance);
52 if (ObjectUtils.isNotNull(tempLedgerBalance)) {
53 ledgerBalance = tempLedgerBalance;
54 operationType = KFSConstants.OperationType.UPDATE;
55 }
56 KualiDecimal amount = transaction.getTransactionLedgerEntryAmount();
57 if (transaction.getBalanceType().isFinancialOffsetGenerationIndicator()) {
58 if (!transaction.getTransactionDebitCreditCode().equals(transaction.getObjectType().getFinObjectTypeDebitcreditCd())) {
59 amount = amount.negated();
60 }
61 }
62
63 ledgerBalance.addAmount(transaction.getUniversityFiscalPeriodCode(), amount);
64
65 if (operationType.equals(KFSConstants.OperationType.INSERT)) {
66 laborAccountingCycleCachingService.insertLedgerBalance(ledgerBalance);
67 } else {
68 laborAccountingCycleCachingService.updateLedgerBalance(ledgerBalance);
69 }
70 return operationType;
71 }
72
73
74
75
76 public String getDestinationName() {
77 return LaborConstants.DestinationNames.LEDGER_BALANCE;
78 }
79
80 public void setLaborAccountingCycleCachingService(LaborAccountingCycleCachingService laborAccountingCycleCachingService) {
81 this.laborAccountingCycleCachingService = laborAccountingCycleCachingService;
82 }
83 }