<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "销售出库">
<query id = "FrmOutList.getOutList" desc = "查询销售出库">
<![CDATA[
SELECT 
       to_char(to_date(t.BAL_YEAR_MONTH,'YYYY-MM'),'yyyy-MM') as BAL_YEAR_MONTH,
       
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       T.MATERIAL_NO,
       T.MATERIAL_NAME,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.STD_CODE,
       T.STD_NAME,
       T.GRADECODE,
       T.GRADENAME,
       T.STEELCODE,
       T.STEELNAME,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.SPEC_CODE,
       T.SPEC_NAME,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.PRO_ORDER_NO,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.ACT_DIMATER,
       T.ACT_HEIGHT,

       T.ACT_LEN_MIN,
       T.ACT_LEN_MAX,
       SUM(T.ACT_LEN)ACT_LEN,
       sum(T.ACT_COUNT) ACT_COUNT,
       sum(T.ACT_WEIGHT)ACT_WEIGHT,
       sum(T.ACT_THEORY_WEIGHT)ACT_THEORY_WEIGHT,
       T.BELONG_CODE,
       T.BELONG_NAME,
       
       T.STORAGE_NO,
       
       
       
       
       
       max(TO_CHAR(T.OUTSTOCK_TIME, 'YYYY-MM-DD HH24:MI:SS')) OUTSTOCK_TIME,
       
      
     
       
       
       
       T.ORD_PK,
       T.ORD_LN_PK,
       T.ORD_LN_DLY_PK,
       
       T.ORDER_NO,
       T.ORDER_SEQ,
       T.DELIVERY_NO,
       
       T.JUDGE_STD_NAME,
       T.JUDGE_STD_CODE,
       T.PONDER_NO,
       sum(T.PONDER_GROSS_WT)PONDER_GROSS_WT,
       
       
       T.OUTSTOCK_PLAN_NO,
       T.OUTSTOCK_DOC,
       T.OUTSTOCK_TYPE_CODE,
       T.OUTSTOCK_TYPE_NAME,
       
       T.VEHICLE_NO,
       
       s.storage_name
 FROM YDM_ZC_OUTLIST t,ydm_bs_storage s
 WHERE t.storage_no = s.storage_no
 AND T.JUDGE_STOVE_NO || '&' LIKE '%' || ? || '%'
 AND T.ORDER_NO || '&' LIKE '%' || ? || '%'
 
 ]]>
</query>
<query id = "FrmOutList.updateYear" desc= "修改结转年月">
<![CDATA[
DECLARE
BEGIN
  FOR MYROW IN (SELECT T.MAT_NO,T.OUTSTOCK_TYPE_CODE
                  FROM YDM_ZC_OUTLIST T
                 WHERE T.OUTSTOCK_DOC = ?
                   AND T.JUDGE_STOVE_NO = ?
                   AND T.BATCH_NO = ?
                   AND T.BATCH_GROUD_NO = ?
                   AND NVL(T.VEHICLE_NO,'/') = NVL(?,'/')
                   AND T.OUTSTOCK_TYPE_CODE = ?
                 ORDER BY T.MAT_NO DESC) LOOP
    UPDATE YDM_ZC_OUTLIST S
       SET S.BAL_YEAR_MONTH = ?,
           S.OUTSTOCK_TIME  = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS')
     WHERE S.MAT_NO = MYROW.MAT_NO;
    UPDATE YDM_ZC_LOADVEHICLE_MAT T
       SET T.BAL_YEAR_MONTH = ?
     WHERE T.MAT_NO = MYROW.MAT_NO;
    INSERT INTO CRM_ZC_OUTLIST(
        LOADVEHICLE_SQE,
        BILL_NO,
        LOADVEHICLE_NO,
        JUDGE_STOVE_NO,
        BATCH_NO,
        BATCH_GROUD_NO,
        MATERIAL_NO,
        MATERIAL_NAME,
        PRODUCCODE,
        PRODUCNAME,
        STD_CODE,
        STD_NAME,
        GRADECODE,
        GRADENAME,
        STEELCODE,
        STEELNAME,
        STD_STYLE,
        STD_STYLE_DESC,
        SPEC_CODE,
        SPEC_NAME,
        MODEL_CODE,
        MODEL_DESC,
        ACT_LEN_MIN,
        ACT_LEN_MAX,
        ACT_COUNT,
        ACT_WEIGHT,
        ACT_LEN,
        STORAGE_NO,
        STORAGE_NAME,
        SEN_TIME,
        VALIDFLAG,
        ORDER_NO,
        ORDER_SEQ,
        DELIVERY_NO,
        ORD_PK,
        ORD_LN_PK,
        ORD_LN_DLY_PK,
        DATA_STATUS,
        CREATE_TIME,
        DELVRY_WHEREABOUTS,
        SUPPLY_UNIT_CODE,
        SUPPLY_UNIT,
        BAL_YEAR_MONTH,
        ACT_DIMATER,
        ACT_HEIGHT,
        BELONG_CODE,
        BELONG_NAME,
        OUTSTOCK_TYPE_CODE,
        OUTSTOCK_TYPE_NAME
        )

        SELECT
        M.LOADVEHICLE_SQE,
        nvl(T.M_BILL_NO,t.bill_no),
        M.LOADVEHICLE_NO,
        T.JUDGE_STOVE_NO,
        T.BATCH_NO,
        T.BATCH_GROUD_NO,
        T.MATERIAL_NO,
        T.MATERIAL_NAME,
        T.PRODUCCODE,
        T.PRODUCNAME,
        T.STD_CODE,
        T.STD_NAME,
        T.GRADECODE,
        T.GRADENAME,
        T.STEELCODE,
        T.STEELNAME,
        T.STD_STYLE,
        T.STD_STYLE_DESC,
        T.SPEC_CODE,
        T.SPEC_NAME,
        T.MODEL_CODE,
        T.MODEL_DESC,
        T.ACT_LEN_MIN,
        T.ACT_LEN_MAX,
        T.ACT_COUNT,
        CASE
        WHEN T.PONDER_NO IS NOT NULL THEN
        CASE
        WHEN (SELECT DISTINCT LOADVEHICLE_TYPE from YDM_ZC_BILL_M WHERE BILL_NO = T.BILL_NO) = 2 AND T.SUPPLY_UNIT_CODE = '120504' THEN
         NVL( T.ACT_WEIGHT, 0 )
        ELSE
         NVL( T.PONDER_GROSS_WT, 0 )
        END
        ELSE NVL( T.ACT_WEIGHT, 0 )
        END ACT_WEIGHT,
        T.ACT_LEN,
        T.STORAGE_NO,
        (SELECT STORAGE_NAME FROM YDM_BS_STORAGE WHERE STORAGE_NO = T.STORAGE_NO),
        M.SEN_TIME,
        DECODE(T.VALIDFLAG,'0','发运无效','1','发运有效','2','确认有效','3','传送发运明细到销售和质检'),
        T.ORDER_NO,
        T.ORDER_SEQ,
        T.DELIVERY_NO,
        T.ORD_PK,
        T.ORD_LN_PK,
        T.ORD_LN_DLY_PK,
        '1',
        SYSDATE,
        (SELECT DELVRY_WHEREABOUTS FROM YDM_ZC_BILL_M WHERE BILL_NO = M.BILL_NO AND VALIDFLAG = '1' AND ROWNUM = 1),
        T.SUPPLY_UNIT_CODE,
        T.SUPPLY_UNIT,
        T.BAL_YEAR_MONTH,
        T.ACT_DIMATER,
        T.ACT_HEIGHT,
        T.BELONG_CODE,
        T.BELONG_NAME,
        T.OUTSTOCK_TYPE_CODE,
        T.OUTSTOCK_TYPE_NAME
        FROM YDM_ZC_OUTLIST T
        LEFT JOIN YDM_ZC_LOADVEHICLE_MAT M ON (T.M_BILL_NO = M.BILL_NO or t.BILL_NO = m.BILL_NO)  and t.MAT_NO = m.MAT_NO
     WHERE
         t.MAT_NO = MYROW.MAT_NO
        AND T.OUTSTOCK_TYPE_CODE = MYROW.OUTSTOCK_TYPE_CODE;
  END LOOP;
END;
]]>
</query>
</queryMap>