Merge pull request 'fix: refs #8731 customerBalance and test' (!1578) from 8731-customerBalanceFix into master
gitea/salix-front/pipeline/head This commit looks good Details

Reviewed-on: #1578
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
Carlos Satorres 2025-03-10 08:22:13 +00:00
commit f1b9b8ffd2
2 changed files with 42 additions and 60 deletions

View File

@ -5,7 +5,7 @@ import { useRoute } from 'vue-router';
import axios from 'axios'; import axios from 'axios';
import { getClientRisk } from '../composables/getClientRisk'; import { getClientRisk } from '../composables/getClientRisk';
import { useDialogPluginComponent } from 'quasar'; import { useDialogPluginComponent } from 'quasar';
import FormModelPopup from 'components/FormModelPopup.vue';
import { usePrintService } from 'composables/usePrintService'; import { usePrintService } from 'composables/usePrintService';
import useNotify from 'src/composables/useNotify.js'; import useNotify from 'src/composables/useNotify.js';
import FetchData from 'components/FetchData.vue'; import FetchData from 'components/FetchData.vue';
@ -74,26 +74,24 @@ onBeforeMount(() => {
urlCreate.value = `Clients/${route.params.id}/createReceipt`; urlCreate.value = `Clients/${route.params.id}/createReceipt`;
}); });
function setPaymentType(accounting) { function setPaymentType(data, accounting) {
data.bankFk = accounting.id;
if (!accounting) return; if (!accounting) return;
accountingType.value = accounting.accountingType; accountingType.value = accounting.accountingType;
initialData.description = []; data.description = [];
initialData.payed = Date.vnNew(); data.payed = Date.vnNew();
isCash.value = accountingType.value.code == 'cash'; isCash.value = accountingType.value.code == 'cash';
viewReceipt.value = isCash.value; viewReceipt.value = isCash.value;
if (accountingType.value.daysInFuture) if (accountingType.value.daysInFuture)
initialData.payed.setDate( data.payed.setDate(data.payed.getDate() + accountingType.value.daysInFuture);
initialData.payed.getDate() + accountingType.value.daysInFuture,
);
maxAmount.value = accountingType.value && accountingType.value.maxAmount; maxAmount.value = accountingType.value && accountingType.value.maxAmount;
if (accountingType.value.code == 'compensation') if (accountingType.value.code == 'compensation') return (data.description = '');
return (initialData.description = '');
let descriptions = []; let descriptions = [];
if (accountingType.value.receiptDescription) if (accountingType.value.receiptDescription)
descriptions.push(accountingType.value.receiptDescription); descriptions.push(accountingType.value.receiptDescription);
if (initialData.description) descriptions.push(initialData.description); if (data.description) descriptions.push(data.description);
initialData.description = descriptions.join(', '); data.description = descriptions.join(', ');
} }
const calculateFromAmount = (event) => { const calculateFromAmount = (event) => {
@ -113,7 +111,6 @@ function onBeforeSave(data) {
if (isCash.value && shouldSendEmail.value && !data.email) if (isCash.value && shouldSendEmail.value && !data.email)
return notify(t('There is no assigned email for this client'), 'negative'); return notify(t('There is no assigned email for this client'), 'negative');
data.bankFk = data.bankFk?.id;
return data; return data;
} }
@ -181,42 +178,19 @@ async function getAmountPaid() {
auto-load auto-load
url="Clients/findOne" url="Clients/findOne"
/> />
<FormModel <FormModelPopup
ref="formModelRef" ref="formModelRef"
:form-initial-data="initialData" :form-initial-data="initialData"
:observe-form-changes="false"
:url-create="urlCreate" :url-create="urlCreate"
:mapper="onBeforeSave" :mapper="onBeforeSave"
@on-data-saved="onDataSaved" @on-data-saved="onDataSaved"
prevent-submit :prevent-submit="true"
> >
<template #form="{ data, validate }"> <template #form-inputs="{ data, validate }">
<span ref="closeButton" class="row justify-end close-icon" v-close-popup>
<QIcon name="close" size="sm" />
</span>
<h5 class="q-mt-none">{{ t('New payment') }}</h5> <h5 class="q-mt-none">{{ t('New payment') }}</h5>
<VnRow>
<VnInputDate
:label="t('Date')"
:required="true"
v-model="data.payed"
/>
<VnSelect
:label="t('Company')"
:options="companyOptions"
:required="true"
:rules="validate('entry.companyFk')"
hide-selected
option-label="code"
option-value="id"
v-model="data.companyFk"
@update:model-value="getAmountPaid()"
/>
</VnRow>
<VnRow> <VnRow>
<VnSelect <VnSelect
autofocus
:label="t('Bank')" :label="t('Bank')"
v-model="data.bankFk" v-model="data.bankFk"
url="Accountings" url="Accountings"
@ -225,9 +199,10 @@ async function getAmountPaid() {
sort-by="id" sort-by="id"
:limit="0" :limit="0"
@update:model-value=" @update:model-value="
(value, options) => setPaymentType(value, options) (value, options) => setPaymentType(data, value, options)
" "
:emit-value="false" :emit-value="false"
data-cy="paymentBank"
> >
<template #option="scope"> <template #option="scope">
<QItem v-bind="scope.itemProps"> <QItem v-bind="scope.itemProps">
@ -245,8 +220,28 @@ async function getAmountPaid() {
@update:model-value="calculateFromAmount($event)" @update:model-value="calculateFromAmount($event)"
clearable clearable
v-model.number="data.amountPaid" v-model.number="data.amountPaid"
data-cy="paymentAmount"
/> />
</VnRow> </VnRow>
<VnRow>
<VnInputDate
:label="t('Date')"
v-model="data.payed"
:required="true"
/>
<VnSelect
:label="t('Company')"
:options="companyOptions"
:required="true"
:rules="validate('entry.companyFk')"
hide-selected
option-label="code"
option-value="id"
v-model="data.companyFk"
@update:model-value="getAmountPaid()"
/>
</VnRow>
<div v-if="data.bankFk?.accountingType?.code == 'compensation'"> <div v-if="data.bankFk?.accountingType?.code == 'compensation'">
<div class="text-h6"> <div class="text-h6">
{{ t('Compensation') }} {{ t('Compensation') }}
@ -287,27 +282,8 @@ async function getAmountPaid() {
<QCheckbox v-model="shouldSendEmail" :label="t('Send email')" /> <QCheckbox v-model="shouldSendEmail" :label="t('Send email')" />
</VnRow> </VnRow>
</div> </div>
<div class="q-mt-lg row justify-end">
<QBtn
:disabled="formModelRef.isLoading"
:label="t('globals.cancel')"
:loading="formModelRef.isLoading"
class="q-ml-sm"
color="primary"
flat
type="reset"
v-close-popup
/>
<QBtn
:disabled="formModelRef.isLoading"
:label="t('globals.save')"
:loading="formModelRef.isLoading"
color="primary"
@click="formModelRef.save()"
/>
</div>
</template> </template>
</FormModel> </FormModelPopup>
</QDialog> </QDialog>
</template> </template>

View File

@ -8,4 +8,10 @@ describe('Client balance', () => {
it('Should load layout', () => { it('Should load layout', () => {
cy.get('.q-page').should('be.visible'); cy.get('.q-page').should('be.visible');
}); });
it('Should create a mandate', () => {
cy.get('.q-page-sticky > div > .q-btn').click();
cy.dataCy('paymentBank').type({ arroyDown });
cy.dataCy('paymentAmount').type('100');
cy.saveCard();
});
}); });