From: Vincent Vanwaelscappel Date: Fri, 27 May 2022 15:58:16 +0000 (+0200) Subject: wip #5298 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=ec6d0b102c0b3e4b6dde2c8d7db13f1f8d7bffb4;p=fluidbook-toolbox.git wip #5298 @0.5 --- diff --git a/app/Jobs/ProcessTotals.php b/app/Jobs/ProcessTotals.php index cbd185368..e8b1e6048 100644 --- a/app/Jobs/ProcessTotals.php +++ b/app/Jobs/ProcessTotals.php @@ -17,6 +17,7 @@ class ProcessTotals extends Base protected $users = []; protected $usersOfCompanies = []; protected $companyOfUser = []; + protected $companyYears = []; protected static $_wstable = 'extranet_clean'; public function handle() @@ -41,6 +42,8 @@ class ProcessTotals extends Base protected function processCompanies() { + $currentYear = date('Y'); + $users = User::withoutGlobalScopes()->get(); foreach ($users as $user) { if (!isset($this->usersOfCompanies[$user->company])) { @@ -54,11 +57,26 @@ class ProcessTotals extends Base if (!isset($this->companyOfUser[$e->client])) { continue; } + + if ($e->status == 0) { + continue; + } else { + $year = date('Y', max($e->date_debut, $e->date_creation, $e->date_fin)); + } + $company = $this->companyOfUser[$e->client]; if (!isset($this->companies[$company])) { $this->companies[$company] = 0; } - $this->companies[$company] += $this->projects[$e->projet_id] ?? 0; + if (!isset($this->companyYears[$company])) { + $this->companyYears[$company] = []; + } + if (!isset($this->companyYears[$company][$year])) { + $this->companyYears[$company][$year] = 0; + } + $a = $this->projects[$e->projet_id] ?? 0; + $this->companies[$company] += $a; + $this->companyYears[$company][$year] += $a; } foreach ($this->companies as $company => $ca) { @@ -66,7 +84,11 @@ class ProcessTotals extends Base if (null === $c) { continue; } - $c->c_ca = $ca; + $c->c_ca = 0; + foreach ($this->companyYears[$company] as $y => $ca) { + $c->c_ca += $ca; + $c->{'c_ca_' . $y} = $ca; + } $c->saveQuietly(); }