This commit is contained in:
Dom 2019-11-26 10:36:34 +01:00
parent fb91452c46
commit b50d5837ab
1 changed files with 106 additions and 0 deletions

View File

@ -33,6 +33,26 @@ type paxanWebOrderEntry struct {
Total2 string Total2 string
} }
// WebOrder -
type WebOrder struct {
InvoiceNumber int
Type string
Date string
Items2 []paxanWebOrderEntry
/*Items []struct {
Position string
ArticleNumber int
Description string
ProductLink string
Amount string
Price string
Total string
Amount2 string
Price2 string
Total2 string
}*/
}
func convertStringToBool(value string) bool { func convertStringToBool(value string) bool {
if value == "X" { if value == "X" {
return true return true
@ -269,3 +289,89 @@ func ExportNewOrders(client *http.Client, lastOrder int) error {
return nil return nil
} }
// GetOrders - Get orders
func GetOrders(client *http.Client, lastOrder int) ([]WebOrder, error) {
orders, err := paxanGetOrders(client)
if err != nil {
return nil, err
}
var objects []WebOrder
for _, order := range orders {
if order.InvoiceNumber <= lastOrder {
continue
}
orderDetails, err := paxanGetOrderDetails(client, order.InvoiceNumber)
if err != nil {
return nil, err
}
objects = append(objects, WebOrder{
order.InvoiceNumber, order.Type, order.Date, orderDetails,
})
}
return nil, nil
}
//TODO make it more like a class -> func (p *paxan) something(foo) {}
/*
func selectWishlist(client *http.Client, wishlistNumber int) error {
url := "https://www.hakopaxan-shop.de/html/customerDocument-customerDocumentId-" + strconv.Itoa(orderNumber) + "-customerDocumentListId-invoice-requestedPeriod-365.html"
r, err := client.Get(url)
if err != nil {
return nil, err
}
doc, err := goquery.NewDocumentFromReader(io.Reader(r.Body))
if err != nil {
return nil, err
}
// Go through table row by row
doc.Find(".tableRowGroup").Each(func(i int, s *goquery.Selection) {
var row []string
s.Find(".tableCell").Each(func(j int, s *goquery.Selection) {
text := s.Contents().Text()
// Column 3 contains some more info
if j == 2 {
text = s.Find(".lineItemName").Text()
// Search for the link to the product page
linkTag := s.Find("a")
link, _ := linkTag.Attr("href")
row = append(row, link)
}
text = strings.Replace(text, "\n", "", -1)
text = strings.TrimSpace(text)
row = append(row, text)
})
num, _ := strconv.Atoi(row[1])
n := paxanWebOrderEntry{Position: row[0],
ArticleNumber: num,
Description: row[3],
ProductLink: row[2],
Amount: row[4],
Price: row[5],
Total: row[6],
Amount2: row[7],
Price2: row[8],
Total2: row[9]}
list = append(list, n)
})
return nil
}
func AddArticleWishlist(client *http.Client, wishlistNumber int, articleNumber int) error {
// select wishlist (if not already selected)
return nil
}
*/