Additional display value in card : GWM

This commit is contained in:
Gowtham M 2025-02-20 11:43:50 +05:30
parent f8135bfb8f
commit 932ff77bd1
4 changed files with 39 additions and 10 deletions

View File

@ -1899,7 +1899,7 @@ func sendStatusChangeEmail(app *pocketbase.PocketBase, record *models.Record, ne
body = fmt.Sprintf(`
<p>Dear %s,</p>
<p>We are pleased to inform you that your registration with FCSC has been approved. You can now log in using the credentials that you had created.</p>
<p>Please access your account using the following link: <a href="http://your-login-url.com">"Access Your Account</a>.</p>
<p>Please access your account using the following link: <a href="http://your-login-url.com"> Access Your Account</a>.</p>
<p>If you have any questions, please feel free to contact us for further clarification.</p>
</br>
<p>Best regards,</p>

Binary file not shown.

Binary file not shown.

View File

@ -20,12 +20,13 @@ type Observation struct {
// ------------------------------------------------------------ card calculation---------------------------------------------------
type CardCalculationRequest struct {
Formula string `json:"formula"`
RecordCount string `json:"record_count"`
RecodeIndex string `json:"record_index"`
RecordKey string `json:"record_key"`
NumberFormat string `json:"number_format"`
Conversion string `json:"conversion"`
Formula string `json:"formula"`
RecordCount string `json:"record_count"`
RecodeIndex string `json:"record_index"`
RecordKey string `json:"record_key"`
AdditionalRecordKey string `json:"additional_record_key"`
NumberFormat string `json:"number_format"`
Conversion string `json:"conversion"`
}
func CardCalculation(data []Observation, req CardCalculationRequest) (map[string]string, error) {
@ -76,11 +77,31 @@ func CardCalculation(data []Observation, req CardCalculationRequest) (map[string
}
convertedValue := applyConversion(result, req.Conversion, req.NumberFormat)
displayValue := extractRecordKeyValue(selectedData, req.RecordKey, req.Formula, result)
fmt.Println("AdditionalRecordKey:", req.AdditionalRecordKey)
displayValue := extractRecordKeyValue(selectedData, req.RecordKey, req.AdditionalRecordKey, req.Formula, result)
color := ""
if req.Formula == "different" {
// Remove the percentage sign if present
convertedValueStr := strings.TrimSuffix(convertedValue, "%")
// Convert to float
convertedValue, err := strconv.ParseFloat(convertedValueStr, 64)
if err != nil {
return nil, err // Handle error if conversion fails
}
if convertedValue > 0 {
color = "#11AF22"
} else if convertedValue < 0 {
color = "#D83731"
}
}
return map[string]string{
"value": convertedValue,
"display_value": displayValue,
"calculation": req.Formula,
"font_color": color,
}, nil
}
@ -237,7 +258,7 @@ func applyConversion(value float64, conversion string, numberFormat string) stri
}
}
func extractRecordKeyValue(data []Observation, key string, formula string, targetValue float64) string {
func extractRecordKeyValue(data []Observation, key string, additionalkey string, formula string, targetValue float64) string {
if len(data) == 0 {
return ""
}
@ -248,10 +269,18 @@ func extractRecordKeyValue(data []Observation, key string, formula string, targe
value, err := obs.ObsValue.Value.Float64()
if err == nil && value == targetValue {
if val, exists := obs.ObsKey[key]; exists {
return val
fmt.Println("additionalkey:", additionalkey)
// Check if additionalkey exists in obs.ObsKey
if val2, exists2 := obs.ObsKey[additionalkey]; exists2 {
fmt.Println("val2:", val2)
return val + " - " + val2
} else {
return val
}
}
}
}
case "total", "average", "different":
if val1, exists1 := data[0].ObsKey[key]; exists1 {
if val2, exists2 := data[len(data)-1].ObsKey[key]; exists2 {