generated from ita-social-projects/DevTemplate
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added new column to big order table view (#1577)
- Loading branch information
1 parent
4aa31f5
commit d984f6b
Showing
10 changed files
with
274 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
185 changes: 185 additions & 0 deletions
185
dao/src/main/resources/db/changelog/logs/add-new-column-to-big_order_table-view.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog | ||
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd"> | ||
|
||
<changeSet id="2025-01-04-delete-big-order-table-view" author="Kizerov Dmytro"> | ||
<dropView viewName="big_order_table"/> | ||
</changeSet> | ||
|
||
<changeSet id="2025-01-04-add-new-column-to-big_order_table" author="Kizerov Dmytro"> | ||
<createView viewName="big_order_table" replaceIfExists="true"> | ||
WITH group_capacity AS ( | ||
SELECT | ||
obm.order_id, | ||
SUM(CASE | ||
WHEN bag.capacity = 120 AND bag.name_eng = 'Mix waste' THEN | ||
CASE | ||
WHEN (SELECT SUM(obm1.confirmed_quantity) | ||
FROM order_bag_mapping obm1 | ||
WHERE obm1.order_id = obm.order_id) IS NULL | ||
AND (SELECT SUM(obm2.exported_quantity) | ||
FROM order_bag_mapping obm2 | ||
WHERE obm2.order_id = obm.order_id) IS NULL | ||
THEN obm.amount | ||
WHEN (SELECT SUM(obm2.exported_quantity) | ||
FROM order_bag_mapping obm2 | ||
WHERE obm2.order_id = obm.order_id) IS NULL | ||
THEN obm.confirmed_quantity | ||
ELSE obm.exported_quantity | ||
END | ||
ELSE 0 | ||
END) AS mixed_waste_120, | ||
SUM(CASE | ||
WHEN bag.capacity = 60 AND bag.name_eng = 'Textile waste' THEN | ||
CASE | ||
WHEN (SELECT SUM(obm1.confirmed_quantity) | ||
FROM order_bag_mapping obm1 | ||
WHERE obm1.order_id = obm.order_id) IS NULL | ||
AND (SELECT SUM(obm2.exported_quantity) | ||
FROM order_bag_mapping obm2 | ||
WHERE obm2.order_id = obm.order_id) IS NULL | ||
THEN obm.amount | ||
WHEN (SELECT SUM(obm2.exported_quantity) | ||
FROM order_bag_mapping obm2 | ||
WHERE obm2.order_id = obm.order_id) IS NULL | ||
THEN obm.confirmed_quantity | ||
ELSE obm.exported_quantity | ||
END | ||
ELSE 0 | ||
END) AS textile_waste_60, | ||
SUM(CASE | ||
WHEN bag.capacity = 20 AND bag.name_eng = 'Textile waste' THEN | ||
CASE | ||
WHEN (SELECT SUM(obm1.confirmed_quantity) | ||
FROM order_bag_mapping obm1 | ||
WHERE obm1.order_id = obm.order_id) IS NULL | ||
AND (SELECT SUM(obm2.exported_quantity) | ||
FROM order_bag_mapping obm2 | ||
WHERE obm2.order_id = obm.order_id) IS NULL | ||
THEN obm.amount | ||
WHEN (SELECT SUM(obm2.exported_quantity) | ||
FROM order_bag_mapping obm2 | ||
WHERE obm2.order_id = obm.order_id) IS NULL | ||
THEN obm.confirmed_quantity | ||
ELSE obm.exported_quantity | ||
END | ||
ELSE 0 | ||
END) AS textile_waste_20, | ||
STRING_AGG( | ||
CASE | ||
WHEN bag.name_eng NOT IN ('Mix waste', 'Textile waste') THEN | ||
CASE | ||
WHEN (SELECT SUM(obm1.confirmed_quantity) | ||
FROM order_bag_mapping obm1 | ||
WHERE obm1.order_id = obm.order_id) IS NULL | ||
AND (SELECT SUM(obm2.exported_quantity) | ||
FROM order_bag_mapping obm2 | ||
WHERE obm2.order_id = obm.order_id) IS NULL | ||
THEN CONCAT(bag.name, ' ', bag.capacity, 'л - ', obm.amount, 'шт') | ||
WHEN (SELECT SUM(obm2.exported_quantity) | ||
FROM order_bag_mapping obm2 | ||
WHERE obm2.order_id = obm.order_id) IS NULL | ||
THEN CONCAT(bag.name, ' ', bag.capacity, 'л - ', obm.confirmed_quantity, 'шт') | ||
ELSE CONCAT(bag.name, ' ', bag.capacity, 'л - ', obm.exported_quantity, 'шт') | ||
END | ||
END, | ||
', ' | ||
) AS other_packages | ||
FROM | ||
order_bag_mapping obm | ||
LEFT JOIN | ||
bag ON obm.bag_id = bag.id | ||
GROUP BY | ||
obm.order_id | ||
) | ||
SELECT | ||
o.id AS id, | ||
o.order_status AS order_status, | ||
o.order_payment_status AS order_payment_status, | ||
CAST(o.order_date AS DATE) AS order_date, | ||
CAST((SELECT MAX(CAST(p.settlement_date AS DATE)) | ||
FROM payment p | ||
WHERE p.order_id = o.id AND o.order_payment_status = 'PAID') AS DATE) AS payment_date, | ||
CONCAT_WS(' ', uu.first_name, uu.last_name) AS client_name, | ||
uu.phone_number AS client_phone_number, | ||
uu.email AS client_email, | ||
CONCAT_WS(' ', uu.sender_first_name, uu.sender_last_name) AS sender_name, | ||
uu.sender_phone_number AS sender_phone, | ||
uu.sender_email AS sender_email, | ||
u.violations AS violations_amount, | ||
a.region AS region, | ||
a.city AS city, | ||
a.district AS district, | ||
CONCAT_WS(', ', | ||
CONCAT(a.street, ' ', a.house_number), | ||
CASE WHEN a.house_corpus IS NOT NULL AND a.house_corpus != '' THEN CONCAT('корп.', a.house_corpus) ELSE 'корп.- ' END, | ||
CASE WHEN a.entrance_number IS NOT NULL AND a.entrance_number != '' THEN CONCAT('п.', a.entrance_number) ELSE 'п.- ' END | ||
) AS address, | ||
a.address_comment AS comment_to_address_for_client, | ||
gc.mixed_waste_120, | ||
gc.textile_waste_60, | ||
gc.textile_waste_20, | ||
gc.other_packages, | ||
o.sum_total_amount_without_discounts AS total_order_sum, | ||
(select string_agg(c.code,', ') from certificate c where c.order_id=o.id) as order_certificate_code, | ||
cast(coalesce((select sum(c.points) from certificate c where c.order_id=o.id), 0) | ||
+ coalesce(o.points_to_use, 0) as bigint) as general_discount, | ||
cast(coalesce(o.sum_total_amount_without_discounts, 0) | ||
- (coalesce((select sum(p.amount) from payment p where p.order_id=o.id and p.payment_status='PAID'), 0) | ||
+ (coalesce((select sum(c.points) from certificate c where c.order_id=o.id), 0) * 100 | ||
+ coalesce(o.points_to_use, 0) * 100)) as bigint ) as amount_due, | ||
o.comment as comment_for_order_by_client, | ||
cast(coalesce((select sum(p.amount) from payment p where p.order_id=o.id and p.payment_status='PAID'), 0) | ||
+ (coalesce((select sum(c.points) from certificate c where c.order_id=o.id), 0) * 100 + coalesce(o.points_to_use, 0) * 100) as bigint) as total_payment, | ||
o.date_of_export as date_of_export, | ||
concat_ws('-', cast(o.deliver_from as time), cast (o.deliver_to as time)) as time_of_export, | ||
(select string_agg(oe.additional_order, '; ') from order_additional oe where oe.orders_id = o.id) as id_order_from_shop, | ||
r.name as receiving_station, | ||
r.id as receiving_station_id, | ||
|
||
(select concat_ws(', ',e.first_name,e.last_name) from employee_order_position eop | ||
left join employees e on eop.employee_id = e.id where order_id =o.id and eop.position_id=3 ) as responsible_logic_man, | ||
(select e.id from employee_order_position eop | ||
left join employees e on eop.employee_id = e.id where order_id =o.id and eop.position_id=3 ) as responsible_logic_man_id, | ||
|
||
(select concat_ws(', ',e.first_name,e.last_name) from employee_order_position eop | ||
left join employees e on eop.employee_id = e.id where order_id =o.id and eop.position_id=5 ) as responsible_driver, | ||
(select e.id from employee_order_position eop | ||
left join employees e on eop.employee_id = e.id where order_id =o.id and eop.position_id=5 ) as responsible_driver_id, | ||
|
||
(select concat_ws(', ',e.first_name,e.last_name) from employee_order_position eop | ||
left join employees e on eop.employee_id = e.id where order_id =o.id and eop.position_id=2 ) as responsible_caller, | ||
(select e.id from employee_order_position eop | ||
left join employees e on eop.employee_id = e.id where order_id =o.id and eop.position_id=2 ) as responsible_caller_id, | ||
|
||
(select concat_ws(', ',e.first_name,e.last_name) from employee_order_position eop | ||
left join employees e on eop.employee_id = e.id where order_id =o.id and eop.position_id=4 ) as responsible_navigator, | ||
(select e.id from employee_order_position eop | ||
left join employees e on eop.employee_id = e.id where order_id =o.id and eop.position_id=4 ) as responsible_navigator_id, | ||
o.blocked as is_blocked, | ||
concat_ws(', ',e.first_name,e.last_name) as blocked_by, | ||
a.region_en as region_en, | ||
a.city_en as city_en, | ||
a.district_en as district_en, | ||
a.region_id as region_id, | ||
a.city_id as city_id, | ||
a.district_id as district_id, | ||
concat_ws(', ',concat(a.street_en , ' ' , a.house_number), | ||
case when (a.house_corpus) is not null and a.house_corpus != '' then concat('b.',a.house_corpus) else 'b.- ' end , | ||
case when (a.entrance_number) is not null and a.entrance_number != '' then concat('e.', a.entrance_number) else 'e.- ' end) | ||
as address_en, | ||
o.tariffs_info_id as tariffs_info_id, | ||
o.admin_comment as comment_for_order_by_admin | ||
|
||
from orders o | ||
left join group_capacity gc ON o.id = gc.order_id | ||
left join employees e on o.employee_id = e.id | ||
left join receiving_stations r on o.receiving_station_id = r.id | ||
left join ubs_user uu on o.ubs_user_id = uu.id | ||
left join order_address a on uu.id = a.id | ||
left join users u on o.users_id = u.id; | ||
</createView> | ||
</changeSet> | ||
</databaseChangeLog> |
55 changes: 55 additions & 0 deletions
55
...ain/resources/db/changelog/logs/add-other-packages-to-column_width_for_employee-table.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog | ||
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd"> | ||
|
||
<changeSet id="2025-01-04-add-other-packages-to-column_width_for_employee" author="Kizerov Dmytro"> | ||
<addColumn tableName="column_width_for_employee"> | ||
<column name="other_packages" type="INT"/> | ||
</addColumn> | ||
</changeSet> | ||
|
||
<changeSet id="2025-01-04-update-column_width_for_employee" author="Kizerov Dmytro"> | ||
<sql> | ||
UPDATE column_width_for_employee | ||
SET address = 165, | ||
amount_due = 165, | ||
blocked_by = 165, | ||
city = 165, | ||
client_email = 165, | ||
client_name = 165, | ||
client_phone = 165, | ||
comment_for_order_by_client = 165, | ||
comment_to_address_for_client = 165, | ||
comments_for_order = 165, | ||
date_of_export = 165, | ||
district = 165, | ||
general_discount = 165, | ||
order_id = 165, | ||
id_order_from_shop = 165, | ||
order_certificate_code = 165, | ||
order_date = 165, | ||
order_payment_status = 165, | ||
order_status = 165, | ||
payment_date = 165, | ||
receiving_status = 165, | ||
region = 165, | ||
responsible_caller = 165, | ||
responsible_driver = 165, | ||
responsible_logic_man = 165, | ||
responsible_navigator = 165, | ||
sender_email = 165, | ||
sender_name = 165, | ||
sender_phone = 165, | ||
time_of_export = 165, | ||
total_order_sum = 165, | ||
total_payment = 165, | ||
violations_amount = 165, | ||
mixed_waste_120l = 106, | ||
textile_waste_60l = 106, | ||
textile_waste_20l = 106, | ||
other_packages = 106; | ||
</sql> | ||
</changeSet> | ||
</databaseChangeLog> |
13 changes: 13 additions & 0 deletions
13
dao/src/main/resources/db/changelog/logs/update-custom_table_view-table.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog | ||
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd"> | ||
|
||
<changeSet id="2025-01-04-update-custom_table_view" author="Kizerov Dmytro"> | ||
<sql> | ||
UPDATE custom_table_view | ||
SET titles = 'select,id,orderStatus,orderPaymentStatus,orderDate,paymentDate,commentsForOrder,clientName,clientPhone,clientEmail,senderName,senderPhone,senderEmail,violationsAmount,region,city,district,address,commentToAddressForClient,mixedWaste120L,textileWaste60L,textileWaste20L,otherPackages,totalOrderSum,orderCertificateCode,generalDiscount,amountDue,commentForOrderByClient,totalPayment,dateOfExport,timeOfExport,idOrderFromShop,receivingStation,responsibleCaller,responsibleLogicMan,responsibleDriver,responsibleNavigator,blockedBy'; | ||
</sql> | ||
</changeSet> | ||
</databaseChangeLog> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.