mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-25 15:55:44 +00:00
feat[BE}: change get penjualan repport dto an add more params
This commit is contained in:
@@ -0,0 +1,186 @@
|
||||
package dto
|
||||
|
||||
// === BASE METRICS ===
|
||||
type FinancialMetrics struct {
|
||||
RpPerBird float64 `json:"rp_per_bird"`
|
||||
RpPerKg float64 `json:"rp_per_kg"`
|
||||
Amount float64 `json:"amount"`
|
||||
}
|
||||
|
||||
type Comparison struct {
|
||||
Budgeting FinancialMetrics `json:"budgeting"`
|
||||
Realization FinancialMetrics `json:"realization"`
|
||||
}
|
||||
|
||||
// === HPP PURCHASES PACKAGE ===
|
||||
type HppItem struct {
|
||||
Type string `json:"type"`
|
||||
Comparison
|
||||
}
|
||||
|
||||
type HppGroup struct {
|
||||
GroupName string `json:"group_name"`
|
||||
Data []HppItem `json:"data"`
|
||||
}
|
||||
|
||||
type SummaryHpp struct {
|
||||
Label string `json:"label"`
|
||||
Comparison
|
||||
}
|
||||
|
||||
// Ini adalah struct mandiri untuk bagian HPP Purchases
|
||||
type HppPurchasesSection struct {
|
||||
Title string `json:"title"`
|
||||
Hpp []HppGroup `json:"hpp"`
|
||||
SummaryHpp SummaryHpp `json:"summary_hpp"`
|
||||
}
|
||||
|
||||
// === PROFIT LOSS PACKAGE ===
|
||||
type PLItem struct {
|
||||
Type string `json:"type"`
|
||||
FinancialMetrics
|
||||
}
|
||||
|
||||
type PLSummaryItem struct {
|
||||
Label string `json:"label"`
|
||||
FinancialMetrics
|
||||
}
|
||||
|
||||
type PLSummaryGroup struct {
|
||||
GrossProfit PLSummaryItem `json:"gross_profit"`
|
||||
SubTotal PLSummaryItem `json:"sub_total"`
|
||||
NetProfit PLSummaryItem `json:"net_profit"`
|
||||
}
|
||||
|
||||
type ProfitLossData struct {
|
||||
Penjualan []PLItem `json:"penjualan"`
|
||||
Pembelian []PLItem `json:"pembelian"`
|
||||
Summary PLSummaryGroup `json:"summary"`
|
||||
}
|
||||
|
||||
// Ini adalah struct mandiri untuk bagian Profit Loss
|
||||
type ProfitLossSection struct {
|
||||
Title string `json:"title"`
|
||||
Data ProfitLossData `json:"data"`
|
||||
}
|
||||
|
||||
// === RESPONSE DTO (ROOT) ===
|
||||
// Sekarang Root-nya terlihat sangat bersih dan tidak "janggal" lagi
|
||||
type ReportResponse struct {
|
||||
HppPurchases HppPurchasesSection `json:"hpp_purchases"`
|
||||
ProfitLoss ProfitLossSection `json:"profit_loss"`
|
||||
}
|
||||
|
||||
// === MAPPER FUNCTIONS ===
|
||||
|
||||
// FinancialMetrics Mappers
|
||||
func ToFinancialMetrics(rpPerBird, rpPerKg, amount float64) FinancialMetrics {
|
||||
return FinancialMetrics{
|
||||
RpPerBird: rpPerBird,
|
||||
RpPerKg: rpPerKg,
|
||||
Amount: amount,
|
||||
}
|
||||
}
|
||||
|
||||
// Comparison Mappers
|
||||
func ToComparison(budgeting, realization FinancialMetrics) Comparison {
|
||||
return Comparison{
|
||||
Budgeting: budgeting,
|
||||
Realization: realization,
|
||||
}
|
||||
}
|
||||
|
||||
// HppItem Mappers
|
||||
func ToHppItem(itemType string, comparison Comparison) HppItem {
|
||||
return HppItem{
|
||||
Type: itemType,
|
||||
Comparison: comparison,
|
||||
}
|
||||
}
|
||||
|
||||
// HppGroup Mappers
|
||||
func ToHppGroup(groupName string, items []HppItem) HppGroup {
|
||||
return HppGroup{
|
||||
GroupName: groupName,
|
||||
Data: items,
|
||||
}
|
||||
}
|
||||
|
||||
// SummaryHpp Mappers
|
||||
func ToSummaryHpp(label string, comparison Comparison) SummaryHpp {
|
||||
return SummaryHpp{
|
||||
Label: label,
|
||||
Comparison: comparison,
|
||||
}
|
||||
}
|
||||
|
||||
// HppPurchasesSection Mappers
|
||||
func ToHppPurchasesSection(title string, hppGroups []HppGroup, summaryHpp SummaryHpp) HppPurchasesSection {
|
||||
return HppPurchasesSection{
|
||||
Title: title,
|
||||
Hpp: hppGroups,
|
||||
SummaryHpp: summaryHpp,
|
||||
}
|
||||
}
|
||||
|
||||
// PLItem Mappers
|
||||
func ToPLItem(itemType string, metrics FinancialMetrics) PLItem {
|
||||
return PLItem{
|
||||
Type: itemType,
|
||||
FinancialMetrics: metrics,
|
||||
}
|
||||
}
|
||||
|
||||
// PLSummaryItem Mappers
|
||||
func ToPLSummaryItem(label string, metrics FinancialMetrics) PLSummaryItem {
|
||||
return PLSummaryItem{
|
||||
Label: label,
|
||||
FinancialMetrics: metrics,
|
||||
}
|
||||
}
|
||||
|
||||
// PLSummaryGroup Mappers
|
||||
func ToPLSummaryGroup(grossProfit, subTotal, netProfit PLSummaryItem) PLSummaryGroup {
|
||||
return PLSummaryGroup{
|
||||
GrossProfit: grossProfit,
|
||||
SubTotal: subTotal,
|
||||
NetProfit: netProfit,
|
||||
}
|
||||
}
|
||||
|
||||
// ProfitLossData Mappers
|
||||
func ToProfitLossData(penjualan, pembelian []PLItem, summary PLSummaryGroup) ProfitLossData {
|
||||
return ProfitLossData{
|
||||
Penjualan: penjualan,
|
||||
Pembelian: pembelian,
|
||||
Summary: summary,
|
||||
}
|
||||
}
|
||||
|
||||
// ProfitLossSection Mappers
|
||||
func ToProfitLossSection(title string, data ProfitLossData) ProfitLossSection {
|
||||
return ProfitLossSection{
|
||||
Title: title,
|
||||
Data: data,
|
||||
}
|
||||
}
|
||||
|
||||
// ReportResponse Mappers
|
||||
func ToReportResponse(hppPurchases HppPurchasesSection, profitLoss ProfitLossSection) ReportResponse {
|
||||
return ReportResponse{
|
||||
HppPurchases: hppPurchases,
|
||||
ProfitLoss: profitLoss,
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to create a complete financial report
|
||||
func BuildFinancialReport(
|
||||
hppGroups []HppGroup,
|
||||
summaryHpp SummaryHpp,
|
||||
penjualan, pembelian []PLItem,
|
||||
plSummary PLSummaryGroup,
|
||||
) ReportResponse {
|
||||
hppSection := ToHppPurchasesSection("HPP Pembelian", hppGroups, summaryHpp)
|
||||
plSection := ToProfitLossSection("Laporan Laba Rugi", ToProfitLossData(penjualan, pembelian, plSummary))
|
||||
return ToReportResponse(hppSection, plSection)
|
||||
}
|
||||
Reference in New Issue
Block a user