Skip to content
Open
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
5 changes: 4 additions & 1 deletion modules/anagrafiche/ajax/select.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,13 @@
$user = auth_osm()->getUser();
$id_azienda = setting('Azienda predefinita');

$query = "SELECT * FROM (SELECT '0' AS id, 'Sede legale' AS `nome_sede`, CONCAT_WS(' - ', \"".tr('Sede legale')."\" , (SELECT CONCAT (`citta`, IF(`indirizzo`!='',CONCAT(' (', `indirizzo`, ')'), ''),' (', `ragione_sociale`,')') FROM `an_anagrafiche` |where|)) AS descrizione UNION SELECT `id`, `nome_sede`, CONCAT_WS(' - ', `nome_sede`, CONCAT(`citta`, IF(`indirizzo`!='',CONCAT(' (', `indirizzo`, ')'), '')) ) FROM `an_sedi` |where| ORDER BY `nome_sede`) AS tab |filter| ORDER BY descrizione";
$query = "SELECT * FROM (SELECT '0' AS id, 'Sede legale' AS `nome_sede`, CONCAT_WS(' - ', \"".tr('Sede legale')."\" , (SELECT CONCAT (`citta`, IF(`indirizzo`!='',CONCAT(' (', `indirizzo`, ')'), ''),' (', `ragione_sociale`,')') FROM `an_anagrafiche` |where|)) AS descrizione UNION SELECT `id`, `nome_sede`, CONCAT_WS(' - ', `nome_sede`, CONCAT(`citta`, IF(`indirizzo`!='',CONCAT(' (', `indirizzo`, ')'), '')) ) FROM `an_sedi` |where_sedi| ORDER BY `nome_sede`) AS tab |filter| ORDER BY descrizione";

$where[] = '`id`='.prepare($id_azienda);
$where[] = 'deleted_at IS NULL';
$where_sedi[] = '`id_anagrafica`='.prepare($id_azienda);
$where_sedi[] = 'deleted_at IS NULL';
$query = str_replace('|where_sedi|', 'WHERE '.implode(' AND ', $where_sedi), $query);

// filtro in base alle sedi abilitate dell'utente
if ($user->gruppo != 'Amministratori') {
Expand Down
19 changes: 19 additions & 0 deletions tests/AnagraficheCompanyLocationsSelectorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

use PHPUnit\Framework\TestCase;

class AnagraficheCompanyLocationsSelectorTest extends TestCase
{
public function testCompanyLocationsUseTheCompanyForeignKey(): void
{
$source = file_get_contents(__DIR__.'/../modules/anagrafiche/ajax/select.php');
preg_match("/case 'sedi_azienda':(?<selector>.*?)case 'referenti':/s", $source, $matches);

$selector = $matches['selector'] ?? '';

$this->assertStringContainsString('FROM `an_sedi` |where_sedi|', $selector);
$this->assertStringContainsString("\$where_sedi[] = '`id_anagrafica`='.prepare(\$id_azienda);", $selector);
$this->assertStringContainsString("\$where_sedi[] = 'deleted_at IS NULL';", $selector);
$this->assertStringContainsString("str_replace('|where_sedi|', 'WHERE '.implode(' AND ', \$where_sedi), \$query)", $selector);
}
}