Add vendor workspace import and pricing export workflow
This commit is contained in:
@@ -31,6 +31,35 @@ func (r *PartnumberBookRepository) GetBookItems(bookID uint) ([]localdb.LocalPar
|
||||
return items, err
|
||||
}
|
||||
|
||||
// GetBookItemsPage returns items for the given local book ID with optional search and pagination.
|
||||
func (r *PartnumberBookRepository) GetBookItemsPage(bookID uint, search string, page, perPage int) ([]localdb.LocalPartnumberBookItem, int64, error) {
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
if perPage < 1 {
|
||||
perPage = 100
|
||||
}
|
||||
|
||||
query := r.db.Model(&localdb.LocalPartnumberBookItem{}).Where("book_id = ?", bookID)
|
||||
trimmedSearch := "%" + search + "%"
|
||||
if search != "" {
|
||||
query = query.Where("partnumber LIKE ? OR lot_name LIKE ?", trimmedSearch, trimmedSearch)
|
||||
}
|
||||
|
||||
var total int64
|
||||
if err := query.Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
var items []localdb.LocalPartnumberBookItem
|
||||
err := query.
|
||||
Order("partnumber ASC, lot_name ASC, id ASC").
|
||||
Offset((page - 1) * perPage).
|
||||
Limit(perPage).
|
||||
Find(&items).Error
|
||||
return items, total, err
|
||||
}
|
||||
|
||||
// FindLotByPartnumber looks up a partnumber in the active book and returns the matching items.
|
||||
func (r *PartnumberBookRepository) FindLotByPartnumber(bookID uint, partnumber string) ([]localdb.LocalPartnumberBookItem, error) {
|
||||
var items []localdb.LocalPartnumberBookItem
|
||||
@@ -64,3 +93,20 @@ func (r *PartnumberBookRepository) CountBookItems(bookID uint) int64 {
|
||||
r.db.Model(&localdb.LocalPartnumberBookItem{}).Where("book_id = ?", bookID).Count(&count)
|
||||
return count
|
||||
}
|
||||
|
||||
func (r *PartnumberBookRepository) CountDistinctLots(bookID uint) int64 {
|
||||
var count int64
|
||||
r.db.Model(&localdb.LocalPartnumberBookItem{}).
|
||||
Where("book_id = ?", bookID).
|
||||
Distinct("lot_name").
|
||||
Count(&count)
|
||||
return count
|
||||
}
|
||||
|
||||
func (r *PartnumberBookRepository) CountPrimaryItems(bookID uint) int64 {
|
||||
var count int64
|
||||
r.db.Model(&localdb.LocalPartnumberBookItem{}).
|
||||
Where("book_id = ? AND is_primary_pn = ?", bookID, true).
|
||||
Count(&count)
|
||||
return count
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user