feat: enhance inventory return line entity and DTOs with return and issued quantity fields
This commit is contained in:
parent
a2e92cf738
commit
b14f2eeafd
|
|
@ -6,7 +6,8 @@ import (
|
|||
|
||||
type TInventoryReturnLineEntity struct {
|
||||
ID uuid.UUID `gorm:"primaryKey;type:uuid;default:uuid_generate_v4()" json:"id"`
|
||||
Quantity float64 `gorm:"type:numeric;default:0" json:"quantity"`
|
||||
ReturnQuantity float64 `gorm:"type:numeric;default:0" json:"return_quantity"`
|
||||
IssuedQuantity float64 `gorm:"type:numeric;default:0" json:"issued_quantity"`
|
||||
Attachment string `gorm:"type:text;" json:"attachment"`
|
||||
|
||||
InvReturnID uuid.UUID `gorm:"type:uuid;index;" json:"inv_return_id"`
|
||||
|
|
|
|||
|
|
@ -73,12 +73,12 @@ func MigrateFresh(db *gorm.DB) error {
|
|||
// &entities.MAisleEntity{},
|
||||
// &entities.TAssignmentEntity{},
|
||||
// &entities.TAssignmentUserEntity{},
|
||||
&entities.TInventoryReceiptEntity{},
|
||||
&entities.TInventoryReceiptLineEntity{},
|
||||
&entities.TInventoryRequestEntity{},
|
||||
&entities.TInventoryRequestLineEntity{},
|
||||
&entities.TInventoryIssueEntity{},
|
||||
&entities.TInventoryIssueLineEntity{},
|
||||
// &entities.TInventoryReceiptEntity{},
|
||||
// &entities.TInventoryReceiptLineEntity{},
|
||||
// &entities.TInventoryRequestEntity{},
|
||||
// &entities.TInventoryRequestLineEntity{},
|
||||
// &entities.TInventoryIssueEntity{},
|
||||
// &entities.TInventoryIssueLineEntity{},
|
||||
&entities.TInventoryReturnEntity{},
|
||||
&entities.TInventoryReturnLineEntity{},
|
||||
// &entities.InventoryTransactionEntity{},
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ package dto
|
|||
|
||||
import (
|
||||
"github.com/Caknoooo/go-gin-clean-starter/database/entities"
|
||||
pkgdto "github.com/Caknoooo/go-gin-clean-starter/pkg/dto"
|
||||
"github.com/Caknoooo/go-gin-clean-starter/pkg/utils"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -33,7 +35,8 @@ type InventoryReturnCreateRequest struct {
|
|||
}
|
||||
|
||||
type InventoryReturnLineCreateRequest struct {
|
||||
Quantity float64 `json:"quantity"`
|
||||
ReturnQuantity float64 `json:"return_quantity"`
|
||||
IssuedQuantity float64 `json:"issued_quantity"`
|
||||
Attachment string `json:"attachment"`
|
||||
InvReturnID string `json:"inv_return_id"`
|
||||
ProductID string `json:"product_id"`
|
||||
|
|
@ -49,7 +52,8 @@ type InventoryReturnUpdateRequest struct {
|
|||
}
|
||||
|
||||
type InventoryReturnLineUpdateRequest struct {
|
||||
Quantity *float64 `json:"quantity"`
|
||||
ReturnQuantity *float64 `json:"return_quantity"`
|
||||
IssuedQuantity *float64 `json:"issued_quantity"`
|
||||
Attachment *string `json:"attachment"`
|
||||
InvReturnID *string `json:"inv_return_id"`
|
||||
ProductID *string `json:"product_id"`
|
||||
|
|
@ -62,18 +66,33 @@ type InventoryReturnResponse struct {
|
|||
DocumentDate string `json:"document_date"`
|
||||
Notes string `json:"notes"`
|
||||
Status string `json:"status"`
|
||||
InvIssueID string `json:"inv_issue_id"`
|
||||
ClientID string `json:"client_id"`
|
||||
InvIssue InvReturnInvIssue `json:"inv_issue"`
|
||||
Client pkgdto.IdNameResponse `json:"client"`
|
||||
ReturnLines []InventoryReturnLineResponse `json:"return_lines,omitempty"`
|
||||
}
|
||||
|
||||
type InvReturnInvIssue struct {
|
||||
ID string `json:"id"`
|
||||
DocumentNumber string `json:"document_number"`
|
||||
DocumentDate string `json:"document_date"`
|
||||
IssuerBy pkgdto.IdNameResponse `json:"issuer_by"`
|
||||
}
|
||||
|
||||
type InventoryReturnLineResponse struct {
|
||||
ID string `json:"id"`
|
||||
Quantity float64 `json:"quantity"`
|
||||
IssuedQuantity float64 `json:"issued_quantity"`
|
||||
ReturnQuantity float64 `json:"return_quantity"`
|
||||
Attachment string `json:"attachment"`
|
||||
InvReturnID string `json:"inv_return_id"`
|
||||
ProductID string `json:"product_id"`
|
||||
ClientID string `json:"client_id"`
|
||||
Product InvReturnProduct `json:"product"`
|
||||
Client pkgdto.IdNameResponse `json:"client"`
|
||||
}
|
||||
|
||||
type InvReturnProduct struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
RefNumber string `json:"ref_number"`
|
||||
Uom pkgdto.IdNameResponse `json:"uom"`
|
||||
}
|
||||
|
||||
// Helper untuk mapping entity ke response
|
||||
|
|
@ -82,25 +101,77 @@ func ToInventoryReturnResponse(entity entities.TInventoryReturnEntity) Inventory
|
|||
for _, line := range entity.ReturnLines {
|
||||
lines = append(lines, ToInventoryReturnLineResponse(line))
|
||||
}
|
||||
|
||||
client := pkgdto.IdNameResponse{}
|
||||
if entity.Client.ID != uuid.Nil {
|
||||
client = pkgdto.IdNameResponse{
|
||||
ID: entity.Client.ID.String(),
|
||||
Name: entity.Client.Name,
|
||||
}
|
||||
}
|
||||
|
||||
invIssue := InvReturnInvIssue{}
|
||||
if entity.InvIssue.ID != uuid.Nil {
|
||||
issuer := pkgdto.IdNameResponse{}
|
||||
if entity.InvIssue.IssuerBy != uuid.Nil {
|
||||
issuer = pkgdto.IdNameResponse{
|
||||
ID: entity.InvIssue.IssuerBy.String(),
|
||||
Name: "", // jika ada relasi user, isi nama user
|
||||
}
|
||||
}
|
||||
invIssue = InvReturnInvIssue{
|
||||
ID: entity.InvIssue.ID.String(),
|
||||
DocumentNumber: entity.InvIssue.DocumentNumber,
|
||||
DocumentDate: utils.DateTimeToString(entity.InvIssue.DocumentDate),
|
||||
IssuerBy: issuer,
|
||||
}
|
||||
}
|
||||
|
||||
return InventoryReturnResponse{
|
||||
ID: entity.ID.String(),
|
||||
DocumentNumber: entity.DocumentNumber,
|
||||
DocumentDate: utils.DateTimeToString(entity.DocumentDate),
|
||||
Notes: entity.Notes,
|
||||
Status: entity.Status,
|
||||
InvIssueID: entity.InvIssueID.String(),
|
||||
ClientID: entity.ClientID.String(),
|
||||
InvIssue: invIssue,
|
||||
Client: client,
|
||||
ReturnLines: lines,
|
||||
}
|
||||
}
|
||||
|
||||
func ToInventoryReturnLineResponse(line entities.TInventoryReturnLineEntity) InventoryReturnLineResponse {
|
||||
client := pkgdto.IdNameResponse{}
|
||||
if line.Client.ID != uuid.Nil {
|
||||
client = pkgdto.IdNameResponse{
|
||||
ID: line.Client.ID.String(),
|
||||
Name: line.Client.Name,
|
||||
}
|
||||
}
|
||||
|
||||
product := InvReturnProduct{}
|
||||
if line.Product.ID != uuid.Nil {
|
||||
uom := pkgdto.IdNameResponse{}
|
||||
if line.Product.Uom.ID != uuid.Nil {
|
||||
uom = pkgdto.IdNameResponse{
|
||||
ID: line.Product.Uom.ID.String(),
|
||||
Name: line.Product.Uom.Name,
|
||||
}
|
||||
}
|
||||
product = InvReturnProduct{
|
||||
ID: line.Product.ID.String(),
|
||||
Name: line.Product.Name,
|
||||
RefNumber: line.Product.RefNumber,
|
||||
Uom: uom,
|
||||
}
|
||||
}
|
||||
|
||||
return InventoryReturnLineResponse{
|
||||
ID: line.ID.String(),
|
||||
Quantity: line.Quantity,
|
||||
IssuedQuantity: line.IssuedQuantity, // pastikan field ini ada di entity
|
||||
ReturnQuantity: line.ReturnQuantity, // pastikan field ini ada di entity
|
||||
Attachment: line.Attachment,
|
||||
InvReturnID: line.InvReturnID.String(),
|
||||
ProductID: line.ProductID.String(),
|
||||
ClientID: line.ClientID.String(),
|
||||
Product: product,
|
||||
Client: client,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,15 +51,17 @@ func (s *inventoryReturnService) UpdateLine(ctx context.Context, lineId string,
|
|||
if err != nil {
|
||||
return dtodomain.InventoryReturnLineResponse{}, err
|
||||
}
|
||||
|
||||
if req.Quantity != nil {
|
||||
if req.ReturnQuantity != nil {
|
||||
if product.IsReturnable {
|
||||
return dtodomain.InventoryReturnLineResponse{},
|
||||
fmt.Errorf("product is not returnable, quantity cannot be updated")
|
||||
} else {
|
||||
line.Quantity = *req.Quantity
|
||||
line.ReturnQuantity = *req.ReturnQuantity
|
||||
}
|
||||
}
|
||||
if req.IssuedQuantity != nil {
|
||||
line.IssuedQuantity = *req.IssuedQuantity
|
||||
}
|
||||
if req.Attachment != nil {
|
||||
line.Attachment = *req.Attachment
|
||||
}
|
||||
|
|
@ -133,7 +135,8 @@ func (s *inventoryReturnService) Create(ctx context.Context, req dtodomain.Inven
|
|||
qty = issueLine.IssuedQuantity
|
||||
}
|
||||
lines = append(lines, entities.TInventoryReturnLineEntity{
|
||||
Quantity: qty,
|
||||
ReturnQuantity: qty,
|
||||
IssuedQuantity: issueLine.IssuedQuantity,
|
||||
Attachment: "", // isi sesuai kebutuhan
|
||||
InvReturnID: created.ID,
|
||||
ProductID: issueLine.ProductID,
|
||||
|
|
@ -237,7 +240,8 @@ func (s *inventoryReturnService) CreateLine(ctx context.Context, returnId string
|
|||
return dtodomain.InventoryReturnLineResponse{}, err
|
||||
}
|
||||
line := entities.TInventoryReturnLineEntity{
|
||||
Quantity: req.Quantity,
|
||||
ReturnQuantity: req.ReturnQuantity,
|
||||
IssuedQuantity: req.IssuedQuantity,
|
||||
Attachment: req.Attachment,
|
||||
InvReturnID: invReturnUUID,
|
||||
ProductID: productUUID,
|
||||
|
|
|
|||
Loading…
Reference in New Issue