Skip to content

Commit b1a6d47

Browse files
authored
feat: partner invoices (#222)
1 parent 658cb0f commit b1a6d47

6 files changed

Lines changed: 36 additions & 1 deletion

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@
6161
</div>
6262

6363
<div class="min-h-20 h-full px-4 pb-2 flex flex-col gap-2.5">
64+
<UBadge
65+
:color="partner.balance >= 0 ? 'neutral' : 'error'"
66+
variant="soft"
67+
size="md"
68+
class="rounded-lg justify-center font-semibold"
69+
:label="`Баланс ${new Intl.NumberFormat().format(partner.balance)} руб`"
70+
/>
71+
6472
<h3 class="text-sm/4 font-bold">
6573
{{ partner.legalEntity?.name }}
6674
</h3>

apps/web-app/app/stores/partner.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Kitchen, Partner, PartnerAgreement, PartnerAgreementFile, PartnerLegalEntity, User } from '@roll-stack/database'
1+
import type { Invoice, Kitchen, Partner, PartnerAgreement, PartnerAgreementFile, PartnerLegalEntity, User } from '@roll-stack/database'
22

33
export type PartnerAgreementWithAllData = PartnerAgreement & {
44
files: PartnerAgreementFile[]
@@ -18,6 +18,7 @@ export type PartnerWithData = Partner & {
1818
kitchens: Kitchen[]
1919
legalEntity: PartnerLegalEntityWithData | null
2020
users: User[]
21+
invoices: Invoice[]
2122
}
2223

2324
export const usePartnerStore = defineStore('partner', () => {

packages/database/src/repository/partner.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export class Partner {
4646
},
4747
},
4848
users: true,
49+
invoices: true,
4950
},
5051
})
5152

packages/database/src/tables.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export const partners = pgTable('partners', {
3737
updatedAt: timestamp('updated_at', { precision: 3, withTimezone: true, mode: 'string' }).notNull().defaultNow(),
3838
priceLevel: integer('price_level').notNull().default(0),
3939
prestige: integer('prestige').notNull().default(0),
40+
balance: numeric('balance', { mode: 'number' }).notNull().default(0),
4041
isActive: boolean('is_active').notNull().default(true),
4142
city: varchar('city'),
4243
legalEntityId: cuid2('legal_entity_id').references(() => partnerLegalEntities.id),
@@ -780,6 +781,17 @@ export const flowItemViews = pgTable('flow_item_views', {
780781
}),
781782
})
782783

784+
export const invoices = pgTable('invoices', {
785+
id: cuid2('id').defaultRandom().primaryKey(),
786+
createdAt: timestamp('created_at', { precision: 3, withTimezone: true, mode: 'string' }).notNull().defaultNow(),
787+
updatedAt: timestamp('updated_at', { precision: 3, withTimezone: true, mode: 'string' }).notNull().defaultNow(),
788+
title: varchar('title').notNull(),
789+
total: numeric('total', { mode: 'number' }).notNull().default(0),
790+
paid: numeric('paid', { mode: 'number' }).notNull().default(0),
791+
status: varchar('status').notNull().$type<entities.InvoiceStatus>().default('unpaid'),
792+
partnerId: cuid2('partner_id').references(() => partners.id),
793+
})
794+
783795
export const userRelations = relations(users, ({ many, one }) => ({
784796
chatMessages: many(chatMessages),
785797
chatMembers: many(chatMembers),
@@ -805,6 +817,7 @@ export const userRelations = relations(users, ({ many, one }) => ({
805817
export const partnerRelations = relations(partners, ({ many, one }) => ({
806818
kitchens: many(kitchens),
807819
users: many(users),
820+
invoices: many(invoices),
808821
legalEntity: one(partnerLegalEntities, {
809822
fields: [partners.legalEntityId],
810823
references: [partnerLegalEntities.id],
@@ -1284,3 +1297,10 @@ export const flowItemViewRelations = relations(flowItemViews, ({ one }) => ({
12841297
references: [flowItems.id],
12851298
}),
12861299
}))
1300+
1301+
export const invoiceRelations = relations(invoices, ({ one }) => ({
1302+
partner: one(partners, {
1303+
fields: [invoices.partnerId],
1304+
references: [partners.id],
1305+
}),
1306+
}))

packages/database/src/types/entities.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,5 @@ export type ActivityScheduleTag = 'permanent'
9696
| 'temporary'
9797
| 'optional'
9898
| 'advertising'
99+
100+
export type InvoiceStatus = 'paid' | 'unpaid'

packages/database/src/types/tables.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,6 @@ export type FlowItemCommentDraft = InferInsertModel<typeof tables.flowItemCommen
171171

172172
export type FlowItemView = InferSelectModel<typeof tables.flowItemViews>
173173
export type FlowItemViewDraft = InferInsertModel<typeof tables.flowItemViews>
174+
175+
export type Invoice = InferSelectModel<typeof tables.invoices>
176+
export type InvoiceDraft = InferInsertModel<typeof tables.invoices>

0 commit comments

Comments
 (0)