Esempio n. 1
0
func (p *InventoryIndex) SetupRender() {
	// verify user role.
	// service.User.RequireRole(p.W, p.R, "admin") // TODO remove w, r. use service injection.

	// fix the pagers
	if p.PageItems <= 0 {
		p.PageItems = config.LIST_PAGE_SIZE // TODO default pager number. Config this.
	}

	// parameter time
	if !utils.IsValidTime(p.TimeFrom) {
		p.TimeFrom = time.Date(2015, time.January, 1, 0, 0, 0, 0, time.Local)
	}
	if !utils.IsValidTime(p.TimeTo) {
		p.TimeTo = time.Now()
	}

	// load inventory group
	var err error
	parser := service.InventoryGroup.EntityManager().NewQueryParser().Where()
	switch strings.ToLower(p.Tab) {
	case "all", "":
	default:
		// parser.And("status", p.Tab)
	}

	// filter by provider
	if p.Provider > 0 {
		fmt.Println("_______________")
		fmt.Println("And filter by provider_id ", p.Provider)
		parser.And(inventory.F_ProviderId, p.Provider)
	}
	// time
	if utils.IsValidTime(p.TimeFrom) && utils.IsValidTime(p.TimeTo) {
		parser.Range(inventory.FSendTime, p.TimeFrom, p.TimeTo)
	}

	parser.And(inventory.F_Type, inventory.TypeReceive)

	// parser.Or("type", model.Wholesale, model.ShippingInstead) // restrict type
	parser.OrderBy(inventory.FSendTime, db.DESC)

	// get total
	p.Total, err = parser.Count()
	if err != nil {
		panic(err.Error())
	}

	// 2. get order list.
	parser.Limit(p.Current, p.PageItems) // pager
	p.InventoryGroups, err = service.InventoryGroup.List(parser, service.WITH_PERSON)
	if err != nil {
		panic(err.Error())
	}
}
Esempio n. 2
0
func (p *FactorySettleAccount) SetupRender() *exit.Exit {

	// parameter time
	if !utils.IsValidTime(p.TimeFrom) {
		p.TimeFrom = time.Date(2015, time.January, 1, 0, 0, 0, 0, time.Local)
	}
	if !utils.IsValidTime(p.TimeTo) {
		p.TimeTo = time.Now()
	}

	fmt.Println("Time is from / to: ", p.TimeFrom, p.TimeTo)

	// p.Data = model.NewTestProductSalesTable() //(startTime, endTime)
	pst, err := settleaccountdao.SettleAccount(p.TimeFrom, p.TimeTo, p.Provider)
	if err != nil {
		fmt.Println(err)
		return exit.Error(err)
	}
	p.Data = pst

	return nil
}