From: Vincent Vanwaelscappel Date: Fri, 2 Sep 2022 17:03:23 +0000 (+0200) Subject: wait #5423 @0.75 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=7d2d4e9bd2294efe111483e38fca5f6b64b1c3d6;p=fluidbook-toolbox.git wait #5423 @0.75 --- diff --git a/.docker/config/mariadb/finetuning.cnf b/.docker/config/mariadb/finetuning.cnf index 11c476589..ea9762385 100644 --- a/.docker/config/mariadb/finetuning.cnf +++ b/.docker/config/mariadb/finetuning.cnf @@ -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 index 000000000..0d659f632 --- /dev/null +++ b/.docker/config/mariadb/logs.cnf @@ -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 diff --git a/app/Fields/User.php b/app/Fields/User.php index ed3ed1709..034c674c7 100644 --- a/app/Fields/User.php +++ b/app/Fields/User.php @@ -6,5 +6,5 @@ namespace App\Fields; class User extends \Cubist\Backpack\Magic\Fields\User { - + protected $_databaseIndex = true; } diff --git a/app/Jobs/ProcessTotals.php b/app/Jobs/ProcessTotals.php index e8b1e6048..bafdcb688 100644 --- a/app/Jobs/ProcessTotals.php +++ b/app/Jobs/ProcessTotals.php @@ -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(); }