f_insert_0_mtrlware.srf 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. $PBExportHeader$f_insert_0_mtrlware.srf
  2. global type f_insert_0_mtrlware from function_object
  3. end type
  4. forward prototypes
  5. global function integer f_insert_0_mtrlware (ref long arg_mtrlwareid, long arg_mtrlid, string arg_mtrlcode, long arg_storageid, long arg_sptid, string arg_status, string arg_woodcode, string arg_pcode, string arg_plancode, string arg_mtrlcuscode, string arg_location, decimal arg_cost, ref string arg_msg)
  6. end prototypes
  7. global function integer f_insert_0_mtrlware (ref long arg_mtrlwareid, long arg_mtrlid, string arg_mtrlcode, long arg_storageid, long arg_sptid, string arg_status, string arg_woodcode, string arg_pcode, string arg_plancode, string arg_mtrlcuscode, string arg_location, decimal arg_cost, ref string arg_msg);Int rslt = 1
  8. Long cnt
  9. Long ls_mtrlwareid,ls_scid
  10. int li_storMtrlprp
  11. SELECT count(*) INTO :cnt FROM u_mtrlware
  12. WHERE mtrlid = :arg_mtrlid
  13. AND storageid = :arg_storageid
  14. AND sptid = :arg_sptid
  15. AND dxflag = 0
  16. AND woodcode = :arg_woodcode
  17. AND pcode = :arg_pcode
  18. AND status = :arg_status
  19. AND plancode = :arg_plancode
  20. AND mtrlcuscode = :arg_mtrlcuscode
  21. AND Location = :arg_location;
  22. IF sqlca.SQLCode <> 0 THEN
  23. arg_msg = '查询物料:'+arg_mtrlcode+'是否有库存失败,请检查'
  24. rslt = 0
  25. GOTO ext
  26. END IF
  27. IF cnt = 1 THEN
  28. SELECT mtrlwareid INTO :ls_mtrlwareid FROM u_mtrlware
  29. WHERE mtrlid = :arg_mtrlid
  30. AND storageid = :arg_storageid
  31. AND sptid = :arg_sptid
  32. AND dxflag = 0
  33. AND woodcode = :arg_woodcode
  34. AND pcode = :arg_pcode
  35. AND status = :arg_status
  36. AND plancode = :arg_plancode
  37. AND mtrlcuscode = :arg_mtrlcuscode
  38. AND Location = :arg_location;
  39. IF sqlca.SQLCode <> 0 THEN
  40. arg_msg = '查询物料:'+arg_mtrlcode+'是否有库存失败,请检查'
  41. rslt = 0
  42. GOTO ext
  43. END IF
  44. arg_mtrlwareid = ls_mtrlwareid
  45. GOTO ext
  46. END IF
  47. SELECT scid,Mtrlprp INTO :ls_scid,:li_storMtrlprp
  48. FROM u_storage
  49. Where storageid = :arg_storageid;
  50. IF sqlca.SQLCode <> 0 THEN
  51. arg_msg = '查询仓库分部失败,请检查'
  52. rslt = 0
  53. GOTO ext
  54. END IF
  55. IF arg_cost = 0 THEN
  56. SELECT planprice INTO :arg_cost
  57. FROM u_mtrldef_planprice
  58. Where mtrlid = :arg_mtrlid
  59. and status = :Arg_status
  60. and woodcode = :arg_woodcode
  61. and pcode = :arg_pcode;
  62. IF sqlca.SQLCode = -1 THEN
  63. arg_msg = '查询计划价失败!!'
  64. rslt = 0
  65. GOTO ext
  66. elseif sqlca.sqlcode = 100 then
  67. arg_cost = 0
  68. END IF
  69. END IF
  70. ls_mtrlwareid = f_sys_scidentity(ls_scid,"u_mtrlware","mtrlwareid",arg_msg,TRUE,id_sqlca)
  71. INSERT INTO u_mtrlware(scid,
  72. mtrlwareid,
  73. mtrlid,
  74. storageid,
  75. noallocqty,
  76. woodcode,
  77. pcode,
  78. plancode,
  79. status,
  80. sptid,
  81. cost,
  82. mtrlcuscode,
  83. location,
  84. storMtrlprp)
  85. VALUES(:ls_scid,
  86. :ls_mtrlwareid,
  87. :arg_mtrlid,
  88. :arg_storageid,
  89. 0,
  90. :arg_woodcode,
  91. :arg_pcode,
  92. :arg_plancode,
  93. :arg_status,
  94. :arg_sptid,
  95. :arg_cost,
  96. :arg_mtrlcuscode,
  97. :arg_location,
  98. :li_storMtrlprp);
  99. IF sqlca.SQLCode <> 0 THEN
  100. arg_msg = '物料:'+arg_mtrlcode+'加0库存失败或物料已经有库存,请检查'+sqlca.SQLErrText
  101. rslt = 0
  102. GOTO ext
  103. END IF
  104. arg_mtrlwareid = ls_mtrlwareid
  105. ext:
  106. IF rslt = 0 THEN
  107. ROLLBACK;
  108. ELSE
  109. COMMIT;
  110. END IF
  111. RETURN rslt
  112. end function