From: newton-cn Date: Sat, 24 May 2025 02:56:07 +0000 (+0900) Subject: mm X-Git-Url: https://git.insang.kr/gitweb/?a=commitdiff_plain;h=9129c14135a79a2a99df228a9993a775867c8930;p=wevape-lu1_pos.git mm --- diff --git a/.vs/newton-cn/v16/.suo b/.vs/newton-cn/v16/.suo index cd8dec7..1c4ac09 100644 Binary files a/.vs/newton-cn/v16/.suo and b/.vs/newton-cn/v16/.suo differ diff --git "a/DB_\355\224\204\353\241\234\354\213\234\354\240\200,\355\212\270\353\246\254\352\261\260/\354\277\274\353\246\254\353\254\270/other_shop_find_ps.sql" "b/DB_\355\224\204\353\241\234\354\213\234\354\240\200,\355\212\270\353\246\254\352\261\260/\354\277\274\353\246\254\353\254\270/other_shop_find_ps.sql" new file mode 100644 index 0000000..89155ae --- /dev/null +++ "b/DB_\355\224\204\353\241\234\354\213\234\354\240\200,\355\212\270\353\246\254\352\261\260/\354\277\274\353\246\254\353\254\270/other_shop_find_ps.sql" @@ -0,0 +1,52 @@ +drop procedure other_shop_find_ps; +CREATE PROCEDURE other_shop_find_ps + @month NVARCHAR(7), -- 예: '2025-05' + @shopName NVARCHAR(100), -- 예: '청라점' + @ctcode NVARCHAR(100) -- 예: '006017' +AS +BEGIN + SET NOCOUNT ON; + + DECLARE @server NVARCHAR(100); + DECLARE @sql NVARCHAR(2000); + DECLARE @startDate NVARCHAR(10); + DECLARE @endDate NVARCHAR(10); + + -- 시작일과 끝일 생성 + SET @startDate = @month + '-01'; + SET @endDate = CONVERT(NVARCHAR(10), DATEADD(MONTH, 1, CAST(@startDate AS DATETIME)), 120) + '-01'; + + -- Linked Server 이름 가져오기 + SELECT @server = gubun + FROM other_shop + WHERE gubun = @shopName; + + IF @server IS NULL + BEGIN + RAISERROR('지점명이 잘못되었거나 서버 정보가 없습니다.', 16, 1); + RETURN; + END + + -- 쿼리 동적 구성 (모든 쿼리는 OPENQUERY 내부에서 실행되어야 함) + SET @sql = N' + SELECT * + FROM OPENQUERY([' + @server + N'], + '' + SELECT + CONVERT(VARCHAR(10), a3.ps_date, 120) + CHAR(13) + CHAR(10) + CONVERT(VARCHAR(5), a3.ps_date, 108) AS 날짜, + a3.ps_prname as 상품명, + a3.ps_up as 금액, + a3.ps_qty as 수량 + FROM + ct a1 + JOIN pe a2 ON a1.ct_code = a2.ct_code + JOIN ps a3 ON a2.pe_id = a3.pe_id + WHERE + a1.ct_code = ''''' + @ctcode + N''''' + AND a3.ps_date BETWEEN ''''' + @startDate + N''''' AND ''''' + @endDate + N''''' + '')'; + + EXEC sp_executesql @sql; +END; + +exec other_shop_find_ps '2025-05', 'lu1', '0000000009'; \ No newline at end of file diff --git "a/DB_\355\224\204\353\241\234\354\213\234\354\240\200,\355\212\270\353\246\254\352\261\260/\354\277\274\353\246\254\353\254\270/\353\213\244\353\245\270\353\247\244\354\236\245\355\232\214\354\233\220\354\240\225\353\263\264\354\241\260\355\232\214.sql" "b/DB_\355\224\204\353\241\234\354\213\234\354\240\200,\355\212\270\353\246\254\352\261\260/\354\277\274\353\246\254\353\254\270/\353\213\244\353\245\270\353\247\244\354\236\245\355\232\214\354\233\220\354\240\225\353\263\264\354\241\260\355\232\214.sql" new file mode 100644 index 0000000..9927db8 --- /dev/null +++ "b/DB_\355\224\204\353\241\234\354\213\234\354\240\200,\355\212\270\353\246\254\352\261\260/\354\277\274\353\246\254\353\254\270/\353\213\244\353\245\270\353\247\244\354\236\245\355\232\214\354\233\220\354\240\225\353\263\264\354\241\260\355\232\214.sql" @@ -0,0 +1,65 @@ +--테이블 +create table other_shop( + gubun varchar(2000) primary key, + name varchar(2000), + memo varchar(2000) +); + +insert into other_shop values ('lu1', '가정점', ''); + + + +drop procedure other_shop_find_ct; +--프로시저 +CREATE PROCEDURE other_shop_find_ct + @shopName NVARCHAR(100), + @searchField NVARCHAR(10), + @keyword NVARCHAR(100) +AS +BEGIN + SET NOCOUNT ON; + + DECLARE @server NVARCHAR(100); + DECLARE @sql NVARCHAR(2000); + DECLARE @where NVARCHAR(2000); + + -- 1. Linked Server 이름 조회 + SELECT @server = gubun + FROM other_shop + WHERE gubun = @shopName; + + -- 2. 서버명이 없을 경우 종료 + IF @server IS NULL + BEGIN + RAISERROR('지점명에 해당하는 서버명이 존재하지 않습니다.', 16, 1); + RETURN; + END + + -- 3. 조건절 구성 + IF @searchField = 'phone' + BEGIN + SET @where = N'ct_phone LIKE ''''%' + @keyword + '%'''' OR ct_cphone LIKE ''''%' + @keyword + '%'''''; + END + ELSE IF @searchField = 'name' + BEGIN + SET @where = N'ct_name LIKE ''''%' + @keyword + '%'''''; + END + ELSE + BEGIN + RAISERROR('검색 조건은 ''phone'' 또는 ''name'' 중 하나여야 합니다.', 16, 1); + RETURN; + END + + -- 4. 전체 쿼리 생성 + SET @sql = N' + SELECT * + FROM OPENQUERY([' + @server + N'], + ''SELECT ct_code as 회원코드, ct_name as 회원명, ct_phone as 전화번호, ct_cphone as 휴대전화, ct_zip, ct_addr1, ct_addr2, ct_memo, ct_no, ct_birth, ct_tpoint, ct_rpoint, ct_visitn, ct_sale, ct_visitd, ct_date + FROM ct + WHERE ' + @where + N''')'; + + -- 5. 실행 + EXEC sp_executesql @sql; +END; + +exec other_shop_find_ct 'lu1', 'phone', '5323'; \ No newline at end of file diff --git "a/DB_\355\224\204\353\241\234\354\213\234\354\240\200,\355\212\270\353\246\254\352\261\260/\354\277\274\353\246\254\353\254\270/\354\203\201\355\222\210 visible \354\227\205\353\215\260\354\235\264\355\212\270\354\213\234 \355\212\270\353\246\254\352\261\260.sql" "b/DB_\355\224\204\353\241\234\354\213\234\354\240\200,\355\212\270\353\246\254\352\261\260/\354\277\274\353\246\254\353\254\270/\354\203\201\355\222\210 visible \354\227\205\353\215\260\354\235\264\355\212\270\354\213\234 \355\212\270\353\246\254\352\261\260.sql" new file mode 100644 index 0000000..751756d --- /dev/null +++ "b/DB_\355\224\204\353\241\234\354\213\234\354\240\200,\355\212\270\353\246\254\352\261\260/\354\277\274\353\246\254\353\254\270/\354\203\201\355\222\210 visible \354\227\205\353\215\260\354\235\264\355\212\270\354\213\234 \355\212\270\353\246\254\352\261\260.sql" @@ -0,0 +1,35 @@ +drop trigger trg_pr_visible_update; + +CREATE TRIGGER trg_pr_visible_update +ON pr +AFTER UPDATE +AS +BEGIN + SET NOCOUNT ON; + + IF UPDATE(PR_VISIBLE) + BEGIN + -- 0 → 1 (숨김 처리) : PR_ORDER보다 큰 친구들은 -1 유지 + UPDATE p + SET p.PR_ORDER = p.PR_ORDER - 1 + FROM pr p + JOIN inserted i ON p.KIND_CODE = i.KIND_CODE + JOIN deleted d ON i.PR_CODE = d.PR_CODE + WHERE + i.PR_VISIBLE = 1 AND d.PR_VISIBLE = 0 + AND p.PR_ORDER > i.PR_ORDER; + + -- 1 → 0 (보임 처리) : pr_order 재설정만 (자리 만드는 작업 없음) + UPDATE p + SET p.PR_ORDER = ( + SELECT COUNT(*) + FROM pr + WHERE kind_code = i.kind_code AND pr_visible = 0 + ) + FROM pr p + JOIN inserted i ON p.PR_CODE = i.PR_CODE + JOIN deleted d ON i.PR_CODE = d.PR_CODE + WHERE + i.PR_VISIBLE = 0 AND d.PR_VISIBLE = 1; + END +END; diff --git "a/DB_\355\224\204\353\241\234\354\213\234\354\240\200,\355\212\270\353\246\254\352\261\260/\354\277\274\353\246\254\353\254\270/\354\203\201\355\222\210\353\223\261\353\241\235 \354\236\220\353\217\231\354\234\274\353\241\234 order \353\223\244\354\226\264\352\260\200\352\262\214.sql" "b/DB_\355\224\204\353\241\234\354\213\234\354\240\200,\355\212\270\353\246\254\352\261\260/\354\277\274\353\246\254\353\254\270/\354\203\201\355\222\210\353\223\261\353\241\235 \354\236\220\353\217\231\354\234\274\353\241\234 order \353\223\244\354\226\264\352\260\200\352\262\214.sql" new file mode 100644 index 0000000..82ee1f6 --- /dev/null +++ "b/DB_\355\224\204\353\241\234\354\213\234\354\240\200,\355\212\270\353\246\254\352\261\260/\354\277\274\353\246\254\353\254\270/\354\203\201\355\222\210\353\223\261\353\241\235 \354\236\220\353\217\231\354\234\274\353\241\234 order \353\223\244\354\226\264\352\260\200\352\262\214.sql" @@ -0,0 +1,205 @@ +-- 청라 +drop trigger trg_pr_insert; + +CREATE TRIGGER trg_pr_insert +ON pr +INSTEAD OF INSERT +AS +BEGIN + SET NOCOUNT ON; + + INSERT INTO pr ( + PR_CODE, + PR_NAME, + KIND_CODE, + PR_KIND, + PR_DATE, + PR_PRICE1, + PR_PRICE2, + PR_PRICE3, + PR_COST, + PR_PRT, + PR_CK, + PR_TAX, + PR_IVCK, + PR_DCGU, + PR_VISIBLE, + PR_SETGU, + PR_COSGU, + PR_OPTGU, + PR_CPRGU, + PR_ORDER, -- ← 덮어씌움 + PR_BARCODE, + PR_QTYS, + PR_QTY, + PR_UNT, + PR_INQTY, + PR_OPEN, + PR_POINT, + PR_PRINTAMT, + PR_REG, + PR_STYPE, + PR_ORDUSE, -- ← 덮어씌움 + PR_FONTSIZE, + PR_AFTERPRICE, + PR_EVT, + PR_ORDER_P, + PR_ORDER_Y, + PR_ORDER_X, + PR_VISIBLE2, + PR_GU, + PR_NICK, + rn + ) + SELECT + i.PR_CODE, + i.PR_NAME, + i.KIND_CODE, + i.PR_KIND, + i.PR_DATE, + i.PR_PRICE1, + i.PR_PRICE2, + i.PR_PRICE3, + i.PR_COST, + i.PR_PRT, + i.PR_CK, + i.PR_TAX, + i.PR_IVCK, + i.PR_DCGU, + i.PR_VISIBLE, + i.PR_SETGU, + i.PR_COSGU, + i.PR_OPTGU, + i.PR_CPRGU, + ( + SELECT COUNT(*) + 1 + FROM pr + WHERE KIND_CODE = i.KIND_CODE and pr_visible= 0 + ) AS PR_ORDER, -- 자동 계산 + i.PR_BARCODE, + i.PR_QTYS, + i.PR_QTY, + i.PR_UNT, + i.PR_INQTY, + i.PR_OPEN, + i.PR_POINT, + i.PR_PRINTAMT, + i.PR_REG, + i.PR_STYPE, + 1 AS PR_ORDUSE, -- 강제 설정 + i.PR_FONTSIZE, + i.PR_AFTERPRICE, + i.PR_EVT, + i.PR_ORDER_P, + i.PR_ORDER_Y, + i.PR_ORDER_X, + i.PR_VISIBLE2, + i.PR_GU, + i.PR_NICK, + i.rn + FROM inserted i; +END; + + + +-- 루원 +drop trigger trg_pr_insert; + +CREATE TRIGGER trg_pr_insert +ON pr +INSTEAD OF INSERT +AS +BEGIN + SET NOCOUNT ON; + + INSERT INTO pr ( + PR_CODE, + PR_NAME, + KIND_CODE, + PR_KIND, + PR_DATE, + PR_PRICE1, + PR_PRICE2, + PR_PRICE3, + PR_COST, + PR_PRT, + PR_CK, + PR_TAX, + PR_IVCK, + PR_DCGU, + PR_VISIBLE, + PR_SETGU, + PR_COSGU, + PR_OPTGU, + PR_CPRGU, + PR_ORDER, -- ← 덮어씌움 + PR_BARCODE, + PR_QTYS, + PR_QTY, + PR_UNT, + PR_INQTY, + PR_OPEN, + PR_POINT, + PR_PRINTAMT, + PR_REG, + PR_STYPE, + PR_ORDUSE, -- ← 덮어씌움 + PR_FONTSIZE, + PR_AFTERPRICE, + PR_EVT, + PR_ORDER_P, + PR_ORDER_Y, + PR_ORDER_X, + PR_VISIBLE2, + PR_GU, + PR_NICK, + rn + ) + SELECT + i.PR_CODE, + i.PR_NAME, + i.KIND_CODE, + i.PR_KIND, + i.PR_DATE, + i.PR_PRICE1, + i.PR_PRICE2, + i.PR_PRICE3, + i.PR_COST, + i.PR_PRT, + i.PR_CK, + i.PR_TAX, + i.PR_IVCK, + i.PR_DCGU, + i.PR_VISIBLE, + i.PR_SETGU, + i.PR_COSGU, + i.PR_OPTGU, + i.PR_CPRGU, + ( + SELECT COUNT(*) + 1 + FROM pr + WHERE KIND_CODE = i.KIND_CODE and pr_visible= 0 + ) AS PR_ORDER, -- 자동 계산 + i.PR_BARCODE, + i.PR_QTYS, + i.PR_QTY, + i.PR_UNT, + i.PR_INQTY, + i.PR_OPEN, + i.PR_POINT, + i.PR_PRINTAMT, + i.PR_REG, + i.PR_STYPE, + 1 AS PR_ORDUSE, -- 강제 설정 + i.PR_FONTSIZE, + i.PR_AFTERPRICE, + i.PR_EVT, + i.PR_ORDER_P, + i.PR_ORDER_Y, + i.PR_ORDER_X, + i.PR_VISIBLE2, + i.PR_GU, + i.PR_NICK, + i.rn + FROM inserted i; +END; diff --git "a/DB_\355\224\204\353\241\234\354\213\234\354\240\200,\355\212\270\353\246\254\352\261\260/\354\277\274\353\246\254\353\254\270/\354\235\274\355\232\214\354\232\251\354\240\201\353\246\275\355\224\204\353\241\234\354\213\234\354\240\200.sql" "b/DB_\355\224\204\353\241\234\354\213\234\354\240\200,\355\212\270\353\246\254\352\261\260/\354\277\274\353\246\254\353\254\270/\354\235\274\355\232\214\354\232\251\354\240\201\353\246\275\355\224\204\353\241\234\354\213\234\354\240\200.sql" new file mode 100644 index 0000000..9eec39e --- /dev/null +++ "b/DB_\355\224\204\353\241\234\354\213\234\354\240\200,\355\212\270\353\246\254\352\261\260/\354\277\274\353\246\254\353\254\270/\354\235\274\355\232\214\354\232\251\354\240\201\353\246\275\355\224\204\353\241\234\354\213\234\354\240\200.sql" @@ -0,0 +1,59 @@ + +drop procedure disposable_analysis_earn; + +EXEC disposable_analysis_earn '2025-05-03'; + +CREATE PROCEDURE disposable_analysis_earn + @SelectedDate DATETIME +AS +BEGIN + SET NOCOUNT ON; + SELECT + CONVERT(CHAR(19), a1.ps_date, 20) AS ps_date, + a2.ct_code, + a2.ct_name + '(' + a5.ct_phone + ')' AS ct_name, + a1.ps_prname, + CAST(a1.ps_qty AS INT) AS ps_qty, + CAST( + ( + ISNULL(( + SELECT SUM(ps_up * ps_qty) + FROM ps + WHERE pe_id = a1.pe_id and ps_no= a1.ps_no + AND ps_prcode IN ( + SELECT pr_code FROM pr + where kind_code in (select kind_code from disposable_analysis_info where gubun in ('wevape', 'etc')) + ) + ), 0) + ) + + + ( + ISNULL(( + SELECT SUM(ps_up * ps_qty) + FROM ps + WHERE pe_id = a1.pe_id + AND ps_prcode IN ( + SELECT pr_code FROM pr + WHERE kind_code = '1100' + ) + ), 0) + ) + AS INT) AS pe_bamt, + a1.pe_id, + a1.ps_no, + ISNULL(a3.is_earn, 0) AS is_earn, + (case when a1.ps_dc != 0 then 'O' else 'X' end) as is_dc + FROM ps a1 + JOIN pe a2 ON a1.pe_id = a2.pe_id AND a2.ct_code != '' + LEFT JOIN disposable_earn_point_status a3 ON a3.pe_id = a1.pe_id AND a3.ps_no = a1.ps_no + JOIN ac a4 ON a4.pe_id = a1.pe_id AND a4.ac_fncd2 NOT IN ('01', '00') + JOIN ct a5 ON a5.ct_code = a2.ct_code + WHERE + a1.ps_prcode IN ( + SELECT pr_code FROM pr WHERE kind_code IN (select kind_code from disposable_analysis_info where gubun in ('wevape', 'etc')) + ) + AND a1.ps_date >= @SelectedDate + AND a1.ps_date < DATEADD(DAY, 1, @SelectedDate) + ORDER BY + a1.pe_id DESC; +END; \ No newline at end of file diff --git "a/DB_\355\224\204\353\241\234\354\213\234\354\240\200,\355\212\270\353\246\254\352\261\260/\354\277\274\353\246\254\353\254\270/\354\235\274\355\232\214\354\232\251\355\224\204\353\241\234\354\213\234\354\240\200.sql" "b/DB_\355\224\204\353\241\234\354\213\234\354\240\200,\355\212\270\353\246\254\352\261\260/\354\277\274\353\246\254\353\254\270/\354\235\274\355\232\214\354\232\251\355\224\204\353\241\234\354\213\234\354\240\200.sql" new file mode 100644 index 0000000..5d3cc47 --- /dev/null +++ "b/DB_\355\224\204\353\241\234\354\213\234\354\240\200,\355\212\270\353\246\254\352\261\260/\354\277\274\353\246\254\353\254\270/\354\235\274\355\232\214\354\232\251\355\224\204\353\241\234\354\213\234\354\240\200.sql" @@ -0,0 +1,311 @@ +create procedure disposable_analysis_old + @year_month nvarchar(7) -- "YYYY-MM" 형식의 월별 입력값 +as +begin + -- 시작일과 종료일 계산 + declare @start_date datetime; + declare @end_date datetime; + + set @start_date = convert(datetime, @year_month + '-01'); + set @end_date = dateadd(month, 1, @start_date); + + -- 임시 테이블 생성 (판매개수 컬럼으로 변경) + create table #product_sales ( + product_name varchar(100), + product_sales varchar(50), -- 문자열로 저장 (반점 포함) + product_ratio varchar(10), -- 문자열로 저장 + product_qty int -- 판매개수 컬럼 + ); + + -- 매출 계산 + declare @totalamount numeric(18, 0); + declare @disposableamount numeric(18, 0); + + select + @totalamount = sum(ps_amt + ps_vat), + @disposableamount = sum(case when kind.kind_code in (1099, 1105, 1106, 1107, 1108) then ps_amt + ps_vat else 0 end) + from ps + join pr on ps.ps_prcode = pr.pr_code + join kind on pr.kind_code = kind.kind_code + where ps.ps_date >= @start_date and ps.ps_date < @end_date; + + declare @totalamount_str varchar(50); + declare @disposableamount_str varchar(50); + + set @totalamount_str = replace(convert(varchar(50), cast(@totalamount as money), 1), '.00', ''); + set @disposableamount_str = replace(convert(varchar(50), cast(@disposableamount as money), 1), '.00', ''); + + insert into #product_sales + values (@year_month + ' ' + '매출', @totalamount_str, null, null); + + insert into #product_sales + values (@year_month + ' ' + '일회용매출', @disposableamount_str, null, null); + + declare @disposable_ratio varchar(10); + if @totalamount > 0 + begin + set @disposable_ratio = cast(cast(@disposableamount * 100.0 / @totalamount as numeric(5, 2)) as varchar(10)) + '%'; + end + else + begin + set @disposable_ratio = '0%'; + end + + update #product_sales + set product_ratio = @disposable_ratio + where product_name = @year_month + ' ' + '일회용매출'; + + insert into #product_sales + select + pr.pr_name as product_name, + replace(convert(varchar(50), cast(sum(ps.ps_amt + ps.ps_vat) as money), 1), '.00', '') as product_sales, + cast(cast(sum(ps.ps_amt + ps.ps_vat) * 100.0 / nullif(@disposableamount, 0) as numeric(5, 2)) as varchar(10)) + '%' as product_ratio, + sum(ps.ps_qty) as product_qty + from ps + join pr on ps.ps_prcode = pr.pr_code + join kind on pr.kind_code = kind.kind_code + where ps.ps_date >= @start_date and ps.ps_date < @end_date + and kind.kind_code in (1099, 1105, 1106, 1107, 1108) + group by pr.pr_name + having sum(ps.ps_amt + ps.ps_vat) > 0; + + declare @total_qty int; + select @total_qty = sum(ps.ps_qty) + from ps + join pr on ps.ps_prcode = pr.pr_code + join kind on pr.kind_code = kind.kind_code + where ps.ps_date >= @start_date and ps.ps_date < @end_date + and kind.kind_code in (1099, 1105, 1106, 1107, 1108); + + update #product_sales + set product_qty = @total_qty + where product_name = @year_month + ' ' + '일회용매출'; + + -- 최종 결과 출력: 매출 → 일회용매출 → 특정 상품들 → 나머지 + select + product_name as 상품명, + product_sales as 매출, + product_ratio as 비율, + product_qty as 개수 + from #product_sales + order by + case product_name + when @year_month + ' ' + '매출' then 1 + when @year_month + ' ' + '일회용매출' then 2 + when '와카' then 3 + when '쥬피터' then 4 + when '에이스' then 5 + when '크리에이터' then 6 + else 7 + end, + product_name; + + drop table #product_sales; +end; + +-- 실행 예제 +EXEC disposable_analysis @year_month = '2025-01'; + + + + +create procedure disposable_analysis_new + @year_month nvarchar(7) +as +begin + declare @start_date datetime; + declare @end_date datetime; + declare @color1 varchar(50); + declare @color2 varchar(50); + declare @color3 varchar(50); + + set @start_date = convert(datetime, @year_month + '-01'); + set @end_date = dateadd(month, 1, @start_date); + set @color1= 'LightYellow'; + set @color2= 'LightPink'; + set @color3= 'PeachPuff'; + + create table #product_sales ( + product_name varchar(100), + product_sales varchar(50), + product_ratio varchar(10), + product_qty int, + row_color varchar(20) + ); + + declare @totalamount numeric(18, 0); + declare @disposableamount numeric(18, 0); + + select + @totalamount = sum(ps_amt + ps_vat) + from ps + join pr on ps.ps_prcode = pr.pr_code + join kind on pr.kind_code = kind.kind_code + where ps.ps_date >= @start_date and ps.ps_date < @end_date; + + select + @disposableamount = sum(ps_amt + ps_vat) + from ps + join pr on ps.ps_prcode = pr.pr_code + join kind on pr.kind_code = kind.kind_code + join disposable_analysis_info on disposable_analysis_info.gubun in ('wevape', 'etc') and kind.kind_code= disposable_analysis_info.kind_code + where ps.ps_date >= @start_date and ps.ps_date < @end_date; + + declare @totalamount_str varchar(50); + declare @disposableamount_str varchar(50); + + set @totalamount_str = replace(convert(varchar(50), cast(@totalamount as money), 1), '.00', ''); + set @disposableamount_str = replace(convert(varchar(50), cast(@disposableamount as money), 1), '.00', ''); + + insert into #product_sales values (@year_month + ' 매출', @totalamount_str, null, null, @color1); + insert into #product_sales values (@year_month + ' 일회용매출', @disposableamount_str, null, null, @color1); + insert into #product_sales values ('----- 일회용매출 -----', null, null, null, null); + + declare @disposable_ratio varchar(10); + if @totalamount > 0 + set @disposable_ratio = cast(cast(@disposableamount * 100.0 / @totalamount as numeric(5, 2)) as varchar(10)) + '%'; + else + set @disposable_ratio = '0%'; + + update #product_sales + set product_ratio = @disposable_ratio + where product_name = @year_month + ' 일회용매출'; + + -- kind별 통합 매출 (매출 없어도 항상 표시되도록 수정) + insert into #product_sales + select + k.kind_name + ' 총 매출', + replace(convert(varchar(50), cast(isnull(sum(ps.ps_amt + ps.ps_vat), 0) as money), 1), '.00', ''), + case when @disposableamount > 0 then + cast(cast(isnull(sum(ps.ps_amt + ps.ps_vat), 0) * 100.0 / nullif(@disposableamount, 0) as numeric(5, 2)) as varchar(10)) + '%' + else '0%' end, + isnull(sum(ps.ps_qty), 0), + @color2 + from ( + select kind_code, kind_name + from kind + where kind_code in (select kind_code from disposable_analysis_info where gubun in ('wevape')) + ) k + left join pr on k.kind_code = pr.kind_code + left join ps on ps.ps_prcode = pr.pr_code and ps.ps_date >= @start_date and ps.ps_date < @end_date + group by k.kind_name; + + -- '그 외 매출 요약' 추가 + declare @sum_known_kind numeric(18, 0); + declare @etc_qty int; + + select @etc_qty= sum(ps.ps_qty) from ps join pr on ps.ps_prcode= pr.pr_code join kind on kind.kind_code= 1099 and kind.kind_code= pr.kind_code where ps.ps_date >= @start_date and ps.ps_date < @end_date + + select @sum_known_kind = sum(amount) + from ( + select sum(ps.ps_amt + ps.ps_vat) as amount + from ps + join pr on ps.ps_prcode = pr.pr_code + join kind k on pr.kind_code = k.kind_code + where ps.ps_date >= @start_date and ps.ps_date < @end_date + and k.kind_code in (select kind_code from disposable_analysis_info where gubun in ('wevape')) + group by k.kind_code + ) as subquery; + + declare @other_amount numeric(18, 0); + set @other_amount = @disposableamount - isnull(@sum_known_kind, 0); + + insert into #product_sales + values ( + '그 외 매출', + replace(convert(varchar(50), cast(isnull(@other_amount, 0) as money), 1), '.00', ''), + case when @disposableamount > 0 then cast(cast(isnull(@other_amount, 0) * 100.0 / nullif(@disposableamount, 0) as numeric(5, 2)) as varchar(10)) + '%' else '0%' end, + @etc_qty, + @color3 + ); + + -- 상세 매출내용 시작 + insert into #product_sales + values ('----- 상세내역 -----', null, null, null, null); + + -- 상품별 상세 매출 삽입 + insert into #product_sales + select + pr.pr_name, + replace(convert(varchar(50), cast(sum(ps.ps_amt + ps.ps_vat) as money), 1), '.00', ''), + cast(cast(sum(ps.ps_amt + ps.ps_vat) * 100.0 / nullif(@disposableamount, 0) as numeric(5, 2)) as varchar(10)) + '%', + sum(ps.ps_qty), + null + from ps + join pr on ps.ps_prcode = pr.pr_code + join kind on pr.kind_code = kind.kind_code + where ps.ps_date >= @start_date and ps.ps_date < @end_date + and kind.kind_code in (select kind_code from disposable_analysis_info where gubun in ('wevape', 'etc')) + group by pr.pr_name + having sum(ps.ps_amt + ps.ps_vat) > 0; + + -- 총 수량 계산해서 일회용매출에 반영 + declare @total_qty int; + select @total_qty = sum(ps.ps_qty) + from ps + join pr on ps.ps_prcode = pr.pr_code + join kind on pr.kind_code = kind.kind_code + where ps.ps_date >= @start_date and ps.ps_date < @end_date + and kind.kind_code in (select kind_code from disposable_analysis_info where gubun in ('wevape', 'etc')); + + update #product_sales + set product_qty = @total_qty + where product_name = @year_month + ' 일회용매출'; + + -- 최종 결과 + select + product_name as 상품명, + product_sales as 매출, + product_ratio as 비율, + product_qty as 개수, + row_color + from #product_sales + order by + case + when product_name = @year_month + ' 매출' then 1 + when product_name = @year_month + ' 일회용매출' then 2 + when product_name = '----- 일회용매출 -----' then 3 + when (product_name like '% 총 매출') then 4 + when product_name = '그 외 매출' then 5 + when product_name = '----- 상세내역 -----' then 6 + else 7 + end, + product_name; + + drop table #product_sales; +end; + + + + + + + +create procedure disposable_analysis + @year_month nvarchar(7) -- "YYYY-MM" 형식 +as +begin + -- 변수 선언 + declare @standard_month nvarchar(7); + set @standard_month = '2025-05'; + + if @year_month < @standard_month + begin + -- 기준월 이전이면 old 프로시저 호출 + exec disposable_analysis_old @year_month; + end + else + begin + -- 기준월 이후거나 같으면 new 프로시저 호출 + exec disposable_analysis_new @year_month; + end +end; + + + + + +EXEC disposable_analysis_old @year_month = '2025-05'; +EXEC disposable_analysis_new @year_month = '2025-05'; +EXEC disposable_analysis @year_month = '2025-05'; +drop procedure disposable_analysis_new; \ No newline at end of file diff --git a/newton-cn/App.config b/newton-cn/App.config index 92c094c..e8e81a2 100644 --- a/newton-cn/App.config +++ b/newton-cn/App.config @@ -2,5 +2,5 @@ - + diff --git a/newton-cn/Properties/Resources.Designer.cs b/newton-cn/Properties/Resources.Designer.cs index c17df5e..e2147a8 100644 --- a/newton-cn/Properties/Resources.Designer.cs +++ b/newton-cn/Properties/Resources.Designer.cs @@ -19,7 +19,7 @@ namespace newton_cn.Properties { // 클래스에서 자동으로 생성되었습니다. // 멤버를 추가하거나 제거하려면 .ResX 파일을 편집한 다음 /str 옵션을 사용하여 ResGen을 // 다시 실행하거나 VS 프로젝트를 다시 빌드하십시오. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { diff --git a/newton-cn/Properties/Settings.Designer.cs b/newton-cn/Properties/Settings.Designer.cs index 17dbd47..21eeacd 100644 --- a/newton-cn/Properties/Settings.Designer.cs +++ b/newton-cn/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace newton_cn.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.14.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/newton-cn/newton-cn.csproj b/newton-cn/newton-cn.csproj index fae4e76..321c85a 100644 --- a/newton-cn/newton-cn.csproj +++ b/newton-cn/newton-cn.csproj @@ -8,7 +8,7 @@ WinExe newton_cn newton-cn - v4.8 + v4.6.1 512 true true diff --git a/newton-cn/obj/Debug/DesignTimeResolveAssemblyReferences.cache b/newton-cn/obj/Debug/DesignTimeResolveAssemblyReferences.cache index 8b0abf3..f5e894a 100644 Binary files a/newton-cn/obj/Debug/DesignTimeResolveAssemblyReferences.cache and b/newton-cn/obj/Debug/DesignTimeResolveAssemblyReferences.cache differ diff --git a/newton-cn/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/newton-cn/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache index bd3b60f..ca7f2ec 100644 Binary files a/newton-cn/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache and b/newton-cn/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/newton-cn/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll b/newton-cn/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll index 65ad0ff..1b61052 100644 Binary files a/newton-cn/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll and b/newton-cn/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll differ diff --git a/newton-cn/obj/Debug/newton-cn.csproj.AssemblyReference.cache b/newton-cn/obj/Debug/newton-cn.csproj.AssemblyReference.cache index efeb79b..f5e894a 100644 Binary files a/newton-cn/obj/Debug/newton-cn.csproj.AssemblyReference.cache and b/newton-cn/obj/Debug/newton-cn.csproj.AssemblyReference.cache differ