List of usage examples for org.joda.time.format DateTimeFormat mediumDate
public static DateTimeFormatter mediumDate()
From source file:org.efaps.esjp.accounting.transaction.evaluation.DocumentInfo_Base.java
License:Apache License
/** * Gets the map4 substitutor./*from ww w . j a v a 2s .c o m*/ * * @param _parameter Parameter as passed by the eFaps API * @return the map4 substitutor * @throws EFapsException on error */ public final Map<String, String> getMap4Substitutor(final Parameter _parameter) throws EFapsException { final Map<String, String> ret = new HashMap<>(); final String transdateStr = _parameter.getParameterValue("date"); final DateTime transdate; if (transdateStr == null) { if (_parameter.getParameterValue("date_eFapsDate") != null) { transdate = DateUtil.getDateFromParameter(_parameter.getParameterValue("date_eFapsDate")); } else { transdate = new DateTime(); } } else { transdate = new DateTime(transdateStr); } ret.put(Accounting.SubstitutorKeys.TRANSACTION_DATE.name(), transdate.toString(DateTimeFormat.mediumDate().withLocale(Context.getThreadContext().getLocale()))); ret.put(Accounting.SubstitutorKeys.DOCUMENT_DATE.name(), getDate() == null ? "" : getDate().toString( DateTimeFormat.mediumDate().withLocale(Context.getThreadContext().getLocale()))); if (getInstance() != null && getInstance().isValid()) { ret.put(Accounting.SubstitutorKeys.DOCUMENT_TYPE.name(), getInstance().getType().getLabel()); if (getInstance().getType().isKindOf(CIERP.DocumentAbstract)) { final PrintQuery print = new PrintQuery(getInstance()); print.addAttribute(CIERP.DocumentAbstract.Name); print.executeWithoutAccessCheck(); ret.put(Accounting.SubstitutorKeys.DOCUMENT_NAME.name(), print.<String>getAttribute(CIERP.DocumentAbstract.Name)); } } else { ret.put(Accounting.SubstitutorKeys.DOCUMENT_TYPE.name(), ""); ret.put(Accounting.SubstitutorKeys.DOCUMENT_NAME.name(), ""); } return ret; }
From source file:org.efaps.esjp.accounting.transaction.Recalculate_Base.java
License:Apache License
/** * Method to recalculate rate./*from w ww . java 2 s .c o m*/ * * @param _parameter Parameter as passed from the eFaps API. * @return new Return. * @throws EFapsException on error. */ public Return recalculateRate(final Parameter _parameter) throws EFapsException { final Instance docInst = Instance.get(_parameter.getParameterValue("docInst")); final PrintQuery print = new PrintQuery(docInst); print.addAttribute(CISales.DocumentSumAbstract.RateCrossTotal, CISales.DocumentSumAbstract.CrossTotal, CISales.DocumentSumAbstract.RateCurrencyId, CISales.DocumentSumAbstract.CurrencyId, CISales.DocumentSumAbstract.Date, CISales.DocumentSumAbstract.Name); print.execute(); final BigDecimal rateCross = print.<BigDecimal>getAttribute(CISales.DocumentSumAbstract.RateCrossTotal); final BigDecimal crossTotal = print.<BigDecimal>getAttribute(CISales.DocumentSumAbstract.CrossTotal); final DateTime dateDoc = print.<DateTime>getAttribute(CISales.DocumentSumAbstract.Date); final String nameDoc = print.<String>getAttribute(CISales.DocumentSumAbstract.Name); final Instance targetCurrInst = Instance.get(CIERP.Currency.getType(), print.<Long>getAttribute(CISales.DocumentSumAbstract.RateCurrencyId)); final Instance currentInst = Instance.get(CIERP.Currency.getType(), print.<Long>getAttribute(CISales.DocumentSumAbstract.CurrencyId)); final CurrencyInst tarCurr = new CurrencyInst(targetCurrInst); final CurrencyInst curr = new CurrencyInst(currentInst); final PriceUtil priceUtil = new PriceUtil(); final BigDecimal[] rates = priceUtil.getRates(_parameter, targetCurrInst, currentInst); final BigDecimal rate = rates[2]; final BigDecimal newCrossTotal = rateCross.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO : rateCross.divide(rate, BigDecimal.ROUND_HALF_UP); final BigDecimal gainloss = newCrossTotal.subtract(crossTotal); final Map<String, String[]> map = validateInfo(_parameter, gainloss); final String[] accs = map.get("accs"); final String[] check = map.get("check"); if (checkAccounts(accs, 0, check).length() > 0 && checkAccounts(accs, 1, check).length() > 0) { if (gainloss.compareTo(BigDecimal.ZERO) != 0) { if (!tarCurr.equals(curr)) { final String[] accOids = map.get("accountOids"); final Insert insert = new Insert(CIAccounting.Transaction); final StringBuilder description = new StringBuilder(); final DateTimeFormatter formater = DateTimeFormat.mediumDate(); final String dateStr = dateDoc.withChronology(Context.getThreadContext().getChronology()) .toString(formater.withLocale(Context.getThreadContext().getLocale())); description .append(DBProperties .getProperty("Accounting_TransactionRecalculateForm.TxnRecalculate.Label")) .append(" ").append(nameDoc).append(" ").append(dateStr); insert.add(CIAccounting.Transaction.Description, description); insert.add(CIAccounting.Transaction.Date, _parameter.getParameterValue("date")); insert.add(CIAccounting.Transaction.PeriodLink, _parameter.getInstance().getId()); insert.add(CIAccounting.Transaction.Status, Status.find(CIAccounting.TransactionStatus.uuid, "Open").getId()); insert.execute(); final Instance instance = insert.getInstance(); new Create().connectDocs2Transaction(_parameter, instance, docInst); final Insert insert2 = new Insert(CIAccounting.TransactionPositionCredit); insert2.add(CIAccounting.TransactionPositionCredit.TransactionLink, instance.getId()); insert2.add(CIAccounting.TransactionPositionCredit.AccountLink, Instance.get(accOids[1]).getId()); insert2.add(CIAccounting.TransactionPositionCredit.CurrencyLink, curr.getInstance().getId()); insert2.add(CIAccounting.TransactionPositionCredit.RateCurrencyLink, curr.getInstance().getId()); insert2.add(CIAccounting.TransactionPositionCredit.Rate, new Object[] { 1, 1 }); insert2.add(CIAccounting.TransactionPositionCredit.RateAmount, gainloss.abs()); insert2.add(CIAccounting.TransactionPositionCredit.Amount, gainloss.abs()); insert2.execute(); final Insert insert3 = new Insert(CIAccounting.TransactionPositionDebit); insert3.add(CIAccounting.TransactionPositionDebit.TransactionLink, instance.getId()); insert3.add(CIAccounting.TransactionPositionDebit.AccountLink, Instance.get(accOids[0]).getId()); insert3.add(CIAccounting.TransactionPositionDebit.CurrencyLink, curr.getInstance().getId()); insert3.add(CIAccounting.TransactionPositionDebit.RateCurrencyLink, curr.getInstance().getId()); insert3.add(CIAccounting.TransactionPositionDebit.Rate, new Object[] { 1, 1 }); insert3.add(CIAccounting.TransactionPositionDebit.RateAmount, gainloss.abs().negate()); insert3.add(CIAccounting.TransactionPositionDebit.Amount, gainloss.abs().negate()); insert3.execute(); _parameter.put(ParameterValues.INSTANCE, docInst); new Accounting4DocSum().recalculateRate(_parameter); } } } return new Return(); }
From source file:org.efaps.esjp.accounting.transaction.Recalculate_Base.java
License:Apache License
/** * Creates the gain loss4 document account. * * @param _parameter Parameter as passed by the eFaps API * @return the return// w w w. ja v a 2 s .c o m * @throws EFapsException on error */ public Return createGainLoss4DocumentAccount(final Parameter _parameter) throws EFapsException { final Set<String> setAccounts = getAccounts4DocumentConfig(_parameter); final String[] oidsDoc = (String[]) Context.getThreadContext().getSessionAttribute( CIFormAccounting.Accounting_GainLoss4DocumentAccountForm.selectedDocuments.name); final DateTime dateTo = new DateTime(_parameter .getParameterValue(CIFormAccounting.Accounting_GainLoss4DocumentAccountForm.transactionDate.name)); for (final String oid : oidsDoc) { final Instance instDoc = Instance.get(oid); final QueryBuilder attrQuerBldr = new QueryBuilder(CIAccounting.Transaction2SalesDocument); attrQuerBldr.addWhereAttrEqValue(CIAccounting.Transaction2SalesDocument.ToLink, instDoc); final AttributeQuery attrQuery = attrQuerBldr .getAttributeQuery(CIAccounting.Transaction2SalesDocument.FromLink); // filter classification Document final QueryBuilder attrQueryBldr2 = new QueryBuilder(CIAccounting.Transaction); attrQueryBldr2.addWhereAttrEqValue(CIAccounting.Transaction.PeriodLink, _parameter.getInstance().getId()); attrQueryBldr2.addWhereAttrInQuery(CIAccounting.Transaction.ID, attrQuery); final AttributeQuery attrQuery2 = attrQuerBldr.getAttributeQuery(CIAccounting.Transaction.ID); final QueryBuilder queryBldr = new QueryBuilder(CIAccounting.TransactionPositionAbstract); queryBldr.addWhereAttrInQuery(CIAccounting.TransactionPositionAbstract.TransactionLink, attrQuery2); final MultiPrintQuery multi = queryBldr.getPrint(); multi.addAttribute(CIAccounting.TransactionPositionAbstract.Amount, CIAccounting.TransactionPositionAbstract.RateAmount, CIAccounting.TransactionPositionAbstract.CurrencyLink, CIAccounting.TransactionPositionAbstract.RateCurrencyLink); final SelectBuilder selAcc = new SelectBuilder() .linkto(CIAccounting.TransactionPositionAbstract.AccountLink).oid(); multi.addSelect(selAcc); multi.execute(); final Map<String, AccountInfo> map = new HashMap<>(); while (multi.next()) { final Instance accountInst = Instance.get(multi.<String>getSelect(selAcc)); if (setAccounts.contains(accountInst.getOid())) { final BigDecimal oldRateAmount = multi .<BigDecimal>getAttribute(CIAccounting.TransactionPositionAbstract.RateAmount); final BigDecimal oldAmount = multi .<BigDecimal>getAttribute(CIAccounting.TransactionPositionAbstract.Amount); final Instance targetCurrInst = Instance.get(CIERP.Currency.getType(), multi.<Long>getAttribute(CIAccounting.TransactionPositionAbstract.RateCurrencyLink)); final Instance currentInst = Instance.get(CIERP.Currency.getType(), multi.<Long>getAttribute(CIAccounting.TransactionPositionAbstract.CurrencyLink)); final PriceUtil priceUtil = new PriceUtil(); final BigDecimal[] rates = priceUtil.getRates(_parameter, targetCurrInst, currentInst); final BigDecimal rate = rates[2]; final BigDecimal newAmount = oldRateAmount.divide(rate, BigDecimal.ROUND_HALF_UP); BigDecimal gainloss = BigDecimal.ZERO; if (!currentInst.equals(targetCurrInst)) { gainloss = newAmount.subtract(oldAmount); } else { gainloss = newAmount; } if (map.containsKey(accountInst.getOid())) { final AccountInfo tarAcc = map.get(accountInst.getOid()); tarAcc.addAmount(gainloss); } else { final AccountInfo tarAcc = new AccountInfo(accountInst, gainloss); tarAcc.setAmountRate(gainloss); tarAcc.setCurrInstance(currentInst); map.put(accountInst.getOid(), tarAcc); } } } if (!map.isEmpty()) { Insert insert = null; CurrencyInst curr = null; BigDecimal gainlossSum = BigDecimal.ZERO; for (final Entry<String, AccountInfo> entry : map.entrySet()) { final AccountInfo tarAcc = entry.getValue(); final Instance instAcc = Instance.get(entry.getKey()); final BigDecimal gainloss = tarAcc.getAmount(); gainlossSum = gainlossSum.add(gainloss); final Instance currInstance = tarAcc.getCurrInstance(); curr = new CurrencyInst(currInstance); final Map<String, String[]> mapVal = validateInfo(_parameter, gainloss); final String[] accs = mapVal.get("accs"); final String[] check = mapVal.get("check"); if (checkAccounts(accs, 0, check).length() > 0) { if (gainloss.compareTo(BigDecimal.ZERO) != 0) { final String[] accOids = mapVal.get("accountOids"); if (insert == null) { final DateTimeFormatter formater = DateTimeFormat.mediumDate(); final String dateStr = dateTo .withChronology(Context.getThreadContext().getChronology()) .toString(formater.withLocale(Context.getThreadContext().getLocale())); final StringBuilder description = new StringBuilder(); description .append(DBProperties .getProperty("Accounting_DocumentAccountForm.TxnRecalculate.Label")) .append(" ").append(dateStr); insert = new Insert(CIAccounting.Transaction); insert.add(CIAccounting.Transaction.Description, description.toString()); insert.add(CIAccounting.Transaction.Date, dateTo); insert.add(CIAccounting.Transaction.PeriodLink, _parameter.getInstance().getId()); insert.add(CIAccounting.Transaction.Status, Status.find(CIAccounting.TransactionStatus.uuid, "Open").getId()); insert.execute(); } Insert insertPos = new Insert(CIAccounting.TransactionPositionCredit); insertPos.add(CIAccounting.TransactionPositionCredit.TransactionLink, insert.getId()); if (gainloss.signum() < 0) { insertPos.add(CIAccounting.TransactionPositionCredit.AccountLink, instAcc.getId()); } else { insertPos.add(CIAccounting.TransactionPositionCredit.AccountLink, Instance.get(accOids[0]).getId()); } insertPos.add(CIAccounting.TransactionPositionCredit.Amount, gainloss.abs()); insertPos.add(CIAccounting.TransactionPositionCredit.RateAmount, gainloss.abs()); insertPos.add(CIAccounting.TransactionPositionCredit.CurrencyLink, currInstance.getId()); insertPos.add(CIAccounting.TransactionPositionCredit.RateCurrencyLink, currInstance.getId()); insertPos.add(CIAccounting.TransactionPositionCredit.Rate, new Object[] { BigDecimal.ONE, BigDecimal.ONE }); insertPos.execute(); insertPos = new Insert(CIAccounting.TransactionPositionDebit); insertPos.add(CIAccounting.TransactionPositionDebit.TransactionLink, insert.getId()); if (gainloss.signum() < 0) { insertPos.add(CIAccounting.TransactionPositionDebit.AccountLink, Instance.get(accOids[0]).getId()); } else { insertPos.add(CIAccounting.TransactionPositionDebit.AccountLink, instAcc.getId()); } insertPos.add(CIAccounting.TransactionPositionDebit.Amount, gainloss.abs().negate()); insertPos.add(CIAccounting.TransactionPositionDebit.RateAmount, gainloss.abs().negate()); insertPos.add(CIAccounting.TransactionPositionDebit.CurrencyLink, currInstance.getId()); insertPos.add(CIAccounting.TransactionPositionDebit.RateCurrencyLink, currInstance.getId()); insertPos.add(CIAccounting.TransactionPositionDebit.Rate, new Object[] { BigDecimal.ONE, BigDecimal.ONE }); insertPos.execute(); } } } if (insert != null) { final Instance instance = insert.getInstance(); // create classifications final Classification classification1 = (Classification) CIAccounting.TransactionClass.getType(); final Insert relInsert1 = new Insert(classification1.getClassifyRelationType()); relInsert1.add(classification1.getRelLinkAttributeName(), instance.getId()); relInsert1.add(classification1.getRelTypeAttributeName(), classification1.getId()); relInsert1.execute(); final Insert classInsert1 = new Insert(classification1); classInsert1.add(classification1.getLinkAttributeName(), instance.getId()); classInsert1.execute(); final Classification classification = (Classification) CIAccounting.TransactionClassGainLoss .getType(); final Insert relInsert = new Insert(classification.getClassifyRelationType()); relInsert.add(classification.getRelLinkAttributeName(), instance.getId()); relInsert.add(classification.getRelTypeAttributeName(), classification.getId()); relInsert.execute(); final Insert classInsert = new Insert(classification); classInsert.add(classification.getLinkAttributeName(), instance.getId()); classInsert.add(CIAccounting.TransactionClassGainLoss.Amount, gainlossSum); classInsert.add(CIAccounting.TransactionClassGainLoss.RateAmount, gainlossSum); classInsert.add(CIAccounting.TransactionClassGainLoss.CurrencyLink, curr.getInstance().getId()); classInsert.add(CIAccounting.TransactionClassGainLoss.RateCurrencyLink, curr.getInstance().getId()); classInsert.add(CIAccounting.TransactionClassGainLoss.Rate, new Object[] { BigDecimal.ONE, BigDecimal.ONE }); classInsert.execute(); new Create().connectDocs2Transaction(_parameter, instance, instDoc); } } } return new Return(); }
From source file:org.emonocot.harvest.media.ImageMetadataExtractorImpl.java
License:Open Source License
public ImageMetadataExtractorImpl() { dateTimeFormatters.add(ISODateTimeFormat.dateTimeParser()); dateTimeFormatters.add(DateTimeFormat.fullDate()); dateTimeFormatters.add(DateTimeFormat.fullDateTime()); dateTimeFormatters.add(DateTimeFormat.shortDate()); dateTimeFormatters.add(DateTimeFormat.shortDateTime()); dateTimeFormatters.add(DateTimeFormat.mediumDate()); dateTimeFormatters.add(DateTimeFormat.mediumDateTime()); }
From source file:org.killbill.billing.invoice.template.formatters.DefaultInvoiceFormatter.java
License:Apache License
public DefaultInvoiceFormatter(final TranslatorConfig config, final Invoice invoice, final Locale locale, final CurrencyConversionApi currencyConversionApi, final ResourceBundleFactory bundleFactory, final InternalTenantContext context) { this.config = config; this.invoice = invoice; this.dateFormatter = DateTimeFormat.mediumDate().withLocale(locale); this.locale = locale; this.currencyConversionApi = currencyConversionApi; this.bundleFactory = bundleFactory; this.context = context; }
From source file:org.killbill.billing.plugin.notification.generator.formatters.DefaultInvoiceFormatter.java
License:Apache License
public DefaultInvoiceFormatter(final Map<String, String> translator, final Invoice invoice, final Locale locale) { this.translator = translator; this.invoice = invoice; this.dateFormatter = DateTimeFormat.mediumDate().withLocale(locale); this.locale = locale; }
From source file:org.killbill.billing.plugin.notification.generator.formatters.PaymentFormatter.java
License:Apache License
public PaymentFormatter(final PaymentTransaction paymentTransaction, final Locale locale) { this.paymentTransaction = paymentTransaction; this.dateFormatter = DateTimeFormat.mediumDate().withLocale(locale); this.locale = locale; }
From source file:org.openhat.androPDI.ports.editors.DialPortDateTimeEditor.java
License:Open Source License
protected void setEventTime(int selectedPosition) { LocalDateTime dateTime = null; switch (selectedPosition) { /*/*from ww w .j a v a 2s .c o m*/ <item>Select…</item> <item>In 30 seconds</item> <item>In one minute</item> <item>In five minutes</item> <item>In 15 minutes</item> <item>In one hour</item> <item>In two hours</item> <item>In six hours</item> <item>In one day</item> */ case 1: // 30 seconds dateTime = new LocalDateTime().plusSeconds(30); break; case 2: // one minute dateTime = new LocalDateTime().plusMinutes(1); break; case 3: // five minutes dateTime = new LocalDateTime().plusMinutes(5); break; case 4: // 15 minutes dateTime = new LocalDateTime().plusMinutes(15); break; case 5: // 30 minutes dateTime = new LocalDateTime().plusMinutes(30); break; case 6: // one hour dateTime = new LocalDateTime().plusHours(1); break; case 7: // two hours dateTime = new LocalDateTime().plusHours(2); break; case 8: // six hours dateTime = new LocalDateTime().plusHours(6); break; case 9: // one day dateTime = new LocalDateTime().plusDays(1); break; default: return; } tvDate.setText(DateTimeFormat.mediumDate().print(dateTime)); tvTime.setText(DateTimeFormat.mediumTime().print(dateTime)); currentDate = dateTime; }
From source file:org.openhat.androPDI.ports.editors.DialPortDateTimeEditor.java
License:Open Source License
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.date_time_editor, container); tvDate = (TextView) view.findViewById(R.id.date_time_editor_date); tvDate.setText(DateTimeFormat.mediumDate().print(currentDate)); tvTime = (TextView) view.findViewById(R.id.date_time_editor_time); tvTime.setText(DateTimeFormat.mediumTime().print(currentDate)); btnDate = (Button) view.findViewById(R.id.date_time_editor_select_date_button); btnTime = (Button) view.findViewById(R.id.date_time_editor_select_time_button); spSelect = (Spinner) view.findViewById(R.id.date_time_editor_spinner); btnOk = (Button) view.findViewById(R.id.date_time_editor_ok_button); btnCancel = (Button) view.findViewById(R.id.date_time_editor_cancel_button); getDialog().setTitle("Select date and time"); btnTime.setOnClickListener(new View.OnClickListener() { @Override/* w w w . j a va 2s .c o m*/ public void onClick(View v) { timePicker = new TimePickerDialogFragment(currentDate, tvTime); timePicker.show(getFragmentManager(), "timePicker"); } }); btnDate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { datePicker = new DatePickerDialogFragment(currentDate, tvDate); datePicker.show(getFragmentManager(), "datePicker"); } }); spSelect.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { setEventTime(position); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); btnOk.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // parse date LocalDate date = null; LocalTime time = null; date = DateTimeFormat.mediumDate().parseLocalDate(tvDate.getText().toString()); String t = tvTime.getText().toString(); /* // add seconds to time if they're missing if (t.split(":").length <= 2) t += ":00"; */ time = DateTimeFormat.mediumTime().parseLocalTime(t); LocalDateTime result = date.toLocalDateTime(time); dismiss(); dismissedListener.dismissed(result); } }); btnCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dismiss(); } }); return view; }
From source file:ro.activemall.photoxserver.utils.thymeleafJoda.JodaTimeDialect.java
License:Open Source License
@Override public Set<IProcessor> getProcessors() { Set<IProcessor> processors = new HashSet<IProcessor>(); processors.add(new JodaTimeFormatProcessor("fullDate", DateTimeFormat.fullDate())); processors.add(new JodaTimeFormatProcessor("fullDateTime", DateTimeFormat.fullDateTime())); processors.add(new JodaTimeFormatProcessor("fullTime", DateTimeFormat.fullTime())); processors.add(new JodaTimeFormatProcessor("longDate", DateTimeFormat.longDate())); processors.add(new JodaTimeFormatProcessor("longDateTime", DateTimeFormat.longDateTime())); processors.add(new JodaTimeFormatProcessor("longTime", DateTimeFormat.longTime())); processors.add(new JodaTimeFormatProcessor("mediumDate", DateTimeFormat.mediumDate())); processors.add(new JodaTimeFormatProcessor("mediumDateTime", DateTimeFormat.mediumDateTime())); processors.add(new JodaTimeFormatProcessor("mediumTime", DateTimeFormat.mediumTime())); processors.add(new JodaTimeFormatProcessor("shortDate", DateTimeFormat.shortDate())); processors.add(new JodaTimeFormatProcessor("shortDateTime", DateTimeFormat.shortDateTime())); processors.add(new JodaTimeFormatProcessor("shortTime", DateTimeFormat.shortTime())); processors.add(new JodaTimeFormatProcessor("isoDateTime", ISODateTimeFormat.dateTime())); return processors; }