Ejemplo n.º 1
0
func main() {
	go func() {
		port := os.Getenv("PORT")
		if port == "" {
			port = "8081"
		}
		http.HandleFunc("/", pageHandler)
		http.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(http.Dir("assets"))))
		http.ListenAndServe(":"+port, nil)
	}()
	for {
		ps, _ := ioutil.ReadFile("assets/people.config")
		people := stringutil.Tokens(string(ps), "\n")
		recurring := datatable.RecurringSales()
		news := datatable.NewSales()
		pages["week"] = &Page{
			Title:     "week",
			Calls:     datatable.WeekCalls(people),
			Total:     news + recurring,
			Remaining: 71970.00 - news - recurring,
			New:       news,
			Recurring: recurring,
		}
		pages["day"] = &Page{
			Title:     "day",
			Calls:     datatable.DayCalls(people),
			Total:     news + recurring,
			Remaining: 71970.00 - news - recurring,
			New:       news,
			Recurring: recurring,
		}
		fmt.Println("manager succeeded")
		time.Sleep(time.Second * 60)
	}
}
Ejemplo n.º 2
0
func pageHandler(rw http.ResponseWriter, r *http.Request) {
	p := stringutil.Tokens(r.URL.Path, "/")[1]
	if pages[p] != nil {
		templates.ExecuteTemplate(rw, p+".html", pages[p])
	} else {
		http.Error(rw, "404 - not found", 404)
	}
}
Ejemplo n.º 3
0
func NewSales() float64 {
	start, end := week.This()
	q, _ := Query("UDA", "SELECT sum(amount) from paypal where date between '"+start+"' and '"+end+"' and result = 0 and [comment 2] not like 'Recurring%'")
	for _, v := range stringutil.Tokens(q, "\n\r ") {
		if f, e := strconv.ParseFloat(v, 64); e == nil {
			return f
		}
	}
	return 0.00
}
Ejemplo n.º 4
0
func rowToAcct(t []string) Account {
	i, _ := strconv.ParseFloat(stringutil.Tokens(t[7], " ")[1], 64)
	return Account{
		t[1],
		t[2],
		t[3],
		i,
		toDate(t[10]),
		toDate(t[11]),
		toDate(t[12]),
		toDate(t[13]),
	}
}
Ejemplo n.º 5
0
func toDate(s string) Date {
	if split := stringutil.Tokens(s, ", \""); len(split) >= 3 {
		return Date{monthToInt(split[2]), stripErr(split[3]), stripErr(split[5])}
	}
	return Date{}
}