use of org.kuali.kfs.vnd.businessobject.VendorContract in project cu-kfs by CU-CommunityApps.
the class PurchasingActionBase method refresh.
/**
* @see org.kuali.kfs.sys.web.struts.KualiAccountingDocumentActionBase#refresh(org.apache.struts.action.ActionMapping,
* org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
PurchasingAccountsPayableFormBase baseForm = (PurchasingAccountsPayableFormBase) form;
PurchasingDocument document = (PurchasingDocument) baseForm.getDocument();
String refreshCaller = baseForm.getRefreshCaller();
BusinessObjectService businessObjectService = SpringContext.getBean(BusinessObjectService.class);
PhoneNumberService phoneNumberService = SpringContext.getBean(PhoneNumberService.class);
// Format phone numbers
document.setInstitutionContactPhoneNumber(phoneNumberService.formatNumberIfPossible(document.getInstitutionContactPhoneNumber()));
document.setRequestorPersonPhoneNumber(phoneNumberService.formatNumberIfPossible(document.getRequestorPersonPhoneNumber()));
document.setDeliveryToPhoneNumber(phoneNumberService.formatNumberIfPossible(document.getDeliveryToPhoneNumber()));
// names in KIM are longer than what we store these names at; truncate them to match our data dictionary maxlengths
if (StringUtils.equals(refreshCaller, "kimPersonLookupable")) {
Integer deliveryToNameMaxLength = SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(document.getClass(), PurapPropertyConstants.DELIVERY_TO_NAME);
// KFSPTS-518/KFSUPGRADE-351
if (deliveryToNameMaxLength == null && document instanceof PurchaseOrderAmendmentDocument) {
deliveryToNameMaxLength = SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(PurchaseOrderDocument.class, PurapPropertyConstants.DELIVERY_TO_NAME);
}
if (StringUtils.isNotEmpty(document.getDeliveryToName()) && ObjectUtils.isNotNull(deliveryToNameMaxLength) && document.getDeliveryToName().length() > deliveryToNameMaxLength.intValue()) {
document.setDeliveryToName(document.getDeliveryToName().substring(0, deliveryToNameMaxLength));
GlobalVariables.getMessageMap().clearErrorPath();
GlobalVariables.getMessageMap().addToErrorPath(PurapConstants.DELIVERY_TAB_ERRORS);
GlobalVariables.getMessageMap().putWarning(PurapPropertyConstants.DELIVERY_TO_NAME, PurapKeyConstants.WARNING_DELIVERY_TO_NAME_TRUNCATED);
GlobalVariables.getMessageMap().removeFromErrorPath(PurapConstants.DELIVERY_TAB_ERRORS);
}
Integer requestorNameMaxLength = SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(document.getClass(), PurapPropertyConstants.REQUESTOR_PERSON_NAME);
// KFSPTS-518/KFSUPGRADE-351
if (requestorNameMaxLength == null && document instanceof PurchaseOrderAmendmentDocument) {
requestorNameMaxLength = SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(PurchaseOrderDocument.class, PurapPropertyConstants.REQUESTOR_PERSON_NAME);
}
if (StringUtils.isNotEmpty(document.getRequestorPersonName()) && ObjectUtils.isNotNull(requestorNameMaxLength) && document.getRequestorPersonName().length() > requestorNameMaxLength.intValue()) {
document.setRequestorPersonName(document.getRequestorPersonName().substring(0, requestorNameMaxLength));
GlobalVariables.getMessageMap().clearErrorPath();
GlobalVariables.getMessageMap().addToErrorPath(PurapConstants.ADDITIONAL_TAB_ERRORS);
GlobalVariables.getMessageMap().putWarning(PurapPropertyConstants.REQUESTOR_PERSON_NAME, PurapKeyConstants.WARNING_REQUESTOR_NAME_TRUNCATED);
GlobalVariables.getMessageMap().removeFromErrorPath(PurapConstants.ADDITIONAL_TAB_ERRORS);
}
}
// Refreshing the fields after returning from a vendor lookup in the vendor tab
if (StringUtils.equals(refreshCaller, VendorConstants.VENDOR_LOOKUPABLE_IMPL) && document.getVendorDetailAssignedIdentifier() != null && document.getVendorHeaderGeneratedIdentifier() != null) {
document.setVendorContractGeneratedIdentifier(null);
document.refreshReferenceObject("vendorContract");
// retrieve vendor based on selection from vendor lookup
document.refreshReferenceObject("vendorDetail");
document.templateVendorDetail(document.getVendorDetail());
// KFSPTS-1612 : populate vendor contract name
if (CollectionUtils.isNotEmpty(document.getVendorDetail().getVendorContracts())) {
for (VendorContract vendorContract : document.getVendorDetail().getVendorContracts()) {
if (vendorContract.isActive()) {
document.setVendorContractGeneratedIdentifier(vendorContract.getVendorContractGeneratedIdentifier());
document.refreshReferenceObject("vendorContract");
}
}
}
// populate default address based on selected vendor
VendorAddress defaultAddress = SpringContext.getBean(VendorService.class).getVendorDefaultAddress(document.getVendorDetail().getVendorAddresses(), document.getVendorDetail().getVendorHeader().getVendorType().getAddressType().getVendorAddressTypeCode(), document.getDeliveryCampusCode());
if (defaultAddress == null) {
GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_DOC_ADDRESS, PurapKeyConstants.ERROR_INACTIVE_VENDORADDRESS);
}
document.templateVendorAddress(defaultAddress);
// CU enhancement KFSUPGRDE-348
document.setPurchaseOrderTransmissionMethodCode(((CuVendorAddressExtension) defaultAddress.getExtension()).getPurchaseOrderTransmissionMethodCode());
}
// Refreshing the fields after returning from a contract lookup in the vendor tab
if (StringUtils.equals(refreshCaller, VendorConstants.VENDOR_CONTRACT_LOOKUPABLE_IMPL)) {
if (StringUtils.isNotEmpty(request.getParameter(KFSPropertyConstants.DOCUMENT + "." + PurapPropertyConstants.VENDOR_CONTRACT_ID))) {
// retrieve Contract based on selection from contract lookup
VendorContract refreshVendorContract = new VendorContract();
refreshVendorContract.setVendorContractGeneratedIdentifier(document.getVendorContractGeneratedIdentifier());
refreshVendorContract = (VendorContract) businessObjectService.retrieve(refreshVendorContract);
// retrieve Vendor based on selected contract
document.setVendorHeaderGeneratedIdentifier(refreshVendorContract.getVendorHeaderGeneratedIdentifier());
document.setVendorDetailAssignedIdentifier(refreshVendorContract.getVendorDetailAssignedIdentifier());
document.refreshReferenceObject("vendorDetail");
document.templateVendorDetail(document.getVendorDetail());
// always template contract after vendor to keep contract defaults last
document.templateVendorContract(refreshVendorContract);
// populate default address from selected vendor
VendorAddress defaultAddress = SpringContext.getBean(VendorService.class).getVendorDefaultAddress(document.getVendorDetail().getVendorAddresses(), document.getVendorDetail().getVendorHeader().getVendorType().getAddressType().getVendorAddressTypeCode(), "");
if (defaultAddress == null) {
GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_DOC_ADDRESS, PurapKeyConstants.ERROR_INACTIVE_VENDORADDRESS);
}
document.templateVendorAddress(defaultAddress);
// update internal dollar limit for PO since the contract might affect this value
if (document instanceof PurchaseOrderDocument) {
PurchaseOrderDocument poDoc = (PurchaseOrderDocument) document;
KualiDecimal limit = SpringContext.getBean(PurchaseOrderService.class).getInternalPurchasingDollarLimit(poDoc);
poDoc.setInternalPurchasingLimit(limit);
}
}
}
// Refreshing the fields after returning from an address lookup in the vendor tab
if (StringUtils.equals(refreshCaller, VendorConstants.VENDOR_ADDRESS_LOOKUPABLE_IMPL)) {
if (StringUtils.isNotEmpty(request.getParameter(KFSPropertyConstants.DOCUMENT + "." + PurapPropertyConstants.VENDOR_ADDRESS_ID))) {
// retrieve address based on selection from address lookup
VendorAddress refreshVendorAddress = new VendorAddress();
refreshVendorAddress.setVendorAddressGeneratedIdentifier(document.getVendorAddressGeneratedIdentifier());
refreshVendorAddress = (VendorAddress) businessObjectService.retrieve(refreshVendorAddress);
document.templateVendorAddress(refreshVendorAddress);
}
}
// Refreshing corresponding fields after returning from various kuali lookups
if (StringUtils.equals(refreshCaller, KFSConstants.KUALI_LOOKUPABLE_IMPL)) {
if (request.getParameter("document.deliveryCampusCode") != null) {
// returning from a building or campus lookup on the delivery tab (update billing address)
BillingAddress billingAddress = new BillingAddress();
billingAddress.setBillingCampusCode(document.getDeliveryCampusCode());
Map keys = SpringContext.getBean(PersistenceService.class).getPrimaryKeyFieldValues(billingAddress);
billingAddress = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(BillingAddress.class, keys);
document.templateBillingAddress(billingAddress);
if (request.getParameter("document.deliveryBuildingName") == null) {
// came from campus lookup not building, so clear building
clearDeliveryBuildingInfo(document, true);
} else {
// came from building lookup then turn off "OTHER" and clear room and line2address
document.setDeliveryBuildingOtherIndicator(false);
document.setDeliveryBuildingRoomNumber("");
document.setDeliveryBuildingLine2Address("");
}
} else if (request.getParameter("document.chartOfAccountsCode") != null) {
// returning from a chart/org lookup on the document detail tab (update receiving address)
document.loadReceivingAddress();
} else {
// returning from a building lookup in a capital asset tab location (update location address)
String buildingCodeParam = findBuildingCodeFromCapitalAssetBuildingLookup(request);
if (!StringUtils.isEmpty(buildingCodeParam)) {
PurchasingFormBase purchasingForm = (PurchasingFormBase) form;
updateCapitalAssetLocation(request, purchasingForm, document, buildingCodeParam);
}
}
}
return super.refresh(mapping, form, request, response);
}
use of org.kuali.kfs.vnd.businessobject.VendorContract in project cu-kfs by CU-CommunityApps.
the class CuRequisitionServiceImpl method checkAutomaticPurchaseOrderRules.
/**
* Checks the rule for Automatic Purchase Order eligibility of the requisition and return a String containing the reason why the
* requisition was not eligible to become an APO if it was not eligible, or return an empty String if the requisition is
* eligible to become an APO
*
* @param requisition the requisition document to be checked for APO eligibility.
* @return String containing the reason why the requisition was not eligible to become an APO if it was not eligible, or an
* empty String if the requisition is eligible to become an APO.
*/
protected String checkAutomaticPurchaseOrderRules(RequisitionDocument requisition) {
String requisitionSource = requisition.getRequisitionSourceCode();
KualiDecimal reqTotal = requisition.getTotalDollarAmount();
KualiDecimal apoLimit = purapService.getApoLimit(requisition.getVendorContractGeneratedIdentifier(), requisition.getChartOfAccountsCode(), requisition.getOrganizationCode());
requisition.setOrganizationAutomaticPurchaseOrderLimit(apoLimit);
if (LOG.isDebugEnabled()) {
LOG.debug("isAPO() reqId = " + requisition.getPurapDocumentIdentifier() + "; apoLimit = " + apoLimit + "; reqTotal = " + reqTotal);
}
if (apoLimit == null) {
return "APO limit is empty.";
} else {
if (reqTotal.compareTo(apoLimit) == 1) {
return "Requisition total is greater than the APO limit.";
}
}
if (reqTotal.compareTo(KualiDecimal.ZERO) <= 0) {
return "Requisition total is not greater than zero.";
}
if (LOG.isDebugEnabled()) {
LOG.debug("isAPO() vendor #" + requisition.getVendorHeaderGeneratedIdentifier() + "-" + requisition.getVendorDetailAssignedIdentifier());
}
if (requisition.getVendorHeaderGeneratedIdentifier() == null || requisition.getVendorDetailAssignedIdentifier() == null) {
return "Vendor was not selected from the vendor database.";
} else {
VendorDetail vendorDetail = vendorService.getVendorDetail(requisition.getVendorHeaderGeneratedIdentifier(), requisition.getVendorDetailAssignedIdentifier());
if (vendorDetail == null) {
return "Error retrieving vendor from the database.";
}
if (StringUtils.isBlank(requisition.getVendorLine1Address()) || StringUtils.isBlank(requisition.getVendorCityName()) || StringUtils.isBlank(requisition.getVendorCountryCode())) {
return "Requisition does not have all of the vendor address fields that are required for Purchase Order.";
}
requisition.setVendorRestrictedIndicator(vendorDetail.getVendorRestrictedIndicator());
if (requisition.getVendorRestrictedIndicator() != null && requisition.getVendorRestrictedIndicator()) {
return "Selected vendor is marked as restricted.";
}
if (vendorDetail.isVendorDebarred()) {
return "Selected vendor is marked as a debarred vendor";
}
requisition.setVendorDetail(vendorDetail);
if ((!PurapConstants.RequisitionSources.B2B.equals(requisitionSource)) && ObjectUtils.isNull(requisition.getVendorContractGeneratedIdentifier())) {
Person initiator = getPersonService().getPerson(requisition.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId());
VendorContract b2bContract = vendorService.getVendorB2BContract(vendorDetail, initiator.getCampusCode());
if (b2bContract != null) {
return "Standard requisition with no contract selected but a B2B contract exists for the selected vendor.";
}
}
// if the vendor is selected through vendor contract is selected
if (StringUtils.isNotBlank(requisition.getVendorContractName())) {
boolean routeToCM = parameterService.getParameterValueAsBoolean(RequisitionDocument.class, CUPurapParameterConstants.ROUTE_REQS_WITH_EXPIRED_CONTRACT_TO_CM, Boolean.FALSE);
if (routeToCM && vendorService.isVendorContractExpired(requisition, requisition.getVendorContractGeneratedIdentifier(), vendorDetail)) {
return "Contracted Vendor used where the contract end date is expired.";
}
}
}
// if vendor address isn't complete, no APO
if (StringUtils.isBlank(requisition.getVendorLine1Address()) || StringUtils.isBlank(requisition.getVendorCityName()) || StringUtils.isBlank(requisition.getVendorCountryCode()) || !postalCodeValidationService.validateAddress(requisition.getVendorCountryCode(), requisition.getVendorStateCode(), requisition.getVendorPostalCode(), "", "")) {
return "Requistion does not contain a complete vendor address";
}
// These are needed for commodity codes. They are put in here so that
// we don't have to loop through items too many times.
String purchaseOrderRequiresCommodityCode = parameterService.getParameterValueAsString(PurchaseOrderDocument.class, PurapRuleConstants.ITEMS_REQUIRE_COMMODITY_CODE_IND);
boolean commodityCodeRequired = purchaseOrderRequiresCommodityCode.equals("Y");
for (Iterator iter = requisition.getItems().iterator(); iter.hasNext(); ) {
RequisitionItem item = (RequisitionItem) iter.next();
if (item.isItemRestrictedIndicator()) {
return "Requisition contains an item that is marked as restricted.";
}
// We only need to check the commodity codes if this is an above the line item.
if (item.getItemType().isLineItemIndicator()) {
String commodityCodesReason = "";
List<VendorCommodityCode> vendorCommodityCodes = commodityCodeRequired ? requisition.getVendorDetail().getVendorCommodities() : null;
commodityCodesReason = checkAPORulesPerItemForCommodityCodes(item, vendorCommodityCodes, commodityCodeRequired);
if (StringUtils.isNotBlank(commodityCodesReason)) {
return commodityCodesReason;
}
}
if (PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE.equals(item.getItemType().getItemTypeCode()) || PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE.equals(item.getItemType().getItemTypeCode())) {
if ((item.getItemUnitPrice() != null) && ((BigDecimal.ZERO.compareTo(item.getItemUnitPrice())) != 0)) {
// discount or trade-in item has unit price that is not empty or zero
return "Requisition contains a " + item.getItemType().getItemTypeDescription() + " item, so it does not qualify as an APO.";
}
}
}
if (StringUtils.isNotEmpty(requisition.getRecurringPaymentTypeCode())) {
return "Payment type is marked as recurring.";
}
if ((requisition.getPurchaseOrderTotalLimit() != null) && (KualiDecimal.ZERO.compareTo(requisition.getPurchaseOrderTotalLimit()) != 0)) {
LOG.debug("isAPO() po total limit is not null and not equal to zero; return false.");
return "The 'PO not to exceed' amount has been entered.";
}
if (StringUtils.isNotEmpty(requisition.getAlternate1VendorName()) || StringUtils.isNotEmpty(requisition.getAlternate2VendorName()) || StringUtils.isNotEmpty(requisition.getAlternate3VendorName()) || StringUtils.isNotEmpty(requisition.getAlternate4VendorName()) || StringUtils.isNotEmpty(requisition.getAlternate5VendorName())) {
LOG.debug("isAPO() alternate vendor name exists; return false.");
return "Requisition contains additional suggested vendor names.";
}
if (requisition.isPostingYearNext() && !purapService.isTodayWithinApoAllowedRange()) {
return "Requisition is set to encumber next fiscal year and approval is not within APO allowed date range.";
}
return "";
}
use of org.kuali.kfs.vnd.businessobject.VendorContract in project cu-kfs by CU-CommunityApps.
the class CuVendorRule method validateB2BDefaultCommodityCode.
protected boolean validateB2BDefaultCommodityCode(MaintenanceDocument document) {
VendorDetail vendorDetail = (VendorDetail) document.getNewMaintainableObject().getBusinessObject();
boolean success = true;
List<VendorContract> vendorContracts = vendorDetail.getVendorContracts();
List<VendorCommodityCode> vendorCommodities = vendorDetail.getVendorCommodities();
Iterator<VendorContract> it = vendorContracts.iterator();
boolean isB2b = false;
while (it.hasNext()) {
VendorContract contract = (VendorContract) it.next();
if (contract.getVendorB2bIndicator()) {
isB2b = true;
break;
}
}
if (isB2b) {
if (vendorCommodities.size() == 0) {
success = false;
// no vendor commodities exist
putFieldError("vendorCommodities", CUVendorKeyConstants.ERROR_VENDOR_COMMODITY_CODE_DEFAULT_IS_REQUIRED_FOR_B2B);
return success;
}
boolean defaultCommodityCodeSpecified = false;
Iterator<VendorCommodityCode> commodities = vendorCommodities.iterator();
int indice = 0;
while (commodities.hasNext()) {
VendorCommodityCode commodity = (VendorCommodityCode) commodities.next();
if (commodity.isCommodityDefaultIndicator() && !defaultCommodityCodeSpecified) {
defaultCommodityCodeSpecified = true;
} else if (commodity.isCommodityDefaultIndicator()) {
// more than one "default" commodity code has been specified
putFieldError("vendorCommodities[" + indice + "].commodityDefaultIndicator", CUVendorKeyConstants.ERROR_DEFAULT_VENDOR_COMMODITY_CODE_ALREADY_EXISTS);
success = false;
}
CommodityCode persistedCommodity = commodityCodeService.getByPrimaryId(commodity.getPurchasingCommodityCode());
if (persistedCommodity == null) {
// a commodity code entered by a user does not exist
putFieldError("vendorCommodities[" + indice + "].purchasingCommodityCode", CUVendorKeyConstants.ERROR_VENDOR_COMMODITY_CODE_DOES_NOT_EXIST, commodity.getPurchasingCommodityCode());
success = false;
}
indice++;
}
if (!defaultCommodityCodeSpecified) {
// no default commodity code has been specified and the vendor has a b2b contract
putFieldError("vendorCommodities", CUVendorKeyConstants.ERROR_VENDOR_COMMODITY_CODE_DEFAULT_IS_REQUIRED_FOR_B2B);
success = false;
}
}
return success;
}
use of org.kuali.kfs.vnd.businessobject.VendorContract in project cu-kfs by CU-CommunityApps.
the class CuVendorDaoOjb method getVendorB2BContract.
public VendorContract getVendorB2BContract(VendorDetail vendorDetail, String campus, Date currentSqlDate) {
Criteria header = new Criteria();
Criteria detail = new Criteria();
Criteria campusCode = new Criteria();
Criteria beginDate = new Criteria();
// Criteria endDate = new Criteria();
Criteria b2b = new Criteria();
header.addEqualTo("VNDR_HDR_GNRTD_ID", vendorDetail.getVendorHeaderGeneratedIdentifier());
detail.addEqualTo("VNDR_DTL_ASND_ID", vendorDetail.getVendorDetailAssignedIdentifier());
campusCode.addEqualTo("VNDR_CMP_CD", campus);
beginDate.addLessOrEqualThan("VNDR_CONTR_BEG_DT", currentSqlDate);
// endDate.addGreaterOrEqualThan("VNDR_CONTR_END_DT", currentSqlDate);
b2b.addEqualTo("VNDR_B2B_IND", "Y");
header.addAndCriteria(detail);
header.addAndCriteria(campusCode);
header.addAndCriteria(beginDate);
// header.addAndCriteria(endDate);
header.addAndCriteria(b2b);
VendorContract contract = (VendorContract) getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(VendorContract.class, header));
return contract;
}
use of org.kuali.kfs.vnd.businessobject.VendorContract in project cu-kfs by CU-CommunityApps.
the class CuB2BShoppingServiceImpl method createRequisitionsFromCxml.
@Override
public List createRequisitionsFromCxml(B2BShoppingCart message, Person user) throws WorkflowException {
LOG.debug("createRequisitionsFromCxml() started");
// for returning requisitions
ArrayList requisitions = new ArrayList();
// get items from the cart
List items = message.getItems();
// get vendor(s) for the items
List vendors = getAllVendors(items);
// create requisition(s) (one per vendor)
for (Iterator iter = vendors.iterator(); iter.hasNext(); ) {
VendorDetail vendor = (VendorDetail) iter.next();
// create requisition
RequisitionDocument req = (RequisitionDocument) documentService.getNewDocument(PurapConstants.REQUISITION_DOCUMENT_TYPE);
String description = ((B2BShoppingCartItem) items.get(0)).getExtrinsic("CartName");
String businessPurpose = ((CuB2BShoppingCart) message).getBusinessPurpose();
req.getDocumentHeader().setDocumentDescription(description);
req.getDocumentHeader().setExplanation(businessPurpose);
req.setupAccountDistributionMethod();
// set b2b contract for vendor
VendorContract contract = vendorService.getVendorB2BContract(vendor, user.getCampusCode());
if (ObjectUtils.isNotNull(contract)) {
req.setVendorContractGeneratedIdentifier(contract.getVendorContractGeneratedIdentifier());
if (ObjectUtils.isNotNull(contract.getPurchaseOrderCostSourceCode())) {
// if cost source is set on contract, use it
req.setPurchaseOrderCostSourceCode(contract.getPurchaseOrderCostSourceCode());
} else {
// if cost source is null on the contract, we set it by default to "Estimate"
req.setPurchaseOrderCostSourceCode(PurapConstants.POCostSources.ESTIMATE);
}
} else {
LOG.error("createRequisitionsFromCxml() Contract is missing for vendor " + vendor.getVendorName() + " (" + vendor.getVendorNumber() + ")");
throw new B2BShoppingException(PurapConstants.B2B_VENDOR_CONTRACT_NOT_FOUND_ERROR_MESSAGE);
}
// get items for this vendor
List itemsForVendor = getAllVendorItems(items, vendor);
// KFSPTS-985
checkToPopulateFavoriteAccount(itemsForVendor, user);
// default data from user
req.setDeliveryCampusCode(user.getCampusCode());
req.setDeliveryToName(user.getName());
req.setDeliveryToEmailAddress(user.getEmailAddressUnmasked());
req.setDeliveryToPhoneNumber(SpringContext.getBean(PhoneNumberService.class).formatNumberIfPossible(user.getPhoneNumber()));
DefaultPrincipalAddress defaultPrincipalAddress = new DefaultPrincipalAddress(user.getPrincipalId());
Map addressKeys = SpringContext.getBean(PersistenceService.class).getPrimaryKeyFieldValues(defaultPrincipalAddress);
defaultPrincipalAddress = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(DefaultPrincipalAddress.class, addressKeys);
if (ObjectUtils.isNotNull(defaultPrincipalAddress) && ObjectUtils.isNotNull(defaultPrincipalAddress.getBuilding())) {
if (defaultPrincipalAddress.getBuilding().isActive()) {
req.setDeliveryCampusCode(defaultPrincipalAddress.getCampusCode());
req.templateBuildingToDeliveryAddress(defaultPrincipalAddress.getBuilding());
req.setDeliveryBuildingRoomNumber(defaultPrincipalAddress.getBuildingRoomNumber());
} else {
// since building is now inactive, delete default building record
SpringContext.getBean(BusinessObjectService.class).delete(defaultPrincipalAddress);
}
}
ChartOrgHolder purapChartOrg = SpringContext.getBean(FinancialSystemUserService.class).getPrimaryOrganization(user, PurapConstants.PURAP_NAMESPACE);
if (ObjectUtils.isNotNull(purapChartOrg)) {
req.setChartOfAccountsCode(purapChartOrg.getChartOfAccountsCode());
req.setOrganizationCode(purapChartOrg.getOrganizationCode());
}
req.setRequestorPersonName(user.getName());
req.setRequestorPersonEmailAddress(user.getEmailAddress());
req.setRequestorPersonPhoneNumber(phoneNumberService.formatNumberIfPossible(user.getPhoneNumber()));
req.setUseTaxIndicator(purchasingService.getDefaultUseTaxIndicatorValue(req));
// set defaults that need to be set
req.setVendorHeaderGeneratedIdentifier(vendor.getVendorHeaderGeneratedIdentifier());
req.setVendorDetailAssignedIdentifier(vendor.getVendorDetailAssignedIdentifier());
req.setVendorName(vendor.getVendorName());
req.setVendorRestrictedIndicator(vendor.getVendorRestrictedIndicator());
req.setItems(itemsForVendor);
req.setDocumentFundingSourceCode(parameterService.getParameterValueAsString(RequisitionDocument.class, PurapParameterConstants.DEFAULT_FUNDING_SOURCE));
req.setRequisitionSourceCode(PurapConstants.RequisitionSources.B2B);
req.updateAndSaveAppDocStatus(PurapConstants.RequisitionStatuses.APPDOC_IN_PROCESS);
// KFSPTS-1446 : Needed to move the setting of method of PO transmission to after the templateVendorAddress call because that method will set the method of PO transmission to the value on the vendor address.
// req.setPurchaseOrderTransmissionMethodCode(PurapConstants.POTransmissionMethods.ELECTRONIC);
req.setOrganizationAutomaticPurchaseOrderLimit(purapService.getApoLimit(req.getVendorContractGeneratedIdentifier(), req.getChartOfAccountsCode(), req.getOrganizationCode()));
// retrieve from an item (sent in cxml at item level, but stored in db at REQ level)
req.setExternalOrganizationB2bSupplierIdentifier(getSupplierIdFromFirstItem(itemsForVendor));
// retrieve default PO address and set address
VendorAddress vendorAddress = vendorService.getVendorDefaultAddress(vendor.getVendorHeaderGeneratedIdentifier(), vendor.getVendorDetailAssignedIdentifier(), VendorConstants.AddressTypes.PURCHASE_ORDER, user.getCampusCode());
if (ObjectUtils.isNotNull(vendorAddress)) {
req.templateVendorAddress(vendorAddress);
}
// KFSPTS-1446: Moved the setting of this attribute here from its original location to maintain the value of ELECTRONIC and not lose it to the templateVendorAddress value
req.setPurchaseOrderTransmissionMethodCode(PurapConstants.POTransmissionMethods.ELECTRONIC);
// retrieve billing address based on delivery campus and populate REQ with retrieved billing address
BillingAddress billingAddress = new BillingAddress();
billingAddress.setBillingCampusCode(req.getDeliveryCampusCode());
Map keys = persistenceService.getPrimaryKeyFieldValues(billingAddress);
billingAddress = businessObjectService.findByPrimaryKey(BillingAddress.class, keys);
req.templateBillingAddress(billingAddress);
// populate receiving address with the default one for the chart/org
req.loadReceivingAddress();
req.fixItemReferences();
// save requisition to database
purapService.saveDocumentNoValidation(req);
// add requisition to List
requisitions.add(req);
}
return requisitions;
}
Aggregations