feat: add TInventoryMovement and TInventoryMovementLine entities with migration updates
Deploy Application / deploy (push) Successful in 24s
Details
Deploy Application / deploy (push) Successful in 24s
Details
This commit is contained in:
parent
2d651faf9e
commit
576d3dcc23
|
|
@ -22,7 +22,7 @@ type InventoryTransactionEntity struct {
|
||||||
Aisle MAisleEntity `gorm:"foreignKey:AisleID;references:ID"`
|
Aisle MAisleEntity `gorm:"foreignKey:AisleID;references:ID"`
|
||||||
Client M_Client `gorm:"foreignKey:ClientID;references:ID"`
|
Client M_Client `gorm:"foreignKey:ClientID;references:ID"`
|
||||||
InvReceipt TInventoryReceiptEntity `gorm:"foreignKey:InvReceiptID;references:ID"`
|
InvReceipt TInventoryReceiptEntity `gorm:"foreignKey:InvReceiptID;references:ID"`
|
||||||
Issue TInventoryIssueEntity `gorm:"foreignKey:InvIssueID;references:ID"`
|
InvIssue TInventoryIssueEntity `gorm:"foreignKey:InvIssueID;references:ID"`
|
||||||
|
|
||||||
FullAuditTrail
|
FullAuditTrail
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,70 @@
|
||||||
|
package entities
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TInventoryMovementEntity struct {
|
||||||
|
ID uuid.UUID `gorm:"primaryKey;type:uuid;default:uuid_generate_v4()" json:"id"`
|
||||||
|
MovementNumber string `gorm:"type:varchar(100);" json:"movement_number"`
|
||||||
|
MovementDate time.Time `gorm:"type:timestamp;" json:"movement_date"`
|
||||||
|
MovementType string `gorm:"type:varchar(50);" json:"movement_type"`
|
||||||
|
Status string `gorm:"type:varchar(50);default:'draft'" json:"status"`
|
||||||
|
|
||||||
|
SourceLocationID uuid.UUID `gorm:"type:uuid;index;" json:"source_location_id"`
|
||||||
|
DestinationLocationID uuid.UUID `gorm:"type:uuid;index;" json:"destination_location_id"`
|
||||||
|
|
||||||
|
Client M_Client `gorm:"foreignKey:ClientID;references:ID"`
|
||||||
|
|
||||||
|
FullAuditTrail
|
||||||
|
}
|
||||||
|
|
||||||
|
func (TInventoryMovementEntity) TableName() string {
|
||||||
|
return "t_inventory_movements"
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenerateDocumentNumber generates a new document number for a client
|
||||||
|
func GenerateDocumentNumberInvMovement(db *gorm.DB, clientId string) (string, error) {
|
||||||
|
prefix := "MOVEMENT"
|
||||||
|
|
||||||
|
// Ambil nama client berdasarkan clientId
|
||||||
|
var client struct {
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
if err := db.Table("m_clients").Select("name").Where("id = ?", clientId).First(&client).Error; err != nil {
|
||||||
|
return "", fmt.Errorf("client not found")
|
||||||
|
}
|
||||||
|
if client.Name == "" {
|
||||||
|
return "", fmt.Errorf("client name is empty")
|
||||||
|
}
|
||||||
|
words := strings.Fields(client.Name)
|
||||||
|
initials := ""
|
||||||
|
for _, w := range words {
|
||||||
|
if len(w) > 0 {
|
||||||
|
initials += strings.ToUpper(string(w[0]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Cari document number terakhir untuk client ini
|
||||||
|
var lastMovement TInventoryMovementEntity
|
||||||
|
err := db.
|
||||||
|
Where("client_id = ?", clientId).
|
||||||
|
Order("movement_number DESC").
|
||||||
|
First(&lastMovement).Error
|
||||||
|
|
||||||
|
seq := 1
|
||||||
|
if err == nil && lastMovement.MovementNumber != "" {
|
||||||
|
parts := strings.Split(lastMovement.MovementNumber, "-")
|
||||||
|
if len(parts) == 3 {
|
||||||
|
fmt.Sscanf(parts[2], "%d", &seq)
|
||||||
|
seq++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
docNum := fmt.Sprintf("%s-%s-%04d", prefix, initials, seq)
|
||||||
|
return docNum, nil
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
package entities
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TInventoryMovementLineEntity struct {
|
||||||
|
ID uuid.UUID `gorm:"primaryKey;type:uuid;default:uuid_generate_v4()" json:"id"`
|
||||||
|
CurrentStock float64 `gorm:"type:numeric;not null;default:0" json:"current_stock"`
|
||||||
|
MinStock float64 `gorm:"type:numeric;not null;default:0" json:"min_stock"`
|
||||||
|
MaxStock float64 `gorm:"type:numeric;not null;default:0" json:"max_stock"`
|
||||||
|
MovedQuantity float64 `gorm:"type:numeric;not null;default:0" json:"moved_quantity"`
|
||||||
|
Status string `gorm:"type:varchar(50);default:'pending'" json:"status"`
|
||||||
|
|
||||||
|
InvMovementID uuid.UUID `gorm:"type:uuid;index;" json:"inv_movement_id"`
|
||||||
|
ProductID uuid.UUID `gorm:"type:uuid;index;" json:"product_id"`
|
||||||
|
StorageID uuid.UUID `gorm:"type:uuid;index;" json:"storage_id"`
|
||||||
|
ClientID uuid.UUID `gorm:"type:uuid;index;" json:"client_id"`
|
||||||
|
|
||||||
|
Product MProductEntity `gorm:"foreignKey:ProductID;references:ID"`
|
||||||
|
InvMovement TInventoryMovementEntity `gorm:"foreignKey:InvMovementID;references:ID"`
|
||||||
|
InvStorage InventoryStorageEntity `gorm:"foreignKey:StorageID;references:ID"`
|
||||||
|
Client M_Client `gorm:"foreignKey:ClientID;references:ID"`
|
||||||
|
|
||||||
|
FullAuditTrail
|
||||||
|
}
|
||||||
|
|
||||||
|
func (TInventoryMovementLineEntity) TableName() string {
|
||||||
|
return "t_inventory_movement_lines"
|
||||||
|
}
|
||||||
|
|
@ -38,8 +38,10 @@ func Migrate(db *gorm.DB) error {
|
||||||
&entities.TInventoryIssueLineEntity{},
|
&entities.TInventoryIssueLineEntity{},
|
||||||
&entities.TInventoryReturnEntity{},
|
&entities.TInventoryReturnEntity{},
|
||||||
&entities.TInventoryReturnLineEntity{},
|
&entities.TInventoryReturnLineEntity{},
|
||||||
// &entities.InventoryTransactionEntity{},
|
&entities.InventoryTransactionEntity{},
|
||||||
// &entities.InventoryStorageEntity{},
|
&entities.InventoryStorageEntity{},
|
||||||
|
&entities.TInventoryMovementEntity{},
|
||||||
|
&entities.TInventoryMovementLineEntity{},
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -81,8 +83,10 @@ func MigrateFresh(db *gorm.DB) error {
|
||||||
&entities.TInventoryIssueLineEntity{},
|
&entities.TInventoryIssueLineEntity{},
|
||||||
&entities.TInventoryReturnEntity{},
|
&entities.TInventoryReturnEntity{},
|
||||||
&entities.TInventoryReturnLineEntity{},
|
&entities.TInventoryReturnLineEntity{},
|
||||||
// &entities.InventoryTransactionEntity{},
|
&entities.InventoryTransactionEntity{},
|
||||||
// &entities.InventoryStorageEntity{},
|
&entities.InventoryStorageEntity{},
|
||||||
|
&entities.TInventoryMovementEntity{},
|
||||||
|
&entities.TInventoryMovementLineEntity{},
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue