feat[BE]: add address field to CustomerRelationDTO and refactor payment report functions for improved clarity and structure

This commit is contained in:
aguhh18
2026-01-15 10:41:44 +07:00
parent 3a89e18b16
commit c316a6d7a9
3 changed files with 30 additions and 24 deletions
@@ -14,6 +14,7 @@ type CustomerRelationDTO struct {
Name string `json:"name"` Name string `json:"name"`
Type string `json:"type"` Type string `json:"type"`
AccountNumber string `json:"account_number"` AccountNumber string `json:"account_number"`
Address string `json:"address,omitempty"`
Balance float64 `json:"balance"` Balance float64 `json:"balance"`
Pic *userDTO.UserRelationDTO `json:"pic,omitempty"` Pic *userDTO.UserRelationDTO `json:"pic,omitempty"`
} }
@@ -52,6 +53,7 @@ func ToCustomerRelationDTO(e entity.Customer) CustomerRelationDTO {
Name: e.Name, Name: e.Name,
Type: e.Type, Type: e.Type,
AccountNumber: e.AccountNumber, AccountNumber: e.AccountNumber,
Address: e.Address,
Balance: e.Balance, Balance: e.Balance,
Pic: pic, Pic: pic,
} }
@@ -4,6 +4,7 @@ import (
"strings" "strings"
"time" "time"
"gitlab.com/mbugroup/lti-api.git/internal/entities"
customerDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/customers/dto" customerDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/customers/dto"
repportRepo "gitlab.com/mbugroup/lti-api.git/internal/modules/repports/repositories" repportRepo "gitlab.com/mbugroup/lti-api.git/internal/modules/repports/repositories"
) )
@@ -70,25 +71,16 @@ func ToCustomerPaymentReportRow(tx repportRepo.CustomerPaymentTransaction) Custo
} }
} }
func parseStringSlice(str string) []string { func ToCustomerPaymentReportItem(customer entities.Customer, initialBalance float64, rows []CustomerPaymentReportRow, summary CustomerPaymentReportSummary) CustomerPaymentReportItem {
str = strings.TrimSpace(str) return CustomerPaymentReportItem{
if str == "" || str == "-" { Customer: customerDTO.ToCustomerRelationDTO(customer),
return []string{} InitialBalance: initialBalance,
Rows: rows,
Summary: summary,
} }
parts := strings.Split(str, ",")
result := make([]string, 0, len(parts))
for _, part := range parts {
part = strings.TrimSpace(part)
if part != "" {
result = append(result, part)
}
}
return result
} }
func CalculateCustomerPaymentSummary(rows []CustomerPaymentReportRow, initialBalance float64) CustomerPaymentReportSummary { func ToCustomerPaymentReportSummary(rows []CustomerPaymentReportRow, initialBalance float64) CustomerPaymentReportSummary {
summary := CustomerPaymentReportSummary{} summary := CustomerPaymentReportSummary{}
for _, row := range rows { for _, row := range rows {
@@ -108,3 +100,21 @@ func CalculateCustomerPaymentSummary(rows []CustomerPaymentReportRow, initialBal
return summary return summary
} }
func parseStringSlice(str string) []string {
str = strings.TrimSpace(str)
if str == "" || str == "-" {
return []string{}
}
parts := strings.Split(str, ",")
result := make([]string, 0, len(parts))
for _, part := range parts {
part = strings.TrimSpace(part)
if part != "" {
result = append(result, part)
}
}
return result
}
@@ -19,7 +19,6 @@ import (
expenseRepo "gitlab.com/mbugroup/lti-api.git/internal/modules/expenses/repositories" expenseRepo "gitlab.com/mbugroup/lti-api.git/internal/modules/expenses/repositories"
marketingRepo "gitlab.com/mbugroup/lti-api.git/internal/modules/marketing/repositories" marketingRepo "gitlab.com/mbugroup/lti-api.git/internal/modules/marketing/repositories"
areaDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/areas/dto" areaDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/areas/dto"
customerDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/customers/dto"
customerRepo "gitlab.com/mbugroup/lti-api.git/internal/modules/master/customers/repositories" customerRepo "gitlab.com/mbugroup/lti-api.git/internal/modules/master/customers/repositories"
supplierDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/suppliers/dto" supplierDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/suppliers/dto"
warehouseDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/warehouses/dto" warehouseDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/warehouses/dto"
@@ -473,14 +472,9 @@ func (s *repportService) processCustomerPayment(ctx context.Context, customerID
rows = filteredRows rows = filteredRows
} }
summary := dto.CalculateCustomerPaymentSummary(rows, initialBalance) summary := dto.ToCustomerPaymentReportSummary(rows, initialBalance)
return dto.CustomerPaymentReportItem{ return dto.ToCustomerPaymentReportItem(*customer, initialBalance, rows, summary), nil
Customer: customerDTO.ToCustomerRelationDTO(*customer),
InitialBalance: initialBalance,
Rows: rows,
Summary: summary,
}, nil
} }
func (s *repportService) determineSalesStatusAndPaymentDate(transactions []repportRepo.CustomerPaymentTransaction, currentIndex int, previousBalance, currentBalance float64) (string, *time.Time) { func (s *repportService) determineSalesStatusAndPaymentDate(transactions []repportRepo.CustomerPaymentTransaction, currentIndex int, previousBalance, currentBalance float64) (string, *time.Time) {