mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
Merge branch 'development' into 'production'
Development See merge request mbugroup/lti-api!476
This commit is contained in:
@@ -25,9 +25,10 @@ func NewProductStockController(productStockService service.ProductStockService)
|
||||
|
||||
func (u *ProductStockController) GetAll(c *fiber.Ctx) error {
|
||||
query := &validation.Query{
|
||||
Page: c.QueryInt("page", 1),
|
||||
Limit: c.QueryInt("limit", 10),
|
||||
Search: c.Query("search", ""),
|
||||
Page: c.QueryInt("page", 1),
|
||||
Limit: c.QueryInt("limit", 10),
|
||||
Search: c.Query("search", ""),
|
||||
ProductCategoryID: uint(c.QueryInt("product_category_id", 0)),
|
||||
}
|
||||
|
||||
if query.Page < 1 || query.Limit < 1 {
|
||||
|
||||
@@ -129,6 +129,9 @@ func (s productStockService) GetAll(c *fiber.Ctx, params *validation.Query) ([]e
|
||||
if params.Search != "" {
|
||||
db = db.Where("products.name ILIKE ?", "%"+params.Search+"%")
|
||||
}
|
||||
if params.ProductCategoryID > 0 {
|
||||
db = db.Where("products.product_category_id = ?", params.ProductCategoryID)
|
||||
}
|
||||
return db.Order("products.created_at DESC").Order("products.updated_at DESC")
|
||||
})
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@ type Update struct {
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
Page int `query:"page" validate:"omitempty,number,min=1,gt=0"`
|
||||
Limit int `query:"limit" validate:"omitempty,number,min=1,max=100,gt=0"`
|
||||
Search string `query:"search" validate:"omitempty,max=50"`
|
||||
Page int `query:"page" validate:"omitempty,number,min=1,gt=0"`
|
||||
Limit int `query:"limit" validate:"omitempty,number,min=1,max=100,gt=0"`
|
||||
Search string `query:"search" validate:"omitempty,max=50"`
|
||||
ProductCategoryID uint `query:"product_category_id" validate:"omitempty"`
|
||||
}
|
||||
|
||||
+22
@@ -23,6 +23,7 @@ type ProductWarehouseRepository interface {
|
||||
GetByCategoryCodeAndWarehouseID(ctx context.Context, categoryCode string, warehouseId uint) ([]entity.ProductWarehouse, error)
|
||||
GetLatestByCategoryCodeAndWarehouseID(ctx context.Context, categoryCode string, warehouseId uint, db *gorm.DB) (*entity.ProductWarehouse, error)
|
||||
GetByFlagAndWarehouseID(ctx context.Context, flagName string, warehouseId uint) ([]entity.ProductWarehouse, error)
|
||||
GetByFlagsAndWarehouseID(ctx context.Context, flagNames []string, excludeFlagNames []string, warehouseId uint) ([]entity.ProductWarehouse, error)
|
||||
GetFirstProductByFlag(ctx context.Context, flagName string) (*entity.Product, error)
|
||||
ListProductIDsByFlagPrefixes(ctx context.Context, prefixes []string, visibleStatus *bool) ([]uint, error)
|
||||
ApplyFlagsFilter(db *gorm.DB, flags []string) *gorm.DB
|
||||
@@ -430,6 +431,27 @@ func (r *ProductWarehouseRepositoryImpl) GetByFlagAndWarehouseID(ctx context.Con
|
||||
return productWarehouses, nil
|
||||
}
|
||||
|
||||
func (r *ProductWarehouseRepositoryImpl) GetByFlagsAndWarehouseID(ctx context.Context, flagNames []string, excludeFlagNames []string, warehouseId uint) ([]entity.ProductWarehouse, error) {
|
||||
var productWarehouses []entity.ProductWarehouse
|
||||
q := r.DB().WithContext(ctx).Model(&entity.ProductWarehouse{}).
|
||||
Joins("JOIN products ON products.id = product_warehouses.product_id").
|
||||
Joins("JOIN flags ON flags.flagable_id = products.id AND flags.flagable_type = 'products'").
|
||||
Where("flags.name IN ? AND product_warehouses.warehouse_id = ?", flagNames, warehouseId)
|
||||
if len(excludeFlagNames) > 0 {
|
||||
q = q.Where("NOT EXISTS (SELECT 1 FROM flags ef WHERE ef.flagable_id = products.id AND ef.flagable_type = 'products' AND ef.name IN ?)", excludeFlagNames)
|
||||
}
|
||||
err := q.Order("product_warehouses.id DESC").
|
||||
Preload("Product").
|
||||
Preload("Product.ProductCategory").
|
||||
Preload("Product.Uom").
|
||||
Preload("Warehouse").
|
||||
Find(&productWarehouses).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return productWarehouses, nil
|
||||
}
|
||||
|
||||
func (r *ProductWarehouseRepositoryImpl) GetFirstProductByFlag(ctx context.Context, flagName string) (*entity.Product, error) {
|
||||
var product entity.Product
|
||||
err := r.DB().WithContext(ctx).
|
||||
|
||||
@@ -25,9 +25,11 @@ func NewTransferController(transferService service.TransferService) *TransferCon
|
||||
|
||||
func (u *TransferController) GetAll(c *fiber.Ctx) error {
|
||||
query := &validation.Query{
|
||||
Page: c.QueryInt("page", 1),
|
||||
Limit: c.QueryInt("limit", 10),
|
||||
Search: c.Query("search", ""),
|
||||
Page: c.QueryInt("page", 1),
|
||||
Limit: c.QueryInt("limit", 10),
|
||||
Search: c.Query("search", ""),
|
||||
ProductID: uint(c.QueryInt("product_id", 0)),
|
||||
WarehouseID: uint(c.QueryInt("warehouse_id", 0)),
|
||||
}
|
||||
|
||||
result, totalResults, err := u.TransferService.GetAll(c, query)
|
||||
|
||||
@@ -157,6 +157,12 @@ func (s transferService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entit
|
||||
Where("movement_number ILIKE ? OR from_warehouses.name ILIKE ? OR to_warehouses.name ILIKE ?",
|
||||
searchTerm, searchTerm, searchTerm)
|
||||
}
|
||||
if params.ProductID > 0 {
|
||||
db = db.Joins("JOIN stock_transfer_details AS filter_std ON filter_std.stock_transfer_id = stock_transfers.id AND filter_std.deleted_at IS NULL AND filter_std.product_id = ?", params.ProductID)
|
||||
}
|
||||
if params.WarehouseID > 0 {
|
||||
db = db.Where("stock_transfers.from_warehouse_id = ? OR stock_transfers.to_warehouse_id = ?", params.WarehouseID, params.WarehouseID)
|
||||
}
|
||||
return db.Order("created_at DESC").Order("updated_at DESC")
|
||||
})
|
||||
|
||||
|
||||
@@ -5,9 +5,11 @@ type Create struct {
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
Page int `query:"page" validate:"omitempty,number,min=1"`
|
||||
Limit int `query:"limit" validate:"omitempty,number,min=1,max=100"`
|
||||
Search string `query:"search" validate:"omitempty,max=50"`
|
||||
Page int `query:"page" validate:"omitempty,number,min=1"`
|
||||
Limit int `query:"limit" validate:"omitempty,number,min=1,max=100"`
|
||||
Search string `query:"search" validate:"omitempty,max=50"`
|
||||
ProductID uint `query:"product_id" validate:"omitempty"`
|
||||
WarehouseID uint `query:"warehouse_id" validate:"omitempty"`
|
||||
}
|
||||
|
||||
type TransferProduct struct {
|
||||
|
||||
+13
-7
@@ -302,16 +302,22 @@ func (s projectFlockKandangService) getAvailableQuantities(c *fiber.Ctx, project
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var productCategoryCode string
|
||||
if projectFlockKandang.ProjectFlock.Category == string(utils.ProjectFlockCategoryGrowing) {
|
||||
productCategoryCode = "DOC"
|
||||
} else if projectFlockKandang.ProjectFlock.Category == string(utils.ProjectFlockCategoryLaying) {
|
||||
productCategoryCode = "PULLET"
|
||||
} else {
|
||||
if projectFlockKandang.ProjectFlock.Category != string(utils.ProjectFlockCategoryGrowing) &&
|
||||
projectFlockKandang.ProjectFlock.Category != string(utils.ProjectFlockCategoryLaying) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
products, err := s.ProductWarehouseRepo.GetByFlagAndWarehouseID(c.Context(), productCategoryCode, warehouse.Id)
|
||||
ayamFlags := []string{
|
||||
string(utils.FlagAyam),
|
||||
string(utils.FlagDOC),
|
||||
string(utils.FlagPullet),
|
||||
}
|
||||
ayamSubFlags := []string{
|
||||
string(utils.FlagAyamAfkir),
|
||||
string(utils.FlagAyamCulling),
|
||||
string(utils.FlagAyamMati),
|
||||
}
|
||||
products, err := s.ProductWarehouseRepo.GetByFlagsAndWarehouseID(c.Context(), ayamFlags, ayamSubFlags, warehouse.Id)
|
||||
if err != nil || len(products) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user