<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "出库未结算实时">
<query id = "FrmRptOutSend.doQueryData" desc = "查询未结算">
<![CDATA[
SELECT PRD_QTY,
       ACT_WGT,
       TALL_COUNT,
       TALL_WGT,
       ASKPLAN_ID,
       ORD_NO,
       ORD_SEQ,
       ORD_LN_DLY,
       PD_NAME,
       SPEC_NAME,
       SPEC_ABBSYMNAME,
       STEELNAME,
       MODEL_DESC,
       STD_STYLE_DESC,
       SALE_ORG_DESC,
       LOADVEHICLE_TYPE,
       BILL_STATUS,
       BALANCESTATUS,
       REALINVOICENO,
       STLMT_UNIT_NM,
       BILL_TICKET_STATUS,
       OUTSTOCK_TICKET_STATUS,
       TRANSMNY_TICKET_STATUS,
       SALE_AREA_DESC,
       ISPRECLOSE,
       PLAN_TRANS_TYPE,
       AGENCY_FL,
       DELVRY_ADDR,
       RECEIV_ADDR,
       REALINVOICENO1,
       CREATE_TIME,
       DELETE_TIME,
       BALANCESTATUS_ORG,
       DELIVERY_STATUS,
       RECV_UNIT,
       TO_NUMBER((CASE
         WHEN LOADVEHICLE_TYPE = '实单' AND BILL_STATUS IN ('关闭', '接收') AND
              REALINVOICENO IS NULL THEN
          PRD_QTY
         WHEN LOADVEHICLE_TYPE = '实单' AND BILL_STATUS = '执行' THEN
          TALL_COUNT
         WHEN LOADVEHICLE_TYPE = '虚单' AND ISPRECLOSE IN ('关闭', '已接收') AND
              REALINVOICENO IS NULL THEN
          PRD_QTY
         ELSE
          0
       END))ACT_COUNT,
       TO_NUMBER((CASE
         WHEN LOADVEHICLE_TYPE = '实单' AND BILL_STATUS IN ('关闭', '接收') AND
              REALINVOICENO IS NULL THEN
          ACT_WGT
         WHEN LOADVEHICLE_TYPE = '实单' AND BILL_STATUS = '执行' THEN
          TALL_WGT
         WHEN LOADVEHICLE_TYPE = '虚单' AND ISPRECLOSE IN ('关闭', '已接收') AND
              REALINVOICENO IS NULL THEN
          ACT_WGT
         ELSE
          0
       END)) ACT_WEIGHT
  FROM (SELECT SUM(S.PLAN_NUM) PRD_QTY,
               SUM(S.PLAN_WT) ACT_WGT,
               0 TALL_COUNT,
               0 TALL_WGT,
               S.BILL_NO ASKPLAN_ID,
               S.ORDER_NO ORD_NO,
               S.ORDER_SEQ ORD_SEQ,
               S.DELIVERY_NO ORD_LN_DLY,
               S.PRODUCNAME PD_NAME,
               S.SPEC_NAME,
               S.STD_NAME SPEC_ABBSYMNAME,
               S.STEELNAME,
               (SELECT T.FINAL_USER_DESC
                  FROM SLM_ORDER_LINE T
                 WHERE S.ORD_PK = T.ORD_PK
                   AND S.ORD_LN_PK = T.ORD_LN_PK) RECV_UNIT,
               (SELECT T.MODEL_DESC
                  FROM SLM_ORDER_LINE T
                 WHERE S.ORD_PK = T.ORD_PK
                   AND S.ORD_LN_PK = T.ORD_LN_PK) MODEL_DESC,
               (SELECT T1.STD_STYLE_DESC
                  FROM SLM_ORDER_LINE T1
                 WHERE S.ORD_PK = T1.ORD_PK
                   AND S.ORD_LN_PK = T1.ORD_LN_PK) STD_STYLE_DESC,
                MAX((SELECT (SELECT T3.BASENAME
          FROM COM_BASE_INFO T3
         WHERE T3.BASECODE = T2.DELIVERY_STATUS)DELIVERY_STATUS
          FROM SLM_ORDER_LINE_DELIVERY T2
         WHERE S.ORD_LN_DLY_PK = T2.ORD_LN_DLY_PK
           ))DELIVERY_STATUS,
               S.SALE_ORG_DESC,
               MAX(DECODE(S.LOADVEHICLE_TYPE, '1', '实单', '2', '虚单')) LOADVEHICLE_TYPE,
               MAX(DECODE(S.BILL_STATUS,
                          '0',
                          '未下发',
                          '1',
                          '下发',
                          '3',
                          '执行',
                          '4',
                          '关闭',
                          '5',
                          '接收')) BILL_STATUS,
               (SELECT MAX(DECODE(Y.BALANCESTATUS, '3', '已编单', '未编单'))
                  FROM SLM_BALANCEINFO Y
                 WHERE Y.ASKPLAN_ID = S.BILL_NO) BALANCESTATUS,
               MAX(S.REALINVOICENO) REALINVOICENO,
               MAX(S.STLMT_UNIT_NM) STLMT_UNIT_NM,
               MAX(DECODE(S.BILL_TICKET_STATUS,
                          '0',
                          '未对齐',
                          '1',
                          '已对齐',
                          '2',
                          '已接收')) BILL_TICKET_STATUS,
               MAX(DECODE(S.OUTSTOCK_TICKET_STATUS,
                          '0',
                          '未对齐',
                          '1',
                          '已对齐',
                          '2',
                          '已接收')) OUTSTOCK_TICKET_STATUS,
               MAX(DECODE(S.TRANSMNY_TICKET_STATUS,
                          '0',
                          '未对齐',
                          '1',
                          '已对齐',
                          '2',
                          '已接收')) TRANSMNY_TICKET_STATUS,
               (SELECT T2.SALE_AREA_DESC
                  FROM SLM_ORDER_HEAD T2
                 WHERE T2.ORD_PK = S.ORD_PK) SALE_AREA_DESC,
               MAX(DECODE(S.ISPRECLOSE,
                          '0',
                          '未关闭',
                          '1',
                          '关闭',
                          '2',
                          '已接收')) ISPRECLOSE,
               MAX(DECODE(S.PLAN_TRANS_TYPE,
                          '110501',
                          '汽运',
                          '110502',
                          '铁运',
                          '110503',
                          '船舶',
                          '110504',
                          '航运')) PLAN_TRANS_TYPE,
               MAX(DECODE(S.AGENCY_FL, '0', '无', '1', '有')) AGENCY_FL,
               MAX(S.DELVRY_ADDR) DELVRY_ADDR,
               MAX(S.RECEIV_ADDR) RECEIV_ADDR,
               MAX(S.REALINVOICENO1) REALINVOICENO1,
               MAX(TO_CHAR(S.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS')) CREATE_TIME,
               MAX(TO_CHAR(S.DELETE_TIME, 'YYYY-MM-DD HH24:MI:SS')) DELETE_TIME,
               (SELECT MAX(DECODE(Y1.BALANCESTATUS_ORG,
                                  '3',
                                  '已编单',
                                  '未编单'))
                  FROM SLM_BALANCEINFO Y1
                 WHERE Y1.ASKPLAN_ID = S.BILL_NO) BALANCESTATUS_ORG

          FROM YDM_ZC_BILL_M S
         WHERE S.LOADVEHICLE_TYPE = '1'
           AND S.BILL_STATUS IN ('4', '5')
           AND (S.REALINVOICENO IS NULL OR S.BILL_TICKET_STATUS = '0' OR
               S.OUTSTOCK_TICKET_STATUS = '0' OR
               S.TRANSMNY_TICKET_STATUS = '0')
        #CONDTIONS#
         GROUP BY S.BILL_NO,
                  S.ORDER_NO,
                  S.ORDER_SEQ,
                  S.DELIVERY_NO,
                  S.PRODUCNAME,
                  S.SPEC_NAME,
                  S.STD_NAME,
                  S.STEELNAME,
                  S.ORD_PK,
                  S.ORD_LN_PK,
                  S.SALE_ORG_DESC,
                  S.BILL_STATUS,
                  S.REALINVOICENO
        UNION ALL
        SELECT SUM(S.PLAN_NUM) PRD_QTY,
               SUM(S.PLAN_WT) ACT_WGT,
               (SELECT SUM(T5.STACKING_PIECE)
                  FROM YDM_ZC_LOADVEHICLE T5
                 WHERE T5.BILL_NO = S.BILL_NO
                   AND T5.AFFIRM_FLAG = '1'
                   AND S.BILL_STATUS = '3') TALL_COUNT,
               (SELECT SUM(T5.STACKING_WT)
                  FROM YDM_ZC_LOADVEHICLE T5
                 WHERE T5.BILL_NO = S.BILL_NO
                   AND T5.AFFIRM_FLAG = '1'
                   AND S.BILL_STATUS = '3') TALL_WGT,
               S.BILL_NO ASKPLAN_ID,
               S.ORDER_NO ORD_NO,
               S.ORDER_SEQ ORD_SEQ,
               S.DELIVERY_NO ORD_LN_DLY,
               S.PRODUCNAME PD_NAME,
               S.SPEC_NAME,
               S.STD_NAME SPEC_ABBSYMNAME,
               S.STEELNAME,
               (SELECT T.FINAL_USER_DESC
                  FROM SLM_ORDER_LINE T
                 WHERE S.ORD_PK = T.ORD_PK
                   AND S.ORD_LN_PK = T.ORD_LN_PK) RECV_UNIT,
               (SELECT T.MODEL_DESC
                  FROM SLM_ORDER_LINE T
                 WHERE S.ORD_PK = T.ORD_PK
                   AND S.ORD_LN_PK = T.ORD_LN_PK) MODEL_DESC,
               (SELECT T1.STD_STYLE_DESC
                  FROM SLM_ORDER_LINE T1
                 WHERE S.ORD_PK = T1.ORD_PK
                   AND S.ORD_LN_PK = T1.ORD_LN_PK) STD_STYLE_DESC,
                   MAX((SELECT (SELECT T3.BASENAME
          FROM COM_BASE_INFO T3
         WHERE T3.BASECODE = T2.DELIVERY_STATUS)DELIVERY_STATUS
          FROM SLM_ORDER_LINE_DELIVERY T2
         WHERE S.ORD_LN_DLY_PK = T2.ORD_LN_DLY_PK
           ))DELIVERY_STATUS,
               S.SALE_ORG_DESC,
               MAX(DECODE(S.LOADVEHICLE_TYPE, '1', '实单', '2', '虚单')) LOADVEHICLE_TYPE,
               MAX(DECODE(S.BILL_STATUS,
                          '0',
                          '未下发',
                          '1',
                          '下发',
                          '3',
                          '执行',
                          '4',
                          '关闭',
                          '5',
                          '接收')) BILL_STATUS,
               (SELECT MAX(DECODE(Y.BALANCESTATUS, '3', '已编单', '未编单'))
                  FROM SLM_BALANCEINFO Y
                 WHERE Y.ASKPLAN_ID = S.BILL_NO) BALANCESTATUS,
               MAX(S.REALINVOICENO) REALINVOICENO,
               MAX(S.STLMT_UNIT_NM) STLMT_UNIT_NM,
               MAX(DECODE(S.BILL_TICKET_STATUS,
                          '0',
                          '未对齐',
                          '1',
                          '已对齐',
                          '2',
                          '已接收')) BILL_TICKET_STATUS,
               MAX(DECODE(S.OUTSTOCK_TICKET_STATUS,
                          '0',
                          '未对齐',
                          '1',
                          '已对齐',
                          '2',
                          '已接收')) OUTSTOCK_TICKET_STATUS,
               MAX(DECODE(S.TRANSMNY_TICKET_STATUS,
                          '0',
                          '未对齐',
                          '1',
                          '已对齐',
                          '2',
                          '已接收')) TRANSMNY_TICKET_STATUS,
               (SELECT T2.SALE_AREA_DESC
                  FROM SLM_ORDER_HEAD T2
                 WHERE T2.ORD_PK = S.ORD_PK) SALE_AREA_DESC,
               MAX(DECODE(S.ISPRECLOSE,
                          '0',
                          '未关闭',
                          '1',
                          '关闭',
                          '2',
                          '已接收')) ISPRECLOSE,
               MAX(DECODE(S.PLAN_TRANS_TYPE,
                          '110501',
                          '汽运',
                          '110502',
                          '铁运',
                          '110503',
                          '船舶',
                          '110504',
                          '航运')) PLAN_TRANS_TYPE,
               MAX(DECODE(S.AGENCY_FL, '0', '无', '1', '有')) AGENCY_FL,
               MAX(S.DELVRY_ADDR) DELVRY_ADDR,
               MAX(S.RECEIV_ADDR) RECEIV_ADDR,
               MAX(S.REALINVOICENO1) REALINVOICENO1,
               MAX(TO_CHAR(S.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS')) CREATE_TIME,
               MAX(TO_CHAR(S.DELETE_TIME, 'YYYY-MM-DD HH24:MI:SS')) DELETE_TIME,
               (SELECT MAX(DECODE(Y1.BALANCESTATUS_ORG,
                                  '3',
                                  '已编单',
                                  '未编单'))
                  FROM SLM_BALANCEINFO Y1
                 WHERE Y1.ASKPLAN_ID = S.BILL_NO) BALANCESTATUS_ORG
          FROM YDM_ZC_BILL_M S
         WHERE S.LOADVEHICLE_TYPE = '1'
           AND S.BILL_STATUS = '3'
           #CONDTIONS#
         GROUP BY S.BILL_NO,
                  S.ORDER_NO,
                  S.ORDER_SEQ,
                  S.DELIVERY_NO,
                  S.PRODUCNAME,
                  S.SPEC_NAME,
                  S.STD_NAME,
                  S.STEELNAME,
                  S.ORD_PK,
                  S.ORD_LN_PK,
                  S.SALE_ORG_DESC,
                  S.BILL_STATUS,
                  S.REALINVOICENO
        UNION ALL
        SELECT SUM(S.PLAN_NUM) PRD_QTY,
               SUM(S.PLAN_WT) ACT_WGT,
               0 TALL_COUNT,
               0 TALL_WGT,
               S.BILL_NO ASKPLAN_ID,
               S.ORDER_NO ORD_NO,
               S.ORDER_SEQ ORD_SEQ,
               S.DELIVERY_NO ORD_LN_DLY,
               S.PRODUCNAME PD_NAME,
               S.SPEC_NAME,
               S.STD_NAME SPEC_ABBSYMNAME,
               S.STEELNAME,
               (SELECT T.FINAL_USER_DESC
                  FROM SLM_ORDER_LINE T
                 WHERE S.ORD_PK = T.ORD_PK
                   AND S.ORD_LN_PK = T.ORD_LN_PK) RECV_UNIT,
               (SELECT T.MODEL_DESC
                  FROM SLM_ORDER_LINE T
                 WHERE S.ORD_PK = T.ORD_PK
                   AND S.ORD_LN_PK = T.ORD_LN_PK) MODEL_DESC,
               (SELECT T1.STD_STYLE_DESC
                  FROM SLM_ORDER_LINE T1
                 WHERE S.ORD_PK = T1.ORD_PK
                   AND S.ORD_LN_PK = T1.ORD_LN_PK) STD_STYLE_DESC,
                   MAX((SELECT (SELECT T3.BASENAME
          FROM COM_BASE_INFO T3
         WHERE T3.BASECODE = T2.DELIVERY_STATUS)DELIVERY_STATUS
          FROM SLM_ORDER_LINE_DELIVERY T2
         WHERE S.ORD_LN_DLY_PK = T2.ORD_LN_DLY_PK
           ))DELIVERY_STATUS,
               S.SALE_ORG_DESC,
               MAX(DECODE(S.LOADVEHICLE_TYPE, '1', '实单', '2', '虚单')) LOADVEHICLE_TYPE,
               MAX(DECODE(S.BILL_STATUS,
                          '0',
                          '未下发',
                          '1',
                          '下发',
                          '3',
                          '执行',
                          '4',
                          '关闭',
                          '5',
                          '接收')) BILL_STATUS,
               (SELECT MAX(DECODE(Y.BALANCESTATUS, '3', '已编单', '未编单'))
                  FROM SLM_BALANCEINFO Y
                 WHERE Y.ASKPLAN_ID = S.BILL_NO) BALANCESTATUS,
               MAX(S.REALINVOICENO) REALINVOICENO,
               MAX(S.STLMT_UNIT_NM) STLMT_UNIT_NM,
               MAX(DECODE(S.BILL_TICKET_STATUS,
                          '0',
                          '未对齐',
                          '1',
                          '已对齐',
                          '2',
                          '已接收')) BILL_TICKET_STATUS,
               MAX(DECODE(S.OUTSTOCK_TICKET_STATUS,
                          '0',
                          '未对齐',
                          '1',
                          '已对齐',
                          '2',
                          '已接收')) OUTSTOCK_TICKET_STATUS,
               MAX(DECODE(S.TRANSMNY_TICKET_STATUS,
                          '0',
                          '未对齐',
                          '1',
                          '已对齐',
                          '2',
                          '已接收')) TRANSMNY_TICKET_STATUS,
               (SELECT T2.SALE_AREA_DESC
                  FROM SLM_ORDER_HEAD T2
                 WHERE T2.ORD_PK = S.ORD_PK) SALE_AREA_DESC,
               MAX(DECODE(S.ISPRECLOSE,
                          '0',
                          '未关闭',
                          '1',
                          '关闭',
                          '2',
                          '已接收')) ISPRECLOSE,
               MAX(DECODE(S.PLAN_TRANS_TYPE,
                          '110501',
                          '汽运',
                          '110502',
                          '铁运',
                          '110503',
                          '船舶',
                          '110504',
                          '航运')) PLAN_TRANS_TYPE,
               MAX(DECODE(S.AGENCY_FL, '0', '无', '1', '有')) AGENCY_FL,
               MAX(S.DELVRY_ADDR) DELVRY_ADDR,
               MAX(S.RECEIV_ADDR) RECEIV_ADDR,
               MAX(S.REALINVOICENO1) REALINVOICENO1,
               MAX(TO_CHAR(S.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS')) CREATE_TIME,
               MAX(TO_CHAR(S.DELETE_TIME, 'YYYY-MM-DD HH24:MI:SS')) DELETE_TIME,
               (SELECT MAX(DECODE(Y1.BALANCESTATUS_ORG,
                                  '3',
                                  '已编单',
                                  '未编单'))
                  FROM SLM_BALANCEINFO Y1
                 WHERE Y1.ASKPLAN_ID = S.BILL_NO) BALANCESTATUS_ORG
          FROM YDM_ZC_BILL_M S
         WHERE S.LOADVEHICLE_TYPE = '2'
           AND S.ISPRECLOSE IN ('1', '2')
           AND (S.REALINVOICENO IS NULL OR S.BILL_TICKET_STATUS = '0' OR
               S.OUTSTOCK_TICKET_STATUS = '0' OR
               S.TRANSMNY_TICKET_STATUS = '0')
        #CONDTIONS#
         GROUP BY S.BILL_NO,
                  S.ORDER_NO,
                  S.ORDER_SEQ,
                  S.DELIVERY_NO,
                  S.PRODUCNAME,
                  S.SPEC_NAME,
                  S.STD_NAME,
                  S.STEELNAME,
                  S.ORD_PK,
                  S.ORD_LN_PK,
                  S.SALE_ORG_DESC,
                  S.BILL_STATUS,
                  S.REALINVOICENO)
 ]]>
</query>

</queryMap>