chore: add point pool
This commit is contained in:
@@ -867,36 +867,25 @@ func (d *Database) CalculateAndAddPointsForCommandTx(tx *sql.Tx, commandID int,
|
|||||||
settings = DefaultSettings()
|
settings = DefaultSettings()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construire les sets de catégories par pool
|
pools := settings.PointsPools
|
||||||
weedCats := make(map[string]bool)
|
if len(pools) == 0 {
|
||||||
for _, cat := range settings.PointsCategoriesWeed {
|
log.Printf("ℹ️ [CalcPointsTx] Aucun pool configuré → 0 points")
|
||||||
weedCats[strings.ToLower(cat)] = true
|
return 0, "", nil
|
||||||
}
|
|
||||||
zipetteCats := make(map[string]bool)
|
|
||||||
for _, cat := range settings.PointsCategoriesZipette {
|
|
||||||
zipetteCats[strings.ToLower(cat)] = true
|
|
||||||
}
|
|
||||||
// pool "total" → toujours compté dans le pool weed (point)
|
|
||||||
totalCats := make(map[string]bool)
|
|
||||||
for _, cat := range settings.PointsCategoriesTotal {
|
|
||||||
totalCats[strings.ToLower(cat)] = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si aucune catégorie configurée → pas de points
|
// Construire la map catégorie → index de pool
|
||||||
if !settings.PointsSeparated {
|
catToPool := make(map[string]int)
|
||||||
// Mode non-séparé : seul le pool Total est actif
|
for i, pool := range pools {
|
||||||
if len(weedCats) == 0 && len(zipetteCats) == 0 && len(totalCats) == 0 {
|
for _, cat := range pool.Categories {
|
||||||
log.Printf("ℹ️ [CalcPointsTx] Mode non-séparé : aucune catégorie configurée → 0 points")
|
catToPool[strings.ToLower(cat)] = i
|
||||||
return 0, "", nil
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Mode séparé : seuls W et Z sont actifs (T ignoré)
|
|
||||||
if len(weedCats) == 0 && len(zipetteCats) == 0 {
|
|
||||||
log.Printf("ℹ️ [CalcPointsTx] Mode séparé : aucune catégorie W/Z configurée → 0 points")
|
|
||||||
return 0, "", nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(catToPool) == 0 {
|
||||||
|
log.Printf("ℹ️ [CalcPointsTx] Aucune catégorie assignée aux pools → 0 points")
|
||||||
|
return 0, "", nil
|
||||||
|
}
|
||||||
|
|
||||||
// ✅ ÉTAPE 1: Récupérer tous les items de la commande avec leurs catégories
|
// ✅ ÉTAPE 1: Récupérer tous les items de la commande avec leurs catégories
|
||||||
rows, err := tx.Query(`
|
rows, err := tx.Query(`
|
||||||
SELECT ci.quantite, ci.prix, COALESCE(p.category, '') as category
|
SELECT ci.quantite, ci.prix, COALESCE(p.category, '') as category
|
||||||
@@ -911,9 +900,7 @@ func (d *Database) CalculateAndAddPointsForCommandTx(tx *sql.Tx, commandID int,
|
|||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
var itemCount int
|
var itemCount int
|
||||||
totalPrixWeed := 0.0
|
poolTotals := make([]float64, len(pools))
|
||||||
totalPrixZipette := 0.0
|
|
||||||
totalPrixTotal := 0.0
|
|
||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var quantite, prix float64
|
var quantite, prix float64
|
||||||
@@ -924,12 +911,8 @@ func (d *Database) CalculateAndAddPointsForCommandTx(tx *sql.Tx, commandID int,
|
|||||||
}
|
}
|
||||||
itemCount++
|
itemCount++
|
||||||
catLower := strings.ToLower(category)
|
catLower := strings.ToLower(category)
|
||||||
if weedCats[catLower] {
|
if poolIdx, ok := catToPool[catLower]; ok {
|
||||||
totalPrixWeed += prix
|
poolTotals[poolIdx] += prix
|
||||||
} else if zipetteCats[catLower] {
|
|
||||||
totalPrixZipette += prix
|
|
||||||
} else if totalCats[catLower] {
|
|
||||||
totalPrixTotal += prix
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -943,58 +926,49 @@ func (d *Database) CalculateAndAddPointsForCommandTx(tx *sql.Tx, commandID int,
|
|||||||
return 0, "", nil
|
return 0, "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("📊 [CalcPointsTx] %d items - weed: %.2f€, zipette: %.2f€, total: %.2f€",
|
for i, t := range poolTotals {
|
||||||
itemCount, totalPrixWeed, totalPrixZipette, totalPrixTotal)
|
log.Printf("📊 [CalcPointsTx] Pool[%d] (%s): %.2f€", i, pools[i].Name, t)
|
||||||
|
}
|
||||||
|
|
||||||
// ✅ ÉTAPE 2: Calculer les points
|
// ✅ ÉTAPE 2: Calculer les points par pool et mettre à jour les colonnes DB
|
||||||
|
// Pool[0] → colonne `point`, Pool[1] → colonne `point_zipette`
|
||||||
var totalPoints int
|
var totalPoints int
|
||||||
var pointCategory string
|
var pointCategory string
|
||||||
var result sql.Result
|
var result sql.Result
|
||||||
|
|
||||||
if !settings.PointsSeparated {
|
pts0 := CalcPointsFromTiers(poolTotals[0], pools[0].Tiers)
|
||||||
// ── Mode non-séparé : Barème Total appliqué sur W + Z + T ──────────────
|
pts1 := 0
|
||||||
allTotal := totalPrixWeed + totalPrixZipette + totalPrixTotal
|
if len(pools) >= 2 {
|
||||||
totalPoints = CalcPointsFromTiers(allTotal, settings.PointsTotalTiers)
|
pts1 = CalcPointsFromTiers(poolTotals[1], pools[1].Tiers)
|
||||||
pointCategory = "total"
|
}
|
||||||
|
totalPoints = pts0 + pts1
|
||||||
|
|
||||||
log.Printf("💰 [CalcPointsTx] Mode non-séparé - total: %.2f€ → %d pts (barème Total)",
|
log.Printf("💰 [CalcPointsTx] pool[0]=%d pts, pool[1]=%d pts", pts0, pts1)
|
||||||
allTotal, totalPoints)
|
|
||||||
|
|
||||||
if totalPoints == 0 {
|
if totalPoints == 0 {
|
||||||
return 0, "", nil
|
return 0, "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if pts0 > 0 && pts1 > 0 {
|
||||||
|
pointCategory = pools[0].Name + " & " + pools[1].Name
|
||||||
|
} else if pts1 > 0 {
|
||||||
|
pointCategory = pools[1].Name
|
||||||
|
} else {
|
||||||
|
pointCategory = pools[0].Name
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(pools) == 1 || pts1 == 0 {
|
||||||
result, err = tx.Exec(`
|
result, err = tx.Exec(`
|
||||||
UPDATE clients
|
UPDATE clients
|
||||||
SET point = point + $1, updated_at = CURRENT_TIMESTAMP
|
SET point = point + $1, updated_at = CURRENT_TIMESTAMP
|
||||||
WHERE username = $2
|
WHERE username = $2
|
||||||
`, totalPoints, username)
|
`, pts0, username)
|
||||||
} else {
|
} else {
|
||||||
// ── Mode séparé : Barèmes W et Z, pool T ignoré ────────────────────────
|
|
||||||
pointsWeed := CalcPointsFromTiers(totalPrixWeed, settings.PointsWeedTiers)
|
|
||||||
pointsZipette := CalcPointsFromTiers(totalPrixZipette, settings.PointsZipetteTiers)
|
|
||||||
totalPoints = pointsWeed + pointsZipette
|
|
||||||
|
|
||||||
log.Printf("💰 [CalcPointsTx] Mode séparé - weed: %d pts, zipette: %d pts",
|
|
||||||
pointsWeed, pointsZipette)
|
|
||||||
|
|
||||||
if totalPoints == 0 {
|
|
||||||
return 0, "", nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if pointsWeed > 0 && pointsZipette > 0 {
|
|
||||||
pointCategory = "mixed"
|
|
||||||
} else if pointsZipette > 0 {
|
|
||||||
pointCategory = "zipette&co"
|
|
||||||
} else {
|
|
||||||
pointCategory = "weed&hash"
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err = tx.Exec(`
|
result, err = tx.Exec(`
|
||||||
UPDATE clients
|
UPDATE clients
|
||||||
SET point = point + $1, point_zipette = point_zipette + $2, updated_at = CURRENT_TIMESTAMP
|
SET point = point + $1, point_zipette = point_zipette + $2, updated_at = CURRENT_TIMESTAMP
|
||||||
WHERE username = $3
|
WHERE username = $3
|
||||||
`, pointsWeed, pointsZipette, username)
|
`, pts0, pts1, username)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -57,48 +57,57 @@ func CalcPointsFromTiers(total float64, tiers []PointsTier) int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PointsPool représente un type de point personnalisable par l'admin
|
||||||
|
// Pool[0] → colonne `point`, Pool[1] → colonne `point_zipette`
|
||||||
|
type PointsPool struct {
|
||||||
|
Key string `json:"key"` // identifiant interne (ex: "pool_0")
|
||||||
|
Name string `json:"name"` // nom affiché (ex: "Cannabis", "Accessoires")
|
||||||
|
Categories []string `json:"categories"` // catégories de produits assignées à ce pool
|
||||||
|
Tiers []PointsTier `json:"tiers"` // barème de points
|
||||||
|
}
|
||||||
|
|
||||||
// AppSettings contient les paramètres globaux de l'application
|
// AppSettings contient les paramètres globaux de l'application
|
||||||
type AppSettings struct {
|
type AppSettings struct {
|
||||||
PenaltiesEnabled bool `json:"penalties_enabled"`
|
PenaltiesEnabled bool `json:"penalties_enabled"`
|
||||||
ShowAmendeScore bool `json:"show_amende_score"` // afficher le score d'amendes aux clients/cabine
|
ShowAmendeScore bool `json:"show_amende_score"` // afficher le score d'amendes aux clients/cabine
|
||||||
PointsEnabled bool `json:"points_enabled"` // afficher/activer le système de points
|
PointsEnabled bool `json:"points_enabled"` // afficher/activer le système de points
|
||||||
PointsCategoriesWeed []string `json:"points_categories_weed"` // catégories → pool point (weed)
|
PointsPools []PointsPool `json:"points_pools"` // types de points personnalisés
|
||||||
PointsCategoriesZipette []string `json:"points_categories_zipette"` // catégories → pool point_zipette
|
ReferralEnabled bool `json:"referral_enabled"` // activer/désactiver le système de parrainage
|
||||||
PointsCategoriesTotal []string `json:"points_categories_total"` // catégories → pool total (point, sans séparation)
|
DeliverySchedule DeliverySchedule `json:"delivery_schedule"` // horaires de livraison par jour
|
||||||
PointsSeparated bool `json:"points_separated"` // true = weed/zipette séparés, false = tout dans point
|
PostalZones []PostalZone `json:"postal_zones"` // zones de livraison avec minimum de commande
|
||||||
// Barème de points par paliers configurables
|
|
||||||
PointsWeedTiers []PointsTier `json:"points_weed_tiers"`
|
|
||||||
PointsZipetteTiers []PointsTier `json:"points_zipette_tiers"`
|
|
||||||
PointsTotalTiers []PointsTier `json:"points_total_tiers"`
|
|
||||||
ReferralEnabled bool `json:"referral_enabled"` // activer/désactiver le système de parrainage
|
|
||||||
DeliverySchedule DeliverySchedule `json:"delivery_schedule"` // horaires de livraison par jour
|
|
||||||
PostalZones []PostalZone `json:"postal_zones"` // zones de livraison avec minimum de commande
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultSettings retourne les paramètres par défaut
|
// DefaultSettings retourne les paramètres par défaut
|
||||||
func DefaultSettings() AppSettings {
|
func DefaultSettings() AppSettings {
|
||||||
return AppSettings{
|
return AppSettings{
|
||||||
PenaltiesEnabled: true,
|
PenaltiesEnabled: true,
|
||||||
ShowAmendeScore: true,
|
ShowAmendeScore: true,
|
||||||
PointsEnabled: true,
|
PointsEnabled: true,
|
||||||
ReferralEnabled: true,
|
ReferralEnabled: true,
|
||||||
PointsCategoriesWeed: []string{},
|
PointsPools: []PointsPool{
|
||||||
PointsCategoriesZipette: []string{},
|
{
|
||||||
PointsCategoriesTotal: []string{},
|
Key: "pool_0",
|
||||||
PointsSeparated: true,
|
Name: "Pool 1",
|
||||||
PointsWeedTiers: []PointsTier{
|
Categories: []string{},
|
||||||
{Min: 30, Max: 50, Points: 1},
|
Tiers: []PointsTier{
|
||||||
{Min: 60, Max: 150, Points: 2},
|
{Min: 30, Max: 50, Points: 1},
|
||||||
{Min: 160, Max: 300, Points: 3},
|
{Min: 60, Max: 150, Points: 2},
|
||||||
{Min: 310, Max: 400, Points: 5},
|
{Min: 160, Max: 300, Points: 3},
|
||||||
{Min: 401, Max: 0, Points: 10},
|
{Min: 310, Max: 400, Points: 5},
|
||||||
|
{Min: 401, Max: 0, Points: 10},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: "pool_1",
|
||||||
|
Name: "Pool 2",
|
||||||
|
Categories: []string{},
|
||||||
|
Tiers: []PointsTier{
|
||||||
|
{Min: 30, Max: 100, Points: 1},
|
||||||
|
{Min: 110, Max: 200, Points: 2},
|
||||||
|
{Min: 210, Max: 0, Points: 3},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
PointsZipetteTiers: []PointsTier{
|
|
||||||
{Min: 30, Max: 100, Points: 1},
|
|
||||||
{Min: 110, Max: 200, Points: 2},
|
|
||||||
{Min: 210, Max: 0, Points: 3},
|
|
||||||
},
|
|
||||||
PointsTotalTiers: []PointsTier{},
|
|
||||||
DeliverySchedule: DefaultDeliverySchedule(),
|
DeliverySchedule: DefaultDeliverySchedule(),
|
||||||
PostalZones: []PostalZone{
|
PostalZones: []PostalZone{
|
||||||
{Name: "Zone 30€", MinAmount: 30, Codes: []string{"44000", "44100", "44200", "44300"}},
|
{Name: "Zone 30€", MinAmount: 30, Codes: []string{"44000", "44100", "44200", "44300"}},
|
||||||
@@ -135,37 +144,10 @@ func (d *Database) GetSettings() (AppSettings, error) {
|
|||||||
settings.ShowAmendeScore = value == "true"
|
settings.ShowAmendeScore = value == "true"
|
||||||
case "points_enabled":
|
case "points_enabled":
|
||||||
settings.PointsEnabled = value == "true"
|
settings.PointsEnabled = value == "true"
|
||||||
case "points_categories_weed":
|
case "points_pools":
|
||||||
var cats []string
|
var pools []PointsPool
|
||||||
if err := json.Unmarshal([]byte(value), &cats); err == nil {
|
if err := json.Unmarshal([]byte(value), &pools); err == nil {
|
||||||
settings.PointsCategoriesWeed = cats
|
settings.PointsPools = pools
|
||||||
}
|
|
||||||
case "points_categories_zipette":
|
|
||||||
var cats []string
|
|
||||||
if err := json.Unmarshal([]byte(value), &cats); err == nil {
|
|
||||||
settings.PointsCategoriesZipette = cats
|
|
||||||
}
|
|
||||||
case "points_categories_total":
|
|
||||||
var cats []string
|
|
||||||
if err := json.Unmarshal([]byte(value), &cats); err == nil {
|
|
||||||
settings.PointsCategoriesTotal = cats
|
|
||||||
}
|
|
||||||
case "points_separated":
|
|
||||||
settings.PointsSeparated = value == "true"
|
|
||||||
case "points_weed_tiers":
|
|
||||||
var tiers []PointsTier
|
|
||||||
if err := json.Unmarshal([]byte(value), &tiers); err == nil {
|
|
||||||
settings.PointsWeedTiers = tiers
|
|
||||||
}
|
|
||||||
case "points_zipette_tiers":
|
|
||||||
var tiers []PointsTier
|
|
||||||
if err := json.Unmarshal([]byte(value), &tiers); err == nil {
|
|
||||||
settings.PointsZipetteTiers = tiers
|
|
||||||
}
|
|
||||||
case "points_total_tiers":
|
|
||||||
var tiers []PointsTier
|
|
||||||
if err := json.Unmarshal([]byte(value), &tiers); err == nil {
|
|
||||||
settings.PointsTotalTiers = tiers
|
|
||||||
}
|
}
|
||||||
case "referral_enabled":
|
case "referral_enabled":
|
||||||
settings.ReferralEnabled = value == "true"
|
settings.ReferralEnabled = value == "true"
|
||||||
@@ -192,27 +174,23 @@ func (d *Database) UpdateSettings(s AppSettings) error {
|
|||||||
}
|
}
|
||||||
return "false"
|
return "false"
|
||||||
}
|
}
|
||||||
if s.PointsCategoriesWeed == nil {
|
|
||||||
s.PointsCategoriesWeed = []string{}
|
if s.PointsPools == nil {
|
||||||
|
s.PointsPools = []PointsPool{}
|
||||||
}
|
}
|
||||||
if s.PointsCategoriesZipette == nil {
|
// S'assurer que chaque pool a des slices non-nil
|
||||||
s.PointsCategoriesZipette = []string{}
|
for i := range s.PointsPools {
|
||||||
}
|
if s.PointsPools[i].Categories == nil {
|
||||||
if s.PointsCategoriesTotal == nil {
|
s.PointsPools[i].Categories = []string{}
|
||||||
s.PointsCategoriesTotal = []string{}
|
}
|
||||||
|
if s.PointsPools[i].Tiers == nil {
|
||||||
|
s.PointsPools[i].Tiers = []PointsTier{}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
weedJSON, err := json.Marshal(s.PointsCategoriesWeed)
|
poolsJSON, err := json.Marshal(s.PointsPools)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("erreur sérialisation weed: %w", err)
|
return fmt.Errorf("erreur sérialisation pools: %w", err)
|
||||||
}
|
|
||||||
zipetteJSON, err := json.Marshal(s.PointsCategoriesZipette)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("erreur sérialisation zipette: %w", err)
|
|
||||||
}
|
|
||||||
totalJSON, err := json.Marshal(s.PointsCategoriesTotal)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("erreur sérialisation total: %w", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tx, err := d.Begin()
|
tx, err := d.Begin()
|
||||||
@@ -224,39 +202,11 @@ func (d *Database) UpdateSettings(s AppSettings) error {
|
|||||||
upsert := `INSERT INTO app_settings (key, value) VALUES ($1, $2)
|
upsert := `INSERT INTO app_settings (key, value) VALUES ($1, $2)
|
||||||
ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value`
|
ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value`
|
||||||
|
|
||||||
if s.PointsWeedTiers == nil {
|
|
||||||
s.PointsWeedTiers = []PointsTier{}
|
|
||||||
}
|
|
||||||
if s.PointsZipetteTiers == nil {
|
|
||||||
s.PointsZipetteTiers = []PointsTier{}
|
|
||||||
}
|
|
||||||
if s.PointsTotalTiers == nil {
|
|
||||||
s.PointsTotalTiers = []PointsTier{}
|
|
||||||
}
|
|
||||||
weedTiersJSON, err := json.Marshal(s.PointsWeedTiers)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("erreur sérialisation weed tiers: %w", err)
|
|
||||||
}
|
|
||||||
zipetteTiersJSON, err := json.Marshal(s.PointsZipetteTiers)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("erreur sérialisation zipette tiers: %w", err)
|
|
||||||
}
|
|
||||||
totalTiersJSON, err := json.Marshal(s.PointsTotalTiers)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("erreur sérialisation total tiers: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
pairs := [][2]string{
|
pairs := [][2]string{
|
||||||
{"penalties_enabled", boolStr(s.PenaltiesEnabled)},
|
{"penalties_enabled", boolStr(s.PenaltiesEnabled)},
|
||||||
{"show_amende_score", boolStr(s.ShowAmendeScore)},
|
{"show_amende_score", boolStr(s.ShowAmendeScore)},
|
||||||
{"points_enabled", boolStr(s.PointsEnabled)},
|
{"points_enabled", boolStr(s.PointsEnabled)},
|
||||||
{"points_categories_weed", string(weedJSON)},
|
{"points_pools", string(poolsJSON)},
|
||||||
{"points_categories_zipette", string(zipetteJSON)},
|
|
||||||
{"points_categories_total", string(totalJSON)},
|
|
||||||
{"points_separated", boolStr(s.PointsSeparated)},
|
|
||||||
{"points_weed_tiers", string(weedTiersJSON)},
|
|
||||||
{"points_zipette_tiers", string(zipetteTiersJSON)},
|
|
||||||
{"points_total_tiers", string(totalTiersJSON)},
|
|
||||||
{"referral_enabled", boolStr(s.ReferralEnabled)},
|
{"referral_enabled", boolStr(s.ReferralEnabled)},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ func GetPublicSettings(c *gin.Context) {
|
|||||||
"penalties_enabled": settings.PenaltiesEnabled,
|
"penalties_enabled": settings.PenaltiesEnabled,
|
||||||
"show_amende_score": settings.ShowAmendeScore,
|
"show_amende_score": settings.ShowAmendeScore,
|
||||||
"points_enabled": settings.PointsEnabled,
|
"points_enabled": settings.PointsEnabled,
|
||||||
"points_separated": settings.PointsSeparated,
|
"points_separated": len(settings.PointsPools) > 1,
|
||||||
"referral_enabled": settings.ReferralEnabled,
|
"referral_enabled": settings.ReferralEnabled,
|
||||||
"delivery_schedule": settings.DeliverySchedule,
|
"delivery_schedule": settings.DeliverySchedule,
|
||||||
})
|
})
|
||||||
@@ -60,8 +60,7 @@ func UpdateSettings(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("✅ [SETTINGS] Mise à jour: penalties=%v, points_separated=%v, weed=%v, zipette=%v, total=%v",
|
log.Printf("✅ [SETTINGS] Mise à jour: penalties=%v, pools=%d", req.PenaltiesEnabled, len(req.PointsPools))
|
||||||
req.PenaltiesEnabled, req.PointsSeparated, req.PointsCategoriesWeed, req.PointsCategoriesZipette, req.PointsCategoriesTotal)
|
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{"success": true, "settings": req})
|
c.JSON(http.StatusOK, gin.H{"success": true, "settings": req})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -704,6 +704,13 @@ export interface PointsTier {
|
|||||||
points: number;
|
points: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface PointsPool {
|
||||||
|
key: string;
|
||||||
|
name: string;
|
||||||
|
categories: string[];
|
||||||
|
tiers: PointsTier[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface PostalZone {
|
export interface PostalZone {
|
||||||
name: string;
|
name: string;
|
||||||
min_amount: number;
|
min_amount: number;
|
||||||
@@ -744,13 +751,7 @@ export interface AppSettings {
|
|||||||
penalties_enabled: boolean;
|
penalties_enabled: boolean;
|
||||||
show_amende_score: boolean;
|
show_amende_score: boolean;
|
||||||
points_enabled: boolean;
|
points_enabled: boolean;
|
||||||
points_categories_weed: string[];
|
points_pools: PointsPool[];
|
||||||
points_categories_zipette: string[];
|
|
||||||
points_categories_total: string[];
|
|
||||||
points_separated: boolean;
|
|
||||||
points_weed_tiers: PointsTier[];
|
|
||||||
points_zipette_tiers: PointsTier[];
|
|
||||||
points_total_tiers: PointsTier[];
|
|
||||||
referral_enabled: boolean;
|
referral_enabled: boolean;
|
||||||
delivery_schedule: DeliverySchedule;
|
delivery_schedule: DeliverySchedule;
|
||||||
postal_zones: PostalZone[];
|
postal_zones: PostalZone[];
|
||||||
|
|||||||
@@ -255,6 +255,26 @@ export default function OrdersScreen() {
|
|||||||
paddingHorizontal: spacing.l,
|
paddingHorizontal: spacing.l,
|
||||||
paddingVertical: spacing.s,
|
paddingVertical: spacing.s,
|
||||||
},
|
},
|
||||||
|
refreshRow: {
|
||||||
|
paddingHorizontal: spacing.l,
|
||||||
|
paddingBottom: spacing.s,
|
||||||
|
alignItems: "flex-start",
|
||||||
|
},
|
||||||
|
refreshBtn: {
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: spacing.xs,
|
||||||
|
paddingHorizontal: spacing.m,
|
||||||
|
paddingVertical: spacing.s,
|
||||||
|
backgroundColor: colors.bgCard,
|
||||||
|
borderRadius: borderRadius.sm,
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: colors.border,
|
||||||
|
},
|
||||||
|
refreshBtnText: {
|
||||||
|
color: colors.textSecondary,
|
||||||
|
fontSize: fontSize.sm,
|
||||||
|
},
|
||||||
filterBtn: {
|
filterBtn: {
|
||||||
paddingHorizontal: spacing.l,
|
paddingHorizontal: spacing.l,
|
||||||
paddingVertical: spacing.s,
|
paddingVertical: spacing.s,
|
||||||
@@ -620,6 +640,20 @@ export default function OrdersScreen() {
|
|||||||
style={styles.filterList}
|
style={styles.filterList}
|
||||||
showsHorizontalScrollIndicator={false}
|
showsHorizontalScrollIndicator={false}
|
||||||
/>
|
/>
|
||||||
|
<View style={styles.refreshRow}>
|
||||||
|
<TouchableOpacity
|
||||||
|
style={styles.refreshBtn}
|
||||||
|
onPress={onRefresh}
|
||||||
|
disabled={refreshing}
|
||||||
|
>
|
||||||
|
<Ionicons
|
||||||
|
name="refresh-outline"
|
||||||
|
size={16}
|
||||||
|
color={refreshing ? colors.textMuted : colors.accent}
|
||||||
|
/>
|
||||||
|
<Text style={styles.refreshBtnText}>Actualiser</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
</View>
|
||||||
<FlatList
|
<FlatList
|
||||||
data={commands}
|
data={commands}
|
||||||
keyExtractor={(item) => item.id.toString()}
|
keyExtractor={(item) => item.id.toString()}
|
||||||
@@ -637,6 +671,7 @@ export default function OrdersScreen() {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
||||||
{/* Modal items */}
|
{/* Modal items */}
|
||||||
<Modal
|
<Modal
|
||||||
visible={itemsModal.visible}
|
visible={itemsModal.visible}
|
||||||
|
|||||||
@@ -15,11 +15,11 @@ import { Ionicons } from "@expo/vector-icons";
|
|||||||
import { spacing, fontSize, borderRadius } from "../../theme";
|
import { spacing, fontSize, borderRadius } from "../../theme";
|
||||||
import { useTheme } from "../../context/ThemeContext";
|
import { useTheme } from "../../context/ThemeContext";
|
||||||
import { getSettings, updateSettings, getCategories, DEFAULT_DELIVERY_SCHEDULE, DEFAULT_POSTAL_ZONES } from "../../api/api_admin";
|
import { getSettings, updateSettings, getCategories, DEFAULT_DELIVERY_SCHEDULE, DEFAULT_POSTAL_ZONES } from "../../api/api_admin";
|
||||||
import type { AppSettings, Category, PointsTier, DaySchedule, DeliverySchedule, PostalZone } from "../../api/api_admin";
|
import type { AppSettings, Category, PointsTier, PointsPool, DaySchedule, DeliverySchedule, PostalZone } from "../../api/api_admin";
|
||||||
import AlertModal from "../../components/ui/AlertModal";
|
import AlertModal from "../../components/ui/AlertModal";
|
||||||
import { useAlert } from "../../hooks/useAlert";
|
import { useAlert } from "../../hooks/useAlert";
|
||||||
|
|
||||||
type PoolAssignment = "weed" | "zipette" | "total" | "none";
|
const POOL_COLORS = ["#10b981", "#9333ea", "#f97316", "#3b82f6", "#ef4444"];
|
||||||
|
|
||||||
const DAYS: { key: keyof DeliverySchedule; label: string }[] = [
|
const DAYS: { key: keyof DeliverySchedule; label: string }[] = [
|
||||||
{ key: "monday", label: "Lundi" },
|
{ key: "monday", label: "Lundi" },
|
||||||
@@ -634,13 +634,10 @@ export default function SettingsScreen() {
|
|||||||
penalties_enabled: true,
|
penalties_enabled: true,
|
||||||
show_amende_score: true,
|
show_amende_score: true,
|
||||||
points_enabled: true,
|
points_enabled: true,
|
||||||
points_categories_weed: [],
|
points_pools: [
|
||||||
points_categories_zipette: [],
|
{ key: "pool_0", name: "Pool 1", categories: [], tiers: [] },
|
||||||
points_categories_total: [],
|
{ key: "pool_1", name: "Pool 2", categories: [], tiers: [] },
|
||||||
points_separated: true,
|
],
|
||||||
points_weed_tiers: [],
|
|
||||||
points_zipette_tiers: [],
|
|
||||||
points_total_tiers: [],
|
|
||||||
referral_enabled: true,
|
referral_enabled: true,
|
||||||
delivery_schedule: DEFAULT_DELIVERY_SCHEDULE,
|
delivery_schedule: DEFAULT_DELIVERY_SCHEDULE,
|
||||||
postal_zones: DEFAULT_POSTAL_ZONES,
|
postal_zones: DEFAULT_POSTAL_ZONES,
|
||||||
@@ -681,10 +678,7 @@ export default function SettingsScreen() {
|
|||||||
if (settingsRes.success && settingsRes.settings) {
|
if (settingsRes.success && settingsRes.settings) {
|
||||||
setSettings({
|
setSettings({
|
||||||
...settingsRes.settings,
|
...settingsRes.settings,
|
||||||
points_categories_weed: settingsRes.settings.points_categories_weed ?? [],
|
points_pools: settingsRes.settings.points_pools ?? [],
|
||||||
points_categories_zipette: settingsRes.settings.points_categories_zipette ?? [],
|
|
||||||
points_categories_total: settingsRes.settings.points_categories_total ?? [],
|
|
||||||
points_total_tiers: settingsRes.settings.points_total_tiers ?? [],
|
|
||||||
delivery_schedule: settingsRes.settings.delivery_schedule ?? DEFAULT_DELIVERY_SCHEDULE,
|
delivery_schedule: settingsRes.settings.delivery_schedule ?? DEFAULT_DELIVERY_SCHEDULE,
|
||||||
postal_zones: settingsRes.settings.postal_zones ?? DEFAULT_POSTAL_ZONES,
|
postal_zones: settingsRes.settings.postal_zones ?? DEFAULT_POSTAL_ZONES,
|
||||||
});
|
});
|
||||||
@@ -702,22 +696,65 @@ export default function SettingsScreen() {
|
|||||||
loadData();
|
loadData();
|
||||||
}, [loadData]);
|
}, [loadData]);
|
||||||
|
|
||||||
const getPoolFor = (name: string): PoolAssignment => {
|
// Retourne l'index du pool auquel la catégorie est assignée, ou -1 si aucun
|
||||||
if ((settings.points_categories_weed ?? []).includes(name)) return "weed";
|
const getPoolIndexFor = (catName: string): number => {
|
||||||
if ((settings.points_categories_zipette ?? []).includes(name)) return "zipette";
|
const pools = settings.points_pools ?? [];
|
||||||
if ((settings.points_categories_total ?? []).includes(name)) return "total";
|
for (let i = 0; i < pools.length; i++) {
|
||||||
return "none";
|
if ((pools[i].categories ?? []).includes(catName)) return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
const setPool = (name: string, pool: PoolAssignment) => {
|
// Assigne une catégorie à un pool (ou la retire si poolIdx === -1)
|
||||||
|
const setCategoryPool = (catName: string, poolIdx: number) => {
|
||||||
setSettings((prev) => {
|
setSettings((prev) => {
|
||||||
const weed = (prev.points_categories_weed ?? []).filter((c) => c !== name);
|
const pools = (prev.points_pools ?? []).map((pool, i) => ({
|
||||||
const zipette = (prev.points_categories_zipette ?? []).filter((c) => c !== name);
|
...pool,
|
||||||
const total = (prev.points_categories_total ?? []).filter((c) => c !== name);
|
categories: (pool.categories ?? []).filter((c) => c !== catName),
|
||||||
if (pool === "weed") weed.push(name);
|
}));
|
||||||
else if (pool === "zipette") zipette.push(name);
|
if (poolIdx >= 0 && poolIdx < pools.length) {
|
||||||
else if (pool === "total") total.push(name);
|
pools[poolIdx] = {
|
||||||
return { ...prev, points_categories_weed: weed, points_categories_zipette: zipette, points_categories_total: total };
|
...pools[poolIdx],
|
||||||
|
categories: [...(pools[poolIdx].categories ?? []), catName],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return { ...prev, points_pools: pools };
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const addPool = () => {
|
||||||
|
setSettings((prev) => {
|
||||||
|
const pools = prev.points_pools ?? [];
|
||||||
|
const newKey = `pool_${Date.now()}`;
|
||||||
|
return {
|
||||||
|
...prev,
|
||||||
|
points_pools: [...pools, { key: newKey, name: `Type ${pools.length + 1}`, categories: [], tiers: [] }],
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const removePool = (poolIdx: number) => {
|
||||||
|
setSettings((prev) => {
|
||||||
|
const pools = (prev.points_pools ?? []).filter((_, i) => i !== poolIdx);
|
||||||
|
return { ...prev, points_pools: pools };
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const renamePool = (poolIdx: number, name: string) => {
|
||||||
|
setSettings((prev) => {
|
||||||
|
const pools = (prev.points_pools ?? []).map((p, i) =>
|
||||||
|
i === poolIdx ? { ...p, name } : p
|
||||||
|
);
|
||||||
|
return { ...prev, points_pools: pools };
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const updatePoolTiers = (poolIdx: number, tiers: PointsTier[]) => {
|
||||||
|
setSettings((prev) => {
|
||||||
|
const pools = (prev.points_pools ?? []).map((p, i) =>
|
||||||
|
i === poolIdx ? { ...p, tiers } : p
|
||||||
|
);
|
||||||
|
return { ...prev, points_pools: pools };
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -842,12 +879,7 @@ export default function SettingsScreen() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const WEED_COLOR = "#10b981";
|
const pools = settings.points_pools ?? [];
|
||||||
const ZIP_COLOR = "#9333ea";
|
|
||||||
const TOTAL_COLOR = "#f97316";
|
|
||||||
|
|
||||||
// Tous les chips toujours disponibles — la config reste modifiable à tout moment
|
|
||||||
const allChips: PoolAssignment[] = ["weed", "zipette", "total", "none"];
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={s.container}>
|
<View style={s.container}>
|
||||||
@@ -918,7 +950,7 @@ export default function SettingsScreen() {
|
|||||||
<View style={s.rowLeft}>
|
<View style={s.rowLeft}>
|
||||||
<Text style={s.rowLabel}>Points activés</Text>
|
<Text style={s.rowLabel}>Points activés</Text>
|
||||||
<Text style={s.rowDesc}>
|
<Text style={s.rowDesc}>
|
||||||
Les clients voient leurs scores de points et point_zipette.{"\n"}
|
Les clients voient leurs scores de points.{"\n"}
|
||||||
La cabine peut réinitialiser les points.
|
La cabine peut réinitialiser les points.
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
@@ -931,22 +963,42 @@ export default function SettingsScreen() {
|
|||||||
thumbColor="#fff"
|
thumbColor="#fff"
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
<View style={s.row}>
|
|
||||||
<View style={s.rowLeft}>
|
{/* Gestion des types de points */}
|
||||||
<Text style={s.rowLabel}>Points séparés par pool</Text>
|
<View style={{ paddingHorizontal: spacing.l, paddingBottom: spacing.m, borderTopWidth: 1, borderTopColor: colors.border, paddingTop: spacing.m }}>
|
||||||
<Text style={s.rowDesc}>
|
<Text style={[s.rowLabel, { marginBottom: spacing.s }]}>Types de points</Text>
|
||||||
Activé : barèmes Weed + Zipette utilisés séparément{"\n"}
|
<Text style={[s.rowDesc, { marginBottom: spacing.m }]}>
|
||||||
Désactivé : barème Total utilisé (catégorie T)
|
Créez vos propres types de points. Le 1er type → colonne principale, le 2e → colonne secondaire.
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
{pools.map((pool, i) => {
|
||||||
<Switch
|
const color = POOL_COLORS[i % POOL_COLORS.length];
|
||||||
value={settings.points_separated}
|
return (
|
||||||
onValueChange={(v) =>
|
<View key={pool.key} style={{ flexDirection: "row", alignItems: "center", gap: spacing.s, marginBottom: spacing.s }}>
|
||||||
setSettings((prev) => ({ ...prev, points_separated: v }))
|
<View style={[s.colorDot, { backgroundColor: color, width: 12, height: 12, borderRadius: 6 }]} />
|
||||||
}
|
<TextInput
|
||||||
trackColor={{ false: colors.border, true: colors.accent }}
|
style={[s.thresholdInput, { flex: 1 }]}
|
||||||
thumbColor="#fff"
|
value={pool.name}
|
||||||
/>
|
onChangeText={(v) => renamePool(i, v)}
|
||||||
|
placeholder={`Type ${i + 1}`}
|
||||||
|
placeholderTextColor={colors.textMuted}
|
||||||
|
/>
|
||||||
|
<TouchableOpacity onPress={() => removePool(i)}>
|
||||||
|
<Ionicons name="trash-outline" size={18} color={colors.danger} />
|
||||||
|
</TouchableOpacity>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
{pools.length < 2 && (
|
||||||
|
<TouchableOpacity
|
||||||
|
onPress={addPool}
|
||||||
|
style={{ flexDirection: "row", alignItems: "center", gap: spacing.xs, marginTop: spacing.xs }}
|
||||||
|
>
|
||||||
|
<Ionicons name="add-circle-outline" size={18} color={colors.accent} />
|
||||||
|
<Text style={{ fontSize: fontSize.sm, color: colors.accent, fontWeight: "600" }}>
|
||||||
|
Ajouter un type
|
||||||
|
</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
)}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
@@ -954,26 +1006,18 @@ export default function SettingsScreen() {
|
|||||||
<View style={s.section}>
|
<View style={s.section}>
|
||||||
<Text style={s.sectionTitle}>Attribution des catégories aux points</Text>
|
<Text style={s.sectionTitle}>Attribution des catégories aux points</Text>
|
||||||
<Text style={s.hint}>
|
<Text style={s.hint}>
|
||||||
{settings.points_separated
|
Choisissez quel type de point est attribué pour chaque catégorie de produit.{"\n"}
|
||||||
? "Mode séparé actif : W et Z utilisés pour le calcul. T ignoré."
|
Vous pouvez modifier les attributions à tout moment.
|
||||||
: "Mode non-séparé actif : T utilisé pour le calcul. W et Z ignorés."}
|
|
||||||
{"\n"}Vous pouvez modifier les attributions à tout moment.
|
|
||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
{/* Légende */}
|
{/* Légende */}
|
||||||
<View style={{ flexDirection: "row", gap: spacing.m, paddingHorizontal: spacing.l, paddingBottom: spacing.m, flexWrap: "wrap" }}>
|
<View style={{ flexDirection: "row", gap: spacing.m, paddingHorizontal: spacing.l, paddingBottom: spacing.m, flexWrap: "wrap" }}>
|
||||||
<View style={{ flexDirection: "row", alignItems: "center", gap: spacing.xs }}>
|
{pools.map((pool, i) => (
|
||||||
<View style={[s.colorDot, { backgroundColor: WEED_COLOR }]} />
|
<View key={pool.key} style={{ flexDirection: "row", alignItems: "center", gap: spacing.xs }}>
|
||||||
<Text style={{ fontSize: fontSize.sm, color: colors.textMuted }}>Weed</Text>
|
<View style={[s.colorDot, { backgroundColor: POOL_COLORS[i % POOL_COLORS.length] }]} />
|
||||||
</View>
|
<Text style={{ fontSize: fontSize.sm, color: colors.textMuted }}>{pool.name}</Text>
|
||||||
<View style={{ flexDirection: "row", alignItems: "center", gap: spacing.xs }}>
|
</View>
|
||||||
<View style={[s.colorDot, { backgroundColor: ZIP_COLOR }]} />
|
))}
|
||||||
<Text style={{ fontSize: fontSize.sm, color: colors.textMuted }}>Zipette</Text>
|
|
||||||
</View>
|
|
||||||
<View style={{ flexDirection: "row", alignItems: "center", gap: spacing.xs }}>
|
|
||||||
<View style={[s.colorDot, { backgroundColor: TOTAL_COLOR }]} />
|
|
||||||
<Text style={{ fontSize: fontSize.sm, color: colors.textMuted }}>Total</Text>
|
|
||||||
</View>
|
|
||||||
<View style={{ flexDirection: "row", alignItems: "center", gap: spacing.xs }}>
|
<View style={{ flexDirection: "row", alignItems: "center", gap: spacing.xs }}>
|
||||||
<View style={[s.colorDot, { backgroundColor: colors.border }]} />
|
<View style={[s.colorDot, { backgroundColor: colors.border }]} />
|
||||||
<Text style={{ fontSize: fontSize.sm, color: colors.textMuted }}>Aucun</Text>
|
<Text style={{ fontSize: fontSize.sm, color: colors.textMuted }}>Aucun</Text>
|
||||||
@@ -981,7 +1025,7 @@ export default function SettingsScreen() {
|
|||||||
</View>
|
</View>
|
||||||
|
|
||||||
{categories.map((cat, index) => {
|
{categories.map((cat, index) => {
|
||||||
const pool = getPoolFor(cat.name);
|
const assignedPoolIdx = getPoolIndexFor(cat.name);
|
||||||
return (
|
return (
|
||||||
<View
|
<View
|
||||||
key={cat.id}
|
key={cat.id}
|
||||||
@@ -995,53 +1039,43 @@ export default function SettingsScreen() {
|
|||||||
/>
|
/>
|
||||||
<Text style={s.catName}>{cat.name}</Text>
|
<Text style={s.catName}>{cat.name}</Text>
|
||||||
<View style={s.chips}>
|
<View style={s.chips}>
|
||||||
{allChips.map((p) => {
|
{pools.map((pool, pi) => {
|
||||||
const active = pool === p;
|
const active = assignedPoolIdx === pi;
|
||||||
const chipColor =
|
const chipColor = POOL_COLORS[pi % POOL_COLORS.length];
|
||||||
p === "weed"
|
const label = pool.name.slice(0, 2).toUpperCase();
|
||||||
? WEED_COLOR
|
return (
|
||||||
: p === "zipette"
|
<TouchableOpacity
|
||||||
? ZIP_COLOR
|
key={pool.key}
|
||||||
: p === "total"
|
style={[
|
||||||
? TOTAL_COLOR
|
s.chip,
|
||||||
: colors.textMuted;
|
{
|
||||||
const label =
|
borderColor: chipColor,
|
||||||
p === "weed"
|
backgroundColor: active ? chipColor : "transparent",
|
||||||
? "W"
|
},
|
||||||
: p === "zipette"
|
]}
|
||||||
? "Z"
|
onPress={() => setCategoryPool(cat.name, active ? -1 : pi)}
|
||||||
: p === "total"
|
>
|
||||||
? "T"
|
<Text style={[s.chipText, { color: active ? "#fff" : chipColor }]}>
|
||||||
: "—";
|
{label}
|
||||||
return (
|
</Text>
|
||||||
<TouchableOpacity
|
</TouchableOpacity>
|
||||||
key={p}
|
);
|
||||||
style={[
|
})}
|
||||||
s.chip,
|
{/* Chip "Aucun" */}
|
||||||
{
|
<TouchableOpacity
|
||||||
borderColor: chipColor,
|
style={[
|
||||||
backgroundColor: active
|
s.chip,
|
||||||
? chipColor
|
{
|
||||||
: "transparent",
|
borderColor: colors.textMuted,
|
||||||
},
|
backgroundColor: assignedPoolIdx === -1 ? colors.textMuted : "transparent",
|
||||||
]}
|
},
|
||||||
onPress={() => setPool(cat.name, p)}
|
]}
|
||||||
>
|
onPress={() => setCategoryPool(cat.name, -1)}
|
||||||
<Text
|
>
|
||||||
style={[
|
<Text style={[s.chipText, { color: assignedPoolIdx === -1 ? "#fff" : colors.textMuted }]}>
|
||||||
s.chipText,
|
—
|
||||||
{
|
</Text>
|
||||||
color: active
|
</TouchableOpacity>
|
||||||
? "#fff"
|
|
||||||
: chipColor,
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
{label}
|
|
||||||
</Text>
|
|
||||||
</TouchableOpacity>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
@@ -1052,36 +1086,26 @@ export default function SettingsScreen() {
|
|||||||
Aucune catégorie disponible
|
Aucune catégorie disponible
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
|
{pools.length === 0 && categories.length > 0 && (
|
||||||
|
<Text style={[s.hint, { paddingTop: 0 }]}>
|
||||||
|
Ajoutez au moins un type de point pour assigner des catégories.
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
{/* Barèmes de points — toujours présents */}
|
{/* Barèmes de points — un par pool */}
|
||||||
<TiersSection
|
{pools.map((pool, i) => (
|
||||||
title="Barème Weed / Hash"
|
<TiersSection
|
||||||
tiers={settings.points_weed_tiers ?? []}
|
key={pool.key}
|
||||||
onChange={(tiers) => setSettings((p) => ({ ...p, points_weed_tiers: tiers }))}
|
title={`Barème — ${pool.name}`}
|
||||||
colors={colors}
|
tiers={pool.tiers ?? []}
|
||||||
s={s}
|
onChange={(tiers) => updatePoolTiers(i, tiers)}
|
||||||
accentColor={WEED_COLOR}
|
colors={colors}
|
||||||
active={settings.points_separated}
|
s={s}
|
||||||
/>
|
accentColor={POOL_COLORS[i % POOL_COLORS.length]}
|
||||||
<TiersSection
|
active={true}
|
||||||
title="Barème Zipette"
|
/>
|
||||||
tiers={settings.points_zipette_tiers ?? []}
|
))}
|
||||||
onChange={(tiers) => setSettings((p) => ({ ...p, points_zipette_tiers: tiers }))}
|
|
||||||
colors={colors}
|
|
||||||
s={s}
|
|
||||||
accentColor={ZIP_COLOR}
|
|
||||||
active={settings.points_separated}
|
|
||||||
/>
|
|
||||||
<TiersSection
|
|
||||||
title="Barème Total"
|
|
||||||
tiers={settings.points_total_tiers ?? []}
|
|
||||||
onChange={(tiers) => setSettings((p) => ({ ...p, points_total_tiers: tiers }))}
|
|
||||||
colors={colors}
|
|
||||||
s={s}
|
|
||||||
accentColor={TOTAL_COLOR}
|
|
||||||
active={!settings.points_separated}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Horaires de livraison */}
|
{/* Horaires de livraison */}
|
||||||
<DeliveryScheduleSection
|
<DeliveryScheduleSection
|
||||||
|
|||||||
@@ -226,6 +226,27 @@ export default function OrdersScreen() {
|
|||||||
() =>
|
() =>
|
||||||
StyleSheet.create({
|
StyleSheet.create({
|
||||||
container: { flex: 1, backgroundColor: colors.bgPrimary },
|
container: { flex: 1, backgroundColor: colors.bgPrimary },
|
||||||
|
refreshRow: {
|
||||||
|
paddingHorizontal: spacing.l,
|
||||||
|
paddingTop: spacing.m,
|
||||||
|
paddingBottom: spacing.s,
|
||||||
|
alignItems: "flex-start",
|
||||||
|
},
|
||||||
|
refreshBtn: {
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: spacing.xs,
|
||||||
|
paddingHorizontal: spacing.m,
|
||||||
|
paddingVertical: spacing.s,
|
||||||
|
backgroundColor: colors.bgCard,
|
||||||
|
borderRadius: borderRadius.sm,
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: colors.border,
|
||||||
|
},
|
||||||
|
refreshBtnText: {
|
||||||
|
color: colors.textSecondary,
|
||||||
|
fontSize: fontSize.sm,
|
||||||
|
},
|
||||||
row: {
|
row: {
|
||||||
flexDirection: "row",
|
flexDirection: "row",
|
||||||
justifyContent: "space-between",
|
justifyContent: "space-between",
|
||||||
@@ -525,6 +546,20 @@ export default function OrdersScreen() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
|
<View style={styles.refreshRow}>
|
||||||
|
<TouchableOpacity
|
||||||
|
style={styles.refreshBtn}
|
||||||
|
onPress={onRefresh}
|
||||||
|
disabled={refreshing}
|
||||||
|
>
|
||||||
|
<Ionicons
|
||||||
|
name="refresh-outline"
|
||||||
|
size={16}
|
||||||
|
color={refreshing ? colors.textMuted : colors.accent}
|
||||||
|
/>
|
||||||
|
<Text style={styles.refreshBtnText}>Actualiser</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
</View>
|
||||||
<FlatList
|
<FlatList
|
||||||
data={commands}
|
data={commands}
|
||||||
keyExtractor={(item) => item.id.toString()}
|
keyExtractor={(item) => item.id.toString()}
|
||||||
|
|||||||
@@ -1671,12 +1671,6 @@ export default function DashboardScreen() {
|
|||||||
/>
|
/>
|
||||||
{" "}Client
|
{" "}Client
|
||||||
</Text>
|
</Text>
|
||||||
<View style={styles.detailRow}>
|
|
||||||
<Text style={styles.detailLabel}>Pseudo</Text>
|
|
||||||
<Text style={styles.detailValue}>
|
|
||||||
{detailsDelivery?.clientUsername || "—"}
|
|
||||||
</Text>
|
|
||||||
</View>
|
|
||||||
<View style={styles.detailRow}>
|
<View style={styles.detailRow}>
|
||||||
<Text style={styles.detailLabel}>Prénom</Text>
|
<Text style={styles.detailLabel}>Prénom</Text>
|
||||||
<Text style={styles.detailValue}>
|
<Text style={styles.detailValue}>
|
||||||
|
|||||||
@@ -634,6 +634,7 @@ export const getCommandItemsWithDetails = async (commandId: number) => {
|
|||||||
export const formatOrderDate = (dateString: string): string => {
|
export const formatOrderDate = (dateString: string): string => {
|
||||||
try {
|
try {
|
||||||
const date = new Date(dateString);
|
const date = new Date(dateString);
|
||||||
|
if (isNaN(date.getTime())) return "";
|
||||||
return date.toLocaleDateString("fr-FR", {
|
return date.toLocaleDateString("fr-FR", {
|
||||||
day: "2-digit",
|
day: "2-digit",
|
||||||
month: "long",
|
month: "long",
|
||||||
@@ -642,7 +643,7 @@ export const formatOrderDate = (dateString: string): string => {
|
|||||||
minute: "2-digit",
|
minute: "2-digit",
|
||||||
});
|
});
|
||||||
} catch {
|
} catch {
|
||||||
return dateString;
|
return "";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -129,11 +129,12 @@ export default function OrderTrackingScreen() {
|
|||||||
try {
|
try {
|
||||||
const res = await confirmReception(orderId);
|
const res = await confirmReception(orderId);
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
const cat = res.category || '';
|
const cat = res.category || "";
|
||||||
let catLabel = '';
|
let catLabel = "";
|
||||||
if (cat === 'total') catLabel = ' (Total)';
|
if (cat === "total") catLabel = " (Total)";
|
||||||
else if (cat.includes('zipette')) catLabel = ' (Zipette&Co)';
|
else if (cat.includes("zipette")) catLabel = " (Zipette&Co)";
|
||||||
else if (cat.includes('weed') || cat.includes('hash')) catLabel = ' (Weed&Hash)';
|
else if (cat.includes("weed") || cat.includes("hash"))
|
||||||
|
catLabel = " (Weed&Hash)";
|
||||||
showToast(
|
showToast(
|
||||||
`Livraison confirmee ! +${res.points_earned || 0} points${catLabel}`,
|
`Livraison confirmee ! +${res.points_earned || 0} points${catLabel}`,
|
||||||
"success",
|
"success",
|
||||||
@@ -456,46 +457,71 @@ export default function OrderTrackingScreen() {
|
|||||||
color={colors.textMuted}
|
color={colors.textMuted}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
{order.address_proposal_status === "pending" && order.proposed_address && (
|
{order.address_proposal_status === "pending" &&
|
||||||
<View style={styles.proposalBox}>
|
order.proposed_address && (
|
||||||
<Text style={styles.proposalTitle}>
|
<View style={styles.proposalBox}>
|
||||||
📍 Nouvelle adresse proposée
|
<Text style={styles.proposalTitle}>
|
||||||
</Text>
|
📍 Nouvelle adresse proposée
|
||||||
<Text style={styles.proposalAddress}>
|
</Text>
|
||||||
{order.proposed_address}
|
<Text
|
||||||
</Text>
|
style={styles.proposalAddress}
|
||||||
<View style={styles.proposalActions}>
|
>
|
||||||
<Button
|
{order.proposed_address}
|
||||||
title="Accepter"
|
</Text>
|
||||||
variant="success"
|
<View
|
||||||
size="sm"
|
style={styles.proposalActions}
|
||||||
onPress={async () => {
|
>
|
||||||
const res = await respondToAddressProposal(order.id, true);
|
<Button
|
||||||
if (res.success) {
|
title="Accepter"
|
||||||
showToast("Adresse acceptée", "success");
|
variant="success"
|
||||||
fetchOrders();
|
size="sm"
|
||||||
} else {
|
onPress={async () => {
|
||||||
showToast(res.message, "error");
|
const res =
|
||||||
}
|
await respondToAddressProposal(
|
||||||
}}
|
order.id,
|
||||||
/>
|
true,
|
||||||
<Button
|
);
|
||||||
title="Refuser"
|
if (res.success) {
|
||||||
variant="danger"
|
showToast(
|
||||||
size="sm"
|
"Adresse acceptée",
|
||||||
onPress={async () => {
|
"success",
|
||||||
const res = await respondToAddressProposal(order.id, false);
|
);
|
||||||
if (res.success) {
|
fetchOrders();
|
||||||
showToast("Adresse refusée", "info");
|
} else {
|
||||||
fetchOrders();
|
showToast(
|
||||||
} else {
|
res.message,
|
||||||
showToast(res.message, "error");
|
"error",
|
||||||
}
|
);
|
||||||
}}
|
}
|
||||||
/>
|
}}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
title="Refuser"
|
||||||
|
variant="danger"
|
||||||
|
size="sm"
|
||||||
|
onPress={async () => {
|
||||||
|
const res =
|
||||||
|
await respondToAddressProposal(
|
||||||
|
order.id,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
if (res.success) {
|
||||||
|
showToast(
|
||||||
|
"Adresse refusée",
|
||||||
|
"info",
|
||||||
|
);
|
||||||
|
fetchOrders();
|
||||||
|
} else {
|
||||||
|
showToast(
|
||||||
|
res.message,
|
||||||
|
"error",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
)}
|
||||||
)}
|
|
||||||
{expanded && (
|
{expanded && (
|
||||||
<View style={styles.expandedSection}>
|
<View style={styles.expandedSection}>
|
||||||
{track?.livreur_username && (
|
{track?.livreur_username && (
|
||||||
@@ -511,23 +537,26 @@ export default function OrderTrackingScreen() {
|
|||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
{eta?.eta_minutes != null &&
|
{(order.status === "en_route" ||
|
||||||
eta.eta_minutes > 0 && (
|
order.status === "arrived") && (
|
||||||
<View style={styles.trackRow}>
|
<View style={styles.trackRow}>
|
||||||
<Ionicons
|
<Ionicons
|
||||||
name="timer-outline"
|
name="timer-outline"
|
||||||
size={16}
|
size={16}
|
||||||
color={colors.warning}
|
color={colors.warning}
|
||||||
/>
|
/>
|
||||||
<Text
|
<Text style={styles.trackText}>
|
||||||
style={styles.trackText}
|
Temps de livraison estimé :
|
||||||
>
|
~
|
||||||
Temps de livraison
|
{eta?.eta_minutes != null &&
|
||||||
estimé : ~
|
eta.eta_minutes > 0 &&
|
||||||
{eta.eta_minutes} min
|
eta.eta_minutes < 5
|
||||||
</Text>
|
? eta.eta_minutes
|
||||||
</View>
|
: 5}{" "}
|
||||||
)}
|
min
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
{track?.current_step && (
|
{track?.current_step && (
|
||||||
<View style={styles.trackRow}>
|
<View style={styles.trackRow}>
|
||||||
<Ionicons
|
<Ionicons
|
||||||
|
|||||||
Reference in New Issue
Block a user