feat(statistics): implement statistics module with controller and service for POS invoices

This commit is contained in:
2026-05-23 18:09:41 +03:30
parent 2dc9480170
commit 2c97b7302d
8 changed files with 317 additions and 0 deletions
+82
View File
@@ -0,0 +1,82 @@
import dayjs, { Dayjs } from 'dayjs'
import 'dayjs/locale/fa'
import relativeTime from 'dayjs/plugin/relativeTime'
import jalaliPlugin from 'jalaliday/dayjs'
dayjs.extend(jalaliPlugin)
dayjs.extend(relativeTime)
export function toJalali(date: string | number | Date | Dayjs): Date {
return dayjs(date).calendar('jalali').toDate()
}
export function toGregorian(date: string | number | Date | Dayjs): Date {
return dayjs(date).calendar('gregory').toDate()
}
export function getCurrentJalaliSeasonStart(
baseDate: string | number | Date | Dayjs = dayjs(),
): Date {
const date = dayjs(baseDate).calendar('jalali')
const month = date.month() + 1
const seasonStartMonth = Math.floor((month - 1) / 3) * 3 + 1
return date.month(seasonStartMonth - 1).startOf('month').startOf('day').toDate()
}
export function getCurrentJalaliSeasonEnd(
baseDate: string | number | Date | Dayjs = dayjs(),
): Date {
return dayjs(getCurrentJalaliSeasonStart(baseDate))
.add(2, 'month')
.endOf('month')
.endOf('day')
.toDate()
}
export function getCurrentGregorianSeasonStart(
baseDate: string | number | Date | Dayjs = dayjs(),
): Date {
const date = dayjs(baseDate).calendar('gregory')
const month = date.month() + 1
const seasonStartMonth = Math.floor((month - 1) / 3) * 3 + 1
return date.month(seasonStartMonth - 1).startOf('month').startOf('day').toDate()
}
export function getCurrentGregorianSeasonEnd(
baseDate: string | number | Date | Dayjs = dayjs(),
): Date {
return dayjs(getCurrentGregorianSeasonStart(baseDate))
.add(2, 'month')
.endOf('month')
.endOf('day')
.toDate()
}
export function getCurrentJalaliSeasonRange(
baseDate: string | number | Date | Dayjs = dayjs(),
): { start: Date; end: Date } {
return {
start: getCurrentJalaliSeasonStart(baseDate),
end: getCurrentJalaliSeasonEnd(baseDate),
}
}
export function getCurrentGregorianSeasonRange(
baseDate: string | number | Date | Dayjs = dayjs(),
): { start: Date; end: Date } {
return {
start: getCurrentGregorianSeasonStart(baseDate),
end: getCurrentGregorianSeasonEnd(baseDate),
}
}
export default {
toJalali,
toGregorian,
getCurrentJalaliSeasonStart,
getCurrentJalaliSeasonEnd,
getCurrentGregorianSeasonStart,
getCurrentGregorianSeasonEnd,
getCurrentJalaliSeasonRange,
getCurrentGregorianSeasonRange,
}
+1
View File
@@ -1,3 +1,4 @@
export * from './date-formatter.utils'
export * from './enum-translator.util'
export * from './field-validator.util'
export * from './http-client.util'
+46
View File
@@ -14,4 +14,50 @@ export class PosKeyMaker {
static goodListByGuildPattern(guildId: string): string {
return `pos:goods:list:guildId:${guildId}:ba:*`
}
static statisticInvoicesPattern(businessActivityId: string): string {
return `pos:statistics:invoices:ba:${businessActivityId}:*`
}
static statisticInvoices(
businessActivityId: string,
posId: string,
from: string,
): string {
return `pos:statistics:invoices:ba:${businessActivityId}:pos:${posId}:from:${from}:all`
}
static statisticInvoicesNotSent(
businessActivityId: string,
posId: string,
from: string,
): string {
return `pos:statistics:invoices:ba:${businessActivityId}:pos:${posId}:from:${from}:not-sent`
}
static statisticInvoicesSuccess(
businessActivityId: string,
posId: string,
from: string,
): string {
return `pos:statistics:invoices:ba:${businessActivityId}:pos:${posId}:from:${from}:success`
}
static statisticInvoicesFailure(
businessActivityId: string,
posId: string,
from: string,
): string {
return `pos:statistics:invoices:ba:${businessActivityId}:pos:${posId}:from:${from}:failure`
}
static statisticInvoicesPending(
businessActivityId: string,
posId: string,
from: string,
): string {
return `pos:statistics:invoices:ba:${businessActivityId}:pos:${posId}:from:${from}:pending`
}
static statisticInvoicesCredit(
businessActivityId: string,
posId: string,
from: string,
): string {
return `pos:statistics:invoices:ba:${businessActivityId}:pos:${posId}:from:${from}:credit`
}
}