Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -15,12 +15,23 @@ import (
|
||||
)
|
||||
|
||||
type sendOrderMarketMailPayload struct {
|
||||
OrderHeaderID string `json:"orderHeaderID"`
|
||||
Operation string `json:"operation"`
|
||||
DeletedItems []string `json:"deletedItems"`
|
||||
UpdatedItems []string `json:"updatedItems"`
|
||||
AddedItems []string `json:"addedItems"`
|
||||
ExtraRecipients []string `json:"extraRecipients"`
|
||||
OrderHeaderID string `json:"orderHeaderID"`
|
||||
Operation string `json:"operation"`
|
||||
DeletedItems []string `json:"deletedItems"`
|
||||
UpdatedItems []string `json:"updatedItems"`
|
||||
AddedItems []string `json:"addedItems"`
|
||||
OldDueDate string `json:"oldDueDate"`
|
||||
NewDueDate string `json:"newDueDate"`
|
||||
ExtraRecipients []string `json:"extraRecipients"`
|
||||
DueDateChanges []sendOrderMailDueDateChange `json:"dueDateChanges"`
|
||||
}
|
||||
|
||||
type sendOrderMailDueDateChange struct {
|
||||
ItemCode string `json:"itemCode"`
|
||||
ColorCode string `json:"colorCode"`
|
||||
ItemDim2Code string `json:"itemDim2Code"`
|
||||
OldDueDate string `json:"oldDueDate"`
|
||||
NewDueDate string `json:"newDueDate"`
|
||||
}
|
||||
|
||||
func SendOrderMarketMailHandler(pg *sql.DB, mssql *sql.DB, ml *mailer.GraphMailer) http.HandlerFunc {
|
||||
@@ -108,6 +119,18 @@ func SendOrderMarketMailHandler(pg *sql.DB, mssql *sql.DB, ml *mailer.GraphMaile
|
||||
if isUpdate {
|
||||
subjectAction = "SİPARİŞ GÜNCELLENDİ."
|
||||
}
|
||||
if payload.NewDueDate != "" && payload.OldDueDate != payload.NewDueDate {
|
||||
subjectAction = "SİPARİŞ TERMİNİ GÜNCELLENDİ."
|
||||
}
|
||||
if isUpdate && subjectAction == "SİPARİŞ GÜNCELLENDİ." {
|
||||
// Satır bazlı termin kontrolü
|
||||
for _, item := range payload.UpdatedItems {
|
||||
if strings.Contains(item, "Termin:") {
|
||||
subjectAction = "SİPARİŞ TERMİNİ GÜNCELLENDİ."
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
subject := fmt.Sprintf("%s kullanıcısı tarafından %s %s", actor, number, subjectAction)
|
||||
|
||||
cariDetail := ""
|
||||
@@ -127,6 +150,13 @@ func SendOrderMarketMailHandler(pg *sql.DB, mssql *sql.DB, ml *mailer.GraphMaile
|
||||
`</p>`,
|
||||
)
|
||||
|
||||
if payload.NewDueDate != "" && payload.OldDueDate != payload.NewDueDate {
|
||||
body = append(body,
|
||||
fmt.Sprintf(`<p><b>Termin Değişikliği:</b> %s → <b style="color:red">%s</b></p>`,
|
||||
htmlEsc(payload.OldDueDate), htmlEsc(payload.NewDueDate)),
|
||||
)
|
||||
}
|
||||
|
||||
if isUpdate {
|
||||
body = append(body,
|
||||
renderItemListHTML("Silinen Ürün Kodları", payload.DeletedItems),
|
||||
@@ -137,6 +167,10 @@ func SendOrderMarketMailHandler(pg *sql.DB, mssql *sql.DB, ml *mailer.GraphMaile
|
||||
|
||||
body = append(body, `<p><i>Bu sipariş BaggiSS App Uygulamasından oluşturulmuştur.</i></p>`)
|
||||
body = append(body, `<p>PDF ektedir.</p>`)
|
||||
if dueDateTableHTML := renderDueDateChangesTableHTML("Termin DeÄŸiÅŸiklikleri", payload.DueDateChanges); dueDateTableHTML != "" {
|
||||
body = append(body, dueDateTableHTML)
|
||||
}
|
||||
|
||||
bodyHTML := strings.Join(body, "\n")
|
||||
|
||||
fileNo := sanitizeFileName(number)
|
||||
@@ -393,3 +427,54 @@ func renderItemListHTML(title string, items []string) string {
|
||||
b = append(b, `</p>`)
|
||||
return strings.Join(b, "\n")
|
||||
}
|
||||
|
||||
func renderDueDateChangesTableHTML(title string, rows []sendOrderMailDueDateChange) string {
|
||||
if len(rows) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
seen := make(map[string]struct{}, len(rows))
|
||||
clean := make([]sendOrderMailDueDateChange, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
itemCode := strings.TrimSpace(row.ItemCode)
|
||||
colorCode := strings.TrimSpace(row.ColorCode)
|
||||
itemDim2Code := strings.TrimSpace(row.ItemDim2Code)
|
||||
oldDueDate := strings.TrimSpace(row.OldDueDate)
|
||||
newDueDate := strings.TrimSpace(row.NewDueDate)
|
||||
if itemCode == "" || newDueDate == "" || oldDueDate == newDueDate {
|
||||
continue
|
||||
}
|
||||
key := strings.ToUpper(strings.Join([]string{itemCode, colorCode, itemDim2Code, oldDueDate, newDueDate}, "|"))
|
||||
if _, ok := seen[key]; ok {
|
||||
continue
|
||||
}
|
||||
seen[key] = struct{}{}
|
||||
clean = append(clean, sendOrderMailDueDateChange{
|
||||
ItemCode: itemCode,
|
||||
ColorCode: colorCode,
|
||||
ItemDim2Code: itemDim2Code,
|
||||
OldDueDate: oldDueDate,
|
||||
NewDueDate: newDueDate,
|
||||
})
|
||||
}
|
||||
|
||||
if len(clean) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
var b strings.Builder
|
||||
b.WriteString(fmt.Sprintf(`<p><b>%s:</b></p>`, htmlEsc(title)))
|
||||
b.WriteString(`<table border="1" cellpadding="5" style="border-collapse: collapse; width: 100%;">`)
|
||||
b.WriteString(`<tr style="background-color: #f2f2f2;"><th>Ürün Kodu</th><th>Renk</th><th>2. Renk</th><th>Eski Termin</th><th>Yeni Termin</th></tr>`)
|
||||
for _, row := range clean {
|
||||
b.WriteString("<tr>")
|
||||
b.WriteString(fmt.Sprintf("<td>%s</td>", htmlEsc(row.ItemCode)))
|
||||
b.WriteString(fmt.Sprintf("<td>%s</td>", htmlEsc(row.ColorCode)))
|
||||
b.WriteString(fmt.Sprintf("<td>%s</td>", htmlEsc(row.ItemDim2Code)))
|
||||
b.WriteString(fmt.Sprintf("<td>%s</td>", htmlEsc(row.OldDueDate)))
|
||||
b.WriteString(fmt.Sprintf(`<td style="color:red;font-weight:bold;">%s</td>`, htmlEsc(row.NewDueDate)))
|
||||
b.WriteString("</tr>")
|
||||
}
|
||||
b.WriteString(`</table>`)
|
||||
return b.String()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user