common

package
v0.0.0-...-566a6b1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Copyright © 2019 zhijie wang

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	Available ItemStatus = 1
	Reserved             = 2
	Shipped              = 3
	Lost                 = 4
)

Available means the item is in inventory, can be sold Reserved means the item is marked for an order. If the order is canceld, the item becomes available again. If the item is shipped, the item becomes shipped. Shipped means the item is shipped and the order is fullfiled. This marks the item can now be consider as part of cost of goods sold. Lost means the item is either damaged or no longer possible for sale. This can be added to either cost of goods sold or to expense for write off.

Variables

This section is empty.

Functions

This section is empty.

Types

type Inventory

type Inventory struct {
	*gorm.DB
}

func OpenInventory

func OpenInventory(path string) *Inventory

func (*Inventory) AddItem

func (db *Inventory) AddItem(pCode string, cost float32, status ItemStatus) error

AddItem function performs the operation adding the Item instance to the database. If there is any issue, the operation will throw an error. The argument db points to a db connection, the argument pCode points to a productCode, should be randomly generated, either UUID or user defined, the status argument is the enumeration represent item status.

func (*Inventory) AddItems

func (db *Inventory) AddItems(pCode string, cost float32, num int) error

AddItems add many items to that of same product code to the database, the serial number is generated automatically. This operation does not check whether the item is already in the database or not. This operation implies bulk intake of product, thus all item status will set to default Availabel

func (*Inventory) AddProduct

func (db *Inventory) AddProduct(pName string, code string) error

func (*Inventory) CostOfGoodsSold

func (db *Inventory) CostOfGoodsSold(month time.Time) int

func (*Inventory) ListInventory

func (db *Inventory) ListInventory(pCode string) *[]Item

func (*Inventory) ListProduct

func (db *Inventory) ListProduct() *[]Product

func (*Inventory) ShipItem

func (db *Inventory) ShipItem(pCode string, date time.Time) error

ShipItem mark item as shipped and shipped date as given date

func (*Inventory) ShipItems

func (db *Inventory) ShipItems(pCode string, number int, date time.Time) error

ShipItems ships multiple items, given a ProductCode and the numbers. The default date time is Now.

type Item

type Item struct {
	gorm.Model
	Status      ItemStatus `gorm:"not null;default:0"`
	ProductCode string     `gorm:"not null"`
	UnitCost    float32
	ShippedDate time.Time
}

Item represent each individual goods to be sold, assume discrete and concrete item.

type ItemStatus

type ItemStatus int

ItemStatus denotes the current status of the individual item. Default to 0, denoting the item is available.

func (*ItemStatus) Scan

func (u *ItemStatus) Scan(value interface{}) error

func (ItemStatus) Value

func (u ItemStatus) Value() (driver.Value, error)

type Product

type Product struct {
	gorm.Model
	Code     string `gorm:"unique;not null"`
	NickName string `gorm:"unique;not null"`
	Items    []Item `gorm:"foreignkey:ProductCode"`
}

Product is the interface defines one type of product or sku

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL