-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpense_create.go
90 lines (70 loc) · 2.83 KB
/
expense_create.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
package gofastbill
import (
"errors"
)
type ExpenseCreate_Request struct {
INVOICE_DATE string `xml:"INVOICE_DATE,omitempty" json:"INVOICE_DATE,omitempty"` // Required Rechnungsdatum
DUE_DATE string `xml:"DUE_DATE,omitempty" json:"DUE_DATE,omitempty"` // Fälligkeitsdatum
PROJECT_ID string `xml:"PROJECT_ID,omitempty" json:"PROJECT_ID,omitempty"` // Eine bestimmte Projekt ID
CUSTOMER_ID string `xml:"CUSTOMER_ID,omitempty" json:"CUSTOMER_ID,omitempty"` // Eine bestimmte Kundennummer
ORGANIZATION string `xml:"ORGANIZATION,omitempty" json:"ORGANIZATION,omitempty"` // Required Firmenname
INVOICE_NUMBER string `xml:"INVOICE_NUMBER,omitempty" json:"INVOICE_NUMBER,omitempty"` // Rechnungsnummer
COMMENT string `xml:"COMMENT,omitempty" json:"COMMENT,omitempty"` // Bemerkung
SUB_TOTAL float64 `xml:"SUB_TOTAL,omitempty" json:"SUB_TOTAL,omitempty"` // Required Nettobetrag
VAT_TOTAL float64 `xml:"VAT_TOTAL,omitempty" json:"VAT_TOTAL,omitempty"` // Vorsteuerbetrag
}
//CREATE Estimate
//FILTER => All fields from Struct: gofastbill.ExpenseCreate_Request
//Required:
//CUSTOMER_ID, ITEMS[]
//RESPONSE: STATUS, ESTIMATE_ID
func (s *Initialization) Expense_create(req ExpenseCreate_Request) (*FBAPI, error) {
var fastbillbody string
var r FBAPI
r.SERVICE = "expense.create"
if req.INVOICE_DATE == "" {
return nil, errors.New(s.Typ + ": INVOICE_DATE must not be empty")
}
if req.ORGANIZATION == "" {
return nil, errors.New(s.Typ + ": ORGANIZATION must not be empty")
}
if req.SUB_TOTAL == 0 {
return nil, errors.New(s.Typ + ": SUB_TOTAL must not be empty")
}
r.DATA.INVOICE_DATE = req.INVOICE_DATE
r.DATA.DUE_DATE = req.DUE_DATE
r.DATA.PROJECT_ID = req.PROJECT_ID
r.DATA.CUSTOMER_ID = req.CUSTOMER_ID
r.DATA.ORGANIZATION = req.ORGANIZATION
r.DATA.INVOICE_NUMBER = req.INVOICE_NUMBER
r.DATA.COMMENT = req.COMMENT
r.DATA.SUB_TOTAL = req.SUB_TOTAL
r.DATA.VAT_TOTAL = req.VAT_TOTAL
//TODO: Beleg als Datei Multipartform
fastbillbody, err := s.GenerateRequest(r)
if err != nil {
return nil, err
}
resp, err := s.FastbillRequest(fastbillbody)
if err != nil {
return nil, err
}
return resp, nil
}
//Aufbau des POST-Requests im Multipart-Format:
//curl -v -X POST \
//–u {E-Mail-Adresse}:{API-Key} \
//-H 'Content-Type: multipart/form-data, boundary=AaB03x' \
//-d '{xml body}' \ https://my.fastbill.com/api/1.0/api.php
//POST /api/1.0/api.php HTTP/1.0
//Host: my.fastbill.com
//Content-type: multipart/form-data, boundary=AaB03x
//Content-Length: {Größe des Inhalts}
//--AaB03x content-disposition: form-data; name="httpbody"
//{XML- oder JSON-Daten}
//--AaB03x
//content-disposition: form-data; name="document"; filename{Dateiname}"
//Content-Type: {MIME Typ}
//Content-Transfer-Encoding: binary
//{Datei-Inhalt}
//--AaB03x--