Search in sources :

Example 46 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.

the class IWantDocument method getTotalDollarAmount.

/**
 * Calculates the total dollar amount
 *
 * @return
 */
@Override
public KualiDecimal getTotalDollarAmount() {
    KualiDecimal totalDollarAmount = KualiDecimal.ZERO;
    KualiDecimal itemTotal = KualiDecimal.ZERO;
    for (IWantItem item : items) {
        if (ObjectUtils.isNull(item.getItemQuantity())) {
            item.setItemQuantity(new KualiDecimal(1));
        }
        if (ObjectUtils.isNull(item.getItemUnitPrice())) {
            item.setItemUnitPrice(BigDecimal.ZERO);
        }
        itemTotal = new KualiDecimal(item.getItemQuantity().bigDecimalValue().multiply(item.getItemUnitPrice()));
        totalDollarAmount = totalDollarAmount.add(itemTotal);
    }
    return totalDollarAmount;
}
Also used : KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) IWantItem(edu.cornell.kfs.module.purap.businessobject.IWantItem)

Example 47 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.

the class CuB2BPurchaseOrderSciquestServiceImpl method getCxml.

@Override
public String getCxml(PurchaseOrderDocument purchaseOrder, String requisitionInitiatorPrincipalId, String password, ContractManager contractManager, String contractManagerEmail, String vendorDuns, boolean includeNewFields) {
    WorkflowDocument workFlowDocument = purchaseOrder.getDocumentHeader().getWorkflowDocument();
    String documentType = workFlowDocument.getDocumentTypeName();
    // KFSUPGRADE-1458 complete the potransmission enhancement
    int disbMethod = 0;
    String poTransmissionCode = purchaseOrder.getPurchaseOrderTransmissionMethodCode();
    if (PurapConstants.POTransmissionMethods.FAX.equalsIgnoreCase(poTransmissionCode)) {
        // fax
        disbMethod = FAX;
    } else if (CUPurapConstants.POTransmissionMethods.EMAIL.equalsIgnoreCase(poTransmissionCode)) {
        // email
        disbMethod = EMAIL;
    } else if (CUPurapConstants.POTransmissionMethods.CONVERSION.equalsIgnoreCase(poTransmissionCode)) {
        // conversion
        disbMethod = CONVERSION;
    } else {
        // manual
        disbMethod = MANUAL;
    }
    StringBuffer cxml = new StringBuffer();
    List<Note> notesToSendToVendor = getNotesToSendToVendor(purchaseOrder);
    // comment out for investigation
    if (CollectionUtils.isNotEmpty(notesToSendToVendor)) {
        cxml.append("--" + CUPurapConstants.MIME_BOUNDARY_FOR_ATTACHMENTS + "\r\n");
        cxml.append("Content-Type: application/xop+xml;\r\n");
        cxml.append("        charset=\"UTF-8\";\r\n");
        cxml.append("        type=\"text/xml\"\r\n");
        cxml.append("Content-Transfer-Encoding: 8bit\r\n");
        cxml.append("Content-ID: <1222711868656.6893160141700477326@sciquest.com>\r\n");
        // blank line before part
        cxml.append("\r\n");
    }
    cxml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    cxml.append("<!DOCTYPE PurchaseOrderMessage SYSTEM \"PO.dtd\">\n");
    cxml.append("<PurchaseOrderMessage version=\"2.0\">\n");
    cxml.append("  <Header>\n");
    // MessageId - can be whatever you would like it to be. Just make it unique.
    cxml.append("    <MessageId>KFS_cXML_PO</MessageId>\n");
    // Timestamp - it doesn't matter what's in the timezone, just that it's there (need "T" space between date/time)
    Date currentDate = getDateTimeService().getCurrentDate();
    SimpleDateFormat dateFormat = PurApDateFormatUtils.getSimpleDateFormat(PurapConstants.NamedDateFormats.CXML_SIMPLE_DATE_FORMAT);
    SimpleDateFormat timeFormat = PurApDateFormatUtils.getSimpleDateFormat(PurapConstants.NamedDateFormats.CXML_SIMPLE_TIME_FORMAT);
    cxml.append("    <Timestamp>").append(dateFormat.format(currentDate)).append("T").append(timeFormat.format(currentDate)).append("+05:30").append("</Timestamp>\n");
    cxml.append("    <Authentication>\n");
    // Cu is using useragent
    // cxml.append("      <Identity>").append(getB2bPurchaseOrderIdentity()).append("</Identity>\n");
    cxml.append("      <Identity>").append(getB2bUserAgent()).append("</Identity>\n");
    cxml.append("      <SharedSecret>").append(password).append("</SharedSecret>\n");
    cxml.append("    </Authentication>\n");
    cxml.append("  </Header>\n");
    cxml.append("  <PurchaseOrder>\n");
    // void = VOPE      ammend = CGIN ?   ammend should =
    if (StringUtils.equals(workFlowDocument.getApplicationDocumentStatus(), PurchaseOrderStatuses.APPDOC_PENDING_VOID) || documentType.equalsIgnoreCase(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_VOID_DOCUMENT)) {
        cxml.append("    <POHeader type=\"cancel\">\n");
        // KFSPTS-1458 -- otherwise distribute revision tag needs to be true (for "Fax", "Email", and "US Mail"=manual mopot).
        if (disbMethod == CONVERSION) {
            cxml.append("    <DistributeRevision>false</DistributeRevision>\n");
        } else {
            // FAX, EMAIL, MANUAL=US Mail
            cxml.append("    <DistributeRevision>true</DistributeRevision>\n");
        }
    } else if (documentType.equals(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_AMENDMENT_DOCUMENT)) {
        cxml.append("    <POHeader type=\"update\">\n");
        // KFSPTS-1458 -- otherwise distribute revision tag needs to be true (for "Fax", "Email", and "US Mail"=manual mopot).
        if (disbMethod == CONVERSION) {
            cxml.append("    <DistributeRevision>false</DistributeRevision>\n");
        } else {
            // FAX, EMAIL, MANUAL=US Mail
            cxml.append("    <DistributeRevision>true</DistributeRevision>\n");
        }
    } else {
        cxml.append("    <POHeader>\n");
    }
    cxml.append("      <PONumber>").append(purchaseOrder.getPurapDocumentIdentifier()).append("</PONumber>\n");
    cxml.append("      <Requestor>\n");
    cxml.append("        <UserProfile username=\"").append(requisitionInitiatorPrincipalId.toUpperCase(Locale.US)).append("\">\n");
    cxml.append("        </UserProfile>\n");
    cxml.append("      </Requestor>\n");
    cxml.append("      <Priority>High</Priority>\n");
    cxml.append("      <AccountingDate>").append(purchaseOrder.getPurchaseOrderCreateTimestamp()).append("</AccountingDate>\n");
    // Provide DUNS number and SupplierNumber if vendor is B2B
    if (purchaseOrder.getVendorContract() != null && purchaseOrder.getVendorContract().getVendorB2bIndicator() && disbMethod != CONVERSION) {
        /**
         *** SUPPLIER SECTION ****
         */
        cxml.append("      <Supplier>\n");
        cxml.append("        <DUNS>").append(vendorDuns).append("</DUNS>\n");
        cxml.append("        <SupplierNumber>").append(purchaseOrder.getVendorNumber()).append("</SupplierNumber>\n");
        // Type attribute is required. Valid values: main and technical. Only main will be considered for POImport.
        cxml.append("        <ContactInfo type=\"main\">\n");
        // TelephoneNumber is required. With all fields, only numeric digits will be stored. Non-numeric characters are allowed, but
        // will be stripped before storing.
        cxml.append("          <Phone>\n");
        cxml.append("            <TelephoneNumber>\n");
        cxml.append("              <CountryCode>1</CountryCode>\n");
        if (contractManager.getContractManagerPhoneNumber().length() > 4) {
            cxml.append("              <AreaCode>").append(contractManager.getContractManagerPhoneNumber().substring(0, 3)).append("</AreaCode>\n");
            cxml.append("              <Number>").append(contractManager.getContractManagerPhoneNumber().substring(3)).append("</Number>\n");
        } else {
            LOG.error("getCxml() The phone number is invalid for this contract manager: " + contractManager.getContractManagerUserIdentifier() + " " + contractManager.getContractManagerName());
            cxml.append("              <AreaCode>555</AreaCode>\n");
            cxml.append("              <Number>").append(contractManager.getContractManagerPhoneNumber()).append("</Number>\n");
        }
        cxml.append("            </TelephoneNumber>\n");
        cxml.append("          </Phone>\n");
        cxml.append("        </ContactInfo>\n");
        cxml.append("      </Supplier>\n");
    // Only pass address and distribution method if vendor is non-B2B
    } else {
        /**
         *** SUPPLIER SECTION ****
         */
        cxml.append("      <Supplier>\n");
        cxml.append("        <Name><![CDATA[").append(purchaseOrder.getVendorName()).append("]]></Name>\n");
        // Type attribute is required. Valid values: main and technical. Only main will be considered for POImport.
        cxml.append("        <ContactInfo type=\"main\">\n");
        // TelephoneNumber is required. With all fields, only numeric digits will be stored. Non-numeric characters are allowed, but
        // will be stripped before storing.
        cxml.append("          <Phone>\n");
        cxml.append("            <TelephoneNumber>\n");
        cxml.append("              <CountryCode>1</CountryCode>\n");
        if (StringUtils.isNotEmpty(purchaseOrder.getVendorPhoneNumber()) && purchaseOrder.getVendorPhoneNumber().length() > 4) {
            cxml.append("              <AreaCode>").append(purchaseOrder.getVendorPhoneNumber().substring(0, 3)).append("</AreaCode>\n");
            cxml.append("              <Number>").append(purchaseOrder.getVendorPhoneNumber().substring(3)).append("</Number>\n");
        } else {
            cxml.append("              <AreaCode>000</AreaCode>\n");
            cxml.append("              <Number>-000-0000</Number>\n");
        }
        cxml.append("            </TelephoneNumber>\n");
        cxml.append("          </Phone>\n");
        cxml.append("          <ContactAddress>\n");
        if (StringUtils.isNotEmpty(purchaseOrder.getVendorLine1Address())) {
            cxml.append("          <AddressLine label=\"Street1\" linenumber=\"1\"><![CDATA[").append(purchaseOrder.getVendorLine1Address()).append("]]></AddressLine>\n");
        }
        if (StringUtils.isNotEmpty(purchaseOrder.getVendorLine2Address())) {
            cxml.append("          <AddressLine label=\"Street2\" linenumber=\"2\"><![CDATA[").append(purchaseOrder.getVendorLine2Address()).append("]]></AddressLine>\n");
        }
        if (StringUtils.isNotEmpty(purchaseOrder.getVendorStateCode())) {
            cxml.append("          <State>").append(purchaseOrder.getBillingStateCode()).append("</State>\n");
        }
        if (StringUtils.isNotEmpty(purchaseOrder.getVendorPostalCode())) {
            cxml.append("          <PostalCode>").append(purchaseOrder.getBillingPostalCode()).append("</PostalCode>\n");
        }
        if (StringUtils.isNotEmpty(purchaseOrder.getVendorCountryCode())) {
            cxml.append("          <Country isocountrycode=\"").append(purchaseOrder.getBillingCountryCode()).append("\">").append(purchaseOrder.getBillingCountryCode()).append("</Country>\n");
        }
        cxml.append("          </ContactAddress>\n");
        cxml.append("        </ContactInfo>\n");
        cxml.append("      </Supplier>\n");
        /**
         *** DISTRIBUTION SECTION ***
         */
        VendorAddress vendorAddress = vendorService.getVendorDefaultAddress(purchaseOrder.getVendorDetail().getVendorAddresses(), VendorConstants.AddressTypes.PURCHASE_ORDER, purchaseOrder.getDeliveryCampusCode());
        cxml.append("      <OrderDistribution>\n");
        // first take fax from PO, if empty then get fax number for PO default vendor address
        String vendorFaxNumber = purchaseOrder.getVendorFaxNumber();
        if (StringUtils.isBlank(vendorFaxNumber) && vendorAddress != null) {
            vendorFaxNumber = vendorAddress.getVendorFaxNumber();
        }
        // KFSPTS-1458 -- code existing prior to this change is commented out below.
        // KFSPTS-1458 -- new code should model how fax number is determined:
        // KFSPTS-1458 -- first take vendor email address from PO, if empty then get vendor email address from PO default vendor address
        // String emailAddress = "";
        // if (vendorAddress != null) {
        // emailAddress = vendorAddress.getVendorAddressEmailAddress();
        // }
        String emailAddress = purchaseOrder.getVendorEmailAddress();
        if (StringUtils.isBlank(emailAddress) && vendorAddress != null) {
            emailAddress = vendorAddress.getVendorAddressEmailAddress();
        }
        // Distribution Method
        switch(disbMethod) {
            case FAX:
                // fax
                cxml.append("        <DistributionMethod type=\"fax\">\n");
                cxml.append("          <Fax>\n");
                cxml.append("            <TelephoneNumber>\n");
                cxml.append("              <CountryCode>1</CountryCode>\n");
                cxml.append("              <AreaCode>").append(vendorFaxNumber.substring(0, 3)).append("</AreaCode>\n");
                cxml.append("              <Number>").append(vendorFaxNumber.substring(3)).append("</Number>\n");
                cxml.append("            </TelephoneNumber>\n");
                cxml.append("          </Fax>\n");
                break;
            case EMAIL:
                // email
                cxml.append("        <DistributionMethod type=\"html_email_attachments\">\n");
                cxml.append("          <Email><![CDATA[").append(emailAddress).append("]]></Email>\n");
                break;
            case CONVERSION:
                // conversion
                // KFSPTS-1458 : removed logic that was temp mopot for conversion.
                // /**
                // * Temporary method of distribution for PO conversion effort.  Will be short-lived, so we
                // * didn't bother setting up constants and parameters to store the email, but rather hard-
                // * coded the email address.
                // */
                // cxml.append("        <DistributionMethod type=\"html_email_attachments\">\n");
                // cxml.append("          <Email><![CDATA[").append("db18@cornell.edu").append("]]></Email>\n");
                // 
                // KFSPTS-1458: replaced temp logic with distribution method type of manual
                cxml.append("        <DistributionMethod type=\"manual\">\n");
                break;
            default:
                // manual
                // KFSPTS-1458 removed: cxml.append("        <DistributionMethod type=\"manual\">\n");
                // 
                // KFSPTS-1458: US Mail = manual should be sent to EGA email address
                // KFSPTS-1458: Replaced hard coded email address with parameterized email address.
                cxml.append("        <DistributionMethod type=\"html_email_attachments\">\n");
                cxml.append("          <Email><![CDATA[").append(this.getMethodOfPOTransmissionConversionEmail()).append("]]></Email>\n");
                break;
        }
        cxml.append("        </DistributionMethod>\n");
        cxml.append("      </OrderDistribution>\n");
    }
    /**
     *** BILL TO SECTION ****
     */
    cxml.append("      <BillTo>\n");
    cxml.append("        <Address>\n");
    cxml.append("          <TemplateName>Bill To</TemplateName>\n");
    cxml.append("          <AddressCode>").append(purchaseOrder.getDeliveryCampusCode()).append("</AddressCode>\n");
    // Contact - There can be 0-5 Contact elements. The label attribute is optional.
    // TODO : this may cause sequence error from SQ if email is empty, then it will send sequence of 1,2,3,5.
    // in CU 3.0.1, it only sends billingphone#
    // cxml.append("          <Contact label=\"FirstName\" linenumber=\"1\"><![CDATA[Accounts]]></Contact>\n");
    // cxml.append("          <Contact label=\"LastName\" linenumber=\"2\"><![CDATA[Payable]]></Contact>\n");
    // cxml.append("          <Contact label=\"Company\" linenumber=\"3\"><![CDATA[").append(purchaseOrder.getBillingName().trim()).append("]]></Contact>\n");
    // // since email address is not required, we need to check whether its empty; if yes, don't add it
    // if (!StringUtils.isEmpty(purchaseOrder.getBillingEmailAddress())) {
    // cxml.append("          <Contact label=\"Email\" linenumber=\"4\"><![CDATA[").append(purchaseOrder.getBillingEmailAddress().trim()).append("]]></Contact>\n");
    // }
    // since phone number is not required, we need to check whether its empty; if yes, don't add it
    // if (!StringUtils.isEmpty(purchaseOrder.getBillingPhoneNumber())) {
    // cxml.append("          <Contact label=\"Phone\" linenumber=\"5\"><![CDATA[").append(purchaseOrder.getBillingPhoneNumber().trim()).append("]]></Contact>\n");
    cxml.append("          <Contact label=\"Phone\" linenumber=\"1\"><![CDATA[").append(purchaseOrder.getBillingPhoneNumber().trim()).append("]]></Contact>\n");
    // }
    // There must be 1-5 AddressLine elements. The label attribute is optional.
    cxml.append("          <AddressLine label=\"Street1\" linenumber=\"1\"><![CDATA[").append(purchaseOrder.getBillingLine1Address()).append("]]></AddressLine>\n");
    cxml.append("          <AddressLine label=\"Street2\" linenumber=\"2\"><![CDATA[").append(purchaseOrder.getBillingLine2Address()).append("]]></AddressLine>\n");
    // Required.
    cxml.append("          <City><![CDATA[").append(purchaseOrder.getBillingCityName()).append("]]></City>\n");
    cxml.append("          <State>").append(purchaseOrder.getBillingStateCode()).append("</State>\n");
    // Required.
    cxml.append("          <PostalCode>").append(purchaseOrder.getBillingPostalCode()).append("</PostalCode>\n");
    cxml.append("          <Country isocountrycode=\"").append(purchaseOrder.getBillingCountryCode()).append("\">").append(purchaseOrder.getBillingCountryCode()).append("</Country>\n");
    cxml.append("        </Address>\n");
    cxml.append("      </BillTo>\n");
    /**
     *** SHIP TO SECTION ****
     */
    cxml.append("      <ShipTo>\n");
    cxml.append("        <Address>\n");
    cxml.append("          <TemplateName>Ship To</TemplateName>\n");
    // AddressCode. A code to identify the address, that is sent to the supplier.
    cxml.append("          <AddressCode>").append(purchaseOrder.getDeliveryBuildingCode()).append("</AddressCode>\n");
    cxml.append("          <Contact label=\"Name\" linenumber=\"1\"><![CDATA[").append(purchaseOrder.getDeliveryToName().trim()).append("]]></Contact>\n");
    cxml.append("          <Contact label=\"PurchasingEmail\" linenumber=\"2\"><![CDATA[").append(contractManagerEmail).append("]]></Contact>\n");
    if (ObjectUtils.isNotNull(purchaseOrder.getInstitutionContactEmailAddress())) {
        cxml.append("          <Contact label=\"ContactEmail\" linenumber=\"3\"><![CDATA[").append(purchaseOrder.getInstitutionContactEmailAddress()).append("]]></Contact>\n");
    } else {
        cxml.append("          <Contact label=\"ContactEmail\" linenumber=\"3\"><![CDATA[").append(purchaseOrder.getRequestorPersonEmailAddress()).append("]]></Contact>\n");
    }
    if (ObjectUtils.isNotNull(purchaseOrder.getInstitutionContactPhoneNumber())) {
        cxml.append("          <Contact label=\"Phone\" linenumber=\"4\"><![CDATA[").append(purchaseOrder.getInstitutionContactPhoneNumber().trim()).append("]]></Contact>\n");
    } else {
        cxml.append("          <Contact label=\"Phone\" linenumber=\"4\"><![CDATA[").append(purchaseOrder.getRequestorPersonPhoneNumber()).append("]]></Contact>\n");
    }
    // check indicator to decide if receiving or delivery address should be sent to the vendor
    if (purchaseOrder.getAddressToVendorIndicator()) {
        // use receiving address
        cxml.append("          <AddressLine label=\"Street1\" linenumber=\"1\"><![CDATA[").append(purchaseOrder.getReceivingName().trim()).append("]]></AddressLine>\n");
        cxml.append("          <AddressLine label=\"Street2\" linenumber=\"2\"><![CDATA[").append(purchaseOrder.getReceivingLine1Address().trim()).append("]]></AddressLine>\n");
        if (ObjectUtils.isNull(purchaseOrder.getReceivingLine2Address())) {
            cxml.append("          <AddressLine label=\"Street3\" linenumber=\"3\"><![CDATA[").append(" ").append("]]></AddressLine>\n");
        } else {
            cxml.append("          <AddressLine label=\"Street3\" linenumber=\"3\"><![CDATA[").append(purchaseOrder.getReceivingLine2Address()).append("]]></AddressLine>\n");
        }
        cxml.append("          <City><![CDATA[").append(purchaseOrder.getReceivingCityName().trim()).append("]]></City>\n");
        cxml.append("          <State>").append(purchaseOrder.getReceivingStateCode()).append("</State>\n");
        cxml.append("          <PostalCode>").append(purchaseOrder.getReceivingPostalCode()).append("</PostalCode>\n");
        cxml.append("          <Country isocountrycode=\"").append(purchaseOrder.getReceivingCountryCode()).append("\">").append(purchaseOrder.getReceivingCountryCode()).append("</Country>\n");
    } else {
        // use final delivery address
        cxml.append(getBuildingLine(purchaseOrder));
        cxml.append("          <AddressLine label=\"Street1\" linenumber=\"1\"><![CDATA[").append(purchaseOrder.getDeliveryBuildingLine1Address().trim()).append("]]></AddressLine>\n");
        cxml.append("          <AddressLine label=\"Street2\" linenumber=\"2\"><![CDATA[Room #").append(purchaseOrder.getDeliveryBuildingRoomNumber().trim()).append("]]></AddressLine>\n");
        cxml.append("          <AddressLine label=\"Company\" linenumber=\"4\"><![CDATA[").append(purchaseOrder.getBillingName().trim()).append("]]></AddressLine>\n");
        if (ObjectUtils.isNull(purchaseOrder.getDeliveryBuildingLine2Address())) {
            cxml.append("          <AddressLine label=\"Street3\" linenumber=\"3\"><![CDATA[").append(" ").append("]]></AddressLine>\n");
        } else {
            cxml.append("          <AddressLine label=\"Street3\" linenumber=\"3\"><![CDATA[").append(purchaseOrder.getDeliveryBuildingLine2Address()).append("]]></AddressLine>\n");
        }
        cxml.append("          <City><![CDATA[").append(purchaseOrder.getDeliveryCityName().trim()).append("]]></City>\n");
        cxml.append("          <State>").append(purchaseOrder.getDeliveryStateCode()).append("</State>\n");
        cxml.append("          <PostalCode>").append(purchaseOrder.getDeliveryPostalCode()).append("</PostalCode>\n");
        cxml.append("          <Country isocountrycode=\"").append(purchaseOrder.getDeliveryCountryCode()).append("\">").append(purchaseOrder.getDeliveryCountryCode()).append("</Country>\n");
    }
    cxml.append("        </Address>\n");
    cxml.append("      </ShipTo>\n");
    // KFSUPGRADE-408
    // Get payment terms for the PO
    String payTermCode = purchaseOrder.getVendorPaymentTermsCode();
    if (StringUtils.isBlank(payTermCode)) {
        // Retrieve the vendor and pull the payment terms from the vendor record if the PO terms are null
        VendorDetail poVendor = vendorService.getByVendorNumber(purchaseOrder.getVendorNumber());
        payTermCode = poVendor.getVendorPaymentTermsCode();
    }
    PaymentTermType payTerm = businessObjectService.findBySinglePrimaryKey(PaymentTermType.class, payTermCode);
    cxml.append("      <PaymentInfo>\n");
    cxml.append("        <Terms>\n");
    if (payTerm.getVendorPaymentTermsPercent().doubleValue() > 0.0) {
        cxml.append("          <Discount>").append(payTerm.getVendorPaymentTermsPercent()).append("</Discount>\n");
    }
    if (payTerm.getVendorDiscountDueNumber().doubleValue() > 0.0) {
        cxml.append("          <Days>").append(payTerm.getVendorDiscountDueNumber()).append("</Days>\n");
    }
    cxml.append("          <Net>").append(payTerm.getVendorNetDueNumber()).append("</Net>\n");
    cxml.append("        </Terms>\n");
    cxml.append("      </PaymentInfo>\n");
    // List<Note> notesToSendToVendor = getNotesToSendToVendor(purchaseOrder);
    if (!notesToSendToVendor.isEmpty()) {
        String allNotes = "";
        String allNotesNoAttach = "";
        String vendorNoteText = purchaseOrder.getVendorNoteText();
        if (ObjectUtils.isNotNull(vendorNoteText)) {
            allNotesNoAttach = vendorNoteText;
        }
        cxml.append("      <ExternalInfo>\n");
        for (int i = 0; i < notesToSendToVendor.size(); i++) {
            Note note = notesToSendToVendor.get(i);
            Attachment attachment = attachmentService.getAttachmentByNoteId(note.getNoteIdentifier());
            if (ObjectUtils.isNotNull(attachment)) {
                allNotes = allNotes + "\n(" + (i + 1) + ") " + note.getNoteText() + "  ";
            } else {
                allNotesNoAttach = allNotesNoAttach + "          " + note.getNoteText() + "          ";
            }
        }
        cxml.append("          <Note><![CDATA[" + allNotesNoAttach + "          " + allNotes + "]]></Note>\n");
        cxml.append("        <Attachments xmlns:xop = \"http://www.w3.org/2004/08/xop/include/\" >\n");
        for (int i = 0; i < notesToSendToVendor.size(); i++) {
            Note note = notesToSendToVendor.get(i);
            Attachment attachment = attachmentService.getAttachmentByNoteId(note.getNoteIdentifier());
            if (ObjectUtils.isNotNull(attachment)) {
                cxml.append("          <Attachment id=\"" + attachment.getAttachmentIdentifier() + "\" type=\"file\">\n");
                cxml.append("            <AttachmentName><![CDATA[" + attachment.getAttachmentFileName() + "]]></AttachmentName>\n");
                cxml.append("            <AttachmentURL>http://usertest.sciquest.com/apps/Router/ReqAttachmentDownload?AttachmentId=" + attachment.getAttachmentIdentifier() + "&amp;DocId=" + purchaseOrder.getPurapDocumentIdentifier() + "&amp;OrgName=SQSupportTest&amp;AuthMethod=Local</AttachmentURL>\n");
                cxml.append("            <AttachmentSize>" + attachment.getAttachmentFileSize() / 1024 + "</AttachmentSize>\n");
                cxml.append("            <xop:Include href=\"cid:" + attachment.getAttachmentIdentifier() + "@sciquest.com\" />\n");
                cxml.append("          </Attachment>\n");
            }
        }
        cxml.append("        </Attachments>\n");
        cxml.append("      </ExternalInfo>\n");
    } else {
        String vendorNoteText = purchaseOrder.getVendorNoteText();
        if (ObjectUtils.isNotNull(vendorNoteText)) {
            cxml.append("      <ExternalInfo>\n");
            cxml.append("        <Note><![CDATA[").append(vendorNoteText).append("]]></Note>\n");
            cxml.append("      </ExternalInfo>\n");
        }
    }
    /*KFSPTS-794: End new code: Define the attachments */
    cxml.append("      <CustomFieldValueSet label=\"Contact Name\" name=\"InitiatorName\">\n");
    cxml.append("        <CustomFieldValue>\n");
    if (ObjectUtils.isNotNull(purchaseOrder.getInstitutionContactName())) {
        cxml.append("          <Value><![CDATA[").append(purchaseOrder.getInstitutionContactName()).append("]]></Value>\n");
    } else {
        cxml.append("          <Value><![CDATA[").append(purchaseOrder.getRequestorPersonName()).append("]]></Value>\n");
    }
    cxml.append("         </CustomFieldValue>\n");
    cxml.append("      </CustomFieldValueSet>\n");
    cxml.append("      <CustomFieldValueSet label=\"Supplier Address\" name=\"SupplierAddress1\">\n");
    cxml.append("        <CustomFieldValue>\n");
    cxml.append("          <Value><![CDATA[").append(purchaseOrder.getVendorLine1Address()).append("]]></Value>\n");
    cxml.append("         </CustomFieldValue>\n");
    cxml.append("      </CustomFieldValueSet>\n");
    cxml.append("      <CustomFieldValueSet label=\"Supplier City State Zip\" name=\"SupplierCityStateZip\">\n");
    cxml.append("        <CustomFieldValue>\n");
    cxml.append("          <Value><![CDATA[").append(purchaseOrder.getVendorCityName()).append(", ").append(purchaseOrder.getVendorStateCode()).append(" ").append(purchaseOrder.getVendorPostalCode()).append("]]></Value>\n");
    cxml.append("         </CustomFieldValue>\n");
    cxml.append("      </CustomFieldValueSet>\n");
    String deliveryInstructionText = purchaseOrder.getDeliveryInstructionText();
    if (ObjectUtils.isNotNull(deliveryInstructionText)) {
        cxml.append("      <CustomFieldValueSet label=\"Delivery Instructions\" name=\"Delivery Instructions\">\n");
        cxml.append("        <CustomFieldValue>\n");
        cxml.append("          <Value><![CDATA[").append(deliveryInstructionText).append("]]></Value>\n");
        cxml.append("         </CustomFieldValue>\n");
        cxml.append("      </CustomFieldValueSet>\n");
    }
    // KFSUPGRADE-583
    if (purchaseOrder.getDocumentFundingSourceCode().equalsIgnoreCase(CUPurapConstants.PurapFundingSources.FEDERAL_FUNDING_SOURCE)) {
        cxml.append("      <CustomFieldValueSet label=\"Funding\" name=\"Funding\">\n");
        cxml.append("        <CustomFieldValue>\n");
        cxml.append("          <Value><![CDATA[" + FEDERAL_FUNDING_TEXT + "]]></Value>\n");
        cxml.append("         </CustomFieldValue>\n");
        cxml.append("      </CustomFieldValueSet>\n");
    }
    // do we have to check if field is empty or null ?
    if (includeNewFields) {
        cxml.append(addCustomFieldValueSet("DeliveryPhone", "Delivery Phone", purchaseOrder.getDeliveryToPhoneNumber()));
        cxml.append(addCustomFieldValueSet("DeliveryEmail", "Delivery Email", purchaseOrder.getDeliveryToEmailAddress()));
        cxml.append(addCustomFieldValueSet("ShipTitle", "Ship Title", getVendorShipTitle(purchaseOrder)));
        cxml.append(addCustomFieldValueSet("ShipPayTerms", "Ship Pay Termse", getVendorShipPayTerms(purchaseOrder)));
        cxml.append(addCustomFieldValueSet("SupplierAddress2", "Supplier Address 2", purchaseOrder.getVendorLine2Address()));
        cxml.append(addCustomFieldValueSet("SupplierCountry", "Supplier Country", getVendorCountry(purchaseOrder)));
    }
    // end KFSUPGRADE-400 KFSPTS-427 fields
    cxml.append("    </POHeader>\n");
    /**
     *** Items Section ****
     */
    List detailList = purchaseOrder.getItems();
    for (Iterator iter = detailList.iterator(); iter.hasNext(); ) {
        PurchaseOrderItem poi = (PurchaseOrderItem) iter.next();
        if ((ObjectUtils.isNotNull(poi.getItemType())) && poi.getItemType().isLineItemIndicator()) {
            // KFSUPGRADE-406
            String uom = poi.getItemUnitOfMeasureCode();
            KualiDecimal quantity = poi.getItemQuantity();
            // Pass in value of 1 for quantity if no quantity provided. This helps handle non-quantity orders in SciQuest. KFSPTS-792
            if (quantity == null || quantity.isZero()) {
                quantity = new KualiDecimal(1);
                uom = NON_QUANTITY_UOM;
            }
            // ==== CU Customization: Use quantity of zero for inactive PO items, allowing SciQuest to cancel them properly. ====
            if (!poi.isItemActiveIndicator()) {
                quantity = new KualiDecimal(0);
            }
            // ==== End CU Customization ====
            cxml.append("    <POLine linenumber=\"").append(poi.getItemLineNumber()).append("\">\n");
            cxml.append("      <Item>\n");
            // CatalogNumber - This is a string that the supplier uses to identify the item (i.e., SKU). Optional.
            cxml.append("        <CatalogNumber><![CDATA[").append(poi.getItemCatalogNumber()).append("]]></CatalogNumber>\n");
            if (ObjectUtils.isNotNull(poi.getItemAuxiliaryPartIdentifier())) {
                cxml.append("        <AuxiliaryCatalogNumber><![CDATA[").append(poi.getItemAuxiliaryPartIdentifier()).append("]]></AuxiliaryCatalogNumber>\n");
            }
            // Required.
            cxml.append("        <Description><![CDATA[").append(poi.getItemDescription()).append("]]></Description>\n");
            cxml.append("        <ProductUnitOfMeasure type=\"supplier\"><Measurement><MeasurementValue><![CDATA[").append(uom).append("]]></MeasurementValue></Measurement></ProductUnitOfMeasure>\n");
            cxml.append("        <ProductUnitOfMeasure type=\"system\"><Measurement><MeasurementValue><![CDATA[").append(uom).append("]]></MeasurementValue></Measurement></ProductUnitOfMeasure>\n");
            // ProductReferenceNumber - Unique id for hosted products in SelectSite
            if (poi.getExternalOrganizationB2bProductTypeName().equals("Punchout")) {
                cxml.append("        <ProductReferenceNumber>null</ProductReferenceNumber>\n");
            } else {
                cxml.append("        <ProductReferenceNumber>").append(poi.getExternalOrganizationB2bProductReferenceNumber()).append("</ProductReferenceNumber>\n");
            }
            // ProductType - Describes the type of the product or service. Valid values: Catalog, Form, Punchout. Mandatory.
            if (PurapConstants.RequisitionSources.B2B.equals(purchaseOrder.getRequisitionSourceCode())) {
                cxml.append("        <ProductType>").append(poi.getExternalOrganizationB2bProductTypeName()).append("</ProductType>\n");
            } else {
                cxml.append("        <ProductType>").append("Form").append("</ProductType>\n");
            }
            cxml.append("      </Item>\n");
            cxml.append("      <Quantity>").append(quantity).append("</Quantity>\n");
            // LineCharges - All the monetary charges for this line, including the price, tax, shipping, and handling.
            // Required.
            cxml.append("      <LineCharges>\n");
            cxml.append("        <UnitPrice>\n");
            cxml.append("          <Money currency=\"USD\">").append(poi.getItemUnitPrice()).append("</Money>\n");
            cxml.append("        </UnitPrice>\n");
            cxml.append("      </LineCharges>\n");
            cxml.append("    </POLine>\n");
        }
    }
    cxml.append("  </PurchaseOrder>\n");
    cxml.append("</PurchaseOrderMessage>\r\n");
    LOG.debug("getCxml(): cXML for po number " + purchaseOrder.getPurapDocumentIdentifier() + ":\n" + cxml.toString());
    // *****************************************************************************************************************
    if (!notesToSendToVendor.isEmpty()) {
        // cxml.append("\r\n");
        for (int i = 0; i < notesToSendToVendor.size(); i++) {
            Note note = notesToSendToVendor.get(i);
            try {
                Attachment poAttachment = attachmentService.getAttachmentByNoteId(note.getNoteIdentifier());
                if (ObjectUtils.isNotNull(poAttachment)) {
                    // cxml.append("\r\n"); // blank line.  This extra blank line cause first word doc has format issue
                    cxml.append("--" + CUPurapConstants.MIME_BOUNDARY_FOR_ATTACHMENTS + "\r\n");
                    cxml.append("Content-Type: application/octet-stream\r\n");
                    // cxml.append("Content-Type: application/pdf\r\n");
                    cxml.append("Content-Transfer-Encoding: binary\r\n");
                    cxml.append("Content-ID: <" + poAttachment.getAttachmentIdentifier() + "@sciquest.com>\r\n");
                    cxml.append("Content-Disposition: attachment; filename=\"" + poAttachment.getAttachmentFileName() + "\"" + "\r\n\r\n");
                    InputStream attInputStream = poAttachment.getAttachmentContents();
                    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
                    int c;
                    while ((c = attInputStream.read()) != -1) buffer.write(c);
                    String binaryStream = new String(buffer.toByteArray(), "ISO-8859-1");
                    cxml.append(binaryStream + "\r\n");
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        // signals this is the last MIME boundary
        cxml.append("--" + CUPurapConstants.MIME_BOUNDARY_FOR_ATTACHMENTS + "--\r\n");
    } else {
    // cxml.append("\n\n--" + CUPurapConstants.MIME_BOUNDARY_FOR_ATTACHMENTS + "--\n");
    }
    return cxml.toString();
}
Also used : WorkflowDocument(org.kuali.kfs.kew.api.WorkflowDocument) InputStream(java.io.InputStream) Attachment(org.kuali.kfs.krad.bo.Attachment) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) PaymentTermType(org.kuali.kfs.vnd.businessobject.PaymentTermType) Date(java.util.Date) VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) PurchaseOrderItem(org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem) Note(org.kuali.kfs.krad.bo.Note) Iterator(java.util.Iterator) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) ArrayList(java.util.ArrayList) List(java.util.List) SimpleDateFormat(java.text.SimpleDateFormat) VendorAddress(org.kuali.kfs.vnd.businessobject.VendorAddress)

Example 48 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.

the class CuPurapServiceImpl method prorateForTradeInAndFullOrderDiscount.

public void prorateForTradeInAndFullOrderDiscount(PurchasingAccountsPayableDocument purDoc) {
    if (purDoc instanceof VendorCreditMemoDocument) {
        throw new RuntimeException("This method not applicable for VCM documents");
    }
    // TODO: are we throwing sufficient errors in this method?
    PurApItem fullOrderDiscount = null;
    PurApItem tradeIn = null;
    KualiDecimal totalAmount = KualiDecimal.ZERO;
    KualiDecimal totalTaxAmount = KualiDecimal.ZERO;
    List<PurApAccountingLine> distributedAccounts = null;
    List<SourceAccountingLine> summaryAccounts = null;
    // iterate through below the line and grab FoD and TrdIn.
    for (PurApItem item : purDoc.getItems()) {
        if (item.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE)) {
            fullOrderDiscount = item;
        } else if (item.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE)) {
            tradeIn = item;
        }
    }
    // If Discount is not null or zero get proration list for all non misc items and set (if not empty?)
    if (fullOrderDiscount != null && fullOrderDiscount.getExtendedPrice() != null && fullOrderDiscount.getExtendedPrice().isNonZero()) {
        // empty
        KNSGlobalVariables.getMessageList().add("Full order discount accounts cleared and regenerated");
        fullOrderDiscount.getSourceAccountingLines().clear();
        // total amount is pretax dollars
        totalAmount = purDoc.getTotalDollarAmountAboveLineItems().subtract(purDoc.getTotalTaxAmountAboveLineItems());
        totalTaxAmount = purDoc.getTotalTaxAmountAboveLineItems();
        // Before we generate account summary, we should update the account amounts first.
        purapAccountingService.updateAccountAmounts(purDoc);
        // calculate tax
        boolean salesTaxInd = parameterService.getParameterValueAsBoolean(KfsParameterConstants.PURCHASING_DOCUMENT.class, PurapParameterConstants.ENABLE_SALES_TAX_IND);
        boolean useTaxIndicator = purDoc.isUseTaxIndicator();
        if (salesTaxInd == true && (ObjectUtils.isNull(fullOrderDiscount.getItemTaxAmount()) && useTaxIndicator == false)) {
            KualiDecimal discountAmount = fullOrderDiscount.getExtendedPrice();
            KualiDecimal discountTaxAmount = discountAmount.divide(totalAmount).multiply(totalTaxAmount);
            fullOrderDiscount.setItemTaxAmount(discountTaxAmount);
        }
        // generate summary
        summaryAccounts = purapAccountingService.generateSummary(PurApItemUtils.getAboveTheLineOnly(purDoc.getItems()));
        if (summaryAccounts.size() == 0) {
            if (purDoc.shouldGiveErrorForEmptyAccountsProration()) {
                GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_SUMMARY_ACCOUNTS_LIST_EMPTY, "full order discount");
            }
        } else {
            // prorate accounts
            distributedAccounts = purapAccountingService.generateAccountDistributionForProration(summaryAccounts, totalAmount.add(totalTaxAmount), 2, fullOrderDiscount.getAccountingLineClass());
            for (PurApAccountingLine distributedAccount : distributedAccounts) {
                // KFSPTS-2200 : set item, so it can be verified as discount when validating
                if (distributedAccount instanceof PurApAccountingLineBase) {
                    ((PurApAccountingLineBase) distributedAccount).setDiscountTradeIn(true);
                }
                BigDecimal percent = distributedAccount.getAccountLinePercent();
                BigDecimal roundedPercent = new BigDecimal(Math.round(percent.doubleValue()));
                distributedAccount.setAccountLinePercent(roundedPercent);
            }
            // update amounts on distributed accounts
            purapAccountingService.updateAccountAmountsWithTotal(distributedAccounts, totalAmount, fullOrderDiscount.getTotalAmount());
            fullOrderDiscount.setSourceAccountingLines(distributedAccounts);
        }
    } else if (fullOrderDiscount != null && (fullOrderDiscount.getExtendedPrice() == null || fullOrderDiscount.getExtendedPrice().isZero())) {
        fullOrderDiscount.getSourceAccountingLines().clear();
    }
    // If tradeIn is not null or zero get proration list for all non misc items and set (if not empty?)
    if (tradeIn != null && tradeIn.getExtendedPrice() != null && tradeIn.getExtendedPrice().isNonZero()) {
        tradeIn.getSourceAccountingLines().clear();
        totalAmount = purDoc.getTotalDollarAmountForTradeIn();
        KualiDecimal tradeInTotalAmount = tradeIn.getTotalAmount();
        // Before we generate account summary, we should update the account amounts first.
        purapAccountingService.updateAccountAmounts(purDoc);
        // Before generating the summary, lets replace the object code in a cloned accounts collection sothat we can
        // consolidate all the modified object codes during summary generation.
        List<PurApItem> clonedTradeInItems = new ArrayList<PurApItem>();
        Collection<String> objectSubTypesRequiringQty = new ArrayList<String>(parameterService.getParameterValuesAsString(KfsParameterConstants.PURCHASING_DOCUMENT.class, PurapParameterConstants.OBJECT_SUB_TYPES_REQUIRING_QUANTITY));
        Collection<String> purchasingObjectSubTypes = new ArrayList<String>(parameterService.getParameterValuesAsString(KfsParameterConstants.CAPITAL_ASSETS_BATCH.class, PurapParameterConstants.PURCHASING_OBJECT_SUB_TYPES));
        String tradeInCapitalObjectCode = parameterService.getParameterValueAsString(PurapConstants.PURAP_NAMESPACE, "Document", "TRADE_IN_OBJECT_CODE_FOR_CAPITAL_ASSET");
        String tradeInCapitalLeaseObjCd = parameterService.getParameterValueAsString(PurapConstants.PURAP_NAMESPACE, "Document", "TRADE_IN_OBJECT_CODE_FOR_CAPITAL_LEASE");
        for (PurApItem item : purDoc.getTradeInItems()) {
            PurApItem cloneItem = (PurApItem) ObjectUtils.deepCopy(item);
            List<PurApAccountingLine> sourceAccountingLines = cloneItem.getSourceAccountingLines();
            for (PurApAccountingLine accountingLine : sourceAccountingLines) {
                if (objectSubTypesRequiringQty.contains(accountingLine.getObjectCode().getFinancialObjectSubTypeCode())) {
                    accountingLine.setFinancialObjectCode(tradeInCapitalObjectCode);
                } else if (purchasingObjectSubTypes.contains(accountingLine.getObjectCode().getFinancialObjectSubTypeCode())) {
                    accountingLine.setFinancialObjectCode(tradeInCapitalLeaseObjCd);
                }
            }
            clonedTradeInItems.add(cloneItem);
        }
        summaryAccounts = purapAccountingService.generateSummary(clonedTradeInItems);
        if (summaryAccounts.size() == 0) {
            if (purDoc.shouldGiveErrorForEmptyAccountsProration()) {
                GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_SUMMARY_ACCOUNTS_LIST_EMPTY, "trade in");
            }
        } else {
            distributedAccounts = purapAccountingService.generateAccountDistributionForProration(summaryAccounts, totalAmount, 2, tradeIn.getAccountingLineClass());
            for (PurApAccountingLine distributedAccount : distributedAccounts) {
                // KFSPTS-2200 : set item, so it can be verified as discount when validating
                if (distributedAccount instanceof PurApAccountingLineBase) {
                    ((PurApAccountingLineBase) distributedAccount).setDiscountTradeIn(true);
                }
                BigDecimal percent = distributedAccount.getAccountLinePercent();
                BigDecimal roundedPercent = new BigDecimal(Math.round(percent.doubleValue()));
                distributedAccount.setAccountLinePercent(roundedPercent);
                // set the accountAmount same as tradeIn amount not line item's amount
                resetAccountAmount(distributedAccount, tradeInTotalAmount);
            }
            tradeIn.setSourceAccountingLines(distributedAccounts);
        }
    }
}
Also used : VendorCreditMemoDocument(org.kuali.kfs.module.purap.document.VendorCreditMemoDocument) PurApItem(org.kuali.kfs.module.purap.businessobject.PurApItem) PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine) KfsParameterConstants(org.kuali.kfs.sys.service.impl.KfsParameterConstants) ArrayList(java.util.ArrayList) SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) PurApAccountingLineBase(org.kuali.kfs.module.purap.businessobject.PurApAccountingLineBase) BigDecimal(java.math.BigDecimal) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal)

Example 49 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal 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.
 */
@Override
protected String checkAutomaticPurchaseOrderRules(RequisitionDocument requisition) {
    String requisitionSource = requisition.getRequisitionSourceCode();
    KualiDecimal reqTotal = requisition.getTotalDollarAmount();
    KualiDecimal apoLimit = ((CuPurapService) purapService).getApoLimit(requisition);
    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 = personService.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())) {
            // CU mod: KFSUPGRADE-926
            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 "Requisition 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 = "Y".equals(purchaseOrderRequiresCommodityCode);
    for (Object anItem : requisition.getItems()) {
        RequisitionItem item = (RequisitionItem) anItem;
        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()) {
            List<VendorCommodityCode> vendorCommodityCodes = commodityCodeRequired ? requisition.getVendorDetail().getVendorCommodities() : null;
            String 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.";
            }
        }
    // //Base code logic check not in CU mod
    // if (!PurapConstants.RequisitionSources.B2B.equals(requisitionSource)) {
    // for (PurApAccountingLine accountingLine : item.getSourceAccountingLines()) {
    // if (capitalAssetManagementModuleService.doesAccountingLineFailAutomaticPurchaseOrderRules(
    // accountingLine)) {
    // return "Requisition contains accounting line with capital object level";
    // }
    // }
    // }
    }
    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 "";
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) CuPurapService(edu.cornell.kfs.module.purap.document.service.CuPurapService) RequisitionItem(org.kuali.kfs.module.purap.businessobject.RequisitionItem) VendorContract(org.kuali.kfs.vnd.businessobject.VendorContract) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) Person(org.kuali.kfs.kim.api.identity.Person) VendorCommodityCode(org.kuali.kfs.vnd.businessobject.VendorCommodityCode)

Example 50 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.

the class CuElectronicInvoiceHelperServiceImpl method checkQtyInvItemForNoQtyOrder.

// KFSPTS-1719 : this is for the first matched the polineitem#
private void checkQtyInvItemForNoQtyOrder(PaymentRequestDocument preqDocument, ElectronicInvoiceOrderHolder orderHolder) {
    List<PaymentRequestItem> preqItems = preqDocument.getItems();
    // non qty not in invoice yet
    List<PaymentRequestItem> nonInvItems = new ArrayList<PaymentRequestItem>();
    for (PaymentRequestItem preqItem : preqItems) {
        // This is to check the first item that matched to po line and convert to qty if inv is qty po is non-qty
        if (StringUtils.equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_SERVICE_CODE, preqItem.getItemTypeCode())) {
            if ((((CuPaymentRequestItemExtension) preqItem.getExtension()).getInvLineNumber() == null && ((CuElectronicInvoiceOrderHolder) orderHolder).getMisMatchItem() == null)) {
                ElectronicInvoiceItemHolder itemHolder = orderHolder.getItemByLineNumber(preqItem.getItemLineNumber());
                if (itemHolder != null) {
                    // if the poitem is not in invoice, then skip this
                    preqItem.setItemCatalogNumber(itemHolder.getCatalogNumberStripped());
                    // even if inv is non qty still set up these values.
                    // if (itemHolder.getInvoiceItemQuantity() != null &&
                    // (new
                    // KualiDecimal(itemHolder.getInvoiceItemQuantity())).isPositive())
                    // {
                    preqItem.setItemQuantity(new KualiDecimal(itemHolder.getInvoiceItemQuantity()));
                    preqItem.setItemUnitOfMeasureCode(itemHolder.getInvoiceItemUnitOfMeasureCode());
                    // don't set unit price for nonqty and see what happened
                    if (itemHolder.getInvoiceItemQuantity() != null && (new KualiDecimal(itemHolder.getInvoiceItemQuantity())).isPositive()) {
                        preqItem.setItemUnitPrice(itemHolder.getInvoiceItemUnitPrice());
                    }
                    preqItem.setPurchaseOrderItemUnitPrice(itemHolder.getInvoiceItemUnitPrice());
                } else {
                    nonInvItems.add(preqItem);
                }
            }
        }
    }
    if (!nonInvItems.isEmpty()) {
        preqDocument.getItems().removeAll(nonInvItems);
    }
}
Also used : PaymentRequestItem(org.kuali.kfs.module.purap.businessobject.PaymentRequestItem) ElectronicInvoiceItemHolder(org.kuali.kfs.module.purap.service.impl.ElectronicInvoiceItemHolder) ArrayList(java.util.ArrayList) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal)

Aggregations

KualiDecimal (org.kuali.kfs.core.api.util.type.KualiDecimal)280 ArrayList (java.util.ArrayList)46 HashMap (java.util.HashMap)36 Test (org.junit.Test)28 AbstractKualiDecimal (org.kuali.kfs.core.api.util.type.AbstractKualiDecimal)21 BigDecimal (java.math.BigDecimal)18 List (java.util.List)18 SourceAccountingLine (org.kuali.kfs.sys.businessobject.SourceAccountingLine)15 Date (java.sql.Date)14 CapitalAssetInformation (org.kuali.kfs.fp.businessobject.CapitalAssetInformation)14 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)14 ConcurStandardAccountingExtractDetailLine (edu.cornell.kfs.concur.batch.businessobject.ConcurStandardAccountingExtractDetailLine)11 KualiInteger (org.kuali.kfs.core.api.util.type.KualiInteger)11 ParameterService (org.kuali.kfs.coreservice.framework.parameter.ParameterService)11 IOException (java.io.IOException)10 InvoiceDetailAccountObjectCode (org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode)10 Map (java.util.Map)9 ParameterEvaluator (org.kuali.kfs.core.api.parameter.ParameterEvaluator)9 CapitalAccountingLines (org.kuali.kfs.fp.businessobject.CapitalAccountingLines)9 PurchaseOrderItem (org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem)8