p_dailyWarehousingInfo_inTB_IF_IncomeLot.sql 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. CREATE procedure [dbo].[p_dailyWarehousingInfo_inTB_IF_IncomeLot]
  2. (@arg_date varchar(8)
  3. , @arg_insertno int
  4. , @rtn_cnt int output)
  5. as
  6. /******************************변수값 SETTING****************************/
  7. declare @exist_cnt int
  8. set @exist_cnt = 0
  9. set @rtn_cnt = 0
  10. /*************************************************************************/
  11. /* 수불일을 Argument로 넘어오지 않을시 현재일 -1일 Date를 마감처리한다 */
  12. if @arg_date = '' or @arg_date is null
  13. begin
  14. select @arg_date = convert(char(8), getdate() -1, 112)
  15. end
  16. /* 처리자가 Argument로 넘어오지 않을시 SYSTEM 계정으로 처리한다 */
  17. if @arg_insertno = 0 or @arg_insertno is null
  18. begin
  19. set @arg_insertno = 1
  20. end
  21. -- select @arg_date, @arg_insertno
  22. -- return
  23. /* 기존에 동일날짜에 대한 수불Data가 있는 경우 삭제처리한다. */
  24. select @exist_cnt = count(*)
  25. from istyle24_wmsif.dbo.TB_IF_IncomeLotItem with (nolock)
  26. where DateIncome = istyle24_wms.dbo.f_chartodate(@arg_date)
  27. if (@exist_cnt > 0)
  28. begin
  29. delete from istyle24_wmsif.dbo.TB_IF_IncomeLotItem with (rowlock)
  30. where DateIncome = istyle24_wms.dbo.f_chartodate(@arg_date)
  31. delete from istyle24_wmsif.dbo.TB_IF_IncomeLot with (rowlock)
  32. where DateIncome = istyle24_wms.dbo.f_chartodate(@arg_date)
  33. end
  34. BEGIN TRY
  35. /* 입고정보 M */
  36. insert istyle24_wmsif.dbo.TB_IF_IncomeLot with (rowlock)
  37. (
  38. LotNo
  39. ,PurchaseNo
  40. ,ProviderNo
  41. ,ProviderName
  42. ,BrandNo
  43. ,BrandName
  44. ,DateIncome
  45. )
  46. select distinct
  47. a.in_no
  48. ,b.pur_no
  49. ,a.entp_no
  50. ,a.entp_nm
  51. ,a.brand_no
  52. ,c.brandname
  53. ,istyle24_wms.dbo.f_chartodate(@arg_date)
  54. from istyle24_wms.dbo.tloin01m a with (nolock)
  55. join istyle24_wms.dbo.tloin01d b with (nolock)
  56. on (a.in_no = b.in_no)
  57. join istyle24_wmsif.dbo.tb_if_brand c with(nolock)
  58. on (a.brand_no = c.BrandNo)
  59. where a.insert_date >= convert(datetime, @arg_date, 112)
  60. and a.insert_date < convert(datetime, @arg_date, 112) + 1
  61. /* 입고정보 D */
  62. insert istyle24_wmsif.dbo.TB_IF_IncomeLotItem with (rowlock)
  63. (
  64. LotNo
  65. ,WMSItemNo
  66. ,DateIncome
  67. ,ProductNo
  68. ,ProductCode
  69. ,ProductName
  70. ,SKUCode
  71. ,NormalQty
  72. ,BrokenQty
  73. ,TotalQty
  74. )
  75. select b.in_no
  76. ,b.in_seq
  77. ,istyle24_wms.dbo.f_chartodate(@arg_date)
  78. ,b.product_no
  79. ,c.productcode
  80. ,c.productname
  81. ,b.sku_code
  82. ,isnull(b.in_qty_old,0) + isnull(b.sample_qty_old,0)
  83. ,isnull(b.in_bqty_old,0)
  84. ,isnull(b.in_qty_old,0) + isnull(b.sample_qty_old,0) + isnull(b.in_bqty_old,0)
  85. from istyle24_wms.dbo.tloin01d b with (nolock)
  86. join istyle24_wmsif.dbo.tb_if_product c with(nolock)
  87. on (b.product_no = c.productno)
  88. where b.insert_date >= convert(datetime, @arg_date, 112)
  89. and b.insert_date < convert(datetime, @arg_date, 112) + 1
  90. /* 입고 수정 D */
  91. insert istyle24_wmsif.dbo.TB_IF_IncomeLotItem with (rowlock)
  92. (
  93. LotNo
  94. ,WMSItemNo
  95. ,DateIncome
  96. ,ProductNo
  97. ,ProductCode
  98. ,ProductName
  99. ,SKUCode
  100. ,NormalQty
  101. ,BrokenQty
  102. ,TotalQty
  103. )
  104. select b.in_no
  105. ,b.in_seq
  106. ,istyle24_wms.dbo.f_chartodate(@arg_date)
  107. ,b.product_no
  108. ,c.productcode
  109. ,c.productname
  110. ,b.sku_code
  111. ,isnull(b.modify_aqty,0)
  112. ,isnull(b.modify_bqty,0)
  113. ,isnull(b.modify_aqty,0) + isnull(b.modify_bqty,0)
  114. from istyle24_wms.dbo.tloin02d b with (nolock)
  115. join istyle24_wmsif.dbo.tb_if_product c with(nolock)
  116. on (b.product_no = c.productno)
  117. join istyle24_wms.dbo.tloin01m a with (nolock)
  118. on (a.in_no = b.in_no
  119. and a.insert_date >= convert(datetime, '20090426', 112) )
  120. where b.insert_date >= convert(datetime, @arg_date, 112)
  121. and b.insert_date < convert(datetime, @arg_date, 112) + 1
  122. END TRY
  123. BEGIN CATCH
  124. END CATCH