From 872a71efda2bac62bc931a26d1b18e5d48ecade8 Mon Sep 17 00:00:00 2001 From: giovanni Date: Sun, 17 May 2026 20:48:13 +0700 Subject: [PATCH] fix get search keuangan; add bank name to supplier and customer --- ...60517132922_add_bank_name_to_customers_suppliers.down.sql | 2 ++ ...0260517132922_add_bank_name_to_customers_suppliers.up.sql | 2 ++ internal/entities/customer.go | 1 + internal/entities/supplier.go | 1 + .../finance/transactions/services/transaction.service.go | 4 ++-- internal/modules/master/customers/dto/customer.dto.go | 4 ++++ .../modules/master/customers/services/customer.service.go | 5 +++++ .../master/customers/validations/customer.validation.go | 2 ++ internal/modules/master/suppliers/dto/supplier.dto.go | 2 ++ .../modules/master/suppliers/services/supplier.service.go | 5 +++++ .../master/suppliers/validations/supplier.validation.go | 2 ++ 11 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 internal/database/migrations/20260517132922_add_bank_name_to_customers_suppliers.down.sql create mode 100644 internal/database/migrations/20260517132922_add_bank_name_to_customers_suppliers.up.sql diff --git a/internal/database/migrations/20260517132922_add_bank_name_to_customers_suppliers.down.sql b/internal/database/migrations/20260517132922_add_bank_name_to_customers_suppliers.down.sql new file mode 100644 index 00000000..08cbd103 --- /dev/null +++ b/internal/database/migrations/20260517132922_add_bank_name_to_customers_suppliers.down.sql @@ -0,0 +1,2 @@ +ALTER TABLE customers DROP COLUMN bank_name; +ALTER TABLE suppliers DROP COLUMN bank_name; diff --git a/internal/database/migrations/20260517132922_add_bank_name_to_customers_suppliers.up.sql b/internal/database/migrations/20260517132922_add_bank_name_to_customers_suppliers.up.sql new file mode 100644 index 00000000..5420a363 --- /dev/null +++ b/internal/database/migrations/20260517132922_add_bank_name_to_customers_suppliers.up.sql @@ -0,0 +1,2 @@ +ALTER TABLE customers ADD COLUMN bank_name VARCHAR(100) NOT NULL DEFAULT ''; +ALTER TABLE suppliers ADD COLUMN bank_name VARCHAR(100); diff --git a/internal/entities/customer.go b/internal/entities/customer.go index f171f0ff..af4bd556 100644 --- a/internal/entities/customer.go +++ b/internal/entities/customer.go @@ -15,6 +15,7 @@ type Customer struct { Phone string `gorm:"not null;size:20"` Email string `gorm:"type:varchar(50);not null"` AccountNumber string `gorm:"not null;size:50"` + BankName string `gorm:"not null;size:100;default:''"` Balance float64 `gorm:"default:0"` CreatedBy uint `gorm:"not null"` CreatedAt time.Time `gorm:"autoCreateTime"` diff --git a/internal/entities/supplier.go b/internal/entities/supplier.go index bdbb4dfe..410cc93b 100644 --- a/internal/entities/supplier.go +++ b/internal/entities/supplier.go @@ -19,6 +19,7 @@ type Supplier struct { Address string `gorm:"not null"` Npwp *string `gorm:"size:50"` AccountNumber *string `gorm:"size:50"` + BankName *string `gorm:"size:100"` Balance float64 `gorm:"type:numeric(15,3);default:0"` DueDate int `gorm:"not null"` CreatedBy uint `gorm:"not null"` diff --git a/internal/modules/finance/transactions/services/transaction.service.go b/internal/modules/finance/transactions/services/transaction.service.go index 39a63849..d58c4aa3 100644 --- a/internal/modules/finance/transactions/services/transaction.service.go +++ b/internal/modules/finance/transactions/services/transaction.service.go @@ -91,7 +91,7 @@ func (s transactionService) GetAll(c *fiber.Ctx, params *validation.Query) ([]en if params.Search != "" { like := "%" + strings.ToLower(strings.TrimSpace(params.Search)) + "%" db = db.Where( - `LOWER(payment_code) LIKE ? OR + `(LOWER(payment_code) LIKE ? OR LOWER(COALESCE(reference_number, '')) LIKE ? OR LOWER(COALESCE(payment_method, '')) LIKE ? OR LOWER(COALESCE(transaction_type, '')) LIKE ? OR @@ -100,7 +100,7 @@ func (s transactionService) GetAll(c *fiber.Ctx, params *validation.Query) ([]en LOWER(COALESCE(suppliers.name, '')) LIKE ? OR LOWER(COALESCE(banks.name, '')) LIKE ? OR CAST(payments.nominal AS TEXT) LIKE ? OR - TO_CHAR(payments.payment_date, 'YYYY-MM-DD') LIKE ?`, + TO_CHAR(payments.payment_date, 'YYYY-MM-DD') LIKE ?)`, like, like, like, like, like, like, like, like, like, like, ) } diff --git a/internal/modules/master/customers/dto/customer.dto.go b/internal/modules/master/customers/dto/customer.dto.go index eceafa39..bc904807 100644 --- a/internal/modules/master/customers/dto/customer.dto.go +++ b/internal/modules/master/customers/dto/customer.dto.go @@ -14,6 +14,7 @@ type CustomerRelationDTO struct { Name string `json:"name"` Type string `json:"type"` AccountNumber string `json:"account_number"` + BankName string `json:"bank_name"` Address string `json:"address,omitempty"` Balance float64 `json:"balance"` Pic *userDTO.UserRelationDTO `json:"pic,omitempty"` @@ -28,6 +29,7 @@ type CustomerListDTO struct { Phone string `json:"phone"` Email string `json:"email"` AccountNumber string `json:"account_number"` + BankName string `json:"bank_name"` Balance float64 `json:"balance"` Pic userDTO.UserRelationDTO `json:"pic"` CreatedUser userDTO.UserRelationDTO `json:"created_user"` @@ -53,6 +55,7 @@ func ToCustomerRelationDTO(e entity.Customer) CustomerRelationDTO { Name: e.Name, Type: e.Type, AccountNumber: e.AccountNumber, + BankName: e.BankName, Address: e.Address, Balance: e.Balance, Pic: pic, @@ -81,6 +84,7 @@ func ToCustomerListDTO(e entity.Customer) CustomerListDTO { Phone: e.Phone, Email: e.Email, AccountNumber: e.AccountNumber, + BankName: e.BankName, Pic: pic, CreatedAt: e.CreatedAt, UpdatedAt: e.UpdatedAt, diff --git a/internal/modules/master/customers/services/customer.service.go b/internal/modules/master/customers/services/customer.service.go index 416d65b3..18178dd7 100644 --- a/internal/modules/master/customers/services/customer.service.go +++ b/internal/modules/master/customers/services/customer.service.go @@ -133,6 +133,7 @@ func (s *customerService) CreateOne(c *fiber.Ctx, req *validation.Create) (*enti Phone: req.Phone, Email: req.Email, AccountNumber: req.AccountNumber, + BankName: req.BankName, CreatedBy: actorID, } @@ -193,6 +194,10 @@ func (s customerService) UpdateOne(c *fiber.Ctx, req *validation.Update, id uint updateBody["account_number"] = *req.AccountNumber } + if req.BankName != nil { + updateBody["bank_name"] = *req.BankName + } + if len(updateBody) == 0 { return s.GetOne(c, id) } diff --git a/internal/modules/master/customers/validations/customer.validation.go b/internal/modules/master/customers/validations/customer.validation.go index 5b814b37..2ca1b9ea 100644 --- a/internal/modules/master/customers/validations/customer.validation.go +++ b/internal/modules/master/customers/validations/customer.validation.go @@ -8,6 +8,7 @@ type Create struct { Phone string `json:"phone" validate:"required_strict,max=20"` Email string `json:"email" validate:"required_strict,email,max=50"` AccountNumber string `json:"account_number" validate:"required_strict,max=50"` + BankName string `json:"bank_name" validate:"required_strict,max=100"` } type Update struct { @@ -18,6 +19,7 @@ type Update struct { Phone *string `json:"phone,omitempty" validate:"omitempty,max=20"` Email *string `json:"email,omitempty" validate:"omitempty,max=50"` AccountNumber *string `json:"account_number,omitempty" validate:"omitempty,max=50"` + BankName *string `json:"bank_name,omitempty" validate:"omitempty,max=100"` } type Query struct { diff --git a/internal/modules/master/suppliers/dto/supplier.dto.go b/internal/modules/master/suppliers/dto/supplier.dto.go index c8302b0b..49f3c824 100644 --- a/internal/modules/master/suppliers/dto/supplier.dto.go +++ b/internal/modules/master/suppliers/dto/supplier.dto.go @@ -26,6 +26,7 @@ type SupplierListDTO struct { Address string `json:"address"` Npwp *string `json:"npwp,omitempty"` AccountNumber *string `json:"account_number,omitempty"` + BankName *string `json:"bank_name,omitempty"` Balance float64 `json:"balance"` DueDate int `json:"due_date"` CreatedUser *userDTO.UserRelationDTO `json:"created_user"` @@ -66,6 +67,7 @@ func ToSupplierListDTO(e entity.Supplier) SupplierListDTO { Address: e.Address, Npwp: e.Npwp, AccountNumber: e.AccountNumber, + BankName: e.BankName, Balance: e.Balance, DueDate: e.DueDate, SupplierRelationDTO: ToSupplierRelationDTO(e), diff --git a/internal/modules/master/suppliers/services/supplier.service.go b/internal/modules/master/suppliers/services/supplier.service.go index d211ed9d..bfa50f84 100644 --- a/internal/modules/master/suppliers/services/supplier.service.go +++ b/internal/modules/master/suppliers/services/supplier.service.go @@ -160,6 +160,7 @@ func (s *supplierService) CreateOne(c *fiber.Ctx, req *validation.Create) (*enti Address: req.Address, Npwp: req.Npwp, AccountNumber: req.AccountNumber, + BankName: req.BankName, DueDate: req.DueDate, CreatedBy: actorID, } @@ -243,6 +244,10 @@ func (s supplierService) UpdateOne(c *fiber.Ctx, req *validation.Update, id uint updateBody["account_number"] = *req.AccountNumber } + if req.BankName != nil { + updateBody["bank_name"] = *req.BankName + } + if req.DueDate != nil { updateBody["due_date"] = *req.DueDate } diff --git a/internal/modules/master/suppliers/validations/supplier.validation.go b/internal/modules/master/suppliers/validations/supplier.validation.go index 720e784e..f0eb1b21 100644 --- a/internal/modules/master/suppliers/validations/supplier.validation.go +++ b/internal/modules/master/suppliers/validations/supplier.validation.go @@ -12,6 +12,7 @@ type Create struct { Address string `json:"address" validate:"required_strict"` Npwp *string `json:"npwp,omitempty" validate:"omitempty,max=50"` AccountNumber *string `json:"account_number,omitempty" validate:"omitempty,max=50"` + BankName *string `json:"bank_name,omitempty" validate:"omitempty,max=100"` DueDate int `json:"due_date" validate:"required_strict,number,gt=0"` } @@ -27,6 +28,7 @@ type Update struct { Address *string `json:"address,omitempty" validate:"omitempty"` Npwp *string `json:"npwp,omitempty" validate:"omitempty,max=50"` AccountNumber *string `json:"account_number,omitempty" validate:"omitempty,max=50"` + BankName *string `json:"bank_name,omitempty" validate:"omitempty,max=100"` DueDate *int `json:"due_date,omitempty" validate:"omitempty,number,gt=0"` }