forked from verdnatura/salix-front
feat: orderCreateDialog
This commit is contained in:
parent
b3391ab522
commit
1f96f5c09a
|
@ -126,6 +126,7 @@ globals:
|
|||
notifications: Notifications
|
||||
defaulter: Defaulter
|
||||
customerCreate: New customer
|
||||
createOrder: New order
|
||||
fiscalData: Fiscal data
|
||||
billingData: Billing data
|
||||
consignees: Consignees
|
||||
|
|
|
@ -123,6 +123,7 @@ globals:
|
|||
inheritedRoles: Roles heredados
|
||||
customers: Clientes
|
||||
customerCreate: Nuevo cliente
|
||||
createOrder: Nuevo pedido
|
||||
list: Listado
|
||||
webPayments: Pagos Web
|
||||
extendedList: Listado extendido
|
||||
|
|
|
@ -179,17 +179,6 @@ const setData = (entity) => (data.value = useCardDescription(entity?.name, entit
|
|||
>
|
||||
<QTooltip>{{ t('Customer invoice out list') }}</QTooltip>
|
||||
</QBtn>
|
||||
<QBtn
|
||||
:to="{
|
||||
name: 'OrderCreate',
|
||||
query: { table: JSON.stringify({ clientFk: entity.id }) },
|
||||
}"
|
||||
size="md"
|
||||
icon="vn:basketadd"
|
||||
color="primary"
|
||||
>
|
||||
<QTooltip>{{ t('New order') }}</QTooltip>
|
||||
</QBtn>
|
||||
<QBtn
|
||||
:to="{
|
||||
name: 'AccountSummary',
|
||||
|
@ -214,7 +203,6 @@ es:
|
|||
Go to module index: Ir al índice del módulo
|
||||
Customer ticket list: Listado de tickets del cliente
|
||||
Customer invoice out list: Listado de facturas del cliente
|
||||
New order: Nuevo pedido
|
||||
Go to user: Ir al usuario
|
||||
Customer unpaid: Cliente impago
|
||||
Unpaid: Impagado
|
||||
|
|
|
@ -9,6 +9,7 @@ import useNotify from 'src/composables/useNotify';
|
|||
|
||||
import VnSmsDialog from 'src/components/common/VnSmsDialog.vue';
|
||||
import TicketCreateDialog from 'src/pages/Ticket/TicketCreateDialog.vue';
|
||||
import OrderCreateDialog from 'src/pages/Order/Card/OrderCreateDialog.vue';
|
||||
import { ref } from 'vue';
|
||||
|
||||
const $props = defineProps({
|
||||
|
@ -42,11 +43,15 @@ const sendSms = async (payload) => {
|
|||
notify(error.message, 'positive');
|
||||
}
|
||||
};
|
||||
const ticketCreateFormDialog = ref(null);
|
||||
|
||||
const ticketCreateFormDialog = ref(null);
|
||||
const openTicketCreateForm = () => {
|
||||
ticketCreateFormDialog.value.show();
|
||||
};
|
||||
const orderCreateFormDialog = ref(null);
|
||||
const openOrderCreateForm = () => {
|
||||
orderCreateFormDialog.value.show();
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
@ -58,6 +63,14 @@ const openTicketCreateForm = () => {
|
|||
</QDialog>
|
||||
</QItemSection>
|
||||
</QItem>
|
||||
<QItem v-ripple clickable @click="openOrderCreateForm()">
|
||||
<QItemSection>
|
||||
{{ t('globals.pageTitles.createOrder') }}
|
||||
<QDialog ref="orderCreateFormDialog">
|
||||
<OrderCreateDialog :client-fk="customer.id" />
|
||||
</QDialog>
|
||||
</QItemSection>
|
||||
</QItem>
|
||||
<QItem v-ripple clickable>
|
||||
<QItemSection @click="showSmsDialog()">{{ t('Send SMS') }}</QItemSection>
|
||||
</QItem>
|
||||
|
|
|
@ -0,0 +1,220 @@
|
|||
<script setup>
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import axios from 'axios';
|
||||
import { useState } from 'composables/useState';
|
||||
import FormModelPopup from 'components/FormModelPopup.vue';
|
||||
import VnRow from 'components/ui/VnRow.vue';
|
||||
import VnSelect from 'components/common/VnSelect.vue';
|
||||
import VnInputDate from 'components/common/VnInputDate.vue';
|
||||
import { useDialogPluginComponent } from 'quasar';
|
||||
import { reactive } from 'vue';
|
||||
import FetchData from 'components/FetchData.vue';
|
||||
|
||||
const { t } = useI18n();
|
||||
const route = useRoute();
|
||||
const state = useState();
|
||||
const ORDER_MODEL = 'order';
|
||||
|
||||
const router = useRouter();
|
||||
const clientList = ref([]);
|
||||
const agencyList = ref([]);
|
||||
const addressList = ref([]);
|
||||
defineEmits(['confirm', ...useDialogPluginComponent.emits]);
|
||||
|
||||
const fetchAddressList = async (addressId) => {
|
||||
try {
|
||||
const { data } = await axios.get('addresses', {
|
||||
params: {
|
||||
filter: JSON.stringify({
|
||||
fields: ['id', 'nickname', 'street', 'city'],
|
||||
where: { id: addressId },
|
||||
}),
|
||||
},
|
||||
});
|
||||
addressList.value = data;
|
||||
if (addressList.value?.length === 1) {
|
||||
state.get(ORDER_MODEL).addressId = addressList.value[0].id;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(`Error fetching addresses`, err);
|
||||
return err.response;
|
||||
}
|
||||
};
|
||||
|
||||
const fetchAgencyList = async (landed, addressFk) => {
|
||||
if (!landed || !addressFk) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const { data } = await axios.get('Agencies/landsThatDay', {
|
||||
params: {
|
||||
addressFk,
|
||||
landed: new Date(landed).toISOString(),
|
||||
},
|
||||
});
|
||||
agencyList.value = data;
|
||||
} catch (err) {
|
||||
console.error(`Error fetching agencies`, err);
|
||||
return err.response;
|
||||
}
|
||||
};
|
||||
|
||||
// const fetchOrderDetails = (order) => {
|
||||
// fetchAddressList(order?.addressFk);
|
||||
// fetchAgencyList(order?.landed, order?.addressFk);
|
||||
// };
|
||||
const $props = defineProps({
|
||||
clientFk: {
|
||||
type: Number,
|
||||
default: null,
|
||||
},
|
||||
});
|
||||
const initialFormState = reactive({
|
||||
active: true,
|
||||
addressId: null,
|
||||
clientFk: $props.clientFk,
|
||||
});
|
||||
// const orderMapper = (order) => {
|
||||
// return {
|
||||
// addressId: order.addressFk,
|
||||
// agencyModeId: order.agencyModeFk,
|
||||
// landed: new Date(order.landed).toISOString(),
|
||||
// };
|
||||
// };
|
||||
// const orderFilter = {
|
||||
// include: [
|
||||
// { relation: 'agencyMode', scope: { fields: ['name'] } },
|
||||
// {
|
||||
// relation: 'address',
|
||||
// scope: { fields: ['nickname'] },
|
||||
// },
|
||||
// { relation: 'rows', scope: { fields: ['id'] } },
|
||||
// {
|
||||
// relation: 'client',
|
||||
// scope: {
|
||||
// fields: [
|
||||
// 'salesPersonFk',
|
||||
// 'name',
|
||||
// 'isActive',
|
||||
// 'isFreezed',
|
||||
// 'isTaxDataChecked',
|
||||
// ],
|
||||
// include: {
|
||||
// relation: 'salesPersonUser',
|
||||
// scope: { fields: ['id', 'name'] },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// ],
|
||||
// };
|
||||
|
||||
const onClientChange = async (clientId = $props.clientFk) => {
|
||||
try {
|
||||
const { data } = await axios.get(`Clients/${clientId}`);
|
||||
await fetchAddressList(data.defaultAddressFk);
|
||||
} catch (error) {
|
||||
console.error('Error al cambiar el cliente:', error);
|
||||
}
|
||||
};
|
||||
|
||||
async function onDataSaved(_, id) {
|
||||
await router.push({ path: `/order/${id}/catalog` });
|
||||
}
|
||||
onMounted(async () => {
|
||||
await onClientChange();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<FetchData
|
||||
url="addresses"
|
||||
@on-fetch="(data) => (clientOptions = data)"
|
||||
:filter="{ fields: ['id', 'name', 'defaultAddressFk'], order: 'id' }"
|
||||
auto-load
|
||||
/>
|
||||
<FormModelPopup
|
||||
url-create="Orders/new"
|
||||
:title="t('Create Order')"
|
||||
@on-data-saved="onDataSaved"
|
||||
:model="ORDER_MODEL"
|
||||
:filter="orderFilter"
|
||||
:form-initial-data="initialFormState"
|
||||
>
|
||||
<template #form-inputs="{ data }">
|
||||
<VnRow class="row q-gutter-md q-mb-md">
|
||||
<VnSelect
|
||||
url="Clients"
|
||||
:label="t('order.form.clientFk')"
|
||||
v-model="data.clientFk"
|
||||
option-value="id"
|
||||
option-label="name"
|
||||
:filter="{
|
||||
fields: ['id', 'name', 'defaultAddressFk'],
|
||||
}"
|
||||
hide-selected
|
||||
@update:model-value="onClientChange"
|
||||
>
|
||||
<template #option="scope">
|
||||
<QItem v-bind="scope.itemProps">
|
||||
<QItemSection>
|
||||
<QItemLabel>
|
||||
{{ `${scope.opt.id}: ${scope.opt.name}` }}
|
||||
</QItemLabel>
|
||||
</QItemSection>
|
||||
</QItem>
|
||||
</template>
|
||||
</VnSelect>
|
||||
<VnSelect
|
||||
:label="t('order.form.addressFk')"
|
||||
v-model="data.addressId"
|
||||
:options="addressList"
|
||||
option-value="id"
|
||||
option-label="street"
|
||||
hide-selected
|
||||
:disable="!addressList?.length"
|
||||
>
|
||||
<template #option="scope">
|
||||
<QItem v-bind="scope.itemProps">
|
||||
<QItemSection>
|
||||
<QItemLabel>
|
||||
{{
|
||||
`${scope.opt.nickname}: ${scope.opt.street},${scope.opt.city}`
|
||||
}}
|
||||
</QItemLabel>
|
||||
</QItemSection>
|
||||
</QItem>
|
||||
</template>
|
||||
</VnSelect>
|
||||
</VnRow>
|
||||
<VnRow class="row q-gutter-md q-mb-md">
|
||||
<VnInputDate
|
||||
placeholder="dd-mm-aaa"
|
||||
:label="t('order.form.landed')"
|
||||
v-model="data.landed"
|
||||
@update:model-value="
|
||||
() => fetchAgencyList(data.landed, data.addressId)
|
||||
"
|
||||
/>
|
||||
</VnRow>
|
||||
<VnRow class="row q-gutter-md q-mb-md">
|
||||
<VnSelect
|
||||
:label="t('order.form.agencyModeFk')"
|
||||
v-model="data.agencyModeId"
|
||||
:options="agencyList"
|
||||
option-value="agencyModeFk"
|
||||
option-label="agencyMode"
|
||||
hide-selected
|
||||
:disable="!agencyList?.length"
|
||||
>
|
||||
</VnSelect>
|
||||
</VnRow>
|
||||
</template>
|
||||
</FormModelPopup>
|
||||
</template>
|
||||
|
||||
<i18n>
|
||||
es:
|
||||
No default address found for the client: No hay ninguna dirección asociada a este cliente.
|
||||
</i18n>
|
Loading…
Reference in New Issue