<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.style24.scm.biz.dao.TssWmsGoodsDao">

	<!-- wms 상품 색상 , 사이즈별 재고 정보 조회 -->
	<select id="getGoodsWmsSizeList" parameterType="String"  resultType = "IfProductSku">
		/* TssWmsGoods.getGoodsWmsSizeList */
		SELECT GOODS_CD
		     , SKUCODE
		     , SKUMODELNO
		     , OPTION1
		     , OPTION2
		     , PRODUCTNO
		     , PRODUCTCODE
		     , WMS_COLOR_CD
		     , (LOC_QTY- PICKING_QTY - EOUT_PICKING_QTY) AS WMS_STOCK_QTY
		FROM (
		      SELECT #{goodsCd} AS GOODS_CD
		           , A.SKUCODE
		           , A.SKUMODELNO
		           , A.OPTION1
		           , A.OPTION2
		           , A.PRODUCTNO
		           , A.PRODUCTCODE
		           , SUM(B.LOC_QTY)          AS LOC_QTY
		           , SUM(B.PICKING_QTY)      AS PICKING_QTY
		           , SUM(B.EOUT_PICKING_QTY) AS EOUT_PICKING_QTY
		           , MAX(CASE WHEN CHARINDEX('F20', REPLACE(A.SKUMODELNO, ' ', '')) = 1 THEN SUBSTRING(REPLACE(A.SKUMODELNO, ' ' , ''),13,2)
		                      WHEN CHARINDEX('-', REPLACE(A.SKUMODELNO, ' ', '')) > 0 AND CHARINDEX(REPLACE(A.SKUMODELNO, ' ' , ''), '-') <![CDATA[<]]> 10 THEN SUBSTRING(REPLACE(A.SKUMODELNO, ' ' , ''),12,2)
		                      ELSE SUBSTRING(REPLACE(A.SKUMODELNO, ' ' , ''),11,2) END) AS WMS_COLOR_CD
		      FROM ISTYLE24_WMSIF.DBO.TB_IF_PRODUCTSKU A
		               LEFT OUTER JOIN ISTYLE24_WMS.DBO.VW_STOCK_BY_LOCCODE B ON A.SKUCODE = B.SKU_CODE
		      WHERE 1 = 1
		      AND (CASE
		               WHEN CHARINDEX('F20', REPLACE(A.SKUMODELNO, ' ', '')) = 1 THEN LEFT(REPLACE(A.SKUMODELNO, ' ', ''), 12)
		               WHEN CHARINDEX('-', REPLACE(A.SKUMODELNO, ' ', '')) > 0 AND CHARINDEX(REPLACE(A.SKUMODELNO, ' ' , ''), '-') <![CDATA[<]]> 10 THEN LEFT(REPLACE(A.SKUMODELNO, ' ', ''), 11)
		               ELSE LEFT(REPLACE(A.SKUMODELNO, ' ', ''), 10) END) = #{goodsCd}
		      GROUP BY A.SKUCODE, A.SKUMODELNO, A.OPTION1, A.OPTION2, A.PRODUCTNO, A.PRODUCTCODE
		     ) Z
		ORDER BY  PRODUCTNO, LEN(SKUCODE), SKUCODE
	</select>
	
	
</mapper>