Files
psp_api/src/modules/consumer/saleInvoices/fiscal/dto/tax-switch.dto.ts
T

239 lines
5.1 KiB
TypeScript
Raw Normal View History

import {
CustomerType,
FiscalInvoiceCustomerType,
FiscalRequestType,
PartnerFiscalSwitchType,
} from '@/generated/prisma/enums'
import { ApiProperty } from '@nestjs/swagger'
import { Type } from 'class-transformer'
import {
IsArray,
IsDateString,
IsEnum,
IsNumber,
IsObject,
IsOptional,
IsString,
ValidateNested,
} from 'class-validator'
export enum TaxSendStatus {
SENT = 'SENT',
FAILED = 'FAILED',
PENDING = 'PENDING',
}
export class CustomerLegalInfoDto {
@ApiProperty({ required: true })
@IsString()
name: string
@ApiProperty({ required: true })
@IsString()
economic_code: string
}
export class CustomerIndividualInfoDto {
@ApiProperty({ required: true })
@IsString()
first_name: string
@ApiProperty({ required: true })
@IsString()
last_name: string
@ApiProperty({ required: true })
@IsString()
national_id: string
@ApiProperty({ required: true })
@IsString()
mobile_number: string
}
export class CustomerInfoDto {
@ApiProperty({ required: true, enum: CustomerType })
@IsEnum(CustomerType)
type: CustomerType
@ApiProperty({})
@Type(() => CustomerLegalInfoDto)
@ValidateNested({ each: true })
legal_info?: CustomerLegalInfoDto
@ApiProperty({})
@Type(() => CustomerIndividualInfoDto)
@ValidateNested({ each: true })
individual_info?: CustomerIndividualInfoDto
}
export class TaxSwitchSendItemPayloadDto {
@ApiProperty({ required: true })
@IsString()
sku: string
@ApiProperty({ required: true })
@IsString()
sku_vat: string
@ApiProperty()
@IsOptional()
@IsString()
discount: string
@ApiProperty({ required: true })
@IsNumber()
unit_price: number
@ApiProperty()
@IsString()
invoice_item_id: string
@ApiProperty()
@IsNumber()
quantity: number
@ApiProperty()
@IsNumber()
total_amount: number
@ApiProperty({ required: true })
@IsString()
measure_unit: string
@ApiProperty({ required: false, nullable: true })
@IsOptional()
@IsString()
good_id?: string | null
@ApiProperty({ required: false, nullable: true })
@IsOptional()
@IsString()
service_id?: string | null
@ApiProperty({ required: false, nullable: true, type: Object })
@IsOptional()
@IsObject()
payload?: unknown
}
export class TaxSwitchSendPayloadDto {
@ApiProperty({ required: true, enum: FiscalRequestType })
@IsEnum(FiscalRequestType)
type: FiscalRequestType
@ApiProperty({ required: true, enum: FiscalInvoiceCustomerType })
@IsEnum(FiscalInvoiceCustomerType)
customer_type: FiscalInvoiceCustomerType
@ApiProperty({ type: [TaxSwitchSendItemPayloadDto] })
@IsArray()
@ValidateNested({ each: true })
@Type(() => TaxSwitchSendItemPayloadDto)
items: TaxSwitchSendItemPayloadDto[]
@ApiProperty({ required: false })
@Type(() => CustomerInfoDto)
@ValidateNested({ each: true })
customer?: CustomerInfoDto
@ApiProperty({ required: true, nullable: true })
@IsString()
invoice_code: string
@ApiProperty({ required: true, nullable: true })
@IsOptional()
@IsDateString()
invoice_date: Date
@ApiProperty({ required: true, nullable: true })
@IsString()
invoice_id: string
@ApiProperty()
@IsNumber()
total_amount: number
@ApiProperty({ required: true, enum: PartnerFiscalSwitchType })
@IsEnum(PartnerFiscalSwitchType)
provider_code: PartnerFiscalSwitchType
}
export class TaxSwitchSendItemResultDto {
@ApiProperty()
@IsString()
invoice_item_id: string
@ApiProperty({ enum: TaxSendStatus })
@IsEnum(TaxSendStatus)
status: TaxSendStatus
@ApiProperty({ required: false, nullable: true })
@IsOptional()
@IsString()
tax_id?: string | null
@ApiProperty({ required: false, nullable: true, type: Object })
@IsOptional()
@IsObject()
request_payload?: unknown
@ApiProperty({ required: false, nullable: true, type: Object })
@IsOptional()
@IsObject()
response_payload?: unknown
@ApiProperty({ required: false, nullable: true })
@IsOptional()
@IsString()
error_message?: string | null
@ApiProperty({ required: false, nullable: true })
@IsOptional()
@IsDateString()
sent_at?: string | null
@ApiProperty({ required: false, nullable: true })
@IsOptional()
@IsDateString()
received_at?: string | null
}
export class TaxSwitchBulkSendResultDto {
@ApiProperty()
@IsString()
invoice_id: string
@ApiProperty({ type: [TaxSwitchSendItemResultDto] })
@IsArray()
@ValidateNested({ each: true })
@Type(() => TaxSwitchSendItemResultDto)
items: TaxSwitchSendItemResultDto[]
}
export class TaxSwitchGetResultDto {
@ApiProperty()
@IsString()
tax_id: string
@ApiProperty({ enum: TaxSendStatus })
@IsEnum(TaxSendStatus)
status: TaxSendStatus
@ApiProperty({ required: false, nullable: true, type: Object })
@IsOptional()
@IsObject()
response_payload?: unknown
@ApiProperty({ required: false, nullable: true })
@IsOptional()
@IsDateString()
received_at?: string | null
}
export interface ITaxSwitchAdapter {
readonly code: string
send(payload: TaxSwitchSendPayloadDto): Promise<TaxSwitchSendItemResultDto[]>
sendBulk(payloads: TaxSwitchSendPayloadDto[]): Promise<TaxSwitchBulkSendResultDto[]>
get(taxId: string): Promise<TaxSwitchGetResultDto>
}