Merge branch 'beta' into taro/outstanding-balance
This commit is contained in:
commit
92ea2a58f7
|
@ -53,6 +53,12 @@ const search = async () => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (props.searchFn) {
|
||||||
|
const data = await props.searchFn(searchTerm.value);
|
||||||
|
emit('onSearch', data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (props.url) {
|
if (props.url) {
|
||||||
const params = {
|
const params = {
|
||||||
filter: props.filter,
|
filter: props.filter,
|
||||||
|
|
|
@ -45,6 +45,8 @@ async function fetch({
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
params.filter = params.filter || {};
|
||||||
|
|
||||||
if (params.filter?.where || exprFilter) {
|
if (params.filter?.where || exprFilter) {
|
||||||
params.filter.where = { ...params.filter.where, ...exprFilter };
|
params.filter.where = { ...params.filter.where, ...exprFilter };
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ import { storeToRefs } from 'pinia';
|
||||||
import { useUserStore } from 'stores/user';
|
import { useUserStore } from 'stores/user';
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const jApi = inject('jApi');
|
|
||||||
const api = inject('api');
|
const api = inject('api');
|
||||||
const { notify } = useNotify();
|
const { notify } = useNotify();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
@ -26,32 +25,30 @@ const fetchAddressesRef = ref(null);
|
||||||
|
|
||||||
const addresses = ref([]);
|
const addresses = ref([]);
|
||||||
const defaultAddress = ref(null);
|
const defaultAddress = ref(null);
|
||||||
const clientId = ref(null);
|
|
||||||
|
|
||||||
const goToAddressDetails = (id = 0) =>
|
const goToAddressDetails = (id = 0) =>
|
||||||
router.push({ name: 'addressDetails', params: { id } });
|
router.push({ name: 'addressDetails', params: { id } });
|
||||||
|
|
||||||
const getDefaultAddress = async () => {
|
const getDefaultAddress = async () => {
|
||||||
try {
|
try {
|
||||||
const [address] = await jApi.query(
|
const filter = { fields: ['defaultAddressFk'] };
|
||||||
'SELECT id, defaultAddressFk FROM myClient c'
|
const { data } = await api.get(`Clients/${userStore?.userId}`, {
|
||||||
);
|
params: { filter: JSON.stringify(filter) }
|
||||||
defaultAddress.value = address.defaultAddressFk;
|
});
|
||||||
clientId.value = address.id;
|
defaultAddress.value = data.defaultAddressFk;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error getting default address:', error);
|
console.error('Error getting default address:', error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const changeDefaultAddress = async () => {
|
const changeDefaultAddress = async address => {
|
||||||
if (!clientId.value) return;
|
if (!userStore?.userId) return;
|
||||||
await jApi.execQuery(
|
|
||||||
`UPDATE myClient
|
await api.patch(
|
||||||
SET defaultAddressFk = #defaultAddress
|
`/Clients/${userStore?.user?.id}/updateAddress/${address.id}`,
|
||||||
WHERE id = #id;`,
|
|
||||||
{
|
{
|
||||||
defaultAddress: defaultAddress.value,
|
...address,
|
||||||
id: clientId.value
|
defaultAddressFk: defaultAddress.value
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
notify(t('defaultAddressModified'), 'positive');
|
notify(t('defaultAddressModified'), 'positive');
|
||||||
|
@ -129,7 +126,7 @@ onMounted(async () => {
|
||||||
v-model="defaultAddress"
|
v-model="defaultAddress"
|
||||||
:val="address.id"
|
:val="address.id"
|
||||||
class="q-mr-sm"
|
class="q-mr-sm"
|
||||||
@update:model-value="changeDefaultAddress"
|
@update:model-value="changeDefaultAddress(address)"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<template #content>
|
<template #content>
|
||||||
|
|
|
@ -7,8 +7,7 @@ import VnList from 'src/components/ui/VnList.vue';
|
||||||
|
|
||||||
import { formatDateTitle } from 'src/lib/filters.js';
|
import { formatDateTitle } from 'src/lib/filters.js';
|
||||||
|
|
||||||
const jApi = inject('jApi');
|
const api = inject('api');
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
|
||||||
const accessLogs = ref([]);
|
const accessLogs = ref([]);
|
||||||
|
@ -17,15 +16,32 @@ const user = ref(null);
|
||||||
const getUser = async () => {
|
const getUser = async () => {
|
||||||
try {
|
try {
|
||||||
if (!route.params.id) return;
|
if (!route.params.id) return;
|
||||||
const [data] = await jApi.query(
|
|
||||||
`SELECT u.id, u.name user, u.nickname, u.email, c.phone, r.name role
|
const filter = {
|
||||||
FROM account.user u
|
where: { id: route.params.id },
|
||||||
JOIN account.role r ON r.id = u.role
|
include: [
|
||||||
LEFT JOIN vn.client c ON c.id = u.id
|
{
|
||||||
WHERE u.id = #user`,
|
relation: 'role',
|
||||||
{ user: route.params.id }
|
scope: {
|
||||||
);
|
fields: ['name']
|
||||||
user.value = data;
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
relation: 'worker',
|
||||||
|
scope: {
|
||||||
|
fields: ['phone']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
const { data } = await api.get('VnUsers/preview', {
|
||||||
|
params: {
|
||||||
|
filter: JSON.stringify(filter)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!data || !data.length) return;
|
||||||
|
user.value = data[0];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error getting user:', error);
|
console.error('Error getting user:', error);
|
||||||
}
|
}
|
||||||
|
@ -33,16 +49,12 @@ const getUser = async () => {
|
||||||
|
|
||||||
const getAccessLogs = async () => {
|
const getAccessLogs = async () => {
|
||||||
try {
|
try {
|
||||||
accessLogs.value = await jApi.query(
|
const { data } = await api.get('visitUsers/getUserVisits', {
|
||||||
`SELECT u.stamp, a.platform, a.browser, a.version, a.javascript, a.cookies
|
params: {
|
||||||
FROM visitUser u
|
userId: route.params.id
|
||||||
JOIN visitAccess c ON c.id = u.accessFk
|
}
|
||||||
JOIN visitAgent a ON a.id = c.agentFk
|
});
|
||||||
WHERE u.userFk = #user
|
accessLogs.value = data;
|
||||||
ORDER BY u.stamp DESC
|
|
||||||
LIMIT 8`,
|
|
||||||
{ user: route.params.id }
|
|
||||||
);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error getting access logs:', error);
|
console.error('Error getting access logs:', error);
|
||||||
}
|
}
|
||||||
|
@ -68,9 +80,9 @@ onMounted(async () => {
|
||||||
{{ user?.nickname }}
|
{{ user?.nickname }}
|
||||||
</span>
|
</span>
|
||||||
<span>#{{ user?.id }} - {{ user.user }} </span>
|
<span>#{{ user?.id }} - {{ user.user }} </span>
|
||||||
<span>{{ user?.role }} </span>
|
<span>{{ user?.role?.name }} </span>
|
||||||
<span>{{ user?.email }} </span>
|
<span>{{ user?.email }} </span>
|
||||||
<span>{{ user?.phone }} </span>
|
<span>{{ user?.worker?.phone }} </span>
|
||||||
</template>
|
</template>
|
||||||
</CardList>
|
</CardList>
|
||||||
<VnList :rows="accessLogs">
|
<VnList :rows="accessLogs">
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -13,6 +13,7 @@ import useNotify from 'src/composables/useNotify.js';
|
||||||
import { currency, formatDateTitle } from 'src/lib/filters.js';
|
import { currency, formatDateTitle } from 'src/lib/filters.js';
|
||||||
import { tpvStore } from 'stores/tpv';
|
import { tpvStore } from 'stores/tpv';
|
||||||
import { useAppStore } from 'stores/app';
|
import { useAppStore } from 'stores/app';
|
||||||
|
import { useUserStore } from 'stores/user';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
@ -26,6 +27,7 @@ const showAmountToPayDialog = ref(null);
|
||||||
const amountToPay = ref(null);
|
const amountToPay = ref(null);
|
||||||
const orders = ref(null);
|
const orders = ref(null);
|
||||||
const debt = ref(0);
|
const debt = ref(0);
|
||||||
|
const userStore = useUserStore();
|
||||||
const tpv = tpvStore();
|
const tpv = tpvStore();
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
@ -57,9 +59,14 @@ const onConfirmPay = async () => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!userStore.companyId) {
|
||||||
|
notify(t('companyConfigError'), 'negative');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const amount = amountToPay.value.toString().replace('.', ',');
|
const amount = amountToPay.value.toString().replace('.', ',');
|
||||||
amountToPay.value = parseFloat(amount);
|
amountToPay.value = parseFloat(amount);
|
||||||
await tpv.pay(amountToPay.value);
|
await tpv.pay(amountToPay.value, userStore.companyId);
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { jApi } from 'boot/axios';
|
import { api } from 'boot/axios';
|
||||||
|
|
||||||
export const tpvStore = defineStore('tpv', {
|
export const tpvStore = defineStore('tpv', {
|
||||||
actions: {
|
actions: {
|
||||||
async check(route) {
|
async check(route) {
|
||||||
const order = route.query.tpvOrder;
|
const orderId = route.query.tpvOrder;
|
||||||
const status = route.query.tpvStatus;
|
const status = route.query.tpvStatus;
|
||||||
if (!(order && status)) return null;
|
if (!(orderId && status)) return null;
|
||||||
|
|
||||||
await jApi.execQuery('CALL myTpvTransaction_end(#order, #status)', {
|
await api.post('tpvTransactions/end', {
|
||||||
order,
|
orderId,
|
||||||
status
|
status
|
||||||
});
|
});
|
||||||
|
|
||||||
if (status === 'ko') {
|
if (status === 'ko') {
|
||||||
const retry = confirm('retryPayQuestion');
|
const retry = confirm('retryPayQuestion');
|
||||||
if (retry) {
|
if (retry) {
|
||||||
this.retryPay(order);
|
this.retryPay(orderId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,27 +27,33 @@ export const tpvStore = defineStore('tpv', {
|
||||||
await this.realPay(amount * 100, company);
|
await this.realPay(amount * 100, company);
|
||||||
},
|
},
|
||||||
|
|
||||||
async retryPay(order) {
|
async retryPay(orderId) {
|
||||||
const payment = await jApi.getObject(
|
const { data: transactions } = await api.get(
|
||||||
`SELECT t.amount, m.companyFk
|
'clients/transactions',
|
||||||
FROM myTpvTransaction t
|
{
|
||||||
JOIN tpvMerchant m ON m.id = t.merchantFk
|
params: {
|
||||||
WHERE t.id = #order`,
|
orderFk: orderId
|
||||||
{ order }
|
}
|
||||||
|
}
|
||||||
);
|
);
|
||||||
await this.realPay(payment.amount, payment.companyFk);
|
if (transactions && transactions.length > 0) {
|
||||||
|
const [transaction] = transactions;
|
||||||
|
await this.realPay(
|
||||||
|
transaction.amount * 100,
|
||||||
|
transaction.merchantFk
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async realPay(amount, company) {
|
async realPay(amount, companyId) {
|
||||||
if (!isNumeric(amount) || amount <= 0) {
|
if (!isNumeric(amount) || amount <= 0) {
|
||||||
throw new Error('payAmountError');
|
throw new Error('payAmountError');
|
||||||
}
|
}
|
||||||
|
const { data: json } = await api.post('tpvTransactions/start', {
|
||||||
const json = await jApi.send('tpv/transaction', {
|
amount,
|
||||||
amount: parseInt(amount),
|
companyId,
|
||||||
urlOk: this.makeUrl('ok'),
|
urlOk: this.makeUrl('ok'),
|
||||||
urlKo: this.makeUrl('ko'),
|
urlKo: this.makeUrl('ko')
|
||||||
company
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const postValues = json.postValues;
|
const postValues = json.postValues;
|
||||||
|
|
|
@ -8,6 +8,7 @@ const { notify } = useNotify();
|
||||||
const TOKEN_MULTIMEDIA = 'tokenMultimedia';
|
const TOKEN_MULTIMEDIA = 'tokenMultimedia';
|
||||||
const TOKEN = 'token';
|
const TOKEN = 'token';
|
||||||
|
|
||||||
|
|
||||||
export const useUserStore = defineStore('user', () => {
|
export const useUserStore = defineStore('user', () => {
|
||||||
const token = ref('');
|
const token = ref('');
|
||||||
const tokenMultimedia = ref('');
|
const tokenMultimedia = ref('');
|
||||||
|
@ -15,7 +16,7 @@ export const useUserStore = defineStore('user', () => {
|
||||||
const user = ref(null); // Usuario en uso => supplantedUser || mainUser
|
const user = ref(null); // Usuario en uso => supplantedUser || mainUser
|
||||||
const supplantedUser = ref(null); // Usuario suplantado
|
const supplantedUser = ref(null); // Usuario suplantado
|
||||||
const mainUser = ref(null); // Usuario principal logueado
|
const mainUser = ref(null); // Usuario principal logueado
|
||||||
|
const companyId = ref(null);
|
||||||
const keepLogin = ref(false);
|
const keepLogin = ref(false);
|
||||||
const intervalId = ref(null);
|
const intervalId = ref(null);
|
||||||
const isCheckingToken = ref(false);
|
const isCheckingToken = ref(false);
|
||||||
|
@ -40,6 +41,7 @@ export const useUserStore = defineStore('user', () => {
|
||||||
} else {
|
} else {
|
||||||
await fetchUser();
|
await fetchUser();
|
||||||
await fetchTokenConfig();
|
await fetchTokenConfig();
|
||||||
|
await fetchCompanyId();
|
||||||
await supplantInit();
|
await supplantInit();
|
||||||
startInterval();
|
startInterval();
|
||||||
}
|
}
|
||||||
|
@ -154,6 +156,7 @@ export const useUserStore = defineStore('user', () => {
|
||||||
await fetchTokenConfig();
|
await fetchTokenConfig();
|
||||||
startInterval();
|
startInterval();
|
||||||
await onLogin();
|
await onLogin();
|
||||||
|
await fetchCompanyId();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error('Error logging in');
|
throw new Error('Error logging in');
|
||||||
}
|
}
|
||||||
|
@ -283,6 +286,12 @@ export const useUserStore = defineStore('user', () => {
|
||||||
user.value.lang = lang;
|
user.value.lang = lang;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const fetchCompanyId = async () => {
|
||||||
|
const { data } = await api.get('UserConfigs/getUserConfig');
|
||||||
|
companyId.value = data.companyFk;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const $reset = () => {
|
const $reset = () => {
|
||||||
token.value = '';
|
token.value = '';
|
||||||
tokenMultimedia.value = '';
|
tokenMultimedia.value = '';
|
||||||
|
@ -317,6 +326,7 @@ export const useUserStore = defineStore('user', () => {
|
||||||
tokenConfig,
|
tokenConfig,
|
||||||
isLoggedIn,
|
isLoggedIn,
|
||||||
storage,
|
storage,
|
||||||
|
companyId,
|
||||||
getToken,
|
getToken,
|
||||||
getTokenMultimedia,
|
getTokenMultimedia,
|
||||||
setToken,
|
setToken,
|
||||||
|
|
Loading…
Reference in New Issue