feat(tahesab): sales report snapshot with org-module gate
Sync linked asnad into CRM, filter by group/kind/metal, and require the tahesab superadmin module plus reports role access.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
@@ -13,11 +14,14 @@ import { JwtAuthGuard } from '../../auth/jwt-auth.guard';
|
||||
import { CurrentUser } from '../../auth/current-user.decorator';
|
||||
import { Roles } from '../../auth/roles.decorator';
|
||||
import { RolesGuard } from '../../auth/roles.guard';
|
||||
import { OrgModuleGuard } from '../../billing/org-module.guard';
|
||||
import { RequireOrgModule } from '../../billing/org-module.decorator';
|
||||
import { TahesabConnectionsService } from './connections.service';
|
||||
import { TahesabPersonLinkService } from './person-link.service';
|
||||
import { TahesabProductLinkService } from './product-link.service';
|
||||
import { TahesabBalanceService } from './balance.service';
|
||||
import { TahesabDocumentsService } from './documents.service';
|
||||
import { TahesabAsnadReportService } from './asnad-report.service';
|
||||
import {
|
||||
CreateInTahesabDto,
|
||||
CreateTahesabConnectionDto,
|
||||
@@ -31,12 +35,14 @@ import {
|
||||
PushSanadDto,
|
||||
SearchTahesabDto,
|
||||
SearchTahesabProductsDto,
|
||||
SyncAsnadReportDto,
|
||||
SyncGroupsPageDto,
|
||||
UpdateTahesabConnectionDto,
|
||||
} from './dto';
|
||||
|
||||
@Controller('integrations/tahesab')
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@UseGuards(JwtAuthGuard, RolesGuard, OrgModuleGuard)
|
||||
@RequireOrgModule('tahesab')
|
||||
export class TahesabController {
|
||||
constructor(
|
||||
private readonly connections: TahesabConnectionsService,
|
||||
@@ -44,6 +50,7 @@ export class TahesabController {
|
||||
private readonly products: TahesabProductLinkService,
|
||||
private readonly balance: TahesabBalanceService,
|
||||
private readonly documents: TahesabDocumentsService,
|
||||
private readonly asnadReport: TahesabAsnadReportService,
|
||||
) {}
|
||||
|
||||
// —— Connections ——
|
||||
@@ -271,4 +278,107 @@ export class TahesabController {
|
||||
) {
|
||||
return this.products.importBulk(user.organizationId, dto);
|
||||
}
|
||||
|
||||
// —— گزارش فروش اسناد (اسنپشات DoListAsnad) ——
|
||||
@Post('reports/asnad/sync')
|
||||
@Roles('owner', 'admin', 'sales')
|
||||
syncAsnadReport(
|
||||
@CurrentUser() user: { organizationId: string },
|
||||
@Body() dto: SyncAsnadReportDto,
|
||||
) {
|
||||
return this.asnadReport.startSync(
|
||||
user.organizationId,
|
||||
dto.connectionId,
|
||||
dto.from,
|
||||
dto.to,
|
||||
);
|
||||
}
|
||||
|
||||
@Get('reports/asnad/sync/:jobId')
|
||||
syncAsnadReportStatus(
|
||||
@CurrentUser() user: { organizationId: string },
|
||||
@Param('jobId') jobId: string,
|
||||
) {
|
||||
return this.asnadReport.getSyncJob(user.organizationId, jobId);
|
||||
}
|
||||
|
||||
@Get('reports/asnad/summary')
|
||||
asnadReportSummary(
|
||||
@CurrentUser() user: { organizationId: string },
|
||||
@Query('connectionId') connectionId?: string,
|
||||
@Query('from') from?: string,
|
||||
@Query('to') to?: string,
|
||||
@Query('groupIds') groupIds?: string | string[],
|
||||
@Query('personId') personId?: string,
|
||||
@Query('kinds') kinds?: string | string[],
|
||||
@Query('jensFelez') jensFelez?: string,
|
||||
) {
|
||||
if (!from || !to) {
|
||||
throw new BadRequestException('پارامتر from و to الزامی است.');
|
||||
}
|
||||
return this.asnadReport.summary(user.organizationId, {
|
||||
connectionId,
|
||||
from,
|
||||
to,
|
||||
...this.parseAsnadFilters(groupIds, personId, kinds, jensFelez),
|
||||
});
|
||||
}
|
||||
|
||||
@Get('reports/asnad')
|
||||
listAsnadReport(
|
||||
@CurrentUser() user: { organizationId: string },
|
||||
@Query('connectionId') connectionId?: string,
|
||||
@Query('from') from?: string,
|
||||
@Query('to') to?: string,
|
||||
@Query('groupIds') groupIds?: string | string[],
|
||||
@Query('personId') personId?: string,
|
||||
@Query('kinds') kinds?: string | string[],
|
||||
@Query('jensFelez') jensFelez?: string,
|
||||
@Query('page') page?: string,
|
||||
@Query('pageSize') pageSize?: string,
|
||||
) {
|
||||
if (!from || !to) {
|
||||
throw new BadRequestException('پارامتر from و to الزامی است.');
|
||||
}
|
||||
return this.asnadReport.query(user.organizationId, {
|
||||
connectionId,
|
||||
from,
|
||||
to,
|
||||
...this.parseAsnadFilters(groupIds, personId, kinds, jensFelez),
|
||||
page: page ? Number(page) : undefined,
|
||||
pageSize: pageSize ? Number(pageSize) : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
private parseAsnadFilters(
|
||||
groupIds?: string | string[],
|
||||
personId?: string,
|
||||
kinds?: string | string[],
|
||||
jensFelez?: string,
|
||||
) {
|
||||
const groups = Array.isArray(groupIds)
|
||||
? groupIds
|
||||
: groupIds
|
||||
? groupIds
|
||||
.split(',')
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean)
|
||||
: undefined;
|
||||
const kindList = Array.isArray(kinds)
|
||||
? kinds
|
||||
: kinds
|
||||
? kinds
|
||||
.split(',')
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean)
|
||||
: undefined;
|
||||
const jf =
|
||||
jensFelez != null && jensFelez !== '' ? Number(jensFelez) : undefined;
|
||||
return {
|
||||
groupIds: groups,
|
||||
personId,
|
||||
kinds: kindList,
|
||||
jensFelez: jf != null && Number.isFinite(jf) ? jf : undefined,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user