diff --git a/src/components/ADempiere/FieldDefinition/FieldDate.vue b/src/components/ADempiere/FieldDefinition/FieldDate.vue index 465c90e5837..a7aeeca4f56 100644 --- a/src/components/ADempiere/FieldDefinition/FieldDate.vue +++ b/src/components/ADempiere/FieldDefinition/FieldDate.vue @@ -45,9 +45,12 @@ import { DATE_PLUS_TIME } from '@/utils/ADempiere/references' import { MULTIPLE_VALUES_OPERATORS_LIST, RANGE_VALUE_OPERATORS_LIST } from '@/utils/ADempiere/dataUtils' +import { + SHORCUTS_DATE, SHORCUTS_DATE_RANGE +} from '@/utils/ADempiere/componentUtils' // Utils and Helper Methods -import { isEmptyValue } from '@/utils/ADempiere/valueUtils.js' +import { getTypeOfValue, isEmptyValue } from '@/utils/ADempiere/valueUtils.js' import { changeTimeZone } from '@/utils/ADempiere/formatValue/dateFormat' /** @@ -63,86 +66,10 @@ export default { data() { return { pickerOptionsDate: { - shortcuts: [{ - text: this.$t('component.date.today'), - onClick(picker) { - picker.$emit('pick', new Date()) - } - }, { - text: this.$t('component.date.yesterday'), - onClick(picker) { - const date = new Date() - date.setTime(date.getTime() - 3600 * 1000 * 24) - picker.$emit('pick', date) - } - }, { - text: this.$t('component.date.week'), - onClick(picker) { - const date = new Date() - const monthEndDay = new Date(date.getFullYear(), date.getMonth() + 1, 0) - picker.$emit('pick', monthEndDay) - } - }] + shortcuts: SHORCUTS_DATE }, pickerOptionsDateRange: { - shortcuts: [{ - text: this.$t('component.date.today'), - onClick(picker) { - const currentDay = new Date() - picker.$emit('pick', [currentDay, currentDay]) - } - }, { - text: this.$t('component.date.yesterday'), - onClick(picker) { - const start = new Date() - start.setTime(start.getTime() - 3600 * 1000 * 24) - picker.$emit('pick', [start, start]) - } - }, { - text: this.$t('component.date.week'), - onClick(picker) { - const start_date = new Date() - start_date.setHours(0, 0, 0, 0) - const end_date = new Date() - const date = null - const currenDate = date ? new Date(date) : new Date() - const first = currenDate.getDate() - currenDate.getDay('monday') - const last = first - 7 - start_date.setDate(last) - end_date.setDate(first - 1) - picker.$emit('pick', [start_date, end_date]) - } - }, { - text: this.$t('component.date.currentWeek'), - onClick(picker) { - const start_date = new Date() - start_date.setHours(0, 0, 0, 0) - const end_date = new Date() - const date = null - const currenDate = date ? new Date(date) : new Date() - const first = currenDate.getDate() - currenDate.getDay('monday') - const last = first - start_date.setDate(last) - end_date.setDate(first + 6) - picker.$emit('pick', [start_date, end_date]) - } - }, { - text: this.$t('component.date.lastMonth'), - onClick(picker) { - const date = new Date() - const monthEndDay = new Date(date.getFullYear(), date.getMonth(), 0) - const monthStartDay = new Date(date.getFullYear(), date.getMonth() - 1, 1) - picker.$emit('pick', [monthStartDay, monthEndDay]) - } - }, { - text: this.$t('component.date.currentMonth'), - onClick(picker) { - const date = new Date() - const monthEndDay = new Date(date.getFullYear(), date.getMonth() + 1, 0) - const monthStartDay = new Date(date.getFullYear(), date.getMonth(), 1) - picker.$emit('pick', [monthStartDay, monthEndDay]) - } - }] + shortcuts: SHORCUTS_DATE_RANGE } } }, @@ -313,9 +240,15 @@ export default { }, methods: { - parseValue(value) { + parseValue(valueToParse) { + let currentValue = valueToParse + // types `decimal` and `date` is a object struct + if ((getTypeOfValue(valueToParse) === 'OBJECT') && !isEmptyValue(valueToParse.type)) { + currentValue = valueToParse.value + } + // not return undefined to v-model - if (isEmptyValue(value)) { + if (isEmptyValue(currentValue)) { if (this.isMultipleValues) { return [] } @@ -323,8 +256,8 @@ export default { } if (this.isMultipleValues) { - if (Array.isArray(value)) { - value = value.map(itemValue => { + if (Array.isArray(currentValue)) { + currentValue = currentValue.map(itemValue => { if (typeof itemValue === 'object') { return itemValue.toUTCString() } @@ -332,22 +265,23 @@ export default { }) } else { const tempValue = [] - if (!isEmptyValue(value)) { - tempValue.push(value) + if (!isEmptyValue(currentValue)) { + tempValue.push(currentValue) } - value = tempValue + currentValue = tempValue } - return value + return currentValue } // instance date from long value - if (typeof value === 'number') { - value = new Date(value).toUTCString() + if (typeof currentValue === 'number') { + currentValue = new Date(currentValue).toUTCString() } // generate range value if (this.isRenderRange && !this.metadata.inTable) { let valueTo + let value = currentValue if (Array.isArray(value)) { valueTo = value.at(1) value = value.at(0) @@ -358,13 +292,13 @@ export default { if (isEmptyValue(valueTo)) { valueTo = undefined } - value = [value, valueTo] - if (isEmptyValue(value.at(0)) || isEmptyValue(value.at(1))) { - value = [] + currentValue = [value, valueTo] + if (isEmptyValue(currentValue.at(0)) || isEmptyValue(currentValue.at(1))) { + currentValue = [] } } - return value + return currentValue }, // validate values before send values to store or server preHandleChange(value) { diff --git a/src/store/modules/ADempiere/sessionContext.js b/src/store/modules/ADempiere/sessionContext.js index 651b36a6667..92a6066b54a 100644 --- a/src/store/modules/ADempiere/sessionContext.js +++ b/src/store/modules/ADempiere/sessionContext.js @@ -1,18 +1,20 @@ -// ADempiere-Vue (Frontend) for ADempiere ERP & CRM Smart Business Solution -// Copyright (C) 2017-Present E.R.P. Consultores y Asociados, C.A. -// Contributor(s): Edwin Betancourt EdwinBetanc0urt@outlook.com www.erpya.com -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . +/** + * ADempiere-Vue (Frontend) for ADempiere ERP & CRM Smart Business Solution + * Copyright (C) 2018-Present E.R.P. Consultores y Asociados, C.A. www.erpya.com + * Contributor(s): Edwin Betancourt EdwinBetanc0urt@outlook.com https://github.com/EdwinBetanc0urt + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ import Vue from 'vue' @@ -21,7 +23,7 @@ import { CLIENT, COUNTRY, ORGANIZATION } from '@/utils/ADempiere/constants/syste import { ACCOUNTING_CONTEXT_PREFIX, GLOBAL_CONTEXT_PREFIX } from '@/utils/ADempiere/contextUtils' // utils and helper methods -import { isEmptyValue, typeValue } from '@/utils/ADempiere/valueUtils.js' +import { isEmptyValue, getTypeOfValue } from '@/utils/ADempiere/valueUtils.js' const sessionContext = { state: { @@ -80,7 +82,7 @@ const sessionContext = { containerUuid, values }) { - const typeOfValue = typeValue(values) + const typeOfValue = getTypeOfValue(values) let actionToDispatch = 'setMultiplePreferenceObject' if (typeOfValue === 'MAP') { diff --git a/src/utils/ADempiere/componentUtils.js b/src/utils/ADempiere/componentUtils.js index 97a64b5aa34..eb05681fd5f 100644 --- a/src/utils/ADempiere/componentUtils.js +++ b/src/utils/ADempiere/componentUtils.js @@ -16,6 +16,7 @@ * along with this program. If not, see . */ +import lang from '@/lang' import router from '@/router' import store from '@/store' @@ -67,3 +68,93 @@ export const closeTagView = function(currentRoute) { }, () => {}) } } + +export const SHORCUTS_DATE = [ + { + text: lang.t('component.date.today'), + onClick(picker) { + picker.$emit('pick', new Date()) + } + }, + { + text: lang.t('component.date.yesterday'), + onClick(picker) { + const date = new Date() + date.setTime(date.getTime() - 3600 * 1000 * 24) + picker.$emit('pick', date) + } + }, + { + text: lang.t('component.date.week'), + onClick(picker) { + const date = new Date() + const monthEndDay = new Date(date.getFullYear(), date.getMonth() + 1, 0) + picker.$emit('pick', monthEndDay) + } + } +] + +export const SHORCUTS_DATE_RANGE = [ + { + text: lang.t('component.date.today'), + onClick(picker) { + const currentDay = new Date() + picker.$emit('pick', [currentDay, currentDay]) + } + }, + { + text: lang.t('component.date.yesterday'), + onClick(picker) { + const start = new Date() + start.setTime(start.getTime() - 3600 * 1000 * 24) + picker.$emit('pick', [start, start]) + } + }, + { + text: lang.t('component.date.week'), + onClick(picker) { + const start_date = new Date() + start_date.setHours(0, 0, 0, 0) + const end_date = new Date() + const date = null + const currenDate = date ? new Date(date) : new Date() + const first = currenDate.getDate() - currenDate.getDay('monday') + const last = first - 7 + start_date.setDate(last) + end_date.setDate(first - 1) + picker.$emit('pick', [start_date, end_date]) + } + }, { + text: lang.t('component.date.currentWeek'), + onClick(picker) { + const start_date = new Date() + start_date.setHours(0, 0, 0, 0) + const end_date = new Date() + const date = null + const currenDate = date ? new Date(date) : new Date() + const first = currenDate.getDate() - currenDate.getDay('monday') + const last = first + start_date.setDate(last) + end_date.setDate(first + 6) + picker.$emit('pick', [start_date, end_date]) + } + }, + { + text: lang.t('component.date.lastMonth'), + onClick(picker) { + const date = new Date() + const monthEndDay = new Date(date.getFullYear(), date.getMonth(), 0) + const monthStartDay = new Date(date.getFullYear(), date.getMonth() - 1, 1) + picker.$emit('pick', [monthStartDay, monthEndDay]) + } + }, + { + text: lang.t('component.date.currentMonth'), + onClick(picker) { + const date = new Date() + const monthEndDay = new Date(date.getFullYear(), date.getMonth() + 1, 0) + const monthStartDay = new Date(date.getFullYear(), date.getMonth(), 1) + picker.$emit('pick', [monthStartDay, monthEndDay]) + } + } +] diff --git a/src/utils/ADempiere/formatValue/dateFormat.js b/src/utils/ADempiere/formatValue/dateFormat.js index 4d77b5e4628..c23b9badf79 100644 --- a/src/utils/ADempiere/formatValue/dateFormat.js +++ b/src/utils/ADempiere/formatValue/dateFormat.js @@ -21,7 +21,7 @@ import store from '@/store' import moment from 'moment' // utils and helper methods -import { isEmptyValue, typeValue } from '@/utils/ADempiere/valueUtils.js' +import { isEmptyValue, getTypeOfValue } from '@/utils/ADempiere/valueUtils.js' import { zeroPad } from '@/utils/ADempiere/formatValue/numberFormat.js' /** @@ -100,7 +100,7 @@ export function formatDate({ value, isTime = false, isDate = false, format }) { if (isEmptyValue(value)) { return undefined } - if (typeValue(value) === 'DATE') { + if (getTypeOfValue(value) === 'DATE') { value = value.getTime() } diff --git a/src/utils/ADempiere/formatValue/stringFormat.js b/src/utils/ADempiere/formatValue/stringFormat.js index 43d37899395..77f36cd3337 100644 --- a/src/utils/ADempiere/formatValue/stringFormat.js +++ b/src/utils/ADempiere/formatValue/stringFormat.js @@ -1,6 +1,6 @@ /** * ADempiere-Vue (Frontend) for ADempiere ERP & CRM Smart Business Solution - * Copyright (C) 2017-Present E.R.P. Consultores y Asociados, C.A. www.erpya.com + * Copyright (C) 2018-Present E.R.P. Consultores y Asociados, C.A. www.erpya.com * Contributor(s): Edwin Betancourt EdwinBetanc0urt@outlook.com https://github.com/EdwinBetanc0urt * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,7 +17,7 @@ */ // Utils and Helper Methods -import { isEmptyValue, typeValue } from '@/utils/ADempiere/valueUtils' +import { isEmptyValue, getTypeOfValue } from '@/utils/ADempiere/valueUtils' /** * Capitalize value @@ -55,7 +55,7 @@ export function removeQuotationMark(stringValue) { if (isEmptyValue(stringValue)) { return stringValue } - if (typeValue(stringValue) !== 'STRING') { + if (getTypeOfValue(stringValue) !== 'STRING') { return stringValue } diff --git a/src/utils/ADempiere/globalMethods.js b/src/utils/ADempiere/globalMethods.js index 26ff802f010..9aed194f7a1 100644 --- a/src/utils/ADempiere/globalMethods.js +++ b/src/utils/ADempiere/globalMethods.js @@ -1,6 +1,6 @@ /** * ADempiere-Vue (Frontend) for ADempiere ERP & CRM Smart Business Solution - * Copyright (C) 2017-Present E.R.P. Consultores y Asociados, C.A. www.erpya.com + * Copyright (C) 2018-Present E.R.P. Consultores y Asociados, C.A. www.erpya.com * Contributor(s): Edwin Betancourt EdwinBetanc0urt@outlook.com https://github.com/EdwinBetanc0urt * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,12 +18,12 @@ export { isEmptyValue, + getTypeOfValue, currencyFind, tenderTypeFind, formatConversionCurrenty, // round, convertValuesToSend, - typeValue, tableColumnDataType } from '@/utils/ADempiere/valueUtils.js' diff --git a/src/utils/ADempiere/valueUtils.js b/src/utils/ADempiere/valueUtils.js index 1f47877870f..2edc7bccf7a 100644 --- a/src/utils/ADempiere/valueUtils.js +++ b/src/utils/ADempiere/valueUtils.js @@ -138,18 +138,6 @@ export function isSameValues(valueA, valueB) { (isEmptyValue(valueA) && isEmptyValue(valueB)) } -/** - * Evaluates the type of data sent, useful with 'array' type data as the typeof - * function returns 'object' in this and other cases. - * @deprecated change by getTypeOfValue method - * @author EdwinBetanc0urt - * @link https://gist.github.com/EdwinBetanc0urt/3fc02172ada073ded4b52e46543553ce - * @param {boolean|array|object|number|string|date|map|set|function} value - * @returns {string} value type in capital letters (STRING, NUMBER, BOOLEAN, ...) - */ -export function typeValue(value) { - return getTypeOfValue(value) -} /** * Evaluates the type of data sent, useful with 'array' type data as the typeof * function returns 'object' in this and other cases. @@ -345,6 +333,11 @@ export function parsedValueComponent({ displayType, isMandatory = false }) { + // types `decimal` and `date` is a object struct + if ((getTypeOfValue(value) === 'OBJECT') && !isEmptyValue(value.type)) { + value = value.value + } + const isEmpty = isEmptyValue(value) if (isEmpty && !isMandatory) { if (componentPath === 'FieldYesNo') {