uo_outware_wfjg.sru 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962
  1. $PBExportHeader$uo_outware_wfjg.sru
  2. forward
  3. global type uo_outware_wfjg from nonvisualobject
  4. end type
  5. end forward
  6. global type uo_outware_wfjg from nonvisualobject
  7. end type
  8. global uo_outware_wfjg uo_outware_wfjg
  9. type variables
  10. PUBLIC PROTECTEDWRITE Long scid = 0 //分部id
  11. PUBLIC PROTECTEDWRITE Long outwareid //进仓单表自动增量id
  12. PUBLIC PROTECTEDWRITE String outwarecode //单据的唯一编号
  13. PUBLIC PROTECTEDWRITE Int billtype = 0 //业务类型
  14. PUBLIC PROTECTEDWRITE DateTime opdate //建立时间,自动
  15. PUBLIC PROTECTEDWRITE String opemp //建立操作员
  16. PUBLIC PROTECTEDWRITE DateTime moddate //修改时间,自动
  17. PUBLIC PROTECTEDWRITE String modemp //修改操作员
  18. PUBLIC PROTECTEDWRITE Int balcflag = 0 //仓库日结标志
  19. PUBLIC PROTECTEDWRITE Int flag = 0 //仓库审核标志
  20. PUBLIC PROTECTEDWRITE DateTime auditingdate //审核时间
  21. PUBLIC PROTECTEDWRITE String auditingrep //审核操作员
  22. Long relid = 0 //关联id
  23. DateTime outdate //进仓发生时间
  24. String outrep = '' //经手人
  25. String part = '' //相关号码
  26. String dscrp = '' //备注
  27. Long sptid = 0 //供应户id
  28. String sptname = '' //供应商名称 
  29. Int thflag = 0 //退货标记
  30. Boolean if_getid_ture = TRUE
  31. Transaction commit_transaction //数据commit事务
  32. s_outwaremx_wfjg outwaremx[] //明细结构数组
  33. Long it_mxbt = 0 //明细结构数组末指针
  34. Boolean it_newbegin = FALSE //新建标志
  35. Boolean it_updatebegin = FALSE //修改标志
  36. end variables
  37. forward prototypes
  38. public function integer newbegin (long arg_scid, integer arg_billtype, ref string arg_msg)
  39. public function integer save (boolean arg_ifcommit, ref string arg_msg)
  40. public function integer auditing (boolean arg_ifcommit, ref string arg_msg)
  41. public function integer updatebegin (long arg_scid, long arg_outwareid, integer arg_billtype, ref string arg_msg)
  42. public function integer getinfo (long arg_scid, long arg_outwareid, ref string arg_msg)
  43. public function integer del (long arg_scid, long arg_outwareid, ref string arg_msg, boolean arg_ifcommit)
  44. public function integer add_dscrp (long arg_scid, long arg_outwareid, string arg_newdescppart, ref string arg_msg)
  45. public function integer c_auditing (boolean arg_ifcommit, ref string arg_msg)
  46. public function integer p_clearmx ()
  47. public function integer p_getinfo (long arg_scid, long arg_outwareid, ref string arg_msg)
  48. public function integer p_reset ()
  49. public function integer p_update_sptware (long arg_mtrlwareid, long arg_mtrlid, string arg_mtrlcode, string arg_plancode, string arg_status, decimal arg_qty, decimal arg_costamt, decimal arg_planprice, long arg_sptid, string arg_woodcode, string arg_pcode, ref string arg_msg)
  50. public function integer uf_create_outware (boolean arg_ifcommit, ref string arg_msg)
  51. public function integer uf_destroy_outware (boolean arg_ifcommit, ref string arg_msg)
  52. public function integer acceptmx (long arg_mtrlwareid, decimal arg_uqty, string arg_uunit, decimal arg_qty, string arg_mxdscrp, long arg_printid, ref string arg_msg, integer arg_ifrel, long arg_relid, long arg_relprintid, long arg_mtrlid, long arg_storageid, integer arg_dxflag, string arg_plancode, string arg_mtrlcode, string arg_status, string arg_woodcode, string arg_pcode, decimal arg_fprice, decimal arg_rebate, long arg_sptid, decimal arg_rate, string arg_jgdscrp, string arg_mxdscrp2)
  53. public function integer acceptmx (long arg_mtrlwareid, decimal arg_uqty, string arg_uunit, decimal arg_qty, string arg_mxdscrp, long arg_printid, ref string arg_msg, integer arg_ifrel, long arg_relid, long arg_relprintid, decimal arg_rate, decimal arg_addqty, string arg_jgdscrp, string arg_mxdscrp2)
  54. end prototypes
  55. public function integer newbegin (long arg_scid, integer arg_billtype, ref string arg_msg);//====================================================================
  56. // Function: newbegin(long arg_scid,int arg_billtype,ref string arg_msg)
  57. //--------------------------------------------------------------------
  58. // Description: 从置对象,设定业务类型,准备建立新进仓单
  59. //--------------------------------------------------------------------
  60. // Arguments:
  61. // value long arg_scid
  62. // value integer arg_billtype
  63. // reference string arg_msg
  64. //--------------------------------------------------------------------
  65. // Returns: integer
  66. //--------------------------------------------------------------------
  67. // Author: yyx Date: 2003.11.12
  68. //--------------------------------------------------------------------
  69. // Modify History:
  70. //
  71. //====================================================================
  72. Int rslt = 1
  73. IF arg_scid < 0 THEN
  74. arg_msg = '请选择分部'
  75. rslt = 0
  76. GOTO ext
  77. END IF
  78. p_reset()
  79. billtype = arg_billtype
  80. scid = arg_scid
  81. it_newbegin = TRUE
  82. it_updatebegin = FALSE
  83. ext:
  84. IF rslt = 0 THEN p_reset()
  85. RETURN rslt
  86. end function
  87. public function integer save (boolean arg_ifcommit, ref string arg_msg);Integer rslt = 1,cnt = 0,i
  88. DateTime server_dt
  89. Long ls_newid
  90. String ls_sccode
  91. IF IsNull(relid) THEN relid = 0
  92. IF IsNull(outrep) THEN outrep = ''
  93. IF IsNull(dscrp) THEN dscrp = ''
  94. IF IsNull(part) THEN part = ''
  95. IF IsNull(sptid) THEN sptid = 0
  96. IF IsNull(sptname) THEN sptname = ''
  97. IF IsNull(thflag) THEN thflag = 0
  98. IF it_newbegin = False And it_updatebegin = False THEN
  99. rslt = 0
  100. arg_msg = "非编辑状态不可以提交"
  101. GOTO ext
  102. END IF
  103. SELECT Top 1 getdate() Into :server_dt From u_user Using commit_transaction ;
  104. //取得系统时间,借用操作员表
  105. IF commit_transaction.SQLCode <> 0 THEN
  106. rslt = 0
  107. arg_msg = "查询操作失败,日期 "
  108. GOTO ext
  109. END IF
  110. IF it_mxbt = 0 THEN //如果输入物料资料错则已经清空
  111. rslt = 0
  112. arg_msg = "没有正确进仓内容"
  113. GOTO ext
  114. END IF
  115. IF Year(Date(outdate)) < 2000 Or IsNull(outdate) THEN
  116. rslt = 0
  117. arg_msg = "缺少出仓发生时间或不合理"
  118. GOTO ext
  119. END IF
  120. //====================================================================
  121. // Script - save ( boolean arg_ifcommit, ref string arg_msg )
  122. // Reason:
  123. //--------------------------------------------------------------------
  124. // Modified By: yyx Date: 2004.01.02
  125. //--------------------------------------------------------------------
  126. IF DaysAfter(Date(String(server_dt,'yyyy-mm-dd')),Date(String(outdate,'yyyy-mm-dd'))) > sys_option_input_days THEN
  127. rslt = 0
  128. arg_msg = '出仓日期错误,日期不能超前系统日期'
  129. GOTO ext
  130. END IF
  131. IF DaysAfter(Date(String(outdate,'yyyy-mm-dd')),Date(String(server_dt,'yyyy-mm-dd'))) > sys_option_input_days THEN
  132. rslt = 0
  133. arg_msg = '出仓日期错误,日期不能落后系统日期'
  134. GOTO ext
  135. END IF
  136. //====================================================================
  137. SELECT name INTO :sptname
  138. FROM u_spt
  139. Where sptid = :sptid Using commit_transaction;
  140. IF commit_transaction.SQLCode <> 0 THEN
  141. rslt = 0
  142. arg_msg = "查询操作失败,加工商资料"
  143. GOTO ext
  144. END IF
  145. //检查 不能超过未发出数
  146. uo_order_wfjg uo_wfjg
  147. uo_wfjg = Create uo_order_wfjg
  148. uo_wfjg.commit_transaction = commit_transaction
  149. IF billtype = 5 THEN //车间外协发出
  150. FOR i = 1 To it_mxbt
  151. IF outwaremx[i].relid > 0 THEN
  152. IF uo_wfjg.check_addmxcmpl_out(scid,outwaremx[i].relid,outwaremx[i].mtrlid,0,outwaremx[i].status,&
  153. outwaremx[i].woodcode,outwaremx[i].pcode,outwaremx[i].qty,&
  154. arg_msg,False) = 0 THEN
  155. arg_msg = '第' + String(i) + '行,物料' +outwaremx[i].mtrlcode + ',' + arg_msg
  156. rslt = 0
  157. GOTO ext
  158. END IF
  159. END IF
  160. NEXT
  161. END IF
  162. ////////////////////////////////////////////// //开始区分:新建/更新 处理
  163. IF outwareid = 0 THEN //新建
  164. ls_newid = f_sys_scidentity(scid,"ow_wfjg_out","outwareid",arg_msg,if_getid_ture,commit_transaction)
  165. IF ls_newid <= 0 THEN
  166. rslt = 0
  167. GOTO ext
  168. END IF
  169. //取分部代号
  170. IF f_get_sccode(scid,commit_transaction,ls_sccode,arg_msg) = 0 THEN
  171. rslt = 0
  172. GOTO ext
  173. END IF
  174. //取得新单据编号
  175. CHOOSE CASE billtype
  176. CASE 4
  177. IF thflag = 0 THEN
  178. outwarecode = getid(scid,ls_sccode + 'WL',Date(server_dt),if_getid_ture,commit_transaction)
  179. ELSE
  180. outwarecode = getid(scid,ls_sccode + 'SL',Date(server_dt),if_getid_ture,commit_transaction)
  181. END IF
  182. CASE 5
  183. IF thflag = 0 THEN
  184. outwarecode = getid(scid,ls_sccode + 'WF',Date(server_dt),if_getid_ture,commit_transaction)
  185. ELSE
  186. outwarecode = getid(scid,ls_sccode + 'OF',Date(server_dt),if_getid_ture,commit_transaction)
  187. END IF
  188. CASE 9
  189. outwarecode = getid(scid,ls_sccode + 'WY',Date(server_dt),if_getid_ture,commit_transaction)
  190. END CHOOSE
  191. IF outwarecode = "err" THEN
  192. outwarecode = ''
  193. rslt = 0
  194. arg_msg = "无法获取出仓单编号"+"~n"+commit_transaction.SQLErrText
  195. GOTO ext
  196. END IF
  197. INSERT INTO ow_wfjg_out (
  198. scid,
  199. outwareid,
  200. outwarecode,
  201. billtype,
  202. relid,
  203. outdate,
  204. outrep,
  205. part,
  206. dscrp,
  207. sptid,
  208. sptname,
  209. thflag,
  210. opdate,
  211. opemp)
  212. VALUES (
  213. :scid,
  214. :ls_newid,
  215. :outwarecode,
  216. :billtype,
  217. :relid,
  218. :outdate,
  219. :outrep,
  220. :part,
  221. :dscrp,
  222. :sptid,
  223. :sptname,
  224. :thflag,
  225. :server_dt,
  226. :publ_operator
  227. ) Using commit_transaction ;
  228. IF commit_transaction.SQLCode <> 0 THEN
  229. rslt = 0
  230. IF Pos(Lower(commit_transaction.SQLErrText),'pk_ow_wfjg_out') > 0 THEN
  231. arg_msg = '插入操作失败,关键字分部ID、单据ID重复'
  232. ELSEIF Pos(Lower(commit_transaction.SQLErrText),'ix_ow_wfjg_inspt') > 0 THEN
  233. arg_msg = '插入操作失败,单据编号重复'
  234. ELSE
  235. arg_msg = "插入主表操作失败"+"~n"+commit_transaction.SQLErrText
  236. END IF
  237. GOTO ext
  238. END IF
  239. //读取新outwareid
  240. outwareid = ls_newid
  241. ELSE //////////////////////////////////////////////// //更新
  242. UPDATE ow_wfjg_out
  243. SET
  244. relid = :relid,
  245. outdate = :outdate,
  246. outrep = :outrep,
  247. part = :part,
  248. dscrp = :dscrp,
  249. sptid = :sptid,
  250. sptname = :sptname,
  251. thflag = :thflag,
  252. moddate = :server_dt,
  253. modemp = :publ_operator
  254. WHERE ow_wfjg_out.outwareid = :outwareid
  255. AND ow_wfjg_out.scid = :scid
  256. And flag = 0 Using commit_transaction;
  257. IF commit_transaction.SQLCode <> 0 Or commit_transaction.SQLNRows <= 0 THEN
  258. rslt = 0
  259. IF Pos(Lower(commit_transaction.SQLErrText),'pk_ow_wfjg_out') > 0 THEN
  260. arg_msg = '更新操作失败,关键字分部ID、单据ID重复'
  261. ELSEIF Pos(Lower(commit_transaction.SQLErrText),'ix_ow_wfjg_inspt') > 0 THEN
  262. arg_msg = '更新操作失败,单据编号重复'
  263. ELSE
  264. arg_msg = "更新主表操作失败"+"~n"+commit_transaction.SQLErrText
  265. END IF
  266. GOTO ext
  267. END IF
  268. //删除原有明细
  269. DELETE FROM ow_wfjgmx_out
  270. WHERE ow_wfjgmx_out.outwareid = :outwareid
  271. And ow_wfjgmx_out.scid = :scid Using commit_transaction;
  272. IF commit_transaction.SQLCode <> 0 THEN
  273. rslt = 0
  274. arg_msg = "删除旧有明细操作失败"+"~n"+commit_transaction.SQLErrText
  275. GOTO ext
  276. END IF
  277. END IF
  278. FOR i = 1 To it_mxbt
  279. INSERT INTO ow_wfjgmx_out
  280. (scid,
  281. storageid,
  282. outwareid,
  283. mtrlwareid,
  284. printid,
  285. mtrlid,
  286. plancode,
  287. status,
  288. woodcode,
  289. pcode,
  290. qty,
  291. fprice,
  292. rebate,
  293. price,
  294. mxdscrp,
  295. costamt,
  296. ifrel,
  297. relid,
  298. relprintid,
  299. relcode,
  300. cost,
  301. uqty,
  302. uunit,
  303. rate,
  304. uprice,
  305. addqty,
  306. jgdscrp,
  307. mxdscrp2)
  308. VALUES (
  309. :scid,
  310. :outwaremx[i].storageid,
  311. :outwareid,
  312. :outwaremx[i].mtrlwareid,
  313. :outwaremx[i].printid,
  314. :outwaremx[i].mtrlid,
  315. :outwaremx[i].plancode,
  316. :outwaremx[i].status,
  317. :outwaremx[i].woodcode,
  318. :outwaremx[i].pcode,
  319. :outwaremx[i].qty,
  320. :outwaremx[i].fprice,
  321. :outwaremx[i].rebate,
  322. :outwaremx[i].price,
  323. :outwaremx[i].mxdscrp,
  324. :outwaremx[i].costamt,
  325. :outwaremx[i].ifrel,
  326. :outwaremx[i].relid,
  327. :outwaremx[i].relprintid,
  328. :outwaremx[i].relcode,
  329. :outwaremx[i].cost,
  330. :outwaremx[i].uqty,
  331. :outwaremx[i].uunit,
  332. :outwaremx[i].rate,
  333. :outwaremx[i].uprice,
  334. :outwaremx[i].addqty,
  335. :outwaremx[i].jgdscrp,
  336. :outwaremx[i].mxdscrp2) Using commit_transaction;
  337. IF commit_transaction.SQLCode <> 0 THEN
  338. IF it_newbegin THEN outwareid = 0 //还原outwareid
  339. rslt = 0
  340. IF Pos(Lower(commit_transaction.SQLErrText),'pk_ow_wfjgmx_out') > 0 THEN
  341. arg_msg = '插入明细操作失败,关键字分部ID、单据ID、明细ID重复'
  342. ELSE
  343. arg_msg = "插入明细操作失败"+"~n"+commit_transaction.SQLErrText
  344. END IF
  345. GOTO ext
  346. END IF
  347. NEXT
  348. it_newbegin = False
  349. it_updatebegin = False
  350. ext:
  351. Destroy uo_wfjg
  352. IF rslt = 0 THEN
  353. ROLLBACK Using commit_transaction;
  354. p_clearmx()
  355. ELSEIF rslt = 1 And arg_ifcommit THEN
  356. COMMIT Using commit_transaction;
  357. END IF
  358. CHOOSE CASE billtype
  359. CASE 4
  360. IF thflag = 0 THEN
  361. arg_msg = '仓库外协发出单,'+ arg_msg
  362. ELSE
  363. arg_msg = '仓库外协退回单,'+ arg_msg
  364. END IF
  365. CASE 5
  366. IF thflag = 0 THEN
  367. arg_msg = '车间外协发出单,'+ arg_msg
  368. ELSE
  369. arg_msg = '车间外协退回单,'+ arg_msg
  370. END IF
  371. CASE 9
  372. arg_msg = '外协盘盈单,'+ arg_msg
  373. END CHOOSE
  374. RETURN rslt
  375. end function
  376. public function integer auditing (boolean arg_ifcommit, ref string arg_msg);Long rslt = 1,cnt = 0,i
  377. Dec new_noallocqty = 0
  378. Long ls_newid
  379. Long ll_orderid
  380. uo_order_wfjg uo_wfjg
  381. uo_wfjg = Create uo_order_wfjg
  382. uo_wfjg.commit_transaction = commit_transaction
  383. IF outwareid = 0 THEN
  384. rslt = 0
  385. arg_msg = "没有审核对象"
  386. GOTO ext
  387. END IF
  388. IF it_newbegin Or it_updatebegin THEN
  389. rslt = 0
  390. arg_msg = "编辑状态下不可以执行审核"
  391. GOTO ext
  392. END IF
  393. IF flag = 1 THEN
  394. rslt = 0
  395. arg_msg = "单据已经审核"
  396. GOTO ext
  397. END IF
  398. UPDATE ow_wfjg_out
  399. SET Auditingemp = :publ_operator,
  400. Auditingdate = getdate(),
  401. flag = 1
  402. WHERE ow_wfjg_out.outwareid = :outwareid
  403. AND flag = 0
  404. And scid = :scid Using commit_transaction;
  405. IF commit_transaction.SQLCode <> 0 THEN
  406. rslt = 0
  407. arg_msg = "因网络或其它原因导致审核单据操作失败"+"~n"+commit_transaction.SQLErrText
  408. GOTO ext
  409. ELSEIF commit_transaction.SQLNRows = 0 THEN
  410. rslt = 0
  411. arg_msg = "单据正在审核,请稍后查询。"
  412. GOTO ext
  413. END IF
  414. //生成出仓单
  415. IF billtype = 4 THEN
  416. IF uf_create_outware(False, arg_msg) = 0 THEN
  417. rslt = 0
  418. GOTO ext
  419. END IF
  420. END IF
  421. //更新供应商库存
  422. FOR i = 1 To it_mxbt
  423. IF p_update_sptware ( outwaremx[i].mtrlwareid, outwaremx[i].mtrlid, &
  424. outwaremx[i].mtrlcode, outwaremx[i].plancode,&
  425. outwaremx[i].status, outwaremx[i].qty, outwaremx[i].costamt,&
  426. outwaremx[i].planprice, sptid, &
  427. outwaremx[i].woodcode, outwaremx[i].pcode,arg_msg) = 0 THEN
  428. rslt = 0
  429. GOTO ext
  430. END IF
  431. IF outwaremx[i].relid > 0 THEN
  432. IF uo_wfjg.addmxcmpl_out(scid,outwaremx[i].relid,outwaremx[i].mtrlid,0,outwaremx[i].status,&
  433. outwaremx[i].woodcode,outwaremx[i].pcode,outwaremx[i].qty,&
  434. arg_msg,False) = 0 THEN
  435. arg_msg = '第' + String(i) + '行,物料' +outwaremx[i].mtrlcode + ',' + arg_msg
  436. rslt = 0
  437. GOTO ext
  438. END IF
  439. END IF
  440. NEXT
  441. flag = 1
  442. ext:
  443. Destroy uo_wfjg
  444. IF rslt = 0 THEN
  445. ROLLBACK Using commit_transaction;
  446. ELSEIF rslt = 1 And arg_ifcommit THEN
  447. COMMIT Using commit_transaction;
  448. END IF
  449. IF thflag = 0 THEN
  450. arg_msg = '仓库外协发出单,'+ arg_msg
  451. ELSE
  452. arg_msg = '仓库外协退回单,'+ arg_msg
  453. END IF
  454. RETURN rslt
  455. end function
  456. public function integer updatebegin (long arg_scid, long arg_outwareid, integer arg_billtype, ref string arg_msg);//====================================================================
  457. // Function: updatebegin(arg_scid,arg_inwareid,arg_billtype,arg_msg)
  458. //--------------------------------------------------------------------
  459. // Description: 从置对象,设定业务类型与关联ID,准备更新进仓单
  460. //--------------------------------------------------------------------
  461. // Arguments:
  462. // value long arg_scid
  463. // value long arg_inwareid
  464. // value integer arg_billtype
  465. // reference string arg_msg
  466. //--------------------------------------------------------------------
  467. // Returns: integer
  468. //--------------------------------------------------------------------
  469. // Author: yyx Date: 2003.11.12
  470. //--------------------------------------------------------------------
  471. // Modify History:
  472. //
  473. //====================================================================
  474. Long rslt = 1
  475. IF arg_scid < 0 THEN
  476. arg_msg = '请选择分部'
  477. rslt = 0
  478. GOTO ext
  479. END IF
  480. IF arg_outwareid <= 0 THEN
  481. rslt = 0
  482. GOTO ext
  483. END IF
  484. rslt = p_getinfo(arg_scid,arg_outwareid,arg_msg)
  485. IF rslt = 0 THEN GOTO ext
  486. IF flag = 1 THEN
  487. rslt = 0
  488. arg_msg = '单据已经审核,不可以修改'
  489. GOTO ext
  490. END IF
  491. outwareid = arg_outwareid
  492. billtype = arg_billtype
  493. scid = arg_scid
  494. it_newbegin = FALSE
  495. it_updatebegin = TRUE
  496. p_clearmx() //清除明细
  497. ext:
  498. IF rslt = 0 THEN p_reset()
  499. IF thflag = 0 THEN
  500. arg_msg = '仓库外协发出单,'+ arg_msg
  501. ELSE
  502. arg_msg = '仓库外协退回单,'+ arg_msg
  503. END IF
  504. RETURN rslt
  505. end function
  506. public function integer getinfo (long arg_scid, long arg_outwareid, ref string arg_msg);//getinfo(arg_scid,arg_outwareid,arg_msg)
  507. //0 失败 1成功
  508. Int rslt = 1,i = 1,no_mxcheck = 0
  509. IF arg_outwareid <= 0 THEN
  510. rslt = 0
  511. arg_msg = "非法出仓单唯一码"
  512. GOTO ext
  513. END IF
  514. rslt = p_getinfo(arg_scid,arg_outwareid,arg_msg)
  515. IF rslt = 0 THEN GOTO ext
  516. //用游标读取明细
  517. DECLARE cur_inwaermx CURSOR FOR
  518. SELECT ow_wfjgmx_out.printid,
  519. ow_wfjgmx_out.mtrlid,
  520. ow_wfjgmx_out.plancode,
  521. ow_wfjgmx_out.status,
  522. ow_wfjgmx_out.qty,
  523. ow_wfjgmx_out.fprice,
  524. ow_wfjgmx_out.rebate,
  525. ow_wfjgmx_out.price,
  526. ow_wfjgmx_out.mxdscrp,
  527. u_mtrldef.mtrlcode,
  528. u_mtrldef.unit,
  529. ow_wfjgmx_out.mtrlwareid,
  530. ow_wfjgmx_out.storageid,
  531. ow_wfjgmx_out.costamt,
  532. ow_wfjgmx_out.ifrel,
  533. ow_wfjgmx_out.relid,
  534. ow_wfjgmx_out.relprintid,
  535. ow_wfjgmx_out.woodcode,
  536. ow_wfjgmx_out.pcode,
  537. ow_wfjgmx_out.cost,
  538. ow_wfjgmx_out.uprice,
  539. ow_wfjgmx_out.uqty,
  540. ow_wfjgmx_out.rate,
  541. ow_wfjgmx_out.uunit,
  542. ow_wfjgmx_out.addqty,
  543. ow_wfjgmx_out.mxdscrp2
  544. FROM ow_wfjgmx_out,u_mtrldef,ow_wfjg_out
  545. WHERE ow_wfjg_out.outwareid = :arg_outwareid AND
  546. ow_wfjgmx_out.mtrlid = u_mtrldef.mtrlid AND
  547. ow_wfjg_out.scid = :arg_scid AND
  548. ow_wfjg_out.outwareid = ow_wfjgmx_out.outwareid AND
  549. ow_wfjg_out.scid = ow_wfjgmx_out.scid USING commit_transaction;
  550. OPEN cur_inwaermx;
  551. FETCH cur_inwaermx INTO
  552. :outwaremx[i].printid,:outwaremx[i].mtrlid,:outwaremx[i].plancode,
  553. :outwaremx[i].status,:outwaremx[i].qty,:outwaremx[i].fprice,
  554. :outwaremx[i].rebate,:outwaremx[i].price,
  555. :outwaremx[i].mxdscrp,:outwaremx[i].mtrlcode,:outwaremx[i].unit,
  556. :outwaremx[i].mtrlwareid,:outwaremx[i].storageid,
  557. :outwaremx[i].costamt,:outwaremx[i].ifrel,
  558. :outwaremx[i].relid,
  559. :outwaremx[i].relprintid,
  560. :outwaremx[i].woodcode,:outwaremx[i].pcode,
  561. :outwaremx[i].cost,:outwaremx[i].uprice,
  562. :outwaremx[i].uqty,
  563. :outwaremx[i].rate,
  564. :outwaremx[i].uunit,
  565. :outwaremx[i].addqty,
  566. :outwaremx[i].mxdscrp2;
  567. DO WHILE commit_transaction.SQLCode = 0
  568. i++
  569. FETCH cur_inwaermx INTO
  570. :outwaremx[i].printid,:outwaremx[i].mtrlid,:outwaremx[i].plancode,
  571. :outwaremx[i].status,:outwaremx[i].qty,:outwaremx[i].fprice,
  572. :outwaremx[i].rebate,:outwaremx[i].price,
  573. :outwaremx[i].mxdscrp,:outwaremx[i].mtrlcode,:outwaremx[i].unit,
  574. :outwaremx[i].mtrlwareid,:outwaremx[i].storageid,
  575. :outwaremx[i].costamt,:outwaremx[i].ifrel,
  576. :outwaremx[i].relid,
  577. :outwaremx[i].relprintid,
  578. :outwaremx[i].woodcode,:outwaremx[i].pcode,
  579. :outwaremx[i].cost,:outwaremx[i].uprice,
  580. :outwaremx[i].uqty,
  581. :outwaremx[i].rate,
  582. :outwaremx[i].uunit,
  583. :outwaremx[i].addqty,
  584. :outwaremx[i].mxdscrp2;
  585. LOOP
  586. CLOSE cur_inwaermx;
  587. //检验明细是否读入完整
  588. SELECT count(*) INTO :no_mxcheck
  589. FROM ow_wfjgmx_out
  590. WHERE ow_wfjgmx_out.outwareid = :arg_outwareid
  591. AND scid = :arg_scid USING commit_transaction;
  592. IF commit_transaction.SQLCode <> 0 THEN
  593. rslt = 0
  594. arg_msg = "查询操作失败,出仓单明细数量"
  595. GOTO ext
  596. END IF
  597. IF i <> (no_mxcheck+1) THEN
  598. rslt = 0
  599. arg_msg = "查询操作失败,出仓单明细"
  600. GOTO ext
  601. END IF
  602. outwareid = arg_outwareid
  603. scid = arg_scid
  604. it_mxbt = i - 1
  605. it_newbegin = FALSE
  606. it_updatebegin = FALSE
  607. ext:
  608. IF rslt = 0 THEN p_reset()
  609. RETURN rslt
  610. end function
  611. public function integer del (long arg_scid, long arg_outwareid, ref string arg_msg, boolean arg_ifcommit);//如果单据还没有审核删除单据极其明细
  612. //0 FAIL, 1 SUCCESS
  613. Int rslt = 1
  614. IF arg_outwareid <= 0 THEN
  615. rslt = 0
  616. arG_MSG = "没有删除对象,操作取消"
  617. GOTO ext
  618. END IF
  619. IF p_getinfo(arg_scid,arg_outwareid,arG_MSG) = 0 THEN
  620. rslt = 0
  621. GOTO ext
  622. END IF
  623. IF flag = 1 THEN
  624. rslt = 0
  625. arG_MSG = "单据已经审核,不可以删除"
  626. GOTO ext
  627. END IF
  628. DELETE FROM ow_wfjg_out
  629. WHERE ow_wfjg_out.outwareid = :arg_outwareid
  630. And ow_wfjg_out.scid = :arg_scid Using commit_transaction;
  631. IF commit_transaction.SQLCode <> 0 THEN
  632. rslt = 0
  633. arG_MSG = "删除进仓单操作失败"+"~n"+commit_transaction.SQLErrText
  634. GOTO ext
  635. END IF
  636. DELETE FROM ow_wfjgmx_out
  637. WHERE ow_wfjgmx_out.outwareid = :arg_outwareid
  638. And ow_wfjgmx_out.scid = :arg_scid Using commit_transaction;
  639. IF commit_transaction.SQLCode <> 0 THEN
  640. rslt = 0
  641. arG_MSG = "删除进仓单明细操作失败"+"~n"+commit_transaction.SQLErrText
  642. GOTO ext
  643. END IF
  644. it_newbegin = False
  645. it_updatebegin = False
  646. ext:
  647. IF rslt = 0 THEN
  648. ROLLBACK Using commit_transaction;
  649. p_reset()
  650. ELSEIF rslt = 1 And arg_ifcommit THEN
  651. COMMIT Using commit_transaction;
  652. END IF
  653. IF thflag = 0 THEN
  654. arG_MSG = '仓库外协发出单,'+ arG_MSG
  655. ELSE
  656. arG_MSG = '仓库外协退回单,'+ arG_MSG
  657. END IF
  658. Return (rslt)
  659. end function
  660. public function integer add_dscrp (long arg_scid, long arg_outwareid, string arg_newdescppart, ref string arg_msg);//add_dscrp(string arg_newdescppart)
  661. //0 fail 1 success
  662. Int rslt = 1
  663. arg_newdescppart = Trim(arg_newdescppart)
  664. //if it_updatebegin or it_newbegin then
  665. // rslt=0
  666. // arg_msg="编辑状态下不可用"
  667. // goto ext
  668. //end if
  669. IF arg_newdescppart = '' THEN
  670. rslt = 0
  671. arg_msg = "要添加内容为空,操作取消"
  672. GOTO ext
  673. END IF
  674. rslt = p_getinfo(arg_scid,arg_outwareid,arg_msg)
  675. IF rslt = 0 THEN GOTO ext
  676. IF flag = 0 THEN
  677. rslt = 0
  678. arg_msg = "非审核状态下不可用"
  679. GOTO ext
  680. END IF
  681. UPDATE ow_wfjg_out
  682. SET dscrp = dscrp+' '+:arg_newdescppart
  683. WHERE ow_wfjg_out.outwareid = :outwareid
  684. And scid = :scid Using commit_transaction;
  685. IF commit_transaction.SQLCode <> 0 THEN
  686. rslt = 0
  687. arg_msg = "添加单据备注操作失败"+"~n"+commit_transaction.SQLErrText
  688. GOTO ext
  689. END IF
  690. dscrp = dscrp+' '+arg_newdescppart
  691. ext:
  692. IF rslt = 0 THEN
  693. ROLLBACK Using commit_transaction;
  694. ELSE
  695. COMMIT Using commit_transaction;
  696. END IF
  697. IF thflag = 0 THEN
  698. arg_msg = '仓库外协发出单,'+ arg_msg
  699. ELSE
  700. arg_msg = '仓库外协退回单,'+ arg_msg
  701. END IF
  702. Return (rslt)
  703. end function
  704. public function integer c_auditing (boolean arg_ifcommit, ref string arg_msg);//====================================================================
  705. // Function: c_auditing(arg_ifcommit,arg_msg)
  706. //--------------------------------------------------------------------
  707. // Description:
  708. //--------------------------------------------------------------------
  709. // Arguments:
  710. // value boolean arg_ifcommit
  711. // reference string arg_msg
  712. //--------------------------------------------------------------------
  713. // Returns: integer
  714. //--------------------------------------------------------------------
  715. // Author: yyx Date: 2003.11.19
  716. //--------------------------------------------------------------------
  717. // Modify History:
  718. //
  719. //====================================================================
  720. Long rslt = 1,cnt = 0,i
  721. Long ls_newid
  722. DateTime null_dt
  723. SetNull(null_dt)
  724. uo_order_wfjg uo_wfjg
  725. uo_wfjg = Create uo_order_wfjg
  726. uo_wfjg.commit_transaction = commit_transaction
  727. IF outwareid = 0 THEN
  728. rslt = 0
  729. arg_msg = "没有审核对象"
  730. GOTO ext
  731. END IF
  732. IF it_newbegin Or it_updatebegin THEN
  733. rslt = 0
  734. arg_msg = "编辑状态下不可以执行审核"
  735. GOTO ext
  736. END IF
  737. IF flag = 0 THEN
  738. rslt = 0
  739. arg_msg = "单据还未审核"
  740. GOTO ext
  741. END IF
  742. IF balcflag = 1 THEN
  743. rslt = 0
  744. arg_msg = "单据已经日结,不能撤审"
  745. GOTO ext
  746. END IF
  747. UPDATE ow_wfjg_out
  748. SET Auditingemp = '',
  749. Auditingdate = :null_dt,
  750. flag = 0
  751. WHERE ow_wfjg_out.outwareid = :outwareid
  752. AND flag = 1
  753. And scid = :scid Using commit_transaction;
  754. IF commit_transaction.SQLCode <> 0 THEN
  755. rslt = 0
  756. arg_msg = "因网络或其它原因导致审核单据操作失败"+"~n"+commit_transaction.SQLErrText
  757. GOTO ext
  758. ELSEIF commit_transaction.SQLNRows = 0 THEN
  759. rslt = 0
  760. arg_msg = "单据正在撤审,请稍后查询。"
  761. GOTO ext
  762. END IF
  763. IF billtype = 4 THEN
  764. IF uf_destroy_outware(False, arg_msg) = 0 THEN
  765. rslt = 0
  766. GOTO ext
  767. END IF
  768. END IF
  769. FOR i = 1 To it_mxbt
  770. IF p_update_sptware ( outwaremx[i].mtrlwareid, outwaremx[i].mtrlid, &
  771. outwaremx[i].mtrlcode, outwaremx[i].plancode,&
  772. outwaremx[i].status, 0 - outwaremx[i].qty, 0 - outwaremx[i].costamt,&
  773. outwaremx[i].planprice, sptid, &
  774. outwaremx[i].woodcode, outwaremx[i].pcode,arg_msg) = 0 THEN
  775. rslt = 0
  776. GOTO ext
  777. END IF
  778. IF outwaremx[i].relid > 0 THEN
  779. IF uo_wfjg.addmxcmpl_out(scid,outwaremx[i].relid,outwaremx[i].mtrlid,0,outwaremx[i].status,&
  780. outwaremx[i].woodcode,outwaremx[i].pcode,0 - outwaremx[i].qty,&
  781. arg_msg,False) = 0 THEN
  782. rslt = 0
  783. GOTO ext
  784. END IF
  785. END IF
  786. NEXT
  787. flag = 0
  788. ext:
  789. Destroy uo_wfjg
  790. IF rslt = 0 THEN
  791. ROLLBACK Using commit_transaction;
  792. ELSEIF rslt = 1 And arg_ifcommit THEN
  793. COMMIT Using commit_transaction;
  794. END IF
  795. IF thflag = 0 THEN
  796. arg_msg = '仓库外协发出单,'+ arg_msg
  797. ELSE
  798. arg_msg = '仓库外协退回单,'+ arg_msg
  799. END IF
  800. RETURN rslt
  801. end function
  802. public function integer p_clearmx ();//int p_clearmx()
  803. //清除明细
  804. it_mxbt=0
  805. return 1
  806. end function
  807. public function integer p_getinfo (long arg_scid, long arg_outwareid, ref string arg_msg);//p_getinfo(arg_scid,arg_outwareid,arg_msg)
  808. //0 失败 1成功
  809. Int rslt = 1
  810. IF arg_outwareid <= 0 THEN
  811. rslt = 0
  812. arG_MSG = "非法出仓单唯一码"
  813. GOTO ext
  814. END IF
  815. SELECT ow_wfjg_out.outwarecode,
  816. ow_wfjg_out.billtype,
  817. ow_wfjg_out.relid,
  818. ow_wfjg_out.outdate,
  819. ow_wfjg_out.outrep,
  820. ow_wfjg_out.part,
  821. ow_wfjg_out.sptid,
  822. ow_wfjg_out.sptname,
  823. ow_wfjg_out.dscrp,
  824. ow_wfjg_out.thflag,
  825. ow_wfjg_out.flag,
  826. ow_wfjg_out.balcflag
  827. INTO :outwarecode,
  828. :billtype,
  829. :relid,
  830. :outdate,
  831. :outrep,
  832. :part,
  833. :sptid,
  834. :sptname,
  835. :dscrp,
  836. :thflag,
  837. :flag,
  838. :balcflag
  839. FROM ow_wfjg_out
  840. WHERE ow_wfjg_out.outwareid = :arg_outwareid
  841. AND scid = :arg_scid
  842. Using commit_transaction;
  843. IF commit_transaction.SQLCode <> 0 THEN
  844. rslt = 0
  845. IF Pos(Lower(commit_transaction.SQLErrText),'more than') > 0 THEN
  846. arG_MSG = '查询操作失败,查询数据返回值多于一个'
  847. ELSE
  848. arG_MSG = "查询操作失败(错误出仓单唯一码)"
  849. END IF
  850. GOTO ext
  851. END IF
  852. outwareid = arg_outwareid
  853. scid = arg_scid
  854. ext:
  855. IF rslt = 0 THEN p_reset()
  856. RETURN rslt
  857. end function
  858. public function integer p_reset ();//int p_reset()
  859. //清除对象及其明细
  860. scid = 0
  861. outwareid = 0
  862. outwarecode = ''
  863. billtype = 0
  864. opemp = ''
  865. modemp = ''
  866. auditingrep = ''
  867. flag = 0
  868. relid = 0
  869. //storageid = 0
  870. outrep = ''
  871. part = ''
  872. dscrp = ''
  873. sptid = 0
  874. sptname = ''
  875. thflag = 0
  876. it_newbegin = FALSE
  877. it_updatebegin = FALSE
  878. //清除明细
  879. p_clearmx()
  880. RETURN 1
  881. end function
  882. public function integer p_update_sptware (long arg_mtrlwareid, long arg_mtrlid, string arg_mtrlcode, string arg_plancode, string arg_status, decimal arg_qty, decimal arg_costamt, decimal arg_planprice, long arg_sptid, string arg_woodcode, string arg_pcode, ref string arg_msg);//外协商进仓
  883. Int rslt = 1
  884. Long ls_newid
  885. Decimal ld_cost
  886. //检查金额
  887. ld_cost = Round(arg_costamt / arg_qty, 5)
  888. //arg_sptid 供应商ID
  889. //IF sys_option_wfjgware_nocost = 0 THEN //核算金额
  890. UPDATE ow_wfjgware
  891. SET noallocqty = noallocqty + :arg_qty ,
  892. wareamt = case when :sys_option_wfjgware_nocost = 1 then 0
  893. else (case noallocqty + :arg_qty when 0 then 0
  894. else (case when (wareamt + :arg_costamt) * (noallocqty + :arg_qty) < 0 then 0 - (wareamt + :arg_costamt) else wareamt + :arg_costamt END) END) end,
  895. cost = case when :sys_option_wfjgware_nocost = 1 then 0
  896. else (case noallocqty + :arg_qty when 0 then cost
  897. else (case when round((wareamt + :arg_costamt)/(noallocqty + :arg_qty),:sys_option_cost_dec) < 0 then :ld_cost else round((wareamt + :arg_costamt)/(noallocqty + :arg_qty),:sys_option_cost_dec) END) END ) end,
  898. waredate = getdate(),
  899. indate = case when :arg_qty > 0 then getdate() else indate END,
  900. outdate = case when :arg_qty < 0 then getdate() else outdate END
  901. WHERE ( mtrlid = :arg_mtrlid )
  902. AND ( scid = :scid )
  903. AND (status = :arg_Status)
  904. AND woodcode = :arg_woodcode
  905. AND pcode = :arg_pcode
  906. AND plancode = :arg_plancode
  907. AND sptid = :arg_sptid
  908. Using commit_transaction ;
  909. IF commit_transaction.SQLCode = 0 THEN
  910. IF commit_transaction.SQLNRows = 0 THEN
  911. ls_newid = f_sys_scidentity(scid,"ow_wfjgware","mtrlwareid",arg_msg,False,commit_transaction)
  912. IF ls_newid <= 0 THEN
  913. rslt = 0
  914. GOTO ext
  915. END IF
  916. INSERT INTO ow_wfjgware
  917. ( scid,
  918. sptid,
  919. mtrlwareid,
  920. mtrlid,
  921. plancode,
  922. status,
  923. woodcode,
  924. pcode,
  925. noallocqty,
  926. allocqty,
  927. wareamt,
  928. cost,
  929. planprice,
  930. indate)
  931. VALUES (
  932. :scid,
  933. :arg_sptid,
  934. :ls_newid,
  935. :arg_mtrlid,
  936. :arg_plancode,
  937. :arg_status,
  938. :arg_woodcode,
  939. :arg_pcode,
  940. :arg_qty,
  941. 0,
  942. case when :sys_option_wfjgware_nocost = 1 then 0 else :arg_costamt end,
  943. case when :sys_option_wfjgware_nocost = 1 then 0 else :ld_cost end,
  944. :arg_planprice,
  945. getdate()) Using commit_transaction ;
  946. IF commit_transaction.SQLCode <> 0 THEN
  947. rslt = 0
  948. IF Pos(Lower(commit_transaction.SQLErrText),'pk_ow_wfjgware') > 0 THEN
  949. arg_msg = '插入外协商库存操作失败,关键字分部ID、库存ID重复'
  950. ELSE
  951. arg_msg = "物料["+arg_mtrlcode+"]外协商库存建立操作失败"+"~n"+commit_transaction.SQLErrText
  952. END IF
  953. GOTO ext
  954. END IF
  955. END IF
  956. ELSE
  957. rslt = 0
  958. String or_err_part = 'column insert or update conflicts with a rule imposed by a previous create rule statement'
  959. IF commit_transaction.SQLCode = 513 Or Pos(Lower(commit_transaction.SQLErrText),or_err_part) > 0 THEN
  960. arg_msg = "物料["+arg_mtrlcode+"]同外协商内同批号没有足够的库存支持冲减"
  961. ELSE
  962. arg_msg = "物料["+arg_mtrlcode+"]外协商库存更新操作失败,没有库存金额不支持冲减"+"~n"+commit_transaction.SQLErrText
  963. END IF
  964. GOTO ext
  965. END IF
  966. //--------------------更新结存
  967. Decimal ld_thqty,ld_thamt
  968. Decimal ld_inqty,ld_inamt
  969. Decimal ld_balcqty,ld_balcamt
  970. Decimal ld_pypkqty,ld_pypkamt
  971. ld_balcqty = arg_qty
  972. ld_balcamt = arg_costamt
  973. CHOOSE CASE billtype
  974. CASE 4,5
  975. IF thflag = 0 THEN
  976. ld_inqty = arg_qty
  977. ld_inamt = arg_costamt
  978. ld_thqty = 0
  979. ld_thamt = 0
  980. ld_pypkqty = 0
  981. ld_pypkamt = 0
  982. ELSE
  983. ld_inqty = 0
  984. ld_inamt = 0
  985. ld_thqty = 0 - arg_qty
  986. ld_thamt = 0 - arg_costamt
  987. ld_pypkqty = 0
  988. ld_pypkamt = 0
  989. END IF
  990. CASE 9
  991. ld_inqty = 0
  992. ld_inamt = 0
  993. ld_thqty = 0
  994. ld_thamt = 0
  995. ld_pypkqty = arg_qty
  996. ld_pypkamt = arg_costamt
  997. END CHOOSE
  998. UPDATE ow_wfjgbalc
  999. SET
  1000. balcqty = balcqty + :ld_balcqty,
  1001. balcamt = case when :sys_option_wfjgware_nocost = 1 then 0 else balcamt + :ld_balcamt end,
  1002. inqty = inqty + :ld_inqty,
  1003. inamt = case when :sys_option_wfjgware_nocost = 1 then 0 else inamt + :ld_inamt end,
  1004. thqty = thqty + :ld_thqty,
  1005. thamt = case when :sys_option_wfjgware_nocost = 1 then 0 else thamt + :ld_thamt end,
  1006. pypkqty = pypkqty + :ld_pypkqty,
  1007. pypkamt = case when :sys_option_wfjgware_nocost = 1 then 0 else pypkamt + :ld_pypkamt end
  1008. WHERE ( scid = :scid ) AND
  1009. ( sptid = :arg_sptid ) AND
  1010. ( mtrlid = :arg_mtrlid ) AND
  1011. ( balcdateint = 0 ) AND
  1012. ( status = :arg_status ) AND
  1013. ( woodcode = :arg_woodcode ) AND
  1014. ( pcode = :arg_pcode ) Using commit_transaction ;
  1015. IF commit_transaction.SQLCode = 0 THEN
  1016. IF commit_transaction.SQLNRows = 0 THEN
  1017. INSERT INTO ow_wfjgbalc
  1018. (scid,
  1019. balcdateint,
  1020. sptid,
  1021. mtrlid,
  1022. status,
  1023. woodcode,
  1024. pcode,
  1025. thqty,
  1026. thamt,
  1027. inqty,
  1028. inamt,
  1029. balcqty,
  1030. balcamt,
  1031. pypkqty,
  1032. pypkamt)
  1033. VALUES (:scid,
  1034. 0,
  1035. :arg_sptid,
  1036. :arg_mtrlid,
  1037. :arg_status,
  1038. :arg_woodcode,
  1039. :arg_pcode,
  1040. :ld_thqty,
  1041. case when :sys_option_wfjgware_nocost = 1 then 0 else :ld_thamt end,
  1042. :ld_inqty,
  1043. case when :sys_option_wfjgware_nocost = 1 then 0 else :ld_inamt end,
  1044. :ld_balcqty,
  1045. case when :sys_option_wfjgware_nocost = 1 then 0 else :ld_balcamt end,
  1046. :ld_pypkqty,
  1047. case when :sys_option_wfjgware_nocost = 1 then 0 else :ld_pypkamt end) Using commit_transaction;
  1048. IF commit_transaction.SQLCode <> 0 THEN
  1049. rslt = 0
  1050. IF Pos(Lower(commit_transaction.SQLErrText),'pk_ow_wfjgbalc') > 0 THEN
  1051. arg_msg = '插入外协商结存操作失败,关键字重复'
  1052. ELSE
  1053. arg_msg = "物料["+arg_mtrlcode+"]外协商结存建立操作失败"+"~n"+commit_transaction.SQLErrText
  1054. END IF
  1055. GOTO ext
  1056. END IF
  1057. END IF
  1058. ELSE
  1059. rslt = 0
  1060. or_err_part = 'column insert or update conflicts with a rule imposed by a previous create rule statement'
  1061. IF commit_transaction.SQLCode = 513 Or Pos(Lower(commit_transaction.SQLErrText),or_err_part) > 0 THEN
  1062. arg_msg = "物料["+arg_mtrlcode+"]同外协商内同批号没有足够的结存支持冲减"
  1063. ELSE
  1064. arg_msg = "物料["+arg_mtrlcode+"]外协商结存更新操作失败"+"~n"+commit_transaction.SQLErrText
  1065. END IF
  1066. GOTO ext
  1067. END IF
  1068. ext:
  1069. IF rslt = 0 THEN
  1070. ROLLBACK;
  1071. END IF
  1072. RETURN rslt
  1073. end function
  1074. public function integer uf_create_outware (boolean arg_ifcommit, ref string arg_msg);Int rslt = 1
  1075. Long lay_storageid[],ll_storageid,rst_outwareid
  1076. Boolean lb_f = False
  1077. Long i,j,k,ch,chc
  1078. Decimal lde_cost
  1079. uo_outware uo_out
  1080. uo_out = Create uo_outware
  1081. uo_out.commit_transaction = commit_transaction
  1082. uo_out.if_getid_ture = False
  1083. //统计仓库数量,确定出仓单数
  1084. FOR i = 1 To it_mxbt
  1085. FOR j = 1 To UpperBound(lay_storageid)
  1086. IF lay_storageid[j] = outwaremx[i].storageid THEN lb_f = True
  1087. NEXT
  1088. IF lb_f = False THEN
  1089. ch++
  1090. lay_storageid[ch] = outwaremx[i].storageid
  1091. END IF
  1092. lb_f = False
  1093. NEXT
  1094. FOR k = 1 To ch
  1095. ll_storageid = lay_storageid[k]
  1096. IF uo_out.newbegin(scid,4,arg_msg) = 0 THEN
  1097. rslt = 0
  1098. GOTO ext
  1099. END IF
  1100. uo_out.relid = outwareid
  1101. uo_out.outdate = outdate
  1102. uo_out.outrep = outrep
  1103. uo_out.part = outwarecode
  1104. uo_out.dscrp = dscrp
  1105. uo_out.cusname = '外协出仓'
  1106. uo_out.storageid = ll_storageid
  1107. uo_out.cusid = sptid
  1108. chc = 0
  1109. FOR i = 1 To it_mxbt
  1110. IF outwaremx[i].storageid <> ll_storageid THEN CONTINUE
  1111. chc++
  1112. IF uo_out.acceptmx(outwaremx[i].mtrlwareid,&
  1113. outwaremx[i].qty,outwaremx[i].addqty,outwaremx[i].price,1,&
  1114. outwaremx[i].mxdscrp,chc,arg_msg,&
  1115. 0,0,0,0,0,0,0,outwaremx[i].unit,1,'','') = 0 THEN
  1116. rslt = 0
  1117. GOTO ext
  1118. END IF
  1119. NEXT
  1120. IF uo_out.Save(False,arg_msg) = 0 THEN
  1121. rslt = 0
  1122. GOTO ext
  1123. END IF
  1124. rst_outwareid = uo_out.outwareid
  1125. //2.原事务审核出仓单
  1126. IF uo_out.getinfo( scid,rst_outwareid,arg_msg) = 0 THEN
  1127. rslt = 0
  1128. GOTO ext
  1129. END IF
  1130. IF uo_out.auditing(False,arg_msg) = 0 THEN
  1131. rslt = 0
  1132. GOTO ext
  1133. END IF
  1134. //用出仓的成本价更新外协发出单的库存成本价
  1135. FOR i = 1 To it_mxbt
  1136. IF outwaremx[i].storageid <> ll_storageid THEN CONTINUE
  1137. SELECT top 1 cost
  1138. INTO :lde_cost
  1139. FROM u_outwaremx
  1140. WHERE scid = :scid
  1141. AND outwareid = :rst_outwareid
  1142. AND mtrlwareid = :outwaremx[i].mtrlwareid
  1143. And unit = :outwaremx[i].unit;
  1144. IF sqlca.SQLCode <> 0 THEN
  1145. arg_msg = '查询对应出仓明细成本价失败,'+sqlca.SQLErrText
  1146. rslt = 0
  1147. GOTO ext
  1148. END IF
  1149. IF sys_option_2unit = 0 THEN
  1150. outwaremx[i].uprice = lde_cost
  1151. ELSE
  1152. outwaremx[i].uprice = Round(outwaremx[i].qty * lde_cost/outwaremx[i].uqty,5)
  1153. END IF
  1154. outwaremx[i].cost = lde_cost
  1155. outwaremx[i].costamt = Round(lde_cost * outwaremx[i].qty, 2)
  1156. outwaremx[i].fprice = lde_cost
  1157. outwaremx[i].price = lde_cost
  1158. UPDATE ow_wfjgmx_out
  1159. SET uprice = :outwaremx[i].uprice,
  1160. cost = :outwaremx[i].cost,
  1161. costamt = :outwaremx[i].costamt,
  1162. fprice = :outwaremx[i].fprice,
  1163. price = :outwaremx[i].price
  1164. WHERE scid = :scid
  1165. AND outwareid = :outwareid
  1166. And printid = :outwaremx[i].printid;
  1167. IF sqlca.SQLCode <> 0 THEN
  1168. arg_msg = '更新发出明细成本价失败,'+sqlca.SQLErrText
  1169. rslt = 0
  1170. GOTO ext
  1171. END IF
  1172. NEXT
  1173. NEXT
  1174. ext:
  1175. Destroy uo_out
  1176. IF rslt = 0 THEN
  1177. ROLLBACK Using commit_transaction;
  1178. ELSEIF arg_ifcommit THEN
  1179. COMMIT Using commit_transaction;
  1180. END IF
  1181. RETURN rslt
  1182. end function
  1183. public function integer uf_destroy_outware (boolean arg_ifcommit, ref string arg_msg);Int rslt = 1
  1184. Long i
  1185. Long ay_outwareid[],ll_outwareid,ch
  1186. DECLARE getoutware CURSOR FOR
  1187. SELECT outwareid FROM u_outware Where billtype = 4 AND relid = :outwareid USING commit_transaction;
  1188. OPEN getoutware;
  1189. DO WHILE commit_transaction.SQLCode = 0
  1190. FETCH getoutware INTO :ll_outwareid;
  1191. IF commit_transaction.SQLCode <> 0 THEN EXIT
  1192. ch++
  1193. ay_outwareid[ch] = ll_outwareid
  1194. LOOP
  1195. CLOSE getoutware;
  1196. uo_outware uo_out
  1197. uo_out = CREATE uo_outware
  1198. uo_out.commit_transaction = commit_transaction
  1199. uo_out.if_getid_ture = FALSE
  1200. FOR i = 1 TO ch
  1201. IF uo_out.getinfo(scid,ay_outwareid[i],arg_msg) = 0 THEN
  1202. rslt = 0
  1203. GOTO ext
  1204. END IF
  1205. IF uo_out.c_auditing(FALSE,arg_msg) = 0 THEN
  1206. rslt = 0
  1207. GOTO ext
  1208. END IF
  1209. IF uo_out.del(scid,ay_outwareid[i],arg_msg,FALSE) = 0 THEN
  1210. rslt = 0
  1211. GOTO ext
  1212. END IF
  1213. NEXT
  1214. ext:
  1215. destroy uo_out
  1216. IF rslt = 0 THEN
  1217. ROLLBACK USING commit_transaction;
  1218. ELSEIF arg_ifcommit THEN
  1219. COMMIT USING commit_transaction ;
  1220. END IF
  1221. RETURN rslt
  1222. end function
  1223. public function integer acceptmx (long arg_mtrlwareid, decimal arg_uqty, string arg_uunit, decimal arg_qty, string arg_mxdscrp, long arg_printid, ref string arg_msg, integer arg_ifrel, long arg_relid, long arg_relprintid, long arg_mtrlid, long arg_storageid, integer arg_dxflag, string arg_plancode, string arg_mtrlcode, string arg_status, string arg_woodcode, string arg_pcode, decimal arg_fprice, decimal arg_rebate, long arg_sptid, decimal arg_rate, string arg_jgdscrp, string arg_mxdscrp2);//外协盘盈,车间外协发出,退回 使用
  1224. Long rslt = 1,cnt = 0,LS_i
  1225. Decimal i_planprice,ld_dftsaleprice
  1226. decimal lde_cost
  1227. Double i_newprice
  1228. String ls_relcode
  1229. IF it_newbegin = False And it_updatebegin = False THEN
  1230. rslt = 0
  1231. arg_msg = "非编辑状态不可以使用,操作取消"
  1232. GOTO ext
  1233. END IF
  1234. //清除空值
  1235. IF IsNull(arg_mtrlwareid) THEN arg_mtrlwareid = 0
  1236. IF IsNull(arg_printid) THEN arg_printid = 0
  1237. IF IsNull(arg_qty) THEN arg_qty = 0
  1238. IF IsNull(arg_mxdscrp) THEN arg_mxdscrp = ''
  1239. IF IsNull(arg_ifrel) THEN arg_ifrel = 0
  1240. IF IsNull(arg_relid) THEN arg_relid = 0
  1241. IF IsNull(arg_mtrlid) THEN arg_mtrlid = 0
  1242. IF IsNull(arg_mtrlcode) THEN arg_mtrlcode = ''
  1243. IF IsNull(arg_plancode) THEN arg_plancode = ''
  1244. IF IsNull(arg_status) THEN arg_status = ''
  1245. IF IsNull(arg_fprice) THEN arg_fprice = 0
  1246. IF IsNull(arg_rebate) THEN arg_rebate = 0
  1247. IF IsNull(arg_mxdscrp) THEN arg_mxdscrp = ''
  1248. IF IsNull(arg_relid) THEN arg_relid = 0
  1249. IF IsNull(arg_relprintid) THEN arg_relprintid = 0
  1250. IF IsNull(arg_ifrel) THEN arg_ifrel = 0
  1251. IF IsNull(arg_mxdscrp) THEN arg_woodcode = ''
  1252. IF IsNull(arg_pcode) THEN arg_pcode = ''
  1253. IF IsNull(arg_storageid) THEN arg_storageid = 0
  1254. IF IsNull(arg_uqty) THEN arg_uqty = 0
  1255. IF IsNull(arg_uunit) THEN arg_uunit = ''
  1256. IF IsNull(arg_rate) THEN arg_rate = 1
  1257. IF IsNull(arg_jgdscrp) THEN arg_jgdscrp = ''
  1258. IF IsNull(arg_mxdscrp2) THEN arg_mxdscrp2 = ''
  1259. // 如果出仓数量为 0,或物料编号为空,则不作任何处理
  1260. IF arg_mtrlid = 0 Or arg_qty = 0 THEN
  1261. rslt = 1
  1262. GOTO ext
  1263. END IF
  1264. IF sys_option_2unit = 1 THEN
  1265. IF arg_uqty = 0 THEN
  1266. arg_msg = '行:'+String(arg_printid)+ ',请输入计价数量'
  1267. rslt = 0
  1268. GOTO ext
  1269. END IF
  1270. IF Trim(arg_uunit) = '' THEN
  1271. arg_msg = '行:'+String(arg_printid)+ ',请输入计价单位'
  1272. rslt = 0
  1273. GOTO ext
  1274. END IF
  1275. END IF
  1276. //检查物料id
  1277. SELECT planprice
  1278. INTO :i_planprice
  1279. FROM u_mtrldef
  1280. Where u_mtrldef.mtrlid = :arg_mtrlid Using commit_transaction ;
  1281. IF commit_transaction.SQLCode <> 0 THEN
  1282. rslt = 0
  1283. IF Pos(Lower(commit_transaction.SQLErrText),'more than') > 0 THEN
  1284. arg_msg = '查询物料资料操作失败,查询数据返回值多于一个'
  1285. ELSE
  1286. arg_msg = "查询操作失败,编码:"+arg_mtrlcode
  1287. END IF
  1288. GOTO ext
  1289. END IF
  1290. IF f_check_status(1, arg_status) = 0 THEN
  1291. rslt = 0
  1292. arg_msg = "查询操作失败,可能颜色未定义,编码:"+arg_mtrlcode+",颜色:"+arg_status
  1293. GOTO ext
  1294. END IF
  1295. IF arg_ifrel = 1 THEN
  1296. IF arg_relid = 0 THEN
  1297. rslt = 0
  1298. arg_msg = '请选择加工计划!'
  1299. GOTO ext
  1300. END IF
  1301. SELECT taskcode INTO :ls_relcode
  1302. FROM u_order_wfjg
  1303. Where wfjgID = :arg_relid Using commit_transaction;
  1304. IF commit_transaction.SQLCode <> 0 THEN
  1305. rslt = 0
  1306. arg_msg = '查询加工计划号失败!没有对应的外加工计划'
  1307. GOTO ext
  1308. END IF
  1309. SELECT count(*) INTO :cnt
  1310. FROM u_order_wfjgMx_out
  1311. WHERE wfjgid = :arg_relid
  1312. AND mtrlid = :arg_mtrlid
  1313. AND status = :arg_status
  1314. Using commit_transaction;
  1315. IF commit_transaction.SQLCode <> 0 THEN
  1316. rslt = 0
  1317. arg_msg = '查询加工计划出仓明细失败!,外加工计划没有对应物料明细'
  1318. GOTO ext
  1319. END IF
  1320. IF cnt = 0 THEN
  1321. rslt = 0
  1322. arg_msg = '出仓物料:'+arg_mtrlcode+'不在加工计划出仓明细中!'
  1323. GOTO ext
  1324. END IF
  1325. END IF
  1326. //***********************************************
  1327. IF thflag = 1 THEN
  1328. //退回单,取供应商库存单价
  1329. SELECT cost
  1330. INTO :lde_cost
  1331. FROM ow_wfjgware
  1332. WHERE ( scid = :scid )
  1333. AND sptid = :sptid
  1334. AND ( mtrlid = :arg_mtrlid )
  1335. AND (status = :arg_Status)
  1336. AND woodcode = :arg_woodcode
  1337. AND pcode = :arg_pcode
  1338. AND plancode = :arg_plancode
  1339. Using commit_transaction ;
  1340. IF commit_transaction.SQLCode <> 0 THEN
  1341. lde_cost = -1
  1342. END IF
  1343. IF lde_cost > 0 THEN
  1344. arg_fprice = lde_cost
  1345. END IF
  1346. END IF
  1347. IF arg_fprice * arg_rebate < 0 THEN //检查进仓价
  1348. rslt = 0
  1349. arg_msg = "编码:" + String(arg_mtrlcode)+" 单价错误"
  1350. GOTO ext
  1351. END IF
  1352. //IF sys_option_buyprice_type = 1 THEN
  1353. arg_plancode = arg_plancode
  1354. //ELSE
  1355. // arg_plancode = String(Round(arg_fprice * arg_rebate,10))
  1356. //END IF
  1357. //写入内容
  1358. it_mxbt++
  1359. outwaremx[it_mxbt].printid = arg_printid
  1360. outwaremx[it_mxbt].storageid = arg_storageid
  1361. outwaremx[it_mxbt].mtrlwareid = arg_mtrlwareid
  1362. outwaremx[it_mxbt].mtrlid = arg_mtrlid
  1363. outwaremx[it_mxbt].status = arg_status
  1364. outwaremx[it_mxbt].woodcode = arg_woodcode
  1365. outwaremx[it_mxbt].pcode = arg_pcode
  1366. outwaremx[it_mxbt].qty = arg_qty
  1367. IF sys_option_2unit = 0 THEN
  1368. IF arg_rate <> 0 THEN
  1369. arg_uqty = arg_qty/arg_rate
  1370. outwaremx[it_mxbt].uprice = Round(arg_qty * arg_fprice/arg_uqty,5)
  1371. outwaremx[it_mxbt].uqty = arg_uqty
  1372. ELSE
  1373. outwaremx[it_mxbt].uprice = arg_fprice
  1374. outwaremx[it_mxbt].uqty = arg_qty
  1375. END IF
  1376. ELSE
  1377. outwaremx[it_mxbt].uprice = Round(arg_qty * arg_fprice/arg_uqty,5)
  1378. outwaremx[it_mxbt].uqty = arg_uqty
  1379. END IF
  1380. outwaremx[it_mxbt].uunit = arg_uunit
  1381. outwaremx[it_mxbt].rate = arg_rate
  1382. outwaremx[it_mxbt].rebate = arg_rebate
  1383. outwaremx[it_mxbt].fprice = arg_fprice
  1384. outwaremx[it_mxbt].price = Round(arg_fprice * arg_rebate,10)
  1385. outwaremx[it_mxbt].cost = arg_fprice
  1386. outwaremx[it_mxbt].costamt = Round(arg_fprice * arg_qty,2)
  1387. outwaremx[it_mxbt].newpriceamt = Round(i_newprice * arg_qty,2)
  1388. outwaremx[it_mxbt].plancode = arg_plancode
  1389. outwaremx[it_mxbt].planprice = i_planprice
  1390. outwaremx[it_mxbt].mtrlcode = arg_mtrlcode
  1391. outwaremx[it_mxbt].mxdscrp = arg_mxdscrp
  1392. outwaremx[it_mxbt].mxdscrp2 = arg_mxdscrp2
  1393. outwaremx[it_mxbt].sptid = arg_sptid
  1394. outwaremx[it_mxbt].dxflag = arg_dxflag
  1395. outwaremx[it_mxbt].ifrel = arg_ifrel
  1396. outwaremx[it_mxbt].relid = arg_relid
  1397. outwaremx[it_mxbt].relprintid = arg_relprintid
  1398. outwaremx[it_mxbt].relcode = ls_relcode
  1399. outwaremx[it_mxbt].jgdscrp = arg_jgdscrp
  1400. ext:
  1401. IF rslt = 0 THEN p_clearmx()
  1402. IF thflag = 0 THEN
  1403. arg_msg = '车间外协发出单,'+ arg_msg
  1404. ELSE
  1405. arg_msg = '车间外协退回单,'+ arg_msg
  1406. END IF
  1407. RETURN rslt
  1408. end function
  1409. public function integer acceptmx (long arg_mtrlwareid, decimal arg_uqty, string arg_uunit, decimal arg_qty, string arg_mxdscrp, long arg_printid, ref string arg_msg, integer arg_ifrel, long arg_relid, long arg_relprintid, decimal arg_rate, decimal arg_addqty, string arg_jgdscrp, string arg_mxdscrp2);//仓库外协发出,退回 使用
  1410. Long rslt = 1,cnt = 0,LS_i
  1411. Long i_mtrlid,i_storageid,i_sptid
  1412. Int i_dxflag
  1413. String i_plancode,i_mtrlcode,i_status,i_woodcode,i_pcode
  1414. Decimal i_planprice,ld_dftsaleprice
  1415. Double i_cost,i_newprice, lde_cost
  1416. Decimal i_notauditqty,i_allouseqty,i_addqty
  1417. String ls_relcode
  1418. Decimal ld_rate = 1
  1419. IF it_newbegin = False And it_updatebegin = False THEN
  1420. rslt = 0
  1421. arg_msg = "非编辑状态不可以使用,操作取消"
  1422. GOTO ext
  1423. END IF
  1424. //清除空值
  1425. IF IsNull(arg_mtrlwareid) THEN arg_mtrlwareid = 0
  1426. IF IsNull(arg_printid) THEN arg_printid = 0
  1427. IF IsNull(arg_qty) THEN arg_qty = 0
  1428. IF IsNull(arg_uqty) THEN arg_uqty = 0
  1429. IF IsNull(arg_uunit) THEN arg_uunit = ''
  1430. IF IsNull(arg_mxdscrp) THEN arg_mxdscrp = ''
  1431. IF IsNull(arg_ifrel) THEN arg_ifrel = 0
  1432. IF IsNull(arg_relid) THEN arg_relid = 0
  1433. IF IsNull(arg_relprintid) THEN arg_relprintid = 0
  1434. IF IsNull(arg_rate) THEN arg_rate = 1
  1435. IF IsNull(arg_addqty) THEN arg_addqty = 0
  1436. IF IsNull(arg_jgdscrp) THEN arg_jgdscrp = ''
  1437. IF IsNull(arg_mxdscrp2) THEN arg_mxdscrp2 = ''
  1438. // 如果出仓数量为 0,或物料编号为空,则不作任何处理
  1439. IF arg_mtrlwareid = 0 Or arg_qty = 0 THEN
  1440. rslt = 1
  1441. GOTO ext
  1442. END IF
  1443. IF sys_option_2unit = 1 THEN
  1444. IF arg_uqty = 0 THEN
  1445. arg_msg = '行:'+String(arg_printid)+ ',请输入计价数量'
  1446. rslt = 0
  1447. GOTO ext
  1448. END IF
  1449. IF Trim(arg_uunit) = '' THEN
  1450. arg_msg = '行:'+String(arg_printid)+ ',请输入计价单位'
  1451. rslt = 0
  1452. GOTO ext
  1453. END IF
  1454. END IF
  1455. //检查物料库存ID
  1456. SELECT u_mtrlware.mtrlid,
  1457. u_mtrlware.storageid,
  1458. u_mtrlware.plancode,
  1459. u_mtrlware.status,
  1460. u_mtrlware.cost,
  1461. u_mtrldef.planprice,
  1462. u_mtrldef.mtrlcode,
  1463. u_mtrlware.sptid,
  1464. u_mtrlware.dxflag,
  1465. u_mtrlware.woodcode,
  1466. u_mtrlware.pcode,
  1467. isnull(uv_mtrlware_noauditingqty.noauditingqty,0),
  1468. u_mtrlware.noallocqty,
  1469. u_mtrlware.allocaddqty
  1470. INTO :i_mtrlid,
  1471. :i_storageid,
  1472. :i_plancode,
  1473. :i_status,
  1474. :i_cost,
  1475. :i_planprice,
  1476. :i_mtrlcode,
  1477. :i_sptid,
  1478. :i_dxflag,
  1479. :i_woodcode,
  1480. :i_pcode,
  1481. :i_notauditqty,
  1482. :i_allouseqty,
  1483. :i_addqty
  1484. FROM u_mtrlware left OUTER join uv_mtrlware_noauditingqty
  1485. on ( u_mtrlware.mtrlwareid = uv_mtrlware_noauditingqty.mtrlwareid)
  1486. AND ( u_mtrlware.scid = uv_mtrlware_noauditingqty.scid),u_mtrldef
  1487. WHERE ( u_mtrlware.mtrlwareid = :arg_mtrlwareid )
  1488. AND ( u_mtrlware.mtrlid = u_mtrldef.mtrlid )
  1489. And ( u_mtrlware.scid = :scid ) Using commit_transaction;
  1490. IF commit_transaction.SQLCode <> 0 THEN
  1491. rslt = 0
  1492. arg_msg = "查询操作失败,库存编号错误"
  1493. GOTO ext
  1494. END IF
  1495. IF IsNull(ld_dftsaleprice) THEN ld_dftsaleprice = 0
  1496. IF IsNull(i_cost) THEN i_cost = 0
  1497. IF IsNull(i_plancode) THEN i_plancode = ''
  1498. IF IsNull(i_status) THEN i_status = ''
  1499. IF IsNull(i_mtrlid) THEN i_mtrlid = 0
  1500. IF IsNull(i_planprice) THEN i_planprice = 0
  1501. IF IsNull(i_sptid) THEN i_sptid = 0
  1502. IF IsNull(i_dxflag) THEN i_dxflag = 0
  1503. IF IsNull(i_woodcode) THEN i_woodcode = ''
  1504. IF IsNull(i_pcode) THEN i_pcode = ''
  1505. IF arg_ifrel = 1 THEN
  1506. IF arg_relid = 0 THEN
  1507. rslt = 0
  1508. arg_msg = '请选择外协订单!'
  1509. GOTO ext
  1510. END IF
  1511. SELECT taskcode INTO :ls_relcode
  1512. FROM u_order_wfjg
  1513. Where wfjgID = :arg_relid Using commit_transaction;
  1514. IF commit_transaction.SQLCode <> 0 THEN
  1515. rslt = 0
  1516. IF Pos(Lower(commit_transaction.SQLErrText),'more than') > 0 THEN
  1517. arg_msg = '查询外协订单号失败!查询数据返回值多于一个'
  1518. ELSE
  1519. arg_msg = '查询外协订单号失败!(错误外协订单唯一码)'
  1520. END IF
  1521. GOTO ext
  1522. END IF
  1523. SELECT count(*) INTO :cnt
  1524. FROM u_order_wfjgMx_out
  1525. WHERE wfjgid = :arg_relid
  1526. AND mtrlid = :i_mtrlid
  1527. AND status = :i_status
  1528. And woodcode = :i_woodcode Using commit_transaction;
  1529. IF commit_transaction.SQLCode <> 0 THEN
  1530. rslt = 0
  1531. arg_msg = '查询外协订单出仓明细失败!'
  1532. GOTO ext
  1533. END IF
  1534. IF cnt = 0 THEN
  1535. rslt = 0
  1536. arg_msg = '行:'+String(arg_printid)+ ',出仓物料:'+i_mtrlcode+'不在外协订单发出明细中!'
  1537. GOTO ext
  1538. END IF
  1539. END IF
  1540. //*****检查大于未开数不可以开单
  1541. IF flag = 0 THEN
  1542. Decimal ol_mtrl_qty = 0
  1543. Int ls_noallocflag
  1544. SELECT noallocflag INTO :ls_noallocflag
  1545. FROM u_storage
  1546. Where storageid = :i_storageid Using commit_transaction;
  1547. IF commit_transaction.SQLCode <> 0 THEN
  1548. rslt = 0
  1549. arg_msg = '查询仓库允许使用未开单库存属性失败'+commit_transaction.SQLErrText
  1550. GOTO ext
  1551. END IF
  1552. IF ls_noallocflag = 1 THEN
  1553. IF it_updatebegin THEN
  1554. SELECT sum(ow_wfjgmx_out.qty)
  1555. INTO :ol_mtrl_qty
  1556. FROM ow_wfjgmx_out
  1557. WHERE ow_wfjgmx_out.outwareid = :outwareid
  1558. AND ow_wfjgmx_out.mtrlwareid = :arg_mtrlwareid
  1559. And scid = :scid Using commit_transaction;
  1560. IF commit_transaction.SQLCode = -1 THEN
  1561. rslt = 0
  1562. arg_msg = '查询原开单数量失败'
  1563. GOTO ext
  1564. END IF
  1565. END IF
  1566. IF arg_qty > ( i_allouseqty - i_notauditqty + ol_mtrl_qty ) THEN
  1567. rslt = 0
  1568. arg_msg = String(i_mtrlcode)+"库存未开单数不够,不能开单.未开单数{"+String(i_allouseqty - i_notauditqty + ol_mtrl_qty,'#####,0.00##')+"}"
  1569. GOTO ext
  1570. END IF
  1571. IF arg_addqty > i_addqty THEN
  1572. rslt = 0
  1573. arg_msg = String(i_mtrlcode)+"库存辅数不够,不能开单.库存辅数{"+String(i_addqty,'#####,0.00##')+"}"
  1574. GOTO ext
  1575. END IF
  1576. END IF
  1577. END IF
  1578. //***********************************************
  1579. IF thflag = 1 THEN
  1580. //退回单,取供应商库存单价
  1581. SELECT cost
  1582. INTO :lde_cost
  1583. FROM ow_wfjgware
  1584. WHERE ( scid = :scid )
  1585. AND sptid = :sptid
  1586. AND ( mtrlid = :i_mtrlid )
  1587. AND (status = :i_Status)
  1588. AND woodcode = :i_woodcode
  1589. AND pcode = :i_pcode
  1590. AND plancode = :i_plancode
  1591. Using commit_transaction ;
  1592. IF commit_transaction.SQLCode <> 0 THEN
  1593. lde_cost = -1
  1594. END IF
  1595. IF lde_cost > 0 THEN
  1596. i_cost = lde_cost
  1597. END IF
  1598. END IF
  1599. IF i_cost < 0 THEN //检查进仓价
  1600. rslt = 0
  1601. arg_msg = "编码:" + String(i_mtrlcode)+" 单价错误"
  1602. GOTO ext
  1603. END IF
  1604. //写入内容
  1605. it_mxbt++
  1606. outwaremx[it_mxbt].printid = arg_printid
  1607. outwaremx[it_mxbt].storageid = i_storageid
  1608. outwaremx[it_mxbt].mtrlwareid = arg_mtrlwareid
  1609. outwaremx[it_mxbt].mtrlid = i_mtrlid
  1610. outwaremx[it_mxbt].status = i_status
  1611. outwaremx[it_mxbt].woodcode = i_woodcode
  1612. outwaremx[it_mxbt].pcode = i_pcode
  1613. outwaremx[it_mxbt].qty = arg_qty
  1614. outwaremx[it_mxbt].uunit = arg_uunit
  1615. outwaremx[it_mxbt].rate = arg_rate
  1616. outwaremx[it_mxbt].addqty = arg_addqty
  1617. IF sys_option_2unit = 0 THEN
  1618. // outwaremx[it_mxbt].uqty = arg_qty
  1619. // outwaremx[it_mxbt].uprice = i_cost
  1620. arg_uqty = arg_qty/arg_rate
  1621. outwaremx[it_mxbt].uqty = arg_uqty
  1622. outwaremx[it_mxbt].uprice = Round(arg_qty * i_cost/arg_uqty,5)
  1623. ELSE
  1624. outwaremx[it_mxbt].uqty = arg_uqty
  1625. outwaremx[it_mxbt].uprice = Round(arg_qty * i_cost/arg_uqty,5)
  1626. END IF
  1627. outwaremx[it_mxbt].cost = i_cost
  1628. outwaremx[it_mxbt].costamt = Round(i_cost * arg_qty,2)
  1629. outwaremx[it_mxbt].newpriceamt = Round(i_newprice * arg_qty,2)
  1630. outwaremx[it_mxbt].rebate = 1
  1631. outwaremx[it_mxbt].fprice = i_cost
  1632. outwaremx[it_mxbt].price = i_cost
  1633. outwaremx[it_mxbt].plancode = i_plancode
  1634. outwaremx[it_mxbt].planprice = i_planprice
  1635. outwaremx[it_mxbt].mtrlcode = i_mtrlcode
  1636. outwaremx[it_mxbt].mxdscrp = arg_mxdscrp
  1637. outwaremx[it_mxbt].mxdscrp2 = arg_mxdscrp2
  1638. outwaremx[it_mxbt].sptid = i_sptid
  1639. outwaremx[it_mxbt].dxflag = i_dxflag
  1640. outwaremx[it_mxbt].ifrel = arg_ifrel
  1641. outwaremx[it_mxbt].relid = arg_relid
  1642. outwaremx[it_mxbt].relprintid = arg_relprintid
  1643. outwaremx[it_mxbt].relcode = ls_relcode
  1644. outwaremx[it_mxbt].jgdscrp = arg_jgdscrp
  1645. ext:
  1646. IF rslt = 0 THEN p_clearmx()
  1647. IF thflag = 0 THEN
  1648. arg_msg = '仓库外协发出单,'+ arg_msg
  1649. ELSE
  1650. arg_msg = '仓库外协退回单,'+ arg_msg
  1651. END IF
  1652. RETURN rslt
  1653. end function
  1654. on uo_outware_wfjg.create
  1655. call super::create
  1656. TriggerEvent( this, "constructor" )
  1657. end on
  1658. on uo_outware_wfjg.destroy
  1659. TriggerEvent( this, "destructor" )
  1660. call super::destroy
  1661. end on