EricKIm před 1 rokem
revize
d7d7ca6d44
100 změnil soubory, kde provedl 4974 přidání a 0 odebrání
  1. 16 0
      function-in-db/functions/_first_date.sql
  2. 18 0
      function-in-db/functions/_is_first_date.sql
  3. 16 0
      function-in-db/functions/_prev_date.sql
  4. 16 0
      function-in-db/functions/_prev_month.sql
  5. 12 0
      function-in-db/functions/curr-yyyymmdd-func.sql
  6. 12 0
      function-in-db/functions/date-day-func.sql
  7. 12 0
      function-in-db/functions/date-month-func.sql
  8. 11 0
      function-in-db/functions/date-week-func-old1.sql
  9. 16 0
      function-in-db/functions/date-week-func.sql
  10. 5 0
      function-in-db/functions/delete-table-drop-func.sql
  11. 12 0
      function-in-db/functions/one-to-check-func.sql
  12. 15 0
      function-in-db/functions/rdecimal.sql
  13. 103 0
      function-in-db/procedures/accounting/lt1-accounting-cash-sum-bal.sql
  14. 124 0
      function-in-db/procedures/accounting/pl1_accounting_cash_ledger_detail.sql
  15. 36 0
      function-in-db/procedures/clo_branch_closing.sql
  16. 112 0
      function-in-db/procedures/clo_pos_closing.sql
  17. 30 0
      function-in-db/procedures/common/file_cal_format.sql
  18. 44 0
      function-in-db/procedures/common/fnc_curr_item_bal.sql
  19. 61 0
      function-in-db/procedures/common/fnc_curr_reward_bal.sql
  20. 303 0
      function-in-db/procedures/conv_eyetest_sorder.sql
  21. 109 0
      function-in-db/procedures/point/credit_bd_act.sql
  22. 55 0
      function-in-db/procedures/point/credit_bd_sync.sql
  23. 121 0
      function-in-db/procedures/point/lt1-credit-bd-sum-bal.sql
  24. 135 0
      function-in-db/procedures/point/lt1-credit-bd-sum-bal.sql--
  25. 121 0
      function-in-db/procedures/point/lt1-reward-bd-sum-bal.sql
  26. 119 0
      function-in-db/procedures/point/pl1_credit_bd_ledger_detail.sql
  27. 122 0
      function-in-db/procedures/point/pl1_reward_bd_ledger_detail.sql
  28. 126 0
      function-in-db/procedures/point/reward_bd_act.sql
  29. 71 0
      function-in-db/procedures/point/reward_bd_sync.sql
  30. 142 0
      function-in-db/procedures/purch/lt1-purch-sum-bal.sql
  31. 123 0
      function-in-db/procedures/purch/pl1_purch_ledger_detail.sql
  32. 142 0
      function-in-db/procedures/sales/lt1-sales-sum-bal.sql
  33. 123 0
      function-in-db/procedures/sales/pl1_sales_ledger_detail.sql
  34. 136 0
      function-in-db/procedures/stock-io/lt1-stock-io-sum-bal.sql
  35. 122 0
      function-in-db/procedures/stock-io/pl1_stock_io_ledger_detail.sql
  36. 94 0
      function-in-db/procedures/stock-io/stock_io_act.sql
  37. 75 0
      function-in-db/procedures/stock-io/stock_io_sync.sql
  38. 16 0
      function-in-db/triggers/company_after_insert.sql-사용않음-재활용용
  39. 7 0
      function-in-db/triggers/credit_after_insert.sql
  40. 6 0
      function-in-db/triggers/credit_bd_insert.sql_확인해서다시구현요
  41. 7 0
      function-in-db/triggers/credit_before_delete.sql
  42. 7 0
      function-in-db/triggers/genio_bd_after_insert.sql
  43. 7 0
      function-in-db/triggers/genio_bd_after_update.sql
  44. 7 0
      function-in-db/triggers/genio_before_delete.sql
  45. 10 0
      function-in-db/triggers/item_after_insert.sql
  46. 9 0
      function-in-db/triggers/item_before_delete.sql
  47. 19 0
      function-in-db/triggers/item_review_after_insert.sql
  48. 15 0
      function-in-db/triggers/item_review_bd_after_insert.sql
  49. 7 0
      function-in-db/triggers/media_before_delete.sql
  50. 7 0
      function-in-db/triggers/member_before_delete.sql
  51. 7 0
      function-in-db/triggers/porder_bd_before_delete.sql
  52. 8 0
      function-in-db/triggers/porder_before_delete.sql
  53. 7 0
      function-in-db/triggers/pquote_before_delete.sql
  54. 7 0
      function-in-db/triggers/purch_bd_after_insert.sql
  55. 7 0
      function-in-db/triggers/purch_bd_after_update.sql
  56. 7 0
      function-in-db/triggers/purch_bd_before_delete.sql
  57. 7 0
      function-in-db/triggers/purch_before_delete.sql
  58. 7 0
      function-in-db/triggers/reward_after_insert.sql
  59. 7 0
      function-in-db/triggers/sales_bd_after_insert.sql
  60. 7 0
      function-in-db/triggers/sales_bd_after_update.sql
  61. 7 0
      function-in-db/triggers/sales_bd_before_delete.sql
  62. 7 0
      function-in-db/triggers/sales_before_delete.sql
  63. 11 0
      function-in-db/triggers/sorder_after_insert-already-.sql
  64. 10 0
      function-in-db/triggers/sorder_after_insert.sql
  65. 7 0
      function-in-db/triggers/sorder_bd_after_insert.sql
  66. 7 0
      function-in-db/triggers/sorder_bd_after_update.sql
  67. 8 0
      function-in-db/triggers/sorder_bd_before_delete.sql
  68. 8 0
      function-in-db/triggers/sorder_before_delete.sql
  69. 7 0
      function-in-db/triggers/users_before_delete.sql
  70. 10 0
      function-in-db/views/igroup_item_thm_view.sql
  71. 18 0
      function-in-db/views/item_big_view.sql
  72. 19 0
      function-in-db/views/item_middle_thm_view.sql
  73. 14 0
      function-in-db/views/item_thumb_view.sql
  74. 5 0
      function-in-db/views/post_seo_view.sql
  75. 4 0
      table-controls/backup.sql
  76. 166 0
      table-controls/compare.sql
  77. 14 0
      table-controls/detail-page-links.sql
  78. 5 0
      table-controls/drop-queries copy.sql
  79. 4 0
      table-controls/dynamic-sql.sql
  80. 5 0
      table-controls/ether-sign-verify.json-viet
  81. 40 0
      table-controls/function-snipet.sql
  82. 1 0
      table-controls/product.sql
  83. 44 0
      table-controls/select-json.sql
  84. 30 0
      table-controls/table-backup.sql
  85. 31 0
      table-controls/truncate-all-tables(위험).sql
  86. 66 0
      table-controls/unixtime-to-date.sql
  87. 87 0
      table-controls/weberp_db_update.sql
  88. 38 0
      table-controls/z-auto-increment-0.sql
  89. 68 0
      table-controls/z-tmp-집계표.sql
  90. 1 0
      table-controls/z-매입원장.sql
  91. 190 0
      table-controls/z-매입집계표.sql
  92. 19 0
      table-controls/z-소트-뱃지-생성.sql
  93. 33 0
      table-controls/검안정보-Json.txt
  94. 228 0
      table-controls/검안정보.Json
  95. 186 0
      table-controls/테이블-DBUpdate-gen-wallet.sql
  96. 72 0
      table-controls/테이블-replace.sql
  97. 147 0
      table-controls/테이블-truncate.sql
  98. 125 0
      table-controls/테이블-unixtime-created.sql
  99. 97 0
      table-controls/테이블-unixtime-updated.sql
  100. 30 0
      table-controls/테이블-update-default.sql

+ 16 - 0
function-in-db/functions/_first_date.sql

@@ -0,0 +1,16 @@
+DELIMITER //
+
+create function _first_date ( _date varchar(8) )
+returns VARCHAR(8)
+
+begin
+   declare ret varchar(8);
+   declare pmDate datetime;
+	   set pmDate = date_add(_date, interval -day(_date)+1 day);
+	   set ret = concat(substring(pmDate, 1,4),substring(pmDate, 6,2),substring(pmDate, 9,2));
+   RETURN ret;
+end; //
+
+DELIMITER ;
+
+select _first_date('20220101')

+ 18 - 0
function-in-db/functions/_is_first_date.sql

@@ -0,0 +1,18 @@
+drop function if exists _is_first_date;
+DELIMITER //
+create function _is_first_date ( _date varchar(8) )
+returns boolean
+
+begin
+   declare ret boolean;
+	   if substring(_date, 7,2) = '01' then
+    	   set ret = true;
+      else
+    	   set ret = false;
+      end if;
+   return ret;
+end; //
+DELIMITER ;
+
+select _is_first_date('20220101')
+

+ 16 - 0
function-in-db/functions/_prev_date.sql

@@ -0,0 +1,16 @@
+DELIMITER //
+
+create function _prev_date ( _date varchar(8) )
+returns VARCHAR(8)
+
+begin
+   declare ret varchar(8);
+   declare pmDate datetime;
+	   set pmDate = date_add( _date, interval -1 day);
+	   set ret = concat(substring(pmDate, 1,4),substring(pmDate, 6,2),substring(pmDate, 9,2));
+   RETURN ret;
+end; //
+
+DELIMITER ;
+
+select _prev_date('20220102')

+ 16 - 0
function-in-db/functions/_prev_month.sql

@@ -0,0 +1,16 @@
+DELIMITER //
+
+create function _prev_month ( _date varchar(8) )
+returns VARCHAR(6)
+
+begin
+   declare ret varchar(6);
+   declare pmDate datetime;
+	   set pmDate = last_day(date_add( _date, interval -1 month));
+	   set ret = concat(substring(pmDate, 1,4),substring(pmDate, 6,2));
+   RETURN ret;
+end; //
+
+DELIMITER ;
+
+select _prev_month('20220101')

+ 12 - 0
function-in-db/functions/curr-yyyymmdd-func.sql

@@ -0,0 +1,12 @@
+DELIMITER $$
+CREATE DEFINER=`root`@`localhost` FUNCTION `CurrYyyymmdd`() RETURNS varchar(8) CHARSET utf8mb4
+BEGIN
+
+   DECLARE ret VARCHAR(8);
+
+	set ret = DATE_FORMAT(CURDATE(), "%Y%m%d");
+
+   RETURN ret;
+
+END$$
+DELIMITER ;

+ 12 - 0
function-in-db/functions/date-day-func.sql

@@ -0,0 +1,12 @@
+DELIMITER //
+
+CREATE FUNCTION DateDay ( date VARCHAR(8) )
+RETURNS VARCHAR(10)
+
+BEGIN
+   DECLARE ret VARCHAR(10);
+	   set ret = concat(substring(date, 1,4),'.',substring(date, 5,2),'.',substring(date, 7,2));
+   RETURN ret;
+END; //
+
+DELIMITER ;

+ 12 - 0
function-in-db/functions/date-month-func.sql

@@ -0,0 +1,12 @@
+DELIMITER //
+
+CREATE FUNCTION DateMonth ( date VARCHAR(8) )
+RETURNS VARCHAR(5)
+
+BEGIN
+   DECLARE ret VARCHAR(5);
+	   set ret = concat(substring(date, 3,2),'.',substring(date, 5,2)) ;
+   RETURN ret;
+END; //
+
+DELIMITER ;

+ 11 - 0
function-in-db/functions/date-week-func-old1.sql

@@ -0,0 +1,11 @@
+DELIMITER //
+CREATE FUNCTION DateWeek ( date VARCHAR(8) )
+RETURNS VARCHAR(8)
+BEGIN
+   DECLARE month VARCHAR(5);
+   DECLARE ret VARCHAR(8);
+      set month = concat(substring(date, 3,2),'.',substring(date, 5,2)) ;
+      set ret = concat(month,'-',week(date)- week(concat(substring(date, 1,6),'01'))+1);
+   RETURN ret;
+END; //
+DELIMITER ;

+ 16 - 0
function-in-db/functions/date-week-func.sql

@@ -0,0 +1,16 @@
+DELIMITER //
+CREATE FUNCTION DateWeek ( date VARCHAR(8) )
+RETURNS VARCHAR(8)
+BEGIN
+   DECLARE month VARCHAR(5);
+   DECLARE ret VARCHAR(8);
+   declare w int;
+   
+   set w = week(date) ;
+   set month = concat(substring(date, 3,2),'.',substring(date, 5,2)) ;
+   set ret = concat(month,'-', if(length(w) = 1, concat('0',w), w) );
+   RETURN ret;
+END; //
+DELIMITER ;
+
+drop function dateweek

+ 5 - 0
function-in-db/functions/delete-table-drop-func.sql

@@ -0,0 +1,5 @@
+
+ DROP FUNCTION  IF EXISTS  DateMonth;
+ DROP FUNCTION  IF EXISTS  DateWeek;
+ 
+ delete from list_type1

+ 12 - 0
function-in-db/functions/one-to-check-func.sql

@@ -0,0 +1,12 @@
+DELIMITER //
+
+CREATE FUNCTION OneToCheck ( val CHAR(1) )
+RETURNS VARCHAR(1)
+
+BEGIN
+   DECLARE ret VARCHAR(1);
+	   set ret = IF(val = '1', '√', '');
+   RETURN ret;
+END; //
+
+DELIMITER ;

+ 15 - 0
function-in-db/functions/rdecimal.sql

@@ -0,0 +1,15 @@
+DELIMITER //
+
+drop function if exists rdecimal;
+CREATE FUNCTION rdecimal ( f float, p int )
+RETURNS decimal(20,4)
+
+BEGIN
+
+   DECLARE ret DECIMAL(20,4);
+	set ret = cast(round(f,p) as decimal(20,4));
+   RETURN ret;
+
+END; //
+
+DELIMITER ;

+ 103 - 0
function-in-db/procedures/accounting/lt1-accounting-cash-sum-bal.sql

@@ -0,0 +1,103 @@
+truncate table dbt_list_sum;
+truncate table dbt_list_type1;
+drop procedure if exists lt1_accounting_cash_sum_bal;
+-- 일단  현금계정만 추가함.
+
+DELIMITER //
+create procedure lt1_accounting_cash_sum_bal( _listToken varchar(21), _sdate varchar(8), _edate varchar(8), 
+_s1 varchar(32), _e1 varchar(32), _s2 varchar(32), _e2 varchar(32), 
+_s3 varchar(32), _e3 varchar(32), _s4 varchar(32), _e4 varchar(32), 
+_where varchar(386), _having varchar(386), _orderby varchar(64), 
+_branch int, _storage int)
+
+BEGIN
+
+Declare _sbal_date varchar(8);
+Declare _ebal_date varchar(8);
+
+Declare _sbet1 varchar(64);
+Declare _ebet1 varchar(64);
+Declare _sbet2 varchar(64);
+Declare _ebet2 varchar(64);
+
+if _is_first_date(_sdate) then
+	set _sbal_date = '19000101';
+	set _ebal_date = '19000101';
+else
+	set _sbal_date = _sdate;
+	set _ebal_date = _edate;
+end if;
+
+if _s1 != '' and _e1 != '' then
+	set _sbet1 = _s1;
+	set _ebet1 = _e1;
+else
+	set _sbet1 = '!';
+	set _ebet1 = '駾';
+end if;
+
+if _s2 != '' and _e2 != '' then
+	set _sbet2 = _s2;
+	set _ebet2 = _e2;
+else
+	set _sbet2 = '!';
+	set _ebet2 = '駾';
+end if;
+
+-- 전월 잔액 --
+insert into dbt_list_sum
+	( created_on, list_token, h_id, id, c1, c2, 
+	  d1, d2, d3, d4, 
+	  order_by )
+
+-- 이월 현금 잔액 --
+select unix_timestamp(), _listToken, mx.id, mx.id, title_code, title_name,
+	bal_amt, 0, 0, 0,
+	title_code
+from 
+	( select acc_title_id, (dr_bal_amt - cr_bal_amt) as bal_amt
+		from dbr_bal_acc_title
+		where yyyy_mm = _prev_month(_sdate) and branch_id = _branch
+	) as last_mbal 
+	inner join dbr_acc_title as mx on mx.id = last_mbal.acc_title_id
+where ( title_code = '1101'  );
+-- 일단  현금계정만 추가함.
+
+-- 입출금 합계 --
+insert into dbt_list_sum
+	( created_on, list_token, h_id, id, c1, c2, 
+	  d1, d2, d3, d4, 
+	  order_by )
+select unix_timestamp(), _listToken, 1, 1, '1101', '현금',
+	0, sum(slip_amt*cast((collect_status+1)/2 as int)), sum(slip_amt*cast(-1*(collect_status-1)/2 as int)), sum(slip_amt*collect_status),
+	'1101'
+from 
+    ( select id,  branch_id, deal_type_id, slip_amt
+        from dbr_acc_slip
+        where acc_date between _sdate and _edate
+			and deal_type_id between 21 and 25
+	) as sbhd
+	inner join dbr_deal_type as deal on deal.id = sbhd.deal_type_id
+where branch_id = _branch
+group by branch_id;
+
+-- dbt_list_type1 으로 집계 --
+insert into dbt_list_type1
+	( created_on, list_token, h_id, id, c1, c2, 
+		d1, d2, d3, d4,
+		order_by )
+select min(unix_timestamp()), min(_listToken), min(id), min(id), min(c1), min(c2),
+	sum(d1),
+	sum(d2),
+	sum(d3),
+	sum(d1) + sum(d2) - sum(d3),
+	min(order_by)
+from dbt_list_sum as mx
+where list_token = _listToken
+group by mx.id
+having min(mx.id) is not null
+order by order_by asc;
+
+END;
+//
+DELIMITER ; 

+ 124 - 0
function-in-db/procedures/accounting/pl1_accounting_cash_ledger_detail.sql

@@ -0,0 +1,124 @@
+truncate table dbt_list_type1;
+truncate table dbt_list_sum;
+drop procedure if exists pl1_sales_ledger_detail;
+
+-- 일단  현금계정만 추가함.
+DELIMITER //
+create procedure pl1_sales_ledger_detail( _listToken varchar(21), _sdate varchar(8), _edate varchar(8), 
+_s1 varchar(32), _e1 varchar(32), _s2 varchar(32), _e2 varchar(32), 
+_s3 varchar(32), _e3 varchar(32), _s4 varchar(32), _e4 varchar(32), 
+_where varchar(386), _having varchar(386), _orderby varchar(64), 
+_branch int, _storage int, _target int)
+
+BEGIN
+
+Declare _sbal_date varchar(8);
+Declare _ebal_date varchar(8);
+
+Declare _first_bal decimal(20,4);
+Declare _first_bal_caption varchar(20);
+
+Declare _first_id int;
+Declare _last_id int;
+
+Declare _line_id int;
+Declare _line_in decimal(20,4) default "0.0000";
+Declare _line_out decimal(20,4) default "0.0000";
+Declare _line_bal decimal(20,4) default "0.0000";
+Declare _in_sum decimal(20,4) default "0.0000";
+Declare _out_sum decimal(20,4) default "0.0000";
+
+Declare _company_name varchar(64);
+Declare _full_name varchar(96);
+
+Declare _not_found boolean;
+Declare _line_cur cursor for 
+    select t_id, d3, d4 from dbt_list_type1 where t_id > _first_id and t_id <= _last_id
+	order by c1, c2, c3 asc;
+Declare continue handler for 
+        not found set _not_found = true;
+
+if _is_first_date(_sdate) then
+	set _sbal_date = '19000101';
+	set _ebal_date = '19000101';
+else
+	set _sbal_date = _sdate;
+	set _ebal_date = _edate;
+end if;
+
+-- 전월잔액 
+select ifnull(last_mbal.bal_amt,0) , '이월잔액' into _first_bal, _first_bal_caption
+from
+	dbr_company as mv
+	left join
+	( select buyer_id, bal_amt
+	from dbr_bal_buyer
+	where yyyy_mm = _prev_month(_sdate) and branch_id = _branch
+	) as last_mbal on mv.id = last_mbal.buyer_id
+where mv.id = _target;
+
+insert into dbt_list_type1 ( created_on, list_token, c4, d5 )
+	values ( unix_timestamp(), _listToken, _first_bal_caption, _first_bal);
+
+-- insert for sales
+insert into dbt_list_type1
+	( created_on, list_token, c1, c2, c3, c4, c5, d1, d2, d3)
+select unix_timestamp(), _listToken, concat( sales_date,'-', deal_code, '*', sbbd.seq_no ), 
+	concat( sales_no, '*', sbbd.seq_no ), deal_code, 
+    concat( item_code, ' / ', item_name, ' / ', sub_name ), '', -- bill_type 은 비운다.
+ 	sales_qty, sorder_prc, sales_sum*sales_status
+from ( select id, sales_no, sales_date
+	from dbr_sales
+    where sales_date between _sdate and _edate 
+	) as sbhd
+	inner join dbr_sales_bd as sbbd on sbhd.id = sbbd.sales_id
+	inner join dbr_sorder_bd as mnbd on mnbd.id = sbbd.sorder_bd_id
+	inner join dbr_sorder as mnhd on mnhd.id = mnbd.sorder_id
+	inner join dbr_item as itm on mnbd.item_id = itm.id
+	inner join dbr_deal_type as deal on deal.id = mnhd.deal_type_id
+where branch_id = _branch and mnhd.buyer_id = _target;
+
+-- 출금내역
+insert into dbt_list_type1
+	( created_on, list_token, c1, c2, c3, c4, c5, d4)
+select unix_timestamp(), _listToken, concat( acc_date,'-', deal_code ), 
+	acc_slip_no, deal_code, 
+	bill_column1, bill_type, -1*slip_amt*sales_status
+from 
+    ( select id, acc_date, acc_slip_no, deal_type_id,
+        bill_column1, bill_type, slip_amt
+        from dbr_acc_slip
+        where ( deal_type_id = 21 or deal_type_id = 23 ) -- 입금과 입금할인만
+            and acc_date between _sdate and _edate 	
+	        and branch_id = _branch and company_id = _target
+    ) as mnhd  
+inner join dbr_deal_type as deal on deal.id = deal_type_id;
+
+-- -- get id range for current ledger
+select min(t_id), max(t_id) into  _first_id, _last_id from dbt_list_type1 where list_token = _listToken;
+
+-- compute line_bal
+set _line_bal = _first_bal;
+open _line_cur;
+	loop1: loop
+		fetch _line_cur into _line_id, _line_in, _line_out;
+		if _not_found then leave loop1; end if;
+
+		set _in_sum = _in_sum + ifnull(_line_in,0);
+		set _out_sum = _out_sum + ifnull(_line_out,0);
+		set _line_bal = ifnull(_line_bal,0) + ifnull(_line_in,0) - ifnull(_line_out,0);
+		update dbt_list_type1 set d5 = _line_bal where t_id = _line_id;
+	end loop loop1;
+close _line_cur;
+
+-- write list_sum
+select company_name, concat(full_name, ' ', company_no) 
+	into _company_name, _full_name from dbr_company where id = _target;
+insert into dbt_list_sum
+	( created_on, list_token, c1, c2, c3, c4, d1, d2, d3, d4)
+	values (unix_timestamp(), _listToken, _company_name, _full_name, _sdate, _edate, 
+	_first_bal, _in_sum, _out_sum, _line_bal);
+
+END;
+//
+DELIMITER ;

+ 36 - 0
function-in-db/procedures/clo_branch_closing.sql

@@ -0,0 +1,36 @@
+-- truncate table dbr_pos_closing;
+
+drop procedure if exists clo_branch_closing;
+
+DELIMITER //
+create procedure clo_branch_closing( _curr_date varchar(8), _branch int, _user int)
+
+BEGIN
+
+Declare _sales_day decimal(20,4) default "0.0000";
+Declare _ccard_day decimal(20,4) default "0.0000";
+Declare _cash_day decimal(20,4) default "0.0000";
+Declare _coupon_day decimal(20,4) default "0.0000";
+Declare _reward_day decimal(20,4) default "0.0000";
+Declare _discount_day decimal(20,4) default "0.0000";
+Declare _sorder_cnt int;
+Declare _sorder_new int;
+Declare _revisit_cnt int;
+
+Declare _log_token varchar(21);
+Declare _seq_no int;
+
+set _seq_no = 0;
+set _log_token = SUBSTR(MD5(RAND()), 1, 21);
+
+call clo_pos_closing(_curr_date, _branch, _user);
+
+-- _seq_no = _seq_no + 1;s
+insert into log_procedure_run
+	( log_token, token_seq_no, calling_procedure, procedure_name)
+values ( _log_token, _seq_no, 'clo_branch_closing',  'clo_pos_closing');
+
+END; //
+DELIMITER ;
+
+call clo_branch_closing('20220815', 1, 5);

+ 112 - 0
function-in-db/procedures/clo_pos_closing.sql

@@ -0,0 +1,112 @@
+-- truncate table dbr_pos_closing;
+
+drop procedure if exists clo_pos_closing;
+
+DELIMITER //
+create procedure clo_pos_closing( _curr_date varchar(8), _branch int, _user int)
+
+BEGIN
+
+Declare _sales_day decimal(20,4) default "0.0000";
+Declare _ccard_day decimal(20,4) default "0.0000";
+Declare _cash_day decimal(20,4) default "0.0000";
+Declare _coupon_day decimal(20,4) default "0.0000";
+Declare _reward_day decimal(20,4) default "0.0000";
+Declare _discount_day decimal(20,4) default "0.0000";
+Declare _sorder_cnt int;
+Declare _sorder_new int;
+Declare _revisit_cnt int;
+
+Declare _sales_month decimal(20,4) default "0.0000";
+Declare _ccard_month decimal(20,4) default "0.0000";
+Declare _cash_month decimal(20,4) default "0.0000";
+Declare _coupon_month decimal(20,4) default "0.0000";
+Declare _reward_month decimal(20,4) default "0.0000";
+Declare _discount_month decimal(20,4) default "0.0000";
+
+Declare _not_found boolean;
+Declare _sales_day_cur cursor for 
+	select 
+	  sum(sorder_sum), sum(ccard_amt), sum(cash_amt), sum(coupon_amt), sum(reward_amt),
+	  sum(discount_amt)
+	from
+		dbr_sorder as mx
+		inner join 
+			( select
+		    dbr_sorder.id, dbr_company.company_name, birth_date, count(sorder_no) as visit_cnt
+	    from
+		    dbr_company
+		    inner join dbr_sorder on dbr_company.id = dbr_sorder.buyer_id
+	    group by company_name) as com
+		on com.id = mx.id
+	  
+	  inner join dbr_sorder_bd on mx.id = dbr_sorder_bd.sorder_id
+	where sorder_date between _curr_date and _curr_date
+				and mx.branch_id = _branch;
+
+Declare _sales_month_cur cursor for
+	select 
+	  sum(sorder_sum), sum(ccard_amt), sum(cash_amt), sum(coupon_amt), sum(reward_amt),
+	  sum(discount_amt)
+	from
+		dbr_sorder as mx
+		inner join 
+			( select
+		    dbr_sorder.id, dbr_company.company_name, birth_date, count(sorder_no) as visit_cnt
+	    from
+		    dbr_company
+		    inner join dbr_sorder on dbr_company.id = dbr_sorder.buyer_id
+	    group by company_name) as com
+		on com.id = mx.id
+	  
+	  inner join dbr_sorder_bd on mx.id = dbr_sorder_bd.sorder_id
+	where sorder_date between _first_date(_curr_date) and _curr_date
+				and mx.branch_id = _branch;
+				
+Declare _visit_day_cur cursor for
+	select
+	  sum(if(is_first_order = '1', 1, 0)), sum(if(is_first_order <> '1', 1, 0))
+	from dbr_sorder as mx
+	where sorder_date between _curr_date and _curr_date
+				and mx.branch_id = _branch;
+
+Declare continue handler for 
+        not found set _not_found = true;
+
+open _sales_day_cur; 
+	loop_sales_day: loop
+		fetch _sales_day_cur into _sales_day, _ccard_day, _cash_day, _coupon_day, _reward_day,
+			_discount_day;
+		if _not_found then leave loop_sales_day; end if;
+	end loop loop_sales_day;
+close _sales_day_cur;
+
+open _sales_month_cur; 
+	loop_month_day: loop
+		fetch _sales_month_cur into _sales_month, _ccard_month, _cash_month, _coupon_month, _reward_month,
+			_discount_month;
+		if _not_found then leave loop_month_day; end if;
+	end loop loop_month_day;
+close _sales_month_cur;
+
+open _visit_day_cur; 
+	loop_visit_day: loop
+		fetch _visit_day_cur into _sorder_new, _revisit_cnt;
+		if _not_found then leave loop_visit_day; end if;
+	end loop loop_visit_day;
+close _visit_day_cur;
+
+delete from dbr_pos_closing
+	where branch_id = branch_id and closing_date = _curr_date and  user_id = _user;       		
+insert into dbr_pos_closing
+	( branch_id, closing_date, user_id, sales_day, ccard_day, 
+	cash_day, reward_day, discount_day, sorder_new, revisit_cnt,
+	sales_month, ccard_month, cash_month, reward_month, discount_month
+	)
+	values ( _branch, _curr_date, _user, _sales_day, _ccard_day, 
+	_cash_day, _reward_day, _discount_day, _sorder_new, _revisit_cnt,
+	_sales_month, _ccard_month, _cash_month, _reward_month, _discount_month
+	 );
+
+END; //
+DELIMITER ;

+ 30 - 0
function-in-db/procedures/common/file_cal_format.sql

@@ -0,0 +1,30 @@
+
+DROP PROCEDURE IF EXISTS fill_cal_format;
+DELIMITER |
+CREATE PROCEDURE fill_cal_format(dateStart DATE, dateEnd DATE)
+BEGIN
+  declare i date ;
+  declare w int;
+
+  set i = dateStart ;
+  WHILE i <= dateEnd DO
+
+    set w = week(i);
+  	IF weekday(i) = 0 THEN
+    	INSERT INTO dbr_cal_format(date_type, date_index)
+    	VALUES ('week', concat( DATE_FORMAT(dateStart, '%y.%m'), '-', if(length(w) = 1, concat('0',w), w) ));
+    END IF;
+
+    IF DATE_FORMAT(i, '%d') = '01' THEN
+    	INSERT INTO dbr_cal_format(date_type, date_index)
+    	VALUES ('month', DATE_FORMAT(i, '%y.%m'));
+    END IF;
+
+    INSERT INTO dbr_cal_format(date_type, date_index)
+    VALUES ('day', DATE_FORMAT(i, '%Y%m%d'));
+    SET i = date_add(i, INTERVAL 1 DAY);
+  END WHILE;
+END;
+|
+DELIMITER ;
+CALL fill_cal_format('2021-01-01','2021-12-31');

+ 44 - 0
function-in-db/procedures/common/fnc_curr_item_bal.sql

@@ -0,0 +1,44 @@
+drop procedure if exists fnc_curr_item_bal;
+DELIMITER //
+create procedure fnc_curr_item_bal( _curr_date varchar(8), _storage int, _target int)
+
+BEGIN
+
+Declare _last_amt decimal(20,4) default "0.0000";
+Declare _last_bad decimal(20,4) default "0.0000";
+Declare _sum_amt decimal(20,4) default "0.0000";
+Declare _sum_bad decimal(20,4) default "0.0000";
+
+Declare _bal_date varchar(8);
+
+if _is_first_date(_curr_date) then
+	set _bal_date = '19000101';
+else
+	set _bal_date = _curr_date;
+end if;
+
+
+select bal_qty, bad_bal_qty
+into _last_amt, _last_bad
+from dbr_bal_item
+where item_id = _target
+    and yyyy_mm = _prev_month(_curr_date) and storage_id = _storage;
+
+
+-- 당월 변동잔액
+select sum(io_qty*stock_status), sum(io_qty*badstk_status)
+into _sum_amt, _sum_bad
+from dbr_stock_io
+    inner join dbr_deal_type as deal on deal.id = deal_type_id
+where item_id = _target
+    and io_date between _first_date(_bal_date) and _bal_date
+    and storage_id = _storage
+group by item_id;
+
+select _last_amt + _sum_amt as c1, _last_bad + _sum_bad as c2;
+
+END;
+//
+DELIMITER ;
+
+call fnc_curr_item_bal('20230228', 1, 1) ;

+ 61 - 0
function-in-db/procedures/common/fnc_curr_reward_bal.sql

@@ -0,0 +1,61 @@
+drop procedure if exists fnc_curr_reward_bal;
+DELIMITER //
+create procedure fnc_curr_reward_bal( _curr_date varchar(8), _branch int, _target int)
+
+BEGIN
+
+Declare _bal_date varchar(8);
+
+Declare _last_amt decimal(20,4);
+Declare _sum_amt decimal(20,4);
+
+Declare _avail_bal decimal(20,4);
+Declare _tmp_int int;
+
+-- setup 변수들 --
+Declare _setup text;
+Declare _reserve int;
+Declare _min_use int;
+
+if _is_first_date(_curr_date) then
+	set _bal_date = '19000101';
+else
+	set _bal_date = _curr_date;
+end if;
+
+-- 아래것 작동됨 ---- https://dololak.tistory.com/257 
+-- Json Data 가져오기
+SELECT json_extract(setup_json, '$.ReservePoint'), json_extract(setup_json, '$.MinUsePoint') 
+	into _reserve, _min_use
+	from dbr_setup
+	where setup_code = 'user-reward';
+
+-- 전월 잔액
+select bal_amt into _last_amt
+from dbr_bal_reward
+where buyer_id = 10
+    and yyyy_mm = _prev_month(_curr_date) and branch_id = _branch;
+
+-- 당월 변동잔액
+select sum(reward_amt*reward_status) into _sum_amt
+from dbr_reward_bd
+    inner join dbr_deal_type as deal on deal.id = deal_type_id
+where buyer_id = _target
+    and avail_date between _first_date(_bal_date) and _bal_date
+    and branch_id = _branch
+group by buyer_id;
+
+
+-- 보관적립금, 최소사용적립금 계산식 --
+set _avail_bal = cast( ( (_last_amt - _reserve) / _min_use) as int) * _min_use;
+if _avail_bal < 0 then
+	set _avail_bal = '0.0000';
+end if;
+
+select _last_amt as c1, _avail_bal as c2;
+
+END;
+//
+DELIMITER ;
+
+call fnc_curr_reward_bal('20230227', 1, 10) ;

+ 303 - 0
function-in-db/procedures/conv_eyetest_sorder.sql

@@ -0,0 +1,303 @@
+
+drop procedure if exists conv_eyetest_sorder;
+
+DELIMITER //
+create procedure conv_eyetest_sorder()
+
+BEGIN
+
+-- Declare _json1 text;
+
+Declare _line_id int;
+Declare _not_found boolean;
+
+Declare _c1 varchar(64); Declare _c2 varchar(64); Declare _c3 varchar(64); Declare _c4 varchar(64); Declare _c5 varchar(64);
+Declare _c6 varchar(64); Declare _c7 varchar(64); Declare _c8 varchar(64); Declare _c9 varchar(64); Declare _c10 varchar(64);
+Declare _c11 varchar(64); Declare _c12 varchar(64); Declare _c13 varchar(64); Declare _c14 varchar(64); Declare _c15 varchar(64);
+Declare _c16 varchar(64); Declare _c17 varchar(64); Declare _c18 varchar(64); Declare _c19 varchar(64); Declare _c20 varchar(64);
+Declare _c21 varchar(64); Declare _c22 varchar(64); Declare _c23 varchar(64); Declare _c24 varchar(64); Declare _c25 varchar(64);
+
+Declare _line_cur_eyetest cursor for 
+    select 
+		c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, c20, c21, c22, c23, c24, c25
+	from zdb_eyetest
+	-- where c1 = '2'
+	order by c1 asc;
+
+Declare continue handler for 
+        not found set _not_found = true;
+
+set _not_found = false;  -- 이것이 Multi cursor를 쓰는 핵심이다.
+open _line_cur_eyetest;
+	loop_eyetest: loop
+		fetch _line_cur_eyetest into 
+			_c1, _c2, _c3, _c4, _c5, _c6, _c7, _c8, _c9, _c10, _c11, _c12, _c13, _c14, _c15, _c16, _c17, _c18, _c19, _c20,
+			_c21, _c22, _c23, _c24, _c25 ;
+		if _not_found then leave loop_eyetest; end if;
+
+		SET @json1 = '{
+			"REyeLens": {
+				"Sph": "",
+				"Cyl": "",
+				"Axis": "",
+				"LongPd": "",
+				"Add": "",
+				"ShortPd": "",
+				"BaseIo": "",
+				"BaseUd": "",
+				"BareEye": "",
+				"Adjust": ""
+			},
+			"LEyeLens": {
+				"Sph": "",
+				"Cyl": "",
+				"Axis": "",
+				"LongPd": "",
+				"Add": "",
+				"ShortPd": "",
+				"BaseIo": "",
+				"BaseUd": "",
+				"BareEye": "",
+				"Adjust": ""
+			},
+			"RContLens": {
+				"Sph": "",
+				"Cyl": "",
+				"Axis": "",
+				"Add": "",
+				"Bc": "",
+				"Dia": "",
+				"Kerato": "",
+				"Prescript": "",
+				"Adjust": ""
+			},
+			"LContLens": {
+				"Sph": "",
+				"Cyl": "",
+				"Axis": "",
+				"Add": "",
+				"Bc": "",
+				"Dia": "",
+				"Kerato": "",
+				"Prescript": "",
+				"Adjust": ""
+			},
+			"Symptoms": "",
+			"OldREyeLens": {
+				"Sph": "",
+				"Cyl": "",
+				"Axis": "",
+				"LongPd": "",
+				"Add": "",
+				"ShortPd": "",
+				"BaseIo": "/",
+				"BaseUd": "/",
+				"BareEye": "",
+				"Adjust": ""
+			},
+			"OldLEyeLens": {
+				"Sph": "",
+				"Cyl": "",
+				"Axis": "",
+				"LongPd": "",
+				"Add": "",
+				"ShortPd": "",
+				"BaseIo": "/",
+				"BaseUd": "/",
+				"BareEye": "",
+				"Adjust": ""
+			},
+			"CcREyeLens": {
+				"Sph": "",
+				"Cyl": "",
+				"Axis": "",
+				"LongPd": "",
+				"Add": "",
+				"ShortPd": "",
+				"BaseIo": "/",
+				"BaseUd": "/",
+				"BareEye": "",
+				"Adjust": ""
+			},
+			"CcLEyeLens": {
+				"Sph": "",
+				"Cyl": "",
+				"Axis": "",
+				"LongPd": "",
+				"Add": "",
+				"ShortPd": "",
+				"BaseIo": "/",
+				"BaseUd": "/",
+				"BareEye": "",
+				"Adjust": ""
+			},
+			"FixEye": 0,
+			"Stereosia": 0,
+			"ColorVision": 0,
+			"OdImGrid": 0,
+			"OsImGrid": 0,
+			"Screen": {
+				"Shielding": {
+				"Long": "",
+				"Short": ""
+				},
+				"FourDot": {
+				"Long": 0,
+				"Short": 0,
+				"LongStr": "",
+				"ShortStr": ""
+				},
+				"Converge": {
+				"Normal": 0,
+				"Str": ""
+				},
+				"Near": {
+				"OdStr": "",
+				"OsStr": ""
+				},
+				"Easy": {
+				"OuStr": "",
+				"OdStr": "",
+				"OsStr": ""
+				}
+			},
+			"BroadH": {
+				"X": "[]",
+				"Y": "[]",
+				"Drage": "[]"
+			},
+			"Bincular": {
+				"Location": {
+				"LongHori": "",
+				"LongVert": "",
+				"ShortHori": "",
+				"ShortVert": ""
+				},
+				"Relative": {
+				"Pra": "",
+				"Nra": ""
+				},
+				"Lag": 0,
+				"Aca": "",
+				"Fusion": {
+				"LongBo": {
+					"Clo": "",
+					"Dis": "",
+					"Rec": ""
+				},
+				"LongBi": {
+					"Clo": "",
+					"Dis": "",
+					"Rec": ""
+				},
+				"LongOdBd": {
+					"Dis": "",
+					"Rec": ""
+				},
+				"LongOdBu": {
+					"Dis": "",
+					"Rec": ""
+				},
+				"LongOsBd": {
+					"Dis": "",
+					"Rec": ""
+				},
+				"LongOsBu": {
+					"Dis": "",
+					"Rec": ""
+				},
+				"ShortBo": {
+					"Clo": "",
+					"Dis": "",
+					"Rec": ""
+				},
+				"ShortBi": {
+					"Clo": "",
+					"Dis": "",
+					"Rec": ""
+				},
+				"ShortOdBd": {
+					"Dis": "",
+					"Rec": ""
+				},
+				"ShortOdBu": {
+					"Dis": "",
+					"Rec": ""
+				},
+				"ShortOsBd": {
+					"Dis": "",
+					"Rec": ""
+				},
+				"ShortOsBu": {
+					"Dis": "",
+					"Rec": ""
+				}
+				}
+			},
+			"Pameter": {
+				"Oh": {
+				"R": "",
+				"L": ""
+				},
+				"Pd": {
+				"R": "",
+				"L": ""
+				},
+				"Distance": {
+				"R": "",
+				"L": ""
+				},
+				"Inset": {
+				"R": "",
+				"L": ""
+				},
+				"Face": "",
+				"Tilt": "",
+				"Length": ""
+			},
+			"Payment": {
+				"CardCompany": "",
+				"CashReceipt": "",
+				"GiftCard": ""
+			}
+		}';
+
+		update dbr_sorder set json1 =  
+			json_replace(@json1, 
+				'$.REyeLens.Sph', _c2, 
+				'$.REyeLens.Cyl', _c3,  
+				'$.REyeLens.Axis', _c4,  
+				'$.REyeLens.LongPd', _c5,  
+				'$.REyeLens.Add', _c6,  
+				'$.REyeLens.ShortPd', _c7,  
+
+				'$.LEyeLens.Sph', _c8,  
+				'$.LEyeLens.Cyl', _c9,  
+				'$.LEyeLens.Axis', _c10,  
+				'$.LEyeLens.LongPd', _c11,  
+				'$.LEyeLens.Add', _c12,  
+				'$.LEyeLens.ShortPd', _c13,  
+
+				'$.RContLens.Sph', _c14,  
+				'$.RContLens.Cyl', _c15,  
+				'$.RContLens.Axis', _c16,  
+				'$.RContLens.Add', _c17,  
+				'$.RContLens.Bc', _c18,  
+				'$.RContLens.Dia', _c19,  
+
+				'$.LContLens.Sph', _c20,  
+				'$.LContLens.Cyl', _c21,  
+				'$.LContLens.Axis', _c22,  
+				'$.LContLens.Add', _c23,  
+				'$.LContLens.Bc', _c24,  
+				'$.LContLens.Dia', _c25
+			)
+		where id = _c1;
+
+	end loop loop_eyetest;
+close _line_cur_eyetest;
+
+END;
+//
+DELIMITER ;
+call conv_eyetest_sorder();

+ 109 - 0
function-in-db/procedures/point/credit_bd_act.sql

@@ -0,0 +1,109 @@
+drop procedure if exists credit_bd_act;
+
+create procedure credit_bd_act( _slip_code varchar(6), _target int, _act int)
+
+BEGIN
+
+Declare _created_on bigint ;
+Declare _updated_on bigint ;
+Declare _created_id int ;
+Declare _sorder_bd_id int(11) defauLt 0;
+Declare _credit_id int(11) default 0;
+Declare _sorder_date varchar(8);
+Declare _avail_date varchar(8);
+Declare _branch_id int ;
+Declare _user_id int ;
+Declare _deal_type_id int;
+
+Declare _sorder_sum decimal(20,4);
+Declare _credit_amt decimal(20,4);
+Declare _add_msg varchar(49);
+
+Declare _from_buyer_id int;
+Declare _to_buyer_id int;
+Declare _is_transfer varchar(49);
+
+Declare _tgt_sorder_bd_id int;
+Declare _tgt_credit_id int;
+
+if _slip_code = 'sordbd' then
+    set _tgt_sorder_bd_id = _target;
+    set _tgt_credit_id = 0;
+	select sobd.id, sorder_date, date_format(date_add(_sorder_date, interval 1 day), '%Y%m%d'),
+		branch_id, sohd.user_id, deal_type_id, 
+		buyer_id, sorder_sum, rdecimal((sorder_qty*offer_credit),0), 
+		concat( sorder_no, ' / ', item_code )
+	into _sorder_bd_id, _sorder_date, _avail_date, _branch_id, _user_id, _deal_type_id,
+		_to_buyer_id, _sorder_sum, _credit_amt, _add_msg
+	from dbr_sorder  as sohd
+		inner join dbr_sorder_bd as sobd on sohd.id = sobd.sorder_id
+		inner join dbr_item as itm on itm.id = sobd.item_id
+	where sobd.id = _target;
+
+elseif _slip_code = 'credit' then -- sorder_date = credit_date = avail_date 로 한다.
+    set _tgt_sorder_bd_id = 0;
+    set _tgt_credit_id =  _target;
+	select id, credit_date, credit_date, branch_id, user_id, deal_type_id, 
+		is_transfer, from_buyer_id, to_buyer_id, manual_amt, credit_no
+	into _credit_id, _sorder_date, _avail_date, _branch_id, _user_id, _deal_type_id,
+		_is_transfer, _from_buyer_id, _to_buyer_id, _credit_amt, _add_msg
+	from dbr_credit as crdt
+	where crdt.id = _target;
+
+end if;
+
+-- act for stock_io
+if _act = 0 then 
+
+	insert into dbr_credit_bd
+		( created_on, bd_id, credit_id, occur_date, avail_date, branch_id,
+		user_id, deal_type_id, buyer_id, credit_amt,
+		add_msg, is_from_buyer )
+	values ( unix_timestamp(), _sorder_bd_id, _credit_id, _sorder_date, _avail_date, _branch_id,
+			_user_id, _deal_type_id, _to_buyer_id, _credit_amt,
+			_add_msg, '0' );
+
+	if _is_transfer = '1' then  -- credit 에서만
+		insert into dbr_credit_bd
+			( created_on, bd_id, credit_id, occur_date, avail_date, branch_id,
+			user_id, deal_type_id, buyer_id, credit_amt,
+			add_msg, is_from_buyer )
+		values ( unix_timestamp(), _sorder_bd_id, _credit_id, _sorder_date, _avail_date, _branch_id,
+				_user_id, _deal_type_id, _from_buyer_id, -1*_credit_amt,
+				_add_msg, '1' );
+	end if;
+
+elseif _act = 1 then
+
+	update dbr_credit_bd
+	set updated_on=unix_timestamp(),
+		bd_id=_sorder_bd_id, occur_date=_sorder_date, avail_date=_avail_date, 
+		branch_id=_branch_id, user_id = _user_id, deal_type_id = _deal_type_id,
+		buyer_id = _to_buyer_id, credit_amt = _credit_amt,
+		add_msg = _add_msg
+	where credit_id=_tgt_credit_id and bd_id= _tgt_sorder_bd_id and is_from_buyer = '0';
+
+
+	if _is_transfer = '1' then  -- credit 에서만
+		update dbr_credit_bd
+		set updated_on=unix_timestamp(),
+			bd_id=_sorder_bd_id, occur_date=_sorder_date, avail_date=_avail_date, 
+			branch_id=_branch_id, user_id = _user_id, deal_type_id = _deal_type_id,
+			buyer_id = _from_buyer_id, credit_amt = -1*_credit_amt,
+			add_msg = _add_msg
+		where credit_id=_tgt_credit_id and bd_id= _tgt_sorder_bd_id and is_from_buyer = '1';
+	end if;
+
+elseif _act = -1 then
+
+	delete from dbr_credit_bd
+	where credit_id=_tgt_credit_id and bd_id= _tgt_sorder_bd_id and is_from_buyer = '0';
+
+	if _is_transfer = '1' then  -- credit 에서만
+		delete from dbr_credit_bd
+		where credit_id=_tgt_credit_id and bd_id= _tgt_sorder_bd_id and is_from_buyer = '1';
+	end if;
+
+end if;
+
+END;

+ 55 - 0
function-in-db/procedures/point/credit_bd_sync.sql

@@ -0,0 +1,55 @@
+
+drop procedure if exists credit_bd_sync;
+
+DELIMITER //
+create procedure credit_bd_sync( _sdate varchar(8), _edate varchar(8) )
+
+BEGIN
+
+Declare _line_id int;
+
+Declare _not_found boolean;
+
+Declare _line_cur_sales cursor for 
+    select sobd.id 
+	from dbr_sorder  as sohd
+		inner join dbr_sorder_bd as sobd on sohd.id = sobd.sorder_id
+		inner join dbr_item as itm on itm.id = sobd.item_id
+	where sorder_date between _sdate and _edate 
+	order by sorder_date asc, sobd.id asc;
+
+Declare _line_cur_credit cursor for 
+    select crdt.id 
+	from dbr_credit as crdt
+	where credit_date between _sdate and _edate 
+	order by credit_date asc, crdt.id asc;
+
+Declare continue handler for 
+        not found set _not_found = true;
+
+-- 지우는 범위는 avail_date가 아니다. 전표발생일자 기준
+delete from dbr_credit_bd where occur_date between _sdate and _edate;
+
+set _not_found = false;  -- 이것이 Multi cursor를 쓰는 핵심이다.
+open _line_cur_sales;
+	loop_sales: loop
+		fetch _line_cur_sales into _line_id;
+		if _not_found then leave loop_sales; end if;
+
+		call credit_bd_act('sordbd', _line_id, 0);
+	end loop loop_sales;
+close _line_cur_sales;
+
+set _not_found = false;  -- 이것이 Multi cursor를 쓰는 핵심이다.
+open _line_cur_credit;
+	loop_credit: loop
+		fetch _line_cur_credit into _line_id;
+		if _not_found then leave loop_credit; end if;
+
+		call credit_bd_act('credit', _line_id, 0);
+	end loop loop_credit;
+close _line_cur_credit;
+
+END;
+//
+DELIMITER ;

+ 121 - 0
function-in-db/procedures/point/lt1-credit-bd-sum-bal.sql

@@ -0,0 +1,121 @@
+truncate table dbt_list_sum;
+truncate table dbt_list_type1;
+drop procedure if exists lt1_credit_bd_sum_bal;
+
+DELIMITER //
+create procedure lt1_credit_bd_sum_bal( _listToken varchar(21), _sdate varchar(8), _edate varchar(8), 
+_s1 varchar(32), _e1 varchar(32), _s2 varchar(32), _e2 varchar(32), 
+_s3 varchar(32), _e3 varchar(32), _s4 varchar(32), _e4 varchar(32), 
+_where varchar(386), _having varchar(386), _orderby varchar(64), 
+_branch int, _storage int)
+
+BEGIN
+
+Declare _sbal_date varchar(8);
+Declare _ebal_date varchar(8);
+
+Declare _sbet1 varchar(64);
+Declare _ebet1 varchar(64);
+Declare _sbet2 varchar(64);
+Declare _ebet2 varchar(64);
+Declare _sbet3 varchar(64);
+Declare _ebet3 varchar(64);
+
+
+if _is_first_date(_sdate) then
+	set _sbal_date = '19000101';
+	set _ebal_date = '19000101';
+else
+	set _sbal_date = _sdate;
+	set _ebal_date = _edate;
+end if;
+
+if _s1 != '' and _e1 != '' then
+	set _sbet1 = _s1;
+	set _ebet1 = _e1;
+else
+	set _sbet1 = '!';
+	set _ebet1 = '힣';
+end if;
+
+if _s2 != '' and _e2 != '' then
+	set _sbet2 = _s2;
+	set _ebet2 = _e2;
+else
+	set _sbet2 = '!';
+	set _ebet2 = '힣';
+end if;
+
+
+if _s3 != '' and _e3 != '' then
+	set _sbet3 = _s3;
+	set _ebet3 = _e3;
+else
+	set _sbet3 = '!';
+	set _ebet3 = '힣';
+end if;
+
+insert into dbt_list_sum
+	( created_on, list_token, h_id, id, c1,
+	  d1, d2, d3, d4,
+	  c2, c3, c4, order_by )
+
+select unix_timestamp(), _listToken, mx.id, mx.id, mx.company_name,
+	bal_amt, 0, 0, 0,
+	cgroup_name, cgroup_code, concat(full_name, ' ', company_no), concat(company_name, ' ', company_no)
+from
+	( select buyer_id, bal_amt
+		from dbr_bal_credit
+		where yyyy_mm = _prev_month(_sdate) and branch_id = _branch
+	) as last_mbal
+	inner join dbr_company as mx on mx.id = last_mbal.buyer_id
+	inner join dbr_cgroup as cgr on cgroup_id = cgr.id
+where cgr.cgroup_code between _sbet1 and _ebet1
+	and mx.company_name between _sbet2 and _ebet2
+	and ( company_class = 'AA' or company_class = 'AB' );
+
+-- 적립금 합계 --
+insert into dbt_list_sum
+	( created_on, list_token, h_id, id, c1, 
+	  d1, d2, d3, d4, 
+	  c2, c3, c4, order_by )
+
+select unix_timestamp(), _listToken, cmp.id, cmp.id, company_name,
+	0, sum(credit_amt*cast((credit_status+1)/2 as int)), sum(credit_amt*cast(-1*(credit_status-1)/2 as int)), sum(credit_amt*credit_status),
+	cgroup_name, cgroup_code, concat(full_name, ' ', company_no), concat(company_name, ' ', company_no)
+from 
+    ( select id, buyer_id, branch_id, deal_type_id, credit_amt
+        from dbr_credit_bd
+        where avail_date between _sdate and _edate
+	) as sbbd
+	inner join dbr_deal_type as deal on deal.id = sbbd.deal_type_id
+    inner join ( select cmp.id, company_name, full_name, company_no, cgroup_name, cgroup_code
+        from dbr_company as cmp
+            inner join dbr_cgroup as cgr on cgroup_id = cgr.id
+        where cgr.cgroup_code between _sbet1 and _ebet1
+			and cmp.company_name between _sbet2 and _ebet2
+			and ( company_class = 'AA' or company_class = 'AB' )
+	) as cmp on cmp.id = sbbd.buyer_id 
+where branch_id = _branch
+group by cmp.id;
+
+-- dbt_list_type1 으로 집계 --
+insert into dbt_list_type1
+	( created_on, list_token, h_id, id, c1, 
+		d1, d2, d3, d4, 
+		c2, c3, c4, order_by)
+select min(unix_timestamp()), min(_listToken), min(id), min(id), min(c1),
+	sum(d1),
+	sum(d2),
+	sum(d3),
+	sum(d1) + sum(d2) - sum(d3),
+	min(c2), min(c3), min(c4), min(order_by)
+from dbt_list_sum as mx
+where list_token = _listToken
+group by mx.id
+having min(mx.id) is not null
+order by order_by asc;
+
+END;
+//
+DELIMITER ; 

+ 135 - 0
function-in-db/procedures/point/lt1-credit-bd-sum-bal.sql--

@@ -0,0 +1,135 @@
+truncate table dbt_list_type1;
+drop procedure if exists lt1_credit_bd_sum_bal;
+
+DELIMITER //
+create procedure lt1_credit_bd_sum_bal( _listToken varchar(21), _sdate varchar(8), _edate varchar(8), 
+_s1 varchar(32), _e1 varchar(32), _s2 varchar(32), _e2 varchar(32), 
+_s3 varchar(32), _e3 varchar(32), _s4 varchar(32), _e4 varchar(32), 
+_where varchar(386), _having varchar(386), _orderby varchar(64), 
+_branch int, _storage int)
+
+BEGIN
+
+Declare _sbal_date varchar(8);
+Declare _ebal_date varchar(8);
+
+Declare _sbet1 varchar(64);
+Declare _ebet1 varchar(64);
+Declare _sbet2 varchar(64);
+Declare _ebet2 varchar(64);
+Declare _sbet3 varchar(64);
+Declare _ebet3 varchar(64);
+
+
+if _is_first_date(_sdate) then
+	set _sbal_date = '19000101';
+	set _ebal_date = '19000101';
+else
+	set _sbal_date = _sdate;
+	set _ebal_date = _edate;
+end if;
+
+if _s1 != '' and _e1 != '' then
+	set _sbet1 = _s1;
+	set _ebet1 = _e1;
+else
+	set _sbet1 = '!';
+	set _ebet1 = '駾';
+end if;
+
+if _s2 != '' and _e2 != '' then
+	set _sbet2 = _s2;
+	set _ebet2 = _e2;
+else
+	set _sbet2 = '!';
+	set _ebet2 = '駾';
+end if;
+
+
+if _s3 != '' and _e3 != '' then
+	set _sbet3 = _s3;
+	set _ebet3 = _e3;
+else
+	set _sbet3 = '!';
+	set _ebet3 = '駾';
+end if;
+
+insert into dbt_list_sum
+	( created_on, list_token, h_id, id, c1,
+	  d1, d2, d3, d4,
+	  c2, c3, c4, order_by )
+
+select unix_timestamp(),'aaa', mx.id, mx.id, mx.company_name,
+	bal_amt, 0, 0, 0,
+	cgroup_name, cgroup_code, concat(company_name, company_no), concat(company_name, company_no)
+from
+	( select buyer_id, bal_amt
+		from dbr_bal_reward
+		where yyyy_mm = _prev_month(_sdate) and branch_id = _branch
+	) as last_mbal
+	inner join dbr_company as mx on mx.id = last_mbal.buyer_id
+	inner join dbr_cgroup as cgr on cgroup_id = cgr.id
+where cgr.cgroup_code between _sbet1 and _ebet1
+	and mx.company_name between _sbet2 and _ebet2
+	and ( company_class = 'AA' or company_class = 'AB' );
+
+
+
+insert into dbt_list_type1
+	( created_on, list_token, id, c1, d1, d2, d3, d4, c2, c3)
+
+select unix_timestamp(), _listToken, mx.id, company_name, bal.last_bal, 
+	ifnull(io_sum.in_tot, 0), ifnull(io_sum.out_tot, 0),
+	bal.last_bal + ifnull(io_sum.in_tot, 0) - ifnull(io_sum.out_tot, 0) as curr_bal, 
+  	cgroup_name, cgroup_code
+
+from
+	dbr_company as mx
+	inner join dbr_cgroup as cgr on mx.cgroup_id = cgr.id
+	left join
+	(
+		select mxv.id,
+			ifnull(last_mbal.bal_amt,0) + ifnull(crd_bal.crd_amt,0) as last_bal
+		from dbr_company as mxv
+		left join
+		( select buyer_id, bal_amt
+			from dbr_bal_credit
+			where yyyy_mm = _prev_month(_sdate) and branch_id = _branch
+		) as last_mbal
+		on mxv.id = last_mbal.buyer_id
+
+		left join
+		( select crd.buyer_id, sum(credit_amt*credit_status) AS crd_amt
+		from dbr_credit_bd  as crd
+			inner join dbr_deal_type as deal on deal.id = crd.deal_type_id
+		where avail_date between _first_date(_sbal_date) and _prev_date(_ebal_date)
+			and branch_id = _branch
+		group by crd.buyer_id
+		) as crd_bal
+		on mxv.id = crd_bal.buyer_id
+
+	) bal
+
+	on mx.id = bal.id
+
+	left join
+		( select crd.buyer_id,
+			sum(credit_amt*cast((credit_status+1)/2 as int)) as in_tot,
+			sum(credit_amt*cast(-1*(credit_status-1)/2 as int)) as out_tot
+		from dbr_credit_bd  as crd
+			inner join dbr_deal_type as deal on deal.id = crd.deal_type_id
+		where avail_date between _sdate and _edate
+			and branch_id = _branch
+		group by crd.buyer_id
+		) as io_sum
+		on mx.id = io_sum.buyer_id
+
+where cgr.cgroup_code between _sbet1 and _ebet1
+	and mx.company_name between _sbet2 and _ebet2
+	and mx.company_class = 'AA' or mx.company_class = 'AB'
+
+order by company_name asc;
+
+END;
+//
+DELIMITER ;

+ 121 - 0
function-in-db/procedures/point/lt1-reward-bd-sum-bal.sql

@@ -0,0 +1,121 @@
+truncate table dbt_list_sum;
+truncate table dbt_list_type1;
+drop procedure if exists lt1_reward_bd_sum_bal;
+
+DELIMITER //
+create procedure lt1_reward_bd_sum_bal( _listToken varchar(21), _sdate varchar(8), _edate varchar(8), 
+_s1 varchar(32), _e1 varchar(32), _s2 varchar(32), _e2 varchar(32), 
+_s3 varchar(32), _e3 varchar(32), _s4 varchar(32), _e4 varchar(32), 
+_where varchar(386), _having varchar(386), _orderby varchar(64), 
+_branch int, _storage int)
+
+BEGIN
+
+Declare _sbal_date varchar(8);
+Declare _ebal_date varchar(8);
+
+Declare _sbet1 varchar(64);
+Declare _ebet1 varchar(64);
+Declare _sbet2 varchar(64);
+Declare _ebet2 varchar(64);
+Declare _sbet3 varchar(64);
+Declare _ebet3 varchar(64);
+
+
+if _is_first_date(_sdate) then
+	set _sbal_date = '19000101';
+	set _ebal_date = '19000101';
+else
+	set _sbal_date = _sdate;
+	set _ebal_date = _edate;
+end if;
+
+if _s1 != '' and _e1 != '' then
+	set _sbet1 = _s1;
+	set _ebet1 = _e1;
+else
+	set _sbet1 = '!';
+	set _ebet1 = '힣';
+end if;
+
+if _s2 != '' and _e2 != '' then
+	set _sbet2 = _s2;
+	set _ebet2 = _e2;
+else
+	set _sbet2 = '!';
+	set _ebet2 = '힣';
+end if;
+
+
+if _s3 != '' and _e3 != '' then
+	set _sbet3 = _s3;
+	set _ebet3 = _e3;
+else
+	set _sbet3 = '!';
+	set _ebet3 = '힣';
+end if;
+
+insert into dbt_list_sum
+	( created_on, list_token, h_id, id, c1,
+	  d1, d2, d3, d4,
+	  c2, c3, c4, order_by )
+
+select unix_timestamp(), _listToken, mx.id, mx.id, mx.company_name,
+	bal_amt, 0, 0, 0,
+	cgroup_name, cgroup_code, concat(full_name, ' ', company_no), concat(company_name, ' ', company_no)
+from
+	( select buyer_id, bal_amt
+		from dbr_bal_reward
+		where yyyy_mm = _prev_month(_sdate) and branch_id = _branch
+	) as last_mbal
+	inner join dbr_company as mx on mx.id = last_mbal.buyer_id
+	inner join dbr_cgroup as cgr on cgroup_id = cgr.id
+where cgr.cgroup_code between _sbet1 and _ebet1
+	and mx.company_name between _sbet2 and _ebet2
+	and ( company_class = 'AA' or company_class = 'AB' );
+
+-- 적립금 합계 --
+insert into dbt_list_sum
+	( created_on, list_token, h_id, id, c1, 
+	  d1, d2, d3, d4, 
+	  c2, c3, c4, order_by )
+
+select unix_timestamp(), _listToken, cmp.id, cmp.id, company_name,
+	0, sum(reward_amt*cast((reward_status+1)/2 as int)), sum(reward_amt*cast(-1*(reward_status-1)/2 as int)), sum(reward_amt*reward_status),
+	cgroup_name, cgroup_code, concat(full_name, ' ', company_no), concat(company_name, ' ', company_no)
+from 
+    ( select id, buyer_id, branch_id, deal_type_id, reward_amt
+        from dbr_reward_bd
+        where avail_date between _sdate and _edate
+	) as sbbd
+	inner join dbr_deal_type as deal on deal.id = sbbd.deal_type_id
+    inner join ( select cmp.id, company_name, full_name, company_no, cgroup_name, cgroup_code
+        from dbr_company as cmp
+            inner join dbr_cgroup as cgr on cgroup_id = cgr.id
+        where cgr.cgroup_code between _sbet1 and _ebet1
+			and cmp.company_name between _sbet2 and _ebet2
+			and ( company_class = 'AA' or company_class = 'AB' )
+	) as cmp on cmp.id = sbbd.buyer_id 
+where branch_id = _branch
+group by cmp.id;
+
+-- dbt_list_type1 으로 집계 --
+insert into dbt_list_type1
+	( created_on, list_token, h_id, id, c1, 
+		d1, d2, d3, d4, 
+		c2, c3, c4, order_by)
+select min(unix_timestamp()), min(_listToken), min(id), min(id), min(c1),
+	sum(d1),
+	sum(d2),
+	sum(d3),
+	sum(d1) + sum(d2) - sum(d3),
+	min(c2), min(c3), min(c4), min(order_by)
+from dbt_list_sum as mx
+where list_token = _listToken
+group by mx.id
+having min(mx.id) is not null
+order by order_by asc;
+
+END;
+//
+DELIMITER ; 

+ 119 - 0
function-in-db/procedures/point/pl1_credit_bd_ledger_detail.sql

@@ -0,0 +1,119 @@
+-- truncate table zzz_log;
+truncate table dbt_list_type1;
+truncate table dbt_list_sum;
+drop procedure if exists pl1_credit_bd_ledger_detail;
+
+create procedure pl1_credit_bd_ledger_detail( _listToken varchar(21), _sdate varchar(8), _edate varchar(8), 
+_s1 varchar(32), _e1 varchar(32), _s2 varchar(32), _e2 varchar(32), 
+_s3 varchar(32), _e3 varchar(32), _s4 varchar(32), _e4 varchar(32), 
+_where varchar(386), _having varchar(386), _orderby varchar(64), 
+_branch int, _storage int, _target int)
+
+BEGIN
+
+Declare _sbal_date varchar(8);
+Declare _ebal_date varchar(8);
+
+Declare _first_bal decimal(20,4);
+Declare _first_bad_bal decimal(20,4);
+Declare _first_bal_caption varchar(20);
+
+Declare _first_id int;
+Declare _last_id int;
+
+Declare _line_id int;
+Declare _line_badcrd_status varchar(64);
+Declare _line_in decimal(20,4) default "0.0000";
+Declare _line_out decimal(20,4) default "0.0000";
+Declare _line_bal decimal(20,4) default "0.0000";
+Declare _line_bad_bal decimal(20,4) default "0.0000";
+Declare _in_sum decimal(20,4) default "0.0000";
+Declare _out_sum decimal(20,4) default "0.0000";
+
+Declare _company_name varchar(64);
+Declare _full_name varchar(96);
+
+Declare _item_code varchar(21);
+Declare _item_sub_name varchar(128);
+
+Declare _not_found boolean;
+Declare _line_cur cursor for -- c5:badcrd_status
+    select t_id, d3, d4 from dbt_list_type1 where list_token = _listToken 
+	order by order_by asc;
+Declare continue handler for 
+        not found set _not_found = true;
+
+if _is_first_date(_sdate) then
+	set _sbal_date = '19000101';
+	set _ebal_date = '19000101';
+else
+	set _sbal_date = _sdate;
+	set _ebal_date = _edate;
+end if;
+
+-- insert for first_bal
+select ifnull(last_mbal.bal_amt,0) + ifnull(crd_bal.credit_amt,0) ,'--이월잔액--' 
+	into _first_bal, _first_bal_caption
+	from
+		dbr_company as mxv
+		left join
+		( select buyer_id, bal_amt
+		from dbr_bal_credit
+		where yyyy_mm = _prev_month(_sdate) and branch_id = _branch
+		) as last_mbal
+		on mxv.id = last_mbal.buyer_id
+
+		left join
+		( select crd.buyer_id, sum(credit_amt*credit_status) AS credit_amt
+		from dbr_credit_bd  as crd
+			inner join dbr_deal_type as deal on deal.id = crd.deal_type_id
+		where avail_date between _first_date(_sbal_date) and _prev_date(_ebal_date)
+			and branch_id = _branch
+		group by crd.buyer_id
+		) as crd_bal
+		on mxv.id = crd_bal.buyer_id
+
+where mxv.id = _target;
+
+insert into dbt_list_type1 ( created_on, list_token, c3, d5, order_by)
+	values ( unix_timestamp(), _listToken, _first_bal_caption, _first_bal, '19000101');
+
+-- insert for credit_bd
+insert into dbt_list_type1
+	( created_on, list_token, c1, c2, c3, d1, d2, d3, d4, order_by )
+select unix_timestamp(), _listToken, avail_date, deal_code, 
+	concat( add_msg,' / ', item_name ), 
+	sobd.sorder_qty, sobd.sorder_sum, crd.credit_amt*cast((credit_status+1)/2 as int), 
+	crd.credit_amt*cast(-1*(credit_status-1)/2 as int),
+	concat( avail_date, '-', -1*credit_status,'-', bd_id)
+from dbr_credit_bd  as crd
+	inner join dbr_deal_type as deal on deal.id = crd.deal_type_id
+	left join dbr_sorder_bd as sobd on sobd.id = crd.bd_id
+	left join dbr_item as itm on sobd.item_id = itm.id
+
+where avail_date between _sdate and _edate and branch_id = _branch and crd.buyer_id = _target;
+
+-- compute line_bal
+set _line_bal = _first_bal;
+set _line_bad_bal = _first_bad_bal;
+open _line_cur;
+	loop1: loop
+		fetch _line_cur into _line_id, _line_in, _line_out;
+		if _not_found then leave loop1; end if;
+
+		set _in_sum = _in_sum + ifnull(_line_in,0);
+		set _out_sum = _out_sum + ifnull(_line_out,0);
+		set _line_bal = ifnull(_line_bal,0) + ifnull(_line_in,0) - ifnull(_line_out,0);
+
+		update dbt_list_type1 set d5 = _line_bal  where t_id = _line_id;
+	end loop loop1;
+close _line_cur;
+
+-- write list_sum
+select company_name, full_name into _company_name, _full_name from dbr_company where id = _target;
+insert into dbt_list_sum
+	( created_on, list_token, c1, c2, c3, c4, d1, d2, d3, d4)
+	values (unix_timestamp(), _listToken, _company_name, _full_name, _sdate, _edate, 
+	_first_bal, _in_sum, _out_sum, _line_bal);
+
+END;

+ 122 - 0
function-in-db/procedures/point/pl1_reward_bd_ledger_detail.sql

@@ -0,0 +1,122 @@
+-- truncate table zzz_log;
+truncate table dbt_list_type1;
+truncate table dbt_list_sum;
+drop procedure if exists pl1_reward_bd_ledger_detail;
+
+DELIMITER //
+create procedure pl1_reward_bd_ledger_detail( _listToken varchar(21), _sdate varchar(8), _edate varchar(8), 
+_s1 varchar(32), _e1 varchar(32), _s2 varchar(32), _e2 varchar(32), 
+_s3 varchar(32), _e3 varchar(32), _s4 varchar(32), _e4 varchar(32), 
+_where varchar(386), _having varchar(386), _orderby varchar(64), 
+_branch int, _storage int, _target int)
+
+BEGIN
+
+Declare _sbal_date varchar(8);
+Declare _ebal_date varchar(8);
+
+Declare _first_bal decimal(20,4);
+Declare _first_bad_bal decimal(20,4);
+Declare _first_bal_caption varchar(20);
+
+Declare _first_id int;
+Declare _last_id int;
+
+Declare _line_id int;
+Declare _line_badrwd_status varchar(64);
+Declare _line_in decimal(20,4) default "0.0000";
+Declare _line_out decimal(20,4) default "0.0000";
+Declare _line_bal decimal(20,4) default "0.0000";
+Declare _line_bad_bal decimal(20,4) default "0.0000";
+Declare _in_sum decimal(20,4) default "0.0000";
+Declare _out_sum decimal(20,4) default "0.0000";
+
+Declare _company_name varchar(64);
+Declare _full_name varchar(96);
+
+Declare _item_code varchar(21);
+Declare _item_sub_name varchar(128);
+
+Declare _not_found boolean;
+Declare _line_cur cursor for -- c5:badrwd_status
+    select t_id, d3, d4 from dbt_list_type1 where list_token = _listToken 
+	order by order_by asc;
+Declare continue handler for 
+        not found set _not_found = true;
+
+if _is_first_date(_sdate) then
+	set _sbal_date = '19000101';
+	set _ebal_date = '19000101';
+else
+	set _sbal_date = _sdate;
+	set _ebal_date = _edate;
+end if;
+
+-- insert for first_bal
+select ifnull(last_mbal.bal_amt,0) + ifnull(rwd_bal.reward_amt,0) ,'이월잔액' 
+	into _first_bal, _first_bal_caption
+	from
+		dbr_company as mxv
+		left join
+		( select buyer_id, bal_amt
+		from dbr_bal_reward
+		where yyyy_mm = _prev_month(_sdate) and branch_id = _branch
+		) as last_mbal
+		on mxv.id = last_mbal.buyer_id
+
+		left join
+		( select rwd.buyer_id, sum(reward_amt*reward_status) AS reward_amt
+		from dbr_reward_bd  as rwd
+			inner join dbr_deal_type as deal on deal.id = rwd.deal_type_id
+		where avail_date between _first_date(_sbal_date) and _prev_date(_ebal_date)
+			and branch_id = _branch
+		group by rwd.buyer_id
+		) as rwd_bal
+		on mxv.id = rwd_bal.buyer_id
+
+where mxv.id = _target;
+
+insert into dbt_list_type1 ( created_on, list_token, c3, d5, order_by)
+	values ( unix_timestamp(), _listToken, _first_bal_caption, _first_bal, '19000101');
+
+-- insert for reward_bd
+insert into dbt_list_type1
+	( created_on, list_token, c1, c2, c3, d1, d2, d3, d4, order_by )
+select unix_timestamp(), _listToken, avail_date, deal_code, 
+	concat( add_msg,' / ', item_name ), 
+	sobd.sorder_qty, sobd.sorder_sum, rwd.reward_amt*cast((reward_status+1)/2 as int), 
+	rwd.reward_amt*cast(-1*(reward_status-1)/2 as int),
+	concat( avail_date, '-', -1*reward_status,'-', bd_id)
+from dbr_reward_bd  as rwd
+	inner join dbr_deal_type as deal on deal.id = rwd.deal_type_id
+	left join dbr_sorder_bd as sobd on sobd.id = rwd.bd_id
+	left join dbr_item as itm on sobd.item_id = itm.id
+
+where avail_date between _sdate and _edate and branch_id = _branch and rwd.buyer_id = _target;
+
+-- compute line_bal
+set _line_bal = _first_bal;
+set _line_bad_bal = _first_bad_bal;
+open _line_cur;
+	loop1: loop
+		fetch _line_cur into _line_id, _line_in, _line_out;
+		if _not_found then leave loop1; end if;
+
+		set _in_sum = _in_sum + ifnull(_line_in,0);
+		set _out_sum = _out_sum + ifnull(_line_out,0);
+		set _line_bal = ifnull(_line_bal,0) + ifnull(_line_in,0) - ifnull(_line_out,0);
+
+		update dbt_list_type1 set d5 = _line_bal  where t_id = _line_id;
+	end loop loop1;
+close _line_cur;
+
+-- write list_sum
+select company_name, concat( main_contact, ' / ', email ) into _company_name, _full_name from dbr_company where id = _target;
+insert into dbt_list_sum
+	( created_on, list_token, c1, c2, c3, c4, d1, d2, d3, d4)
+	values (unix_timestamp(), _listToken, _company_name, _full_name, _sdate, _edate, 
+	_first_bal, _in_sum, _out_sum, _line_bal);
+
+END;
+//
+DELIMITER ;

+ 126 - 0
function-in-db/procedures/point/reward_bd_act.sql

@@ -0,0 +1,126 @@
+
+drop procedure if exists reward_bd_act;
+
+DELIMITER //
+create procedure reward_bd_act( _slip_code varchar(6), _target int, _act int)
+
+_procedure: BEGIN
+
+Declare _created_on bigint ;
+Declare _updated_on bigint ;
+Declare _created_id int ;
+Declare _hd_id int(11) defauLt 0;
+Declare _bd_id int(11) defauLt 0;
+Declare _reward_id int(11) default 0;
+Declare _sorder_date varchar(8);
+Declare _avail_date varchar(8);
+Declare _branch_id int ;
+Declare _user_id int ;
+Declare _deal_type_id int;
+
+Declare _sorder_sum decimal(20,4);
+Declare _reward_rate decimal(4,2);
+Declare _reward_amt decimal(20,4);
+Declare _add_msg varchar(49);
+
+Declare _from_buyer_id int;
+Declare _to_buyer_id int;
+Declare _is_transfer char(1);
+
+Declare _deal_sordbd int(11) default 55; -- 적립금 발생 
+Declare _deal_sorder int(11) default 56; -- 적립금 사용 
+Declare _deal_reward int(11) default 57; -- 적립금 변경
+
+if _slip_code = 'sordbd' then  -- 적립금 발생 
+	select sobd.id, sorder_date, date_format(date_add(_sorder_date, interval 1 day), '%Y%m%d'),
+		branch_id, sohd.user_id, _deal_sordbd, 
+		buyer_id, sorder_sum, reward_rate, rdecimal((sorder_sum*reward_rate)/100,0), 
+		concat( sorder_no, ' / ', item_code )
+	into _bd_id, _sorder_date, _avail_date, _branch_id, _user_id, _deal_type_id,
+		_to_buyer_id, _sorder_sum, _reward_rate, _reward_amt, _add_msg
+	from dbr_sorder  as sohd
+		inner join dbr_sorder_bd as sobd on sohd.id = sobd.sorder_id
+		inner join dbr_item as itm on itm.id = sobd.item_id
+	where sobd.id = _target;
+
+elseif _slip_code = 'reward' then -- sorder_date = reward_date = avail_date 로 한다.
+	select id, reward_date, reward_date, branch_id, user_id, deal_type_id, 
+		is_transfer, from_buyer_id, to_buyer_id, '0.00', manual_amt, reward_no
+	into _reward_id, _sorder_date, _avail_date, _branch_id, _user_id, _deal_type_id,
+		_is_transfer, _from_buyer_id, _to_buyer_id, _reward_rate, _reward_amt, _add_msg
+	from dbr_reward as rewd
+	where rewd.id = _target;
+
+elseif _slip_code = 'sorder' then -- 적립금 사용
+	select sohd.id, sorder_date, sorder_date,
+		branch_id, sohd.user_id, _deal_sorder, 
+		buyer_id, ifnull(sum(sorder_sum), 0),'0.00', reward_use_amt, 
+		concat( sorder_no, ' / ', max(item_code) )
+	into _hd_id, _sorder_date, _avail_date, _branch_id, _user_id, _deal_type_id,
+		_to_buyer_id, _sorder_sum, _reward_rate, _reward_amt, _add_msg
+	from dbr_sorder  as sohd
+		left join dbr_sorder_bd as sobd on sohd.id = sobd.sorder_id
+		left join dbr_item as itm on itm.id = sobd.item_id
+	where sohd.id = _target;
+
+end if;
+
+if _reward_amt = '0.0000' then
+	leave _procedure;
+end if;
+
+if _act = 0 then 
+
+	insert into dbr_reward_bd
+		( created_on, hd_id, bd_id, reward_id, occur_date, avail_date, branch_id,
+		user_id, deal_type_id, buyer_id, reward_rate, reward_amt,
+		add_msg, is_from_buyer )
+	values ( unix_timestamp(), _hd_id, _bd_id, _reward_id, _sorder_date, _avail_date, _branch_id,
+			_user_id, _deal_type_id, _to_buyer_id, _reward_rate, _reward_amt,
+			_add_msg, '0' );
+
+	if _is_transfer = '1' then  -- reward 에서만
+		insert into dbr_reward_bd
+			( created_on, hd_id, bd_id, reward_id, occur_date, avail_date, branch_id,
+			user_id, deal_type_id, buyer_id, reward_rate, reward_amt,
+			add_msg, is_from_buyer )
+		values ( unix_timestamp(), _hd_id, _bd_id, _reward_id, _sorder_date, _avail_date, _branch_id,
+				_user_id, _deal_type_id, _from_buyer_id, _reward_rate, -1*_reward_amt,
+				_add_msg, '1' );
+	end if;
+
+elseif _act = 1 then
+
+	update dbr_reward_bd
+	set updated_on=unix_timestamp(),
+		hd_id=_hd_id, bd_id=_bd_id, occur_date=_sorder_date, avail_date=_avail_date, 
+		branch_id=_branch_id, user_id = _user_id, deal_type_id = _deal_type_id,
+		buyer_id = _to_buyer_id, reward_rate = _reward_rate, reward_amt = _reward_amt,
+		add_msg = _add_msg
+	where hd_id = _hd_id  and bd_id = _bd_id and is_from_buyer = '0';
+
+	if _is_transfer = '1' then  -- reward 에서만
+		update dbr_reward_bd
+		set updated_on=unix_timestamp(),
+			hd_id=_hd_id, bd_id=_bd_id, occur_date=_sorder_date, avail_date=_avail_date, 
+			branch_id=_branch_id, user_id = _user_id, deal_type_id = _deal_type_id,
+			buyer_id = _from_buyer_id, reward_rate = _reward_rate, reward_amt = -1*_reward_amt,
+			add_msg = _add_msg
+		where hd_id = _hd_id  and bd_id = _bd_id and is_from_buyer = '1';
+	end if;
+
+elseif _act = -1 then
+
+	delete from dbr_reward_bd
+	where hd_id=_hd_id and bd_id= _bd_id and is_from_buyer = '0';
+
+	if _is_transfer = '1' then  -- reward 에서만
+		delete from dbr_reward_bd
+		where hd_id = _hd_id  and bd_id = _bd_id and is_from_buyer = '1';
+	end if;
+
+end if;
+
+END;
+//
+DELIMITER ;

+ 71 - 0
function-in-db/procedures/point/reward_bd_sync.sql

@@ -0,0 +1,71 @@
+
+drop procedure if exists reward_bd_sync;
+
+DELIMITER //
+create procedure reward_bd_sync( _sdate varchar(8), _edate varchar(8) )
+
+BEGIN
+
+Declare _line_id int;
+
+Declare _not_found boolean;
+
+Declare _line_cur_sales cursor for 
+    select sobd.id 
+	from dbr_sorder  as sohd
+		inner join dbr_sorder_bd as sobd on sohd.id = sobd.sorder_id
+		inner join dbr_item as itm on itm.id = sobd.item_id
+	where sorder_date between _sdate and _edate 
+	order by sorder_date asc, sobd.id asc;
+
+Declare _line_cur_reward cursor for 
+    select rewd.id 
+	from dbr_reward as rewd
+	where reward_date between _sdate and _edate 
+	order by reward_date asc, rewd.id asc;
+
+Declare _line_cur_sorder cursor for 
+    select sohd.id 
+	from dbr_sorder as sohd
+	where sorder_date between _sdate and _edate 
+	order by sorder_date asc, sohd.id asc;
+
+Declare continue handler for 
+        not found set _not_found = true;
+
+-- 지우는 범위는 avail_date가 아니다. 전표발생일자 기준
+delete from dbr_reward_bd where occur_date between _sdate and _edate;
+
+set _not_found = false;  -- 이것이 Multi cursor를 쓰는 핵심이다.
+open _line_cur_sales;
+	loop_sales: loop
+		fetch _line_cur_sales into _line_id;
+		if _not_found then leave loop_sales; end if;
+
+		call reward_bd_act('sordbd', _line_id, 0);
+	end loop loop_sales;
+close _line_cur_sales;
+
+set _not_found = false;  -- 이것이 Multi cursor를 쓰는 핵심이다.
+open _line_cur_reward;
+	loop_reward: loop
+		fetch _line_cur_reward into _line_id;
+		if _not_found then leave loop_reward; end if;
+
+		call reward_bd_act('reward', _line_id, 0);
+	end loop loop_reward;
+close _line_cur_reward;
+
+set _not_found = false;  -- 이것이 Multi cursor를 쓰는 핵심이다.
+open _line_cur_sorder;
+	loop_sorder: loop
+		fetch _line_cur_sorder into _line_id;
+		if _not_found then leave loop_sorder; end if;
+
+		call reward_bd_act('sorder', _line_id, 0);
+	end loop loop_sorder;
+close _line_cur_sorder;
+
+END;
+//
+DELIMITER ;

+ 142 - 0
function-in-db/procedures/purch/lt1-purch-sum-bal.sql

@@ -0,0 +1,142 @@
+truncate table dbt_list_sum;
+truncate table dbt_list_type1;
+drop procedure if exists lt1_purch_sum_bal;
+
+DELIMITER //
+create procedure lt1_purch_sum_bal( _listToken varchar(21), _sdate varchar(8), _edate varchar(8), 
+_s1 varchar(32), _e1 varchar(32), _s2 varchar(32), _e2 varchar(32), 
+_s3 varchar(32), _e3 varchar(32), _s4 varchar(32), _e4 varchar(32), 
+_where varchar(386), _having varchar(386), _orderby varchar(64), 
+_branch int, _storage int)
+
+BEGIN
+
+Declare _sbal_date varchar(8);
+Declare _ebal_date varchar(8);
+
+Declare _sbet1 varchar(64);
+Declare _ebet1 varchar(64);
+Declare _sbet2 varchar(64);
+Declare _ebet2 varchar(64);
+
+if _is_first_date(_sdate) then
+	set _sbal_date = '19000101';
+	set _ebal_date = '19000101';
+else
+	set _sbal_date = _sdate;
+	set _ebal_date = _edate;
+end if;
+
+if _s1 != '' and _e1 != '' then
+	set _sbet1 = _s1;
+	set _ebet1 = _e1;
+else
+	set _sbet1 = '!';
+	set _ebet1 = '힣';
+end if;
+
+if _s2 != '' and _e2 != '' then
+	set _sbet2 = _s2;
+	set _ebet2 = _e2;
+else
+	set _sbet2 = '!';
+	set _ebet2 = '힣';
+end if;
+
+-- 전월 잔액 --
+insert into dbt_list_sum
+	( created_on, list_token, h_id, id, c1, 
+		d1, d2, d3, d4, d5, d6, 
+		c2, c3, c4, order_by)
+
+select unix_timestamp(), _listToken, mx.id, mx.id, mx.company_name,
+	bal_amt, 0, 0, 0, 0, 0,
+	cgroup_name, cgroup_code, concat(full_name, ' ', company_no), concat(company_name, company_no)
+from 
+	( select supplier_id, bal_amt
+		from dbr_bal_supplier
+		where yyyy_mm = _prev_month(_sdate) and branch_id = _branch
+	) as last_mbal 
+	inner join dbr_company as mx on mx.id = last_mbal.supplier_id
+	inner join dbr_cgroup as cgr on cgroup_id = cgr.id
+where cgr.cgroup_code between _sbet1 and _ebet1
+	and mx.company_name between _sbet2 and _ebet2
+	and company_class = 'BB';
+
+-- 매출/반품 합계 --
+insert into dbt_list_sum
+	( created_on, list_token, h_id, id, c1, 
+		d1, d2, d3, d4, d5, d6, 
+		c2, c3, c4, order_by)
+select unix_timestamp(), _listToken, cmp.id, cmp.id, company_name,
+	0, sum(purch_sum*cast((purch_status+1)/2 as int)), sum(purch_sum*cast(-1*(purch_status-1)/2 as int)), 0, 0, 0,
+	cgroup_name, cgroup_code, concat(full_name, ' ', company_no), concat(company_name, company_no)
+from 
+    ( select id, purch_no, purch_date
+        from dbr_purch
+        where purch_date between _sdate and _edate
+	) as sbhd
+	inner join dbr_purch_bd as sbbd on sbhd.id = sbbd.purch_id
+	inner join dbr_porder_bd as mnbd on mnbd.id = sbbd.porder_bd_id
+	inner join dbr_porder as mnhd on mnhd.id = mnbd.porder_id
+	inner join dbr_item as itm on mnbd.item_id = itm.id
+	inner join dbr_deal_type as deal on deal.id = mnhd.deal_type_id
+    inner join ( select cmp.id, company_name, full_name, company_no, cgroup_name, cgroup_code
+        from dbr_company as cmp
+            inner join dbr_cgroup as cgr on cgroup_id = cgr.id
+        where cgr.cgroup_code between _sbet1 and _ebet1
+			and cmp.company_name between _sbet2 and _ebet2
+			and company_class = 'BB'
+	) as cmp on cmp.id = mnhd.supplier_id 
+where branch_id = _branch
+group by cmp.id;
+
+-- 입금/입금할인 합계 --
+insert into dbt_list_sum
+	( created_on, list_token, h_id, id, c1, 
+		d1, d2, d3, d4, d5, d6, 
+		c2, c3, c4, order_by)
+select unix_timestamp(), _listToken, cmp.id, cmp.id, company_name,
+	0, 0, 0, sum(slip_amt*cast((collect_status+1)/2 as int)), 
+    sum(slip_amt*cast(-1*(collect_status-1)/2 as int)), 0,
+	cgroup_name, cgroup_code, concat(full_name, ' ', company_no), concat(company_name, company_no)
+from 
+    ( select id, acc_date, acc_slip_no, deal_type_id,
+        bill_column1, bill_type, slip_amt, company_id
+        from dbr_acc_slip
+        where ( deal_type_id = 22 or deal_type_id = 24 ) -- 출금과 출금할인만
+            and acc_date between _sdate and _edate
+	        and branch_id = _branch
+    ) as mnhd 
+	inner join dbr_deal_type as deal on deal.id = mnhd.deal_type_id
+    inner join ( select cmp.id, company_name, full_name, company_no, cgroup_name, cgroup_code
+        from dbr_company as cmp
+            inner join dbr_cgroup as cgr on cgroup_id = cgr.id
+        where cgr.cgroup_code between _sbet1 and _ebet1
+			and cmp.company_name between _sbet2 and _ebet2
+			and company_class = 'BB'
+	) as cmp on cmp.id = mnhd.company_id 
+group by cmp.id;
+
+-- dbt_list_type1 으로 집계 --
+insert into dbt_list_type1
+	( created_on, list_token, h_id, id, c1, 
+		d1, d2, d3, d4, d5, d6, 
+		c2, c3, c4, order_by)
+select min(unix_timestamp()), min(_listToken), min(id), min(id), min(c1),
+	sum(d1),
+	sum(d2),
+	sum(d3),
+	sum(d4),
+	sum(d5),
+	sum(d1) + sum(d2) + sum(d3) - sum(d4) - sum(d5),
+	min(c2), min(c3), min(c4), min(order_by)
+from dbt_list_sum as mx
+where list_token = _listToken
+group by mx.id
+having min(mx.id) is not null
+order by order_by asc;
+
+END;
+//
+DELIMITER ; 

+ 123 - 0
function-in-db/procedures/purch/pl1_purch_ledger_detail.sql

@@ -0,0 +1,123 @@
+truncate table dbt_list_type1;
+truncate table dbt_list_sum;
+drop procedure if exists pl1_purch_ledger_detail;
+
+DELIMITER //
+create procedure pl1_purch_ledger_detail( _listToken varchar(21), _sdate varchar(8), _edate varchar(8), 
+_s1 varchar(32), _e1 varchar(32), _s2 varchar(32), _e2 varchar(32), 
+_s3 varchar(32), _e3 varchar(32), _s4 varchar(32), _e4 varchar(32), 
+_where varchar(386), _having varchar(386), _orderby varchar(64), 
+_branch int, _storage int, _target int)
+
+BEGIN
+
+Declare _sbal_date varchar(8);
+Declare _ebal_date varchar(8);
+
+Declare _first_bal decimal(20,4);
+Declare _first_bal_caption varchar(20);
+
+Declare _first_id int;
+Declare _last_id int;
+
+Declare _line_id int;
+Declare _line_in decimal(20,4) default "0.0000";
+Declare _line_out decimal(20,4) default "0.0000";
+Declare _line_bal decimal(20,4) default "0.0000";
+Declare _in_sum decimal(20,4) default "0.0000";
+Declare _out_sum decimal(20,4) default "0.0000";
+
+Declare _company_name varchar(64);
+Declare _full_name varchar(96);
+
+Declare _not_found boolean;
+Declare _line_cur cursor for 
+    select t_id, d3, d4 from dbt_list_type1 where t_id > _first_id and t_id <= _last_id
+	order by c1, c2, c3 asc;
+Declare continue handler for 
+        not found set _not_found = true;
+
+if _is_first_date(_sdate) then
+	set _sbal_date = '19000101';
+	set _ebal_date = '19000101';
+else
+	set _sbal_date = _sdate;
+	set _ebal_date = _edate;
+end if;
+
+-- 전월잔액 
+select ifnull(last_mbal.bal_amt,0) , '이월잔액' into _first_bal, _first_bal_caption
+from
+	dbr_company as mv
+	left join
+	( select supplier_id, bal_amt
+	from dbr_bal_supplier
+	where yyyy_mm = _prev_month(_sdate) and branch_id = _branch
+	) as last_mbal on mv.id = last_mbal.supplier_id
+where mv.id = _target;
+
+insert into dbt_list_type1 ( created_on, list_token, c4, d5 )
+	values ( unix_timestamp(), _listToken, _first_bal_caption, _first_bal);
+
+-- insert for purch
+insert into dbt_list_type1
+	( created_on, list_token, c1, c2, c3, c4, c5, d1, d2, d3)
+select unix_timestamp(), _listToken, concat( purch_date,'-', deal_code, '*', sbbd.seq_no ), 
+	concat( purch_no, '*', sbbd.seq_no ), deal_code, 
+    concat( item_code, ' / ', item_name, ' / ', sub_name ), '', -- bill_type 은 비운다.
+ 	purch_qty, porder_prc, purch_sum*purch_status
+from ( select id, purch_no, purch_date
+	from dbr_purch
+    where purch_date between _sdate and _edate 
+	) as sbhd
+	inner join dbr_purch_bd as sbbd on sbhd.id = sbbd.purch_id
+	inner join dbr_porder_bd as mnbd on mnbd.id = sbbd.porder_bd_id
+	inner join dbr_porder as mnhd on mnhd.id = mnbd.porder_id
+	inner join dbr_item as itm on mnbd.item_id = itm.id
+	inner join dbr_deal_type as deal on deal.id = mnhd.deal_type_id
+where branch_id = _branch and mnhd.supplier_id = _target;
+
+-- 출금내역
+insert into dbt_list_type1
+	( created_on, list_token, c1, c2, c3, c4, c5, d4)
+select unix_timestamp(), _listToken, concat( acc_date,'-', deal_code ), 
+	acc_slip_no, deal_code, 
+	bill_column1, bill_type, -1*slip_amt*purch_status
+from 
+    ( select id, acc_date, acc_slip_no, deal_type_id,
+        bill_column1, bill_type, slip_amt
+        from dbr_acc_slip
+        where ( deal_type_id = 22 or deal_type_id = 24 ) -- 출금과 출금할인만
+            and acc_date between _sdate and _edate 	
+	        and branch_id = _branch and company_id = _target
+    ) as mnhd  
+inner join dbr_deal_type as deal on deal.id = deal_type_id;
+
+-- -- get id range for current ledger
+select min(t_id), max(t_id) into  _first_id, _last_id from dbt_list_type1 where list_token = _listToken;
+
+-- compute line_bal
+set _line_bal = _first_bal;
+open _line_cur;
+	loop1: loop
+		fetch _line_cur into _line_id, _line_in, _line_out;
+		if _not_found then leave loop1; end if;
+
+		set _in_sum = _in_sum + ifnull(_line_in,0);
+		set _out_sum = _out_sum + ifnull(_line_out,0);
+		set _line_bal = ifnull(_line_bal,0) + ifnull(_line_in,0) - ifnull(_line_out,0);
+		update dbt_list_type1 set d5 = _line_bal where t_id = _line_id;
+	end loop loop1;
+close _line_cur;
+
+-- write list_sum
+select company_name, concat(full_name, ' ', company_no) 
+	into _company_name, _full_name from dbr_company where id = _target;
+insert into dbt_list_sum
+	( created_on, list_token, c1, c2, c3, c4, d1, d2, d3, d4)
+	values (unix_timestamp(), _listToken, _company_name, _full_name, _sdate, _edate, 
+	_first_bal, _in_sum, _out_sum, _line_bal);
+
+END;
+//
+DELIMITER ;

+ 142 - 0
function-in-db/procedures/sales/lt1-sales-sum-bal.sql

@@ -0,0 +1,142 @@
+truncate table dbt_list_sum;
+truncate table dbt_list_type1;
+drop procedure if exists lt1_sales_sum_bal;
+
+DELIMITER //
+create procedure lt1_sales_sum_bal( _listToken varchar(21), _sdate varchar(8), _edate varchar(8), 
+_s1 varchar(32), _e1 varchar(32), _s2 varchar(32), _e2 varchar(32), 
+_s3 varchar(32), _e3 varchar(32), _s4 varchar(32), _e4 varchar(32), 
+_where varchar(386), _having varchar(386), _orderby varchar(64), 
+_branch int, _storage int)
+
+BEGIN
+
+Declare _sbal_date varchar(8);
+Declare _ebal_date varchar(8);
+
+Declare _sbet1 varchar(64);
+Declare _ebet1 varchar(64);
+Declare _sbet2 varchar(64);
+Declare _ebet2 varchar(64);
+
+if _is_first_date(_sdate) then
+	set _sbal_date = '19000101';
+	set _ebal_date = '19000101';
+else
+	set _sbal_date = _sdate;
+	set _ebal_date = _edate;
+end if;
+
+if _s1 != '' and _e1 != '' then
+	set _sbet1 = _s1;
+	set _ebet1 = _e1;
+else
+	set _sbet1 = '!';
+	set _ebet1 = '힣';
+end if;
+
+if _s2 != '' and _e2 != '' then
+	set _sbet2 = _s2;
+	set _ebet2 = _e2;
+else
+	set _sbet2 = '!';
+	set _ebet2 = '힣';
+end if;
+
+-- 전월 잔액 --
+insert into dbt_list_sum
+	( created_on, list_token, h_id, id, c1, 
+		d1, d2, d3, d4, d5, d6, 
+		c2, c3, c4, order_by)
+
+select unix_timestamp(), _listToken, mx.id, mx.id, mx.company_name,
+	bal_amt, 0, 0, 0, 0, 0,
+	cgroup_name, cgroup_code, concat(full_name, ' ', company_no), concat(company_name, company_no)
+from 
+	( select buyer_id, bal_amt
+		from dbr_bal_buyer
+		where yyyy_mm = _prev_month(_sdate) and branch_id = _branch
+	) as last_mbal 
+	inner join dbr_company as mx on mx.id = last_mbal.buyer_id
+	inner join dbr_cgroup as cgr on cgroup_id = cgr.id
+where cgr.cgroup_code between _sbet1 and _ebet1
+	and mx.company_name between _sbet2 and _ebet2
+	and ( company_class = 'AA' or company_class = 'AB' );
+
+-- 매출/반품 합계 --
+insert into dbt_list_sum
+	( created_on, list_token, h_id, id, c1, 
+		d1, d2, d3, d4, d5, d6, 
+		c2, c3, c4, order_by)
+select unix_timestamp(), _listToken, cmp.id, cmp.id, company_name,
+	0, sum(sales_sum*cast((sales_status+1)/2 as int)), sum(sales_sum*cast(-1*(sales_status-1)/2 as int)), 0, 0, 0,
+	cgroup_name, cgroup_code, concat(full_name, ' ', company_no), concat(company_name, company_no)
+from 
+    ( select id, sales_no, sales_date
+        from dbr_sales
+        where sales_date between _sdate and _edate
+	) as sbhd
+	inner join dbr_sales_bd as sbbd on sbhd.id = sbbd.sales_id
+	inner join dbr_sorder_bd as mnbd on mnbd.id = sbbd.sorder_bd_id
+	inner join dbr_sorder as mnhd on mnhd.id = mnbd.sorder_id
+	inner join dbr_item as itm on mnbd.item_id = itm.id
+	inner join dbr_deal_type as deal on deal.id = mnhd.deal_type_id
+    inner join ( select cmp.id, company_name, full_name, company_no, cgroup_name, cgroup_code
+        from dbr_company as cmp
+            inner join dbr_cgroup as cgr on cgroup_id = cgr.id
+        where cgr.cgroup_code between _sbet1 and _ebet1
+			and cmp.company_name between _sbet2 and _ebet2
+			and ( company_class = 'AA' or company_class = 'AB' )
+	) as cmp on cmp.id = mnhd.buyer_id 
+where branch_id = _branch
+group by cmp.id;
+
+-- 입금/입금할인 합계 --
+insert into dbt_list_sum
+	( created_on, list_token, h_id, id, c1, 
+		d1, d2, d3, d4, d5, d6, 
+		c2, c3, c4, order_by)
+select unix_timestamp(), _listToken, cmp.id, cmp.id, company_name,
+	0, 0, 0, sum(slip_amt*cast((collect_status+1)/2 as int)), 
+    sum(slip_amt*cast(-1*(collect_status-1)/2 as int)), 0,
+	cgroup_name, cgroup_code, concat(full_name, ' ', company_no), concat(company_name, company_no)
+from 
+    ( select id, acc_date, acc_slip_no, deal_type_id,
+        bill_column1, bill_type, slip_amt, company_id
+        from dbr_acc_slip
+        where ( deal_type_id = 21 or deal_type_id = 23 ) -- 입금과 입금할인만
+            and acc_date between _sdate and _edate
+	        and branch_id = _branch
+    ) as mnhd 
+	inner join dbr_deal_type as deal on deal.id = mnhd.deal_type_id
+    inner join ( select cmp.id, company_name, full_name, company_no, cgroup_name, cgroup_code
+        from dbr_company as cmp
+            inner join dbr_cgroup as cgr on cgroup_id = cgr.id
+        where cgr.cgroup_code between _sbet1 and _ebet1
+			and cmp.company_name between _sbet2 and _ebet2
+			and ( company_class = 'AA' or company_class = 'AB' )
+	) as cmp on cmp.id = mnhd.company_id 
+group by cmp.id;
+
+-- dbt_list_type1 으로 집계 --
+insert into dbt_list_type1
+	( created_on, list_token, h_id, id, c1, 
+		d1, d2, d3, d4, d5, d6, 
+		c2, c3, c4, order_by)
+select min(unix_timestamp()), min(_listToken), min(id), min(id), min(c1),
+	sum(d1),
+	sum(d2),
+	sum(d3),
+	sum(d4),
+	sum(d5),
+	sum(d1) + sum(d2) + sum(d3) - sum(d4) - sum(d5),
+	min(c2), min(c3), min(c4), min(order_by)
+from dbt_list_sum as mx
+where list_token = _listToken
+group by mx.id
+having min(mx.id) is not null
+order by order_by asc;
+
+END;
+//
+DELIMITER ; 

+ 123 - 0
function-in-db/procedures/sales/pl1_sales_ledger_detail.sql

@@ -0,0 +1,123 @@
+truncate table dbt_list_type1;
+truncate table dbt_list_sum;
+drop procedure if exists pl1_sales_ledger_detail;
+
+DELIMITER //
+create procedure pl1_sales_ledger_detail( _listToken varchar(21), _sdate varchar(8), _edate varchar(8), 
+_s1 varchar(32), _e1 varchar(32), _s2 varchar(32), _e2 varchar(32), 
+_s3 varchar(32), _e3 varchar(32), _s4 varchar(32), _e4 varchar(32), 
+_where varchar(386), _having varchar(386), _orderby varchar(64), 
+_branch int, _storage int, _target int)
+
+BEGIN
+
+Declare _sbal_date varchar(8);
+Declare _ebal_date varchar(8);
+
+Declare _first_bal decimal(20,4);
+Declare _first_bal_caption varchar(20);
+
+Declare _first_id int;
+Declare _last_id int;
+
+Declare _line_id int;
+Declare _line_in decimal(20,4) default "0.0000";
+Declare _line_out decimal(20,4) default "0.0000";
+Declare _line_bal decimal(20,4) default "0.0000";
+Declare _in_sum decimal(20,4) default "0.0000";
+Declare _out_sum decimal(20,4) default "0.0000";
+
+Declare _company_name varchar(64);
+Declare _full_name varchar(96);
+
+Declare _not_found boolean;
+Declare _line_cur cursor for 
+    select t_id, d3, d4 from dbt_list_type1 where t_id > _first_id and t_id <= _last_id
+	order by c1, c2, c3 asc;
+Declare continue handler for 
+        not found set _not_found = true;
+
+if _is_first_date(_sdate) then
+	set _sbal_date = '19000101';
+	set _ebal_date = '19000101';
+else
+	set _sbal_date = _sdate;
+	set _ebal_date = _edate;
+end if;
+
+-- 전월잔액 
+select ifnull(last_mbal.bal_amt,0) , '이월잔액' into _first_bal, _first_bal_caption
+from
+	dbr_company as mv
+	left join
+	( select buyer_id, bal_amt
+	from dbr_bal_buyer
+	where yyyy_mm = _prev_month(_sdate) and branch_id = _branch
+	) as last_mbal on mv.id = last_mbal.buyer_id
+where mv.id = _target;
+
+insert into dbt_list_type1 ( created_on, list_token, c4, d5 )
+	values ( unix_timestamp(), _listToken, _first_bal_caption, _first_bal);
+
+-- insert for sales
+insert into dbt_list_type1
+	( created_on, list_token, c1, c2, c3, c4, c5, d1, d2, d3)
+select unix_timestamp(), _listToken, concat( sales_date,'-', deal_code, '*', sbbd.seq_no ), 
+	concat( sales_no, '*', sbbd.seq_no ), deal_code, 
+    concat( item_code, ' / ', item_name, ' / ', sub_name ), '', -- bill_type 은 비운다.
+ 	sales_qty, sorder_prc, sales_sum*sales_status
+from ( select id, sales_no, sales_date
+	from dbr_sales
+    where sales_date between _sdate and _edate 
+	) as sbhd
+	inner join dbr_sales_bd as sbbd on sbhd.id = sbbd.sales_id
+	inner join dbr_sorder_bd as mnbd on mnbd.id = sbbd.sorder_bd_id
+	inner join dbr_sorder as mnhd on mnhd.id = mnbd.sorder_id
+	inner join dbr_item as itm on mnbd.item_id = itm.id
+	inner join dbr_deal_type as deal on deal.id = mnhd.deal_type_id
+where branch_id = _branch and mnhd.buyer_id = _target;
+
+-- 출금내역
+insert into dbt_list_type1
+	( created_on, list_token, c1, c2, c3, c4, c5, d4)
+select unix_timestamp(), _listToken, concat( acc_date,'-', deal_code ), 
+	acc_slip_no, deal_code, 
+	bill_column1, bill_type, -1*slip_amt*sales_status
+from 
+    ( select id, acc_date, acc_slip_no, deal_type_id,
+        bill_column1, bill_type, slip_amt
+        from dbr_acc_slip
+        where ( deal_type_id = 21 or deal_type_id = 23 ) -- 입금과 입금할인만
+            and acc_date between _sdate and _edate 	
+	        and branch_id = _branch and company_id = _target
+    ) as mnhd  
+inner join dbr_deal_type as deal on deal.id = deal_type_id;
+
+-- -- get id range for current ledger
+select min(t_id), max(t_id) into  _first_id, _last_id from dbt_list_type1 where list_token = _listToken;
+
+-- compute line_bal
+set _line_bal = _first_bal;
+open _line_cur;
+	loop1: loop
+		fetch _line_cur into _line_id, _line_in, _line_out;
+		if _not_found then leave loop1; end if;
+
+		set _in_sum = _in_sum + ifnull(_line_in,0);
+		set _out_sum = _out_sum + ifnull(_line_out,0);
+		set _line_bal = ifnull(_line_bal,0) + ifnull(_line_in,0) - ifnull(_line_out,0);
+		update dbt_list_type1 set d5 = _line_bal where t_id = _line_id;
+	end loop loop1;
+close _line_cur;
+
+-- write list_sum
+select company_name, concat(full_name, ' ', company_no) 
+	into _company_name, _full_name from dbr_company where id = _target;
+insert into dbt_list_sum
+	( created_on, list_token, c1, c2, c3, c4, d1, d2, d3, d4)
+	values (unix_timestamp(), _listToken, _company_name, _full_name, _sdate, _edate, 
+	_first_bal, _in_sum, _out_sum, _line_bal);
+
+END;
+//
+DELIMITER ;

+ 136 - 0
function-in-db/procedures/stock-io/lt1-stock-io-sum-bal.sql

@@ -0,0 +1,136 @@
+truncate table dbt_list_type1;
+
+drop procedure if exists lt1_stock_io_sum_bal;
+DELIMITER //
+create procedure lt1_stock_io_sum_bal( _listToken varchar(21), _sdate varchar(8), _edate varchar(8), 
+_s1 varchar(32), _e1 varchar(32), _s2 varchar(32), _e2 varchar(32), 
+_s3 varchar(32), _e3 varchar(32), _s4 varchar(32), _e4 varchar(32), 
+_where varchar(386), _having varchar(386), _orderby varchar(64), 
+_branch int, _storage int)
+
+BEGIN
+
+Declare _sbal_date varchar(8);
+Declare _ebal_date varchar(8);
+
+Declare _sbet1 varchar(64);
+Declare _ebet1 varchar(64);
+Declare _sbet2 varchar(64);
+Declare _ebet2 varchar(64);
+Declare _sbet3 varchar(64);
+Declare _ebet3 varchar(64);
+
+
+if _is_first_date(_sdate) then
+	set _sbal_date = '19000101';
+	set _ebal_date = '19000101';
+else
+	set _sbal_date = _sdate;
+	set _ebal_date = _edate;
+end if;
+
+if _s1 != '' and _e1 != '' then
+	set _sbet1 = _s1;
+	set _ebet1 = _e1;
+else
+	set _sbet1 = '!';
+	set _ebet1 = '힣';
+end if;
+
+if _s2 != '' and _e2 != '' then
+	set _sbet2 = _s2;
+	set _ebet2 = _e2;
+else
+	set _sbet2 = '!';
+	set _ebet2 = '힣';
+end if;
+
+
+if _s3 != '' and _e3 != '' then
+	set _sbet3 = _s3;
+	set _ebet3 = _e3;
+else
+	set _sbet3 = '!';
+	set _ebet3 = '힣';
+end if;
+
+-- 전월 재고 --
+-- bad_qty 는 Delta 만 보여줌.
+insert into dbt_list_sum
+	( created_on, list_token, h_id, id, c1, c2, c3,
+     d1, d2, d3, d4, d5,
+     c4, c5, order_by )
+
+select unix_timestamp(), _listToken, mx.id, mx.id, item_code, item_name, sub_name,
+     bal_qty, 0, 0, 0, 0,
+   	igroup_name, igroup_code, item_code
+
+from ( select id, item_code, item_name, sub_name, igroup_id
+		from dbr_item as itm
+		where item_code between _sbet2 and _ebet2
+            and isnt_stkio = '0' and is_material = '0'
+	) as mx
+    inner join ( select item_id, bal_qty  
+		from dbr_bal_item
+		where yyyy_mm = _prev_month(_sdate) and storage_id = _storage
+	) as bal on mx.id = bal.item_id
+
+    inner join ( select id, igroup_code, igroup_name
+		from dbr_igroup
+		where igroup_code between _sbet1 and _ebet1
+	) as igr on mx.igroup_id = igr.id
+
+order by item_code asc;
+
+-- 당월 수불 합계 --
+insert into dbt_list_sum
+	( created_on, list_token, h_id, id, c1, c2, c3,
+     d1, d2, d3,
+     d4, d5,
+     c4, c5, order_by )
+
+select unix_timestamp(), _listToken, mx.id, mx.id, item_code, item_name, sub_name,
+     0, sum(io_qty*cast((stock_status+1)/2 as int)), sum(io_qty*cast(-1*(stock_status-1)/2 as int)),
+     0, sum(io_qty*badstk_status),
+   	igroup_name, igroup_code, item_code
+
+from ( select id, item_code, item_name, sub_name, igroup_id
+		from dbr_item as itm
+		where item_code between _sbet2 and _ebet2
+            and isnt_stkio = '0' and is_material = '0'
+	) as mx
+    inner join ( select item_id, io_qty, stock_status, badstk_status
+		from dbr_stock_io  as stk
+            inner join dbr_deal_type as deal on deal.id = stk.deal_type_id
+		where io_date between _sdate and _edate
+			and storage_id = _storage
+	) as stk on mx.id = stk.item_id
+
+    inner join ( select id, igroup_code, igroup_name
+		from dbr_igroup
+		where igroup_code between _sbet1 and _ebet1
+	) as igr on mx.igroup_id = igr.id
+group by stk.item_id
+order by item_code asc;
+
+-- dbt_list_type1 으로 집계 --
+insert into dbt_list_type1
+	( created_on, list_token, h_id, id, c1, c2, c3,
+		d1, d2, d3, d4, d5,
+		c4, c5, order_by)
+select min(unix_timestamp()), min(_listToken), min(id), min(id), min(c1), min(c2), min(c3),
+	sum(d1),
+	sum(d2),
+	sum(d3),
+    sum(d1) + sum(d2) - sum(d3),
+	sum(d5),
+	min(c4), min(c5), min(order_by)
+from dbt_list_sum as mx
+where list_token = _listToken
+group by mx.id
+having min(mx.id) is not null
+order by order_by asc;
+
+END;
+//
+DELIMITER ;

+ 122 - 0
function-in-db/procedures/stock-io/pl1_stock_io_ledger_detail.sql

@@ -0,0 +1,122 @@
+truncate table dbt_list_type1;
+truncate table dbt_list_sum;
+drop procedure if exists pl1_stock_io_ledger_detail;
+
+DELIMITER //
+create procedure pl1_stock_io_ledger_detail( _listToken varchar(21), _sdate varchar(8), _edate varchar(8), 
+_s1 varchar(32), _e1 varchar(32), _s2 varchar(32), _e2 varchar(32), 
+_s3 varchar(32), _e3 varchar(32), _s4 varchar(32), _e4 varchar(32), 
+_where varchar(386), _having varchar(386), _orderby varchar(64), 
+_branch int, _storage int, _target int)
+
+BEGIN
+
+Declare _sbal_date varchar(8);
+Declare _ebal_date varchar(8);
+
+Declare _first_bal decimal(20,4);
+Declare _first_bad_bal decimal(20,4);
+Declare _first_bal_caption varchar(20);
+
+-- Declare _first_id int;
+-- Declare _last_id int;
+
+Declare _line_id int;
+Declare _line_badstk_status varchar(64);
+Declare _line_in decimal(20,4) default "0.0000";
+Declare _line_out decimal(20,4) default "0.0000";
+Declare _line_bal decimal(20,4) default "0.0000";
+Declare _line_bad_bal decimal(20,4) default "0.0000";
+Declare _in_sum decimal(20,4) default "0.0000";
+Declare _out_sum decimal(20,4) default "0.0000";
+
+Declare _company_name varchar(64);
+
+Declare _item_code varchar(21);
+Declare _item_sub_name varchar(128);
+
+Declare _not_found boolean;
+Declare _line_cur cursor for -- c5:badstk_status
+    select t_id, c5, d2, d3 from dbt_list_type1 where list_token = _listToken 
+	order by order_by asc;
+Declare continue handler for 
+        not found set _not_found = true;
+
+if _is_first_date(_sdate) then
+	set _sbal_date = '19000101';
+	set _ebal_date = '19000101';
+else
+	set _sbal_date = _sdate;
+	set _ebal_date = _edate;
+end if;
+
+-- insert for first_bal
+select ifnull(last_mbal.bal_qty,0) + ifnull(stk_bal.io_qty,0) , 
+		ifnull(last_mbal.bad_bal_qty,0) + ifnull(stk_bal.bad_io_qty,0) ,'이월재고' 
+	into _first_bal, _first_bad_bal, _first_bal_caption
+	from
+		dbr_item as mxv
+		left join
+		( select item_id, bal_qty, bad_bal_qty
+		from dbr_bal_item
+		where yyyy_mm = _prev_month(_sdate) and storage_id = _storage
+		) as last_mbal
+		on mxv.id = last_mbal.item_id
+
+		left join
+		( select stk.item_id, sum(io_qty*stock_status) AS io_qty, sum(io_qty*badstk_status) AS bad_io_qty
+		from dbr_stock_io  as stk
+			inner join dbr_deal_type as deal on deal.id = stk.deal_type_id
+		where io_date between _first_date(_sbal_date) and _prev_date(_ebal_date)
+			and storage_id = _storage
+		group by stk.item_id
+		) as stk_bal
+		on mxv.id = stk_bal.item_id
+
+where mxv.id = _target;
+
+insert into dbt_list_type1 ( created_on, list_token, c3, d4, d5, order_by)
+	values ( unix_timestamp(), _listToken, _first_bal_caption, _first_bal, _first_bad_bal, '19000101');
+
+-- insert for stock_io
+insert into dbt_list_type1
+	( created_on, list_token, c1, c2, c3, c4, c5, d1, d2, d3, order_by)
+select unix_timestamp(), _listToken, io_date, deal_code, concat(slip_no,' / ', stk.seq_no )slip_no, company_name, badstk_status,
+		io_prc, stk.io_qty*cast((stock_status+1)/2 as int), stk.io_qty*cast(-1*(stock_status-1)/2 as int),
+		concat( io_date, '-', -1*stock_status,'-', slip_no, '-', seq_no)
+from dbr_stock_io  as stk
+	inner join dbr_company as cmp on cmp.id = stk.company_id
+	inner join dbr_deal_type as deal on deal.id = stk.deal_type_id
+where io_date between _sdate and _edate and storage_id = _storage and stk.item_id = _target;
+
+-- compute line_bal
+set _line_bal = _first_bal;
+set _line_bad_bal = _first_bad_bal;
+open _line_cur;
+	loop1: loop
+		fetch _line_cur into _line_id, _line_badstk_status, _line_in, _line_out;
+		if _not_found then leave loop1; end if;
+
+		set _in_sum = _in_sum + ifnull(_line_in,0);
+		set _out_sum = _out_sum + ifnull(_line_out,0);
+
+		if _line_badstk_status = '0' then
+			set _line_bal = ifnull(_line_bal,0) + ifnull(_line_in,0) - ifnull(_line_out,0);
+		else 
+			set _line_bad_bal = ifnull(_line_bad_bal,0) + ifnull(_line_in,0) - ifnull(_line_out,0);
+		end if;
+
+		update dbt_list_type1 set d4 = _line_bal, d5 = _line_bad_bal  where t_id = _line_id;
+	end loop loop1;
+close _line_cur;
+
+-- write list_sum
+select item_code, concat(item_name,' / ',sub_name ) into _item_code, _item_sub_name from dbr_item where id = _target;
+insert into dbt_list_sum
+	( created_on, list_token, c1, c2, c3, c4, d1, d2, d3, d4)
+	values (unix_timestamp(), _listToken, _item_code, _item_sub_name, _sdate, _edate, 
+	_first_bal, _in_sum, _out_sum, _line_bal);
+
+END;
+//
+DELIMITER ;

+ 94 - 0
function-in-db/procedures/stock-io/stock_io_act.sql

@@ -0,0 +1,94 @@
+-- truncate table dbr_stock_io;
+drop procedure if exists stock_io_act;
+
+DELIMITER //
+create procedure stock_io_act( _slip_code varchar(6), _target int, _act int)
+
+BEGIN
+
+Declare _created_on bigint ;
+Declare _updated_on bigint ;
+Declare _slip_bd_id int ;
+Declare _slip_no varchar(21) ;
+Declare _seq_no tinyint;
+Declare _io_date char(8);
+Declare _deal_type_id int;
+Declare _storage_id int;
+Declare _company_id int;
+Declare _vat_rate_id int;
+Declare _item_id int;
+Declare _io_qty decimal(20,4);
+Declare _io_prc decimal(20,4);
+Declare _io_supply decimal(20,4);
+Declare _io_vat decimal(20,4);
+Declare _io_sum decimal(20,4);
+
+if _slip_code = 'purch' then
+	select pubd.id, purch_no, pubd.seq_no, purch_date, deal_type_id, 
+		storage_id, supplier_id, vat_rate_id, item_id, purch_qty,
+		porder_prc, purch_supply, purch_vat, purch_sum
+	into _slip_bd_id, _slip_no, _seq_no, _io_date, _deal_type_id,
+		_storage_id, _company_id, _vat_rate_id, _item_id, _io_qty,
+		_io_prc, _io_supply, _io_vat, _io_sum
+	from dbr_porder  as pohd
+		inner join dbr_porder_bd as pobd on pohd.id = pobd.porder_id
+		inner join dbr_purch_bd as pubd on pobd.id = pubd.porder_bd_id
+		inner join dbr_purch as puhd on puhd.id = pubd.purch_id
+	where pubd.id = _target;
+
+elseif _slip_code = 'sales' then
+	select sabd.id, sales_no, sabd.seq_no, sales_date, deal_type_id, 
+		storage_id, buyer_id, vat_rate_id, item_id, sales_qty,
+		sorder_prc, sales_supply, sales_vat, sales_sum
+	into _slip_bd_id, _slip_no, _seq_no, _io_date, _deal_type_id,
+		_storage_id, _company_id, _vat_rate_id, _item_id, _io_qty,
+		_io_prc, _io_supply, _io_vat, _io_sum
+	from dbr_sorder  as sohd
+		inner join dbr_sorder_bd as sobd on sohd.id = sobd.sorder_id
+		inner join dbr_sales_bd as sabd on sobd.id = sabd.sorder_bd_id
+		inner join dbr_sales as sahd on sahd.id = sabd.sales_id
+	where sabd.id = _target;
+
+elseif _slip_code = 'genio' then
+	select gnhd.id, genio_no, gnbd.seq_no, genio_date, deal_type_id, 
+		storage_id, company_id, vat_rate_id, item_id, genio_qty,
+		genio_prc, genio_supply, genio_vat, genio_sum
+	into _slip_bd_id, _slip_no, _seq_no, _io_date, _deal_type_id,
+		_storage_id, _company_id, _vat_rate_id, _item_id, _io_qty,
+		_io_prc, _io_supply, _io_vat, _io_sum
+	from dbr_genio  as gnhd
+		inner join dbr_genio_bd as gnbd on gnhd.id = gnbd.genio_id
+	where gnbd.id = _target;
+end if;
+
+-- act for stock_io
+if _act = 0 then 
+	insert into dbr_stock_io
+		( created_on, slip_code, slip_bd_id, slip_no, seq_no, io_date, 
+			deal_type_id, storage_id, company_id, vat_rate_id, item_id, 
+			io_qty, io_prc, io_supply, io_vat, io_sum )
+	values ( unix_timestamp(), _slip_code, _slip_bd_id, _slip_no, _seq_no, _io_date, 
+			_deal_type_id, _storage_id, _company_id, _vat_rate_id, _item_id, 
+			_io_qty, _io_prc, _io_supply, _io_vat, _io_sum );
+
+elseif _act = 1 then
+	update dbr_stock_io
+	set updated_on=unix_timestamp(),
+		slip_no=_slip_no, seq_no=_seq_no, io_date=_io_date, 
+		deal_type_id=_deal_type_id, storage_id=_storage_id, company_id=_company_id, 
+		vat_rate_id=_vat_rate_id, item_id=_item_id, 
+		io_qty=_io_qty, io_prc=_io_prc, io_supply=_io_supply, 
+		io_vat=_io_vat, io_sum= _io_sum
+	where  slip_code=_slip_code and slip_bd_id= _target;
+
+elseif _act = -1 then
+	delete from dbr_stock_io
+	where  slip_code=_slip_code and slip_bd_id= _target;
+
+end if;
+
+END;
+//
+DELIMITER ;
+
+-- call stock_io_act('purch', 1, 1);

+ 75 - 0
function-in-db/procedures/stock-io/stock_io_sync.sql

@@ -0,0 +1,75 @@
+
+drop procedure if exists stock_io_sync;
+
+DELIMITER //
+create procedure stock_io_sync( _sdate varchar(8), _edate varchar(8) )
+
+BEGIN
+
+Declare _line_id int;
+
+Declare _not_found boolean;
+
+Declare _line_cur_sales cursor for 
+    select sabd.id 
+	from dbr_sorder  as sohd
+		inner join dbr_sorder_bd as sobd on sohd.id = sobd.sorder_id
+		inner join dbr_sales_bd as sabd on sobd.id = sabd.sorder_bd_id
+		inner join dbr_sales as sahd on sahd.id = sabd.sales_id
+	where sales_date between _sdate and _edate 
+	order by sales_date asc, sabd.id asc;
+
+Declare _line_cur_purch cursor for 
+    select pubd.id 
+	from dbr_porder  as pohd
+		inner join dbr_porder_bd as pobd on pohd.id = pobd.porder_id
+		inner join dbr_purch_bd as pubd on pobd.id = pubd.porder_bd_id
+		inner join dbr_purch as puhd on puhd.id = pubd.purch_id
+	where purch_date between _sdate and _edate 
+	order by purch_date asc, pubd.id asc;
+
+Declare _line_cur_genio cursor for 
+    select gnbd.id 
+	from dbr_genio  as gnhd
+		inner join dbr_genio_bd as gnbd on gnhd.id = gnbd.genio_id
+	where genio_date between _sdate and _edate 	
+	order by genio_date asc, gnbd.id asc;
+
+Declare continue handler for 
+        not found set _not_found = true;
+
+delete from dbr_stock_io where io_date between _sdate and _edate;
+
+set _not_found = false;  -- 이것이 Multi cursor를 쓰는 핵심이다.
+open _line_cur_sales;
+	loop_sales: loop
+		fetch _line_cur_sales into _line_id;
+		if _not_found then leave loop_sales; end if;
+
+		call stock_io_act('sales', _line_id, 0);
+	end loop loop_sales;
+close _line_cur_sales;
+
+set _not_found = false;  -- 이것이 Multi cursor를 쓰는 핵심이다.
+open _line_cur_purch;
+	loop_purch: loop
+		fetch _line_cur_purch into _line_id;
+		if _not_found then leave loop_purch; end if;
+
+		call stock_io_act('purch', _line_id, 0);
+	end loop loop_purch;
+close _line_cur_purch;
+
+set _not_found = false;  -- 이것이 Multi cursor를 쓰는 핵심이다.
+open _line_cur_genio;
+	loop_genio: loop
+		fetch _line_cur_genio into _line_id;
+		if _not_found then leave loop_genio; end if;
+
+		call stock_io_act('genio', _line_id, 0);
+	end loop loop_genio;
+close _line_cur_genio;
+
+END;
+//
+DELIMITER ;

+ 16 - 0
function-in-db/triggers/company_after_insert.sql-사용않음-재활용용

@@ -0,0 +1,16 @@
+drop trigger if exists company_after_insert;
+DELIMITER // 
+create trigger company_after_insert after insert on dbr_company
+    for each row begin
+        if new.mobile_no != '' then
+            insert into dbr_item_thm 
+                ( id, created_on, updated_on, 
+                  member_buyer_id, seq_no, sort, contact_name, mobile_no
+                ) 
+            value 
+                ( NULL, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 
+                    new.id, 0, '0', new.company_name, new.mobile_no
+                ) ;
+        end if;
+    end//
+DELIMITER ;

+ 7 - 0
function-in-db/triggers/credit_after_insert.sql

@@ -0,0 +1,7 @@
+drop trigger if exists credit_after_insert;
+DELIMITER // 
+create trigger credit_after_insert after insert on dbr_credit
+    for each row begin
+        call credit_bd_act('credit', new.id, 0);
+    end//
+DELIMITER ;

+ 6 - 0
function-in-db/triggers/credit_bd_insert.sql_확인해서다시구현요

@@ -0,0 +1,6 @@
+DELIMITER // 
+CREATE TRIGGER credit_bd_insert AFTER INSERT ON dbr_credit_bd
+    FOR EACH ROW BEGIN
+        UPDATE dbr_company SET curr_credit_bal = new.bal_amt WHERE id = new.buyer_id;
+    END//
+DELIMITER ;

+ 7 - 0
function-in-db/triggers/credit_before_delete.sql

@@ -0,0 +1,7 @@
+drop trigger if exists credit_before_delete;
+DELIMITER // 
+create trigger credit_before_delete after delete on dbr_credit
+    for each row begin
+        delete from dbr_credit_bd where credit_id = old.id;
+    END//
+DELIMITER ;

+ 7 - 0
function-in-db/triggers/genio_bd_after_insert.sql

@@ -0,0 +1,7 @@
+drop trigger if exists genio_bd_after_insert;
+DELIMITER // 
+create trigger genio_bd_after_insert after insert on dbr_genio_bd
+    for each row begin
+        call stock_io_act('genio', new.id, 0);
+    end//
+DELIMITER ;

+ 7 - 0
function-in-db/triggers/genio_bd_after_update.sql

@@ -0,0 +1,7 @@
+drop trigger if exists genio_bd_after_update;
+DELIMITER // 
+create trigger genio_bd_after_update after update on dbr_genio_bd
+    for each row begin
+        call stock_io_act('genio', new.id, 1);
+    end//
+DELIMITER ;

+ 7 - 0
function-in-db/triggers/genio_before_delete.sql

@@ -0,0 +1,7 @@
+drop trigger if exists genio_before_delete;
+DELIMITER // 
+create trigger genio_before_delete after delete on dbr_genio
+    for each row begin
+        delete from dbr_genio_bd where genio_id = old.id;
+    END//
+DELIMITER ;

+ 10 - 0
function-in-db/triggers/item_after_insert.sql

@@ -0,0 +1,10 @@
+drop trigger if exists item_after_insert;
+DELIMITER // 
+create trigger item_after_insert after insert on dbr_item
+    for each row begin
+        replace into dbr_item_thm ( id, created_on, upload_batch ) 
+            value (new.id, unix_timestamp(), new.upload_batch ) ;
+        replace into pro_item_revsum (id, created_on, updated_on ) value (new.id, unix_timestamp(), unix_timestamp()) ;
+    end
+//
+DELIMITER ;

+ 9 - 0
function-in-db/triggers/item_before_delete.sql

@@ -0,0 +1,9 @@
+drop trigger if exists item_before_delete;
+DELIMITER // 
+create trigger item_before_delete before delete on dbr_item
+    for each row begin
+        delete from dbr_item_thm where id = old.id;
+        delete from pro_item_revsum where id = old.id;
+    end
+//
+DELIMITER ;

+ 19 - 0
function-in-db/triggers/item_review_after_insert.sql

@@ -0,0 +1,19 @@
+-- dynamic sql doesn't work in store procedure or trigger.
+drop trigger if exists item_review_after_insert;
+DELIMITER // 
+create trigger item_review_after_insert after insert on pro_item_review
+    for each row begin
+        if new.rating_score = 1 then
+            update pro_item_revsum set score1_cnt=score1_cnt+1  where id = new.item_id;
+        elseif new.rating_score = 2 then
+            update pro_item_revsum set score2_cnt=score2_cnt+1  where id = new.item_id;
+        elseif new.rating_score = 3 then
+            update pro_item_revsum set score3_cnt=score3_cnt+1  where id = new.item_id;
+        elseif new.rating_score = 4 then
+            update pro_item_revsum set score4_cnt=score4_cnt+1  where id = new.item_id;
+        elseif new.rating_score = 5 then
+            update pro_item_revsum set score5_cnt=score5_cnt+1  where id = new.item_id;
+        end if;
+    end
+//
+DELIMITER ;

+ 15 - 0
function-in-db/triggers/item_review_bd_after_insert.sql

@@ -0,0 +1,15 @@
+-- dynamic sql doesn't work in store procedure or trigger.
+drop trigger if exists item_review_bd_after_insert;
+DELIMITER // 
+create trigger item_review_bd_after_insert after insert on pro_item_review_bd
+    for each row begin
+        if new.score = 1 then
+            update pro_item_revpro set score1_cnt=score1_cnt+1  where item_id = new.item_id and revindex_id = new.revindex_id;
+        elseif new.score = 2 then
+            update pro_item_revpro set score2_cnt=score2_cnt+1  where item_id = new.item_id and revindex_id = new.revindex_id;
+        elseif new.score = 3 then
+            update pro_item_revpro set score3_cnt=score3_cnt+1  where item_id = new.item_id and revindex_id = new.revindex_id;
+        end if;
+    end
+//
+DELIMITER ;

+ 7 - 0
function-in-db/triggers/media_before_delete.sql

@@ -0,0 +1,7 @@
+drop trigger if exists media_before_delete;
+DELIMITER // 
+create trigger media_before_delete after delete on dbr_media
+    for each row begin
+        delete from dbr_media_bd where media_id = old.id;
+    END//
+DELIMITER ;

+ 7 - 0
function-in-db/triggers/member_before_delete.sql

@@ -0,0 +1,7 @@
+drop trigger if exists member_before_delete;
+DELIMITER // 
+create trigger member_before_delete before delete on pro_member
+    for each row begin
+        delete from pro_member_ext where id = old.id;
+    end//
+DELIMITER ;

+ 7 - 0
function-in-db/triggers/porder_bd_before_delete.sql

@@ -0,0 +1,7 @@
+drop trigger if exists porder_bd_before_delete;
+DELIMITER // 
+create trigger porder_bd_before_delete before delete on dbr_porder_bd
+    for each row begin
+        delete from dbr_purch_bd where porder_bd_id = old.id;
+    END//
+DELIMITER ;

+ 8 - 0
function-in-db/triggers/porder_before_delete.sql

@@ -0,0 +1,8 @@
+drop trigger if exists porder_before_delete;
+DELIMITER // 
+create trigger porder_before_delete after delete on dbr_porder
+    for each row begin
+        delete from dbr_porder_bd where porder_id = old.id;
+        delete from dbr_purch where porder_id = old.id;
+    END//
+DELIMITER ;

+ 7 - 0
function-in-db/triggers/pquote_before_delete.sql

@@ -0,0 +1,7 @@
+drop trigger if exists pquote_before_delete;
+DELIMITER // 
+create trigger pquote_before_delete after delete on dbr_pquote
+    for each row begin
+        delete from dbr_pquote_bd where pquote_id = old.id;
+    END//
+DELIMITER ;

+ 7 - 0
function-in-db/triggers/purch_bd_after_insert.sql

@@ -0,0 +1,7 @@
+drop trigger if exists purch_bd_after_insert;
+DELIMITER // 
+create trigger purch_bd_after_insert after insert on dbr_purch_bd
+    for each row begin
+        call stock_io_act('purch', new.id, 0);
+    end//
+DELIMITER ;

+ 7 - 0
function-in-db/triggers/purch_bd_after_update.sql

@@ -0,0 +1,7 @@
+drop trigger if exists purch_bd_after_update;
+DELIMITER // 
+create trigger purch_bd_after_update after update on dbr_purch_bd
+    for each row begin
+        call stock_io_act('purch', old.id, 1);
+    end//
+DELIMITER ;

+ 7 - 0
function-in-db/triggers/purch_bd_before_delete.sql

@@ -0,0 +1,7 @@
+drop trigger if exists purch_bd_before_delete;
+DELIMITER // 
+create trigger purch_bd_before_delete before delete on dbr_purch_bd
+    for each row begin
+        call stock_io_act('purch', old.id, -1);
+    end//
+DELIMITER ;

+ 7 - 0
function-in-db/triggers/purch_before_delete.sql

@@ -0,0 +1,7 @@
+drop trigger if exists purch_before_delete;
+DELIMITER // 
+create trigger purch_before_delete after delete on dbr_purch
+    for each row begin
+        delete from dbr_purch_bd where purch_id = old.id;
+    END//
+DELIMITER ;

+ 7 - 0
function-in-db/triggers/reward_after_insert.sql

@@ -0,0 +1,7 @@
+drop trigger if exists reward_after_insert;
+DELIMITER // 
+create trigger reward_after_insert after insert on dbr_reward
+    for each row begin
+        call reward_bd_act('reward', new.id, 0);
+    end//
+DELIMITER ;

+ 7 - 0
function-in-db/triggers/sales_bd_after_insert.sql

@@ -0,0 +1,7 @@
+drop trigger if exists sales_bd_after_insert;
+DELIMITER // 
+create trigger sales_bd_after_insert after insert on dbr_sales_bd
+    for each row begin
+        call stock_io_act('sales', new.id, 0);
+    end//
+DELIMITER ;

+ 7 - 0
function-in-db/triggers/sales_bd_after_update.sql

@@ -0,0 +1,7 @@
+drop trigger if exists sales_bd_after_update;
+DELIMITER // 
+create trigger sales_bd_after_update after update on dbr_sales_bd
+    for each row begin
+        call stock_io_act('sales', new.id, 1);
+    end//
+DELIMITER ;

+ 7 - 0
function-in-db/triggers/sales_bd_before_delete.sql

@@ -0,0 +1,7 @@
+drop trigger if exists sales_bd_before_delete;
+DELIMITER // 
+create trigger sales_bd_before_delete before delete on dbr_sales_bd
+    for each row begin
+        call stock_io_act('sales', old.id, -1);
+    end//
+DELIMITER ;

+ 7 - 0
function-in-db/triggers/sales_before_delete.sql

@@ -0,0 +1,7 @@
+drop trigger if exists sales_before_delete;
+DELIMITER // 
+create trigger sales_before_delete after delete on dbr_sales
+    for each row begin
+        delete from dbr_sales_bd where sales_id = old.id;
+    END//
+DELIMITER ;

+ 11 - 0
function-in-db/triggers/sorder_after_insert-already-.sql

@@ -0,0 +1,11 @@
+drop trigger if exists sorder_after_insert;
+DELIMITER // 
+create trigger sorder_after_insert after insert on dbr_sorder
+    for each row begin
+        if new.reward_amt <> '0.0000' then
+            call reward_bd_act('sorder', new.id, 0);
+        end if; 
+    end //
+DELIMITER ;
+
+2022/08/03 05:00:35 [Log]: jfhgkeytg @  DB error in Adding Id of 0 in dbr_sorder Error 1442: Can't update table 'dbr_sorder' in stored function/trigger because it is already used by statement which invoked this stored function/trigger 

+ 10 - 0
function-in-db/triggers/sorder_after_insert.sql

@@ -0,0 +1,10 @@
+drop trigger if exists sorder_after_insert;
+DELIMITER // 
+create trigger sorder_after_insert after insert on dbr_sorder
+    for each row begin
+        insert into pro_sorder_shop (id) value (new.id) ;
+        if new.reward_amt <> '0.0000' then
+            call reward_bd_act('sorder', new.id, 0);
+        end if; 
+    end //
+DELIMITER ;

+ 7 - 0
function-in-db/triggers/sorder_bd_after_insert.sql

@@ -0,0 +1,7 @@
+drop trigger if exists sorder_bd_after_insert;
+DELIMITER // 
+create trigger sorder_bd_after_insert after insert on dbr_sorder_bd
+    for each row begin
+        call credit_bd_act('sordbd', new.id, 0);
+    end//
+DELIMITER ;

+ 7 - 0
function-in-db/triggers/sorder_bd_after_update.sql

@@ -0,0 +1,7 @@
+drop trigger if exists sorder_bd_after_update;
+DELIMITER // 
+create trigger sorder_bd_after_update after update on dbr_sorder_bd
+    for each row begin
+        call credit_bd_act('sordbd', new.id, 1);
+    end//
+DELIMITER ;

+ 8 - 0
function-in-db/triggers/sorder_bd_before_delete.sql

@@ -0,0 +1,8 @@
+drop trigger if exists sorder_bd_before_delete;
+DELIMITER // 
+create trigger sorder_bd_before_delete before delete on dbr_sorder_bd
+    for each row begin
+        delete from dbr_sales_bd where sorder_bd_id = old.id;
+        call credit_bd_act('sordbd', old.id, -1);
+    END//
+DELIMITER ;

+ 8 - 0
function-in-db/triggers/sorder_before_delete.sql

@@ -0,0 +1,8 @@
+drop trigger if exists sorder_before_delete;
+DELIMITER // 
+create trigger sorder_before_delete after delete on dbr_sorder
+    for each row begin
+        delete from dbr_sorder_bd where sorder_id = old.id;
+        delete from dbr_sales where sorder_id = old.id;
+    END//
+DELIMITER ;

+ 7 - 0
function-in-db/triggers/users_before_delete.sql

@@ -0,0 +1,7 @@
+drop trigger if exists users_before_delete;
+DELIMITER // 
+create trigger users_before_delete before delete on users
+    for each row begin
+        delete from dbr_user_ext where id = old.id;
+    end//
+DELIMITER ;

+ 10 - 0
function-in-db/views/igroup_item_thm_view.sql

@@ -0,0 +1,10 @@
+create or replace view igroup_item_thm_view as 
+select
+	dbr_item.*, igroup_code, igroup_name,
+	media_id1, media_id2, media_id3, media_id4, media_id5,
+	pc1, pc2, pc3, pc4, pc5, pc6, pc7, pc8, pc9, pc10,   
+	pd1, pd2, pd3, pd4, pd5, pd6, pd7, pd8, pd9, pd10
+from
+	dbr_item
+	inner join dbr_igroup on dbr_item.igroup_id = dbr_igroup.id
+	inner join dbr_item_thm on dbr_item.id = dbr_item_thm.id;

+ 18 - 0
function-in-db/views/item_big_view.sql

@@ -0,0 +1,18 @@
+create or replace view item_big_view as 
+select
+	dbr_item.*, bd_file_url, igroup_code, igroup_name
+from
+	dbr_item
+	inner join dbr_igroup on dbr_igroup.id = dbr_igroup.id
+	left join 
+		( select
+			media_id,
+			bd_file_url
+		from
+			dbr_media_bd
+		where image_type = 'big'
+		) as com
+	on com.media_id = dbr_item.media_id
+
+	ALTER TABLE `dbr_company` CHANGE `certi_img` `certi_img` VARCHAR(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '사업자등록증 사진';
+	ALTER TABLE `dbr_company` CHANGE `company_json` `company_json` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '커스터마이징 내용';

+ 19 - 0
function-in-db/views/item_middle_thm_view.sql

@@ -0,0 +1,19 @@
+create or replace view item_middle_thm_view as 
+select
+	dbr_item.*, bd_file_url,
+	media_id1, media_id2, media_id3, media_id4, media_id5,
+	pc1, pc2, pc3, pc4, pc5, pc6, pc7, pc8, pc9, pc10,   
+	pd1, pd2, pd3, pd4, pd5, pd6, pd7, pd8, pd9, pd10
+from
+	dbr_item
+	inner join dbr_igroup on dbr_igroup.id = dbr_igroup.id
+	inner join dbr_item_thm on dbr_item.id = dbr_item_thm.id
+	left join 
+		( select
+			media_id,
+			bd_file_url
+		from
+			dbr_media_bd
+		where image_type = 'middle'
+		) as com
+	on com.media_id = dbr_item.media_id

+ 14 - 0
function-in-db/views/item_thumb_view.sql

@@ -0,0 +1,14 @@
+create or replace view item_thumb_view as 
+select
+	dbr_item.*, bd_file_url
+from
+	dbr_item
+	left join 
+		( select
+			media_id,
+			bd_file_url
+		from
+			dbr_media_bd
+		where image_type = 'thumb'
+		) as com
+	on com.media_id = dbr_item.media_id

+ 5 - 0
function-in-db/views/post_seo_view.sql

@@ -0,0 +1,5 @@
+create or replace view post_seo_view as 
+select
+	pro_post.*
+from
+	pro_post

+ 4 - 0
table-controls/backup.sql

@@ -0,0 +1,4 @@
+set @table := concat('bak_company', '_', date_format(curdate(), '%y%m%d'),'_',time_format(current_time, '%H%i%s'));
+set @qry1 := concat('create table ',@table, ' select * from dbr_company');
+prepare run_query from @qry1 ;
+execute run_query ;

+ 166 - 0
table-controls/compare.sql

@@ -0,0 +1,166 @@
+SELECT
+	UNIX_TIMESTAMP(),
+	p.str2, p.str0, p.rng0, p.rng2, p.rng3, 
+	p.dec2, p.str4, p.str3, p.rng4, p.rng5
+FROM (	
+SELECT DISTINCT
+		mx.account_name,
+		mx.str0,
+		mx.str1,
+		mx.str2,
+		mx.str3,
+		mx.str4,
+		mx.str5,
+		mx.str6,
+		mx.str7,
+		mx.str8,
+		mx.str9,
+
+		mx.rng0,
+		mx.rng1,
+		mx.rng2,
+		mx.rng3,
+		mx.rng4,
+		mx.rng5,
+		mx.rng6,
+		mx.rng7,
+		mx.rng8,
+		mx.rng9,
+
+		mx.dec0,
+		mx.dec1,
+		mx.dec2,
+		mx.dec3,
+		mx.dec4,
+		mx.dec5,
+		mx.dec6,
+		mx.dec7,
+		mx.dec8,
+		mx.dec9,
+
+		mx.chk0_opt0,
+		mx.chk0_opt1,
+		mx.chk0_opt2,
+		mx.chk0_opt3,
+		mx.chk0_opt4,
+
+		mx.chk1_opt0,
+		mx.chk1_opt1,
+		mx.chk1_opt2,
+		mx.chk1_opt3,
+		mx.chk1_opt4,
+
+		mx.chk2_opt0,
+		mx.chk2_opt1,
+		mx.chk2_opt2,
+		mx.chk2_opt3,
+		mx.chk2_opt4,
+
+		mx.chk3_opt0,
+		mx.chk3_opt1,
+		mx.chk3_opt2,
+		mx.chk3_opt3,
+		mx.chk3_opt4,
+
+		mx.chk4_opt0,
+		mx.chk4_opt1,
+		mx.chk4_opt2,
+		mx.chk4_opt3,
+		mx.chk4_opt4,
+
+		mx.chk5_opt0,
+		mx.chk5_opt1,
+		mx.chk5_opt2,
+		mx.chk5_opt3,
+		mx.chk5_opt4,
+
+		mx.chk6_opt0,
+		mx.chk6_opt1,
+		mx.chk6_opt2,
+		mx.chk6_opt3,
+		mx.chk6_opt4,
+
+		mx.chk7_opt0,
+		mx.chk7_opt1,
+		mx.chk7_opt2,
+		mx.chk7_opt3,
+		mx.chk7_opt4,
+
+		mx.chk8_opt0,
+		mx.chk8_opt1,
+		mx.chk8_opt2,
+		mx.chk8_opt3,
+		mx.chk8_opt4,
+
+		mx.chk9_opt0,
+		mx.chk9_opt1,
+		mx.chk9_opt2,
+		mx.chk9_opt3,
+		mx.chk9_opt4,
+
+		mb.item_name,
+		mb.str0 as _str0,
+		mb.str1 as _str1,
+		mb.str2 as _str2,
+		mb.str3 as _str3,
+		mb.str4 as _str4,
+		mb.str5 as _str5,
+		mb.str6 as _str6,
+		mb.str7 as _str7,
+		mb.str8 as _str8,
+		mb.str9 as _str9,
+
+		mb.rng0 as _rng0,
+		mb.rng1 as _rng1,
+		mb.rng2 as _rng2,
+		mb.rng3 as _rng3,
+		mb.rng4 as _rng4,
+
+		mb.dec0 as _dec0,
+		mb.dec1 as _dec1,
+		mb.dec2 as _dec2,
+		mb.dec3 as _dec3,
+		mb.dec4 as _dec4,
+
+		mb.chk0_opt0 as _chk0_opt0,
+		mb.chk0_opt1 as _chk0_opt1,
+		mb.chk0_opt2 as _chk0_opt2,
+		mb.chk0_opt3 as _chk0_opt3,
+		mb.chk0_opt4 as _chk0_opt4,
+
+		mb.chk1_opt0 as _chk1_opt0,
+		mb.chk1_opt1 as _chk1_opt1,
+		mb.chk1_opt2 as _chk1_opt2,
+		mb.chk1_opt3 as _chk1_opt3,
+		mb.chk1_opt4 as _chk1_opt4,
+
+		mb.chk2_opt0 as _chk2_opt0,
+		mb.chk2_opt1 as _chk2_opt1,
+		mb.chk2_opt2 as _chk2_opt2,
+		mb.chk2_opt3 as _chk2_opt3,
+		mb.chk2_opt4 as _chk2_opt4,
+
+		mb.chk3_opt0 as _chk3_opt0,
+		mb.chk3_opt1 as _chk3_opt1,
+		mb.chk3_opt2 as _chk3_opt2,
+		mb.chk3_opt3 as _chk3_opt3,
+		mb.chk3_opt4 as _chk3_opt4,
+
+		mb.chk4_opt0 as _chk4_opt0,
+		mb.chk4_opt1 as _chk4_opt1,
+		mb.chk4_opt2 as _chk4_opt2,
+		mb.chk4_opt3 as _chk4_opt3,
+		mb.chk4_opt4 as _chk4_opt4
+
+	FROM
+		crm_account as mx LEFT JOIN crm_account_item as mb ON mx.id = mb.account_id
+	
+where true 
+	GROUP BY mx.buyer_id, mx.account_name
+	
+having true  and ( true or  true or  false )  and ( true or  false )  and ( true or  false )  and ( true or  false ) 
+
+) p
+
+having true 
+having true  and ( true or  true or  false )  and ( true or  false )  and ( true or  false )  and ( true or  false ) 

+ 14 - 0
table-controls/detail-page-links.sql

@@ -0,0 +1,14 @@
+update dbr_setup set component = 'popup-setup.form-a.user-credit-form' WHERE setup_code = 'user-credit';
+
+ALTER TABLE `dbr_setup` CHANGE `created_on` `created_on` BIGINT(11) NOT NULL DEFAULT unix_timestamp();
+
+update dbr_setup set setup_json = '{"PolicyDesc":"비밀번호는 특수문자 포함 8자 이상 가능합니다.","MinLength":8,"IsUpperMixed":false,"IsSpecialMixed":true,"IsProhibitReuse":false}' WHERE setup_code = 'passwd-policy';
+update dbr_setup set setup_name = '사용자비밀번호 정책' WHERE setup_code = 'passwd-policy' and brand_code = 'users' ;
+
+update dbr_setup set setup_name = '품목미디어 바디생성',  setup_code = 'media-body', brand_code = 'item'
+WHERE setup_code = 'item-media' ;
+
+update dbr_setup set setup_name = '블로그 미디어 바디생성',  setup_code = 'media-body', brand_code = 'post'
+WHERE setup_code = 'blog-media' ;
+
+delete from dbr_setup WHERE setup_code = 'custom-media' ;

+ 5 - 0
table-controls/drop-queries copy.sql

@@ -0,0 +1,5 @@
+select last_day(NOW())
+DATE_FORMAT(STR_TO_DATE(date, '%Y%m%d'),'%Y-%m-%d ')
+*DATE_FORMAT ( Date, format )
+
+SELECT DATE(CONCAT(YEAR(CURDATE()),"-12-31"))

+ 4 - 0
table-controls/dynamic-sql.sql

@@ -0,0 +1,4 @@
+        set @pos := new.rating_score;
+        set @qry1 := concat('update pro_item_revsum set score', @pos, '_cnt=score', @pos, '_cnt+1  where id = ', new.item_id );
+        prepare run_query from @qry1 ;
+        execute run_query ;

+ 5 - 0
table-controls/ether-sign-verify.json-viet

@@ -0,0 +1,5 @@
+{
+  "ContractAddr": "0xA7f8B17bDB7e7fAb42b81609Ed28F589aA8549f1",
+  "Signature": "0xb006e1ff75af248ef5a1c52df3fe749077a29a11d2877942095e7ad26f1fc8a51e04482cba4bc54f2a19c535356d225e8923e0a0e29f9aee6d14244803503d391b",
+  "Message": "I, hereby verify that I am the owner/creator of the address"
+}

+ 40 - 0
table-controls/function-snipet.sql

@@ -0,0 +1,40 @@
+SHOW FUNCTION STATUS WHERE Db = 'genmodel_back';
+SHOW PROCEDURE STATUS WHERE Db = 'genmodel_back';
+
+SELECT
+    CONCAT('DROP ',ROUTINE_TYPE,' `',ROUTINE_SCHEMA,'`.`',ROUTINE_NAME,'`;') as stmt
+FROM information_schema.ROUTINES Where ROUTINE_SCHEMA = 'ssohost_db'
+
+SELECT
+    CONCAT('DROP ',ROUTINE_TYPE,' ','`',ROUTINE_NAME,'`;') as stmt
+FROM information_schema.ROUTINES Where ROUTINE_SCHEMA = 'genmodel_back'
+
+SELECT group_concat(COLUMN_NAME) FROM INFORMATION_SCHEMA.COLUMNS 
+WHERE TABLE_SCHEMA = 'weberp_db' AND TABLE_NAME = 'dbr_setup';
+
+SELECT concat('###', table_name,"$$$;", CHAR(10 using utf8)) FROM information_schema.tables
+WHERE table_schema = 'weberp_db';
+
+describe dbr_user_perm;
+
+delete from dbr_company where email = 'sales@dabory.com';
+delete from pro_member where email = 'sales@dabory.com';
+
+delete from dbr_company where email = 'admin@dabory.com';
+delete from pro_member where email = 'admin@dabory.com';
+
+delete from dbr_company where email = 'dev1@dabory.com';
+delete from pro_member where email = 'dev1@dabory.com';
+delete from dbr_company where email = 'dev2@dabory.com';
+delete from pro_member where email = 'dev2@dabory.com';
+
+delete from dbr_company where email = 'dev1.dabory@gmail.com';
+delete from pro_member where email = 'dev1.dabory@gmail.com';
+delete from dbr_company where email = 'dev2.dabory@gmail.com';
+delete from pro_member where email = 'dev2.dabory@gmail.com';
+
+delete from dbr_company where email = 'wngur6076@naver.com';
+delete from pro_member where email = 'wngur6076@naver.com';
+
+delete from dbr_company where email = 'kimhi65@naver.com';
+delete from pro_member where email = 'kimhi65@naver.com';

+ 1 - 0
table-controls/product.sql

@@ -0,0 +1 @@
+ALTER TABLE `dbr_item` CHANGE `isnt_pro` `isnt_pro` CHAR(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '0' COMMENT '0;OnOff판매가, 1:On판매않음, 2:LinkedProduct';

+ 44 - 0
table-controls/select-json.sql

@@ -0,0 +1,44 @@
+drop procedure if exists fnc_curr_reward_bal;
+
+create procedure fnc_curr_reward_bal()
+
+BEGIN
+
+-- setup 변수들 --
+Declare _sgroup_id int;
+
+
+-- see manual int ---- https://dololak.tistory.com/257  Json Data extract
+SELECT json_extract(sorder_json, '$.OfcCode') from dbr_sorder where setup_code = 'office-info'
+
+END;
+
+SELECT json_extract(setup_json, '$.REyeLens.LongPd') from dbr_sorder where sorder_nosorder_no = '200928-152292'
+
+
+SET @json_k = '{
+  "qqq": "aaa"
+}';
+
+SELECT json_extract(@json_k, '$.qqq');
+SELECT @json_k = JSON_replace(@json_k, "$.qqq", "kkk");
+
+
+SELECT @json_k;
+SELECT json_extract(@json_k, '$.qqq');
+
+select json_extract(json1, '$.REyeLens.Sph') from dbr_sorder where id =2 ;
+
+select json_replace(json1, '$.REyeLens.Sph', 'hhhh') from dbr_sorder where id =2 ;
+
+SET @json_k = '{
+  "qqq": "aaa"
+}';
+
+
+update dbr_sorder set json1 = json_replace(@json_k, '$.REyeLens.Sph', 'qqeqrq')where id =2 ;
+
+SET @json_k = '{
+  "qqq": "aaa"
+}';
+update dbr_sorder set json1 = json_replace(@json_k, '$.qqq', 'qqeqrq') where id =2 ;

+ 30 - 0
table-controls/table-backup.sql

@@ -0,0 +1,30 @@
+set @table := concat('bak_company', '_', date_format(curdate(), '%y_%m_%d'),'_',time_format(current_time, '%H_%i_%s'));
+set @qry1 := concat('create table ',@table, ' select * from dbr_company');
+prepare run_query from @qry1 ;
+execute run_query ;
+
+
+CREATE TABLE concat("kkk_company", "_", date_format(CURDATE(), "%y_%m_%d") SELECT * FROM dbr_company
+SELECT concat('kkk_company', '_', date_format(CURDATE(), '%y_%m_%d'),'_',time_format(CURRENT_TIME, "%H_%i_%s"))
+SELECT concat("kkk_company", "_", date_format(CURDATE(), "%y_%m_%d"),"_",time_format(CURRENT_TIME, "%H_%i_%s"))
+
+CREATE TABLE ( SELECT concat('kkk_company', '_', date_format(CURDATE(), '%y_%m_%d'),'_',time_format(CURRENT_TIME, "%H_%i_%s"))
+) SELECT * FROM dbr_company
+
+
+CREATE TABLE `concat("kkk_company", "_", date_format(CURDATE(), "%y_%m_%d"),"_",time_format(CURRENT_TIME, "%H_%i_%s"))` SELECT * FROM dbr_company
+
+
+
+SELECT CURRENT_TIME;
+
+SELECT TIME_FORMAT(CURRENT_TIME, "%H_%i_%s");
+TIME_FORMAT(CURRENT_TIME, "%H_%i_%s")
+
+concat(date_format(CURDATE(), '%Y_%m_%d'),'_',time_format(CURRENT_TIME, "%H_%i_%s"))
+
+
+set @table := concat("bak_company", "_", date_format(curdate(), "%y_%m_%d"),"_",time_format(current_date, "%H_%i_%s"));
+set @qry1:= concat('create table ',@table, ' select * from dbr_company');
+prepare run_query from @qry1 ;
+execute run_query ;

+ 31 - 0
table-controls/truncate-all-tables(위험).sql

@@ -0,0 +1,31 @@
+DROP PROCEDURE IF EXISTS trunctables;
+DELIMITER ;;
+CREATE  PROCEDURE trunctables(theDb varchar(64))
+BEGIN
+    declare tname varchar(64);
+    declare table_except text;
+    declare is_found int;
+    declare tcursor CURSOR FOR 
+        SELECT table_name FROM information_schema.tables WHERE table_type <> 'VIEW' AND table_schema = theDb order by table_name;
+
+    set table_except = 'dbr_agroup';
+    SET FOREIGN_KEY_CHECKS = 0; 
+    OPEN tcursor;
+    l1: LOOP
+        FETCH tcursor INTO tname;
+        if tname = NULL then leave l1; end if;
+        set is_found = instr(table_except, tname);
+        insert into aaaa (aaa, bbb) values(table_except, tname);
+        if is_found = 0 then
+            set @sql = CONCAT('truncate `', theDB, '`.`', tname, '`');
+            PREPARE stmt from @sql;
+            EXECUTE stmt;
+            DEALLOCATE PREPARE stmt;
+        end if;
+    END LOOP l1;
+    CLOSE tcursor;
+    SET FOREIGN_KEY_CHECKS = 1; 
+END ;;
+DELIMITER ;
+
+call trunctables('ssokkk_db');

+ 66 - 0
table-controls/unixtime-to-date.sql

@@ -0,0 +1,66 @@
+select block_no, from_unixtime(created_on) from bcs_block order by created_on desc
+limit 10 offset 0;
+
+select txn_hash, from_unixtime(created_on) from bcs_tranxn order by created_on desc
+limit 10 offset 0;
+
+CREATE TABLE `dbt_upload_type1` (
+  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+  `created_on` int(11) NOT NULL DEFAULT unix_timestamp(),
+  `list_token` varchar(21) NOT NULL,
+  `order_by` varchar(32) DEFAULT NULL,
+  `c1` tinytext DEFAULT NULL,
+  `c2` tinytext DEFAULT NULL,
+  `c3` tinytext DEFAULT NULL,
+  `c4` tinytext DEFAULT NULL,
+  `c5` tinytext DEFAULT NULL,
+  `c6` tinytext DEFAULT NULL,
+  `c7` tinytext DEFAULT NULL,
+  `c8` tinytext DEFAULT NULL,
+  `c9` tinytext DEFAULT NULL,
+  `c10` tinytext DEFAULT NULL,
+  `c11` tinytext DEFAULT NULL,
+  `c12` tinytext DEFAULT NULL,
+  `c13` tinytext DEFAULT NULL,
+  `c14` tinytext DEFAULT NULL,
+  `c15` tinytext DEFAULT NULL,
+  `c16` tinytext DEFAULT NULL,
+  `c17` tinytext DEFAULT NULL,
+  `c18` tinytext DEFAULT NULL,
+  `c19` tinytext DEFAULT NULL,
+  `c20` tinytext DEFAULT NULL,
+  `c21` tinytext DEFAULT NULL,
+  `c22` tinytext DEFAULT NULL,
+  `c23` tinytext DEFAULT NULL,
+  `c24` tinytext DEFAULT NULL,
+  `c25` tinytext DEFAULT NULL,
+  `c26` tinytext DEFAULT NULL,
+  `c27` tinytext DEFAULT NULL,
+  `c28` tinytext DEFAULT NULL,
+  `c29` tinytext DEFAULT NULL,
+  `c30` tinytext DEFAULT NULL,
+  PRIMARY KEY (`id`)
+  
+
+  [안경점 포스 특성 DB 컨버젼]
+ A. MS SQL Server 설치
+   (DB 컨버젼 시스템 설치 및 테스트)
+    (1) AWS DB Conversion Station 설치.
+    (2) MS Windows Server 설치
+    (3) MS SQL Server 설치
+
+ B. 1차 iTech DB 컨버젼
+   (1) iTech 프로그램 설치
+   (2) iTech DB 설치 및 분석
+   (3) Query 작성 및 테스트
+   (4) Excel Download 테스트
+   
+ C. 기준 산출물
+   (1) 기초고객정보
+     고객명, 생년월일, 휴대전화, 유선번호, 적립금, 주소
+   (2) 안경렌즈-검안정보(전체기간)
+     SPH, CYL, AXIS, 원용PD, ADD
+   (3) 콘텍트렌즈-검안정보(전체기간)
+     SPH, DIA, B.C, CYL, AXIS
+   (4) 판매이력
+     고객, 상품 구매이력, 고객방문 기록

+ 87 - 0
table-controls/weberp_db_update.sql

@@ -0,0 +1,87 @@
+ALTER TABLE `dbr_user_menu` CHANGE `menu_lang_0` `menu_lang0` VARCHAR(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL;
+ALTER TABLE `dbr_user_menu` CHANGE `menu_lang_1` `menu_lang1` VARCHAR(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL;
+ALTER TABLE `dbr_user_menu` CHANGE `menu_lang_2` `menu_lang2` VARCHAR(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL;
+ALTER TABLE `dbr_user_menu` CHANGE `menu_lang_3` `menu_lang3` VARCHAR(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL;
+
+ALTER TABLE `pro_member_menu` CHANGE `menu_lang_0` `menu_lang0` VARCHAR(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL;
+ALTER TABLE `pro_member_menu` CHANGE `menu_lang_1` `menu_lang1` VARCHAR(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL;
+ALTER TABLE `pro_member_menu` CHANGE `menu_lang_2` `menu_lang2` VARCHAR(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL;
+ALTER TABLE `pro_member_menu` CHANGE `menu_lang_3` `menu_lang3` VARCHAR(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL;
+
+
+select
+	bal.id as id,
+	dbr_company.id as code_id,
+	company_name as name,
+	ifnull(bal_amt,0) as balance2
+from
+	dbr_company
+	left outer join
+	( 
+	select
+		id, buyer_id, bal_amt
+	from dbr_bal_buyer
+	where yyyy_mm = '202201' and branch_id = 1
+	) 
+as bal
+	ON dbr_company.id = bal.buyer_id
+
+where company_class = '' or company_class = 'AB'
+order by company_name asc
+
+UPDATE `pro_member` SET reset_code= 'Ef63EYPjqzOIWl3G'
+
+
+DROP TABLE zzz_dbr_statis;
+ALTER TABLE zzz_log RENAME TO zsp_test_log;
+
+
+ALTER TABLE `dbt_list_type1` ADD `c21` VARCHAR(64) NULL DEFAULT NULL AFTER `c20`;
+ALTER TABLE `dbt_list_type1` ADD `c22` VARCHAR(64) NULL DEFAULT NULL AFTER `c21`;
+ALTER TABLE `dbt_list_type1` ADD `c23` VARCHAR(64) NULL DEFAULT NULL AFTER `c22`;
+ALTER TABLE `dbt_list_type1` ADD `c24` VARCHAR(64) NULL DEFAULT NULL AFTER `c23`;
+ALTER TABLE `dbt_list_type1` ADD `c25` VARCHAR(64) NULL DEFAULT NULL AFTER `c24`;
+ALTER TABLE `dbt_list_type1` ADD `c26` VARCHAR(64) NULL DEFAULT NULL AFTER `c25`;
+ALTER TABLE `dbt_list_type1` ADD `c27` VARCHAR(64) NULL DEFAULT NULL AFTER `c26`;
+ALTER TABLE `dbt_list_type1` ADD `c28` VARCHAR(64) NULL DEFAULT NULL AFTER `c27`;
+ALTER TABLE `dbt_list_type1` ADD `c29` VARCHAR(64) NULL DEFAULT NULL AFTER `c28`;
+ALTER TABLE `dbt_list_type1` ADD `c20` VARCHAR(64) NULL DEFAULT NULL AFTER `c29`;
+
+ALTER TABLE `bcm_contract` CHANGE `token_name` `token_name` VARCHAR(128) COMMENT 'token name';
+
+ALTER TABLE `dbr_company` CHANGE `company_name` `company_name` VARCHAR(64)  COMMENT '고객명: POS의 경우 고객코드로 사용';
+ALTER TABLE `dbr_company` CHANGE `main_contact` `main_contact` VARCHAR(21)  COMMENT '주담당자: POS의 경우 고객이름(동명이인 사용가능)으로 사용';
+
+UPDATE `dbr_setup` SET component = 'popup-setup.form-a.passwd-policy-form' where setup_code = 'user-dabory';
+UPDATE `dbr_setup` SET setup_code = 'sso-client',   brand_code = 'user-dabory' where setup_code = 'user-dabory';
+
+UPDATE `dbr_setup` SET is_on_use = '0' where setup_code = 'sso-client';
+
+UPDATE `dbr_setup` SET setup_name = 'SSO 관리자 로그인', brand_code = 'user-dabory' where setup_code = 'sso-client' and brand_code = 'user-dabory';
+
+UPDATE `dbr_setup` SET brand_code = 'user-dabory' where setup_code = 'sso-client' and brand_code = 'user-dabory';
+
+UPDATE `dbr_setup` SET brand_code = 'member-dabory' where setup_code = 'sso-client' and brand_code = 'dabory';
+UPDATE `dbr_setup` SET brand_code = 'member-google' where setup_code = 'sso-client' and brand_code = 'google';
+UPDATE `dbr_setup` SET brand_code = 'member-kakao' where setup_code = 'sso-client' and brand_code = 'kakao';
+UPDATE `dbr_setup` SET brand_code = 'member-facebook' where setup_code = 'sso-client' and brand_code = 'facebook';
+UPDATE `dbr_setup` SET brand_code = 'member-naver' where setup_code = 'sso-client' and brand_code = 'naver';
+
+delete from dbr_setup where setup_code = 'member-policy';
+
+
+INSERT INTO dbr_setup (branch_id, setup_code, brand_code, setup_name, component, parameter, is_on_use, is_brand_select, setup_json )
+VALUES (0, 'cdn-aws-s3', '', 'Media-AWS-S3 설정', 'popup-setup.form-a.cdn.aws-s3-form', 'popup-setup/form-a/cdn/aws-s3', '1', '0', '{\"AccessKeyId\":\"AKIA2DK3AOJ3HTHQRO3N\",\"SecretAccessKey\":\"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\",\"DefaultRegion\":\"ap-northeast-2\",\"Bucket\":\"dbr02-s3\"}');
+
+delete from dbr_setup where setup_code = 'login-info';
+INSERT INTO dbr_setup (branch_id, setup_code, brand_code, setup_name, component, parameter, is_on_use, is_brand_select, setup_json )
+VALUES (0, 'login-info', '', '로그인 정보', 'popup-setup.form-a.login-info-form', '/popup-setup/form-a/login-info', '1', '0', '{\"IsMemberSsoOnly\":true,\"MemberEmail\":\"kimhi65@naver.com\",\"MemberPasswd\":\"China13579\",\"IsUserSsoOnly\":false,\"UserEmail\":\"kimhi65@naver.com\",\"UserPasswd\":\"China13579\"}');
+
+UPDATE `dbr_etc` SET select_name = 'pay_terms' where etc_type = 'domestic' and select_name = 'pay_terms';
+UPDATE `dbr_etc` SET select_name = 'pay_period' where etc_type = 'domestic' and select_name = 'pay_period';
+UPDATE `dbr_etc` SET select_name = 'destination' where etc_type = 'domestic' and select_name = 'destination';
+UPDATE `dbr_etc` SET select_name = 'delivery' where etc_type = 'domestic' and select_name = 'destination';
+UPDATE `dbr_etc` SET select_name = 'column1' where etc_type = 'domestic' and select_name = 'column1';
+UPDATE `dbr_etc` SET select_name = 'column2' where etc_type = 'domestic' and select_name = 'column2';
+
+UPDATE `dbr_etc` SET select_name = 'our_contact' where etc_type = 'domestic' and select_name = '담당자';

+ 38 - 0
table-controls/z-auto-increment-0.sql

@@ -0,0 +1,38 @@
+
+[create sort_menu]
+ALTER TABLE `dbr_sort_menu`
+  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=16;
+  ALTER TABLE your_table_name AUTO_INCREMENT = 0;
+
+
+DELIMITER //
+
+CREATE PROCEDURE ResetAutoIncrement()
+BEGIN
+    DECLARE done INT DEFAULT FALSE;
+    DECLARE tableName VARCHAR(255);
+    DECLARE cur CURSOR FOR
+        SELECT table_name
+        FROM information_schema.tables
+        WHERE table_schema = DATABASE() AND table_type = 'BASE TABLE';
+
+    DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
+
+    OPEN cur;
+
+    read_loop: LOOP
+        FETCH cur INTO tableName;
+        IF done THEN
+            LEAVE read_loop;
+        END IF;
+
+        SET @sql = CONCAT('ALTER TABLE ', tableName, ' AUTO_INCREMENT = 0;');
+        PREPARE stmt FROM @sql;
+        EXECUTE stmt;
+        DEALLOCATE PREPARE stmt;
+    END LOOP;
+
+    CLOSE cur;
+END //
+
+DELIMITER ;

+ 68 - 0
table-controls/z-tmp-집계표.sql

@@ -0,0 +1,68 @@
+drop procedure if exists fnc_curr_item_bal;
+DELIMITER //
+create procedure fnc_curr_item_bal( _curr_date varchar(8), _storage int, _target int)
+
+BEGIN
+
+Declare _curr_bal decimal(20,4) default "0.0000";
+Declare _curr_bad decimal(20,4) default "0.0000";
+Declare _sum_stkio decimal(20,4) default "0.0000";
+Declare _sum_bad decimal(20,4) default "0.0000";
+
+Declare _bal_date varchar(8);
+
+if _is_first_date(_curr_date) then
+	set _bal_date = '19000101';
+else
+	set _bal_date = _curr_date;
+end if;
+
+
+select bal_qty, bad_bal_qty
+into _curr_bal, _curr_bad
+from dbr_bal_item
+where item_id = _target
+    and yyyy_mm = _prev_month(_curr_date) and storage_id = _storage;
+
+select sum(io_qty*stock_status), sum(io_qty*badstk_status)
+into _sum_stkio, _sum_bad
+from ( select item_id, io_qty, stock_status, badstk_status
+    from dbr_stock_io  as stk
+        inner join dbr_deal_type as deal on deal.id = stk.deal_type_id
+    where item_id = _target
+        and io_date between _first_date(_bal_date) and _bal_date
+        and storage_id = _storage
+    ) stkio
+group by stkio.item_id;
+
+select _curr_bal + _sum_stkio as c1, _curr_bad + _sum_bad as c2;
+
+END;
+//
+DELIMITER ;
+
+call fnc_curr_item_bal('20230228', 1, 1) ;
+
+
+
+
+
+
+
+ALTER TABLE `crm_account` CHANGE `account_name` `order_by` VARCHAR(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '';
+ALTER TABLE `crm_account_item` CHANGE `item_name` `order_by` VARCHAR(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '';
+
+
+select bal_amt
+from dbr_bal_reward
+where buyer_id = 10
+    and yyyy_mm = _prev_month('20230228') and branch_id = 1;
+
+
+select sum(reward_amt*reward_status)
+from dbr_reward_bd  as rwd
+    inner join dbr_deal_type as deal on deal.id = deal_type_id
+where buyer_id = 10
+    and avail_date between '20230201' and '20230228'
+    and branch_id = 1
+group by buyer_id;

+ 1 - 0
table-controls/z-매입원장.sql

@@ -0,0 +1 @@
+

+ 190 - 0
table-controls/z-매입집계표.sql

@@ -0,0 +1,190 @@
+-- 전월 재고 --
+insert into dbt_list_sum
+	( created_on, list_token, h_id, id, c1, c2, c3,
+     d1, d2, d3, d4, d5,
+     c4, c5, order_by )
+
+select unix_timestamp(), 'a', mx.id, mx.id, item_code, item_name, sub_name,
+     bal_qty, 0, 0, 0, 0,
+   	igroup_name, igroup_code, item_code
+
+from ( select id, item_code, item_name, sub_name, igroup_id
+		from dbr_item as itm
+		where item_code between '!' and '駾'
+            and isnt_stkio = '0' and is_material = '0'
+	) as mx
+    inner join ( select item_id, bal_qty
+		from dbr_bal_item
+		where yyyy_mm = _prev_month('20230201') and storage_id = 1
+	) as bal on mx.id = bal.item_id
+
+    inner join ( select id, igroup_code, igroup_name
+		from dbr_igroup
+		where igroup_code between '!' and '駾'
+	) as igr on mx.igroup_id = igr.id
+
+order by item_code asc;
+
+-- 당월 수불 합계 --
+insert into dbt_list_sum
+	( created_on, list_token, h_id, id, c1, c2, c3,
+     d1, d2, d3,
+     d4, d5,
+     c4, c5, order_by )
+
+select unix_timestamp(), 'a', mx.id, mx.id, item_code, item_name, sub_name,
+     0, sum(io_qty*cast((stock_status+1)/2 as int)), sum(io_qty*cast(-1*(stock_status-1)/2 as int)),
+     0, sum(io_qty*badstk_status),
+   	igroup_name, igroup_code, item_code
+
+from ( select id, item_code, item_name, sub_name, igroup_id
+		from dbr_item as itm
+		where item_code between '!' and '駾'
+            and isnt_stkio = '0' and is_material = '0'
+	) as mx
+    inner join ( select item_id, io_qty, stock_status, badstk_status
+		from dbr_stock_io  as stk
+            inner join dbr_deal_type as deal on deal.id = stk.deal_type_id
+		where io_date between '20230201' and '20230231'
+			and storage_id = 1
+	) as stk on mx.id = stk.item_id
+
+    inner join ( select id, igroup_code, igroup_name
+		from dbr_igroup
+		where igroup_code between '!' and '駾'
+	) as igr on mx.igroup_id = igr.id
+group by stk.item_id
+order by item_code asc;
+
+-- dbt_list_type1 으로 집계 --
+insert into dbt_list_type1
+	( created_on, list_token, h_id, id, c1, c2, c3,
+		d1, d2, d3, d4, d5,
+		c4, c5, order_by)
+select min(unix_timestamp()), min('a'), min(id), min(id), min(c1), min(c2), min(c2),
+	sum(d1),
+	sum(d2),
+	sum(d3),
+    sum(d1) + sum(d2) - sum(d3),
+	sum(d5),
+	min(c4), min(c5), min(order_by)
+from dbt_list_sum as mx
+where list_token = 'a'
+group by mx.id
+having min(mx.id) is not null
+order by order_by asc;
+=======
+=======
+>>>>>>> 62bdebd054e19dd2c2ce53384ce4fe759d13dd29
+insert into dbt_list_type1
+	( created_on, list_token, h_id, id, c1, c2, c3,
+    d1, d2, d3, d4, d5,
+    c4, c5 )
+
+select unix_timestamp(), 'a', mx.id, mx.id, item_code, item_name, sub_name,
+    bal_qty, 0, 0, 0, 0,
+  	igroup_name, igroup_code
+<<<<<<< HEAD
+=======
+
+from ( select id, item_code, item_name, sub_name, igroup_id
+        from dbr_item as itm
+  	    where itm.item_code between '!' and '駾'
+        	and ( isnt_stkio = '0' or is_material = '0' )
+    ) as mx
+
+	inner join (
+        select item_id, bal_qty
+		from dbr_bal_item
+		where yyyy_mm = _prev_month('20230201') and storage_id = 1
+	) as last_mbal on last_mbal.item_id = mx.id
+
+	inner join (
+        select id, igroup_code, igroup_name from dbr_igroup as igr
+        where igr.igroup_code between '!' and '駾'
+    ) as igr on igr.id = mx.igroup_id
+
+order by item_code asc;
+
+-- 당월 수불합계 --
+insert into dbt_list_type1
+	( created_on, list_token, h_id, id, c1, c2, c3,
+    d1, d2, d3, d4, d5,
+    c4, c5 )
+
+select unix_timestamp(), 'a', mx.id, mx.id, item_code, item_name, sub_name,
+    0, sum(io_qty*cast((stock_status+1)/2 as int)), sum(io_qty*cast(-1*(stock_status-1)/2 as int)), 0,
+    sum(io_qty*badstk_status),
+  	igroup_name, igroup_code
+
+from ( select id, item_code, item_name, sub_name, igroup_id
+        from dbr_item as itm
+  	    where itm.item_code between '!' and '駾'
+        	and ( isnt_stkio = '0' or is_material = '0' )
+    ) as mx
+
+	inner join ( select item_id, deal_type_id, io_qty
+		from dbr_stock_io
+		where io_date between '20230201' and '20230231'
+        	and storage_id = 1
+    ) as stk on stk.item_id = mx.id
+
+	inner join ( select id, igroup_code, igroup_name from dbr_igroup as igr
+        where igr.igroup_code between '!' and '駾'
+    ) as igr on igr.id = mx.igroup_id
+
+    inner join dbr_deal_type as deal on deal.id = stk.deal_type_id
+
+order by item_code asc;
+
+from ( select id, item_code, item_name, sub_name, igroup_id
+        from dbr_item as itm
+  	    where itm.item_code between '!' and '駾'
+        	and ( isnt_stkio = '0' or is_material = '0' )
+    ) as mx
+
+	inner join (
+        select item_id, bal_qty
+		from dbr_bal_item
+		where yyyy_mm = _prev_month('20230201') and storage_id = 1
+	) as last_mbal on last_mbal.item_id = mx.id
+
+	inner join (
+        select id, igroup_code, igroup_name from dbr_igroup as igr
+        where igr.igroup_code between '!' and '駾'
+    ) as igr on igr.id = mx.igroup_id
+
+order by item_code asc;
+
+-- 당월 수불합계 --
+insert into dbt_list_type1
+	( created_on, list_token, h_id, id, c1, c2, c3,
+    d1, d2, d3, d4, d5,
+    c4, c5 )
+
+select unix_timestamp(), 'a', mx.id, mx.id, item_code, item_name, sub_name,
+    0, sum(io_qty*cast((stock_status+1)/2 as int)), sum(io_qty*cast(-1*(stock_status-1)/2 as int)), 0,
+    sum(io_qty*badstk_status),
+  	igroup_name, igroup_code
+
+from ( select id, item_code, item_name, sub_name, igroup_id
+        from dbr_item as itm
+  	    where itm.item_code between '!' and '駾'
+        	and ( isnt_stkio = '0' or is_material = '0' )
+    ) as mx
+
+	inner join ( select item_id, deal_type_id, io_qty
+		from dbr_stock_io
+		where io_date between '20230201' and '20230231'
+        	and storage_id = 1
+    ) as stk on stk.item_id = mx.id
+
+	inner join ( select id, igroup_code, igroup_name from dbr_igroup as igr
+        where igr.igroup_code between '!' and '駾'
+    ) as igr on igr.id = mx.igroup_id
+
+    inner join dbr_deal_type as deal on deal.id = stk.deal_type_id
+
+order by item_code asc;
+
+>>>>>>> a12a75b5e2b8584ff6dcd2fe635e566613dfec2c

+ 19 - 0
table-controls/z-소트-뱃지-생성.sql

@@ -0,0 +1,19 @@
+
+[create sort_menu]
+truncate table dbr_sort_menu;
+INSERT INTO `dbr_sort_menu` (`id`, `created_on`, `updated_on`, `menu_code`, `sort_type`, `bgcolor_code`, `dash_page_url`, `component`, `parameter`, `icon`, `is_enabled`) VALUES
+(1, 1692935876, 1692935876, '100000', 'optical_pos', '00004d', '/dabory/erp', 'optical_pos', '', 'fas fa-glasses', '1'),
+(2, 1692935876, 1692935876, '200000', 'shop', '1a3300', '/dabory/erp', '', '', 'fas fa-shopping-cart', '1'),
+(3, 1692935876, 1692935876, '300000', 'homepage', '4d1a00', '/dabory/erp', '', '', 'fas fa-home', '1'),
+(4, 1692935876, 1692935876, '500000', 'groupware', '4d3300', '/dabory/erp', '', '', 'fas fa-layer-group', '1'),
+(5, 1692935876, 1692935876, '600000', 'erp', '260d0d', '/dabory/erp', '', '', 'fas fa-sitemap', '1'),
+(6, 1692935876, 1692935876, '700000', 'kkcrm', '1a2738', '/dabory/erp', '', '', 'fas fa-comment-dollar', '1'),
+(7, 1692935876, 1692935876, '700000', 'dbr_main', '263806', '/dabory/erp', '', '', 'fas fa-glasses', '1');
+
+
+[create item_badge]
+truncate table pro_item_badge;
+REPLACE INTO `pro_item_badge` (`id`, `created_on`, `updated_on`, `sort`, `badge_name`, `lang_type`, `device_type`, `badge_type`, `badge_image`, `x_pos`, `y_pos`, `is_hide`) VALUES (1, '0', '0', '1', '신제품', 'ko', 'desktop', '1', '', '3', '3', '0');
+REPLACE INTO `pro_item_badge` (`id`, `created_on`, `updated_on`, `sort`, `badge_name`, `lang_type`, `device_type`, `badge_type`, `badge_image`, `x_pos`, `y_pos`, `is_hide`) VALUES (2, '0', '0', '1', '10%할인', 'ko', 'desktop', '1', '', '3', '3', '0');
+REPLACE INTO `pro_item_badge` (`id`, `created_on`, `updated_on`, `sort`, `badge_name`, `lang_type`, `device_type`, `badge_type`, `badge_image`, `x_pos`, `y_pos`, `is_hide`) VALUES (3, '0', '0', '1', '경품할인', 'ko', 'desktop', '1', '', '3', '3', '0');
+REPLACE INTO `pro_item_badge` (`id`, `created_on`, `updated_on`, `sort`, `badge_name`, `lang_type`, `device_type`, `badge_type`, `badge_image`, `x_pos`, `y_pos`, `is_hide`) VALUES (4, '0', '0', '1', '타임세일', 'ko', 'desktop', '1', '', '3', '3', '0');

+ 33 - 0
table-controls/검안정보-Json.txt

@@ -0,0 +1,33 @@
+package models_json
+
+type SorderJson1 struct {
+	REyeLens  EyeLens  //(컨버전시 이것만)
+	LEyeLens  EyeLens  //(컨버전시 이것만)
+	RContLens ContLens //(컨버전시 이것만)
+	LContLens ContLens //(컨버전시 이것만)
+}
+
+type EyeLens struct {
+	Sph     string
+	Cyl     string
+	Axis    string
+	LongPd  string
+	Add     string
+	ShortPd string
+	BaseIo  string
+	BaseUd  string
+	BareEye string
+	Adjust  string
+}
+
+type ContLens struct {
+	Sph       string
+	Cyl       string
+	Axis      string
+	Add       string
+	Bc        string
+	Dia       string
+	Kerato    string
+	Prescript string
+	Adjust    string
+}

+ 228 - 0
table-controls/검안정보.Json

@@ -0,0 +1,228 @@
+SET @json_t = '{
+  "REyeLens": {
+    "Sph": "",
+    "Cyl": "",
+    "Axis": "",
+    "LongPd": "11",
+    "Add": "",
+    "ShortPd": "",
+    "BaseIo": "/",
+    "BaseUd": "/",
+    "BareEye": "",
+    "Adjust": ""
+  },
+  "LEyeLens": {
+    "Sph": "",
+    "Cyl": "",
+    "Axis": "",
+    "LongPd": "11",
+    "Add": "",
+    "ShortPd": "",
+    "BaseIo": "/",
+    "BaseUd": "/",
+    "BareEye": "",
+    "Adjust": ""
+  },
+  "RContLens": {
+    "Sph": "",
+    "Cyl": "",
+    "Axis": "",
+    "Add": "",
+    "Bc": "",
+    "Dia": "",
+    "Kerato": "",
+    "Prescript": "",
+    "Adjust": ""
+  },
+  "LContLens": {
+    "Sph": "",
+    "Cyl": "",
+    "Axis": "",
+    "Add": "",
+    "Bc": "",
+    "Dia": "",
+    "Kerato": "",
+    "Prescript": "",
+    "Adjust": ""
+  },
+  "Symptoms": "",
+  "OldREyeLens": {
+    "Sph": "",
+    "Cyl": "",
+    "Axis": "",
+    "LongPd": "",
+    "Add": "",
+    "ShortPd": "",
+    "BaseIo": "/",
+    "BaseUd": "/",
+    "BareEye": "",
+    "Adjust": ""
+  },
+  "OldLEyeLens": {
+    "Sph": "",
+    "Cyl": "",
+    "Axis": "",
+    "LongPd": "",
+    "Add": "",
+    "ShortPd": "",
+    "BaseIo": "/",
+    "BaseUd": "/",
+    "BareEye": "",
+    "Adjust": ""
+  },
+  "CcREyeLens": {
+    "Sph": "",
+    "Cyl": "",
+    "Axis": "",
+    "LongPd": "",
+    "Add": "",
+    "ShortPd": "",
+    "BaseIo": "/",
+    "BaseUd": "/",
+    "BareEye": "",
+    "Adjust": ""
+  },
+  "CcLEyeLens": {
+    "Sph": "",
+    "Cyl": "",
+    "Axis": "",
+    "LongPd": "",
+    "Add": "",
+    "ShortPd": "",
+    "BaseIo": "/",
+    "BaseUd": "/",
+    "BareEye": "",
+    "Adjust": ""
+  },
+  "FixEye": 0,
+  "Stereosia": 0,
+  "ColorVision": 0,
+  "OdImGrid": 0,
+  "OsImGrid": 0,
+  "Screen": {
+    "Shielding": {
+      "Long": "",
+      "Short": ""
+    },
+    "FourDot": {
+      "Long": 0,
+      "Short": 0,
+      "LongStr": "",
+      "ShortStr": ""
+    },
+    "Converge": {
+      "Normal": 0,
+      "Str": ""
+    },
+    "Near": {
+      "OdStr": "",
+      "OsStr": ""
+    },
+    "Easy": {
+      "OuStr": "",
+      "OdStr": "",
+      "OsStr": ""
+    }
+  },
+  "BroadH": {
+    "X": "[]",
+    "Y": "[]",
+    "Drage": "[]"
+  },
+  "Bincular": {
+    "Location": {
+      "LongHori": "",
+      "LongVert": "",
+      "ShortHori": "",
+      "ShortVert": ""
+    },
+    "Relative": {
+      "Pra": "",
+      "Nra": ""
+    },
+    "Lag": 0,
+    "Aca": "",
+    "Fusion": {
+      "LongBo": {
+        "Clo": "",
+        "Dis": "",
+        "Rec": ""
+      },
+      "LongBi": {
+        "Clo": "",
+        "Dis": "",
+        "Rec": ""
+      },
+      "LongOdBd": {
+        "Dis": "",
+        "Rec": ""
+      },
+      "LongOdBu": {
+        "Dis": "",
+        "Rec": ""
+      },
+      "LongOsBd": {
+        "Dis": "",
+        "Rec": ""
+      },
+      "LongOsBu": {
+        "Dis": "",
+        "Rec": ""
+      },
+      "ShortBo": {
+        "Clo": "",
+        "Dis": "",
+        "Rec": ""
+      },
+      "ShortBi": {
+        "Clo": "",
+        "Dis": "",
+        "Rec": ""
+      },
+      "ShortOdBd": {
+        "Dis": "",
+        "Rec": ""
+      },
+      "ShortOdBu": {
+        "Dis": "",
+        "Rec": ""
+      },
+      "ShortOsBd": {
+        "Dis": "",
+        "Rec": ""
+      },
+      "ShortOsBu": {
+        "Dis": "",
+        "Rec": ""
+      }
+    }
+  },
+  "Pameter": {
+    "Oh": {
+      "R": "",
+      "L": ""
+    },
+    "Pd": {
+      "R": "",
+      "L": ""
+    },
+    "Distance": {
+      "R": "",
+      "L": ""
+    },
+    "Inset": {
+      "R": "",
+      "L": ""
+    },
+    "Face": "",
+    "Tilt": "",
+    "Length": ""
+  },
+  "Payment": {
+    "CardCompany": "",
+    "CashReceipt": "",
+    "GiftCard": ""
+  }
+}';
+
+SELECT json_extract(@json_t, '$.REyeLens.LongPd');

+ 186 - 0
table-controls/테이블-DBUpdate-gen-wallet.sql

@@ -0,0 +1,186 @@
+SELECT * FROM `dbr_company` WHERE email like '%bseyewear1@gmail.com%'
+SELECT * FROM `pro_member` WHERE email like '%dabory%'
+
+delete FROM `pro_member` WHERE email like 'bseyewear@naver.com'
+
+delete FROM `pro_member` WHERE email like 'vietdinh1912@gmail.com'
+delete FROM `users` WHERE email like 'Vietpv94@gmail.com'
+
+
+ALTER TABLE `dbr_user_menu` ADD `guest_app_id` INT(11) NOT NULL DEFAULT '0' AFTER `is_skipped`;
+
+ALTER TABLE `bcs_circulatiing`
+  CHANGE `circulatiing_supply` `circulating_supply` DECIMAL (34, 0) DEFAULT 0 NOT NULL;
+
+RENAME TABLE `bcs_circulatiing` TO `bcs_circulating`;
+
+
+ALTER TABLE `dbr_porder_bd` 
+  ADD `memo` TEXT NULL DEFAULT NULL AFTER `confirm_date`,
+  ADD `column2` varchar(69) DEFAULT NULL AFTER `confirm_date`,
+  ADD `column1` varchar(69) DEFAULT NULL AFTER `confirm_date`;
+
+
+update dbr_setup set setup_type = 'pro' where setup_code='contact-us';
+update dbr_setup set setup_type = 'add-service' where setup_code='text-sent';
+update dbr_setup set setup_type = 'add-service' where setup_code='import-pg';
+update dbr_setup set setup_type = 'point' where setup_code='user-credit';
+update dbr_setup set setup_type = 'point' where setup_code='user-reward';
+update dbr_setup set setup_type = 'common' where setup_code='seo-meta';
+update dbr_setup set setup_type = 'common' where setup_code='signup-default';
+update dbr_setup set setup_type = 'common' where setup_code='login-info';
+update dbr_setup set setup_type = 'common' where setup_code='decimal-point';
+update dbr_setup set setup_type = 'member' where setup_code='dormant-default';
+update dbr_setup set setup_type = 'member' where setup_code='dormant-default';
+update dbr_setup set setup_name = '일반설정(mail/.env)' where setup_code='general-info';
+
+
+delete FROM `dbr_setup` WHERE setup_code = 'office-info';
+
+INSERT INTO dbr_setup (branch_id, setup_code, brand_code, setup_name, component, parameter, is_on_use, is_brand_select, setup_json )
+VALUES (0, 'offic-info', '', '사무실정보', 'popup-setup.form-a.office-info-form', '/popup-setup/form-a/office-info', '1', '0', '{\"OfcCode\":\"baeksan-optical\",\"OfcPlace\":\"2\",\"OfcName\":\"3\",\"OfcTaxNo\":\"4\",\"OfcEmail\":\"5\",\"OfcTelNo\":\"6\",\"OfcFaxNo\":\"7\",\"OfcMobile\":\"8\",\"OfcZipCode\":\"9\",\"OfcPresident\":\"10\",\"OfcAddress\":\"11\",\"OfcBizType\":\"12\",\"OfcDealItem\":\"13\"}');
+
+update dbr_setup set component = 'popup-setup.form-a.media-library-form' where setup_code='media-body'
+
+INSERT INTO dbr_setup (branch_id, setup_code, brand_code, setup_name, component, parameter, is_on_use, is_brand_select, setup_json )
+VALUES (0, 'contact-us', 'main', '컨택트폼-메인', 'popup-setup.form-a.contact-us-form', '/popup-setup/form-a/contact-us', '1', '1', '');
+
+delete FROM `dbr_setup` WHERE setup_code = 'contact-us';
+
+INSERT INTO dbr_setup (branch_id, setup_code, brand_code, setup_name, component, parameter, is_on_use, is_brand_select, setup_json )
+VALUES (0, 'contact-us', 'main', '컨택트폼-메인', 'popup-setup.form-a.contact-us-form', '/popup-setup/form-a/contact-us', '1', '1', '');
+
+delete FROM `dbr_setup` WHERE setup_code = 'contact-us' and brand_code = 'sub-1';
+INSERT INTO dbr_setup (branch_id, setup_code, brand_code, setup_name, component, parameter, is_on_use, is_brand_select, setup_json )
+VALUES (0, 'contact-us', 'sub1', '컨택트폼-서브1', 'popup-setup.form-a.contact-us-form', '/popup-setup/form-a/contact-us', '1', '1', '');
+
+
+drop table if exists dbt_list_type1;
+CREATE TABLE `dbt_list_type1` (
+ `t_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `id` int(10) unsigned DEFAULT NULL,
+ `created_on` int(11) NOT NULL DEFAULT unix_timestamp(),
+ `list_token` varchar(21) NOT NULL,
+ `order_by` varchar(32) DEFAULT NULL,
+ `c1` varchar(64) DEFAULT NULL,
+ `c2` varchar(64) DEFAULT NULL,
+ `c3` varchar(64) DEFAULT NULL,
+ `c4` varchar(64) DEFAULT NULL,
+ `c5` varchar(64) DEFAULT NULL,
+ `c6` varchar(64) DEFAULT NULL,
+ `c7` varchar(64) DEFAULT NULL,
+ `c8` varchar(64) DEFAULT NULL,
+ `c9` varchar(64) DEFAULT NULL,
+ `c10` varchar(64) DEFAULT NULL,
+ `c11` varchar(64) DEFAULT NULL,
+ `c12` varchar(64) DEFAULT NULL,
+ `c13` varchar(64) DEFAULT NULL,
+ `c14` varchar(64) DEFAULT NULL,
+ `c15` varchar(64) DEFAULT NULL,
+ `c16` varchar(64) DEFAULT NULL,
+ `c17` varchar(64) DEFAULT NULL,
+ `c18` varchar(64) DEFAULT NULL,
+ `c19` varchar(64) DEFAULT NULL,
+ `c20` varchar(64) DEFAULT NULL,
+ `d1` decimal(20,4) DEFAULT '0.0000',
+ `d2` decimal(20,4) DEFAULT '0.0000',
+ `d3` decimal(20,4) DEFAULT '0.0000',
+ `d4` decimal(20,4) DEFAULT '0.0000',
+ `d5` decimal(20,4) DEFAULT '0.0000',
+ `d6` decimal(20,4) DEFAULT '0.0000',
+ `d7` decimal(20,4) DEFAULT '0.0000',
+ `d8` decimal(20,4) DEFAULT '0.0000',
+ `d9` decimal(20,4) DEFAULT '0.0000',
+ `d10` decimal(20,4) DEFAULT '0.0000',
+ `is_sum` char(1) NOT NULL DEFAULT '0',
+ `t1` mediumtext DEFAULT NULL,
+ `t2` mediumtext DEFAULT NULL,
+ UNIQUE KEY `tid` (`t_id`)
+) ENGINE=MyISAM AUTO_INCREMENT=2273 DEFAULT CHARSET=utf8mb4
+
+drop table if exists cry_list1;
+drop table if exists cry_list1_federated;
+
+drop table if exists fed_crystal_host;
+CREATE TABLE `fed_crystal_host` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `created_on` int(11) NOT NULL DEFAULT unix_timestamp(),
+ `list_token` varchar(21) NOT NULL,
+ `position` varchar(10) NOT NULL,
+ `order_by` varchar(32) DEFAULT NULL,
+ `c1` varchar(64) DEFAULT NULL,
+ `c2` varchar(64) DEFAULT NULL,
+ `c3` varchar(64) DEFAULT NULL,
+ `c4` varchar(64) DEFAULT NULL,
+ `c5` varchar(64) DEFAULT NULL,
+ `c6` varchar(64) DEFAULT NULL,
+ `c7` varchar(64) DEFAULT NULL,
+ `c8` varchar(64) DEFAULT NULL,
+ `c9` varchar(64) DEFAULT NULL,
+ `c10` varchar(64) DEFAULT NULL,
+ `c11` varchar(64) DEFAULT NULL,
+ `c12` varchar(64) DEFAULT NULL,
+ `c13` varchar(64) DEFAULT NULL,
+ `c14` varchar(64) DEFAULT NULL,
+ `c15` varchar(64) DEFAULT NULL,
+ `c16` varchar(64) DEFAULT NULL,
+ `c17` varchar(64) DEFAULT NULL,
+ `c18` varchar(64) DEFAULT NULL,
+ `c19` varchar(64) DEFAULT NULL,
+ `c20` varchar(64) DEFAULT NULL,
+ `d1` decimal(20,4) DEFAULT '0.0000',
+ `d2` decimal(20,4) DEFAULT '0.0000',
+ `d3` decimal(20,4) DEFAULT '0.0000',
+ `d4` decimal(20,4) DEFAULT '0.0000',
+ `d5` decimal(20,4) DEFAULT '0.0000',
+ `d6` decimal(20,4) DEFAULT '0.0000',
+ `d7` decimal(20,4) DEFAULT '0.0000',
+ `d8` decimal(20,4) DEFAULT '0.0000',
+ `d9` decimal(20,4) DEFAULT '0.0000',
+ `d10` decimal(20,4) DEFAULT '0.0000',
+ `is_sum` char(1) NOT NULL DEFAULT '0',
+ `t1` mediumtext DEFAULT NULL,
+ `t2` mediumtext DEFAULT NULL,
+ UNIQUE KEY `id` (`id`)
+) ENGINE=MyISAM AUTO_INCREMENT=2273 DEFAULT CHARSET=utf8mb4;
+
+GRANT ALL PRIVILEGES ON *.* TO 'weberp_db'@'localhost' WITH GRANT OPTION;
+FLUSH PRIVILEGES;
+
+drop table if exists zdb_optpos_contact_lens;
+
+
+ALTER TABLE `dbr_sorder` ADD INDEX `sorder_date` (`sorder_date`);
+
+ALTER TABLE `dbr_sgroup` ADD `Sort` CHAR(1) NOT NULL DEFAULT '0' AFTER `agroup_id`;
+ALTER TABLE `dbr_sgroup` ADD `branch_id` INT(11) NOT NULL DEFAULT '0' AFTER `agroup_id`;
+
+
+show create table bcs_circulating
+
+ALTER TABLE 
+	CHANGE `` * COMMENT '',
+	CHANGE `` * COMMENT '';
+
+drop table if exists pro_sorder_shop;
+CREATE TABLE `pro_sorder_shop` (
+ `id` int(11) unsigned NOT NULL,
+ `ship_contact` varchar(64) DEFAULT NULL COMMENT '연락처명',
+ `ship_mobile` varchar(21) DEFAULT NULL COMMENT '모바일번호',
+ `ship_method` varchar(32) DEFAULT NULL COMMENT '배송방식',
+ `shipfee_amt` decimal(20,4) DEFAULT 0.0000 COMMENT '배송비',
+ `ship_zip_code` varchar(21) DEFAULT NULL COMMENT '우편번호',
+ `ship_addr1` varchar(64) DEFAULT NULL COMMENT '주소1',
+ `ship_addr2` varchar(64) DEFAULT NULL COMMENT '주소2',
+ `paymethod` char(2) NOT NULL DEFAULT '0' COMMENT '결재방식',
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
+
+ALTER TABLE `dbr_sorder` 
+  ADD `paymethod` char(2) NOT NULL DEFAULT '0' COMMENT '결재방식' AFTER `is_locked`,
+  ADD `ship_addr2` varchar(64) DEFAULT NULL COMMENT '주소2' AFTER `is_locked`,
+  ADD `ship_addr1` varchar(64) DEFAULT NULL COMMENT '주소1' AFTER `is_locked`,
+  ADD `ship_zip_code` varchar(21) DEFAULT NULL COMMENT '우편번호' AFTER `is_locked`,
+  ADD `ship_fee` decimal(20,4) DEFAULT 0.0000 COMMENT '배송비' AFTER `is_locked`,
+  ADD `ship_method` varchar(32) DEFAULT NULL COMMENT '배송방식' AFTER `is_locked`,
+  ADD `ship_contact` varchar(64) DEFAULT NULL COMMENT '연락처명' AFTER `is_locked`;

+ 72 - 0
table-controls/테이블-replace.sql

@@ -0,0 +1,72 @@
+REPLACE INTO dbr_media
+    (id, media_no, media_date, user_id, branch_id, media_brand, media_name)
+VALUES
+    (1, '200101-0000', '20000101', 5, 1, 'item', 'blank_image');
+
+REPLACE INTO dbr_media_bd (id,  media_id, seq_no, image_type, bd_file_url) VALUES (1, 1, 1, 'big', '');
+REPLACE INTO dbr_media_bd (id,  media_id, seq_no, image_type, bd_file_url) VALUES (2, 1, 2, 'middle', '');
+REPLACE INTO dbr_media_bd (id,  media_id, seq_no, image_type, bd_file_url) VALUES (3, 1, 3, 'thumb', '');
+
+REPLACE INTO users
+    (id, email, password, activate_code, reset_code, nick_name, first_name, sur_name, status)
+VALUES
+    (1, SUBSTR(MD5(RAND()),1,20), 'unlinked', 'unlinked', 'unlinked', 'unlinked', 'unlinked', 'unlinked', '5');
+
+REPLACE INTO dbr_user_ext
+    (id, mobile_no, phone_no, user_perm_id, menu_lang_sw,
+    sgroup_id, branch_id, storage_id, agroup_id, country_code, is_expired)
+VALUES
+    (1, 'unlinked', 'unlinked', 7, 0, 
+    1, 1, 1, 1, 'ko_KR', '0');
+
+REPLACE INTO pro_member
+    (id, email, password, activate_code, reset_code, nick_name, first_name, sur_name, status, buyer_id)
+VALUES
+    (1, 'email-unlinked', 'unlinked', 'unlinked', 'unlinked', 'unlinked', 'unlinked', 'unlinked', '5', 1);
+
+REPLACE INTO pro_member
+    (id, email, password, activate_code, reset_code, nick_name, first_name, sur_name, status, sso_sub_id, is_member_app)
+VALUES
+    (2, 'ab64-app', 'ab64-app', 'unlinked', 'unlinked', 'unlinked', 'unlinked', 'unlinked', '5', 2, '1');
+
+REPLACE INTO pro_member
+    (id, email, password, activate_code, reset_code, nick_name, first_name, sur_name, status, sso_sub_id, is_member_app)
+VALUES
+    (3, 'api23-app', 'api23-app', 'unlinked', 'unlinked', 'unlinked', 'unlinked', 'unlinked', '5', 3, '1');
+
+REPLACE INTO pro_member_ext
+    (id, mobile_no, phone_no, member_perm_id, menu_lang_sw,
+    sgroup_id, branch_id, storage_id, agroup_id, country_code, is_expired)
+VALUES
+    (1, 'unlinked', 'unlinked', 7, 0, 
+    1, 1, 1, 1, 'ko_KR', '0');
+
+REPLACE INTO pro_member_ext
+    (id, mobile_no, phone_no, member_perm_id, menu_lang_sw,
+    sgroup_id, branch_id, storage_id, agroup_id, country_code, is_expired)
+VALUES
+    (2, 'unlinked', 'unlinked', 7, 0, 
+    1, 1, 1, 1, 'ko_KR', '0');
+
+REPLACE INTO pro_member_ext
+    (id, mobile_no, phone_no, member_perm_id, menu_lang_sw,
+    sgroup_id, branch_id, storage_id, agroup_id, country_code, is_expired)
+VALUES
+    (3, 'unlinked', 'unlinked', 7, 0, 
+    1, 1, 1, 1, 'ko_KR', '0');
+
+REPLACE INTO dbr_company
+    (id, created_on, updated_on, 
+    company_date, company_no, company_name, company_class, full_name 
+    )
+VALUES
+    (1, unix_timestamp(), unix_timestamp(),
+    '00000000', '000000-00', 'unlinked', 'AA', 'unlinked');
+
+REPLACE INTO pro_member_device
+    (id, created_on, activate_on,
+     member_id, device_ip, device_hash, device_desc, last_login_on, status )
+VALUES
+    (1, unix_timestamp(), unix_timestamp(),
+    1, 'unlinked', 'unlinked', 'unlinked', 0, '0');
+

+ 147 - 0
table-controls/테이블-truncate.sql

@@ -0,0 +1,147 @@
+truncate table dbr_item;
+truncate table dbr_item_thm;
+
+truncate table dbr_last_slip_no;
+truncate table pro_member;
+truncate table pro_member_app;
+truncate table pro_member_ext;
+truncate table dbr_company;
+
+truncate table dbr_squote;
+truncate table dbr_squote_bd;
+
+truncate table dbr_sorder;
+truncate table dbr_sorder_bd;
+
+truncate table dbr_last_slip_no;
+
+truncate table dbr_sorder;
+truncate table dbr_sorder_bd;
+truncate table dbr_sales;
+truncate table dbr_sales_bd;
+
+truncate table dbr_credit_bd;
+truncate table dbr_credit;
+
+truncate table dbr_genio_bd;
+truncate table dbr_genio;
+
+truncate table dbr_pquote_bd;
+truncate table dbr_pquote;
+truncate table dbr_porder_bd;
+truncate table dbr_porder;
+truncate table dbr_purch_bd;
+truncate table dbr_purch;
+
+truncate table dbr_credit;
+truncate table dbr_credit_bd;
+truncate table dbr_reward;
+truncate table dbr_reward_bd;
+
+truncate table dbr_bal_item;
+truncate table dbr_bal_buyer;
+truncate table dbr_bal_supplier;
+truncate table dbr_credit_bd;
+
+truncate table dbr_acc_slip;
+truncate table dbr_acc_slip_bd;
+
+truncate table dbr_pos_closing;
+
+truncate table dbt_log_access;
+truncate table dbt_list_type1;
+
+truncate table pro_post;
+
+truncate table crp_wallet;
+truncate table crp_wallet_token;
+
+truncate table pro_post;
+truncate table pro_post_bd;
+truncate table pro_sorder_shop;
+
+truncate table dbr_bal_reward;
+truncate table dbr_bal_supplier;
+truncate table dbr_bal_buyer;
+truncate table dbr_bal_acc_title;
+truncate table dbr_bal_credit;
+truncate table dbr_credit;
+truncate table dbr_credit_bd;
+truncate table dbr_customer_tie;
+truncate table dbr_customer_tie_bd;
+
+truncate table pro_company_contact_bd;
+truncate table pro_company_crcard_bd;
+truncate table pro_company_destina_bd;
+truncate table dbr_coupon;
+
+truncate table zdb_eyetest;
+truncate table zdb_sales;
+truncate table zdb_sorder;
+
+truncate table dbt_list_sum;
+truncate table dbt_list_type1;
+truncate table dbt_log_access;
+truncate table dbt_upload_type1;
+truncate table dbt_webcat_cart;
+
+truncate table main_sso_app;
+truncate table main_sso_app_bd;
+truncate table main_sso_app_log;
+
+truncate table pro_cart;
+
+truncate table pro_item_review;
+truncate table pro_item_review_bd;
+truncate table pro_item_revpro;
+truncate table pro_item_revsum;
+
+truncate table bcs_block;
+truncate table bcs_circulating;
+truncate table bcs_contract;
+truncate table bcs_dgn_holder;
+truncate table bcs_nft;
+truncate table bcs_token;
+truncate table bcs_token_holder;
+truncate table bcs_trans_inter;
+truncate table bcs_tranxn;
+truncate table bcs_txn_transfer;
+truncate table bcs_uncle_block;
+truncate table bcs_unconfirm;
+UPDATE bcs_last_sync_no SET last_sync_no = 0 where id = 1;
+
+truncate table bcm_contract;
+truncate table bcs_contract_abi;
+truncate table bcs_contract_sol;
+truncate table bcs_token_add;
+truncate table bcs_token_holder;
+
+truncate table fed_crystal_guest;
+truncate table fed_crystal_host;
+
+[개발설정용 테이블 테이블]-기본데이터 초기화에서는 Truncate 불가
+
+truncate table pro_item_revindex;
+
+truncate table dbr_media;
+truncate table dbr_media_bd;
+
+truncate table pro_widget_taxo;
+truncate table pro_widget_taxo_bd;
+truncate table pro_item_taxo;
+truncate table pro_item_taxo_bd;
+
+truncate table pro_member_device;
+truncate table pro_member_passwd;
+truncate table pro_member_log;
+
+[지우지 말아야 할 테이블]
+
+dbr_deal_type
+dbr_etc
+dbr_user_menu
+dbr_rpt_custom
+
+
+
+

+ 125 - 0
table-controls/테이블-unixtime-created.sql

@@ -0,0 +1,125 @@
+ALTER TABLE bcs_contract_sol CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE bcs_block CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE bcs_token_add CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE bcs_contract_abi CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE bcs_token_holder CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE crm_account CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE crm_account_item CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_acc_slip CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_acc_slip_bd CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_agroup CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_app_slip CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_bal_buyer CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_bal_item CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_bal_supplier CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_branch CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_post CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_wish CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_cgroup CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_sorder_shop CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_coupon CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_cpack CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_credit CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE users CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_credit_bd CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_bal_credit CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_customer_tie CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_customer_tie_bd CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_deal_type CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_etc CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_genio CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_genio_bd CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_global CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_rpt_custom CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_iheader CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_item CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_last_slip_no CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_media CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_media_bd CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_porder CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_stock_io CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE bcs_trans_inter CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_pquote CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_widget_taxo CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_pquote_bd CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_item_taxo CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_purch CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_purch_bd CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_sales CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_sales_bd CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE crm_project CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_sgroup CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE upt_dbupdate CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbt_list_sum CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_pos_closing CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_sorder_bd CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE zdb_sorder CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbt_upload_type1 CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE main_sso_app_bd CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_storage CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_text_template CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE bcs_tranxn CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE zdb_eyetest CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_sorder CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_user_ext CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE zdb_sales CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_user_perm CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_user_perm_bd CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_vat_rate CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE zdb_item CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_app_guest CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE upt_encrypt CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE main_sso_app_log CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE crp_net_group CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_cart CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_guest_log CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_member_ext CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_member_perm CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_member_perm_bd CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE bcs_uncle_block CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_ticket_bd CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_widget_taxo_bd CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_member_app CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_member CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE bcs_contract CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE bcs_token CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_bal_acc CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_reward_bd CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_app_perm CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE crp_token_group CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbt_webcat_cart CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE main_sso_app CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbt_log_access CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE crp_wallet_token CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_daily_calc CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_reward CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE bcs_nft CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_post_bd CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_app_perm_bd CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE bcs_last_sync_no CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE bcm_contract CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_app_api CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_company_contact_bd CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_bal_reward CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE crp_wallet CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_acc_code CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE log_branch_closing CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_setup CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_company CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_member_dormant CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_squote CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE zdb_supplier CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_post_type CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_item_taxo_bd CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_squote_bd CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE zdb_buyer CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_sorder_bd_ship CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_igroup CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_user_menu CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_company_crcard_bd CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbt_list_type1 CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_company_destina_bd CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE log_procedure_run CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_porder_bd CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_member_menu CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE zdb_nonitem CHANGE `created_on` `created_on` BIGINT(20) NULL DEFAULT '0';

+ 97 - 0
table-controls/테이블-unixtime-updated.sql

@@ -0,0 +1,97 @@
+ALTER TABLE crm_account CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE crm_account_item CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_acc_slip CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_acc_slip_bd CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_agroup CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_app_slip CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_bal_buyer CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_bal_item CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_bal_supplier CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_branch CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_post CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_wish CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_cgroup CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_sorder_shop CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_coupon CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_cpack CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_credit CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE users CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_credit_bd CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_bal_credit CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_customer_tie CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_customer_tie_bd CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_deal_type CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_etc CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_genio CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_genio_bd CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_global CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_rpt_custom CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_iheader CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_item CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_last_slip_no CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_media CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_media_bd CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_porder CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_stock_io CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_pquote CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_widget_taxo CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_pquote_bd CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_item_taxo CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_purch CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_purch_bd CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_sales CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_sales_bd CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE crm_project CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_sgroup CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE upt_dbupdate CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_sorder_bd CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE main_sso_app_bd CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_storage CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_text_template CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_sorder CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_user_ext CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_user_perm CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_user_perm_bd CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_vat_rate CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_app_guest CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE upt_encrypt CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE crp_net_group CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_cart CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_guest_log CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_member_ext CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_member_perm CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_member_perm_bd CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_ticket_bd CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_widget_taxo_bd CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_member_app CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_member CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_bal_acc CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_reward_bd CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_app_perm CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE crp_token_group CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbt_webcat_cart CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE main_sso_app CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE crp_wallet_token CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_reward CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_post_bd CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_app_perm_bd CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE bcm_contract CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_app_api CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_company_contact_bd CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_bal_reward CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE crp_wallet CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_acc_code CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_setup CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_company CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_member_dormant CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_squote CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_post_type CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_item_taxo_bd CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_squote_bd CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_sorder_bd_ship CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_igroup CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_user_menu CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_company_crcard_bd CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_company_destina_bd CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE dbr_porder_bd CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';
+ALTER TABLE pro_member_menu CHANGE `updated_on` `updated_on` BIGINT(20) NULL DEFAULT '0';

+ 30 - 0
table-controls/테이블-update-default.sql

@@ -0,0 +1,30 @@
+update pro_post set member_id = 1 where member_id = 0;
+update pro_post set user_id = 1 where user_id = 0;
+update pro_post set media_id = 1 where media_id = 0;
+
+update dbr_item set media_id = 1 where media_id = 0;
+update dbr_item set igroup_id = 1 where igroup_id = 0;
+
+update dbr_item_thm set media_id1 = 1 where media_id1 = 0;
+update dbr_item_thm set media_id2 = 1 where media_id2 = 0;
+update dbr_item_thm set media_id3 = 1 where media_id3 = 0;
+update dbr_item_thm set media_id4 = 1 where media_id4 = 0;
+update dbr_item_thm set media_id5 = 1 where media_id5 = 0;
+
+update dbr_sorder set user_id = 1 where user_id = 0;
+update dbr_sorder set branch_id = 1 where branch_id = 0;
+update dbr_sorder set storage_id = 1 where storage_id = 0;
+update dbr_sorder set sgroup_id = 1 where sgroup_id = 0;
+update dbr_sorder set vat_rate_id = 1 where vat_rate_id = 0;
+update dbr_sorder set project_id = 1 where project_id = 0;
+update dbr_sorder set deal_type_id = 1 where deal_type_id = 0;
+update dbr_sorder set sgroup2_id = 1 where sgroup2_id = 0;
+
+update dbr_porder set user_id = 1 where user_id = 0;
+update dbr_porder set branch_id = 1 where branch_id = 0;
+update dbr_porder set storage_id = 1 where storage_id = 0;
+update dbr_porder set sgroup_id = 1 where sgroup_id = 0;
+update dbr_porder set vat_rate_id = 1 where vat_rate_id = 0;
+update dbr_porder set deal_type_id = 1 where deal_type_id = 0;
+
+UPDATE `dbr_company` SET is_deal_end = '0';

Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů