Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions apps/web-app/server/api/kitchen/revenue/iiko-daily.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async function parseFileAndUpdateData(file: MultiPartData) {
})
}

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

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

// Remove first 4 rows and last row
const dataRows = data.slice(4, data.length - 1)
// Remove first 5 rows and last row
const dataRows = data.slice(5, data.length - 1)
if (!dataRows) {
throw createError({
statusCode: 400,
message: 'Invalid data',
})
}

const parsedKitchens: { name: string, total: number }[] = []
const parsedKitchens: { name: string, total: number, checks: number }[] = []

for (const row of dataRows) {
const name = row[indexOfName]
const total = row[indexOfTotal]
const checks = row[indexOfChecks]

if (typeof name !== 'string' || typeof total !== 'number') {
if (typeof name !== 'string' || typeof total !== 'number' || typeof checks !== 'number') {
continue
}

parsedKitchens.push({
name,
total,
checks,
})
}

Expand All @@ -151,10 +154,12 @@ async function parseFileAndUpdateData(file: MultiPartData) {
kitchenId: found.id,
date: dateOnly,
total: kitchen.total,
checks: kitchen.checks,
})
} else {
await repository.kitchen.updateRevenue(revenue.id, {
total: kitchen.total,
checks: kitchen.checks,
})
}

Expand Down
1 change: 1 addition & 0 deletions packages/database/src/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ export const kitchenRevenues = pgTable('kitchen_revenues', {
updatedAt: timestamp('updated_at', { precision: 3, withTimezone: true, mode: 'string' }).notNull().defaultNow(),
date: date('date', { mode: 'string' }).notNull(),
total: numeric('total', { mode: 'number' }).notNull().default(0),
checks: integer('checks').notNull().default(0),
kitchenId: cuid2('kitchen_id').notNull().references(() => kitchens.id),
})

Expand Down