Passed
Push — master ( 2a103b...f47022 )
by Mathieu
02:07
created

server/src/Domain/Accounting/Invoice.entity.ts   A

Complexity

Total Complexity 8
Complexity/F 1

Size

Lines of Code 100
Function Count 8

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 85
dl 0
loc 100
rs 10
c 0
b 0
f 0
wmc 8
mnd 0
bc 0
fnc 8
bpm 0
cpm 1
noi 0

8 Functions

Rating   Name   Duplication   Size   Complexity  
A Invoice.getStatus 0 3 1
A Invoice.getOwner 0 3 1
A Invoice.getQuote 0 3 1
A Invoice.getCustomer 0 3 1
A Invoice.getInvoiceId 0 3 1
A Invoice.getExpiryDate 0 3 1
A Invoice.getId 0 3 1
A Invoice.getCreatedAt 0 3 1
1
import {
2
  Entity,
3
  Column,
4
  PrimaryGeneratedColumn,
5
  ManyToOne,
6
  OneToMany
7
} from 'typeorm';
8
import { Customer } from '../Customer/Customer.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 billingId: 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: false})
38
  private owner: User;
39
40
  @ManyToOne(type => Quote, {nullable: true})
41
  private quote: Quote;
42
43
  @ManyToOne(type => Customer, {nullable: false})
44
  private customer: Customer;
45
46
  @OneToMany(
47
    type => InvoiceItem,
48
    billingItem => billingItem.billing
49
  )
50
  items: InvoiceItem[];
51
52
  constructor(
53
    billingId: string,
54
    status: InvoiceStatus,
55
    expiryDate: string,
56
    owner: User,
57
    customer: Customer,
58
    quote?: Quote
59
  ) {
60
    this.billingId = billingId;
61
    this.status = status;
62
    this.expiryDate = expiryDate;
63
    this.owner = owner;
64
    this.customer = customer;
65
    this.quote = quote;
66
  }
67
68
  public getId(): string {
69
    return this.id;
70
  }
71
72
  public getInvoiceId(): string {
73
    return this.billingId;
74
  }
75
76
  public getExpiryDate(): string {
77
    return this.expiryDate;
78
  }
79
80
  public getStatus(): InvoiceStatus {
81
    return this.status;
82
  }
83
84
  public getCreatedAt(): Date {
85
    return this.createdAt;
86
  }
87
88
  public getCustomer(): Customer {
89
    return this.customer;
90
  }
91
92
  public getOwner(): User {
93
    return this.owner;
94
  }
95
96
  public getQuote(): Quote | undefined {
97
    return this.quote;
98
  }
99
}
100