示例#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

}
示例#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
}
示例#3
0
func (s *Stock) SubmitOut(o OutCmd) (e Out, err error) {
	s.Items = items.Sub(s.Items, o.Items)
	e = Out{o.Items}
	return
}