Merge branch 'test' into warmfix_ticketList
gitea/salix-front/pipeline/pr-test There was a failure building this commit Details

This commit is contained in:
Javier Segarra 2025-02-21 08:26:52 +00:00
commit fdf9cfab74
20 changed files with 455 additions and 271 deletions

View File

@ -247,6 +247,7 @@ async function saveAndGo() {
} }
function reset() { function reset() {
formData.value = JSON.parse(JSON.stringify(originalData.value));
updateAndEmit('onFetch', { val: originalData.value }); updateAndEmit('onFetch', { val: originalData.value });
if ($props.observeFormChanges) { if ($props.observeFormChanges) {
hasChanges.value = false; hasChanges.value = false;

View File

@ -1,6 +1,6 @@
<script setup> <script setup>
import { markRaw, computed } from 'vue'; import { markRaw, computed } from 'vue';
import { QIcon, QCheckbox, QToggle } from 'quasar'; import { QIcon, QToggle } from 'quasar';
import { dashIfEmpty } from 'src/filters'; import { dashIfEmpty } from 'src/filters';
import VnSelect from 'components/common/VnSelect.vue'; import VnSelect from 'components/common/VnSelect.vue';

View File

@ -152,7 +152,7 @@ const onTabPressed = async () => {
}; };
</script> </script>
<template> <template>
<div v-if="showFilter" class="full-width flex-center" style="overflow: hidden"> <div v-if="showFilter" class="full-width" style="overflow: hidden">
<VnColumn <VnColumn
:column="$props.column" :column="$props.column"
default="input" default="input"

View File

@ -23,6 +23,10 @@ const $props = defineProps({
type: Boolean, type: Boolean,
default: false, default: false,
}, },
align: {
type: String,
default: 'end',
},
}); });
const hover = ref(); const hover = ref();
const arrayData = useArrayData($props.dataKey, { searchUrl: $props.searchUrl }); const arrayData = useArrayData($props.dataKey, { searchUrl: $props.searchUrl });
@ -46,16 +50,27 @@ async function orderBy(name, direction) {
} }
defineExpose({ orderBy }); defineExpose({ orderBy });
function textAlignToFlex(textAlign) {
return `justify-content: ${
{
'text-center': 'center',
'text-left': 'start',
'text-right': 'end',
}[textAlign] || 'start'
};`;
}
</script> </script>
<template> <template>
<div <div
@mouseenter="hover = true" @mouseenter="hover = true"
@mouseleave="hover = false" @mouseleave="hover = false"
@click="orderBy(name, model?.direction)" @click="orderBy(name, model?.direction)"
class="row items-center no-wrap cursor-pointer title" class="items-center no-wrap cursor-pointer title"
:style="textAlignToFlex(align)"
> >
<span :title="label">{{ label }}</span> <span :title="label">{{ label }}</span>
<sup v-if="name && model?.index"> <div v-if="name && model?.index">
<QChip <QChip
:label="!vertical ? model?.index : ''" :label="!vertical ? model?.index : ''"
:icon=" :icon="
@ -92,20 +107,16 @@ defineExpose({ orderBy });
/> />
</div> </div>
</QChip> </QChip>
</sup> </div>
</div> </div>
</template> </template>
<style lang="scss" scoped> <style lang="scss" scoped>
.title { .title {
display: flex; display: flex;
justify-content: center;
align-items: center; align-items: center;
height: 30px; height: 30px;
width: 100%; width: 100%;
color: var(--vn-label-color); color: var(--vn-label-color);
} white-space: nowrap;
sup {
vertical-align: super; /* Valor predeterminado */
/* También puedes usar otros valores como "baseline", "top", "text-top", etc. */
} }
</style> </style>

View File

@ -10,14 +10,15 @@ import {
render, render,
inject, inject,
useAttrs, useAttrs,
nextTick,
} from 'vue'; } from 'vue';
import { useArrayData } from 'src/composables/useArrayData'; import { useArrayData } from 'src/composables/useArrayData';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
import { useQuasar } from 'quasar'; import { useQuasar, date } from 'quasar';
import { useStateStore } from 'stores/useStateStore'; import { useStateStore } from 'stores/useStateStore';
import { useFilterParams } from 'src/composables/useFilterParams'; import { useFilterParams } from 'src/composables/useFilterParams';
import { dashIfEmpty } from 'src/filters'; import { dashIfEmpty, toDate } from 'src/filters';
import CrudModel from 'src/components/CrudModel.vue'; import CrudModel from 'src/components/CrudModel.vue';
import FormModelPopup from 'components/FormModelPopup.vue'; import FormModelPopup from 'components/FormModelPopup.vue';
@ -345,7 +346,7 @@ const clickHandler = async (event) => {
if (isDateElement || isTimeElement || isQselectDropDown) return; if (isDateElement || isTimeElement || isQselectDropDown) return;
if (clickedElement === null) { if (clickedElement === null) {
destroyInput(editingRow.value, editingField.value); await destroyInput(editingRow.value, editingField.value);
return; return;
} }
const rowIndex = clickedElement.getAttribute('data-row-index'); const rowIndex = clickedElement.getAttribute('data-row-index');
@ -355,7 +356,7 @@ const clickHandler = async (event) => {
if (editingRow.value !== null && editingField.value !== null) { if (editingRow.value !== null && editingField.value !== null) {
if (editingRow.value == rowIndex && editingField.value == colField) return; if (editingRow.value == rowIndex && editingField.value == colField) return;
destroyInput(editingRow.value, editingField.value); await destroyInput(editingRow.value, editingField.value);
} }
if (isEditableColumn(column)) { if (isEditableColumn(column)) {
@ -365,7 +366,7 @@ const clickHandler = async (event) => {
async function handleTabKey(event, rowIndex, colField) { async function handleTabKey(event, rowIndex, colField) {
if (editingRow.value == rowIndex && editingField.value == colField) if (editingRow.value == rowIndex && editingField.value == colField)
destroyInput(editingRow.value, editingField.value); await destroyInput(editingRow.value, editingField.value);
const direction = event.shiftKey ? -1 : 1; const direction = event.shiftKey ? -1 : 1;
const { nextRowIndex, nextColumnName } = await handleTabNavigation( const { nextRowIndex, nextColumnName } = await handleTabNavigation(
@ -425,7 +426,8 @@ async function renderInput(rowId, field, clickedElement) {
await column?.cellEvent?.['update:modelValue']?.(value, oldValue, row); await column?.cellEvent?.['update:modelValue']?.(value, oldValue, row);
}, },
keyup: async (event) => { keyup: async (event) => {
if (event.key === 'Enter') handleBlur(rowId, field, clickedElement); if (event.key === 'Enter')
await destroyInput(rowIndex, field, clickedElement);
}, },
keydown: async (event) => { keydown: async (event) => {
switch (event.key) { switch (event.key) {
@ -434,7 +436,7 @@ async function renderInput(rowId, field, clickedElement) {
event.stopPropagation(); event.stopPropagation();
break; break;
case 'Escape': case 'Escape':
destroyInput(rowId, field, clickedElement); await destroyInput(rowId, field, clickedElement);
break; break;
default: default:
break; break;
@ -456,12 +458,13 @@ async function renderInput(rowId, field, clickedElement) {
node.el?.querySelector('span > div > div').focus(); node.el?.querySelector('span > div > div').focus();
} }
function destroyInput(rowIndex, field, clickedElement) { async function destroyInput(rowIndex, field, clickedElement) {
if (!clickedElement) if (!clickedElement)
clickedElement = document.querySelector( clickedElement = document.querySelector(
`[data-row-index="${rowIndex}"][data-col-field="${field}"]`, `[data-row-index="${rowIndex}"][data-col-field="${field}"]`,
); );
if (clickedElement) { if (clickedElement) {
await nextTick();
render(null, clickedElement); render(null, clickedElement);
Array.from(clickedElement.childNodes).forEach((child) => { Array.from(clickedElement.childNodes).forEach((child) => {
child.style.visibility = 'visible'; child.style.visibility = 'visible';
@ -473,10 +476,6 @@ function destroyInput(rowIndex, field, clickedElement) {
editingField.value = null; editingField.value = null;
} }
function handleBlur(rowIndex, field, clickedElement) {
destroyInput(rowIndex, field, clickedElement);
}
async function handleTabNavigation(rowIndex, colName, direction) { async function handleTabNavigation(rowIndex, colName, direction) {
const columns = $props.columns; const columns = $props.columns;
const totalColumns = columns.length; const totalColumns = columns.length;
@ -521,17 +520,41 @@ function getToggleIcon(value) {
} }
function formatColumnValue(col, row, dashIfEmpty) { function formatColumnValue(col, row, dashIfEmpty) {
if (col?.format) { if (col?.format || row[col?.name + 'TextValue']) {
if (selectRegex.test(col?.component) && row[col?.name + 'TextValue']) { if (selectRegex.test(col?.component) && row[col?.name + 'TextValue']) {
return dashIfEmpty(row[col?.name + 'TextValue']); return dashIfEmpty(row[col?.name + 'TextValue']);
} else { } else {
return col.format(row, dashIfEmpty); return col.format(row, dashIfEmpty);
} }
} else {
return dashIfEmpty(row[col?.name]);
} }
if (col?.component === 'date') return dashIfEmpty(toDate(row[col?.name]));
if (col?.component === 'time')
return row[col?.name] >= 5
? dashIfEmpty(date.formatDate(new Date(row[col?.name]), 'HH:mm'))
: row[col?.name];
if (selectRegex.test(col?.component) && $props.isEditable) {
const { find, url } = col.attrs;
const urlRelation = url?.charAt(0)?.toLocaleLowerCase() + url?.slice(1, -1);
if (col?.attrs.options) {
const find = col?.attrs.options.find((option) => option.id === row[col.name]);
if (!col.attrs?.optionLabel || !find) return dashIfEmpty(row[col?.name]);
return dashIfEmpty(find[col.attrs?.optionLabel ?? 'name']);
}
if (typeof row[urlRelation] == 'object') {
if (typeof find == 'object')
return dashIfEmpty(row[urlRelation][find?.label ?? 'name']);
return dashIfEmpty(row[urlRelation][col?.attrs.optionLabel ?? 'name']);
}
if (typeof row[urlRelation] == 'string') return dashIfEmpty(row[urlRelation]);
}
return dashIfEmpty(row[col?.name]);
} }
const checkbox = ref(null);
function cardClick(_, row) { function cardClick(_, row) {
if ($props.redirect) router.push({ path: `/${$props.redirect}/${row.id}` }); if ($props.redirect) router.push({ path: `/${$props.redirect}/${row.id}` });
} }
@ -633,15 +656,14 @@ function cardClick(_, row) {
v-bind:class="col.headerClass" v-bind:class="col.headerClass"
class="body-cell" class="body-cell"
:style="col?.width ? `max-width: ${col?.width}` : ''" :style="col?.width ? `max-width: ${col?.width}` : ''"
style="padding: inherit"
> >
<div <div
class="no-padding" class="no-padding"
:style=" :style="[
withFilters && $props.columnSearch ? 'height: 75px' : '' withFilters && $props.columnSearch ? 'height: 75px' : '',
" ]"
> >
<div class="text-center" style="height: 30px"> <div style="height: 30px">
<QTooltip v-if="col.toolTip">{{ col.toolTip }}</QTooltip> <QTooltip v-if="col.toolTip">{{ col.toolTip }}</QTooltip>
<VnTableOrder <VnTableOrder
v-model="orders[col.orderBy ?? col.name]" v-model="orders[col.orderBy ?? col.name]"
@ -649,6 +671,7 @@ function cardClick(_, row) {
:label="col?.labelAbbreviation ?? col?.label" :label="col?.labelAbbreviation ?? col?.label"
:data-key="$attrs['data-key']" :data-key="$attrs['data-key']"
:search-url="searchUrl" :search-url="searchUrl"
:align="getColAlign(col)"
/> />
</div> </div>
<VnFilter <VnFilter
@ -730,7 +753,11 @@ function cardClick(_, row) {
<span <span
v-else v-else
:class="hasEditableFormat(col)" :class="hasEditableFormat(col)"
:style="col?.style ? col.style(row) : null" :style="
typeof col?.style == 'function'
? col.style(row)
: col?.style
"
style="bottom: 0" style="bottom: 0"
> >
{{ formatColumnValue(col, row, dashIfEmpty) }} {{ formatColumnValue(col, row, dashIfEmpty) }}
@ -783,7 +810,7 @@ function cardClick(_, row) {
<QCardSection <QCardSection
vertical vertical
class="no-margin no-padding" class="no-margin no-padding"
:class="colsMap.tableActions ? '' : 'fit'" :class="colsMap.tableActions ? 'w-80' : 'fit'"
> >
<!-- Chips --> <!-- Chips -->
<QCardSection <QCardSection
@ -1025,8 +1052,8 @@ es:
} }
.body-cell { .body-cell {
padding-left: 2px !important; padding-left: 4px !important;
padding-right: 2px !important; padding-right: 4px !important;
position: relative; position: relative;
} }
.bg-chip-secondary { .bg-chip-secondary {

View File

@ -48,7 +48,8 @@ function toValueAttrs(attrs) {
<span <span
v-for="toComponent of componentArray" v-for="toComponent of componentArray"
:key="toComponent.name" :key="toComponent.name"
class="column flex-center fit" class="column fit"
:class="toComponent?.component == 'checkbox' ? 'flex-center' : ''"
> >
<component <component
v-if="toComponent?.component" v-if="toComponent?.component"

View File

@ -1,13 +1,14 @@
export function getColAlign(col) { export function getColAlign(col) {
let align; let align;
switch (col.component) { switch (col.component) {
case 'time':
case 'date':
case 'select': case 'select':
align = 'left'; align = 'left';
break; break;
case 'number': case 'number':
align = 'right'; align = 'right';
break; break;
case 'date':
case 'checkbox': case 'checkbox':
align = 'center'; align = 'center';
break; break;

View File

@ -3,6 +3,8 @@ import { useI18n } from 'vue-i18n';
export default function (value, options = {}) { export default function (value, options = {}) {
if (!value) return; if (!value) return;
if (!isValidDate(value)) return null;
if (!options.dateStyle && !options.timeStyle) { if (!options.dateStyle && !options.timeStyle) {
options.day = '2-digit'; options.day = '2-digit';
options.month = '2-digit'; options.month = '2-digit';
@ -10,7 +12,12 @@ export default function (value, options = {}) {
} }
const { locale } = useI18n(); const { locale } = useI18n();
const date = new Date(value); const newDate = new Date(value);
return new Intl.DateTimeFormat(locale.value, options).format(date); return new Intl.DateTimeFormat(locale.value, options).format(newDate);
}
// handle 0000-00-00
function isValidDate(date) {
const parsedDate = new Date(date);
return parsedDate instanceof Date && !isNaN(parsedDate.getTime());
} }

View File

@ -49,6 +49,7 @@ globals:
rowRemoved: Row removed rowRemoved: Row removed
pleaseWait: Please wait... pleaseWait: Please wait...
noPinnedModules: You don't have any pinned modules noPinnedModules: You don't have any pinned modules
enterToConfirm: Press Enter to confirm
summary: summary:
basicData: Basic data basicData: Basic data
daysOnward: Days onward daysOnward: Days onward

View File

@ -51,6 +51,7 @@ globals:
pleaseWait: Por favor espera... pleaseWait: Por favor espera...
noPinnedModules: No has fijado ningún módulo noPinnedModules: No has fijado ningún módulo
split: Split split: Split
enterToConfirm: Pulsa Enter para confirmar
summary: summary:
basicData: Datos básicos basicData: Datos básicos
daysOnward: Días adelante daysOnward: Días adelante

View File

@ -16,7 +16,6 @@ import ItemDescriptor from 'src/pages/Item/Card/ItemDescriptor.vue';
import axios from 'axios'; import axios from 'axios';
import VnSelectEnum from 'src/components/common/VnSelectEnum.vue'; import VnSelectEnum from 'src/components/common/VnSelectEnum.vue';
import { checkEntryLock } from 'src/composables/checkEntryLock'; import { checkEntryLock } from 'src/composables/checkEntryLock';
import SkeletonDescriptor from 'src/components/ui/SkeletonDescriptor.vue';
const $props = defineProps({ const $props = defineProps({
id: { id: {
@ -103,7 +102,7 @@ const columns = [
name: 'itemFk', name: 'itemFk',
component: 'number', component: 'number',
isEditable: false, isEditable: false,
width: '40px', width: '35px',
}, },
{ {
labelAbbreviation: '', labelAbbreviation: '',
@ -111,7 +110,7 @@ const columns = [
name: 'hex', name: 'hex',
columnSearch: false, columnSearch: false,
isEditable: false, isEditable: false,
width: '5px', width: '9px',
component: 'select', component: 'select',
attrs: { attrs: {
url: 'Inks', url: 'Inks',
@ -181,6 +180,7 @@ const columns = [
url: 'packagings', url: 'packagings',
fields: ['id'], fields: ['id'],
optionLabel: 'id', optionLabel: 'id',
optionValue: 'id',
}, },
create: true, create: true,
width: '40px', width: '40px',
@ -192,7 +192,7 @@ const columns = [
component: 'number', component: 'number',
create: true, create: true,
width: '35px', width: '35px',
format: (row, dashIfEmpty) => parseFloat(row['weight']).toFixed(1), format: (row) => parseFloat(row['weight']).toFixed(1),
}, },
{ {
labelAbbreviation: 'P', labelAbbreviation: 'P',
@ -330,6 +330,25 @@ const columns = [
create: true, create: true,
format: (row) => parseFloat(row['price3']).toFixed(2), format: (row) => parseFloat(row['price3']).toFixed(2),
}, },
{
align: 'center',
labelAbbreviation: 'CM',
label: t('Check min price'),
toolTip: t('Check min price'),
name: 'hasMinPrice',
attrs: {
toggleIndeterminate: false,
},
component: 'checkbox',
cellEvent: {
'update:modelValue': async (value, oldValue, row) => {
await axios.patch(`Items/${row['itemFk']}`, {
hasMinPrice: value,
});
},
},
width: '25px',
},
{ {
align: 'center', align: 'center',
labelAbbreviation: 'Min.', labelAbbreviation: 'Min.',
@ -350,25 +369,6 @@ const columns = [
}, },
format: (row) => parseFloat(row['minPrice']).toFixed(2), format: (row) => parseFloat(row['minPrice']).toFixed(2),
}, },
{
align: 'center',
labelAbbreviation: 'CM',
label: t('Check min price'),
toolTip: t('Check min price'),
name: 'hasMinPrice',
attrs: {
toggleIndeterminate: false,
},
component: 'checkbox',
cellEvent: {
'update:modelValue': async (value, oldValue, row) => {
await axios.patch(`Items/${row['itemFk']}`, {
hasMinPrice: value,
});
},
},
width: '25px',
},
{ {
align: 'center', align: 'center',
labelAbbreviation: t('P.Sen'), labelAbbreviation: t('P.Sen'),
@ -378,6 +378,9 @@ const columns = [
component: 'number', component: 'number',
isEditable: false, isEditable: false,
width: '40px', width: '40px',
style: () => {
return { color: 'var(--vn-label-color)' };
},
}, },
{ {
align: 'center', align: 'center',
@ -417,6 +420,9 @@ const columns = [
component: 'input', component: 'input',
isEditable: false, isEditable: false,
width: '35px', width: '35px',
style: () => {
return { color: 'var(--vn-label-color)' };
},
}, },
]; ];
@ -644,8 +650,8 @@ onMounted(() => {
:is-editable="editableMode" :is-editable="editableMode"
:without-header="!editableMode" :without-header="!editableMode"
:with-filters="editableMode" :with-filters="editableMode"
:right-search="false" :right-search="true"
:right-search-icon="false" :right-search-icon="true"
:row-click="false" :row-click="false"
:columns="columns" :columns="columns"
:beforeSaveFn="beforeSave" :beforeSaveFn="beforeSave"

View File

@ -199,7 +199,6 @@ const columns = computed(() => [
optionValue: 'code', optionValue: 'code',
optionLabel: 'description', optionLabel: 'description',
}, },
cardVisible: true,
width: '65px', width: '65px',
format: (row, dashIfEmpty) => dashIfEmpty(row.entryTypeDescription), format: (row, dashIfEmpty) => dashIfEmpty(row.entryTypeDescription),
}, },

View File

@ -57,7 +57,7 @@ const columns = computed(() => [
create: true, create: true,
component: 'number', component: 'number',
summation: true, summation: true,
width: '60px', width: '50px',
}, },
{ {
align: 'center', align: 'center',
@ -286,7 +286,7 @@ function round(value) {
justify-content: center; justify-content: center;
} }
.column { .column {
min-width: 30%; min-width: 40%;
margin-top: 5%; margin-top: 5%;
display: flex; display: flex;
flex-direction: column; flex-direction: column;

View File

@ -101,7 +101,8 @@ const columns = [
</template> </template>
<style lang="css" scoped> <style lang="css" scoped>
.container { .container {
max-width: 50vw; max-width: 100%;
width: 50%;
overflow: auto; overflow: auto;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
@ -109,9 +110,6 @@ const columns = [
background-color: var(--vn-section-color); background-color: var(--vn-section-color);
padding: 2%; padding: 2%;
} }
.container > div > div > .q-table__top.relative-position.row.items-center {
background-color: red !important;
}
</style> </style>
<i18n> <i18n>
es: es:

View File

@ -21,6 +21,10 @@ const $props = defineProps({
type: String, type: String,
default: 'mana', default: 'mana',
}, },
sale: {
type: Object,
default: null,
},
}); });
const emit = defineEmits(['save', 'cancel']); const emit = defineEmits(['save', 'cancel']);
@ -29,8 +33,8 @@ const { t } = useI18n();
const QPopupProxyRef = ref(null); const QPopupProxyRef = ref(null);
const manaCode = ref($props.manaCode); const manaCode = ref($props.manaCode);
const save = () => { const save = (sale = $props.sale) => {
emit('save'); emit('save', sale);
QPopupProxyRef.value.hide(); QPopupProxyRef.value.hide();
}; };
@ -38,10 +42,11 @@ const cancel = () => {
emit('cancel'); emit('cancel');
QPopupProxyRef.value.hide(); QPopupProxyRef.value.hide();
}; };
defineExpose({ save });
</script> </script>
<template> <template>
<QPopupProxy ref="QPopupProxyRef"> <QPopupProxy ref="QPopupProxyRef" data-cy="ticketEditManaProxy">
<div class="container"> <div class="container">
<QSpinner v-if="!mana" color="primary" size="md" /> <QSpinner v-if="!mana" color="primary" size="md" />
<div v-else> <div v-else>

View File

@ -22,7 +22,6 @@ import { useVnConfirm } from 'composables/useVnConfirm';
import useNotify from 'src/composables/useNotify.js'; import useNotify from 'src/composables/useNotify.js';
import axios from 'axios'; import axios from 'axios';
import VnTable from 'src/components/VnTable/VnTable.vue'; import VnTable from 'src/components/VnTable/VnTable.vue';
import VnUsesMana from 'src/components/ui/VnUsesMana.vue';
import VnConfirm from 'src/components/ui/VnConfirm.vue'; import VnConfirm from 'src/components/ui/VnConfirm.vue';
import TicketProblems from 'src/components/TicketProblems.vue'; import TicketProblems from 'src/components/TicketProblems.vue';
import RightMenu from 'src/components/common/RightMenu.vue'; import RightMenu from 'src/components/common/RightMenu.vue';
@ -33,6 +32,7 @@ const { t } = useI18n();
const { notify } = useNotify(); const { notify } = useNotify();
const { openConfirmationModal } = useVnConfirm(); const { openConfirmationModal } = useVnConfirm();
const editPriceProxyRef = ref(null); const editPriceProxyRef = ref(null);
const editManaProxyRef = ref(null);
const stateBtnDropdownRef = ref(null); const stateBtnDropdownRef = ref(null);
const quasar = useQuasar(); const quasar = useQuasar();
const arrayData = useArrayData('Ticket'); const arrayData = useArrayData('Ticket');
@ -53,7 +53,6 @@ const transfer = ref({
sales: [], sales: [],
}); });
const tableRef = ref([]); const tableRef = ref([]);
const canProceed = ref();
watch( watch(
() => route.params.id, () => route.params.id,
@ -133,7 +132,6 @@ const columns = computed(() => [
align: 'left', align: 'left',
label: t('globals.amount'), label: t('globals.amount'),
name: 'amount', name: 'amount',
format: (row) => toCurrency(getSaleTotal(row)),
}, },
{ {
align: 'left', align: 'left',
@ -183,8 +181,6 @@ const resetChanges = async () => {
}; };
const rowToUpdate = ref(null); const rowToUpdate = ref(null);
const changeQuantity = async (sale) => { const changeQuantity = async (sale) => {
canProceed.value = await isSalePrepared(sale);
if (!canProceed.value) return;
if ( if (
!sale.itemFk || !sale.itemFk ||
sale.quantity == null || sale.quantity == null ||
@ -193,11 +189,21 @@ const changeQuantity = async (sale) => {
return; return;
if (!sale.id) return addSale(sale); if (!sale.id) return addSale(sale);
if (await isSalePrepared(sale)) {
await confirmUpdate(() => updateQuantity(sale));
} else await updateQuantity(sale);
};
const updateQuantity = async (sale) => {
try { try {
let { quantity, id } = sale;
if (!rowToUpdate.value) return; if (!rowToUpdate.value) return;
rowToUpdate.value = null; rowToUpdate.value = null;
sale.isNew = false; sale.isNew = false;
await updateQuantity(sale); const params = { quantity: quantity };
await axios.post(`Sales/${id}/updateQuantity`, params);
notify('globals.dataSaved', 'positive');
tableRef.value.reload();
} catch (e) { } catch (e) {
const { quantity } = tableRef.value.CrudModelRef.originalData.find( const { quantity } = tableRef.value.CrudModelRef.originalData.find(
(s) => s.id === sale.id, (s) => s.id === sale.id,
@ -207,12 +213,6 @@ const changeQuantity = async (sale) => {
} }
}; };
const updateQuantity = async ({ quantity, id }) => {
const params = { quantity: quantity };
await axios.post(`Sales/${id}/updateQuantity`, params);
notify('globals.dataSaved', 'positive');
};
const addSale = async (sale) => { const addSale = async (sale) => {
const params = { const params = {
barcode: sale.itemFk, barcode: sale.itemFk,
@ -237,13 +237,17 @@ const addSale = async (sale) => {
sale.isNew = false; sale.isNew = false;
arrayData.fetch({}); arrayData.fetch({});
}; };
const changeConcept = async (sale) => {
if (await isSalePrepared(sale)) {
await confirmUpdate(() => updateConcept(sale));
} else await updateConcept(sale);
};
const updateConcept = async (sale) => { const updateConcept = async (sale) => {
canProceed.value = await isSalePrepared(sale);
if (!canProceed.value) return;
const data = { newConcept: sale.concept }; const data = { newConcept: sale.concept };
await axios.post(`Sales/${sale.id}/updateConcept`, data); await axios.post(`Sales/${sale.id}/updateConcept`, data);
notify('globals.dataSaved', 'positive'); notify('globals.dataSaved', 'positive');
tableRef.value.reload();
}; };
const DEFAULT_EDIT = { const DEFAULT_EDIT = {
@ -295,33 +299,43 @@ const onOpenEditDiscountPopover = async (sale) => {
}; };
} }
}; };
const changePrice = async (sale) => {
const updatePrice = async (sale) => {
canProceed.value = await isSalePrepared(sale);
if (!canProceed.value) return;
const newPrice = edit.value.price; const newPrice = edit.value.price;
if (newPrice != null && newPrice != sale.price) { if (newPrice != null && newPrice != sale.price) {
if (await isSalePrepared(sale)) {
await confirmUpdate(() => updatePrice(sale, newPrice));
} else updatePrice(sale, newPrice);
}
await getMana();
};
const updatePrice = async (sale, newPrice) => {
await axios.post(`Sales/${sale.id}/updatePrice`, { newPrice }); await axios.post(`Sales/${sale.id}/updatePrice`, { newPrice });
sale.price = newPrice; sale.price = newPrice;
edit.value = { ...DEFAULT_EDIT }; edit.value = { ...DEFAULT_EDIT };
notify('globals.dataSaved', 'positive'); notify('globals.dataSaved', 'positive');
} tableRef.value.reload();
await getMana();
}; };
const changeDiscount = async (sale) => { const changeDiscount = async (sale) => {
canProceed.value = await isSalePrepared(sale);
if (!canProceed.value) return;
const newDiscount = edit.value.discount; const newDiscount = edit.value.discount;
if (newDiscount != null && newDiscount != sale.discount) updateDiscount([sale]); if (newDiscount != null && newDiscount != sale.discount) {
if (await isSalePrepared(sale))
await confirmUpdate(() => updateDiscount([sale], newDiscount));
else await updateDiscount([sale], newDiscount);
}
};
const updateDiscounts = async (sales, newDiscount = null) => {
const salesTracking = await fetchSalesTracking();
const someSaleIsPrepared = salesTracking.some((sale) =>
matchSale(salesTracking, sale),
);
if (someSaleIsPrepared) await confirmUpdate(() => updateDiscount(sales, newDiscount));
else updateDiscount(sales, newDiscount);
}; };
const updateDiscount = async (sales, newDiscount = null) => { const updateDiscount = async (sales, newDiscount = null) => {
for (const sale of sales) {
const canProceed = await isSalePrepared(sale);
if (!canProceed) return;
}
const saleIds = sales.map((sale) => sale.id); const saleIds = sales.map((sale) => sale.id);
const _newDiscount = newDiscount || edit.value.discount; const _newDiscount = newDiscount || edit.value.discount;
const params = { const params = {
@ -424,9 +438,13 @@ onMounted(async () => {
const items = ref([]); const items = ref([]);
const newRow = ref({}); const newRow = ref({});
const changeItem = async (sale) => {
if (await isSalePrepared(sale)) {
await confirmUpdate(() => updateItem(sale));
} else await updateItem(sale);
};
const updateItem = async (row) => { const updateItem = async (row) => {
canProceed.value = await isSalePrepared(row);
if (!canProceed.value) return;
const selectedItem = items.value.find((item) => item.id === row.itemFk); const selectedItem = items.value.find((item) => item.id === row.itemFk);
if (selectedItem) { if (selectedItem) {
row.item = selectedItem; row.item = selectedItem;
@ -470,7 +488,18 @@ const endNewRow = (row) => {
} }
}; };
async function isSalePrepared(item) { async function confirmUpdate(cb) {
await quasar
.dialog({
component: VnConfirm,
componentProps: {
title: t('Item prepared'),
message: t('This item is already prepared. Do you want to continue?'),
},
})
.onOk(cb);
}
async function fetchSalesTracking() {
const filter = { const filter = {
params: { params: {
where: { ticketFk: route.params.id }, where: { ticketFk: route.params.id },
@ -482,48 +511,37 @@ async function isSalePrepared(item) {
filter: JSON.stringify(filter), filter: JSON.stringify(filter),
}, },
}); });
return data;
const matchingSale = data.find((sale) => sale.itemFk === item.itemFk);
if (!matchingSale) {
return true;
}
if (
matchingSale.hasSaleGroupDetail ||
matchingSale.isControled ||
matchingSale.isPrepared ||
matchingSale.isPrevious ||
matchingSale.isPreviousSelected
) {
try {
await new Promise((resolve, reject) => {
quasar
.dialog({
component: VnConfirm,
componentProps: {
title: t('Item prepared'),
message: t(
'This item is already prepared. Do you want to continue?',
),
data: item,
},
})
.onOk(() => resolve(true))
.onCancel(() => reject(new Error('cancelled')));
});
} catch (error) {
tableRef.value.reload();
return false;
}
}
return true;
} }
async function isSalePrepared(sale) {
const data = await fetchSalesTracking();
return matchSale(data, sale);
}
function matchSale(data, sale) {
const matchingSale = data.find(({ itemFk }) => itemFk === sale.itemFk);
if (!matchingSale) {
return false;
}
return isPrepared(matchingSale);
}
function isPrepared(sale) {
const flagsToCheck = [
'hasSaleGroupDetail',
'isControled',
'isPrepared',
'isPrevious',
'isPreviousSelected',
];
return flagsToCheck.some((flag) => sale[flag] === 1);
}
watch( watch(
() => newRow.value.itemFk, () => newRow.value.itemFk,
(newItemFk) => { (newItemFk) => {
if (newItemFk) { if (newItemFk) {
updateItem(newRow.value); changeItem(newRow.value);
} }
}, },
); );
@ -584,7 +602,7 @@ watch(
:mana="mana" :mana="mana"
:ticket-config="ticketConfig" :ticket-config="ticketConfig"
@get-mana="getMana()" @get-mana="getMana()"
@update-discounts="updateDiscount" @update-discounts="updateDiscounts"
@refresh-table="resetChanges" @refresh-table="resetChanges"
/> />
<QBtn <QBtn
@ -715,7 +733,7 @@ watch(
option-value="id" option-value="id"
v-model="row.itemFk" v-model="row.itemFk"
:use-like="false" :use-like="false"
@update:model-value="updateItem(row)" @update:model-value="changeItem(row)"
> >
<template #option="scope"> <template #option="scope">
<QItem v-bind="scope.itemProps"> <QItem v-bind="scope.itemProps">
@ -741,16 +759,21 @@ watch(
</div> </div>
<FetchedTags :item="row" :max-length="6" /> <FetchedTags :item="row" :max-length="6" />
<QPopupProxy v-if="row.id && isTicketEditable"> <QPopupProxy v-if="row.id && isTicketEditable">
<VnInput v-model="row.concept" @change="updateConcept(row)" /> <VnInput
v-model="row.concept"
@keyup.enter.stop="changeConcept(row)"
:hint="t('globals.enterToConfirm')"
/>
</QPopupProxy> </QPopupProxy>
</template> </template>
<template #column-quantity="{ row }"> <template #column-quantity="{ row }">
<VnInput <VnInput
data-cy="ticketSaleQuantityInput"
v-if="row.isNew || isTicketEditable" v-if="row.isNew || isTicketEditable"
type="number" type="number"
v-model.number="row.quantity" v-model.number="row.quantity"
@blur="changeQuantity(row)" @blur="changeQuantity(row)"
@keyup.enter="changeQuantity(row)" @keyup.enter.stop="changeQuantity(row)"
@update:model-value="() => (rowToUpdate = row)" @update:model-value="() => (rowToUpdate = row)"
@focus="edit.oldQuantity = row.quantity" @focus="edit.oldQuantity = row.quantity"
/> />
@ -764,10 +787,12 @@ watch(
<TicketEditManaProxy <TicketEditManaProxy
ref="editPriceProxyRef" ref="editPriceProxyRef"
:mana="mana" :mana="mana"
:sale="row"
:new-price="getNewPrice" :new-price="getNewPrice"
@save="updatePrice(row)" @save="changePrice"
> >
<VnInput <VnInput
@keyup.enter.stop="() => editManaProxyRef.save(row)"
v-model.number="edit.price" v-model.number="edit.price"
:label="t('basicData.price')" :label="t('basicData.price')"
type="number" type="number"
@ -781,31 +806,30 @@ watch(
<QBtn flat class="link" dense @click="onOpenEditDiscountPopover(row)"> <QBtn flat class="link" dense @click="onOpenEditDiscountPopover(row)">
{{ toPercentage(row.discount / 100) }} {{ toPercentage(row.discount / 100) }}
</QBtn> </QBtn>
<TicketEditManaProxy <TicketEditManaProxy
ref="editManaProxyRef"
:mana="mana" :mana="mana"
:sale="row"
:new-price="getNewPrice" :new-price="getNewPrice"
:uses-mana="usesMana" :uses-mana="usesMana"
:mana-code="manaCode" :mana-code="manaCode"
@save="changeDiscount(row)" @save="changeDiscount"
> >
<template #default="{ popup }">
<VnInput <VnInput
autofocus autofocus
@keyup.enter=" @keyup.enter.stop="() => editManaProxyRef.save(row)"
() => {
changeDiscount(row);
popup.hide();
}
"
v-model.number="edit.discount" v-model.number="edit.discount"
:label="t('ticketSale.discount')" :label="t('ticketSale.discount')"
type="number" type="number"
/> />
</template>
</TicketEditManaProxy> </TicketEditManaProxy>
</template> </template>
<span v-else>{{ toPercentage(row.discount / 100) }}</span> <span v-else>{{ toPercentage(row.discount / 100) }}</span>
</template> </template>
<template #column-amount="{ row }">
{{ toCurrency(getSaleTotal(row)) }}
</template>
</VnTable> </VnTable>
<QPageSticky :offset="[20, 20]" style="z-index: 2"> <QPageSticky :offset="[20, 20]" style="z-index: 2">

View File

@ -209,7 +209,7 @@ const onThermographCreated = async (data) => {
}" }"
sort-by="thermographFk ASC" sort-by="thermographFk ASC"
option-label="thermographFk" option-label="thermographFk"
option-filter-value="id" option-filter-value="thermographFk"
:disable="viewAction === 'edit'" :disable="viewAction === 'edit'"
:tooltip="t('New thermograph')" :tooltip="t('New thermograph')"
:roles-allowed-to-create="['logistic']" :roles-allowed-to-create="['logistic']"

View File

@ -119,7 +119,7 @@ const columns = computed(() => [
:url="`Workers/${entityId}/trainingCourse`" :url="`Workers/${entityId}/trainingCourse`"
:url-create="`Workers/${entityId}/trainingCourse`" :url-create="`Workers/${entityId}/trainingCourse`"
save-url="TrainingCourses/crud" save-url="TrainingCourses/crud"
:filter="courseFilter" :user-filter="courseFilter"
:create="{ :create="{
urlCreate: 'trainingCourses', urlCreate: 'trainingCourses',
title: t('Create training course'), title: t('Create training course'),

View File

@ -3,11 +3,23 @@ import { ref, computed } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import VnTable from 'components/VnTable/VnTable.vue'; import VnTable from 'components/VnTable/VnTable.vue';
import { dashIfEmpty } from 'src/filters';
const tableRef = ref(); const tableRef = ref();
const { t } = useI18n(); const { t } = useI18n();
const route = useRoute(); const route = useRoute();
const entityId = computed(() => route.params.id); const entityId = computed(() => route.params.id);
const centerFilter = {
include: [
{
relation: 'center',
scope: {
fields: ['id', 'name'],
},
},
],
};
const columns = [ const columns = [
{ {
align: 'left', align: 'left',
@ -36,6 +48,9 @@ const columns = [
url: 'medicalCenters', url: 'medicalCenters',
fields: ['id', 'name'], fields: ['id', 'name'],
}, },
format: (row, dashIfEmpty) => {
return dashIfEmpty(row.center?.name);
},
}, },
{ {
align: 'left', align: 'left',
@ -84,6 +99,7 @@ const columns = [
ref="tableRef" ref="tableRef"
data-key="WorkerMedical" data-key="WorkerMedical"
:url="`Workers/${entityId}/medicalReview`" :url="`Workers/${entityId}/medicalReview`"
:user-filter="centerFilter"
save-url="MedicalReviews/crud" save-url="MedicalReviews/crud"
:create="{ :create="{
urlCreate: 'medicalReviews', urlCreate: 'medicalReviews',

View File

@ -1,6 +1,7 @@
/// <reference types="cypress" /> /// <reference types="cypress" />
describe('TicketSale', () => { describe('TicketSale', () => {
describe('Free ticket #31', () => {
beforeEach(() => { beforeEach(() => {
cy.login('developer'); cy.login('developer');
cy.viewport(1920, 1080); cy.viewport(1920, 1080);
@ -119,4 +120,89 @@ describe('TicketSale', () => {
cy.get(firstRow).find('.q-btn:last').click(); cy.get(firstRow).find('.q-btn:last').click();
cy.url().should('match', /\/ticket\/31\/log/); cy.url().should('match', /\/ticket\/31\/log/);
}); });
});
describe('Ticket prepared #23', () => {
beforeEach(() => {
cy.login('developer');
cy.viewport(1920, 1080);
cy.visit('/#/ticket/23/sale');
});
const firstRow = 'tbody > :nth-child(1)';
const selectFirstRow = () => {
cy.waitForElement(firstRow);
cy.get(firstRow).find('.q-checkbox__inner').click();
};
it('update price', () => {
const price = Number((Math.random() * 99 + 1).toFixed(2));
cy.waitForElement(firstRow);
cy.get(':nth-child(10) > .q-btn').click();
cy.waitForElement('[data-cy="ticketEditManaProxy"]');
cy.dataCy('ticketEditManaProxy').should('exist');
cy.waitForElement('[data-cy="Price_input"]');
cy.dataCy('Price_input').clear();
cy.dataCy('Price_input').type(price);
cy.dataCy('saveManaBtn').click();
handleVnConfirm();
cy.get(':nth-child(10) > .q-btn > .q-btn__content').should(
'have.text',
`${price}`,
);
});
it('update dicount', () => {
const discount = Math.floor(Math.random() * 100) + 1;
selectFirstRow();
cy.get(':nth-child(11) > .q-btn').click();
cy.waitForElement('[data-cy="ticketEditManaProxy"]');
cy.dataCy('ticketEditManaProxy').should('exist');
cy.waitForElement('[data-cy="Disc_input"]');
cy.dataCy('Disc_input').clear();
cy.dataCy('Disc_input').type(discount);
cy.dataCy('saveManaBtn').click();
handleVnConfirm();
cy.get(':nth-child(11) > .q-btn > .q-btn__content').should(
'have.text',
`${discount}.00%`,
);
});
it('change concept', () => {
const quantity = Math.floor(Math.random() * 100) + 1;
cy.waitForElement(firstRow);
cy.get(':nth-child(8) > .row').click();
cy.get(
'.q-menu > [data-v-ca3f07a4=""] > .q-field > .q-field__inner > .q-field__control > .q-field__control-container > [data-cy="undefined_input"]',
)
.type(quantity)
.type('{enter}');
handleVnConfirm();
cy.get(':nth-child(8) >.row').should('contain.text', `${quantity}`);
});
it('changequantity ', () => {
const quantity = Math.floor(Math.random() * 100) + 1;
cy.waitForElement(firstRow);
cy.dataCy('ticketSaleQuantityInput').clear();
cy.dataCy('ticketSaleQuantityInput').type(quantity).trigger('tab');
cy.get('.q-page > :nth-child(6)').click();
handleVnConfirm();
cy.get('[data-cy="ticketSaleQuantityInput"]')
.find('[data-cy="undefined_input"]')
.should('have.value', `${quantity}`);
});
});
}); });
function handleVnConfirm() {
cy.get('[data-cy="VnConfirm_confirm"] > .q-btn__content > .block').click();
cy.waitForElement('.q-notification__message');
cy.get('.q-notification__message').should('be.visible');
cy.checkNotification('Data saved');
}