Mhamdans17 commited on
Commit
2796e25
·
1 Parent(s): 77568d0

feat: include branch name in point history reason

Browse files
controllers/member_controller.go CHANGED
@@ -149,11 +149,19 @@ func SetPoints(c *gin.Context) {
149
  }
150
 
151
  if delta != 0 {
 
 
 
 
 
 
 
 
152
  history := models.PointHistory{
153
  CompanyID: companyID,
154
  MemberID: member.ID,
155
  PointsDelta: delta,
156
- Reason: "Penyesuaian manual oleh " + user.Name,
157
  }
158
  config.DB.Create(&history)
159
  }
 
149
  }
150
 
151
  if delta != 0 {
152
+ var branch models.Branch
153
+ branchName := "Pusat"
154
+ if user.BranchID != nil {
155
+ if err := config.DB.First(&branch, *user.BranchID).Error; err == nil {
156
+ branchName = branch.Name
157
+ }
158
+ }
159
+
160
  history := models.PointHistory{
161
  CompanyID: companyID,
162
  MemberID: member.ID,
163
  PointsDelta: delta,
164
+ Reason: "Penyesuaian manual oleh " + user.Name + " (Cabang " + branchName + ")",
165
  }
166
  config.DB.Create(&history)
167
  }
controllers/order_controller.go CHANGED
@@ -981,11 +981,19 @@ func awardPoints(tx *gorm.DB, order *models.Order, company *models.Company) {
981
  order.Member = &member
982
  tx.Save(order)
983
 
 
 
 
 
 
 
 
 
984
  history := models.PointHistory{
985
  CompanyID: company.ID,
986
  MemberID: member.ID,
987
  PointsDelta: pointsToAdd,
988
- Reason: "Poin dari transaksi " + order.OrderNumber,
989
  }
990
  tx.Create(&history)
991
 
 
981
  order.Member = &member
982
  tx.Save(order)
983
 
984
+ var branch models.Branch
985
+ branchName := "Pusat"
986
+ if order.BranchID != nil {
987
+ if err := tx.First(&branch, *order.BranchID).Error; err == nil {
988
+ branchName = branch.Name
989
+ }
990
+ }
991
+
992
  history := models.PointHistory{
993
  CompanyID: company.ID,
994
  MemberID: member.ID,
995
  PointsDelta: pointsToAdd,
996
+ Reason: "Poin dari transaksi " + order.OrderNumber + " (Cabang " + branchName + ")",
997
  }
998
  tx.Create(&history)
999