Merge branch 'feature/catalog-view' of https://gitea.verdnatura.es/wbuezas/hedera-web-mindshore into feature/catalog-view
This commit is contained in:
commit
52653bf196
|
@ -69,6 +69,10 @@ const props = defineProps({
|
|||
filter: {
|
||||
type: Object,
|
||||
default: null
|
||||
},
|
||||
dataRequired: {
|
||||
type: Object,
|
||||
default: () => {}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -122,9 +126,10 @@ onMounted(async () => {
|
|||
|
||||
async function fetch() {
|
||||
try {
|
||||
let { data } = await api.get(props.url, {
|
||||
params: { filter: JSON.stringify(props.filter) }
|
||||
});
|
||||
const params = props.filter
|
||||
? { filter: JSON.stringify(props.filter) }
|
||||
: {};
|
||||
let { data } = await api.get(props.url, { params });
|
||||
if (Array.isArray(data)) data = data[0] ?? {};
|
||||
formData.value = { ...data };
|
||||
emit('onDataFetched', formData.value);
|
||||
|
@ -144,9 +149,10 @@ async function save() {
|
|||
|
||||
isLoading.value = true;
|
||||
try {
|
||||
const body = props.mapper
|
||||
let body = props.mapper
|
||||
? props.mapper(formData.value, originalData.value)
|
||||
: formData.value;
|
||||
body = { ...body, ...props.dataRequired };
|
||||
const method = props.urlCreate ? 'post' : 'patch';
|
||||
const url = props.urlCreate || props.urlUpdate || props.url;
|
||||
|
||||
|
|
|
@ -168,6 +168,7 @@ export default {
|
|||
// Errors
|
||||
errors: {
|
||||
statusUnauthorized: 'Accés denegat',
|
||||
tokenConfig: 'Error al obtenir la configuració del token'
|
||||
tokenConfig: 'Error al obtenir la configuració del token',
|
||||
orderNotOwnedByUser: 'The order belongs to another user'
|
||||
}
|
||||
};
|
||||
|
|
|
@ -200,6 +200,7 @@ export default {
|
|||
// Errors
|
||||
errors: {
|
||||
statusUnauthorized: 'Access denied',
|
||||
tokenConfig: 'Error fetching token config'
|
||||
tokenConfig: 'Error fetching token config',
|
||||
orderNotOwnedByUser: 'The order belongs to another user'
|
||||
}
|
||||
};
|
||||
|
|
|
@ -200,6 +200,7 @@ export default {
|
|||
// Errors
|
||||
errors: {
|
||||
statusUnauthorized: 'Acceso denegado',
|
||||
tokenConfig: 'Error al obtener configuración de token'
|
||||
tokenConfig: 'Error al obtener configuración de token',
|
||||
orderNotOwnedByUser: 'The order belongs to another user'
|
||||
}
|
||||
};
|
||||
|
|
|
@ -172,6 +172,7 @@ export default {
|
|||
errors: {
|
||||
statusUnauthorized: 'Accès refusé',
|
||||
tokenConfig:
|
||||
'Erreur lors de la récupération de la configuration du jeton'
|
||||
'Erreur lors de la récupération de la configuration du jeton',
|
||||
orderNotOwnedByUser: 'The order belongs to another user'
|
||||
}
|
||||
};
|
||||
|
|
|
@ -166,6 +166,7 @@ export default {
|
|||
// Errors
|
||||
errors: {
|
||||
statusUnauthorized: 'Acesso negado',
|
||||
tokenConfig: 'Erro ao obter configuração do token'
|
||||
tokenConfig: 'Erro ao obter configuração do token',
|
||||
orderNotOwnedByUser: 'The order belongs to another user'
|
||||
}
|
||||
};
|
||||
|
|
|
@ -7,19 +7,21 @@ import VnImg from 'src/components/ui/VnImg.vue';
|
|||
import VnForm from 'src/components/common/VnForm.vue';
|
||||
import VnSelect from 'src/components/common/VnSelect.vue';
|
||||
import VnInput from 'src/components/common/VnInput.vue';
|
||||
import FormModel from 'src/components/common/FormModel.vue';
|
||||
|
||||
import { useAppStore } from 'stores/app';
|
||||
import { useUserStore } from 'stores/user';
|
||||
import { storeToRefs } from 'pinia';
|
||||
|
||||
const jApi = inject('jApi');
|
||||
const api = inject('api');
|
||||
const { t } = useI18n();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const appStore = useAppStore();
|
||||
const userStore = useUserStore();
|
||||
const { isHeaderMounted } = storeToRefs(appStore);
|
||||
|
||||
const newsTags = ref([]);
|
||||
const pks = computed(() => ({ id: route.params.id }));
|
||||
const isEditMode = !!route.params.id;
|
||||
const formData = ref(
|
||||
!route.params.id
|
||||
|
@ -32,22 +34,25 @@ const formData = ref(
|
|||
: undefined
|
||||
);
|
||||
|
||||
const fetchNewDataSql = computed(() => {
|
||||
const initialFetchUrl = computed(() => {
|
||||
if (!route.params.id) return undefined;
|
||||
return {
|
||||
query: `
|
||||
SELECT id, title, text, tag, priority, image
|
||||
FROM news WHERE id = #id`,
|
||||
params: { id: route.params.id }
|
||||
};
|
||||
return `news/${route.params.id}`;
|
||||
});
|
||||
|
||||
const urlUpdate = computed(() => {
|
||||
if (!route.params.id) return undefined;
|
||||
return `news/${route.params.id}`;
|
||||
});
|
||||
|
||||
const urlCreate = computed(() => {
|
||||
if (route.params.id) return undefined;
|
||||
return 'news';
|
||||
});
|
||||
|
||||
const getNewsTag = async () => {
|
||||
try {
|
||||
newsTags.value = await jApi.query(
|
||||
`SELECT name, description FROM newsTag
|
||||
ORDER BY description`
|
||||
);
|
||||
const { data } = await api.get('newsTags');
|
||||
newsTags.value = data;
|
||||
} catch (error) {
|
||||
console.error('Error getting newsTag:', error);
|
||||
}
|
||||
|
@ -73,19 +78,14 @@ onMounted(async () => {
|
|||
<QTooltip>{{ t('back') }}</QTooltip>
|
||||
</QBtn>
|
||||
</Teleport>
|
||||
<VnForm
|
||||
ref="vnFormRef"
|
||||
:fetch-form-data-sql="fetchNewDataSql"
|
||||
<FormModel
|
||||
:form-initial-data="formData"
|
||||
:create-model-default="{
|
||||
field: 'userFk',
|
||||
value: 'account.myUser_getId()'
|
||||
}"
|
||||
:pks="pks"
|
||||
:is-edit-mode="isEditMode"
|
||||
table="news"
|
||||
schema="hedera"
|
||||
separation-between-inputs="lg"
|
||||
:url="initialFetchUrl"
|
||||
:auto-load="isEditMode"
|
||||
:url-create="urlCreate"
|
||||
:url-update="urlUpdate"
|
||||
:data-required="{ userFk: userStore.userId }"
|
||||
:show-bottom-actions="false"
|
||||
@on-data-saved="goBack()"
|
||||
>
|
||||
<template #form="{ data }">
|
||||
|
@ -215,7 +215,7 @@ onMounted(async () => {
|
|||
}"
|
||||
/>
|
||||
</template>
|
||||
</VnForm>
|
||||
</FormModel>
|
||||
</QPage>
|
||||
</template>
|
||||
|
||||
|
|
|
@ -5,47 +5,31 @@ import { useI18n } from 'vue-i18n';
|
|||
import CardList from 'src/components/ui/CardList.vue';
|
||||
import VnImg from 'src/components/ui/VnImg.vue';
|
||||
import VnList from 'src/components/ui/VnList.vue';
|
||||
import FetchData from 'src/components/common/FetchData.vue';
|
||||
|
||||
import { useAppStore } from 'stores/app';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useVnConfirm } from 'src/composables/useVnConfirm.js';
|
||||
import useNotify from 'src/composables/useNotify.js';
|
||||
|
||||
const jApi = inject('jApi');
|
||||
const api = inject('api');
|
||||
const { t } = useI18n();
|
||||
const appStore = useAppStore();
|
||||
const { openConfirmationModal } = useVnConfirm();
|
||||
const { isHeaderMounted } = storeToRefs(appStore);
|
||||
const { notify } = useNotify();
|
||||
|
||||
const loading = ref(false);
|
||||
const loading = ref(true);
|
||||
const news = ref([]);
|
||||
|
||||
const getNews = async () => {
|
||||
try {
|
||||
loading.value = true;
|
||||
news.value = await jApi.query(
|
||||
`SELECT n.id, u.nickname, n.priority, n.image, n.title
|
||||
FROM news n
|
||||
JOIN account.user u ON u.id = n.userFk
|
||||
ORDER BY priority, n.created DESC`
|
||||
);
|
||||
loading.value = false;
|
||||
} catch (error) {
|
||||
console.error('Error getting news:', error);
|
||||
}
|
||||
const onFetch = data => {
|
||||
news.value = data;
|
||||
loading.value = false;
|
||||
};
|
||||
|
||||
const deleteNew = async (id, index) => {
|
||||
try {
|
||||
await jApi.execQuery(
|
||||
`START TRANSACTION;
|
||||
DELETE FROM hedera.news WHERE ((id = #id));
|
||||
COMMIT`,
|
||||
{
|
||||
id
|
||||
}
|
||||
);
|
||||
await api.delete(`news/${id}`);
|
||||
news.value.splice(index, 1);
|
||||
notify(t('dataSaved'), 'positive');
|
||||
} catch (error) {
|
||||
|
@ -57,6 +41,7 @@ onMounted(async () => getNews());
|
|||
</script>
|
||||
|
||||
<template>
|
||||
<FetchData ref="fetchNewsRef" url="news" auto-load @on-fetch="onFetch" />
|
||||
<Teleport v-if="isHeaderMounted" to="#actions">
|
||||
<QBtn
|
||||
:label="t('addNew')"
|
||||
|
|
|
@ -3,11 +3,10 @@ import { useI18n } from 'vue-i18n';
|
|||
import { ref, onMounted, inject, reactive, computed } from 'vue';
|
||||
|
||||
import VnSelect from 'src/components/common/VnSelect.vue';
|
||||
import VnForm from 'src/components/common/VnForm.vue';
|
||||
import VnInput from 'src/components/common/VnInput.vue';
|
||||
import useNotify from 'src/composables/useNotify.js';
|
||||
import FormModel from 'src/components/common/FormModel.vue';
|
||||
|
||||
const jApi = inject('jApi');
|
||||
const api = inject('api');
|
||||
const { t } = useI18n();
|
||||
const { notify } = useNotify();
|
||||
|
@ -33,7 +32,7 @@ const statusIcons = {
|
|||
}
|
||||
};
|
||||
const formInitialData = reactive({
|
||||
schema: 'catalog',
|
||||
collectionFk: 'catalog',
|
||||
updateMatching: true
|
||||
});
|
||||
const imageCollections = ref([]);
|
||||
|
@ -45,9 +44,8 @@ const isSubmitable = computed(() =>
|
|||
|
||||
const getImageCollections = async () => {
|
||||
try {
|
||||
imageCollections.value = await jApi.query(
|
||||
'SELECT name, `desc` FROM imageCollection ORDER BY `desc`'
|
||||
);
|
||||
const { data } = await api.get('imageCollections');
|
||||
imageCollections.value = data;
|
||||
} catch (error) {
|
||||
console.error('Error getting image collections:', error);
|
||||
}
|
||||
|
@ -61,38 +59,36 @@ const onSubmit = async data => {
|
|||
const filteredFiles = addedFiles.value.filter(
|
||||
file => file.uploadStatus === 'pending'
|
||||
);
|
||||
const promises = filteredFiles.map((file, index) => {
|
||||
const promises = filteredFiles.map(async (file, index) => {
|
||||
const fileIndex = filteredFiles[index].index;
|
||||
addedFiles.value[fileIndex].uploadStatus = 'uploading';
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('updateMatching', data.updateMatching);
|
||||
formData.append('image', file.file);
|
||||
formData.append('name', file.name);
|
||||
formData.append('schema', data.schema);
|
||||
formData.append('srv', 'json:image/upload');
|
||||
return api({
|
||||
method: 'post',
|
||||
url: location.origin,
|
||||
data: formData,
|
||||
const now = new Date();
|
||||
const timestamp = now.getTime();
|
||||
const fileName = `${file.name}_${timestamp}`;
|
||||
formData.append('image', file.file, fileName);
|
||||
|
||||
await api.post('images/uploadPhotoAdmin', formData, {
|
||||
params: {
|
||||
name: fileName,
|
||||
collection: data.collectionFk,
|
||||
updateMatching: data.updateMatching
|
||||
},
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data'
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const results = await Promise.allSettled(promises);
|
||||
results.forEach((result, index) => {
|
||||
const fileIndex = filteredFiles[index].index;
|
||||
addedFiles.value[fileIndex].uploadStatus = result.status;
|
||||
|
||||
if (result.status === 'rejected') {
|
||||
addedFiles.value[fileIndex].errorMessage = t(
|
||||
result.reason?.response?.data?.data?.message
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
const allSuccessful = results.every(
|
||||
result => result.status === 'fulfilled'
|
||||
);
|
||||
|
@ -139,16 +135,17 @@ onMounted(async () => getImageCollections());
|
|||
|
||||
<template>
|
||||
<QPage class="vn-w-sm">
|
||||
<VnForm
|
||||
<FormModel
|
||||
ref="vnFormRef"
|
||||
:default-actions="false"
|
||||
:form-initial-data="formInitialData"
|
||||
separation-between-inputs="md"
|
||||
show-bottom-actions
|
||||
:save-fn="onSubmit"
|
||||
>
|
||||
<template #form="{ data }">
|
||||
<VnSelect
|
||||
v-model="data.schema"
|
||||
v-model="data.collectionFk"
|
||||
:label="t('collection')"
|
||||
option-label="desc"
|
||||
option-value="name"
|
||||
|
@ -269,7 +266,7 @@ onMounted(async () => getImageCollections());
|
|||
data-cy="photoUploadSubmitBtn"
|
||||
/>
|
||||
</template>
|
||||
</VnForm>
|
||||
</FormModel>
|
||||
</QPage>
|
||||
</template>
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import { useAppStore } from 'stores/app';
|
|||
import { storeToRefs } from 'pinia';
|
||||
|
||||
const { t } = useI18n();
|
||||
const jApi = inject('jApi');
|
||||
const api = inject('api');
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const appStore = useAppStore();
|
||||
|
@ -24,28 +24,21 @@ const visitsData = ref(null);
|
|||
const getVisits = async () => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const [visitsResponse] = await jApi.query(
|
||||
`SELECT browser,
|
||||
MIN(CAST(version AS DECIMAL(4,1))) minVersion,
|
||||
MAX(CAST(version AS DECIMAL(4,1))) maxVersion,
|
||||
MAX(c.stamp) lastVisit,
|
||||
COUNT(DISTINCT c.id) visits,
|
||||
SUM(a.firstAccessFk = c.id AND v.firstAgentFk = a.id) newVisits
|
||||
FROM visitUser e
|
||||
JOIN visitAccess c ON c.id = e.accessFk
|
||||
JOIN visitAgent a ON a.id = c.agentFk
|
||||
JOIN visit v ON v.id = a.visitFk
|
||||
WHERE c.stamp BETWEEN TIMESTAMP(#from,'00:00:00') AND TIMESTAMP(#to,'23:59:59')
|
||||
GROUP BY browser ORDER BY visits DESC`,
|
||||
{
|
||||
|
||||
const { data } = await api.get('visitUsers/getVisits', {
|
||||
params: {
|
||||
from: date(from.value),
|
||||
to: date(to.value)
|
||||
}
|
||||
);
|
||||
visitsData.value = visitsResponse;
|
||||
loading.value = false;
|
||||
});
|
||||
|
||||
if (!data || !data.length) return;
|
||||
|
||||
visitsData.value = data[0];
|
||||
} catch (error) {
|
||||
console.error('Error getting visits:', error);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -7,15 +7,18 @@ import VnSelect from 'src/components/common/VnSelect.vue';
|
|||
|
||||
import { formatDateTitle, formatDate } from 'src/lib/filters.js';
|
||||
import useNotify from 'src/composables/useNotify.js';
|
||||
import { onUserId } from 'src/utils/onUserId';
|
||||
import { useUserStore } from 'stores/user';
|
||||
import { useAppStore } from 'stores/app';
|
||||
import { storeToRefs } from 'pinia';
|
||||
|
||||
const jApi = inject('jApi');
|
||||
const api = inject('api');
|
||||
const { t } = useI18n();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const { notify } = useNotify();
|
||||
const appStore = useAppStore();
|
||||
const userStore = useUserStore();
|
||||
const { localeDates, isMobile } = storeToRefs(appStore);
|
||||
|
||||
const stepperRef = ref(null);
|
||||
|
@ -148,38 +151,103 @@ const validateStep = (formField, errorMessage) => {
|
|||
return validation;
|
||||
};
|
||||
|
||||
const getAddresses = async () => {
|
||||
const getAddresses = async (clientFk) => {
|
||||
try {
|
||||
addresses.value = await jApi.query(
|
||||
`SELECT a.id, a.nickname, p.name province, a.city, a.street, a.isActive, c.name
|
||||
FROM myAddress a
|
||||
LEFT JOIN vn.province p ON p.id = a.provinceFk
|
||||
JOIN vn.country c ON c.id = p.countryFk
|
||||
WHERE a.isActive`
|
||||
);
|
||||
const filter = {
|
||||
where: {
|
||||
clientFk,
|
||||
isActive: true,
|
||||
},
|
||||
include: [
|
||||
{
|
||||
relation: 'province',
|
||||
scope: {
|
||||
fields: ['name', 'countryFk'],
|
||||
include: [
|
||||
'country',
|
||||
{
|
||||
relation: 'country',
|
||||
scope: {
|
||||
fields: ['name'],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
fields: [
|
||||
'id',
|
||||
'nickname',
|
||||
'city',
|
||||
'street',
|
||||
'isActive',
|
||||
'provinceFk',
|
||||
]
|
||||
};
|
||||
|
||||
const { data: myAddresses } = await api.get('Addresses', {
|
||||
params: {
|
||||
filter: JSON.stringify(filter)
|
||||
}
|
||||
});
|
||||
|
||||
addresses.value = myAddresses;
|
||||
} catch (error) {
|
||||
console.error('Error getting addresses:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const getOrder = async (orderId) => {
|
||||
const { data } = await api.get(`Orders/${orderId}`, {
|
||||
params: {
|
||||
filter: JSON.stringify({
|
||||
include: [
|
||||
{
|
||||
relation: 'deliveryMethod',
|
||||
scope: {
|
||||
fields: ['code'],
|
||||
},
|
||||
},
|
||||
],
|
||||
fields: [
|
||||
'id',
|
||||
'delivery_method_id',
|
||||
'landed',
|
||||
'agencyModeFk',
|
||||
'addressFk',
|
||||
]
|
||||
})
|
||||
}
|
||||
});
|
||||
return data;
|
||||
};
|
||||
|
||||
const getAgenciesInZone = async () => {
|
||||
const agenciesInZone = await api.get('Agencies/landsThatDay', {
|
||||
params: {
|
||||
addressFk: orderForm.value.address,
|
||||
landed: new Date(orderForm.value.date),
|
||||
}
|
||||
});
|
||||
const deliveryMethods = await api.get('DeliveryMethods');
|
||||
|
||||
return agenciesInZone.data
|
||||
.filter(agency => agency.isVisible)
|
||||
.map(agency => ({
|
||||
id: agency.agencyModeFk,
|
||||
description: agency.description,
|
||||
deliveryMethod: deliveryMethods.data.find(dm => dm.id === agency.deliveryMethodFk).code,
|
||||
}))
|
||||
.toSorted((a, b) => a.description.localeCompare(b.description));
|
||||
};
|
||||
|
||||
const getAgencies = async () => {
|
||||
try {
|
||||
const { results } = await jApi.execQuery(
|
||||
`CALL vn.zone_getAgency(#address, #date);
|
||||
SELECT DISTINCT a.agencyModeFk id, a.description
|
||||
FROM tmp.zoneGetAgency a
|
||||
JOIN vn.deliveryMethod d
|
||||
ON d.id = a.deliveryMethodFk
|
||||
WHERE d.code IN ('AGENCY', 'DELIVERY')
|
||||
AND a.isVisible
|
||||
ORDER BY a.description;
|
||||
DROP TEMPORARY TABLE tmp.zoneGetAgency`,
|
||||
{
|
||||
address: orderForm.value.address,
|
||||
date: new Date(orderForm.value.date)
|
||||
}
|
||||
);
|
||||
agencies.value = results[1].data;
|
||||
const agenciesInZone = await getAgenciesInZone();
|
||||
const results = agenciesInZone
|
||||
.filter(agency => agency.deliveryMethod === 'AGENCY' || agency.deliveryMethod === 'DELIVERY');
|
||||
|
||||
agencies.value = results;
|
||||
|
||||
if (agencies.value && agencies.value.length && defaultValues.value) {
|
||||
const found = agencies.value.find(
|
||||
|
@ -196,22 +264,10 @@ const getAgencies = async () => {
|
|||
|
||||
const getWarehouses = async () => {
|
||||
try {
|
||||
const { results } = await jApi.execQuery(
|
||||
`CALL vn.zone_getAgency(#address, #date);
|
||||
SELECT DISTINCT a.agencyModeFk id, a.description
|
||||
FROM tmp.zoneGetAgency a
|
||||
JOIN vn.deliveryMethod d
|
||||
ON d.id = a.deliveryMethodFk
|
||||
WHERE d.code IN ('PICKUP')
|
||||
AND a.isVisible
|
||||
ORDER BY a.description;
|
||||
DROP TEMPORARY TABLE tmp.zoneGetAgency;`,
|
||||
{
|
||||
address: orderForm.value.address,
|
||||
date: new Date(orderForm.value.date)
|
||||
}
|
||||
);
|
||||
warehouses.value = results[1].data;
|
||||
const agenciesInZone = await getAgenciesInZone();
|
||||
const results = agenciesInZone.filter(agency => agency.deliveryMethod === 'PICKUP');
|
||||
|
||||
warehouses.value = results;
|
||||
|
||||
if (!warehouses.value || !warehouses.value.length) {
|
||||
notify(t('noWarehousesAvailableForDate'), 'negative');
|
||||
|
@ -260,32 +316,60 @@ const onPreviousStep = async stepIndex => {
|
|||
}
|
||||
};
|
||||
|
||||
const configureOrder = (orderId) => api.post(
|
||||
'applications/myOrder_configure/execute-proc',
|
||||
{
|
||||
schema: 'hedera',
|
||||
params: [
|
||||
orderId,
|
||||
new Date(orderForm.value.date),
|
||||
orderForm.value.method,
|
||||
orderForm.value.agency,
|
||||
orderForm.value.address,
|
||||
],
|
||||
},
|
||||
);
|
||||
|
||||
const createOrder = async (userId) => {
|
||||
const orderConfig = await api.get('OrderConfigs');
|
||||
|
||||
const companyFk = orderConfig.data[0]?.defaultCompanyFk;
|
||||
|
||||
return await api.post(
|
||||
'Orders',
|
||||
{
|
||||
sourceApp: 'WEB',
|
||||
landed: new Date(orderForm.value.date),
|
||||
clientFk: userId,
|
||||
companyFk,
|
||||
addressFk: orderForm.value.address,
|
||||
agencyModeFk: orderForm.value.agency,
|
||||
},
|
||||
)
|
||||
};
|
||||
|
||||
const submit = async () => {
|
||||
loading.value = true;
|
||||
let query =
|
||||
'CALL myOrder_create(@orderId, #date, #method, #agency, #address); SELECT @orderId;';
|
||||
if (id) {
|
||||
orderForm.value.id = id;
|
||||
query =
|
||||
'CALL myOrder_configure(#id, #date, #method, #agency, #address)';
|
||||
}
|
||||
|
||||
let resultSet;
|
||||
const userId = userStore.user.id;
|
||||
|
||||
try {
|
||||
const { date, ...restOfForm } = orderForm.value;
|
||||
const _date = new Date(date);
|
||||
resultSet = await jApi.execQuery(query, { ...restOfForm, date: _date });
|
||||
if (id) {
|
||||
notify(t('orderUpdated'), 'positive');
|
||||
if (route.query.continue === 'catalog') {
|
||||
router.push({ name: 'catalog' });
|
||||
} else {
|
||||
router.push({ name: 'basket', params: { id } });
|
||||
}
|
||||
if (!id) {
|
||||
const order = await createOrder(userId);
|
||||
const orderId = order.data.id;
|
||||
await configureOrder(orderId);
|
||||
|
||||
appStore.loadIntoBasket(orderId);
|
||||
router.push({ name: 'catalog' });
|
||||
} else {
|
||||
const orderId = resultSet.results[1].data[0]['@orderId'];
|
||||
appStore.loadIntoBasket(orderId);
|
||||
await configureOrder(id);
|
||||
|
||||
notify(t('orderUpdated'), 'positive');
|
||||
if (route.query.continue === 'catalog') {
|
||||
router.push({ name: 'catalog' });
|
||||
} else {
|
||||
router.push({ name: 'basket', params: { id } });
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error submitting order:', error);
|
||||
|
@ -295,10 +379,8 @@ const submit = async () => {
|
|||
};
|
||||
|
||||
const getDefaultValues = async () => {
|
||||
return await jApi.query(
|
||||
`SELECT deliveryMethod, agencyModeFk, addressFk, defaultAgencyFk
|
||||
FROM myBasketDefaults`
|
||||
);
|
||||
const { data: myBasketDefaults } = await api.get('Clients/myBasketDefaults');
|
||||
return myBasketDefaults;
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
|
@ -308,17 +390,11 @@ onMounted(async () => {
|
|||
if (route.params.id) {
|
||||
notify(t('rememberReconfiguringImpact'), 'warning');
|
||||
|
||||
const [order] = await jApi.query(
|
||||
`SELECT m.code deliveryMethod, o.sent, o.agencyModeFk, o.addressFk
|
||||
FROM myOrder o
|
||||
JOIN vn.deliveryMethod m ON m.id = o.deliveryMethodFk
|
||||
WHERE o.id = #id`,
|
||||
{ id: route.params.id }
|
||||
);
|
||||
const order = await getOrder(route.params.id);
|
||||
|
||||
if (order) {
|
||||
orderForm.value.method = order.deliveryMethod;
|
||||
orderForm.value.date = formatDate(order.sent, 'YYYY/MM/DD');
|
||||
orderForm.value.method = order.deliveryMethod.code;
|
||||
orderForm.value.date = formatDate(order.landed, 'YYYY/MM/DD');
|
||||
orderForm.value.agency = order.agencyModeFk;
|
||||
orderForm.value.address = order.addressFk;
|
||||
}
|
||||
|
@ -326,10 +402,10 @@ onMounted(async () => {
|
|||
const [_defaultValues] = await getDefaultValues();
|
||||
if (_defaultValues) defaultValues.value = _defaultValues;
|
||||
}
|
||||
|
||||
getAddresses();
|
||||
});
|
||||
|
||||
onUserId(getAddresses);
|
||||
|
||||
watch(
|
||||
() => orderForm.value.method,
|
||||
() => {
|
||||
|
|
|
@ -8,9 +8,10 @@ import { currency, formatDate } from 'src/lib/filters.js';
|
|||
import { usePrintService } from 'src/composables/usePrintService';
|
||||
import { useAppStore } from 'stores/app';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { onUserId } from 'src/utils/onUserId';
|
||||
|
||||
const { t } = useI18n();
|
||||
const jApi = inject('jApi');
|
||||
const api = inject('api');
|
||||
const { openReport } = usePrintService();
|
||||
const appStore = useAppStore();
|
||||
const { isHeaderMounted } = storeToRefs(appStore);
|
||||
|
@ -50,27 +51,38 @@ const columns = computed(() => [
|
|||
}
|
||||
]);
|
||||
|
||||
const fetchInvoices = async () => {
|
||||
const params = {
|
||||
const fetchInvoices = async clientFk => {
|
||||
const { from, to } = {
|
||||
from: new Date(currentYear.value, 0),
|
||||
to: new Date(currentYear.value, 11, 31, 23, 59, 59)
|
||||
};
|
||||
invoices.value = await jApi.query(
|
||||
`SELECT id, ref, issued, amount, hasPdf
|
||||
FROM myInvoice
|
||||
WHERE issued BETWEEN #from AND #to
|
||||
ORDER BY issued DESC
|
||||
LIMIT 100`,
|
||||
params
|
||||
);
|
||||
const filter = {
|
||||
where: {
|
||||
clientFk,
|
||||
issued: {
|
||||
between: [from, to]
|
||||
}
|
||||
},
|
||||
order: ['issued DESC'],
|
||||
fields: ['id', 'ref', 'issued', 'amount', 'hasPdf'],
|
||||
limit: 100
|
||||
};
|
||||
|
||||
const { data } = await api.get('InvoiceOuts', {
|
||||
params: {
|
||||
filter: JSON.stringify(filter)
|
||||
}
|
||||
});
|
||||
invoices.value = data;
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
await fetchInvoices();
|
||||
for (let year = currentYear.value - 5; year <= currentYear.value; year++) {
|
||||
years.value.push(year);
|
||||
}
|
||||
});
|
||||
|
||||
onUserId(fetchInvoices);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
|
@ -81,14 +81,6 @@ export const useAppStore = defineStore('hedera', {
|
|||
this.basketOrderId = localStorage.getItem(storageOrderName);
|
||||
},
|
||||
|
||||
async checkOrder(orderId) {
|
||||
const resultSet = await jApi.execQuery(
|
||||
'CALL myOrder_checkConfig(#id)',
|
||||
{ id: orderId }
|
||||
);
|
||||
resultSet.fetchValue();
|
||||
},
|
||||
|
||||
async check(checkoutContinue) {
|
||||
if (this.basketOrderId) {
|
||||
return await this.checkRedirect(checkoutContinue);
|
||||
|
@ -99,26 +91,36 @@ export const useAppStore = defineStore('hedera', {
|
|||
},
|
||||
|
||||
async checkRedirect(checkoutContinue) {
|
||||
try {
|
||||
await this.checkOrder(this.basketOrderId);
|
||||
return true;
|
||||
} catch (err) {
|
||||
switch (err.code) {
|
||||
case 'orderConfirmed':
|
||||
case 'orderNotOwnedByUser':
|
||||
this.unloadOrder();
|
||||
await this.redirect();
|
||||
break;
|
||||
default:
|
||||
this.router.push({
|
||||
name: 'checkout',
|
||||
params: { id: this.basketOrderId },
|
||||
query: { continue: checkoutContinue }
|
||||
});
|
||||
notify(err.message, 'negative');
|
||||
}
|
||||
return false;
|
||||
const orderId = this.basketOrderId;
|
||||
const myOrder_checkConfig = await api.post('applications/myOrder_checkConfig/execute-proc', {
|
||||
schema: 'hedera',
|
||||
params: [orderId],
|
||||
}, {
|
||||
validateStatus: () => true,
|
||||
});
|
||||
|
||||
if (myOrder_checkConfig.status >= 200 && myOrder_checkConfig.status < 300) {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (myOrder_checkConfig.data.error?.message) {
|
||||
case 'orderNotOwnedByUser':
|
||||
notify(t(`errors.orderNotOwnedByUser`), 'negative');
|
||||
case 'orderConfirmed':
|
||||
case 'orderNotOwnedByUser':
|
||||
this.unloadOrder();
|
||||
await this.redirect();
|
||||
break;
|
||||
default:
|
||||
this.router.push({
|
||||
name: 'checkout',
|
||||
params: { id: this.basketOrderId },
|
||||
query: { continue: checkoutContinue }
|
||||
});
|
||||
notify(myOrder_checkConfig.data.error.message, 'negative');
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
async redirect() {
|
||||
|
|
|
@ -296,6 +296,8 @@ export const useUserStore = defineStore('user', () => {
|
|||
tokenConfig.value = null;
|
||||
};
|
||||
|
||||
const userId = computed(() => user.value?.id);
|
||||
|
||||
watch(
|
||||
[mainUser, supplantedUser],
|
||||
() => (user.value = supplantedUser.value || mainUser.value),
|
||||
|
@ -336,6 +338,7 @@ export const useUserStore = defineStore('user', () => {
|
|||
updateUserLang,
|
||||
init,
|
||||
$reset,
|
||||
onLogin
|
||||
onLogin,
|
||||
userId
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue