<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250106183714 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE tourapp.travel_members ADD order_note TEXT DEFAULT NULL');
$this->addSql('ALTER TABLE tourapp.travel ADD opt_note_on_order BOOLEAN DEFAULT false NOT NULL');
$this->addSql('ALTER TABLE tourapp.travel ADD opt_participant_free BOOLEAN DEFAULT false NOT NULL');
$this->addSql('ALTER TABLE tourapp.email_template ADD variables JSON DEFAULT NULL');
// $this->addSql('ALTER TABLE tourapp.travel_members ADD CONSTRAINT FK_5B052B5BECAB15B3 FOREIGN KEY (travel_id) REFERENCES tourapp.travel (travel_id) NOT DEFERRABLE INITIALLY IMMEDIATE');
// $this->addSql('CREATE INDEX IDX_5B052B5BECAB15B3 ON tourapp.travel_members (travel_id)');
$this->addSql('ALTER TABLE tourapp.travel RENAME COLUMN group_name TO label');
$this->addSql('ALTER TABLE tourapp.travel_members_participant ADD role VARCHAR(255);');
$this->addSql('UPDATE tourapp.travel_members_participant SET role = \'PARTICIPANT\' WHERE role IS NULL;');
$this->addSql('ALTER TABLE tourapp.travel_members_participant ALTER COLUMN role SET NOT NULL;');
$this->addSql('ALTER TABLE tourapp.product_default ADD quantity INT');
$this->addSql('ALTER TABLE tourapp.product_travel ADD quantity INT');
$this->addSql('CREATE SEQUENCE tourapp.travelpay_reckoning_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('CREATE TABLE tourapp.travelpay_reckoning (id INT NOT NULL, packageId INT NOT NULL, packageName VARCHAR(255) NOT NULL, reckoningDate TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, reckoningStartDate TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, reckoningEndDate TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, fixedAmount NUMERIC(10, 2) NOT NULL, percentageRevenue NUMERIC(5, 2) NOT NULL, amountPerParticipantPoint NUMERIC(10, 2) NOT NULL, amountPerTravelPoint NUMERIC(10, 2) NOT NULL, participantsThreshold INT NOT NULL, clientId VARCHAR(100) NOT NULL, clientEmail VARCHAR(100) NOT NULL, tripDetails JSON NOT NULL, paymentDetails JSON NOT NULL, totalPayments NUMERIC(10, 2) NOT NULL, totalPariticpantPoints INT NOT NULL, totalTravelPoints INT NOT NULL, calculatePayments NUMERIC(10, 2) NOT NULL, calculatePerTravel NUMERIC(10, 2) NOT NULL, calculatePerParticipant NUMERIC(10, 2) NOT NULL, reckoningAmount NUMERIC(10, 2) NOT NULL, fakturowniaInvoiceId VARCHAR(255) DEFAULT NULL, invoiceSent BOOLEAN NOT NULL, invoiceSentDate TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))');
$this->addSql('ALTER TABLE tourapp.bank_transaction ADD reference VARCHAR(255) DEFAULT NULL');
$this->addSql('
UPDATE tourapp.email_template
SET variables = \'{
"travel_id": {
"description": "ID wycieczki",
"value": null
},
"travel_name": {
"description": "Nazwa wycieczki",
"value": null
},
"company": {
"description": "Firma",
"value": null
},
"coordinator": {
"description": "Koordynator",
"value": null
},
"travel_date_compartment": {
"description": "Zakres dat podróży",
"value": null
},
"username": {
"description": "Nazwa użytkownika",
"value": null
},
"userpassword": {
"description": "Hasło użytkownika",
"value": null
},
"homelink": {
"description": "Link do strony głównej",
"value": null
}
}\'
WHERE email_template_id=1;');
$this->addSql('
UPDATE tourapp.email_template
SET variables = \'{
"travel_id": {
"description": "ID wycieczki",
"value": null
},
"memberiban": {
"description": "Numer konta do wpłat zamawiającego",
"value": null
},
"payulink": {
"description": "Link do płatności online",
"value": null
},
"harmonogram_platnosci": {
"description": "Harmonogram płatności",
"value": null
},
"tresc_o_ubezpieczeniu_kr": {
"description": "Treść o ubezpieczeniu (KR)",
"value": null
},
"nr_rezerwacji": {
"description": "Numer rezerwacji",
"value": null
}
}\'
WHERE email_template_id=2;');
$this->addSql('
UPDATE tourapp.email_template
SET variables = \'{
"travel_id": {
"description": "ID wycieczki",
"value": null
},
"payulink": {
"description": "Link do płatności online",
"value": null
},
"memberiban": {
"description": "Numer konta do wpłat zamawiającego",
"value": null
},
"harmonogram_platnosci": {
"description": "Harmonogram płatności",
"value": null
},
"faktura": {
"description": "Status faktury wymagana / nie wymagana",
"value": null
},
"tresc_o_ubezpieczeniu_kr": {
"description": "Treść o ubezpieczeniu (KR)",
"value": null
},
"nr_rezerwacji": {
"description": "Numer rezerwacji",
"value": null
}
}\'
WHERE email_template_id=3;');
$this->addSql('
UPDATE tourapp.email_template
SET variables = \'{
"travel_id": {
"description": "ID wycieczki",
"value": null
},
"travel_name": {
"description": "Nazwa wycieczki",
"value": null
},
"company": {
"description": "Firma",
"value": null
},
"coordinator": {
"description": "Koordynator",
"value": null
},
"travel_date_compartment": {
"description": "Zakres dat podróży",
"value": null
},
"travelprice": {
"description": "Cena podróży - wycieczka",
"value": null
},
"orderfullname": {
"description": "Imię i nazwisko zamawiającego",
"value": null
},
"ordermemberlist": {
"description": "Lista członków zamówienia",
"value": null
},
"payrest": {
"description": "Pozostała kwota do zapłaty",
"value": null
},
"memberiban": {
"description": "Numer konta do wpłat zamawiającego",
"value": null
},
"payulink": {
"description": "Link do płatności online",
"value": null
},
"paid": {
"description": "Kwota zapłacona",
"value": null
},
"harmonogram_platnosci": {
"description": "Harmonogram płatności",
"value": null
},
"faktura": {
"description": "Status faktury wymagana / nie wymagana",
"value": null
},
"tresc_o_ubezpieczeniu_kr": {
"description": "Treść o ubezpieczeniu (KR)",
"value": null
},
"nr_rezerwacji": {
"description": "Numer rezerwacji",
"value": null
}
}\'
WHERE email_template_id=4;');
$this->addSql('
UPDATE tourapp.email_template
SET variables = \'{
"travel_id": {
"description": "ID wycieczki",
"value": null
},
"travel_name": {
"description": "Nazwa wycieczki",
"value": null
},
"company": {
"description": "Firma",
"value": null
},
"coordinator": {
"description": "Koordynator",
"value": null
},
"travel_date_compartment": {
"description": "Zakres dat podróży",
"value": null
},
"payulink": {
"description": "Link do płatności online",
"value": null
},
"homelink": {
"description": "Link do strony głównej",
"value": null
},
"harmonogram_platnosci": {
"description": "Harmonogram płatności",
"value": null
},
"tresc_o_ubezpieczeniu_kr": {
"description": "Treść o ubezpieczeniu (KR)",
"value": null
}
}\'
WHERE email_template_id=5;');
$this->addSql('
UPDATE tourapp.email_template
SET variables = \'{
"travel_id": {
"description": "ID wycieczki",
"value": null
},
"memberiban": {
"description": "Numer konta do wpłat zamawiającego",
"value": null
},
"harmonogram_platnosci": {
"description": "Harmonogram płatności",
"value": null
},
"tresc_o_ubezpieczeniu_kr": {
"description": "Treść o ubezpieczeniu (KR)",
"value": null
},
"nr_rezerwacji": {
"description": "Numer rezerwacji",
"value": null
}
}\'
WHERE email_template_id=6;');
$this->addSql('
UPDATE tourapp.email_template
SET variables = \'{
"travel_id": {
"description": "ID wycieczki",
"value": null
},
"payulink": {
"description": "Link do płatności online",
"value": null
},
"memberiban": {
"description": "Numer konta do wpłat zamawiającego",
"value": null
},
"harmonogram_platnosci": {
"description": "Harmonogram płatności",
"value": null
},
"tresc_o_ubezpieczeniu_kr": {
"description": "Treść o ubezpieczeniu (KR)",
"value": null
},
"nr_rezerwacji": {
"description": "Numer rezerwacji",
"value": null
}
}\'
WHERE email_template_id=7;');
$this->addSql('
UPDATE tourapp.email_template
SET variables = \'{
"travel_id": {
"description": "ID wycieczki",
"value": null
},
"transferamount": {
"description": "Kwota wpłaty",
"value": null
},
"travel_name": {
"description": "Nazwa wycieczki",
"value": null
},
"company": {
"description": "Firma",
"value": null
},
"coordinator": {
"description": "Koordynator",
"value": null
},
"travel_date_compartment": {
"description": "Zakres dat podróży",
"value": null
},
"travelprice": {
"description": "Cena podróży - wycieczka",
"value": null
},
"payrest": {
"description": "Pozostała kwota do zapłaty",
"value": null
},
"memberiban": {
"description": "Numer konta do wpłat zamawiającego",
"value": null
},
"payulink": {
"description": "Link do płatności online",
"value": null
},
"paid": {
"description": "Kwota zapłacona",
"value": null
},
"harmonogram_platnosci": {
"description": "Harmonogram płatności",
"value": null
},
"faktura": {
"description": "Status faktury wymagana / nie wymagana",
"value": null
},
"tresc_o_ubezpieczeniu_kr": {
"description": "Treść o ubezpieczeniu (KR)",
"value": null
},
"nr_rezerwacji": {
"description": "Numer rezerwacji",
"value": null
}
}\'
WHERE email_template_id=8;');
$this->addSql('
UPDATE tourapp.email_template
SET variables = \'{
"travel_id": {
"description": "ID wycieczki",
"value": null
},
"travel_name": {
"description": "Nazwa wycieczki",
"value": null
},
"company": {
"description": "Firma",
"value": null
},
"coordinator": {
"description": "Koordynator",
"value": null
},
"travel_date_compartment": {
"description": "Zakres dat podróży",
"value": null
},
"payulink": {
"description": "Link do płatności online",
"value": null
},
"homelink": {
"description": "Link do strony głównej",
"value": null
},
"harmonogram_platnosci": {
"description": "Harmonogram płatności",
"value": null
},
"tresc_o_ubezpieczeniu_kr": {
"description": "Treść o ubezpieczeniu (KR)",
"value": null
}
}\'
WHERE email_template_id=9;');
$this->addSql('
UPDATE tourapp.email_template
SET variables = \'{
"user_login": {
"description": "Login użytkownika",
"value": null
},
"user_change_password_url": {
"description": "Link do zmiany hasła",
"value": null
}
}\'
WHERE email_template_id=10;');
$this->addSql('
UPDATE tourapp.email_template
SET variables = \'{
"travel_id": {
"description": "ID wycieczki",
"value": null
},
"travel_name": {
"description": "Nazwa wycieczki",
"value": null
},
"company": {
"description": "Firma",
"value": null
},
"coordinator": {
"description": "Koordynator",
"value": null
},
"travel_date_compartment": {
"description": "Zakres dat podróży",
"value": null
},
"orderfullname": {
"description": "Imię i nazwisko zamawiającego",
"value": null
},
"ordermemberlist": {
"description": "Lista członków zamówienia",
"value": null
},
"nr_rezerwacji": {
"description": "Numer rezerwacji",
"value": null
}
}\'
WHERE email_template_id=11;');
$this->addSql('
UPDATE tourapp.email_template
SET variables = \'{
"link_ankieta": {
"description": "Link do ankiety",
"value": null
}
}\'
WHERE email_template_id=12;');
$this->addSql('
UPDATE tourapp.email_template
SET variables = \'{
"orderId": {
"description": "ID zamówienia",
"value": null
},
"travelId": {
"description": "ID wycieczki",
"value": null
},
"travelName": {
"description": "Nazwa wycieczki",
"value": null
},
"travelFrom": {
"description": "Data rozpoczęcia wycieczki",
"value": null
},
"travelTo": {
"description": "Data zakończenia wycieczki",
"value": null
}
}\'
WHERE email_template_id=13;
');
$this->addSql('
UPDATE tourapp.travel_members_participant tp set
travel_member_participant_bday = x.travel_member_participant_bday2,
travel_member_participant_document_release_date = x.travel_member_participant_document_release_date2,
travel_member_participant_document_expiration_date = x.travel_member_participant_document_expiration_date2
from (
select
*,
CASE
WHEN travel_member_participant_bday ~ \'^\d{2}\.\d{2}\.\d{4}$\'
THEN TO_DATE(travel_member_participant_bday, \'DD.MM.YYYY\')
WHEN travel_member_participant_bday ~ \'^\d{4}-\d{2}-\d{2}$\'
THEN travel_member_participant_bday::DATE
ELSE NULL -- Opcjonalnie obsłuż inne formaty
END AS travel_member_participant_bday2,
CASE
WHEN travel_member_participant_document_release_date ~ \'^\d{2}\.\d{2}\.\d{4}$\'
THEN TO_DATE(travel_member_participant_document_release_date, \'DD.MM.YYYY\')
WHEN travel_member_participant_document_release_date ~ \'^\d{4}-\d{2}-\d{2}$\'
THEN travel_member_participant_document_release_date::DATE
ELSE NULL -- Opcjonalnie obsłuż inne formaty
END AS travel_member_participant_document_release_date2,
CASE
WHEN travel_member_participant_document_expiration_date ~ \'^\d{2}\.\d{2}\.\d{4}$\'
THEN TO_DATE(travel_member_participant_document_expiration_date, \'DD.MM.YYYY\')
WHEN travel_member_participant_document_expiration_date ~ \'^\d{4}-\d{2}-\d{2}$\'
THEN travel_member_participant_document_expiration_date::DATE
ELSE NULL -- Opcjonalnie obsłuż inne formaty
END AS travel_member_participant_document_expiration_date2
from (
SELECT
travel_member_participant_id,
replace(travel_member_participant_bday,\'\'\'\',\'\') as travel_member_participant_bday,
replace(travel_member_participant_document_release_date,\'\'\'\',\'\') as travel_member_participant_document_release_date,
replace(travel_member_participant_document_expiration_date,\'\'\'\',\'\') as travel_member_participant_document_expiration_date
FROM tourapp.travel_members_participant
) w
) x
where tp.travel_member_participant_id = x.travel_member_participant_id
');
$this->addSql('ALTER TABLE tourapp.travel_members_participant ALTER COLUMN travel_member_participant_document_release_date TYPE date USING travel_member_participant_document_release_date::date;');
$this->addSql('ALTER TABLE tourapp.travel_members_participant ALTER COLUMN travel_member_participant_bday TYPE date USING travel_member_participant_bday::date;');
$this->addSql('ALTER TABLE tourapp.travel_members_participant ALTER COLUMN travel_member_participant_document_expiration_date TYPE date USING travel_member_participant_document_expiration_date::date;');
$this->addSql('
UPDATE tourapp.travel_members tm
SET
travel_member_terminate_pay_deadline_cost_1 = x."Kwota raty 1 - zamowienie",
travel_member_terminate_pay_deadline_cost_2 = x."Kwota raty 2 - zamowienie",
travel_member_terminate_pay_deadline_cost_3 = x."Kwota raty 3 - zamowienie"
FROM (
select
*
from (
select
*,
case
when (
("Data raty 1 - zamowienie" is null and "Kwota raty 1 - zamowienie" > 0 or "Data raty 1 - zamowienie" is not null and "Kwota raty 1 - zamowienie" = 0)
or ("Data raty 2 - zamowienie" is null and "Kwota raty 2 - zamowienie" > 0 or "Data raty 2 - zamowienie" is not null and "Kwota raty 2 - zamowienie" = 0)
or ("Data raty 3 - zamowienie" is null and "Kwota raty 3 - zamowienie" > 0 or "Data raty 3 - zamowienie" is not null and "Kwota raty 3 - zamowienie" = 0)
) then \'Przypadek brak terminu na zamowieniu a na wycieczce widnieje\'
when (("Kwota raty 1 - zamowienie" + "Kwota raty 2 - zamowienie" + "Kwota raty 3 - zamowienie") <> "Cena domyślna za wycieczkę" ) then \'Suma rat inna niz cena wycieczki - zamówienia\'
else \'brak\'
end as type_error
from (
select
travel_member_id as "Id zamowienia",
travel_id as "Id wycieczki",
travel_focus_id as "Id wycieczki klienta",
travel_costofthetour as "Cena wycieczki",
travel_cost_terminate_pay_deadline_1 as "Koszt raty 1 - wycieczka",
travel_date_terminate_pay_deadline_1 as "Data raty 1 - wycieczka",
travel_days_terminate_pay_deadline_1_status as "Status dni od zapisu",
travel_cost_terminate_pay_deadline_2 as "Koszt raty 2 - wycieczka",
travel_date_terminate_pay_deadline_2 as "Data raty 2 - wycieczka",
travel_date_terminate_pay as "Data zapłaty - ostateczna",
rata_data_1 as "Data raty 1 - zamowienie",
rata_data_2 as "Data raty 2 - zamowienie",
rata_data_3 as "Data raty 3 - zamowienie",
case when rata_data_1 is null then 0 else coalesce(rata_kwota_1,0) end as "Kwota raty 1 - zamowienie",
case when rata_data_2 is null then 0 else coalesce(rata_kwota_2,0) end as "Kwota raty 2 - zamowienie",
rata_kwota_3 + case when rata_data_1 is null then coalesce(rata_kwota_1,0) else 0 end + case when rata_data_2 is null then coalesce(rata_kwota_2,0) else 0 end as "Kwota raty 3 - zamowienie",
--travel_days_terminate_pay_deadline_1_status,
travel_member_participant_topay as "Cena domyślna za wycieczkę"
from (
select
travel_member_id,
travel_id,
travel_focus_id,
travel_costofthetour,
travel_date_terminate_pay,
travel_cost_terminate_pay_deadline_1,
travel_date_terminate_pay_deadline_1,
travel_cost_terminate_pay_deadline_2,
travel_date_terminate_pay_deadline_2,
rata_data_1,
rata_data_2,
rata_data_3,
case when rata_data_1 is null then 0 else coalesce(rata_kwota_1,0) end as rata_kwota_1,
case when rata_data_2 is null then 0 else coalesce(rata_kwota_2,0) end as rata_kwota_2,
rata_kwota_3 + case when rata_data_1 is null then coalesce(rata_kwota_1,0) else 0 end + case when rata_data_2 is null then coalesce(rata_kwota_2,0) else 0 end as rata_kwota_3,
travel_days_terminate_pay_deadline_1_status,
travel_member_participant_topay,
created_at
from (
SELECT
tm.travel_member_id,
tm.travel_id,
tm.travel_focus_id,
t.travel_costofthetour,
tmp.travel_member_participant_topay,
t.travel_date_terminate_pay,
t.travel_cost_terminate_pay_deadline_1,
case when travel_days_terminate_pay_deadline_1_status then (tm.created_at::date + (t.travel_days_terminate_pay_deadline_1 || \' days\')::interval)::date else t.travel_date_terminate_pay_deadline_1 end as travel_date_terminate_pay_deadline_1,
t.travel_cost_terminate_pay_deadline_2,
t.travel_date_terminate_pay_deadline_2,
tm.travel_member_terminate_pay_deadline_date_1 AS rata_data_1,
--case when tm.travel_member_terminate_pay_deadline_date_1 is null and t.travel_days_terminate_pay_deadline_1_status then (tm.created_at::date + (t.travel_days_terminate_pay_deadline_1 || \' days\')::interval)::date else null end as potential_rata_data_1,
t.travel_cost_terminate_pay_deadline_1 AS rata_kwota_1,
tm.travel_member_terminate_pay_deadline_date_2 AS rata_data_2,
t.travel_cost_terminate_pay_deadline_2 AS rata_kwota_2,
tm.travel_member_terminate_pay_deadline_date_3 AS rata_data_3,
CASE
WHEN (coalesce(t.travel_cost_terminate_pay_deadline_1,0) + coalesce(t.travel_cost_terminate_pay_deadline_2,0)) >= coalesce(tmp.travel_member_participant_topay ,0) or (coalesce(tmp.travel_member_participant_topay,0) - (coalesce(t.travel_cost_terminate_pay_deadline_1,0) + coalesce(t.travel_cost_terminate_pay_deadline_2,0))) <= 0
THEN 0
ELSE coalesce(tmp.travel_member_participant_topay,0) - (coalesce(t.travel_cost_terminate_pay_deadline_1,0) + coalesce(t.travel_cost_terminate_pay_deadline_2,0))
END AS rata_kwota_3,
t.travel_days_terminate_pay_deadline_1_status,
tm.created_at::date
FROM tourapp.travel_members tm
JOIN tourapp.travel t ON tm.travel_id = t.travel_id
left join (
select
tm.travel_member_id,
tmp.travel_member_participant_topay
from tourapp.travel_members tm
join tourapp.travel_members_participant tmp on tm.travel_member_id = tmp.travel_member_id --and tmp.travel_member_participant_status
group by
tm.travel_member_id,
tmp.travel_member_participant_topay
) tmp on tm.travel_member_id = tmp.travel_member_id
) w
) w
where true
) w
) w
) x
WHERE tm.travel_member_id = x."Id zamowienia";
');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE tourapp.travel_members DROP order_note');
$this->addSql('ALTER TABLE tourapp.travel DROP opt_note_on_order');
$this->addSql('ALTER TABLE tourapp.email_template DROP variables');
$this->addSql('ALTER TABLE tourapp.product_travel DROP quantity');
$this->addSql('ALTER TABLE tourapp.product_default DROP quantity');
$this->addSql('CREATE SCHEMA public');
$this->addSql('DROP SEQUENCE tourapp.travelpay_reckoning_id_seq CASCADE');
$this->addSql('DROP TABLE tourapp.travelpay_reckoning');
$this->addSql('ALTER TABLE tourapp.bank_transaction DROP reference');
}
}