Skip to content

Commit 516f5d8

Browse files
committed
feat: checks
1 parent 4b6b86c commit 516f5d8

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

apps/web-app/server/api/kitchen/revenue/iiko-daily.post.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ async function parseFileAndUpdateData(file: MultiPartData) {
7575
})
7676
}
7777

78-
const dictionary = data[3]
78+
const dictionary = data[4] // 4th row - empty, 5th - column names
7979
if (!dictionary) {
8080
throw createError({
8181
statusCode: 400,
@@ -85,7 +85,8 @@ async function parseFileAndUpdateData(file: MultiPartData) {
8585

8686
const indexOfName = dictionary.indexOf('Группа')
8787
const indexOfTotal = dictionary.indexOf('Сумма со скидкой, р. Всего')
88-
if (!dictionary || indexOfName < 0 || indexOfTotal < 0) {
88+
const indexOfChecks = dictionary.indexOf('Чеков')
89+
if (!dictionary || indexOfName < 0 || indexOfTotal < 0 || indexOfChecks < 0) {
8990
throw createError({
9091
statusCode: 400,
9192
message: 'Invalid dictionary',
@@ -111,28 +112,30 @@ async function parseFileAndUpdateData(file: MultiPartData) {
111112
})
112113
}
113114

114-
// Remove first 4 rows and last row
115-
const dataRows = data.slice(4, data.length - 1)
115+
// Remove first 5 rows and last row
116+
const dataRows = data.slice(5, data.length - 1)
116117
if (!dataRows) {
117118
throw createError({
118119
statusCode: 400,
119120
message: 'Invalid data',
120121
})
121122
}
122123

123-
const parsedKitchens: { name: string, total: number }[] = []
124+
const parsedKitchens: { name: string, total: number, checks: number }[] = []
124125

125126
for (const row of dataRows) {
126127
const name = row[indexOfName]
127128
const total = row[indexOfTotal]
129+
const checks = row[indexOfChecks]
128130

129-
if (typeof name !== 'string' || typeof total !== 'number') {
131+
if (typeof name !== 'string' || typeof total !== 'number' || typeof checks !== 'number') {
130132
continue
131133
}
132134

133135
parsedKitchens.push({
134136
name,
135137
total,
138+
checks,
136139
})
137140
}
138141

@@ -151,10 +154,12 @@ async function parseFileAndUpdateData(file: MultiPartData) {
151154
kitchenId: found.id,
152155
date: dateOnly,
153156
total: kitchen.total,
157+
checks: kitchen.checks,
154158
})
155159
} else {
156160
await repository.kitchen.updateRevenue(revenue.id, {
157161
total: kitchen.total,
162+
checks: kitchen.checks,
158163
})
159164
}
160165

packages/database/src/tables.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ export const kitchenRevenues = pgTable('kitchen_revenues', {
420420
updatedAt: timestamp('updated_at', { precision: 3, withTimezone: true, mode: 'string' }).notNull().defaultNow(),
421421
date: date('date', { mode: 'string' }).notNull(),
422422
total: numeric('total', { mode: 'number' }).notNull().default(0),
423+
checks: integer('checks').notNull().default(0),
423424
kitchenId: cuid2('kitchen_id').notNull().references(() => kitchens.id),
424425
})
425426

0 commit comments

Comments
 (0)