mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-26 00:05:44 +00:00
add sorting transaction, report keuangan
This commit is contained in:
@@ -52,6 +52,19 @@ func (r *debtSupplierRepositoryImpl) latestPurchaseApproval(ctx context.Context)
|
||||
)
|
||||
}
|
||||
|
||||
func resolveDebtSupplierSortClause(filters *validation.DebtSupplierQuery) string {
|
||||
direction := "ASC"
|
||||
if strings.EqualFold(strings.TrimSpace(filters.SortOrder), "desc") {
|
||||
direction = "DESC"
|
||||
}
|
||||
switch strings.ToLower(strings.TrimSpace(filters.SortBy)) {
|
||||
case "supplier":
|
||||
return "suppliers.name " + direction
|
||||
default:
|
||||
return "suppliers.name ASC"
|
||||
}
|
||||
}
|
||||
|
||||
func resolveDebtSupplierDateColumn(filterBy string) string {
|
||||
switch strings.ToLower(strings.TrimSpace(filterBy)) {
|
||||
case "po_date":
|
||||
@@ -129,15 +142,24 @@ func (r *debtSupplierRepositoryImpl) GetSuppliersWithPurchases(ctx context.Conte
|
||||
offset = 0
|
||||
}
|
||||
|
||||
var supplierIDs []uint
|
||||
if err := query.
|
||||
Select("suppliers.id").
|
||||
Order("suppliers.id ASC").
|
||||
type supplierIDResult struct {
|
||||
ID uint `gorm:"column:id"`
|
||||
Name string `gorm:"column:name"`
|
||||
}
|
||||
var idResults []supplierIDResult
|
||||
if err := r.baseSupplierQuery(ctx, filters).
|
||||
Select("suppliers.id, suppliers.name").
|
||||
Group("suppliers.id, suppliers.name").
|
||||
Order(resolveDebtSupplierSortClause(filters)).
|
||||
Offset(offset).
|
||||
Limit(limit).
|
||||
Pluck("suppliers.id", &supplierIDs).Error; err != nil {
|
||||
Scan(&idResults).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
supplierIDs := make([]uint, 0, len(idResults))
|
||||
for _, r := range idResults {
|
||||
supplierIDs = append(supplierIDs, r.ID)
|
||||
}
|
||||
|
||||
if len(supplierIDs) == 0 {
|
||||
return []entity.Supplier{}, totalSuppliers, nil
|
||||
@@ -146,6 +168,7 @@ func (r *debtSupplierRepositoryImpl) GetSuppliersWithPurchases(ctx context.Conte
|
||||
var suppliers []entity.Supplier
|
||||
if err := r.db.WithContext(ctx).
|
||||
Where("id IN ?", supplierIDs).
|
||||
Order(resolveDebtSupplierSortClause(filters)).
|
||||
Find(&suppliers).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user