Search in sources :

Example 11 with DateTimeService

use of org.kuali.rice.core.api.datetime.DateTimeService in project cu-kfs by CU-CommunityApps.

the class CreateAccountingDocumentServiceImplTest method buildMockDateTimeService.

private DateTimeService buildMockDateTimeService() throws Exception {
    DateTimeService dateTimeService = EasyMock.createMock(DateTimeService.class);
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HH-mm-ss-S");
    Capture<Date> dateArg = EasyMock.newCapture();
    EasyMock.expect(dateTimeService.toDateTimeStringForFilename(EasyMock.capture(dateArg))).andStubAnswer(() -> dateFormat.format(dateArg.getValue()));
    EasyMock.expect(dateTimeService.getCurrentDate()).andStubAnswer(Date::new);
    EasyMock.replay(dateTimeService);
    return dateTimeService;
}
Also used : DateTimeService(org.kuali.rice.core.api.datetime.DateTimeService) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 12 with DateTimeService

use of org.kuali.rice.core.api.datetime.DateTimeService 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)

Aggregations

DateTimeService (org.kuali.rice.core.api.datetime.DateTimeService)12 CustomerProfile (org.kuali.kfs.pdp.businessobject.CustomerProfile)4 Person (org.kuali.rice.kim.api.identity.Person)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 List (java.util.List)3 ParseException (java.text.ParseException)2 Parameter (org.kuali.kfs.coreservice.api.parameter.Parameter)2 FormatProcessSummary (org.kuali.kfs.pdp.businessobject.FormatProcessSummary)2 FormatSelection (org.kuali.kfs.pdp.businessobject.FormatSelection)2 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)2 CuFormatService (edu.cornell.kfs.pdp.service.CuFormatService)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 StringBufferInputStream (java.io.StringBufferInputStream)1 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 ParameterService (org.kuali.kfs.coreservice.framework.parameter.ParameterService)1 BusinessObjectService (org.kuali.kfs.krad.service.BusinessObjectService)1 LaborEnterpriseFeedStep (org.kuali.kfs.module.ld.batch.LaborEnterpriseFeedStep)1