func (o *Order) ReceiveItem(id string, quantity int) error {
	i, err := o.findItem(id)
	if err != nil {
		return err
	}
	o.Items[i].receive(quantity)
	if o.receivedAll() {
		o.Status = Complete
		return nil
	}
	o.Status = Processed
	return nil
}
Updates the quantity received of an item
package supply
import (
	"errors"
	"fmt"
	"time"
)
var (
	ErrMustHaveItems     = errors.New("order must have at least 1 Item")
	ErrQuantityZero      = errors.New("quantity of all order Items must be greater than 0")
	ErrItemNotFound      = errors.New("item not found")
	ErrItemAlreadyOnList = errors.New("item already on list")
)
type OrderRepository interface {
	Save(o *Order) error
	Find(id string) (*Order, error)
	Delete(id string) error
}
type Order struct {
	ID string
	Project
	Items    []Item
	SentDate int64
	Status   OrderStatus
	Comments string
}
func Create(id, pid, name, foreman, email string) *Order {
	return &Order{
		ID: id,
		Project: Project{
			ID:           pid,
			Name:         name,
			Foreman:      foreman,
			ForemanEmail: email,
		},
		Items:    []Item{},
		SentDate: time.Now().Unix(),
		Status:   Draft,
	}
}
func (o *Order) AddItem(id, name, uom string) error {
	_, err := o.findItem(id)
	if err == nil {
		return ErrItemAlreadyOnList
	}
	item := newItem(id, name, uom)
	o.Items = append([]Item{item}, o.Items...)
	return nil
}
func (o *Order) RemoveItem(id string) error {
	i, err := o.findItem(id)
	if err != nil {
		return err
	}
	o.Items[i].Removed = true
	return nil
}
func (o *Order) UpdateQuantityRequested(id string, quantity int) error {
	i, err := o.findItem(id)
	if err != nil {
		return err
	}
	o.Items[i].QuantityRequested = quantity
	return nil
}
func (o *Order) Send(comments string) error {
	switch {
	case len(o.Items) == 0:
		return ErrMustHaveItems
	case o.missingQuantities():
		return ErrQuantityZero
	}
	for i := range o.Items {
		item := &o.Items[i]
		item.ItemStatus = ToBeOrdered
		item.QuantityRemaining = item.QuantityRequested
	}
	o.Comments = comments
	o.Status = Sent
	o.SentDate = time.Now().Unix()
	return nil
}
func (o *Order) Process() {
	for i := range o.Items {
		item := &o.Items[i]
		item.ItemStatus = Waiting
	}
	o.Status = Processed
}
func (o *Order) UpdatePO(id, po string) error {
	i, err := o.findItem(id)
	if err != nil {
		return err
	}
	if po == "" {
		po = "N/A"
	}
	o.Items[i].PONumber = po
	return nil
}