-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinvoice.ts
178 lines (153 loc) · 4.17 KB
/
invoice.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/**
* SudoSOS back-end API service.
* Copyright (C) 2024 Study association GEWIS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* @license
*/
/**
* This is the module page of invoicing.
*
* ```ts
* const invoice = await this.manager.findOne(Invoice, {
* where: { id: invoiceId }, relations: ['transfer', 'transfer.from',
* 'invoiceStatus', 'invoiceStatus.changedBy']
* });
* ```
*
* @module invoicing
* @mergeTarget
*/
import {
Column,
Entity, JoinColumn, ManyToOne, OneToMany, OneToOne, ManyToMany, JoinTable,
} from 'typeorm';
import BaseEntity from '../base-entity';
import User from '../user/user';
import Transfer from '../transactions/transfer';
// eslint-disable-next-line import/no-cycle
import InvoiceStatus from './invoice-status';
import InvoicePdf from '../file/invoice-pdf';
import SubTransactionRow from '../transactions/sub-transaction-row';
import { INVOICE_PDF_LOCATION } from '../../files/storage';
import { PdfAble } from '../file/pdf-able';
import InvoicePdfService from '../../service/pdf/invoice-pdf-service';
@Entity()
export default class Invoice extends PdfAble(BaseEntity) {
/**
* The ID of the account for whom the invoice is
*/
@Column({ nullable: false })
public toId: number;
/**
* The account for whom the invoice is
*/
@ManyToOne(() => User, { nullable: false })
public to: User;
/**
* The transfer entity representing the invoice.
*/
@OneToOne(() => Transfer, {
nullable: false,
})
@JoinColumn()
public transfer: Transfer;
/**
* The status history of the invoice
*/
@OneToMany(() => InvoiceStatus,
(invoiceStatus) => invoiceStatus.invoice,
{ cascade: true })
public invoiceStatus: InvoiceStatus[];
/**
* Name of the addressed
*/
@Column()
public addressee: string;
/**
* Special attention to the addressee
*/
@Column({ nullable: true, default: '' })
public attention: string;
/**
* The description of the invoice
*/
@Column({ nullable: true, default: '' })
public description: string;
/**
* The ID of the PDF file
*/
@Column({ nullable: true })
public pdfId?: number;
/**
* The PDF file
*
* onDelete: 'CASCADE' is not possible here, because removing the
* pdf from the database will not remove it from storage
*/
@OneToOne(() => InvoicePdf, { nullable: true, onDelete: 'RESTRICT' })
@JoinColumn()
public pdf?: InvoicePdf;
/**
* The reference of the invoice
*/
@Column()
public reference: string;
/**
* Street to use on the invoice
*/
@Column()
public street: string;
/**
* Postal code to use on the invoice
*/
@Column()
public postalCode:string;
/**
* City to use on the invoice
*/
@Column()
public city: string;
/**
* Country to use on the invoice
*/
@Column()
public country: string;
@Column({ nullable: true })
public creditTransferId?: number;
/**
* If this invoice is deleted, this will be credit transfer.
*/
@OneToOne(() => Transfer, { nullable: true })
@JoinColumn()
public creditTransfer?: Transfer;
/**
* Date of the invoice
*/
@Column({
type: 'datetime',
default: () => 'CURRENT_TIMESTAMP',
})
public date: Date;
@OneToMany(() => SubTransactionRow, (row) => row.invoice, { cascade: false })
public subTransactionRows: SubTransactionRow[];
@ManyToMany(() => SubTransactionRow, { cascade: false })
@JoinTable()
public subTransactionRowsDeletedInvoice: SubTransactionRow[];
pdfService = new InvoicePdfService(INVOICE_PDF_LOCATION);
async getOwner(): Promise<User> {
return this.to;
}
}