use of org.kuali.kfs.fp.businessobject.CapitalAssetInformation in project cu-kfs by CU-CommunityApps.
the class CuCapitalAssetManagementModuleServiceImpl method validateAssetTagLocationLines.
protected boolean validateAssetTagLocationLines(CapitalAssetInformation capitalAssetInformation, int capitalAssetIndex, AccountingDocument accountingDocument) {
boolean valid = true;
CapitalAssetEditable capitalAssetEditable = (CapitalAssetEditable) accountingDocument;
List<CapitalAssetInformation> capitalAssets = capitalAssetEditable.getCapitalAssetInformation();
List<CapitalAssetInformationDetail> capitalAssetInformationDetails = capitalAssetInformation.getCapitalAssetInformationDetails();
int index = 0;
for (CapitalAssetInformationDetail dtl : capitalAssetInformationDetails) {
CapitalAssetInformationDetailExtendedAttribute capDetailExt = (CapitalAssetInformationDetailExtendedAttribute) dtl.getExtension();
String assetLocationCityName = capDetailExt.getAssetLocationCityName();
String assetLocationCountryCode = capDetailExt.getAssetLocationCountryCode();
String assetLocationStateCode = capDetailExt.getAssetLocationStateCode();
String assetLocationStreetAddress = capDetailExt.getAssetLocationStreetAddress();
String assetLocationZipCode = capDetailExt.getAssetLocationZipCode();
// We have to explicitly call this DD service to upper case each field. This may not be the best place and maybe form
// populate is a better place but we CAMS team don't own FP document. This is the best we can do for now.
businessObjectDictionaryService.performForceUppercase(dtl);
String errorPathPrefix = KFSPropertyConstants.DOCUMENT + "." + KFSPropertyConstants.CAPITAL_ASSET_INFORMATION + "[" + capitalAssetIndex + "]." + KFSPropertyConstants.CAPITAL_ASSET_INFORMATION_DETAILS;
if (StringUtils.isNotBlank(dtl.getCampusCode())) {
Campus campus = campusService.getCampus(dtl.getCampusCode());
if (ObjectUtils.isNull(campus)) {
valid = false;
String label = this.getDataDictionaryService().getAttributeLabel(Campus.class, KFSPropertyConstants.CODE);
GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(errorPathPrefix + "[" + index + "]" + "." + KFSPropertyConstants.CAMPUS_CODE, KFSKeyConstants.ERROR_EXISTENCE, label);
}
}
Map<String, String> params;
if (StringUtils.isNotBlank(dtl.getCampusCode()) && StringUtils.isNotBlank(dtl.getBuildingCode()) && StringUtils.isBlank(assetLocationCityName) && StringUtils.isBlank(assetLocationStateCode) && StringUtils.isBlank(assetLocationCountryCode) && StringUtils.isBlank(assetLocationStreetAddress) && StringUtils.isBlank(assetLocationZipCode)) {
params = new HashMap<String, String>();
params.put(KFSPropertyConstants.CAMPUS_CODE, dtl.getCampusCode());
params.put(KFSPropertyConstants.BUILDING_CODE, dtl.getBuildingCode());
Building building = businessObjectService.findByPrimaryKey(Building.class, params);
// Check if building is valid
if (ObjectUtils.isNull(building)) {
valid = false;
GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(errorPathPrefix + "[" + index + "]" + "." + KFSPropertyConstants.BUILDING_CODE, CamsKeyConstants.AssetLocationGlobal.ERROR_INVALID_BUILDING_CODE, dtl.getBuildingCode(), dtl.getCampusCode());
}
}
AssetType assetType = getAssetType(capitalAssetInformation.getCapitalAssetTypeCode());
if (StringUtils.isBlank(assetLocationCityName) && StringUtils.isBlank(assetLocationStateCode) && StringUtils.isBlank(assetLocationCountryCode) && StringUtils.isBlank(assetLocationStreetAddress) && StringUtils.isBlank(assetLocationZipCode)) {
// If building was specified but was not required for this asset type display an error
if (StringUtils.isNotBlank(dtl.getBuildingCode()) && ObjectUtils.isNotNull(assetType) && !assetType.isMovingIndicator() && !assetType.isRequiredBuildingIndicator()) {
valid = false;
String label = this.getDataDictionaryService().getAttributeLabel(Building.class, KFSPropertyConstants.BUILDING_CODE);
GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(errorPathPrefix + "[" + index + "]" + "." + KFSPropertyConstants.BUILDING_CODE, CamsKeyConstants.AssetLocation.ERROR_ASSET_LOCATION_BUILDING_NONMOVEABLE, label);
}
if (StringUtils.isNotBlank(dtl.getCampusCode()) && StringUtils.isNotBlank(dtl.getBuildingCode()) && StringUtils.isNotBlank(dtl.getBuildingRoomNumber())) {
params = new HashMap<>();
params.put(KFSPropertyConstants.CAMPUS_CODE, dtl.getCampusCode());
params.put(KFSPropertyConstants.BUILDING_CODE, dtl.getBuildingCode());
params.put(KFSPropertyConstants.BUILDING_ROOM_NUMBER, dtl.getBuildingRoomNumber());
Room room = businessObjectService.findByPrimaryKey(Room.class, params);
// Check if room is valid
if (ObjectUtils.isNull(room)) {
valid = false;
GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(errorPathPrefix + "[" + index + "]" + "." + KFSPropertyConstants.BUILDING_ROOM_NUMBER, CamsKeyConstants.AssetLocationGlobal.ERROR_INVALID_ROOM_NUMBER, dtl.getBuildingRoomNumber(), dtl.getBuildingCode(), dtl.getCampusCode());
}
}
// If room was specified but was not required for this asset type display an error
if (StringUtils.isNotBlank(dtl.getBuildingRoomNumber()) && ObjectUtils.isNotNull(assetType) && !assetType.isMovingIndicator()) {
valid = false;
String label = this.getDataDictionaryService().getAttributeLabel(Room.class, KFSPropertyConstants.BUILDING_ROOM_NUMBER);
GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(errorPathPrefix + "[" + index + "]" + "." + KFSPropertyConstants.BUILDING_ROOM_NUMBER, CamsKeyConstants.AssetLocation.ERROR_ASSET_LOCATION_ROOM_NUMBER_NONMOVEABLE, label);
}
}
index++;
}
return valid;
}
use of org.kuali.kfs.fp.businessobject.CapitalAssetInformation in project cu-kfs by CU-CommunityApps.
the class ProcurementCardCreateDocumentServiceImpl method createProcurementCardDocument.
/**
* Creates a ProcurementCardDocument from the List of transactions given.
*
* @param transactions List of ProcurementCardTransaction objects to be used for creating the document.
* @return A ProcurementCardDocument populated with the transactions provided.
*/
@SuppressWarnings({ "rawtypes", "deprecation" })
@Override
public ProcurementCardDocument createProcurementCardDocument(List transactions) {
ProcurementCardDocument pcardDocument = null;
dataDictionaryService = SpringContext.getBean(DataDictionaryService.class);
try {
// get new document from doc service
pcardDocument = buildNewProcurementCardDocument();
List<CapitalAssetInformation> capitalAssets = pcardDocument.getCapitalAssetInformation();
for (CapitalAssetInformation capitalAsset : capitalAssets) {
if (ObjectUtils.isNotNull(capitalAsset) && ObjectUtils.isNotNull(capitalAsset.getCapitalAssetInformationDetails())) {
capitalAsset.setDocumentNumber(pcardDocument.getDocumentNumber());
}
}
ProcurementCardTransaction trans = (ProcurementCardTransaction) transactions.get(0);
String errorText = validateTransaction(trans);
createCardHolderRecord(pcardDocument, trans);
// for each transaction, create transaction detail object and then acct lines for the detail
int transactionLineNumber = 1;
KualiDecimal documentTotalAmount = KualiDecimal.ZERO;
ProcurementCardTransaction transaction = null;
for (Iterator iter = transactions.iterator(); iter.hasNext(); ) {
/*ProcurementCardTransaction*/
transaction = (ProcurementCardTransaction) iter.next();
// create transaction detail record with accounting lines
errorText += createTransactionDetailRecord(pcardDocument, transaction, transactionLineNumber);
// update document total
documentTotalAmount = documentTotalAmount.add(transaction.getFinancialDocumentTotalAmount());
transactionLineNumber++;
}
pcardDocument.getFinancialSystemDocumentHeader().setFinancialDocumentTotalAmount(documentTotalAmount);
// pcardDocument.getDocumentHeader().setDocumentDescription("SYSTEM Generated");
transaction = (ProcurementCardTransaction) transactions.get(0);
String cardHolderName = transaction.getCardHolderName();
String vendorName = transaction.getVendorName();
String transactionType = ((ProcurementCardTransactionExtendedAttribute) transaction.getExtension()).getTransactionType();
if (transactionType != null && StringUtils.isNotBlank(transactionType)) {
VENDOR_NAME_MAX_LENGTH = 16;
} else {
VENDOR_NAME_MAX_LENGTH = 19;
}
if (cardHolderName.length() > CARD_HOLDER_MAX_LENGTH && vendorName.length() > VENDOR_NAME_MAX_LENGTH) {
cardHolderName = cardHolderName.substring(0, CARD_HOLDER_MAX_LENGTH);
vendorName = vendorName.substring(0, VENDOR_NAME_MAX_LENGTH);
}
if (cardHolderName.length() > CARD_HOLDER_MAX_LENGTH && vendorName.length() <= VENDOR_NAME_MAX_LENGTH) {
Integer endIndice = 0;
if ((CARD_HOLDER_MAX_LENGTH + (VENDOR_NAME_MAX_LENGTH - vendorName.length())) > cardHolderName.length()) {
endIndice = cardHolderName.length();
} else {
endIndice = CARD_HOLDER_MAX_LENGTH + (VENDOR_NAME_MAX_LENGTH - vendorName.length());
}
cardHolderName = cardHolderName.substring(0, endIndice);
}
if (vendorName.length() > VENDOR_NAME_MAX_LENGTH && cardHolderName.length() <= CARD_HOLDER_MAX_LENGTH) {
Integer endIndice = 0;
if ((VENDOR_NAME_MAX_LENGTH + (CARD_HOLDER_MAX_LENGTH - cardHolderName.length())) > vendorName.length()) {
endIndice = vendorName.length();
} else {
endIndice = VENDOR_NAME_MAX_LENGTH + (CARD_HOLDER_MAX_LENGTH - cardHolderName.length());
}
vendorName = vendorName.substring(0, endIndice);
}
String creditCardNumber = transaction.getTransactionCreditCardNumber();
String lastFour = "";
if (creditCardNumber.length() > CC_LAST_FOUR) {
lastFour = creditCardNumber.substring(creditCardNumber.length() - CC_LAST_FOUR);
}
String docDesc = cardHolderName + "/" + vendorName + "/" + lastFour;
if (transactionType != null && StringUtils.isNotBlank(transactionType)) {
docDesc = transactionType + "/" + cardHolderName + "/" + vendorName + "/" + lastFour;
}
if (docDesc.length() > MAX_DOC_DESC_LENGTH) {
docDesc = docDesc.substring(0, MAX_DOC_DESC_LENGTH);
}
pcardDocument.getDocumentHeader().setDocumentDescription(docDesc);
// Remove duplicate messages from errorText
String[] messages = StringUtils.split(errorText, ".");
for (int i = 0; i < messages.length; i++) {
int countMatches = StringUtils.countMatches(errorText, messages[i]) - 1;
errorText = StringUtils.replace(errorText, messages[i] + ".", "", countMatches);
}
// In case errorText is still too long, truncate it and indicate so.
Integer documentExplanationMaxLength = dataDictionaryService.getAttributeMaxLength(DocumentHeader.class.getName(), KFSPropertyConstants.EXPLANATION);
if (documentExplanationMaxLength != null && errorText.length() > documentExplanationMaxLength.intValue()) {
String truncatedMessage = " ... TRUNCATED.";
errorText = errorText.substring(0, documentExplanationMaxLength - truncatedMessage.length()) + truncatedMessage;
}
pcardDocument.getDocumentHeader().setExplanation(errorText);
} catch (WorkflowException e) {
LOG.error("Error creating pcdo documents: " + e.getMessage(), e);
throw new RuntimeException("Error creating pcdo documents: " + e.getMessage(), e);
}
return pcardDocument;
}
use of org.kuali.kfs.fp.businessobject.CapitalAssetInformation in project cu-kfs by CU-CommunityApps.
the class CapitalAssetInformationActionBase method redistributeModifyCapitalAssetAmount.
/**
* redistributes the capital asset amount for the modify capital asset lines.
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws Exception
*/
public ActionForward redistributeModifyCapitalAssetAmount(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
LOG.debug("redistributeModifyCapitalAssetAmount() - start");
KualiDecimal remainingAmountToDistribute = KualiDecimal.ZERO;
CapitalAccountingLinesFormBase calfb = (CapitalAccountingLinesFormBase) form;
CapitalAccountingLinesDocumentBase caldb = (CapitalAccountingLinesDocumentBase) calfb.getFinancialDocument();
List<CapitalAccountingLines> selectedCapitalAccountingLines = new ArrayList<CapitalAccountingLines>();
String distributionCode = calfb.getCapitalAccountingLine().getDistributionCode();
remainingAmountToDistribute = getRemainingAmounToDistribute(selectedCapitalAccountingLines, form);
KualiAccountingDocumentFormBase kualiAccountingDocumentFormBase = (KualiAccountingDocumentFormBase) form;
List<CapitalAssetInformation> capitalAssetInformation = this.getCurrentCapitalAssetInformationObject(kualiAccountingDocumentFormBase);
// run the process to redistribute the accounting line amount to the capital assets.
redistributeAmountsForAccountingsLineForModifyAssets(selectedCapitalAccountingLines, capitalAssetInformation, remainingAmountToDistribute);
redistributeIndividualAmountsForAccountingLinesForModifyAssets(selectedCapitalAccountingLines, capitalAssetInformation);
// now process any capital assets that has distribution set to "by amount"
redistributeAmountsForAccountingsLineForModifyAssetsByAmounts(selectedCapitalAccountingLines, capitalAssetInformation, remainingAmountToDistribute);
// adjust any variance from capital accounting lines to the distributed accounting lines amounts....
adjustCapitalAssetsAccountingLinesAmounts(selectedCapitalAccountingLines, capitalAssetInformation);
processRemainingCapitalAssetInfo(form, capitalAssetInformation);
// redistribute capital asset amount to its group accounting lines on refresh
DistributeCapitalAssetAmountToGroupAccountingLines((KualiAccountingDocumentFormBase) form);
checkCapitalAccountingLinesSelected(calfb);
return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
use of org.kuali.kfs.fp.businessobject.CapitalAssetInformation in project cu-kfs by CU-CommunityApps.
the class CapitalAssetInformationActionBase method redistributeAmountsForAccountingsLineForModifyAssets.
/**
* @param selectedCapitalAccountingLines
* @param capitalAssetInformation
* @param remainingAmountToDistribute
*/
protected void redistributeAmountsForAccountingsLineForModifyAssets(List<CapitalAccountingLines> selectedCapitalAccountingLines, List<CapitalAssetInformation> capitalAssetInformation, KualiDecimal remainingAmountToDistribute) {
// get the total capital assets quantity
int totalQuantity = getNumberOfModifiedAssetsExist(selectedCapitalAccountingLines, capitalAssetInformation);
if (totalQuantity > 0) {
KualiDecimal equalModifyAssetAmount = remainingAmountToDistribute.divide(new KualiDecimal(totalQuantity), true);
int lastAssetIndex = 0;
CapitalAssetInformation lastCapitalAsset = new CapitalAssetInformation();
if (equalModifyAssetAmount.compareTo(KualiDecimal.ZERO) != 0) {
for (CapitalAssetInformation capitalAsset : capitalAssetInformation) {
if (KFSConstants.CapitalAssets.CAPITAL_ASSET_MODIFY_ACTION_INDICATOR.equals(capitalAsset.getCapitalAssetActionIndicator()) && (ObjectUtils.isNotNull(capitalAsset.getCapitalAssetNumber())) && (KFSConstants.CapitalAssets.DISTRIBUTE_COST_EQUALLY_CODE.equalsIgnoreCase(capitalAsset.getDistributionAmountCode()))) {
if (capitalAssetExists(selectedCapitalAccountingLines, capitalAsset, KFSConstants.CapitalAssets.CAPITAL_ASSET_MODIFY_ACTION_INDICATOR)) {
capitalAsset.setCapitalAssetQuantity(1);
redistributeEqualAmounts(selectedCapitalAccountingLines, capitalAsset, equalModifyAssetAmount, totalQuantity);
lastAssetIndex++;
// get a reference to the last capital create asset to fix any variances...
lastCapitalAsset = capitalAsset;
}
}
}
}
// apply any variance left to the last
KualiDecimal varianceForAssets = remainingAmountToDistribute.subtract(equalModifyAssetAmount.multiply(new KualiDecimal(lastAssetIndex)));
if (varianceForAssets.isNonZero()) {
lastCapitalAsset.setCapitalAssetLineAmount(lastCapitalAsset.getCapitalAssetLineAmount().add(varianceForAssets));
redistributeEqualAmountsOnLastCapitalAsset(selectedCapitalAccountingLines, lastCapitalAsset, capitalAssetInformation, KFSConstants.CapitalAssets.CAPITAL_ASSET_MODIFY_ACTION_INDICATOR);
}
}
}
use of org.kuali.kfs.fp.businessobject.CapitalAssetInformation in project cu-kfs by CU-CommunityApps.
the class CapitalAssetInformationActionBase method deleteCapitalAssetInfo.
/**
* deletes the capital asset information
*/
public ActionForward deleteCapitalAssetInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
LOG.debug("deleteCapitalAssetInfoDetail() - start");
KualiAccountingDocumentFormBase kualiAccountingDocumentFormBase = (KualiAccountingDocumentFormBase) form;
List<CapitalAssetInformation> capitalAssetInformation = this.getCurrentCapitalAssetInformationObject(kualiAccountingDocumentFormBase);
if (capitalAssetInformation == null) {
return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
int lineIndexForCapitalAssetInfo = this.getLineToDelete(request);
if (capitalAssetInformation.get(lineIndexForCapitalAssetInfo).getCapitalAssetInformationDetails() != null && capitalAssetInformation.get(lineIndexForCapitalAssetInfo).getCapitalAssetInformationDetails().size() > 0) {
capitalAssetInformation.get(lineIndexForCapitalAssetInfo).getCapitalAssetInformationDetails().clear();
}
if (capitalAssetInformation.get(lineIndexForCapitalAssetInfo).getCapitalAssetAccountsGroupDetails() != null && capitalAssetInformation.get(lineIndexForCapitalAssetInfo).getCapitalAssetAccountsGroupDetails().size() > 0) {
capitalAssetInformation.get(lineIndexForCapitalAssetInfo).getCapitalAssetAccountsGroupDetails().clear();
}
capitalAssetInformation.remove(lineIndexForCapitalAssetInfo);
// now process the remaining capital asset records
processRemainingCapitalAssetInfo(form, capitalAssetInformation);
return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
Aggregations