Search in sources :

Example 46 with PurchaseOrderDocument

use of org.kuali.kfs.module.purap.document.PurchaseOrderDocument in project cu-kfs by CU-CommunityApps.

the class CuPaymentRequestServiceImpl method purchaseOrderForPaymentRequestIsWithinAutoApproveAmountLimit.

/**
 * This implementation uses the "DEFAULT_PURCHASE_ORDER_POS_APRVL_LMT_FOR_PREQ" parameter
 * to get the cutoff value for which the PO amount can allow for automatic PREQ approval.
 *
 * @see edu.cornell.kfs.module.purap.document.service.CuPaymentRequestService#isPurchaseOrderWithinAmountLimitForPaymentRequestAutoApprove(
 * org.kuali.kfs.module.purap.document.PaymentRequestDocument)
 */
@Override
public boolean purchaseOrderForPaymentRequestIsWithinAutoApproveAmountLimit(PaymentRequestDocument document) {
    PurchaseOrderDocument po = document.getPurchaseOrderDocument();
    String amountParameterValue = parameterService.getParameterValueAsString(PaymentRequestDocument.class, CUPurapParameterConstants.DEFAULT_PURCHASE_ORDER_POS_APRVL_LMT_FOR_PREQ);
    KualiDecimal amountLimit = new KualiDecimal(amountParameterValue);
    boolean withinLimit = po.getFinancialSystemDocumentHeader().getFinancialDocumentTotalAmount().isLessThan(amountLimit);
    String messagePattern = createLogMessagePatternForPOAmountLimitResult(withinLimit);
    LOG.info(MessageFormat.format(messagePattern, document.getDocumentNumber(), amountLimit.toString()));
    return withinLimit;
}
Also used : PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal)

Example 47 with PurchaseOrderDocument

use of org.kuali.kfs.module.purap.document.PurchaseOrderDocument in project cu-kfs by CU-CommunityApps.

the class CuPurchaseOrderServiceImpl method getPurchaseOrderNotes.

// mjmc end
/**
 * Overridden to use the PO's note target object ID to retrieve the notes, instead of always using the doc header as the target.
 *
 * @see org.kuali.kfs.module.purap.document.service.impl.PurchaseOrderServiceImpl#getPurchaseOrderNotes(java.lang.Integer)
 */
@Override
public List<Note> getPurchaseOrderNotes(Integer id) {
    List<Note> notes = new ArrayList<>();
    PurchaseOrderDocument po = getPurchaseOrderByDocumentNumber(purchaseOrderDao.getOldestPurchaseOrderDocumentNumber(id));
    if (ObjectUtils.isNotNull(po)) {
        // ==== CU Customization: Use the PO's actual note target instead of assuming that the doc header is the target. ====
        notes = noteService.getByRemoteObjectId(po.getNoteTarget().getObjectId());
    }
    return notes;
}
Also used : Note(org.kuali.kfs.krad.bo.Note) ArrayList(java.util.ArrayList) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) AccountingLineOverride(org.kuali.kfs.sys.businessobject.AccountingLineOverride)

Example 48 with PurchaseOrderDocument

use of org.kuali.kfs.module.purap.document.PurchaseOrderDocument in project cu-kfs by CU-CommunityApps.

the class CuPurchaseOrderAmendmentDocumentPresentationController method getEditModes.

@Override
public Set<String> getEditModes(Document document) {
    Set<String> editModes = super.getEditModes(document);
    PurchaseOrderDocument poDocument = (PurchaseOrderDocument) document;
    if (PurapConstants.PurchaseOrderStatuses.APPDOC_CHANGE_IN_PROCESS.equals(poDocument.getApplicationDocumentStatus())) {
        WorkflowDocument workflowDocument = poDocument.getFinancialSystemDocumentHeader().getWorkflowDocument();
        // amendment doc needs to lock its field for initiator while enroute
        if (workflowDocument.isInitiated() || workflowDocument.isSaved() || workflowDocument.isCompletionRequested()) {
            editModes.add(PurchaseOrderEditMode.AMENDMENT_ENTRY);
        }
    }
    // KFSUPGRADE-339
    if (PurchaseOrderStatuses.APPDOC_AWAITING_FISCAL_REVIEW.equals(((PurchaseOrderDocument) document).getApplicationDocumentStatus())) {
        editModes.add(PurchaseOrderEditMode.AMENDMENT_ENTRY);
    }
    if (SpringContext.getBean(PurapService.class).isDocumentStoppedInRouteNode((PurchasingAccountsPayableDocument) document, "New Unordered Items")) {
        editModes.add(PurchaseOrderEditMode.UNORDERED_ITEM_ACCOUNT_ENTRY);
    }
    boolean showDisableRemoveAccounts = true;
    PurchaseOrderAmendmentDocument purchaseOrderAmendmentDocument = (PurchaseOrderAmendmentDocument) document;
    List<PurApItem> aboveTheLinePOItems = PurApItemUtils.getAboveTheLineOnly(purchaseOrderAmendmentDocument.getItems());
    PurchaseOrderDocument po = (PurchaseOrderDocument) document;
    boolean containsUnpaidPaymentRequestsOrCreditMemos = po.getContainsUnpaidPaymentRequestsOrCreditMemos();
    ItemLoop: for (PurApItem poItem : aboveTheLinePOItems) {
        boolean acctLinesEditable = allowAccountingLinesAreEditable((PurchaseOrderItem) poItem, containsUnpaidPaymentRequestsOrCreditMemos);
        for (PurApAccountingLine poAccoutingLine : poItem.getSourceAccountingLines()) {
            if (!acctLinesEditable) {
                showDisableRemoveAccounts = false;
                break ItemLoop;
            }
        }
    }
    if (!showDisableRemoveAccounts) {
        editModes.add(PurchaseOrderEditMode.DISABLE_REMOVE_ACCTS);
    }
    // KFSPTS-985
    if (document instanceof PurchaseOrderDocument && !editModes.contains(RequisitionEditMode.DISABLE_SETUP_ACCT_DISTRIBUTION) && !hasEmptyAcctline((PurchaseOrderDocument) document)) {
        editModes.add(RequisitionEditMode.DISABLE_SETUP_ACCT_DISTRIBUTION);
    }
    return editModes;
}
Also used : PurchaseOrderAmendmentDocument(org.kuali.kfs.module.purap.document.PurchaseOrderAmendmentDocument) PurchaseOrderItem(org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem) PurapService(org.kuali.kfs.module.purap.document.service.PurapService) WorkflowDocument(org.kuali.rice.kew.api.WorkflowDocument) PurApItem(org.kuali.kfs.module.purap.businessobject.PurApItem) PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument)

Example 49 with PurchaseOrderDocument

use of org.kuali.kfs.module.purap.document.PurchaseOrderDocument in project cu-kfs by CU-CommunityApps.

the class CuElectronicInvoiceTestAction method generate.

public ActionForward generate(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    checkAuthorization(form, "");
    ElectronicInvoiceTestForm testForm = (ElectronicInvoiceTestForm) form;
    String poDocNumber = testForm.getPoDocNumber();
    LOG.info("Generating Electronic Invoice XML file for Purchase Order Document " + poDocNumber);
    PurchaseOrderService poService = SpringContext.getBean(PurchaseOrderService.class);
    PurchaseOrderDocument po = null;
    if (StringUtils.isBlank(poDocNumber)) {
        GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_DOCUMENT_NUMBER, PurapKeyConstants.ERROR_ELECTRONIC_INVOICE_GENERATION_PURCHASE_ORDER_NUMBER_EMPTY, new String[] { poDocNumber });
        return mapping.findForward(RiceConstants.MAPPING_BASIC);
    }
    if (!getDocumentService().documentExists(poDocNumber)) {
        GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_DOCUMENT_NUMBER, PurapKeyConstants.ERROR_ELECTRONIC_INVOICE_GENERATION_PURCHASE_ORDER_DOES_NOT_EXIST, poDocNumber);
        return mapping.findForward(RiceConstants.MAPPING_BASIC);
    }
    try {
        po = poService.getPurchaseOrderByDocumentNumber(poDocNumber);
    } catch (Exception e) {
        throw e;
    }
    response.setHeader("Cache-Control", "max-age=30");
    response.setContentType("application/xml");
    StringBuffer sbContentDispValue = new StringBuffer();
    String useJavascript = request.getParameter("useJavascript");
    if (useJavascript == null || useJavascript.equalsIgnoreCase("false")) {
        sbContentDispValue.append("attachment");
    } else {
        sbContentDispValue.append("inline");
    }
    StringBuffer sbFilename = new StringBuffer();
    sbFilename.append("PO_");
    sbFilename.append(poDocNumber);
    sbFilename.append(".xml");
    sbContentDispValue.append("; filename=");
    sbContentDispValue.append(sbFilename);
    response.setHeader("Content-disposition", sbContentDispValue.toString());
    // lookup the PO and fill in the XML with valid data
    if (po != null) {
        String duns = "";
        if (po.getVendorDetail() != null) {
            duns = StringUtils.defaultString(po.getVendorDetail().getVendorDunsNumber());
        }
        DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class);
        // getting date in kfs format
        String currDate = ElectronicInvoiceUtils.getDateDisplayText(dateTimeService.getCurrentDate());
        String vendorNumber = po.getVendorDetail().getVendorNumber();
        String eInvoiceFile = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "\n<!-- ******Testing tool generated XML****** Version 1.2." + "\n\n  Generated On " + currDate + " for PO " + po.getPurapDocumentIdentifier() + " (Doc# " + poDocNumber + ") -->\n\n" + "<!-- All the cXML attributes are junk values -->\n" + "<cXML payloadID=\"200807260401062080.964@eai002\"\n" + "    timestamp=\"2008-07-26T04:01:06-08:00\"\n" + "    version=\"1.2.014\" xml:lang=\"en\" \n" + "    xmlns=\"http://www.kuali.org/kfs/purap/electronicInvoice\" \n" + "    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" + "  <Header>\n" + "      <From>\n" + "          <Credential domain=\"DUNS\">\n" + "              <Identity>" + duns + "</Identity> <!-- DUNS number from PO Vendor " + vendorNumber + "-->\n" + "          </Credential>\n" + "      </From>\n" + "      <To>\n" + "          <Credential domain=\"NetworkId\">\n" + "              <Identity>" + "IU" + "</Identity> <!-- Hardcoded --> \n" + "          </Credential>\n" + "      </To>\n" + "      <Sender>\n" + "          <Credential domain=\"DUNS\">\n" + "              <Identity>" + duns + "</Identity> <!-- DUNS number from PO Vendor " + vendorNumber + "-->\n" + "          </Credential>\n" + "          <UserAgent/>\n" + "      </Sender>\n" + "  </Header>\n" + "  <Request deploymentMode=\"production\">\n" + "      <InvoiceDetailRequest>\n" + "          <InvoiceDetailRequestHeader\n" + "              invoiceDate=\"" + currDate + "\" invoiceID=\"" + RandomUtils.nextInt() + "\" operation=\"new\" purpose=\"standard\"> <!-- invoiceID=Random unique Id, invoiceDate=Curr date -->\n" + "              <InvoiceDetailHeaderIndicator/>\n" + "              <InvoiceDetailLineIndicator/>\n" + "              <InvoicePartner>\n" + getContactXMLChunk("billTo", po) + "              </InvoicePartner>\n" + "              <InvoicePartner>\n" + "                  <Contact addressID=\"" + RandomUtils.nextInt() + "\" role=\"remitTo\"> <!-- Vendor address -->\n" + "                      <Name xml:lang=\"en\">\n" + "                          " + po.getVendorName() + "\n" + "                      </Name>\n" + "                      <PostalAddress>\n" + "                          <Street>" + StringUtils.defaultString(po.getVendorLine1Address()) + "</Street>\n" + "                          <Street>" + StringUtils.defaultString(po.getVendorLine2Address()) + "</Street>\n" + "                          <City>" + StringUtils.defaultString(po.getVendorCityName()) + "</City>\n" + "                          <State>" + StringUtils.defaultString(po.getVendorStateCode()) + "</State>\n" + "                          <PostalCode>" + StringUtils.defaultString(po.getVendorPostalCode()) + "</PostalCode>\n" + "                          <Country isoCountryCode=\"" + StringUtils.defaultString(po.getVendorCountryCode()) + "\">\n" + "                              " + StringUtils.defaultString(po.getVendorCountry().getName()) + "\n" + "                          </Country>\n" + "                      </PostalAddress>\n" + "                  </Contact>\n" + "              </InvoicePartner>\n" + getDeliveryAddressXMLChunk("shipTo", po) + getPaymentTermXML(po) + "          </InvoiceDetailRequestHeader>\n" + "          <InvoiceDetailOrder>\n" + "              <InvoiceDetailOrderInfo>\n" + "                  <OrderReference\n" + "                      orderDate=\"" + ElectronicInvoiceUtils.getDateDisplayText(dateTimeService.getCurrentDate()) + "\" orderID=\"" + po.getPurapDocumentIdentifier() + "\"> <!--orderDate=Curr date,orderID=PO#-->\n" + "                      <DocumentReference payloadID=\"NA\" /> <!--HardCoded-->\n" + "                  </OrderReference>\n" + "              </InvoiceDetailOrderInfo>\n" + "              <!-- No junk values in Items-->\n";
        for (int i = 0; i < po.getItems().size(); i++) {
            List items = po.getItems();
            PurchaseOrderItem item = (PurchaseOrderItem) items.get(i);
            if (!item.getItemType().isAdditionalChargeIndicator()) {
                eInvoiceFile = eInvoiceFile + getPOItemXMLChunk(item);
            }
        }
        KualiDecimal totalDollarAmt = po.getTotalDollarAmount() == null ? KualiDecimal.ZERO : po.getTotalDollarAmount();
        eInvoiceFile = eInvoiceFile + "          </InvoiceDetailOrder>\n" + "          <InvoiceDetailSummary>\n" + "              <SubtotalAmount>\n" + "                  <Money currency=\"USD\">" + po.getTotalPreTaxDollarAmount() + "</Money>\n" + "              </SubtotalAmount>\n" + "              <Tax>\n" + "                  <Money currency=\"USD\">" + po.getTotalTaxAmount() + "</Money>\n" + "                  <Description xml:lang=\"en\">Total Tax</Description>\n" + "              </Tax>\n" + "              <SpecialHandlingAmount>\n" + "                  <Money currency=\"USD\">0.00</Money>\n" + "              </SpecialHandlingAmount>\n" + "              <ShippingAmount>\n" + "                  <Money currency=\"USD\">0.00</Money>\n" + "              </ShippingAmount>\n" + "              <GrossAmount>\n" + "                  <Money currency=\"USD\">" + totalDollarAmt + "</Money>\n" + "              </GrossAmount>\n" + "              <InvoiceDetailDiscount>\n" + "                  <Money currency=\"USD\">0.00</Money>\n" + "                  </InvoiceDetailDiscount>\n" + "              <NetAmount>\n" + "                  <Money currency=\"USD\">" + totalDollarAmt + "</Money>\n" + "              </NetAmount>\n" + "              <DepositAmount>\n" + "                  <Money currency=\"USD\">0.00</Money>\n" + "              </DepositAmount>\n" + "              <DueAmount>\n" + "                  <Money currency=\"USD\">" + totalDollarAmt + "</Money>\n" + "              </DueAmount>\n" + "          </InvoiceDetailSummary>\n" + "      </InvoiceDetailRequest>\n" + "  </Request>\n" + "</cXML>";
        ServletOutputStream sos;
        sos = response.getOutputStream();
        ByteArrayOutputStream baOutStream = new ByteArrayOutputStream();
        StringBufferInputStream inStream = new StringBufferInputStream(eInvoiceFile);
        convert(baOutStream, inStream);
        response.setContentLength(baOutStream.size());
        baOutStream.writeTo(sos);
        sos.flush();
    }
    return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
Also used : PurchaseOrderService(org.kuali.kfs.module.purap.document.service.PurchaseOrderService) ServletOutputStream(javax.servlet.ServletOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PurchaseOrderItem(org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem) StringBufferInputStream(java.io.StringBufferInputStream) ElectronicInvoiceTestForm(org.kuali.kfs.module.purap.document.web.struts.ElectronicInvoiceTestForm) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) List(java.util.List) DateTimeService(org.kuali.rice.core.api.datetime.DateTimeService)

Example 50 with PurchaseOrderDocument

use of org.kuali.kfs.module.purap.document.PurchaseOrderDocument in project cu-kfs by CU-CommunityApps.

the class CuPurchaseOrderAction method movePoCxer.

protected ActionForward movePoCxer(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, String newStatus, String newStatusLabel) throws Exception {
    KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
    PurchaseOrderDocument po = (PurchaseOrderDocument) kualiDocumentFormBase.getDocument();
    Object question = request.getParameter(KFSConstants.QUESTION_INST_ATTRIBUTE_NAME);
    // If the user has not received the question screen yet, then perform the PO status update.
    if (ObjectUtils.isNull(question)) {
        // Check authorization.
        checkMovePoCxerAuthorization(po);
        // Use logic similar to the executeManualStatusChange() method to override the document's status.
        try {
            PurapService purapService = SpringContext.getBean(PurapService.class);
            po.updateAndSaveAppDocStatus(newStatus);
            purapService.saveDocumentNoValidation(po);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        // Add a message to the route log.
        po.getDocumentHeader().getWorkflowDocument().logAnnotation("Moved PO document from 'Error occurred sending cxml' status to '" + newStatusLabel + "' status.");
        // Present a success message to the user.
        String message = "PO document " + po.getDocumentNumber() + " was successfully moved to '" + newStatusLabel + "' status.";
        return this.performQuestionWithoutInput(mapping, form, request, response, MOVE_CXML_ERROR_PO_SUCCESS, message, STATUS_OVERRIDE_QUESTION, MOVE_CXML_ERROR_PO_SUCCESS, "");
    }
    return returnToSender(request, mapping, kualiDocumentFormBase);
}
Also used : PurapService(org.kuali.kfs.module.purap.document.service.PurapService) KualiDocumentFormBase(org.kuali.kfs.kns.web.struts.form.KualiDocumentFormBase) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) AuthorizationException(org.kuali.kfs.krad.exception.AuthorizationException)

Aggregations

PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)52 CuPaymentRequestDocument (edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument)17 DocumentService (org.kuali.kfs.krad.service.DocumentService)16 PaymentRequestDocument (org.kuali.kfs.module.purap.document.PaymentRequestDocument)14 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)12 PaymentRequestItem (org.kuali.kfs.module.purap.businessobject.PaymentRequestItem)9 ArrayList (java.util.ArrayList)6 PurchaseOrderItem (org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem)6 RequisitionDocument (org.kuali.kfs.module.purap.document.RequisitionDocument)5 PurchaseOrderService (org.kuali.kfs.module.purap.document.service.PurchaseOrderService)5 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4 BusinessObjectService (org.kuali.kfs.krad.service.BusinessObjectService)4 MessageMap (org.kuali.kfs.krad.util.MessageMap)4 PurchaseOrderAmendmentDocument (org.kuali.kfs.module.purap.document.PurchaseOrderAmendmentDocument)4 PurapService (org.kuali.kfs.module.purap.document.service.PurapService)4 File (java.io.File)3 BigDecimal (java.math.BigDecimal)3 Iterator (java.util.Iterator)3