import { DataTypes, Model, Optional } from 'sequelize'; import { sequelize } from '@config/database'; import { Form16CreditNote } from './Form16CreditNote'; export interface Form16SapResponseAttributes { id: number; type: 'credit'; fileName: string; creditNoteId?: number | null; // Well-known SAP CSV columns stored as individual fields trnsUniqNo?: string | null; // TRNS_UNIQ_NO – our unique ID echoed back by SAP tdsTransId?: string | null; // TDS_TRNS_ID – credit note number echoed back (primary match key) claimNumber?: string | null; // CLAIM_NUMBER (alias / fallback) sapDocumentNumber?: string | null;// DOC_NO – SAP-generated document number msgTyp?: string | null; // MSG_TYP message?: string | null; // MESSAGE docDate?: string | null; // DOC_DATE tdsAmt?: string | null; // TDS_AMT rawRow?: Record | null; // any extra / unknown columns from the CSV storageUrl?: string | null; createdAt: Date; updatedAt: Date; } interface Form16SapResponseCreationAttributes extends Optional< Form16SapResponseAttributes, | 'id' | 'creditNoteId' | 'trnsUniqNo' | 'tdsTransId' | 'claimNumber' | 'sapDocumentNumber' | 'msgTyp' | 'message' | 'docDate' | 'tdsAmt' | 'rawRow' | 'storageUrl' | 'createdAt' | 'updatedAt' > {} class Form16SapResponse extends Model implements Form16SapResponseAttributes { public id!: number; public type!: 'credit'; public fileName!: string; public creditNoteId?: number | null; public trnsUniqNo?: string | null; public tdsTransId?: string | null; public claimNumber?: string | null; public sapDocumentNumber?: string | null; public msgTyp?: string | null; public message?: string | null; public docDate?: string | null; public tdsAmt?: string | null; public rawRow?: Record | null; public storageUrl?: string | null; public createdAt!: Date; public updatedAt!: Date; public creditNote?: Form16CreditNote; } Form16SapResponse.init( { id: { type: DataTypes.INTEGER, autoIncrement: true, primaryKey: true }, type: { type: DataTypes.STRING(10), allowNull: false }, fileName: { type: DataTypes.STRING(255), allowNull: false, unique: true, field: 'file_name' }, creditNoteId: { type: DataTypes.INTEGER, allowNull: true, field: 'credit_note_id' }, trnsUniqNo: { type: DataTypes.STRING(200), allowNull: true, field: 'trns_uniq_no' }, tdsTransId: { type: DataTypes.STRING(200), allowNull: true, field: 'tds_trns_id' }, claimNumber: { type: DataTypes.STRING(200), allowNull: true, field: 'claim_number' }, sapDocumentNumber:{ type: DataTypes.STRING(100), allowNull: true, field: 'sap_document_number' }, msgTyp: { type: DataTypes.STRING(20), allowNull: true, field: 'msg_typ' }, message: { type: DataTypes.TEXT, allowNull: true }, docDate: { type: DataTypes.STRING(20), allowNull: true, field: 'doc_date' }, tdsAmt: { type: DataTypes.STRING(50), allowNull: true, field: 'tds_amt' }, rawRow: { type: DataTypes.JSONB, allowNull: true, field: 'raw_row' }, storageUrl: { type: DataTypes.STRING(500), allowNull: true, field: 'storage_url' }, createdAt: { type: DataTypes.DATE, allowNull: false, field: 'created_at' }, updatedAt: { type: DataTypes.DATE, allowNull: false, field: 'updated_at' }, }, { sequelize, tableName: 'form16_sap_responses', timestamps: true, underscored: true, createdAt: 'created_at', updatedAt: 'updated_at', } ); Form16SapResponse.belongsTo(Form16CreditNote, { as: 'creditNote', foreignKey: 'creditNoteId', targetKey: 'id', }); export { Form16SapResponse };