feat: add CSV export for approved orders && add non-delivery reason modal for livreurs
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/csv"
|
||||
"fmt"
|
||||
"gestion/db"
|
||||
"gestion/utils"
|
||||
@@ -259,6 +261,47 @@ func RespondToAddressProposal(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
func ExportApprovedCommandsCSV(c *gin.Context) {
|
||||
database := c.MustGet("database").(*db.Database)
|
||||
|
||||
commands, err := database.GetApprovedCommands()
|
||||
if err != nil {
|
||||
log.Printf("❌ [EXPORT_CSV] Erreur: %v", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Erreur export CSV"})
|
||||
return
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
w := csv.NewWriter(&buf)
|
||||
|
||||
_ = w.Write([]string{
|
||||
"ID", "Client Order ID", "User ID", "Username",
|
||||
"Statut", "Total (€)", "Adresse", "Livreur",
|
||||
"Créé le", "Mis à jour le",
|
||||
})
|
||||
|
||||
for _, cmd := range commands {
|
||||
_ = w.Write([]string{
|
||||
strconv.Itoa(cmd.ID),
|
||||
strconv.Itoa(cmd.ClientOrderID),
|
||||
strconv.Itoa(cmd.UserID),
|
||||
cmd.Username,
|
||||
cmd.Status,
|
||||
strconv.FormatFloat(cmd.Total, 'f', 2, 64),
|
||||
cmd.DeliveryAddress,
|
||||
cmd.LivreurAssign,
|
||||
cmd.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
cmd.UpdatedAt.Format("2006-01-02 15:04:05"),
|
||||
})
|
||||
}
|
||||
w.Flush()
|
||||
|
||||
filename := fmt.Sprintf("commandes_approved_%s.csv", time.Now().Format("2006-01-02"))
|
||||
c.Header("Content-Type", "text/csv; charset=utf-8")
|
||||
c.Header("Content-Disposition", "attachment; filename="+filename)
|
||||
c.String(http.StatusOK, buf.String())
|
||||
}
|
||||
|
||||
func GetAllCommands(c *gin.Context) {
|
||||
database := c.MustGet("database").(*db.Database)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user