use of org.kuali.kfs.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(KFSConstants.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(KFSConstants.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 || "false".equalsIgnoreCase(useJavascript)) {
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);
}
use of org.kuali.kfs.core.api.datetime.DateTimeService in project cu-kfs by CU-CommunityApps.
the class CuFormatAction method start.
@Override
public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
CuFormatForm formatForm = (CuFormatForm) form;
Person kualiUser = GlobalVariables.getUserSession().getPerson();
FormatSelection formatSelection = formatService.getDataForFormat(kualiUser);
DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class);
formatForm.setCampus(kualiUser.getCampusCode());
// no data for format because another format process is already running
if (formatSelection.getStartDate() != null) {
GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.Format.ERROR_PDP_FORMAT_PROCESS_ALREADY_RUNNING, dateTimeService.toDateTimeString(formatSelection.getStartDate()));
} else {
List<CustomerProfile> customers = formatSelection.getCustomerList();
for (CustomerProfile element : customers) {
if (formatSelection.getCampus().equals(element.getDefaultPhysicalCampusProcessingCode())) {
element.setSelectedForFormat(Boolean.TRUE);
} else {
element.setSelectedForFormat(Boolean.FALSE);
}
}
formatForm.setPaymentDate(dateTimeService.toDateString(dateTimeService.getCurrentTimestamp()));
formatForm.setPaymentTypes(PdpConstants.PaymentTypes.ALL);
formatForm.setPaymentDistribution(CUPdpConstants.PaymentDistributions.PROCESS_ALL);
formatForm.setCustomers(customers);
formatForm.setRanges(formatSelection.getRangeList());
}
return mapping.findForward(PdpConstants.MAPPING_SELECTION);
}
use of org.kuali.kfs.core.api.datetime.DateTimeService in project cu-kfs by CU-CommunityApps.
the class FormatAction method prepare.
/**
* This method marks the payments for format
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward prepare(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
FormatForm formatForm = (FormatForm) form;
DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class);
if (formatForm.getCampus() == null) {
return mapping.findForward(PdpConstants.MAPPING_SELECTION);
}
// Figure out which ones they have selected
List<CustomerProfile> selectedCustomers = new ArrayList<>();
for (CustomerProfile customer : formatForm.getCustomers()) {
if (customer.isSelectedForFormat()) {
selectedCustomers.add(customer);
}
}
Date paymentDate = dateTimeService.convertToSqlDate(formatForm.getPaymentDate());
Person kualiUser = GlobalVariables.getUserSession().getPerson();
FormatProcessSummary formatProcessSummary = formatService.startFormatProcess(kualiUser, formatForm.getCampus(), selectedCustomers, paymentDate, formatForm.getPaymentTypes());
if (formatProcessSummary.getProcessSummaryList().size() == 0) {
KNSGlobalVariables.getMessageList().add(PdpKeyConstants.Format.ERROR_PDP_NO_MATCHING_PAYMENT_FOR_FORMAT);
return mapping.findForward(PdpConstants.MAPPING_SELECTION);
}
formatForm.setFormatProcessSummary(formatProcessSummary);
return mapping.findForward(PdpConstants.MAPPING_CONTINUE);
}
use of org.kuali.kfs.core.api.datetime.DateTimeService in project cu-kfs by CU-CommunityApps.
the class BatchStepRunner method main.
public static void main(String[] args) {
if (args.length < 1) {
System.err.println("ERROR: You must pass the name of the step to run on the command line.");
System.exit(8);
}
try {
SpringContextForBatchRunner.initializeKfs();
/*
* CU Customization to initialize PojoPropertyUtilsBean for batch processing
*/
PojoPlugin.initBeanUtils();
String[] stepNames;
if (args[0].indexOf(",") > 0) {
stepNames = StringUtils.split(args[0], ",");
} else {
stepNames = new String[] { args[0] };
}
ParameterService parameterService = SpringContext.getBean(ParameterService.class);
DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class);
String jobName = args.length >= 2 ? args[1] : KFSConstants.BATCH_STEP_RUNNER_JOB_NAME;
Date jobRunDate = dateTimeService.getCurrentDate();
LOG.info("Executing job: " + jobName + " steps: " + Arrays.toString(stepNames));
for (int i = 0; i < stepNames.length; ++i) {
Step step = BatchSpringContext.getStep(stepNames[i]);
if (step != null) {
Step unProxiedStep = (Step) ProxyUtils.getTargetIfProxied(step);
Class<?> stepClass = unProxiedStep.getClass();
ModuleService module = getModuleService(stepClass);
String nestedDiagnosticContext = getReportsDirectory() + File.separator + StringUtils.substringAfter(module.getModuleConfiguration().getNamespaceCode(), "-").toLowerCase(Locale.US) + File.separator + step.getName() + "-" + dateTimeService.toDateTimeStringForFilename(dateTimeService.getCurrentDate());
boolean ndcSet = false;
try {
ThreadContext.put(KFSConstants.BATCH_LOGGER_THREAD_CONTEXT_KEY, nestedDiagnosticContext);
ndcSet = true;
} catch (Exception ex) {
LOG.warn("Could not initialize custom logging for step: " + step.getName(), ex);
}
try {
if (!Job.runStep(parameterService, jobName, i, step, jobRunDate)) {
System.exit(4);
}
} finally {
if (ndcSet) {
ThreadContext.remove(KFSConstants.BATCH_LOGGER_THREAD_CONTEXT_KEY);
}
}
} else {
throw new IllegalArgumentException("Unable to find step: " + stepNames[i]);
}
}
LOG.info("Finished executing job: " + jobName + " steps: " + Arrays.toString(stepNames));
System.exit(0);
} catch (Throwable t) {
System.err.println("ERROR: Exception caught: ");
t.printStackTrace(System.err);
System.exit(8);
}
}
use of org.kuali.kfs.core.api.datetime.DateTimeService in project cu-kfs by CU-CommunityApps.
the class CreateAccountingDocumentServiceImplTest method buildMockDateTimeService.
private DateTimeService buildMockDateTimeService() throws Exception {
DateTimeService dateTimeService = Mockito.mock(DateTimeService.class);
Mockito.when(dateTimeService.toDateTimeStringForFilename(Mockito.any())).then(this::formatDate);
Mockito.when(dateTimeService.getCurrentDate()).then(this::buildNewDate);
Mockito.when(dateTimeService.getCurrentSqlDate()).then(this::buildStaticSqlDate);
return dateTimeService;
}
Aggregations