mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-22 06:15:44 +00:00
feat[BE]: enhance customer payment report with vehicle numbers and pickup info, add date filtering
This commit is contained in:
@@ -1,32 +1,35 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
customerDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/customers/dto"
|
||||
repportRepo "gitlab.com/mbugroup/lti-api.git/internal/modules/repports/repositories"
|
||||
)
|
||||
|
||||
type CustomerPaymentReportRow struct {
|
||||
TransactionType string `json:"transaction_type"`
|
||||
TransactionID int64 `json:"transaction_id"`
|
||||
TransDate time.Time `json:"trans_date"`
|
||||
DeliveryDate *time.Time `json:"delivery_date"`
|
||||
Reference string `json:"reference"`
|
||||
VehicleNumbers string `json:"vehicle_numbers"`
|
||||
Qty float64 `json:"qty"`
|
||||
Weight float64 `json:"weight"`
|
||||
AverageWeight float64 `json:"average_weight"`
|
||||
Price float64 `json:"price"`
|
||||
CreditNote float64 `json:"credit_note"`
|
||||
FinalPrice float64 `json:"final_price"`
|
||||
PPN float64 `json:"ppn"`
|
||||
TotalPrice float64 `json:"total_price"`
|
||||
PaymentAmount float64 `json:"payment_amount"`
|
||||
AccountsReceivable float64 `json:"accounts_receivable"`
|
||||
AgingDay *int `json:"aging_day"`
|
||||
Status string `json:"status"`
|
||||
PickupInfo string `json:"pickup_info"`
|
||||
SalesPerson string `json:"sales_person"`
|
||||
TransactionType string `json:"transaction_type"`
|
||||
TransactionID int64 `json:"transaction_id"`
|
||||
TransDate time.Time `json:"trans_date"`
|
||||
DeliveryDate *time.Time `json:"delivery_date"`
|
||||
Reference string `json:"reference"`
|
||||
|
||||
Qty float64 `json:"qty"`
|
||||
Weight float64 `json:"weight"`
|
||||
AverageWeight float64 `json:"average_weight"`
|
||||
Price float64 `json:"price"`
|
||||
CreditNote float64 `json:"credit_note"`
|
||||
FinalPrice float64 `json:"final_price"`
|
||||
PPN float64 `json:"ppn"`
|
||||
TotalPrice float64 `json:"total_price"`
|
||||
PaymentAmount float64 `json:"payment_amount"`
|
||||
AccountsReceivable float64 `json:"accounts_receivable"`
|
||||
AgingDay *int `json:"aging_day"`
|
||||
Status string `json:"status"`
|
||||
VehicleNumbers []string `json:"vehicle_numbers"`
|
||||
PickupInfo []string `json:"pickup_info"`
|
||||
SalesPerson string `json:"sales_person"`
|
||||
}
|
||||
|
||||
type CustomerPaymentReportSummary struct {
|
||||
@@ -51,3 +54,70 @@ type CustomerPaymentReportItem struct {
|
||||
type CustomerPaymentReportResponse struct {
|
||||
Data []CustomerPaymentReportItem `json:"data"`
|
||||
}
|
||||
|
||||
func ToCustomerPaymentReportRow(tx repportRepo.CustomerPaymentTransaction) CustomerPaymentReportRow {
|
||||
return CustomerPaymentReportRow{
|
||||
TransactionType: tx.TransactionType,
|
||||
TransactionID: tx.TransactionID,
|
||||
TransDate: tx.TransDate,
|
||||
DeliveryDate: tx.DeliveryDate,
|
||||
Reference: tx.Reference,
|
||||
Qty: tx.Qty,
|
||||
Weight: tx.Weight,
|
||||
AverageWeight: tx.AverageWeight,
|
||||
Price: tx.Price,
|
||||
CreditNote: tx.CreditNote,
|
||||
FinalPrice: tx.FinalPrice,
|
||||
PPN: tx.PPN,
|
||||
TotalPrice: tx.TotalPrice,
|
||||
PaymentAmount: tx.PaymentAmount,
|
||||
VehicleNumbers: parseStringSlice(tx.VehicleNumbers),
|
||||
PickupInfo: parseStringSlice(tx.PickupInfo),
|
||||
SalesPerson: tx.SalesPerson,
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func CalculateCustomerPaymentSummary(rows []CustomerPaymentReportRow, initialBalance float64) CustomerPaymentReportSummary {
|
||||
summary := CustomerPaymentReportSummary{}
|
||||
|
||||
for _, row := range rows {
|
||||
summary.TotalQty += row.Qty
|
||||
summary.TotalWeight += row.Weight
|
||||
summary.TotalCreditNote += row.CreditNote
|
||||
summary.TotalPPN += row.PPN
|
||||
|
||||
if row.TransactionType == "SALES" {
|
||||
summary.TotalInitialAmount += row.TotalPrice
|
||||
summary.TotalFinalAmount += row.FinalPrice
|
||||
summary.TotalGrandAmount += row.TotalPrice
|
||||
} else if row.TransactionType == "PAYMENT" {
|
||||
summary.TotalPayment += row.PaymentAmount
|
||||
}
|
||||
}
|
||||
|
||||
// Formula: Total AR = Initial Balance - Total Sales + Total Payment
|
||||
// - Initial balance: positive (customer deposit)
|
||||
// - Sales: reduces balance (customer debt)
|
||||
// - Payment: increases balance (customer pays)
|
||||
summary.TotalAccountsReceivable = initialBalance - summary.TotalGrandAmount + summary.TotalPayment
|
||||
|
||||
return summary
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user