@@ -13,12 +13,13 @@ package sevdesk
13
13
14
14
import (
15
15
"encoding/json"
16
+ "fmt"
16
17
"net/http"
17
18
"net/url"
18
19
"strings"
19
20
)
20
21
21
- // The data that the function uses
22
+ // Invoice for the data that the function uses
22
23
type Invoice struct {
23
24
ContactID string
24
25
InvoiceDate string
@@ -28,12 +29,12 @@ type Invoice struct {
28
29
Token string
29
30
}
30
31
31
- // To return the data from invoices
32
+ // InvoicesReturn to return the data from invoices
32
33
type InvoicesReturn struct {
33
34
Objects []InvoiceObjects `json:"objects"`
34
35
}
35
36
36
- // For returning the data
37
+ // NewInvoiceReturn is for returning the data
37
38
type NewInvoiceReturn struct {
38
39
Objects InvoiceObjects `json:"objects"`
39
40
}
@@ -109,13 +110,114 @@ type InvoiceObjects struct {
109
110
SumDiscountGrossForeignCurrency string `json:"sumDiscountGrossForeignCurrency"`
110
111
}
111
112
112
- // Uses for invoices and positions
113
113
type ObjectName struct {
114
114
Id string `json:"id"`
115
115
ObjectName string `json:"objectName"`
116
116
}
117
117
118
- // Check invoices
118
+ // InvoiceEmail is to send invoice by email
119
+ type InvoiceEmail struct {
120
+ ID string
121
+ Email string
122
+ Subject string
123
+ Text string
124
+ CC string
125
+ BCC string
126
+ Token string
127
+ }
128
+
129
+ // SendInvoiceEmailReturn is to decode json data
130
+ type SendInvoiceEmailReturn struct {
131
+ Objects SendInvoiceEmailObjects `json:"objects"`
132
+ }
133
+
134
+ type SendInvoiceEmailObjects struct {
135
+ ID string `json:"id"`
136
+ ObjectName string `json:"objectName"`
137
+ AdditionalInformation interface {} `json:"additionalInformation"`
138
+ Create string `json:"create"`
139
+ Update string `json:"update"`
140
+ Object SendInvoiceEmailObject `json:"object"`
141
+ From string `json:"from"`
142
+ To string `json:"to"`
143
+ Subject string `json:"subject"`
144
+ Text string `json:"text"`
145
+ sevClient ObjectName `json:"sevClient"`
146
+ }
147
+
148
+ type SendInvoiceEmailObject struct {
149
+ ID string `json:"id"`
150
+ ObjectName string `json:"objectName"`
151
+ AdditionalInformation interface {} `json:"additionalInformation"`
152
+ InvoiceNumber string `json:"invoiceNumber"`
153
+ Contact ObjectName `json:"contact"`
154
+ Create string `json:"create"`
155
+ Update string `json:"update"`
156
+ SevClient ObjectName `json:"sevClient"`
157
+ InvoiceDate string `json:"invoice_date"`
158
+ Header string `json:"header"`
159
+ HeadText interface {} `json:"headText"`
160
+ FootText interface {} `json:"footText"`
161
+ TimeToPay interface {} `json:"timeToPay"`
162
+ DiscountTime interface {} `json:"discountTime"`
163
+ Discount string `json:"discount"`
164
+ AddressName interface {} `json:"addressName"`
165
+ AddressStreet interface {} `json:"addressStreet"`
166
+ AddressZip interface {} `json:"addressZip"`
167
+ AddressCity interface {} `json:"addressCity"`
168
+ PayDate interface {} `json:"payDate"`
169
+ CreateUser ObjectName `json:"createUser"`
170
+ DeliveryDate string `json:"deliveryDate"`
171
+ Status string `json:"status"`
172
+ SmallSettlement string `json:"smallSettlement"`
173
+ ContactPerson ObjectName `json:"contactPerson"`
174
+ TaxRate string `json:"taxRate"`
175
+ TaxText string `json:"taxText"`
176
+ DunningLevel interface {} `json:"dunningLevel"`
177
+ AddressParentName interface {} `json:"addressParentName"`
178
+ TaxType string `json:"taxType"`
179
+ SendDate interface {} `json:"sendDate"`
180
+ OriginLastInvoice interface {} `json:"originLastInvoice"`
181
+ InvoiceType string `json:"invoiceType"`
182
+ AccountIntervall interface {} `json:"accountIntervall"`
183
+ AccountLastInvoice interface {} `json:"accountLastInvoice"`
184
+ AccountNextInvoice interface {} `json:"accountNextInvoice"`
185
+ ReminderTotal interface {} `json:"reminderTotal"`
186
+ ReminderDebit interface {} `json:"reminderDebit"`
187
+ ReminderDeadline interface {} `json:"reminderDeadline"`
188
+ ReminderCharge interface {} `json:"reminderCharge"`
189
+ AddressParentName2 interface {} `json:"addressParentName2"`
190
+ AddressName2 interface {} `json:"addressName2"`
191
+ AddressGender interface {} `json:"addressGender"`
192
+ AccountStartDate interface {} `json:"accountStartDate"`
193
+ AccountEndDate interface {} `json:"accountEndDate"`
194
+ Address interface {} `json:"address"`
195
+ Currency string `json:"currency"`
196
+ SumNet string `json:"sumNet"`
197
+ SumTax string `json:"sumTax"`
198
+ SumGross string `json:"sumGross"`
199
+ SumDiscounts string `json:"sumDiscounts"`
200
+ SumNetForeignCurrency string `json:"sumNetForeignCurrency"`
201
+ SumTaxForeignCurrency string `json:"sumTaxForeignCurrency"`
202
+ SumGrossForeignCurrency string `json:"sumGrossForeignCurrency"`
203
+ SumDiscountsForeignCurrency string `json:"sumDiscountsForeignCurrency"`
204
+ SumNetAccounting string `json:"sumNetAccounting"`
205
+ SumTaxAccounting string `json:"sumTaxAccounting"`
206
+ SumGrossAccounting string `json:"sumGrossAccounting"`
207
+ PaidAmount string `json:"paidAmount"`
208
+ CustomerInternalNote interface {} `json:"customerInternalNote"`
209
+ ShowNet string `json:"showNet"`
210
+ Enshrined interface {} `json:"enshrined"`
211
+ SendType string `json:"sendType"`
212
+ DeliveryDateUntil interface {} `json:"deliveryDateUntil"`
213
+ SendPaymentReceivedNotificationDate interface {} `json:"sendPaymentReceivedNotificationDate"`
214
+ SumDiscountNet string `json:"sumDiscountNet"`
215
+ SumDiscountGross string `json:"sumDiscountGross"`
216
+ SumDiscountNetForeignCurrency string `json:"sumDiscountNetForeignCurrency"`
217
+ SumDiscountGrossForeignCurrency string `json:"sumDiscountGrossForeignCurrency"`
218
+ }
219
+
220
+ // Invoices to check invoices
119
221
func Invoices (token string ) (InvoicesReturn , error ) {
120
222
121
223
// Define client
@@ -152,7 +254,7 @@ func Invoices(token string) (InvoicesReturn, error) {
152
254
153
255
}
154
256
155
- // Create a new invoice
257
+ // NewInvoice to create a new invoice
156
258
func NewInvoice (config Invoice ) (NewInvoiceReturn , error ) {
157
259
158
260
// Define client
@@ -209,3 +311,51 @@ func NewInvoice(config Invoice) (NewInvoiceReturn, error) {
209
311
return decode , nil
210
312
211
313
}
314
+
315
+ // SendInvoiceEmail to send an invoice by mail
316
+ func SendInvoiceEmail (config InvoiceEmail ) (SendInvoiceEmailReturn , error ) {
317
+
318
+ // Define client
319
+ client := & http.Client {}
320
+
321
+ // Define body data
322
+ body := url.Values {}
323
+ body .Set ("toEmail" , config .Email )
324
+ body .Set ("subject" , config .Subject )
325
+ body .Set ("text" , config .Text )
326
+ body .Set ("copy" , "false" )
327
+ body .Set ("additionalAttachments" , "null" )
328
+ body .Set ("ccEmail" , config .CC )
329
+ body .Set ("bccEmail" , config .BCC )
330
+
331
+ // New http request
332
+ request , err := http .NewRequest ("POST" , fmt .Sprintf ("https://my.sevdesk.de/api/v1/Invoice/%s/sendViaEmail" , config .ID ), strings .NewReader (body .Encode ()))
333
+ if err != nil {
334
+ return SendInvoiceEmailReturn {}, err
335
+ }
336
+
337
+ // Set header
338
+ request .Header .Set ("Content-Type" , "application/x-www-form-urlencoded" )
339
+ request .Header .Set ("Authorization" , config .Token )
340
+
341
+ // Response to sevDesk
342
+ response , err := client .Do (request )
343
+ if err != nil {
344
+ return SendInvoiceEmailReturn {}, err
345
+ }
346
+
347
+ // Close response
348
+ defer response .Body .Close ()
349
+
350
+ // Decode data
351
+ var decode SendInvoiceEmailReturn
352
+
353
+ err = json .NewDecoder (response .Body ).Decode (& decode )
354
+ if err != nil {
355
+ return SendInvoiceEmailReturn {}, err
356
+ }
357
+
358
+ // Return data
359
+ return decode , nil
360
+
361
+ }
0 commit comments