uo_outware_scll.sru 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782
  1. $PBExportHeader$uo_outware_scll.sru
  2. forward
  3. global type uo_outware_scll from uo_outware
  4. end type
  5. end forward
  6. global type uo_outware_scll from uo_outware
  7. end type
  8. global uo_outware_scll uo_outware_scll
  9. type variables
  10. Int uo_option_wkpmtrlware
  11. Int uo_option_inware_sc_location
  12. int uo_option_outware_scll_new_cj_mtrlware
  13. int uo_option_scll_plan_wsaudit
  14. s_aps_orderrqmtrl ins_s_rqmtrl,ins_s_empty
  15. long ins_itmx_aps
  16. end variables
  17. forward prototypes
  18. public function integer auditing (boolean arg_ifcommit, ref string arg_msg)
  19. public function integer c_auditing (boolean arg_ifcommit, ref string arg_msg)
  20. public function integer secauditing (boolean arg_ifcommit, ref string arg_msg)
  21. public function integer c_secauditing (boolean arg_ifcommit, ref string arg_msg)
  22. public function integer priceaudit (boolean arg_ifcommit, ref string arg_msg)
  23. public function integer c_priceaudit (boolean arg_ifcommit, ref string arg_msg)
  24. public function integer uof_auto_secaudit (ref string arg_msg)
  25. public function integer wsauditing (long arg_scid, long arg_outwareid, long arg_printid, ref string arg_msg, boolean arg_ifcommit)
  26. public function integer wscauditing (long arg_scid, long arg_outwareid, long arg_printid, ref string arg_msg, boolean arg_ifcommit)
  27. public function integer cauditing_cw (long arg_scid, long arg_outwareid, long arg_printid, ref string arg_msg, boolean arg_ifcommit)
  28. public function integer auditing_cw (long arg_scid, long arg_outwareid, long arg_printid, ref string arg_msg, boolean arg_ifcommit)
  29. end prototypes
  30. public function integer auditing (boolean arg_ifcommit, ref string arg_msg);Int rslt = 1
  31. Long cnt = 0,i,li_type,ll_i,j
  32. Decimal ld_overqty,lde_addqty,lde_adduqty
  33. s_cmplpackpro_ref_mtrlwareid_array s_mtrlwareid_array_rst
  34. ins_ref_outwaremx = ins_empty_outwaremx
  35. ins_ref_mxbt = 0
  36. uo_mtrlware_assign uo_ma
  37. uo_ma = Create uo_mtrlware_assign
  38. uo_ma.commit_transaction = commit_transaction
  39. uo_cmpl_packpro uo_cmpl_p
  40. uo_cmpl_p = Create uo_cmpl_packpro
  41. uo_cmpl_p.commit_transaction = commit_transaction
  42. //库存分配ds
  43. datastore ds_out_assign
  44. ds_out_assign = Create datastore
  45. ds_out_assign.DataObject = 'ds_outwaremx_assign_scll'
  46. ds_out_assign.SetTransObject(commit_transaction)
  47. ins_itmx_aps = 0
  48. ins_s_rqmtrl = ins_s_empty
  49. If f_aps_mrp_cklock(scid,arg_msg) = 0 Then
  50. rslt = 0
  51. Goto ext
  52. End If
  53. If uo_option_confirmaudit_scll = -1000 Then
  54. arg_msg = '选项:[006]生产领料单先确认再审核,读取初始默认值失败,操作取消!'
  55. rslt = 0
  56. Goto ext
  57. End If
  58. If uo_option_wkpmtrlware = -1000 Then
  59. arg_msg = '选项:[057]生产使用车间核算,读取初始默认值失败,操作取消!'
  60. rslt = 0
  61. Goto ext
  62. End If
  63. If uo_option_inware_sc_location = -1000 Then
  64. arg_msg = '选项:[151]车间仓仓位按工组名称,读取初始默认值失败,操作取消!'
  65. rslt = 0
  66. Goto ext
  67. End If
  68. If uo_option_scll_plan_wsaudit = -1000 Then
  69. arg_msg = '选项:[377]发料单使用明细车间审核流程,读取初始默认值失败,操作取消!'
  70. rslt = 0
  71. Goto ext
  72. End If
  73. uo_order_ml uo_order
  74. uo_order = Create uo_order_ml
  75. //更新备料领料单实领数
  76. uo_outware_scllplan uo_scllplan
  77. uo_scllplan = Create uo_outware_scllplan
  78. If storageid = 0 Then
  79. rslt = 0
  80. arg_msg = '没有正确的仓库'
  81. Goto ext
  82. End If
  83. //yyx20120808加盘点表生成的领料单不检查
  84. If billtype <> 9 And Not (billtype = 3 And Pos(dscrp,'的领料单') > 0) Then
  85. If uof_check_warepdb_audit(storageid,arg_msg) = 0 Then
  86. rslt = 0
  87. Goto ext
  88. End If
  89. End If
  90. String ls_storagename
  91. Int li_storagetype
  92. Select storagename,storagetype
  93. Into :ls_storagename,:li_storagetype
  94. From u_storage
  95. Where storageid = :storageid Using commit_transaction ;
  96. If commit_transaction.SQLCode <> 0 Then
  97. rslt = 0
  98. arg_msg = "查询操作失败,仓库"
  99. Goto ext
  100. End If
  101. //检查是否有该仓库的建立权限
  102. If sys_user_storagestr_audit <> '0' Then
  103. If Pos(sys_user_storagestr_audit,','+String(storageid)+',') <= 0 Then
  104. rslt = 0
  105. arg_msg = '没有仓库: '+ls_storagename+' 的审核权限,不允许审核该仓库的单据'
  106. Goto ext
  107. End If
  108. End If
  109. //
  110. If outwareid = 0 Then
  111. rslt = 0
  112. arg_msg = "没有审核对象"
  113. Goto ext
  114. End If
  115. If uo_option_confirmaudit_scll = 1 And relint_1 = 0 Then
  116. If priceflag = 0 Then
  117. arg_msg = '单据未确认,请核对'
  118. rslt = 0
  119. Goto ext
  120. End If
  121. End If
  122. If flag = 1 Then
  123. rslt = 0
  124. arg_msg = "单据已经审核"
  125. Goto ext
  126. End If
  127. //IF relint_1 = 0 THEN
  128. If uo_option_confirmaudit_scll = 1 Then
  129. Update u_outware
  130. Set Auditingrep = :publ_operator,
  131. Auditingdate = getdate(),
  132. flag = 1
  133. Where u_outware.outwareid = :outwareid
  134. And flag = 0
  135. And priceflag = 1 Using commit_transaction;
  136. Else
  137. Update u_outware
  138. Set Auditingrep = :publ_operator,
  139. Auditingdate = getdate(),
  140. flag = 1,
  141. priceemp = :publ_operator,
  142. pricedate = getdate(),
  143. priceflag = 1
  144. Where u_outware.outwareid = :outwareid
  145. And flag = 0 Using commit_transaction;
  146. End If
  147. //ELSE
  148. //
  149. //END IF
  150. If commit_transaction.SQLCode <> 0 Then
  151. rslt = 0
  152. arg_msg = "因网络或其它原因导致审核单据操作失败"+"~n"+commit_transaction.SQLErrText
  153. Goto ext
  154. ElseIf commit_transaction.SQLNRows = 0 Then
  155. rslt = 0
  156. arg_msg = "单据正在审核,请稍后查询。"+"~n"+commit_transaction.SQLErrText
  157. Goto ext
  158. End If
  159. Decimal ld_assign_outqty,ld_sumnotoutqty,ld_sumnotoutqty_bill
  160. Long ll_row
  161. Long ll_porderid,ll_orderid_retrieve
  162. Int li_ordertype_zl
  163. For i = 1 To it_mxbt
  164. Decimal ld_ref_costamt
  165. If p_update_cost(outwaremx[i].mtrlwareid,outwaremx[i].mtrlcode,&
  166. outwaremx[i].qty,outwaremx[i].printid,ld_ref_costamt,arg_msg,False) = 0 Then
  167. rslt = 0
  168. Goto ext
  169. End If
  170. If outwaremx[i].relid > 0 And relint_1 <> 4 Then
  171. //先扣库存分配,再扣库存
  172. If billtype = 3 And li_storagetype = 1 And outwaremx[i].relid > 0 And outwaremx[i].iffp = 1 Then
  173. Select ordertype,porderid
  174. Into :li_ordertype_zl,:ll_porderid
  175. From u_order_ml
  176. Where u_order_ml.scid = :scid
  177. And u_order_ml.orderid = :outwaremx[i].relid
  178. Using commit_transaction ;
  179. If commit_transaction.SQLCode <> 0 Then
  180. rslt = 0
  181. arg_msg = '行:'+String(i)+',查询指令单属性失败,'+commit_transaction.SQLErrText
  182. Goto ext
  183. End If
  184. If li_ordertype_zl = 4 Then
  185. ll_orderid_retrieve = ll_porderid
  186. Else
  187. ll_orderid_retrieve = outwaremx[i].relid
  188. End If
  189. ll_row = ds_out_assign.Retrieve(scid,outwaremx[i].mtrlwareid,ll_orderid_retrieve)
  190. ds_out_assign.AcceptText()
  191. If ll_row <= 0 Then
  192. ld_sumnotoutqty = 0
  193. Else
  194. ld_sumnotoutqty = ds_out_assign.Object.sumnotoutqty[1]
  195. End If
  196. ld_sumnotoutqty_bill = 0
  197. ld_sumnotoutqty_bill = outwaremx[i].qty
  198. If ld_sumnotoutqty_bill > ld_sumnotoutqty Then
  199. arg_msg = '行:'+String(i)+'计划库存分配数不足,请检查库存分配明细'
  200. rslt = 0
  201. Goto ext
  202. Else
  203. ld_assign_outqty = 0
  204. For j = 1 To ds_out_assign.RowCount()
  205. If ds_out_assign.Object.notoutqty[j] >= ld_sumnotoutqty_bill Then
  206. ld_assign_outqty = ld_sumnotoutqty_bill
  207. If uo_ma.uof_assign_addoutqty(ds_out_assign.Object.assignid[j],ld_assign_outqty,arg_msg,False) = 0 Then
  208. arg_msg = '行:'+String(i)+','+arg_msg
  209. rslt = 0
  210. Goto ext
  211. End If
  212. Exit
  213. Else
  214. ld_assign_outqty = ds_out_assign.Object.notoutqty[j]
  215. If uo_ma.uof_assign_addoutqty(ds_out_assign.Object.assignid[j],ld_assign_outqty,arg_msg,False) = 0 Then
  216. arg_msg = '行:'+String(i)+','+arg_msg
  217. rslt = 0
  218. Goto ext
  219. End If
  220. ld_sumnotoutqty_bill = ld_sumnotoutqty_bill - ds_out_assign.Object.notoutqty[j]
  221. End If
  222. Next
  223. End If
  224. End If
  225. ////////////////////////////////////////////////////////////////////////// //
  226. If uo_order.f_add_dstrqty(scid,outwaremx[i].relid,relid,&
  227. outwaremx[i].mtrlid,outwaremx[i].mtrlcode,&
  228. outwaremx[i].status,outwaremx[i].woodcode,outwaremx[i].pcode,&
  229. outwaremx[i].qty,ld_ref_costamt,arg_msg,False,relint_1,ld_overqty) = 0 Then
  230. rslt = 0
  231. arg_msg = '行:'+String(i)+','+arg_msg
  232. Goto ext
  233. End If
  234. For ll_i = 1 To uo_order.it_mx_rq
  235. ins_itmx_aps++
  236. ins_s_rqmtrl.mtrlid[ins_itmx_aps] = uo_order.ins_s_rqmtrl.mtrlid[ll_i]
  237. ins_s_rqmtrl.status[ins_itmx_aps] = uo_order.ins_s_rqmtrl.status[ll_i]
  238. ins_s_rqmtrl.woodcode[ins_itmx_aps] = uo_order.ins_s_rqmtrl.woodcode[ll_i]
  239. ins_s_rqmtrl.pcode[ins_itmx_aps] = uo_order.ins_s_rqmtrl.pcode[ll_i]
  240. ins_s_rqmtrl.wrkgrpid[ins_itmx_aps] = uo_order.ins_s_rqmtrl.wrkgrpid[ll_i]
  241. ins_s_rqmtrl.orderid[ins_itmx_aps] = uo_order.ins_s_rqmtrl.orderid[ll_i]
  242. ins_s_rqmtrl.qty[ins_itmx_aps] = uo_order.ins_s_rqmtrl.qty[ll_i]
  243. ins_s_rqmtrl.scid[ins_itmx_aps] = uo_order.ins_s_rqmtrl.scid[ll_i]
  244. Next
  245. If ld_overqty > 0 Then
  246. Update u_outwaremx
  247. Set overqty = overqty + :ld_overqty
  248. Where outwareid = :outwareid
  249. And scid = :scid
  250. And printid = :outwaremx[i].printid;
  251. If commit_transaction.SQLCode <> 0 Then
  252. rslt = 0
  253. arg_msg = '行:'+String(i)+','+'更新超计划领料数量失败'+"~n"+commit_transaction.SQLErrText
  254. Goto ext
  255. End If
  256. End If
  257. End If
  258. //发料单
  259. If billtype = 3 And relint_1 = 4 Then
  260. lde_addqty = outwaremx[i].qty
  261. lde_adduqty = outwaremx[i].uqty
  262. // If lde_addqty <> 0 And outwaremx[i].relid > 0 Then
  263. If outwaremx[i].relid > 0 Then
  264. //先扣库存分配,再扣库存(在p_addfactscllqty处理)
  265. If uo_scllplan.p_addfactscllqty(outwaremx[i].relid,outwaremx[i].mtrlwareid,storageid,outwaremx[i].mtrlid, outwaremx[i].status, outwaremx[i].woodcode, outwaremx[i].pcode, lde_addqty, lde_adduqty,ld_overqty,ld_ref_costamt,outwaremx[i].planqty - outwaremx[i].qty,1,False, arg_msg ) = 0 Then
  266. arg_msg = '行:'+String(i)+','+arg_msg
  267. rslt = 0
  268. Goto ext
  269. End If
  270. For ll_i = 1 To uo_order.it_mx_rq
  271. ins_itmx_aps++
  272. ins_s_rqmtrl.mtrlid[ins_itmx_aps] = uo_scllplan.ins_s_rqmtrl.mtrlid[ll_i]
  273. ins_s_rqmtrl.status[ins_itmx_aps] = uo_scllplan.ins_s_rqmtrl.status[ll_i]
  274. ins_s_rqmtrl.woodcode[ins_itmx_aps] = uo_scllplan.ins_s_rqmtrl.woodcode[ll_i]
  275. ins_s_rqmtrl.pcode[ins_itmx_aps] = uo_scllplan.ins_s_rqmtrl.pcode[ll_i]
  276. ins_s_rqmtrl.wrkgrpid[ins_itmx_aps] = uo_scllplan.ins_s_rqmtrl.wrkgrpid[ll_i]
  277. ins_s_rqmtrl.orderid[ins_itmx_aps] = uo_scllplan.ins_s_rqmtrl.orderid[ll_i]
  278. ins_s_rqmtrl.qty[ins_itmx_aps] = uo_scllplan.ins_s_rqmtrl.qty[ll_i]
  279. ins_s_rqmtrl.scid[ins_itmx_aps] = uo_scllplan.ins_s_rqmtrl.scid[ll_i]
  280. Next
  281. If ld_overqty > 0 Then
  282. Update u_outwaremx
  283. Set overqty = overqty + :ld_overqty
  284. Where outwareid = :outwareid
  285. And scid = :scid
  286. And printid = :outwaremx[i].printid;
  287. If commit_transaction.SQLCode <> 0 Then
  288. rslt = 0
  289. arg_msg = '行:'+String(i)+','+'更新超计划领料数量失败'+"~n"+commit_transaction.SQLErrText
  290. Goto ext
  291. End If
  292. End If
  293. End If
  294. End If
  295. If p_update_mtrlware ( outwaremx[i].mtrlwareid, outwaremx[i].mtrlid, &
  296. outwaremx[i].mtrlcode, storageid, outwaremx[i].plancode,&
  297. outwaremx[i].status, outwaremx[i].qty, outwaremx[i].uqty,ld_ref_costamt,&
  298. outwaremx[i].planprice, outwaremx[i].sptid,outwaremx[i].dxflag,&
  299. outwaremx[i].woodcode,outwaremx[i].pcode,&
  300. outwaremx[i].mtrlcuscode,outwaremx[i].Location,outwaremx[i].ifvqty,arg_msg) = 0 Then
  301. rslt = 0
  302. arg_msg = '行:'+String(i)+','+arg_msg
  303. Goto ext
  304. End If
  305. //yyx2012-9-29返回计算可装数库存id数组
  306. If ( outwaremx[i].ifpack = 1 Or outwaremx[i].ifpack = 2 Or outwaremx[i].ifpackpro = 3 Or outwaremx[i].ifpackpro = 4 ) And uo_option_mtrlware_autocmp = 1 Then
  307. If uo_option_noauditingqty_mode = 0 Then
  308. If uo_cmpl_p.uof_ref_mtrlwarid_array(outwaremx[i].mtrlid,outwaremx[i].plancode,outwaremx[i].mtrlcuscode,storageid,s_mtrlwareid_array_rst,arg_msg) = 0 Then
  309. rslt = 0
  310. Goto ext
  311. End If
  312. Else
  313. ins_ref_mxbt++
  314. ins_ref_outwaremx[ins_ref_mxbt].mtrlid = outwaremx[i].mtrlid
  315. ins_ref_outwaremx[ins_ref_mxbt].plancode = outwaremx[i].plancode
  316. ins_ref_outwaremx[ins_ref_mxbt].mtrlcuscode = outwaremx[i].mtrlcuscode
  317. ins_ref_outwaremx[ins_ref_mxbt].storageid = storageid
  318. End If
  319. End If
  320. //
  321. Next
  322. //更新库存已开单数(减)
  323. If uof_noauditingqty_del(scid,outwareid,arG_MSG) = 0 Then
  324. rslt = 0
  325. Goto ext
  326. End If
  327. //yyx2012-9-29返回计算可装数库存id数组计算可装数
  328. If UpperBound(s_mtrlwareid_array_rst.mtrlwareid) > 0 And uo_option_mtrlware_autocmp = 1 Then
  329. If uo_option_noauditingqty_mode = 0 Then
  330. If uo_cmpl_p.uof_cmpl_diqty(s_mtrlwareid_array_rst,arg_msg) = 0 Then
  331. rslt = 0
  332. Goto ext
  333. End If
  334. End If
  335. End If
  336. //
  337. //领料单审核自动生成车间进仓单
  338. If uo_option_wkpmtrlware = 0 And uo_option_scll_plan_wsaudit = 0 And billtype = 3 And relint_1 = 4 Then
  339. If getinfo(scid,outwareid,arg_msg) = 0 Then
  340. rslt = 0
  341. Goto ext
  342. End If
  343. Long ll_wrkGrpid
  344. Long ll_storageid,ll_storageid_scid
  345. Long ll_inwareid,ll_inwareid_ws
  346. Long ll_pid
  347. Int li_ifwkpmtrlware
  348. Int li_iforder,li_ifover
  349. Decimal ld_qty_tmp,ld_uqty_tmp
  350. String ls_wrkgrpname,ls_location
  351. Select wrkGrpid Into :ll_wrkGrpid
  352. From u_workgroup
  353. Where workgroupid = :relid Using commit_transaction;
  354. If commit_transaction.SQLCode <> 0 Then
  355. rslt = 0
  356. arg_msg = '查询工作组所属工组失败'+"~n"+commit_transaction.SQLErrText
  357. Goto ext
  358. End If
  359. If ll_wrkGrpid = 0 Then
  360. arg_msg = '领料组未设定所属工组'
  361. rslt = 0
  362. Goto ext
  363. End If
  364. Select u_sc_wkp.storageid,
  365. isnull(u_storage.scid,0),
  366. u_sc_wkp.ifwkpmtrlware,
  367. u_sc_workgroup.wrkgrpname
  368. Into :ll_storageid,
  369. :ll_storageid_scid,
  370. :li_ifwkpmtrlware,
  371. :ls_wrkgrpname
  372. From u_sc_workgroup,u_storage,u_sc_wkp
  373. Where u_sc_workgroup.wrkGrpid = :ll_wrkGrpid
  374. And u_sc_wkp.storageid = u_storage.storageid
  375. And u_sc_wkp.wrkGrpid = u_sc_workgroup.storageid
  376. Using commit_transaction;
  377. If commit_transaction.SQLCode <> 0 Then
  378. rslt = 0
  379. arg_msg = '查询工组所属车间所属仓库失败'+"~n"+commit_transaction.SQLErrText
  380. Goto ext
  381. End If
  382. If uo_option_inware_sc_location = 1 Then
  383. ls_location = ls_wrkgrpname
  384. Else
  385. ls_location = ''
  386. End If
  387. If IsNull(ll_storageid) Then ll_storageid = 0
  388. If IsNull(ll_storageid_scid) Then ll_storageid_scid = 0
  389. If IsNull(li_ifwkpmtrlware) Then li_ifwkpmtrlware = 0
  390. If ll_storageid = 0 Then
  391. arg_msg = '领料组所属车间未指定仓库'
  392. rslt = 0
  393. Goto ext
  394. End If
  395. If ll_storageid_scid <> scid Then
  396. arg_msg = '领料车间对就仓库分部与单据分部不相符,请检查'
  397. rslt = 0
  398. Goto ext
  399. End If
  400. li_iforder = 0
  401. li_ifover = 0
  402. For i = 1 To it_mxbt
  403. If outwaremx[i].relid > 0 Then
  404. If outwaremx[i].overqty > 0 Then
  405. li_ifover = 1
  406. End If
  407. Else
  408. li_ifover = 1
  409. End If
  410. If li_ifover = 1 Then Exit
  411. Next
  412. If li_ifover = 1 Then
  413. uo_inware uo_in
  414. uo_in = Create uo_inware
  415. uo_in.commit_transaction = commit_transaction
  416. uo_in.if_getid_ture = False
  417. If uo_in.newbegin(scid,16,arg_msg) = 0 Then
  418. rslt = 0
  419. Goto ext
  420. End If
  421. uo_in.indate = outdate
  422. uo_in.inrep = outrep
  423. uo_in.part = outwarecode
  424. uo_in.dscrp = ''
  425. uo_in.storageid = ll_storageid
  426. uo_in.sptname = '车间领料自动进仓(不按计划/超数量)'
  427. uo_in.relint_3 = outwareid
  428. ll_pid = 0
  429. For i = 1 To it_mxbt
  430. ld_qty_tmp = 0
  431. ld_uqty_tmp = 0
  432. If outwaremx[i].relid = 0 Or &
  433. ( outwaremx[i].relid > 0 And outwaremx[i].overqty > 0 ) Then
  434. If outwaremx[i].relid = 0 Then
  435. ld_qty_tmp = outwaremx[i].qty
  436. ld_uqty_tmp = outwaremx[i].uqty
  437. Else
  438. ld_qty_tmp = outwaremx[i].overqty
  439. ld_uqty_tmp = outwaremx[i].overqty / outwaremx[i].rate
  440. End If
  441. Else
  442. Continue
  443. End If
  444. ll_pid++
  445. If uo_in.acceptmx(ll_pid,&
  446. outwaremx[i].mtrlid,&
  447. outwaremx[i].mtrlcode,&
  448. outwaremx[i].plancode,&
  449. outwaremx[i].status,&
  450. ld_uqty_tmp,&
  451. outwaremx[i].cost,&
  452. outwaremx[i].rebate,&
  453. outwaremx[i].mxdscrp,&
  454. arg_msg,&
  455. 0,0,0,&
  456. outwaremx[i].woodcode,&
  457. outwaremx[i].pcode,0,&
  458. outwaremx[i].unit,&
  459. outwaremx[i].rate,&
  460. ld_qty_tmp,&
  461. 0,0,'','',0,0,'',ls_location,&
  462. ld_uqty_tmp,&
  463. 0) = 0 Then
  464. arg_msg = '建立相关自动车间进仓单失败,' + arg_msg
  465. rslt = 0
  466. Goto ext
  467. End If
  468. Next
  469. If uo_in.Save(False,arg_msg) = 0 Then
  470. arg_msg = '建立相关自动车间进仓单失败,' + arg_msg
  471. rslt = 0
  472. Goto ext
  473. End If
  474. ll_inwareid = uo_in.inwareid
  475. If uo_in.getinfo(scid,ll_inwareid,arg_msg) = 0 Then
  476. arg_msg = '审核相关自动车间进仓单失败,' + arg_msg
  477. rslt = 0
  478. Goto ext
  479. End If
  480. If uo_in.auditing(False,arg_msg) = 0 Then
  481. arg_msg = '审核相关自动车间进仓单失败,' + arg_msg
  482. rslt = 0
  483. Goto ext
  484. End If
  485. //
  486. // Update u_outware
  487. // Set relint_2 = :ll_inwareid
  488. // Where outwareid = :outwareid
  489. // And scid = :scid
  490. // Using commit_transaction;
  491. // If commit_transaction.SQLCode <> 0 Then
  492. // rslt = 0
  493. // arg_msg = '更新出仓单失败'+'~n'+commit_transaction.SQLErrText
  494. // Goto ext
  495. // End If
  496. Destroy uo_in
  497. End If
  498. End If
  499. //如果是退料单,按明细类型执行相关处理
  500. datastore ds_mtrlware
  501. ds_mtrlware = Create datastore
  502. ds_mtrlware.DataObject = 'ds_mtrl_storage_mtrlware'
  503. ds_mtrlware.SetTransObject(commit_transaction)
  504. Long ll_row_ds,ll_j,ll_k
  505. Long ll_mtrlwareid_arr[],ll_scid_arr[],ll_storageid_arr[],ll_storageid_bu_arr[],ll_scid_bu_arr[]
  506. Int li_ifrel_arr[]
  507. Long ll_relid_arr[],ll_olmtrlid_arr[]
  508. Decimal ld_cost_arr[],ld_qty_arr[]
  509. String ls_unit_arr[]
  510. Decimal ld_qty_temp,ld_qty_bu
  511. Long ll_cnt_bu = 0,ll_cnt_storageid = 0
  512. Boolean lb_find_storage = False
  513. DateTime server_dt
  514. Long ll_printid_bu
  515. Long ll_wrkgrpid_back
  516. Decimal ld_truerqqty,ld_sqty,ld_dqty
  517. Boolean lb_backtype = False
  518. s_order_ml_mtrl_change_mx arg_s_mx[],arg_s_empty_mx[]
  519. Select Top 1 getdate() Into :server_dt From u_user Using commit_transaction ;
  520. //取得系统时间,借用操作员表
  521. If commit_transaction.SQLCode <> 0 Then
  522. rslt = 0
  523. arg_msg = "查询操作失败,日期 "
  524. Goto ext
  525. End If
  526. uo_outware uo_out_bu
  527. uo_out_bu = Create uo_outware
  528. uo_out_bu.commit_transaction = commit_transaction
  529. uo_out_bu.if_getid_ture = False
  530. If billtype = 3 And relint_1 = 2 Then
  531. Select wrkGrpid
  532. Into :ll_wrkgrpid_back
  533. From u_workgroup
  534. Where workgroupid = :relid Using commit_transaction;
  535. If commit_transaction.SQLCode <> 0 Then
  536. arg_msg = '查询工作中心所属工组失败 ' +commit_transaction.SQLErrText
  537. rslt = 0
  538. Goto ext
  539. End If
  540. For ll_i = 1 To it_mxbt
  541. If outwaremx[ll_i].backtype = 1 Then
  542. ld_qty_temp = 0 - outwaremx[ll_i].qty
  543. ll_row_ds = ds_mtrlware.Retrieve(outwaremx[ll_i].mtrlid,outwaremx[ll_i].status,outwaremx[ll_i].woodcode,outwaremx[ll_i].pcode)
  544. lb_backtype = False
  545. For ll_j = 1 To ll_row_ds
  546. If ds_mtrlware.Object.qty[ll_j] <= 0 Then Continue
  547. If ld_qty_temp > ds_mtrlware.Object.qty[ll_j] Then
  548. ld_qty_bu = ds_mtrlware.Object.qty[ll_j]
  549. ld_qty_temp = ld_qty_temp - ds_mtrlware.Object.qty[ll_j]
  550. Else
  551. ld_qty_bu = ld_qty_temp
  552. ld_qty_temp = 0
  553. End If
  554. ll_cnt_bu++
  555. ll_scid_arr[ll_cnt_bu] = ds_mtrlware.Object.u_mtrlware_scid[ll_j]
  556. ll_mtrlwareid_arr[ll_cnt_bu] = ds_mtrlware.Object.u_mtrlware_mtrlwareid[ll_j]
  557. ll_storageid_arr[ll_cnt_bu] = ds_mtrlware.Object.u_mtrlware_storageid[ll_j]
  558. ld_cost_arr[ll_cnt_bu] = ds_mtrlware.Object.u_mtrlware_cost[ll_j]
  559. ld_qty_arr[ll_cnt_bu] = ld_qty_bu
  560. ls_unit_arr[ll_cnt_bu] = ds_mtrlware.Object.u_mtrldef_unit[ll_j]
  561. li_ifrel_arr[ll_cnt_bu] = outwaremx[ll_i].ifrel
  562. ll_relid_arr[ll_cnt_bu] = outwaremx[ll_i].relid
  563. ll_olmtrlid_arr[ll_cnt_bu] = outwaremx[ll_i].olmtrlid
  564. lb_backtype = True
  565. lb_find_storage = False
  566. For ll_k = 1 To ll_cnt_storageid
  567. If ll_storageid_bu_arr[ll_k] = ll_storageid_arr[ll_cnt_bu] Then
  568. lb_find_storage = True
  569. Exit
  570. End If
  571. Next
  572. If lb_find_storage = False Then
  573. ll_cnt_storageid++
  574. ll_storageid_bu_arr[ll_cnt_storageid] = ll_storageid_arr[ll_cnt_bu]
  575. ll_scid_bu_arr[ll_cnt_storageid] = ll_scid_arr[ll_cnt_bu]
  576. End If
  577. If ld_qty_temp <= 0 Then Goto _next_bu
  578. Next
  579. If lb_backtype = False Then
  580. Update u_outwaremx
  581. Set backtype = 0
  582. Where scid = :scid
  583. And outwareid = :outwareid
  584. And printid = :outwaremx[ll_i].printid Using commit_transaction;
  585. If commit_transaction.SQLCode <> 0 Then
  586. arg_msg = '第'+String(ll_i)+'行,更新明细退料类型为不自动建立补料单失败,'+commit_transaction.SQLErrText
  587. rslt = 0
  588. Goto ext
  589. Else
  590. arg_msg = arg_msg + '第'+String(ll_i)+'行,明细物料没有库存自动建立补料单,退料类型自动变为不自动建立补料单'+'~r~n'
  591. End If
  592. End If
  593. ElseIf outwaremx[ll_i].backtype = 2 Then
  594. If outwaremx[ll_i].relid > 0 Then
  595. Select truerqqty
  596. Into :ld_truerqqty
  597. From u_orderrqmtrl_scll
  598. Where orderid = :outwaremx[ll_i].relid
  599. And mtrlid = :outwaremx[ll_i].mtrlid
  600. And wrkGrpid = :ll_wrkgrpid_back
  601. And scid = :scid
  602. And status = :outwaremx[ll_i].status
  603. And woodcode = :outwaremx[ll_i].woodcode
  604. And pcode = :outwaremx[ll_i].pcode Using commit_transaction;
  605. If commit_transaction.SQLCode <> 0 Then
  606. arg_msg = '第'+String(ll_i)+'行,查询指令单领料明细信息失败,'+commit_transaction.SQLErrText
  607. rslt = 0
  608. Goto ext
  609. End If
  610. ld_sqty = ld_truerqqty
  611. ld_dqty = ld_truerqqty + outwaremx[ll_i].qty
  612. uo_order_ml_mtrl_change uo_mtrl_ch
  613. uo_mtrl_ch = Create uo_order_ml_mtrl_change
  614. s_order_ml_mtrl_change arg_s_mtrl_ch
  615. arg_s_mtrl_ch.scid = scid
  616. arg_s_mtrl_ch.billid = 0
  617. arg_s_mtrl_ch.billdate = server_dt
  618. arg_s_mtrl_ch.billemp = publ_operator
  619. arg_s_mtrl_ch.relcode = ''
  620. arg_s_mtrl_ch.dscrp = '退料单终止用料自动生成' //注意修改时这里时要修改uo_order_ml_mtrl_change.audit
  621. arg_s_mtrl_ch.orderid = outwaremx[ll_i].relid
  622. arg_s_mtrl_ch.smtrlid = outwaremx[ll_i].mtrlid
  623. arg_s_mtrl_ch.wrkgrpid = ll_wrkgrpid_back
  624. arg_s_mtrl_ch.status = outwaremx[ll_i].status
  625. arg_s_mtrl_ch.woodcode = outwaremx[ll_i].woodcode
  626. arg_s_mtrl_ch.pcode = outwaremx[ll_i].pcode
  627. arg_s_mtrl_ch.dmtrlid = outwaremx[ll_i].mtrlid
  628. arg_s_mtrl_ch.sqty = ld_sqty
  629. arg_s_mtrl_ch.dqty = ld_dqty
  630. arg_s_mtrl_ch.billtype = 1
  631. arg_s_mtrl_ch.ifchange = 1
  632. //加明细
  633. arg_s_mx = arg_s_empty_mx
  634. If f_addmx_mtrl_change(scid,outwaremx[ll_i].relid,outwaremx[ll_i].mtrlid,ll_wrkgrpid_back,outwaremx[ll_i].status, outwaremx[ll_i].woodcode,outwaremx[ll_i].pcode,ld_sqty,ld_dqty,arg_s_mx,arg_msg) = 0 Then
  635. rslt = 0
  636. arg_msg = '明细第'+String(ll_i)+'行,生成生产指令单换料单失败,原因:计算单据明细失败.'+arg_msg
  637. Goto ext
  638. End If
  639. arg_s_mtrl_ch.arg_s_mx = arg_s_mx
  640. If uo_mtrl_ch.Save(arg_s_mtrl_ch,publ_operator,arg_msg,False) = 0 Then
  641. rslt = 0
  642. arg_msg = '明细第'+String(ll_i)+'行,生成生产指令单换料单失败,'+arg_msg
  643. Goto ext
  644. End If
  645. If uo_mtrl_ch.audit(uo_mtrl_ch.uo_billid,publ_operator,arg_msg,False) = 0 Then
  646. rslt = 0
  647. arg_msg = '明细第'+String(ll_i)+'行,审核相关生产指令单换料单失败,'+arg_msg
  648. Goto ext
  649. End If
  650. Destroy uo_mtrl_ch
  651. End If
  652. End If
  653. _next_bu:
  654. Next
  655. For ll_i = 1 To ll_cnt_storageid
  656. If uo_out_bu.newbegin(ll_scid_bu_arr[ll_i],3,arg_msg) = 0 Then
  657. rslt = 0
  658. Goto ext
  659. End If
  660. uo_out_bu.outdate = server_dt
  661. uo_out_bu.outrep = publ_operator
  662. uo_out_bu.part = outwarecode
  663. uo_out_bu.dscrp = '生产退料单仓审自动生成'
  664. uo_out_bu.cusname = '补料'
  665. uo_out_bu.storageid = ll_storageid_bu_arr[ll_i]
  666. uo_out_bu.relid = relid
  667. uo_out_bu.relint_1 = 5
  668. uo_out_bu.relint_4 = outwareid
  669. ll_printid_bu = 0
  670. For ll_j = 1 To ll_cnt_bu
  671. If ll_storageid_arr[ll_j] <> ll_storageid_bu_arr[ll_i] Then Continue
  672. ll_printid_bu++
  673. If uo_out_bu.acceptmx(ll_mtrlwareid_arr[ll_j],&
  674. ld_qty_arr[ll_j],&
  675. ld_cost_arr[ll_j],&
  676. 1,&
  677. '',&
  678. ll_printid_bu,&
  679. arg_msg,&
  680. li_ifrel_arr[ll_j],&
  681. ll_relid_arr[ll_j],&
  682. ll_olmtrlid_arr[ll_j],0,'',0,0,&
  683. ls_unit_arr[ll_j],&
  684. ld_qty_arr[ll_j],&
  685. 1,'','',0,0,'',0,0,0,0,'','') = 0 Then
  686. arg_msg = '自动建立生产补料单失败,' + arg_msg
  687. rslt = 0
  688. Goto ext
  689. End If
  690. Next
  691. If ll_printid_bu > 0 Then
  692. If uo_out_bu.Save(False,arg_msg) = 0 Then
  693. arg_msg = '自动建立生产补料单失败,' + arg_msg
  694. rslt = 0
  695. Goto ext
  696. End If
  697. End If
  698. Next
  699. End If
  700. flag = 1
  701. ext:
  702. If rslt = 0 Then
  703. Rollback Using commit_transaction;
  704. ElseIf rslt = 1 And arg_ifcommit Then
  705. Commit Using commit_transaction;
  706. End If
  707. Destroy uo_order
  708. Destroy uo_scllplan
  709. Destroy uo_ma
  710. Destroy uo_cmpl_p
  711. Destroy ds_out_assign
  712. Destroy ds_mtrlware
  713. Destroy uo_out_bu
  714. Return rslt
  715. end function
  716. public function integer c_auditing (boolean arg_ifcommit, ref string arg_msg);Int rslt = 1
  717. Long cnt = 0,i,li_type,ll_i,j
  718. Decimal ld_overqty,lde_addqty,lde_adduqty
  719. s_cmplpackpro_ref_mtrlwareid_array s_mtrlwareid_array_rst
  720. ins_ref_outwaremx = ins_empty_outwaremx
  721. ins_ref_mxbt = 0
  722. uo_mtrlware_assign uo_ma
  723. uo_ma = Create uo_mtrlware_assign
  724. uo_ma.commit_transaction = commit_transaction
  725. uo_cmpl_packpro uo_cmpl_p
  726. uo_cmpl_p = Create uo_cmpl_packpro
  727. uo_cmpl_p.commit_transaction = commit_transaction
  728. //库存分配ds
  729. datastore ds_out_assign
  730. ds_out_assign = Create datastore
  731. ds_out_assign.DataObject = 'ds_outwaremx_assign_cancel_scll'
  732. ds_out_assign.SetTransObject(commit_transaction)
  733. ins_itmx_aps = 0
  734. ins_s_rqmtrl = ins_s_empty
  735. If f_aps_mrp_cklock(scid,arg_msg) = 0 Then
  736. rslt = 0
  737. Goto ext
  738. End If
  739. If uo_option_confirmaudit_scll = -1000 Then
  740. arg_msg = '选项:[006]生产领料单先确认再审核,读取初始默认值失败,操作取消!'
  741. rslt = 0
  742. Goto ext
  743. End If
  744. If uo_option_scll_plan_wsaudit = -1000 Then
  745. arg_msg = '选项:[377]发料单使用明细车间审核流程,读取初始默认值失败,操作取消!'
  746. rslt = 0
  747. Goto ext
  748. End If
  749. DateTime null_dt
  750. SetNull(null_dt)
  751. uo_order_ml uo_order
  752. uo_order = Create uo_order_ml
  753. uo_outware_scllplan uo_scllplan
  754. uo_scllplan = Create uo_outware_scllplan
  755. If storageid = 0 Then
  756. rslt = 0
  757. arg_msg = '没有正确的仓库'
  758. Goto ext
  759. End If
  760. If billtype <> 9 and not (billtype = 3 And Pos(dscrp,'电脑生成的') > 0 And Pos(dscrp,'的领料单') > 0) Then
  761. If uof_check_warepdb_audit(storageid,arg_msg) = 0 Then
  762. rslt = 0
  763. Goto ext
  764. End If
  765. End If
  766. String ls_storagename
  767. Int li_storagetype
  768. Select storagename,storagetype
  769. Into :ls_storagename,:li_storagetype
  770. From u_storage
  771. Where storageid = :storageid Using commit_transaction ;
  772. If commit_transaction.SQLCode <> 0 Then
  773. rslt = 0
  774. arg_msg = "查询操作失败,仓库"
  775. Goto ext
  776. End If
  777. //检查是否有该仓库的建立权限
  778. If sys_user_storagestr_audit <> '0' Then
  779. If Pos(sys_user_storagestr_audit,','+String(storageid)+',') <= 0 Then
  780. rslt = 0
  781. arg_msg = '没有仓库: '+ls_storagename+' 的审核权限,不允许撤审该仓库的单据'
  782. Goto ext
  783. End If
  784. End If
  785. //
  786. If outwareid = 0 Then
  787. rslt = 0
  788. arg_msg = "没有审核对象"
  789. Goto ext
  790. End If
  791. If ctmint > 0 Then
  792. arg_msg = '单据已截数,不能操作'
  793. rslt = 0
  794. Goto ext
  795. End If
  796. If flag = 0 Then
  797. rslt = 0
  798. arg_msg = "单据还未审核"
  799. Goto ext
  800. End If
  801. If balcflag = 1 Then
  802. rslt = 0
  803. arg_msg = "单据已经日结,不能撤审"
  804. Goto ext
  805. End If
  806. If uo_option_confirmaudit_scll = 1 Then
  807. Update u_outware
  808. Set Auditingrep = '',
  809. Auditingdate = :null_dt,
  810. flag = 0
  811. Where u_outware.outwareid = :outwareid
  812. And scid = :scid
  813. And flag = 1
  814. And priceflag = 1
  815. And secflag = 0 Using commit_transaction;
  816. Else
  817. Update u_outware
  818. Set Auditingrep = '',
  819. Auditingdate = :null_dt,
  820. flag = 0,
  821. priceemp = '',
  822. pricedate = :null_dt,
  823. priceflag = 0
  824. Where u_outware.outwareid = :outwareid
  825. And scid = :scid
  826. And flag = 1
  827. And secflag = 0 Using commit_transaction;
  828. End If
  829. If commit_transaction.SQLCode <> 0 Then
  830. rslt = 0
  831. arg_msg = "因网络或其它原因导致撤审单据操作失败"+"~n"+commit_transaction.SQLErrText
  832. Goto ext
  833. ElseIf commit_transaction.SQLNRows = 0 Then
  834. rslt = 0
  835. arg_msg = "单据正在撤审,请稍后查询。"+"~n"+commit_transaction.SQLErrText
  836. Goto ext
  837. End If
  838. //如果是退料单,根据明细类型进行处理
  839. Decimal ld_truerqqty,ld_sqty,ld_dqty
  840. Long ll_wrkgrpid_back
  841. DateTime server_dt
  842. Long ll_cnt_bu
  843. s_order_ml_mtrl_change_mx arg_s_mx[],arg_s_empty_mx[]
  844. Select Top 1 getdate() Into :server_dt From u_user Using commit_transaction ;
  845. //取得系统时间,借用操作员表
  846. If commit_transaction.SQLCode <> 0 Then
  847. rslt = 0
  848. arg_msg = "查询操作失败,日期 "
  849. Goto ext
  850. End If
  851. uo_outware uo_out_bu
  852. uo_out_bu = Create uo_outware
  853. uo_out_bu.commit_transaction = commit_transaction
  854. uo_out_bu.if_getid_ture = False
  855. Long ll_scid_bu[],ll_outwareid_bu[]
  856. Long ll_mxbt_bu
  857. String ls_outwarecode_bu[]
  858. If billtype = 3 And relint_1 = 2 Then
  859. Select count(*)
  860. Into :ll_cnt_bu
  861. From u_outware
  862. Where billtype = 3
  863. And relint_1 = 5
  864. And relint_4 = :outwareid
  865. And flag = 1 Using commit_transaction;
  866. If commit_transaction.SQLCode <> 0 Then
  867. rslt = 0
  868. arg_msg = '查询退料单是否有相关自动建立的补料单失败 '+commit_transaction.SQLErrText
  869. Goto ext
  870. End If
  871. If ll_cnt_bu > 0 Then
  872. rslt = 0
  873. arg_msg = '相关自动建立的补料单已仓审,不能撤审退料单'
  874. Goto ext
  875. End If
  876. ll_mxbt_bu = 1
  877. Declare cur_outware_bu Cursor For
  878. Select scid,outwareid,outwarecode
  879. From u_outware
  880. Where billtype = 3
  881. And relint_1 = 5
  882. And relint_4 = :outwareid Using commit_transaction;
  883. Open cur_outware_bu;
  884. Fetch cur_outware_bu Into :ll_scid_bu[ll_mxbt_bu],:ll_outwareid_bu[ll_mxbt_bu],:ls_outwarecode_bu[ll_mxbt_bu];
  885. Do While commit_transaction.SQLCode = 0
  886. ll_mxbt_bu++
  887. Fetch cur_outware_bu Into :ll_scid_bu[ll_mxbt_bu],:ll_outwareid_bu[ll_mxbt_bu],:ls_outwarecode_bu[ll_mxbt_bu];
  888. Loop
  889. Close cur_outware_bu;
  890. For ll_i = 1 To ll_mxbt_bu - 1
  891. If uo_out_bu.del(ll_scid_bu[ll_i],ll_outwareid_bu[ll_i],0,arg_msg,False) = 0 Then
  892. arg_msg = '删除相关自动建立的补料单失败,:'+ls_outwarecode_bu[ll_i]+','+arg_msg
  893. rslt = 0
  894. Goto ext
  895. End If
  896. Next
  897. For ll_i = 1 To it_mxbt
  898. Select wrkGrpid
  899. Into :ll_wrkgrpid_back
  900. From u_workgroup
  901. Where workgroupid = :relid Using commit_transaction;
  902. If commit_transaction.SQLCode <> 0 Then
  903. arg_msg = '查询工作中心所属工组失败 ' +commit_transaction.SQLErrText
  904. rslt = 0
  905. Goto ext
  906. End If
  907. If outwaremx[ll_i].backtype = 2 And outwaremx[ll_i].relid > 0 Then
  908. Select truerqqty
  909. Into :ld_truerqqty
  910. From u_orderrqmtrl_scll
  911. Where orderid = :outwaremx[ll_i].relid
  912. And mtrlid = :outwaremx[ll_i].mtrlid
  913. And wrkGrpid = :ll_wrkgrpid_back
  914. And scid = :scid
  915. And status = :outwaremx[ll_i].status
  916. And woodcode = :outwaremx[ll_i].woodcode
  917. And pcode = :outwaremx[ll_i].pcode Using commit_transaction;
  918. If commit_transaction.SQLCode <> 0 Then
  919. arg_msg = '第'+String(ll_i)+'行,查询指令单领料明细信息失败,'+commit_transaction.SQLErrText
  920. rslt = 0
  921. Goto ext
  922. End If
  923. ld_sqty = ld_truerqqty
  924. ld_dqty = ld_truerqqty - outwaremx[ll_i].qty
  925. uo_order_ml_mtrl_change uo_mtrl_ch
  926. uo_mtrl_ch = Create uo_order_ml_mtrl_change
  927. s_order_ml_mtrl_change arg_s_mtrl_ch
  928. arg_s_mtrl_ch.scid = scid
  929. arg_s_mtrl_ch.billid = 0
  930. arg_s_mtrl_ch.billdate = server_dt
  931. arg_s_mtrl_ch.billemp = publ_operator
  932. arg_s_mtrl_ch.relcode = ''
  933. arg_s_mtrl_ch.dscrp = '退料单撤审取消终止自动生成' //注意修改时这里时要修改uo_order_ml_mtrl_change.audit
  934. arg_s_mtrl_ch.orderid = outwaremx[ll_i].relid
  935. arg_s_mtrl_ch.smtrlid = outwaremx[ll_i].mtrlid
  936. arg_s_mtrl_ch.wrkGrpid = ll_wrkgrpid_back
  937. arg_s_mtrl_ch.status = outwaremx[ll_i].status
  938. arg_s_mtrl_ch.woodcode = outwaremx[ll_i].woodcode
  939. arg_s_mtrl_ch.pcode = outwaremx[ll_i].pcode
  940. arg_s_mtrl_ch.dmtrlid = outwaremx[ll_i].mtrlid
  941. arg_s_mtrl_ch.sqty = ld_sqty
  942. arg_s_mtrl_ch.dqty = ld_dqty
  943. arg_s_mtrl_ch.billtype = 1
  944. arg_s_mtrl_ch.ifchange = 1
  945. //加明细
  946. arg_s_mx = arg_s_empty_mx
  947. If f_addmx_mtrl_change(scid,outwaremx[ll_i].relid,outwaremx[ll_i].mtrlid,ll_wrkgrpid_back,outwaremx[ll_i].status, outwaremx[ll_i].woodcode,outwaremx[ll_i].pcode,ld_sqty,ld_dqty,arg_s_mx,arg_msg) = 0 Then
  948. rslt = 0
  949. arg_msg = '明细第'+String(ll_i)+'行,生成生产指令单换料单失败,原因:计算单据明细失败.'+arg_msg
  950. Goto ext
  951. End If
  952. arg_s_mtrl_ch.arg_s_mx = arg_s_mx
  953. If uo_mtrl_ch.Save(arg_s_mtrl_ch,publ_operator,arg_msg,False) = 0 Then
  954. rslt = 0
  955. arg_msg = '明细第'+String(ll_i)+'行,生成生产指令单换料单失败,'+arg_msg
  956. Goto ext
  957. End If
  958. If uo_mtrl_ch.audit(uo_mtrl_ch.uo_billid,publ_operator,arg_msg,False) = 0 Then
  959. rslt = 0
  960. arg_msg = '明细第'+String(ll_i)+'行,审核相关生产指令单换料单失败,'+arg_msg
  961. Goto ext
  962. End If
  963. Destroy uo_mtrl_ch
  964. End If
  965. Next
  966. //检查明细是否还有开过补料单
  967. For ll_i = 1 To it_mxbt
  968. cnt = 0
  969. Select count(*)
  970. Into :cnt
  971. From u_outware Inner JOIN
  972. u_outwaremx ON u_outware.scid = u_outwaremx.scid And
  973. u_outware.outwareid = u_outwaremx.outwareid
  974. Where (u_outware.billtype = 3)
  975. And (u_outware.relint_1 = 5)
  976. And (u_outwaremx.relid = :outwaremx[ll_i].relid)
  977. And (u_outwaremx.mtrlid = :outwaremx[ll_i].mtrlid) Using commit_transaction;
  978. If commit_transaction.SQLCode <> 0 Then
  979. arg_msg = '第'+String(ll_i)+'行,查询单据明细是否已开补料单失败,'+commit_transaction.SQLErrText
  980. rslt = 0
  981. Goto ext
  982. End If
  983. If cnt > 0 Then
  984. arg_msg = '第'+String(ll_i)+'行,单据明细已开补料单,不能撤审'
  985. rslt = 0
  986. Goto ext
  987. End If
  988. Next
  989. End If
  990. For i = 1 To it_mxbt
  991. If p_update_mtrlware ( outwaremx[i].mtrlwareid, outwaremx[i].mtrlid, &
  992. outwaremx[i].mtrlcode, storageid, outwaremx[i].plancode,&
  993. outwaremx[i].status, 0 - outwaremx[i].qty,0 - outwaremx[i].uqty,0 - outwaremx[i].costamt,&
  994. outwaremx[i].planprice, outwaremx[i].sptid,outwaremx[i].dxflag,&
  995. outwaremx[i].woodcode, outwaremx[i].pcode,&
  996. outwaremx[i].mtrlcuscode,outwaremx[i].Location,outwaremx[i].ifvqty,arg_msg) = 0 Then
  997. rslt = 0
  998. Goto ext
  999. End If
  1000. If outwaremx[i].relid > 0 And relint_1 <> 4 Then
  1001. If uo_order.f_add_dstrqty(scid,outwaremx[i].relid,relid,&
  1002. outwaremx[i].mtrlid,outwaremx[i].mtrlcode,&
  1003. outwaremx[i].status,outwaremx[i].woodcode,outwaremx[i].pcode,&
  1004. 0 - outwaremx[i].qty,0 - outwaremx[i].costamt,arg_msg,False,relint_1,ld_overqty) = 0 Then
  1005. rslt = 0
  1006. Goto ext
  1007. End If
  1008. For ll_i = 1 To uo_order.it_mx_rq
  1009. ins_itmx_aps++
  1010. ins_s_rqmtrl.mtrlid[ins_itmx_aps] = uo_order.ins_s_rqmtrl.mtrlid[ll_i]
  1011. ins_s_rqmtrl.status[ins_itmx_aps] = uo_order.ins_s_rqmtrl.status[ll_i]
  1012. ins_s_rqmtrl.woodcode[ins_itmx_aps] = uo_order.ins_s_rqmtrl.woodcode[ll_i]
  1013. ins_s_rqmtrl.pcode[ins_itmx_aps] = uo_order.ins_s_rqmtrl.pcode[ll_i]
  1014. ins_s_rqmtrl.wrkGrpid[ins_itmx_aps] = uo_order.ins_s_rqmtrl.wrkGrpid[ll_i]
  1015. ins_s_rqmtrl.orderid[ins_itmx_aps] = uo_order.ins_s_rqmtrl.orderid[ll_i]
  1016. ins_s_rqmtrl.qty[ins_itmx_aps] = uo_order.ins_s_rqmtrl.qty[ll_i]
  1017. ins_s_rqmtrl.scid[ins_itmx_aps] = uo_order.ins_s_rqmtrl.scid[ll_i]
  1018. Next
  1019. If outwaremx[i].overqty > 0 Then
  1020. Update u_outwaremx
  1021. Set overqty = overqty - :outwaremx[i].overqty
  1022. Where outwareid = :outwareid
  1023. And scid = :scid
  1024. And printid = :outwaremx[i].printid;
  1025. If commit_transaction.SQLCode <> 0 Then
  1026. rslt = 0
  1027. arg_msg = '更新超计划领料数量失败'+"~n"+commit_transaction.SQLErrText
  1028. Goto ext
  1029. End If
  1030. End If
  1031. //更新库存分配
  1032. Decimal ld_assign_outqty,ld_sumnotoutqty,ld_outmxqty
  1033. Long ll_row
  1034. Long ll_porderid,ll_orderid_retrieve
  1035. Int li_ordertype_zl
  1036. If billtype = 3 And li_storagetype = 1 And outwaremx[i].iffp = 1 And outwaremx[i].relid > 0 Then
  1037. Select ordertype,porderid
  1038. Into :li_ordertype_zl,:ll_porderid
  1039. From u_order_ml
  1040. Where u_order_ml.scid = :scid
  1041. And u_order_ml.orderid = :outwaremx[i].relid
  1042. Using commit_transaction ;
  1043. If commit_transaction.SQLCode <> 0 Then
  1044. rslt = 0
  1045. arg_msg = '行:'+String(i)+',查询指令单属性失败,'+commit_transaction.SQLErrText
  1046. Goto ext
  1047. End If
  1048. If li_ordertype_zl = 4 Then
  1049. ll_orderid_retrieve = ll_porderid
  1050. Else
  1051. ll_orderid_retrieve = outwaremx[i].relid
  1052. End If
  1053. ll_row = ds_out_assign.Retrieve(scid,outwaremx[i].mtrlwareid,ll_orderid_retrieve)
  1054. ds_out_assign.AcceptText()
  1055. If ll_row <= 0 Then
  1056. ld_sumnotoutqty = 0
  1057. Else
  1058. ld_sumnotoutqty = ds_out_assign.Object.sumnotoutqty[1]
  1059. End If
  1060. ld_outmxqty = outwaremx[i].qty
  1061. If ld_outmxqty > ld_sumnotoutqty Then
  1062. arg_msg = '行:'+String(i)+'订单库存分配已出仓数不足,不能撤审,请检查库存分配明细'
  1063. rslt = 0
  1064. Goto ext
  1065. Else
  1066. ld_assign_outqty = 0
  1067. For j = 1 To ds_out_assign.RowCount()
  1068. If ds_out_assign.Object.notoutqty[j] >= ld_outmxqty Then
  1069. ld_assign_outqty = ld_outmxqty
  1070. If uo_ma.uof_assign_addoutqty(ds_out_assign.Object.assignid[j],0 - ld_assign_outqty,arg_msg,False) = 0 Then
  1071. arg_msg = '行:'+String(i)+','+arg_msg
  1072. rslt = 0
  1073. Goto ext
  1074. End If
  1075. Exit
  1076. Else
  1077. ld_assign_outqty = ds_out_assign.Object.notoutqty[j]
  1078. If uo_ma.uof_assign_addoutqty(ds_out_assign.Object.assignid[j],0 - ld_assign_outqty,arg_msg,False) = 0 Then
  1079. arg_msg = '行:'+String(i)+','+arg_msg
  1080. rslt = 0
  1081. Goto ext
  1082. End If
  1083. ld_outmxqty = ld_outmxqty - ds_out_assign.Object.notoutqty[j]
  1084. End If
  1085. Next
  1086. End If
  1087. End If
  1088. End If
  1089. //发料单
  1090. If billtype = 3 And relint_1 = 4 Then
  1091. lde_addqty = 0 - outwaremx[i].qty
  1092. lde_adduqty = 0 - outwaremx[i].uqty
  1093. // IF lde_addqty <> 0 And outwaremx[i].relid > 0 THEN
  1094. If outwaremx[i].relid > 0 Then
  1095. If uo_scllplan.p_addfactscllqty(outwaremx[i].relid,outwaremx[i].mtrlwareid,storageid,outwaremx[i].mtrlid, outwaremx[i].status, outwaremx[i].woodcode, outwaremx[i].pcode,lde_addqty,lde_adduqty, ld_overqty,0 - outwaremx[i].costamt,outwaremx[i].qty - outwaremx[i].planqty,0,False, arg_msg ) = 0 Then
  1096. rslt = 0
  1097. Goto ext
  1098. End If
  1099. For ll_i = 1 To uo_order.it_mx_rq
  1100. ins_itmx_aps++
  1101. ins_s_rqmtrl.mtrlid[ins_itmx_aps] = uo_scllplan.ins_s_rqmtrl.mtrlid[ll_i]
  1102. ins_s_rqmtrl.status[ins_itmx_aps] = uo_scllplan.ins_s_rqmtrl.status[ll_i]
  1103. ins_s_rqmtrl.woodcode[ins_itmx_aps] = uo_scllplan.ins_s_rqmtrl.woodcode[ll_i]
  1104. ins_s_rqmtrl.pcode[ins_itmx_aps] = uo_scllplan.ins_s_rqmtrl.pcode[ll_i]
  1105. ins_s_rqmtrl.wrkGrpid[ins_itmx_aps] = uo_scllplan.ins_s_rqmtrl.wrkGrpid[ll_i]
  1106. ins_s_rqmtrl.orderid[ins_itmx_aps] = uo_scllplan.ins_s_rqmtrl.orderid[ll_i]
  1107. ins_s_rqmtrl.qty[ins_itmx_aps] = uo_scllplan.ins_s_rqmtrl.qty[ll_i]
  1108. ins_s_rqmtrl.scid[ins_itmx_aps] = uo_scllplan.ins_s_rqmtrl.scid[ll_i]
  1109. Next
  1110. If outwaremx[i].overqty > 0 Then
  1111. Update u_outwaremx
  1112. Set overqty = overqty - :outwaremx[i].overqty
  1113. Where outwareid = :outwareid
  1114. And scid = :scid
  1115. And printid = :outwaremx[i].printid;
  1116. If commit_transaction.SQLCode <> 0 Then
  1117. rslt = 0
  1118. arg_msg = '更新超计划领料数量失败'+"~n"+commit_transaction.SQLErrText
  1119. Goto ext
  1120. End If
  1121. End If
  1122. End If
  1123. End If
  1124. //yyx2012-9-29返回计算可装数库存id数组
  1125. If ( outwaremx[i].ifpack = 1 Or outwaremx[i].ifpack = 2 Or outwaremx[i].ifpackpro = 3 Or outwaremx[i].ifpackpro = 4 ) And uo_option_mtrlware_autocmp = 1 Then
  1126. If uo_option_noauditingqty_mode = 0 Then
  1127. If uo_cmpl_p.uof_ref_mtrlwarid_array(outwaremx[i].mtrlid,outwaremx[i].plancode,outwaremx[i].mtrlcuscode,storageid,s_mtrlwareid_array_rst,arg_msg) = 0 Then
  1128. rslt = 0
  1129. Goto ext
  1130. End If
  1131. Else
  1132. ins_ref_mxbt++
  1133. ins_ref_outwaremx[ins_ref_mxbt].mtrlid = outwaremx[i].mtrlid
  1134. ins_ref_outwaremx[ins_ref_mxbt].plancode = outwaremx[i].plancode
  1135. ins_ref_outwaremx[ins_ref_mxbt].mtrlcuscode = outwaremx[i].mtrlcuscode
  1136. ins_ref_outwaremx[ins_ref_mxbt].storageid = storageid
  1137. End If
  1138. End If
  1139. //
  1140. Next
  1141. //增加已开单数
  1142. If uof_noauditingqty_add(scid,billtype,relint_1,arg_msg) = 0 Then
  1143. rslt = 0
  1144. Goto ext
  1145. End If
  1146. //yyx2012-9-29返回计算可装数库存id数组计算可装数
  1147. If UpperBound(s_mtrlwareid_array_rst.mtrlwareid) > 0 And uo_option_mtrlware_autocmp = 1 Then
  1148. If uo_option_noauditingqty_mode = 0 Then
  1149. If uo_cmpl_p.uof_cmpl_diqty(s_mtrlwareid_array_rst,arg_msg) = 0 Then
  1150. rslt = 0
  1151. Goto ext
  1152. End If
  1153. End If
  1154. End If
  1155. //
  1156. If uo_option_wkpmtrlware = 0 And uo_option_scll_plan_wsaudit = 0 And billtype = 3 And relint_1 = 4 Then
  1157. Long ll_inwareid
  1158. Select count(*)
  1159. Into :cnt
  1160. From u_inware
  1161. Where relint_3 = :outwareid
  1162. And scid = :scid Using commit_transaction;
  1163. If commit_transaction.SQLCode <> 0 Then
  1164. rslt = 0
  1165. arg_msg = '查询发料单是否有相关车间进仓单失败,'+commit_transaction.SQLErrText
  1166. Goto ext
  1167. End If
  1168. If cnt > 0 Then
  1169. Select top 1 inwareid Into :ll_inwareid
  1170. From u_inware
  1171. Where relint_3 = :outwareid
  1172. And scid = :scid Using commit_transaction;
  1173. If commit_transaction.SQLCode <> 0 Then
  1174. rslt = 0
  1175. arg_msg = '查询发料单是否有相关车间进仓单失败,'+commit_transaction.SQLErrText
  1176. Goto ext
  1177. End If
  1178. End If
  1179. If ll_inwareid > 0 Then
  1180. uo_inware uo_in
  1181. uo_in = Create uo_inware
  1182. uo_in.commit_transaction = commit_transaction
  1183. If uo_in.getinfo(scid,ll_inwareid,arg_msg) = 0 Then
  1184. arg_msg = '删除相关自动车间进仓单失败,' + arg_msg
  1185. rslt = 0
  1186. Goto ext
  1187. End If
  1188. If uo_in.c_auditing(False,arg_msg) = 0 Then
  1189. arg_msg = '删除相关自动车间进仓单失败,' + arg_msg
  1190. rslt = 0
  1191. Goto ext
  1192. End If
  1193. If uo_in.del(scid,ll_inwareid,arg_msg,False) = 0 Then
  1194. arg_msg = '删除相关自动车间进仓单失败,' + arg_msg
  1195. rslt = 0
  1196. Goto ext
  1197. End If
  1198. End If
  1199. End If
  1200. flag = 0
  1201. ext:
  1202. If rslt = 0 Then
  1203. Rollback Using commit_transaction;
  1204. ElseIf rslt = 1 And arg_ifcommit Then
  1205. Commit Using commit_transaction;
  1206. End If
  1207. Destroy uo_order
  1208. Destroy uo_scllplan
  1209. Destroy uo_ma
  1210. Destroy uo_cmpl_p
  1211. Destroy ds_out_assign
  1212. Destroy uo_out_bu
  1213. Return rslt
  1214. end function
  1215. public function integer secauditing (boolean arg_ifcommit, ref string arg_msg);Int rslt = 1
  1216. Long i,cnt = 0
  1217. String ls_location
  1218. String ls_wrkgrpname
  1219. IF uo_option_wkpmtrlware = -1000 THEN
  1220. arg_msg = '选项:[057]生产使用车间核算,读取初始默认值失败,操作取消!'
  1221. rslt = 0
  1222. GOTO ext
  1223. END IF
  1224. IF uo_option_inware_sc_location = -1000 THEN
  1225. arg_msg = '选项:[151]车间仓仓位按工组名称,读取初始默认值失败,操作取消!'
  1226. rslt = 0
  1227. GOTO ext
  1228. END IF
  1229. IF uo_option_outware_scll_new_cj_mtrlware = -1000 THEN
  1230. arg_msg = '选项:[355]其它领料单增加车间仓库存,读取初始默认值失败,操作取消!'
  1231. rslt = 0
  1232. GOTO ext
  1233. END IF
  1234. If uo_option_scll_plan_wsaudit = -1000 Then
  1235. arg_msg = '选项:[377]发料单使用明细车间审核流程,读取初始默认值失败,操作取消!'
  1236. rslt = 0
  1237. Goto ext
  1238. End If
  1239. IF outwareid = 0 THEN
  1240. rslt = 0
  1241. arg_msg = "没有审核对象"
  1242. GOTO ext
  1243. END IF
  1244. IF flag = 0 THEN
  1245. rslt = 0
  1246. arg_msg = "单据还没有经过仓库审核"
  1247. GOTO ext
  1248. END IF
  1249. IF secflag = 1 THEN
  1250. rslt = 0
  1251. arg_msg = "单据已经过二审"
  1252. GOTO ext
  1253. END IF
  1254. //SELECT count(*) INTO :cnt
  1255. // FROM u_user
  1256. // Where username = :publ_operator Using commit_transaction ;
  1257. //IF commit_transaction.SQLCode <> 0 THEN
  1258. // rslt = 0
  1259. // arg_msg = "查询操作失败,操作员"
  1260. // GOTO ext
  1261. //END IF
  1262. //
  1263. //IF cnt = 0 THEN
  1264. // rslt = 0
  1265. // arg_msg = "操作员姓名未登记或已取消"
  1266. // GOTO ext
  1267. //END IF
  1268. UPDATE u_outware
  1269. SET secauditingrep = :publ_operator,
  1270. secauditingdate = getdate(),
  1271. secflag = 1
  1272. WHERE u_outware.outwareid = :outwareid AND
  1273. flag = 1 AND secflag = 0
  1274. And scid = :scid Using commit_transaction;
  1275. IF commit_transaction.SQLCode <> 0 THEN
  1276. rslt = 0
  1277. arg_msg = "因网络或其它原因导致二审单据操作失败"+"~n"+commit_transaction.SQLErrText
  1278. GOTO ext
  1279. ELSEIF commit_transaction.SQLNRows = 0 THEN
  1280. rslt = 0
  1281. arg_msg = "单据正在二审,请稍后查询。"+"~n"+commit_transaction.SQLErrText
  1282. GOTO ext
  1283. END IF
  1284. //领料单审核自动生成车间进仓单
  1285. IF uo_option_wkpmtrlware = 1 THEN
  1286. IF relint_1 = 3 And uo_option_outware_scll_new_cj_mtrlware = 0 THEN
  1287. GOTO end_inware
  1288. END IF
  1289. IF relint_1 = 4 And uo_option_scll_plan_wsaudit = 1 THEN
  1290. GOTO end_inware
  1291. END IF
  1292. Long ll_wrkGrpid
  1293. Long ll_storageid,ll_storageid_scid
  1294. Long ll_inwareid,ll_inwareid_ws
  1295. Long ll_pid
  1296. Int li_ifwkpmtrlware
  1297. Int li_iforder,li_ifover
  1298. Decimal ld_qty_tmp,ld_uqty_tmp
  1299. SELECT wrkGrpid INTO :ll_wrkGrpid
  1300. FROM u_workgroup
  1301. Where workgroupid = :relid Using commit_transaction;
  1302. IF commit_transaction.SQLCode <> 0 THEN
  1303. rslt = 0
  1304. arg_msg = '查询工作组所属工组失败'+"~n"+commit_transaction.SQLErrText
  1305. GOTO ext
  1306. END IF
  1307. IF ll_wrkGrpid = 0 THEN
  1308. arg_msg = '领料组未设定所属工组'
  1309. rslt = 0
  1310. GOTO ext
  1311. END IF
  1312. SELECT u_sc_wkp.storageid,
  1313. isnull(u_storage.scid,0),
  1314. u_sc_wkp.ifwkpmtrlware,
  1315. u_sc_workgroup.wrkgrpname
  1316. INTO :ll_storageid,
  1317. :ll_storageid_scid,
  1318. :li_ifwkpmtrlware,
  1319. :ls_wrkgrpname
  1320. FROM u_sc_workgroup,u_storage,u_sc_wkp
  1321. WHERE u_sc_workgroup.wrkGrpid = :ll_wrkGrpid
  1322. AND u_sc_wkp.storageid = u_storage.storageid
  1323. AND u_sc_wkp.wrkGrpid = u_sc_workgroup.storageid
  1324. Using commit_transaction;
  1325. IF commit_transaction.SQLCode <> 0 THEN
  1326. rslt = 0
  1327. arg_msg = '查询工组所属车间所属仓库失败'+"~n"+commit_transaction.SQLErrText
  1328. GOTO ext
  1329. END IF
  1330. IF uo_option_inware_sc_location = 1 THEN
  1331. ls_location = ls_wrkgrpname
  1332. ELSE
  1333. ls_location = ''
  1334. END IF
  1335. IF IsNull(ll_storageid) THEN ll_storageid = 0
  1336. IF IsNull(ll_storageid_scid) THEN ll_storageid_scid = 0
  1337. IF IsNull(li_ifwkpmtrlware) THEN li_ifwkpmtrlware = 0
  1338. IF li_ifwkpmtrlware = 1 THEN
  1339. IF ll_storageid = 0 THEN
  1340. arg_msg = '领料组所属车间未指定仓库'
  1341. rslt = 0
  1342. GOTO ext
  1343. END IF
  1344. IF ll_storageid_scid <> scid THEN
  1345. arg_msg = '领料车间对就仓库分部与单据分部不相符,请检查'
  1346. rslt = 0
  1347. GOTO ext
  1348. END IF
  1349. li_iforder = 0
  1350. li_ifover = 0
  1351. FOR i = 1 To it_mxbt
  1352. IF outwaremx[i].relid > 0 THEN
  1353. li_iforder = 1
  1354. IF outwaremx[i].overqty > 0 THEN
  1355. li_ifover = 1
  1356. END IF
  1357. ELSE
  1358. li_ifover = 1
  1359. END IF
  1360. IF li_iforder = 1 And li_ifover = 1 THEN EXIT
  1361. NEXT
  1362. IF li_ifover = 1 THEN
  1363. uo_inware uo_in
  1364. uo_in = Create uo_inware
  1365. uo_in.commit_transaction = commit_transaction
  1366. uo_in.if_getid_ture = False
  1367. IF uo_in.newbegin(scid,16,arg_msg) = 0 THEN
  1368. rslt = 0
  1369. GOTO ext
  1370. END IF
  1371. uo_in.indate = outdate
  1372. uo_in.inrep = outrep
  1373. uo_in.part = outwarecode
  1374. uo_in.dscrp = dscrp
  1375. uo_in.storageid = ll_storageid
  1376. uo_in.sptname = '车间领料自动进仓(不按计划/超数量)'
  1377. ll_pid = 0
  1378. FOR i = 1 To it_mxbt
  1379. ld_qty_tmp = 0
  1380. ld_uqty_tmp = 0
  1381. IF outwaremx[i].relid = 0 Or &
  1382. ( outwaremx[i].relid > 0 And outwaremx[i].overqty > 0 ) THEN
  1383. IF outwaremx[i].relid = 0 THEN
  1384. ld_qty_tmp = outwaremx[i].qty
  1385. ld_uqty_tmp = outwaremx[i].uqty
  1386. ELSE
  1387. ld_qty_tmp = outwaremx[i].overqty
  1388. ld_uqty_tmp = outwaremx[i].overqty / outwaremx[i].rate
  1389. END IF
  1390. ELSE
  1391. CONTINUE
  1392. END IF
  1393. ll_pid++
  1394. IF uo_in.acceptmx(ll_pid,&
  1395. outwaremx[i].mtrlid,&
  1396. outwaremx[i].mtrlcode,&
  1397. outwaremx[i].plancode,&
  1398. outwaremx[i].status,&
  1399. ld_uqty_tmp,&
  1400. outwaremx[i].cost,&
  1401. outwaremx[i].rebate,&
  1402. outwaremx[i].mxdscrp,&
  1403. arg_msg,&
  1404. 0,0,0,&
  1405. outwaremx[i].woodcode,&
  1406. outwaremx[i].pcode,0,&
  1407. outwaremx[i].unit,&
  1408. outwaremx[i].rate,&
  1409. ld_qty_tmp,&
  1410. 0,0,'','',0,0,'',ls_location,&
  1411. ld_uqty_tmp,&
  1412. 0) = 0 THEN
  1413. rslt = 0
  1414. GOTO ext
  1415. END IF
  1416. NEXT
  1417. IF ll_pid > 0 THEN
  1418. IF uo_in.Save(False,arg_msg) = 0 THEN
  1419. rslt = 0
  1420. GOTO ext
  1421. END IF
  1422. ll_inwareid = uo_in.inwareid
  1423. IF uo_in.getinfo(scid,ll_inwareid,arg_msg) = 0 THEN
  1424. rslt = 0
  1425. GOTO ext
  1426. END IF
  1427. IF uo_in.auditing(False,arg_msg) = 0 THEN
  1428. rslt = 0
  1429. GOTO ext
  1430. END IF
  1431. END IF
  1432. END IF
  1433. IF li_iforder = 1 THEN
  1434. uo_inware uo_in_ws
  1435. uo_in_ws = Create uo_inware
  1436. uo_in_ws.commit_transaction = commit_transaction
  1437. uo_in_ws.if_getid_ture = False
  1438. IF uo_in_ws.newbegin(scid,20,arg_msg) = 0 THEN
  1439. rslt = 0
  1440. GOTO ext
  1441. END IF
  1442. uo_in_ws.indate = outdate
  1443. uo_in_ws.inrep = outrep
  1444. uo_in_ws.part = outwarecode
  1445. uo_in_ws.dscrp = dscrp
  1446. uo_in_ws.storageid = ll_storageid
  1447. uo_in_ws.sptname = '车间领料自动进仓(按计划)'
  1448. ll_pid = 0
  1449. FOR i = 1 To it_mxbt
  1450. ld_qty_tmp = 0
  1451. ld_uqty_tmp = 0
  1452. IF outwaremx[i].relid > 0 THEN
  1453. ld_qty_tmp = outwaremx[i].qty - outwaremx[i].overqty
  1454. ld_uqty_tmp = (outwaremx[i].qty - outwaremx[i].overqty) / outwaremx[i].rate
  1455. ELSE
  1456. CONTINUE
  1457. END IF
  1458. ll_pid++
  1459. IF uo_in_ws.acceptmx(ll_pid,&
  1460. outwaremx[i].mtrlid,&
  1461. outwaremx[i].mtrlcode,&
  1462. outwaremx[i].plancode,&
  1463. outwaremx[i].status,&
  1464. ld_uqty_tmp,&
  1465. outwaremx[i].cost,&
  1466. outwaremx[i].rebate,&
  1467. outwaremx[i].mxdscrp,&
  1468. arg_msg,&
  1469. 0,0,0,&
  1470. outwaremx[i].woodcode,&
  1471. outwaremx[i].pcode,0,&
  1472. outwaremx[i].unit,&
  1473. outwaremx[i].rate,&
  1474. ld_qty_tmp,&
  1475. 0,0,'','',0,0,'',ls_location,&
  1476. ld_uqty_tmp,&
  1477. 0) = 0 THEN
  1478. rslt = 0
  1479. GOTO ext
  1480. END IF
  1481. NEXT
  1482. IF ll_pid > 0 THEN
  1483. IF uo_in_ws.Save(False,arg_msg) = 0 THEN
  1484. rslt = 0
  1485. GOTO ext
  1486. END IF
  1487. ll_inwareid_ws = uo_in_ws.inwareid
  1488. IF uo_in_ws.getinfo(scid,ll_inwareid_ws,arg_msg) = 0 THEN
  1489. rslt = 0
  1490. GOTO ext
  1491. END IF
  1492. IF uo_in_ws.auditing(False,arg_msg) = 0 THEN
  1493. rslt = 0
  1494. GOTO ext
  1495. END IF
  1496. END IF
  1497. END IF
  1498. UPDATE u_outware
  1499. SET relint_2 = :ll_inwareid,
  1500. relint_3 = :ll_inwareid_ws
  1501. WHERE outwareid = :outwareid
  1502. AND scid = :scid
  1503. Using commit_transaction;
  1504. IF commit_transaction.SQLCode <> 0 THEN
  1505. rslt = 0
  1506. arg_msg = '更新出仓单失败'+'~n'+commit_transaction.SQLErrText
  1507. GOTO ext
  1508. END IF
  1509. Destroy uo_in
  1510. Destroy uo_in_ws
  1511. END IF
  1512. END IF
  1513. end_inware:
  1514. secflag = 1
  1515. ext:
  1516. IF rslt = 0 THEN
  1517. ROLLBACK Using commit_transaction;
  1518. ELSEIF rslt = 1 And arg_ifcommit THEN
  1519. COMMIT Using commit_transaction;
  1520. END IF
  1521. RETURN rslt
  1522. end function
  1523. public function integer c_secauditing (boolean arg_ifcommit, ref string arg_msg);Int rslt = 1
  1524. Long cnt = 0
  1525. DateTime null_datetime
  1526. IF uo_option_wkpmtrlware = -1000 THEN
  1527. arg_msg = '选项:[057]生产使用车间核算,读取初始默认值失败,操作取消!'
  1528. rslt = 0
  1529. GOTO ext
  1530. END IF
  1531. IF uo_option_outware_scll_new_cj_mtrlware = -1000 THEN
  1532. arg_msg = '选项:[355]其它领料单增加车间仓库存,读取初始默认值失败,操作取消!'
  1533. rslt = 0
  1534. GOTO ext
  1535. END IF
  1536. If uo_option_scll_plan_wsaudit = -1000 Then
  1537. arg_msg = '选项:[377]发料单使用明细车间审核流程,读取初始默认值失败,操作取消!'
  1538. rslt = 0
  1539. Goto ext
  1540. End If
  1541. IF outwareid = 0 THEN
  1542. rslt = 0
  1543. arG_MSG = "没有撤审对象"
  1544. GOTO ext
  1545. END IF
  1546. IF ctmint > 0 THEN
  1547. arG_MSG = '单据已截数,不能操作'
  1548. rslt = 0
  1549. GOTO ext
  1550. END IF
  1551. IF secflag = 0 THEN
  1552. rslt = 0
  1553. arG_MSG = "该单据未二审,不能进行二级撤审"
  1554. GOTO ext
  1555. END IF
  1556. SELECT count(*) INTO :cnt
  1557. FROM u_user
  1558. Where username = :publ_operator USING commit_transaction ;
  1559. IF commit_transaction.SQLCode <> 0 THEN
  1560. rslt = 0
  1561. arG_MSG = "查询操作失败,操作员"
  1562. GOTO ext
  1563. END IF
  1564. IF cnt = 0 THEN
  1565. rslt = 0
  1566. arG_MSG = "操作员姓名未登记或已取消"
  1567. GOTO ext
  1568. END IF
  1569. SetNull(null_datetime)
  1570. UPDATE u_outware
  1571. SET secAuditingrep = '',
  1572. secAuditingdate = :null_datetime,
  1573. secflag = 0
  1574. WHERE u_outware.outwareid = :outwareid
  1575. AND scid = :scid USING commit_transaction;
  1576. IF commit_transaction.SQLCode <> 0 THEN
  1577. rslt = 0
  1578. arG_MSG = "因网络或其它原因导致二审单据操作失败"+"~n"+commit_transaction.SQLErrText
  1579. GOTO ext
  1580. ELSEIF commit_transaction.SQLNRows = 0 THEN
  1581. rslt = 0
  1582. arG_MSG = "单据正在二审,请稍后查询。"+"~n"+commit_transaction.SQLErrText
  1583. GOTO ext
  1584. END IF
  1585. //领料单撤销审核自动删除车间进仓单
  1586. IF uo_option_wkpmtrlware = 1 THEN
  1587. IF relint_1 = 3 And uo_option_outware_scll_new_cj_mtrlware = 0 THEN
  1588. GOTO end_inware
  1589. END IF
  1590. IF relint_1 = 4 And uo_option_scll_plan_wsaudit = 0 THEN
  1591. GOTO end_inware
  1592. END IF
  1593. IF relint_2 > 0 THEN
  1594. uo_inware uo_in
  1595. uo_in = CREATE uo_inware
  1596. uo_in.commit_transaction = commit_transaction
  1597. IF uo_in.getinfo(scid,relint_2,arG_MSG) = 0 THEN
  1598. rslt = 0
  1599. GOTO ext
  1600. END IF
  1601. IF uo_in.c_auditing(FALSE,arG_MSG) = 0 THEN
  1602. rslt = 0
  1603. GOTO ext
  1604. END IF
  1605. IF uo_in.del(scid,relint_2,arG_MSG,FALSE) = 0 THEN
  1606. rslt = 0
  1607. GOTO ext
  1608. END IF
  1609. UPDATE u_outware
  1610. SET relint_2 = 0
  1611. WHERE outwareid = :outwareid
  1612. AND scid = :scid
  1613. USING commit_transaction;
  1614. IF commit_transaction.SQLCode <> 0 THEN
  1615. rslt = 0
  1616. arG_MSG = '更新出仓单失败'+'~n'+commit_transaction.SQLErrText
  1617. GOTO ext
  1618. END IF
  1619. END IF
  1620. IF relint_3 > 0 THEN
  1621. uo_inware uo_in_ws
  1622. uo_in_ws = CREATE uo_inware
  1623. uo_in_ws.commit_transaction = commit_transaction
  1624. IF uo_in_ws.getinfo(scid,relint_3,arG_MSG) = 0 THEN
  1625. rslt = 0
  1626. GOTO ext
  1627. END IF
  1628. IF uo_in_ws.c_auditing(FALSE,arG_MSG) = 0 THEN
  1629. rslt = 0
  1630. GOTO ext
  1631. END IF
  1632. IF uo_in_ws.del(scid,relint_3,arG_MSG,FALSE) = 0 THEN
  1633. rslt = 0
  1634. GOTO ext
  1635. END IF
  1636. UPDATE u_outware
  1637. SET relint_3 = 0
  1638. WHERE outwareid = :outwareid
  1639. AND scid = :scid
  1640. USING commit_transaction;
  1641. IF commit_transaction.SQLCode <> 0 THEN
  1642. rslt = 0
  1643. arG_MSG = '更新出仓单失败'+'~n'+commit_transaction.SQLErrText
  1644. GOTO ext
  1645. END IF
  1646. END IF
  1647. DESTROY uo_in_ws
  1648. END IF
  1649. end_inware:
  1650. secflag = 0
  1651. ext:
  1652. IF rslt = 0 THEN
  1653. ROLLBACK USING commit_transaction;
  1654. ELSEIF rslt = 1 AND arg_ifcommit THEN
  1655. COMMIT USING commit_transaction;
  1656. END IF
  1657. RETURN rslt
  1658. end function
  1659. public function integer priceaudit (boolean arg_ifcommit, ref string arg_msg);Long rslt = 1,i
  1660. IF priceflag = 1 THEN
  1661. rslt = 0
  1662. arg_msg = "单据已经确认"
  1663. GOTO ext
  1664. END IF
  1665. UPDATE u_outware
  1666. SET priceemp = :publ_operator,
  1667. pricedate = getdate(),
  1668. priceflag = 1
  1669. WHERE u_outware.outwareid = :outwareid
  1670. AND priceflag = 0
  1671. AND scid = :scid USING commit_transaction;
  1672. IF commit_transaction.SQLCode <> 0 THEN
  1673. rslt = 0
  1674. arg_msg = "因网络或其它原因导致确认单据操作失败"+"~n"+commit_transaction.SQLErrText
  1675. GOTO ext
  1676. ELSEIF commit_transaction.SQLNRows = 0 THEN
  1677. rslt = 0
  1678. arg_msg = "单据正在确认,请稍后查询。"+"~n"+commit_transaction.SQLErrText
  1679. GOTO ext
  1680. END IF
  1681. priceflag = 1
  1682. ext:
  1683. IF rslt = 0 THEN
  1684. ROLLBACK USING commit_transaction;
  1685. ELSEIF rslt = 1 AND arg_ifcommit THEN
  1686. COMMIT USING commit_transaction;
  1687. END IF
  1688. RETURN rslt
  1689. end function
  1690. public function integer c_priceaudit (boolean arg_ifcommit, ref string arg_msg);Long rslt = 1,i
  1691. DateTime null_dt
  1692. SetNull(null_dt)
  1693. IF uo_option_confirmaudit_sale = -1000 THEN
  1694. arg_msg = '选项:[025]销售发货单先确认后仓库审核,读取初始默认值失败,操作取消!'
  1695. rslt = 0
  1696. GOTO ext
  1697. END IF
  1698. IF priceflag = 0 THEN
  1699. rslt = 0
  1700. arg_msg = "单据还未确认,不能反确认"
  1701. GOTO ext
  1702. END IF
  1703. IF uo_option_confirmaudit_sale = 1 THEN
  1704. IF flag = 1 THEN
  1705. rslt = 0
  1706. arg_msg = "领料单已仓审,不能反确认"
  1707. GOTO ext
  1708. END IF
  1709. END IF
  1710. UPDATE u_outware
  1711. SET priceemp = '',
  1712. pricedate = :null_dt,
  1713. priceflag = 0
  1714. WHERE u_outware.outwareid = :outwareid
  1715. AND priceflag = 1
  1716. AND scid = :scid USING commit_transaction;
  1717. IF commit_transaction.SQLCode <> 0 THEN
  1718. rslt = 0
  1719. arg_msg = "因网络或其它原因导致反确认单据操作失败"+"~n"+commit_transaction.SQLErrText
  1720. GOTO ext
  1721. ELSEIF commit_transaction.SQLNRows = 0 THEN
  1722. rslt = 0
  1723. arg_msg = "单据正在反确认,请稍后查询。"+"~n"+commit_transaction.SQLErrText
  1724. GOTO ext
  1725. END IF
  1726. priceflag = 0
  1727. ext:
  1728. IF rslt = 0 THEN
  1729. ROLLBACK USING commit_transaction;
  1730. ELSEIF rslt = 1 AND arg_ifcommit THEN
  1731. COMMIT USING commit_transaction;
  1732. END IF
  1733. RETURN rslt
  1734. end function
  1735. public function integer uof_auto_secaudit (ref string arg_msg);Long ll_i
  1736. Int rslt = 1
  1737. Long ll_scid,ll_outwareid
  1738. String ls_outwarecode
  1739. datastore ds_scll
  1740. ds_scll = Create datastore
  1741. ds_scll.DataObject = 'ds_outware_scll_auto_secaudit'
  1742. ds_scll.SetTransObject(commit_transaction)
  1743. ds_scll.Retrieve()
  1744. For ll_i = 1 To ds_scll.RowCount()
  1745. ll_scid = ds_scll.Object.scid[ll_i]
  1746. ll_outwareid = ds_scll.Object.outwareid[ll_i]
  1747. ls_outwarecode = ds_scll.Object.outwarecode[ll_i]
  1748. If getinfo(ll_scid,ll_outwareid,arg_msg) = 0 Then
  1749. rslt = 0
  1750. arg_msg = arg_msg + ls_outwarecode+' 审核失败,'+arg_msg + '~r~n'
  1751. Continue
  1752. End If
  1753. If secauditing(True,arg_msg) = 0 Then
  1754. rslt = 0
  1755. arg_msg = arg_msg + ls_outwarecode+' 审核失败,'+arg_msg + '~r~n'
  1756. Continue
  1757. End If
  1758. Next
  1759. destroy ds_scll
  1760. Return rslt
  1761. end function
  1762. public function integer wsauditing (long arg_scid, long arg_outwareid, long arg_printid, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  1763. Int li_flag,li_wsauditflag
  1764. Decimal ld_planqty,ld_qty
  1765. Decimal ld_trueoverqty,ld_wasteqty
  1766. Long ll_relwsinwareid,ll_relwsoutwareid,ll_relid
  1767. Long ll_wrkgrpid,ll_storageid,ll_storageid_scid
  1768. String ls_wrkgrpname,ls_location
  1769. Long ll_mtrlid
  1770. String ls_mtrlcode,ls_plancode,ls_status,ls_woodcode,ls_pcode
  1771. Decimal ld_cost,ld_rebate
  1772. String ls_mxdscrp,ls_unit
  1773. Long cnt
  1774. DateTime server_dt
  1775. String ls_overreason
  1776. Long ll_mtrlwareid
  1777. Decimal ld_price
  1778. //判断选项
  1779. If uo_option_scll_plan_wsaudit = -1000 Then
  1780. arg_msg = '选项:[377]发料单使用明细车间审核流程,读取初始默认值失败,操作取消!'
  1781. rslt = 0
  1782. Goto ext
  1783. End If
  1784. If uo_option_scll_plan_wsaudit = 0 Then
  1785. rslt = 0
  1786. arg_msg = '选项[377]发料单使用明细车间审核流程设为否,不能使用明细车间审核/撤审功能'
  1787. Goto ext
  1788. End If
  1789. Select Top 1 getdate() Into :server_dt From u_user Using commit_transaction ;
  1790. //取得系统时间,借用操作员表
  1791. If commit_transaction.SQLCode <> 0 Then
  1792. rslt = 0
  1793. arg_msg = "查询操作失败,日期 "
  1794. Goto ext
  1795. End If
  1796. //判断单据是否已仓审,是否已做过车间审
  1797. Select u_outware.flag,
  1798. u_outwaremx.wsauditflag,
  1799. u_outwaremx.planqty,
  1800. u_outwaremx.qty,
  1801. u_outwaremx.trueoverqty,
  1802. u_outware.relid,
  1803. u_outwaremx.mtrlid,
  1804. u_mtrldef.mtrlcode,
  1805. u_outwaremx.plancode,
  1806. u_outwaremx.status,
  1807. u_outwaremx.woodcode,
  1808. u_outwaremx.pcode,
  1809. u_outwaremx.cost,
  1810. u_outwaremx.rebate,
  1811. u_outwaremx.mxdscrp,
  1812. u_mtrldef.unit,
  1813. u_outwaremx.overreason
  1814. Into :li_flag,
  1815. :li_wsauditflag,
  1816. :ld_planqty,
  1817. :ld_qty,
  1818. :ld_trueoverqty,
  1819. :ll_relid,
  1820. :ll_mtrlid,
  1821. :ls_mtrlcode,
  1822. :ls_plancode,
  1823. :ls_status,
  1824. :ls_woodcode,
  1825. :ls_pcode,
  1826. :ld_cost,
  1827. :ld_rebate,
  1828. :ls_mxdscrp,
  1829. :ls_unit,
  1830. :ls_overreason
  1831. From u_outwaremx Inner JOIN
  1832. u_outware ON u_outwaremx.scid = u_outware.scid And
  1833. u_outwaremx.outwareid = u_outware.outwareid Inner JOIN
  1834. u_mtrldef ON u_outwaremx.mtrlid = u_mtrldef.mtrlid
  1835. Where u_outwaremx.scid = :arg_scid
  1836. And u_outwaremx.outwareid = :arg_outwareid
  1837. And u_outwaremx.printid = :arg_printid Using commit_transaction;
  1838. If commit_transaction.SQLCode <> 0 Then
  1839. rslt = 0
  1840. arg_msg = '查询发料单信息失败,'+commit_transaction.SQLErrText
  1841. Goto ext
  1842. End If
  1843. If li_flag <> 1 Then
  1844. rslt = 0
  1845. arg_msg = '单据未执行仓审,不能进行车间审'
  1846. Goto ext
  1847. End If
  1848. If li_wsauditflag = 1 Then
  1849. rslt = 0
  1850. arg_msg = '明细已执行过车间审,不能重复执行'
  1851. Goto ext
  1852. End If
  1853. ld_wasteqty = ld_qty - ld_planqty - ld_trueoverqty
  1854. If ld_qty - ld_planqty > 0 Or ld_wasteqty > 0 Then
  1855. If getinfo(arg_scid,arg_outwareid,arg_msg) = 0 Then
  1856. rslt = 0
  1857. Goto ext
  1858. End If
  1859. Select wrkGrpid Into :ll_wrkGrpid
  1860. From u_workgroup
  1861. Where workgroupid = :relid Using commit_transaction;
  1862. If commit_transaction.SQLCode <> 0 Then
  1863. rslt = 0
  1864. arg_msg = '查询工作组所属工组失败'+"~n"+commit_transaction.SQLErrText
  1865. Goto ext
  1866. End If
  1867. If ll_wrkgrpid = 0 Then
  1868. arg_msg = '领料组未设定所属工组'
  1869. rslt = 0
  1870. Goto ext
  1871. End If
  1872. Select u_sc_wkp.storageid,
  1873. isnull(u_storage.scid,0),
  1874. u_sc_workgroup.wrkgrpname
  1875. Into :ll_storageid,
  1876. :ll_storageid_scid,
  1877. :ls_wrkgrpname
  1878. From u_sc_workgroup,u_storage,u_sc_wkp
  1879. Where u_sc_workgroup.wrkGrpid = :ll_wrkGrpid
  1880. And u_sc_wkp.storageid = u_storage.storageid
  1881. And u_sc_wkp.wrkGrpid = u_sc_workgroup.storageid
  1882. Using commit_transaction;
  1883. If commit_transaction.SQLCode <> 0 Then
  1884. rslt = 0
  1885. arg_msg = '查询工组所属车间所属仓库失败'+"~n"+commit_transaction.SQLErrText
  1886. Goto ext
  1887. End If
  1888. If uo_option_inware_sc_location = 1 Then
  1889. ls_location = ls_wrkgrpname
  1890. Else
  1891. ls_location = ''
  1892. End If
  1893. If IsNull(ll_storageid) Then ll_storageid = 0
  1894. If IsNull(ll_storageid_scid) Then ll_storageid_scid = 0
  1895. If ll_storageid = 0 Then
  1896. arg_msg = '领料组所属车间未指定仓库'
  1897. rslt = 0
  1898. Goto ext
  1899. End If
  1900. If ll_storageid_scid <> scid Then
  1901. arg_msg = '领料车间对就仓库分部与单据分部不相符,请检查'
  1902. rslt = 0
  1903. Goto ext
  1904. End If
  1905. If ld_qty - ld_planqty > 0 Then
  1906. uo_inware uo_in
  1907. uo_in = Create uo_inware
  1908. uo_in.commit_transaction = commit_transaction
  1909. uo_in.if_getid_ture = False
  1910. If uo_in.newbegin(scid,16,arg_msg) = 0 Then
  1911. rslt = 0
  1912. Goto ext
  1913. End If
  1914. uo_in.indate = server_dt
  1915. uo_in.inrep = publ_operator
  1916. uo_in.part = outwarecode
  1917. uo_in.dscrp = ''
  1918. uo_in.storageid = ll_storageid
  1919. uo_in.sptname = '发料单车间审核自动进仓/损耗出仓'
  1920. uo_in.relint_3 = outwareid
  1921. //生成相关单据
  1922. cnt++
  1923. If uo_in.acceptmx(cnt,&
  1924. ll_mtrlid,&
  1925. ls_mtrlcode,&
  1926. ls_plancode,&
  1927. ls_status,&
  1928. ld_qty - ld_planqty,&
  1929. ld_cost,&
  1930. ld_rebate,&
  1931. ls_mxdscrp,&
  1932. arg_msg,&
  1933. 0,0,0,&
  1934. ls_woodcode,&
  1935. ls_pcode,0,&
  1936. ls_unit,&
  1937. 1,&
  1938. ld_qty - ld_planqty,&
  1939. 0,0,'','',0,0,'',ls_location,&
  1940. ld_qty - ld_planqty,&
  1941. 0) = 0 Then
  1942. arg_msg = '建立相关自动车间进仓单失败,' + arg_msg
  1943. rslt = 0
  1944. Goto ext
  1945. End If
  1946. If uo_in.Save(False,arg_msg) = 0 Then
  1947. arg_msg = '建立相关自动车间进仓单失败,' + arg_msg
  1948. rslt = 0
  1949. Goto ext
  1950. End If
  1951. ll_relwsinwareid = uo_in.inwareid
  1952. If uo_in.getinfo(scid,ll_relwsinwareid,arg_msg) = 0 Then
  1953. arg_msg = '审核相关自动车间进仓单失败,' + arg_msg
  1954. rslt = 0
  1955. Goto ext
  1956. End If
  1957. If uo_in.auditing(False,arg_msg) = 0 Then
  1958. arg_msg = '审核相关自动车间进仓单失败,' + arg_msg
  1959. rslt = 0
  1960. Goto ext
  1961. End If
  1962. End If
  1963. If ld_wasteqty > 0 Then
  1964. uo_outware uo_out_ws
  1965. uo_out_ws = Create uo_outware
  1966. uo_out_ws.commit_transaction = commit_transaction
  1967. uo_out_ws.if_getid_ture = False
  1968. If uo_out_ws.newbegin(scid,25,arg_msg) = 0 Then
  1969. rslt = 0
  1970. Goto ext
  1971. End If
  1972. uo_out_ws.outdate = server_dt
  1973. uo_out_ws.outrep = publ_operator
  1974. uo_out_ws.part = outwarecode
  1975. uo_out_ws.dscrp = ls_overreason
  1976. uo_out_ws.cusname = '发料单损耗出仓'
  1977. uo_out_ws.storageid = ll_storageid
  1978. Select top 1 u_mtrlware.mtrlwareid,
  1979. u_mtrlware.cost
  1980. Into :ll_mtrlwareid,
  1981. :ld_price
  1982. From u_mtrlware
  1983. Where u_mtrlware.storageid = :ll_storageid
  1984. And u_mtrlware.mtrlid = ll_mtrlid
  1985. And u_mtrlware.status = ls_status
  1986. And u_mtrlware.woodcode = ls_woodcode
  1987. And u_mtrlware.pcode = ls_pcode
  1988. Using commit_transaction;
  1989. If commit_transaction.SQLCode <> 0 Then
  1990. ll_mtrlwareid = 0
  1991. ld_price = 0
  1992. If f_insert_0_mtrlware(ll_mtrlwareid,ll_mtrlid,ls_mtrlcode,ll_storageid,0,ls_status,ls_woodcode,ls_pcode,'','','',0,arg_msg) = 0 Then
  1993. arg_msg = '发料损耗单>>增加车间仓0库存失败,'+arg_msg
  1994. rslt = 0
  1995. Goto ext
  1996. End If
  1997. End If
  1998. If uo_out_ws.acceptmx(ll_mtrlwareid,ld_wasteqty,&
  1999. ld_price,1,'',1,arg_msg,&
  2000. 0,0,0,0,'',0,0,ls_unit,ld_wasteqty,1,'','',0,0,'',0,0,0,0,'','') = 0 Then
  2001. arg_msg = '发料损耗单>>物料'+ls_mtrlcode+','+arg_msg
  2002. rslt = 0
  2003. Goto ext
  2004. End If
  2005. If uo_out_ws.Save(False,arg_msg) = 0 Then
  2006. arg_msg = '自动发料损耗单建立失败,'+arg_msg
  2007. rslt = 0
  2008. Goto ext
  2009. End If
  2010. ll_relwsoutwareid = uo_out_ws.outwareid
  2011. //2.原事务审核出仓单
  2012. If uo_out_ws.getinfo(scid,ll_relwsoutwareid,arg_msg) = 0 Then
  2013. rslt = 0
  2014. Goto ext
  2015. End If
  2016. If uo_out_ws.auditing(False,arg_msg) = 0 Then
  2017. arg_msg = '发料损耗单审核失败,'+arg_msg
  2018. rslt = 0
  2019. Goto ext
  2020. End If
  2021. End If
  2022. End If
  2023. Update u_outwaremx
  2024. Set u_outwaremx.wsauditflag = 1,
  2025. u_outwaremx.wsauditemp = :publ_operator,
  2026. u_outwaremx.wsauditdate = getdate(),
  2027. u_outwaremx.relwsinwareid = :ll_relwsinwareid,
  2028. u_outwaremx.relwsoutwareid = :ll_relwsoutwareid
  2029. Where u_outwaremx.scid = :arg_scid
  2030. And u_outwaremx.outwareid = :arg_outwareid
  2031. And u_outwaremx.printid = :arg_printid Using commit_transaction;
  2032. If commit_transaction.SQLCode <> 0 Then
  2033. rslt = 0
  2034. arg_msg = '更新单据明细车间审状态失败,'+commit_transaction.SQLErrText
  2035. Goto ext
  2036. End If
  2037. ext:
  2038. Destroy uo_in
  2039. Destroy uo_out_ws
  2040. If rslt = 0 Then
  2041. Rollback Using commit_transaction;
  2042. ElseIf rslt = 1 And arg_ifcommit Then
  2043. Commit Using commit_transaction;
  2044. End If
  2045. Return rslt
  2046. end function
  2047. public function integer wscauditing (long arg_scid, long arg_outwareid, long arg_printid, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  2048. DateTime null_dt
  2049. SetNull(null_dt)
  2050. Long ll_relwsinwareid,ll_relwsoutwareid
  2051. Int li_wsauditflag,li_cwauditflag
  2052. //判断选项
  2053. If uo_option_scll_plan_wsaudit = -1000 Then
  2054. arg_msg = '选项:[377]发料单使用明细车间审核流程,读取初始默认值失败,操作取消!'
  2055. rslt = 0
  2056. Goto ext
  2057. End If
  2058. If uo_option_scll_plan_wsaudit = 0 Then
  2059. rslt = 0
  2060. arg_msg = '选项[377]发料单使用明细车间审核流程设为否,不能使用明细车间审核/撤审功能'
  2061. Goto ext
  2062. End If
  2063. //判断单据是否已仓审,是否已做过车间审
  2064. Select u_outwaremx.wsauditflag,
  2065. u_outwaremx.cwauditflag,
  2066. u_outwaremx.relwsinwareid,
  2067. u_outwaremx.relwsoutwareid
  2068. Into :li_wsauditflag,
  2069. :li_cwauditflag,
  2070. :ll_relwsinwareid,
  2071. :ll_relwsoutwareid
  2072. From u_outwaremx Inner JOIN
  2073. u_outware ON u_outwaremx.scid = u_outware.scid And
  2074. u_outwaremx.outwareid = u_outware.outwareid Inner JOIN
  2075. u_mtrldef ON u_outwaremx.mtrlid = u_mtrldef.mtrlid
  2076. Where u_outwaremx.scid = :arg_scid
  2077. And u_outwaremx.outwareid = :arg_outwareid
  2078. And u_outwaremx.printid = :arg_printid Using commit_transaction;
  2079. If commit_transaction.SQLCode <> 0 Then
  2080. rslt = 0
  2081. arg_msg = '查询发料单信息失败,'+commit_transaction.SQLErrText
  2082. Goto ext
  2083. End If
  2084. If li_cwauditflag = 1 Then
  2085. rslt = 0
  2086. arg_msg = '明细已执行财务审,不能撤车间审'
  2087. Goto ext
  2088. End If
  2089. If li_wsauditflag = 0 Then
  2090. rslt = 0
  2091. arg_msg = '明细未进行车间审,不能撤审'
  2092. Goto ext
  2093. End If
  2094. If ll_relwsinwareid > 0 Then
  2095. uo_inware uo_in
  2096. uo_in = Create uo_inware
  2097. uo_in.commit_transaction = commit_transaction
  2098. If uo_in.getinfo(arg_scid,ll_relwsinwareid,arg_msg) = 0 Then
  2099. arg_msg = '删除相关自动车间进仓单失败,' + arg_msg
  2100. rslt = 0
  2101. Goto ext
  2102. End If
  2103. If uo_in.c_auditing(False,arg_msg) = 0 Then
  2104. arg_msg = '删除相关自动车间进仓单失败,' + arg_msg
  2105. rslt = 0
  2106. Goto ext
  2107. End If
  2108. If uo_in.del(arg_scid,ll_relwsinwareid,arg_msg,False) = 0 Then
  2109. arg_msg = '删除相关自动车间进仓单失败,' + arg_msg
  2110. rslt = 0
  2111. Goto ext
  2112. End If
  2113. End If
  2114. If ll_relwsoutwareid > 0 Then
  2115. uo_outware uo_out
  2116. uo_out = Create uo_outware
  2117. uo_out.commit_transaction = commit_transaction
  2118. If uo_out.getinfo(arg_scid,ll_relwsoutwareid,arg_msg) = 0 Then
  2119. arg_msg = '删除相关自动发料损耗单失败,' + arg_msg
  2120. rslt = 0
  2121. Goto ext
  2122. End If
  2123. If uo_out.c_auditing(False,arg_msg) = 0 Then
  2124. arg_msg = '删除相关自动发料损耗单失败,' + arg_msg
  2125. rslt = 0
  2126. Goto ext
  2127. End If
  2128. If uo_out.del(arg_scid,ll_relwsoutwareid,0,arg_msg,False) = 0 Then
  2129. arg_msg = '删除相关自动发料损耗单失败,' + arg_msg
  2130. rslt = 0
  2131. Goto ext
  2132. End If
  2133. End If
  2134. Update u_outwaremx
  2135. Set u_outwaremx.wsauditflag = 0,
  2136. u_outwaremx.wsauditemp = '',
  2137. u_outwaremx.wsauditdate = :null_dt,
  2138. u_outwaremx.relwsinwareid = 0,
  2139. u_outwaremx.relwsoutwareid = 0
  2140. Where u_outwaremx.scid = :arg_scid
  2141. And u_outwaremx.outwareid = :arg_outwareid
  2142. And u_outwaremx.printid = :arg_printid
  2143. Using commit_transaction;
  2144. If commit_transaction.SQLCode <> 0 Then
  2145. rslt = 0
  2146. arg_msg = '更新单据明细车间审状态失败,'+commit_transaction.SQLErrText
  2147. Goto ext
  2148. End If
  2149. ext:
  2150. Destroy uo_in
  2151. Destroy uo_out
  2152. If rslt = 0 Then
  2153. Rollback Using commit_transaction;
  2154. ElseIf rslt = 1 And arg_ifcommit Then
  2155. Commit Using commit_transaction;
  2156. End If
  2157. Return rslt
  2158. end function
  2159. public function integer cauditing_cw (long arg_scid, long arg_outwareid, long arg_printid, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  2160. DateTime null_dt
  2161. SetNull(null_dt)
  2162. Int li_wsauditflag,li_cwauditflag
  2163. //判断选项
  2164. If uo_option_scll_plan_wsaudit = -1000 Then
  2165. arg_msg = '选项:[377]发料单使用明细车间审核流程,读取初始默认值失败,操作取消!'
  2166. rslt = 0
  2167. Goto ext
  2168. End If
  2169. If uo_option_scll_plan_wsaudit = 0 Then
  2170. rslt = 0
  2171. arg_msg = '选项[377]发料单使用明细车间审核流程设为否,不能使用明细财务审核/撤审功能'
  2172. Goto ext
  2173. End If
  2174. //判断单据是否已仓审,是否已做过车间审
  2175. Select u_outwaremx.wsauditflag,
  2176. u_outwaremx.cwauditflag
  2177. Into :li_wsauditflag,
  2178. :li_cwauditflag
  2179. From u_outwaremx Inner JOIN
  2180. u_outware ON u_outwaremx.scid = u_outware.scid And
  2181. u_outwaremx.outwareid = u_outware.outwareid Inner JOIN
  2182. u_mtrldef ON u_outwaremx.mtrlid = u_mtrldef.mtrlid
  2183. Where u_outwaremx.scid = :arg_scid
  2184. And u_outwaremx.outwareid = :arg_outwareid
  2185. And u_outwaremx.printid = :arg_printid Using commit_transaction;
  2186. If commit_transaction.SQLCode <> 0 Then
  2187. rslt = 0
  2188. arg_msg = '查询发料单信息失败,'+commit_transaction.SQLErrText
  2189. Goto ext
  2190. End If
  2191. If li_cwauditflag = 0 Then
  2192. rslt = 0
  2193. arg_msg = '明细未进行财务审,不能撤审'
  2194. Goto ext
  2195. End If
  2196. Update u_outwaremx
  2197. Set u_outwaremx.cwauditflag = 0,
  2198. u_outwaremx.cwauditemp = '',
  2199. u_outwaremx.cwauditdate = :null_dt
  2200. Where u_outwaremx.scid = :arg_scid
  2201. And u_outwaremx.outwareid = :arg_outwareid
  2202. And u_outwaremx.printid = :arg_printid
  2203. Using commit_transaction;
  2204. If commit_transaction.SQLCode <> 0 Then
  2205. rslt = 0
  2206. arg_msg = '更新单据明细财务审状态失败,'+commit_transaction.SQLErrText
  2207. Goto ext
  2208. End If
  2209. ext:
  2210. If rslt = 0 Then
  2211. Rollback Using commit_transaction;
  2212. ElseIf rslt = 1 And arg_ifcommit Then
  2213. Commit Using commit_transaction;
  2214. End If
  2215. Return rslt
  2216. end function
  2217. public function integer auditing_cw (long arg_scid, long arg_outwareid, long arg_printid, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  2218. Int li_flag,li_wsauditflag,li_cwauditflag
  2219. //判断选项
  2220. If uo_option_scll_plan_wsaudit = -1000 Then
  2221. arg_msg = '选项:[377]发料单使用明细车间审核流程,读取初始默认值失败,操作取消!'
  2222. rslt = 0
  2223. Goto ext
  2224. End If
  2225. If uo_option_scll_plan_wsaudit = 0 Then
  2226. rslt = 0
  2227. arg_msg = '选项[377]发料单使用明细车间审核流程设为否,不能使用明细财务审核/撤审功能'
  2228. Goto ext
  2229. End If
  2230. //判断单据是否已仓审,是否已做过车间审
  2231. Select u_outware.flag,
  2232. u_outwaremx.wsauditflag,
  2233. u_outwaremx.cwauditflag
  2234. Into :li_flag,
  2235. :li_wsauditflag,
  2236. :li_cwauditflag
  2237. From u_outwaremx Inner JOIN
  2238. u_outware ON u_outwaremx.scid = u_outware.scid And
  2239. u_outwaremx.outwareid = u_outware.outwareid Inner JOIN
  2240. u_mtrldef ON u_outwaremx.mtrlid = u_mtrldef.mtrlid
  2241. Where u_outwaremx.scid = :arg_scid
  2242. And u_outwaremx.outwareid = :arg_outwareid
  2243. And u_outwaremx.printid = :arg_printid Using commit_transaction;
  2244. If commit_transaction.SQLCode <> 0 Then
  2245. rslt = 0
  2246. arg_msg = '查询发料单信息失败,'+commit_transaction.SQLErrText
  2247. Goto ext
  2248. End If
  2249. If li_flag <> 1 Then
  2250. rslt = 0
  2251. arg_msg = '单据未执行仓审,不能进行车间审'
  2252. Goto ext
  2253. End If
  2254. If li_wsauditflag = 0 Then
  2255. rslt = 0
  2256. arg_msg = '明细未执行车间审,不能财务审'
  2257. Goto ext
  2258. End If
  2259. If li_cwauditflag = 1 Then
  2260. rslt = 0
  2261. arg_msg = '明细已执行过财务审,不能重复执行'
  2262. Goto ext
  2263. End If
  2264. Update u_outwaremx
  2265. Set u_outwaremx.cwauditflag = 1,
  2266. u_outwaremx.cwauditemp = :publ_operator,
  2267. u_outwaremx.cwauditdate = getdate()
  2268. Where u_outwaremx.scid = :arg_scid
  2269. And u_outwaremx.outwareid = :arg_outwareid
  2270. And u_outwaremx.printid = :arg_printid Using commit_transaction;
  2271. If commit_transaction.SQLCode <> 0 Then
  2272. rslt = 0
  2273. arg_msg = '更新单据明细财务审状态失败,'+commit_transaction.SQLErrText
  2274. Goto ext
  2275. End If
  2276. ext:
  2277. If rslt = 0 Then
  2278. Rollback Using commit_transaction;
  2279. ElseIf rslt = 1 And arg_ifcommit Then
  2280. Commit Using commit_transaction;
  2281. End If
  2282. Return rslt
  2283. end function
  2284. on uo_outware_scll.create
  2285. call super::create
  2286. end on
  2287. on uo_outware_scll.destroy
  2288. call super::destroy
  2289. end on
  2290. event constructor;call super::constructor;
  2291. String arg_msg
  2292. String str_optionvalue
  2293. str_optionvalue = ''
  2294. f_get_sys_option_value('057',str_optionvalue,arg_msg)
  2295. uo_option_wkpmtrlware = Long(str_optionvalue)
  2296. str_optionvalue = ''
  2297. f_get_sys_option_value('151',str_optionvalue,arg_msg)
  2298. uo_option_inware_sc_location = Long(str_optionvalue)
  2299. str_optionvalue = ''
  2300. f_get_sys_option_value('355',str_optionvalue,arg_msg)
  2301. uo_option_outware_scll_new_cj_mtrlware = Long(str_optionvalue)
  2302. str_optionvalue = ''
  2303. f_get_sys_option_value('377',str_optionvalue,arg_msg)
  2304. uo_option_scll_plan_wsaudit = Long(str_optionvalue)
  2305. end event