lt1-stock-io-sum-bal.sql 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. truncate table dbt_list_type1;
  2. drop procedure if exists lt1_stock_io_sum_bal;
  3. DELIMITER //
  4. create procedure lt1_stock_io_sum_bal( _listToken varchar(21), _sdate varchar(8), _edate varchar(8),
  5. _s1 varchar(32), _e1 varchar(32), _s2 varchar(32), _e2 varchar(32),
  6. _s3 varchar(32), _e3 varchar(32), _s4 varchar(32), _e4 varchar(32),
  7. _having varchar(386), _orderby varchar(64),
  8. _branch int, _storage int, _member_company_id int, _lt_filter int)
  9. SQL SECURITY INVOKER
  10. BEGIN
  11. Declare _sbal_date varchar(8);
  12. Declare _ebal_date varchar(8);
  13. Declare _sbet1 varchar(64);
  14. Declare _ebet1 varchar(64);
  15. Declare _sbet2 varchar(64);
  16. Declare _ebet2 varchar(64);
  17. Declare _sbet3 varchar(64);
  18. Declare _ebet3 varchar(64);
  19. if _is_first_date(_sdate) then
  20. set _sbal_date = '19000101';
  21. set _ebal_date = '19000101';
  22. else
  23. set _sbal_date = _sdate;
  24. set _ebal_date = _edate;
  25. end if;
  26. if _s1 != '' and _e1 != '' then
  27. set _sbet1 = _s1;
  28. set _ebet1 = _e1;
  29. else
  30. set _sbet1 = '!';
  31. set _ebet1 = '힣';
  32. end if;
  33. if _s2 != '' and _e2 != '' then
  34. set _sbet2 = _s2;
  35. set _ebet2 = _e2;
  36. else
  37. set _sbet2 = '!';
  38. set _ebet2 = '힣';
  39. end if;
  40. if _s3 != '' and _e3 != '' then
  41. set _sbet3 = _s3;
  42. set _ebet3 = _e3;
  43. else
  44. set _sbet3 = '!';
  45. set _ebet3 = '힣';
  46. end if;
  47. insert into dbt_list_type1
  48. ( created_on, list_token, h_id, id, c1, c2, c3,
  49. d1, d2, d3, d4, d5,
  50. d6, c4, c5, order_by )
  51. select unix_timestamp(), _listToken, item_id, item_id, item_code, item_name, sub_name,
  52. begin_bal_qty, in_sum_qty, out_sum_qty, end_bal_qty, (bad_end_bal_qty - bad_begin_bal_qty),
  53. bad_end_bal_qty, igroup_name, igroup_code, item_code
  54. from dbr_bal_item as mx
  55. inner join dbr_item as itm on itm.id = mx.item_id
  56. inner join dbr_igroup as igr on igr.id = itm.igroup_id
  57. where yyyy_mm = _curr_month(_sdate) and storage_id = _storage
  58. and igroup_code between _sbet1 and _ebet1
  59. order by item_code asc;
  60. END;
  61. //
  62. DELIMITER ;