]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5298 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 27 May 2022 15:58:16 +0000 (17:58 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 27 May 2022 15:58:16 +0000 (17:58 +0200)
app/Jobs/ProcessTotals.php

index cbd185368248746419739c9495ea6b58250601c9..e8b1e6048d915edd0272ebdc19c419c36a70f178 100644 (file)
@@ -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();
         }