golexoffice

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2022 License: MIT Imports: 7 Imported by: 0

README

Lexoffice for GO

Install

go get github.com/jjideenschmiede/golexoffice

How to use?

Get all contacts

To get all contacts you can perform the following function.

// Get all contacts
contacts, err := golexoffice.Contacts("token")
if err != nil {
    fmt.Println(err)
} else {
    fmt.Println(contacts)
}
Get a contact by id

If you want to read out a specific contact, you can do this via the id (UUID).

// Get a contact by id
contact, err := golexoffice.Contact("b324c2be-b745-4128-9ecd-e262a0a761cd", "token")
if err != nil {
    fmt.Println(err)
} else {
    fmt.Println(contact)
}
Create a new contact

To create a new contact, lexoffice needs some data. These must be entered in a structure.

// Define body
body := golexoffice.ContactBody{
    "",
    0,
	golexoffice.ContactBodyRoles{
    golexoffice.ContactBodyCustomer{},
    golexoffice.ContactBodyVendor{},
	},
    golexoffice.ContactBodyCompany{
        "J&J Ideenschmiede GmbH",
        "12345/12345",
        "DE123456789",
        true,
        []golexoffice.ContactBodyContactPersons{{
            "Herr",
            "Jonas",
            "Kwiedor",
            "jonas.kwiedor@jj-ideenschmiede.de",
            "04152 8903730",
        }},
    },
    golexoffice.ContactBodyAddresses{
        []golexoffice.ContactBodyBilling{{
            "Rechnungsadressenzusatz",
            "Fährstraße 31",
            "21502",
            "Geesthacht",
            "DE",
        }},
        []golexoffice.ContactBodyShipping{{
            "Lieferadressenzusatz",
            "Fährstraße 31",
            "21502",
            "Geesthacht",
            "DE",
        }},
    },
    golexoffice.ContactBodyEmailAddresses{
        []string{"info@jj-ideenschmiede.de"},
        []string{"info@jj-ideenschmiede.de"},
        []string{"info@jj-ideenschmiede.de"},
        []string{"info@jj-ideenschmiede.de"},
    },
    golexoffice.ContactBodyPhoneNumbers{
        []string{"04152 8903730"},
        []string{"04152 8903730"},
        []string{"04152 8903730"},
        []string{"04152 8903730"},
        []string{"04152 8903730"},
        []string{"04152 8903730"},
    },
    "Testnotiz",
    false,
}

// Create new contact
contactReturn, err := golexoffice.AddContact(body, "token")
if err != nil {
    fmt.Println(err)
} else {
    fmt.Println(contactReturn)
}
Update a contact

If you want to update a contact, then some information is very important. You need the ID of the contact & the version.

// Define body
body := golexoffice.ContactBody{
    "ID",
    1,
	golexoffice.ContactBodyRoles{
        golexoffice.ContactBodyCustomer{},
        golexoffice.ContactBodyVendor{},
    },
    golexoffice.ContactBodyCompany{
        "J&J Ideenschmiede GmbH",
        "12345/12345",
        "DE123456789",
        true,
        []golexoffice.ContactBodyContactPersons{{
            "Herr",
            "Jonas",
            "Kwiedor",
            "jonas.kwiedor@jj-ideenschmiede.de",
            "017684714777",
        }},
    },
    golexoffice.ContactBodyAddresses{
        []golexoffice.ContactBodyBilling{{
            "Rechnungsadressenzusatz",
            "Fährstraße 31",
            "21502",
            "Geesthacht",
            "DE",
        }},
        []golexoffice.ContactBodyShipping{{
            "Lieferadressenzusatz",
            "Fährstraße 31",
            "21502",
            "Geesthacht",
            "DE",
        }},
    },
    golexoffice.ContactBodyEmailAddresses{
        []string{"info@jj-ideenschmiede.de"},
        []string{"info@jj-ideenschmiede.de"},
        []string{"info@jj-ideenschmiede.de"},
        []string{"info@jj-ideenschmiede.de"},
    },
    golexoffice.ContactBodyPhoneNumbers{
        []string{"04152 8903730"},
        []string{"04152 8903730"},
        []string{"04152 8903730"},
        []string{"04152 8903730"},
        []string{"04152 8903730"},
        []string{"04152 8903730"},
    },
    "Testnotiz",
    false,
}

// Create new contact
contactReturn, err := UpdateContact(body, "token")
if err != nil {
    fmt.Println(err)
} else {
    fmt.Println(contactReturn)
}
Get a invoice

If you want to read out a specific invoice, you can do this via the id (UUID).

// Invoice is to get a invoice by id
invoice, err := Invoice("0cf8142b-6f54-4c96-9766-6f44a9a4814b", "token")
if err != nil {
    fmt.Println(err)
} else {
    fmt.Println(invoice)
}
Create a invoice

In order to create a new invoice, the data must be sent in a certain format. This works as follows.

If you can assign an invoice to an existing customer, then in the struct InvoiceBodyAddress{} please specify only the Id and leave the rest empty.

For more information, please refer to the documentation.

// Define body
body := golexoffice.InvoiceBody{
    "",
    "",
    "",
    "",
    1,
    false,
    "",
    "",
    "2021-07-20T00:00:00.000+01:00",
    "",
    golexoffice.InvoiceBodyAddress{
        "",
        "Test Company",
        "",
        "Teststreet 12",
        "Geesthacht",
        "21502",
        "DE",
    },
    []golexoffice.InvoiceBodyLineItems{{
        "",
        "custom",
        "Testarticle",
        "Very nice article!",
        1,
        "Stück",
		golexoffice.InvoiceBodyUnitPrice{
            "EUR",
            13.4,
            15.59,
            19,
        },
        0,
        13.4,
    }},
    golexoffice.InvoiceBodyTotalPrice{
        "EUR",
        13.4,
        15.95,
        nil,
        2.55,
        nil,
        nil,
    },
    []golexoffice.InvoiceBodyTaxAmounts{{
        19,
        2.55,
        15.95,
    }},
    golexoffice.InvoiceBodyTaxConditions{
        "net",
        nil,
    },
    golexoffice.InvoiceBodyPaymentConditions{
        "Please pay within the next 30 days.",
        30,
		golexoffice.InvoiceBodyPaymentDiscountConditions{
            0,
            0,
        },
    },
    golexoffice.InvoiceBodyShippingConditions{
        "2021-07-20T00:00:00.000+01:00",
        nil,
        "none",
    },
    "Invoice",
    "We hereby invoice you for the items you have ordered",
    "Thank you for your purchase",
}

// Create new contact
invoice, err := golexoffice.AddInvoice(body, "token")
if err != nil {
    fmt.Println(err)
} else {
    fmt.Println(invoice)
}
Upload a file

Here you will find a function with which you can upload a file to lexoffice. You only need the path to the file and the lexoffice token.

For more information, please refer to the documentation.

// Open file
file, err := os.Open("/Users/jonaskwiedor/Downloads/Rechnung 201912101300005.pdf")
if err != nil {
    fmt.Println(err)
}

// Files is to create a new file
files, err := golexoffice.AddFile(file, "Rechnung 201912101300005.pdf", "token")
if err != nil {
    fmt.Println(err)
} else {
    fmt.Println(files)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Path, Method, Token string
	ContentType         string
	Body                io.Reader
}

Config is to define the request data

func (Config) Send

func (c Config) Send() (*http.Response, error)

Send is to send a new request

type ContactBody

type ContactBody struct {
	Id             string                    `json:"id,omitempty"`
	Version        int                       `json:"version,omitempty"`
	Roles          ContactBodyRoles          `json:"roles"`
	Company        ContactBodyCompany        `json:"company"`
	Addresses      ContactBodyAddresses      `json:"addresses"`
	EmailAddresses ContactBodyEmailAddresses `json:"emailAddresses"`
	PhoneNumbers   ContactBodyPhoneNumbers   `json:"phoneNumbers"`
	Note           string                    `json:"note"`
	Archived       bool                      `json:"archived,omitempty"`
}

ContactBody is to create a new contact

type ContactBodyAddresses

type ContactBodyAddresses struct {
	Billing  []ContactBodyBilling  `json:"billing"`
	Shipping []ContactBodyShipping `json:"shipping"`
}

type ContactBodyBilling

type ContactBodyBilling struct {
	Supplement  string `json:"supplement"`
	Street      string `json:"street"`
	Zip         string `json:"zip"`
	City        string `json:"city"`
	CountryCode string `json:"countryCode"`
}

type ContactBodyCompany

type ContactBodyCompany struct {
	Name                 string                      `json:"name"`
	TaxNumber            string                      `json:"taxNumber"`
	VatRegistrationId    string                      `json:"vatRegistrationId"`
	AllowTaxFreeInvoices bool                        `json:"allowTaxFreeInvoices"`
	ContactPersons       []ContactBodyContactPersons `json:"contactPersons"`
}

type ContactBodyContactPersons

type ContactBodyContactPersons struct {
	Salutation   string `json:"salutation"`
	FirstName    string `json:"firstName"`
	LastName     string `json:"lastName"`
	EmailAddress string `json:"emailAddress"`
	PhoneNumber  string `json:"phoneNumber"`
}

type ContactBodyCustomer

type ContactBodyCustomer struct {
	Number int `json:"number,omitempty"`
}

type ContactBodyEmailAddresses

type ContactBodyEmailAddresses struct {
	Business []string `json:"business"`
	Office   []string `json:"office"`
	Private  []string `json:"private"`
	Other    []string `json:"other"`
}

type ContactBodyPhoneNumbers

type ContactBodyPhoneNumbers struct {
	Business []string `json:"business"`
	Office   []string `json:"office"`
	Mobile   []string `json:"mobile"`
	Private  []string `json:"private"`
	Fax      []string `json:"fax"`
	Other    []string `json:"other"`
}

type ContactBodyRoles

type ContactBodyRoles struct {
	Customer ContactBodyCustomer `json:"customer"`
	Vendor   ContactBodyVendor   `json:"vendor"`
}

type ContactBodyShipping

type ContactBodyShipping struct {
	Supplement  string `json:"supplement"`
	Street      string `json:"street"`
	Zip         string `json:"zip"`
	City        string `json:"city"`
	CountryCode string `json:"countryCode"`
}

type ContactBodyVendor

type ContactBodyVendor struct {
	Number int `json:"number,omitempty"`
}

type ContactReturn

type ContactReturn struct {
	ID          string `json:"id"`
	ResourceUri string `json:"resourceUri"`
	CreatedDate string `json:"createdDate"`
	UpdatedDate string `json:"updatedDate"`
	Version     int    `json:"version"`
}

ContactReturn is to decode json return

func AddContact

func AddContact(body ContactBody, token string) (ContactReturn, error)

AddContact is to add a new contact

func UpdateContact

func UpdateContact(body ContactBody, token string) (ContactReturn, error)

UpdateContact is to add a new contact

type ContactsReturn

type ContactsReturn struct {
	Content          []ContactsReturnContent `json:"content"`
	First            bool                    `json:"first"`
	Last             bool                    `json:"last"`
	TotalPages       int                     `json:"totalPages"`
	TotalElements    int                     `json:"totalElements"`
	NumberOfElements int                     `json:"numberOfElements"`
	Size             int                     `json:"size"`
	Number           int                     `json:"number"`
	Sort             []ContactsReturnSort    `json:"sort"`
}

ContactsReturn is to decode json data

type ContactsReturnAddresses

type ContactsReturnAddresses struct {
	Billing  []ContactsReturnBilling  `json:"billing"`
	Shipping []ContactsReturnShipping `json:"shipping"`
}

type ContactsReturnBilling

type ContactsReturnBilling struct {
	Supplement  string `json:"supplement"`
	Street      string `json:"street"`
	Zip         string `json:"zip"`
	City        string `json:"city"`
	CountryCode string `json:"countryCode"`
}

type ContactsReturnCompany

type ContactsReturnCompany struct {
	Name                 string                         `json:"name"`
	TaxNumber            string                         `json:"taxNumber"`
	VatRegistrationId    string                         `json:"vatRegistrationId"`
	AllowTaxFreeInvoices bool                           `json:"allowTaxFreeInvoices"`
	ContactPersons       []ContactsReturnContactPersons `json:"contactPersons"`
}

type ContactsReturnContactPersons

type ContactsReturnContactPersons struct {
	Salutation   string `json:"salutation"`
	FirstName    string `json:"firstName"`
	LastName     string `json:"lastName"`
	EmailAddress string `json:"emailAddress"`
	PhoneNumber  string `json:"phoneNumber"`
}

type ContactsReturnContent

type ContactsReturnContent struct {
	Id             string                    `json:"id,omitempty"`
	Version        int                       `json:"version,omitempty"`
	Roles          ContactBodyRoles          `json:"roles"`
	Company        ContactBodyCompany        `json:"company"`
	Addresses      ContactBodyAddresses      `json:"addresses"`
	EmailAddresses ContactBodyEmailAddresses `json:"emailAddresses"`
	PhoneNumbers   ContactBodyPhoneNumbers   `json:"phoneNumbers"`
	Note           string                    `json:"note"`
	Archived       bool                      `json:"archived,omitempty"`
}

func Contact

func Contact(id, token string) (ContactsReturnContent, error)

Contact is to get a contact by id

func Contacts

func Contacts(token string) ([]ContactsReturnContent, error)

Contacts is to get a list of all contacts

type ContactsReturnCustomer

type ContactsReturnCustomer struct {
	Number int `json:"number,omitempty"`
}

type ContactsReturnEmailAddresses

type ContactsReturnEmailAddresses struct {
	Business []string `json:"business"`
	Office   []string `json:"office"`
	Private  []string `json:"private"`
	Other    []string `json:"other"`
}

type ContactsReturnPhoneNumbers

type ContactsReturnPhoneNumbers struct {
	Business []string `json:"business"`
	Office   []string `json:"office"`
	Mobile   []string `json:"mobile"`
	Private  []string `json:"private"`
	Fax      []string `json:"fax"`
	Other    []string `json:"other"`
}

type ContactsReturnRoles

type ContactsReturnRoles struct {
	Customer ContactsReturnCustomer `json:"customer"`
	Vendor   ContactsReturnVendor   `json:"vendor"`
}

type ContactsReturnShipping

type ContactsReturnShipping struct {
	Supplement  string `json:"supplement"`
	Street      string `json:"street"`
	Zip         string `json:"zip"`
	City        string `json:"city"`
	CountryCode string `json:"countryCode"`
}

type ContactsReturnSort

type ContactsReturnSort struct {
	Property     string `json:"property"`
	Direction    string `json:"direction"`
	IgnoreCase   bool   `json:"ignoreCase"`
	NullHandling string `json:"nullHandling"`
	Ascending    bool   `json:"ascending"`
}

type ContactsReturnVendor

type ContactsReturnVendor struct {
	Number int `json:"number,omitempty"`
}

type FileReturn

type FileReturn struct {
	Id string `json:"id"`
}

FileReturn is to decode json data

func AddFile

func AddFile(file *os.File, name string, token string) (FileReturn, error)

AddFile is to upload a file

type InvoiceBody

type InvoiceBody struct {
	Id                 string                        `json:"id"`
	OrganizationId     string                        `json:"organizationId"`
	CreateDate         string                        `json:"createDate"`
	UpdatedDate        string                        `json:"updatedDate"`
	Version            int                           `json:"version"`
	Archived           bool                          `json:"archived"`
	VoucherStatus      string                        `json:"voucherStatus"`
	VoucherNumber      string                        `json:"voucherNumber"`
	VoucherDate        string                        `json:"voucherDate"`
	DueDate            interface{}                   `json:"dueDate"`
	Address            InvoiceBodyAddress            `json:"address"`
	LineItems          []InvoiceBodyLineItems        `json:"lineItems"`
	TotalPrice         InvoiceBodyTotalPrice         `json:"totalPrice"`
	TaxAmounts         []InvoiceBodyTaxAmounts       `json:"taxAmounts"`
	TaxConditions      InvoiceBodyTaxConditions      `json:"taxConditions"`
	PaymentConditions  InvoiceBodyPaymentConditions  `json:"paymentConditions"`
	ShippingConditions InvoiceBodyShippingConditions `json:"shippingConditions"`
	Title              string                        `json:"title"`
	Introduction       string                        `json:"introduction"`
	Remark             string                        `json:"remark"`
}

InvoiceBody is to define body data

func Invoice

func Invoice(id, token string) (InvoiceBody, error)

Invoice is to get a invoice by id

type InvoiceBodyAddress

type InvoiceBodyAddress struct {
	ContactId   string `json:"contactId"`
	Name        string `json:"name"`
	Supplement  string `json:"supplement"`
	Street      string `json:"street"`
	City        string `json:"city"`
	Zip         string `json:"zip"`
	CountryCode string `json:"countryCode"`
}

type InvoiceBodyLineItems

type InvoiceBodyLineItems struct {
	Id                 string               `json:"id,omitempty"`
	Type               string               `json:"type"`
	Name               string               `json:"name"`
	Description        string               `json:"description"`
	Quantity           float64              `json:"quantity"`
	UnitName           string               `json:"unitName"`
	UnitPrice          InvoiceBodyUnitPrice `json:"unitPrice"`
	DiscountPercentage int                  `json:"discountPercentage"`
	LineItemAmount     float64              `json:"lineItemAmount"`
}

type InvoiceBodyPaymentConditions

type InvoiceBodyPaymentConditions struct {
	PaymentTermLabel          string                               `json:"paymentTermLabel"`
	PaymentTermDuration       int                                  `json:"paymentTermDuration"`
	PaymentDiscountConditions InvoiceBodyPaymentDiscountConditions `json:"paymentDiscountConditions"`
}

type InvoiceBodyPaymentDiscountConditions

type InvoiceBodyPaymentDiscountConditions struct {
	DiscountPercentage int `json:"discountPercentage"`
	DiscountRange      int `json:"discountRange"`
}

type InvoiceBodyShippingConditions

type InvoiceBodyShippingConditions struct {
	ShippingDate    string      `json:"shippingDate"`
	ShippingEndDate interface{} `json:"shippingEndDate"`
	ShippingType    string      `json:"shippingType"`
}

type InvoiceBodyTaxAmounts

type InvoiceBodyTaxAmounts struct {
	TaxRatePercentage int     `json:"taxRatePercentage"`
	TaxAmount         float64 `json:"taxAmount"`
	Amount            float64 `json:"amount"`
}

type InvoiceBodyTaxConditions

type InvoiceBodyTaxConditions struct {
	TaxType     string      `json:"taxType"`
	TaxTypeNote interface{} `json:"taxTypeNote"`
}

type InvoiceBodyTotalPrice

type InvoiceBodyTotalPrice struct {
	Currency                string      `json:"currency"`
	TotalNetAmount          float64     `json:"totalNetAmount"`
	TotalGrossAmount        float64     `json:"totalGrossAmount"`
	TaxRatePercentage       interface{} `json:"taxRatePercentage"`
	TotalTaxAmount          float64     `json:"totalTaxAmount"`
	TotalDiscountAbsolute   interface{} `json:"totalDiscountAbsolute"`
	TotalDiscountPercentage interface{} `json:"totalDiscountPercentage"`
}

type InvoiceBodyUnitPrice

type InvoiceBodyUnitPrice struct {
	Currency          string  `json:"currency"`
	NetAmount         float64 `json:"netAmount"`
	GrossAmount       float64 `json:"grossAmount"`
	TaxRatePercentage int     `json:"taxRatePercentage"`
}

type InvoiceReturn

type InvoiceReturn struct {
	Id          string `json:"id"`
	ResourceUri string `json:"resourceUri"`
	CreatedDate string `json:"createdDate"`
	UpdatedDate string `json:"updatedDate"`
	Version     int    `json:"version"`
}

InvoiceReturn is to decode json data

func AddInvoice

func AddInvoice(body InvoiceBody, token string) (InvoiceReturn, error)

AddInvoice is to create a invoice

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL