-- Table structure for table `shopordcs`
--

CREATE TABLE `shopordcs` (
  `ORDSEQ` int NOT NULL,
  `CSSEQ` int NOT NULL,
  `CSMEMO` varchar(2000) DEFAULT NULL,
  `CSCLOSE` char(1) DEFAULT NULL,
  `INSERTDT` varchar(20) DEFAULT NULL,
  `INSERTID` varchar(50) DEFAULT NULL,
  `UPDATEDT` varchar(20) DEFAULT NULL,
  `UPDATEID` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
  PRIMARY KEY (`ORDSEQ`,`CSSEQ`),
  UNIQUE KEY `CSSEQ_ORDSEQ` (`CSSEQ`,`ORDSEQ`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `shopordcs`
--


--
-- Table structure for table `shopordmst`
--

CREATE TABLE `shopordmst` (
  `ORDSEQ` int NOT NULL AUTO_INCREMENT COMMENT '일련번호',
  `COMPNO` int NOT NULL,
  `REG_DATE` varchar(50) NOT NULL COMMENT '수집일자',
  `ORDER_ID` varchar(50) DEFAULT NULL COMMENT '주문번호(쇼핑몰)',
  `SHOPID` varchar(50) DEFAULT NULL COMMENT '쇼핑몰명',
  `SHOPSEQ` int DEFAULT NULL,
  `SHOP_USERID` varchar(50) DEFAULT NULL COMMENT '쇼핑몰ID',
  `DOMEORDERNO` varchar(50) DEFAULT NULL COMMENT '도매몰 오더 ID',
  `ORDER_STATUS` varchar(50) DEFAULT NULL COMMENT '주문상태',
  `DS_ORDER_STATUS` varchar(50) DEFAULT NULL COMMENT '도신주문상태',
  `USER_ID` varchar(50) DEFAULT NULL COMMENT '주문자ID',
  `USER_NAME` varchar(50) DEFAULT NULL COMMENT '주문자명',
  `USER_TEL` varchar(50) DEFAULT NULL COMMENT '주문자전화번호',
  `USER_CEL` varchar(50) DEFAULT NULL COMMENT '주문자핸드폰번호',
  `USER_EMAIL` varchar(50) DEFAULT NULL COMMENT '주문자이메일주소',
  `RECEIVE_TEL` varchar(50) DEFAULT NULL COMMENT '수취인전화번호',
  `RECEIVE_CEL` varchar(50) DEFAULT NULL COMMENT '수취인핸드폰번호',
  `RECEIVE_EMAIL` varchar(50) DEFAULT NULL COMMENT '수취인이메일주소',
  `DELV_MSG` varchar(200) DEFAULT NULL COMMENT '배송메세지',
  `RECEIVE_NAME` varchar(50) DEFAULT NULL COMMENT '수취인명',
  `RECEIVE_ZIPCODE` varchar(50) DEFAULT NULL COMMENT '수취인우편번호',
  `RECEIVE_ADDR` varchar(500) DEFAULT NULL COMMENT '수취인주소',
  `TOTAL_COST` int DEFAULT NULL COMMENT '주문금액',
  `PAY_COST` int DEFAULT NULL COMMENT '결제금액',
  `ORDER_DATE` varchar(50) DEFAULT NULL COMMENT '주문일자',
  `PARTNER_ID` varchar(50) DEFAULT NULL COMMENT '매입처명',
  `DPARTNER_ID` varchar(50) DEFAULT NULL COMMENT '물류처명',
  `MALL_PRODUCT_ID` varchar(50) DEFAULT NULL COMMENT '상품코드(쇼핑몰)',
  `MALL_EXP_CD` varchar(50) DEFAULT '0' COMMENT '각쇼핑몰의코드 (11번가경우주문순번)',
  `PRODUCT_ID` varchar(50) DEFAULT NULL COMMENT '품번코드(엠링크)',
  `SKU_ID` varchar(50) DEFAULT NULL COMMENT '단품코드(엠링크)',
  `P_PRODUCT_NAME` varchar(200) DEFAULT NULL COMMENT '상품명(확정)',
  `P_SKU_ID` varchar(50) DEFAULT NULL,
  `P_SKU_VALUE` varchar(500) DEFAULT NULL COMMENT '옵션(확정)',
  `PRODUCT_NAME` varchar(500) DEFAULT NULL COMMENT '상품명(수집)',
  `SALE_COST` int DEFAULT NULL COMMENT '판매가(수집)',
  `MALL_WON_COST` int DEFAULT NULL COMMENT '공급단가',
  `WON_COST` int DEFAULT NULL COMMENT '원가',
  `SKU_VALUE` varchar(500) DEFAULT NULL COMMENT '옵션(수집)',
  `SALE_CNT` int DEFAULT NULL COMMENT '수량',
  `DELIVERY_METHOD_STR` varchar(50) DEFAULT NULL COMMENT '배송구분',
  `DELV_COST` int DEFAULT NULL COMMENT '배송비(수집)',
  `COMPAYNY_GOODS_CD` varchar(50) DEFAULT NULL COMMENT '자체상품코드',
  `SKU_ALIAS` varchar(50) DEFAULT NULL COMMENT '옵션별칭',
  `BOX_EA` int DEFAULT NULL COMMENT 'EA(상품)',
  `JUNG_CHK_YN` varchar(50) DEFAULT NULL COMMENT '정산대조확인여부',
  `MALL_ORDER_SEQ` varchar(50) DEFAULT NULL COMMENT '주문순번',
  `MALL_ORDER_ID` varchar(50) DEFAULT NULL COMMENT '부주문번호',
  `ETC_FIELD3` varchar(50) DEFAULT NULL COMMENT '수정된 수집옵션명',
  `ORDER_GUBUN` varchar(50) DEFAULT NULL COMMENT '주문구분',
  `P_EA` int DEFAULT NULL COMMENT 'EA(확정)',
  `ORD_FIELD2` varchar(50) DEFAULT NULL COMMENT '세트분리주문구분',
  `COPY_IDX` varchar(50) DEFAULT NULL COMMENT '원주문번호(사방넷)',
  `GOODS_NM_PR` varchar(50) DEFAULT NULL COMMENT '출력상품명',
  `GOODS_KEYWORD` varchar(50) DEFAULT NULL COMMENT '상품약어',
  `ORD_CONFIRM_DATE` varchar(50) DEFAULT NULL COMMENT '주문 확인일자',
  `RTN_DT` varchar(50) DEFAULT NULL COMMENT '반품 완료일자',
  `CHNG_DT` varchar(50) DEFAULT NULL COMMENT '교환 완료일자',
  `DELIVERY_CONFIRM_DATE` varchar(50) DEFAULT NULL COMMENT '출고 완료일자',
  `RECEIPTID` varchar(50) DEFAULT NULL COMMENT '반품접수번호',
  `EXCHANGEID` varchar(50) DEFAULT NULL COMMENT '교환접수번호',
  `CANCEL_DT` varchar(50) DEFAULT NULL COMMENT '취소 완료일자',
  `CLASS_CD1` varchar(50) DEFAULT NULL COMMENT '대분류코드',
  `CLASS_CD2` varchar(50) DEFAULT NULL COMMENT '중분류코드',
  `CLASS_CD3` varchar(50) DEFAULT NULL COMMENT '소분류코드',
  `CLASS_CD4` varchar(50) DEFAULT NULL COMMENT '세분류코드',
  `BRAND_NM` varchar(50) DEFAULT NULL COMMENT '브랜드명',
  `DELIVERY_ID` varchar(50) DEFAULT NULL COMMENT '택배사코드',
  `INVOICE_NO` varchar(50) DEFAULT NULL COMMENT '송장번호',
  `HOPE_DELV_DATE` varchar(50) DEFAULT NULL COMMENT '배송희망일자',
  `FLD_DSP` varchar(50) DEFAULT NULL COMMENT '주문엑셀용 ',
  `INV_SEND_MSG` varchar(50) DEFAULT NULL COMMENT '운송장 전송 결과 메시지',
  `MODEL_NO` varchar(50) DEFAULT NULL COMMENT '모델NO',
  `SET_GUBUN` varchar(50) DEFAULT NULL COMMENT '상품구분',
  `ETC_MSG` varchar(50) DEFAULT NULL COMMENT '기타메세지',
  `DELV_MSG1` varchar(50) DEFAULT NULL COMMENT '배송메세지',
  `MUL_DELV_MSG` varchar(500) DEFAULT NULL COMMENT '물류메세지',
  `BARCODE` varchar(50) DEFAULT NULL COMMENT '바코드',
  `INV_SEND_DM` varchar(50) DEFAULT NULL COMMENT '송장전송일자',
  `DELIVERY_METHOD_STR2` varchar(50) DEFAULT NULL COMMENT '배송구분(배송비반영)',
  `LABEL` varchar(50) DEFAULT NULL COMMENT '라벨',
  `ORDER_ETC_1` varchar(50) DEFAULT NULL COMMENT '자사몰필드',
  `ORDER_ETC_2` varchar(50) DEFAULT NULL,
  `ORDER_ETC_3` varchar(50) DEFAULT NULL,
  `ORDER_ETC_4` varchar(50) DEFAULT NULL,
  `ORDER_ETC_5` varchar(50) DEFAULT NULL,
  `ORDER_ETC_6` varchar(50) DEFAULT NULL,
  `ORDER_ETC_7` varchar(50) DEFAULT NULL,
  `ORDER_ETC_8` varchar(50) DEFAULT NULL,
  `ORDER_ETC_9` varchar(50) DEFAULT NULL,
  `ORDER_ETC_10` varchar(50) DEFAULT NULL,
  `ORDER_ETC_11` varchar(50) DEFAULT NULL,
  `ORDER_ETC_12` varchar(50) DEFAULT NULL,
  `ORDER_ETC_13` varchar(50) DEFAULT NULL,
  `ORDER_ETC_14` varchar(50) DEFAULT NULL,
  `MLORDDT` varchar(8) DEFAULT NULL,
  `MLORDSEQ` int DEFAULT NULL,
  `MLSEQ` int DEFAULT NULL,
  `AUTHKEY1` varchar(50) DEFAULT NULL,
  `DOSINORDCD` varchar(50) DEFAULT NULL COMMENT '도신주문코드',
  `DEL_YN` char(1) DEFAULT 'N',
  `BEFORE_COMPAYNY_GOODS_CD` varchar(50) DEFAULT NULL COMMENT '주문연동 아이템 위너로 변경했을 경우 변경전 기존코드',
  `BEFORE_WON_COST` int DEFAULT NULL COMMENT '주문연동 아이템 위너로 변경했을 경우 변경전 원가',
  PRIMARY KEY (`ORDSEQ`),
  UNIQUE KEY `ORDSEQ` (`ORDSEQ`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `shopordmst`
--

DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `shopordmst_after_insert` AFTER INSERT ON `shopordmst` FOR EACH ROW BEGIN

	IF (SELECT EXISTS (SELECT 1  FROM SHOPPRODIN  

					    WHERE COMPNO = NEW.COMPNO

						  AND SHOPCD = NEW.SHOPID

						  AND SHOPPRODNO = SUBSTRING_INDEX(NEW.MALL_PRODUCT_ID, ',', 1)

						  AND COMPAYNY_GOODS_CD = NEW.COMPAYNY_GOODS_CD) AS FLAG) THEN

		UPDATE SHOPPRODIN SET DESCRITION = ifnull(DESCRITION,0) + ifnull(NEW.SALE_CNT,0)  

		 WHERE COMPNO = NEW.COMPNO

		   AND SHOPCD = NEW.SHOPID 

		   AND SHOPPRODNO = SUBSTRING_INDEX(NEW.MALL_PRODUCT_ID, ',', 1)

			AND COMPAYNY_GOODS_CD = NEW.COMPAYNY_GOODS_CD;

	END IF;   

END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `shopordmst_before_update` BEFORE UPDATE ON `shopordmst` FOR EACH ROW BEGIN

	IF (SELECT EXISTS (SELECT 1  FROM SHOPPRODIN  

					    WHERE COMPNO = OLD.COMPNO

						  AND SHOPCD = OLD.SHOPID

						  AND SHOPPRODNO = SUBSTRING_INDEX(OLD.MALL_PRODUCT_ID, ',', 1) 

						  AND COMPAYNY_GOODS_CD = OLD.COMPAYNY_GOODS_CD) AS FLAG) THEN

		UPDATE SHOPPRODIN SET DESCRITION = ifnull(DESCRITION,0) - ifnull(OLD.SALE_CNT,0)

		 WHERE COMPNO = OLD.COMPNO

		   AND SHOPCD = OLD.SHOPID

		   AND SHOPPRODNO = SUBSTRING_INDEX(OLD.MALL_PRODUCT_ID, ',', 1) 

		   AND COMPAYNY_GOODS_CD = OLD.COMPAYNY_GOODS_CD;

	END IF; 

END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `shopordmst_after_update` AFTER UPDATE ON `shopordmst` FOR EACH ROW BEGIN

	IF (SELECT EXISTS (SELECT 1  FROM SHOPPRODIN  

					    WHERE COMPNO = NEW.COMPNO

						  AND SHOPCD = NEW.SHOPID

						  AND SHOPPRODNO = SUBSTRING_INDEX(NEW.MALL_PRODUCT_ID, ',', 1) 

						  AND COMPAYNY_GOODS_CD = NEW.COMPAYNY_GOODS_CD) AS FLAG) THEN

		UPDATE SHOPPRODIN SET DESCRITION = ifnull(DESCRITION,0) + ifnull(NEW.SALE_CNT,0)  

		 WHERE COMPNO = NEW.COMPNO

		   AND SHOPCD = NEW.SHOPID 

		   AND SHOPPRODNO = SUBSTRING_INDEX(NEW.MALL_PRODUCT_ID, ',', 1) 

		   AND COMPAYNY_GOODS_CD = NEW.COMPAYNY_GOODS_CD;

	END IF; 

END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `shopordmst_before_delete` BEFORE DELETE ON `shopordmst` FOR EACH ROW BEGIN

	IF (SELECT EXISTS (SELECT 1  FROM SHOPPRODIN  

					    WHERE COMPNO = OLD.COMPNO

					  	  AND SHOPCD = OLD.SHOPID

						  AND SHOPPRODNO = SUBSTRING_INDEX(OLD.MALL_PRODUCT_ID, ',', 1) 

						  AND COMPAYNY_GOODS_CD = OLD.COMPAYNY_GOODS_CD) AS FLAG) THEN

		UPDATE SHOPPRODIN SET DESCRITION = ifnull(DESCRITION,0) - ifnull(OLD.SALE_CNT,0)  

		 WHERE COMPNO = OLD.COMPNO

		   AND SHOPCD = OLD.SHOPID

		   AND SHOPPRODNO = SUBSTRING_INDEX(OLD.MALL_PRODUCT_ID, ',', 1) 

		   AND COMPAYNY_GOODS_CD = OLD.COMPAYNY_GOODS_CD;

	END IF; 

END */;;
DELIMITER ;

--
-- Table structure for table `shopordstatus`
--

CREATE TABLE `shopordstatus` (
  `SHOPID` varchar(10) NOT NULL,
  `CODE` varchar(4) NOT NULL,
  `MALL_CODE` varchar(4) NOT NULL,
  `NAME` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`SHOPID`,`CODE`,`MALL_CODE`),
  UNIQUE KEY `SHOPID_CODE` (`SHOPID`,`CODE`),
  UNIQUE KEY `MALL_CODE` (`MALL_CODE`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `shopordstatus`
--

INSERT INTO `shopordstatus` VALUES ('shop0003','100','202','신규주문'),('shop0003','201','301','주문확인'),('shop0003','202','203','보류'),('shop0003','203','902','보류해제'),('shop0003','301','903','송장출력'),('shop0003','401','904','송장입력'),('shop0003','402','905','출고'),('shop0003','403','401','배송중'),('shop0003','410','501','수취확인'),('shop0003','500','500','도매신규'),('shop0003','501','000','도매준비'),('shop0003','503','503','도신반품'),('shop0003','504','504','도신교환'),('shop0003','505','505','도신취소'),('shop0003','601','601','반품신청'),('shop0003','701','701','취소신청'),('shop0003','900','906','정산완료'),('shop0003','901','901','구매확정'),('shop0003','907','907','교환신청'),('shop0003','C01','C01','취소요청'),('shop0003','C02','B01','취소마감'),('shop0003','E01','E01','교환요청'),('shop0003','E02','908','교환마감'),('shop0003','R01','R01','반품요청'),('shop0003','R02','A01','반품마감');

--
-- Table structure for table `shopordstatuslog`
--

CREATE TABLE `shopordstatuslog` (
  `SEQ` int NOT NULL AUTO_INCREMENT,
  `COMPNO` int DEFAULT NULL,
  `SHOPID` varchar(10) DEFAULT NULL,
  `ORDER_ID` varchar(50) DEFAULT NULL,
  `SHOPUSERID` varchar(50) DEFAULT NULL,
  `PRODUCT_NAME` varchar(200) DEFAULT NULL,
  `ORDER_STATUS` varchar(6) DEFAULT NULL,
  `ORDER_STATUSNM` varchar(20) NOT NULL DEFAULT '0',
  `RESULTMESSAGE` varchar(1000) DEFAULT NULL,
  `SENDDT` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`SEQ`),
  UNIQUE KEY `ORDSEQ_SEQ` (`SEQ`),
  KEY `COMPNO_SHOPID_ORDER_ID` (`COMPNO`,`SHOPID`,`ORDER_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `shopordstatuslog`
--


--
-- Table structure for table `shopproddtl`
--

CREATE TABLE `shopproddtl` (
  `PRODSEQ` int NOT NULL,
  `PRODDTSEQ` int NOT NULL,
  `PRODDTCD` varchar(20) DEFAULT NULL,
  `PRODDTNM` varchar(100) DEFAULT NULL,
  `SPECDTDES` varchar(100) DEFAULT NULL,
  `EXPDTCD` varchar(2) DEFAULT NULL,
  `DELYN` bit(1) DEFAULT NULL,
  `USEYN` varchar(2) DEFAULT NULL,
  `INSERTDT` varchar(20) DEFAULT NULL,
  `INSERTID` varchar(50) DEFAULT NULL,
  `MODIFYDT` varchar(20) DEFAULT NULL,
  `MODIFYID` varchar(50) DEFAULT NULL,
  `FLAGSET` char(1) DEFAULT NULL,
  `QTYSET` int DEFAULT NULL,
  `LEVSET` char(1) DEFAULT NULL,
  PRIMARY KEY (`PRODSEQ`,`PRODDTSEQ`),
  UNIQUE KEY `XPKPRODDTL` (`PRODSEQ`,`PRODDTSEQ`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='셋트상품 구성을 위한 테이블';

--
-- Dumping data for table `shopproddtl`
--


--
-- Table structure for table `shopproderr`
--

CREATE TABLE `shopproderr` (
  `SENDSEQ` int NOT NULL AUTO_INCREMENT COMMENT '송신번호',
  `COMPNO` int DEFAULT NULL COMMENT '회사코드',
  `SHOPCD` varchar(50) DEFAULT NULL COMMENT '쇼핑몰코드',
  `SHOPSEQ` int DEFAULT NULL COMMENT '순번',
  `PRODSEQ` int DEFAULT NULL COMMENT '품번코드',
  `SEQ` int DEFAULT NULL COMMENT '부가정보코드',
  `SHOPCATNO` int DEFAULT NULL COMMENT '카테고리코드',
  `MARGINSEQ` int DEFAULT NULL COMMENT '마진코드',
  `DESCRITION` varchar(50) DEFAULT NULL COMMENT '관리자메모',
  `FAILCONTENT` varchar(100) DEFAULT NULL,
  `INSERTDT` varchar(50) DEFAULT NULL COMMENT '최초송신일자',
  `INSERTID` varchar(50) DEFAULT NULL,
  `MODIFYDT` varchar(50) DEFAULT NULL COMMENT '재송신일자',
  `MODIFYID` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`SENDSEQ`),
  UNIQUE KEY `SENDSEQ` (`SENDSEQ`)
) ENGINE=InnoDB AUTO_INCREMENT=528 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `shopproderr`
--


--
-- Table structure for table `shopprodfolders`
--

CREATE TABLE `shopprodfolders` (
  `COMPNO` int NOT NULL,
  `FOLDER` varchar(50) NOT NULL,
  `COMPAYNY_GOODS_CD` varchar(50) NOT NULL,
  PRIMARY KEY (`COMPNO`,`FOLDER`,`COMPAYNY_GOODS_CD`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `shopprodfolders`
--


--
-- Table structure for table `shopprodin`
--

CREATE TABLE `shopprodin` (
  `SENDSEQ` int NOT NULL AUTO_INCREMENT COMMENT '송신번호',
  `COMPNO` int DEFAULT NULL COMMENT '회사코드',
  `GOODS_NM` text COMMENT '상품명',
  `SHOPCD` varchar(50) DEFAULT NULL COMMENT '쇼핑몰코드',
  `PRODSEQ` int DEFAULT NULL COMMENT '품번코드',
  `SHOP_USERID` varchar(50) DEFAULT NULL COMMENT '쇼핑몰등록 (사용자아이디)',
  `SHOPSEQ` int DEFAULT NULL COMMENT '순번',
  `SHOPPRODNO` varchar(50) DEFAULT NULL COMMENT '완료후쇼핑몰상품코드',
  `SEQ` int DEFAULT NULL COMMENT '부가정보코드',
  `SHOPCATNO` varchar(50) DEFAULT NULL COMMENT '카테고리코드',
  `GOODS_KEYWORD` varchar(200) DEFAULT NULL,
  `MODEL_NM` varchar(50) DEFAULT NULL COMMENT '모델명',
  `BRAND_NM` varchar(50) DEFAULT NULL COMMENT '브랜드명',
  `COMPAYNY_GOODS_CD` varchar(50) DEFAULT NULL COMMENT '자체상품코드',
  `GOODS_SEARCH` text COMMENT '사이트검색어',
  `GOODS_GUBUN` varchar(50) DEFAULT NULL COMMENT '상품구분',
  `SHOP_CID_INFO` json DEFAULT NULL COMMENT '카테고리',
  `SELECT_OPTION` text,
  `TEXT_OPTION` text,
  `CLASS_CD1` varchar(50) DEFAULT NULL COMMENT '대분류코드',
  `CLASS_CD2` varchar(50) DEFAULT NULL COMMENT '중분류코드',
  `CLASS_CD3` varchar(50) DEFAULT NULL COMMENT '소분류코드',
  `CLASS_CD4` varchar(50) DEFAULT NULL COMMENT '세분류코드',
  `GMCATEGNM` varchar(200) DEFAULT NULL COMMENT '지마켓카테고리',
  `PARTNER_ID` varchar(50) DEFAULT NULL,
  `DPARTNER_ID` varchar(50) DEFAULT NULL,
  `MAKER` varchar(50) DEFAULT NULL COMMENT '제조사',
  `ORIGIN` varchar(50) DEFAULT NULL COMMENT '원산지(제조국)',
  `MAKE_YEAR` varchar(50) DEFAULT NULL,
  `MAKE_DM` varchar(50) DEFAULT NULL,
  `GOODS_SEASON` varchar(50) DEFAULT NULL,
  `SEX` varchar(50) DEFAULT NULL COMMENT '남녀구분',
  `STATUS` varchar(50) DEFAULT NULL COMMENT '상품상태 0: 판매중, 1:품절, 2:판매종료',
  `DELIV_ABLE_REGION` varchar(50) DEFAULT NULL COMMENT '판매지역',
  `TAX_YN` varchar(50) DEFAULT NULL COMMENT '세금구분',
  `DELV_TYPE` varchar(50) DEFAULT NULL COMMENT '배송비구분',
  `DELV_COST` int DEFAULT NULL COMMENT '배송비',
  `RETURN_DELV_COST` int DEFAULT NULL COMMENT '반품배송비',
  `DELV_QTY` int DEFAULT NULL COMMENT '수량별시 갯수',
  `BANPUM_AREA` varchar(50) DEFAULT NULL COMMENT '반품지구분',
  `GOODS_COST` int DEFAULT NULL COMMENT '쇼핑몰 원가(공급가)',
  `GOODS_PRICE` int DEFAULT NULL COMMENT '판매가',
  `MARKET_PRICE` int DEFAULT NULL COMMENT '마켓에등록한 가격',
  `GOODS_CONSUMER_PRICE` int DEFAULT NULL COMMENT 'TAG가(소비자가)',
  `ISLIMIT` int DEFAULT NULL,
  `LIMIT_PRICE` int DEFAULT NULL,
  `IS_OVERSEAS` int DEFAULT NULL,
  `ADULT` int DEFAULT NULL,
  `ISRETURN` int DEFAULT NULL,
  `ITYPE` int DEFAULT NULL,
  `OPTIONYN` varchar(50) DEFAULT NULL COMMENT '옵션유무 00 없음 01 있음',
  `CHAR_1_NM` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '옵션제목(1)',
  `CHAR_1_VAL` text COMMENT '옵션상세명칭(1)',
  `CHAR_2_NM` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '옵션제목(2)',
  `CHAR_2_VAL` text COMMENT '옵션상세명칭(2)',
  `IMG_PATH` varchar(200) DEFAULT NULL COMMENT '대표이미지',
  `IMG_PATH1` varchar(200) DEFAULT NULL COMMENT '종합몰(JPG)이미지',
  `IMG_PATH2` varchar(200) DEFAULT NULL COMMENT '부가이미지2',
  `IMG_PATH3` varchar(200) DEFAULT NULL COMMENT '부가이미지3',
  `IMG_PATH4` varchar(200) DEFAULT NULL COMMENT '부가이미지4',
  `IMG_PATH5` varchar(200) DEFAULT NULL COMMENT '부가이미지5',
  `IMG_PATH6` varchar(200) DEFAULT NULL COMMENT '부가이미지6',
  `IMG_PATH7` varchar(200) DEFAULT NULL COMMENT '부가이미지7',
  `IMG_PATH8` varchar(200) DEFAULT NULL COMMENT '부가이미지8',
  `IMG_PATH9` varchar(200) DEFAULT NULL COMMENT '부가이미지9',
  `IMG_PATH10` varchar(200) DEFAULT NULL COMMENT '부가이미지10',
  `IMG_PATH11` varchar(100) DEFAULT NULL COMMENT '부가이미지11',
  `IMG_PATH12` varchar(100) DEFAULT NULL COMMENT '부가이미지12',
  `IMG_PATH13` varchar(100) DEFAULT NULL COMMENT '부가이미지13',
  `IMG_PATH14` varchar(100) DEFAULT NULL COMMENT '부가이미지14',
  `IMG_PATH15` varchar(100) DEFAULT NULL COMMENT '부가이미지15',
  `IMG_PATH16` varchar(100) DEFAULT NULL COMMENT '부가이미지16',
  `IMG_PATH17` varchar(100) DEFAULT NULL COMMENT '부가이미지17',
  `IMG_PATH18` varchar(100) DEFAULT NULL COMMENT '부가이미지18',
  `IMG_PATH19` varchar(100) DEFAULT NULL COMMENT '부가이미지19',
  `IMG_PATH20` varchar(100) DEFAULT NULL COMMENT '부가이미지20',
  `IMG_PATH21` varchar(100) DEFAULT NULL COMMENT '부가이미지21',
  `IMG_PATH22` varchar(100) DEFAULT NULL COMMENT '부가이미지22',
  `IMG_PATH23` varchar(100) DEFAULT NULL COMMENT '인증서이미지',
  `IMG_PATH24` varchar(100) DEFAULT NULL COMMENT '수입면장이미지',
  `GOODS_REMARKS` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '상품상세설명',
  `CERT_TYPE` varchar(50) DEFAULT NULL COMMENT '상품인증타입  0:인증대상아님, 1:인증대상, 2:상세설명에 표기',
  `CERT` varchar(50) DEFAULT NULL,
  `CERTNO` varchar(50) DEFAULT NULL COMMENT '인증번호',
  `AVLST_DM` varchar(50) DEFAULT NULL COMMENT '인증유효 시작일',
  `AVLED_DM` varchar(50) DEFAULT NULL COMMENT '인증유효 마지막일',
  `ISSUEDATE` varchar(100) DEFAULT NULL COMMENT '발급일자',
  `CERTDATE` varchar(50) DEFAULT NULL COMMENT '인증일자',
  `CERT_AGENCY` varchar(50) DEFAULT NULL COMMENT '인증기관',
  `CERTFIELD` varchar(50) DEFAULT NULL COMMENT '인증분야',
  `CERTMODEL` varchar(50) DEFAULT NULL COMMENT '인증모델',
  `CERTNAME` varchar(50) DEFAULT NULL COMMENT '인증상호',
  `EXEMPTIONTYPE` varchar(50) DEFAULT NULL COMMENT '면제유형',
  `MATERIAL` varchar(50) DEFAULT NULL COMMENT '식품재료/원산지',
  `STOCK_USE_YN` varchar(50) DEFAULT NULL COMMENT '재고관리사용여부',
  `OPT_TYPE` varchar(50) DEFAULT NULL COMMENT '옵션수정여부',
  `PROP_EDIT_YN` varchar(50) DEFAULT NULL COMMENT '속성수정여부',
  `PROP1_CD` varchar(50) DEFAULT NULL COMMENT '속성분류코드',
  `PROP_VAL1` text COMMENT '속성값1',
  `PROP_VAL2` text COMMENT '속성값2',
  `PROP_VAL3` text COMMENT '속성값3',
  `PROP_VAL4` text COMMENT '속성값4',
  `PROP_VAL5` text COMMENT '속성값5',
  `PROP_VAL6` text COMMENT '속성값6',
  `PROP_VAL7` text COMMENT '속성값7',
  `PROP_VAL8` text COMMENT '속성값8',
  `PROP_VAL9` text COMMENT '속성값9',
  `PROP_VAL10` text COMMENT '속성값10',
  `PROP_VAL11` text COMMENT '속성값11',
  `PROP_VAL12` text COMMENT '속성값12',
  `PROP_VAL13` text COMMENT '속성값13',
  `PROP_VAL14` text COMMENT '속성값14',
  `PROP_VAL15` text COMMENT '속성값15',
  `PROP_VAL16` text COMMENT '속성값16',
  `PROP_VAL17` text COMMENT '속성값17',
  `PROP_VAL18` text COMMENT '속성값18',
  `PROP_VAL19` text COMMENT '속성값19',
  `PROP_VAL20` text COMMENT '속성값20',
  `PROP_VAL21` text COMMENT '속성값21',
  `PROP_VAL22` text COMMENT '속성값22',
  `PROP_VAL23` text COMMENT '속성값23',
  `PROP_VAL24` text COMMENT '속성값24',
  `PROP_VAL25` text COMMENT '속성값25',
  `PROP_VAL26` text COMMENT '속성값26',
  `PROP_VAL27` text COMMENT '속성값27',
  `PROP_VAL28` text COMMENT '속성값28',
  `PACK_CODE_STR` varchar(50) DEFAULT NULL COMMENT '추가상품그룹코드',
  `GOODS_NM_EN` varchar(50) DEFAULT NULL COMMENT '영문 상품명',
  `GOODS_NM_PR` varchar(50) DEFAULT NULL COMMENT '출력 상품명',
  `GOODS_REMARKS2` text COMMENT '추가상세설명',
  `GOODS_REMARKS3` text COMMENT '광고/홍보',
  `GOODS_REMARKS4` varchar(50) DEFAULT NULL COMMENT '추가 상품상세설명_3',
  `IMPORTNO` varchar(50) DEFAULT NULL COMMENT '수입신고번호',
  `GOODS_COST2` varchar(50) DEFAULT NULL COMMENT '원가2',
  `ORIGIN2` varchar(50) DEFAULT NULL COMMENT '원산지 상세지역',
  `EXPIRE_DM` varchar(50) DEFAULT NULL COMMENT '유효일자',
  `SUPPLY_SAVE_YN` varchar(50) DEFAULT NULL COMMENT '합포제외여부',
  `DESCRITION` varchar(50) DEFAULT NULL COMMENT '관리자메모',
  `INSERTDT` varchar(50) DEFAULT NULL COMMENT '송신일자',
  `INSERTID` varchar(50) DEFAULT NULL,
  `MODIFYDT` varchar(50) DEFAULT NULL,
  `MODIFYID` varchar(50) DEFAULT NULL,
  `SALEENDDT` varchar(50) DEFAULT NULL COMMENT '판매종료일자',
  `SHOPSENDSTATUS` int DEFAULT NULL COMMENT '전송대기 = 9000,판매중 = 8000 ,수정대기 = 7000,자체수정 = 6000,종료대기 = 5000,품절 = 4000,판매종료 = 3000,삭제 = 2000,전송대기_전송실패  -9000,수정대기_전송실패 -7000',
  `SHOPMODIFYCONTENT` longtext COMMENT '수정내용',
  `SELFMOD_NO` varchar(50) DEFAULT NULL COMMENT '자체수정 항목번호(1=카테고리,2=상품명,3=키워드검색)',
  `NOTICE` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '배송 정책 관련/ 구간별 수량별 특이사항 있을 때 내용',
  PRIMARY KEY (`SENDSEQ`),
  UNIQUE KEY `COMPNO_SHOPCD_PRODSEQ_SHOP_USERID_SHOPSEQ` (`COMPNO`,`SHOPCD`,`PRODSEQ`,`SHOPSEQ`) USING BTREE,
  KEY `idx_shopprodin_PRODSEQ` (`COMPNO`,`PRODSEQ`),
  KEY `idx_shopprodin_COMPAYNY_GOODS_CD` (`COMPNO`,`COMPAYNY_GOODS_CD`),
  KEY `INSERTDT_DESC` (`COMPNO`,`INSERTDT` DESC,`SHOPCD`,`SHOPSEQ`,`SHOPSENDSTATUS`,`COMPAYNY_GOODS_CD`),
  KEY `SALEENDDT` (`COMPNO`,`SALEENDDT`,`SHOPSENDSTATUS`),
  KEY `PRODSEQ` (`PRODSEQ`),
  KEY `idx_shopprodin_SHOPPRODNO` (`COMPNO`,`SHOPPRODNO`),
  KEY `idx_shopprodin_SHOPSENDSTATUS` (`COMPNO`,`SHOPSENDSTATUS`),
  KEY `SHOPSENDSTATUS` (`COMPNO`,`SHOPCD`,`SHOPSEQ`,`SHOPSENDSTATUS`) USING BTREE,
  KEY `CLASS_CD3` (`CLASS_CD3`),
  KEY `idx_comno_prodseq_shopcd_shopseq_status` (`COMPNO`,`PRODSEQ`,`SHOPCD`,`SHOPSEQ`,`SHOPSENDSTATUS`),
  KEY `idx_shopprodin_GOODS_NM` (`COMPNO`,`GOODS_NM`(50)),
  KEY `idx_shopprodin_PARTNER_ID` (`COMPNO`,`PARTNER_ID`),
  KEY `idx_shopprodin_GOODS_SEARCH` (`COMPNO`,`GOODS_SEARCH`(50)),
  KEY `idx_shopprodin_GMCATEGNM` (`COMPNO`,`GMCATEGNM`(50)),
  KEY `idx_shopprodin_DELV_TYPE` (`COMPNO`,`DELV_TYPE`),
  KEY `idx_shopprodin_IS_OVERSEAS` (`COMPNO`,`IS_OVERSEAS`),
  KEY `idx_shopprodin_ADULT` (`COMPNO`,`ADULT`),
  KEY `idx_shopprodin_GOODS_COST` (`COMPNO`,`GOODS_COST`),
  KEY `idx_shopprodin_DESCRITION` (`COMPNO`,`DESCRITION`),
  KEY `idx_shopprodin_IMG_PATH22` (`COMPNO`,`IMG_PATH22`(30)),
  KEY `idx_shopprodin_CHAR_1_NM` (`COMPNO`,`CHAR_1_NM`),
  KEY `idx_shopprodin_DELV_COST` (`COMPNO`,`DELV_COST`),
  KEY `idx_shopprodin_RETURN_DELV_COST` (`COMPNO`,`RETURN_DELV_COST`),
  KEY `idx_shopprodin_STATUS` (`COMPNO`,`STATUS`),
  KEY `idx_shopprodin_INSERTDT` (`COMPNO`,`INSERTDT`),
  KEY `idx_shopprodin_MODIFYDT` (`COMPNO`,`MODIFYDT`),
  KEY `idx_shopprodin_GOODS_KEYWORD` (`COMPNO`,`GOODS_KEYWORD`),
  KEY `idx_shopprodin_class_shopcd_shopuserid_shopseq` (`COMPNO`,`CLASS_CD3`,`SHOPCD`,`SHOP_USERID`,`SHOPSEQ`,`SHOPSENDSTATUS`),
  FULLTEXT KEY `idx_shopprodin_SHOPMODIFYCONTENT` (`SHOPMODIFYCONTENT`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `shopprodin`
--

DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `shopprodin_after_insert` AFTER INSERT ON `shopprodin` FOR EACH ROW BEGIN

	IF (SELECT EXISTS (SELECT 1  FROM SUM_PRODINCOUNTS  

							  WHERE COMPNO = NEW.COMPNO AND GOODS_KEYWORD = ifnull(NEW.GOODS_KEYWORD,'')

							    AND SHOPCD = NEW.SHOPCD AND SHOPID = ifnull(NEW.SHOP_USERID,'') AND SHOPSEQ = ifnull(NEW.SHOPSEQ,0)

								 AND SHOPSENDSTATUS = NEW.SHOPSENDSTATUS) AS FLAG) THEN

		UPDATE SUM_PRODINCOUNTS SET COUNTS = COUNTS + 1  WHERE COMPNO = NEW.COMPNO AND GOODS_KEYWORD = ifnull(NEW.GOODS_KEYWORD,'')

							    AND SHOPCD = NEW.SHOPCD AND SHOPID = ifnull(NEW.SHOP_USERID,'') AND SHOPSEQ = ifnull(NEW.SHOPSEQ,0)

								 AND SHOPSENDSTATUS = NEW.SHOPSENDSTATUS;

	ELSE 

		INSERT INTO SUM_PRODINCOUNTS(COMPNO,GOODS_KEYWORD,SHOPCD,SHOPID,SHOPSEQ,SHOPSENDSTATUS,COUNTS) VALUES (NEW.COMPNO,ifnull(NEW.GOODS_KEYWORD,''),NEW.SHOPCD,ifnull(NEW.SHOP_USERID,''),

		ifnull(NEW.SHOPSEQ,0),NEW.SHOPSENDSTATUS,1);

	END IF;

END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `shopprodin_before_update` BEFORE UPDATE ON `shopprodin` FOR EACH ROW BEGIN



	UPDATE SUM_PRODINCOUNTS SET COUNTS = COUNTS - 1 

	 WHERE COMPNO = OLD.COMPNO 

	   AND GOODS_KEYWORD = OLD.GOODS_KEYWORD

	   AND SHOPCD = OLD.SHOPCD 

		AND SHOPID = OLD.SHOP_USERID 

		AND SHOPSEQ = OLD.SHOPSEQ 

		AND SHOPSENDSTATUS = OLD.SHOPSENDSTATUS;



	IF (SELECT EXISTS (SELECT 1  FROM SHOPPRODINFO WHERE PRODSEQ = OLD.PRODSEQ) AS FLAG2) THEN

		UPDATE SHOPPRODINFO 

           SET DESCRITION = ifnull(DESCRITION,0) - IFNULL(OLD.DESCRITION,0)  		 

         WHERE COMPNO = OLD.COMPNO

           AND PRODSEQ= OLD.PRODSEQ

           AND IFNULL(OLD.DESCRITION,0) > 0;

	END IF;	



END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `shopprodin_after_update` AFTER UPDATE ON `shopprodin` FOR EACH ROW BEGIN



	IF (SELECT EXISTS (SELECT 1  FROM SUM_PRODINCOUNTS  

							  WHERE COMPNO = NEW.COMPNO 

								AND GOODS_KEYWORD = ifnull(NEW.GOODS_KEYWORD,'')

								AND SHOPCD = NEW.SHOPCD 

								 AND SHOPID = ifnull(NEW.SHOP_USERID,'') 

								 AND SHOPSEQ = ifnull(NEW.SHOPSEQ,0)

								 AND SHOPSENDSTATUS = NEW.SHOPSENDSTATUS) AS FLAG) THEN

		UPDATE SUM_PRODINCOUNTS SET COUNTS = COUNTS + 1  

		 WHERE COMPNO = NEW.COMPNO 

		   AND GOODS_KEYWORD = ifnull(NEW.GOODS_KEYWORD,'')

			AND SHOPCD = NEW.SHOPCD 

			AND SHOPID = ifnull(NEW.SHOP_USERID,'') 

			AND SHOPSEQ = ifnull(NEW.SHOPSEQ,0) 

			AND SHOPSENDSTATUS = NEW.SHOPSENDSTATUS;

	ELSE 

		INSERT INTO SUM_PRODINCOUNTS(COMPNO,GOODS_KEYWORD,SHOPCD,SHOPID,SHOPSEQ,SHOPSENDSTATUS,COUNTS) 

		VALUES (NEW.COMPNO,ifnull(NEW.GOODS_KEYWORD,''),NEW.SHOPCD,ifnull(NEW.SHOP_USERID,''),ifnull(NEW.SHOPSEQ,0),NEW.SHOPSENDSTATUS,1);

	END IF;



	

	IF (SELECT EXISTS (SELECT 1  FROM SHOPPRODINFO WHERE PRODSEQ = NEW.PRODSEQ) AS FLAG2) THEN

		UPDATE SHOPPRODINFO 

	      SET DESCRITION = ifnull(DESCRITION,0) + IFNULL(NEW.DESCRITION,0)  		 

	    WHERE PRODSEQ= NEW.PRODSEQ

	      AND IFNULL(NEW.DESCRITION,0) > 0;

	END IF;

	

END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `shopprodin_before_delete` BEFORE DELETE ON `shopprodin` FOR EACH ROW BEGIN



	UPDATE SUM_PRODINCOUNTS SET COUNTS = COUNTS - 1 

	 WHERE COMPNO = OLD.COMPNO AND GOODS_KEYWORD = OLD.GOODS_KEYWORD

	   AND SHOPCD = OLD.SHOPCD AND SHOPID = OLD.SHOP_USERID AND SHOPSEQ = OLD.SHOPSEQ 

		AND SHOPSENDSTATUS = OLD.SHOPSENDSTATUS;



	IF (SELECT EXISTS (SELECT 1  FROM SHOPPRODINFO WHERE PRODSEQ = OLD.PRODSEQ) AS FLAG2) THEN

		UPDATE SHOPPRODINFO 

		   SET DESCRITION = ifnull(DESCRITION,0) - IFNULL(OLD.DESCRITION,0)  		 

    	 WHERE COMPNO = OLD.COMPNO

           AND PRODSEQ= OLD.PRODSEQ

           AND IFNULL(OLD.DESCRITION,0) > 0;

	END IF;

	

END */;;
DELIMITER ;

--
-- Table structure for table `shopprodinfo`
--

CREATE TABLE `shopprodinfo` (
  `PRODSEQ` int NOT NULL AUTO_INCREMENT COMMENT '품번코드',
  `COMPNO` int DEFAULT NULL,
  `GOODS_NM` text COMMENT '상품명',
  `GOODS_KEYWORD` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '상품약어',
  `MODEL_NM` varchar(50) DEFAULT NULL COMMENT '모델명',
  `MODEL_NO` varchar(50) DEFAULT NULL COMMENT '모델No',
  `BRAND_NM` varchar(50) DEFAULT NULL COMMENT '브랜드명',
  `COMPAYNY_GOODS_CD` varchar(50) DEFAULT NULL COMMENT '자체상품코드',
  `GOODS_SEARCH` text COMMENT '사이트검색어',
  `GOODS_GUBUN` varchar(50) DEFAULT NULL COMMENT '상품구분',
  `SHOP_CID_INFO` json DEFAULT NULL,
  `SELECT_OPTION` text,
  `TEXT_OPTION` text,
  `CLASS_CD1` varchar(50) DEFAULT NULL COMMENT '대분류코드',
  `CLASS_CD2` varchar(50) DEFAULT NULL COMMENT '중분류코드',
  `CLASS_CD3` varchar(50) DEFAULT NULL COMMENT '소분류코드',
  `CLASS_CD4` varchar(50) DEFAULT NULL COMMENT '세분류코드',
  `GMCATEGNM` varchar(200) DEFAULT NULL COMMENT '지마켓카테고리이름',
  `PARTNER_ID` varchar(50) DEFAULT NULL COMMENT '매입처ID',
  `DPARTNER_ID` varchar(50) DEFAULT NULL COMMENT '물류처ID',
  `MAKER` varchar(50) DEFAULT NULL COMMENT '제조사',
  `ORIGIN` varchar(50) DEFAULT NULL COMMENT '원산지(제조국)',
  `MAKE_YEAR` varchar(50) DEFAULT NULL COMMENT '생산연도',
  `MAKE_DM` varchar(50) DEFAULT NULL COMMENT '제조일자',
  `GOODS_SEASON` varchar(50) DEFAULT NULL COMMENT '시즌',
  `SEX` varchar(50) DEFAULT NULL COMMENT '남녀구분',
  `STATUS` varchar(50) DEFAULT NULL COMMENT '상품상태 0: 판매중, 1:품절, 2:판매종료',
  `DELIV_ABLE_REGION` varchar(50) DEFAULT NULL COMMENT '판매지역',
  `TAX_YN` varchar(50) DEFAULT NULL COMMENT '세금구분',
  `DELV_TYPE` varchar(50) DEFAULT NULL COMMENT '배송비구분(0:유료,0:무료,2:착불,3:수량별)',
  `DELV_COST` int DEFAULT NULL COMMENT '배송비',
  `RETURN_DELV_COST` int DEFAULT NULL COMMENT '반품배송비',
  `DELV_QTY` int DEFAULT NULL COMMENT '수량별시 갯수',
  `BANPUM_AREA` varchar(50) DEFAULT NULL COMMENT '반품지구분',
  `GOODS_COST` int DEFAULT NULL COMMENT '자체 상품 원가',
  `GOODS_PRICE` int DEFAULT NULL COMMENT '판매가',
  `GOODS_CONSUMER_PRICE` int DEFAULT NULL COMMENT 'TAG가(소비자가)',
  `ISLIMIT` int DEFAULT NULL COMMENT '소비자가 준수여부  0: 자율판매, 1: 판매가 준수상품',
  `LIMIT_PRICE` int DEFAULT NULL COMMENT '판매준수 가격',
  `IS_OVERSEAS` int DEFAULT NULL COMMENT '해외직배송여부  1:해외직배송상품, 0:국내배송상품',
  `ADULT` int DEFAULT NULL COMMENT '성인상품여부  0:전체이용가, 1:성인전용상품',
  `ISRETURN` int DEFAULT NULL COMMENT '1:반품가능, 0:반품불가',
  `ITYPE` int DEFAULT NULL COMMENT '상품상태타입  0:새상품, 1:중고상품',
  `OPTIONYN` varchar(50) DEFAULT NULL COMMENT '옵션 유무 00 없음 01 있음 ',
  `CHAR_1_NM` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '옵션제목(1)',
  `CHAR_1_VAL` text COMMENT '옵션상세명칭(1)',
  `CHAR_2_NM` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '옵션제목(2)',
  `CHAR_2_VAL` text COMMENT '옵션상세명칭(2)',
  `IMG_PATH` varchar(200) DEFAULT NULL COMMENT '대표이미지',
  `IMG_PATH1` varchar(200) DEFAULT NULL COMMENT '종합몰(JPG)이미지',
  `IMG_PATH2` varchar(200) DEFAULT NULL COMMENT '부가이미지2',
  `IMG_PATH3` varchar(200) DEFAULT NULL COMMENT '부가이미지3',
  `IMG_PATH4` varchar(200) DEFAULT NULL COMMENT '부가이미지4',
  `IMG_PATH5` varchar(200) DEFAULT NULL COMMENT '부가이미지5',
  `IMG_PATH6` varchar(200) DEFAULT NULL COMMENT '부가이미지6',
  `IMG_PATH7` varchar(200) DEFAULT NULL COMMENT '부가이미지7',
  `IMG_PATH8` varchar(200) DEFAULT NULL COMMENT '부가이미지8',
  `IMG_PATH9` varchar(200) DEFAULT NULL COMMENT '부가이미지9',
  `IMG_PATH10` varchar(200) DEFAULT NULL COMMENT '부가이미지10',
  `IMG_PATH11` varchar(200) DEFAULT NULL COMMENT '부가이미지11',
  `IMG_PATH12` varchar(200) DEFAULT NULL COMMENT '부가이미지12',
  `IMG_PATH13` varchar(200) DEFAULT NULL COMMENT '부가이미지13',
  `IMG_PATH14` varchar(200) DEFAULT NULL COMMENT '부가이미지14',
  `IMG_PATH15` varchar(200) DEFAULT NULL COMMENT '부가이미지15',
  `IMG_PATH16` varchar(100) DEFAULT NULL COMMENT '부가이미지16',
  `IMG_PATH17` varchar(100) DEFAULT NULL COMMENT '부가이미지17',
  `IMG_PATH18` varchar(100) DEFAULT NULL COMMENT '부가이미지18',
  `IMG_PATH19` varchar(100) DEFAULT NULL COMMENT '부가이미지19',
  `IMG_PATH20` varchar(100) DEFAULT NULL COMMENT '부가이미지20',
  `IMG_PATH21` varchar(100) DEFAULT NULL COMMENT '부가이미지21',
  `IMG_PATH22` varchar(100) DEFAULT NULL COMMENT '부가이미지22',
  `IMG_PATH23` varchar(100) DEFAULT NULL COMMENT '인증서이미지',
  `IMG_PATH24` varchar(100) DEFAULT NULL COMMENT '수입면장이미지',
  `GOODS_REMARKS` longtext COMMENT '상품상세설명',
  `CERT_TYPE` int DEFAULT '0' COMMENT '상품인증타입  0:인증대상아님, 1:인증대상, 2:상세설명에 표기',
  `CERT` varchar(50) DEFAULT NULL COMMENT '상품인증코드',
  `CERTNO` varchar(50) DEFAULT NULL COMMENT '인증번호',
  `AVLST_DM` varchar(50) DEFAULT NULL COMMENT '인증유효 시작일',
  `AVLED_DM` varchar(50) DEFAULT NULL COMMENT '인증유효 마지막일',
  `ISSUEDATE` varchar(50) DEFAULT NULL COMMENT '발급일자',
  `CERTDATE` varchar(50) DEFAULT NULL COMMENT '인증일자',
  `CERT_AGENCY` varchar(50) DEFAULT NULL COMMENT '인증기관',
  `CERTFIELD` varchar(50) DEFAULT NULL COMMENT '인증분야',
  `CERTMODEL` varchar(50) DEFAULT NULL COMMENT '인증모델',
  `CERTNAME` varchar(50) DEFAULT NULL COMMENT '인증상호',
  `EXEMPTIONTYPE` varchar(50) DEFAULT NULL COMMENT '면제유형',
  `MATERIAL` varchar(50) DEFAULT NULL COMMENT '식품재료/원산지',
  `STOCK_USE_YN` varchar(50) DEFAULT NULL COMMENT '재고관리사용여부',
  `OPT_TYPE` varchar(50) DEFAULT NULL COMMENT '옵션수정여부',
  `PROP_EDIT_YN` varchar(50) DEFAULT NULL COMMENT '속성수정여부',
  `PROP1_CD` varchar(50) DEFAULT NULL COMMENT '속성분류코드',
  `PROP_VAL1` text COMMENT '속성값1',
  `PROP_VAL2` text COMMENT '속성값2',
  `PROP_VAL3` text COMMENT '속성값3',
  `PROP_VAL4` text COMMENT '속성값4',
  `PROP_VAL5` text COMMENT '속성값5',
  `PROP_VAL6` text COMMENT '속성값6',
  `PROP_VAL7` text COMMENT '속성값7',
  `PROP_VAL8` text COMMENT '속성값8',
  `PROP_VAL9` text,
  `PROP_VAL10` text COMMENT '속성값10',
  `PROP_VAL11` text COMMENT '속성값11',
  `PROP_VAL12` text COMMENT '속성값12',
  `PROP_VAL13` text COMMENT '속성값13',
  `PROP_VAL14` text COMMENT '속성값14',
  `PROP_VAL15` text COMMENT '속성값15',
  `PROP_VAL16` text COMMENT '속성값16',
  `PROP_VAL17` text COMMENT '속성값17',
  `PROP_VAL18` text COMMENT '속성값18',
  `PROP_VAL19` text COMMENT '속성값19',
  `PROP_VAL20` text COMMENT '속성값20',
  `PROP_VAL21` text COMMENT '속성값21',
  `PROP_VAL22` text COMMENT '속성값22',
  `PROP_VAL23` text COMMENT '속성값23',
  `PROP_VAL24` text COMMENT '속성값24',
  `PROP_VAL25` text COMMENT '속성값25',
  `PROP_VAL26` text COMMENT '속성값26',
  `PROP_VAL27` text COMMENT '속성값27',
  `PROP_VAL28` text COMMENT '속성값28',
  `PACK_CODE_STR` varchar(50) DEFAULT NULL COMMENT '추가상품그룹코드',
  `GOODS_NM_EN` varchar(50) DEFAULT NULL COMMENT '영문 상품명',
  `GOODS_NM_PR` varchar(50) DEFAULT NULL COMMENT '출력 상품명',
  `GOODS_REMARKS2` text COMMENT '추가상세설명',
  `GOODS_REMARKS3` text COMMENT '광고/홍보',
  `GOODS_REMARKS4` varchar(50) DEFAULT NULL COMMENT '추가 상품상세설명_3',
  `IMPORTNO` varchar(50) DEFAULT NULL COMMENT '수입신고번호',
  `GOODS_COST2` varchar(50) DEFAULT NULL COMMENT '원가2',
  `ORIGIN2` varchar(50) DEFAULT NULL COMMENT '원산지 상세지역',
  `EXPIRE_DM` varchar(50) DEFAULT NULL COMMENT '유효일자',
  `SUPPLY_SAVE_YN` varchar(50) DEFAULT NULL COMMENT '합포제외여부',
  `DESCRITION` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT '0' COMMENT '관리자메모(판매량)',
  `SHOPPRODNO` varchar(20) DEFAULT NULL COMMENT '완료후쇼핑몰코드(등록수정을한폼으로진행하기위해)',
  `INSERTDT` varchar(50) DEFAULT NULL COMMENT '입력일자',
  `INSERTID` varchar(50) DEFAULT NULL,
  `MODIFYDT` varchar(50) DEFAULT NULL COMMENT '수정일자',
  `MODIFYID` varchar(50) DEFAULT NULL,
  `SHOPSENDSTATUS` int DEFAULT NULL COMMENT '전송대기 = 9000,판매중 = 8000 ,수정대기 = 7000,자체수정 = 6000,종료대기 = 5000,품절 = 4000,판매종료 = 3000,삭제 = 2000,전송대기_전송실패  -9000,수정대기_전송실패 -7000',
  `SHOPMODIFYCONTENT` longtext COMMENT '수정내용',
  `SELFMOD_NO` varchar(50) DEFAULT NULL COMMENT '자체수정 항목번호(1=카테고리,2=상품명,3=키워드검색)',
  `NOTICE` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '배송 정책 등 특이사항, 구간별, 수량별 배송비 추가 등',
  PRIMARY KEY (`PRODSEQ`),
  UNIQUE KEY `idx_shopprodinfo_COMPAYNY_GOODS_CD` (`COMPNO`,`COMPAYNY_GOODS_CD`),
  KEY `SHOPSENDSTATUS` (`COMPNO`,`SHOPSENDSTATUS`),
  KEY `COMPNO_STATUS` (`COMPNO`,`STATUS`),
  KEY `idx_shopprodinfo_goods_keyword_status` (`COMPNO`,`GOODS_KEYWORD`,`STATUS`),
  KEY `INSERTDT_DESC` (`COMPNO`,`GOODS_KEYWORD`,`INSERTDT` DESC,`SHOPSENDSTATUS`,`COMPAYNY_GOODS_CD`),
  KEY `CLASS_CD3` (`CLASS_CD3`),
  KEY `idx_shopprodinfo_compno_classcd3_goods` (`COMPNO`,`CLASS_CD3`,`COMPAYNY_GOODS_CD`),
  KEY `idx_shopprodinfo_compno_cost_status_goods_prodseq` (`COMPNO`,`GOODS_COST`,`SHOPSENDSTATUS`,`COMPAYNY_GOODS_CD`,`PRODSEQ`),
  KEY `idx_shopprodinfo_GOODS_NM` (`COMPNO`,`GOODS_NM`(50)),
  KEY `idx_shopprodinfo_PARTNER_ID` (`COMPNO`,`PARTNER_ID`),
  KEY `idx_shopprodinfo_GOODS_SEARCH` (`COMPNO`,`GOODS_SEARCH`(50)),
  KEY `idx_shopprodinfo_GMCATEGNM` (`COMPNO`,`GMCATEGNM`(50)),
  KEY `idx_shopprodinfo_DELV_TYPE` (`COMPNO`,`DELV_TYPE`),
  KEY `idx_shopprodinfo_IS_OVERSEAS` (`COMPNO`,`IS_OVERSEAS`),
  KEY `idx_shopprodinfo_ADULT` (`COMPNO`,`ADULT`),
  KEY `idx_shopprodinfo_GOODS_COST` (`COMPNO`,`SHOPSENDSTATUS`,`GOODS_COST`,`CLASS_CD3`,`COMPAYNY_GOODS_CD`),
  KEY `idx_shopprodinfo_DESCRITION` (`COMPNO`,`SHOPSENDSTATUS`,`DESCRITION`,`CLASS_CD3`,`COMPAYNY_GOODS_CD`),
  KEY `idx_shopprodinfo_IMG_PATH22` (`COMPNO`,`IMG_PATH22`(30)),
  KEY `idx_shopprodinfo_CHAR_1_NM` (`COMPNO`,`CHAR_1_NM`),
  KEY `idx_shopprodinfo_DELV_COST` (`COMPNO`,`SHOPSENDSTATUS`,`DELV_COST`,`CLASS_CD3`,`COMPAYNY_GOODS_CD`),
  KEY `idx_shopprodinfo_RETURN_DELV_COST` (`COMPNO`,`SHOPSENDSTATUS`,`RETURN_DELV_COST`,`CLASS_CD3`,`COMPAYNY_GOODS_CD`),
  KEY `idx_shopprodinfo_STATUS` (`COMPNO`,`STATUS`),
  KEY `idx_shopprodinfo_INSERTDT` (`COMPNO`,`INSERTDT`),
  KEY `idx_shopprodinfo_MODIFYDT` (`COMPNO`,`MODIFYDT`),
  KEY `idx_shopprodinfo_shopsendstat_class_prodseq_desc` (`COMPNO`,`SHOPSENDSTATUS`,`CLASS_CD3`,`COMPAYNY_GOODS_CD`,`PRODSEQ` DESC),
  KEY `idx_shopprodinfo_class_cd3_shopsendstat` (`COMPNO`,`CLASS_CD3`,`SHOPSENDSTATUS`,`COMPAYNY_GOODS_CD`,`PRODSEQ`),
  FULLTEXT KEY `idx_shopprodinfo_SHOPMODIFYCONTENT` (`SHOPMODIFYCONTENT`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `shopprodinfo`
--


--
-- Table structure for table `shopprodinfo_user`
--

CREATE TABLE `shopprodinfo_user` (
  `id` int NOT NULL AUTO_INCREMENT,
  `userid` varchar(10) NOT NULL,
  `dome_code` varchar(10) NOT NULL,
  `icode` varchar(20) NOT NULL,
  `iname` text,
  `cid` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
  `es_code` varchar(50) DEFAULT NULL,
  `shop_cid_info` text,
  `cate_fullname` varchar(1000) DEFAULT NULL,
  `icountry` varchar(200) DEFAULT NULL,
  `cate_dept` varchar(10) DEFAULT NULL,
  `maker` varchar(200) DEFAULT NULL,
  `brand` varchar(200) DEFAULT NULL,
  `tax` char(1) DEFAULT NULL,
  `vender_code` varchar(200) DEFAULT NULL,
  `delivery_type` char(1) DEFAULT NULL,
  `delivery_amount` decimal(10,0) DEFAULT NULL,
  `r_delivery_amount` decimal(10,0) DEFAULT NULL,
  `delivery_qty` varchar(200) DEFAULT NULL,
  `search` varchar(200) DEFAULT NULL,
  `keyword` text,
  `price` int DEFAULT NULL,
  `price_consumer` int DEFAULT NULL,
  `islimit` char(1) DEFAULT NULL,
  `limit_price` int DEFAULT NULL,
  `content` text,
  `img` text,
  `select_option` text,
  `text_option` varchar(200) DEFAULT NULL,
  `option_use` char(1) DEFAULT NULL,
  `notice` text,
  `itype` char(1) DEFAULT NULL,
  `status` char(1) DEFAULT NULL,
  `adult` char(1) DEFAULT NULL,
  `reg_datetime` varchar(50) DEFAULT NULL,
  `up_datetime` varchar(50) DEFAULT NULL,
  `isreturn` char(1) DEFAULT NULL,
  `cert_type` char(1) DEFAULT NULL,
  `cert` varchar(100) DEFAULT NULL,
  `cert_no` varchar(100) DEFAULT NULL,
  `gosi_code` varchar(20) DEFAULT NULL,
  `gosi_info` text,
  `is_overseas` varchar(10) DEFAULT NULL,
  `is_medical` varchar(10) DEFAULT NULL,
  `is_h_food` varchar(10) DEFAULT NULL,
  `a_vender_code` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
  `a_status` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
  `img_text_detected` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '0: 텍스트 없음, 1: 텍스트 있음',
  PRIMARY KEY (`id`),
  UNIQUE KEY `shopprodinfo_user_unique` (`userid`,`dome_code`,`icode`)
) ENGINE=InnoDB AUTO_INCREMENT=4226 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `shopprodinfo_user`
--


--
-- Table structure for table `shopprodinfo_user_option`
--

CREATE TABLE `shopprodinfo_user_option` (
  `ID` int NOT NULL,
  `SKUSEQ` int NOT NULL,
  `PRODCD` varchar(20) NOT NULL,
  `OPTPRODCD` varchar(20) DEFAULT NULL,
  `OPTPRODNM` varchar(200) DEFAULT NULL,
  `OPTSPECDES` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
  `OPTEA` int DEFAULT NULL,
  `OPTSALE` char(1) DEFAULT NULL,
  `OPTSALEOUT` char(1) DEFAULT NULL,
  `OPTNOTUSE` char(1) DEFAULT NULL,
  `OPTSAFESTOCK` int DEFAULT NULL,
  `OPTVERTSTOCK` int DEFAULT NULL,
  `OPTADDAMT` int DEFAULT NULL,
  `LIMIT_PRICE` int DEFAULT '0' COMMENT '준수가격 추가',
  `OPTDELYN` char(1) DEFAULT NULL,
  `BARCODE` varchar(20) DEFAULT NULL,
  `INSERTDT` varchar(20) DEFAULT NULL,
  `INSERTID` varchar(50) DEFAULT NULL,
  `MODIFYDT` varchar(20) DEFAULT NULL,
  `MODIFYID` varchar(50) DEFAULT NULL,
  `STATUS` varchar(1) DEFAULT NULL COMMENT '사용자 정상품절 관리상태 0:정상, 1:품절',
  PRIMARY KEY (`ID`,`SKUSEQ`),
  UNIQUE KEY `shopprodinfo_user_option_un` (`ID`,`SKUSEQ`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `shopprodinfo_user_option`
--


--
-- Table structure for table `shopprodinlog`
--

CREATE TABLE `shopprodinlog` (
  `SENDSEQ` varchar(50) NOT NULL,
  `COMPNO` varchar(50) NOT NULL,
  `SHOPCD` varchar(50) DEFAULT NULL,
  `SHOPPRODNO` varchar(50) DEFAULT NULL,
  `PRODNO` varchar(50) DEFAULT NULL,
  `JSON` longtext,
  PRIMARY KEY (`SENDSEQ`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `shopprodinlog`
--


--
-- Table structure for table `shopprodinremarks`
--

CREATE TABLE `shopprodinremarks` (
  `COMPNO` int NOT NULL COMMENT '회사코드',
  `SHOPCD` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '쇼핑몰 코드',
  `SHOPSEQ` int NOT NULL COMMENT '쇼핑몰 별 SEQ',
  `PRODSEQ` int NOT NULL DEFAULT '0' COMMENT '판매자 상품코드',
  `HTML_DESC` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT 'HTML 상세설명',
  `ADD_DESC` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '추가 상세설명',
  `PRMT_DESC` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '광고/홍보 상세설명',
  `ENG_DESC` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '영어 상세설명',
  `CHI_DESC` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '중국어 상세설명',
  `JAP_DESC` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '일본어 상세설명',
  PRIMARY KEY (`COMPNO`,`SHOPCD`,`PRODSEQ`,`SHOPSEQ`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='상세설명 템플릿 테이블';

--
-- Dumping data for table `shopprodinremarks`
--


--
-- Table structure for table `shoprecvdtl`
--

CREATE TABLE `shoprecvdtl` (
  `COMPNO` int NOT NULL,
  `SHOPCD` varchar(10) NOT NULL,
  `SHOPSEQ` int NOT NULL,
  `RECVDT` varchar(8) NOT NULL,
  `RECVSEQ` int NOT NULL,
  `SEQ` int NOT NULL,
  `REMARK` varchar(100) DEFAULT NULL,
  `PLANDT` varchar(20) DEFAULT NULL,
  `BEFQTY` int DEFAULT NULL,
  `AFTQTY` int DEFAULT NULL,
  `REALDT` varchar(8) DEFAULT NULL,
  `INSERTDT` varchar(20) DEFAULT NULL,
  `INSERTID` varchar(50) DEFAULT NULL,
  `MODIFYDT` varchar(20) DEFAULT NULL,
  `MODIFYID` varchar(50) DEFAULT NULL,
  `SPARERACK1` varchar(20) DEFAULT NULL,
  `SPARERACK2` varchar(20) DEFAULT NULL,
  `SPARERACK3` varchar(20) DEFAULT NULL,
  `SPARERACK4` varchar(20) DEFAULT NULL,
  `SPARERACK5` varchar(20) DEFAULT NULL,
  `SENDSEQ` int DEFAULT NULL,
  PRIMARY KEY (`COMPNO`,`SHOPCD`,`SHOPSEQ`,`RECVDT`,`RECVSEQ`,`SEQ`),
  UNIQUE KEY `COMPNO_SHOPCD_SHOPSEQ_RECVDT_RECVSEQ_SEQ` (`COMPNO`,`SHOPCD`,`SHOPSEQ`,`RECVDT`,`RECVSEQ`,`SEQ`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `shoprecvdtl`
--


--
-- Table structure for table `shoprecvmst`
--

CREATE TABLE `shoprecvmst` (
  `COMPNO` int NOT NULL,
  `SHOPCD` varchar(10) NOT NULL,
  `SHOPSEQ` int NOT NULL,
  `RECVDT` varchar(8) NOT NULL,
  `RECVSEQ` int NOT NULL,
  `RECVGUBUN` varchar(50) DEFAULT NULL,
  `ENTDT` varchar(20) DEFAULT NULL,
  `RECVDESC` varchar(200) DEFAULT NULL,
  `BEFQTY` int DEFAULT NULL,
  `REALDT` varchar(8) DEFAULT NULL,
  `AFTQTY` int DEFAULT NULL,
  `CONFNAM` varchar(20) DEFAULT NULL,
  `CONTNO` varchar(50) DEFAULT NULL,
  `AUTOCHK` char(1) DEFAULT NULL,
  `INSERTID` varchar(50) DEFAULT NULL,
  `UPDATEID` varchar(10) DEFAULT NULL,
  `INSERTDT` varchar(20) DEFAULT NULL,
  `UPDATEDT` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`COMPNO`,`SHOPCD`,`SHOPSEQ`,`RECVDT`,`RECVSEQ`),
  UNIQUE KEY `COMPNO_SHOPCD_SHOPSEQ_RECVDT_RECVSEQ` (`COMPNO`,`SHOPCD`,`SHOPSEQ`,`RECVDT`,`RECVSEQ`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `shoprecvmst`
--


--
-- Table structure for table `shopssgaddidtl`
--

CREATE TABLE `shopssgaddidtl` (
  `SEQ` int NOT NULL,
  `COMPNO` int DEFAULT NULL,
  `SHOPCD` varchar(20) DEFAULT NULL,
  `SHOPSEQ` int DEFAULT NULL,
  `SHOPUSERID` varchar(200) DEFAULT NULL,
  `TITLE` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '제목',
  `IMGONEONONE` varchar(200) DEFAULT NULL COMMENT '이미지 1:1비율 노출',
  `IMGTHREEONFOUR` varchar(200) DEFAULT NULL COMMENT '이미지 3:4비율 노출',
  `ISCATEGORY` varchar(50) DEFAULT NULL,
  `LAGCATCD` varchar(50) DEFAULT NULL,
  `MIDCATCD` varchar(50) DEFAULT NULL,
  `SMLCATCD` varchar(50) DEFAULT NULL,
  `DETCATCD` varchar(50) DEFAULT NULL,
  `SHOPCATNO` varchar(50) DEFAULT NULL,
  `SHOPCATSITENM` varchar(50) DEFAULT NULL,
  `BRANDYN` varchar(2) DEFAULT NULL COMMENT '브랜드등록여부',
  `BRANDPRDNADDI` varchar(2) DEFAULT NULL COMMENT '브랜드상품정보사용/부가정보사용여부',
  `BRANDPRDFAIL` varchar(2) DEFAULT NULL COMMENT '브랜드상품정보사용시 실패처리/브랜드없이등록',
  `BRANDID` varchar(50) DEFAULT NULL COMMENT '브랜드아이디',
  `PRODMANUFCNTRYID` varchar(50) DEFAULT NULL COMMENT '제조국아이디',
  `ITEMCHRCTDIVCD` varchar(10) DEFAULT NULL COMMENT '상품특성구분',
  `ITEMCHRCTDTLCD` varchar(10) DEFAULT NULL COMMENT '상품특성상세',
  `EXUSITEMDIVCD` varchar(10) DEFAULT NULL COMMENT '전용상품구분',
  `EXUSITEMDTLCD` varchar(10) DEFAULT NULL COMMENT '판매유형',
  `ADULTITEMTYPECD` varchar(10) DEFAULT NULL COMMENT '성인상품유형',
  `ITEMSTATTYPECD` varchar(10) DEFAULT NULL COMMENT '새상품여부',
  `ITEMSELLWAYCD` varchar(10) DEFAULT NULL COMMENT '상품판매방법',
  `PALIMPITEMYN` varchar(10) DEFAULT NULL COMMENT '병행수입상품여부',
  `GIFTPSBLYN` varchar(10) DEFAULT NULL COMMENT '선물가능여부',
  `WHINNOTIYN` varchar(10) DEFAULT NULL COMMENT '입고알림여부',
  `MAX1DYORDPSBLQTY` int DEFAULT NULL COMMENT '1일주문가능수량',
  `MINONETORDPSBLQTY` int DEFAULT NULL COMMENT '1회주문가능수량최소',
  `MAXONETORDPSBLQTY` int DEFAULT NULL COMMENT '1회주문가능수량최대',
  `RESERVEYN` varchar(2) DEFAULT NULL COMMENT '판매종료일설정여부',
  `RESERVEDATE` varchar(20) DEFAULT NULL COMMENT '판매종료일',
  `OPTZEROPRICEYN` varchar(2) DEFAULT NULL COMMENT '추가금있는옵션제외등록여부',
  `PROMOTIONYN` varchar(2) DEFAULT NULL COMMENT '프로모션문구설정',
  `RPLCTEXTNM1` varchar(200) DEFAULT NULL COMMENT '이미지텍스트1',
  `RPLCTEXTNM2` varchar(200) DEFAULT NULL COMMENT '이미지텍스트2',
  `RPLCTEXTNM3` varchar(200) DEFAULT NULL COMMENT '이미지텍스트3',
  `RPLCTEXTNM4` varchar(200) DEFAULT NULL COMMENT '이미지텍스트4',
  `RPLCTEXTNM5` varchar(200) DEFAULT NULL COMMENT '이미지텍스트5',
  `EPLNKGYN` varchar(20) DEFAULT NULL COMMENT '가격비교사이트연동여부',
  `DCEXPSRYN` varchar(20) DEFAULT NULL COMMENT '할인가노출여부',
  `PROMOTIONAPLYN` varchar(20) DEFAULT NULL COMMENT '프로모션판촉활동여부',
  `BUYAPLYN` varchar(20) DEFAULT NULL COMMENT '구매확정적립금여부',
  `BASCPRVDPRFTVAL` int DEFAULT NULL COMMENT '구매확정적립금값',
  `BASCPRVDPRFTTYPECD` varchar(20) DEFAULT NULL COMMENT '구매확정적립금단위',
  `ADDPRVDPRFTVAL` int DEFAULT NULL COMMENT '차등적립금값',
  `ADDPRVDPRFTTYPECD` varchar(20) DEFAULT NULL COMMENT '차등적립금단위',
  `BUYAPLENDDT` varchar(20) DEFAULT NULL COMMENT '구매확적적립금할인일자',
  `REVIEWAPLYN` varchar(20) DEFAULT NULL COMMENT '리뷰등록적립금여부',
  `TEXTPRVDPRFTVAL` int DEFAULT NULL COMMENT '텍스트리뷰값',
  `PHOTOPRVDPRFTVAL` int DEFAULT NULL COMMENT '포토리뷰값',
  `REVIEWAPLENDDT` varchar(20) DEFAULT NULL COMMENT '리뷰등록할인일자',
  `MULTIBUYDISCOUNTYN` varchar(20) DEFAULT NULL COMMENT '복수구매할인여부',
  `MULTIBUYDISCOUNTTGT` int DEFAULT NULL COMMENT '복수구매할인최소금액',
  `MULTIBUYDISCOUNTTYPECD` varchar(20) DEFAULT NULL COMMENT '복수구매할인최소금액단위',
  `MULTIBUYDISCOUNT` int DEFAULT NULL COMMENT '복수구매할인제공금액',
  `MULTIBUYDISCOUNTPRICETYPECD` varchar(20) DEFAULT NULL COMMENT '복수구매할인제공단위',
  `MULTIBUYDISCOUNTISAPLDATE` varchar(20) DEFAULT NULL COMMENT '복수구매할인기간여부',
  `MULTIBUYDISCOUNTENDDT` varchar(20) DEFAULT NULL COMMENT '복수구매할인기간',
  `IMMDISCOUNTYN` varchar(20) DEFAULT NULL COMMENT '즉시할인여부',
  `IMMDISCOUNT` int DEFAULT NULL COMMENT '즉시할인금액',
  `IMMDISCOUNTTYPECD` varchar(20) DEFAULT NULL COMMENT '즉시할인금액단위',
  `IMMDISCOUNTISAPLDATE` varchar(20) DEFAULT NULL COMMENT '즉시할인기간설정',
  `IMMDISCOUNTENDDT` varchar(20) DEFAULT NULL COMMENT '즉시할인기간',
  `FREBIEINCLYN` varchar(20) DEFAULT NULL COMMENT '사은품등록여부',
  `FREBIEINCLPRDNADDI` varchar(20) DEFAULT NULL COMMENT '사은품상품정보사용/부가정보사용여부',
  `FREEGIFTNM` varchar(500) DEFAULT NULL COMMENT '사은품부가정보사용시입력글',
  `FREEGIFTAPLENDDT` varchar(20) DEFAULT NULL COMMENT '사은품적용기간',
  `INVMNGYN` varchar(20) DEFAULT NULL COMMENT '사은품재고관리사용여부',
  `INVQTY` int DEFAULT NULL COMMENT '사은품재고관리수량',
  `SALLER_DC_RATE` float DEFAULT NULL COMMENT '판매자즉시할인',
  `DC_RATE` float DEFAULT NULL COMMENT '할인율',
  `FLOAT_DC` float DEFAULT NULL COMMENT '정액할인',
  `MARGIN_RATE` float DEFAULT NULL COMMENT '마진율',
  `COMMISSION_RATE` float DEFAULT NULL COMMENT '수수료율',
  `SHPPMTHDCD` varchar(20) DEFAULT NULL COMMENT '배송방법',
  `SHPPITEMDIVCD` varchar(20) DEFAULT NULL COMMENT '배송상품구분',
  `CTVATLNCLYN` varchar(20) DEFAULT NULL COMMENT '관부가세포함여부',
  `EXPRTCNTRYID` varchar(50) DEFAULT NULL COMMENT '적출국아이디',
  `SHPPRQRMDCNT` int DEFAULT NULL COMMENT '배송소요일수',
  `RETEXCHPSBLYN` varchar(20) DEFAULT NULL COMMENT '반품가능여부',
  `TDSHPPPSBLYN` varchar(20) DEFAULT NULL COMMENT '오늘출발여부',
  `TDWHOUTCLSGHM` varchar(20) DEFAULT NULL COMMENT '오늘출발시제한시간',
  `DOFFLST` varchar(20) DEFAULT NULL COMMENT '오늘출발시토요일휴무여부',
  `MAREASHPPYN` varchar(20) DEFAULT NULL COMMENT '수도권외지역배송불가여부',
  `JEJUSHPPDISABYN` varchar(20) DEFAULT NULL COMMENT '제주배송불가여부',
  `ISMTARSHPPDISABYN` varchar(20) DEFAULT NULL COMMENT '도서산간배송불가여부',
  `WHOUTSHPPCSTID` varchar(50) DEFAULT NULL COMMENT '출고배송비아이디',
  `FREEDELIVERY` varchar(2) DEFAULT NULL,
  `EXPPRC` int DEFAULT NULL,
  `RETSHPPCSTID` varchar(50) DEFAULT NULL COMMENT '반품배송비아이디',
  `WHOUTADDRID` varchar(50) DEFAULT NULL COMMENT '출고지아이디',
  `SNBKADDRID` varchar(50) DEFAULT NULL COMMENT '반송지아이디',
  `ISMTARADDSHPPCSTID` varchar(50) DEFAULT NULL COMMENT '도서산간추가배송비아이디',
  `JEJUADDSHPPCSTID` varchar(50) DEFAULT NULL COMMENT '제주추가배송비아이디',
  `NOTICEBATCHYN` varchar(20) DEFAULT NULL COMMENT '일괄적용설정여부',
  `NOTICECD` varchar(20) DEFAULT NULL COMMENT '일괄적용밑에콤보(의미없음)',
  `NOTICETITLEYN` varchar(20) DEFAULT NULL COMMENT '품목고시타이틀사용여부',
  `SELLTATCAPA` varchar(50) DEFAULT NULL COMMENT '농수축산물시총용량',
  `SELLUNITCAPA` varchar(20) DEFAULT NULL COMMENT '농수축산물시단위수량',
  `SELLCAPAUNITCD` varchar(20) DEFAULT NULL COMMENT '농수축산물시판매용량단위',
  `SELLUNITQTY` varchar(50) DEFAULT NULL COMMENT '농수축산물시판매개수',
  `EXPORTINGCOUNTRY` varchar(50) DEFAULT NULL COMMENT '건강기능식품시수출국명',
  `TRAVELSELECTEXPENSES` varchar(500) DEFAULT NULL COMMENT '여행상품시선택경비유무',
  `TRAVELGUIDETIPS` varchar(500) DEFAULT NULL COMMENT '여행상품시가이드팁',
  `TRAVELSIGN` varchar(500) DEFAULT NULL COMMENT '여행상품시가입',
  `PHONESUBSCRIPTIONTYPE` varchar(200) DEFAULT NULL COMMENT '휴대폰시가입유형',
  `PHONEPLAN` varchar(200) DEFAULT NULL COMMENT '휴대폰시요금제',
  `PHONECONTRACTPERIOD` varchar(50) DEFAULT NULL COMMENT '휴대폰시약정기간',
  `PHONEUSIMFEE` varchar(50) DEFAULT NULL COMMENT '휴대폰시유심비',
  `PHONESUBSCRIPTIONFEE` varchar(50) DEFAULT NULL COMMENT '휴대폰시가입비',
  `PHONERELEASE` varchar(50) DEFAULT NULL COMMENT '휴대폰시출고가',
  `PHONEDISCLOSURESUBSIDY` varchar(50) DEFAULT NULL COMMENT '휴대폰시공시지원금',
  `PHONESUPPLEMENTARYSUPPORT` varchar(50) DEFAULT NULL COMMENT '휴대폰시추가지원금',
  `PHONEINSTALLMENTPRINCIPAL` varchar(50) DEFAULT NULL COMMENT '휴대폰시할부원금',
  `PHONEMONTHLYAMOUNT` varchar(50) DEFAULT NULL COMMENT '휴대폰시월할부금액',
  `PHONEMOMTHLYFEE` varchar(50) DEFAULT NULL COMMENT '휴대폰시월요금납부금액',
  `PHONEBILLDISCOUNT` varchar(50) DEFAULT NULL COMMENT '휴대폰시요금할인',
  `PHONEMONTHLYTOTALFEE` varchar(50) DEFAULT NULL COMMENT '휴대폰시월평균토탈금액',
  `RENTALMONTHLYFEE` varchar(50) DEFAULT NULL COMMENT '물품대여시월이용료',
  `EFFICIENCYYN` varchar(20) DEFAULT NULL COMMENT '가전제품시 으뜸효율가전환급여부',
  `NUTRIENT` varchar(20) DEFAULT NULL COMMENT '가공식품시영양성분표시대상여부',
  `BABYFOOD` varchar(20) DEFAULT NULL COMMENT '가공식품시영유아식여부',
  `PRODOUTPUT` varchar(20) DEFAULT NULL COMMENT '상품명출력방법',
  `PRODNMFIRST` varchar(500) DEFAULT NULL COMMENT '상품명추가앞',
  `PRODNMLAST` varchar(500) DEFAULT NULL COMMENT '상품명추가뒤',
  `REMARKFIRST` longtext COMMENT '상세설명추가앞',
  `REMARKLAST` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '상세설명추가뒤',
  `REMARKOUTPUT` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '상세설명뒤부분출력위치',
  `CHANGESIZE` varchar(50) DEFAULT NULL COMMENT '대표사진사이즈변경 버튼',
  `CHANGESIZEX` varchar(50) DEFAULT NULL COMMENT '대표사진사이즈변경 X',
  `CHANGESIZEY` varchar(50) DEFAULT NULL COMMENT '대표사진사이즈변경 Y',
  `CHANGESIZEW` varchar(50) DEFAULT NULL COMMENT '대표사진사이즈변경 W',
  `CHANGESIZEH` varchar(50) DEFAULT NULL COMMENT '대표사진사이즈변경 H',
  `DETAILKEYWORDB` varchar(50) DEFAULT NULL COMMENT '상세페이지 상단 (키워드) 버튼',
  `DETAILKEYWORDL` text COMMENT '상세페이지 상단 (키워드)',
  `DETAILKEYWORDR` text,
  `DETAILPRODUCTCODEB` varchar(50) DEFAULT NULL COMMENT '상세페이지 상단 (상품코드) 버튼',
  `DETAILPRODUCTCODEL` text COMMENT '상세페이지 상단 (상품코드)',
  `DETAILPRODUCTCODER` text,
  `DETAILPRODUCTNAMEB` varchar(50) DEFAULT NULL COMMENT '상세페이지 상단 (상품명) 버튼',
  `DETAILPRODUCTNAMEL` text COMMENT '상세페이지 상단 (상품명)',
  `DETAILPRODUCTNAMER` text,
  `ADDOPTIONLB` varchar(50) DEFAULT NULL COMMENT '옵션추가 왼쪽 버튼',
  `ADDOPTIONL` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '옵션추가 왼쪽',
  `ADDOPTIONRB` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '옵션추가 오른쪽 버튼',
  `ADDOPTIONR` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '옵션추가 오른쪽',
  `IMG_ANGLE` double DEFAULT '0' COMMENT '이미지 회전 각도',
  `IMG_SCALE_PERCENT` double DEFAULT '0' COMMENT '확대율',
  PRIMARY KEY (`SEQ`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `shopssgaddidtl`
--


--
-- Table structure for table `shoptmonaddidtl`
--

CREATE TABLE `shoptmonaddidtl` (
  `SEQ` int NOT NULL AUTO_INCREMENT,
  `COMPNO` int NOT NULL DEFAULT '0',
  `SHOPCD` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
  `SHOPSEQ` int DEFAULT NULL,
  `SHOPUSERID` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
  `TITLE` varchar(50) DEFAULT NULL COMMENT '부가정보 이름',
  `ISCATEGORY` varchar(50) DEFAULT NULL,
  `LAGCATCD` varchar(50) DEFAULT NULL,
  `MIDCATCD` varchar(50) DEFAULT NULL,
  `SMLCATCD` varchar(50) DEFAULT NULL,
  `DETCATCD` varchar(50) DEFAULT NULL,
  `SHOPCATNO` varchar(50) DEFAULT NULL,
  `SHOPCATSITENM` varchar(50) DEFAULT NULL,
  `PRODPERIOD` varchar(50) DEFAULT NULL COMMENT '판매기간',
  `PRODUCTSTATUS` varchar(10) DEFAULT NULL COMMENT '상품상태 "신상품" "중고" "리퍼" "전시" "반품" "스크레치"',
  `SELLMETHOD` varchar(10) DEFAULT NULL COMMENT '판매방식 "해당없음" "도매" "렌탈" "대여" "할부" "예약판매" "구매대행"',
  `ADULTCONFIRMATION` varchar(10) DEFAULT NULL COMMENT '성인물여부 "Y'' "N"',
  `PRODNMTOP` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '딜 홍보 문구',
  `ORIGINYN` varchar(10) DEFAULT NULL COMMENT '원산지 사용 여부',
  `MAXQTYPERPERSON` varchar(10) DEFAULT NULL COMMENT '1인당 최대 구매가능 수량',
  `PURCHASELIMIT` varchar(10) DEFAULT NULL COMMENT '1인당 최대 구매가능 수량 리셋주기',
  `SEARCHEXPOSURE` varchar(10) DEFAULT NULL COMMENT '검색노출여부',
  `PRICECOMPARISON` varchar(10) DEFAULT NULL COMMENT '가격비교사이트노출여부',
  `PRODMODIFYIMAGE` varchar(10) DEFAULT NULL COMMENT '상품수정시 이미지변경안함',
  `FOREIGNPROD` varchar(10) DEFAULT NULL COMMENT '병행수입여부',
  `FOREIGNPRODVALUE` mediumtext COMMENT '수입신고필증',
  `SELLERDC` float DEFAULT NULL COMMENT '판매자즉시할인',
  `DCRATE` float DEFAULT NULL COMMENT '할인율',
  `CUMDC` float DEFAULT NULL COMMENT '정액할인',
  `MARGINDC` float DEFAULT NULL COMMENT '마진율',
  `COMMDC` float DEFAULT NULL COMMENT '수수료율',
  `DELIVERYFEESRL` varchar(50) DEFAULT NULL COMMENT '배송비템플릿 번호',
  `FREEDELIVERY` varchar(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '+2500 Y사용함 N사용안함',
  `EXPPRC` int DEFAULT NULL,
  `DELIVERYPRODUCTTYPE` varchar(50) DEFAULT NULL COMMENT '상품유형',
  `COLLECTIDENTIFY` varchar(50) DEFAULT NULL COMMENT '개인통관번호 입력 유무',
  `DELIVERYCORPTYPE` varchar(50) DEFAULT NULL COMMENT '택배사',
  `REFUNDTYPE` varchar(50) DEFAULT NULL COMMENT '단순변심 환불가능여부',
  `REFUNDREASON` varchar(50) DEFAULT NULL COMMENT '단순변심 환불 이유',
  `DIFFERENTDELIVERYFEE` varchar(50) DEFAULT NULL COMMENT '지역별차등배송비적용',
  `DIFFERENTDELIVERYFEECONTENTS` varchar(50) DEFAULT NULL COMMENT '지역별차등배송비적용 문구',
  `DELIVERYTEMPLATE` varchar(50) DEFAULT NULL COMMENT '배송비템플릿 추가',
  `NOTICEBATCHYN` varchar(10) DEFAULT NULL COMMENT '상품고시 일괄적용 여부',
  `NOTICECD` varchar(10) DEFAULT NULL COMMENT '상품고시 일괄적용시 고시코드번호',
  `PRODOUTPUT` varchar(50) DEFAULT NULL COMMENT '상품명출력방법',
  `PRODNMFIRST` varchar(100) DEFAULT NULL COMMENT '상품명추가글귀앞',
  `PRODNMLAST` varchar(100) DEFAULT NULL COMMENT '상품명추가글귀뒤',
  `REMARKFIRST` mediumtext COMMENT '상세설명앞부분추가',
  `REMARKLAST` mediumtext COMMENT '상세설명뒷부분추가',
  `REMARKOUTPUT` varchar(50) DEFAULT NULL COMMENT '상품상세설명뒷부분출력위치',
  `CHANGESIZE` varchar(50) DEFAULT NULL COMMENT '대표사진사이즈변경 버튼',
  `CHANGESIZEX` varchar(50) DEFAULT NULL COMMENT '대표사진사이즈변경 X',
  `CHANGESIZEY` varchar(50) DEFAULT NULL COMMENT '대표사진사이즈변경 Y',
  `CHANGESIZEW` varchar(50) DEFAULT NULL COMMENT '대표사진사이즈변경 W',
  `CHANGESIZEH` varchar(50) DEFAULT NULL COMMENT '대표사진사이즈변경 H',
  `DETAILKEYWORDB` varchar(50) DEFAULT NULL COMMENT '상세페이지 상단 (키워드) 버튼',
  `DETAILKEYWORDL` text COMMENT '상세페이지 상단 (키워드)',
  `DETAILKEYWORDR` text,
  `DETAILPRODUCTCODEB` varchar(50) DEFAULT NULL COMMENT '상세페이지 상단 (상품코드) 버튼',
  `DETAILPRODUCTCODEL` text COMMENT '상세페이지 상단 (상품코드)',
  `DETAILPRODUCTCODER` text,
  `DETAILPRODUCTNAMEB` varchar(50) DEFAULT NULL COMMENT '상세페이지 상단 (상품명) 버튼',
  `DETAILPRODUCTNAMEL` text COMMENT '상세페이지 상단 (상품명)',
  `DETAILPRODUCTNAMER` text,
  `ADDOPTIONLB` varchar(50) DEFAULT NULL COMMENT '옵션추가 왼쪽 버튼',
  `ADDOPTIONL` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '옵션추가 왼쪽',
  `ADDOPTIONRB` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '옵션추가 오른쪽 버튼',
  `ADDOPTIONR` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '옵션추가 오른쪽',
  `IMG_ANGLE` double DEFAULT '0' COMMENT '이미지 회전 각도',
  `IMG_SCALE_PERCENT` double DEFAULT '0' COMMENT '확대율',
  `MIRRORIMGYN` char(1) DEFAULT 'N' COMMENT '대표사진 좌우반전 사용 여부',
  PRIMARY KEY (`SEQ`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=DYNAMIC;

--
-- Dumping data for table `shoptmonaddidtl`
--


--
-- Table structure for table `shoptossshoppingadddtl`
--

CREATE TABLE `shoptossshoppingadddtl` (
  `SEQ` int NOT NULL COMMENT '일련번호',
  `COMPNO` int DEFAULT NULL COMMENT '회사코드',
  `SHOPCD` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '쇼핑몰코드',
  `SHOPSEQ` int DEFAULT NULL,
  `SHOPID` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '아이디',
  `TITLE` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '부가정보이름',
  `ISCATEGORY` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
  `LAGCATCD` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
  `MIDCATCD` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
  `SMLCATCD` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
  `DETCATCD` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
  `SHOPCATNO` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
  `SHOPCATSITENM` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
  `USEADIMGYN` varchar(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '광고 이미지',
  `RESIZETHUMBNAILYN` varchar(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '섬네일 이미지리사이징',
  `RESIZEADYN` varchar(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '광고 이미지리사이징',
  `DELIVERY_TEMP_ID` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '배송템플릿',
  `EXCHANGEORRETURN_TEMP_ID` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '교환 · 반품 템플릿',
  `MINDELIVERYELAPSEDDAY` int DEFAULT NULL COMMENT '최소배송일수',
  `MAXDELIVERYELAPSEDDAY` int DEFAULT NULL COMMENT '최대배송일수',
  `DELIVERYAVAILABLEREGION` varchar(200) DEFAULT NULL COMMENT '배송가능지역',
  `CANBEDELIVEREDLONGDISTANCE` varchar(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '제주/도서산간 배송 가능 여부',
  `LONGDISTANCEDELIVERYCOST` int DEFAULT NULL COMMENT '제주/도서산간 추가 배송비',
  `BOTHWAYSDELIVERYCOST` int DEFAULT NULL COMMENT '교환/반품 시 왕복 배송비',
  `APPLICATIONMETHODDESCRIPTION` text COMMENT '교환/반품 신청 방법',
  `APPLICATIONTERMDESCRIPTION` varchar(200) DEFAULT NULL COMMENT '교환/반품 신청 가능 기간',
  `APPLICATIONIMPOSSIBLECASEDESCRIPTION` text COMMENT '교환/반품 불가 조건',
  `DELIVERYCOST` int DEFAULT '0' COMMENT '배송비',
  `COLLECTIVEAPPLICATION` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '일괄적용설정',
  `COLLECTIVEAPPVALUE1` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '일괄적용설정 값',
  `TITLEYN` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '타이틀사용여부',
  `PRODNMOUTPUT` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '상품명출력방법 ',
  `PRODNMADDFRONT` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '상품명추가글귀(앞)',
  `PRODNMADDBACK` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '상품명추가글귀(뒤)',
  `ANGLE` double DEFAULT '0' COMMENT '이미지 회전 각도',
  `SCALEPERCENT` double DEFAULT '0' COMMENT '확대율',
  `CHANGESIZE` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '대표사진사이즈변경 버튼',
  `CHANGESIZEX` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '대표사진사이즈변경 X',
  `CHANGESIZEY` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '대표사진사이즈변경 Y',
  `CHANGESIZEW` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '대표사진사이즈변경 W',
  `CHANGESIZEH` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '대표사진사이즈변경 H',
  `DETAILKEYWORDB` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '상세페이지 상단 (키워드) 버튼',
  `DETAILKEYWORDL` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '상세페이지 상단 (키워드)',
  `DETAILKEYWORDR` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
  `DETAILPRODUCTCODEB` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '상세페이지 상단 (상품코드) 버튼',
  `DETAILPRODUCTCODEL` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '상세페이지 상단 (상품코드)',
  `DETAILPRODUCTCODER` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
  `DETAILPRODUCTNAMEB` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '상세페이지 상단 (상품명) 버튼',
  `DETAILPRODUCTNAMEL` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '상세페이지 상단 (상품명)',
  `DETAILPRODUCTNAMER` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
  `PRODDETAILFRONT` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '상품상세설명앞부분추가내용',
  `PRODDETAILBACK` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '상품상세설명뒷부분추가내용',
  `PRODDETAILOUTPUT` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '상품상세설명뒷부분출력위치',
  `ADDOPTIONLB` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '옵션추가 왼쪽 버튼',
  `ADDOPTIONL` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '옵션추가 왼쪽',
  `ADDOPTIONRB` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '옵션추가 오른쪽 버튼',
  `SELLERDC` float DEFAULT NULL COMMENT '판매자즉시할인',
  `COMMDC` float DEFAULT NULL COMMENT '수수료율',
  `DCRATE` float DEFAULT NULL COMMENT '할인율',
  `FLATDC` float DEFAULT NULL COMMENT '정액할인',
  `MARGINDC` float DEFAULT NULL COMMENT '마진율',
  `IMGONEONONE` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '이미지 1:1비율 노출',
  `IMGTHREEONFOUR` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '이미지 3:4비율 노출',
  `ADDOPTIONR` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
  `DELIVERYMETHOD` varchar(200) DEFAULT NULL COMMENT '배송 방식',
  `ISGROUPDELIVERY` varchar(2) DEFAULT NULL COMMENT '묶음배송 여부',
  `LOCATIONID` varchar(200) DEFAULT NULL COMMENT '묶음배송 로케이션아이디',
  `DELIVERYFEETYPE` varchar(200) DEFAULT NULL COMMENT '배송비 유형',
  `JEJUDELIVERYFEE` int DEFAULT NULL COMMENT '제주도 추가 배송비',
  `EXCHANGEROUNDTRIPDELIVERYFEE` int DEFAULT NULL COMMENT '교환 왕복 배송비',
  `GROUPDELIVERYNAME` varchar(200) DEFAULT NULL COMMENT '묶음그룹명',
  `REFUNDEXCHANGENAME` varchar(200) DEFAULT NULL COMMENT '교환반품지명',
  `REFUNDEXCHANGELOCATIONID` varchar(200) DEFAULT NULL COMMENT '교환반품 로케이션 아이디',
  `REMOVEIMGTEXTYN` char(1) DEFAULT 'N' COMMENT '이미지 텍스트 제거 여부',
  `MIRRORIMGYN` char(1) DEFAULT 'N' COMMENT '대표사진 좌우반전 사용 여부',
  `PRICEADDDELIVERYCOSTYN` char(1) DEFAULT 'Y' COMMENT '무료배송일때 상품가격에 배송비 추가 사용여부',
  `EXPPRC` varchar(10) DEFAULT '9999' COMMENT '추가할 배송비 ''9999''이면 상품정보에 있는거 없으면 환경설정 배송비',
  `USERSALEYN` char(1) DEFAULT 'N' COMMENT '사용자 할인율 적용 사용여부',
  `USERSALEPERCENT` int DEFAULT NULL COMMENT '사용자 할인율',
  `USEADDITIONALDELIVERYTYPEYN` char(1) DEFAULT 'Y' COMMENT '배송유형 부가정보사용 : Y , 상품정보사용 : N',
  `DELIVERYTYPE` char(1) DEFAULT 'F' COMMENT '배송비 유형 무료 : F(FREE), 유료 : P(PAID),  조건부 : C(CONDITIONAL)',
  `BASEFEE` int DEFAULT '0' COMMENT '부가정보사용 유료일때 기본 배송비',
  `FREEAMTCOND` int DEFAULT '0' COMMENT '조건부무료 하기위한 최소금액',
  `IMGTEXTEXCLUDEYN` char(1) DEFAULT 'N' COMMENT '텍스트 포함 이미지 등록 제외 여부 - 등록 : Y, 제외 : N',
  `DELIVERYDEADLINE` varchar(100) DEFAULT NULL COMMENT '출고 마감 시각 (HH:mm, 30분 단위)',
  `PREPARATIONDAYS` int DEFAULT NULL COMMENT '상품 준비 기간 (일, 최대 14일)',
  `DELIVERYCOMPANYID` int DEFAULT NULL COMMENT '택배사 ID',
  PRIMARY KEY (`SEQ`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `shoptossshoppingadddtl`
--


--
-- Table structure for table `shopwemarketadddtl`
--

CREATE TABLE `shopwemarketadddtl` (
  `SEQ` int NOT NULL AUTO_INCREMENT,
  `COMPNO` int NOT NULL DEFAULT '0',
  `SHOPCD` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
  `SHOPSEQ` int DEFAULT NULL,
  `SHOPUSERID` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
  `TITLE` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '부가정보 이름',
  `IMGONEONONE` varchar(200) DEFAULT NULL COMMENT '이미지 1:1비율 노출',
  `IMGTHREEONFOUR` varchar(50) DEFAULT NULL COMMENT '이미지 3:4비율 노출',
  `ISCATEGORY` varchar(50) DEFAULT NULL,
  `LAGCATCD` varchar(50) DEFAULT NULL,
  `MIDCATCD` varchar(50) DEFAULT NULL,
  `SMLCATCD` varchar(50) DEFAULT NULL,
  `DETCATCD` varchar(50) DEFAULT NULL,
  `SHOPCATNO` varchar(50) DEFAULT NULL,
  `SHOPCATSITENM` varchar(50) DEFAULT NULL,
  `PRODUCTTYPE` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '상품유형',
  `BRANDYN` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '브랜드여부',
  `BRANDNM` varchar(50) DEFAULT NULL COMMENT '브랜드명',
  `BRANDNO` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '브랜드부가정보시입력',
  `MAKERYN` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '제조사여부',
  `MAKERNM` varchar(50) DEFAULT NULL COMMENT '제조사명',
  `MAKERNO` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '제조사부가정보시입력',
  `BIZYN` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '사업자전용상품여부',
  `DISPLAYYN` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '노출여부',
  `DISPLAYONLYDEALYN` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '딜에서만노출여부',
  `TAXYN` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '과세여부',
  `REFERENCEPRICETYPE` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '기준가격근거',
  `SALEPERIODYN` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '판매기간여부',
  `SALEENDPERIOD` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '판매종료일',
  `PURCHASEMINCOUNT` int DEFAULT NULL COMMENT '최소구매수량',
  `PURCHASELIMITYN` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '구매수량제한여부',
  `PURCHASELIMITDURATION` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '구매수량제한기준',
  `PURCHASELIMITDAY` int DEFAULT NULL COMMENT '구매수량1',
  `PURCHASELIMITCOUNT` int DEFAULT NULL COMMENT '구매수량2',
  `BASKETLIMITYN` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '장바구니제한여부',
  `IMAGERESIZEYN` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '이미지리사이징여부',
  `IMAGERESIZE` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '이미지리사이징값',
  `PRICECOMPARISONSITEYN` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '제휴채널등록여부',
  `ADULTLIMITYN` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '19금제한여부',
  `PARALLELIMPORTYN` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '병행수입여부',
  `PARALLELIMPORTURL` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '수입신고필증',
  `LABELNOLIST` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '상품속성라벨',
  `REVIEWDISP` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '구매후기노출제한여부',
  `SELLERDC` float DEFAULT NULL COMMENT '판매자즉시할인',
  `DCRATE` float DEFAULT NULL COMMENT '할인율',
  `CUMDC` float DEFAULT NULL COMMENT '정액할인',
  `MARGINDC` float DEFAULT NULL COMMENT '마진율',
  `COMMDC` float DEFAULT NULL COMMENT '수수료율',
  `SHIPPOLICYNO` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '배송비템플릿 번호',
  `FREEDELIVERY` varchar(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '+2500 T 사용함 F사용안함',
  `EXPPRC` int DEFAULT NULL,
  `NOTICEBATCHYN` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '상품고시 일괄적용 여부',
  `NOTICECD` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '상품고시 일괄적용시 고시코드번호',
  `PRODOUTPUT` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '상품명출력방법',
  `PRODNMFIRST` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '상품명추가글귀앞',
  `PRODNMLAST` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '상품명추가글귀뒤',
  `REMARKFIRST` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '상세설명앞부분추가',
  `REMARKLAST` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '상세설명뒷부분추가',
  `REMARKOUTPUT` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '상품상세설명뒷부분출력위치',
  `CHANGESIZE` varchar(50) DEFAULT NULL COMMENT '대표사진사이즈변경 버튼',
  `CHANGESIZEX` varchar(50) DEFAULT NULL COMMENT '대표사진사이즈변경 X',
  `CHANGESIZEY` varchar(50) DEFAULT NULL COMMENT '대표사진사이즈변경 Y',
  `CHANGESIZEW` varchar(50) DEFAULT NULL COMMENT '대표사진사이즈변경 W',
  `CHANGESIZEH` varchar(50) DEFAULT NULL COMMENT '대표사진사이즈변경 H',
  `DETAILKEYWORDB` varchar(50) DEFAULT NULL COMMENT '상세페이지 상단 (키워드) 버튼',
  `DETAILKEYWORDL` text COMMENT '상세페이지 상단 (키워드)',
  `DETAILKEYWORDR` text,
  `DETAILPRODUCTCODEB` varchar(50) DEFAULT NULL COMMENT '상세페이지 상단 (상품코드) 버튼',
  `DETAILPRODUCTCODEL` text COMMENT '상세페이지 상단 (상품코드)',
  `DETAILPRODUCTCODER` text,
  `DETAILPRODUCTNAMEB` varchar(50) DEFAULT NULL COMMENT '상세페이지 상단 (상품명) 버튼',
  `DETAILPRODUCTNAMEL` text COMMENT '상세페이지 상단 (상품명)',
  `DETAILPRODUCTNAMER` text,
  `ADDOPTIONLB` varchar(50) DEFAULT NULL COMMENT '옵션추가 왼쪽 버튼',
  `ADDOPTIONL` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '옵션추가 왼쪽',
  `ADDOPTIONRB` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '옵션추가 오른쪽 버튼',
  `ADDOPTIONR` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '옵션추가 오른쪽',
  `IMG_ANGLE` double DEFAULT '0' COMMENT '이미지 회전 각도',
  `IMG_SCALE_PERCENT` double DEFAULT '0' COMMENT '확대율',
  `MIRRORIMGYN` char(1) DEFAULT 'N' COMMENT '대표사진 좌우반전 사용 여부',
  PRIMARY KEY (`SEQ`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=DYNAMIC;

--
-- Dumping data for table `shopwemarketadddtl`
--


--
-- Table structure for table `smschargedtl`
--

CREATE TABLE `smschargedtl` (
  `COMPNO` int NOT NULL,
  `ALIASESEQ` varchar(50) NOT NULL COMMENT '별명+일련번호',
  `TOCONTACT` varchar(20) DEFAULT NULL COMMENT '받는사람연락처',
  `CONTENTS` varchar(1000) DEFAULT NULL COMMENT '내용',
  `SENTDATE` varchar(20) DEFAULT NULL COMMENT '보낸날짜',
  `TIMESPENT` varchar(20) DEFAULT NULL COMMENT '보낸시간',
  `SMSTYPE` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`COMPNO`,`ALIASESEQ`),
  UNIQUE KEY `COMPNO_ALIASESEQ` (`COMPNO`,`ALIASESEQ`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `smschargedtl`
--


--
-- Table structure for table `smschargemst`
--

CREATE TABLE `smschargemst` (
  `COMPNO` int NOT NULL COMMENT '회사코드',
  `SMSALIASE` varchar(100) NOT NULL DEFAULT '' COMMENT '별명',
  `SMSNO` varchar(100) DEFAULT NULL COMMENT '발신번호',
  `SMSCHGAMT` int DEFAULT NULL COMMENT '충전금액',
  `SMSUSEAMT` int DEFAULT NULL COMMENT '사용금액',
  `SMSBALANCE` int DEFAULT NULL COMMENT '잔액',
  `CONTPRICE` int DEFAULT NULL COMMENT '계약단가',
  `SERIALNO` int NOT NULL COMMENT '일련번호',
  `USERID` varchar(50) NOT NULL COMMENT '사용자아이디',
  `SMSPRICE` int NOT NULL,
  `LMSPRICE` int NOT NULL,
  PRIMARY KEY (`COMPNO`),
  UNIQUE KEY `COMPNM` (`COMPNO`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `smschargemst`
--


--
-- Table structure for table `sum_prodincounts`
--

CREATE TABLE `sum_prodincounts` (
  `COMPNO` int NOT NULL,
  `GOODS_KEYWORD` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  `SHOPCD` varchar(50) NOT NULL,
  `SHOPID` varchar(50) NOT NULL,
  `SHOPSEQ` int NOT NULL,
  `SHOPSENDSTATUS` int NOT NULL,
  `COUNTS` int DEFAULT NULL,
  PRIMARY KEY (`COMPNO`,`GOODS_KEYWORD`,`SHOPCD`,`SHOPID`,`SHOPSEQ`,`SHOPSENDSTATUS`),
  UNIQUE KEY `COMPNO_GOODS_KEYWORD_SHOPCD_SHOPID_SHOPSEQ_SHOPSENDSTATUS` (`COMPNO`,`GOODS_KEYWORD`,`SHOPCD`,`SHOPID`,`SHOPSEQ`,`SHOPSENDSTATUS`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `sum_prodincounts`
--


--
-- Table structure for table `sum_prodwareqty`
--

CREATE TABLE `sum_prodwareqty` (
  `COMPNO` int NOT NULL COMMENT '회사코드',
  `prodcd` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '상품코드',
  `baseqty` decimal(54,0) NOT NULL DEFAULT '0' COMMENT '기초재고',
  `receiveqty` decimal(54,0) NOT NULL DEFAULT '0' COMMENT '입고수량',
  `saleqty` decimal(54,0) NOT NULL DEFAULT '0' COMMENT '판매수량',
  `inwareqty` decimal(56,0) NOT NULL DEFAULT '0' COMMENT '수불재고',
  `befqty` decimal(54,0) NOT NULL DEFAULT '0' COMMENT '이동중 재고',
  `retnqty` decimal(57,0) NOT NULL DEFAULT '0' COMMENT '입고수량중 반품입고수량',
  `warqty` decimal(57,0) NOT NULL DEFAULT '0' COMMENT '창고재고',
  PRIMARY KEY (`COMPNO`,`prodcd`),
  UNIQUE KEY `COMPNO_prodcd` (`COMPNO`,`prodcd`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `sum_prodwareqty`
--


--
-- Table structure for table `sum_shop_prodwareqty`
--

CREATE TABLE `sum_shop_prodwareqty` (
  `COMPNO` int NOT NULL,
  `SHOPCD` varchar(10) NOT NULL,
  `SHOPSEQ` int NOT NULL,
  `SENDSEQ` int NOT NULL,
  `OPTPRODCD` varchar(20) NOT NULL,
  `BASEQTY` decimal(10,0) DEFAULT NULL,
  `RECEIVEQTY` decimal(10,0) DEFAULT NULL,
  `SUPPQTY` decimal(10,0) DEFAULT NULL,
  `SALEQTY` decimal(10,0) DEFAULT NULL,
  `INWAREQTY` decimal(10,0) DEFAULT NULL,
  `BEFQTY` decimal(10,0) DEFAULT NULL,
  `RETNQTY` decimal(10,0) DEFAULT NULL,
  `WARQTY` decimal(10,0) DEFAULT NULL,
  PRIMARY KEY (`COMPNO`,`SHOPCD`,`SHOPSEQ`,`SENDSEQ`,`OPTPRODCD`),
  UNIQUE KEY `COMPNO_SHOPCD_SHOPSEQ_SENDSEQ_OPTPRODCD` (`COMPNO`,`SHOPCD`,`SHOPSEQ`,`SENDSEQ`,`OPTPRODCD`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `sum_shop_prodwareqty`
--


--
-- Table structure for table `sum_shopwareqty`
--

CREATE TABLE `sum_shopwareqty` (
  `COMPNO` varchar(20) NOT NULL DEFAULT '',
  `SHOPCD` decimal(57,0) NOT NULL DEFAULT '0',
  `PRODCD` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '',
  `BASEQTY` decimal(54,0) NOT NULL DEFAULT '0',
  `RECEIVEQTY` decimal(54,0) NOT NULL DEFAULT '0',
  `SALEQTY` decimal(54,0) NOT NULL DEFAULT '0',
  `INWAREQTY` decimal(56,0) NOT NULL DEFAULT '0',
  `BEFQTY` decimal(54,0) NOT NULL DEFAULT '0',
  `RETNQTY` decimal(57,0) NOT NULL DEFAULT '0',
  `WARQTY` decimal(57,0) NOT NULL DEFAULT '0',
  PRIMARY KEY (`COMPNO`,`SHOPCD`,`PRODCD`),
  UNIQUE KEY `COMPNO_SHOPCD_PRODCD` (`COMPNO`,`SHOPCD`,`PRODCD`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `sum_shopwareqty`
--


--
-- Table structure for table `suppdtl`
--

CREATE TABLE `suppdtl` (
  `COMPNO` int NOT NULL,
  `BRANDCD` int NOT NULL,
  `SUPPDT` varchar(8) NOT NULL,
  `SUPPSEQ` int NOT NULL,
  `SEQ` int NOT NULL,
  `EXPNM` varchar(50) DEFAULT NULL COMMENT '택배업체',
  `INVNO` varchar(50) DEFAULT NULL COMMENT '송장번호',
  `ORDDT` varchar(8) DEFAULT NULL,
  `ORDSEQ` int DEFAULT NULL COMMENT '차수',
  `ORDHSEQ` int DEFAULT NULL COMMENT '주문일련번호',
  `RCVNAM` varchar(50) DEFAULT NULL,
  `PSTNO` varchar(10) DEFAULT NULL,
  `ADDR` varchar(200) DEFAULT NULL,
  `PRODCD` varchar(20) DEFAULT NULL COMMENT '대표상품코드',
  `EXPPRODNM` varchar(1000) DEFAULT NULL,
  `QTY` int DEFAULT NULL COMMENT '출고요청수량',
  `PICQTY` int DEFAULT NULL COMMENT '실출고수량',
  PRIMARY KEY (`COMPNO`,`BRANDCD`,`SUPPDT`,`SUPPSEQ`,`SEQ`),
  UNIQUE KEY `COMPNO_BRANDCD_ORDDT_ORDSEQ_SEQ` (`COMPNO`,`BRANDCD`,`SUPPDT`,`SUPPSEQ`,`SEQ`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `suppdtl`
--


--
-- Table structure for table `suppware`
--

CREATE TABLE `suppware` (
  `COMPNO` int NOT NULL,
  `BRANDCD` int NOT NULL,
  `SUPPDT` varchar(8) NOT NULL,
  `SUPPSEQ` int NOT NULL COMMENT 'dtl차수',
  `SEQ` int NOT NULL COMMENT 'dtl순번',
  `NECSEQ` int NOT NULL COMMENT '세트번호',
  `ADDSEQ` int NOT NULL COMMENT '순번',
  `PRODCDM` varchar(20) DEFAULT NULL COMMENT '대표상품코드',
  `PRODCD` varchar(20) DEFAULT NULL COMMENT '재고관리상품코드',
  `SETLEVEL` tinyint DEFAULT NULL COMMENT '세트레벨',
  `WARECD` int DEFAULT NULL COMMENT '창고코드',
  `NECCD1` varchar(2) DEFAULT NULL,
  `NECCD2` int DEFAULT NULL,
  `NECCD3` int DEFAULT NULL,
  `QTY` int DEFAULT NULL,
  PRIMARY KEY (`COMPNO`,`BRANDCD`,`SUPPDT`,`SUPPSEQ`,`SEQ`,`NECSEQ`,`ADDSEQ`),
  UNIQUE KEY `COMPNO_BRANDCD_SUPPDT_SUPPSEQ_SEQ_NECSEQ_ADDSEQ` (`COMPNO`,`BRANDCD`,`SUPPDT`,`SUPPSEQ`,`SEQ`,`NECSEQ`,`ADDSEQ`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `suppware`
--

DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `suppware_after_insert` AFTER INSERT ON `suppware` FOR EACH ROW BEGIN

	IF (SELECT EXISTS (SELECT 1  FROM SUM_WAREHOUSEQTY

							  WHERE COMPNO = NEW.COMPNO 

								AND BRANDCD = NEW.BRANDCD 

							   AND PRODCD = NEW.PRODCD 

								AND WARECD = NEW.WARECD 

								AND NECCD1 = NEW.NECCD1

								AND NECCD2 = NEW.NECCD2

								AND NECCD3 = NEW.NECCD3) AS FLAG) THEN

		UPDATE SUM_WAREHOUSEQTY SET SALEQTY = SALEQTY + IFNULL(NEW.QTY,0), WAREQTY = WAREQTY - IFNULL(NEW.QTY,0)

							  WHERE COMPNO = NEW.COMPNO 

								AND BRANDCD = NEW.BRANDCD 

							   AND PRODCD = NEW.PRODCD 

								AND WARECD = NEW.WARECD 

								AND NECCD1 = NEW.NECCD1

								AND NECCD2 = NEW.NECCD2

								AND NECCD3 = NEW.NECCD3;

	ELSE 

		INSERT INTO SUM_WAREHOUSEQTY(COMPNO, BRANDCD, PRODCD, WARECD, NECCD1, NECCD2, NECCD3, BASEQTY, RECEIVEQTY, SALEQTY, WAREQTY) 

		VALUES (NEW.COMPNO, NEW.BRANDCD, NEW.PRODCD, NEW.WARECD, NEW.NECCD1, NEW.NECCD2, NEW.NECCD3, 0, 0, IFNULL(NEW.QTY,0), IFNULL(NEW.QTY,0)*-1);

	END IF;

END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `suppware_before_update` BEFORE UPDATE ON `suppware` FOR EACH ROW BEGIN

	UPDATE SUM_WAREHOUSEQTY SET SALEQTY = SALEQTY - IFNULL(OLD.QTY,0), WAREQTY = WAREQTY +  IFNULL(OLD.QTY,0)

							  WHERE COMPNO = OLD.COMPNO 

								AND BRANDCD = OLD.BRANDCD 

							   AND PRODCD = OLD.PRODCD 

								AND WARECD = OLD.WARECD 

								AND NECCD1 = OLD.NECCD1

								AND NECCD2 = OLD.NECCD2

								AND NECCD3 = OLD.NECCD3;

END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `suppware_after_update` AFTER UPDATE ON `suppware` FOR EACH ROW BEGIN

	IF (SELECT EXISTS (SELECT 1  FROM SUM_WAREHOUSEQTY

							  WHERE COMPNO = NEW.COMPNO 

								AND BRANDCD = NEW.BRANDCD 

							   AND PRODCD = NEW.PRODCD 

								AND WARECD = NEW.WARECD 

								AND NECCD1 = NEW.NECCD1

								AND NECCD2 = NEW.NECCD2

								AND NECCD3 = NEW.NECCD3) AS FLAG) THEN

		UPDATE SUM_WAREHOUSEQTY SET SALEQTY = SALEQTY + IFNULL(NEW.QTY,0), WAREQTY = WAREQTY - IFNULL(NEW.QTY,0)

							  WHERE COMPNO = NEW.COMPNO 

								AND BRANDCD = NEW.BRANDCD 

							   AND PRODCD = NEW.PRODCD 

								AND WARECD = NEW.WARECD 

								AND NECCD1 = NEW.NECCD1

								AND NECCD2 = NEW.NECCD2

								AND NECCD3 = NEW.NECCD3;

	ELSE 

		INSERT INTO SUM_WAREHOUSEQTY(COMPNO, BRANDCD, PRODCD, WARECD, NECCD1, NECCD2, NECCD3, BASEQTY, RECEIVEQTY, SALEQTY, WAREQTY) 

		VALUES (NEW.COMPNO, NEW.BRANDCD, NEW.PRODCD, NEW.WARECD, NEW.NECCD1, NEW.NECCD2, NEW.NECCD3, 0, 0, IFNULL(NEW.QTY,0), IFNULL(NEW.QTY,0)*-1);

	END IF;

END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `suppware_after_delete` AFTER DELETE ON `suppware` FOR EACH ROW BEGIN

	UPDATE SUM_WAREHOUSEQTY SET SALEQTY = SALEQTY - IFNULL(OLD.QTY,0), WAREQTY = WAREQTY +  IFNULL(OLD.QTY,0)

							  WHERE COMPNO = OLD.COMPNO 

								AND BRANDCD = OLD.BRANDCD 

							   AND PRODCD = OLD.PRODCD 

								AND WARECD = OLD.WARECD 

								AND NECCD1 = OLD.NECCD1

								AND NECCD2 = OLD.NECCD2

								AND NECCD3 = OLD.NECCD3;

END */;;
DELIMITER ;

--
-- Table structure for table `systemconf`
--

CREATE TABLE `systemconf` (
  `COMPNO` int NOT NULL,
  `SUGGPROCNT` int NOT NULL COMMENT '작업관리 제안프로세스 갯수',
  `ORDPERIOD` int NOT NULL COMMENT '주문 기본검색일자(7일간 자료)',
  `ORDSTATUS` varchar(50) NOT NULL COMMENT '주문 기본 표시 주문 상태',
  `ORDIMPTPER` int NOT NULL COMMENT '주문 검색기간(90일)',
  `PRODMNG` int NOT NULL COMMENT '상품관리검색일자',
  `PRODLINK` int NOT NULL COMMENT '상품연동검색일자',
  `PRODFAIL` int NOT NULL COMMENT '상품실패검색일자',
  `EXCEPKEYWDYN` char(1) NOT NULL COMMENT '상품등록 금지 키워드 YN',
  `EXCEPKEYWD` varchar(200) NOT NULL COMMENT '상품등록 금지 키워드',
  `PRODNM_LENMNGYN` char(1) NOT NULL COMMENT '상품명길이관리여부',
  `STSCPERIOD` int NOT NULL COMMENT '통계검색기간',
  `ENDDATE` int NOT NULL COMMENT '종료대기 전환일자',
  `DELIVERYNM` varchar(50) NOT NULL COMMENT '자주사용하는 택배사',
  `PRODSEARCHYN` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT 'backjob실행시 수정대기',
  `PRODSEARCHYN2` char(1) DEFAULT NULL COMMENT 'backjob실행시 자체수정',
  `PROCCNT` int DEFAULT '100' COMMENT '프로세스당실행개수',
  `DELIVERYCOST` int DEFAULT NULL COMMENT '(반품)배송비',
  `PRODDUP1` char(1) DEFAULT NULL,
  `PRODDUP2` char(1) DEFAULT NULL,
  `PRODCPYYN` char(1) DEFAULT NULL COMMENT '복사 상품코드 사용여부 ',
  `AUTOSTAT` tinyint DEFAULT '0',
  `URL_PRODRECV` varchar(50) DEFAULT 'http://api.kdjsystem.com:8080',
  `SECONDAUTH11STYN` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '11번가 2차인증 사용여부',
  `DISPLAYHOME` char(1) DEFAULT 'Y' COMMENT 'home표시여부',
  `OUTOFPRODINFO` char(1) DEFAULT 'N' COMMENT '상품관리 전체상품에 쇼핑몰정보 포함여부',
  `PRODDUP3` char(1) DEFAULT NULL COMMENT '엠링크 전체 중복체크',
  `PRODCPY_LOC` varchar(10) DEFAULT 'right' COMMENT '복사 상품 코드 사용 시 위치',
  `SAVEPRODUCTLOGYN` char(1) DEFAULT 'N' COMMENT '상품 등록 시 통계정보에 로그 남길건지 사용여부',
  `SLACKYN` char(1) DEFAULT 'N',
  `SLACKKEY` varchar(500) DEFAULT NULL,
  `SLACKURL` varchar(500) DEFAULT NULL,
  `SLACKID` varchar(50) DEFAULT NULL,
  `STARTMENU` varchar(10) DEFAULT 'N' COMMENT '시작메뉴 설정 - 엠링크',
  `Y_STARTMENU` varchar(10) DEFAULT 'N' COMMENT '시작메뉴 설정 - 옐림',
  `SELFCHANGEYN` char(1) DEFAULT 'N',
  `SELFMOD_NO` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT '',
  `MODIFY_YES_SALE_ACTION` char(1) DEFAULT 'K',
  `MODIFY_NO_SALE_ACTION` char(1) DEFAULT 'D',
  `SOLDOUT_YES_SALE_ACTION` char(1) DEFAULT 'D',
  `SOLDOUT_NO_SALE_ACTION` char(1) DEFAULT 'D',
  `ALLOWLOSSORDER` char(1) DEFAULT 'N' COMMENT '역마진 주문 처리(Y : 역마진 주문 허용, N : 역마진 주문 제외)',
  PRIMARY KEY (`COMPNO`),
  UNIQUE KEY `COMPNO` (`COMPNO`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `systemconf`
--

INSERT INTO `systemconf` VALUES (4,1,7,'ALL',90,7,7,7,'Y','대마,몰카','Y',7,7,'','N','N',100,0,'N','N','N',0,'http://api.sellmall.co.kr:8080','N','Y','N','N','','N','N','',NULL,'','N','N','N','','K','D','D','D','N');

--
-- Table structure for table `table1`
--

CREATE TABLE `table1` (
  `column1` int DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `table1`
--


--
-- Table structure for table `tally`
--

CREATE TABLE `tally` (
  `n` smallint unsigned NOT NULL,
  PRIMARY KEY (`n`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `tally`
--

INSERT INTO `tally` VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),(16),(17),(18),(19),(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),(30),(31),(32),(33),(34),(35),(36),(37),(38),(39),(40),(41),(42),(43),(44),(45),(46),(47),(48),(49),(50),(51),(52),(53),(54),(55),(56),(57),(58),(59),(60),(61),(62),(63),(64),(65),(66),(67),(68),(69),(70),(71),(72),(73),(74),(75),(76),(77),(78),(79),(80),(81),(82),(83),(84),(85),(86),(87),(88),(89),(90),(91),(92),(93),(94),(95),(96),(97),(98),(99),(100),(101),(102),(103),(104),(105),(106),(107),(108),(109),(110),(111),(112),(113),(114),(115),(116),(117),(118),(119),(120),(121),(122),(123),(124),(125),(126),(127),(128),(129),(130),(131),(132),(133),(134),(135),(136),(137),(138),(139),(140),(141),(142),(143),(144),(145),(146),(147),(148),(149),(150),(151),(152),(153),(154),(155),(156),(157),(158),(159),(160),(161),(162),(163),(164),(165),(166),(167),(168),(169),(170),(171),(172),(173),(174),(175),(176),(177),(178),(179),(180),(181),(182),(183),(184),(185),(186),(187),(188),(189),(190),(191),(192),(193),(194),(195),(196),(197),(198),(199),(200),(201),(202),(203),(204),(205),(206),(207),(208),(209),(210),(211),(212),(213),(214),(215),(216),(217),(218),(219),(220),(221),(222),(223),(224),(225),(226),(227),(228),(229),(230),(231),(232),(233),(234),(235),(236),(237),(238),(239),(240),(241),(242),(243),(244),(245),(246),(247),(248),(249),(250),(251),(252),(253),(254),(255),(256),(257),(258),(259),(260),(261),(262),(263),(264),(265),(266),(267),(268),(269),(270),(271),(272),(273),(274),(275),(276),(277),(278),(279),(280),(281),(282),(283),(284),(285),(286),(287),(288),(289),(290),(291),(292),(293),(294),(295),(296),(297),(298),(299),(300),(301),(302),(303),(304),(305),(306),(307),(308),(309),(310),(311),(312),(313),(314),(315),(316),(317),(318),(319),(320),(321),(322),(323),(324),(325),(326),(327),(328),(329),(330),(331),(332),(333),(334),(335),(336),(337),(338),(339),(340),(341),(342),(343),(344),(345),(346),(347),(348),(349),(350),(351),(352),(353),(354),(355),(356),(357),(358),(359),(360),(361),(362),(363),(364),(365),(366),(367),(368),(369),(370),(371),(372),(373),(374),(375),(376),(377),(378),(379),(380),(381),(382),(383),(384),(385),(386),(387),(388),(389),(390),(391),(392),(393),(394),(395),(396),(397),(398),(399),(400),(401),(402),(403),(404),(405),(406),(407),(408),(409),(410),(411),(412),(413),(414),(415),(416),(417),(418),(419),(420),(421),(422),(423),(424),(425),(426),(427),(428),(429),(430),(431),(432),(433),(434),(435),(436),(437),(438),(439),(440),(441),(442),(443),(444),(445),(446),(447),(448),(449),(450),(451),(452),(453),(454),(455),(456),(457),(458),(459),(460),(461),(462),(463),(464),(465),(466),(467),(468),(469),(470),(471),(472),(473),(474),(475),(476),(477),(478),(479),(480),(481),(482),(483),(484),(485),(486),(487),(488),(489),(490),(491),(492),(493),(494),(495),(496),(497),(498),(499),(500),(501),(502),(503),(504),(505),(506),(507),(508),(509),(510),(511),(512),(513),(514),(515),(516),(517),(518),(519),(520),(521),(522),(523),(524),(525),(526),(527),(528),(529),(530),(531),(532),(533),(534),(535),(536),(537),(538),(539),(540),(541),(542),(543),(544),(545),(546),(547),(548),(549),(550),(551),(552),(553),(554),(555),(556),(557),(558),(559),(560),(561),(562),(563),(564),(565),(566),(567),(568),(569),(570),(571),(572),(573),(574),(575),(576),(577),(578),(579),(580),(581),(582),(583),(584),(585),(586),(587),(588),(589),(590),(591),(592),(593),(594),(595),(596),(597),(598),(599),(600),(601),(602),(603),(604),(605),(606),(607),(608),(609),(610),(611),(612),(613),(614),(615),(616),(617),(618),(619),(620),(621),(622),(623),(624),(625),(626),(627),(628),(629),(630),(631),(632),(633),(634),(635),(636),(637),(638),(639),(640),(641),(642),(643),(644),(645),(646),(647),(648),(649),(650),(651),(652),(653),(654),(655),(656),(657),(658),(659),(660),(661),(662),(663),(664),(665),(666),(667),(668),(669),(670),(671),(672),(673),(674),(675),(676),(677),(678),(679),(680),(681),(682),(683),(684),(685),(686),(687),(688),(689),(690),(691),(692),(693),(694),(695),(696),(697),(698),(699),(700),(701),(702),(703),(704),(705),(706),(707),(708),(709),(710),(711),(712),(713),(714),(715),(716),(717),(718),(719),(720),(721),(722),(723),(724),(725),(726),(727),(728),(729),(730),(731),(732),(733),(734),(735),(736),(737),(738),(739),(740),(741),(742),(743),(744),(745),(746),(747),(748),(749),(750),(751),(752),(753),(754),(755),(756),(757),(758),(759),(760),(761),(762),(763),(764),(765),(766),(767),(768),(769),(770),(771),(772),(773),(774),(775),(776),(777),(778),(779),(780),(781),(782),(783),(784),(785),(786),(787),(788),(789),(790),(791),(792),(793),(794),(795),(796),(797),(798),(799),(800),(801),(802),(803),(804),(805),(806),(807),(808),(809),(810),(811),(812),(813),(814),(815),(816),(817),(818),(819),(820),(821),(822),(823),(824),(825),(826),(827),(828),(829),(830),(831),(832),(833),(834),(835),(836),(837),(838),(839),(840),(841),(842),(843),(844),(845),(846),(847),(848),(849),(850),(851),(852),(853),(854),(855),(856),(857),(858),(859),(860),(861),(862),(863),(864),(865),(866),(867),(868),(869),(870),(871),(872),(873),(874),(875),(876),(877),(878),(879),(880),(881),(882),(883),(884),(885),(886),(887),(888),(889),(890),(891),(892),(893),(894),(895),(896),(897),(898),(899),(900),(901),(902),(903),(904),(905),(906),(907),(908),(909),(910),(911),(912),(913),(914),(915),(916),(917),(918),(919),(920),(921),(922),(923),(924),(925),(926),(927),(928),(929),(930),(931),(932),(933),(934),(935),(936),(937),(938),(939),(940),(941),(942),(943),(944),(945),(946),(947),(948),(949),(950),(951),(952),(953),(954),(955),(956),(957),(958),(959),(960),(961),(962),(963),(964),(965),(966),(967),(968),(969),(970),(971),(972),(973),(974),(975),(976),(977),(978),(979),(980),(981),(982),(983),(984),(985),(986),(987),(988),(989),(990),(991),(992),(993),(994),(995),(996),(997),(998),(999),(1000);

--
-- Table structure for table `temp01`
--

CREATE TABLE `temp01` (
  `PRODCD` varchar(50) DEFAULT NULL,
  `SHOPCD` varchar(50) DEFAULT NULL,
  `SHOPPRODCD` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `temp01`
--


--
-- Table structure for table `test01`
--

CREATE TABLE `test01` (
  `aa` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `test01`
--


--
-- Table structure for table `user_excel_form_detail`
--

CREATE TABLE `user_excel_form_detail` (
  `DETAIL_SEQ` int NOT NULL AUTO_INCREMENT,
  `MASTER_SEQ` int NOT NULL,
  `COL_INDEX` varchar(5) NOT NULL,
  `COL_NAME` varchar(200) DEFAULT NULL,
  `COL_VALUE` varchar(200) DEFAULT NULL,
  `COL_MEMO` varchar(500) DEFAULT NULL,
  `CREATE_DT` datetime DEFAULT CURRENT_TIMESTAMP,
  `MODIFY_DT` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`DETAIL_SEQ`),
  KEY `FK_EXCEL_FORM_MASTER` (`MASTER_SEQ`),
  CONSTRAINT `FK_EXCEL_FORM_MASTER` FOREIGN KEY (`MASTER_SEQ`) REFERENCES `user_excel_form_master` (`SEQ`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2040 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `user_excel_form_detail`
--


--
-- Table structure for table `user_excel_form_master`
--

CREATE TABLE `user_excel_form_master` (
  `SEQ` int NOT NULL AUTO_INCREMENT,
  `NAME` varchar(100) NOT NULL,
  `USE_YN` char(1) DEFAULT 'Y',
  `TOP_INSERT_ROW` int DEFAULT '0',
  `CREATE_DT` datetime DEFAULT CURRENT_TIMESTAMP,
  `CREATE_USER` varchar(100) DEFAULT NULL,
  `MODIFY_DT` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `MODIFY_USER` varchar(100) DEFAULT NULL,
  `GUBUN1` varchar(100) DEFAULT NULL,
  `GUBUN2` varchar(100) DEFAULT NULL,
  `GUBUN3` varchar(100) DEFAULT NULL,
  `GUBUN4` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`SEQ`)
) ENGINE=InnoDB AUTO_INCREMENT=54 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `user_excel_form_master`
--


--
-- Table structure for table `user_joblog`
--

CREATE TABLE `user_joblog` (
  `SEQ` int NOT NULL AUTO_INCREMENT,
  `USERID` varchar(120) NOT NULL,
  `JOBDATE` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  `JOBTYPE` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  `JOBMAIN` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  `JOBSUB` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  `JOBLOG_COUNT` int DEFAULT NULL,
  `COST` double DEFAULT NULL,
  `COST2` double DEFAULT NULL,
  PRIMARY KEY (`SEQ`),
  UNIQUE KEY `USER_JOBLOG_USERID_IDX` (`USERID`,`JOBDATE`,`JOBTYPE`,`JOBMAIN`,`JOBSUB`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=397 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `user_joblog`
--

DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `user_joblog_insert` AFTER INSERT ON `user_joblog` FOR EACH ROW begin
    DECLARE v_bill_type VARCHAR(10);

    -- 청구 여부 확인
    SELECT BILL_TYPE
    INTO v_bill_type
    FROM creditmst
    WHERE JOBTYPE = NEW.JOBTYPE
    LIMIT 1;
   
    IF v_bill_type IS NULL THEN
	    SET v_bill_type = '제외';
	END IF;

    -- 청구만 처리
    IF v_bill_type = '청구' THEN
	    INSERT INTO credit_transactions (
	        user_id,
	        credit_type,
	        amount,
	        balance_after,
	        description,
	        reference_id,
	        reference_type,
	        meta_data,
	        created_at
	    )
	    VALUES (
	        NEW.USERID,
	        'USAGE',
	        -IFNULL(NEW.JOBLOG_COUNT,0),
	        0,
	        CONCAT('JOBLOG usage (', NEW.JOBDATE, ')'),
	        NEW.JOBDATE,
	        'joblog',
	        JSON_OBJECT('jobdate', NEW.JOBDATE),
	        NOW()
	    )
	    ON DUPLICATE KEY UPDATE
	        amount = amount - IFNULL(NEW.JOBLOG_COUNT,0),
	        created_at = NOW();
	       
    END IF;
   
end */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `user_joblog_after_update` AFTER UPDATE ON `user_joblog` FOR EACH ROW BEGIN
    DECLARE v_delta INT;
    DECLARE v_bill_type VARCHAR(10);   

    -- 변화량 계산
    SET v_delta = IFNULL(NEW.JOBLOG_COUNT,0) - IFNULL(OLD.JOBLOG_COUNT,0);
   
    -- 청구 여부 확인
    SELECT BILL_TYPE
    INTO v_bill_type
    FROM creditmst
    WHERE JOBTYPE = NEW.JOBTYPE
    LIMIT 1;
   
    IF v_bill_type IS NULL THEN
	    SET v_bill_type = '제외';
	END IF;

    -- 청구만 처리
    IF v_bill_type = '청구' AND v_delta <> 0 THEN 
	    INSERT INTO credit_transactions (
	        user_id,
	        credit_type,
	        amount,
	        balance_after,
	        description,
	        reference_id,
	        reference_type,
	        meta_data,
	        created_at
	    )
	    VALUES (
	        NEW.USERID,
	        'USAGE',
	        -v_delta,
	        0,
	        CONCAT('JOBLOG usage (', NEW.JOBDATE, ')'),
	        NEW.JOBDATE,
	        'joblog',
	        JSON_OBJECT('jobdate', NEW.JOBDATE),
	        NOW()
	    )
	    ON DUPLICATE KEY UPDATE
	        amount = amount - v_delta,
	        created_at = NOW();

    END IF;
   
END */;;
DELIMITER ;

--
-- Table structure for table `userinf`
--

CREATE TABLE `userinf` (
  `COMPNO` int DEFAULT NULL,
  `USERID` varchar(20) NOT NULL,
  `USERNAM` varchar(20) DEFAULT NULL,
  `USERPWD` varchar(20) DEFAULT NULL,
  `EMAIL` varchar(30) DEFAULT NULL,
  `PROGCD` varchar(100) DEFAULT NULL,
  `USEYN` char(1) DEFAULT NULL,
  `LTYPE` char(1) DEFAULT NULL,
  `STARTUSE` varchar(50) DEFAULT NULL,
  `ENDUSE` varchar(50) DEFAULT NULL,
  `BRANDCD` int DEFAULT NULL,
  KEY `idx_userinf_startuse` (`STARTUSE` DESC)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `userinf`
--

INSERT INTO `userinf` VALUES (4,'hosikan','','1111','',NULL,'N','2',NULL,NULL,-1),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-04-10 13:44:37',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-04-24 09:14:32',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-04-24 09:14:58',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-04-24 09:15:22',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-04-25 15:50:57',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-04-25 15:51:27',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-04-25 15:52:17',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-04-25 19:05:06',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-04-29 07:28:36',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-04-30 23:09:36',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-05-07 11:24:11',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-05-19 09:23:59',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-06-09 09:51:54',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-06-23 08:27:00',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-06-23 08:27:27',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-06-27 17:11:55',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-06-27 17:12:43',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-06-27 17:15:16',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-06-27 17:15:58',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-06-27 17:18:35',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-06-30 15:20:23',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-06-30 15:21:01',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-06-30 15:21:35',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-06-30 16:04:40',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-06-30 16:05:06',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-06-30 19:16:42',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-07-03 14:55:07',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-07-03 14:55:33',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-07-03 14:56:36',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-07-03 14:56:54',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-07-03 14:59:43',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-07-03 15:02:25',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-07-03 15:03:49',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-07-09 14:45:13',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-08-22 07:41:10',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-08-22 07:41:53',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-08-22 09:47:41',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-08-22 11:17:52',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-08-29 13:45:23',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-08-29 13:46:07',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-09-12 07:51:40',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-09-12 07:52:23',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2025-09-12 07:53:57',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2026-01-14 10:34:28',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2026-01-14 10:35:53',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2026-02-09 07:25:34',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2026-02-11 16:18:34',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2026-02-11 17:17:42',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2026-02-11 17:20:43',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2026-02-11 17:22:59',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2026-02-11 17:24:16',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2026-02-20 15:56:30',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2026-02-20 15:56:59',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2026-04-06 11:55:06',NULL,NULL),(NULL,'hosikan',NULL,NULL,NULL,NULL,NULL,NULL,'2026-04-06 11:55:35',NULL,NULL);
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `userinf_after_update` AFTER INSERT ON `userinf` FOR EACH ROW BEGIN
    DECLARE first_run_date DATE;
    DECLARE today DATE;
    DECLARE user_exists INT;
    SET today = CURDATE();
    SELECT MIN(DATE(STARTUSE)) INTO first_run_date
      FROM userinf
     WHERE USERID = NEW.USERID
       AND YEAR(STARTUSE) = YEAR(today)
       AND MONTH(STARTUSE) = MONTH(today);
    IF first_run_date IS NOT NULL AND first_run_date = today THEN
        UPDATE cloudinaryapiinfo SET apikey = '0' WHERE compno = 0;
    END IF;
END */;;
DELIMITER ;

--
-- Temporary view structure for view `v_products`
--

/*!50001 DROP VIEW IF EXISTS `v_products`*/;
/*!50001 CREATE VIEW `v_products` AS SELECT 
 1 AS `compno`,
 1 AS `brandcd`,
 1 AS `prodcd`,
 1 AS `prodnm`,
 1 AS `specdes`,
 1 AS `ecountcd`,
 1 AS `neccd1`,
 1 AS `neccd2`,
 1 AS `neccd3`,
 1 AS `expbundcd`,
 1 AS `expcd`,
 1 AS `expkindnm`,
 1 AS `expfile`,
 1 AS `prodcdm`,
 1 AS `price`,
 1 AS `tagprice`,
 1 AS `remark`,
 1 AS `flagset`,
 1 AS `sabcd`,
 1 AS `expinvqty`,
 1 AS `expoutnm`,
 1 AS `cusprice`,
 1 AS `optprodcd`,
 1 AS `expinner`,
 1 AS `expcostnm`,
 1 AS `delyn`,
 1 AS `flagpart`*/;

--
-- Table structure for table `warehouse`
--

CREATE TABLE `warehouse` (
  `COMPNO` int NOT NULL,
  `BRANDCD` int NOT NULL,
  `WARECD` int NOT NULL,
  `WARENM` varchar(100) DEFAULT NULL,
  `DSPSEQ` int DEFAULT NULL,
  PRIMARY KEY (`COMPNO`,`BRANDCD`,`WARECD`),
  UNIQUE KEY `COMPNO_BRANDCD_WARECD` (`COMPNO`,`BRANDCD`,`WARECD`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `warehouse`
--

INSERT INTO `warehouse` VALUES (4,1,1,'본사창고',1);

--
-- Table structure for table `workmgrdetail`
--

CREATE TABLE `workmgrdetail` (
  `WORKGRP` varchar(50) NOT NULL DEFAULT '0' COMMENT '작업그룹아이디',
  `SEQ` int NOT NULL DEFAULT '0' COMMENT '순서',
  `PRODSEQ` varchar(50) DEFAULT NULL COMMENT '품번코드',
  `STATUS` varchar(50) DEFAULT NULL COMMENT '상태 : 성공 1 , 실패 0',
  `MESSAGE` text COMMENT '메시지',
  PRIMARY KEY (`WORKGRP`,`SEQ`),
  UNIQUE KEY `WORKGRP_SEQ` (`WORKGRP`,`SEQ`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='''testdb.v_products'' is not BASE TABLE';

--
-- Dumping data for table `workmgrdetail`
--

DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `workmgrdetail_after_insert` AFTER INSERT ON `workmgrdetail` FOR EACH ROW BEGIN 
    IF NEW.status = '-1'
       AND NEW.message NOT LIKE '%out of total%'
       AND NEW.message NOT LIKE '%상품수%'
       AND NEW.message NOT LIKE '%최대 개수%'
       AND NEW.message NOT LIKE '%상품 수%'
	   AND NEW.message NOT LIKE '%판매 중인 상품은 최대%'
	   AND NEW.message NOT LIKE '%상품 등록이 1분 이상 소요되어%'
    THEN
        UPDATE shopprodinfo
           SET SHOPSENDSTATUS = 9100
         WHERE compno = 4
           AND COMPAYNY_GOODS_CD = NEW.prodseq;
    END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `trg_workmgrdetail_after_insert_joblog` AFTER INSERT ON `workmgrdetail` FOR EACH ROW BEGIN
  DECLARE v_shopcd VARCHAR(50);
  DECLARE v_shopseq INT;
  DECLARE v_shopuserid VARCHAR(50);
  DECLARE v_nickname VARCHAR(50);
  DECLARE v_workcd VARCHAR(50);
  DECLARE v_jobtype VARCHAR(50);
  DECLARE v_jobmain VARCHAR(50);
  DECLARE v_jobsub VARCHAR(50);
  DECLARE v_logmessage TEXT;
  DECLARE v_shopprodno VARCHAR(50);
  DECLARE v_jobresult VARCHAR(10);

    SELECT workmgrmaster.SHOPCD, workmgrmaster.SHOPSEQ, workmgrmaster.WORKCD, workmgrmaster.SHOP_USER_ID
      INTO v_shopcd, v_shopseq, v_workcd, v_shopuserid
      FROM workmgrmaster
     WHERE workmgrmaster.WORKGRP = NEW.WORKGRP
     LIMIT 1;
    
    SELECT shopdtl.NICKNM1
      INTO v_nickname
      FROM shopdtl
     WHERE shopdtl.SHOPCD = v_shopcd
       AND shopdtl.SHOPSEQ = v_shopseq
     LIMIT 1;
    
	 IF v_workcd = '100' then
	 	SET v_jobtype = 'PRD_REG';
	 	SET v_jobmain = 'PRD';
	 	SET v_jobsub = 'REG';
	 	SET v_logmessage = NEW.`MESSAGE`;
		IF NEW.STATUS = 'W06' THEN
		    IF NEW.`MESSAGE` LIKE '%취소%' THEN
		        SET v_jobresult = '실패';
		    ELSE
		        SET v_jobresult = '성공';
		    END IF;
		ELSE
		    SET v_jobresult = '실패';
		END IF;
    ELSEIF v_workcd = '200' then
	 	SET v_jobtype = 'PRD_EDT';
 	 	SET v_jobmain = 'PRD';
 		SET v_jobsub = 'EDT';
 		SET v_logmessage = NEW.`MESSAGE`;
		IF NEW.STATUS = 'W06' THEN
		    IF NEW.`MESSAGE` LIKE '%취소%' THEN
		        SET v_jobresult = '실패';
		    ELSE
		        SET v_jobresult = '성공';
		    END IF;
		ELSE
		    SET v_jobresult = '실패';
		END IF;
    ELSEIF v_workcd = '700' then
	 	SET v_jobtype = 'PRD_DIS';
 	 	SET v_jobmain = 'PRD';
 		SET v_jobsub = 'DIS';
 		SET v_logmessage = NEW.`MESSAGE`;
		IF NEW.STATUS = 'W06' THEN
		    IF NEW.`MESSAGE` LIKE '%취소%' THEN
		        SET v_jobresult = '실패';
		    ELSE
		        SET v_jobresult = '성공';
		    END IF;
		ELSE
		    SET v_jobresult = '실패';
		END IF;
	ELSEIF v_workcd = '800' then
	 	SET v_jobtype = 'PRD_RSL';
 	 	SET v_jobmain = 'PRD';
 		SET v_jobsub = 'RSL';
 		SET v_logmessage = NEW.`MESSAGE`;
		IF NEW.STATUS = 'W06' THEN
		    IF NEW.`MESSAGE` LIKE '%취소%' THEN
		        SET v_jobresult = '실패';
		    ELSE
		        SET v_jobresult = '성공';
		    END IF;
		ELSE
		    SET v_jobresult = '실패';
		END IF;
	ELSEIF v_workcd IN ('600', '500') then
	 	SET v_jobtype = 'PRD_DEL';
  	 	SET v_jobmain = 'PRD';
 		SET v_jobsub = 'DEL';
		IF NEW.STATUS = 'W06' THEN
		    IF NEW.`MESSAGE` LIKE '%취소%' THEN
		        SET v_jobresult = '실패';
		        SET v_logmessage = NEW.`MESSAGE`;
		    ELSE
		        SET v_jobresult = '성공';
		        SET v_logmessage = '[작업관리] 상품이 삭제되었습니다.';
		    END IF;
		ELSE
		    SET v_jobresult = '실패';
		   	SET v_logmessage = NEW.`MESSAGE`;
		END IF;
    END IF;
   
   IF NEW.STATUS = 'W06' then
	   	SET v_shopprodno = TRIM(BOTH ']' 
	                    FROM SUBSTRING_INDEX(
	                           SUBSTRING_INDEX(new.MESSAGE, '[', -1), 
	                           ']', 
	                           1
	                         ));
   ELSE
   		SET v_shopprodno = '';
   END IF;	
  
	INSERT INTO joblog (
		JOBDATE, JOBTYPE, JOBMAIN, JOBSUB, JOBDETAIL, PRODCD, SHOPPRODNO, SHOPCD, 
		SHOPUSERID, NICKNAME, SHOPSEQ, ORDID, PRODUCTNAME, OPTIONNAME, SALECNT, SALECOST, 
		RECEIVE_NAME, JOBRESULT, LOGMESSAGE
	)
	VALUES (
		NOW(), v_jobtype, v_jobmain, v_jobsub, "", NEW.prodseq, v_shopprodno, v_shopcd, 
		v_shopuserid, v_nickname, v_shopseq, "", "", "", 0, 0,
		"", v_jobresult, v_logmessage
	);

END */;;
DELIMITER ;

--
-- Table structure for table `workmgrlog`
--

CREATE TABLE `workmgrlog` (
  `WORKGRP` varchar(50) NOT NULL COMMENT '작업관리 ID',
  `SHOPCD` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '쇼핑몰코드',
  `SHOPNM` varchar(20) DEFAULT NULL COMMENT '쇼핑몰이름',
  `SHOPSEQ` int DEFAULT NULL COMMENT '쇼핑몰 순번',
  `SHOPPINGID` varchar(50) DEFAULT NULL COMMENT '로그인 ID',
  `NICKNM1` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '닉네임',
  `SEQ` int DEFAULT NULL COMMENT 'WORKGRP에 있는 순서',
  `PRODSEQ` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '자체상품코드',
  `STATUS` varchar(100) DEFAULT NULL COMMENT '판매상태',
  `MESSAGE` varchar(150) DEFAULT NULL COMMENT '작업 관련 메세지',
  `ADDITIONALSEQ` int DEFAULT NULL COMMENT '부가정보 순서',
  `ADDITIONALTITLE` varchar(100) DEFAULT NULL COMMENT '부가정보 제목',
  `IMGONEONONE` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '이미지 리사이징 사용여부',
  `DSCAMTPERCENT` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '할인율',
  `MARGINDC` float DEFAULT NULL COMMENT '마진율',
  `COMMDC` float DEFAULT NULL COMMENT '수수료율',
  `CHANGESIZEX` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '대표사진사이즈변경 X',
  `CHANGESIZEY` varchar(50) DEFAULT NULL COMMENT '대표사진사이즈변경 Y',
  `CHANGESIZEW` varchar(50) DEFAULT NULL COMMENT '대표사진사이즈변경 W',
  `CHANGESIZEH` varchar(50) DEFAULT NULL COMMENT '대표사진사이즈변경 H',
  `IMG_ANGLE` double DEFAULT NULL COMMENT '이미지 회전 각도',
  `IMG_SCALE_PERCENT` double DEFAULT NULL COMMENT '이미지 확대율',
  `MIRRORIMGYN` char(1) DEFAULT NULL COMMENT '반전사용여부',
  `GOODS_KEYWORD` varchar(30) DEFAULT NULL COMMENT '도매몰',
  `CLASS_CD3` varchar(50) DEFAULT NULL COMMENT '소분류코드',
  `FULL_NAME` text COMMENT '카테고리 풀이름',
  `INSERTDT` varchar(50) DEFAULT NULL COMMENT '입력/등록 일자',
  `GOODS_COST` int DEFAULT NULL COMMENT '원가',
  `DELV_COST` int DEFAULT NULL COMMENT '배송비',
  `GOODS_SEARCH` text COMMENT '키워드',
  `SALE_CNT` int DEFAULT NULL COMMENT '주문수량',
  KEY `SHOPCD_SHOPPINGID_PRODSEQ` (`SHOPCD`,`SHOPPINGID`,`PRODSEQ`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='상품등록하면서 쌓이는 기록 [ 환경설정에 체크 시 ]';

--
-- Dumping data for table `workmgrlog`
--


--
-- Table structure for table `workmgrmaster`
--

CREATE TABLE `workmgrmaster` (
  `WORKGRP` varchar(50) NOT NULL DEFAULT '0' COMMENT '작업그룹아이디',
  `SHOPCD` varchar(10) DEFAULT NULL COMMENT '쇼핑몰코드',
  `SHOPSEQ` int DEFAULT NULL,
  `COMPNO` int DEFAULT NULL COMMENT '회사코드',
  `WORKCD` varchar(50) DEFAULT NULL COMMENT '작업코드',
  `WORK_STATUS` varchar(50) DEFAULT NULL COMMENT '상태 ',
  `SHOP_USER_ID` varchar(50) DEFAULT NULL COMMENT '쇼핑몰 아이디',
  `WORK_USERID` varchar(50) DEFAULT NULL COMMENT '작업자',
  `WORK_STARTDATE` varchar(50) DEFAULT NULL COMMENT '작업시작시간',
  `WORK_ENDDATE` varchar(50) DEFAULT NULL COMMENT '작업종료시간',
  `WORK_DLAPSED` varchar(50) DEFAULT NULL COMMENT '경과시간',
  `PROGRESS_RATE` int DEFAULT NULL COMMENT '진행률',
  PRIMARY KEY (`WORKGRP`),
  UNIQUE KEY `WORKGRP` (`WORKGRP`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='''testdb.v_products'' is not BASE TABLE';

--
-- Dumping data for table `workmgrmaster`
--


--
-- Table structure for table `workmngr`
--

CREATE TABLE `workmngr` (
  `WORKGRP` varchar(50) NOT NULL DEFAULT '0',
  `WORKSEQ` int NOT NULL COMMENT '작업관리일련번호',
  `SHOPCD` varchar(10) DEFAULT NULL COMMENT '쇼핑몰코드',
  `COMPNO` int DEFAULT NULL COMMENT '회사코드',
  `WORKCD` varchar(50) DEFAULT NULL COMMENT '작업코드',
  `WORKDETCD` varchar(50) DEFAULT NULL COMMENT '작업상세코드',
  `INSERTID` varchar(50) DEFAULT NULL,
  `WORKDATEFROM` varchar(50) DEFAULT NULL COMMENT '작업시작시간',
  `WORKDATETO` varchar(50) DEFAULT NULL COMMENT '작업종료시간',
  `WORKDLAPSED` varchar(50) DEFAULT NULL COMMENT '경과시간',
  `WORKSTATS` varchar(50) DEFAULT NULL COMMENT '상태',
  `WORKCURRRATE` varchar(50) DEFAULT NULL COMMENT '진행률',
  `WORKMESSAGE` varchar(500) DEFAULT NULL COMMENT '메세지',
  `WORKLOG` varchar(500) DEFAULT NULL COMMENT '상세로고',
  `PRODSEQ` int DEFAULT NULL COMMENT '품번코드',
  `SHOPSEQ` int DEFAULT NULL COMMENT 'SHOPDTL일련번호',
  `USER_ID` varchar(50) DEFAULT NULL,
  `ADDRSEQ` int DEFAULT NULL COMMENT '부가정보코드',
  `SHOPCATNO` int DEFAULT NULL COMMENT '카테고리코드',
  PRIMARY KEY (`WORKGRP`,`WORKSEQ`),
  UNIQUE KEY `WORKGRP_WORKSEQ` (`WORKGRP`,`WORKSEQ`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `workmngr`
--


--
-- Dumping events for database 'mlink'
--

--
-- Dumping routines for database 'mlink'
--
/*!50003 DROP FUNCTION IF EXISTS `GET_ALL_ESCODE` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `GET_ALL_ESCODE`(

	`V_SHOPCD` VARCHAR(50),

	`V_CODE` VARCHAR(50),

	`V_SHOPCATE` JSON

) RETURNS text CHARSET utf8mb4
    DETERMINISTIC
BEGIN

	DECLARE RETURN_VALUE TEXT;

	DECLARE v_idx2       INT;

	

	BEGIN

		SELECT GET_CATEGORY_JSON_IDX(V_SHOPCATE,V_SHOPCD) INTO v_idx2;		   

		SELECT concat(ID,'|', SHOPCATE) into RETURN_VALUE 

		 FROM CATEGORY

			WHERE 

		 JSON_EXTRACT(SHOPCATE, CONCAT('$[',v_idx2,'].cid')) = V_CODE limit 1;

			   

	END;

 	SET RETURN_VALUE = IFNULL(RETURN_VALUE, '');

   RETURN (RETURN_VALUE);

END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `GET_CATEGORY_JSON_IDX` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `GET_CATEGORY_JSON_IDX`(

	`V_SHOPCATE` JSON,

	`V_SHOPCD` VARCHAR(50)

) RETURNS varchar(50) CHARSET utf8mb4
    DETERMINISTIC
BEGIN

	DECLARE RETURN_VALUE INT;

	BEGIN

		SELECT idx INTO RETURN_VALUE

		  FROM (SELECT  0 AS idx UNION

				  SELECT  1 AS idx UNION

				  SELECT  2 AS idx UNION

				  SELECT  3 AS idx UNION

				  SELECT  4 AS idx UNION

				  SELECT  5 AS idx UNION

				  SELECT  6 AS idx UNION

				  SELECT  7 AS idx UNION

				  SELECT  8 AS idx UNION

				  SELECT  9 AS idx UNION

				  SELECT  10 AS idx UNION

				  SELECT  11 AS idx UNION

				  SELECT  12 AS idx UNION

				  SELECT  13 AS idx UNION

				  SELECT  14 AS idx UNION

				  SELECT  15 AS idx UNION

				  SELECT  16 AS idx UNION

				  SELECT  17 AS idx UNION

				  SELECT  18 AS idx UNION

				  SELECT  19 AS idx UNION

				  SELECT  20 AS idx UNION

				  SELECT  21 AS idx UNION

				  SELECT  22 AS idx UNION

				  SELECT  23

				  ) AS indexes

		 WHERE JSON_EXTRACT(V_SHOPCATE, CONCAT('$[', idx, '].shopcd')) = V_SHOPCD;

	END;

	SET RETURN_VALUE = IFNULL(RETURN_VALUE, 9999);

   RETURN (RETURN_VALUE);

END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `GET_COUPANG_ESCODE` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `GET_COUPANG_ESCODE`(

	`V_CODE` VARCHAR(50)



) RETURNS text CHARSET utf8mb4
    DETERMINISTIC
BEGIN

	DECLARE RETURN_VALUE TEXT;

	

	BEGIN

		   

	SELECT concat(ID,'|', SHOPCATE) into RETURN_VALUE 

	 FROM CATEGORY

		WHERE 

	 JSON_EXTRACT(SHOPCATE, '$[0].cid') = V_CODE limit 1;

		   

	END;

 	SET RETURN_VALUE = IFNULL(RETURN_VALUE, '');

   RETURN (RETURN_VALUE);

END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `GET_NAVER_ESCODE` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `GET_NAVER_ESCODE`(
	`V_CODE` VARCHAR(50)
) RETURNS text CHARSET utf8mb4
    DETERMINISTIC
BEGIN
	DECLARE RETURN_VALUE TEXT;
	
	BEGIN
		   
	SELECT concat(ID,'|', SHOPCATE) into RETURN_VALUE 
	 FROM CATEGORY
		WHERE 
	 JSON_EXTRACT(SHOPCATE, '$[5].cid') = V_CODE  AND LEVEL > 2 limit 1;
		   
	END;
 	SET RETURN_VALUE = IFNULL(RETURN_VALUE, '');
   RETURN (RETURN_VALUE);
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `GET_PRODCD` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `GET_PRODCD`(

	`p_seq_name` VARCHAR(4)

) RETURNS varchar(12) CHARSET utf8mb4
    DETERMINISTIC
BEGIN

	DECLARE RTN_VAL VARCHAR(12);

	

    INSERT INTO productcd_sequence (seq_name, seq_no)

         values (p_seq_name, LAST_INSERT_ID(1))

    ON DUPLICATE KEY UPDATE seq_no=LAST_INSERT_ID(seq_no+1);

	

    set @ret = row_count();

	

    if @ret = 0 then 

        set RTN_VAL = '0'; 

    else

        SET RTN_VAL = (SELECT CONCAT(p_seq_name,  LPAD(LAST_INSERT_ID(),8,'0'))); 

    end if;

	

	RETURN RTN_VAL;

END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `GET_SHOPALLCODE_ESCODE` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `GET_SHOPALLCODE_ESCODE`(

	`V_CODE` JSON



) RETURNS varchar(50) CHARSET utf8mb4
    DETERMINISTIC
BEGIN

	DECLARE _shopid  varchar(50);

	DECLARE _shopcd  varchar(50);

	DECLARE RETURN_VALUE varchar(50);

	DECLARE rownum  int;



	DECLARE c1 CURSOR FOR SELECT ifnull(JSON_EXTRACT(V_CODE, CONCAT('$[', n - 1, '].cid')),'') as shopid, 

										  ifnull(JSON_EXTRACT(V_CODE, CONCAT('$[', n - 1, '].cid')),'') as shopcd

									FROM tally

								  WHERE n <= JSON_LENGTH(V_CODE); 



	Block0: BEGIN	

 		SET RETURN_VALUE = '';

 		SET rownum = 0;

	END Block0;						   

	

	Block1: BEGIN

		

		DECLARE done INT DEFAULT 0;

		DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;



		open c1;

		REPEAT

			FETCH NEXT FROM c1 INTO _shopid,_shopcd;

			IF not done THEN			

				if _shopid = 'null' then set _shopid=''; end if;

				if _shopcd = 'null' then set _shopcd=''; end if;

				SELECT ID into RETURN_VALUE 

	 			  FROM CATEGORY

				 WHERE JSON_EXTRACT(SHOPCATE, CONCAT('$[', rownum, '].cid')) = replace(_shopid,'"','')  limit 1;

				

				SET RETURN_VALUE = IFNULL(RETURN_VALUE, '');

				IF RETURN_VALUE <> '' then 

					SET done = 1;

				END IF;	

				SET rownum = rownum + 1;

				

			END IF;

		UNTIL done END REPEAT;

		close c1;			 

	END Block1;

	

	if RETURN_VALUE='' then

		set RETURN_VALUE = '999999999';

	END if;

	

	RETURN (RETURN_VALUE);

	

END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `YWM_FUNC_BOSSPRODCD` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `YWM_FUNC_BOSSPRODCD`(

	`V_COMPNO` INT,

	`V_BRANDCD` INT,

	`V_PRODCD` VARCHAR(20)

) RETURNS varchar(20) CHARSET utf8mb4
    DETERMINISTIC
BEGIN



	DECLARE V_PRODCDM VARCHAR(20) DEFAULT V_PRODCD;

	

	BEGIN

		   

		SELECT IFNULL(PRODCD,V_PRODCD) INTO V_PRODCDM

		  FROM OPTPRODMST

		 WHERE COMPNO    = V_COMPNO 

		 	AND BRANDCD   = V_BRANDCD

		   AND OPTPRODCD = V_PRODCD;

		   

	END;

 

   RETURN (V_PRODCDM);

 

END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `YWM_FUNC_PRODWAREQTY` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `YWM_FUNC_PRODWAREQTY`(

	`V_COMPNO` INT,

	`V_BASEDATE` VARCHAR(8),

	`V_PRODCD` VARCHAR(20)













) RETURNS int
    DETERMINISTIC
    COMMENT '특정 상품 재고수량 (주문 재고 체크시 사용)'
BEGIN



	DECLARE v_inwareqty int DEFAULT 0;

	

	BEGIN

		

		
		CALL YWM_WAREPRODLIST_UNIT(V_COMPNO, V_PRODCD);

		
		
		
		
		
		SELECT MIN(INWAREQTY) INTO v_inwareqty 

		  FROM SUM_PRODWAREQTY 

		 WHERE COMPNO=V_COMPNO 

		   AND PRODCD IN (SELECT PRODCD FROM TMP_WAREPRODLIST);

		

	END;

 

   RETURN (IFNULL(v_inwareqty,0));

 

END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `YWM_FUNC_SHOPCOMMIS` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `YWM_FUNC_SHOPCOMMIS`(

	`v_compno` INT,

	`v_shopcd` VARCHAR(50),

	`v_shopprodno` VARCHAR(50)













) RETURNS float
    DETERMINISTIC
BEGIN

	

	
	
	
	DECLARE v_shopcommis float DEFAULT null;

	

	begin 

	

		SELECT shopcommis into v_shopcommis 

		  FROM SHOPCATINF WHERE shopcatno =

				  (SELECT (case when ifnull(class_cd4,'') = '' 

						      	then case when ifnull(class_cd3,'') = '' 

											 then case when ifnull(class_cd2,'')='' 

										       		  then (SELECT max(shopcatno) FROM CATEGLGMAP WHERE compno=v_compno AND CODE=class_cd1 AND shopcd=shopcd)

								     			 		  ELSE (SELECT max(shopcatno) FROM CATEGMDMAP WHERE compno=v_compno AND CODE=concat(class_cd1,class_cd2) AND shopcd=shopcd) END 

											 ELSE (SELECT max(shopcatno) FROM CATEGSMMAP WHERE compno=v_compno AND CODE=concat(class_cd1,class_cd2,class_cd3) AND shopcd=shopcd) END 

									ELSE (SELECT max(shopcatno) FROM CATEGDTLMAP WHERE compno=v_compno AND CODE=concat(class_cd1,class_cd2,class_cd3,class_cd4) AND shopcd=shopcd) END ) 

				    FROM SHOPPRODIN 

					WHERE shopprodno=v_shopprodno)

		   and compno=v_compno

		   AND shopcd=v_shopcd;

		   

		 

	end; 



	return ( ifnull(v_shopcommis,0.13) );

	

END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `YWM_FUNC_SHOPCOMMIS_PRODMST` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `YWM_FUNC_SHOPCOMMIS_PRODMST`(

	`v_compno` INT,

	`v_shopcd` VARCHAR(50),

	`v_prodcd` VARCHAR(50)

) RETURNS float
    DETERMINISTIC
BEGIN

	

	
	
	
	DECLARE v_shopcommis float DEFAULT null;

	

	begin 

	

		SELECT shopcommis into v_shopcommis 

		  FROM SHOPCATINF WHERE shopcatno =

				  (SELECT (case when ifnull(CATEGDETCD,'') = '' 

						      	 then case when ifnull(CATEGSMLCD,'') = '' 

											     then case when ifnull(CATEGMIDCD,'')='' 

										       		      then CATEGLAGCD

								     			 		      ELSE CATEGMIDCD END 

											     ELSE CATEGSMLCD END 

									 ELSE CATEGDETCD END ) 

				     FROM PRODMST 

					 WHERE prodcd=v_prodcd)

		   and compno=v_compno

		   AND shopcd=v_shopcd;

		 

	end; 



	return ( ifnull(v_shopcommis,0.13) );

	

END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `YWM_FUNC_TOTAL_WEEKDAYS` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `YWM_FUNC_TOTAL_WEEKDAYS`(

	`date1` DATE,

	`date2` DATE



) RETURNS int
    DETERMINISTIC
    COMMENT '워킹데이 일수계산'
RETURN ABS(DATEDIFF(date2, date1)) + 1 - ABS(DATEDIFF(ADDDATE(date2, INTERVAL 1 - DAYOFWEEK(date2) DAY), 

       ADDDATE(date1, INTERVAL 1 - DAYOFWEEK(date1) DAY)))/7 * 2 

    - (DAYOFWEEK(IF(date1 < date2, date1, date2)) = 1) 

    - (DAYOFWEEK(IF(date1 > date2, date1, date2)) = 7) ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `YWM_FUNC_WORKING_DAY` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `YWM_FUNC_WORKING_DAY`(

	`vfromDate` VARCHAR(8),

	`vday` INT







) RETURNS varchar(8) CHARSET utf8mb4
    DETERMINISTIC
    COMMENT '오늘로 부터 몇일(3일) 이후 날자 반환'
BEGIN



	DECLARE toDate date;

	DECLARE toWeek int DEFAULT 0;

	DECLARE nCnt int DEFAULT 0;

	

	BEGIN

		

		select DATE_FORMAT(vfromDate,'%Y-%m-%d') into toDate from dual;

		

		loop_date:LOOP



			IF (nCnt >= vday) THEN

				LEAVE loop_date; 

		   END IF;

			

			SET nCnt = nCnt + 1;			

			SELECT DATE_ADD(toDate, INTERVAL 1 DAY) into toDate from dual;

			SELECT DAYOFWEEK(toDate) into toWeek from dual;

			

			if toWeek = 1 or toWeek = 7 then

				SET nCnt = nCnt - 1; 

			end if;

			

		END LOOP;

		

	END;

 

   RETURN ( DATE_FORMAT(toDate,'%Y%m%d') );

 

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `DELETE_EXCELMASTER` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `DELETE_EXCELMASTER`(

	IN `inSeq` INT

)
BEGIN

    DECLARE exit handler for sqlexception

    BEGIN

        -- Error occurred, rollback changes or perform necessary actions

        ROLLBACK;

    END;



    START TRANSACTION; -- Start a transaction to ensure data consistency



    -- Attempt the following block of code, handle any exceptions if they occur

    BEGIN

        -- Delete records from excelformdetail

        DELETE FROM excelformdetail WHERE MasterSeq = inSeq;



        -- Delete records from excelformmaster

        DELETE FROM excelformmaster WHERE Seq = inSeq;



        -- Commit the transaction if no exceptions occur

        COMMIT;

    END;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `INSERT_COPY_EXCELMASTER` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `INSERT_COPY_EXCELMASTER`(

	IN `inSeq` INT

)
BEGIN

	 DECLARE newSeq INT ;

    DECLARE exit handler for sqlexception

    BEGIN

        -- Error occurred, rollback changes or perform necessary actions

        ROLLBACK;

        SELECT -1 AS NewSequence; -- Return -1 to indicate an error

    END;



    START TRANSACTION; -- Start a transaction to ensure data consistency



    -- Attempt the following block of code, handle any exceptions if they occur

    BEGIN

        SET newSeq = IFNULL((SELECT MAX(Seq) FROM excelformmaster), 0) + 1;



        -- Inserting a copy of the record and adjusting fields in excelformmaster

        INSERT INTO excelformmaster (Seq, ExcelFormName, USEYN, Registrant, RegistrationDt)

        SELECT newSeq, CONCAT(ExcelFormName, '_COPY'), USEYN, Registrant, CURDATE()

        FROM excelformmaster

        WHERE Seq = inSeq;



        -- Inserting details into excelformdetail

        INSERT INTO excelformdetail (Seq, MasterSeq, ExcelColumnName, ExcelColumnIndex, ExcelColumnValue, ExcelColumnMemo)

        SELECT Seq, newSeq, ExcelColumnName, ExcelColumnIndex, ExcelColumnValue, ExcelColumnMemo

        FROM excelformdetail

        WHERE MasterSeq = inSeq;



        -- Commit the transaction if no exceptions occur

        COMMIT;

        -- Return the newly generated sequence number

        SELECT newSeq AS NewSequence;

    END;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `usp_UpdateShopSendStatus` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `usp_UpdateShopSendStatus`()
BEGIN

    DECLARE v_AffectedRows INT DEFAULT 0;

    UPDATE shopprodin AS a

    LEFT JOIN (

        SELECT 'N' AS IMAGERESIZE, MIRRORIMGYN, CHANGESIZE, IMGTHREEONFOUR, 'N' AS REMOVEIMGTEXTYN, SEQ FROM shop11staddidtl

        UNION ALL

        SELECT 'N' AS IMAGERESIZE, MIRRORIMGYN, CHANGESIZE, IMGTHREEONFOUR, 'N' AS REMOVEIMGTEXTYN, SEQ FROM shoplotteonadddtl

        UNION ALL

        SELECT IMAGERESIZE, MIRRORIMGYN, CHANGESIZE, IMGTHREEONFOUR, 'N' AS REMOVEIMGTEXTYN, SEQ FROM shopaddrkakaodtl

        UNION ALL

        SELECT IMAGERESIZE, MIRRORIMGYN, CHANGESIZE, IMGTHREEONFOUR, REMOVEIMGTEXTYN, SEQ FROM shopaddrnaverstoredtl

        UNION ALL

        SELECT IMAGERESIZE, MIRRORIMGYN, CHANGESIZE, IMGTHREEONFOUR, 'N' AS REMOVEIMGTEXTYN, SEQ FROM shopgmarket2adddtl

        UNION ALL

        SELECT IMAGERESIZE, MIRRORIMGYN, CHANGESIZE, IMGTHREEONFOUR, 'N' AS REMOVEIMGTEXTYN, SEQ FROM shopauction2adddtl

        UNION ALL

        SELECT IMAGERESIZEYN AS IMAGERESIZE, MIRRORIMGYN, CHANGESIZE, IMGTHREEONFOUR, 'N' AS REMOVEIMGTEXTYN, SEQ FROM shopalwayzadddtl

        UNION ALL

        SELECT 'N' AS IMAGERESIZE, MIRRORIMGYN, CHANGESIZE, IMGTHREEONFOUR, 'N' AS REMOVEIMGTEXTYN, SEQ FROM shoptossshoppingadddtl

        UNION ALL

        SELECT 'N' AS IMAGERESIZE, MIRRORIMGYN, CHANGESIZE, 'N' AS IMGTHREEONFOUR, 'N' AS REMOVEIMGTEXTYN, SEQ FROM shopcoupangaddidtl

        UNION ALL

        SELECT 'N' AS IMAGERESIZE, MIRRORIMGYN, CHANGESIZE, 'N' AS IMGTHREEONFOUR, 'N' AS REMOVEIMGTEXTYN, SEQ FROM shopmelchiaddidtl

    ) AS D ON D.SEQ = a.SEQ

    	SET a.SHOPSENDSTATUS = 7000

    WHERE a.SHOPSENDSTATUS != 7000 

      AND a.INSERTDT >= '2025-05-26' AND a.INSERTDT <  '2025-06-05'

      AND (D.IMAGERESIZE = 'Y' OR D.IMAGERESIZE = '02' OR D.MIRRORIMGYN = 'Y' OR D.CHANGESIZE = 'Y' OR D.IMGTHREEONFOUR = 'Y' OR D.REMOVEIMGTEXTYN = 'Y');

    SET v_AffectedRows = ROW_COUNT();

    SELECT v_AffectedRows AS ResultMessage;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_BASESTOCKAUTO_PROC` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_BASESTOCKAUTO_PROC`(

	IN `V_COMPNO` INT,

	IN `V_BRANDCD` INT,

	IN `V_STKDT` VARCHAR(8),

	IN `V_INSERTID` VARCHAR(20)











)
    COMMENT '기초재고 차이 자동전표'
BEGIN

	DECLARE _STKDT  varchar(8);

	DECLARE _STKSEQ INT;

	DECLARE _PRODCD  varchar(20);

	DECLARE _PRODNM  varchar(200);

	DECLARE _QTY INT;

	DECLARE V_PRODCNT INT;

	DECLARE V_DIFFQTY INT;

	DECLARE v_maxrecvseq INT;

	DECLARE V_REALDT varchar(8);

	DECLARE v_idx INT DEFAULT 0;

	DECLARE v_first INT DEFAULT 1;

	

	DECLARE done INT DEFAULT 0;

	DECLARE c1 CURSOR FOR SELECT STKDT,STKSEQ,PRODCD,DIFFQTY,

								 		  (SELECT PRODNM FROM V_PRODUCTS B WHERE B.COMPNO=A.COMPNO AND B.BRANDCD=A.BRANDCD AND B.PRODCD=A.PRODCD) AS PRODNM

									FROM BASSTKDTL A

								  WHERE A.COMPNO = V_COMPNO

								    and A.BRANDCD= V_BRANDCD

								    and A.STKDT  = V_STKDT

									 and A.DIFFQTY <> 0;

	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;

	

	set V_PRODCNT = 0;

	set V_DIFFQTY = 0;

	SELECT count(*), SUM(DIFFQTY) into V_PRODCNT,V_DIFFQTY FROM BASSTKDTL WHERE COMPNO  = V_COMPNO and BRANDCD  = V_BRANDCD and STKDT  = V_STKDT and DIFFQTY <> 0;

	

	open c1;

	REPEAT

		FETCH NEXT FROM c1 INTO _STKDT,_STKSEQ,_PRODCD,_QTY,_PRODNM;

		IF not done THEN

			IF v_first then

				SELECT DATE_FORMAT(DATE_ADD(_STKDT, INTERVAL 0 DAY),'%Y%m%d') into V_REALDT FROM dual;

				set v_maxrecvseq = 0;

				SELECT MAX(RECVSEQ) INTO v_maxrecvseq FROM RECVMST WHERE COMPNO  = V_COMPNO and BRANDCD  = V_BRANDCD and RECVDT = _STKDT;

				INSERT INTO RECVMST(COMPNO,BRANDCD,RECVDT,RECVSEQ,RECVGUBUN,ENTDT,RECVDESC,BEFQTY,

										  REALDT,AFTQTY,CONFNAM,AUTOCHK,INSERTDT,INSERTID) 

							 	 VALUES(V_COMPNO,V_BRANDCD,_STKDT,IFNULL(v_maxrecvseq,0)+1,'재고차이',_STKDT,concat(_PRODNM,'외_',ifnull(V_PRODCNT,0),'개'),V_DIFFQTY,

										  V_REALDT,V_DIFFQTY,'admin','1',NOW(),V_INSERTID);

				set v_first = 0;

			END IF;

			set v_idx = v_idx + 1;

			INSERT INTO RECVDTL(COMPNO,BRANDCD,RECVDT,RECVSEQ,SEQ,PRODCD,BEFQTY,AFTQTY,REALDT,INSERTDT,INSERTID) 

						    VALUES(V_COMPNO,V_BRANDCD,_STKDT,IFNULL(v_maxrecvseq,0)+1,v_idx,_PRODCD,_QTY,_QTY,V_REALDT,NOW(),V_INSERTID);

						 

			UPDATE BASSTKMST SET RECVDT = _STKDT, RECVSEQ = IFNULL(v_maxrecvseq,0)+1 WHERE COMPNO = V_COMPNO and BRANDCD  = V_BRANDCD AND STKDT  = V_STKDT;

				

		END IF;

	UNTIL done END REPEAT;

	close c1;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_BASSTK_CRTNQURY` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_BASSTK_CRTNQURY`(

	IN `v_compno` INT,

	IN `v_brandcd` INT,

	IN `v_opt` INT,

	IN `v_name` VARCHAR(100),

	IN `v_stkdt` VARCHAR(8)

)
    COMMENT '기초재고 검색'
BEGIN



	DECLARE v_exists INT;

	DECLARE _stkdt varchar(8);

	DECLARE _sdt varchar(8);

	DECLARE _edt varchar(8);

	

	BEGIN

		SELECT 1 INTO v_exists FROM BASSTKMST WHERE COMPNO = v_compno and brandcd = v_brandcd and STKDT = v_stkdt;

		IF v_exists = 1 THEN

			SET @xSql = CONCAT("SELECT a.prodcd,ifnull(b.optprodcd,a.prodcd) as img,b.prodnm,b.specdes, a.qty,a.realqty,a.diffqty,a.reason 

							 FROM BASSTKDTL a, V_PRODUCTS b 

							WHERE a.compno = ", v_compno, " 

							and a.brandcd = ", v_brandcd, "

							  and a.STKDT = ", v_stkdt, " 

							  and a.prodcd=b.prodcd " );

			if v_opt = 1 then					 

				SET @v_colsql = CONCAT(@xSql, " and b.prodnm  like ?

									 order by b.prodnm" );

			end if;

			if v_opt = 0 then					 

				SET @v_colsql = CONCAT(@xSql, " and a.prodcd  like ?

									 order by a.prodcd" );

			end if;

		 

			set @temp2 = v_name;				

		 				 

			PREPARE dSql FROM @v_colsql;

			EXECUTE dSql USING @temp2;

			DEALLOCATE PREPARE dSql;

		ELSE

			Block1: BEGIN

				SELECT MAX(STKDT) INTO _stkdt FROM BASSTKMST where compno = v_compno and brandcd = v_brandcd;

				SELECT DATE_FORMAT(DATE_ADD(IFNULL(_stkdt,'20181231'), INTERVAL 1 DAY),'%Y%m%d') into _sdt FROM dual;

				set _edt = v_stkdt;

				CALL YWM_SETCODELIST(v_compno,v_brandcd,_sdt,_edt);

				SELECT distinct b.prodcdm as prodcd, ifnull(b.optprodcd,b.prodcdm) as img, b.prodnm,b.specdes, 

						 SUM(a.baseqty) + SUM(a.receiveqty) - SUM(a.saleqty) as qty, 

						 0 as realqty,0 as diffqty,'' as reason

				  FROM (SELECT distinct prodcd, sum(realqty) as baseqty, 0 AS receiveqty,0 AS saleqty

				  		    FROM BASSTKDTL 

						   WHERE compno = v_compno 

						   	and brandcd = v_brandcd

						     and STKDT = IFNULL(_stkdt,'20181231')

						   group BY prodcd

						  UNION all

						  SELECT distinct prodcd, 0 as baseqty, sum(AFTQTY) AS receiveqty, 0 AS saleqty

						    FROM RECVDTL

						   WHERE compno = v_compno 

						   	and brandcd = v_brandcd

						     and REALDT BETWEEN _sdt AND _edt

						   group BY prodcd

						  UNION all

						  SELECT distinct prodcd, 0 as baseqty, 0 AS receiveqty, sum(qty) AS saleqty

						    FROM WAREHOUSE_QTY_TMP2

						   group BY prodcd

					    ) a, V_PRODUCTS b

				 where v_compno = b.compno

				 and v_brandcd = b.brandcd 

				 and a.prodcd=b.prodcd

			    group BY b.prodcdm, b.optprodcd,b.prodnm,b.specdes ;

			END Block1;

		END IF;

	END;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_CLAIMAUTO_PROC` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_CLAIMAUTO_PROC`(

	IN `V_COMPNO` INT,

	IN `V_BRANDCD` INT,

	IN `V_CLMDT` VARCHAR(8),

	IN `V_CLMSEQ` INT,

	IN `V_INSERTID` VARCHAR(20)

)
    COMMENT '상담 자동전표발생시 사용'
BEGIN

	DECLARE _PROCTYPE varchar(50);

	DECLARE _CLMDT varchar(8);

	DECLARE _REGDT  varchar(20);

	DECLARE _RCVNAM  varchar(50);

	DECLARE _ADDR  varchar(200);

	DECLARE _CLPNO  varchar(50);

	DECLARE _PRODCD  varchar(20);

	DECLARE _PRODCDM  varchar(20);

	DECLARE _DIRAMT  INT;

	DECLARE _SUPPNAM  varchar(50);

	DECLARE _SUPPAMT  INT;

	DECLARE _QTY INT;

	DECLARE _PRICE INT;

	DECLARE _PRODNM varchar(200);

	DECLARE _SPECDES varchar(100);

	DECLARE _CLMCONTS varchar(200);

	DECLARE _RESALNAM varchar(50);

	DECLARE _GUBUN char(1);

	

	DECLARE v_exists INT;

	DECLARE v_maxordseq INT;

	DECLARE v_maxrecvseq INT;

	

	DECLARE done INT DEFAULT 0;

	DECLARE c1 CURSOR FOR SELECT PROCTYPE,CLMDT,REGDT,RCVNAM,ADDR,CLPNO,PRODCD,QTY,SUPPNAM,SUPPAMT,DIRAMT,left(CLMCONTS,200),RESALNAM,

										  (SELECT PRODNM FROM V_PRODUCTS B WHERE B.COMPNO=V_COMPNO AND B.PRODCD=A.PRODCD AND B.BRANDCD=V_BRANDCD) AS PRODNM,

										  (SELECT SPECDES FROM V_PRODUCTS B WHERE B.COMPNO=V_COMPNO AND B.PRODCD=A.PRODCD AND B.BRANDCD=V_BRANDCD) AS SPECDES,

										  (SELECT PRODCDM FROM V_PRODUCTS B WHERE B.COMPNO=V_COMPNO AND B.PRODCD=A.PRODCD AND B.BRANDCD=V_BRANDCD) AS PRODCDM

									FROM CLMLIST A

								  WHERE A.COMPNO  = V_COMPNO 

								    AND A.clmdt  = V_CLMDT

									 AND A.clmseq = V_CLMSEQ

									 AND A.BRANDCD = V_BRANDCD;

	DECLARE c2 CURSOR FOR SELECT A.gubun,A.prodcd,A.qty,ifnull(A.cusprice,1),

	 									  (SELECT PRODCDM FROM V_PRODUCTS B WHERE B.COMPNO=V_COMPNO AND B.PRODCD=A.PRODCD AND B.BRANDCD=V_BRANDCD) AS PRODCDM

									FROM CLMLISTDTL A

								  WHERE A.COMPNO=V_COMPNO 

								    AND A.clmdt=V_CLMDT  

								    AND A.clmseq=V_CLMSEQ

									  AND A.BRANDCD = V_BRANDCD;									

	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;

	



	

	open c1;

	REPEAT

		FETCH NEXT FROM c1 INTO _PROCTYPE,_CLMDT,_REGDT,_RCVNAM,_ADDR,_CLPNO,_PRODCD,_QTY,_SUPPNAM,_SUPPAMT,_DIRAMT,_CLMCONTS,_RESALNAM,_PRODNM,_SPECDES,_PRODCDM;

		if ifnull(_SPECDES,'') <> '' then

			set _PRODNM = concat(_PRODNM,'_',_SPECDES);

		end if;

		IF not done THEN

			IF IFNULL(_DIRAMT,0) = 0 THEN 

				SET _DIRAMT = 1;

			END IF;

			IF _PROCTYPE = '신규' OR _PROCTYPE ='직거래' OR _PROCTYPE ='파손 재발송' OR _PROCTYPE ='누락 재발송' OR _PROCTYPE ='불량재발송' OR _PROCTYPE ='미착 재발송' OR _PROCTYPE='분실 재발송' OR _PROCTYPE='오배송 재발송' then

				Block2: BEGIN

					DECLARE done2 INT DEFAULT 0;

					DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done2 = 1;

					open c2;

					REPEAT

						FETCH NEXT FROM c2 INTO _GUBUN,_PRODCD,_QTY,_PRICE,_PRODCDM;

						SELECT MAX(CONCAT(PRODNM,'_',IFNULL(SPECDES,''))) INTO _PRODNM FROM V_PRODUCTS WHERE COMPNO=V_COMPNO AND PRODCD=_PRODCD AND BRANDCD = V_BRANDCD;

						IF not done2 THEN 

							set v_maxordseq = 0;

							SET v_exists = 0;

							if _PRICE = 0 then set _PRICE = 1; end if;

							SELECT MAX(ORDSEQ) INTO v_exists FROM ORDMST WHERE COMPNO=V_COMPNO AND ORDDT =_CLMDT AND ORDSEQ = 3 AND BRANDCD = V_BRANDCD;

							IF v_exists > 0 then

								SELECT MAX(SEQ) INTO v_maxordseq FROM ORDDTL WHERE COMPNO=V_COMPNO AND ORDDT =_CLMDT AND ORDSEQ = 3 AND BRANDCD = V_BRANDCD;

								INSERT INTO ORDDTL(COMPNO,BRANDCD ,ORDDT,ORDSEQ,SEQ,RORDDT,RCVNAM,ADDR,CLPNO,QTY,SHPFEE,CREDIT,OPTDESC,PRODCD,MESSGE,ORDNM,ORDAMT) 

											VALUES(V_COMPNO,V_BRANDCD,_CLMDT, 3, IFNULL(v_maxordseq,0)+1, DATE_FORMAT(_REGDT,'%Y-%m-%d %H:%i'), _RCVNAM, _ADDR, _CLPNO,_QTY,_SUPPNAM,_SUPPAMT,_PRODNM,_PRODCD,_CLMCONTS,_RESALNAM,_PRICE);

							else

								INSERT INTO ORDMST(COMPNO,BRANDCD,ORDDT,ORDSEQ,INSERTDT,INSERTID)

											VALUES(V_COMPNO,V_BRANDCD,_CLMDT, 3, NOW(), V_INSERTID);

								INSERT INTO ORDDTL(COMPNO,BRANDCD,ORDDT,ORDSEQ,SEQ,RORDDT,RCVNAM,ADDR,CLPNO,QTY,SHPFEE,CREDIT,OPTDESC,PRODCD,MESSGE,ORDNM,ORDAMT) 

											VALUES(V_COMPNO,V_BRANDCD,_CLMDT,3,1,DATE_FORMAT(_REGDT,'%Y-%m-%d %H:%i'),_RCVNAM,_ADDR,_CLPNO,_QTY,_SUPPNAM,_SUPPAMT,_PRODNM,_PRODCD,_CLMCONTS,_RESALNAM,_PRICE);

							end if;

							UPDATE CLMLIST SET ORDDT = _CLMDT , ORDSEQ = 3, SEQ = IFNULL(v_maxordseq,0)+1 WHERE COMPNO=V_COMPNO AND clmdt  = V_CLMDT AND clmseq = V_CLMSEQ AND BRANDCD = V_BRANDCD;

						END IF;

					UNTIL done2 END REPEAT;

					close c2;

				END Block2;

			ELSEIF _PROCTYPE = "변심 맞교환" OR  _PROCTYPE ="불량 맞교환" OR _PROCTYPE ="파손 맞교환" OR _PROCTYPE ="오배송 맞 교환" OR _PROCTYPE ="분실맞교환" then

				Block4: BEGIN

					DECLARE done2 INT DEFAULT 0;

					DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done2 = 1;

					open c2;

					REPEAT

						FETCH NEXT FROM c2 INTO _GUBUN,_PRODCD,_QTY,_PRICE,_PRODCDM;

						SELECT MAX(CONCAT(PRODNM,'_',IFNULL(SPECDES,''))) INTO _PRODNM FROM V_PRODUCTS WHERE COMPNO=V_COMPNO AND PRODCD=_PRODCD AND BRANDCD = V_BRANDCD;

						IF not done2 THEN 

							if _PRICE = 0 then set _PRICE = 1; end if;

							IF _GUBUN = "2" THEN 

								set v_maxordseq = 0;

								SET v_exists = 0;

								SELECT MAX(ORDSEQ) INTO v_exists FROM ORDMST WHERE COMPNO=V_COMPNO AND ORDDT =_CLMDT AND ORDSEQ = 3 AND BRANDCD = V_BRANDCD;

								IF v_exists > 0 then

									SELECT MAX(SEQ) INTO v_maxordseq FROM ORDDTL WHERE COMPNO=V_COMPNO AND ORDDT =_CLMDT AND ORDSEQ = 3 AND BRANDCD = V_BRANDCD;

									INSERT INTO ORDDTL(COMPNO,BRANDCD,ORDDT,ORDSEQ,SEQ,RORDDT,RCVNAM,ADDR,CLPNO,QTY,SHPFEE,CREDIT,OPTDESC,PRODCD,MESSGE,ORDNM,ORDAMT) 

												VALUES(V_COMPNO,V_BRANDCD,_CLMDT, 3, IFNULL(v_maxordseq,0)+1, DATE_FORMAT(_REGDT,'%Y-%m-%d %H:%i'), _RCVNAM, _ADDR, _CLPNO,_QTY,_SUPPNAM,_SUPPAMT,_PRODNM,_PRODCD,_CLMCONTS,_RESALNAM,_PRICE);

								else

									INSERT INTO ORDMST(COMPNO,BRANDCD,ORDDT,ORDSEQ,INSERTDT,INSERTID)

												VALUES(V_COMPNO,V_BRANDCD,_CLMDT, 3, NOW(), V_INSERTID);

									INSERT INTO ORDDTL(COMPNO,BRANDCD,ORDDT,ORDSEQ,SEQ,RORDDT,RCVNAM,ADDR,CLPNO,QTY,SHPFEE,CREDIT,OPTDESC,PRODCD,MESSGE,ORDNM,ORDAMT) 

												VALUES(V_COMPNO,V_BRANDCD,_CLMDT,3,1,DATE_FORMAT(_REGDT,'%Y-%m-%d %H:%i'),_RCVNAM,_ADDR,_CLPNO,_QTY,_SUPPNAM,_SUPPAMT,_PRODNM,_PRODCD,_CLMCONTS,_RESALNAM,_PRICE);

								end if;

								

								set v_maxrecvseq = 0;

								SELECT MAX(RECVSEQ) INTO v_maxrecvseq FROM RECVMST WHERE COMPNO=V_COMPNO AND RECVDT = _CLMDT AND BRANDCD = V_BRANDCD;

								INSERT INTO RECVMST(COMPNO,BRANDCD,RECVDT,RECVSEQ,RECVGUBUN,ENTDT,RECVDESC,BEFQTY,AUTOCHK,INSERTDT,INSERTID) 

											 VALUES(V_COMPNO,V_BRANDCD,_CLMDT,IFNULL(v_maxrecvseq,0)+1,'반품',_REGDT,_PRODNM,_QTY,'1',NOW(),V_INSERTID);

								INSERT INTO RECVDTL(COMPNO,BRANDCD,RECVDT,RECVSEQ,SEQ,PRODCD,BEFQTY,INSERTDT,INSERTID) 

											 VALUES(V_COMPNO,V_BRANDCD,_CLMDT,IFNULL(v_maxrecvseq,0)+1,1,_PRODCDM,_QTY,NOW(),V_INSERTID);

											 

								UPDATE CLMLIST SET RECVDT = _CLMDT, RECVSEQ = IFNULL(v_maxrecvseq,0)+1 WHERE COMPNO=V_COMPNO AND clmdt  = V_CLMDT AND clmseq = V_CLMSEQ AND BRANDCD = V_BRANDCD;

								UPDATE CLMLIST SET ORDDT = _CLMDT , ORDSEQ = 3, SEQ = IFNULL(v_maxordseq,0)+1 WHERE COMPNO=V_COMPNO AND clmdt  = V_CLMDT AND clmseq = V_CLMSEQ AND BRANDCD = V_BRANDCD;

							ELSEIF _GUBUN = "1" THEN

								set v_maxrecvseq = 0;

								SELECT MAX(RECVSEQ) INTO v_maxrecvseq FROM RECVMST WHERE COMPNO=V_COMPNO AND RECVDT = _CLMDT AND BRANDCD = V_BRANDCD;

								INSERT INTO RECVMST(COMPNO,BRANDCD,RECVDT,RECVSEQ,RECVGUBUN,ENTDT,RECVDESC,BEFQTY,AUTOCHK,INSERTDT,INSERTID) 

											 VALUES(V_COMPNO,V_BRANDCD,_CLMDT,IFNULL(v_maxrecvseq,0)+1,'반품',_REGDT,_PRODNM,_QTY,'1',NOW(),V_INSERTID);

								INSERT INTO RECVDTL(COMPNO,BRANDCD,RECVDT,RECVSEQ,SEQ,PRODCD,BEFQTY,INSERTDT,INSERTID) 

											 VALUES(V_COMPNO,V_BRANDCD,_CLMDT,IFNULL(v_maxrecvseq,0)+1,1,_PRODCDM,_QTY,NOW(),V_INSERTID);

											 

								UPDATE CLMLIST SET RECVDT = _CLMDT, RECVSEQ = IFNULL(v_maxrecvseq,0)+1 WHERE COMPNO=V_COMPNO AND clmdt  = V_CLMDT AND clmseq = V_CLMSEQ AND BRANDCD = V_BRANDCD;								

							ELSEIF _GUBUN = "3" THEN

								set v_maxordseq = 0;

								SET v_exists = 0;

								SELECT MAX(ORDSEQ) INTO v_exists FROM ORDMST WHERE COMPNO=V_COMPNO AND ORDDT =_CLMDT AND ORDSEQ = 3 AND BRANDCD = V_BRANDCD;

								IF v_exists > 0 then

									SELECT MAX(SEQ) INTO v_maxordseq FROM ORDDTL WHERE COMPNO=V_COMPNO AND ORDDT =_CLMDT AND ORDSEQ = 3 AND BRANDCD = V_BRANDCD;

									INSERT INTO ORDDTL(COMPNO,BRANDCD,ORDDT,ORDSEQ,SEQ,RORDDT,RCVNAM,ADDR,CLPNO,QTY,SHPFEE,CREDIT,OPTDESC,PRODCD,MESSGE,ORDNM,ORDAMT) 

												VALUES(V_COMPNO,V_BRANDCD,_CLMDT, 3, IFNULL(v_maxordseq,0)+1, DATE_FORMAT(_REGDT,'%Y-%m-%d %H:%i'), _RCVNAM, _ADDR, _CLPNO,_QTY,_SUPPNAM,_SUPPAMT,_PRODNM,_PRODCD,_CLMCONTS,_RESALNAM,_PRICE);

								else

									INSERT INTO ORDMST(COMPNO,BRANDCD,ORDDT,ORDSEQ,INSERTDT,INSERTID)

												VALUES(V_COMPNO,V_BRANDCD,_CLMDT, 3, NOW(), V_INSERTID);

									INSERT INTO ORDDTL(COMPNO,BRANDCD,ORDDT,ORDSEQ,SEQ,RORDDT,RCVNAM,ADDR,CLPNO,QTY,SHPFEE,CREDIT,OPTDESC,PRODCD,MESSGE,ORDNM,ORDAMT) 

												VALUES(V_COMPNO,V_BRANDCD,_CLMDT,3,1,DATE_FORMAT(_REGDT,'%Y-%m-%d %H:%i'),_RCVNAM,_ADDR,_CLPNO,_QTY,_SUPPNAM,_SUPPAMT,_PRODNM,_PRODCD,_CLMCONTS,_RESALNAM,_PRICE);

											

								end if;

								UPDATE CLMLIST SET ORDDT = _CLMDT , ORDSEQ = 3, SEQ = IFNULL(v_maxordseq,0)+1 WHERE COMPNO=V_COMPNO AND clmdt  = V_CLMDT AND clmseq = V_CLMSEQ AND BRANDCD = V_BRANDCD;	

							END IF;

									

						END IF;

					UNTIL done2 END REPEAT;

					close c2;

				END Block4;	

			ELSEIF _PROCTYPE = "파손 반품회수" OR  _PROCTYPE ="불량 반품회수" OR _PROCTYPE ="변심 반품회수" OR _PROCTYPE ="오배송 반품회수" OR _PROCTYPE ="배송지연 반품" OR _PROCTYPE ="배송거부 반품" then

				Block3: BEGIN

					DECLARE done2 INT DEFAULT 0;

					DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done2 = 1;

					open c2;

					REPEAT

						FETCH NEXT FROM c2 INTO _GUBUN,_PRODCD,_QTY,_PRICE,_PRODCDM;

						SELECT MAX(CONCAT(PRODNM,'_',IFNULL(SPECDES,''))) INTO _PRODNM FROM V_PRODUCTS WHERE COMPNO=V_COMPNO AND PRODCD=_PRODCD AND BRANDCD = V_BRANDCD;

						IF not done2 THEN 

							if _PRICE = 0 then set _PRICE = 1; end if;

							set v_maxrecvseq = 0;

							SELECT MAX(RECVSEQ) INTO v_maxrecvseq FROM RECVMST WHERE COMPNO = V_COMPNO AND RECVDT = _CLMDT AND BRANDCD = V_BRANDCD;

							INSERT INTO RECVMST(COMPNO,BRANDCD,RECVDT,RECVSEQ,RECVGUBUN,ENTDT,RECVDESC,BEFQTY,AUTOCHK,INSERTDT,INSERTID) 

										 VALUES(V_COMPNO,V_BRANDCD,_CLMDT,IFNULL(v_maxrecvseq,0)+1,'반품',_REGDT,_PRODNM,_QTY,'1',NOW(),V_INSERTID);

							INSERT INTO RECVDTL(COMPNO,BRANDCD,RECVDT,RECVSEQ,SEQ,PRODCD,BEFQTY,INSERTDT,INSERTID) 

										 VALUES(V_COMPNO,V_BRANDCD,_CLMDT,IFNULL(v_maxrecvseq,0)+1,1,_PRODCDM,_QTY,NOW(),V_INSERTID);

							UPDATE CLMLIST SET RECVDT = _CLMDT, RECVSEQ = IFNULL(v_maxrecvseq,0)+1 WHERE COMPNO=V_COMPNO AND clmdt  = V_CLMDT AND clmseq = V_CLMSEQ AND BRANDCD = V_BRANDCD;

						END IF;

					UNTIL done2 END REPEAT;

					close c2;

				END Block3;	

			END IF;

		END IF;

	UNTIL done END REPEAT;

	close c1;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_CLAIMAUTO_PROC_VER2` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_CLAIMAUTO_PROC_VER2`(

	IN `V_COMPNO` INT,

	IN `V_BRANDCD` INT,

	IN `V_CLMDT` VARCHAR(8),

	IN `V_CLMSEQ` INT,

	IN `V_INSERTID` VARCHAR(20)

)
BEGIN

	DECLARE	_PROCTYPE	varchar(50);

	DECLARE	_CLMDT		varchar(8);

	DECLARE	_REGDT		varchar(20);

	DECLARE	_RCVNAM		varchar(50);

	DECLARE	_ADDR			varchar(200);

	DECLARE	_CLPNO		varchar(50);

	DECLARE	_PRODCD		varchar(20);

	DECLARE	_PRODCDM		varchar(20);

	DECLARE	_DIRAMT		INT;

	DECLARE	_SUPPNAM		varchar(50);

	DECLARE	_SUPPAMT		INT;

	DECLARE	_QTY			INT;

	DECLARE	_PRICE		INT;

	DECLARE	_PRODNM		varchar(200);

	DECLARE	_SPECDES		varchar(100);

	DECLARE	_CLMCONTS	varchar(200);

	DECLARE	_RESALNAM	varchar(50);

	DECLARE	_GUBUN		char(1);

	

	DECLARE	_inouttype	VARCHAR(100);

	

	DECLARE v_warecd int;

	DECLARE v_neccd1 varchar(200);

	DECLARE v_neccd2 int;

	DECLARE v_neccd3 int;	

	

	DECLARE	v_exists			INT;

	DECLARE	v_maxordseq		INT;

	DECLARE	v_maxrecvseq	INT;

	

	DECLARE	done	INT	DEFAULT	0;

	

	

	DECLARE	c1	CURSOR	FOR	

		SELECT	PROCTYPE,	CLMDT,	REGDT,	RCVNAM,	ADDR,		CLPNO,	

					PRODCD,		QTY,		SUPPNAM,	SUPPAMT,	DIRAMT,	left(CLMCONTS,200),	RESALNAM,

					(SELECT		PRODNM	FROM	V_PRODUCTS	B	WHERE	B.COMPNO=V_COMPNO AND B.PRODCD=A.PRODCD AND B.BRANDCD=V_BRANDCD) AS PRODNM,

					(SELECT		SPECDES	FROM	V_PRODUCTS	B	WHERE B.COMPNO=V_COMPNO AND B.PRODCD=A.PRODCD AND B.BRANDCD=V_BRANDCD) AS SPECDES,

					(SELECT		PRODCDM	FROM	V_PRODUCTS	B	WHERE B.COMPNO=V_COMPNO AND B.PRODCD=A.PRODCD AND B.BRANDCD=V_BRANDCD) AS PRODCDM

		FROM		CLMLIST		A

		WHERE		A.COMPNO		=	V_COMPNO 

	 	AND		A.clmdt		=	V_CLMDT

		AND		A.clmseq		=	V_CLMSEQ

		AND		A.BRANDCD	=	V_BRANDCD;



	

	DECLARE	c2	CURSOR	FOR

		SELECT	A.gubun,		A.prodcd,		A.qty,		ifnull(A.cusprice,1),

					(SELECT	PRODCDM	FROM	V_PRODUCTS	B	WHERE B.COMPNO=V_COMPNO AND B.PRODCD=A.PRODCD AND B.BRANDCD=V_BRANDCD) AS PRODCDM

		FROM		CLMLISTDTL	A

		WHERE		A.COMPNO		=	V_COMPNO 

		AND		A.clmdt		=	V_CLMDT  

		AND		A.clmseq		=	V_CLMSEQ

		AND		A.BRANDCD	=	V_BRANDCD;

		

	DECLARE	CONTINUE	HANDLER	FOR	SQLSTATE	'02000'	SET	done	=	1;



	OPEN	c1;

	

	REPEAT

		FETCH	NEXT	FROM	c1

				INTO	_PROCTYPE,	_CLMDT,	_REGDT,		_RCVNAM,		_ADDR,	_CLPNO,

						_PRODCD,		_QTY,		_SUPPNAM,	_SUPPAMT,	_DIRAMT,	_CLMCONTS,

						_RESALNAM,	_PRODNM,	_SPECDES,	_PRODCDM;

						

		if	ifnull(_SPECDES, '')	<>	''	then

			SET	_PRODNM	=	concat(_PRODNM, '_', _SPECDES);

		END	if;

		

		IF	NOT	done	THEN

			IF	IFNULL(_DIRAMT, 0)	=	0	THEN 

				SET	_DIRAMT = 1;

			END	IF;

			

			

			INOUTTYPE_SELECT_Block:	begin

				DECLARE	sel_done		INT	DEFAULT	0;

				DECLARE	continue		handler	FOR	SQLSTATE	'02000'	SET	sel_done	=	1;

				

				SET	_inouttype	=	"";

				

				SELECT	inouttype

				INTO		_inouttype

				FROM		PROCTYPE

				WHERE		compno		=	v_compno

				AND		brandcd		=	v_brandcd

				AND		proctypecd	=	_PROCTYPE;

			END	INOUTTYPE_SELECT_Block;			

			

			IF	_inouttype	=	"발송"	then

				Block2:	BEGIN

					DECLARE	done2	INT	DEFAULT	0;

					DECLARE	CONTINUE	HANDLER	FOR	SQLSTATE	'02000'	SET	done2	=	1;

					

					OPEN	c2;

					

					REPEAT

						FETCH	NEXT	FROM	c2	

								INTO	_GUBUN,	_PRODCD,	_QTY,	_PRICE,	_PRODCDM;

								

						

						SELECT	MAX(CONCAT(PRODNM,'_',IFNULL(SPECDES,'')))

						INTO		_PRODNM

						FROM		V_PRODUCTS

						WHERE		COMPNO	=	V_COMPNO

						AND		PRODCD	=	_PRODCD

						AND		BRANDCD	=	V_BRANDCD;

						

						IF	NOT	done2	THEN 

							SET	v_maxordseq	=	0;

							SET	v_exists		=	0;

							

							if	_PRICE	=	0	then

								set _PRICE	=	1;	

							END	if;

							

							SELECT	MAX(ORDSEQ)

							INTO		v_exists

							FROM		ORDMST

							WHERE		COMPNO	=	V_COMPNO

							AND		ORDDT		=	_CLMDT

							AND		ORDSEQ	=	3

							AND		BRANDCD	=	V_BRANDCD;

							

							IF	v_exists	>	0	then

								SELECT	MAX(SEQ)

								INTO		v_maxordseq

								FROM		ORDDTL

								WHERE		COMPNO	=	V_COMPNO

								AND		ORDDT		=	_CLMDT

								AND		ORDSEQ	=	3

								AND		BRANDCD	=	V_BRANDCD;



								

								

								INSERT	INTO	ORDDTL	(COMPNO,		BRANDCD,		ORDDT,		ORDSEQ,		SEQ,

																RORDDT,	

																RCVNAM,		ADDR,			CLPNO,		QTY,			SHPFEE,

																CREDIT,		OPTDESC,		PRODCD,		MESSGE,		ORDNM,

																ORDAMT,		CLMDT,		CLMSEQ) 

											VALUES			(V_COMPNO,	V_BRANDCD,	_CLMDT,		3,				IFNULL(v_maxordseq,0)+1,

																DATE_FORMAT(_REGDT,'%Y-%m-%d %H:%i'),

																_RCVNAM,		_ADDR,		_CLPNO,		_QTY,			_SUPPAMT,

																_SUPPNAM,	_PRODNM,		_PRODCD,		_CLMCONTS,	_RESALNAM,

																_PRICE,		V_CLMDT,		V_CLMSEQ);

							ELSE

								

								INSERT	INTO	ORDMST	(COMPNO,		BRANDCD,		ORDDT,	ORDSEQ,		INSERTDT,	INSERTID)

											VALUES			(V_COMPNO,	V_BRANDCD,	_CLMDT,	3,				NOW(),		V_INSERTID);

											

								

								INSERT	INTO	ORDDTL	(COMPNO,		BRANDCD,		ORDDT,		ORDSEQ,		SEQ,

																RORDDT,

																RCVNAM,		ADDR,			CLPNO,		QTY,			SHPFEE,

																CREDIT,		OPTDESC,		PRODCD,		MESSGE,		ORDNM,

																ORDAMT,		CLMDT,		CLMSEQ) 

											VALUES			(V_COMPNO,	V_BRANDCD,	_CLMDT,		3,				1,

																DATE_FORMAT(_REGDT,'%Y-%m-%d %H:%i'),

																_RCVNAM,		_ADDR,		_CLPNO,		_QTY,			_SUPPAMT,

																_SUPPNAM,	_PRODNM,		_PRODCD,		_CLMCONTS,	_RESALNAM,

																_PRICE,		V_CLMDT,		V_CLMSEQ);

							END	if;

							

							

							UPDATE	CLMLIST

							SET		ORDDT		=	_CLMDT,

										ORDSEQ	=	3,

										SEQ		=	IFNULL(v_maxordseq, 0) + 1

							WHERE		COMPNO	=	V_COMPNO

							AND		clmdt		=	V_CLMDT

							AND		clmseq	=	V_CLMSEQ

							AND		BRANDCD	=	V_BRANDCD;

						END	IF;

					UNTIL	done2	END	REPEAT;

					

					close	c2;

				END	Block2;

			ELSEIF	_inouttype	=	"회수_발송"	then

				Block4: BEGIN

					DECLARE	done2	INT	DEFAULT	0;

					DECLARE	CONTINUE	HANDLER	FOR	SQLSTATE	'02000'	SET	done2	=	1;

					

					OPEN	c2;

					

					REPEAT

						FETCH	NEXT	FROM	c2

								INTO	_GUBUN,	_PRODCD,	_QTY,	_PRICE,	_PRODCDM;

								

						SELECT	MAX(CONCAT(PRODNM,'_',IFNULL(SPECDES,'')))

						INTO		_PRODNM

						FROM		V_PRODUCTS

						WHERE		COMPNO	=	V_COMPNO

						AND		PRODCD	=	_PRODCD

						AND		BRANDCD	=	V_BRANDCD;

						

						IF	NOT	done2	THEN 

							if	_PRICE	=	0	then

								set _PRICE	=	1;

							END	if;

							

							

							IF	_GUBUN = "2" THEN

								SET	v_maxordseq	=	0;

								SET	v_exists		=	0;

								

								SELECT	MAX(ORDSEQ)

								INTO		v_exists

								FROM		ORDMST

								WHERE		COMPNO	=	V_COMPNO

								AND		ORDDT		=	_CLMDT

								AND		ORDSEQ	=	3

								AND		BRANDCD	=	V_BRANDCD;

								

								IF	v_exists	>	0	then

									SELECT	MAX(SEQ)

									INTO		v_maxordseq

									FROM		ORDDTL

									WHERE		COMPNO	=	V_COMPNO

									AND		ORDDT		=	_CLMDT

									AND		ORDSEQ	=	3

									AND		BRANDCD	=	V_BRANDCD;

									

									

									INSERT	INTO	ORDDTL	(COMPNO,		BRANDCD,		ORDDT,		ORDSEQ,		SEQ,

																	RORDDT,

																	RCVNAM,		ADDR,			CLPNO,		QTY,			SHPFEE,

																	CREDIT,		OPTDESC,		PRODCD,		MESSGE,		ORDNM,

																	ORDAMT,		CLMDT,		CLMSEQ) 

												VALUES			(V_COMPNO,	V_BRANDCD,	_CLMDT,		3,				IFNULL(v_maxordseq,0) + 1,

																	DATE_FORMAT(_REGDT,'%Y-%m-%d %H:%i'),

																	_RCVNAM,		_ADDR,		_CLPNO,		_QTY,			_SUPPAMT,

																	_SUPPNAM,	_PRODNM,		_PRODCD,		_CLMCONTS,	_RESALNAM,

																	_PRICE,		V_CLMDT,		V_CLMSEQ);

								ELSE	

									

									INSERT	INTO	ORDMST	(COMPNO,		BRANDCD,		ORDDT,	ORDSEQ,	INSERTDT,	INSERTID)

												VALUES			(V_COMPNO,	V_BRANDCD,	_CLMDT,	3,			NOW(),		V_INSERTID);

										

									

									INSERT	INTO	ORDDTL	(COMPNO,		BRANDCD,		ORDDT,		ORDSEQ,		SEQ,

																	RORDDT,

																	RCVNAM,		ADDR,			CLPNO,		QTY,			SHPFEE,

																	CREDIT,		OPTDESC,		PRODCD,		MESSGE,		ORDNM,

																	ORDAMT,		CLMDDT,		CLMSEQ) 

												VALUES			(V_COMPNO,	V_BRANDCD,	_CLMDT,		3,				1,

																	DATE_FORMAT(_REGDT,'%Y-%m-%d %H:%i'),

																	_RCVNAM,		_ADDR,		_CLPNO,		_QTY,			_SUPPAMT,

																	_SUPPNAM,	_PRODNM,		_PRODCD,		_CLMCONTS,	_RESALNAM,

																	_PRICE,		V_CLMDT,		V_CLMSEQ);

								END	if;

								

								SET	v_maxrecvseq	=	0;

								

								SELECT	MAX(RECVSEQ)

								INTO		v_maxrecvseq

								FROM		RECVMST

								WHERE		COMPNO	=	V_COMPNO

								AND		RECVDT	=	_CLMDT

								AND		BRANDCD	=	V_BRANDCD;

								

								

								INSERT	INTO	RECVMST	(COMPNO,		BRANDCD,		RECVDT,		RECVSEQ,

																RECVGUBUN,

																ENTDT,		RECVDESC,	BEFQTY,		AUTOCHK,		INSERTDT,	INSERTID) 

											VALUES			(V_COMPNO,	V_BRANDCD,	_CLMDT,		IFNULL(v_maxrecvseq,0) + 1,

																'반품',	

																_REGDT,		_PRODNM,		_QTY,			'1',			NOW(),		V_INSERTID);

																

								

								INSERT	INTO	RECVDTL	(COMPNO,		BRANDCD,		RECVDT,		RECVSEQ,

																SEQ,			PRODCD,		BEFQTY,		INSERTDT,	INSERTID) 

											 VALUES			(V_COMPNO,	V_BRANDCD,	_CLMDT,		IFNULL(v_maxrecvseq,0) + 1,

											 					1,				_PRODCDM,	_QTY,			NOW(),		V_INSERTID);

											 

								# 추가 park 2021-11-19			 					

								select ifnull(max(WARECD),1), ifnull(max(NECCD1),'A'), ifnull(max(NECCD2),1), ifnull(max(NECCD3),1) into v_warecd, v_neccd1, v_neccd2, v_neccd3 

								  from NECPRODMST 

								 where compno=V_COMPNO 

								   and prodcd=_PRODCDM;

								   

								insert into RECVWARE(COMPNO, BRANDCD, RECVDT, RECVSEQ, SEQ, NECSEQ, PRODCD, WARECD, NECCD1, NECCD2, NECCD3, BEFQTY, AFTQTY)

								              values(V_COMPNO,1,_CLMDT, IFNULL(v_maxrecvseq,0)+1, 1, 1, _PRODCDM, v_warecd, v_neccd1, v_neccd2, v_neccd3, _QTY, _QTY);			 					

								

								UPDATE	CLMLIST	

								SET		RECVDT	=	_CLMDT,

											RECVSEQ	=	IFNULL(v_maxrecvseq,0) + 1

								WHERE		COMPNO	=	V_COMPNO

								AND		clmdt		=	V_CLMDT

								AND		clmseq	=	V_CLMSEQ

								AND		BRANDCD	=	V_BRANDCD;

								

								

								UPDATE	CLMLIST

								SET		ORDDT		=	_CLMDT,

											ORDSEQ	=	3,

											SEQ		=	IFNULL(v_maxordseq,0) + 1

								WHERE		COMPNO	=	V_COMPNO

								AND		clmdt		=	V_CLMDT

								AND		clmseq	=	V_CLMSEQ

								AND		BRANDCD	=	V_BRANDCD;



							

							ELSEIF	_GUBUN	=	"1"	THEN

								SET	v_maxrecvseq	=	0;

								

								SELECT	MAX(RECVSEQ)

								INTO		v_maxrecvseq

								FROM		RECVMST

								WHERE		COMPNO	=	V_COMPNO

								AND		RECVDT	=	_CLMDT

								AND		BRANDCD	=	V_BRANDCD;

								

								

								INSERT	INTO	RECVMST	(COMPNO,		BRANDCD,		RECVDT,	RECVSEQ,

																RECVGUBUN,

																ENTDT,		RECVDESC,	BEFQTY,	AUTOCHK,		INSERTDT,	INSERTID) 

											VALUES			(V_COMPNO,	V_BRANDCD,	_CLMDT,	IFNULL(v_maxrecvseq,0) + 1,

																'반품',

																_REGDT,		_PRODNM,		_QTY,		'1',			NOW(),		V_INSERTID);

								

								

								INSERT	INTO	RECVDTL	(COMPNO,		BRANDCD,		RECVDT,	RECVSEQ,

																SEQ,			PRODCD,		BEFQTY,	INSERTDT,	INSERTID) 

											VALUES			(V_COMPNO,	V_BRANDCD,	_CLMDT,	IFNULL(v_maxrecvseq,0)+1,

																1,				_PRODCDM,	_QTY,		NOW(),		V_INSERTID);

											 

								# park 2021-11-19

								select ifnull(max(WARECD),1), ifnull(max(NECCD1),'A'), ifnull(max(NECCD2),1), ifnull(max(NECCD3),1) into v_warecd, v_neccd1, v_neccd2, v_neccd3 

								  from NECPRODMST 

								 where compno=V_COMPNO 

								   and prodcd=_PRODCDM;

								   

								insert into RECVWARE(COMPNO, BRANDCD, RECVDT, RECVSEQ, SEQ, NECSEQ, PRODCD, WARECD, NECCD1, NECCD2, NECCD3, BEFQTY, AFTQTY)

								              values(V_COMPNO,1,_CLMDT, IFNULL(v_maxrecvseq,0)+1, 1, 1, _PRODCDM, v_warecd, v_neccd1, v_neccd2, v_neccd3, _QTY, _QTY);

											  								

								UPDATE	CLMLIST

								SET		RECVDT	=	_CLMDT,

											RECVSEQ	=	IFNULL(v_maxrecvseq,0) + 1

								WHERE		COMPNO	=	V_COMPNO

								AND		clmdt		=	V_CLMDT

								AND		clmseq	=	V_CLMSEQ

								AND		BRANDCD	=	V_BRANDCD;								



							

							ELSEIF	_GUBUN	=	"3"	THEN

								SET	v_maxordseq	=	0;

								SET	v_exists		=	0;

								

								SELECT	MAX(ORDSEQ)

								INTO		v_exists

								FROM		ORDMST

								WHERE		COMPNO	=	V_COMPNO

								AND		ORDDT		=	_CLMDT

								AND		ORDSEQ	=	3

								AND		BRANDCD	=	V_BRANDCD;

								

								IF	v_exists	>	0	then

									SELECT	MAX(SEQ)

									INTO		v_maxordseq

									FROM		ORDDTL

									WHERE		COMPNO	=	V_COMPNO

									AND		ORDDT		=	_CLMDT

									AND		ORDSEQ	=	3

									AND		BRANDCD	=	V_BRANDCD;

									

									

									INSERT	INTO	ORDDTL	(COMPNO,		BRANDCD,		ORDDT,	ORDSEQ,		SEQ,

																	RORDDT,

																	RCVNAM,		ADDR,			CLPNO,	QTY,			SHPFEE,

																	CREDIT,		OPTDESC,		PRODCD,	MESSGE,		ORDNM,

																	ORDAMT,		CLMDT,		CLMSEQ) 

												VALUES			(V_COMPNO,	V_BRANDCD,	_CLMDT,	3, 			IFNULL(v_maxordseq,0)+1,

																	DATE_FORMAT(_REGDT,'%Y-%m-%d %H:%i'),

																	_RCVNAM,		_ADDR,		_CLPNO,	_QTY,			_SUPPAMT,

																	_SUPPNAM,	_PRODNM,		_PRODCD,	_CLMCONTS,	_RESALNAM,

																	_PRICE,		V_CLMDT,		V_CLMSEQ);

								ELSE

									

									INSERT	INTO	ORDMST	(COMPNO,		BRANDCD,		ORDDT,		ORDSEQ,	INSERTDT,	INSERTID)

												VALUES			(V_COMPNO,	V_BRANDCD,	_CLMDT,		3,			NOW(),		V_INSERTID);

												

									

									INSERT	INTO	ORDDTL	(COMPNO,		BRANDCD,		ORDDT,		ORDSEQ,		SEQ,

																	RORDDT,

																	RCVNAM,		ADDR,			CLPNO,		QTY,			SHPFEE,

																	CREDIT,		OPTDESC,		PRODCD,		MESSGE,		ORDNM,

																	ORDAMT,		CLMDT,		CLMSEQ) 

												VALUES			(V_COMPNO,	V_BRANDCD,	_CLMDT,		3,				1,

																	DATE_FORMAT(_REGDT,'%Y-%m-%d %H:%i'),

																	_RCVNAM,		_ADDR,		_CLPNO,		_QTY,			_SUPPAMT,

																	_SUPPNAM,	_PRODNM,		_PRODCD,		_CLMCONTS,	_RESALNAM,

																	_PRICE,		V_CLMDT,		V_CLMSEQ);

								END	if;

								

								

								UPDATE	CLMLIST

								SET		ORDDT		=	_CLMDT,

											ORDSEQ	=	3,

											SEQ		=	IFNULL(v_maxordseq,0) + 1

								WHERE		COMPNO	=	V_COMPNO

								AND		clmdt		=	V_CLMDT

								AND		clmseq	=	V_CLMSEQ

								AND		BRANDCD	=	V_BRANDCD;	

							END	IF;

						END	IF;

					UNTIL	done2	END	REPEAT;

					

					close	c2;

				END	Block4;	

			ELSEIF	_inouttype	=	"회수"	then

				Block3:	BEGIN

					DECLARE	done2	INT	DEFAULT	0;

					DECLARE	CONTINUE	HANDLER	FOR	SQLSTATE	'02000'	SET	done2	=	1;

					

					OPEN	c2;

					

					REPEAT

						FETCH	NEXT	FROM	c2

								INTO	_GUBUN,	_PRODCD,	_QTY,	_PRICE,	_PRODCDM;

								

						SELECT	MAX(CONCAT(PRODNM,'_',IFNULL(SPECDES,'')))

						INTO		_PRODNM

						FROM		V_PRODUCTS

						WHERE		COMPNO	=	V_COMPNO

						AND		PRODCD	=	_PRODCD

						AND		BRANDCD	=	V_BRANDCD;

						

						IF	NOT	done2	THEN 

							if	_PRICE	=	0	then

								SET	_PRICE	=	1;

							END	if;

							

							SET	v_maxrecvseq	=	0;

							

							SELECT	MAX(RECVSEQ)

							INTO		v_maxrecvseq

							FROM		RECVMST

							WHERE		COMPNO	=	V_COMPNO

							AND		RECVDT	=	_CLMDT

							AND		BRANDCD	=	V_BRANDCD;

							

							

							INSERT	INTO	RECVMST	(COMPNO,		BRANDCD,		RECVDT,		RECVSEQ,

															RECVGUBUN,

															ENTDT,		RECVDESC,	BEFQTY,		AUTOCHK,		INSERTDT,	INSERTID) 

										VALUES			(V_COMPNO,	V_BRANDCD,	_CLMDT,		IFNULL(v_maxrecvseq,0)+1,

															'반품',

															_REGDT,		_PRODNM,		_QTY,			'1',			NOW(),		V_INSERTID);

															

							

							INSERT	INTO	RECVDTL	(COMPNO,		BRANDCD,		RECVDT,		RECVSEQ,								SEQ,

															PRODCD,		BEFQTY,		INSERTDT,	INSERTID) 

										VALUES			(V_COMPNO,	V_BRANDCD,	_CLMDT,		IFNULL(v_maxrecvseq,0) + 1,	1,

															_PRODCDM,	_QTY,			NOW(),		V_INSERTID);

							

							# 입출고 창고위치 테이블 삽입 park 2021-11-19

							select ifnull(max(WARECD),1), ifnull(max(NECCD1),'A'), ifnull(max(NECCD2),1), ifnull(max(NECCD3),1) into v_warecd, v_neccd1, v_neccd2, v_neccd3 

							  from NECPRODMST 

							 where compno=V_COMPNO 

							   and prodcd=_PRODCDM;

							   

							insert into RECVWARE(COMPNO, BRANDCD, RECVDT, RECVSEQ, SEQ, NECSEQ, PRODCD, WARECD, NECCD1, NECCD2, NECCD3, BEFQTY, AFTQTY)

							              values(V_COMPNO,1,_CLMDT, IFNULL(v_maxrecvseq,0)+1, 1, 1, _PRODCDM, v_warecd, v_neccd1, v_neccd2, v_neccd3, _QTY, _QTY);

							              

							UPDATE	CLMLIST

							SET		RECVDT	=	_CLMDT,

										RECVSEQ	=	IFNULL(v_maxrecvseq,0) + 1

							WHERE		COMPNO	=	V_COMPNO

							AND		clmdt		=	V_CLMDT

							AND		clmseq	=	V_CLMSEQ

							AND		BRANDCD	=	V_BRANDCD;

						END	IF;

					UNTIL	done2	END	REPEAT;

					

					close	c2;

				END	Block3;	

			END	IF;

		END	IF;

	UNTIL	done	END	REPEAT;

	

	close	c1;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_EXCEL_EXPPICUP` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_EXCEL_EXPPICUP`(

	IN `V_COMPNO` INT,

	IN `V_BRANDCD` INT,

	IN `V_ORDDT` VARCHAR(20),

	IN `V_ORDSEQ` INT,

	IN `V_EORDSEQ` INT

)
    COMMENT '택배사별 픽업 리스트'
BEGIN

	drop TEMPORARY TABLE if EXISTS tmp;

	CREATE TEMPORARY TABLE IF NOT EXISTS tmp ENGINE=MEMORY AS

	(SELECT d.ordseq*1000000+d.seq AS seq,LEFT(d.rorddt,10) as rorddt,d.rcvnam,replace(d.pstno,'-','') as pstno,d.addr,d.clpno,d.telno,d.qty,

			  IFNULL((SELECT delivamt FROM EXPORDQTYTAB a, EXPCOST c WHERE a.COMPNO=b.COMPNO and a.brandcd = b.brandcd AND a.prodcd = b.prodcdm AND a.ordqty=d.qty AND a.COMPNO=c.COMPNO and a.brandcd = c.brandcd AND a.PRODCD=c.prodcd AND a.delivtabno=c.tabno),0) as shpfee,

			  d.credit,concat(ifnull(b.expkindnm,''),"◆",TRIM(ifnull(b.prodnm,'')),TRIM(ifnull(b.specdes,'')),"-",d.qty,"개") AS expprodnm,d.messge,d.pkgclss,d.shipcls,d.sabordno,d.shopid,d.ordnm,d.etcmsg,'' as mallcd, d.ordamt,d.prodcd,

			  d.optdesc,				 

			  concat(case when IFNULL(b.expbundcd,'') = "" then b.prodcdm 

			              else IFNULL(b.expbundcd,'') END ,"|", LEFT(d.orddt,10),"|",d.rcvnam,"|",d.addr,"|",d.clpno) AS expbundnm,

			  0 as boxcnt,ifnull(b.expfile,"기타") as expfile, ifnull(b.expcd,'') as expcd, ifnull(b.flagset,''), b.prodcdm, IFNULL(b.expinvqty,0) as expinvqty,

			  TRIM(ifnull(b.prodnm,'')) as prodnm,ifnull(b.specdes,'') as specdes,

			  
			  
			  d.qty as qty2,

			  concat(case when IFNULL(b.expbundcd,'') = "" then b.prodcdm 

			              else IFNULL(b.expbundcd,'') END ,"|", LEFT(d.orddt,10),"|",d.rcvnam,"|",d.addr,"|",d.clpno) as racknm,

			  b.optprodcd as optprodcd, ifnull(b.expinner,'') as expinner, ifnull(b.expcostnm,'') as expcostnm,

			  (SELECT ifnull(a.shopcd,'') FROM SHOPINFO a WHERE a.SHOPNM like CONCAT('%',trim(MID( shopid,1, CHAR_LENGTH(shopid)-INSTR(REVERSE(shopid),' ')+1 )),'%')  limit 1) AS shopcd,

			  0 as shopseq,

			  trim(MID( shopid, CHAR_LENGTH(shopid)-INSTR(REVERSE(shopid),' ')+1, 20)) AS shop_userid

	   FROM ORDDTL d

	   JOIN V_PRODUCTS b ON d.compno=b.compno  and d.brandcd = b.brandcd and d.prodcd=b.prodcd

	  WHERE d.compno = V_COMPNO	    

	  	 AND d.brandcd = V_BRANDCD

	    and d.orddt  = V_ORDDT

	    AND d.ordseq >= V_ORDSEQ

	    AND d.ordseq <= V_EORDSEQ

	    and d.ordamt <> 0

	    and d.asigndt is null

		ORDER BY expbundnm, d.ordseq*1000000+d.seq );

	

	alter table tmp modify expprodnm VARCHAR(1000) ;

		

	drop TEMPORARY TABLE if EXISTS tmp2;

	CREATE TEMPORARY TABLE IF NOT EXISTS tmp2 ENGINE=MEMORY AS (select * from tmp LIMIT 1);

	delete from tmp2;

	drop TEMPORARY TABLE if EXISTS tmp3;

	CREATE TEMPORARY TABLE IF NOT EXISTS tmp3 ENGINE=MEMORY AS (select * from tmp LIMIT 1);

	delete from tmp3;

	drop TEMPORARY TABLE if EXISTS tmp4;

	CREATE TEMPORARY TABLE IF NOT EXISTS tmp4 ENGINE=MEMORY AS (select * from tmp LIMIT 1);

	delete from tmp4;

	drop TEMPORARY TABLE if EXISTS tmp5;

	CREATE TEMPORARY TABLE IF NOT EXISTS tmp5 ENGINE=MEMORY AS (select * from tmp LIMIT 1);

	delete from tmp5;

	drop TEMPORARY TABLE if EXISTS tmp6;

	CREATE TEMPORARY TABLE IF NOT EXISTS tmp6 ENGINE=MEMORY AS (select * from tmp LIMIT 1);

	delete from tmp6;

	

	begin 

	   DECLARE _seq int;

		DECLARE _rorddt varchar(200);

		DECLARE _rcvnam varchar(200);

		DECLARE c_rcvnam varchar(200);

		DECLARE _pstno varchar(200);

		DECLARE _addr varchar(200);

		DECLARE _clpno varchar(200);

		DECLARE _telno varchar(200);

		DECLARE _qty int;

		DECLARE _qty2 int;

		DECLARE _shpfee bigint;

		DECLARE _credit varchar(200);

		DECLARE v_credit varchar(2000);

		DECLARE _optdesc varchar(200);

		DECLARE _messge varchar(200);

		DECLARE _pkgclss varchar(200);

		DECLARE _shipcls varchar(200);

		DECLARE _sabordno varchar(200);

		DECLARE _shopid varchar(200);

		DECLARE _ordnm varchar(200);

		DECLARE _etcmsg varchar(200);

		DECLARE _mallcd varchar(200);

		DECLARE _ordamt int;

		DECLARE _prodcd varchar(200); 

		DECLARE v_prodnm varchar(200);

		DECLARE v_prodcdm varchar(200);

		DECLARE _optprodcd varchar(20); 

		DECLARE v_optprodcd varchar(20);

		DECLARE _specdes varchar(200);

		DECLARE _expprodnm varchar(1000);

		DECLARE v_expprodnm varchar(1000);

		DECLARE _expbundnm varchar(200);

		DECLARE _racknm  varchar(200);

		DECLARE _boxcnt int;

		DECLARE _expfile varchar(200);

		DECLARE _expcd varchar(200);

		DECLARE _flagset varchar(200);

		DECLARE _prodcdm varchar(200);

		declare _expinvqty int;

		declare v_qty int;

		declare v_qty2 int;

		DECLARE _prodcdnm varchar(200);

		DECLARE _flagplus char(1);

		DECLARE _flagrack char(1);

		DECLARE _rackconts char(1);

		DECLARE _instrcnt char(1);

		DECLARE _setcnt int;

		DECLARE _levsetcnt int;

		DECLARE _expinner  char(1);

		DECLARE _expcostnm  char(1);

		DECLARE _shopcd varchar(20);

		DECLARE _shop_userid varchar(20);

		DECLARE v_expminbunqty int;

      DECLARE v_specdes varchar(200);

		DECLARE v_exists INT DEFAULT 0;

		DECLARE v_exists2 INT DEFAULT 0;

		DECLARE v_exists3 INT DEFAULT 0;

		DECLARE v_exists5 INT DEFAULT 0;

		DECLARE v_addr varchar(200);

		DECLARE v_cnt int;

		DECLARE v_rcvnam varchar(200);

		

		DECLARE v_existsexpsite INT DEFAULT 0;

		DECLARE _shopseq INT;

		

		DECLARE u_ordseq int;

		DECLARE u_seq int;

		

		Block1: BEGIN

			DECLARE done INT DEFAULT 0; 

	   	DECLARE c1 CURSOR FOR SELECT * FROM tmp;

	   	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;

	

	   	OPEN c1;

	   	REPEAT

			   FETCH c1 INTO _seq, _rorddt, _rcvnam, _pstno, _addr, _clpno, _telno, _qty,

							 _shpfee, _credit,  _expprodnm, _messge, _pkgclss, _shipcls, _sabordno, 

							 _shopid, _ordnm, _etcmsg, _mallcd, _ordamt, _prodcd, _optdesc,_expbundnm, 

							 _boxcnt, _expfile, _expcd, _flagset, _prodcdm, _expinvqty, v_prodnm, _specdes, _qty2,

							 _racknm,_optprodcd,_expinner,_expcostnm,_shopcd,_shopseq,_shop_userid;

			   IF not done THEN

					set v_exists = v_exists + 1;

					 

					if _shopid like "%롯데쇼핑%" then set v_credit ="선불"; 

					elseif left(_prodcd , 3) = "YYW" then set v_credit ="선불"; 

					elseif _credit ="" then set v_credit = "착불";

					elseif _credit like "%유료%" or _credit like "%무료%" or _credit like "%선결제%" then set v_credit ="선불"; 

					else set v_credit = _credit;

					end if;

					 

			   	if _expcd = "천일택배" or _expcd = "대신택배" then

					   if v_credit = "선불" then

							set v_credit ="현불"; 

						end if;

					end if;

					

					if _expcostnm = '1' then 

						set v_credit ="현불";

					end if;

					

					if ifnull(_shopcd,'') <> '' and ifnull(_shop_userid,'') <> '' then 

					   
						SELECT EXISTS(SELECT 1 FROM SHOPDTL WHERE compno=V_COMPNO  and shopcd = _shopcd and shoppingid=_shop_userid) INTO _shopseq;

						if ifnull(_shopseq,0) <> 0 then 

							set v_existsexpsite = 0;

							
							SELECT MIN(shopseq) into _shopseq FROM SHOPDTL WHERE compno=V_COMPNO  and shopcd = _shopcd and shoppingid=_shop_userid;

							SELECT EXISTS(SELECT 1 FROM EXPSITE WHERE COMPNO=V_COMPNO AND BRANDCD = V_BRANDCD AND PRODCD=_prodcdm AND shopcd = _shopcd and shopseq=_shopseq) INTO v_existsexpsite; 

							if v_existsexpsite <> 0 then 

								set v_credit ="착불";

							end if;

						end if;

					end if;

					

			   	set _instrcnt = '';

					SELECT ifnull(EXPOUTNM,'') into _instrcnt FROM EXPPRODMST WHERE COMPNO=V_COMPNO AND BRANDCD = V_BRANDCD AND PRODCD = _prodcdm;

			   	

			   	if ifnull(_instrcnt,'') = '1' then

						SET v_qty = _qty;

					elseif ifnull(_flagset,'') = '1' then

						set _setcnt = 0;

						set _levsetcnt = 0;

						set v_expminbunqty = 0;

						SELECT count(*) into _setcnt FROM PRODDTL WHERE COMPNO=V_COMPNO AND BRANDCD = V_BRANDCD AND prodcd=_prodcdm and ifnull(flagset,'')='1';

						SELECT count(*) into _levsetcnt FROM PRODDTL WHERE COMPNO=V_COMPNO AND BRANDCD = V_BRANDCD AND prodcd=_prodcdm and ifnull(levset,'')='2';

						SELECT expminbunqty into v_expminbunqty FROM EXPPRODMST where COMPNO=V_COMPNO AND BRANDCD = V_BRANDCD AND prodcd = _prodcdm;

						if ifnull(v_expminbunqty,0) = 9 then

							SET v_qty = _qty * _expinvqty;

						elseif ifnull(_levsetcnt,0) > 0 then

							set v_qty = _setcnt - 1;

						else

							SET v_qty = _setcnt;

						end if;

					else

						SET v_qty = _qty * _expinvqty;

					end if;

			   	

					SET v_exists2 = 0;

					select max(seq) into v_exists2 from tmp2  where expbundnm = _expbundnm;

					IF ifnull(v_exists2,0) > 0 THEN

						select expprodnm,prodcdm,qty,ifnull(optprodcd,'None') into v_expprodnm,v_prodcdm,v_qty2,v_optprodcd from tmp2 where seq = v_exists2;

						
						
						
						
						
						if ifnull(_flagset,'') = '1' and ifnull(v_expminbunqty,0) <> 9 then

							set _setcnt = 0;

							set _levsetcnt = 0;

							SELECT count(*) into _setcnt FROM PRODDTL WHERE COMPNO=V_COMPNO AND BRANDCD = V_BRANDCD AND prodcd=_prodcdm and ifnull(flagset,'')='1';

							SELECT count(*) into _levsetcnt FROM PRODDTL WHERE COMPNO=V_COMPNO AND BRANDCD = V_BRANDCD AND prodcd=_prodcdm and ifnull(levset,'')='2';

							
							if ifnull(_levsetcnt,0) > 0 then

								select ifnull(specdes,'') into v_specdes from PRODMST where COMPNO=V_COMPNO AND BRANDCD = V_BRANDCD AND prodcd=_prodcdm;

								set _expprodnm = concat(v_expprodnm,",",ifnull(v_specdes,''));

							   set _setcnt = _setcnt - 1;

							   update tmp2 set qty2=qty2+_qty2, qty = qty + ifnull(_setcnt,1), expprodnm=ifnull(_expprodnm,'') where seq = v_exists2;

							else

								if _prodcdm = v_prodcdm then

									set _expprodnm = concat(v_expprodnm,",",_specdes,"-",_qty,"개");

								else	

									set _expprodnm = concat(v_expprodnm,",",v_prodnm,"_",ifnull(_specdes,''),"-",_qty,"개");

								end if;

								update tmp2 set qty2=qty2+_qty2, qty = qty + ifnull(_setcnt,1), expprodnm=_expprodnm where seq = v_exists2;

							end if;

						else	

							
							if _prodcdm = v_prodcdm 	then

								set _expprodnm = concat(v_expprodnm,",",_specdes,"-",_qty,"개");

							else

								set _expprodnm = concat(v_expprodnm,",",v_prodnm,"_",ifnull(_specdes,''),"-",_qty,"개");

							end if;

							update tmp2 set qty2=qty2+_qty2, qty = qty + v_qty, expprodnm=_expprodnm where seq = v_exists2;				

						end if;

						

						SELECT FLOOR((_seq) / 1000000), MOD(_seq, 1000000) into u_ordseq, u_seq;

						update ORDDTL set moveseq=v_exists2 where compno=V_COMPNO and brandcd = V_BRANDCD and orddt=V_ORDDT and ordseq=u_ordseq and seq=u_seq;

						

						
					else

						insert into tmp2 values(_seq, _rorddt, _rcvnam, _pstno, _addr, _clpno, _telno, v_qty,

						 				_shpfee, v_credit, _expprodnm, _messge, _pkgclss, _shipcls, _sabordno, 

										_shopid, _ordnm, _etcmsg, _mallcd, _ordamt, _prodcd, _optdesc, _expbundnm, 

									    _boxcnt, _expfile, _expcd,_flagset, _prodcdm, _expinvqty, v_prodnm, _specdes,_qty2,

									    _racknm,_optprodcd,_expinner,_expcostnm,_shopcd,_shopseq,_shop_userid);

					END IF;

				END IF;

			UNTIL done END REPEAT;

		   CLOSE c1;

	   END Block1;

	   

	   
		Block2: BEGIN

	   		DECLARE done2 INT DEFAULT 0;

	   		DECLARE c2 CURSOR FOR SELECT * FROM tmp2;

		   	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done2 = 1;

		   	open c2;

			   REPEAT

			   	FETCH NEXT FROM c2 INTO _seq, _rorddt, _rcvnam, _pstno, _addr, _clpno, _telno, _qty,

						 _shpfee, _credit,  _expprodnm, _messge, _pkgclss, _shipcls, _sabordno, 

						 _shopid, _ordnm, _etcmsg, _mallcd, _ordamt, _prodcd, _optdesc,_expbundnm, 

						 _boxcnt, _expfile, _expcd, _flagset, _prodcdm, _expinvqty, v_prodnm, _specdes, _qty2,

						 _racknm, _optprodcd,_expinner,_expcostnm,_shopcd,_shopseq,_shop_userid;

					IF not done2 THEN

						set _instrcnt = '';

						SELECT ifnull(EXPOUTNM,'') into _instrcnt FROM EXPPRODMST WHERE COMPNO=V_COMPNO AND BRANDCD = V_BRANDCD AND PRODCD = _prodcdm;

						

						
						
						SELECT max(FLAGRACK) into _flagrack FROM EXPPRODMST WHERE COMPNO=V_COMPNO  AND BRANDCD = V_BRANDCD AND PRODCD = _prodcdm;

						set _racknm = concat(_rcvnam, "|", _addr, "|", ifnull(_flagrack,'') );

						

						set v_qty = 0;

						if ifnull(_instrcnt,'') = '1' then

							set v_qty = 0;

							SELECT sum(delivtabno) into v_qty FROM EXPORDQTYTAB WHERE COMPNO=V_COMPNO AND BRANDCD = V_BRANDCD AND prodcd = _prodcdm AND ordqty = _qty;

						else

							set v_qty = _qty;

						end if;

						insert into tmp3 values(_seq, _rorddt, _rcvnam, _pstno, _addr, _clpno, _telno, ifnull(v_qty,0),

					 				_shpfee, _credit, _expprodnm, _messge, _pkgclss, _shipcls, _sabordno, 

									_shopid, _ordnm, _etcmsg, _mallcd, _ordamt, _prodcd, _optdesc, _expbundnm, 

								    _boxcnt, _expfile, _expcd,_flagset, _prodcdm, _expinvqty, v_prodnm, _specdes,_qty2,

								    _racknm, _optprodcd,_expinner,_expcostnm,_shopcd,_shopseq,_shop_userid);

					END IF;

				UNTIL done2 END REPEAT;

				close c2;

		END Block2;

		

		
		Block3: BEGIN

	   		DECLARE done3 INT DEFAULT 0;

	   		DECLARE c3 CURSOR FOR SELECT * FROM tmp3 order by racknm;

		   	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done3 = 1;

		   	open c3;

			    REPEAT

			   	FETCH NEXT FROM c3 INTO _seq, _rorddt, _rcvnam, _pstno, _addr, _clpno, _telno, _qty,

						 _shpfee, _credit,  _expprodnm, _messge, _pkgclss, _shipcls, _sabordno, 

						 _shopid, _ordnm, _etcmsg, _mallcd, _ordamt, _prodcd, _optdesc,_expbundnm, 

						 _boxcnt, _expfile, _expcd, _flagset, _prodcdm, _expinvqty, v_prodnm, _specdes, _qty2, 

						 _racknm,_optprodcd,_expinner,_expcostnm,_shopcd,_shopseq,_shop_userid;

					IF not done3 THEN

						set _flagrack = '';

						set _rackconts = '';

						SELECT max(FLAGRACK),max(rackconts) into _flagrack,_rackconts FROM EXPPRODMST WHERE COMPNO=V_COMPNO AND BRANDCD = V_BRANDCD AND PRODCD = _prodcdm;

						IF ifnull(_flagrack,'')='1' and ifnull(_rackconts,'') <> '0' and _qty = 1 then

							set v_exists3 = 0;

							select max(seq) into v_exists3 from tmp4 where racknm = _racknm;

							IF ifnull(v_exists3,0) > 0 THEN

								set v_qty2 = 0;

								select sum(qty),max(expprodnm) into v_qty2,v_expprodnm from tmp4 where seq = v_exists3;

								if  ifnull(v_qty2,0) = 1 then 

									set _expprodnm = concat(v_expprodnm,",",v_prodnm,"_",ifnull(_specdes,''),"-",_qty2,"개");

									update tmp4 set qty2=qty2+_qty2, expprodnm=_expprodnm where seq = v_exists3;	

									

									SELECT FLOOR((_seq) / 1000000), MOD(_seq, 1000000) into u_ordseq, u_seq;

									update ORDDTL set moveseq=v_exists3 where compno=V_COMPNO and brandcd = V_BRANDCD and orddt=V_ORDDT and ordseq=u_ordseq and seq=u_seq;

									

									
								else 

									insert into tmp4 values(_seq, _rorddt, _rcvnam, _pstno, _addr, _clpno, _telno, _qty,

										_shpfee, _credit, _expprodnm, _messge, _pkgclss, _shipcls, _sabordno, 

										_shopid, _ordnm, _etcmsg, _mallcd, _ordamt, _prodcd, _optdesc, _expbundnm, 

									    _boxcnt, _expfile, _expcd,_flagset, _prodcdm, _expinvqty, v_prodnm, _specdes,_qty2,

									    _racknm, _optprodcd,_expinner,_expcostnm,_shopcd,_shopseq,_shop_userid);

								end if;

							else 

								insert into tmp4 values(_seq, _rorddt, _rcvnam, _pstno, _addr, _clpno, _telno, _qty,

										_shpfee, _credit, _expprodnm, _messge, _pkgclss, _shipcls, _sabordno, 

										_shopid, _ordnm, _etcmsg, _mallcd, _ordamt, _prodcd, _optdesc, _expbundnm, 

									    _boxcnt, _expfile, _expcd,_flagset, _prodcdm, _expinvqty, v_prodnm, _specdes,_qty2,

									    _racknm, _optprodcd,_expinner,_expcostnm,_shopcd,_shopseq,_shop_userid);

							end if;

						else  

							insert into tmp4 values(_seq, _rorddt, _rcvnam, _pstno, _addr, _clpno, _telno, _qty,

										_shpfee, _credit, _expprodnm, _messge, _pkgclss, _shipcls, _sabordno, 

										_shopid, _ordnm, _etcmsg, _mallcd, _ordamt, _prodcd, _optdesc, _expbundnm, 

									    _boxcnt, _expfile, _expcd,_flagset, _prodcdm, _expinvqty, v_prodnm, _specdes,_qty2,

									    _racknm, _optprodcd,_expinner,_expcostnm,_shopcd,_shopseq,_shop_userid);

						END if;

					END IF;

				UNTIL done3 END REPEAT;

				close c3;

		END Block3;

	   

	   
		Block4: BEGIN

	   		DECLARE done4 INT DEFAULT 0;

	   		DECLARE c4 CURSOR FOR SELECT * FROM tmp4 order by rcvnam, addr;

		   	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done4 = 1;

				set v_rcvnam = '';

				set v_addr = '';

				set v_cnt = 0;

		   	open c4;

			    REPEAT

			   	FETCH NEXT FROM c4 INTO _seq, _rorddt, _rcvnam, _pstno, _addr, _clpno, _telno, _qty,

						 _shpfee, _credit,  _expprodnm, _messge, _pkgclss, _shipcls, _sabordno, 

						 _shopid, _ordnm, _etcmsg, _mallcd, _ordamt, _prodcd, _optdesc,_expbundnm, 

						 _boxcnt, _expfile, _expcd, _flagset, _prodcdm, _expinvqty, v_prodnm, _specdes, _qty2, 

						 _racknm, _optprodcd,_expinner,_expcostnm,_shopcd,_shopseq,_shop_userid;

					IF not done4 THEN

						if _rcvnam = v_rcvnam then 

							if _addr <> v_addr then

								set v_cnt = v_cnt + 1;

								set c_rcvnam = concat( _rcvnam, "_", cast(v_cnt as char(2)) );

								set v_addr = _addr;

							end if;

						else 

							set v_rcvnam = _rcvnam;

							set v_addr = _addr;

							set v_cnt = 0;

							set c_rcvnam = _rcvnam;

						end if;

						insert into tmp5 values(_seq, _rorddt, c_rcvnam, _pstno, _addr, _clpno, _telno, _qty,

										_shpfee, _credit, _expprodnm, _messge, _pkgclss, _shipcls, _sabordno, 

										_shopid, _ordnm, _etcmsg, _mallcd, _ordamt, _prodcd, _optdesc, _expbundnm, 

									    _boxcnt, _expfile, _expcd,_flagset, _prodcdm, _expinvqty, v_prodnm, _specdes,_qty2,

									    _racknm, _optprodcd,_expinner,_expcostnm,_shopcd,_shopseq,_shop_userid); 

						

					END IF;

				UNTIL done4 END REPEAT;

				close c4;

		END Block4;

		

		
		Block5: BEGIN

	   		DECLARE done5 INT DEFAULT 0;

	   		DECLARE c5 CURSOR FOR SELECT * FROM tmp5 order by rcvnam, addr, expinner;

		   	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done5 = 1;

		   	open c5;

			    REPEAT

			   	FETCH NEXT FROM c5 INTO _seq, _rorddt, _rcvnam, _pstno, _addr, _clpno, _telno, _qty,

						 _shpfee, _credit,  _expprodnm, _messge, _pkgclss, _shipcls, _sabordno, 

						 _shopid, _ordnm, _etcmsg, _mallcd, _ordamt, _prodcd, _optdesc,_expbundnm, 

						 _boxcnt, _expfile, _expcd, _flagset, _prodcdm, _expinvqty, v_prodnm, _specdes, _qty2, 

						 _racknm, _optprodcd,_expinner,_expcostnm,_shopcd,_shopseq,_shop_userid;

					IF not done5 THEN

						if _expinner = '1' then

							set v_exists5 = 0;

							select min(seq), min(expprodnm) into v_exists5,v_expprodnm from tmp6 where rcvnam = _rcvnam and addr = _addr;

							
							IF ifnull(v_exists5,0) > 0 THEN

								set _expprodnm = concat(v_expprodnm,",",v_prodnm,"_",ifnull(_specdes,''),"-",_qty,"개");

								update tmp6 set qty2=qty2+_qty2, expprodnm=_expprodnm where seq = v_exists5;

								

								SELECT FLOOR((_seq) / 1000000), MOD(_seq, 1000000) into u_ordseq, u_seq;

								update ORDDTL set moveseq=v_exists5 where compno=V_COMPNO and brandcd = V_BRANDCD and orddt=V_ORDDT and ordseq=u_ordseq and seq=u_seq;

						

								
							else

								insert into tmp6 values(_seq, _rorddt, _rcvnam, _pstno, _addr, _clpno, _telno, _qty,

										_shpfee, _credit, _expprodnm, _messge, _pkgclss, _shipcls, _sabordno, 

										_shopid, _ordnm, _etcmsg, _mallcd, _ordamt, _prodcd, _optdesc, _expbundnm, 

									    _boxcnt, _expfile, _expcd,_flagset, _prodcdm, _expinvqty, v_prodnm, _specdes,_qty2,

									    _racknm, _optprodcd,_expinner,_expcostnm,_shopcd,_shopseq,_shop_userid);

							end if;

						else

							insert into tmp6 values(_seq, _rorddt, _rcvnam, _pstno, _addr, _clpno, _telno, _qty,

										_shpfee, _credit, _expprodnm, _messge, _pkgclss, _shipcls, _sabordno, 

										_shopid, _ordnm, _etcmsg, _mallcd, _ordamt, _prodcd, _optdesc, _expbundnm, 

									    _boxcnt, _expfile, _expcd,_flagset, _prodcdm, _expinvqty, v_prodnm, _specdes,_qty2,

									    _racknm, _optprodcd,_expinner,_expcostnm,_shopcd,_shopseq,_shop_userid);

						end if;

					END IF;

				UNTIL done5 END REPEAT;

				close c5;

		END Block5;

		

		
		Block6: BEGIN

			   DECLARE v_delivamt int DEFAULT 0;

	   		DECLARE done6 INT DEFAULT 0;

	   		DECLARE c6 CURSOR FOR SELECT a.seq, a.prodcdm, a.qty2

									FROM tmp6 a, EXPPRODMST b 

								   WHERE a.prodcdm=b.prodcd 

								     AND IFNULL(b.EXPTABLEFLAG,'')='2'

									 AND b.COMPNO=V_COMPNO

									 AND b.BRANDCD = V_BRANDCD ;

		   	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done6 = 1;

		   	open c6;

			    REPEAT

			   	FETCH NEXT FROM c6 INTO _seq, _prodcdm, _qty2;

					IF not done6 THEN

						set v_delivamt = 0;

						SELECT ifnull(delivamt,0) into v_delivamt FROM EXPCOST WHERE COMPNO=V_COMPNO AND BRANDCD = V_BRANDCD AND prodcd=_prodcdm AND TABNO =_qty2;

						update tmp6 set shpfee=v_delivamt where seq = _seq;

					END IF;

				UNTIL done6 END REPEAT;

				close c6;

		END Block6;		

			

		SELECT a.*,ifnull(b.neccd1,''),ifnull(b.neccd2,''),ifnull(b.neccd3,'')

		  FROM tmp6 a left join NECPRODMST b on b.compno=V_COMPNO AND b.BRANDCD = V_BRANDCD AND a.prodcdm=b.prodcd;

		

		
	end;

	

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_EXCEL_EXPPICUP_VER2` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_EXCEL_EXPPICUP_VER2`(

	IN `in_para` VARCHAR(200)

)
BEGIN

	DECLARE	start_pos		INT	DEFAULT	0;

	DECLARE	end_pos			INT	DEFAULT	0;

	DECLARE	cut_pos			INT	DEFAULT	0;

	DECLARE	cut_para			VARCHAR(200);

	

	DECLARE	safe_count		INT	DEFAULT	20;	# 20회 이상 반복 구간이 실행되는 것을 방지

	

	DECLARE	cut_compno		INT;

	DECLARE	cut_brandcd		INT;

	DECLARE	cut_orddt		VARCHAR(10);

	DECLARE	cut_ordseq		INT;

	DECLARE	cut_seq_from	INT;

	DECLARE	cut_seq_to		INT;

	

	DECLARE	first_proc		BOOLEAN	DEFAULT	TRUE;

	

	SET	start_pos	=	1;

	SET	end_pos		=	LENGTH(IN_para);

	

	# SET	tmp_table_size			=	1024	*	1024	*	1024	*	2;

	# SET	max_heap_table_size	=	1024	*	1024	*	1024	*	2;

	

	while	start_pos	<	end_pos	do

		SET	cut_pos	=	LOCATE(",", in_para, start_pos);

		

		if	cut_pos	=	0	then

			SET	cut_para		=	SUBSTRING(in_para, start_pos, end_pos);

			SET	start_pos	=	end_pos;

		else

			SET	cut_para		=	SUBSTRING(in_para, start_pos, cut_pos - start_pos);

			SET	start_pos	=	cut_pos	+	1;

		END	if;

		

		# 하나의 주문차수는 30 Byte

		if	LENGTH(cut_para)		=	30	then

			SET	cut_compno		=	CAST(SUBSTRING(cut_para, 1, 5)	AS	UNSIGNED);

			SET	cut_brandcd		=	CAST(SUBSTRING(cut_para, 6, 5)	AS	UNSIGNED);

			SET	cut_orddt		=	SUBSTRING(cut_para, 11, 8);

			SET	cut_ordseq		=	CAST(SUBSTRING(cut_para, 19, 2)	AS	UNSIGNED);

			SET	cut_seq_from	=	CAST(SUBSTRING(cut_para, 21, 5)	AS	UNSIGNED);

			SET	cut_seq_to		=	CAST(SUBSTRING(cut_para, 26, 5)	AS	UNSIGNED);

			

			# TO 순번이 0이면 99999을 강제로 넣어줘 순번 전체를 조회되게 처리

			if	cut_seq_to	=	0	then

				SET	cut_seq_to	=	99999;

			END	if;

			

			# ==========================================

			# 기존 SP(YWM_EXCEL_EXPPICUP) 붙여넣은 부분

			# ==========================================

			YWM_EXCEL_EXPPICUP_Block:	begin

				DROP	TEMPORARY	TABLE	if	EXISTS	TMP;

		

				# 주문상세(ORDDT)와 상품뷰(V_PRODMST) 

				# 주문수량택배번호(EXPORDQTYTAB)와 택배비용(EXPCOST)

				CREATE	TEMPORARY	TABLE	IF	NOT	EXISTS	TMP	ENGINE=MEMORY	AS

					(SELECT	CAST(SUBSTR(orddt, 7, 8) * 10000000 + ordseq * 1000000 + seq AS unsigned)	AS	seq,	LEFT(d.rorddt,10)	AS	rorddt,	d.rcvnam,	replace(d.pstno,'-','')	AS	pstno,	d.addr,	d.clpno,

								d.telno,d.qty,	 

								IFNULL((SELECT	delivamt	

											FROM	EXPORDQTYTAB	a,	EXPCOST	c

											WHERE	a.COMPNO			=	b.COMPNO

											AND	a.brandcd		=	b.brandcd	

											AND	a.prodcd			=	b.prodcdm	

											AND	a.ordqty			=	d.qty

											AND	a.COMPNO			=	c.COMPNO

											AND	a.brandcd		=	c.brandcd

											AND	a.PRODCD			=	c.prodcd

											AND	a.delivtabno	=	c.tabno), 0)	AS	shpfee,

								d.credit,	concat(ifnull(b.expkindnm,''), "◆", TRIM(ifnull(b.prodnm, '')),	TRIM(ifnull(b.specdes,'')), "-", d.qty, "개")	AS expprodnm,

								d.messge,	d.pkgclss,	ifnull(d.shipcls,'택배'),	d.sabordno,	d.shopid,	d.ordnm,	d.etcmsg,	''	AS	mallcd,	d.ordamt,	d.prodcd,

								d.optdesc,	concat(case when IFNULL(b.expbundcd,'') = "" then b.prodcdm else IFNULL(b.expbundcd,'') END ,

								"|",	LEFT(d.orddt,10),"|",d.rcvnam,"|",d.addr,"|",d.clpno)	AS	expbundnm,	0	AS	boxcnt,	ifnull(b.expfile,"기타")	AS expfile,

								ifnull(b.expcd,'')	AS	expcd,	ifnull(b.flagset,'') AS flagset,	b.prodcdm,	IFNULL(b.expinvqty,0)	AS	expinvqty,

								TRIM(ifnull(b.prodnm,''))	AS	prodnm,	ifnull(b.specdes,'')	AS	specdes,

								

								# 주문수량별 배송비 산출을 위해 주문수량 집계용 2019.09.04

								# 모든 update문에 기존 주문수량에 새로운 주문수량을 합산 하는(qty2=qty2+_qty2)계산식 추가함

								d.qty	AS	qty2,	

								

								concat(case when IFNULL(b.expbundcd,'')	=	""	then	b.prodcdm	ELSE	IFNULL(b.expbundcd,'')	END, "|", LEFT(d.orddt,10),"|",d.rcvnam,"|",d.addr,"|",d.clpno)	AS	racknm,

								b.optprodcd	AS	optprodcd,	ifnull(b.expinner,'')	AS	expinner,	ifnull(b.expcostnm,'')	AS	expcostnm,

								(SELECT	ifnull(a.shopcd,'')

								FROM		SHOPINFO	a	

								WHERE		a.SHOPNM	LIKE	CONCAT('%',trim(MID( shopid,1, CHAR_LENGTH(shopid)-INSTR(REVERSE(shopid),' ')+1 )),'%')  limit 1)	AS	shopcd,

								0	AS	shopseq,	trim(MID( shopid, CHAR_LENGTH(shopid)-INSTR(REVERSE(shopid),' ')+1, 20))	AS	shop_userid,

								d.orddt	AS	order_orddt,	d.ordseq	AS	order_ordseq,	d.seq	AS	order_seq,								# (2021.6.15) 주문상세의 주문일자, 차수, 순번을 사용하기 위해 추가

								ifnull(d.clmdt,'') AS orddtl_clmdt, d.clmseq AS orddtl_clmseq

					FROM		ORDDTL d	JOIN	V_PRODUCTS	b	

											ON		d.compno		=	b.compno

											AND	d.brandcd	=	b.brandcd

											AND	d.prodcd		=	b.prodcd

					WHERE		d.compno		=	cut_compno

					AND		d.brandcd	=	cut_brandcd

					AND		d.orddt		=	cut_orddt

					AND		d.ordseq		=	cut_ordseq

					AND		d.seq			>=	cut_seq_from

					AND		d.seq			<=	cut_seq_to

					AND		d.ordamt		<>	0

					AND		d.asigndt	IS	NULL

					AND		ifnull(b.flagpart, '')	<>	'1'							# (2021.6.15) 부품인 경우 제외

					ORDER	BY	expbundnm,	SUBSTR(orddt, 7, 8) * 10000000 + ordseq * 1000000 + seq);

				

				ALTER	TABLE	TMP	MODIFY	expprodnm	VARCHAR(1000);

					

				DROP	TEMPORARY	TABLE	if	EXISTS	TMP2;

				CREATE	TEMPORARY	TABLE	IF	NOT	EXISTS	TMP2	ENGINE=MEMORY	AS

					(SELECT	*

					FROM		TMP	LIMIT	1);

				DELETE	FROM	TMP2;

				

				DROP	TEMPORARY	TABLE	if	EXISTS	TMP3;

				CREATE	TEMPORARY	TABLE	IF	NOT	EXISTS	TMP3(INDEX index_tmp3(racknm))	ENGINE=MEMORY	AS	

					(SELECT	*	

					FROM		TMP	LIMIT	1);

				DELETE	FROM	TMP3;

				

				DROP	TEMPORARY	TABLE	if	EXISTS	TMP4;

				CREATE	TEMPORARY	TABLE	IF	NOT	EXISTS	TMP4(INDEX index_tmp4(rcvnam, addr))	ENGINE=MEMORY	AS

				(SELECT	*

				FROM		TMP	LIMIT	1);

				DELETE	FROM	TMP4;

				

				DROP	TEMPORARY	TABLE	if	EXISTS	TMP5;

				CREATE	TEMPORARY	TABLE	IF	NOT	EXISTS	TMP5(INDEX index_tmp5(rcvnam, addr, expinner))	ENGINE=MEMORY	AS

					(SELECT	*

					FROM		TMP	LIMIT	1);

				DELETE	FROM	TMP5;

				

				if	first_proc	then

					DROP	TEMPORARY	TABLE	if	EXISTS	TMP6;

					CREATE	TEMPORARY	TABLE	IF	NOT	EXISTS	TMP6	ENGINE=MEMORY	AS

					(SELECT	*

					FROM		TMP	LIMIT	1);

					DELETE	FROM	TMP6;

					

					# (2021.6.28) 묶음배송 이동후 번호 초기화(시작)

					# tmp5를 돌면서 ORDDTL 테이블의 묶음배송 이동후 번호를 초기화 시키는 부분이 있던 것을

					# 속도 문제로 한번에 초기화하는 것으로 수정함

					UPDATE	ORDDTL	

					SET		moveseq	=	0

					WHERE		compno	=	cut_compno

					AND		brandcd	=	cut_brandcd

					AND		orddt		=	cut_orddt

					AND		ordseq	=	cut_ordseq

					AND		seq		>=	cut_seq_from

					AND		seq		<=	cut_seq_to

					AND		ordamt	<>	0

					AND		asigndt	IS	NULL;

					# (2021.6.28) 묶음배송 이동후 번호 초기화(종료)

					

					SET	first_proc	=	FALSE;

				END	if;

	

				BEGIN

					DECLARE	_seq				INT;

					DECLARE	_rorddt			VARCHAR(200);

					DECLARE	_rcvnam			VARCHAR(200);

					DECLARE	c_rcvnam			VARCHAR(200);

					DECLARE	_pstno			VARCHAR(200);

					DECLARE	_addr				VARCHAR(200);

					DECLARE	_clpno			VARCHAR(200);

					DECLARE	_telno			VARCHAR(200);

					DECLARE	_qty				INT;

					DECLARE	_qty2				INT;

					DECLARE	_shpfee			BIGINT;

					DECLARE	_credit			VARCHAR(200);

					DECLARE	v_credit			VARCHAR(2000);

					DECLARE	_optdesc			VARCHAR(200);

					DECLARE	_messge			VARCHAR(200);

					DECLARE	_pkgclss			VARCHAR(200);

					DECLARE	_shipcls			VARCHAR(200);

					DECLARE	_sabordno		VARCHAR(200);

					DECLARE	_shopid			VARCHAR(200);

					DECLARE	_ordnm			VARCHAR(200);

					DECLARE	_etcmsg			VARCHAR(200);

					DECLARE	_mallcd			VARCHAR(200);

					DECLARE	_ordamt			INT;

					DECLARE	_prodcd			VARCHAR(200); 

					DECLARE	v_prodnm			VARCHAR(200);

					DECLARE	v_prodcdm		VARCHAR(200);

					DECLARE	_optprodcd		VARCHAR(20); 

					DECLARE	v_optprodcd		VARCHAR(20);

					DECLARE	_specdes			VARCHAR(200);

					DECLARE	_expprodnm		VARCHAR(1000);

					DECLARE	v_expprodnm		VARCHAR(1000);

					DECLARE	_expbundnm		VARCHAR(200);

					DECLARE	_racknm			VARCHAR(200);

					DECLARE	_boxcnt			INT;

					DECLARE	_expfile			VARCHAR(200);

					DECLARE	_expcd			VARCHAR(200);

					DECLARE	_flagset			VARCHAR(200);

					DECLARE	_prodcdm			VARCHAR(200);

					DECLARE	_expinvqty		INT;

					DECLARE	v_qty				INT;

					DECLARE	v_qty2			INT;

					DECLARE	_prodcdnm		VARCHAR(200);

					DECLARE	_flagplus		CHAR(1);

					DECLARE	_flagrack		CHAR(1);

					DECLARE	_rackconts		CHAR(1);

					DECLARE	_instrcnt		CHAR(1);

					DECLARE	_setcnt			INT;

					DECLARE	_levsetcnt		INT;

					DECLARE	_expinner		CHAR(1);

					DECLARE	_expcostnm		CHAR(1);

					DECLARE	_shopcd			VARCHAR(20);

					DECLARE	_shop_userid	VARCHAR(20);

					DECLARE	v_expminbunqty INT;

			      DECLARE	v_specdes		VARCHAR(200);

					DECLARE	v_exists			INT	DEFAULT	0;

					DECLARE	v_exists2		INT	DEFAULT	0;

					DECLARE	v_exists3		INT	DEFAULT	0;

					DECLARE	v_exists5		INT	DEFAULT	0;

					DECLARE	v_addr			VARCHAR(200);

					DECLARE	v_cnt				INT;

					DECLARE	v_rcvnam			VARCHAR(200);

					

					DECLARE	v_existsexpsite	INT	DEFAULT	0;

					DECLARE	_shopseq				INT;

					

					DECLARE	u_ordseq	INT;

					DECLARE	u_seq		INT;

					

					DECLARE	_order_orddt	VARCHAR(10);

					DECLARE	_order_ordseq	INT;

					DECLARE	_order_seq		INT;

					DECLARE	_delivery_type	VARCHAR(10);

					declare	sel_cnt			int;

					

					# (2021.7.14) 변수 추가

					declare	v_orddtl_clmdt		varchar(8)	default	'';

					declare	v_orddtl_clmseq	int			default	0;

					declare	_orddtl_clmdt		varchar(8)	default	'';

					declare	_orddtl_clmseq		int			default	0;

					declare	clmlist_expcd		varchar(50)	default	'';

					declare	clmlist_proctype	varchar(50)	default	'';

					DECLARE	clmlist_suppamt	int			default	0;

					DECLARE	clmlist_boxcnt	int			default	0;

					

					DECLARE	imsi_seq				int			default	0;

					# (2021.7.14) 변수 추가

					

					Block1: BEGIN

						DECLARE	done	INT	DEFAULT	0; 

				   	DECLARE	c1	CURSOR	FOR

							SELECT	*	FROM	TMP;

							

				   	DECLARE	CONTINUE	HANDLER	FOR	SQLSTATE	'02000'	SET	done	=	1;

				   	

				   	OPEN	c1;

						REPEAT

							FETCH	NEXT	FROM	c1	

							INTO	_seq,				_rorddt,			_rcvnam,		_pstno,		_addr,		_clpno,		_telno,			_qty,

									_shpfee,			_credit,			_expprodnm,	_messge,		_pkgclss,	_shipcls,	_sabordno,		_shopid,

									_ordnm,			_etcmsg,			_mallcd,		_ordamt,		_prodcd,		_optdesc,	_expbundnm,		_boxcnt,

									_expfile,		_expcd,			_flagset,	_prodcdm,	_expinvqty,	v_prodnm,	_specdes,		_qty2,

									_racknm,			_optprodcd,		_expinner,	_expcostnm,	_shopcd,		_shopseq,	_shop_userid,

									_order_orddt,	_order_ordseq,	_order_seq, _orddtl_clmdt, _orddtl_clmseq;

									

							IF	NOT	done	THEN

								SET	_delivery_type	=	"택배";

									

								# (2021.7.14) 무임건은 택배사를 '무임'으로 변경

								if	_order_ordseq	=	3	then

									set	sel_cnt	=	0;

									

									set	v_orddtl_clmdt		=	'';

									set	v_orddtl_clmseq		=	0;

									set	clmlist_expcd		=	'';

									set	clmlist_proctype	=	'';

									set	clmlist_suppamt	=	0;

									set	clmlist_boxcnt	   =	0;

									

									#select	max(clmdt),		max(clmseq)

									#into		orddtl_clmdt,	orddtl_clmseq

									#from		ORDDTL

									#where		compno	=	cut_compno

									#and		brandcd	=	cut_brandcd

									#and		orddt		=	_order_orddt

									#and		ordseq	=	_order_ordseq

									#and		seq		=	_order_seq;

									

									select	IFNULL(max(expcd), ''),		IFNULL(max(proctype), ''),	IFNULL(max(suppamt), 0), IFNULL(max(SUPPAKNM), 0)

									into		clmlist_expcd,					clmlist_proctype,				clmlist_suppamt, clmlist_boxcnt

									from		CLMLIST

									where		compno	=	cut_compno

									and		brandcd	=	cut_brandcd

									and		clmdt		=	_orddtl_clmdt

									and		clmseq	=	_orddtl_clmseq;

									

									# (20210901) 상담접수건인 경우 상담접수 시 등록한 택배비로 택배비 설정

									set		_shpfee	=	clmlist_suppamt;

									# (20220208) park 상담접수건인 경우 상담접수 시 등록한 box 설정

									set		_boxcnt	=	clmlist_boxcnt;

									

									# (202107.19) 상담접수/처리에 등록된 택배사로 할당될 수 있도록 처리 (시작)

									if			clmlist_expcd	=	'경동'	then

										set	_expfile	=	'경동택배';

									elseif	clmlist_expcd	=	'롯데'	then

										set	_expfile	=	'롯데택배';

									elseif	clmlist_expcd	=	'한진'	then

										set	_expfile	=	'한진택배';

									elseif	clmlist_expcd	=	'대신'	then

										set	_expfile	=	'합동택배';

										set	_expcd	=	'대신택배';

									elseif	clmlist_expcd	=	'천일'	then

										set	_expfile	=	'합동택배';

										set	_expcd	=	'천일택배';

									elseif	clmlist_expcd	=	''			then

										set	_expfile	=	'공용';

									end	if;

									# (202107.19) 상담접수/처리에 등록된 택배사로 할당될 수 있도록 처리 (끝)

									

									# DELFREEMST 테이블에 택배사와 처리유형이

									# 입력되어 있으면 무임으로 처리

									select	COUNT(*)

									into		sel_cnt

									FROM		DELFREEMST

									WHERE		compno		=	cut_compno

									AND		brandcd		=	cut_brandcd

									AND		expcd			=	clmlist_expcd

									AND		proctypecd	=	clmlist_proctype;

									

									if	sel_cnt	>=	1	then

										set	_expfile	=	'무임';

									end	if;

									

									# (2021.08.09) 배송방법이 '직송'인 경우 '택배사를 '공용'으로 변경

									SELECT	IFNULL(max(deliverytype), '택배')

									INTO		_delivery_type

									FROM		PROCTYPE

									WHERE		compno		=	cut_compno

									AND		brandcd		=	cut_brandcd

									AND		proctypecd	=	clmlist_proctype;

									

									if	_delivery_type	=	'직송'	then

										set	_expfile	=	'공용';

									end	if;

								end	if;

								# (2021.7.14) 무임건은 택배사를 '공용'으로 변경

							

								if	_delivery_type	=	"택배"	or	_delivery_type	=	"직송"	then

									SET	v_exists	=	v_exists	+	1;

									 

									if			_shopid	LIKE	"%롯데쇼핑%"	then	SET	v_credit	=	"선불";

									ELSEIF	left(_prodcd , 3)	=	"YYW"	then	SET	v_credit =	"선불"; 

									ELSEIF	_credit	=		""				then	SET	v_credit	=	"착불";

									ELSEIF	_credit	LIKE	"%유료%"		or

												_credit	LIKE	"%무료%"		or

												_credit	LIKE	"%선결제%"	then	SET	v_credit	=	"선불"; 

									ELSE	SET	v_credit	=	_credit;

									END	if;

									 

							   	if	_expcd	=	"천일택배"	OR 	_expcd = "대신택배" then

									   if v_credit = "선불" then

											set v_credit ="현불"; 

										end if;

									end if;

									

									if _expcostnm = '1' then 

										set v_credit ="현불";

									end if;

									

									#----------

									# 설명 필요

									#----------

									if	ifnull(_shopcd,'')	<>	''	AND	ifnull(_shop_userid,'')	<>	''	then 

									   #SELECT _shopcd,_shop_userid;

										SELECT	EXISTS(SELECT	1	

															FROM	SHOPDTL

															WHERE	compno		=	cut_compno

															AND	shopcd		=	_shopcd

															AND	shoppingid	=	_shop_userid)

										INTO		_shopseq;

															

										if	ifnull(_shopseq, 0)	<>	0	then 

											SET	v_existsexpsite	=	0;

											

											#SELECT _shopcd,_shop_userid;

											SELECT	MIN(shopseq)	

											INTO		_shopseq

											FROM		SHOPDTL

											WHERE		compno		=	cut_compno

											AND		shopcd		=	_shopcd

											AND		shoppingid	=	_shop_userid;

											

											SELECT	EXISTS(SELECT	1

																FROM	EXPSITE

																WHERE	COMPNO	=	cut_compno

																AND	BRANDCD	=	cut_brandcd

																AND	PRODCD	=	_prodcdm

																AND	shopcd	=	_shopcd

																AND	shopseq	=	_shopseq)

											INTO		v_existsexpsite; 

																

											if	v_existsexpsite	<>	0	then 

												SET	v_credit	=	"착불";

											END	if;

										END	if;

									END	if;

									

							   	SET	_instrcnt	=	'';

							   	

							   	# 택배정보(EXPPRODMST)의 주문수량별택배테이블적용여부(1, EXPOUTNM)

									SELECT	ifnull(EXPOUTNM, '')

									INTO		_instrcnt

									FROM		EXPPRODMST

									WHERE		COMPNO	=	cut_compno

									AND		BRANDCD	=	cut_brandcd

									AND		PRODCD	=	_prodcdm;

							   	

							   	# 상담접수건은 별도처리 2022-02-10 park

							   	if	_order_ordseq	=	3	then

										SET	v_qty	=	_boxcnt;

							   	ELSEif	ifnull(_instrcnt, '')	=	'1'	then

										SET	v_qty	=	_qty;

									ELSEIF	ifnull(_flagset,'')		=	'1'	then

										SET	_setcnt			=	0;

										SET	_levsetcnt		=	0;

										SET	v_expminbunqty	=	0;

										

										# 세트여부(PRODDTL.FLAGSET)(1)

										SELECT	COUNT(*)	

										INTO		_setcnt

										FROM		PRODDTL

										WHERE		COMPNO	=	cut_compno

										AND		BRANDCD	=	cut_brandcd

										AND		prodcd	=	_prodcdm

										AND		ifnull(flagset,'')	=	'1';

										

										# 세트레벨(PRODDTL.LEVSET)

										SELECT	count(*)

										INTO		_levsetcnt

										FROM		PRODDTL

										WHERE		COMPNO	=	cut_compno

										AND		BRANDCD	=	cut_brandcd

										AND		prodcd	=	_prodcdm

										AND		ifnull(levset,'')	=	'2';

										

										# 합동택배 이관 최소 수량(EXPPRODMST.EXPMINBUNQTY)

										SELECT	expminbunqty

										INTO		v_expminbunqty

										FROM		EXPPRODMST

										WHERE		COMPNO	=	cut_compno

										AND		BRANDCD	=	cut_brandcd

										AND		prodcd	=	_prodcdm;

										

										if			ifnull(v_expminbunqty, 0)	=	9	then

											SET	v_qty	=	_qty		*	_expinvqty;

										ELSEIF	ifnull(_levsetcnt, 0)		>	0	then

											SET	v_qty	=	_setcnt	-	1;

										else

											SET	v_qty	=	_setcnt;

										END	if;

									ELSE

										SET	v_qty	=	_qty	* _expinvqty;

									END	if;

							   	

									SET	v_exists2	=	0;

									

									SELECT	max(seq)	

									INTO		v_exists2

									FROM		TMP2

									WHERE		expbundnm	=	_expbundnm;

									

									IF	ifnull(v_exists2, 0)	>	0	THEN

										SELECT expprodnm,prodcdm,qty,ifnull(optprodcd,'None'),orddtl_clmdt,orddtl_clmseq

										  INTO v_expprodnm,v_prodcdm,v_qty2,v_optprodcd,v_orddtl_clmdt,v_orddtl_clmseq

										  FROM TMP2

										 WHERE seq = v_exists2;

										

										# 합배송대상이면서 상담번호가 같으면 

										# 2022-03-04 park 상담상품은 묶는과정에서 수량이 합해지는것 방지

										if _order_ordseq = 3 and _orddtl_clmdt=v_orddtl_clmdt and _orddtl_clmseq=v_orddtl_clmseq then

											set v_qty = 0;

										end if;

										#

										# 세트 상품이면서 

										# 송장수량변경 : 배송관리의 '합동택배이관최소수량' 이 '9' 이면 Rule 1. or Rule 2 로 변경 적용

										#                (즉 특정상품 이면 배송관리의 '주문수량별 택배테이블'의 '주문수량' 에 해당 하는 '테이블번호' 아니면 배송관리의 

										#                 송장수량' * 주문수량 )

										#

										#if	ifnull(_flagset, '')	=	'1'	AND	ifnull(v_expminbunqty, 0)	<>	9	then

										if _order_ordseq	<>	3 and ifnull(_flagset, '')	=	'1' AND ifnull(v_expminbunqty, 0) <> 9	then

											SET	_setcnt		=	0;

											SET	_levsetcnt	=	0;

											

											# 세트여부(PRODDTL.FLAGSET)

											SELECT	count(*)

											INTO		_setcnt

											FROM		PRODDTL

											WHERE		COMPNO	=	cut_compno

											AND		BRANDCD	=	cut_brandcd

											AND		prodcd	=	_prodcdm

											AND		ifnull(flagset, '')	=	'1';

											

											# 세트레벨(PRODDTL.LEVSET)

											SELECT	count(*)

											INTO		_levsetcnt

											FROM		PRODDTL

											WHERE		COMPNO	=	cut_compno

											AND		BRANDCD	=	cut_brandcd

											AND		prodcd	=	_prodcdm

											AND		ifnull(levset,'')	=	'2';

											

											#주문수량별 택배테이블 적용시  

											if	ifnull(_levsetcnt, 0)	>	0	then

												# 규격(PRODMST.SPECDES)

												SELECT	ifnull(specdes, '')

												INTO		v_specdes

												FROM		PRODMST

												WHERE		COMPNO	=	cut_compno

												AND		BRANDCD	=	cut_brandcd

												AND		prodcd	=	_prodcdm;

												

												SET	_expprodnm	=	concat(v_expprodnm, ",", ifnull(v_specdes,''));

											   SET	_setcnt		=	_setcnt	-	1;

											   

											   UPDATE	TMP2

												SET		qty2			=	qty2	+	_qty2,

															qty			=	qty	+	ifnull(_setcnt, 1),

															expprodnm	=	ifnull(_expprodnm, '')

												WHERE		seq			=	v_exists2;

											ELSE

												if	_prodcdm	=	v_prodcdm	then

													SET	_expprodnm	=	concat(v_expprodnm,",",_specdes,"-",_qty,"개");

												else	

													SET	_expprodnm	=	concat(v_expprodnm, ",", v_prodnm, "_", ifnull(_specdes,''), "-", _qty, "개");

												end if;

												

												UPDATE	TMP2

												SET		qty2			=	qty2	+	_qty2,

															qty			=	qty	+	ifnull(_setcnt, 1),

															expprodnm	=	_expprodnm

												WHERE		seq			=	v_exists2;

											end if;

										else	

											# 대표상품, 옵션상품코드 같은 경우 동일상품이므로 칼라/사이즈만 찍는다 

											if	_prodcdm	=	v_prodcdm	then

												SET	_expprodnm	=	concat(v_expprodnm, ",", _specdes, "-", _qty, "개");

											else

												SET	_expprodnm	=	concat(v_expprodnm, ",", v_prodnm, "_", ifnull(_specdes, ''), "-", _qty, "개");

											end if;

											

											UPDATE	TMP2

											SET		qty2			=	qty2	+	_qty2,

														qty			=	qty	+	v_qty,

														expprodnm	=	_expprodnm

											WHERE		seq			=	v_exists2;				

										end if;

										

										# (2021.9.17) 수정 (시작)

										set	imsi_seq	=	_seq	-	(SUBSTR(cut_orddt, 7, 8) * 10000000);

										# (2021.9.17) 수정 (끝)

										

										# (2021.9.17) (우측 코드를 아래로 수정) SELECT	FLOOR((_seq) / 1000000),	MOD(_seq, 1000000)

										SELECT	FLOOR((imsi_seq) / 1000000),	MOD(imsi_seq, 1000000)

										INTO		u_ordseq,							u_seq;

										

										UPDATE	ORDDTL

										SET		moveseq	=	v_exists2

										WHERE		compno	=	cut_compno

										AND		brandcd	=	cut_brandcd

										AND		orddt		=	cut_orddt

										AND		ordseq	=	u_ordseq

										AND		seq		=	u_seq;

									ELSE

										INSERT	INTO	TMP2

										VALUES	(_seq,			_rorddt,			_rcvnam,		_pstno,		_addr,		_clpno,		_telno,			v_qty,

										 			_shpfee,			v_credit,		_expprodnm,	_messge,		_pkgclss,	_shipcls,	_sabordno,		_shopid,

													_ordnm,			_etcmsg,			_mallcd,		_ordamt,		_prodcd,		_optdesc,	_expbundnm,		_boxcnt,

													_expfile,		_expcd,			_flagset,	_prodcdm,	_expinvqty,	v_prodnm,	_specdes,		_qty2,

													_racknm,			_optprodcd,		_expinner,	_expcostnm,	_shopcd,		_shopseq,	_shop_userid,

													_order_orddt,	_order_ordseq,	_order_seq, _orddtl_clmdt, _orddtl_clmseq);

									END	IF;

								END	if;

							END	IF;

						UNTIL	done	END	REPEAT;

						

					   CLOSE	c1;

				   END	Block1;

				   

				   #배송관리-> "주문수량테이블 적용여부"에 체크된 상품들의 경우 출고수량(box)를 테이블에 맞게 변경함 

					Block2: BEGIN

				   	DECLARE	done2	INT	DEFAULT	0;

				   		

				   	DECLARE	c2	CURSOR	FOR

							SELECT	*	

							FROM		TMP2;

							

					   DECLARE	CONTINUE	HANDLER	FOR	SQLSTATE	'02000'	SET	done2	=	1;

					   

					   OPEN	c2;

					   	

						REPEAT

							FETCH	NEXT	FROM	c2

							INTO	_seq,				_rorddt,			_rcvnam,		_pstno,		_addr,		_clpno,		_telno, 			_qty,

									_shpfee,			_credit,			_expprodnm,	_messge,		_pkgclss,	_shipcls,	_sabordno,		_shopid,

									_ordnm,			_etcmsg,			_mallcd,		_ordamt, 	_prodcd,		_optdesc,	_expbundnm, 	_boxcnt,	

									_expfile,		_expcd,			_flagset,	_prodcdm,	_expinvqty,	v_prodnm,	_specdes, 		_qty2,

									_racknm,			_optprodcd,		_expinner,	_expcostnm,	_shopcd,		_shopseq,	_shop_userid,

									_order_orddt,	_order_ordseq,	_order_seq, _orddtl_clmdt, _orddtl_clmseq;

										

							IF	NOT	done2	THEN

								SET	_instrcnt	=	'';

								

								# 택배정보(EXPPRODMST)의 주문수량별택배테이블적용여부(1)(EXPOUTNM)

								SELECT	ifnull(EXPOUTNM, '')	

								INTO		_instrcnt

								FROM		EXPPRODMST

								WHERE		COMPNO	=	cut_compno

								AND		BRANDCD	=	cut_brandcd

								AND		PRODCD	=	_prodcdm;

									

								# 택배정보(EXPPRODMST)의 랙제품 유무(FLAGRACK)

								#랙제품 준비 

								#이름+주소+랙제품 유무 통합 항목 만들기  

								SELECT	max(FLAGRACK)

								INTO		_flagrack

								FROM		EXPPRODMST

								WHERE		COMPNO	=	cut_compno

								AND		BRANDCD	=	cut_brandcd

								AND		PRODCD	=	_prodcdm;

									

								SET	_racknm	=	concat(_rcvnam, "|", _addr, "|", ifnull(_flagrack,'') );

									

								SET	v_qty	=	0;

								

								# 상담접수건은 별도처리 2022-02-10 park

							   if	_order_ordseq	=	3	then

									SET	v_qty	=	_qty;

								elseif	ifnull(_instrcnt, '')	=	'1'	then

									SET	v_qty	=	0;

									SELECT	sum(delivtabno)

									INTO		v_qty

									FROM		EXPORDQTYTAB

									WHERE		COMPNO	=	cut_compno

									AND		BRANDCD	=	cut_brandcd

									AND		prodcd	=	_prodcdm

									AND		ordqty	=	_qty;

								else

									SET	v_qty	=	_qty;

								END	if;

									

								INSERT	INTO	TMP3

								VALUES	(_seq,			_rorddt,			_rcvnam,		_pstno,		_addr,		_clpno,		_telno,			ifnull(v_qty,0),

							 				_shpfee,			_credit,			_expprodnm,	_messge,		_pkgclss,	_shipcls,	_sabordno,		_shopid, 

											_ordnm,			_etcmsg,			_mallcd,		_ordamt,		_prodcd,		_optdesc,	_expbundnm, 	_boxcnt, 

											_expfile,		_expcd,			_flagset,	_prodcdm,	_expinvqty,	v_prodnm,	_specdes,		_qty2,

											_racknm,			_optprodcd,		_expinner,	_expcostnm,	_shopcd,		_shopseq,	_shop_userid,

											_order_orddt,	_order_ordseq,	_order_seq, _orddtl_clmdt, _orddtl_clmseq);

							END	IF;

						UNTIL	done2	END	REPEAT;

						

						close c2;

					END	Block2;

					

					#랙 제품중 본품이 1개 인경우 포함배송(선반,기타) 처리함 

					Block3:	BEGIN

						DECLARE	done3	INT	DEFAULT	0;

				   	DECLARE	c3	CURSOR	FOR

							SELECT	*

							FROM		TMP3

							ORDER	BY	racknm;

											

					   DECLARE	CONTINUE	HANDLER	FOR	SQLSTATE	'02000'	SET	done3	=	1;

					   

					   OPEN	c3;

					   	

						REPEAT

						  	FETCH	NEXT	FROM	c3

							INTO	_seq,				_rorddt,			_rcvnam,		_pstno,		_addr,		_clpno,		_telno,			_qty,

									_shpfee,			_credit,			_expprodnm,	_messge,		_pkgclss,	_shipcls,	_sabordno,		_shopid,

									_ordnm,			_etcmsg,			_mallcd,		_ordamt,		_prodcd,		_optdesc,	_expbundnm, 	_boxcnt,

									_expfile,		_expcd,			_flagset,	_prodcdm,	_expinvqty,	v_prodnm,	_specdes,		_qty2, 

									_racknm,			_optprodcd,		_expinner,	_expcostnm,	_shopcd,		_shopseq,	_shop_userid,

									_order_orddt,	_order_ordseq,	_order_seq, _orddtl_clmdt, _orddtl_clmseq;

										

							IF	NOT	done3	THEN

								SET	_flagrack	=	'';

								SET	_rackconts	=	'';

									

								SELECT	max(FLAGRACK),	max(rackconts)

								INTO		_flagrack,		_rackconts

								FROM		EXPPRODMST

								WHERE		COMPNO	=	cut_compno

								AND		BRANDCD	=	cut_brandcd

								AND		PRODCD	=	_prodcdm;

								

								IF	ifnull(_flagrack,'')		=	'1'	AND	

									ifnull(_rackconts,'')	<>	'0'	and 

									_qty							=	1		then

									SET	v_exists3	=	0;

										

									SELECT	max(seq)

									INTO		v_exists3

									FROM		TMP4

									WHERE		racknm	=	_racknm;

										

									IF	ifnull(v_exists3,0)	>	0	THEN

										SET	v_qty2	=	0;

											

										SELECT	sum(qty),	max(expprodnm)

										INTO		v_qty2,		v_expprodnm

										FROM		TMP4

										WHERE		seq	=	v_exists3;

											

										if	ifnull(v_qty2, 0)	=	1	then 

											SET	_expprodnm	=	concat(v_expprodnm, ",", v_prodnm, "_", ifnull(_specdes,''), "-", _qty2, "개");

												

											UPDATE	TMP4

											SET		qty2			=	qty2	+	_qty2, 

														expprodnm	=	_expprodnm

											WHERE		seq			=	v_exists3;	

												

											# (2021.9.17) 수정 (시작)

											set	imsi_seq	=	_seq	-	(SUBSTR(cut_orddt, 7, 8) * 10000000);

											# (2021.9.17) 수정 (끝)

										

											# (2021.9.17) (우측 코드를 아래로 수정) SELECT	FLOOR((_seq) / 1000000),	MOD(_seq, 1000000)

											SELECT	FLOOR((imsi_seq) / 1000000),	MOD(imsi_seq, 1000000)

											INTO		u_ordseq,							u_seq;

												

											UPDATE	ORDDTL	

											SET		moveseq	=	v_exists3

											WHERE		compno	=	cut_compno

											AND		brandcd	=	cut_brandcd

											AND		orddt		=	cut_orddt

											AND		ordseq	=	u_ordseq

											AND		seq		=	u_seq;

										else 

											INSERT	INTO	TMP4

											VALUES	(_seq,			_rorddt,			_rcvnam,		_pstno,		_addr,		_clpno,		_telno,			_qty,

														_shpfee,			_credit,			_expprodnm,	_messge,		_pkgclss,	_shipcls,	_sabordno,		_shopid,

														_ordnm,			_etcmsg,			_mallcd,		_ordamt,		_prodcd,		_optdesc,	_expbundnm, 	_boxcnt,

														_expfile,		_expcd,			_flagset,	_prodcdm,	_expinvqty,	v_prodnm,	_specdes,		_qty2,

														_racknm,			_optprodcd,		_expinner,	_expcostnm,	_shopcd,		_shopseq,	_shop_userid,

														_order_orddt,	_order_ordseq,	_order_seq, _orddtl_clmdt, _orddtl_clmseq);

										END	if;

									else 

										INSERT	INTO	TMP4

										VALUES	(_seq,			_rorddt,			_rcvnam,		_pstno,		_addr,		_clpno,		_telno,			_qty,

													_shpfee,			_credit,			_expprodnm,	_messge,		_pkgclss,	_shipcls,	_sabordno,		_shopid,

													_ordnm,			_etcmsg,			_mallcd,		_ordamt,		_prodcd,		_optdesc,	_expbundnm, 	_boxcnt,

													_expfile,		_expcd,			_flagset,	_prodcdm,	_expinvqty,	v_prodnm,	_specdes,		_qty2,

													_racknm,			_optprodcd,		_expinner,	_expcostnm,	_shopcd,		_shopseq,	_shop_userid,

													_order_orddt,	_order_ordseq,	_order_seq, _orddtl_clmdt, _orddtl_clmseq);

									END	if;

								else  

									INSERT	INTO	TMP4

									VALUES	(_seq,			_rorddt,			_rcvnam,		_pstno,		_addr,		_clpno,		_telno,			_qty,

												_shpfee,			_credit,			_expprodnm,	_messge,		_pkgclss,	_shipcls,	_sabordno,		_shopid, 

												_ordnm,			_etcmsg,			_mallcd,		_ordamt,		_prodcd,		_optdesc,	_expbundnm, 	_boxcnt, 

												_expfile,		_expcd,			_flagset,	_prodcdm,	_expinvqty,	v_prodnm,	_specdes,		_qty2,

												_racknm,			_optprodcd,		_expinner,	_expcostnm,	_shopcd,		_shopseq,	_shop_userid,

												_order_orddt,	_order_ordseq,	_order_seq, _orddtl_clmdt, _orddtl_clmseq);

								END	if;

							END	IF;

						UNTIL	done3	END	REPEAT;

							

						close	c3;

					END	Block3;

				   

					#동명 2인 의 이름에 유일성 부여

					Block4: BEGIN

						DECLARE	done4	INT	DEFAULT	0;

				   		

				   	DECLARE	c4	CURSOR	FOR

							SELECT	*

							FROM		TMP4

										ORDER	BY	rcvnam, addr;

											

					   DECLARE	CONTINUE	HANDLER	FOR	SQLSTATE	'02000'	SET	done4	=	1;

					   	

						SET	v_rcvnam	=	'';

						SET	v_addr	=	'';

						SET	v_cnt		=	0;

							

						OPEN	c4;

							

						REPEAT

							FETCH	NEXT	FROM	c4

							INTO	_seq,				_rorddt,			_rcvnam,		_pstno,		_addr,		_clpno,		_telno,			_qty,

									_shpfee,			_credit,			_expprodnm,	_messge,		_pkgclss,	_shipcls,	_sabordno,		_shopid,

									_ordnm,			_etcmsg,			_mallcd,		_ordamt,		_prodcd,		_optdesc,	_expbundnm,		_boxcnt,

									_expfile,		_expcd,			_flagset,	_prodcdm,	_expinvqty,	v_prodnm,	_specdes,		_qty2, 

									_racknm,			_optprodcd,		_expinner,	_expcostnm,	_shopcd,		_shopseq,	_shop_userid,

									_order_orddt,	_order_ordseq,	_order_seq, _orddtl_clmdt, _orddtl_clmseq;

										

							IF	NOT	done4	THEN

								if	_rcvnam	=	v_rcvnam	then 

									if	_addr	<>	v_addr	then

										SET	v_cnt		=	v_cnt	+	1;

										SET	c_rcvnam	=	concat( _rcvnam, "_", cast(v_cnt as char(2)) );

										SET	v_addr	=	_addr;

									END	if;

								else 

									SET	v_rcvnam	=	_rcvnam;

									SET	v_addr	=	_addr;

									SET	v_cnt		=	0;

									SET	c_rcvnam	=	_rcvnam;

								END	if;

									

								INSERT	INTO	TMP5

								VALUES	(_seq,			_rorddt,			c_rcvnam,	_pstno,		_addr,		_clpno,		_telno,			_qty,

											_shpfee,			_credit,			_expprodnm,	_messge,		_pkgclss,	_shipcls,	_sabordno,		_shopid, 

											_ordnm,			_etcmsg,			_mallcd,		_ordamt,		_prodcd,		_optdesc,	_expbundnm,		_boxcnt, 

											_expfile,		_expcd,			_flagset,	_prodcdm,	_expinvqty,	v_prodnm,	_specdes,		_qty2,

											_racknm,			_optprodcd,		_expinner,	_expcostnm,	_shopcd,		_shopseq,	_shop_userid,

											_order_orddt,	_order_ordseq,	_order_seq, _orddtl_clmdt, _orddtl_clmseq);

							END	IF;

						UNTIL	done4	END	REPEAT;

						

						close	c4;

					END	Block4;

					

					# 타제품과 포함배송 여부가 있는 상품 처리

					Block5:	BEGIN

						DECLARE	done5	INT	DEFAULT	0;

						

						DECLARE	c5	CURSOR	FOR

							SELECT	*	

							FROM		TMP5

										ORDER	BY	rcvnam,	addr,	expinner;

										

						DECLARE	CONTINUE	HANDLER	FOR	SQLSTATE	'02000'	SET	done5	=	1;

						

					   OPEN	c5;

					   

						REPEAT

							FETCH	NEXT	FROM	c5

							INTO	_seq,				_rorddt,			_rcvnam,		_pstno,		_addr,		_clpno,		_telno,			_qty,

									_shpfee,			_credit,			_expprodnm,	_messge,		_pkgclss,	_shipcls,	_sabordno,		_shopid,

									_ordnm,			_etcmsg,			_mallcd,		_ordamt,		_prodcd,		_optdesc,	_expbundnm,		_boxcnt,

									_expfile,		_expcd,			_flagset,	_prodcdm,	_expinvqty,	v_prodnm,	_specdes,		_qty2, 

									_racknm,			_optprodcd,		_expinner,	_expcostnm,	_shopcd,		_shopseq,	_shop_userid,

									_order_orddt,	_order_ordseq,	_order_seq, _orddtl_clmdt, _orddtl_clmseq;

									

							IF	NOT	done5	THEN

								if	_expinner	=	'1'	then

									SET	v_exists5	=	0;

										

									SELECT	min(seq),	min(expprodnm)

									INTO		v_exists5,	v_expprodnm

									FROM		TMP6

									WHERE		rcvnam	=	_rcvnam

									AND		addr		=	_addr;

										

									#select concat("step1=",v_exists5);

									IF	ifnull(v_exists5, 0)	>	0	THEN

										SET	_expprodnm	=	concat(v_expprodnm, ",", v_prodnm, "_", ifnull(_specdes,''), "-", _qty, "개");

											

										UPDATE	TMP6

										SET		qty2			=	qty2	+	_qty2,

													expprodnm	=	_expprodnm

										WHERE		seq			=	v_exists5;

											

										# (2021.9.17) 수정 (시작)

										set	imsi_seq	=	_seq	-	(SUBSTR(cut_orddt, 7, 8) * 10000000);

										# (2021.9.17) 수정 (끝)

										

										# (2021.9.17) (우측 코드를 아래로 수정) SELECT	FLOOR((_seq) / 1000000),	MOD(_seq, 1000000)

										SELECT	FLOOR((imsi_seq) / 1000000),	MOD(imsi_seq, 1000000)

										INTO		u_ordseq,							u_seq;

											

										UPDATE	ORDDTL	

										SET		moveseq	=	v_exists5

										WHERE		compno	=	cut_compno

										AND		brandcd	=	cut_brandcd

										AND		orddt		=	cut_orddt

										AND		ordseq	=	u_ordseq

										AND		seq		=	u_seq;

									else

										INSERT	INTO	TMP6

										VALUES	(_seq,			_rorddt,			_rcvnam,		_pstno,		_addr,		_clpno,		_telno,			_qty,

													_shpfee,			_credit,			_expprodnm,	_messge,		_pkgclss,	_shipcls,	_sabordno,		_shopid,

													_ordnm,			_etcmsg,			_mallcd,		_ordamt,		_prodcd,		_optdesc,	_expbundnm,		_boxcnt,

													_expfile,		_expcd,			_flagset,	_prodcdm,	_expinvqty,	v_prodnm,	_specdes,		_qty2,

													_racknm,			_optprodcd,		_expinner,	_expcostnm,	_shopcd,		_shopseq,	_shop_userid,

													_order_orddt,	_order_ordseq,	_order_seq, _orddtl_clmdt, _orddtl_clmseq);

									END	if;

								else

									INSERT	INTO	TMP6

									VALUES	(_seq,			_rorddt,			_rcvnam,		_pstno,		_addr,		_clpno,		_telno,			_qty,

												_shpfee,			_credit,			_expprodnm,	_messge,		_pkgclss,	_shipcls,	_sabordno,		_shopid, 

												_ordnm,			_etcmsg,			_mallcd,		_ordamt,		_prodcd,		_optdesc,	_expbundnm,		_boxcnt, 

												_expfile,		_expcd,			_flagset,	_prodcdm,	_expinvqty,	v_prodnm,	_specdes,		_qty2,

												_racknm,			_optprodcd,		_expinner,	_expcostnm,	_shopcd,		_shopseq,	_shop_userid,

												_order_orddt,	_order_ordseq,	_order_seq, _orddtl_clmdt, _orddtl_clmseq);

								END	if;

							END	IF;

						UNTIL	done5	END	REPEAT;

							

						close	c5;

					END	Block5;

					

					# 주문수량으로 택배가격 결정 하는 상품 별도처리 

					Block6:	BEGIN

						DECLARE	v_delivamt	INT	DEFAULT 0;

						DECLARE	done6			INT	DEFAULT	0;

						

				   	DECLARE	c6	CURSOR	FOR

							SELECT	a.seq,	a.prodcdm,	a.qty2

							FROM		TMP6	a,	EXPPRODMST	b 

							WHERE		a.prodcdm	=	b.prodcd 

							AND      a.order_ordseq <> 3

							AND		IFNULL(b.EXPTABLEFLAG,'')	=	'2'

							AND		b.COMPNO		=	cut_compno

							AND		b.BRANDCD	=	cut_brandcd;

							

					   DECLARE	CONTINUE	HANDLER	FOR	SQLSTATE	'02000'	SET	done6	=	1;

					   	

					   OPEN	c6;

					   	

					   REPEAT

						  	FETCH	NEXT	FROM	c6

							INTO	_seq,	_prodcdm,	_qty2;

								

							IF	NOT	done6	THEN

								SET	v_delivamt	=	0;

									

								SELECT	ifnull(delivamt,0)

								INTO		v_delivamt

								FROM		EXPCOST

								WHERE		COMPNO	=	cut_compno

								AND		BRANDCD	=	cut_brandcd

								AND		prodcd	=	_prodcdm

								AND		TABNO		=	_qty2;

									

								UPDATE	TMP6

								SET		shpfee	=	v_delivamt

								WHERE		seq		=	_seq;

							END	IF;

						UNTIL	done6	END	REPEAT;

							

						close	c6;

					END	Block6;		

				END;

			END	YWM_EXCEL_EXPPICUP_Block;

			#=====================================

			# 기존 SP(YWM_EXCEL_EXPPICUP) 영역 끝

			#====================================

			

			# 무한루프 방지

			SET	safe_count	=	safe_count	-	1;

			

			if		safe_count	<=	0	then

				SET	start_pos	=	1;

				SET	end_pos		=	0;

			END	if;

		END	if;

	END	while;

	

	SELECT a.seq,a.rorddt,a.rcvnam,a.pstno,a.addr,a.clpno,a.telno,a.qty,a.shpfee,a.credit,a.expprodnm,a.messge,a.pkgclss,a.shipcls,a.sabordno,a.shopid,a.ordnm,a.etcmsg,a.mallcd,a.ordamt,a.prodcd,a.optdesc,

	       a.expbundnm,a.boxcnt,a.expfile,

		    a.expcd,a.flagset,a.prodcdm,a.expinvqty,a.prodnm,a.specdes,a.qty2,a.racknm,a.optprodcd,a.expinner,a.expcostnm,a.shopcd,a.shopseq,a.shop_userid,a.order_orddt,a.order_ordseq,a.order_seq,	

		    ifnull(b.neccd1,''),ifnull(b.neccd2,''),ifnull(b.neccd3,'')

	FROM		TMP6	a	LEFT	JOIN	NECPRODMST	b	

							ON		b.compno		=	cut_compno

							AND	b.BRANDCD	=	cut_brandcd

							AND	a.prodcdm	=	b.prodcd;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_EXCEL_MAP` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_EXCEL_MAP`(
	IN `_IN_OrdDt` VARCHAR(8),
	IN `_IN_OrdSeq` INT

























)
    COMMENT '주문상세 기준으로 Excel 랙 정보 설정'
BEGIN

	
	DECLARE _CurNecCd1	VARCHAR(2);
	DECLARE _CurNecCd2	INT;
	DECLARE _CurNecCd3 	INT;
	
	DECLARE _CurProdCd 	VARCHAR(20);
	DECLARE _CurProdNm 	VARCHAR(100);
	
	DECLARE _CurQty 		INT;

	DECLARE _NextProdCd	VARCHAR(20);
	DECLARE _NextNecCd1	VARCHAR(2);
	DECLARE _NextNecCd2	INT;
	DECLARE _NextNecCd3 INT;
	
	
	
	DECLARE _LastNecCd1 	VARCHAR(2) DEFAULT '-';
	DECLARE _LastNecCd2 	INT;
	DECLARE _LastNecCd3 	INT;
	
	
	
	DECLARE _NecCd31_Cd  VARCHAR(20);	
	DECLARE _NecCd31_Nm  VARCHAR(100);	
	DECLARE _NecCd31_Qty INT;				

	DECLARE _NecCd32_Cd  VARCHAR(20);
	DECLARE _NecCd32_Nm  VARCHAR(100);
	DECLARE _NecCd32_Qty INT;			

	DECLARE _NecCd33_Cd  VARCHAR(20);
	DECLARE _NecCd33_Nm  VARCHAR(100);
	DECLARE _NecCd33_Qty INT;			

	DECLARE _NecCd34_Cd  VARCHAR(20);
	DECLARE _NecCd34_Nm  VARCHAR(100);
	DECLARE _NecCd34_Qty INT;		

	DECLARE _NecCd35_Cd  VARCHAR(20);
	DECLARE _NecCd35_Nm  VARCHAR(100);
	DECLARE _NecCd35_Qty INT;		

	DECLARE _NecCd36_Cd  VARCHAR(20);	
	DECLARE _NecCd36_Nm  VARCHAR(100);	
	DECLARE _NecCd36_Qty INT;				

	DECLARE _NecCd37_Cd  VARCHAR(20);
	DECLARE _NecCd37_Nm  VARCHAR(100);
	DECLARE _NecCd37_Qty INT;			

	DECLARE _NecCd38_Cd  VARCHAR(20);
	DECLARE _NecCd38_Nm  VARCHAR(100);
	DECLARE _NecCd38_Qty INT;			

	DECLARE _NecCd39_Cd  VARCHAR(20);
	DECLARE _NecCd39_Nm  VARCHAR(100);
	DECLARE _NecCd39_Qty INT;		

	DECLARE _NecCd3A_Cd  VARCHAR(20);
	DECLARE _NecCd3A_Nm  VARCHAR(100);
	DECLARE _NecCd3A_Qty INT;		

	DECLARE _NecCd3B_Cd  VARCHAR(20);
	DECLARE _NecCd3B_Nm  VARCHAR(100);
	DECLARE _NecCd3B_Qty INT;		

	DECLARE _NecCd3C_Cd  VARCHAR(20);
	DECLARE _NecCd3C_Nm  VARCHAR(100);
	DECLARE _NecCd3C_Qty INT;		

	DECLARE _NecCd3D_Cd  VARCHAR(20);
	DECLARE _NecCd3D_Nm  VARCHAR(100);
	DECLARE _NecCd3D_Qty INT;		

	DECLARE _NecCd3E_Cd  VARCHAR(20);
	DECLARE _NecCd3E_Nm  VARCHAR(100);
	DECLARE _NecCd3E_Qty INT;		

	DECLARE _NecCd3F_Cd  VARCHAR(20);
	DECLARE _NecCd3F_Nm  VARCHAR(100);
	DECLARE _NecCd3F_Qty INT;		


	
	DECLARE _NecCd2		INT;
	DECLARE _NecCd31_Cd1 VARCHAR(20);
	DECLARE _NecCd32_Cd1 VARCHAR(20);
	DECLARE _NecCd33_Cd1 VARCHAR(20);
	DECLARE _NecCd34_Cd1 VARCHAR(20);
	DECLARE _NecCd35_Cd1 VARCHAR(20);
	DECLARE _NecCd36_Cd1 VARCHAR(20);
	DECLARE _NecCd37_Cd1 VARCHAR(20);
	DECLARE _NecCd38_Cd1 VARCHAR(20);
	DECLARE _NecCd39_Cd1 VARCHAR(20);
	DECLARE _NecCd3A_Cd1 VARCHAR(20);
	DECLARE _NecCd3B_Cd1 VARCHAR(20);
	DECLARE _NecCd3C_Cd1 VARCHAR(20);
	DECLARE _NecCd3D_Cd1 VARCHAR(20);
	DECLARE _NecCd3E_Cd1 VARCHAR(20);
	DECLARE _NecCd3F_Cd1 VARCHAR(20);
				
	
	DECLARE _ReptNo		INT;
	
	
	DECLARE _done 			INT DEFAULT FALSE;
	DECLARE _Exist			INT DEFAULT FALSE;
	DECLARE _Exist2		INT DEFAULT FALSE;
	DECLARE _First			INT DEFAULT TRUE;
	DECLARE _ReptRecCd1 	VARCHAR(20);
	DECLARE _ReptRecCd2	INT DEFAULT FALSE;
	DECLARE _ReptRecCd3	INT DEFAULT FALSE;
	


	
	DECLARE c_ORDDTL CURSOR FOR
	SELECT a.NecCd1 AS CurNecCd1, a.NecCd2 AS CurNecCd2, a.NecCd3 AS CurNecCd3,
	       b.ProdCd AS CurProdCd, a.ProdNm  AS CurProdNm, SUM(b.qty) AS CurQty,
          LAG(b.ProdCd,1) OVER (PARTITION BY a.NecCd1, a.NecCd2, a.NecCd3 ORDER BY a.NecCd1, a.NecCd2, a.NecCd3, b.ProdCd ) AS NextProdCd,
          LAG(a.NecCd1,1) OVER (ORDER BY a.NecCd1, a.NecCd2 DESC, a.NecCd3, b.ProdCd ) AS NextNecCd1,
          LAG(a.NecCd2,1) OVER (ORDER BY a.NecCd1, a.NecCd2, a.NecCd3, b.ProdCd ) AS NextNecCd2,
          LAG(a.NecCd3,1) OVER (ORDER BY a.NecCd1, a.NecCd2, a.NecCd3, b.ProdCd ) AS NextNecCd3
	  FROM V_PRODUCTS a, ORDDTL b
    WHERE 1=1
       AND a.ProdCd = b.ProdCd
       AND b.OrdDt  = _IN_OrdDt
       AND b.OrdSeq = _IN_OrdSeq
       AND IFNULL(a.NecCd1, '') <> ''
       AND IFNULL(a.ProdCd, '') <> ''
		 AND IFNULL(a.NecCd2, '') <> ''
		 AND IFNULL(a.NecCd3, '') <> ''
   GROUP BY a.NecCd1, a.NecCd2, a.NecCd3, b.ProdCd, a.ProdNm
   ORDER BY a.NecCd1, a.NecCd2 DESC, a.NecCd3, b.ProdCd, a.ProdNm
	;
	
	
	DECLARE CONTINUE HANDLER FOR NOT FOUND SET _done = TRUE;

	
	DELETE FROM ERRMST
    WHERE 1=1
      AND ModNm   = 'YWM_EXCEL_MAP'
      AND WorkDt = _IN_OrdDt
      AND WorkSeq= _IN_OrdSeq
	;

	
	INSERT INTO ERRMST
		(MODNM, WORKDT, WORKSEQ, MODTITLE, ERRDESC, EXEDT)
	SELECT 'YWM_EXCEL_MAP' 	AS MODNM,
			 _IN_OrdDt 			AS WORKDT,
			 _IN_OrdSeq			AS WORKSEQ, 
			 '상품코드 미존재  확인: '    AS MODTITLE, 
 			 CONCAT('ProdCd: ', b.ProdCd) AS ERRDESC, 
			NOW()					AS EXEDT
	  FROM ORDDTL b LEFT JOIN V_PRODUCTS a ON a.ProdCd = b.ProdCd
    WHERE 1=1
      AND b.ORDDT = _IN_OrdDt
      AND b.OrdSeq= _IN_OrdSeq
      AND (a.prodcd IS NULL OR a.prodcd ='')
	;

	
	INSERT INTO ERRMST
		(MODNM, WORKDT, WORKSEQ, MODTITLE, ERRDESC, EXEDT)
	SELECT 'YWM_EXCEL_MAP' 	AS MODNM,
			 _IN_OrdDt 			AS WORKDT,
			 _IN_OrdSeq			AS WORKSEQ, 
			 'Null 확인: '  	 AS MODTITLE, 
 			 CONCAT('ProdCd: ', b.ProdCd, ', Null컬럼: ', IF(a.NecCd1 IS NULL, 'NecCd1', ''), ', ', IF(a.NecCd2 IS NULL, 'NecCd2', ''), ', ', IF(a.NecCd3 IS NULL, 'NecCd3', '')) AS ERRDESC, 
			NOW()					AS EXEDT
	  FROM V_PRODUCTS a, ORDDTL b
    WHERE 1=1
	   AND a.ProdCd = b.ProdCd
      AND b.ORDDT = _IN_OrdDt
      AND b.OrdSeq= _IN_OrdSeq
      AND (a.NecCd1 IS NULL OR a.NecCd2 IS NULL OR a.NecCd3 IS NULL)
	;

	
	DELETE FROM EXCELMST
	 WHERE 1=1
      AND OrdDt  <  DATE_FORMAT(date_add(NOW(), interval -1 month), '%Y%m%d')
   ;

	
	DELETE FROM EXCELMST
	 WHERE 1=1
      AND OrdDt  = _IN_OrdDt
      AND OrdSeq = _IN_OrdSeq
   ;
	
   
	SET _NextNecCd1 = '-';
	SET _LastNecCd1 = '-';
	
	OPEN c_ORDDTL;
	REPEAT
		
		FETCH c_ORDDTL 
		INTO _CurNecCd1, _CurNecCd2, _CurNecCd3,
	        _CurProdCd, _CurProdNm, _CurQty,
           _NextProdCd, _NextNecCd1, _NextNecCd2, _NextNecCd3
		 ;
		 
		IF NOT _done THEN
		
			
			IF _CurNecCd1 <> _NextNecCd1 OR _First = TRUE THEN
			
				
				SET _NecCd31_Cd  = '';
				SET _NecCd31_Nm  = '';
				SET _NecCd31_Qty = NULL;

				SET _NecCd32_Cd  = '';
				SET _NecCd32_Nm  = '';
				SET _NecCd32_Qty = NULL;

				SET _NecCd33_Cd  = '';
				SET _NecCd33_Nm  = '';
				SET _NecCd33_Qty = NULL;

				SET _NecCd34_Cd  = '';
				SET _NecCd34_Nm  = '';
				SET _NecCd34_Qty = NULL;

				SET _NecCd35_Cd  = '';
				SET _NecCd35_Nm  = '';
				SET _NecCd35_Qty = NULL;

				SET _NecCd36_Cd  = '';
				SET _NecCd36_Nm  = '';
				SET _NecCd36_Qty = NULL;

				SET _NecCd37_Cd  = '';
				SET _NecCd37_Nm  = '';
				SET _NecCd37_Qty = NULL;

				SET _NecCd38_Cd  = '';
				SET _NecCd38_Nm  = '';
				SET _NecCd38_Qty = NULL;

				SET _NecCd39_Cd  = '';
				SET _NecCd39_Nm  = '';
				SET _NecCd39_Qty = NULL;

				SET _NecCd3A_Cd  = '';
				SET _NecCd3A_Nm  = '';
				SET _NecCd3A_Qty = NULL;

				SET _NecCd3B_Cd  = '';
				SET _NecCd3B_Nm  = '';
				SET _NecCd3B_Qty = NULL;

				SET _NecCd3C_Cd  = '';
				SET _NecCd3C_Nm  = '';
				SET _NecCd3C_Qty = NULL;

				SET _NecCd3D_Cd  = '';
				SET _NecCd3D_Nm  = '';
				SET _NecCd3D_Qty = NULL;

				SET _NecCd3E_Cd  = '';
				SET _NecCd3E_Nm  = '';
				SET _NecCd3E_Qty = NULL;

				SET _NecCd3F_Cd  = '';
				SET _NecCd3F_Nm  = '';
				SET _NecCd3F_Qty = NULL;

				
				
				SET _ReptNo = 1;

				REPEAT
					INSERT INTO EXCELMST
						(OrdDt, OrdSeq, NecCd1, NecCd2

						) 
					VALUE
						(_IN_OrdDt, _IN_OrdSeq, _CurNecCd1, _ReptNo

					);

					SET _ReptNo = _ReptNo + 1;
					
				UNTIL _ReptNo > 5
				END REPEAT;
				SET _First = FALSE;
			END IF;
			
			SET _ReptRecCd1 =	_CurNecCd1;
			SET _ReptRecCd2 =	_CurNecCd2;
			SET _ReptRecCd3 =	_CurNecCd3;
		
			

			

						
			REPEAT
				SET _Exist = FALSE;
				SELECT 
					 NecCd2,
					 NecCd31_Cd, NecCd32_Cd, NecCd33_Cd, NecCd34_Cd, NecCd35_Cd,
					 NecCd36_Cd, NecCd37_Cd, NecCd38_Cd, NecCd39_Cd, NecCd3A_Cd,
					 NecCd3B_Cd, NecCd3C_Cd, NecCd3D_Cd, NecCd3E_Cd, NecCd3F_Cd
				  INTO 
					 _NecCd2,
					 _NecCd31_Cd1, _NecCd32_Cd1, _NecCd33_Cd1, _NecCd34_Cd1, _NecCd35_Cd1,
					 _NecCd36_Cd1, _NecCd37_Cd1, _NecCd38_Cd1, _NecCd39_Cd1, _NecCd3A_Cd1,
					 _NecCd3B_Cd1, _NecCd3C_Cd1, _NecCd3D_Cd1, _NecCd3E_Cd1, _NecCd3F_Cd1
				  FROM EXCELMST
				 WHERE OrdDt  = _IN_OrdDt
				   AND OrdSeq = _IN_OrdSeq
					AND NecCd1 = _ReptRecCd1
					AND NecCd2 = _ReptRecCd2
				;


				CASE _ReptRecCd2
				WHEN 1 THEN
					CASE _ReptRecCd3
					WHEN 1 THEN
						IF IFNULL(_NecCd31_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 2 THEN
						IF IFNULL(_NecCd32_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 3 THEN
						IF IFNULL(_NecCd33_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 4 THEN
						IF IFNULL(_NecCd34_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 5 THEN
						IF IFNULL(_NecCd35_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 6 THEN
						IF IFNULL(_NecCd36_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 7 THEN
						IF IFNULL(_NecCd37_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 8 THEN
						IF IFNULL(_NecCd38_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 9 THEN
						IF IFNULL(_NecCd39_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 10 THEN
						IF IFNULL(_NecCd3A_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 11 THEN
						IF IFNULL(_NecCd3B_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 12 THEN
						IF IFNULL(_NecCd3C_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 13 THEN
						IF IFNULL(_NecCd3D_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 14 THEN
						IF IFNULL(_NecCd3E_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 15 THEN
						IF IFNULL(_NecCd3F_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					ELSE
						BEGIN END;
						
					END CASE;
				WHEN 2 THEN
					CASE _ReptRecCd3
					WHEN 1 THEN
						IF IFNULL(_NecCd31_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 2 THEN
						IF IFNULL(_NecCd32_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 3 THEN
						IF IFNULL(_NecCd33_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 4 THEN
						IF IFNULL(_NecCd34_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 5 THEN
						IF IFNULL(_NecCd35_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 6 THEN
						IF IFNULL(_NecCd36_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 7 THEN
						IF IFNULL(_NecCd37_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 8 THEN
						IF IFNULL(_NecCd38_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 9 THEN
						IF IFNULL(_NecCd39_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 10 THEN
						IF IFNULL(_NecCd3A_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 11 THEN
						IF IFNULL(_NecCd3B_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 12 THEN
						IF IFNULL(_NecCd3C_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 13 THEN
						IF IFNULL(_NecCd3D_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 14 THEN
						IF IFNULL(_NecCd3E_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 15 THEN
						IF IFNULL(_NecCd3F_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					ELSE
						BEGIN END;
						
					END CASE;
				WHEN 3 THEN
					CASE _ReptRecCd3
					WHEN 1 THEN
						IF IFNULL(_NecCd31_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 2 THEN
						IF IFNULL(_NecCd32_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 3 THEN
						IF IFNULL(_NecCd33_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 4 THEN
						IF IFNULL(_NecCd34_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 5 THEN
						IF IFNULL(_NecCd35_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 6 THEN
						IF IFNULL(_NecCd36_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 7 THEN
						IF IFNULL(_NecCd37_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 8 THEN
						IF IFNULL(_NecCd38_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 9 THEN
						IF IFNULL(_NecCd39_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 10 THEN
						IF IFNULL(_NecCd3A_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 11 THEN
						IF IFNULL(_NecCd3B_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 12 THEN
						IF IFNULL(_NecCd3C_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 13 THEN
						IF IFNULL(_NecCd3D_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 14 THEN
						IF IFNULL(_NecCd3E_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 15 THEN
						IF IFNULL(_NecCd3F_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					ELSE
						BEGIN END;
						
					END CASE;
				WHEN 4 THEN
					CASE _ReptRecCd3
					WHEN 1 THEN
						IF IFNULL(_NecCd31_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 2 THEN
						IF IFNULL(_NecCd32_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 3 THEN
						IF IFNULL(_NecCd33_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 4 THEN
						IF IFNULL(_NecCd34_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 5 THEN
						IF IFNULL(_NecCd35_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 6 THEN
						IF IFNULL(_NecCd36_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 7 THEN
						IF IFNULL(_NecCd37_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 8 THEN
						IF IFNULL(_NecCd38_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 9 THEN
						IF IFNULL(_NecCd39_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 10 THEN
						IF IFNULL(_NecCd3A_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 11 THEN
						IF IFNULL(_NecCd3B_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 12 THEN
						IF IFNULL(_NecCd3C_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 13 THEN
						IF IFNULL(_NecCd3D_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 14 THEN
						IF IFNULL(_NecCd3E_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 15 THEN
						IF IFNULL(_NecCd3F_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					ELSE
						BEGIN END;
						
					END CASE;
				WHEN 5 THEN
					CASE _ReptRecCd3
					WHEN 1 THEN
						IF IFNULL(_NecCd31_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 2 THEN
						IF IFNULL(_NecCd32_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 3 THEN
						IF IFNULL(_NecCd33_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 4 THEN
						IF IFNULL(_NecCd34_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 5 THEN
						IF IFNULL(_NecCd35_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 6 THEN
						IF IFNULL(_NecCd36_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 7 THEN
						IF IFNULL(_NecCd37_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 8 THEN
						IF IFNULL(_NecCd38_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 9 THEN
						IF IFNULL(_NecCd39_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 10 THEN
						IF IFNULL(_NecCd3A_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 11 THEN
						IF IFNULL(_NecCd3B_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 12 THEN
						IF IFNULL(_NecCd3C_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 13 THEN
						IF IFNULL(_NecCd3D_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 14 THEN
						IF IFNULL(_NecCd3E_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					WHEN 15 THEN
						IF IFNULL(_NecCd3F_Cd1, '-') <> '-' THEN
							SET _Exist = TRUE;
						END IF;
					ELSE
						BEGIN END;
					
					END CASE;
				END CASE;
				
				IF _Exist = TRUE THEN
					IF _ReptRecCd2 = 1 THEN
						SET _ReptRecCd2 = 5;
						SET _ReptRecCd3 = _ReptRecCd3 + 1;
					ELSE
						SET _ReptRecCd2 = _ReptRecCd2 - 1;
					END IF;
					set _Exist2 = FALSE;
				ELSE
					set _Exist2 = TRUE;
				END IF;
				
			UNTIL _Exist2 = TRUE OR _ReptRecCd3 > 15
			END REPEAT;

			IF _ReptRecCd2 > 5 OR _ReptRecCd3 > 15 THEN 
						INSERT INTO ERRMST
							(MODNM, WORKDT, WORKSEQ, MODTITLE, ERRDESC, EXEDT)
						SELECT 'YWM_EXCEL_MAP' 	AS MODNM,
								 _IN_OrdDt 			AS WORKDT,
								 _IN_OrdSeq			AS WORKSEQ, 
								 'CELL INFO ERROR'   AS MODTITLE, 
			 			 		CONCAT(_CurProdCd, ', ', _CurProdNm, ', ', _CurQty, ', ', _CurNecCd1, ', ', _CurNecCd2, ', ', _CurNecCd3) AS ERRDESC, 
								NOW()	;
			ELSE
			
				
				IF _Exist2 = TRUE THEN
					CASE _ReptRecCd3
					WHEN 1 THEN
						UPDATE EXCELMST
							SET NecCd31_Cd  = _CurProdCd
							  , NecCd31_Nm  = _CurProdNm
							  , NecCd31_Qty = _CurQty
						 WHERE OrdDt  = _IN_OrdDt
						   AND OrdSeq = _IN_OrdSeq
							AND NecCd1 = _CurNecCd1
							AND NecCd2 = _ReptRecCd2;
		 
					WHEN 2 THEN
						UPDATE EXCELMST
							SET NecCd32_Cd  = _CurProdCd
							  , NecCd32_Nm  = _CurProdNm
							  , NecCd32_Qty = _CurQty
						 WHERE OrdDt  = _IN_OrdDt
						   AND OrdSeq = _IN_OrdSeq
							AND NecCd1 = _CurNecCd1
							AND NecCd2 = _ReptRecCd2;
		
					WHEN 3 THEN
						UPDATE EXCELMST
							SET NecCd33_Cd  = _CurProdCd
							  , NecCd33_Nm  = _CurProdNm
							  , NecCd33_Qty = _CurQty
						 WHERE OrdDt  = _IN_OrdDt
						   AND OrdSeq = _IN_OrdSeq
							AND NecCd1 = _CurNecCd1
							AND NecCd2 = _ReptRecCd2;
		
					WHEN 4 THEN
						UPDATE EXCELMST
							SET NecCd34_Cd  = _CurProdCd
							  , NecCd34_Nm  = _CurProdNm
							  , NecCd34_Qty = _CurQty
						 WHERE OrdDt  = _IN_OrdDt
						   AND OrdSeq = _IN_OrdSeq
							AND NecCd1 = _CurNecCd1
							AND NecCd2 = _ReptRecCd2;
		
					WHEN 5 THEN
						UPDATE EXCELMST
							SET NecCd35_Cd  = _CurProdCd
							  , NecCd35_Nm  = _CurProdNm
							  , NecCd35_Qty = _CurQty
						 WHERE OrdDt  = _IN_OrdDt
						   AND OrdSeq = _IN_OrdSeq
							AND NecCd1 = _CurNecCd1
							AND NecCd2 = _ReptRecCd2;
		
					WHEN 6 THEN
						UPDATE EXCELMST
							SET NecCd36_Cd  = _CurProdCd
							  , NecCd36_Nm  = _CurProdNm
							  , NecCd36_Qty = _CurQty
						 WHERE OrdDt  = _IN_OrdDt
						   AND OrdSeq = _IN_OrdSeq
							AND NecCd1 = _CurNecCd1
							AND NecCd2 = _ReptRecCd2;
		
					WHEN 7 THEN
						UPDATE EXCELMST
							SET NecCd37_Cd  = _CurProdCd
							  , NecCd37_Nm  = _CurProdNm
							  , NecCd37_Qty = _CurQty
						 WHERE OrdDt  = _IN_OrdDt
						   AND OrdSeq = _IN_OrdSeq
							AND NecCd1 = _CurNecCd1
							AND NecCd2 = _ReptRecCd2;
		
					WHEN 8 THEN
						UPDATE EXCELMST
							SET NecCd38_Cd  = _CurProdCd
							  , NecCd38_Nm  = _CurProdNm
							  , NecCd38_Qty = _CurQty
						 WHERE OrdDt  = _IN_OrdDt
						   AND OrdSeq = _IN_OrdSeq
							AND NecCd1 = _CurNecCd1
							AND NecCd2 = _ReptRecCd2;
		
					WHEN 9 THEN
						UPDATE EXCELMST
							SET NecCd39_Cd  = _CurProdCd
							  , NecCd39_Nm  = _CurProdNm
							  , NecCd39_Qty = _CurQty
						 WHERE OrdDt  = _IN_OrdDt
						   AND OrdSeq = _IN_OrdSeq
							AND NecCd1 = _CurNecCd1
							AND NecCd2 = _ReptRecCd2;
		
					WHEN 10 THEN
						UPDATE EXCELMST
							SET NecCd3A_Cd  = _CurProdCd
							  , NecCd3A_Nm  = _CurProdNm
							  , NecCd3A_Qty = _CurQty
						 WHERE OrdDt  = _IN_OrdDt
						   AND OrdSeq = _IN_OrdSeq
							AND NecCd1 = _CurNecCd1
							AND NecCd2 = _ReptRecCd2;
		
					WHEN 11 THEN
						UPDATE EXCELMST
							SET NecCd3B_Cd  = _CurProdCd
							  , NecCd3B_Nm  = _CurProdNm
							  , NecCd3B_Qty = _CurQty
						 WHERE OrdDt  = _IN_OrdDt
						   AND OrdSeq = _IN_OrdSeq
							AND NecCd1 = _CurNecCd1
							AND NecCd2 = _ReptRecCd2;
		
					WHEN 12 THEN
						UPDATE EXCELMST
							SET NecCd3C_Cd  = _CurProdCd
							  , NecCd3C_Nm  = _CurProdNm
							  , NecCd3C_Qty = _CurQty
						 WHERE OrdDt  = _IN_OrdDt
						   AND OrdSeq = _IN_OrdSeq
							AND NecCd1 = _CurNecCd1
							AND NecCd2 = _ReptRecCd2;
		
					WHEN 13 THEN
						UPDATE EXCELMST
							SET NecCd3D_Cd  = _CurProdCd
							  , NecCd3D_Nm  = _CurProdNm
							  , NecCd3D_Qty = _CurQty
						 WHERE OrdDt  = _IN_OrdDt
						   AND OrdSeq = _IN_OrdSeq
							AND NecCd1 = _CurNecCd1
							AND NecCd2 = _ReptRecCd2;
		
					WHEN 14 THEN
						UPDATE EXCELMST
							SET NecCd3E_Cd  = _CurProdCd
							  , NecCd3E_Nm  = _CurProdNm
							  , NecCd3E_Qty = _CurQty
						 WHERE OrdDt  = _IN_OrdDt
						   AND OrdSeq = _IN_OrdSeq
							AND NecCd1 = _CurNecCd1
							AND NecCd2 = _ReptRecCd2;
		
					WHEN 15 THEN
						UPDATE EXCELMST
							SET NecCd3F_Cd  = _CurProdCd
							  , NecCd3F_Nm  = _CurProdNm
							  , NecCd3F_Qty = _CurQty
						 WHERE OrdDt  = _IN_OrdDt
						   AND OrdSeq = _IN_OrdSeq
							AND NecCd1 = _CurNecCd1
							AND NecCd2 = _ReptRecCd2;
		
					ELSE

						INSERT INTO ERRMST
							(MODNM, WORKDT, WORKSEQ, MODTITLE, ERRDESC, EXEDT)
						SELECT 'YWM_EXCEL_MAP' 	AS MODNM,
								 _IN_OrdDt 			AS WORKDT,
								 _IN_OrdSeq			AS WORKSEQ, 
								 'UPDATE ERROR'   AS MODTITLE, 
			 			 		CONCAT(_CurProdCd, ', ', _CurProdNm, ', ', _CurQty, ', ', _CurNecCd1, ', ', _CurNecCd2, ', ', _CurNecCd3) AS ERRDESC, 
								NOW()	;
					END CASE;
				END IF;
				
				SET _done = FALSE;
			END IF;
		END IF;
	UNTIL _done END REPEAT;
	
	
	CLOSE c_ORDDTL;
	
	
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_EXCEL_ORDER` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_EXCEL_ORDER`(

	IN `V_COMPNO` INT,

	IN `V_BRANDCD` INT,

	IN `V_BASEDATE` VARCHAR(8)




























)
    COMMENT '적정재고 관리위한 판매 재고현황 '
BEGIN



	DECLARE _stkdt varchar(8);

	DECLARE _sdt varchar(8);

	DECLARE _edt varchar(8);

	DECLARE _sale2mdate varchar(8);

	DECLARE _sale15mdate varchar(8);

	DECLARE _sale25mdate varchar(8);

	DECLARE _sale3mdate varchar(8);

	

	BEGIN



		SELECT MAX(STKDT) INTO _stkdt FROM BASSTKMST WHERE COMPNO=V_COMPNO and BRANDCD = V_BRANDCD;

		SELECT DATE_FORMAT(DATE_ADD(IFNULL(_stkdt,'20181231'), INTERVAL 1 DAY),'%Y%m%d') into _sdt FROM dual;

		set _edt = V_BASEDATE;

		SELECT DATE_FORMAT(DATE_SUB(_edt, INTERVAL 3 MONTH),'%Y%m%d') into _sale3mdate FROM dual;

		SELECT DATE_FORMAT(DATE_SUB(_edt, INTERVAL 2 MONTH),'%Y%m%d') into _sale2mdate FROM dual;

		SELECT DATE_FORMAT(DATE_SUB(_sale2mdate, INTERVAL 15 DAY),'%Y%m%d') into _sale25mdate FROM dual;

		SELECT DATE_FORMAT(DATE_SUB(_edt, INTERVAL 1 MONTH),'%Y%m%d') into _sale15mdate FROM dual;

		SELECT DATE_FORMAT(DATE_SUB(_sale15mdate, INTERVAL 15 DAY),'%Y%m%d') into _sale15mdate FROM dual;

		

		if _sale3mdate < _sdt then

			
			CALL YWM_SETCODELIST(V_COMPNO,V_BRANDCD,_sale3mdate,_edt);

		else

			CALL YWM_SETCODELIST(V_COMPNO,V_BRANDCD,_sdt,_edt);

		end if;

		

		DROP TABLE if EXISTS IMSI_ORDSUM;

		CREATE TABLE IF NOT EXISTS IMSI_ORDSUM AS SELECT * FROM WAREHOUSE_QTY_TMP2 ;

		

		SELECT DISTINCT a.prodcd, b.prodnm,b.specdes,sum(a.sale3qty) AS sale3qty,sum(a.sale25qty) AS sale25qty,

							 sum(a.sale2qty) AS sale2qty,

		 					 sum(a.sale15qty) AS sale15qty,CEILING(sum(a.sale3qty)/3) as saleAvqty, 

							 SUM(a.baseqty) + SUM(a.receiveqty) - SUM(a.saleqty) as qty,

							 sum(a.befqty) as befqty, sum(a.retnqty) as retnqty,

							 (SUM(a.baseqty) + SUM(a.receiveqty) - SUM(a.saleqty)) + sum(a.befqty) as warqty

		  FROM (SELECT distinct prodcdm as prodcd , sum(qty) AS sale3qty, 0 AS sale25qty,0 AS sale2qty,0 AS sale15qty,0 as befqty, 0 as baseqty, 0 AS receiveqty, 

		  					0 AS saleqty,0 as retnqty

					 FROM IMSI_ORDSUM 

					where orddt between _sale3mdate and _edt

				   group BY prodcdm

				   UNION all

				  SELECT distinct prodcdm as prodcd , 0 AS sale3qty, sum(qty) AS sale25qty,0 AS sale2qty,0 AS sale15qty,0 as befqty, 0 as baseqty, 0 AS receiveqty, 

		  					0 AS saleqty,0 as retnqty

					 FROM IMSI_ORDSUM 

					where orddt between _sale25mdate and _edt

				   group BY prodcdm

				   UNION all

				  SELECT distinct prodcdm as prodcd , 0 AS sale3qty, 0 AS sale25qty, sum(qty) AS sale2qty,0 AS sale15qty,0 as befqty, 0 as baseqty, 0 AS receiveqty, 

		  					0 AS saleqty,0 as retnqty

					 FROM IMSI_ORDSUM 

					where orddt between _sale2mdate and _edt

				   group BY prodcdm

				   UNION all

				  SELECT distinct prodcdm as prodcd , 0 AS sale3qty, 0 AS sale25qty, 0 AS sale2qty, sum(qty) AS sale15qty,0 as befqty, 0 as baseqty, 0 AS receiveqty, 

		  					0 AS saleqty,0 as retnqty

					 FROM IMSI_ORDSUM 

					where orddt between _sale15mdate and _edt

				   group BY prodcdm

				   UNION all

				  
				  SELECT distinct prodcdm as prodcd , 0 AS sale3qty, 0 AS sale25qty, 0 AS sale2qty, 0 AS sale15qty,0 as befqty, 0 as baseqty, 0 AS receiveqty, 

		  					sum(qty) AS saleqty,0 as retnqty

					 FROM IMSI_ORDSUM 

					where orddt between _sdt AND _edt

				   group BY prodcdm

				   UNION all

				  SELECT distinct prodcd, 0 AS sale3qty,0 AS sale25qty,0 AS sale2qty,0 AS sale15qty,sum(A.befqty) as befqty, 0 as baseqty, 0 AS receiveqty, 

				  			0 AS saleqty,0 as retnqty

					 FROM RECVDTL A, RECVMST B

				   WHERE A.COMPNO=V_COMPNO

				     AND A.BRANDCD = V_BRANDCD

				     AND IFNULL(A.befqty,0) <> 0 

					  AND IFNULL(A.aftqty,0) = 0

					  AND A.COMPNO=B.COMPNO

					  AND A.BRANDCD = B.BRANDCD

					  AND A.RECVDT=B.RECVDT

					  AND A.RECVSEQ=B.RECVSEQ

					  AND B.RECVGUBUN <> '반품'

				   group BY prodcd

				  UNION all

				  SELECT distinct prodcd, 0 AS sale3qty,0 AS sale25qty,0 AS sale2qty,0 AS sale15qty,0 as befqty, 0 as baseqty, 0 AS receiveqty, 

				  			0 AS saleqty,sum(A.befqty) as retnqty

					 FROM RECVDTL A, RECVMST B

				   WHERE A.COMPNO=V_COMPNO

				   AND A.BRANDCD = V_BRANDCD

				     AND IFNULL(A.befqty,0) <> 0 

					  AND IFNULL(A.aftqty,0) = 0

					  AND A.COMPNO=B.COMPNO

					  AND A.BRANDCD = B.BRANDCD

					  AND A.RECVDT=B.RECVDT

					  AND A.RECVSEQ=B.RECVSEQ

					  AND B.RECVGUBUN = '반품'

				   group BY prodcd

				  UNION all

				  
				  SELECT distinct prodcd, 0 AS sale3qty,0 AS sale25qty,0 AS sale2qty,0 AS sale15qty,0 as befqty, sum(realqty) as baseqty, 0 AS receiveqty,

				  			0 AS saleqty,0 as retnqty

					 FROM BASSTKDTL 

					

				   WHERE COMPNO=V_COMPNO

				    AND BRANDCD = V_BRANDCD

				     AND STKDT = IFNULL(_stkdt,'20181231')

				   group BY prodcd

				  UNION all

				  
				  SELECT distinct prodcd, 0 AS sale3qty,0 AS sale25qty,0 AS sale2qty,0 AS sale15qty,0 as befqty, 0 as baseqty, sum(AFTQTY) AS receiveqty, 

				  			0 AS saleqty,0 as retnqty

					 FROM RECVDTL

				   WHERE COMPNO=V_COMPNO

				     AND BRANDCD = V_BRANDCD

				     AND REALDT BETWEEN _sdt AND _edt

				   group BY prodcd

				) a, PRODMST b

		 where a.prodcd=b.prodcd AND b.COMPNO=V_COMPNO

		 AND b.BRANDCD = V_BRANDCD

		 group BY a.prodcd, b.prodnm,b.specdes ;

		 

	END;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_IMSI` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_IMSI`(

	IN `v_compno` INT





)
BEGIN

	DECLARE _prodseq    INT;

	DECLARE _prodcd     VARCHAR(20);

	DECLARE _optprodcd  VARCHAR(20);

	DECLARE _optprodnm  VARCHAR(20);

	DECLARE _optspecdes VARCHAR(20);

	DECLARE _skuseq     INT;

	

	DECLARE done2 INT DEFAULT 0;

	DECLARE c1 CURSOR FOR SELECT optprodcd,optprodnm,optspecdes,

       								  IFNULL((SELECT MAX(column1) FROM TABLE1),0) +ROW_NUMBER() OVER (ORDER BY optprodcd) 

  									FROM optprodmst 

								  WHERE compno=v_compno 

								    AND prodcd=_prodcd;

	DECLARE c2 CURSOR FOR SELECT prodseq,compayny_goods_cd

								   FROM SHOPPRODINFO 

								  WHERE COMPNO = v_compno;

	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done2 = 1;

	BEGIN

		OPEN c2;

		REPEAT

		FETCH NEXT FROM c2 INTO _prodseq,_prodcd;

		IF not done2 THEN

			BEGIN

				

				DECLARE done INT DEFAULT 0;

				DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;

				

				OPEN c1;

				REPEAT

				FETCH NEXT FROM c1 INTO _optprodcd,_optprodnm,_optspecdes,_skuseq;

				IF not done THEN

					INSERT SHOP_OPTPRODINFO(prodseq,skuseq,compno,prodcd,optprodcd,optprodnm,optspecdes) 

			                		  VALUES(_prodseq,_skuseq,v_compno,_prodcd,_optprodcd,_optprodnm,_optspecdes);

			   END if;

			   UNTIL done END REPEAT;

				close c1;

			END;

		END if;

		UNTIL done2 END REPEAT;

		close c2;

	END;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_IMSI11` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_IMSI11`()
BEGIN

	DECLARE _prodseq     			INT;

	DECLARE _full_name  				VARCHAR(200);

	

	DECLARE done2 INT DEFAULT 0;

	DECLARE c1 CURSOR FOR  SELECT a.PRODSEQ,b.FULL_NAME 

									 FROM SHOPPRODINFO AS a JOIN category AS b ON a.CLASS_CD3=b.ID

								   WHERE a.CLASS_CD3 <> '' 

									  AND a.gmcategnm = '';

	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done2 = 1;

	BEGIN

		OPEN c1;

		REPEAT

		FETCH NEXT FROM c1 INTO _prodseq,_full_name;

		IF not done2 THEN

			UPDATE SHOPPRODINFO SET gmcategnm = _full_name

			 WHERE prodseq=_prodseq;

		END if;

		COMMIT;

		UNTIL done2 END REPEAT;

		close c1;

	END;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_IMSI12` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_IMSI12`()
BEGIN

	DECLARE _compaygoodscd     VARCHAR(50);
	
	DECLARE done2 INT DEFAULT 0;
	DECLARE c1 CURSOR FOR SELECT a.COMPAYNY_GOODS_CD
									FROM shopprodinfo a
									LEFT JOIN (SELECT DISTINCT COMPAYNY_GOODS_CD FROM shopprodin WHERE compno=4) b
									  ON a.COMPAYNY_GOODS_CD = b.COMPAYNY_GOODS_CD
									WHERE b.COMPAYNY_GOODS_CD IS NULL;
   
	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done2 = 1;
	BEGIN
		OPEN c1;
		REPEAT
		FETCH NEXT FROM c1 INTO _compaygoodscd;
		IF not done2 THEN
			DELETE FROM shopprodinfo WHERE compno=4 AND COMPAYNY_GOODS_CD=_compaygoodscd;
			DELETE FROM shop_optprodinfo WHERE compno=4 AND prodcd=_compaygoodscd;
			commit;
		END if;
		UNTIL done2 END REPEAT;
		close c1;
	END;
	
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_IMSI13` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_IMSI13`()
BEGIN



	DECLARE _prodseq     		INT;

	DECLARE _shop_cid_info     JSON;

	DECLARE v_class_cd3			VARCHAR(50);

	

	DECLARE done2 INT DEFAULT 0;

	DECLARE c1 CURSOR FOR SELECT PRODSEQ,SHOP_CID_INFO FROM SHOPPRODINFO AS a left join CATEGORY AS b ON a.class_cd3=b.ID WHERE b.id is NULL;

   

	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done2 = 1;

	BEGIN

		OPEN c1;

		REPEAT

		FETCH NEXT FROM c1 INTO _prodseq,_shop_cid_info;

		IF not done2 THEN

			set v_class_cd3 = GET_SHOPALLCODE_ESCODE(_shop_cid_info);

			UPDATE SHOPPRODINFO SET class_cd3 = v_class_cd3 WHERE PRODSEQ = _prodseq;

			UPDATE SHOPPRODIN SET class_cd3 = v_class_cd3 WHERE PRODSEQ = _prodseq;

			commit;

		END if;

		UNTIL done2 END REPEAT;

		close c1;

	END;

	

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_IMSI14` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_IMSI14`()
BEGIN



	DECLARE _sendseq     		INT;

	DECLARE _shop_cid_info     JSON;

	DECLARE v_class_cd3			VARCHAR(50);

	

	DECLARE done2 INT DEFAULT 0;

	DECLARE c1 CURSOR FOR SELECT SENDSEQ,SHOP_CID_INFO FROM SHOPPRODIN AS a left join CATEGORY AS b ON a.class_cd3=b.ID WHERE b.id is NULL;

   

	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done2 = 1;

	BEGIN

		OPEN c1;

		REPEAT

		FETCH NEXT FROM c1 INTO _sendseq,_shop_cid_info;

		IF not done2 THEN

			set v_class_cd3 = GET_SHOPALLCODE_ESCODE(_shop_cid_info);

			UPDATE SHOPPRODIN SET class_cd3 = v_class_cd3 WHERE SENDSEQ = _sendseq;

			commit;

		END if;

		UNTIL done2 END REPEAT;

		close c1;

	END;

	

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_IMSI2` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_IMSI2`(

	IN `v_compno` INT

)
BEGIN

	DECLARE _prodcd     VARCHAR(20);

	DECLARE _orderprice     INT;

	

	DECLARE done2 INT DEFAULT 0;

	DECLARE c1 CURSOR FOR SELECT b.prodcd, b.orderprice

								   FROM shopprodinfo a, prodmst b 

								  WHERE a.compno=v_compno

								    AND a.compno=b.compno and a.compayny_goods_cd=b.prodcd;

	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done2 = 1;

	BEGIN

		OPEN c1;

		REPEAT

		FETCH NEXT FROM c1 INTO _prodcd,_orderprice;

		IF not done2 THEN

			UPDATE shopprodinfo SET goods_cost = _orderprice WHERE compno=v_compno AND compayny_goods_cd=_prodcd;

		END if;

		UNTIL done2 END REPEAT;

		close c1;

	END;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_IMSI3` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_IMSI3`()
BEGIN

	DECLARE _goods_keyword     VARCHAR(200);

	DECLARE _shopcd     			VARCHAR(200);

	DECLARE _shopid     			VARCHAR(200);

	DECLARE _compno     			INT;

	DECLARE _shopseq     		INT;

	DECLARE _shopsendstatus 	INT;

	

	DECLARE done2 INT DEFAULT 0;

	DECLARE c1 CURSOR FOR SELECT compno,goods_keyword,shopcd,SHOP_USERID,shopseq,shopsendstatus

								   FROM SHOPPRODIN ;

	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done2 = 1;

	BEGIN

	

		truncate table SUM_PRODINCOUNTS;

	

		OPEN c1;

		REPEAT

		FETCH NEXT FROM c1 INTO _compno,_goods_keyword,_shopcd,_shopid,_shopseq,_shopsendstatus;

		IF not done2 THEN



			IF (SELECT EXISTS (SELECT 1  FROM SUM_PRODINCOUNTS  

									  WHERE COMPNO 		 = _compno 

									    AND GOODS_KEYWORD = ifnull(_goods_keyword,'')

										 AND SHOPCD 		 = _shopcd 

										 AND SHOPID 		 = ifnull(_shopid,'') 

										 AND SHOPSEQ 		 = ifnull(_shopseq,0)

										 AND SHOPSENDSTATUS= _shopsendstatus) AS FLAG) THEN

				UPDATE SUM_PRODINCOUNTS SET COUNTS = COUNTS + 1  

						WHERE COMPNO 			= _compno 

						  AND GOODS_KEYWORD  = ifnull(_goods_keyword,'')

						  AND SHOPCD 			= _shopcd 

						  AND SHOPID 			= ifnull(_shopid,'') 

						  AND SHOPSEQ 			= ifnull(_shopseq,0)

						  AND SHOPSENDSTATUS = _shopsendstatus;

			ELSE 

				INSERT INTO SUM_PRODINCOUNTS(COMPNO,GOODS_KEYWORD,SHOPCD,SHOPID,SHOPSEQ,SHOPSENDSTATUS,COUNTS) 

											VALUES (_compno,ifnull(_goods_keyword,''),_shopcd,ifnull(_shopid,''), ifnull(_shopseq,0),_shopsendstatus,1);

			END IF;



			commit;

		END if;

		UNTIL done2 END REPEAT;

		close c1;

	END;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_IMSI4` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_IMSI4`()
BEGIN

	DECLARE _prodcd     VARCHAR(20);

	DECLARE _catcd      VARCHAR(200);

	DECLARE _shopcd     VARCHAR(20);

	DECLARE v_prodcd    VARCHAR(20);	

	DECLARE v_first     VARCHAR(20); 

	DECLARE v_text      TEXT;		

	DECLARE v_sw        VARCHAR(20); 

	

	DECLARE done2 INT DEFAULT 0;

	DECLARE c1 CURSOR FOR SELECT a.COMPAYNY_GOODS_CD,c.SHOPSMLCATCD,b.shopcd

								   FROM shopprodinfo AS a 

								   JOIN categdtlmap AS b ON b.compno=3 AND b.CODE = concat(class_cd1,class_cd2,class_cd3,class_cd4)

								   JOIN shopcatinf AS c ON c.compno=3 AND c.shopcd = b.shopcd AND c.SHOPCATNO=b.SHOPCATNO

								  WHERE a.compno=3 

								    AND a.STATUS=0

								    
									 order by a.COMPAYNY_GOODS_CD;

	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done2 = 1;

	BEGIN

		set v_first = '';

		set v_sw = '';

		OPEN c1;

		REPEAT

			FETCH NEXT FROM c1 INTO _prodcd,_catcd,_shopcd;

			IF not done2 THEN

				if v_first = '' then

					set v_first = 'lst';

					set v_prodcd = _prodcd;

					set v_text = '[';

				end if;

				

				if _prodcd = v_prodcd then

					if v_sw = 'lst' then 

						set v_text = concat(v_text , ',');

					end if;

					set v_text = concat(v_text , '{"cid": "' , _catcd , '", "shopcd": "' , _shopcd , '", "esm_auction": "", "esm_gmarket": ""}');

					set v_sw = 'lst';

				else

					set v_text = concat(v_text , ']');

					
					UPDATE shopprodinfo SET SHOP_CID_INFO = v_text WHERE compno=3 AND compayny_goods_cd=v_prodcd;

					UPDATE shopprodin SET SHOP_CID_INFO = v_text WHERE compno=3 AND compayny_goods_cd=v_prodcd;

					set v_prodcd = _prodcd;

					set v_text = concat('[{"cid": "' , _catcd , '", "shopcd": "' , _shopcd , '", "esm_auction": "", "esm_gmarket": ""}');

					set v_sw = 'lst';

				end if;

				

			END if;

		

		UNTIL done2 END REPEAT;

		

		if v_sw = 'lst' then 

			set v_text = concat(v_text , ']');

			
			UPDATE shopprodinfo SET SHOP_CID_INFO = v_text WHERE compno=3 AND compayny_goods_cd=v_prodcd;

			UPDATE shopprodin SET SHOP_CID_INFO = v_text WHERE compno=3 AND compayny_goods_cd=v_prodcd;

		end if;

			

		close c1;

	END;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_IMSI6` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_IMSI6`()
BEGIN
    DECLARE i INT DEFAULT 1; 
    WHILE (i <= 30000) DO 
		
		DELETE FROM shopprodinfo AS a 
		 WHERE NOT EXISTS(SELECT 1 FROM shopprodin AS b WHERE a.PRODSEQ=b.prodseq)
		 LIMIT 100;
		 
		DELETE FROM shop_optprodinfo AS a 
		 WHERE NOT EXISTS(SELECT 1 FROM shopprodin AS b WHERE a.PRODSEQ=b.prodseq)
		 LIMIT 100;
		 
		COMMIT;
		  
      SET i = i + 1; 
    END WHILE;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_IMSI7` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_IMSI7`()
BEGIN

	DECLARE _compno         		INT;

	DECLARE _shopid     				varchar(50);

	DECLARE _mall_product_id		varchar(50);

	DECLARE _compayny_goods_cd    varchar(50);

	DECLARE _sale_cnt   				INT;

	

	DECLARE done2 INT DEFAULT 0;

	DECLARE c1 CURSOR FOR  SELECT COMPNO,SHOPID,SUBSTRING_INDEX(MALL_PRODUCT_ID, ',', 1) as MALL_PRODUCT_ID,

											COMPAYNY_GOODS_CD,SUM(SALE_CNT) AS SALE_CNT

									 FROM SHOPORDMST

									WHERE compno=4

								GROUP BY COMPNO,SHOPID,MALL_PRODUCT_ID,COMPAYNY_GOODS_CD

								  HAVING SUM(SALE_CNT)>0;

	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done2 = 1;

	BEGIN

		OPEN c1;

		REPEAT

		FETCH NEXT FROM c1 INTO _compno,_shopid,_mall_product_id,_compayny_goods_cd,_sale_cnt;

		IF not done2 THEN

			UPDATE SHOPPRODIN SET DESCRITION = _sale_cnt 

			 WHERE compno = _compno 

			   AND shopcd = _shopid

			   AND shopprodno = _mall_product_id

			   AND compayny_goods_cd = _compayny_goods_cd;

		END if;

		COMMIT;

		UNTIL done2 END REPEAT;

		close c1;

	END;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_IMSI8` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_IMSI8`()
BEGIN

	DECLARE _compno         		INT;

	DECLARE _prodseq     			INT;

	DECLARE _sale_cnt   				INT;

	

	DECLARE done2 INT DEFAULT 0;

	DECLARE c1 CURSOR FOR  SELECT COMPNO,PRODSEQ,SUM(DESCRITION) AS SALE_CNT

									 FROM SHOPPRODIN

									WHERE compno=4

									  AND ifnull(DESCRITION,0) > 0

								GROUP BY COMPNO,PRODSEQ

								  HAVING SUM(DESCRITION)>0;

	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done2 = 1;

	BEGIN

		OPEN c1;

		REPEAT

		FETCH NEXT FROM c1 INTO _compno,_prodseq,_sale_cnt;

		IF not done2 THEN

			UPDATE SHOPPRODINFO SET DESCRITION = _sale_cnt 

			 WHERE compno	= _compno 

			 	AND prodseq	= _prodseq;

		END if;

		COMMIT;

		UNTIL done2 END REPEAT;

		close c1;

	END;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_INVENTORY_DETAIL` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_INVENTORY_DETAIL`(

	IN `V_COMPNO` INT,

	IN `V_BRANDCD` INT,

	IN `V_PRODCD` VARCHAR(20),

	IN `V_SDATE` VARCHAR(8),

	IN `V_EDATE` VARCHAR(8)

)
    COMMENT '재고현황 상세 검색에서 사용'
BEGIN

	DECLARE _stkdt varchar(8);

	BEGIN

		SELECT MAX(STKDT) INTO _stkdt FROM BASSTKMST WHERE COMPNO=V_COMPNO;

		

		CALL YWM_SETCODE(V_COMPNO, V_PRODCD, V_SDATE , V_EDATE);

		

		drop TEMPORARY TABLE if EXISTS tmp;

		CREATE TEMPORARY TABLE IF NOT EXISTS tmp ENGINE=MEMORY AS

		SELECT DISTINCT a.rsdate, sum(a.baseqty), sum(a.receiveqty), sum(a.saleqty), sum(a.baseqty)+sum(a.receiveqty)-sum(a.saleqty)

		  FROM (SELECT distinct REALDT as rsdate, 0 as baseqty, sum(AFTQTY) AS receiveqty, 0 AS saleqty

				    FROM RECVDTL

				   WHERE COMPNO = V_COMPNO

				     AND REALDT BETWEEN V_SDATE AND V_EDATE

				     AND PRODCD = V_PRODCD

				   group BY REALDT

				   UNION ALL

				   SELECT DISTINCT SUPPDT as rsdate, 0 as baseqty, 0 AS receiveqty, sum(qty) AS saleqty

				     FROM SUPPWARE

				    WHERE COMPNO = V_COMPNO

				     AND SUPPDT BETWEEN V_SDATE AND V_EDATE

				     AND PRODCD = V_PRODCD

				    GROUP BY SUPPDT

				    UNION all

				  
				  
				  
				  
				  SELECT distinct _stkdt as rsdate, sum(baseqty) as baseqty, 0 AS receiveqty, 0 AS saleqty

					FROM SUM_PRODWAREQTY

					WHERE PRODCD = V_PRODCD 

				   group BY _stkdt

				) a

		group by a.rsdate

		ORDER BY a.rsdate;

		

		drop TEMPORARY TABLE if EXISTS tmp2;

		CREATE TEMPORARY TABLE IF NOT EXISTS tmp2 ENGINE=MEMORY AS (select * from tmp LIMIT 1);

		delete from tmp2;

		

		Block1: BEGIN

			DECLARE v_qty int DEFAULT 0;

			DECLARE _rsdate varchar(8);

			DECLARE _baseqty int;

			DECLARE _receiveqty int;

			DECLARE _saleqty int;

			DECLARE _qty int;

			DECLARE first_sw int DEFAULT 1;

			DECLARE done INT DEFAULT 0; 

	   	DECLARE c1 CURSOR FOR SELECT * FROM tmp;

	   	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;

	

	   	OPEN c1;

	   	REPEAT

			FETCH c1 INTO _rsdate, _baseqty, _receiveqty, _saleqty, _qty;

			IF not done THEN

				if first_sw = 1 then

					set v_qty = _qty;

					set first_sw = 0;

				else

					set v_qty = v_qty + _qty;

				end if;

				insert into tmp2 values (_rsdate, _baseqty, _receiveqty, _saleqty, v_qty);

			END IF;

			UNTIL done END REPEAT;

			CLOSE c1;

		END Block1;

		

		select * from tmp2;

						 				 	 

	END;

	

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_MIGRATION_CREATE_BASS` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_MIGRATION_CREATE_BASS`(

	IN `V_COMPNO` INT

)
BEGIN

	
	
	
	
	DECLARE _prodcd  varchar(20);

	DECLARE _realqty  INT;

	
	DECLARE _stkdt varchar(8);

	

	DECLARE v_warecd int;

	DECLARE v_neccd1 varchar(200);

	DECLARE v_neccd2 int;

	DECLARE v_neccd3 int;

	



	DECLARE c1 CURSOR FOR SELECT PRODCD,REALQTY FROM BASSTKDTL WHERE compno=V_COMPNO AND stkdt=_stkdt;					   

	

	Block1: BEGIN

		

		
		DECLARE done INT DEFAULT 0;

		DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;

		

		SELECT MAX(STKDT) INTO _stkdt FROM BASSTKMST WHERE COMPNO=V_COMPNO;

		

		open c1;

		REPEAT

			FETCH NEXT FROM c1 INTO _prodcd,_realqty;

			IF not done THEN

			

				select ifnull(max(WARECD),1), ifnull(max(NECCD1),'A'), ifnull(max(NECCD2),1), ifnull(max(NECCD3),1) into v_warecd, v_neccd1, v_neccd2, v_neccd3 

				  from NECPRODMST 

				 where compno=V_COMPNO

				   and brandcd=1 

				   and prodcd=_prodcd;

				   

				IF (SELECT EXISTS (select 1 from SUM_WAREHOUSEQTY where compno=V_COMPNO and prodcd=_prodcd

					   AND WARECD = v_warecd 

					   AND NECCD1 = v_neccd1

					   AND NECCD2 = v_neccd2

					   AND NECCD3 = v_neccd3) AS FLAG) THEN

					   

					update SUM_WAREHOUSEQTY SET BASEQTY = BASEQTY + _realqty , WAREQTY = WAREQTY + _realqty 

					 where compno=V_COMPNO and prodcd=_prodcd

					   AND WARECD = v_warecd 

					   AND NECCD1 = v_neccd1

					   AND NECCD2 = v_neccd2

					   AND NECCD3 = v_neccd3;

					   

				else 

					insert into SUM_WAREHOUSEQTY(COMPNO, BRANDCD, PRODCD, WARECD, NECCD1, NECCD2, NECCD3, BASEQTY, BEF_RECEIVEQTY, RECEIVEQTY, SALEQTY, WAREQTY)

				              values(V_COMPNO,1,_prodcd, v_warecd, v_neccd1, v_neccd2, v_neccd3, _realqty, 0,0,0,_realqty);

				END IF;



			END IF;

		UNTIL done END REPEAT;

		close c1;			 

	END Block1;

	

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_MIGRATION_CREATE_RECV` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_MIGRATION_CREATE_RECV`(

	IN `V_COMPNO` INT

)
BEGIN

	
	
	
	
	DECLARE _recvdt  varchar(8);

	DECLARE _recvseq INT;

	DECLARE _seq  	  INT;

	DECLARE _prodcd  varchar(20);

	DECLARE _befqty  INT;

	DECLARE _aftqty  INT;

	DECLARE _realdt  varchar(8);

	DECLARE v_warecd int;

	DECLARE v_neccd1 varchar(200);

	DECLARE v_neccd2 int;

	DECLARE v_neccd3 int;

	DECLARE _stkdt varchar(8);



	DECLARE c1 CURSOR FOR SELECT RECVDT, RECVSEQ, SEQ, PRODCD, BEFQTY, AFTQTY,REALDT

									FROM RECVDTL

								  WHERE compno = V_COMPNO

									 and recvdt > _stkdt;

						   

	
	Block0: BEGIN	

		IF (SELECT EXISTS (SELECT 1 FROM RECVWARE where compno=V_COMPNO) AS FLAG) THEN

			delete from RECVWARE where compno=V_COMPNO;	

		END IF;	

		

		SELECT MAX(STKDT) INTO _stkdt FROM BASSTKMST WHERE COMPNO=V_COMPNO;

		set _stkdt = ifnull(_stkdt,'20181231');

 

	END Block0;						   

	

	Block1: BEGIN

		
		DECLARE done INT DEFAULT 0;

		DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;

		select _stkdt;

		open c1;

		REPEAT

			FETCH NEXT FROM c1 INTO _recvdt, _recvseq, _seq, _prodcd, _befqty, _aftqty, _realdt;

			IF not done THEN

				if _realdt = '' then 

					set _aftqty = 0;

				end if;

				

				select ifnull(max(WARECD),1), ifnull(max(NECCD1),'A'), ifnull(max(NECCD2),1), ifnull(max(NECCD3),1) into v_warecd, v_neccd1, v_neccd2, v_neccd3 

				  from NECPRODMST 

				 where compno=V_COMPNO 

				   and prodcd=_prodcd;

				   

				insert into RECVWARE(COMPNO, BRANDCD, RECVDT, RECVSEQ, SEQ, NECSEQ, PRODCD, WARECD, NECCD1, NECCD2, NECCD3, BEFQTY, AFTQTY)

				              values(V_COMPNO,1,_recvdt, _recvseq, _seq, 1, _prodcd, v_warecd, v_neccd1, v_neccd2, v_neccd3, _befqty, _aftqty);

				

			END IF;

		UNTIL done END REPEAT;

		close c1;			 

	END Block1;

	

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_MIGRATION_CREATE_SUPP` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_MIGRATION_CREATE_SUPP`(

	IN `V_COMPNO` INT,

	IN `V_BRANDCD` INT

)
BEGIN

	
	
	
	
	DECLARE _orddt varchar(8);

	DECLARE _ordseq  INT;

	DECLARE _seq  INT;

	DECLARE _dlvid varchar(100);

	DECLARE _invno varchar(100);

	DECLARE _rcvnam varchar(50);

	DECLARE _pstno varchar(10);

	DECLARE _addr varchar(200);

	DECLARE _expprodnm varchar(1000);

	DECLARE _sprodcdm varchar(20);

	DECLARE _sqty INT;

	DECLARE _picqty INT;

	

   DECLARE _prodcdm varchar(200);

   DECLARE _qty int;

   DECLARE _qty2 int;

   DECLARE _flagset char(1);

   DECLARE _levset char(1);

   DECLARE _proddtcd varchar(200);

   

   DECLARE u_orddt varchar(8);

	DECLARE u_ordseq  INT;

	DECLARE u_seq  INT;

   

   DECLARE v_warecd int;

   DECLARE v_neccd1 varchar(200);

   DECLARE v_neccd2 int;

   DECLARE v_neccd3 int;

   

   DECLARE _stkdt varchar(8);

   

	DECLARE v_seq INT DEFAULT 0;

	DECLARE v_necseq INT DEFAULT 0;



	DECLARE c2 CURSOR FOR SELECT orddt,ordseq,seq,dlvid,invno,rcvnam,pstno,addr,optdesc,a.prodcd,qty,qty as picqty ,b.prodcdm,b.flagset

								   FROM ORDDTL a, V_PRODUCTS b 

								  WHERE a.compno  = V_COMPNO

								    and a.ORDDT   > _stkdt

								    
								    
								    AND IFNULL(a.ORDAMT,0) <> 0 

							  		 AND a.compno  = b.compno

							  		 AND a.prodcd  = b.prodcd

							  		 AND b.delyn   = 'N' ;

	DECLARE c4 CURSOR FOR SELECT proddtcd, levset, qtyset

									FROM PRODDTL 

								  WHERE COMPNO  = V_COMPNO

									 and PRODCD  = _prodcdm 

									 AND ifnull(flagset,'')='1';

	DECLARE c5 CURSOR FOR SELECT proddtcd, levset, qtyset 

									FROM PRODDTL 

								  WHERE COMPNO  = V_COMPNO

									 and PRODCD  = _proddtcd

									 AND ifnull(flagset,'')='1';

									 

	
	Block0: BEGIN	

		
		
		
		
		
		

		SELECT MAX(STKDT) INTO _stkdt FROM BASSTKMST WHERE COMPNO=V_COMPNO and BRANDCD=V_BRANDCD;

		set _stkdt = ifnull(_stkdt,'20181231');

		

		commit;

			 

	END Block0;

	

	Block1: BEGIN

		
		DECLARE done INT DEFAULT 0;

		DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;

		

		
		select _stkdt;

		

		open c2;

		REPEAT

			FETCH NEXT FROM c2 INTO _orddt,_ordseq,_seq,_dlvid,_invno,_rcvnam,_pstno,_addr,_expprodnm,_sprodcdm,_sqty,_picqty,_prodcdm,_flagset;

			IF not done THEN

			



				set v_necseq = 0;

				IF (SELECT EXISTS (SELECT 1 FROM SUPPDTL where compno=V_COMPNO and brandcd=V_BRANDCD and suppdt=_orddt and suppseq=_ordseq and seq=_seq) AS FLAG) THEN

					set v_necseq = 0;

				else 

					INSERT INTO SUPPDTL(COMPNO, BRANDCD, SUPPDT, SUPPSEQ, SEQ, EXPNM, INVNO, ORDDT, ORDSEQ, ORDHSEQ, RCVNAM, PSTNO, ADDR, PRODCD, EXPPRODNM, QTY, PICQTY)

									 VALUES(V_COMPNO,V_BRANDCD,_orddt,_ordseq,_seq,_dlvid,_invno,_orddt,_ordseq,_seq,_rcvnam, _pstno, _addr, _prodcdm,_expprodnm,_sqty,_picqty);

									 

					
	

					IF _sprodcdm <> _prodcdm then

						SELECT flagset into _flagset FROM PRODMST WHERE COMPNO = V_COMPNO and prodcd =_prodcdm;

					end if;



					IF ifnull(_flagset,'') = '1' then

						Block4: BEGIN

							DECLARE done4 INT DEFAULT 0;

							DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done4 = 1;

							open c4;

							REPEAT

								FETCH NEXT FROM c4 INTO _proddtcd,_levset,_qty2;

								IF not done4 THEN 

									IF IFNULL(_levset,'') = '2' THEN

										Block5: BEGIN

											DECLARE done5 INT DEFAULT 0;

											DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done5 = 1;

											open c5;

											REPEAT

												FETCH NEXT FROM c5 INTO _proddtcd,_levset,_qty2;

												IF not done5 THEN 

													

													set v_necseq = v_necseq + 1;

												   select ifnull(max(WARECD),1), ifnull(max(NECCD1),'A'), ifnull(max(NECCD2),1), ifnull(max(NECCD3),1) into v_warecd, v_neccd1, v_neccd2, v_neccd3 

													  from NECPRODMST 

													 where compno=V_COMPNO and prodcd=_prodcdm;

													insert into SUPPWARE(COMPNO, BRANDCD, SUPPDT, SUPPSEQ, SEQ, NECSEQ, ADDSEQ, PRODCDM, PRODCD, SETLEVEL, WARECD, NECCD1, NECCD2, NECCD3, QTY) 

													VALUES(V_COMPNO,V_BRANDCD,_orddt,_ordseq,_seq,v_necseq,1,_prodcdm,_proddtcd,3,v_warecd,v_neccd1,v_neccd2,v_neccd3,_picqty*_qty2);

												END IF;

											UNTIL done5 END REPEAT;

											close c5;

										END Block5;

									ELSE

	

										set v_necseq = v_necseq + 1;

									   select ifnull(max(WARECD),1), ifnull(max(NECCD1),'A'), ifnull(max(NECCD2),1), ifnull(max(NECCD3),1) into v_warecd, v_neccd1, v_neccd2, v_neccd3 

										  from NECPRODMST 

										 where compno=V_COMPNO and prodcd=_prodcdm;

										insert into SUPPWARE(COMPNO, BRANDCD, SUPPDT, SUPPSEQ, SEQ, NECSEQ, ADDSEQ, PRODCDM, PRODCD, SETLEVEL, WARECD, NECCD1, NECCD2, NECCD3, QTY) 

										VALUES(V_COMPNO,V_BRANDCD,_orddt,_ordseq,_seq,v_necseq,1,_prodcdm,_proddtcd,2,v_warecd,v_neccd1,v_neccd2,v_neccd3,_picqty*_qty2);

									END IF;

								END IF;

							

							UNTIL done4 END REPEAT;

							close c4;

						END Block4;

					else

					   

					   set v_necseq = v_necseq + 1;

					   select ifnull(max(WARECD),1), ifnull(max(NECCD1),'A'), ifnull(max(NECCD2),1), ifnull(max(NECCD3),1) into v_warecd, v_neccd1, v_neccd2, v_neccd3 

						  from NECPRODMST 

						 where compno=V_COMPNO and prodcd=_prodcdm;

						insert into SUPPWARE(COMPNO, BRANDCD, SUPPDT, SUPPSEQ, SEQ, NECSEQ, ADDSEQ, PRODCDM, PRODCD, SETLEVEL, WARECD, NECCD1, NECCD2, NECCD3, QTY) 

						VALUES(V_COMPNO,V_BRANDCD,_orddt,_ordseq,_seq,v_necseq,1,_prodcdm,_prodcdm,1,v_warecd,v_neccd1,v_neccd2,v_neccd3,_picqty);

						

					END IF;

				END IF;

			END IF;

		

			commit;

		

		UNTIL done END REPEAT;

		close c2;			 

	END Block1;

	

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_ORDERAUTO_PROC` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_ORDERAUTO_PROC`(

	IN `V_COMPNO` INT,

	IN `V_DIRTGUBUN` CHAR(1),

	IN `V_ORDDT` VARCHAR(8),

	IN `V_PRODCD` VARCHAR(20),

	IN `V_QTY` INT,

	IN `V_INSERTID` VARCHAR(20)

)
BEGIN

	
	
	
	
	
	DECLARE _AFTQTY varchar(20) default V_QTY;

	DECLARE _REALDT varchar(8) default V_ORDDT;

	DECLARE _CONFNAM varchar(20) default V_INSERTID;

	DECLARE v_maxrecvseq INT;

	

	Block3: BEGIN

	

		
		if V_DIRTGUBUN = '1' then set _AFTQTY = 0; set _REALDT = null; set _CONFNAM = null; end if;

		

		set v_maxrecvseq = 0;

		SELECT MAX(RECVSEQ) INTO v_maxrecvseq FROM RECVMST WHERE COMPNO = V_COMPNO AND RECVDT = V_ORDDT;

		

		INSERT INTO RECVMST(COMPNO,RECVDT,RECVSEQ,RECVGUBUN,ENTDT,RECVDESC,BEFQTY,REALDT,AFTQTY,CONFNAM,AUTOCHK,INSERTDT,INSERTID) 

					    VALUES(V_COMPNO,V_ORDDT,IFNULL(v_maxrecvseq,0)+1,'입고',V_ORDDT,V_PRODCD,V_QTY,_REALDT,_AFTQTY,_CONFNAM,'1',NOW(),V_INSERTID);

		INSERT INTO RECVDTL(COMPNO,RECVDT,RECVSEQ,SEQ,PRODCD,BEFQTY,AFTQTY,REALDT,INSERTDT,INSERTID) 

					    VALUES(V_COMPNO,V_ORDDT,IFNULL(v_maxrecvseq,0)+1,1,V_PRODCD,V_QTY,_AFTQTY,_REALDT,NOW(),V_INSERTID);

					 

	END Block3;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_PERIOD_PRODWARE_LIST` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_PERIOD_PRODWARE_LIST`(

	IN `V_COMPNO` INT,

	IN `V_BRANDCD` INT,

	IN `V_BDATE` VARCHAR(8),

	IN `V_SDATE` VARCHAR(8),

	IN `V_EDATE` VARCHAR(8),

	IN `V_OPT` INT,

	IN `V_PROD` VARCHAR(100)

)
    COMMENT '기간 재고 현황에서 사용'
BEGIN

	

	BEGIN



		
		

		SET @xSql = CONCAT("

						SELECT DISTINCT a.prodcd, YWM_FUNC_BOSSPRODCD(",V_COMPNO, ",",V_BRANDCD, ",a.prodcd) as img,   b.prodnm,b.specdes,

											 ifnull(SUM(a.baseqty),0) AS baseqty,ifnull(SUM(a.receiveqty),0) AS receiveqty,ifnull(SUM(a.saleqty),0) AS saleqty,

											 ifnull(SUM(a.baseqty),0) + ifnull(SUM(a.receiveqty),0) - ifnull(SUM(a.saleqty),0) as inwareqty,

											 ifnull(sum(a.befqty),0) as befqty, ifnull(sum(a.day3befqty),0) as day3befqty,ifnull(sum(a.retnqty),0) as retnqty,

											 (ifnull(SUM(a.baseqty),0) + ifnull(SUM(a.receiveqty),0) - ifnull(SUM(a.saleqty),0) ) + ifnull(sum(a.befqty),0) + ifnull(sum(a.retnqty),0) as warqty

						  FROM (SELECT distinct prodcd,0 as befqty, sum(realqty) as baseqty, 0 AS receiveqty, 0 AS saleqty,0 as retnqty,0 as day3befqty

									 FROM BASSTKDTL 

								   WHERE COMPNO = ", V_COMPNO, "

								     AND BRANDCD = ", V_BRANDCD, "

								     AND STKDT = ", V_BDATE, "

								   group BY prodcd

								  UNION all	

								  SELECT distinct prodcd, 0 as befqty, 0 as baseqty, sum(AFTQTY) AS receiveqty, 0 AS saleqty,0 as retnqty,0 as day3befqty

									 FROM RECVWARE

								   WHERE COMPNO = ", V_COMPNO, " 

								     AND BRANDCD = ", V_BRANDCD, "

								     AND RECVDT BETWEEN ", V_SDATE," AND ", V_EDATE, "

								   group BY prodcd

								  UNION all

								   SELECT distinct prodcd, 0 as befqty, 0 as baseqty, 0 AS receiveqty, SUM(qty) AS saleqty,0 as retnqty,0 as day3befqty

									 FROM SUPPWARE

								   WHERE COMPNO = ", V_COMPNO, " 

								     AND BRANDCD = ", V_BRANDCD, "

								     AND suppdt BETWEEN ", V_SDATE," AND ", V_EDATE, "

								   group BY prodcd							

								  UNION all

								  SELECT distinct prodcd, sum(A.befqty) as befqty, 0 as baseqty, 0 AS receiveqty, 0 AS saleqty,0 as retnqty,0 as day3befqty

									 FROM RECVDTL A, RECVMST B

								   WHERE A.COMPNO = ", V_COMPNO, " 

								   AND A.BRANDCD = ", V_BRANDCD, "

								     AND IFNULL(A.befqty,0) <> 0 

									  AND IFNULL(A.aftqty,0) = 0

									  AND A.COMPNO=B.COMPNO

									  AND A.BRANDCD = B.BRANDCD

									  AND A.RECVDT=B.RECVDT

									  AND A.RECVSEQ=B.RECVSEQ

									  AND B.RECVGUBUN <> '반품'

									group BY A.prodcd

								  UNION all

								  SELECT distinct prodcd, 0 as befqty, 0 as baseqty, 0 AS receiveqty, 0 AS saleqty,sum(A.befqty) as retnqty,0 as day3befqty

									 FROM RECVDTL A, RECVMST B

								   WHERE A.COMPNO = ", V_COMPNO, " 

								     AND IFNULL(A.befqty,0) <> 0 

									  AND IFNULL(A.aftqty,0) = 0

									  AND A.COMPNO=B.COMPNO

									  AND A.RECVDT=B.RECVDT

									  AND A.RECVSEQ=B.RECVSEQ

									  AND B.RECVGUBUN = '반품'

								   group BY prodcd

								  UNION all

								  SELECT distinct A.prodcd, 0 as befqty, 0 as baseqty, 0 AS receiveqty, 0 AS saleqty,0 as retnqty,sum(A.befqty) as day3befqty

									 FROM RECVDTL A, RECVMST B

								   WHERE A.COMPNO = ", V_COMPNO, " 

								   AND A.BRANDCD = ", V_BRANDCD, "

								     AND A.PLANDT >= ", V_EDATE, "

									  AND A.PLANDT <= YWM_FUNC_WORKING_DAY(", V_EDATE, " ,3)

									  and ifnull(A.befqty,0) <> 0 

									  AND ifnull(A.aftqty,0) = 0

									  AND A.COMPNO =B.COMPNO

									   AND A.BRANDCD = B.BRANDCD

									  AND A.RECVDT =B.RECVDT

									  AND A.RECVSEQ=B.RECVSEQ

									  AND B.RECVGUBUN <> '반품'

								   group BY A.prodcd

								) a, PRODMST b

						 where b.compno=", V_COMPNO, " and a.prodcd=b.prodcd  ");

						 				 

       if V_OPT = 1 then					 

		    SET @v_colsql = CONCAT(@xSql, " and b.prodnm  like ?

									 group BY a.prodcd,b.prodnm,b.specdes 

									 order by b.prodnm" );

		 end if;

		 if V_OPT = 0 then					 

		    SET @v_colsql = CONCAT(@xSql, " and a.prodcd  like ?

									 group BY a.prodcd,b.prodnm,b.specdes 

									 order by a.prodcd" );

		 end if;

		 

		 set @temp2 = V_PROD;				

		 				 

		 PREPARE dSql FROM @v_colsql;

		 EXECUTE dSql USING @temp2;

		 DEALLOCATE PREPARE dSql;

		 	 

	END;

	

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_PERIOD_SALE_LIST` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_PERIOD_SALE_LIST`(

	IN `V_COMPNO` INT,

	IN `V_BRANDCD` INT,

	IN `V_SDATE` VARCHAR(8),

	IN `V_EDATE` VARCHAR(8),

	IN `V_OPT` INT,

	IN `V_PROD` VARCHAR(100),

	IN `V_WGUBUN` INT

)
    COMMENT '기간판매 현황에서 사용'
BEGIN



	DECLARE _stkdt varchar(8);

	DECLARE _sdt varchar(8);

	

	BEGIN



		
		

		if V_WGUBUN = 0 THEN

			SET @xSql = CONCAT("

						SELECT DISTINCT a.prodcd, YWM_FUNC_BOSSPRODCD(",V_COMPNO, ",", V_BRANDCD, ", a.prodcd ) as img,   b.prodnm, b.specdes, a.saleqty, a.saleqty*b.price AS saleamt,

						                0 as inwareqty

						  FROM  (

						  	 SELECT distinct prodcd, sum(qty) AS saleqty

									FROM SUPPWARE 

								  WHERE compno = ", V_COMPNO, "

								    AND brandcd = ", V_BRANDCD, "

								    AND SUPPDT BETWEEN ", V_SDATE," AND ", V_EDATE, "

								   group BY prodcd ) a, PRODMST b

						 where b.compno=", V_COMPNO, " AND b.brandcd=", V_BRANDCD, "  and a.prodcd=b.prodcd  "); 

		ELSE

			SELECT MAX(STKDT) INTO _stkdt FROM BASSTKMST WHERE COMPNO=V_COMPNO AND BRANDCD = V_BRANDCD;

			set _stkdt = ifnull(_stkdt,'20181231');

			SELECT DATE_FORMAT(DATE_ADD(_stkdt, INTERVAL 1 DAY),'%Y%m%d') into _sdt FROM dual;

			

			SET @xSql = CONCAT("

						SELECT DISTINCT a.prodcd, YWM_FUNC_BOSSPRODCD(",V_COMPNO, ",", V_BRANDCD, ", a.prodcd ) as img, b.prodnm, b.specdes, sum(a.saleqty), sum(a.saleqty)*b.price AS saleamt,

										    sum(a.inwareqty) AS inwareqty

						  FROM (

						  		SELECT distinct prodcd as prodcd, 0 as baseqty, 0 AS receiveqty, sum(qty) AS saleqty,0 AS inwareqty

									FROM SUPPWARE 

								  WHERE compno = ", V_COMPNO, "

								    AND brandcd = ", V_BRANDCD, "

								    AND SUPPDT BETWEEN ", V_SDATE," AND ", V_EDATE, "

								   group BY prodcd

								  UNION all

								  SELECT distinct prodcd AS prodcd, 0 AS baseqty , 0 AS receiveqty, 0 as saleqty, SUM(WAREQTY) AS inwareqty

									 FROM SUM_WAREHOUSEQTY

									 where compno = ", V_COMPNO, "

									 AND brandcd  =", V_BRANDCD, " 

								   group BY prodcd 

									) a, PRODMST b

						 where b.compno=", V_COMPNO, "  AND b.brandcd=", V_BRANDCD, " and a.prodcd=b.prodcd  ");

		END IF;



											 

		if V_OPT = 1 then					 

			SET @v_colsql = CONCAT(@xSql, " and b.prodnm  like ?

									 group BY a.prodcd,b.prodnm,b.specdes ,b.price

									 order by b.prodnm" );

		end if;

		if V_OPT = 0 then					 

			SET @v_colsql = CONCAT(@xSql, " and a.prodcd  like ?

									 group BY a.prodcd,b.prodnm,b.specdes ,b.price

									 order by a.prodcd" );

		end if;

		 

		set @temp2 = V_PROD;				

						 

		PREPARE dSql FROM @v_colsql;

		EXECUTE dSql USING @temp2;

		DEALLOCATE PREPARE dSql;

			 

	END;

	

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_PRODWAREQTY_LIST` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_PRODWAREQTY_LIST`(

	IN `V_COMPNO` INT,

	IN `V_OPT` INT,

	IN `V_PROD` VARCHAR(100)

)
    COMMENT '상품 수불부 리스트(재고 집계 테이블 생성시 사용)'
BEGIN

 

	DECLARE _stkdt varchar(8);

	DECLARE _sdt varchar(8);

	DECLARE _edt varchar(8);

	

	BEGIN

		SELECT MAX(STKDT) INTO _stkdt FROM BASSTKMST WHERE COMPNO = V_COMPNO;

		set _stkdt = ifnull(_stkdt,'20181231');



		SELECT DATE_FORMAT(DATE_ADD(_stkdt, INTERVAL 1 DAY),'%Y%m%d') into _sdt FROM dual;

		set _edt = DATE_FORMAT(now(),'%Y%m%d');



		CALL YWM_SETCODELIST(V_COMPNO,_sdt,_edt);

		SET @xSql = CONCAT("

						SELECT DISTINCT a.prodcd, b.prodnm,b.specdes,

											 ifnull(SUM(a.baseqty),0) AS baseqty,ifnull(SUM(a.receiveqty),0) AS receiveqty,ifnull(SUM(a.saleqty),0) AS saleqty,

											 ifnull(SUM(a.baseqty),0) + ifnull(SUM(a.receiveqty),0) - ifnull(SUM(a.saleqty),0) as inwareqty,

											 ifnull(sum(a.befqty),0) as befqty,ifnull(sum(a.retnqty),0) as retnqty,

											 (ifnull(SUM(a.baseqty),0) + ifnull(SUM(a.receiveqty),0) - ifnull(SUM(a.saleqty),0) ) + ifnull(sum(a.befqty),0) + ifnull(sum(a.retnqty),0) as warqty

						  FROM (SELECT distinct prodcd,0 as befqty, sum(realqty) as baseqty, 0 AS receiveqty, 0 AS saleqty,0 as retnqty

									 FROM BASSTKDTL 

								   WHERE COMPNO = ", V_COMPNO, "

								     AND STKDT = ", _stkdt, "

								   group BY prodcd

								  UNION all

								  SELECT distinct prodcd, 0 as befqty, 0 as baseqty, sum(AFTQTY) AS receiveqty, 0 AS saleqty,0 as retnqty

									 FROM RECVDTL

								   WHERE COMPNO = ", V_COMPNO, "

								     AND REALDT BETWEEN ", _sdt," AND ", _edt, "

								   group BY prodcd

								  UNION all

								  SELECT distinct prodcdm as prodcd, 0 as befqty, 0 as baseqty, 0 AS receiveqty, sum(qty) AS saleqty,0 as retnqty

									 FROM WAREHOUSE_QTY_TMP2 

								   group BY prodcdm

								  UNION all

								  SELECT distinct prodcd, sum(A.befqty) as befqty, 0 as baseqty, 0 AS receiveqty, 0 AS saleqty,0 as retnqty

									 FROM RECVDTL A, RECVMST B

								   WHERE A.COMPNO = ", V_COMPNO, "

								      AND IFNULL(A.befqty,0) <> 0 

									  AND IFNULL(A.aftqty,0) = 0

									  AND A.COMPNO=B.COMPNO

									  AND A.RECVDT=B.RECVDT

									  AND A.RECVSEQ=B.RECVSEQ

									  AND B.RECVGUBUN <> '반품'

								   group BY prodcd

								  UNION all

								  SELECT distinct prodcd, 0 as befqty, 0 as baseqty, 0 AS receiveqty, 0 AS saleqty,sum(A.befqty) as retnqty

									 FROM RECVDTL A, RECVMST B

								   WHERE A.COMPNO = ", V_COMPNO, "

								      AND IFNULL(A.befqty,0) <> 0 

									  AND IFNULL(A.aftqty,0) = 0

									  AND A.COMPNO=B.COMPNO

									  AND A.RECVDT=B.RECVDT

									  AND A.RECVSEQ=B.RECVSEQ

									  AND B.RECVGUBUN = '반품'

								   group BY prodcd

								) a, PRODMST b

						 where b.compno=", V_COMPNO, " and a.prodcd=b.prodcd  ");

						 				 

       if V_OPT = 1 then					 

		    SET @v_colsql = CONCAT(@xSql, " and b.prodnm  like ?

									 group BY a.prodcd,b.prodnm,b.specdes 

									 order by b.prodnm" );

		 end if;

		 if V_OPT = 0 then					 

		    SET @v_colsql = CONCAT(@xSql, " and a.prodcd  like ?

									 group BY a.prodcd,b.prodnm,b.specdes 

									 order by a.prodcd" );

		 end if;

		 

		 set @temp2 = V_PROD;				

		 				 

		 PREPARE dSql FROM @v_colsql;

		 EXECUTE dSql USING @temp2;

		 DEALLOCATE PREPARE dSql;

		 	 

	END;

	

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_PRODWAREQTY_LIST_REFRESH` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_PRODWAREQTY_LIST_REFRESH`(

	IN `V_COMPNO` INT,

	IN `V_BRANDCD` INT

)
    COMMENT '오늘 이전의 입고 또는 출고내역을 삭제 했을경우 집계테이블을 다시 생성 해줄때 사용'
BEGIN

 

	DECLARE _stkdt varchar(8);

	DECLARE _sdt varchar(8);

	DECLARE _edt varchar(8);

	DECLARE _edt2 varchar(8);

	

	BEGIN

		SELECT MAX(STKDT) INTO _stkdt FROM BASSTKMST WHERE COMPNO=V_COMPNO and BRANDCD=V_BRANDCD;

		set _stkdt = ifnull(_stkdt,'20181231');



		SELECT DATE_FORMAT(DATE_ADD(_stkdt, INTERVAL 1 DAY),'%Y%m%d') into _sdt FROM dual;

		SELECT DATE_FORMAT(DATE_ADD(now(), INTERVAL -1 DAY),'%Y%m%d') into _edt FROM dual;

		set _edt2 = DATE_FORMAT(now(),'%Y%m%d');



		
		

		
		
		
		
		
		
		SET @xSql = CONCAT("

						SELECT DISTINCT a.prodcd, b.prodnm,b.specdes,

											 ifnull(SUM(a.baseqty),0) AS baseqty,ifnull(SUM(a.receiveqty),0) AS receiveqty,ifnull(SUM(a.saleqty),0) AS saleqty,

											 ifnull(SUM(a.baseqty),0) + ifnull(SUM(a.receiveqty),0) - ifnull(SUM(a.saleqty),0) as inwareqty,

											 ifnull(sum(a.befqty),0) as befqty,ifnull(sum(a.retnqty),0) as retnqty,

											 (ifnull(SUM(a.baseqty),0) + ifnull(SUM(a.receiveqty),0) - ifnull(SUM(a.saleqty),0) ) + ifnull(sum(a.befqty),0) + ifnull(sum(a.retnqty),0) as warqty

						  FROM (

						  			#sum_warehouseqty 에서 기초재고,입고수량,판매수량 가지고 오는거

						  			SELECT distinct prodcd,0 as befqty, sum(baseqty) as baseqty, SUM(receiveqty) AS receiveqty, sum(saleqty) AS saleqty, 0 as retnqty									      

									 FROM SUM_WAREHOUSEQTY

								   WHERE COMPNO = ", V_COMPNO, "

								     AND BRANDCD = ", V_BRANDCD, "

								   group BY prodcd

								  UNION all

								  SELECT distinct prodcd, sum(A.befqty) as befqty, 0 as baseqty, 0 AS receiveqty, 0 AS saleqty,0 as retnqty

									 FROM RECVDTL A, RECVMST B

								   WHERE A.COMPNO = ", V_COMPNO, "

								     AND A.BRANDCD = ", V_BRANDCD, "

								     AND A.REALDT = ", _edt2, "

								     and A.RECVDT < ", _edt2, "

									  AND A.COMPNO=B.COMPNO

									  AND A.BRANDCD=B.BRANDCD

									  AND A.RECVDT=B.RECVDT

									  AND A.RECVSEQ=B.RECVSEQ

									  AND B.RECVGUBUN <> '반품'

								   group BY prodcd

								  UNION all

								  SELECT distinct prodcd, sum(A.befqty) as befqty, 0 as baseqty, 0 AS receiveqty, 0 AS saleqty,0 as retnqty

									 FROM RECVDTL A, RECVMST B

								   WHERE A.COMPNO = ", V_COMPNO, "

								     AND A.BRANDCD = ", V_BRANDCD, "

								     AND A.RECVDT < ", _edt2, "

								     AND IFNULL(A.befqty,0) <> 0 

									  AND IFNULL(A.aftqty,0) = 0

									  AND A.COMPNO=B.COMPNO

									  AND A.BRANDCD=B.BRANDCD

									  AND A.RECVDT=B.RECVDT

									  AND A.RECVSEQ=B.RECVSEQ

									  AND B.RECVGUBUN <> '반품'

								   group BY prodcd

								  UNION all

								  SELECT distinct prodcd, 0 as befqty, 0 as baseqty, 0 AS receiveqty, 0 AS saleqty,sum(A.befqty) as retnqty

									 FROM RECVDTL A, RECVMST B

								   WHERE A.COMPNO = ", V_COMPNO, "

								     AND A.BRANDCD = ", V_BRANDCD, "

								      AND IFNULL(A.befqty,0) <> 0 

									  AND IFNULL(A.aftqty,0) = 0

									  AND A.COMPNO=B.COMPNO

									  AND A.BRANDCD=B.BRANDCD

									  AND A.RECVDT=B.RECVDT

									  AND A.RECVSEQ=B.RECVSEQ

									  AND B.RECVGUBUN = '반품'

								   group BY prodcd

								) a, PRODMST b

						 where b.compno=", V_COMPNO, " and b.brandcd=", V_BRANDCD, " and a.prodcd=b.prodcd  

						 group BY a.prodcd,b.prodnm,b.specdes ");				

		 				 

		 PREPARE dSql FROM @xSql;

		 EXECUTE dSql ;

		 DEALLOCATE PREPARE dSql;

		 	 

	END;

	

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_PRODWAREQTY_LIST_WSUM` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_PRODWAREQTY_LIST_WSUM`(

	IN `V_COMPNO` INT,

	IN `V_BRANDCD` INT,

	IN `V_OPT` INT,

	IN `V_PROD` VARCHAR(100)

)
    COMMENT '재고현황 조회시 사용'
BEGIN

 

	DECLARE _edt varchar(8);

	

	BEGIN



		set _edt = DATE_FORMAT(now(),'%Y%m%d');

		
		

		SET @xSql = CONCAT("

						SELECT DISTINCT a.prodcd, YWM_FUNC_BOSSPRODCD(",V_COMPNO, ",",V_BRANDCD, ",a.prodcd) as img,

											 b.prodnm,b.specdes,

											 ifnull(SUM(a.baseqty),0) AS baseqty,ifnull(SUM(a.receiveqty),0) AS receiveqty,ifnull(SUM(a.saleqty),0) AS saleqty,

											 ifnull(SUM(a.baseqty),0) + ifnull(SUM(a.receiveqty),0) - ifnull(SUM(a.saleqty),0) as inwareqty,

											 ifnull(sum(a.befqty),0) as befqty, ifnull(sum(a.day3befqty),0) as day3befqty, ifnull(sum(a.retnqty),0) as retnqty,

											 (ifnull(SUM(a.baseqty),0) + ifnull(SUM(a.receiveqty),0) - ifnull(SUM(a.saleqty),0) ) + ifnull(sum(a.befqty),0) + ifnull(sum(a.retnqty),0) as warqty,

											 max(a.rak1), max(a.rak2), max(a.rak3), max(a.rak4), max(a.rak5) 				 

						  FROM (

						  			#sum_warehouseqty 에서 기초재고,입고수량,판매수량 가지고 오는거

						  			SELECT distinct prodcd, 0 as befqty, sum(baseqty) as baseqty, SUM(receiveqty) AS receiveqty, sum(saleqty) AS saleqty, 0 as retnqty, 0 as day3befqty,

									      '' AS recvdt, '' as rak1, '' as rak2, '' as rak3, '' as rak4, '' as rak5									      

									 FROM SUM_WAREHOUSEQTY

								   WHERE COMPNO = ", V_COMPNO, "

								     AND BRANDCD = ", V_BRANDCD, "

								   group BY prodcd

								  UNION all

								  #인천항 재고 가지고 오는거 반품이 아니면서 입고일자가 오늘이고 일자가 전일인거

								 # SELECT distinct prodcd, sum(A.AFTQTY)*-1 as befqty, 0 as baseqty, 0 AS receiveqty, 0 AS saleqty, 0 as retnqty,0 as day3befqty,

								#		   '' AS recvdt, '' as rak1, '' as rak2, '' as rak3, '' as rak4, '' as rak5

								#	 FROM RECVDTL A, RECVMST B

								#   WHERE A.COMPNO = ", V_COMPNO, "

								#     AND A.BRANDCD = ", V_BRANDCD, "

								#     AND A.REALDT = ", _edt, "

								#     and A.RECVDT < ", _edt, "

								#	  AND A.COMPNO =B.COMPNO

								#	  AND A.BRANDCD = B.BRANDCD

								#     AND A.RECVDT =B.RECVDT

								#	  AND A.RECVSEQ=B.RECVSEQ

								#	  AND B.RECVGUBUN <> '반품'

								#   group BY prodcd

								#  UNION all

								  #인천항 재고 가지고 오는거 반품이 아니면서 입고수량이0이면서 입고확정수량이 0이 아닌거

								   SELECT distinct A.prodcd, sum(A.befqty) as befqty, 0 as baseqty, 0 AS receiveqty, 0 AS saleqty, 0 as retnqty,0 as day3befqty,

										   '' AS recvdt, '' as rak1, '' as rak2, '' as rak3, '' as rak4, '' as rak5

									 FROM RECVDTL A, RECVMST B

								   WHERE A.COMPNO = ", V_COMPNO, "

								     AND A.BRANDCD = ", V_BRANDCD, "

								     #AND A.RECVDT = ", _edt, "

									  and ifnull(A.befqty,0) <> 0 

									  AND ifnull(A.aftqty,0) = 0

									  AND A.COMPNO =B.COMPNO

									  AND A.BRANDCD = B.BRANDCD

									  AND A.RECVDT =B.RECVDT

									  AND A.RECVSEQ=B.RECVSEQ

									  AND B.RECVGUBUN <> '반품'

								   group BY A.prodcd

								  UNION all

								  #반품 미확인 수량

								  SELECT distinct prodcd, 0 as befqty, 0 as baseqty, 0 AS receiveqty, 0 AS saleqty, sum(A.AFTQTY)*-1 as retnqty,0 as day3befqty,

										   '' AS recvdt, '' as rak1, '' as rak2, '' as rak3, '' as rak4, '' as rak5

									 FROM RECVDTL A, RECVMST B

								   WHERE A.COMPNO = ", V_COMPNO, "

								     AND A.BRANDCD = ", V_BRANDCD, "

								     AND A.REALDT = ", _edt, "

								     and A.RECVDT < ", _edt, "

									  AND A.COMPNO =B.COMPNO

									  AND A.BRANDCD = B.BRANDCD

								     AND A.RECVDT =B.RECVDT

									  AND A.RECVSEQ=B.RECVSEQ

									  AND B.RECVGUBUN = '반품'

								   group BY prodcd

								  UNION all	

								  #반품미확인수량							 

								  SELECT distinct A.prodcd, 0 as befqty, 0 as baseqty, 0 AS receiveqty, 0 AS saleqty,sum(A.befqty) as retnqty,0 as day3befqty,

										   '' AS recvdt, '' as rak1, '' as rak2, '' as rak3, '' as rak4, '' as rak5

									 FROM RECVDTL A, RECVMST B

								   WHERE A.COMPNO = ", V_COMPNO, "

								     AND A.BRANDCD = ", V_BRANDCD, "

								     AND A.RECVDT = ", _edt, "

									  and ifnull(A.befqty,0) <> 0 

									  AND ifnull(A.aftqty,0) = 0

									  AND A.COMPNO =B.COMPNO

									  AND A.BRANDCD = B.BRANDCD

									  AND A.RECVDT =B.RECVDT

									  AND A.RECVSEQ=B.RECVSEQ

									  AND B.RECVGUBUN = '반품'

								   group BY A.prodcd

								  UNION all

								  #3일후 입고수량

								  SELECT distinct A.prodcd, 0 as befqty, 0 as baseqty, 0 AS receiveqty, 0 AS saleqty,0 as retnqty,sum(A.befqty) as day3befqty,

								         '' AS recvdt, '' as rak1, '' as rak2, '' as rak3, '' as rak4, '' as rak5 

									 FROM RECVDTL A, RECVMST B

								   WHERE A.COMPNO = ", V_COMPNO, "

								   AND A.BRANDCD = ", V_BRANDCD, "

								     AND A.PLANDT >= ", _edt, "

									  AND A.PLANDT <= YWM_FUNC_WORKING_DAY(", _edt, ",3)

									  and ifnull(A.befqty,0) <> 0 

									  AND ifnull(A.aftqty,0) = 0

									  AND A.COMPNO =B.COMPNO

									  AND A.BRANDCD = B.BRANDCD

									  AND A.RECVDT =B.RECVDT

									  AND A.RECVSEQ=B.RECVSEQ

									  AND B.RECVGUBUN <> '반품'

								   group BY A.prodcd

								  UNION all

								  #랙가지고오기

								  SELECT distinct prodcd, 0 as befqty, 0 as baseqty, 0 AS receiveqty, 0 AS saleqty, 0 as retnqty,

										   0 as day3befqty, 

										   MAX(recvdt) AS recvdt, max(sparerack1) as rak1, max(sparerack2) as rak2, max(sparerack3) as rak3, max(sparerack4) as rak4, max(sparerack5) as rak5 

									 FROM RECVDTL re

									WHERE re.compno = ", V_COMPNO, "

									  AND re.BRANDCD = ", V_BRANDCD, "

									  AND ifnull(re.sparerack1,'') <> ''

									  and re.recvdt = (select  MAX(recvdt) from RECVDTL where compno=re.compno AND brandcd = re.brandcd  and prodcd=re.prodcd AND ifnull(sparerack1,'') <> '')

									group BY re.prodcd

								) a, PRODMST b

						 where b.compno=", V_COMPNO, " AND b.brandcd = ", V_BRANDCD, " and a.prodcd=b.prodcd  ");

						 				 

       if V_OPT = 1 then					 

		    SET @v_colsql = CONCAT(@xSql, " and b.prodnm  like ?

									 group BY a.prodcd,b.prodnm,b.specdes 

									 order by b.prodnm" );

		 end if;

		 if V_OPT = 0 then					 

		    SET @v_colsql = CONCAT(@xSql, " and a.prodcd  like ?

									 group BY a.prodcd,b.prodnm,b.specdes 

									 order by a.prodcd" );

		 end if;

		 

		 set @temp2 = V_PROD;				

		 				 

		 PREPARE dSql FROM @v_colsql;

		 EXECUTE dSql USING @temp2;

		 DEALLOCATE PREPARE dSql;

		 	 

	END;

	

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_RACKPICUP_LIST` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_RACKPICUP_LIST`(

	IN `V_COMPNO` INT,

	IN `V_BRANDCD` INT,

	IN `V_ORDDT` VARCHAR(20),

	IN `V_ORDSEQ` INT








)
    COMMENT '주문번호를 입력 받아서 랙별 픽업리스트 출력용 (세트상품을 감안 하여 재고관리용 상품코드로 풀어준다)'
BEGIN

	drop TEMPORARY TABLE if EXISTS tmp;

	CREATE TEMPORARY TABLE IF NOT EXISTS tmp ENGINE=MEMORY AS

	(SELECT a.prodcd, b.prodcdm, a.qty, b.flagset 

	   FROM ORDDTL a, V_PRODUCTS b 

	  WHERE a.compno = V_COMPNO 

	  	 AND a.brandcd = V_BRANDCD

	    AND a.OrdDt  = V_ORDDT 

		 AND a.OrdSeq = V_ORDSEQ

	    AND IFNULL(ORDAMT,0) <> 0

	    AND a.compno = b.compno

	    AND a.brandcd = b.brandcd

		 AND a.prodcd = b.prodcd);

		

	drop TEMPORARY TABLE if EXISTS RACKPICUP_TMP;

	CREATE TEMPORARY TABLE IF NOT EXISTS RACKPICUP_TMP ENGINE=MEMORY AS (select * from tmp LIMIT 1);

	delete from RACKPICUP_TMP;

	

	begin 

	   DECLARE _prodcd varchar(200);

	   DECLARE _prodnm varchar(200);

	   DECLARE _qty int;

	   DECLARE _qty2 int;

	   DECLARE _prodcdm varchar(200);

	   DECLARE _flagset char(1);

	   DECLARE _levset char(1);

	   DECLARE _proddtcd varchar(200);



	   DECLARE done INT DEFAULT 0; 

		DECLARE c2 CURSOR FOR SELECT proddtcd, levset, qtyset

										FROM PRODDTL 

									  WHERE compno = V_COMPNO

									    AND brandcd = V_BRANDCD

									    AND prodcd=_prodcdm 

									    AND ifnull(flagset,'')='1';

		DECLARE c3 CURSOR FOR SELECT proddtcd, levset, qtyset 

										FROM PRODDTL 

									   WHERE compno = V_COMPNO

									     AND brandcd = V_BRANDCD

									     AND prodcd=_proddtcd

										 AND ifnull(flagset,'')='1';										 	   

	   DECLARE c1 CURSOR FOR SELECT * FROM tmp;

		DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;

								

		open c1;

	   REPEAT

		   FETCH NEXT FROM c1 INTO _prodcd,_prodcdm,_qty,_flagset;

			   IF not done THEN   

				   IF _prodcd <> _prodcdm then

						SELECT flagset into _flagset FROM PRODMST WHERE compno = V_COMPNO AND brandcd = V_BRANDCD AND prodcd =_prodcdm;

				   end if;

				   IF ifnull(_flagset,'') = '1' then

				   	Block2: BEGIN

				   		DECLARE done2 INT DEFAULT 0;

					   	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done2 = 1;

					   	open c2;

						   REPEAT

						   	FETCH NEXT FROM c2 INTO _proddtcd,_levset,_qty2;

							   	IF not done2 THEN 

								   	IF IFNULL(_levset,'') = '2' THEN

											Block3: BEGIN

												DECLARE done3 INT DEFAULT 0;

										   	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done3 = 1;

										   	open c3;

											   REPEAT

											   	FETCH NEXT FROM c3 INTO _proddtcd,_levset,_qty2;

								   				IF not done3 THEN 

														insert into RACKPICUP_TMP values(_prodcd,_proddtcd,_qty*_qty2,_flagset);

													END IF;

											   UNTIL done3 END REPEAT;

											   close c3;

											END Block3;

										ELSE

											insert into RACKPICUP_TMP values(_prodcd,_proddtcd,_qty*_qty2,_flagset);

										END IF;

									END IF;

						   UNTIL done2 END REPEAT;

						   close c2;

					   END Block2;

				   else

						insert into RACKPICUP_TMP values(_prodcd,_prodcdm,_qty,_flagset);

					END IF;

				END IF;

		UNTIL done END REPEAT;

		close c1;

	end;

	

	SELECT a.NecCd1, a.NecCd2, a.NecCd3, 

		 	 case ifnull(a.SPECDES,'') when '' then CONCAT(ifnull(a.ProdNm,''),'\n') ELSE CONCAT(a.prodnm ,'_',ifnull(a.SPECDES,''),'\n') END, 

		    concat(SUM(b.qty),'\n')  

     FROM V_PRODUCTS a, RACKPICUP_TMP b 

    WHERE a.compno = V_COMPNO

    AND a.brandcd = V_BRANDCD

	  AND a.prodcd = b.prodcdm 

      AND IFNULL(a.NecCd1, '') <> '' 

      AND IFNULL(a.ProdCd, '') <> '' 

      AND IFNULL(a.NecCd2, 0) between 1 and 5 

      AND IFNULL(a.NecCd3, 0) <> 0 

    GROUP BY a.NecCd1, a.NecCd2, a.NecCd3, a.SPECDES, a.ProdNm 

    ORDER BY a.NecCd1, a.NecCd2 DESC, a.NecCd3, a.ProdNm;

	

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_RACKPICUP_LIST_VER2` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_RACKPICUP_LIST_VER2`(

	IN `in_order_asign` VARCHAR(10),

	IN `in_gubun` VARCHAR(10),

	IN `in_para` VARCHAR(200)

)
BEGIN

	DECLARE	start_pos		INT	DEFAULT	0;

	DECLARE	end_pos			INT	DEFAULT	1;

	DECLARE	cut_pos			INT	DEFAULT	0;

	DECLARE	cut_para			vARCHAR(200);

	

	DECLARE	safe_count		INT	DEFAULT	20; /* 20회 이상 반복 구간이 실행되는 것을 방지 */

	

	DECLARE	cut_compno		INT;

	DECLARE	cut_brandcd		INT;

	DECLARE	cut_orddt		VARCHAR(10);

	DECLARE	cut_ordseq		INT;

	DECLARE	cut_seq_from	INT;

	DECLARE	cut_seq_to		INT;

	

	DECLARE	first_proc		BOOLEAN	DEFAULT	true;



	SET	start_pos	=	1;

	SET	end_pos		=	LENGTH(in_para);



	while	start_pos	<	end_pos	do

		SET	cut_pos	=	LOCATE(",", in_para, start_pos);

			

		if	cut_pos	=	0	then

			SET	cut_para		=	SUBSTRING(in_para, start_pos, end_pos);

			SET	start_pos	=	end_pos;

		else

			SET	cut_para		=	SUBSTRING(in_para, start_pos, cut_pos - start_pos);

			SET	start_pos	=	cut_pos	+	1;

		END	if;

		

		# 주문 차수에 대한 유효성 체크 

		if	LENGTH(cut_para)	=	30	then

			SET	cut_compno		=	cast(substring(cut_para, 1, 5) AS unsigned);

			SET	cut_brandcd		=	CAST(SUBSTRING(cut_para, 6, 5) AS UNSIGNED);

			SET	cut_orddt		=	SUBSTRING(cut_para, 11, 8);

			SET	cut_ordseq		=	CAST(SUBSTRING(cut_para, 19, 2) AS UNSIGNED);

			SET	cut_seq_from	=	CAST(SUBSTRING(cut_para, 21, 5) AS UNSIGNED);

			SET	cut_seq_to		=	CAST(SUBSTRING(cut_para, 26, 5) AS UNSIGNED);

			

			# TO 순번이 0이면 9999를 강제로 넣어줘 순번 전체가 조회되게 처리

			if	cut_seq_to	=	0	then

				SET	cut_seq_to	=	99999;

			END	if;

				

			# ==========================================

			# 기존 SP(YWM_+RACKPICUP_LIST) 붙여넣은 영역

			# ==========================================

			YWM_RACKPIUP_LIST_Block:	begin

				DECLARE	_orddt				VARCHAR(8);

				DECLARE	_ordseq				INT;

				DECLARE	_seq					INT;

				DECLARE	_asigndt				VARCHAR(8);

				DECLARE	v_delivery_type	VARCHAR(10);

				

				DECLARE	print_yn		BOOLEAN;



				DECLARE	_prodcd		VARCHAR(200);

				DECLARE	_prodnm		VARCHAR(200);

				DECLARE	_qty			INT;

				DECLARE	_qty2			INT;

				DECLARE	_prodcdm		VARCHAR(200);

				DECLARE	_flagset		CHAR(1);

				DECLARE	_levset		CHAR(1);

				DECLARE	_proddtcd	VARCHAR(200);

				

				DECLARE	done			INT	DEFAULT	0; 

				

				# (2021.7.19) 변수 추가

				DECLARE	_clmdt		VARCHAR(8);

				DECLARE	_clmseq		INT;

				DECLARE	sel_cnt				int;

				DECLARE	chkFreeCharge		boolean	default	false;

				DECLARE	clmlist_expcd		varchar(50);

				DECLARE	clmlist_proctype	varchar(50);

				# (2021.7.19) 변수 추가

					

				DECLARE	c2	CURSOR	FOR

					SELECT	proddtcd,	levset,	qtyset

					FROM		PRODDTL 

				 	WHERE		compno	=	cut_compno

			 		AND		brandcd 	=	cut_brandcd

					AND		prodcd	=	_prodcdm 

					AND		ifnull(flagset, '')	=	'1';

						

				DECLARE	c3	CURSOR	FOR

					SELECT	proddtcd,	levset,	qtyset 

					FROM		PRODDTL 

					WHERE		compno	=	cut_compno

					AND		brandcd	=	cut_brandcd

					AND		prodcd	=	_proddtcd

					AND		ifnull(flagset, '')	=	'1';										 	   

						

				DECLARE	c1	CURSOR	FOR

					SELECT	*

					FROM		tmp;

						

				DECLARE	CONTINUE	HANDLER	FOR	SQLSTATE	'02000'	SET	done	=	1;

						

				# 택배/직송 및 할당 여부 추가(2021.6.8)						

				# 주문품목 중 부품은 제외, 부품은 상담접수의 엑셀 저장을 통해 택배사로 수동 전송

				DROP		TEMPORARY	TABLE	if	EXISTS	tmp;

				CREATE	TEMPORARY	TABLE	IF	NOT	EXISTS	tmp	ENGINE=MEMORY	AS

					(SELECT	a.orddt,		a.ordseq,	a.seq,		ifnull(a.asigndt, ''),

								a.prodcd,	b.prodcdm,	a.qty,		b.flagset,

								a.clmdt,		a.clmseq

					FROM		ORDDTL a,	V_PRODUCTS b 

					WHERE		a.compno		=	cut_compno 

					AND		a.brandcd	=	cut_brandcd

					AND		a.orddt		=	cut_orddt

					AND		a.ordseq		=	cut_ordseq

					AND		a.seq			>=	cut_seq_from

					AND		a.seq			<=	cut_seq_to

					AND		iFNULL(ORDAMT, 0)	<>	0

					AND		a.compno		=	b.compno

					AND		a.brandcd	=	b.brandcd

					AND		a.prodcd		=	b.prodcd

					AND		ifnull(b.flagpart, '0')	<>	'1');	

			

				if	first_proc	then

					DROP		TEMPORARY	TABLE	if	EXISTS	RACKPICUP_TMP;

					CREATE	TEMPORARY	TABLE	IF	NOT	EXISTS	RACKPICUP_TMP

					(

						prodcd	varchar(20),

						prodcdm	varchar(20),

						qty		INT,

						flagset	char(1)

					)	ENGINE=MEMORY;

					DELETE	FROM	RACKPICUP_TMP;

					

					SET	FIRST_proc	=	FALSE;

				END	if;

					

				OPEN	c1;

					

				REPEAT

					FETCH	NEXT	FROM	c1

					INTO	_orddt,	_ordseq,		_seq,	_asigndt,

							_prodcd,	_prodcdm,	_qty,	_flagset,

							_clmdt,	_clmseq;

					

					IF	NOT	done	THEN

						# 주문기준 또는 할당구분 추가(2021.6.8)

						if	in_order_asign	=	"주문기준"	then

							SET	print_yn	=	TRUE;

						else

							if	LENGTH(_asigndt)	>	0	then

								SET	print_yn	=	TRUE;

							else

								SET	print_yn	=	FALSE;

							END	if;

						END	if;

						

						# 택배 또는 직송 추구 (2021.6.8)

						DELIVERY_SELECT_Block:	begin

							DECLARE	sel_done	INT	DEFAULT	0;

							DECLARE	continue	handler	FOR	SQLSTATE	'02000'	SET	sel_done	=	1;

						

							SET	v_delivery_type	=	'택배';

							

							SELECT	ifnull(b.deliverytype, '택배'),

										ifnull(a.expcd, ''),

										ifnull(a.proctype, '')

							INTO		v_delivery_type,

										clmlist_expcd,

										clmlist_proctype

							FROM		CLMLIST	AS	a	LEFT	JOIN	PROCTYPE	AS	b

																	ON		a.compno		=	b.compno

																	AND	a.brandcd	=	b.brandcd

																	AND	a.proctype	=	b.proctypecd

							WHERE		a.compno			=	cut_compno

							AND		a.brandcd		=	cut_brandcd

							AND		a.clmdt			=	_clmdt

							AND		a.clmseq			=	_clmseq;

						END	DELIVERY_SELECT_Block;

						

						# (2021.7.19) DELFREEMST 테이블에 택배사와 처리유형이

						# 입력되어 있으면 무임건으로 픽업 리스트에서 제외

						select	COUNT(*)

						into		sel_cnt

						FROM		DELFREEMST

						WHERE		compno		=	cut_compno

						AND		brandcd		=	cut_brandcd

						AND		expcd			=	clmlist_expcd

						AND		proctypecd	=	clmlist_proctype;

									

						if	sel_cnt	>=	1	then

							set	chkFreeCharge	=	true;

						else

							set	chkFreeCharge	=	false;

						end	if;

						# (2021.7.19) DELFREEMST (종료)

						

						# 배송유형(택배/직송)과 주문/할당 기준 체크

						if	v_delivery_type	=	in_gubun	AND	print_yn	and	chkFreeCharge	=	false	then

							IF	_prodcd	<>	_prodcdm	then

								SELECT	flagset

								INTO	_flagset

								FROM	PRODMST

								WHERE	compno	=	cut_compno

								AND	brandcd	=	cut_brandcd

								AND	prodcd	=	_prodcdm;

							END	if;

								

							IF	ifnull(_flagset, '')	=	'1'	then

								Block2: BEGIN

									DECLARE	done2	INT	DEFAULT	0;

									DECLARE	CONTINUE	HANDLER	FOR	SQLSTATE	'02000'	SET	done2	=	1;

									

									OPEN	c2;

										

									REPEAT

										FETCH	NEXT	FROM	c2

										INTO	_proddtcd,	_levset,	_qty2;

											

										IF	NOT	done2	THEN 

											IF	IFNULL(_levset, '')	=	'2'	THEN

												Block3: BEGIN

													DECLARE	done3	INT	DEFAULT	0;

													DECLARE	CONTINUE	HANDLER	FOR	SQLSTATE	'02000'	SET	done3	=	1;

														

													OPEN	c3;

														

													REPEAT

														FETCH	NEXT	FROM	c3

														INTO	_proddtcd,	_levset,	_qty2;

															

														IF	NOT	done3	THEN 

															INSERT	INTO	RACKPICUP_TMP

															VALUES	(_prodcd,	_proddtcd,	_qty*_qty2,	_flagset);

														END	IF;

													UNTIL	done3	END	REPEAT;

													

													close	c3;

												END Block3;

											ELSE

												INSERT	INTO	RACKPICUP_TMP

												VALUES	(_prodcd,	_proddtcd,	_qty*_qty2,	_flagset);

											END	IF;

										END	IF;

									UNTIL	done2	END	REPEAT;

									

									close	c2;

								END	Block2;

							ELSE

								INSERT	INTO	RACKPICUP_TMP

								VALUES	(_prodcd,	_prodcdm,	_qty,	_flagset);

							END	IF;

						END	if;

					END	IF;

				UNTIL	done	END	REPEAT;

					

				close	c1;

			END YWM_RACKPIUP_LIST_Block;	# 기존 SP(YWM_+RACKPICUP_LIST) 붙여넣은 영역 끝

		END	if;

			

		/* 무한루프 방지 */

		SET	safe_count	=	safe_count	-	1;

		if	safe_count	<=	0	then

			SET	start_pos	=	1;

			SET	end_pos		=	0;

		END	if;

	END	while;	



	SELECT	a.NecCd1,	a.NecCd2,	a.NecCd3, 

				case	ifnull(a.SPECDES,'')	

				when	''	then	CONCAT(ifnull(a.ProdNm,''),'\n')

							ELSE	CONCAT(a.prodnm ,'_',ifnull(a.SPECDES,''),'\n')

							END, 

			   concat(SUM(b.qty),'\n')  

	FROM		V_PRODUCTS a,	RACKPICUP_TMP b 

	WHERE		a.compno		=	cut_compno

	AND		a.brandcd	=	cut_brandcd

	AND		a.prodcd		=	b.prodcdm 

	AND		IFNULL(a.NecCd1, '')	<>	'' 

	AND		IFNULL(a.ProdCd, '')	<>	'' 

	AND		IFNULL(a.NecCd2, 0)	BETWEEN	1	AND	5 

	AND		IFNULL(a.NecCd3, 0)	<>	0 

				GROUP	BY	a.NecCd1,	a.NecCd2,	a.NecCd3,	a.SPECDES,	a.ProdNm 

				ORDER	BY	a.NecCd1,	a.NecCd2	DESC,	a.NecCd3,	a.ProdNm;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_SALES_STATISTICS` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_SALES_STATISTICS`(

	IN `V_COMPNO` INT,

	IN `V_SDATE` VARCHAR(8),

	IN `V_EDATE` VARCHAR(8),

	IN `V_OPT` INT,

	IN `V_SHOPID` VARCHAR(10),

	IN `V_SHOP_USERID` VARCHAR(50)



)
    COMMENT '쇼핑몰 통계정보'
BEGIN

	drop TEMPORARY TABLE if EXISTS tmp;

	CREATE TEMPORARY TABLE IF NOT EXISTS tmp ENGINE=MEMORY AS

	(SELECT DATE_FORMAT(a.reg_date,'%Y%m%d') as reg_date, DATE_FORMAT(left(a.order_date,19),'%Y%m%d') as order_date,a.shopid,

			  (SELECT shopnm FROM SHOPINFO WHERE shopcd=a.shopid) AS shopnam,(SELECT nicknm1 FROM shopdtl WHERE shopseq=a.shopseq and shopcd = a.shopid and compno=a.compno) as shop_nickname,

			  a.shop_userid,a.order_id,a.order_status,IFNULL(a.mall_exp_cd,'0'),

			  a.mall_product_id,a.compayny_goods_cd,a.product_name,sku_id,a.p_product_name,a.p_sku_id,a.p_sku_value,

	        a.user_name,a.sale_cnt,a.total_cost,0 as ret_cnt,0 as ret_cost,0 as cnc_cnt,0 as cnc_cost,

			  0 as goods_cost, 0.00 commmis, 0.00 AS compare,

	         a.won_cost, a.mall_won_cost,a.delv_cost,0 as profit

	   FROM SHOPORDMST a

	  WHERE a.compno=V_COMPNO and order_status <> '202' AND order_status <> 'E02'

	    AND DATE_FORMAT(left(a.order_date,19),'%Y%m%d') BETWEEN V_SDATE AND V_EDATE 

		AND a.shopid like V_SHOPID AND a.shopseq like V_SHOP_USERID 

		order by 2);

		

	drop TEMPORARY TABLE if EXISTS tmp2;

	CREATE TEMPORARY TABLE IF NOT EXISTS tmp2 ENGINE=MEMORY AS (select * from tmp LIMIT 1);

	delete from tmp2;

	

	BEGIN



		DECLARE _reg_date varchar(8);

		DECLARE _order_date varchar(8);

		DECLARE _shopid varchar(20);

		DECLARE _shopnam varchar(200);

		DECLARE _shop_nickname varchar(200);

		DECLARE _shop_userid varchar(200);

		DECLARE _order_id varchar(50);

		DECLARE _order_status varchar(5);

		DECLARE _mall_exp_cd varchar(200);

		DECLARE _mall_product_id VARCHAR(50);

		DECLARE _compayny_goods_cd varchar(50);

		DECLARE _product_name varchar(200);

		DECLARE _sku_id varchar(200);

		DECLARE _p_product_name varchar(200);

		DECLARE _p_sku_id varchar(20);

		DECLARE _p_sku_value varchar(200);

		DECLARE _user_name varchar(50);

		DECLARE _sale_cnt INT;

		DECLARE _total_cost INT;

		DECLARE _ret_cnt INT;

		DECLARE _ret_cost INT;

		DECLARE _cnc_cnt INT;

		DECLARE _cnc_cost INT;

		DECLARE _goods_cost int;

		DECLARE _commmis float; 

		DECLARE _compare float;

		

		DECLARE _won_cost INT;

		DECLARE _mall_won_cost INT; 

		DECLARE _delv_cost INT;

		DECLARE _profit INT;		

		

		DECLARE v_prodseq INT;

		DECLARE v_shopseq INT;

		DECLARE v_shop_rate_amt INT;

		DECLARE v_seq INT;

		

		DECLARE bf_sale_cnt INT;

		DECLARE bf_total_cost double;

		DECLARE af_sale_cnt INT;

		DECLARE af_total_cost double;

		

		Block1: BEGIN

		

			DECLARE done INT DEFAULT 0; 

			DECLARE c1 CURSOR FOR SELECT * FROM tmp;

			

			DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;

			

			

			

	

			OPEN c1;

			REPEAT

				FETCH c1 INTO _reg_date,_order_date,_shopid,_shopnam,_shop_nickname,_shop_userid,_order_id,_order_status,_mall_exp_cd,

								  _mall_product_id,_compayny_goods_cd,_product_name,_sku_id,_p_product_name,

								  _p_sku_id,_p_sku_value,_user_name,_sale_cnt,_total_cost,_ret_cnt,_ret_cost,

								  _cnc_cnt,_cnc_cost,_goods_cost,_commmis,

								  _compare,_won_cost,_mall_won_cost,_delv_cost,_profit;

							  

				IF not done THEN 

					

					set _won_cost = ifnull(_won_cost,0);  					

					 

						

					set _profit = ifnull(_mall_won_cost,0) - ifnull(_won_cost,0);					

					

					if _mall_exp_cd = 'R02' then

						

						set _ret_cnt = _sale_cnt; 

						set _ret_cost = _total_cost;

						set _sale_cnt = _sale_cnt;

						set _total_cost = _total_cost;

						set _won_cost = _won_cost  ;

						set _mall_won_cost = _mall_won_cost  ;

					elseif _mall_exp_cd = 'C02' then

						

						set _cnc_cnt = _sale_cnt;

						set _cnc_cost = _total_cost;

						set _sale_cnt = _sale_cnt;

						set _total_cost = _total_cost;

						set _won_cost = _won_cost  ;

						set _mall_won_cost = _mall_won_cost ;

					end if;

 					

					insert into tmp2 values(_reg_date,_order_date,_shopid,_shopnam,_shop_nickname,_shop_userid,_order_id,_order_status,_mall_exp_cd,

													_mall_product_id,_compayny_goods_cd,_product_name,_sku_id,_p_product_name,

													_p_sku_id,_p_sku_value,_user_name,_sale_cnt,_total_cost,_ret_cnt,_ret_cost,

									 				_cnc_cnt,_cnc_cost,_won_cost,_commmis,

													_compare,_won_cost,_mall_won_cost,_delv_cost,_profit);  



				END IF;

				

			UNTIL done END REPEAT;

			CLOSE c1;

		END Block1;	

		

		

		Block2: BEGIN

			drop TEMPORARY TABLE if EXISTS tmp3;

			CREATE TEMPORARY TABLE IF NOT EXISTS tmp3 ENGINE=MEMORY AS (select * from tmp2 LIMIT 1);

			delete from tmp3;

			

			

			SELECT sum(sale_cnt),sum(total_cost) into bf_sale_cnt,bf_total_cost

			  FROM SHOPORDMST

			 WHERE compno=V_COMPNO

			   AND DATE_FORMAT(reg_date,'%Y%m%d') 

				    BETWEEN DATE_FORMAT(DATE_ADD(DATE_FORMAT(V_SDATE,'%Y%m%d'), INTERVAL -1 MONTH),'%Y%m%d') 

				        AND DATE_FORMAT(DATE_ADD(DATE_FORMAT(V_EDATE,'%Y%m%d'), INTERVAL -1 MONTH),'%Y%m%d');

			

			

			SELECT sum(sale_cnt)-sum(ret_cnt)-sum(cnc_cnt), sum(total_cost)-sum(ret_cost)-sum(cnc_cost) 

			  into af_sale_cnt,af_total_cost

			  FROM tmp2; 

			  

			insert into tmp3(sale_cnt,total_cost) values( round(af_sale_cnt/bf_sale_cnt*100),round(af_total_cost/bf_total_cost*100) );

		END Block2;

		

		

		Block3: BEGIN

			if V_OPT = 1 then 

				select distinct compayny_goods_cd,p_product_name,shop_nickname,count(*) as ord_cnt,sum(sale_cnt) as sale_cnt,sum(total_cost) as total_cost,

					    sum(ret_cnt) as ret_cnt, sum(ret_cost) as ret_cost, sum(cnc_cnt) as cnc_cnt,sum(cnc_cost) as cnc_cost,

						 sum(goods_cost) as goods_cost,sum(mall_won_cost) as mall_won_cost,

					    sum(delv_cost) as delv_cost, sum(profit) as profit

				  from tmp2

				 group by compayny_goods_cd,p_product_name,shop_nickname

				 union all 

				select compayny_goods_cd, p_product_name,shop_nickname, 0 as ord_cnt, sale_cnt, total_cost,

					    ret_cnt,ret_cost,cnc_cnt,cnc_cost, goods_cost, mall_won_cost,

					    delv_cost, profit

				  from tmp3;

			elseif V_OPT = 2 then 

				select distinct order_date, count(*) as ord_cnt,sum(sale_cnt) as sale_cnt,sum(total_cost) as total_cost,

					    sum(ret_cnt) as ret_cnt, sum(ret_cost) as ret_cost, sum(cnc_cnt) as cnc_cnt,sum(cnc_cost) as cnc_cost,

						 sum(goods_cost) as goods_cost,sum(mall_won_cost) as mall_won_cost,

					    sum(delv_cost) as delv_cost, sum(profit) as profit

				  from tmp2

				 group by order_date

				 union all 

				select order_date, 0 as ord_cnt, sale_cnt, total_cost,

					    ret_cnt,ret_cost,cnc_cnt,cnc_cost, goods_cost, mall_won_cost,

					    delv_cost, profit

				  from tmp3;

			elseif V_OPT = 3 then 

				select distinct DATE_FORMAT(reg_date,'%Y%m') as reg_ym, count(*) as ord_cnt,sum(sale_cnt) as sale_cnt,sum(total_cost) as total_cost,

					    sum(ret_cnt) as ret_cnt, sum(ret_cost) as ret_cost, sum(cnc_cnt) as cnc_cnt,sum(cnc_cost) as cnc_cost,

						 sum(goods_cost) as goods_cost,sum(mall_won_cost) as mall_won_cost,

					    sum(delv_cost) as delv_cost, sum(profit) as profit

				  from tmp2

				 group by DATE_FORMAT(reg_date,'%Y%m')

				 union all 

				select '' as reg_ym, 0 as ord_cnt, sale_cnt, total_cost,

					    ret_cnt,ret_cost,cnc_cnt,cnc_cost, goods_cost, mall_won_cost,

					    delv_cost, profit 

				  from tmp3;

			elseif V_OPT = 4 then 

				select shopnam,shop_userid,shop_nickname, count(*) as ord_cnt,sum(sale_cnt) as sale_cnt,sum(total_cost) as total_cost,

					    sum(ret_cnt) as ret_cnt, sum(ret_cost) as ret_cost, sum(cnc_cnt) as cnc_cnt,sum(cnc_cost) as cnc_cost,

						 sum(goods_cost) as goods_cost,sum(mall_won_cost) as mall_won_cost,

					    sum(delv_cost) as delv_cost, sum(profit) as profit

				  from tmp2

				 group by shopnam,shop_userid,shop_nickname

				 union all 

				select shopnam,shop_userid,shop_nickname, 0 as ord_cnt, sale_cnt, total_cost,

					    ret_cnt,ret_cost,cnc_cnt,cnc_cost, goods_cost, mall_won_cost,

					    delv_cost, profit

				  from tmp3

				  order by shopnam;

			elseif V_OPT = 5 then 

				select distinct user_name, shop_nickname ,p_product_name,count(*) as ord_cnt,sum(sale_cnt) as sale_cnt,sum(total_cost) as total_cost,

					    sum(ret_cnt) as ret_cnt, sum(ret_cost) as ret_cost, sum(cnc_cnt) as cnc_cnt,sum(cnc_cost) as cnc_cost,

						 sum(goods_cost) as goods_cost,sum(mall_won_cost) as mall_won_cost,

					    sum(delv_cost) as delv_cost, sum(profit) as profit 

				  from tmp2

				 group by user_name,shop_nickname,p_product_name

				 union all 

				select user_name,shop_nickname ,p_product_name, 0 as ord_cnt, sale_cnt, total_cost,

					    ret_cnt,ret_cost,cnc_cnt,cnc_cost, goods_cost, mall_won_cost,

					    delv_cost, profit 

				  from tmp3;

			end if;

		END Block3;

	   

	END;



END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_SALES_STATISTICS_MLINK` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_SALES_STATISTICS_MLINK`(

	IN `V_COMPNO` INT,

	IN `V_SDATE` VARCHAR(8),

	IN `V_EDATE` VARCHAR(8)





















,

	IN `V_OPT` INT











)
    COMMENT '통계정보'
BEGIN

	drop TEMPORARY TABLE if EXISTS tmp;

	CREATE TEMPORARY TABLE IF NOT EXISTS tmp ENGINE=MEMORY AS

	(SELECT orddt as reg_date, orddt as order_date,

		    (SELECT ifnull(a.shopcd,'') FROM SHOPINFO a, SHOPMST b WHERE a.SHOPNM like concat('%',trim(MID( shopid,1, CHAR_LENGTH(shopid)-INSTR(REVERSE(shopid),' ')+1 )),'%') AND b.compno=V_COMPNO AND b.SHOPCD=a.shopcd AND dealtrade='거래중' limit 1) AS shopid,

		    trim(MID( shopid,1, CHAR_LENGTH(shopid)-INSTR(REVERSE(shopid),' ')+1 )) AS shopnam,

			trim(MID( shopid, CHAR_LENGTH(shopid)-INSTR(REVERSE(shopid),' ')+1, 20)) AS shop_userid, sabordno AS order_id, '403' AS order_status,

			prodcd as mall_product_id, prodcd as compayny_goods_cd,optdesc as product_name, prodcd as sku_id, optdesc as p_product_name, prodcd as p_sku_id, prodcd as p_sku_value,

			ordnm as user_name, qty as sale_cnt,

		   (SELECT ifnull(max(price),0) FROM PRODMST b WHERE b.compno=V_COMPNO and b.prodcd=dt.prodcd) as sale_cost,

			0 as ret_cnt,0 as ret_cost,0 as cnc_cnt,0 as cnc_cost,0 AS goods_cost,

			0.00 AS commmis, 0.00 AS compare, 

			ordamt as total_cost, 

			0 as total_wonamt, 0 as mall_won_cost, shpfee, 0 as profit

      FROM ORDDTL dt

     WHERE compno=V_COMPNO

       AND orddt BETWEEN V_SDATE AND V_EDATE

	  union all

	 SELECT cl.CLMDT as reg_date, ordid as order_date, 

			case when trim(MID( mallcd,1, CHAR_LENGTH(mallcd)-INSTR(REVERSE(mallcd),' ')+1 ))='' 

			     then null 

			 	 ELSE (SELECT ifnull(a.shopcd,'') 

						 FROM SHOPINFO a, SHOPMST b 

				 		WHERE a.SHOPNM like concat('%',trim(MID( mallcd,1, CHAR_LENGTH(mallcd)-INSTR(REVERSE(mallcd),' ')+1 )),'%') 

						  AND b.compno=V_COMPNO 

						  AND b.SHOPCD=a.shopcd 

						  AND dealtrade='거래중' limit 1) end AS shopid,

			trim(MID( mallcd,1, CHAR_LENGTH(mallcd)-INSTR(REVERSE(mallcd),' ')+1 )) AS shopnam,

			trim(MID( mallcd, CHAR_LENGTH(mallcd)-INSTR(REVERSE(mallcd),' ')+1, 20)) AS shop_userid,'' AS order_id, 'R03' AS order_status,

			cld.prodcd as mall_product_id, cld.prodcd as compayny_goods_cd ,

			(SELECT prodnm FROM PRODMST b WHERE b.compno=V_COMPNO and b.prodcd=cld.prodcd) as product_name, 

			cld.prodcd as sku_id, (SELECT prodnm FROM PRODMST b WHERE b.compno=V_COMPNO and b.prodcd=cld.prodcd) as p_product_name, 

			cld.prodcd as p_sku_id, cld.prodcd as p_sku_value,

			resalnam as user_name, 0 as sale_cnt, 0 AS sale_cost, cld.qty as ret_cnt, 

			(SELECT ifnull(max(price),0) FROM PRODMST b WHERE b.compno=V_COMPNO and b.prodcd=cld.prodcd) as ret_cost,

			0 as cnc_cnt,0 as cnc_cost,0 AS goods_cost,

			0.00 AS commmis, 0.00 AS compare, 

			(SELECT ifnull(max(price),0) FROM PRODMST b WHERE b.compno=V_COMPNO and b.prodcd=cld.prodcd)*cld.qty as total_cost, 

			0 as total_wonamt, 0 as mall_won_cost, suppamt+retamt as shpfee, 0 as profit

	  FROM CLMLIST cl, CLMLISTDTL cld

	 WHERE cl.compno=V_COMPNO 

	   AND cl.recvdt BETWEEN V_SDATE AND V_EDATE

	   AND cl.compno=cld.compno

	   AND cl.CLMDT =cld.CLMDT

	   AND cl.clmseq=cld.clmseq);

			  

	drop TEMPORARY TABLE if EXISTS tmp2;

	CREATE TEMPORARY TABLE IF NOT EXISTS tmp2 ENGINE=MEMORY AS (select * from tmp LIMIT 1);

	delete from tmp2;

	

	begin 

		DECLARE _reg_date varchar(8);

		DECLARE _order_date varchar(20);

		DECLARE _shopid varchar(20);

		DECLARE _shopnam varchar(200);

		DECLARE _shop_userid varchar(20);

		DECLARE _order_id varchar(20);

		DECLARE _order_status varchar(5);

		DECLARE _mall_product_id varchar(20);

		DECLARE _compayny_goods_cd varchar(20);

		DECLARE _product_name varchar(200);

		DECLARE _sku_id varchar(200);

		DECLARE _p_product_name varchar(200);

		DECLARE _p_sku_id varchar(20);

		DECLARE _p_sku_value varchar(200);

		DECLARE _user_name varchar(200);

		DECLARE _sale_cnt INT;

		DECLARE _sale_cost INT;

		DECLARE _ret_cnt INT;

		DECLARE _ret_cost INT;

		DECLARE _cnc_cnt INT;

		DECLARE _cnc_cost INT;

		DECLARE _goods_cost int;

		DECLARE _commmis float; 

		DECLARE _compare float;

		DECLARE _total_cost INT;

		DECLARE _total_won_amt INT;

		DECLARE _mall_won_cost INT; 

		DECLARE _shpfee varchar(20);

		DECLARE _profit INT;

		

		DECLARE v_delv_cost INT;

		DECLARE v_prodseq INT;

		DECLARE v_shopseq INT;

		DECLARE v_shop_rate_amt INT;

		

		DECLARE bf_sale_cnt INT;

		DECLARE bf_sale_cost double;

		DECLARE af_sale_cnt INT;

		DECLARE af_sale_cost double;

		

		Block1: BEGIN

		

			DECLARE v_qty INT default 0;

			DECLARE v_amt INT default 0;

			

			DECLARE done INT DEFAULT 0; 

			DECLARE c1 CURSOR FOR SELECT * FROM tmp;

			
			DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;

			
			
			
	

			OPEN c1;

			REPEAT

				FETCH c1 INTO 	_reg_date,_order_date,_shopid,_shopnam,_shop_userid,_order_id,_order_status,

								_mall_product_id,_compayny_goods_cd,_product_name,_sku_id,_p_product_name,

								_p_sku_id,_p_sku_value,_user_name,_sale_cnt,_sale_cost,_ret_cnt,_ret_cost,

								_cnc_cnt,_cnc_cost,_goods_cost,_commmis,

								_compare,_total_cost,_total_won_amt,_mall_won_cost,_shpfee,_profit;

								  

				IF not done THEN



					if left(_order_status,1) = 'R' then

						set v_qty = _ret_cnt;

						set v_amt = _ret_cost;

					else

						set v_qty = _sale_cnt;

						set v_amt = _sale_cost;

					end if;

			   	

					
					if _goods_cost = 0 then

						set _goods_cost = round(ifnull(v_amt,0) * 0.7); 

					end if;

					set _total_won_amt = ifnull(v_qty,0) * ifnull(_goods_cost,0);



					
					set v_shop_rate_amt = round(ifnull(_total_cost,0) * ( 0.13 + 0.02 ));

					set _mall_won_cost = ifnull(_total_cost,0) - v_shop_rate_amt;

			   	

					
					if ifnull(_total_cost,0) < 30000 then 

						set v_delv_cost = -2500; 

					else 

						set v_delv_cost = 0; 

					end if;

			   	

					
					set _profit = _mall_won_cost - _total_won_amt + v_delv_cost;

			   	

									

					insert into tmp2 values(_reg_date,_order_date,_shopid,_shopnam,_shop_userid,_order_id,_order_status,

													_mall_product_id,_compayny_goods_cd,_product_name,_sku_id,_p_product_name,

													_p_sku_id,_p_sku_value,_user_name,_sale_cnt,_sale_cost,_ret_cnt,_ret_cost,

											 		_cnc_cnt,_cnc_cost,_goods_cost,_commmis,

													_compare,_total_cost,_total_won_amt,_mall_won_cost,v_delv_cost,_profit);  

											

				END IF;

				

			UNTIL done END REPEAT;

		   CLOSE c1;

		END Block1;	

	

		
		Block2: BEGIN

		

			DECLARE v_qty1 INT default 0;

			DECLARE v_qty2 INT default 0;

			DECLARE v_amt1 INT default 0;

			DECLARE v_amt2 INT default 0;

		

			drop TEMPORARY TABLE if EXISTS tmp3;

			CREATE TEMPORARY TABLE IF NOT EXISTS tmp3 ENGINE=MEMORY AS (select * from tmp2 LIMIT 1);

			delete from tmp3;

			

			
			SELECT sum(qty),sum(ordamt) into v_qty1,v_amt1

			  FROM ORDDTL dt

			 WHERE compno=V_COMPNO

			   AND DATE_FORMAT(orddt,'%Y%m%d') 

				    BETWEEN DATE_FORMAT(DATE_ADD(DATE_FORMAT(V_SDATE,'%Y%m%d'), INTERVAL -1 MONTH),'%Y%m%d') 

				        AND DATE_FORMAT(DATE_ADD(DATE_FORMAT(V_EDATE,'%Y%m%d'), INTERVAL -1 MONTH),'%Y%m%d');

			

			
			SELECT sum(cld.qty),

				   sum((SELECT ifnull(max(price),0) FROM PRODMST b WHERE b.compno=V_COMPNO and b.prodcd=cld.prodcd)*cld.qty)

			  into v_qty2,v_amt2

			  FROM CLMLIST cl, CLMLISTDTL cld

			 WHERE cl.compno=V_COMPNO 

			   AND DATE_FORMAT(cl.recvdt,'%Y%m%d') 

				    BETWEEN DATE_FORMAT(DATE_ADD(DATE_FORMAT(V_SDATE,'%Y%m%d'), INTERVAL -1 MONTH),'%Y%m%d') 

				        AND DATE_FORMAT(DATE_ADD(DATE_FORMAT(V_EDATE,'%Y%m%d'), INTERVAL -1 MONTH),'%Y%m%d')

			   AND cl.compno=cld.compno

			   AND cl.CLMDT =cld.CLMDT

			   AND cl.clmseq=cld.clmseq;

			   

			set bf_sale_cnt = v_qty1 - v_qty2;

			set bf_sale_cost = v_amt1 - v_amt2;

					

			
			SELECT sum(sale_cnt)-sum(ret_cnt)-sum(cnc_cnt), sum(total_cost)-sum(ret_cost)-sum(cnc_cost)

			  into af_sale_cnt,af_sale_cost

			  FROM tmp2; 

			

			
			insert into tmp3 values('','','','','','','','','','','','','','',0,0,

									round(af_sale_cnt/bf_sale_cnt*100),

									round(af_sale_cost/bf_sale_cost*100),

									0,0,0,0,0.00,0.00,0,0,0,0,0);

			  

		END Block2;

		

		
		Block3: BEGIN

			if V_OPT = 1 then 

				select a.* from ( select distinct compayny_goods_cd,p_product_name,count(*) as ord_cnt,sum(sale_cnt) as sale_cnt,sum(sale_cost) as sale_cost,

											    sum(ret_cnt) as ret_cnt, sum(ret_cost) as ret_cost, sum(cnc_cnt) as cnc_cnt,sum(cnc_cost) as cnc_cost,

												 sum(goods_cost) as goods_cost,sum(mall_won_cost) as mall_won_cost,

											    sum(shpfee) as delv_cost, sum(profit) as profit

										  from tmp2 

										 group by compayny_goods_cd,p_product_name

										 union all 

										select compayny_goods_cd, p_product_name, 0 as ord_cnt, sale_cnt, sale_cost,

											    ret_cnt,ret_cost,cnc_cnt,cnc_cost, goods_cost, mall_won_cost,

											    shpfee, profit

										  from tmp3 ) a order by sale_cnt desc;

			elseif V_OPT = 2 then 

				select a.* from ( select distinct reg_date, count(*) as ord_cnt,sum(sale_cnt) as sale_cnt,sum(sale_cost) as sale_cost,

											    sum(ret_cnt) as ret_cnt, sum(ret_cost) as ret_cost, sum(cnc_cnt) as cnc_cnt,sum(cnc_cost) as cnc_cost,

												 sum(goods_cost) as goods_cost,sum(mall_won_cost) as mall_won_cost,

											    sum(shpfee) as delv_cost, sum(profit) as profit

										  from tmp2

										 group by reg_date

										 union all 

										select reg_date, 0 as ord_cnt, sale_cnt, sale_cost,

											    ret_cnt,ret_cost,cnc_cnt,cnc_cost, goods_cost, mall_won_cost,

											    shpfee, profit

										  from tmp3 ) a order by reg_date desc;

			elseif V_OPT = 3 then 

				select a.* from ( select distinct DATE_FORMAT(reg_date,'%Y%m') as reg_ym, count(*) as ord_cnt,sum(sale_cnt) as sale_cnt,sum(sale_cost) as sale_cost,

											    sum(ret_cnt) as ret_cnt, sum(ret_cost) as ret_cost, sum(cnc_cnt) as cnc_cnt,sum(cnc_cost) as cnc_cost,

												 sum(goods_cost) as goods_cost,sum(mall_won_cost) as mall_won_cost,

											    sum(shpfee) as delv_cost, sum(profit) as profit

										  from tmp2

										 group by DATE_FORMAT(reg_date,'%Y%m')

										 union all 

										select '' as reg_ym, 0 as ord_cnt, sale_cnt, sale_cost,

											    ret_cnt,ret_cost,cnc_cnt,cnc_cost, goods_cost, mall_won_cost,

											    shpfee, profit 

										  from tmp3 ) a order by sale_cnt desc;

			elseif V_OPT = 4 then 

				select a.* from ( select distinct shopnam, count(*) as ord_cnt,sum(sale_cnt) as sale_cnt,sum(sale_cost) as sale_cost,

											    sum(ret_cnt) as ret_cnt, sum(ret_cost) as ret_cost, sum(cnc_cnt) as cnc_cnt,sum(cnc_cost) as cnc_cost,

												 sum(goods_cost) as goods_cost,sum(mall_won_cost) as mall_won_cost,

											    sum(shpfee) as delv_cost, sum(profit) as profit

										  from tmp2 

										 group by shopnam

										 union all 

										select shopnam, 0 as ord_cnt, sale_cnt, sale_cost,

											    ret_cnt,ret_cost,cnc_cnt,cnc_cost, goods_cost, mall_won_cost,

											    shpfee, profit

										  from tmp3 ) a order by sale_cnt desc;

			elseif V_OPT = 5 then 

				select a.* from ( select distinct user_name, count(*) as ord_cnt,sum(sale_cnt) as sale_cnt,sum(sale_cost) as sale_cost,

											    sum(ret_cnt) as ret_cnt, sum(ret_cost) as ret_cost, sum(cnc_cnt) as cnc_cnt,sum(cnc_cost) as cnc_cost,

												 sum(goods_cost) as goods_cost,sum(mall_won_cost) as mall_won_cost,

											    sum(shpfee) as delv_cost, sum(profit) as profit

										  from tmp2 

										 group by user_name

										 union all 

										select user_name, 0 as ord_cnt, sale_cnt, sale_cost,

											    ret_cnt,ret_cost,cnc_cnt,cnc_cost, goods_cost, mall_won_cost,

											    shpfee, profit

										  from tmp3 ) a order by sale_cnt desc;

			end if;

		END Block3;

		

	END;

	

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_SETCODE` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_SETCODE`(

	IN `V_COMPNO` INT,

	IN `V_PRODCD` VARCHAR(20),

	IN `V_FORDDT` VARCHAR(8),

	IN `V_TORDDT` VARCHAR(8)




















)
    COMMENT '구성품의 주문(판매) 역추적 기능  ( 재고현황의 상세내역 조회에서 사용)'
BEGIN

	drop TEMPORARY TABLE if EXISTS tmp;

	CREATE TEMPORARY TABLE IF NOT EXISTS tmp ENGINE=MEMORY AS

	(SELECT '12345678901234567890' as prodcd, '12345678901234567890' as proddtcd, 0 as qty, '1' as flagset, '20190101' as ORDDT

	   FROM dual);

		

	drop TEMPORARY TABLE if EXISTS WAREHOUSE_QTY_TMP2;

	CREATE TEMPORARY TABLE IF NOT EXISTS WAREHOUSE_QTY_TMP2 ENGINE=MEMORY AS (select * from tmp LIMIT 1);

	delete from WAREHOUSE_QTY_TMP2;

	

	begin 

		DECLARE _prodcd varchar(20);

		DECLARE _prodcd3 varchar(20);

		DECLARE _qty int;

		DECLARE _qtyset int;

		DECLARE _qtyset2 int;

		DECLARE v_exists int;

		DECLARE _prodcdm varchar(20);

		DECLARE _prodcdm2 varchar(20);

		DECLARE _flagset char(1);

		DECLARE _orddt varchar(8);

		

		DECLARE done INT DEFAULT 0; 

		DECLARE c2 CURSOR FOR SELECT prodcd, proddtcd, qtyset, flagset

								FROM PRODDTL 

							   WHERE compno = V_COMPNO 

							     and proddtcd=_prodcd 

								 AND ifnull(flagset,'')='1';

		DECLARE c3 CURSOR FOR  SELECT a.prodcd , b.qty, b.orddt

								 FROM V_PRODUCTS a, ORDDTL b

								WHERE b.compno  = V_COMPNO

								  and b.ORDDT BETWEEN V_FORDDT AND V_TORDDT

								  and IFNULL(b.ORDAMT,0) <> 0 

								  and b.compno = a.compno

								  and a.prodcdm = _prodcd 

								  AND a.prodcd  = b.prodcd ;										 	   

	   DECLARE c1 CURSOR FOR SELECT prodcd, proddtcd, qtyset, flagset

								FROM PRODDTL 

							   WHERE compno = V_COMPNO

							    AND proddtcd = V_PRODCD

								AND ifnull(flagset,'')='1';

		DECLARE c4 CURSOR FOR SELECT prodcd FROM PRODMST WHERE compno=V_COMPNO and prodcd = V_PRODCD and ifnull(flagset,'') <> '1';

		DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;

		

		Block1: BEGIN		

			open c1;

			REPEAT

				FETCH NEXT FROM c1 INTO _prodcd,_prodcdm,_qtyset,_flagset;

					IF not done THEN  

						SELECT sum(1) into v_exists FROM PRODDTL WHERE compno=V_COMPNO and proddtcd = _prodcd;

						
						
						
						
						
						
						
						
						
						
						
						
						IF ifnull(v_exists,0) > 0 then

							Block2: BEGIN

								DECLARE done2 INT DEFAULT 0;

								DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done2 = 1;

								
								
								
								open c2;

								REPEAT

									FETCH NEXT FROM c2 INTO _prodcd,_prodcdm2,_qtyset2,_flagset;

										IF not done2 THEN 

										

											Block3: BEGIN

												DECLARE done3 INT DEFAULT 0;

												DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done3 = 1;

												
												
												
												open c3;

												REPEAT

													FETCH NEXT FROM c3 INTO _prodcd3, _qty, _orddt;

														IF not done3 THEN 

															insert into WAREHOUSE_QTY_TMP2 values(_prodcd3,_prodcdm2,_qty*(_qtyset*_qtyset2),_flagset,_orddt);

														END IF;

												UNTIL done3 END REPEAT;

												close c3;

											END Block3;

										

										END IF;

								UNTIL done2 END REPEAT;

								close c2;

							END Block2;

						else

							Block4: BEGIN

								DECLARE done3 INT DEFAULT 0;

								DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done3 = 1;

								
								
								
								
								open c3;

								REPEAT

									FETCH NEXT FROM c3 INTO _prodcd3, _qty, _orddt;

										IF not done3 THEN 

											insert into WAREHOUSE_QTY_TMP2 values(_prodcd3,_prodcdm,_qty*_qtyset,_flagset,_orddt);

										END IF;

								UNTIL done3 END REPEAT;

								close c3;

							END Block4;

						END IF;

					END IF;

			UNTIL done END REPEAT;

			close c1;

		END Block1;

		

		
		Block22: BEGIN

			DECLARE done22 INT DEFAULT 0;

			DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done22 = 1;

			open c4;

			REPEAT

				FETCH NEXT FROM c4 INTO _prodcd;

					IF not done22 THEN 

					

						Block32: BEGIN

							DECLARE done32 INT DEFAULT 0;

							DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done32 = 1;

							open c3;

							REPEAT

								FETCH NEXT FROM c3 INTO _prodcd3, _qty, _orddt;

									IF not done32 THEN 

										insert into WAREHOUSE_QTY_TMP2 values(_prodcd3,_prodcd,_qty,'0',_orddt);

									END IF;

							UNTIL done32 END REPEAT;

							close c3;

						END Block32;

					

					END IF;

			UNTIL done22 END REPEAT;

			close c4;

		END Block22;

		

	end;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_SETCODELIST` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_SETCODELIST`(

	IN `V_COMPNO` INT,

	IN `V_BRANDCD` INT,

	IN `V_FORDDT` VARCHAR(8),

	IN `V_TORDDT` VARCHAR(8)































)
    COMMENT '상품수불 출력을 위한 셋트상품 풀어놓은것'
BEGIN

	drop TEMPORARY TABLE if EXISTS tmp;

	CREATE TEMPORARY TABLE IF NOT EXISTS tmp ENGINE=MEMORY AS

	(SELECT a.prodcd, b.prodcdm, a.qty, b.flagset, a.ORDDT 

	   FROM ORDDTL a, V_PRODUCTS b 

	  WHERE a.COMPNO = V_COMPNO 

	  	 AND a.BRANDCD = V_BRANDCD

	    AND a.ORDDT between V_FORDDT and V_TORDDT

	    AND IFNULL(a.ORDAMT,0) <> 0

	    AND a.compno = b.compno

		AND a.brandcd = b.brandcd 

		 AND a.prodcd = b.prodcd);

		

	drop TEMPORARY TABLE if EXISTS WAREHOUSE_QTY_TMP2;

	CREATE TEMPORARY TABLE IF NOT EXISTS WAREHOUSE_QTY_TMP2 ENGINE=MEMORY AS (select * from tmp LIMIT 1);

	delete from WAREHOUSE_QTY_TMP2;

	

	begin 

	   DECLARE _prodcd varchar(200);

	   DECLARE _prodnm varchar(200);

	   DECLARE _qty int;

	   DECLARE _qty2 int;

	   DECLARE _prodcdm varchar(200);

	   DECLARE _flagset char(1);

	   DECLARE _levset char(1);

	   DECLARE _proddtcd varchar(200);

	   DECLARE _orddt varchar(8);



	   DECLARE done INT DEFAULT 0; 

		DECLARE c2 CURSOR FOR SELECT proddtcd, levset, qtyset

										FROM PRODDTL 

									  WHERE COMPNO = V_COMPNO 

									    AND BRANDCD = V_BRANDCD

										 and prodcd=_prodcdm 

									    AND ifnull(flagset,'')='1';

		DECLARE c3 CURSOR FOR SELECT proddtcd, levset, qtyset 

										FROM PRODDTL 

									  WHERE COMPNO = V_COMPNO 

									    AND BRANDCD = V_BRANDCD

										 and prodcd=_proddtcd

										 AND ifnull(flagset,'')='1';										 	   

	   DECLARE c1 CURSOR FOR SELECT * FROM tmp;

		DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;

								

		open c1;

	   REPEAT

		   FETCH NEXT FROM c1 INTO _prodcd,_prodcdm,_qty,_flagset,_orddt;

			   IF not done THEN   

				   IF _prodcd <> _prodcdm then

						SELECT flagset into _flagset FROM PRODMST WHERE COMPNO = V_COMPNO and BRANDCD = V_BRANDCD and prodcd =_prodcdm;

				   end if;

				   IF ifnull(_flagset,'') = '1' then

				   	Block2: BEGIN

				   		DECLARE done2 INT DEFAULT 0;

					   	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done2 = 1;

					   	open c2;

						   REPEAT

						   	FETCH NEXT FROM c2 INTO _proddtcd,_levset,_qty2;

							   	IF not done2 THEN 

								   	IF IFNULL(_levset,'') = '2' THEN

											Block3: BEGIN

												DECLARE done3 INT DEFAULT 0;

										   	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done3 = 1;

										   	open c3;

											   REPEAT

											   	FETCH NEXT FROM c3 INTO _proddtcd,_levset,_qty2;

								   				IF not done3 THEN 

								   					

														insert into WAREHOUSE_QTY_TMP2 values(_prodcd,_proddtcd,_qty*_qty2,_flagset,_orddt);

													END IF;

											   UNTIL done3 END REPEAT;

											   close c3;

											END Block3;

										ELSE

											

											insert into WAREHOUSE_QTY_TMP2 values(_prodcd,_proddtcd,_qty*_qty2,_flagset,_orddt);

										END IF;

									END IF;

						   UNTIL done2 END REPEAT;

						   close c2;

					   END Block2;

				   else

				   	

						insert into WAREHOUSE_QTY_TMP2 values(_prodcd,_prodcdm,_qty,_flagset,_orddt);

					END IF;

				END IF;

		UNTIL done END REPEAT;

		close c1;

	end;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_SHOPORDAUTO_PROC` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_SHOPORDAUTO_PROC`(

	IN `V_BRANDCD` INT,

	IN `V_ORDSEQ` INT



,

	IN `V_INSERTID` VARCHAR(50)























)
BEGIN

	

	DECLARE _ORDSEQ INT;	

	DECLARE _COMPNO INT;

	DECLARE _REG_DATE  varchar(50);

	DECLARE _USER_NAME varchar(50);

	DECLARE _RECEIVE_ZIPCODE varchar(50);

	DECLARE _RECEIVE_ADDR varchar(200);

	DECLARE _RECEIVE_CEL varchar(50);

	DECLARE _RECEIVE_TEL varchar(50);

	DECLARE _SALE_CNT INT;						

	DECLARE _DELIVERY_METHOD_STR2 varchar(50);

	DECLARE _DELV_COST INT;

	DECLARE _PRODUCT_NAME varchar(200);

	DECLARE _PRODCD varchar(50);

	DECLARE _MALL_PRODUCT_ID varchar(50);

	DECLARE _SHOP_USERID varchar(50);

	DECLARE _DELV_MSG varchar(200);

	DECLARE _RECEIVE_NAME varchar(200);

	DECLARE _SALE_COST INT;

	

	DECLARE V_ORDDT varchar(8);

	DECLARE v_exists INT;

	DECLARE v_maxordseq INT;

	

	DECLARE done INT DEFAULT 0;

	DECLARE c1 CURSOR FOR SELECT ORDSEQ,COMPNO,REG_DATE,RECEIVE_NAME,RECEIVE_ZIPCODE,RECEIVE_ADDR,RECEIVE_TEL,RECEIVE_CEL,SALE_CNT,

								 		  DELV_COST,DELIVERY_METHOD_STR2,(case when char_length(ifnull(P_SKU_VALUE,''))>2 then P_SKU_VALUE else P_PRODUCT_NAME end),

								 		  COMPAYNY_GOODS_CD AS PRODCD,

								 		  DELV_MSG,concat((SELECT shopnm FROM shopinfo WHERE shopcd=A.shopid),' ',SHOP_USERID) as SHOP_USERID,

										  USER_NAME,MALL_PRODUCT_ID,total_cost

								   FROM SHOPORDMST A

						   	  WHERE ORDSEQ=V_ORDSEQ;									

	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;

	

	open c1;

	REPEAT

		FETCH NEXT FROM c1 INTO _ORDSEQ,_COMPNO,_REG_DATE,_RECEIVE_NAME,_RECEIVE_ZIPCODE,_RECEIVE_ADDR,_RECEIVE_TEL,_RECEIVE_CEL,_SALE_CNT,

								      _DELV_COST,_DELIVERY_METHOD_STR2,_PRODUCT_NAME,

								      _PRODCD,_DELV_MSG,_SHOP_USERID,_USER_NAME,_MALL_PRODUCT_ID,_SALE_COST;

		IF not done THEN

			set v_maxordseq = 0;

			SET v_exists = 0;

			SET V_ORDDT = DATE_FORMAT(_REG_DATE,'%Y%m%d');

			

			SELECT MAX(ORDSEQ) INTO v_exists FROM ORDMST WHERE COMPNO=_COMPNO AND ORDDT = V_ORDDT AND ORDSEQ = 3;

			IF v_exists > 0 then

				SELECT MAX(SEQ) INTO v_maxordseq FROM ORDDTL WHERE COMPNO = _COMPNO AND ORDDT = V_ORDDT AND ORDSEQ = 3;

				INSERT INTO ORDDTL(COMPNO,BRANDCD, ORDDT,ORDSEQ,SEQ,RORDDT,

								       RCVNAM,PSTNO,ADDR,CLPNO,TELNO,QTY,SHPFEE,CREDIT,OPTDESC,PRODCD,MESSGE,SABORDNO,SHOPID,ORDNM,MALLCD,ORDAMT) 

							   VALUES(_COMPNO,V_BRANDCD,V_ORDDT, 3, IFNULL(v_maxordseq,0)+1, DATE_FORMAT(_REG_DATE,'%Y-%m-%d %H:%i'), 

							          _RECEIVE_NAME,_RECEIVE_ZIPCODE, _RECEIVE_ADDR, _RECEIVE_CEL, _RECEIVE_TEL,_SALE_CNT,

								      _DELV_COST,_DELIVERY_METHOD_STR2,_PRODUCT_NAME,_PRODCD,_DELV_MSG,_ORDSEQ,_SHOP_USERID,_USER_NAME,_MALL_PRODUCT_ID,_SALE_COST);

			else

				INSERT INTO ORDMST(COMPNO,BRANDCD,ORDDT,ORDSEQ,INSERTDT,INSERTID)

							   VALUES(_COMPNO,V_BRANDCD,V_ORDDT, 3, NOW(), V_INSERTID);

				INSERT INTO ORDDTL(COMPNO,BRANDCD,ORDDT,ORDSEQ,SEQ,RORDDT,

								       RCVNAM,PSTNO,ADDR,CLPNO,TELNO,QTY,SHPFEE,CREDIT,OPTDESC,PRODCD,MESSGE,SABORDNO,SHOPID,ORDNM,MALLCD,ORDAMT) 

							   VALUES(_COMPNO,V_BRANDCD,V_ORDDT, 3, IFNULL(v_maxordseq,0)+1, DATE_FORMAT(_REG_DATE,'%Y-%m-%d %H:%i'), 

							          _RECEIVE_NAME,_RECEIVE_ZIPCODE, _RECEIVE_ADDR, _RECEIVE_CEL, _RECEIVE_TEL,_SALE_CNT,

								       _DELV_COST,_DELIVERY_METHOD_STR2,_PRODUCT_NAME,_PRODCD,_DELV_MSG,_ORDSEQ,_SHOP_USERID,_USER_NAME,_MALL_PRODUCT_ID,_SALE_COST);

			end if;

			UPDATE SHOPORDMST SET MLORDDT = V_ORDDT, MLORDSEQ = 3, MLSEQ = IFNULL(v_maxordseq,0)+1 WHERE COMPNO=_COMPNO AND ORDSEQ=V_ORDSEQ;

		END IF;

	UNTIL done END REPEAT;

	close c1;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_SUPPLYAUTO_PROC` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_SUPPLYAUTO_PROC`(

	IN `V_COMPNO` INT,

	IN `V_BRANDCD` INT,

	IN `V_ASIGNDT` VARCHAR(8),

	IN `V_ASIGNSEQ` INT,

	IN `V_SUPPDT` VARCHAR(8),

	IN `V_SUPPSEQ` INT



)
BEGIN

	
	
	
	
	DECLARE _orddt varchar(8);

	DECLARE _ordseq  INT;

	DECLARE _seq  INT;

	DECLARE _expnm varchar(100);

	DECLARE _invno varchar(100);

	

	DECLARE _rcvnam varchar(50);

	DECLARE _pstno varchar(10);

	DECLARE _addr varchar(200);

	DECLARE _expprodnm varchar(1000);

	

	DECLARE _sprodcdm varchar(20);

	

	DECLARE _sqty INT;

	DECLARE _picqty INT;

	

	DECLARE _prodcd varchar(200);

   DECLARE _prodcdm varchar(200);

   DECLARE _qty int;

   DECLARE _qty2 int;

   DECLARE _flagset char(1);

   DECLARE _levset char(1);

   DECLARE _proddtcd varchar(200);

   

   DECLARE u_orddt varchar(8);

	DECLARE u_ordseq  INT;

	DECLARE u_seq  INT;

   

   DECLARE v_warecd int;

   DECLARE v_neccd1 varchar(200);

   DECLARE v_neccd2 int;

   DECLARE v_neccd3 int;

   

	DECLARE v_seq INT DEFAULT 0;

	DECLARE v_necseq INT DEFAULT 0;



	DECLARE c1 CURSOR FOR SELECT orddt,ordseq,seq,expnm,invno,rcvnam, pstno, addr, expprodnm,prodcdm,qty2,qty2 as picqty 

									FROM PICKUPEXP

						   	  WHERE compno =V_COMPNO 

						     		 AND brandcd=V_BRANDCD

						     		 AND orddt  =V_ASIGNDT

							 		 AND ordseq =V_ASIGNSEQ;

							 		
							 		

	DECLARE c2 CURSOR FOR SELECT a.prodcd, b.prodcdm, a.qty, b.flagset

								   FROM ORDDTL a, V_PRODUCTS b 

								  WHERE a.COMPNO  = V_COMPNO

								    AND a.BRANDCD = V_BRANDCD

								    AND a.ASIGNDT   = _orddt

									 AND a.ASIGNSEQ  = _ordseq

									 AND a.ASIGNHSEQ = _seq

								    AND IFNULL(a.ORDAMT,0) <> 0

								    AND a.compno  = b.compno

									 AND a.brandcd = b.brandcd

									 AND a.prodcd  = b.prodcd

								  UNION

								 SELECT a.prodcd, b.prodcdm, a.qty, b.flagset

								   FROM ORDDTL a, V_PRODUCTS b 

								  WHERE a.COMPNO  = V_COMPNO

								    AND a.BRANDCD = V_BRANDCD

								    AND a.ORDDT = _orddt

									 
									 AND a.MOVESEQ = _seq

								    AND IFNULL(a.ORDAMT,0) <> 0

								    AND a.compno  = b.compno

									 AND a.brandcd = b.brandcd

									 AND a.prodcd  = b.prodcd;

									 

	DECLARE c4 CURSOR FOR SELECT proddtcd, levset, qtyset

									FROM PRODDTL 

								  WHERE COMPNO  = V_COMPNO 

								    and BRANDCD = V_BRANDCD

									 and PRODCD  = _prodcdm 

									 AND ifnull(flagset,'')='1';

	DECLARE c5 CURSOR FOR SELECT proddtcd, levset, qtyset 

									FROM PRODDTL 

								  WHERE COMPNO  = V_COMPNO

								    AND BRANDCD = V_BRANDCD 

									 and PRODCD  = _proddtcd

									 AND ifnull(flagset,'')='1';

									 

	
	
	Block0: BEGIN	

		update PICKUPEXP set SUPPDT=null,SUPPSEQ=null,SUPPHSEQ=null where compno=V_COMPNO and brandcd=V_BRANDCD AND SUPPDT = V_SUPPDT AND SUPPSEQ=V_SUPPSEQ;

		IF (SELECT EXISTS (SELECT 1 FROM SUPPDTL where compno=V_COMPNO and brandcd=V_BRANDCD AND SUPPDT = V_SUPPDT AND SUPPSEQ=V_SUPPSEQ) AS FLAG) THEN

			delete from SUPPDTL where compno=V_COMPNO and brandcd=V_BRANDCD AND SUPPDT = V_SUPPDT AND SUPPSEQ=V_SUPPSEQ;	

			delete from SUPPWARE where compno=V_COMPNO and brandcd=V_BRANDCD AND SUPPDT = V_SUPPDT AND SUPPSEQ=V_SUPPSEQ;	

		END IF;		 

	END Block0;

	

	Block1: BEGIN

		
		DECLARE done INT DEFAULT 0;

		DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;

		open c1;

		REPEAT

			FETCH NEXT FROM c1 INTO _orddt,_ordseq,_seq,_expnm,_invno,_rcvnam,_pstno,_addr,_expprodnm,_sprodcdm,_sqty,_picqty;

			IF not done THEN

			

				set v_necseq = 0;

				set v_seq = v_seq + 1;

				
				SELECT max(orddt),max(ordseq),max(seq) into u_orddt,u_ordseq,u_seq FROM ORDDTL WHERE compno=V_COMPNO and brandcd=V_BRANDCD AND asigndt = _orddt AND asignseq=_ordseq AND ASIGNHSEQ=_seq; 

				

				INSERT INTO SUPPDTL(COMPNO, BRANDCD, SUPPDT, SUPPSEQ, SEQ, EXPNM, INVNO, ORDDT, ORDSEQ, ORDHSEQ, RCVNAM, PSTNO, ADDR, PRODCD, EXPPRODNM, QTY, PICQTY)

								 VALUES(V_COMPNO,V_BRANDCD,V_SUPPDT,V_SUPPSEQ,v_seq,_expnm,_invno,u_orddt,u_ordseq,u_seq,_rcvnam, _pstno, _addr, _sprodcdm,_expprodnm,_sqty,_picqty);

								 

				update PICKUPEXP set SUPPDT=V_SUPPDT,SUPPSEQ=V_SUPPSEQ,SUPPHSEQ=v_seq where compno=V_COMPNO and brandcd=V_BRANDCD AND ORDDT = _orddt AND ORDSEQ=_ordseq AND SEQ=_seq;								 

				

				Block2: BEGIN

					
					DECLARE done2 INT DEFAULT 0;

					DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done2 = 1;

					open c2;

					REPEAT

						FETCH NEXT FROM c2 INTO _prodcd,_prodcdm,_qty,_flagset;

						IF not done2 THEN

							IF _prodcd <> _prodcdm then

								SELECT flagset into _flagset FROM PRODMST WHERE COMPNO = V_COMPNO and prodcd =_prodcdm;

							end if;

							IF ifnull(_flagset,'') = '1' then

								Block4: BEGIN

									DECLARE done4 INT DEFAULT 0;

									DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done4 = 1;

									open c4;

									REPEAT

										FETCH NEXT FROM c4 INTO _proddtcd,_levset,_qty2;

										IF not done4 THEN 

											IF IFNULL(_levset,'') = '2' THEN

												Block5: BEGIN

													DECLARE done5 INT DEFAULT 0;

													DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done5 = 1;

													open c5;

													REPEAT

														FETCH NEXT FROM c5 INTO _proddtcd,_levset,_qty2;

														IF not done5 THEN 

															

															set v_necseq = v_necseq + 1;

														   select ifnull(max(WARECD),1), ifnull(max(NECCD1),'A'), ifnull(max(NECCD2),1), ifnull(max(NECCD3),1) into v_warecd, v_neccd1, v_neccd2, v_neccd3 

															  from NECPRODMST 

															 where compno=V_COMPNO and brandcd=V_BRANDCD and prodcd=_prodcdm;

															 

															insert into SUPPWARE(COMPNO, BRANDCD, SUPPDT, SUPPSEQ, SEQ, NECSEQ, ADDSEQ, PRODCDM, PRODCD, SETLEVEL, WARECD, NECCD1, NECCD2, NECCD3, QTY) 

															VALUES(V_COMPNO,V_BRANDCD,V_SUPPDT,V_SUPPSEQ,v_seq,v_necseq,1,_prodcdm,_proddtcd,3,v_warecd,v_neccd1,v_neccd2,v_neccd3,_qty*_qty2);

															
														END IF;

													UNTIL done5 END REPEAT;

													close c5;

												END Block5;

											ELSE

			

												set v_necseq = v_necseq + 1;

											   select ifnull(max(WARECD),1), ifnull(max(NECCD1),'A'), ifnull(max(NECCD2),1), ifnull(max(NECCD3),1) into v_warecd, v_neccd1, v_neccd2, v_neccd3 

												  from NECPRODMST 

												 where compno=V_COMPNO and brandcd=V_BRANDCD and prodcd=_prodcdm;

												insert into SUPPWARE(COMPNO, BRANDCD, SUPPDT, SUPPSEQ, SEQ, NECSEQ, ADDSEQ, PRODCDM, PRODCD, SETLEVEL, WARECD, NECCD1, NECCD2, NECCD3, QTY) 

												VALUES(V_COMPNO,V_BRANDCD,V_SUPPDT,V_SUPPSEQ,v_seq,v_necseq,1,_prodcdm,_proddtcd,2,v_warecd,v_neccd1,v_neccd2,v_neccd3,_qty*_qty2);

												
											END IF;

										END IF;

									

									UNTIL done4 END REPEAT;

									close c4;

								END Block4;

							else

							   

							   set v_necseq = v_necseq + 1;

							   select ifnull(max(WARECD),1), ifnull(max(NECCD1),'A'), ifnull(max(NECCD2),1), ifnull(max(NECCD3),1) into v_warecd, v_neccd1, v_neccd2, v_neccd3 

								  from NECPRODMST 

								 where compno=V_COMPNO and brandcd=V_BRANDCD and prodcd=_prodcdm;

								 

								insert into SUPPWARE(COMPNO, BRANDCD, SUPPDT, SUPPSEQ, SEQ, NECSEQ, ADDSEQ, PRODCDM, PRODCD, SETLEVEL, WARECD, NECCD1, NECCD2, NECCD3, QTY) 

								VALUES(V_COMPNO,V_BRANDCD,V_SUPPDT,V_SUPPSEQ,v_seq,v_necseq,1,_prodcdm,_prodcdm,1,v_warecd,v_neccd1,v_neccd2,v_neccd3,_qty);

								

							END IF;

						END IF;

					UNTIL done2 END REPEAT;

					close c2;

				END Block2;

				

			END IF;

		UNTIL done END REPEAT;

		close c1;			 

	END Block1;

	

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_WAREHOUSE_QTY` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_WAREHOUSE_QTY`(

	IN `V_COMPNO` INT,

	IN `V_BRANDCD` INT,

	IN `V_ORDDT` VARCHAR(50),

	IN `V_ORDSEQ` INT,

	IN `V_CHKSEND` VARCHAR(1)

)
    COMMENT '이카운트 재고차감'
BEGIN

	drop TEMPORARY TABLE if EXISTS tmp;

	CREATE TEMPORARY TABLE IF NOT EXISTS tmp ENGINE=MEMORY AS

	(SELECT a.seq, ifnull(a.rorddt,'') as rorddt, ifnull(a.rcvnam,'') as rcvnam, ifnull(a.pstno,'') as pstno, 

			  ifnull(a.addr,'') as addr, ifnull(a.clpno,'') as clpno, ifnull(a.telno,'') as telno, a.qty, ifnull(a.shpfee,'') as shpfee, ifnull(a.credit,'') as credit,

		     IFNULL(b.prodnm,'') as prodnm, ifnull(b.ecountcd,'') as ecountcd, ifnull(a.messge,'') as messge, ifnull(a.pkgclss,'') as pkgclss,

			  ifnull(a.shipcls,'') as shipcls, ifnull(a.sabordno,'') as sabordno, ifnull(a.shopid,'') as shopid, ifnull(a.ordnm,'') as ordnm,  

		     ifnull(a.etcmsg,'') as etcmsg, ifnull(a.mallcd,'') as mallcd, ifnull(a.ordamt,'') as ordamt, ifnull(a.ECOUNTSNDYN,'N') as ecountsndyn, 

			  b.prodcd, b.prodcdm, b.flagset,b.expkindnm,b.expbundcd,b.expfile,b.expcd,b.expinvqty,ifnull(b.specdes,'') as specdes

	   FROM ORDDTL a, V_PRODUCTS b 

	  WHERE a.COMPNO=V_COMPNO 

	  	AND a.BRANDCD = V_BRANDCD

	    AND a.ORDDT=V_ORDDT

	    AND a.ORDSEQ=V_ORDSEQ

	    AND IFNULL(a.ORDAMT,0) <> 0

	    AND ifnull(a.ecountsndyn,'N') = V_CHKSEND

	    AND a.compno = b.compno

	    AND a.brandcd = b.brandcd

		AND a.prodcd = b.prodcd);

		

	drop TEMPORARY TABLE if EXISTS WAREHOUSE_QTY_TMP;

	CREATE TEMPORARY TABLE IF NOT EXISTS WAREHOUSE_QTY_TMP ENGINE=MEMORY AS (select * from tmp LIMIT 1);

	delete from WAREHOUSE_QTY_TMP;

	

	begin 

	   DECLARE _seq int;

	   DECLARE _ecountcd varchar(200);

	   DECLARE _prodcd varchar(200);

	   DECLARE _prodnm varchar(200);

	   DECLARE _specdes varchar(200);

	   DECLARE _qty int;

	   DECLARE _qty2 int;

	   DECLARE _rorddt varchar(200);

		DECLARE _rcvnam varchar(200);

		DECLARE _pstno varchar(200);

		DECLARE _addr varchar(200);

		DECLARE _clpno varchar(200);

		DECLARE _telno varchar(200);

		DECLARE _shpfee varchar(200);

		DECLARE _credit varchar(200);

		DECLARE _messge varchar(200);

		DECLARE _pkgclss varchar(200);

		DECLARE _shipcls varchar(200);

		DECLARE _sabordno varchar(200);

		DECLARE _shopid varchar(200);

		DECLARE _ordnm varchar(200);

		DECLARE _etcmsg varchar(200);

		DECLARE _mallcd varchar(200);

		DECLARE _ordamt varchar(200);

		DECLARE _ecountsndyn char(1);

	   DECLARE _prodcdm varchar(200);

	   DECLARE _flagset char(1);

	   DECLARE _levset char(1);

	   DECLARE _proddtcd varchar(200);

	   DECLARE _expkindnm varchar(200);

	   DECLARE _expbundcd varchar(200);

	   DECLARE _expfile varchar(200);

	   DECLARE _expcd  varchar(200);

	   DECLARE _expinvqty int;



	   DECLARE done INT DEFAULT 0; 

		DECLARE c2 CURSOR FOR SELECT proddtcd, levset, qtyset

										FROM PRODDTL 

									  WHERE compno=V_COMPNO

									  	 and brandcd = V_BRANDCD

									    and prodcd=_prodcdm 

									    AND ifnull(flagset,'')='1';

		DECLARE c3 CURSOR FOR SELECT proddtcd, levset, qtyset 

										FROM PRODDTL 

									   WHERE compno=V_COMPNO

									     and brandcd = V_BRANDCD

									     AND prodcd=_proddtcd

										 AND ifnull(flagset,'')='1';										 	   

	   DECLARE c1 CURSOR FOR SELECT * FROM tmp;

		DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;

								

		open c1;

	   REPEAT

		   FETCH NEXT FROM c1 INTO _seq,_rorddt,_rcvnam,_pstno,_addr,_clpno,_telno,_qty,

											_shpfee,_credit,_prodnm,_ecountcd,

											_messge,_pkgclss,_shipcls,_sabordno,_shopid,_ordnm,_etcmsg,_mallcd,_ordamt,

											_ecountsndyn,_prodcd,_prodcdm,_flagset,_expkindnm,_expbundcd,_expfile,_expcd,_expinvqty,_specdes;

			   IF not done THEN   

				   IF _prodcd <>_prodcdm then

						SELECT flagset into _flagset FROM PRODMST WHERE compno=V_COMPNO and brandcd = V_BRANDCD AND prodcd =_prodcdm;

				   end if;

				   IF ifnull(_flagset,'') = '1' then

				   	Block2: BEGIN

				   		DECLARE done2 INT DEFAULT 0;

					   	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done2 = 1;

					   	open c2;

						   REPEAT

						   	FETCH NEXT FROM c2 INTO _proddtcd,_levset,_qty2;

							   	IF not done2 THEN 

								   	IF IFNULL(_levset,'') = '2' THEN

											Block3: BEGIN

												DECLARE done3 INT DEFAULT 0;

										   	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done3 = 1;

										   	open c3;

											   REPEAT

											   	FETCH NEXT FROM c3 INTO _proddtcd,_levset,_qty2;

								   				IF not done3 THEN 

												   	SELECT ecountcd,ifnull(prodnm,''),ifnull(specdes,'') into _ecountcd,_prodnm,_specdes FROM PRODMST WHERE compno=V_COMPNO and brandcd = V_BRANDCD AND prodcd=_proddtcd;

														insert into WAREHOUSE_QTY_TMP values(_seq,_rorddt,_rcvnam,_pstno,_addr,_clpno,_telno, _qty*_qty2,

																						_shpfee,_credit,concat(_prodnm,'_',_specdes),_ecountcd,

																						_messge,_pkgclss,_shipcls,_sabordno,_shopid,_ordnm,_etcmsg,_mallcd,_ordamt,

																						_ecountsndyn,_proddtcd,_prodcdm,_flagset,_expkindnm,_expbundcd,_expfile,_expcd,_expinvqty,_specdes);

													END IF;

											   UNTIL done3 END REPEAT;

											   close c3;

											END Block3;

										ELSE

											SELECT ecountcd,ifnull(prodnm,''),ifnull(specdes,'') into _ecountcd,_prodnm,_specdes FROM PRODMST WHERE compno=V_COMPNO and brandcd = V_BRANDCD AND prodcd=_proddtcd;

											insert into WAREHOUSE_QTY_TMP values(_seq,_rorddt,_rcvnam,_pstno,_addr,_clpno,_telno, _qty*_qty2,

																			_shpfee,_credit,concat(_prodnm,'_',_specdes),_ecountcd,

																			_messge,_pkgclss,_shipcls,_sabordno,_shopid,_ordnm,_etcmsg,_mallcd,_ordamt,

																			_ecountsndyn,_proddtcd,_prodcdm,_flagset,_expkindnm,_expbundcd,_expfile,_expcd,_expinvqty,_specdes);

										END IF;

									END IF;

						   UNTIL done2 END REPEAT;

						   close c2;

					   END Block2;

				   else

						insert into WAREHOUSE_QTY_TMP values(_seq,_rorddt,_rcvnam,_pstno,_addr,_clpno,_telno,_qty,

														_shpfee,_credit,concat(_prodnm,'_',_specdes),_ecountcd,

														_messge,_pkgclss,_shipcls,_sabordno,_shopid,_ordnm,_etcmsg,_mallcd,_ordamt,

														_ecountsndyn,_prodcd,_prodcdm,_flagset,_expkindnm,_expbundcd,_expfile,_expcd,_expinvqty,_specdes);

					END IF;

				END IF;

		UNTIL done END REPEAT;

		select * from WAREHOUSE_QTY_TMP;

		close c1;

	end;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `YWM_WAREPRODLIST_UNIT` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `YWM_WAREPRODLIST_UNIT`(

	IN `V_COMPNO` INT,

	IN `V_PRODCD` VARCHAR(20)

)
    COMMENT '특정상품별 셋트상품 감안한 상품리스트'
BEGIN



	
	
	
	
	
	
	
	
	
	
	
	
					

	drop TEMPORARY TABLE if EXISTS tmp;

	CREATE TEMPORARY TABLE IF NOT EXISTS tmp ENGINE=MEMORY AS

	(SELECT prodcd, prodcdm, flagset

	   FROM V_PRODUCTS

	  WHERE compno=V_COMPNO and prodcd = V_PRODCD);

		

	drop TEMPORARY TABLE if EXISTS TMP_WAREPRODLIST;

	CREATE TEMPORARY TABLE IF NOT EXISTS TMP_WAREPRODLIST ENGINE=MEMORY AS (select prodcd from tmp LIMIT 1);

	delete from TMP_WAREPRODLIST;

	

	begin 

	   DECLARE _prodcd varchar(200);

	   DECLARE _prodnm varchar(200);

	   DECLARE _prodcdm varchar(200);

	   DECLARE _flagset char(1);

	   DECLARE _levset char(1);

	   DECLARE _proddtcd varchar(200);

		DECLARE done INT DEFAULT 0; 

		DECLARE c2 CURSOR FOR SELECT proddtcd, levset

										FROM PRODDTL 

									  WHERE compno=V_COMPNO 

									    and prodcd=_prodcdm 

									    AND ifnull(flagset,'')='1';

		DECLARE c3 CURSOR FOR SELECT proddtcd

										FROM PRODDTL 

									   WHERE compno=V_COMPNO 

									     and prodcd=_proddtcd

										 AND ifnull(flagset,'')='1';										 	   

	   DECLARE c1 CURSOR FOR SELECT * FROM tmp;

		DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;

		

		

							

		open c1;

	   REPEAT

			FETCH NEXT FROM c1 INTO _prodcd,_prodcdm,_flagset;

				IF not done THEN  

					
					IF _prodcd <> _prodcdm then

						SELECT flagset into _flagset FROM PRODMST WHERE compno=V_COMPNO and prodcd =_prodcdm;

				   end if;

				   IF ifnull(_flagset,'') = '1' then

						Block2: BEGIN

				   		DECLARE done2 INT DEFAULT 0;

					   	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done2 = 1;

					   	open c2;

						   REPEAT

						   	FETCH NEXT FROM c2 INTO _proddtcd,_levset;

							   	IF not done2 THEN 

								   	IF IFNULL(_levset,'') = '2' THEN

											Block3: BEGIN

											DECLARE done3 INT DEFAULT 0;

											DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done3 = 1;

											open c3;

											REPEAT

											  	FETCH NEXT FROM c3 INTO _proddtcd;

								   			IF not done3 THEN

													
													insert into TMP_WAREPRODLIST values(_proddtcd);

												END IF;

											UNTIL done3 END REPEAT;

											close c3;

											END Block3;

										ELSE

											
											insert into TMP_WAREPRODLIST values(_proddtcd);

										END IF;

									END IF;

						    UNTIL done2 END REPEAT;

						    close c2;

					   END Block2;

				   else

				   	
						insert into TMP_WAREPRODLIST values(_prodcdm);

					END IF;

				 END IF;

		UNTIL done END REPEAT;

		close c1;

	end;

END ;;
DELIMITER ;

--
-- Final view structure for view `v_products`
--

/*!50001 DROP VIEW IF EXISTS `v_products`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `v_products` AS select `a`.`compno` AS `compno`,`a`.`brandcd` AS `brandcd`,`a`.`prodcd` AS `prodcd`,`a`.`prodnm` AS `prodnm`,`a`.`specdes` AS `specdes`,`a`.`ecountcd` AS `ecountcd`,`a`.`neccd1` AS `neccd1`,`a`.`neccd2` AS `neccd2`,`a`.`neccd3` AS `neccd3`,`a`.`expbundcd` AS `expbundcd`,`a`.`expcd` AS `expcd`,`a`.`expkindnm` AS `expkindnm`,`a`.`expfile` AS `expfile`,`a`.`prodcdm` AS `prodcdm`,`a`.`price` AS `price`,`a`.`tagprice` AS `tagprice`,`a`.`remark` AS `remark`,`a`.`flagset` AS `flagset`,`a`.`sabcd` AS `sabcd`,`a`.`expinvqty` AS `expinvqty`,`a`.`expoutnm` AS `expoutnm`,`a`.`cusprice` AS `cusprice`,`a`.`optprodcd` AS `optprodcd`,`a`.`expinner` AS `expinner`,`a`.`expcostnm` AS `expcostnm`,`a`.`delyn` AS `delyn`,`a`.`flagpart` AS `flagpart` from (select `a`.`COMPNO` AS `compno`,`a`.`BRANDCD` AS `brandcd`,`a`.`PRODCD` AS `prodcd`,`a`.`PRODNM` AS `prodnm`,`a`.`SPECDES` AS `specdes`,`a`.`ECOUNTCD` AS `ecountcd`,`c`.`NECCD1` AS `neccd1`,`c`.`NECCD2` AS `neccd2`,`c`.`NECCD3` AS `neccd3`,`d`.`EXPBUNDCD` AS `expbundcd`,`d`.`EXPCD` AS `expcd`,`d`.`EXPKINDNM` AS `expkindnm`,`d`.`EXPFILE` AS `expfile`,`a`.`PRODCD` AS `prodcdm`,`a`.`PRICE` AS `price`,`a`.`TAGPRICE` AS `tagprice`,`a`.`REMARK` AS `remark`,`a`.`FLAGSET` AS `flagset`,`a`.`SABCD` AS `sabcd`,`d`.`EXPINVQTY` AS `expinvqty`,`d`.`EXPOUTNM` AS `expoutnm`,`a`.`CUSPRICE` AS `cusprice`,`e`.`PRODCD` AS `optprodcd`,`d`.`EXPINNER` AS `expinner`,`d`.`EXPCOSTNM` AS `expcostnm`,ifnull(`a`.`DELYN`,'N') AS `delyn`,`a`.`FLAGPART` AS `flagpart` from (((`prodmst` `a` left join `necprodmst` `c` on(((`a`.`COMPNO` = `c`.`COMPNO`) and (`a`.`BRANDCD` = `c`.`BRANDCD`) and (`a`.`PRODCD` = `c`.`PRODCD`)))) left join `expprodmst` `d` on(((`a`.`COMPNO` = `d`.`COMPNO`) and (`a`.`BRANDCD` = `d`.`BRANDCD`) and (`a`.`PRODCD` = `d`.`PRODCD`)))) left join `optprodmst` `e` on(((`a`.`COMPNO` = `e`.`COMPNO`) and (`a`.`BRANDCD` = `e`.`BRANDCD`) and (convert(`a`.`PRODCD` using utf8mb4) = `e`.`OPTPRODCD`)))) union select `a`.`COMPNO` AS `compno`,`a`.`BRANDCD` AS `brandcd`,`a`.`PRODDTCD` AS `prodcd`,`b`.`PRODNM` AS `prodnm`,`b`.`SPECDES` AS `specdes`,`b`.`ECOUNTCD` AS `ecountcd`,`c`.`NECCD1` AS `neccd1`,`c`.`NECCD2` AS `neccd2`,`c`.`NECCD3` AS `neccd3`,`d`.`EXPBUNDCD` AS `expbundcd`,`d`.`EXPCD` AS `expcd`,`d`.`EXPKINDNM` AS `expkindnm`,`d`.`EXPFILE` AS `expfile`,`b`.`PRODCD` AS `prodcdm`,`b`.`PRICE` AS `price`,`b`.`TAGPRICE` AS `tagprice`,`b`.`REMARK` AS `remark`,`a`.`FLAGSET` AS `flagset`,`a`.`SABCD` AS `sabcd`,`d`.`EXPINVQTY` AS `expinvqty`,`d`.`EXPOUTNM` AS `expoutnm`,`b`.`CUSPRICE` AS `cusprice`,`e`.`PRODCD` AS `optprodcd`,`d`.`EXPINNER` AS `expinner`,`d`.`EXPCOSTNM` AS `expcostnm`,ifnull(`b`.`DELYN`,'N') AS `delyn`,`b`.`FLAGPART` AS `flagpart` from ((((`proddtl` `a` join `prodmst` `b` on(((`a`.`COMPNO` = `b`.`COMPNO`) and (`a`.`BRANDCD` = `b`.`BRANDCD`) and (`a`.`PRODCD` = `b`.`PRODCD`)))) left join `necprodmst` `c` on(((`b`.`COMPNO` = `c`.`COMPNO`) and (`b`.`BRANDCD` = `c`.`BRANDCD`) and (`b`.`PRODCD` = `c`.`PRODCD`)))) left join `expprodmst` `d` on(((`b`.`COMPNO` = `d`.`COMPNO`) and (`b`.`BRANDCD` = `d`.`BRANDCD`) and (`b`.`PRODCD` = `d`.`PRODCD`)))) left join `optprodmst` `e` on(((`a`.`COMPNO` = `e`.`COMPNO`) and (`a`.`BRANDCD` = `e`.`BRANDCD`) and (convert(`a`.`PRODCD` using utf8mb4) = `e`.`OPTPRODCD`)))) where (ifnull(`a`.`FLAGSET`,'') <> '1')) `a` */;


