diff --git a/src/api/ADempiere/form/VAllocation.js b/src/api/ADempiere/form/VAllocation.js index 7dc456b9f9e..d17db1d5833 100644 --- a/src/api/ADempiere/form/VAllocation.js +++ b/src/api/ADempiere/form/VAllocation.js @@ -80,13 +80,12 @@ export function requestListCurrencies({ }) } -export function listPayments({ +export function requestListPayments({ // DSL Query searchValue, businessPartnerId, date, organizationId, - organizationUuid, currencyId, isMultiCurrency, transactionType, @@ -116,7 +115,7 @@ export function listPayments({ }) } -export function listInvoices({ +export function requestListInvoices({ // DSL Query searchValue, businessPartnerId, @@ -187,7 +186,7 @@ export function requestListTransactionOrganizations({ } // process -export function process({ +export function requestProcess({ date, chargeId, currencyId, @@ -199,7 +198,7 @@ export function process({ transactionOrganizationId }) { return request({ - url: '/payment-allocation/process-receipt', + url: '/payment-allocation/process', method: 'post', data: { // DSL Query diff --git a/src/components/ADempiere/FormDefinition/VAllocation/components/InvoceTable.vue b/src/components/ADempiere/FormDefinition/VAllocation/components/InvoceTable.vue index 7bc0163580a..79c967af52c 100644 --- a/src/components/ADempiere/FormDefinition/VAllocation/components/InvoceTable.vue +++ b/src/components/ADempiere/FormDefinition/VAllocation/components/InvoceTable.vue @@ -54,7 +54,13 @@

+ {{ scope.row[header.columnName].value }} +

+

{{ scope.row[header.columnName] }} @@ -94,7 +100,7 @@ import store from '@/store' import headersInvoice from './headersInvoice.js' // Utils and Helper Methods -import { isEmptyValue } from '@/utils/ADempiere/valueUtils' +import { isEmptyValue, getTypeOfValue } from '@/utils/ADempiere/valueUtils' export default defineComponent({ name: 'InvocesTable', @@ -103,7 +109,9 @@ export default defineComponent({ const diference = ref(0) const sumApplied = computed(() => { const sumInvoce = selectListAll.value.map(list => { - if (list.type === 'isInvoce') return list.amountApplied + if (list.type === 'isInvoce') { + return list.amountApplied + } return list.applied }) const initialValue = 0 @@ -118,10 +126,10 @@ export default defineComponent({ */ const listInvocesTable = ref(null) const panelInvoce = ref(300) + /** * computed */ - const selectListAll = computed(() => { return store.getters.getListSelectInvoceandPayment }) @@ -133,7 +141,6 @@ export default defineComponent({ /** * Methods */ - function isCellInput(cell) { const { columnName } = cell let isInput = false @@ -186,17 +193,17 @@ export default defineComponent({ function appliedPay(currentInvoce) { const { open_amount, discount_amount } = currentInvoce if (selectListAll.value.length < 1) { - return open_amount - discount_amount + return open_amount.value - discount_amount.value } - if (num(sumApplied.value) <= num(open_amount - discount_amount) && Math.sign(sumApplied.value) < 0) { + if (num(sumApplied.value) <= num(open_amount.value - discount_amount.value) && Math.sign(sumApplied.value) < 0) { if (num(sumApplied.value) === 0) { if (Math.sign(sumApplied.value) < 0) { - return open_amount - discount_amount + return open_amount.value - discount_amount.value } } return sumApplied.value } - return open_amount - discount_amount + return open_amount.value - discount_amount.value } function setToggleSelection() { @@ -232,8 +239,13 @@ export default defineComponent({ } function num(amount) { + if (getTypeOfValue(amount) === 'OBJECT') { + amount = Number(amount.value) + } const math = Math.sign(amount) - if (math >= 0) return amount + if (math >= 0) { + return amount + } return -(amount) } diff --git a/src/components/ADempiere/FormDefinition/VAllocation/components/Payments.vue b/src/components/ADempiere/FormDefinition/VAllocation/components/Payments.vue index e0c0465990f..324c7c0b8f5 100644 --- a/src/components/ADempiere/FormDefinition/VAllocation/components/Payments.vue +++ b/src/components/ADempiere/FormDefinition/VAllocation/components/Payments.vue @@ -442,9 +442,13 @@ export default defineComponent({ }) const maximumDefiniteDate = computed(() => { - if (isEmptyValue(selectListAll.value)) return new Date() + if (isEmptyValue(selectListAll.value)) { + return new Date() + } const date = selectListAll.value.map(date => { - if (date.type === 'isPayment') return date.transaction_date + if (date.type === 'isPayment') { + return date.transaction_date + } return date.date_invoiced }) return date.sort((a, b) => { @@ -457,7 +461,9 @@ export default defineComponent({ }) const sumApplied = computed(() => { - const sumInvoce = selectListAll.value.filter(list => list.type === 'isInvoce').map(list => { + const sumInvoce = selectListAll.value.filter(list => { + return list.type === 'isInvoce' + }).map(list => { const { transaction_type } = list if (list.type === 'isInvoce') { if (transaction_type.value === 'R') { @@ -467,7 +473,11 @@ export default defineComponent({ } return list.applied }) - const sumPayment = selectListAll.value.filter(list => list.type !== 'isInvoce').map(list => list.applied) + const sumPayment = selectListAll.value.filter(list => { + return list.type !== 'isInvoce' + }).map(list => { + return list.applied + }) const initialValue = 0 const initialValuePayment = 0 const initialValueAll = 0 diff --git a/src/components/ADempiere/FormDefinition/VAllocation/components/PaymentsTable.vue b/src/components/ADempiere/FormDefinition/VAllocation/components/PaymentsTable.vue index 2806f3900e7..524336e15f2 100644 --- a/src/components/ADempiere/FormDefinition/VAllocation/components/PaymentsTable.vue +++ b/src/components/ADempiere/FormDefinition/VAllocation/components/PaymentsTable.vue @@ -94,7 +94,7 @@ import store from '@/store' import headersPayments from './headersPayments.js' // Utils and Helper Methods -import { isEmptyValue } from '@/utils/ADempiere/valueUtils' +import { isEmptyValue, getTypeOfValue } from '@/utils/ADempiere/valueUtils' export default defineComponent({ name: 'PaymentsTable', @@ -110,15 +110,16 @@ export default defineComponent({ const { isLoadingPayments } = store.getters.getisLoadTables return isLoadingPayments }) + /** * Refs */ const listPaymentsTable = ref(null) const panelInvoce = ref(100) + /** * computed */ - const listPayments = computed(() => { return store.getters.getListVAllocation.payments }) @@ -128,7 +129,9 @@ export default defineComponent({ }) const sumAppliedInvoce = computed(() => { - const sumInvoce = selectListAll.value.filter(list => list.type === 'isInvoce').map(list => { + const sumInvoce = selectListAll.value.filter(list => { + return list.type === 'isInvoce' + }).map(list => { const { transaction_type } = list if (list.type === 'isInvoce') { if (transaction_type.value === 'R') { @@ -138,7 +141,9 @@ export default defineComponent({ } return list.applied }) - const sumPayment = selectListAll.value.filter(list => list.type !== 'isInvoce').map(list => list.applied) + const sumPayment = selectListAll.value.filter(list => { + return list.type !== 'isInvoce' + }).map(list => list.applied) const initialValue = 0 const initialValuePayment = 0 const initialValueAll = 0 @@ -235,24 +240,32 @@ export default defineComponent({ } function applied(row) { - if (isEmptyValue(selectListAll.value)) return row.open_amount + if (isEmptyValue(selectListAll.value)) { + return row.open_amount.value + } if (num(sumAppliedInvoce.value) > 0) { - if (num(sumAppliedInvoce.value) > num(row.open_amount)) { - return row.open_amount + if (num(sumAppliedInvoce.value) > num(row.open_amount.value)) { + return row.open_amount.value } - if (Math.sign(sumAppliedInvoce.value) === Math.sign(row.open_amount)) { - return row.open_amount + if (Math.sign(sumAppliedInvoce.value) === Math.sign(row.open_amount.value)) { + return row.open_amount.value + } + if (row.transaction_type.value === 'P') { + return -(sumAppliedInvoce.value) } - if (row.transaction_type.value === 'P') return -(sumAppliedInvoce.value) return sumAppliedInvoce.value - } else { - return row.open_amount } + return row.open_amount.value } function num(amount) { + if (getTypeOfValue(amount) === 'OBJECT') { + amount = Number(amount.value) + } const math = Math.sign(amount) - if (math > 0) return amount + if (math > 0) { + return amount + } return -(amount) } diff --git a/src/components/ADempiere/FormDefinition/VAllocation/index.vue b/src/components/ADempiere/FormDefinition/VAllocation/index.vue index fdbf1e391f1..fdfdcc41f1a 100644 --- a/src/components/ADempiere/FormDefinition/VAllocation/index.vue +++ b/src/components/ADempiere/FormDefinition/VAllocation/index.vue @@ -137,10 +137,15 @@ export default defineComponent({ }) function nextStep(step) { - if (currentSetp.value === 0) store.commit('setListSelectInvoceandPayment', []) - if (currentSetp.value === 1) store.dispatch('processSend') - if (currentSetp.value >= 1) return - + if (currentSetp.value === 0) { + store.commit('setListSelectInvoceandPayment', []) + } + if (currentSetp.value === 1) { + store.dispatch('processSend') + } + if (currentSetp.value >= 1) { + return + } currentSetp.value++ if (currentSetp.value === 1) { store.dispatch('findListPayment') diff --git a/src/store/modules/ADempiere/form/VAllocation.js b/src/store/modules/ADempiere/form/VAllocation.js index 9073f3ce791..05a0094c143 100644 --- a/src/store/modules/ADempiere/form/VAllocation.js +++ b/src/store/modules/ADempiere/form/VAllocation.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): Elsio Sanchez elsiosanchez15@outlook.com https://github.com/elsiosanchez * 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,9 +18,9 @@ // API Request Methods import { - process, - listPayments, - listInvoices + requestProcess, + requestListPayments, + requestListInvoices } from '@/api/ADempiere/form/VAllocation.js' // Utils and Helper Methods @@ -81,6 +81,7 @@ const VAllocation = { export default { state: VAllocation, + mutations: { setSearchCriteria(state, structure) { state.searchCriteria = structure @@ -173,6 +174,7 @@ export default { state.listSelectAll = list } }, + actions: { findListPayment({ commit, state }) { return new Promise(resolve => { @@ -193,7 +195,7 @@ export default { criteria: 'isLoadTables', value: true }) - listPayments({ + requestListPayments({ businessPartnerId, businessPartnerUuid, date, @@ -259,7 +261,7 @@ export default { criteria: 'isLoadTables', value: true }) - listInvoices({ + requestListInvoices({ businessPartnerId, businessPartnerUuid, date, @@ -326,7 +328,7 @@ export default { listInvoce = state.listSelectAll.filter(list => list.type === 'isInvoce') listPayments = state.listSelectAll.filter(list => list.type === 'isPayment') } - process({ + requestProcess({ date, chargeId, currencyId, @@ -367,6 +369,7 @@ export default { return } }, + getters: { getSearchFilter(state) { return state.searchCriteria diff --git a/src/utils/ADempiere/formatValue/numberFormat.js b/src/utils/ADempiere/formatValue/numberFormat.js index f4d0409dcb1..dbbdcb36ad2 100644 --- a/src/utils/ADempiere/formatValue/numberFormat.js +++ b/src/utils/ADempiere/formatValue/numberFormat.js @@ -27,7 +27,7 @@ import { import { isCurrencyField, isIntegerField } from '@/utils/ADempiere/references.js' -import { charInText, isEmptyValue } from '@/utils/ADempiere/valueUtils.js' +import { charInText, getTypeOfValue, isEmptyValue } from '@/utils/ADempiere/valueUtils.js' /** * Is Number Value @@ -109,15 +109,22 @@ export function formatNumber({ /** * Format Quantity - * @param {number} value - * @param {boolean} isInteger + * @param {Number} value + * @param {Boolean} isInteger */ export function formatQuantity({ value, isInteger = false, precision }) { + const { + value: currentValue, precision: currentPrecision + } = getNumberFromGRPC({ + value + }) + value = currentValue + precision = currentPrecision if (isEmptyValue(value)) { value = 0 } - if (isEmptyValue(precision)) { + if (isEmptyValue(precision) || precision === 0) { precision = getStandardPrecision() } // without decimals @@ -197,6 +204,35 @@ export function formatPercent(value) { }).format(value) } +/** + * Return number value and precision + * @param {Object} value { value, type } + * @returns {Object} { value, precision } + */ +export function getNumberFromGRPC({ value }) { + let numberValue = value + let scale = 0 + + if (getTypeOfValue(value) === 'OBJECT') { + numberValue = value.value + if (getTypeOfValue(numberValue) === 'STRING') { + const index = numberValue + .toString() + .indexOf('.') + if (index !== -1) { + scale = numberValue.toString().length - index - 1 + } + + numberValue = Number(numberValue) + } + } + + return { + value: numberValue, + precision: scale + } +} + /** * zero pad * @author EdwinBetanc0urt