Compare commits

...

7 Commits

Author SHA1 Message Date
QuanTT0110 fffcc281cc push 2022-09-14 23:30:22 +07:00
QuanTT0110 f731be7b62 push 2022-09-14 18:04:18 +07:00
Tue 42a6d04413 bank info 2022-09-14 17:33:18 +07:00
Tue ee32f2d8bb bank info 2022-09-14 17:23:01 +07:00
Tue 0e35b6aec3 bank info 2022-09-14 14:25:16 +07:00
Tue e1a18df726 bank info 2022-09-14 14:14:27 +07:00
Tue b32ceefab1 add bank info 2022-09-14 14:09:48 +07:00
9 changed files with 229 additions and 26 deletions

39
client/bank.go Normal file
View File

@ -0,0 +1,39 @@
package client
import (
"encoding/json"
"errors"
"github.com/Selly-Modules/natsio"
"github.com/Selly-Modules/natsio/model"
"github.com/Selly-Modules/natsio/subject"
)
// Bank ...
type Bank struct{}
// GetBank ...
func GetBank() Bank {
return Bank{}
}
func (s Bank) GetBankById(bankID string) (*model.BankBrief, error) {
msg, err := natsio.GetServer().Request(subject.Bank.GetBankById, toBytes(bankID))
if err != nil {
return nil, err
}
var r struct {
Data *model.BankBrief `json:"data"`
Error string `json:"error"`
}
if err = json.Unmarshal(msg.Data, &r); err != nil {
return nil, err
}
if r.Error != "" {
return nil, errors.New(r.Error)
}
return r.Data, nil
}

39
client/bank_branch.go Normal file
View File

@ -0,0 +1,39 @@
package client
import (
"encoding/json"
"errors"
"github.com/Selly-Modules/natsio"
"github.com/Selly-Modules/natsio/model"
"github.com/Selly-Modules/natsio/subject"
)
// BankBranch ...
type BankBranch struct{}
// GetBankBranch ...
func GetBankBranch() Bank {
return Bank{}
}
func (s Bank) GetBankBranchById(bankBranchID string) (*model.BankBranchBrief, error) {
msg, err := natsio.GetServer().Request(subject.Bank.GetBankBranchById, toBytes(bankBranchID))
if err != nil {
return nil, err
}
var r struct {
Data *model.BankBranchBrief `json:"data"`
Error string `json:"error"`
}
if err = json.Unmarshal(msg.Data, &r); err != nil {
return nil, err
}
if r.Error != "" {
return nil, errors.New(r.Error)
}
return r.Data, nil
}

View File

@ -79,3 +79,60 @@ func (s Supplier) FindAll(supplierID model.SupplierRequestPayload) (*model.Suppl
return r.Data, nil return r.Data, nil
} }
func (s Supplier) GetBankInfoByID(supplierID model.SupplierRequestPayload) (*model.SupplierAll, error) {
msg, err := natsio.GetServer().Request(subject.Supplier.FindAll, toBytes(supplierID))
if err != nil {
return nil, err
}
var r struct {
Data *model.SupplierAll `json:"data"`
Error string `json:"error"`
}
if err = json.Unmarshal(msg.Data, &r); err != nil {
return nil, err
}
if r.Error != "" {
return nil, errors.New(r.Error)
}
return r.Data, nil
}
// CreateWarehouseIntoServiceSupplier ...
func (s Supplier) CreateWarehouseIntoServiceSupplier(p model.CreateSupplierWarehousePayload) error {
msg, err := natsio.GetServer().Request(subject.Warehouse.CreateWarehouseIntoServiceSupplier, toBytes(p))
if err != nil {
return err
}
var r struct {
Error string `json:"error"`
}
if err = json.Unmarshal(msg.Data, &r); err != nil {
return err
}
if r.Error != "" {
return errors.New(r.Error)
}
return nil
}
// UpdateWarehouseIntoServiceSupplier ...
func (s Supplier) UpdateWarehouseIntoServiceSupplier(p model.UpdateSupplierWarehousePayload) error {
msg, err := natsio.GetServer().Request(subject.Warehouse.UpdateWarehouseIntoServiceSupplier, toBytes(p))
if err != nil {
return err
}
var r struct {
Error string `json:"error"`
}
if err = json.Unmarshal(msg.Data, &r); err != nil {
return err
}
if r.Error != "" {
return errors.New(r.Error)
}
return nil
}

View File

@ -0,0 +1,11 @@
package model
// BankBranchBrief ...
type BankBranchBrief struct {
ID string `json:"_id"`
City string `json:"city"`
BankCode string `json:"bankCode"`
Bank string `json:"bank"`
Active bool `json:"active"`
Name string `json:"name"`
}

21
model/bank_response.go Normal file
View File

@ -0,0 +1,21 @@
package model
// MultiLang ...
type MultiLang struct {
En string `json:"en"`
Vi string `json:"vi"`
}
// BankBrief ...
type BankBrief struct {
ID string `json:"_id"`
Name MultiLang `json:"name"`
ShortName string `json:"shortName"`
Active bool `json:"active"`
BenBankName string `json:"benBankName"`
BankCode int `json:"bankCode"`
IsBranchRequired bool `json:"isBranchRequired"`
SearchString string `json:"searchString"`
BeneficiaryForVietinbank string `json:"beneficiaryForVietinbank"`
CreatedBy string `json:"createdBy,omitempty"`
}

View File

@ -22,3 +22,19 @@ type SupplierRequestPayload struct {
PIC string PIC string
ContractStatus string ContractStatus string
} }
type CreateSupplierWarehousePayload struct {
Supplier string `json:"supplier"`
Warehouse string `json:"warehouse"`
ProvinceCode int `json:"provinceCode"`
DistrictCode int `json:"districtCode"`
WardCode int `json:"wardCode"`
}
type UpdateSupplierWarehousePayload struct {
Supplier string `json:"supplier"`
Warehouse string `json:"warehouse"`
ProvinceCode int `json:"provinceCode"`
DistrictCode int `json:"districtCode"`
WardCode int `json:"wardCode"`
}

14
subject/bank.go Normal file
View File

@ -0,0 +1,14 @@
package subject
import "fmt"
func getBankValue(val string) string {
return fmt.Sprintf("%s.%s", prefixes.Bank, val)
}
var Bank = struct {
GetBankById string
GetBankBranchById string
}{
GetBankBranchById: getBankValue("get_bank_by_id"),
}

View File

@ -5,6 +5,7 @@ var prefixes = struct {
Order string Order string
Warehouse string Warehouse string
Location string Location string
Bank string
Supplier string Supplier string
}{ }{
Communication: "communication", Communication: "communication",
@ -12,4 +13,5 @@ var prefixes = struct {
Warehouse: "warehouse", Warehouse: "warehouse",
Location: "location", Location: "location",
Supplier: "supplier", Supplier: "supplier",
Bank: "bank",
} }

View File

@ -20,6 +20,8 @@ var Warehouse = struct {
Count string Count string
AfterUpdateWarehouse string AfterUpdateWarehouse string
AfterCreateWarehouse string AfterCreateWarehouse string
CreateWarehouseIntoServiceSupplier string
UpdateWarehouseIntoServiceSupplier string
}{ }{
AfterCreateWarehouse: getWarehouseValue("after_create_warehouse"), AfterCreateWarehouse: getWarehouseValue("after_create_warehouse"),
AfterUpdateWarehouse: getWarehouseValue("after_update_warehouse"), AfterUpdateWarehouse: getWarehouseValue("after_update_warehouse"),
@ -34,4 +36,6 @@ var Warehouse = struct {
FindByCondition: getWarehouseValue("find_all_by_condition"), FindByCondition: getWarehouseValue("find_all_by_condition"),
Distinct: getWarehouseValue("distinct"), Distinct: getWarehouseValue("distinct"),
Count: getWarehouseValue("count"), Count: getWarehouseValue("count"),
CreateWarehouseIntoServiceSupplier: getWarehouseValue("create_warehouse_into_service_supplier"),
UpdateWarehouseIntoServiceSupplier: getWarehouseValue("update_warehouse_into_service_supplier"),
} }