migrations/Version20250106183714.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. /**
  7.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20250106183714 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return '';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         $this->addSql('ALTER TABLE tourapp.travel_members ADD order_note TEXT DEFAULT NULL');
  18.         $this->addSql('ALTER TABLE tourapp.travel ADD opt_note_on_order BOOLEAN DEFAULT false NOT NULL');
  19.         $this->addSql('ALTER TABLE tourapp.travel ADD opt_participant_free BOOLEAN DEFAULT false NOT NULL');
  20.         $this->addSql('ALTER TABLE tourapp.email_template ADD variables JSON DEFAULT NULL');
  21. //        $this->addSql('ALTER TABLE tourapp.travel_members ADD CONSTRAINT FK_5B052B5BECAB15B3 FOREIGN KEY (travel_id) REFERENCES tourapp.travel (travel_id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  22. //        $this->addSql('CREATE INDEX IDX_5B052B5BECAB15B3 ON tourapp.travel_members (travel_id)');
  23.         $this->addSql('ALTER TABLE tourapp.travel RENAME COLUMN group_name TO label');
  24.         $this->addSql('ALTER TABLE tourapp.travel_members_participant ADD role VARCHAR(255);');
  25.         $this->addSql('UPDATE tourapp.travel_members_participant SET role = \'PARTICIPANT\' WHERE role IS NULL;');
  26.         $this->addSql('ALTER TABLE tourapp.travel_members_participant ALTER COLUMN role SET NOT NULL;');
  27.         $this->addSql('ALTER TABLE tourapp.product_default ADD quantity INT');
  28.         $this->addSql('ALTER TABLE tourapp.product_travel ADD quantity INT');
  29.         $this->addSql('CREATE SEQUENCE tourapp.travelpay_reckoning_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
  30.         $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))');
  31.         $this->addSql('ALTER TABLE tourapp.bank_transaction ADD reference VARCHAR(255) DEFAULT NULL');
  32.         $this->addSql('
  33.             UPDATE tourapp.email_template
  34.             SET variables = \'{
  35.                 "travel_id": {
  36.                     "description": "ID wycieczki",
  37.                     "value": null
  38.                 },
  39.                 "travel_name": {
  40.                     "description": "Nazwa wycieczki",
  41.                     "value": null
  42.                 },
  43.                 "company": {
  44.                     "description": "Firma",
  45.                     "value": null
  46.                 },
  47.                 "coordinator": {
  48.                     "description": "Koordynator",
  49.                     "value": null
  50.                 },
  51.                 "travel_date_compartment": {
  52.                     "description": "Zakres dat podróży",
  53.                     "value": null
  54.                 },
  55.                 "username": {
  56.                     "description": "Nazwa użytkownika",
  57.                     "value": null
  58.                 },
  59.                 "userpassword": {
  60.                     "description": "Hasło użytkownika",
  61.                     "value": null
  62.                 },
  63.                 "homelink": {
  64.                     "description": "Link do strony głównej",
  65.                     "value": null
  66.                 }
  67.             }\'
  68.             WHERE email_template_id=1;');
  69.         $this->addSql('
  70.             UPDATE tourapp.email_template
  71.             SET variables = \'{
  72.               "travel_id": {
  73.                 "description": "ID wycieczki",
  74.                 "value": null
  75.               },
  76.               "memberiban": {
  77.                 "description": "Numer konta do wpłat zamawiającego",
  78.                 "value": null
  79.               },
  80.               "payulink": {
  81.                 "description": "Link do płatności online",
  82.                 "value": null
  83.               },
  84.               "harmonogram_platnosci": {
  85.                 "description": "Harmonogram płatności",
  86.                 "value": null
  87.               },
  88.               "tresc_o_ubezpieczeniu_kr": {
  89.                 "description": "Treść o ubezpieczeniu (KR)",
  90.                 "value": null
  91.               },
  92.               "nr_rezerwacji": {
  93.                 "description": "Numer rezerwacji",
  94.                 "value": null
  95.               }
  96.             }\'
  97.             WHERE email_template_id=2;');
  98.         $this->addSql('
  99.             UPDATE tourapp.email_template
  100.             SET variables = \'{
  101.               "travel_id": {
  102.                 "description": "ID wycieczki",
  103.                 "value": null
  104.               },
  105.               "payulink": {
  106.                 "description": "Link do płatności online",
  107.                 "value": null
  108.               },
  109.               "memberiban": {
  110.                 "description": "Numer konta do wpłat zamawiającego",
  111.                 "value": null
  112.               },
  113.               "harmonogram_platnosci": {
  114.                 "description": "Harmonogram płatności",
  115.                 "value": null
  116.               },
  117.               "faktura": {
  118.                 "description": "Status faktury wymagana / nie wymagana",
  119.                 "value": null
  120.               },
  121.               "tresc_o_ubezpieczeniu_kr": {
  122.                 "description": "Treść o ubezpieczeniu (KR)",
  123.                 "value": null
  124.               },
  125.               "nr_rezerwacji": {
  126.                 "description": "Numer rezerwacji",
  127.                 "value": null
  128.               }
  129.             }\'
  130.             WHERE email_template_id=3;');
  131.         $this->addSql('
  132.             UPDATE tourapp.email_template
  133.             SET variables = \'{
  134.               "travel_id": {
  135.                 "description": "ID wycieczki",
  136.                 "value": null
  137.               },
  138.               "travel_name": {
  139.                 "description": "Nazwa wycieczki",
  140.                 "value": null
  141.               },
  142.               "company": {
  143.                 "description": "Firma",
  144.                 "value": null
  145.               },
  146.               "coordinator": {
  147.                 "description": "Koordynator",
  148.                 "value": null
  149.               },
  150.               "travel_date_compartment": {
  151.                 "description": "Zakres dat podróży",
  152.                 "value": null
  153.               },
  154.               "travelprice": {
  155.                 "description": "Cena podróży - wycieczka",
  156.                 "value": null
  157.               },
  158.               "orderfullname": {
  159.                 "description": "Imię i nazwisko zamawiającego",
  160.                 "value": null
  161.               },
  162.               "ordermemberlist": {
  163.                 "description": "Lista członków zamówienia",
  164.                 "value": null
  165.               },
  166.               "payrest": {
  167.                 "description": "Pozostała kwota do zapłaty",
  168.                 "value": null
  169.               },
  170.               "memberiban": {
  171.                 "description": "Numer konta do wpłat zamawiającego",
  172.                 "value": null
  173.               },
  174.               "payulink": {
  175.                 "description": "Link do płatności online",
  176.                 "value": null
  177.               },
  178.               "paid": {
  179.                 "description": "Kwota zapłacona",
  180.                 "value": null
  181.               },
  182.               "harmonogram_platnosci": {
  183.                 "description": "Harmonogram płatności",
  184.                 "value": null
  185.               },
  186.               "faktura": {
  187.                 "description": "Status faktury wymagana / nie wymagana",
  188.                 "value": null
  189.               },
  190.               "tresc_o_ubezpieczeniu_kr": {
  191.                 "description": "Treść o ubezpieczeniu (KR)",
  192.                 "value": null
  193.               },
  194.               "nr_rezerwacji": {
  195.                 "description": "Numer rezerwacji",
  196.                 "value": null
  197.               }
  198.             }\'
  199.             WHERE email_template_id=4;');
  200.         $this->addSql('
  201.             UPDATE tourapp.email_template
  202.             SET variables = \'{
  203.                 "travel_id": {
  204.                     "description": "ID wycieczki",
  205.                     "value": null
  206.                 },
  207.                 "travel_name": {
  208.                     "description": "Nazwa wycieczki",
  209.                     "value": null
  210.                 },
  211.                 "company": {
  212.                     "description": "Firma",
  213.                     "value": null
  214.                 },
  215.                 "coordinator": {
  216.                     "description": "Koordynator",
  217.                     "value": null
  218.                 },
  219.                 "travel_date_compartment": {
  220.                     "description": "Zakres dat podróży",
  221.                     "value": null
  222.                 },
  223.                 "payulink": {
  224.                     "description": "Link do płatności online",
  225.                     "value": null
  226.                 },
  227.                 "homelink": {
  228.                     "description": "Link do strony głównej",
  229.                     "value": null
  230.                 },
  231.                 "harmonogram_platnosci": {
  232.                     "description": "Harmonogram płatności",
  233.                     "value": null
  234.                 },
  235.                 "tresc_o_ubezpieczeniu_kr": {
  236.                     "description": "Treść o ubezpieczeniu (KR)",
  237.                     "value": null
  238.                 }
  239.             }\'
  240.             WHERE email_template_id=5;');
  241.         $this->addSql('
  242.             UPDATE tourapp.email_template
  243.             SET variables = \'{
  244.               "travel_id": {
  245.                 "description": "ID wycieczki",
  246.                 "value": null
  247.               },
  248.               "memberiban": {
  249.                 "description": "Numer konta do wpłat zamawiającego",
  250.                 "value": null
  251.               },
  252.               "harmonogram_platnosci": {
  253.                 "description": "Harmonogram płatności",
  254.                 "value": null
  255.               },
  256.               "tresc_o_ubezpieczeniu_kr": {
  257.                 "description": "Treść o ubezpieczeniu (KR)",
  258.                 "value": null
  259.               },
  260.               "nr_rezerwacji": {
  261.                 "description": "Numer rezerwacji",
  262.                 "value": null
  263.               }
  264.             }\'
  265.             WHERE email_template_id=6;');
  266.         $this->addSql('
  267.             UPDATE tourapp.email_template
  268.             SET variables = \'{
  269.               "travel_id": {
  270.                 "description": "ID wycieczki",
  271.                 "value": null
  272.               },
  273.               "payulink": {
  274.                 "description": "Link do płatności online",
  275.                 "value": null
  276.               },
  277.               "memberiban": {
  278.                 "description": "Numer konta do wpłat zamawiającego",
  279.                 "value": null
  280.               },
  281.               "harmonogram_platnosci": {
  282.                 "description": "Harmonogram płatności",
  283.                 "value": null
  284.               },
  285.               "tresc_o_ubezpieczeniu_kr": {
  286.                 "description": "Treść o ubezpieczeniu (KR)",
  287.                 "value": null
  288.               },
  289.               "nr_rezerwacji": {
  290.                 "description": "Numer rezerwacji",
  291.                 "value": null
  292.               }
  293.             }\'
  294.             WHERE email_template_id=7;');
  295.         $this->addSql('
  296.             UPDATE tourapp.email_template
  297.             SET variables = \'{
  298.               "travel_id": {
  299.                 "description": "ID wycieczki",
  300.                 "value": null
  301.               },
  302.               "transferamount": {
  303.                 "description": "Kwota wpłaty",
  304.                 "value": null
  305.               },
  306.               "travel_name": {
  307.                 "description": "Nazwa wycieczki",
  308.                 "value": null
  309.               },
  310.               "company": {
  311.                 "description": "Firma",
  312.                 "value": null
  313.               },
  314.               "coordinator": {
  315.                 "description": "Koordynator",
  316.                 "value": null
  317.               },
  318.               "travel_date_compartment": {
  319.                 "description": "Zakres dat podróży",
  320.                 "value": null
  321.               },
  322.               "travelprice": {
  323.                 "description": "Cena podróży - wycieczka",
  324.                 "value": null
  325.               },
  326.               "payrest": {
  327.                 "description": "Pozostała kwota do zapłaty",
  328.                 "value": null
  329.               },
  330.               "memberiban": {
  331.                 "description": "Numer konta do wpłat zamawiającego",
  332.                 "value": null
  333.               },
  334.               "payulink": {
  335.                 "description": "Link do płatności online",
  336.                 "value": null
  337.               },
  338.               "paid": {
  339.                 "description": "Kwota zapłacona",
  340.                 "value": null
  341.               },
  342.               "harmonogram_platnosci": {
  343.                 "description": "Harmonogram płatności",
  344.                 "value": null
  345.               },
  346.               "faktura": {
  347.                 "description": "Status faktury wymagana / nie wymagana",
  348.                 "value": null
  349.               },
  350.               "tresc_o_ubezpieczeniu_kr": {
  351.                 "description": "Treść o ubezpieczeniu (KR)",
  352.                 "value": null
  353.               },
  354.               "nr_rezerwacji": {
  355.                 "description": "Numer rezerwacji",
  356.                 "value": null
  357.               }
  358.             }\'
  359.             WHERE email_template_id=8;');
  360.         $this->addSql('
  361.             UPDATE tourapp.email_template
  362.             SET variables = \'{
  363.               "travel_id": {
  364.                 "description": "ID wycieczki",
  365.                 "value": null
  366.               },
  367.               "travel_name": {
  368.                 "description": "Nazwa wycieczki",
  369.                 "value": null
  370.               },
  371.               "company": {
  372.                 "description": "Firma",
  373.                 "value": null
  374.               },
  375.               "coordinator": {
  376.                 "description": "Koordynator",
  377.                 "value": null
  378.               },
  379.               "travel_date_compartment": {
  380.                 "description": "Zakres dat podróży",
  381.                 "value": null
  382.               },
  383.               "payulink": {
  384.                 "description": "Link do płatności online",
  385.                 "value": null
  386.               },
  387.               "homelink": {
  388.                 "description": "Link do strony głównej",
  389.                 "value": null
  390.               },
  391.               "harmonogram_platnosci": {
  392.                 "description": "Harmonogram płatności",
  393.                 "value": null
  394.               },
  395.               "tresc_o_ubezpieczeniu_kr": {
  396.                 "description": "Treść o ubezpieczeniu (KR)",
  397.                 "value": null
  398.               }
  399.             }\'
  400.             WHERE email_template_id=9;');
  401.         $this->addSql('
  402.             UPDATE tourapp.email_template
  403.             SET variables = \'{
  404.               "user_login": {
  405.                 "description": "Login użytkownika",
  406.                 "value": null
  407.               },
  408.               "user_change_password_url": {
  409.                 "description": "Link do zmiany hasła",
  410.                 "value": null
  411.               }
  412.             }\'
  413.             WHERE email_template_id=10;');
  414.         $this->addSql('
  415.             UPDATE tourapp.email_template
  416.             SET variables = \'{
  417.               "travel_id": {
  418.                 "description": "ID wycieczki",
  419.                 "value": null
  420.               },
  421.               "travel_name": {
  422.                 "description": "Nazwa wycieczki",
  423.                 "value": null
  424.               },
  425.               "company": {
  426.                 "description": "Firma",
  427.                 "value": null
  428.               },
  429.               "coordinator": {
  430.                 "description": "Koordynator",
  431.                 "value": null
  432.               },
  433.               "travel_date_compartment": {
  434.                 "description": "Zakres dat podróży",
  435.                 "value": null
  436.               },
  437.               "orderfullname": {
  438.                 "description": "Imię i nazwisko zamawiającego",
  439.                 "value": null
  440.               },
  441.               "ordermemberlist": {
  442.                 "description": "Lista członków zamówienia",
  443.                 "value": null
  444.               },
  445.               "nr_rezerwacji": {
  446.                 "description": "Numer rezerwacji",
  447.                 "value": null
  448.               }
  449.             }\'
  450.             WHERE email_template_id=11;');
  451.         $this->addSql('
  452.             UPDATE tourapp.email_template
  453.             SET variables = \'{
  454.               "link_ankieta": {
  455.                 "description": "Link do ankiety",
  456.                 "value": null
  457.               }
  458.             }\'
  459.             WHERE email_template_id=12;');
  460.         $this->addSql('
  461.             UPDATE tourapp.email_template
  462.             SET variables = \'{
  463.               "orderId": {
  464.                 "description": "ID zamówienia",
  465.                 "value": null
  466.               },
  467.               "travelId": {
  468.                 "description": "ID wycieczki",
  469.                 "value": null
  470.               },
  471.               "travelName": {
  472.                 "description": "Nazwa wycieczki",
  473.                 "value": null
  474.               },
  475.               "travelFrom": {
  476.                 "description": "Data rozpoczęcia wycieczki",
  477.                 "value": null
  478.               },
  479.               "travelTo": {
  480.                 "description": "Data zakończenia wycieczki",
  481.                 "value": null
  482.               }
  483.             }\'
  484.             WHERE email_template_id=13;
  485.         ');
  486.         $this->addSql('
  487.             UPDATE tourapp.travel_members_participant tp set
  488.                 travel_member_participant_bday = x.travel_member_participant_bday2,
  489.                 travel_member_participant_document_release_date = x.travel_member_participant_document_release_date2,
  490.                 travel_member_participant_document_expiration_date = x.travel_member_participant_document_expiration_date2
  491.             from (
  492.                 select
  493.                     *,
  494.                     CASE
  495.                         WHEN travel_member_participant_bday ~ \'^\d{2}\.\d{2}\.\d{4}$\'
  496.                             THEN TO_DATE(travel_member_participant_bday, \'DD.MM.YYYY\')
  497.                         WHEN travel_member_participant_bday ~ \'^\d{4}-\d{2}-\d{2}$\'
  498.                             THEN travel_member_participant_bday::DATE
  499.                         ELSE NULL  -- Opcjonalnie obsłuż inne formaty
  500.                     END AS travel_member_participant_bday2,
  501.                     CASE
  502.                         WHEN travel_member_participant_document_release_date ~ \'^\d{2}\.\d{2}\.\d{4}$\'
  503.                             THEN TO_DATE(travel_member_participant_document_release_date, \'DD.MM.YYYY\')
  504.                         WHEN travel_member_participant_document_release_date ~ \'^\d{4}-\d{2}-\d{2}$\'
  505.                             THEN travel_member_participant_document_release_date::DATE
  506.                         ELSE NULL  -- Opcjonalnie obsłuż inne formaty
  507.                     END AS travel_member_participant_document_release_date2,
  508.                     CASE
  509.                         WHEN travel_member_participant_document_expiration_date ~ \'^\d{2}\.\d{2}\.\d{4}$\'
  510.                             THEN TO_DATE(travel_member_participant_document_expiration_date, \'DD.MM.YYYY\')
  511.                         WHEN travel_member_participant_document_expiration_date ~ \'^\d{4}-\d{2}-\d{2}$\'
  512.                             THEN travel_member_participant_document_expiration_date::DATE
  513.                         ELSE NULL  -- Opcjonalnie obsłuż inne formaty
  514.                     END AS travel_member_participant_document_expiration_date2
  515.                 from (
  516.                     SELECT
  517.                         travel_member_participant_id,
  518.                         replace(travel_member_participant_bday,\'\'\'\',\'\') as travel_member_participant_bday,
  519.                         replace(travel_member_participant_document_release_date,\'\'\'\',\'\') as travel_member_participant_document_release_date,
  520.                         replace(travel_member_participant_document_expiration_date,\'\'\'\',\'\') as travel_member_participant_document_expiration_date
  521.                     FROM tourapp.travel_members_participant
  522.                 ) w
  523.             ) x
  524.             where tp.travel_member_participant_id = x.travel_member_participant_id
  525.         ');
  526.         $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;');
  527.         $this->addSql('ALTER TABLE tourapp.travel_members_participant ALTER COLUMN travel_member_participant_bday TYPE date USING travel_member_participant_bday::date;');
  528.         $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;');
  529.         $this->addSql('
  530.             UPDATE tourapp.travel_members tm
  531.             SET
  532.                 travel_member_terminate_pay_deadline_cost_1 = x."Kwota raty 1 - zamowienie",
  533.                 travel_member_terminate_pay_deadline_cost_2 = x."Kwota raty 2 - zamowienie",
  534.                 travel_member_terminate_pay_deadline_cost_3 = x."Kwota raty 3 - zamowienie"
  535.             FROM (
  536.                 select
  537.                     *
  538.                 from (
  539.                     select
  540.                         *,
  541.                         case
  542.                             when (
  543.                             ("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)
  544.                             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)
  545.                             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)
  546.                             ) then \'Przypadek brak terminu na zamowieniu a na wycieczce widnieje\'
  547.                             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\'
  548.                         else \'brak\'
  549.                     end as type_error
  550.                     from (
  551.                         select
  552.                             travel_member_id as "Id zamowienia",
  553.                             travel_id as "Id wycieczki",
  554.                             travel_focus_id as "Id wycieczki klienta",
  555.                             travel_costofthetour as "Cena wycieczki",
  556.                             travel_cost_terminate_pay_deadline_1 as "Koszt raty 1 - wycieczka",
  557.                             travel_date_terminate_pay_deadline_1 as "Data raty 1 - wycieczka",
  558.                             travel_days_terminate_pay_deadline_1_status as "Status dni od zapisu",
  559.                             travel_cost_terminate_pay_deadline_2 as "Koszt raty 2 - wycieczka",
  560.                             travel_date_terminate_pay_deadline_2 as "Data raty 2 - wycieczka",
  561.                             travel_date_terminate_pay as "Data zapłaty - ostateczna",
  562.                             rata_data_1 as "Data raty 1 - zamowienie",
  563.                             rata_data_2 as "Data raty 2 - zamowienie",
  564.                             rata_data_3 as "Data raty 3 - zamowienie",
  565.                             case when rata_data_1 is null then 0 else coalesce(rata_kwota_1,0) end as "Kwota raty 1 - zamowienie",
  566.                             case when rata_data_2 is null then 0 else coalesce(rata_kwota_2,0) end as "Kwota raty 2 - zamowienie",
  567.                             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",
  568.                             --travel_days_terminate_pay_deadline_1_status,
  569.                             travel_member_participant_topay as "Cena domyślna za wycieczkę"
  570.                         from (
  571.                             select
  572.                                 travel_member_id,
  573.                                 travel_id,
  574.                                 travel_focus_id,
  575.                                 travel_costofthetour,
  576.                                 travel_date_terminate_pay,
  577.                                 travel_cost_terminate_pay_deadline_1,
  578.                                 travel_date_terminate_pay_deadline_1,
  579.                                 travel_cost_terminate_pay_deadline_2,
  580.                                 travel_date_terminate_pay_deadline_2,
  581.                                 rata_data_1,
  582.                                 rata_data_2,
  583.                                 rata_data_3,
  584.                                 case when rata_data_1 is null then 0 else coalesce(rata_kwota_1,0) end as rata_kwota_1,
  585.                                 case when rata_data_2 is null then 0 else coalesce(rata_kwota_2,0) end as rata_kwota_2,
  586.                                 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,
  587.                                 travel_days_terminate_pay_deadline_1_status,
  588.                                 travel_member_participant_topay,
  589.                                 created_at
  590.                             from (
  591.                                 SELECT
  592.                                     tm.travel_member_id,
  593.                                     tm.travel_id,
  594.                                     tm.travel_focus_id,
  595.                                     t.travel_costofthetour,
  596.                                     tmp.travel_member_participant_topay,
  597.                                     t.travel_date_terminate_pay,
  598.                                     t.travel_cost_terminate_pay_deadline_1,
  599.                                     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,
  600.                                     t.travel_cost_terminate_pay_deadline_2,
  601.                                     t.travel_date_terminate_pay_deadline_2,
  602.                                     tm.travel_member_terminate_pay_deadline_date_1 AS rata_data_1,
  603.                                     --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,
  604.                                     t.travel_cost_terminate_pay_deadline_1 AS rata_kwota_1,
  605.                                     tm.travel_member_terminate_pay_deadline_date_2 AS rata_data_2,
  606.                                     t.travel_cost_terminate_pay_deadline_2 AS rata_kwota_2,
  607.                                     tm.travel_member_terminate_pay_deadline_date_3 AS rata_data_3,
  608.                                     CASE
  609.                                         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
  610.                                         THEN 0
  611.                                         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))
  612.                                     END AS rata_kwota_3,
  613.                                     t.travel_days_terminate_pay_deadline_1_status,
  614.                                     tm.created_at::date
  615.                                 FROM tourapp.travel_members tm
  616.                                 JOIN tourapp.travel t ON tm.travel_id = t.travel_id
  617.                                 left join (
  618.                                     select
  619.                                         tm.travel_member_id,
  620.                                         tmp.travel_member_participant_topay
  621.                                     from tourapp.travel_members tm
  622.                                     join tourapp.travel_members_participant tmp on tm.travel_member_id = tmp.travel_member_id --and tmp.travel_member_participant_status
  623.                                     group by
  624.                                         tm.travel_member_id,
  625.                                         tmp.travel_member_participant_topay
  626.                                 ) tmp on tm.travel_member_id = tmp.travel_member_id
  627.                             ) w
  628.                         ) w
  629.                         where true
  630.                     ) w
  631.                 ) w
  632.             ) x
  633.             WHERE tm.travel_member_id = x."Id zamowienia";
  634.         ');
  635.     }
  636.     public function down(Schema $schema): void
  637.     {
  638.         $this->addSql('ALTER TABLE tourapp.travel_members DROP order_note');
  639.         $this->addSql('ALTER TABLE tourapp.travel DROP opt_note_on_order');
  640.         $this->addSql('ALTER TABLE tourapp.email_template DROP variables');
  641.         $this->addSql('ALTER TABLE tourapp.product_travel DROP quantity');
  642.         $this->addSql('ALTER TABLE tourapp.product_default DROP quantity');
  643.         $this->addSql('CREATE SCHEMA public');
  644.         $this->addSql('DROP SEQUENCE tourapp.travelpay_reckoning_id_seq CASCADE');
  645.         $this->addSql('DROP TABLE tourapp.travelpay_reckoning');
  646.         $this->addSql('ALTER TABLE tourapp.bank_transaction DROP reference');
  647.     }
  648. }