mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
Feat(BE-339): make reporting purchase per supplier with filterization
This commit is contained in:
@@ -106,8 +106,8 @@ func (c *RepportController) GetPurchaseSupplier(ctx *fiber.Ctx) error {
|
|||||||
SupplierId: int64(ctx.QueryInt("supplier_id", 0)),
|
SupplierId: int64(ctx.QueryInt("supplier_id", 0)),
|
||||||
ProductId: int64(ctx.QueryInt("product_id", 0)),
|
ProductId: int64(ctx.QueryInt("product_id", 0)),
|
||||||
ProductCategoryId: int64(ctx.QueryInt("product_category_id", 0)),
|
ProductCategoryId: int64(ctx.QueryInt("product_category_id", 0)),
|
||||||
DateFrom: ctx.Query("date_from", ""),
|
StartDate: ctx.Query("start_date", ""),
|
||||||
DateTo: ctx.Query("date_to", ""),
|
EndDate: ctx.Query("end_date", ""),
|
||||||
SortBy: ctx.Query("sort_by", ""),
|
SortBy: ctx.Query("sort_by", ""),
|
||||||
FilterBy: ctx.Query("filter_by", ""),
|
FilterBy: ctx.Query("filter_by", ""),
|
||||||
}
|
}
|
||||||
@@ -126,8 +126,8 @@ func (c *RepportController) GetPurchaseSupplier(ctx *fiber.Ctx) error {
|
|||||||
"supplier_id": query.SupplierId,
|
"supplier_id": query.SupplierId,
|
||||||
"product_id": query.ProductId,
|
"product_id": query.ProductId,
|
||||||
"product_category_id": query.ProductCategoryId,
|
"product_category_id": query.ProductCategoryId,
|
||||||
"date_from": query.DateFrom,
|
"start_date": query.StartDate,
|
||||||
"date_to": query.DateTo,
|
"end_date": query.EndDate,
|
||||||
"sort_by": query.SortBy,
|
"sort_by": query.SortBy,
|
||||||
"filter_by": query.FilterBy,
|
"filter_by": query.FilterBy,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ func NewPurchaseSupplierRepository(db *gorm.DB) PurchaseSupplierRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *purchaseSupplierRepositoryImpl) baseSupplierQuery(ctx context.Context, filters *validation.PurchaseSupplierQuery) *gorm.DB {
|
func (r *purchaseSupplierRepositoryImpl) baseSupplierQuery(ctx context.Context, filters *validation.PurchaseSupplierQuery) *gorm.DB {
|
||||||
// Tentukan kolom tanggal yang akan dipakai untuk filter
|
|
||||||
dateColumn := "purchase_items.received_date"
|
dateColumn := "purchase_items.received_date"
|
||||||
switch strings.ToLower(strings.TrimSpace(filters.FilterBy)) {
|
switch strings.ToLower(strings.TrimSpace(filters.FilterBy)) {
|
||||||
case "po_date":
|
case "po_date":
|
||||||
@@ -60,14 +59,14 @@ func (r *purchaseSupplierRepositoryImpl) baseSupplierQuery(ctx context.Context,
|
|||||||
Where("warehouses.area_id = ?", filters.AreaId)
|
Where("warehouses.area_id = ?", filters.AreaId)
|
||||||
}
|
}
|
||||||
|
|
||||||
if filters.DateFrom != "" {
|
if filters.StartDate != "" {
|
||||||
if dateFrom, err := utils.ParseDateString(filters.DateFrom); err == nil {
|
if dateFrom, err := utils.ParseDateString(filters.StartDate); err == nil {
|
||||||
db = db.Where(fmt.Sprintf("DATE(%s) >= ?", dateColumn), dateFrom)
|
db = db.Where(fmt.Sprintf("DATE(%s) >= ?", dateColumn), dateFrom)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if filters.DateTo != "" {
|
if filters.EndDate != "" {
|
||||||
if dateTo, err := utils.ParseDateString(filters.DateTo); err == nil {
|
if dateTo, err := utils.ParseDateString(filters.EndDate); err == nil {
|
||||||
db = db.Where(fmt.Sprintf("DATE(%s) <= ?", dateColumn), dateTo)
|
db = db.Where(fmt.Sprintf("DATE(%s) <= ?", dateColumn), dateTo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -171,14 +170,14 @@ func (r *purchaseSupplierRepositoryImpl) GetItemsBySuppliers(ctx context.Context
|
|||||||
Where("warehouses.area_id = ?", filters.AreaId)
|
Where("warehouses.area_id = ?", filters.AreaId)
|
||||||
}
|
}
|
||||||
|
|
||||||
if filters.DateFrom != "" {
|
if filters.StartDate != "" {
|
||||||
if dateFrom, err := utils.ParseDateString(filters.DateFrom); err == nil {
|
if dateFrom, err := utils.ParseDateString(filters.StartDate); err == nil {
|
||||||
db = db.Where(fmt.Sprintf("DATE(%s) >= ?", dateColumn), dateFrom)
|
db = db.Where(fmt.Sprintf("DATE(%s) >= ?", dateColumn), dateFrom)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if filters.DateTo != "" {
|
if filters.EndDate != "" {
|
||||||
if dateTo, err := utils.ParseDateString(filters.DateTo); err == nil {
|
if dateTo, err := utils.ParseDateString(filters.EndDate); err == nil {
|
||||||
db = db.Where(fmt.Sprintf("DATE(%s) <= ?", dateColumn), dateTo)
|
db = db.Where(fmt.Sprintf("DATE(%s) <= ?", dateColumn), dateTo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ type PurchaseSupplierQuery struct {
|
|||||||
SupplierId int64 `query:"supplier_id" validate:"omitempty"`
|
SupplierId int64 `query:"supplier_id" validate:"omitempty"`
|
||||||
ProductId int64 `query:"product_id" validate:"omitempty"`
|
ProductId int64 `query:"product_id" validate:"omitempty"`
|
||||||
ProductCategoryId int64 `query:"product_category_id" validate:"omitempty"`
|
ProductCategoryId int64 `query:"product_category_id" validate:"omitempty"`
|
||||||
DateFrom string `query:"date_from" validate:"omitempty"`
|
StartDate string `query:"start_date" validate:"omitempty"`
|
||||||
DateTo string `query:"date_to" validate:"omitempty"`
|
EndDate string `query:"end_date" validate:"omitempty"`
|
||||||
SortBy string `query:"sort_by" validate:"omitempty"`
|
SortBy string `query:"sort_by" validate:"omitempty"`
|
||||||
FilterBy string `query:"filter_by" validate:"omitempty"`
|
FilterBy string `query:"filter_by" validate:"omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user