Update Filters, Limit, Search, Page
This commit is contained in:
@@ -14,7 +14,7 @@ func NewCollectionRepository(db *gorm.DB) *CollectionRepository {
|
||||
return &CollectionRepository{DB: db}
|
||||
}
|
||||
|
||||
func (r *CollectionRepository) FindAll(limit, offset int, search string) ([]models.Collection, error) {
|
||||
func (r *CollectionRepository) FindAll(page, limit, offset int, search string) ([]models.Collection, error) {
|
||||
|
||||
var collections []models.Collection
|
||||
query := r.DB.Model(&models.Collection{})
|
||||
@@ -24,6 +24,7 @@ func (r *CollectionRepository) FindAll(limit, offset int, search string) ([]mode
|
||||
}
|
||||
|
||||
err := query.
|
||||
Order("created_at DESC").
|
||||
Limit(limit).
|
||||
Offset(offset).
|
||||
Find(&collections).Error
|
||||
|
||||
@@ -14,7 +14,7 @@ func NewColourRepository(db *gorm.DB) *ColourRepository {
|
||||
return &ColourRepository{DB: db}
|
||||
}
|
||||
|
||||
func (r *ColourRepository) FindAll(limit, offset int, search string) ([]models.Colour, error) {
|
||||
func (r *ColourRepository) FindAll(page, limit, offset int, search string) ([]models.Colour, error) {
|
||||
var colours []models.Colour
|
||||
|
||||
query := r.DB.Model(&models.Colour{})
|
||||
@@ -24,6 +24,7 @@ func (r *ColourRepository) FindAll(limit, offset int, search string) ([]models.C
|
||||
}
|
||||
|
||||
err := query.
|
||||
Order("created_at DESC").
|
||||
Limit(limit).
|
||||
Offset(offset).
|
||||
Find(&colours).Error
|
||||
|
||||
@@ -16,7 +16,7 @@ func NewProductRepository(db *gorm.DB) *ProductRepository {
|
||||
return &ProductRepository{DB: db}
|
||||
}
|
||||
|
||||
func (r *ProductRepository) FindAll(limit, offset int, search string, categoryID, collectionID, colourID, sizeID uint) ([]models.Product, error) {
|
||||
func (r *ProductRepository) FindAll(page, limit, offset int, search string, categoryID, collectionID, colourID, sizeID uint) ([]models.Product, error) {
|
||||
var products []models.Product
|
||||
|
||||
query := r.DB.Model(&models.Product{}).
|
||||
@@ -43,6 +43,7 @@ func (r *ProductRepository) FindAll(limit, offset int, search string, categoryID
|
||||
}
|
||||
|
||||
err := query.
|
||||
Order("created_at DESC").
|
||||
Limit(limit).
|
||||
Offset(offset).
|
||||
Find(&products).Error
|
||||
|
||||
@@ -14,7 +14,7 @@ func NewCategoryRepository(db *gorm.DB) *CategoryRepository {
|
||||
return &CategoryRepository{DB: db}
|
||||
}
|
||||
|
||||
func (r *CategoryRepository) FindAll(limit, offset int, search string) ([]models.ProductCategory, error) {
|
||||
func (r *CategoryRepository) FindAll(page, limit, offset int, search string) ([]models.ProductCategory, error) {
|
||||
var categories []models.ProductCategory
|
||||
query := r.DB.Model(&models.ProductCategory{})
|
||||
|
||||
@@ -23,6 +23,7 @@ func (r *CategoryRepository) FindAll(limit, offset int, search string) ([]models
|
||||
}
|
||||
|
||||
err := query.
|
||||
Order("created_at DESC").
|
||||
Limit(limit).
|
||||
Offset(offset).
|
||||
Find(&categories).Error
|
||||
|
||||
@@ -14,13 +14,31 @@ func NewProductComponentRepository(db *gorm.DB) *ProductComponentRepository {
|
||||
return &ProductComponentRepository{DB: db}
|
||||
}
|
||||
|
||||
func (r *ProductComponentRepository) FindAll() ([]models.ProductComponent, error) {
|
||||
var data []models.ProductComponent
|
||||
err := r.DB.
|
||||
func (r *ProductComponentRepository) FindAll(page, limit, offset int, search string, productID, componenID uint) ([]models.ProductComponent, error) {
|
||||
var components []models.ProductComponent
|
||||
|
||||
query := r.DB.Model(&models.ProductComponent{}).
|
||||
Preload("Product").
|
||||
Preload("Component").
|
||||
Find(&data).Error
|
||||
return data, err
|
||||
Preload("Component")
|
||||
|
||||
if search != "" {
|
||||
query = query.Where("product_id ILIKE ? OR componen_id ILIKE ?", "%"+search+"%", "%"+search+"%")
|
||||
}
|
||||
|
||||
if productID != 0 {
|
||||
query = query.Where("product_id = ?", productID)
|
||||
}
|
||||
if componenID != 0 {
|
||||
query = query.Where("componen_id = ?", componenID)
|
||||
}
|
||||
|
||||
err := query.
|
||||
Order("created_at DESC").
|
||||
Limit(limit).
|
||||
Offset(offset).
|
||||
Find(&components).Error
|
||||
|
||||
return components, err
|
||||
}
|
||||
|
||||
func (r *ProductComponentRepository) Create(pc *models.ProductComponent) error {
|
||||
|
||||
@@ -2,6 +2,7 @@ package repository
|
||||
|
||||
import (
|
||||
"BE-MiniERP/modules/inventory/models"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -14,9 +15,37 @@ func NewProductionOrderRepository(db *gorm.DB) *ProductionOrderRepository {
|
||||
return &ProductionOrderRepository{DB: db}
|
||||
}
|
||||
|
||||
func (r *ProductionOrderRepository) FindAll() ([]models.ProductionOrder, error) {
|
||||
func (r *ProductionOrderRepository) FindAll(page, limit, offset int, search string, productID, warehouseID uint, startDate, endDate time.Time) ([]models.ProductionOrder, error) {
|
||||
var orders []models.ProductionOrder
|
||||
err := r.DB.Preload("Product").Find(&orders).Error
|
||||
|
||||
query := r.DB.Model(&models.ProductionOrder{}).
|
||||
Preload("Product").
|
||||
Preload("OriginWarehouse")
|
||||
|
||||
if search != "" {
|
||||
query = query.Where("status ILIKE ?", "%"+search+"%")
|
||||
}
|
||||
|
||||
if productID != 0 {
|
||||
query = query.Where("product_id = ?", productID)
|
||||
}
|
||||
|
||||
if warehouseID != 0 {
|
||||
query = query.Where("origin_warehouse_id = ?", warehouseID)
|
||||
}
|
||||
|
||||
if !startDate.IsZero() {
|
||||
query = query.Where("created_at >= ?", startDate)
|
||||
}
|
||||
if !endDate.IsZero() {
|
||||
query = query.Where("created_at <= ?", endDate)
|
||||
}
|
||||
err := query.
|
||||
Order("created_at DESC").
|
||||
Limit(limit).
|
||||
Offset(offset).
|
||||
Find(&orders).Error
|
||||
|
||||
return orders, err
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ func NewSizeRepository(db *gorm.DB) *SizeRepository {
|
||||
return &SizeRepository{DB: db}
|
||||
}
|
||||
|
||||
func (r *SizeRepository) FindAll(limit, offset int, search string) ([]models.Size, error) {
|
||||
func (r *SizeRepository) FindAll(page, limit, offset int, search string) ([]models.Size, error) {
|
||||
var sizes []models.Size
|
||||
|
||||
query := r.DB.Model(&models.Size{})
|
||||
@@ -24,6 +24,7 @@ func (r *SizeRepository) FindAll(limit, offset int, search string) ([]models.Siz
|
||||
}
|
||||
|
||||
err := query.
|
||||
Order("created_at DESC").
|
||||
Limit(limit).
|
||||
Offset(offset).
|
||||
Find(&sizes).Error
|
||||
|
||||
@@ -2,6 +2,7 @@ package repository
|
||||
|
||||
import (
|
||||
"BE-MiniERP/modules/inventory/models"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -14,12 +15,35 @@ func NewStockMovementRepository(db *gorm.DB) *StockMovementRepository {
|
||||
return &StockMovementRepository{DB: db}
|
||||
}
|
||||
|
||||
func (r *StockMovementRepository) FindAll() ([]models.StockMovement, error) {
|
||||
func (r *StockMovementRepository) FindAll(page, limit, offset int, search string, productID, originID, destinationID uint, selectedDate time.Time) ([]models.StockMovement, error) {
|
||||
var movements []models.StockMovement
|
||||
err := r.DB.
|
||||
query := r.DB.Model(&models.StockMovement{}).
|
||||
Preload("Product").
|
||||
Preload("OriginWarehouse").
|
||||
Preload("DestinationWarehouse").
|
||||
Preload("DestinationWarehouse")
|
||||
|
||||
if search != "" {
|
||||
query = query.Where("stock_type ILIKE ?", "%"+search+"%")
|
||||
}
|
||||
|
||||
if productID != 0 {
|
||||
query = query.Where("product_id = ?", productID)
|
||||
}
|
||||
if originID != 0 {
|
||||
query = query.Where("origin_warehouse_id = ?", originID)
|
||||
}
|
||||
if destinationID != 0 {
|
||||
query = query.Where("destination_warehouse_id = ?", destinationID)
|
||||
}
|
||||
|
||||
if !selectedDate.IsZero() {
|
||||
query = query.Where("DATE(created_at) = ?", selectedDate.Format("2006-01-02"))
|
||||
}
|
||||
|
||||
err := query.
|
||||
Order("created_at DESC").
|
||||
Limit(limit).
|
||||
Offset(offset).
|
||||
Find(&movements).Error
|
||||
return movements, err
|
||||
}
|
||||
|
||||
@@ -14,9 +14,19 @@ func NewWarehouseRepository(db *gorm.DB) *WarehouseRepository {
|
||||
return &WarehouseRepository{DB: db}
|
||||
}
|
||||
|
||||
func (r *WarehouseRepository) FindAll() ([]models.Warehouse, error) {
|
||||
func (r *WarehouseRepository) FindAll(page, limit, offset int, search string) ([]models.Warehouse, error) {
|
||||
var warehouses []models.Warehouse
|
||||
err := r.DB.Find(&warehouses).Error
|
||||
query := r.DB.Model(&models.Warehouse{})
|
||||
|
||||
if search != "" {
|
||||
query = query.Where("name ILIKE ? OR kode ILIKE ? OR stackholder ILIKE ? OR number ILIKE ?", "%"+search+"%", "%"+search+"%", "%"+search+"%", "%"+search+"%")
|
||||
}
|
||||
|
||||
err := query.
|
||||
Order("created_at DESC").
|
||||
Limit(limit).
|
||||
Offset(offset).
|
||||
Find(&warehouses).Error
|
||||
return warehouses, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user