feat: categoria is_tax exclui impostos do denominador do savings_pct

savings_pct = (receita - despesas) / (receita - impostos).
Toggle IMPOSTO no CRUD de categorias; badge dourado na lista.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This commit is contained in:
2026-05-27 15:53:53 -03:00
co-authored by Claude Sonnet 4.6
parent 2cf6d94a03
commit 7dae05cabf
10 changed files with 90 additions and 35 deletions
+5 -4
View File
@@ -7,6 +7,7 @@ export interface Category {
name: string
color: string
is_default: boolean
is_tax: boolean
created_at: string
updated_at: string
}
@@ -28,14 +29,14 @@ export const useCategoriesStore = defineStore('categories', () => {
}
}
async function create(name: string, color: string) {
const cat = await api.post<Category>('/categories', { name, color })
async function create(name: string, color: string, isTax = false) {
const cat = await api.post<Category>('/categories', { name, color, is_tax: isTax })
categories.value.push(cat)
return cat
}
async function update(id: number, name: string, color: string) {
const cat = await api.put<Category>(`/categories/${id}`, { name, color })
async function update(id: number, name: string, color: string, isTax = false) {
const cat = await api.put<Category>(`/categories/${id}`, { name, color, is_tax: isTax })
const idx = categories.value.findIndex((c) => c.id === id)
if (idx !== -1) categories.value[idx] = cat
return cat
+32 -8
View File
@@ -6,19 +6,19 @@ import NeonPanel from '@/components/NeonPanel.vue'
const store = useCategoriesStore()
onMounted(() => store.fetchAll())
const form = ref({ name: '', color: '#a855f7' })
const form = ref({ name: '', color: '#a855f7', is_tax: false })
const editId = ref<number | null>(null)
const formError = ref<string | null>(null)
function startEdit(id: number, name: string, color: string) {
function startEdit(id: number, name: string, color: string, isTax: boolean) {
editId.value = id
form.value = { name, color }
form.value = { name, color, is_tax: isTax }
formError.value = null
}
function cancelEdit() {
editId.value = null
form.value = { name: '', color: '#a855f7' }
form.value = { name: '', color: '#a855f7', is_tax: false }
formError.value = null
}
@@ -26,11 +26,11 @@ async function submit() {
formError.value = null
try {
if (editId.value !== null) {
await store.update(editId.value, form.value.name, form.value.color)
await store.update(editId.value, form.value.name, form.value.color, form.value.is_tax)
cancelEdit()
} else {
await store.create(form.value.name, form.value.color)
form.value = { name: '', color: '#a855f7' }
await store.create(form.value.name, form.value.color, form.value.is_tax)
form.value = { name: '', color: '#a855f7', is_tax: false }
}
} catch (e: any) {
formError.value = e.message
@@ -61,6 +61,10 @@ async function remove(id: number, name: string) {
<input type="color" v-model="form.color" class="fc-color-input" />
<span class="fc-mono fc-cat-form__hex">{{ form.color }}</span>
</div>
<label class="fc-cat-form__tax fc-mono">
<input type="checkbox" v-model="form.is_tax" />
IMPOSTO
</label>
</div>
<p v-if="formError" class="fc-cat-form__error fc-mono">{{ formError }}</p>
<div class="fc-cat-form__actions">
@@ -84,8 +88,9 @@ async function remove(id: number, name: string) {
<span class="fc-cat-item__dot" :style="{ background: cat.color }" />
<span class="fc-body fc-cat-item__name">{{ cat.name }}</span>
<span v-if="cat.is_default" class="fc-pixel fc-cat-item__default">PADRÃO</span>
<span v-if="cat.is_tax" class="fc-pixel fc-cat-item__tax">IMPOSTO</span>
<div class="fc-cat-item__actions">
<button class="fc-btn fc-btn--sm fc-btn--ghost" @click="startEdit(cat.id, cat.name, cat.color)">EDITAR</button>
<button class="fc-btn fc-btn--sm fc-btn--ghost" @click="startEdit(cat.id, cat.name, cat.color, cat.is_tax)">EDITAR</button>
<button
v-if="!cat.is_default"
class="fc-btn fc-btn--sm fc-btn--danger"
@@ -211,5 +216,24 @@ async function remove(id: number, name: string) {
border-radius: 2px;
}
.fc-cat-item__tax {
font-size: 6px;
color: var(--fc-gold);
background: rgba(255,180,0,.15);
border: 1px solid rgba(255,180,0,.4);
padding: 3px 6px;
border-radius: 2px;
}
.fc-cat-form__tax {
display: flex;
align-items: center;
gap: 6px;
font-size: 10px;
color: var(--fc-text-dim);
cursor: pointer;
flex-shrink: 0;
}
.fc-cat-item__actions { display: flex; gap: var(--fc-space-1); }
</style>