Skip to content

Commit 7a9c357

Browse files
authored
chore: invoice updated (#237)
1 parent f80cf5b commit 7a9c357

File tree

7 files changed

+50
-24
lines changed

7 files changed

+50
-24
lines changed

apps/web-app/app/components/InvoiceCard.vue

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<UCard class="group/list">
33
<div class="flex flex-col gap-2.5">
44
<div class="flex flex-row justify-between">
5-
<UIcon name="i-lucide-banknote-arrow-up" class="size-14 text-primary" />
5+
<UIcon name="i-lucide-banknote-arrow-up" class="size-10 text-muted/50" />
66

77
<UButton
88
variant="outline"
@@ -14,6 +14,10 @@
1414
/>
1515
</div>
1616

17+
<div class="text-sm/4 text-muted">
18+
Создан {{ format(new Date(invoice.createdAt), 'd MMMM в HH:mm', { locale: ru }) }}
19+
</div>
20+
1721
<h3 class="text-xl md:text-xl/6 font-semibold">
1822
{{ new Intl.NumberFormat().format(invoice.total) }} ₽
1923
</h3>
@@ -22,7 +26,7 @@
2226
{{ invoice.title }}
2327
</p>
2428

25-
<p class="text-sm/4 text-muted">
29+
<p v-if="invoice.description" class="text-sm/4 text-muted">
2630
{{ invoice.description }}
2731
</p>
2832

@@ -36,7 +40,7 @@
3640

3741
<UBadge
3842
:label="getInfoByStatus(invoice.status)"
39-
:color="invoice.status === 'unpaid' ? 'error' : 'success'"
43+
:color="invoice.status === 'unpaid' ? 'error' : 'neutral'"
4044
size="md"
4145
variant="soft"
4246
/>
@@ -48,6 +52,8 @@
4852
<script setup lang="ts">
4953
import type { Invoice } from '@roll-stack/database'
5054
import { ModalUpdateInvoice } from '#components'
55+
import { format } from 'date-fns'
56+
import { ru } from 'date-fns/locale/ru'
5157
5258
defineProps<{
5359
invoice: Invoice
@@ -59,8 +65,16 @@ function getInfoByType(type: Invoice['type']) {
5965
return 'Пополнение'
6066
case 'royalties':
6167
return 'Роялти'
68+
case 'lump_sum_fee':
69+
return 'Паушальный взнос'
70+
case 'marketing_fee':
71+
return 'Маркетинговый сбор'
72+
case 'rospatent_fee':
73+
return 'Роспатент'
6274
case 'other':
6375
return 'Другое'
76+
default:
77+
return 'Другое'
6478
}
6579
}
6680
@@ -70,6 +84,8 @@ function getInfoByStatus(status: Invoice['status']) {
7084
return 'Не оплачен'
7185
case 'paid':
7286
return 'Оплачен'
87+
default:
88+
return 'Неизвестно'
7389
}
7490
}
7591

apps/web-app/app/components/form/CreateInvoice.vue

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@
3131
<UFormField label="Тип" name="type">
3232
<USelect
3333
v-model="state.type"
34-
:items="[
35-
{ label: 'Оплата роялти', value: 'royalties' },
36-
{ label: 'Пополнение', value: 'replenishment' },
37-
{ label: 'Другое', value: 'other' },
38-
]"
34+
:items="getInvoiceTypeForSelect()"
3935
:placeholder="$t('common.select')"
4036
size="xl"
4137
class="w-full"
@@ -72,6 +68,7 @@
7268
import type { CreatePartnerInvoice } from '#shared/services/partner'
7369
import type { FormSubmitEvent } from '@nuxt/ui'
7470
import { createPartnerInvoiceSchema } from '#shared/services/partner'
71+
import { getInvoiceTypeForSelect } from '#shared/utils/helpers'
7572
7673
const { partnerId } = defineProps<{ partnerId?: string }>()
7774
const emit = defineEmits(['success', 'submitted'])

apps/web-app/app/components/form/UpdateInvoice.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@
4848
<UFormField label="Тип" name="type">
4949
<USelect
5050
v-model="state.type"
51-
:items="[
52-
{ label: 'Оплата роялти', value: 'royalties' },
53-
{ label: 'Пополнение', value: 'replenishment' },
54-
]"
51+
:items="getInvoiceTypeForSelect()"
5552
:placeholder="$t('common.select')"
5653
size="xl"
5754
class="w-full"
@@ -88,6 +85,7 @@
8885
import type { UpdatePartnerInvoice } from '#shared/services/partner'
8986
import type { FormSubmitEvent } from '@nuxt/ui'
9087
import { updatePartnerInvoiceSchema } from '#shared/services/partner'
88+
import { getInvoiceTypeForSelect } from '#shared/utils/helpers'
9189
9290
const { invoiceId } = defineProps<{
9391
invoiceId: string

apps/web-app/app/pages/partner/[id]/invoice.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<PartnerBalanceCard :balance="partner?.balance ?? 0" />
55

66
<InvoiceCard
7-
v-for="invoice in activeInvoices"
7+
v-for="invoice in invoices"
88
:key="invoice.id"
99
:invoice="invoice"
1010
/>
@@ -28,8 +28,7 @@ const { params } = useRoute('partner-id')
2828
2929
const partnerStore = usePartnerStore()
3030
const partner = computed(() => partnerStore.partners.find((partner) => partner.id === params.id))
31-
32-
const activeInvoices = computed(() => partner.value?.invoices)
31+
const invoices = computed(() => partner.value?.invoices.toSorted((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()))
3332
3433
const overlay = useOverlay()
3534
const modalCreateInvoice = overlay.create(ModalCreateInvoice)

apps/web-app/server/services/invoice.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ export async function recountPartnerBalance(partnerId: string) {
55

66
let balance = 0
77
for (const invoice of partnerInvoices) {
8-
if (invoice.type === 'replenishment' && invoice.status === 'paid') {
9-
balance += invoice.total
10-
}
8+
if (invoice.type === 'replenishment') {
9+
if (invoice.status === 'paid') {
10+
balance += invoice.total
11+
}
1112

12-
if (invoice.type === 'royalties') {
13-
balance -= invoice.total
14-
}
15-
if (invoice.type === 'other') {
16-
balance -= invoice.total
13+
continue
1714
}
15+
16+
// All other invoices
17+
balance -= invoice.total
1818
}
1919

2020
await db.partner.update(partnerId, {

apps/web-app/shared/utils/helpers.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
import type { AgreementPatentStatus, User } from '@roll-stack/database'
22
import type { Resolution } from '../services/task'
33

4+
export function getInvoiceTypeForSelect() {
5+
return [
6+
{ label: 'Оплата роялти', value: 'royalties' },
7+
{ label: 'Паушальный взнос', value: 'lump_sum_fee' },
8+
{ label: 'Маркетинговый сбор', value: 'marketing_fee' },
9+
{ label: 'Роспатент', value: 'rospatent_fee' },
10+
{ label: 'Пополнение', value: 'replenishment' },
11+
{ label: 'Другое', value: 'other' },
12+
]
13+
}
14+
415
export function getResolutionForSelect(): { value: Resolution, label: string, icon: string }[] {
516
return [
617
{ value: 'success', label: 'Успешно выполнена', icon: 'i-lucide-circle-check' },

packages/database/src/types/entities.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,10 @@ export type ActivityScheduleTag = 'permanent'
9797
| 'optional'
9898
| 'advertising'
9999

100-
export type InvoiceType = 'replenishment' | 'royalties' | 'other'
100+
export type InvoiceType = 'replenishment'
101+
| 'royalties' // Роялти
102+
| 'lump_sum_fee' // Паушальный взнос
103+
| 'marketing_fee' // Маркетинговый сбор
104+
| 'rospatent_fee' // Роспатент
105+
| 'other'
101106
export type InvoiceStatus = 'paid' | 'unpaid'

0 commit comments

Comments
 (0)