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');
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) {
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();
}