Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Controller/ReportContacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
namespace FacturaScripts\Plugins\Informes\Controller;

use FacturaScripts\Core\Base\Controller;
use FacturaScripts\Core\Base\DataBase;
use FacturaScripts\Core\Plugins;
use FacturaScripts\Core\Tools;
use FacturaScripts\Dinamic\Model\Pais;
Expand All @@ -33,6 +34,7 @@ class ReportContacts extends Controller
public $charts = [];
public $totals = [];
public $countries = [];
public $provinces = [];
public $companyCountry = '';
public $companyCountryCode = '';

Expand Down Expand Up @@ -124,6 +126,14 @@ protected function loadNewContactsByYear(): void

protected function loadContactsByProvince(): void
{
$db = new DataBase();
$sql = "SELECT COALESCE(NULLIF(c.provincia, ''), '-') AS provincia, COUNT(*) as total
FROM contactos c
WHERE c.codpais = " . $db->var2str($this->companyCountryCode) . "
GROUP BY COALESCE(NULLIF(c.provincia, ''), '-')
ORDER BY total DESC;";
$this->provinces = $db->select($sql);

$report = new Report();
$report->type = Report::TYPE_TREE_MAP;
$report->table = 'contactos c';
Expand Down Expand Up @@ -154,6 +164,10 @@ protected function loadSourcesChart(): void

protected function loadInterestsChart(): void
{
if (false === (new DataBase())->tableExists('crm_intereses_contactos')) {
return;
}

$report = new Report();
$report->type = Report::TYPE_DOUGHNUT;
$report->table = 'contactos c';
Expand Down
151 changes: 125 additions & 26 deletions View/ReportContacts.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,39 @@
</div>
<div class="card-body">
<div id="regions_div" style="min-height: 320px;"></div>
{% if fsc.countries %}
<div class="mt-3">
<button class="btn btn-sm btn-outline-secondary w-100" type="button"
data-bs-toggle="collapse" data-bs-target="#countries-table-collapse"
aria-expanded="false" aria-controls="countries-table-collapse">
<i class="fa-solid fa-list me-1"></i>
{{ trans('country') }} ({{ fsc.countries|length }})
</button>
<div class="collapse" id="countries-table-collapse">
<div style="max-height: 280px; overflow-y: auto;">
<table class="table table-sm table-hover mb-0">
<thead class="table-light sticky-top">
<tr>
<th>{{ trans('country') }}</th>
<th class="text-end">{{ trans('total') }}</th>
<th class="text-end">%</th>
</tr>
</thead>
<tbody>
{% for row in fsc.countries %}
{% set perc = fsc.totals.total > 0 ? ((row.total / fsc.totals.total) * 100)|round(1) : 0 %}
<tr>
<td>{{ row.nombre ?: row.codpais ?: '-' }}</td>
<td class="text-end">{{ row.total }}</td>
<td class="text-end text-muted">{{ perc }}%</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
{% endif %}
</div>
</div>
</div>
Expand All @@ -172,6 +205,40 @@
</div>
<div class="card-body">
{{ fsc.charts.contactsByProvince.getChart().render({'height':320}) | raw }}
{% if fsc.provinces %}
<div class="mt-3">
<button class="btn btn-sm btn-outline-secondary w-100" type="button"
data-bs-toggle="collapse" data-bs-target="#provinces-table-collapse"
aria-expanded="false" aria-controls="provinces-table-collapse">
<i class="fa-solid fa-list me-1"></i>
{{ trans('province') }} ({{ fsc.provinces|length }})
</button>
<div class="collapse" id="provinces-table-collapse">
<div style="max-height: 280px; overflow-y: auto;">
<table class="table table-sm table-hover mb-0">
<thead class="table-light sticky-top">
<tr>
<th>{{ trans('province') }}</th>
<th class="text-end">{{ trans('total') }}</th>
<th class="text-end">%</th>
</tr>
</thead>
<tbody>
{% set province_total = fsc.provinces|reduce((carry, row) => carry + row.total, 0) %}
{% for row in fsc.provinces %}
{% set perc = province_total > 0 ? ((row.total / province_total) * 100)|round(1) : 0 %}
<tr>
<td>{{ row.provincia }}</td>
<td class="text-end">{{ row.total }}</td>
<td class="text-end text-muted">{{ perc }}%</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
{% endif %}
</div>
</div>
</div>
Expand All @@ -189,21 +256,37 @@

{# Period breakdowns for sources (30/90/365) #}
<div class="mt-3">
<h6>{{ trans('r-contactos-sources-periods') }}</h6>
<div class="row">
{% for days, rows in fsc.sources_periods %}
<div class="col-12 col-md-4">
<div class="small-card p-2">
<strong>{{ days }} {{ trans('days') }}</strong>
<ul class="list-unstyled mb-0">
{% for r in rows|slice(0,8) %}
<li>{{ r.nombre|default('-') }} - <span class="badge bg-light text-dark">{{ r.total }}</span></li>
{% endfor %}
</ul>
{% for days, rows in fsc.sources_periods %}
<div class="mb-1">
<button class="btn btn-sm btn-outline-secondary w-100 text-start" type="button"
data-bs-toggle="collapse" data-bs-target="#sources-period-{{ days }}"
aria-expanded="false" aria-controls="sources-period-{{ days }}">
<i class="fa-solid fa-list me-1"></i>
{{ days }} {{ trans('days') }}
<span class="badge bg-secondary ms-1">{{ rows|length }}</span>
</button>
<div class="collapse" id="sources-period-{{ days }}">
<div style="max-height: 280px; overflow-y: auto;">
<table class="table table-sm table-hover mb-0">
<thead class="table-light sticky-top">
<tr>
<th>{{ trans('source') }}</th>
<th class="text-end">{{ trans('total') }}</th>
</tr>
</thead>
<tbody>
{% for r in rows %}
<tr>
<td>{{ r.nombre|default('-') }}</td>
<td class="text-end">{{ r.total }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endfor %}
</div>
</div>
{% endfor %}
</div>
</div>
</div>
Expand All @@ -223,21 +306,37 @@

{# Period breakdowns for interests (30/90/365) #}
<div class="mt-3">
<h6>{{ trans('r-contactos-interests-periods') }}</h6>
<div class="row">
{% for days, rows in fsc.interests_periods %}
<div class="col-12 col-md-4">
<div class="small-card p-2">
<strong>{{ days }} {{ trans('days') }}</strong>
<ul class="list-unstyled mb-0">
{% for r in rows|slice(0,8) %}
<li>{{ r.nombre|default('-') }} - <span class="badge bg-light text-dark">{{ r.total }}</span></li>
{% endfor %}
</ul>
{% for days, rows in fsc.interests_periods %}
<div class="mb-1">
<button class="btn btn-sm btn-outline-secondary w-100 text-start" type="button"
data-bs-toggle="collapse" data-bs-target="#interests-period-{{ days }}"
aria-expanded="false" aria-controls="interests-period-{{ days }}">
<i class="fa-solid fa-list me-1"></i>
{{ days }} {{ trans('days') }}
<span class="badge bg-secondary ms-1">{{ rows|length }}</span>
</button>
<div class="collapse" id="interests-period-{{ days }}">
<div style="max-height: 280px; overflow-y: auto;">
<table class="table table-sm table-hover mb-0">
<thead class="table-light sticky-top">
<tr>
<th>{{ trans('interest') }}</th>
<th class="text-end">{{ trans('total') }}</th>
</tr>
</thead>
<tbody>
{% for r in rows %}
<tr>
<td>{{ r.nombre|default('-') }}</td>
<td class="text-end">{{ r.total }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endfor %}
</div>
</div>
{% endfor %}
</div>
</div>
</div>
Expand Down