diff --git a/client/supplier.go b/client/supplier.go index 1488a1b..d926398 100644 --- a/client/supplier.go +++ b/client/supplier.go @@ -176,3 +176,56 @@ func (s Supplier) CreateCashflow(p model.SupplierCashflowCreatePayload) (*model. } return r.Data, nil } + +func (s Supplier) UpdateBalance(p model.SupplierUpdateBalanceReq) (*model.SupplierUpdateBalanceRes, error) { + msg, err := natsio.GetServer().Request(subject.Supplier.UpdateBalance, toBytes(p)) + if err != nil { + return nil, err + } + var r struct { + Error string `json:"error"` + Data *model.SupplierUpdateBalanceRes `json:"data"` + } + 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 +} + +func (s Supplier) GetCurrentBalance(p model.SupplierGetCurrentBalanceReq) (*model.SupplierGetCurrentBalanceRes, error) { + msg, err := natsio.GetServer().Request(subject.Supplier.GetCurrentBalance, toBytes(p)) + if err != nil { + return nil, err + } + var r struct { + Error string `json:"error"` + Data *model.SupplierGetCurrentBalanceRes `json:"data"` + } + 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 +} + +func (s Supplier) DeleteCashflow(p model.SupplierDeleteCashflowReq) error { + msg, err := natsio.GetServer().Request(subject.Supplier.DeleteCashflow, 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 +} diff --git a/model/supplier_request.go b/model/supplier_request.go index 17c7266..05c374b 100644 --- a/model/supplier_request.go +++ b/model/supplier_request.go @@ -52,3 +52,15 @@ type SupplierCashflowCreatePayload struct { type SupplierFreeShipInfoRequestPayload struct { SupplierIDs []string `json:"supplierIds"` } + +type SupplierUpdateBalanceReq struct { + SupplierID string `json:"supplierId"` +} + +type SupplierGetCurrentBalanceReq struct { + SupplierID string `json:"supplierId"` +} + +type SupplierDeleteCashflowReq struct { + CashflowID string `json:"cashflowId"` +} diff --git a/model/supplier_response.go b/model/supplier_response.go index dc10c0f..655e85b 100644 --- a/model/supplier_response.go +++ b/model/supplier_response.go @@ -55,3 +55,20 @@ type SupplierShort struct { Name string `json:"name"` Logo interface{} `json:"logo"` } + +type SupplierUpdateBalanceRes struct { + CurrentCash float64 `json:"currentCash"` + TotalPendingCash float64 `json:"totalPendingCash"` + OrderPendingCash float64 `json:"orderPendingCash"` + OrderWaitingForReconcileCash float64 `json:"orderWaitingForReconcileCash"` + OrderReconciledCash float64 `json:"orderReconciledCash"` + WithdrawPendingCash float64 `json:"withdrawPendingCash"` + WithdrawSuccessCash float64 `json:"withdrawSuccessCash"` + WithdrawRejectCash float64 `json:"withdrawRejectCash"` + ChangeBalanceRequestApproved float64 `json:"changeBalanceRequestApproved"` + UpdatedAt string `json:"updatedAt"` +} + +type SupplierGetCurrentBalanceRes struct { + CurrentCash float64 `json:"currentCash"` +} diff --git a/subject/supplier.go b/subject/supplier.go index 12cc3ea..441118f 100644 --- a/subject/supplier.go +++ b/subject/supplier.go @@ -12,6 +12,9 @@ var Supplier = struct { FindAll string GetListWarehouseFreeShip string CreateCashflow string + DeleteCashflow string + UpdateBalance string + GetCurrentBalance string GetFreeShipInfo string }{ GetListSupplierInfo: getSupplierValue("get_list_supplier_info"), @@ -19,5 +22,8 @@ var Supplier = struct { FindAll: getSupplierValue("find_all"), GetListWarehouseFreeShip: getSupplierValue("get_list_warehouse_free_ship"), CreateCashflow: getSupplierValue("create_cashflow"), + DeleteCashflow: getSupplierValue("delete_cashflow"), + UpdateBalance: getSupplierValue("update_balance"), + GetCurrentBalance: getSupplierValue("get_current_balance"), GetFreeShipInfo: getSupplierValue("get_free_ship_info"), }