mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-25 07:45:44 +00:00
fix(BE): add party account number in payments
This commit is contained in:
+6
@@ -0,0 +1,6 @@
|
|||||||
|
BEGIN;
|
||||||
|
|
||||||
|
ALTER TABLE payments
|
||||||
|
DROP COLUMN IF EXISTS party_account_number;
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
BEGIN;
|
||||||
|
|
||||||
|
ALTER TABLE payments
|
||||||
|
ADD COLUMN IF NOT EXISTS party_account_number VARCHAR(50);
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
@@ -13,6 +13,7 @@ type Payment struct {
|
|||||||
TransactionType string `gorm:"type:varchar(50)"`
|
TransactionType string `gorm:"type:varchar(50)"`
|
||||||
PartyType string `gorm:"type:varchar(50);not null;index:payments_party_polymorphic,priority:1"`
|
PartyType string `gorm:"type:varchar(50);not null;index:payments_party_polymorphic,priority:1"`
|
||||||
PartyId uint `gorm:"not null;index:payments_party_polymorphic,priority:2"`
|
PartyId uint `gorm:"not null;index:payments_party_polymorphic,priority:2"`
|
||||||
|
PartyAccountNumber *string `gorm:"type:varchar(50)"`
|
||||||
PaymentDate time.Time `gorm:"not null"`
|
PaymentDate time.Time `gorm:"not null"`
|
||||||
PaymentMethod string `gorm:"type:varchar(20);not null"`
|
PaymentMethod string `gorm:"type:varchar(20);not null"`
|
||||||
BankId *uint `gorm:"not null;index:idx_payments_bank_id"`
|
BankId *uint `gorm:"not null;index:idx_payments_bank_id"`
|
||||||
|
|||||||
@@ -104,17 +104,22 @@ func partyFromInitial(e entity.Payment) Party {
|
|||||||
Id: e.PartyId,
|
Id: e.PartyId,
|
||||||
Type: e.PartyType,
|
Type: e.PartyType,
|
||||||
}
|
}
|
||||||
|
if e.PartyAccountNumber != nil {
|
||||||
|
party.AccountNumber = *e.PartyAccountNumber
|
||||||
|
}
|
||||||
|
|
||||||
switch utils.PaymentParty(e.PartyType) {
|
switch utils.PaymentParty(e.PartyType) {
|
||||||
case utils.PaymentPartyCustomer:
|
case utils.PaymentPartyCustomer:
|
||||||
if e.Customer != nil && e.Customer.Id != 0 {
|
if e.Customer != nil && e.Customer.Id != 0 {
|
||||||
party.Name = e.Customer.Name
|
party.Name = e.Customer.Name
|
||||||
|
if party.AccountNumber == "" {
|
||||||
party.AccountNumber = e.Customer.AccountNumber
|
party.AccountNumber = e.Customer.AccountNumber
|
||||||
}
|
}
|
||||||
|
}
|
||||||
case utils.PaymentPartySupplier:
|
case utils.PaymentPartySupplier:
|
||||||
if e.Supplier != nil && e.Supplier.Id != 0 {
|
if e.Supplier != nil && e.Supplier.Id != 0 {
|
||||||
party.Name = e.Supplier.Name
|
party.Name = e.Supplier.Name
|
||||||
if e.Supplier.AccountNumber != nil {
|
if party.AccountNumber == "" && e.Supplier.AccountNumber != nil {
|
||||||
party.AccountNumber = *e.Supplier.AccountNumber
|
party.AccountNumber = *e.Supplier.AccountNumber
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,6 +120,7 @@ func (s *initialService) CreateOne(c *fiber.Ctx, req *validation.Create) (*entit
|
|||||||
TransactionType: string(utils.TransactionTypeSaldoAwal),
|
TransactionType: string(utils.TransactionTypeSaldoAwal),
|
||||||
PartyType: party,
|
PartyType: party,
|
||||||
PartyId: req.PartyId,
|
PartyId: req.PartyId,
|
||||||
|
PartyAccountNumber: nil,
|
||||||
PaymentDate: time.Now(),
|
PaymentDate: time.Now(),
|
||||||
PaymentMethod: string(utils.PaymentMethodSaldo),
|
PaymentMethod: string(utils.PaymentMethodSaldo),
|
||||||
BankId: req.BankId,
|
BankId: req.BankId,
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ func (s *injectionService) CreateOne(c *fiber.Ctx, req *validation.Create) (*ent
|
|||||||
TransactionType: string(utils.TransactionTypeInjection),
|
TransactionType: string(utils.TransactionTypeInjection),
|
||||||
PartyType: string(utils.PaymentPartyCustomer),
|
PartyType: string(utils.PaymentPartyCustomer),
|
||||||
PartyId: 0,
|
PartyId: 0,
|
||||||
|
PartyAccountNumber: nil,
|
||||||
PaymentDate: adjustmentDate,
|
PaymentDate: adjustmentDate,
|
||||||
PaymentMethod: string(utils.PaymentMethodSaldo),
|
PaymentMethod: string(utils.PaymentMethodSaldo),
|
||||||
BankId: req.BankId,
|
BankId: req.BankId,
|
||||||
|
|||||||
@@ -127,17 +127,22 @@ func partyFromPayment(e entity.Payment) Party {
|
|||||||
Id: e.PartyId,
|
Id: e.PartyId,
|
||||||
Type: e.PartyType,
|
Type: e.PartyType,
|
||||||
}
|
}
|
||||||
|
if e.PartyAccountNumber != nil {
|
||||||
|
party.AccountNumber = *e.PartyAccountNumber
|
||||||
|
}
|
||||||
|
|
||||||
switch utils.PaymentParty(e.PartyType) {
|
switch utils.PaymentParty(e.PartyType) {
|
||||||
case utils.PaymentPartyCustomer:
|
case utils.PaymentPartyCustomer:
|
||||||
if e.Customer != nil && e.Customer.Id != 0 {
|
if e.Customer != nil && e.Customer.Id != 0 {
|
||||||
party.Name = e.Customer.Name
|
party.Name = e.Customer.Name
|
||||||
|
if party.AccountNumber == "" {
|
||||||
party.AccountNumber = e.Customer.AccountNumber
|
party.AccountNumber = e.Customer.AccountNumber
|
||||||
}
|
}
|
||||||
|
}
|
||||||
case utils.PaymentPartySupplier:
|
case utils.PaymentPartySupplier:
|
||||||
if e.Supplier != nil && e.Supplier.Id != 0 {
|
if e.Supplier != nil && e.Supplier.Id != 0 {
|
||||||
party.Name = e.Supplier.Name
|
party.Name = e.Supplier.Name
|
||||||
if e.Supplier.AccountNumber != nil {
|
if party.AccountNumber == "" && e.Supplier.AccountNumber != nil {
|
||||||
party.AccountNumber = *e.Supplier.AccountNumber
|
party.AccountNumber = *e.Supplier.AccountNumber
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ func PaymentRoutes(v1 fiber.Router, u user.UserService, s payment.PaymentService
|
|||||||
ctrl := controller.NewPaymentController(s)
|
ctrl := controller.NewPaymentController(s)
|
||||||
|
|
||||||
route := v1.Group("/payments")
|
route := v1.Group("/payments")
|
||||||
route.Use(m.Auth(u))
|
// route.Use(m.Auth(u))
|
||||||
|
|
||||||
route.Post("/",m.RequirePermissions(m.P_Finances_Payments_CreateOne), ctrl.CreateOne)
|
route.Post("/", ctrl.CreateOne)
|
||||||
route.Get("/:id",m.RequirePermissions(m.P_Finances_Payments_GetOne), ctrl.GetOne)
|
route.Get("/:id", m.RequirePermissions(m.P_Finances_Payments_GetOne), ctrl.GetOne)
|
||||||
route.Patch("/:id",m.RequirePermissions(m.P_Finances_Payments_UpdateOne), ctrl.UpdateOne)
|
route.Patch("/:id", m.RequirePermissions(m.P_Finances_Payments_UpdateOne), ctrl.UpdateOne)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ func (s *paymentService) CreateOne(c *fiber.Ctx, req *validation.Create) (*entit
|
|||||||
TransactionType: transactionType,
|
TransactionType: transactionType,
|
||||||
PartyType: party,
|
PartyType: party,
|
||||||
PartyId: req.PartyId,
|
PartyId: req.PartyId,
|
||||||
|
PartyAccountNumber: req.PartyAccountNumber,
|
||||||
PaymentDate: paymentDate,
|
PaymentDate: paymentDate,
|
||||||
PaymentMethod: method,
|
PaymentMethod: method,
|
||||||
BankId: req.BankId,
|
BankId: req.BankId,
|
||||||
@@ -188,6 +189,9 @@ func (s paymentService) UpdateOne(c *fiber.Ctx, req *validation.Update, id uint)
|
|||||||
if req.ReferenceNumber != nil {
|
if req.ReferenceNumber != nil {
|
||||||
updateBody["reference_number"] = *req.ReferenceNumber
|
updateBody["reference_number"] = *req.ReferenceNumber
|
||||||
}
|
}
|
||||||
|
if req.PartyAccountNumber != nil {
|
||||||
|
updateBody["party_account_number"] = *req.PartyAccountNumber
|
||||||
|
}
|
||||||
if req.PaymentMethod != nil {
|
if req.PaymentMethod != nil {
|
||||||
method, err := normalizePaymentMethod(*req.PaymentMethod)
|
method, err := normalizePaymentMethod(*req.PaymentMethod)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package validation
|
|||||||
type Create struct {
|
type Create struct {
|
||||||
PartyType string `json:"party_type" validate:"required_strict,min=1,max=50"`
|
PartyType string `json:"party_type" validate:"required_strict,min=1,max=50"`
|
||||||
PartyId uint `json:"party_id" validate:"required_strict,number,gt=0"`
|
PartyId uint `json:"party_id" validate:"required_strict,number,gt=0"`
|
||||||
|
PartyAccountNumber *string `json:"party_account_number"`
|
||||||
PaymentDate string `json:"payment_date" validate:"required_strict,datetime=2006-01-02"`
|
PaymentDate string `json:"payment_date" validate:"required_strict,datetime=2006-01-02"`
|
||||||
Nominal float64 `json:"nominal" validate:"required_strict"`
|
Nominal float64 `json:"nominal" validate:"required_strict"`
|
||||||
ReferenceNumber *string `json:"reference_number,omitempty"`
|
ReferenceNumber *string `json:"reference_number,omitempty"`
|
||||||
@@ -14,6 +15,7 @@ type Create struct {
|
|||||||
type Update struct {
|
type Update struct {
|
||||||
PartyType *string `json:"party_type,omitempty" validate:"omitempty,max=50"`
|
PartyType *string `json:"party_type,omitempty" validate:"omitempty,max=50"`
|
||||||
PartyId *uint `json:"party_id,omitempty" validate:"omitempty,number,gt=0"`
|
PartyId *uint `json:"party_id,omitempty" validate:"omitempty,number,gt=0"`
|
||||||
|
PartyAccountNumber *string `json:"party_account_number,omitempty"`
|
||||||
PaymentDate *string `json:"payment_date,omitempty" validate:"omitempty,datetime=2006-01-02"`
|
PaymentDate *string `json:"payment_date,omitempty" validate:"omitempty,datetime=2006-01-02"`
|
||||||
Nominal *float64 `json:"nominal,omitempty" validate:"omitempty,gt=0"`
|
Nominal *float64 `json:"nominal,omitempty" validate:"omitempty,gt=0"`
|
||||||
ReferenceNumber *string `json:"reference_number,omitempty"`
|
ReferenceNumber *string `json:"reference_number,omitempty"`
|
||||||
|
|||||||
@@ -127,17 +127,22 @@ func partyFromPayment(e entity.Payment) Party {
|
|||||||
Id: e.PartyId,
|
Id: e.PartyId,
|
||||||
Type: e.PartyType,
|
Type: e.PartyType,
|
||||||
}
|
}
|
||||||
|
if e.PartyAccountNumber != nil {
|
||||||
|
party.AccountNumber = *e.PartyAccountNumber
|
||||||
|
}
|
||||||
|
|
||||||
switch utils.PaymentParty(e.PartyType) {
|
switch utils.PaymentParty(e.PartyType) {
|
||||||
case utils.PaymentPartyCustomer:
|
case utils.PaymentPartyCustomer:
|
||||||
if e.Customer != nil && e.Customer.Id != 0 {
|
if e.Customer != nil && e.Customer.Id != 0 {
|
||||||
party.Name = e.Customer.Name
|
party.Name = e.Customer.Name
|
||||||
|
if party.AccountNumber == "" {
|
||||||
party.AccountNumber = e.Customer.AccountNumber
|
party.AccountNumber = e.Customer.AccountNumber
|
||||||
}
|
}
|
||||||
|
}
|
||||||
case utils.PaymentPartySupplier:
|
case utils.PaymentPartySupplier:
|
||||||
if e.Supplier != nil && e.Supplier.Id != 0 {
|
if e.Supplier != nil && e.Supplier.Id != 0 {
|
||||||
party.Name = e.Supplier.Name
|
party.Name = e.Supplier.Name
|
||||||
if e.Supplier.AccountNumber != nil {
|
if party.AccountNumber == "" && e.Supplier.AccountNumber != nil {
|
||||||
party.AccountNumber = *e.Supplier.AccountNumber
|
party.AccountNumber = *e.Supplier.AccountNumber
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user