protected $users = [];
protected $usersOfCompanies = [];
protected $companyOfUser = [];
+ protected $companyYears = [];
protected static $_wstable = 'extranet_clean';
public function handle()
protected function processCompanies()
{
+ $currentYear = date('Y');
+
$users = User::withoutGlobalScopes()->get();
foreach ($users as $user) {
if (!isset($this->usersOfCompanies[$user->company])) {
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) {
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();
}