277 lines
9.5 KiB
Go
277 lines
9.5 KiB
Go
package mappers
|
|
|
|
import (
|
|
"apskel-pos-be/internal/contract"
|
|
"apskel-pos-be/internal/models"
|
|
"github.com/google/uuid"
|
|
"time"
|
|
)
|
|
|
|
// Chart of Account Type Mappers
|
|
func ContractToModelCreateChartOfAccountTypeRequest(req *contract.CreateChartOfAccountTypeRequest) *models.CreateChartOfAccountTypeRequest {
|
|
return &models.CreateChartOfAccountTypeRequest{
|
|
Name: req.Name,
|
|
Code: req.Code,
|
|
Description: req.Description,
|
|
}
|
|
}
|
|
|
|
func ContractToModelUpdateChartOfAccountTypeRequest(req *contract.UpdateChartOfAccountTypeRequest) *models.UpdateChartOfAccountTypeRequest {
|
|
return &models.UpdateChartOfAccountTypeRequest{
|
|
Name: req.Name,
|
|
Code: req.Code,
|
|
Description: req.Description,
|
|
IsActive: req.IsActive,
|
|
}
|
|
}
|
|
|
|
func ModelToContractChartOfAccountTypeResponse(resp *models.ChartOfAccountTypeResponse) *contract.ChartOfAccountTypeResponse {
|
|
return &contract.ChartOfAccountTypeResponse{
|
|
ID: resp.ID,
|
|
Name: resp.Name,
|
|
Code: resp.Code,
|
|
Description: resp.Description,
|
|
IsActive: resp.IsActive,
|
|
CreatedAt: resp.CreatedAt.Format(time.RFC3339),
|
|
UpdatedAt: resp.UpdatedAt.Format(time.RFC3339),
|
|
}
|
|
}
|
|
|
|
// Chart of Account Mappers
|
|
func ContractToModelCreateChartOfAccountRequest(req *contract.CreateChartOfAccountRequest) *models.CreateChartOfAccountRequest {
|
|
return &models.CreateChartOfAccountRequest{
|
|
ChartOfAccountTypeID: req.ChartOfAccountTypeID,
|
|
ParentID: req.ParentID,
|
|
Name: req.Name,
|
|
Code: req.Code,
|
|
Description: req.Description,
|
|
}
|
|
}
|
|
|
|
func ContractToModelUpdateChartOfAccountRequest(req *contract.UpdateChartOfAccountRequest) *models.UpdateChartOfAccountRequest {
|
|
return &models.UpdateChartOfAccountRequest{
|
|
ChartOfAccountTypeID: req.ChartOfAccountTypeID,
|
|
ParentID: req.ParentID,
|
|
Name: req.Name,
|
|
Code: req.Code,
|
|
Description: req.Description,
|
|
IsActive: req.IsActive,
|
|
}
|
|
}
|
|
|
|
func ContractToModelListChartOfAccountsRequest(req *contract.ListChartOfAccountsRequest, organizationID, outletID uuid.UUID) *models.ListChartOfAccountsRequest {
|
|
return &models.ListChartOfAccountsRequest{
|
|
OrganizationID: organizationID,
|
|
OutletID: outletID,
|
|
ChartOfAccountTypeID: req.ChartOfAccountTypeID,
|
|
ParentID: req.ParentID,
|
|
IsActive: req.IsActive,
|
|
IsSystem: req.IsSystem,
|
|
Page: req.Page,
|
|
Limit: req.Limit,
|
|
}
|
|
}
|
|
|
|
func ModelToContractChartOfAccountResponse(resp *models.ChartOfAccountResponse) *contract.ChartOfAccountResponse {
|
|
contractResp := &contract.ChartOfAccountResponse{
|
|
ID: resp.ID,
|
|
OrganizationID: resp.OrganizationID,
|
|
OutletID: resp.OutletID,
|
|
ChartOfAccountTypeID: resp.ChartOfAccountTypeID,
|
|
ParentID: resp.ParentID,
|
|
Name: resp.Name,
|
|
Code: resp.Code,
|
|
Description: resp.Description,
|
|
IsActive: resp.IsActive,
|
|
IsSystem: resp.IsSystem,
|
|
CreatedAt: resp.CreatedAt.Format(time.RFC3339),
|
|
UpdatedAt: resp.UpdatedAt.Format(time.RFC3339),
|
|
}
|
|
|
|
if resp.ChartOfAccountType != nil {
|
|
contractResp.ChartOfAccountType = ModelToContractChartOfAccountTypeResponse(resp.ChartOfAccountType)
|
|
}
|
|
|
|
if resp.Parent != nil {
|
|
contractResp.Parent = ModelToContractChartOfAccountResponse(resp.Parent)
|
|
}
|
|
|
|
if len(resp.Children) > 0 {
|
|
contractResp.Children = make([]contract.ChartOfAccountResponse, len(resp.Children))
|
|
for i, child := range resp.Children {
|
|
contractResp.Children[i] = *ModelToContractChartOfAccountResponse(&child)
|
|
}
|
|
}
|
|
|
|
return contractResp
|
|
}
|
|
|
|
// Account Mappers
|
|
func ContractToModelCreateAccountRequest(req *contract.CreateAccountRequest) *models.CreateAccountRequest {
|
|
return &models.CreateAccountRequest{
|
|
ChartOfAccountID: req.ChartOfAccountID,
|
|
Name: req.Name,
|
|
Number: req.Number,
|
|
AccountType: req.AccountType,
|
|
OpeningBalance: req.OpeningBalance,
|
|
Description: req.Description,
|
|
}
|
|
}
|
|
|
|
func ContractToModelUpdateAccountRequest(req *contract.UpdateAccountRequest) *models.UpdateAccountRequest {
|
|
return &models.UpdateAccountRequest{
|
|
ChartOfAccountID: req.ChartOfAccountID,
|
|
Name: req.Name,
|
|
Number: req.Number,
|
|
AccountType: req.AccountType,
|
|
OpeningBalance: req.OpeningBalance,
|
|
Description: req.Description,
|
|
IsActive: req.IsActive,
|
|
}
|
|
}
|
|
|
|
func ContractToModelListAccountsRequest(req *contract.ListAccountsRequest) *models.ListAccountsRequest {
|
|
return &models.ListAccountsRequest{
|
|
OrganizationID: req.OrganizationID,
|
|
OutletID: req.OutletID,
|
|
ChartOfAccountID: req.ChartOfAccountID,
|
|
AccountType: req.AccountType,
|
|
IsActive: req.IsActive,
|
|
IsSystem: req.IsSystem,
|
|
Page: req.Page,
|
|
Limit: req.Limit,
|
|
}
|
|
}
|
|
|
|
func ModelToContractAccountResponse(resp *models.AccountResponse) *contract.AccountResponse {
|
|
contractResp := &contract.AccountResponse{
|
|
ID: resp.ID,
|
|
OrganizationID: resp.OrganizationID,
|
|
OutletID: resp.OutletID,
|
|
ChartOfAccountID: resp.ChartOfAccountID,
|
|
Name: resp.Name,
|
|
Number: resp.Number,
|
|
AccountType: resp.AccountType,
|
|
OpeningBalance: resp.OpeningBalance,
|
|
CurrentBalance: resp.CurrentBalance,
|
|
Description: resp.Description,
|
|
IsActive: resp.IsActive,
|
|
IsSystem: resp.IsSystem,
|
|
CreatedAt: resp.CreatedAt.Format(time.RFC3339),
|
|
UpdatedAt: resp.UpdatedAt.Format(time.RFC3339),
|
|
}
|
|
|
|
if resp.ChartOfAccount != nil {
|
|
contractResp.ChartOfAccount = ModelToContractChartOfAccountResponse(resp.ChartOfAccount)
|
|
}
|
|
|
|
return contractResp
|
|
}
|
|
|
|
// Order Ingredient Transaction mappers
|
|
func ContractToModelCreateOrderIngredientTransactionRequest(req *contract.CreateOrderIngredientTransactionRequest) *models.CreateOrderIngredientTransactionRequest {
|
|
return &models.CreateOrderIngredientTransactionRequest{
|
|
OrderID: req.OrderID,
|
|
OrderItemID: req.OrderItemID,
|
|
ProductID: req.ProductID,
|
|
ProductVariantID: req.ProductVariantID,
|
|
IngredientID: req.IngredientID,
|
|
GrossQty: req.GrossQty,
|
|
NetQty: req.NetQty,
|
|
WasteQty: req.WasteQty,
|
|
Unit: req.Unit,
|
|
TransactionDate: req.TransactionDate,
|
|
}
|
|
}
|
|
|
|
func ContractToModelUpdateOrderIngredientTransactionRequest(req *contract.UpdateOrderIngredientTransactionRequest) *models.UpdateOrderIngredientTransactionRequest {
|
|
return &models.UpdateOrderIngredientTransactionRequest{
|
|
GrossQty: req.GrossQty,
|
|
NetQty: req.NetQty,
|
|
WasteQty: req.WasteQty,
|
|
Unit: req.Unit,
|
|
TransactionDate: req.TransactionDate,
|
|
}
|
|
}
|
|
|
|
func ModelToContractOrderIngredientTransactionResponse(resp *models.OrderIngredientTransactionResponse) *contract.OrderIngredientTransactionResponse {
|
|
return &contract.OrderIngredientTransactionResponse{
|
|
ID: resp.ID,
|
|
OrganizationID: resp.OrganizationID,
|
|
OutletID: resp.OutletID,
|
|
OrderID: resp.OrderID,
|
|
OrderItemID: resp.OrderItemID,
|
|
ProductID: resp.ProductID,
|
|
ProductVariantID: resp.ProductVariantID,
|
|
IngredientID: resp.IngredientID,
|
|
GrossQty: resp.GrossQty,
|
|
NetQty: resp.NetQty,
|
|
WasteQty: resp.WasteQty,
|
|
Unit: resp.Unit,
|
|
TransactionDate: resp.TransactionDate,
|
|
CreatedBy: resp.CreatedBy,
|
|
CreatedAt: resp.CreatedAt,
|
|
UpdatedAt: resp.UpdatedAt,
|
|
Organization: resp.Organization,
|
|
Outlet: resp.Outlet,
|
|
Order: resp.Order,
|
|
OrderItem: resp.OrderItem,
|
|
Product: resp.Product,
|
|
ProductVariant: resp.ProductVariant,
|
|
Ingredient: resp.Ingredient,
|
|
CreatedByUser: resp.CreatedByUser,
|
|
}
|
|
}
|
|
|
|
func ModelToContractOrderIngredientTransactionResponses(responses []*models.OrderIngredientTransactionResponse) []*contract.OrderIngredientTransactionResponse {
|
|
if responses == nil {
|
|
return nil
|
|
}
|
|
|
|
contractResponses := make([]*contract.OrderIngredientTransactionResponse, len(responses))
|
|
for i, resp := range responses {
|
|
contractResponses[i] = ModelToContractOrderIngredientTransactionResponse(resp)
|
|
}
|
|
|
|
return contractResponses
|
|
}
|
|
|
|
func ContractToModelListOrderIngredientTransactionsRequest(req *contract.ListOrderIngredientTransactionsRequest) *models.ListOrderIngredientTransactionsRequest {
|
|
return &models.ListOrderIngredientTransactionsRequest{
|
|
OrderID: req.OrderID,
|
|
OrderItemID: req.OrderItemID,
|
|
ProductID: req.ProductID,
|
|
ProductVariantID: req.ProductVariantID,
|
|
IngredientID: req.IngredientID,
|
|
StartDate: req.StartDate,
|
|
EndDate: req.EndDate,
|
|
Page: req.Page,
|
|
Limit: req.Limit,
|
|
}
|
|
}
|
|
|
|
func ModelToContractOrderIngredientTransactionSummary(resp *models.OrderIngredientTransactionSummary) *contract.OrderIngredientTransactionSummary {
|
|
return &contract.OrderIngredientTransactionSummary{
|
|
IngredientID: resp.IngredientID,
|
|
IngredientName: resp.IngredientName,
|
|
TotalGrossQty: resp.TotalGrossQty,
|
|
TotalNetQty: resp.TotalNetQty,
|
|
TotalWasteQty: resp.TotalWasteQty,
|
|
WastePercentage: resp.WastePercentage,
|
|
Unit: resp.Unit,
|
|
}
|
|
}
|
|
|
|
func ModelToContractOrderIngredientTransactionSummaries(responses []*models.OrderIngredientTransactionSummary) []*contract.OrderIngredientTransactionSummary {
|
|
if responses == nil {
|
|
return nil
|
|
}
|
|
|
|
contractResponses := make([]*contract.OrderIngredientTransactionSummary, len(responses))
|
|
for i, resp := range responses {
|
|
contractResponses[i] = ModelToContractOrderIngredientTransactionSummary(resp)
|
|
}
|
|
|
|
return contractResponses
|
|
}
|