]> _ Git - fluidbook-toolbox.git/commitdiff
wait #5423 @0.75
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 2 Sep 2022 17:03:23 +0000 (19:03 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 2 Sep 2022 17:03:23 +0000 (19:03 +0200)
.docker/config/mariadb/finetuning.cnf
.docker/config/mariadb/logs.cnf [new file with mode: 0644]
app/Fields/User.php
app/Jobs/ProcessTotals.php

index 11c47658920302c7c172f17fb10dfb5b0e0a9c6a..ea97623851a59c6d82f0b6e4723ecdf5174af705 100644 (file)
@@ -12,3 +12,5 @@ innodb_buffer_pool_size = 4G
 join_buffer_size        = 32M
 join_buffer_space_limit = 256M
 join_cache_level        = 12
+
+query_cache_size       = 256M
diff --git a/.docker/config/mariadb/logs.cnf b/.docker/config/mariadb/logs.cnf
new file mode 100644 (file)
index 0000000..0d659f6
--- /dev/null
@@ -0,0 +1,8 @@
+[mariadb]
+skip-log-error
+
+general_log         = 1
+general_log_file    = /var/log/mysql/queries.log
+
+slow_query_log      = 1
+slow_query_log_file    = /var/log/mysql/slow_queries.log
index ed3ed1709703af8f2573bc5a87843bb6e14c6090..034c674c783acd4b3b8d94d9394e5fdc3345737d 100644 (file)
@@ -6,5 +6,5 @@ namespace App\Fields;
 
 class User extends \Cubist\Backpack\Magic\Fields\User
 {
-
+    protected $_databaseIndex = true;
 }
index e8b1e6048d915edd0272ebdc19c419c36a70f178..bafdcb688e2bd7be0ac08a77d3beca622ea423d1 100644 (file)
@@ -13,33 +13,51 @@ class ProcessTotals extends Base
 
 
     protected $projects = [];
+    protected $invoices = [];
+    protected $invoicesByProject = [];
     protected $companies = [];
     protected $users = [];
     protected $usersOfCompanies = [];
     protected $companyOfUser = [];
     protected $companyYears = [];
+    protected $unpaidYears = [];
+    protected $unpaid = [];
     protected static $_wstable = 'extranet_clean';
 
     public function handle()
     {
-        $this->processProjects();
+        $this->processInvoices();
+        //$this->processProjects();
         $this->processCompanies();
         $this->processFluidbookCounts();
         Artisan::command('ws:precache', function () {
         });
     }
 
-    protected function processProjects()
+    protected function processInvoices()
     {
-        foreach (DB::table(self::$_wstable . '.taches')->get() as $e) {
-            if (!isset($this->projects[$e->projet])) {
-                $this->projects[$e->projet] = 0;
+        foreach (DB::table(self::$_wstable . '.factures')->whereIn('status', [1, 2])->get() as $e) {
+
+            $this->invoices[$e->facture_id] =
+                ['status' => $e->status, 'amount' => $e->total_ht, 'project' => $e->projet, 'year' => date('Y', $e->date_creation), 'paid' => $e->status == 2];
+            if (!isset($this->invoicesByProject[$e->projet])) {
+                $this->invoicesByProject[$e->projet] = [];
             }
-            $this->projects[$e->projet] += $e->budget;
+            $this->invoicesByProject[$e->projet][] = $e->facture_id;
         }
-
     }
 
+//    protected function processProjects()
+//    {
+//        foreach (DB::table(self::$_wstable . '.taches')->get() as $e) {
+//            if (!isset($this->projects[$e->projet])) {
+//                $this->projects[$e->projet] = 0;
+//            }
+//            $this->projects[$e->projet] += $e->budget;
+//        }
+//
+//    }
+
     protected function processCompanies()
     {
         $currentYear = date('Y');
@@ -58,25 +76,34 @@ class ProcessTotals extends Base
                 continue;
             }
 
-            if ($e->status == 0) {
+            if (!isset($this->invoicesByProject[$e->projet_id])) {
                 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;
-            }
-            if (!isset($this->companyYears[$company])) {
-                $this->companyYears[$company] = [];
             }
-            if (!isset($this->companyYears[$company][$year])) {
-                $this->companyYears[$company][$year] = 0;
+            foreach ($this->invoicesByProject[$e->projet_id] as $invoice_id) {
+                $invoice = $this->invoices[$invoice_id];
+
+                $company = $this->companyOfUser[$e->client];
+                if (!isset($this->companies[$company])) {
+                    $this->companies[$company] = 0;
+                    $this->unpaid[$company] = 0;
+                }
+                if (!isset($this->companyYears[$company])) {
+                    $this->companyYears[$company] = [];
+                    $this->unpaidYears[$company] = [];
+                }
+                if (!isset($this->companyYears[$company][$invoice['year']])) {
+                    $this->companyYears[$company][$invoice['year']] = 0;
+                    $this->unpaidYears[$company][$invoice['year']] = 0;
+                }
+                $a = $invoice['amount'];
+                $this->companies[$company] += $a;
+                $this->companyYears[$company][$invoice['year']] += $a;
+                if (!$invoice['paid']) {
+                    $this->unpaid[$company] += $a;
+                    $this->unpaidYears[$company][$invoice['year']] += $a;
+                }
             }
-            $a = $this->projects[$e->projet_id] ?? 0;
-            $this->companies[$company] += $a;
-            $this->companyYears[$company][$year] += $a;
+
         }
 
         foreach ($this->companies as $company => $ca) {
@@ -84,10 +111,13 @@ class ProcessTotals extends Base
             if (null === $c) {
                 continue;
             }
-            $c->c_ca = 0;
-            foreach ($this->companyYears[$company] as $y => $ca) {
-                $c->c_ca += $ca;
-                $c->{'c_ca_' . $y} = $ca;
+            $c->c_ca = $ca;
+            foreach ($this->companyYears[$company] as $y => $yca) {
+                $c->{'c_ca_' . $y} = $yca;
+            }
+            $c->c_unpaid = $this->unpaid[$company];
+            foreach ($this->unpaidYears[$company] as $y => $unpaid) {
+                $c->{'c_unpaid_' . $y} = $unpaid;
             }
             $c->saveQuietly();
         }