#6696 - mana #1052
36
package.json
36
package.json
|
@ -22,36 +22,36 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@quasar/cli": "^2.3.0",
|
"@quasar/cli": "^2.3.0",
|
||||||
"@quasar/extras": "^1.16.9",
|
"@quasar/extras": "^1.16.9",
|
||||||
"axios": "^1.4.0",
|
"axios": "^1.6.7",
|
||||||
"chromium": "^3.0.3",
|
"chromium": "^3.0.3",
|
||||||
"croppie": "^2.6.5",
|
"croppie": "^2.6.5",
|
||||||
"pinia": "^2.1.3",
|
"pinia": "^2.1.7",
|
||||||
"quasar": "^2.14.5",
|
"quasar": "^2.14.5",
|
||||||
"validator": "^13.9.0",
|
"validator": "^13.11.0",
|
||||||
"vue": "^3.3.4",
|
"vue": "^3.4.19",
|
||||||
"vue-i18n": "^9.2.2",
|
"vue-i18n": "^9.9.1",
|
||||||
"vue-router": "^4.2.1"
|
"vue-router": "^4.2.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@commitlint/cli": "^19.2.1",
|
"@commitlint/cli": "^19.4.0",
|
||||||
"@commitlint/config-conventional": "^19.1.0",
|
"@commitlint/config-conventional": "^19.2.2",
|
||||||
"@intlify/unplugin-vue-i18n": "^0.8.1",
|
"@intlify/unplugin-vue-i18n": "^0.8.2",
|
||||||
"@pinia/testing": "^0.1.2",
|
"@pinia/testing": "^0.1.3",
|
||||||
"@quasar/app-vite": "^1.7.3",
|
"@quasar/app-vite": "^1.7.3",
|
||||||
"@quasar/quasar-app-extension-qcalendar": "4.0.0-beta.15",
|
"@quasar/quasar-app-extension-qcalendar": "4.0.0-beta.15",
|
||||||
"@quasar/quasar-app-extension-testing-unit-vitest": "^0.4.0",
|
"@quasar/quasar-app-extension-testing-unit-vitest": "^0.4.0",
|
||||||
"@vue/test-utils": "^2.4.4",
|
"@vue/test-utils": "^2.4.4",
|
||||||
"autoprefixer": "^10.4.14",
|
"autoprefixer": "^10.4.17",
|
||||||
"cypress": "^13.6.6",
|
"cypress": "^13.6.6",
|
||||||
"cypress-mochawesome-reporter": "^3.8.2",
|
"cypress-mochawesome-reporter": "^3.8.2",
|
||||||
"eslint": "^8.41.0",
|
"eslint": "^8.56.0",
|
||||||
"eslint-config-prettier": "^8.8.0",
|
"eslint-config-prettier": "^8.10.0",
|
||||||
"eslint-plugin-cypress": "^2.13.3",
|
"eslint-plugin-cypress": "^2.15.1",
|
||||||
"eslint-plugin-vue": "^9.14.1",
|
"eslint-plugin-vue": "^9.21.1",
|
||||||
"husky": "^8.0.0",
|
"husky": "^8.0.3",
|
||||||
"postcss": "^8.4.23",
|
"postcss": "^8.4.35",
|
||||||
"prettier": "^2.8.8",
|
"prettier": "^2.8.8",
|
||||||
"vitest": "^0.31.1"
|
"vitest": "^0.31.4"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^20 || ^18 || ^16",
|
"node": "^20 || ^18 || ^16",
|
||||||
|
|
495
pnpm-lock.yaml
495
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
@ -1,55 +0,0 @@
|
||||||
<script setup>
|
|
||||||
import { defineProps, ref } from 'vue';
|
|
||||||
import { useI18n } from 'vue-i18n';
|
|
||||||
|
|
||||||
const { t } = useI18n();
|
|
||||||
const props = defineProps({
|
|
||||||
usesMana: {
|
|
||||||
type: Boolean,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
manaCode: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
manaVal: {
|
|
||||||
type: String,
|
|
||||||
default: 'mana',
|
|
||||||
},
|
|
||||||
manaLabel: {
|
|
||||||
type: String,
|
|
||||||
default: 'Promotion mana',
|
|
||||||
},
|
|
||||||
manaClaimVal: {
|
|
||||||
type: String,
|
|
||||||
default: 'manaClaim',
|
|
||||||
},
|
|
||||||
claimLabel: {
|
|
||||||
type: String,
|
|
||||||
default: 'Claim mana',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const manaCode = ref(props.manaCode);
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div class="column q-gutter-y-sm q-mt-sm">
|
|
||||||
<QRadio
|
|
||||||
v-model="manaCode"
|
|
||||||
dense
|
|
||||||
:val="manaVal"
|
|
||||||
:label="t(manaLabel)"
|
|
||||||
:dark="true"
|
|
||||||
class="q-mb-sm"
|
|
||||||
/>
|
|
||||||
<QRadio
|
|
||||||
v-model="manaCode"
|
|
||||||
dense
|
|
||||||
:val="manaClaimVal"
|
|
||||||
:label="t(claimLabel)"
|
|
||||||
:dark="true"
|
|
||||||
class="q-mb-sm"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
|
@ -123,8 +123,8 @@ async function fetchMana() {
|
||||||
|
|
||||||
async function updateDiscount({ saleFk, discount, canceller }) {
|
async function updateDiscount({ saleFk, discount, canceller }) {
|
||||||
const body = { salesIds: [saleFk], newDiscount: discount };
|
const body = { salesIds: [saleFk], newDiscount: discount };
|
||||||
const claimId = claim.value.ticketFk;
|
const ticketFk = claim.value.ticketFk;
|
||||||
const query = `Tickets/${claimId}/updateDiscount`;
|
const query = `Tickets/${ticketFk}/updateDiscount`;
|
||||||
|
|
||||||
await axios.post(query, body, {
|
await axios.post(query, body, {
|
||||||
signal: canceller.signal,
|
signal: canceller.signal,
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { computed, ref, onMounted } from 'vue';
|
import { computed, ref } from 'vue';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import VnUserLink from 'src/components/ui/VnUserLink.vue';
|
import VnUserLink from 'src/components/ui/VnUserLink.vue';
|
||||||
|
|
||||||
import { toCurrency, toPercentage, toDate, dashOrCurrency } from 'src/filters';
|
import { toCurrency, toPercentage, toDate, dashOrCurrency } from 'src/filters';
|
||||||
import CardSummary from 'components/ui/CardSummary.vue';
|
import CardSummary from 'components/ui/CardSummary.vue';
|
||||||
import { getUrl } from 'src/composables/getUrl';
|
|
||||||
import VnLv from 'src/components/ui/VnLv.vue';
|
import VnLv from 'src/components/ui/VnLv.vue';
|
||||||
import VnLinkPhone from 'src/components/ui/VnLinkPhone.vue';
|
import VnLinkPhone from 'src/components/ui/VnLinkPhone.vue';
|
||||||
import VnLinkMail from 'src/components/ui/VnLinkMail.vue';
|
import VnLinkMail from 'src/components/ui/VnLinkMail.vue';
|
||||||
|
|
|
@ -2,35 +2,27 @@
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { toCurrency } from 'src/filters';
|
import { toCurrency } from 'src/filters';
|
||||||
import VnUsesMana from 'components/ui/VnUsesMana.vue';
|
import axios from 'axios';
|
||||||
|
import { useRoute } from 'vue-router';
|
||||||
|
|
||||||
|
const route = useRoute();
|
||||||
const $props = defineProps({
|
const $props = defineProps({
|
||||||
mana: {
|
|
||||||
type: Number,
|
|
||||||
default: null,
|
|
||||||
},
|
|
||||||
newPrice: {
|
newPrice: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 0,
|
default: 0,
|
||||||
},
|
},
|
||||||
usesMana: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
manaCode: {
|
|
||||||
type: String,
|
|
||||||
default: 'mana',
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits(['save', 'cancel']);
|
const emit = defineEmits(['save', 'cancel', 'show']);
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const QPopupProxyRef = ref(null);
|
const QPopupProxyRef = ref(null);
|
||||||
const manaCode = ref($props.manaCode);
|
const componentName = ref('mana');
|
||||||
|
const mana = ref(null);
|
||||||
|
const usesMana = ref(null);
|
||||||
|
|
||||||
const save = () => {
|
const save = () => {
|
||||||
emit('save');
|
emit('save', componentName.value);
|
||||||
QPopupProxyRef.value.hide();
|
QPopupProxyRef.value.hide();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -38,15 +30,53 @@ const cancel = () => {
|
||||||
emit('cancel');
|
emit('cancel');
|
||||||
QPopupProxyRef.value.hide();
|
QPopupProxyRef.value.hide();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function onShow() {
|
||||||
|
const { data: manaData } = await axios.get(
|
||||||
|
`Tickets/${route.params.id}/getSalesPersonMana`
|
||||||
|
);
|
||||||
|
mana.value = manaData;
|
||||||
|
|
||||||
|
const { data: usesManaData } = await axios.get('Sales/usesMana');
|
||||||
|
usesMana.value = usesManaData;
|
||||||
|
|
||||||
|
emit('show');
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<QPopupProxy ref="QPopupProxyRef">
|
<QPopupProxy ref="QPopupProxyRef" @show="onShow()">
|
||||||
<div class="container">
|
<QForm @submit="save">
|
||||||
|
<div>
|
||||||
<QSpinner v-if="!mana" color="primary" size="md" />
|
<QSpinner v-if="!mana" color="primary" size="md" />
|
||||||
<div v-else>
|
<div v-else>
|
||||||
<div class="header">Mana: {{ toCurrency(mana) }}</div>
|
<div class="header">Mana: {{ toCurrency(mana) }}</div>
|
||||||
<div class="q-pa-md">
|
<div class="q-pa-md">
|
||||||
|
<div v-if="usesMana" class="column q-gutter-y-sm q-mt-sm">
|
||||||
|
<div class="column q-gutter-y-sm q-mt-sm">
|
||||||
|
<QRadio
|
||||||
|
v-model="componentName"
|
||||||
|
dense
|
||||||
|
val="mana"
|
||||||
|
:label="t('Mana')"
|
||||||
|
class="q-mb-sm"
|
||||||
|
/>
|
||||||
|
<QRadio
|
||||||
|
v-model="componentName"
|
||||||
|
dense
|
||||||
|
val="debtCollection"
|
||||||
|
:label="t('Greuge')"
|
||||||
|
class="q-mb-sm"
|
||||||
|
/>
|
||||||
|
<QRadio
|
||||||
|
v-model="componentName"
|
||||||
|
dense
|
||||||
|
val="manaClaim"
|
||||||
|
:label="t('Claim')"
|
||||||
|
class="q-mb-sm"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<slot />
|
<slot />
|
||||||
<div v-if="newPrice" class="column items-center q-mt-lg">
|
<div v-if="newPrice" class="column items-center q-mt-lg">
|
||||||
<span class="text-primary">{{ t('New price') }}</span>
|
<span class="text-primary">{{ t('New price') }}</span>
|
||||||
|
@ -56,9 +86,6 @@ const cancel = () => {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="usesMana" class="column q-gutter-y-sm q-mt-sm">
|
|
||||||
<VnUsesMana :mana-code="manaCode" />
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<QBtn
|
<QBtn
|
||||||
color="primary"
|
color="primary"
|
||||||
|
@ -74,22 +101,18 @@ const cancel = () => {
|
||||||
class="no-border-radius"
|
class="no-border-radius"
|
||||||
dense
|
dense
|
||||||
style="width: 50%"
|
style="width: 50%"
|
||||||
@click="save()"
|
|
||||||
data-cy="saveManaBtn"
|
data-cy="saveManaBtn"
|
||||||
|
type="submit"
|
||||||
>
|
>
|
||||||
{{ t('globals.save') }}
|
{{ t('globals.save') }}
|
||||||
</QBtn>
|
</QBtn>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</QForm>
|
||||||
</QPopupProxy>
|
</QPopupProxy>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.container {
|
|
||||||
background-color: $dark;
|
|
||||||
width: 230px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.header {
|
.header {
|
||||||
height: 54px;
|
height: 54px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
@ -106,4 +129,5 @@ const cancel = () => {
|
||||||
<i18n>
|
<i18n>
|
||||||
es:
|
es:
|
||||||
New price: Nuevo precio
|
New price: Nuevo precio
|
||||||
|
Claim: Reclamación
|
||||||
</i18n>
|
</i18n>
|
||||||
|
|
|
@ -3,19 +3,16 @@ import { onMounted, ref, computed, onUnmounted, watch } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useRouter, useRoute } from 'vue-router';
|
import { useRouter, useRoute } from 'vue-router';
|
||||||
import { useQuasar } from 'quasar';
|
import { useQuasar } from 'quasar';
|
||||||
|
|
||||||
import FetchData from 'components/FetchData.vue';
|
import FetchData from 'components/FetchData.vue';
|
||||||
import FetchedTags from 'components/ui/FetchedTags.vue';
|
import FetchedTags from 'components/ui/FetchedTags.vue';
|
||||||
import VnInput from 'src/components/common/VnInput.vue';
|
import VnInput from 'src/components/common/VnInput.vue';
|
||||||
import VnSelect from 'src/components/common/VnSelect.vue';
|
import VnSelect from 'src/components/common/VnSelect.vue';
|
||||||
import ItemDescriptorProxy from 'src/pages/Item/Card/ItemDescriptorProxy.vue';
|
import ItemDescriptorProxy from 'src/pages/Item/Card/ItemDescriptorProxy.vue';
|
||||||
import TicketEditManaProxy from './TicketEditMana.vue';
|
import TicketEditMana from './TicketEditMana.vue';
|
||||||
import VnImg from 'src/components/ui/VnImg.vue';
|
import VnImg from 'src/components/ui/VnImg.vue';
|
||||||
|
|
||||||
import VnSubToolbar from 'src/components/ui/VnSubToolbar.vue';
|
import VnSubToolbar from 'src/components/ui/VnSubToolbar.vue';
|
||||||
import TicketSaleMoreActions from './TicketSaleMoreActions.vue';
|
import TicketSaleMoreActions from './TicketSaleMoreActions.vue';
|
||||||
import TicketTransfer from './TicketTransfer.vue';
|
import TicketTransfer from './TicketTransfer.vue';
|
||||||
|
|
||||||
import { useStateStore } from 'stores/useStateStore';
|
import { useStateStore } from 'stores/useStateStore';
|
||||||
import { toCurrency, toPercentage } from 'src/filters';
|
import { toCurrency, toPercentage } from 'src/filters';
|
||||||
import { useArrayData } from 'composables/useArrayData';
|
import { useArrayData } from 'composables/useArrayData';
|
||||||
|
@ -23,7 +20,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';
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
@ -32,7 +28,6 @@ const stateStore = useStateStore();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const { notify } = useNotify();
|
const { notify } = useNotify();
|
||||||
const { openConfirmationModal } = useVnConfirm();
|
const { openConfirmationModal } = useVnConfirm();
|
||||||
const editPriceProxyRef = ref(null);
|
|
||||||
const stateBtnDropdownRef = ref(null);
|
const stateBtnDropdownRef = ref(null);
|
||||||
const quasar = useQuasar();
|
const quasar = useQuasar();
|
||||||
const arrayData = useArrayData('ticketData');
|
const arrayData = useArrayData('ticketData');
|
||||||
|
@ -45,8 +40,6 @@ const isTicketEditable = ref(false);
|
||||||
const sales = ref([]);
|
const sales = ref([]);
|
||||||
const editableStatesOptions = ref([]);
|
const editableStatesOptions = ref([]);
|
||||||
const selectedSales = ref([]);
|
const selectedSales = ref([]);
|
||||||
const mana = ref(null);
|
|
||||||
const manaCode = ref('mana');
|
|
||||||
const ticketState = computed(() => store.data?.ticketState?.state?.code);
|
const ticketState = computed(() => store.data?.ticketState?.state?.code);
|
||||||
const transfer = ref({
|
const transfer = ref({
|
||||||
lastActiveTickets: [],
|
lastActiveTickets: [],
|
||||||
|
@ -137,7 +130,7 @@ const columns = computed(() => [
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
align: 'left',
|
align: 'left',
|
||||||
label: t('ticketSale.packaging'),
|
label: t('ticketSale.pack'),
|
||||||
name: 'itemPackingTypeFk',
|
name: 'itemPackingTypeFk',
|
||||||
format: (row, dashIfEmpty) => dashIfEmpty(row?.item?.itemPackingTypeFk),
|
format: (row, dashIfEmpty) => dashIfEmpty(row?.item?.itemPackingTypeFk),
|
||||||
},
|
},
|
||||||
|
@ -154,7 +147,6 @@ const columns = computed(() => [
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const getConfig = async () => {
|
const getConfig = async () => {
|
||||||
let filter = {
|
let filter = {
|
||||||
fields: ['daysForWarningClaim'],
|
fields: ['daysForWarningClaim'],
|
||||||
|
@ -252,18 +244,6 @@ const DEFAULT_EDIT = {
|
||||||
oldQuantity: null,
|
oldQuantity: null,
|
||||||
};
|
};
|
||||||
const edit = ref({ ...DEFAULT_EDIT });
|
const edit = ref({ ...DEFAULT_EDIT });
|
||||||
const usesMana = ref(null);
|
|
||||||
|
|
||||||
const getUsesMana = async () => {
|
|
||||||
const { data } = await axios.get('Sales/usesMana');
|
|
||||||
usesMana.value = data;
|
|
||||||
};
|
|
||||||
|
|
||||||
const getMana = async () => {
|
|
||||||
const { data } = await axios.get(`Tickets/${route.params.id}/getSalesPersonMana`);
|
|
||||||
mana.value = data;
|
|
||||||
await getUsesMana();
|
|
||||||
};
|
|
||||||
|
|
||||||
const selectedValidSales = computed(() => {
|
const selectedValidSales = computed(() => {
|
||||||
if (!sales.value) return;
|
if (!sales.value) return;
|
||||||
|
@ -271,65 +251,46 @@ const selectedValidSales = computed(() => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const onOpenEditPricePopover = async (sale) => {
|
const onOpenEditPricePopover = async (sale) => {
|
||||||
await getMana();
|
|
||||||
edit.value = {
|
edit.value = {
|
||||||
sale: JSON.parse(JSON.stringify(sale)),
|
sale: JSON.parse(JSON.stringify(sale)),
|
||||||
price: sale.price,
|
price: sale.price,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const onOpenEditDiscountPopover = async (sale) => {
|
const onDiscountClick = async (sale) => {
|
||||||
await getMana();
|
|
||||||
if (isLocked.value) return;
|
if (isLocked.value) return;
|
||||||
if (sale) {
|
if (sale) {
|
||||||
edit.value = {
|
edit.value = {
|
||||||
sale: JSON.parse(JSON.stringify(sale)),
|
sale: JSON.parse(JSON.stringify(sale)),
|
||||||
discount: sale.discount,
|
discount: sale.discount,
|
||||||
};
|
};
|
||||||
} else {
|
|
||||||
edit.value = {
|
|
||||||
discount: null,
|
|
||||||
sales: selectedValidSales.value,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const updatePrice = async (sale) => {
|
const updatePrice = async (sale, componentName) => {
|
||||||
canProceed.value = await isSalePrepared(sale);
|
canProceed.value = await isSalePrepared(sale);
|
||||||
if (!canProceed.value) return;
|
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) {
|
||||||
await axios.post(`Sales/${sale.id}/updatePrice`, { newPrice });
|
await axios.post(`Sales/${sale.id}/updatePrice`, { newPrice, componentName });
|
||||||
sale.price = newPrice;
|
sale.price = newPrice;
|
||||||
edit.value = { ...DEFAULT_EDIT };
|
edit.value = { ...DEFAULT_EDIT };
|
||||||
notify('globals.dataSaved', 'positive');
|
notify('globals.dataSaved', 'positive');
|
||||||
}
|
}
|
||||||
|
|
||||||
await getMana();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const changeDiscount = async (sale) => {
|
const updateDiscount = async (sales, componentName, newDiscount) => {
|
||||||
canProceed.value = await isSalePrepared(sale);
|
const hasChanges = sales.some((sale) => sale.discount != newDiscount);
|
||||||
if (!canProceed.value) return;
|
if (!hasChanges || newDiscount == null || newDiscount === '') return;
|
||||||
const newDiscount = edit.value.discount;
|
const canProceed = await Promise.all(sales.map((sale) => isSalePrepared(sale)));
|
||||||
if (newDiscount != null && newDiscount != sale.discount) updateDiscount([sale]);
|
if (canProceed.includes(false)) return;
|
||||||
};
|
|
||||||
|
|
||||||
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 params = { salesIds: saleIds, newDiscount, componentName };
|
||||||
const params = {
|
|
||||||
salesIds: saleIds,
|
|
||||||
newDiscount: _newDiscount,
|
|
||||||
manaCode: manaCode.value,
|
|
||||||
};
|
|
||||||
await axios.post(`Tickets/${route.params.id}/updateDiscount`, params);
|
await axios.post(`Tickets/${route.params.id}/updateDiscount`, params);
|
||||||
notify('globals.dataSaved', 'positive');
|
notify('globals.dataSaved', 'positive');
|
||||||
for (let sale of sales) sale.discount = _newDiscount;
|
for (let sale of sales) sale.discount = params.newDiscount;
|
||||||
edit.value = { ...DEFAULT_EDIT };
|
edit.value = { ...DEFAULT_EDIT };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -377,7 +338,6 @@ const changeTicketState = async (val) => {
|
||||||
notify('globals.dataSaved', 'positive');
|
notify('globals.dataSaved', 'positive');
|
||||||
await resetChanges();
|
await resetChanges();
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeSelectedSales = () => {
|
const removeSelectedSales = () => {
|
||||||
selectedRows.value.forEach((sale) => {
|
selectedRows.value.forEach((sale) => {
|
||||||
const index = sales.value.indexOf(sale);
|
const index = sales.value.indexOf(sale);
|
||||||
|
@ -582,9 +542,7 @@ watch(
|
||||||
:is-ticket-editable="isTicketEditable"
|
:is-ticket-editable="isTicketEditable"
|
||||||
:sales="selectedValidSales"
|
:sales="selectedValidSales"
|
||||||
:disable="!hasSelectedRows"
|
:disable="!hasSelectedRows"
|
||||||
:mana="mana"
|
|
||||||
:ticket-config="ticketConfig"
|
:ticket-config="ticketConfig"
|
||||||
@get-mana="getMana()"
|
|
||||||
@update-discounts="updateDiscount"
|
@update-discounts="updateDiscount"
|
||||||
@refresh-table="resetChanges"
|
@refresh-table="resetChanges"
|
||||||
/>
|
/>
|
||||||
|
@ -794,45 +752,44 @@ watch(
|
||||||
</template>
|
</template>
|
||||||
<template #column-price="{ row }">
|
<template #column-price="{ row }">
|
||||||
<template v-if="isTicketEditable && row.id">
|
<template v-if="isTicketEditable && row.id">
|
||||||
<QBtn flat class="link" dense @click="onOpenEditPricePopover(row)">
|
<QBtn flat class="link" dense>
|
||||||
{{ toCurrency(row.price) }}
|
{{ toCurrency(row.price) }}
|
||||||
</QBtn>
|
<TicketEditMana
|
||||||
<TicketEditManaProxy
|
|
||||||
ref="editPriceProxyRef"
|
|
||||||
:mana="mana"
|
|
||||||
:new-price="getNewPrice"
|
:new-price="getNewPrice"
|
||||||
@save="updatePrice(row)"
|
@show="onOpenEditPricePopover(row)"
|
||||||
|
@save="(componentName) => updatePrice(row, componentName)"
|
||||||
>
|
>
|
||||||
<VnInput
|
<VnInput
|
||||||
v-model.number="edit.price"
|
v-model.number="edit.price"
|
||||||
:label="t('basicData.price')"
|
:label="t('basicData.price')"
|
||||||
type="number"
|
type="number"
|
||||||
/>
|
/>
|
||||||
</TicketEditManaProxy>
|
</TicketEditMana>
|
||||||
|
</QBtn>
|
||||||
</template>
|
</template>
|
||||||
<span v-else>{{ toCurrency(row.price) }}</span>
|
<span v-else>{{ toCurrency(row.price) }}</span>
|
||||||
</template>
|
</template>
|
||||||
<template #column-discount="{ row }">
|
<template #column-discount="{ row }">
|
||||||
<template v-if="!isLocked && row.id">
|
<template v-if="!isLocked && row.id">
|
||||||
<QBtn flat class="link" dense @click="onOpenEditDiscountPopover(row)">
|
<QBtn flat class="link" dense>
|
||||||
{{ toPercentage(row.discount / 100) }}
|
{{ toPercentage(row.discount / 100) }}
|
||||||
</QBtn>
|
<TicketEditMana
|
||||||
<TicketEditManaProxy
|
|
||||||
:mana="mana"
|
|
||||||
:new-price="getNewPrice"
|
:new-price="getNewPrice"
|
||||||
:uses-mana="usesMana"
|
@show="onDiscountClick(row)"
|
||||||
:mana-code="manaCode"
|
@save="
|
||||||
@save="changeDiscount(row)"
|
(componentName) =>
|
||||||
|
updateDiscount([row], componentName, edit.discount)
|
||||||
|
"
|
||||||
>
|
>
|
||||||
<VnInput
|
<VnInput
|
||||||
v-model.number="edit.discount"
|
v-model.number="edit.discount"
|
||||||
:label="t('ticketSale.discount')"
|
:label="t('ticketSale.discount')"
|
||||||
type="number"
|
type="number"
|
||||||
|
@keydown.enter.prevent.stop
|
||||||
|
autofocus
|
||||||
/>
|
/>
|
||||||
<div v-if="usesMana" class="column q-gutter-y-sm q-mt-sm">
|
</TicketEditMana>
|
||||||
<VnUsesMana :mana-code="manaCode" />
|
</QBtn>
|
||||||
</div>
|
|
||||||
</TicketEditManaProxy>
|
|
||||||
</template>
|
</template>
|
||||||
<span v-else>{{ toPercentage(row.discount / 100) }}</span>
|
<span v-else>{{ toPercentage(row.discount / 100) }}</span>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { useQuasar } from 'quasar';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
import VnSmsDialog from 'components/common/VnSmsDialog.vue';
|
import VnSmsDialog from 'components/common/VnSmsDialog.vue';
|
||||||
import TicketEditManaProxy from './TicketEditMana.vue';
|
import TicketEditMana from './TicketEditMana.vue';
|
||||||
import VnInput from 'src/components/common/VnInput.vue';
|
import VnInput from 'src/components/common/VnInput.vue';
|
||||||
|
|
||||||
import useNotify from 'src/composables/useNotify.js';
|
import useNotify from 'src/composables/useNotify.js';
|
||||||
|
@ -14,7 +14,7 @@ import { toDateFormat } from 'src/filters/date';
|
||||||
import { useRole } from 'src/composables/useRole';
|
import { useRole } from 'src/composables/useRole';
|
||||||
import { useVnConfirm } from 'composables/useVnConfirm';
|
import { useVnConfirm } from 'composables/useVnConfirm';
|
||||||
|
|
||||||
const emit = defineEmits(['updateDiscounts', 'getMana', 'refreshTable']);
|
const emit = defineEmits(['updateDiscounts', 'refreshTable']);
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
disable: {
|
disable: {
|
||||||
|
@ -28,16 +28,11 @@ const props = defineProps({
|
||||||
ticket: {
|
ticket: {
|
||||||
type: Object,
|
type: Object,
|
||||||
required: true,
|
required: true,
|
||||||
default: () => {},
|
|
||||||
},
|
},
|
||||||
sales: {
|
sales: {
|
||||||
type: Array,
|
type: Array,
|
||||||
default: () => [],
|
default: () => [],
|
||||||
},
|
},
|
||||||
mana: {
|
|
||||||
type: Number,
|
|
||||||
default: null,
|
|
||||||
},
|
|
||||||
ticketConfig: {
|
ticketConfig: {
|
||||||
type: Array,
|
type: Array,
|
||||||
default: () => [],
|
default: () => [],
|
||||||
|
@ -110,13 +105,9 @@ const calculateSalePrice = async () => {
|
||||||
emit('refreshTable', props.sales);
|
emit('refreshTable', props.sales);
|
||||||
};
|
};
|
||||||
|
|
||||||
const changeMultipleDiscount = () => {
|
const changeMultipleDiscount = (componentName, newDiscount) => {
|
||||||
const hasChanges = props.sales.some((sale) => {
|
if (newDiscount != null)
|
||||||
return sale.discount != newDiscount.value;
|
emit('updateDiscounts', props.sales, componentName, newDiscount);
|
||||||
});
|
|
||||||
|
|
||||||
if (newDiscount.value != null && hasChanges)
|
|
||||||
emit('updateDiscounts', props.sales, newDiscount.value);
|
|
||||||
btnDropdownRef.value.hide();
|
btnDropdownRef.value.hide();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -205,23 +196,23 @@ const createRefund = async (withWarehouse) => {
|
||||||
<QItemLabel>{{ t('Recalculate price') }}</QItemLabel>
|
<QItemLabel>{{ t('Recalculate price') }}</QItemLabel>
|
||||||
</QItemSection>
|
</QItemSection>
|
||||||
</QItem>
|
</QItem>
|
||||||
<QItem
|
<QItem clickable v-ripple data-cy="updateDiscountItem">
|
||||||
clickable
|
|
||||||
v-ripple
|
|
||||||
@click="emit('getMana')"
|
|
||||||
data-cy="updateDiscountItem"
|
|
||||||
>
|
|
||||||
<QItemSection>
|
<QItemSection>
|
||||||
<QItemLabel>{{ t('Update discount') }}</QItemLabel>
|
<QItemLabel>{{ t('Update discount') }}</QItemLabel>
|
||||||
</QItemSection>
|
</QItemSection>
|
||||||
<TicketEditManaProxy :mana="props.mana" @save="changeMultipleDiscount()">
|
<TicketEditMana
|
||||||
|
@save="
|
||||||
|
(componentName) =>
|
||||||
|
changeMultipleDiscount(componentName, newDiscount)
|
||||||
|
"
|
||||||
|
>
|
||||||
<VnInput
|
<VnInput
|
||||||
v-model.number="newDiscount"
|
v-model.number="newDiscount"
|
||||||
:label="t('ticketSale.discount')"
|
:label="t('ticketSale.discount')"
|
||||||
type="number"
|
type="number"
|
||||||
data-cy="ticketSaleDiscountInput"
|
data-cy="ticketSaleDiscountInput"
|
||||||
/>
|
/>
|
||||||
</TicketEditManaProxy>
|
</TicketEditMana>
|
||||||
</QItem>
|
</QItem>
|
||||||
<QItem
|
<QItem
|
||||||
v-if="isClaimable"
|
v-if="isClaimable"
|
||||||
|
|
|
@ -15,6 +15,7 @@ ticketSale:
|
||||||
available: Available
|
available: Available
|
||||||
discount: Disc
|
discount: Disc
|
||||||
packaging: Packaging
|
packaging: Packaging
|
||||||
|
pack: Pack.
|
||||||
subtotal: Subtotal
|
subtotal: Subtotal
|
||||||
tax: VAT
|
tax: VAT
|
||||||
history: History
|
history: History
|
||||||
|
|
|
@ -116,6 +116,7 @@ ticketSale:
|
||||||
available: Disponible
|
available: Disponible
|
||||||
discount: Dto
|
discount: Dto
|
||||||
packaging: Encajado
|
packaging: Encajado
|
||||||
|
pack: Enc.
|
||||||
subtotal: Subtotal
|
subtotal: Subtotal
|
||||||
tax: IVA
|
tax: IVA
|
||||||
history: Historial
|
history: Historial
|
||||||
|
|
|
@ -0,0 +1,99 @@
|
||||||
|
import { vi, describe, it, beforeEach, afterEach, expect } from 'vitest';
|
||||||
|
import { createWrapper } from 'app/test/vitest/helper';
|
||||||
|
import TicketSale from 'pages/Ticket/Card/TicketSale.vue';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
describe('TicketSale ', () => {
|
||||||
|
let wrapper;
|
||||||
|
let vm;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.spyOn(axios, 'post').mockResolvedValue({});
|
||||||
|
vi.spyOn(axios, 'get').mockImplementation(() => ({
|
||||||
|
data: [
|
||||||
|
{ id: 1, discount: 5 },
|
||||||
|
{ id: 2, discount: 7 },
|
||||||
|
],
|
||||||
|
}));
|
||||||
|
wrapper = createWrapper(TicketSale, {
|
||||||
|
props: {
|
||||||
|
ticket: { id: 123, name: 'Sample Ticket' },
|
||||||
|
isTicketEditable: true,
|
||||||
|
},
|
||||||
|
global: {
|
||||||
|
mocks: {
|
||||||
|
store: {
|
||||||
|
data: { id: 123, name: 'Sample Ticket' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
// wrapper.vm.route = { params: { id: 123 } };
|
||||||
|
vm = wrapper.vm;
|
||||||
|
vi.spyOn(vm, 'isSalePrepared').mockResolvedValue(true);
|
||||||
|
vm.edit = { discount: 10 }; // Set the discount in the edit state
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
vi.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should update discounts for sales when changes exist', async () => {
|
||||||
|
const sales = [
|
||||||
|
{ id: 1, discount: 5 },
|
||||||
|
{ id: 2, discount: 7 },
|
||||||
|
];
|
||||||
|
|
||||||
|
const newDiscount = 10;
|
||||||
|
const componentName = 'TicketSale';
|
||||||
|
|
||||||
|
await vm.updateDiscount(sales, componentName, newDiscount);
|
||||||
|
|
||||||
|
expect(sales[0].discount).toBe(newDiscount);
|
||||||
|
expect(sales[1].discount).toBe(newDiscount);
|
||||||
|
expect(vm.edit).toEqual({
|
||||||
|
price: null,
|
||||||
|
discount: null,
|
||||||
|
sale: null,
|
||||||
|
sales: null,
|
||||||
|
oldQuantity: null,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it.only('should not update discounts if there are no changes', async () => {
|
||||||
|
const newDiscount = 10;
|
||||||
|
const sales = [
|
||||||
|
{ id: 1, itemFk: 123, discount: 10 },
|
||||||
|
{ id: 2, itemFk: 456, discount: 10 },
|
||||||
|
];
|
||||||
|
const componentName = 'TicketSale';
|
||||||
|
|
||||||
|
await vm.updateDiscount(sales, componentName, newDiscount);
|
||||||
|
|
||||||
|
expect(axios.post).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not update discounts if there is no discount', async () => {
|
||||||
|
const sales = [{ id: 1, discount: 10 }];
|
||||||
|
const componentName = 'TicketSale';
|
||||||
|
|
||||||
|
await vm.updateDiscount(sales, componentName, null);
|
||||||
|
|
||||||
|
expect(axios.post).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not update discounts if any sale is not prepared', async () => {
|
||||||
|
vi.spyOn(vm, 'isSalePrepared').mockImplementation((sale) =>
|
||||||
|
Promise.resolve(sale.id !== 1)
|
||||||
|
);
|
||||||
|
const sales = [
|
||||||
|
{ id: 1, discount: 5 },
|
||||||
|
{ id: 2, discount: 7 },
|
||||||
|
];
|
||||||
|
const componentName = 'TicketSale';
|
||||||
|
|
||||||
|
await vm.updateDiscount(sales, componentName);
|
||||||
|
|
||||||
|
expect(axios.post).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
|
@ -86,7 +86,7 @@ export function createWrapper(component, options) {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const mountOptions = Object.assign({}, defaultOptions);
|
const mountOptions = { ...defaultOptions };
|
||||||
|
|
||||||
if (options instanceof Object) {
|
if (options instanceof Object) {
|
||||||
Object.assign(mountOptions, options);
|
Object.assign(mountOptions, options);
|
||||||
|
|
Loading…
Reference in New Issue