add homeless to person addresses

This commit is contained in:
2020-05-01 15:51:30 +02:00
parent de560b4d3b
commit 320598e905
10 changed files with 197 additions and 8 deletions

View File

@@ -0,0 +1,138 @@
<?php declare(strict_types=1);
namespace Application\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20200422125935 extends AbstractMigration
{
public function up(Schema $schema) : void
{
$this->addSql('DROP FUNCTION get_last_address(integer, date)');
$this->addSql(<<<'SQL'
CREATE OR REPLACE FUNCTION public.get_last_address (
pid integer,
before_date date)
RETURNS TABLE(
person_id integer,
address_id integer,
streetaddress1 varchar(255),
streetaddress2 varchar(255),
validfrom date,
postcode_label varchar(255),
postcode_code varchar(100),
postcode_id integer,
isnoaddress boolean,
country_name json,
country_code varchar(3),
country_id integer)
AS
$BODY$
SELECT
pid AS person_id,
chill_main_address.id AS address_id,
chill_main_address.streetaddress1,
chill_main_address.streetaddress2,
chill_main_address.validfrom,
chill_main_postal_code.label,
chill_main_postal_code.code,
chill_main_postal_code.id AS postal_code_id,
chill_main_address.isnoaddress AS isnoaddress,
country.name,
country.countrycode,
country.id AS country_id
FROM chill_main_address
JOIN (
SELECT
chill_main_address.id AS address_id,
validfrom,
rank() OVER (PARTITION BY person_id ORDER BY validfrom DESC) as pos
FROM chill_person_persons_to_addresses
JOIN chill_main_address ON chill_person_persons_to_addresses.address_id = chill_main_address.id
WHERE person_id = pid
AND chill_main_address.validfrom <= before_date
) AS ranking ON ranking.address_id = chill_main_address.id
JOIN chill_main_postal_code ON chill_main_address.postcode_id = chill_main_postal_code.id
JOIN country ON chill_main_postal_code.country_id = country.id
WHERE ranking.pos = 1
$BODY$
LANGUAGE sql VOLATILE
COST 100;
SQL
);
$this->addSql(<<<'SQL'
CREATE OR REPLACE FUNCTION get_last_address_isnoaddress (
pid integer,
before_date date)
RETURNS BOOL AS
$BODY$
SELECT isnoaddress FROM get_last_address(pid, before_date)
$BODY$
LANGUAGE sql volatile
COST 100;
SQL
);
}
public function down(Schema $schema) : void
{
$this->addSql('DROP FUNCTION public.get_last_address_isnoaddress(integer, date);');
$this->addSql('DROP FUNCTION get_last_address(integer, date)');
$this->addSql(<<<'SQL'
CREATE OR REPLACE FUNCTION public.get_last_address (
pid integer,
before_date date)
RETURNS TABLE(
person_id integer,
address_id integer,
streetaddress1 varchar(255),
streetaddress2 varchar(255),
validfrom date,
postcode_label varchar(255),
postcode_code varchar(100),
postcode_id integer,
country_name json,
country_code varchar(3),
country_id integer)
AS
$BODY$
SELECT
pid AS person_id,
chill_main_address.id AS address_id,
chill_main_address.streetaddress1,
chill_main_address.streetaddress2,
chill_main_address.validfrom,
chill_main_postal_code.label,
chill_main_postal_code.code,
chill_main_postal_code.id AS postal_code_id,
country.name,
country.countrycode,
country.id AS country_id
FROM chill_main_address
JOIN (
SELECT
chill_main_address.id AS address_id,
validfrom,
rank() OVER (PARTITION BY person_id ORDER BY validfrom DESC) as pos
FROM chill_person_persons_to_addresses
JOIN chill_main_address ON chill_person_persons_to_addresses.address_id = chill_main_address.id
WHERE person_id = pid
AND chill_main_address.validfrom <= before_date
) AS ranking ON ranking.address_id = chill_main_address.id
JOIN chill_main_postal_code ON chill_main_address.postcode_id = chill_main_postal_code.id
JOIN country ON chill_main_postal_code.country_id = country.id
WHERE ranking.pos = 1
$BODY$
LANGUAGE sql VOLATILE
COST 100;
SQL
);
}
}

View File

@@ -26,6 +26,7 @@
{{ form_start(form) }}
{{ form_row(form.isNoAddress) }}
{{ form_row(form.streetAddress1) }}
{{ form_row(form.streetAddress2) }}
{{ form_row(form.postCode) }}

View File

@@ -50,7 +50,7 @@
<td><strong>{{ 'Since %date%'|trans( { '%date%' : address.validFrom|localizeddate('long', 'none') } ) }}</strong></td>
<td>
{{ address_macros._render(address, { 'with_valid_from' : false } ) }}
{{ address_macros._render(address, { 'with_valid_from' : false, 'has_no_address': true } ) }}
</td>
<td>

View File

@@ -26,6 +26,7 @@
{{ form_start(form) }}
{{ form_row(form.isNoAddress) }}
{{ form_row(form.streetAddress1) }}
{{ form_errors(form.streetAddress1) }}
{{ form_row(form.streetAddress2) }}

View File

@@ -178,7 +178,7 @@ This view should receive those arguments:
<dt>{{ 'Address'|trans }}</dt>
<dd>
{%- if person.lastAddress is not empty -%}
{{ address._render(person.lastAddress) }}
{{ address._render(person.lastAddress, {'has_no_address': true}) }}
<ul class="record_actions record_actions_small">
<li>