Exemplo n.º 1
0
func (endPt EndPt) ProdValEvol(id string) (data map[string]items.Items) {
	// TODO : should be generated when even arrives
	acts := endPt.Db.GetAllEvents(id)
	data = make(map[string]items.Items, len(acts))
	state := make(items.Items, 0)

	i := 0
loop:
	for _, a := range acts {
		switch act := a.(skelet.Event).Act.(type) {
		case stock.In:
			state = items.Add(state, act.Items)
		case stock.Out:
			state = items.Sub(state, act.Items)
		case stock.Inventory:
			state = act.Items.Copy()
		default:
			continue loop
		}
		data[a.(skelet.Event).Date] = state.Copy()
		i++
	}

	return

}
Exemplo n.º 2
0
func FromActions(acts []interface{}, id string) skelet.Ider {
	s := MakeStock(id).(*Stock)
	for _, act := range acts {
		switch act := act.(type) {
		case In:
			s.Items = items.Add(s.Items, act.Items)
		case Out:
			s.Items = items.Sub(s.Items, act.Items)
		case Inventory:
			s.Items = act.Items.Copy()
		case Rename:
			s.Name = act.Name
		}
	}
	return s
}
Exemplo n.º 3
0
func (s *Stock) SubmitIn(i InCmd) (e In, err error) {
	s.Items = items.Add(s.Items, i.Items)
	e = In{i.Items}
	return
}