++ fix statistiche campagne
- Dettaglio campagna: mostra tutti i territori conteggiati (stessa base della percentuale), non solo quelli assegnati dopo l'inizio. - Rientro: se più campagne corrispondono propone la più recente invece della prima creata; testo del banner chiarito. - Dettaglio campagna: nuova sezione "In corso" con i territori fuori durante la campagna e non ancora rientrati. - README: regola di conteggio documentata. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -18,16 +18,27 @@ class CampagnaShow extends Component
|
||||
|
||||
public function render()
|
||||
{
|
||||
// Assignments counted for this campaign:
|
||||
// - assigned on or after campaign start
|
||||
// - linked to this campaign (campaign_id), regardless of returned_at (retroactive returns allowed)
|
||||
$conteggiate = Assegnazione::where('campaign_id', $this->campagna->id)
|
||||
->where('counted_in_campaign', true)
|
||||
->where('assigned_at', '>=', $this->campagna->start_date)
|
||||
// Assignments counted for this campaign: linked via campaign_id and
|
||||
// flagged as counted — the same set used by the percentage
|
||||
// (Campagna::percentuale_percorrenza). Which campaign is offered on
|
||||
// return is decided by Assegnazione::campagnaApplicabile().
|
||||
$conteggiate = $this->campagna->assegnazioniConteggiate()
|
||||
->with(['territorio', 'proclamatore'])
|
||||
->orderBy('returned_at')
|
||||
->get();
|
||||
|
||||
// Open assignments can still be counted for this campaign only while
|
||||
// no later campaign has started: on return the most recent one is
|
||||
// offered (see Assegnazione::campagnaApplicabile()).
|
||||
$superata = Campagna::where('start_date', '>', $this->campagna->start_date)
|
||||
->where('start_date', '<=', now()->toDateString())
|
||||
->exists();
|
||||
|
||||
$inCorso = $superata ? null : $this->campagna->assegnazioniInCorso()
|
||||
->with(['territorio', 'proclamatore'])
|
||||
->orderBy('assigned_at')
|
||||
->get();
|
||||
|
||||
// All assignments that were active during this campaign range
|
||||
$assegnateNelRange = Assegnazione::where('assigned_at', '<=', $this->campagna->end_date)
|
||||
->where(function ($q) {
|
||||
@@ -38,6 +49,7 @@ class CampagnaShow extends Component
|
||||
|
||||
return view('livewire.campagne.campagna-show', [
|
||||
'conteggiate' => $conteggiate,
|
||||
'inCorso' => $inCorso,
|
||||
'assegnateNelRange' => $assegnateNelRange,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -203,10 +203,18 @@ class Assegnazione extends Model
|
||||
*/
|
||||
public function campagnaApplicabile(?\Carbon\Carbon $returnDate = null): ?Campagna
|
||||
{
|
||||
$returnDate = $returnDate ?? now();
|
||||
$returnDate = ($returnDate ?? now())->toDateString();
|
||||
$assignedAt = $this->assigned_at->toDateString();
|
||||
|
||||
// Il territorio può essere conteggiato per una campagna se è rimasto
|
||||
// in mano al proclamatore almeno in parte del periodo: assegnato
|
||||
// durante la campagna, rientrato durante la campagna, oppure fuori per
|
||||
// tutta la sua durata (assegnato prima e rientrato dopo). Se sia stato
|
||||
// davvero percorso lo decide l'operatore con la spunta.
|
||||
// Se più campagne corrispondono si propone la più recente.
|
||||
return Campagna::where('start_date', '<=', $returnDate)
|
||||
->where('end_date', '>=', $this->assigned_at)
|
||||
->where('end_date', '>=', $assignedAt)
|
||||
->orderByDesc('start_date')
|
||||
->first();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,16 @@ class Campagna extends Model
|
||||
->where('counted_in_campaign', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assignments still open that were out during this campaign (assigned
|
||||
* on or before its end): they can be counted for it when they come back.
|
||||
*/
|
||||
public function assegnazioniInCorso()
|
||||
{
|
||||
return Assegnazione::whereNull('returned_at')
|
||||
->where('assigned_at', '<=', $this->end_date);
|
||||
}
|
||||
|
||||
/**
|
||||
* All assignments with assigned_at in this campaign's range.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user