use of org.kuali.kfs.coa.businessobject.AccountingPeriod in project cu-kfs by CU-CommunityApps.
the class LaborLedgerEnterpriseFeedServiceImpl method createDisencumbrance.
/**
* @see edu.cornell.kfs.module.ld.service.LaborLedgerEnterpriseFeedService#createDisencumbrance(java.io.InputStream)
*/
public InputStream createDisencumbrance(InputStream encumbranceFile) {
InputStream disencumbranceStream = null;
if (encumbranceFile == null) {
return null;
}
Date currentSqlDate = dateTimeService.getCurrentSqlDate();
java.util.Date currentDate = dateTimeService.getCurrentDate();
// get fiscal period code for current date
AccountingPeriod accountingPeriod = accountingPeriodService.getByDate(currentSqlDate);
String fiscalPeriodCode = accountingPeriod.getUniversityFiscalPeriodCode();
ByteArrayOutputStream disencEntriesPrintStream = new ByteArrayOutputStream();
try {
InputStream fStream = encumbranceFile;
BufferedReader in = new BufferedReader(new InputStreamReader(fStream));
while (in.ready()) {
String currentLine = in.readLine();
if (currentLine != null && currentLine.length() == LD_ENTERPRISE_FEED_LINE_LENGTH) {
String resultLine = currentLine;
// set fiscal period code
resultLine = StringUtils.overlay(resultLine, fiscalPeriodCode, UNIV_FISCAL_PRD_CD_START_INDEX, UNIV_FISCAL_PRD_CD_END_INDEX);
// set the sign to always pe +
resultLine = StringUtils.overlay(resultLine, TRANSACTION_SIGN, TRANSACTION_SIGN_START_INDEX, TRANSACTION_SIGN_END_INDEX);
// set the debit/credit code
if (KFSConstants.GL_CREDIT_CODE.equalsIgnoreCase(StringUtils.substring(currentLine, CREDIT_DEBIT_CODE_START_INDEX, CREDIT_DEBIT_CODE_END_INDEX))) {
resultLine = StringUtils.overlay(resultLine, KFSConstants.GL_DEBIT_CODE, CREDIT_DEBIT_CODE_START_INDEX, CREDIT_DEBIT_CODE_END_INDEX);
} else if (KFSConstants.GL_DEBIT_CODE.equalsIgnoreCase(StringUtils.substring(currentLine, CREDIT_DEBIT_CODE_START_INDEX, CREDIT_DEBIT_CODE_END_INDEX))) {
resultLine = StringUtils.overlay(resultLine, KFSConstants.GL_CREDIT_CODE, CREDIT_DEBIT_CODE_START_INDEX, CREDIT_DEBIT_CODE_END_INDEX);
}
// set transaction date
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
String currentDateString = sdf.format(currentDate);
resultLine = StringUtils.overlay(resultLine, currentDateString, TRANSACTION_DT_STRART_INDEX, TRANSACTION_DT_END_INDEX);
// set the reference transaction document type code to be the same as the input transaction document type
// code
String inputTransDocumentTypeCode = StringUtils.substring(currentLine, FDOC_TYP_CD_START_INDEX, FDOC_TYP_CD_END_INDEX);
// resultLine = StringUtils.overlay(resultLine, FDOC_REF_TYP_CD, FDOC_REF_TYP_CD_START_INDEX,
// FDOC_REF_TYP_CD_END_INDEX);
resultLine = StringUtils.overlay(resultLine, inputTransDocumentTypeCode, FDOC_REF_TYP_CD_START_INDEX, FDOC_REF_TYP_CD_END_INDEX);
// set the reference origination code to be the same as the input transaction origination code
String inputTransOriginationCode = StringUtils.substring(currentLine, FS_ORIGIN_CD_START_INDEX, FS_ORIGIN_CD_END_INDEX);
// resultLine = StringUtils.overlay(resultLine, FS_REF_ORIGIN_CD, FS_REF_ORIGIN_CD_START_INDEX,
// FS_REF_ORIGIN_CD_END_INDEX);
resultLine = StringUtils.overlay(resultLine, inputTransOriginationCode, FS_REF_ORIGIN_CD_START_INDEX, FS_REF_ORIGIN_CD_END_INDEX);
// set the transaction encumbrance update code to be R
resultLine = StringUtils.overlay(resultLine, TRN_ENCUM_UPDT_CD, TRN_ENCUM_UPDT_CD_START_INDEX, TRN_ENCUM_UPDT_CD_END_INDEX);
// set the reference document number to be the input transaction document number
String fDocNbr = resultLine.substring(FDOC_NBR_START_INDEX, FDOC_NBR_END_INDEX);
resultLine = StringUtils.overlay(resultLine, fDocNbr, FDOC_REF_NBR_START_INDEX, FDOC_REF_NBR_END_INDEX);
resultLine = resultLine.concat(KFSConstants.NEWLINE);
disencEntriesPrintStream.write((resultLine.getBytes()));
} else {
LOG.info("Input file has an invalid format");
in.close();
disencEntriesPrintStream.close();
return null;
}
}
in.close();
disencEntriesPrintStream.flush();
disencumbranceStream = new ByteArrayInputStream(disencEntriesPrintStream.toByteArray());
disencEntriesPrintStream.close();
return disencumbranceStream;
} catch (FileNotFoundException e) {
LOG.info("Error creating PrintStream to write invalid entries");
} catch (IOException e) {
LOG.info("Error creating the disencumbrance file");
}
return disencumbranceStream;
}
use of org.kuali.kfs.coa.businessobject.AccountingPeriod in project cu-kfs by CU-CommunityApps.
the class PendingTransactionServiceImpl method populatePaymentGeneralLedgerPendingEntry.
/**
* Populates and stores a new GLPE for each account detail in the payment group.
*
* @param paymentGroup payment group to generate entries for
* @param achFdocTypeCode doc type for ach disbursements
* @param checkFdocTypeCod doc type for check disbursements
* @param reversal boolean indicating if this is a reversal
*/
protected void populatePaymentGeneralLedgerPendingEntry(PaymentGroup paymentGroup, String achFdocTypeCode, String checkFdocTypeCod, boolean reversal) {
List<PaymentAccountDetail> accountListings = new ArrayList<PaymentAccountDetail>();
for (PaymentDetail paymentDetail : paymentGroup.getPaymentDetails()) {
accountListings.addAll(paymentDetail.getAccountDetail());
}
BusinessObjectEntry businessObjectEntry = dataDictionaryService.getDataDictionary().getBusinessObjectEntry(PaymentDetail.class.getName());
AttributeDefinition attributeDefinition = businessObjectEntry.getAttributeDefinition("paymentGroup.payeeName");
AttributeSecurity originalPayeeNameAttributeSecurity = attributeDefinition.getAttributeSecurity();
String maskLiteral = ((MaskFormatterLiteral) originalPayeeNameAttributeSecurity.getMaskFormatter()).getLiteral();
GeneralLedgerPendingEntrySequenceHelper sequenceHelper = new GeneralLedgerPendingEntrySequenceHelper();
for (PaymentAccountDetail paymentAccountDetail : accountListings) {
GlPendingTransaction glPendingTransaction = new GlPendingTransaction();
glPendingTransaction.setSequenceNbr(new KualiInteger(sequenceHelper.getSequenceCounter()));
if (StringUtils.isNotBlank(paymentAccountDetail.getPaymentDetail().getFinancialSystemOriginCode()) && StringUtils.isNotBlank(paymentAccountDetail.getPaymentDetail().getFinancialDocumentTypeCode())) {
glPendingTransaction.setFdocRefTypCd(paymentAccountDetail.getPaymentDetail().getFinancialDocumentTypeCode());
glPendingTransaction.setFsRefOriginCd(paymentAccountDetail.getPaymentDetail().getFinancialSystemOriginCode());
} else {
glPendingTransaction.setFdocRefTypCd(PdpConstants.PDP_FDOC_TYPE_CODE);
glPendingTransaction.setFsRefOriginCd(PdpConstants.PDP_FDOC_ORIGIN_CODE);
}
glPendingTransaction.setFinancialBalanceTypeCode(KFSConstants.BALANCE_TYPE_ACTUAL);
Date transactionTimestamp = new Date(dateTimeService.getCurrentDate().getTime());
glPendingTransaction.setTransactionDt(transactionTimestamp);
AccountingPeriod fiscalPeriod = accountingPeriodService.getByDate(new java.sql.Date(transactionTimestamp.getTime()));
glPendingTransaction.setUniversityFiscalYear(fiscalPeriod.getUniversityFiscalYear());
glPendingTransaction.setUnivFiscalPrdCd(fiscalPeriod.getUniversityFiscalPeriodCode());
glPendingTransaction.setAccountNumber(paymentAccountDetail.getAccountNbr());
glPendingTransaction.setSubAccountNumber(paymentAccountDetail.getSubAccountNbr());
glPendingTransaction.setChartOfAccountsCode(paymentAccountDetail.getFinChartCode());
if (paymentGroup.getDisbursementType().getCode().equals(PdpConstants.DisbursementTypeCodes.ACH)) {
glPendingTransaction.setFinancialDocumentTypeCode(achFdocTypeCode);
} else if (paymentGroup.getDisbursementType().getCode().equals(PdpConstants.DisbursementTypeCodes.CHECK)) {
glPendingTransaction.setFinancialDocumentTypeCode(checkFdocTypeCod);
}
glPendingTransaction.setFsOriginCd(PdpConstants.PDP_FDOC_ORIGIN_CODE);
glPendingTransaction.setFdocNbr(paymentGroup.getDisbursementNbr().toString());
Boolean relieveLiabilities = paymentGroup.getBatch().getCustomerProfile().getRelieveLiabilities();
if ((relieveLiabilities != null) && (relieveLiabilities.booleanValue()) && paymentAccountDetail.getPaymentDetail().getFinancialDocumentTypeCode() != null) {
OffsetDefinition offsetDefinition = SpringContext.getBean(OffsetDefinitionService.class).getByPrimaryId(glPendingTransaction.getUniversityFiscalYear(), glPendingTransaction.getChartOfAccountsCode(), paymentAccountDetail.getPaymentDetail().getFinancialDocumentTypeCode(), glPendingTransaction.getFinancialBalanceTypeCode());
glPendingTransaction.setFinancialObjectCode(offsetDefinition != null ? offsetDefinition.getFinancialObjectCode() : paymentAccountDetail.getFinObjectCode());
glPendingTransaction.setFinancialSubObjectCode(KFSConstants.getDashFinancialSubObjectCode());
} else {
glPendingTransaction.setFinancialObjectCode(paymentAccountDetail.getFinObjectCode());
glPendingTransaction.setFinancialSubObjectCode(paymentAccountDetail.getFinSubObjectCode());
}
glPendingTransaction.setProjectCd(paymentAccountDetail.getProjectCode());
glPendingTransaction.setDebitCrdtCd(pdpUtilService.isDebit(paymentAccountDetail, reversal) ? KFSConstants.GL_DEBIT_CODE : KFSConstants.GL_CREDIT_CODE);
glPendingTransaction.setAmount(paymentAccountDetail.getAccountNetAmount().abs());
// Changes for Research Participant Upload
String trnDesc = StringUtils.EMPTY;
CustomerProfile customerProfile = paymentGroup.getBatch().getCustomerProfile();
if (researchParticipantPaymentValidationService.isResearchParticipantPayment(customerProfile)) {
trnDesc = maskLiteral;
} else {
String payeeName = paymentGroup.getPayeeName();
if (StringUtils.isNotBlank(payeeName)) {
trnDesc = payeeName.length() > 40 ? payeeName.substring(0, 40) : StringUtils.rightPad(payeeName, 40);
}
if (reversal) {
String poNbr = paymentAccountDetail.getPaymentDetail().getPurchaseOrderNbr();
if (StringUtils.isNotBlank(poNbr)) {
trnDesc += " " + (poNbr.length() > 9 ? poNbr.substring(0, 9) : StringUtils.rightPad(poNbr, 9));
}
String invoiceNbr = paymentAccountDetail.getPaymentDetail().getInvoiceNbr();
if (StringUtils.isNotBlank(invoiceNbr)) {
trnDesc += " " + (invoiceNbr.length() > 14 ? invoiceNbr.substring(0, 14) : StringUtils.rightPad(invoiceNbr, 14));
}
if (trnDesc.length() > 40) {
trnDesc = trnDesc.substring(0, 40);
}
}
}
glPendingTransaction.setDescription(trnDesc);
glPendingTransaction.setOrgDocNbr(paymentAccountDetail.getPaymentDetail().getOrganizationDocNbr());
glPendingTransaction.setOrgReferenceId(paymentAccountDetail.getOrgReferenceId());
glPendingTransaction.setFdocRefNbr(paymentAccountDetail.getPaymentDetail().getCustPaymentDocNbr());
// update the offset account if necessary
SpringContext.getBean(FlexibleOffsetAccountService.class).updateOffset(glPendingTransaction);
this.businessObjectService.save(glPendingTransaction);
sequenceHelper.increment();
if (bankService.isBankSpecificationEnabled()) {
this.populateBankOffsetEntry(paymentGroup, glPendingTransaction, sequenceHelper);
}
}
}
use of org.kuali.kfs.coa.businessobject.AccountingPeriod in project cu-kfs by CU-CommunityApps.
the class ScrubberValidatorImpl method validateUniversityFiscalPeriodCode.
/**
* Validates the period code of the origin entry
*
* @param originEntry the origin entry being scrubbed
* @param workingEntry the scrubbed version of the origin entry
* @param universityRunDate the university date when this scrubber process is being run
* @return a Message if an error was encountered, otherwise null
*/
protected Message validateUniversityFiscalPeriodCode(OriginEntryInformation originEntry, OriginEntryInformation workingEntry, UniversityDate universityRunDate, AccountingCycleCachingService accountingCycleCachingService) {
LOG.debug("validateUniversityFiscalPeriodCode() started");
String periodCode = originEntry.getUniversityFiscalPeriodCode();
if (!StringUtils.hasText(periodCode)) {
if (universityRunDate.getAccountingPeriod().isOpen()) {
workingEntry.setUniversityFiscalPeriodCode(universityRunDate.getUniversityFiscalAccountingPeriod());
workingEntry.setUniversityFiscalYear(universityRunDate.getUniversityFiscalYear());
} else {
return MessageBuilder.buildMessage(KFSKeyConstants.ERROR_ACCOUNTING_PERIOD_CLOSED, " (year " + universityRunDate.getUniversityFiscalYear() + ", period " + universityRunDate.getUniversityFiscalAccountingPeriod(), Message.TYPE_FATAL);
}
} else {
AccountingPeriod originEntryAccountingPeriod = accountingCycleCachingService.getAccountingPeriod(originEntry.getUniversityFiscalYear(), originEntry.getUniversityFiscalPeriodCode());
if (originEntryAccountingPeriod == null) {
return MessageBuilder.buildMessage(KFSKeyConstants.ERROR_ACCOUNTING_PERIOD_NOT_FOUND, periodCode, Message.TYPE_FATAL);
} else if (!originEntryAccountingPeriod.isActive()) {
return MessageBuilder.buildMessage(KFSKeyConstants.ERROR_ACCOUNTING_PERIOD_NOT_ACTIVE, periodCode, Message.TYPE_FATAL);
}
workingEntry.setUniversityFiscalPeriodCode(periodCode);
}
return null;
}
use of org.kuali.kfs.coa.businessobject.AccountingPeriod in project cu-kfs by CU-CommunityApps.
the class RecurringDisbursementVoucherDocumentServiceImpl method updateGLPEDatesAndAddRecurringDocumentLinks.
private void updateGLPEDatesAndAddRecurringDocumentLinks(DisbursementVoucherDocument dv, String recurringDisbursemntVoucherDocumentNumber) {
for (GeneralLedgerPendingEntry glpe : dv.getGeneralLedgerPendingEntries()) {
glpe.setTransactionDate(dv.getDisbursementVoucherDueDate());
glpe.setReferenceFinancialDocumentTypeCode(CuFPConstants.RecurringDisbursementVoucherDocumentConstants.RECURRING_DV_DOCUMENT_TYPE_NAME);
glpe.setReferenceFinancialDocumentNumber(recurringDisbursemntVoucherDocumentNumber);
AccountingPeriod ap = getAccountingPeriodService().getByDate(dv.getDisbursementVoucherDueDate());
glpe.setAccountingPeriod(ap);
glpe.setUniversityFiscalPeriodCode(ap.getUniversityFiscalPeriodCode());
glpe.setUniversityFiscalYear(ap.getUniversityFiscalYear());
getBusinessObjectService().save(glpe);
}
}
use of org.kuali.kfs.coa.businessobject.AccountingPeriod in project cu-kfs by CU-CommunityApps.
the class RecurringDisbursementVoucherDocumentServiceImpl method getCurrentFiscalPeriodEndDate.
private Date getCurrentFiscalPeriodEndDate() {
Date today = KfsDateUtils.convertToSqlDate(new Date(Calendar.getInstance().getTimeInMillis()));
AccountingPeriod currentPeriod = getAccountingPeriodService().getByDate(today);
if (currentPeriod == null) {
return null;
} else {
return currentPeriod.getUniversityFiscalPeriodEndDate();
}
}
Aggregations