Skip to content

Commit

Permalink
Change structs and types
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Kwiedor committed Nov 23, 2020
1 parent e8294fc commit 272d9fd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ You can currently only create invoices and items in the invoices. For this purpo
Here you will find an example how to create a new invoice in sevDesk.

```go
invoice, err := sevdesk.NewInvoice(sevdesk.Invoice{"", "clientID", "21.11.2020", "100", "RE", "contactID", "token"})
invoice, err := sevdesk.NewInvoice(sevdesk.Invoice{, 323456, "21.11.2020", 100, "RE", 234353, "token"})
if err != nil {
fmt.Println("Error: ", err)
}
Expand All @@ -33,7 +33,7 @@ For this I have worked it all out as follows. The funny thing is that the ID doe
In sevDesk the price is transferred in gross, therefore we have added a calculation of the gross value to the function. So you set the net value + the VAT in the function.

```go
Position, err := NewPosition(Position{"45", "1", "16", "Backups", "Backups of all Websites", "9", "invoiceID", "token"})
Position, err := NewPosition(Position{45, 1, 16, "Backups", "Backups of all Websites", 9, invoiceID, "token"})
if err != nil {
fmt.Println("Error: ", err)
}
Expand Down
17 changes: 9 additions & 8 deletions invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import (
"encoding/json"
"net/http"
"net/url"
"strconv"
"strings"
)

// The data that the function uses
type Invoice struct {
InvoiceNumber string
ContactID string
InvoiceNumber int
ContactID int
InvoiceDate string
Status string
Status int
InvoiceType string
ContactPerson string
ContactPerson int
Token string
}

Expand Down Expand Up @@ -108,18 +109,18 @@ func NewInvoice(config Invoice) (InvoiceReturn, error) {

// Define body data
body := url.Values{}
body.Set("invoiceNumber", config.InvoiceNumber)
body.Set("contact[id]", config.ContactID)
body.Set("invoiceNumber", strconv.Itoa(config.InvoiceNumber))
body.Set("contact[id]", strconv.Itoa(config.ContactID))
body.Set("contact[objectName]", "Contact")
body.Set("invoiceDate", config.InvoiceDate)
body.Set("header", "")
body.Set("status", config.Status)
body.Set("status", strconv.Itoa(config.Status))
body.Set("invoiceType", config.InvoiceType)
body.Set("currency", "EUR")
body.Set("mapAll", "true")
body.Set("objectName", "Invoice")
body.Set("discount", "false")
body.Set("contactPerson[id]", config.ContactPerson)
body.Set("contactPerson[id]", strconv.Itoa(config.ContactPerson))
body.Set("contactPerson[objectName]", "SevUser")
body.Set("taxType", "default")
body.Set("taxRate", "")
Expand Down
12 changes: 6 additions & 6 deletions position.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (

type Position struct {
PriceNet float64
Quantity string
Quantity float64
TaxRate int
Name string
Description string
UnityID string
InvoiceID string
UnityID int
InvoiceID int
Token string
}

Expand Down Expand Up @@ -143,15 +143,15 @@ func NewPosition(config Position) (PositionReturn, error) {
// Define body data
body := url.Values{}
body.Set("price", fmt.Sprintf("%.2f", gross))
body.Set("quantity", config.Quantity)
body.Set("quantity", fmt.Sprintf("%.2f", config.Quantity))
body.Set("taxRate", strconv.Itoa(config.TaxRate))
body.Set("name", config.Name)
body.Set("text", config.Description)
body.Set("unity[id]", config.UnityID)
body.Set("unity[id]", strconv.Itoa(config.UnityID))
body.Set("unity[objectName]", "Unity")
body.Set("objectName", "InvoicePos")
body.Set("mapAll", "true")
body.Set("invoice[id]", config.InvoiceID)
body.Set("invoice[id]", strconv.Itoa(config.InvoiceID))
body.Set("invoice[objectName]", "Invoice")

// Define request
Expand Down

0 comments on commit 272d9fd

Please sign in to comment.