uo_outware_wfjg.sru 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262
  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
  11. PUBLIC PROTECTEDWRITE Long outwareid
  12. PUBLIC PROTECTEDWRITE String outwarecode
  13. PUBLIC PROTECTEDWRITE Int billtype
  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
  19. PUBLIC PROTECTEDWRITE Int flag
  20. PUBLIC PROTECTEDWRITE DateTime auditingdate
  21. PUBLIC PROTECTEDWRITE String auditingrep
  22. PUBLIC PROTECTEDWRITE Decimal sum_amt
  23. PUBLIC PROTECTEDWRITE Int secflag
  24. PUBLIC PROTECTEDWRITE DateTime secauditingdate
  25. PUBLIC PROTECTEDWRITE String secauditingrep
  26. PUBLIC PROTECTEDWRITE Long ctmint
  27. Long relid
  28. DateTime outdate
  29. String outrep
  30. String part
  31. String dscrp
  32. Long sptid
  33. String sptname
  34. Int thflag
  35. Long banktypeid
  36. Long refpayid
  37. Boolean if_getid_ture = TRUE
  38. Transaction commit_transaction //数据commit事务
  39. s_outwaremx_wfjg outwaremx[] //明细结构数组
  40. Long it_mxbt = 0 //明细结构数组末指针
  41. Boolean it_newbegin = FALSE //新建标志
  42. Boolean it_updatebegin = FALSE //修改标志
  43. int uo_option_autocreate_outware,uo_option_2unit
  44. int uo_option_noauditingqty_mode
  45. end variables
  46. forward prototypes
  47. public function integer newbegin (long arg_scid, integer arg_billtype, ref string arg_msg)
  48. public function integer save (boolean arg_ifcommit, ref string arg_msg)
  49. public function integer auditing (boolean arg_ifcommit, ref string arg_msg)
  50. public function integer updatebegin (long arg_scid, long arg_outwareid, integer arg_billtype, ref string arg_msg)
  51. public function integer getinfo (long arg_scid, long arg_outwareid, ref string arg_msg)
  52. public function integer del (long arg_scid, long arg_outwareid, ref string arg_msg, boolean arg_ifcommit)
  53. public function integer add_dscrp (long arg_scid, long arg_outwareid, string arg_newdescppart, ref string arg_msg)
  54. public function integer c_auditing (boolean arg_ifcommit, ref string arg_msg)
  55. public function integer p_clearmx ()
  56. public function integer p_getinfo (long arg_scid, long arg_outwareid, ref string arg_msg)
  57. public function integer p_reset ()
  58. public function integer secauditing (boolean arg_ifcommit, ref string arg_msg)
  59. public function integer c_secauditing (boolean arg_ifcommit, ref string arg_msg)
  60. public function integer acceptmx (long arg_mtrlwareid, decimal arg_uqty, string arg_uunit, decimal arg_qty, decimal arg_fprice, string arg_mxdscrp, long arg_printid, ref string arg_msg, integer arg_ifrel, long arg_relid, long arg_relprintid, long arg_olmtrlid, decimal arg_rate)
  61. public function integer uof_check_sptpdb_audit (long arg_sptid, ref string arg_msg)
  62. public function integer uof_noauditingqty_add (ref string arg_msg)
  63. public function integer uof_noauditingqty_del (long arg_scid, long arg_outwareid, ref string arg_msg)
  64. public function integer acceptmx (s_outwaremx_wfjg s_mx, ref string arg_msg)
  65. end prototypes
  66. public function integer newbegin (long arg_scid, integer arg_billtype, ref string arg_msg);Int rslt = 1
  67. IF arg_scid < 0 THEN
  68. arg_msg = '请选择分部'
  69. rslt = 0
  70. GOTO ext
  71. END IF
  72. IF Not (arg_billtype = 4 OR &
  73. arg_billtype = 7) THEN
  74. rslt = 0
  75. arg_msg = '此单据类型必须为:'
  76. arg_msg = arg_msg+'4-仓库外协发出单,'
  77. arg_msg = arg_msg+'7-外协销售发货单'
  78. GOTO ext
  79. END IF
  80. p_reset()
  81. billtype = arg_billtype
  82. scid = arg_scid
  83. it_newbegin = TRUE
  84. it_updatebegin = FALSE
  85. ext:
  86. IF rslt = 0 THEN p_reset()
  87. RETURN rslt
  88. end function
  89. public function integer save (boolean arg_ifcommit, ref string arg_msg);Integer rslt = 1,cnt = 0,i
  90. DateTime server_dt
  91. Long ls_newid
  92. String ls_sccode
  93. IF IsNull(relid) THEN relid = 0
  94. IF IsNull(outrep) THEN outrep = ''
  95. IF IsNull(dscrp) THEN dscrp = ''
  96. IF IsNull(part) THEN part = ''
  97. IF IsNull(sptid) THEN sptid = 0
  98. IF IsNull(sptname) THEN sptname = ''
  99. IF IsNull(thflag) THEN thflag = 0
  100. IF IsNull(banktypeid) THEN banktypeid = 0
  101. IF it_newbegin = False And it_updatebegin = False THEN
  102. rslt = 0
  103. arg_msg = "非编辑状态不可以提交"
  104. GOTO ext
  105. END IF
  106. SELECT Top 1 getdate() Into :server_dt From u_user Using commit_transaction ;
  107. //取得系统时间,借用操作员表
  108. IF commit_transaction.SQLCode <> 0 THEN
  109. rslt = 0
  110. arg_msg = "查询操作失败,日期 "
  111. GOTO ext
  112. END IF
  113. IF it_mxbt = 0 THEN //如果输入物料资料错则已经清空
  114. rslt = 0
  115. arg_msg = "外协发出单没有正确出仓内容"
  116. GOTO ext
  117. END IF
  118. IF f_check_inoutdate(0,outdate,False,arg_msg) = 0 THEN
  119. rslt = 0
  120. GOTO ext
  121. END IF
  122. IF f_check_inoutdate_wfjg(scid,sptid,outdate,arg_msg) = 0 THEN
  123. rslt = 0
  124. GOTO ext
  125. END IF
  126. IF billtype = 7 THEN
  127. IF banktypeid = 0 THEN
  128. arg_msg = '请选择结算方式'
  129. rslt = 0
  130. GOTO ext
  131. END IF
  132. cnt = 0
  133. SELECT count(*) INTO :cnt
  134. FROM cw_banktype
  135. Where banktypeid = :banktypeid Using commit_transaction;
  136. IF commit_transaction.SQLCode <> 0 THEN
  137. rslt = 0
  138. arg_msg = "查询操作失败,结算方式"
  139. GOTO ext
  140. END IF
  141. IF cnt = 0 THEN
  142. arg_msg = '结算方式资料不存在'
  143. rslt = 0
  144. GOTO ext
  145. END IF
  146. END IF
  147. SELECT name INTO :sptname
  148. FROM u_spt
  149. Where sptid = :sptid Using commit_transaction;
  150. IF commit_transaction.SQLCode <> 0 THEN
  151. rslt = 0
  152. arg_msg = "查询操作失败,加工商资料"
  153. GOTO ext
  154. END IF
  155. ////////////////////////////////////////////// //开始区分:新建/更新 处理
  156. IF outwareid = 0 THEN //新建
  157. ls_newid = f_sys_scidentity(scid,"ow_wfjg_out","outwareid",arg_msg,True,id_sqlca)
  158. IF ls_newid <= 0 THEN
  159. rslt = 0
  160. GOTO ext
  161. END IF
  162. //取分部代号
  163. IF f_get_sccode(scid,commit_transaction,ls_sccode,arg_msg) = 0 THEN
  164. rslt = 0
  165. GOTO ext
  166. END IF
  167. //取得新单据编号
  168. IF billtype = 4 THEN
  169. IF thflag = 0 THEN
  170. outwarecode = getid(scid,ls_sccode + 'WL',Date(server_dt),if_getid_ture,commit_transaction)
  171. ELSE
  172. outwarecode = getid(scid,ls_sccode + 'SL',Date(server_dt),if_getid_ture,commit_transaction)
  173. END IF
  174. ELSE //销售
  175. IF thflag = 0 THEN
  176. outwarecode = getid(scid,ls_sccode + 'SW',Date(server_dt),if_getid_ture,commit_transaction)
  177. ELSE
  178. outwarecode = getid(scid,ls_sccode + 'UW',Date(server_dt),if_getid_ture,commit_transaction)
  179. END IF
  180. END IF
  181. IF outwarecode = "err" THEN
  182. outwarecode = ''
  183. rslt = 0
  184. arg_msg = "无法获取出仓单编号"+"~n"+commit_transaction.SQLErrText
  185. GOTO ext
  186. END IF
  187. INSERT INTO ow_wfjg_out (
  188. scid,
  189. outwareid,
  190. outwarecode,
  191. billtype,
  192. relid,
  193. outdate,
  194. outrep,
  195. part,
  196. dscrp,
  197. sptid,
  198. sptname,
  199. thflag,
  200. banktypeid,
  201. opdate,
  202. opemp)
  203. VALUES (
  204. :scid,
  205. :ls_newid,
  206. :outwarecode,
  207. :billtype,
  208. :relid,
  209. :outdate,
  210. :outrep,
  211. :part,
  212. :dscrp,
  213. :sptid,
  214. :sptname,
  215. :thflag,
  216. :banktypeid,
  217. :server_dt,
  218. :publ_operator
  219. ) Using commit_transaction ;
  220. IF commit_transaction.SQLCode <> 0 THEN
  221. rslt = 0
  222. arg_msg = "插入操作失败"+"~n"+commit_transaction.SQLErrText
  223. GOTO ext
  224. END IF
  225. //读取新outwareid
  226. outwareid = ls_newid
  227. // FOR i = 1 TO it_mxbt
  228. // INSERT INTO ow_wfjgmx_out
  229. // (scid,
  230. // storageid,
  231. // outwareid,
  232. // mtrlwareid,
  233. // printid,
  234. // mtrlid,
  235. // plancode,
  236. // status,
  237. // qty,
  238. // fprice,
  239. // rebate,
  240. // price,
  241. // mxdscrp,
  242. // costamt,
  243. // ifrel,
  244. // relid,
  245. // relprintid,
  246. // woodcode,
  247. // relcode,
  248. // pcode,
  249. // cost,
  250. // olmtrlid,
  251. // uqty,
  252. // uprice,
  253. // uunit,
  254. // rate,
  255. // mtrlcuscode,
  256. // location)
  257. // VALUES (
  258. // :scid,
  259. // :outwaremx[i].storageid,
  260. // :ls_newid,
  261. // :outwaremx[i].mtrlwareid,
  262. // :outwaremx[i].printid,
  263. // :outwaremx[i].mtrlid,
  264. // :outwaremx[i].plancode,
  265. // :outwaremx[i].status,
  266. // :outwaremx[i].qty,
  267. // :outwaremx[i].fprice,
  268. // :outwaremx[i].rebate,
  269. // :outwaremx[i].price,
  270. // :outwaremx[i].mxdscrp,
  271. // :outwaremx[i].costamt,
  272. // :outwaremx[i].ifrel,
  273. // :outwaremx[i].relid,
  274. // :outwaremx[i].relprintid,
  275. // :outwaremx[i].woodcode,
  276. // :outwaremx[i].relcode,
  277. // :outwaremx[i].pcode,
  278. // :outwaremx[i].cost,
  279. // :outwaremx[i].olmtrlid,
  280. // :outwaremx[i].uqty,
  281. // :outwaremx[i].uprice,
  282. // :outwaremx[i].uunit,
  283. // :outwaremx[i].rate,
  284. // :outwaremx[i].mtrlcuscode,
  285. // :outwaremx[i].location) USING commit_transaction;
  286. // IF commit_transaction.SQLCode <> 0 THEN
  287. // outwareid = 0 //还原outwareid
  288. // rslt = 0
  289. // arg_msg = "插入明细操作失败"+"~n"+commit_transaction.SQLErrText
  290. // GOTO ext
  291. // END IF
  292. // NEXT
  293. //
  294. // //更新库存已开单数
  295. // If uof_noauditingqty_add(arg_msg) = 0 Then
  296. // rslt = 0
  297. // Goto ext
  298. // End If
  299. ELSE //////////////////////////////////////////////// //更新
  300. UPDATE ow_wfjg_out
  301. SET billtype = :billtype,
  302. relid = :relid,
  303. outdate = :outdate,
  304. outrep = :outrep,
  305. part = :part,
  306. dscrp = :dscrp,
  307. sptid = :sptid,
  308. sptname = :sptname,
  309. thflag = :thflag,
  310. banktypeid = :banktypeid,
  311. moddate = :server_dt,
  312. modemp = :publ_operator
  313. WHERE ow_wfjg_out.outwareid = :outwareid
  314. AND ow_wfjg_out.scid = :scid
  315. And flag = 0 Using commit_transaction;
  316. IF commit_transaction.SQLCode <> 0 Or commit_transaction.SQLNRows <= 0 THEN
  317. rslt = 0
  318. arg_msg = "更新单据操作失败(1)"+"~n"+commit_transaction.SQLErrText
  319. GOTO ext
  320. END IF
  321. //更新库存已开单数(减)
  322. IF uof_noauditingqty_del(scid,outwareid,arg_msg) = 0 THEN
  323. rslt = 0
  324. GOTO ext
  325. END IF
  326. //删除原有明细
  327. DELETE FROM ow_wfjgmx_out
  328. WHERE ow_wfjgmx_out.outwareid = :outwareid
  329. And ow_wfjgmx_out.scid = :scid Using commit_transaction;
  330. IF commit_transaction.SQLCode <> 0 THEN
  331. rslt = 0
  332. arg_msg = "删除旧有明细操作失败"+"~n"+commit_transaction.SQLErrText
  333. GOTO ext
  334. END IF
  335. END IF
  336. FOR i = 1 To it_mxbt
  337. INSERT INTO ow_wfjgmx_out
  338. (scid,
  339. storageid,
  340. outwareid,
  341. mtrlwareid,
  342. printid,
  343. mtrlid,
  344. plancode,
  345. status,
  346. qty,
  347. fprice,
  348. rebate,
  349. price,
  350. mxdscrp,
  351. costamt,
  352. ifrel,
  353. relid,
  354. relprintid,
  355. woodcode,
  356. relcode,
  357. pcode,
  358. cost,
  359. olmtrlid,
  360. uqty,
  361. uprice,
  362. uunit,
  363. rate,
  364. mtrlcuscode,
  365. location,
  366. thtype,
  367. relprintid2,
  368. relmtrlid2,
  369. relqty2)
  370. VALUES (
  371. :scid,
  372. :outwaremx[i].storageid,
  373. :outwareid,
  374. :outwaremx[i].mtrlwareid,
  375. :outwaremx[i].printid,
  376. :outwaremx[i].mtrlid,
  377. :outwaremx[i].plancode,
  378. :outwaremx[i].status,
  379. :outwaremx[i].qty,
  380. :outwaremx[i].fprice,
  381. :outwaremx[i].rebate,
  382. :outwaremx[i].price,
  383. :outwaremx[i].mxdscrp,
  384. :outwaremx[i].costamt,
  385. :outwaremx[i].ifrel,
  386. :outwaremx[i].relid,
  387. :outwaremx[i].relprintid,
  388. :outwaremx[i].woodcode,
  389. :outwaremx[i].relcode,
  390. :outwaremx[i].pcode,
  391. :outwaremx[i].cost,
  392. :outwaremx[i].olmtrlid,
  393. :outwaremx[i].uqty,
  394. :outwaremx[i].uprice,
  395. :outwaremx[i].uunit,
  396. :outwaremx[i].rate,
  397. :outwaremx[i].mtrlcuscode,
  398. :outwaremx[i].location,
  399. :outwaremx[i].thtype,
  400. :outwaremx[i].relprintid2,
  401. :outwaremx[i].relmtrlid2,
  402. :outwaremx[i].relqty2) Using commit_transaction;
  403. IF commit_transaction.SQLCode <> 0 THEN
  404. IF it_newbegin THEN outwareid = 0
  405. rslt = 0
  406. arg_msg = "插入明细操作失败"+"~n"+commit_transaction.SQLErrText
  407. GOTO ext
  408. END IF
  409. NEXT
  410. //更新库存已开单数
  411. IF uof_noauditingqty_add(arg_msg) = 0 THEN
  412. rslt = 0
  413. GOTO ext
  414. END IF
  415. it_newbegin = False
  416. it_updatebegin = False
  417. ext:
  418. IF rslt = 0 THEN
  419. ROLLBACK Using commit_transaction;
  420. p_clearmx()
  421. ELSEIF rslt = 1 And arg_ifcommit THEN
  422. COMMIT Using commit_transaction;
  423. END IF
  424. RETURN rslt
  425. end function
  426. public function integer auditing (boolean arg_ifcommit, ref string arg_msg);Long rslt = 1,cnt = 0,i
  427. IF f_aps_mrp_cklock(scid,arg_msg) = 0 THEN
  428. rslt = 0
  429. GOTO ext
  430. END IF
  431. uo_order_wfjg uo_wfjg
  432. uo_wfjg = Create uo_order_wfjg
  433. uo_wfjg.commit_transaction = commit_transaction
  434. uo_outware uo_out
  435. uo_out = Create uo_outware
  436. uo_out.commit_transaction = commit_transaction
  437. uo_out.if_getid_ture = False
  438. IF outwareid = 0 THEN
  439. rslt = 0
  440. arg_msg = "没有审核对象"
  441. GOTO ext
  442. END IF
  443. IF flag = 1 THEN
  444. rslt = 0
  445. arg_msg = "单据已经审核"
  446. GOTO ext
  447. END IF
  448. //检查外协商盘点表是否未审
  449. IF billtype = 4 THEN
  450. IF uof_check_sptpdb_audit(sptid,arg_msg) = 0 THEN
  451. rslt = 0
  452. GOTO ext
  453. END IF
  454. END IF
  455. UPDATE ow_wfjg_out
  456. SET Auditingemp = :publ_operator,
  457. Auditingdate = getdate(),
  458. flag = 1
  459. WHERE ow_wfjg_out.outwareid = :outwareid
  460. AND flag = 0
  461. And scid = :scid Using commit_transaction;
  462. IF commit_transaction.SQLCode <> 0 THEN
  463. rslt = 0
  464. arg_msg = "审核单据操作失败"+"~n"+commit_transaction.SQLErrText
  465. GOTO ext
  466. ELSEIF commit_transaction.SQLNRows = 0 THEN
  467. rslt = 0
  468. arg_msg = "单据正在审核,请稍后查询。"+"~n"+commit_transaction.SQLErrText
  469. GOTO ext
  470. END IF
  471. //生成出仓单
  472. Long lay_storageid[],ll_storageid,rst_outwareid
  473. Boolean lb_f = False
  474. Long j,k,ch,chc
  475. //统计仓库数量,确定出仓单数
  476. FOR i = 1 To it_mxbt
  477. FOR j = 1 To UpperBound(lay_storageid)
  478. IF lay_storageid[j] = outwaremx[i].storageid THEN lb_f = True
  479. NEXT
  480. IF lb_f = False THEN
  481. ch++
  482. lay_storageid[ch] = outwaremx[i].storageid
  483. END IF
  484. lb_f = False
  485. NEXT
  486. FOR k = 1 To ch
  487. ll_storageid = lay_storageid[k]
  488. IF uo_out.newbegin(scid,billtype,arg_msg) = 0 THEN
  489. rslt = 0
  490. GOTO ext
  491. END IF
  492. uo_out.relid = outwareid
  493. uo_out.outdate = outdate
  494. uo_out.outrep = outrep
  495. uo_out.part = outwarecode
  496. uo_out.dscrp = dscrp
  497. IF billtype = 4 THEN
  498. uo_out.cusname = '仓库外协出仓:'+sptname
  499. ELSE
  500. uo_out.cusname = '仓库外协销售:'+sptname
  501. END IF
  502. uo_out.storageid = ll_storageid
  503. uo_out.cusid = sptid
  504. chc = 0
  505. FOR i = 1 To it_mxbt
  506. IF outwaremx[i].storageid <> ll_storageid THEN CONTINUE
  507. chc++
  508. IF uo_out.acceptmx(outwaremx[i].mtrlwareid,&
  509. outwaremx[i].qty,outwaremx[i].price,1,&
  510. outwaremx[i].mxdscrp,chc,arg_msg,0,0,outwaremx[i].olmtrlid,0,'',0,0,outwaremx[i].uunit,outwaremx[i].uqty,outwaremx[i].rate,'','',0,0,'',0,0,0,0,'','') = 0 THEN
  511. rslt = 0
  512. GOTO ext
  513. END IF
  514. NEXT
  515. IF uo_out.Save(False,arg_msg) = 0 THEN
  516. rslt = 0
  517. GOTO ext
  518. END IF
  519. rst_outwareid = uo_out.outwareid
  520. //2.原事务审核出仓单
  521. IF uo_out.getinfo( scid,rst_outwareid,arg_msg) = 0 THEN
  522. rslt = 0
  523. GOTO ext
  524. END IF
  525. IF uo_out.auditing(False,arg_msg) = 0 THEN
  526. rslt = 0
  527. GOTO ext
  528. END IF
  529. NEXT
  530. //更新供应商库存
  531. IF billtype = 4 THEN
  532. FOR i = 1 To it_mxbt
  533. //更新订单已发出数
  534. IF outwaremx[i].relid > 0 THEN
  535. IF outwaremx[i].relprintid > 0 THEN
  536. IF outwaremx[i].thtype = 0 THEN //重新发出
  537. IF uo_wfjg.addmxcmpl_out(scid,outwaremx[i].relid,outwaremx[i].relprintid,outwaremx[i].qty,arg_msg,False) <> 1 THEN
  538. rslt = 0
  539. GOTO ext
  540. END IF
  541. ELSEIF outwaremx[i].thtype = 1 THEN //终止收货
  542. IF uo_wfjg.stopaddqty(scid, outwaremx[i].relid, outwaremx[i].relprintid2,'', 0 - outwaremx[i].relqty2,0,'终止收货',arg_msg, False) = 0 THEN
  543. //arg_msg = '更新行:'+String(i)+','+arg_msg
  544. rslt = 0
  545. GOTO ext
  546. END IF
  547. END IF
  548. ELSE //兼容旧数据,以后可删 20120910
  549. IF uo_wfjg.addmxcmpl_out(scid,outwaremx[i].relid,outwaremx[i].mtrlid,outwaremx[i].sptid,outwaremx[i].status,outwaremx[i].woodcode,outwaremx[i].pcode,outwaremx[i].qty,arg_msg,False) <> 1 THEN
  550. rslt = 0
  551. GOTO ext
  552. END IF
  553. END IF
  554. END IF
  555. IF f_update_mtrlware_spt_out (billtype,thflag,scid,outwaremx[i].mtrlid, &
  556. outwaremx[i].mtrlcode, outwaremx[i].plancode,&
  557. outwaremx[i].status, outwaremx[i].qty, outwaremx[i].costamt,&
  558. outwaremx[i].planprice, sptid, &
  559. outwaremx[i].woodcode, outwaremx[i].pcode,arg_msg,False,commit_transaction) = 0 THEN
  560. rslt = 0
  561. GOTO ext
  562. END IF
  563. NEXT
  564. END IF
  565. //更新库存已开单数(减)
  566. IF uof_noauditingqty_del(scid,outwareid,arg_msg) = 0 THEN
  567. rslt = 0
  568. GOTO ext
  569. END IF
  570. flag = 1
  571. ext:
  572. Destroy uo_out
  573. Destroy uo_wfjg
  574. IF rslt = 0 THEN
  575. ROLLBACK Using commit_transaction;
  576. ELSEIF rslt = 1 And arg_ifcommit THEN
  577. COMMIT Using commit_transaction;
  578. END IF
  579. RETURN rslt
  580. end function
  581. public function integer updatebegin (long arg_scid, long arg_outwareid, integer arg_billtype, ref string arg_msg);Long rslt = 1
  582. IF uo_option_autocreate_outware = -1000 THEN
  583. rslt = 0
  584. arg_msg = '选项:[087]外协订单审核自动生成仓库外协发出单,读取初始默认值失败,操作取消!'
  585. GOTO ext
  586. END IF
  587. IF arg_scid < 0 THEN
  588. arg_msg = '请选择分部'
  589. rslt = 0
  590. GOTO ext
  591. END IF
  592. IF Not (arg_billtype = 4 OR &
  593. arg_billtype = 7) THEN
  594. rslt = 0
  595. arg_msg = '此单据类型必须为:'
  596. arg_msg = arg_msg+'4-仓库外协发出单,'
  597. arg_msg = arg_msg+'7-外协销售发货单'
  598. GOTO ext
  599. END IF
  600. IF arg_outwareid <= 0 THEN
  601. rslt = 0
  602. GOTO ext
  603. END IF
  604. rslt = p_getinfo(arg_scid,arg_outwareid,arg_msg)
  605. IF rslt = 0 THEN GOTO ext
  606. IF billtype = 4 AND relid > 0 AND uo_option_autocreate_outware = 1 THEN //自动生成的外协发出单,不允许修改
  607. rslt = 0
  608. arg_msg = '自动生成的单据,不可以修改'
  609. GOTO ext
  610. END IF
  611. IF flag = 1 THEN
  612. rslt = 0
  613. arg_msg = '单据已经审核,不可以修改'
  614. GOTO ext
  615. END IF
  616. outwareid = arg_outwareid
  617. billtype = arg_billtype
  618. scid = arg_scid
  619. it_newbegin = FALSE
  620. it_updatebegin = TRUE
  621. p_clearmx() //清除明细
  622. ext:
  623. IF rslt = 0 THEN p_reset()
  624. RETURN rslt
  625. end function
  626. public function integer getinfo (long arg_scid, long arg_outwareid, ref string arg_msg);Int rslt = 1,i = 1,no_mxcheck = 0
  627. sum_amt = 0
  628. IF arg_outwareid <= 0 THEN
  629. rslt = 0
  630. arg_msg = "非法出仓单唯一码"
  631. GOTO ext
  632. END IF
  633. rslt = p_getinfo(arg_scid,arg_outwareid,arg_msg)
  634. IF rslt = 0 THEN GOTO ext
  635. //用游标读取明细
  636. DECLARE cur_inwaermx CURSOR FOR
  637. SELECT ow_wfjgmx_out.printid,
  638. ow_wfjgmx_out.mtrlid,
  639. ow_wfjgmx_out.plancode,
  640. ow_wfjgmx_out.status,
  641. ow_wfjgmx_out.qty,
  642. ow_wfjgmx_out.fprice,
  643. ow_wfjgmx_out.rebate,
  644. ow_wfjgmx_out.price,
  645. ow_wfjgmx_out.mxdscrp,
  646. u_mtrldef.mtrlcode,
  647. ow_wfjgmx_out.mtrlwareid,
  648. ow_wfjgmx_out.storageid,
  649. ow_wfjgmx_out.costamt,
  650. ow_wfjgmx_out.ifrel,
  651. ow_wfjgmx_out.relid,
  652. ow_wfjgmx_out.relprintid,
  653. ow_wfjgmx_out.woodcode,
  654. ow_wfjgmx_out.pcode,
  655. ow_wfjgmx_out.cost,
  656. ow_wfjgmx_out.olmtrlid,
  657. ow_wfjgmx_out.uqty,
  658. ow_wfjgmx_out.uprice,
  659. ow_wfjgmx_out.rate,
  660. ow_wfjgmx_out.uunit,
  661. ow_wfjgmx_out.mtrlcuscode,
  662. ow_wfjgmx_out.location,
  663. ow_wfjgmx_out.thtype,
  664. ow_wfjgmx_out.relprintid2,
  665. ow_wfjgmx_out.relmtrlid2,
  666. ow_wfjgmx_out.relqty2
  667. FROM ow_wfjgmx_out,u_mtrldef,ow_wfjg_out
  668. WHERE ow_wfjg_out.outwareid = :arg_outwareid AND
  669. ow_wfjgmx_out.mtrlid = u_mtrldef.mtrlid AND
  670. ow_wfjg_out.scid = :arg_scid AND
  671. ow_wfjg_out.outwareid = ow_wfjgmx_out.outwareid AND
  672. ow_wfjg_out.scid = ow_wfjgmx_out.scid USING commit_transaction;
  673. OPEN cur_inwaermx;
  674. FETCH cur_inwaermx INTO
  675. :outwaremx[i].printid,:outwaremx[i].mtrlid,:outwaremx[i].plancode,
  676. :outwaremx[i].status,:outwaremx[i].qty,:outwaremx[i].fprice,
  677. :outwaremx[i].rebate,:outwaremx[i].price,
  678. :outwaremx[i].mxdscrp,:outwaremx[i].mtrlcode,
  679. :outwaremx[i].mtrlwareid,:outwaremx[i].storageid,
  680. :outwaremx[i].costamt,:outwaremx[i].ifrel,
  681. :outwaremx[i].relid,
  682. :outwaremx[i].relprintid,
  683. :outwaremx[i].woodcode,:outwaremx[i].pcode,
  684. :outwaremx[i].cost,:outwaremx[i].olmtrlid,
  685. :outwaremx[i].uqty,:outwaremx[i].uprice,:outwaremx[i].rate,
  686. :outwaremx[i].uunit,:outwaremx[i].mtrlcuscode,:outwaremx[i].location,
  687. :outwaremx[i].thtype,:outwaremx[i].relprintid2,:outwaremx[i].relmtrlid2,:outwaremx[i].relqty2;
  688. DO WHILE commit_transaction.SQLCode = 0
  689. sum_amt = sum_amt + round(outwaremx[i].qty * outwaremx[i].price,2) //计算单据总金额
  690. i++
  691. FETCH cur_inwaermx INTO
  692. :outwaremx[i].printid,:outwaremx[i].mtrlid,:outwaremx[i].plancode,
  693. :outwaremx[i].status,:outwaremx[i].qty,:outwaremx[i].fprice,
  694. :outwaremx[i].rebate,:outwaremx[i].price,
  695. :outwaremx[i].mxdscrp,:outwaremx[i].mtrlcode,
  696. :outwaremx[i].mtrlwareid,:outwaremx[i].storageid,
  697. :outwaremx[i].costamt,:outwaremx[i].ifrel,
  698. :outwaremx[i].relid,
  699. :outwaremx[i].relprintid,
  700. :outwaremx[i].woodcode,:outwaremx[i].pcode,
  701. :outwaremx[i].cost,:outwaremx[i].olmtrlid,
  702. :outwaremx[i].uqty,:outwaremx[i].uprice,:outwaremx[i].rate,
  703. :outwaremx[i].uunit,:outwaremx[i].mtrlcuscode,:outwaremx[i].location,
  704. :outwaremx[i].thtype,:outwaremx[i].relprintid2,:outwaremx[i].relmtrlid2,:outwaremx[i].relqty2;
  705. LOOP
  706. CLOSE cur_inwaermx;
  707. //检验明细是否读入完整
  708. SELECT count(*) INTO :no_mxcheck
  709. FROM ow_wfjgmx_out
  710. WHERE ow_wfjgmx_out.outwareid = :arg_outwareid
  711. AND scid = :arg_scid USING commit_transaction;
  712. IF commit_transaction.SQLCode <> 0 THEN
  713. rslt = 0
  714. arg_msg = "查询操作失败,出仓单明细数量"
  715. GOTO ext
  716. END IF
  717. IF i <> (no_mxcheck+1) THEN
  718. rslt = 0
  719. arg_msg = "查询操作失败,出仓单明细"
  720. GOTO ext
  721. END IF
  722. outwareid = arg_outwareid
  723. scid = arg_scid
  724. it_mxbt = i - 1
  725. it_newbegin = FALSE
  726. it_updatebegin = FALSE
  727. ext:
  728. IF rslt = 0 THEN p_reset()
  729. RETURN rslt
  730. end function
  731. public function integer del (long arg_scid, long arg_outwareid, ref string arg_msg, boolean arg_ifcommit);//如果单据还没有审核删除单据极其明细
  732. //0 FAIL, 1 SUCCESS
  733. Int rslt = 1
  734. IF arg_outwareid <= 0 THEN
  735. rslt = 0
  736. arG_MSG = "没有删除对象,操作取消"
  737. GOTO ext
  738. END IF
  739. p_getinfo(arg_scid,arg_outwareid,arg_msg)
  740. IF flag = 1 THEN
  741. rslt = 0
  742. arG_MSG = "单据已经审核,不可以删除"
  743. GOTO ext
  744. END IF
  745. //更新库存已开单数(减)
  746. If uof_noauditingqty_del(arg_scid,arg_outwareid,arG_MSG) = 0 Then
  747. rslt = 0
  748. Goto ext
  749. End If
  750. DELETE FROM ow_wfjg_out
  751. WHERE ow_wfjg_out.outwareid = :arg_outwareid
  752. AND ow_wfjg_out.scid = :arg_scid USING commit_transaction;
  753. IF commit_transaction.SQLCode <> 0 THEN
  754. rslt = 0
  755. arG_MSG = "删除单据操作失败"+"~n"+commit_transaction.SQLErrText
  756. GOTO ext
  757. END IF
  758. DELETE FROM ow_wfjgmx_out
  759. WHERE ow_wfjgmx_out.outwareid = :arg_outwareid
  760. AND ow_wfjgmx_out.scid = :arg_scid USING commit_transaction;
  761. IF commit_transaction.SQLCode <> 0 THEN
  762. rslt = 0
  763. arG_MSG = "删除单据明细操作失败"+"~n"+commit_transaction.SQLErrText
  764. GOTO ext
  765. END IF
  766. it_newbegin = FALSE
  767. it_updatebegin = FALSE
  768. ext:
  769. IF rslt = 0 THEN
  770. ROLLBACK USING commit_transaction;
  771. p_reset()
  772. ELSEIF rslt = 1 AND arg_ifcommit THEN
  773. COMMIT USING commit_transaction;
  774. END IF
  775. RETURN (rslt)
  776. end function
  777. public function integer add_dscrp (long arg_scid, long arg_outwareid, string arg_newdescppart, ref string arg_msg);//add_dscrp(string arg_newdescppart)
  778. //0 fail 1 success
  779. Int rslt = 1
  780. arg_newdescppart = Trim(arg_newdescppart)
  781. IF arg_newdescppart = '' THEN
  782. rslt = 0
  783. arg_msg = "要添加内容为空,操作取消"
  784. GOTO ext
  785. END IF
  786. rslt = p_getinfo(arg_scid,arg_outwareid,arg_msg)
  787. IF rslt = 0 THEN GOTO ext
  788. IF flag = 0 THEN
  789. rslt = 0
  790. arg_msg = "非审核状态下不可用"
  791. GOTO ext
  792. END IF
  793. UPDATE ow_wfjg_out
  794. SET dscrp = ltrim(rtrim(dscrp))+' '+:arg_newdescppart
  795. WHERE ow_wfjg_out.outwareid = :outwareid
  796. AND scid = :scid USING commit_transaction;
  797. IF commit_transaction.SQLCode <> 0 THEN
  798. ROLLBACK ;
  799. rslt = 0
  800. arg_msg = "因网络或其它原因导致添加单据备注操作失败"+"~n"+commit_transaction.SQLErrText
  801. GOTO ext
  802. END IF
  803. COMMIT USING commit_transaction;
  804. dscrp = dscrp+' '+arg_newdescppart
  805. ext: Return (rslt)
  806. end function
  807. public function integer c_auditing (boolean arg_ifcommit, ref string arg_msg);Long rslt = 1,cnt = 0,i
  808. IF f_aps_mrp_cklock(scid,arg_msg) = 0 THEN
  809. rslt = 0
  810. GOTO ext
  811. END IF
  812. DateTime null_dt
  813. SetNull(null_dt)
  814. uo_order_wfjg uo_wfjg
  815. uo_wfjg = Create uo_order_wfjg
  816. uo_wfjg.commit_transaction = commit_transaction
  817. uo_outware uo_out
  818. uo_out = Create uo_outware
  819. uo_out.commit_transaction = commit_transaction
  820. uo_out.if_getid_ture = False
  821. IF outwareid = 0 THEN
  822. rslt = 0
  823. arg_msg = "没有审核对象"
  824. GOTO ext
  825. END IF
  826. IF ctmint > 0 THEN
  827. arg_msg = '单据已截数,不能操作'
  828. rslt = 0
  829. GOTO ext
  830. END IF
  831. IF flag = 0 THEN
  832. rslt = 0
  833. arg_msg = "单据还未审核"
  834. GOTO ext
  835. END IF
  836. IF secflag = 1 THEN
  837. rslt = 0
  838. arg_msg = "单据已财务审核"
  839. GOTO ext
  840. END IF
  841. IF balcflag = 1 THEN
  842. rslt = 0
  843. arg_msg = "单据已经结存,不能撤审"
  844. GOTO ext
  845. END IF
  846. //检查外协商盘点表是否未审
  847. IF billtype = 4 THEN
  848. IF uof_check_sptpdb_audit(sptid,arg_msg) = 0 THEN
  849. rslt = 0
  850. GOTO ext
  851. END IF
  852. END IF
  853. UPDATE ow_wfjg_out
  854. SET Auditingemp = '',
  855. Auditingdate = :null_dt,
  856. flag = 0
  857. WHERE ow_wfjg_out.outwareid = :outwareid
  858. AND flag = 1
  859. And scid = :scid Using commit_transaction;
  860. IF commit_transaction.SQLCode <> 0 THEN
  861. rslt = 0
  862. arg_msg = "审核单据操作失败"+"~n"+commit_transaction.SQLErrText
  863. GOTO ext
  864. ELSEIF commit_transaction.SQLNRows = 0 THEN
  865. rslt = 0
  866. arg_msg = "单据正在审核,请稍后查询。"+"~n"+commit_transaction.SQLErrText
  867. GOTO ext
  868. END IF
  869. Long ay_outwareid[],ll_outwareid,ch
  870. DECLARE getoutware CURSOR FOR
  871. SELECT outwareid FROM u_outware WHERE billtype = :billtype
  872. AND relid = :outwareid
  873. AND scid = :scid
  874. Using commit_transaction;
  875. OPEN getoutware;
  876. DO WHILE commit_transaction.SQLCode = 0
  877. FETCH getoutware Into :ll_outwareid;
  878. IF commit_transaction.SQLCode <> 0 THEN EXIT
  879. ch++
  880. ay_outwareid[ch] = ll_outwareid
  881. LOOP
  882. CLOSE getoutware;
  883. IF ch = 0 THEN
  884. arg_msg = '没有对应的出仓单'
  885. rslt = 0
  886. GOTO ext
  887. END IF
  888. FOR i = 1 To ch
  889. IF uo_out.getinfo(scid,ay_outwareid[i],arg_msg) = 0 THEN
  890. rslt = 0
  891. GOTO ext
  892. END IF
  893. IF uo_out.c_auditing(False,arg_msg) = 0 THEN
  894. rslt = 0
  895. GOTO ext
  896. END IF
  897. IF uo_out.del(scid,ay_outwareid[i],0,arg_msg,False) = 0 THEN
  898. rslt = 0
  899. GOTO ext
  900. END IF
  901. NEXT
  902. IF billtype = 4 THEN
  903. FOR i = 1 To it_mxbt
  904. IF f_update_mtrlware_spt_out (billtype,thflag,scid,outwaremx[i].mtrlid, &
  905. outwaremx[i].mtrlcode, outwaremx[i].plancode,&
  906. outwaremx[i].status, 0 - outwaremx[i].qty, 0 - outwaremx[i].costamt,&
  907. outwaremx[i].planprice, sptid, &
  908. outwaremx[i].woodcode, outwaremx[i].pcode,arg_msg,False,commit_transaction) = 0 THEN
  909. rslt = 0
  910. GOTO ext
  911. END IF
  912. IF outwaremx[i].relid > 0 THEN
  913. IF outwaremx[i].thtype = 0 THEN //重新发出
  914. IF uo_wfjg.addmxcmpl_out(scid,outwaremx[i].relid,outwaremx[i].relprintid,0 - outwaremx[i].qty,arg_msg,False) <> 1 THEN
  915. rslt = 0
  916. GOTO ext
  917. END IF
  918. ELSEIF outwaremx[i].thtype = 1 THEN //取消 终止收货
  919. IF uo_wfjg.stopaddqty(scid, outwaremx[i].relid, outwaremx[i].relprintid2,'', outwaremx[i].relqty2,0,'终止收货',arg_msg, False) = 0 THEN
  920. //arg_msg = '更新行:'+String(i)+','+arg_msg
  921. rslt = 0
  922. GOTO ext
  923. END IF
  924. END IF
  925. END IF
  926. NEXT
  927. END IF
  928. //更新库存已开单数
  929. IF uof_noauditingqty_add(arg_msg) = 0 THEN
  930. rslt = 0
  931. GOTO ext
  932. END IF
  933. flag = 0
  934. ext:
  935. Destroy uo_out
  936. Destroy uo_wfjg
  937. IF rslt = 0 THEN
  938. ROLLBACK Using commit_transaction;
  939. ELSEIF rslt = 1 And arg_ifcommit THEN
  940. COMMIT Using commit_transaction;
  941. END IF
  942. RETURN rslt
  943. end function
  944. public function integer p_clearmx ();//int p_clearmx()
  945. //清除明细
  946. it_mxbt=0
  947. return 1
  948. end function
  949. public function integer p_getinfo (long arg_scid, long arg_outwareid, ref string arg_msg);//p_getinfo(arg_scid,arg_outwareid,arg_msg)
  950. //0 失败 1成功
  951. INT rslt=1
  952. IF arg_outwareid<=0 THEN
  953. rslt=0
  954. arG_MSG="非法出仓单唯一码"
  955. goto ext
  956. end if
  957. SELECT ow_wfjg_out.outwarecode,
  958. ow_wfjg_out.billtype,
  959. ow_wfjg_out.relid,
  960. ow_wfjg_out.outdate,
  961. ow_wfjg_out.outrep,
  962. ow_wfjg_out.part,
  963. ow_wfjg_out.sptid,
  964. ow_wfjg_out.sptname,
  965. ow_wfjg_out.dscrp,
  966. ow_wfjg_out.thflag,
  967. ow_wfjg_out.flag,
  968. ow_wfjg_out.secflag,
  969. ow_wfjg_out.balcflag ,
  970. ow_wfjg_out.banktypeid ,
  971. ow_wfjg_out.refpayid ,
  972. ow_wfjg_out.ctmint
  973. INTO :outwarecode,
  974. :billtype,
  975. :relid,
  976. :outdate,
  977. :outrep,
  978. :part,
  979. :sptid,
  980. :sptname,
  981. :dscrp,
  982. :thflag,
  983. :flag,
  984. :secflag,
  985. :balcflag ,
  986. :banktypeid,
  987. :refpayid,
  988. :ctmint
  989. FROM ow_wfjg_out
  990. WHERE ow_wfjg_out.outwareid = :arg_outwareid
  991. and scid=:arg_scid
  992. using commit_transaction;
  993. if commit_transaction.sqlcode<>0 then
  994. rslt=0
  995. arG_MSG="查询操作失败(错误出仓单唯一码),出仓单"+commit_transaction.sqlerrtext
  996. goto ext
  997. end if
  998. outwareid = arg_outwareid
  999. scid = arg_scid
  1000. ext:
  1001. IF rslt=0 THEN p_reset()
  1002. return rslt
  1003. end function
  1004. public function integer p_reset ();//int p_reset()
  1005. //清除对象及其明细
  1006. scid = 0
  1007. outwareid = 0
  1008. outwarecode = ''
  1009. billtype = 0
  1010. opemp = ''
  1011. modemp = ''
  1012. auditingrep = ''
  1013. flag = 0
  1014. relid = 0
  1015. //storageid = 0
  1016. outrep = ''
  1017. part = ''
  1018. dscrp = ''
  1019. sptid = 0
  1020. sptname = ''
  1021. thflag = 0
  1022. it_newbegin = FALSE
  1023. it_updatebegin = FALSE
  1024. //清除明细
  1025. p_clearmx()
  1026. RETURN 1
  1027. end function
  1028. public function integer secauditing (boolean arg_ifcommit, ref string arg_msg);Long rslt = 1,cnt = 0,i
  1029. String ls_about,ls_dscrp
  1030. uo_mustpay uo_pay
  1031. uo_pay = Create uo_mustpay
  1032. Decimal ld_payamt = 0,ld_mstpayamt = 0
  1033. IF outwareid = 0 THEN
  1034. rslt = 0
  1035. arg_msg = "没有审核对象"
  1036. GOTO ext
  1037. END IF
  1038. IF flag = 0 THEN
  1039. rslt = 0
  1040. arg_msg = "单据还没有经过审核"
  1041. GOTO ext
  1042. END IF
  1043. IF secflag = 1 THEN
  1044. rslt = 0
  1045. arg_msg = "单据已经过财务审核"
  1046. GOTO ext
  1047. END IF
  1048. Int li_btype
  1049. Long ll_accountsid
  1050. Long ll_moneyid_native
  1051. SELECT count(*) INTO :cnt
  1052. FROM u_user
  1053. Where username = :publ_operator Using commit_transaction ;
  1054. IF commit_transaction.SQLCode <> 0 THEN
  1055. rslt = 0
  1056. arg_msg = "查询操作失败,操作员"
  1057. GOTO ext
  1058. END IF
  1059. IF cnt = 0 THEN
  1060. rslt = 0
  1061. arg_msg = "操作员姓名未登记或已取消"
  1062. GOTO ext
  1063. END IF
  1064. UPDATE ow_wfjg_out
  1065. SET secauditingrep = :publ_operator,
  1066. secauditingdate = getdate(),
  1067. secflag = 1
  1068. WHERE ow_wfjg_out.outwareid = :outwareid
  1069. AND flag = 1
  1070. AND secflag = 0
  1071. And scid = :scid Using commit_transaction;
  1072. IF commit_transaction.SQLCode <> 0 THEN
  1073. rslt = 0
  1074. arg_msg = "因网络或其它原因导致财务审核单据操作失败"+"~n"+commit_transaction.SQLErrText
  1075. GOTO ext
  1076. ELSEIF commit_transaction.SQLNRows = 0 THEN
  1077. rslt = 0
  1078. arg_msg = "单据正在财务审核,请稍后查询。"+"~n"+commit_transaction.SQLErrText
  1079. GOTO ext
  1080. END IF
  1081. IF sum_amt <> 0 And billtype = 7 THEN
  1082. SELECT btype,accountsid INTO :li_btype,:ll_accountsid
  1083. FROM cw_banktype
  1084. Where banktypeid = :banktypeid Using commit_transaction;
  1085. IF commit_transaction.SQLCode <> 0 THEN
  1086. rslt = 0
  1087. arg_msg = '查询结算方式类型失败,'+ commit_transaction.SQLErrText
  1088. GOTO ext
  1089. END IF
  1090. SELECT moneyid INTO :ll_moneyid_native
  1091. FROM cw_currency
  1092. Where native = 1;
  1093. IF commit_transaction.SQLCode <> 0 THEN
  1094. arg_msg = '查询本位币资料失败'
  1095. rslt = 0
  1096. GOTO ext
  1097. END IF
  1098. IF thflag = 1 THEN
  1099. ls_about = outwarecode + "退货款,相关号:"+part
  1100. ELSE
  1101. ls_about = outwarecode + "应收款,相关号:"+part
  1102. END IF
  1103. ls_dscrp = ls_about
  1104. ld_mstpayamt = sum_amt
  1105. IF li_btype = 1 THEN
  1106. ld_payamt = ld_mstpayamt
  1107. ELSE
  1108. ld_payamt = 0
  1109. END IF
  1110. Long ll_dft_itemid
  1111. IF thflag = 1 THEN
  1112. SELECT itemid INTO :ll_dft_itemid
  1113. FROM u_itemdef
  1114. Where dfttype = 9;
  1115. IF sqlca.SQLCode <> 0 THEN
  1116. arg_msg = '查询默认外协销售退货项目资料失败'+sqlca.SQLErrText
  1117. rslt = 0
  1118. GOTO ext
  1119. END IF
  1120. ELSE
  1121. SELECT itemid INTO :ll_dft_itemid
  1122. FROM u_itemdef
  1123. Where dfttype = 8;
  1124. IF sqlca.SQLCode <> 0 THEN
  1125. arg_msg = '查询默认外协销售项目资料失败'+sqlca.SQLErrText
  1126. rslt = 0
  1127. GOTO ext
  1128. END IF
  1129. END IF
  1130. s_bmstpay s_pay
  1131. s_pay.scid = scid
  1132. s_pay.sptid = sptid
  1133. s_pay.paydate = outdate
  1134. s_pay.inrep = outrep
  1135. s_pay.oriamt = 0 - ld_mstpayamt
  1136. s_pay.mstpayamt = 0 - ld_mstpayamt
  1137. s_pay.payamt = 0 - ld_payamt
  1138. s_pay.dscrp = ls_about
  1139. s_pay.billcode = outwarecode
  1140. s_pay.banktypeid = banktypeid
  1141. // s_pay.viewdate = plandate
  1142. s_pay.opemp = publ_operator
  1143. s_pay.buildtype = 1
  1144. s_pay.inwareid = outwareid
  1145. s_pay.accountsid = ll_accountsid
  1146. s_pay.itemid = ll_dft_itemid
  1147. s_pay.moneyid = ll_moneyid_native
  1148. s_pay.moneyid_cn = ll_moneyid_native
  1149. IF uo_pay.add_payrec (s_pay,arg_msg,False) = 0 THEN
  1150. rslt = 0
  1151. GOTO ext
  1152. END IF
  1153. UPDATE ow_wfjg_out
  1154. SET refpayid = :uo_pay.ref_payid
  1155. WHERE ow_wfjg_out.outwareid = :outwareid
  1156. AND scid = :scid
  1157. And flag = 1 Using commit_transaction;
  1158. IF commit_transaction.SQLCode <> 0 THEN
  1159. arg_msg = '更新外协单相关应收帐ID失败'
  1160. rslt = 0
  1161. GOTO ext
  1162. END IF
  1163. END IF
  1164. secflag = 1
  1165. ext:
  1166. IF rslt = 0 THEN
  1167. ROLLBACK Using commit_transaction;
  1168. ELSEIF rslt = 1 And arg_ifcommit THEN
  1169. COMMIT Using commit_transaction;
  1170. END IF
  1171. Destroy uo_pay
  1172. RETURN rslt
  1173. end function
  1174. public function integer c_secauditing (boolean arg_ifcommit, ref string arg_msg);Long rslt = 1,cnt = 0,i
  1175. DateTime null_dt
  1176. SetNull(null_dt)
  1177. uo_mustpay uo_pay
  1178. uo_pay = Create uo_mustpay
  1179. String ls_mtrlname
  1180. IF outwareid = 0 THEN
  1181. rslt = 0
  1182. arg_msg = "没有撤审对象"
  1183. GOTO ext
  1184. END IF
  1185. IF ctmint > 0 THEN
  1186. arg_msg = '单据已截数,不能操作'
  1187. rslt = 0
  1188. GOTO ext
  1189. END IF
  1190. IF secflag = 0 THEN
  1191. rslt = 0
  1192. arg_msg = "该单据财务未审,不能进行财务撤审"
  1193. GOTO ext
  1194. END IF
  1195. UPDATE ow_wfjg_out
  1196. SET secauditingrep = '',
  1197. secauditingdate = :null_dt,
  1198. secflag = 0,
  1199. refpayid = 0
  1200. WHERE ow_wfjg_out.outwareid = :outwareid
  1201. AND secflag = 1
  1202. And scid = :scid Using commit_transaction;
  1203. IF commit_transaction.SQLCode <> 0 THEN
  1204. rslt = 0
  1205. arg_msg = "因网络或其它原因导致财务撤审单据操作失败"+"~n"+commit_transaction.SQLErrText
  1206. GOTO ext
  1207. ELSEIF commit_transaction.SQLNRows = 0 THEN
  1208. rslt = 0
  1209. arg_msg = "单据正在财务撤审,请稍后查询。"+"~n"+commit_transaction.SQLErrText
  1210. GOTO ext
  1211. END IF
  1212. IF sum_amt <> 0 And billtype = 7 THEN
  1213. IF uo_pay.del_payrec(scid,1,refpayid,sptid,arg_msg,False) = 0 THEN
  1214. rslt = 0
  1215. GOTO ext
  1216. END IF
  1217. END IF
  1218. secflag = 0
  1219. ext:
  1220. IF rslt = 0 THEN
  1221. ROLLBACK Using commit_transaction;
  1222. ELSEIF rslt = 1 And arg_ifcommit THEN
  1223. COMMIT Using commit_transaction;
  1224. END IF
  1225. Destroy uo_pay
  1226. RETURN rslt
  1227. end function
  1228. public function integer acceptmx (long arg_mtrlwareid, decimal arg_uqty, string arg_uunit, decimal arg_qty, decimal arg_fprice, string arg_mxdscrp, long arg_printid, ref string arg_msg, integer arg_ifrel, long arg_relid, long arg_relprintid, long arg_olmtrlid, decimal arg_rate);s_outwaremx_wfjg s_mx
  1229. s_mx.mtrlwareid = arg_mtrlwareid
  1230. s_mx.uqty = arg_uqty
  1231. s_mx.uunit = arg_uunit
  1232. s_mx.qty = arg_qty
  1233. s_mx.fprice = arg_fprice
  1234. s_mx.mxdscrp = arg_mxdscrp
  1235. s_mx.printid = arg_printid
  1236. s_mx.ifrel = arg_ifrel
  1237. s_mx.relid = arg_relid
  1238. s_mx.relprintid = arg_relprintid
  1239. s_mx.olmtrlid = arg_olmtrlid
  1240. s_mx.rate = arg_rate
  1241. s_mx.rebate = 1
  1242. return acceptmx(s_mx, arg_msg)
  1243. ///*
  1244. //Long rslt = 1,cnt = 0,LS_i
  1245. //Long i_mtrlid,i_storageid,i_sptid
  1246. //Int i_dxflag
  1247. //String i_plancode,i_mtrlcode,i_status,i_woodcode,i_pcode
  1248. //string ls_mtrlcuscode,ls_location
  1249. //Decimal i_planprice
  1250. //Double i_cost
  1251. //Decimal i_notauditqty,i_allouseqty
  1252. //String ls_relcode
  1253. //Decimal ld_rate = 1
  1254. //
  1255. //IF uo_option_2unit = -1000 THEN
  1256. // rslt = 0
  1257. // arg_msg = '选项:[067]外协双单位核算,读取初始默认值失败,操作取消!'
  1258. // GOTO ext
  1259. //END IF
  1260. //
  1261. //IF it_newbegin = FALSE AND it_updatebegin = FALSE THEN
  1262. // rslt = 0
  1263. // arg_msg = "非编辑状态不可以使用,操作取消"
  1264. // GOTO ext
  1265. //END IF
  1266. //
  1267. ////清除空值
  1268. //IF IsNull(arg_mtrlwareid) THEN arg_mtrlwareid = 0
  1269. //IF IsNull(arg_printid) THEN arg_printid = 0
  1270. //IF IsNull(arg_qty) THEN arg_qty = 0
  1271. //IF IsNull(arg_mxdscrp) THEN arg_mxdscrp = ''
  1272. //IF IsNull(arg_ifrel) THEN arg_ifrel = 0
  1273. //IF IsNull(arg_relid) THEN arg_relid = 0
  1274. //IF IsNull(arg_relprintid) THEN arg_relprintid = 0
  1275. //IF IsNull(arg_olmtrlid) THEN arg_olmtrlid = 0
  1276. //IF IsNull(arg_uqty) THEN arg_uqty = 0
  1277. //IF IsNull(arg_uunit) THEN arg_uunit = ''
  1278. //IF IsNull(arg_qty) THEN arg_qty = 0
  1279. //IF IsNull(arg_fprice) THEN arg_fprice = 0
  1280. //IF IsNull(arg_rate) THEN arg_rate = 0
  1281. //
  1282. //
  1283. //
  1284. //// 如果出仓数量为 0,或物料编号为空,则不作任何处理
  1285. //IF arg_mtrlwareid = 0 OR arg_qty = 0 THEN
  1286. // rslt = 1
  1287. // GOTO ext
  1288. //END IF
  1289. //
  1290. //IF uo_option_2unit = 1 THEN
  1291. // IF arg_uqty = 0 THEN
  1292. // arg_msg = '行:'+String(arg_printid)+ ',请输入计价数量'
  1293. // rslt = 0
  1294. // GOTO ext
  1295. // END IF
  1296. //
  1297. // IF Trim(arg_uunit) = '' THEN
  1298. // arg_msg = '行:'+String(arg_printid)+ ',请输入计价单位'
  1299. // rslt = 0
  1300. // GOTO ext
  1301. // END IF
  1302. //END IF
  1303. //
  1304. //
  1305. //
  1306. ////检查物料库存ID
  1307. //SELECT u_mtrlware.mtrlid,
  1308. // u_mtrlware.storageid,
  1309. // u_mtrlware.plancode,
  1310. // u_mtrlware.status,
  1311. // u_mtrlware.cost,
  1312. // u_mtrldef.planprice,
  1313. // u_mtrldef.mtrlcode,
  1314. // u_mtrlware.sptid,
  1315. // u_mtrlware.dxflag,
  1316. // u_mtrlware.woodcode,
  1317. // u_mtrlware.pcode,
  1318. // u_mtrlware.noauditingqty,
  1319. // u_mtrlware.noallocqty,
  1320. // u_mtrlware.mtrlcuscode,
  1321. // u_mtrlware.location
  1322. // INTO :i_mtrlid,
  1323. // :i_storageid,
  1324. // :i_plancode,
  1325. // :i_status,
  1326. // :i_cost,
  1327. // :i_planprice,
  1328. // :i_mtrlcode,
  1329. // :i_sptid,
  1330. // :i_dxflag,
  1331. // :i_woodcode,
  1332. // :i_pcode,
  1333. // :i_notauditqty,
  1334. // :i_allouseqty,
  1335. // :ls_mtrlcuscode,
  1336. // :ls_location
  1337. // FROM u_mtrlware ,u_mtrldef
  1338. // WHERE ( u_mtrlware.mtrlwareid = :arg_mtrlwareid )
  1339. // AND ( u_mtrlware.mtrlid = u_mtrldef.mtrlid )
  1340. // And ( u_mtrlware.scid = :scid ) USING commit_transaction;
  1341. //
  1342. //IF commit_transaction.SQLCode <> 0 THEN
  1343. // rslt = 0
  1344. // arg_msg = '行:'+String(arg_printid)+ ",查询操作失败,库存编号错误"
  1345. // GOTO ext
  1346. //END IF
  1347. //
  1348. //IF IsNull(i_cost) THEN i_cost = 0
  1349. //IF IsNull(i_plancode) THEN i_plancode = ''
  1350. //IF IsNull(i_status) THEN i_status = ''
  1351. //IF IsNull(i_mtrlid) THEN i_mtrlid = 0
  1352. //IF IsNull(i_planprice) THEN i_planprice = 0
  1353. //IF IsNull(i_sptid) THEN i_sptid = 0
  1354. //IF IsNull(i_dxflag) THEN i_dxflag = 0
  1355. //IF IsNull(i_woodcode) THEN i_woodcode = ''
  1356. //IF IsNull(i_pcode) THEN i_pcode = ''
  1357. //IF IsNull(ls_mtrlcuscode) THEN ls_mtrlcuscode = ''
  1358. //IF IsNull(ls_location) THEN ls_location = ''
  1359. //
  1360. //IF arg_ifrel = 1 THEN
  1361. // IF arg_relid = 0 THEN
  1362. // rslt = 0
  1363. // arg_msg = '行:'+String(arg_printid)+ ',请选择加工计划!'
  1364. // GOTO ext
  1365. // END IF
  1366. //
  1367. // SELECT taskcode INTO :ls_relcode
  1368. // FROM u_order_wfjg
  1369. // Where wfjgID = :arg_relid USING commit_transaction;
  1370. // IF commit_transaction.SQLCode <> 0 THEN
  1371. // rslt = 0
  1372. // arg_msg = '行:'+String(arg_printid)+ ',查询加工计划号失败!>>'+commit_transaction.SQLErrText
  1373. // GOTO ext
  1374. // END IF
  1375. //
  1376. // SELECT count(*) INTO :cnt
  1377. // FROM u_order_wfjgMx_out
  1378. // WHERE wfjgid = :arg_relid
  1379. // AND mtrlid = :i_mtrlid
  1380. // AND status = :i_status
  1381. // AND woodcode = :i_woodcode
  1382. // AND orderid = :arg_olmtrlid
  1383. // AND printid = :arg_relprintid USING commit_transaction;
  1384. // IF commit_transaction.SQLCode <> 0 THEN
  1385. // rslt = 0
  1386. // arg_msg = '行:'+String(arg_printid)+ ',查询加工计划出仓明细失败!>'+commit_transaction.SQLErrText
  1387. // GOTO ext
  1388. // END IF
  1389. //
  1390. // IF cnt = 0 THEN
  1391. // rslt = 0
  1392. // arg_msg = '行:'+String(arg_printid)+ ',出仓物料:'+i_mtrlcode+'不在加工计划出仓明细中!'
  1393. // GOTO ext
  1394. // END IF
  1395. //END IF
  1396. //
  1397. ////*****检查大于未开数不可以开单
  1398. //IF flag = 0 THEN
  1399. // Decimal ol_mtrl_qty = 0
  1400. // Int ls_noallocflag
  1401. //
  1402. // SELECT noallocflag INTO :ls_noallocflag
  1403. // FROM u_storage
  1404. // Where storageid = :i_storageid USING commit_transaction;
  1405. // IF commit_transaction.SQLCode <> 0 THEN
  1406. // rslt = 0
  1407. // arg_msg = '行:'+String(arg_printid)+ ',查询仓库允许使用未开单库存属性失败'+sqlca.SQLErrText
  1408. // GOTO ext
  1409. // END IF
  1410. //
  1411. // IF ls_noallocflag = 1 THEN
  1412. //
  1413. // IF it_updatebegin THEN
  1414. // SELECT sum(ow_wfjgmx_out.qty)
  1415. // INTO :ol_mtrl_qty
  1416. // FROM ow_wfjgmx_out
  1417. // WHERE ow_wfjgmx_out.outwareid = :outwareid
  1418. // AND ow_wfjgmx_out.mtrlwareid = :arg_mtrlwareid
  1419. // AND scid = :scid USING commit_transaction;
  1420. // IF commit_transaction.SQLCode = -1 THEN
  1421. // rslt = 0
  1422. // arg_msg = '行:'+String(arg_printid)+ ',查询原开单数量失败'
  1423. // GOTO ext
  1424. // END IF
  1425. // END IF
  1426. //
  1427. // IF arg_qty > ( i_allouseqty - i_notauditqty + ol_mtrl_qty ) THEN
  1428. // rslt = 0
  1429. // arg_msg = String(i_mtrlcode)+"库存未开单数不够,不能开单.未开单数{"+String(i_allouseqty - i_notauditqty + ol_mtrl_qty,'#####,0.00##')+"}"
  1430. // GOTO ext
  1431. // END IF
  1432. // END IF
  1433. //END IF
  1434. //
  1435. ////***********************************************
  1436. //
  1437. //
  1438. //IF i_cost < 0 THEN //检查进仓价
  1439. // rslt = 0
  1440. // arg_msg = '行:'+String(arg_printid)+ ",物料:" + String(i_mtrlcode)+" 单价错误"
  1441. // GOTO ext
  1442. //END IF
  1443. //
  1444. ////写入内容
  1445. //it_mxbt++
  1446. //
  1447. //
  1448. //outwaremx[it_mxbt].mtrlwareid = arg_mtrlwareid
  1449. //outwaremx[it_mxbt].mtrlid = i_mtrlid
  1450. //outwaremx[it_mxbt].status = i_status
  1451. //outwaremx[it_mxbt].qty = arg_qty
  1452. //outwaremx[it_mxbt].storageid = i_storageid
  1453. //outwaremx[it_mxbt].cost = i_cost
  1454. //outwaremx[it_mxbt].costamt = Round(i_cost * arg_qty,2)
  1455. //outwaremx[it_mxbt].newpriceamt = 0
  1456. //outwaremx[it_mxbt].plancode = i_plancode
  1457. //outwaremx[it_mxbt].planprice = i_planprice
  1458. //outwaremx[it_mxbt].mtrlcode = i_mtrlcode
  1459. //outwaremx[it_mxbt].mxdscrp = arg_mxdscrp
  1460. //outwaremx[it_mxbt].printid = arg_printid
  1461. //outwaremx[it_mxbt].olmtrlid = arg_olmtrlid
  1462. //
  1463. //outwaremx[it_mxbt].rebate = 1
  1464. //IF billtype = 7 THEN
  1465. // outwaremx[it_mxbt].fprice = arg_fprice
  1466. // outwaremx[it_mxbt].price = arg_fprice
  1467. // outwaremx[it_mxbt].uprice = arg_fprice
  1468. //ELSE
  1469. // outwaremx[it_mxbt].fprice = i_cost
  1470. // outwaremx[it_mxbt].price = i_cost
  1471. //
  1472. // IF uo_option_2unit = 0 THEN
  1473. // outwaremx[it_mxbt].uprice = i_cost
  1474. // outwaremx[it_mxbt].uqty = arg_qty
  1475. // ELSE
  1476. // outwaremx[it_mxbt].uprice = Round(arg_qty * i_cost/arg_uqty,5)
  1477. // outwaremx[it_mxbt].uqty = arg_uqty
  1478. // END IF
  1479. //END IF
  1480. //
  1481. //IF arg_uqty <> 0 THEN
  1482. // outwaremx[it_mxbt].rate = arg_qty / arg_uqty
  1483. //ELSE
  1484. // outwaremx[it_mxbt].rate = 0
  1485. //END IF
  1486. //
  1487. //
  1488. //outwaremx[it_mxbt].uunit = arg_uunit
  1489. //
  1490. //outwaremx[it_mxbt].sptid = i_sptid
  1491. //outwaremx[it_mxbt].dxflag = i_dxflag
  1492. //outwaremx[it_mxbt].ifrel = arg_ifrel
  1493. //outwaremx[it_mxbt].relid = arg_relid
  1494. //outwaremx[it_mxbt].relprintid = arg_relprintid
  1495. //
  1496. //outwaremx[it_mxbt].woodcode = i_woodcode
  1497. //outwaremx[it_mxbt].pcode = i_pcode
  1498. //outwaremx[it_mxbt].relcode = ls_relcode
  1499. //outwaremx[it_mxbt].mtrlcuscode = ls_mtrlcuscode
  1500. //outwaremx[it_mxbt].location = ls_location
  1501. //
  1502. //ext:
  1503. //IF rslt = 0 THEN p_clearmx()
  1504. //RETURN rslt
  1505. //*/
  1506. end function
  1507. public function integer uof_check_sptpdb_audit (long arg_sptid, ref string arg_msg);Int rslt = 1
  1508. Long cnt
  1509. if billtype = 9 then goto ext //盘点单不算
  1510. SELECT count(*)
  1511. INTO :cnt
  1512. FROM ow_wfjg_sptpdb
  1513. WHERE sptid = :arg_sptid
  1514. And flag = 0 Using commit_transaction;
  1515. IF commit_transaction.SQLCode <> 0 THEN
  1516. rslt = 0
  1517. arg_msg = '查询外协商库存是否有盘点表未审核失败,'+commit_transaction.SQLErrText
  1518. GOTO ext
  1519. END IF
  1520. IF cnt > 0 THEN
  1521. rslt = 0
  1522. arg_msg = '外协商库存有盘点表未审核,不能仓审或仓撤单据,请检查'
  1523. GOTO ext
  1524. END IF
  1525. ext:
  1526. RETURN rslt
  1527. end function
  1528. public function integer uof_noauditingqty_add (ref string arg_msg);If uo_option_noauditingqty_mode = 0 Then Return 1
  1529. Int rslt = 1
  1530. Long i
  1531. For i = 1 To it_mxbt
  1532. Update u_mtrlware
  1533. Set noauditingqty = noauditingqty + :outwaremx[i].qty,
  1534. noauditinguqty = noauditingqty + :outwaremx[i].uqty
  1535. Where scid = :scid
  1536. And mtrlwareid = :outwaremx[i].mtrlwareid;
  1537. If sqlca.SQLCode <> 0 Then
  1538. rslt = 0
  1539. arg_msg = '物料:'+String(outwaremx[i].mtrlcode)+',更新明细库存已开单数失败 '+sqlca.SQLErrText
  1540. Goto ext
  1541. End If
  1542. Next
  1543. ext:
  1544. Return rslt
  1545. end function
  1546. public function integer uof_noauditingqty_del (long arg_scid, long arg_outwareid, ref string arg_msg);If uo_option_noauditingqty_mode = 0 Then Return 1
  1547. Int rslt = 1
  1548. Long i,ll_i
  1549. i = 1
  1550. s_outwaremx_wfjg arg_s_mx[]
  1551. Declare cur_wfjgmx Cursor For
  1552. Select ow_wfjgmx_out.mtrlwareid,
  1553. ow_wfjgmx_out.qty,
  1554. ow_wfjgmx_out.uqty,
  1555. u_mtrldef.mtrlcode
  1556. From ow_wfjgmx_out,u_mtrldef
  1557. Where ow_wfjgmx_out.outwareid = :arg_outwareid And
  1558. ow_wfjgmx_out.mtrlid = u_mtrldef.mtrlid And
  1559. ow_wfjgmx_out.scid = :arg_scid Using commit_transaction;
  1560. Open cur_wfjgmx;
  1561. Fetch cur_wfjgmx Into :arg_s_mx[i].mtrlwareid,
  1562. :arg_s_mx[i].qty,:arg_s_mx[i].uqty,:arg_s_mx[i].mtrlcode;
  1563. Do While sqlca.SQLCode = 0
  1564. i++
  1565. Fetch cur_wfjgmx Into :arg_s_mx[i].mtrlwareid,
  1566. :arg_s_mx[i].qty,:arg_s_mx[i].uqty,:arg_s_mx[i].mtrlcode;
  1567. Loop
  1568. Close cur_wfjgmx;
  1569. For ll_i = 1 To i - 1
  1570. Update u_mtrlware
  1571. Set noauditingqty = noauditingqty - :arg_s_mx[ll_i].qty,
  1572. noauditinguqty = noauditingqty - :arg_s_mx[ll_i].uqty
  1573. Where scid = :arg_scid
  1574. And mtrlwareid = :arg_s_mx[ll_i].mtrlwareid;
  1575. If sqlca.SQLCode <> 0 Then
  1576. rslt = 0
  1577. arg_msg = '物料:'+String(arg_s_mx[ll_i].mtrlcode)+',更新明细库存已开单数失败 '+sqlca.SQLErrText
  1578. Goto ext
  1579. End If
  1580. Next
  1581. ext:
  1582. Return rslt
  1583. end function
  1584. public function integer acceptmx (s_outwaremx_wfjg s_mx, ref string arg_msg);Long rslt = 1,cnt = 0,LS_i
  1585. Long i_mtrlid,i_storageid,i_sptid
  1586. Int i_dxflag
  1587. String i_plancode,i_mtrlcode,i_status,i_woodcode,i_pcode
  1588. String ls_mtrlcuscode,ls_location
  1589. Decimal i_planprice
  1590. Double i_cost
  1591. Decimal i_notauditqty,i_allouseqty
  1592. String ls_relcode
  1593. Decimal ld_rate = 1
  1594. IF uo_option_2unit = -1000 THEN
  1595. rslt = 0
  1596. arg_msg = '选项:[067]外协双单位核算,读取初始默认值失败,操作取消!'
  1597. GOTO ext
  1598. END IF
  1599. IF it_newbegin = False And it_updatebegin = False THEN
  1600. rslt = 0
  1601. arg_msg = "非编辑状态不可以使用,操作取消"
  1602. GOTO ext
  1603. END IF
  1604. //清除空值
  1605. IF IsNull(s_mx.mtrlwareid) THEN s_mx.mtrlwareid = 0
  1606. IF IsNull(s_mx.printid) THEN s_mx.printid = 0
  1607. IF IsNull(s_mx.qty) THEN s_mx.qty = 0
  1608. IF IsNull(s_mx.mxdscrp) THEN s_mx.mxdscrp = ''
  1609. IF IsNull(s_mx.ifrel) THEN s_mx.ifrel = 0
  1610. IF IsNull(s_mx.relid) THEN s_mx.relid = 0
  1611. IF IsNull(s_mx.relprintid) THEN s_mx.relprintid = 0
  1612. IF IsNull(s_mx.olmtrlid) THEN s_mx.olmtrlid = 0
  1613. IF IsNull(s_mx.uqty) THEN s_mx.uqty = 0
  1614. IF IsNull(s_mx.uunit) THEN s_mx.uunit = ''
  1615. IF IsNull(s_mx.qty) THEN s_mx.qty = 0
  1616. IF IsNull(s_mx.fprice) THEN s_mx.fprice = 0
  1617. IF IsNull(s_mx.rate) THEN s_mx.rate = 0
  1618. IF IsNull(s_mx.thtype) THEN s_mx.thtype = 0
  1619. IF IsNull(s_mx.relprintid2) THEN s_mx.relprintid2 = 0
  1620. //IF IsNull(s_mx.relmtrlid2) THEN s_mx.relmtrlid2 = 0
  1621. //IF IsNull(s_mx.relqty2) THEN s_mx.relqty2 = 0
  1622. // 如果出仓数量为 0,或物料编号为空,则不作任何处理
  1623. IF s_mx.mtrlwareid = 0 Or s_mx.qty = 0 THEN
  1624. rslt = 1
  1625. GOTO ext
  1626. END IF
  1627. IF uo_option_2unit = 1 THEN
  1628. IF s_mx.uqty = 0 THEN
  1629. arg_msg = '行:'+String(s_mx.printid)+ ',请输入计价数量'
  1630. rslt = 0
  1631. GOTO ext
  1632. END IF
  1633. IF Trim(s_mx.uunit) = '' THEN
  1634. arg_msg = '行:'+String(s_mx.printid)+ ',请输入计价单位'
  1635. rslt = 0
  1636. GOTO ext
  1637. END IF
  1638. END IF
  1639. //检查物料库存ID
  1640. SELECT u_mtrlware.mtrlid,
  1641. u_mtrlware.storageid,
  1642. u_mtrlware.plancode,
  1643. u_mtrlware.status,
  1644. u_mtrlware.cost,
  1645. u_mtrldef.planprice,
  1646. u_mtrldef.mtrlcode,
  1647. u_mtrlware.sptid,
  1648. u_mtrlware.dxflag,
  1649. u_mtrlware.woodcode,
  1650. u_mtrlware.pcode,
  1651. u_mtrlware.noauditingqty,
  1652. u_mtrlware.noallocqty,
  1653. u_mtrlware.mtrlcuscode,
  1654. u_mtrlware.location
  1655. INTO :i_mtrlid,
  1656. :i_storageid,
  1657. :i_plancode,
  1658. :i_status,
  1659. :i_cost,
  1660. :i_planprice,
  1661. :i_mtrlcode,
  1662. :i_sptid,
  1663. :i_dxflag,
  1664. :i_woodcode,
  1665. :i_pcode,
  1666. :i_notauditqty,
  1667. :i_allouseqty,
  1668. :ls_mtrlcuscode,
  1669. :ls_location
  1670. FROM u_mtrlware ,u_mtrldef
  1671. WHERE ( u_mtrlware.mtrlwareid = :s_mx.mtrlwareid )
  1672. AND ( u_mtrlware.mtrlid = u_mtrldef.mtrlid )
  1673. And ( u_mtrlware.scid = :scid ) Using commit_transaction;
  1674. IF commit_transaction.SQLCode <> 0 THEN
  1675. rslt = 0
  1676. arg_msg = '行:'+String(s_mx.printid)+ ",查询操作失败,库存编号错误"
  1677. GOTO ext
  1678. END IF
  1679. IF IsNull(i_cost) THEN i_cost = 0
  1680. IF IsNull(i_plancode) THEN i_plancode = ''
  1681. IF IsNull(i_status) THEN i_status = ''
  1682. IF IsNull(i_mtrlid) THEN i_mtrlid = 0
  1683. IF IsNull(i_planprice) THEN i_planprice = 0
  1684. IF IsNull(i_sptid) THEN i_sptid = 0
  1685. IF IsNull(i_dxflag) THEN i_dxflag = 0
  1686. IF IsNull(i_woodcode) THEN i_woodcode = ''
  1687. IF IsNull(i_pcode) THEN i_pcode = ''
  1688. IF IsNull(ls_mtrlcuscode) THEN ls_mtrlcuscode = ''
  1689. IF IsNull(ls_location) THEN ls_location = ''
  1690. IF s_mx.ifrel = 1 THEN
  1691. IF s_mx.relid = 0 THEN
  1692. rslt = 0
  1693. arg_msg = '行:'+String(s_mx.printid)+ ',请选择外协订单!'
  1694. GOTO ext
  1695. END IF
  1696. SELECT taskcode INTO :ls_relcode
  1697. FROM u_order_wfjg
  1698. Where wfjgID = :s_mx.relid Using commit_transaction;
  1699. IF commit_transaction.SQLCode <> 0 THEN
  1700. rslt = 0
  1701. arg_msg = '行:'+String(s_mx.printid)+ ',查询外协订单号失败!>>'+commit_transaction.SQLErrText
  1702. GOTO ext
  1703. END IF
  1704. SELECT count(*) INTO :cnt
  1705. FROM u_order_wfjgMx_out
  1706. WHERE wfjgid = :s_mx.relid
  1707. AND mtrlid = :i_mtrlid
  1708. AND status = :i_status
  1709. AND woodcode = :i_woodcode
  1710. AND orderid = :s_mx.olmtrlid
  1711. And printid = :s_mx.relprintid Using commit_transaction;
  1712. IF commit_transaction.SQLCode <> 0 THEN
  1713. rslt = 0
  1714. arg_msg = '行:'+String(s_mx.printid)+ ',查询外协订单出仓明细失败!>'+commit_transaction.SQLErrText
  1715. GOTO ext
  1716. END IF
  1717. IF cnt = 0 THEN
  1718. rslt = 0
  1719. arg_msg = '行:'+String(s_mx.printid)+ ',出仓物料:'+i_mtrlcode+'不在外协订单出仓明细中!'
  1720. GOTO ext
  1721. END IF
  1722. IF s_mx.thtype = 1 THEN
  1723. IF s_mx.relprintid2 = 0 THEN
  1724. //先找找是否只有一条, 如果是,自己分配,如果是多条,强制选择
  1725. SELECT count(*) INTO :cnt
  1726. FROM u_order_wfjgMx_out INNER JOIN
  1727. u_order_wfjgmx_out_mx ON
  1728. u_order_wfjgMx_out.scid = u_order_wfjgmx_out_mx.scid AND
  1729. u_order_wfjgMx_out.wfjgID = u_order_wfjgmx_out_mx.wfjgid AND
  1730. u_order_wfjgMx_out.MtrlID = u_order_wfjgmx_out_mx.mtrlid AND
  1731. u_order_wfjgMx_out.status = u_order_wfjgmx_out_mx.status AND
  1732. u_order_wfjgMx_out.woodcode = u_order_wfjgmx_out_mx.woodcode AND
  1733. u_order_wfjgMx_out.pcode = u_order_wfjgmx_out_mx.pcode AND
  1734. u_order_wfjgMx_out.unit = u_order_wfjgmx_out_mx.unit
  1735. WHERE (u_order_wfjgMx_out.wfjgID = :s_mx.relid)
  1736. And (u_order_wfjgMx_out.printid = :s_mx.relprintid) Using commit_transaction ;
  1737. IF commit_transaction.SQLCode <> 0 THEN
  1738. arg_msg = '行:'+String(s_mx.printid)+',查询外协订单收货明细ID失败,'+commit_transaction.SQLErrText
  1739. rslt = 0
  1740. GOTO ext
  1741. END IF
  1742. IF cnt = 1 THEN
  1743. SELECT u_order_wfjgmx_out_mx.relprintid INTO :s_mx.relprintid2
  1744. FROM u_order_wfjgMx_out INNER JOIN
  1745. u_order_wfjgmx_out_mx ON
  1746. u_order_wfjgMx_out.scid = u_order_wfjgmx_out_mx.scid AND
  1747. u_order_wfjgMx_out.wfjgID = u_order_wfjgmx_out_mx.wfjgid AND
  1748. u_order_wfjgMx_out.MtrlID = u_order_wfjgmx_out_mx.mtrlid AND
  1749. u_order_wfjgMx_out.status = u_order_wfjgmx_out_mx.status AND
  1750. u_order_wfjgMx_out.woodcode = u_order_wfjgmx_out_mx.woodcode AND
  1751. u_order_wfjgMx_out.pcode = u_order_wfjgmx_out_mx.pcode AND
  1752. u_order_wfjgMx_out.unit = u_order_wfjgmx_out_mx.unit
  1753. WHERE (u_order_wfjgMx_out.wfjgID = :s_mx.relid)
  1754. And (u_order_wfjgMx_out.printid = :s_mx.relprintid) Using commit_transaction ;
  1755. IF commit_transaction.SQLCode <> 0 THEN
  1756. arg_msg = '行:'+String(s_mx.printid)+',查询外协订单收货明细ID失败,'+commit_transaction.SQLErrText
  1757. rslt = 0
  1758. GOTO ext
  1759. END IF
  1760. END IF
  1761. IF s_mx.relprintid2 = 0 THEN
  1762. arg_msg = '行:'+String(s_mx.printid)+',请选择对应的外协订单收货明细'
  1763. rslt = 0
  1764. GOTO ext
  1765. END IF
  1766. END IF
  1767. Decimal lde_truerqqty_in_pf, lde_rqqty_out_pf, lde_sonscale
  1768. //得到收货物料 s_mx.relmtrlid2
  1769. SELECT u_order_wfjgMx.mtrlid, u_order_wfjgMx.qty
  1770. INTO :s_mx.relmtrlid2, :lde_truerqqty_in_pf
  1771. FROM u_order_wfjgMx
  1772. WHERE u_order_wfjgMx.scid = :scid
  1773. AND u_order_wfjgMx.wfjgid = :s_mx.relid
  1774. And u_order_wfjgMx.printid = :s_mx.relprintid2 Using commit_transaction ;
  1775. IF commit_transaction.SQLCode <> 0 THEN
  1776. arg_msg = '行:'+String(s_mx.printid)+',查询外协订单收货物料失败,'+commit_transaction.SQLErrText
  1777. rslt = 0
  1778. GOTO ext
  1779. END IF
  1780. //得到发出物料
  1781. SELECT top 1 qty
  1782. INTO :lde_rqqty_out_pf
  1783. FROM u_order_wfjgmx_out_mx
  1784. WHERE (u_order_wfjgmx_out_mx.wfjgID = :s_mx.relid)
  1785. AND (u_order_wfjgmx_out_mx.relprintid = :s_mx.relprintid2)
  1786. Using commit_transaction ;
  1787. IF commit_transaction.SQLCode <> 0 THEN
  1788. arg_msg = '行:'+String(s_mx.printid)+',查询外协订单收货明细ID失败,'+commit_transaction.SQLErrText
  1789. rslt = 0
  1790. GOTO ext
  1791. END IF
  1792. //计算收货终止数量 s_mx.relqty2
  1793. s_mx.relqty2 = (lde_truerqqty_in_pf / lde_rqqty_out_pf ) * s_mx.qty
  1794. lde_sonscale = lde_rqqty_out_pf / lde_truerqqty_in_pf
  1795. ELSE
  1796. s_mx.relprintid2 = 0
  1797. s_mx.relmtrlid2 = 0
  1798. s_mx.relqty2 = 0
  1799. END IF
  1800. ELSE
  1801. s_mx.relid = 0
  1802. s_mx.relprintid = 0
  1803. s_mx.thtype = 0
  1804. s_mx.relprintid2 = 0
  1805. s_mx.relmtrlid2 = 0
  1806. s_mx.relqty2 = 0
  1807. END IF
  1808. //*****检查大于未开数不可以开单
  1809. IF flag = 0 THEN
  1810. Decimal ol_mtrl_qty = 0
  1811. Int ls_noallocflag
  1812. SELECT noallocflag INTO :ls_noallocflag
  1813. FROM u_storage
  1814. Where storageid = :i_storageid Using commit_transaction;
  1815. IF commit_transaction.SQLCode <> 0 THEN
  1816. rslt = 0
  1817. arg_msg = '行:'+String(s_mx.printid)+ ',查询仓库允许使用未开单库存属性失败'+sqlca.SQLErrText
  1818. GOTO ext
  1819. END IF
  1820. IF ls_noallocflag = 1 THEN
  1821. IF it_updatebegin THEN
  1822. SELECT sum(ow_wfjgmx_out.qty)
  1823. INTO :ol_mtrl_qty
  1824. FROM ow_wfjgmx_out
  1825. WHERE ow_wfjgmx_out.outwareid = :outwareid
  1826. AND ow_wfjgmx_out.mtrlwareid = :s_mx.mtrlwareid
  1827. And scid = :scid Using commit_transaction;
  1828. IF commit_transaction.SQLCode = -1 THEN
  1829. rslt = 0
  1830. arg_msg = '行:'+String(s_mx.printid)+ ',查询原开单数量失败'
  1831. GOTO ext
  1832. END IF
  1833. END IF
  1834. IF s_mx.qty > ( i_allouseqty - i_notauditqty + ol_mtrl_qty ) THEN
  1835. rslt = 0
  1836. arg_msg = String(i_mtrlcode)+"库存未开单数不够,不能开单.未开单数{"+String(i_allouseqty - i_notauditqty + ol_mtrl_qty,'#####,0.00##')+"}"
  1837. GOTO ext
  1838. END IF
  1839. END IF
  1840. END IF
  1841. //***********************************************
  1842. IF i_cost < 0 THEN //检查进仓价
  1843. rslt = 0
  1844. arg_msg = '行:'+String(s_mx.printid)+ ",物料:" + String(i_mtrlcode)+" 单价错误"
  1845. GOTO ext
  1846. END IF
  1847. //写入内容
  1848. it_mxbt++
  1849. outwaremx[it_mxbt].mtrlwareid = s_mx.mtrlwareid
  1850. outwaremx[it_mxbt].mtrlid = i_mtrlid
  1851. outwaremx[it_mxbt].status = i_status
  1852. outwaremx[it_mxbt].qty = s_mx.qty
  1853. outwaremx[it_mxbt].storageid = i_storageid
  1854. outwaremx[it_mxbt].cost = i_cost
  1855. outwaremx[it_mxbt].costamt = Round(i_cost * s_mx.qty,2)
  1856. outwaremx[it_mxbt].newpriceamt = 0
  1857. outwaremx[it_mxbt].plancode = i_plancode
  1858. outwaremx[it_mxbt].planprice = i_planprice
  1859. outwaremx[it_mxbt].mtrlcode = i_mtrlcode
  1860. outwaremx[it_mxbt].mxdscrp = s_mx.mxdscrp
  1861. outwaremx[it_mxbt].printid = s_mx.printid
  1862. outwaremx[it_mxbt].olmtrlid = s_mx.olmtrlid
  1863. outwaremx[it_mxbt].rebate = s_mx.rebate
  1864. IF billtype = 7 THEN
  1865. outwaremx[it_mxbt].fprice = s_mx.fprice
  1866. outwaremx[it_mxbt].price = s_mx.fprice * s_mx.rebate
  1867. outwaremx[it_mxbt].uprice = s_mx.fprice
  1868. ELSE
  1869. outwaremx[it_mxbt].fprice = i_cost
  1870. outwaremx[it_mxbt].price = i_cost
  1871. IF uo_option_2unit = 0 THEN
  1872. outwaremx[it_mxbt].uprice = i_cost
  1873. outwaremx[it_mxbt].uqty = s_mx.qty
  1874. ELSE
  1875. outwaremx[it_mxbt].uprice = Round(s_mx.qty * i_cost/s_mx.uqty,5)
  1876. outwaremx[it_mxbt].uqty = s_mx.uqty
  1877. END IF
  1878. END IF
  1879. IF s_mx.uqty <> 0 THEN
  1880. outwaremx[it_mxbt].rate = s_mx.qty / s_mx.uqty
  1881. ELSE
  1882. outwaremx[it_mxbt].rate = 0
  1883. END IF
  1884. outwaremx[it_mxbt].uunit = s_mx.uunit
  1885. outwaremx[it_mxbt].sptid = i_sptid
  1886. outwaremx[it_mxbt].dxflag = i_dxflag
  1887. outwaremx[it_mxbt].ifrel = s_mx.ifrel
  1888. outwaremx[it_mxbt].relid = s_mx.relid
  1889. outwaremx[it_mxbt].relprintid = s_mx.relprintid
  1890. outwaremx[it_mxbt].woodcode = i_woodcode
  1891. outwaremx[it_mxbt].pcode = i_pcode
  1892. outwaremx[it_mxbt].relcode = ls_relcode
  1893. outwaremx[it_mxbt].mtrlcuscode = ls_mtrlcuscode
  1894. outwaremx[it_mxbt].Location = ls_location
  1895. outwaremx[it_mxbt].thtype = s_mx.thtype
  1896. outwaremx[it_mxbt].relprintid2 = s_mx.relprintid2
  1897. outwaremx[it_mxbt].relmtrlid2 = s_mx.relmtrlid2
  1898. outwaremx[it_mxbt].relqty2 = s_mx.relqty2
  1899. ext:
  1900. IF rslt = 0 THEN p_clearmx()
  1901. RETURN rslt
  1902. end function
  1903. on uo_outware_wfjg.create
  1904. call super::create
  1905. TriggerEvent( this, "constructor" )
  1906. end on
  1907. on uo_outware_wfjg.destroy
  1908. TriggerEvent( this, "destructor" )
  1909. call super::destroy
  1910. end on
  1911. event constructor;String str_optionvalue,arg_msg
  1912. f_get_sys_option_value('087',str_optionvalue,arg_msg)
  1913. uo_option_autocreate_outware = Long(str_optionvalue)
  1914. f_get_sys_option_value('067',str_optionvalue,arg_msg)
  1915. uo_option_2unit = Long(str_optionvalue)
  1916. f_get_sys_option_value('390',str_optionvalue,arg_msg)
  1917. uo_option_noauditingqty_mode = Long(str_optionvalue)
  1918. end event