Compare commits

...

3 Commits

3 changed files with 83 additions and 4 deletions

View File

@ -930,6 +930,7 @@ worker:
debit: Debt debit: Debt
credit: Have credit: Have
concept: Concept concept: Concept
id: id
wagon: wagon:
type: type:
name: Name name: Name

View File

@ -927,6 +927,7 @@ worker:
debit: Debe debit: Debe
credit: Haber credit: Haber
concept: Concepto concept: Concepto
id: id
wagon: wagon:
type: type:
name: Nombre name: Nombre

View File

@ -1,14 +1,45 @@
<script setup> <script setup>
import { ref, computed } from 'vue'; import axios from 'axios';
import { ref, computed, onMounted } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import { useQuasar } from 'quasar';
import { useVnConfirm } from 'composables/useVnConfirm';
import VnTable from 'components/VnTable/VnTable.vue'; import VnTable from 'components/VnTable/VnTable.vue';
import { useStateStore } from 'stores/useStateStore';
import { toCurrency } from 'filters/index';
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 quasar = useQuasar();
const { openConfirmationModal } = useVnConfirm();
const amount = ref();
const positiveAmount = ref();
const negativeAmount = ref();
const stateStore = useStateStore();
async function fetchBalance(rows, newRows) {
if (newRows) rows = newRows;
positiveAmount.value = 0;
negativeAmount.value = 0;
if (!rows || !rows.length) return;
for (const row of rows) {
positiveAmount.value = positiveAmount.value + row.debit;
negativeAmount.value = negativeAmount.value + row.credit;
}
return (amount.value = positiveAmount.value - negativeAmount.value);
}
const columns = computed(() => [ const columns = computed(() => [
{
align: 'left',
name: 'id',
label: t('worker.balance.tableVisibleColumns.id'),
field: 'id',
cardVisible: true,
},
{ {
align: 'left', align: 'left',
name: 'paymentDate', name: 'paymentDate',
@ -57,11 +88,55 @@ const columns = computed(() => [
field: 'concept', field: 'concept',
cardVisible: true, cardVisible: true,
}, },
{
align: 'right',
label: '',
name: 'tableActions',
actions: [
{
title: t('Remove'),
icon: 'delete',
action: (row) =>
openConfirmationModal(
t('Do you want to delete this entry?'),
t(''),
() => deleteBalance(row)
),
isPrimary: true,
},
],
},
]); ]);
async function deleteBalance({ id }) {
try {
await axios.delete(`workerIncomes/${id}`);
quasar.notify({
message: t('Remove incomes'),
type: 'positive',
});
tableRef.value.reload();
} catch (error) {
quasar.notify({
message: t('Error'),
type: 'error',
});
}
}
</script> </script>
<template> <template>
<Teleport to="#st-data" v-if="stateStore.isSubToolbarShown()">
<div class="row q-gutter-md">
<div>
{{ t('Total:') }}
<QChip :dense="$q.screen.lt.sm" text-color="white">
{{ toCurrency(amount) }}
</QChip>
</div>
</div>
</Teleport>
<VnTable <VnTable
class="column flex-center"
ref="tableRef" ref="tableRef"
data-key="WorkerBalance" data-key="WorkerBalance"
:url="`Workers/${entityId}/incomes`" :url="`Workers/${entityId}/incomes`"
@ -69,8 +144,8 @@ const columns = computed(() => [
save-url="WorkerIncomes/crud" save-url="WorkerIncomes/crud"
:create="{ :create="{
urlCreate: 'workerIncomes', urlCreate: 'workerIncomes',
title: t('Create workerBalance'), title: t('Create Balance'),
onDataSaved: () => tableRef.reload(), onDataSaved: () => fetchBalance(),
formInitialData: { formInitialData: {
workerFk: entityId, workerFk: entityId,
}, },
@ -81,10 +156,12 @@ const columns = computed(() => [
:right-search="false" :right-search="false"
:is-editable="true" :is-editable="true"
:use-model="true" :use-model="true"
@on-fetch="fetchBalance"
/> />
</template> </template>
<i18n> <i18n>
es: es:
Create workerBalance: Crear balance Create Balance: Crear balance
Do you want to delete this entry?: ¿Desea eliminar esta entrada?
</i18n> </i18n>