fix api get all closing; fix get closing sapronak; fix get all maste data product

This commit is contained in:
MacBook Air M1
2025-12-30 14:42:53 +07:00
parent ddda696454
commit 0285852c42
4 changed files with 131 additions and 49 deletions
+26 -24
View File
@@ -28,18 +28,19 @@ type ClosingDetailDTO struct {
} }
type ClosingListItemDTO struct { type ClosingListItemDTO struct {
Id uint `json:"id"` Id uint `json:"id"`
LocationID uint `json:"location_id"` ProjectName string `json:"project_name"`
LocationName string `json:"location_name"` LocationID uint `json:"location_id"`
ProjectCategory string `json:"project_category"` LocationName string `json:"location_name"`
Period int `json:"period"` ProjectCategory string `json:"project_category"`
ClosingDate string `json:"closing_date"` Period int `json:"period"`
ShedLabel string `json:"shed_label"` ClosingDate string `json:"closing_date"`
ShedCount int `json:"shed_count"` ShedLabel string `json:"shed_label"`
SalesPaidAmount int64 `json:"sales_paid_amount"` ShedCount int `json:"shed_count"`
SalesRemainingAmount int64 `json:"sales_remaining_amount"` // SalesPaidAmount int64 `json:"sales_paid_amount"`
SalesPaymentStatus string `json:"sales_payment_status"` // SalesRemainingAmount int64 `json:"sales_remaining_amount"`
ProjectStatus string `json:"project_status"` // SalesPaymentStatus string `json:"sales_payment_status"`
ProjectStatus string `json:"project_status"`
} }
type ClosingSummaryDTO struct { type ClosingSummaryDTO struct {
@@ -133,18 +134,19 @@ func ToClosingListItemDTO(project entity.ProjectFlock, projectStatus string) Clo
shedCount := len(project.KandangHistory) shedCount := len(project.KandangHistory)
return ClosingListItemDTO{ return ClosingListItemDTO{
Id: project.Id, Id: project.Id,
LocationID: project.LocationId, ProjectName: project.FlockName,
LocationName: project.Location.Name, LocationID: project.LocationId,
ProjectCategory: project.Category, LocationName: project.Location.Name,
Period: maxPeriod(project.KandangHistory), ProjectCategory: project.Category,
ClosingDate: "17-Nov-2025", Period: maxPeriod(project.KandangHistory),
ShedLabel: fmt.Sprintf("%d Kandang", shedCount), ClosingDate: "17-Nov-2025",
ShedCount: shedCount, ShedLabel: fmt.Sprintf("%d Kandang", shedCount),
SalesPaidAmount: 21993726, ShedCount: shedCount,
SalesRemainingAmount: 11075919, // SalesPaidAmount: 21993726,
SalesPaymentStatus: "Lunas", // SalesRemainingAmount: 11075919,
ProjectStatus: projectStatus, // SalesPaymentStatus: "Lunas",
ProjectStatus: projectStatus,
} }
} }
@@ -330,13 +330,33 @@ SELECT
COALESCE(p.po_number, '') AS reference_number, COALESCE(p.po_number, '') AS reference_number,
'Purchase' AS transaction_type, 'Purchase' AS transaction_type,
prod.name AS product_name, prod.name AS product_name,
pc.name AS product_category,
COALESCE(( COALESCE((
SELECT string_agg(f.name, ' ') SELECT string_agg(
f.name,
' ' ORDER BY
CASE
WHEN UPPER(f.name) IN ('DOC', 'PAKAN', 'OVK', 'PULLET') THEN 0
ELSE 1
END,
f.name
)
FROM flags f
WHERE f.flagable_type = 'products' AND f.flagable_id = prod.id
), '') AS product_category,
COALESCE((
SELECT string_agg(
f.name,
' ' ORDER BY
CASE
WHEN UPPER(f.name) IN ('DOC', 'PAKAN', 'OVK', 'PULLET') THEN 0
ELSE 1
END,
f.name
)
FROM flags f FROM flags f
WHERE f.flagable_type = 'products' AND f.flagable_id = prod.id WHERE f.flagable_type = 'products' AND f.flagable_id = prod.id
), '') AS product_sub_category, ), '') AS product_sub_category,
'External Supplier' AS source_warehouse, '-' AS source_warehouse,
w.name AS destination_warehouse, w.name AS destination_warehouse,
'' AS destination, '' AS destination,
pi.total_qty AS quantity, pi.total_qty AS quantity,
@@ -345,7 +365,6 @@ SELECT
FROM purchase_items pi FROM purchase_items pi
JOIN purchases p ON p.id = pi.purchase_id JOIN purchases p ON p.id = pi.purchase_id
JOIN products prod ON prod.id = pi.product_id JOIN products prod ON prod.id = pi.product_id
JOIN product_categories pc ON pc.id = prod.product_category_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 = pi.warehouse_id JOIN warehouses w ON w.id = pi.warehouse_id
WHERE pi.warehouse_id IN ? WHERE pi.warehouse_id IN ?
@@ -359,9 +378,29 @@ SELECT
st.movement_number AS reference_number, st.movement_number AS reference_number,
'Internal Transfer In' AS transaction_type, 'Internal Transfer In' AS transaction_type,
prod.name AS product_name, prod.name AS product_name,
pc.name AS product_category,
COALESCE(( COALESCE((
SELECT string_agg(f.name, ' ') SELECT string_agg(
f.name,
' ' ORDER BY
CASE
WHEN UPPER(f.name) IN ('DOC', 'PAKAN', 'OVK', 'PULLET') THEN 0
ELSE 1
END,
f.name
)
FROM flags f
WHERE f.flagable_type = 'products' AND f.flagable_id = prod.id
), '') AS product_category,
COALESCE((
SELECT string_agg(
f.name,
' ' ORDER BY
CASE
WHEN UPPER(f.name) IN ('DOC', 'PAKAN', 'OVK', 'PULLET') THEN 0
ELSE 1
END,
f.name
)
FROM flags f FROM flags f
WHERE f.flagable_type = 'products' AND f.flagable_id = prod.id WHERE f.flagable_type = 'products' AND f.flagable_id = prod.id
), '') AS product_sub_category, ), '') AS product_sub_category,
@@ -376,7 +415,6 @@ JOIN stock_transfers st ON st.id = std.stock_transfer_id
LEFT JOIN warehouses fw ON fw.id = st.from_warehouse_id LEFT JOIN warehouses fw ON fw.id = st.from_warehouse_id
LEFT JOIN warehouses tw ON tw.id = st.to_warehouse_id LEFT JOIN warehouses tw ON tw.id = st.to_warehouse_id
JOIN products prod ON prod.id = std.product_id JOIN products prod ON prod.id = std.product_id
JOIN product_categories pc ON pc.id = prod.product_category_id
JOIN uoms u ON u.id = prod.uom_id JOIN uoms u ON u.id = prod.uom_id
WHERE st.to_warehouse_id IN ? WHERE st.to_warehouse_id IN ?
` `
@@ -389,9 +427,29 @@ SELECT
st.movement_number AS reference_number, st.movement_number AS reference_number,
'Internal Transfer Out' AS transaction_type, 'Internal Transfer Out' AS transaction_type,
prod.name AS product_name, prod.name AS product_name,
pc.name AS product_category,
COALESCE(( COALESCE((
SELECT string_agg(f.name, ' ') SELECT string_agg(
f.name,
' ' ORDER BY
CASE
WHEN UPPER(f.name) IN ('DOC', 'PAKAN', 'OVK', 'PULLET') THEN 0
ELSE 1
END,
f.name
)
FROM flags f
WHERE f.flagable_type = 'products' AND f.flagable_id = prod.id
), '') AS product_category,
COALESCE((
SELECT string_agg(
f.name,
' ' ORDER BY
CASE
WHEN UPPER(f.name) IN ('DOC', 'PAKAN', 'OVK', 'PULLET') THEN 0
ELSE 1
END,
f.name
)
FROM flags f FROM flags f
WHERE f.flagable_type = 'products' AND f.flagable_id = prod.id WHERE f.flagable_type = 'products' AND f.flagable_id = prod.id
), '') AS product_sub_category, ), '') AS product_sub_category,
@@ -406,7 +464,6 @@ JOIN stock_transfers st ON st.id = std.stock_transfer_id
LEFT JOIN warehouses fw ON fw.id = st.from_warehouse_id LEFT JOIN warehouses fw ON fw.id = st.from_warehouse_id
LEFT JOIN warehouses tw ON tw.id = st.to_warehouse_id LEFT JOIN warehouses tw ON tw.id = st.to_warehouse_id
JOIN products prod ON prod.id = std.product_id JOIN products prod ON prod.id = std.product_id
JOIN product_categories pc ON pc.id = prod.product_category_id
JOIN uoms u ON u.id = prod.uom_id JOIN uoms u ON u.id = prod.uom_id
WHERE st.from_warehouse_id IN ? WHERE st.from_warehouse_id IN ?
` `
@@ -419,9 +476,29 @@ SELECT
m.so_number AS reference_number, m.so_number AS reference_number,
'Trading Sales' AS transaction_type, 'Trading Sales' AS transaction_type,
prod.name AS product_name, prod.name AS product_name,
pc.name AS product_category,
COALESCE(( COALESCE((
SELECT string_agg(f.name, ' ') SELECT string_agg(
f.name,
' ' ORDER BY
CASE
WHEN UPPER(f.name) IN ('DOC', 'PAKAN', 'OVK', 'PULLET') THEN 0
ELSE 1
END,
f.name
)
FROM flags f
WHERE f.flagable_type = 'products' AND f.flagable_id = prod.id
), '') AS product_category,
COALESCE((
SELECT string_agg(
f.name,
' ' ORDER BY
CASE
WHEN UPPER(f.name) IN ('DOC', 'PAKAN', 'OVK', 'PULLET') THEN 0
ELSE 1
END,
f.name
)
FROM flags f FROM flags f
WHERE f.flagable_type = 'products' AND f.flagable_id = prod.id WHERE f.flagable_type = 'products' AND f.flagable_id = prod.id
), '') AS product_sub_category, ), '') AS product_sub_category,
@@ -435,7 +512,6 @@ FROM marketing_products mp
JOIN marketings m ON m.id = mp.marketing_id JOIN marketings m ON m.id = mp.marketing_id
JOIN product_warehouses pw ON pw.id = mp.product_warehouse_id JOIN product_warehouses pw ON pw.id = mp.product_warehouse_id
JOIN products prod ON prod.id = pw.product_id JOIN products prod ON prod.id = pw.product_id
JOIN product_categories pc ON pc.id = prod.product_category_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 ?
@@ -808,12 +884,12 @@ func (r *ClosingRepositoryImpl) FetchSapronakTransfers(ctx context.Context, kand
} }
type ActualUsageCostRow struct { type ActualUsageCostRow struct {
ProductID uint `gorm:"column:product_id"` ProductID uint `gorm:"column:product_id"`
ProductName string `gorm:"column:product_name"` ProductName string `gorm:"column:product_name"`
FlagName string `gorm:"column:flag_name"` FlagName string `gorm:"column:flag_name"`
TotalQty float64 `gorm:"column:total_qty"` TotalQty float64 `gorm:"column:total_qty"`
TotalPrice float64 `gorm:"column:total_price"` TotalPrice float64 `gorm:"column:total_price"`
AveragePrice float64 `gorm:"column:average_price"` AveragePrice float64 `gorm:"column:average_price"`
} }
func (r *ClosingRepositoryImpl) GetActualUsageCostByProjectFlockID(ctx context.Context, projectFlockID uint) ([]ActualUsageCostRow, error) { func (r *ClosingRepositoryImpl) GetActualUsageCostByProjectFlockID(ctx context.Context, projectFlockID uint) ([]ActualUsageCostRow, error) {
@@ -6,6 +6,7 @@ import (
"math" "math"
"strconv" "strconv"
"strings" "strings"
"time"
commonSvc "gitlab.com/mbugroup/lti-api.git/internal/common/service" commonSvc "gitlab.com/mbugroup/lti-api.git/internal/common/service"
entity "gitlab.com/mbugroup/lti-api.git/internal/entities" entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
@@ -332,18 +333,20 @@ func (s closingService) getApprovalStatuses(ctx context.Context, projectFlockID
} }
var ( var (
minStep uint16 minStep uint16
statusProject string statusProject string
completed int completed int
latestActionAt time.Time
) )
for _, rec := range records { for _, rec := range records {
if minStep == 0 || rec.StepNumber < minStep { if minStep == 0 || rec.StepNumber < minStep {
minStep = rec.StepNumber minStep = rec.StepNumber
statusProject = rec.StepName
} }
if rec.StepNumber == uint16(utils.ProjectFlockStepAktif) {
completed++ if latestActionAt.IsZero() || rec.ActionAt.After(latestActionAt) {
latestActionAt = rec.ActionAt
statusProject = rec.StepName
} }
} }
@@ -70,6 +70,7 @@ func (s productService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entity
products, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB { products, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB {
db = s.withRelations(db) db = s.withRelations(db)
db = db.Where("is_visible = ?", true)
if params.Search != "" { if params.Search != "" {
return db.Where("name LIKE ?", "%"+params.Search+"%") return db.Where("name LIKE ?", "%"+params.Search+"%")
} }