Files
psp_api/src/modules/tspProviders/switch/nama/nama-provider.dto.ts
T
ahasani ea6f1bfdd0 feat: add settlement_type to SalesInvoice model and related DTOs
- Added settlement_type field to SalesInvoice model with ENUM values (CASH, CREDIT, MIXED).
- Updated SalesInvoice aggregate types, input types, and where filters to include settlement_type.
- Modified StatisticsService to calculate credit amounts based on settlement_type.
- Enhanced TspProviderOriginalSendPayloadDto to include settlement_type.
- Updated NamaProvider DTOs and utility functions to handle new settlement_type logic.
- Created migration to add settlement_type column to sales_invoices table and backfill existing records.
2026-05-24 19:40:04 +03:30

562 lines
12 KiB
TypeScript

import { TspProviderResponseStatus } from '@/generated/prisma/enums'
import { ApiProperty } from '@nestjs/swagger'
import { Type } from 'class-transformer'
import {
IsArray,
IsEnum,
IsNumber,
IsOptional,
IsString,
Min,
ValidateNested,
} from 'class-validator'
export enum NamaProviderResponseStatus {
POSTED = 'SUCCESS',
PENDING = 'PENDING',
IN_PROGRESS = 'IN_PROGRESS',
SUCCESS = 'SUCCESS',
FAILED = 'FAILED',
}
export class NamaProviderPaymentInfoDto {
@ApiProperty({ required: true, description: 'روش پرداخت' })
@IsNumber()
pmt: number
@ApiProperty({ required: true, description: 'مبلغ پرداختی' })
@IsNumber()
@Min(10_000)
pv: number
@ApiProperty({ required: false, description: 'شماره‌ی پیگیری' })
@IsOptional()
@IsString()
trn?: string
@ApiProperty({ required: false, description: 'شماره‌ی کارت پرداخت کننده‌ی صورت‌حساب' })
@IsOptional()
@IsString()
pcn?: string
@ApiProperty({ required: false, description: 'تاریخ و زمان پرداخت صورت‌حساب unix' })
@IsOptional()
@IsNumber()
pdt?: string
}
export class NamaProviderBodyItemDto {
@ApiProperty({ required: true, description: 'شناسه کالا / خدمت' })
@IsString()
sstid: string
@ApiProperty({
required: true,
description: `نرخ مالیات بر ارزش افزوده`,
})
@IsString()
vra: string
// @ApiProperty()
// @IsString()
// sstt: string
@ApiProperty({
required: true,
description: 'مبلغ واحد',
})
@IsString()
fee: string
@ApiProperty({
required: true,
description: 'مبلغ تخفیف',
})
@IsString()
dis: string
@ApiProperty({
required: true,
description: 'واحد اندازه گیری',
})
@IsString()
mu: string
@ApiProperty({
required: true,
description: 'تعداد / مقدار',
})
@IsString()
am: string
@ApiProperty({
description: ' اجرت ساخت (طلا)',
})
@IsString()
consfee: string
@ApiProperty({
description: 'حق العمل',
})
@IsString()
bros: string
@ApiProperty({
description: 'سود فروشنده',
})
@IsString()
spro: string
}
export class NamaProviderHeaderDto {
@ApiProperty({ required: true, description: 'موضوع صورتحساب' })
@IsString()
ins: string
@ApiProperty({ required: true, description: 'الگوی صورتحساب' })
@IsString()
inp: string
@ApiProperty({ required: true, description: 'نوع صورتحساب' })
@IsString()
inty: string
// @ApiProperty({required: true})
// @IsString()
// unique_tax_code: string
@ApiProperty({ required: true, description: 'سریال صورتحساب داخلی حافظه مالیاتی' })
@IsString()
inno: string
// @ApiProperty({ required: true })
// @IsString()
// tins: string
@ApiProperty({
required: true,
description: 'تاریخ و زمان صدور صورتحساب به صورت timestamp',
})
@IsString()
indatim: string
@ApiProperty({ required: true, description: 'نام مشتری' })
@IsString()
name: string
@ApiProperty({
required: false,
description:
'نوع شخصیت خریدار (در صورتی‌که خریدار نوع ۲ باشه باید ۱ یا ۲ گذاشته بشه)',
})
@IsString()
tob: string
@ApiProperty({ description: 'آدرس' })
@IsOptional()
@IsString()
address?: string
@ApiProperty({ description: 'شماره موبایل' })
@IsOptional()
@IsString()
mobile?: string
@ApiProperty({
description: `شماره ملی / شناسه ملی / شناسه مشارکت مدنی / کد فراگیر خریدار`,
})
@IsString()
bid: string
@ApiProperty({ required: true, description: 'روش تسویه (۱.نقدی، ۲.نسیه، ۳.نقدی-نسیه)' })
@IsString()
setm: '1' | '2' | '3'
@ApiProperty({ description: 'سهم پرداخت نقدی در صورتی که نقدی - نسیه باشد (۳)' })
@IsString()
cap: string
@ApiProperty({ description: 'سهم پرداخت نسیه در صورتی که نقدی - نسیه باشد (۳)' })
@IsString()
insp: string
}
export class NamaProviderRequestDto {
@ApiProperty({ type: [NamaProviderBodyItemDto] })
@IsArray()
@ValidateNested({ each: true })
@Type(() => NamaProviderBodyItemDto)
body: NamaProviderBodyItemDto[]
@ApiProperty({ type: [NamaProviderPaymentInfoDto] })
@IsArray()
@ValidateNested({ each: true })
@Type(() => NamaProviderPaymentInfoDto)
payment: NamaProviderPaymentInfoDto[]
@ApiProperty({ type: NamaProviderHeaderDto })
@ValidateNested()
@Type(() => NamaProviderHeaderDto)
header: NamaProviderHeaderDto
@ApiProperty()
@IsString()
uuid: string
@ApiProperty()
@IsString()
economic_code: string
@ApiProperty()
@IsString()
fiscal_id: string
}
export class NamaProviderApiErrorItemDto {
@ApiProperty()
@IsString()
code: string
@ApiProperty()
@IsString()
message: string
}
export class NamaProviderApiErrorResponseDto {
@ApiProperty({ type: [NamaProviderApiErrorItemDto], required: false })
@IsOptional()
@IsArray()
@ValidateNested({ each: true })
@Type(() => NamaProviderApiErrorItemDto)
error?: NamaProviderApiErrorItemDto
}
export class NamaProviderSendItemResponseDto {
@ApiProperty()
@IsString()
uuid: string
@ApiProperty()
@IsString()
message: string
@ApiProperty()
@IsString()
status: NamaProviderResponseStatus
@ApiProperty()
@IsString()
tax_id: string
@ApiProperty()
@IsString()
inno: string
@ApiProperty({ required: true })
@IsString()
reference_number: string
@ApiProperty({ type: () => NamaProviderApiErrorResponseDto, required: false })
@IsOptional()
@ValidateNested()
@Type(() => NamaProviderApiErrorResponseDto)
tax_api_response?: NamaProviderApiErrorResponseDto
@ApiProperty({ required: false })
@IsOptional()
@IsString()
tsp_update_time: string
}
export class NamaProviderGetResponseDto {
@ApiProperty()
@IsString()
uuid: string
@ApiProperty()
@IsString()
message: string
@ApiProperty({ enum: TspProviderResponseStatus })
@IsEnum(TspProviderResponseStatus)
status: TspProviderResponseStatus
@ApiProperty()
@IsString()
tax_id: string
@ApiProperty()
@IsString()
inno: string
@ApiProperty()
@IsString()
reference_number: string
@ApiProperty()
@IsString()
tsp_update_time: string
}
export class NamaProviderRevokeHeaderDto {
@ApiProperty({ required: true, description: 'موضوع صورتحساب' })
@IsString()
ins: string
@ApiProperty({ required: true, description: 'سریال صورتحساب داخلی حافظه مالیاتی' })
@IsString()
inno: string
@ApiProperty({
required: true,
description: 'تاریخ و زمان صدور صورتحساب به صورت timestamp',
})
@IsString()
indatim: string
@ApiProperty({
required: true,
description: 'آخرین شماره مالیاتی دریافت شده مربوط به فاکتور',
})
@IsString()
irtaxid: string
}
export class NamaProviderRevokeRequestDto {
// @ApiProperty({ type: [NamaProviderBodyItemDto] })
// @IsArray()
// @ValidateNested({ each: true })
// @Type(() => NamaProviderBodyItemDto)
// body: NamaProviderBodyItemDto[]
// @ApiProperty({ type: [NamaProviderPaymentInfoDto] })
// @IsArray()
// @ValidateNested({ each: true })
// @Type(() => NamaProviderPaymentInfoDto)
// payment: NamaProviderPaymentInfoDto[]
// @ApiProperty({ type: Object, required: true })
// @IsObject()
// body: {}
@ApiProperty({ type: NamaProviderRevokeHeaderDto })
@ValidateNested()
@Type(() => NamaProviderRevokeHeaderDto)
header: NamaProviderRevokeHeaderDto
@ApiProperty()
@IsString()
uuid: string
@ApiProperty()
@IsString()
economic_code: string
@ApiProperty()
@IsString()
fiscal_id: string
}
export class NamaProviderRevokeResponseDto {
@ApiProperty()
@IsString()
uuid: string
@ApiProperty()
@IsString()
message: string
@ApiProperty()
@IsString()
status: NamaProviderResponseStatus
@ApiProperty()
@IsString()
tax_id: string
@ApiProperty()
@IsString()
inno: string
@ApiProperty({ required: true })
@IsString()
reference_number: string
@ApiProperty({ type: () => NamaProviderApiErrorResponseDto, required: false })
@IsOptional()
@ValidateNested()
@Type(() => NamaProviderApiErrorResponseDto)
tax_api_response?: NamaProviderApiErrorResponseDto
@ApiProperty({ required: false })
@IsOptional()
@IsString()
tsp_update_time: string
}
/////////////// Correction DTOs ///////////////
export class NamaProviderCorrectionBodyItemDto {
@ApiProperty({ required: true, description: 'شناسه کالا / خدمت' })
@IsString()
sstid: string
@ApiProperty({
required: true,
description: `نرخ مالیات بر ارزش افزوده`,
})
@IsString()
vra: string
// @ApiProperty()
// @IsString()
// sstt: string
@ApiProperty({
required: true,
description: 'مبلغ واحد',
})
@IsString()
fee: string
@ApiProperty({
required: true,
description: 'مبلغ تخفیف',
})
@IsString()
dis: string
@ApiProperty({
required: true,
description: 'واحد اندازه گیری',
})
@IsString()
mu: string
@ApiProperty({
required: true,
description: 'تعداد / مقدار',
})
@IsString()
am: string
@ApiProperty({
description: ' اجرت ساخت (طلا)',
})
@IsString()
consfee: string
@ApiProperty({
description: 'حق العمل',
})
@IsString()
bros: string
@ApiProperty({
description: 'سود فروشنده',
})
@IsString()
spro: string
}
export class NamaProviderCorrectionHeaderDto {
@ApiProperty({ required: true, description: 'موضوع صورتحساب' })
@IsString()
ins: string
@ApiProperty({ required: true, description: 'الگوی صورتحساب' })
@IsString()
inp: string
@ApiProperty({ required: true, description: 'نوع صورتحساب' })
@IsString()
inty: string
// @ApiProperty({required: true})
// @IsString()
// unique_tax_code: string
@ApiProperty({ required: true, description: 'سریال صورتحساب داخلی حافظه مالیاتی' })
@IsString()
inno: string
// @ApiProperty({ required: true })
// @IsString()
// tins: string
@ApiProperty({
required: true,
description: 'تاریخ و زمان صدور صورتحساب به صورت timestamp',
})
@IsString()
indatim: string
@ApiProperty({ required: true, description: 'نام مشتری' })
@IsString()
name: string
@ApiProperty({
required: false,
description:
'نوع شخصیت خریدار (در صورتی‌که خریدار نوع ۲ باشه باید ۱ یا ۲ گذاشته بشه)',
})
@IsString()
tob: string
@ApiProperty({ description: 'آدرس' })
@IsOptional()
@IsString()
address?: string
@ApiProperty({ description: 'شماره موبایل' })
@IsOptional()
@IsString()
mobile?: string
@ApiProperty({
description: `شماره ملی / شناسه ملی / شناسه مشارکت مدنی / کد فراگیر خریدار`,
})
@IsString()
bid: string
@ApiProperty({ required: true, description: 'روش تسویه (۱.نقدی، ۲.نسیه، ۳.نقدی-نسیه)' })
@IsString()
setm: '1' | '2' | '3'
@ApiProperty({ description: 'سهم پرداخت نقدی در صورتی که نقدی - نسیه باشد (۳)' })
@IsString()
cap: string
@ApiProperty({ description: 'سهم پرداخت نسیه در صورتی که نقدی - نسیه باشد (۳)' })
@IsString()
insp: string
}
export class NamaProviderCorrectionRequestDto {
@ApiProperty({ type: [NamaProviderCorrectionBodyItemDto] })
@IsArray()
@ValidateNested({ each: true })
@Type(() => NamaProviderCorrectionBodyItemDto)
body: NamaProviderCorrectionBodyItemDto[]
@ApiProperty({ type: [NamaProviderPaymentInfoDto] })
@IsArray()
@ValidateNested({ each: true })
@Type(() => NamaProviderPaymentInfoDto)
payment: NamaProviderPaymentInfoDto[]
@ApiProperty({ type: NamaProviderCorrectionHeaderDto })
@ValidateNested()
@Type(() => NamaProviderCorrectionHeaderDto)
header: NamaProviderCorrectionHeaderDto
@ApiProperty()
@IsString()
uuid: string
@ApiProperty()
@IsString()
economic_code: string
@ApiProperty()
@IsString()
fiscal_id: string
}