-
Notifications
You must be signed in to change notification settings - Fork 2
/
company.go
123 lines (94 loc) · 3.43 KB
/
company.go
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
package nfeio
import (
"encoding/json"
"time"
)
func (c *Client) GetCompany(idOrTaxNumber string) (response CompanyResponse, err error) {
err = c.Get("companies/"+idOrTaxNumber, nil, nil, &response)
return
}
func (c *Client) GetCompanies(pageCount, pageIndex int64) (response CompaniesResponse, err error) {
err = c.Get("companies", Params{"pageCount": pageCount, "pageIndex": pageIndex}, nil, &response)
return
}
func (c *Client) AddCompany(company *Company) (response CompanyResponse, err error) {
var params interface{}
if c.apiUrl == ServiceUrl {
params = company
} else {
params = map[string]interface{}{
"company": company,
}
}
err = c.Post("companies", params, nil, &response)
return
}
func (c *Client) SetCompany(company *Company) (response CompanyResponse, err error) {
var params interface{}
if c.apiUrl == ServiceUrl {
params = company
} else {
params = map[string]interface{}{
"company": company,
}
}
err = c.Put("companies/"+company.Id, params, nil, &response)
return
}
func (c *Client) DeleteCompany(id string) (err error) {
err = c.Delete("companies/"+id, nil, nil, nil)
return
}
type CompanyResponse struct {
Data Company
Company Company `json:"company"`
Companies Company `json:"companies"`
}
type CompaniesResponse struct {
Data []Company `json:"companies"`
pagination
}
type Company struct {
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
TradeName string `json:"tradeName,omitempty"`
Email string `json:"email,omitempty"`
FederalTaxNumber json.Number `json:"federalTaxNumber,omitempty"`
RegionalTaxNumber json.Number `json:"regionalTaxNumber,omitempty"`
MunicipalTaxNumber json.Number `json:"municipalTaxNumber,omitempty"`
CompanyRegistryNumber json.Number `json:"companyRegistryNumber,omitempty"`
TaxRegime interface{} `json:"taxRegime,omitempty"`
SpecialTaxRegime interface{} `json:"specialTaxRegime,omitempty"`
LegalNature interface{} `json:"legalNature,omitempty"`
RpsSerialNumber interface{} `json:"rpsSerialNumber,omitempty"`
RpsNumber interface{} `json:"rpsNumber,omitempty"`
IssRate float64 `json:"issRate,omitempty"`
Environment string `json:"environment,omitempty"`
FiscalStatus string `json:"fiscalStatus,omitempty"`
Address *Address `json:"address,omitempty"`
Certificate *Certificate `json:"certificate,omitempty"`
EconomicActivities []EconomicActivity `json:"economicActivities,omitempty"`
OpenningDate *time.Time `json:"openningDate,omitempty"`
CreatedOn *time.Time `json:"createdOn,omitempty"`
ModifiedOn *time.Time `json:"modifiedOn,omitempty"`
}
type EconomicActivity struct {
Type string `json:"type,omitempty"`
Code json.Number `json:"code,omitempty"`
}
// only to avoid recursion in UnmarshalJSON below
type cr CompanyResponse
// override default json.Unmarshal
func (c *CompanyResponse) UnmarshalJSON(b []byte) (err error) {
aux := cr{}
if err = json.Unmarshal(b, &aux); err == nil {
*c = CompanyResponse(aux)
if c.Company.Id != "" {
c.Data = c.Company
}
if c.Companies.Id != "" {
c.Data = c.Companies
}
}
return nil
}