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

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