uo_outware_sale.sru 126 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822
  1. $PBExportHeader$uo_outware_sale.sru
  2. forward
  3. global type uo_outware_sale from uo_outware
  4. end type
  5. end forward
  6. global type uo_outware_sale from uo_outware
  7. end type
  8. global uo_outware_sale uo_outware_sale
  9. type variables
  10. Int uo_option_m_msttake
  11. Int uo_option_otheramt_msttake
  12. String uo_option_change_otheramt
  13. Int uo_option_outware_sale_ifmating
  14. Int uo_option_secaudit_notupdate_hisprice
  15. end variables
  16. forward prototypes
  17. public function integer secauditing (boolean arg_ifcommit, ref string arg_msg)
  18. public function integer c_secauditing (boolean arg_ifcommit, ref string arg_msg)
  19. public function integer auditing (boolean arg_ifcommit, ref string arg_msg)
  20. public function integer c_auditing (boolean arg_ifcommit, ref string arg_msg)
  21. public function integer c_priceaudit (long arg_scid, long arg_outwareid, boolean arg_ifcommit, ref string arg_msg)
  22. public function integer uof_create_owe (ref string arg_msg)
  23. public function integer auditing_th (boolean arg_ifcommit, ref string arg_msg)
  24. public function integer c_auditing_th (boolean arg_ifcommit, ref string arg_msg)
  25. public function integer uof_check_pt (ref string arg_msg)
  26. public function integer priceaudit (long arg_scid, long arg_outwareid, boolean arg_ifcommit, ref string arg_msg, string arg_emp)
  27. end prototypes
  28. public function integer secauditing (boolean arg_ifcommit, ref string arg_msg);Long rslt = 1,cnt = 0,i,j
  29. IF uo_option_m_msttake = -1000 THEN
  30. rslt = 0
  31. arg_msg = '选项:[045]系统使用多币种应收帐,读取初始默认值失败,操作取消!'
  32. GOTO ext
  33. END IF
  34. IF uo_option_otheramt_msttake = -1000 THEN
  35. rslt = 0
  36. arg_msg = '选项:[052]优惠金额多币种,读取初始默认值失败,操作取消!'
  37. GOTO ext
  38. END IF
  39. IF uo_option_change_otheramt = '-1000' THEN
  40. rslt = 0
  41. arg_msg = '选项:[050]销售发货单优惠金额文本,读取初始默认值失败,操作取消!'
  42. GOTO ext
  43. END IF
  44. IF uo_option_price_rmb = -1000 THEN
  45. rslt = 0
  46. arg_msg = '选项:[238]销售单价按人民币单价折算,读取初始默认值失败,操作取消!'
  47. GOTO ext
  48. END IF
  49. IF uo_option_secaudit_notupdate_hisprice = -1000 THEN
  50. rslt = 0
  51. arg_msg = '选项:[332]销售发货单财审时不更新客户价格历史,读取初始默认值失败,操作取消!'
  52. GOTO ext
  53. END IF
  54. uo_cusprice uo_update_cusprice
  55. uo_update_cusprice = Create uo_cusprice
  56. uo_musttake uo_take
  57. uo_take = Create uo_musttake
  58. String ls_mtrlname
  59. String ls_about
  60. Decimal ld_takeamt = 0,ld_msttakeamt = 0,ld_taxamt = 0
  61. Long ll_moneyid,ll_moneyid_yh,ll_moneyid_native
  62. Long ll_dft_itemid_take,ll_dft_itemid_yh,ll_dft_itemid_tax
  63. Decimal ld_mrate_amt
  64. Decimal ld_itemamt = 0
  65. String ls_taskdscrp
  66. Decimal ld_taskamt
  67. String ls_taskcode[]
  68. Decimal ld_saletaskamt[]
  69. Long ll_i,k
  70. String ls_itemname
  71. Decimal ld_mrate,ld_mrate_yh
  72. s_bmsttakemx s_takemx_item
  73. IF outwareid = 0 THEN
  74. rslt = 0
  75. arg_msg = "没有审核对象"
  76. GOTO ext
  77. END IF
  78. IF flag = 0 THEN
  79. rslt = 0
  80. arg_msg = "单据还没有经过仓库审核"
  81. GOTO ext
  82. END IF
  83. IF secflag = 1 THEN
  84. rslt = 0
  85. arg_msg = "单据已经过财务审核"
  86. GOTO ext
  87. END IF
  88. Int li_btype
  89. Long ll_accountsid
  90. SELECT btype,accountsid INTO :li_btype,:ll_accountsid
  91. FROM cw_banktype
  92. Where banktypeid = :relint_1 Using commit_transaction;
  93. IF commit_transaction.SQLCode <> 0 THEN
  94. rslt = 0
  95. arg_msg = '查询结算方式类型失败,'+ commit_transaction.SQLErrText
  96. GOTO ext
  97. END IF
  98. SELECT count(*) INTO :cnt
  99. FROM u_user
  100. Where username = :publ_operator Using commit_transaction ;
  101. IF commit_transaction.SQLCode <> 0 THEN
  102. rslt = 0
  103. arg_msg = "查询操作失败,操作员"
  104. GOTO ext
  105. END IF
  106. IF cnt = 0 THEN
  107. rslt = 0
  108. arg_msg = "操作员姓名未登记或已取消"
  109. GOTO ext
  110. END IF
  111. UPDATE u_outware
  112. SET secauditingrep = :publ_operator,
  113. secauditingdate = getdate(),
  114. secflag = 1
  115. WHERE u_outware.outwareid = :outwareid AND
  116. flag = 1 AND secflag = 0
  117. And scid = :scid Using commit_transaction;
  118. IF commit_transaction.SQLCode <> 0 THEN
  119. rslt = 0
  120. arg_msg = "因网络或其它原因导致财务审核单据操作失败"+"~n"+commit_transaction.SQLErrText
  121. GOTO ext
  122. ELSEIF commit_transaction.SQLNRows = 0 THEN
  123. rslt = 0
  124. arg_msg = "单据正在财务审核,请稍后查询。"+"~n"+commit_transaction.SQLErrText
  125. GOTO ext
  126. END IF
  127. IF uo_option_secaudit_notupdate_hisprice = 0 THEN
  128. FOR i = 1 To it_mxbt
  129. IF outwaremx[i].outtype <> '' THEN CONTINUE
  130. IF uo_update_cusprice.uof_update_custprice(thflag,0,cusid,&
  131. outwaremx[i].mtrlid,outwaremx[i].mtrlcode,outwaremx[i].status,&
  132. outwaremx[i].woodcode,outwaremx[i].pcode,&
  133. outwareid,outwarecode,outdate,outwaremx[i].enprice,&
  134. outwaremx[i].rebate,outwaremx[i].costamt,0,'',&
  135. outwaremx[i].printid,0,relint_2,0,0,False,arg_msg) = 0 THEN
  136. rslt = 0
  137. GOTO ext
  138. END IF
  139. NEXT
  140. END IF
  141. FOR j = 1 To it_mxbt_item
  142. IF outware_itemmx[j].IsCusAmt = 1 THEN
  143. ld_itemamt = ld_itemamt + outware_itemmx[j].amt
  144. END IF
  145. NEXT
  146. IF sum_amt <> 0 Or ld_itemamt <> 0 THEN
  147. IF thflag = 1 THEN
  148. ls_about = outwarecode + "退货款,相关号:"+part
  149. SELECT itemid INTO :ll_dft_itemid_take
  150. FROM u_itemdef
  151. Where dfttype = 4 Using commit_transaction;
  152. IF commit_transaction.SQLCode <> 0 THEN
  153. arg_msg = '查询默认销售退货项目资料失败,'+commit_transaction.SQLErrText
  154. rslt = 0
  155. GOTO ext
  156. END IF
  157. ELSE
  158. ls_about = outwarecode + "应收款,相关号:"+part
  159. SELECT itemid INTO :ll_dft_itemid_take
  160. FROM u_itemdef
  161. Where dfttype = 1 Using commit_transaction;
  162. IF commit_transaction.SQLCode <> 0 THEN
  163. arg_msg = '查询默认应收项目资料失败,'+commit_transaction.SQLErrText
  164. rslt = 0
  165. GOTO ext
  166. END IF
  167. END IF
  168. SELECT moneyid INTO :ll_moneyid_native
  169. FROM cw_currency
  170. Where native = 1;
  171. IF sqlca.SQLCode <> 0 THEN
  172. arg_msg = '查询本位币资料失败'
  173. rslt = 0
  174. GOTO ext
  175. END IF
  176. IF uo_option_m_msttake = 0 THEN
  177. ld_msttakeamt = sum_amt
  178. ll_moneyid = ll_moneyid_native
  179. ld_taxamt = sum_taxamt
  180. ld_mrate = 1
  181. ELSE
  182. ld_msttakeamt = sum_amt_en
  183. ll_moneyid = relint_2
  184. ld_taxamt = sum_taxamt_en
  185. IF uo_option_price_rmb = 0 THEN
  186. ld_mrate = mrate
  187. ELSE
  188. ld_mrate = Round(sum_amt/sum_amt_en,10)
  189. END IF
  190. END IF
  191. IF otheramt <> 0 THEN
  192. IF uo_option_otheramt_msttake = 1 THEN
  193. ld_mrate_amt = otheramt * mrate
  194. ll_moneyid_yh = ll_moneyid_native
  195. ld_mrate_yh = mrate
  196. ELSE
  197. ld_mrate_amt = otheramt
  198. ll_moneyid_yh = relint_2
  199. ld_mrate_yh = 1
  200. END IF
  201. END IF
  202. IF li_btype = 1 THEN
  203. ld_takeamt = ld_msttakeamt - ld_mrate_amt + ld_itemamt
  204. ELSE
  205. ld_takeamt = 0
  206. END IF
  207. ll_i = 0
  208. FOR i = 1 To it_mxbt
  209. IF outwaremx[i].ifrel = 1 THEN
  210. IF uo_option_m_msttake = 0 THEN
  211. ld_taskamt = outwaremx[i].saleqty * outwaremx[i].price / (1 + outwaremx[i].taxrate) //计算单据总金额
  212. ELSE
  213. ld_taskamt = outwaremx[i].saleqty * outwaremx[i].rebate * outwaremx[i].enprice / (1 + outwaremx[i].taxrate) //计算单据总金额
  214. END IF
  215. FOR j = 1 To ll_i
  216. IF ls_taskcode[j] = outwaremx[i].relcode THEN
  217. ld_saletaskamt[j] = ld_saletaskamt[j] + ld_taskamt
  218. GOTO exit_for
  219. END IF
  220. NEXT
  221. ll_i++
  222. ls_taskcode[ll_i] = outwaremx[i].relcode
  223. ld_saletaskamt[ll_i] = ld_taskamt
  224. END IF
  225. exit_for:
  226. NEXT
  227. FOR k = 1 To ll_i
  228. ls_taskdscrp = ls_taskdscrp + '订单'+ls_taskcode[k]+'金额:'+String(ld_saletaskamt[k],'#,##0.00')+','
  229. NEXT
  230. IF sum_amt <> 0 THEN
  231. s_bmsttake s_take
  232. s_take.scid = scid
  233. s_take.cusid = cusid
  234. s_take.takedate = outdate
  235. s_take.inrep = outrep
  236. s_take.oriamt = ld_msttakeamt
  237. s_take.msttakeamt = ld_msttakeamt
  238. s_take.takeamt = ld_takeamt
  239. s_take.takeamt_cn = ld_takeamt
  240. s_take.dscrp = ls_about
  241. s_take.billcode = outwarecode
  242. s_take.relcode = part
  243. s_take.banktypeid = relint_1
  244. s_take.opemp = publ_operator
  245. s_take.buildtype = 1
  246. s_take.outwareid = outwareid
  247. s_take.accountsid = ll_accountsid
  248. s_take.itemid = ll_dft_itemid_take
  249. s_take.moneyid = ll_moneyid
  250. s_take.moneyid_cn = ll_moneyid
  251. s_take.viewdate = viewdate
  252. s_take.taskdscrp = ls_taskdscrp
  253. s_take.mrate = ld_mrate
  254. s_take.exchangeid = exchangeid
  255. IF uo_take.add_takerec(s_take,arg_msg,False) = 0 THEN
  256. rslt = 0
  257. GOTO ext
  258. END IF
  259. IF otheramt <> 0 THEN
  260. ls_about = outwarecode + uo_option_change_otheramt +",相关号:"+part
  261. SELECT itemid INTO :ll_dft_itemid_yh
  262. FROM u_itemdef
  263. Where dfttype = 3 Using commit_transaction;
  264. IF commit_transaction.SQLCode <> 0 THEN
  265. arg_msg = '查询默认优惠项目资料失败'
  266. rslt = 0
  267. GOTO ext
  268. END IF
  269. s_bmsttakemx s_takemx
  270. s_takemx.scid = scid
  271. s_takemx.takeid = uo_take.ref_takeid
  272. s_takemx.cusid = cusid
  273. s_takemx.takedate = outdate
  274. s_takemx.inrep = outrep
  275. s_takemx.msttakeamt = 0 - ld_mrate_amt
  276. s_takemx.takeamt = 0
  277. s_takemx.dscrp = ls_about
  278. s_takemx.billcode = outwarecode
  279. s_takemx.relcode = part
  280. s_takemx.banktypeid = relint_1
  281. s_takemx.opemp = publ_operator
  282. s_takemx.buildtype = 3
  283. s_takemx.outwareid = outwareid
  284. s_takemx.salebillid = 0
  285. s_takemx.itemid = ll_dft_itemid_yh
  286. s_takemx.moneyid = ll_moneyid_yh
  287. s_takemx.mrate = ld_mrate_yh
  288. IF uo_take.add_takerecmx(s_takemx,arg_msg,False) = 0 THEN
  289. rslt = 0
  290. GOTO ext
  291. END IF
  292. END IF
  293. IF ld_taxamt <> 0 THEN
  294. ls_about = outwarecode + "销售税金,相关号:"+part
  295. SELECT itemid INTO :ll_dft_itemid_tax
  296. FROM u_itemdef
  297. Where dfttype = 12 Using commit_transaction;
  298. IF commit_transaction.SQLCode <> 0 THEN
  299. arg_msg = '查询默认销售税金项目资料失败,'+commit_transaction.SQLErrText
  300. rslt = 0
  301. GOTO ext
  302. END IF
  303. s_bmsttakemx s_takemx_tax
  304. s_takemx_tax.scid = scid
  305. s_takemx_tax.takeid = uo_take.ref_takeid
  306. s_takemx_tax.cusid = cusid
  307. s_takemx_tax.takedate = outdate
  308. s_takemx_tax.inrep = outrep
  309. s_takemx_tax.msttakeamt = ld_taxamt
  310. s_takemx_tax.takeamt = 0
  311. s_takemx_tax.dscrp = ls_about
  312. s_takemx_tax.billcode = outwarecode
  313. s_takemx_tax.relcode = part
  314. s_takemx_tax.banktypeid = relint_1
  315. s_takemx_tax.opemp = publ_operator
  316. s_takemx_tax.buildtype = 3
  317. s_takemx_tax.outwareid = outwareid
  318. s_takemx_tax.salebillid = 0
  319. s_takemx_tax.itemid = ll_dft_itemid_tax
  320. s_takemx_tax.moneyid = ll_moneyid
  321. s_takemx_tax.mrate = ld_mrate
  322. IF uo_take.add_takerecmx(s_takemx_tax,arg_msg,False) = 0 THEN
  323. rslt = 0
  324. GOTO ext
  325. END IF
  326. END IF
  327. END IF
  328. FOR i = 1 To it_mxbt_item
  329. IF outware_itemmx[i].amt <> 0 THEN
  330. SELECT itemname
  331. INTO :ls_itemname
  332. FROM u_itemdef
  333. Where itemid = :outware_itemmx[i].itemid Using commit_transaction;
  334. IF commit_transaction.SQLCode <> 0 THEN
  335. rslt = 0
  336. arg_msg = '查询第'+String(i)+'行费用项目信息失败,'+ commit_transaction.SQLErrText
  337. GOTO ext
  338. END IF
  339. IF sum_amt = 0 And i = 1 THEN
  340. ls_about = outwarecode + '费用项目金额,相关号:'+part
  341. s_bmsttake s_take_it
  342. s_take_it.scid = scid
  343. s_take_it.cusid = cusid
  344. s_take_it.takedate = outdate
  345. s_take_it.inrep = outrep
  346. s_take_it.oriamt = outware_itemmx[i].amt
  347. s_take_it.msttakeamt = outware_itemmx[i].amt
  348. s_take_it.takeamt = 0
  349. s_take_it.takeamt_cn = 0
  350. s_take_it.dscrp = ls_about
  351. s_take_it.billcode = outwarecode
  352. s_take_it.relcode = part
  353. s_take_it.banktypeid = relint_1
  354. s_take_it.opemp = publ_operator
  355. s_take_it.buildtype = 1
  356. s_take_it.outwareid = outwareid
  357. s_take_it.accountsid = ll_accountsid
  358. s_take_it.itemid = ll_dft_itemid_take
  359. s_take_it.moneyid = ll_moneyid
  360. s_take_it.moneyid_cn = ll_moneyid
  361. s_take_it.viewdate = viewdate
  362. s_take_it.taskdscrp = ls_taskdscrp
  363. s_take_it.mrate = ld_mrate
  364. IF uo_take.add_takerec(s_take_it,arg_msg,False) = 0 THEN
  365. rslt = 0
  366. GOTO ext
  367. END IF
  368. ELSE
  369. ls_about = outwarecode + '费用项目:'+ls_itemname +",相关号:"+part
  370. s_takemx_item.scid = scid
  371. s_takemx_item.takeid = uo_take.ref_takeid
  372. s_takemx_item.cusid = cusid
  373. s_takemx_item.takedate = outdate
  374. s_takemx_item.inrep = outrep
  375. s_takemx_item.msttakeamt = outware_itemmx[i].amt
  376. s_takemx_item.takeamt = 0
  377. s_takemx_item.dscrp = ls_about
  378. s_takemx_item.billcode = outwarecode
  379. s_takemx_item.relcode = part
  380. s_takemx_item.banktypeid = relint_1
  381. s_takemx_item.opemp = publ_operator
  382. s_takemx_item.buildtype = 3
  383. s_takemx_item.outwareid = outwareid
  384. s_takemx_item.salebillid = 0
  385. s_takemx_item.itemid = outware_itemmx[i].itemid
  386. s_takemx_item.moneyid = ll_moneyid
  387. s_takemx_item.mrate = ld_mrate
  388. IF uo_take.add_takerecmx(s_takemx_item,arg_msg,False) = 0 THEN
  389. rslt = 0
  390. GOTO ext
  391. END IF
  392. END IF
  393. END IF
  394. NEXT
  395. UPDATE u_outware
  396. SET relint_3 = :uo_take.ref_takeid
  397. WHERE u_outware.outwareid = :outwareid
  398. AND scid = :scid
  399. AND flag = 1
  400. And secflag = 1 Using commit_transaction;
  401. IF commit_transaction.SQLCode <> 0 THEN
  402. arg_msg = '更新相关应收帐id失败'
  403. rslt = 0
  404. GOTO ext
  405. END IF
  406. END IF
  407. secflag = 1
  408. ext:
  409. IF rslt = 0 THEN
  410. ROLLBACK Using commit_transaction;
  411. ELSEIF rslt = 1 And arg_ifcommit THEN
  412. COMMIT Using commit_transaction;
  413. END IF
  414. Destroy uo_update_cusprice
  415. Destroy uo_take
  416. RETURN rslt
  417. end function
  418. public function integer c_secauditing (boolean arg_ifcommit, ref string arg_msg);Long rslt = 1,cnt = 0,i,j
  419. uo_musttake uo_take
  420. uo_take = Create uo_musttake
  421. uo_cusprice uo_update_cusprice
  422. uo_update_cusprice = Create uo_cusprice
  423. IF uo_option_secaudit_notupdate_hisprice = -1000 THEN
  424. rslt = 0
  425. arg_msg = '选项:[332]销售发货单财审时不更新客户价格历史,读取初始默认值失败,操作取消!'
  426. GOTO ext
  427. END IF
  428. String ls_mtrlname
  429. String ls_cusname
  430. DateTime null_datetime
  431. Long ll_takeid
  432. Decimal ld_itemamt
  433. int li_StoreBalcType,li_AmtAuditFlag
  434. IF outwareid = 0 THEN
  435. rslt = 0
  436. arg_msg = "没有撤审对象"
  437. GOTO ext
  438. END IF
  439. IF ctmint > 0 THEN
  440. arg_msg = '单据已截数,不能操作'
  441. rslt = 0
  442. GOTO ext
  443. END IF
  444. IF secflag = 0 THEN
  445. rslt = 0
  446. arg_msg = "该单据财务未审,不能进行财务撤审"
  447. GOTO ext
  448. END IF
  449. //检查仓库是否分开结存
  450. IF balcdateint <> 0 THEN
  451. SELECT StoreBalcType
  452. INTO :li_StoreBalcType
  453. FROM u_storage
  454. Where storageid = :storageid;
  455. IF sqlca.SQLCode <> 0 THEN
  456. li_StoreBalcType = 0
  457. END IF
  458. //如果分开结存,检查结存表是否已金额结存
  459. IF li_StoreBalcType = 1 THEN
  460. SELECT top 1 AmtAuditFlag
  461. INTO :li_AmtAuditFlag
  462. FROM u_warebalc
  463. WHERE storageid = :storageid
  464. And balcdateint = :balcdateint;
  465. IF sqlca.SQLCode <> 0 THEN
  466. li_AmtAuditFlag = 0
  467. END IF
  468. IF li_AmtAuditFlag = 1 THEN
  469. rslt = 0
  470. arg_msg = '仓库结存日期段已执行过金额结存,不能财撤单据'
  471. GOTO ext
  472. END IF
  473. END IF
  474. END IF
  475. SELECT count(*) INTO :cnt
  476. FROM u_user
  477. Where username = :publ_operator Using commit_transaction ;
  478. IF commit_transaction.SQLCode <> 0 THEN
  479. rslt = 0
  480. arg_msg = "查询操作失败,操作员"
  481. GOTO ext
  482. END IF
  483. IF cnt = 0 THEN
  484. rslt = 0
  485. arg_msg = "操作员姓名未登记或已取消"
  486. GOTO ext
  487. END IF
  488. SetNull(null_datetime)
  489. UPDATE u_outware
  490. SET secAuditingrep = '',
  491. secAuditingdate = :null_datetime,
  492. secflag = 0,
  493. relint_3 = 0
  494. WHERE u_outware.outwareid = :outwareid
  495. And scid = :scid Using commit_transaction;
  496. IF commit_transaction.SQLCode <> 0 THEN
  497. rslt = 0
  498. arg_msg = "因网络或其它原因导致财务审核单据操作失败"+"~n"+commit_transaction.SQLErrText
  499. GOTO ext
  500. ELSEIF commit_transaction.SQLNRows = 0 THEN
  501. rslt = 0
  502. arg_msg = "单据正在财务撤审,请稍后查询。"+"~n"+commit_transaction.SQLErrText
  503. GOTO ext
  504. END IF
  505. IF uo_option_secaudit_notupdate_hisprice = 0 THEN
  506. FOR i = 1 To it_mxbt
  507. IF outwaremx[i].outtype <> '' THEN CONTINUE
  508. IF uo_update_cusprice.uof_del_cusprice_auto(cusid,outwareid,&
  509. outwaremx[i].printid,outwaremx[i].mtrlid,outwaremx[i].status,&
  510. outwaremx[i].woodcode,outwaremx[i].pcode,&
  511. 0,relint_2,0,0,False,arg_msg) = 0 THEN
  512. rslt = 0
  513. GOTO ext
  514. END IF
  515. NEXT
  516. END IF
  517. FOR j = 1 To it_mxbt_item
  518. IF outware_itemmx[j].IsCusAmt = 1 THEN
  519. ld_itemamt = ld_itemamt + outware_itemmx[j].amt
  520. END IF
  521. NEXT
  522. If (sum_amt <> 0 Or ld_itemamt <> 0) And relint_3 <> 0 THEN
  523. IF uo_take.del_takerec(scid,1,relint_3,cusid,arg_msg,False) = 0 THEN
  524. rslt = 0
  525. GOTO ext
  526. END IF
  527. END IF
  528. secflag = 0
  529. ext:
  530. IF rslt = 0 THEN
  531. ROLLBACK Using commit_transaction;
  532. ELSEIF rslt = 1 And arg_ifcommit THEN
  533. COMMIT Using commit_transaction;
  534. END IF
  535. Destroy uo_take
  536. Destroy uo_update_cusprice
  537. RETURN rslt
  538. end function
  539. public function integer auditing (boolean arg_ifcommit, ref string arg_msg);Int rslt = 1
  540. Long cnt = 0,i,j,mx_barcode_cnt,k
  541. Long chc
  542. Long rst_outwareid //
  543. Long rst_inwareid //
  544. Long ll_i,ll_j,ll_k,ll_l
  545. Int li_ifpack,li_ifunit,li_ifpackpro
  546. Int li_ifpackcnt,li_ifpackprocnt
  547. Decimal ld_rate,ld_uqty,ld_rate_buy
  548. Decimal ld_fprice,ld_uprice,ld_planprice
  549. String ls_uunit,ls_unit_buy,ls_unit
  550. Long ll_storageid_arr[]
  551. //
  552. Decimal ld_assign_outqty,ld_sumnotoutqty,ld_sumnotoutqty_bill
  553. Long ll_row
  554. Long ll_pda_hh
  555. Int li_ifvqty
  556. uo_cmpl_packpro uo_pack
  557. uo_pack = Create uo_cmpl_packpro
  558. uo_pack.commit_transaction = commit_transaction
  559. s_inwaremx s_mx
  560. s_outwaremx s_mx_out
  561. ins_ref_outwaremx = ins_empty_outwaremx
  562. ins_ref_mxbt = 0
  563. If f_aps_mrp_cklock(scid,arg_msg) = 0 Then
  564. rslt = 0
  565. Goto ext
  566. End If
  567. If uo_option_confirmaudit_sale = -1000 Then
  568. rslt = 0
  569. arg_msg = '选项:[025]销售单先确认后审核,读取初始默认值失败,操作取消!'
  570. Goto ext
  571. End If
  572. If uo_option_outware_saleout = -1000 Then
  573. rslt = 0
  574. arg_msg = '选项:[147]使用销售出仓单,读取初始默认值失败,操作取消!'
  575. Goto ext
  576. End If
  577. If uo_option_outware_sale_ifmating = -1000 Then
  578. rslt = 0
  579. arg_msg = '选项:[188]销售发货单仓审时是否检查配套出仓,读取初始默认值失败,操作取消!'
  580. Goto ext
  581. End If
  582. If uo_option_pda_sale_lock = -1000 Then
  583. rslt = 0
  584. arg_msg = '选项:[310]PDA销售发货加锁,读取初始默认值失败,操作取消!'
  585. Goto ext
  586. End If
  587. If uo_option_canpack_ifzanyong = -1000 Then
  588. rslt = 0
  589. arg_msg = '选项:[417]通用包件产品可装数选项,读取初始默认值失败,操作取消!'
  590. Goto ext
  591. End If
  592. uo_sqlpro uo_pro
  593. uo_pro = Create uo_sqlpro
  594. uo_pro.commit_transaction = commit_transaction
  595. uo_saletask uo_task
  596. uo_task = Create uo_saletask
  597. uo_task.commit_transaction = commit_transaction
  598. uo_saleout uo_sout
  599. uo_sout = Create uo_saleout
  600. uo_sout.commit_transaction = commit_transaction
  601. uo_mtrlware_assign uo_ma
  602. uo_ma = Create uo_mtrlware_assign
  603. uo_ma.commit_transaction = commit_transaction
  604. //库存分配ds
  605. datastore ds_out_assign
  606. ds_out_assign = Create datastore
  607. ds_out_assign.DataObject = 'ds_outwaremx_assign'
  608. ds_out_assign.SetTransObject(commit_transaction)
  609. If outwareid = 0 Then
  610. rslt = 0
  611. arg_msg = "没有审核对象"
  612. Goto ext
  613. End If
  614. If storageid = 0 Then
  615. rslt = 0
  616. arg_msg = '没有正确的仓库'
  617. Goto ext
  618. End If
  619. If billtype <> 9 Then
  620. If uof_check_warepdb_audit(storageid,arg_msg) = 0 Then
  621. rslt = 0
  622. Goto ext
  623. End If
  624. End If
  625. String ls_storagename
  626. Int li_outtype_storage,li_storagetype
  627. Select storagename,outtype,storagetype
  628. Into :ls_storagename,:li_outtype_storage,:li_storagetype
  629. From u_storage
  630. Where storageid = :storageid Using commit_transaction ;
  631. If commit_transaction.SQLCode <> 0 Then
  632. rslt = 0
  633. arg_msg = "查询操作失败,仓库"
  634. Goto ext
  635. End If
  636. //检查是否有该仓库的建立权限
  637. If sys_user_storagestr_audit <> '0' Then
  638. If Pos(sys_user_storagestr_audit,','+String(storageid)+',') <= 0 Then
  639. rslt = 0
  640. arg_msg = '没有仓库: '+ls_storagename+' 的审核权限,不允许审核该仓库的单据'
  641. Goto ext
  642. End If
  643. End If
  644. //
  645. If flag = 1 Then
  646. rslt = 0
  647. arg_msg = "单据已经审核"
  648. Goto ext
  649. End If
  650. //yyx2013-4-3
  651. If f_power_ind(3715,sys_msg_pow) And Not sys_power_issuper Then
  652. For i = 1 To it_mxbt
  653. If outwaremx[i].qty <> outwaremx[i].planqty Then
  654. arg_msg = '有实发数与计划发货数不相等的发货明细,你没有权限操作'
  655. rslt = 0
  656. Goto ext
  657. End If
  658. Next
  659. End If
  660. //
  661. If uo_option_pda_sale_lock = 1 And uo_option_inout_type = 2 And li_outtype_storage = 2 Then
  662. If pda_flag = 1 Then
  663. Select Top 1 DATEDIFF(hh, :pda_date, getdate()) Into :ll_pda_hh From u_user Using commit_transaction;
  664. If commit_transaction.SQLCode <> 0 Then
  665. rslt = 0
  666. arg_msg = "查询单据条码扫描开始时间与当前时间的小时间隔失败,"+commit_transaction.SQLErrText
  667. Goto ext
  668. End If
  669. If ll_pda_hh < 4 Then
  670. rslt = 0
  671. arg_msg = "单据正在扫描条码,不能仓审单据,操作取消"
  672. Goto ext
  673. End If
  674. End If
  675. End If
  676. If uo_option_confirmaudit_sale = 1 Then
  677. If priceflag = 0 Then
  678. rslt = 0
  679. arg_msg = "销售单要确认后才能审核"
  680. Goto ext
  681. End If
  682. End If
  683. //检查配套
  684. If uo_option_outware_sale_ifmating = 1 And li_outtype_storage > 0 Then
  685. If uof_check_pt(arg_msg) = 0 Then
  686. rslt = 0
  687. Goto ext
  688. End If
  689. End If
  690. Update u_outware
  691. Set Auditingrep = :publ_operator,
  692. Auditingdate = getdate(),
  693. flag = 1,
  694. carflag = 1
  695. Where u_outware.outwareid = :outwareid
  696. And flag = 0
  697. And scid = :scid Using commit_transaction;
  698. If commit_transaction.SQLCode <> 0 Then
  699. rslt = 0
  700. arg_msg = "因网络或其它原因导致审核单据操作失败"+"~n"+commit_transaction.SQLErrText
  701. Goto ext
  702. ElseIf commit_transaction.SQLNRows = 0 Then
  703. rslt = 0
  704. arg_msg = "单据正在审核,请稍后查询。"+"~n"+commit_transaction.SQLErrText
  705. Goto ext
  706. End If
  707. uo_inware uo_in
  708. uo_outware uo_out
  709. uo_in = Create uo_inware
  710. uo_in.commit_transaction = sqlca
  711. uo_in.if_getid_ture = False
  712. uo_out = Create uo_outware
  713. uo_out.commit_transaction = sqlca
  714. uo_out.if_getid_ture = False
  715. If li_outtype_storage <> 0 And uo_option_outware_saleout = 0 Then
  716. //yyx20120906包件产品先更新分配出仓数
  717. For i = 1 To it_mxbt
  718. //yyx20120825
  719. //仓库是用库存分配,(包件出仓或条码出仓),包件产品扣分配,包件在销售出仓单做
  720. If billtype = 1 And li_storagetype = 1 And li_outtype_storage > 0 And ( outwaremx[i].ifpackpro > 0 And outwaremx[i].ifpackpro <> 4 Or outwaremx[i].ifpackpro = 4 And (Pos(outwaremx[i].status,'+') > 0 Or Pos(outwaremx[i].status,'*') > 0)) And outwaremx[i].relid > 0 Then
  721. ll_row = ds_out_assign.Retrieve(scid,outwaremx[i].mtrlwareid,outwaremx[i].relid,outwaremx[i].relprintid)
  722. ds_out_assign.AcceptText()
  723. If ll_row <= 0 Then
  724. ld_sumnotoutqty = 0
  725. Else
  726. ld_sumnotoutqty = ds_out_assign.Object.sumnotoutqty[1]
  727. End If
  728. ld_sumnotoutqty_bill = 0
  729. ld_sumnotoutqty_bill = outwaremx[i].qty
  730. If ld_sumnotoutqty > 0 And ld_sumnotoutqty_bill > 0 Then
  731. ld_assign_outqty = 0
  732. For j = 1 To ds_out_assign.RowCount()
  733. If ds_out_assign.Object.notoutqty[j] >= ld_sumnotoutqty_bill Then
  734. ld_assign_outqty = ld_sumnotoutqty_bill
  735. If uo_ma.uof_assign_addoutqty(ds_out_assign.Object.assignid[j],ld_assign_outqty,arg_msg,False) = 0 Then
  736. arg_msg = '物料:'+outwaremx[i].mtrlcode+',销售发货单(发货明细)行:'+String(i)+','+arg_msg
  737. rslt = 0
  738. Goto ext
  739. End If
  740. Exit
  741. Else
  742. ld_assign_outqty = ds_out_assign.Object.notoutqty[j]
  743. If uo_ma.uof_assign_addoutqty(ds_out_assign.Object.assignid[j],ld_assign_outqty,arg_msg,False) = 0 Then
  744. arg_msg = '物料:'+outwaremx[i].mtrlcode+',销售发货单(发货明细)行:'+String(i)+','+arg_msg
  745. rslt = 0
  746. Goto ext
  747. End If
  748. ld_sumnotoutqty_bill = ld_sumnotoutqty_bill - ds_out_assign.Object.notoutqty[j]
  749. End If
  750. Next
  751. End If
  752. End If
  753. //end_20120825
  754. Next
  755. //yyx20120906
  756. cnt = 1
  757. For ll_i = 1 To it_mxbt_mx
  758. If ll_i = 1 Then
  759. ll_storageid_arr[cnt] = outwaremx_mx[ll_i].storageid
  760. Goto _next
  761. End If
  762. For ll_j = 1 To cnt
  763. If ll_storageid_arr[ll_j] = outwaremx_mx[ll_i].storageid Then
  764. Goto _next
  765. End If
  766. Next
  767. cnt++
  768. ll_storageid_arr[cnt] = outwaremx_mx[ll_i].storageid
  769. _next:
  770. Next
  771. For ll_i = 1 To cnt
  772. If uo_out.newbegin(scid,21,arg_msg) = 0 Then
  773. rslt = 0
  774. Goto ext
  775. End If
  776. uo_out.relid = outwareid
  777. uo_out.outdate = outdate
  778. uo_out.outrep = outrep
  779. uo_out.part = outwarecode
  780. uo_out.dscrp = dscrp
  781. uo_out.cusname = '销售发货单包件明细自动出仓'
  782. uo_out.storageid = ll_storageid_arr[ll_i]
  783. chc = 0
  784. For i = 1 To it_mxbt_mx
  785. If outwaremx_mx[i].storageid <> ll_storageid_arr[ll_i] Then Continue
  786. Select ifpack,ifunit,unit,rate_buy,unit_buy
  787. Into :li_ifpack,:li_ifunit,:ls_unit,:ld_rate_buy,:ls_unit_buy
  788. From u_mtrldef
  789. Where mtrlid = :outwaremx_mx[i].mtrlid;
  790. If commit_transaction.SQLCode <> 0 Then
  791. rslt = 0
  792. arg_msg = '销售发货单(包件明细)'+String(i)+",查询应发明细操作失败"+"~n"+commit_transaction.SQLErrText
  793. Goto ext
  794. End If
  795. f_get_planprice_mtrl(outwaremx_mx[i].mtrlid,outwaremx_mx[i].status,outwaremx_mx[i].woodcode,outwaremx_mx[i].pcode,ld_fprice)
  796. chc++
  797. If li_ifunit = 0 Then
  798. ls_uunit = ls_unit
  799. ld_rate = 1
  800. ld_uqty = outwaremx_mx[i].qty
  801. Else
  802. If ld_rate_buy = 0 Then
  803. arg_msg = '销售发货单(包件明细)'+String(i)+',资料设为双数量核算,但没有设置默认转换率,请检查'
  804. rslt = 0
  805. Goto ext
  806. End If
  807. ls_uunit = ls_unit_buy
  808. ld_rate = ld_rate_buy
  809. ld_uqty = outwaremx_mx[i].qty /ld_rate_buy
  810. End If
  811. li_ifvqty = 0
  812. For k = 1 To it_mxbt
  813. If outwaremx[k].printid = outwaremx_mx[i].printid Then
  814. If outwaremx[k].mtrlid = outwaremx_mx[i].mtrlid And &
  815. outwaremx[k].status = outwaremx_mx[i].status And &
  816. outwaremx[k].woodcode = outwaremx_mx[i].woodcode And &
  817. outwaremx[k].pcode = outwaremx_mx[i].pcode Then
  818. li_ifvqty = 1
  819. Else
  820. li_ifvqty = 0
  821. End If
  822. Exit
  823. End If
  824. Next
  825. s_mx_out.mtrlwareid = outwaremx_mx[i].mtrlwareid
  826. s_mx_out.qty = outwaremx_mx[i].qty
  827. s_mx_out.fprice = ld_fprice
  828. s_mx_out.rebate = 1
  829. s_mx_out.mxdscrp = outwaremx_mx[i].mxdscrp
  830. s_mx_out.printid = chc
  831. s_mx_out.ifrel = 0
  832. s_mx_out.relid = 0
  833. s_mx_out.olmtrlid = outwaremx_mx[i].printid
  834. s_mx_out.packqty = 0
  835. s_mx_out.outtype = ''
  836. s_mx_out.planqty = 0
  837. s_mx_out.relprintid = outwaremx_mx[i].mxprintid
  838. s_mx_out.unit = ls_uunit
  839. s_mx_out.uqty = ld_uqty
  840. s_mx_out.rate = ld_rate
  841. s_mx_out.pricetype = ''
  842. s_mx_out.formula = ''
  843. s_mx_out.saleoutid = 0
  844. s_mx_out.saleoutprintid = 0
  845. s_mx_out.mxdscrp2 = ''
  846. s_mx_out.net_weight = 0
  847. s_mx_out.gross_weight = 0
  848. s_mx_out.cubage = 0
  849. s_mx_out.taxrate = 0
  850. s_mx_out.priceformula = ''
  851. s_mx_out.qtyformula = ''
  852. s_mx_out.ifvqty = li_ifvqty
  853. s_mx_out.ifnotinout = outwaremx_mx[i].ifnotinout
  854. If uo_out.acceptmx(s_mx_out,arg_msg) = 0 Then
  855. arg_msg = '销售发货单(包件明细)'+String(i)+','+arg_msg
  856. rslt = 0
  857. Goto ext
  858. End If
  859. // IF uo_out.acceptmx(outwaremx_mx[i].mtrlwareid,&
  860. // outwaremx_mx[i].qty,ld_fprice,1,&
  861. // outwaremx_mx[i].mxdscrp,chc,arg_msg,0,0,outwaremx_mx[i].printid,0,'',0,outwaremx_mx[i].mxprintid,&
  862. // ls_uunit,ld_uqty,ld_rate,'','',0,0,'',0,0,0,0,'','') = 0 THEN
  863. // arg_msg = '销售发货单(包件明细)'+String(i)+','+arg_msg
  864. // rslt = 0
  865. // GOTO ext
  866. // END IF
  867. Next
  868. If uo_out.Save(False,arg_msg) = 0 Then
  869. arg_msg = '销售发货单(包件明细),'+arg_msg
  870. rslt = 0
  871. Goto ext
  872. End If
  873. rst_outwareid = uo_out.outwareid
  874. //2.原事务审核出仓单
  875. If uo_out.getinfo(scid,rst_outwareid,arg_msg) = 0 Then
  876. arg_msg = '销售发货单(包件明细),'+arg_msg
  877. rslt = 0
  878. Goto ext
  879. End If
  880. If uo_out.auditing(False,arg_msg) = 0 Then
  881. arg_msg = '销售发货单(包件明细),'+arg_msg
  882. rslt = 0
  883. Goto ext
  884. End If
  885. If uo_option_noauditingqty_mode = 1 Then
  886. If UpperBound(uo_out.ins_ref_outwaremx) > 0 Then
  887. For ll_l = 1 To UpperBound(uo_out.ins_ref_outwaremx)
  888. ins_ref_mxbt++
  889. ins_ref_outwaremx[ins_ref_mxbt].mtrlid = uo_out.ins_ref_outwaremx[ll_l].mtrlid
  890. ins_ref_outwaremx[ins_ref_mxbt].plancode = uo_out.ins_ref_outwaremx[ll_l].plancode
  891. ins_ref_outwaremx[ins_ref_mxbt].mtrlcuscode = uo_out.ins_ref_outwaremx[ll_l].mtrlcuscode
  892. ins_ref_outwaremx[ins_ref_mxbt].storageid = uo_out.storageid
  893. Next
  894. End If
  895. End If
  896. Next
  897. If uo_in.newbegin(scid,23,arg_msg) = 0 Then
  898. rslt = 0
  899. Goto ext
  900. End If
  901. uo_in.relid = outwareid
  902. uo_in.indate = outdate
  903. uo_in.inrep = outrep
  904. uo_in.part = outwarecode
  905. uo_in.dscrp = dscrp
  906. uo_in.sptname = '销售发货单发货明细包件产品自动进仓'
  907. uo_in.storageid = storageid
  908. chc = 0
  909. For i = 1 To it_mxbt
  910. Select ifpackpro,ifunit,unit,rate_buy,unit_buy
  911. Into :li_ifpackpro,:li_ifunit,:ls_unit,:ld_rate_buy,:ls_unit_buy
  912. From u_mtrldef
  913. Where mtrlid = :outwaremx[i].mtrlid;
  914. If commit_transaction.SQLCode <> 0 Then
  915. rslt = 0
  916. arg_msg = '销售发货单(发货明细)行:'+String(i)+','+"查询应发明细操作失败"+"~n"+commit_transaction.SQLErrText
  917. Goto ext
  918. End If
  919. chc++
  920. f_get_planprice_mtrl(outwaremx[i].mtrlid,outwaremx[i].status,outwaremx[i].woodcode,outwaremx[i].pcode,ld_planprice)
  921. If li_ifpackpro = 0 Then
  922. Select cost Into :ld_fprice
  923. From u_mtrlware
  924. Where mtrlwareid = :outwaremx[i].mtrlwareid
  925. And scid = :scid;
  926. If commit_transaction.SQLCode <> 0 Then
  927. rslt = 0
  928. arg_msg = '销售发货单(发货明细)行:'+String(i)+','+"查询库存成本价操作失败"+"~n"+commit_transaction.SQLErrText
  929. Goto ext
  930. End If
  931. If ld_fprice = 0 Then ld_fprice = ld_planprice
  932. Else
  933. If ld_planprice <> 0 Then
  934. ld_fprice = ld_planprice
  935. Else
  936. For j = 1 To it_mxbt_mx
  937. If outwaremx_mx[j].printid = outwaremx[i].printid Then
  938. f_get_planprice_mtrl(outwaremx_mx[j].mtrlid,outwaremx_mx[j].status,outwaremx_mx[j].woodcode,outwaremx_mx[j].pcode,ld_planprice)
  939. If outwaremx[i].planqty <> 0 Then
  940. ld_fprice = ld_fprice + outwaremx_mx[j].planqty / outwaremx[i].planqty * ld_planprice
  941. End If
  942. End If
  943. Next
  944. End If
  945. End If
  946. If li_ifunit = 0 Then
  947. ls_uunit = ls_unit
  948. ld_rate = 1
  949. ld_uqty = outwaremx[i].qty
  950. ld_uprice = ld_fprice
  951. Else
  952. If ld_rate_buy = 0 Then
  953. arg_msg = '物料:'+outwaremx[i].mtrlcode+',销售发货单(发货明细)行:'+String(i)+',资料设为双数量核算,但没有设置默认转换率,请检查'
  954. rslt = 0
  955. Goto ext
  956. End If
  957. ls_uunit = ls_unit_buy
  958. ld_rate = ld_rate_buy
  959. ld_uqty = outwaremx[i].qty /ld_rate_buy
  960. ld_uprice = ld_fprice * ld_rate
  961. End If
  962. s_mx.printid = chc
  963. s_mx.mtrlid = outwaremx[i].mtrlid
  964. s_mx.mtrlcode = outwaremx[i].mtrlcode
  965. s_mx.plancode = outwaremx[i].plancode
  966. s_mx.status = outwaremx[i].status
  967. s_mx.uqty = ld_uqty
  968. s_mx.enprice = ld_uprice
  969. s_mx.rebate = 1
  970. s_mx.mxdscrp = outwaremx[i].mxdscrp
  971. s_mx.jgprice = 0
  972. s_mx.relid = 0
  973. s_mx.ifrel = 0
  974. s_mx.woodcode = outwaremx[i].woodcode
  975. s_mx.pcode = outwaremx[i].pcode
  976. s_mx.sptid = outwaremx[i].sptid
  977. s_mx.unit = ls_uunit
  978. s_mx.rate = ld_rate
  979. s_mx.qty = outwaremx[i].qty
  980. s_mx.relprintid = 0
  981. s_mx.checkqty = 0
  982. s_mx.result = ''
  983. s_mx.waredscrp = ''
  984. s_mx.relbillid = 0
  985. s_mx.relbillprintid = 0
  986. s_mx.mtrlcuscode = outwaremx[i].mtrlcuscode
  987. s_mx.Location = outwaremx[i].Location
  988. s_mx.deliqty = ld_uqty
  989. s_mx.tax = 0
  990. If outwaremx[i].ifpackpro = 0 Then
  991. s_mx.ifvqty = 1
  992. s_mx.ifnotinout = 1
  993. Else
  994. s_mx.ifvqty = 0
  995. s_mx.ifnotinout = 0
  996. End If
  997. If uo_in.acceptmx(s_mx, arg_msg) = 0 Then
  998. arg_msg = '销售发货单(发货明细),行:'+String(i)+','+arg_msg
  999. rslt = 0
  1000. Goto ext
  1001. End If
  1002. // IF uo_in.acceptmx(chc,&
  1003. // outwaremx[i].mtrlid,&
  1004. // outwaremx[i].mtrlcode,&
  1005. // outwaremx[i].plancode,&
  1006. // outwaremx[i].status,&
  1007. // ld_uqty,&
  1008. // ld_uprice,&
  1009. // 1,&
  1010. // outwaremx[i].mxdscrp,&
  1011. // arg_msg,&
  1012. // 0,0,0,outwaremx[i].woodcode,outwaremx[i].pcode,outwaremx[i].sptid,ls_uunit,ld_rate,&
  1013. // outwaremx[i].qty,0,0,'','',0,0,&
  1014. // outwaremx[i].mtrlcuscode,outwaremx[i].Location,&
  1015. // ld_uqty,&
  1016. // 0) = 0 THEN
  1017. // arg_msg = '销售发货单(发货明细),'+arg_msg
  1018. // rslt = 0
  1019. // GOTO ext
  1020. // END IF
  1021. Next
  1022. If uo_in.Save(False,arg_msg) = 0 Then
  1023. arg_msg = '销售发货单(发货明细),'+arg_msg
  1024. rslt = 0
  1025. Goto ext
  1026. End If
  1027. rst_inwareid = uo_in.inwareid
  1028. //4.原事务审核进仓单
  1029. If uo_in.getinfo(scid,rst_inwareid,arg_msg) = 0 Then
  1030. arg_msg = '销售发货单(发货明细),'+arg_msg
  1031. rslt = 0
  1032. Goto ext
  1033. End If
  1034. If uo_in.auditing(False,arg_msg) = 0 Then
  1035. arg_msg = '销售发货单(发货明细),'+arg_msg
  1036. rslt = 0
  1037. Goto ext
  1038. End If
  1039. // END IF
  1040. End If
  1041. Long ll_printid_arr[],ll_mtrlwareid_arr[],ll_mtrlid_arr[]
  1042. String ls_status_arr[],ls_woodcode_arr[],ls_pcode_arr[]
  1043. Decimal ld_qty_arr[]
  1044. Long ll_cnt = 1
  1045. Long ll_printid
  1046. Decimal ld_maxqty
  1047. Long ll_mtrlid
  1048. Int li_outtype
  1049. String ls_pf_status[],ls_pf_woodcode[],ls_pf_pcode[]
  1050. Int li_ifover[],li_dipztype[]
  1051. Decimal ld_Sonscale[]
  1052. Long ll_SonMtrlid[]
  1053. Long it_mxt = 1
  1054. String ls_status_find,ls_woodcode_find,ls_pcode_find
  1055. String ls_status,ls_woodcode,ls_pcode
  1056. Decimal ld_pfqty
  1057. If uo_option_outware_saleout = 1 Then
  1058. Declare cur_mx Cursor For
  1059. Select u_outwaremx.relid, u_outwaremx.mtrlwareid, u_outwaremx.mtrlid,
  1060. u_outwaremx.status, u_outwaremx.woodcode, u_outwaremx.pcode,
  1061. u_outwaremx.qty
  1062. From u_outwaremx Inner JOIN
  1063. u_outware ON u_outwaremx.scid = u_outware.scid And
  1064. u_outwaremx.outwareid = u_outware.outwareid
  1065. Where u_outware.relid = :outwareid And
  1066. u_outware.scid = :scid And
  1067. u_outware.billtype = 21 Using commit_transaction;
  1068. Open cur_mx;
  1069. Fetch cur_mx Into :ll_printid_arr[ll_cnt],:ll_mtrlwareid_arr[ll_cnt],:ll_mtrlid_arr[ll_cnt],
  1070. :ls_status_arr[ll_cnt],:ls_woodcode_arr[ll_cnt],:ls_pcode_arr[ll_cnt],:ld_qty_arr[ll_cnt];
  1071. Do While commit_transaction.SQLCode = 0
  1072. ll_cnt++
  1073. Fetch cur_mx Into :ll_printid_arr[ll_cnt],:ll_mtrlwareid_arr[ll_cnt],:ll_mtrlid_arr[ll_cnt],
  1074. :ls_status_arr[ll_cnt],:ls_woodcode_arr[ll_cnt],:ls_pcode_arr[ll_cnt],:ld_qty_arr[ll_cnt];
  1075. Loop
  1076. Close cur_mx;
  1077. ll_cnt = ll_cnt - 1
  1078. For ll_i = 1 To it_mxbt
  1079. ld_maxqty = 0
  1080. it_mxt = 1
  1081. ll_printid = outwaremx[ll_i].printid
  1082. ll_mtrlid = outwaremx[ll_i].mtrlid
  1083. ls_status = outwaremx[ll_i].status
  1084. ls_woodcode = outwaremx[ll_i].woodcode
  1085. ls_pcode = outwaremx[ll_i].pcode
  1086. Select outtype,ifpackpro Into :li_outtype,:li_ifpackpro
  1087. From u_mtrldef
  1088. Where mtrlid = :ll_mtrlid Using commit_transaction;
  1089. If commit_transaction.SQLCode <> 0 Then
  1090. arg_msg = '销售发货单(发货明细)行:'+String(ll_i)+',查询产品出仓类型失败,'+commit_transaction.SQLErrText
  1091. rslt = 0
  1092. Goto ext
  1093. End If
  1094. // IF li_outtype = 0 or li_ifpackpro = 0 THEN
  1095. If Not ((li_outtype = 1 Or li_outtype = 2) And li_ifpackpro = 1) Then
  1096. For ll_j = 1 To ll_cnt
  1097. If ll_mtrlwareid_arr[ll_j] = 0 Then Continue
  1098. If ll_printid_arr[ll_j] = ll_printid Then
  1099. ld_maxqty = ld_qty_arr[ll_j]
  1100. Exit
  1101. End If
  1102. Next
  1103. Update u_outwaremx
  1104. Set qty = :ld_maxqty,
  1105. saleqty = :ld_maxqty
  1106. Where outwareid = :outwareid
  1107. And scid = :scid
  1108. And printid = :ll_printid Using commit_transaction;
  1109. If commit_transaction.SQLCode <> 0 Then
  1110. rslt = 0
  1111. arg_msg = '销售发货单(发货明细)行:'+String(ll_i)+',更新实发数失败,'+commit_transaction.SQLErrText
  1112. Goto ext
  1113. End If
  1114. Else
  1115. Declare cur_pf Cursor For
  1116. Select u_PrdPF.SonMtrlid,
  1117. u_PrdPF.status,
  1118. u_PrdPF.woodcode,
  1119. u_PrdPF.pcode,
  1120. u_PrdPF.ifover,
  1121. u_prdpf.dipztype,
  1122. u_prdpf.Sonscale
  1123. From u_PrdPF,u_mtrl_pf
  1124. Where ( u_PrdPF.mtrlid = u_mtrl_pf.mtrlid )
  1125. And ( u_PrdPF.pfcode = u_mtrl_pf.pfcode )
  1126. And ( u_PrdPF.mtrlid = :ll_mtrlid )
  1127. And ( u_mtrl_pf.ifdi = 1 And :li_ifpackpro = 0
  1128. Or u_mtrl_pf.ifdft = 1 And :li_ifpackpro = 1 );
  1129. Open cur_pf;
  1130. Fetch cur_pf Into :ll_SonMtrlid[it_mxt],:ls_pf_status[it_mxt],
  1131. :ls_pf_woodcode[it_mxt],:ls_pf_pcode[it_mxt],:li_ifover[it_mxt],
  1132. :li_dipztype[it_mxt],:ld_Sonscale[it_mxt];
  1133. Do While sqlca.SQLCode = 0
  1134. it_mxt++
  1135. Fetch cur_pf Into :ll_SonMtrlid[it_mxt],:ls_pf_status[it_mxt],
  1136. :ls_pf_woodcode[it_mxt],:ls_pf_pcode[it_mxt],:li_ifover[it_mxt],
  1137. :li_dipztype[it_mxt],:ld_Sonscale[it_mxt];
  1138. Loop
  1139. it_mxt = it_mxt - 1
  1140. Close cur_pf;
  1141. For ll_k = 1 To it_mxt
  1142. If li_ifover[ll_k] = 1 Then
  1143. Choose Case li_dipztype[ll_k]
  1144. Case 0
  1145. ls_status_find = ls_status
  1146. ls_woodcode_find = ''
  1147. ls_pcode_find = ''
  1148. Case 1
  1149. ls_status_find = ''
  1150. ls_woodcode_find = ls_woodcode
  1151. ls_pcode_find = ''
  1152. Case 2
  1153. ls_status_find = ''
  1154. ls_woodcode_find = ''
  1155. ls_pcode_find = ls_pcode
  1156. Case 3
  1157. ls_status_find = ls_status
  1158. ls_woodcode_find = ls_woodcode
  1159. ls_pcode_find = ''
  1160. Case 4
  1161. ls_status_find = ''
  1162. ls_woodcode_find = ls_woodcode
  1163. ls_pcode_find = ls_pcode
  1164. Case 5
  1165. ls_status_find = ls_status
  1166. ls_woodcode_find = ''
  1167. ls_pcode_find = ls_pcode
  1168. Case 6
  1169. ls_status_find = ls_status
  1170. ls_woodcode_find = ls_woodcode
  1171. ls_pcode_find = ls_pcode
  1172. End Choose
  1173. Else
  1174. ls_status_find = ls_pf_status[ll_k]
  1175. ls_woodcode_find = ls_pf_woodcode[ll_k]
  1176. ls_pcode_find = ls_pf_pcode[ll_k]
  1177. End If
  1178. ls_status_find = Trim(ls_status_find)
  1179. ls_woodcode_find = Trim(ls_woodcode_find)
  1180. ls_pcode_find = Trim(ls_pcode_find)
  1181. ld_pfqty = 0
  1182. For ll_j = 1 To ll_cnt
  1183. If ll_mtrlwareid_arr[ll_j] = 0 Then Continue
  1184. If ll_printid_arr[ll_j] = ll_printid And &
  1185. ll_mtrlid_arr[ll_j] = ll_SonMtrlid[ll_k] And &
  1186. ls_status_arr[ll_j] = ls_status_find And &
  1187. ls_woodcode_arr[ll_j] = ls_woodcode_find And &
  1188. ls_pcode_arr[ll_j] = ls_pcode_find Then
  1189. ld_pfqty = ld_pfqty + ld_qty_arr[ll_j] / ld_Sonscale[ll_k]
  1190. End If
  1191. Next
  1192. If thflag = 0 Then
  1193. If ld_pfqty > ld_maxqty Then ld_maxqty = ld_pfqty
  1194. Else
  1195. If ld_pfqty < ld_maxqty Then ld_maxqty = ld_pfqty
  1196. End If
  1197. Next
  1198. Update u_outwaremx
  1199. Set qty = :ld_maxqty,
  1200. saleqty = :ld_maxqty
  1201. Where outwareid = :outwareid
  1202. And scid = :scid
  1203. And printid = :ll_printid Using commit_transaction;
  1204. If commit_transaction.SQLCode <> 0 Then
  1205. rslt = 0
  1206. arg_msg = '销售发货单(发货明细)行:'+String(ll_i)+',更新实发数失败,'+commit_transaction.SQLErrText
  1207. Goto ext
  1208. End If
  1209. End If
  1210. outwaremx[ll_i].qty = ld_maxqty
  1211. Next
  1212. If uo_in.newbegin(scid,23,arg_msg) = 0 Then
  1213. rslt = 0
  1214. Goto ext
  1215. End If
  1216. uo_in.relid = outwareid
  1217. uo_in.indate = outdate
  1218. uo_in.inrep = outrep
  1219. uo_in.part = outwarecode
  1220. uo_in.dscrp = dscrp
  1221. uo_in.sptname = '销售发货单发货明细包件产品自动进仓'
  1222. uo_in.storageid = storageid
  1223. chc = 0
  1224. For i = 1 To it_mxbt
  1225. Select ifpackpro,ifunit,unit,rate_buy,unit_buy,planprice
  1226. Into :li_ifpackpro,:li_ifunit,:ls_unit,:ld_rate_buy,:ls_unit_buy,:ld_fprice
  1227. From u_mtrldef
  1228. Where mtrlid = :outwaremx[i].mtrlid;
  1229. If commit_transaction.SQLCode <> 0 Then
  1230. rslt = 0
  1231. arg_msg = '销售发货单(发货明细)行:'+String(ll_i)+",查询物料资料失败"+"~n"+commit_transaction.SQLErrText
  1232. Goto ext
  1233. End If
  1234. chc++
  1235. f_get_planprice_mtrl(outwaremx[i].mtrlid,outwaremx[i].status,outwaremx[i].woodcode,outwaremx[i].pcode,ld_fprice)
  1236. If li_ifunit = 0 Then
  1237. ls_uunit = ls_unit
  1238. ld_rate = 1
  1239. ld_uqty = outwaremx[i].qty
  1240. ld_uprice = ld_fprice
  1241. Else
  1242. If ld_rate_buy = 0 Then
  1243. arg_msg = '销售发货单(发货明细)行:'+String(i)+',资料设为双数量核算,但没有设置默认转换率,请检查'
  1244. rslt = 0
  1245. Goto ext
  1246. End If
  1247. ls_uunit = ls_unit_buy
  1248. ld_rate = ld_rate_buy
  1249. ld_uqty = outwaremx[i].qty /ld_rate_buy
  1250. ld_uprice = ld_fprice * ld_rate
  1251. End If
  1252. If ld_uqty <> 0 Or outwaremx[i].qty <> 0 Then
  1253. s_mx.printid = chc
  1254. s_mx.mtrlid = outwaremx[i].mtrlid
  1255. s_mx.mtrlcode = outwaremx[i].mtrlcode
  1256. s_mx.plancode = outwaremx[i].plancode
  1257. s_mx.status = outwaremx[i].status
  1258. s_mx.uqty = ld_uqty
  1259. s_mx.enprice = ld_uprice
  1260. s_mx.rebate = 1
  1261. s_mx.mxdscrp = outwaremx[i].mxdscrp
  1262. s_mx.jgprice = 0
  1263. s_mx.relid = 0
  1264. s_mx.ifrel = 0
  1265. s_mx.woodcode = outwaremx[i].woodcode
  1266. s_mx.pcode = outwaremx[i].pcode
  1267. s_mx.sptid = outwaremx[i].sptid
  1268. s_mx.unit = ls_uunit
  1269. s_mx.rate = ld_rate
  1270. s_mx.qty = outwaremx[i].qty
  1271. s_mx.relprintid = 0
  1272. s_mx.checkqty = 0
  1273. s_mx.result = ''
  1274. s_mx.waredscrp = ''
  1275. s_mx.relbillid = 0
  1276. s_mx.relbillprintid = 0
  1277. s_mx.mtrlcuscode = outwaremx[i].mtrlcuscode
  1278. s_mx.Location = outwaremx[i].Location
  1279. s_mx.deliqty = ld_uqty
  1280. s_mx.tax = 0
  1281. If outwaremx[i].ifpackpro = 0 Then
  1282. s_mx.ifvqty = 1
  1283. s_mx.ifnotinout = 1
  1284. Else
  1285. s_mx.ifvqty = 0
  1286. s_mx.ifnotinout = 0
  1287. End If
  1288. If uo_in.acceptmx(s_mx, arg_msg) = 0 Then
  1289. arg_msg = '销售发货单(发货明细),行:'+String(i)+','+arg_msg
  1290. rslt = 0
  1291. Goto ext
  1292. End If
  1293. // IF uo_in.acceptmx(chc,&
  1294. // outwaremx[i].mtrlid,&
  1295. // outwaremx[i].mtrlcode,&
  1296. // outwaremx[i].plancode,&
  1297. // outwaremx[i].status,&
  1298. // ld_uqty,&
  1299. // ld_uprice,&
  1300. // 1,&
  1301. // outwaremx[i].mxdscrp,&
  1302. // arg_msg,&
  1303. // 0,0,0,outwaremx[i].woodcode,outwaremx[i].pcode,outwaremx[i].sptid,ls_uunit,ld_rate,&
  1304. // outwaremx[i].qty,0,0,'','',0,0,&
  1305. // outwaremx[i].mtrlcuscode,outwaremx[i].Location,&
  1306. // ld_uqty,&
  1307. // 0) = 0 THEN
  1308. // arg_msg = '销售发货单(发货明细)行:'+String(i)+','+arg_msg
  1309. // rslt = 0
  1310. // GOTO ext
  1311. // END IF
  1312. End If
  1313. Next
  1314. If uo_in.Save(False,arg_msg) = 0 Then
  1315. arg_msg = '销售发货单(发货明细),'+arg_msg
  1316. rslt = 0
  1317. Goto ext
  1318. End If
  1319. rst_inwareid = uo_in.inwareid
  1320. //4.原事务审核进仓单
  1321. If uo_in.getinfo(scid,rst_inwareid,arg_msg) = 0 Then
  1322. arg_msg = '销售发货单(发货明细),'+arg_msg
  1323. rslt = 0
  1324. Goto ext
  1325. End If
  1326. If uo_in.auditing(False,arg_msg) = 0 Then
  1327. arg_msg = '销售发货单(发货明细),'+arg_msg
  1328. rslt = 0
  1329. Goto ext
  1330. End If
  1331. End If
  1332. //审核原发货单明细出仓
  1333. For i = 1 To it_mxbt
  1334. //先扣库存分配,再扣库存
  1335. //仓库是用库存分配,不是(包件出仓和条码出仓),包件的在销售出仓单做
  1336. If billtype = 1 And li_storagetype = 1 And li_outtype_storage = 0 And outwaremx[i].relid > 0 Then
  1337. ll_row = ds_out_assign.Retrieve(scid,outwaremx[i].mtrlwareid,outwaremx[i].relid,outwaremx[i].relprintid)
  1338. ds_out_assign.AcceptText()
  1339. If ll_row <= 0 Then
  1340. ld_sumnotoutqty = 0
  1341. Else
  1342. ld_sumnotoutqty = ds_out_assign.Object.sumnotoutqty[1]
  1343. End If
  1344. ld_sumnotoutqty_bill = 0
  1345. ld_sumnotoutqty_bill = outwaremx[i].qty
  1346. If ld_sumnotoutqty_bill > ld_sumnotoutqty Then
  1347. arg_msg = '发货明细行:'+String(i)+'订单库存分配数不足,请检查库存分配明细'
  1348. rslt = 0
  1349. Goto ext
  1350. Else
  1351. ld_assign_outqty = 0
  1352. For j = 1 To ds_out_assign.RowCount()
  1353. If ds_out_assign.Object.notoutqty[j] >= ld_sumnotoutqty_bill Then
  1354. ld_assign_outqty = ld_sumnotoutqty_bill
  1355. If uo_ma.uof_assign_addoutqty(ds_out_assign.Object.assignid[j],ld_assign_outqty,arg_msg,False) = 0 Then
  1356. arg_msg = '发货明细行:'+String(i)+','+arg_msg
  1357. rslt = 0
  1358. Goto ext
  1359. End If
  1360. Exit
  1361. Else
  1362. ld_assign_outqty = ds_out_assign.Object.notoutqty[j]
  1363. If uo_ma.uof_assign_addoutqty(ds_out_assign.Object.assignid[j],ld_assign_outqty,arg_msg,False) = 0 Then
  1364. arg_msg = '发货明细行:'+String(i)+','+arg_msg
  1365. rslt = 0
  1366. Goto ext
  1367. End If
  1368. ld_sumnotoutqty_bill = ld_sumnotoutqty_bill - ds_out_assign.Object.notoutqty[j]
  1369. End If
  1370. Next
  1371. End If
  1372. End If
  1373. //扣库存
  1374. Decimal ld_ref_costamt
  1375. If p_update_cost(outwaremx[i].mtrlwareid,outwaremx[i].mtrlcode,&
  1376. outwaremx[i].qty,outwaremx[i].printid,ld_ref_costamt,arg_msg,False) = 0 Then
  1377. arg_msg = '发货明细行:'+String(i)+','+arg_msg
  1378. rslt = 0
  1379. Goto ext
  1380. End If
  1381. If sys_option_inout_procedure = 0 Then
  1382. If p_update_mtrlware ( outwaremx[i].mtrlwareid, outwaremx[i].mtrlid, &
  1383. outwaremx[i].mtrlcode, storageid, outwaremx[i].plancode,&
  1384. outwaremx[i].status, outwaremx[i].qty,outwaremx[i].uqty, ld_ref_costamt,&
  1385. outwaremx[i].planprice, outwaremx[i].sptid,outwaremx[i].dxflag,&
  1386. outwaremx[i].woodcode,outwaremx[i].pcode,outwaremx[i].mtrlcuscode,&
  1387. outwaremx[i].Location,outwaremx[i].ifvqty,arg_msg) = 0 Then
  1388. arg_msg = '发货明细行:'+String(i)+','+arg_msg
  1389. rslt = 0
  1390. Goto ext
  1391. End If
  1392. Else
  1393. If uo_pro.p_outware_update_mtrlware(scid,outwareid,outwaremx[i].printid,outwaremx[i].mtrlwareid,&
  1394. outwaremx[i].mtrlid,outwaremx[i].mtrlcode,storageid,outwaremx[i].plancode,outwaremx[i].status,&
  1395. outwaremx[i].qty,outwaremx[i].uqty,ld_ref_costamt,&
  1396. outwaremx[i].planprice, outwaremx[i].sptid,outwaremx[i].dxflag,&
  1397. outwaremx[i].woodcode, outwaremx[i].pcode,outwaremx[i].mtrlcuscode,outwaremx[i].Location,arg_msg) = 0 Then
  1398. arg_msg = '发货明细行:'+String(i)+','+arg_msg
  1399. rslt = 0
  1400. Goto ext
  1401. End If
  1402. End If
  1403. If billtype = 1 And outwaremx[i].saleoutid > 0 Then
  1404. If uo_sout.addmxcmpl(outwaremx[i].saleoutid,outwaremx[i].saleoutprintid,outwaremx[i].saleqty,arg_msg,False) <> 1 Then
  1405. arg_msg = '发货明细行:'+String(i)+','+arg_msg
  1406. rslt = 0
  1407. Goto ext
  1408. End If
  1409. End If
  1410. If billtype = 1 And outwaremx[i].saleoutid > 0 Then
  1411. If uo_sout.trycmpsaleout(outwaremx[i].saleoutid,arg_msg,False) <> 1 Then
  1412. arg_msg = '发货明细行:'+String(i)+','+arg_msg
  1413. rslt = 0
  1414. Goto ext
  1415. End If
  1416. End If
  1417. If (billtype = 1 Or billtype = 5) And outwaremx[i].relid > 0 Then
  1418. If uo_task.addmxcmpl(scid,outwaremx[i].relid,outwaremx[i].relprintid,outwaremx[i].saleqty,arg_msg,False) <> 1 Then
  1419. arg_msg = '发货明细行:'+String(i)+','+arg_msg
  1420. rslt = 0
  1421. Goto ext
  1422. End If
  1423. End If
  1424. If (billtype = 1 Or billtype = 5) And outwaremx[i].relid > 0 Then
  1425. If uo_task.trycmplsaletask(scid,outwaremx[i].relid,arg_msg,False) = 0 Then
  1426. arg_msg = '发货明细行:'+String(i)+','+arg_msg
  1427. rslt = 0
  1428. Goto ext
  1429. End If
  1430. End If
  1431. If li_outtype_storage = 2 And outwaremx[i].outtype_mtrl = 2 Then mx_barcode_cnt++
  1432. Next
  1433. If li_outtype_storage = 2 And mx_barcode_cnt > 0 Then
  1434. If uof_p_barcode(1,arg_msg) = 0 Then
  1435. rslt = 0
  1436. Goto ext
  1437. End If
  1438. End If
  1439. If uof_create_owe(arg_msg) = 0 Then
  1440. rslt = 0
  1441. Goto ext
  1442. End If
  1443. //更新库存已开单数(减)
  1444. If uo_option_inout_type = 0 Or (uo_option_inout_type <> 0 And uo_option_outware_saleout = 0) Then
  1445. If uof_noauditingqty_del(scid,outwareid,arg_msg) = 0 Then
  1446. rslt = 0
  1447. Goto ext
  1448. End If
  1449. End If
  1450. //更新通用包件明细已占用数(outqty)
  1451. Long ll_mtrlwareid_fp,ll_mtrlid_fp,ll_cpmtrlwareid_fp,ll_cpmtrlid_fp
  1452. If uo_option_canpack_ifzanyong = 1 Then
  1453. For ll_i = 1 To it_mxbt_mx
  1454. ll_mtrlwareid_fp = 0
  1455. ll_mtrlid_fp = 0
  1456. ll_cpmtrlwareid_fp = 0
  1457. ll_cpmtrlid_fp = 0
  1458. If outwaremx_mx[ll_i].ifpack = 1 Then
  1459. ll_mtrlwareid_fp = outwaremx_mx[ll_i].mtrlwareid
  1460. ll_mtrlid_fp = outwaremx_mx[ll_i].mtrlid
  1461. //查找包件明细对应的发货明细
  1462. For ll_j = 1 To it_mxbt
  1463. If outwaremx_mx[ll_i].printid = outwaremx[ll_j].printid Then
  1464. If outwaremx[ll_j].ifpackpro = 1 Then
  1465. ll_cpmtrlwareid_fp = outwaremx[ll_j].mtrlwareid
  1466. ll_cpmtrlid_fp = outwaremx[ll_j].mtrlid
  1467. Else
  1468. Goto _next_mx
  1469. End If
  1470. End If
  1471. Next
  1472. If ll_cpmtrlwareid_fp = 0 Then Goto _next_mx
  1473. If uo_pack.uof_add_fpqty_out(scid,ll_mtrlwareid_fp,ll_mtrlid_fp,ll_cpmtrlwareid_fp,ll_cpmtrlid_fp,outwaremx_mx[ll_i].qty,arg_msg,False) = 0 Then
  1474. rslt = 0
  1475. Goto ext
  1476. End If
  1477. End If
  1478. _next_mx:
  1479. Next
  1480. End If
  1481. flag = 1
  1482. ext:
  1483. If rslt = 0 Then
  1484. Rollback Using commit_transaction;
  1485. ElseIf rslt = 1 And arg_ifcommit Then
  1486. Commit Using commit_transaction;
  1487. End If
  1488. Destroy uo_task
  1489. Destroy uo_in
  1490. Destroy uo_out
  1491. Destroy uo_ma
  1492. Destroy uo_sout
  1493. Destroy uo_pro
  1494. Destroy ds_out_assign
  1495. Destroy uo_pack
  1496. Return rslt
  1497. end function
  1498. public function integer c_auditing (boolean arg_ifcommit, ref string arg_msg);Int rslt = 1
  1499. Long cnt = 0,i,j,mx_barcode_cnt
  1500. Long ls_newid
  1501. DateTime null_dt
  1502. SetNull(null_dt)
  1503. Long ll_inwareid_rel,ll_outwareid_rel
  1504. String ls_inwarecode_rel,ls_outwarecode_rel
  1505. String ls_outwarecode_arr[]
  1506. Long ll_outwareid[]
  1507. Long ll_itmx = 1,ll_i,ll_l,ll_j
  1508. ins_ref_outwaremx = ins_empty_outwaremx
  1509. ins_ref_mxbt = 0
  1510. If f_aps_mrp_cklock(scid,arg_msg) = 0 Then
  1511. rslt = 0
  1512. Goto ext
  1513. End If
  1514. uo_sqlpro uo_pro
  1515. uo_pro = Create uo_sqlpro
  1516. uo_pro.commit_transaction = commit_transaction
  1517. If uo_option_outware_saleout = -1000 Then
  1518. rslt = 0
  1519. arg_msg = '选项:[147]使用销售出仓单,读取初始默认值失败,操作取消!'
  1520. Goto ext
  1521. End If
  1522. uo_saletask uo_task
  1523. uo_task = Create uo_saletask
  1524. uo_task.commit_transaction = commit_transaction
  1525. uo_saleout uo_sout
  1526. uo_sout = Create uo_saleout
  1527. uo_sout.commit_transaction = commit_transaction
  1528. uo_mtrlware_assign uo_ma
  1529. uo_ma = Create uo_mtrlware_assign
  1530. uo_ma.commit_transaction = commit_transaction
  1531. uo_cmpl_packpro uo_pack
  1532. uo_pack = Create uo_cmpl_packpro
  1533. uo_pack.commit_transaction = commit_transaction
  1534. //库存分配ds
  1535. datastore ds_out_assign
  1536. ds_out_assign = Create datastore
  1537. ds_out_assign.DataObject = 'ds_outwaremx_assign_cancel'
  1538. ds_out_assign.SetTransObject(commit_transaction)
  1539. uo_inware uo_in
  1540. uo_outware uo_out
  1541. uo_in = Create uo_inware
  1542. uo_in.commit_transaction = sqlca
  1543. uo_in.if_getid_ture = False
  1544. uo_out = Create uo_outware
  1545. uo_out.commit_transaction = sqlca
  1546. uo_out.if_getid_ture = False
  1547. If storageid = 0 Then
  1548. rslt = 0
  1549. arg_msg = '没有正确的仓库'
  1550. Goto ext
  1551. End If
  1552. If billtype <> 9 Then
  1553. If uof_check_warepdb_audit(storageid,arg_msg) = 0 Then
  1554. rslt = 0
  1555. Goto ext
  1556. End If
  1557. End If
  1558. String ls_storagename
  1559. Int li_outtype_storage,li_storagetype
  1560. Select storagename,outtype,storagetype
  1561. Into :ls_storagename,:li_outtype_storage,:li_storagetype
  1562. From u_storage
  1563. Where storageid = :storageid Using commit_transaction ;
  1564. If commit_transaction.SQLCode <> 0 Then
  1565. rslt = 0
  1566. arg_msg = "查询操作失败,仓库"
  1567. Goto ext
  1568. End If
  1569. //检查是否有该仓库的建立权限
  1570. If sys_user_storagestr_audit <> '0' Then
  1571. If Pos(sys_user_storagestr_audit,','+String(storageid)+',') <= 0 Then
  1572. rslt = 0
  1573. arg_msg = '没有仓库: '+ls_storagename+' 的审核权限,不允许撤审该仓库的单据'
  1574. Goto ext
  1575. End If
  1576. End If
  1577. //
  1578. If outwareid = 0 Then
  1579. rslt = 0
  1580. arg_msg = "没有审核对象"
  1581. Goto ext
  1582. End If
  1583. If ctmint > 0 Then
  1584. arg_msg = '单据已截数,不能操作'
  1585. rslt = 0
  1586. Goto ext
  1587. End If
  1588. If flag = 0 Then
  1589. rslt = 0
  1590. arg_msg = "单据还未审核"
  1591. Goto ext
  1592. End If
  1593. If secflag = 1 Then
  1594. rslt = 0
  1595. arg_msg = "单据已经过财务审核"
  1596. Goto ext
  1597. End If
  1598. If balcflag = 1 Then
  1599. rslt = 0
  1600. arg_msg = "单据已经日结,不能撤审"
  1601. Goto ext
  1602. End If
  1603. String ls_owecode
  1604. Int li_oweflag
  1605. Long ll_owebillid
  1606. cnt = 0
  1607. Select count(*) Into :cnt
  1608. From u_owegood
  1609. Where scid = :scid
  1610. And relid = :outwareid Using commit_transaction;
  1611. If commit_transaction.SQLCode <> 0 Then
  1612. rslt = 0
  1613. arg_msg = '因网络或其它原因导致查询是否存在相关欠货单操作失败'+"~n"+commit_transaction.SQLErrText
  1614. Goto ext
  1615. End If
  1616. If cnt > 1 Then
  1617. rslt = 0
  1618. arg_msg = '不合理的欠货单数量(存在多张相关欠货单),请检查'
  1619. Goto ext
  1620. ElseIf cnt = 1 Then
  1621. Select billid,billcode ,flag
  1622. Into :ll_owebillid,:ls_owecode,:li_oweflag
  1623. From u_owegood
  1624. Where scid = :scid
  1625. And relid = :outwareid Using commit_transaction;
  1626. If commit_transaction.SQLCode <> 0 Then
  1627. rslt = 0
  1628. arg_msg = '因网络或其它原因导致查询\相关欠货单信息操作失败'+"~n"+commit_transaction.SQLErrText
  1629. Goto ext
  1630. End If
  1631. If li_oweflag <> 0 Then
  1632. rslt = 0
  1633. arg_msg = '相关欠货单:'+ls_owecode+' 已在进行或完成,不能撤审销售发货单,请检查'
  1634. Goto ext
  1635. End If
  1636. Delete From u_owegoodmx
  1637. Where billid = :ll_owebillid;
  1638. If commit_transaction.SQLCode <> 0 Then
  1639. rslt = 0
  1640. arg_msg = "删除相关欠货单明细操作失败"+"~n"+commit_transaction.SQLErrText
  1641. Goto ext
  1642. End If
  1643. Delete From u_owegood
  1644. Where billid = :ll_owebillid
  1645. And flag = 0;
  1646. If commit_transaction.SQLCode <> 0 Then
  1647. rslt = 0
  1648. arg_msg = "删除相关欠货单操作失败"+"~n"+commit_transaction.SQLErrText
  1649. Goto ext
  1650. End If
  1651. End If
  1652. Update u_outware
  1653. Set Auditingrep = '',
  1654. Auditingdate = :null_dt,
  1655. flag = 0,
  1656. carflag = 0
  1657. Where u_outware.outwareid = :outwareid
  1658. And flag = 1
  1659. And scid = :scid Using commit_transaction;
  1660. If commit_transaction.SQLCode <> 0 Then
  1661. rslt = 0
  1662. arg_msg = "因网络或其它原因导致审核单据操作失败"+"~n"+commit_transaction.SQLErrText
  1663. Goto ext
  1664. ElseIf commit_transaction.SQLNRows = 0 Then
  1665. rslt = 0
  1666. arg_msg = "单据正在审核,请稍后查询。"+"~n"+commit_transaction.SQLErrText
  1667. Goto ext
  1668. End If
  1669. //原发货单明细
  1670. For i = 1 To it_mxbt
  1671. If sys_option_inout_procedure = 0 Then
  1672. If p_update_mtrlware ( outwaremx[i].mtrlwareid, outwaremx[i].mtrlid, &
  1673. outwaremx[i].mtrlcode, storageid, outwaremx[i].plancode,&
  1674. outwaremx[i].status, 0 - outwaremx[i].qty,0 - outwaremx[i].uqty,0 - outwaremx[i].costamt,&
  1675. outwaremx[i].planprice, outwaremx[i].sptid, outwaremx[i].dxflag,&
  1676. outwaremx[i].woodcode, outwaremx[i].pcode, outwaremx[i].mtrlcuscode,&
  1677. outwaremx[i].Location,outwaremx[i].ifvqty,arg_msg) = 0 Then
  1678. arg_msg = '发货明细行:'+String(i)+','+arg_msg
  1679. rslt = 0
  1680. Goto ext
  1681. End If
  1682. Else
  1683. If uo_pro.p_outware_update_mtrlware(scid,outwareid,outwaremx[i].printid,outwaremx[i].mtrlwareid,&
  1684. outwaremx[i].mtrlid,outwaremx[i].mtrlcode,storageid,outwaremx[i].plancode,outwaremx[i].status,&
  1685. 0 - outwaremx[i].qty,0 - outwaremx[i].uqty,outwaremx[i].costamt,&
  1686. outwaremx[i].planprice, outwaremx[i].sptid,outwaremx[i].dxflag,&
  1687. outwaremx[i].woodcode, outwaremx[i].pcode,outwaremx[i].mtrlcuscode,outwaremx[i].Location,arg_msg) = 0 Then
  1688. arg_msg = '发货明细行:'+String(i)+','+arg_msg
  1689. rslt = 0
  1690. Goto ext
  1691. End If
  1692. End If
  1693. If billtype = 1 And outwaremx[i].saleoutid > 0 Then
  1694. If uo_sout.addmxcmpl(outwaremx[i].saleoutid,outwaremx[i].saleoutprintid,0 - outwaremx[i].saleqty,arg_msg,False) <> 1 Then
  1695. arg_msg = '发货明细行:'+String(i)+','+arg_msg
  1696. rslt = 0
  1697. Goto ext
  1698. End If
  1699. End If
  1700. If billtype = 1 And outwaremx[i].saleoutid > 0 Then
  1701. If uo_sout.trycmpsaleout(outwaremx[i].saleoutid,arg_msg,False) <> 1 Then
  1702. arg_msg = '发货明细行:'+String(i)+','+arg_msg
  1703. rslt = 0
  1704. Goto ext
  1705. End If
  1706. End If
  1707. If (billtype = 1 Or billtype = 5) And outwaremx[i].relid > 0 Then
  1708. If uo_task.addmxcmpl(scid,outwaremx[i].relid,outwaremx[i].relprintid, 0 - outwaremx[i].saleqty,arg_msg,False) <> 1 Then
  1709. arg_msg = '发货明细行:'+String(i)+','+arg_msg
  1710. rslt = 0
  1711. Goto ext
  1712. End If
  1713. End If
  1714. If (billtype = 1 Or billtype = 5) And outwaremx[i].relid > 0 Then
  1715. If uo_task.trycmplsaletask(scid,outwaremx[i].relid,arg_msg,False) = 0 Then
  1716. arg_msg = '发货明细行:'+String(i)+','+arg_msg
  1717. rslt = 0
  1718. Goto ext
  1719. End If
  1720. End If
  1721. //更新库存分配
  1722. Decimal ld_assign_outqty,ld_sumnotoutqty,ld_outmxqty
  1723. Long ll_row
  1724. If billtype = 1 And li_storagetype = 1 And li_outtype_storage = 0 And outwaremx[i].relid > 0 Then
  1725. ll_row = ds_out_assign.Retrieve(scid,outwaremx[i].mtrlwareid,outwaremx[i].relid,outwaremx[i].relprintid)
  1726. ds_out_assign.AcceptText()
  1727. If ll_row <= 0 Then
  1728. ld_sumnotoutqty = 0
  1729. Else
  1730. ld_sumnotoutqty = ds_out_assign.Object.sumnotoutqty[1]
  1731. End If
  1732. ld_outmxqty = outwaremx[i].qty
  1733. If ld_sumnotoutqty > 0 And ld_outmxqty > 0 Then
  1734. // IF ld_outmxqty > ld_sumnotoutqty THEN
  1735. // arg_msg = '发货明细行:'+String(i)+'订单库存分配已出仓数不足,不能撤审,请检查库存分配已出仓明细'
  1736. // rslt = 0
  1737. // GOTO ext
  1738. // ELSE
  1739. ld_assign_outqty = 0
  1740. For j = 1 To ds_out_assign.RowCount()
  1741. If ds_out_assign.Object.notoutqty[j] >= ld_outmxqty Then
  1742. ld_assign_outqty = ld_outmxqty
  1743. If uo_ma.uof_assign_addoutqty(ds_out_assign.Object.assignid[j],0 - ld_assign_outqty,arg_msg,False) = 0 Then
  1744. arg_msg = '发货明细行:'+String(i)+','+arg_msg
  1745. rslt = 0
  1746. Goto ext
  1747. End If
  1748. Exit
  1749. Else
  1750. ld_assign_outqty = ds_out_assign.Object.notoutqty[j]
  1751. If uo_ma.uof_assign_addoutqty(ds_out_assign.Object.assignid[j],0 - ld_assign_outqty,arg_msg,False) = 0 Then
  1752. arg_msg = '发货明细行:'+String(i)+','+arg_msg
  1753. rslt = 0
  1754. Goto ext
  1755. End If
  1756. ld_outmxqty = ld_outmxqty - ds_out_assign.Object.notoutqty[j]
  1757. End If
  1758. Next
  1759. // END IF
  1760. End If
  1761. End If
  1762. If li_outtype_storage = 2 And outwaremx[i].outtype_mtrl = 2 Then mx_barcode_cnt++
  1763. Next
  1764. If li_outtype_storage <> 0 And uo_option_outware_saleout = 0 Then
  1765. Select count(*)
  1766. Into :cnt
  1767. From u_inware
  1768. Where scid = :scid
  1769. And relid = :outwareid
  1770. And billtype = 23 Using commit_transaction;
  1771. If commit_transaction.SQLCode <> 0 Then
  1772. rslt = 0
  1773. arg_msg = "因网络或其它原因导致查询相关包件进仓单操作失败"+"~n"+commit_transaction.SQLErrText
  1774. Goto ext
  1775. End If
  1776. If cnt > 0 Then
  1777. Select inwareid,inwarecode
  1778. Into :ll_inwareid_rel,:ls_inwarecode_rel
  1779. From u_inware
  1780. Where scid = :scid
  1781. And relid = :outwareid
  1782. And billtype = 23 Using commit_transaction;
  1783. If commit_transaction.SQLCode <> 0 Then
  1784. rslt = 0
  1785. arg_msg = "因网络或其它原因导致查询相关包件进仓单操作失败"+"~n"+commit_transaction.SQLErrText
  1786. Goto ext
  1787. End If
  1788. If uo_in.getinfo(scid,ll_inwareid_rel,arg_msg) = 0 Then
  1789. arg_msg = '相关进仓单:'+ls_inwarecode_rel+','+arg_msg
  1790. rslt = 0
  1791. Goto ext
  1792. End If
  1793. If uo_in.c_auditing(False,arg_msg) = 0 Then
  1794. arg_msg = '相关进仓单:'+ls_inwarecode_rel+','+arg_msg
  1795. rslt = 0
  1796. Goto ext
  1797. End If
  1798. If uo_in.del(scid,ll_inwareid_rel,arg_msg,False) = 0 Then
  1799. arg_msg = '相关进仓单:'+ls_inwarecode_rel+','+arg_msg
  1800. rslt = 0
  1801. Goto ext
  1802. End If
  1803. End If
  1804. Declare cur_mx Cursor For
  1805. Select outwareid,outwarecode
  1806. From u_outware
  1807. Where billtype = 21
  1808. And relid = :outwareid
  1809. And scid = :scid Using commit_transaction;
  1810. Open cur_mx;
  1811. Fetch cur_mx Into :ll_outwareid[ll_itmx],:ls_outwarecode_arr[ll_itmx];
  1812. Do While commit_transaction.SQLCode = 0
  1813. ll_itmx++
  1814. Fetch cur_mx Into :ll_outwareid[ll_itmx],:ls_outwarecode_arr[ll_itmx];
  1815. Loop
  1816. ll_itmx = ll_itmx - 1
  1817. Close cur_mx;
  1818. For ll_i = 1 To ll_itmx
  1819. If uo_out.getinfo(scid,ll_outwareid[ll_i],arg_msg) = 0 Then
  1820. rslt = 0
  1821. arg_msg = '查询相关出仓单失败,' + arg_msg
  1822. Goto ext
  1823. End If
  1824. If uo_out.c_auditing(False,arg_msg) = 0 Then
  1825. rslt = 0
  1826. arg_msg = '撤审相关出仓单失败,' + arg_msg
  1827. Goto ext
  1828. End If
  1829. If uo_out.del(scid,ll_outwareid[ll_i],0,arg_msg,False) = 0 Then
  1830. arg_msg = '相关出仓单:'+ls_outwarecode_rel+','+arg_msg
  1831. rslt = 0
  1832. Goto ext
  1833. End If
  1834. Next
  1835. //原发货单明细取消分配出仓
  1836. For i = 1 To it_mxbt
  1837. //yyx20120825
  1838. If billtype = 1 And li_storagetype = 1 And li_outtype_storage > 0 And ( outwaremx[i].ifpackpro > 0 And outwaremx[i].ifpackpro <> 4 Or outwaremx[i].ifpackpro = 4 And (Pos(outwaremx[i].status,'+') > 0 Or Pos(outwaremx[i].status,'*') > 0)) And outwaremx[i].relid > 0 Then
  1839. ll_row = ds_out_assign.Retrieve(scid,outwaremx[i].mtrlwareid,outwaremx[i].relid,outwaremx[i].relprintid)
  1840. ds_out_assign.AcceptText()
  1841. If ll_row <= 0 Then
  1842. ld_sumnotoutqty = 0
  1843. Else
  1844. ld_sumnotoutqty = ds_out_assign.Object.sumnotoutqty[1]
  1845. End If
  1846. ld_outmxqty = outwaremx[i].qty
  1847. If ld_sumnotoutqty > 0 And ld_outmxqty > 0 Then
  1848. // IF ld_outmxqty > ld_sumnotoutqty THEN
  1849. // arg_msg = '发货明细行:'+String(i)+'订单库存分配已出仓数不足,不能撤审,请检查库存分配已出仓明细'
  1850. // rslt = 0
  1851. // GOTO ext
  1852. // ELSE
  1853. ld_assign_outqty = 0
  1854. For j = 1 To ds_out_assign.RowCount()
  1855. If ds_out_assign.Object.notoutqty[j] >= ld_outmxqty Then
  1856. ld_assign_outqty = ld_outmxqty
  1857. If uo_ma.uof_assign_addoutqty(ds_out_assign.Object.assignid[j],0 - ld_assign_outqty,arg_msg,False) = 0 Then
  1858. arg_msg = '发货明细行:'+String(i)+','+arg_msg
  1859. rslt = 0
  1860. Goto ext
  1861. End If
  1862. Exit
  1863. Else
  1864. ld_assign_outqty = ds_out_assign.Object.notoutqty[j]
  1865. If uo_ma.uof_assign_addoutqty(ds_out_assign.Object.assignid[j],0 - ld_assign_outqty,arg_msg,False) = 0 Then
  1866. arg_msg = '发货明细行:'+String(i)+','+arg_msg
  1867. rslt = 0
  1868. Goto ext
  1869. End If
  1870. ld_outmxqty = ld_outmxqty - ds_out_assign.Object.notoutqty[j]
  1871. End If
  1872. Next
  1873. End If
  1874. // END IF
  1875. End If
  1876. //
  1877. Next
  1878. End If
  1879. If uo_option_outware_saleout = 1 Then
  1880. Select count(*)
  1881. Into :cnt
  1882. From u_inware
  1883. Where scid = :scid
  1884. And relid = :outwareid
  1885. And billtype = 23 Using commit_transaction;
  1886. If commit_transaction.SQLCode <> 0 Then
  1887. rslt = 0
  1888. arg_msg = "因网络或其它原因导致查询相关包件进仓单操作失败"+"~n"+commit_transaction.SQLErrText
  1889. Goto ext
  1890. End If
  1891. If cnt > 0 Then
  1892. Select inwareid,inwarecode
  1893. Into :ll_inwareid_rel,:ls_inwarecode_rel
  1894. From u_inware
  1895. Where scid = :scid
  1896. And relid = :outwareid
  1897. And billtype = 23;
  1898. If commit_transaction.SQLCode <> 0 Then
  1899. rslt = 0
  1900. arg_msg = "因网络或其它原因导致查询相关包件进仓单操作失败"+"~n"+commit_transaction.SQLErrText
  1901. Goto ext
  1902. End If
  1903. If uo_in.getinfo(scid,ll_inwareid_rel,arg_msg) = 0 Then
  1904. arg_msg = '相关进仓单:'+ls_inwarecode_rel+','+arg_msg
  1905. rslt = 0
  1906. Goto ext
  1907. End If
  1908. If uo_in.c_auditing(False,arg_msg) = 0 Then
  1909. arg_msg = '相关进仓单:'+ls_inwarecode_rel+','+arg_msg
  1910. rslt = 0
  1911. Goto ext
  1912. End If
  1913. If uo_in.del(scid,ll_inwareid_rel,arg_msg,False) = 0 Then
  1914. arg_msg = '相关进仓单:'+ls_inwarecode_rel+','+arg_msg
  1915. rslt = 0
  1916. Goto ext
  1917. End If
  1918. End If
  1919. Declare cur_mx_rel Cursor For
  1920. Select outwareid
  1921. From u_outware
  1922. Where billtype = 21
  1923. And relid = :outwareid
  1924. And scid = :scid Using commit_transaction;
  1925. Open cur_mx_rel;
  1926. Fetch cur_mx_rel Into :ll_outwareid[ll_itmx];
  1927. Do While commit_transaction.SQLCode = 0
  1928. ll_itmx++
  1929. Fetch cur_mx_rel Into :ll_outwareid[ll_itmx];
  1930. Loop
  1931. ll_itmx = ll_itmx - 1
  1932. Close cur_mx_rel;
  1933. For ll_i = 1 To ll_itmx
  1934. If uo_out.getinfo(scid,ll_outwareid[ll_i],arg_msg) = 0 Then
  1935. rslt = 0
  1936. arg_msg = '查询相关出仓单失败,' + arg_msg
  1937. Goto ext
  1938. End If
  1939. If uo_out.c_auditing(False,arg_msg) = 0 Then
  1940. rslt = 0
  1941. arg_msg = '撤审相关出仓单失败,' + arg_msg
  1942. Goto ext
  1943. End If
  1944. If uo_option_noauditingqty_mode = 1 Then
  1945. If UpperBound(uo_out.ins_ref_outwaremx) > 0 Then
  1946. For ll_l = 1 To UpperBound(uo_out.ins_ref_outwaremx)
  1947. ins_ref_mxbt++
  1948. ins_ref_outwaremx[ins_ref_mxbt].mtrlid = uo_out.ins_ref_outwaremx[ll_l].mtrlid
  1949. ins_ref_outwaremx[ins_ref_mxbt].plancode = uo_out.ins_ref_outwaremx[ll_l].plancode
  1950. ins_ref_outwaremx[ins_ref_mxbt].mtrlcuscode = uo_out.ins_ref_outwaremx[ll_l].mtrlcuscode
  1951. ins_ref_outwaremx[ins_ref_mxbt].storageid = uo_out.storageid
  1952. Next
  1953. End If
  1954. End If
  1955. Next
  1956. End If
  1957. If li_outtype_storage = 2 And mx_barcode_cnt > 0 Then
  1958. If uof_p_barcode(0,arg_msg) = 0 Then
  1959. rslt = 0
  1960. Goto ext
  1961. End If
  1962. End If
  1963. //增加已开单数
  1964. If uo_option_inout_type = 0 Or (uo_option_inout_type <> 0 And uo_option_outware_saleout = 0) Then
  1965. If uof_noauditingqty_add(scid,billtype,relint_1,arg_msg) = 0 Then
  1966. rslt = 0
  1967. Goto ext
  1968. End If
  1969. End If
  1970. //更新通用包件明细已占用数(outqty)
  1971. Long ll_mtrlwareid_fp,ll_mtrlid_fp,ll_cpmtrlwareid_fp,ll_cpmtrlid_fp
  1972. If uo_option_canpack_ifzanyong = 1 Then
  1973. For ll_i = 1 To it_mxbt_mx
  1974. ll_mtrlwareid_fp = 0
  1975. ll_mtrlid_fp = 0
  1976. ll_cpmtrlwareid_fp = 0
  1977. ll_cpmtrlid_fp = 0
  1978. If outwaremx_mx[ll_i].ifpack = 1 Then
  1979. ll_mtrlwareid_fp = outwaremx_mx[ll_i].mtrlwareid
  1980. ll_mtrlid_fp = outwaremx_mx[ll_i].mtrlid
  1981. //查找包件明细对应的发货明细
  1982. For ll_j = 1 To it_mxbt
  1983. If outwaremx_mx[ll_i].printid = outwaremx[ll_j].printid Then
  1984. If outwaremx[ll_j].ifpackpro = 1 Then
  1985. ll_cpmtrlwareid_fp = outwaremx[ll_j].mtrlwareid
  1986. ll_cpmtrlid_fp = outwaremx[ll_j].mtrlid
  1987. Else
  1988. Goto _next_mx
  1989. End If
  1990. End If
  1991. Next
  1992. If ll_cpmtrlwareid_fp = 0 Then Goto _next_mx
  1993. If uo_pack.uof_add_fpqty_out(scid,ll_mtrlwareid_fp,ll_mtrlid_fp,ll_cpmtrlwareid_fp,ll_cpmtrlid_fp,0 - outwaremx_mx[ll_i].qty,arg_msg,False) = 0 Then
  1994. rslt = 0
  1995. Goto ext
  1996. End If
  1997. End If
  1998. _next_mx:
  1999. Next
  2000. End If
  2001. flag = 0
  2002. ext:
  2003. If rslt = 0 Then
  2004. Rollback Using commit_transaction;
  2005. ElseIf rslt = 1 And arg_ifcommit Then
  2006. Commit Using commit_transaction;
  2007. End If
  2008. Destroy uo_task
  2009. Destroy uo_in
  2010. Destroy uo_out
  2011. Destroy uo_ma
  2012. Destroy uo_sout
  2013. Destroy uo_pro
  2014. Destroy ds_out_assign
  2015. destroy uo_pack
  2016. Return rslt
  2017. end function
  2018. public function integer c_priceaudit (long arg_scid, long arg_outwareid, boolean arg_ifcommit, ref string arg_msg);Long rslt = 1,i
  2019. DateTime null_dt
  2020. Long cnt
  2021. Long ll_pda_hh
  2022. IF uo_option_outware_saleout = -1000 THEN
  2023. rslt = 0
  2024. arg_msg = '选项:[147]使用销售出仓单,读取初始默认值失败,操作取消!'
  2025. GOTO ext
  2026. END IF
  2027. IF uo_option_checkprice_native = -1000 THEN
  2028. rslt = 0
  2029. arg_msg = '选项:[056]销售价按本位币限价,读取初始默认值失败,操作取消!'
  2030. GOTO ext
  2031. END IF
  2032. IF uo_option_inout_type = -1000 THEN
  2033. rslt = 0
  2034. arg_msg = '选项:[142]进出仓高级选项,读取初始默认值失败,操作取消!'
  2035. GOTO ext
  2036. END IF
  2037. IF uo_option_confirmaudit_sale = -1000 THEN
  2038. rslt = 0
  2039. arg_msg = '选项:[025]销售单先确认后审核,读取初始默认值失败,操作取消!'
  2040. GOTO ext
  2041. END IF
  2042. IF uo_option_pda_sale_lock = -1000 THEN
  2043. rslt = 0
  2044. arg_msg = '选项:[310]PDA销售发货加锁,读取初始默认值失败,操作取消!'
  2045. GOTO ext
  2046. END IF
  2047. uo_cusprice uo_price
  2048. uo_outware uo_out
  2049. SetNull(null_dt)
  2050. IF arg_scid < 0 THEN
  2051. rslt = 0
  2052. arg_msg = "错误的分部ID"
  2053. GOTO ext
  2054. END IF
  2055. IF arg_outwareid <= 0 THEN
  2056. rslt = 0
  2057. arg_msg = "没有确认对象"
  2058. GOTO ext
  2059. END IF
  2060. IF getinfo(arg_scid,arg_outwareid,arg_msg) = 0 THEN
  2061. rslt = 0
  2062. GOTO ext
  2063. END IF
  2064. IF priceflag = 0 THEN
  2065. rslt = 0
  2066. arg_msg = "单据还未确认,不能反确认"
  2067. GOTO ext
  2068. END IF
  2069. IF uo_option_confirmaudit_sale = 1 THEN
  2070. IF flag = 1 THEN
  2071. rslt = 0
  2072. arg_msg = "销售单已仓审,不能反确认"
  2073. GOTO ext
  2074. END IF
  2075. END IF
  2076. Int li_outtype_storage
  2077. Long mx_barcode_cnt
  2078. SELECT outtype
  2079. INTO :li_outtype_storage
  2080. FROM u_storage
  2081. Where storageid = :storageid Using commit_transaction ;
  2082. IF commit_transaction.SQLCode <> 0 THEN
  2083. rslt = 0
  2084. arg_msg = "查询操作失败,仓库"
  2085. GOTO ext
  2086. END IF
  2087. IF li_outtype_storage = 2 THEN
  2088. FOR i = 1 To it_mxbt
  2089. IF li_outtype_storage = 2 And outwaremx[i].outtype_mtrl = 2 THEN mx_barcode_cnt++
  2090. NEXT
  2091. END IF
  2092. IF uo_option_pda_sale_lock = 1 And uo_option_inout_type = 2 And li_outtype_storage = 2 THEN
  2093. IF pda_flag = 1 THEN
  2094. SELECT Top 1 DATEDIFF(hh, :pda_date, getdate()) Into :ll_pda_hh From u_user Using commit_transaction;
  2095. IF commit_transaction.SQLCode <> 0 THEN
  2096. rslt = 0
  2097. arg_msg = "查询单据条码扫描开始时间与当前时间的小时间隔失败,"+commit_transaction.SQLErrText
  2098. GOTO ext
  2099. END IF
  2100. IF ll_pda_hh < 4 THEN
  2101. rslt = 0
  2102. arg_msg = "单据正在扫描条码,不能反确认,操作取消"
  2103. GOTO ext
  2104. END IF
  2105. END IF
  2106. END IF
  2107. IF uo_option_inout_type = 2 And li_outtype_storage = 2 And mx_barcode_cnt > 0 THEN
  2108. SELECT count(*) INTO :cnt
  2109. FROM u_outwaremx_mx_barcode
  2110. WHERE scid = :arg_scid
  2111. AND outwareid = :arg_outwareid
  2112. And billtype = 1 Using commit_transaction;
  2113. IF commit_transaction.SQLCode <> 0 THEN
  2114. rslt = 0
  2115. arg_msg = "查询单据是否已扫描条码失败,"+commit_transaction.SQLErrText
  2116. GOTO ext
  2117. END IF
  2118. IF cnt > 0 THEN
  2119. rslt = 0
  2120. arg_msg = "单据已扫描条码,不能反确认,如需反确认请与仓库协商先清除已扫描条码"
  2121. GOTO ext
  2122. END IF
  2123. END IF
  2124. uo_price = Create uo_cusprice
  2125. uo_out = Create uo_outware
  2126. uo_out.commit_transaction = sqlca
  2127. uo_out.if_getid_ture = False
  2128. FOR i = 1 To it_mxbt
  2129. IF outwaremx[i].outtype <> '' THEN CONTINUE
  2130. IF uo_option_checkprice_native = 1 THEN
  2131. IF uo_price.uof_check_price (cusid,outwaremx[i].mtrlid,&
  2132. outwaremx[i].mtrlcode,outwaremx[i].status,outwaremx[i].pcode,&
  2133. outwaremx[i].woodcode,relint_2,outwaremx[i].price,outwaremx[i].uqty,arg_msg) = 0 THEN
  2134. rslt = 0
  2135. GOTO ext
  2136. END IF
  2137. ELSE
  2138. IF uo_price.uof_check_price (cusid,outwaremx[i].mtrlid,&
  2139. outwaremx[i].mtrlcode,outwaremx[i].status,outwaremx[i].pcode,&
  2140. outwaremx[i].woodcode,relint_2,outwaremx[i].enprice * outwaremx[i].enprice,outwaremx[i].uqty,arg_msg) = 0 THEN
  2141. rslt = 0
  2142. GOTO ext
  2143. END IF
  2144. END IF
  2145. NEXT
  2146. IF uo_option_outware_saleout = 1 THEN
  2147. cnt = 0
  2148. Long ll_outwareid[]
  2149. Long ll_itmx = 1,ll_i
  2150. SELECT count(*) INTO :cnt
  2151. FROM u_outware
  2152. WHERE billtype = 21
  2153. AND relid = :arg_outwareid
  2154. AND scid = :arg_scid
  2155. And flag = 1 Using commit_transaction;
  2156. IF commit_transaction.SQLCode <> 0 THEN
  2157. rslt = 0
  2158. arg_msg = "查询相关出仓单失败"+"~n"+commit_transaction.SQLErrText
  2159. GOTO ext
  2160. END IF
  2161. IF cnt > 0 THEN
  2162. rslt = 0
  2163. arg_msg = '相关出仓单已仓审,不能反确认,请检查'
  2164. GOTO ext
  2165. END IF
  2166. DECLARE cur_mx CURSOR FOR
  2167. SELECT outwareid
  2168. FROM u_outware
  2169. WHERE billtype = 21
  2170. AND relid = :arg_outwareid
  2171. And scid = :arg_scid Using commit_transaction;
  2172. OPEN cur_mx;
  2173. FETCH cur_mx Into :ll_outwareid[ll_itmx];
  2174. DO WHILE commit_transaction.SQLCode = 0
  2175. ll_itmx++
  2176. FETCH cur_mx Into :ll_outwareid[ll_itmx];
  2177. LOOP
  2178. ll_itmx = ll_itmx - 1
  2179. FOR ll_i = 1 To ll_itmx
  2180. IF uo_out.del(arg_scid,ll_outwareid[ll_i],0,arg_msg,False) = 0 THEN
  2181. rslt = 0
  2182. arg_msg = '删除相关出仓单失败,' + arg_msg
  2183. GOTO ext
  2184. END IF
  2185. NEXT
  2186. END IF
  2187. If uo_option_outware_saleout > 0 Then
  2188. //增加库存已开单数
  2189. If uof_noauditingqty_add(arg_scid,billtype,relint_1,arg_msg) = 0 Then
  2190. rslt = 0
  2191. Goto ext
  2192. End If
  2193. End If
  2194. UPDATE u_outware
  2195. SET priceemp = '',
  2196. pricedate = :null_dt,
  2197. priceflag = 0
  2198. WHERE u_outware.outwareid = :arg_outwareid
  2199. AND priceflag = 1
  2200. And scid = :arg_scid Using commit_transaction;
  2201. IF commit_transaction.SQLCode <> 0 THEN
  2202. rslt = 0
  2203. arg_msg = "因网络或其它原因导致反确认单据操作失败"+"~n"+commit_transaction.SQLErrText
  2204. GOTO ext
  2205. ELSEIF commit_transaction.SQLNRows = 0 THEN
  2206. rslt = 0
  2207. arg_msg = "单据正在反确认,请稍后查询。"+"~n"+commit_transaction.SQLErrText
  2208. GOTO ext
  2209. END IF
  2210. priceflag = 0
  2211. ext:
  2212. IF rslt = 0 THEN
  2213. ROLLBACK Using commit_transaction;
  2214. ELSEIF rslt = 1 And arg_ifcommit THEN
  2215. COMMIT Using commit_transaction;
  2216. END IF
  2217. Destroy uo_price
  2218. Destroy uo_out
  2219. RETURN rslt
  2220. end function
  2221. public function integer uof_create_owe (ref string arg_msg);Int rslt = 1
  2222. Long ll_i,ll_j,ll_k
  2223. Long ll_printid,ll_mtrlid
  2224. Int li_ifpackpro,li_outtype
  2225. String ls_pf_status[],ls_pf_woodcode[],ls_pf_pcode[]
  2226. Int li_ifover[],li_dipztype[]
  2227. Decimal ld_Sonscale[]
  2228. Long ll_SonMtrlid[]
  2229. Long it_mxt = 1
  2230. String ls_status_find,ls_woodcode_find,ls_pcode_find
  2231. String ls_status,ls_woodcode,ls_pcode
  2232. Decimal ld_qty,ld_pfqty
  2233. Long count
  2234. Long ll_taskid
  2235. String ls_taskcode,ls_taskrelcode
  2236. uo_owegood uo_owe
  2237. uo_owe = CREATE uo_owegood
  2238. s_owegood arg_s_owe
  2239. FOR ll_i = 1 TO it_mxbt
  2240. ll_mtrlid = outwaremx[ll_i].mtrlid
  2241. ls_status = outwaremx[ll_i].status
  2242. ls_woodcode = outwaremx[ll_i].woodcode
  2243. ls_pcode = outwaremx[ll_i].pcode
  2244. ll_printid = outwaremx[ll_i].printid
  2245. ld_qty = outwaremx[ll_i].qty
  2246. ll_taskid = outwaremx[ll_i].relid
  2247. IF ll_taskid > 0 THEN
  2248. SELECT taskcode,relcode
  2249. INTO :ls_taskcode,:ls_taskrelcode
  2250. FROM u_saletask
  2251. WHERE taskid = :ll_taskid
  2252. AND scid = :scid using commit_transaction;
  2253. IF commit_transaction.SQLCode <> 0 THEN
  2254. rslt = 0
  2255. arg_msg = '查询明细相关订单失败'+commit_transaction.SQLErrText
  2256. GOTO ext
  2257. END IF
  2258. END IF
  2259. SELECT outtype,ifpackpro INTO :li_outtype,:li_ifpackpro
  2260. FROM u_mtrldef
  2261. Where mtrlid = :ll_mtrlid using commit_transaction;
  2262. IF commit_transaction.SQLCode <> 0 THEN
  2263. arg_msg = '查询产品出仓类型失败'+commit_transaction.SQLErrText
  2264. rslt = 0
  2265. GOTO ext
  2266. END IF
  2267. it_mxt = 1 //yyx20100424
  2268. IF li_outtype <> 0 THEN
  2269. DECLARE cur_pf CURSOR FOR
  2270. SELECT u_PrdPF.SonMtrlid,
  2271. u_PrdPF.status,
  2272. u_PrdPF.woodcode,
  2273. u_PrdPF.pcode,
  2274. u_PrdPF.ifover,
  2275. u_prdpf.dipztype,
  2276. u_prdpf.Sonscale
  2277. FROM u_PrdPF,u_mtrl_pf
  2278. WHERE ( u_PrdPF.mtrlid = u_mtrl_pf.mtrlid )
  2279. AND ( u_PrdPF.pfcode = u_mtrl_pf.pfcode )
  2280. AND ( u_PrdPF.mtrlid = :ll_mtrlid )
  2281. AND ( u_mtrl_pf.ifdi = 1 AND :li_ifpackpro = 0
  2282. OR u_mtrl_pf.ifdft = 1 AND :li_ifpackpro = 1 ) using commit_transaction;
  2283. OPEN cur_pf;
  2284. FETCH cur_pf INTO :ll_SonMtrlid[it_mxt],:ls_pf_status[it_mxt],
  2285. :ls_pf_woodcode[it_mxt],:ls_pf_pcode[it_mxt],:li_ifover[it_mxt],
  2286. :li_dipztype[it_mxt],:ld_Sonscale[it_mxt];
  2287. DO WHILE sqlca.SQLCode = 0
  2288. it_mxt++
  2289. FETCH cur_pf INTO :ll_SonMtrlid[it_mxt],:ls_pf_status[it_mxt],
  2290. :ls_pf_woodcode[it_mxt],:ls_pf_pcode[it_mxt],:li_ifover[it_mxt],
  2291. :li_dipztype[it_mxt],:ld_Sonscale[it_mxt];
  2292. LOOP
  2293. it_mxt = it_mxt - 1
  2294. CLOSE cur_pf;
  2295. FOR ll_k = 1 TO it_mxt
  2296. IF li_ifover[ll_k] = 1 THEN
  2297. CHOOSE CASE li_dipztype[ll_k]
  2298. CASE 0
  2299. ls_status_find = ls_status
  2300. ls_woodcode_find = ''
  2301. ls_pcode_find = ''
  2302. CASE 1
  2303. ls_status_find = ''
  2304. ls_woodcode_find = ls_woodcode
  2305. ls_pcode_find = ''
  2306. CASE 2
  2307. ls_status_find = ''
  2308. ls_woodcode_find = ''
  2309. ls_pcode_find = ls_pcode
  2310. CASE 3
  2311. ls_status_find = ls_status
  2312. ls_woodcode_find = ls_woodcode
  2313. ls_pcode_find = ''
  2314. CASE 4
  2315. ls_status_find = ''
  2316. ls_woodcode_find = ls_woodcode
  2317. ls_pcode_find = ls_pcode
  2318. CASE 5
  2319. ls_status_find = ls_status
  2320. ls_woodcode_find = ''
  2321. ls_pcode_find = ls_pcode
  2322. CASE 6
  2323. ls_status_find = ls_status
  2324. ls_woodcode_find = ls_woodcode
  2325. ls_pcode_find = ls_pcode
  2326. END CHOOSE
  2327. ELSE
  2328. ls_status_find = ls_pf_status[ll_k]
  2329. ls_woodcode_find = ls_pf_woodcode[ll_k]
  2330. ls_pcode_find = ls_pf_pcode[ll_k]
  2331. END IF
  2332. ls_status_find = Trim(ls_status_find)
  2333. ls_woodcode_find = Trim(ls_woodcode_find)
  2334. ls_pcode_find = Trim(ls_pcode_find)
  2335. ld_pfqty = 0
  2336. FOR ll_j = 1 TO it_mxbt_mx
  2337. IF outwaremx_mx[ll_j].printid = ll_printid AND &
  2338. outwaremx_mx[ll_j].mtrlid = ll_SonMtrlid[ll_k] AND &
  2339. outwaremx_mx[ll_j].status = ls_status_find AND &
  2340. outwaremx_mx[ll_j].woodcode = ls_woodcode_find AND &
  2341. outwaremx_mx[ll_j].pcode = ls_pcode_find THEN
  2342. ld_pfqty = ld_pfqty + outwaremx_mx[ll_j].qty
  2343. END IF
  2344. NEXT
  2345. IF ld_qty * ld_Sonscale[ll_k] > ld_pfqty THEN
  2346. count++
  2347. arg_s_owe.arg_s_mx[count].printid = count
  2348. arg_s_owe.arg_s_mx[count].taskid = ll_taskid
  2349. arg_s_owe.arg_s_mx[count].taskprintid = ll_printid
  2350. arg_s_owe.arg_s_mx[count].taskcode = ls_taskcode
  2351. arg_s_owe.arg_s_mx[count].taskrelcode = ls_taskrelcode
  2352. arg_s_owe.arg_s_mx[count].taskmtrlid = ll_mtrlid
  2353. arg_s_owe.arg_s_mx[count].mtrlid = ll_SonMtrlid[ll_k]
  2354. arg_s_owe.arg_s_mx[count].status = ls_status_find
  2355. arg_s_owe.arg_s_mx[count].woodcode = ls_woodcode_find
  2356. arg_s_owe.arg_s_mx[count].pcode = ls_pcode_find
  2357. arg_s_owe.arg_s_mx[count].plancode = outwaremx[ll_i].plancode
  2358. arg_s_owe.arg_s_mx[count].qty = ld_qty * ld_Sonscale[ll_k] - ld_pfqty
  2359. arg_s_owe.arg_s_mx[count].mxdscrp = ''
  2360. IF ll_taskid > 0 THEN
  2361. arg_s_owe.arg_s_mx[count].ifrel = 1
  2362. ELSE
  2363. arg_s_owe.arg_s_mx[count].ifrel = 0
  2364. END IF
  2365. END IF
  2366. NEXT
  2367. END IF
  2368. NEXT
  2369. IF count > 0 THEN
  2370. arg_s_owe.scid = scid
  2371. arg_s_owe.billid = 0
  2372. arg_s_owe.cusid = cusid
  2373. arg_s_owe.loandate = outdate
  2374. arg_s_owe.relcode = outwarecode
  2375. arg_s_owe.dscrp = '销售发货单仓审自动生成'
  2376. arg_s_owe.assignemp = outrep
  2377. arg_s_owe.storageid = storageid
  2378. arg_s_owe.ifaddware = 0
  2379. arg_s_owe.relid = outwareid
  2380. IF uo_owe.Save(arg_s_owe,publ_operator,arg_msg,FALSE) = 0 THEN
  2381. rslt = 0
  2382. GOTO ext
  2383. END IF
  2384. END IF
  2385. ext:
  2386. IF rslt = 0 THEN
  2387. ROLLBACK;
  2388. END IF
  2389. DESTROY uo_owe
  2390. RETURN rslt
  2391. end function
  2392. public function integer auditing_th (boolean arg_ifcommit, ref string arg_msg);
  2393. Long rslt = 1,cnt = 0,i,j,k
  2394. Long chc
  2395. Long rst_outwareid //
  2396. Long rst_inwareid //
  2397. Long ll_i,ll_j,ll_k
  2398. Int li_ifpack,li_ifunit,li_ifpackpro
  2399. Int li_ifpackcnt,li_ifpackprocnt
  2400. Decimal ld_rate,ld_uqty,ld_rate_buy
  2401. Decimal ld_fprice,ld_uprice
  2402. String ls_uunit,ls_unit_buy,ls_unit
  2403. Long ll_storageid_arr[]
  2404. Long mx_barcode_cnt
  2405. Decimal ld_ref_costamt
  2406. Int li_flag
  2407. Int li_ifvqty
  2408. s_inwaremx s_mx
  2409. s_outwaremx s_mx_out
  2410. uo_sqlpro uo_pro
  2411. uo_pro = Create uo_sqlpro
  2412. uo_pro.commit_transaction = commit_transaction
  2413. //库存分配ds
  2414. datastore ds_out_assign
  2415. ds_out_assign = Create datastore
  2416. ds_out_assign.DataObject = 'ds_outwaremx_assign_cancel'
  2417. ds_out_assign.SetTransObject(commit_transaction)
  2418. uo_mtrlware_assign uo_ma
  2419. uo_ma = Create uo_mtrlware_assign
  2420. uo_ma.commit_transaction = commit_transaction
  2421. If uo_option_outware_saleout = -1000 Then
  2422. rslt = 0
  2423. arg_msg = '选项:[147]使用销售出仓单,读取初始默认值失败,操作取消!'
  2424. Goto ext
  2425. End If
  2426. If uo_option_inout_type = -1000 Then
  2427. rslt = 0
  2428. arg_msg = '选项:[142]进出仓高级选项,读取初始默认值失败,操作取消!'
  2429. Goto ext
  2430. End If
  2431. If uo_option_confirmaudit_sale = -1000 Then
  2432. rslt = 0
  2433. arg_msg = '选项:[025]销售单先确认后审核,读取初始默认值失败,操作取消!'
  2434. Goto ext
  2435. End If
  2436. uo_saletask uo_task
  2437. uo_task = Create uo_saletask
  2438. uo_task.commit_transaction = commit_transaction
  2439. If storageid = 0 Then
  2440. rslt = 0
  2441. arg_msg = '没有正确的仓库'
  2442. Goto ext
  2443. End If
  2444. If billtype <> 9 Then
  2445. If uof_check_warepdb_audit(storageid,arg_msg) = 0 Then
  2446. rslt = 0
  2447. Goto ext
  2448. End If
  2449. End If
  2450. String ls_storagename
  2451. Int li_outtype_storage,li_storagetype
  2452. Select storagename,outtype,storagetype
  2453. Into :ls_storagename,:li_outtype_storage,:li_storagetype
  2454. From u_storage
  2455. Where storageid = :storageid Using commit_transaction ;
  2456. If commit_transaction.SQLCode <> 0 Then
  2457. rslt = 0
  2458. arg_msg = "查询操作失败,仓库"
  2459. Goto ext
  2460. End If
  2461. //检查是否有该仓库的建立权限
  2462. If sys_user_storagestr_audit <> '0' Then
  2463. If Pos(sys_user_storagestr_audit,','+String(storageid)+',') <= 0 Then
  2464. rslt = 0
  2465. arg_msg = '没有仓库: '+ls_storagename+' 的审核权限,不允许审核该仓库的单据'
  2466. Goto ext
  2467. End If
  2468. End If
  2469. //
  2470. If outwareid = 0 Then
  2471. rslt = 0
  2472. arg_msg = "没有审核对象"
  2473. Goto ext
  2474. End If
  2475. If flag = 1 Then
  2476. rslt = 0
  2477. arg_msg = "单据已经审核"
  2478. Goto ext
  2479. End If
  2480. If uo_option_confirmaudit_sale = 1 Then
  2481. If priceflag = 0 Then
  2482. rslt = 0
  2483. arg_msg = "销售单要确认后才能审核"
  2484. Goto ext
  2485. End If
  2486. End If
  2487. Update u_outware
  2488. Set Auditingrep = :publ_operator,
  2489. Auditingdate = getdate(),
  2490. flag = 1
  2491. Where u_outware.outwareid = :outwareid
  2492. And flag = 0
  2493. And scid = :scid Using commit_transaction;
  2494. If commit_transaction.SQLCode <> 0 Then
  2495. rslt = 0
  2496. arg_msg = "因网络或其它原因导致审核单据操作失败"+"~n"+commit_transaction.SQLErrText
  2497. Goto ext
  2498. ElseIf commit_transaction.SQLNRows = 0 Then
  2499. rslt = 0
  2500. arg_msg = "单据正在审核,请稍后查询。"+"~n"+commit_transaction.SQLErrText
  2501. Goto ext
  2502. End If
  2503. uo_inware uo_in
  2504. uo_outware uo_out
  2505. uo_in = Create uo_inware
  2506. uo_in.commit_transaction = sqlca
  2507. uo_in.if_getid_ture = False
  2508. uo_out = Create uo_outware
  2509. uo_out.commit_transaction = sqlca
  2510. uo_out.if_getid_ture = False
  2511. For i = 1 To it_mxbt
  2512. ld_ref_costamt = 0
  2513. If p_update_cost(outwaremx[i].mtrlwareid,outwaremx[i].mtrlcode,&
  2514. outwaremx[i].qty,outwaremx[i].printid,ld_ref_costamt,arg_msg,False) = 0 Then
  2515. arg_msg = '退货明细行:'+String(i)+','+arg_msg
  2516. rslt = 0
  2517. Goto ext
  2518. End If
  2519. If ld_ref_costamt = 0 Then
  2520. ld_ref_costamt = Round(outwaremx[i].qty * outwaremx[i].planprice,2)
  2521. End If
  2522. If sys_option_inout_procedure = 0 Then
  2523. If p_update_mtrlware ( outwaremx[i].mtrlwareid, outwaremx[i].mtrlid, &
  2524. outwaremx[i].mtrlcode, storageid, outwaremx[i].plancode,&
  2525. outwaremx[i].status, outwaremx[i].qty,outwaremx[i].uqty, ld_ref_costamt,&
  2526. outwaremx[i].planprice, outwaremx[i].sptid,outwaremx[i].dxflag,&
  2527. outwaremx[i].woodcode,outwaremx[i].pcode,outwaremx[i].mtrlcuscode,&
  2528. outwaremx[i].Location,outwaremx[i].ifvqty,arg_msg) = 0 Then
  2529. arg_msg = '退货明细行:'+String(i)+','+arg_msg
  2530. rslt = 0
  2531. Goto ext
  2532. End If
  2533. Else
  2534. If uo_pro.p_outware_update_mtrlware(scid,outwareid,outwaremx[i].printid,outwaremx[i].mtrlwareid,&
  2535. outwaremx[i].mtrlid,outwaremx[i].mtrlcode,storageid,outwaremx[i].plancode,outwaremx[i].status,&
  2536. outwaremx[i].qty,outwaremx[i].uqty,ld_ref_costamt,&
  2537. outwaremx[i].planprice, outwaremx[i].sptid,outwaremx[i].dxflag,&
  2538. outwaremx[i].woodcode, outwaremx[i].pcode,outwaremx[i].mtrlcuscode,outwaremx[i].Location,arg_msg) = 0 Then
  2539. arg_msg = '退货明细行:'+String(i)+','+arg_msg
  2540. rslt = 0
  2541. Goto ext
  2542. End If
  2543. End If
  2544. If (billtype = 1 Or billtype = 5) And outwaremx[i].relid > 0 Then
  2545. If uo_task.addmxcmpl(scid,outwaremx[i].relid,outwaremx[i].relprintid,outwaremx[i].qty,arg_msg,False) <> 1 Then
  2546. arg_msg = '退货明细行:'+String(i)+','+arg_msg
  2547. rslt = 0
  2548. Goto ext
  2549. End If
  2550. End If
  2551. If (billtype = 1 Or billtype = 5) And outwaremx[i].relid > 0 Then
  2552. Select status Into :li_flag
  2553. From u_saletask
  2554. Where scid = :scid
  2555. And taskid = :outwaremx[i].relid Using commit_transaction;
  2556. If commit_transaction.SQLCode <> 0 Then
  2557. rslt = 0
  2558. arg_msg = '查询相关订单状态失败,'+sqlca.SQLErrText
  2559. arg_msg = '退货明细行:'+String(i)+','+arg_msg
  2560. Goto ext
  2561. End If
  2562. If li_flag = 1 Or li_flag = 5 Then
  2563. If uo_task.trycmplsaletask(scid,outwaremx[i].relid,arg_msg,False) = 0 Then
  2564. arg_msg = '退货明细行:'+String(i)+','+arg_msg
  2565. rslt = 0
  2566. Goto ext
  2567. End If
  2568. End If
  2569. End If
  2570. //更新库存分配yyx20130130
  2571. Decimal ld_assign_outqty,ld_sumnotoutqty,ld_outmxqty
  2572. Long ll_row
  2573. If billtype = 1 And li_storagetype = 1 And li_outtype_storage = 0 And outwaremx[i].relid > 0 Then
  2574. ll_row = ds_out_assign.Retrieve(scid,outwaremx[i].mtrlwareid,outwaremx[i].relid,outwaremx[i].relprintid)
  2575. ds_out_assign.AcceptText()
  2576. If ll_row <= 0 Then
  2577. ld_sumnotoutqty = 0
  2578. Else
  2579. ld_sumnotoutqty = ds_out_assign.Object.sumnotoutqty[1]
  2580. End If
  2581. ld_outmxqty = Abs(outwaremx[i].qty)
  2582. If ld_outmxqty > ld_sumnotoutqty Then
  2583. arg_msg = '退货明细行:'+String(i)+'订单库存分配已出仓数不足,不能撤审,请检查库存分配已出仓明细'
  2584. rslt = 0
  2585. Goto ext
  2586. Else
  2587. ld_assign_outqty = 0
  2588. For j = 1 To ds_out_assign.RowCount()
  2589. If ds_out_assign.Object.notoutqty[j] >= ld_outmxqty Then
  2590. ld_assign_outqty = ld_outmxqty
  2591. If uo_ma.uof_assign_addoutqty(ds_out_assign.Object.assignid[j],0 - ld_assign_outqty,arg_msg,False) = 0 Then
  2592. arg_msg = '退货明细行:'+String(i)+','+arg_msg
  2593. rslt = 0
  2594. Goto ext
  2595. End If
  2596. Exit
  2597. Else
  2598. ld_assign_outqty = ds_out_assign.Object.notoutqty[j]
  2599. If uo_ma.uof_assign_addoutqty(ds_out_assign.Object.assignid[j],0 - ld_assign_outqty,arg_msg,False) = 0 Then
  2600. arg_msg = '退货明细行:'+String(i)+','+arg_msg
  2601. rslt = 0
  2602. Goto ext
  2603. End If
  2604. ld_outmxqty = ld_outmxqty - ds_out_assign.Object.notoutqty[j]
  2605. End If
  2606. Next
  2607. End If
  2608. End If
  2609. If li_outtype_storage = 2 And outwaremx[i].outtype_mtrl = 2 Then mx_barcode_cnt++
  2610. Next
  2611. If li_outtype_storage <> 0 And uo_option_outware_saleout = 0 Then
  2612. cnt = 1
  2613. For ll_i = 1 To it_mxbt_mx
  2614. If ll_i = 1 Then
  2615. ll_storageid_arr[cnt] = outwaremx_mx[ll_i].storageid
  2616. Goto _next
  2617. End If
  2618. For ll_j = 1 To cnt
  2619. If ll_storageid_arr[ll_j] = outwaremx_mx[ll_i].storageid Then
  2620. Goto _next
  2621. End If
  2622. Next
  2623. cnt++
  2624. ll_storageid_arr[cnt] = outwaremx_mx[ll_i].storageid
  2625. _next:
  2626. Next
  2627. For ll_i = 1 To cnt
  2628. If uo_out.newbegin(scid,21,arg_msg) = 0 Then
  2629. arg_msg = '退货单(包件明细),' + arg_msg
  2630. rslt = 0
  2631. Goto ext
  2632. End If
  2633. uo_out.relid = outwareid
  2634. uo_out.outdate = outdate
  2635. uo_out.outrep = outrep
  2636. uo_out.part = outwarecode
  2637. uo_out.dscrp = dscrp
  2638. uo_out.cusname = '包件明细自动出仓'
  2639. uo_out.storageid = ll_storageid_arr[ll_i]
  2640. uo_out.thflag = 1
  2641. chc = 0
  2642. For i = 1 To it_mxbt_mx
  2643. If outwaremx_mx[i].storageid <> ll_storageid_arr[ll_i] Then Continue
  2644. Select ifpack,ifunit,unit,rate_buy,unit_buy
  2645. Into :li_ifpack,:li_ifunit,:ls_unit,:ld_rate_buy,:ls_unit_buy
  2646. From u_mtrldef
  2647. Where mtrlid = :outwaremx_mx[i].mtrlid;
  2648. If commit_transaction.SQLCode <> 0 Then
  2649. rslt = 0
  2650. arg_msg = '退货单(包件明细)行:'+String(i)+",因网络或其它原因导致查询应发明细操作失败"+"~n"+commit_transaction.SQLErrText
  2651. Goto ext
  2652. End If
  2653. chc++
  2654. f_get_planprice_mtrl(outwaremx_mx[i].mtrlid,outwaremx_mx[i].status,outwaremx_mx[i].woodcode,outwaremx_mx[i].pcode,ld_fprice)
  2655. If li_ifunit = 0 Then
  2656. ls_uunit = ls_unit
  2657. ld_rate = 1
  2658. ld_uqty = outwaremx_mx[i].qty
  2659. Else
  2660. If ld_rate_buy = 0 Then
  2661. arg_msg = '退货单(包件明细)行:'+String(i)+',资料设为双数量核算,但没有设置默认转换率,请检查'
  2662. rslt = 0
  2663. Goto ext
  2664. End If
  2665. ls_uunit = ls_unit_buy
  2666. ld_rate = ld_rate_buy
  2667. ld_uqty = outwaremx_mx[i].qty /ld_rate_buy
  2668. End If
  2669. li_ifvqty = 0
  2670. For k = 1 To it_mxbt
  2671. If outwaremx[k].printid = outwaremx_mx[i].printid Then
  2672. If outwaremx[k].mtrlid = outwaremx_mx[i].mtrlid And &
  2673. outwaremx[k].status = outwaremx_mx[i].status And &
  2674. outwaremx[k].woodcode = outwaremx_mx[i].woodcode And &
  2675. outwaremx[k].pcode = outwaremx_mx[i].pcode Then
  2676. li_ifvqty = 1
  2677. Else
  2678. li_ifvqty = 0
  2679. End If
  2680. Exit
  2681. End If
  2682. Next
  2683. s_mx_out.mtrlwareid = outwaremx_mx[i].mtrlwareid
  2684. s_mx_out.qty = outwaremx_mx[i].qty
  2685. s_mx_out.fprice = ld_fprice
  2686. s_mx_out.rebate = 1
  2687. s_mx_out.mxdscrp = outwaremx_mx[i].mxdscrp
  2688. s_mx_out.printid = chc
  2689. s_mx_out.ifrel = 0
  2690. s_mx_out.relid = 0
  2691. s_mx_out.olmtrlid = outwaremx_mx[i].printid
  2692. s_mx_out.packqty = 0
  2693. s_mx_out.outtype = ''
  2694. s_mx_out.planqty = 0
  2695. s_mx_out.relprintid = outwaremx_mx[i].mxprintid
  2696. s_mx_out.unit = ls_uunit
  2697. s_mx_out.uqty = ld_uqty
  2698. s_mx_out.rate = ld_rate
  2699. s_mx_out.pricetype = ''
  2700. s_mx_out.formula = ''
  2701. s_mx_out.saleoutid = 0
  2702. s_mx_out.saleoutprintid = 0
  2703. s_mx_out.mxdscrp2 = ''
  2704. s_mx_out.net_weight = 0
  2705. s_mx_out.gross_weight = 0
  2706. s_mx_out.cubage = 0
  2707. s_mx_out.taxrate = 0
  2708. s_mx_out.priceformula = ''
  2709. s_mx_out.qtyformula = ''
  2710. s_mx_out.ifnotinout = outwaremx_mx[i].ifnotinout
  2711. s_mx_out.ifvqty = li_ifvqty
  2712. If uo_out.acceptmx(s_mx_out,arg_msg) = 0 Then
  2713. arg_msg = '退货单(包件明细)'+String(i)+','+arg_msg
  2714. rslt = 0
  2715. Goto ext
  2716. End If
  2717. // IF uo_out.acceptmx(outwaremx_mx[i].mtrlwareid,&
  2718. // outwaremx_mx[i].qty,ld_fprice,1,&
  2719. // outwaremx_mx[i].mxdscrp,chc,arg_msg,0,0,outwaremx_mx[i].printid,0,'',0,outwaremx_mx[i].mxprintid,&
  2720. // ls_uunit,ld_uqty,ld_rate,'','',0,0,'',0,0,0,0,'','') = 0 THEN
  2721. // arg_msg = '退货单(包件明细)行:'+String(i)+arg_msg
  2722. // rslt = 0
  2723. // GOTO ext
  2724. // END IF
  2725. Next
  2726. If uo_out.Save(False,arg_msg) = 0 Then
  2727. arg_msg = '退货单(包件明细),' + arg_msg
  2728. rslt = 0
  2729. Goto ext
  2730. End If
  2731. rst_outwareid = uo_out.outwareid
  2732. //2.原事务审核出仓单
  2733. If uo_out.getinfo(scid,rst_outwareid,arg_msg) = 0 Then
  2734. arg_msg = '退货单(包件明细),' + arg_msg
  2735. rslt = 0
  2736. Goto ext
  2737. End If
  2738. If uo_out.auditing(False,arg_msg) = 0 Then
  2739. arg_msg = '退货单(包件明细),' + arg_msg
  2740. rslt = 0
  2741. Goto ext
  2742. End If
  2743. Next
  2744. If uo_in.newbegin(scid,23,arg_msg) = 0 Then
  2745. arg_msg = '退货单(退货明细),' + arg_msg
  2746. rslt = 0
  2747. Goto ext
  2748. End If
  2749. uo_in.relid = outwareid
  2750. uo_in.indate = outdate
  2751. uo_in.inrep = outrep
  2752. uo_in.part = outwarecode
  2753. uo_in.dscrp = dscrp
  2754. uo_in.sptname = '银售退货单(退货明细)自动进仓'
  2755. uo_in.storageid = storageid
  2756. chc = 0
  2757. For i = 1 To it_mxbt
  2758. Select ifpackpro,ifunit,unit,rate_buy,unit_buy
  2759. Into :li_ifpackpro,:li_ifunit,:ls_unit,:ld_rate_buy,:ls_unit_buy
  2760. From u_mtrldef
  2761. Where mtrlid = :outwaremx[i].mtrlid;
  2762. If commit_transaction.SQLCode <> 0 Then
  2763. rslt = 0
  2764. arg_msg = '退货单(退货明细)行'+String(i)+",查询应发明细操作失败"+"~n"+commit_transaction.SQLErrText
  2765. Goto ext
  2766. End If
  2767. // IF li_ifpackpro = 1 THEN
  2768. // f_get_planprice_mtrl(outwaremx[i].mtrlid,outwaremx[i].status,outwaremx[i].woodcode,outwaremx[i].pcode,ld_fprice)
  2769. ld_ref_costamt = 0
  2770. If p_update_cost(outwaremx[i].mtrlwareid,outwaremx[i].mtrlcode,&
  2771. outwaremx[i].qty,outwaremx[i].printid,ld_ref_costamt,arg_msg,False) = 0 Then
  2772. arg_msg = '退货单(退货明细)行'+String(i)+','+arg_msg
  2773. rslt = 0
  2774. Goto ext
  2775. End If
  2776. // IF ld_ref_costamt > 0 THEN
  2777. If outwaremx[i].qty <> 0 Then
  2778. ld_fprice = Round(ld_ref_costamt/outwaremx[i].qty,uo_option_cost_dec)
  2779. End If
  2780. // END IF
  2781. chc++
  2782. If li_ifunit = 0 Then
  2783. ls_uunit = ls_unit
  2784. ld_rate = 1
  2785. ld_uqty = outwaremx[i].qty
  2786. ld_uprice = ld_fprice
  2787. Else
  2788. If ld_rate_buy = 0 Then
  2789. arg_msg = '退货单(退货明细)行:'+String(i)+',资料设为双数量核算,但没有设置默认转换率,请检查'
  2790. rslt = 0
  2791. Goto ext
  2792. End If
  2793. ls_uunit = ls_unit_buy
  2794. ld_rate = ld_rate_buy
  2795. ld_uqty = outwaremx[i].qty /ld_rate_buy
  2796. ld_uprice = ld_fprice * ld_rate
  2797. End If
  2798. s_mx.printid = chc
  2799. s_mx.mtrlid = outwaremx[i].mtrlid
  2800. s_mx.mtrlcode = outwaremx[i].mtrlcode
  2801. s_mx.plancode = outwaremx[i].plancode
  2802. s_mx.status = outwaremx[i].status
  2803. s_mx.uqty = ld_uqty
  2804. s_mx.enprice = ld_uprice
  2805. s_mx.rebate = 1
  2806. s_mx.mxdscrp = outwaremx[i].mxdscrp
  2807. s_mx.jgprice = 0
  2808. s_mx.relid = 0
  2809. s_mx.ifrel = 0
  2810. s_mx.woodcode = outwaremx[i].woodcode
  2811. s_mx.pcode = outwaremx[i].pcode
  2812. s_mx.sptid = outwaremx[i].sptid
  2813. s_mx.unit = ls_uunit
  2814. s_mx.rate = ld_rate
  2815. s_mx.qty = outwaremx[i].qty
  2816. s_mx.relprintid = 0
  2817. s_mx.checkqty = 0
  2818. s_mx.result = ''
  2819. s_mx.waredscrp = ''
  2820. s_mx.relbillid = 0
  2821. s_mx.relbillprintid = 0
  2822. s_mx.mtrlcuscode = outwaremx[i].mtrlcuscode
  2823. s_mx.Location = outwaremx[i].Location
  2824. s_mx.deliqty = ld_uqty
  2825. s_mx.tax = 0
  2826. If outwaremx[i].ifpackpro = 0 Then
  2827. s_mx.ifvqty = 1
  2828. s_mx.ifnotinout = 1
  2829. Else
  2830. s_mx.ifvqty = 0
  2831. s_mx.ifnotinout = 0
  2832. End If
  2833. If uo_in.acceptmx(s_mx, arg_msg) = 0 Then
  2834. arg_msg = '退货单(退货明细),行:'+String(i)+','+arg_msg
  2835. rslt = 0
  2836. Goto ext
  2837. End If
  2838. // IF uo_in.acceptmx(chc,&
  2839. // outwaremx[i].mtrlid,&
  2840. // outwaremx[i].mtrlcode,&
  2841. // outwaremx[i].plancode,&
  2842. // outwaremx[i].status,&
  2843. // ld_uqty,&
  2844. // ld_uprice,&
  2845. // 1,&
  2846. // outwaremx[i].mxdscrp,&
  2847. // arg_msg,&
  2848. // 0,0,0,outwaremx[i].woodcode,outwaremx[i].pcode,outwaremx[i].sptid,ls_uunit,ld_rate,&
  2849. // outwaremx[i].qty,0,0,'','',0,0,&
  2850. // outwaremx[i].mtrlcuscode,outwaremx[i].Location,&
  2851. // ld_uqty,&
  2852. // 0) = 0 THEN
  2853. // arg_msg = '退货单(退货明细)行'+String(i)+','+arg_msg
  2854. // rslt = 0
  2855. // GOTO ext
  2856. // END IF
  2857. // END IF
  2858. Next
  2859. If uo_in.Save(False,arg_msg) = 0 Then
  2860. arg_msg = '退货单(退货明细),'+arg_msg
  2861. rslt = 0
  2862. Goto ext
  2863. End If
  2864. rst_inwareid = uo_in.inwareid
  2865. //4.原事务审核进仓单
  2866. If uo_in.getinfo(scid,rst_inwareid,arg_msg) = 0 Then
  2867. arg_msg = '退货单(退货明细),'+arg_msg
  2868. rslt = 0
  2869. Goto ext
  2870. End If
  2871. If uo_in.auditing(False,arg_msg) = 0 Then
  2872. arg_msg = '退货单(退货明细),'+arg_msg
  2873. rslt = 0
  2874. Goto ext
  2875. End If
  2876. // END IF
  2877. //原发货单明细取消分配出仓
  2878. For i = 1 To it_mxbt
  2879. //yyx20130130
  2880. If billtype = 1 And li_storagetype = 1 And li_outtype_storage > 0 And ( outwaremx[i].ifpackpro > 0 And outwaremx[i].ifpackpro <> 4 Or outwaremx[i].ifpackpro = 4 And (Pos(outwaremx[i].status,'+') > 0 Or Pos(outwaremx[i].status,'*') > 0)) And outwaremx[i].relid > 0 Then
  2881. ll_row = ds_out_assign.Retrieve(scid,outwaremx[i].mtrlwareid,outwaremx[i].relid,outwaremx[i].relprintid)
  2882. ds_out_assign.AcceptText()
  2883. If ll_row <= 0 Then
  2884. ld_sumnotoutqty = 0
  2885. Else
  2886. ld_sumnotoutqty = ds_out_assign.Object.sumnotoutqty[1]
  2887. End If
  2888. ld_outmxqty = Abs(outwaremx[i].qty)
  2889. If ld_outmxqty > ld_sumnotoutqty Then
  2890. arg_msg = '退货明细行:'+String(i)+'订单库存分配已出仓数不足,不能撤审,请检查库存分配已出仓明细'
  2891. rslt = 0
  2892. Goto ext
  2893. Else
  2894. ld_assign_outqty = 0
  2895. For j = 1 To ds_out_assign.RowCount()
  2896. If ds_out_assign.Object.notoutqty[j] >= ld_outmxqty Then
  2897. ld_assign_outqty = ld_outmxqty
  2898. If uo_ma.uof_assign_addoutqty(ds_out_assign.Object.assignid[j],0 - ld_assign_outqty,arg_msg,False) = 0 Then
  2899. arg_msg = '发货明细行:'+String(i)+','+arg_msg
  2900. rslt = 0
  2901. Goto ext
  2902. End If
  2903. Exit
  2904. Else
  2905. ld_assign_outqty = ds_out_assign.Object.notoutqty[j]
  2906. If uo_ma.uof_assign_addoutqty(ds_out_assign.Object.assignid[j],0 - ld_assign_outqty,arg_msg,False) = 0 Then
  2907. arg_msg = '发货明细行:'+String(i)+','+arg_msg
  2908. rslt = 0
  2909. Goto ext
  2910. End If
  2911. ld_outmxqty = ld_outmxqty - ds_out_assign.Object.notoutqty[j]
  2912. End If
  2913. Next
  2914. End If
  2915. End If
  2916. //
  2917. Next
  2918. End If
  2919. Long ll_printid_arr[],ll_mtrlwareid_arr[],ll_mtrlid_arr[]
  2920. String ls_status_arr[],ls_woodcode_arr[],ls_pcode_arr[]
  2921. Decimal ld_qty_arr[]
  2922. Long ll_cnt = 1
  2923. Long ll_printid
  2924. Decimal ld_maxqty
  2925. Long ll_mtrlid
  2926. Int li_outtype
  2927. String ls_pf_status[],ls_pf_woodcode[],ls_pf_pcode[]
  2928. Int li_ifover[],li_dipztype[]
  2929. Decimal ld_Sonscale[]
  2930. Long ll_SonMtrlid[]
  2931. Long it_mxt = 1
  2932. String ls_status_find,ls_woodcode_find,ls_pcode_find
  2933. String ls_status,ls_woodcode,ls_pcode
  2934. Decimal ld_pfqty
  2935. If uo_option_outware_saleout = 1 Then
  2936. Declare cur_mx Cursor For
  2937. Select u_outwaremx.relid, u_outwaremx.mtrlwareid, u_outwaremx.mtrlid,
  2938. u_outwaremx.status, u_outwaremx.woodcode, u_outwaremx.pcode,
  2939. u_outwaremx.qty
  2940. From u_outwaremx Inner JOIN
  2941. u_outware ON u_outwaremx.scid = u_outware.scid And
  2942. u_outwaremx.outwareid = u_outware.outwareid
  2943. Where u_outware.relid = :outwareid And
  2944. u_outware.scid = :scid And
  2945. u_outware.billtype = 21 Using commit_transaction;
  2946. Open cur_mx;
  2947. Fetch cur_mx Into :ll_printid_arr[ll_cnt],:ll_mtrlwareid_arr[ll_cnt],:ll_mtrlid_arr[ll_cnt],
  2948. :ls_status_arr[ll_cnt],:ls_woodcode_arr[ll_cnt],:ls_pcode_arr[ll_cnt],:ld_qty_arr[ll_cnt];
  2949. Do While commit_transaction.SQLCode = 0
  2950. ll_cnt++
  2951. Fetch cur_mx Into :ll_printid_arr[ll_cnt],:ll_mtrlwareid_arr[ll_cnt],:ll_mtrlid_arr[ll_cnt],
  2952. :ls_status_arr[ll_cnt],:ls_woodcode_arr[ll_cnt],:ls_pcode_arr[ll_cnt],:ld_qty_arr[ll_cnt];
  2953. Loop
  2954. Close cur_mx;
  2955. ll_cnt = ll_cnt - 1
  2956. For ll_i = 1 To it_mxbt
  2957. ld_maxqty = 0
  2958. it_mxt = 1
  2959. ll_printid = outwaremx[ll_i].printid
  2960. ll_mtrlid = outwaremx[ll_i].mtrlid
  2961. ls_status = outwaremx[ll_i].status
  2962. ls_woodcode = outwaremx[ll_i].woodcode
  2963. ls_pcode = outwaremx[ll_i].pcode
  2964. Select outtype,ifpackpro Into :li_outtype,:li_ifpackpro
  2965. From u_mtrldef
  2966. Where mtrlid = :ll_mtrlid Using commit_transaction;
  2967. If commit_transaction.SQLCode <> 0 Then
  2968. arg_msg = '查询产品出仓类型失败'
  2969. rslt = 0
  2970. Goto ext
  2971. End If
  2972. // IF li_outtype = 0 or li_ifpackpro = 0 THEN
  2973. If Not ((li_outtype = 1 Or li_outtype = 2) And li_ifpackpro = 1) Then
  2974. For ll_j = 1 To ll_cnt
  2975. If ll_mtrlwareid_arr[ll_j] = 0 Then Continue
  2976. If ll_printid_arr[ll_j] = ll_printid Then
  2977. ld_maxqty = ld_qty_arr[ll_j]
  2978. Exit
  2979. End If
  2980. Next
  2981. Update u_outwaremx
  2982. Set qty = :ld_maxqty
  2983. Where outwareid = :outwareid
  2984. And scid = :scid
  2985. And printid = :ll_printid Using commit_transaction;
  2986. If commit_transaction.SQLCode <> 0 Then
  2987. rslt = 0
  2988. arg_msg = '更新实发数失败'
  2989. Goto ext
  2990. End If
  2991. Else
  2992. Declare cur_pf Cursor For
  2993. Select u_PrdPF.SonMtrlid,
  2994. u_PrdPF.status,
  2995. u_PrdPF.woodcode,
  2996. u_PrdPF.pcode,
  2997. u_PrdPF.ifover,
  2998. u_prdpf.dipztype,
  2999. u_prdpf.Sonscale
  3000. From u_PrdPF,u_mtrl_pf
  3001. Where ( u_PrdPF.mtrlid = u_mtrl_pf.mtrlid )
  3002. And ( u_PrdPF.pfcode = u_mtrl_pf.pfcode )
  3003. And ( u_PrdPF.mtrlid = :ll_mtrlid )
  3004. And ( u_mtrl_pf.ifdi = 1 And :li_ifpackpro = 0
  3005. Or u_mtrl_pf.ifdft = 1 And :li_ifpackpro = 1 );
  3006. Open cur_pf;
  3007. Fetch cur_pf Into :ll_SonMtrlid[it_mxt],:ls_pf_status[it_mxt],
  3008. :ls_pf_woodcode[it_mxt],:ls_pf_pcode[it_mxt],:li_ifover[it_mxt],
  3009. :li_dipztype[it_mxt],:ld_Sonscale[it_mxt];
  3010. Do While sqlca.SQLCode = 0
  3011. it_mxt++
  3012. Fetch cur_pf Into :ll_SonMtrlid[it_mxt],:ls_pf_status[it_mxt],
  3013. :ls_pf_woodcode[it_mxt],:ls_pf_pcode[it_mxt],:li_ifover[it_mxt],
  3014. :li_dipztype[it_mxt],:ld_Sonscale[it_mxt];
  3015. Loop
  3016. it_mxt = it_mxt - 1
  3017. Close cur_pf;
  3018. For ll_k = 1 To it_mxt
  3019. If li_ifover[ll_k] = 1 Then
  3020. Choose Case li_dipztype[ll_k]
  3021. Case 0
  3022. ls_status_find = ls_status
  3023. ls_woodcode_find = ''
  3024. ls_pcode_find = ''
  3025. Case 1
  3026. ls_status_find = ''
  3027. ls_woodcode_find = ls_woodcode
  3028. ls_pcode_find = ''
  3029. Case 2
  3030. ls_status_find = ''
  3031. ls_woodcode_find = ''
  3032. ls_pcode_find = ls_pcode
  3033. Case 3
  3034. ls_status_find = ls_status
  3035. ls_woodcode_find = ls_woodcode
  3036. ls_pcode_find = ''
  3037. Case 4
  3038. ls_status_find = ''
  3039. ls_woodcode_find = ls_woodcode
  3040. ls_pcode_find = ls_pcode
  3041. Case 5
  3042. ls_status_find = ls_status
  3043. ls_woodcode_find = ''
  3044. ls_pcode_find = ls_pcode
  3045. Case 6
  3046. ls_status_find = ls_status
  3047. ls_woodcode_find = ls_woodcode
  3048. ls_pcode_find = ls_pcode
  3049. End Choose
  3050. Else
  3051. ls_status_find = ls_pf_status[ll_k]
  3052. ls_woodcode_find = ls_pf_woodcode[ll_k]
  3053. ls_pcode_find = ls_pf_pcode[ll_k]
  3054. End If
  3055. ls_status_find = Trim(ls_status_find)
  3056. ls_woodcode_find = Trim(ls_woodcode_find)
  3057. ls_pcode_find = Trim(ls_pcode_find)
  3058. ld_pfqty = 0
  3059. For ll_j = 1 To ll_cnt
  3060. If ll_mtrlwareid_arr[ll_j] = 0 Then Continue
  3061. If ll_printid_arr[ll_j] = ll_printid And &
  3062. ll_mtrlid_arr[ll_j] = ll_SonMtrlid[ll_k] And &
  3063. ls_status_arr[ll_j] = ls_status_find And &
  3064. ls_woodcode_arr[ll_j] = ls_woodcode_find And &
  3065. ls_pcode_arr[ll_j] = ls_pcode_find Then
  3066. ld_pfqty = ld_pfqty + ld_qty_arr[ll_j] / ld_Sonscale[ll_k]
  3067. End If
  3068. Next
  3069. If thflag = 0 Then
  3070. If ld_pfqty > ld_maxqty Then ld_maxqty = ld_pfqty
  3071. Else
  3072. If ld_pfqty < ld_maxqty Then ld_maxqty = ld_pfqty
  3073. End If
  3074. Next
  3075. Update u_outwaremx
  3076. Set qty = :ld_maxqty
  3077. Where outwareid = :outwareid
  3078. And scid = :scid
  3079. And printid = :ll_printid Using commit_transaction;
  3080. If commit_transaction.SQLCode <> 0 Then
  3081. rslt = 0
  3082. arg_msg = '更新实发数失败'
  3083. Goto ext
  3084. End If
  3085. End If
  3086. outwaremx[ll_i].qty = ld_maxqty
  3087. Next
  3088. If uo_in.newbegin(scid,23,arg_msg) = 0 Then
  3089. rslt = 0
  3090. Goto ext
  3091. End If
  3092. uo_in.relid = outwareid
  3093. uo_in.indate = outdate
  3094. uo_in.inrep = outrep
  3095. uo_in.part = outwarecode
  3096. uo_in.dscrp = dscrp
  3097. uo_in.sptname = '包件自动进仓'
  3098. uo_in.storageid = storageid
  3099. chc = 0
  3100. For i = 1 To it_mxbt
  3101. Select ifpackpro,ifunit,unit,rate_buy,unit_buy
  3102. Into :li_ifpackpro,:li_ifunit,:ls_unit,:ld_rate_buy,:ls_unit_buy
  3103. From u_mtrldef
  3104. Where mtrlid = :outwaremx[i].mtrlid;
  3105. If commit_transaction.SQLCode <> 0 Then
  3106. rslt = 0
  3107. arg_msg = "因网络或其它原因导致查询应发明细操作失败"+"~n"+commit_transaction.SQLErrText
  3108. Goto ext
  3109. End If
  3110. chc++
  3111. f_get_planprice_mtrl(outwaremx[i].mtrlid,outwaremx[i].status,outwaremx[i].woodcode,outwaremx[i].pcode,ld_fprice)
  3112. If li_ifunit = 0 Then
  3113. ls_uunit = ls_unit
  3114. ld_rate = 1
  3115. ld_uqty = outwaremx[i].qty
  3116. ld_uprice = ld_fprice
  3117. Else
  3118. If ld_rate_buy = 0 Then
  3119. arg_msg = '明细行:'+String(i)+',资料设为双数量核算,但没有设置默认转换率,请检查'
  3120. rslt = 0
  3121. Goto ext
  3122. End If
  3123. ls_uunit = ls_unit_buy
  3124. ld_rate = ld_rate_buy
  3125. ld_uqty = outwaremx[i].qty /ld_rate_buy
  3126. ld_uprice = ld_fprice * ld_rate
  3127. End If
  3128. If ld_uqty <> 0 Or outwaremx[i].qty <> 0 Then
  3129. s_mx.printid = chc
  3130. s_mx.mtrlid = outwaremx[i].mtrlid
  3131. s_mx.mtrlcode = outwaremx[i].mtrlcode
  3132. s_mx.plancode = outwaremx[i].plancode
  3133. s_mx.status = outwaremx[i].status
  3134. s_mx.uqty = ld_uqty
  3135. s_mx.enprice = ld_uprice
  3136. s_mx.rebate = 1
  3137. s_mx.mxdscrp = outwaremx[i].mxdscrp
  3138. s_mx.jgprice = 0
  3139. s_mx.relid = 0
  3140. s_mx.ifrel = 0
  3141. s_mx.woodcode = outwaremx[i].woodcode
  3142. s_mx.pcode = outwaremx[i].pcode
  3143. s_mx.sptid = outwaremx[i].sptid
  3144. s_mx.unit = ls_uunit
  3145. s_mx.rate = ld_rate
  3146. s_mx.qty = outwaremx[i].qty
  3147. s_mx.relprintid = 0
  3148. s_mx.checkqty = 0
  3149. s_mx.result = ''
  3150. s_mx.waredscrp = ''
  3151. s_mx.relbillid = 0
  3152. s_mx.relbillprintid = 0
  3153. s_mx.mtrlcuscode = outwaremx[i].mtrlcuscode
  3154. s_mx.Location = outwaremx[i].Location
  3155. s_mx.deliqty = ld_uqty
  3156. s_mx.tax = 0
  3157. If outwaremx[i].ifpackpro = 0 Then
  3158. s_mx.ifvqty = 1
  3159. s_mx.ifnotinout = 1
  3160. Else
  3161. s_mx.ifvqty = 0
  3162. s_mx.ifnotinout = 0
  3163. End If
  3164. If uo_in.acceptmx(s_mx, arg_msg) = 0 Then
  3165. arg_msg = '退货单(退货明细),行:'+String(i)+','+arg_msg
  3166. rslt = 0
  3167. Goto ext
  3168. End If
  3169. // IF uo_in.acceptmx(chc,&
  3170. // outwaremx[i].mtrlid,&
  3171. // outwaremx[i].mtrlcode,&
  3172. // outwaremx[i].plancode,&
  3173. // outwaremx[i].status,&
  3174. // ld_uqty,&
  3175. // ld_uprice,&
  3176. // 1,&
  3177. // outwaremx[i].mxdscrp,&
  3178. // arg_msg,&
  3179. // 0,0,0,outwaremx[i].woodcode,outwaremx[i].pcode,outwaremx[i].sptid,ls_uunit,ld_rate,&
  3180. // outwaremx[i].qty,0,0,'','',0,0,&
  3181. // outwaremx[i].mtrlcuscode,outwaremx[i].Location,&
  3182. // ld_uqty,&
  3183. // 0) = 0 THEN
  3184. // rslt = 0
  3185. // GOTO ext
  3186. // END IF
  3187. End If
  3188. Next
  3189. If uo_in.Save(False,arg_msg) = 0 Then
  3190. rslt = 0
  3191. Goto ext
  3192. End If
  3193. rst_inwareid = uo_in.inwareid
  3194. //4.原事务审核进仓单
  3195. If uo_in.getinfo(scid,rst_inwareid,arg_msg) = 0 Then
  3196. rslt = 0
  3197. Goto ext
  3198. End If
  3199. If uo_in.auditing(False,arg_msg) = 0 Then
  3200. rslt = 0
  3201. Goto ext
  3202. End If
  3203. End If
  3204. If li_outtype_storage = 2 And mx_barcode_cnt > 0 Then
  3205. If uof_p_barcode(1,arg_msg) = 0 Then
  3206. rslt = 0
  3207. Goto ext
  3208. End If
  3209. End If
  3210. flag = 1
  3211. ext:
  3212. If rslt = 0 Then
  3213. Rollback Using commit_transaction;
  3214. ElseIf rslt = 1 And arg_ifcommit Then
  3215. Commit Using commit_transaction;
  3216. End If
  3217. Destroy uo_pro
  3218. Destroy uo_task
  3219. Destroy uo_in
  3220. Destroy uo_out
  3221. Destroy ds_out_assign
  3222. Destroy uo_ma
  3223. Return rslt
  3224. end function
  3225. public function integer c_auditing_th (boolean arg_ifcommit, ref string arg_msg);Long rslt = 1,cnt = 0,i,j
  3226. Long ls_newid
  3227. DateTime null_dt
  3228. Long ll_inwareid_rel,ll_outwareid_rel
  3229. String ls_inwarecode_rel,ls_outwarecode_rel
  3230. String ls_outwarecode_arr[]
  3231. Long mx_barcode_cnt
  3232. Long ll_outwareid[]
  3233. Long ll_itmx = 1,ll_i
  3234. Int li_flag
  3235. Decimal ld_assign_outqty,ld_sumnotoutqty,ld_sumnotoutqty_bill
  3236. Long ll_row
  3237. IF uo_option_outware_saleout = -1000 THEN
  3238. rslt = 0
  3239. arg_msg = '选项:[147]使用销售出仓单,读取初始默认值失败,操作取消!'
  3240. GOTO ext
  3241. END IF
  3242. IF uo_option_inout_type = -1000 THEN
  3243. rslt = 0
  3244. arg_msg = '选项:[142]进出仓高级选项,读取初始默认值失败,操作取消!'
  3245. GOTO ext
  3246. END IF
  3247. SetNull(null_dt)
  3248. uo_saletask uo_task
  3249. uo_task = Create uo_saletask
  3250. uo_task.commit_transaction = commit_transaction
  3251. uo_sqlpro uo_pro
  3252. uo_pro = Create uo_sqlpro
  3253. uo_pro.commit_transaction = commit_transaction
  3254. uo_inware uo_in
  3255. uo_outware uo_out
  3256. uo_in = Create uo_inware
  3257. uo_in.commit_transaction = sqlca
  3258. uo_in.if_getid_ture = False
  3259. uo_out = Create uo_outware
  3260. uo_out.commit_transaction = sqlca
  3261. uo_out.if_getid_ture = False
  3262. uo_mtrlware_assign uo_ma
  3263. uo_ma = Create uo_mtrlware_assign
  3264. uo_ma.commit_transaction = commit_transaction
  3265. //库存分配ds
  3266. datastore ds_out_assign
  3267. ds_out_assign = Create datastore
  3268. ds_out_assign.DataObject = 'ds_outwaremx_assign'
  3269. ds_out_assign.SetTransObject(commit_transaction)
  3270. IF storageid = 0 THEN
  3271. rslt = 0
  3272. arg_msg = '没有正确的仓库'
  3273. GOTO ext
  3274. END IF
  3275. IF billtype <> 9 THEN
  3276. IF uof_check_warepdb_audit(storageid,arg_msg) = 0 THEN
  3277. rslt = 0
  3278. GOTO ext
  3279. END IF
  3280. END IF
  3281. String ls_storagename
  3282. Int li_outtype_storage,li_storagetype
  3283. SELECT storagename,outtype,storagetype
  3284. INTO :ls_storagename,:li_outtype_storage,:li_storagetype
  3285. FROM u_storage
  3286. Where storageid = :storageid Using commit_transaction ;
  3287. IF commit_transaction.SQLCode <> 0 THEN
  3288. rslt = 0
  3289. arg_msg = "查询操作失败,仓库"
  3290. GOTO ext
  3291. END IF
  3292. //检查是否有该仓库的建立权限
  3293. IF sys_user_storagestr_audit <> '0' THEN
  3294. IF Pos(sys_user_storagestr_audit,','+String(storageid)+',') <= 0 THEN
  3295. rslt = 0
  3296. arg_msg = '没有仓库: '+ls_storagename+' 的审核权限,不允许撤审该仓库的单据'
  3297. GOTO ext
  3298. END IF
  3299. END IF
  3300. //
  3301. IF outwareid = 0 THEN
  3302. rslt = 0
  3303. arg_msg = "没有审核对象"
  3304. GOTO ext
  3305. END IF
  3306. IF ctmint > 0 THEN
  3307. arg_msg = '单据已截数,不能操作'
  3308. rslt = 0
  3309. GOTO ext
  3310. END IF
  3311. IF flag = 0 THEN
  3312. rslt = 0
  3313. arg_msg = "单据还未审核"
  3314. GOTO ext
  3315. END IF
  3316. IF secflag = 1 THEN
  3317. rslt = 0
  3318. arg_msg = "单据已经过财务审核"
  3319. GOTO ext
  3320. END IF
  3321. IF balcflag = 1 THEN
  3322. rslt = 0
  3323. arg_msg = "单据已经日结,不能撤审"
  3324. GOTO ext
  3325. END IF
  3326. String ls_owecode
  3327. Int li_oweflag
  3328. Long ll_owebillid
  3329. cnt = 0
  3330. SELECT count(*) INTO :cnt
  3331. FROM u_owegood
  3332. WHERE scid = :scid
  3333. And relid = :outwareid Using commit_transaction;
  3334. IF commit_transaction.SQLCode <> 0 THEN
  3335. rslt = 0
  3336. arg_msg = '因网络或其它原因导致查询是否存在相关欠货单操作失败'+"~n"+commit_transaction.SQLErrText
  3337. GOTO ext
  3338. END IF
  3339. IF cnt > 1 THEN
  3340. rslt = 0
  3341. arg_msg = '不合理的欠货单数量(存在多张相关欠货单),请检查'
  3342. GOTO ext
  3343. ELSEIF cnt = 1 THEN
  3344. SELECT billid,billcode ,flag
  3345. INTO :ll_owebillid,:ls_owecode,:li_oweflag
  3346. FROM u_owegood
  3347. WHERE scid = :scid
  3348. And relid = :outwareid Using commit_transaction;
  3349. IF commit_transaction.SQLCode <> 0 THEN
  3350. rslt = 0
  3351. arg_msg = '因网络或其它原因导致查询\相关欠货单信息操作失败'+"~n"+commit_transaction.SQLErrText
  3352. GOTO ext
  3353. END IF
  3354. IF li_oweflag <> 0 THEN
  3355. rslt = 0
  3356. arg_msg = '相关欠货单:'+ls_owecode+' 已在进行或完成,不能撤审销售发货单,请检查'
  3357. GOTO ext
  3358. END IF
  3359. DELETE FROM u_owegoodmx
  3360. Where billid = :ll_owebillid;
  3361. IF commit_transaction.SQLCode <> 0 THEN
  3362. rslt = 0
  3363. arg_msg = "删除相关欠货单明细操作失败"+"~n"+commit_transaction.SQLErrText
  3364. GOTO ext
  3365. END IF
  3366. DELETE FROM u_owegood
  3367. WHERE billid = :ll_owebillid
  3368. And flag = 0;
  3369. IF commit_transaction.SQLCode <> 0 THEN
  3370. rslt = 0
  3371. arg_msg = "删除相关欠货单操作失败"+"~n"+commit_transaction.SQLErrText
  3372. GOTO ext
  3373. END IF
  3374. END IF
  3375. UPDATE u_outware
  3376. SET Auditingrep = '',
  3377. Auditingdate = :null_dt,
  3378. flag = 0
  3379. WHERE u_outware.outwareid = :outwareid
  3380. AND flag = 1
  3381. And scid = :scid Using commit_transaction;
  3382. IF commit_transaction.SQLCode <> 0 THEN
  3383. rslt = 0
  3384. arg_msg = "因网络或其它原因导致审核单据操作失败"+"~n"+commit_transaction.SQLErrText
  3385. GOTO ext
  3386. ELSEIF commit_transaction.SQLNRows = 0 THEN
  3387. rslt = 0
  3388. arg_msg = "单据正在审核,请稍后查询。"+"~n"+commit_transaction.SQLErrText
  3389. GOTO ext
  3390. END IF
  3391. IF li_outtype_storage <> 0 And uo_option_outware_saleout = 0 THEN
  3392. //yyx20130130
  3393. //仓库是用库存分配,(包件出仓或条码出仓),包件产品扣分配,包件在销售出仓单做
  3394. FOR i = 1 To it_mxbt
  3395. IF billtype = 1 And li_storagetype = 1 And li_outtype_storage > 0 And ( outwaremx[i].ifpackpro > 0 And outwaremx[i].ifpackpro <> 4 Or outwaremx[i].ifpackpro = 4 And (Pos(outwaremx[i].status,'+') > 0 Or Pos(outwaremx[i].status,'*') > 0)) And outwaremx[i].relid > 0 THEN
  3396. ll_row = ds_out_assign.Retrieve(scid,outwaremx[i].mtrlwareid,outwaremx[i].relid,outwaremx[i].relprintid)
  3397. ds_out_assign.AcceptText()
  3398. IF ll_row <= 0 THEN
  3399. ld_sumnotoutqty = 0
  3400. ELSE
  3401. ld_sumnotoutqty = ds_out_assign.Object.sumnotoutqty[1]
  3402. END IF
  3403. ld_sumnotoutqty_bill = 0
  3404. ld_sumnotoutqty_bill = Abs(outwaremx[i].qty)
  3405. IF ld_sumnotoutqty > 0 And ld_sumnotoutqty_bill > 0 THEN
  3406. ld_assign_outqty = 0
  3407. FOR j = 1 To ds_out_assign.RowCount()
  3408. IF ds_out_assign.Object.notoutqty[j] >= ld_sumnotoutqty_bill THEN
  3409. ld_assign_outqty = ld_sumnotoutqty_bill
  3410. IF uo_ma.uof_assign_addoutqty(ds_out_assign.Object.assignid[j],ld_assign_outqty,arg_msg,False) = 0 THEN
  3411. arg_msg = '物料:'+outwaremx[i].mtrlcode+',销售退货单(发货明细)行:'+String(i)+','+arg_msg
  3412. rslt = 0
  3413. GOTO ext
  3414. END IF
  3415. EXIT
  3416. ELSE
  3417. ld_assign_outqty = ds_out_assign.Object.notoutqty[j]
  3418. IF uo_ma.uof_assign_addoutqty(ds_out_assign.Object.assignid[j],ld_assign_outqty,arg_msg,False) = 0 THEN
  3419. arg_msg = '物料:'+outwaremx[i].mtrlcode+',销售退货单(发货明细)行:'+String(i)+','+arg_msg
  3420. rslt = 0
  3421. GOTO ext
  3422. END IF
  3423. ld_sumnotoutqty_bill = ld_sumnotoutqty_bill - ds_out_assign.Object.notoutqty[j]
  3424. END IF
  3425. NEXT
  3426. END IF
  3427. END IF
  3428. NEXT
  3429. //end_20130130
  3430. SELECT count(*)
  3431. INTO :cnt
  3432. FROM u_inware
  3433. WHERE scid = :scid
  3434. AND relid = :outwareid
  3435. And billtype = 23 Using commit_transaction;
  3436. IF commit_transaction.SQLCode <> 0 THEN
  3437. rslt = 0
  3438. arg_msg = "因网络或其它原因导致查询相关包件进仓单操作失败"+"~n"+commit_transaction.SQLErrText
  3439. GOTO ext
  3440. END IF
  3441. IF cnt > 0 THEN
  3442. SELECT inwareid,inwarecode
  3443. INTO :ll_inwareid_rel,:ls_inwarecode_rel
  3444. FROM u_inware
  3445. WHERE scid = :scid
  3446. AND relid = :outwareid
  3447. And billtype = 23 Using commit_transaction;
  3448. IF commit_transaction.SQLCode <> 0 THEN
  3449. rslt = 0
  3450. arg_msg = "因网络或其它原因导致查询相关包件进仓单操作失败"+"~n"+commit_transaction.SQLErrText
  3451. GOTO ext
  3452. END IF
  3453. IF uo_in.getinfo(scid,ll_inwareid_rel,arg_msg) = 0 THEN
  3454. arg_msg = '相关进仓单:'+ls_inwarecode_rel+','+arg_msg
  3455. rslt = 0
  3456. GOTO ext
  3457. END IF
  3458. IF uo_in.c_auditing(False,arg_msg) = 0 THEN
  3459. arg_msg = '相关进仓单:'+ls_inwarecode_rel+','+arg_msg
  3460. rslt = 0
  3461. GOTO ext
  3462. END IF
  3463. IF uo_in.del(scid,ll_inwareid_rel,arg_msg,False) = 0 THEN
  3464. arg_msg = '相关进仓单:'+ls_inwarecode_rel+','+arg_msg
  3465. rslt = 0
  3466. GOTO ext
  3467. END IF
  3468. END IF
  3469. DECLARE cur_mx CURSOR FOR
  3470. SELECT outwareid,outwarecode
  3471. FROM u_outware
  3472. WHERE billtype = 21
  3473. AND relid = :outwareid
  3474. And scid = :scid Using commit_transaction;
  3475. OPEN cur_mx;
  3476. FETCH cur_mx Into :ll_outwareid[ll_itmx],:ls_outwarecode_arr[ll_itmx];
  3477. DO WHILE commit_transaction.SQLCode = 0
  3478. ll_itmx++
  3479. FETCH cur_mx Into :ll_outwareid[ll_itmx],:ls_outwarecode_arr[ll_itmx];
  3480. LOOP
  3481. ll_itmx = ll_itmx - 1
  3482. CLOSE cur_mx;
  3483. FOR ll_i = 1 To ll_itmx
  3484. IF uo_out.getinfo(scid,ll_outwareid[ll_i],arg_msg) = 0 THEN
  3485. rslt = 0
  3486. arg_msg = '查询相关出仓单失败,' + arg_msg
  3487. GOTO ext
  3488. END IF
  3489. IF uo_out.c_auditing(False,arg_msg) = 0 THEN
  3490. rslt = 0
  3491. arg_msg = '撤审相关出仓单失败,' + arg_msg
  3492. GOTO ext
  3493. END IF
  3494. IF uo_out.del(scid,ll_outwareid[ll_i],0,arg_msg,False) = 0 THEN
  3495. arg_msg = '相关出仓单:'+ls_outwarecode_rel+','+arg_msg
  3496. rslt = 0
  3497. GOTO ext
  3498. END IF
  3499. NEXT
  3500. END IF
  3501. IF uo_option_outware_saleout = 1 THEN
  3502. SELECT count(*)
  3503. INTO :cnt
  3504. FROM u_inware
  3505. WHERE scid = :scid
  3506. AND relid = :outwareid
  3507. And billtype = 23 Using commit_transaction;
  3508. IF commit_transaction.SQLCode <> 0 THEN
  3509. rslt = 0
  3510. arg_msg = "因网络或其它原因导致查询相关包件进仓单操作失败"+"~n"+commit_transaction.SQLErrText
  3511. GOTO ext
  3512. END IF
  3513. IF cnt > 0 THEN
  3514. SELECT inwareid,inwarecode
  3515. INTO :ll_inwareid_rel,:ls_inwarecode_rel
  3516. FROM u_inware
  3517. WHERE scid = :scid
  3518. AND relid = :outwareid
  3519. And billtype = 23;
  3520. IF commit_transaction.SQLCode <> 0 THEN
  3521. rslt = 0
  3522. arg_msg = "因网络或其它原因导致查询相关包件进仓单操作失败"+"~n"+commit_transaction.SQLErrText
  3523. GOTO ext
  3524. END IF
  3525. IF uo_in.getinfo(scid,ll_inwareid_rel,arg_msg) = 0 THEN
  3526. arg_msg = '相关进仓单:'+ls_inwarecode_rel+','+arg_msg
  3527. rslt = 0
  3528. GOTO ext
  3529. END IF
  3530. IF uo_in.c_auditing(False,arg_msg) = 0 THEN
  3531. arg_msg = '相关进仓单:'+ls_inwarecode_rel+','+arg_msg
  3532. rslt = 0
  3533. GOTO ext
  3534. END IF
  3535. IF uo_in.del(scid,ll_inwareid_rel,arg_msg,False) = 0 THEN
  3536. arg_msg = '相关进仓单:'+ls_inwarecode_rel+','+arg_msg
  3537. rslt = 0
  3538. GOTO ext
  3539. END IF
  3540. END IF
  3541. DECLARE cur_mx_rel CURSOR FOR
  3542. SELECT outwareid
  3543. FROM u_outware
  3544. WHERE billtype = 21
  3545. AND relid = :outwareid
  3546. And scid = :scid Using commit_transaction;
  3547. OPEN cur_mx_rel;
  3548. FETCH cur_mx_rel Into :ll_outwareid[ll_itmx];
  3549. DO WHILE commit_transaction.SQLCode = 0
  3550. ll_itmx++
  3551. FETCH cur_mx_rel Into :ll_outwareid[ll_itmx];
  3552. LOOP
  3553. ll_itmx = ll_itmx - 1
  3554. CLOSE cur_mx_rel;
  3555. FOR ll_i = 1 To ll_itmx
  3556. IF uo_out.getinfo(scid,ll_outwareid[ll_i],arg_msg) = 0 THEN
  3557. rslt = 0
  3558. arg_msg = '查询相关出仓单失败,' + arg_msg
  3559. GOTO ext
  3560. END IF
  3561. IF uo_out.c_auditing(False,arg_msg) = 0 THEN
  3562. rslt = 0
  3563. arg_msg = '撤审相关出仓单失败,' + arg_msg
  3564. GOTO ext
  3565. END IF
  3566. NEXT
  3567. END IF
  3568. FOR i = 1 To it_mxbt
  3569. //更新分配
  3570. IF billtype = 1 And li_storagetype = 1 And li_outtype_storage = 0 And outwaremx[i].relid > 0 THEN
  3571. ll_row = ds_out_assign.Retrieve(scid,outwaremx[i].mtrlwareid,outwaremx[i].relid,outwaremx[i].relprintid)
  3572. ds_out_assign.AcceptText()
  3573. IF ll_row <= 0 THEN
  3574. ld_sumnotoutqty = 0
  3575. ELSE
  3576. ld_sumnotoutqty = ds_out_assign.Object.sumnotoutqty[1]
  3577. END IF
  3578. ld_sumnotoutqty_bill = 0
  3579. ld_sumnotoutqty_bill = outwaremx[i].qty
  3580. IF ld_sumnotoutqty_bill > ld_sumnotoutqty THEN
  3581. arg_msg = '发货明细行:'+String(i)+'订单库存分配数不足,请检查库存分配未出仓明细'
  3582. rslt = 0
  3583. GOTO ext
  3584. ELSE
  3585. ld_assign_outqty = 0
  3586. FOR j = 1 To ds_out_assign.RowCount()
  3587. IF ds_out_assign.Object.notoutqty[j] >= ld_sumnotoutqty_bill THEN
  3588. ld_assign_outqty = ld_sumnotoutqty_bill
  3589. IF uo_ma.uof_assign_addoutqty(ds_out_assign.Object.assignid[j],ld_assign_outqty,arg_msg,False) = 0 THEN
  3590. arg_msg = '发货明细行:'+String(i)+','+arg_msg
  3591. rslt = 0
  3592. GOTO ext
  3593. END IF
  3594. EXIT
  3595. ELSE
  3596. ld_assign_outqty = ds_out_assign.Object.notoutqty[j]
  3597. IF uo_ma.uof_assign_addoutqty(ds_out_assign.Object.assignid[j],ld_assign_outqty,arg_msg,False) = 0 THEN
  3598. arg_msg = '发货明细行:'+String(i)+','+arg_msg
  3599. rslt = 0
  3600. GOTO ext
  3601. END IF
  3602. ld_sumnotoutqty_bill = ld_sumnotoutqty_bill - ds_out_assign.Object.notoutqty[j]
  3603. END IF
  3604. NEXT
  3605. END IF
  3606. END IF
  3607. IF sys_option_inout_procedure = 0 THEN
  3608. IF p_update_mtrlware ( outwaremx[i].mtrlwareid, outwaremx[i].mtrlid, &
  3609. outwaremx[i].mtrlcode, storageid, outwaremx[i].plancode,&
  3610. outwaremx[i].status, 0 - outwaremx[i].qty,0 - outwaremx[i].uqty,0 - outwaremx[i].costamt,&
  3611. outwaremx[i].planprice, outwaremx[i].sptid, outwaremx[i].dxflag,&
  3612. outwaremx[i].woodcode, outwaremx[i].pcode, outwaremx[i].mtrlcuscode,&
  3613. outwaremx[i].Location,outwaremx[i].ifvqty,arg_msg) = 0 THEN
  3614. rslt = 0
  3615. GOTO ext
  3616. END IF
  3617. ELSE
  3618. IF uo_pro.p_outware_update_mtrlware(scid,outwareid,outwaremx[i].printid,outwaremx[i].mtrlwareid,&
  3619. outwaremx[i].mtrlid,outwaremx[i].mtrlcode,storageid,outwaremx[i].plancode,outwaremx[i].status,&
  3620. 0 - outwaremx[i].qty,0 - outwaremx[i].uqty,outwaremx[i].costamt,&
  3621. outwaremx[i].planprice, outwaremx[i].sptid,outwaremx[i].dxflag,&
  3622. outwaremx[i].woodcode, outwaremx[i].pcode,outwaremx[i].mtrlcuscode,outwaremx[i].Location,arg_msg) = 0 THEN
  3623. arg_msg = '行:'+String(i)+','+arg_msg
  3624. rslt = 0
  3625. GOTO ext
  3626. END IF
  3627. END IF
  3628. If (billtype = 1 Or billtype = 5) And outwaremx[i].relid > 0 THEN
  3629. IF uo_task.addmxcmpl(scid,outwaremx[i].relid,outwaremx[i].relprintid, 0 - outwaremx[i].qty,arg_msg,False) <> 1 THEN
  3630. rslt = 0
  3631. GOTO ext
  3632. END IF
  3633. END IF
  3634. If (billtype = 1 Or billtype = 5) And outwaremx[i].relid > 0 THEN
  3635. SELECT status INTO :li_flag
  3636. FROM u_saletask
  3637. WHERE scid = :scid
  3638. And taskid = :outwaremx[i].relid Using commit_transaction;
  3639. IF commit_transaction.SQLCode <> 0 THEN
  3640. rslt = 0
  3641. arg_msg = '查询相关订单状态失败,'+sqlca.SQLErrText
  3642. GOTO ext
  3643. END IF
  3644. IF li_flag = 1 Or li_flag = 5 THEN
  3645. IF uo_task.trycmplsaletask(scid,outwaremx[i].relid,arg_msg,False) = 0 THEN
  3646. rslt = 0
  3647. GOTO ext
  3648. END IF
  3649. END IF
  3650. END IF
  3651. IF li_outtype_storage = 2 And outwaremx[i].outtype_mtrl = 2 THEN mx_barcode_cnt++
  3652. NEXT
  3653. IF li_outtype_storage = 2 And mx_barcode_cnt > 0 THEN
  3654. IF uof_p_barcode(0,arg_msg) = 0 THEN
  3655. rslt = 0
  3656. GOTO ext
  3657. END IF
  3658. END IF
  3659. flag = 0
  3660. ext:
  3661. IF rslt = 0 THEN
  3662. ROLLBACK Using commit_transaction;
  3663. ELSEIF rslt = 1 And arg_ifcommit THEN
  3664. COMMIT Using commit_transaction;
  3665. END IF
  3666. Destroy uo_task
  3667. Destroy uo_in
  3668. Destroy uo_out
  3669. Destroy uo_pro
  3670. Destroy ds_out_assign
  3671. Destroy uo_ma
  3672. RETURN rslt
  3673. end function
  3674. public function integer uof_check_pt (ref string arg_msg);Int rslt = 1
  3675. Long ll_ucrow,cnt
  3676. Long ll_i,ll_j,ll_k,ll_l
  3677. Boolean lb_f = False,lb_f2 = False
  3678. Long ll_mtrlid_child
  3679. Long ll_printid_child
  3680. Decimal ld_planqty_child,ld_qty_child
  3681. Long ll_taskid,ll_printid_task
  3682. Int li_outtype,li_ifpackpro
  3683. Decimal ld_planqty_mx_sum
  3684. Decimal ld_Sonscale[],ld_Sonscale_fm[]
  3685. Long ll_SonMtrlid[]
  3686. Long it_mxt = 1
  3687. Decimal ld_rqty_mx
  3688. s_mtrlcfg_expr s_pz[]
  3689. String ls_status_child,ls_woodcode_child,ls_pcode_child
  3690. String ls_status[],ls_woodcode[],ls_pcode[]
  3691. //检查包件明细to包货明细
  3692. FOR ll_j = 1 To it_mxbt_mx
  3693. lb_f2 = False
  3694. FOR ll_i = 1 To it_mxbt
  3695. IF outwaremx_mx[ll_j].printid = outwaremx[ll_i].printid THEN
  3696. lb_f2 = True
  3697. END IF
  3698. NEXT
  3699. IF Not lb_f2 THEN
  3700. arg_msg = '包件明细行:'+String(outwaremx_mx[ll_j].mxprintid)+',相关发货明细行:'+String(outwaremx_mx[ll_j].printid)+',没有配套发货明细行,请检查'
  3701. rslt = 0
  3702. GOTO ext
  3703. END IF
  3704. NEXT
  3705. //检查发货明细to包件明细
  3706. FOR ll_i = 1 To it_mxbt
  3707. ll_mtrlid_child = outwaremx[ll_i].mtrlid
  3708. ll_printid_child = outwaremx[ll_i].printid
  3709. ld_planqty_child = outwaremx[ll_i].qty
  3710. ls_status_child = outwaremx[ll_i].status
  3711. ls_woodcode_child = outwaremx[ll_i].woodcode
  3712. ls_pcode_child = outwaremx[ll_i].pcode
  3713. ll_taskid = outwaremx[ll_i].relid
  3714. ll_printid_task = outwaremx[ll_i].relprintid
  3715. SELECT outtype,ifpackpro
  3716. INTO :li_outtype,:li_ifpackpro
  3717. FROM u_mtrldef
  3718. WHERE mtrlid = :ll_mtrlid_child
  3719. Using commit_transaction;
  3720. IF commit_transaction.SQLCode <> 0 THEN
  3721. arg_msg = '发货明细行:'+String(ll_i)+',编码:'+outwaremx[ll_i].mtrlcode+',查询产品出仓类型及包件产品属性失败,'+commit_transaction.SQLErrText
  3722. rslt = 0
  3723. GOTO ext
  3724. END IF
  3725. IF Not ((li_outtype = 1 Or li_outtype = 2) And li_ifpackpro > 0) THEN
  3726. ld_planqty_mx_sum = 0
  3727. lb_f = False
  3728. FOR ll_j = 1 To it_mxbt_mx
  3729. IF outwaremx_mx[ll_j].printid = ll_printid_child THEN
  3730. ld_planqty_mx_sum += outwaremx_mx[ll_j].qty
  3731. lb_f = True
  3732. END IF
  3733. NEXT
  3734. IF Not lb_f THEN
  3735. arg_msg = '发货明细行:'+String(ll_i)+',编码:'+outwaremx[ll_i].mtrlcode+',没有配套包件明细行,请检查,可能包件库存不足'
  3736. rslt = 0
  3737. GOTO ext
  3738. END IF
  3739. IF ld_planqty_child <> ld_planqty_mx_sum THEN
  3740. arg_msg = '发货明细行:'+String(ll_i)+',编码:'+outwaremx[ll_i].mtrlcode+',与包件明细行配套数量不相符,请检查'
  3741. rslt = 0
  3742. GOTO ext
  3743. END IF
  3744. ELSE
  3745. IF li_ifpackpro = 1 Or li_ifpackpro = 2 THEN
  3746. it_mxt = 1
  3747. cnt = 0
  3748. //查是否有换清单
  3749. IF li_ifpackpro = 2 And ll_taskid > 0 THEN
  3750. SELECT count(*) INTO :cnt FROM u_saletaskmx_pf
  3751. WHERE scid = :scid
  3752. AND taskid = :ll_taskid
  3753. And printid = :ll_printid_task;
  3754. IF sqlca.SQLCode <> 0 THEN
  3755. arg_msg = '查询发货明细:'+String(ll_i)+',编码:'+outwaremx[ll_i].mtrlcode+',对应订单明细否有换包件失败,'+sqlca.SQLErrText
  3756. RETURN 0
  3757. END IF
  3758. END IF
  3759. IF cnt > 0 THEN
  3760. DECLARE cur_pf_saletaskmx CURSOR FOR
  3761. SELECT u_saletaskmx_pf.SonMtrlid,
  3762. u_saletaskmx_pf.Sonscale,
  3763. u_saletaskmx_pf.Sonscale_fm
  3764. FROM u_saletaskmx_pf
  3765. WHERE ( u_saletaskmx_pf.scid = :scid )
  3766. AND ( u_saletaskmx_pf.taskid = :ll_taskid )
  3767. And ( u_saletaskmx_pf.printid = :ll_printid_task );
  3768. OPEN cur_pf_saletaskmx;
  3769. FETCH cur_pf_saletaskmx Into :ll_SonMtrlid[it_mxt],:ld_Sonscale[it_mxt],:ld_Sonscale_fm[it_mxt];
  3770. DO WHILE sqlca.SQLCode = 0
  3771. it_mxt++
  3772. FETCH cur_pf_saletaskmx Into :ll_SonMtrlid[it_mxt],:ld_Sonscale[it_mxt],:ld_Sonscale_fm[it_mxt];
  3773. LOOP
  3774. it_mxt = it_mxt - 1
  3775. CLOSE cur_pf_saletaskmx;
  3776. ELSE
  3777. DECLARE cur_pf CURSOR FOR
  3778. SELECT u_PrdPF.SonMtrlid,
  3779. u_prdpf.Sonscale,
  3780. 1
  3781. FROM u_PrdPF,u_mtrl_pf,u_mtrldef
  3782. WHERE ( u_PrdPF.mtrlid = u_mtrl_pf.mtrlid )
  3783. AND ( u_PrdPF.pfcode = u_mtrl_pf.pfcode )
  3784. AND ( u_PrdPF.SonMtrlid = u_mtrldef.mtrlid )
  3785. AND ( u_PrdPF.mtrlid = :ll_mtrlid_child )
  3786. AND ( u_mtrl_pf.ifdi = 1 AND :li_ifpackpro = 0
  3787. OR u_mtrl_pf.ifdft = 1 AND (:li_ifpackpro = 1 OR :li_ifpackpro = 2) AND u_mtrldef.ifpack > 0)
  3788. Order By u_PrdPF.printid;
  3789. OPEN cur_pf;
  3790. FETCH cur_pf Into :ll_SonMtrlid[it_mxt],:ld_Sonscale[it_mxt],:ld_Sonscale_fm[it_mxt];
  3791. DO WHILE sqlca.SQLCode = 0
  3792. it_mxt++
  3793. FETCH cur_pf Into :ll_SonMtrlid[it_mxt],:ld_Sonscale[it_mxt],:ld_Sonscale_fm[it_mxt];
  3794. LOOP
  3795. it_mxt = it_mxt - 1
  3796. CLOSE cur_pf;
  3797. END IF
  3798. ELSEIF li_ifpackpro = 5 THEN
  3799. DECLARE cur_pf5 CURSOR FOR
  3800. SELECT u_PrdPF.SonMtrlid,
  3801. u_prdpf.Sonscale,
  3802. 1
  3803. FROM u_PrdPF,u_mtrldef
  3804. WHERE ( u_PrdPF.pfcode = :ls_status_child )
  3805. AND ( u_PrdPF.SonMtrlid = u_mtrldef.mtrlid )
  3806. AND ( u_PrdPF.mtrlid = :ll_mtrlid_child )
  3807. AND ( u_mtrldef.ifpack > 0)
  3808. Order By u_PrdPF.printid;
  3809. OPEN cur_pf5;
  3810. FETCH cur_pf5 Into :ll_SonMtrlid[it_mxt],:ld_Sonscale[it_mxt],:ld_Sonscale_fm[it_mxt];
  3811. DO WHILE sqlca.SQLCode = 0
  3812. it_mxt++
  3813. FETCH cur_pf5 Into :ll_SonMtrlid[it_mxt],:ld_Sonscale[it_mxt],:ld_Sonscale_fm[it_mxt];
  3814. LOOP
  3815. it_mxt = it_mxt - 1
  3816. CLOSE cur_pf5;
  3817. ELSEIF li_ifpackpro = 3 Or li_ifpackpro = 4 THEN
  3818. f_checkpz(ls_status_child,s_pz[])
  3819. it_mxt = UpperBound(s_pz)
  3820. FOR ll_l = 1 To it_mxt
  3821. ll_SonMtrlid[ll_l] = ll_mtrlid_child
  3822. ld_Sonscale[ll_l] = Dec(s_pz[ll_l].qty)
  3823. ld_Sonscale_fm[ll_l] = 1
  3824. ls_status[ll_l] = s_pz[ll_l].cfgname
  3825. ls_woodcode[ll_l] = ls_woodcode_child
  3826. ls_pcode[ll_l] = ls_pcode_child
  3827. NEXT
  3828. END IF
  3829. FOR ll_k = 1 To it_mxt
  3830. ld_planqty_mx_sum = 0
  3831. lb_f = False
  3832. ld_rqty_mx = ld_planqty_child * ld_Sonscale[ll_k]/ld_Sonscale_fm[ll_k]
  3833. IF li_ifpackpro = 1 Or li_ifpackpro = 2 THEN
  3834. FOR ll_j = 1 To it_mxbt_mx
  3835. IF outwaremx_mx[ll_j].printid = ll_printid_child And &
  3836. outwaremx_mx[ll_j].mtrlid = ll_SonMtrlid[ll_k] THEN
  3837. ld_planqty_mx_sum += outwaremx_mx[ll_j].qty
  3838. lb_f = True
  3839. END IF
  3840. NEXT
  3841. ELSE
  3842. FOR ll_j = 1 To it_mxbt_mx
  3843. IF outwaremx_mx[ll_j].printid = ll_printid_child And &
  3844. outwaremx_mx[ll_j].mtrlid = ll_SonMtrlid[ll_k] And &
  3845. outwaremx_mx[ll_j].status = ls_status[ll_k] And &
  3846. outwaremx_mx[ll_j].woodcode = ls_woodcode[ll_k] And &
  3847. outwaremx_mx[ll_j].pcode = ls_pcode[ll_k] THEN
  3848. ld_planqty_mx_sum += outwaremx_mx[ll_j].qty
  3849. lb_f = True
  3850. END IF
  3851. NEXT
  3852. END IF
  3853. IF Not lb_f THEN
  3854. arg_msg = '发货明细行:'+String(ll_i)+',编码:'+outwaremx[ll_i].mtrlcode+',没有配套包件明细行,请检查,可能包件库存不足'
  3855. rslt = 0
  3856. GOTO ext
  3857. END IF
  3858. IF ld_rqty_mx <> ld_planqty_mx_sum THEN
  3859. arg_msg = '发货明细行:'+String(ll_i)+',编码:'+outwaremx[ll_i].mtrlcode+',与包件明细行配套数量不相符,请检查'
  3860. rslt = 0
  3861. GOTO ext
  3862. END IF
  3863. NEXT
  3864. END IF
  3865. NEXT
  3866. ext:
  3867. RETURN rslt
  3868. end function
  3869. public function integer priceaudit (long arg_scid, long arg_outwareid, boolean arg_ifcommit, ref string arg_msg, string arg_emp);Long rslt = 1,i
  3870. uo_cusprice uo_price
  3871. If uo_option_outware_saleout = -1000 Then
  3872. rslt = 0
  3873. arg_msg = '选项:[147]使用销售出仓单,读取初始默认值失败,操作取消!'
  3874. Goto ext
  3875. End If
  3876. If uo_option_checkprice_native = -1000 Then
  3877. rslt = 0
  3878. arg_msg = '选项:[056]销售价按本位币限价,读取初始默认值失败,操作取消!'
  3879. Goto ext
  3880. End If
  3881. If arg_scid < 0 Then
  3882. rslt = 0
  3883. arg_msg = "错误的分部ID"
  3884. Goto ext
  3885. End If
  3886. If arg_outwareid <= 0 Then
  3887. rslt = 0
  3888. arg_msg = "没有确认对象"
  3889. Goto ext
  3890. End If
  3891. If getinfo(arg_scid,arg_outwareid,arg_msg) = 0 Then
  3892. rslt = 0
  3893. Goto ext
  3894. End If
  3895. If priceflag = 1 Then
  3896. rslt = 0
  3897. arg_msg = "单据已经确认"
  3898. Goto ext
  3899. End If
  3900. //yyx20150529调整顺序
  3901. Update u_outware
  3902. Set priceemp = :arg_emp,
  3903. pricedate = getdate(),
  3904. priceflag = 1
  3905. Where u_outware.outwareid = :arg_outwareid
  3906. And priceflag = 0
  3907. And scid = :arg_scid Using commit_transaction;
  3908. If commit_transaction.SQLCode <> 0 Then
  3909. rslt = 0
  3910. arg_msg = "因网络或其它原因导致确认单据操作失败"+"~n"+commit_transaction.SQLErrText
  3911. Goto ext
  3912. ElseIf commit_transaction.SQLNRows = 0 Then
  3913. rslt = 0
  3914. arg_msg = "单据正在确认,请稍后查询。"+"~n"+commit_transaction.SQLErrText
  3915. Goto ext
  3916. End If
  3917. uo_price = Create uo_cusprice
  3918. For i = 1 To it_mxbt
  3919. If outwaremx[i].outtype <> '' Then Continue
  3920. If uo_option_checkprice_native = 1 Then
  3921. If uo_price.uof_check_price (cusid,outwaremx[i].mtrlid,&
  3922. outwaremx[i].mtrlcode,outwaremx[i].status,outwaremx[i].pcode,&
  3923. outwaremx[i].woodcode,relint_2,outwaremx[i].price,outwaremx[i].uqty,arg_msg) = 0 Then
  3924. rslt = 0
  3925. Goto ext
  3926. End If
  3927. Else
  3928. If uo_price.uof_check_price (cusid,outwaremx[i].mtrlid,&
  3929. outwaremx[i].mtrlcode,outwaremx[i].status,outwaremx[i].pcode,&
  3930. outwaremx[i].woodcode,relint_2,outwaremx[i].enprice * outwaremx[i].rebate,outwaremx[i].uqty,arg_msg) = 0 Then
  3931. rslt = 0
  3932. Goto ext
  3933. End If
  3934. End If
  3935. Next
  3936. If uo_option_outware_saleout > 0 Then
  3937. //更新库存已开单数(减)
  3938. If uof_noauditingqty_del(arg_scid,arg_outwareid,arg_msg) = 0 Then
  3939. rslt = 0
  3940. Goto ext
  3941. End If
  3942. End If
  3943. If uo_option_outware_saleout = 1 Then
  3944. Int li_ifpack,li_ifunit,li_ifpackpro
  3945. Int li_ifpackcnt,li_ifpackprocnt
  3946. Decimal ld_rate,ld_uqty,ld_rate_buy
  3947. Decimal ld_fprice,ld_uprice
  3948. String ls_uunit,ls_unit_buy,ls_unit
  3949. Long chc,ll_j,ll_i
  3950. Long ll_storageid_arr[],cnt = 0
  3951. li_ifpackcnt = 0
  3952. uo_outware uo_out
  3953. uo_out = Create uo_outware
  3954. uo_out.commit_transaction = sqlca
  3955. uo_out.if_getid_ture = False
  3956. For ll_i = 1 To it_mxbt_mx
  3957. If ll_i = 1 Then
  3958. cnt++
  3959. ll_storageid_arr[cnt] = outwaremx_mx[ll_i].storageid
  3960. Goto _next
  3961. End If
  3962. For ll_j = 1 To cnt
  3963. If ll_storageid_arr[ll_j] = outwaremx_mx[ll_i].storageid Then
  3964. Goto _next
  3965. End If
  3966. Next
  3967. cnt++
  3968. ll_storageid_arr[cnt] = outwaremx_mx[ll_i].storageid
  3969. _next:
  3970. Next
  3971. For ll_i = 1 To cnt
  3972. If uo_out.newbegin(scid,21,arg_msg) = 0 Then
  3973. rslt = 0
  3974. Goto ext
  3975. End If
  3976. uo_out.relid = outwareid
  3977. uo_out.outdate = outdate
  3978. uo_out.outrep = outrep
  3979. uo_out.part = outwarecode
  3980. uo_out.dscrp = dscrp
  3981. uo_out.cusname = '包件明细自动出仓'
  3982. uo_out.storageid = ll_storageid_arr[ll_i]
  3983. chc = 0
  3984. For i = 1 To it_mxbt_mx
  3985. If outwaremx_mx[i].storageid <> ll_storageid_arr[ll_i] Then Continue
  3986. Select ifpack,ifunit,unit,rate_buy,unit_buy,planprice
  3987. Into :li_ifpack,:li_ifunit,:ls_unit,:ld_rate_buy,:ls_unit_buy,:ld_fprice
  3988. From u_mtrldef
  3989. Where mtrlid = :outwaremx_mx[i].mtrlid;
  3990. If commit_transaction.SQLCode <> 0 Then
  3991. rslt = 0
  3992. arg_msg = "因网络或其它原因导致查询应发明细操作失败"+"~n"+commit_transaction.SQLErrText
  3993. Goto ext
  3994. End If
  3995. chc++
  3996. If li_ifunit = 0 Then
  3997. ls_uunit = ls_unit
  3998. ld_rate = 1
  3999. ld_uqty = outwaremx_mx[i].qty
  4000. Else
  4001. If ld_rate_buy = 0 Then
  4002. arg_msg = '明细行:'+String(i)+',资料设为双数量核算,但没有设置默认转换率,请检查'
  4003. rslt = 0
  4004. Goto ext
  4005. End If
  4006. ls_uunit = ls_unit_buy
  4007. ld_rate = ld_rate_buy
  4008. ld_uqty = outwaremx_mx[i].qty /ld_rate_buy
  4009. End If
  4010. If uo_out.acceptmx(outwaremx_mx[i].mtrlwareid,&
  4011. outwaremx_mx[i].qty,ld_fprice,1,&
  4012. outwaremx_mx[i].mxdscrp,chc,arg_msg,0,outwaremx_mx[i].printid,0,0,'',outwaremx_mx[i].planqty,outwaremx_mx[i].mxprintid,&
  4013. ls_uunit,ld_uqty,ld_rate,'','',0,0,'',0,0,0,0,'','') = 0 Then
  4014. rslt = 0
  4015. Goto ext
  4016. End If
  4017. Next
  4018. If uo_out.Save(False,arg_msg) = 0 Then
  4019. rslt = 0
  4020. Goto ext
  4021. End If
  4022. Next
  4023. End If
  4024. priceflag = 1
  4025. //将相关虚拟库存数设为无效
  4026. For i = 1 To it_mxbt
  4027. Update u_mtrlware_view
  4028. Set inuse = 0
  4029. Where cusid = :cusid
  4030. And mtrlwareid = :outwaremx[i].mtrlwareid
  4031. And inuse = 1 Using commit_transaction;
  4032. If commit_transaction.SQLCode <> 0 Then
  4033. rslt = 0
  4034. arg_msg = '更新相关虚拟库存为无效失败'+'~n'+commit_transaction.SQLErrText
  4035. Goto ext
  4036. End If
  4037. Next
  4038. For i = 1 To it_mxbt_mx
  4039. Update u_mtrlware_view
  4040. Set inuse = 0
  4041. Where cusid = :cusid
  4042. And mtrlwareid = :outwaremx_mx[i].mtrlwareid
  4043. And inuse = 1 Using commit_transaction;
  4044. If commit_transaction.SQLCode <> 0 Then
  4045. rslt = 0
  4046. arg_msg = '更新相关包件明细虚拟库存为无效失败'+'~n'+commit_transaction.SQLErrText
  4047. Goto ext
  4048. End If
  4049. Next
  4050. ext:
  4051. If rslt = 0 Then
  4052. Rollback Using commit_transaction;
  4053. ElseIf rslt = 1 And arg_ifcommit Then
  4054. Commit Using commit_transaction;
  4055. End If
  4056. Destroy uo_price
  4057. Destroy uo_out
  4058. Return rslt
  4059. end function
  4060. on uo_outware_sale.create
  4061. call super::create
  4062. end on
  4063. on uo_outware_sale.destroy
  4064. call super::destroy
  4065. end on
  4066. event constructor;call super::constructor;String str_optionvalue,arg_msg
  4067. f_get_sys_option_value('045',str_optionvalue,arg_msg)
  4068. uo_option_m_msttake = Long(str_optionvalue)
  4069. f_get_sys_option_value('052',str_optionvalue,arg_msg)
  4070. uo_option_otheramt_msttake = Long(str_optionvalue)
  4071. f_get_sys_option_value('050',str_optionvalue,arg_msg)
  4072. uo_option_change_otheramt = trim(str_optionvalue)
  4073. f_get_sys_option_value('188',str_optionvalue,arg_msg)
  4074. uo_option_outware_sale_ifmating = Long(str_optionvalue)
  4075. f_get_sys_option_value('332',str_optionvalue,arg_msg)
  4076. uo_option_secaudit_notupdate_hisprice = Long(str_optionvalue)
  4077. end event