|
1
|
|
|
import { |
|
2
|
|
|
Entity, |
|
3
|
|
|
Column, |
|
4
|
|
|
PrimaryGeneratedColumn, |
|
5
|
|
|
ManyToOne, |
|
6
|
|
|
OneToMany |
|
7
|
|
|
} from 'typeorm'; |
|
8
|
|
|
import { Project } from '../Project/Project.entity'; |
|
9
|
|
|
import { User } from '../HumanResource/User/User.entity'; |
|
10
|
|
|
import { InvoiceItem } from './InvoiceItem.entity'; |
|
11
|
|
|
import { Quote } from './Quote.entity'; |
|
12
|
|
|
|
|
13
|
|
|
export enum InvoiceStatus { |
|
14
|
|
|
DRAFT = 'draft', |
|
15
|
|
|
SENT = 'sent', |
|
16
|
|
|
PAYED = 'payed', |
|
17
|
|
|
CANCELED = 'canceled' |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
@Entity() |
|
21
|
|
|
export class Invoice { |
|
22
|
|
|
@PrimaryGeneratedColumn('uuid') |
|
23
|
|
|
private id: string; |
|
24
|
|
|
|
|
25
|
|
|
@Column('enum', {enum: InvoiceStatus, nullable: false}) |
|
26
|
|
|
private status: InvoiceStatus; |
|
27
|
|
|
|
|
28
|
|
|
@Column({type: 'varchar', nullable: false, unique: true}) |
|
29
|
|
|
private invoiceId: string; |
|
30
|
|
|
|
|
31
|
|
|
@Column({type: 'timestamp', default: () => 'CURRENT_TIMESTAMP'}) |
|
32
|
|
|
private createdAt: Date; |
|
33
|
|
|
|
|
34
|
|
|
@Column({type: 'timestamp'}) |
|
35
|
|
|
private expiryDate: string; |
|
36
|
|
|
|
|
37
|
|
|
@ManyToOne(type => User, {nullable: true, onDelete: 'SET NULL'}) |
|
38
|
|
|
private owner: User; |
|
39
|
|
|
|
|
40
|
|
|
@ManyToOne(type => Quote, {nullable: true, onDelete: 'SET NULL'}) |
|
41
|
|
|
private quote: Quote; |
|
42
|
|
|
|
|
43
|
|
|
@ManyToOne(type => Project, {nullable: true, onDelete: 'SET NULL'}) |
|
44
|
|
|
private project: Project; |
|
45
|
|
|
|
|
46
|
|
|
@OneToMany( |
|
47
|
|
|
type => InvoiceItem, |
|
48
|
|
|
invoiceItem => invoiceItem.invoice, |
|
49
|
|
|
) |
|
50
|
|
|
items: InvoiceItem[]; |
|
51
|
|
|
|
|
52
|
|
|
constructor( |
|
53
|
|
|
invoiceId: string, |
|
54
|
|
|
status: InvoiceStatus, |
|
55
|
|
|
expiryDate: string, |
|
56
|
|
|
owner: User, |
|
57
|
|
|
project: Project |
|
58
|
|
|
) { |
|
59
|
|
|
this.invoiceId = invoiceId; |
|
60
|
|
|
this.status = status; |
|
61
|
|
|
this.expiryDate = expiryDate; |
|
62
|
|
|
this.owner = owner; |
|
63
|
|
|
this.project = project; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public getId(): string { |
|
67
|
|
|
return this.id; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public getInvoiceId(): string { |
|
71
|
|
|
return this.invoiceId; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public getExpiryDate(): string { |
|
75
|
|
|
return this.expiryDate; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public getStatus(): InvoiceStatus { |
|
79
|
|
|
return this.status; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public getCreatedAt(): Date { |
|
83
|
|
|
return this.createdAt; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public getProject(): Project { |
|
87
|
|
|
return this.project; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public getOwner(): User { |
|
91
|
|
|
return this.owner; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public getQuote(): Quote | undefined { |
|
95
|
|
|
return this.quote; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|