mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
Merge branch 'development' of https://gitlab.com/mbugroup/lti-api into dev/teguh
This commit is contained in:
@@ -534,6 +534,13 @@ JOIN products prod ON prod.id = pw.product_id
|
|||||||
JOIN uoms u ON u.id = prod.uom_id
|
JOIN uoms u ON u.id = prod.uom_id
|
||||||
JOIN warehouses w ON w.id = pw.warehouse_id
|
JOIN warehouses w ON w.id = pw.warehouse_id
|
||||||
WHERE pw.project_flock_kandang_id IN ?
|
WHERE pw.project_flock_kandang_id IN ?
|
||||||
|
AND EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM flags f
|
||||||
|
WHERE f.flagable_id = pw.product_id
|
||||||
|
AND f.flagable_type = 'products'
|
||||||
|
AND UPPER(f.name) NOT IN ('DOC', 'LAYER', 'PULLET')
|
||||||
|
)
|
||||||
`
|
`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -260,11 +260,18 @@ func (s *transferService) CreateOne(c *fiber.Ctx, req *validation.TransferReques
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set ProjectFlockKandangId hanya jika ada kandang
|
||||||
|
var pfkID *uint
|
||||||
|
if projectFlockKandangID > 0 {
|
||||||
|
pfkID = &projectFlockKandangID
|
||||||
|
}
|
||||||
|
|
||||||
destPW = &entity.ProductWarehouse{
|
destPW = &entity.ProductWarehouse{
|
||||||
ProductId: uint(product.ProductID),
|
ProductId: uint(product.ProductID),
|
||||||
WarehouseId: uint(req.DestinationWarehouseID),
|
WarehouseId: uint(req.DestinationWarehouseID),
|
||||||
Quantity: 0,
|
Quantity: 0,
|
||||||
ProjectFlockKandangId: &projectFlockKandangID,
|
ProjectFlockKandangId: pfkID,
|
||||||
}
|
}
|
||||||
if err := productWarehouseRepoTX.CreateOne(c.Context(), destPW, nil); err != nil {
|
if err := productWarehouseRepoTX.CreateOne(c.Context(), destPW, nil); err != nil {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, fmt.Sprintf("Gagal membuat product warehouse untuk produk %d di gudang tujuan", product.ProductID))
|
return fiber.NewError(fiber.StatusInternalServerError, fmt.Sprintf("Gagal membuat product warehouse untuk produk %d di gudang tujuan", product.ProductID))
|
||||||
@@ -464,13 +471,6 @@ func (s *transferService) notifyExpenseItemsDelivered(c *fiber.Ctx, transferID u
|
|||||||
return s.ExpenseBridge.OnItemsDelivered(c, transferID, payloads)
|
return s.ExpenseBridge.OnItemsDelivered(c, transferID, payloads)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *transferService) notifyExpenseDetailsDeleted(ctx context.Context, transferID uint64, items []entity.StockTransferDetail) error {
|
|
||||||
if s.ExpenseBridge == nil || transferID == 0 || len(items) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return s.ExpenseBridge.OnItemsDeleted(ctx, transferID, items)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *transferService) getActiveProjectFlockKandangID(ctx context.Context, warehouseID uint) (uint, error) {
|
func (s *transferService) getActiveProjectFlockKandangID(ctx context.Context, warehouseID uint) (uint, error) {
|
||||||
warehouse, err := s.WarehouseRepo.GetByID(ctx, warehouseID, nil)
|
warehouse, err := s.WarehouseRepo.GetByID(ctx, warehouseID, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -480,8 +480,9 @@ func (s *transferService) getActiveProjectFlockKandangID(ctx context.Context, wa
|
|||||||
return 0, fiber.NewError(fiber.StatusInternalServerError, fmt.Sprintf("Gagal mengambil data gudang dengan ID %d", warehouseID))
|
return 0, fiber.NewError(fiber.StatusInternalServerError, fmt.Sprintf("Gagal mengambil data gudang dengan ID %d", warehouseID))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Jika warehouse tidak punya kandang_id, return 0 tanpa error
|
||||||
if warehouse.KandangId == nil || *warehouse.KandangId == 0 {
|
if warehouse.KandangId == nil || *warehouse.KandangId == 0 {
|
||||||
return 0, fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("Gudang '%s' (ID: %d) belum terhubung ke kandang", warehouse.Name, warehouseID))
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
projectFlockKandang, err := s.ProjectFlockKandangRepo.GetActiveByKandangID(ctx, uint(*warehouse.KandangId))
|
projectFlockKandang, err := s.ProjectFlockKandangRepo.GetActiveByKandangID(ctx, uint(*warehouse.KandangId))
|
||||||
|
|||||||
@@ -140,8 +140,8 @@ func (r *MarketingDeliveryProductRepositoryImpl) GetAllWithFilters(ctx context.C
|
|||||||
Joins("JOIN marketings ON marketings.id = marketing_products.marketing_id").
|
Joins("JOIN marketings ON marketings.id = marketing_products.marketing_id").
|
||||||
Where("marketing_delivery_products.delivery_date IS NOT NULL")
|
Where("marketing_delivery_products.delivery_date IS NOT NULL")
|
||||||
|
|
||||||
if filters.ProductId > 0 || filters.WarehouseId > 0 || filters.Search != "" || filters.MarketingType != "" {
|
if filters.ProductId > 0 || filters.WarehouseId > 0 || filters.AreaId > 0 || filters.LocationId > 0 || filters.Search != "" || filters.MarketingType != "" {
|
||||||
db = db.Joins("LEFT JOIN product_warehouses ON product_warehouses.id = marketing_delivery_products.product_warehouse_id")
|
db = db.Joins("LEFT JOIN product_warehouses ON product_warehouses.id = marketing_products.product_warehouse_id")
|
||||||
}
|
}
|
||||||
|
|
||||||
if filters.ProductId > 0 || filters.Search != "" || filters.MarketingType != "" {
|
if filters.ProductId > 0 || filters.Search != "" || filters.MarketingType != "" {
|
||||||
@@ -190,6 +190,19 @@ func (r *MarketingDeliveryProductRepositoryImpl) GetAllWithFilters(ctx context.C
|
|||||||
db = db.Where("product_warehouses.warehouse_id = ?", filters.WarehouseId)
|
db = db.Where("product_warehouses.warehouse_id = ?", filters.WarehouseId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if filters.AreaId > 0 || filters.LocationId > 0 {
|
||||||
|
db = db.Joins("LEFT JOIN project_flock_kandangs ON project_flock_kandangs.id = product_warehouses.project_flock_kandang_id").
|
||||||
|
Joins("LEFT JOIN project_flocks ON project_flocks.id = project_flock_kandangs.project_flock_id")
|
||||||
|
|
||||||
|
if filters.AreaId > 0 {
|
||||||
|
db = db.Where("project_flocks.area_id = ?", filters.AreaId)
|
||||||
|
}
|
||||||
|
|
||||||
|
if filters.LocationId > 0 {
|
||||||
|
db = db.Where("project_flocks.location_id = ?", filters.LocationId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if filters.MarketingType != "" {
|
if filters.MarketingType != "" {
|
||||||
db = db.Joins("LEFT JOIN flags ON flags.flagable_id = products.id AND flags.flagable_type = 'products'").
|
db = db.Joins("LEFT JOIN flags ON flags.flagable_id = products.id AND flags.flagable_type = 'products'").
|
||||||
Group("marketing_delivery_products.id")
|
Group("marketing_delivery_products.id")
|
||||||
@@ -198,7 +211,6 @@ func (r *MarketingDeliveryProductRepositoryImpl) GetAllWithFilters(ctx context.C
|
|||||||
case "ayam":
|
case "ayam":
|
||||||
db = db.Where("flags.name IN (?)", []string{
|
db = db.Where("flags.name IN (?)", []string{
|
||||||
string(utils.FlagDOC), string(utils.FlagPullet), string(utils.FlagLayer),
|
string(utils.FlagDOC), string(utils.FlagPullet), string(utils.FlagLayer),
|
||||||
string(utils.FlagAyamAfkir), string(utils.FlagAyamCulling), string(utils.FlagAyamMati),
|
|
||||||
})
|
})
|
||||||
case "telur":
|
case "telur":
|
||||||
db = db.Where("flags.name IN (?)", []string{
|
db = db.Where("flags.name IN (?)", []string{
|
||||||
|
|||||||
@@ -82,6 +82,8 @@ func (c *RepportController) GetMarketing(ctx *fiber.Ctx) error {
|
|||||||
ProductId: int64(ctx.QueryInt("product_id", 0)),
|
ProductId: int64(ctx.QueryInt("product_id", 0)),
|
||||||
WarehouseId: int64(ctx.QueryInt("warehouse_id", 0)),
|
WarehouseId: int64(ctx.QueryInt("warehouse_id", 0)),
|
||||||
SalesPersonId: int64(ctx.QueryInt("sales_person_id", 0)),
|
SalesPersonId: int64(ctx.QueryInt("sales_person_id", 0)),
|
||||||
|
AreaId: int64(ctx.QueryInt("area_id", 0)),
|
||||||
|
LocationId: int64(ctx.QueryInt("location_id", 0)),
|
||||||
MarketingType: ctx.Query("marketing_type", ""),
|
MarketingType: ctx.Query("marketing_type", ""),
|
||||||
FilterBy: ctx.Query("filter_by", ""),
|
FilterBy: ctx.Query("filter_by", ""),
|
||||||
StartDate: ctx.Query("start_date", ""),
|
StartDate: ctx.Query("start_date", ""),
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ type MarketingQuery struct {
|
|||||||
ProductId int64 `query:"product_id" validate:"omitempty"`
|
ProductId int64 `query:"product_id" validate:"omitempty"`
|
||||||
WarehouseId int64 `query:"warehouse_id" validate:"omitempty"`
|
WarehouseId int64 `query:"warehouse_id" validate:"omitempty"`
|
||||||
SalesPersonId int64 `query:"sales_person_id" validate:"omitempty"`
|
SalesPersonId int64 `query:"sales_person_id" validate:"omitempty"`
|
||||||
|
AreaId int64 `query:"area_id" validate:"omitempty"`
|
||||||
|
LocationId int64 `query:"location_id" validate:"omitempty"`
|
||||||
MarketingType string `query:"marketing_type" validate:"omitempty,oneof=ayam telur trading"`
|
MarketingType string `query:"marketing_type" validate:"omitempty,oneof=ayam telur trading"`
|
||||||
FilterBy string `query:"filter_by" validate:"omitempty,oneof=so_date realization_date"`
|
FilterBy string `query:"filter_by" validate:"omitempty,oneof=so_date realization_date"`
|
||||||
StartDate string `query:"start_date" validate:"omitempty,datetime=2006-01-02"`
|
StartDate string `query:"start_date" validate:"omitempty,datetime=2006-01-02"`
|
||||||
@@ -56,7 +58,7 @@ type DebtSupplierQuery struct {
|
|||||||
|
|
||||||
type HppPerKandangQuery struct {
|
type HppPerKandangQuery struct {
|
||||||
Page int `query:"page" validate:"omitempty,min=1,gt=0"`
|
Page int `query:"page" validate:"omitempty,min=1,gt=0"`
|
||||||
Limit int `query:"limit" validate:"omitempty,min=1,max=100,gt=0"`
|
Limit int `query:"limit" validate:"omitempty,min=1,max=1000,gt=0"`
|
||||||
Period string `query:"period" validate:"required"`
|
Period string `query:"period" validate:"required"`
|
||||||
ShowUnrecorded bool `query:"show_unrecorded"`
|
ShowUnrecorded bool `query:"show_unrecorded"`
|
||||||
AreaIDs []int64 `query:"-"`
|
AreaIDs []int64 `query:"-"`
|
||||||
@@ -68,7 +70,7 @@ type HppPerKandangQuery struct {
|
|||||||
|
|
||||||
type ProductionResultQuery struct {
|
type ProductionResultQuery struct {
|
||||||
Page int `query:"page" validate:"omitempty,min=1,gt=0"`
|
Page int `query:"page" validate:"omitempty,min=1,gt=0"`
|
||||||
Limit int `query:"limit" validate:"omitempty,min=1,max=100,gt=0"`
|
Limit int `query:"limit" validate:"omitempty,min=1,max=1000,gt=0"`
|
||||||
ProjectFlockKandangID uint `query:"-" validate:"required,gt=0"`
|
ProjectFlockKandangID uint `query:"-" validate:"required,gt=0"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user