Search in sources :

Example 1 with IWantDocument

use of edu.cornell.kfs.module.purap.document.IWantDocument in project cu-kfs by CU-CommunityApps.

the class IWantDocumentFeedServiceImpl method populateIWantDocument.

/**
 * Populates an I Want document based on the input data.
 *
 * @param batchIWantDocument
 */
private void populateIWantDocument(BatchIWantDocument batchIWantDocument, String incomingFileName) {
    boolean noErrors = true;
    List<AdHocRoutePerson> adHocRoutePersons = new ArrayList<AdHocRoutePerson>();
    LOG.info("Creating I Want document from data related to source number: " + batchIWantDocument.getSourceNumber());
    try {
        if (StringUtils.isBlank(batchIWantDocument.getInitiator())) {
            LOG.error("Initiator net ID cannot be empty: " + batchIWantDocument.getInitiator());
            noErrors = false;
        }
        // if initiator is blank we cannot create the I Want doc
        if (noErrors) {
            Person initiator = personService.getPersonByPrincipalName(batchIWantDocument.getInitiator());
            if (ObjectUtils.isNull(initiator)) {
                LOG.error("Initiator net ID is not valid: " + batchIWantDocument.getInitiator());
                noErrors = false;
            }
            // if initiator is not valid we cannot create the I Want doc
            if (noErrors) {
                IWantDocument iWantDocument = (IWantDocument) documentService.getNewDocument(CUPurapConstants.IWNT_DOC_TYPE, batchIWantDocument.getInitiator());
                iWantDocumentService.setUpIWantDocDefaultValues(iWantDocument, initiator);
                if (StringUtils.isNotBlank(batchIWantDocument.getInitiatorNetID())) {
                    iWantDocument.setInitiatorNetID(batchIWantDocument.getInitiatorNetID());
                }
                iWantDocument.getDocumentHeader().setExplanation(batchIWantDocument.getBusinessPurpose());
                iWantDocument.setExplanation(batchIWantDocument.getBusinessPurpose());
                if (StringUtils.isNotBlank(batchIWantDocument.getCollegeLevelOrganization())) {
                    iWantDocument.setCollegeLevelOrganization(batchIWantDocument.getCollegeLevelOrganization());
                }
                if (StringUtils.isNotBlank(batchIWantDocument.getDepartmentLevelOrganization())) {
                    iWantDocument.setDepartmentLevelOrganization(batchIWantDocument.getDepartmentLevelOrganization());
                }
                iWantDocument.getDocumentHeader().setOrganizationDocumentNumber(batchIWantDocument.getSourceNumber());
                // populate requester fields
                populateIWantDocRequestorSection(initiator, batchIWantDocument, iWantDocument);
                // populate deliver to section
                populateIWantDocDeliverToSection(batchIWantDocument, iWantDocument);
                // populate vendor data
                if (StringUtils.isNotBlank(batchIWantDocument.getVendorNumber())) {
                    String[] vendorNumbers = batchIWantDocument.getVendorNumber().split("-");
                    if (vendorNumbers.length == 2) {
                        try {
                            Integer vendorHeaderId = new Integer(vendorNumbers[0]);
                            Integer vendorId = new Integer(vendorNumbers[1]);
                            String phoneNumber = "Phone: ";
                            Map<String, Object> fieldValues = new HashMap<String, Object>();
                            fieldValues.put("vendorHeaderGeneratedIdentifier", vendorHeaderId);
                            fieldValues.put("vendorDetailAssignedIdentifier", vendorId);
                            fieldValues.put("vendorPhoneTypeCode", "PH");
                            Collection<VendorPhoneNumber> vendorPhoneNumbers = businessObjectService.findMatching(VendorPhoneNumber.class, fieldValues);
                            if (ObjectUtils.isNotNull(vendorPhoneNumbers) && vendorPhoneNumbers.size() > 0) {
                                VendorPhoneNumber retrievedVendorPhoneNumber = vendorPhoneNumbers.toArray(new VendorPhoneNumber[1])[0];
                                phoneNumber += retrievedVendorPhoneNumber.getVendorPhoneNumber();
                            }
                            Map<String, Object> fieldValuesVendorDetail = new HashMap<String, Object>();
                            fieldValuesVendorDetail.put("vendorHeaderGeneratedIdentifier", vendorHeaderId);
                            fieldValuesVendorDetail.put("vendorDetailAssignedIdentifier", vendorId);
                            VendorDetail vendorDetail = businessObjectService.findByPrimaryKey(VendorDetail.class, fieldValuesVendorDetail);
                            if (ObjectUtils.isNotNull(vendorDetail)) {
                                iWantDocument.setVendorHeaderGeneratedIdentifier(vendorHeaderId);
                                iWantDocument.setVendorDetailAssignedIdentifier(vendorId);
                                iWantDocument.setVendorName(vendorDetail.getVendorName());
                                updateDefaultVendorAddress(vendorDetail);
                                // populate vendor info
                                String addressLine1 = vendorDetail.getDefaultAddressLine1() != null ? vendorDetail.getDefaultAddressLine1() : StringUtils.EMPTY;
                                String addressLine2 = vendorDetail.getDefaultAddressLine2() != null ? vendorDetail.getDefaultAddressLine2() : StringUtils.EMPTY;
                                String cityName = vendorDetail.getDefaultAddressCity() != null ? vendorDetail.getDefaultAddressCity() : StringUtils.EMPTY;
                                String stateCode = vendorDetail.getDefaultAddressStateCode() != null ? vendorDetail.getDefaultAddressStateCode() : StringUtils.EMPTY;
                                String countryCode = vendorDetail.getDefaultAddressCountryCode() != null ? vendorDetail.getDefaultAddressCountryCode() : StringUtils.EMPTY;
                                String postalCode = vendorDetail.getDefaultAddressPostalCode() != null ? vendorDetail.getDefaultAddressPostalCode() : StringUtils.EMPTY;
                                String faxNumber = "Fax: " + (vendorDetail.getDefaultFaxNumber() != null ? vendorDetail.getDefaultFaxNumber() : StringUtils.EMPTY);
                                String url = "URL: " + (vendorDetail.getVendorUrlAddress() != null ? vendorDetail.getVendorUrlAddress() : StringUtils.EMPTY);
                                String vendorInfo = new StringBuilder(100).append(addressLine1).append('\n').append(addressLine2).append('\n').append(cityName).append(", ").append(postalCode).append(", ").append(stateCode).append(", ").append(countryCode).append('\n').append(faxNumber).append('\n').append(phoneNumber).append(" \n").append(url).toString();
                                iWantDocument.setVendorDescription(vendorInfo);
                            } else {
                                // Invalid vendor number
                                LOG.error("Vendor with id: " + batchIWantDocument.getVendorNumber() + " does not exist.");
                                noErrors = false;
                            }
                        } catch (NumberFormatException e) {
                            LOG.error("Vendor id: " + batchIWantDocument.getVendorNumber() + " is not valid.");
                            noErrors = false;
                        }
                    } else {
                        // Invalid vendor number
                        LOG.error("Vendor ID is not valid: " + batchIWantDocument.getVendorNumber());
                        noErrors = false;
                    }
                } else {
                    if (StringUtils.isNotEmpty(batchIWantDocument.getVendorName())) {
                        iWantDocument.setVendorName(batchIWantDocument.getVendorName());
                    }
                    if (StringUtils.isNotEmpty(batchIWantDocument.getVendorDescription())) {
                        iWantDocument.setVendorDescription(batchIWantDocument.getVendorDescription());
                    }
                }
                // add items
                noErrors &= populateIWantDocItems(batchIWantDocument, iWantDocument);
                // add accounts
                noErrors &= populateIWantDocAccounts(batchIWantDocument, iWantDocument);
                // account Description
                if (StringUtils.isNotBlank(batchIWantDocument.getAccountDescriptionTxt())) {
                    iWantDocument.setAccountDescriptionTxt(batchIWantDocument.getAccountDescriptionTxt());
                }
                if (StringUtils.isNotBlank(batchIWantDocument.getCommentsAndSpecialInstructions())) {
                    iWantDocument.setCommentsAndSpecialInstructions(batchIWantDocument.getCommentsAndSpecialInstructions());
                }
                iWantDocument.setGoods(batchIWantDocument.isGoods());
                if (StringUtils.isNotBlank(batchIWantDocument.getServicePerformedOnCampus())) {
                    iWantDocument.setServicePerformedOnCampus(batchIWantDocument.getServicePerformedOnCampus());
                }
                if (StringUtils.isNotBlank(batchIWantDocument.getCurrentRouteToNetId())) {
                    Person adHocRouteTo = personService.getPersonByPrincipalName(batchIWantDocument.getCurrentRouteToNetId());
                    if (ObjectUtils.isNull(adHocRouteTo)) {
                        LOG.error("Ad Hoc Route to net ID is not valid: " + batchIWantDocument.getCurrentRouteToNetId());
                        noErrors = false;
                    } else {
                        iWantDocument.setCurrentRouteToNetId(batchIWantDocument.getCurrentRouteToNetId());
                        AdHocRoutePerson recipient = new AdHocRoutePerson();
                        recipient.setId(iWantDocument.getCurrentRouteToNetId());
                        recipient.setActionRequested(KewApiConstants.ACTION_REQUEST_APPROVE_REQ);
                        adHocRoutePersons.add(recipient);
                        iWantDocument.setAdHocRoutePersons(adHocRoutePersons);
                    }
                }
                iWantDocumentService.setIWantDocumentDescription(iWantDocument);
                // add notes
                addNotes(iWantDocument, batchIWantDocument);
                // add attachments
                loadDocumentAttachments(iWantDocument, batchIWantDocument.getAttachments(), incomingFileName);
                boolean rulePassed = true;
                // call business rules
                rulePassed &= ruleService.applyRules(new SaveDocumentEvent("", iWantDocument));
                if (!rulePassed) {
                    LOG.error("I Want document " + iWantDocument.getDocumentNumber() + "not saved due to errors");
                    logErrorMessages();
                } else if (noErrors) {
                    documentService.saveDocument(iWantDocument);
                }
            }
        }
    } catch (Exception e) {
        LOG.error("error while creating I Want document:  " + e.getMessage(), e);
        throw new RuntimeException("Error encountered while attempting to create I Want document " + e.getMessage(), e);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SaveDocumentEvent(org.kuali.kfs.krad.rules.rule.event.SaveDocumentEvent) AdHocRoutePerson(org.kuali.kfs.krad.bo.AdHocRoutePerson) VendorPhoneNumber(org.kuali.kfs.vnd.businessobject.VendorPhoneNumber) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) ParseException(org.kuali.kfs.sys.exception.ParseException) VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) AdHocRoutePerson(org.kuali.kfs.krad.bo.AdHocRoutePerson) Person(org.kuali.rice.kim.api.identity.Person) BatchIWantDocument(edu.cornell.kfs.module.purap.document.BatchIWantDocument) IWantDocument(edu.cornell.kfs.module.purap.document.IWantDocument)

Example 2 with IWantDocument

use of edu.cornell.kfs.module.purap.document.IWantDocument in project cu-kfs by CU-CommunityApps.

the class IWantDocumentPresentationController method getEditModes.

@Override
public Set<String> getEditModes(Document document) {
    Set<String> editModes = super.getEditModes(document);
    WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
    IWantDocument iWantDocument = (IWantDocument) document;
    if (SpringContext.getBean(FinancialSystemWorkflowHelperService.class).isAdhocApprovalRequestedForPrincipal(workflowDocument, GlobalVariables.getUserSession().getPrincipalId())) {
        editModes.add("completeOrder");
    }
    if (workflowDocument.isInitiated() || workflowDocument.isSaved()) {
        editModes.add("wizard");
    }
    if (CUPurapConstants.IWantDocumentSteps.CUSTOMER_DATA_STEP.equalsIgnoreCase(iWantDocument.getStep())) {
        editModes.add(CUPurapConstants.IWantDocumentSteps.CUSTOMER_DATA_STEP);
        // remove all others
        editModes.remove(CUPurapConstants.IWantDocumentSteps.ITEMS_AND_ACCT_DATA_STEP);
        editModes.remove(CUPurapConstants.IWantDocumentSteps.VENDOR_STEP);
        editModes.remove(CUPurapConstants.IWantDocumentSteps.ROUTING_STEP);
    }
    if (CUPurapConstants.IWantDocumentSteps.ITEMS_AND_ACCT_DATA_STEP.equalsIgnoreCase(iWantDocument.getStep())) {
        editModes.add(CUPurapConstants.IWantDocumentSteps.ITEMS_AND_ACCT_DATA_STEP);
        // remove all others
        editModes.remove(CUPurapConstants.IWantDocumentSteps.CUSTOMER_DATA_STEP);
        editModes.remove(CUPurapConstants.IWantDocumentSteps.VENDOR_STEP);
        editModes.remove(CUPurapConstants.IWantDocumentSteps.ROUTING_STEP);
    }
    if (CUPurapConstants.IWantDocumentSteps.VENDOR_STEP.equalsIgnoreCase(iWantDocument.getStep())) {
        editModes.add(CUPurapConstants.IWantDocumentSteps.VENDOR_STEP);
        // remove all others
        editModes.remove(CUPurapConstants.IWantDocumentSteps.CUSTOMER_DATA_STEP);
        editModes.remove(CUPurapConstants.IWantDocumentSteps.ITEMS_AND_ACCT_DATA_STEP);
        editModes.remove(CUPurapConstants.IWantDocumentSteps.ROUTING_STEP);
    }
    if (CUPurapConstants.IWantDocumentSteps.ROUTING_STEP.equalsIgnoreCase(iWantDocument.getStep())) {
        editModes.add(CUPurapConstants.IWantDocumentSteps.ROUTING_STEP);
        // remove all others
        editModes.remove(CUPurapConstants.IWantDocumentSteps.CUSTOMER_DATA_STEP);
        editModes.remove(CUPurapConstants.IWantDocumentSteps.ITEMS_AND_ACCT_DATA_STEP);
        editModes.remove(CUPurapConstants.IWantDocumentSteps.VENDOR_STEP);
    }
    // KFSPTS-2527 only display create req and create DV buttons if neither REQ not DV has been created from I Want doc
    if ((StringUtils.isBlank(iWantDocument.getReqsDocId()) && StringUtils.isBlank(iWantDocument.getDvDocId())) && !workflowDocument.isInitiated() && !workflowDocument.isSaved()) {
        editModes.add(CUPurapConstants.IWNT_DOC_CREATE_REQ);
        editModes.add(CUPurapConstants.IWNT_DOC_CREATE_DV);
    }
    editModes.add(CUPurapConstants.IWNT_DOC_USE_LOOKUPS);
    return editModes;
}
Also used : WorkflowDocument(org.kuali.rice.kew.api.WorkflowDocument) FinancialSystemWorkflowHelperService(org.kuali.kfs.sys.service.FinancialSystemWorkflowHelperService) IWantDocument(edu.cornell.kfs.module.purap.document.IWantDocument)

Example 3 with IWantDocument

use of edu.cornell.kfs.module.purap.document.IWantDocument in project cu-kfs by CU-CommunityApps.

the class CuDisbursementVoucherAction method createDVFromIWantDoc.

/**
 * Creates a DV document based on information on an I Want document.
 *
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
public ActionForward createDVFromIWantDoc(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    String iWantDocumentNumber = request.getParameter("docId");
    CuDisbursementVoucherForm disbursementVoucherForm = (CuDisbursementVoucherForm) form;
    IWantDocument iWantDocument = (IWantDocument) getDocumentService().getByDocumentHeaderId(iWantDocumentNumber);
    // Do not allow the DV to be created if the IWNT doc is already associated with another DV.
    if (iWantDocument != null && (StringUtils.isNotBlank(iWantDocument.getReqsDocId()) || StringUtils.isNotBlank(iWantDocument.getDvDocId()))) {
        GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, CUPurapKeyConstants.ERROR_DV_OR_REQ_ALREADY_CREATED_FROM_IWNT, iWantDocumentNumber);
        return mapping.findForward("error");
    }
    IWantDocumentService iWantDocumentService = SpringContext.getBean(IWantDocumentService.class);
    createDocument(disbursementVoucherForm);
    CuDisbursementVoucherDocument disbursementVoucherDocument = (CuDisbursementVoucherDocument) disbursementVoucherForm.getDocument();
    iWantDocumentService.setUpDVDetailsFromIWantDoc(iWantDocument, disbursementVoucherDocument, disbursementVoucherForm);
    // Set the DV doc ID reference on the IWantDocument.
    iWantDocument.setDvDocId(disbursementVoucherDocument.getDocumentNumber());
    SpringContext.getBean(PurapService.class).saveDocumentNoValidation(iWantDocument);
    return mapping.findForward(RiceConstants.MAPPING_BASIC);
}
Also used : CuDisbursementVoucherDocument(edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument) PurapService(org.kuali.kfs.module.purap.document.service.PurapService) IWantDocument(edu.cornell.kfs.module.purap.document.IWantDocument) IWantDocumentService(edu.cornell.kfs.module.purap.document.service.IWantDocumentService)

Example 4 with IWantDocument

use of edu.cornell.kfs.module.purap.document.IWantDocument in project cu-kfs by CU-CommunityApps.

the class IWantDocumentAction method deleteAccount.

/**
 * Deletes the selected account
 *
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
public ActionForward deleteAccount(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    IWantDocumentForm iWantForm = (IWantDocumentForm) form;
    IWantDocument iWantDocument = (IWantDocument) iWantForm.getDocument();
    iWantDocument.deleteAccount(getSelectedLine(request));
    return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
Also used : IWantDocument(edu.cornell.kfs.module.purap.document.IWantDocument) PurApFavoriteAccountLineBuilderForIWantDocument(edu.cornell.kfs.module.purap.util.PurApFavoriteAccountLineBuilderForIWantDocument)

Example 5 with IWantDocument

use of edu.cornell.kfs.module.purap.document.IWantDocument in project cu-kfs by CU-CommunityApps.

the class IWantDocumentAction method continueToCustomerData.

/**
 * Takes the user to next page
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
public ActionForward continueToCustomerData(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    IWantDocumentForm iWantForm = (IWantDocumentForm) form;
    IWantDocument iWantDocument = iWantForm.getIWantDocument();
    iWantForm.setStep(CUPurapConstants.IWantDocumentSteps.CUSTOMER_DATA_STEP);
    iWantDocument.setStep(CUPurapConstants.IWantDocumentSteps.CUSTOMER_DATA_STEP);
    return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
Also used : IWantDocument(edu.cornell.kfs.module.purap.document.IWantDocument) PurApFavoriteAccountLineBuilderForIWantDocument(edu.cornell.kfs.module.purap.util.PurApFavoriteAccountLineBuilderForIWantDocument)

Aggregations

IWantDocument (edu.cornell.kfs.module.purap.document.IWantDocument)27 PurApFavoriteAccountLineBuilderForIWantDocument (edu.cornell.kfs.module.purap.util.PurApFavoriteAccountLineBuilderForIWantDocument)18 IWantDocumentService (edu.cornell.kfs.module.purap.document.service.IWantDocumentService)8 ActionForward (org.apache.struts.action.ActionForward)7 IWantAccount (edu.cornell.kfs.module.purap.businessobject.IWantAccount)4 IWantItem (edu.cornell.kfs.module.purap.businessobject.IWantItem)4 HashMap (java.util.HashMap)3 RouteDocumentEvent (org.kuali.kfs.krad.rules.rule.event.RouteDocumentEvent)3 KualiRuleService (org.kuali.kfs.krad.service.KualiRuleService)3 WorkflowDocument (org.kuali.rice.kew.api.WorkflowDocument)3 Person (org.kuali.rice.kim.api.identity.Person)3 CuDisbursementVoucherDocument (edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument)2 LevelOrganization (edu.cornell.kfs.module.purap.businessobject.LevelOrganization)2 KualiDocumentFormBase (org.kuali.kfs.kns.web.struts.form.KualiDocumentFormBase)2 RequisitionDocument (org.kuali.kfs.module.purap.document.RequisitionDocument)2 PurapService (org.kuali.kfs.module.purap.document.service.PurapService)2 RequisitionForm (org.kuali.kfs.module.purap.document.web.struts.RequisitionForm)2 FinancialSystemWorkflowHelperService (org.kuali.kfs.sys.service.FinancialSystemWorkflowHelperService)2 VendorPhoneNumber (org.kuali.kfs.vnd.businessobject.VendorPhoneNumber)2 ConcreteKeyValue (org.kuali.rice.core.api.util.ConcreteKeyValue)2