diff --git a/src/main/resources/mapper/outboundNotification/OutboundNotificationHeadMapper.xml b/src/main/resources/mapper/outboundNotification/OutboundNotificationHeadMapper.xml
index 23654e6..bd15845 100644
--- a/src/main/resources/mapper/outboundNotification/OutboundNotificationHeadMapper.xml
+++ b/src/main/resources/mapper/outboundNotification/OutboundNotificationHeadMapper.xml
@@ -8,12 +8,16 @@
SELECT
a.site,
a.bu_no,
- dbo.get_bu_desc(a.site, a.bu_no) as buDesc,
+ dbo.get_bu_desc(a.site, a.bu_no) AS buDesc,
a.order_no,
a.order_type,
a.order_status,
- a.customer_id,
- b.customerName,
+ COALESCE(NULLIF(LTRIM(RTRIM(a.customer_id)), ''), s.SupplierID) AS customer_id,
+ COALESCE(
+ NULLIF(LTRIM(RTRIM(b.customerName)), ''),
+ NULLIF(LTRIM(RTRIM(s.SupplierName)), ''),
+ ''
+ ) AS customerName,
a.related_order_no,
a.related_order_line_no,
a.required_outbound_date,
@@ -41,19 +45,20 @@
a.out_warehouse,
a.customer_order_no,
a.show_in_query_flag
- FROM outbound_notification_head as a
- left join Customer as b on a.site = b.site and a.customer_id = b.CustomerID
+ FROM outbound_notification_head AS a
+ LEFT JOIN Customer AS b ON a.site = b.site AND LTRIM(RTRIM(a.customer_id)) = b.CustomerID
+ LEFT JOIN Supplier AS s ON a.site = s.site AND (NULLIF(LTRIM(RTRIM(a.customer_id)), '') IS NULL OR b.CustomerID IS NULL) AND LTRIM(RTRIM(a.customer_id)) = s.SupplierID
- a.site in (select site from AccessSite where userID = #{query.userName})
- and a.bu_no in (select bu_no from AccessBu where username = #{query.userName})
+ a.site IN (SELECT site FROM AccessSite WHERE userID = #{query.userName})
+ AND a.bu_no IN (SELECT bu_no FROM AccessBu WHERE username = #{query.userName})
- AND a.order_no like '%' + #{query.orderNo} + '%'
+ AND a.order_no LIKE '%' + #{query.orderNo} + '%'
AND a.order_type = #{query.orderType}
- AND a.order_status in
+ AND a.order_status IN
#{item}
@@ -65,12 +70,16 @@
AND #{query.endDate} >= a.required_outbound_date
- AND a.customer_id like '%' + #{query.customerId} + '%'
+ AND a.customer_id LIKE '%' + #{query.customerId} + '%'
- AND b.customerName like '%' + #{query.customerName} + '%'
+ AND (
+ b.customerName LIKE '%' + #{query.customerName} + '%'
+ OR s.SupplierName LIKE '%' + #{query.customerName} + '%'
+ )
+ ORDER BY a.created_date DESC;