Search in sources :

Example 6 with VendorContract

use of org.kuali.kfs.vnd.businessobject.VendorContract in project cu-kfs by CU-CommunityApps.

the class CuRequisitionDocument method toCopyFromGateway.

/**
 * toCopyFromGateway
 */
public void toCopyFromGateway() throws WorkflowException, ValidationException {
    // no validation for the KFS copy requisition rules:
    String sourceDocumentHeaderId = getDocumentNumber();
    setNewDocumentHeader();
    getDocumentHeader().setDocumentTemplateNumber(sourceDocumentHeaderId);
    // Clear out existing notes.
    if (getNotes() != null) {
        getNotes().clear();
    }
    addCopyErrorDocumentNote("copied from document " + sourceDocumentHeaderId);
    // --- LedgerPostingDocumentBase:
    setAccountingPeriod(retrieveCurrentAccountingPeriod());
    // --GeneralLedgerPostingDocumentBase:
    getGeneralLedgerPendingEntries().clear();
    // --AccountingDocumentBase:
    copyAccountingLines(false);
    updatePostingYearForAccountingLines(getSourceAccountingLines());
    updatePostingYearForAccountingLines(getTargetAccountingLines());
    // --RequisitionDocument:
    // Clear related views
    this.setAccountsPayablePurchasingDocumentLinkIdentifier(null);
    this.setRelatedViews(null);
    Person currentUser = GlobalVariables.getUserSession().getPerson();
    ChartOrgHolder purapChartOrg = SpringContext.getBean(FinancialSystemUserService.class).getPrimaryOrganization(currentUser, PurapConstants.PURAP_NAMESPACE);
    this.setPurapDocumentIdentifier(null);
    // Set req status to INPR.
    // for app doc status
    updateAndSaveAppDocStatus(PurapConstants.RequisitionStatuses.APPDOC_IN_PROCESS);
    // Set fields from the user.
    if (ObjectUtils.isNotNull(purapChartOrg)) {
        this.setChartOfAccountsCode(purapChartOrg.getChartOfAccountsCode());
        this.setOrganizationCode(purapChartOrg.getOrganizationCode());
    }
    this.setPostingYear(SpringContext.getBean(UniversityDateService.class).getCurrentFiscalYear());
    boolean activeVendor = true;
    boolean activeContract = true;
    Date today = SpringContext.getBean(DateTimeService.class).getCurrentDate();
    VendorContract vendorContract = new VendorContract();
    vendorContract.setVendorContractGeneratedIdentifier(this.getVendorContractGeneratedIdentifier());
    Map keys = SpringContext.getBean(PersistenceService.class).getPrimaryKeyFieldValues(vendorContract);
    vendorContract = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(VendorContract.class, keys);
    if (!(vendorContract != null && today.after(vendorContract.getVendorContractBeginningDate()) && today.before(vendorContract.getVendorContractEndDate()))) {
        activeContract = false;
    }
    VendorDetail vendorDetail = SpringContext.getBean(VendorService.class).getVendorDetail(this.getVendorHeaderGeneratedIdentifier(), this.getVendorDetailAssignedIdentifier());
    if (!(vendorDetail != null && vendorDetail.isActiveIndicator())) {
        activeVendor = false;
    }
    // KFSPTS-916 : need vendor address key for business rules and only way to get it is to retrieve the default PO address for the vendor.
    if (vendorDetail != null) {
        VendorAddress vendorAddress = SpringContext.getBean(VendorService.class).getVendorDefaultAddress(this.getVendorHeaderGeneratedIdentifier(), this.getVendorDetailAssignedIdentifier(), VendorConstants.AddressTypes.PURCHASE_ORDER, "");
        if (vendorAddress != null) {
            super.templateVendorAddress(vendorAddress);
        }
    }
    // B2B - only copy if contract and vendor are both active (throw separate errors to print to screen)
    if (this.getRequisitionSourceCode().equals(PurapConstants.RequisitionSources.B2B)) {
        if (!activeContract) {
        // --  throw new ValidationException(PurapKeyConstants.ERROR_REQ_COPY_EXPIRED_CONTRACT);
        }
        if (!activeVendor) {
        // -- throw new ValidationException(PurapKeyConstants.ERROR_REQ_COPY_INACTIVE_VENDOR);
        }
    }
    if (!activeVendor) {
        this.setVendorContractGeneratedIdentifier(null);
    }
    if (!activeContract) {
        this.setVendorContractGeneratedIdentifier(null);
    }
    // These fields should not be set in this method; force to be null
    this.setOrganizationAutomaticPurchaseOrderLimit(null);
    this.setPurchaseOrderAutomaticIndicator(false);
    for (Iterator iter = this.getItems().iterator(); iter.hasNext(); ) {
        RequisitionItem item = (RequisitionItem) iter.next();
        item.setPurapDocumentIdentifier(null);
        item.setItemIdentifier(null);
        for (Iterator acctIter = item.getSourceAccountingLines().iterator(); acctIter.hasNext(); ) {
            RequisitionAccount account = (RequisitionAccount) acctIter.next();
            account.setAccountIdentifier(null);
            account.setItemIdentifier(null);
        }
    }
    if (!PurapConstants.RequisitionSources.B2B.equals(this.getRequisitionSourceCode())) {
        SpringContext.getBean(PurapService.class).addBelowLineItems(this);
    }
    this.setOrganizationAutomaticPurchaseOrderLimit(SpringContext.getBean(PurapService.class).getApoLimit(this.getVendorContractGeneratedIdentifier(), this.getChartOfAccountsCode(), this.getOrganizationCode()));
    clearCapitalAssetFields();
    SpringContext.getBean(PurapService.class).clearTax(this, this.isUseTaxIndicator());
    this.refreshNonUpdateableReferences();
}
Also used : RequisitionAccount(org.kuali.kfs.module.purap.businessobject.RequisitionAccount) VendorContract(org.kuali.kfs.vnd.businessobject.VendorContract) Date(java.util.Date) PersistenceService(org.kuali.kfs.krad.service.PersistenceService) VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) VendorService(org.kuali.kfs.vnd.document.service.VendorService) RequisitionItem(org.kuali.kfs.module.purap.businessobject.RequisitionItem) PurapService(org.kuali.kfs.module.purap.document.service.PurapService) ChartOrgHolder(org.kuali.kfs.sys.businessobject.ChartOrgHolder) FinancialSystemUserService(org.kuali.kfs.sys.service.FinancialSystemUserService) Iterator(java.util.Iterator) Person(org.kuali.rice.kim.api.identity.Person) DateTimeService(org.kuali.rice.core.api.datetime.DateTimeService) Map(java.util.Map) VendorAddress(org.kuali.kfs.vnd.businessobject.VendorAddress)

Aggregations

VendorContract (org.kuali.kfs.vnd.businessobject.VendorContract)6 VendorDetail (org.kuali.kfs.vnd.businessobject.VendorDetail)4 Iterator (java.util.Iterator)3 Map (java.util.Map)3 PersistenceService (org.kuali.kfs.krad.service.PersistenceService)3 VendorAddress (org.kuali.kfs.vnd.businessobject.VendorAddress)3 BusinessObjectService (org.kuali.kfs.krad.service.BusinessObjectService)2 BillingAddress (org.kuali.kfs.module.purap.businessobject.BillingAddress)2 RequisitionItem (org.kuali.kfs.module.purap.businessobject.RequisitionItem)2 ChartOrgHolder (org.kuali.kfs.sys.businessobject.ChartOrgHolder)2 FinancialSystemUserService (org.kuali.kfs.sys.service.FinancialSystemUserService)2 VendorCommodityCode (org.kuali.kfs.vnd.businessobject.VendorCommodityCode)2 VendorService (org.kuali.kfs.vnd.document.service.VendorService)2 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)2 Person (org.kuali.rice.kim.api.identity.Person)2 CuB2BShoppingCart (edu.cornell.kfs.module.purap.util.cxml.CuB2BShoppingCart)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 Criteria (org.apache.ojb.broker.query.Criteria)1