Merge branch 'dev' into feature/ZoneWarehouses
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Javier Segarra 2024-05-20 08:40:27 +02:00
commit c40f322a8f
12 changed files with 834 additions and 21 deletions

View File

@ -22,6 +22,10 @@ const $props = defineProps({
type: String,
default: '',
},
optionFilter: {
type: String,
default: null,
},
url: {
type: String,
default: '',
@ -59,7 +63,7 @@ const $props = defineProps({
const { t } = useI18n();
const requiredFieldRule = (val) => val ?? t('globals.fieldRequired');
const { optionLabel, optionValue, options, modelValue } = toRefs($props);
const { optionLabel, optionValue, optionFilter, options, modelValue } = toRefs($props);
const myOptions = ref([]);
const myOptionsOriginal = ref([]);
const vnSelectRef = ref();
@ -109,9 +113,9 @@ async function fetchFilter(val) {
const { fields, sortBy, limit } = $props;
let key = optionLabel.value;
if (new RegExp(/\d/g).test(val)) key = optionValue.value;
if (new RegExp(/\d/g).test(val)) key = optionFilter.value ?? optionValue.value;
const where = { [key]: { like: `%${val}%` } };
const where = { ...{ [key]: { like: `%${val}%` } }, ...$props.where };
return dataRef.value.fetch({ fields, where, order: sortBy, limit });
}

View File

@ -108,7 +108,7 @@ const containerClasses = computed(() => {
font-size: 13px;
&:hover {
background-color: var(--vn-accent-color);
background-color: var(--vn-label-color);
cursor: pointer;
}
}

View File

@ -130,7 +130,8 @@ export function useArrayData(key, userOptions) {
store.filter = {};
if (params) store.userParams = Object.assign({}, params);
await fetch({ append: false });
const response = await fetch({ append: false });
return response;
}
async function addFilter({ filter, params }) {

View File

@ -13,6 +13,7 @@ import VnLinkPhone from 'src/components/ui/VnLinkPhone.vue';
import { getUrl } from 'src/composables/getUrl';
import VnUserLink from 'src/components/ui/VnUserLink.vue';
import VnTitle from 'src/components/common/VnTitle.vue';
import ItemDescriptorProxy from 'src/pages/Item/Card/ItemDescriptorProxy.vue';
const route = useRoute();
const router = useRouter();
@ -262,9 +263,12 @@ async function changeState(value) {
:url="ticketUrl + 'sale'"
:text="t('ticket.summary.saleLines')"
/>
<QTable :rows="ticket.sales">
<QTable :rows="ticket.sales" style="text-align: center">
<template #body-cell="{ value }">
<QTd>{{ value }}</QTd>
</template>
<template #header="props">
<QTr :props="props">
<QTr class="tr-header" :props="props">
<QTh auto-width></QTh>
<QTh auto-width>{{ t('ticket.summary.item') }}</QTh>
<QTh auto-width>{{ t('ticket.summary.visible') }}</QTh>
@ -360,23 +364,29 @@ async function changeState(value) {
</QTooltip>
</QIcon>
</QTd>
<QTd class="link">{{ props.row.itemFk }}</QTd>
<QTd>
<QBtn class="link" flat>
{{ props.row.itemFk }}
<ItemDescriptorProxy :id="props.row.itemFk" />
</QBtn>
</QTd>
<QTd>{{ props.row.visible }}</QTd>
<QTd>{{ props.row.available }}</QTd>
<QTd>{{ props.row.quantity }}</QTd>
<QTd>
<div class="fetched-tags">
<span>{{ props.row.item.name }}</span>
<span v-if="props.row.item.subName" class="subName">{{
props.row.item.subName
}}</span>
<QTd class="description-cell">
<div class="row full-width justify-between">
{{ props.row.item.name }}
<div v-if="props.row.item.subName" class="subName">
{{ props.row.item.subName.toUpperCase() }}
</div>
</div>
<fetched-tags
<FetchedTags
class="fetched-tags"
:item="props.row.item"
:max-length="5"
></fetched-tags>
></FetchedTags>
</QTd>
<QTd>{{ props.row.price }}</QTd>
<QTd>{{ props.row.price }} </QTd>
<QTd>{{ props.row.discount }} %</QTd>
<QTd
>{{
@ -453,4 +463,28 @@ async function changeState(value) {
padding: 1%;
}
}
.q-table {
tr,
th,
.q-td {
border-bottom: 1px solid black;
}
}
.subName {
margin-left: 10%;
}
.tr-header,
.subName {
color: var(--vn-label-color);
}
.description-cell {
width: 25%;
}
.fetched-tags {
max-width: 70%;
}
</style>

View File

@ -0,0 +1,112 @@
<script setup>
import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router';
import { computed } from 'vue';
import { toCurrency } from 'src/filters';
import ZoneSummary from 'src/pages/Zone/Card/ZoneSummary.vue';
import { useSummaryDialog } from 'src/composables/useSummaryDialog';
import { toTimeFormat } from 'filters/date.js';
const { t } = useI18n();
const router = useRouter();
const { viewSummary } = useSummaryDialog();
defineProps({
rows: {
type: Array,
required: true,
default: () => [],
},
});
const columns = computed(() => [
{
label: t('zoneClosingTable.id'),
name: 'id',
field: 'id',
sortable: true,
align: 'left',
},
{
label: t('zoneClosingTable.name'),
name: 'name',
field: 'name',
sortable: true,
align: 'left',
},
{
label: t('zoneClosingTable.agency'),
name: 'agency',
field: 'agencyModeName',
sortable: true,
align: 'left',
},
{
label: t('zoneClosingTable.closing'),
name: 'close',
field: 'hour',
sortable: true,
align: 'left',
format: (val) => toTimeFormat(val),
},
{
label: t('zoneClosingTable.price'),
name: 'price',
field: 'price',
sortable: true,
align: 'left',
format: (val) => toCurrency(val),
},
{
name: 'actions',
align: 'left',
},
]);
const redirectToZoneSummary = (id) => {
router.push({ name: 'ZoneSummary', params: { id } });
};
</script>
<template>
<div>
<div class="header">
<span>{{ t('zoneClosingTable.zones') }}</span>
</div>
<QTable
:rows="rows"
:columns="columns"
@row-click="(_, row) => redirectToZoneSummary(row.id)"
style="max-height: 400px"
>
<template #body-cell-actions="props">
<QTd :props="props">
<div class="table-actions">
<QIcon
name="preview"
size="sm"
color="primary"
@click.stop="viewSummary(props.row.id, ZoneSummary)"
>
<QTooltip>{{ t('zoneClosingTable.preview') }}</QTooltip>
</QIcon>
</div>
</QTd>
</template>
</QTable>
</div>
</template>
<style scoped lang="scss">
.header {
width: 100%;
height: 34px;
display: flex;
justify-content: center;
align-items: center;
font-weight: bold;
background-color: $primary;
}
</style>

View File

@ -0,0 +1,192 @@
<script setup>
import { ref, computed } from 'vue';
import { useI18n } from 'vue-i18n';
import { date } from 'quasar';
import ZoneClosingTable from './ZoneClosingTable.vue';
import QCalendarMonthWrapper from 'src/components/ui/QCalendarMonthWrapper.vue';
import { QCalendarMonth } from '@quasar/quasar-ui-qcalendar/src/index.js';
import '@quasar/quasar-ui-qcalendar/src/QCalendarVariables.sass';
import { useWeekdayStore } from 'src/stores/useWeekdayStore';
import axios from 'axios';
const props = defineProps({
year: {
type: Number,
required: true,
},
month: {
type: Number,
required: true,
},
monthDate: {
type: Object,
default: null,
},
geoExclusions: {
type: Object,
default: () => {},
},
exclusions: {
type: Object,
default: () => {},
},
daysMap: {
type: Object,
default: null,
},
});
const { locale } = useI18n();
const calendarRef = ref(null);
const weekdayStore = useWeekdayStore();
const showZoneClosingTable = ref(false);
const zoneClosingData = ref(null);
const today = ref(date.formatDate(Date.vnNew(), 'YYYY-MM-DD'));
const todayTimestamp = computed(() => {
const date = Date.vnNew();
date.setHours(0, 0, 0, 0);
return date.getTime();
});
const _monthDate = computed(() => date.formatDate(props.monthDate, 'YYYY-MM-DD'));
const onEventSelection = async ({ year, month, day }) => {
const date = new Date(year, month - 1, day);
const stamp = date.getTime();
const events = props.daysMap[stamp];
if (!events) return;
const zoneIds = [];
for (let event of events) zoneIds.push(event.zoneFk);
const params = {
zoneIds: zoneIds,
date: date,
};
const { data } = await axios.post('Zones/getZoneClosing', params);
zoneClosingData.value = data;
showZoneClosingTable.value = true;
};
const getEventByTimestamp = ({ year, month, day }) => {
const stamp = new Date(year, month - 1, day).getTime();
return (
props.daysMap[stamp] ||
props.exclusions[stamp] ||
props.geoExclusions[stamp] ||
null
);
};
const getEventAttrs = ({ year, month, day }) => {
const stamp = new Date(year, month - 1, day).getTime();
let colorClass = '--event';
if (props.geoExclusions[stamp]) colorClass = '--geoExcluded';
else if (props.exclusions[stamp]) colorClass = '--excluded';
const attrs = {
class: colorClass,
label: day,
};
return attrs;
};
const isToday = (timestamp) => {
const { year, month, day } = timestamp;
return todayTimestamp.value === new Date(year, month - 1, day).getTime();
};
const calendarHeaderTitle = computed(() => {
return `${weekdayStore.getLocaleMonths[props.month - 1].locale} ${props.year}`;
});
</script>
<template>
<QCalendarMonthWrapper
style="height: 290px; width: 290px"
transparent-background
view-customization="workerCalendar"
>
<template #header>
<span class="full-width text-center text-body1 q-py-sm">{{
calendarHeaderTitle
}}</span>
</template>
<template #calendar>
<QCalendarMonth
ref="calendarRef"
:model-value="_monthDate"
show-work-weeks
no-outside-days
no-active-date
:weekdays="[1, 2, 3, 4, 5, 6, 0]"
short-weekday-label
:locale="locale"
:now="today"
mini-mode
>
<template #day="{ scope: { timestamp } }">
<!-- Este slot representa cada día del calendario y muestra un botón representando el correspondiente evento -->
<QBtn
v-if="getEventByTimestamp(timestamp)"
v-bind="{ ...getEventAttrs(timestamp) }"
@click="onEventSelection(timestamp)"
rounded
dense
flat
class="calendar-event"
:class="{
'--today': isToday(timestamp),
}"
>
<QPopupProxy>
<ZoneClosingTable
v-if="zoneClosingData && zoneClosingData.length"
:rows="zoneClosingData"
/>
</QPopupProxy>
</QBtn>
</template>
</QCalendarMonth>
</template>
</QCalendarMonthWrapper>
</template>
<style lang="scss">
.calendar-event {
display: flex;
justify-content: center;
width: 32px;
height: 32px;
font-size: 13px;
line-height: 1.715em;
cursor: pointer;
color: white;
&.--today {
border: 2px solid $info;
}
&.--event {
background-color: $positive;
color: black;
}
&.--excluded {
background-color: $negative;
}
&.--geoExcluded {
background-color: $primary;
}
&:hover {
opacity: 0.8;
}
}
</style>

View File

@ -1 +1,257 @@
<template>Zone Delivery days</template>
<script setup>
import { computed, onMounted, ref, watch, onUnmounted } from 'vue';
import { useI18n } from 'vue-i18n';
import ZoneDeliveryPanel from './ZoneDeliveryPanel.vue';
import ZoneDeliveryCalendar from './ZoneDeliveryCalendar.vue';
import { useStateStore } from 'stores/useStateStore';
import { useWeekdayStore } from 'src/stores/useWeekdayStore';
import { useArrayData } from 'src/composables/useArrayData';
const { t } = useI18n();
const stateStore = useStateStore();
const weekdayStore = useWeekdayStore();
const nMonths = ref(4);
const _date = ref(Date.vnNew());
const _data = ref(null);
const firstDay = ref(null);
const lastDay = ref(null);
const months = ref([]);
const days = ref({});
const exclusions = ref({});
const geoExclusions = ref({});
const events = ref([]);
const arrayData = useArrayData('ZoneDeliveryDays', {
url: 'Zones/getEvents',
});
const { store } = arrayData;
const refreshEvents = () => {
days.value = {};
if (!data.value) return;
let day = new Date(firstDay.value.getTime());
while (day <= lastDay.value) {
let stamp = day.getTime();
let wday = day.getDay();
let dayEvents = [];
let _exclusions = exclusions.value[stamp] || [];
if (events.value) {
for (let event of events.value) {
let match;
switch (event.type) {
case 'day':
match = event.dated == stamp;
break;
default:
match =
event.wdays[wday] &&
(!event.started || stamp >= event.started) &&
(!event.ended || stamp <= event.ended);
break;
}
if (match && !_exclusions.find((e) => e.zoneFk == event.zoneFk)) {
dayEvents.push(event);
}
}
}
if (dayEvents.length) days.value[stamp] = dayEvents;
day.setDate(day.getDate() + 1);
}
};
const date = computed({
get: () => _date.value,
set: (value) => {
_date.value = value;
let stamp = value.getTime();
firstDay.value = new Date(stamp);
firstDay.value.setDate(1);
lastDay.value = new Date(stamp);
lastDay.value.setMonth(lastDay.value.getMonth() + nMonths.value);
lastDay.value.setDate(0);
months.value = [];
for (let i = 0; i < nMonths.value; i++) {
let monthDate = new Date(stamp);
monthDate.setMonth(value.getMonth() + i);
months.value.push(monthDate);
}
refreshEvents();
},
});
const data = computed({
get: () => {
return _data.value;
},
set: (value) => {
_data.value = value;
value = value || {};
events.value = value.events;
function toStamp(date) {
return date && new Date(date).setHours(0, 0, 0, 0);
}
exclusions.value = {};
let _exclusions = value.exclusions;
if (_exclusions) {
for (let exclusion of _exclusions) {
let stamp = toStamp(exclusion.dated);
if (!exclusions[stamp]) exclusions.value[stamp] = [];
exclusions.value[stamp].push(exclusion);
}
}
geoExclusions.value = {};
let _geoExclusions = value.geoExclusions;
if (_geoExclusions) {
for (let geoExclusion of _geoExclusions) {
let stamp = toStamp(geoExclusion.dated);
if (!geoExclusions[stamp]) geoExclusions.value[stamp] = [];
geoExclusions.value[stamp].push(geoExclusion);
}
}
let _events = value.events;
if (_events) {
for (let event of _events) {
event.dated = toStamp(event.dated);
event.ended = toStamp(event.ended);
event.started = toStamp(event.started);
event.wdays = weekdayStore.fromSet(event.weekDays || '');
}
}
refreshEvents();
},
});
watch(
() => store.data,
(value) => {
data.value = value;
},
{ immediate: true }
);
const getMonthNameAndYear = (date) => {
const monthName = weekdayStore.getLocaleMonths[date.getMonth()].locale;
const year = date.getFullYear();
return `${monthName} ${year}`;
};
const headerTitle = computed(() => {
if (!months.value?.length) return;
const firstMonth = getMonthNameAndYear(months.value[0]);
const lastMonth = getMonthNameAndYear(months.value[months.value.length - 1]);
return `${firstMonth} - ${lastMonth}`;
});
const step = (direction) => {
const _date = new Date(date.value);
_date.setMonth(_date.getMonth() + nMonths.value * direction);
date.value = _date;
};
onMounted(async () => {
stateStore.rightDrawer = true;
let initialDate = Date.vnNew();
initialDate.setDate(1);
initialDate.setHours(0, 0, 0, 0);
date.value = initialDate;
weekdayStore.initStore();
});
onUnmounted(() => arrayData.destroy());
</script>
<template>
<template v-if="stateStore.isHeaderMounted()">
<Teleport to="#actions-append">
<div class="row q-gutter-x-sm">
<QBtn
flat
@click="stateStore.toggleRightDrawer()"
round
dense
icon="menu"
>
<QTooltip bottom anchor="bottom right">
{{ t('globals.collapseMenu') }}
</QTooltip>
</QBtn>
</div>
</Teleport>
</template>
<QDrawer v-model="stateStore.rightDrawer" side="right" :width="256" show-if-above>
<QScrollArea class="fit text-grey-8">
<ZoneDeliveryPanel />
</QScrollArea>
</QDrawer>
<QPage class="q-pa-md flex justify-center">
<QCard style="height: max-content">
<div class="calendars-header">
<QBtn
icon="arrow_left"
size="sm"
flat
class="full-height"
@click="step(-1)"
/>
<span>{{ headerTitle }}</span>
<QBtn
icon="arrow_right"
size="sm"
flat
class="full-height"
@click="step(1)"
/>
</div>
<div class="calendars-container">
<ZoneDeliveryCalendar
v-for="(month, index) in months"
:key="index"
:month="month.getMonth() + 1"
:year="month.getFullYear()"
:month-date="month"
:geo-exclusions="geoExclusions"
:exclusions="exclusions"
:days-map="days"
/>
</div>
</QCard>
</QPage>
</template>
<style lang="scss" scoped>
.calendars-header {
height: 45px;
display: flex;
justify-content: space-between;
align-items: center;
background-color: $primary;
font-weight: bold;
font-size: 16px;
}
.calendars-container {
max-width: 800px;
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
}
</style>

View File

@ -0,0 +1,149 @@
<script setup>
import { onMounted, ref, reactive } from 'vue';
import { useI18n } from 'vue-i18n';
import FetchData from 'components/FetchData.vue';
import VnSelect from 'src/components/common/VnSelect.vue';
import { useArrayData } from 'src/composables/useArrayData';
import axios from 'axios';
import useNotify from 'src/composables/useNotify.js';
import { watch } from 'vue';
const { t } = useI18n();
const { notify } = useNotify();
const deliveryMethodFk = ref(null);
const deliveryMethods = ref([]);
const formData = reactive({});
const arrayData = useArrayData('ZoneDeliveryDays', {
url: 'Zones/getEvents',
});
const fetchDeliveryMethods = async (filter) => {
try {
const params = { filter: JSON.stringify(filter) };
const { data } = await axios.get('DeliveryMethods', { params });
return data.map((deliveryMethod) => deliveryMethod.id);
} catch (err) {
console.error('Error fetching delivery methods: ', err);
}
};
watch(
() => deliveryMethodFk.value,
async (val) => {
let filter;
if (val === 'pickUp') filter = { where: { code: 'PICKUP' } };
else filter = { where: { code: { inq: ['DELIVERY', 'AGENCY'] } } };
deliveryMethods.value = await fetchDeliveryMethods(filter);
},
{ immediate: true }
);
const fetchData = async (params) => {
try {
const { data } = params
? await arrayData.applyFilter({
params,
})
: await arrayData.fetch({ append: false });
if (!data.events || !data.events.length)
notify(t('deliveryPanel.noEventsWarning'), 'warning');
} catch (err) {
console.error('Error fetching events: ', err);
}
};
const onSubmit = async () => {
const params = { deliveryMethodFk: deliveryMethodFk.value, ...formData };
await fetchData(params);
};
onMounted(async () => {
deliveryMethodFk.value = 'delivery';
formData.geoFk = arrayData.store?.userParams?.geoFk;
formData.agencyModeFk = arrayData.store?.userParams?.agencyModeFk;
if (formData.geoFk || formData.agencyModeFk) await fetchData();
});
</script>
<template>
<QForm @submit="onSubmit()" class="q-pa-md">
<div class="column q-gutter-y-sm">
<QRadio
v-model="deliveryMethodFk"
dense
val="pickUp"
:label="t('deliveryPanel.pickup')"
/>
<QRadio
v-model="deliveryMethodFk"
dense
val="delivery"
:label="t('deliveryPanel.delivery')"
class="q-mb-sm"
/>
<VnSelect
v-if="deliveryMethodFk === 'delivery'"
:label="t('deliveryPanel.postcode')"
v-model="formData.geoFk"
url="Postcodes/location"
:fields="['geoFk', 'code', 'townFk']"
sort-by="code, townFk"
option-value="geoFk"
option-label="code"
option-filter="code"
hide-selected
dense
outlined
rounded
>
<template #option="{ itemProps, opt }">
<QItem v-bind="itemProps">
<QItemSection v-if="opt.code">
<QItemLabel>{{ opt.code }}</QItemLabel>
<QItemLabel caption
>{{ opt.town?.province?.name }},
{{ opt.town?.province?.country?.country }}</QItemLabel
>
</QItemSection>
</QItem>
</template>
</VnSelect>
<VnSelect
:label="
t(
deliveryMethodFk === 'delivery'
? 'deliveryPanel.agency'
: 'deliveryPanel.warehouse'
)
"
v-model="formData.agencyModeFk"
url="AgencyModes/isActive"
:fields="['id', 'name']"
:where="{
deliveryMethodFk: { inq: deliveryMethods },
}"
sort-by="name ASC"
option-value="id"
option-label="name"
hide-selected
dense
outlined
rounded
/>
</div>
<QBtn
:label="t('deliveryPanel.query')"
type="submit"
color="primary"
class="q-mt-md full-width"
unelevated
rounded
dense
/>
</QForm>
</template>

View File

@ -4,7 +4,7 @@ zone:
zonesList: Zones
zoneCreate: Create zone
locations: Locations
deliveryList: Delivery days
deliveryDays: Delivery days
upcomingList: Upcoming deliveries
warehouses: Warehouses
list:
@ -42,6 +42,22 @@ summary:
filterPanel:
name: Name
agencyModeFk: Agency
deliveryPanel:
pickup: Pick up
delivery: Delivery
postcode: Postcode
agency: Agency
warehouse: Warehouse
query: Query
noEventsWarning: No service for the specified zone
zoneClosingTable:
id: Id
name: Name
agency: Agency
closing: Closing
price: Price
preview: Preview
zones: Zones
warehouses:
delete: Delete
deleteTitle: This item will be deleted

View File

@ -4,7 +4,7 @@ zone:
zonesList: Zonas
zoneCreate: Nueva zona
locations: Localizaciones
deliveryList: Días de entrega
deliveryDays: Días de entrega
upcomingList: Próximos repartos
warehouses: Almacenes
list:
@ -42,6 +42,24 @@ summary:
filterPanel:
name: Nombre
agencyModeFk: Agencia
deliveryPanel:
pickup: Recogida
delivery: Entrega
postcode: Código postal
agency: Agencia
warehouse: Almacén
query: Consultar
noEventsWarning: No hay servicio para la zona especificada
zoneClosingTable:
id: Id
name: Nombre
agency: Agencia
closing: Cierre
preview: Vista previa
price: Precio
zones: Zonas
Search zones: Buscar zonas
You can search by zone reference: Puedes buscar por referencia de la zona
warehouses:
delete: Eliminar
deleteTitle: Este elemento será eliminado

View File

@ -11,7 +11,7 @@ export default {
component: RouterView,
redirect: { name: 'ZoneMain' },
menus: {
main: ['ZoneList', 'ZoneDeliveryList', 'ZoneUpcomingList'],
main: ['ZoneList', 'ZoneDeliveryDays', 'ZoneUpcomingList'],
card: ['ZoneBasicData', 'ZoneWarehouses', 'ZoneHistory', 'ZoneLocations'],
},
children: [
@ -30,6 +30,15 @@ export default {
},
component: () => import('src/pages/Zone/ZoneList.vue'),
},
{
path: 'delivery-days',
name: 'ZoneDeliveryDays',
meta: {
title: 'deliveryDays',
icon: 'vn:calendar',
},
component: () => import('src/pages/Zone/ZoneDeliveryDays.vue'),
},
{
path: 'create',
name: 'ZoneCreate',

View File

@ -85,6 +85,27 @@ export const useWeekdayStore = defineStore('weekdayStore', () => {
return locales;
});
/**
* Transforms weekday set into an array whose indexes are weekday index
* with selected days set to %true.
*
* @param {String} weekDays Weekday codes separated by commas
* @return {Array<Boolean>} Array with selected days set to %true
*/
const fromSet = (_weekDays) => {
let wdays = [];
if (_weekDays) {
let codes = _weekDays.split(',');
for (let code of codes) {
let data = weekdaysMap[code];
if (data) wdays[data.index] = true;
}
}
return wdays;
};
return {
initStore,
weekdaysMap,
@ -93,5 +114,6 @@ export const useWeekdayStore = defineStore('weekdayStore', () => {
weekdays,
monthCodes,
getLocaleMonths,
fromSet,
};
});